leds: Improve and export led_update_brightness
authorJacek Anaszewski <j.anaszewski@samsung.com>
Wed, 20 Aug 2014 13:41:55 +0000 (06:41 -0700)
committerBryan Wu <cooloney@gmail.com>
Fri, 12 Sep 2014 21:01:54 +0000 (14:01 -0700)
led_update_brightness helper function used to be exploited only locally
in the led-class.c module, where its result was being passed to the
brightness_show sysfs callback. With the introduction of v4l2-flash
subdevice the same functionality becomes required for reading current
brightness from a LED device. This patch adds checking of return value
of the brightness_get callback and moves the led_update_brightness()
function to the LED subsystem public API.

Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
Acked-by: Kyungmin Park <kyungmin.park@samsung.com>
Cc: Richard Purdie <rpurdie@rpsys.net>
Signed-off-by: Bryan Wu <cooloney@gmail.com>
drivers/leds/led-class.c
drivers/leds/led-core.c
include/linux/leds.h

index 71666a40b79aa3d05f3ce9fbad171f2ee01036ec..7440c58b8e6fd3f729e6fb3381750648c145a6c4 100644 (file)
 
 static struct class *leds_class;
 
-static void led_update_brightness(struct led_classdev *led_cdev)
-{
-       if (led_cdev->brightness_get)
-               led_cdev->brightness = led_cdev->brightness_get(led_cdev);
-}
-
 static ssize_t brightness_show(struct device *dev,
                struct device_attribute *attr, char *buf)
 {
index 50b579ad948e3530cc4cbe184a877ac5c4c9bdf6..aaa8eba9099f4cf1932bae96a4081cc273214876 100644 (file)
@@ -127,3 +127,19 @@ void led_set_brightness(struct led_classdev *led_cdev,
        __led_set_brightness(led_cdev, brightness);
 }
 EXPORT_SYMBOL(led_set_brightness);
+
+int led_update_brightness(struct led_classdev *led_cdev)
+{
+       int ret = 0;
+
+       if (led_cdev->brightness_get) {
+               ret = led_cdev->brightness_get(led_cdev);
+               if (ret >= 0) {
+                       led_cdev->brightness = ret;
+                       return 0;
+               }
+       }
+
+       return ret;
+}
+EXPORT_SYMBOL(led_update_brightness);
index f2e1cbc257059d75951001c2248b8e7cf91a690e..a57611d0c94e147433336fa5277aa755d07076d6 100644 (file)
@@ -140,6 +140,16 @@ extern void led_blink_set_oneshot(struct led_classdev *led_cdev,
  */
 extern void led_set_brightness(struct led_classdev *led_cdev,
                               enum led_brightness brightness);
+/**
+ * led_update_brightness - update LED brightness
+ * @led_cdev: the LED to query
+ *
+ * Get an LED's current brightness and update led_cdev->brightness
+ * member with the obtained value.
+ *
+ * Returns: 0 on success or negative error value on failure
+ */
+extern int led_update_brightness(struct led_classdev *led_cdev);
 
 /*
  * LED Triggers