aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/Kconfig1
-rw-r--r--drivers/i2c/busses/Kconfig22
-rw-r--r--drivers/i2c/busses/Makefile3
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c2
-rw-r--r--drivers/i2c/busses/i2c-ali15x3.c2
-rw-r--r--drivers/i2c/busses/i2c-amd756.c2
-rw-r--r--drivers/i2c/busses/i2c-amd8111.c4
-rw-r--r--drivers/i2c/busses/i2c-designware.c488
-rw-r--r--drivers/i2c/busses/i2c-i801.c7
-rw-r--r--drivers/i2c/busses/i2c-imx.c86
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c6
-rw-r--r--drivers/i2c/busses/i2c-isch.c2
-rw-r--r--drivers/i2c/busses/i2c-mpc.c10
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c3
-rw-r--r--drivers/i2c/busses/i2c-omap.c64
-rw-r--r--drivers/i2c/busses/i2c-piix4.c12
-rw-r--r--drivers/i2c/busses/i2c-pnx.c12
-rw-r--r--drivers/i2c/busses/i2c-powermac.c139
-rw-r--r--drivers/i2c/busses/i2c-pxa.c2
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c2
-rw-r--r--drivers/i2c/busses/i2c-scmi.c7
-rw-r--r--drivers/i2c/busses/i2c-sh_mobile.c2
-rw-r--r--drivers/i2c/busses/i2c-sis5595.c2
-rw-r--r--drivers/i2c/busses/i2c-sis630.c2
-rw-r--r--drivers/i2c/busses/i2c-sis96x.c2
-rw-r--r--drivers/i2c/busses/i2c-stub.c34
-rw-r--r--drivers/i2c/busses/i2c-viapro.c2
-rw-r--r--drivers/i2c/busses/i2c-voodoo3.c248
-rw-r--r--drivers/i2c/chips/Kconfig10
-rw-r--r--drivers/i2c/chips/Makefile1
-rw-r--r--drivers/i2c/chips/ds1682.c267
-rw-r--r--drivers/i2c/chips/tsl2550.c3
-rw-r--r--drivers/i2c/i2c-core.c228
-rw-r--r--drivers/i2c/i2c-dev.c22
34 files changed, 701 insertions, 998 deletions
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index d7ece131b4f4..8d8a00e5a30e 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -5,6 +5,7 @@
5menuconfig I2C 5menuconfig I2C
6 tristate "I2C support" 6 tristate "I2C support"
7 depends on HAS_IOMEM 7 depends on HAS_IOMEM
8 select RT_MUTEXES
8 ---help--- 9 ---help---
9 I2C (pronounce: I-square-C) is a slow serial bus protocol used in 10 I2C (pronounce: I-square-C) is a slow serial bus protocol used in
10 many micro controller applications and developed by Philips. SMBus, 11 many micro controller applications and developed by Philips. SMBus,
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 6bedd2fcfc15..5f318ce29770 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -128,7 +128,7 @@ config I2C_PIIX4
128 ATI SB600 128 ATI SB600
129 ATI SB700 129 ATI SB700
130 ATI SB800 130 ATI SB800
131 AMD SB900 131 AMD Hudson-2
132 Serverworks OSB4 132 Serverworks OSB4
133 Serverworks CSB5 133 Serverworks CSB5
134 Serverworks CSB6 134 Serverworks CSB6
@@ -477,8 +477,8 @@ config I2C_PNX
477 will be called i2c-pnx. 477 will be called i2c-pnx.
478 478
479config I2C_PXA 479config I2C_PXA
480 tristate "Intel PXA2XX I2C adapter (EXPERIMENTAL)" 480 tristate "Intel PXA2XX I2C adapter"
481 depends on EXPERIMENTAL && ARCH_PXA 481 depends on ARCH_PXA || ARCH_MMP
482 help 482 help
483 If you have devices in the PXA I2C bus, say yes to this option. 483 If you have devices in the PXA I2C bus, say yes to this option.
484 This driver can also be built as a module. If so, the module 484 This driver can also be built as a module. If so, the module
@@ -640,22 +640,6 @@ config I2C_TINY_USB
640 This driver can also be built as a module. If so, the module 640 This driver can also be built as a module. If so, the module
641 will be called i2c-tiny-usb. 641 will be called i2c-tiny-usb.
642 642
643comment "Graphics adapter I2C/DDC channel drivers"
644 depends on PCI
645
646config I2C_VOODOO3
647 tristate "Voodoo 3 (DEPRECATED)"
648 depends on PCI
649 select I2C_ALGOBIT
650 help
651 If you say yes to this option, support will be included for the
652 Voodoo 3 I2C interface. This driver is deprecated and you should
653 use the tdfxfb driver instead, which additionally provides
654 framebuffer support.
655
656 This driver can also be built as a module. If so, the module
657 will be called i2c-voodoo3.
658
659comment "Other I2C/SMBus bus drivers" 643comment "Other I2C/SMBus bus drivers"
660 644
661config I2C_ACORN 645config I2C_ACORN
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index ff937ac69f5b..302c551977bb 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -61,9 +61,6 @@ obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o
61obj-$(CONFIG_I2C_TAOS_EVM) += i2c-taos-evm.o 61obj-$(CONFIG_I2C_TAOS_EVM) += i2c-taos-evm.o
62obj-$(CONFIG_I2C_TINY_USB) += i2c-tiny-usb.o 62obj-$(CONFIG_I2C_TINY_USB) += i2c-tiny-usb.o
63 63
64# Graphics adapter I2C/DDC channel drivers
65obj-$(CONFIG_I2C_VOODOO3) += i2c-voodoo3.o
66
67# Other I2C/SMBus bus drivers 64# Other I2C/SMBus bus drivers
68obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o 65obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o
69obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o 66obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index d108450df064..8de7d7b87bb0 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -138,7 +138,7 @@ static unsigned short ali1535_smba;
138 Note the differences between kernels with the old PCI BIOS interface and 138 Note the differences between kernels with the old PCI BIOS interface and
139 newer kernels with the real PCI interface. In compat.h some things are 139 newer kernels with the real PCI interface. In compat.h some things are
140 defined to make the transition easier. */ 140 defined to make the transition easier. */
141static int ali1535_setup(struct pci_dev *dev) 141static int __devinit ali1535_setup(struct pci_dev *dev)
142{ 142{
143 int retval = -ENODEV; 143 int retval = -ENODEV;
144 unsigned char temp; 144 unsigned char temp;
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index d627fceb790b..e7e3205f1286 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -131,7 +131,7 @@ MODULE_PARM_DESC(force_addr,
131static struct pci_driver ali15x3_driver; 131static struct pci_driver ali15x3_driver;
132static unsigned short ali15x3_smba; 132static unsigned short ali15x3_smba;
133 133
134static int ali15x3_setup(struct pci_dev *ALI15X3_dev) 134static int __devinit ali15x3_setup(struct pci_dev *ALI15X3_dev)
135{ 135{
136 u16 a; 136 u16 a;
137 unsigned char temp; 137 unsigned char temp;
diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index f7d6fe9c49ba..8f0b90ef8c76 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -364,7 +364,7 @@ static int __devinit amd756_probe(struct pci_dev *pdev,
364 error = acpi_check_region(amd756_ioport, SMB_IOSIZE, 364 error = acpi_check_region(amd756_ioport, SMB_IOSIZE,
365 amd756_driver.name); 365 amd756_driver.name);
366 if (error) 366 if (error)
367 return error; 367 return -ENODEV;
368 368
369 if (!request_region(amd756_ioport, SMB_IOSIZE, amd756_driver.name)) { 369 if (!request_region(amd756_ioport, SMB_IOSIZE, amd756_driver.name)) {
370 dev_err(&pdev->dev, "SMB region 0x%x already in use!\n", 370 dev_err(&pdev->dev, "SMB region 0x%x already in use!\n",
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c
index a7c59908c457..5b4ad86ca166 100644
--- a/drivers/i2c/busses/i2c-amd8111.c
+++ b/drivers/i2c/busses/i2c-amd8111.c
@@ -376,8 +376,10 @@ static int __devinit amd8111_probe(struct pci_dev *dev,
376 smbus->size = pci_resource_len(dev, 0); 376 smbus->size = pci_resource_len(dev, 0);
377 377
378 error = acpi_check_resource_conflict(&dev->resource[0]); 378 error = acpi_check_resource_conflict(&dev->resource[0]);
379 if (error) 379 if (error) {
380 error = -ENODEV;
380 goto out_kfree; 381 goto out_kfree;
382 }
381 383
382 if (!request_region(smbus->base, smbus->size, amd8111_driver.name)) { 384 if (!request_region(smbus->base, smbus->size, amd8111_driver.name)) {
383 error = -EBUSY; 385 error = -EBUSY;
diff --git a/drivers/i2c/busses/i2c-designware.c b/drivers/i2c/busses/i2c-designware.c
index b444762e9b9f..9e18ef97f156 100644
--- a/drivers/i2c/busses/i2c-designware.c
+++ b/drivers/i2c/busses/i2c-designware.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Synopsys Designware I2C adapter driver (master only). 2 * Synopsys DesignWare I2C adapter driver (master only).
3 * 3 *
4 * Based on the TI DAVINCI I2C adapter driver. 4 * Based on the TI DAVINCI I2C adapter driver.
5 * 5 *
@@ -49,7 +49,20 @@
49#define DW_IC_FS_SCL_LCNT 0x20 49#define DW_IC_FS_SCL_LCNT 0x20
50#define DW_IC_INTR_STAT 0x2c 50#define DW_IC_INTR_STAT 0x2c
51#define DW_IC_INTR_MASK 0x30 51#define DW_IC_INTR_MASK 0x30
52#define DW_IC_RAW_INTR_STAT 0x34
53#define DW_IC_RX_TL 0x38
54#define DW_IC_TX_TL 0x3c
52#define DW_IC_CLR_INTR 0x40 55#define DW_IC_CLR_INTR 0x40
56#define DW_IC_CLR_RX_UNDER 0x44
57#define DW_IC_CLR_RX_OVER 0x48
58#define DW_IC_CLR_TX_OVER 0x4c
59#define DW_IC_CLR_RD_REQ 0x50
60#define DW_IC_CLR_TX_ABRT 0x54
61#define DW_IC_CLR_RX_DONE 0x58
62#define DW_IC_CLR_ACTIVITY 0x5c
63#define DW_IC_CLR_STOP_DET 0x60
64#define DW_IC_CLR_START_DET 0x64
65#define DW_IC_CLR_GEN_CALL 0x68
53#define DW_IC_ENABLE 0x6c 66#define DW_IC_ENABLE 0x6c
54#define DW_IC_STATUS 0x70 67#define DW_IC_STATUS 0x70
55#define DW_IC_TXFLR 0x74 68#define DW_IC_TXFLR 0x74
@@ -64,9 +77,23 @@
64#define DW_IC_CON_RESTART_EN 0x20 77#define DW_IC_CON_RESTART_EN 0x20
65#define DW_IC_CON_SLAVE_DISABLE 0x40 78#define DW_IC_CON_SLAVE_DISABLE 0x40
66 79
67#define DW_IC_INTR_TX_EMPTY 0x10 80#define DW_IC_INTR_RX_UNDER 0x001
68#define DW_IC_INTR_TX_ABRT 0x40 81#define DW_IC_INTR_RX_OVER 0x002
82#define DW_IC_INTR_RX_FULL 0x004
83#define DW_IC_INTR_TX_OVER 0x008
84#define DW_IC_INTR_TX_EMPTY 0x010
85#define DW_IC_INTR_RD_REQ 0x020
86#define DW_IC_INTR_TX_ABRT 0x040
87#define DW_IC_INTR_RX_DONE 0x080
88#define DW_IC_INTR_ACTIVITY 0x100
69#define DW_IC_INTR_STOP_DET 0x200 89#define DW_IC_INTR_STOP_DET 0x200
90#define DW_IC_INTR_START_DET 0x400
91#define DW_IC_INTR_GEN_CALL 0x800
92
93#define DW_IC_INTR_DEFAULT_MASK (DW_IC_INTR_RX_FULL | \
94 DW_IC_INTR_TX_EMPTY | \
95 DW_IC_INTR_TX_ABRT | \
96 DW_IC_INTR_STOP_DET)
70 97
71#define DW_IC_STATUS_ACTIVITY 0x1 98#define DW_IC_STATUS_ACTIVITY 0x1
72 99
@@ -96,31 +123,49 @@
96#define ABRT_SBYTE_ACKDET 7 123#define ABRT_SBYTE_ACKDET 7
97#define ABRT_SBYTE_NORSTRT 9 124#define ABRT_SBYTE_NORSTRT 9
98#define ABRT_10B_RD_NORSTRT 10 125#define ABRT_10B_RD_NORSTRT 10
99#define ARB_MASTER_DIS 11 126#define ABRT_MASTER_DIS 11
100#define ARB_LOST 12 127#define ARB_LOST 12
101 128
129#define DW_IC_TX_ABRT_7B_ADDR_NOACK (1UL << ABRT_7B_ADDR_NOACK)
130#define DW_IC_TX_ABRT_10ADDR1_NOACK (1UL << ABRT_10ADDR1_NOACK)
131#define DW_IC_TX_ABRT_10ADDR2_NOACK (1UL << ABRT_10ADDR2_NOACK)
132#define DW_IC_TX_ABRT_TXDATA_NOACK (1UL << ABRT_TXDATA_NOACK)
133#define DW_IC_TX_ABRT_GCALL_NOACK (1UL << ABRT_GCALL_NOACK)
134#define DW_IC_TX_ABRT_GCALL_READ (1UL << ABRT_GCALL_READ)
135#define DW_IC_TX_ABRT_SBYTE_ACKDET (1UL << ABRT_SBYTE_ACKDET)
136#define DW_IC_TX_ABRT_SBYTE_NORSTRT (1UL << ABRT_SBYTE_NORSTRT)
137#define DW_IC_TX_ABRT_10B_RD_NORSTRT (1UL << ABRT_10B_RD_NORSTRT)
138#define DW_IC_TX_ABRT_MASTER_DIS (1UL << ABRT_MASTER_DIS)
139#define DW_IC_TX_ARB_LOST (1UL << ARB_LOST)
140
141#define DW_IC_TX_ABRT_NOACK (DW_IC_TX_ABRT_7B_ADDR_NOACK | \
142 DW_IC_TX_ABRT_10ADDR1_NOACK | \
143 DW_IC_TX_ABRT_10ADDR2_NOACK | \
144 DW_IC_TX_ABRT_TXDATA_NOACK | \
145 DW_IC_TX_ABRT_GCALL_NOACK)
146
102static char *abort_sources[] = { 147static char *abort_sources[] = {
103 [ABRT_7B_ADDR_NOACK] = 148 [ABRT_7B_ADDR_NOACK] =
104 "slave address not acknowledged (7bit mode)", 149 "slave address not acknowledged (7bit mode)",
105 [ABRT_10ADDR1_NOACK] = 150 [ABRT_10ADDR1_NOACK] =
106 "first address byte not acknowledged (10bit mode)", 151 "first address byte not acknowledged (10bit mode)",
107 [ABRT_10ADDR2_NOACK] = 152 [ABRT_10ADDR2_NOACK] =
108 "second address byte not acknowledged (10bit mode)", 153 "second address byte not acknowledged (10bit mode)",
109 [ABRT_TXDATA_NOACK] = 154 [ABRT_TXDATA_NOACK] =
110 "data not acknowledged", 155 "data not acknowledged",
111 [ABRT_GCALL_NOACK] = 156 [ABRT_GCALL_NOACK] =
112 "no acknowledgement for a general call", 157 "no acknowledgement for a general call",
113 [ABRT_GCALL_READ] = 158 [ABRT_GCALL_READ] =
114 "read after general call", 159 "read after general call",
115 [ABRT_SBYTE_ACKDET] = 160 [ABRT_SBYTE_ACKDET] =
116 "start byte acknowledged", 161 "start byte acknowledged",
117 [ABRT_SBYTE_NORSTRT] = 162 [ABRT_SBYTE_NORSTRT] =
118 "trying to send start byte when restart is disabled", 163 "trying to send start byte when restart is disabled",
119 [ABRT_10B_RD_NORSTRT] = 164 [ABRT_10B_RD_NORSTRT] =
120 "trying to read when restart is disabled (10bit mode)", 165 "trying to read when restart is disabled (10bit mode)",
121 [ARB_MASTER_DIS] = 166 [ABRT_MASTER_DIS] =
122 "trying to use disabled adapter", 167 "trying to use disabled adapter",
123 [ARB_LOST] = 168 [ARB_LOST] =
124 "lost arbitration", 169 "lost arbitration",
125}; 170};
126 171
@@ -129,7 +174,6 @@ static char *abort_sources[] = {
129 * @dev: driver model device node 174 * @dev: driver model device node
130 * @base: IO registers pointer 175 * @base: IO registers pointer
131 * @cmd_complete: tx completion indicator 176 * @cmd_complete: tx completion indicator
132 * @pump_msg: continue in progress transfers
133 * @lock: protect this struct and IO registers 177 * @lock: protect this struct and IO registers
134 * @clk: input reference clock 178 * @clk: input reference clock
135 * @cmd_err: run time hadware error code 179 * @cmd_err: run time hadware error code
@@ -155,27 +199,81 @@ struct dw_i2c_dev {
155 struct device *dev; 199 struct device *dev;
156 void __iomem *base; 200 void __iomem *base;
157 struct completion cmd_complete; 201 struct completion cmd_complete;
158 struct tasklet_struct pump_msg;
159 struct mutex lock; 202 struct mutex lock;
160 struct clk *clk; 203 struct clk *clk;
161 int cmd_err; 204 int cmd_err;
162 struct i2c_msg *msgs; 205 struct i2c_msg *msgs;
163 int msgs_num; 206 int msgs_num;
164 int msg_write_idx; 207 int msg_write_idx;
165 u16 tx_buf_len; 208 u32 tx_buf_len;
166 u8 *tx_buf; 209 u8 *tx_buf;
167 int msg_read_idx; 210 int msg_read_idx;
168 u16 rx_buf_len; 211 u32 rx_buf_len;
169 u8 *rx_buf; 212 u8 *rx_buf;
170 int msg_err; 213 int msg_err;
171 unsigned int status; 214 unsigned int status;
172 u16 abort_source; 215 u32 abort_source;
173 int irq; 216 int irq;
174 struct i2c_adapter adapter; 217 struct i2c_adapter adapter;
175 unsigned int tx_fifo_depth; 218 unsigned int tx_fifo_depth;
176 unsigned int rx_fifo_depth; 219 unsigned int rx_fifo_depth;
177}; 220};
178 221
222static u32
223i2c_dw_scl_hcnt(u32 ic_clk, u32 tSYMBOL, u32 tf, int cond, int offset)
224{
225 /*
226 * DesignWare I2C core doesn't seem to have solid strategy to meet
227 * the tHD;STA timing spec. Configuring _HCNT based on tHIGH spec
228 * will result in violation of the tHD;STA spec.
229 */
230 if (cond)
231 /*
232 * Conditional expression:
233 *
234 * IC_[FS]S_SCL_HCNT + (1+4+3) >= IC_CLK * tHIGH
235 *
236 * This is based on the DW manuals, and represents an ideal
237 * configuration. The resulting I2C bus speed will be
238 * faster than any of the others.
239 *
240 * If your hardware is free from tHD;STA issue, try this one.
241 */
242 return (ic_clk * tSYMBOL + 5000) / 10000 - 8 + offset;
243 else
244 /*
245 * Conditional expression:
246 *
247 * IC_[FS]S_SCL_HCNT + 3 >= IC_CLK * (tHD;STA + tf)
248 *
249 * This is just experimental rule; the tHD;STA period turned
250 * out to be proportinal to (_HCNT + 3). With this setting,
251 * we could meet both tHIGH and tHD;STA timing specs.
252 *
253 * If unsure, you'd better to take this alternative.
254 *
255 * The reason why we need to take into account "tf" here,
256 * is the same as described in i2c_dw_scl_lcnt().
257 */
258 return (ic_clk * (tSYMBOL + tf) + 5000) / 10000 - 3 + offset;
259}
260
261static u32 i2c_dw_scl_lcnt(u32 ic_clk, u32 tLOW, u32 tf, int offset)
262{
263 /*
264 * Conditional expression:
265 *
266 * IC_[FS]S_SCL_LCNT + 1 >= IC_CLK * (tLOW + tf)
267 *
268 * DW I2C core starts counting the SCL CNTs for the LOW period
269 * of the SCL clock (tLOW) as soon as it pulls the SCL line.
270 * In order to meet the tLOW timing spec, we need to take into
271 * account the fall time of SCL signal (tf). Default tf value
272 * should be 0.3 us, for safety.
273 */
274 return ((ic_clk * (tLOW + tf) + 5000) / 10000) - 1 + offset;
275}
276
179/** 277/**
180 * i2c_dw_init() - initialize the designware i2c master hardware 278 * i2c_dw_init() - initialize the designware i2c master hardware
181 * @dev: device private data 279 * @dev: device private data
@@ -187,25 +285,49 @@ struct dw_i2c_dev {
187static void i2c_dw_init(struct dw_i2c_dev *dev) 285static void i2c_dw_init(struct dw_i2c_dev *dev)
188{ 286{
189 u32 input_clock_khz = clk_get_rate(dev->clk) / 1000; 287 u32 input_clock_khz = clk_get_rate(dev->clk) / 1000;
190 u16 ic_con; 288 u32 ic_con, hcnt, lcnt;
191 289
192 /* Disable the adapter */ 290 /* Disable the adapter */
193 writeb(0, dev->base + DW_IC_ENABLE); 291 writel(0, dev->base + DW_IC_ENABLE);
194 292
195 /* set standard and fast speed deviders for high/low periods */ 293 /* set standard and fast speed deviders for high/low periods */
196 writew((input_clock_khz * 40 / 10000)+1, /* std speed high, 4us */ 294
197 dev->base + DW_IC_SS_SCL_HCNT); 295 /* Standard-mode */
198 writew((input_clock_khz * 47 / 10000)+1, /* std speed low, 4.7us */ 296 hcnt = i2c_dw_scl_hcnt(input_clock_khz,
199 dev->base + DW_IC_SS_SCL_LCNT); 297 40, /* tHD;STA = tHIGH = 4.0 us */
200 writew((input_clock_khz * 6 / 10000)+1, /* fast speed high, 0.6us */ 298 3, /* tf = 0.3 us */
201 dev->base + DW_IC_FS_SCL_HCNT); 299 0, /* 0: DW default, 1: Ideal */
202 writew((input_clock_khz * 13 / 10000)+1, /* fast speed low, 1.3us */ 300 0); /* No offset */
203 dev->base + DW_IC_FS_SCL_LCNT); 301 lcnt = i2c_dw_scl_lcnt(input_clock_khz,
302 47, /* tLOW = 4.7 us */
303 3, /* tf = 0.3 us */
304 0); /* No offset */
305 writel(hcnt, dev->base + DW_IC_SS_SCL_HCNT);
306 writel(lcnt, dev->base + DW_IC_SS_SCL_LCNT);
307 dev_dbg(dev->dev, "Standard-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt);
308
309 /* Fast-mode */
310 hcnt = i2c_dw_scl_hcnt(input_clock_khz,
311 6, /* tHD;STA = tHIGH = 0.6 us */
312 3, /* tf = 0.3 us */
313 0, /* 0: DW default, 1: Ideal */
314 0); /* No offset */
315 lcnt = i2c_dw_scl_lcnt(input_clock_khz,
316 13, /* tLOW = 1.3 us */
317 3, /* tf = 0.3 us */
318 0); /* No offset */
319 writel(hcnt, dev->base + DW_IC_FS_SCL_HCNT);
320 writel(lcnt, dev->base + DW_IC_FS_SCL_LCNT);
321 dev_dbg(dev->dev, "Fast-mode HCNT:LCNT = %d:%d\n", hcnt, lcnt);
322
323 /* Configure Tx/Rx FIFO threshold levels */
324 writel(dev->tx_fifo_depth - 1, dev->base + DW_IC_TX_TL);
325 writel(0, dev->base + DW_IC_RX_TL);
204 326
205 /* configure the i2c master */ 327 /* configure the i2c master */
206 ic_con = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE | 328 ic_con = DW_IC_CON_MASTER | DW_IC_CON_SLAVE_DISABLE |
207 DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST; 329 DW_IC_CON_RESTART_EN | DW_IC_CON_SPEED_FAST;
208 writew(ic_con, dev->base + DW_IC_CON); 330 writel(ic_con, dev->base + DW_IC_CON);
209} 331}
210 332
211/* 333/*
@@ -215,7 +337,7 @@ static int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev)
215{ 337{
216 int timeout = TIMEOUT; 338 int timeout = TIMEOUT;
217 339
218 while (readb(dev->base + DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) { 340 while (readl(dev->base + DW_IC_STATUS) & DW_IC_STATUS_ACTIVITY) {
219 if (timeout <= 0) { 341 if (timeout <= 0) {
220 dev_warn(dev->dev, "timeout waiting for bus ready\n"); 342 dev_warn(dev->dev, "timeout waiting for bus ready\n");
221 return -ETIMEDOUT; 343 return -ETIMEDOUT;
@@ -227,106 +349,125 @@ static int i2c_dw_wait_bus_not_busy(struct dw_i2c_dev *dev)
227 return 0; 349 return 0;
228} 350}
229 351
352static void i2c_dw_xfer_init(struct dw_i2c_dev *dev)
353{
354 struct i2c_msg *msgs = dev->msgs;
355 u32 ic_con;
356
357 /* Disable the adapter */
358 writel(0, dev->base + DW_IC_ENABLE);
359
360 /* set the slave (target) address */
361 writel(msgs[dev->msg_write_idx].addr, dev->base + DW_IC_TAR);
362
363 /* if the slave address is ten bit address, enable 10BITADDR */
364 ic_con = readl(dev->base + DW_IC_CON);
365 if (msgs[dev->msg_write_idx].flags & I2C_M_TEN)
366 ic_con |= DW_IC_CON_10BITADDR_MASTER;
367 else
368 ic_con &= ~DW_IC_CON_10BITADDR_MASTER;
369 writel(ic_con, dev->base + DW_IC_CON);
370
371 /* Enable the adapter */
372 writel(1, dev->base + DW_IC_ENABLE);
373
374 /* Enable interrupts */
375 writel(DW_IC_INTR_DEFAULT_MASK, dev->base + DW_IC_INTR_MASK);
376}
377
230/* 378/*
231 * Initiate low level master read/write transaction. 379 * Initiate (and continue) low level master read/write transaction.
232 * This function is called from i2c_dw_xfer when starting a transfer. 380 * This function is only called from i2c_dw_isr, and pumping i2c_msg
233 * This function is also called from dw_i2c_pump_msg to continue a transfer 381 * messages into the tx buffer. Even if the size of i2c_msg data is
234 * that is longer than the size of the TX FIFO. 382 * longer than the size of the tx buffer, it handles everything.
235 */ 383 */
236static void 384static void
237i2c_dw_xfer_msg(struct i2c_adapter *adap) 385i2c_dw_xfer_msg(struct dw_i2c_dev *dev)
238{ 386{
239 struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
240 struct i2c_msg *msgs = dev->msgs; 387 struct i2c_msg *msgs = dev->msgs;
241 int num = dev->msgs_num; 388 u32 intr_mask;
242 u16 ic_con, intr_mask; 389 int tx_limit, rx_limit;
243 int tx_limit = dev->tx_fifo_depth - readb(dev->base + DW_IC_TXFLR); 390 u32 addr = msgs[dev->msg_write_idx].addr;
244 int rx_limit = dev->rx_fifo_depth - readb(dev->base + DW_IC_RXFLR); 391 u32 buf_len = dev->tx_buf_len;
245 u16 addr = msgs[dev->msg_write_idx].addr; 392 u8 *buf = dev->tx_buf;;
246 u16 buf_len = dev->tx_buf_len;
247
248 if (!(dev->status & STATUS_WRITE_IN_PROGRESS)) {
249 /* Disable the adapter */
250 writeb(0, dev->base + DW_IC_ENABLE);
251
252 /* set the slave (target) address */
253 writew(msgs[dev->msg_write_idx].addr, dev->base + DW_IC_TAR);
254 393
255 /* if the slave address is ten bit address, enable 10BITADDR */ 394 intr_mask = DW_IC_INTR_DEFAULT_MASK;
256 ic_con = readw(dev->base + DW_IC_CON);
257 if (msgs[dev->msg_write_idx].flags & I2C_M_TEN)
258 ic_con |= DW_IC_CON_10BITADDR_MASTER;
259 else
260 ic_con &= ~DW_IC_CON_10BITADDR_MASTER;
261 writew(ic_con, dev->base + DW_IC_CON);
262 395
263 /* Enable the adapter */ 396 for (; dev->msg_write_idx < dev->msgs_num; dev->msg_write_idx++) {
264 writeb(1, dev->base + DW_IC_ENABLE); 397 /*
265 } 398 * if target address has changed, we need to
266
267 for (; dev->msg_write_idx < num; dev->msg_write_idx++) {
268 /* if target address has changed, we need to
269 * reprogram the target address in the i2c 399 * reprogram the target address in the i2c
270 * adapter when we are done with this transfer 400 * adapter when we are done with this transfer
271 */ 401 */
272 if (msgs[dev->msg_write_idx].addr != addr) 402 if (msgs[dev->msg_write_idx].addr != addr) {
273 return; 403 dev_err(dev->dev,
404 "%s: invalid target address\n", __func__);
405 dev->msg_err = -EINVAL;
406 break;
407 }
274 408
275 if (msgs[dev->msg_write_idx].len == 0) { 409 if (msgs[dev->msg_write_idx].len == 0) {
276 dev_err(dev->dev, 410 dev_err(dev->dev,
277 "%s: invalid message length\n", __func__); 411 "%s: invalid message length\n", __func__);
278 dev->msg_err = -EINVAL; 412 dev->msg_err = -EINVAL;
279 return; 413 break;
280 } 414 }
281 415
282 if (!(dev->status & STATUS_WRITE_IN_PROGRESS)) { 416 if (!(dev->status & STATUS_WRITE_IN_PROGRESS)) {
283 /* new i2c_msg */ 417 /* new i2c_msg */
284 dev->tx_buf = msgs[dev->msg_write_idx].buf; 418 buf = msgs[dev->msg_write_idx].buf;
285 buf_len = msgs[dev->msg_write_idx].len; 419 buf_len = msgs[dev->msg_write_idx].len;
286 } 420 }
287 421
422 tx_limit = dev->tx_fifo_depth - readl(dev->base + DW_IC_TXFLR);
423 rx_limit = dev->rx_fifo_depth - readl(dev->base + DW_IC_RXFLR);
424
288 while (buf_len > 0 && tx_limit > 0 && rx_limit > 0) { 425 while (buf_len > 0 && tx_limit > 0 && rx_limit > 0) {
289 if (msgs[dev->msg_write_idx].flags & I2C_M_RD) { 426 if (msgs[dev->msg_write_idx].flags & I2C_M_RD) {
290 writew(0x100, dev->base + DW_IC_DATA_CMD); 427 writel(0x100, dev->base + DW_IC_DATA_CMD);
291 rx_limit--; 428 rx_limit--;
292 } else 429 } else
293 writew(*(dev->tx_buf++), 430 writel(*buf++, dev->base + DW_IC_DATA_CMD);
294 dev->base + DW_IC_DATA_CMD);
295 tx_limit--; buf_len--; 431 tx_limit--; buf_len--;
296 } 432 }
433
434 dev->tx_buf = buf;
435 dev->tx_buf_len = buf_len;
436
437 if (buf_len > 0) {
438 /* more bytes to be written */
439 dev->status |= STATUS_WRITE_IN_PROGRESS;
440 break;
441 } else
442 dev->status &= ~STATUS_WRITE_IN_PROGRESS;
297 } 443 }
298 444
299 intr_mask = DW_IC_INTR_STOP_DET | DW_IC_INTR_TX_ABRT; 445 /*
300 if (buf_len > 0) { /* more bytes to be written */ 446 * If i2c_msg index search is completed, we don't need TX_EMPTY
301 intr_mask |= DW_IC_INTR_TX_EMPTY; 447 * interrupt any more.
302 dev->status |= STATUS_WRITE_IN_PROGRESS; 448 */
303 } else 449 if (dev->msg_write_idx == dev->msgs_num)
304 dev->status &= ~STATUS_WRITE_IN_PROGRESS; 450 intr_mask &= ~DW_IC_INTR_TX_EMPTY;
305 writew(intr_mask, dev->base + DW_IC_INTR_MASK); 451
452 if (dev->msg_err)
453 intr_mask = 0;
306 454
307 dev->tx_buf_len = buf_len; 455 writel(intr_mask, dev->base + DW_IC_INTR_MASK);
308} 456}
309 457
310static void 458static void
311i2c_dw_read(struct i2c_adapter *adap) 459i2c_dw_read(struct dw_i2c_dev *dev)
312{ 460{
313 struct dw_i2c_dev *dev = i2c_get_adapdata(adap);
314 struct i2c_msg *msgs = dev->msgs; 461 struct i2c_msg *msgs = dev->msgs;
315 int num = dev->msgs_num; 462 int rx_valid;
316 u16 addr = msgs[dev->msg_read_idx].addr;
317 int rx_valid = readw(dev->base + DW_IC_RXFLR);
318 463
319 for (; dev->msg_read_idx < num; dev->msg_read_idx++) { 464 for (; dev->msg_read_idx < dev->msgs_num; dev->msg_read_idx++) {
320 u16 len; 465 u32 len;
321 u8 *buf; 466 u8 *buf;
322 467
323 if (!(msgs[dev->msg_read_idx].flags & I2C_M_RD)) 468 if (!(msgs[dev->msg_read_idx].flags & I2C_M_RD))
324 continue; 469 continue;
325 470
326 /* different i2c client, reprogram the i2c adapter */
327 if (msgs[dev->msg_read_idx].addr != addr)
328 return;
329
330 if (!(dev->status & STATUS_READ_IN_PROGRESS)) { 471 if (!(dev->status & STATUS_READ_IN_PROGRESS)) {
331 len = msgs[dev->msg_read_idx].len; 472 len = msgs[dev->msg_read_idx].len;
332 buf = msgs[dev->msg_read_idx].buf; 473 buf = msgs[dev->msg_read_idx].buf;
@@ -335,8 +476,10 @@ i2c_dw_read(struct i2c_adapter *adap)
335 buf = dev->rx_buf; 476 buf = dev->rx_buf;
336 } 477 }
337 478
479 rx_valid = readl(dev->base + DW_IC_RXFLR);
480
338 for (; len > 0 && rx_valid > 0; len--, rx_valid--) 481 for (; len > 0 && rx_valid > 0; len--, rx_valid--)
339 *buf++ = readb(dev->base + DW_IC_DATA_CMD); 482 *buf++ = readl(dev->base + DW_IC_DATA_CMD);
340 483
341 if (len > 0) { 484 if (len > 0) {
342 dev->status |= STATUS_READ_IN_PROGRESS; 485 dev->status |= STATUS_READ_IN_PROGRESS;
@@ -348,6 +491,29 @@ i2c_dw_read(struct i2c_adapter *adap)
348 } 491 }
349} 492}
350 493
494static int i2c_dw_handle_tx_abort(struct dw_i2c_dev *dev)
495{
496 unsigned long abort_source = dev->abort_source;
497 int i;
498
499 if (abort_source & DW_IC_TX_ABRT_NOACK) {
500 for_each_bit(i, &abort_source, ARRAY_SIZE(abort_sources))
501 dev_dbg(dev->dev,
502 "%s: %s\n", __func__, abort_sources[i]);
503 return -EREMOTEIO;
504 }
505
506 for_each_bit(i, &abort_source, ARRAY_SIZE(abort_sources))
507 dev_err(dev->dev, "%s: %s\n", __func__, abort_sources[i]);
508
509 if (abort_source & DW_IC_TX_ARB_LOST)
510 return -EAGAIN;
511 else if (abort_source & DW_IC_TX_ABRT_GCALL_READ)
512 return -EINVAL; /* wrong msgs[] data */
513 else
514 return -EIO;
515}
516
351/* 517/*
352 * Prepare controller for a transaction and call i2c_dw_xfer_msg 518 * Prepare controller for a transaction and call i2c_dw_xfer_msg
353 */ 519 */
@@ -369,13 +535,14 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
369 dev->msg_read_idx = 0; 535 dev->msg_read_idx = 0;
370 dev->msg_err = 0; 536 dev->msg_err = 0;
371 dev->status = STATUS_IDLE; 537 dev->status = STATUS_IDLE;
538 dev->abort_source = 0;
372 539
373 ret = i2c_dw_wait_bus_not_busy(dev); 540 ret = i2c_dw_wait_bus_not_busy(dev);
374 if (ret < 0) 541 if (ret < 0)
375 goto done; 542 goto done;
376 543
377 /* start the transfers */ 544 /* start the transfers */
378 i2c_dw_xfer_msg(adap); 545 i2c_dw_xfer_init(dev);
379 546
380 /* wait for tx to complete */ 547 /* wait for tx to complete */
381 ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, HZ); 548 ret = wait_for_completion_interruptible_timeout(&dev->cmd_complete, HZ);
@@ -394,23 +561,16 @@ i2c_dw_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
394 561
395 /* no error */ 562 /* no error */
396 if (likely(!dev->cmd_err)) { 563 if (likely(!dev->cmd_err)) {
397 /* read rx fifo, and disable the adapter */ 564 /* Disable the adapter */
398 do { 565 writel(0, dev->base + DW_IC_ENABLE);
399 i2c_dw_read(adap);
400 } while (dev->status & STATUS_READ_IN_PROGRESS);
401 writeb(0, dev->base + DW_IC_ENABLE);
402 ret = num; 566 ret = num;
403 goto done; 567 goto done;
404 } 568 }
405 569
406 /* We have an error */ 570 /* We have an error */
407 if (dev->cmd_err == DW_IC_ERR_TX_ABRT) { 571 if (dev->cmd_err == DW_IC_ERR_TX_ABRT) {
408 unsigned long abort_source = dev->abort_source; 572 ret = i2c_dw_handle_tx_abort(dev);
409 int i; 573 goto done;
410
411 for_each_bit(i, &abort_source, ARRAY_SIZE(abort_sources)) {
412 dev_err(dev->dev, "%s: %s\n", __func__, abort_sources[i]);
413 }
414 } 574 }
415 ret = -EIO; 575 ret = -EIO;
416 576
@@ -422,21 +582,67 @@ done:
422 582
423static u32 i2c_dw_func(struct i2c_adapter *adap) 583static u32 i2c_dw_func(struct i2c_adapter *adap)
424{ 584{
425 return I2C_FUNC_I2C | I2C_FUNC_10BIT_ADDR; 585 return I2C_FUNC_I2C |
586 I2C_FUNC_10BIT_ADDR |
587 I2C_FUNC_SMBUS_BYTE |
588 I2C_FUNC_SMBUS_BYTE_DATA |
589 I2C_FUNC_SMBUS_WORD_DATA |
590 I2C_FUNC_SMBUS_I2C_BLOCK;
426} 591}
427 592
428static void dw_i2c_pump_msg(unsigned long data) 593static u32 i2c_dw_read_clear_intrbits(struct dw_i2c_dev *dev)
429{ 594{
430 struct dw_i2c_dev *dev = (struct dw_i2c_dev *) data; 595 u32 stat;
431 u16 intr_mask; 596
432 597 /*
433 i2c_dw_read(&dev->adapter); 598 * The IC_INTR_STAT register just indicates "enabled" interrupts.
434 i2c_dw_xfer_msg(&dev->adapter); 599 * Ths unmasked raw version of interrupt status bits are available
435 600 * in the IC_RAW_INTR_STAT register.
436 intr_mask = DW_IC_INTR_STOP_DET | DW_IC_INTR_TX_ABRT; 601 *
437 if (dev->status & STATUS_WRITE_IN_PROGRESS) 602 * That is,
438 intr_mask |= DW_IC_INTR_TX_EMPTY; 603 * stat = readl(IC_INTR_STAT);
439 writew(intr_mask, dev->base + DW_IC_INTR_MASK); 604 * equals to,
605 * stat = readl(IC_RAW_INTR_STAT) & readl(IC_INTR_MASK);
606 *
607 * The raw version might be useful for debugging purposes.
608 */
609 stat = readl(dev->base + DW_IC_INTR_STAT);
610
611 /*
612 * Do not use the IC_CLR_INTR register to clear interrupts, or
613 * you'll miss some interrupts, triggered during the period from
614 * readl(IC_INTR_STAT) to readl(IC_CLR_INTR).
615 *
616 * Instead, use the separately-prepared IC_CLR_* registers.
617 */
618 if (stat & DW_IC_INTR_RX_UNDER)
619 readl(dev->base + DW_IC_CLR_RX_UNDER);
620 if (stat & DW_IC_INTR_RX_OVER)
621 readl(dev->base + DW_IC_CLR_RX_OVER);
622 if (stat & DW_IC_INTR_TX_OVER)
623 readl(dev->base + DW_IC_CLR_TX_OVER);
624 if (stat & DW_IC_INTR_RD_REQ)
625 readl(dev->base + DW_IC_CLR_RD_REQ);
626 if (stat & DW_IC_INTR_TX_ABRT) {
627 /*
628 * The IC_TX_ABRT_SOURCE register is cleared whenever
629 * the IC_CLR_TX_ABRT is read. Preserve it beforehand.
630 */
631 dev->abort_source = readl(dev->base + DW_IC_TX_ABRT_SOURCE);
632 readl(dev->base + DW_IC_CLR_TX_ABRT);
633 }
634 if (stat & DW_IC_INTR_RX_DONE)
635 readl(dev->base + DW_IC_CLR_RX_DONE);
636 if (stat & DW_IC_INTR_ACTIVITY)
637 readl(dev->base + DW_IC_CLR_ACTIVITY);
638 if (stat & DW_IC_INTR_STOP_DET)
639 readl(dev->base + DW_IC_CLR_STOP_DET);
640 if (stat & DW_IC_INTR_START_DET)
641 readl(dev->base + DW_IC_CLR_START_DET);
642 if (stat & DW_IC_INTR_GEN_CALL)
643 readl(dev->base + DW_IC_CLR_GEN_CALL);
644
645 return stat;
440} 646}
441 647
442/* 648/*
@@ -446,20 +652,37 @@ static void dw_i2c_pump_msg(unsigned long data)
446static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id) 652static irqreturn_t i2c_dw_isr(int this_irq, void *dev_id)
447{ 653{
448 struct dw_i2c_dev *dev = dev_id; 654 struct dw_i2c_dev *dev = dev_id;
449 u16 stat; 655 u32 stat;
450 656
451 stat = readw(dev->base + DW_IC_INTR_STAT); 657 stat = i2c_dw_read_clear_intrbits(dev);
452 dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat); 658 dev_dbg(dev->dev, "%s: stat=0x%x\n", __func__, stat);
659
453 if (stat & DW_IC_INTR_TX_ABRT) { 660 if (stat & DW_IC_INTR_TX_ABRT) {
454 dev->abort_source = readw(dev->base + DW_IC_TX_ABRT_SOURCE);
455 dev->cmd_err |= DW_IC_ERR_TX_ABRT; 661 dev->cmd_err |= DW_IC_ERR_TX_ABRT;
456 dev->status = STATUS_IDLE; 662 dev->status = STATUS_IDLE;
457 } else if (stat & DW_IC_INTR_TX_EMPTY)
458 tasklet_schedule(&dev->pump_msg);
459 663
460 readb(dev->base + DW_IC_CLR_INTR); /* clear interrupts */ 664 /*
461 writew(0, dev->base + DW_IC_INTR_MASK); /* disable interrupts */ 665 * Anytime TX_ABRT is set, the contents of the tx/rx
462 if (stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET)) 666 * buffers are flushed. Make sure to skip them.
667 */
668 writel(0, dev->base + DW_IC_INTR_MASK);
669 goto tx_aborted;
670 }
671
672 if (stat & DW_IC_INTR_RX_FULL)
673 i2c_dw_read(dev);
674
675 if (stat & DW_IC_INTR_TX_EMPTY)
676 i2c_dw_xfer_msg(dev);
677
678 /*
679 * No need to modify or disable the interrupt mask here.
680 * i2c_dw_xfer_msg() will take care of it according to
681 * the current transmit status.
682 */
683
684tx_aborted:
685 if ((stat & (DW_IC_INTR_TX_ABRT | DW_IC_INTR_STOP_DET)) || dev->msg_err)
463 complete(&dev->cmd_complete); 686 complete(&dev->cmd_complete);
464 687
465 return IRQ_HANDLED; 688 return IRQ_HANDLED;
@@ -474,8 +697,8 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev)
474{ 697{
475 struct dw_i2c_dev *dev; 698 struct dw_i2c_dev *dev;
476 struct i2c_adapter *adap; 699 struct i2c_adapter *adap;
477 struct resource *mem, *irq, *ioarea; 700 struct resource *mem, *ioarea;
478 int r; 701 int irq, r;
479 702
480 /* NOTE: driver uses the static register mapping */ 703 /* NOTE: driver uses the static register mapping */
481 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 704 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -484,10 +707,10 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev)
484 return -EINVAL; 707 return -EINVAL;
485 } 708 }
486 709
487 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0); 710 irq = platform_get_irq(pdev, 0);
488 if (!irq) { 711 if (irq < 0) {
489 dev_err(&pdev->dev, "no irq resource?\n"); 712 dev_err(&pdev->dev, "no irq resource?\n");
490 return -EINVAL; 713 return irq; /* -ENXIO */
491 } 714 }
492 715
493 ioarea = request_mem_region(mem->start, resource_size(mem), 716 ioarea = request_mem_region(mem->start, resource_size(mem),
@@ -504,10 +727,9 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev)
504 } 727 }
505 728
506 init_completion(&dev->cmd_complete); 729 init_completion(&dev->cmd_complete);
507 tasklet_init(&dev->pump_msg, dw_i2c_pump_msg, (unsigned long) dev);
508 mutex_init(&dev->lock); 730 mutex_init(&dev->lock);
509 dev->dev = get_device(&pdev->dev); 731 dev->dev = get_device(&pdev->dev);
510 dev->irq = irq->start; 732 dev->irq = irq;
511 platform_set_drvdata(pdev, dev); 733 platform_set_drvdata(pdev, dev);
512 734
513 dev->clk = clk_get(&pdev->dev, NULL); 735 dev->clk = clk_get(&pdev->dev, NULL);
@@ -531,8 +753,8 @@ static int __devinit dw_i2c_probe(struct platform_device *pdev)
531 } 753 }
532 i2c_dw_init(dev); 754 i2c_dw_init(dev);
533 755
534 writew(0, dev->base + DW_IC_INTR_MASK); /* disable IRQ */ 756 writel(0, dev->base + DW_IC_INTR_MASK); /* disable IRQ */
535 r = request_irq(dev->irq, i2c_dw_isr, 0, pdev->name, dev); 757 r = request_irq(dev->irq, i2c_dw_isr, IRQF_DISABLED, pdev->name, dev);
536 if (r) { 758 if (r) {
537 dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq); 759 dev_err(&pdev->dev, "failure requesting irq %i\n", dev->irq);
538 goto err_iounmap; 760 goto err_iounmap;
@@ -587,7 +809,7 @@ static int __devexit dw_i2c_remove(struct platform_device *pdev)
587 clk_put(dev->clk); 809 clk_put(dev->clk);
588 dev->clk = NULL; 810 dev->clk = NULL;
589 811
590 writeb(0, dev->base + DW_IC_ENABLE); 812 writel(0, dev->base + DW_IC_ENABLE);
591 free_irq(dev->irq, dev); 813 free_irq(dev->irq, dev);
592 kfree(dev); 814 kfree(dev);
593 815
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 9d2c5adf5d4f..df6ab553f975 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -732,8 +732,10 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
732 } 732 }
733 733
734 err = acpi_check_resource_conflict(&dev->resource[SMBBAR]); 734 err = acpi_check_resource_conflict(&dev->resource[SMBBAR]);
735 if (err) 735 if (err) {
736 err = -ENODEV;
736 goto exit; 737 goto exit;
738 }
737 739
738 err = pci_request_region(dev, SMBBAR, i801_driver.name); 740 err = pci_request_region(dev, SMBBAR, i801_driver.name);
739 if (err) { 741 if (err) {
@@ -765,6 +767,9 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
765 /* set up the sysfs linkage to our parent device */ 767 /* set up the sysfs linkage to our parent device */
766 i801_adapter.dev.parent = &dev->dev; 768 i801_adapter.dev.parent = &dev->dev;
767 769
770 /* Retry up to 3 times on lost arbitration */
771 i801_adapter.retries = 3;
772
768 snprintf(i801_adapter.name, sizeof(i801_adapter.name), 773 snprintf(i801_adapter.name, sizeof(i801_adapter.name),
769 "SMBus I801 adapter at %04lx", i801_smba); 774 "SMBus I801 adapter at %04lx", i801_smba);
770 err = i2c_add_adapter(&i801_adapter); 775 err = i2c_add_adapter(&i801_adapter);
diff --git a/drivers/i2c/busses/i2c-imx.c b/drivers/i2c/busses/i2c-imx.c
index 4afba3ec2a61..e3654d683e15 100644
--- a/drivers/i2c/busses/i2c-imx.c
+++ b/drivers/i2c/busses/i2c-imx.c
@@ -120,19 +120,26 @@ struct imx_i2c_struct {
120 wait_queue_head_t queue; 120 wait_queue_head_t queue;
121 unsigned long i2csr; 121 unsigned long i2csr;
122 unsigned int disable_delay; 122 unsigned int disable_delay;
123 int stopped;
124 unsigned int ifdr; /* IMX_I2C_IFDR */
123}; 125};
124 126
125/** Functions for IMX I2C adapter driver *************************************** 127/** Functions for IMX I2C adapter driver ***************************************
126*******************************************************************************/ 128*******************************************************************************/
127 129
128static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx) 130static int i2c_imx_bus_busy(struct imx_i2c_struct *i2c_imx, int for_busy)
129{ 131{
130 unsigned long orig_jiffies = jiffies; 132 unsigned long orig_jiffies = jiffies;
133 unsigned int temp;
131 134
132 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); 135 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
133 136
134 /* wait for bus not busy */ 137 while (1) {
135 while (readb(i2c_imx->base + IMX_I2C_I2SR) & I2SR_IBB) { 138 temp = readb(i2c_imx->base + IMX_I2C_I2SR);
139 if (for_busy && (temp & I2SR_IBB))
140 break;
141 if (!for_busy && !(temp & I2SR_IBB))
142 break;
136 if (signal_pending(current)) { 143 if (signal_pending(current)) {
137 dev_dbg(&i2c_imx->adapter.dev, 144 dev_dbg(&i2c_imx->adapter.dev,
138 "<%s> I2C Interrupted\n", __func__); 145 "<%s> I2C Interrupted\n", __func__);
@@ -179,41 +186,62 @@ static int i2c_imx_acked(struct imx_i2c_struct *i2c_imx)
179 return 0; 186 return 0;
180} 187}
181 188
182static void i2c_imx_start(struct imx_i2c_struct *i2c_imx) 189static int i2c_imx_start(struct imx_i2c_struct *i2c_imx)
183{ 190{
184 unsigned int temp = 0; 191 unsigned int temp = 0;
192 int result;
185 193
186 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); 194 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
187 195
196 clk_enable(i2c_imx->clk);
197 writeb(i2c_imx->ifdr, i2c_imx->base + IMX_I2C_IFDR);
188 /* Enable I2C controller */ 198 /* Enable I2C controller */
199 writeb(0, i2c_imx->base + IMX_I2C_I2SR);
189 writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR); 200 writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR);
201
202 /* Wait controller to be stable */
203 udelay(50);
204
190 /* Start I2C transaction */ 205 /* Start I2C transaction */
191 temp = readb(i2c_imx->base + IMX_I2C_I2CR); 206 temp = readb(i2c_imx->base + IMX_I2C_I2CR);
192 temp |= I2CR_MSTA; 207 temp |= I2CR_MSTA;
193 writeb(temp, i2c_imx->base + IMX_I2C_I2CR); 208 writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
209 result = i2c_imx_bus_busy(i2c_imx, 1);
210 if (result)
211 return result;
212 i2c_imx->stopped = 0;
213
194 temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK; 214 temp |= I2CR_IIEN | I2CR_MTX | I2CR_TXAK;
195 writeb(temp, i2c_imx->base + IMX_I2C_I2CR); 215 writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
216 return result;
196} 217}
197 218
198static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx) 219static void i2c_imx_stop(struct imx_i2c_struct *i2c_imx)
199{ 220{
200 unsigned int temp = 0; 221 unsigned int temp = 0;
201 222
202 /* Stop I2C transaction */ 223 if (!i2c_imx->stopped) {
203 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); 224 /* Stop I2C transaction */
204 temp = readb(i2c_imx->base + IMX_I2C_I2CR); 225 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
205 temp &= ~I2CR_MSTA; 226 temp = readb(i2c_imx->base + IMX_I2C_I2CR);
206 writeb(temp, i2c_imx->base + IMX_I2C_I2CR); 227 temp &= ~(I2CR_MSTA | I2CR_MTX);
207 /* setup chip registers to defaults */ 228 writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
208 writeb(I2CR_IEN, i2c_imx->base + IMX_I2C_I2CR); 229 i2c_imx->stopped = 1;
209 writeb(0, i2c_imx->base + IMX_I2C_I2SR); 230 }
210 /* 231 if (cpu_is_mx1()) {
211 * This delay caused by an i.MXL hardware bug. 232 /*
212 * If no (or too short) delay, no "STOP" bit will be generated. 233 * This delay caused by an i.MXL hardware bug.
213 */ 234 * If no (or too short) delay, no "STOP" bit will be generated.
214 udelay(i2c_imx->disable_delay); 235 */
236 udelay(i2c_imx->disable_delay);
237 }
238
239 if (!i2c_imx->stopped)
240 i2c_imx_bus_busy(i2c_imx, 0);
241
215 /* Disable I2C controller */ 242 /* Disable I2C controller */
216 writeb(0, i2c_imx->base + IMX_I2C_I2CR); 243 writeb(0, i2c_imx->base + IMX_I2C_I2CR);
244 clk_disable(i2c_imx->clk);
217} 245}
218 246
219static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx, 247static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
@@ -233,8 +261,8 @@ static void __init i2c_imx_set_clk(struct imx_i2c_struct *i2c_imx,
233 else 261 else
234 for (i = 0; i2c_clk_div[i][0] < div; i++); 262 for (i = 0; i2c_clk_div[i][0] < div; i++);
235 263
236 /* Write divider value to register */ 264 /* Store divider value */
237 writeb(i2c_clk_div[i][1], i2c_imx->base + IMX_I2C_IFDR); 265 i2c_imx->ifdr = i2c_clk_div[i][1];
238 266
239 /* 267 /*
240 * There dummy delay is calculated. 268 * There dummy delay is calculated.
@@ -341,11 +369,15 @@ static int i2c_imx_read(struct imx_i2c_struct *i2c_imx, struct i2c_msg *msgs)
341 if (result) 369 if (result)
342 return result; 370 return result;
343 if (i == (msgs->len - 1)) { 371 if (i == (msgs->len - 1)) {
372 /* It must generate STOP before read I2DR to prevent
373 controller from generating another clock cycle */
344 dev_dbg(&i2c_imx->adapter.dev, 374 dev_dbg(&i2c_imx->adapter.dev,
345 "<%s> clear MSTA\n", __func__); 375 "<%s> clear MSTA\n", __func__);
346 temp = readb(i2c_imx->base + IMX_I2C_I2CR); 376 temp = readb(i2c_imx->base + IMX_I2C_I2CR);
347 temp &= ~I2CR_MSTA; 377 temp &= ~(I2CR_MSTA | I2CR_MTX);
348 writeb(temp, i2c_imx->base + IMX_I2C_I2CR); 378 writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
379 i2c_imx_bus_busy(i2c_imx, 0);
380 i2c_imx->stopped = 1;
349 } else if (i == (msgs->len - 2)) { 381 } else if (i == (msgs->len - 2)) {
350 dev_dbg(&i2c_imx->adapter.dev, 382 dev_dbg(&i2c_imx->adapter.dev,
351 "<%s> set TXAK\n", __func__); 383 "<%s> set TXAK\n", __func__);
@@ -370,14 +402,11 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
370 402
371 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__); 403 dev_dbg(&i2c_imx->adapter.dev, "<%s>\n", __func__);
372 404
373 /* Check if i2c bus is not busy */ 405 /* Start I2C transfer */
374 result = i2c_imx_bus_busy(i2c_imx); 406 result = i2c_imx_start(i2c_imx);
375 if (result) 407 if (result)
376 goto fail0; 408 goto fail0;
377 409
378 /* Start I2C transfer */
379 i2c_imx_start(i2c_imx);
380
381 /* read/write data */ 410 /* read/write data */
382 for (i = 0; i < num; i++) { 411 for (i = 0; i < num; i++) {
383 if (i) { 412 if (i) {
@@ -386,6 +415,9 @@ static int i2c_imx_xfer(struct i2c_adapter *adapter,
386 temp = readb(i2c_imx->base + IMX_I2C_I2CR); 415 temp = readb(i2c_imx->base + IMX_I2C_I2CR);
387 temp |= I2CR_RSTA; 416 temp |= I2CR_RSTA;
388 writeb(temp, i2c_imx->base + IMX_I2C_I2CR); 417 writeb(temp, i2c_imx->base + IMX_I2C_I2CR);
418 result = i2c_imx_bus_busy(i2c_imx, 1);
419 if (result)
420 goto fail0;
389 } 421 }
390 dev_dbg(&i2c_imx->adapter.dev, 422 dev_dbg(&i2c_imx->adapter.dev,
391 "<%s> transfer message: %d\n", __func__, i); 423 "<%s> transfer message: %d\n", __func__, i);
@@ -500,7 +532,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
500 dev_err(&pdev->dev, "can't get I2C clock\n"); 532 dev_err(&pdev->dev, "can't get I2C clock\n");
501 goto fail3; 533 goto fail3;
502 } 534 }
503 clk_enable(i2c_imx->clk);
504 535
505 /* Request IRQ */ 536 /* Request IRQ */
506 ret = request_irq(i2c_imx->irq, i2c_imx_isr, 0, pdev->name, i2c_imx); 537 ret = request_irq(i2c_imx->irq, i2c_imx_isr, 0, pdev->name, i2c_imx);
@@ -549,7 +580,6 @@ static int __init i2c_imx_probe(struct platform_device *pdev)
549fail5: 580fail5:
550 free_irq(i2c_imx->irq, i2c_imx); 581 free_irq(i2c_imx->irq, i2c_imx);
551fail4: 582fail4:
552 clk_disable(i2c_imx->clk);
553 clk_put(i2c_imx->clk); 583 clk_put(i2c_imx->clk);
554fail3: 584fail3:
555 release_mem_region(i2c_imx->res->start, resource_size(res)); 585 release_mem_region(i2c_imx->res->start, resource_size(res));
@@ -586,8 +616,6 @@ static int __exit i2c_imx_remove(struct platform_device *pdev)
586 if (pdata && pdata->exit) 616 if (pdata && pdata->exit)
587 pdata->exit(&pdev->dev); 617 pdata->exit(&pdev->dev);
588 618
589 /* Disable I2C clock */
590 clk_disable(i2c_imx->clk);
591 clk_put(i2c_imx->clk); 619 clk_put(i2c_imx->clk);
592 620
593 release_mem_region(i2c_imx->res->start, resource_size(i2c_imx->res)); 621 release_mem_region(i2c_imx->res->start, resource_size(i2c_imx->res));
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index a75c75e77b92..5901707fc66a 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -56,12 +56,6 @@ iic_cook_addr(struct i2c_msg *msg)
56 if (msg->flags & I2C_M_RD) 56 if (msg->flags & I2C_M_RD)
57 addr |= 1; 57 addr |= 1;
58 58
59 /*
60 * Read or Write?
61 */
62 if (msg->flags & I2C_M_REV_DIR_ADDR)
63 addr ^= 1;
64
65 return addr; 59 return addr;
66} 60}
67 61
diff --git a/drivers/i2c/busses/i2c-isch.c b/drivers/i2c/busses/i2c-isch.c
index 9f6b8e0f8632..dba6eb053e2f 100644
--- a/drivers/i2c/busses/i2c-isch.c
+++ b/drivers/i2c/busses/i2c-isch.c
@@ -281,7 +281,7 @@ static int __devinit sch_probe(struct pci_dev *dev,
281 return -ENODEV; 281 return -ENODEV;
282 } 282 }
283 if (acpi_check_region(sch_smba, SMBIOSIZE, sch_driver.name)) 283 if (acpi_check_region(sch_smba, SMBIOSIZE, sch_driver.name))
284 return -EBUSY; 284 return -ENODEV;
285 if (!request_region(sch_smba, SMBIOSIZE, sch_driver.name)) { 285 if (!request_region(sch_smba, SMBIOSIZE, sch_driver.name)) {
286 dev_err(&dev->dev, "SMBus region 0x%x already in use!\n", 286 dev_err(&dev->dev, "SMBus region 0x%x already in use!\n",
287 sch_smba); 287 sch_smba);
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index d325e86e3103..f627001108b8 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -365,9 +365,6 @@ static int mpc_write(struct mpc_i2c *i2c, int target,
365 unsigned timeout = i2c->adap.timeout; 365 unsigned timeout = i2c->adap.timeout;
366 u32 flags = restart ? CCR_RSTA : 0; 366 u32 flags = restart ? CCR_RSTA : 0;
367 367
368 /* Start with MEN */
369 if (!restart)
370 writeccr(i2c, CCR_MEN);
371 /* Start as master */ 368 /* Start as master */
372 writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA | CCR_MTX | flags); 369 writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA | CCR_MTX | flags);
373 /* Write target byte */ 370 /* Write target byte */
@@ -396,9 +393,6 @@ static int mpc_read(struct mpc_i2c *i2c, int target,
396 int i, result; 393 int i, result;
397 u32 flags = restart ? CCR_RSTA : 0; 394 u32 flags = restart ? CCR_RSTA : 0;
398 395
399 /* Start with MEN */
400 if (!restart)
401 writeccr(i2c, CCR_MEN);
402 /* Switch to read - restart */ 396 /* Switch to read - restart */
403 writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA | CCR_MTX | flags); 397 writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA | CCR_MTX | flags);
404 /* Write target address byte - this time with the read flag set */ 398 /* Write target address byte - this time with the read flag set */
@@ -425,9 +419,9 @@ static int mpc_read(struct mpc_i2c *i2c, int target,
425 /* Generate txack on next to last byte */ 419 /* Generate txack on next to last byte */
426 if (i == length - 2) 420 if (i == length - 2)
427 writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA | CCR_TXAK); 421 writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA | CCR_TXAK);
428 /* Generate stop on last byte */ 422 /* Do not generate stop on last byte */
429 if (i == length - 1) 423 if (i == length - 1)
430 writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_TXAK); 424 writeccr(i2c, CCR_MIEN | CCR_MEN | CCR_MSTA | CCR_MTX);
431 data[i] = readb(i2c->base + MPC_I2C_DR); 425 data[i] = readb(i2c->base + MPC_I2C_DR);
432 } 426 }
433 427
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index bbab0e166630..ed387ffa4730 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -338,9 +338,6 @@ mv64xxx_i2c_prepare_for_io(struct mv64xxx_i2c_data *drv_data,
338 if (msg->flags & I2C_M_RD) 338 if (msg->flags & I2C_M_RD)
339 dir = 1; 339 dir = 1;
340 340
341 if (msg->flags & I2C_M_REV_DIR_ADDR)
342 dir ^= 1;
343
344 if (msg->flags & I2C_M_TEN) { 341 if (msg->flags & I2C_M_TEN) {
345 drv_data->addr1 = 0xf0 | (((u32)msg->addr & 0x300) >> 7) | dir; 342 drv_data->addr1 = 0xf0 | (((u32)msg->addr & 0x300) >> 7) | dir;
346 drv_data->addr2 = (u32)msg->addr & 0xff; 343 drv_data->addr2 = (u32)msg->addr & 0xff;
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index 827da0858136..75bf3ad18099 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -178,6 +178,12 @@ struct omap_i2c_dev {
178 unsigned b_hw:1; /* bad h/w fixes */ 178 unsigned b_hw:1; /* bad h/w fixes */
179 unsigned idle:1; 179 unsigned idle:1;
180 u16 iestate; /* Saved interrupt register */ 180 u16 iestate; /* Saved interrupt register */
181 u16 pscstate;
182 u16 scllstate;
183 u16 sclhstate;
184 u16 bufstate;
185 u16 syscstate;
186 u16 westate;
181}; 187};
182 188
183static inline void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev, 189static inline void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev,
@@ -230,9 +236,18 @@ static void omap_i2c_unidle(struct omap_i2c_dev *dev)
230 236
231 clk_enable(dev->iclk); 237 clk_enable(dev->iclk);
232 clk_enable(dev->fclk); 238 clk_enable(dev->fclk);
239 if (cpu_is_omap34xx()) {
240 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
241 omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, dev->pscstate);
242 omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, dev->scllstate);
243 omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG, dev->sclhstate);
244 omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, dev->bufstate);
245 omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, dev->syscstate);
246 omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, dev->westate);
247 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
248 }
233 dev->idle = 0; 249 dev->idle = 0;
234 if (dev->iestate) 250 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate);
235 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate);
236} 251}
237 252
238static void omap_i2c_idle(struct omap_i2c_dev *dev) 253static void omap_i2c_idle(struct omap_i2c_dev *dev)
@@ -258,7 +273,7 @@ static void omap_i2c_idle(struct omap_i2c_dev *dev)
258 273
259static int omap_i2c_init(struct omap_i2c_dev *dev) 274static int omap_i2c_init(struct omap_i2c_dev *dev)
260{ 275{
261 u16 psc = 0, scll = 0, sclh = 0; 276 u16 psc = 0, scll = 0, sclh = 0, buf = 0;
262 u16 fsscll = 0, fssclh = 0, hsscll = 0, hssclh = 0; 277 u16 fsscll = 0, fssclh = 0, hsscll = 0, hssclh = 0;
263 unsigned long fclk_rate = 12000000; 278 unsigned long fclk_rate = 12000000;
264 unsigned long timeout; 279 unsigned long timeout;
@@ -287,24 +302,22 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
287 SYSC_AUTOIDLE_MASK); 302 SYSC_AUTOIDLE_MASK);
288 303
289 } else if (dev->rev >= OMAP_I2C_REV_ON_3430) { 304 } else if (dev->rev >= OMAP_I2C_REV_ON_3430) {
290 u32 v; 305 dev->syscstate = SYSC_AUTOIDLE_MASK;
291 306 dev->syscstate |= SYSC_ENAWAKEUP_MASK;
292 v = SYSC_AUTOIDLE_MASK; 307 dev->syscstate |= (SYSC_IDLEMODE_SMART <<
293 v |= SYSC_ENAWAKEUP_MASK;
294 v |= (SYSC_IDLEMODE_SMART <<
295 __ffs(SYSC_SIDLEMODE_MASK)); 308 __ffs(SYSC_SIDLEMODE_MASK));
296 v |= (SYSC_CLOCKACTIVITY_FCLK << 309 dev->syscstate |= (SYSC_CLOCKACTIVITY_FCLK <<
297 __ffs(SYSC_CLOCKACTIVITY_MASK)); 310 __ffs(SYSC_CLOCKACTIVITY_MASK));
298 311
299 omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, v); 312 omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG,
313 dev->syscstate);
300 /* 314 /*
301 * Enabling all wakup sources to stop I2C freezing on 315 * Enabling all wakup sources to stop I2C freezing on
302 * WFI instruction. 316 * WFI instruction.
303 * REVISIT: Some wkup sources might not be needed. 317 * REVISIT: Some wkup sources might not be needed.
304 */ 318 */
305 omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, 319 dev->westate = OMAP_I2C_WE_ALL;
306 OMAP_I2C_WE_ALL); 320 omap_i2c_write_reg(dev, OMAP_I2C_WE_REG, dev->westate);
307
308 } 321 }
309 } 322 }
310 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0); 323 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
@@ -394,23 +407,28 @@ static int omap_i2c_init(struct omap_i2c_dev *dev)
394 omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, scll); 407 omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG, scll);
395 omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG, sclh); 408 omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG, sclh);
396 409
397 if (dev->fifo_size) 410 if (dev->fifo_size) {
398 /* Note: setup required fifo size - 1 */ 411 /* Note: setup required fifo size - 1. RTRSH and XTRSH */
399 omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, 412 buf = (dev->fifo_size - 1) << 8 | OMAP_I2C_BUF_RXFIF_CLR |
400 (dev->fifo_size - 1) << 8 | /* RTRSH */ 413 (dev->fifo_size - 1) | OMAP_I2C_BUF_TXFIF_CLR;
401 OMAP_I2C_BUF_RXFIF_CLR | 414 omap_i2c_write_reg(dev, OMAP_I2C_BUF_REG, buf);
402 (dev->fifo_size - 1) | /* XTRSH */ 415 }
403 OMAP_I2C_BUF_TXFIF_CLR);
404 416
405 /* Take the I2C module out of reset: */ 417 /* Take the I2C module out of reset: */
406 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN); 418 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
407 419
408 /* Enable interrupts */ 420 /* Enable interrupts */
409 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, 421 dev->iestate = (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY |
410 (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY |
411 OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK | 422 OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK |
412 OMAP_I2C_IE_AL) | ((dev->fifo_size) ? 423 OMAP_I2C_IE_AL) | ((dev->fifo_size) ?
413 (OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0)); 424 (OMAP_I2C_IE_RDR | OMAP_I2C_IE_XDR) : 0);
425 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG, dev->iestate);
426 if (cpu_is_omap34xx()) {
427 dev->pscstate = psc;
428 dev->scllstate = scll;
429 dev->sclhstate = sclh;
430 dev->bufstate = buf;
431 }
414 return 0; 432 return 0;
415} 433}
416 434
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index a782c7a08f9e..1e245e9cad31 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -22,7 +22,7 @@
22 Intel PIIX4, 440MX 22 Intel PIIX4, 440MX
23 Serverworks OSB4, CSB5, CSB6, HT-1000, HT-1100 23 Serverworks OSB4, CSB5, CSB6, HT-1000, HT-1100
24 ATI IXP200, IXP300, IXP400, SB600, SB700, SB800 24 ATI IXP200, IXP300, IXP400, SB600, SB700, SB800
25 AMD SB900 25 AMD Hudson-2
26 SMSC Victory66 26 SMSC Victory66
27 27
28 Note: we assume there can only be one device, with one SMBus interface. 28 Note: we assume there can only be one device, with one SMBus interface.
@@ -169,7 +169,7 @@ static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
169 } 169 }
170 170
171 if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) 171 if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name))
172 return -EBUSY; 172 return -ENODEV;
173 173
174 if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) { 174 if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) {
175 dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n", 175 dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n",
@@ -233,9 +233,9 @@ static int __devinit piix4_setup_sb800(struct pci_dev *PIIX4_dev,
233 unsigned short smba_idx = 0xcd6; 233 unsigned short smba_idx = 0xcd6;
234 u8 smba_en_lo, smba_en_hi, i2ccfg, i2ccfg_offset = 0x10, smb_en = 0x2c; 234 u8 smba_en_lo, smba_en_hi, i2ccfg, i2ccfg_offset = 0x10, smb_en = 0x2c;
235 235
236 /* SB800 SMBus does not support forcing address */ 236 /* SB800 and later SMBus does not support forcing address */
237 if (force || force_addr) { 237 if (force || force_addr) {
238 dev_err(&PIIX4_dev->dev, "SB800 SMBus does not support " 238 dev_err(&PIIX4_dev->dev, "SMBus does not support "
239 "forcing address!\n"); 239 "forcing address!\n");
240 return -EINVAL; 240 return -EINVAL;
241 } 241 }
@@ -260,7 +260,7 @@ static int __devinit piix4_setup_sb800(struct pci_dev *PIIX4_dev,
260 260
261 piix4_smba = ((smba_en_hi << 8) | smba_en_lo) & 0xffe0; 261 piix4_smba = ((smba_en_hi << 8) | smba_en_lo) & 0xffe0;
262 if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) 262 if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name))
263 return -EBUSY; 263 return -ENODEV;
264 264
265 if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) { 265 if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) {
266 dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n", 266 dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n",
@@ -480,7 +480,7 @@ static struct pci_device_id piix4_ids[] = {
480 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_SMBUS) }, 480 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP300_SMBUS) },
481 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS) }, 481 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP400_SMBUS) },
482 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS) }, 482 { PCI_DEVICE(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS) },
483 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_SB900_SMBUS) }, 483 { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_HUDSON2_SMBUS) },
484 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, 484 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
485 PCI_DEVICE_ID_SERVERWORKS_OSB4) }, 485 PCI_DEVICE_ID_SERVERWORKS_OSB4) },
486 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS, 486 { PCI_DEVICE(PCI_VENDOR_ID_SERVERWORKS,
diff --git a/drivers/i2c/busses/i2c-pnx.c b/drivers/i2c/busses/i2c-pnx.c
index 6ff6c20f1e78..5d1c2603a130 100644
--- a/drivers/i2c/busses/i2c-pnx.c
+++ b/drivers/i2c/busses/i2c-pnx.c
@@ -19,7 +19,9 @@
19#include <linux/completion.h> 19#include <linux/completion.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/i2c-pnx.h> 21#include <linux/i2c-pnx.h>
22#include <linux/io.h>
22#include <mach/hardware.h> 23#include <mach/hardware.h>
24#include <mach/i2c.h>
23#include <asm/irq.h> 25#include <asm/irq.h>
24#include <asm/uaccess.h> 26#include <asm/uaccess.h>
25 27
@@ -54,6 +56,9 @@ static inline void i2c_pnx_arm_timer(struct i2c_adapter *adap)
54 struct timer_list *timer = &data->mif.timer; 56 struct timer_list *timer = &data->mif.timer;
55 int expires = I2C_PNX_TIMEOUT / (1000 / HZ); 57 int expires = I2C_PNX_TIMEOUT / (1000 / HZ);
56 58
59 if (expires <= 1)
60 expires = 2;
61
57 del_timer_sync(timer); 62 del_timer_sync(timer);
58 63
59 dev_dbg(&adap->dev, "Timer armed at %lu plus %u jiffies.\n", 64 dev_dbg(&adap->dev, "Timer armed at %lu plus %u jiffies.\n",
@@ -633,7 +638,8 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
633 638
634 /* Register this adapter with the I2C subsystem */ 639 /* Register this adapter with the I2C subsystem */
635 i2c_pnx->adapter->dev.parent = &pdev->dev; 640 i2c_pnx->adapter->dev.parent = &pdev->dev;
636 ret = i2c_add_adapter(i2c_pnx->adapter); 641 i2c_pnx->adapter->nr = pdev->id;
642 ret = i2c_add_numbered_adapter(i2c_pnx->adapter);
637 if (ret < 0) { 643 if (ret < 0) {
638 dev_err(&pdev->dev, "I2C: Failed to add bus\n"); 644 dev_err(&pdev->dev, "I2C: Failed to add bus\n");
639 goto out_irq; 645 goto out_irq;
@@ -645,7 +651,7 @@ static int __devinit i2c_pnx_probe(struct platform_device *pdev)
645 return 0; 651 return 0;
646 652
647out_irq: 653out_irq:
648 free_irq(alg_data->irq, alg_data); 654 free_irq(alg_data->irq, i2c_pnx->adapter);
649out_clock: 655out_clock:
650 i2c_pnx->set_clock_stop(pdev); 656 i2c_pnx->set_clock_stop(pdev);
651out_unmap: 657out_unmap:
@@ -664,7 +670,7 @@ static int __devexit i2c_pnx_remove(struct platform_device *pdev)
664 struct i2c_adapter *adap = i2c_pnx->adapter; 670 struct i2c_adapter *adap = i2c_pnx->adapter;
665 struct i2c_pnx_algo_data *alg_data = adap->algo_data; 671 struct i2c_pnx_algo_data *alg_data = adap->algo_data;
666 672
667 free_irq(alg_data->irq, alg_data); 673 free_irq(alg_data->irq, i2c_pnx->adapter);
668 i2c_del_adapter(adap); 674 i2c_del_adapter(adap);
669 i2c_pnx->set_clock_stop(pdev); 675 i2c_pnx->set_clock_stop(pdev);
670 iounmap((void *)alg_data->ioaddr); 676 iounmap((void *)alg_data->ioaddr);
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c
index 3c9d71f60187..1c440a70ec61 100644
--- a/drivers/i2c/busses/i2c-powermac.c
+++ b/drivers/i2c/busses/i2c-powermac.c
@@ -49,48 +49,38 @@ static s32 i2c_powermac_smbus_xfer( struct i2c_adapter* adap,
49 int rc = 0; 49 int rc = 0;
50 int read = (read_write == I2C_SMBUS_READ); 50 int read = (read_write == I2C_SMBUS_READ);
51 int addrdir = (addr << 1) | read; 51 int addrdir = (addr << 1) | read;
52 int mode, subsize, len;
53 u32 subaddr;
54 u8 *buf;
52 u8 local[2]; 55 u8 local[2];
53 56
54 rc = pmac_i2c_open(bus, 0); 57 if (size == I2C_SMBUS_QUICK || size == I2C_SMBUS_BYTE) {
55 if (rc) 58 mode = pmac_i2c_mode_std;
56 return rc; 59 subsize = 0;
60 subaddr = 0;
61 } else {
62 mode = read ? pmac_i2c_mode_combined : pmac_i2c_mode_stdsub;
63 subsize = 1;
64 subaddr = command;
65 }
57 66
58 switch (size) { 67 switch (size) {
59 case I2C_SMBUS_QUICK: 68 case I2C_SMBUS_QUICK:
60 rc = pmac_i2c_setmode(bus, pmac_i2c_mode_std); 69 buf = NULL;
61 if (rc) 70 len = 0;
62 goto bail;
63 rc = pmac_i2c_xfer(bus, addrdir, 0, 0, NULL, 0);
64 break; 71 break;
65 case I2C_SMBUS_BYTE: 72 case I2C_SMBUS_BYTE:
66 rc = pmac_i2c_setmode(bus, pmac_i2c_mode_std);
67 if (rc)
68 goto bail;
69 rc = pmac_i2c_xfer(bus, addrdir, 0, 0, &data->byte, 1);
70 break;
71 case I2C_SMBUS_BYTE_DATA: 73 case I2C_SMBUS_BYTE_DATA:
72 rc = pmac_i2c_setmode(bus, read ? 74 buf = &data->byte;
73 pmac_i2c_mode_combined : 75 len = 1;
74 pmac_i2c_mode_stdsub);
75 if (rc)
76 goto bail;
77 rc = pmac_i2c_xfer(bus, addrdir, 1, command, &data->byte, 1);
78 break; 76 break;
79 case I2C_SMBUS_WORD_DATA: 77 case I2C_SMBUS_WORD_DATA:
80 rc = pmac_i2c_setmode(bus, read ?
81 pmac_i2c_mode_combined :
82 pmac_i2c_mode_stdsub);
83 if (rc)
84 goto bail;
85 if (!read) { 78 if (!read) {
86 local[0] = data->word & 0xff; 79 local[0] = data->word & 0xff;
87 local[1] = (data->word >> 8) & 0xff; 80 local[1] = (data->word >> 8) & 0xff;
88 } 81 }
89 rc = pmac_i2c_xfer(bus, addrdir, 1, command, local, 2); 82 buf = local;
90 if (rc == 0 && read) { 83 len = 2;
91 data->word = ((u16)local[1]) << 8;
92 data->word |= local[0];
93 }
94 break; 84 break;
95 85
96 /* Note that these are broken vs. the expected smbus API where 86 /* Note that these are broken vs. the expected smbus API where
@@ -105,28 +95,44 @@ static s32 i2c_powermac_smbus_xfer( struct i2c_adapter* adap,
105 * a repeat start/addr phase (but not stop in between) 95 * a repeat start/addr phase (but not stop in between)
106 */ 96 */
107 case I2C_SMBUS_BLOCK_DATA: 97 case I2C_SMBUS_BLOCK_DATA:
108 rc = pmac_i2c_setmode(bus, read ? 98 buf = data->block;
109 pmac_i2c_mode_combined : 99 len = data->block[0] + 1;
110 pmac_i2c_mode_stdsub);
111 if (rc)
112 goto bail;
113 rc = pmac_i2c_xfer(bus, addrdir, 1, command, data->block,
114 data->block[0] + 1);
115
116 break; 100 break;
117 case I2C_SMBUS_I2C_BLOCK_DATA: 101 case I2C_SMBUS_I2C_BLOCK_DATA:
118 rc = pmac_i2c_setmode(bus, read ? 102 buf = &data->block[1];
119 pmac_i2c_mode_combined : 103 len = data->block[0];
120 pmac_i2c_mode_stdsub);
121 if (rc)
122 goto bail;
123 rc = pmac_i2c_xfer(bus, addrdir, 1, command,
124 &data->block[1], data->block[0]);
125 break; 104 break;
126 105
127 default: 106 default:
128 rc = -EINVAL; 107 return -EINVAL;
108 }
109
110 rc = pmac_i2c_open(bus, 0);
111 if (rc) {
112 dev_err(&adap->dev, "Failed to open I2C, err %d\n", rc);
113 return rc;
114 }
115
116 rc = pmac_i2c_setmode(bus, mode);
117 if (rc) {
118 dev_err(&adap->dev, "Failed to set I2C mode %d, err %d\n",
119 mode, rc);
120 goto bail;
129 } 121 }
122
123 rc = pmac_i2c_xfer(bus, addrdir, subsize, subaddr, buf, len);
124 if (rc) {
125 dev_err(&adap->dev,
126 "I2C transfer at 0x%02x failed, size %d, err %d\n",
127 addrdir >> 1, size, rc);
128 goto bail;
129 }
130
131 if (size == I2C_SMBUS_WORD_DATA && read) {
132 data->word = ((u16)local[1]) << 8;
133 data->word |= local[0];
134 }
135
130 bail: 136 bail:
131 pmac_i2c_close(bus); 137 pmac_i2c_close(bus);
132 return rc; 138 return rc;
@@ -146,20 +152,33 @@ static int i2c_powermac_master_xfer( struct i2c_adapter *adap,
146 int read; 152 int read;
147 int addrdir; 153 int addrdir;
148 154
155 if (num != 1) {
156 dev_err(&adap->dev,
157 "Multi-message I2C transactions not supported\n");
158 return -EOPNOTSUPP;
159 }
160
149 if (msgs->flags & I2C_M_TEN) 161 if (msgs->flags & I2C_M_TEN)
150 return -EINVAL; 162 return -EINVAL;
151 read = (msgs->flags & I2C_M_RD) != 0; 163 read = (msgs->flags & I2C_M_RD) != 0;
152 addrdir = (msgs->addr << 1) | read; 164 addrdir = (msgs->addr << 1) | read;
153 if (msgs->flags & I2C_M_REV_DIR_ADDR)
154 addrdir ^= 1;
155 165
156 rc = pmac_i2c_open(bus, 0); 166 rc = pmac_i2c_open(bus, 0);
157 if (rc) 167 if (rc) {
168 dev_err(&adap->dev, "Failed to open I2C, err %d\n", rc);
158 return rc; 169 return rc;
170 }
159 rc = pmac_i2c_setmode(bus, pmac_i2c_mode_std); 171 rc = pmac_i2c_setmode(bus, pmac_i2c_mode_std);
160 if (rc) 172 if (rc) {
173 dev_err(&adap->dev, "Failed to set I2C mode %d, err %d\n",
174 pmac_i2c_mode_std, rc);
161 goto bail; 175 goto bail;
176 }
162 rc = pmac_i2c_xfer(bus, addrdir, 0, 0, msgs->buf, msgs->len); 177 rc = pmac_i2c_xfer(bus, addrdir, 0, 0, msgs->buf, msgs->len);
178 if (rc < 0)
179 dev_err(&adap->dev, "I2C %s 0x%02x failed, err %d\n",
180 addrdir & 1 ? "read from" : "write to", addrdir >> 1,
181 rc);
163 bail: 182 bail:
164 pmac_i2c_close(bus); 183 pmac_i2c_close(bus);
165 return rc < 0 ? rc : 1; 184 return rc < 0 ? rc : 1;
@@ -183,19 +202,16 @@ static const struct i2c_algorithm i2c_powermac_algorithm = {
183static int __devexit i2c_powermac_remove(struct platform_device *dev) 202static int __devexit i2c_powermac_remove(struct platform_device *dev)
184{ 203{
185 struct i2c_adapter *adapter = platform_get_drvdata(dev); 204 struct i2c_adapter *adapter = platform_get_drvdata(dev);
186 struct pmac_i2c_bus *bus = i2c_get_adapdata(adapter);
187 int rc; 205 int rc;
188 206
189 rc = i2c_del_adapter(adapter); 207 rc = i2c_del_adapter(adapter);
190 pmac_i2c_detach_adapter(bus, adapter);
191 i2c_set_adapdata(adapter, NULL);
192 /* We aren't that prepared to deal with this... */ 208 /* We aren't that prepared to deal with this... */
193 if (rc) 209 if (rc)
194 printk(KERN_WARNING 210 printk(KERN_WARNING
195 "i2c-powermac.c: Failed to remove bus %s !\n", 211 "i2c-powermac.c: Failed to remove bus %s !\n",
196 adapter->name); 212 adapter->name);
197 platform_set_drvdata(dev, NULL); 213 platform_set_drvdata(dev, NULL);
198 kfree(adapter); 214 memset(adapter, 0, sizeof(*adapter));
199 215
200 return 0; 216 return 0;
201} 217}
@@ -206,12 +222,12 @@ static int __devinit i2c_powermac_probe(struct platform_device *dev)
206 struct pmac_i2c_bus *bus = dev->dev.platform_data; 222 struct pmac_i2c_bus *bus = dev->dev.platform_data;
207 struct device_node *parent = NULL; 223 struct device_node *parent = NULL;
208 struct i2c_adapter *adapter; 224 struct i2c_adapter *adapter;
209 char name[32];
210 const char *basename; 225 const char *basename;
211 int rc; 226 int rc;
212 227
213 if (bus == NULL) 228 if (bus == NULL)
214 return -EINVAL; 229 return -EINVAL;
230 adapter = pmac_i2c_get_adapter(bus);
215 231
216 /* Ok, now we need to make up a name for the interface that will 232 /* Ok, now we need to make up a name for the interface that will
217 * match what we used to do in the past, that is basically the 233 * match what we used to do in the past, that is basically the
@@ -237,29 +253,22 @@ static int __devinit i2c_powermac_probe(struct platform_device *dev)
237 default: 253 default:
238 return -EINVAL; 254 return -EINVAL;
239 } 255 }
240 snprintf(name, 32, "%s %d", basename, pmac_i2c_get_channel(bus)); 256 snprintf(adapter->name, sizeof(adapter->name), "%s %d", basename,
257 pmac_i2c_get_channel(bus));
241 of_node_put(parent); 258 of_node_put(parent);
242 259
243 adapter = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
244 if (adapter == NULL) {
245 printk(KERN_ERR "i2c-powermac: can't allocate inteface !\n");
246 return -ENOMEM;
247 }
248 platform_set_drvdata(dev, adapter); 260 platform_set_drvdata(dev, adapter);
249 strcpy(adapter->name, name);
250 adapter->algo = &i2c_powermac_algorithm; 261 adapter->algo = &i2c_powermac_algorithm;
251 i2c_set_adapdata(adapter, bus); 262 i2c_set_adapdata(adapter, bus);
252 adapter->dev.parent = &dev->dev; 263 adapter->dev.parent = &dev->dev;
253 pmac_i2c_attach_adapter(bus, adapter);
254 rc = i2c_add_adapter(adapter); 264 rc = i2c_add_adapter(adapter);
255 if (rc) { 265 if (rc) {
256 printk(KERN_ERR "i2c-powermac: Adapter %s registration " 266 printk(KERN_ERR "i2c-powermac: Adapter %s registration "
257 "failed\n", name); 267 "failed\n", adapter->name);
258 i2c_set_adapdata(adapter, NULL); 268 memset(adapter, 0, sizeof(*adapter));
259 pmac_i2c_detach_adapter(bus, adapter);
260 } 269 }
261 270
262 printk(KERN_INFO "PowerMac i2c bus %s registered\n", name); 271 printk(KERN_INFO "PowerMac i2c bus %s registered\n", adapter->name);
263 272
264 if (!strncmp(basename, "uni-n", 5)) { 273 if (!strncmp(basename, "uni-n", 5)) {
265 struct device_node *np; 274 struct device_node *np;
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 049555777f67..7647a20523a0 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -1155,7 +1155,7 @@ static int i2c_pxa_resume_noirq(struct device *dev)
1155 return 0; 1155 return 0;
1156} 1156}
1157 1157
1158static struct dev_pm_ops i2c_pxa_dev_pm_ops = { 1158static const struct dev_pm_ops i2c_pxa_dev_pm_ops = {
1159 .suspend_noirq = i2c_pxa_suspend_noirq, 1159 .suspend_noirq = i2c_pxa_suspend_noirq,
1160 .resume_noirq = i2c_pxa_resume_noirq, 1160 .resume_noirq = i2c_pxa_resume_noirq,
1161}; 1161};
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 96aafb91b69a..1d8c98613fa0 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -967,7 +967,7 @@ static int s3c24xx_i2c_resume(struct device *dev)
967 return 0; 967 return 0;
968} 968}
969 969
970static struct dev_pm_ops s3c24xx_i2c_dev_pm_ops = { 970static const struct dev_pm_ops s3c24xx_i2c_dev_pm_ops = {
971 .suspend_noirq = s3c24xx_i2c_suspend_noirq, 971 .suspend_noirq = s3c24xx_i2c_suspend_noirq,
972 .resume = s3c24xx_i2c_resume, 972 .resume = s3c24xx_i2c_resume,
973}; 973};
diff --git a/drivers/i2c/busses/i2c-scmi.c b/drivers/i2c/busses/i2c-scmi.c
index 276a046ac93f..365e0becaf12 100644
--- a/drivers/i2c/busses/i2c-scmi.c
+++ b/drivers/i2c/busses/i2c-scmi.c
@@ -363,15 +363,14 @@ static int acpi_smbus_cmi_add(struct acpi_device *device)
363 smbus_cmi->cap_write = 0; 363 smbus_cmi->cap_write = 0;
364 364
365 acpi_walk_namespace(ACPI_TYPE_METHOD, smbus_cmi->handle, 1, 365 acpi_walk_namespace(ACPI_TYPE_METHOD, smbus_cmi->handle, 1,
366 acpi_smbus_cmi_query_methods, smbus_cmi, NULL); 366 acpi_smbus_cmi_query_methods, NULL, smbus_cmi, NULL);
367 367
368 if (smbus_cmi->cap_info == 0) 368 if (smbus_cmi->cap_info == 0)
369 goto err; 369 goto err;
370 370
371 snprintf(smbus_cmi->adapter.name, sizeof(smbus_cmi->adapter.name), 371 snprintf(smbus_cmi->adapter.name, sizeof(smbus_cmi->adapter.name),
372 "SMBus CMI adapter %s (%s)", 372 "SMBus CMI adapter %s",
373 acpi_device_name(device), 373 acpi_device_name(device));
374 acpi_device_uid(device));
375 smbus_cmi->adapter.owner = THIS_MODULE; 374 smbus_cmi->adapter.owner = THIS_MODULE;
376 smbus_cmi->adapter.algo = &acpi_smbus_cmi_algorithm; 375 smbus_cmi->adapter.algo = &acpi_smbus_cmi_algorithm;
377 smbus_cmi->adapter.algo_data = smbus_cmi; 376 smbus_cmi->adapter.algo_data = smbus_cmi;
diff --git a/drivers/i2c/busses/i2c-sh_mobile.c b/drivers/i2c/busses/i2c-sh_mobile.c
index 86a9d4e81472..ccc46418ef7f 100644
--- a/drivers/i2c/busses/i2c-sh_mobile.c
+++ b/drivers/i2c/busses/i2c-sh_mobile.c
@@ -647,7 +647,7 @@ static int sh_mobile_i2c_runtime_nop(struct device *dev)
647 return 0; 647 return 0;
648} 648}
649 649
650static struct dev_pm_ops sh_mobile_i2c_dev_pm_ops = { 650static const struct dev_pm_ops sh_mobile_i2c_dev_pm_ops = {
651 .runtime_suspend = sh_mobile_i2c_runtime_nop, 651 .runtime_suspend = sh_mobile_i2c_runtime_nop,
652 .runtime_resume = sh_mobile_i2c_runtime_nop, 652 .runtime_resume = sh_mobile_i2c_runtime_nop,
653}; 653};
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index 139f0c7f12a4..844569f7d8b7 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -142,7 +142,7 @@ static void sis5595_write(u8 reg, u8 data)
142 outb(data, sis5595_base + SMB_DAT); 142 outb(data, sis5595_base + SMB_DAT);
143} 143}
144 144
145static int sis5595_setup(struct pci_dev *SIS5595_dev) 145static int __devinit sis5595_setup(struct pci_dev *SIS5595_dev)
146{ 146{
147 u16 a; 147 u16 a;
148 u8 val; 148 u8 val;
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c
index 70ca41e90e58..68cff7af7013 100644
--- a/drivers/i2c/busses/i2c-sis630.c
+++ b/drivers/i2c/busses/i2c-sis630.c
@@ -389,7 +389,7 @@ static u32 sis630_func(struct i2c_adapter *adapter)
389 I2C_FUNC_SMBUS_BLOCK_DATA; 389 I2C_FUNC_SMBUS_BLOCK_DATA;
390} 390}
391 391
392static int sis630_setup(struct pci_dev *sis630_dev) 392static int __devinit sis630_setup(struct pci_dev *sis630_dev)
393{ 393{
394 unsigned char b; 394 unsigned char b;
395 struct pci_dev *dummy = NULL; 395 struct pci_dev *dummy = NULL;
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index 8295885b2fdb..1649963b00dc 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -280,7 +280,7 @@ static int __devinit sis96x_probe(struct pci_dev *dev,
280 280
281 retval = acpi_check_resource_conflict(&dev->resource[SIS96x_BAR]); 281 retval = acpi_check_resource_conflict(&dev->resource[SIS96x_BAR]);
282 if (retval) 282 if (retval)
283 return retval; 283 return -ENODEV;
284 284
285 /* Everything is happy, let's grab the memory and set things up. */ 285 /* Everything is happy, let's grab the memory and set things up. */
286 if (!request_region(sis96x_smbus_base, SMB_IOSIZE, 286 if (!request_region(sis96x_smbus_base, SMB_IOSIZE,
diff --git a/drivers/i2c/busses/i2c-stub.c b/drivers/i2c/busses/i2c-stub.c
index 1b7b2af94036..0c770eabe85e 100644
--- a/drivers/i2c/busses/i2c-stub.c
+++ b/drivers/i2c/busses/i2c-stub.c
@@ -35,6 +35,10 @@ module_param_array(chip_addr, ushort, NULL, S_IRUGO);
35MODULE_PARM_DESC(chip_addr, 35MODULE_PARM_DESC(chip_addr,
36 "Chip addresses (up to 10, between 0x03 and 0x77)"); 36 "Chip addresses (up to 10, between 0x03 and 0x77)");
37 37
38static unsigned long functionality = ~0UL;
39module_param(functionality, ulong, S_IRUGO | S_IWUSR);
40MODULE_PARM_DESC(functionality, "Override functionality bitfield");
41
38struct stub_chip { 42struct stub_chip {
39 u8 pointer; 43 u8 pointer;
40 u16 words[256]; /* Byte operations use the LSB as per SMBus 44 u16 words[256]; /* Byte operations use the LSB as per SMBus
@@ -48,7 +52,7 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
48 char read_write, u8 command, int size, union i2c_smbus_data * data) 52 char read_write, u8 command, int size, union i2c_smbus_data * data)
49{ 53{
50 s32 ret; 54 s32 ret;
51 int i; 55 int i, len;
52 struct stub_chip *chip = NULL; 56 struct stub_chip *chip = NULL;
53 57
54 /* Search for the right chip */ 58 /* Search for the right chip */
@@ -118,6 +122,29 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
118 ret = 0; 122 ret = 0;
119 break; 123 break;
120 124
125 case I2C_SMBUS_I2C_BLOCK_DATA:
126 len = data->block[0];
127 if (read_write == I2C_SMBUS_WRITE) {
128 for (i = 0; i < len; i++) {
129 chip->words[command + i] &= 0xff00;
130 chip->words[command + i] |= data->block[1 + i];
131 }
132 dev_dbg(&adap->dev, "i2c block data - addr 0x%02x, "
133 "wrote %d bytes at 0x%02x.\n",
134 addr, len, command);
135 } else {
136 for (i = 0; i < len; i++) {
137 data->block[1 + i] =
138 chip->words[command + i] & 0xff;
139 }
140 dev_dbg(&adap->dev, "i2c block data - addr 0x%02x, "
141 "read %d bytes at 0x%02x.\n",
142 addr, len, command);
143 }
144
145 ret = 0;
146 break;
147
121 default: 148 default:
122 dev_dbg(&adap->dev, "Unsupported I2C/SMBus command\n"); 149 dev_dbg(&adap->dev, "Unsupported I2C/SMBus command\n");
123 ret = -EOPNOTSUPP; 150 ret = -EOPNOTSUPP;
@@ -129,8 +156,9 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
129 156
130static u32 stub_func(struct i2c_adapter *adapter) 157static u32 stub_func(struct i2c_adapter *adapter)
131{ 158{
132 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 159 return (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
133 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA; 160 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
161 I2C_FUNC_SMBUS_I2C_BLOCK) & functionality;
134} 162}
135 163
136static const struct i2c_algorithm smbus_algorithm = { 164static const struct i2c_algorithm smbus_algorithm = {
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 54d810a4d00f..e4b1543015af 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -365,7 +365,7 @@ static int __devinit vt596_probe(struct pci_dev *pdev,
365found: 365found:
366 error = acpi_check_region(vt596_smba, 8, vt596_driver.name); 366 error = acpi_check_region(vt596_smba, 8, vt596_driver.name);
367 if (error) 367 if (error)
368 return error; 368 return -ENODEV;
369 369
370 if (!request_region(vt596_smba, 8, vt596_driver.name)) { 370 if (!request_region(vt596_smba, 8, vt596_driver.name)) {
371 dev_err(&pdev->dev, "SMBus region 0x%x already in use!\n", 371 dev_err(&pdev->dev, "SMBus region 0x%x already in use!\n",
diff --git a/drivers/i2c/busses/i2c-voodoo3.c b/drivers/i2c/busses/i2c-voodoo3.c
deleted file mode 100644
index 7663d57833a0..000000000000
--- a/drivers/i2c/busses/i2c-voodoo3.c
+++ /dev/null
@@ -1,248 +0,0 @@
1/*
2 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>,
3 Philip Edelbrock <phil@netroedge.com>,
4 Ralph Metzler <rjkm@thp.uni-koeln.de>, and
5 Mark D. Studebaker <mdsxyz123@yahoo.com>
6
7 Based on code written by Ralph Metzler <rjkm@thp.uni-koeln.de> and
8 Simon Vogl
9
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23*/
24
25/* This interfaces to the I2C bus of the Voodoo3 to gain access to
26 the BT869 and possibly other I2C devices. */
27
28#include <linux/kernel.h>
29#include <linux/module.h>
30#include <linux/init.h>
31#include <linux/pci.h>
32#include <linux/i2c.h>
33#include <linux/i2c-algo-bit.h>
34#include <asm/io.h>
35
36/* the only registers we use */
37#define REG 0x78
38#define REG2 0x70
39
40/* bit locations in the register */
41#define DDC_ENAB 0x00040000
42#define DDC_SCL_OUT 0x00080000
43#define DDC_SDA_OUT 0x00100000
44#define DDC_SCL_IN 0x00200000
45#define DDC_SDA_IN 0x00400000
46#define I2C_ENAB 0x00800000
47#define I2C_SCL_OUT 0x01000000
48#define I2C_SDA_OUT 0x02000000
49#define I2C_SCL_IN 0x04000000
50#define I2C_SDA_IN 0x08000000
51
52/* initialization states */
53#define INIT2 0x2
54#define INIT3 0x4
55
56/* delays */
57#define CYCLE_DELAY 10
58#define TIMEOUT (HZ / 2)
59
60
61static void __iomem *ioaddr;
62
63/* The voo GPIO registers don't have individual masks for each bit
64 so we always have to read before writing. */
65
66static void bit_vooi2c_setscl(void *data, int val)
67{
68 unsigned int r;
69 r = readl(ioaddr + REG);
70 if (val)
71 r |= I2C_SCL_OUT;
72 else
73 r &= ~I2C_SCL_OUT;
74 writel(r, ioaddr + REG);
75 readl(ioaddr + REG); /* flush posted write */
76}
77
78static void bit_vooi2c_setsda(void *data, int val)
79{
80 unsigned int r;
81 r = readl(ioaddr + REG);
82 if (val)
83 r |= I2C_SDA_OUT;
84 else
85 r &= ~I2C_SDA_OUT;
86 writel(r, ioaddr + REG);
87 readl(ioaddr + REG); /* flush posted write */
88}
89
90/* The GPIO pins are open drain, so the pins always remain outputs.
91 We rely on the i2c-algo-bit routines to set the pins high before
92 reading the input from other chips. */
93
94static int bit_vooi2c_getscl(void *data)
95{
96 return (0 != (readl(ioaddr + REG) & I2C_SCL_IN));
97}
98
99static int bit_vooi2c_getsda(void *data)
100{
101 return (0 != (readl(ioaddr + REG) & I2C_SDA_IN));
102}
103
104static void bit_vooddc_setscl(void *data, int val)
105{
106 unsigned int r;
107 r = readl(ioaddr + REG);
108 if (val)
109 r |= DDC_SCL_OUT;
110 else
111 r &= ~DDC_SCL_OUT;
112 writel(r, ioaddr + REG);
113 readl(ioaddr + REG); /* flush posted write */
114}
115
116static void bit_vooddc_setsda(void *data, int val)
117{
118 unsigned int r;
119 r = readl(ioaddr + REG);
120 if (val)
121 r |= DDC_SDA_OUT;
122 else
123 r &= ~DDC_SDA_OUT;
124 writel(r, ioaddr + REG);
125 readl(ioaddr + REG); /* flush posted write */
126}
127
128static int bit_vooddc_getscl(void *data)
129{
130 return (0 != (readl(ioaddr + REG) & DDC_SCL_IN));
131}
132
133static int bit_vooddc_getsda(void *data)
134{
135 return (0 != (readl(ioaddr + REG) & DDC_SDA_IN));
136}
137
138static int config_v3(struct pci_dev *dev)
139{
140 unsigned long cadr;
141
142 /* map Voodoo3 memory */
143 cadr = dev->resource[0].start;
144 cadr &= PCI_BASE_ADDRESS_MEM_MASK;
145 ioaddr = ioremap_nocache(cadr, 0x1000);
146 if (ioaddr) {
147 writel(0x8160, ioaddr + REG2);
148 writel(0xcffc0020, ioaddr + REG);
149 dev_info(&dev->dev, "Using Banshee/Voodoo3 I2C device at %p\n", ioaddr);
150 return 0;
151 }
152 return -ENODEV;
153}
154
155static struct i2c_algo_bit_data voo_i2c_bit_data = {
156 .setsda = bit_vooi2c_setsda,
157 .setscl = bit_vooi2c_setscl,
158 .getsda = bit_vooi2c_getsda,
159 .getscl = bit_vooi2c_getscl,
160 .udelay = CYCLE_DELAY,
161 .timeout = TIMEOUT
162};
163
164static struct i2c_adapter voodoo3_i2c_adapter = {
165 .owner = THIS_MODULE,
166 .name = "I2C Voodoo3/Banshee adapter",
167 .algo_data = &voo_i2c_bit_data,
168};
169
170static struct i2c_algo_bit_data voo_ddc_bit_data = {
171 .setsda = bit_vooddc_setsda,
172 .setscl = bit_vooddc_setscl,
173 .getsda = bit_vooddc_getsda,
174 .getscl = bit_vooddc_getscl,
175 .udelay = CYCLE_DELAY,
176 .timeout = TIMEOUT
177};
178
179static struct i2c_adapter voodoo3_ddc_adapter = {
180 .owner = THIS_MODULE,
181 .class = I2C_CLASS_DDC,
182 .name = "DDC Voodoo3/Banshee adapter",
183 .algo_data = &voo_ddc_bit_data,
184};
185
186static struct pci_device_id voodoo3_ids[] __devinitdata = {
187 { PCI_DEVICE(PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_VOODOO3) },
188 { PCI_DEVICE(PCI_VENDOR_ID_3DFX, PCI_DEVICE_ID_3DFX_BANSHEE) },
189 { 0, }
190};
191
192MODULE_DEVICE_TABLE (pci, voodoo3_ids);
193
194static int __devinit voodoo3_probe(struct pci_dev *dev, const struct pci_device_id *id)
195{
196 int retval;
197
198 retval = config_v3(dev);
199 if (retval)
200 return retval;
201
202 /* set up the sysfs linkage to our parent device */
203 voodoo3_i2c_adapter.dev.parent = &dev->dev;
204 voodoo3_ddc_adapter.dev.parent = &dev->dev;
205
206 retval = i2c_bit_add_bus(&voodoo3_i2c_adapter);
207 if (retval)
208 return retval;
209 retval = i2c_bit_add_bus(&voodoo3_ddc_adapter);
210 if (retval)
211 i2c_del_adapter(&voodoo3_i2c_adapter);
212 return retval;
213}
214
215static void __devexit voodoo3_remove(struct pci_dev *dev)
216{
217 i2c_del_adapter(&voodoo3_i2c_adapter);
218 i2c_del_adapter(&voodoo3_ddc_adapter);
219 iounmap(ioaddr);
220}
221
222static struct pci_driver voodoo3_driver = {
223 .name = "voodoo3_smbus",
224 .id_table = voodoo3_ids,
225 .probe = voodoo3_probe,
226 .remove = __devexit_p(voodoo3_remove),
227};
228
229static int __init i2c_voodoo3_init(void)
230{
231 return pci_register_driver(&voodoo3_driver);
232}
233
234static void __exit i2c_voodoo3_exit(void)
235{
236 pci_unregister_driver(&voodoo3_driver);
237}
238
239
240MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
241 "Philip Edelbrock <phil@netroedge.com>, "
242 "Ralph Metzler <rjkm@thp.uni-koeln.de>, "
243 "and Mark D. Studebaker <mdsxyz123@yahoo.com>");
244MODULE_DESCRIPTION("Voodoo3 I2C/SMBus driver");
245MODULE_LICENSE("GPL");
246
247module_init(i2c_voodoo3_init);
248module_exit(i2c_voodoo3_exit);
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index f9618f4d4e47..ae4539d99bef 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -6,16 +6,6 @@
6 6
7menu "Miscellaneous I2C Chip support" 7menu "Miscellaneous I2C Chip support"
8 8
9config DS1682
10 tristate "Dallas DS1682 Total Elapsed Time Recorder with Alarm"
11 depends on EXPERIMENTAL
12 help
13 If you say yes here you get support for Dallas Semiconductor
14 DS1682 Total Elapsed Time Recorder.
15
16 This driver can also be built as a module. If so, the module
17 will be called ds1682.
18
19config SENSORS_TSL2550 9config SENSORS_TSL2550
20 tristate "Taos TSL2550 ambient light sensor" 10 tristate "Taos TSL2550 ambient light sensor"
21 depends on EXPERIMENTAL 11 depends on EXPERIMENTAL
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile
index 749cf3606294..fe0af0f81f2d 100644
--- a/drivers/i2c/chips/Makefile
+++ b/drivers/i2c/chips/Makefile
@@ -10,7 +10,6 @@
10# * I/O expander drivers go to drivers/gpio 10# * I/O expander drivers go to drivers/gpio
11# 11#
12 12
13obj-$(CONFIG_DS1682) += ds1682.o
14obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o 13obj-$(CONFIG_SENSORS_TSL2550) += tsl2550.o
15 14
16ifeq ($(CONFIG_I2C_DEBUG_CHIP),y) 15ifeq ($(CONFIG_I2C_DEBUG_CHIP),y)
diff --git a/drivers/i2c/chips/ds1682.c b/drivers/i2c/chips/ds1682.c
deleted file mode 100644
index f3ee4a1abb77..000000000000
--- a/drivers/i2c/chips/ds1682.c
+++ /dev/null
@@ -1,267 +0,0 @@
1/*
2 * Dallas Semiconductor DS1682 Elapsed Time Recorder device driver
3 *
4 * Written by: Grant Likely <grant.likely@secretlab.ca>
5 *
6 * Copyright (C) 2007 Secret Lab Technologies Ltd.
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13/*
14 * The DS1682 elapsed timer recorder is a simple device that implements
15 * one elapsed time counter, one event counter, an alarm signal and 10
16 * bytes of general purpose EEPROM.
17 *
18 * This driver provides access to the DS1682 counters and user data via
19 * the sysfs. The following attributes are added to the device node:
20 * elapsed_time (u32): Total elapsed event time in ms resolution
21 * alarm_time (u32): When elapsed time exceeds the value in alarm_time,
22 * then the alarm pin is asserted.
23 * event_count (u16): number of times the event pin has gone low.
24 * eeprom (u8[10]): general purpose EEPROM
25 *
26 * Counter registers and user data are both read/write unless the device
27 * has been write protected. This driver does not support turning off write
28 * protection. Once write protection is turned on, it is impossible to
29 * turn it off again, so I have left the feature out of this driver to avoid
30 * accidental enabling, but it is trivial to add write protect support.
31 *
32 */
33
34#include <linux/module.h>
35#include <linux/init.h>
36#include <linux/slab.h>
37#include <linux/i2c.h>
38#include <linux/string.h>
39#include <linux/list.h>
40#include <linux/sysfs.h>
41#include <linux/ctype.h>
42#include <linux/hwmon-sysfs.h>
43
44/* Device registers */
45#define DS1682_REG_CONFIG 0x00
46#define DS1682_REG_ALARM 0x01
47#define DS1682_REG_ELAPSED 0x05
48#define DS1682_REG_EVT_CNTR 0x09
49#define DS1682_REG_EEPROM 0x0b
50#define DS1682_REG_RESET 0x1d
51#define DS1682_REG_WRITE_DISABLE 0x1e
52#define DS1682_REG_WRITE_MEM_DISABLE 0x1f
53
54#define DS1682_EEPROM_SIZE 10
55
56/*
57 * Generic counter attributes
58 */
59static ssize_t ds1682_show(struct device *dev, struct device_attribute *attr,
60 char *buf)
61{
62 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
63 struct i2c_client *client = to_i2c_client(dev);
64 __le32 val = 0;
65 int rc;
66
67 dev_dbg(dev, "ds1682_show() called on %s\n", attr->attr.name);
68
69 /* Read the register */
70 rc = i2c_smbus_read_i2c_block_data(client, sattr->index, sattr->nr,
71 (u8 *) & val);
72 if (rc < 0)
73 return -EIO;
74
75 /* Special case: the 32 bit regs are time values with 1/4s
76 * resolution, scale them up to milliseconds */
77 if (sattr->nr == 4)
78 return sprintf(buf, "%llu\n",
79 ((unsigned long long)le32_to_cpu(val)) * 250);
80
81 /* Format the output string and return # of bytes */
82 return sprintf(buf, "%li\n", (long)le32_to_cpu(val));
83}
84
85static ssize_t ds1682_store(struct device *dev, struct device_attribute *attr,
86 const char *buf, size_t count)
87{
88 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
89 struct i2c_client *client = to_i2c_client(dev);
90 char *endp;
91 u64 val;
92 __le32 val_le;
93 int rc;
94
95 dev_dbg(dev, "ds1682_store() called on %s\n", attr->attr.name);
96
97 /* Decode input */
98 val = simple_strtoull(buf, &endp, 0);
99 if (buf == endp) {
100 dev_dbg(dev, "input string not a number\n");
101 return -EINVAL;
102 }
103
104 /* Special case: the 32 bit regs are time values with 1/4s
105 * resolution, scale input down to quarter-seconds */
106 if (sattr->nr == 4)
107 do_div(val, 250);
108
109 /* write out the value */
110 val_le = cpu_to_le32(val);
111 rc = i2c_smbus_write_i2c_block_data(client, sattr->index, sattr->nr,
112 (u8 *) & val_le);
113 if (rc < 0) {
114 dev_err(dev, "register write failed; reg=0x%x, size=%i\n",
115 sattr->index, sattr->nr);
116 return -EIO;
117 }
118
119 return count;
120}
121
122/*
123 * Simple register attributes
124 */
125static SENSOR_DEVICE_ATTR_2(elapsed_time, S_IRUGO | S_IWUSR, ds1682_show,
126 ds1682_store, 4, DS1682_REG_ELAPSED);
127static SENSOR_DEVICE_ATTR_2(alarm_time, S_IRUGO | S_IWUSR, ds1682_show,
128 ds1682_store, 4, DS1682_REG_ALARM);
129static SENSOR_DEVICE_ATTR_2(event_count, S_IRUGO | S_IWUSR, ds1682_show,
130 ds1682_store, 2, DS1682_REG_EVT_CNTR);
131
132static const struct attribute_group ds1682_group = {
133 .attrs = (struct attribute *[]) {
134 &sensor_dev_attr_elapsed_time.dev_attr.attr,
135 &sensor_dev_attr_alarm_time.dev_attr.attr,
136 &sensor_dev_attr_event_count.dev_attr.attr,
137 NULL,
138 },
139};
140
141/*
142 * User data attribute
143 */
144static ssize_t ds1682_eeprom_read(struct kobject *kobj, struct bin_attribute *attr,
145 char *buf, loff_t off, size_t count)
146{
147 struct i2c_client *client = kobj_to_i2c_client(kobj);
148 int rc;
149
150 dev_dbg(&client->dev, "ds1682_eeprom_read(p=%p, off=%lli, c=%zi)\n",
151 buf, off, count);
152
153 if (off >= DS1682_EEPROM_SIZE)
154 return 0;
155
156 if (off + count > DS1682_EEPROM_SIZE)
157 count = DS1682_EEPROM_SIZE - off;
158
159 rc = i2c_smbus_read_i2c_block_data(client, DS1682_REG_EEPROM + off,
160 count, buf);
161 if (rc < 0)
162 return -EIO;
163
164 return count;
165}
166
167static ssize_t ds1682_eeprom_write(struct kobject *kobj, struct bin_attribute *attr,
168 char *buf, loff_t off, size_t count)
169{
170 struct i2c_client *client = kobj_to_i2c_client(kobj);
171
172 dev_dbg(&client->dev, "ds1682_eeprom_write(p=%p, off=%lli, c=%zi)\n",
173 buf, off, count);
174
175 if (off >= DS1682_EEPROM_SIZE)
176 return -ENOSPC;
177
178 if (off + count > DS1682_EEPROM_SIZE)
179 count = DS1682_EEPROM_SIZE - off;
180
181 /* Write out to the device */
182 if (i2c_smbus_write_i2c_block_data(client, DS1682_REG_EEPROM + off,
183 count, buf) < 0)
184 return -EIO;
185
186 return count;
187}
188
189static struct bin_attribute ds1682_eeprom_attr = {
190 .attr = {
191 .name = "eeprom",
192 .mode = S_IRUGO | S_IWUSR,
193 },
194 .size = DS1682_EEPROM_SIZE,
195 .read = ds1682_eeprom_read,
196 .write = ds1682_eeprom_write,
197};
198
199/*
200 * Called when a ds1682 device is matched with this driver
201 */
202static int ds1682_probe(struct i2c_client *client,
203 const struct i2c_device_id *id)
204{
205 int rc;
206
207 if (!i2c_check_functionality(client->adapter,
208 I2C_FUNC_SMBUS_I2C_BLOCK)) {
209 dev_err(&client->dev, "i2c bus does not support the ds1682\n");
210 rc = -ENODEV;
211 goto exit;
212 }
213
214 rc = sysfs_create_group(&client->dev.kobj, &ds1682_group);
215 if (rc)
216 goto exit;
217
218 rc = sysfs_create_bin_file(&client->dev.kobj, &ds1682_eeprom_attr);
219 if (rc)
220 goto exit_bin_attr;
221
222 return 0;
223
224 exit_bin_attr:
225 sysfs_remove_group(&client->dev.kobj, &ds1682_group);
226 exit:
227 return rc;
228}
229
230static int ds1682_remove(struct i2c_client *client)
231{
232 sysfs_remove_bin_file(&client->dev.kobj, &ds1682_eeprom_attr);
233 sysfs_remove_group(&client->dev.kobj, &ds1682_group);
234 return 0;
235}
236
237static const struct i2c_device_id ds1682_id[] = {
238 { "ds1682", 0 },
239 { }
240};
241MODULE_DEVICE_TABLE(i2c, ds1682_id);
242
243static struct i2c_driver ds1682_driver = {
244 .driver = {
245 .name = "ds1682",
246 },
247 .probe = ds1682_probe,
248 .remove = ds1682_remove,
249 .id_table = ds1682_id,
250};
251
252static int __init ds1682_init(void)
253{
254 return i2c_add_driver(&ds1682_driver);
255}
256
257static void __exit ds1682_exit(void)
258{
259 i2c_del_driver(&ds1682_driver);
260}
261
262MODULE_AUTHOR("Grant Likely <grant.likely@secretlab.ca>");
263MODULE_DESCRIPTION("DS1682 Elapsed Time Indicator driver");
264MODULE_LICENSE("GPL");
265
266module_init(ds1682_init);
267module_exit(ds1682_exit);
diff --git a/drivers/i2c/chips/tsl2550.c b/drivers/i2c/chips/tsl2550.c
index aa96bd2d27ea..a0702f36a72f 100644
--- a/drivers/i2c/chips/tsl2550.c
+++ b/drivers/i2c/chips/tsl2550.c
@@ -257,6 +257,7 @@ static DEVICE_ATTR(operating_mode, S_IWUSR | S_IRUGO,
257 257
258static ssize_t __tsl2550_show_lux(struct i2c_client *client, char *buf) 258static ssize_t __tsl2550_show_lux(struct i2c_client *client, char *buf)
259{ 259{
260 struct tsl2550_data *data = i2c_get_clientdata(client);
260 u8 ch0, ch1; 261 u8 ch0, ch1;
261 int ret; 262 int ret;
262 263
@@ -274,6 +275,8 @@ static ssize_t __tsl2550_show_lux(struct i2c_client *client, char *buf)
274 ret = tsl2550_calculate_lux(ch0, ch1); 275 ret = tsl2550_calculate_lux(ch0, ch1);
275 if (ret < 0) 276 if (ret < 0)
276 return ret; 277 return ret;
278 if (data->operating_mode == 1)
279 ret *= 5;
277 280
278 return sprintf(buf, "%d\n", ret); 281 return sprintf(buf, "%d\n", ret);
279} 282}
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 8d80fceca6a4..0ac2f90ab840 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -155,6 +155,35 @@ static void i2c_device_shutdown(struct device *dev)
155 driver->shutdown(client); 155 driver->shutdown(client);
156} 156}
157 157
158#ifdef CONFIG_SUSPEND
159static int i2c_device_pm_suspend(struct device *dev)
160{
161 const struct dev_pm_ops *pm;
162
163 if (!dev->driver)
164 return 0;
165 pm = dev->driver->pm;
166 if (!pm || !pm->suspend)
167 return 0;
168 return pm->suspend(dev);
169}
170
171static int i2c_device_pm_resume(struct device *dev)
172{
173 const struct dev_pm_ops *pm;
174
175 if (!dev->driver)
176 return 0;
177 pm = dev->driver->pm;
178 if (!pm || !pm->resume)
179 return 0;
180 return pm->resume(dev);
181}
182#else
183#define i2c_device_pm_suspend NULL
184#define i2c_device_pm_resume NULL
185#endif
186
158static int i2c_device_suspend(struct device *dev, pm_message_t mesg) 187static int i2c_device_suspend(struct device *dev, pm_message_t mesg)
159{ 188{
160 struct i2c_client *client = i2c_verify_client(dev); 189 struct i2c_client *client = i2c_verify_client(dev);
@@ -219,6 +248,11 @@ static const struct attribute_group *i2c_dev_attr_groups[] = {
219 NULL 248 NULL
220}; 249};
221 250
251const static struct dev_pm_ops i2c_device_pm_ops = {
252 .suspend = i2c_device_pm_suspend,
253 .resume = i2c_device_pm_resume,
254};
255
222struct bus_type i2c_bus_type = { 256struct bus_type i2c_bus_type = {
223 .name = "i2c", 257 .name = "i2c",
224 .match = i2c_device_match, 258 .match = i2c_device_match,
@@ -227,6 +261,7 @@ struct bus_type i2c_bus_type = {
227 .shutdown = i2c_device_shutdown, 261 .shutdown = i2c_device_shutdown,
228 .suspend = i2c_device_suspend, 262 .suspend = i2c_device_suspend,
229 .resume = i2c_device_resume, 263 .resume = i2c_device_resume,
264 .pm = &i2c_device_pm_ops,
230}; 265};
231EXPORT_SYMBOL_GPL(i2c_bus_type); 266EXPORT_SYMBOL_GPL(i2c_bus_type);
232 267
@@ -558,11 +593,9 @@ static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
558 up_read(&__i2c_board_lock); 593 up_read(&__i2c_board_lock);
559} 594}
560 595
561static int i2c_do_add_adapter(struct device_driver *d, void *data) 596static int i2c_do_add_adapter(struct i2c_driver *driver,
597 struct i2c_adapter *adap)
562{ 598{
563 struct i2c_driver *driver = to_i2c_driver(d);
564 struct i2c_adapter *adap = data;
565
566 /* Detect supported devices on that bus, and instantiate them */ 599 /* Detect supported devices on that bus, and instantiate them */
567 i2c_detect(adap, driver); 600 i2c_detect(adap, driver);
568 601
@@ -574,6 +607,11 @@ static int i2c_do_add_adapter(struct device_driver *d, void *data)
574 return 0; 607 return 0;
575} 608}
576 609
610static int __process_new_adapter(struct device_driver *d, void *data)
611{
612 return i2c_do_add_adapter(to_i2c_driver(d), data);
613}
614
577static int i2c_register_adapter(struct i2c_adapter *adap) 615static int i2c_register_adapter(struct i2c_adapter *adap)
578{ 616{
579 int res = 0, dummy; 617 int res = 0, dummy;
@@ -584,7 +622,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
584 goto out_list; 622 goto out_list;
585 } 623 }
586 624
587 mutex_init(&adap->bus_lock); 625 rt_mutex_init(&adap->bus_lock);
588 626
589 /* Set default timeout to 1 second if not already set */ 627 /* Set default timeout to 1 second if not already set */
590 if (adap->timeout == 0) 628 if (adap->timeout == 0)
@@ -614,7 +652,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
614 /* Notify drivers */ 652 /* Notify drivers */
615 mutex_lock(&core_lock); 653 mutex_lock(&core_lock);
616 dummy = bus_for_each_drv(&i2c_bus_type, NULL, adap, 654 dummy = bus_for_each_drv(&i2c_bus_type, NULL, adap,
617 i2c_do_add_adapter); 655 __process_new_adapter);
618 mutex_unlock(&core_lock); 656 mutex_unlock(&core_lock);
619 657
620 return 0; 658 return 0;
@@ -715,10 +753,9 @@ retry:
715} 753}
716EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter); 754EXPORT_SYMBOL_GPL(i2c_add_numbered_adapter);
717 755
718static int i2c_do_del_adapter(struct device_driver *d, void *data) 756static int i2c_do_del_adapter(struct i2c_driver *driver,
757 struct i2c_adapter *adapter)
719{ 758{
720 struct i2c_driver *driver = to_i2c_driver(d);
721 struct i2c_adapter *adapter = data;
722 struct i2c_client *client, *_n; 759 struct i2c_client *client, *_n;
723 int res; 760 int res;
724 761
@@ -750,6 +787,11 @@ static int __unregister_client(struct device *dev, void *dummy)
750 return 0; 787 return 0;
751} 788}
752 789
790static int __process_removed_adapter(struct device_driver *d, void *data)
791{
792 return i2c_do_del_adapter(to_i2c_driver(d), data);
793}
794
753/** 795/**
754 * i2c_del_adapter - unregister I2C adapter 796 * i2c_del_adapter - unregister I2C adapter
755 * @adap: the adapter being unregistered 797 * @adap: the adapter being unregistered
@@ -762,6 +804,7 @@ int i2c_del_adapter(struct i2c_adapter *adap)
762{ 804{
763 int res = 0; 805 int res = 0;
764 struct i2c_adapter *found; 806 struct i2c_adapter *found;
807 struct i2c_client *client, *next;
765 808
766 /* First make sure that this adapter was ever added */ 809 /* First make sure that this adapter was ever added */
767 mutex_lock(&core_lock); 810 mutex_lock(&core_lock);
@@ -776,11 +819,21 @@ int i2c_del_adapter(struct i2c_adapter *adap)
776 /* Tell drivers about this removal */ 819 /* Tell drivers about this removal */
777 mutex_lock(&core_lock); 820 mutex_lock(&core_lock);
778 res = bus_for_each_drv(&i2c_bus_type, NULL, adap, 821 res = bus_for_each_drv(&i2c_bus_type, NULL, adap,
779 i2c_do_del_adapter); 822 __process_removed_adapter);
780 mutex_unlock(&core_lock); 823 mutex_unlock(&core_lock);
781 if (res) 824 if (res)
782 return res; 825 return res;
783 826
827 /* Remove devices instantiated from sysfs */
828 list_for_each_entry_safe(client, next, &userspace_devices, detected) {
829 if (client->adapter == adap) {
830 dev_dbg(&adap->dev, "Removing %s at 0x%x\n",
831 client->name, client->addr);
832 list_del(&client->detected);
833 i2c_unregister_device(client);
834 }
835 }
836
784 /* Detach any active clients. This can't fail, thus we do not 837 /* Detach any active clients. This can't fail, thus we do not
785 checking the returned value. */ 838 checking the returned value. */
786 res = device_for_each_child(&adap->dev, NULL, __unregister_client); 839 res = device_for_each_child(&adap->dev, NULL, __unregister_client);
@@ -815,22 +868,11 @@ EXPORT_SYMBOL(i2c_del_adapter);
815 868
816/* ------------------------------------------------------------------------- */ 869/* ------------------------------------------------------------------------- */
817 870
818static int __attach_adapter(struct device *dev, void *data) 871static int __process_new_driver(struct device *dev, void *data)
819{ 872{
820 struct i2c_adapter *adapter;
821 struct i2c_driver *driver = data;
822
823 if (dev->type != &i2c_adapter_type) 873 if (dev->type != &i2c_adapter_type)
824 return 0; 874 return 0;
825 adapter = to_i2c_adapter(dev); 875 return i2c_do_add_adapter(data, to_i2c_adapter(dev));
826
827 i2c_detect(adapter, driver);
828
829 /* Legacy drivers scan i2c busses directly */
830 if (driver->attach_adapter)
831 driver->attach_adapter(adapter);
832
833 return 0;
834} 876}
835 877
836/* 878/*
@@ -862,40 +904,18 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
862 INIT_LIST_HEAD(&driver->clients); 904 INIT_LIST_HEAD(&driver->clients);
863 /* Walk the adapters that are already present */ 905 /* Walk the adapters that are already present */
864 mutex_lock(&core_lock); 906 mutex_lock(&core_lock);
865 bus_for_each_dev(&i2c_bus_type, NULL, driver, __attach_adapter); 907 bus_for_each_dev(&i2c_bus_type, NULL, driver, __process_new_driver);
866 mutex_unlock(&core_lock); 908 mutex_unlock(&core_lock);
867 909
868 return 0; 910 return 0;
869} 911}
870EXPORT_SYMBOL(i2c_register_driver); 912EXPORT_SYMBOL(i2c_register_driver);
871 913
872static int __detach_adapter(struct device *dev, void *data) 914static int __process_removed_driver(struct device *dev, void *data)
873{ 915{
874 struct i2c_adapter *adapter;
875 struct i2c_driver *driver = data;
876 struct i2c_client *client, *_n;
877
878 if (dev->type != &i2c_adapter_type) 916 if (dev->type != &i2c_adapter_type)
879 return 0; 917 return 0;
880 adapter = to_i2c_adapter(dev); 918 return i2c_do_del_adapter(data, to_i2c_adapter(dev));
881
882 /* Remove the devices we created ourselves as the result of hardware
883 * probing (using a driver's detect method) */
884 list_for_each_entry_safe(client, _n, &driver->clients, detected) {
885 dev_dbg(&adapter->dev, "Removing %s at 0x%x\n",
886 client->name, client->addr);
887 list_del(&client->detected);
888 i2c_unregister_device(client);
889 }
890
891 if (driver->detach_adapter) {
892 if (driver->detach_adapter(adapter))
893 dev_err(&adapter->dev,
894 "detach_adapter failed for driver [%s]\n",
895 driver->driver.name);
896 }
897
898 return 0;
899} 919}
900 920
901/** 921/**
@@ -906,7 +926,7 @@ static int __detach_adapter(struct device *dev, void *data)
906void i2c_del_driver(struct i2c_driver *driver) 926void i2c_del_driver(struct i2c_driver *driver)
907{ 927{
908 mutex_lock(&core_lock); 928 mutex_lock(&core_lock);
909 bus_for_each_dev(&i2c_bus_type, NULL, driver, __detach_adapter); 929 bus_for_each_dev(&i2c_bus_type, NULL, driver, __process_removed_driver);
910 mutex_unlock(&core_lock); 930 mutex_unlock(&core_lock);
911 931
912 driver_unregister(&driver->driver); 932 driver_unregister(&driver->driver);
@@ -1081,12 +1101,12 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
1081#endif 1101#endif
1082 1102
1083 if (in_atomic() || irqs_disabled()) { 1103 if (in_atomic() || irqs_disabled()) {
1084 ret = mutex_trylock(&adap->bus_lock); 1104 ret = rt_mutex_trylock(&adap->bus_lock);
1085 if (!ret) 1105 if (!ret)
1086 /* I2C activity is ongoing. */ 1106 /* I2C activity is ongoing. */
1087 return -EAGAIN; 1107 return -EAGAIN;
1088 } else { 1108 } else {
1089 mutex_lock_nested(&adap->bus_lock, adap->level); 1109 rt_mutex_lock(&adap->bus_lock);
1090 } 1110 }
1091 1111
1092 /* Retry automatically on arbitration loss */ 1112 /* Retry automatically on arbitration loss */
@@ -1098,7 +1118,7 @@ int i2c_transfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
1098 if (time_after(jiffies, orig_jiffies + adap->timeout)) 1118 if (time_after(jiffies, orig_jiffies + adap->timeout))
1099 break; 1119 break;
1100 } 1120 }
1101 mutex_unlock(&adap->bus_lock); 1121 rt_mutex_unlock(&adap->bus_lock);
1102 1122
1103 return ret; 1123 return ret;
1104 } else { 1124 } else {
@@ -1169,7 +1189,7 @@ EXPORT_SYMBOL(i2c_master_recv);
1169 * ---------------------------------------------------- 1189 * ----------------------------------------------------
1170 */ 1190 */
1171 1191
1172static int i2c_detect_address(struct i2c_client *temp_client, int kind, 1192static int i2c_detect_address(struct i2c_client *temp_client,
1173 struct i2c_driver *driver) 1193 struct i2c_driver *driver)
1174{ 1194{
1175 struct i2c_board_info info; 1195 struct i2c_board_info info;
@@ -1188,22 +1208,18 @@ static int i2c_detect_address(struct i2c_client *temp_client, int kind,
1188 if (i2c_check_addr(adapter, addr)) 1208 if (i2c_check_addr(adapter, addr))
1189 return 0; 1209 return 0;
1190 1210
1191 /* Make sure there is something at this address, unless forced */ 1211 /* Make sure there is something at this address */
1192 if (kind < 0) { 1212 if (i2c_smbus_xfer(adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK, NULL) < 0)
1193 if (i2c_smbus_xfer(adapter, addr, 0, 0, 0, 1213 return 0;
1194 I2C_SMBUS_QUICK, NULL) < 0)
1195 return 0;
1196 1214
1197 /* prevent 24RF08 corruption */ 1215 /* Prevent 24RF08 corruption */
1198 if ((addr & ~0x0f) == 0x50) 1216 if ((addr & ~0x0f) == 0x50)
1199 i2c_smbus_xfer(adapter, addr, 0, 0, 0, 1217 i2c_smbus_xfer(adapter, addr, 0, 0, 0, I2C_SMBUS_QUICK, NULL);
1200 I2C_SMBUS_QUICK, NULL);
1201 }
1202 1218
1203 /* Finally call the custom detection function */ 1219 /* Finally call the custom detection function */
1204 memset(&info, 0, sizeof(struct i2c_board_info)); 1220 memset(&info, 0, sizeof(struct i2c_board_info));
1205 info.addr = addr; 1221 info.addr = addr;
1206 err = driver->detect(temp_client, kind, &info); 1222 err = driver->detect(temp_client, &info);
1207 if (err) { 1223 if (err) {
1208 /* -ENODEV is returned if the detection fails. We catch it 1224 /* -ENODEV is returned if the detection fails. We catch it
1209 here as this isn't an error. */ 1225 here as this isn't an error. */
@@ -1233,13 +1249,13 @@ static int i2c_detect_address(struct i2c_client *temp_client, int kind,
1233 1249
1234static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver) 1250static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
1235{ 1251{
1236 const struct i2c_client_address_data *address_data; 1252 const unsigned short *address_list;
1237 struct i2c_client *temp_client; 1253 struct i2c_client *temp_client;
1238 int i, err = 0; 1254 int i, err = 0;
1239 int adap_id = i2c_adapter_id(adapter); 1255 int adap_id = i2c_adapter_id(adapter);
1240 1256
1241 address_data = driver->address_data; 1257 address_list = driver->address_list;
1242 if (!driver->detect || !address_data) 1258 if (!driver->detect || !address_list)
1243 return 0; 1259 return 0;
1244 1260
1245 /* Set up a temporary client to help detect callback */ 1261 /* Set up a temporary client to help detect callback */
@@ -1248,40 +1264,13 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
1248 return -ENOMEM; 1264 return -ENOMEM;
1249 temp_client->adapter = adapter; 1265 temp_client->adapter = adapter;
1250 1266
1251 /* Force entries are done first, and are not affected by ignore
1252 entries */
1253 if (address_data->forces) {
1254 const unsigned short * const *forces = address_data->forces;
1255 int kind;
1256
1257 for (kind = 0; forces[kind]; kind++) {
1258 for (i = 0; forces[kind][i] != I2C_CLIENT_END;
1259 i += 2) {
1260 if (forces[kind][i] == adap_id
1261 || forces[kind][i] == ANY_I2C_BUS) {
1262 dev_dbg(&adapter->dev, "found force "
1263 "parameter for adapter %d, "
1264 "addr 0x%02x, kind %d\n",
1265 adap_id, forces[kind][i + 1],
1266 kind);
1267 temp_client->addr = forces[kind][i + 1];
1268 err = i2c_detect_address(temp_client,
1269 kind, driver);
1270 if (err)
1271 goto exit_free;
1272 }
1273 }
1274 }
1275 }
1276
1277 /* Stop here if the classes do not match */ 1267 /* Stop here if the classes do not match */
1278 if (!(adapter->class & driver->class)) 1268 if (!(adapter->class & driver->class))
1279 goto exit_free; 1269 goto exit_free;
1280 1270
1281 /* Stop here if we can't use SMBUS_QUICK */ 1271 /* Stop here if we can't use SMBUS_QUICK */
1282 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) { 1272 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) {
1283 if (address_data->probe[0] == I2C_CLIENT_END 1273 if (address_list[0] == I2C_CLIENT_END)
1284 && address_data->normal_i2c[0] == I2C_CLIENT_END)
1285 goto exit_free; 1274 goto exit_free;
1286 1275
1287 dev_warn(&adapter->dev, "SMBus Quick command not supported, " 1276 dev_warn(&adapter->dev, "SMBus Quick command not supported, "
@@ -1290,48 +1279,11 @@ static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
1290 goto exit_free; 1279 goto exit_free;
1291 } 1280 }
1292 1281
1293 /* Probe entries are done second, and are not affected by ignore 1282 for (i = 0; address_list[i] != I2C_CLIENT_END; i += 1) {
1294 entries either */
1295 for (i = 0; address_data->probe[i] != I2C_CLIENT_END; i += 2) {
1296 if (address_data->probe[i] == adap_id
1297 || address_data->probe[i] == ANY_I2C_BUS) {
1298 dev_dbg(&adapter->dev, "found probe parameter for "
1299 "adapter %d, addr 0x%02x\n", adap_id,
1300 address_data->probe[i + 1]);
1301 temp_client->addr = address_data->probe[i + 1];
1302 err = i2c_detect_address(temp_client, -1, driver);
1303 if (err)
1304 goto exit_free;
1305 }
1306 }
1307
1308 /* Normal entries are done last, unless shadowed by an ignore entry */
1309 for (i = 0; address_data->normal_i2c[i] != I2C_CLIENT_END; i += 1) {
1310 int j, ignore;
1311
1312 ignore = 0;
1313 for (j = 0; address_data->ignore[j] != I2C_CLIENT_END;
1314 j += 2) {
1315 if ((address_data->ignore[j] == adap_id ||
1316 address_data->ignore[j] == ANY_I2C_BUS)
1317 && address_data->ignore[j + 1]
1318 == address_data->normal_i2c[i]) {
1319 dev_dbg(&adapter->dev, "found ignore "
1320 "parameter for adapter %d, "
1321 "addr 0x%02x\n", adap_id,
1322 address_data->ignore[j + 1]);
1323 ignore = 1;
1324 break;
1325 }
1326 }
1327 if (ignore)
1328 continue;
1329
1330 dev_dbg(&adapter->dev, "found normal entry for adapter %d, " 1283 dev_dbg(&adapter->dev, "found normal entry for adapter %d, "
1331 "addr 0x%02x\n", adap_id, 1284 "addr 0x%02x\n", adap_id, address_list[i]);
1332 address_data->normal_i2c[i]); 1285 temp_client->addr = address_list[i];
1333 temp_client->addr = address_data->normal_i2c[i]; 1286 err = i2c_detect_address(temp_client, driver);
1334 err = i2c_detect_address(temp_client, -1, driver);
1335 if (err) 1287 if (err)
1336 goto exit_free; 1288 goto exit_free;
1337 } 1289 }
@@ -1902,7 +1854,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
1902 flags &= I2C_M_TEN | I2C_CLIENT_PEC; 1854 flags &= I2C_M_TEN | I2C_CLIENT_PEC;
1903 1855
1904 if (adapter->algo->smbus_xfer) { 1856 if (adapter->algo->smbus_xfer) {
1905 mutex_lock(&adapter->bus_lock); 1857 rt_mutex_lock(&adapter->bus_lock);
1906 1858
1907 /* Retry automatically on arbitration loss */ 1859 /* Retry automatically on arbitration loss */
1908 orig_jiffies = jiffies; 1860 orig_jiffies = jiffies;
@@ -1916,7 +1868,7 @@ s32 i2c_smbus_xfer(struct i2c_adapter *adapter, u16 addr, unsigned short flags,
1916 orig_jiffies + adapter->timeout)) 1868 orig_jiffies + adapter->timeout))
1917 break; 1869 break;
1918 } 1870 }
1919 mutex_unlock(&adapter->bus_lock); 1871 rt_mutex_unlock(&adapter->bus_lock);
1920 } else 1872 } else
1921 res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write, 1873 res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write,
1922 command, protocol, data); 1874 command, protocol, data);
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index 7e13d2df9af3..f4110aa49600 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -34,7 +34,6 @@
34#include <linux/list.h> 34#include <linux/list.h>
35#include <linux/i2c.h> 35#include <linux/i2c.h>
36#include <linux/i2c-dev.h> 36#include <linux/i2c-dev.h>
37#include <linux/smp_lock.h>
38#include <linux/jiffies.h> 37#include <linux/jiffies.h>
39#include <asm/uaccess.h> 38#include <asm/uaccess.h>
40 39
@@ -445,20 +444,14 @@ static int i2cdev_open(struct inode *inode, struct file *file)
445 struct i2c_client *client; 444 struct i2c_client *client;
446 struct i2c_adapter *adap; 445 struct i2c_adapter *adap;
447 struct i2c_dev *i2c_dev; 446 struct i2c_dev *i2c_dev;
448 int ret = 0;
449 447
450 lock_kernel();
451 i2c_dev = i2c_dev_get_by_minor(minor); 448 i2c_dev = i2c_dev_get_by_minor(minor);
452 if (!i2c_dev) { 449 if (!i2c_dev)
453 ret = -ENODEV; 450 return -ENODEV;
454 goto out;
455 }
456 451
457 adap = i2c_get_adapter(i2c_dev->adap->nr); 452 adap = i2c_get_adapter(i2c_dev->adap->nr);
458 if (!adap) { 453 if (!adap)
459 ret = -ENODEV; 454 return -ENODEV;
460 goto out;
461 }
462 455
463 /* This creates an anonymous i2c_client, which may later be 456 /* This creates an anonymous i2c_client, which may later be
464 * pointed to some address using I2C_SLAVE or I2C_SLAVE_FORCE. 457 * pointed to some address using I2C_SLAVE or I2C_SLAVE_FORCE.
@@ -470,8 +463,7 @@ static int i2cdev_open(struct inode *inode, struct file *file)
470 client = kzalloc(sizeof(*client), GFP_KERNEL); 463 client = kzalloc(sizeof(*client), GFP_KERNEL);
471 if (!client) { 464 if (!client) {
472 i2c_put_adapter(adap); 465 i2c_put_adapter(adap);
473 ret = -ENOMEM; 466 return -ENOMEM;
474 goto out;
475 } 467 }
476 snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr); 468 snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr);
477 client->driver = &i2cdev_driver; 469 client->driver = &i2cdev_driver;
@@ -479,9 +471,7 @@ static int i2cdev_open(struct inode *inode, struct file *file)
479 client->adapter = adap; 471 client->adapter = adap;
480 file->private_data = client; 472 file->private_data = client;
481 473
482out: 474 return 0;
483 unlock_kernel();
484 return ret;
485} 475}
486 476
487static int i2cdev_release(struct inode *inode, struct file *file) 477static int i2cdev_release(struct inode *inode, struct file *file)