UPSTREAM: video / backlight: add two APIs for drivers to use
authorAaron Lu <aaron.lu@intel.com>
Wed, 27 Apr 2016 12:45:02 +0000 (20:45 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Mon, 6 Mar 2017 10:28:40 +0000 (18:28 +0800)
It is useful to get the backlight device's pointer and use it to set
backlight in some cases(the following patch will make use of it) so add
the two APIs and export them.

Signed-off-by: Aaron Lu <aaron.lu@intel.com>
Acked-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
(cherry picked from commit f6a4790a5471d7cba406d87f6b41323f40bb93d2)

Change-Id: Ia7d06bf600f86ae25939b830e49f5057f48f992d
Signed-off-by: David Wu <david.wu@rock-chips.com>
drivers/video/backlight/backlight.c
include/linux/backlight.h

index c2ab0cd0cf71a0533aed062c27afd353922cc1a4..9bf81e03e0d959e9143942b1b81ddd6a9989b99e 100644 (file)
@@ -167,18 +167,10 @@ static ssize_t brightness_show(struct device *dev,
        return sprintf(buf, "%d\n", bd->props.brightness);
 }
 
-static ssize_t brightness_store(struct device *dev,
-               struct device_attribute *attr, const char *buf, size_t count)
+int backlight_device_set_brightness(struct backlight_device *bd,
+                                   unsigned long brightness)
 {
-       int rc;
-       struct backlight_device *bd = to_backlight_device(dev);
-       unsigned long brightness;
-
-       rc = kstrtoul(buf, 0, &brightness);
-       if (rc)
-               return rc;
-
-       rc = -ENXIO;
+       int rc = -ENXIO;
 
        mutex_lock(&bd->ops_lock);
        if (bd->ops) {
@@ -188,7 +180,7 @@ static ssize_t brightness_store(struct device *dev,
                        pr_debug("set brightness to %lu\n", brightness);
                        bd->props.brightness = brightness;
                        backlight_update_status(bd);
-                       rc = count;
+                       rc = 0;
                }
        }
        mutex_unlock(&bd->ops_lock);
@@ -197,6 +189,23 @@ static ssize_t brightness_store(struct device *dev,
 
        return rc;
 }
+EXPORT_SYMBOL(backlight_device_set_brightness);
+
+static ssize_t brightness_store(struct device *dev,
+               struct device_attribute *attr, const char *buf, size_t count)
+{
+       int rc;
+       struct backlight_device *bd = to_backlight_device(dev);
+       unsigned long brightness;
+
+       rc = kstrtoul(buf, 0, &brightness);
+       if (rc)
+               return rc;
+
+       rc = backlight_device_set_brightness(bd, brightness);
+
+       return rc ? rc : count;
+}
 static DEVICE_ATTR_RW(brightness);
 
 static ssize_t type_show(struct device *dev, struct device_attribute *attr,
@@ -383,7 +392,7 @@ struct backlight_device *backlight_device_register(const char *name,
 }
 EXPORT_SYMBOL(backlight_device_register);
 
-bool backlight_device_registered(enum backlight_type type)
+struct backlight_device *backlight_device_get_by_type(enum backlight_type type)
 {
        bool found = false;
        struct backlight_device *bd;
@@ -397,7 +406,13 @@ bool backlight_device_registered(enum backlight_type type)
        }
        mutex_unlock(&backlight_dev_list_mutex);
 
-       return found;
+       return found ? bd : NULL;
+}
+EXPORT_SYMBOL(backlight_device_get_by_type);
+
+bool backlight_device_registered(enum backlight_type type)
+{
+       return backlight_device_get_by_type(type) ? true : false;
 }
 EXPORT_SYMBOL(backlight_device_registered);
 
index 1e7a69adbe6f6992fa955e1c907d0820a224d177..f46b88fa4a098774f58879c9976be4aefb128591 100644 (file)
@@ -144,6 +144,8 @@ extern void backlight_force_update(struct backlight_device *bd,
 extern bool backlight_device_registered(enum backlight_type type);
 extern int backlight_register_notifier(struct notifier_block *nb);
 extern int backlight_unregister_notifier(struct notifier_block *nb);
+extern struct backlight_device *backlight_device_get_by_type(enum backlight_type type);
+extern int backlight_device_set_brightness(struct backlight_device *bd, unsigned long brightness);
 
 #define to_backlight_device(obj) container_of(obj, struct backlight_device, dev)