leds: core: Drivers shouldn't enforce SYNC/ASYNC brightness setting
authorJacek Anaszewski <j.anaszewski@samsung.com>
Wed, 7 Oct 2015 09:10:43 +0000 (11:10 +0200)
committerJacek Anaszewski <j.anaszewski@samsung.com>
Mon, 4 Jan 2016 08:57:31 +0000 (09:57 +0100)
This patch removes SET_BRIGHTNESS_ASYNC and SET_BRIGHTNESS_SYNC flags.
led_set_brightness() now calls led_set_brightness_nosleep() instead of
choosing between sync and async op basing on the flags defined by the
driver.

From now on, if a user wants to make sure that brightness will be set
synchronously, they have to use led_set_brightness_sync() API. It is now
being made publicly available since it has become apparent that it is
a caller who should decide whether brightness is to be set in
a synchronous or an asynchronous way.

Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
Acked-by: Sakari Ailus <sakari.ailus@linux.intel.com>
drivers/leds/led-class-flash.c
drivers/leds/led-class.c
drivers/leds/led-core.c
drivers/leds/leds.h
include/linux/leds.h

index 300a2c9007cac4465cd77cbceeb9a3b4af88e5b5..f53783b8d5e8bc0914d5fd2971be52c1526f3f0e 100644 (file)
@@ -316,10 +316,6 @@ int led_classdev_flash_register(struct device *parent,
        if (ret < 0)
                return ret;
 
-       /* Setting a torch brightness needs to have immediate effect */
-       led_cdev->flags &= ~SET_BRIGHTNESS_ASYNC;
-       led_cdev->flags |= SET_BRIGHTNESS_SYNC;
-
        return 0;
 }
 EXPORT_SYMBOL_GPL(led_classdev_flash_register);
index 83a1dc7258646fa961a59926ce07b382d04e7baf..d946991091fb50d551bc37b3407cb5adf47550f9 100644 (file)
@@ -215,8 +215,6 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
        if (!led_cdev->max_brightness)
                led_cdev->max_brightness = LED_FULL;
 
-       led_cdev->flags |= SET_BRIGHTNESS_ASYNC;
-
        led_update_brightness(led_cdev);
 
        led_init_core(led_cdev);
index f57a96cb7b7d0017fed9d1902cb9014235b06d23..19e1e60dfaa354585ca01e2ffdc2a47f29c49c3b 100644 (file)
@@ -205,8 +205,6 @@ EXPORT_SYMBOL_GPL(led_stop_software_blink);
 void led_set_brightness(struct led_classdev *led_cdev,
                        enum led_brightness brightness)
 {
-       int ret = 0;
-
        /*
         * In case blinking is on delay brightness setting
         * until the next timer tick.
@@ -227,17 +225,7 @@ void led_set_brightness(struct led_classdev *led_cdev,
                return;
        }
 
-       if (led_cdev->flags & SET_BRIGHTNESS_ASYNC) {
-               led_set_brightness_nosleep(led_cdev, brightness);
-               return;
-       } else if (led_cdev->flags & SET_BRIGHTNESS_SYNC)
-               ret = led_set_brightness_sync(led_cdev, brightness);
-       else
-               ret = -EINVAL;
-
-       if (ret < 0)
-               dev_dbg(led_cdev->dev, "Setting LED brightness failed (%d)\n",
-                       ret);
+       led_set_brightness_nosleep(led_cdev, brightness);
 }
 EXPORT_SYMBOL_GPL(led_set_brightness);
 
@@ -268,6 +256,24 @@ void led_set_brightness_nosleep(struct led_classdev *led_cdev,
 }
 EXPORT_SYMBOL_GPL(led_set_brightness_nosleep);
 
+int led_set_brightness_sync(struct led_classdev *led_cdev,
+                           enum led_brightness value)
+{
+       if (led_cdev->blink_delay_on || led_cdev->blink_delay_off)
+               return -EBUSY;
+
+       led_cdev->brightness = min(value, led_cdev->max_brightness);
+
+       if (led_cdev->flags & LED_SUSPENDED)
+               return 0;
+
+       if (led_cdev->brightness_set_blocking)
+               return led_cdev->brightness_set_blocking(led_cdev,
+                                                        led_cdev->brightness);
+       return -ENOTSUPP;
+}
+EXPORT_SYMBOL_GPL(led_set_brightness_sync);
+
 int led_update_brightness(struct led_classdev *led_cdev)
 {
        int ret = 0;
index 683a605fd33c40590b502da638225b654c9412f4..db3f20da7221738920bf49bd35fbc13b1768e65d 100644 (file)
 #include <linux/rwsem.h>
 #include <linux/leds.h>
 
-static inline int led_set_brightness_sync(struct led_classdev *led_cdev,
-                                       enum led_brightness value)
-{
-       int ret = 0;
-
-       led_cdev->brightness = min(value, led_cdev->max_brightness);
-
-       if (!(led_cdev->flags & LED_SUSPENDED))
-               ret = led_cdev->brightness_set_blocking(led_cdev,
-                                               led_cdev->brightness);
-       return ret;
-}
-
 static inline int led_get_brightness(struct led_classdev *led_cdev)
 {
        return led_cdev->brightness;
index b35e0f5b8d6c1380a2c3c8878eba4798e7d3cd1c..088f1da02beda06d08abb07426c570edbf6c8fb9 100644 (file)
@@ -47,9 +47,7 @@ struct led_classdev {
 #define LED_BLINK_BRIGHTNESS_CHANGE (1 << 20)
 #define LED_BLINK_DISABLE      (1 << 21)
 #define LED_SYSFS_DISABLE      (1 << 22)
-#define SET_BRIGHTNESS_ASYNC   (1 << 23)
-#define SET_BRIGHTNESS_SYNC    (1 << 24)
-#define LED_DEV_CAP_FLASH      (1 << 25)
+#define LED_DEV_CAP_FLASH      (1 << 23)
 
        /* Set LED brightness level */
        /* Must not sleep, use a workqueue if needed */
@@ -162,6 +160,21 @@ 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_set_brightness_sync - set LED brightness synchronously
+ * @led_cdev: the LED to set
+ * @brightness: the brightness to set it to
+ *
+ * Set an LED's brightness immediately. This function will block
+ * the caller for the time required for accessing device registers,
+ * and it can sleep.
+ *
+ * Returns: 0 on success or negative error value on failure
+ */
+extern int led_set_brightness_sync(struct led_classdev *led_cdev,
+                                  enum led_brightness value);
+
 /**
  * led_update_brightness - update LED brightness
  * @led_cdev: the LED to query