aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/busses/Kconfig10
-rw-r--r--drivers/i2c/busses/Makefile1
-rw-r--r--drivers/i2c/busses/i2c-cadence.c11
-rw-r--r--drivers/i2c/busses/i2c-davinci.c8
-rw-r--r--drivers/i2c/busses/i2c-designware-core.c2
-rw-r--r--drivers/i2c/busses/i2c-dln2.c262
-rw-r--r--drivers/i2c/busses/i2c-hix5hd2.c2
-rw-r--r--drivers/i2c/busses/i2c-nomadik.c2
-rw-r--r--drivers/i2c/busses/i2c-omap.c12
-rw-r--r--drivers/i2c/i2c-core.c1
10 files changed, 296 insertions, 15 deletions
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 917c3585f45b..b4d135cc2f39 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -881,6 +881,16 @@ config I2C_DIOLAN_U2C
881 This driver can also be built as a module. If so, the module 881 This driver can also be built as a module. If so, the module
882 will be called i2c-diolan-u2c. 882 will be called i2c-diolan-u2c.
883 883
884config I2C_DLN2
885 tristate "Diolan DLN-2 USB I2C adapter"
886 depends on MFD_DLN2
887 help
888 If you say yes to this option, support will be included for Diolan
889 DLN2, a USB to I2C interface.
890
891 This driver can also be built as a module. If so, the module
892 will be called i2c-dln2.
893
884config I2C_PARPORT 894config I2C_PARPORT
885 tristate "Parallel port adapter" 895 tristate "Parallel port adapter"
886 depends on PARPORT 896 depends on PARPORT
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 78d56c54ba2b..cdac7f15eab5 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -87,6 +87,7 @@ obj-$(CONFIG_I2C_RCAR) += i2c-rcar.o
87 87
88# External I2C/SMBus adapter drivers 88# External I2C/SMBus adapter drivers
89obj-$(CONFIG_I2C_DIOLAN_U2C) += i2c-diolan-u2c.o 89obj-$(CONFIG_I2C_DIOLAN_U2C) += i2c-diolan-u2c.o
90obj-$(CONFIG_I2C_DLN2) += i2c-dln2.o
90obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o 91obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o
91obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o 92obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o
92obj-$(CONFIG_I2C_ROBOTFUZZ_OSIF) += i2c-robotfuzz-osif.o 93obj-$(CONFIG_I2C_ROBOTFUZZ_OSIF) += i2c-robotfuzz-osif.o
diff --git a/drivers/i2c/busses/i2c-cadence.c b/drivers/i2c/busses/i2c-cadence.c
index 63f3f03ecc9b..c604f4c3ac0d 100644
--- a/drivers/i2c/busses/i2c-cadence.c
+++ b/drivers/i2c/busses/i2c-cadence.c
@@ -111,6 +111,8 @@
111#define CDNS_I2C_DIVA_MAX 4 111#define CDNS_I2C_DIVA_MAX 4
112#define CDNS_I2C_DIVB_MAX 64 112#define CDNS_I2C_DIVB_MAX 64
113 113
114#define CDNS_I2C_TIMEOUT_MAX 0xFF
115
114#define cdns_i2c_readreg(offset) readl_relaxed(id->membase + offset) 116#define cdns_i2c_readreg(offset) readl_relaxed(id->membase + offset)
115#define cdns_i2c_writereg(val, offset) writel_relaxed(val, id->membase + offset) 117#define cdns_i2c_writereg(val, offset) writel_relaxed(val, id->membase + offset)
116 118
@@ -852,6 +854,15 @@ static int cdns_i2c_probe(struct platform_device *pdev)
852 goto err_clk_dis; 854 goto err_clk_dis;
853 } 855 }
854 856
857 /*
858 * Cadence I2C controller has a bug wherein it generates
859 * invalid read transaction after HW timeout in master receiver mode.
860 * HW timeout is not used by this driver and the interrupt is disabled.
861 * But the feature itself cannot be disabled. Hence maximum value
862 * is written to this register to reduce the chances of error.
863 */
864 cdns_i2c_writereg(CDNS_I2C_TIMEOUT_MAX, CDNS_I2C_TIME_OUT_OFFSET);
865
855 dev_info(&pdev->dev, "%u kHz mmio %08lx irq %d\n", 866 dev_info(&pdev->dev, "%u kHz mmio %08lx irq %d\n",
856 id->i2c_clk / 1000, (unsigned long)r_mem->start, id->irq); 867 id->i2c_clk / 1000, (unsigned long)r_mem->start, id->irq);
857 868
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index d15b7c9b9219..01f0cd87a4a5 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -407,11 +407,9 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
407 if (dev->cmd_err & DAVINCI_I2C_STR_NACK) { 407 if (dev->cmd_err & DAVINCI_I2C_STR_NACK) {
408 if (msg->flags & I2C_M_IGNORE_NAK) 408 if (msg->flags & I2C_M_IGNORE_NAK)
409 return msg->len; 409 return msg->len;
410 if (stop) { 410 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG);
411 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); 411 w |= DAVINCI_I2C_MDR_STP;
412 w |= DAVINCI_I2C_MDR_STP; 412 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w);
413 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w);
414 }
415 return -EREMOTEIO; 413 return -EREMOTEIO;
416 } 414 }
417 return -EIO; 415 return -EIO;
diff --git a/drivers/i2c/busses/i2c-designware-core.c b/drivers/i2c/busses/i2c-designware-core.c
index edca99dbba23..23628b7bfb8d 100644
--- a/drivers/i2c/busses/i2c-designware-core.c
+++ b/drivers/i2c/busses/i2c-designware-core.c
@@ -359,7 +359,7 @@ int i2c_dw_init(struct dw_i2c_dev *dev)
359 } 359 }
360 360
361 /* Configure Tx/Rx FIFO threshold levels */ 361 /* Configure Tx/Rx FIFO threshold levels */
362 dw_writel(dev, dev->tx_fifo_depth - 1, DW_IC_TX_TL); 362 dw_writel(dev, dev->tx_fifo_depth / 2, DW_IC_TX_TL);
363 dw_writel(dev, 0, DW_IC_RX_TL); 363 dw_writel(dev, 0, DW_IC_RX_TL);
364 364
365 /* configure the i2c master */ 365 /* configure the i2c master */
diff --git a/drivers/i2c/busses/i2c-dln2.c b/drivers/i2c/busses/i2c-dln2.c
new file mode 100644
index 000000000000..b3fb86af4cbb
--- /dev/null
+++ b/drivers/i2c/busses/i2c-dln2.c
@@ -0,0 +1,262 @@
1/*
2 * Driver for the Diolan DLN-2 USB-I2C adapter
3 *
4 * Copyright (c) 2014 Intel Corporation
5 *
6 * Derived from:
7 * i2c-diolan-u2c.c
8 * Copyright (c) 2010-2011 Ericsson AB
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation, version 2.
13 */
14
15#include <linux/kernel.h>
16#include <linux/module.h>
17#include <linux/types.h>
18#include <linux/slab.h>
19#include <linux/i2c.h>
20#include <linux/platform_device.h>
21#include <linux/mfd/dln2.h>
22
23#define DLN2_I2C_MODULE_ID 0x03
24#define DLN2_I2C_CMD(cmd) DLN2_CMD(cmd, DLN2_I2C_MODULE_ID)
25
26/* I2C commands */
27#define DLN2_I2C_GET_PORT_COUNT DLN2_I2C_CMD(0x00)
28#define DLN2_I2C_ENABLE DLN2_I2C_CMD(0x01)
29#define DLN2_I2C_DISABLE DLN2_I2C_CMD(0x02)
30#define DLN2_I2C_IS_ENABLED DLN2_I2C_CMD(0x03)
31#define DLN2_I2C_WRITE DLN2_I2C_CMD(0x06)
32#define DLN2_I2C_READ DLN2_I2C_CMD(0x07)
33#define DLN2_I2C_SCAN_DEVICES DLN2_I2C_CMD(0x08)
34#define DLN2_I2C_PULLUP_ENABLE DLN2_I2C_CMD(0x09)
35#define DLN2_I2C_PULLUP_DISABLE DLN2_I2C_CMD(0x0A)
36#define DLN2_I2C_PULLUP_IS_ENABLED DLN2_I2C_CMD(0x0B)
37#define DLN2_I2C_TRANSFER DLN2_I2C_CMD(0x0C)
38#define DLN2_I2C_SET_MAX_REPLY_COUNT DLN2_I2C_CMD(0x0D)
39#define DLN2_I2C_GET_MAX_REPLY_COUNT DLN2_I2C_CMD(0x0E)
40
41#define DLN2_I2C_MAX_XFER_SIZE 256
42#define DLN2_I2C_BUF_SIZE (DLN2_I2C_MAX_XFER_SIZE + 16)
43
44struct dln2_i2c {
45 struct platform_device *pdev;
46 struct i2c_adapter adapter;
47 u8 port;
48 /*
49 * Buffer to hold the packet for read or write transfers. One is enough
50 * since we can't have multiple transfers in parallel on the i2c bus.
51 */
52 void *buf;
53};
54
55static int dln2_i2c_enable(struct dln2_i2c *dln2, bool enable)
56{
57 u16 cmd;
58 struct {
59 u8 port;
60 } tx;
61
62 tx.port = dln2->port;
63
64 if (enable)
65 cmd = DLN2_I2C_ENABLE;
66 else
67 cmd = DLN2_I2C_DISABLE;
68
69 return dln2_transfer_tx(dln2->pdev, cmd, &tx, sizeof(tx));
70}
71
72static int dln2_i2c_write(struct dln2_i2c *dln2, u8 addr,
73 u8 *data, u16 data_len)
74{
75 int ret;
76 struct {
77 u8 port;
78 u8 addr;
79 u8 mem_addr_len;
80 __le32 mem_addr;
81 __le16 buf_len;
82 u8 buf[DLN2_I2C_MAX_XFER_SIZE];
83 } __packed *tx = dln2->buf;
84 unsigned len;
85
86 BUILD_BUG_ON(sizeof(*tx) > DLN2_I2C_BUF_SIZE);
87
88 tx->port = dln2->port;
89 tx->addr = addr;
90 tx->mem_addr_len = 0;
91 tx->mem_addr = 0;
92 tx->buf_len = cpu_to_le16(data_len);
93 memcpy(tx->buf, data, data_len);
94
95 len = sizeof(*tx) + data_len - DLN2_I2C_MAX_XFER_SIZE;
96 ret = dln2_transfer_tx(dln2->pdev, DLN2_I2C_WRITE, tx, len);
97 if (ret < 0)
98 return ret;
99
100 return data_len;
101}
102
103static int dln2_i2c_read(struct dln2_i2c *dln2, u16 addr, u8 *data,
104 u16 data_len)
105{
106 int ret;
107 struct {
108 u8 port;
109 u8 addr;
110 u8 mem_addr_len;
111 __le32 mem_addr;
112 __le16 buf_len;
113 } __packed tx;
114 struct {
115 __le16 buf_len;
116 u8 buf[DLN2_I2C_MAX_XFER_SIZE];
117 } __packed *rx = dln2->buf;
118 unsigned rx_len = sizeof(*rx);
119
120 BUILD_BUG_ON(sizeof(*rx) > DLN2_I2C_BUF_SIZE);
121
122 tx.port = dln2->port;
123 tx.addr = addr;
124 tx.mem_addr_len = 0;
125 tx.mem_addr = 0;
126 tx.buf_len = cpu_to_le16(data_len);
127
128 ret = dln2_transfer(dln2->pdev, DLN2_I2C_READ, &tx, sizeof(tx),
129 rx, &rx_len);
130 if (ret < 0)
131 return ret;
132 if (rx_len < sizeof(rx->buf_len) + data_len)
133 return -EPROTO;
134 if (le16_to_cpu(rx->buf_len) != data_len)
135 return -EPROTO;
136
137 memcpy(data, rx->buf, data_len);
138
139 return data_len;
140}
141
142static int dln2_i2c_xfer(struct i2c_adapter *adapter,
143 struct i2c_msg *msgs, int num)
144{
145 struct dln2_i2c *dln2 = i2c_get_adapdata(adapter);
146 struct i2c_msg *pmsg;
147 struct device *dev = &dln2->adapter.dev;
148 int i;
149
150 for (i = 0; i < num; i++) {
151 int ret;
152
153 pmsg = &msgs[i];
154
155 if (pmsg->len > DLN2_I2C_MAX_XFER_SIZE) {
156 dev_warn(dev, "maximum transfer size exceeded\n");
157 return -EOPNOTSUPP;
158 }
159
160 if (pmsg->flags & I2C_M_RD) {
161 ret = dln2_i2c_read(dln2, pmsg->addr, pmsg->buf,
162 pmsg->len);
163 if (ret < 0)
164 return ret;
165
166 pmsg->len = ret;
167 } else {
168 ret = dln2_i2c_write(dln2, pmsg->addr, pmsg->buf,
169 pmsg->len);
170 if (ret != pmsg->len)
171 return -EPROTO;
172 }
173 }
174
175 return num;
176}
177
178static u32 dln2_i2c_func(struct i2c_adapter *a)
179{
180 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_BYTE | I2C_FUNC_SMBUS_BYTE_DATA |
181 I2C_FUNC_SMBUS_WORD_DATA | I2C_FUNC_SMBUS_BLOCK_PROC_CALL |
182 I2C_FUNC_SMBUS_I2C_BLOCK;
183}
184
185static const struct i2c_algorithm dln2_i2c_usb_algorithm = {
186 .master_xfer = dln2_i2c_xfer,
187 .functionality = dln2_i2c_func,
188};
189
190static int dln2_i2c_probe(struct platform_device *pdev)
191{
192 int ret;
193 struct dln2_i2c *dln2;
194 struct device *dev = &pdev->dev;
195 struct dln2_platform_data *pdata = dev_get_platdata(&pdev->dev);
196
197 dln2 = devm_kzalloc(dev, sizeof(*dln2), GFP_KERNEL);
198 if (!dln2)
199 return -ENOMEM;
200
201 dln2->buf = devm_kmalloc(dev, DLN2_I2C_BUF_SIZE, GFP_KERNEL);
202 if (!dln2->buf)
203 return -ENOMEM;
204
205 dln2->pdev = pdev;
206 dln2->port = pdata->port;
207
208 /* setup i2c adapter description */
209 dln2->adapter.owner = THIS_MODULE;
210 dln2->adapter.class = I2C_CLASS_HWMON;
211 dln2->adapter.algo = &dln2_i2c_usb_algorithm;
212 dln2->adapter.dev.parent = dev;
213 i2c_set_adapdata(&dln2->adapter, dln2);
214 snprintf(dln2->adapter.name, sizeof(dln2->adapter.name), "%s-%s-%d",
215 "dln2-i2c", dev_name(pdev->dev.parent), dln2->port);
216
217 platform_set_drvdata(pdev, dln2);
218
219 /* initialize the i2c interface */
220 ret = dln2_i2c_enable(dln2, true);
221 if (ret < 0) {
222 dev_err(dev, "failed to initialize adapter: %d\n", ret);
223 return ret;
224 }
225
226 /* and finally attach to i2c layer */
227 ret = i2c_add_adapter(&dln2->adapter);
228 if (ret < 0) {
229 dev_err(dev, "failed to add I2C adapter: %d\n", ret);
230 goto out_disable;
231 }
232
233 return 0;
234
235out_disable:
236 dln2_i2c_enable(dln2, false);
237
238 return ret;
239}
240
241static int dln2_i2c_remove(struct platform_device *pdev)
242{
243 struct dln2_i2c *dln2 = platform_get_drvdata(pdev);
244
245 i2c_del_adapter(&dln2->adapter);
246 dln2_i2c_enable(dln2, false);
247
248 return 0;
249}
250
251static struct platform_driver dln2_i2c_driver = {
252 .driver.name = "dln2-i2c",
253 .probe = dln2_i2c_probe,
254 .remove = dln2_i2c_remove,
255};
256
257module_platform_driver(dln2_i2c_driver);
258
259MODULE_AUTHOR("Laurentiu Palcu <laurentiu.palcu@intel.com>");
260MODULE_DESCRIPTION("Driver for the Diolan DLN2 I2C master interface");
261MODULE_LICENSE("GPL v2");
262MODULE_ALIAS("platform:dln2-i2c");
diff --git a/drivers/i2c/busses/i2c-hix5hd2.c b/drivers/i2c/busses/i2c-hix5hd2.c
index 9490d0f4255c..8fe78d08e01c 100644
--- a/drivers/i2c/busses/i2c-hix5hd2.c
+++ b/drivers/i2c/busses/i2c-hix5hd2.c
@@ -528,7 +528,7 @@ static int hix5hd2_i2c_runtime_resume(struct device *dev)
528#endif 528#endif
529 529
530static const struct dev_pm_ops hix5hd2_i2c_pm_ops = { 530static const struct dev_pm_ops hix5hd2_i2c_pm_ops = {
531 SET_PM_RUNTIME_PM_OPS(hix5hd2_i2c_runtime_suspend, 531 SET_RUNTIME_PM_OPS(hix5hd2_i2c_runtime_suspend,
532 hix5hd2_i2c_runtime_resume, 532 hix5hd2_i2c_runtime_resume,
533 NULL) 533 NULL)
534}; 534};
diff --git a/drivers/i2c/busses/i2c-nomadik.c b/drivers/i2c/busses/i2c-nomadik.c
index 9ad038d223c4..97998946c4f6 100644
--- a/drivers/i2c/busses/i2c-nomadik.c
+++ b/drivers/i2c/busses/i2c-nomadik.c
@@ -932,7 +932,7 @@ static int nmk_i2c_runtime_resume(struct device *dev)
932 932
933static const struct dev_pm_ops nmk_i2c_pm = { 933static const struct dev_pm_ops nmk_i2c_pm = {
934 SET_LATE_SYSTEM_SLEEP_PM_OPS(nmk_i2c_suspend_late, nmk_i2c_resume_early) 934 SET_LATE_SYSTEM_SLEEP_PM_OPS(nmk_i2c_suspend_late, nmk_i2c_resume_early)
935 SET_PM_RUNTIME_PM_OPS(nmk_i2c_runtime_suspend, 935 SET_RUNTIME_PM_OPS(nmk_i2c_runtime_suspend,
936 nmk_i2c_runtime_resume, 936 nmk_i2c_runtime_resume,
937 NULL) 937 NULL)
938}; 938};
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 26942c159de1..0e650a0d0ad0 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -922,14 +922,12 @@ omap_i2c_isr_thread(int this_irq, void *dev_id)
922 if (stat & OMAP_I2C_STAT_NACK) { 922 if (stat & OMAP_I2C_STAT_NACK) {
923 err |= OMAP_I2C_STAT_NACK; 923 err |= OMAP_I2C_STAT_NACK;
924 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_NACK); 924 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_NACK);
925 break;
926 } 925 }
927 926
928 if (stat & OMAP_I2C_STAT_AL) { 927 if (stat & OMAP_I2C_STAT_AL) {
929 dev_err(dev->dev, "Arbitration lost\n"); 928 dev_err(dev->dev, "Arbitration lost\n");
930 err |= OMAP_I2C_STAT_AL; 929 err |= OMAP_I2C_STAT_AL;
931 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_AL); 930 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_AL);
932 break;
933 } 931 }
934 932
935 /* 933 /*
@@ -954,11 +952,13 @@ omap_i2c_isr_thread(int this_irq, void *dev_id)
954 if (dev->fifo_size) 952 if (dev->fifo_size)
955 num_bytes = dev->buf_len; 953 num_bytes = dev->buf_len;
956 954
957 omap_i2c_receive_data(dev, num_bytes, true); 955 if (dev->errata & I2C_OMAP_ERRATA_I207) {
958
959 if (dev->errata & I2C_OMAP_ERRATA_I207)
960 i2c_omap_errata_i207(dev, stat); 956 i2c_omap_errata_i207(dev, stat);
957 num_bytes = (omap_i2c_read_reg(dev,
958 OMAP_I2C_BUFSTAT_REG) >> 8) & 0x3F;
959 }
961 960
961 omap_i2c_receive_data(dev, num_bytes, true);
962 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RDR); 962 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RDR);
963 continue; 963 continue;
964 } 964 }
@@ -1280,7 +1280,6 @@ static int omap_i2c_remove(struct platform_device *pdev)
1280} 1280}
1281 1281
1282#ifdef CONFIG_PM 1282#ifdef CONFIG_PM
1283#ifdef CONFIG_PM_RUNTIME
1284static int omap_i2c_runtime_suspend(struct device *dev) 1283static int omap_i2c_runtime_suspend(struct device *dev)
1285{ 1284{
1286 struct platform_device *pdev = to_platform_device(dev); 1285 struct platform_device *pdev = to_platform_device(dev);
@@ -1318,7 +1317,6 @@ static int omap_i2c_runtime_resume(struct device *dev)
1318 1317
1319 return 0; 1318 return 0;
1320} 1319}
1321#endif /* CONFIG_PM_RUNTIME */
1322 1320
1323static struct dev_pm_ops omap_i2c_pm_ops = { 1321static struct dev_pm_ops omap_i2c_pm_ops = {
1324 SET_RUNTIME_PM_OPS(omap_i2c_runtime_suspend, 1322 SET_RUNTIME_PM_OPS(omap_i2c_runtime_suspend,
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index d8afd3f28ca4..229a89e84b0f 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -404,6 +404,7 @@ static int acpi_i2c_install_space_handler(struct i2c_adapter *adapter)
404 return -ENOMEM; 404 return -ENOMEM;
405 } 405 }
406 406
407 acpi_walk_dep_device_list(handle);
407 return 0; 408 return 0;
408} 409}
409 410