Skip to content

Commit 98ada3c

Browse files
committed
ACPI: EC: Simplify acpi_ec_ecdt_start() and acpi_ec_init()
Notice that the return value of acpi_ec_init() is discarded anyway, so it can be void and it doesn't need to check the return values of acpi_bus_register_driver() and acpi_ec_ecdt_start() called by it. Thus the latter can be void too and it really has nothing to do if acpi_ec_add() has already found an EC matching the boot one in the namespace. Also, acpi_ec_ecdt_get_handle() can be folded into it. Modify the code accordingly and while at it create a propoer kerneldoc comment to document acpi_ec_ecdt_start() and move the remark regarding ASUS X550ZE along with the related bug URL from acpi_ec_init() into that comment. Additionally, fix up a stale comment in acpi_ec_init(). Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 03e9a0e commit 98ada3c

File tree

2 files changed

+37
-56
lines changed

2 files changed

+37
-56
lines changed

drivers/acpi/ec.c

Lines changed: 36 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,25 +1594,6 @@ static int acpi_ec_setup(struct acpi_ec *ec, struct acpi_device *device)
15941594
return ret;
15951595
}
15961596

1597-
static bool acpi_ec_ecdt_get_handle(acpi_handle *phandle)
1598-
{
1599-
struct acpi_table_ecdt *ecdt_ptr;
1600-
acpi_status status;
1601-
acpi_handle handle;
1602-
1603-
status = acpi_get_table(ACPI_SIG_ECDT, 1,
1604-
(struct acpi_table_header **)&ecdt_ptr);
1605-
if (ACPI_FAILURE(status))
1606-
return false;
1607-
1608-
status = acpi_get_handle(NULL, ecdt_ptr->id, &handle);
1609-
if (ACPI_FAILURE(status))
1610-
return false;
1611-
1612-
*phandle = handle;
1613-
return true;
1614-
}
1615-
16161597
static int acpi_ec_add(struct acpi_device *device)
16171598
{
16181599
struct acpi_ec *ec;
@@ -1784,35 +1765,42 @@ void __init acpi_ec_dsdt_probe(void)
17841765
}
17851766

17861767
/*
1787-
* If the DSDT EC is not functioning, we still need to prepare a fully
1788-
* functioning ECDT EC first in order to handle the events.
1789-
* https://bugzilla.kernel.org/show_bug.cgi?id=115021
1768+
* acpi_ec_ecdt_start - Finalize the boot ECDT EC initialization.
1769+
*
1770+
* First, look for an ACPI handle for the boot ECDT EC if acpi_ec_add() has not
1771+
* found a matching object in the namespace.
1772+
*
1773+
* Next, in case the DSDT EC is not functioning, it is still necessary to
1774+
* provide a functional ECDT EC to handle events, so add an extra device object
1775+
* to represent it (see https://bugzilla.kernel.org/show_bug.cgi?id=115021).
1776+
*
1777+
* This is useful on platforms with valid ECDT and invalid DSDT EC settings,
1778+
* like ASUS X550ZE (see https://bugzilla.kernel.org/show_bug.cgi?id=196847).
17901779
*/
1791-
static int __init acpi_ec_ecdt_start(void)
1780+
static void __init acpi_ec_ecdt_start(void)
17921781
{
1782+
struct acpi_table_ecdt *ecdt_ptr;
17931783
acpi_handle handle;
1784+
acpi_status status;
17941785

1795-
if (!boot_ec)
1796-
return -ENODEV;
1797-
/* In case acpi_ec_ecdt_start() is called after acpi_ec_add() */
1798-
if (!boot_ec_is_ecdt)
1799-
return -ENODEV;
1786+
/* Bail out if a matching EC has been found in the namespace. */
1787+
if (!boot_ec || boot_ec->handle != ACPI_ROOT_OBJECT)
1788+
return;
18001789

1801-
/*
1802-
* At this point, the namespace and the GPE is initialized, so
1803-
* start to find the namespace objects and handle the events.
1804-
*
1805-
* Note: ec->handle can be valid if this function is called after
1806-
* acpi_ec_add(), hence the fast path.
1807-
*/
1808-
if (boot_ec->handle == ACPI_ROOT_OBJECT) {
1809-
if (!acpi_ec_ecdt_get_handle(&handle))
1810-
return -ENODEV;
1811-
boot_ec->handle = handle;
1812-
}
1790+
/* Look up the object pointed to from the ECDT in the namespace. */
1791+
status = acpi_get_table(ACPI_SIG_ECDT, 1,
1792+
(struct acpi_table_header **)&ecdt_ptr);
1793+
if (ACPI_FAILURE(status))
1794+
return;
1795+
1796+
status = acpi_get_handle(NULL, ecdt_ptr->id, &handle);
1797+
if (ACPI_FAILURE(status))
1798+
return;
18131799

1814-
/* Register to ACPI bus with PM ops attached */
1815-
return acpi_bus_register_early_device(ACPI_BUS_TYPE_ECDT_EC);
1800+
boot_ec->handle = handle;
1801+
1802+
/* Add a special ACPI device object to represent the boot EC. */
1803+
acpi_bus_register_early_device(ACPI_BUS_TYPE_ECDT_EC);
18161804
}
18171805

18181806
#if 0
@@ -2156,14 +2144,13 @@ static const struct dmi_system_id acpi_ec_no_wakeup[] = {
21562144
{ },
21572145
};
21582146

2159-
int __init acpi_ec_init(void)
2147+
void __init acpi_ec_init(void)
21602148
{
21612149
int result;
2162-
int ecdt_fail, dsdt_fail;
21632150

21642151
result = acpi_ec_init_workqueues();
21652152
if (result)
2166-
return result;
2153+
return;
21672154

21682155
/*
21692156
* Disable EC wakeup on following systems to prevent periodic
@@ -2174,16 +2161,10 @@ int __init acpi_ec_init(void)
21742161
pr_debug("Disabling EC wakeup on suspend-to-idle\n");
21752162
}
21762163

2177-
/* Drivers must be started after acpi_ec_query_init() */
2178-
dsdt_fail = acpi_bus_register_driver(&acpi_ec_driver);
2179-
/*
2180-
* Register ECDT to ACPI bus only when PNP0C09 probe fails. This is
2181-
* useful for platforms (confirmed on ASUS X550ZE) with valid ECDT
2182-
* settings but invalid DSDT settings.
2183-
* https://bugzilla.kernel.org/show_bug.cgi?id=196847
2184-
*/
2185-
ecdt_fail = acpi_ec_ecdt_start();
2186-
return ecdt_fail && dsdt_fail ? -ENODEV : 0;
2164+
/* Driver must be registered after acpi_ec_init_workqueues(). */
2165+
acpi_bus_register_driver(&acpi_ec_driver);
2166+
2167+
acpi_ec_ecdt_start();
21872168
}
21882169

21892170
/* EC driver currently not unloadable */

drivers/acpi/internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ extern struct acpi_ec *first_ec;
190190
/* External interfaces use first EC only, so remember */
191191
typedef int (*acpi_ec_query_func) (void *data);
192192

193-
int acpi_ec_init(void);
193+
void acpi_ec_init(void);
194194
void acpi_ec_ecdt_probe(void);
195195
void acpi_ec_dsdt_probe(void);
196196
void acpi_ec_block_transactions(void);

0 commit comments

Comments
 (0)