Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1565124 > unrolled thread

[PATCH v3 0/3] Init device ids from ACPI of_compatible

Started byDan O'Donovan <dan@emutex.com>
First post2017-01-23 17:50 +0100
Last post2017-01-28 22:40 +0100
Articles 15 — 5 participants

Back to article view | Back to linux.kernel

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  [PATCH v3 0/3] Init device ids from ACPI of_compatible Dan O'Donovan <dan@emutex.com> - 2017-01-23 17:50 +0100
    [PATCH v3 1/3] ACPI / bus: Export acpi_of_modalias equiv of of_modalias_node Dan O'Donovan <dan@emutex.com> - 2017-01-23 17:50 +0100
    [PATCH v3 3/3] spi: acpi: Initialize modalias from of_compatible Dan O'Donovan <dan@emutex.com> - 2017-01-23 17:50 +0100
      Re: [PATCH v3 3/3] spi: acpi: Initialize modalias from of_compatible Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-01-23 18:20 +0100
        Re: [PATCH v3 3/3] spi: acpi: Initialize modalias from of_compatible Dan O'Donovan <dan@emutex.com> - 2017-01-27 12:20 +0100
          Re: [PATCH v3 3/3] spi: acpi: Initialize modalias from of_compatible Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-01-27 15:00 +0100
      Re: [PATCH v3 3/3] spi: acpi: Initialize modalias from of_compatible "Rafael J. Wysocki" <rafael@kernel.org> - 2017-01-30 10:50 +0100
    Re: [PATCH v3 0/3] Init device ids from ACPI of_compatible Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-01-23 18:20 +0100
    Re: [PATCH v3 0/3] Init device ids from ACPI of_compatible Andy Shevchenko <andy.shevchenko@gmail.com> - 2017-01-24 16:20 +0100
    Re: [PATCH v3 0/3] Init device ids from ACPI of_compatible Jarkko Nikula <jarkko.nikula@intel.com> - 2017-01-24 16:20 +0100
    [PATCH v4 0/3] Init device ids from ACPI of_compatible Dan O'Donovan <dan@emutex.com> - 2017-01-27 14:40 +0100
      [PATCH v4 1/3] ACPI / bus: Export acpi_of_modalias equiv of of_modalias_node Dan O'Donovan <dan@emutex.com> - 2017-01-27 14:40 +0100
      [PATCH v4 3/3] spi: acpi: Initialize modalias from of_compatible Dan O'Donovan <dan@emutex.com> - 2017-01-27 14:40 +0100
      [PATCH v4 2/3] i2c: acpi: Initialize info.type from of_compatible Dan O'Donovan <dan@emutex.com> - 2017-01-27 14:40 +0100
        Re: [PATCH v4 2/3] i2c: acpi: Initialize info.type from of_compatible Wolfram Sang <wsa@the-dreams.de> - 2017-01-28 22:40 +0100

#1565124 — [PATCH v3 0/3] Init device ids from ACPI of_compatible

FromDan O'Donovan <dan@emutex.com>
Date2017-01-23 17:50 +0100
Subject[PATCH v3 0/3] Init device ids from ACPI of_compatible
Message-ID<t2PYB-mQ-3@gated-at.bofh.it>
(Re-submitting this patch set originally created by Leonard Crestez,
possibly abandoned by Leonard due to a change in employment)

When using devicetree, stuff like i2c_client.name or spi_device.modalias
is initialized to the first DT compatible id with the vendor prefix
stripped. Since some drivers rely on this in order to differentiate between
hardware variants try to replicate it when using ACPI with DT ids.

This also makes it so that the i2c_device_id parameter passed to probe is
non-NULL when matching with ACPI and DT ids.

Tested using ACPI overlays but there is no actual dependency. This series
just extends the PRP0001 feature to be more useful for I2C/SPI.

The patches only touches the ACPI-specific parts of the i2c and spi core.

Here is an example .dsl for an SPI accelerometer connected to minnowboard max:

Device (ACCL)
{
    Name (_ADR, Zero)
    Name (_HID, "PRP0001")
    Name (_UID, One)

    Method (_CRS, 0, Serialized)
    {
	Name (RBUF, ResourceTemplate ()
	{
	    SPISerialBus(1, PolarityLow, FourWireMode, 16,
		    ControllerInitiated, 1000000, ClockPolarityLow,
		    ClockPhaseFirst, "\\_SB.SPI1",)
	    GpioInt (Edge, ActiveHigh, Exclusive, PullDown, 0x0000,
		     "\\_SB.GPO2", 0x00, ResourceConsumer, , )
	    { // Pin list
		    1
	    }
	})
	Return (RBUF)
    }
    Name (_DSD, Package ()
    {
	ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
	Package ()
	{
	    Package () {"compatible", "st,lis3dh"},
	}
    })
}

