Skip to content

Commit 4c09e20

Browse files
refractionwarelag-linaro
authored andcommitted
backlight: lp855x: Initialize PWM state on first brightness change
As pointed out by Uwe Kleine-König[1], the changes introduced in commit c1ff7da ("video: backlight: lp855x: Get PWM for PWM mode during probe") caused the PWM state set up by the bootloader to be re-set when the driver is probed. This differs from the behavior from before that patch, where the PWM state would be initialized on the first brightness change. Fix this by moving the PWM state initialization into the PWM control function. Add a new variable, needs_pwm_init, to the device info struct to allow us to check whether we need the initialization, or whether it has already been done. [1] https://lore.kernel.org/lkml/20230614083953.e4kkweddjz7wztby@pengutronix.de/ Fixes: c1ff7da ("video: backlight: lp855x: Get PWM for PWM mode during probe") Signed-off-by: Artur Weber <aweber.kernel@gmail.com> Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org> Link: https://lore.kernel.org/r/20230714121440.7717-2-aweber.kernel@gmail.com Signed-off-by: Lee Jones <lee@kernel.org>
1 parent 1bb5187 commit 4c09e20

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

drivers/video/backlight/lp855x_bl.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ struct lp855x {
7171
struct device *dev;
7272
struct lp855x_platform_data *pdata;
7373
struct pwm_device *pwm;
74+
bool needs_pwm_init;
7475
struct regulator *supply; /* regulator for VDD input */
7576
struct regulator *enable; /* regulator for EN/VDDIO input */
7677
};
@@ -220,7 +221,15 @@ static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br)
220221
{
221222
struct pwm_state state;
222223

223-
pwm_get_state(lp->pwm, &state);
224+
if (lp->needs_pwm_init) {
225+
pwm_init_state(lp->pwm, &state);
226+
/* Legacy platform data compatibility */
227+
if (lp->pdata->period_ns > 0)
228+
state.period = lp->pdata->period_ns;
229+
lp->needs_pwm_init = false;
230+
} else {
231+
pwm_get_state(lp->pwm, &state);
232+
}
224233

225234
state.duty_cycle = div_u64(br * state.period, max_br);
226235
state.enabled = state.duty_cycle;
@@ -387,7 +396,6 @@ static int lp855x_probe(struct i2c_client *cl)
387396
const struct i2c_device_id *id = i2c_client_get_device_id(cl);
388397
const struct acpi_device_id *acpi_id = NULL;
389398
struct device *dev = &cl->dev;
390-
struct pwm_state pwmstate;
391399
struct lp855x *lp;
392400
int ret;
393401

@@ -470,15 +478,11 @@ static int lp855x_probe(struct i2c_client *cl)
470478
else
471479
return dev_err_probe(dev, ret, "getting PWM\n");
472480

481+
lp->needs_pwm_init = false;
473482
lp->mode = REGISTER_BASED;
474483
dev_dbg(dev, "mode: register based\n");
475484
} else {
476-
pwm_init_state(lp->pwm, &pwmstate);
477-
/* Legacy platform data compatibility */
478-
if (lp->pdata->period_ns > 0)
479-
pwmstate.period = lp->pdata->period_ns;
480-
pwm_apply_state(lp->pwm, &pwmstate);
481-
485+
lp->needs_pwm_init = true;
482486
lp->mode = PWM_BASED;
483487
dev_dbg(dev, "mode: PWM based\n");
484488
}

0 commit comments

Comments
 (0)