2 * $Id: power.c,v 1.10 2001/09/25 09:17:15 vojtech Exp $
4 * Copyright (c) 2001 "Crazy" James Simmons
6 * Input driver Power Management.
8 * Sponsored by Transvirtual Technology.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 * Should you need to contact me, the author, you can do so by
27 * e-mail - mail your message to <jsimmons@transvirtual.com>.
30 #include <linux/module.h>
31 #include <linux/config.h>
32 #include <linux/input.h>
33 #include <linux/slab.h>
34 #include <linux/init.h>
35 #include <linux/tty.h>
36 #include <linux/delay.h>
39 static struct input_handler power_handler
;
42 * Power management can't be done in a interrupt context. So we have to
45 static int suspend_button_pushed
= 0;
46 static void suspend_button_task_handler(void *data
)
48 //extern void pm_do_suspend(void);
49 udelay(200); /* debounce */
51 suspend_button_pushed
= 0;
54 static DECLARE_WORK(suspend_button_task
, suspend_button_task_handler
, NULL
);
56 static void power_event(struct input_handle
*handle
, unsigned int type
,
57 unsigned int code
, int down
)
59 struct input_dev
*dev
= handle
->dev
;
61 printk("Entering power_event\n");
63 if (type
!= EV_KEY
|| type
!= EV_PWR
) return;
68 printk("Powering down entire device\n");
70 //pm_send_all(PM_SUSPEND, dev);
72 if (!suspend_button_pushed
) {
73 suspend_button_pushed
= 1;
74 schedule_work(&suspend_button_task
);
78 /* Hum power down the machine. */
86 printk("Powering down input device\n");
87 /* This is risky. See pm.h for details. */
88 if (dev
->state
!= PM_RESUME
)
89 dev
->state
= PM_RESUME
;
91 dev
->state
= PM_SUSPEND
;
92 pm_send(dev
->pm_dev
, dev
->state
, dev
);
95 /* Turn the input device off completely ? */
104 static struct input_handle
*power_connect(struct input_handler
*handler
,
105 struct input_dev
*dev
,
106 struct input_device_id
*id
)
108 struct input_handle
*handle
;
110 if (!test_bit(EV_KEY
, dev
->evbit
) || !test_bit(EV_PWR
, dev
->evbit
))
113 if (!test_bit(KEY_SUSPEND
, dev
->keybit
) || (!test_bit(KEY_POWER
, dev
->keybit
)))
116 if (!(handle
= kmalloc(sizeof(struct input_handle
), GFP_KERNEL
)))
118 memset(handle
, 0, sizeof(struct input_handle
));
121 handle
->handler
= handler
;
123 input_open_device(handle
);
125 printk(KERN_INFO
"power.c: Adding power management to input layer\n");
129 static void power_disconnect(struct input_handle
*handle
)
131 input_close_device(handle
);
135 static struct input_device_id power_ids
[] = {
137 .flags
= INPUT_DEVICE_ID_MATCH_EVBIT
| INPUT_DEVICE_ID_MATCH_KEYBIT
,
138 .evbit
= { BIT(EV_KEY
) },
139 .keybit
= { [LONG(KEY_SUSPEND
)] = BIT(KEY_SUSPEND
) }
142 .flags
= INPUT_DEVICE_ID_MATCH_EVBIT
| INPUT_DEVICE_ID_MATCH_KEYBIT
,
143 .evbit
= { BIT(EV_KEY
) },
144 .keybit
= { [LONG(KEY_POWER
)] = BIT(KEY_POWER
) }
147 .flags
= INPUT_DEVICE_ID_MATCH_EVBIT
,
148 .evbit
= { BIT(EV_PWR
) },
150 { }, /* Terminating entry */
153 MODULE_DEVICE_TABLE(input
, power_ids
);
155 static struct input_handler power_handler
= {
156 .event
= power_event
,
157 .connect
= power_connect
,
158 .disconnect
= power_disconnect
,
160 .id_table
= power_ids
,
163 static int __init
power_init(void)
165 input_register_handler(&power_handler
);
169 static void __exit
power_exit(void)
171 input_unregister_handler(&power_handler
);
174 module_init(power_init
);
175 module_exit(power_exit
);
177 MODULE_AUTHOR("James Simmons <jsimmons@transvirtual.com>");
178 MODULE_DESCRIPTION("Input Power Management driver");