[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-id: <20090225093440.GA5414@july>
Date: Wed, 25 Feb 2009 18:34:40 +0900
From: Kyungmin Park <kmpark@...radead.org>
To: linux-kernel@...r.kernel.org, linux-input@...r.kernel.org
Cc: dmitry.torokhov@...il.com, soni.trilok@...il.com, rpurdie@...ys.net
Subject: [PATCH] LED key trigger support
When key button is pressed or released, it turns on or off LED.
It's depends on input notifier support patch.
Signed-off-by: Kyungmin Park <kyungmin.park@...sung.com>
---
diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig
index 1b2a491..256f883 100644
--- a/drivers/leds/Kconfig
+++ b/drivers/leds/Kconfig
@@ -248,4 +248,11 @@ config LEDS_TRIGGER_DEFAULT_ON
This allows LEDs to be initialised in the ON state.
If unsure, say Y.
+config LEDS_TRIGGER_KEY
+ tristate "LED Key input Trigger"
+ depends on LEDS_TRIGGERS
+ help
+ This allows LEDs to be controlled by key input.
+ If unsure, say Y.
+
endif # NEW_LEDS
diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile
index 89526ad..f31417d 100644
--- a/drivers/leds/Makefile
+++ b/drivers/leds/Makefile
@@ -34,3 +34,4 @@ obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o
obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o
obj-$(CONFIG_LEDS_TRIGGER_BACKLIGHT) += ledtrig-backlight.o
obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o
+obj-$(CONFIG_LEDS_TRIGGER_KEY) += ledtrig-key.o
diff --git a/drivers/leds/ledtrig-key.c b/drivers/leds/ledtrig-key.c
new file mode 100644
index 0000000..2e62663
--- /dev/null
+++ b/drivers/leds/ledtrig-key.c
@@ -0,0 +1,93 @@
+/*
+ * LED key trigger
+ *
+ * Copyright (C) 2009 Samsung Electronics
+ * Kyungmin Park <kyungmin.park@...sung.com>
+ *
+ * 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/kernel.h>
+#include <linux/init.h>
+#include <linux/leds.h>
+#include <linux/input.h>
+#include "leds.h"
+
+struct key_trigger_notifier {
+ struct led_classdev *led;
+ struct notifier_block notifier;
+};
+
+static int key_notifier_callback(struct notifier_block *nb,
+ unsigned long event, void *data)
+{
+ struct key_trigger_notifier *kn = container_of(nb,
+ struct key_trigger_notifier, notifier);
+ struct led_classdev *led = kn->led;
+ unsigned int *key_value = (unsigned int *) data;
+
+ /* In case of touchscreen, just skip it */
+ if (*key_value == BTN_TOUCH)
+ return 0;
+
+ led_set_brightness(led, event);
+ return 0;
+
+}
+
+static void key_led_activate(struct led_classdev *led)
+{
+ struct key_trigger_notifier *kn;
+ int ret;
+
+ kn = kzalloc(sizeof(struct key_trigger_notifier), GFP_KERNEL);
+ if (!kn) {
+ dev_err(led->dev, "unable to allocatate key trigger\n");
+ return;
+ }
+
+ led->trigger_data = kn;
+
+ kn->led = led;
+ kn->notifier.notifier_call = key_notifier_callback;
+
+ ret = input_register_client(&kn->notifier);
+ if (ret)
+ dev_err(led->dev, "unable to register key trigger\n");
+}
+
+static void key_led_deactivate(struct led_classdev *led)
+{
+ struct key_trigger_notifier *kn = led->trigger_data;
+
+ if (kn) {
+ input_unregister_client(&kn->notifier);
+ kfree(kn);
+ }
+}
+
+static struct led_trigger key_led_trigger = {
+ .name = "key",
+ .activate = key_led_activate,
+ .deactivate = key_led_deactivate,
+};
+
+static int __init key_led_trigger_init(void)
+{
+ return led_trigger_register(&key_led_trigger);
+}
+
+static void __exit key_led_trigger_exit(void)
+{
+ led_trigger_unregister(&key_led_trigger);
+}
+
+module_init(key_led_trigger_init);
+module_exit(key_led_trigger_exit);
+
+MODULE_AUTHOR("Kyungmin Park <kyungmin.park@...sung.com>");
+MODULE_DESCRIPTION("Key LED trigger");
+MODULE_LICENSE("GPL");
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists