Commit 488bf314bf219c66922305a1a320950efa86662f

Authored by Grant Likely
Committed by Jean Delvare
1 parent 3fea5df41d

i2c: Allow i2c_add_numbered_adapter() to assign a bus id

Currently, if an i2c bus driver supports both static and dynamic bus
ids, it needs to choose between calling i2c_add_numbered_adapter() and
i2c_add_adapter().  This patch makes i2c_add_numbered_adapter()
redirect to i2c_add_adapter() if the requested bus id is -1.

Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Signed-off-by: Jean Delvare <khali@linux-fr.org>

Showing 4 changed files with 10 additions and 14 deletions Side-by-side Diff

drivers/i2c/busses/i2c-cpm.c
... ... @@ -662,11 +662,8 @@
662 662 /* register new adapter to i2c module... */
663 663  
664 664 data = of_get_property(ofdev->dev.of_node, "linux,i2c-index", &len);
665   - if (data && len == 4) {
666   - cpm->adap.nr = *data;
667   - result = i2c_add_numbered_adapter(&cpm->adap);
668   - } else
669   - result = i2c_add_adapter(&cpm->adap);
  665 + cpm->adap.nr = (data && len == 4) ? be32_to_cpup(data) : -1;
  666 + result = i2c_add_numbered_adapter(&cpm->adap);
670 667  
671 668 if (result < 0) {
672 669 dev_err(&ofdev->dev, "Unable to register with I2C\n");
drivers/i2c/busses/i2c-pxa.c
... ... @@ -1079,7 +1079,7 @@
1079 1079 * The reason to do so is to avoid sysfs names that only make
1080 1080 * sense when there are multiple adapters.
1081 1081 */
1082   - i2c->adap.nr = dev->id != -1 ? dev->id : 0;
  1082 + i2c->adap.nr = dev->id;
1083 1083 snprintf(i2c->adap.name, sizeof(i2c->adap.name), "pxa_i2c-i2c.%u",
1084 1084 i2c->adap.nr);
1085 1085  
... ... @@ -1142,10 +1142,7 @@
1142 1142 i2c->adap.dev.of_node = dev->dev.of_node;
1143 1143 #endif
1144 1144  
1145   - if (i2c_type == REGS_CE4100)
1146   - ret = i2c_add_adapter(&i2c->adap);
1147   - else
1148   - ret = i2c_add_numbered_adapter(&i2c->adap);
  1145 + ret = i2c_add_numbered_adapter(&i2c->adap);
1149 1146 if (ret < 0) {
1150 1147 printk(KERN_INFO "I2C: Failed to add bus\n");
1151 1148 goto eadapt;
drivers/i2c/busses/i2c-s6000.c
... ... @@ -341,10 +341,7 @@
341 341 i2c_wr16(iface, S6_I2C_TXTL, 0);
342 342  
343 343 platform_set_drvdata(dev, iface);
344   - if (bus_num < 0)
345   - rc = i2c_add_adapter(p_adap);
346   - else
347   - rc = i2c_add_numbered_adapter(p_adap);
  344 + rc = i2c_add_numbered_adapter(p_adap);
348 345 if (rc)
349 346 goto err_irq_free;
350 347 return 0;
drivers/i2c/i2c-core.c
... ... @@ -925,6 +925,9 @@
925 925 * or otherwise built in to the system's mainboard, and where i2c_board_info
926 926 * is used to properly configure I2C devices.
927 927 *
  928 + * If the requested bus number is set to -1, then this function will behave
  929 + * identically to i2c_add_adapter, and will dynamically assign a bus number.
  930 + *
928 931 * If no devices have pre-been declared for this bus, then be sure to
929 932 * register the adapter before any dynamically allocated ones. Otherwise
930 933 * the required bus ID may not be available.
... ... @@ -940,6 +943,8 @@
940 943 int id;
941 944 int status;
942 945  
  946 + if (adap->nr == -1) /* -1 means dynamically assign bus id */
  947 + return i2c_add_adapter(adap);
943 948 if (adap->nr & ~MAX_ID_MASK)
944 949 return -EINVAL;
945 950