Re: [i2c] [PATCH 1/5] Implement module aliasing for i2c to translate from device tree names
On 1/13/08, Jean Delvare <[EMAIL PROTECTED]> wrote: > Hi Jon, > > On Sat, 12 Jan 2008 11:26:34 -0500, Jon Smirl wrote: > > The common scheme used elsewhere in the kernel for handling more than > > one device in a single driver is aliases. The i2c code's existing > > driver_name/type combination is a different way of implementing the > > same feature. But there is no real need for driver_name/type on any > > platform if aliases are used. Back in version 10 or 11 I had code in > > there which replaced the two fields with aliases on all platforms but > > too many people objected so I removed it.. > > While I agree that aliases make i2c_client.driver_name obsolete, > i2c_client.type is still needed. Not for device/driver matching in the > kernel, granted, but for device identification from userspace. This is > a first problem your patch has: when using your aliasing mechanism, the > type string is left empty. i2c-core exports this value to user-space > via the "name" sysfs attribute, and some libraries and applications > make use of it. I know of libsensors at least, but I guess there are > more. I can't apply your patch until this problem is solved, otherwise > we would break some user-space applications. > > > IMHO, driver_name/type should be removed in new style drivers and > > replaced with aliases on all platforms since aliases are the standard > > kernel mechanism. > > I agree. But we can take your aliasing code now (once you have > addressed the issues I raised) and convert the users of driver_name > later; it doesn't have to be done all at once. GregKH, adding a new dynamically loadable subsystem is not something that happens every day, can you check to make sure all of the standard kernels mechanisms are being used? I'm not totally sure how the modalias naming code is supposed to be done. The subsystem core code in these patches needs review. Jean, could you take over the i2c core portion of the patch? That will let you decide exactly how you want the driver_name/name fields to be dealt with. After you get standard naming support into i2c core I'll rework the rest of the patch to use your new code. I don't think driver_name/name fields should be stored in an i2c structure at all. They are redundant with the standard mechanism. The kernel automatically exposes modalias as a sysfs attribute so the string must be recorded further down in the driver support layers. No need to keep a copy in the i2c structure. Standard devices don't export a 'name' attribute. To see the driver name for a device in sysfs look at the 'driver' link. > The second problem I have with your patch is that you make use of the > driver_name field, while I ultimately want to get rid of it. I'd rather > see you use a different field for aliases, so that the later removal of > the driver_name field and the associated mechanism is easier. > > A third, related problem, is the contents of the modalias file when > using your patch. When I tested on my ADM1032 evaluation board, the > modalias contained "adm1032". This isn't a valid module alias string: > "modprobe adm1032" doesn't work. What works is "modprobe i2c:Nadm1032" > so the modalias file should contain "i2c:Nadm1032". Just take a look at > all modalias files in /sys, they all include the subsystem prefix and a > simple modprobe `cat modalias` loads the required driver. I fail to see > why the i2c subsystem would be different. > > I said this is related to the second problem because right now, > i2c-core can't easily differentiate between driver names and aliases, > as both are stored in i2c_client.driver_name. Having separate fields > would make it possible (and relatively easy) to add the required prefix > before aliases but not before driver names. The only drawback is that > it will increase the size of the i2c_client structure, but I do not > care that much given that it is only temporary. > > -- > Jean Delvare > -- Jon Smirl [EMAIL PROTECTED] ___ Linuxppc-dev mailing list Linuxppc-dev@ozlabs.org https://ozlabs.org/mailman/listinfo/linuxppc-dev
Re: [i2c] [PATCH 1/5] Implement module aliasing for i2c to translate from device tree names
Hi Jon, On Sat, 12 Jan 2008 11:26:34 -0500, Jon Smirl wrote: > The common scheme used elsewhere in the kernel for handling more than > one device in a single driver is aliases. The i2c code's existing > driver_name/type combination is a different way of implementing the > same feature. But there is no real need for driver_name/type on any > platform if aliases are used. Back in version 10 or 11 I had code in > there which replaced the two fields with aliases on all platforms but > too many people objected so I removed it.. While I agree that aliases make i2c_client.driver_name obsolete, i2c_client.type is still needed. Not for device/driver matching in the kernel, granted, but for device identification from userspace. This is a first problem your patch has: when using your aliasing mechanism, the type string is left empty. i2c-core exports this value to user-space via the "name" sysfs attribute, and some libraries and applications make use of it. I know of libsensors at least, but I guess there are more. I can't apply your patch until this problem is solved, otherwise we would break some user-space applications. > IMHO, driver_name/type should be removed in new style drivers and > replaced with aliases on all platforms since aliases are the standard > kernel mechanism. I agree. But we can take your aliasing code now (once you have addressed the issues I raised) and convert the users of driver_name later; it doesn't have to be done all at once. The second problem I have with your patch is that you make use of the driver_name field, while I ultimately want to get rid of it. I'd rather see you use a different field for aliases, so that the later removal of the driver_name field and the associated mechanism is easier. A third, related problem, is the contents of the modalias file when using your patch. When I tested on my ADM1032 evaluation board, the modalias contained "adm1032". This isn't a valid module alias string: "modprobe adm1032" doesn't work. What works is "modprobe i2c:Nadm1032" so the modalias file should contain "i2c:Nadm1032". Just take a look at all modalias files in /sys, they all include the subsystem prefix and a simple modprobe `cat modalias` loads the required driver. I fail to see why the i2c subsystem would be different. I said this is related to the second problem because right now, i2c-core can't easily differentiate between driver names and aliases, as both are stored in i2c_client.driver_name. Having separate fields would make it possible (and relatively easy) to add the required prefix before aliases but not before driver names. The only drawback is that it will increase the size of the i2c_client structure, but I do not care that much given that it is only temporary. -- Jean Delvare ___ Linuxppc-dev mailing list Linuxppc-dev@ozlabs.org https://ozlabs.org/mailman/listinfo/linuxppc-dev
Re: [i2c] [PATCH 1/5] Implement module aliasing for i2c to translate from device tree names
On 1/12/08, Jean Delvare <[EMAIL PROTECTED]> wrote: > Hi Jon, > > On Fri, 11 Jan 2008 20:20:15 +0100, Jean Delvare wrote: > > > +{ > > > + /* only powerpc drivers implement the id_table, > > > +* it is empty on other platforms */ > > > + if (id) { > > > + while (id->name[0]) { > > > + if (strcmp(client->driver_name, id->name) == 0) > > > > This doesn't look right to me. You should be comparing client->name, > > not client->driver_name, with id->name. Where id_table is implemented, > > client->driver_name might not even be set. I see that the next patch in > > the series makes use of client->driver_name as well, so your code > > "works"... but this ain't correct still. > > Err, scratch this (and related comments), I just realized what you were > trying to do. That's different from what I had in mind and so I read > your code wrong. I'll read it (and test it) again not making this > incorrect assumption and my comments will likely be different after > that. Well, I still think that it needs to be changed a bit, but > probably not in the direction I suggested at first (which, I realize > now, has its own share of issues - so it's not fair to me to point you > there.) The common scheme used elsewhere in the kernel for handling more than one device in a single driver is aliases. The i2c code's existing driver_name/type combination is a different way of implementing the same feature. But there is no real need for driver_name/type on any platform if aliases are used. Back in version 10 or 11 I had code in there which replaced the two fields with aliases on all platforms but too many people objected so I removed it.. IMHO, driver_name/type should be removed in new style drivers and replaced with aliases on all platforms since aliases are the standard kernel mechanism. > > Sorry for the trouble. I'll post updated comments later today, but I'm > also pretty busy with other issues, some of which need to be solved > before 2.6.24 is released so I can't really delay them. > > -- > Jean Delvare > -- Jon Smirl [EMAIL PROTECTED] ___ Linuxppc-dev mailing list Linuxppc-dev@ozlabs.org https://ozlabs.org/mailman/listinfo/linuxppc-dev
Re: [i2c] [PATCH 1/5] Implement module aliasing for i2c to translate from device tree names
Hi Jon, On Fri, 11 Jan 2008 20:20:15 +0100, Jean Delvare wrote: > > +{ > > + /* only powerpc drivers implement the id_table, > > +* it is empty on other platforms */ > > + if (id) { > > + while (id->name[0]) { > > + if (strcmp(client->driver_name, id->name) == 0) > > This doesn't look right to me. You should be comparing client->name, > not client->driver_name, with id->name. Where id_table is implemented, > client->driver_name might not even be set. I see that the next patch in > the series makes use of client->driver_name as well, so your code > "works"... but this ain't correct still. Err, scratch this (and related comments), I just realized what you were trying to do. That's different from what I had in mind and so I read your code wrong. I'll read it (and test it) again not making this incorrect assumption and my comments will likely be different after that. Well, I still think that it needs to be changed a bit, but probably not in the direction I suggested at first (which, I realize now, has its own share of issues - so it's not fair to me to point you there.) Sorry for the trouble. I'll post updated comments later today, but I'm also pretty busy with other issues, some of which need to be solved before 2.6.24 is released so I can't really delay them. -- Jean Delvare ___ Linuxppc-dev mailing list Linuxppc-dev@ozlabs.org https://ozlabs.org/mailman/listinfo/linuxppc-dev
Re: [i2c] [PATCH 1/5] Implement module aliasing for i2c to translate from device tree names
Hi Jon, On Wed, 19 Dec 2007 23:41:38 -0500, Jon Smirl wrote: > This patch allows new style i2c chip drivers to have alias names using > the official kernel aliasing system and MODULE_DEVICE_TABLE(). I've > tested it on PowerPC and x86. This change is required for PowerPC > device tree support. Your patch adds compilation warnings on several i2c drivers: drivers/hwmon/f75375s.c:135: warning: initialization from incompatible pointer type drivers/i2c/chips/ds1682.c:241: warning: initialization from incompatible pointer type drivers/i2c/chips/tps65010.c:590: warning: initialization from incompatible pointer type drivers/i2c/chips/tsl2550.c:461: warning: initialization from incompatible pointer type drivers/rtc/rtc-ds1307.c:538: warning: initialization from incompatible pointer type drivers/rtc/rtc-ds1374.c:430: warning: initialization from incompatible pointer type drivers/rtc/rtc-m41t80.c:897: warning: initialization from incompatible pointer type drivers/rtc/rtc-rs5c372.c:652: warning: initialization from incompatible pointer type And there may be more drivers affected that just happen to not build on x86_64 so I did not spot them. Please check this and fix them all. I see that 4 of these warnings are fixed in the next patch of this series, but that's not sufficient: each patch must be correct by itself, so that bisections can be performed safely. > > Signed-off-by: Jon Smirl <[EMAIL PROTECTED]> > --- > > drivers/i2c/i2c-core.c | 32 ++-- > include/linux/i2c.h |9 - > include/linux/mod_devicetable.h | 20 > scripts/mod/file2alias.c| 19 +++ > 4 files changed, 69 insertions(+), 11 deletions(-) > > > diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c > index b5e13e4..fce06fd 100644 > --- a/drivers/i2c/i2c-core.c > +++ b/drivers/i2c/i2c-core.c > @@ -47,10 +47,25 @@ static DEFINE_IDR(i2c_adapter_idr); > > /* - > */ > > -static int i2c_device_match(struct device *dev, struct device_driver *drv) > +static const struct i2c_device_id *i2c_device_match(const struct > i2c_device_id *id, struct i2c_client *client) Line too long, please fold. Following the pci and usb examples, this function would be named i2c_match_id. > +{ > + /* only powerpc drivers implement the id_table, > + * it is empty on other platforms */ > + if (id) { > + while (id->name[0]) { > + if (strcmp(client->driver_name, id->name) == 0) This doesn't look right to me. You should be comparing client->name, not client->driver_name, with id->name. Where id_table is implemented, client->driver_name might not even be set. I see that the next patch in the series makes use of client->driver_name as well, so your code "works"... but this ain't correct still. > + return id; > + id++; > + } > + } > + return NULL; > +} > + > +static int i2c_bus_match(struct device *dev, struct device_driver *drv) And this function would be named i2c_device_match (i.e. don't change the name.) > { > struct i2c_client *client = to_i2c_client(dev); > struct i2c_driver *driver = to_i2c_driver(drv); > + const struct i2c_device_id *found_id; > > /* make legacy i2c drivers bypass driver model probing entirely; >* such drivers scan each i2c adapter/bus themselves. > @@ -58,9 +73,11 @@ static int i2c_device_match(struct device *dev, struct > device_driver *drv) > if (!is_newstyle_driver(driver)) > return 0; > > - /* new style drivers use the same kind of driver matching policy > - * as platform devices or SPI: compare device and driver IDs. > - */ This comment still applies to the last part of the function. > + /* match on an id table if there is one */ > + found_id = i2c_device_match(driver->id_table, client); > + if (found_id) > + return 1; If the driver has an id_table but the device doesn't match any entry, you fallback to the string comparison below. Is this really what you want? Why not return 0 right away instead? Again, client->driver_name might not even be set. > + > return strcmp(client->driver_name, drv->name) == 0; > } > > @@ -89,12 +106,15 @@ static int i2c_device_probe(struct device *dev) > { > struct i2c_client *client = to_i2c_client(dev); > struct i2c_driver *driver = to_i2c_driver(dev->driver); > + const struct i2c_device_id *id; > > if (!driver->probe) > return -ENODEV; > client->driver = driver; > dev_dbg(dev, "probe\n"); > - return driver->probe(client); > + > + id = i2c_device_match(driver->id_table, client); > + return driver->probe(client, id); > } > > static int i2c_device_remove(struct device *dev) > @@ -189,7 +209,7 @@ static struct d