Re: [PATCH] ACPI / LPSS: Add device link for CHT SD card dependency on I2C

From: Adrian Hunter
Date: Mon Dec 04 2017 - 09:42:34 EST


On 04/12/17 16:33, Hans de Goede wrote:
> Hi,
>
> On 04-12-17 15:30, Adrian Hunter wrote:
>> On 04/12/17 15:48, Hans de Goede wrote:
>>> Hi,
>>>
>>> Wouldn't it be easier to use the ACPI _DEP tracking for this, e.g.
>>
>> It is using _DEP, see acpi_lpss_dep()
>>
>>> add something like this to the the probe function:
>>>
>>> ÂÂÂÂÂstruct acpi_device = ACPI_COMPANION(device);
>>>
>>> ÂÂÂÂÂif (acpi_device->dep_unmet)
>>> ÂÂÂÂÂÂÂÂ return -EPROBE_DEFER;
>>>
>>> No idea if this will work, but if it does work, using the deps described
>>> in the ACPI tables seems like a better solution then hardcoding this.
>>
>> That would not work because there are other devices listed in the _DEP
>> method so dep_unmet is always true. So we are left checking _DEP but only
>> for specific device dependencies.
>
> Ugh, understood thank you for explaining this. Perhaps it is a good idea
> to mention in the commit message why acpi_dev->dep_unmet cannot be used
> here?

dep_unmet predates device links, but now we have device links, they are
better anyway.

