diff options
author | Ezequiel Garcia <ezequiel@vanguardiasur.com.ar> | 2016-04-28 18:03:38 -0400 |
---|---|---|
committer | Jacek Anaszewski <j.anaszewski@samsung.com> | 2016-05-06 04:22:09 -0400 |
commit | ba93cdce5bbe6929fd7486f87c985598ded8f451 (patch) | |
tree | e9bedbf17709dceafabbcd753a3d6cc97c36d6fb | |
parent | f15c65afddbe16a832cfe3f311588c7e34a4efbf (diff) |
leds: triggers: Allow to switch the trigger to "panic" on a kernel panic
This commit adds a new led_cdev flag LED_PANIC_INDICATOR, which
allows to mark a specific LED to be switched to the "panic"
trigger, on a kernel panic.
This is useful to allow the user to assign a regular trigger
to a given LED, and still blink that LED on a kernel panic.
Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Reviewed-by: Matthias Brugger <mbrugger@suse.com>
Acked-by: Pavel Machek <pavel@ucw.cz>
Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
-rw-r--r-- | drivers/leds/led-triggers.c | 2 | ||||
-rw-r--r-- | drivers/leds/leds.h | 1 | ||||
-rw-r--r-- | drivers/leds/trigger/Kconfig | 3 | ||||
-rw-r--r-- | drivers/leds/trigger/ledtrig-panic.c | 47 | ||||
-rw-r--r-- | include/linux/leds.h | 1 |
5 files changed, 53 insertions, 1 deletions
diff --git a/drivers/leds/led-triggers.c b/drivers/leds/led-triggers.c index 2181581795d3..55fa65e1ae03 100644 --- a/drivers/leds/led-triggers.c +++ b/drivers/leds/led-triggers.c | |||
@@ -26,7 +26,7 @@ | |||
26 | * Nests outside led_cdev->trigger_lock | 26 | * Nests outside led_cdev->trigger_lock |
27 | */ | 27 | */ |
28 | static DECLARE_RWSEM(triggers_list_lock); | 28 | static DECLARE_RWSEM(triggers_list_lock); |
29 | static LIST_HEAD(trigger_list); | 29 | LIST_HEAD(trigger_list); |
30 | 30 | ||
31 | /* Used by LED Class */ | 31 | /* Used by LED Class */ |
32 | 32 | ||
diff --git a/drivers/leds/leds.h b/drivers/leds/leds.h index db3f20da7221..7d38e6b9a740 100644 --- a/drivers/leds/leds.h +++ b/drivers/leds/leds.h | |||
@@ -30,5 +30,6 @@ void led_set_brightness_nosleep(struct led_classdev *led_cdev, | |||
30 | 30 | ||
31 | extern struct rw_semaphore leds_list_lock; | 31 | extern struct rw_semaphore leds_list_lock; |
32 | extern struct list_head leds_list; | 32 | extern struct list_head leds_list; |
33 | extern struct list_head trigger_list; | ||
33 | 34 | ||
34 | #endif /* __LEDS_H_INCLUDED */ | 35 | #endif /* __LEDS_H_INCLUDED */ |
diff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig index beac8c31c51b..9893d911390d 100644 --- a/drivers/leds/trigger/Kconfig +++ b/drivers/leds/trigger/Kconfig | |||
@@ -121,6 +121,9 @@ config LEDS_TRIGGER_PANIC | |||
121 | depends on LEDS_TRIGGERS | 121 | depends on LEDS_TRIGGERS |
122 | help | 122 | help |
123 | This allows LEDs to be configured to blink on a kernel panic. | 123 | This allows LEDs to be configured to blink on a kernel panic. |
124 | Enabling this option will allow to mark certain LEDs as panic indicators, | ||
125 | allowing to blink them on a kernel panic, even if they are set to | ||
126 | a different trigger. | ||
124 | If unsure, say Y. | 127 | If unsure, say Y. |
125 | 128 | ||
126 | endif # LEDS_TRIGGERS | 129 | endif # LEDS_TRIGGERS |
diff --git a/drivers/leds/trigger/ledtrig-panic.c b/drivers/leds/trigger/ledtrig-panic.c index 627b350c5ec3..d735526b9db4 100644 --- a/drivers/leds/trigger/ledtrig-panic.c +++ b/drivers/leds/trigger/ledtrig-panic.c | |||
@@ -11,10 +11,54 @@ | |||
11 | 11 | ||
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/init.h> | 13 | #include <linux/init.h> |
14 | #include <linux/notifier.h> | ||
14 | #include <linux/leds.h> | 15 | #include <linux/leds.h> |
16 | #include "../leds.h" | ||
15 | 17 | ||
16 | static struct led_trigger *trigger; | 18 | static struct led_trigger *trigger; |
17 | 19 | ||
20 | /* | ||
21 | * This is called in a special context by the atomic panic | ||
22 | * notifier. This means the trigger can be changed without | ||
23 | * worrying about locking. | ||
24 | */ | ||
25 | static void led_trigger_set_panic(struct led_classdev *led_cdev) | ||
26 | { | ||
27 | struct led_trigger *trig; | ||
28 | |||
29 | list_for_each_entry(trig, &trigger_list, next_trig) { | ||
30 | if (strcmp("panic", trig->name)) | ||
31 | continue; | ||
32 | if (led_cdev->trigger) | ||
33 | list_del(&led_cdev->trig_list); | ||
34 | list_add_tail(&led_cdev->trig_list, &trig->led_cdevs); | ||
35 | |||
36 | /* Avoid the delayed blink path */ | ||
37 | led_cdev->blink_delay_on = 0; | ||
38 | led_cdev->blink_delay_off = 0; | ||
39 | |||
40 | led_cdev->trigger = trig; | ||
41 | if (trig->activate) | ||
42 | trig->activate(led_cdev); | ||
43 | break; | ||
44 | } | ||
45 | } | ||
46 | |||
47 | static int led_trigger_panic_notifier(struct notifier_block *nb, | ||
48 | unsigned long code, void *unused) | ||
49 | { | ||
50 | struct led_classdev *led_cdev; | ||
51 | |||
52 | list_for_each_entry(led_cdev, &leds_list, node) | ||
53 | if (led_cdev->flags & LED_PANIC_INDICATOR) | ||
54 | led_trigger_set_panic(led_cdev); | ||
55 | return NOTIFY_DONE; | ||
56 | } | ||
57 | |||
58 | static struct notifier_block led_trigger_panic_nb = { | ||
59 | .notifier_call = led_trigger_panic_notifier, | ||
60 | }; | ||
61 | |||
18 | static long led_panic_blink(int state) | 62 | static long led_panic_blink(int state) |
19 | { | 63 | { |
20 | led_trigger_event(trigger, state ? LED_FULL : LED_OFF); | 64 | led_trigger_event(trigger, state ? LED_FULL : LED_OFF); |
@@ -23,6 +67,9 @@ static long led_panic_blink(int state) | |||
23 | 67 | ||
24 | static int __init ledtrig_panic_init(void) | 68 | static int __init ledtrig_panic_init(void) |
25 | { | 69 | { |
70 | atomic_notifier_chain_register(&panic_notifier_list, | ||
71 | &led_trigger_panic_nb); | ||
72 | |||
26 | led_trigger_register_simple("panic", &trigger); | 73 | led_trigger_register_simple("panic", &trigger); |
27 | panic_blink = led_panic_blink; | 74 | panic_blink = led_panic_blink; |
28 | return 0; | 75 | return 0; |
diff --git a/include/linux/leds.h b/include/linux/leds.h index 19eb10278bea..7e9fb00e15e8 100644 --- a/include/linux/leds.h +++ b/include/linux/leds.h | |||
@@ -50,6 +50,7 @@ struct led_classdev { | |||
50 | #define LED_SYSFS_DISABLE (1 << 22) | 50 | #define LED_SYSFS_DISABLE (1 << 22) |
51 | #define LED_DEV_CAP_FLASH (1 << 23) | 51 | #define LED_DEV_CAP_FLASH (1 << 23) |
52 | #define LED_HW_PLUGGABLE (1 << 24) | 52 | #define LED_HW_PLUGGABLE (1 << 24) |
53 | #define LED_PANIC_INDICATOR (1 << 25) | ||
53 | 54 | ||
54 | /* Set LED brightness level | 55 | /* Set LED brightness level |
55 | * Must not sleep. Use brightness_set_blocking for drivers | 56 | * Must not sleep. Use brightness_set_blocking for drivers |