From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de> To: Lee Jones <lee.jones@linaro.org>, Daniel Thompson <daniel.thompson@linaro.org>, Jingoo Han <jingoohan1@gmail.com> Cc: Thierry Reding <thierry.reding@gmail.com>, dri-devel@lists.freedesktop.org, linux-fbdev@vger.kernel.org, kernel@pengutronix.de Subject: [PATCH] backlight: lm3630a: convert to atomic PWM API and check for errors Date: Fri, 18 Jun 2021 10:58:44 +0200 [thread overview] Message-ID: <20210618085844.231751-1-u.kleine-koenig@pengutronix.de> (raw) The practical upside here is that this only needs a single API call to program the hardware which (depending on the underlaying hardware) can be more effective and prevents glitches. Up to now the return value of the pwm functions was ignored. Fix this and propagate the error to the caller. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> --- drivers/video/backlight/lm3630a_bl.c | 33 +++++++++++++++------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/drivers/video/backlight/lm3630a_bl.c b/drivers/video/backlight/lm3630a_bl.c index e88a2b0e5904..24fa7e6938fa 100644 --- a/drivers/video/backlight/lm3630a_bl.c +++ b/drivers/video/backlight/lm3630a_bl.c @@ -52,6 +52,7 @@ struct lm3630a_chip { struct gpio_desc *enable_gpio; struct regmap *regmap; struct pwm_device *pwmd; + struct pwm_state pwmd_state; }; /* i2c access */ @@ -167,16 +168,19 @@ static int lm3630a_intr_config(struct lm3630a_chip *pchip) return rval; } -static void lm3630a_pwm_ctrl(struct lm3630a_chip *pchip, int br, int br_max) +static int lm3630a_pwm_ctrl(struct lm3630a_chip *pchip, int br, int br_max) { - unsigned int period = pchip->pdata->pwm_period; - unsigned int duty = br * period / br_max; + int err; - pwm_config(pchip->pwmd, duty, period); - if (duty) - pwm_enable(pchip->pwmd); - else - pwm_disable(pchip->pwmd); + pchip->pwmd_state.period = pchip->pdata->pwm_period; + + err = pwm_set_relative_duty_cycle(&pchip->pwmd_state, br, br_max); + if (err) + return err; + + pchip->pwmd_state.enabled = pchip->pwmd_state.duty_cycle ? true : false; + + return pwm_apply_state(pchip->pwmd, &pchip->pwmd_state); } /* update and get brightness */ @@ -188,8 +192,11 @@ static int lm3630a_bank_a_update_status(struct backlight_device *bl) /* pwm control */ if ((pwm_ctrl & LM3630A_PWM_BANK_A) != 0) { - lm3630a_pwm_ctrl(pchip, bl->props.brightness, - bl->props.max_brightness); + ret = lm3630a_pwm_ctrl(pchip, bl->props.brightness, + bl->props.max_brightness); + if (ret) + return ret; + return bl->props.brightness; } @@ -563,11 +570,7 @@ static int lm3630a_probe(struct i2c_client *client, return PTR_ERR(pchip->pwmd); } - /* - * FIXME: pwm_apply_args() should be removed when switching to - * the atomic PWM API. - */ - pwm_apply_args(pchip->pwmd); + pwm_init_state(pchip->pwmd, &pchip->pwmd_state); } /* interrupt enable : irq 0 is not allowed */ -- 2.30.2
WARNING: multiple messages have this Message-ID (diff)
From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de> To: Lee Jones <lee.jones@linaro.org>, Daniel Thompson <daniel.thompson@linaro.org>, Jingoo Han <jingoohan1@gmail.com> Cc: linux-fbdev@vger.kernel.org, Thierry Reding <thierry.reding@gmail.com>, kernel@pengutronix.de, dri-devel@lists.freedesktop.org Subject: [PATCH] backlight: lm3630a: convert to atomic PWM API and check for errors Date: Fri, 18 Jun 2021 10:58:44 +0200 [thread overview] Message-ID: <20210618085844.231751-1-u.kleine-koenig@pengutronix.de> (raw) The practical upside here is that this only needs a single API call to program the hardware which (depending on the underlaying hardware) can be more effective and prevents glitches. Up to now the return value of the pwm functions was ignored. Fix this and propagate the error to the caller. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> --- drivers/video/backlight/lm3630a_bl.c | 33 +++++++++++++++------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/drivers/video/backlight/lm3630a_bl.c b/drivers/video/backlight/lm3630a_bl.c index e88a2b0e5904..24fa7e6938fa 100644 --- a/drivers/video/backlight/lm3630a_bl.c +++ b/drivers/video/backlight/lm3630a_bl.c @@ -52,6 +52,7 @@ struct lm3630a_chip { struct gpio_desc *enable_gpio; struct regmap *regmap; struct pwm_device *pwmd; + struct pwm_state pwmd_state; }; /* i2c access */ @@ -167,16 +168,19 @@ static int lm3630a_intr_config(struct lm3630a_chip *pchip) return rval; } -static void lm3630a_pwm_ctrl(struct lm3630a_chip *pchip, int br, int br_max) +static int lm3630a_pwm_ctrl(struct lm3630a_chip *pchip, int br, int br_max) { - unsigned int period = pchip->pdata->pwm_period; - unsigned int duty = br * period / br_max; + int err; - pwm_config(pchip->pwmd, duty, period); - if (duty) - pwm_enable(pchip->pwmd); - else - pwm_disable(pchip->pwmd); + pchip->pwmd_state.period = pchip->pdata->pwm_period; + + err = pwm_set_relative_duty_cycle(&pchip->pwmd_state, br, br_max); + if (err) + return err; + + pchip->pwmd_state.enabled = pchip->pwmd_state.duty_cycle ? true : false; + + return pwm_apply_state(pchip->pwmd, &pchip->pwmd_state); } /* update and get brightness */ @@ -188,8 +192,11 @@ static int lm3630a_bank_a_update_status(struct backlight_device *bl) /* pwm control */ if ((pwm_ctrl & LM3630A_PWM_BANK_A) != 0) { - lm3630a_pwm_ctrl(pchip, bl->props.brightness, - bl->props.max_brightness); + ret = lm3630a_pwm_ctrl(pchip, bl->props.brightness, + bl->props.max_brightness); + if (ret) + return ret; + return bl->props.brightness; } @@ -563,11 +570,7 @@ static int lm3630a_probe(struct i2c_client *client, return PTR_ERR(pchip->pwmd); } - /* - * FIXME: pwm_apply_args() should be removed when switching to - * the atomic PWM API. - */ - pwm_apply_args(pchip->pwmd); + pwm_init_state(pchip->pwmd, &pchip->pwmd_state); } /* interrupt enable : irq 0 is not allowed */ -- 2.30.2
next reply other threads:[~2021-06-18 8:58 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-06-18 8:58 Uwe Kleine-König [this message] 2021-06-18 8:58 ` [PATCH] backlight: lm3630a: convert to atomic PWM API and check for errors Uwe Kleine-König 2021-06-18 10:31 ` Daniel Thompson 2021-06-18 10:31 ` Daniel Thompson 2021-06-18 21:17 ` Uwe Kleine-König
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210618085844.231751-1-u.kleine-koenig@pengutronix.de \ --to=u.kleine-koenig@pengutronix.de \ --cc=daniel.thompson@linaro.org \ --cc=dri-devel@lists.freedesktop.org \ --cc=jingoohan1@gmail.com \ --cc=kernel@pengutronix.de \ --cc=lee.jones@linaro.org \ --cc=linux-fbdev@vger.kernel.org \ --cc=thierry.reding@gmail.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.