Link to v2: https://lkml.org/lkml/2016/7/13/392
Changes:
 * Use appropriate subject prefix for each subsystem (Mark Brown)
 * Use ACPI info as before if getting OF info fails (Mark Brown)
 * Minor cosmetic/readability improvements (Rafael J. Wysocki)

Link to v1: https://www.spinics.net/lists/linux-acpi/msg66469.html
Changes:
 * Rebase on after acpi overlays got it.
 * Change acpi_of_modalias outlen param to size_t
 * Use {} after else

Crestez Dan Leonard (3):
  ACPI / bus: Export acpi_of_modalias equiv of of_modalias_node
  i2c: acpi: Initialize info.type from of_compatible
  spi: acpi: Initialize modalias from of_compatible

 drivers/acpi/bus.c      | 35 +++++++++++++++++++++++++++++++++++
 drivers/i2c/i2c-core.c  |  8 +++++++-
 drivers/spi/spi.c       | 10 +++++++++-
 include/acpi/acpi_bus.h |  1 +
 4 files changed, 52 insertions(+), 2 deletions(-)

-- 
2.7.4

[toc] | [next] | [standalone]


#1565127 — [PATCH v3 1/3] ACPI / bus: Export acpi_of_modalias equiv of of_modalias_node

FromDan O'Donovan <dan@emutex.com>
Date2017-01-23 17:50 +0100
Subject[PATCH v3 1/3] ACPI / bus: Export acpi_of_modalias equiv of of_modalias_node
Message-ID<t2PYC-mQ-41@gated-at.bofh.it>
In reply to#1565124
From: Crestez Dan Leonard <leonard.crestez@intel.com>

When using devicetree stuff like i2c_client.name or spi_device.modalias
is initialized to the first DT compatible id with the vendor prefix
stripped. Since some drivers rely on this try to replicate it when using
ACPI with DT ids.

Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
Signed-off-by: Dan O'Donovan <dan@emutex.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
---
 drivers/acpi/bus.c      | 35 +++++++++++++++++++++++++++++++++++
 include/acpi/acpi_bus.h |  1 +
 2 files changed, 36 insertions(+)

diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 95855cb..8b9657f 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -677,6 +677,41 @@ static bool acpi_of_match_device(struct acpi_device *adev,
 	return false;
 }
 