>
> Regards,
>
> Hans
>
>
>>> On 04-12-17 13:32, Adrian Hunter wrote:
>>>> Some Cherry Trail boards have a dependency between the SDHCI host
>>>> controller used for SD cards and an external PMIC accessed via I2C. Add a
>>>> device link between the SDHCI host controller (consumer) and the I2C
>>>> adapter (supplier).
>>>>
>>>> This patch depends on a fix to devices links, namely commit 0ff26c662d5f
>>>> ("driver core: Fix device link deferred probe"). And also either,
>>>> commit 126dbc6b49c8 ("PM: i2c-designware-platdrv: Clean up PM handling in
>>>> probe"), or patch "PM / runtime: Fix handling of suppliers with disabled
>>>> runtime PM".
>>>>
>>>> Signed-off-by: Adrian Hunter <adrian.hunter@xxxxxxxxx>
>>>> ---
>>>> ÂÂ drivers/acpi/acpi_lpss.c | 139
>>>> +++++++++++++++++++++++++++++++++++++++++++++++
>>>> ÂÂ 1 file changed, 139 insertions(+)
>>>>
>>>> diff --git a/drivers/acpi/acpi_lpss.c b/drivers/acpi/acpi_lpss.c
>>>> index 7f2b02cc8ea1..9d82f2f6c327 100644
>>>> --- a/drivers/acpi/acpi_lpss.c
>>>> +++ b/drivers/acpi/acpi_lpss.c
>>>> @@ -290,6 +290,11 @@ static void bsw_pwm_setup(struct lpss_private_data
>>>> *pdata)
>>>> ÂÂÂÂÂÂ {}
>>>> ÂÂ };
>>>> ÂÂ +static const struct x86_cpu_id cht_cpu[] = {
>>>> +ÂÂÂ ICPU(INTEL_FAM6_ATOM_AIRMONT),ÂÂÂ /* Braswell, Cherry Trail */
>>>> +ÂÂÂ {}
>>>> +};
>>>> +
>>>> ÂÂ #else
>>>> ÂÂ Â #define LPSS_ADDR(desc) (0UL)
>>>> @@ -427,6 +432,139 @@ static int register_device_clock(struct acpi_device
>>>> *adev,
>>>> ÂÂÂÂÂÂ return 0;
>>>> ÂÂ }
>>>> ÂÂ +struct lpss_device_links {
>>>> +ÂÂÂ const char *supplier_hid;
>>>> +ÂÂÂ const char *supplier_uid;
>>>> +ÂÂÂ const char *consumer_hid;
>>>> +ÂÂÂ const char *consumer_uid;
>>>> +ÂÂÂ const struct x86_cpu_id *cpus;
>>>> +ÂÂÂ u32 flags;
>>>> +};
>>>> +
>>>> +static const struct lpss_device_links lpss_device_links[] = {
>>>> +ÂÂÂ {"808622C1", "7", "80860F14", "3", cht_cpu, DL_FLAG_PM_RUNTIME},
>>>> +};
>>>> +
>>>> +static bool hid_uid_match(const char *hid1, const char *uid1,
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂ const char *hid2, const char *uid2)
>>>> +{
>>>> +ÂÂÂ return !strcmp(hid1, hid2) && uid1 && uid2 && !strcmp(uid1, uid2);
>>>> +}
>>>> +
>>>> +static bool acpi_lpss_is_supplier(struct acpi_device *adev,
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ const struct lpss_device_links *link)
>>>> +{
>>>> +ÂÂÂ return hid_uid_match(acpi_device_hid(adev), acpi_device_uid(adev),
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ link->supplier_hid, link->supplier_uid);
>>>> +}
>>>> +
>>>> +static bool acpi_lpss_is_consumer(struct acpi_device *adev,
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ const struct lpss_device_links *link)
>>>> +{
>>>> +ÂÂÂ return hid_uid_match(acpi_device_hid(adev), acpi_device_uid(adev),
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ link->consumer_hid, link->consumer_uid);
>>>> +}
>>>> +
>>>> +struct hid_uid {
>>>> +ÂÂÂ const char *hid;
>>>> +ÂÂÂ const char *uid;
>>>> +};
>>>> +
>>>> +static int match_hid_uid(struct device *dev, void *data)
>>>> +{
>>>> +ÂÂÂ struct acpi_device *adev = ACPI_COMPANION(dev);
>>>> +ÂÂÂ struct hid_uid *id = data;
>>>> +
>>>> +ÂÂÂ if (!adev)
>>>> +ÂÂÂÂÂÂÂ return 0;
>>>> +
>>>> +ÂÂÂ return hid_uid_match(acpi_device_hid(adev), acpi_device_uid(adev),
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ id->hid, id->uid);
>>>> +}
>>>> +
>>>> +static struct device *acpi_lpss_find_device(const char *hid, const char
>>>> *uid)
>>>> +{
>>>> +ÂÂÂ struct hid_uid data = {
>>>> +ÂÂÂÂÂÂÂ .hid = hid,
>>>> +ÂÂÂÂÂÂÂ .uid = uid,
>>>> +ÂÂÂ };
>>>> +
>>>> +ÂÂÂ return bus_find_device(&platform_bus_type, NULL, &data,
>>>> match_hid_uid);
>>>> +}
>>>> +
>>>> +static bool acpi_lpss_dep(struct acpi_device *adev, acpi_handle handle)
>>>> +{
>>>> +ÂÂÂ struct acpi_handle_list dep_devices;
>>>> +ÂÂÂ acpi_status status;
>>>> +ÂÂÂ int i;
>>>> +
>>>> +ÂÂÂ if (!acpi_has_method(adev->handle, "_DEP"))
>>>> +ÂÂÂÂÂÂÂ return false;
>>>> +
>>>> +ÂÂÂ status = acpi_evaluate_reference(adev->handle, "_DEP", NULL,
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ &dep_devices);
>>>> +ÂÂÂ if (ACPI_FAILURE(status)) {
>>>> +ÂÂÂÂÂÂÂ dev_dbg(&adev->dev, "Failed to evaluate _DEP.\n");
>>>> +ÂÂÂÂÂÂÂ return false;
>>>> +ÂÂÂ }
>>>> +
>>>> +ÂÂÂ for (i = 0; i < dep_devices.count; i++) {
>>>> +ÂÂÂÂÂÂÂ if (dep_devices.handles[i] == handle)
>>>> +ÂÂÂÂÂÂÂÂÂÂÂ return true;
>>>> +ÂÂÂ }
>>>> +
>>>> +ÂÂÂ return false;
>>>> +}
>>>> +
>>>> +static void acpi_lpss_link_consumer(struct device *dev1,
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ const struct lpss_device_links *link)
>>>> +{
>>>> +ÂÂÂ struct device *dev2;
>>>> +
>>>> +ÂÂÂ dev2 = acpi_lpss_find_device(link->consumer_hid, link->consumer_uid);
>>>> +ÂÂÂ if (!dev2)
>>>> +ÂÂÂÂÂÂÂ return;
>>>> +
>>>> +ÂÂÂ if (acpi_lpss_dep(ACPI_COMPANION(dev2), ACPI_HANDLE(dev1)))
>>>> +ÂÂÂÂÂÂÂ device_link_add(dev2, dev1, link->flags);
>>>> +
>>>> +ÂÂÂ put_device(dev2);
>>>> +}
>>>> +
>>>> +static void acpi_lpss_link_supplier(struct device *dev1,
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ const struct lpss_device_links *link)
>>>> +{
>>>> +ÂÂÂ struct device *dev2;
>>>> +
>>>> +ÂÂÂ dev2 = acpi_lpss_find_device(link->supplier_hid, link->supplier_uid);
>>>> +ÂÂÂ if (!dev2)
>>>> +ÂÂÂÂÂÂÂ return;
>>>> +
>>>> +ÂÂÂ if (acpi_lpss_dep(ACPI_COMPANION(dev1), ACPI_HANDLE(dev2)))
>>>> +ÂÂÂÂÂÂÂ device_link_add(dev1, dev2, link->flags);
>>>> +
>>>> +ÂÂÂ put_device(dev2);
>>>> +}
>>>> +
>>>> +static void acpi_lpss_create_device_links(struct acpi_device *adev,
>>>> +ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ struct platform_device *pdev)
>>>> +{
>>>> +ÂÂÂ int i;
>>>> +
>>>> +ÂÂÂ for (i = 0; i < ARRAY_SIZE(lpss_device_links); i++) {
>>>> +ÂÂÂÂÂÂÂ const struct lpss_device_links *link = &lpss_device_links[i];
>>>> +
>>>> +ÂÂÂÂÂÂÂ if (link->cpus && !x86_match_cpu(link->cpus))
>>>> +ÂÂÂÂÂÂÂÂÂÂÂ continue;
>>>> +
>>>> +ÂÂÂÂÂÂÂ if (acpi_lpss_is_supplier(adev, link))
>>>> +ÂÂÂÂÂÂÂÂÂÂÂ acpi_lpss_link_consumer(&pdev->dev, link);
>>>> +
>>>> +ÂÂÂÂÂÂÂ if (acpi_lpss_is_consumer(adev, link))
>>>> +ÂÂÂÂÂÂÂÂÂÂÂ acpi_lpss_link_supplier(&pdev->dev, link);
>>>> +ÂÂÂ }
>>>> +}
>>>> +
>>>> ÂÂ static int acpi_lpss_create_device(struct acpi_device *adev,
>>>> ÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂÂ const struct acpi_device_id *id)
>>>> ÂÂ {
>>>> @@ -500,6 +638,7 @@ static int acpi_lpss_create_device(struct acpi_device
>>>> *adev,
>>>> ÂÂÂÂÂÂ adev->driver_data = pdata;
>>>> ÂÂÂÂÂÂ pdev = acpi_create_platform_device(adev, dev_desc->properties);
>>>> ÂÂÂÂÂÂ if (!IS_ERR_OR_NULL(pdev)) {
>>>> +ÂÂÂÂÂÂÂ acpi_lpss_create_device_links(adev, pdev);
>>>> ÂÂÂÂÂÂÂÂÂÂ return 1;
>>>> ÂÂÂÂÂÂ }
>>>> Â
>>>
>>
>