* [PATCH] LED key trigger support
@ 2009-02-25 9:34 Kyungmin Park
2009-02-26 7:05 ` Trilok Soni
0 siblings, 1 reply; 3+ messages in thread
From: Kyungmin Park @ 2009-02-25 9:34 UTC (permalink / raw)
To: linux-kernel, linux-input; +Cc: dmitry.torokhov, soni.trilok, rpurdie
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@samsung.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@samsung.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@samsung.com>");
+MODULE_DESCRIPTION("Key LED trigger");
+MODULE_LICENSE("GPL");
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] LED key trigger support
2009-02-25 9:34 [PATCH] LED key trigger support Kyungmin Park
@ 2009-02-26 7:05 ` Trilok Soni
2009-02-27 2:13 ` Kyungmin Park
0 siblings, 1 reply; 3+ messages in thread
From: Trilok Soni @ 2009-02-26 7:05 UTC (permalink / raw)
To: Kyungmin Park; +Cc: linux-kernel, linux-input, dmitry.torokhov, rpurdie
Hi Kyungmin,
> +
> +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;
No need of casting from void *.
> +
> + /* In case of touchscreen, just skip it */
> + if (*key_value == BTN_TOUCH)
> + return 0;
I think this filtering is already done by notification patch.
> +
> + 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");
s/allocatate/allocate
--
---Trilok Soni
http://triloksoni.wordpress.com
http://www.linkedin.com/in/triloksoni
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] LED key trigger support
2009-02-26 7:05 ` Trilok Soni
@ 2009-02-27 2:13 ` Kyungmin Park
0 siblings, 0 replies; 3+ messages in thread
From: Kyungmin Park @ 2009-02-27 2:13 UTC (permalink / raw)
To: Trilok Soni; +Cc: linux-kernel, linux-input, dmitry.torokhov, rpurdie
On Thu, Feb 26, 2009 at 4:05 PM, Trilok Soni <soni.trilok@gmail.com> wrote:
> Hi Kyungmin,
>
>> +
>> +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;
>
> No need of casting from void *.
>
>> +
>> + /* In case of touchscreen, just skip it */
>> + if (*key_value == BTN_TOUCH)
>> + return 0;
>
> I think this filtering is already done by notification patch.
No, touchscreen also use input_report_key function so it passed BTN_TOUCH value.
I don't want to key led blink at touchscreen.
>
>> +
>> + 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");
>
> s/allocatate/allocate
Sorry for typo, I will fix it.
Thank you,
Kyungmin Park
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2009-02-27 2:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-25 9:34 [PATCH] LED key trigger support Kyungmin Park
2009-02-26 7:05 ` Trilok Soni
2009-02-27 2:13 ` Kyungmin Park
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).