Skip to content

Commit b5a7fc2

Browse files
zenghuchen-gglag-linaro
authored andcommitted
leds: lm3601x: Calculate max_brightness and brightness properly
The torch_current_max should be checked not exceeding the upper bound. If it does, throw a warning message and set to LM3601X_MAX_TORCH_I_UA. LM3601x torch brigthness register (LM3601X_LED_TORCH_REG) takes 0 as the minimum output (2.4 mA). However, 0 of led_brightness means LED_OFF. Adding a -1 offset to brightness before writing to brightness register, so when users write minimum brightness (1), it sets lm3601x output the minimum. Signed-off-by: Jack Chen <zenghuchen@google.com> Link: https://lore.kernel.org/r/20240704191500.766846-1-zenghuchen@google.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent 8400291 commit b5a7fc2

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

drivers/leds/flash/leds-lm3601x.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ static int lm3601x_brightness_set(struct led_classdev *cdev,
190190
goto out;
191191
}
192192

193-
ret = regmap_write(led->regmap, LM3601X_LED_TORCH_REG, brightness);
193+
ret = regmap_write(led->regmap, LM3601X_LED_TORCH_REG, brightness - 1);
194194
if (ret < 0)
195195
goto out;
196196

@@ -341,8 +341,9 @@ static int lm3601x_register_leds(struct lm3601x_led *led,
341341

342342
led_cdev = &led->fled_cdev.led_cdev;
343343
led_cdev->brightness_set_blocking = lm3601x_brightness_set;
344-
led_cdev->max_brightness = DIV_ROUND_UP(led->torch_current_max,
345-
LM3601X_TORCH_REG_DIV);
344+
led_cdev->max_brightness =
345+
DIV_ROUND_UP(led->torch_current_max - LM3601X_MIN_TORCH_I_UA + 1,
346+
LM3601X_TORCH_REG_DIV);
346347
led_cdev->flags |= LED_DEV_CAP_FLASH;
347348

348349
init_data.fwnode = fwnode;
@@ -386,6 +387,14 @@ static int lm3601x_parse_node(struct lm3601x_led *led,
386387
goto out_err;
387388
}
388389

390+
if (led->torch_current_max > LM3601X_MAX_TORCH_I_UA) {
391+
dev_warn(&led->client->dev,
392+
"Max torch current set too high (%d vs %d)\n",
393+
led->torch_current_max,
394+
LM3601X_MAX_TORCH_I_UA);
395+
led->torch_current_max = LM3601X_MAX_TORCH_I_UA;
396+
}
397+
389398
ret = fwnode_property_read_u32(child, "flash-max-microamp",
390399
&led->flash_current_max);
391400
if (ret) {

0 commit comments

Comments
 (0)