aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
authorPaul Mundt <lethal@linux-sh.org>2010-05-19 22:57:38 -0400
committerPaul Mundt <lethal@linux-sh.org>2010-05-19 22:57:38 -0400
commitffee72d4681c8777918268a96aef42bdeb6c367b (patch)
tree4baf91483886d561c198ed0524ab54b783273e86 /drivers/i2c
parentfb54d268329846aa13b2bc44a64d90e9b7131192 (diff)
parentf72caf7e496465182eeda842ac66a5e75404ddf1 (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/Kconfig2
-rw-r--r--drivers/i2c/busses/i2c-imx.c6
-rw-r--r--drivers/i2c/busses/i2c-octeon.c4
-rw-r--r--drivers/i2c/busses/i2c-omap.c10
-rw-r--r--drivers/i2c/busses/i2c-pnx.c8
-rw-r--r--drivers/i2c/busses/i2c-stu300.c2
-rw-r--r--drivers/i2c/i2c-core.c63
7 files changed, 61 insertions, 34 deletions
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 41b0754eaf62..dec387d3f04d 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -564,7 +564,7 @@ config I2C_STU300
564 564
565config I2C_VERSATILE 565config I2C_VERSATILE
566 tristate "ARM Versatile/Realview I2C bus support" 566 tristate "ARM Versatile/Realview I2C bus support"
567 depends on ARCH_VERSATILE || ARCH_REALVIEW 567 depends on ARCH_VERSATILE || ARCH_REALVIEW || ARCH_VEXPRESS
568 select I2C_ALGOBIT 568 select I2C_ALGOBIT
569 help 569 help
570 Say yes if you want to support the I2C serial bus on ARMs Versatile 570 Say yes if you want to support the I2C serial bus on ARMs Versatile
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index f7e27b702375..d1ff9408dc1f 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -146,10 +146,10 @@ static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
146 "<%s> I2C Interrupted\n", __func__); 146 "<%s> I2C Interrupted\n", __func__);
147 return -EINTR; 147 return -EINTR;
148 } 148 }
149 if (time_after(jiffies, orig_jiffies + HZ / 1000)) { 149 if (time_after(jiffies, orig_jiffies + msecs_to_jiffies(500))) {
150 dev_dbg(&i2c_imx->adapter.dev, 150 dev_dbg(&i2c_imx->adapter.dev,
151 "<%s> I2C bus is busy\n", __func__); 151 "<%s> I2C bus is busy\n", __func__);
152 return -EIO; 152 return -ETIMEDOUT;
153 } 153 }
154 schedule(); 154 schedule();
155 } 155 }
@@ -444,6 +444,8 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
444 result = i2c_imx_read(i2c_imx, &msgs[i]); 444 result = i2c_imx_read(i2c_imx, &msgs[i]);
445 else 445 else
446 result = i2c_imx_write(i2c_imx, &msgs[i]); 446 result = i2c_imx_write(i2c_imx, &msgs[i]);
447 if (result)
448 goto fail0;
447 } 449 }
448 450
449fail0: 451fail0:
diff --git a/drivers/i2c/busses/i2c-octeon.c b/drivers/i2c/busses/i2c-octeon.c
index a2481f40ea1c..0e9f85d0a835 100644
--- a/drivers/i2c/busses/i2c-octeon.c
+++ b/drivers/i2c/busses/i2c-octeon.c
@@ -447,7 +447,7 @@ static struct i2c_adapter octeon_i2c_ops = {
447/** 447/**
448 * octeon_i2c_setclock - Calculate and set clock divisors. 448 * octeon_i2c_setclock - Calculate and set clock divisors.
449 */ 449 */
450static int __init octeon_i2c_setclock(struct octeon_i2c *i2c) 450static int __devinit octeon_i2c_setclock(struct octeon_i2c *i2c)
451{ 451{
452 int tclk, thp_base, inc, thp_idx, mdiv_idx, ndiv_idx, foscl, diff; 452 int tclk, thp_base, inc, thp_idx, mdiv_idx, ndiv_idx, foscl, diff;
453 int thp = 0x18, mdiv = 2, ndiv = 0, delta_hz = 1000000; 453 int thp = 0x18, mdiv = 2, ndiv = 0, delta_hz = 1000000;
@@ -490,7 +490,7 @@ static int __init octeon_i2c_setclock(struct octeon_i2c *i2c)
490 return 0; 490 return 0;
491} 491}
492 492
493static int __init octeon_i2c_initlowlevel(struct octeon_i2c *i2c) 493static int __devinit octeon_i2c_initlowlevel(struct octeon_i2c *i2c)
494{ 494{
495 u8 status; 495 u8 status;
496 int tries; 496 int tries;
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 6bd0f19cd451..389ac6032a7b 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -903,6 +903,11 @@ omap_i2c_probe(struct platform_device *pdev)
903 903
904 platform_set_drvdata(pdev, dev); 904 platform_set_drvdata(pdev, dev);
905 905
906 if (cpu_is_omap7xx())
907 dev->reg_shift = 1;
908 else
909 dev->reg_shift = 2;
910
906 if ((r = omap_i2c_get_clocks(dev)) != 0) 911 if ((r = omap_i2c_get_clocks(dev)) != 0)
907 goto err_iounmap; 912 goto err_iounmap;
908 913
@@ -926,11 +931,6 @@ omap_i2c_probe(struct platform_device *pdev)
926 dev->b_hw = 1; /* Enable hardware fixes */ 931 dev->b_hw = 1; /* Enable hardware fixes */
927 } 932 }
928 933
929 if (cpu_is_omap7xx())
930 dev->reg_shift = 1;
931 else
932 dev->reg_shift = 2;
933
934 /* reset ASAP, clearing any IRQs */ 934 /* reset ASAP, clearing any IRQs */
935 omap_i2c_init(dev); 935 omap_i2c_init(dev);
936 936
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c
index 247103372a06..a97e3fec8148 100644
--- a/drivers/i2c/busses/i2c-pnx.c
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -173,6 +173,9 @@ static int i2c_pnx_master_xmit(struct i2c_pnx_algo_data *alg_data)
173 /* We still have something to talk about... */ 173 /* We still have something to talk about... */
174 val = *alg_data->mif.buf++; 174 val = *alg_data->mif.buf++;
175 175
176 if (alg_data->mif.len == 1)
177 val |= stop_bit;
178
176 alg_data->mif.len--; 179 alg_data->mif.len--;
177 iowrite32(val, I2C_REG_TX(alg_data)); 180 iowrite32(val, I2C_REG_TX(alg_data));
178 181
@@ -246,6 +249,9 @@ static int i2c_pnx_master_rcv(struct i2c_pnx_algo_data *alg_data)
246 __func__); 249 __func__);
247 250
248 if (alg_data->mif.len == 1) { 251 if (alg_data->mif.len == 1) {
252 /* Last byte, do not acknowledge next rcv. */
253 val |= stop_bit;
254
249 /* 255 /*
250 * Enable interrupt RFDAIE (data in Rx fifo), 256 * Enable interrupt RFDAIE (data in Rx fifo),
251 * and disable DRMIE (need data for Tx) 257 * and disable DRMIE (need data for Tx)
@@ -633,6 +639,8 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
633 */ 639 */
634 640
635 tmp = ((freq / 1000) / I2C_PNX_SPEED_KHZ) / 2 - 2; 641 tmp = ((freq / 1000) / I2C_PNX_SPEED_KHZ) / 2 - 2;
642 if (tmp > 0x3FF)
643 tmp = 0x3FF;
636 iowrite32(tmp, I2C_REG_CKH(alg_data)); 644 iowrite32(tmp, I2C_REG_CKH(alg_data));
637 iowrite32(tmp, I2C_REG_CKL(alg_data)); 645 iowrite32(tmp, I2C_REG_CKL(alg_data));
638 646
diff --git a/drivers/i2c/busses/i2c-stu300.c b/drivers/i2c/busses/i2c-stu300.c
index 1f5b38be73bc..495be451d326 100644
--- a/drivers/i2c/busses/i2c-stu300.c
+++ b/drivers/i2c/busses/i2c-stu300.c
@@ -498,7 +498,7 @@ static int stu300_set_clk(struct stu300_dev *dev, unsigned long clkrate)
498 int i = 0; 498 int i = 0;
499 499
500 /* Locate the apropriate clock setting */ 500 /* Locate the apropriate clock setting */
501 while (i < ARRAY_SIZE(stu300_clktable) && 501 while (i < ARRAY_SIZE(stu300_clktable) - 1 &&
502 stu300_clktable[i].rate < clkrate) 502 stu300_clktable[i].rate < clkrate)
503 i++; 503 i++;
504 504
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 3202a86f420e..c2258a51fe0c 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -40,12 +40,11 @@
40#include "i2c-core.h" 40#include "i2c-core.h"
41 41
42 42
43/* core_lock protects i2c_adapter_idr, userspace_devices, and guarantees 43/* core_lock protects i2c_adapter_idr, and guarantees
44 that device detection, deletion of detected devices, and attach_adapter 44 that device detection, deletion of detected devices, and attach_adapter
45 and detach_adapter calls are serialized */ 45 and detach_adapter calls are serialized */
46static DEFINE_MUTEX(core_lock); 46static DEFINE_MUTEX(core_lock);
47static DEFINE_IDR(i2c_adapter_idr); 47static DEFINE_IDR(i2c_adapter_idr);
48static LIST_HEAD(userspace_devices);
49 48
50static struct device_type i2c_client_type; 49static struct device_type i2c_client_type;
51static int i2c_check_addr(struct i2c_adapter *adapter, int addr); 50static int i2c_check_addr(struct i2c_adapter *adapter, int addr);
@@ -117,8 +116,10 @@ static int i2c_device_probe(struct device *dev)
117 dev_dbg(dev, "probe\n"); 116 dev_dbg(dev, "probe\n");
118 117
119 status = driver->probe(client, i2c_match_id(driver->id_table, client)); 118 status = driver->probe(client, i2c_match_id(driver->id_table, client));
120 if (status) 119 if (status) {
121 client->driver = NULL; 120 client->driver = NULL;
121 i2c_set_clientdata(client, NULL);
122 }
122 return status; 123 return status;
123} 124}
124 125
@@ -139,8 +140,10 @@ static int i2c_device_remove(struct device *dev)
139 dev->driver = NULL; 140 dev->driver = NULL;
140 status = 0; 141 status = 0;
141 } 142 }
142 if (status == 0) 143 if (status == 0) {
143 client->driver = NULL; 144 client->driver = NULL;
145 i2c_set_clientdata(client, NULL);
146 }
144 return status; 147 return status;
145} 148}
146 149
@@ -538,9 +541,9 @@ i2c_sysfs_new_device(struct device *dev, struct device_attribute *attr,
538 return -EEXIST; 541 return -EEXIST;
539 542
540 /* Keep track of the added device */ 543 /* Keep track of the added device */
541 mutex_lock(&core_lock); 544 i2c_lock_adapter(adap);
542 list_add_tail(&client->detected, &userspace_devices); 545 list_add_tail(&client->detected, &adap->userspace_clients);
543 mutex_unlock(&core_lock); 546 i2c_unlock_adapter(adap);
544 dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device", 547 dev_info(dev, "%s: Instantiated device %s at 0x%02hx\n", "new_device",
545 info.type, info.addr); 548 info.type, info.addr);
546 549
@@ -579,9 +582,10 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
579 582
580 /* Make sure the device was added through sysfs */ 583 /* Make sure the device was added through sysfs */
581 res = -ENOENT; 584 res = -ENOENT;
582 mutex_lock(&core_lock); 585 i2c_lock_adapter(adap);
583 list_for_each_entry_safe(client, next, &userspace_devices, detected) { 586 list_for_each_entry_safe(client, next, &adap->userspace_clients,
584 if (client->addr == addr && client->adapter == adap) { 587 detected) {
588 if (client->addr == addr) {
585 dev_info(dev, "%s: Deleting device %s at 0x%02hx\n", 589 dev_info(dev, "%s: Deleting device %s at 0x%02hx\n",
586 "delete_device", client->name, client->addr); 590 "delete_device", client->name, client->addr);
587 591
@@ -591,7 +595,7 @@ i2c_sysfs_delete_device(struct device *dev, struct device_attribute *attr,
591 break; 595 break;
592 } 596 }
593 } 597 }
594 mutex_unlock(&core_lock); 598 i2c_unlock_adapter(adap);
595 599
596 if (res < 0) 600 if (res < 0)
597 dev_err(dev, "%s: Can't find device in list\n", 601 dev_err(dev, "%s: Can't find device in list\n",
@@ -673,6 +677,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
673 } 677 }
674 678
675 rt_mutex_init(&adap->bus_lock); 679 rt_mutex_init(&adap->bus_lock);
680 INIT_LIST_HEAD(&adap->userspace_clients);
676 681
677 /* Set default timeout to 1 second if not already set */ 682 /* Set default timeout to 1 second if not already set */
678 if (adap->timeout == 0) 683 if (adap->timeout == 0)
@@ -875,14 +880,15 @@ int i2c_del_adapter(struct i2c_adapter *adap)
875 return res; 880 return res;
876 881
877 /* Remove devices instantiated from sysfs */ 882 /* Remove devices instantiated from sysfs */
878 list_for_each_entry_safe(client, next, &userspace_devices, detected) { 883 i2c_lock_adapter(adap);
879 if (client->adapter == adap) { 884 list_for_each_entry_safe(client, next, &adap->userspace_clients,
880 dev_dbg(&adap->dev, "Removing %s at 0x%x\n", 885 detected) {
881 client->name, client->addr); 886 dev_dbg(&adap->dev, "Removing %s at 0x%x\n", client->name,
882 list_del(&client->detected); 887 client->addr);
883 i2c_unregister_device(client); 888 list_del(&client->detected);
884 } 889 i2c_unregister_device(client);
885 } 890 }
891 i2c_unlock_adapter(adap);
886 892
887 /* Detach any active clients. This can't fail, thus we do not 893 /* Detach any active clients. This can't fail, thus we do not
888 checking the returned value. */ 894 checking the returned value. */
@@ -1260,12 +1266,23 @@ static int i2c_detect_address(struct i2c_client *temp_client,
1260 return 0; 1266 return 0;
1261 1267
1262 /* Make sure there is something at this address */ 1268 /* Make sure there is something at this address */
1263 if (i2c_smbus_xfer(adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK, NULL) < 0) 1269 if (addr == 0x73 && (adapter->class & I2C_CLASS_HWMON)) {
1264 return 0; 1270 /* Special probe for FSC hwmon chips */
1271 union i2c_smbus_data dummy;
1265 1272
1266 /* Prevent 24RF08 corruption */ 1273 if (i2c_smbus_xfer(adapter, addr, 0, I2C_SMBUS_READ, 0,
1267 if ((addr & ~0x0f) == 0x50) 1274 I2C_SMBUS_BYTE_DATA, &dummy) < 0)
1268 i2c_smbus_xfer(adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK, NULL); 1275 return 0;
1276 } else {
1277 if (i2c_smbus_xfer(adapter, addr, 0, I2C_SMBUS_WRITE, 0,
1278 I2C_SMBUS_QUICK, NULL) < 0)
1279 return 0;
1280
1281 /* Prevent 24RF08 corruption */
1282 if ((addr & ~0x0f) == 0x50)
1283 i2c_smbus_xfer(adapter, addr, 0, I2C_SMBUS_WRITE, 0,
1284 I2C_SMBUS_QUICK, NULL);
1285 }
1269 1286
1270 /* Finally call the custom detection function */ 1287 /* Finally call the custom detection function */
1271 memset(&info, 0, sizeof(struct i2c_board_info)); 1288 memset(&info, 0, sizeof(struct i2c_board_info));