linux-pwm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2] backlight: lp855x: Fixes after c1ff7da03e16
@ 2023-07-14 12:14 Artur Weber
  2023-07-14 12:14 ` [PATCH 1/2] backlight: lp855x: Initialize PWM state on first brightness change Artur Weber
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Artur Weber @ 2023-07-14 12:14 UTC (permalink / raw)
  To: Lee Jones
  Cc: Daniel Thompson, Jingoo Han, Helge Deller, Thierry Reding,
	Uwe Kleine-König, Artur Weber, dri-devel, linux-fbdev,
	linux-kernel, linux-pwm, ~postmarketos/upstreaming

Two small fixes after commit c1ff7da03e16 ("video: backlight: lp855x:
Get PWM for PWM mode during probe"), stemming from a review[1] by
Uwe Kleine-König.

[1] https://lore.kernel.org/all/20230614083953.e4kkweddjz7wztby@pengutronix.de/

Signed-off-by: Artur Weber <aweber.kernel@gmail.com>

Artur Weber (2):
  backlight: lp855x: Initialize PWM state on first brightness change
  backlight: lp855x: Catch errors when changing brightness

 drivers/video/backlight/lp855x_bl.c | 33 +++++++++++++++++------------
 1 file changed, 20 insertions(+), 13 deletions(-)


base-commit: 7fcd473a6455450428795d20db7afd2691c92336
-- 
2.41.0


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH 1/2] backlight: lp855x: Initialize PWM state on first brightness change
  2023-07-14 12:14 [PATCH 0/2] backlight: lp855x: Fixes after c1ff7da03e16 Artur Weber
@ 2023-07-14 12:14 ` Artur Weber
  2023-07-17  8:38   ` Daniel Thompson
  2023-07-14 12:14 ` [PATCH 2/2] backlight: lp855x: Catch errors when changing brightness Artur Weber
  2023-07-28  9:22 ` [PATCH 0/2] backlight: lp855x: Fixes after c1ff7da03e16 Lee Jones
  2 siblings, 1 reply; 6+ messages in thread
From: Artur Weber @ 2023-07-14 12:14 UTC (permalink / raw)
  To: Lee Jones
  Cc: Daniel Thompson, Jingoo Han, Helge Deller, Thierry Reding,
	Uwe Kleine-König, Artur Weber, dri-devel, linux-fbdev,
	linux-kernel, linux-pwm, ~postmarketos/upstreaming

As pointed out by Uwe Kleine-König[1], the changes introduced in
commit c1ff7da03e16 ("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: c1ff7da03e16 ("video: backlight: lp855x: Get PWM for PWM mode during probe")
Signed-off-by: Artur Weber <aweber.kernel@gmail.com>
---
 drivers/video/backlight/lp855x_bl.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c
index 1c9e921bca14..349ec324bc1e 100644
--- a/drivers/video/backlight/lp855x_bl.c
+++ b/drivers/video/backlight/lp855x_bl.c
@@ -71,6 +71,7 @@ struct lp855x {
 	struct device *dev;
 	struct lp855x_platform_data *pdata;
 	struct pwm_device *pwm;
+	bool needs_pwm_init;
 	struct regulator *supply;	/* regulator for VDD input */
 	struct regulator *enable;	/* regulator for EN/VDDIO input */
 };
@@ -220,7 +221,15 @@ static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br)
 {
 	struct pwm_state state;
 
-	pwm_get_state(lp->pwm, &state);
+	if (lp->needs_pwm_init) {
+		pwm_init_state(lp->pwm, &state);
+		/* Legacy platform data compatibility */
+		if (lp->pdata->period_ns > 0)
+			state.period = lp->pdata->period_ns;
+		lp->needs_pwm_init = false;
+	} else {
+		pwm_get_state(lp->pwm, &state);
+	}
 
 	state.duty_cycle = div_u64(br * state.period, max_br);
 	state.enabled = state.duty_cycle;
@@ -387,7 +396,6 @@ static int lp855x_probe(struct i2c_client *cl)
 	const struct i2c_device_id *id = i2c_client_get_device_id(cl);
 	const struct acpi_device_id *acpi_id = NULL;
 	struct device *dev = &cl->dev;
-	struct pwm_state pwmstate;
 	struct lp855x *lp;
 	int ret;
 
@@ -470,15 +478,11 @@ static int lp855x_probe(struct i2c_client *cl)
 		else
 			return dev_err_probe(dev, ret, "getting PWM\n");
 
+		lp->needs_pwm_init = false;
 		lp->mode = REGISTER_BASED;
 		dev_dbg(dev, "mode: register based\n");
 	} else {
-		pwm_init_state(lp->pwm, &pwmstate);
-		/* Legacy platform data compatibility */
-		if (lp->pdata->period_ns > 0)
-			pwmstate.period = lp->pdata->period_ns;
-		pwm_apply_state(lp->pwm, &pwmstate);
-
+		lp->needs_pwm_init = true;
 		lp->mode = PWM_BASED;
 		dev_dbg(dev, "mode: PWM based\n");
 	}
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] backlight: lp855x: Catch errors when changing brightness
  2023-07-14 12:14 [PATCH 0/2] backlight: lp855x: Fixes after c1ff7da03e16 Artur Weber
  2023-07-14 12:14 ` [PATCH 1/2] backlight: lp855x: Initialize PWM state on first brightness change Artur Weber
