lkml.org 
[lkml]   [2012]   [Nov]   [7]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] pwm-backlight: Allow any kind of brightness curve
Date
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


\
 
 \ /
  Last update: 2012-11-07 18:01    [W:0.026 / U:0.476 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site