@@ -398,12 +398,10 @@ static void acpi_lid_initialize_state(struct acpi_device *device)
398
398
button -> lid_state_initialized = true;
399
399
}
400
400
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 )
402
402
{
403
403
struct acpi_device * device = data ;
404
404
struct acpi_button * button ;
405
- struct input_dev * input ;
406
- int keycode ;
407
405
408
406
if (event != ACPI_BUTTON_NOTIFY_STATUS ) {
409
407
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)
412
410
}
413
411
414
412
button = acpi_driver_data (device );
413
+ if (!button -> lid_state_initialized )
414
+ return ;
415
415
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
+ }
419
418
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 );
420
429
return ;
421
430
}
422
431
423
432
acpi_pm_wakeup_event (& device -> dev );
424
433
434
+ button = acpi_driver_data (device );
425
435
if (button -> suspended )
426
436
return ;
427
437
@@ -488,6 +498,7 @@ static int acpi_lid_input_open(struct input_dev *input)
488
498
489
499
static int acpi_button_add (struct acpi_device * device )
490
500
{
501
+ acpi_notify_handler handler ;
491
502
struct acpi_button * button ;
492
503
struct input_dev * input ;
493
504
const char * hid = acpi_device_hid (device );
@@ -517,17 +528,20 @@ static int acpi_button_add(struct acpi_device *device)
517
528
if (!strcmp (hid , ACPI_BUTTON_HID_POWER ) ||
518
529
!strcmp (hid , ACPI_BUTTON_HID_POWERF )) {
519
530
button -> type = ACPI_BUTTON_TYPE_POWER ;
531
+ handler = acpi_button_notify ;
520
532
strcpy (name , ACPI_BUTTON_DEVICE_NAME_POWER );
521
533
sprintf (class , "%s/%s" ,
522
534
ACPI_BUTTON_CLASS , ACPI_BUTTON_SUBCLASS_POWER );
523
535
} else if (!strcmp (hid , ACPI_BUTTON_HID_SLEEP ) ||
524
536
!strcmp (hid , ACPI_BUTTON_HID_SLEEPF )) {
525
537
button -> type = ACPI_BUTTON_TYPE_SLEEP ;
538
+ handler = acpi_button_notify ;
526
539
strcpy (name , ACPI_BUTTON_DEVICE_NAME_SLEEP );
527
540
sprintf (class , "%s/%s" ,
528
541
ACPI_BUTTON_CLASS , ACPI_BUTTON_SUBCLASS_SLEEP );
529
542
} else if (!strcmp (hid , ACPI_BUTTON_HID_LID )) {
530
543
button -> type = ACPI_BUTTON_TYPE_LID ;
544
+ handler = acpi_lid_notify ;
531
545
strcpy (name , ACPI_BUTTON_DEVICE_NAME_LID );
532
546
sprintf (class , "%s/%s" ,
533
547
ACPI_BUTTON_CLASS , ACPI_BUTTON_SUBCLASS_LID );
@@ -585,8 +599,7 @@ static int acpi_button_add(struct acpi_device *device)
585
599
break ;
586
600
default :
587
601
status = acpi_install_notify_handler (device -> handle ,
588
- ACPI_DEVICE_NOTIFY ,
589
- acpi_button_notify ,
602
+ ACPI_DEVICE_NOTIFY , handler ,
590
603
device );
591
604
break ;
592
605
}
@@ -631,7 +644,9 @@ static void acpi_button_remove(struct acpi_device *device)
631
644
break ;
632
645
default :
633
646
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 );
635
650
break ;
636
651
}
637
652
acpi_os_wait_events_complete ();
0 commit comments