 drivers/input/Kconfig |   15 +++
 drivers/input/power.c |  240 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 255 insertions(+)

Index: linux-2.6.21/drivers/input/power.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ linux-2.6.21/drivers/input/power.c	2007-07-01 22:37:47.000000000 +0100
@@ -0,0 +1,238 @@
+/*
+ * $Id: power.c,v 1.10 2001/09/25 09:17:15 vojtech Exp $
+ *
+ *  Copyright (c) 2001 "Crazy" James Simmons
+ *  Copyright (c) 2005 Dmitry Torokhov
+ *
+ *  Input driver Power Management.
+ *
+ *  Sponsored by Transvirtual Technology.
+ */
+
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * Should you need to contact me, the author, you can do so by
+ * e-mail - mail your message to <jsimmons@transvirtual.com>.
+ */
+
+#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>
+#ifdef CONFIG_ACPI
+#include <linux/acpi.h>
+#endif
+#ifdef CONFIG_APM_EMULATION
+#if defined(CONFIG_ARM) && !defined(CONFIG_ARM26)
+#include <linux/apm-emulation.h>
+#endif
+#endif
+
+
+static struct input_handler power_handler;
+//static long suspend_time_pressed;
+//static DEFINE_SPINLOCK(suspend_time_lock);
+
+#ifdef CONFIG_ACPI
+/* FIXME: This should be in ACPI */
+static void acpi_queue_event(int suspend)
+{
+	struct acpi_device dev;
+
+	sprintf(acpi_device_name(&dev), "%s", suspend ? "KEY_SUSPEND" : "KEY_POWER");
+	sprintf(acpi_device_class(&dev), "button/%s", suspend ? "sleep" : "power");
+	acpi_bus_generate_event(&dev, 1, 1);
+}
+#endif
+
+static void system_power_event(unsigned int keycode)
+{
+//	unsigned long flags;
+
+	switch (keycode) {
+		case KEY_SUSPEND:
+
+			/* ignore jitter */
+	//		spin_lock_irqsave(&suspend_time_lock, flags);
+	//		if (time_before(jiffies, suspend_time_pressed + msecs_to_jiffies(200))) {
+	//			spin_unlock_irqrestore(&suspend_time_lock, flags);
+	//			break;
+	//		}
+	//		suspend_time_pressed = jiffies;
+	//		spin_unlock_irqrestore(&suspend_time_lock, flags);
+
+	//		if (!PM_IS_ACTIVE()) {
+	//			printk(KERN_INFO "power: PM is not active, ignoring suspend request\n");
+	//			break;
+	//		}
+
+			printk(KERN_INFO "power: requesting system suspend...\n");
+#ifdef CONFIG_ACPI
+			if (!acpi_disabled) {
+				acpi_queue_event(1);
+				break;
+			}
+#endif
+
+#ifdef CONFIG_APM_EMULATION
+#if defined(CONFIG_ARM) && !defined(CONFIG_ARM26)
+			/* only ARM has apm_queue_event */
+			apm_queue_event(APM_USER_SUSPEND);
+#endif
+#endif
+			break;
+
+		case KEY_POWER:
+
+	//		if (!PM_IS_ACTIVE()) {
+	//			printk(KERN_INFO "power: PM is not active, ignoring shutdown request\n");
+	//			break;
+	//		}
+#ifdef CONFIG_ACPI
+			if (!acpi_disabled) {
+				printk(KERN_INFO "power: requesting system shutdown...\n");
+				acpi_queue_event(0);
+				break;
+			}
+#endif
+
+#ifdef CONFIG_APM_EMULATION
+			printk(KERN_INFO "power: shutdown via APM is not supported...\n");
+#endif
+			break;
+
+		default:
+			break;
+	}
+}
+
+static void device_power_event(struct input_dev *dev, unsigned int keycode)
+{
+	switch (keycode) {
+		case KEY_SUSPEND:
+		case KEY_POWER:
+			printk(KERN_DEBUG "power.c: device-level power management is not supported yet\n");
+			break;
+
+		default:
+			break;
+	}
+}
+
+static void power_event(struct input_handle *handle, unsigned int type,
+		        unsigned int code, int value)
+{
+	/* only react on key down events */
+	if (value != 1)
+		return;
+
+	switch (type) {
+		case EV_PWR:
+			system_power_event(code);
+			break;
+
+		case EV_KEY:
+			device_power_event(handle->dev, code);
+			break;
+
+		default:
+			break;
+	}
+}
+
+static struct input_handle *power_connect(struct input_handler *handler,
+					  struct input_dev *dev,
+					  const struct input_device_id *id)
+{
+	struct input_handle *handle;
+	int err;
+
+	if (!(handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL)))
+		return -ENOMEM;
+
+	handle->dev = dev;
+	handle->handler = handler;
+	handle->name = "power";
+
+
+	printk(KERN_INFO "power.c: Adding power management to input layer\n");
+
+	handler->private = handle;
+	err = input_register_handle(handle);
+	if (err) {
+		kfree(handle);
+		return err;
+	}
+
+	input_open_device(handle);
+	return 0;
+}
+
+static void power_disconnect(struct input_handle *handler)
+{
+	struct input_handle *handle = handler->private;
+
+	input_close_device(handle);
+	kfree(handle);
+}
+
+static const struct input_device_id power_ids[] = {
+	{
+		.flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT,
+		.evbit = { BIT(EV_KEY) },
+		.keybit = { [LONG(KEY_SUSPEND)] = BIT(KEY_SUSPEND) }
+	},
+	{
+		.flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT,
+		.evbit = { BIT(EV_KEY) },
+		.keybit = { [LONG(KEY_POWER)] = BIT(KEY_POWER) }
+	},
+	{
+		.flags = INPUT_DEVICE_ID_MATCH_EVBIT,
+		.evbit = { BIT(EV_PWR) },
+	},
+	{ }, 	/* Terminating entry */
+};
+
+MODULE_DEVICE_TABLE(input, power_ids);
+
+static struct input_handler power_handler = {
+	.event =	power_event,
+	.connect =	power_connect,
+	.disconnect =	power_disconnect,
+	.name =		"power",
+	.id_table =	power_ids,
+};
+
+static int __init power_init(void)
+{
+	return input_register_handler(&power_handler);
+}
+
+static void __exit power_exit(void)
+{
+	input_unregister_handler(&power_handler);
+}
+
+module_init(power_init);
+module_exit(power_exit);
+
+MODULE_AUTHOR("James Simmons <jsimmons@transvirtual.com>");
+MODULE_DESCRIPTION("Input Power Management driver");
+MODULE_LICENSE("GPL");
Index: linux-2.6.21/drivers/input/Kconfig
===================================================================
--- linux-2.6.21.orig/drivers/input/Kconfig	2007-07-01 19:00:29.000000000 +0100
+++ linux-2.6.21/drivers/input/Kconfig	2007-07-01 19:50:14.000000000 +0100
@@ -158,6 +158,21 @@ config INPUT_EVBUG
 
 	  To compile this driver as a module, choose M here: the
 	  module will be called evbug.
+	  
+config INPUT_POWER
+	tristate "Power management interface"
+	depends on INPUT
+	---help---
+	  Say Y here if you have an input device (keyboard) that has
+	  sleep/power keys and you would like use these keys to
+	  initiate power management operations. Note that on many
+	  machines power and sleep keys are not part of the input
+	  system and only accessible when using ACPI button driver.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called power.
 
 comment "Input Device Drivers"
 
---
 drivers/input/Makefile |    1 +
 1 file changed, 1 insertion(+)

Index: linux-2.6.21/drivers/input/Makefile
===================================================================
--- linux-2.6.21.orig/drivers/input/Makefile	2007-07-01 21:21:37.000000000 +0100
+++ linux-2.6.21/drivers/input/Makefile	2007-07-01 23:26:40.000000000 +0100
@@ -23,3 +23,4 @@ obj-$(CONFIG_INPUT_TABLET)	+= tablet/
 obj-$(CONFIG_INPUT_TOUCHSCREEN)	+= touchscreen/
 obj-$(CONFIG_INPUT_MISC)	+= misc/
 
+obj-$(CONFIG_INPUT_POWER)	+= power.o
