LED: Add LED Trigger Support
PATCH 3/11 LED: Add LED Trigger Support
Add support for LED triggers to the LED subsystem. "Triggers" are events which change the state of an LED. Two kinds of trigger are available, simple ones which can be added to exising code with minimum disruption and complex ones for implementing new or more complex functionality.
Signed-off-by Richard Purdie <[email protected]>
drivers/leds/Kconfig +8 -0
@@ -14,5 +14,13 @@ This option enables the led sysfs class in /sys/class/leds. You'll need this to do anything useful with LEDs. If unsure, say N. +config LEDS_TRIGGERS + bool "LED Trigger support" + depends NEW_LEDS + help + This option enables trigger support for the leds class. + These triggers allow kernel events to drive the LEDs and can + be configured via sysfs. If unsure, say Y. + endmenu
drivers/leds/Makefile +1 -0
@@ -2,3 +2,4 @@ # LED Core obj-$(CONFIG_NEW_LEDS) += led-core.o obj-$(CONFIG_LEDS_CLASS) += led-class.o +obj-$(CONFIG_LEDS_TRIGGERS) += led-triggers.o
drivers/leds/leds.h +10 -0
@@ -24,3 +24,13 @@extern rwlock_t leds_list_lock;extern struct list_head leds_list; +#ifdef CONFIG_LEDS_TRIGGERS +void led_trigger_set_default (struct led_device *led_dev); +void led_trigger_set (struct led_device *led_dev,struct led_trigger *trigger); +#else +#define led_trigger_set_default (x) do {} while(0) +#define led_trigger_set (x, y) do {} while(0) +#endif + +ssize_t led_trigger_store (struct class_device *dev,const char *buf,size_t count); +ssize_t led_trigger_show (struct class_device *dev,char *buf);
include/linux/leds.h +49 -0
58 lines not on this page · raw message
drivers/leds/led-class.c +14 -0
@@ -55,6 +55,9 @@ static CLASS_DEVICE_ATTR(brightness, 0644, led_brightness_show, led_brightness_store); +#ifdef CONFIG_LEDS_TRIGGERS +static CLASS_DEVICE_ATTR(trigger, 0644, led_trigger_show, led_trigger_store); +#endif /** * led_device_suspend - suspend an led_device.
@@ -96,12 +99,17 @@/* register the attributes */ class_device_create_file (led_dev->class_dev, &class_device_attr_brightness); +#ifdef CONFIG_LEDS_TRIGGERS +class_device_create_file (led_dev->class_dev, &class_device_attr_trigger); +#endif /* add to the list of leds */ write_lock (&leds_list_lock);list_add_tail (&led_dev->node, &leds_list);write_unlock (&leds_list_lock); +led_trigger_set_default (led_dev); +printk (KERN_INFO "Registered led device: %s\n" , led_dev->class_dev->class_id);return 0 ;
@@ -116,6 +124,12 @@void led_device_unregister (struct led_device *led_dev) {class_device_remove_file (led_dev->class_dev, &class_device_attr_brightness); +#ifdef CONFIG_LEDS_TRIGGERS +class_device_remove_file (led_dev->class_dev, &class_device_attr_trigger); +#endif + +if (led_dev->trigger) +led_trigger_set (led_dev,NULL );class_device_unregister (led_dev->class_dev);
drivers/leds/led-triggers.c new file +236 -0
236 lines not on this page · raw message