From 9a94241afcc9a481691a9c29b7460217925b59b8 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Wed, 11 Aug 2010 18:20:56 +0200 Subject: i2c: Add support for custom probe function The probe method used by i2c_new_probed_device() may not be suitable for all cases. Let the caller provide its own, optional probe function. Signed-off-by: Jean Delvare Acked-by: Mauro Carvalho Chehab --- drivers/media/video/bt8xx/bttv-i2c.c | 2 +- drivers/media/video/cx18/cx18-i2c.c | 3 ++- drivers/media/video/em28xx/em28xx-cards.c | 2 +- drivers/media/video/ivtv/ivtv-i2c.c | 9 +++++---- drivers/media/video/v4l2-common.c | 3 ++- 5 files changed, 11 insertions(+), 8 deletions(-) (limited to 'drivers/media') diff --git a/drivers/media/video/bt8xx/bttv-i2c.c b/drivers/media/video/bt8xx/bttv-i2c.c index 407fa61e4cda..685d6597ee79 100644 --- a/drivers/media/video/bt8xx/bttv-i2c.c +++ b/drivers/media/video/bt8xx/bttv-i2c.c @@ -411,7 +411,7 @@ void __devinit init_bttv_i2c_ir(struct bttv *btv) memset(&info, 0, sizeof(struct i2c_board_info)); strlcpy(info.type, "ir_video", I2C_NAME_SIZE); - i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list); + i2c_new_probed_device(&btv->c.i2c_adap, &info, addr_list, NULL); } } diff --git a/drivers/media/video/cx18/cx18-i2c.c b/drivers/media/video/cx18/cx18-i2c.c index 809f7d37129c..73ce90c2f577 100644 --- a/drivers/media/video/cx18/cx18-i2c.c +++ b/drivers/media/video/cx18/cx18-i2c.c @@ -117,7 +117,8 @@ static int cx18_i2c_new_ir(struct cx18 *cx, struct i2c_adapter *adap, u32 hw, break; } - return i2c_new_probed_device(adap, &info, addr_list) == NULL ? -1 : 0; + return i2c_new_probed_device(adap, &info, addr_list, NULL) == NULL ? + -1 : 0; } int cx18_i2c_register(struct cx18 *cx, unsigned idx) diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c index ffbe544e30f4..e7efb4bffabd 100644 --- a/drivers/media/video/em28xx/em28xx-cards.c +++ b/drivers/media/video/em28xx/em28xx-cards.c @@ -2385,7 +2385,7 @@ void em28xx_register_i2c_ir(struct em28xx *dev) if (dev->init_data.name) info.platform_data = &dev->init_data; - i2c_new_probed_device(&dev->i2c_adap, &info, addr_list); + i2c_new_probed_device(&dev->i2c_adap, &info, addr_list, NULL); } void em28xx_card_setup(struct em28xx *dev) diff --git a/drivers/media/video/ivtv/ivtv-i2c.c b/drivers/media/video/ivtv/ivtv-i2c.c index d391bbdb0b8a..a74fa099c565 100644 --- a/drivers/media/video/ivtv/ivtv-i2c.c +++ b/drivers/media/video/ivtv/ivtv-i2c.c @@ -183,8 +183,8 @@ static int ivtv_i2c_new_ir(struct ivtv *itv, u32 hw, const char *type, u8 addr) return -1; memset(&info, 0, sizeof(struct i2c_board_info)); strlcpy(info.type, type, I2C_NAME_SIZE); - return i2c_new_probed_device(adap, &info, addr_list) == NULL - ? -1 : 0; + return i2c_new_probed_device(adap, &info, addr_list, NULL) + == NULL ? -1 : 0; } /* Only allow one IR receiver to be registered per board */ @@ -221,7 +221,8 @@ static int ivtv_i2c_new_ir(struct ivtv *itv, u32 hw, const char *type, u8 addr) info.platform_data = init_data; strlcpy(info.type, type, I2C_NAME_SIZE); - return i2c_new_probed_device(adap, &info, addr_list) == NULL ? -1 : 0; + return i2c_new_probed_device(adap, &info, addr_list, NULL) == NULL ? + -1 : 0; } /* Instantiate the IR receiver device using probing -- undesirable */ @@ -249,7 +250,7 @@ struct i2c_client *ivtv_i2c_new_ir_legacy(struct ivtv *itv) memset(&info, 0, sizeof(struct i2c_board_info)); strlcpy(info.type, "ir_video", I2C_NAME_SIZE); - return i2c_new_probed_device(&itv->i2c_adap, &info, addr_list); + return i2c_new_probed_device(&itv->i2c_adap, &info, addr_list, NULL); } int ivtv_i2c_register(struct ivtv *itv, unsigned idx) diff --git a/drivers/media/video/v4l2-common.c b/drivers/media/video/v4l2-common.c index 3ce7c64e5789..8ee1179be926 100644 --- a/drivers/media/video/v4l2-common.c +++ b/drivers/media/video/v4l2-common.c @@ -381,7 +381,8 @@ struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev, /* Create the i2c client */ if (info->addr == 0 && probe_addrs) - client = i2c_new_probed_device(adapter, info, probe_addrs); + client = i2c_new_probed_device(adapter, info, probe_addrs, + NULL); else client = i2c_new_device(adapter, info); -- cgit v1.2.3-59-g8ed1b From d44f19d586b6113fb5db10e1a36457f0db3b01aa Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Wed, 11 Aug 2010 18:20:57 +0200 Subject: V4L/DVB: Use custom I2C probing function mechanism Now that i2c-core offers the possibility to provide custom probing function for I2C devices, let's make use of it. Signed-off-by: Jean Delvare Acked-by: Mauro Carvalho Chehab --- drivers/i2c/i2c-core.c | 7 +++++++ drivers/media/video/cx23885/cx23885-i2c.c | 15 ++++----------- drivers/media/video/cx88/cx88-i2c.c | 19 ++++--------------- include/linux/i2c.h | 3 +++ 4 files changed, 18 insertions(+), 26 deletions(-) (limited to 'drivers/media') diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index cf14ca063181..6e1c2f54d9cf 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -1461,6 +1461,13 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver) return err; } +int i2c_probe_func_quick_read(struct i2c_adapter *adap, unsigned short addr) +{ + return i2c_smbus_xfer(adap, addr, 0, I2C_SMBUS_READ, 0, + I2C_SMBUS_QUICK, NULL) >= 0; +} +EXPORT_SYMBOL_GPL(i2c_probe_func_quick_read); + struct i2c_client * i2c_new_probed_device(struct i2c_adapter *adap, struct i2c_board_info *info, diff --git a/drivers/media/video/cx23885/cx23885-i2c.c b/drivers/media/video/cx23885/cx23885-i2c.c index 1a391486e551..ed3d8f55029b 100644 --- a/drivers/media/video/cx23885/cx23885-i2c.c +++ b/drivers/media/video/cx23885/cx23885-i2c.c @@ -364,17 +364,10 @@ int cx23885_i2c_register(struct cx23885_i2c *bus) memset(&info, 0, sizeof(struct i2c_board_info)); strlcpy(info.type, "ir_video", I2C_NAME_SIZE); - /* - * We can't call i2c_new_probed_device() because it uses - * quick writes for probing and the IR receiver device only - * replies to reads. - */ - if (i2c_smbus_xfer(&bus->i2c_adap, addr_list[0], 0, - I2C_SMBUS_READ, 0, I2C_SMBUS_QUICK, - NULL) >= 0) { - info.addr = addr_list[0]; - i2c_new_device(&bus->i2c_adap, &info); - } + /* Use quick read command for probe, some IR chips don't + * support writes */ + i2c_new_probed_device(&bus->i2c_adap, &info, addr_list, + i2c_probe_func_quick_read); } return bus->i2c_rc; diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c index 375ad53f7961..82db555b22dd 100644 --- a/drivers/media/video/cx88/cx88-i2c.c +++ b/drivers/media/video/cx88/cx88-i2c.c @@ -193,24 +193,13 @@ void cx88_i2c_init_ir(struct cx88_core *core) 0x18, 0x6b, 0x71, I2C_CLIENT_END }; - const unsigned short *addrp; memset(&info, 0, sizeof(struct i2c_board_info)); strlcpy(info.type, "ir_video", I2C_NAME_SIZE); - /* - * We can't call i2c_new_probed_device() because it uses - * quick writes for probing and at least some R receiver - * devices only reply to reads. - */ - for (addrp = addr_list; *addrp != I2C_CLIENT_END; addrp++) { - if (i2c_smbus_xfer(&core->i2c_adap, *addrp, 0, - I2C_SMBUS_READ, 0, - I2C_SMBUS_QUICK, NULL) >= 0) { - info.addr = *addrp; - i2c_new_device(&core->i2c_adap, &info); - break; - } - } + /* Use quick read command for probe, some IR chips don't + * support writes */ + i2c_new_probed_device(&core->i2c_adap, &info, addr_list, + i2c_probe_func_quick_read); } } diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 59a9f3cdc0b5..c8627e453e97 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -294,6 +294,9 @@ i2c_new_probed_device(struct i2c_adapter *adap, unsigned short const *addr_list, int (*probe)(struct i2c_adapter *, unsigned short addr)); +/* Common custom probe functions */ +extern int i2c_probe_func_quick_read(struct i2c_adapter *, unsigned short addr); + /* For devices that use several addresses, use i2c_new_dummy() to make * client handles for the extra addresses. */ -- cgit v1.2.3-59-g8ed1b