mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH] video: pwm-backlight: Honour discrete brightness levels from dt
Date: Mon, 23 Nov 2015 09:51:11 +0100	[thread overview]
Message-ID: <1448268672-26204-1-git-send-email-s.hauer@pengutronix.de> (raw)

If probed from device tree we have an array of pwm duty cycle levels
in the brightness-levels property. Although the driver parsed the property,
the values have been ignored. Make use of these flags so that the driver
can work for example with inverted PWMs.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/video/backlight-pwm.c | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)

diff --git a/drivers/video/backlight-pwm.c b/drivers/video/backlight-pwm.c
index ba6f9bc..91435f8 100644
--- a/drivers/video/backlight-pwm.c
+++ b/drivers/video/backlight-pwm.c
@@ -39,6 +39,7 @@ struct pwm_backlight {
 	int enable_active_high;
 	int max_value;
 	int enabled;
+	unsigned int scale;
 };
 
 static int backlight_pwm_enable(struct pwm_backlight *pwm_backlight)
@@ -87,18 +88,26 @@ static int backlight_pwm_disable(struct pwm_backlight *pwm_backlight)
 	return 0;
 }
 
+static int compute_duty_cycle(struct pwm_backlight *pwm_backlight, int brightness)
+{
+	int duty_cycle;
+
+	if (pwm_backlight->levels)
+		duty_cycle = pwm_backlight->levels[brightness];
+	else
+		duty_cycle = brightness;
+
+	return duty_cycle * pwm_backlight->period / pwm_backlight->scale;
+}
+
 static int backlight_pwm_set(struct backlight_device *backlight,
 		int brightness)
 {
 	struct pwm_backlight *pwm_backlight = container_of(backlight,
 			struct pwm_backlight, backlight);
-	unsigned long long duty =  pwm_backlight->period;
-	unsigned int max = pwm_backlight->backlight.brightness_max;
-
-	duty *= brightness;
-	do_div(duty, max);
 
-	pwm_config(pwm_backlight->pwm, duty, pwm_backlight->period);
+	pwm_config(pwm_backlight->pwm, compute_duty_cycle(pwm_backlight, brightness),
+		   pwm_backlight->period);
 
 	if (brightness)
 		return backlight_pwm_enable(pwm_backlight);
@@ -113,7 +122,7 @@ static int pwm_backlight_parse_dt(struct device_d *dev,
 	struct property *prop;
 	int length;
 	u32 value;
-	int ret;
+	int ret, i;
 	enum of_gpio_flags flags;
 
 	if (!node)
@@ -141,6 +150,10 @@ static int pwm_backlight_parse_dt(struct device_d *dev,
 		if (ret < 0)
 			return ret;
 
+		for (i = 0; i <=  pwm_backlight->backlight.brightness_max; i++)
+			if (pwm_backlight->levels[i] > pwm_backlight->scale)
+				pwm_backlight->scale = pwm_backlight->levels[i];
+
 		ret = of_property_read_u32(node, "default-brightness-level",
 					   &value);
 		if (ret < 0)
-- 
2.6.2


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

                 reply	other threads:[~2015-11-23  8:51 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=1448268672-26204-1-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@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