@@ -398,12 +398,10 @@ static void acpi_lid_initialize_state(struct acpi_device *device)
398398 button -> lid_state_initialized = true;
399399}
400400
401- static void acpi_button_notify (acpi_handle handle , u32 event , void * data )
401+ static void acpi_lid_notify (acpi_handle handle , u32 event , void * data )
402402{
403403 struct acpi_device * device = data ;
404404 struct acpi_button * button ;
405- struct input_dev * input ;
406- int keycode ;
407405
408406 if (event != ACPI_BUTTON_NOTIFY_STATUS ) {
409407 acpi_handle_debug (device -> handle , "Unsupported event [0x%x]\n" ,
@@ -412,16 +410,28 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
412410 }
413411
414412 button = acpi_driver_data (device );
413+ if (!button -> lid_state_initialized )
414+ return ;
415415
416- if (button -> type == ACPI_BUTTON_TYPE_LID ) {
417- if (button -> lid_state_initialized )
418- acpi_lid_update_state (device , true);
416+ acpi_lid_update_state (device , true);
417+ }
419418
419+ static void acpi_button_notify (acpi_handle handle , u32 event , void * data )
420+ {
421+ struct acpi_device * device = data ;
422+ struct acpi_button * button ;
423+ struct input_dev * input ;
424+ int keycode ;
425+
426+ if (event != ACPI_BUTTON_NOTIFY_STATUS ) {
427+ acpi_handle_debug (device -> handle , "Unsupported event [0x%x]\n" ,
428+ event );
420429 return ;
421430 }
422431
423432 acpi_pm_wakeup_event (& device -> dev );
424433
434+ button = acpi_driver_data (device );
425435 if (button -> suspended )
426436 return ;
427437
@@ -488,6 +498,7 @@ static int acpi_lid_input_open(struct input_dev *input)
488498
489499static int acpi_button_add (struct acpi_device * device )
490500{
501+ acpi_notify_handler handler ;
491502 struct acpi_button * button ;
492503 struct input_dev * input ;
493504 const char * hid = acpi_device_hid (device );
@@ -517,17 +528,20 @@ static int acpi_button_add(struct acpi_device *device)
517528 if (!strcmp (hid , ACPI_BUTTON_HID_POWER ) ||
518529 !strcmp (hid , ACPI_BUTTON_HID_POWERF )) {
519530 button -> type = ACPI_BUTTON_TYPE_POWER ;
531+ handler = acpi_button_notify ;
520532 strcpy (name , ACPI_BUTTON_DEVICE_NAME_POWER );
521533 sprintf (class , "%s/%s" ,
522534 ACPI_BUTTON_CLASS , ACPI_BUTTON_SUBCLASS_POWER );
523535 } else if (!strcmp (hid , ACPI_BUTTON_HID_SLEEP ) ||
524536 !strcmp (hid , ACPI_BUTTON_HID_SLEEPF )) {
525537 button -> type = ACPI_BUTTON_TYPE_SLEEP ;
538+ handler = acpi_button_notify ;
526539 strcpy (name , ACPI_BUTTON_DEVICE_NAME_SLEEP );
527540 sprintf (class , "%s/%s" ,
528541 ACPI_BUTTON_CLASS , ACPI_BUTTON_SUBCLASS_SLEEP );
529542 } else if (!strcmp (hid , ACPI_BUTTON_HID_LID )) {
530543 button -> type = ACPI_BUTTON_TYPE_LID ;
544+ handler = acpi_lid_notify ;
531545 strcpy (name , ACPI_BUTTON_DEVICE_NAME_LID );
532546 sprintf (class , "%s/%s" ,
533547 ACPI_BUTTON_CLASS , ACPI_BUTTON_SUBCLASS_LID );
@@ -585,8 +599,7 @@ static int acpi_button_add(struct acpi_device *device)
585599 break ;
586600 default :
587601 status = acpi_install_notify_handler (device -> handle ,
588- ACPI_DEVICE_NOTIFY ,
589- acpi_button_notify ,
602+ ACPI_DEVICE_NOTIFY , handler ,
590603 device );
591604 break ;
592605 }
@@ -631,7 +644,9 @@ static void acpi_button_remove(struct acpi_device *device)
631644 break ;
632645 default :
633646 acpi_remove_notify_handler (device -> handle , ACPI_DEVICE_NOTIFY ,
634- acpi_button_notify );
647+ button -> type == ACPI_BUTTON_TYPE_LID ?
648+ acpi_lid_notify :
649+ acpi_button_notify );
635650 break ;
636651 }
637652 acpi_os_wait_events_complete ();
0 commit comments