Skip to content

Commit df7083b

Browse files
agxpavelmachek
authored andcommitted
leds: lm3692x: Make sure we don't exceed the maximum LED current
The current is given by the formular from page 12 of https://www.ti.com/lit/ds/symlink/lm36922.pdf. We use this to limit the led's max_brightness using the led-max-microamp DT property. The formula for the lm36923 is identical according to the data sheet. Signed-off-by: Guido Günther <[email protected]> Acked-by: Pavel Machek <[email protected]> Signed-off-by: Pavel Machek <[email protected]>
1 parent 3e0801b commit df7083b

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

drivers/leds/leds-lm3692x.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <linux/i2c.h>
77
#include <linux/init.h>
88
#include <linux/leds.h>
9+
#include <linux/log2.h>
910
#include <linux/module.h>
1011
#include <linux/mutex.h>
1112
#include <linux/of.h>
@@ -321,11 +322,24 @@ static int lm3692x_init(struct lm3692x_led *led)
321322
return ret;
322323
}
323324

325+
static enum led_brightness lm3692x_max_brightness(struct lm3692x_led *led,
326+
u32 max_cur)
327+
{
328+
u32 max_code;
329+
330+
/* see p.12 of LM36922 data sheet for brightness formula */
331+
max_code = ((max_cur * 1000) - 37806) / 12195;
332+
if (max_code > 0x7FF)
333+
max_code = 0x7FF;
334+
335+
return max_code >> 3;
336+
}
337+
324338
static int lm3692x_probe_dt(struct lm3692x_led *led)
325339
{
326340
struct fwnode_handle *child = NULL;
327341
struct led_init_data init_data = {};
328-
u32 ovp;
342+
u32 ovp, max_cur;
329343
int ret;
330344

331345
led->enable_gpio = devm_gpiod_get_optional(&led->client->dev,
@@ -391,6 +405,10 @@ static int lm3692x_probe_dt(struct lm3692x_led *led)
391405
return ret;
392406
}
393407

408+
ret = fwnode_property_read_u32(child, "led-max-microamp", &max_cur);
409+
led->led_dev.max_brightness = ret ? LED_FULL :
410+
lm3692x_max_brightness(led, max_cur);
411+
394412
init_data.fwnode = child;
395413
init_data.devicename = led->client->name;
396414
init_data.default_label = ":";

0 commit comments

Comments
 (0)