CHROMIUM: drivers/backlight: allow setting a resume_brightness
authorStéphane Marchesin <marcheu@chromium.org>
Tue, 13 Nov 2012 01:31:44 +0000 (17:31 -0800)
committerChromeBot <chrome-bot@google.com>
Thu, 10 Jan 2013 01:12:21 +0000 (17:12 -0800)
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 <marcheu@chromium.org>
[olofj: added reference to testcase bug and fixed checkpatch error]
Signed-off-by: Olof Johansson <olofj@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/37974

drivers/video/backlight/backlight.c
include/linux/backlight.h

index bf5b1ec..49af059 100644 (file)
@@ -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) {
index 5ffc6dd..c1707b6 100644 (file)
@@ -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