Patchwork i2c: Make I2C ID tables non-mandatory for DT'ed and/or ACPI'ed devices

login
register
mail settings
Submitter Lee Jones
Date May 30, 2014, 12:26 p.m.
Message ID <1401452797-29521-2-git-send-email-lee.jones@linaro.org>
Download mbox | patch
Permalink /patch/354124/
State Superseded
Headers show

Comments

Lee Jones - May 30, 2014, 12:26 p.m.
Currently the I2C framework insists on devices supplying an I2C ID
table.  Many of the devices which do so unnecessarily adding quite a
few wasted lines to kernel code.  This patch allows drivers a means
to 'not' supply the aforementioned table and match on either DT
and/or ACPI match tables instead.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/i2c/i2c-core.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
Wolfram Sang - May 30, 2014, 12:36 p.m.
On Fri, May 30, 2014 at 01:26:36PM +0100, Lee Jones wrote:
> Currently the I2C framework insists on devices supplying an I2C ID
> table.  Many of the devices which do so unnecessarily adding quite a
> few wasted lines to kernel code.  This patch allows drivers a means
> to 'not' supply the aforementioned table and match on either DT
> and/or ACPI match tables instead.
> 
> Signed-off-by: Lee Jones <lee.jones@linaro.org>

Sadly, it is not that easy...

> +	/*
> +	 * An I2C ID table is not madatory, if and only if, a suitable Device
> +	 * Tree and/or ACPI match table entry is supplied for the probing
> +	 * device.
> +	 */

That means we end up with drivers which cannot be used for run-time
instantiation via the 'new_device'-file in sysfs. I don't like that.
Lee Jones - May 30, 2014, 12:55 p.m.
On Fri, 30 May 2014, Wolfram Sang wrote:

> On Fri, May 30, 2014 at 01:26:36PM +0100, Lee Jones wrote:
> > Currently the I2C framework insists on devices supplying an I2C ID
> > table.  Many of the devices which do so unnecessarily adding quite a
> > few wasted lines to kernel code.  This patch allows drivers a means
> > to 'not' supply the aforementioned table and match on either DT
> > and/or ACPI match tables instead.
> > 
> > Signed-off-by: Lee Jones <lee.jones@linaro.org>
> 
> Sadly, it is not that easy...
> 
> > +	/*
> > +	 * An I2C ID table is not madatory, if and only if, a suitable Device
> > +	 * Tree and/or ACPI match table entry is supplied for the probing
> > +	 * device.
> > +	 */
> 
> That means we end up with drivers which cannot be used for run-time
> instantiation via the 'new_device'-file in sysfs. I don't like that.

Would you mind explaining that a little please?  And perhaps point me
to the code?
Lee Jones - May 30, 2014, 1:34 p.m.
> > Currently the I2C framework insists on devices supplying an I2C ID
> > table.  Many of the devices which do so unnecessarily adding quite a
> > few wasted lines to kernel code.  This patch allows drivers a means
> > to 'not' supply the aforementioned table and match on either DT
> > and/or ACPI match tables instead.
> > 
> > Signed-off-by: Lee Jones <lee.jones@linaro.org>
> 
> Sadly, it is not that easy...
> 
> > +	/*
> > +	 * An I2C ID table is not madatory, if and only if, a suitable Device
> > +	 * Tree and/or ACPI match table entry is supplied for the probing
> > +	 * device.
> > +	 */
> 
> That means we end up with drivers which cannot be used for run-time
> instantiation via the 'new_device'-file in sysfs. I don't like that.

I've found the code and taken a quick look at it.  I'm still not sure
I understand your point.  The semantics for any device attempting to
register with an I2C ID table should be unchanged.  The only intended
difference would be for drivers which do not wish to supply one due
to the fact that they have other means of matching, namely DT and
ACPI.

Would you mind telling me what I have changed that affects drivers
registering via Sysfs?
Wolfram Sang - May 30, 2014, 5:48 p.m.
Hi Lee,

