]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
i2c: Add support for custom probe function
authorJean Delvare <khali@linux-fr.org>
Wed, 11 Aug 2010 16:20:56 +0000 (18:20 +0200)
committerJean Delvare <khali@linux-fr.org>
Wed, 11 Aug 2010 16:20:56 +0000 (18:20 +0200)
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 <khali@linux-fr.org>
Acked-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Documentation/i2c/instantiating-devices
drivers/i2c/i2c-core.c
drivers/macintosh/therm_windtunnel.c
drivers/media/video/bt8xx/bttv-i2c.c
drivers/media/video/cx18/cx18-i2c.c
drivers/media/video/em28xx/em28xx-cards.c
drivers/media/video/ivtv/ivtv-i2c.c
drivers/media/video/v4l2-common.c
drivers/usb/host/ohci-pnx4008.c
drivers/video/matrox/i2c-matroxfb.c
include/linux/i2c.h

index e89490270abad1ece6f8003b16ac815490f8de17..87da405a85979d9cf925fc711590f5d0deef9b7c 100644 (file)
@@ -102,7 +102,7 @@ static int __devinit usb_hcd_pnx4008_probe(struct platform_device *pdev)
        memset(&i2c_info, 0, sizeof(struct i2c_board_info));
        strlcpy(i2c_info.name, "isp1301_pnx", I2C_NAME_SIZE);
        isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info,
-                                                  normal_i2c);
+                                                  normal_i2c, NULL);
        i2c_put_adapter(i2c_adap);
        (...)
 }
index df937df845ebf3b50b3941c9aea569ef3bb7f22b..cf14ca063181b0abdb55fe8d33dd863edc8d4d48 100644 (file)
@@ -1464,14 +1464,18 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
 struct i2c_client *
 i2c_new_probed_device(struct i2c_adapter *adap,
                      struct i2c_board_info *info,
-                     unsigned short const *addr_list)
+                     unsigned short const *addr_list,
+                     int (*probe)(struct i2c_adapter *, unsigned short addr))
 {
        int i;
 
-       /* Stop here if the bus doesn't support probing */
-       if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE)) {
-               dev_err(&adap->dev, "Probing not supported\n");
-               return NULL;
+       if (!probe) {
+               /* Stop here if the bus doesn't support probing */
+               if (!i2c_check_functionality(adap, I2C_FUNC_SMBUS_READ_BYTE)) {
+                       dev_err(&adap->dev, "Probing not supported\n");
+                       return NULL;
+               }
+               probe = i2c_default_probe;
        }
 
        for (i = 0; addr_list[i] != I2C_CLIENT_END; i++) {
@@ -1490,7 +1494,7 @@ i2c_new_probed_device(struct i2c_adapter *adap,
                }
 
                /* Test address responsiveness */
-               if (i2c_default_probe(adap, addr_list[i]))
+               if (probe(adap, addr_list[i]))
                        break;
        }
 
index 5c9367acf0cf2c6a3411fe691f12540caab7ffd7..7d1bfeb6a82c42d6393d3bd20643b8609b3914d6 100644 (file)
@@ -322,10 +322,10 @@ do_attach( struct i2c_adapter *adapter )
 
                memset(&info, 0, sizeof(struct i2c_board_info));
                strlcpy(info.type, "therm_ds1775", I2C_NAME_SIZE);
-               i2c_new_probed_device(adapter, &info, scan_ds1775);
+               i2c_new_probed_device(adapter, &info, scan_ds1775, NULL);
 
                strlcpy(info.type, "therm_adm1030", I2C_NAME_SIZE);
-               i2c_new_probed_device(adapter, &info, scan_adm1030);
+               i2c_new_probed_device(adapter, &info, scan_adm1030, NULL);
 
                if( x.thermostat && x.fan ) {
                        x.running = 1;
index 407fa61e4cdab12269358063b562157b1c6c0a31..685d6597ee796ce5f59b12ed7a25e95933499330 100644 (file)
@@ -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);
        }
 }
 
index 809f7d37129c9b475d9cc15c46e7b1fb12e24750..73ce90c2f57757f6b0da6ee166cf21783d014cd2 100644 (file)
@@ -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)
index ffbe544e30f4cc868b213ab2e614eca48b933280..e7efb4bffabdeaeea65d270ec1d63bef84695e9f 100644 (file)
@@ -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)
index d391bbdb0b8a600f729c5efcd36aa4d8196ebeae..a74fa099c56536c0939df5cb4a41e0595ce01b00 100644 (file)
@@ -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)
index 3ce7c64e57897aec0fbe81f911d742604d95872d..8ee1179be926ed16d8199e7573ad65c8adb49c23 100644 (file)
@@ -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);
 
index cd74bbdd007cef3e218dc649361e2e516c47f454..653d6a60edb54e9e748b9e11e18a22192c8e3900 100644 (file)
@@ -329,7 +329,7 @@ static int __devinit usb_hcd_pnx4008_probe(struct platform_device *pdev)
        memset(&i2c_info, 0, sizeof(struct i2c_board_info));
        strlcpy(i2c_info.type, "isp1301_pnx", I2C_NAME_SIZE);
        isp1301_i2c_client = i2c_new_probed_device(i2c_adap, &i2c_info,
-                                                  normal_i2c);
+                                                  normal_i2c, NULL);
        i2c_put_adapter(i2c_adap);
        if (!isp1301_i2c_client) {
                err("failed to connect I2C to ISP1301 USB Transceiver");
index 403b14445a7830c7c29744acb8e92d6c9eb3ab2f..0fb280ead3dc1d76428cff3ace0b71f2cbf68802 100644 (file)
@@ -191,7 +191,7 @@ static void* i2c_matroxfb_probe(struct matrox_fb_info* minfo) {
                        };
 
                        i2c_new_probed_device(&m2info->maven.adapter,
-                                             &maven_info, addr_list);
+                                             &maven_info, addr_list, NULL);
                }
        }
        return m2info;
index 38dd4025aa4e47b9da99570e7f60ea72003ba600..59a9f3cdc0b5eabee5f4846589b9cc9b68e035b7 100644 (file)
@@ -284,12 +284,15 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info);
 
 /* If you don't know the exact address of an I2C device, use this variant
  * instead, which can probe for device presence in a list of possible
- * addresses.
+ * addresses. The "probe" callback function is optional. If it is provided,
+ * it must return 1 on successful probe, 0 otherwise. If it is not provided,
+ * a default probing method is used.
  */
 extern struct i2c_client *
 i2c_new_probed_device(struct i2c_adapter *adap,
                      struct i2c_board_info *info,
-                     unsigned short const *addr_list);
+                     unsigned short const *addr_list,
+                     int (*probe)(struct i2c_adapter *, unsigned short addr));
 
 /* For devices that use several addresses, use i2c_new_dummy() to make
  * client handles for the extra addresses.