diff mbox

[2/3] acpi i2c: Initialize info.type from of_compatible

Message ID 13cb5b7766b1b25a2bb61ce0053a38f6f440907b.1466014238.git.leonard.crestez@intel.com (mailing list archive)
State New, archived
Headers show

Commit Message

Crestez Dan Leonard June 15, 2016, 6:30 p.m. UTC
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>
---
 drivers/i2c/i2c-core.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

Comments

Mika Westerberg June 16, 2016, 8:11 a.m. UTC | #1
On Wed, Jun 15, 2016 at 09:30:28PM +0300, Crestez Dan Leonard wrote:
> 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.

Adding Jarkko -- he was the original author of I2C/SPI device naming in
ACPI. Since this only affects devices with PRP0001 in their _HID/_CID,
it should not break anything.

> Signed-off-by: Crestez Dan Leonard <leonard.crestez@intel.com>
> ---
>  drivers/i2c/i2c-core.c | 8 +++++++-
>  1 file changed, 7 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index af11b65..5ab1fb9 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -188,8 +188,14 @@ static acpi_status acpi_i2c_add_device(acpi_handle handle, u32 level,
>  
>  	acpi_dev_free_resource_list(&resource_list);
>  
> +	if (adev->data.of_compatible) {

We may want to add acpi_is_of_compatible(adev) or similar at some point.

> +		ret = acpi_of_modalias(adev, info.type, sizeof(info.type));
> +		if (ret)
> +			return -EINVAL;
> +	} else
> +		strlcpy(info.type, dev_name(&adev->dev), sizeof(info.type));

Please use {} in the else branch as well. See Documentation/CodingStyle.

> +
>  	adev->power.flags.ignore_parent = true;
> -	strlcpy(info.type, dev_name(&adev->dev), sizeof(info.type));
>  	if (!i2c_new_device(adapter, &info)) {
>  		adev->power.flags.ignore_parent = false;
>  		dev_err(&adapter->dev,
> -- 
> 2.5.5
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Crestez Dan Leonard June 17, 2016, 12:07 p.m. UTC | #2
On 06/16/2016 11:11 AM, Mika Westerberg wrote:
> On Wed, Jun 15, 2016 at 09:30:28PM +0300, Crestez Dan Leonard wrote:
>> 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.
> 
> Adding Jarkko -- he was the original author of I2C/SPI device naming in
> ACPI. Since this only affects devices with PRP0001 in their _HID/_CID,
> it should not break anything.

It's possible to have something like this:

            Name (_HID, "XXX1234")
            Name (_CID, "PRP0001")
            Name (_DSD, Package () {
                ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
                Package () {
                    Package () {"compatible", "vendor,x1234"},
                }
            })

With these patches the i2c device name changes from "XXX1234:00" to
"x1234". This would happen even if a driver matches the XXX1234 acpi ID.
It's not clear if anyone actually uses that or if this change would be
harmful.

It theory it would be possible to use of_compatible for naming only if
there are no other real IDs. I don't think it's worthwhile.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mika Westerberg June 17, 2016, 12:19 p.m. UTC | #3
On Fri, Jun 17, 2016 at 03:07:39PM +0300, Crestez Dan Leonard wrote:
> On 06/16/2016 11:11 AM, Mika Westerberg wrote:
> > On Wed, Jun 15, 2016 at 09:30:28PM +0300, Crestez Dan Leonard wrote:
> >> 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.
> > 
> > Adding Jarkko -- he was the original author of I2C/SPI device naming in
> > ACPI. Since this only affects devices with PRP0001 in their _HID/_CID,
> > it should not break anything.
> 
> It's possible to have something like this:
> 
>             Name (_HID, "XXX1234")
>             Name (_CID, "PRP0001")
>             Name (_DSD, Package () {
>                 ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
>                 Package () {
>                     Package () {"compatible", "vendor,x1234"},
>                 }
>             })
> 
> With these patches the i2c device name changes from "XXX1234:00" to
> "x1234". This would happen even if a driver matches the XXX1234 acpi ID.
> It's not clear if anyone actually uses that or if this change would be
> harmful.

I have not seen a single machine using _DSD with PRP0001 so I don't
think it is a problem.

> It theory it would be possible to use of_compatible for naming only if
> there are no other real IDs. I don't think it's worthwhile.

I agree.
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index af11b65..5ab1fb9 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -188,8 +188,14 @@  static acpi_status acpi_i2c_add_device(acpi_handle handle, u32 level,
 
 	acpi_dev_free_resource_list(&resource_list);
 
+	if (adev->data.of_compatible) {
+		ret = acpi_of_modalias(adev, info.type, sizeof(info.type));
+		if (ret)
+			return -EINVAL;
+	} else
+		strlcpy(info.type, dev_name(&adev->dev), sizeof(info.type));
+
 	adev->power.flags.ignore_parent = true;
-	strlcpy(info.type, dev_name(&adev->dev), sizeof(info.type));
 	if (!i2c_new_device(adapter, &info)) {
 		adev->power.flags.ignore_parent = false;
 		dev_err(&adapter->dev,