Merge branch 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mfashe...
[pandora-kernel.git] / drivers / input / misc / atlas_btns.c
1 /*
2  *  atlas_btns.c - Atlas Wallmount Touchscreen ACPI Extras
3  *
4  *  Copyright (C) 2006 Jaya Kumar
5  *  Based on Toshiba ACPI by John Belmonte and ASUS ACPI
6  *  This work was sponsored by CIS(M) Sdn Bhd.
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  *
22  */
23
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/input.h>
28 #include <linux/types.h>
29 #include <asm/uaccess.h>
30 #include <acpi/acpi_drivers.h>
31
32 #define ACPI_ATLAS_NAME                 "Atlas ACPI"
33 #define ACPI_ATLAS_CLASS                "Atlas"
34
35 static struct input_dev *input_dev;
36
37 /* button handling code */
38 static acpi_status acpi_atlas_button_setup(acpi_handle region_handle,
39                     u32 function, void *handler_context, void **return_context)
40 {
41         *return_context =
42                 (function != ACPI_REGION_DEACTIVATE) ? handler_context : NULL;
43
44         return AE_OK;
45 }
46
47 static acpi_status acpi_atlas_button_handler(u32 function,
48                       acpi_physical_address address,
49                       u32 bit_width, acpi_integer *value,
50                       void *handler_context, void *region_context)
51 {
52         acpi_status status;
53         int keycode;
54
55         if (function == ACPI_WRITE) {
56                 keycode = KEY_F1 + (address & 0x0F);
57                 input_report_key(input_dev, keycode, !(address & 0x10));
58                 input_sync(input_dev);
59                 status = 0;
60         } else {
61                 printk(KERN_WARNING "atlas: shrugged on unexpected function"
62                         ":function=%x,address=%lx,value=%x\n",
63                         function, (unsigned long)address, (u32)*value);
64                 status = -EINVAL;
65         }
66
67         return status;
68 }
69
70 static int atlas_acpi_button_add(struct acpi_device *device)
71 {
72         acpi_status status;
73         int err;
74
75         input_dev = input_allocate_device();
76         if (!input_dev) {
77                 printk(KERN_ERR "atlas: unable to allocate input device\n");
78                 return -ENOMEM;
79         }
80
81         input_dev->name = "Atlas ACPI button driver";
82         input_dev->phys = "ASIM0000/atlas/input0";
83         input_dev->id.bustype = BUS_HOST;
84         input_dev->evbit[BIT_WORD(EV_KEY)] = BIT_MASK(EV_KEY);
85
86         set_bit(KEY_F1, input_dev->keybit);
87         set_bit(KEY_F2, input_dev->keybit);
88         set_bit(KEY_F3, input_dev->keybit);
89         set_bit(KEY_F4, input_dev->keybit);
90         set_bit(KEY_F5, input_dev->keybit);
91         set_bit(KEY_F6, input_dev->keybit);
92         set_bit(KEY_F7, input_dev->keybit);
93         set_bit(KEY_F8, input_dev->keybit);
94         set_bit(KEY_F9, input_dev->keybit);
95
96         err = input_register_device(input_dev);
97         if (err) {
98                 printk(KERN_ERR "atlas: couldn't register input device\n");
99                 input_free_device(input_dev);
100                 return err;
101         }
102
103         /* hookup button handler */
104         status = acpi_install_address_space_handler(device->handle,
105                                 0x81, &acpi_atlas_button_handler,
106                                 &acpi_atlas_button_setup, device);
107         if (ACPI_FAILURE(status)) {
108                 printk(KERN_ERR "Atlas: Error installing addr spc handler\n");
109                 input_unregister_device(input_dev);
110                 status = -EINVAL;
111         }
112
113         return status;
114 }
115
116 static int atlas_acpi_button_remove(struct acpi_device *device, int type)
117 {
118         acpi_status status;
119
120         status = acpi_remove_address_space_handler(device->handle,
121                                 0x81, &acpi_atlas_button_handler);
122         if (ACPI_FAILURE(status)) {
123                 printk(KERN_ERR "Atlas: Error removing addr spc handler\n");
124                 status = -EINVAL;
125         }
126
127         input_unregister_device(input_dev);
128
129         return status;
130 }
131
132 static const struct acpi_device_id atlas_device_ids[] = {
133         {"ASIM0000", 0},
134         {"", 0},
135 };
136 MODULE_DEVICE_TABLE(acpi, atlas_device_ids);
137
138 static struct acpi_driver atlas_acpi_driver = {
139         .name   = ACPI_ATLAS_NAME,
140         .class  = ACPI_ATLAS_CLASS,
141         .ids    = atlas_device_ids,
142         .ops    = {
143                 .add    = atlas_acpi_button_add,
144                 .remove = atlas_acpi_button_remove,
145         },
146 };
147
148 static int __init atlas_acpi_init(void)
149 {
150         int result;
151
152         if (acpi_disabled)
153                 return -ENODEV;
154
155         result = acpi_bus_register_driver(&atlas_acpi_driver);
156         if (result < 0) {
157                 printk(KERN_ERR "Atlas ACPI: Unable to register driver\n");
158                 return -ENODEV;
159         }
160
161         return 0;
162 }
163
164 static void __exit atlas_acpi_exit(void)
165 {
166         acpi_bus_unregister_driver(&atlas_acpi_driver);
167 }
168
169 module_init(atlas_acpi_init);
170 module_exit(atlas_acpi_exit);
171
172 MODULE_AUTHOR("Jaya Kumar");
173 MODULE_LICENSE("GPL");
174 MODULE_DESCRIPTION("Atlas button driver");
175