summaryrefslogtreecommitdiff
path: root/drivers/video
diff options
context:
space:
mode:
authorMike Dunn <mikedunn@newsguy.com>2013-09-22 09:59:56 -0700
committerNitin Garg <nitin.garg@freescale.com>2014-04-16 08:58:17 -0500
commita8b160f1c0a57b57d38001bb795145078f92f01e (patch)
tree34910af614005c2ae595cbd980833387c67cf6d9 /drivers/video
parent958f652dd6f28d558205d449fd44d90ce4ee0621 (diff)
pwm-backlight: Allow for non-increasing brightness levels
Currently the driver assumes that the values specified in the brightness-levels device tree property increase as they are parsed from left to right. But boards that invert the signal between the PWM output and the backlight will need to specify decreasing brightness-levels. This patch removes the assumption that the last element of the array is the maximum value, and instead searches the array for the maximum value and uses that in the duty cycle calculation. Signed-off-by: Mike Dunn <mikedunn@newsguy.com> Signed-off-by: Thierry Reding <treding@nvidia.com> (cherry picked from commit 8f43e18e2769b3b28383903d501b4da29e388aad) Conflicts: drivers/video/backlight/pwm_bl.c
Diffstat (limited to 'drivers/video')
-rw-r--r--drivers/video/backlight/pwm_bl.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/drivers/video/backlight/pwm_bl.c b/drivers/video/backlight/pwm_bl.c
index 18b885497289..65b63961d3fd 100644
--- a/drivers/video/backlight/pwm_bl.c
+++ b/drivers/video/backlight/pwm_bl.c
@@ -32,6 +32,7 @@ struct pwm_bl_data {
bool enabled;
int enable_gpio;
unsigned long enable_gpio_flags;
+ unsigned int scale;
int (*notify)(struct device *,
int brightness);
void (*notify_after)(struct device *,
@@ -41,23 +42,20 @@ struct pwm_bl_data {
const char *fb_names[FB_MAX];
};
-static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness,
- int max)
+static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness)
{
+ unsigned int lth = pb->lth_brightness;
int duty_cycle, err;
if (pb->enabled)
return;
- if (pb->levels) {
+ if (pb->levels)
duty_cycle = pb->levels[brightness];
- max = pb->levels[max];
- } else {
+ else
duty_cycle = brightness;
- }
- duty_cycle = (duty_cycle * (pb->period - pb->lth_brightness) / max) +
- pb->lth_brightness;
+ duty_cycle = (duty_cycle * (pb->period - lth) / pb->scale) + lth;
pwm_config(pb->pwm, duty_cycle, pb->period);
@@ -94,7 +92,6 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
{
struct pwm_bl_data *pb = bl_get_data(bl);
int brightness = bl->props.brightness;
- int max = bl->props.max_brightness;
if (bl->props.power != FB_BLANK_UNBLANK ||
bl->props.fb_blank != FB_BLANK_UNBLANK ||
@@ -105,7 +102,7 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
brightness = pb->notify(pb->dev, brightness);
if (brightness > 0)
- pwm_backlight_power_on(pb, brightness, max);
+ pwm_backlight_power_on(pb, brightness);
else
pwm_backlight_power_off(pb);
@@ -233,7 +230,6 @@ static int pwm_backlight_probe(struct platform_device *pdev)
struct backlight_properties props;
struct backlight_device *bl;
struct pwm_bl_data *pb;
- unsigned int max;
int ret, index;
if (!data) {
@@ -269,10 +265,15 @@ static int pwm_backlight_probe(struct platform_device *pdev)
}
if (data->levels) {
- max = data->levels[data->max_brightness];
+ unsigned int i;
+
+ for (i = 0; i <= data->max_brightness; i++)
+ if (data->levels[i] > pb->scale)
+ pb->scale = data->levels[i];
+
pb->levels = data->levels;
} else
- max = data->max_brightness;
+ pb->scale = data->max_brightness;
pb->enable_gpio = data->enable_gpio;
pb->enable_gpio_flags = data->enable_gpio_flags;
@@ -322,7 +323,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
pwm_set_period(pb->pwm, data->pwm_period_ns);
pb->period = pwm_get_period(pb->pwm);
- pb->lth_brightness = data->lth_brightness * (pb->period / max);
+ pb->lth_brightness = data->lth_brightness * (pb->period / pb->scale);
memset(&props, 0, sizeof(struct backlight_properties));
props.type = BACKLIGHT_RAW;