Version 17, series to add device tree naming to i2c
Subsystems (6)
cover Version 17, series to add device tree naming to i2c
Since copying i2c-mpc.c to maintain support for the ppc architecture seems to be an issue; instead rework i2c-mpc.c to use CONFIG_PPC_MERGE #ifdefs to support both the ppc and powerpc architecture. When ppc is deleted in six months these #ifdefs will need to be removed.
Another rework of the i2c for powerpc device tree patch. This version implements standard alias naming only on the powerpc platform and only for the device tree names. The old naming mechanism of i2c_client.name,driver_name is left in place and not changed for non-powerpc platforms. This patch is fully capable of dynamically loading the i2c modules. You can modprobe in the i2c-mpc driver and the i2c modules described in the device tree will be automatically loaded. Modules also work if compiled in.
The follow on patch to module-init-tools is also needed since the i2c subsystem has never implemented dynamic loading.
The following series implements standard linux module aliasing for i2c modules on arch=powerpc. It then converts the mpc i2c driver from being a platform driver to an open firmware one. I2C device names are picked up from the device tree. Module aliasing is used to translate from device tree names into to linux kernel names. Several i2c drivers are updated to use the new aliasing.
--
Jon Smirl
[email protected]
PATCH 1/5 Implement module aliasing for i2c to translate from device tree names
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.
---
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(-)
drivers/i2c/i2c-core.c +26 -6
@@ -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) +{ +/* 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 ) +return id; + id++; + } + } +return NULL ; +} + +static int i2c_bus_match (struct device *dev,struct device_driver *drv) {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. -*/ +/* match on an id table if there is one */ + found_id =i2c_device_match (driver->id_table, client); +if (found_id) +return 1 ; +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 device_attribute i2c_dev_attrs[] = {static struct bus_type i2c_bus_type = { .name ="i2c" , .dev_attrs = i2c_dev_attrs, - .match = i2c_device_match, + .match = i2c_bus_match, .uevent = i2c_device_uevent, .probe = i2c_device_probe, .remove = i2c_device_remove,
include/linux/i2c.h +4 -5
@@ -126,7 +126,7 @@ struct i2c_driver {* With the driver model, device enumeration is NEVER done by drivers; * it's done by infrastructure. (NEW STYLE DRIVERS ONLY) */ -int (*probe)(struct i2c_client *); +int (*probe)(struct i2c_client *,const struct i2c_device_id *id);int (*remove)(struct i2c_client *);/* driver model interfaces that don't relate to enumeration */
@@ -141,11 +141,10 @@ struct i2c_driver {struct device_driver driver;struct list_head list; +struct i2c_device_id *id_table; };#define to_i2c_driver (d) container_of(d, struct i2c_driver, driver) -#define I2C_NAME_SIZE 20 -/** * struct i2c_client - represent an I2C slave device * @flags: I2C_CLIENT_TEN indicates the device uses a ten bit chip address;
@@ -179,7 +178,7 @@ struct i2c_client {/* to the client */ struct device dev;/* the device structure */ int irq;/* irq issued by device (or -1) */ -char driver_name[KOBJ_NAME_LEN ]; +char driver_name[I2C_NAME_SIZE ];struct list_head list;struct completion released; };
@@ -223,7 +222,7 @@ static inline void i2c_set_clientdata (struct i2c_client *dev, void *data)* with the adapter already known. */ struct i2c_board_info { -char driver_name[KOBJ_NAME_LEN ]; +char driver_name[I2C_NAME_SIZE ];char type[I2C_NAME_SIZE ];unsigned short flags;unsigned short addr;
include/linux/mod_devicetable.h +20 -0
@@ -367,4 +367,24 @@ struct virtio_device_id { };#define VIRTIO_DEV_ANY_ID 0xffffffff +/* i2c */ + +/* These defines are used to separate PowerPC open firmware +* drivers into their own namespace */ +#define I2C_NAME_SIZE (16*3) +#define I2C_MODULE_PREFIX "i2c:N" +#ifdef CONFIG_OF +#define OF_I2C_PREFIX "OF," +#define I2C_OF_MODULE_PREFIX I2C_MODULE_PREFIX OF_I2C_PREFIX +#define OF_I2C_ID (s,d) {OF_I2C_PREFIX s, (d) }, +#else +#define OF_I2C_ID (s,d) +#endif + +struct i2c_device_id { +char name[I2C_NAME_SIZE ]; +kernel_ulong_t driver_data;/* Data private to the driver */ +}; + +#endif /* LINUX_MOD_DEVICETABLE_H */
scripts/mod/file2alias.c +19 -0
@@ -539,6 +539,21 @@ static int do_virtio_entry(const char *filename, struct virtio_device_id *id,return 1 ; } +/* Looks like: i2c:Ns */ +static int do_i2c_entry (const char *filename,struct i2c_device_id *id, +char *alias) +{ +char *tmp; +sprintf (alias,I2C_MODULE_PREFIX "%s" , id->name); + +/* Replace all whitespace with underscores */ +for (tmp = alias; tmp && *tmp; tmp++) +if (isspace (*tmp)) + *tmp ='_' ; + +return 1 ; +} +/* Ignore any prefix, eg. v850 prepends _ */ static inline int sym_is (const char *symbol,const char *name) {
@@ -669,6 +684,10 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,do_table (symval, sym->st_size,sizeof (struct virtio_device_id ),"virtio" , do_virtio_entry, mod); + else if (sym_is(symname, "__mod_i2c_device_table")) + do_table(symval, sym->st_size, + sizeof(struct i2c_device_id), "i2c", + do_i2c_entry, mod);free (zeros ); }
Re: [i2c] [PATCH 1/5] Implement module aliasing for i2c to translate from device tree names
Hi Jon,
Quoted 4 lines · Jon Smirl
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.
Quoted 16 lines
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(-)drivers/i2c/i2c-core.c +0
-0
drivers/i2c/i2c-core.c static DEFINE_IDR(i2c_adapter_idr); · line 50
Quoted 5 lines
drivers/i2c/i2c-core.c +1
-1@@ -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.
drivers/i2c/i2c-core.c static DEFINE_IDR(i2c_adapter_idr); · line 56
Quoted 6 lines
drivers/i2c/i2c-core.c +6
-0+{ +/* 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.
drivers/i2c/i2c-core.c static DEFINE_IDR(i2c_adapter_idr); · line 64
Quoted 8 lines
drivers/i2c/i2c-core.c +8
-0+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.)
Quoted 8 lines
drivers/i2c/i2c-core.c +1
-0{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.
drivers/i2c/i2c-core.c static int i2c_device_match(struct device *dev, struct device_driver *drv) · line 63
Quoted 6 lines
drivers/i2c/i2c-core.c +0
-3@@ -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.
drivers/i2c/i2c-core.c static int i2c_device_match(struct device *dev, struct device_driver *drv) · line 79
Quoted 4 lines
drivers/i2c/i2c-core.c +4
-0+/* 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.
Quoted 57 lines
drivers/i2c/i2c-core.c +6
-2+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 device_attribute i2c_dev_attrs[] = {static struct bus_type i2c_bus_type = { .name ="i2c" , .dev_attrs = i2c_dev_attrs, - .match = i2c_device_match, + .match = i2c_bus_match, .uevent = i2c_device_uevent, .probe = i2c_device_probe, .remove = i2c_device_remove,include/linux/i2c.h +2
-3@@ -126,7 +126,7 @@ struct i2c_driver {* With the driver model, device enumeration is NEVER done by drivers; * it's done by infrastructure. (NEW STYLE DRIVERS ONLY) */ -int (*probe)(struct i2c_client *); +int (*probe)(struct i2c_client *,const struct i2c_device_id *id);int (*remove)(struct i2c_client *);/* driver model interfaces that don't relate to enumeration */ @@ -141,11 +141,10 @@ struct i2c_driver {struct device_driver driver;struct list_head list; +struct i2c_device_id *id_table; };#define to_i2c_driver (d) container_of(d, struct i2c_driver, driver) -#define I2C_NAME_SIZE 20 -/** * struct i2c_client - represent an I2C slave device * @flags: I2C_CLIENT_TEN indicates the device uses a ten bit chip address;
include/linux/i2c.h struct i2c_client { · line 181
Quoted 5 lines
include/linux/i2c.h +1
-1@@ -179,7 +178,7 @@ struct i2c_client {/* to the client */ struct device dev;/* the device structure */ int irq;/* irq issued by device (or -1) */ -char driver_name[KOBJ_NAME_LEN ]; +char driver_name[I2C_NAME_SIZE ];
Rationale please? I can't see why this change would be needed.
include/linux/i2c.h static inline void i2c_set_clientdata (struct i2c_client *dev, void *data) · line 225
Quoted 9 lines
include/linux/i2c.h +1
-1struct list_head list;struct completion released; };@@ -223,7 +222,7 @@ static inline void i2c_set_clientdata (struct i2c_client *dev, void *data)* with the adapter already known. */ struct i2c_board_info { -char driver_name[KOBJ_NAME_LEN ]; +char driver_name[I2C_NAME_SIZE ];
Ditto.
Quoted 8 lines
include/linux/i2c.h +0
-0char type[I2C_NAME_SIZE ];unsigned short flags;unsigned short addr;include/linux/mod_devicetable.h +0
-0
include/linux/mod_devicetable.h struct virtio_device_id { · line 374
Quoted 8 lines
include/linux/mod_devicetable.h +5
-0@@ -367,4 +367,24 @@ struct virtio_device_id { };#define VIRTIO_DEV_ANY_ID 0xffffffff +/* i2c */ + +/* These defines are used to separate PowerPC open firmware +* drivers into their own namespace */ +#define I2C_NAME_SIZE (16*3)
Rationale for this value? 48 bytes seems quite large, the longest string you handle in the next patch is only 15-bytes long. 32 would seem to be a more reasonable compromise (but see also my other reply to this thread for why you probably shouldn't change I2C_NAME_SIZE at all.)
include/linux/mod_devicetable.h struct virtio_device_id { · line 375
Quoted 1 line
include/linux/mod_devicetable.h +1
-0+#define I2C_MODULE_PREFIX "i2c:N"
This "N" shouldn't be part of the prefix... if it should be there at all. It makes the aliases harder to read and I don't see what it is good for.
include/linux/mod_devicetable.h struct virtio_device_id { · line 378
Quoted 3 lines
include/linux/mod_devicetable.h +3
-0+#ifdef CONFIG_OF +#define OF_I2C_PREFIX "OF," +#define I2C_OF_MODULE_PREFIX I2C_MODULE_PREFIX OF_I2C_PREFIX
This one isn't used anywhere?
include/linux/mod_devicetable.h struct virtio_device_id { · line 379
Quoted 1 line
include/linux/mod_devicetable.h +1
-0+#define OF_I2C_ID (s,d) {OF_I2C_PREFIX s, (d) },
Coding style: space afte opening curly brace.
Quoted 16 lines
include/linux/mod_devicetable.h +10
-0+#else +#define OF_I2C_ID (s,d) +#endif + +struct i2c_device_id { +char name[I2C_NAME_SIZE ]; +kernel_ulong_t driver_data;/* Data private to the driver */ +}; + +#endif /* LINUX_MOD_DEVICETABLE_H */ scripts/mod/file2alias.c +0
-0
scripts/mod/file2alias.c static int do_virtio_entry(const char *filename, struct virtio_device_id *id, · line 547
Quoted 9 lines
scripts/mod/file2alias.c +6
-0@@ -539,6 +539,21 @@ static int do_virtio_entry(const char *filename, struct virtio_device_id *id,return 1 ; } +/* Looks like: i2c:Ns */ +static int do_i2c_entry (const char *filename,struct i2c_device_id *id, +char *alias) +{ +char *tmp; +sprintf (alias,I2C_MODULE_PREFIX "%s" , id->name);
Coding style: no space before opening parenthesis. Also please use tabs for indentation.
scripts/mod/file2alias.c static int do_virtio_entry(const char *filename, struct virtio_device_id *id, · line 552
Quoted 5 lines
scripts/mod/file2alias.c +5
-0+ +/* Replace all whitespace with underscores */ +for (tmp = alias; tmp && *tmp; tmp++) +if (isspace (*tmp)) + *tmp ='_' ;
Is this needed? Are there really OF (or other) device names that contain whitespaces? None of the examples in this patch series do, and I can't think of any.
Quoted 17 lines
scripts/mod/file2alias.c +8
-0+ +return 1 ; +} +/* Ignore any prefix, eg. v850 prepends _ */ static inline int sym_is (const char *symbol,const char *name) {@@ -669,6 +684,10 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,do_table (symval, sym->st_size,sizeof (struct virtio_device_id ),"virtio" , do_virtio_entry, mod); + else if (sym_is(symname, "__mod_i2c_device_table")) + do_table(symval, sym->st_size, + sizeof(struct i2c_device_id), "i2c", + do_i2c_entry, mod);free (zeros ); }
Signature · 1 line
Jean Delvare
Re: [i2c] [PATCH 1/5] Implement module aliasing for i2c to translate from device tree names
Hi Jon,
Quoted 4 lines · Jean Delvare
Quoted 4 lines
drivers/i2c/i2c-core.c +4
-0+{ +/* only powerpc drivers implement the id_table, +* it is empty on other platforms */ +if (id) {
Quoted 8 lines
drivers/i2c/i2c-core.c static DEFINE_IDR(i2c_adapter_idr); · line 56
Quoted 2 lines
drivers/i2c/i2c-core.c +2
-0+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, notclient->driver_name, withid->name. Whereid_tableis implemented,client->driver_namemight not even be set. I see that the next patch in the series makes use ofclient->driver_nameas 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.
Signature · 1 line
Jean Delvare
Re: [i2c] [PATCH 1/5] Implement module aliasing for i2c to translate from device tree names
Quoted 16 lines · Jean Delvare
Hi Jon,
Quoted 7 lines · Jean Delvare
drivers/i2c/i2c-core.c static DEFINE_IDR(i2c_adapter_idr); · line 56
Quoted 6 lines
drivers/i2c/i2c-core.c +6
-0+{ +/* 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 )Quoted 5 lines
This doesn't look right to me. You should be comparing
client->name, notclient->driver_name, withid->name. Whereid_tableis implemented,client->driver_namemight not even be set. I see that the next patch in the series makes use ofclient->driver_nameas well, so your code "works"... but this ain't correct still.
Quoted 8 lines
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.
Quoted 8 lines
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
Signature · 2 lines
Jon Smirl [email protected]
Re: [i2c] [PATCH 1/5] Implement module aliasing for i2c to translate from device tree names
Hi Jon,
Quoted 7 lines · Jon Smirl
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.
Quoted 3 lines
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.
Signature · 1 line
Jean Delvare
Re: [i2c] [PATCH 1/5] Implement module aliasing for i2c to translate from device tree names
Quoted 21 lines · Jean Delvare
Hi Jon,
Quoted 7 lines · Jon Smirl
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.
Quoted 7 lines
Quoted 3 lines
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_namelater; 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.
Quoted 25 lines
The second problem I have with your patch is that you make use of the
driver_namefield, 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 thedriver_namefield 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 modprobecat modaliasloads 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_clientstructure, but I do not care that much given that it is only temporary.--
Jean Delvare
Signature · 2 lines
Jon Smirl [email protected]
Re: [PATCH 1/5] Implement module aliasing for i2c to translate from device tree names
Quoted 16 lines · Jon Smirl
Quoted 8 lines · Jean Delvare
Quoted 3 lines · Jon Smirl
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_namelater; 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.
Quoted 4 lines
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.
Yes, that could be done, and I agree that it will probably be faster than iterative review/rework cycles between you and me. I'll free some cycles next week for that.
Quoted 6 lines
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.
Really? I didn't know that. So that's another thing that the i2c subsystem is not doing like the rest of the kernel? Can you please point me to the code that does this?
Quoted 2 lines
Standard devices don't export a 'name' attribute. To see the driver name for a device in sysfs look at the 'driver' link.
The driver name and the device name are different things! The "name" attribute that i2c devices have tells user-space the device name, not the driver name.
You may not like what the i2c subsystem does but you can't ignore its history. The name attribute of i2c devices has been there pretty much forever and user-space relies on it, thus we can't remove it.
Signature · 1 line
Jean Delvare
Re: [PATCH 1/5] Implement module aliasing for i2c to translate from device tree names
Quoted 29 lines · Jean Delvare
Quoted 16 lines · Jon Smirl
Quoted 8 lines · Jean Delvare
Quoted 3 lines · Jon Smirl
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_namelater; 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.
Quoted 4 lines
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.
Yes, that could be done, and I agree that it will probably be faster than iterative review/rework cycles between you and me. I'll free some cycles next week for that.
Quoted 3 lines
I don't think driver_name/name fields should be stored in an i2c structure at all. They are redundant with the standard mechanism.
Quoted 7 lines
Quoted 3 lines
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.
Really? I didn't know that. So that's another thing that the i2c subsystem is not doing like the rest of the kernel? Can you please point me to the code that does this?
I never noticed it before either. Just do find | grep modalias in /sys and see that every driver has a modalias attribute. It is probably implement in drivers/base.
Quoted 7 lines
Quoted 3 lines
Standard devices don't export a 'name' attribute. To see the driver name for a device in sysfs look at the 'driver' link.
The driver name and the device name are different things! The "name" attribute that i2c devices have tells user-space the device name, not the driver name.
For this system my i2c device names are:
0-0050 0-0051 0-0052 0-0053
How does the name=eeprom attribute interact with this? All four of my devices have name=eeprom. What is the name field used for in user space?
jonsmirl@terra:/sys/bus/i2c/devices/0-0052$ ls driver eeprom modalias name power subsystem uevent jonsmirl@terra:/sys/bus/i2c/devices/0-0052$ cat name eeprom jonsmirl@terra:/sys/bus/i2c/devices/0-0052$ ls driver -l lrwxrwxrwx 1 root root 0 2008-01-13 12:46 driver -> ../../../../../../bus/i2c/drivers/eeprom jonsmirl@terra:/sys/bus/i2c/devices/0-0052$
jonsmirl@terra:/sys/bus/i2c/drivers$ ls eeprom jonsmirl@terra:/sys/bus/i2c/drivers$ ls eeprom 0-0050 0-0051 0-0052 0-0053 bind module uevent unbind
Quoted 8 lines
You may not like what the i2c subsystem does but you can't ignore its history. The name attribute of i2c devices has been there pretty much forever and user-space relies on it, thus we can't remove it.
--
Jean Delvare
Signature · 2 lines
Jon Smirl [email protected]
Re: [PATCH 1/5] Implement module aliasing for i2c to translate from device tree names
Hi Jon,
Quoted 6 lines · Jon Smirl
Quoted 5 lines · Jean Delvare
Quoted 3 lines · Jon Smirl
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.
Quoted 7 lines
Quoted 3 lines
Really? I didn't know that. So that's another thing that the i2c subsystem is not doing like the rest of the kernel? Can you please point me to the code that does this?
I never noticed it before either. Just do find | grep modalias in /sys and see that every driver has a modalias attribute. It is probably implement in
drivers/base.
This doesn't mean that the kernel does this automatically! It could also be that each subsystem does it on its own. Given that the format of the modalias depends on the bus type, it wouldn't be all that surprising. Anyway, I'll go look at how the other subsystems handle it before going on.
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
Standard devices don't export a 'name' attribute. To see the driver name for a device in sysfs look at the 'driver' link.
The driver name and the device name are different things! The "name" attribute that i2c devices have tells user-space the device name, not the driver name.
For this system my i2c device names are:
0-0050 0-0051 0-0052 0-0053
These are not device names, these are device bus IDs. They tell you how to access the devices, but they do not tell you what these devices are.
Quoted 3 lines
How does the name=eeprom attribute interact with this? All four of my devices have name=eeprom. What is the name field used for in user space?
The eeprom case might be a bit confusing because that i2c driver supports a single device type, so the driver name is the same as the device name. Take a look at the hwmon/lm90 driver for a better example:
this device supports 7 different devices. The devices are mostly compatible so it made sense to have a single driver for them, but they all differ in some way. For example, the LM90 doesn't support PEC, while the ADM1032 does. User-space needs to be able to distinguish between the various types. That's the reason why we export the device name through sysfs.
Most i2c sensor drivers support several chip types, and libsensors has been relying heavily on the name attribute. Less so with the lm-sensors 3.0.0 rewrite, where most things are automatically detected, but if nothing else, giving humans a way to distinguish between the different sensor chip types is very useful. Also, not everyone will upgrade to lm-sensors 3.0.0 so we need to keep supporting the previous versions.
Signature · 1 line
Jean Delvare
Re: [PATCH 1/5] Implement module aliasing for i2c to translate from device tree names
Quoted 50 lines · Jean Delvare
Hi Jon,
Quoted 6 lines · Jon Smirl
Quoted 5 lines · Jean Delvare
Quoted 3 lines · Jon Smirl
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.
Quoted 7 lines
Quoted 3 lines
Really? I didn't know that. So that's another thing that the i2c subsystem is not doing like the rest of the kernel? Can you please point me to the code that does this?
I never noticed it before either. Just do find | grep modalias in /sys and see that every driver has a modalias attribute. It is probably implement in
drivers/base.This doesn't mean that the kernel does this automatically! It could also be that each subsystem does it on its own. Given that the format of the modalias depends on the bus type, it wouldn't be all that surprising. Anyway, I'll go look at how the other subsystems handle it before going on.
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
Standard devices don't export a 'name' attribute. To see the driver name for a device in sysfs look at the 'driver' link.
The driver name and the device name are different things! The "name" attribute that i2c devices have tells user-space the device name, not the driver name.
For this system my i2c device names are:
0-0050 0-0051 0-0052 0-0053These are not device names, these are device bus IDs. They tell you how to access the devices, but they do not tell you what these devices are.
Quoted 3 lines
How does the name=eeprom attribute interact with this? All four of my devices have name=eeprom. What is the name field used for in user space?
The eeprom case might be a bit confusing because that i2c driver supports a single device type, so the driver name is the same as the device name. Take a look at the hwmon/lm90 driver for a better example:
this device supports 7 different devices. The devices are mostly compatible so it made sense to have a single driver for them, but they all differ in some way. For example, the LM90 doesn't support PEC, while the ADM1032 does. User-space needs to be able to distinguish between the various types. That's the reason why we export the device name through sysfs.
Quoted 6 lines
Most i2c sensor drivers support several chip types, and libsensors has been relying heavily on the name attribute. Less so with the lm-sensors 3.0.0 rewrite, where most things are automatically detected, but if nothing else, giving humans a way to distinguish between the different sensor chip types is very useful. Also, not everyone will upgrade to lm-sensors 3.0.0 so we need to keep supporting the previous versions.
Another way to handle this is to have the drivers register multiple times using different names. So LM90 would register as both LM90 and ADM1032. All the code is shared, you just register it multiple times under different names.
Signature · 2 lines
Jon Smirl [email protected]
Re: [PATCH 1/5] Implement module aliasing for i2c to translate from device tree names
Quoted 18 lines · Jon Smirl
Quoted 10 lines · Jean Delvare
The eeprom case might be a bit confusing because that i2c driver supports a single device type, so the driver name is the same as the device name. Take a look at the hwmon/lm90 driver for a better example:
this device supports 7 different devices. The devices are mostly compatible so it made sense to have a single driver for them, but they all differ in some way. For example, the LM90 doesn't support PEC, while the ADM1032 does. User-space needs to be able to distinguish between the various types. That's the reason why we export the device name through sysfs.Quoted 6 lines
Most i2c sensor drivers support several chip types, and libsensors has been relying heavily on the name attribute. Less so with the lm-sensors 3.0.0 rewrite, where most things are automatically detected, but if nothing else, giving humans a way to distinguish between the different sensor chip types is very useful. Also, not everyone will upgrade to lm-sensors 3.0.0 so we need to keep supporting the previous versions.
Quoted 4 lines
Another way to handle this is to have the drivers register multiple times using different names. So LM90 would register as both LM90 and ADM1032. All the code is shared, you just register it multiple times under different names.
This won't let us get rid of the name attribute. As I repeatedly explained, removing that file now would instantly break at least all versions of lm-sensors before 3.0.0. This alone is enough to make it unacceptable for the years to come.
Not to mention that this seems like a waste of kernel memory. The name attribute certainly takes one order of magnitude less memory than registering the same driver multiple times.
I'm not sure why you want these i2c chip names to go way, given that the module aliases you'd like to add are almost the same, just in a different form and using OF names instead of arbitrary names.
Signature · 1 line
Jean Delvare
PATCH 2/5 Modify several rtc drivers to use the alias names list property of i2c
In reply to Jon SmirlThis patch modifies the ds1307, ds1374, and rs5c372 i2c drivers to support device tree names using the new i2c mod alias support
---
arch/powerpc/sysdev/fsl_soc.c | 44 ++++---------------------------- drivers/rtc/rtc-ds1307.c | 20 +++++++++++++- drivers/rtc/rtc-ds1374.c | 9 ++++++ drivers/rtc/rtc-m41t80.c | 57 ++++++++++++++++++++++++++++------------- drivers/rtc/rtc-rs5c372.c | 16 ++++++++++-- 5 files changed, 85 insertions(+), 61 deletions(-)
arch/powerpc/sysdev/fsl_soc.c +6 -38
@@ -320,48 +320,12 @@ arch_initcall(gfar_of_init);#ifdef CONFIG_I2C_BOARDINFO #include <linux/i2c.h> -struct i2c_driver_device { -char *of_device; -char *i2c_driver; -char *i2c_type; -}; - -static struct i2c_driver_device i2c_devices[]__initdata = { - {"ricoh,rs5c372a" ,"rtc-rs5c372" ,"rs5c372a" ,}, - {"ricoh,rs5c372b" ,"rtc-rs5c372" ,"rs5c372b" ,}, - {"ricoh,rv5c386" ,"rtc-rs5c372" ,"rv5c386" ,}, - {"ricoh,rv5c387a" ,"rtc-rs5c372" ,"rv5c387a" ,}, - {"dallas,ds1307" ,"rtc-ds1307" ,"ds1307" ,}, - {"dallas,ds1337" ,"rtc-ds1307" ,"ds1337" ,}, - {"dallas,ds1338" ,"rtc-ds1307" ,"ds1338" ,}, - {"dallas,ds1339" ,"rtc-ds1307" ,"ds1339" ,}, - {"dallas,ds1340" ,"rtc-ds1307" ,"ds1340" ,}, - {"stm,m41t00" ,"rtc-ds1307" ,"m41t00" }, - {"dallas,ds1374" ,"rtc-ds1374" ,"rtc-ds1374" ,}, -}; - -static int __init of_find_i2c_driver (struct device_node *node, -struct i2c_board_info *info) -{ -int i; - -for (i =0 ; i <ARRAY_SIZE (i2c_devices); i++) { -if (!of_device_is_compatible (node, i2c_devices[i].of_device)) -continue ; -if (strlcpy (info->driver_name, i2c_devices[i].i2c_driver, -KOBJ_NAME_LEN ) >=KOBJ_NAME_LEN || -strlcpy (info->type, i2c_devices[i].i2c_type, -I2C_NAME_SIZE ) >=I2C_NAME_SIZE ) -return -ENOMEM ; -return 0 ; - } -return -ENODEV ; -}static void __init of_register_i2c_devices (struct device_node *adap_node,int bus_num) {struct device_node *node =NULL ; +const char *compatible;while ((node =of_get_next_child (adap_node, node))) {struct i2c_board_info info = {};
@@ -378,8 +342,12 @@ static void __init of_register_i2c_devices(struct device_node *adap_node,if (info.irq ==NO_IRQ ) info.irq =-1 ; -if (of_find_i2c_driver (node, &info) <0 ) + compatible =of_get_property (node,"compatible" , &len); +if (!compatible) { +printk (KERN_WARNING "i2c-mpc.c: invalid entry, missing compatible attribute\n" );continue ; + } +strncpy (info.driver_name, compatible,sizeof (info.driver_name)); info.addr = *addr;
drivers/rtc/rtc-ds1307.c +18 -2
@@ -139,6 +139,17 @@ static inline const struct chip_desc *find_chip(const char *s)return NULL ; } +static struct i2c_device_id ds1307_id[] = { + OF_I2C_ID("dallas,ds1307", ds_1307) + OF_I2C_ID("dallas,ds1337", ds_1337) + OF_I2C_ID("dallas,ds1338", ds_1338) + OF_I2C_ID("dallas,ds1339", ds_1339) + OF_I2C_ID("dallas,ds1340", ds_1340) + OF_I2C_ID("stm,m41t00", m41t00) + {}, +}; +MODULE_DEVICE_TABLE (i2c, ds1307_id); +static int ds1307_get_time (struct device *dev,struct rtc_time *t) {struct ds1307 *ds1307 =dev_get_drvdata (dev);
@@ -326,7 +337,7 @@ static struct bin_attribute nvram = {static struct i2c_driver ds1307_driver; -static int __devinit ds1307_probe (struct i2c_client *client) +static int __devinit ds1307_probe (struct i2c_client *client,const struct i2c_device_id *id) {struct ds1307 *ds1307;int err = -ENODEV ;
@@ -334,7 +345,11 @@ static int __devinit ds1307_probe(struct i2c_client *client)const struct chip_desc *chip;struct i2c_adapter *adapter =to_i2c_adapter (client->dev.parent); - chip =find_chip (client->name); +if (id) + chip = &chips[id->driver_data]; +else + chip =find_chip (client->name); +if (!chip) {dev_err (&client->dev,"unknown chip type '%s'\n" , client->name);
@@ -537,6 +552,7 @@ static struct i2c_driver ds1307_driver = { }, .probe = ds1307_probe, .remove = __devexit_p(ds1307_remove), + .id_table = ds1307_id, };static int __init ds1307_init (void )
drivers/rtc/rtc-ds1374.c +8 -1
@@ -41,6 +41,12 @@#define DS1374_REG_SR_AF 0x01/* Alarm Flag */ #define DS1374_REG_TCR 0x09/* Trickle Charge */ +static struct i2c_device_id ds1374_id[] = { + OF_I2C_ID("dallas,ds1374", 0) + {}, +}; +MODULE_DEVICE_TABLE (i2c, ds1374_id); +struct ds1374 {struct i2c_client *client;struct rtc_device *rtc;
@@ -355,7 +361,7 @@ static const struct rtc_class_ops ds1374_rtc_ops = { .ioctl = ds1374_ioctl, }; -static int ds1374_probe (struct i2c_client *client) +static int ds1374_probe (struct i2c_client *client,const struct i2c_device_id *id) {struct ds1374 *ds1374;int ret;
@@ -429,6 +435,7 @@ static struct i2c_driver ds1374_driver = { }, .probe = ds1374_probe, .remove = __devexit_p(ds1374_remove), + .id_table = ds1374_id, };static int __init ds1374_init (void )
drivers/rtc/rtc-m41t80.c +39 -18
117 lines not on this page · raw message
drivers/rtc/rtc-rs5c372.c +14 -2
@@ -69,6 +69,15 @@ enum rtc_type { rtc_rv5c387a, }; +static struct i2c_device_id rs5c372_id[] = { + OF_I2C_ID("ricoh,rs5c372a", rtc_rs5c372a) + OF_I2C_ID("ricoh,rs5c372b", rtc_rs5c372b) + OF_I2C_ID("ricoh,rv5c386", rtc_rv5c386) + OF_I2C_ID("ricoh,rv5c387a", rtc_rv5c387a) + {}, +}; +MODULE_DEVICE_TABLE (i2c, rs5c372_id); +/* REVISIT: this assumes that: * - we're in the 21st century, so it's safe to ignore the century * bit for rv5c38[67] (REG_MONTH bit 7);
@@ -494,7 +503,7 @@ static void rs5c_sysfs_unregister(struct device *dev)static struct i2c_driver rs5c372_driver; -static int rs5c372_probe (struct i2c_client *client) +static int rs5c372_probe (struct i2c_client *client,const struct i2c_device_id *id) {int err =0 ;struct rs5c372 *rs5c372;
@@ -522,7 +531,9 @@ static int rs5c372_probe(struct i2c_client *client)if (err <0 ) goto exit_kfree; -if (strcmp (client->name,"rs5c372a" ) ==0 ) +if (id) + rs5c372->type = id->driver_data; +else if (strcmp (client->name,"rs5c372a" ) ==0 ) rs5c372->type = rtc_rs5c372a;else if (strcmp (client->name,"rs5c372b" ) ==0 ) rs5c372->type = rtc_rs5c372b;
@@ -651,6 +662,7 @@ static struct i2c_driver rs5c372_driver = { }, .probe = rs5c372_probe, .remove = rs5c372_remove, + .id_table = rs5c372_id, };static __init int rs5c372_init (void )
PATCH 3/5 Clean up error returns
In reply to Jon SmirlReturn errors that were being ignored in the mpc-i2c driver
---
drivers/i2c/busses/i2c-mpc.c | 30 +++++++++++++++++------------- 1 files changed, 17 insertions(+), 13 deletions(-)
drivers/i2c/busses/i2c-mpc.c +17 -13
@@ -180,7 +180,7 @@ static void mpc_i2c_stop(struct mpc_i2c *i2c)static int mpc_write (struct mpc_i2c *i2c,int target,const u8 * data,int length,int restart) { -int i; +int i, result;unsigned timeout = i2c->adap.timeout;u32 flags = restart ?CCR_RSTA :0 ;
@@ -192,15 +192,17 @@ static int mpc_write(struct mpc_i2c *i2c, int target,/* Write target byte */ writeb ((target <<1 ), i2c->base +MPC_I2C_DR ); -if (i2c_wait (i2c, timeout,1 ) <0 ) -return -1 ; + result =i2c_wait (i2c, timeout,1 ); +if (result <0 ) +return result;for (i =0 ; i < length; i++) {/* Write data byte */ writeb (data[i], i2c->base +MPC_I2C_DR ); -if (i2c_wait (i2c, timeout,1 ) <0 ) -return -1 ; + result =i2c_wait (i2c, timeout,1 ); +if (result <0 ) +return result; }return 0 ;
@@ -210,7 +212,7 @@ static int mpc_read(struct mpc_i2c *i2c, int target, u8 * data, int length, int restart) { unsigned timeout = i2c->adap.timeout; -int i; +int i, result;u32 flags = restart ?CCR_RSTA :0 ;/* Start with MEN */
@@ -221,8 +223,9 @@ static int mpc_read(struct mpc_i2c *i2c, int target,/* Write target address byte - this time with the read flag set */ writeb ((target <<1 ) |1 , i2c->base +MPC_I2C_DR ); -if (i2c_wait (i2c, timeout,1 ) <0 ) -return -1 ; + result =i2c_wait (i2c, timeout,1 ); +if (result <0 ) +return result;if (length) {if (length ==1 )
@@ -234,8 +237,9 @@ static int mpc_read(struct mpc_i2c *i2c, int target, }for (i =0 ; i < length; i++) { -if (i2c_wait (i2c, timeout,0 ) <0 ) -return -1 ; + result =i2c_wait (i2c, timeout,0 ); +if (result <0 ) +return result;/* Generate txack on next to last byte */ if (i == length -2 )
@@ -321,9 +325,9 @@ static int fsl_i2c_probe(struct platform_device *pdev) pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data; -if (!(i2c =kzalloc (sizeof (*i2c),GFP_KERNEL ))) { + i2c =kzalloc (sizeof (*i2c),GFP_KERNEL ); +if (!i2c)return -ENOMEM ; - } i2c->irq =platform_get_irq (pdev,0 );if (i2c->irq <0 ) {
@@ -381,7 +385,7 @@ static int fsl_i2c_remove(struct platform_device *pdev)i2c_del_adapter (&i2c->adap);platform_set_drvdata (pdev,NULL ); -if (i2c->irq !=0 ) +if (i2c->irq !=NO_IRQ )free_irq (i2c->irq, i2c);iounmap (i2c->base);
PATCH 4/5 Convert PowerPC MPC i2c to of_platform_driver from platform_driver
In reply to Jon SmirlConvert MPC i2c driver from being a platform_driver to an open firmware version. Error returns were improved. Routine names were changed from fsl_ to mpc_ to make them match the file name.
---
arch/powerpc/sysdev/fsl_soc.c | 96 ---------------------- drivers/i2c/busses/i2c-mpc.c | 183 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 180 insertions(+), 99 deletions(-)
arch/powerpc/sysdev/fsl_soc.c +0 -96
@@ -318,102 +318,6 @@ err:arch_initcall (gfar_of_init); -#ifdef CONFIG_I2C_BOARDINFO -#include <linux/i2c.h> - -static void __init of_register_i2c_devices (struct device_node *adap_node, -int bus_num) -{ -struct device_node *node =NULL ; -const char *compatible; - -while ((node =of_get_next_child (adap_node, node))) { -struct i2c_board_info info = {}; -const u32 *addr; -int len; - - addr =of_get_property (node,"reg" , &len); -if (!addr || len <sizeof (int ) || *addr > (1 <<10 ) -1 ) { -printk (KERN_WARNING "fsl_soc.c: invalid i2c device entry\n" ); -continue ; - } - - info.irq =irq_of_parse_and_map (node,0 ); -if (info.irq ==NO_IRQ ) - info.irq =-1 ; - - compatible =of_get_property (node,"compatible" , &len); -if (!compatible) { -printk (KERN_WARNING "i2c-mpc.c: invalid entry, missing compatible attribute\n" ); -continue ; - } -strncpy (info.driver_name, compatible,sizeof (info.driver_name)); - - info.addr = *addr; - -i2c_register_board_info (bus_num, &info,1 ); - } -} - -static int __init fsl_i2c_of_init (void ) -{ -struct device_node *np; -unsigned int i; -struct platform_device *i2c_dev; -int ret; - -for (np =NULL , i =0 ; - (np =of_find_compatible_node (np,"i2c" ,"fsl-i2c" )) !=NULL ; - i++) { -struct resource r[2 ]; -struct fsl_i2c_platform_data i2c_data; -const unsigned char *flags =NULL ; - -memset (&r,0 ,sizeof (r)); -memset (&i2c_data,0 ,sizeof (i2c_data)); - - ret =of_address_to_resource (np,0 , &r[0 ]); -if (ret) - goto err; - -of_irq_to_resource (np,0 , &r[1 ]); - - i2c_dev =platform_device_register_simple ("fsl-i2c" , i, r,2 ); -if (IS_ERR (i2c_dev)) { - ret =PTR_ERR (i2c_dev); - goto err; - } - - i2c_data.device_flags =0 ; - flags =of_get_property (np,"dfsrr" ,NULL ); -if (flags) - i2c_data.device_flags |=FSL_I2C_DEV_SEPARATE_DFSRR ; - - flags =of_get_property (np,"fsl5200-clocking" ,NULL ); -if (flags) - i2c_data.device_flags |=FSL_I2C_DEV_CLOCK_5200 ; - - ret = -platform_device_add_data (i2c_dev, &i2c_data, -sizeof (struct -fsl_i2c_platform_data )); -if (ret) - goto unreg; - -of_register_i2c_devices (np, i); - } - -return 0 ; - -unreg: -platform_device_unregister (i2c_dev); -err: -return ret; -} - -arch_initcall (fsl_i2c_of_init); -#endif -#ifdef CONFIG_PPC_83xxstatic int __init mpc83xx_wdt_init (void ) {
drivers/i2c/busses/i2c-mpc.c +180 -3
212 lines not on this page · raw message
Re: [PATCH 4/5] Convert PowerPC MPC i2c to of_platform_driver from platform_driver
Quoted 3 lines · Jon Smirl
Convert MPC i2c driver from being a
platform_driverto an open firmware version. Error returns were improved. Routine names were changed fromfsl_tompc_to make them match the file name.
In discussions BenH and I have had, we've actually concluded that moving this from platform drivers to of_platform drives is not actually a good idea.
In fact we're planning to move away from of_platform devices and drivers and instead develop a framework for instantiating platform devices or i2c devices or whatever devices from the device tree nodes.
Signature · 4 lines
David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson
Re: [PATCH 4/5] Convert PowerPC MPC i2c to of_platform_driver from platform_driver
Quoted 5 lines · David Gibson
Quoted 3 lines · Jon Smirl
Convert MPC i2c driver from being a
platform_driverto an open firmware version. Error returns were improved. Routine names were changed fromfsl_tompc_to make them match the file name.
Quoted 7 lines
In discussions BenH and I have had, we've actually concluded that moving this from platform drivers to
of_platformdrives is not actually a good idea.In fact we're planning to move away from
of_platformdevices and drivers and instead develop a framework for instantiating platform devices or i2c devices or whatever devices from the device tree nodes.
There's been talk about that for a long time. Whenever that framework is done, all the other drivers that have been converted (or written) must/can be converted back as well.
Meanwhile, this should go in so those of us who can make use of the other improvements the series brings can make use of them.
Thanks,
Olof
Re: [PATCH 4/5] Convert PowerPC MPC i2c to of_platform_driver from platform_driver
In reply to David GibsonQuoted 5 lines · David Gibson
Quoted 3 lines · Jon Smirl
Convert MPC i2c driver from being a
platform_driverto an open firmware version. Error returns were improved. Routine names were changed fromfsl_tompc_to make them match the file name.
Quoted 7 lines
In discussions BenH and I have had, we've actually concluded that moving this from platform drivers to
of_platformdrives is not actually a good idea.In fact we're planning to move away from
of_platformdevices and drivers and instead develop a framework for instantiating platform devices or i2c devices or whatever devices from the device tree nodes.
Now that is interesting news. I like this idea.
But what should be done to support the still missing devices in the 4xx arch/powerpc tree, like I2C, NAND etc.? Should we wait with those driver till this framework is available?
Thanks.
Cheers,
Stefan
Re: [PATCH 4/5] Convert PowerPC MPC i2c to of_platform_driver from platform_driver
In reply to David GibsonQuoted 5 lines · David Gibson
Quoted 3 lines · Jon Smirl
Convert MPC i2c driver from being a
platform_driverto an open firmware version. Error returns were improved. Routine names were changed fromfsl_tompc_to make them match the file name.
Quoted 7 lines
In discussions BenH and I have had, we've actually concluded that moving this from platform drivers to
of_platformdrives is not actually a good idea.In fact we're planning to move away from
of_platformdevices and drivers and instead develop a framework for instantiating platform devices or i2c devices or whatever devices from the device tree nodes.
I have to work with what is in the kernel tree so this patch is based the current kernel. A lot of time and testing has going into all the revisions of this patch. It has been posted in various forms for the last month and a half.
As for platform vs of_platform, IMHO of_platform should have been derived from platform instead of being an unrelated structure. In the current scheme of unrelated structures it makes more sense to use one or the other and not mix them. I am in agreement with Olof that if and when a new scheme is adopted the drivers should be converted then.
In my local builds I have disabled platform and use only of_platform. An of_platform only system works fine and is capable of instantiating everything from the device tree as this patch illustrates. Once this patch goes in I'll post another series that shows how I went of_platform only on mpc5200.
Everyone seems to be focusing on a small piece of driver initialization code and ignoring the much more complicated part which implements dynamic i2c driver loading. It's the complicated part of the code that needs review.
Ben, I know we talked about not putting the alias names into their own namespace. But the i2c people don't want to move onto the standard kernel aliasing scheme for other platforms and asked for #ifdef powerpc. In version 15 I removed the cross platform support and made everything powerpc specific. .
Signature · 2 lines
Jon Smirl [email protected]
Re: [PATCH 4/5] Convert PowerPC MPC i2c to of_platform_driver from platform_driver
In reply to Jon SmirlHi Jon,
Quoted 1 line
Convert MPC i2c driver from being a
platform_driverto an open firmware version. Error returns were improved. Routine names were changed fromfsl_tompc_to make them match the file name
I did the same for my i2c-cpm. Tested with the frontprocessor driver (dbox2 specific) converted to new style. I'll post the new i2c-cpm, as well.
Quoted 35 lines
drivers/i2c/busses/i2c-mpc.c +35
-0+static void of_register_i2c_devices (struct i2c_adapter *adap,struct device_node *adap_node) +{ +struct device_node *node =NULL ; + +while ((node =of_get_next_child (adap_node, node))) { +struct i2c_board_info info; +const u32 *addr; +const char *compatible; +int len; + + addr =of_get_property (node,"reg" , &len); +if (!addr || len <sizeof (int ) || *addr > (1 <<10 ) -1 ) { +printk (KERN_ERR "i2c-mpc.c: invalid entry, missing reg attribute\n" ); +continue ; + } + + info.irq =irq_of_parse_and_map (node,0 ); +if (info.irq ==NO_IRQ ) + info.irq =-1 ; + + compatible =of_get_property (node,"compatible" , &len); +if (!compatible) { +printk (KERN_ERR "i2c-mpc.c: invalid entry, missing compatible attribute\n" ); +continue ; + } + +/* need full alias i2c:NOF,vendor,device */ +strcpy (info.driver_name,I2C_OF_MODULE_PREFIX ); +strncat (info.driver_name, compatible,sizeof (info.driver_name)); +request_module (info.driver_name); + +/* need module alias OF,vendor,device */ +strcpy (info.driver_name,OF_I2C_PREFIX ); +strncat (info.driver_name, compatible,sizeof (info.driver_name)); +
drivers/i2c/busses/i2c-mpc.c static struct i2c_adapter mpc_ops = { · line 371
Quoted 10 lines
drivers/i2c/busses/i2c-mpc.c +10
-0+ info.type[0 ] ='\0' ; + info.platform_data =NULL ; + info.addr = *addr; + +if (!i2c_new_device (adap, &info)) { +printk (KERN_ERR "i2c-mpc.c: Failed to load driver for %s\n" , info.driver_name); +continue ; + } + } +}
Should this go into some central file? Else we would have to copy it in any i2c bus driver that supports powerpc. This would at least be i2c-cpm and i2c-gpio.
Quoted 54 lines
drivers/i2c/busses/i2c-mpc.c +54
-0+static int mpc_i2c_probe (struct of_device *op,const struct of_device_id *match) +{ +int result =0 ; +struct mpc_i2c *i2c; + + i2c =kzalloc (sizeof (*i2c),GFP_KERNEL ); +if (!i2c) +return -ENOMEM ; + +if (of_get_property (op->node,"dfsrr" ,NULL )) + i2c->flags |=FSL_I2C_DEV_SEPARATE_DFSRR ; + +if (of_device_is_compatible (op->node,"mpc5200-i2c" )) + i2c->flags |=FSL_I2C_DEV_CLOCK_5200 ; + +init_waitqueue_head (&i2c->queue); + + i2c->base =of_iomap (op->node,0 ); +if (!i2c->base) { +printk (KERN_ERR "i2c-mpc - failed to map controller\n" ); + result = -ENOMEM ; + goto fail_map; + } + + i2c->irq =irq_of_parse_and_map (op->node,0 ); +if (i2c->irq ==NO_IRQ ) { + result = -ENXIO ; + goto fail_irq; + } + + result =request_irq (i2c->irq, mpc_i2c_isr,IRQF_SHARED ,"i2c-mpc" , i2c); +if (result <0 ) { +printk (KERN_ERR "i2c-mpc - failed to attach interrupt\n" ); + goto fail_request; + } + +mpc_i2c_setclock (i2c); + +dev_set_drvdata (&op->dev, i2c); + + i2c->adap = mpc_ops; +i2c_set_adapdata (&i2c->adap, i2c); + i2c->adap.dev.parent = &op->dev; + + result =i2c_add_adapter (&i2c->adap); +if (result <0 ) { +printk (KERN_ERR "i2c-mpc - failed to add adapter\n" ); + goto fail_add; + } + +of_register_i2c_devices (&i2c->adap, op->node); + +return result; +
drivers/i2c/busses/i2c-mpc.c static struct i2c_adapter mpc_ops = { · line 436
Quoted 10 lines
drivers/i2c/busses/i2c-mpc.c +10
-0+fail_add: +free_irq (i2c->irq, i2c); +fail_request: +irq_dispose_mapping (i2c->irq); +fail_irq: +iounmap (i2c->base); +fail_map: +kfree (i2c); +return result; +};
IMHO, there should be a node attribute to override i2c_adapter.class. Legacy i2c drivers (in particular v4l and dvb drivers) use this class to decide which adapter to bind to. dbox2 needs I2C_CLASS_TV_DIGITAL (4).
Thanks,
Jochen
Re: [PATCH 4/5] Convert PowerPC MPC i2c to of_platform_driver from platform_driver
Quoted 3 lines · Jochen Friedrich
Should this go into some central file? Else we would have to copy it in any i2c bus driver that supports powerpc. This would at least be i2c-cpm and i2c-gpio.
I can change that in the next rev. I'm waiting to see if there are any more changes.
Quoted 1 line
IMHO, there should be a node attribute to override i2c_adapter.class. Legacy i2c drivers (in particular v4l and dvb drivers) use this class to decide which adapter to bind to. dbox2 needs
I2C_CLASS_TV_DIGITAL(4).
I hadn't paid any attention to i2c_adapter.class. Now that you mention it I wonder why i2c has it. It appears to be a holdover from the older mechanism of searching for devices and it is used as a filter to reduce the number of device being searched. I would think a new style driver could just ignore it.
It is probably best to fix it in a successive patch.
Signature · 2 lines
Jon Smirl [email protected]
PATCH 5/5 Convert pfc8563 i2c driver from old style to new style
In reply to Jon SmirlConvert pfc8563 i2c driver from old style to new style. The driver is also modified to support device tree names via the i2c mod alias mechanism.
---
drivers/rtc/rtc-pcf8563.c | 107 +++++++++++---------------------------------- 1 files changed, 27 insertions(+), 80 deletions(-)
drivers/rtc/rtc-pcf8563.c +27 -80
@@ -25,10 +25,6 @@* located at 0x51 will pass the validation routine due to * the way the registers are implemented. */ -static unsigned short normal_i2c[] = {I2C_CLIENT_END }; - -/* Module parameters */ -I2C_CLIENT_INSMOD ;#define PCF8563_REG_ST1 0x00/* status */ #define PCF8563_REG_ST2 0x01
@@ -72,9 +68,6 @@ struct pcf8563 {int c_polarity;/* 0: MO_C=1 means 19xx, otherwise MO_C=1 means 20xx */ }; -static int pcf8563_probe (struct i2c_adapter *adapter,int address,int kind); -static int pcf8563_detach (struct i2c_client *client); -/* * In the routines that deal directly with the pcf8563 hardware, we use * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch.
@@ -257,98 +250,52 @@ static const struct rtc_class_ops pcf8563_rtc_ops = { .set_time = pcf8563_rtc_set_time, }; -static int pcf8563_attach (struct i2c_adapter *adapter) +static int pcf8563_remove (struct i2c_client *client) { -return i2c_probe (adapter, &addr_data, pcf8563_probe); +struct rtc_device *rtc =i2c_get_clientdata (client); + +if (rtc) +rtc_device_unregister (rtc); + +return 0 ; } +static struct i2c_device_id pcf8563_id[] = { + OF_I2C_ID("philips,pcf8563", 0) + OF_I2C_ID("epson,rtc8564", 0) + {}, +}; +MODULE_DEVICE_TABLE (i2c, pcf8563_id); + +static int pcf8563_probe (struct i2c_client *client,const struct i2c_device_id *id); +static struct i2c_driver pcf8563_driver = { .driver = { - .name ="pcf8563" , + .name ="rtc-pcf8563" , }, .id =I2C_DRIVERID_PCF8563 , - .attach_adapter = &pcf8563_attach, - .detach_client = &pcf8563_detach, + .probe = &pcf8563_probe, + .remove = &pcf8563_remove, + .id_table = pcf8563_id, }; -static int pcf8563_probe (struct i2c_adapter *adapter,int address,int kind) +static int pcf8563_probe (struct i2c_client *client,const struct i2c_device_id *id) { -struct pcf8563 *pcf8563; -struct i2c_client *client; +int result;struct rtc_device *rtc; -int err =0 ; - -dev_dbg (&adapter->dev,"%s\n" , __FUNCTION__); - -if (!i2c_check_functionality (adapter,I2C_FUNC_I2C )) { - err = -ENODEV ; - goto exit; - } - -if (!(pcf8563 =kzalloc (sizeof (struct pcf8563 ),GFP_KERNEL ))) { - err = -ENOMEM ; - goto exit; - } - - client = &pcf8563->client; - client->addr = address; - client->driver = &pcf8563_driver; - client->adapter = adapter; - -strlcpy (client->name, pcf8563_driver.driver.name,I2C_NAME_SIZE ); - -/* Verify the chip is really an PCF8563 */ -if (kind <0 ) { -if (pcf8563_validate_client (client) <0 ) { - err = -ENODEV ; - goto exit_kfree; - } - } - -/* Inform the i2c layer */ -if ((err =i2c_attach_client (client))) - goto exit_kfree; - -dev_info (&client->dev,"chip found, driver version " DRV_VERSION "\n" ); + result =pcf8563_validate_client (client); +if (result) +return result; rtc =rtc_device_register (pcf8563_driver.driver.name, &client->dev, &pcf8563_rtc_ops,THIS_MODULE ); - -if (IS_ERR (rtc)) { - err =PTR_ERR (rtc); - goto exit_detach; - } +if (IS_ERR (rtc)) +return PTR_ERR (rtc);i2c_set_clientdata (client, rtc);return 0 ; - -exit_detach: -i2c_detach_client (client); - -exit_kfree: -kfree (pcf8563); - -exit: -return err; -} - -static int pcf8563_detach (struct i2c_client *client) -{ - struct pcf8563 *pcf8563 = container_of(client, struct pcf8563, client); -int err; -struct rtc_device *rtc =i2c_get_clientdata (client); - -if (rtc) -rtc_device_unregister (rtc); - -if ((err =i2c_detach_client (client))) -return err; - -kfree (pcf8563); - -return 0 ; }static int __init pcf8563_init (void )
Are there any other objections to this patch? If not, can it be targeted for 2.6.25?
Quoted 17 lines · Jon Smirl
Since copying
i2c-mpc.cto maintain support for the ppc architecture seems to be an issue; instead reworki2c-mpc.cto useCONFIG_PPC_MERGE#ifdefs to support both the ppc and powerpc architecture. When ppc is deleted in six months these #ifdefs will need to be removed.Another rework of the i2c for powerpc device tree patch. This version implements standard alias naming only on the powerpc platform and only for the device tree names. The old naming mechanism of i2c_client.name,driver_name is left in place and not changed for non-powerpc platforms. This patch is fully capable of dynamically loading the i2c modules. You can modprobe in the i2c-mpc driver and the i2c modules described in the device tree will be automatically loaded. Modules also work if compiled in.
The follow on patch to module-init-tools is also needed since the i2c subsystem has never implemented dynamic loading.
The following series implements standard linux module aliasing for i2c modules on arch=powerpc. It then converts the mpc i2c driver from being a platform driver to an open firmware one. I2C device names are picked up from the device tree. Module aliasing is used to translate from device tree names into to linux kernel names. Several i2c drivers are updated to use the new aliasing.
--
Jon Smirl
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 2 lines
Jon Smirl [email protected]
Quoted 1 line · Jon Smirl
Another rework of the i2c for powerpc device tree patch. This version implements standard alias naming only on the powerpc platform and only for the device tree names. The old naming mechanism of i2c_client.name,driver_name is left in place and not changed for non-powerpc platforms. This patch is fully capable of dynamically loading the i2c modules. You can modprobe in the i2c-mpc driver and the i2c modules described in the device tree will be automatically loaded. Modules also work if compiled in.
Are there any further objections to this patch? Can it all go in through the powerpc trees or do the i2c people want to send it on?
Signature · 2 lines
Jon Smirl [email protected]
Hi John,
Le 27/12/2007, Jon Smirl écrit:
Quoted 5 lines · Jon Smirl
Quoted 1 line
Another rework of the i2c for powerpc device tree patch. This version implements standard alias naming only on the powerpc platform and only for the device tree names. The old naming mechanism of i2c_client.name,driver_name is left in place and not changed for non-powerpc platforms. This patch is fully capable of dynamically loading the i2c modules. You can modprobe in the i2c-mpc driver and the i2c modules described in the device tree will be automatically loaded. Modules also work if compiled in.
Are there any further objections to this patch? Can it all go in through the powerpc trees or do the i2c people want to send it on?
I am on vacation until January 4th. I will review your patchset the week following my return.
Thanks for your patience,
--
Jean Delvare
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
A message that is not in the archive (sent off-list or not yet received): 20071220044136.20091.70984.stgit-+J+k29bDNxlBDLzU/[email protected]
What is the review status of this series, should I post it again?
Quoted 17 lines · Jon Smirl
Since copying
i2c-mpc.cto maintain support for the ppc architecture seems to be an issue; instead reworki2c-mpc.cto useCONFIG_PPC_MERGE#ifdefs to support both the ppc and powerpc architecture. When ppc is deleted in six months these #ifdefs will need to be removed.Another rework of the i2c for powerpc device tree patch. This version implements standard alias naming only on the powerpc platform and only for the device tree names. The old naming mechanism of i2c_client.name,driver_name is left in place and not changed for non-powerpc platforms. This patch is fully capable of dynamically loading the i2c modules. You can modprobe in the i2c-mpc driver and the i2c modules described in the device tree will be automatically loaded. Modules also work if compiled in.
The follow on patch to module-init-tools is also needed since the i2c subsystem has never implemented dynamic loading.
The following series implements standard linux module aliasing for i2c modules on arch=powerpc. It then converts the mpc i2c driver from being a platform driver to an open firmware one. I2C device names are picked up from the device tree. Module aliasing is used to translate from device tree names into to linux kernel names. Several i2c drivers are updated to use the new aliasing.
--
Jon Smirl
[email protected]
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Signature · 2 lines
Jon Smirl [email protected]
A message that is not in the archive (sent off-list or not yet received): 9e4733910801100614y7522a573qb2af41a714b08d5-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org
Quoted 1 line · Jon Smirl
What is the review status of this series, should I post it again?
No please! /o\
I'll go through your numerous past posts now, stay tuned.
Signature · 1 line
Jean Delvare
Hi Jon,
Quoted 7 lines · Jon Smirl
Since copying
i2c-mpc.cto maintain support for the ppc architecture seems to be an issue; instead reworki2c-mpc.cto useCONFIG_PPC_MERGE#ifdefs to support both the ppc and powerpc architecture. When ppc is deleted in six months these #ifdefs will need to be removed.Another rework of the i2c for powerpc device tree patch. This version implements standard alias naming only on the powerpc platform and only for the device tree names. The old naming mechanism of i2c_client.name,driver_name is left in place and not changed for non-powerpc platforms. This patch is fully capable of dynamically loading the i2c modules. You can modprobe in the i2c-mpc driver and the i2c modules described in the device tree will be automatically loaded. Modules also work if compiled in.
The follow on patch to module-init-tools is also needed since the i2c subsystem has never implemented dynamic loading.
The following series implements standard linux module aliasing for i2c modules on arch=powerpc. It then converts the mpc i2c driver from being a platform driver to an open firmware one. I2C device names are picked up from the device tree. Module aliasing is used to translate from device tree names into to linux kernel names. Several i2c drivers are updated to use the new aliasing.
Now that I have read all the previous versions of this patch series and, more importantly, all objections that were raised on the way, I can start reviewing the latest iteration of your patches. I'll also do some testing, although I have no powerpc stuff here, but at least I want to make sure that there are no regressions introduced by your patches on x86.
Signature · 1 line
Jean Delvare
Quoted 9 lines · Jean Delvare
Hi Jon,
Quoted 6 lines · Jon Smirl
Since copying
i2c-mpc.cto maintain support for the ppc architecture seems to be an issue; instead reworki2c-mpc.cto useCONFIG_PPC_MERGE#ifdefs to support both the ppc and powerpc architecture. When ppc is deleted in six months these #ifdefs will need to be removed.Another rework of the i2c for powerpc device tree patch. This version implements standard alias naming only on the powerpc platform and only for the device tree names. The old naming mechanism of i2c_client.name,driver_name is left in place and not changed for non-powerpc platforms. This patch is fully capable of dynamically loading the i2c modules. You can modprobe in the i2c-mpc driver and the i2c modules described in the device tree will be automatically loaded. Modules also work if compiled in.
The follow on patch to module-init-tools is also needed since the i2c subsystem has never implemented dynamic loading.
Quoted 8 lines
Quoted 1 line
The following series implements standard linux module aliasing for i2c modules on arch=powerpc. It then converts the mpc i2c driver from being a platform driver to an open firmware one. I2C device names are picked up from the device tree. Module aliasing is used to translate from device tree names into to linux kernel names. Several i2c drivers are updated to use the new aliasing.
Now that I have read all the previous versions of this patch series and, more importantly, all objections that were raised on the way, I can start reviewing the latest iteration of your patches. I'll also do some testing, although I have no powerpc stuff here, but at least I want to make sure that there are no regressions introduced by your patches on x86.
Various people were worried about x86. Around version 15 I altered the patches so that they only impacted PowerPC. If they impact x86 in current form that is a bug.
When x86 is ready for it I do think dynamic module loading should be implemented there also.
Quoted 4 lines
--
Jean Delvare
Signature · 2 lines
Jon Smirl [email protected]
Hi Jon,
Quoted 9 lines
Quoted 8 lines
Quoted 1 line
The following series implements standard linux module aliasing for i2c modules on arch=powerpc. It then converts the mpc i2c driver from being a platform driver to an open firmware one. I2C device names are picked up from the device tree. Module aliasing is used to translate from device tree names into to linux kernel names. Several i2c drivers are updated to use the new aliasing.
Now that I have read all the previous versions of this patch series and, more importantly, all objections that were raised on the way, I can start reviewing the latest iteration of your patches. I'll also do some testing, although I have no powerpc stuff here, but at least I want to make sure that there are no regressions introduced by your patches on x86.
Quoted 3 lines
Various people were worried about x86. Around version 15 I altered the patches so that they only impacted PowerPC. If they impact x86 in current form that is a bug.
I can only second this. The latest version of i2c-cpm
(http://patchwork.ozlabs.org/linuxppc/patch?person=1023&id=15902) makes use of this patch, as well. On the dbox2, loading and unloading of modules in any order just works fine.
Thanks,
Jochen
Quoted 9 lines · Jon Smirl
Quoted 6 lines · Jean Delvare
Now that I have read all the previous versions of this patch series and, more importantly, all objections that were raised on the way, I can start reviewing the latest iteration of your patches. I'll also do some testing, although I have no powerpc stuff here, but at least I want to make sure that there are no regressions introduced by your patches on x86.
Quoted 6 lines
Various people were worried about x86. Around version 15 I altered the patches so that they only impacted PowerPC. If they impact x86 in current form that is a bug.
When x86 is ready for it I do think dynamic module loading should be implemented there also.
I agree, and I am doing some testing on x86 to make sure that your patch will work fine there as well once we decide to go that way.
Your patch set really contains two different parts which should be clearly identified and discussed separately. Firstly, it lets i2c drivers export module aliases so that the rest of the world knows which devices they support. This part I think everybody agrees is needed, so that platform code no longer needs to specify the driver name for every I2C device.
Secondly, it promotes OF device names as acceptable aliases. This I don't think I agree with. While I see some value in moving the OF name -> Linux name translation to the drivers themselves (even though I don't see this as a mandatory move either), this doesn't imply that OF names should be used as aliases. I don't like the idea that different architectures will name the same device differently in a visible way. This could easily break user-space code that makes assumptions on the device names (libsensors comes to mind.) So, I think that this part will need some more discussion.
Signature · 1 line
Jean Delvare
Quoted 9 lines · Jean Delvare
Secondly, it promotes OF device names as acceptable aliases. This I don't think I agree with. While I see some value in moving the OF name -> Linux name translation to the drivers themselves (even though I don't see this as a mandatory move either), this doesn't imply that OF names should be used as aliases. I don't like the idea that different architectures will name the same device differently in a visible way. This could easily break user-space code that makes assumptions on the device names (libsensors comes to mind.) So, I think that this part will need some more discussion.
They're aliases. On the x86 my e1000 Ethernet driver loads using this alias name:
"pci:v00008086d00001010sv*sd*bc*sc*i*"
In fact, the e1000 driver has 63 alias names in addition to "e1000"
But it's still the e1000 driver after it is loaded.
jonsmirl@terra:/home/linux/drivers/net/e1000$ lsmod | grep e1000 e1000 115968 0
Loading a I2C driver with an OF alias name is not going to change the module name after it is loaded. In fact, once the module is in memory there's no way to tell what name was used to load it.
OF device names are set by the Open Firmware committee. It is not reasonable to force the Linux names back into Open Firmware since this would force the other operating systems using Open Firmware to adopt the Linux names.
This issue hasn't been visible before since there was a global table in the PowerPC code mapping all known Open Firmware names into linux names. Keeping this as a global table doesn't scale. The mapping needs to be done by each device individually.
Quoted 4 lines
--
Jean Delvare
Signature · 2 lines
Jon Smirl [email protected]
Quoted 16 lines · Jon Smirl
Quoted 9 lines · Jean Delvare
Secondly, it promotes OF device names as acceptable aliases. This I don't think I agree with. While I see some value in moving the OF name -> Linux name translation to the drivers themselves (even though I don't see this as a mandatory move either), this doesn't imply that OF names should be used as aliases. I don't like the idea that different architectures will name the same device differently in a visible way. This could easily break user-space code that makes assumptions on the device names (libsensors comes to mind.) So, I think that this part will need some more discussion.
They're aliases. On the x86 my e1000 Ethernet driver loads using this alias name:
"pci:v00008086d00001010sv*sd*bc*sc*i*"
In fact, the e1000 driver has 63 alias names in addition to "e1000"
Quoted 7 lines
But it's still the e1000 driver after it is loaded.
jonsmirl@terra:/home/linux/drivers/net/e1000$ lsmod | grep e1000 e1000 115968 0Loading a I2C driver with an OF alias name is not going to change the module name after it is loaded. In fact, once the module is in memory there's no way to tell what name was used to load it.
Of course. That's not what I was worried about... what I was worried about is something your patch set doesn't do but I misread the code and I thought it was doing. I'll read it again before I make more comments on this.
Quoted 4 lines
OF device names are set by the Open Firmware committee. It is not reasonable to force the Linux names back into Open Firmware since this would force the other operating systems using Open Firmware to adopt the Linux names.
I never meant to force the Linux names into Open Firmware. It wouldn't make sense especially when the Linux names are invented by random contributors with no specific rules, and can even change over time.
What I meant is that the translation from Open Firmware device name to Linux device name could happen in different ways. Making module aliases out of the is one possibility but this is not the only one.
I am curious why the translation could not happen "offline". As I understand it, you're getting the device names from these .dts files. However you're not parsing them in the kernel directly, are you? I presume that you have some tool that converts these files into C code that the kernel can use? This conversion tool could translate the names.
Quoted 4 lines
This issue hasn't been visible before since there was a global table in the PowerPC code mapping all known Open Firmware names into linux names. Keeping this as a global table doesn't scale. The mapping needs to be done by each device individually.
Looking at your patch set, I see only 11 entries in the table (in arch/powerpc/sysdev/fsl_soc.c) that patch #2 deletes. Are there more in other files? I'm asking because 11 entries hardly qualifies as "doesn't scale". I sure hope that you're not doing all this for the sole purpose of getting rid of this 11-element table.
Signature · 1 line
Jean Delvare
Quoted 43 lines · Jean Delvare
Quoted 16 lines · Jon Smirl
Quoted 9 lines · Jean Delvare
Secondly, it promotes OF device names as acceptable aliases. This I don't think I agree with. While I see some value in moving the OF name -> Linux name translation to the drivers themselves (even though I don't see this as a mandatory move either), this doesn't imply that OF names should be used as aliases. I don't like the idea that different architectures will name the same device differently in a visible way. This could easily break user-space code that makes assumptions on the device names (libsensors comes to mind.) So, I think that this part will need some more discussion.
They're aliases. On the x86 my e1000 Ethernet driver loads using this alias name:
"pci:v00008086d00001010sv*sd*bc*sc*i*"
In fact, the e1000 driver has 63 alias names in addition to "e1000"Quoted 7 lines
But it's still the e1000 driver after it is loaded.
jonsmirl@terra:/home/linux/drivers/net/e1000$ lsmod | grep e1000 e1000 115968 0Loading a I2C driver with an OF alias name is not going to change the module name after it is loaded. In fact, once the module is in memory there's no way to tell what name was used to load it.
Of course. That's not what I was worried about... what I was worried about is something your patch set doesn't do but I misread the code and I thought it was doing. I'll read it again before I make more comments on this.
Quoted 4 lines
OF device names are set by the Open Firmware committee. It is not reasonable to force the Linux names back into Open Firmware since this would force the other operating systems using Open Firmware to adopt the Linux names.
I never meant to force the Linux names into Open Firmware. It wouldn't make sense especially when the Linux names are invented by random contributors with no specific rules, and can even change over time.
What I meant is that the translation from Open Firmware device name to Linux device name could happen in different ways. Making module aliases out of the is one possibility but this is not the only one.
Quoted 5 lines
I am curious why the translation could not happen "offline". As I understand it, you're getting the device names from these .dts files. However you're not parsing them in the kernel directly, are you? I presume that you have some tool that converts these files into C code that the kernel can use? This conversion tool could translate the names.
Those dts files are for embedded devices that were specifically developed for Linux. All of the PowerPC Macs in the world have a device tree in ROM that was developed by Apple following the Open Firmware standard. Same thing for Sun boxes, but I'm not working on those.
The kernel has an existing mechanism for handling translations like these, the alias scheme.
Quoted 10 lines
Quoted 4 lines
This issue hasn't been visible before since there was a global table in the PowerPC code mapping all known Open Firmware names into linux names. Keeping this as a global table doesn't scale. The mapping needs to be done by each device individually.
Looking at your patch set, I see only 11 entries in the table (in
arch/powerpc/sysdev/fsl_soc.c) that patch #2 deletes. Are there more in other files? I'm asking because 11 entries hardly qualifies as "doesn't scale". I sure hope that you're not doing all this for the sole purpose of getting rid of this 11-element table.
Currently developers add entries to the table in their private builds for the i2c devices they are using. Another way to avoid adding a table entry is to create a platform device in the platform code. But this support is being extended to audio codecs too. There are hundreds of audio codecs.
The whole purpose of this code is to dynamically load the correct i2c and audio drivers by reading the device tree instead of having static i2s/codec devices for every possible platform combination.
Signature · 2 lines
Jon Smirl [email protected]
Hi Jon,
Quoted 11 lines · Jon Smirl
Quoted 9 lines · Jean Delvare
What I meant is that the translation from Open Firmware device name to Linux device name could happen in different ways. Making module aliases out of the is one possibility but this is not the only one.
I am curious why the translation could not happen "offline". As I understand it, you're getting the device names from these .dts files. However you're not parsing them in the kernel directly, are you? I presume that you have some tool that converts these files into C code that the kernel can use? This conversion tool could translate the names.
Quoted 5 lines
Those dts files are for embedded devices that were specifically developed for Linux. All of the PowerPC Macs in the world have a device tree in ROM that was developed by Apple following the Open Firmware standard. Same thing for Sun boxes, but I'm not working on those.
OK. So basically we have to handle two different cases here, trees that come from the .dts files and trees that are read from ROMs, right? Does this mean that .dts files are compiled to some binary format to look like what is in the ROMs? Is there kernel code that parses this? Please explain how both types are handled by the kernel. I need to understand how this works before I can decide where the OF names -> Linux names translation can happen.
Quoted 2 lines
The kernel has an existing mechanism for handling translations like these, the alias scheme.
That we agree on. My concern here is that you want to replace the Linux names of i2c devices by OF names, without realizing that the Linux names have a use outside of the kernel. We can't just replace them like that, it would break some user-space applications. That's the reason why I believe that it would make more sense to translate from OF names to Linux names early in the process, so that the kernel, and thus user-space applications, always handle and see the Linux names, independently of the platform. I'm asking questions in order to figure out whether and how this could be achieved.
Quoted 9 lines
Currently developers add entries to the table in their private builds for the i2c devices they are using. Another way to avoid adding a table entry is to create a platform device in the platform code. But this support is being extended to audio codecs too. There are hundreds of audio codecs.
The whole purpose of this code is to dynamically load the correct i2c and audio drivers by reading the device tree instead of having static i2s/codec devices for every possible platform combination.
I2C driver autoloading is already implemented, and works. Just not the way you expected, but it works.
Replacing this mechanism with standard aliases is IMHO a good idea, it makes the code cleaner and also more similar to what the rest of the kernel does, which is always nice.
However, having a module aliasing mechanism for i2c drivers does NOT require that OF names are used. We could implement aliasing using Linux device names. Note that I have no problem with using OF names for aliasing, however it should not break applications that currently know the I2C devices by their Linux name.
Signature · 1 line
Jean Delvare