sorry for the delay.

> Would you mind telling me what I have changed that affects drivers
> registering via Sysfs?

Check Documentation/i2c/instantiating-devices, method 4. If a driver
does not have i2c_device_id, then this method won't work because the
newly created device has no of_node or ACPI_node and nothing will match.
Looking at the bigger picture, I'd really like to keep this feature.
People use it.

Regards,

   Wolfram
Lee Jones - May 30, 2014, 7:25 p.m.
> > Would you mind telling me what I have changed that affects drivers
> > registering via Sysfs?
> 
> Check Documentation/i2c/instantiating-devices, method 4. If a driver
> does not have i2c_device_id, then this method won't work because the
> newly created device has no of_node or ACPI_node and nothing will match.
> Looking at the bigger picture, I'd really like to keep this feature.
> People use it.

Right, I read the function which provides the functionality, but my
point is; I don't think my patch changes the semantics in a way which
would adversely affect this option.  If you think that it does, can you
specify how please?

Does the sysfs method create a i2c_device_id table?  If not, how does
it probe successfully pre-patch?
Wolfram Sang - May 31, 2014, 1:48 p.m.
> Right, I read the function which provides the functionality, but my
> point is; I don't think my patch changes the semantics in a way which
> would adversely affect this option.  If you think that it does, can you
> specify how please?

Currently, if a driver would be DT only and does not provide a seperate
i2c_device_id table, then the driver is unusable with method 4. I don't
like to have some drivers being capable of it and some not.

> Does the sysfs method create a i2c_device_id table?  If not, how does
> it probe successfully pre-patch?

The sysfs method creates a device. Its name is matched against
i2c_device_ids only since it does not have a node pointer for DT to be
matched against.
Linus Walleij - June 2, 2014, 12:16 p.m.
On Sat, May 31, 2014 at 3:48 PM, Wolfram Sang <wsa@the-dreams.de> wrote:
>
>> Right, I read the function which provides the functionality, but my
>> point is; I don't think my patch changes the semantics in a way which
>> would adversely affect this option.  If you think that it does, can you
>> specify how please?
>
> Currently, if a driver would be DT only and does not provide a seperate
> i2c_device_id table, then the driver is unusable with method 4. I don't
> like to have some drivers being capable of it and some not.
>
>> Does the sysfs method create a i2c_device_id table?  If not, how does
>> it probe successfully pre-patch?
>
> The sysfs method creates a device. Its name is matched against
> i2c_device_ids only since it does not have a node pointer for DT to be
> matched against.

Is this really so useful on embedded systems?

I was under the impression that this method was something used
on say PC desktops with temperature monitors and EEPROMs
on some I2C link on the PCB, usage entirely optional and fun
for userspace hacks.

And when we say "people use it" do we mean "sensors-detect
uses it, on desktops", really?

Yours,
Linus Walleij
--
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
Wolfram Sang - June 2, 2014, 12:38 p.m.
On Mon, Jun 02, 2014 at 02:16:59PM +0200, Linus Walleij wrote:
> On Sat, May 31, 2014 at 3:48 PM, Wolfram Sang <wsa@the-dreams.de> wrote:
> >
> >> Right, I read the function which provides the functionality, but my
> >> point is; I don't think my patch changes the semantics in a way which
> >> would adversely affect this option.  If you think that it does, can you
> >> specify how please?
> >
> > Currently, if a driver would be DT only and does not provide a seperate
> > i2c_device_id table, then the driver is unusable with method 4. I don't
> > like to have some drivers being capable of it and some not.
> >
> >> Does the sysfs method create a i2c_device_id table?  If not, how does
> >> it probe successfully pre-patch?
> >
> > The sysfs method creates a device. Its name is matched against
> > i2c_device_ids only since it does not have a node pointer for DT to be
> > matched against.
> 
> Is this really so useful on embedded systems?

Well, this feature is at least nice with embedded:

---

* You are developing a driver on a test board, where you soldered the I2C
  device yourself.

---

