leds: core: Move LED core callbacks out of led-class.c
authorJacek Anaszewski <j.anaszewski@samsung.com>
Mon, 28 Sep 2015 12:38:04 +0000 (14:38 +0200)
committerJacek Anaszewski <j.anaszewski@samsung.com>
Tue, 3 Nov 2015 07:59:22 +0000 (08:59 +0100)
Since the API for controlling LED brightness and blinking is defined in
the LED core, move the related timer and work callbacks to the led-core.c,
and initialize them through a new led_core_init API.

Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
Acked-by: Andrew Lunn <andrew@lunn.ch>
Acked-by: Pavel Machek <pavel@ucw.cz>
drivers/leds/led-class.c
drivers/leds/led-core.c
drivers/leds/leds.h

index ca51d58bed244c488d815003c366d03acf79e418..7385f98dd54b4b42cf7e430b94952150b979827b 100644 (file)
@@ -102,70 +102,6 @@ static const struct attribute_group *led_groups[] = {
        NULL,
 };
 
-static void led_timer_function(unsigned long data)
-{
-       struct led_classdev *led_cdev = (void *)data;
-       unsigned long brightness;
-       unsigned long delay;
-
-       if (!led_cdev->blink_delay_on || !led_cdev->blink_delay_off) {
-               led_set_brightness_async(led_cdev, LED_OFF);
-               return;
-       }
-
-       if (led_cdev->flags & LED_BLINK_ONESHOT_STOP) {
-               led_cdev->flags &= ~LED_BLINK_ONESHOT_STOP;
-               return;
-       }
-
-       brightness = led_get_brightness(led_cdev);
-       if (!brightness) {
-               /* Time to switch the LED on. */
-               if (led_cdev->delayed_set_value) {
-                       led_cdev->blink_brightness =
-                                       led_cdev->delayed_set_value;
-                       led_cdev->delayed_set_value = 0;
-               }
-               brightness = led_cdev->blink_brightness;
-               delay = led_cdev->blink_delay_on;
-       } else {
-               /* Store the current brightness value to be able
-                * to restore it when the delay_off period is over.
-                */
-               led_cdev->blink_brightness = brightness;
-               brightness = LED_OFF;
-               delay = led_cdev->blink_delay_off;
-       }
-
-       led_set_brightness_async(led_cdev, brightness);
-
-       /* Return in next iteration if led is in one-shot mode and we are in
-        * the final blink state so that the led is toggled each delay_on +
-        * delay_off milliseconds in worst case.
-        */
-       if (led_cdev->flags & LED_BLINK_ONESHOT) {
-               if (led_cdev->flags & LED_BLINK_INVERT) {
-                       if (brightness)
-                               led_cdev->flags |= LED_BLINK_ONESHOT_STOP;
-               } else {
-                       if (!brightness)
-                               led_cdev->flags |= LED_BLINK_ONESHOT_STOP;
-               }
-       }
-
-       mod_timer(&led_cdev->blink_timer, jiffies + msecs_to_jiffies(delay));
-}
-
-static void set_brightness_delayed(struct work_struct *ws)
-{
-       struct led_classdev *led_cdev =
-               container_of(ws, struct led_classdev, set_brightness_work);
-
-       led_stop_software_blink(led_cdev);
-
-       led_set_brightness_async(led_cdev, led_cdev->delayed_set_value);
-}
-
 /**
  * led_classdev_suspend - suspend an led_classdev.
  * @led_cdev: the led_classdev to suspend.
@@ -283,10 +219,7 @@ int led_classdev_register(struct device *parent, struct led_classdev *led_cdev)
 
        led_update_brightness(led_cdev);
 
-       INIT_WORK(&led_cdev->set_brightness_work, set_brightness_delayed);
-
-       setup_timer(&led_cdev->blink_timer, led_timer_function,
-                   (unsigned long)led_cdev);
+       led_init_core(led_cdev);
 
 #ifdef CONFIG_LEDS_TRIGGERS
        led_trigger_set_default(led_cdev);
index 549de7e24cfdf445f27180ab7c776da21af50a94..c1c3af089634cded4f27fd8e6397a9519025ad70 100644 (file)
@@ -25,6 +25,70 @@ EXPORT_SYMBOL_GPL(leds_list_lock);
 LIST_HEAD(leds_list);
 EXPORT_SYMBOL_GPL(leds_list);
 
+static void led_timer_function(unsigned long data)
+{
+       struct led_classdev *led_cdev = (void *)data;
+       unsigned long brightness;
+       unsigned long delay;
+
+       if (!led_cdev->blink_delay_on || !led_cdev->blink_delay_off) {
+               led_set_brightness_async(led_cdev, LED_OFF);
+               return;
+       }
+
+       if (led_cdev->flags & LED_BLINK_ONESHOT_STOP) {
+               led_cdev->flags &= ~LED_BLINK_ONESHOT_STOP;
+               return;
+       }
+
+       brightness = led_get_brightness(led_cdev);
+       if (!brightness) {
+               /* Time to switch the LED on. */
+               if (led_cdev->delayed_set_value) {
+                       led_cdev->blink_brightness =
+                                       led_cdev->delayed_set_value;
+                       led_cdev->delayed_set_value = 0;
+               }
+               brightness = led_cdev->blink_brightness;
+               delay = led_cdev->blink_delay_on;
+       } else {
+               /* Store the current brightness value to be able
+                * to restore it when the delay_off period is over.
+                */
+               led_cdev->blink_brightness = brightness;
+               brightness = LED_OFF;
+               delay = led_cdev->blink_delay_off;
+       }
+
+       led_set_brightness_async(led_cdev, brightness);
+
+       /* Return in next iteration if led is in one-shot mode and we are in
+        * the final blink state so that the led is toggled each delay_on +
+        * delay_off milliseconds in worst case.
+        */
+       if (led_cdev->flags & LED_BLINK_ONESHOT) {
+               if (led_cdev->flags & LED_BLINK_INVERT) {
+                       if (brightness)
+                               led_cdev->flags |= LED_BLINK_ONESHOT_STOP;
+               } else {
+                       if (!brightness)
+                               led_cdev->flags |= LED_BLINK_ONESHOT_STOP;
+               }
+       }
+
+       mod_timer(&led_cdev->blink_timer, jiffies + msecs_to_jiffies(delay));
+}
+
+static void set_brightness_delayed(struct work_struct *ws)
+{
+       struct led_classdev *led_cdev =
+               container_of(ws, struct led_classdev, set_brightness_work);
+
+       led_stop_software_blink(led_cdev);
+
+       led_set_brightness_async(led_cdev, led_cdev->delayed_set_value);
+}
+
 static void led_set_software_blink(struct led_classdev *led_cdev,
                                   unsigned long delay_on,
                                   unsigned long delay_off)
@@ -72,6 +136,15 @@ static void led_blink_setup(struct led_classdev *led_cdev,
        led_set_software_blink(led_cdev, *delay_on, *delay_off);
 }
 
+void led_init_core(struct led_classdev *led_cdev)
+{
+       INIT_WORK(&led_cdev->set_brightness_work, set_brightness_delayed);
+
+       setup_timer(&led_cdev->blink_timer, led_timer_function,
+                   (unsigned long)led_cdev);
+}
+EXPORT_SYMBOL_GPL(led_init_core);
+
 void led_blink_set(struct led_classdev *led_cdev,
                   unsigned long *delay_on,
                   unsigned long *delay_off)
index bc89d7ace2c44e48b1e4c318dc53103767eba942..4238fbc31d3587923f95a61f5ba2b33e5cf74d92 100644 (file)
@@ -44,6 +44,7 @@ static inline int led_get_brightness(struct led_classdev *led_cdev)
        return led_cdev->brightness;
 }
 
+void led_init_core(struct led_classdev *led_cdev);
 void led_stop_software_blink(struct led_classdev *led_cdev);
 
 extern struct rw_semaphore leds_list_lock;