Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

i2c: Add support for device alias names

Based on earlier work by Jon Smirl and Jochen Friedrich.

This patch allows new-style i2c chip drivers to have alias names using
the official kernel aliasing system and MODULE_DEVICE_TABLE(). At this
point, the old i2c driver binding scheme (driver_name/type) is still
supported.

Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Jochen Friedrich <jochen@scram.de>
Cc: Jon Smirl <jonsmirl@gmail.com>
Cc: Kay Sievers <kay.sievers@vrfy.org>

authored by

Jean Delvare and committed by
Jean Delvare
d2653e92 ee56d977

+146 -54
+2 -1
Documentation/i2c/writing-clients
··· 164 164 kind of driver in Linux: they provide a probe() method to bind to 165 165 those devices, and a remove() method to unbind. 166 166 167 - static int foo_probe(struct i2c_client *client); 167 + static int foo_probe(struct i2c_client *client, 168 + const struct i2c_device_id *id); 168 169 static int foo_remove(struct i2c_client *client); 169 170 170 171 Remember that the i2c_driver does not create those client handles. The
+2 -1
drivers/gpio/pca953x.c
··· 192 192 gc->owner = THIS_MODULE; 193 193 } 194 194 195 - static int __devinit pca953x_probe(struct i2c_client *client) 195 + static int __devinit pca953x_probe(struct i2c_client *client, 196 + const struct i2c_device_id *did) 196 197 { 197 198 struct pca953x_platform_data *pdata; 198 199 struct pca953x_chip *chip;
+2 -1
drivers/gpio/pcf857x.c
··· 142 142 143 143 /*-------------------------------------------------------------------------*/ 144 144 145 - static int pcf857x_probe(struct i2c_client *client) 145 + static int pcf857x_probe(struct i2c_client *client, 146 + const struct i2c_device_id *id) 146 147 { 147 148 struct pcf857x_platform_data *pdata; 148 149 struct pcf857x *gpio;
+5 -3
drivers/hwmon/f75375s.c
··· 117 117 static int f75375_attach_adapter(struct i2c_adapter *adapter); 118 118 static int f75375_detect(struct i2c_adapter *adapter, int address, int kind); 119 119 static int f75375_detach_client(struct i2c_client *client); 120 - static int f75375_probe(struct i2c_client *client); 120 + static int f75375_probe(struct i2c_client *client, 121 + const struct i2c_device_id *id); 121 122 static int f75375_remove(struct i2c_client *client); 122 123 123 124 static struct i2c_driver f75375_legacy_driver = { ··· 629 628 630 629 } 631 630 632 - static int f75375_probe(struct i2c_client *client) 631 + static int f75375_probe(struct i2c_client *client, 632 + const struct i2c_device_id *id) 633 633 { 634 634 struct f75375_data *data = i2c_get_clientdata(client); 635 635 struct f75375s_platform_data *f75375s_pdata = client->dev.platform_data; ··· 750 748 if ((err = i2c_attach_client(client))) 751 749 goto exit_free; 752 750 753 - if ((err = f75375_probe(client)) < 0) 751 + if ((err = f75375_probe(client, NULL)) < 0) 754 752 goto exit_detach; 755 753 756 754 return 0;
+2 -1
drivers/i2c/chips/ds1682.c
··· 200 200 /* 201 201 * Called when a ds1682 device is matched with this driver 202 202 */ 203 - static int ds1682_probe(struct i2c_client *client) 203 + static int ds1682_probe(struct i2c_client *client, 204 + const struct i2c_device_id *id) 204 205 { 205 206 int rc; 206 207
+2 -1
drivers/i2c/chips/menelaus.c
··· 1149 1149 1150 1150 static struct i2c_driver menelaus_i2c_driver; 1151 1151 1152 - static int menelaus_probe(struct i2c_client *client) 1152 + static int menelaus_probe(struct i2c_client *client, 1153 + const struct i2c_device_id *id) 1153 1154 { 1154 1155 struct menelaus_chip *menelaus; 1155 1156 int rev = 0, val;
+2 -1
drivers/i2c/chips/tps65010.c
··· 532 532 return 0; 533 533 } 534 534 535 - static int tps65010_probe(struct i2c_client *client) 535 + static int tps65010_probe(struct i2c_client *client, 536 + const struct i2c_device_id *id) 536 537 { 537 538 struct tps65010 *tps; 538 539 int status;
+2 -1
drivers/i2c/chips/tsl2550.c
··· 364 364 */ 365 365 366 366 static struct i2c_driver tsl2550_driver; 367 - static int __devinit tsl2550_probe(struct i2c_client *client) 367 + static int __devinit tsl2550_probe(struct i2c_client *client, 368 + const struct i2c_device_id *id) 368 369 { 369 370 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); 370 371 struct tsl2550_data *data;
+42 -9
drivers/i2c/i2c-core.c
··· 48 48 49 49 /* ------------------------------------------------------------------------- */ 50 50 51 + static const struct i2c_device_id *i2c_match_id(const struct i2c_device_id *id, 52 + const struct i2c_client *client) 53 + { 54 + while (id->name[0]) { 55 + if (strcmp(client->name, id->name) == 0) 56 + return id; 57 + id++; 58 + } 59 + return NULL; 60 + } 61 + 51 62 static int i2c_device_match(struct device *dev, struct device_driver *drv) 52 63 { 53 64 struct i2c_client *client = to_i2c_client(dev); ··· 69 58 */ 70 59 if (!is_newstyle_driver(driver)) 71 60 return 0; 61 + 62 + /* match on an id table if there is one */ 63 + if (driver->id_table) 64 + return i2c_match_id(driver->id_table, client) != NULL; 72 65 73 66 /* new style drivers use the same kind of driver matching policy 74 67 * as platform devices or SPI: compare device and driver IDs. ··· 88 73 struct i2c_client *client = to_i2c_client(dev); 89 74 90 75 /* by definition, legacy drivers can't hotplug */ 91 - if (dev->driver || !client->driver_name) 76 + if (dev->driver) 92 77 return 0; 93 78 94 - if (add_uevent_var(env, "MODALIAS=%s", client->driver_name)) 95 - return -ENOMEM; 79 + if (client->driver_name[0]) { 80 + if (add_uevent_var(env, "MODALIAS=%s", client->driver_name)) 81 + return -ENOMEM; 82 + } else { 83 + if (add_uevent_var(env, "MODALIAS=%s%s", 84 + I2C_MODULE_PREFIX, client->name)) 85 + return -ENOMEM; 86 + } 96 87 dev_dbg(dev, "uevent\n"); 97 88 return 0; 98 89 } ··· 111 90 { 112 91 struct i2c_client *client = to_i2c_client(dev); 113 92 struct i2c_driver *driver = to_i2c_driver(dev->driver); 93 + const struct i2c_device_id *id; 114 94 int status; 115 95 116 96 if (!driver->probe) 117 97 return -ENODEV; 118 98 client->driver = driver; 119 99 dev_dbg(dev, "probe\n"); 120 - status = driver->probe(client); 100 + 101 + if (driver->id_table) 102 + id = i2c_match_id(driver->id_table, client); 103 + else 104 + id = NULL; 105 + status = driver->probe(client, id); 121 106 if (status) 122 107 client->driver = NULL; 123 108 return status; ··· 206 179 static ssize_t show_modalias(struct device *dev, struct device_attribute *attr, char *buf) 207 180 { 208 181 struct i2c_client *client = to_i2c_client(dev); 209 - return client->driver_name 182 + return client->driver_name[0] 210 183 ? sprintf(buf, "%s\n", client->driver_name) 211 - : 0; 184 + : sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name); 212 185 } 213 186 214 187 static struct device_attribute i2c_dev_attrs[] = { ··· 327 300 EXPORT_SYMBOL_GPL(i2c_unregister_device); 328 301 329 302 330 - static int dummy_nop(struct i2c_client *client) 303 + static int dummy_probe(struct i2c_client *client, 304 + const struct i2c_device_id *id) 305 + { 306 + return 0; 307 + } 308 + 309 + static int dummy_remove(struct i2c_client *client) 331 310 { 332 311 return 0; 333 312 } 334 313 335 314 static struct i2c_driver dummy_driver = { 336 315 .driver.name = "dummy", 337 - .probe = dummy_nop, 338 - .remove = dummy_nop, 316 + .probe = dummy_probe, 317 + .remove = dummy_remove, 339 318 }; 340 319 341 320 /**
+2 -1
drivers/media/video/cs5345.c
··· 142 142 143 143 /* ----------------------------------------------------------------------- */ 144 144 145 - static int cs5345_probe(struct i2c_client *client) 145 + static int cs5345_probe(struct i2c_client *client, 146 + const struct i2c_device_id *id) 146 147 { 147 148 /* Check if the adapter supports the needed features */ 148 149 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
+2 -1
drivers/media/video/cs53l32a.c
··· 135 135 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' 136 136 */ 137 137 138 - static int cs53l32a_probe(struct i2c_client *client) 138 + static int cs53l32a_probe(struct i2c_client *client, 139 + const struct i2c_device_id *id) 139 140 { 140 141 int i; 141 142
+2 -1
drivers/media/video/cx25840/cx25840-core.c
··· 1209 1209 1210 1210 /* ----------------------------------------------------------------------- */ 1211 1211 1212 - static int cx25840_probe(struct i2c_client *client) 1212 + static int cx25840_probe(struct i2c_client *client, 1213 + const struct i2c_device_id *did) 1213 1214 { 1214 1215 struct cx25840_state *state; 1215 1216 u32 id;
+2 -1
drivers/media/video/m52790.c
··· 126 126 127 127 /* i2c implementation */ 128 128 129 - static int m52790_probe(struct i2c_client *client) 129 + static int m52790_probe(struct i2c_client *client, 130 + const struct i2c_device_id *id) 130 131 { 131 132 struct m52790_state *state; 132 133
+1 -1
drivers/media/video/msp3400-driver.c
··· 805 805 806 806 /* ----------------------------------------------------------------------- */ 807 807 808 - static int msp_probe(struct i2c_client *client) 808 + static int msp_probe(struct i2c_client *client, const struct i2c_device_id *id) 809 809 { 810 810 struct msp_state *state; 811 811 int (*thread_func)(void *data) = NULL;
+2 -1
drivers/media/video/mt9m001.c
··· 620 620 soc_camera_video_stop(&mt9m001->icd); 621 621 } 622 622 623 - static int mt9m001_probe(struct i2c_client *client) 623 + static int mt9m001_probe(struct i2c_client *client, 624 + const struct i2c_device_id *did) 624 625 { 625 626 struct mt9m001 *mt9m001; 626 627 struct soc_camera_device *icd;
+2 -1
drivers/media/video/mt9v022.c
··· 745 745 soc_camera_video_stop(&mt9v022->icd); 746 746 } 747 747 748 - static int mt9v022_probe(struct i2c_client *client) 748 + static int mt9v022_probe(struct i2c_client *client, 749 + const struct i2c_device_id *did) 749 750 { 750 751 struct mt9v022 *mt9v022; 751 752 struct soc_camera_device *icd;
+2 -1
drivers/media/video/saa7115.c
··· 1450 1450 1451 1451 /* ----------------------------------------------------------------------- */ 1452 1452 1453 - static int saa7115_probe(struct i2c_client *client) 1453 + static int saa7115_probe(struct i2c_client *client, 1454 + const struct i2c_device_id *id) 1454 1455 { 1455 1456 struct saa711x_state *state; 1456 1457 int i;
+2 -1
drivers/media/video/saa7127.c
··· 661 661 662 662 /* ----------------------------------------------------------------------- */ 663 663 664 - static int saa7127_probe(struct i2c_client *client) 664 + static int saa7127_probe(struct i2c_client *client, 665 + const struct i2c_device_id *id) 665 666 { 666 667 struct saa7127_state *state; 667 668 struct v4l2_sliced_vbi_data vbi = { 0, 0, 0, 0 }; /* set to disabled */
+2 -1
drivers/media/video/saa717x.c
··· 1418 1418 /* i2c implementation */ 1419 1419 1420 1420 /* ----------------------------------------------------------------------- */ 1421 - static int saa717x_probe(struct i2c_client *client) 1421 + static int saa717x_probe(struct i2c_client *client, 1422 + const struct i2c_device_id *did) 1422 1423 { 1423 1424 struct saa717x_state *decoder; 1424 1425 u8 id = 0;
+2 -1
drivers/media/video/tcm825x.c
··· 840 840 }, 841 841 }; 842 842 843 - static int tcm825x_probe(struct i2c_client *client) 843 + static int tcm825x_probe(struct i2c_client *client, 844 + const struct i2c_device_id *did) 844 845 { 845 846 struct tcm825x_sensor *sensor = &tcm825x; 846 847 int rval;
+2 -1
drivers/media/video/tlv320aic23b.c
··· 125 125 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' 126 126 */ 127 127 128 - static int tlv320aic23b_probe(struct i2c_client *client) 128 + static int tlv320aic23b_probe(struct i2c_client *client, 129 + const struct i2c_device_id *id) 129 130 { 130 131 struct tlv320aic23b_state *state; 131 132
+2 -1
drivers/media/video/tuner-core.c
··· 1073 1073 /* During client attach, set_type is called by adapter's attach_inform callback. 1074 1074 set_type must then be completed by tuner_probe. 1075 1075 */ 1076 - static int tuner_probe(struct i2c_client *client) 1076 + static int tuner_probe(struct i2c_client *client, 1077 + const struct i2c_device_id *id) 1077 1078 { 1078 1079 struct tuner *t; 1079 1080 struct tuner *radio;
+1 -1
drivers/media/video/tvaudio.c
··· 1461 1461 /* ---------------------------------------------------------------------- */ 1462 1462 /* i2c registration */ 1463 1463 1464 - static int chip_probe(struct i2c_client *client) 1464 + static int chip_probe(struct i2c_client *client, const struct i2c_device_id *id) 1465 1465 { 1466 1466 struct CHIPSTATE *chip; 1467 1467 struct CHIPDESC *desc;
+2 -1
drivers/media/video/upd64031a.c
··· 195 195 196 196 /* i2c implementation */ 197 197 198 - static int upd64031a_probe(struct i2c_client *client) 198 + static int upd64031a_probe(struct i2c_client *client, 199 + const struct i2c_device_id *id) 199 200 { 200 201 struct upd64031a_state *state; 201 202 int i;
+2 -1
drivers/media/video/upd64083.c
··· 172 172 173 173 /* i2c implementation */ 174 174 175 - static int upd64083_probe(struct i2c_client *client) 175 + static int upd64083_probe(struct i2c_client *client, 176 + const struct i2c_device_id *id) 176 177 { 177 178 struct upd64083_state *state; 178 179 int i;
+3 -2
drivers/media/video/v4l2-common.c
··· 710 710 /* Helper function for I2C legacy drivers */ 711 711 712 712 int v4l2_i2c_attach(struct i2c_adapter *adapter, int address, struct i2c_driver *driver, 713 - const char *name, int (*probe)(struct i2c_client *)) 713 + const char *name, 714 + int (*probe)(struct i2c_client *, const struct i2c_device_id *)) 714 715 { 715 716 struct i2c_client *client; 716 717 int err; ··· 725 724 client->driver = driver; 726 725 strlcpy(client->name, name, sizeof(client->name)); 727 726 728 - err = probe(client); 727 + err = probe(client, NULL); 729 728 if (err == 0) { 730 729 i2c_attach_client(client); 731 730 } else {
+2 -1
drivers/media/video/vp27smpx.c
··· 121 121 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' 122 122 */ 123 123 124 - static int vp27smpx_probe(struct i2c_client *client) 124 + static int vp27smpx_probe(struct i2c_client *client, 125 + const struct i2c_device_id *id) 125 126 { 126 127 struct vp27smpx_state *state; 127 128
+2 -1
drivers/media/video/wm8739.c
··· 261 261 262 262 /* i2c implementation */ 263 263 264 - static int wm8739_probe(struct i2c_client *client) 264 + static int wm8739_probe(struct i2c_client *client, 265 + const struct i2c_device_id *id) 265 266 { 266 267 struct wm8739_state *state; 267 268
+2 -1
drivers/media/video/wm8775.c
··· 159 159 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' 160 160 */ 161 161 162 - static int wm8775_probe(struct i2c_client *client) 162 + static int wm8775_probe(struct i2c_client *client, 163 + const struct i2c_device_id *id) 163 164 { 164 165 struct wm8775_state *state; 165 166
+2 -1
drivers/rtc/rtc-ds1307.c
··· 326 326 327 327 static struct i2c_driver ds1307_driver; 328 328 329 - static int __devinit ds1307_probe(struct i2c_client *client) 329 + static int __devinit ds1307_probe(struct i2c_client *client, 330 + const struct i2c_device_id *id) 330 331 { 331 332 struct ds1307 *ds1307; 332 333 int err = -ENODEV;
+2 -1
drivers/rtc/rtc-ds1374.c
··· 355 355 .ioctl = ds1374_ioctl, 356 356 }; 357 357 358 - static int ds1374_probe(struct i2c_client *client) 358 + static int ds1374_probe(struct i2c_client *client, 359 + const struct i2c_device_id *id) 359 360 { 360 361 struct ds1374 *ds1374; 361 362 int ret;
+1 -1
drivers/rtc/rtc-isl1208.c
··· 490 490 } 491 491 492 492 static int 493 - isl1208_probe(struct i2c_client *client) 493 + isl1208_probe(struct i2c_client *client, const struct i2c_device_id *id) 494 494 { 495 495 int rc = 0; 496 496 struct rtc_device *rtc;
+2 -1
drivers/rtc/rtc-m41t80.c
··· 756 756 * 757 757 ***************************************************************************** 758 758 */ 759 - static int m41t80_probe(struct i2c_client *client) 759 + static int m41t80_probe(struct i2c_client *client, 760 + const struct i2c_device_id *id) 760 761 { 761 762 int i, rc = 0; 762 763 struct rtc_device *rtc = NULL;
+2 -1
drivers/rtc/rtc-pcf8563.c
··· 246 246 .set_time = pcf8563_rtc_set_time, 247 247 }; 248 248 249 - static int pcf8563_probe(struct i2c_client *client) 249 + static int pcf8563_probe(struct i2c_client *client, 250 + const struct i2c_device_id *id) 250 251 { 251 252 struct pcf8563 *pcf8563; 252 253
+2 -1
drivers/rtc/rtc-rs5c372.c
··· 494 494 495 495 static struct i2c_driver rs5c372_driver; 496 496 497 - static int rs5c372_probe(struct i2c_client *client) 497 + static int rs5c372_probe(struct i2c_client *client, 498 + const struct i2c_device_id *id) 498 499 { 499 500 int err = 0; 500 501 struct rs5c372 *rs5c372;
+2 -1
drivers/rtc/rtc-s35390a.c
··· 195 195 196 196 static struct i2c_driver s35390a_driver; 197 197 198 - static int s35390a_probe(struct i2c_client *client) 198 + static int s35390a_probe(struct i2c_client *client, 199 + const struct i2c_device_id *id) 199 200 { 200 201 int err; 201 202 unsigned int i;
+2 -1
drivers/rtc/rtc-x1205.c
··· 494 494 } 495 495 496 496 497 - static int x1205_probe(struct i2c_client *client) 497 + static int x1205_probe(struct i2c_client *client, 498 + const struct i2c_device_id *id) 498 499 { 499 500 int err = 0; 500 501 unsigned char sr;
+2 -3
include/linux/i2c.h
··· 126 126 * With the driver model, device enumeration is NEVER done by drivers; 127 127 * it's done by infrastructure. (NEW STYLE DRIVERS ONLY) 128 128 */ 129 - int (*probe)(struct i2c_client *); 129 + int (*probe)(struct i2c_client *, const struct i2c_device_id *); 130 130 int (*remove)(struct i2c_client *); 131 131 132 132 /* driver model interfaces that don't relate to enumeration */ ··· 140 140 int (*command)(struct i2c_client *client,unsigned int cmd, void *arg); 141 141 142 142 struct device_driver driver; 143 + const struct i2c_device_id *id_table; 143 144 }; 144 145 #define to_i2c_driver(d) container_of(d, struct i2c_driver, driver) 145 - 146 - #define I2C_NAME_SIZE 20 147 146 148 147 /** 149 148 * struct i2c_client - represent an I2C slave device
+11
include/linux/mod_devicetable.h
··· 368 368 }; 369 369 #define VIRTIO_DEV_ANY_ID 0xffffffff 370 370 371 + /* i2c */ 372 + 373 + #define I2C_NAME_SIZE 20 374 + #define I2C_MODULE_PREFIX "i2c:" 375 + 376 + struct i2c_device_id { 377 + char name[I2C_NAME_SIZE]; 378 + kernel_ulong_t driver_data; /* Data private to the driver */ 379 + }; 380 + 381 + 371 382 #endif /* LINUX_MOD_DEVICETABLE_H */
+3 -1
include/media/v4l2-common.h
··· 107 107 struct i2c_driver; 108 108 struct i2c_adapter; 109 109 struct i2c_client; 110 + struct i2c_device_id; 110 111 111 112 int v4l2_i2c_attach(struct i2c_adapter *adapter, int address, struct i2c_driver *driver, 112 - const char *name, int (*probe)(struct i2c_client *)); 113 + const char *name, 114 + int (*probe)(struct i2c_client *, const struct i2c_device_id *)); 113 115 114 116 /* ------------------------------------------------------------------------- */ 115 117
+1 -1
include/media/v4l2-i2c-drv-legacy.h
··· 25 25 const char * const name; 26 26 int driverid; 27 27 int (*command)(struct i2c_client *client, unsigned int cmd, void *arg); 28 - int (*probe)(struct i2c_client *client); 28 + int (*probe)(struct i2c_client *client, const struct i2c_device_id *id); 29 29 int (*remove)(struct i2c_client *client); 30 30 int (*suspend)(struct i2c_client *client, pm_message_t state); 31 31 int (*resume)(struct i2c_client *client);
+1 -1
include/media/v4l2-i2c-drv.h
··· 30 30 const char * const name; 31 31 int driverid; 32 32 int (*command)(struct i2c_client *client, unsigned int cmd, void *arg); 33 - int (*probe)(struct i2c_client *client); 33 + int (*probe)(struct i2c_client *client, const struct i2c_device_id *id); 34 34 int (*remove)(struct i2c_client *client); 35 35 int (*suspend)(struct i2c_client *client, pm_message_t state); 36 36 int (*resume)(struct i2c_client *client);
+13
scripts/mod/file2alias.c
··· 576 576 return 1; 577 577 } 578 578 579 + /* Looks like: i2c:S */ 580 + static int do_i2c_entry(const char *filename, struct i2c_device_id *id, 581 + char *alias) 582 + { 583 + sprintf(alias, I2C_MODULE_PREFIX "%s", id->name); 584 + 585 + return 1; 586 + } 587 + 579 588 /* Ignore any prefix, eg. v850 prepends _ */ 580 589 static inline int sym_is(const char *symbol, const char *name) 581 590 { ··· 713 704 do_table(symval, sym->st_size, 714 705 sizeof(struct virtio_device_id), "virtio", 715 706 do_virtio_entry, mod); 707 + else if (sym_is(symname, "__mod_i2c_device_table")) 708 + do_table(symval, sym->st_size, 709 + sizeof(struct i2c_device_id), "i2c", 710 + do_i2c_entry, mod); 716 711 free(zeros); 717 712 } 718 713