From 6dab5ebe0bbeda03abbfcb20407e82e268a2a617 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Marchesin?= Date: Mon, 12 Nov 2012 17:31:44 -0800 Subject: [PATCH] CHROMIUM: drivers/backlight: allow setting a resume_brightness MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This lets us set a resume-time backlight value. BUG=chrome-os-partner:13364 TEST=by hand; automated testcase tracked in crosbug.com/36747 Change-Id: I59ebea1ba3fa59beccdce0970a0e846ee858062c Signed-off-by: Stéphane Marchesin [olofj: added reference to testcase bug and fixed checkpatch error] Signed-off-by: Olof Johansson Reviewed-on: https://gerrit.chromium.org/gerrit/37974 --- drivers/video/backlight/backlight.c | 45 ++++++++++++++++++++++++++++- include/linux/backlight.h | 2 ++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/drivers/video/backlight/backlight.c b/drivers/video/backlight/backlight.c index bf5b1ece71605..49af059629f2a 100644 --- a/drivers/video/backlight/backlight.c +++ b/drivers/video/backlight/backlight.c @@ -175,6 +175,43 @@ static ssize_t backlight_store_brightness(struct device *dev, return rc; } +static ssize_t backlight_show_resume_brightness(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct backlight_device *bd = to_backlight_device(dev); + + return sprintf(buf, "%d\n", bd->props.resume_brightness); +} + +static ssize_t backlight_store_resume_brightness(struct device *dev, + struct device_attribute *attr, const char *buf, size_t count) +{ + int rc; + struct backlight_device *bd = to_backlight_device(dev); + long resume_brightness; + + rc = kstrtol(buf, 0, &resume_brightness); + if (rc) + return rc; + + rc = -ENXIO; + + mutex_lock(&bd->ops_lock); + if (bd->ops) { + if (resume_brightness > bd->props.max_brightness) + rc = -EINVAL; + else { + pr_debug("backlight: set resume_brightness to %ld\n", + resume_brightness); + bd->props.resume_brightness = resume_brightness; + rc = count; + } + } + mutex_unlock(&bd->ops_lock); + + return rc; +} + static ssize_t backlight_show_type(struct device *dev, struct device_attribute *attr, char *buf) { @@ -226,8 +263,11 @@ static int backlight_resume(struct device *dev) struct backlight_device *bd = to_backlight_device(dev); mutex_lock(&bd->ops_lock); - if (bd->ops && bd->ops->options & BL_CORE_SUSPENDRESUME) { + if ((bd->ops && bd->ops->options & BL_CORE_SUSPENDRESUME) || + bd->props.resume_brightness != -1) { bd->props.state &= ~BL_CORE_SUSPENDED; + if (bd->props.resume_brightness != -1) + bd->props.brightness = bd->props.resume_brightness; backlight_update_status(bd); } mutex_unlock(&bd->ops_lock); @@ -245,6 +285,8 @@ static struct device_attribute bl_device_attributes[] = { __ATTR(bl_power, 0644, backlight_show_power, backlight_store_power), __ATTR(brightness, 0644, backlight_show_brightness, backlight_store_brightness), + __ATTR(resume_brightness, 0644, backlight_show_resume_brightness, + backlight_store_resume_brightness), __ATTR(actual_brightness, 0444, backlight_show_actual_brightness, NULL), __ATTR(max_brightness, 0444, backlight_show_max_brightness, NULL), @@ -317,6 +359,7 @@ struct backlight_device *backlight_device_register(const char *name, } else { new_bd->props.type = BACKLIGHT_RAW; } + new_bd->props.resume_brightness = -1; rc = device_register(&new_bd->dev); if (rc) { diff --git a/include/linux/backlight.h b/include/linux/backlight.h index 5ffc6dda46751..c1707b696dd61 100644 --- a/include/linux/backlight.h +++ b/include/linux/backlight.h @@ -61,6 +61,8 @@ struct backlight_ops { struct backlight_properties { /* Current User requested brightness (0 - max_brightness) */ int brightness; + /* The brightness at resume (0 - max_brightness, -1 to disable) */ + int resume_brightness; /* Maximal value for brightness (read-only) */ int max_brightness; /* Current FB Power mode (0: full on, 1..3: power saving -- 2.39.5