Skip to content

Commit 040159e

Browse files
walshbTzung-Bi Shih
authored andcommitted
platform/chrome: cros_ec_lpc: Add a new quirk for ACPI id
Framework Laptops' ACPI exposes the EC with id "PNP0C09". But "PNP0C09" is part of the ACPI standard; there are lots of computers with EC chips with this id, and most of them don't support the cros_ec protocol. The driver could find the ACPI device by having "PNP0C09" in the acpi_match_table, but this would match devices which don't support the cros_ec protocol. Instead, add a new quirk "CROS_EC_LPC_QUIRK_ACPI_ID" which allows the id to be specified. This quirk is applied after the DMI check shows that the device is supported. Tested-by: Dustin L. Howett <[email protected]> Signed-off-by: Ben Walsh <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Tzung-Bi Shih <[email protected]>
1 parent 60c7df6 commit 040159e

File tree

1 file changed

+38
-12
lines changed

1 file changed

+38
-12
lines changed

drivers/platform/chrome/cros_ec_lpc.c

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,24 @@ static bool cros_ec_lpc_acpi_device_found;
3939
* be used as the base port for EC mapped memory.
4040
*/
4141
#define CROS_EC_LPC_QUIRK_REMAP_MEMORY BIT(0)
42+
/*
43+
* Indicates that lpc_driver_data.quirk_acpi_id should be used to find
44+
* the ACPI device.
45+
*/
46+
#define CROS_EC_LPC_QUIRK_ACPI_ID BIT(1)
4247

4348
/**
4449
* struct lpc_driver_data - driver data attached to a DMI device ID to indicate
4550
* hardware quirks.
4651
* @quirks: a bitfield composed of quirks from CROS_EC_LPC_QUIRK_*
4752
* @quirk_mmio_memory_base: The first I/O port addressing EC mapped memory (used
4853
* when quirk ...REMAP_MEMORY is set.)
54+
* @quirk_acpi_id: An ACPI HID to be used to find the ACPI device.
4955
*/
5056
struct lpc_driver_data {
5157
u32 quirks;
5258
u16 quirk_mmio_memory_base;
59+
const char *quirk_acpi_id;
5360
};
5461

5562
/**
@@ -418,6 +425,26 @@ static void cros_ec_lpc_acpi_notify(acpi_handle device, u32 value, void *data)
418425
pm_system_wakeup();
419426
}
420427

428+
static acpi_status cros_ec_lpc_parse_device(acpi_handle handle, u32 level,
429+
void *context, void **retval)
430+
{
431+
*(struct acpi_device **)context = acpi_fetch_acpi_dev(handle);
432+
return AE_CTRL_TERMINATE;
433+
}
434+
435+
static struct acpi_device *cros_ec_lpc_get_device(const char *id)
436+
{
437+
struct acpi_device *adev = NULL;
438+
acpi_status status = acpi_get_devices(id, cros_ec_lpc_parse_device,
439+
&adev, NULL);
440+
if (ACPI_FAILURE(status)) {
441+
pr_warn(DRV_NAME ": Looking for %s failed\n", id);
442+
return NULL;
443+
}
444+
445+
return adev;
446+
}
447+
421448
static int cros_ec_lpc_probe(struct platform_device *pdev)
422449
{
423450
struct device *dev = &pdev->dev;
@@ -445,6 +472,16 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)
445472

446473
if (quirks & CROS_EC_LPC_QUIRK_REMAP_MEMORY)
447474
ec_lpc->mmio_memory_base = driver_data->quirk_mmio_memory_base;
475+
476+
if (quirks & CROS_EC_LPC_QUIRK_ACPI_ID) {
477+
adev = cros_ec_lpc_get_device(driver_data->quirk_acpi_id);
478+
if (!adev) {
479+
dev_err(dev, "failed to get ACPI device '%s'",
480+
driver_data->quirk_acpi_id);
481+
return -ENODEV;
482+
}
483+
ACPI_COMPANION_SET(dev, adev);
484+
}
448485
}
449486

450487
/*
@@ -709,23 +746,12 @@ static struct platform_device cros_ec_lpc_device = {
709746
.name = DRV_NAME
710747
};
711748

712-
static acpi_status cros_ec_lpc_parse_device(acpi_handle handle, u32 level,
713-
void *context, void **retval)
714-
{
715-
*(bool *)context = true;
716-
return AE_CTRL_TERMINATE;
717-
}
718-
719749
static int __init cros_ec_lpc_init(void)
720750
{
721751
int ret;
722-
acpi_status status;
723752
const struct dmi_system_id *dmi_match;
724753

725-
status = acpi_get_devices(ACPI_DRV_NAME, cros_ec_lpc_parse_device,
726-
&cros_ec_lpc_acpi_device_found, NULL);
727-
if (ACPI_FAILURE(status))
728-
pr_warn(DRV_NAME ": Looking for %s failed\n", ACPI_DRV_NAME);
754+
cros_ec_lpc_acpi_device_found = !!cros_ec_lpc_get_device(ACPI_DRV_NAME);
729755

730756
dmi_match = dmi_first_match(cros_ec_lpc_dmi_table);
731757

0 commit comments

Comments
 (0)