aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/input/Kconfig12
-rw-r--r--drivers/input/Makefile1
-rw-r--r--drivers/input/apm-power.c131
3 files changed, 144 insertions, 0 deletions
diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 63512d906f02..9dea14db724c 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -137,6 +137,18 @@ config INPUT_EVBUG
137 To compile this driver as a module, choose M here: the 137 To compile this driver as a module, choose M here: the
138 module will be called evbug. 138 module will be called evbug.
139 139
140config INPUT_APMPOWER
141 tristate "Input Power Event -> APM Bridge" if EMBEDDED
142 depends on INPUT && APM_EMULATION
143 ---help---
144 Say Y here if you want suspend key events to trigger a user
145 requested suspend through APM. This is useful on embedded
146 systems where such behviour is desired without userspace
147 interaction. If unsure, say N.
148
149 To compile this driver as a module, choose M here: the
150 module will be called apm-power.
151
140comment "Input Device Drivers" 152comment "Input Device Drivers"
141 153
142source "drivers/input/keyboard/Kconfig" 154source "drivers/input/keyboard/Kconfig"
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index 99af903bd3ce..2ae87b19caa8 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -22,3 +22,4 @@ obj-$(CONFIG_INPUT_TABLET) += tablet/
22obj-$(CONFIG_INPUT_TOUCHSCREEN) += touchscreen/ 22obj-$(CONFIG_INPUT_TOUCHSCREEN) += touchscreen/
23obj-$(CONFIG_INPUT_MISC) += misc/ 23obj-$(CONFIG_INPUT_MISC) += misc/
24 24
25obj-$(CONFIG_INPUT_APMPOWER) += apm-power.o
diff --git a/drivers/input/apm-power.c b/drivers/input/apm-power.c
new file mode 100644
index 000000000000..c36d110b349a
--- /dev/null
+++ b/drivers/input/apm-power.c
@@ -0,0 +1,131 @@
1/*
2 * Input Power Event -> APM Bridge
3 *
4 * Copyright (c) 2007 Richard Purdie
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11
12#include <linux/module.h>
13#include <linux/input.h>
14#include <linux/slab.h>
15#include <linux/init.h>
16#include <linux/tty.h>
17#include <linux/delay.h>
18#include <linux/pm.h>
19#include <linux/apm-emulation.h>
20
21static void system_power_event(unsigned int keycode)
22{
23 switch (keycode) {
24 case KEY_SUSPEND:
25 apm_queue_event(APM_USER_SUSPEND);
26
27 printk(KERN_INFO "apm-power: Requesting system suspend...\n");
28 break;
29 default:
30 break;
31 }
32}
33
34static void apmpower_event(struct input_handle *handle, unsigned int type,
35 unsigned int code, int value)
36{
37 /* only react on key down events */
38 if (value != 1)
39 return;
40
41 switch (type) {
42 case EV_PWR:
43 system_power_event(code);
44 break;
45
46 default:
47 break;
48 }
49}
50
51static int apmpower_connect(struct input_handler *handler,
52 struct input_dev *dev,
53 const struct input_device_id *id)
54{
55 struct input_handle *handle;
56 int error;
57
58 handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
59 if (!handle)
60 return -ENOMEM;
61
62 handle->dev = dev;
63 handle->handler = handler;
64 handle->name = "apm-power";
65
66 handler->private = handle;
67
68 error = input_register_handle(handle);
69 if (error) {
70 printk(KERN_ERR
71 "apm-power: Failed to register input power handler, "
72 "error %d\n", error);
73 kfree(handle);
74 return error;
75 }
76
77 error = input_open_device(handle);
78 if (error) {
79 printk(KERN_ERR
80 "apm-power: Failed to open input power device, "
81 "error %d\n", error);
82 input_unregister_handle(handle);
83 kfree(handle);
84 return error;
85 }
86
87 return 0;
88}
89
90static void apmpower_disconnect(struct input_handle *handler)
91{
92 struct input_handle *handle = handler->private;
93
94 input_close_device(handle);
95 kfree(handle);
96}
97
98static const struct input_device_id apmpower_ids[] = {
99 {
100 .flags = INPUT_DEVICE_ID_MATCH_EVBIT,
101 .evbit = { BIT_MASK(EV_PWR) },
102 },
103 { },
104};
105
106MODULE_DEVICE_TABLE(input, apmpower_ids);
107
108static struct input_handler apmpower_handler = {
109 .event = apmpower_event,
110 .connect = apmpower_connect,
111 .disconnect = apmpower_disconnect,
112 .name = "apm-power",
113 .id_table = apmpower_ids,
114};
115
116static int __init apmpower_init(void)
117{
118 return input_register_handler(&apmpower_handler);
119}
120
121static void __exit apmpower_exit(void)
122{
123 input_unregister_handler(&apmpower_handler);
124}
125
126module_init(apmpower_init);
127module_exit(apmpower_exit);
128
129MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
130MODULE_DESCRIPTION("Input Power Event -> APM Bridge");
131MODULE_LICENSE("GPL");