Skip to content

Commit d347d0c

Browse files
Enric Balletbo i SerraLee Jones
authored andcommitted
backlight: pwm_bl: Fix brightness levels for non-DT case.
Commit '88ba95bedb79 ("backlight: pwm_bl: Compute brightness of LED linearly to human eye")' allows the possibility to compute a default brightness table when there isn't the brightness-levels property in the DT. Unfortunately the changes made broke the pwm backlight for the non-DT boards. Usually, the non-DT boards don't pass the brightness levels via platform data, instead, it sets the max_brightness in their platform data and the driver calculates the level without a table. The offending patch assumed that when there is no brightness levels table we should create one, but this is clearly wrong for the non-DT case. After this patch the code handles the DT and the non-DT case taking in consideration also if max_brightness is set or not. Fixes: 88ba95b ("backlight: pwm_bl: Compute brightness of LED linearly to human eye") Reported-by: Robert Jarzmik <robert.jarzmik@free.fr> Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com> Tested-by: Robert Jarzmik <robert.jarzmik@free.fr> Acked-by: Daniel Thompson <daniel.thompson@linaro.org> Signed-off-by: Lee Jones <lee.jones@linaro.org>
1 parent 6510223 commit d347d0c

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

drivers/video/backlight/pwm_bl.c

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -562,21 +562,50 @@ static int pwm_backlight_probe(struct platform_device *pdev)
562562
goto err_alloc;
563563
}
564564

565-
if (!data->levels) {
565+
if (data->levels) {
566+
/*
567+
* For the DT case, only when brightness levels is defined
568+
* data->levels is filled. For the non-DT case, data->levels
569+
* can come from platform data, however is not usual.
570+
*/
571+
for (i = 0; i <= data->max_brightness; i++) {
572+
if (data->levels[i] > pb->scale)
573+
pb->scale = data->levels[i];
574+
575+
pb->levels = data->levels;
576+
}
577+
} else if (!data->max_brightness) {
578+
/*
579+
* If no brightness levels are provided and max_brightness is
580+
* not set, use the default brightness table. For the DT case,
581+
* max_brightness is set to 0 when brightness levels is not
582+
* specified. For the non-DT case, max_brightness is usually
583+
* set to some value.
584+
*/
585+
586+
/* Get the PWM period (in nanoseconds) */
587+
pwm_get_state(pb->pwm, &state);
588+
566589
ret = pwm_backlight_brightness_default(&pdev->dev, data,
567590
state.period);
568591
if (ret < 0) {
569592
dev_err(&pdev->dev,
570593
"failed to setup default brightness table\n");
571594
goto err_alloc;
572595
}
573-
}
574596

575-
for (i = 0; i <= data->max_brightness; i++) {
576-
if (data->levels[i] > pb->scale)
577-
pb->scale = data->levels[i];
597+
for (i = 0; i <= data->max_brightness; i++) {
598+
if (data->levels[i] > pb->scale)
599+
pb->scale = data->levels[i];
578600

579-
pb->levels = data->levels;
601+
pb->levels = data->levels;
602+
}
603+
} else {
604+
/*
605+
* That only happens for the non-DT case, where platform data
606+
* sets the max_brightness value.
607+
*/
608+
pb->scale = data->max_brightness;
580609
}
581610

582611
pb->lth_brightness = data->lth_brightness * (state.period / pb->scale);

0 commit comments

Comments
 (0)