Skip to contentSkip to conversation

Add generic EV_LED handler and LED trigger

PATCH New David Anders 1 participant 1 message Nov 5, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add generic EV_LED handler and LED trigger

this patch is to provide for an initial implementation of a generic EV_LED handler which supports LED triggers in the leds subsystem.

Signed-off-by David Anders <danders at amltd.com>
drivers/input/generic-leds.c +116 -0
diff -urN linux-2.6.27-clean/drivers/input/generic-leds.c linux-2.6.27/drivers/input/generic-leds.c
@@ -0,0 +1,116 @@
+/*
+ *  Generic Leds Event
+ *
+ *  Copyright (c) 2008 David Anders
+ *
+ *  Based on the Input Power Event -> APM Bridge
+ *
+ *  Copyright (c) 2007 Richard Purdie
+ *
+ *  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/module.h>
+#include <linux/input.h>
+#include <linux/slab.h>
+#include <linux/init.h>
+#include <linux/tty.h>
+#include <linux/delay.h>
+#include <linux/pm.h>
+#include <linux/leds.h>
+
+static void generic_leds_event(struct input_handle *handle, unsigned int type,
+				unsigned int code, int value)
+{
+	switch (type) {
+	case EV_LED:
+		ledtrig_ev_led_activity(value);
+		break;
+
+	default:
+		break;
+	}
+}
+
+static int generic_leds_connect(struct input_handler *handler,
+					  struct input_dev *dev,
+					  const struct input_device_id *id)
+{
+	struct input_handle *handle;
+	int error;
+
+	handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
+	if (!handle)
+		return -ENOMEM;
+
+	handle->dev = dev;
+	handle->handler = handler;
+	handle->name = "generic-leds";
+
+	error = input_register_handle(handle);
+	if (error) {
+		printk(KERN_ERR
+			"generic-leds: Failed to register generic-leds handler,"
+			" error %d\n", error);
+		kfree(handle);
+		return error;
+	}
+
+	error = input_open_device(handle);
+	if (error) {
+		printk(KERN_ERR
+			"generic-leds: Failed to open generic-leds device,"
+			" error %d\n", error);
+		input_unregister_handle(handle);
+		kfree(handle);
+		return error;
+	}
+
+	return 0;
+}
+
+static void generic_leds_disconnect(struct input_handle *handle)
+{
+	input_close_device(handle);
+	input_unregister_handle(handle);
+	kfree(handle);
+}
+
+static const struct input_device_id generic_leds_ids[] = {
+	{
+		.flags = INPUT_DEVICE_ID_MATCH_EVBIT,
+		.evbit = { BIT_MASK(EV_LED) },
+	},
+	{ },
+};
+
+MODULE_DEVICE_TABLE(input, generic_leds_ids);
+
+
+static struct input_handler generic_leds_handler = {
+	.event =	generic_leds_event,
+	.connect =	generic_leds_connect,
+	.disconnect =	generic_leds_disconnect,
+	.name =		"generic-leds",
+	.id_table =	generic_leds_ids,
+};
+
+static int __init generic_leds_init(void)
+{
+	return input_register_handler(&generic_leds_handler);
+}
+
+static void __exit generic_leds_exit(void)
+{
+	input_unregister_handler(&generic_leds_handler);
+}
+
+module_init(generic_leds_init);
+module_exit(generic_leds_exit);
+
+MODULE_AUTHOR("David Anders <[email protected]>");
+MODULE_DESCRIPTION("Generic Led Events");
+MODULE_LICENSE("GPL");
drivers/input/Kconfig +9 -0
diff -urN linux-2.6.27-clean/drivers/input/Kconfig linux-2.6.27/drivers/input/Kconfig
@@ -52,6 +52,15 @@
 	  To compile this driver as a module, choose M here: the
 	  module will be called input-polldev.
 
+config INPUT_GENERICLEDS
+	tristate "Generic LED Handler"
+	depends on INPUT
+	---help---
+	  Say Y here if you want LED events to be passed to the
+	  leds subsystem as a trigger. This is useful on embedded
+	  systems where such behviour is desired without userspace
+	  interaction. If unsure, say N.
+
 comment "Userland interfaces"
 
 config INPUT_MOUSEDEV
drivers/input/Makefile +1 -0
diff -urN linux-2.6.27-clean/drivers/input/Makefile linux-2.6.27/drivers/input/Makefile
@@ -9,6 +9,7 @@
 
 obj-$(CONFIG_INPUT_FF_MEMLESS)	+= ff-memless.o
 obj-$(CONFIG_INPUT_POLLDEV)	+= input-polldev.o
+obj-$(CONFIG_INPUT_GENERICLEDS)	+= generic-leds.o
 
 obj-$(CONFIG_INPUT_MOUSEDEV)	+= mousedev.o
 obj-$(CONFIG_INPUT_JOYDEV)	+= joydev.o
drivers/leds/Kconfig +7 -0
diff -urN linux-2.6.27-clean/drivers/leds/Kconfig linux-2.6.27/drivers/leds/Kconfig
@@ -172,6 +172,13 @@
 	  These triggers allow kernel events to drive the LEDs and can
 	  be configured via sysfs. If unsure, say Y.
 
+config LEDS_TRIGGER_EV_LED
+	tristate "EV_LED Input Trigger"
+	depends on LEDS_TRIGGERS
+	help
+	  This allows LEDs to be controlled by the use of the EV_LED
+	  events from the input system.
+
 config LEDS_TRIGGER_TIMER
 	tristate "LED Timer Trigger"
 	depends on LEDS_TRIGGERS
drivers/leds/ledtrig-ev-led.c +55 -0

55 lines not on this page · raw message

drivers/leds/Makefile +1 -0
diff -urN linux-2.6.27-clean/drivers/leds/Makefile linux-2.6.27/drivers/leds/Makefile
@@ -25,6 +25,7 @@
 obj-$(CONFIG_LEDS_PCA955X)		+= leds-pca955x.o
 
 # LED Triggers
+obj-$(CONFIG_LEDS_TRIGGER_EV_LED)	+= ledtrig-ev-led.o
 obj-$(CONFIG_LEDS_TRIGGER_TIMER)	+= ledtrig-timer.o
 obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK)	+= ledtrig-ide-disk.o
 obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT)	+= ledtrig-heartbeat.o
include/linux/leds.h +6 -0
diff -urN linux-2.6.27-clean/include/linux/leds.h linux-2.6.27/include/linux/leds.h
@@ -118,6 +118,12 @@
 #define ledtrig_ide_activity() do {} while(0)
 #endif
 
+#ifdef CONFIG_LEDS_TRIGGER_EV_LED
+extern void ledtrig_ev_led_activity(void);
+#else
+#define ledtrig_ev_led_activity() do {} while (0)
+#endif
+
 /*
  * Generic LED platform data for describing LED names and default triggers.
  */