diff options
Diffstat (limited to 'drivers/acpi/button.c')
-rw-r--r-- | drivers/acpi/button.c | 86 |
1 files changed, 32 insertions, 54 deletions
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c index 4b6d9f0096a..5ef885e82c7 100644 --- a/drivers/acpi/button.c +++ b/drivers/acpi/button.c | |||
@@ -82,20 +82,19 @@ static struct acpi_driver acpi_button_driver = { | |||
82 | }; | 82 | }; |
83 | 83 | ||
84 | struct acpi_button { | 84 | struct acpi_button { |
85 | acpi_handle handle; | ||
86 | struct acpi_device *device; /* Fixed button kludge */ | 85 | struct acpi_device *device; /* Fixed button kludge */ |
87 | u8 type; | 86 | u8 type; |
88 | unsigned long pushed; | 87 | unsigned long pushed; |
89 | }; | 88 | }; |
90 | 89 | ||
91 | static struct file_operations acpi_button_info_fops = { | 90 | static const struct file_operations acpi_button_info_fops = { |
92 | .open = acpi_button_info_open_fs, | 91 | .open = acpi_button_info_open_fs, |
93 | .read = seq_read, | 92 | .read = seq_read, |
94 | .llseek = seq_lseek, | 93 | .llseek = seq_lseek, |
95 | .release = single_release, | 94 | .release = single_release, |
96 | }; | 95 | }; |
97 | 96 | ||
98 | static struct file_operations acpi_button_state_fops = { | 97 | static const struct file_operations acpi_button_state_fops = { |
99 | .open = acpi_button_state_open_fs, | 98 | .open = acpi_button_state_open_fs, |
100 | .read = seq_read, | 99 | .read = seq_read, |
101 | .llseek = seq_lseek, | 100 | .llseek = seq_lseek, |
@@ -112,15 +111,14 @@ static int acpi_button_info_seq_show(struct seq_file *seq, void *offset) | |||
112 | { | 111 | { |
113 | struct acpi_button *button = (struct acpi_button *)seq->private; | 112 | struct acpi_button *button = (struct acpi_button *)seq->private; |
114 | 113 | ||
115 | ACPI_FUNCTION_TRACE("acpi_button_info_seq_show"); | ||
116 | 114 | ||
117 | if (!button || !button->device) | 115 | if (!button || !button->device) |
118 | return_VALUE(0); | 116 | return 0; |
119 | 117 | ||
120 | seq_printf(seq, "type: %s\n", | 118 | seq_printf(seq, "type: %s\n", |
121 | acpi_device_name(button->device)); | 119 | acpi_device_name(button->device)); |
122 | 120 | ||
123 | return_VALUE(0); | 121 | return 0; |
124 | } | 122 | } |
125 | 123 | ||
126 | static int acpi_button_info_open_fs(struct inode *inode, struct file *file) | 124 | static int acpi_button_info_open_fs(struct inode *inode, struct file *file) |
@@ -134,12 +132,11 @@ static int acpi_button_state_seq_show(struct seq_file *seq, void *offset) | |||
134 | acpi_status status; | 132 | acpi_status status; |
135 | unsigned long state; | 133 | unsigned long state; |
136 | 134 | ||
137 | ACPI_FUNCTION_TRACE("acpi_button_state_seq_show"); | ||
138 | 135 | ||
139 | if (!button || !button->device) | 136 | if (!button || !button->device) |
140 | return_VALUE(0); | 137 | return 0; |
141 | 138 | ||
142 | status = acpi_evaluate_integer(button->handle, "_LID", NULL, &state); | 139 | status = acpi_evaluate_integer(button->device->handle, "_LID", NULL, &state); |
143 | if (ACPI_FAILURE(status)) { | 140 | if (ACPI_FAILURE(status)) { |
144 | seq_printf(seq, "state: unsupported\n"); | 141 | seq_printf(seq, "state: unsupported\n"); |
145 | } else { | 142 | } else { |
@@ -147,7 +144,7 @@ static int acpi_button_state_seq_show(struct seq_file *seq, void *offset) | |||
147 | (state ? "open" : "closed")); | 144 | (state ? "open" : "closed")); |
148 | } | 145 | } |
149 | 146 | ||
150 | return_VALUE(0); | 147 | return 0; |
151 | } | 148 | } |
152 | 149 | ||
153 | static int acpi_button_state_open_fs(struct inode *inode, struct file *file) | 150 | static int acpi_button_state_open_fs(struct inode *inode, struct file *file) |
@@ -164,10 +161,9 @@ static int acpi_button_add_fs(struct acpi_device *device) | |||
164 | struct proc_dir_entry *entry = NULL; | 161 | struct proc_dir_entry *entry = NULL; |
165 | struct acpi_button *button = NULL; | 162 | struct acpi_button *button = NULL; |
166 | 163 | ||
167 | ACPI_FUNCTION_TRACE("acpi_button_add_fs"); | ||
168 | 164 | ||
169 | if (!device || !acpi_driver_data(device)) | 165 | if (!device || !acpi_driver_data(device)) |
170 | return_VALUE(-EINVAL); | 166 | return -EINVAL; |
171 | 167 | ||
172 | button = acpi_driver_data(device); | 168 | button = acpi_driver_data(device); |
173 | 169 | ||
@@ -195,21 +191,19 @@ static int acpi_button_add_fs(struct acpi_device *device) | |||
195 | } | 191 | } |
196 | 192 | ||
197 | if (!entry) | 193 | if (!entry) |
198 | return_VALUE(-ENODEV); | 194 | return -ENODEV; |
199 | entry->owner = THIS_MODULE; | 195 | entry->owner = THIS_MODULE; |
200 | 196 | ||
201 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), entry); | 197 | acpi_device_dir(device) = proc_mkdir(acpi_device_bid(device), entry); |
202 | if (!acpi_device_dir(device)) | 198 | if (!acpi_device_dir(device)) |
203 | return_VALUE(-ENODEV); | 199 | return -ENODEV; |
204 | acpi_device_dir(device)->owner = THIS_MODULE; | 200 | acpi_device_dir(device)->owner = THIS_MODULE; |
205 | 201 | ||
206 | /* 'info' [R] */ | 202 | /* 'info' [R] */ |
207 | entry = create_proc_entry(ACPI_BUTTON_FILE_INFO, | 203 | entry = create_proc_entry(ACPI_BUTTON_FILE_INFO, |
208 | S_IRUGO, acpi_device_dir(device)); | 204 | S_IRUGO, acpi_device_dir(device)); |
209 | if (!entry) | 205 | if (!entry) |
210 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 206 | return -ENODEV; |
211 | "Unable to create '%s' fs entry\n", | ||
212 | ACPI_BUTTON_FILE_INFO)); | ||
213 | else { | 207 | else { |
214 | entry->proc_fops = &acpi_button_info_fops; | 208 | entry->proc_fops = &acpi_button_info_fops; |
215 | entry->data = acpi_driver_data(device); | 209 | entry->data = acpi_driver_data(device); |
@@ -221,9 +215,7 @@ static int acpi_button_add_fs(struct acpi_device *device) | |||
221 | entry = create_proc_entry(ACPI_BUTTON_FILE_STATE, | 215 | entry = create_proc_entry(ACPI_BUTTON_FILE_STATE, |
222 | S_IRUGO, acpi_device_dir(device)); | 216 | S_IRUGO, acpi_device_dir(device)); |
223 | if (!entry) | 217 | if (!entry) |
224 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | 218 | return -ENODEV; |
225 | "Unable to create '%s' fs entry\n", | ||
226 | ACPI_BUTTON_FILE_INFO)); | ||
227 | else { | 219 | else { |
228 | entry->proc_fops = &acpi_button_state_fops; | 220 | entry->proc_fops = &acpi_button_state_fops; |
229 | entry->data = acpi_driver_data(device); | 221 | entry->data = acpi_driver_data(device); |
@@ -231,14 +223,13 @@ static int acpi_button_add_fs(struct acpi_device *device) | |||
231 | } | 223 | } |
232 | } | 224 | } |
233 | 225 | ||
234 | return_VALUE(0); | 226 | return 0; |
235 | } | 227 | } |
236 | 228 | ||
237 | static int acpi_button_remove_fs(struct acpi_device *device) | 229 | static int acpi_button_remove_fs(struct acpi_device *device) |
238 | { | 230 | { |
239 | struct acpi_button *button = NULL; | 231 | struct acpi_button *button = NULL; |
240 | 232 | ||
241 | ACPI_FUNCTION_TRACE("acpi_button_remove_fs"); | ||
242 | 233 | ||
243 | button = acpi_driver_data(device); | 234 | button = acpi_driver_data(device); |
244 | if (acpi_device_dir(device)) { | 235 | if (acpi_device_dir(device)) { |
@@ -253,7 +244,7 @@ static int acpi_button_remove_fs(struct acpi_device *device) | |||
253 | acpi_device_dir(device) = NULL; | 244 | acpi_device_dir(device) = NULL; |
254 | } | 245 | } |
255 | 246 | ||
256 | return_VALUE(0); | 247 | return 0; |
257 | } | 248 | } |
258 | 249 | ||
259 | /* -------------------------------------------------------------------------- | 250 | /* -------------------------------------------------------------------------- |
@@ -264,10 +255,9 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data) | |||
264 | { | 255 | { |
265 | struct acpi_button *button = (struct acpi_button *)data; | 256 | struct acpi_button *button = (struct acpi_button *)data; |
266 | 257 | ||
267 | ACPI_FUNCTION_TRACE("acpi_button_notify"); | ||
268 | 258 | ||
269 | if (!button || !button->device) | 259 | if (!button || !button->device) |
270 | return_VOID; | 260 | return; |
271 | 261 | ||
272 | switch (event) { | 262 | switch (event) { |
273 | case ACPI_BUTTON_NOTIFY_STATUS: | 263 | case ACPI_BUTTON_NOTIFY_STATUS: |
@@ -280,21 +270,20 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data) | |||
280 | break; | 270 | break; |
281 | } | 271 | } |
282 | 272 | ||
283 | return_VOID; | 273 | return; |
284 | } | 274 | } |
285 | 275 | ||
286 | static acpi_status acpi_button_notify_fixed(void *data) | 276 | static acpi_status acpi_button_notify_fixed(void *data) |
287 | { | 277 | { |
288 | struct acpi_button *button = (struct acpi_button *)data; | 278 | struct acpi_button *button = (struct acpi_button *)data; |
289 | 279 | ||
290 | ACPI_FUNCTION_TRACE("acpi_button_notify_fixed"); | ||
291 | 280 | ||
292 | if (!button) | 281 | if (!button) |
293 | return_ACPI_STATUS(AE_BAD_PARAMETER); | 282 | return AE_BAD_PARAMETER; |
294 | 283 | ||
295 | acpi_button_notify(button->handle, ACPI_BUTTON_NOTIFY_STATUS, button); | 284 | acpi_button_notify(button->device->handle, ACPI_BUTTON_NOTIFY_STATUS, button); |
296 | 285 | ||
297 | return_ACPI_STATUS(AE_OK); | 286 | return AE_OK; |
298 | } | 287 | } |
299 | 288 | ||
300 | static int acpi_button_add(struct acpi_device *device) | 289 | static int acpi_button_add(struct acpi_device *device) |
@@ -303,18 +292,16 @@ static int acpi_button_add(struct acpi_device *device) | |||
303 | acpi_status status = AE_OK; | 292 | acpi_status status = AE_OK; |
304 | struct acpi_button *button = NULL; | 293 | struct acpi_button *button = NULL; |
305 | 294 | ||
306 | ACPI_FUNCTION_TRACE("acpi_button_add"); | ||
307 | 295 | ||
308 | if (!device) | 296 | if (!device) |
309 | return_VALUE(-EINVAL); | 297 | return -EINVAL; |
310 | 298 | ||
311 | button = kmalloc(sizeof(struct acpi_button), GFP_KERNEL); | 299 | button = kmalloc(sizeof(struct acpi_button), GFP_KERNEL); |
312 | if (!button) | 300 | if (!button) |
313 | return_VALUE(-ENOMEM); | 301 | return -ENOMEM; |
314 | memset(button, 0, sizeof(struct acpi_button)); | 302 | memset(button, 0, sizeof(struct acpi_button)); |
315 | 303 | ||
316 | button->device = device; | 304 | button->device = device; |
317 | button->handle = device->handle; | ||
318 | acpi_driver_data(device) = button; | 305 | acpi_driver_data(device) = button; |
319 | 306 | ||
320 | /* | 307 | /* |
@@ -349,8 +336,8 @@ static int acpi_button_add(struct acpi_device *device) | |||
349 | sprintf(acpi_device_class(device), "%s/%s", | 336 | sprintf(acpi_device_class(device), "%s/%s", |
350 | ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID); | 337 | ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID); |
351 | } else { | 338 | } else { |
352 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, "Unsupported hid [%s]\n", | 339 | printk(KERN_ERR PREFIX "Unsupported hid [%s]\n", |
353 | acpi_device_hid(device))); | 340 | acpi_device_hid(device)); |
354 | result = -ENODEV; | 341 | result = -ENODEV; |
355 | goto end; | 342 | goto end; |
356 | } | 343 | } |
@@ -373,7 +360,7 @@ static int acpi_button_add(struct acpi_device *device) | |||
373 | button); | 360 | button); |
374 | break; | 361 | break; |
375 | default: | 362 | default: |
376 | status = acpi_install_notify_handler(button->handle, | 363 | status = acpi_install_notify_handler(device->handle, |
377 | ACPI_DEVICE_NOTIFY, | 364 | ACPI_DEVICE_NOTIFY, |
378 | acpi_button_notify, | 365 | acpi_button_notify, |
379 | button); | 366 | button); |
@@ -381,8 +368,6 @@ static int acpi_button_add(struct acpi_device *device) | |||
381 | } | 368 | } |
382 | 369 | ||
383 | if (ACPI_FAILURE(status)) { | 370 | if (ACPI_FAILURE(status)) { |
384 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | ||
385 | "Error installing notify handler\n")); | ||
386 | result = -ENODEV; | 371 | result = -ENODEV; |
387 | goto end; | 372 | goto end; |
388 | } | 373 | } |
@@ -406,7 +391,7 @@ static int acpi_button_add(struct acpi_device *device) | |||
406 | kfree(button); | 391 | kfree(button); |
407 | } | 392 | } |
408 | 393 | ||
409 | return_VALUE(result); | 394 | return result; |
410 | } | 395 | } |
411 | 396 | ||
412 | static int acpi_button_remove(struct acpi_device *device, int type) | 397 | static int acpi_button_remove(struct acpi_device *device, int type) |
@@ -414,10 +399,9 @@ static int acpi_button_remove(struct acpi_device *device, int type) | |||
414 | acpi_status status = 0; | 399 | acpi_status status = 0; |
415 | struct acpi_button *button = NULL; | 400 | struct acpi_button *button = NULL; |
416 | 401 | ||
417 | ACPI_FUNCTION_TRACE("acpi_button_remove"); | ||
418 | 402 | ||
419 | if (!device || !acpi_driver_data(device)) | 403 | if (!device || !acpi_driver_data(device)) |
420 | return_VALUE(-EINVAL); | 404 | return -EINVAL; |
421 | 405 | ||
422 | button = acpi_driver_data(device); | 406 | button = acpi_driver_data(device); |
423 | 407 | ||
@@ -434,45 +418,39 @@ static int acpi_button_remove(struct acpi_device *device, int type) | |||
434 | acpi_button_notify_fixed); | 418 | acpi_button_notify_fixed); |
435 | break; | 419 | break; |
436 | default: | 420 | default: |
437 | status = acpi_remove_notify_handler(button->handle, | 421 | status = acpi_remove_notify_handler(device->handle, |
438 | ACPI_DEVICE_NOTIFY, | 422 | ACPI_DEVICE_NOTIFY, |
439 | acpi_button_notify); | 423 | acpi_button_notify); |
440 | break; | 424 | break; |
441 | } | 425 | } |
442 | 426 | ||
443 | if (ACPI_FAILURE(status)) | ||
444 | ACPI_DEBUG_PRINT((ACPI_DB_ERROR, | ||
445 | "Error removing notify handler\n")); | ||
446 | |||
447 | acpi_button_remove_fs(device); | 427 | acpi_button_remove_fs(device); |
448 | 428 | ||
449 | kfree(button); | 429 | kfree(button); |
450 | 430 | ||
451 | return_VALUE(0); | 431 | return 0; |
452 | } | 432 | } |
453 | 433 | ||
454 | static int __init acpi_button_init(void) | 434 | static int __init acpi_button_init(void) |
455 | { | 435 | { |
456 | int result = 0; | 436 | int result = 0; |
457 | 437 | ||
458 | ACPI_FUNCTION_TRACE("acpi_button_init"); | ||
459 | 438 | ||
460 | acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir); | 439 | acpi_button_dir = proc_mkdir(ACPI_BUTTON_CLASS, acpi_root_dir); |
461 | if (!acpi_button_dir) | 440 | if (!acpi_button_dir) |
462 | return_VALUE(-ENODEV); | 441 | return -ENODEV; |
463 | acpi_button_dir->owner = THIS_MODULE; | 442 | acpi_button_dir->owner = THIS_MODULE; |
464 | result = acpi_bus_register_driver(&acpi_button_driver); | 443 | result = acpi_bus_register_driver(&acpi_button_driver); |
465 | if (result < 0) { | 444 | if (result < 0) { |
466 | remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir); | 445 | remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir); |
467 | return_VALUE(-ENODEV); | 446 | return -ENODEV; |
468 | } | 447 | } |
469 | 448 | ||
470 | return_VALUE(0); | 449 | return 0; |
471 | } | 450 | } |
472 | 451 | ||
473 | static void __exit acpi_button_exit(void) | 452 | static void __exit acpi_button_exit(void) |
474 | { | 453 | { |
475 | ACPI_FUNCTION_TRACE("acpi_button_exit"); | ||
476 | 454 | ||
477 | acpi_bus_unregister_driver(&acpi_button_driver); | 455 | acpi_bus_unregister_driver(&acpi_button_driver); |
478 | 456 | ||
@@ -484,7 +462,7 @@ static void __exit acpi_button_exit(void) | |||
484 | remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir); | 462 | remove_proc_entry(ACPI_BUTTON_SUBCLASS_LID, acpi_button_dir); |
485 | remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir); | 463 | remove_proc_entry(ACPI_BUTTON_CLASS, acpi_root_dir); |
486 | 464 | ||
487 | return_VOID; | 465 | return; |
488 | } | 466 | } |
489 | 467 | ||
490 | module_init(acpi_button_init); | 468 | module_init(acpi_button_init); |