Skip to content

Commit 79fad92

Browse files
Daniel ThompsonLee Jones
authored andcommitted
backlight: pwm_bl: Improve bootloader/kernel device handover
Currently there are (at least) two problems in the way pwm_bl starts managing the enable_gpio pin. Both occur when the backlight is initially off and the driver finds the pin not already in output mode and, as a result, unconditionally switches it to output-mode and asserts the signal. Problem 1: This could cause the backlight to flicker since, at this stage in driver initialisation, we have no idea what the PWM and regulator are doing (an unconfigured PWM could easily "rest" at 100% duty cycle). Problem 2: This will cause us not to correctly honour the post_pwm_on_delay (which also risks flickers). Fix this by moving the code to configure the GPIO output mode until after we have examines the handover state. That allows us to initialize enable_gpio to off if the backlight is currently off and on if the backlight is on. Cc: [email protected] Reported-by: Marek Vasut <[email protected]> Signed-off-by: Daniel Thompson <[email protected]> Acked-by: Marek Vasut <[email protected]> Tested-by: Marek Vasut <[email protected]> Signed-off-by: Lee Jones <[email protected]>
1 parent daa3736 commit 79fad92

File tree

1 file changed

+28
-26
lines changed

1 file changed

+28
-26
lines changed

drivers/video/backlight/pwm_bl.c

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,33 @@ static bool pwm_backlight_is_linear(struct platform_pwm_backlight_data *data)
409409
static int pwm_backlight_initial_power_state(const struct pwm_bl_data *pb)
410410
{
411411
struct device_node *node = pb->dev->of_node;
412+
bool active = true;
413+
414+
/*
415+
* If the enable GPIO is present, observable (either as input
416+
* or output) and off then the backlight is not currently active.
417+
* */
418+
if (pb->enable_gpio && gpiod_get_value_cansleep(pb->enable_gpio) == 0)
419+
active = false;
420+
421+
if (!regulator_is_enabled(pb->power_supply))
422+
active = false;
423+
424+
if (!pwm_is_enabled(pb->pwm))
425+
active = false;
426+
427+
/*
428+
* Synchronize the enable_gpio with the observed state of the
429+
* hardware.
430+
*/
431+
if (pb->enable_gpio)
432+
gpiod_direction_output(pb->enable_gpio, active);
433+
434+
/*
435+
* Do not change pb->enabled here! pb->enabled essentially
436+
* tells us if we own one of the regulator's use counts and
437+
* right now we do not.
438+
*/
412439

413440
/* Not booted with device tree or no phandle link to the node */
414441
if (!node || !node->phandle)
@@ -420,20 +447,7 @@ static int pwm_backlight_initial_power_state(const struct pwm_bl_data *pb)
420447
* assume that another driver will enable the backlight at the
421448
* appropriate time. Therefore, if it is disabled, keep it so.
422449
*/
423-
424-
/* if the enable GPIO is disabled, do not enable the backlight */
425-
if (pb->enable_gpio && gpiod_get_value_cansleep(pb->enable_gpio) == 0)
426-
return FB_BLANK_POWERDOWN;
427-
428-
/* The regulator is disabled, do not enable the backlight */
429-
if (!regulator_is_enabled(pb->power_supply))
430-
return FB_BLANK_POWERDOWN;
431-
432-
/* The PWM is disabled, keep it like this */
433-
if (!pwm_is_enabled(pb->pwm))
434-
return FB_BLANK_POWERDOWN;
435-
436-
return FB_BLANK_UNBLANK;
450+
return active ? FB_BLANK_UNBLANK: FB_BLANK_POWERDOWN;
437451
}
438452

439453
static int pwm_backlight_probe(struct platform_device *pdev)
@@ -486,18 +500,6 @@ static int pwm_backlight_probe(struct platform_device *pdev)
486500
goto err_alloc;
487501
}
488502

489-
/*
490-
* If the GPIO is not known to be already configured as output, that
491-
* is, if gpiod_get_direction returns either 1 or -EINVAL, change the
492-
* direction to output and set the GPIO as active.
493-
* Do not force the GPIO to active when it was already output as it
494-
* could cause backlight flickering or we would enable the backlight too
495-
* early. Leave the decision of the initial backlight state for later.
496-
*/
497-
if (pb->enable_gpio &&
498-
gpiod_get_direction(pb->enable_gpio) != 0)
499-
gpiod_direction_output(pb->enable_gpio, 1);
500-
501503
pb->power_supply = devm_regulator_get(&pdev->dev, "power");
502504
if (IS_ERR(pb->power_supply)) {
503505
ret = PTR_ERR(pb->power_supply);

0 commit comments

Comments
 (0)