@@ -522,15 +522,99 @@ static int acpi_lid_input_open(struct input_dev *input)
522522 return 0 ;
523523}
524524
525+ static acpi_notify_handler acpi_button_notify_handler (struct acpi_button * button )
526+ {
527+ if (button -> type == ACPI_BUTTON_TYPE_LID )
528+ return acpi_lid_notify ;
529+
530+ return acpi_button_notify ;
531+ }
532+
533+ static void acpi_button_remove_event_handler (struct acpi_button * button )
534+ {
535+ struct acpi_device * adev = button -> adev ;
536+
537+ switch (adev -> device_type ) {
538+ case ACPI_BUS_TYPE_POWER_BUTTON :
539+ acpi_remove_fixed_event_handler (ACPI_EVENT_POWER_BUTTON ,
540+ acpi_button_event );
541+ break ;
542+
543+ case ACPI_BUS_TYPE_SLEEP_BUTTON :
544+ acpi_remove_fixed_event_handler (ACPI_EVENT_SLEEP_BUTTON ,
545+ acpi_button_event );
546+ break ;
547+
548+ default :
549+ if (button -> gpe_enabled ) {
550+ dev_dbg (button -> dev , "Disabling ACPI GPE%02llx\n" ,
551+ adev -> wakeup .gpe_number );
552+ acpi_disable_gpe (adev -> wakeup .gpe_device ,
553+ adev -> wakeup .gpe_number );
554+ }
555+ acpi_remove_notify_handler (adev -> handle , ACPI_ALL_NOTIFY ,
556+ acpi_button_notify_handler (button ));
557+ break ;
558+ }
559+ acpi_os_wait_events_complete ();
560+ }
561+
562+ static int acpi_button_add_fixed_event_handler (u32 event ,
563+ struct acpi_button * button )
564+ {
565+ acpi_status status ;
566+
567+ status = acpi_install_fixed_event_handler (event , acpi_button_event , button );
568+ if (ACPI_FAILURE (status ))
569+ return - ENODEV ;
570+
571+ return 0 ;
572+ }
573+
574+ static int acpi_button_add_event_handler (struct acpi_button * button )
575+ {
576+ struct acpi_device * adev = button -> adev ;
577+ acpi_status status ;
578+
579+ if (adev -> device_type == ACPI_BUS_TYPE_POWER_BUTTON )
580+ return acpi_button_add_fixed_event_handler (ACPI_EVENT_POWER_BUTTON ,
581+ button );
582+
583+ if (adev -> device_type == ACPI_BUS_TYPE_SLEEP_BUTTON )
584+ return acpi_button_add_fixed_event_handler (ACPI_EVENT_SLEEP_BUTTON ,
585+ button );
586+
587+ status = acpi_install_notify_handler (adev -> handle , ACPI_ALL_NOTIFY ,
588+ acpi_button_notify_handler (button ),
589+ button );
590+ if (ACPI_FAILURE (status ))
591+ return - ENODEV ;
592+
593+ if (!adev -> wakeup .flags .valid )
594+ return 0 ;
595+
596+ /*
597+ * If the wakeup GPE has a handler method, enable it in case it is also
598+ * used for signaling runtime events.
599+ */
600+ status = acpi_enable_gpe_cond (adev -> wakeup .gpe_device ,
601+ adev -> wakeup .gpe_number ,
602+ ACPI_GPE_DISPATCH_METHOD );
603+ button -> gpe_enabled = ACPI_SUCCESS (status );
604+ if (button -> gpe_enabled )
605+ dev_dbg (button -> dev , "Enabled ACPI GPE%02llx\n" ,
606+ adev -> wakeup .gpe_number );
607+
608+ return 0 ;
609+ }
610+
525611static int acpi_button_probe (struct platform_device * pdev )
526612{
527613 struct device * dev = & pdev -> dev ;
528614 struct acpi_device * device = ACPI_COMPANION (dev );
529615 const struct acpi_device_id * id ;
530- acpi_notify_handler handler ;
531616 struct acpi_button * button ;
532617 struct input_dev * input ;
533- acpi_status status ;
534618 u8 button_type ;
535619 int error = 0 ;
536620
@@ -567,8 +651,6 @@ static int acpi_button_probe(struct platform_device *pdev)
567651 input_set_capability (input , EV_SW , SW_LID );
568652 input -> open = acpi_lid_input_open ;
569653
570- handler = acpi_lid_notify ;
571-
572654 error = acpi_lid_add_fs (button );
573655 if (error ) {
574656 input_free_device (input );
@@ -582,17 +664,13 @@ static int acpi_button_probe(struct platform_device *pdev)
582664 input -> name = ACPI_BUTTON_DEVICE_NAME_POWER ;
583665 input_set_capability (input , EV_KEY , KEY_POWER );
584666 input_set_capability (input , EV_KEY , KEY_WAKEUP );
585-
586- handler = acpi_button_notify ;
587667 break ;
588668
589669 case ACPI_BUTTON_TYPE_SLEEP :
590670 button -> class = ACPI_BUTTON_CLASS_SLEEP ;
591671
592672 input -> name = ACPI_BUTTON_DEVICE_NAME_SLEEP ;
593673 input_set_capability (input , EV_KEY , KEY_SLEEP );
594-
595- handler = acpi_button_notify ;
596674 break ;
597675
598676 default :
@@ -618,42 +696,9 @@ static int acpi_button_probe(struct platform_device *pdev)
618696
619697 device_init_wakeup (button -> dev , true);
620698
621- switch (device -> device_type ) {
622- case ACPI_BUS_TYPE_POWER_BUTTON :
623- status = acpi_install_fixed_event_handler (ACPI_EVENT_POWER_BUTTON ,
624- acpi_button_event ,
625- button );
626- break ;
627- case ACPI_BUS_TYPE_SLEEP_BUTTON :
628- status = acpi_install_fixed_event_handler (ACPI_EVENT_SLEEP_BUTTON ,
629- acpi_button_event ,
630- button );
631- break ;
632- default :
633- status = acpi_install_notify_handler (device -> handle ,
634- ACPI_ALL_NOTIFY , handler ,
635- button );
636- if (ACPI_SUCCESS (status ) && device -> wakeup .flags .valid ) {
637- acpi_status st ;
638-
639- /*
640- * If the wakeup GPE has a handler method, enable it in
641- * case it is also used for signaling runtime events.
642- */
643- st = acpi_enable_gpe_cond (device -> wakeup .gpe_device ,
644- device -> wakeup .gpe_number ,
645- ACPI_GPE_DISPATCH_METHOD );
646- button -> gpe_enabled = ACPI_SUCCESS (st );
647- if (button -> gpe_enabled )
648- dev_dbg (button -> dev , "Enabled ACPI GPE%02llx\n" ,
649- device -> wakeup .gpe_number );
650- }
651- break ;
652- }
653- if (ACPI_FAILURE (status )) {
654- error = - ENODEV ;
699+ error = acpi_button_add_event_handler (button );
700+ if (error )
655701 goto err_input_unregister ;
656- }
657702
658703 if (button_type == ACPI_BUTTON_TYPE_LID ) {
659704 /*
@@ -686,29 +731,7 @@ static void acpi_button_remove(struct platform_device *pdev)
686731 if (button -> type == ACPI_BUTTON_TYPE_LID )
687732 acpi_lid_forget (adev );
688733
689- switch (adev -> device_type ) {
690- case ACPI_BUS_TYPE_POWER_BUTTON :
691- acpi_remove_fixed_event_handler (ACPI_EVENT_POWER_BUTTON ,
692- acpi_button_event );
693- break ;
694- case ACPI_BUS_TYPE_SLEEP_BUTTON :
695- acpi_remove_fixed_event_handler (ACPI_EVENT_SLEEP_BUTTON ,
696- acpi_button_event );
697- break ;
698- default :
699- if (button -> gpe_enabled ) {
700- dev_dbg (button -> dev , "Disabling ACPI GPE%02llx\n" ,
701- adev -> wakeup .gpe_number );
702- acpi_disable_gpe (adev -> wakeup .gpe_device ,
703- adev -> wakeup .gpe_number );
704- }
705- acpi_remove_notify_handler (adev -> handle , ACPI_ALL_NOTIFY ,
706- button -> type == ACPI_BUTTON_TYPE_LID ?
707- acpi_lid_notify :
708- acpi_button_notify );
709- break ;
710- }
711- acpi_os_wait_events_complete ();
734+ acpi_button_remove_event_handler (button );
712735
713736 device_init_wakeup (button -> dev , false);
714737
0 commit comments