@ 2023-07-14 12:14 ` Artur Weber
  2023-07-17  8:39   ` Daniel Thompson
  2023-07-28  9:22 ` [PATCH 0/2] backlight: lp855x: Fixes after c1ff7da03e16 Lee Jones
  2 siblings, 1 reply; 6+ messages in thread
From: Artur Weber @ 2023-07-14 12:14 UTC (permalink / raw)
  To: Lee Jones
  Cc: Daniel Thompson, Jingoo Han, Helge Deller, Thierry Reding,
	Uwe Kleine-König, Artur Weber, dri-devel, linux-fbdev,
	linux-kernel, linux-pwm, ~postmarketos/upstreaming

The lp855x_bl_update_status function's return type is int, but
it always returns 0, without checking for the results of the
write_byte/pwm_ctrl functions called within.

Make this function return the return values of the functions it
calls, and modify the lp855x_pwm_ctrl function to return errors.

Signed-off-by: Artur Weber <aweber.kernel@gmail.com>
---
 drivers/video/backlight/lp855x_bl.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/video/backlight/lp855x_bl.c b/drivers/video/backlight/lp855x_bl.c
index 349ec324bc1e..61a7f45bfad8 100644
--- a/drivers/video/backlight/lp855x_bl.c
+++ b/drivers/video/backlight/lp855x_bl.c
@@ -217,7 +217,7 @@ static int lp855x_configure(struct lp855x *lp)
 	return ret;
 }
 
-static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br)
+static int lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br)
 {
 	struct pwm_state state;
 
@@ -234,23 +234,26 @@ static void lp855x_pwm_ctrl(struct lp855x *lp, int br, int max_br)
 	state.duty_cycle = div_u64(br * state.period, max_br);
 	state.enabled = state.duty_cycle;
 
-	pwm_apply_state(lp->pwm, &state);
+	return pwm_apply_state(lp->pwm, &state);
 }
 
 static int lp855x_bl_update_status(struct backlight_device *bl)
 {
 	struct lp855x *lp = bl_get_data(bl);
 	int brightness = bl->props.brightness;
+	int ret;
 
 	if (bl->props.state & (BL_CORE_SUSPENDED | BL_CORE_FBBLANK))
 		brightness = 0;
 
 	if (lp->mode == PWM_BASED)
-		lp855x_pwm_ctrl(lp, brightness, bl->props.max_brightness);
+		ret = lp855x_pwm_ctrl(lp, brightness,
+				      bl->props.max_brightness);
 	else if (lp->mode == REGISTER_BASED)
-		lp855x_write_byte(lp, lp->cfg->reg_brightness, (u8)brightness);
+		ret = lp855x_write_byte(lp, lp->cfg->reg_brightness,
+					(u8)brightness);
 
-	return 0;
+	return ret;
 }
 
 static const struct backlight_ops lp855x_bl_ops = {
-- 
2.41.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH 1/2] backlight: lp855x: Initialize PWM state on first brightness change
  2023-07-14 12:14 ` [PATCH 1/2] backlight: lp855x: Initialize PWM state on first brightness change Artur Weber
