Commit ba93cdce authored by Ezequiel Garcia's avatar Ezequiel Garcia Committed by Jacek Anaszewski

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: default avatarEzequiel Garcia <ezequiel@vanguardiasur.com.ar>
Reviewed-by: default avatarMatthias Brugger <mbrugger@suse.com>
Acked-by: default avatarPavel Machek <pavel@ucw.cz>
Signed-off-by: default avatarJacek Anaszewski <j.anaszewski@samsung.com>
parent f15c65af
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
* Nests outside led_cdev->trigger_lock * Nests outside led_cdev->trigger_lock
*/ */
static DECLARE_RWSEM(triggers_list_lock); static DECLARE_RWSEM(triggers_list_lock);
static LIST_HEAD(trigger_list); LIST_HEAD(trigger_list);
/* Used by LED Class */ /* Used by LED Class */
......
...@@ -30,5 +30,6 @@ void led_set_brightness_nosleep(struct led_classdev *led_cdev, ...@@ -30,5 +30,6 @@ void led_set_brightness_nosleep(struct led_classdev *led_cdev,
extern struct rw_semaphore leds_list_lock; extern struct rw_semaphore leds_list_lock;
extern struct list_head leds_list; extern struct list_head leds_list;
extern struct list_head trigger_list;
#endif /* __LEDS_H_INCLUDED */ #endif /* __LEDS_H_INCLUDED */
...@@ -121,6 +121,9 @@ config LEDS_TRIGGER_PANIC ...@@ -121,6 +121,9 @@ config LEDS_TRIGGER_PANIC
depends on LEDS_TRIGGERS depends on LEDS_TRIGGERS
help help
This allows LEDs to be configured to blink on a kernel panic. This allows LEDs to be configured to blink on a kernel panic.
Enabling this option will allow to mark certain LEDs as panic indicators,
allowing to blink them on a kernel panic, even if they are set to
a different trigger.
If unsure, say Y. If unsure, say Y.
endif # LEDS_TRIGGERS endif # LEDS_TRIGGERS
...@@ -11,10 +11,54 @@ ...@@ -11,10 +11,54 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/notifier.h>
#include <linux/leds.h> #include <linux/leds.h>
#include "../leds.h"
static struct led_trigger *trigger; static struct led_trigger *trigger;
/*
* This is called in a special context by the atomic panic
* notifier. This means the trigger can be changed without
* worrying about locking.
*/
static void led_trigger_set_panic(struct led_classdev *led_cdev)
{
struct led_trigger *trig;
list_for_each_entry(trig, &trigger_list, next_trig) {
if (strcmp("panic", trig->name))
continue;
if (led_cdev->trigger)
list_del(&led_cdev->trig_list);
list_add_tail(&led_cdev->trig_list, &trig->led_cdevs);
/* Avoid the delayed blink path */
led_cdev->blink_delay_on = 0;
led_cdev->blink_delay_off = 0;
led_cdev->trigger = trig;
if (trig->activate)
trig->activate(led_cdev);
break;
}
}
static int led_trigger_panic_notifier(struct notifier_block *nb,
unsigned long code, void *unused)
{
struct led_classdev *led_cdev;
list_for_each_entry(led_cdev, &leds_list, node)
if (led_cdev->flags & LED_PANIC_INDICATOR)
led_trigger_set_panic(led_cdev);
return NOTIFY_DONE;
}
static struct notifier_block led_trigger_panic_nb = {
.notifier_call = led_trigger_panic_notifier,
};
static long led_panic_blink(int state) static long led_panic_blink(int state)
{ {
led_trigger_event(trigger, state ? LED_FULL : LED_OFF); led_trigger_event(trigger, state ? LED_FULL : LED_OFF);
...@@ -23,6 +67,9 @@ static long led_panic_blink(int state) ...@@ -23,6 +67,9 @@ static long led_panic_blink(int state)
static int __init ledtrig_panic_init(void) static int __init ledtrig_panic_init(void)
{ {
atomic_notifier_chain_register(&panic_notifier_list,
&led_trigger_panic_nb);
led_trigger_register_simple("panic", &trigger); led_trigger_register_simple("panic", &trigger);
panic_blink = led_panic_blink; panic_blink = led_panic_blink;
return 0; return 0;
......
...@@ -50,6 +50,7 @@ struct led_classdev { ...@@ -50,6 +50,7 @@ struct led_classdev {
#define LED_SYSFS_DISABLE (1 << 22) #define LED_SYSFS_DISABLE (1 << 22)
#define LED_DEV_CAP_FLASH (1 << 23) #define LED_DEV_CAP_FLASH (1 << 23)
#define LED_HW_PLUGGABLE (1 << 24) #define LED_HW_PLUGGABLE (1 << 24)
#define LED_PANIC_INDICATOR (1 << 25)
/* Set LED brightness level /* Set LED brightness level
* Must not sleep. Use brightness_set_blocking for drivers * Must not sleep. Use brightness_set_blocking for drivers
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment