pwm-backlight: Allow any kind of brightness curve
Subsystems (3)
PATCH 1/1 pwm-backlight: Allow any kind of brightness curve
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 <[email protected]>
--- .../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(-)
Documentation/devicetree/bindings/video/backlight/pwm-backlight.txt +3 -5
@@ -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)
drivers/video/backlight/pwm_bl.c +13 -15
@@ -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;
include/linux/pwm_backlight.h +2 -0
@@ -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;
Signature · 1 line
1.7.0.4