leds: gpio: Allow LED to retain state at shutdown
authorAndrew Jeffery <andrew@aj.id.au>
Mon, 28 Aug 2017 00:17:11 +0000 (09:47 +0930)
committerJacek Anaszewski <jacek.anaszewski@gmail.com>
Tue, 29 Aug 2017 19:10:40 +0000 (21:10 +0200)
In some systems, such as Baseboard Management Controllers (BMCs), we
want to retain the state of LEDs across a reboot of the BMC (whilst the
host remains up). Implement support for the retain-state-shutdown
devicetree property in leds-gpio.

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Acked-by: Pavel Machek <pavel@ucw.cz>
Tested-by: Brandon Wyman <bjwyman@gmail.com>
Signed-off-by: Jacek Anaszewski <jacek.anaszewski@gmail.com>
drivers/leds/leds-gpio.c
include/linux/leds.h

index e753ba93ba1e544986f1774d9c33c45aab23a996..764c31301f903cef5d785a4adf49b4056df0dc2d 100644 (file)
@@ -134,6 +134,8 @@ static int create_gpio_led(const struct gpio_led *template,
                led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
        if (template->panic_indicator)
                led_dat->cdev.flags |= LED_PANIC_INDICATOR;
+       if (template->retain_state_shutdown)
+               led_dat->cdev.flags |= LED_RETAIN_AT_SHUTDOWN;
 
        ret = gpiod_direction_output(led_dat->gpiod, state);
        if (ret < 0)
@@ -205,6 +207,8 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
 
                if (fwnode_property_present(child, "retain-state-suspended"))
                        led.retain_state_suspended = 1;
+               if (fwnode_property_present(child, "retain-state-shutdown"))
+                       led.retain_state_shutdown = 1;
                if (fwnode_property_present(child, "panic-indicator"))
                        led.panic_indicator = 1;
 
@@ -267,7 +271,8 @@ static void gpio_led_shutdown(struct platform_device *pdev)
        for (i = 0; i < priv->num_leds; i++) {
                struct gpio_led_data *led = &priv->leds[i];
 
-               gpio_led_set(&led->cdev, LED_OFF);
+               if (!(led->cdev.flags & LED_RETAIN_AT_SHUTDOWN))
+                       gpio_led_set(&led->cdev, LED_OFF);
        }
 }
 
index 64c56d454f7df9f864a5242ce4212df586f66886..bf6db4fe895bcd67e04ee65e8f76ea104af6299f 100644 (file)
@@ -49,6 +49,7 @@ struct led_classdev {
 #define LED_HW_PLUGGABLE       (1 << 19)
 #define LED_PANIC_INDICATOR    (1 << 20)
 #define LED_BRIGHT_HW_CHANGED  (1 << 21)
+#define LED_RETAIN_AT_SHUTDOWN (1 << 22)
 
        /* set_brightness_work / blink_timer flags, atomic, private. */
        unsigned long           work_flags;
@@ -392,6 +393,7 @@ struct gpio_led {
        unsigned        retain_state_suspended : 1;
        unsigned        panic_indicator : 1;
        unsigned        default_state : 2;
+       unsigned        retain_state_shutdown : 1;
        /* default_state should be one of LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP) */
        struct gpio_desc *gpiod;
 };