From: Grant Likely <grant.likely@linaro.org>
To: "Rafael J. Wysocki" <rjw@rjwysocki.net>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Arnd Bergmann <arnd@arndb.de>,
Mika Westerberg <mika.westerberg@linux.intel.com>,
ACPI Devel Maling List <linux-acpi@vger.kernel.org>,
Aaron Lu <aaron.lu@intel.com>,
devicetree@vger.kernel.org,
Linus Walleij <linus.walleij@linaro.org>,
Alexandre Courbot <gnurou@gmail.com>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Bryan Wu <cooloney@gmail.com>,
Darren Hart <dvhart@linux.intel.com>,
Mark Rutland <mark.rutland@arm.com>
Subject: Re: [PATCH v5 03/12] ACPI: Allow drivers to match using Device Tree compatible property
Date: Mon, 20 Oct 2014 16:05:01 +0200 [thread overview]
Message-ID: <20141020140501.D10A5C40982@trevor.secretlab.ca> (raw)
In-Reply-To: <3167500.xrhugPHshV@vostro.rjw.lan>
On Fri, 17 Oct 2014 14:05:59 +0200
, "Rafael J. Wysocki" <rjw@rjwysocki.net>
wrote:
> From: Mika Westerberg <mika.westerberg@linux.intel.com>
>
> We have lots of existing Device Tree enabled drivers and allocating
> separate _HID for each is not feasible. Instead we allocate special _HID
> "PRP0001" that means that the match should be done using Device Tree
> compatible property using driver's .of_match_table instead if the driver
> is missing .acpi_match_table.
(Not a critique of this patch, but merely a helpful comment; my previous
ack remains intact) :-)
It would be useful for the code to point at some document that describes
the semantics of the PRP0001 binding.
g.
>
> If there is a need to distinguish from where the device is enumerated
> (DT/ACPI) driver can check dev->of_node or ACPI_COMPATION(dev).
>
> Signed-off-by: Mika Westerberg <mika.westerberg@linux.intel.com>
> Reviewed-by: Grant Likely <grant.likely@linaro.org>
> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
> ---
> drivers/acpi/property.c | 34 +++++++++++++++++
> drivers/acpi/scan.c | 97 +++++++++++++++++++++++++++++++++++++++++++------
> include/acpi/acpi_bus.h | 1 +
> include/linux/acpi.h | 8 +---
> 4 files changed, 123 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/acpi/property.c b/drivers/acpi/property.c
> index 680f7f1..ff53eb8 100644
> --- a/drivers/acpi/property.c
> +++ b/drivers/acpi/property.c
> @@ -76,6 +76,37 @@ static bool acpi_properties_format_valid(const union acpi_object *properties)
> return true;
> }
>
> +static void acpi_init_of_compatible(struct acpi_device *adev)
> +{
> + const union acpi_object *of_compatible;
> + struct acpi_hardware_id *hwid;
> + bool acpi_of = false;
> +
> + /*
> + * Check if the special PRP0001 ACPI ID is present and in that
> + * case we fill in Device Tree compatible properties for this
> + * device.
> + */
> + list_for_each_entry(hwid, &adev->pnp.ids, list) {
> + if (!strcmp(hwid->id, "PRP0001")) {
> + acpi_of = true;
> + break;
> + }
> + }
> +
> + if (!acpi_of)
> + return;
> +
> + if (acpi_dev_get_property_array(adev, "compatible", ACPI_TYPE_STRING,
> + &of_compatible)) {
> + acpi_handle_warn(adev->handle,
> + "PRP0001 requires compatible property\n");
> + return;
> + }
> +
> + adev->data.of_compatible = of_compatible;
> +}
> +
> void acpi_init_properties(struct acpi_device *adev)
> {
> struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER };
> @@ -119,6 +150,8 @@ void acpi_init_properties(struct acpi_device *adev)
>
> adev->data.pointer = buf.pointer;
> adev->data.properties = properties;
> +
> + acpi_init_of_compatible(adev);
> return;
> }
>
> @@ -130,6 +163,7 @@ void acpi_init_properties(struct acpi_device *adev)
> void acpi_free_properties(struct acpi_device *adev)
> {
> ACPI_FREE((void *)adev->data.pointer);
> + adev->data.of_compatible = NULL;
> adev->data.pointer = NULL;
> adev->data.properties = NULL;
> }
> diff --git a/drivers/acpi/scan.c b/drivers/acpi/scan.c
> index 1979ab3..bc999f1 100644
> --- a/drivers/acpi/scan.c
> +++ b/drivers/acpi/scan.c
> @@ -124,17 +124,51 @@ static int create_modalias(struct acpi_device *acpi_dev, char *modalias,
> if (list_empty(&acpi_dev->pnp.ids))
> return 0;
>
> - len = snprintf(modalias, size, "acpi:");
> - size -= len;
> -
> - list_for_each_entry(id, &acpi_dev->pnp.ids, list) {
> - count = snprintf(&modalias[len], size, "%s:", id->id);
> - if (count < 0)
> - return -EINVAL;
> - if (count >= size)
> - return -ENOMEM;
> - len += count;
> - size -= count;
> + /*
> + * If the device has PRP0001 we expose DT compatible modalias
> + * instead in form of of:NnameTCcompatible.
> + */
> + if (acpi_dev->data.of_compatible) {
> + struct acpi_buffer buf = { ACPI_ALLOCATE_BUFFER };
> + const union acpi_object *of_compatible, *obj;
> + char *c;
> + int i;
> +
> + acpi_get_name(acpi_dev->handle, ACPI_SINGLE_NAME, &buf);
> + /* DT strings are all in lower case */
> + for (c = buf.pointer; *c != '\0'; c++)
> + *c = tolower(*c);
> +
> + len = snprintf(modalias, size, "of:N%sT", (char *)buf.pointer);
> + ACPI_FREE(buf.pointer);
> +
> + of_compatible = acpi_dev->data.of_compatible;
> + for (i = 0; i < of_compatible->package.count; i++) {
> + obj = &of_compatible->package.elements[i];
> +
> + count = snprintf(&modalias[len], size, "C%s",
> + obj->string.pointer);
> + if (count < 0)
> + return -EINVAL;
> + if (count >= size)
> + return -ENOMEM;
> +
> + len += count;
> + size -= count;
> + }
> + } else {
> + len = snprintf(modalias, size, "acpi:");
> + size -= len;
> +
> + list_for_each_entry(id, &acpi_dev->pnp.ids, list) {
> + count = snprintf(&modalias[len], size, "%s:", id->id);
> + if (count < 0)
> + return -EINVAL;
> + if (count >= size)
> + return -ENOMEM;
> + len += count;
> + size -= count;
> + }
> }
>
> modalias[len] = '\0';
> @@ -864,6 +898,47 @@ int acpi_match_device_ids(struct acpi_device *device,
> }
> EXPORT_SYMBOL(acpi_match_device_ids);
>
> +/* Performs match against special "PRP0001" shoehorn ACPI ID */
> +static bool acpi_of_driver_match_device(struct device *dev,
> + const struct device_driver *drv)
> +{
> + const union acpi_object *of_compatible;
> + struct acpi_device *adev;
> + int i;
> +
> + adev = ACPI_COMPANION(dev);
> + if (!adev)
> + return false;
> +
> + of_compatible = adev->data.of_compatible;
> + if (!drv->of_match_table || !of_compatible)
> + return false;
> +
> + /* Now we can look for the driver DT compatible strings */
> + for (i = 0; i < of_compatible->package.count; i++) {
> + const struct of_device_id *id;
> + const union acpi_object *obj;
> +
> + obj = &of_compatible->package.elements[i];
> +
> + for (id = drv->of_match_table; id->compatible[0]; id++)
> + if (!strcasecmp(obj->string.pointer, id->compatible))
> + return true;
> + }
> +
> + return false;
> +}
> +
> +bool acpi_driver_match_device(struct device *dev,
> + const struct device_driver *drv)
> +{
> + if (!drv->acpi_match_table)
> + return acpi_of_driver_match_device(dev, drv);
> +
> + return !!acpi_match_device(drv->acpi_match_table, dev);
> +}
> +EXPORT_SYMBOL_GPL(acpi_driver_match_device);
> +
> static void acpi_free_power_resources_lists(struct acpi_device *device)
> {
> int i;
> diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
> index f9734fa..98cd723 100644
> --- a/include/acpi/acpi_bus.h
> +++ b/include/acpi/acpi_bus.h
> @@ -341,6 +341,7 @@ struct acpi_device_physical_node {
> struct acpi_device_data {
> const union acpi_object *pointer;
> const union acpi_object *properties;
> + const union acpi_object *of_compatible;
> };
>
> /* Device */
> diff --git a/include/linux/acpi.h b/include/linux/acpi.h
> index 18c1bc3..11aa6b8 100644
> --- a/include/linux/acpi.h
> +++ b/include/linux/acpi.h
> @@ -424,12 +424,8 @@ extern int acpi_nvs_for_each_region(int (*func)(__u64, __u64, void *),
> const struct acpi_device_id *acpi_match_device(const struct acpi_device_id *ids,
> const struct device *dev);
>
> -static inline bool acpi_driver_match_device(struct device *dev,
> - const struct device_driver *drv)
> -{
> - return !!acpi_match_device(drv->acpi_match_table, dev);
> -}
> -
> +extern bool acpi_driver_match_device(struct device *dev,
> + const struct device_driver *drv);
> int acpi_device_uevent_modalias(struct device *, struct kobj_uevent_env *);
> int acpi_device_modalias(struct device *, char *, int);
>
> --
> 1.9.3
>
>
next prev parent reply other threads:[~2014-10-20 14:05 UTC|newest]
Thread overview: 104+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-10-07 0:10 [PATCH v4 00/13] Add ACPI _DSD and unified device properties support Rafael J. Wysocki
2014-10-07 0:12 ` [PATCH 01/13] ACPI: Add support for device specific properties Rafael J. Wysocki
2014-10-13 12:47 ` Grant Likely
2014-10-07 0:12 ` [PATCH 02/13] Driver core: Unified device properties interface for platform firmware Rafael J. Wysocki
2014-10-07 0:13 ` [PATCH 03/13] ACPI: Allow drivers to match using Device Tree compatible property Rafael J. Wysocki
2014-10-14 13:38 ` Grant Likely
2014-10-07 0:14 ` [PATCH 04/13] ACPI: Document ACPI device specific properties Rafael J. Wysocki
2014-10-13 12:41 ` Grant Likely
2014-10-14 9:42 ` Mika Westerberg
2014-10-07 0:14 ` [PATCH 05/13] misc: at25: Make use of device property API Rafael J. Wysocki
2014-10-07 9:10 ` Geert Uytterhoeven
2014-10-07 9:32 ` Mika Westerberg
2014-10-07 0:15 ` [PATCH 06/13] gpio / ACPI: Add support for _DSD device properties Rafael J. Wysocki
2014-10-14 13:44 ` Grant Likely
2014-10-15 8:46 ` Mika Westerberg
2014-10-07 0:15 ` [PATCH 07/13] gpio: sch: Consolidate core and resume banks Rafael J. Wysocki
2014-10-07 0:16 ` [PATCH 08/13] leds: leds-gpio: Add support for GPIO descriptors Rafael J. Wysocki
2014-10-07 0:16 ` [PATCH 09/12] input: gpio_keys_polled - " Rafael J. Wysocki
2014-10-07 17:29 ` Dmitry Torokhov
2014-10-07 0:17 ` [PATCH 10/13] Driver core: Child node properties for devices Rafael J. Wysocki
2014-10-07 0:18 ` [PATCH 11/13] gpio: Support for unified device properties interface Rafael J. Wysocki
2014-10-07 10:22 ` Alexandre Courbot
2014-10-07 10:40 ` Mika Westerberg
2014-10-07 10:52 ` Alexandre Courbot
2014-10-08 0:09 ` Rafael J. Wysocki
2014-10-08 2:55 ` Alexandre Courbot
2014-10-08 14:01 ` Rafael J. Wysocki
2014-10-07 0:18 ` [PATCH 12/13] leds: leds-gpio: Make use of device property API Rafael J. Wysocki
2014-10-08 14:04 ` Rafael J. Wysocki
2014-10-08 17:47 ` Bryan Wu
2014-10-08 22:02 ` Rafael J. Wysocki
2014-10-07 0:19 ` [PATCH 13/13] input: gpio_keys_polled - " Rafael J. Wysocki
2014-10-07 17:30 ` Dmitry Torokhov
2014-10-07 0:39 ` [PATCH v4 00/13] Add ACPI _DSD and unified device properties support Rafael J. Wysocki
2014-10-07 2:28 ` Greg Kroah-Hartman
2014-10-15 13:04 ` David Woodhouse
2014-10-15 13:15 ` Mark Rutland
2014-10-15 13:28 ` David Woodhouse
2014-10-15 13:42 ` Mark Rutland
2014-10-15 14:08 ` David Woodhouse
2014-10-15 14:46 ` Darren Hart
2014-10-15 15:11 ` David Woodhouse
2014-10-15 15:17 ` Mark Rutland
2014-10-15 15:43 ` Darren Hart
2014-10-16 10:05 ` Rafael J. Wysocki
2014-10-16 14:55 ` David Woodhouse
2014-10-18 8:37 ` Grant Likely
2014-10-18 8:39 ` Grant Likely
2014-10-18 8:35 ` Grant Likely
2014-10-21 21:50 ` [PATCH v4 00/13] Add ACPI _DSD and unified device properties? support Darren Hart
2015-01-14 18:42 ` [PATCH v4 00/13] Add ACPI _DSD and unified device properties support David Woodhouse
2015-01-15 9:12 ` Rafael J. Wysocki
2014-10-17 12:01 ` [PATCH v5 00/12] " Rafael J. Wysocki
2014-10-17 12:03 ` [PATCH v5 01/12] ACPI: Add support for device specific properties Rafael J. Wysocki
2014-10-17 12:04 ` [PATCH v5 02/12] Driver core: Unified device properties interface for platform firmware Rafael J. Wysocki
2014-10-20 0:07 ` [Update][PATCH " Rafael J. Wysocki
2014-10-17 12:05 ` [PATCH v5 03/12] ACPI: Allow drivers to match using Device Tree compatible property Rafael J. Wysocki
2014-10-20 14:05 ` Grant Likely [this message]
2014-10-20 22:19 ` Rafael J. Wysocki
2014-10-17 12:07 ` [PATCH v5 04/12] misc: at25: Make use of device property API Rafael J. Wysocki
2014-10-17 12:09 ` [PATCH v5 05/12] gpio / ACPI: Add support for _DSD device properties Rafael J. Wysocki
2014-10-17 12:10 ` [PATCH v5 06/12] gpio: sch: Consolidate core and resume banks Rafael J. Wysocki
2014-10-17 12:11 ` [PATCH v5 07/12] leds: leds-gpio: Add support for GPIO descriptors Rafael J. Wysocki
2014-10-28 15:26 ` Linus Walleij
2014-10-28 21:56 ` Rafael J. Wysocki
2014-10-29 8:53 ` Mika Westerberg
2014-10-30 15:40 ` Linus Walleij
2014-10-30 16:15 ` Mika Westerberg
2014-10-31 9:41 ` Linus Walleij
2014-10-31 9:55 ` Mika Westerberg
2014-10-30 15:34 ` Linus Walleij
2014-10-17 12:12 ` [PATCH v5 08/12] input: gpio_keys_polled - " Rafael J. Wysocki
2014-10-17 12:14 ` [PATCH v5 09/12] Driver core: Unified interface for firmware node properties Rafael J. Wysocki
2014-10-18 9:35 ` Arnd Bergmann
2014-10-19 23:30 ` Rafael J. Wysocki
2014-10-20 14:14 ` Arnd Bergmann
2014-10-18 14:55 ` Grant Likely
2014-10-19 23:46 ` Rafael J. Wysocki
2014-10-20 14:18 ` Grant Likely
2014-10-20 22:14 ` Rafael J. Wysocki
2014-10-20 14:19 ` Arnd Bergmann
2014-10-20 14:55 ` Grant Likely
2014-10-20 22:22 ` Rafael J. Wysocki
2014-10-19 22:14 ` Greg Kroah-Hartman
2014-10-19 23:31 ` Rafael J. Wysocki
2014-10-20 0:15 ` [Update][PATCH " Rafael J. Wysocki
2014-10-17 12:16 ` [PATCH v5 10/12] gpio: Support for unified device properties interface Rafael J. Wysocki
2014-10-17 18:09 ` Arnd Bergmann
2014-10-18 9:47 ` Arnd Bergmann
2014-10-19 23:58 ` Rafael J. Wysocki
2014-10-20 14:22 ` Arnd Bergmann
2014-10-20 6:12 ` Alexandre Courbot
2014-10-20 14:26 ` Arnd Bergmann
2014-10-17 12:17 ` [PATCH v5 11/12] leds: leds-gpio: Make use of device property API Rafael J. Wysocki
2014-10-17 12:18 ` [PATCH v5 12/12] input: gpio_keys_polled - " Rafael J. Wysocki
2014-10-17 12:22 ` [PATCH v5 00/12] Add ACPI _DSD and unified device properties support Rafael J. Wysocki
2014-10-17 15:40 ` Greg Kroah-Hartman
2014-10-17 19:23 ` Darren Hart
2014-10-17 21:49 ` Rafael J. Wysocki
2014-10-19 22:14 ` Greg Kroah-Hartman
2014-10-17 18:04 ` Arnd Bergmann
2014-10-17 22:50 ` Rafael J. Wysocki
2014-10-18 8:49 ` Grant Likely
2014-10-19 23:32 ` Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20141020140501.D10A5C40982@trevor.secretlab.ca \
--to=grant.likely@linaro.org \
--cc=aaron.lu@intel.com \
--cc=arnd@arndb.de \
--cc=cooloney@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=dvhart@linux.intel.com \
--cc=gnurou@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=linus.walleij@linaro.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mika.westerberg@linux.intel.com \
--cc=rjw@rjwysocki.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).