Commit e4c8ae3e authored by Heiko Stuebner's avatar Heiko Stuebner Committed by Lee Jones

backlight: pwm_bl: Re-add driver internal enabled tracking

Commit e6bcca08 ("backlight: pwm_bl: Switch to using "atomic" PWM API")
removed the driver internal enabled tracking in favor of simply checking
the pwm state.

This can lead to issues as all of gpio-, regulator- and pwm-state are used
to determine the initial state and the bootloader or kernel can leave them
in an inconsistent state at boot.

In my case on rk3399-kevin, the pwm backlight is build as module and the
kernel disables the supply regulator as unused while keeping the pwm running
thus pwm_bl calling pwm_backlight_power_off() during probe and creating an
unmatched regulator-disable call, as it never got enabled from the pwm-bl
before.

To prevent these consistency issues, reintroduce the driver-internal
tracking of the enabled state.

Fixes: e6bcca08 ("backlight: pwm_bl: Switch to using "atomic" PWM API")
Signed-off-by: default avatarHeiko Stuebner <heiko@sntech.de>
Acked-by: default avatarThierry Reding <thierry.reding@gmail.com>
Acked-by: default avatarDaniel Thompson <daniel.thompson@linaro.org>
Signed-off-by: default avatarLee Jones <lee.jones@linaro.org>
parent 65102238
...@@ -30,6 +30,7 @@ struct pwm_bl_data { ...@@ -30,6 +30,7 @@ struct pwm_bl_data {
struct device *dev; struct device *dev;
unsigned int lth_brightness; unsigned int lth_brightness;
unsigned int *levels; unsigned int *levels;
bool enabled;
struct regulator *power_supply; struct regulator *power_supply;
struct gpio_desc *enable_gpio; struct gpio_desc *enable_gpio;
unsigned int scale; unsigned int scale;
...@@ -50,7 +51,7 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb) ...@@ -50,7 +51,7 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb)
int err; int err;
pwm_get_state(pb->pwm, &state); pwm_get_state(pb->pwm, &state);
if (state.enabled) if (pb->enabled)
return; return;
err = regulator_enable(pb->power_supply); err = regulator_enable(pb->power_supply);
...@@ -65,6 +66,8 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb) ...@@ -65,6 +66,8 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb)
if (pb->enable_gpio) if (pb->enable_gpio)
gpiod_set_value_cansleep(pb->enable_gpio, 1); gpiod_set_value_cansleep(pb->enable_gpio, 1);
pb->enabled = true;
} }
static void pwm_backlight_power_off(struct pwm_bl_data *pb) static void pwm_backlight_power_off(struct pwm_bl_data *pb)
...@@ -72,7 +75,7 @@ static void pwm_backlight_power_off(struct pwm_bl_data *pb) ...@@ -72,7 +75,7 @@ static void pwm_backlight_power_off(struct pwm_bl_data *pb)
struct pwm_state state; struct pwm_state state;
pwm_get_state(pb->pwm, &state); pwm_get_state(pb->pwm, &state);
if (!state.enabled) if (!pb->enabled)
return; return;
if (pb->enable_gpio) if (pb->enable_gpio)
...@@ -86,6 +89,7 @@ static void pwm_backlight_power_off(struct pwm_bl_data *pb) ...@@ -86,6 +89,7 @@ static void pwm_backlight_power_off(struct pwm_bl_data *pb)
pwm_apply_state(pb->pwm, &state); pwm_apply_state(pb->pwm, &state);
regulator_disable(pb->power_supply); regulator_disable(pb->power_supply);
pb->enabled = false;
} }
static int compute_duty_cycle(struct pwm_bl_data *pb, int brightness) static int compute_duty_cycle(struct pwm_bl_data *pb, int brightness)
...@@ -483,6 +487,7 @@ static int pwm_backlight_probe(struct platform_device *pdev) ...@@ -483,6 +487,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
pb->check_fb = data->check_fb; pb->check_fb = data->check_fb;
pb->exit = data->exit; pb->exit = data->exit;
pb->dev = &pdev->dev; pb->dev = &pdev->dev;
pb->enabled = false;
pb->post_pwm_on_delay = data->post_pwm_on_delay; pb->post_pwm_on_delay = data->post_pwm_on_delay;
pb->pwm_off_delay = data->pwm_off_delay; pb->pwm_off_delay = data->pwm_off_delay;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment