Commit 040159e0 authored by Ben Walsh's avatar Ben Walsh Committed by Tzung-Bi Shih
Browse files

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: default avatarDustin L. Howett <dustin@howett.net>
Signed-off-by: default avatarBen Walsh <ben@jubnut.com>
Link: https://lore.kernel.org/r/20240605063351.14836-4-ben@jubnut.com


Signed-off-by: default avatarTzung-Bi Shih <tzungbi@kernel.org>
parent 60c7df66
Loading
Loading
Loading
Loading
+38 −12
Original line number Diff line number Diff line
@@ -39,6 +39,11 @@ static bool cros_ec_lpc_acpi_device_found;
 * be used as the base port for EC mapped memory.
 */
#define CROS_EC_LPC_QUIRK_REMAP_MEMORY              BIT(0)
/*
 * Indicates that lpc_driver_data.quirk_acpi_id should be used to find
 * the ACPI device.
 */
#define CROS_EC_LPC_QUIRK_ACPI_ID                   BIT(1)

/**
 * struct lpc_driver_data - driver data attached to a DMI device ID to indicate
@@ -46,10 +51,12 @@ static bool cros_ec_lpc_acpi_device_found;
 * @quirks: a bitfield composed of quirks from CROS_EC_LPC_QUIRK_*
 * @quirk_mmio_memory_base: The first I/O port addressing EC mapped memory (used
 *                          when quirk ...REMAP_MEMORY is set.)
 * @quirk_acpi_id: An ACPI HID to be used to find the ACPI device.
 */
struct lpc_driver_data {
	u32 quirks;
	u16 quirk_mmio_memory_base;
	const char *quirk_acpi_id;
};

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

static acpi_status cros_ec_lpc_parse_device(acpi_handle handle, u32 level,
					    void *context, void **retval)
{
	*(struct acpi_device **)context = acpi_fetch_acpi_dev(handle);
	return AE_CTRL_TERMINATE;
}

static struct acpi_device *cros_ec_lpc_get_device(const char *id)
{
	struct acpi_device *adev = NULL;
	acpi_status status = acpi_get_devices(id, cros_ec_lpc_parse_device,
					      &adev, NULL);
	if (ACPI_FAILURE(status)) {
		pr_warn(DRV_NAME ": Looking for %s failed\n", id);
		return NULL;
	}

	return adev;
}

static int cros_ec_lpc_probe(struct platform_device *pdev)
{
	struct device *dev = &pdev->dev;
@@ -445,6 +472,16 @@ static int cros_ec_lpc_probe(struct platform_device *pdev)

		if (quirks & CROS_EC_LPC_QUIRK_REMAP_MEMORY)
			ec_lpc->mmio_memory_base = driver_data->quirk_mmio_memory_base;

		if (quirks & CROS_EC_LPC_QUIRK_ACPI_ID) {
			adev = cros_ec_lpc_get_device(driver_data->quirk_acpi_id);
			if (!adev) {
				dev_err(dev, "failed to get ACPI device '%s'",
					driver_data->quirk_acpi_id);
				return -ENODEV;
			}
			ACPI_COMPANION_SET(dev, adev);
		}
	}

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

static acpi_status cros_ec_lpc_parse_device(acpi_handle handle, u32 level,
					    void *context, void **retval)
{
	*(bool *)context = true;
	return AE_CTRL_TERMINATE;
}

static int __init cros_ec_lpc_init(void)
{
	int ret;
	acpi_status status;
	const struct dmi_system_id *dmi_match;

	status = acpi_get_devices(ACPI_DRV_NAME, cros_ec_lpc_parse_device,
				  &cros_ec_lpc_acpi_device_found, NULL);
	if (ACPI_FAILURE(status))
		pr_warn(DRV_NAME ": Looking for %s failed\n", ACPI_DRV_NAME);
	cros_ec_lpc_acpi_device_found = !!cros_ec_lpc_get_device(ACPI_DRV_NAME);

	dmi_match = dmi_first_match(cros_ec_lpc_dmi_table);