diff mbox

ACPI I2C device-driver matching issue

Message ID CAE7DoPbODXiUcsxMD1qRXCvX_o0evf6KsK2qu65g9uxnw5GNAw@mail.gmail.com
State Superseded
Headers show

Commit Message

Ben Gardner Oct. 22, 2015, 6:05 p.m. UTC
Hi all,

I have a custom Baytrail board with a M24C02 EEPROM attached to I2C bus 3.
I am using coreboot/SeaBIOS, so I have complete control over the ACPI tables.
I am using Linux 4.2.3.

I have defined a EEPROM device on I2C3 using I2cSerialBus() and it
shows up as expected.

Scope (\_SB.PCI0.I2C3) {
  Device (EEP0) {
    Name (_CID, Package() { "24c02" })
    Name (_CRS, ResourceTemplate () {
      I2cSerialBus (0x0057, ControllerInitiated, 400000,
        AddressingMode7Bit, "\\_SB.PCI0.I2C3", 0x00,
        ResourceConsumer,,)
    })
  }
}

Everything is nearly working, except that acpi_i2c_add_device() is
using the ACPI name to match the driver, which is "24C02:00".
The "at42" driver supports the device with the "24c02" alias.
i2c_match_id() in i2c-core.c uses strcmp() to match the device.
That obviously doesn't match, as "24c02" != "24C02:00".

When I modified acpi_i2c_add_device() to truncate at the colon and
convert it to lower case, it matches and works.


What is the right way to declare a I2C device in ACPI so that it
matches existing drivers?


For reference only, I included the change I made to get it to work below.
(Copy/pasted into gmail, so tabs are lost.)

Thanks,
Ben Gardner

                dev_err(&adapter->dev,
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Comments

Rafael J. Wysocki Oct. 24, 2015, 3:32 p.m. UTC | #1
CC: Mika

On Thursday, October 22, 2015 01:05:42 PM Ben Gardner wrote:
> Hi all,
> 
> I have a custom Baytrail board with a M24C02 EEPROM attached to I2C bus 3.
> I am using coreboot/SeaBIOS, so I have complete control over the ACPI tables.
> I am using Linux 4.2.3.
> 
> I have defined a EEPROM device on I2C3 using I2cSerialBus() and it
> shows up as expected.
> 
> Scope (\_SB.PCI0.I2C3) {
>   Device (EEP0) {
>     Name (_CID, Package() { "24c02" })
>     Name (_CRS, ResourceTemplate () {
>       I2cSerialBus (0x0057, ControllerInitiated, 400000,
>         AddressingMode7Bit, "\\_SB.PCI0.I2C3", 0x00,
>         ResourceConsumer,,)
>     })
>   }
> }
> 
> Everything is nearly working, except that acpi_i2c_add_device() is
> using the ACPI name to match the driver, which is "24C02:00".
> The "at42" driver supports the device with the "24c02" alias.
> i2c_match_id() in i2c-core.c uses strcmp() to match the device.
> That obviously doesn't match, as "24c02" != "24C02:00".
> 
> When I modified acpi_i2c_add_device() to truncate at the colon and
> convert it to lower case, it matches and works.
> 
> 
> What is the right way to declare a I2C device in ACPI so that it
> matches existing drivers?
> 
> 
> For reference only, I included the change I made to get it to work below.
> (Copy/pasted into gmail, so tabs are lost.)
> 
> Thanks,
> Ben Gardner
> 
> diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
> index c83e4d1..64caddc 100644
> --- a/drivers/i2c/i2c-core.c
> +++ b/drivers/i2c/i2c-core.c
> @@ -144,7 +144,13 @@ static acpi_status
> acpi_i2c_add_device(acpi_handle handle, u32 level,
>                 return AE_OK;
> 
>         adev->power.flags.ignore_parent = true;
> -       strlcpy(info.type, dev_name(&adev->dev), sizeof(info.type));
> +       {
> +               const char *dn = dev_name(&adev->dev);
> +               int idx;
> +               for (idx = 0; idx < sizeof(info.type) - 1 && dn[idx]
> && dn[idx] != ':'; idx++)
> +                       info.type[idx] = tolower(dn[idx]);
> +       }
>         if (!i2c_new_device(adapter, &info)) {
>                 adev->power.flags.ignore_parent = false;
>                 dev_err(&adapter->dev,
> --
> To unsubscribe from this list: send the line "unsubscribe linux-acpi" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
Mika Westerberg Oct. 26, 2015, 9:29 a.m. UTC | #2
On Sat, Oct 24, 2015 at 05:32:29PM +0200, Rafael J. Wysocki wrote:
> CC: Mika
> 
> On Thursday, October 22, 2015 01:05:42 PM Ben Gardner wrote:
> > Hi all,
> > 
> > I have a custom Baytrail board with a M24C02 EEPROM attached to I2C bus 3.
> > I am using coreboot/SeaBIOS, so I have complete control over the ACPI tables.
> > I am using Linux 4.2.3.
> > 
> > I have defined a EEPROM device on I2C3 using I2cSerialBus() and it
> > shows up as expected.
> > 
> > Scope (\_SB.PCI0.I2C3) {
> >   Device (EEP0) {
> >     Name (_CID, Package() { "24c02" })
> >     Name (_CRS, ResourceTemplate () {
> >       I2cSerialBus (0x0057, ControllerInitiated, 400000,
> >         AddressingMode7Bit, "\\_SB.PCI0.I2C3", 0x00,
> >         ResourceConsumer,,)
> >     })
> >   }
> > }

This is being discussed in another thread:

http://marc.info/?l=linux-acpi&m=144562104914442&w=2
--
To unsubscribe from this list: send the line "unsubscribe linux-i2c" 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 c83e4d1..64caddc 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -144,7 +144,13 @@  static acpi_status
acpi_i2c_add_device(acpi_handle handle, u32 level,
                return AE_OK;

        adev->power.flags.ignore_parent = true;
-       strlcpy(info.type, dev_name(&adev->dev), sizeof(info.type));
+       {
+               const char *dn = dev_name(&adev->dev);
+               int idx;
+               for (idx = 0; idx < sizeof(info.type) - 1 && dn[idx]
&& dn[idx] != ':'; idx++)
+                       info.type[idx] = tolower(dn[idx]);
+       }
        if (!i2c_new_device(adapter, &info)) {
                adev->power.flags.ignore_parent = false;