Commit 8f43e18e authored by Mike Dunn's avatar Mike Dunn Committed by Thierry Reding

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: default avatarMike Dunn <mikedunn@newsguy.com>
Signed-off-by: default avatarThierry Reding <treding@nvidia.com>
parent 22ceeee1
...@@ -34,6 +34,7 @@ struct pwm_bl_data { ...@@ -34,6 +34,7 @@ struct pwm_bl_data {
struct regulator *power_supply; struct regulator *power_supply;
int enable_gpio; int enable_gpio;
unsigned long enable_gpio_flags; unsigned long enable_gpio_flags;
unsigned int scale;
int (*notify)(struct device *, int (*notify)(struct device *,
int brightness); int brightness);
void (*notify_after)(struct device *, void (*notify_after)(struct device *,
...@@ -42,23 +43,20 @@ struct pwm_bl_data { ...@@ -42,23 +43,20 @@ struct pwm_bl_data {
void (*exit)(struct device *); void (*exit)(struct device *);
}; };
static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness, static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness)
int max)
{ {
unsigned int lth = pb->lth_brightness;
int duty_cycle, err; int duty_cycle, err;
if (pb->enabled) if (pb->enabled)
return; return;
if (pb->levels) { if (pb->levels)
duty_cycle = pb->levels[brightness]; duty_cycle = pb->levels[brightness];
max = pb->levels[max]; else
} else {
duty_cycle = brightness; duty_cycle = brightness;
}
duty_cycle = (duty_cycle * (pb->period - pb->lth_brightness) / max) + duty_cycle = (duty_cycle * (pb->period - lth) / pb->scale) + lth;
pb->lth_brightness;
pwm_config(pb->pwm, duty_cycle, pb->period); pwm_config(pb->pwm, duty_cycle, pb->period);
...@@ -100,7 +98,6 @@ static int pwm_backlight_update_status(struct backlight_device *bl) ...@@ -100,7 +98,6 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
{ {
struct pwm_bl_data *pb = bl_get_data(bl); struct pwm_bl_data *pb = bl_get_data(bl);
int brightness = bl->props.brightness; int brightness = bl->props.brightness;
int max = bl->props.max_brightness;
if (bl->props.power != FB_BLANK_UNBLANK || if (bl->props.power != FB_BLANK_UNBLANK ||
bl->props.fb_blank != FB_BLANK_UNBLANK || bl->props.fb_blank != FB_BLANK_UNBLANK ||
...@@ -111,7 +108,7 @@ static int pwm_backlight_update_status(struct backlight_device *bl) ...@@ -111,7 +108,7 @@ static int pwm_backlight_update_status(struct backlight_device *bl)
brightness = pb->notify(pb->dev, brightness); brightness = pb->notify(pb->dev, brightness);
if (brightness > 0) if (brightness > 0)
pwm_backlight_power_on(pb, brightness, max); pwm_backlight_power_on(pb, brightness);
else else
pwm_backlight_power_off(pb); pwm_backlight_power_off(pb);
...@@ -218,7 +215,6 @@ static int pwm_backlight_probe(struct platform_device *pdev) ...@@ -218,7 +215,6 @@ static int pwm_backlight_probe(struct platform_device *pdev)
struct backlight_properties props; struct backlight_properties props;
struct backlight_device *bl; struct backlight_device *bl;
struct pwm_bl_data *pb; struct pwm_bl_data *pb;
unsigned int max;
int ret; int ret;
if (!data) { if (!data) {
...@@ -245,10 +241,15 @@ static int pwm_backlight_probe(struct platform_device *pdev) ...@@ -245,10 +241,15 @@ static int pwm_backlight_probe(struct platform_device *pdev)
} }
if (data->levels) { 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; pb->levels = data->levels;
} else } else
max = data->max_brightness; pb->scale = data->max_brightness;
pb->enable_gpio = data->enable_gpio; pb->enable_gpio = data->enable_gpio;
pb->enable_gpio_flags = data->enable_gpio_flags; pb->enable_gpio_flags = data->enable_gpio_flags;
...@@ -304,7 +305,7 @@ static int pwm_backlight_probe(struct platform_device *pdev) ...@@ -304,7 +305,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
pwm_set_period(pb->pwm, data->pwm_period_ns); pwm_set_period(pb->pwm, data->pwm_period_ns);
pb->period = pwm_get_period(pb->pwm); 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)); memset(&props, 0, sizeof(struct backlight_properties));
props.type = BACKLIGHT_RAW; props.type = BACKLIGHT_RAW;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment