[PATCH 2/3] leds:gpio:Add the support for "panic-indicator-on" and "panic-indicator-off"

From: chaochao2021666
Date: Mon Sep 06 2021 - 09:55:17 EST


From: chao zeng <chao.zeng@xxxxxxxxxxx>

This commit extend the panic indicator,allowing to set LED a variety of
different of states on a kernel panic.There are on and off state
in addition to blink for a given LED.

Signed-off-by: chao zeng <chao.zeng@xxxxxxxxxxx>
---
drivers/leds/leds-gpio.c | 9 +++++++++
include/linux/leds.h | 4 ++++
2 files changed, 13 insertions(+)

diff --git a/drivers/leds/leds-gpio.c b/drivers/leds/leds-gpio.c
index 092eb59a7d32..d77ec57f3f71 100644
--- a/drivers/leds/leds-gpio.c
+++ b/drivers/leds/leds-gpio.c
@@ -103,6 +103,11 @@ 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;
+ else if (template->panic_indicator_on)
+ led_dat->cdev.flags |= LED_PANIC_INDICATOR_ON;
+ else if (template->panic_indicator_off)
+ led_dat->cdev.flags |= LED_PANIC_INDICATOR_OFF;
+
if (template->retain_state_shutdown)
led_dat->cdev.flags |= LED_RETAIN_AT_SHUTDOWN;

@@ -169,6 +174,10 @@ static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev)
led.retain_state_shutdown = 1;
if (fwnode_property_present(child, "panic-indicator"))
led.panic_indicator = 1;
+ else if (fwnode_property_present(child, "panic-indicator-on"))
+ led.panic_indicator_on = 1;
+ else if (fwnode_property_present(child, "panic-indicator-off"))
+ led.panic_indicator_off = 1;

ret = create_gpio_led(&led, led_dat, dev, child, NULL);
if (ret < 0) {
diff --git a/include/linux/leds.h b/include/linux/leds.h
index a0b730be40ad..6b3ae1dbc65f 100644
--- a/include/linux/leds.h
+++ b/include/linux/leds.h
@@ -85,6 +85,8 @@ struct led_classdev {
#define LED_BRIGHT_HW_CHANGED BIT(21)
#define LED_RETAIN_AT_SHUTDOWN BIT(22)
#define LED_INIT_DEFAULT_TRIGGER BIT(23)
+#define LED_PANIC_INDICATOR_ON BIT(24)
+#define LED_PANIC_INDICATOR_OFF BIT(25)

/* set_brightness_work / blink_timer flags, atomic, private. */
unsigned long work_flags;
@@ -521,6 +523,8 @@ struct gpio_led {
unsigned active_low : 1;
unsigned retain_state_suspended : 1;
unsigned panic_indicator : 1;
+ unsigned panic_indicator_on : 1;
+ unsigned panic_indicator_off : 1;
unsigned default_state : 2;
unsigned retain_state_shutdown : 1;
/* default_state should be one of LEDS_GPIO_DEFSTATE_(ON|OFF|KEEP) */
--
2.17.1