Message ID | 20090527070850.GA11221@linux-sh.org (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
On Wed, 27 May 2009 16:08:50 +0900, Paul Mundt wrote: > Another day, another module-related failure due to the i2c interface > being used in code that optionally uses it: > > ERROR: "i2c_new_device" [drivers/media/video/soc_camera.ko] undefined! > ERROR: "i2c_get_adapter" [drivers/media/video/soc_camera.ko] undefined! > ERROR: "i2c_put_adapter" [drivers/media/video/soc_camera.ko] undefined! > ERROR: "i2c_unregister_device" [drivers/media/video/soc_camera.ko] undefined! > make[2]: *** [__modpost] Error 1 > make[1]: *** [modules] Error 2 > make: *** [sub-make] Error 2 > > In the interest of not continually inserting i2c ifdefs in to every > driver that supports an optional i2c interface, this provides a stubbed > set of interfaces for the CONFIG_I2C=n case. > > I've covered the obvious ones that cause the majority of the build > failures, anything more involved really ought to have its dependencies > fixed instead. Violent nack. Drivers which optionally use I2C are a minority. Designing them in such a way that a single #ifdef CONFIG_I2C will make them work can't be that hard, really. Not to mention that having a dozen stubs in i2c.h in the CONFIG_I2C=n case won't save you much work at the driver level anyway, because you certainly need to run different code paths depending on how the device is connected, and you also have to differentiate between the "I2C support is missing" case and the "I2C device registration failed" case, etc.
On Wed, May 27, 2009 at 09:18:31AM +0200, Jean Delvare wrote: > On Wed, 27 May 2009 16:08:50 +0900, Paul Mundt wrote: > > Another day, another module-related failure due to the i2c interface > > being used in code that optionally uses it: > > > > ERROR: "i2c_new_device" [drivers/media/video/soc_camera.ko] undefined! > > ERROR: "i2c_get_adapter" [drivers/media/video/soc_camera.ko] undefined! > > ERROR: "i2c_put_adapter" [drivers/media/video/soc_camera.ko] undefined! > > ERROR: "i2c_unregister_device" [drivers/media/video/soc_camera.ko] undefined! > > make[2]: *** [__modpost] Error 1 > > make[1]: *** [modules] Error 2 > > make: *** [sub-make] Error 2 > > > > In the interest of not continually inserting i2c ifdefs in to every > > driver that supports an optional i2c interface, this provides a stubbed > > set of interfaces for the CONFIG_I2C=n case. > > > > I've covered the obvious ones that cause the majority of the build > > failures, anything more involved really ought to have its dependencies > > fixed instead. > > Violent nack. Drivers which optionally use I2C are a minority. If they were a minority we wouldn't be hitting them on a weekly basis, and other busses already do similar things for similar reasons. You may not like it, but it's much less distasteful than littering random i2c ifdefs around every driver that chooses to have an optional i2c interface. If every multi-bus driver was forced to go through these sorts of hoops, the drivers would be even less readable than they already are today. -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Wed, May 27, 2009 at 09:18:31AM +0200, Jean Delvare wrote: > Violent nack. Drivers which optionally use I2C are a minority. It's extremely common for devices like the CODECs and PMICs used in embedded systems to have both I2C and SPI interfaces, selectable via a pin strap at power on. It's less common to have the SPI option for things like hardware monitoring chips found in PCs but for anything that might be I/O bound the high speed interface is a very common option. > Designing them in such a way that a single #ifdef CONFIG_I2C will make > them work can't be that hard, really. Not to mention that having a > dozen stubs in i2c.h in the CONFIG_I2C=n case won't save you much work > at the driver level anyway, because you certainly need to run different > code paths depending on how the device is connected, and you also have > to differentiate between the "I2C support is missing" case and the "I2C > device registration failed" case, etc. For the devices I've dealt with there's very little work at the driver level - the various interfaces that can be used each probe using the normal device model, set some register read/write operations and possibly some other things and then call into the bulk of the driver which has all the I/O abstracted away from it. The error handling is already an issue with the current situation since people are just silently building out the I2C support when I2C is not enabled. At the minute the main problem is with people not remembering to do the #ifdef (a lot of platforms really need I2C enabled to be useful so people never think to do the build without). -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
Hi Mark, On Wed, 27 May 2009 13:01:40 +0100, Mark Brown wrote: > On Wed, May 27, 2009 at 09:18:31AM +0200, Jean Delvare wrote: > > > Violent nack. Drivers which optionally use I2C are a minority. > > It's extremely common for devices like the CODECs and PMICs used in > embedded systems to have both I2C and SPI interfaces, selectable via a > pin strap at power on. It's less common to have the SPI option for > things like hardware monitoring chips found in PCs but for anything that > might be I/O bound the high speed interface is a very common option. Can you please point me at a couple of affected drivers? > > Designing them in such a way that a single #ifdef CONFIG_I2C will make > > them work can't be that hard, really. Not to mention that having a > > dozen stubs in i2c.h in the CONFIG_I2C=n case won't save you much work > > at the driver level anyway, because you certainly need to run different > > code paths depending on how the device is connected, and you also have > > to differentiate between the "I2C support is missing" case and the "I2C > > device registration failed" case, etc. > > For the devices I've dealt with there's very little work at the driver > level - the various interfaces that can be used each probe using the > normal device model, set some register read/write operations and > possibly some other things and then call into the bulk of the driver > which has all the I/O abstracted away from it. It might make sense to define stubs for the CONFIG_I2C=n case for a few of the i2c API functions, which are called from common driver parts, in particular i2c_add/del_driver(), and as a matter of fact we already do this for i2c_register_board_info(). But for lower-level functions, this sounds wrong. The lower-level functions will only ever be called in functions which should be completely discarded if I2C support is missing from the kernel, and I would not count on gcc to be smart enough to really discard all the code thanks to the i2c API being all stubs. Meaning you end up with drivers larger than they should be - which is no good for embedded systems. I would really expect all I2C-related code to be in one place of the driver (or even in a separate source file) and same for SPI-related code. Then surrounding one big block of code with an ifdef doesn't sound that difficult to read. > The error handling is already an issue with the current situation since > people are just silently building out the I2C support when I2C is not > enabled. At the minute the main problem is with people not remembering > to do the #ifdef (a lot of platforms really need I2C enabled to be > useful so people never think to do the build without). I can't think of a way to solve this, other than what you do today (build without I2C support from times to times and fix what needs to be.) At least today you have a link breakage that tells you a given driver needs to be reviewed for the CONFIG_I2C=n case. If we add stubs all around to workaround the link breakage, this means the review never happens, so the code might as well build and link but not work properly or at least not be optimal. I wouldn't call this progress. What could be done, OTOH, is to surround all the function declarations in <linux/i2c.h> with a simple #ifdef CONFIG_I2C, so that mistakes are caught earlier (build time instead of link time.)
On Tue, Jun 02, 2009 at 09:12:29AM +0200, Jean Delvare wrote: > On Wed, 27 May 2009 13:01:40 +0100, Mark Brown wrote: > > It's extremely common for devices like the CODECs and PMICs used in > > embedded systems to have both I2C and SPI interfaces, selectable via a > Can you please point me at a couple of affected drivers? Most of the Wolfson CODECs in sound/soc/codecs are affected (more than actually have the SPI code at the minute), probably a lot of the other CODECs there too. I'd expect most I2C devices in drivers/mfd will also be affectd. For anything with more than a few registers the tendency is to have both options unless there's a hardware constraint. > I would really expect all I2C-related code to be in one place of the > driver (or even in a separate source file) and same for SPI-related > code. Then surrounding one big block of code with an ifdef doesn't > sound that difficult to read. It's not a legibility issue, it's to do with people remembering to handle all the cases. It's a bit of a PITA but not the end of the world - I'm mentioning this more because you were suggesting that a driver that was still useful with I2C=n was unusual rather than anything else. > driver needs to be reviewed for the CONFIG_I2C=n case. If we add stubs > all around to workaround the link breakage, this means the review never > happens, so the code might as well build and link but not work properly > or at least not be optimal. I wouldn't call this progress. I can't really see a situation where things wouldn't work properly beyond the current situation where I2C support can just be built out - if nobody is running the code then that's a separate issue. > What could be done, OTOH, is to surround all the function declarations > in <linux/i2c.h> with a simple #ifdef CONFIG_I2C, so that mistakes are > caught earlier (build time instead of link time.) That'd be helpful, yes. -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/include/linux/i2c.h b/include/linux/i2c.h index ad25805..ba73cd0 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -277,6 +277,8 @@ struct i2c_board_info { .type = dev_type, .addr = (dev_addr) +#ifdef CONFIG_I2C + /* Add-on boards should register/unregister their devices; e.g. a board * with integrated I2C, a config eeprom, sensors, and a codec that's * used in conjunction with the primary hardware. @@ -301,6 +303,33 @@ i2c_new_dummy(struct i2c_adapter *adap, u16 address); extern void i2c_unregister_device(struct i2c_client *); +#else + +static inline struct i2c_client * +i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info) +{ + return NULL; +} + +static inline struct i2c_client * +i2c_new_probed_device(struct i2c_adapter *adap, + struct i2c_board_info *info, + unsigned short const *addr_list) +{ + return NULL; +} + +static inline struct i2c_client * +i2c_new_dummy(struct i2c_adapter *adap, u16 address) +{ + return NULL; +} + +static inline void i2c_unregister_device(struct i2c_client *client) +{ +} +#endif /* CONFIG_I2C */ + /* Mainboard arch_initcall() code should register all its I2C devices. * This is done at arch_initcall time, before declaring any i2c adapters. * Modules for add-on boards must use other calls. @@ -415,6 +444,7 @@ struct i2c_client_address_data { /* ----- functions exported by i2c.o */ +#ifdef CONFIG_I2C /* administration... */ extern int i2c_add_adapter(struct i2c_adapter *); @@ -460,6 +490,85 @@ static inline u32 i2c_get_functionality(struct i2c_adapter *adap) return adap->algo->functionality(adap); } +#else + +static inline int i2c_add_adapter(struct i2c_adapter *adap) +{ + return -ENODEV; +} + +static inline int i2c_del_adapter(struct i2c_adapter *adap) +{ + return -ENODEV; +} + +static inline int i2c_add_numbered_adapter(struct i2c_adapter *adap) +{ + return -ENODEV; +} + +static inline int i2c_register_driver(struct module *module, + struct i2c_driver *driver) +{ + return -ENODEV; +} + +static inline void i2c_del_driver(struct i2c_driver *driver) +{ +} + +static inline int i2c_add_driver(struct i2c_driver *driver) +{ + return -ENODEV; +} + +static inline int __deprecated i2c_attach_client(struct i2c_client *client) +{ + return -EINVAL; +} + +static inline int __deprecated i2c_detach_client(struct i2c_client *client) +{ + return -EINVAL; +} + +static inline struct i2c_client *i2c_use_client(struct i2c_client *client) +{ + return NULL; +} + +static inline void i2c_release_client(struct i2c_client *client) +{ +} + +static inline void i2c_clients_command(struct i2c_adapter *adap, + unsigned int cmd, void *arg) +{ +} + +static inline int i2c_probe(struct i2c_adapter *adapter, + const struct i2c_client_address_data *address_data, + int (*found_proc) (struct i2c_adapter *, int, int)) +{ + return -ENODEV; +} + +static inline struct i2c_adapter *i2c_get_adapter(int id) +{ + return NULL; +} + +static inline void i2c_put_adapter(struct i2c_adapter *adap) +{ +} + +/* Return the functionality mask */ +static inline u32 i2c_get_functionality(struct i2c_adapter *adap) +{ + return 0; +} +#endif /* CONFIG_I2C */ + /* Return 1 if adapter supports everything we need, 0 if not. */ static inline int i2c_check_functionality(struct i2c_adapter *adap, u32 func) {
Another day, another module-related failure due to the i2c interface being used in code that optionally uses it: ERROR: "i2c_new_device" [drivers/media/video/soc_camera.ko] undefined! ERROR: "i2c_get_adapter" [drivers/media/video/soc_camera.ko] undefined! ERROR: "i2c_put_adapter" [drivers/media/video/soc_camera.ko] undefined! ERROR: "i2c_unregister_device" [drivers/media/video/soc_camera.ko] undefined! make[2]: *** [__modpost] Error 1 make[1]: *** [modules] Error 2 make: *** [sub-make] Error 2 In the interest of not continually inserting i2c ifdefs in to every driver that supports an optional i2c interface, this provides a stubbed set of interfaces for the CONFIG_I2C=n case. I've covered the obvious ones that cause the majority of the build failures, anything more involved really ought to have its dependencies fixed instead. Signed-off-by: Paul Mundt <lethal@linux-sh.org> --- include/linux/i2c.h | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html