diff options
author | Bjorn Helgaas <bjorn.helgaas@hp.com> | 2009-03-30 13:48:18 -0400 |
---|---|---|
committer | Len Brown <len.brown@intel.com> | 2009-04-05 02:25:07 -0400 |
commit | 373cfc360ec773be2f7615e59a19f3313255db7c (patch) | |
tree | 86c68db2a5f5b1b400bda46370353e109c9d5482 /drivers/acpi | |
parent | 46ec8598fde74ba59703575c22a6fb0b6b151bb6 (diff) |
ACPI: button: use .notify method instead of installing handler directly
This patch adds a .notify() method. The presence of .notify() causes
Linux/ACPI to manage event handlers and notify handlers on our behalf,
so we don't have to install and remove them ourselves.
Note that events from fixed hardware buttons now show up as a special
notify event, so to preserve user-space backward compatibility, we
convert that back to ACPI_BUTTON_NOTIFY_STATUS.
Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Reviewed-by: Alex Chiang <achiang@hp.com>
CC: Alexey Starikovskiy <alexey.y.starikovskiy@linux.intel.com>
Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/acpi')
-rw-r--r-- | drivers/acpi/button.c | 77 |
1 files changed, 8 insertions, 69 deletions
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c index c2f06069dcd4..d73c94b8441d 100644 --- a/drivers/acpi/button.c +++ b/drivers/acpi/button.c | |||
@@ -78,6 +78,7 @@ MODULE_DEVICE_TABLE(acpi, button_device_ids); | |||
78 | static int acpi_button_add(struct acpi_device *device); | 78 | static int acpi_button_add(struct acpi_device *device); |
79 | static int acpi_button_remove(struct acpi_device *device, int type); | 79 | static int acpi_button_remove(struct acpi_device *device, int type); |
80 | static int acpi_button_resume(struct acpi_device *device); | 80 | static int acpi_button_resume(struct acpi_device *device); |
81 | static void acpi_button_notify(struct acpi_device *device, u32 event); | ||
81 | static int acpi_button_info_open_fs(struct inode *inode, struct file *file); | 82 | static int acpi_button_info_open_fs(struct inode *inode, struct file *file); |
82 | static int acpi_button_state_open_fs(struct inode *inode, struct file *file); | 83 | static int acpi_button_state_open_fs(struct inode *inode, struct file *file); |
83 | 84 | ||
@@ -89,6 +90,7 @@ static struct acpi_driver acpi_button_driver = { | |||
89 | .add = acpi_button_add, | 90 | .add = acpi_button_add, |
90 | .resume = acpi_button_resume, | 91 | .resume = acpi_button_resume, |
91 | .remove = acpi_button_remove, | 92 | .remove = acpi_button_remove, |
93 | .notify = acpi_button_notify, | ||
92 | }, | 94 | }, |
93 | }; | 95 | }; |
94 | 96 | ||
@@ -263,15 +265,18 @@ static int acpi_lid_send_state(struct acpi_button *button) | |||
263 | return 0; | 265 | return 0; |
264 | } | 266 | } |
265 | 267 | ||
266 | static void acpi_button_notify(acpi_handle handle, u32 event, void *data) | 268 | static void acpi_button_notify(struct acpi_device *device, u32 event) |
267 | { | 269 | { |
268 | struct acpi_button *button = data; | 270 | struct acpi_button *button = acpi_driver_data(device); |
269 | struct input_dev *input; | 271 | struct input_dev *input; |
270 | 272 | ||
271 | if (!button || !button->device) | 273 | if (!button || !button->device) |
272 | return; | 274 | return; |
273 | 275 | ||
274 | switch (event) { | 276 | switch (event) { |
277 | case ACPI_FIXED_HARDWARE_EVENT: | ||
278 | event = ACPI_BUTTON_NOTIFY_STATUS; | ||
279 | /* fall through */ | ||
275 | case ACPI_BUTTON_NOTIFY_STATUS: | 280 | case ACPI_BUTTON_NOTIFY_STATUS: |
276 | input = button->input; | 281 | input = button->input; |
277 | if (button->type == ACPI_BUTTON_TYPE_LID) { | 282 | if (button->type == ACPI_BUTTON_TYPE_LID) { |
@@ -298,46 +303,6 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data) | |||
298 | return; | 303 | return; |
299 | } | 304 | } |
300 | 305 | ||
301 | static acpi_status acpi_button_notify_fixed(void *data) | ||
302 | { | ||
303 | struct acpi_button *button = data; | ||
304 | |||
305 | if (!button) | ||
306 | return AE_BAD_PARAMETER; | ||
307 | |||
308 | acpi_button_notify(button->device->handle, ACPI_BUTTON_NOTIFY_STATUS, button); | ||
309 | |||
310 | return AE_OK; | ||
311 | } | ||
312 | |||
313 | static int acpi_button_install_notify_handlers(struct acpi_button *button) | ||
314 | { | ||
315 | acpi_status status; | ||
316 | |||
317 | switch (button->type) { | ||
318 | case ACPI_BUTTON_TYPE_POWERF: | ||
319 | status = | ||
320 | acpi_install_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, | ||
321 | acpi_button_notify_fixed, | ||
322 | button); | ||
323 | break; | ||
324 | case ACPI_BUTTON_TYPE_SLEEPF: | ||
325 | status = | ||
326 | acpi_install_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, | ||
327 | acpi_button_notify_fixed, | ||
328 | button); | ||
329 | break; | ||
330 | default: | ||
331 | status = acpi_install_notify_handler(button->device->handle, | ||
332 | ACPI_DEVICE_NOTIFY, | ||
333 | acpi_button_notify, | ||
334 | button); | ||
335 | break; | ||
336 | } | ||
337 | |||
338 | return ACPI_FAILURE(status) ? -ENODEV : 0; | ||
339 | } | ||
340 | |||
341 | static int acpi_button_resume(struct acpi_device *device) | 306 | static int acpi_button_resume(struct acpi_device *device) |
342 | { | 307 | { |
343 | struct acpi_button *button; | 308 | struct acpi_button *button; |
@@ -349,25 +314,6 @@ static int acpi_button_resume(struct acpi_device *device) | |||
349 | return 0; | 314 | return 0; |
350 | } | 315 | } |
351 | 316 | ||
352 | static void acpi_button_remove_notify_handlers(struct acpi_button *button) | ||
353 | { | ||
354 | switch (button->type) { | ||
355 | case ACPI_BUTTON_TYPE_POWERF: | ||
356 | acpi_remove_fixed_event_handler(ACPI_EVENT_POWER_BUTTON, | ||
357 | acpi_button_notify_fixed); | ||
358 | break; | ||
359 | case ACPI_BUTTON_TYPE_SLEEPF: | ||
360 | acpi_remove_fixed_event_handler(ACPI_EVENT_SLEEP_BUTTON, | ||
361 | acpi_button_notify_fixed); | ||
362 | break; | ||
363 | default: | ||
364 | acpi_remove_notify_handler(button->device->handle, | ||
365 | ACPI_DEVICE_NOTIFY, | ||
366 | acpi_button_notify); | ||
367 | break; | ||
368 | } | ||
369 | } | ||
370 | |||
371 | static int acpi_button_add(struct acpi_device *device) | 317 | static int acpi_button_add(struct acpi_device *device) |
372 | { | 318 | { |
373 | int error; | 319 | int error; |
@@ -432,10 +378,6 @@ static int acpi_button_add(struct acpi_device *device) | |||
432 | if (error) | 378 | if (error) |
433 | goto err_free_input; | 379 | goto err_free_input; |
434 | 380 | ||
435 | error = acpi_button_install_notify_handlers(button); | ||
436 | if (error) | ||
437 | goto err_remove_fs; | ||
438 | |||
439 | snprintf(button->phys, sizeof(button->phys), | 381 | snprintf(button->phys, sizeof(button->phys), |
440 | "%s/button/input0", acpi_device_hid(device)); | 382 | "%s/button/input0", acpi_device_hid(device)); |
441 | 383 | ||
@@ -466,7 +408,7 @@ static int acpi_button_add(struct acpi_device *device) | |||
466 | 408 | ||
467 | error = input_register_device(input); | 409 | error = input_register_device(input); |
468 | if (error) | 410 | if (error) |
469 | goto err_remove_handlers; | 411 | goto err_remove_fs; |
470 | if (button->type == ACPI_BUTTON_TYPE_LID) | 412 | if (button->type == ACPI_BUTTON_TYPE_LID) |
471 | acpi_lid_send_state(button); | 413 | acpi_lid_send_state(button); |
472 | 414 | ||
@@ -485,8 +427,6 @@ static int acpi_button_add(struct acpi_device *device) | |||
485 | 427 | ||
486 | return 0; | 428 | return 0; |
487 | 429 | ||
488 | err_remove_handlers: | ||
489 | acpi_button_remove_notify_handlers(button); | ||
490 | err_remove_fs: | 430 | err_remove_fs: |
491 | acpi_button_remove_fs(device); | 431 | acpi_button_remove_fs(device); |
492 | err_free_input: | 432 | err_free_input: |
@@ -505,7 +445,6 @@ static int acpi_button_remove(struct acpi_device *device, int type) | |||
505 | 445 | ||
506 | button = acpi_driver_data(device); | 446 | button = acpi_driver_data(device); |
507 | 447 | ||
508 | acpi_button_remove_notify_handlers(button); | ||
509 | acpi_button_remove_fs(device); | 448 | acpi_button_remove_fs(device); |
510 | input_unregister_device(button->input); | 449 | input_unregister_device(button->input); |
511 | kfree(button); | 450 | kfree(button); |