Or during HW bringup, you this or that driver for a device (out-of-tree
vs. in-kernel), and hey, the RTC even has an EEPROM at another address,
let's try. Such things are the use cases I have mostly seen and those
customers liked it.

The problem is that we are talking about matching against I2C slave
drivers. I can't see a line between embedded and non-embedded when it
comes to slaves. They are just slaves and could be on any hardware.
Keeping the bigger picture in mind, IMO it is cumbersome if some drivers
support user-space instantiation and some not.

Though, I wouldn't mind if compatible entries could be passed to the
'new_device' file, in addition to i2c_device_ids. Yet, this needs some
extra handling I haven't found the time for, yet.
Linus Walleij - June 2, 2014, 1:26 p.m.
On Mon, Jun 2, 2014 at 2:38 PM, Wolfram Sang <wsa@the-dreams.de> wrote:

> Though, I wouldn't mind if compatible entries could be passed to the
> 'new_device' file, in addition to i2c_device_ids. Yet, this needs some
> extra handling I haven't found the time for, yet.

Hm that's a way forward then I guess... but passing a compatible
string to that same file is a bit arbitrarily ambigous. So we'd rather
add a new instatiation file named new_device_of_compatible or so?

Yours,
Linus Walleij
--
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
Lee Jones - June 2, 2014, 1:26 p.m.
On Mon, 02 Jun 2014, Wolfram Sang wrote:

> On Mon, Jun 02, 2014 at 02:16:59PM +0200, Linus Walleij wrote:
> > On Sat, May 31, 2014 at 3:48 PM, Wolfram Sang <wsa@the-dreams.de> wrote:
> > >
> > >> Right, I read the function which provides the functionality, but my
> > >> point is; I don't think my patch changes the semantics in a way which
> > >> would adversely affect this option.  If you think that it does, can you
> > >> specify how please?
> > >
> > > Currently, if a driver would be DT only and does not provide a seperate
> > > i2c_device_id table, then the driver is unusable with method 4. I don't
> > > like to have some drivers being capable of it and some not.
> > >
> > >> Does the sysfs method create a i2c_device_id table?  If not, how does
> > >> it probe successfully pre-patch?
> > >
> > > The sysfs method creates a device. Its name is matched against
> > > i2c_device_ids only since it does not have a node pointer for DT to be
> > > matched against.
> > 
> > Is this really so useful on embedded systems?
> 
> Well, this feature is at least nice with embedded:
> 
> ---
> 
> * You are developing a driver on a test board, where you soldered the I2C
>   device yourself.
> 
> ---
> 
> Or during HW bringup, you this or that driver for a device (out-of-tree
> vs. in-kernel), and hey, the RTC even has an EEPROM at another address,
> let's try. Such things are the use cases I have mostly seen and those
> customers liked it.
> 
> The problem is that we are talking about matching against I2C slave
> drivers. I can't see a line between embedded and non-embedded when it
> comes to slaves. They are just slaves and could be on any hardware.
> Keeping the bigger picture in mind, IMO it is cumbersome if some drivers
> support user-space instantiation and some not.
> 
> Though, I wouldn't mind if compatible entries could be passed to the
> 'new_device' file, in addition to i2c_device_ids. Yet, this needs some
> extra handling I haven't found the time for, yet.

Actually, I'm just about to submit a new set.

