diff options
author | Grant Likely <grant.likely@secretlab.ca> | 2011-07-25 11:49:43 -0400 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2011-07-25 11:49:43 -0400 |
commit | 488bf314bf219c66922305a1a320950efa86662f (patch) | |
tree | 84337cff8d57af18311129495f7cac4979845c55 /drivers | |
parent | 3fea5df41df685de53aa985678ad7a9b2d6b3bb5 (diff) |
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>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/i2c/busses/i2c-cpm.c | 7 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-pxa.c | 7 | ||||
-rw-r--r-- | drivers/i2c/busses/i2c-s6000.c | 5 | ||||
-rw-r--r-- | drivers/i2c/i2c-core.c | 5 |
4 files changed, 10 insertions, 14 deletions
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c index 3a20961bef1e..b1d9cd28d8da 100644 --- a/drivers/i2c/busses/i2c-cpm.c +++ b/drivers/i2c/busses/i2c-cpm.c | |||
@@ -662,11 +662,8 @@ static int __devinit cpm_i2c_probe(struct platform_device *ofdev) | |||
662 | /* register new adapter to i2c module... */ | 662 | /* register new adapter to i2c module... */ |
663 | 663 | ||
664 | data = of_get_property(ofdev->dev.of_node, "linux,i2c-index", &len); | 664 | data = of_get_property(ofdev->dev.of_node, "linux,i2c-index", &len); |
665 | if (data && len == 4) { | 665 | cpm->adap.nr = (data && len == 4) ? be32_to_cpup(data) : -1; |
666 | cpm->adap.nr = *data; | 666 | result = i2c_add_numbered_adapter(&cpm->adap); |
667 | result = i2c_add_numbered_adapter(&cpm->adap); | ||
668 | } else | ||
669 | result = i2c_add_adapter(&cpm->adap); | ||
670 | 667 | ||
671 | if (result < 0) { | 668 | if (result < 0) { |
672 | dev_err(&ofdev->dev, "Unable to register with I2C\n"); | 669 | dev_err(&ofdev->dev, "Unable to register with I2C\n"); |
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c index f59224a5c761..d60364650990 100644 --- a/drivers/i2c/busses/i2c-pxa.c +++ b/drivers/i2c/busses/i2c-pxa.c | |||
@@ -1079,7 +1079,7 @@ static int i2c_pxa_probe(struct platform_device *dev) | |||
1079 | * The reason to do so is to avoid sysfs names that only make | 1079 | * The reason to do so is to avoid sysfs names that only make |
1080 | * sense when there are multiple adapters. | 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 | snprintf(i2c->adap.name, sizeof(i2c->adap.name), "pxa_i2c-i2c.%u", | 1083 | snprintf(i2c->adap.name, sizeof(i2c->adap.name), "pxa_i2c-i2c.%u", |
1084 | i2c->adap.nr); | 1084 | i2c->adap.nr); |
1085 | 1085 | ||
@@ -1142,10 +1142,7 @@ static int i2c_pxa_probe(struct platform_device *dev) | |||
1142 | i2c->adap.dev.of_node = dev->dev.of_node; | 1142 | i2c->adap.dev.of_node = dev->dev.of_node; |
1143 | #endif | 1143 | #endif |
1144 | 1144 | ||
1145 | if (i2c_type == REGS_CE4100) | 1145 | ret = i2c_add_numbered_adapter(&i2c->adap); |
1146 | ret = i2c_add_adapter(&i2c->adap); | ||
1147 | else | ||
1148 | ret = i2c_add_numbered_adapter(&i2c->adap); | ||
1149 | if (ret < 0) { | 1146 | if (ret < 0) { |
1150 | printk(KERN_INFO "I2C: Failed to add bus\n"); | 1147 | printk(KERN_INFO "I2C: Failed to add bus\n"); |
1151 | goto eadapt; | 1148 | goto eadapt; |
diff --git a/drivers/i2c/busses/i2c-s6000.c b/drivers/i2c/busses/i2c-s6000.c index cb5d01e279c6..c64ba736f480 100644 --- a/drivers/i2c/busses/i2c-s6000.c +++ b/drivers/i2c/busses/i2c-s6000.c | |||
@@ -341,10 +341,7 @@ static int __devinit s6i2c_probe(struct platform_device *dev) | |||
341 | i2c_wr16(iface, S6_I2C_TXTL, 0); | 341 | i2c_wr16(iface, S6_I2C_TXTL, 0); |
342 | 342 | ||
343 | platform_set_drvdata(dev, iface); | 343 | platform_set_drvdata(dev, iface); |
344 | if (bus_num < 0) | 344 | rc = i2c_add_numbered_adapter(p_adap); |
345 | rc = i2c_add_adapter(p_adap); | ||
346 | else | ||
347 | rc = i2c_add_numbered_adapter(p_adap); | ||
348 | if (rc) | 345 | if (rc) |
349 | goto err_irq_free; | 346 | goto err_irq_free; |
350 | return 0; | 347 | return 0; |
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 9a58994ff7ea..131079a3e292 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c | |||
@@ -925,6 +925,9 @@ EXPORT_SYMBOL(i2c_add_adapter); | |||
925 | * or otherwise built in to the system's mainboard, and where i2c_board_info | 925 | * or otherwise built in to the system's mainboard, and where i2c_board_info |
926 | * is used to properly configure I2C devices. | 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 | * If no devices have pre-been declared for this bus, then be sure to | 931 | * If no devices have pre-been declared for this bus, then be sure to |
929 | * register the adapter before any dynamically allocated ones. Otherwise | 932 | * register the adapter before any dynamically allocated ones. Otherwise |
930 | * the required bus ID may not be available. | 933 | * the required bus ID may not be available. |
@@ -940,6 +943,8 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adap) | |||
940 | int id; | 943 | int id; |
941 | int status; | 944 | int status; |
942 | 945 | ||
946 | if (adap->nr == -1) /* -1 means dynamically assign bus id */ | ||
947 | return i2c_add_adapter(adap); | ||
943 | if (adap->nr & ~MAX_ID_MASK) | 948 | if (adap->nr & ~MAX_ID_MASK) |
944 | return -EINVAL; | 949 | return -EINVAL; |
945 | 950 | ||