leds:lm3601x:calculate max_brightness and brightness properly
PATCH 1/1 leds:lm3601x:calculate max_brightness and brightness properly
1) check the range of torch_current_max,
2) calcualtes max_brightness precisely,
3) lm3601x torch brightness register starts from 0 (2.4 mA).
Tested: tested with a lm36011 and it can set its brightness to lowest value (2.4 mA)
--- drivers/leds/flash/leds-lm3601x.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)
drivers/leds/flash/leds-lm3601x.c +12 -3
@@ -190,7 +190,7 @@ static int lm3601x_brightness_set(struct led_classdev *cdev, goto out; } - ret =regmap_write (led->regmap,LM3601X_LED_TORCH_REG , brightness); + ret =regmap_write (led->regmap,LM3601X_LED_TORCH_REG , brightness -1 );if (ret <0 ) goto out;
@@ -341,8 +341,9 @@ static int lm3601x_register_leds(struct lm3601x_led *led, led_cdev = &led->fled_cdev.led_cdev; led_cdev->brightness_set_blocking = lm3601x_brightness_set; - led_cdev->max_brightness =DIV_ROUND_UP (led->torch_current_max, -LM3601X_TORCH_REG_DIV ); + led_cdev->max_brightness =DIV_ROUND_UP ( + led->torch_current_max -LM3601X_MIN_TORCH_I_UA +1 , +LM3601X_TORCH_REG_DIV ); led_cdev->flags |=LED_DEV_CAP_FLASH ; init_data.fwnode = fwnode;
@@ -386,6 +387,14 @@ static int lm3601x_parse_node(struct lm3601x_led *led, goto out_err; } +if (led->torch_current_max >LM3601X_MAX_TORCH_I_UA ) { +dev_warn (&led->client->dev, +"led-max-microamp cannot be higher than %d\n" , +LM3601X_MAX_TORCH_I_UA ); + led->torch_current_max =LM3601X_MAX_TORCH_I_UA ; + } + + ret =fwnode_property_read_u32 (child,"flash-max-microamp" , &led->flash_current_max);if (ret) {
Signature · 1 line
2.45.2.803.g4e1b14247a-goog
Lee Jones
maintainerSubject line needs fixing.
git log --oneline -- drivers/<subsystem> is your friend.
Quoted 3 lines
1) check the range of
torch_current_max,
2) calcualtesmax_brightnessprecisely,
3) lm3601x torch brightness register starts from 0 (2.4 mA).
Please write this out as a proper paragraph.
This isn't really a numbered list type situation.
Quoted 2 lines
Tested: tested with a lm36011 and it can set its brightness to lowest value (2.4 mA)
What is the Tested: trailer? Again, please write this out properly.
Quoted 10 lines
Signed-off-by Jack Chen <[email protected]>--- drivers/leds/flash/leds-lm3601x.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)drivers/leds/flash/leds-lm3601x.c +0
-0
drivers/leds/flash/leds-lm3601x.c static int lm3601x_brightness_set(struct led_classdev *cdev, · line 193
Quoted 5 lines
drivers/leds/flash/leds-lm3601x.c +1
-1@@ -190,7 +190,7 @@ static int lm3601x_brightness_set(struct led_classdev *cdev, goto out; } - ret =regmap_write (led->regmap,LM3601X_LED_TORCH_REG , brightness); + ret =regmap_write (led->regmap,LM3601X_LED_TORCH_REG , brightness -1 );
Why is there now a need to start adding/subtracting 1s to make the maths work?
drivers/leds/flash/leds-lm3601x.c static int lm3601x_register_leds(struct lm3601x_led *led, · line 344
Quoted 10 lines
drivers/leds/flash/leds-lm3601x.c +1
-2if (ret <0 ) goto out;@@ -341,8 +341,9 @@ static int lm3601x_register_leds(struct lm3601x_led *led, led_cdev = &led->fled_cdev.led_cdev; led_cdev->brightness_set_blocking = lm3601x_brightness_set; - led_cdev->max_brightness =DIV_ROUND_UP (led->torch_current_max, -LM3601X_TORCH_REG_DIV ); + led_cdev->max_brightness = DIV_ROUND_UP(
This is no place to break a line.
Break after the '=' and wrap at 100-chars instead.
drivers/leds/flash/leds-lm3601x.c static int lm3601x_parse_node(struct lm3601x_led *led, · line 393
Quoted 13 lines
drivers/leds/flash/leds-lm3601x.c +6
-0+ led->torch_current_max -LM3601X_MIN_TORCH_I_UA +1 , + LM3601X_TORCH_REG_DIV); led_cdev->flags |=LED_DEV_CAP_FLASH ; init_data.fwnode = fwnode;@@ -386,6 +387,14 @@ static int lm3601x_parse_node(struct lm3601x_led *led, goto out_err; } +if (led->torch_current_max >LM3601X_MAX_TORCH_I_UA ) { +dev_warn (&led->client->dev, +"led-max-microamp cannot be higher than %d\n" , +LM3601X_MAX_TORCH_I_UA );
"Max torch current set too high (%d vs %d)"
drivers/leds/flash/leds-lm3601x.c static int lm3601x_parse_node(struct lm3601x_led *led, · line 397
Quoted 4 lines
drivers/leds/flash/leds-lm3601x.c +4
-0+ led->torch_current_max =LM3601X_MAX_TORCH_I_UA ; + } + +
2 lines?
Quoted 6 lines
drivers/leds/flash/leds-lm3601x.c +0
-0ret =fwnode_property_read_u32 (child,"flash-max-microamp" , &led->flash_current_max);if (ret) {Signature · 1 line
2.45.2.803.g4e1b14247a-goog
Signature · 1 line
Lee Jones [李琼斯]
Many thanks to Lee for the quick response. I will submit a V2 patch later.
Quoted 4 lines
drivers/leds/flash/leds-lm3601x.c static int lm3601x_brightness_set(struct led_classdev *cdev, · line 193
Quoted 2 lines
drivers/leds/flash/leds-lm3601x.c +1
-1- ret =regmap_write (led->regmap,LM3601X_LED_TORCH_REG , brightness); + ret =regmap_write (led->regmap,LM3601X_LED_TORCH_REG , brightness -1 );Why is there now a need to start adding/subtracting 1s to make the maths work?
This is because lm3601x torch brightness register takes 0 as the minimum output current (2.4mA). But led_brightness uses 0 as LED_OFF. So we need to add -1 offset to avoid blocking users who want to set the torch output minimum.
Quoted 83 lines · Lee Jones
Subject line needs fixing.
git log --oneline -- drivers/<subsystem>is your friend.Quoted 3 lines
1) check the range of
torch_current_max,
2) calcualtesmax_brightnessprecisely,
3) lm3601x torch brightness register starts from 0 (2.4 mA).Please write this out as a proper paragraph.
This isn't really a numbered list type situation.
Quoted 2 lines
Tested: tested with a lm36011 and it can set its brightness to lowest value (2.4 mA)
What is the Tested: trailer? Again, please write this out properly.
Quoted 10 lines
Signed-off-by Jack Chen <[email protected]>--- drivers/leds/flash/leds-lm3601x.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-)drivers/leds/flash/leds-lm3601x.c +0
-0drivers/leds/flash/leds-lm3601x.c static int lm3601x_brightness_set(struct led_classdev *cdev, · line 193
Quoted 5 lines
drivers/leds/flash/leds-lm3601x.c +1
-1@@ -190,7 +190,7 @@ static int lm3601x_brightness_set(struct led_classdev *cdev, goto out; } - ret =regmap_write (led->regmap,LM3601X_LED_TORCH_REG , brightness); + ret =regmap_write (led->regmap,LM3601X_LED_TORCH_REG , brightness -1 );Why is there now a need to start adding/subtracting 1s to make the maths work?
drivers/leds/flash/leds-lm3601x.c static int lm3601x_register_leds(struct lm3601x_led *led, · line 344
Quoted 10 lines
drivers/leds/flash/leds-lm3601x.c +1
-2if (ret <0 ) goto out;@@ -341,8 +341,9 @@ static int lm3601x_register_leds(struct lm3601x_led *led, led_cdev = &led->fled_cdev.led_cdev; led_cdev->brightness_set_blocking = lm3601x_brightness_set; - led_cdev->max_brightness =DIV_ROUND_UP (led->torch_current_max, -LM3601X_TORCH_REG_DIV ); + led_cdev->max_brightness = DIV_ROUND_UP(This is no place to break a line.
Break after the '=' and wrap at 100-chars instead.
drivers/leds/flash/leds-lm3601x.c static int lm3601x_parse_node(struct lm3601x_led *led, · line 393
Quoted 13 lines
drivers/leds/flash/leds-lm3601x.c +6
-0+ led->torch_current_max -LM3601X_MIN_TORCH_I_UA +1 , + LM3601X_TORCH_REG_DIV); led_cdev->flags |=LED_DEV_CAP_FLASH ; init_data.fwnode = fwnode;@@ -386,6 +387,14 @@ static int lm3601x_parse_node(struct lm3601x_led *led, goto out_err; } +if (led->torch_current_max >LM3601X_MAX_TORCH_I_UA ) { +dev_warn (&led->client->dev, +"led-max-microamp cannot be higher than %d\n" , +LM3601X_MAX_TORCH_I_UA );"Max torch current set too high (%d vs %d)"
drivers/leds/flash/leds-lm3601x.c static int lm3601x_parse_node(struct lm3601x_led *led, · line 397
Quoted 4 lines
drivers/leds/flash/leds-lm3601x.c +4
-0+ led->torch_current_max =LM3601X_MAX_TORCH_I_UA ; + } + +2 lines?
Quoted 6 lines
drivers/leds/flash/leds-lm3601x.c +0
-1ret =fwnode_property_read_u32 (child,"flash-max-microamp" , &led->flash_current_max);if (ret) { --2.45.2.803.g4e1b14247a-goog
--
Lee Jones [李琼斯]