Hopefully we cover some bases.
Michael Lawnick - June 2, 2014, 2:29 p.m.
Am 02.06.2014 14:16, schrieb Linus Walleij:
> On Sat, May 31, 2014 at 3:48 PM, Wolfram Sang <wsa@the-dreams.de> wrote:
>>
>>> Right, I read the function which provides the functionality, but my
>>> point is; I don't think my patch changes the semantics in a way which
>>> would adversely affect this option.  If you think that it does, can you
>>> specify how please?
>>
>> Currently, if a driver would be DT only and does not provide a seperate
>> i2c_device_id table, then the driver is unusable with method 4. I don't
>> like to have some drivers being capable of it and some not.
>>
>>> Does the sysfs method create a i2c_device_id table?  If not, how does
>>> it probe successfully pre-patch?
>>
>> The sysfs method creates a device. Its name is matched against
>> i2c_device_ids only since it does not have a node pointer for DT to be
>> matched against.
>
> Is this really so useful on embedded systems?
>
> I was under the impression that this method was something used
> on say PC desktops with temperature monitors and EEPROMs
> on some I2C link on the PCB, usage entirely optional and fun
> for userspace hacks.
>
We use it for dynamic instantiating whole subsystems with multiplexers, 
sensors, controllers in an embedded system. The device list is taken 
from an I2C eeprom which gets read on hotplug.

KR
Michael


--
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
Linus Walleij - June 3, 2014, 11:18 a.m.
On Mon, Jun 2, 2014 at 4:29 PM, Michael Lawnick <ml.lawnick@gmx.de> wrote:
> Am 02.06.2014 14:16, schrieb Linus Walleij:

>> Is this really so useful on embedded systems?
>>
>> I was under the impression that this method was something used
>> on say PC desktops with temperature monitors and EEPROMs
>> on some I2C link on the PCB, usage entirely optional and fun
>> for userspace hacks.
>>
> We use it for dynamic instantiating whole subsystems with multiplexers,
> sensors, controllers in an embedded system. The device list is taken from an
> I2C eeprom which gets read on hotplug.

Does this mean that you have stored the names (strings) that are used
by the Linux kernel for identifying the devices into your EEPROM?

That means that you have made the kernel-internal device driver names
an ABI which is unfortunate :-/

This is one of the reasons to why we insist on device tree: OS neutral
hardware description.

Yours,
Linus Walleij
--
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
Michael Lawnick - June 4, 2014, 6:09 a.m.
Am 03.06.2014 13:18, schrieb Linus Walleij:
> On Mon, Jun 2, 2014 at 4:29 PM, Michael Lawnick <ml.lawnick@gmx.de> wrote:
>> Am 02.06.2014 14:16, schrieb Linus Walleij:
>
>>> Is this really so useful on embedded systems?
>>>
>>> I was under the impression that this method was something used
>>> on say PC desktops with temperature monitors and EEPROMs
>>> on some I2C link on the PCB, usage entirely optional and fun
>>> for userspace hacks.
>>>
>> We use it for dynamic instantiating whole subsystems with multiplexers,
>> sensors, controllers in an embedded system. The device list is taken from an
>> I2C eeprom which gets read on hotplug.
>
> Does this mean that you have stored the names (strings) that are used
> by the Linux kernel for identifying the devices into your EEPROM?
>
> That means that you have made the kernel-internal device driver names
> an ABI which is unfortunate :-/
>
> This is one of the reasons to why we insist on device tree: OS neutral
> hardware description.

The eeprom contains a device tree that is dynamically merged.

KR
Michael


--
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
Linus Walleij - June 12, 2014, 7:55 a.m.
On Wed, Jun 4, 2014 at 8:09 AM, Michael Lawnick <ml.lawnick@gmx.de> wrote:
> Am 03.06.2014 13:18, schrieb Linus Walleij:
>> On Mon, Jun 2, 2014 at 4:29 PM, Michael Lawnick <ml.lawnick@gmx.de> wrote:
>>>
>>> Am 02.06.2014 14:16, schrieb Linus Walleij:
>>
>>
>>>> Is this really so useful on embedded systems?
>>>>
>>>> I was under the impression that this method was something used
>>>> on say PC desktops with temperature monitors and EEPROMs
>>>> on some I2C link on the PCB, usage entirely optional and fun
>>>> for userspace hacks.
>>>>
>>> We use it for dynamic instantiating whole subsystems with multiplexers,
>>> sensors, controllers in an embedded system. The device list is taken from
>>> an
>>> I2C eeprom which gets read on hotplug.
>>
>>
>> Does this mean that you have stored the names (strings) that are used
>> by the Linux kernel for identifying the devices into your EEPROM?
>>
>> That means that you have made the kernel-internal device driver names
>> an ABI which is unfortunate :-/
>>
>> This is one of the reasons to why we insist on device tree: OS neutral
>> hardware description.
>
> The eeprom contains a device tree that is dynamically merged.