@ 2023-07-17  8:38   ` Daniel Thompson
  0 siblings, 0 replies; 6+ messages in thread
From: Daniel Thompson @ 2023-07-17  8:38 UTC (permalink / raw)
  To: Artur Weber
  Cc: Lee Jones, Jingoo Han, Helge Deller, Thierry Reding,
	Uwe Kleine-König, dri-devel, linux-fbdev, linux-kernel,
	linux-pwm, ~postmarketos/upstreaming

On Fri, Jul 14, 2023 at 02:14:39PM +0200, Artur Weber wrote:
> As pointed out by Uwe Kleine-König[1], the changes introduced in
> commit c1ff7da03e16 ("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: c1ff7da03e16 ("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>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 2/2] backlight: lp855x: Catch errors when changing brightness
  2023-07-14 12:14 ` [PATCH 2/2] backlight: lp855x: Catch errors when changing brightness Artur Weber
@ 2023-07-17  8:39   ` Daniel Thompson
  0 siblings, 0 replies; 6+ messages in thread
From: Daniel Thompson @ 2023-07-17  8:39 UTC (permalink / raw)
  To: Artur Weber
  Cc: Lee Jones, Jingoo Han, Helge Deller, Thierry Reding,
	Uwe Kleine-König, dri-devel, linux-fbdev, linux-kernel,
	linux-pwm, ~postmarketos/upstreaming

On Fri, Jul 14, 2023 at 02:14:40PM +0200, Artur Weber wrote:
> The lp855x_bl_update_status function's return type is int, but
> it always returns 0, without checking for the results of the
> write_byte/pwm_ctrl functions called within.
>
> Make this function return the return values of the functions it
> calls, and modify the lp855x_pwm_ctrl function to return errors.
>
> Signed-off-by: Artur Weber <aweber.kernel@gmail.com>

Reviewed-by: Daniel Thompson <daniel.thompson@linaro.org>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2] backlight: lp855x: Fixes after c1ff7da03e16
  2023-07-14 12:14 [PATCH 0/2] backlight: lp855x: Fixes after c1ff7da03e16 Artur Weber
  2023-07-14 12:14 ` [PATCH 1/2] backlight: lp855x: Initialize PWM state on first brightness change Artur Weber
  2023-07-14 12:14 ` [PATCH 2/2] backlight: lp855x: Catch errors when changing brightness Artur Weber
@ 2023-07-28  9:22 ` Lee Jones
  2 siblings, 0 replies; 6+ messages in thread
From: Lee Jones @ 2023-07-28  9:22 UTC (permalink / raw)
  To: Lee Jones, Artur Weber
  Cc: Daniel Thompson, Jingoo Han, Helge Deller, Thierry Reding,
	Uwe Kleine-König, dri-devel, linux-fbdev, linux-kernel,
	linux-pwm, ~postmarketos/upstreaming

On Fri, 14 Jul 2023 14:14:38 +0200, Artur Weber wrote:
> Two small fixes after commit c1ff7da03e16 ("video: backlight: lp855x:
> Get PWM for PWM mode during probe"), stemming from a review[1] by
> Uwe Kleine-König.
> 
> [1] https://lore.kernel.org/all/20230614083953.e4kkweddjz7wztby@pengutronix.de/
> 
> Signed-off-by: Artur Weber <aweber.kernel@gmail.com>
> 
> [...]

Applied, thanks!

[1/2] backlight: lp855x: Initialize PWM state on first brightness change
      commit: 4c09e20b3c85f60353ace21092e34f35f5e3ab00
[2/2] backlight: lp855x: Catch errors when changing brightness
      commit: 5145531be5fbad0e914d1dc1cbd392d7b756abaa

--
Lee Jones [李琼斯]


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-07-28  9:27 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-14 12:14 [PATCH 0/2] backlight: lp855x: Fixes after c1ff7da03e16 Artur Weber
2023-07-14 12:14 ` [PATCH 1/2] backlight: lp855x: Initialize PWM state on first brightness change Artur Weber
2023-07-17  8:38   ` Daniel Thompson
2023-07-14 12:14 ` [PATCH 2/2] backlight: lp855x: Catch errors when changing brightness Artur Weber
2023-07-17  8:39   ` Daniel Thompson
2023-07-28  9:22 ` [PATCH 0/2] backlight: lp855x: Fixes after c1ff7da03e16 Lee Jones

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).