iwlwifi: do not register bands with no supported channels
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / input / apm-power.c
blobc36d110b349af2d1a5ee8f591c79ccfe7cfbba31
1 /*
2 * Input Power Event -> APM Bridge
4 * Copyright (c) 2007 Richard Purdie
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.
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>
21 static void system_power_event(unsigned int keycode)
23 switch (keycode) {
24 case KEY_SUSPEND:
25 apm_queue_event(APM_USER_SUSPEND);
27 printk(KERN_INFO "apm-power: Requesting system suspend...\n");
28 break;
29 default:
30 break;
34 static void apmpower_event(struct input_handle *handle, unsigned int type,
35 unsigned int code, int value)
37 /* only react on key down events */
38 if (value != 1)
39 return;
41 switch (type) {
42 case EV_PWR:
43 system_power_event(code);
44 break;
46 default:
47 break;
51 static int apmpower_connect(struct input_handler *handler,
52 struct input_dev *dev,
53 const struct input_device_id *id)
55 struct input_handle *handle;
56 int error;
58 handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
59 if (!handle)
60 return -ENOMEM;
62 handle->dev = dev;
63 handle->handler = handler;
64 handle->name = "apm-power";
66 handler->private = handle;
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;
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;
87 return 0;
90 static void apmpower_disconnect(struct input_handle *handler)
92 struct input_handle *handle = handler->private;
94 input_close_device(handle);
95 kfree(handle);
98 static const struct input_device_id apmpower_ids[] = {
100 .flags = INPUT_DEVICE_ID_MATCH_EVBIT,
101 .evbit = { BIT_MASK(EV_PWR) },
103 { },
106 MODULE_DEVICE_TABLE(input, apmpower_ids);
108 static 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,
116 static int __init apmpower_init(void)
118 return input_register_handler(&apmpower_handler);
121 static void __exit apmpower_exit(void)
123 input_unregister_handler(&apmpower_handler);
126 module_init(apmpower_init);
127 module_exit(apmpower_exit);
129 MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
130 MODULE_DESCRIPTION("Input Power Event -> APM Bridge");
131 MODULE_LICENSE("GPL");