+/**
+ * acpi_of_modalias - Like of_modalias_node for ACPI with DT ids
+ * @adev:	ACPI device object to match.
+ * @outstr:	Pointer to buffer for result
+ * @outlen:	Length of outstr value
+ *
+ * This is a counterpart of of_modalias_node() for struct acpi_device
+ * objects. If there is a compatible string for @adev, copy it to the
+ * @outstr location with the vendor prefix stripped.
+ *
+ * Returns 0 on success or negative errno on failure.
+ */
+int acpi_of_modalias(struct acpi_device *adev, char *outstr, size_t outlen)
+{
+	const union acpi_object *of_compatible;
+	const union acpi_object *obj;
+	const char *str, *chr;
+
+	of_compatible = adev->data.of_compatible;
+	if (!of_compatible)
+		return -ENODEV;
+
+	if (of_compatible->type == ACPI_TYPE_PACKAGE)
+		obj = of_compatible->package.elements;
+	else /* Must be ACPI_TYPE_STRING. */
+		obj = of_compatible;
+
+	str = obj->string.pointer;
+	chr = strchr(str, ',');
+	strlcpy(outstr, chr ? chr + 1 : str, outlen);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(acpi_of_modalias);
+
 static bool __acpi_match_device_cls(const struct acpi_device_id *id,
 				    struct acpi_hardware_id *hwid)
 {
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 4242c31..351b4a4 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -522,6 +522,7 @@ void acpi_bus_trim(struct acpi_device *start);
 acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd);
 int acpi_match_device_ids(struct acpi_device *device,
 			  const struct acpi_device_id *ids);
+int acpi_of_modalias(struct acpi_device *adev, char *outstr, size_t outlen);
 int acpi_create_dir(struct acpi_device *);
 void acpi_remove_dir(struct acpi_device *);
 
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1565129 — [PATCH v3 3/3] spi: acpi: Initialize modalias from of_compatible

FromDan O'Donovan <dan@emutex.com>
Date2017-01-23 17:50 +0100
Subject[PATCH v3 3/3] spi: acpi: Initialize modalias from of_compatible
Message-ID<t2PYD-mQ-51@gated-at.bofh.it>
In reply to#1565124
From: Crestez Dan Leonard <leonard.crestez@intel.com>

When using devicetree spi_device.modalias is set to the compatible
string with the vendor prefix removed. For SPI devices described via
ACPI the spi_device.modalias string is initialized by acpi_device_hid.
When using ACPI and DT ids this string ends up something like "PRP0001".

Change acpi_register_spi_device to use the of_compatible property if
present. This makes it easier to instantiate spi drivers through ACPI
with DT ids.

Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
Signed-off-by: Dan O'Donovan <dan@emutex.com>
---
 drivers/spi/spi.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 656dd3e..4b562e8 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1722,13 +1722,21 @@ static acpi_status acpi_register_spi_device(struct spi_master *master,
 		return AE_OK;
 	}
 
+	/*
+	 * Populate modalias from compatible property if available,
+	 * otherwise use native ACPI information
+	 */
+	if ((!adev->data.of_compatible) ||
+	    acpi_of_modalias(adev, spi->modalias, sizeof(spi->modalias)))
+		strlcpy(spi->modalias, acpi_device_hid(adev),
+			sizeof(spi->modalias));
+
 	if (spi->irq < 0)
 		spi->irq = acpi_dev_gpio_irq_get(adev, 0);
 
 	acpi_device_set_enumerated(adev);
 
 	adev->power.flags.ignore_parent = true;
-	strlcpy(spi->modalias, acpi_device_hid(adev), sizeof(spi->modalias));
 	if (spi_add_device(spi)) {
 		adev->power.flags.ignore_parent = false;
 		dev_err(&master->dev, "failed to add SPI device %s from ACPI\n",
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1565175 — Re: [PATCH v3 3/3] spi: acpi: Initialize modalias from of_compatible

FromAndy Shevchenko <andy.shevchenko@gmail.com>
Date2017-01-23 18:20 +0100
SubjectRe: [PATCH v3 3/3] spi: acpi: Initialize modalias from of_compatible
Message-ID<t2QrF-Nm-63@gated-at.bofh.it>
In reply to#1565129
On Mon, Jan 23, 2017 at 6:08 PM, Dan O'Donovan <dan@emutex.com> wrote:
> From: Crestez Dan Leonard <leonard.crestez@intel.com>
>
> When using devicetree spi_device.modalias is set to the compatible
> string with the vendor prefix removed. For SPI devices described via
> ACPI the spi_device.modalias string is initialized by acpi_device_hid.
> When using ACPI and DT ids this string ends up something like "PRP0001".
>
> Change acpi_register_spi_device to use the of_compatible property if
> present. This makes it easier to instantiate spi drivers through ACPI
> with DT ids.

> +       /*
> +        * Populate modalias from compatible property if available,
> +        * otherwise use native ACPI information
> +        */
> +       if ((!adev->data.of_compatible) ||
> +           acpi_of_modalias(adev, spi->modalias, sizeof(spi->modalias)))

Same comment as in patch 2.

> +               strlcpy(spi->modalias, acpi_device_hid(adev),
> +                       sizeof(spi->modalias));

Could this be one line?

-- 
With Best Regards,
Andy Shevchenko

[toc] | [prev] | [next] | [standalone]


#1568113 — Re: [PATCH v3 3/3] spi: acpi: Initialize modalias from of_compatible

FromDan O'Donovan <dan@emutex.com>
Date2017-01-27 12:20 +0100
SubjectRe: [PATCH v3 3/3] spi: acpi: Initialize modalias from of_compatible
Message-ID<t4cJs-3oK-17@gated-at.bofh.it>
In reply to#1565175
On 01/23/2017 05:11 PM, Andy Shevchenko wrote:
> On Mon, Jan 23, 2017 at 6:08 PM, Dan O'Donovan <dan@emutex.com> wrote:
>> From: Crestez Dan Leonard <leonard.crestez@intel.com>
>>
>> When using devicetree spi_device.modalias is set to the compatible
>> string with the vendor prefix removed. For SPI devices described via
>> ACPI the spi_device.modalias string is initialized by acpi_device_hid.
>> When using ACPI and DT ids this string ends up something like "PRP0001".
>>
>> Change acpi_register_spi_device to use the of_compatible property if
>> present. This makes it easier to instantiate spi drivers through ACPI
>> with DT ids.
>> +       /*
>> +        * Populate modalias from compatible property if available,
>> +        * otherwise use native ACPI information
>> +        */
>> +       if ((!adev->data.of_compatible) ||
>> +           acpi_of_modalias(adev, spi->modalias, sizeof(spi->modalias)))
> Same comment as in patch 2.
Thanks for the feedback, Andy.  The check on of_compatible is redundant,
because its repeated in acpi_of_modalias(), so I'll remove it here (and
in patch 2) to reduce this to one line.  v4 on the way.
>> +               strlcpy(spi->modalias, acpi_device_hid(adev),
>> +                       sizeof(spi->modalias));
> Could this be one line?
I couldn't see a way to reduce this to one line without exceeding 80
chars or adding another line somewhere else, so I'll leave this one as
it is if that's ok.

[toc] | [prev] | [next] | [standalone]


#1568382 — Re: [PATCH v3 3/3] spi: acpi: Initialize modalias from of_compatible

FromAndy Shevchenko <andy.shevchenko@gmail.com>
Date2017-01-27 15:00 +0100
SubjectRe: [PATCH v3 3/3] spi: acpi: Initialize modalias from of_compatible
Message-ID<t4feh-4Q7-5@gated-at.bofh.it>
In reply to#1568113
On Fri, Jan 27, 2017 at 12:35 PM, Dan O'Donovan <dan@emutex.com> wrote:
> On 01/23/2017 05:11 PM, Andy Shevchenko wrote:
>> On Mon, Jan 23, 2017 at 6:08 PM, Dan O'Donovan <dan@emutex.com> wrote:

>>> +               strlcpy(spi->modalias, acpi_device_hid(adev),
>>> +                       sizeof(spi->modalias));
>> Could this be one line?
> I couldn't see a way to reduce this to one line without exceeding 80
> chars or adding another line somewhere else, so I'll leave this one as
> it is if that's ok.

80 characters per line is not carved in stone. How many do you have
over? 3 like "s);"?

-- 
With Best Regards,
Andy Shevchenko

[toc] | [prev] | [next] | [standalone]


#1569500 — Re: [PATCH v3 3/3] spi: acpi: Initialize modalias from of_compatible

From"Rafael J. Wysocki" <rafael@kernel.org>
Date2017-01-30 10:50 +0100
SubjectRe: [PATCH v3 3/3] spi: acpi: Initialize modalias from of_compatible
Message-ID<t5gL0-2ll-23@gated-at.bofh.it>
In reply to#1565129
On Mon, Jan 23, 2017 at 5:08 PM, Dan O'Donovan <dan@emutex.com> wrote:
> From: Crestez Dan Leonard <leonard.crestez@intel.com>
>
> When using devicetree spi_device.modalias is set to the compatible
> string with the vendor prefix removed. For SPI devices described via
> ACPI the spi_device.modalias string is initialized by acpi_device_hid.
> When using ACPI and DT ids this string ends up something like "PRP0001".
>
> Change acpi_register_spi_device to use the of_compatible property if
> present. This makes it easier to instantiate spi drivers through ACPI
> with DT ids.
>
> Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
> Signed-off-by: Dan O'Donovan <dan@emutex.com>
> ---
>  drivers/spi/spi.c | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
> index 656dd3e..4b562e8 100644
> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -1722,13 +1722,21 @@ static acpi_status acpi_register_spi_device(struct spi_master *master,
>                 return AE_OK;
>         }
>
> +       /*
> +        * Populate modalias from compatible property if available,
> +        * otherwise use native ACPI information
> +        */
> +       if ((!adev->data.of_compatible) ||
> +           acpi_of_modalias(adev, spi->modalias, sizeof(spi->modalias)))
> +               strlcpy(spi->modalias, acpi_device_hid(adev),
> +                       sizeof(spi->modalias));
> +
>         if (spi->irq < 0)
>                 spi->irq = acpi_dev_gpio_irq_get(adev, 0);
>
>         acpi_device_set_enumerated(adev);
>
>         adev->power.flags.ignore_parent = true;
> -       strlcpy(spi->modalias, acpi_device_hid(adev), sizeof(spi->modalias));
>         if (spi_add_device(spi)) {
>                 adev->power.flags.ignore_parent = false;
>                 dev_err(&master->dev, "failed to add SPI device %s from ACPI\n",
> --

Mark, any objections here?

Thanks,
Rafael

[toc] | [prev] | [next] | [standalone]


#1565160

FromAndy Shevchenko <andy.shevchenko@gmail.com>
Date2017-01-23 18:20 +0100
Message-ID<t2QrD-Nm-7@gated-at.bofh.it>
In reply to#1565124
On Mon, Jan 23, 2017 at 6:08 PM, Dan O'Donovan <dan@emutex.com> wrote:
> (Re-submitting this patch set originally created by Leonard Crestez,
> possibly abandoned by Leonard due to a change in employment)
>
> When using devicetree, stuff like i2c_client.name or spi_device.modalias
> is initialized to the first DT compatible id with the vendor prefix
> stripped. Since some drivers rely on this in order to differentiate between
> hardware variants try to replicate it when using ACPI with DT ids.
>
> This also makes it so that the i2c_device_id parameter passed to probe is
> non-NULL when matching with ACPI and DT ids.
>
> Tested using ACPI overlays but there is no actual dependency. This series
> just extends the PRP0001 feature to be more useful for I2C/SPI.
>
> The patches only touches the ACPI-specific parts of the i2c and spi core.

The series looks good. Few nitpicks in the comments of corresponding
patches though.
FWIW:
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

>
> Here is an example .dsl for an SPI accelerometer connected to minnowboard max:
>
> Device (ACCL)
> {
>     Name (_ADR, Zero)
>     Name (_HID, "PRP0001")
>     Name (_UID, One)
>
>     Method (_CRS, 0, Serialized)
>     {
>         Name (RBUF, ResourceTemplate ()
>         {
>             SPISerialBus(1, PolarityLow, FourWireMode, 16,
>                     ControllerInitiated, 1000000, ClockPolarityLow,
>                     ClockPhaseFirst, "\\_SB.SPI1",)
>             GpioInt (Edge, ActiveHigh, Exclusive, PullDown, 0x0000,
>                      "\\_SB.GPO2", 0x00, ResourceConsumer, , )
>             { // Pin list
>                     1
>             }
>         })
>         Return (RBUF)
>     }
>     Name (_DSD, Package ()
>     {
>         ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
>         Package ()
>         {
>             Package () {"compatible", "st,lis3dh"},
>         }
>     })
> }
>
> Link to v2: https://lkml.org/lkml/2016/7/13/392
> Changes:
>  * Use appropriate subject prefix for each subsystem (Mark Brown)
>  * Use ACPI info as before if getting OF info fails (Mark Brown)
>  * Minor cosmetic/readability improvements (Rafael J. Wysocki)
>
> Link to v1: https://www.spinics.net/lists/linux-acpi/msg66469.html
> Changes:
>  * Rebase on after acpi overlays got it.
>  * Change acpi_of_modalias outlen param to size_t
>  * Use {} after else
>
> Crestez Dan Leonard (3):
>   ACPI / bus: Export acpi_of_modalias equiv of of_modalias_node
>   i2c: acpi: Initialize info.type from of_compatible
>   spi: acpi: Initialize modalias from of_compatible
>
>  drivers/acpi/bus.c      | 35 +++++++++++++++++++++++++++++++++++
>  drivers/i2c/i2c-core.c  |  8 +++++++-
>  drivers/spi/spi.c       | 10 +++++++++-
>  include/acpi/acpi_bus.h |  1 +
>  4 files changed, 52 insertions(+), 2 deletions(-)
>
> --
> 2.7.4
>



-- 
With Best Regards,
Andy Shevchenko

[toc] | [prev] | [next] | [standalone]


#1565930

FromAndy Shevchenko <andy.shevchenko@gmail.com>
Date2017-01-24 16:20 +0100
Message-ID<t3b34-5VZ-9@gated-at.bofh.it>
In reply to#1565124
On Tue, Jan 24, 2017 at 5:11 PM, Jarkko Nikula <jarkko.nikula@intel.com> wrote:
> After addressing comments from Andy
>
> Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
> Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
> ---------------------------------------------------------------------
> Intel Finland Oy
> Registered Address: PL 281, 00181 Helsinki Business Identity Code: 0357606 -
> 4 Domiciled in Helsinki
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.

Ai-ai-ai ^^^

-- 
With Best Regards,
Andy Shevchenko

[toc] | [prev] | [next] | [standalone]


#1565933

FromJarkko Nikula <jarkko.nikula@intel.com>
Date2017-01-24 16:20 +0100
Message-ID<t3b34-5VZ-11@gated-at.bofh.it>
In reply to#1565124
On 01/23/2017 06:08 PM, Dan O'Donovan wrote:
> (Re-submitting this patch set originally created by Leonard Crestez,
> possibly abandoned by Leonard due to a change in employment)
>
> When using devicetree, stuff like i2c_client.name or spi_device.modalias
> is initialized to the first DT compatible id with the vendor prefix
> stripped. Since some drivers rely on this in order to differentiate between
> hardware variants try to replicate it when using ACPI with DT ids.
>
> This also makes it so that the i2c_device_id parameter passed to probe is
> non-NULL when matching with ACPI and DT ids.
>
> Tested using ACPI overlays but there is no actual dependency. This series
> just extends the PRP0001 feature to be more useful for I2C/SPI.
>
> The patches only touches the ACPI-specific parts of the i2c and spi core.
>
> Here is an example .dsl for an SPI accelerometer connected to minnowboard max:
>
> Device (ACCL)
> {
>     Name (_ADR, Zero)
>     Name (_HID, "PRP0001")
>     Name (_UID, One)
>
>     Method (_CRS, 0, Serialized)
>     {
> 	Name (RBUF, ResourceTemplate ()
> 	{
> 	    SPISerialBus(1, PolarityLow, FourWireMode, 16,
> 		    ControllerInitiated, 1000000, ClockPolarityLow,
> 		    ClockPhaseFirst, "\\_SB.SPI1",)
> 	    GpioInt (Edge, ActiveHigh, Exclusive, PullDown, 0x0000,
> 		     "\\_SB.GPO2", 0x00, ResourceConsumer, , )
> 	    { // Pin list
> 		    1
> 	    }
> 	})
> 	Return (RBUF)
>     }
>     Name (_DSD, Package ()
>     {
> 	ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
> 	Package ()
> 	{
> 	    Package () {"compatible", "st,lis3dh"},
> 	}
>     })
> }
>
> Link to v2: https://lkml.org/lkml/2016/7/13/392
> Changes:
>  * Use appropriate subject prefix for each subsystem (Mark Brown)
>  * Use ACPI info as before if getting OF info fails (Mark Brown)
>  * Minor cosmetic/readability improvements (Rafael J. Wysocki)
>
> Link to v1: https://www.spinics.net/lists/linux-acpi/msg66469.html
> Changes:
>  * Rebase on after acpi overlays got it.
>  * Change acpi_of_modalias outlen param to size_t
>  * Use {} after else
>
> Crestez Dan Leonard (3):
>   ACPI / bus: Export acpi_of_modalias equiv of of_modalias_node
>   i2c: acpi: Initialize info.type from of_compatible
>   spi: acpi: Initialize modalias from of_compatible
>
>  drivers/acpi/bus.c      | 35 +++++++++++++++++++++++++++++++++++
>  drivers/i2c/i2c-core.c  |  8 +++++++-
>  drivers/spi/spi.c       | 10 +++++++++-
>  include/acpi/acpi_bus.h |  1 +
>  4 files changed, 52 insertions(+), 2 deletions(-)
>
After addressing comments from Andy

Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---------------------------------------------------------------------
Intel Finland Oy
Registered Address: PL 281, 00181 Helsinki 
Business Identity Code: 0357606 - 4 
Domiciled in Helsinki 

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

[toc] | [prev] | [next] | [standalone]


#1568357 — [PATCH v4 0/3] Init device ids from ACPI of_compatible

FromDan O'Donovan <dan@emutex.com>
Date2017-01-27 14:40 +0100
Subject[PATCH v4 0/3] Init device ids from ACPI of_compatible
Message-ID<t4eUW-4Ja-11@gated-at.bofh.it>
In reply to#1565124
When using devicetree, stuff like i2c_client.name or spi_device.modalias
is initialized to the first DT compatible id with the vendor prefix
stripped. Since some drivers rely on this in order to differentiate between
hardware variants, try to replicate it when using ACPI with DT ids.

This also makes it so that the i2c_device_id parameter passed to probe is
non-NULL when matching with ACPI and DT ids.

Tested using ACPI overlays but there is no actual dependency. This series
just extends the PRP0001 feature to be more useful for I2C/SPI.

The patches only touches the ACPI-specific parts of the i2c and spi core.

Here is an example .dsl for an SPI accelerometer connected to minnowboard max:

Device (ACCL)
{
    Name (_ADR, Zero)
    Name (_HID, "PRP0001")
    Name (_UID, One)

    Method (_CRS, 0, Serialized)
    {
	Name (RBUF, ResourceTemplate ()
	{
	    SPISerialBus(1, PolarityLow, FourWireMode, 16,
		    ControllerInitiated, 1000000, ClockPolarityLow,
		    ClockPhaseFirst, "\\_SB.SPI1",)
	    GpioInt (Edge, ActiveHigh, Exclusive, PullDown, 0x0000,
		     "\\_SB.GPO2", 0x00, ResourceConsumer, , )
	    { // Pin list
		    1
	    }
	})
	Return (RBUF)
    }
    Name (_DSD, Package ()
    {
	ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
	Package ()
	{
	    Package () {"compatible", "st,lis3dh"},
	}
    })
}

Link to v3: http://www.spinics.net/lists/linux-acpi/msg71531.html
Changes:
 * Minor cosmetic/readability improvements (Andy Shevchenko)

Link to v2: https://lkml.org/lkml/2016/7/13/392
Changes:
 * Use appropriate subject prefix for each subsystem (Mark Brown)
 * Use ACPI info as before if getting OF info fails (Mark Brown)
 * Minor cosmetic/readability improvements (Rafael J. Wysocki)

Link to v1: https://www.spinics.net/lists/linux-acpi/msg66469.html
Changes:
 * Rebase on after acpi overlays got it.
 * Change acpi_of_modalias outlen param to size_t
 * Use {} after else

Crestez Dan Leonard (3):
  ACPI / bus: Export acpi_of_modalias equiv of of_modalias_node
  i2c: acpi: Initialize info.type from of_compatible
  spi: acpi: Initialize modalias from of_compatible

 drivers/acpi/bus.c      | 35 +++++++++++++++++++++++++++++++++++
 drivers/i2c/i2c-core.c  |  7 ++++++-
 drivers/spi/spi.c       |  9 ++++++++-
 include/acpi/acpi_bus.h |  1 +
 4 files changed, 50 insertions(+), 2 deletions(-)

-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1568361 — [PATCH v4 1/3] ACPI / bus: Export acpi_of_modalias equiv of of_modalias_node

FromDan O'Donovan <dan@emutex.com>
Date2017-01-27 14:40 +0100
Subject[PATCH v4 1/3] ACPI / bus: Export acpi_of_modalias equiv of of_modalias_node
Message-ID<t4eUW-4Ja-17@gated-at.bofh.it>
In reply to#1568357
From: Crestez Dan Leonard <leonard.crestez@intel.com>

When using devicetree stuff like i2c_client.name or spi_device.modalias
is initialized to the first DT compatible id with the vendor prefix
stripped. Since some drivers rely on this try to replicate it when using
ACPI with DT ids.

Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
Signed-off-by: Dan O'Donovan <dan@emutex.com>
Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
 drivers/acpi/bus.c      | 35 +++++++++++++++++++++++++++++++++++
 include/acpi/acpi_bus.h |  1 +
 2 files changed, 36 insertions(+)

diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 95855cb..8b9657f 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -677,6 +677,41 @@ static bool acpi_of_match_device(struct acpi_device *adev,
 	return false;
 }
 
+/**
+ * acpi_of_modalias - Like of_modalias_node for ACPI with DT ids
+ * @adev:	ACPI device object to match.
+ * @outstr:	Pointer to buffer for result
+ * @outlen:	Length of outstr value
+ *
+ * This is a counterpart of of_modalias_node() for struct acpi_device
+ * objects. If there is a compatible string for @adev, copy it to the
+ * @outstr location with the vendor prefix stripped.
+ *
+ * Returns 0 on success or negative errno on failure.
+ */
+int acpi_of_modalias(struct acpi_device *adev, char *outstr, size_t outlen)
+{
+	const union acpi_object *of_compatible;
+	const union acpi_object *obj;
+	const char *str, *chr;
+
+	of_compatible = adev->data.of_compatible;
+	if (!of_compatible)
+		return -ENODEV;
+
+	if (of_compatible->type == ACPI_TYPE_PACKAGE)
+		obj = of_compatible->package.elements;
+	else /* Must be ACPI_TYPE_STRING. */
+		obj = of_compatible;
+
+	str = obj->string.pointer;
+	chr = strchr(str, ',');
+	strlcpy(outstr, chr ? chr + 1 : str, outlen);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(acpi_of_modalias);
+
 static bool __acpi_match_device_cls(const struct acpi_device_id *id,
 				    struct acpi_hardware_id *hwid)
 {
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 4242c31..351b4a4 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -522,6 +522,7 @@ void acpi_bus_trim(struct acpi_device *start);
 acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd);
 int acpi_match_device_ids(struct acpi_device *device,
 			  const struct acpi_device_id *ids);
+int acpi_of_modalias(struct acpi_device *adev, char *outstr, size_t outlen);
 int acpi_create_dir(struct acpi_device *);
 void acpi_remove_dir(struct acpi_device *);
 
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1568362 — [PATCH v4 3/3] spi: acpi: Initialize modalias from of_compatible

FromDan O'Donovan <dan@emutex.com>
Date2017-01-27 14:40 +0100
Subject[PATCH v4 3/3] spi: acpi: Initialize modalias from of_compatible
Message-ID<t4eUW-4Ja-19@gated-at.bofh.it>
In reply to#1568357
From: Crestez Dan Leonard <leonard.crestez@intel.com>

When using devicetree spi_device.modalias is set to the compatible
string with the vendor prefix removed. For SPI devices described via
ACPI the spi_device.modalias string is initialized by acpi_device_hid.
When using ACPI and DT ids this string ends up something like "PRP0001".

Change acpi_register_spi_device to use the of_compatible property if
present. This makes it easier to instantiate spi drivers through ACPI
with DT ids.

Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
Signed-off-by: Dan O'Donovan <dan@emutex.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
 drivers/spi/spi.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 656dd3e..9a8c880 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1722,13 +1722,20 @@ static acpi_status acpi_register_spi_device(struct spi_master *master,
 		return AE_OK;
 	}
 
+	/*
+	 * Populate modalias from compatible property if available,
+	 * otherwise use native ACPI information
+	 */
+	if (acpi_of_modalias(adev, spi->modalias, sizeof(spi->modalias)))
+		strlcpy(spi->modalias, acpi_device_hid(adev),
+			sizeof(spi->modalias));
+
 	if (spi->irq < 0)
 		spi->irq = acpi_dev_gpio_irq_get(adev, 0);
 
 	acpi_device_set_enumerated(adev);
 
 	adev->power.flags.ignore_parent = true;
-	strlcpy(spi->modalias, acpi_device_hid(adev), sizeof(spi->modalias));
 	if (spi_add_device(spi)) {
 		adev->power.flags.ignore_parent = false;
 		dev_err(&master->dev, "failed to add SPI device %s from ACPI\n",
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1568366 — [PATCH v4 2/3] i2c: acpi: Initialize info.type from of_compatible

FromDan O'Donovan <dan@emutex.com>
Date2017-01-27 14:40 +0100
Subject[PATCH v4 2/3] i2c: acpi: Initialize info.type from of_compatible
Message-ID<t4eUX-4Ja-33@gated-at.bofh.it>
In reply to#1568357
From: Crestez Dan Leonard <leonard.crestez@intel.com>

When using devicetree i2c_board_info.type is set to the compatible
string with the vendor prefix removed. For I2C devices described via
ACPI the i2c_board_info.type string is set to the ACPI device name. When
using ACPI and DT ids this string ends up something like "PRP0001:00".

If the of_compatible property is present try to use that instead. This
makes it easier to instantiate i2c drivers through ACPI with DT ids.

Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
Signed-off-by: Dan O'Donovan <dan@emutex.com>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
---
 drivers/i2c/i2c-core.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 583e950..6e99431 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -221,7 +221,12 @@ static int i2c_acpi_get_info(struct acpi_device *adev,
 
 	acpi_dev_free_resource_list(&resource_list);
 
-	strlcpy(info->type, dev_name(&adev->dev), sizeof(info->type));
+	/*
+	 * Populate modalias from compatible property if available,
+	 * otherwise use native ACPI information
+	 */
+	if (acpi_of_modalias(adev, info->type, sizeof(info->type)))
+		strlcpy(info->type, dev_name(&adev->dev), sizeof(info->type));
 
 	return 0;
 }
-- 
2.7.4

[toc] | [prev] | [next] | [standalone]


#1569018 — Re: [PATCH v4 2/3] i2c: acpi: Initialize info.type from of_compatible

FromWolfram Sang <wsa@the-dreams.de>
Date2017-01-28 22:40 +0100
SubjectRe: [PATCH v4 2/3] i2c: acpi: Initialize info.type from of_compatible
Message-ID<t4ISZ-6It-3@gated-at.bofh.it>
In reply to#1568366

[Multipart message — attachments visible in raw view] — view raw

On Fri, Jan 27, 2017 at 01:30:14PM +0000, Dan O'Donovan wrote:
> From: Crestez Dan Leonard <leonard.crestez@intel.com>
> 
> When using devicetree i2c_board_info.type is set to the compatible
> string with the vendor prefix removed. For I2C devices described via
> ACPI the i2c_board_info.type string is set to the ACPI device name. When
> using ACPI and DT ids this string ends up something like "PRP0001:00".
> 
> If the of_compatible property is present try to use that instead. This
> makes it easier to instantiate i2c drivers through ACPI with DT ids.
> 
> Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
> Signed-off-by: Dan O'Donovan <dan@emutex.com>
> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
> Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
> Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>

I assume this shall go in as one series via ACPI tree, so:

Acked-by: Wolfram Sang <wsa@the-dreams.de>

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web