leds: trigger: Introduce a kernel panic LED trigger
authorEzequiel Garcia <ezequiel@vanguardiasur.com.ar>
Tue, 29 Mar 2016 20:35:47 +0000 (17:35 -0300)
committerJacek Anaszewski <j.anaszewski@samsung.com>
Wed, 30 Mar 2016 09:16:39 +0000 (11:16 +0200)
This commit introduces a new LED trigger which allows to configure
a LED to blink on a kernel panic (through panic_blink).

Notice that currently the Openmoko FreeRunner (GTA02) mach code
sets panic_blink to blink a hard-coded LED. The new trigger is
meant to introduce a generic mechanism to achieve this.

Signed-off-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
drivers/leds/trigger/Kconfig
drivers/leds/trigger/Makefile
drivers/leds/trigger/ledtrig-panic.c [new file with mode: 0644]

index 5bda6a9b56bbd90b4a3749f87bc0c6fda8dd5034..554f5bfbeced19cc5dfcbb85ac5d9981f72a3740 100644 (file)
@@ -108,4 +108,11 @@ config LEDS_TRIGGER_CAMERA
          This enables direct flash/torch on/off by the driver, kernel space.
          If unsure, say Y.
 
+config LEDS_TRIGGER_PANIC
+       bool "LED Panic Trigger"
+       depends on LEDS_TRIGGERS
+       help
+         This allows LEDs to be configured to blink on a kernel panic.
+         If unsure, say Y.
+
 endif # LEDS_TRIGGERS
index 1abf48dacf7ebfcfb8208f7ae7bdf29d7c11ba32..547bf5c80e52d79e427bbf6bfc8c29a9897b6ca7 100644 (file)
@@ -8,3 +8,4 @@ obj-$(CONFIG_LEDS_TRIGGER_CPU)          += ledtrig-cpu.o
 obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON)  += ledtrig-default-on.o
 obj-$(CONFIG_LEDS_TRIGGER_TRANSIENT)   += ledtrig-transient.o
 obj-$(CONFIG_LEDS_TRIGGER_CAMERA)      += ledtrig-camera.o
+obj-$(CONFIG_LEDS_TRIGGER_PANIC)       += ledtrig-panic.o
diff --git a/drivers/leds/trigger/ledtrig-panic.c b/drivers/leds/trigger/ledtrig-panic.c
new file mode 100644 (file)
index 0000000..627b350
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Kernel Panic LED Trigger
+ *
+ * Copyright 2016 Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/leds.h>
+
+static struct led_trigger *trigger;
+
+static long led_panic_blink(int state)
+{
+       led_trigger_event(trigger, state ? LED_FULL : LED_OFF);
+       return 0;
+}
+
+static int __init ledtrig_panic_init(void)
+{
+       led_trigger_register_simple("panic", &trigger);
+       panic_blink = led_panic_blink;
+       return 0;
+}
+device_initcall(ledtrig_panic_init);