mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <ahmad@a3f.at>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 08/12] video: backlight-pwm: use new pwm_apply_state API
Date: Mon, 30 Mar 2020 16:57:13 +0200	[thread overview]
Message-ID: <20200330145717.667403-9-ahmad@a3f.at> (raw)
In-Reply-To: <20200330145717.667403-1-ahmad@a3f.at>

From: Ahmad Fatoum <a.fatoum@pengutronix.de>

Use pwm_apply_state we can avoid having to store PWM state in the
instance structure and in future we have an easy way to support new
parameters like inverted duty cycle.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 drivers/video/backlight-pwm.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/video/backlight-pwm.c b/drivers/video/backlight-pwm.c
index 9111a42d7544..8b6494dac929 100644
--- a/drivers/video/backlight-pwm.c
+++ b/drivers/video/backlight-pwm.c
@@ -33,7 +33,6 @@ struct pwm_backlight {
 	struct backlight_device backlight;
 	struct pwm_device *pwm;
 	struct regulator *power;
-	uint32_t period;
 	unsigned int *levels;
 	int enable_gpio;
 	int enable_active_high;
@@ -91,13 +90,16 @@ static int backlight_pwm_disable(struct pwm_backlight *pwm_backlight)
 static int compute_duty_cycle(struct pwm_backlight *pwm_backlight, int brightness)
 {
 	int duty_cycle;
+	struct pwm_state state;
+
+	pwm_get_state(pwm_backlight->pwm, &state);
 
 	if (pwm_backlight->levels)
 		duty_cycle = pwm_backlight->levels[brightness];
 	else
 		duty_cycle = brightness;
 
-	return duty_cycle * pwm_backlight->period / pwm_backlight->scale;
+	return duty_cycle * state.period_ns / pwm_backlight->scale;
 }
 
 static int backlight_pwm_set(struct backlight_device *backlight,
@@ -105,9 +107,11 @@ static int backlight_pwm_set(struct backlight_device *backlight,
 {
 	struct pwm_backlight *pwm_backlight = container_of(backlight,
 			struct pwm_backlight, backlight);
+	struct pwm_state state;
 
-	pwm_config(pwm_backlight->pwm, compute_duty_cycle(pwm_backlight, brightness),
-		   pwm_backlight->period);
+	pwm_get_state(pwm_backlight->pwm, &state);
+	state.duty_ns = compute_duty_cycle(pwm_backlight, brightness);
+	pwm_apply_state(pwm_backlight->pwm, &state);
 
 	if (brightness)
 		return backlight_pwm_enable(pwm_backlight);
@@ -192,7 +196,6 @@ static int backlight_pwm_of_probe(struct device_d *dev)
 
 	pwm_backlight = xzalloc(sizeof(*pwm_backlight));
 	pwm_backlight->pwm = pwm;
-	pwm_backlight->period = pwm_get_period(pwm);
 
 	ret = pwm_backlight_parse_dt(dev, pwm_backlight);
 	if (ret)
-- 
2.20.1


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2020-03-30 14:57 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-30 14:57 [PATCH 00/12] PWM: add support for ->apply, polarity and STM32 Ahmad Fatoum
2020-03-30 14:57 ` [PATCH 01/12] led: pwm: always initialize PWM LEDs as inactive Ahmad Fatoum
2020-03-30 14:57 ` [PATCH 02/12] PWM: core: remove FLAG_ENABLED Ahmad Fatoum
2020-03-30 14:57 ` [PATCH 03/12] PWM: core: remove ineffectual pwm_{set,get}_duty_cycle Ahmad Fatoum
2020-03-30 14:57 ` [PATCH 04/12] PWM: core: group PWM state into new struct pwm_state Ahmad Fatoum
2020-03-30 14:57 ` [PATCH 05/12] PWM: core: remove old PWM API in favor of Linux ->apply Ahmad Fatoum
2020-03-30 14:57 ` [PATCH 06/12] PWM: core: retire pwm_set_period Ahmad Fatoum
2020-03-30 14:57 ` [PATCH 07/12] PWM: core: apply initial state in of_pwm_request Ahmad Fatoum
2020-03-30 14:57 ` Ahmad Fatoum [this message]
2020-03-31  6:10   ` [PATCH 08/12] video: backlight-pwm: use new pwm_apply_state API Sascha Hauer
2020-03-31  6:54     ` Ahmad Fatoum
2020-03-31  7:49       ` Sascha Hauer
2020-03-30 14:57 ` [PATCH 09/12] led: pwm: " Ahmad Fatoum
2020-03-30 14:57 ` [PATCH 10/12] PWM: core: add apply API support for polarity Ahmad Fatoum
2020-03-30 14:57 ` [PATCH 11/12] of: introduce of_property_count_elems_of_size Ahmad Fatoum
2020-03-30 14:57 ` [PATCH 12/12] PWM: add support for STM32 Ahmad Fatoum
2020-03-31  6:41   ` Sascha Hauer
2020-03-31  6:49     ` Ahmad Fatoum
2020-03-31  7:49       ` Sascha Hauer

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=20200330145717.667403-9-ahmad@a3f.at \
    --to=ahmad@a3f.at \
    --cc=a.fatoum@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox