• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/components/opensource/linux/linux-2.6.36/drivers/input/
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	error = input_register_handle(handle);
67	if (error) {
68		printk(KERN_ERR
69			"apm-power: Failed to register input power handler, "
70			"error %d\n", error);
71		kfree(handle);
72		return error;
73	}
74
75	error = input_open_device(handle);
76	if (error) {
77		printk(KERN_ERR
78			"apm-power: Failed to open input power device, "
79			"error %d\n", error);
80		input_unregister_handle(handle);
81		kfree(handle);
82		return error;
83	}
84
85	return 0;
86}
87
88static void apmpower_disconnect(struct input_handle *handle)
89{
90	input_close_device(handle);
91	input_unregister_handle(handle);
92	kfree(handle);
93}
94
95static const struct input_device_id apmpower_ids[] = {
96	{
97		.flags = INPUT_DEVICE_ID_MATCH_EVBIT,
98		.evbit = { BIT_MASK(EV_PWR) },
99	},
100	{ },
101};
102
103MODULE_DEVICE_TABLE(input, apmpower_ids);
104
105static struct input_handler apmpower_handler = {
106	.event =	apmpower_event,
107	.connect =	apmpower_connect,
108	.disconnect =	apmpower_disconnect,
109	.name =		"apm-power",
110	.id_table =	apmpower_ids,
111};
112
113static int __init apmpower_init(void)
114{
115	return input_register_handler(&apmpower_handler);
116}
117
118static void __exit apmpower_exit(void)
119{
120	input_unregister_handler(&apmpower_handler);
121}
122
123module_init(apmpower_init);
124module_exit(apmpower_exit);
125
126MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
127MODULE_DESCRIPTION("Input Power Event -> APM Bridge");
128MODULE_LICENSE("GPL");
129