All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kyungmin Park <kmpark@infradead.org>
To: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org
Cc: dmitry.torokhov@gmail.com, soni.trilok@gmail.com, rpurdie@rpsys.net
Subject: [PATCH] LED key trigger support
Date: Wed, 25 Feb 2009 18:34:40 +0900	[thread overview]
Message-ID: <20090225093440.GA5414@july> (raw)

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");

             reply	other threads:[~2009-02-25  9:34 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-25  9:34 Kyungmin Park [this message]
2009-02-26  7:05 ` [PATCH] LED key trigger support Trilok Soni
2009-02-26  7:05   ` Trilok Soni
2009-02-27  2:13   ` Kyungmin Park
2009-02-27  2:13     ` Kyungmin Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20090225093440.GA5414@july \
    --to=kmpark@infradead.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=rpurdie@rpsys.net \
    --cc=soni.trilok@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.