Skip to content

Commit

Permalink
pwm-backlight: Track enable state
Browse files Browse the repository at this point in the history
Follow up patches will add support for more complex means of powering
the backlight on and off such as using a regulator. To prevent calls to
the regulator API from becoming unbalanced, keep track of the enabled
state internally.

Signed-off-by: Thierry Reding <treding@nvidia.com>
  • Loading branch information
Thierry Reding authored and Thierry Reding committed Oct 16, 2013
1 parent 62b744a commit 97c3843
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions drivers/video/backlight/pwm_bl.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ struct pwm_bl_data {
unsigned int period;
unsigned int lth_brightness;
unsigned int *levels;
bool enabled;
int (*notify)(struct device *,
int brightness);
void (*notify_after)(struct device *,
Expand All @@ -40,6 +41,9 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness,
{
int duty_cycle, err;

if (pb->enabled)
return;

if (pb->levels) {
duty_cycle = pb->levels[brightness];
max = pb->levels[max];
Expand All @@ -52,12 +56,18 @@ static void pwm_backlight_power_on(struct pwm_bl_data *pb, int brightness,

pwm_config(pb->pwm, duty_cycle, pb->period);
pwm_enable(pb->pwm);
pb->enabled = true;
}

static void pwm_backlight_power_off(struct pwm_bl_data *pb)
{
if (!pb->enabled)
return;

pwm_config(pb->pwm, 0, pb->period);
pwm_disable(pb->pwm);

pb->enabled = false;
}

static int pwm_backlight_update_status(struct backlight_device *bl)
Expand Down Expand Up @@ -216,6 +226,7 @@ static int pwm_backlight_probe(struct platform_device *pdev)
pb->check_fb = data->check_fb;
pb->exit = data->exit;
pb->dev = &pdev->dev;
pb->enabled = false;

pb->pwm = devm_pwm_get(&pdev->dev, NULL);
if (IS_ERR(pb->pwm)) {
Expand Down

0 comments on commit 97c3843

Please sign in to comment.