From: Alban Bedel <alban.bedel@avionic-design.de>
To: Thierry Reding <thierry.reding@avionic-design.de>
Cc: linux-kernel@vger.kernel.org, Richard Purdie <rpurdie@rpsys.net>,
Alban Bedel <alban.bedel@avionic-design.de>
Subject: [PATCH] pwm-backlight: Allow any kind of brightness curve
Date: Wed, 7 Nov 2012 16:14:08 +0100 [thread overview]
Message-ID: <1352301248-8418-1-git-send-email-alban.bedel@avionic-design.de> (raw)
The brightness curve assume that the first level always have a duty
cycle of 0% and the last level 100%. However it is desirable to allow
any kind of curve to handle low-active devices, or devices that need
to clamp the curve to some range.
To allow defining any kind of curve the brightness levels are expected
to be in the range from 0 to 255, where 0 is 0% duty and 255 is 100% duty.
Signed-off-by: Alban Bedel <alban.bedel@avionic-design.de>
---
.../bindings/video/backlight/pwm-backlight.txt | 8 ++---
drivers/video/backlight/pwm_bl.c | 28 +++++++++----------
include/linux/pwm_backlight.h | 2 +
3 files changed, 18 insertions(+), 20 deletions(-)
diff --git a/Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt b/Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt
index 1e4fc72..d0ecbd4 100644
--- a/Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt
+++ b/Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt
@@ -3,11 +3,9 @@ pwm-backlight bindings
Required properties:
- compatible: "pwm-backlight"
- pwms: OF device-tree PWM specification (see PWM binding[0])
- - brightness-levels: Array of distinct brightness levels. Typically these
- are in the range from 0 to 255, but any range starting at 0 will do.
- The actual brightness level (PWM duty cycle) will be interpolated
- from these values. 0 means a 0% duty cycle (darkest/off), while the
- last value in the array represents a 100% duty cycle (brightest).
+ - brightness-levels: Array of distinct brightness levels in the
+ range from 0 to 255. 0 means a 0% duty cycle, while 255
+ represents a 100% duty cycle.
- default-brightness-level: the default brightness level (index into the
array defined by the "brightness-levels" property)
diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index 995f016..09ce501 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -40,6 +40,7 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
struct pwm_bl_data *pb = dev_get_drvdata(&bl->dev);
int brightness = bl->props.brightness;
int max = bl->props.max_brightness;
+ int duty_cycle;
if (bl->props.power != FB_BLANK_UNBLANK)
brightness = 0;
@@ -50,24 +51,21 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
if (pb->notify)
brightness = pb->notify(pb->dev, brightness);
- if (brightness == 0) {
- pwm_config(pb->pwm, 0, pb->period);
- pwm_disable(pb->pwm);
+ if (pb->levels) {
+ duty_cycle = pb->levels[brightness];
+ max = PWM_BL_MAX_LEVEL;
} else {
- int duty_cycle;
+ duty_cycle = brightness;
+ }
- if (pb->levels) {
- duty_cycle = pb->levels[brightness];
- max = pb->levels[max];
- } else {
- duty_cycle = brightness;
- }
+ duty_cycle = pb->lth_brightness +
+ (duty_cycle * (pb->period - pb->lth_brightness) / max);
- duty_cycle = pb->lth_brightness +
- (duty_cycle * (pb->period - pb->lth_brightness) / max);
- pwm_config(pb->pwm, duty_cycle, pb->period);
+ pwm_config(pb->pwm, duty_cycle, pb->period);
+ if (duty_cycle == 0)
+ pwm_disable(pb->pwm);
+ else
pwm_enable(pb->pwm);
- }
if (pb->notify_after)
pb->notify_after(pb->dev, brightness);
@@ -202,7 +200,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
}
if (data->levels) {
- max = data->levels[data->max_brightness];
+ max = PWM_BL_MAX_LEVEL;
pb->levels = data->levels;
} else
max = data->max_brightness;
diff --git a/include/linux/pwm_backlight.h b/include/linux/pwm_backlight.h
index 56f4a86..f5ed046 100644
--- a/include/linux/pwm_backlight.h
+++ b/include/linux/pwm_backlight.h
@@ -6,6 +6,8 @@
#include <linux/backlight.h>
+#define PWM_BL_MAX_LEVEL 255
+
struct platform_pwm_backlight_data {
int pwm_id;
unsigned int max_brightness;
--
1.7.0.4
reply other threads:[~2012-11-07 15:14 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=1352301248-8418-1-git-send-email-alban.bedel@avionic-design.de \
--to=alban.bedel@avionic-design.de \
--cc=linux-kernel@vger.kernel.org \
--cc=rpurdie@rpsys.net \
--cc=thierry.reding@avionic-design.de \
/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
all inboxes | Powered by JetHome®