That is a kind of way of saying "yes we made the kernel-internal
driver named an ABI" I guess?

Yours,
Linus Walleij
--
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
Michael Lawnick - June 12, 2014, 9:28 a.m.
Am 12.06.2014 09:55, schrieb Linus Walleij:
> On Wed, Jun 4, 2014 at 8:09 AM, Michael Lawnick <ml.lawnick@gmx.de> wrote:
>> Am 03.06.2014 13:18, schrieb Linus Walleij:
>>> On Mon, Jun 2, 2014 at 4:29 PM, Michael Lawnick <ml.lawnick@gmx.de> wrote:
>>>>
>>>> Am 02.06.2014 14:16, schrieb Linus Walleij:
>>>
>>>
>>>>> Is this really so useful on embedded systems?
>>>>>
>>>>> I was under the impression that this method was something used
>>>>> on say PC desktops with temperature monitors and EEPROMs
>>>>> on some I2C link on the PCB, usage entirely optional and fun
>>>>> for userspace hacks.
>>>>>
>>>> We use it for dynamic instantiating whole subsystems with multiplexers,
>>>> sensors, controllers in an embedded system. The device list is taken from
>>>> an
>>>> I2C eeprom which gets read on hotplug.
>>>
>>>
>>> Does this mean that you have stored the names (strings) that are used
>>> by the Linux kernel for identifying the devices into your EEPROM?
>>>
>>> That means that you have made the kernel-internal device driver names
>>> an ABI which is unfortunate :-/
>>>
>>> This is one of the reasons to why we insist on device tree: OS neutral
>>> hardware description.
>>
>> The eeprom contains a device tree that is dynamically merged.
>
> That is a kind of way of saying "yes we made the kernel-internal
> driver named an ABI" I guess?

Sorry, I fear I don't get you. Could you please rephrase?
Of course it might be that I'm missing some fundamental idea of device 
tree. The mechanism we use started with K2.6 where device tree usage on 
MIPS wasn't that intensive. Anyway the original idea of removing 
i2c_table now moved towards non-mandatory usage.

Patch

diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 7c7f4b8..703da9e 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -260,13 +260,25 @@  static int i2c_device_probe(struct device *dev)
 {
 	struct i2c_client	*client = i2c_verify_client(dev);
 	struct i2c_driver	*driver;
+	const struct of_device_id *of_match	= dev->driver->of_match_table;
+	const struct acpi_device_id *acpi_match	= dev->driver->acpi_match_table;
 	int status;
 
 	if (!client)
 		return 0;
 
 	driver = to_i2c_driver(dev->driver);
-	if (!driver->probe || !driver->id_table)
+	if (!driver->probe)
+		return -EINVAL;
+
+	/*
+	 * An I2C ID table is not madatory, if and only if, a suitable Device
+	 * Tree and/or ACPI match table entry is supplied for the probing
+	 * device.
+	 */
+	if (!driver->id_table &&
+	    !of_match_device(of_match, dev) &&
+	    !acpi_match_device(acpi_match, dev))
 		return -ENODEV;
 
 	if (!device_can_wakeup(&client->dev))
@@ -275,7 +287,12 @@  static int i2c_device_probe(struct device *dev)
 	dev_dbg(dev, "probe\n");
 
 	acpi_dev_pm_attach(&client->dev, true);
-	status = driver->probe(client, i2c_match_id(driver->id_table, client));
+
+	if (!driver->id_table)
+		status = driver->probe(client, NULL);
+	else
+		status = driver->probe(client,
+				       i2c_match_id(driver->id_table, client));
 	if (status)
 		acpi_dev_pm_detach(&client->dev, true);