@@ -398,7 +398,7 @@ static void acpi_ec_submit_request(struct acpi_ec *ec)
398
398
{
399
399
ec -> reference_count ++ ;
400
400
if (test_bit (EC_FLAGS_EVENT_HANDLER_INSTALLED , & ec -> flags ) &&
401
- ec -> reference_count == 1 )
401
+ ec -> gpe >= 0 && ec -> reference_count == 1 )
402
402
acpi_ec_enable_gpe (ec , true);
403
403
}
404
404
@@ -408,7 +408,7 @@ static void acpi_ec_complete_request(struct acpi_ec *ec)
408
408
409
409
ec -> reference_count -- ;
410
410
if (test_bit (EC_FLAGS_EVENT_HANDLER_INSTALLED , & ec -> flags ) &&
411
- ec -> reference_count == 0 )
411
+ ec -> gpe >= 0 && ec -> reference_count == 0 )
412
412
acpi_ec_disable_gpe (ec , true);
413
413
flushed = acpi_ec_flushed (ec );
414
414
if (flushed )
@@ -418,7 +418,11 @@ static void acpi_ec_complete_request(struct acpi_ec *ec)
418
418
static void acpi_ec_mask_events (struct acpi_ec * ec )
419
419
{
420
420
if (!test_bit (EC_FLAGS_EVENTS_MASKED , & ec -> flags )) {
421
- acpi_ec_disable_gpe (ec , false);
421
+ if (ec -> gpe >= 0 )
422
+ acpi_ec_disable_gpe (ec , false);
423
+ else
424
+ disable_irq_nosync (ec -> irq );
425
+
422
426
ec_dbg_drv ("Polling enabled" );
423
427
set_bit (EC_FLAGS_EVENTS_MASKED , & ec -> flags );
424
428
}
@@ -428,7 +432,11 @@ static void acpi_ec_unmask_events(struct acpi_ec *ec)
428
432
{
429
433
if (test_bit (EC_FLAGS_EVENTS_MASKED , & ec -> flags )) {
430
434
clear_bit (EC_FLAGS_EVENTS_MASKED , & ec -> flags );
431
- acpi_ec_enable_gpe (ec , false);
435
+ if (ec -> gpe >= 0 )
436
+ acpi_ec_enable_gpe (ec , false);
437
+ else
438
+ enable_irq (ec -> irq );
439
+
432
440
ec_dbg_drv ("Polling disabled" );
433
441
}
434
442
}
@@ -648,7 +656,9 @@ static void advance_transaction(struct acpi_ec *ec)
648
656
* ensure a hardware STS 0->1 change after this clearing can always
649
657
* trigger a GPE interrupt.
650
658
*/
651
- acpi_ec_clear_gpe (ec );
659
+ if (ec -> gpe >= 0 )
660
+ acpi_ec_clear_gpe (ec );
661
+
652
662
status = acpi_ec_read_status (ec );
653
663
t = ec -> curr ;
654
664
/*
@@ -1275,18 +1285,28 @@ static void acpi_ec_event_handler(struct work_struct *work)
1275
1285
acpi_ec_check_event (ec );
1276
1286
}
1277
1287
1278
- static u32 acpi_ec_gpe_handler (acpi_handle gpe_device ,
1279
- u32 gpe_number , void * data )
1288
+ static void acpi_ec_handle_interrupt (struct acpi_ec * ec )
1280
1289
{
1281
1290
unsigned long flags ;
1282
- struct acpi_ec * ec = data ;
1283
1291
1284
1292
spin_lock_irqsave (& ec -> lock , flags );
1285
1293
advance_transaction (ec );
1286
1294
spin_unlock_irqrestore (& ec -> lock , flags );
1295
+ }
1296
+
1297
+ static u32 acpi_ec_gpe_handler (acpi_handle gpe_device ,
1298
+ u32 gpe_number , void * data )
1299
+ {
1300
+ acpi_ec_handle_interrupt (data );
1287
1301
return ACPI_INTERRUPT_HANDLED ;
1288
1302
}
1289
1303
1304
+ static irqreturn_t acpi_ec_irq_handler (int irq , void * data )
1305
+ {
1306
+ acpi_ec_handle_interrupt (data );
1307
+ return IRQ_HANDLED ;
1308
+ }
1309
+
1290
1310
/* --------------------------------------------------------------------------
1291
1311
* Address Space Management
1292
1312
* -------------------------------------------------------------------------- */
@@ -1359,6 +1379,8 @@ static struct acpi_ec *acpi_ec_alloc(void)
1359
1379
ec -> timestamp = jiffies ;
1360
1380
ec -> busy_polling = true;
1361
1381
ec -> polling_guard = 0 ;
1382
+ ec -> gpe = -1 ;
1383
+ ec -> irq = -1 ;
1362
1384
return ec ;
1363
1385
}
1364
1386
@@ -1406,9 +1428,13 @@ ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
1406
1428
/* Get GPE bit assignment (EC events). */
1407
1429
/* TODO: Add support for _GPE returning a package */
1408
1430
status = acpi_evaluate_integer (handle , "_GPE" , NULL , & tmp );
1409
- if (ACPI_FAILURE (status ))
1410
- return status ;
1411
- ec -> gpe = tmp ;
1431
+ if (ACPI_SUCCESS (status ))
1432
+ ec -> gpe = tmp ;
1433
+
1434
+ /*
1435
+ * Errors are non-fatal, allowing for ACPI Reduced Hardware
1436
+ * platforms which use GpioInt instead of GPE.
1437
+ */
1412
1438
}
1413
1439
/* Use the global lock for all EC transactions? */
1414
1440
tmp = 0 ;
@@ -1418,12 +1444,57 @@ ec_parse_device(acpi_handle handle, u32 Level, void *context, void **retval)
1418
1444
return AE_CTRL_TERMINATE ;
1419
1445
}
1420
1446
1447
+ static void install_gpe_event_handler (struct acpi_ec * ec )
1448
+ {
1449
+ acpi_status status =
1450
+ acpi_install_gpe_raw_handler (NULL , ec -> gpe ,
1451
+ ACPI_GPE_EDGE_TRIGGERED ,
1452
+ & acpi_ec_gpe_handler ,
1453
+ ec );
1454
+ if (ACPI_SUCCESS (status )) {
1455
+ /* This is not fatal as we can poll EC events */
1456
+ set_bit (EC_FLAGS_EVENT_HANDLER_INSTALLED , & ec -> flags );
1457
+ acpi_ec_leave_noirq (ec );
1458
+ if (test_bit (EC_FLAGS_STARTED , & ec -> flags ) &&
1459
+ ec -> reference_count >= 1 )
1460
+ acpi_ec_enable_gpe (ec , true);
1461
+ }
1462
+ }
1463
+
1464
+ /* ACPI reduced hardware platforms use a GpioInt specified in _CRS. */
1465
+ static int install_gpio_irq_event_handler (struct acpi_ec * ec ,
1466
+ struct acpi_device * device )
1467
+ {
1468
+ int irq = acpi_dev_gpio_irq_get (device , 0 );
1469
+ int ret ;
1470
+
1471
+ if (irq < 0 )
1472
+ return irq ;
1473
+
1474
+ ret = request_irq (irq , acpi_ec_irq_handler , IRQF_SHARED ,
1475
+ "ACPI EC" , ec );
1476
+
1477
+ /*
1478
+ * Unlike the GPE case, we treat errors here as fatal, we'll only
1479
+ * implement GPIO polling if we find a case that needs it.
1480
+ */
1481
+ if (ret < 0 )
1482
+ return ret ;
1483
+
1484
+ ec -> irq = irq ;
1485
+ set_bit (EC_FLAGS_EVENT_HANDLER_INSTALLED , & ec -> flags );
1486
+ acpi_ec_leave_noirq (ec );
1487
+
1488
+ return 0 ;
1489
+ }
1490
+
1421
1491
/*
1422
1492
* Note: This function returns an error code only when the address space
1423
1493
* handler is not installed, which means "not able to handle
1424
1494
* transactions".
1425
1495
*/
1426
- static int ec_install_handlers (struct acpi_ec * ec , bool handle_events )
1496
+ static int ec_install_handlers (struct acpi_ec * ec , struct acpi_device * device ,
1497
+ bool handle_events )
1427
1498
{
1428
1499
acpi_status status ;
1429
1500
@@ -1464,16 +1535,15 @@ static int ec_install_handlers(struct acpi_ec *ec, bool handle_events)
1464
1535
set_bit (EC_FLAGS_QUERY_METHODS_INSTALLED , & ec -> flags );
1465
1536
}
1466
1537
if (!test_bit (EC_FLAGS_EVENT_HANDLER_INSTALLED , & ec -> flags )) {
1467
- status = acpi_install_gpe_raw_handler (NULL , ec -> gpe ,
1468
- ACPI_GPE_EDGE_TRIGGERED ,
1469
- & acpi_ec_gpe_handler , ec );
1470
- /* This is not fatal as we can poll EC events */
1471
- if (ACPI_SUCCESS (status )) {
1472
- set_bit (EC_FLAGS_EVENT_HANDLER_INSTALLED , & ec -> flags );
1473
- acpi_ec_leave_noirq (ec );
1474
- if (test_bit (EC_FLAGS_STARTED , & ec -> flags ) &&
1475
- ec -> reference_count >= 1 )
1476
- acpi_ec_enable_gpe (ec , true);
1538
+ if (ec -> gpe >= 0 ) {
1539
+ install_gpe_event_handler (ec );
1540
+ } else if (device ) {
1541
+ int ret = install_gpio_irq_event_handler (ec , device );
1542
+
1543
+ if (ret )
1544
+ return ret ;
1545
+ } else { /* No GPE and no GpioInt? */
1546
+ return - ENODEV ;
1477
1547
}
1478
1548
}
1479
1549
/* EC is fully operational, allow queries */
@@ -1505,9 +1575,14 @@ static void ec_remove_handlers(struct acpi_ec *ec)
1505
1575
acpi_ec_stop (ec , false);
1506
1576
1507
1577
if (test_bit (EC_FLAGS_EVENT_HANDLER_INSTALLED , & ec -> flags )) {
1508
- if (ACPI_FAILURE (acpi_remove_gpe_handler (NULL , ec -> gpe ,
1509
- & acpi_ec_gpe_handler )))
1578
+ if (ec -> gpe >= 0 &&
1579
+ ACPI_FAILURE (acpi_remove_gpe_handler (NULL , ec -> gpe ,
1580
+ & acpi_ec_gpe_handler )))
1510
1581
pr_err ("failed to remove gpe handler\n" );
1582
+
1583
+ if (ec -> irq >= 0 )
1584
+ free_irq (ec -> irq , ec );
1585
+
1511
1586
clear_bit (EC_FLAGS_EVENT_HANDLER_INSTALLED , & ec -> flags );
1512
1587
}
1513
1588
if (test_bit (EC_FLAGS_QUERY_METHODS_INSTALLED , & ec -> flags )) {
@@ -1516,11 +1591,12 @@ static void ec_remove_handlers(struct acpi_ec *ec)
1516
1591
}
1517
1592
}
1518
1593
1519
- static int acpi_ec_setup (struct acpi_ec * ec , bool handle_events )
1594
+ static int acpi_ec_setup (struct acpi_ec * ec , struct acpi_device * device ,
1595
+ bool handle_events )
1520
1596
{
1521
1597
int ret ;
1522
1598
1523
- ret = ec_install_handlers (ec , handle_events );
1599
+ ret = ec_install_handlers (ec , device , handle_events );
1524
1600
if (ret )
1525
1601
return ret ;
1526
1602
@@ -1531,8 +1607,8 @@ static int acpi_ec_setup(struct acpi_ec *ec, bool handle_events)
1531
1607
}
1532
1608
1533
1609
acpi_handle_info (ec -> handle ,
1534
- "GPE=0x%x, EC_CMD/EC_SC=0x%lx, EC_DATA=0x%lx\n" ,
1535
- ec -> gpe , ec -> command_addr , ec -> data_addr );
1610
+ "GPE=0x%x, IRQ=%d, EC_CMD/EC_SC=0x%lx, EC_DATA=0x%lx\n" ,
1611
+ ec -> gpe , ec -> irq , ec -> command_addr , ec -> data_addr );
1536
1612
return ret ;
1537
1613
}
1538
1614
@@ -1596,7 +1672,7 @@ static int acpi_ec_add(struct acpi_device *device)
1596
1672
}
1597
1673
}
1598
1674
1599
- ret = acpi_ec_setup (ec , true);
1675
+ ret = acpi_ec_setup (ec , device , true);
1600
1676
if (ret )
1601
1677
goto err_query ;
1602
1678
@@ -1716,7 +1792,7 @@ void __init acpi_ec_dsdt_probe(void)
1716
1792
* At this point, the GPE is not fully initialized, so do not to
1717
1793
* handle the events.
1718
1794
*/
1719
- ret = acpi_ec_setup (ec , false);
1795
+ ret = acpi_ec_setup (ec , NULL , false);
1720
1796
if (ret ) {
1721
1797
acpi_ec_free (ec );
1722
1798
return ;
@@ -1889,14 +1965,21 @@ void __init acpi_ec_ecdt_probe(void)
1889
1965
ec -> command_addr = ecdt_ptr -> control .address ;
1890
1966
ec -> data_addr = ecdt_ptr -> data .address ;
1891
1967
}
1892
- ec -> gpe = ecdt_ptr -> gpe ;
1968
+
1969
+ /*
1970
+ * Ignore the GPE value on Reduced Hardware platforms.
1971
+ * Some products have this set to an erroneous value.
1972
+ */
1973
+ if (!acpi_gbl_reduced_hardware )
1974
+ ec -> gpe = ecdt_ptr -> gpe ;
1975
+
1893
1976
ec -> handle = ACPI_ROOT_OBJECT ;
1894
1977
1895
1978
/*
1896
1979
* At this point, the namespace is not initialized, so do not find
1897
1980
* the namespace objects, or handle the events.
1898
1981
*/
1899
- ret = acpi_ec_setup (ec , false);
1982
+ ret = acpi_ec_setup (ec , NULL , false);
1900
1983
if (ret ) {
1901
1984
acpi_ec_free (ec );
1902
1985
return ;
@@ -1928,7 +2011,7 @@ static int acpi_ec_suspend_noirq(struct device *dev)
1928
2011
* masked at the low level without side effects.
1929
2012
*/
1930
2013
if (ec_no_wakeup && test_bit (EC_FLAGS_STARTED , & ec -> flags ) &&
1931
- ec -> reference_count >= 1 )
2014
+ ec -> gpe >= 0 && ec -> reference_count >= 1 )
1932
2015
acpi_set_gpe (NULL , ec -> gpe , ACPI_GPE_DISABLE );
1933
2016
1934
2017
acpi_ec_enter_noirq (ec );
@@ -1943,7 +2026,7 @@ static int acpi_ec_resume_noirq(struct device *dev)
1943
2026
acpi_ec_leave_noirq (ec );
1944
2027
1945
2028
if (ec_no_wakeup && test_bit (EC_FLAGS_STARTED , & ec -> flags ) &&
1946
- ec -> reference_count >= 1 )
2029
+ ec -> gpe >= 0 && ec -> reference_count >= 1 )
1947
2030
acpi_set_gpe (NULL , ec -> gpe , ACPI_GPE_ENABLE );
1948
2031
1949
2032
return 0 ;
0 commit comments