Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * acpi_button.c - ACPI Button Driver ($Revision: 30 $) | |
3 | * | |
4 | * Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> | |
5 | * Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | |
6 | * | |
7 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; either version 2 of the License, or (at | |
12 | * your option) any later version. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, but | |
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License along | |
20 | * with this program; if not, write to the Free Software Foundation, Inc., | |
21 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
22 | * | |
23 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
24 | */ | |
25 | ||
26 | #include <linux/kernel.h> | |
27 | #include <linux/module.h> | |
28 | #include <linux/init.h> | |
b34a8030 AS |
29 | #include <linux/types.h> |
30 | #include <linux/proc_fs.h> | |
31 | #include <linux/seq_file.h> | |
c0968f0e | 32 | #include <linux/input.h> |
1da177e4 LT |
33 | #include <acpi/acpi_bus.h> |
34 | #include <acpi/acpi_drivers.h> | |
35 | ||
1da177e4 | 36 | #define ACPI_BUTTON_COMPONENT 0x00080000 |
1da177e4 | 37 | #define ACPI_BUTTON_CLASS "button" |
b34a8030 AS |
38 | #define ACPI_BUTTON_FILE_INFO "info" |
39 | #define ACPI_BUTTON_FILE_STATE "state" | |
40 | #define ACPI_BUTTON_TYPE_UNKNOWN 0x00 | |
1da177e4 LT |
41 | #define ACPI_BUTTON_NOTIFY_STATUS 0x80 |
42 | ||
43 | #define ACPI_BUTTON_SUBCLASS_POWER "power" | |
4be44fcd | 44 | #define ACPI_BUTTON_HID_POWER "PNP0C0C" |
1da177e4 LT |
45 | #define ACPI_BUTTON_DEVICE_NAME_POWER "Power Button (CM)" |
46 | #define ACPI_BUTTON_DEVICE_NAME_POWERF "Power Button (FF)" | |
47 | #define ACPI_BUTTON_TYPE_POWER 0x01 | |
48 | #define ACPI_BUTTON_TYPE_POWERF 0x02 | |
49 | ||
50 | #define ACPI_BUTTON_SUBCLASS_SLEEP "sleep" | |
51 | #define ACPI_BUTTON_HID_SLEEP "PNP0C0E" | |
52 | #define ACPI_BUTTON_DEVICE_NAME_SLEEP "Sleep Button (CM)" | |
53 | #define ACPI_BUTTON_DEVICE_NAME_SLEEPF "Sleep Button (FF)" | |
54 | #define ACPI_BUTTON_TYPE_SLEEP 0x03 | |
55 | #define ACPI_BUTTON_TYPE_SLEEPF 0x04 | |
56 | ||
57 | #define ACPI_BUTTON_SUBCLASS_LID "lid" | |
58 | #define ACPI_BUTTON_HID_LID "PNP0C0D" | |
59 | #define ACPI_BUTTON_DEVICE_NAME_LID "Lid Switch" | |
60 | #define ACPI_BUTTON_TYPE_LID 0x05 | |
61 | ||
62 | #define _COMPONENT ACPI_BUTTON_COMPONENT | |
f52fd66d | 63 | ACPI_MODULE_NAME("button"); |
1da177e4 | 64 | |
c0968f0e | 65 | MODULE_AUTHOR("Paul Diefenbaugh"); |
7cda93e0 | 66 | MODULE_DESCRIPTION("ACPI Button Driver"); |
1da177e4 LT |
67 | MODULE_LICENSE("GPL"); |
68 | ||
1ba90e3a TR |
69 | static const struct acpi_device_id button_device_ids[] = { |
70 | {ACPI_BUTTON_HID_LID, 0}, | |
71 | {ACPI_BUTTON_HID_SLEEP, 0}, | |
72 | {ACPI_BUTTON_HID_SLEEPF, 0}, | |
73 | {ACPI_BUTTON_HID_POWER, 0}, | |
74 | {ACPI_BUTTON_HID_POWERF, 0}, | |
75 | {"", 0}, | |
76 | }; | |
77 | MODULE_DEVICE_TABLE(acpi, button_device_ids); | |
78 | ||
4be44fcd LB |
79 | static int acpi_button_add(struct acpi_device *device); |
80 | static int acpi_button_remove(struct acpi_device *device, int type); | |
23de5d9e | 81 | static int acpi_button_resume(struct acpi_device *device); |
b34a8030 AS |
82 | static int acpi_button_info_open_fs(struct inode *inode, struct file *file); |
83 | static int acpi_button_state_open_fs(struct inode *inode, struct file *file); | |
1da177e4 LT |
84 | |
85 | static struct acpi_driver acpi_button_driver = { | |
c2b6705b | 86 | .name = "button", |
4be44fcd | 87 | .class = ACPI_BUTTON_CLASS, |
1ba90e3a | 88 | .ids = button_device_ids, |
4be44fcd LB |
89 | .ops = { |
90 | .add = acpi_button_add, | |
23de5d9e | 91 | .resume = acpi_button_resume, |
4be44fcd | 92 | .remove = acpi_button_remove, |
c0968f0e | 93 | }, |
1da177e4 LT |
94 | }; |
95 | ||
96 | struct acpi_button { | |
4be44fcd | 97 | struct acpi_device *device; /* Fixed button kludge */ |
c0968f0e DT |
98 | unsigned int type; |
99 | struct input_dev *input; | |
100 | char phys[32]; /* for input device */ | |
4be44fcd | 101 | unsigned long pushed; |
1da177e4 LT |
102 | }; |
103 | ||
d7508032 | 104 | static const struct file_operations acpi_button_info_fops = { |
cf7acfab | 105 | .owner = THIS_MODULE, |
4be44fcd LB |
106 | .open = acpi_button_info_open_fs, |
107 | .read = seq_read, | |
108 | .llseek = seq_lseek, | |
109 | .release = single_release, | |
b34a8030 AS |
110 | }; |
111 | ||
d7508032 | 112 | static const struct file_operations acpi_button_state_fops = { |
cf7acfab | 113 | .owner = THIS_MODULE, |
4be44fcd LB |
114 | .open = acpi_button_state_open_fs, |
115 | .read = seq_read, | |
116 | .llseek = seq_lseek, | |
117 | .release = single_release, | |
b34a8030 | 118 | }; |
4be44fcd | 119 | |
b34a8030 AS |
120 | /* -------------------------------------------------------------------------- |
121 | FS Interface (/proc) | |
122 | -------------------------------------------------------------------------- */ | |
123 | ||
4be44fcd | 124 | static struct proc_dir_entry *acpi_button_dir; |
b34a8030 AS |
125 | |
126 | static int acpi_button_info_seq_show(struct seq_file *seq, void *offset) | |
127 | { | |
c0968f0e | 128 | struct acpi_button *button = seq->private; |
b34a8030 AS |
129 | |
130 | if (!button || !button->device) | |
d550d98d | 131 | return 0; |
b34a8030 | 132 | |
4be44fcd LB |
133 | seq_printf(seq, "type: %s\n", |
134 | acpi_device_name(button->device)); | |
b34a8030 | 135 | |
d550d98d | 136 | return 0; |
b34a8030 AS |
137 | } |
138 | ||
139 | static int acpi_button_info_open_fs(struct inode *inode, struct file *file) | |
140 | { | |
141 | return single_open(file, acpi_button_info_seq_show, PDE(inode)->data); | |
142 | } | |
4be44fcd | 143 | |
b34a8030 AS |
144 | static int acpi_button_state_seq_show(struct seq_file *seq, void *offset) |
145 | { | |
c0968f0e | 146 | struct acpi_button *button = seq->private; |
4be44fcd | 147 | acpi_status status; |
27663c58 | 148 | unsigned long long state; |
b34a8030 | 149 | |
b34a8030 | 150 | if (!button || !button->device) |
d550d98d | 151 | return 0; |
b34a8030 | 152 | |
27b1d3e8 | 153 | status = acpi_evaluate_integer(button->device->handle, "_LID", NULL, &state); |
c0968f0e DT |
154 | seq_printf(seq, "state: %s\n", |
155 | ACPI_FAILURE(status) ? "unsupported" : | |
156 | (state ? "open" : "closed")); | |
d550d98d | 157 | return 0; |
b34a8030 AS |
158 | } |
159 | ||
160 | static int acpi_button_state_open_fs(struct inode *inode, struct file *file) | |
161 | { | |
162 | return single_open(file, acpi_button_state_seq_show, PDE(inode)->data); | |
163 | } | |
164 | ||
165 | static struct proc_dir_entry *acpi_power_dir; | |
166 | static struct proc_dir_entry *acpi_sleep_dir; | |
167 | static struct proc_dir_entry *acpi_lid_dir; | |
168 | ||
4be44fcd | 169 | static int acpi_button_add_fs(struct acpi_device *device) |
b34a8030 | 170 | { |
4be44fcd | 171 | struct proc_dir_entry *entry = NULL; |
c0968f0e | 172 | struct acpi_button *button; |
b34a8030 AS |
173 | |
174 | if (!device || !acpi_driver_data(device)) | |
d550d98d | 175 | return -EINVAL; |
b34a8030 AS |
176 | |
177 | button = acpi_driver_data(device); | |
178 | ||
179 | switch (button->type) { | |
180 | case ACPI_BUTTON_TYPE_POWER: | |
181 | case ACPI_BUTTON_TYPE_POWERF: | |
182 | if (!acpi_power_dir) | |
4be44fcd LB |
183 | acpi_power_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_POWER, |
184 | acpi_button_dir); | |
b34a8030 AS |
185 | entry = acpi_power_dir; |
186 | break; | |
187 | case ACPI_BUTTON_TYPE_SLEEP: | |
188 | case ACPI_BUTTON_TYPE_SLEEPF: | |
189 | if (!acpi_sleep_dir) | |
4be44fcd LB |
190 | acpi_sleep_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_SLEEP, |
191 | acpi_button_dir); | |
b34a8030 AS |
192 | entry = acpi_sleep_dir; |
193 | break; | |
194 | case ACPI_BUTTON_TYPE_LID: | |
195 | if (!acpi_lid_dir) | |
4be44fcd LB |
196 | acpi_lid_dir = proc_mkdir(ACPI_BUTTON_SUBCLASS_LID, |
197 | acpi_button_dir); | |
b34a8030 AS |
198 | entry = acpi_lid_dir; |
199 | break; | |
200 | } | |
201 | ||
202 | if (!entry) | |
d550d98d | 203 | return -ENODEV; |
b34a8030 AS |
204 | entry->owner = THIS_MODULE; |
205 | ||
206 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), entry); | |
207 | if (!acpi_device_dir(device)) | |
d550d98d | 208 | return -ENODEV; |
b34a8030 AS |
209 | acpi_device_dir(device)->owner = THIS_MODULE; |
210 | ||
211 | /* 'info' [R] */ | |
cf7acfab DL |
212 | entry = proc_create_data(ACPI_BUTTON_FILE_INFO, |
213 | S_IRUGO, acpi_device_dir(device), | |
214 | &acpi_button_info_fops, | |
215 | acpi_driver_data(device)); | |
b34a8030 | 216 | if (!entry) |
d550d98d | 217 | return -ENODEV; |
b34a8030 AS |
218 | |
219 | /* show lid state [R] */ | |
220 | if (button->type == ACPI_BUTTON_TYPE_LID) { | |
cf7acfab DL |
221 | entry = proc_create_data(ACPI_BUTTON_FILE_STATE, |
222 | S_IRUGO, acpi_device_dir(device), | |
223 | &acpi_button_state_fops, | |
224 | acpi_driver_data(device)); | |
b34a8030 | 225 | if (!entry) |
a6fc6720 | 226 | return -ENODEV; |
b34a8030 AS |
227 | } |
228 | ||
d550d98d | 229 | return 0; |
b34a8030 AS |
230 | } |
231 | ||
4be44fcd | 232 | static int acpi_button_remove_fs(struct acpi_device *device) |
b34a8030 | 233 | { |
c0968f0e | 234 | struct acpi_button *button = acpi_driver_data(device); |
b34a8030 | 235 | |
b34a8030 AS |
236 | if (acpi_device_dir(device)) { |
237 | if (button->type == ACPI_BUTTON_TYPE_LID) | |
238 | remove_proc_entry(ACPI_BUTTON_FILE_STATE, | |
4be44fcd | 239 | acpi_device_dir(device)); |
b34a8030 | 240 | remove_proc_entry(ACPI_BUTTON_FILE_INFO, |
4be44fcd | 241 | acpi_device_dir(device)); |
b34a8030 AS |
242 | |
243 | remove_proc_entry(acpi_device_bid(device), | |
4be44fcd | 244 | acpi_device_dir(device)->parent); |
b34a8030 AS |
245 | acpi_device_dir(device) = NULL; |
246 | } | |
247 | ||
d550d98d | 248 | return 0; |
b34a8030 AS |
249 | } |
250 | ||
1da177e4 LT |
251 | /* -------------------------------------------------------------------------- |
252 | Driver Interface | |
253 | -------------------------------------------------------------------------- */ | |
23de5d9e AS |
254 | static int acpi_lid_send_state(struct acpi_button *button) |
255 | { | |
27663c58 | 256 | unsigned long long state; |
23de5d9e AS |
257 | acpi_status status; |
258 | ||
259 | status = acpi_evaluate_integer(button->device->handle, "_LID", NULL, | |
260 | &state); | |
261 | if (ACPI_FAILURE(status)) | |
262 | return -ENODEV; | |
263 | /* input layer checks if event is redundant */ | |
264 | input_report_switch(button->input, SW_LID, !state); | |
df316e93 | 265 | input_sync(button->input); |
23de5d9e AS |
266 | return 0; |
267 | } | |
1da177e4 | 268 | |
4be44fcd | 269 | static void acpi_button_notify(acpi_handle handle, u32 event, void *data) |
1da177e4 | 270 | { |
c0968f0e DT |
271 | struct acpi_button *button = data; |
272 | struct input_dev *input; | |
1da177e4 LT |
273 | |
274 | if (!button || !button->device) | |
d550d98d | 275 | return; |
1da177e4 LT |
276 | |
277 | switch (event) { | |
278 | case ACPI_BUTTON_NOTIFY_STATUS: | |
c0968f0e | 279 | input = button->input; |
c0968f0e | 280 | if (button->type == ACPI_BUTTON_TYPE_LID) { |
23de5d9e | 281 | acpi_lid_send_state(button); |
c0968f0e DT |
282 | } else { |
283 | int keycode = test_bit(KEY_SLEEP, input->keybit) ? | |
284 | KEY_SLEEP : KEY_POWER; | |
285 | ||
286 | input_report_key(input, keycode, 1); | |
287 | input_sync(input); | |
288 | input_report_key(input, keycode, 0); | |
df316e93 | 289 | input_sync(input); |
c0968f0e | 290 | } |
c0968f0e | 291 | |
14e04fb3 | 292 | acpi_bus_generate_proc_event(button->device, event, |
4be44fcd | 293 | ++button->pushed); |
1da177e4 LT |
294 | break; |
295 | default: | |
296 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | |
4be44fcd | 297 | "Unsupported event [0x%x]\n", event)); |
1da177e4 LT |
298 | break; |
299 | } | |
300 | ||
d550d98d | 301 | return; |
1da177e4 LT |
302 | } |
303 | ||
4be44fcd | 304 | static acpi_status acpi_button_notify_fixed(void *data) |
1da177e4 | 305 | { |
c0968f0e | 306 | struct acpi_button *button = data; |
1da177e4 | 307 | |
b34a8030 | 308 | if (!button) |
d550d98d | 309 | return AE_BAD_PARAMETER; |
1da177e4 | 310 | |
27b1d3e8 | 311 | acpi_button_notify(button->device->handle, ACPI_BUTTON_NOTIFY_STATUS, button); |
1da177e4 | 312 | |
d550d98d | 313 | return AE_OK; |
1da177e4 LT |
314 | } |
315 | ||
c0968f0e | 316 | static int acpi_button_install_notify_handlers(struct acpi_button *button) |
1da177e4 | 317 | { |
c0968f0e | 318 | acpi_status status; |
1da177e4 | 319 | |
c0968f0e DT |
320 | switch (button->type) { |
321 | case ACPI_BUTTON_TYPE_POWERF: | |
322 | status = | |
323 | acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, | |
324 | acpi_button_notify_fixed, | |
325 | button); | |
326 | break; | |
327 | case ACPI_BUTTON_TYPE_SLEEPF: | |
328 | status = | |
329 | acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, | |
330 | acpi_button_notify_fixed, | |
331 | button); | |
332 | break; | |
333 | default: | |
334 | status = acpi_install_notify_handler(button->device->handle, | |
335 | ACPI_DEVICE_NOTIFY, | |
336 | acpi_button_notify, | |
337 | button); | |
338 | break; | |
339 | } | |
340 | ||
341 | return ACPI_FAILURE(status) ? -ENODEV : 0; | |
342 | } | |
343 | ||
23de5d9e AS |
344 | static int acpi_button_resume(struct acpi_device *device) |
345 | { | |
346 | struct acpi_button *button; | |
347 | if (!device) | |
348 | return -EINVAL; | |
349 | button = acpi_driver_data(device); | |
350 | if (button && button->type == ACPI_BUTTON_TYPE_LID) | |
351 | return acpi_lid_send_state(button); | |
352 | return 0; | |
353 | } | |
354 | ||
c0968f0e DT |
355 | static void acpi_button_remove_notify_handlers(struct acpi_button *button) |
356 | { | |
357 | switch (button->type) { | |
358 | case ACPI_BUTTON_TYPE_POWERF: | |
359 | acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, | |
360 | acpi_button_notify_fixed); | |
361 | break; | |
362 | case ACPI_BUTTON_TYPE_SLEEPF: | |
363 | acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, | |
364 | acpi_button_notify_fixed); | |
365 | break; | |
366 | default: | |
367 | acpi_remove_notify_handler(button->device->handle, | |
368 | ACPI_DEVICE_NOTIFY, | |
369 | acpi_button_notify); | |
370 | break; | |
371 | } | |
372 | } | |
373 | ||
374 | static int acpi_button_add(struct acpi_device *device) | |
375 | { | |
376 | int error; | |
377 | struct acpi_button *button; | |
378 | struct input_dev *input; | |
1da177e4 LT |
379 | |
380 | if (!device) | |
d550d98d | 381 | return -EINVAL; |
1da177e4 | 382 | |
c0968f0e | 383 | button = kzalloc(sizeof(struct acpi_button), GFP_KERNEL); |
1da177e4 | 384 | if (!button) |
d550d98d | 385 | return -ENOMEM; |
1da177e4 LT |
386 | |
387 | button->device = device; | |
db89b4f0 | 388 | device->driver_data = button; |
1da177e4 | 389 | |
c0968f0e DT |
390 | button->input = input = input_allocate_device(); |
391 | if (!input) { | |
392 | error = -ENOMEM; | |
393 | goto err_free_button; | |
394 | } | |
395 | ||
1da177e4 LT |
396 | /* |
397 | * Determine the button type (via hid), as fixed-feature buttons | |
398 | * need to be handled a bit differently than generic-space. | |
399 | */ | |
400 | if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_POWER)) { | |
401 | button->type = ACPI_BUTTON_TYPE_POWER; | |
4be44fcd LB |
402 | strcpy(acpi_device_name(device), ACPI_BUTTON_DEVICE_NAME_POWER); |
403 | sprintf(acpi_device_class(device), "%s/%s", | |
1da177e4 | 404 | ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_POWER); |
4be44fcd | 405 | } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_POWERF)) { |
1da177e4 LT |
406 | button->type = ACPI_BUTTON_TYPE_POWERF; |
407 | strcpy(acpi_device_name(device), | |
4be44fcd LB |
408 | ACPI_BUTTON_DEVICE_NAME_POWERF); |
409 | sprintf(acpi_device_class(device), "%s/%s", | |
1da177e4 | 410 | ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_POWER); |
4be44fcd | 411 | } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_SLEEP)) { |
1da177e4 | 412 | button->type = ACPI_BUTTON_TYPE_SLEEP; |
4be44fcd LB |
413 | strcpy(acpi_device_name(device), ACPI_BUTTON_DEVICE_NAME_SLEEP); |
414 | sprintf(acpi_device_class(device), "%s/%s", | |
1da177e4 | 415 | ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_SLEEP); |
4be44fcd | 416 | } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_SLEEPF)) { |
1da177e4 LT |
417 | button->type = ACPI_BUTTON_TYPE_SLEEPF; |
418 | strcpy(acpi_device_name(device), | |
4be44fcd LB |
419 | ACPI_BUTTON_DEVICE_NAME_SLEEPF); |
420 | sprintf(acpi_device_class(device), "%s/%s", | |
1da177e4 | 421 | ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_SLEEP); |
4be44fcd | 422 | } else if (!strcmp(acpi_device_hid(device), ACPI_BUTTON_HID_LID)) { |
1da177e4 | 423 | button->type = ACPI_BUTTON_TYPE_LID; |
4be44fcd LB |
424 | strcpy(acpi_device_name(device), ACPI_BUTTON_DEVICE_NAME_LID); |
425 | sprintf(acpi_device_class(device), "%s/%s", | |
1da177e4 | 426 | ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID); |
4be44fcd | 427 | } else { |
6468463a LB |
428 | printk(KERN_ERR PREFIX "Unsupported hid [%s]\n", |
429 | acpi_device_hid(device)); | |
c0968f0e DT |
430 | error = -ENODEV; |
431 | goto err_free_input; | |
1da177e4 LT |
432 | } |
433 | ||
c0968f0e DT |
434 | error = acpi_button_add_fs(device); |
435 | if (error) | |
436 | goto err_free_input; | |
437 | ||
438 | error = acpi_button_install_notify_handlers(button); | |
439 | if (error) | |
440 | goto err_remove_fs; | |
441 | ||
442 | snprintf(button->phys, sizeof(button->phys), | |
443 | "%s/button/input0", acpi_device_hid(device)); | |
444 | ||
445 | input->name = acpi_device_name(device); | |
446 | input->phys = button->phys; | |
447 | input->id.bustype = BUS_HOST; | |
448 | input->id.product = button->type; | |
3b34e523 | 449 | input->dev.parent = &device->dev; |
b34a8030 | 450 | |
1da177e4 | 451 | switch (button->type) { |
c0968f0e | 452 | case ACPI_BUTTON_TYPE_POWER: |
1da177e4 | 453 | case ACPI_BUTTON_TYPE_POWERF: |
7b19ada2 | 454 | input->evbit[0] = BIT_MASK(EV_KEY); |
c0968f0e | 455 | set_bit(KEY_POWER, input->keybit); |
1da177e4 | 456 | break; |
c0968f0e DT |
457 | |
458 | case ACPI_BUTTON_TYPE_SLEEP: | |
1da177e4 | 459 | case ACPI_BUTTON_TYPE_SLEEPF: |
7b19ada2 | 460 | input->evbit[0] = BIT_MASK(EV_KEY); |
c0968f0e | 461 | set_bit(KEY_SLEEP, input->keybit); |
1da177e4 | 462 | break; |
c0968f0e DT |
463 | |
464 | case ACPI_BUTTON_TYPE_LID: | |
7b19ada2 | 465 | input->evbit[0] = BIT_MASK(EV_SW); |
c0968f0e | 466 | set_bit(SW_LID, input->swbit); |
1da177e4 LT |
467 | break; |
468 | } | |
469 | ||
c0968f0e DT |
470 | error = input_register_device(input); |
471 | if (error) | |
472 | goto err_remove_handlers; | |
23de5d9e AS |
473 | if (button->type == ACPI_BUTTON_TYPE_LID) |
474 | acpi_lid_send_state(button); | |
1da177e4 LT |
475 | |
476 | if (device->wakeup.flags.valid) { | |
477 | /* Button's GPE is run-wake GPE */ | |
4be44fcd LB |
478 | acpi_set_gpe_type(device->wakeup.gpe_device, |
479 | device->wakeup.gpe_number, | |
480 | ACPI_GPE_TYPE_WAKE_RUN); | |
481 | acpi_enable_gpe(device->wakeup.gpe_device, | |
482 | device->wakeup.gpe_number, ACPI_NOT_ISR); | |
1da177e4 LT |
483 | device->wakeup.state.enabled = 1; |
484 | } | |
485 | ||
4be44fcd LB |
486 | printk(KERN_INFO PREFIX "%s [%s]\n", |
487 | acpi_device_name(device), acpi_device_bid(device)); | |
1da177e4 | 488 | |
c0968f0e | 489 | return 0; |
1da177e4 | 490 | |
c0968f0e DT |
491 | err_remove_handlers: |
492 | acpi_button_remove_notify_handlers(button); | |
493 | err_remove_fs: | |
494 | acpi_button_remove_fs(device); | |
495 | err_free_input: | |
496 | input_free_device(input); | |
497 | err_free_button: | |
498 | kfree(button); | |
499 | return error; | |
1da177e4 LT |
500 | } |
501 | ||
4be44fcd | 502 | static int acpi_button_remove(struct acpi_device *device, int type) |
1da177e4 | 503 | { |
c0968f0e | 504 | struct acpi_button *button; |
1da177e4 LT |
505 | |
506 | if (!device || !acpi_driver_data(device)) | |
d550d98d | 507 | return -EINVAL; |
1da177e4 LT |
508 | |
509 | button = acpi_driver_data(device); | |
510 | ||
c0968f0e | 511 | acpi_button_remove_notify_handlers(button); |
4be44fcd | 512 | acpi_button_remove_fs(device); |
c0968f0e | 513 | input_unregister_device(button->input); |
1da177e4 LT |
514 | kfree(button); |
515 | ||
d550d98d | 516 | return 0; |
1da177e4 LT |
517 | } |
518 | ||
4be44fcd | 519 | static int __init acpi_button_init(void) |
1da177e4 | 520 | { |
c0968f0e | 521 | int result; |
1da177e4 | 522 | |
b34a8030 AS |
523 | acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir); |
524 | if (!acpi_button_dir) | |
d550d98d | 525 | return -ENODEV; |
b34a8030 | 526 | acpi_button_dir->owner = THIS_MODULE; |
1da177e4 LT |
527 | result = acpi_bus_register_driver(&acpi_button_driver); |
528 | if (result < 0) { | |
b34a8030 | 529 | remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir); |
d550d98d | 530 | return -ENODEV; |
1da177e4 LT |
531 | } |
532 | ||
d550d98d | 533 | return 0; |
1da177e4 LT |
534 | } |
535 | ||
4be44fcd | 536 | static void __exit acpi_button_exit(void) |
1da177e4 | 537 | { |
1da177e4 LT |
538 | acpi_bus_unregister_driver(&acpi_button_driver); |
539 | ||
4be44fcd | 540 | if (acpi_power_dir) |
b34a8030 AS |
541 | remove_proc_entry(ACPI_BUTTON_SUBCLASS_POWER, acpi_button_dir); |
542 | if (acpi_sleep_dir) | |
543 | remove_proc_entry(ACPI_BUTTON_SUBCLASS_SLEEP, acpi_button_dir); | |
544 | if (acpi_lid_dir) | |
545 | remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir); | |
546 | remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir); | |
1da177e4 LT |
547 | } |
548 | ||
1da177e4 LT |
549 | module_init(acpi_button_init); |
550 | module_exit(acpi_button_exit); |