aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/algos/i2c-algo-bit.c4
-rw-r--r--drivers/i2c/algos/i2c-algo-pca.c2
-rw-r--r--drivers/i2c/algos/i2c-algo-pcf.c48
-rw-r--r--drivers/i2c/busses/Kconfig715
-rw-r--r--drivers/i2c/busses/Makefile57
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c38
-rw-r--r--drivers/i2c/busses/i2c-ali1563.c38
-rw-r--r--drivers/i2c/busses/i2c-ali15x3.c32
-rw-r--r--drivers/i2c/busses/i2c-amd756-s4882.c31
-rw-r--r--drivers/i2c/busses/i2c-amd756.c37
-rw-r--r--drivers/i2c/busses/i2c-amd8111.c54
-rw-r--r--drivers/i2c/busses/i2c-au1550.c132
-rw-r--r--drivers/i2c/busses/i2c-bfin-twi.c35
-rw-r--r--drivers/i2c/busses/i2c-cpm.c745
-rw-r--r--drivers/i2c/busses/i2c-davinci.c89
-rw-r--r--drivers/i2c/busses/i2c-elektor.c4
-rw-r--r--drivers/i2c/busses/i2c-gpio.c11
-rw-r--r--drivers/i2c/busses/i2c-hydra.c3
-rw-r--r--drivers/i2c/busses/i2c-i801.c284
-rw-r--r--drivers/i2c/busses/i2c-i810.c260
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c206
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c2
-rw-r--r--drivers/i2c/busses/i2c-isch.c339
-rw-r--r--drivers/i2c/busses/i2c-mpc.c114
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c2
-rw-r--r--drivers/i2c/busses/i2c-nforce2-s4985.c256
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c77
-rw-r--r--drivers/i2c/busses/i2c-ocores.c44
-rw-r--r--drivers/i2c/busses/i2c-pasemi.c2
-rw-r--r--drivers/i2c/busses/i2c-pca-platform.c2
-rw-r--r--drivers/i2c/busses/i2c-piix4.c118
-rw-r--r--drivers/i2c/busses/i2c-pmcmsp.c2
-rw-r--r--drivers/i2c/busses/i2c-prosavage.c325
-rw-r--r--drivers/i2c/busses/i2c-pxa.c32
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c159
-rw-r--r--drivers/i2c/busses/i2c-savage4.c185
-rw-r--r--drivers/i2c/busses/i2c-sibyte.c14
-rw-r--r--drivers/i2c/busses/i2c-sis5595.c29
-rw-r--r--drivers/i2c/busses/i2c-sis630.c59
-rw-r--r--drivers/i2c/busses/i2c-sis96x.c37
-rw-r--r--drivers/i2c/busses/i2c-stub.c6
-rw-r--r--drivers/i2c/busses/i2c-taos-evm.c5
-rw-r--r--drivers/i2c/busses/i2c-via.c5
-rw-r--r--drivers/i2c/busses/i2c-viapro.c31
-rw-r--r--drivers/i2c/busses/i2c-voodoo3.c2
-rw-r--r--drivers/i2c/busses/scx200_acb.c2
-rw-r--r--drivers/i2c/chips/Kconfig45
-rw-r--r--drivers/i2c/chips/Makefile1
-rw-r--r--drivers/i2c/chips/at24.c583
-rw-r--r--drivers/i2c/chips/eeprom.c143
-rw-r--r--drivers/i2c/chips/isp1301_omap.c163
-rw-r--r--drivers/i2c/chips/max6875.c125
-rw-r--r--drivers/i2c/chips/pca9539.c110
-rw-r--r--drivers/i2c/chips/pcf8574.c115
-rw-r--r--drivers/i2c/chips/pcf8575.c96
-rw-r--r--drivers/i2c/chips/pcf8591.c111
-rw-r--r--drivers/i2c/chips/tps65010.c2
-rw-r--r--drivers/i2c/i2c-core.c617
-rw-r--r--drivers/i2c/i2c-dev.c40
59 files changed, 4183 insertions, 2642 deletions
diff --git a/drivers/i2c/algos/i2c-algo-bit.c b/drivers/i2c/algos/i2c-algo-bit.c
index 35812823787b..eb8f72ca02f4 100644
--- a/drivers/i2c/algos/i2c-algo-bit.c
+++ b/drivers/i2c/algos/i2c-algo-bit.c
@@ -320,7 +320,7 @@ static int try_address(struct i2c_adapter *i2c_adap,
320 unsigned char addr, int retries) 320 unsigned char addr, int retries)
321{ 321{
322 struct i2c_algo_bit_data *adap = i2c_adap->algo_data; 322 struct i2c_algo_bit_data *adap = i2c_adap->algo_data;
323 int i, ret = -1; 323 int i, ret = 0;
324 324
325 for (i = 0; i <= retries; i++) { 325 for (i = 0; i <= retries; i++) {
326 ret = i2c_outb(i2c_adap, addr); 326 ret = i2c_outb(i2c_adap, addr);
@@ -508,7 +508,7 @@ static int bit_doAddress(struct i2c_adapter *i2c_adap, struct i2c_msg *msg)
508 addr ^= 1; 508 addr ^= 1;
509 ret = try_address(i2c_adap, addr, retries); 509 ret = try_address(i2c_adap, addr, retries);
510 if ((ret != 1) && !nak_ok) 510 if ((ret != 1) && !nak_ok)
511 return -EREMOTEIO; 511 return -ENXIO;
512 } 512 }
513 513
514 return 0; 514 return 0;
diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c
index e954a20b97a6..d50b329a3c94 100644
--- a/drivers/i2c/algos/i2c-algo-pca.c
+++ b/drivers/i2c/algos/i2c-algo-pca.c
@@ -182,7 +182,7 @@ static int pca_xfer(struct i2c_adapter *i2c_adap,
182 } 182 }
183 if (state != 0xf8) { 183 if (state != 0xf8) {
184 dev_dbg(&i2c_adap->dev, "bus is not idle. status is %#04x\n", state); 184 dev_dbg(&i2c_adap->dev, "bus is not idle. status is %#04x\n", state);
185 return -EIO; 185 return -EAGAIN;
186 } 186 }
187 187
188 DEB1("{{{ XFER %d messages\n", num); 188 DEB1("{{{ XFER %d messages\n", num);
diff --git a/drivers/i2c/algos/i2c-algo-pcf.c b/drivers/i2c/algos/i2c-algo-pcf.c
index 8907b0191677..1e328d19cd6d 100644
--- a/drivers/i2c/algos/i2c-algo-pcf.c
+++ b/drivers/i2c/algos/i2c-algo-pcf.c
@@ -78,6 +78,36 @@ static void i2c_stop(struct i2c_algo_pcf_data *adap)
78 set_pcf(adap, 1, I2C_PCF_STOP); 78 set_pcf(adap, 1, I2C_PCF_STOP);
79} 79}
80 80
81static void handle_lab(struct i2c_algo_pcf_data *adap, const int *status)
82{
83 DEB2(printk(KERN_INFO
84 "i2c-algo-pcf.o: lost arbitration (CSR 0x%02x)\n",
85 *status));
86
87 /* Cleanup from LAB -- reset and enable ESO.
88 * This resets the PCF8584; since we've lost the bus, no
89 * further attempts should be made by callers to clean up
90 * (no i2c_stop() etc.)
91 */
92 set_pcf(adap, 1, I2C_PCF_PIN);
93 set_pcf(adap, 1, I2C_PCF_ESO);
94
95 /* We pause for a time period sufficient for any running
96 * I2C transaction to complete -- the arbitration logic won't
97 * work properly until the next START is seen.
98 * It is assumed the bus driver or client has set a proper value.
99 *
100 * REVISIT: should probably use msleep instead of mdelay if we
101 * know we can sleep.
102 */
103 if (adap->lab_mdelay)
104 mdelay(adap->lab_mdelay);
105
106 DEB2(printk(KERN_INFO
107 "i2c-algo-pcf.o: reset LAB condition (CSR 0x%02x)\n",
108 get_pcf(adap, 1)));
109}
110
81static int wait_for_bb(struct i2c_algo_pcf_data *adap) { 111static int wait_for_bb(struct i2c_algo_pcf_data *adap) {
82 112
83 int timeout = DEF_TIMEOUT; 113 int timeout = DEF_TIMEOUT;
@@ -109,23 +139,7 @@ static int wait_for_pin(struct i2c_algo_pcf_data *adap, int *status) {
109 *status = get_pcf(adap, 1); 139 *status = get_pcf(adap, 1);
110 } 140 }
111 if (*status & I2C_PCF_LAB) { 141 if (*status & I2C_PCF_LAB) {
112 DEB2(printk(KERN_INFO 142 handle_lab(adap, status);
113 "i2c-algo-pcf.o: lost arbitration (CSR 0x%02x)\n",
114 *status));
115 /* Cleanup from LAB-- reset and enable ESO.
116 * This resets the PCF8584; since we've lost the bus, no
117 * further attempts should be made by callers to clean up
118 * (no i2c_stop() etc.)
119 */
120 set_pcf(adap, 1, I2C_PCF_PIN);
121 set_pcf(adap, 1, I2C_PCF_ESO);
122 /* TODO: we should pause for a time period sufficient for any
123 * running I2C transaction to complete-- the arbitration
124 * logic won't work properly until the next START is seen.
125 */
126 DEB2(printk(KERN_INFO
127 "i2c-algo-pcf.o: reset LAB condition (CSR 0x%02x)\n",
128 get_pcf(adap,1)));
129 return(-EINTR); 143 return(-EINTR);
130 } 144 }
131#endif 145#endif
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 48438cc5d0ca..6ee997b2817c 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -4,6 +4,9 @@
4 4
5menu "I2C Hardware Bus support" 5menu "I2C Hardware Bus support"
6 6
7comment "PC SMBus host controller drivers"
8 depends on PCI
9
7config I2C_ALI1535 10config I2C_ALI1535
8 tristate "ALI 1535" 11 tristate "ALI 1535"
9 depends on PCI 12 depends on PCI
@@ -73,6 +76,186 @@ config I2C_AMD8111
73 This driver can also be built as a module. If so, the module 76 This driver can also be built as a module. If so, the module
74 will be called i2c-amd8111. 77 will be called i2c-amd8111.
75 78
79config I2C_I801
80 tristate "Intel 82801 (ICH)"
81 depends on PCI
82 help
83 If you say yes to this option, support will be included for the Intel
84 801 family of mainboard I2C interfaces. Specifically, the following
85 versions of the chipset are supported:
86 82801AA
87 82801AB
88 82801BA
89 82801CA/CAM
90 82801DB
91 82801EB/ER (ICH5/ICH5R)
92 6300ESB
93 ICH6
94 ICH7
95 ESB2
96 ICH8
97 ICH9
98 Tolapai
99 ICH10
100
101 This driver can also be built as a module. If so, the module
102 will be called i2c-i801.
103
104config I2C_ISCH
105 tristate "Intel SCH SMBus 1.0"
106 depends on PCI
107 help
108 Say Y here if you want to use SMBus controller on the Intel SCH
109 based systems.
110
111 This driver can also be built as a module. If so, the module
112 will be called i2c-isch.
113
114config I2C_PIIX4
115 tristate "Intel PIIX4 and compatible (ATI/Serverworks/Broadcom/SMSC)"
116 depends on PCI
117 help
118 If you say yes to this option, support will be included for the Intel
119 PIIX4 family of mainboard I2C interfaces. Specifically, the following
120 versions of the chipset are supported (note that Serverworks is part
121 of Broadcom):
122 Intel PIIX4
123 Intel 440MX
124 ATI IXP200
125 ATI IXP300
126 ATI IXP400
127 ATI SB600
128 ATI SB700
129 ATI SB800
130 Serverworks OSB4
131 Serverworks CSB5
132 Serverworks CSB6
133 Serverworks HT-1000
134 SMSC Victory66
135
136 This driver can also be built as a module. If so, the module
137 will be called i2c-piix4.
138
139config I2C_NFORCE2
140 tristate "Nvidia nForce2, nForce3 and nForce4"
141 depends on PCI
142 help
143 If you say yes to this option, support will be included for the Nvidia
144 nForce2, nForce3 and nForce4 families of mainboard I2C interfaces.
145
146 This driver can also be built as a module. If so, the module
147 will be called i2c-nforce2.
148
149config I2C_NFORCE2_S4985
150 tristate "SMBus multiplexing on the Tyan S4985"
151 depends on I2C_NFORCE2 && EXPERIMENTAL
152 help
153 Enabling this option will add specific SMBus support for the Tyan
154 S4985 motherboard. On this 4-CPU board, the SMBus is multiplexed
155 over 4 different channels, where the various memory module EEPROMs
156 live. Saying yes here will give you access to these in addition
157 to the trunk.
158
159 This driver can also be built as a module. If so, the module
160 will be called i2c-nforce2-s4985.
161
162config I2C_SIS5595
163 tristate "SiS 5595"
164 depends on PCI
165 help
166 If you say yes to this option, support will be included for the
167 SiS5595 SMBus (a subset of I2C) interface.
168
169 This driver can also be built as a module. If so, the module
170 will be called i2c-sis5595.
171
172config I2C_SIS630
173 tristate "SiS 630/730"
174 depends on PCI
175 help
176 If you say yes to this option, support will be included for the
177 SiS630 and SiS730 SMBus (a subset of I2C) interface.
178
179 This driver can also be built as a module. If so, the module
180 will be called i2c-sis630.
181
182config I2C_SIS96X
183 tristate "SiS 96x"
184 depends on PCI
185 help
186 If you say yes to this option, support will be included for the SiS
187 96x SMBus (a subset of I2C) interfaces. Specifically, the following
188 chipsets are supported:
189 645/961
190 645DX/961
191 645DX/962
192 648/961
193 650/961
194 735
195 745
196
197 This driver can also be built as a module. If so, the module
198 will be called i2c-sis96x.
199
200config I2C_VIA
201 tristate "VIA VT82C586B"
202 depends on PCI && EXPERIMENTAL
203 select I2C_ALGOBIT
204 help
205 If you say yes to this option, support will be included for the VIA
206 82C586B I2C interface
207
208 This driver can also be built as a module. If so, the module
209 will be called i2c-via.
210
211config I2C_VIAPRO
212 tristate "VIA VT82C596/82C686/82xx and CX700"
213 depends on PCI
214 help
215 If you say yes to this option, support will be included for the VIA
216 VT82C596 and later SMBus interface. Specifically, the following
217 chipsets are supported:
218 VT82C596A/B
219 VT82C686A/B
220 VT8231
221 VT8233/A
222 VT8235
223 VT8237R/A/S
224 VT8251
225 CX700
226
227 This driver can also be built as a module. If so, the module
228 will be called i2c-viapro.
229
230comment "Mac SMBus host controller drivers"
231 depends on PPC_CHRP || PPC_PMAC
232
233config I2C_HYDRA
234 tristate "CHRP Apple Hydra Mac I/O I2C interface"
235 depends on PCI && PPC_CHRP && EXPERIMENTAL
236 select I2C_ALGOBIT
237 help
238 This supports the use of the I2C interface in the Apple Hydra Mac
239 I/O chip on some CHRP machines (e.g. the LongTrail). Say Y if you
240 have such a machine.
241
242 This support is also available as a module. If so, the module
243 will be called i2c-hydra.
244
245config I2C_POWERMAC
246 tristate "Powermac I2C interface"
247 depends on PPC_PMAC
248 default y
249 help
250 This exposes the various PowerMac i2c interfaces to the linux i2c
251 layer and to userland. It is used by various drivers on the PowerMac
252 platform, and should generally be enabled.
253
254 This support is also available as a module. If so, the module
255 will be called i2c-powermac.
256
257comment "I2C system bus drivers (mostly embedded / system-on-chip)"
258
76config I2C_AT91 259config I2C_AT91
77 tristate "Atmel AT91 I2C Two-Wire interface (TWI)" 260 tristate "Atmel AT91 I2C Two-Wire interface (TWI)"
78 depends on ARCH_AT91 && EXPERIMENTAL && BROKEN 261 depends on ARCH_AT91 && EXPERIMENTAL && BROKEN
@@ -101,10 +284,9 @@ config I2C_AU1550
101config I2C_BLACKFIN_TWI 284config I2C_BLACKFIN_TWI
102 tristate "Blackfin TWI I2C support" 285 tristate "Blackfin TWI I2C support"
103 depends on BLACKFIN 286 depends on BLACKFIN
287 depends on !BF561 && !BF531 && !BF532 && !BF533
104 help 288 help
105 This is the TWI I2C device driver for Blackfin BF522, BF525, 289 This is the I2C bus driver for Blackfin on-chip TWI interface.
106 BF527, BF534, BF536, BF537 and BF54x. For other Blackfin processors,
107 please don't use this driver.
108 290
109 This driver can also be built as a module. If so, the module 291 This driver can also be built as a module. If so, the module
110 will be called i2c-bfin-twi. 292 will be called i2c-bfin-twi.
@@ -117,6 +299,16 @@ config I2C_BLACKFIN_TWI_CLK_KHZ
117 help 299 help
118 The unit of the TWI clock is kHz. 300 The unit of the TWI clock is kHz.
119 301
302config I2C_CPM
303 tristate "Freescale CPM1 or CPM2 (MPC8xx/826x)"
304 depends on (CPM1 || CPM2) && OF_I2C
305 help
306 This supports the use of the I2C interface on Freescale
307 processors with CPM1 or CPM2.
308
309 This driver can also be built as a module. If so, the module
310 will be called i2c-cpm.
311
120config I2C_DAVINCI 312config I2C_DAVINCI
121 tristate "DaVinci I2C driver" 313 tristate "DaVinci I2C driver"
122 depends on ARCH_DAVINCI 314 depends on ARCH_DAVINCI
@@ -130,17 +322,6 @@ config I2C_DAVINCI
130 devices such as DaVinci NIC. 322 devices such as DaVinci NIC.
131 For details please see http://www.ti.com/davinci 323 For details please see http://www.ti.com/davinci
132 324
133config I2C_ELEKTOR
134 tristate "Elektor ISA card"
135 depends on ISA && BROKEN_ON_SMP
136 select I2C_ALGOPCF
137 help
138 This supports the PCF8584 ISA bus I2C adapter. Say Y if you own
139 such an adapter.
140
141 This support is also available as a module. If so, the module
142 will be called i2c-elektor.
143
144config I2C_GPIO 325config I2C_GPIO
145 tristate "GPIO-based bitbanging I2C" 326 tristate "GPIO-based bitbanging I2C"
146 depends on GENERIC_GPIO 327 depends on GENERIC_GPIO
@@ -149,104 +330,6 @@ config I2C_GPIO
149 This is a very simple bitbanging I2C driver utilizing the 330 This is a very simple bitbanging I2C driver utilizing the
150 arch-neutral GPIO API to control the SCL and SDA lines. 331 arch-neutral GPIO API to control the SCL and SDA lines.
151 332
152config I2C_HYDRA
153 tristate "CHRP Apple Hydra Mac I/O I2C interface"
154 depends on PCI && PPC_CHRP && EXPERIMENTAL
155 select I2C_ALGOBIT
156 help
157 This supports the use of the I2C interface in the Apple Hydra Mac
158 I/O chip on some CHRP machines (e.g. the LongTrail). Say Y if you
159 have such a machine.
160
161 This support is also available as a module. If so, the module
162 will be called i2c-hydra.
163
164config I2C_I801
165 tristate "Intel 82801 (ICH)"
166 depends on PCI
167 help
168 If you say yes to this option, support will be included for the Intel
169 801 family of mainboard I2C interfaces. Specifically, the following
170 versions of the chipset are supported:
171 82801AA
172 82801AB
173 82801BA
174 82801CA/CAM
175 82801DB
176 82801EB/ER (ICH5/ICH5R)
177 6300ESB
178 ICH6
179 ICH7
180 ESB2
181 ICH8
182 ICH9
183 Tolapai
184 ICH10
185
186 This driver can also be built as a module. If so, the module
187 will be called i2c-i801.
188
189config I2C_I810
190 tristate "Intel 810/815 (DEPRECATED)"
191 default n
192 depends on PCI
193 select I2C_ALGOBIT
194 help
195 If you say yes to this option, support will be included for the Intel
196 810/815 family of mainboard I2C interfaces. Specifically, the
197 following versions of the chipset are supported:
198 i810AA
199 i810AB
200 i810E
201 i815
202 i845G
203
204 This driver is deprecated in favor of the i810fb and intelfb drivers.
205
206 This driver can also be built as a module. If so, the module
207 will be called i2c-i810.
208
209config I2C_PXA
210 tristate "Intel PXA2XX I2C adapter (EXPERIMENTAL)"
211 depends on EXPERIMENTAL && ARCH_PXA
212 help
213 If you have devices in the PXA I2C bus, say yes to this option.
214 This driver can also be built as a module. If so, the module
215 will be called i2c-pxa.
216
217config I2C_PXA_SLAVE
218 bool "Intel PXA2XX I2C Slave comms support"
219 depends on I2C_PXA
220 help
221 Support I2C slave mode communications on the PXA I2C bus. This
222 is necessary for systems where the PXA may be a target on the
223 I2C bus.
224
225config I2C_PIIX4
226 tristate "Intel PIIX4 and compatible (ATI/Serverworks/Broadcom/SMSC)"
227 depends on PCI
228 help
229 If you say yes to this option, support will be included for the Intel
230 PIIX4 family of mainboard I2C interfaces. Specifically, the following
231 versions of the chipset are supported (note that Serverworks is part
232 of Broadcom):
233 Intel PIIX4
234 Intel 440MX
235 ATI IXP200
236 ATI IXP300
237 ATI IXP400
238 ATI SB600
239 ATI SB700
240 ATI SB800
241 Serverworks OSB4
242 Serverworks CSB5
243 Serverworks CSB6
244 Serverworks HT-1000
245 SMSC Victory66
246
247 This driver can also be built as a module. If so, the module
248 will be called i2c-piix4.
249
250config I2C_IBM_IIC 333config I2C_IBM_IIC
251 tristate "IBM PPC 4xx on-chip I2C interface" 334 tristate "IBM PPC 4xx on-chip I2C interface"
252 depends on 4xx 335 depends on 4xx
@@ -281,18 +364,6 @@ config I2C_IXP2000
281 This driver is deprecated and will be dropped soon. Use i2c-gpio 364 This driver is deprecated and will be dropped soon. Use i2c-gpio
282 instead. 365 instead.
283 366
284config I2C_POWERMAC
285 tristate "Powermac I2C interface"
286 depends on PPC_PMAC
287 default y
288 help
289 This exposes the various PowerMac i2c interfaces to the linux i2c
290 layer and to userland. It is used by various drivers on the PowerMac
291 platform, and should generally be enabled.
292
293 This support is also available as a module. If so, the module
294 will be called i2c-powermac.
295
296config I2C_MPC 367config I2C_MPC
297 tristate "MPC107/824x/85xx/52xx/86xx" 368 tristate "MPC107/824x/85xx/52xx/86xx"
298 depends on PPC32 369 depends on PPC32
@@ -305,15 +376,15 @@ config I2C_MPC
305 This driver can also be built as a module. If so, the module 376 This driver can also be built as a module. If so, the module
306 will be called i2c-mpc. 377 will be called i2c-mpc.
307 378
308config I2C_NFORCE2 379config I2C_MV64XXX
309 tristate "Nvidia nForce2, nForce3 and nForce4" 380 tristate "Marvell mv64xxx I2C Controller"
310 depends on PCI 381 depends on (MV64X60 || PLAT_ORION) && EXPERIMENTAL
311 help 382 help
312 If you say yes to this option, support will be included for the Nvidia 383 If you say yes to this option, support will be included for the
313 nForce2, nForce3 and nForce4 families of mainboard I2C interfaces. 384 built-in I2C interface on the Marvell 64xxx line of host bridges.
314 385
315 This driver can also be built as a module. If so, the module 386 This driver can also be built as a module. If so, the module
316 will be called i2c-nforce2. 387 will be called i2c-mv64xxx.
317 388
318config I2C_OCORES 389config I2C_OCORES
319 tristate "OpenCores I2C Controller" 390 tristate "OpenCores I2C Controller"
@@ -336,76 +407,37 @@ config I2C_OMAP
336 Like OMAP1510/1610/1710/5912 and OMAP242x. 407 Like OMAP1510/1610/1710/5912 and OMAP242x.
337 For details see http://www.ti.com/omap. 408 For details see http://www.ti.com/omap.
338 409
339config I2C_PARPORT
340 tristate "Parallel port adapter"
341 depends on PARPORT
342 select I2C_ALGOBIT
343 help
344 This supports parallel port I2C adapters such as the ones made by
345 Philips or Velleman, Analog Devices evaluation boards, and more.
346 Basically any adapter using the parallel port as an I2C bus with
347 no extra chipset is supported by this driver, or could be.
348
349 This driver is a replacement for (and was inspired by) an older
350 driver named i2c-philips-par. The new driver supports more devices,
351 and makes it easier to add support for new devices.
352
353 An adapter type parameter is now mandatory. Please read the file
354 Documentation/i2c/busses/i2c-parport for details.
355
356 Another driver exists, named i2c-parport-light, which doesn't depend
357 on the parport driver. This is meant for embedded systems. Don't say
358 Y here if you intend to say Y or M there.
359
360 This support is also available as a module. If so, the module
361 will be called i2c-parport.
362
363config I2C_PARPORT_LIGHT
364 tristate "Parallel port adapter (light)"
365 select I2C_ALGOBIT
366 help
367 This supports parallel port I2C adapters such as the ones made by
368 Philips or Velleman, Analog Devices evaluation boards, and more.
369 Basically any adapter using the parallel port as an I2C bus with
370 no extra chipset is supported by this driver, or could be.
371
372 This driver is a light version of i2c-parport. It doesn't depend
373 on the parport driver, and uses direct I/O access instead. This
374 might be preferred on embedded systems where wasting memory for
375 the clean but heavy parport handling is not an option. The
376 drawback is a reduced portability and the impossibility to
377 daisy-chain other parallel port devices.
378
379 Don't say Y here if you said Y or M to i2c-parport. Saying M to
380 both is possible but both modules should not be loaded at the same
381 time.
382
383 This support is also available as a module. If so, the module
384 will be called i2c-parport-light.
385
386config I2C_PASEMI 410config I2C_PASEMI
387 tristate "PA Semi SMBus interface" 411 tristate "PA Semi SMBus interface"
388 depends on PPC_PASEMI && PCI 412 depends on PPC_PASEMI && PCI
389 help 413 help
390 Supports the PA Semi PWRficient on-chip SMBus interfaces. 414 Supports the PA Semi PWRficient on-chip SMBus interfaces.
391 415
392config I2C_PROSAVAGE 416config I2C_PNX
393 tristate "S3/VIA (Pro)Savage (DEPRECATED)" 417 tristate "I2C bus support for Philips PNX targets"
394 default n 418 depends on ARCH_PNX4008
395 depends on PCI
396 select I2C_ALGOBIT
397 help 419 help
398 If you say yes to this option, support will be included for the 420 This driver supports the Philips IP3204 I2C IP block master and/or
399 I2C bus and DDC bus of the S3VIA embedded Savage4 and ProSavage8 421 slave controller
400 graphics processors.
401 chipsets supported:
402 S3/VIA KM266/VT8375 aka ProSavage8
403 S3/VIA KM133/VT8365 aka Savage4
404 422
405 This driver is deprecated in favor of the savagefb driver. 423 This driver can also be built as a module. If so, the module
424 will be called i2c-pnx.
406 425
407 This support is also available as a module. If so, the module 426config I2C_PXA
408 will be called i2c-prosavage. 427 tristate "Intel PXA2XX I2C adapter (EXPERIMENTAL)"
428 depends on EXPERIMENTAL && ARCH_PXA
429 help
430 If you have devices in the PXA I2C bus, say yes to this option.
431 This driver can also be built as a module. If so, the module
432 will be called i2c-pxa.
433
434config I2C_PXA_SLAVE
435 bool "Intel PXA2XX I2C Slave comms support"
436 depends on I2C_PXA
437 help
438 Support I2C slave mode communications on the PXA I2C bus. This
439 is necessary for systems where the PXA may be a target on the
440 I2C bus.
409 441
410config I2C_S3C2410 442config I2C_S3C2410
411 tristate "S3C2410 I2C Driver" 443 tristate "S3C2410 I2C Driver"
@@ -414,25 +446,24 @@ config I2C_S3C2410
414 Say Y here to include support for I2C controller in the 446 Say Y here to include support for I2C controller in the
415 Samsung S3C2410 based System-on-Chip devices. 447 Samsung S3C2410 based System-on-Chip devices.
416 448
417config I2C_SAVAGE4 449config I2C_SH7760
418 tristate "S3 Savage 4 (DEPRECATED)" 450 tristate "Renesas SH7760 I2C Controller"
419 default n 451 depends on CPU_SUBTYPE_SH7760
420 depends on PCI
421 select I2C_ALGOBIT
422 help 452 help
423 If you say yes to this option, support will be included for the 453 This driver supports the 2 I2C interfaces on the Renesas SH7760.
424 S3 Savage 4 I2C interface.
425
426 This driver is deprecated in favor of the savagefb driver.
427 454
428 This driver can also be built as a module. If so, the module 455 This driver can also be built as a module. If so, the module
429 will be called i2c-savage4. 456 will be called i2c-sh7760.
430 457
431config I2C_SIBYTE 458config I2C_SH_MOBILE
432 tristate "SiByte SMBus interface" 459 tristate "SuperH Mobile I2C Controller"
433 depends on SIBYTE_SB1xxx_SOC 460 depends on SUPERH
434 help 461 help
435 Supports the SiByte SOC on-chip I2C interfaces (2 channels). 462 If you say yes to this option, support will be included for the
463 built-in I2C interface on the Renesas SH-Mobile processor.
464
465 This driver can also be built as a module. If so, the module
466 will be called i2c-sh_mobile.
436 467
437config I2C_SIMTEC 468config I2C_SIMTEC
438 tristate "Simtec Generic I2C interface" 469 tristate "Simtec Generic I2C interface"
@@ -446,86 +477,65 @@ config I2C_SIMTEC
446 This driver can also be built as a module. If so, the module 477 This driver can also be built as a module. If so, the module
447 will be called i2c-simtec. 478 will be called i2c-simtec.
448 479
449config SCx200_I2C 480config I2C_VERSATILE
450 tristate "NatSemi SCx200 I2C using GPIO pins (DEPRECATED)" 481 tristate "ARM Versatile/Realview I2C bus support"
451 depends on SCx200_GPIO 482 depends on ARCH_VERSATILE || ARCH_REALVIEW
452 select I2C_ALGOBIT 483 select I2C_ALGOBIT
453 help 484 help
454 Enable the use of two GPIO pins of a SCx200 processor as an I2C bus. 485 Say yes if you want to support the I2C serial bus on ARMs Versatile
455 486 range of platforms.
456 If you don't know what to do here, say N.
457 487
458 This support is also available as a module. If so, the module 488 This driver can also be built as a module. If so, the module
459 will be called scx200_i2c. 489 will be called i2c-versatile.
460 490
461 This driver is deprecated and will be dropped soon. Use i2c-gpio 491comment "External I2C/SMBus adapter drivers"
462 (or scx200_acb) instead.
463 492
464config SCx200_I2C_SCL 493config I2C_PARPORT
465 int "GPIO pin used for SCL" 494 tristate "Parallel port adapter"
466 depends on SCx200_I2C 495 depends on PARPORT
467 default "12" 496 select I2C_ALGOBIT
468 help 497 help
469 Enter the GPIO pin number used for the SCL signal. This value can 498 This supports parallel port I2C adapters such as the ones made by
470 also be specified with a module parameter. 499 Philips or Velleman, Analog Devices evaluation boards, and more.
500 Basically any adapter using the parallel port as an I2C bus with
501 no extra chipset is supported by this driver, or could be.
471 502
472config SCx200_I2C_SDA 503 This driver is a replacement for (and was inspired by) an older
473 int "GPIO pin used for SDA" 504 driver named i2c-philips-par. The new driver supports more devices,
474 depends on SCx200_I2C 505 and makes it easier to add support for new devices.
475 default "13"
476 help
477 Enter the GPIO pin number used for the SSA signal. This value can
478 also be specified with a module parameter.
479 506
480config SCx200_ACB 507 An adapter type parameter is now mandatory. Please read the file
481 tristate "Geode ACCESS.bus support" 508 Documentation/i2c/busses/i2c-parport for details.
482 depends on X86_32 && PCI
483 help
484 Enable the use of the ACCESS.bus controllers on the Geode SCx200 and
485 SC1100 processors and the CS5535 and CS5536 Geode companion devices.
486 509
487 If you don't know what to do here, say N. 510 Another driver exists, named i2c-parport-light, which doesn't depend
511 on the parport driver. This is meant for embedded systems. Don't say
512 Y here if you intend to say Y or M there.
488 513
489 This support is also available as a module. If so, the module 514 This support is also available as a module. If so, the module
490 will be called scx200_acb. 515 will be called i2c-parport.
491
492config I2C_SIS5595
493 tristate "SiS 5595"
494 depends on PCI
495 help
496 If you say yes to this option, support will be included for the
497 SiS5595 SMBus (a subset of I2C) interface.
498
499 This driver can also be built as a module. If so, the module
500 will be called i2c-sis5595.
501 516
502config I2C_SIS630 517config I2C_PARPORT_LIGHT
503 tristate "SiS 630/730" 518 tristate "Parallel port adapter (light)"
504 depends on PCI 519 select I2C_ALGOBIT
505 help 520 help
506 If you say yes to this option, support will be included for the 521 This supports parallel port I2C adapters such as the ones made by
507 SiS630 and SiS730 SMBus (a subset of I2C) interface. 522 Philips or Velleman, Analog Devices evaluation boards, and more.
523 Basically any adapter using the parallel port as an I2C bus with
524 no extra chipset is supported by this driver, or could be.
508 525
509 This driver can also be built as a module. If so, the module 526 This driver is a light version of i2c-parport. It doesn't depend
510 will be called i2c-sis630. 527 on the parport driver, and uses direct I/O access instead. This
528 might be preferred on embedded systems where wasting memory for
529 the clean but heavy parport handling is not an option. The
530 drawback is a reduced portability and the impossibility to
531 daisy-chain other parallel port devices.
511 532
512config I2C_SIS96X 533 Don't say Y here if you said Y or M to i2c-parport. Saying M to
513 tristate "SiS 96x" 534 both is possible but both modules should not be loaded at the same
514 depends on PCI 535 time.
515 help
516 If you say yes to this option, support will be included for the SiS
517 96x SMBus (a subset of I2C) interfaces. Specifically, the following
518 chipsets are supported:
519 645/961
520 645DX/961
521 645DX/962
522 648/961
523 650/961
524 735
525 745
526 536
527 This driver can also be built as a module. If so, the module 537 This support is also available as a module. If so, the module
528 will be called i2c-sis96x. 538 will be called i2c-parport-light.
529 539
530config I2C_TAOS_EVM 540config I2C_TAOS_EVM
531 tristate "TAOS evaluation module" 541 tristate "TAOS evaluation module"
@@ -543,21 +553,8 @@ config I2C_TAOS_EVM
543 This support is also available as a module. If so, the module 553 This support is also available as a module. If so, the module
544 will be called i2c-taos-evm. 554 will be called i2c-taos-evm.
545 555
546config I2C_STUB
547 tristate "I2C/SMBus Test Stub"
548 depends on EXPERIMENTAL && m
549 default 'n'
550 help
551 This module may be useful to developers of SMBus client drivers,
552 especially for certain kinds of sensor chips.
553
554 If you do build this module, be sure to read the notes and warnings
555 in <file:Documentation/i2c/i2c-stub>.
556
557 If you don't know what to do here, definitely say N.
558
559config I2C_TINY_USB 556config I2C_TINY_USB
560 tristate "I2C-Tiny-USB" 557 tristate "Tiny-USB adapter"
561 depends on USB 558 depends on USB
562 help 559 help
563 If you say yes to this option, support will be included for the 560 If you say yes to this option, support will be included for the
@@ -567,16 +564,21 @@ config I2C_TINY_USB
567 This driver can also be built as a module. If so, the module 564 This driver can also be built as a module. If so, the module
568 will be called i2c-tiny-usb. 565 will be called i2c-tiny-usb.
569 566
570config I2C_VERSATILE 567comment "Graphics adapter I2C/DDC channel drivers"
571 tristate "ARM Versatile/Realview I2C bus support" 568 depends on PCI
572 depends on ARCH_VERSATILE || ARCH_REALVIEW 569
570config I2C_VOODOO3
571 tristate "Voodoo 3"
572 depends on PCI
573 select I2C_ALGOBIT 573 select I2C_ALGOBIT
574 help 574 help
575 Say yes if you want to support the I2C serial bus on ARMs Versatile 575 If you say yes to this option, support will be included for the
576 range of platforms. 576 Voodoo 3 I2C interface.
577 577
578 This driver can also be built as a module. If so, the module 578 This driver can also be built as a module. If so, the module
579 will be called i2c-versatile. 579 will be called i2c-voodoo3.
580
581comment "Other I2C/SMBus bus drivers"
580 582
581config I2C_ACORN 583config I2C_ACORN
582 tristate "Acorn IOC/IOMD I2C bus support" 584 tristate "Acorn IOC/IOMD I2C bus support"
@@ -588,46 +590,16 @@ config I2C_ACORN
588 590
589 If you don't know, say Y. 591 If you don't know, say Y.
590 592
591config I2C_VIA 593config I2C_ELEKTOR
592 tristate "VIA 82C586B" 594 tristate "Elektor ISA card"
593 depends on PCI && EXPERIMENTAL 595 depends on ISA && BROKEN_ON_SMP
594 select I2C_ALGOBIT 596 select I2C_ALGOPCF
595 help
596 If you say yes to this option, support will be included for the VIA
597 82C586B I2C interface
598
599 This driver can also be built as a module. If so, the module
600 will be called i2c-via.
601
602config I2C_VIAPRO
603 tristate "VIA VT82C596/82C686/82xx and CX700"
604 depends on PCI
605 help
606 If you say yes to this option, support will be included for the VIA
607 VT82C596 and later SMBus interface. Specifically, the following
608 chipsets are supported:
609 VT82C596A/B
610 VT82C686A/B
611 VT8231
612 VT8233/A
613 VT8235
614 VT8237R/A/S
615 VT8251
616 CX700
617
618 This driver can also be built as a module. If so, the module
619 will be called i2c-viapro.
620
621config I2C_VOODOO3
622 tristate "Voodoo 3"
623 depends on PCI
624 select I2C_ALGOBIT
625 help 597 help
626 If you say yes to this option, support will be included for the 598 This supports the PCF8584 ISA bus I2C adapter. Say Y if you own
627 Voodoo 3 I2C interface. 599 such an adapter.
628 600
629 This driver can also be built as a module. If so, the module 601 This support is also available as a module. If so, the module
630 will be called i2c-voodoo3. 602 will be called i2c-elektor.
631 603
632config I2C_PCA_ISA 604config I2C_PCA_ISA
633 tristate "PCA9564 on an ISA bus" 605 tristate "PCA9564 on an ISA bus"
@@ -657,26 +629,6 @@ config I2C_PCA_PLATFORM
657 This driver can also be built as a module. If so, the module 629 This driver can also be built as a module. If so, the module
658 will be called i2c-pca-platform. 630 will be called i2c-pca-platform.
659 631
660config I2C_MV64XXX
661 tristate "Marvell mv64xxx I2C Controller"
662 depends on (MV64X60 || PLAT_ORION) && EXPERIMENTAL
663 help
664 If you say yes to this option, support will be included for the
665 built-in I2C interface on the Marvell 64xxx line of host bridges.
666
667 This driver can also be built as a module. If so, the module
668 will be called i2c-mv64xxx.
669
670config I2C_PNX
671 tristate "I2C bus support for Philips PNX targets"
672 depends on ARCH_PNX4008
673 help
674 This driver supports the Philips IP3204 I2C IP block master and/or
675 slave controller
676
677 This driver can also be built as a module. If so, the module
678 will be called i2c-pnx.
679
680config I2C_PMCMSP 632config I2C_PMCMSP
681 tristate "PMC MSP I2C TWI Controller" 633 tristate "PMC MSP I2C TWI Controller"
682 depends on PMC_MSP 634 depends on PMC_MSP
@@ -686,23 +638,66 @@ config I2C_PMCMSP
686 This driver can also be built as module. If so, the module 638 This driver can also be built as module. If so, the module
687 will be called i2c-pmcmsp. 639 will be called i2c-pmcmsp.
688 640
689config I2C_SH7760 641config I2C_SIBYTE
690 tristate "Renesas SH7760 I2C Controller" 642 tristate "SiByte SMBus interface"
691 depends on CPU_SUBTYPE_SH7760 643 depends on SIBYTE_SB1xxx_SOC
692 help 644 help
693 This driver supports the 2 I2C interfaces on the Renesas SH7760. 645 Supports the SiByte SOC on-chip I2C interfaces (2 channels).
694 646
695 This driver can also be built as a module. If so, the module 647config I2C_STUB
696 will be called i2c-sh7760. 648 tristate "I2C/SMBus Test Stub"
649 depends on EXPERIMENTAL && m
650 default 'n'
651 help
652 This module may be useful to developers of SMBus client drivers,
653 especially for certain kinds of sensor chips.
697 654
698config I2C_SH_MOBILE 655 If you do build this module, be sure to read the notes and warnings
699 tristate "SuperH Mobile I2C Controller" 656 in <file:Documentation/i2c/i2c-stub>.
700 depends on SUPERH 657
658 If you don't know what to do here, definitely say N.
659
660config SCx200_I2C
661 tristate "NatSemi SCx200 I2C using GPIO pins (DEPRECATED)"
662 depends on SCx200_GPIO
663 select I2C_ALGOBIT
701 help 664 help
702 If you say yes to this option, support will be included for the 665 Enable the use of two GPIO pins of a SCx200 processor as an I2C bus.
703 built-in I2C interface on the Renesas SH-Mobile processor.
704 666
705 This driver can also be built as a module. If so, the module 667 If you don't know what to do here, say N.
706 will be called i2c-sh_mobile. 668
669 This support is also available as a module. If so, the module
670 will be called scx200_i2c.
671
672 This driver is deprecated and will be dropped soon. Use i2c-gpio
673 (or scx200_acb) instead.
674
675config SCx200_I2C_SCL
676 int "GPIO pin used for SCL"
677 depends on SCx200_I2C
678 default "12"
679 help
680 Enter the GPIO pin number used for the SCL signal. This value can
681 also be specified with a module parameter.
682
683config SCx200_I2C_SDA
684 int "GPIO pin used for SDA"
685 depends on SCx200_I2C
686 default "13"
687 help
688 Enter the GPIO pin number used for the SSA signal. This value can
689 also be specified with a module parameter.
690
691config SCx200_ACB
692 tristate "Geode ACCESS.bus support"
693 depends on X86_32 && PCI
694 help
695 Enable the use of the ACCESS.bus controllers on the Geode SCx200 and
696 SC1100 processors and the CS5535 and CS5536 Geode companion devices.
697
698 If you don't know what to do here, say N.
699
700 This support is also available as a module. If so, the module
701 will be called scx200_acb.
707 702
708endmenu 703endmenu
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index e8c882a5ea66..97dbfa2107fe 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -2,57 +2,68 @@
2# Makefile for the i2c bus drivers. 2# Makefile for the i2c bus drivers.
3# 3#
4 4
5# PC SMBus host controller drivers
5obj-$(CONFIG_I2C_ALI1535) += i2c-ali1535.o 6obj-$(CONFIG_I2C_ALI1535) += i2c-ali1535.o
6obj-$(CONFIG_I2C_ALI1563) += i2c-ali1563.o 7obj-$(CONFIG_I2C_ALI1563) += i2c-ali1563.o
7obj-$(CONFIG_I2C_ALI15X3) += i2c-ali15x3.o 8obj-$(CONFIG_I2C_ALI15X3) += i2c-ali15x3.o
8obj-$(CONFIG_I2C_AMD756) += i2c-amd756.o 9obj-$(CONFIG_I2C_AMD756) += i2c-amd756.o
9obj-$(CONFIG_I2C_AMD756_S4882) += i2c-amd756-s4882.o 10obj-$(CONFIG_I2C_AMD756_S4882) += i2c-amd756-s4882.o
10obj-$(CONFIG_I2C_AMD8111) += i2c-amd8111.o 11obj-$(CONFIG_I2C_AMD8111) += i2c-amd8111.o
12obj-$(CONFIG_I2C_I801) += i2c-i801.o
13obj-$(CONFIG_I2C_ISCH) += i2c-isch.o
14obj-$(CONFIG_I2C_NFORCE2) += i2c-nforce2.o
15obj-$(CONFIG_I2C_NFORCE2_S4985) += i2c-nforce2-s4985.o
16obj-$(CONFIG_I2C_PIIX4) += i2c-piix4.o
17obj-$(CONFIG_I2C_SIS5595) += i2c-sis5595.o
18obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o
19obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o
20obj-$(CONFIG_I2C_VIA) += i2c-via.o
21obj-$(CONFIG_I2C_VIAPRO) += i2c-viapro.o
22
23# Mac SMBus host controller drivers
24obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o
25obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o
26
27# Embebbed system I2C/SMBus host controller drivers
11obj-$(CONFIG_I2C_AT91) += i2c-at91.o 28obj-$(CONFIG_I2C_AT91) += i2c-at91.o
12obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o 29obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
13obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o 30obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
31obj-$(CONFIG_I2C_CPM) += i2c-cpm.o
14obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o 32obj-$(CONFIG_I2C_DAVINCI) += i2c-davinci.o
15obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o
16obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o 33obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o
17obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o
18obj-$(CONFIG_I2C_I801) += i2c-i801.o
19obj-$(CONFIG_I2C_I810) += i2c-i810.o
20obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o 34obj-$(CONFIG_I2C_IBM_IIC) += i2c-ibm_iic.o
21obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o 35obj-$(CONFIG_I2C_IOP3XX) += i2c-iop3xx.o
22obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o 36obj-$(CONFIG_I2C_IXP2000) += i2c-ixp2000.o
23obj-$(CONFIG_I2C_POWERMAC) += i2c-powermac.o
24obj-$(CONFIG_I2C_MPC) += i2c-mpc.o 37obj-$(CONFIG_I2C_MPC) += i2c-mpc.o
25obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o 38obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o
26obj-$(CONFIG_I2C_NFORCE2) += i2c-nforce2.o
27obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o 39obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o
28obj-$(CONFIG_I2C_OMAP) += i2c-omap.o 40obj-$(CONFIG_I2C_OMAP) += i2c-omap.o
29obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o
30obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o
31obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o 41obj-$(CONFIG_I2C_PASEMI) += i2c-pasemi.o
32obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o
33obj-$(CONFIG_I2C_PCA_PLATFORM) += i2c-pca-platform.o
34obj-$(CONFIG_I2C_PIIX4) += i2c-piix4.o
35obj-$(CONFIG_I2C_PMCMSP) += i2c-pmcmsp.o
36obj-$(CONFIG_I2C_PNX) += i2c-pnx.o 42obj-$(CONFIG_I2C_PNX) += i2c-pnx.o
37obj-$(CONFIG_I2C_PROSAVAGE) += i2c-prosavage.o
38obj-$(CONFIG_I2C_PXA) += i2c-pxa.o 43obj-$(CONFIG_I2C_PXA) += i2c-pxa.o
39obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o 44obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o
40obj-$(CONFIG_I2C_SAVAGE4) += i2c-savage4.o
41obj-$(CONFIG_I2C_SH7760) += i2c-sh7760.o 45obj-$(CONFIG_I2C_SH7760) += i2c-sh7760.o
42obj-$(CONFIG_I2C_SH_MOBILE) += i2c-sh_mobile.o 46obj-$(CONFIG_I2C_SH_MOBILE) += i2c-sh_mobile.o
43obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o
44obj-$(CONFIG_I2C_SIMTEC) += i2c-simtec.o 47obj-$(CONFIG_I2C_SIMTEC) += i2c-simtec.o
45obj-$(CONFIG_I2C_SIS5595) += i2c-sis5595.o 48obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o
46obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o 49
47obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o 50# External I2C/SMBus adapter drivers
48obj-$(CONFIG_I2C_STUB) += i2c-stub.o 51obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o
52obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o
49obj-$(CONFIG_I2C_TAOS_EVM) += i2c-taos-evm.o 53obj-$(CONFIG_I2C_TAOS_EVM) += i2c-taos-evm.o
50obj-$(CONFIG_I2C_TINY_USB) += i2c-tiny-usb.o 54obj-$(CONFIG_I2C_TINY_USB) += i2c-tiny-usb.o
51obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o 55
52obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o 56# Graphics adapter I2C/DDC channel drivers
53obj-$(CONFIG_I2C_VIA) += i2c-via.o
54obj-$(CONFIG_I2C_VIAPRO) += i2c-viapro.o
55obj-$(CONFIG_I2C_VOODOO3) += i2c-voodoo3.o 57obj-$(CONFIG_I2C_VOODOO3) += i2c-voodoo3.o
58
59# Other I2C/SMBus bus drivers
60obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o
61obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o
62obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o
63obj-$(CONFIG_I2C_PCA_PLATFORM) += i2c-pca-platform.o
64obj-$(CONFIG_I2C_PMCMSP) += i2c-pmcmsp.o
65obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o
66obj-$(CONFIG_I2C_STUB) += i2c-stub.o
56obj-$(CONFIG_SCx200_ACB) += scx200_acb.o 67obj-$(CONFIG_SCx200_ACB) += scx200_acb.o
57obj-$(CONFIG_SCx200_I2C) += scx200_i2c.o 68obj-$(CONFIG_SCx200_I2C) += scx200_i2c.o
58 69
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index f14372ac2fc5..9cead9b9458e 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -1,6 +1,4 @@
1/* 1/*
2 i2c-ali1535.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl>, 2 Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl>,
5 Philip Edelbrock <phil@netroedge.com>, 3 Philip Edelbrock <phil@netroedge.com>,
6 Mark D. Studebaker <mdsxyz123@yahoo.com>, 4 Mark D. Studebaker <mdsxyz123@yahoo.com>,
@@ -61,6 +59,7 @@
61#include <linux/ioport.h> 59#include <linux/ioport.h>
62#include <linux/i2c.h> 60#include <linux/i2c.h>
63#include <linux/init.h> 61#include <linux/init.h>
62#include <linux/acpi.h>
64#include <asm/io.h> 63#include <asm/io.h>
65 64
66 65
@@ -159,6 +158,11 @@ static int ali1535_setup(struct pci_dev *dev)
159 goto exit; 158 goto exit;
160 } 159 }
161 160
161 retval = acpi_check_region(ali1535_smba, ALI1535_SMB_IOSIZE,
162 ali1535_driver.name);
163 if (retval)
164 goto exit;
165
162 if (!request_region(ali1535_smba, ALI1535_SMB_IOSIZE, 166 if (!request_region(ali1535_smba, ALI1535_SMB_IOSIZE,
163 ali1535_driver.name)) { 167 ali1535_driver.name)) {
164 dev_err(&dev->dev, "ALI1535_smb region 0x%x already in use!\n", 168 dev_err(&dev->dev, "ALI1535_smb region 0x%x already in use!\n",
@@ -259,7 +263,7 @@ static int ali1535_transaction(struct i2c_adapter *adap)
259 dev_err(&adap->dev, 263 dev_err(&adap->dev,
260 "SMBus reset failed! (0x%02x) - controller or " 264 "SMBus reset failed! (0x%02x) - controller or "
261 "device on bus is probably hung\n", temp); 265 "device on bus is probably hung\n", temp);
262 return -1; 266 return -EBUSY;
263 } 267 }
264 } else { 268 } else {
265 /* check and clear done bit */ 269 /* check and clear done bit */
@@ -281,12 +285,12 @@ static int ali1535_transaction(struct i2c_adapter *adap)
281 285
282 /* If the SMBus is still busy, we give up */ 286 /* If the SMBus is still busy, we give up */
283 if (timeout >= MAX_TIMEOUT) { 287 if (timeout >= MAX_TIMEOUT) {
284 result = -1; 288 result = -ETIMEDOUT;
285 dev_err(&adap->dev, "SMBus Timeout!\n"); 289 dev_err(&adap->dev, "SMBus Timeout!\n");
286 } 290 }
287 291
288 if (temp & ALI1535_STS_FAIL) { 292 if (temp & ALI1535_STS_FAIL) {
289 result = -1; 293 result = -EIO;
290 dev_dbg(&adap->dev, "Error: Failed bus transaction\n"); 294 dev_dbg(&adap->dev, "Error: Failed bus transaction\n");
291 } 295 }
292 296
@@ -295,7 +299,7 @@ static int ali1535_transaction(struct i2c_adapter *adap)
295 * do a printk. This means that bus collisions go unreported. 299 * do a printk. This means that bus collisions go unreported.
296 */ 300 */
297 if (temp & ALI1535_STS_BUSERR) { 301 if (temp & ALI1535_STS_BUSERR) {
298 result = -1; 302 result = -ENXIO;
299 dev_dbg(&adap->dev, 303 dev_dbg(&adap->dev,
300 "Error: no response or bus collision ADD=%02x\n", 304 "Error: no response or bus collision ADD=%02x\n",
301 inb_p(SMBHSTADD)); 305 inb_p(SMBHSTADD));
@@ -303,13 +307,13 @@ static int ali1535_transaction(struct i2c_adapter *adap)
303 307
304 /* haven't ever seen this */ 308 /* haven't ever seen this */
305 if (temp & ALI1535_STS_DEV) { 309 if (temp & ALI1535_STS_DEV) {
306 result = -1; 310 result = -EIO;
307 dev_err(&adap->dev, "Error: device error\n"); 311 dev_err(&adap->dev, "Error: device error\n");
308 } 312 }
309 313
310 /* check to see if the "command complete" indication is set */ 314 /* check to see if the "command complete" indication is set */
311 if (!(temp & ALI1535_STS_DONE)) { 315 if (!(temp & ALI1535_STS_DONE)) {
312 result = -1; 316 result = -ETIMEDOUT;
313 dev_err(&adap->dev, "Error: command never completed\n"); 317 dev_err(&adap->dev, "Error: command never completed\n");
314 } 318 }
315 319
@@ -332,7 +336,7 @@ static int ali1535_transaction(struct i2c_adapter *adap)
332 return result; 336 return result;
333} 337}
334 338
335/* Return -1 on error. */ 339/* Return negative errno on error. */
336static s32 ali1535_access(struct i2c_adapter *adap, u16 addr, 340static s32 ali1535_access(struct i2c_adapter *adap, u16 addr,
337 unsigned short flags, char read_write, u8 command, 341 unsigned short flags, char read_write, u8 command,
338 int size, union i2c_smbus_data *data) 342 int size, union i2c_smbus_data *data)
@@ -357,10 +361,6 @@ static s32 ali1535_access(struct i2c_adapter *adap, u16 addr,
357 outb_p(0xFF, SMBHSTSTS); 361 outb_p(0xFF, SMBHSTSTS);
358 362
359 switch (size) { 363 switch (size) {
360 case I2C_SMBUS_PROC_CALL:
361 dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n");
362 result = -1;
363 goto EXIT;
364 case I2C_SMBUS_QUICK: 364 case I2C_SMBUS_QUICK:
365 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 365 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
366 SMBHSTADD); 366 SMBHSTADD);
@@ -418,13 +418,15 @@ static s32 ali1535_access(struct i2c_adapter *adap, u16 addr,
418 outb_p(data->block[i], SMBBLKDAT); 418 outb_p(data->block[i], SMBBLKDAT);
419 } 419 }
420 break; 420 break;
421 default:
422 dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
423 result = -EOPNOTSUPP;
424 goto EXIT;
421 } 425 }
422 426
423 if (ali1535_transaction(adap)) { 427 result = ali1535_transaction(adap);
424 /* Error in transaction */ 428 if (result)
425 result = -1;
426 goto EXIT; 429 goto EXIT;
427 }
428 430
429 if ((read_write == I2C_SMBUS_WRITE) || (size == ALI1535_QUICK)) { 431 if ((read_write == I2C_SMBUS_WRITE) || (size == ALI1535_QUICK)) {
430 result = 0; 432 result = 0;
@@ -475,7 +477,7 @@ static const struct i2c_algorithm smbus_algorithm = {
475static struct i2c_adapter ali1535_adapter = { 477static struct i2c_adapter ali1535_adapter = {
476 .owner = THIS_MODULE, 478 .owner = THIS_MODULE,
477 .id = I2C_HW_SMBUS_ALI1535, 479 .id = I2C_HW_SMBUS_ALI1535,
478 .class = I2C_CLASS_HWMON, 480 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
479 .algo = &smbus_algorithm, 481 .algo = &smbus_algorithm,
480}; 482};
481 483
diff --git a/drivers/i2c/busses/i2c-ali1563.c b/drivers/i2c/busses/i2c-ali1563.c
index 6b68074e518a..fc3e5b026423 100644
--- a/drivers/i2c/busses/i2c-ali1563.c
+++ b/drivers/i2c/busses/i2c-ali1563.c
@@ -21,6 +21,7 @@
21#include <linux/i2c.h> 21#include <linux/i2c.h>
22#include <linux/pci.h> 22#include <linux/pci.h>
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/acpi.h>
24 25
25#define ALI1563_MAX_TIMEOUT 500 26#define ALI1563_MAX_TIMEOUT 500
26#define ALI1563_SMBBA 0x80 27#define ALI1563_SMBBA 0x80
@@ -67,6 +68,7 @@ static int ali1563_transaction(struct i2c_adapter * a, int size)
67{ 68{
68 u32 data; 69 u32 data;
69 int timeout; 70 int timeout;
71 int status = -EIO;
70 72
71 dev_dbg(&a->dev, "Transaction (pre): STS=%02x, CNTL1=%02x, " 73 dev_dbg(&a->dev, "Transaction (pre): STS=%02x, CNTL1=%02x, "
72 "CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n", 74 "CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n",
@@ -103,13 +105,15 @@ static int ali1563_transaction(struct i2c_adapter * a, int size)
103 /* Issue 'kill' to host controller */ 105 /* Issue 'kill' to host controller */
104 outb_p(HST_CNTL2_KILL,SMB_HST_CNTL2); 106 outb_p(HST_CNTL2_KILL,SMB_HST_CNTL2);
105 data = inb_p(SMB_HST_STS); 107 data = inb_p(SMB_HST_STS);
108 status = -ETIMEDOUT;
106 } 109 }
107 110
108 /* device error - no response, ignore the autodetection case */ 111 /* device error - no response, ignore the autodetection case */
109 if ((data & HST_STS_DEVERR) && (size != HST_CNTL2_QUICK)) { 112 if (data & HST_STS_DEVERR) {
110 dev_err(&a->dev, "Device error!\n"); 113 if (size != HST_CNTL2_QUICK)
114 dev_err(&a->dev, "Device error!\n");
115 status = -ENXIO;
111 } 116 }
112
113 /* bus collision */ 117 /* bus collision */
114 if (data & HST_STS_BUSERR) { 118 if (data & HST_STS_BUSERR) {
115 dev_err(&a->dev, "Bus collision!\n"); 119 dev_err(&a->dev, "Bus collision!\n");
@@ -122,13 +126,14 @@ static int ali1563_transaction(struct i2c_adapter * a, int size)
122 outb_p(0x0,SMB_HST_CNTL2); 126 outb_p(0x0,SMB_HST_CNTL2);
123 } 127 }
124 128
125 return -1; 129 return status;
126} 130}
127 131
128static int ali1563_block_start(struct i2c_adapter * a) 132static int ali1563_block_start(struct i2c_adapter * a)
129{ 133{
130 u32 data; 134 u32 data;
131 int timeout; 135 int timeout;
136 int status = -EIO;
132 137
133 dev_dbg(&a->dev, "Block (pre): STS=%02x, CNTL1=%02x, " 138 dev_dbg(&a->dev, "Block (pre): STS=%02x, CNTL1=%02x, "
134 "CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n", 139 "CNTL2=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, DAT1=%02x\n",
@@ -164,13 +169,20 @@ static int ali1563_block_start(struct i2c_adapter * a)
164 169
165 if (timeout && !(data & HST_STS_BAD)) 170 if (timeout && !(data & HST_STS_BAD))
166 return 0; 171 return 0;
172
173 if (timeout == 0)
174 status = -ETIMEDOUT;
175
176 if (data & HST_STS_DEVERR)
177 status = -ENXIO;
178
167 dev_err(&a->dev, "SMBus Error: %s%s%s%s%s\n", 179 dev_err(&a->dev, "SMBus Error: %s%s%s%s%s\n",
168 timeout ? "Timeout " : "", 180 timeout ? "" : "Timeout ",
169 data & HST_STS_FAIL ? "Transaction Failed " : "", 181 data & HST_STS_FAIL ? "Transaction Failed " : "",
170 data & HST_STS_BUSERR ? "No response or Bus Collision " : "", 182 data & HST_STS_BUSERR ? "No response or Bus Collision " : "",
171 data & HST_STS_DEVERR ? "Device Error " : "", 183 data & HST_STS_DEVERR ? "Device Error " : "",
172 !(data & HST_STS_DONE) ? "Transaction Never Finished " : ""); 184 !(data & HST_STS_DONE) ? "Transaction Never Finished " : "");
173 return -1; 185 return status;
174} 186}
175 187
176static int ali1563_block(struct i2c_adapter * a, union i2c_smbus_data * data, u8 rw) 188static int ali1563_block(struct i2c_adapter * a, union i2c_smbus_data * data, u8 rw)
@@ -235,10 +247,6 @@ static s32 ali1563_access(struct i2c_adapter * a, u16 addr,
235 247
236 /* Map the size to what the chip understands */ 248 /* Map the size to what the chip understands */
237 switch (size) { 249 switch (size) {
238 case I2C_SMBUS_PROC_CALL:
239 dev_err(&a->dev, "I2C_SMBUS_PROC_CALL not supported!\n");
240 error = -EINVAL;
241 break;
242 case I2C_SMBUS_QUICK: 250 case I2C_SMBUS_QUICK:
243 size = HST_CNTL2_QUICK; 251 size = HST_CNTL2_QUICK;
244 break; 252 break;
@@ -254,6 +262,10 @@ static s32 ali1563_access(struct i2c_adapter * a, u16 addr,
254 case I2C_SMBUS_BLOCK_DATA: 262 case I2C_SMBUS_BLOCK_DATA:
255 size = HST_CNTL2_BLOCK; 263 size = HST_CNTL2_BLOCK;
256 break; 264 break;
265 default:
266 dev_warn(&a->dev, "Unsupported transaction %d\n", size);
267 error = -EOPNOTSUPP;
268 goto Done;
257 } 269 }
258 270
259 outb_p(((addr & 0x7f) << 1) | (rw & 0x01), SMB_HST_ADD); 271 outb_p(((addr & 0x7f) << 1) | (rw & 0x01), SMB_HST_ADD);
@@ -345,6 +357,10 @@ static int __devinit ali1563_setup(struct pci_dev * dev)
345 } 357 }
346 } 358 }
347 359
360 if (acpi_check_region(ali1563_smba, ALI1563_SMB_IOSIZE,
361 ali1563_pci_driver.name))
362 goto Err;
363
348 if (!request_region(ali1563_smba, ALI1563_SMB_IOSIZE, 364 if (!request_region(ali1563_smba, ALI1563_SMB_IOSIZE,
349 ali1563_pci_driver.name)) { 365 ali1563_pci_driver.name)) {
350 dev_err(&dev->dev, "Could not allocate I/O space at 0x%04x\n", 366 dev_err(&dev->dev, "Could not allocate I/O space at 0x%04x\n",
@@ -371,7 +387,7 @@ static const struct i2c_algorithm ali1563_algorithm = {
371static struct i2c_adapter ali1563_adapter = { 387static struct i2c_adapter ali1563_adapter = {
372 .owner = THIS_MODULE, 388 .owner = THIS_MODULE,
373 .id = I2C_HW_SMBUS_ALI1563, 389 .id = I2C_HW_SMBUS_ALI1563,
374 .class = I2C_CLASS_HWMON, 390 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
375 .algo = &ali1563_algorithm, 391 .algo = &ali1563_algorithm,
376}; 392};
377 393
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index 93bf87d70961..234fdde7d40e 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -1,6 +1,4 @@
1/* 1/*
2 ali15x3.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 1999 Frodo Looijaard <frodol@dds.nl> and 2 Copyright (c) 1999 Frodo Looijaard <frodol@dds.nl> and
5 Philip Edelbrock <phil@netroedge.com> and 3 Philip Edelbrock <phil@netroedge.com> and
6 Mark D. Studebaker <mdsxyz123@yahoo.com> 4 Mark D. Studebaker <mdsxyz123@yahoo.com>
@@ -68,6 +66,7 @@
68#include <linux/delay.h> 66#include <linux/delay.h>
69#include <linux/i2c.h> 67#include <linux/i2c.h>
70#include <linux/init.h> 68#include <linux/init.h>
69#include <linux/acpi.h>
71#include <asm/io.h> 70#include <asm/io.h>
72 71
73/* ALI15X3 SMBus address offsets */ 72/* ALI15X3 SMBus address offsets */
@@ -166,6 +165,10 @@ static int ali15x3_setup(struct pci_dev *ALI15X3_dev)
166 if(force_addr) 165 if(force_addr)
167 ali15x3_smba = force_addr & ~(ALI15X3_SMB_IOSIZE - 1); 166 ali15x3_smba = force_addr & ~(ALI15X3_SMB_IOSIZE - 1);
168 167
168 if (acpi_check_region(ali15x3_smba, ALI15X3_SMB_IOSIZE,
169 ali15x3_driver.name))
170 return -EBUSY;
171
169 if (!request_region(ali15x3_smba, ALI15X3_SMB_IOSIZE, 172 if (!request_region(ali15x3_smba, ALI15X3_SMB_IOSIZE,
170 ali15x3_driver.name)) { 173 ali15x3_driver.name)) {
171 dev_err(&ALI15X3_dev->dev, 174 dev_err(&ALI15X3_dev->dev,
@@ -282,7 +285,7 @@ static int ali15x3_transaction(struct i2c_adapter *adap)
282 dev_err(&adap->dev, "SMBus reset failed! (0x%02x) - " 285 dev_err(&adap->dev, "SMBus reset failed! (0x%02x) - "
283 "controller or device on bus is probably hung\n", 286 "controller or device on bus is probably hung\n",
284 temp); 287 temp);
285 return -1; 288 return -EBUSY;
286 } 289 }
287 } else { 290 } else {
288 /* check and clear done bit */ 291 /* check and clear done bit */
@@ -304,12 +307,12 @@ static int ali15x3_transaction(struct i2c_adapter *adap)
304 307
305 /* If the SMBus is still busy, we give up */ 308 /* If the SMBus is still busy, we give up */
306 if (timeout >= MAX_TIMEOUT) { 309 if (timeout >= MAX_TIMEOUT) {
307 result = -1; 310 result = -ETIMEDOUT;
308 dev_err(&adap->dev, "SMBus Timeout!\n"); 311 dev_err(&adap->dev, "SMBus Timeout!\n");
309 } 312 }
310 313
311 if (temp & ALI15X3_STS_TERM) { 314 if (temp & ALI15X3_STS_TERM) {
312 result = -1; 315 result = -EIO;
313 dev_dbg(&adap->dev, "Error: Failed bus transaction\n"); 316 dev_dbg(&adap->dev, "Error: Failed bus transaction\n");
314 } 317 }
315 318
@@ -320,7 +323,7 @@ static int ali15x3_transaction(struct i2c_adapter *adap)
320 This means that bus collisions go unreported. 323 This means that bus collisions go unreported.
321 */ 324 */
322 if (temp & ALI15X3_STS_COLL) { 325 if (temp & ALI15X3_STS_COLL) {
323 result = -1; 326 result = -ENXIO;
324 dev_dbg(&adap->dev, 327 dev_dbg(&adap->dev,
325 "Error: no response or bus collision ADD=%02x\n", 328 "Error: no response or bus collision ADD=%02x\n",
326 inb_p(SMBHSTADD)); 329 inb_p(SMBHSTADD));
@@ -328,7 +331,7 @@ static int ali15x3_transaction(struct i2c_adapter *adap)
328 331
329 /* haven't ever seen this */ 332 /* haven't ever seen this */
330 if (temp & ALI15X3_STS_DEV) { 333 if (temp & ALI15X3_STS_DEV) {
331 result = -1; 334 result = -EIO;
332 dev_err(&adap->dev, "Error: device error\n"); 335 dev_err(&adap->dev, "Error: device error\n");
333 } 336 }
334 dev_dbg(&adap->dev, "Transaction (post): STS=%02x, CNT=%02x, CMD=%02x, " 337 dev_dbg(&adap->dev, "Transaction (post): STS=%02x, CNT=%02x, CMD=%02x, "
@@ -338,7 +341,7 @@ static int ali15x3_transaction(struct i2c_adapter *adap)
338 return result; 341 return result;
339} 342}
340 343
341/* Return -1 on error. */ 344/* Return negative errno on error. */
342static s32 ali15x3_access(struct i2c_adapter * adap, u16 addr, 345static s32 ali15x3_access(struct i2c_adapter * adap, u16 addr,
343 unsigned short flags, char read_write, u8 command, 346 unsigned short flags, char read_write, u8 command,
344 int size, union i2c_smbus_data * data) 347 int size, union i2c_smbus_data * data)
@@ -362,9 +365,6 @@ static s32 ali15x3_access(struct i2c_adapter * adap, u16 addr,
362 } 365 }
363 366
364 switch (size) { 367 switch (size) {
365 case I2C_SMBUS_PROC_CALL:
366 dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n");
367 return -1;
368 case I2C_SMBUS_QUICK: 368 case I2C_SMBUS_QUICK:
369 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 369 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
370 SMBHSTADD); 370 SMBHSTADD);
@@ -417,12 +417,16 @@ static s32 ali15x3_access(struct i2c_adapter * adap, u16 addr,
417 } 417 }
418 size = ALI15X3_BLOCK_DATA; 418 size = ALI15X3_BLOCK_DATA;
419 break; 419 break;
420 default:
421 dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
422 return -EOPNOTSUPP;
420 } 423 }
421 424
422 outb_p(size, SMBHSTCNT); /* output command */ 425 outb_p(size, SMBHSTCNT); /* output command */
423 426
424 if (ali15x3_transaction(adap)) /* Error in transaction */ 427 temp = ali15x3_transaction(adap);
425 return -1; 428 if (temp)
429 return temp;
426 430
427 if ((read_write == I2C_SMBUS_WRITE) || (size == ALI15X3_QUICK)) 431 if ((read_write == I2C_SMBUS_WRITE) || (size == ALI15X3_QUICK))
428 return 0; 432 return 0;
@@ -470,7 +474,7 @@ static const struct i2c_algorithm smbus_algorithm = {
470static struct i2c_adapter ali15x3_adapter = { 474static struct i2c_adapter ali15x3_adapter = {
471 .owner = THIS_MODULE, 475 .owner = THIS_MODULE,
472 .id = I2C_HW_SMBUS_ALI15X3, 476 .id = I2C_HW_SMBUS_ALI15X3,
473 .class = I2C_CLASS_HWMON, 477 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
474 .algo = &smbus_algorithm, 478 .algo = &smbus_algorithm,
475}; 479};
476 480
diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
index c38a0a112208..72872d1e63ef 100644
--- a/drivers/i2c/busses/i2c-amd756-s4882.c
+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
@@ -58,7 +58,7 @@ static s32 amd756_access_virt0(struct i2c_adapter * adap, u16 addr,
58 /* We exclude the multiplexed addresses */ 58 /* We exclude the multiplexed addresses */
59 if (addr == 0x4c || (addr & 0xfc) == 0x50 || (addr & 0xfc) == 0x30 59 if (addr == 0x4c || (addr & 0xfc) == 0x50 || (addr & 0xfc) == 0x30
60 || addr == 0x18) 60 || addr == 0x18)
61 return -1; 61 return -ENXIO;
62 62
63 mutex_lock(&amd756_lock); 63 mutex_lock(&amd756_lock);
64 64
@@ -86,7 +86,7 @@ static inline s32 amd756_access_channel(struct i2c_adapter * adap, u16 addr,
86 86
87 /* We exclude the non-multiplexed addresses */ 87 /* We exclude the non-multiplexed addresses */
88 if (addr != 0x4c && (addr & 0xfc) != 0x50 && (addr & 0xfc) != 0x30) 88 if (addr != 0x4c && (addr & 0xfc) != 0x50 && (addr & 0xfc) != 0x30)
89 return -1; 89 return -ENXIO;
90 90
91 mutex_lock(&amd756_lock); 91 mutex_lock(&amd756_lock);
92 92
@@ -155,6 +155,16 @@ static int __init amd756_s4882_init(void)
155 int i, error; 155 int i, error;
156 union i2c_smbus_data ioconfig; 156 union i2c_smbus_data ioconfig;
157 157
158 /* Configure the PCA9556 multiplexer */
159 ioconfig.byte = 0x00; /* All I/O to output mode */
160 error = i2c_smbus_xfer(&amd756_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03,
161 I2C_SMBUS_BYTE_DATA, &ioconfig);
162 if (error) {
163 dev_err(&amd756_smbus.dev, "PCA9556 configuration failed\n");
164 error = -EIO;
165 goto ERROR0;
166 }
167
158 /* Unregister physical bus */ 168 /* Unregister physical bus */
159 error = i2c_del_adapter(&amd756_smbus); 169 error = i2c_del_adapter(&amd756_smbus);
160 if (error) { 170 if (error) {
@@ -198,22 +208,11 @@ static int __init amd756_s4882_init(void)
198 s4882_algo[3].smbus_xfer = amd756_access_virt3; 208 s4882_algo[3].smbus_xfer = amd756_access_virt3;
199 s4882_algo[4].smbus_xfer = amd756_access_virt4; 209 s4882_algo[4].smbus_xfer = amd756_access_virt4;
200 210
201 /* Configure the PCA9556 multiplexer */
202 ioconfig.byte = 0x00; /* All I/O to output mode */
203 error = amd756_smbus.algo->smbus_xfer(&amd756_smbus, 0x18, 0,
204 I2C_SMBUS_WRITE, 0x03,
205 I2C_SMBUS_BYTE_DATA, &ioconfig);
206 if (error) {
207 dev_err(&amd756_smbus.dev, "PCA9556 configuration failed\n");
208 error = -EIO;
209 goto ERROR3;
210 }
211
212 /* Register virtual adapters */ 211 /* Register virtual adapters */
213 for (i = 0; i < 5; i++) { 212 for (i = 0; i < 5; i++) {
214 error = i2c_add_adapter(s4882_adapter+i); 213 error = i2c_add_adapter(s4882_adapter+i);
215 if (error) { 214 if (error) {
216 dev_err(&amd756_smbus.dev, 215 printk(KERN_ERR "i2c-amd756-s4882: "
217 "Virtual adapter %d registration " 216 "Virtual adapter %d registration "
218 "failed, module not inserted\n", i); 217 "failed, module not inserted\n", i);
219 for (i--; i >= 0; i--) 218 for (i--; i >= 0; i--)
@@ -252,8 +251,8 @@ static void __exit amd756_s4882_exit(void)
252 251
253 /* Restore physical bus */ 252 /* Restore physical bus */
254 if (i2c_add_adapter(&amd756_smbus)) 253 if (i2c_add_adapter(&amd756_smbus))
255 dev_err(&amd756_smbus.dev, "Physical bus restoration " 254 printk(KERN_ERR "i2c-amd756-s4882: "
256 "failed\n"); 255 "Physical bus restoration failed\n");
257} 256}
258 257
259MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 258MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index 2fa43183d375..1ea39254dac6 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -1,7 +1,4 @@
1/* 1/*
2 amd756.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4
5 Copyright (c) 1999-2002 Merlin Hughes <merlin@merlin.org> 2 Copyright (c) 1999-2002 Merlin Hughes <merlin@merlin.org>
6 3
7 Shamelessly ripped from i2c-piix4.c: 4 Shamelessly ripped from i2c-piix4.c:
@@ -45,6 +42,7 @@
45#include <linux/ioport.h> 42#include <linux/ioport.h>
46#include <linux/i2c.h> 43#include <linux/i2c.h>
47#include <linux/init.h> 44#include <linux/init.h>
45#include <linux/acpi.h>
48#include <asm/io.h> 46#include <asm/io.h>
49 47
50/* AMD756 SMBus address offsets */ 48/* AMD756 SMBus address offsets */
@@ -151,17 +149,17 @@ static int amd756_transaction(struct i2c_adapter *adap)
151 } 149 }
152 150
153 if (temp & GS_PRERR_STS) { 151 if (temp & GS_PRERR_STS) {
154 result = -1; 152 result = -ENXIO;
155 dev_dbg(&adap->dev, "SMBus Protocol error (no response)!\n"); 153 dev_dbg(&adap->dev, "SMBus Protocol error (no response)!\n");
156 } 154 }
157 155
158 if (temp & GS_COL_STS) { 156 if (temp & GS_COL_STS) {
159 result = -1; 157 result = -EIO;
160 dev_warn(&adap->dev, "SMBus collision!\n"); 158 dev_warn(&adap->dev, "SMBus collision!\n");
161 } 159 }
162 160
163 if (temp & GS_TO_STS) { 161 if (temp & GS_TO_STS) {
164 result = -1; 162 result = -ETIMEDOUT;
165 dev_dbg(&adap->dev, "SMBus protocol timeout!\n"); 163 dev_dbg(&adap->dev, "SMBus protocol timeout!\n");
166 } 164 }
167 165
@@ -189,22 +187,18 @@ static int amd756_transaction(struct i2c_adapter *adap)
189 outw_p(inw(SMB_GLOBAL_ENABLE) | GE_ABORT, SMB_GLOBAL_ENABLE); 187 outw_p(inw(SMB_GLOBAL_ENABLE) | GE_ABORT, SMB_GLOBAL_ENABLE);
190 msleep(100); 188 msleep(100);
191 outw_p(GS_CLEAR_STS, SMB_GLOBAL_STATUS); 189 outw_p(GS_CLEAR_STS, SMB_GLOBAL_STATUS);
192 return -1; 190 return -EIO;
193} 191}
194 192
195/* Return -1 on error. */ 193/* Return negative errno on error. */
196static s32 amd756_access(struct i2c_adapter * adap, u16 addr, 194static s32 amd756_access(struct i2c_adapter * adap, u16 addr,
197 unsigned short flags, char read_write, 195 unsigned short flags, char read_write,
198 u8 command, int size, union i2c_smbus_data * data) 196 u8 command, int size, union i2c_smbus_data * data)
199{ 197{
200 int i, len; 198 int i, len;
199 int status;
201 200
202 /** TODO: Should I supporte the 10-bit transfers? */
203 switch (size) { 201 switch (size) {
204 case I2C_SMBUS_PROC_CALL:
205 dev_dbg(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n");
206 /* TODO: Well... It is supported, I'm just not sure what to do here... */
207 return -1;
208 case I2C_SMBUS_QUICK: 202 case I2C_SMBUS_QUICK:
209 outw_p(((addr & 0x7f) << 1) | (read_write & 0x01), 203 outw_p(((addr & 0x7f) << 1) | (read_write & 0x01),
210 SMB_HOST_ADDRESS); 204 SMB_HOST_ADDRESS);
@@ -251,13 +245,17 @@ static s32 amd756_access(struct i2c_adapter * adap, u16 addr,
251 } 245 }
252 size = AMD756_BLOCK_DATA; 246 size = AMD756_BLOCK_DATA;
253 break; 247 break;
248 default:
249 dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
250 return -EOPNOTSUPP;
254 } 251 }
255 252
256 /* How about enabling interrupts... */ 253 /* How about enabling interrupts... */
257 outw_p(size & GE_CYC_TYPE_MASK, SMB_GLOBAL_ENABLE); 254 outw_p(size & GE_CYC_TYPE_MASK, SMB_GLOBAL_ENABLE);
258 255
259 if (amd756_transaction(adap)) /* Error in transaction */ 256 status = amd756_transaction(adap);
260 return -1; 257 if (status)
258 return status;
261 259
262 if ((read_write == I2C_SMBUS_WRITE) || (size == AMD756_QUICK)) 260 if ((read_write == I2C_SMBUS_WRITE) || (size == AMD756_QUICK))
263 return 0; 261 return 0;
@@ -290,7 +288,7 @@ static u32 amd756_func(struct i2c_adapter *adapter)
290{ 288{
291 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 289 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
292 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 290 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
293 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL; 291 I2C_FUNC_SMBUS_BLOCK_DATA;
294} 292}
295 293
296static const struct i2c_algorithm smbus_algorithm = { 294static const struct i2c_algorithm smbus_algorithm = {
@@ -301,7 +299,7 @@ static const struct i2c_algorithm smbus_algorithm = {
301struct i2c_adapter amd756_smbus = { 299struct i2c_adapter amd756_smbus = {
302 .owner = THIS_MODULE, 300 .owner = THIS_MODULE,
303 .id = I2C_HW_SMBUS_AMD756, 301 .id = I2C_HW_SMBUS_AMD756,
304 .class = I2C_CLASS_HWMON, 302 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
305 .algo = &smbus_algorithm, 303 .algo = &smbus_algorithm,
306}; 304};
307 305
@@ -368,6 +366,11 @@ static int __devinit amd756_probe(struct pci_dev *pdev,
368 amd756_ioport += SMB_ADDR_OFFSET; 366 amd756_ioport += SMB_ADDR_OFFSET;
369 } 367 }
370 368
369 error = acpi_check_region(amd756_ioport, SMB_IOSIZE,
370 amd756_driver.name);
371 if (error)
372 return error;
373
371 if (!request_region(amd756_ioport, SMB_IOSIZE, amd756_driver.name)) { 374 if (!request_region(amd756_ioport, SMB_IOSIZE, amd756_driver.name)) {
372 dev_err(&pdev->dev, "SMB region 0x%x already in use!\n", 375 dev_err(&pdev->dev, "SMB region 0x%x already in use!\n",
373 amd756_ioport); 376 amd756_ioport);
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c
index 5d1a27ef2504..3972208876b3 100644
--- a/drivers/i2c/busses/i2c-amd8111.c
+++ b/drivers/i2c/busses/i2c-amd8111.c
@@ -16,6 +16,7 @@
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/i2c.h> 17#include <linux/i2c.h>
18#include <linux/delay.h> 18#include <linux/delay.h>
19#include <linux/acpi.h>
19#include <asm/io.h> 20#include <asm/io.h>
20 21
21MODULE_LICENSE("GPL"); 22MODULE_LICENSE("GPL");
@@ -77,7 +78,7 @@ static unsigned int amd_ec_wait_write(struct amd_smbus *smbus)
77 if (!timeout) { 78 if (!timeout) {
78 dev_warn(&smbus->dev->dev, 79 dev_warn(&smbus->dev->dev,
79 "Timeout while waiting for IBF to clear\n"); 80 "Timeout while waiting for IBF to clear\n");
80 return -1; 81 return -ETIMEDOUT;
81 } 82 }
82 83
83 return 0; 84 return 0;
@@ -93,7 +94,7 @@ static unsigned int amd_ec_wait_read(struct amd_smbus *smbus)
93 if (!timeout) { 94 if (!timeout) {
94 dev_warn(&smbus->dev->dev, 95 dev_warn(&smbus->dev->dev,
95 "Timeout while waiting for OBF to set\n"); 96 "Timeout while waiting for OBF to set\n");
96 return -1; 97 return -ETIMEDOUT;
97 } 98 }
98 99
99 return 0; 100 return 0;
@@ -102,16 +103,21 @@ static unsigned int amd_ec_wait_read(struct amd_smbus *smbus)
102static unsigned int amd_ec_read(struct amd_smbus *smbus, unsigned char address, 103static unsigned int amd_ec_read(struct amd_smbus *smbus, unsigned char address,
103 unsigned char *data) 104 unsigned char *data)
104{ 105{
105 if (amd_ec_wait_write(smbus)) 106 int status;
106 return -1; 107
108 status = amd_ec_wait_write(smbus);
109 if (status)
110 return status;
107 outb(AMD_EC_CMD_RD, smbus->base + AMD_EC_CMD); 111 outb(AMD_EC_CMD_RD, smbus->base + AMD_EC_CMD);
108 112
109 if (amd_ec_wait_write(smbus)) 113 status = amd_ec_wait_write(smbus);
110 return -1; 114 if (status)
115 return status;
111 outb(address, smbus->base + AMD_EC_DATA); 116 outb(address, smbus->base + AMD_EC_DATA);
112 117
113 if (amd_ec_wait_read(smbus)) 118 status = amd_ec_wait_read(smbus);
114 return -1; 119 if (status)
120 return status;
115 *data = inb(smbus->base + AMD_EC_DATA); 121 *data = inb(smbus->base + AMD_EC_DATA);
116 122
117 return 0; 123 return 0;
@@ -120,16 +126,21 @@ static unsigned int amd_ec_read(struct amd_smbus *smbus, unsigned char address,
120static unsigned int amd_ec_write(struct amd_smbus *smbus, unsigned char address, 126static unsigned int amd_ec_write(struct amd_smbus *smbus, unsigned char address,
121 unsigned char data) 127 unsigned char data)
122{ 128{
123 if (amd_ec_wait_write(smbus)) 129 int status;
124 return -1; 130
131 status = amd_ec_wait_write(smbus);
132 if (status)
133 return status;
125 outb(AMD_EC_CMD_WR, smbus->base + AMD_EC_CMD); 134 outb(AMD_EC_CMD_WR, smbus->base + AMD_EC_CMD);
126 135
127 if (amd_ec_wait_write(smbus)) 136 status = amd_ec_wait_write(smbus);
128 return -1; 137 if (status)
138 return status;
129 outb(address, smbus->base + AMD_EC_DATA); 139 outb(address, smbus->base + AMD_EC_DATA);
130 140
131 if (amd_ec_wait_write(smbus)) 141 status = amd_ec_wait_write(smbus);
132 return -1; 142 if (status)
143 return status;
133 outb(data, smbus->base + AMD_EC_DATA); 144 outb(data, smbus->base + AMD_EC_DATA);
134 145
135 return 0; 146 return 0;
@@ -267,12 +278,17 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr,
267 278
268 default: 279 default:
269 dev_warn(&adap->dev, "Unsupported transaction %d\n", size); 280 dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
270 return -1; 281 return -EOPNOTSUPP;
271 } 282 }
272 283
273 amd_ec_write(smbus, AMD_SMB_ADDR, addr << 1); 284 amd_ec_write(smbus, AMD_SMB_ADDR, addr << 1);
274 amd_ec_write(smbus, AMD_SMB_PRTCL, protocol); 285 amd_ec_write(smbus, AMD_SMB_PRTCL, protocol);
275 286
287 /* FIXME this discards status from ec_read(); so temp[0] will
288 * hold stack garbage ... the rest of this routine will act
289 * nonsensically. Ignored ec_write() status might explain
290 * some such failures...
291 */
276 amd_ec_read(smbus, AMD_SMB_STS, temp + 0); 292 amd_ec_read(smbus, AMD_SMB_STS, temp + 0);
277 293
278 if (~temp[0] & AMD_SMB_STS_DONE) { 294 if (~temp[0] & AMD_SMB_STS_DONE) {
@@ -286,7 +302,7 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr,
286 } 302 }
287 303
288 if ((~temp[0] & AMD_SMB_STS_DONE) || (temp[0] & AMD_SMB_STS_STATUS)) 304 if ((~temp[0] & AMD_SMB_STS_DONE) || (temp[0] & AMD_SMB_STS_STATUS))
289 return -1; 305 return -EIO;
290 306
291 if (read_write == I2C_SMBUS_WRITE) 307 if (read_write == I2C_SMBUS_WRITE)
292 return 0; 308 return 0;
@@ -359,6 +375,10 @@ static int __devinit amd8111_probe(struct pci_dev *dev,
359 smbus->base = pci_resource_start(dev, 0); 375 smbus->base = pci_resource_start(dev, 0);
360 smbus->size = pci_resource_len(dev, 0); 376 smbus->size = pci_resource_len(dev, 0);
361 377
378 error = acpi_check_resource_conflict(&dev->resource[0]);
379 if (error)
380 goto out_kfree;
381
362 if (!request_region(smbus->base, smbus->size, amd8111_driver.name)) { 382 if (!request_region(smbus->base, smbus->size, amd8111_driver.name)) {
363 error = -EBUSY; 383 error = -EBUSY;
364 goto out_kfree; 384 goto out_kfree;
@@ -368,7 +388,7 @@ static int __devinit amd8111_probe(struct pci_dev *dev,
368 snprintf(smbus->adapter.name, sizeof(smbus->adapter.name), 388 snprintf(smbus->adapter.name, sizeof(smbus->adapter.name),
369 "SMBus2 AMD8111 adapter at %04x", smbus->base); 389 "SMBus2 AMD8111 adapter at %04x", smbus->base);
370 smbus->adapter.id = I2C_HW_SMBUS_AMD8111; 390 smbus->adapter.id = I2C_HW_SMBUS_AMD8111;
371 smbus->adapter.class = I2C_CLASS_HWMON; 391 smbus->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
372 smbus->adapter.algo = &smbus_algorithm; 392 smbus->adapter.algo = &smbus_algorithm;
373 smbus->adapter.algo_data = smbus; 393 smbus->adapter.algo_data = smbus;
374 394
diff --git a/drivers/i2c/busses/i2c-au1550.c b/drivers/i2c/busses/i2c-au1550.c
index 491718fe46b7..66a04c2c660f 100644
--- a/drivers/i2c/busses/i2c-au1550.c
+++ b/drivers/i2c/busses/i2c-au1550.c
@@ -269,9 +269,13 @@ static int
269au1550_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num) 269au1550_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
270{ 270{
271 struct i2c_au1550_data *adap = i2c_adap->algo_data; 271 struct i2c_au1550_data *adap = i2c_adap->algo_data;
272 volatile psc_smb_t *sp = (volatile psc_smb_t *)adap->psc_base;
272 struct i2c_msg *p; 273 struct i2c_msg *p;
273 int i, err = 0; 274 int i, err = 0;
274 275
276 sp->psc_ctrl = PSC_CTRL_ENABLE;
277 au_sync();
278
275 for (i = 0; !err && i < num; i++) { 279 for (i = 0; !err && i < num; i++) {
276 p = &msgs[i]; 280 p = &msgs[i];
277 err = do_address(adap, p->addr, p->flags & I2C_M_RD, 281 err = do_address(adap, p->addr, p->flags & I2C_M_RD,
@@ -288,6 +292,10 @@ au1550_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
288 */ 292 */
289 if (err == 0) 293 if (err == 0)
290 err = num; 294 err = num;
295
296 sp->psc_ctrl = PSC_CTRL_SUSPEND;
297 au_sync();
298
291 return err; 299 return err;
292} 300}
293 301
@@ -302,6 +310,61 @@ static const struct i2c_algorithm au1550_algo = {
302 .functionality = au1550_func, 310 .functionality = au1550_func,
303}; 311};
304 312
313static void i2c_au1550_setup(struct i2c_au1550_data *priv)
314{
315 volatile psc_smb_t *sp = (volatile psc_smb_t *)priv->psc_base;
316 u32 stat;
317
318 sp->psc_ctrl = PSC_CTRL_DISABLE;
319 au_sync();
320 sp->psc_sel = PSC_SEL_PS_SMBUSMODE;
321 sp->psc_smbcfg = 0;
322 au_sync();
323 sp->psc_ctrl = PSC_CTRL_ENABLE;
324 au_sync();
325 do {
326 stat = sp->psc_smbstat;
327 au_sync();
328 } while ((stat & PSC_SMBSTAT_SR) == 0);
329
330 sp->psc_smbcfg = (PSC_SMBCFG_RT_FIFO8 | PSC_SMBCFG_TT_FIFO8 |
331 PSC_SMBCFG_DD_DISABLE);
332
333 /* Divide by 8 to get a 6.25 MHz clock. The later protocol
334 * timings are based on this clock.
335 */
336 sp->psc_smbcfg |= PSC_SMBCFG_SET_DIV(PSC_SMBCFG_DIV8);
337 sp->psc_smbmsk = PSC_SMBMSK_ALLMASK;
338 au_sync();
339
340 /* Set the protocol timer values. See Table 71 in the
341 * Au1550 Data Book for standard timing values.
342 */
343 sp->psc_smbtmr = PSC_SMBTMR_SET_TH(0) | PSC_SMBTMR_SET_PS(15) | \
344 PSC_SMBTMR_SET_PU(15) | PSC_SMBTMR_SET_SH(15) | \
345 PSC_SMBTMR_SET_SU(15) | PSC_SMBTMR_SET_CL(15) | \
346 PSC_SMBTMR_SET_CH(15);
347 au_sync();
348
349 sp->psc_smbcfg |= PSC_SMBCFG_DE_ENABLE;
350 do {
351 stat = sp->psc_smbstat;
352 au_sync();
353 } while ((stat & PSC_SMBSTAT_SR) == 0);
354
355 sp->psc_ctrl = PSC_CTRL_SUSPEND;
356 au_sync();
357}
358
359static void i2c_au1550_disable(struct i2c_au1550_data *priv)
360{
361 volatile psc_smb_t *sp = (volatile psc_smb_t *)priv->psc_base;
362
363 sp->psc_smbcfg = 0;
364 sp->psc_ctrl = PSC_CTRL_DISABLE;
365 au_sync();
366}
367
305/* 368/*
306 * registering functions to load algorithms at runtime 369 * registering functions to load algorithms at runtime
307 * Prior to calling us, the 50MHz clock frequency and routing 370 * Prior to calling us, the 50MHz clock frequency and routing
@@ -311,9 +374,7 @@ static int __devinit
311i2c_au1550_probe(struct platform_device *pdev) 374i2c_au1550_probe(struct platform_device *pdev)
312{ 375{
313 struct i2c_au1550_data *priv; 376 struct i2c_au1550_data *priv;
314 volatile psc_smb_t *sp;
315 struct resource *r; 377 struct resource *r;
316 u32 stat;
317 int ret; 378 int ret;
318 379
319 r = platform_get_resource(pdev, IORESOURCE_MEM, 0); 380 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
@@ -335,7 +396,7 @@ i2c_au1550_probe(struct platform_device *pdev)
335 goto out_mem; 396 goto out_mem;
336 } 397 }
337 398
338 priv->psc_base = r->start; 399 priv->psc_base = CKSEG1ADDR(r->start);
339 priv->xfer_timeout = 200; 400 priv->xfer_timeout = 200;
340 priv->ack_timeout = 200; 401 priv->ack_timeout = 200;
341 402
@@ -348,43 +409,7 @@ i2c_au1550_probe(struct platform_device *pdev)
348 409
349 /* Now, set up the PSC for SMBus PIO mode. 410 /* Now, set up the PSC for SMBus PIO mode.
350 */ 411 */
351 sp = (volatile psc_smb_t *)priv->psc_base; 412 i2c_au1550_setup(priv);
352 sp->psc_ctrl = PSC_CTRL_DISABLE;
353 au_sync();
354 sp->psc_sel = PSC_SEL_PS_SMBUSMODE;
355 sp->psc_smbcfg = 0;
356 au_sync();
357 sp->psc_ctrl = PSC_CTRL_ENABLE;
358 au_sync();
359 do {
360 stat = sp->psc_smbstat;
361 au_sync();
362 } while ((stat & PSC_SMBSTAT_SR) == 0);
363
364 sp->psc_smbcfg = (PSC_SMBCFG_RT_FIFO8 | PSC_SMBCFG_TT_FIFO8 |
365 PSC_SMBCFG_DD_DISABLE);
366
367 /* Divide by 8 to get a 6.25 MHz clock. The later protocol
368 * timings are based on this clock.
369 */
370 sp->psc_smbcfg |= PSC_SMBCFG_SET_DIV(PSC_SMBCFG_DIV8);
371 sp->psc_smbmsk = PSC_SMBMSK_ALLMASK;
372 au_sync();
373
374 /* Set the protocol timer values. See Table 71 in the
375 * Au1550 Data Book for standard timing values.
376 */
377 sp->psc_smbtmr = PSC_SMBTMR_SET_TH(0) | PSC_SMBTMR_SET_PS(15) | \
378 PSC_SMBTMR_SET_PU(15) | PSC_SMBTMR_SET_SH(15) | \
379 PSC_SMBTMR_SET_SU(15) | PSC_SMBTMR_SET_CL(15) | \
380 PSC_SMBTMR_SET_CH(15);
381 au_sync();
382
383 sp->psc_smbcfg |= PSC_SMBCFG_DE_ENABLE;
384 do {
385 stat = sp->psc_smbstat;
386 au_sync();
387 } while ((stat & PSC_SMBSTAT_DR) == 0);
388 413
389 ret = i2c_add_numbered_adapter(&priv->adap); 414 ret = i2c_add_numbered_adapter(&priv->adap);
390 if (ret == 0) { 415 if (ret == 0) {
@@ -392,10 +417,7 @@ i2c_au1550_probe(struct platform_device *pdev)
392 return 0; 417 return 0;
393 } 418 }
394 419
395 /* disable the PSC */ 420 i2c_au1550_disable(priv);
396 sp->psc_smbcfg = 0;
397 sp->psc_ctrl = PSC_CTRL_DISABLE;
398 au_sync();
399 421
400 release_resource(priv->ioarea); 422 release_resource(priv->ioarea);
401 kfree(priv->ioarea); 423 kfree(priv->ioarea);
@@ -409,27 +431,24 @@ static int __devexit
409i2c_au1550_remove(struct platform_device *pdev) 431i2c_au1550_remove(struct platform_device *pdev)
410{ 432{
411 struct i2c_au1550_data *priv = platform_get_drvdata(pdev); 433 struct i2c_au1550_data *priv = platform_get_drvdata(pdev);
412 volatile psc_smb_t *sp = (volatile psc_smb_t *)priv->psc_base;
413 434
414 platform_set_drvdata(pdev, NULL); 435 platform_set_drvdata(pdev, NULL);
415 i2c_del_adapter(&priv->adap); 436 i2c_del_adapter(&priv->adap);
416 sp->psc_smbcfg = 0; 437 i2c_au1550_disable(priv);
417 sp->psc_ctrl = PSC_CTRL_DISABLE;
418 au_sync();
419 release_resource(priv->ioarea); 438 release_resource(priv->ioarea);
420 kfree(priv->ioarea); 439 kfree(priv->ioarea);
421 kfree(priv); 440 kfree(priv);
422 return 0; 441 return 0;
423} 442}
424 443
444#ifdef CONFIG_PM
425static int 445static int
426i2c_au1550_suspend(struct platform_device *pdev, pm_message_t state) 446i2c_au1550_suspend(struct platform_device *pdev, pm_message_t state)
427{ 447{
428 struct i2c_au1550_data *priv = platform_get_drvdata(pdev); 448 struct i2c_au1550_data *priv = platform_get_drvdata(pdev);
429 volatile psc_smb_t *sp = (volatile psc_smb_t *)priv->psc_base;
430 449
431 sp->psc_ctrl = PSC_CTRL_SUSPEND; 450 i2c_au1550_disable(priv);
432 au_sync(); 451
433 return 0; 452 return 0;
434} 453}
435 454
@@ -437,14 +456,15 @@ static int
437i2c_au1550_resume(struct platform_device *pdev) 456i2c_au1550_resume(struct platform_device *pdev)
438{ 457{
439 struct i2c_au1550_data *priv = platform_get_drvdata(pdev); 458 struct i2c_au1550_data *priv = platform_get_drvdata(pdev);
440 volatile psc_smb_t *sp = (volatile psc_smb_t *)priv->psc_base;
441 459
442 sp->psc_ctrl = PSC_CTRL_ENABLE; 460 i2c_au1550_setup(priv);
443 au_sync(); 461
444 while (!(sp->psc_smbstat & PSC_SMBSTAT_SR))
445 au_sync();
446 return 0; 462 return 0;
447} 463}
464#else
465#define i2c_au1550_suspend NULL
466#define i2c_au1550_resume NULL
467#endif
448 468
449static struct platform_driver au1xpsc_smbus_driver = { 469static struct platform_driver au1xpsc_smbus_driver = {
450 .driver = { 470 .driver = {
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
index 48d084bdf7c8..3c855ff2992f 100644
--- a/drivers/i2c/busses/i2c-bfin-twi.c
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -49,6 +49,8 @@ struct bfin_twi_iface {
49 struct i2c_msg *pmsg; 49 struct i2c_msg *pmsg;
50 int msg_num; 50 int msg_num;
51 int cur_msg; 51 int cur_msg;
52 u16 saved_clkdiv;
53 u16 saved_control;
52 void __iomem *regs_base; 54 void __iomem *regs_base;
53}; 55};
54 56
@@ -565,32 +567,43 @@ static u32 bfin_twi_functionality(struct i2c_adapter *adap)
565 I2C_FUNC_I2C; 567 I2C_FUNC_I2C;
566} 568}
567 569
568
569static struct i2c_algorithm bfin_twi_algorithm = { 570static struct i2c_algorithm bfin_twi_algorithm = {
570 .master_xfer = bfin_twi_master_xfer, 571 .master_xfer = bfin_twi_master_xfer,
571 .smbus_xfer = bfin_twi_smbus_xfer, 572 .smbus_xfer = bfin_twi_smbus_xfer,
572 .functionality = bfin_twi_functionality, 573 .functionality = bfin_twi_functionality,
573}; 574};
574 575
575 576static int i2c_bfin_twi_suspend(struct platform_device *pdev, pm_message_t state)
576static int i2c_bfin_twi_suspend(struct platform_device *dev, pm_message_t state)
577{ 577{
578 struct bfin_twi_iface *iface = platform_get_drvdata(dev); 578 struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
579
580 iface->saved_clkdiv = read_CLKDIV(iface);
581 iface->saved_control = read_CONTROL(iface);
582
583 free_irq(iface->irq, iface);
579 584
580 /* Disable TWI */ 585 /* Disable TWI */
581 write_CONTROL(iface, read_CONTROL(iface) & ~TWI_ENA); 586 write_CONTROL(iface, iface->saved_control & ~TWI_ENA);
582 SSYNC();
583 587
584 return 0; 588 return 0;
585} 589}
586 590
587static int i2c_bfin_twi_resume(struct platform_device *dev) 591static int i2c_bfin_twi_resume(struct platform_device *pdev)
588{ 592{
589 struct bfin_twi_iface *iface = platform_get_drvdata(dev); 593 struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
590 594
591 /* Enable TWI */ 595 int rc = request_irq(iface->irq, bfin_twi_interrupt_entry,
592 write_CONTROL(iface, read_CONTROL(iface) | TWI_ENA); 596 IRQF_DISABLED, pdev->name, iface);
593 SSYNC(); 597 if (rc) {
598 dev_err(&pdev->dev, "Can't get IRQ %d !\n", iface->irq);
599 return -ENODEV;
600 }
601
602 /* Resume TWI interface clock as specified */
603 write_CLKDIV(iface, iface->saved_clkdiv);
604
605 /* Resume TWI */
606 write_CONTROL(iface, iface->saved_control);
594 607
595 return 0; 608 return 0;
596} 609}
diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c
new file mode 100644
index 000000000000..8164de1f4d72
--- /dev/null
+++ b/drivers/i2c/busses/i2c-cpm.c
@@ -0,0 +1,745 @@
1/*
2 * Freescale CPM1/CPM2 I2C interface.
3 * Copyright (c) 1999 Dan Malek (dmalek@jlc.net).
4 *
5 * moved into proper i2c interface;
6 * Brad Parker (brad@heeltoe.com)
7 *
8 * Parts from dbox2_i2c.c (cvs.tuxbox.org)
9 * (C) 2000-2001 Felix Domke (tmbinc@gmx.net), Gillem (htoa@gmx.net)
10 *
11 * (C) 2007 Montavista Software, Inc.
12 * Vitaly Bordug <vitb@kernel.crashing.org>
13 *
14 * Converted to of_platform_device. Renamed to i2c-cpm.c.
15 * (C) 2007,2008 Jochen Friedrich <jochen@scram.de>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 */
31
32#include <linux/kernel.h>
33#include <linux/module.h>
34#include <linux/delay.h>
35#include <linux/slab.h>
36#include <linux/init.h>
37#include <linux/interrupt.h>
38#include <linux/errno.h>
39#include <linux/stddef.h>
40#include <linux/i2c.h>
41#include <linux/io.h>
42#include <linux/dma-mapping.h>
43#include <linux/of_device.h>
44#include <linux/of_platform.h>
45#include <linux/of_i2c.h>
46#include <sysdev/fsl_soc.h>
47#include <asm/cpm.h>
48
49/* Try to define this if you have an older CPU (earlier than rev D4) */
50/* However, better use a GPIO based bitbang driver in this case :/ */
51#undef I2C_CHIP_ERRATA
52
53#define CPM_MAX_READ 513
54#define CPM_MAXBD 4
55
56#define I2C_EB (0x10) /* Big endian mode */
57#define I2C_EB_CPM2 (0x30) /* Big endian mode, memory snoop */
58
59#define DPRAM_BASE ((u8 __iomem __force *)cpm_muram_addr(0))
60
61/* I2C parameter RAM. */
62struct i2c_ram {
63 ushort rbase; /* Rx Buffer descriptor base address */
64 ushort tbase; /* Tx Buffer descriptor base address */
65 u_char rfcr; /* Rx function code */
66 u_char tfcr; /* Tx function code */
67 ushort mrblr; /* Max receive buffer length */
68 uint rstate; /* Internal */
69 uint rdp; /* Internal */
70 ushort rbptr; /* Rx Buffer descriptor pointer */
71 ushort rbc; /* Internal */
72 uint rxtmp; /* Internal */
73 uint tstate; /* Internal */
74 uint tdp; /* Internal */
75 ushort tbptr; /* Tx Buffer descriptor pointer */
76 ushort tbc; /* Internal */
77 uint txtmp; /* Internal */
78 char res1[4]; /* Reserved */
79 ushort rpbase; /* Relocation pointer */
80 char res2[2]; /* Reserved */
81};
82
83#define I2COM_START 0x80
84#define I2COM_MASTER 0x01
85#define I2CER_TXE 0x10
86#define I2CER_BUSY 0x04
87#define I2CER_TXB 0x02
88#define I2CER_RXB 0x01
89#define I2MOD_EN 0x01
90
91/* I2C Registers */
92struct i2c_reg {
93 u8 i2mod;
94 u8 res1[3];
95 u8 i2add;
96 u8 res2[3];
97 u8 i2brg;
98 u8 res3[3];
99 u8 i2com;
100 u8 res4[3];
101 u8 i2cer;
102 u8 res5[3];
103 u8 i2cmr;
104};
105
106struct cpm_i2c {
107 char *base;
108 struct of_device *ofdev;
109 struct i2c_adapter adap;
110 uint dp_addr;
111 int version; /* CPM1=1, CPM2=2 */
112 int irq;
113 int cp_command;
114 int freq;
115 struct i2c_reg __iomem *i2c_reg;
116 struct i2c_ram __iomem *i2c_ram;
117 u16 i2c_addr;
118 wait_queue_head_t i2c_wait;
119 cbd_t __iomem *tbase;
120 cbd_t __iomem *rbase;
121 u_char *txbuf[CPM_MAXBD];
122 u_char *rxbuf[CPM_MAXBD];
123 u32 txdma[CPM_MAXBD];
124 u32 rxdma[CPM_MAXBD];
125};
126
127static irqreturn_t cpm_i2c_interrupt(int irq, void *dev_id)
128{
129 struct cpm_i2c *cpm;
130 struct i2c_reg __iomem *i2c_reg;
131 struct i2c_adapter *adap = dev_id;
132 int i;
133
134 cpm = i2c_get_adapdata(dev_id);
135 i2c_reg = cpm->i2c_reg;
136
137 /* Clear interrupt. */
138 i = in_8(&i2c_reg->i2cer);
139 out_8(&i2c_reg->i2cer, i);
140
141 dev_dbg(&adap->dev, "Interrupt: %x\n", i);
142
143 wake_up_interruptible(&cpm->i2c_wait);
144
145 return i ? IRQ_HANDLED : IRQ_NONE;
146}
147
148static void cpm_reset_i2c_params(struct cpm_i2c *cpm)
149{
150 struct i2c_ram __iomem *i2c_ram = cpm->i2c_ram;
151
152 /* Set up the I2C parameters in the parameter ram. */
153 out_be16(&i2c_ram->tbase, (u8 __iomem *)cpm->tbase - DPRAM_BASE);
154 out_be16(&i2c_ram->rbase, (u8 __iomem *)cpm->rbase - DPRAM_BASE);
155
156 if (cpm->version == 1) {
157 out_8(&i2c_ram->tfcr, I2C_EB);
158 out_8(&i2c_ram->rfcr, I2C_EB);
159 } else {
160 out_8(&i2c_ram->tfcr, I2C_EB_CPM2);
161 out_8(&i2c_ram->rfcr, I2C_EB_CPM2);
162 }
163
164 out_be16(&i2c_ram->mrblr, CPM_MAX_READ);
165
166 out_be32(&i2c_ram->rstate, 0);
167 out_be32(&i2c_ram->rdp, 0);
168 out_be16(&i2c_ram->rbptr, 0);
169 out_be16(&i2c_ram->rbc, 0);
170 out_be32(&i2c_ram->rxtmp, 0);
171 out_be32(&i2c_ram->tstate, 0);
172 out_be32(&i2c_ram->tdp, 0);
173 out_be16(&i2c_ram->tbptr, 0);
174 out_be16(&i2c_ram->tbc, 0);
175 out_be32(&i2c_ram->txtmp, 0);
176}
177
178static void cpm_i2c_force_close(struct i2c_adapter *adap)
179{
180 struct cpm_i2c *cpm = i2c_get_adapdata(adap);
181 struct i2c_reg __iomem *i2c_reg = cpm->i2c_reg;
182
183 dev_dbg(&adap->dev, "cpm_i2c_force_close()\n");
184
185 cpm_command(cpm->cp_command, CPM_CR_CLOSE_RX_BD);
186
187 out_8(&i2c_reg->i2cmr, 0x00); /* Disable all interrupts */
188 out_8(&i2c_reg->i2cer, 0xff);
189}
190
191static void cpm_i2c_parse_message(struct i2c_adapter *adap,
192 struct i2c_msg *pmsg, int num, int tx, int rx)
193{
194 cbd_t __iomem *tbdf;
195 cbd_t __iomem *rbdf;
196 u_char addr;
197 u_char *tb;
198 u_char *rb;
199 struct cpm_i2c *cpm = i2c_get_adapdata(adap);
200
201 tbdf = cpm->tbase + tx;
202 rbdf = cpm->rbase + rx;
203
204 addr = pmsg->addr << 1;
205 if (pmsg->flags & I2C_M_RD)
206 addr |= 1;
207
208 tb = cpm->txbuf[tx];
209 rb = cpm->rxbuf[rx];
210
211 /* Align read buffer */
212 rb = (u_char *) (((ulong) rb + 1) & ~1);
213
214 tb[0] = addr; /* Device address byte w/rw flag */
215
216 out_be16(&tbdf->cbd_datlen, pmsg->len + 1);
217 out_be16(&tbdf->cbd_sc, 0);
218
219 if (!(pmsg->flags & I2C_M_NOSTART))
220 setbits16(&tbdf->cbd_sc, BD_I2C_START);
221
222 if (tx + 1 == num)
223 setbits16(&tbdf->cbd_sc, BD_SC_LAST | BD_SC_WRAP);
224
225 if (pmsg->flags & I2C_M_RD) {
226 /*
227 * To read, we need an empty buffer of the proper length.
228 * All that is used is the first byte for address, the remainder
229 * is just used for timing (and doesn't really have to exist).
230 */
231
232 dev_dbg(&adap->dev, "cpm_i2c_read(abyte=0x%x)\n", addr);
233
234 out_be16(&rbdf->cbd_datlen, 0);
235 out_be16(&rbdf->cbd_sc, BD_SC_EMPTY | BD_SC_INTRPT);
236
237 if (rx + 1 == CPM_MAXBD)
238 setbits16(&rbdf->cbd_sc, BD_SC_WRAP);
239
240 eieio();
241 setbits16(&tbdf->cbd_sc, BD_SC_READY);
242 } else {
243 dev_dbg(&adap->dev, "cpm_i2c_write(abyte=0x%x)\n", addr);
244
245 memcpy(tb+1, pmsg->buf, pmsg->len);
246
247 eieio();
248 setbits16(&tbdf->cbd_sc, BD_SC_READY | BD_SC_INTRPT);
249 }
250}
251
252static int cpm_i2c_check_message(struct i2c_adapter *adap,
253 struct i2c_msg *pmsg, int tx, int rx)
254{
255 cbd_t __iomem *tbdf;
256 cbd_t __iomem *rbdf;
257 u_char *tb;
258 u_char *rb;
259 struct cpm_i2c *cpm = i2c_get_adapdata(adap);
260
261 tbdf = cpm->tbase + tx;
262 rbdf = cpm->rbase + rx;
263
264 tb = cpm->txbuf[tx];
265 rb = cpm->rxbuf[rx];
266
267 /* Align read buffer */
268 rb = (u_char *) (((uint) rb + 1) & ~1);
269
270 eieio();
271 if (pmsg->flags & I2C_M_RD) {
272 dev_dbg(&adap->dev, "tx sc 0x%04x, rx sc 0x%04x\n",
273 in_be16(&tbdf->cbd_sc), in_be16(&rbdf->cbd_sc));
274
275 if (in_be16(&tbdf->cbd_sc) & BD_SC_NAK) {
276 dev_dbg(&adap->dev, "I2C read; No ack\n");
277 return -ENXIO;
278 }
279 if (in_be16(&rbdf->cbd_sc) & BD_SC_EMPTY) {
280 dev_err(&adap->dev,
281 "I2C read; complete but rbuf empty\n");
282 return -EREMOTEIO;
283 }
284 if (in_be16(&rbdf->cbd_sc) & BD_SC_OV) {
285 dev_err(&adap->dev, "I2C read; Overrun\n");
286 return -EREMOTEIO;
287 }
288 memcpy(pmsg->buf, rb, pmsg->len);
289 } else {
290 dev_dbg(&adap->dev, "tx sc %d 0x%04x\n", tx,
291 in_be16(&tbdf->cbd_sc));
292
293 if (in_be16(&tbdf->cbd_sc) & BD_SC_NAK) {
294 dev_dbg(&adap->dev, "I2C write; No ack\n");
295 return -ENXIO;
296 }
297 if (in_be16(&tbdf->cbd_sc) & BD_SC_UN) {
298 dev_err(&adap->dev, "I2C write; Underrun\n");
299 return -EIO;
300 }
301 if (in_be16(&tbdf->cbd_sc) & BD_SC_CL) {
302 dev_err(&adap->dev, "I2C write; Collision\n");
303 return -EIO;
304 }
305 }
306 return 0;
307}
308
309static int cpm_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
310{
311 struct cpm_i2c *cpm = i2c_get_adapdata(adap);
312 struct i2c_reg __iomem *i2c_reg = cpm->i2c_reg;
313 struct i2c_ram __iomem *i2c_ram = cpm->i2c_ram;
314 struct i2c_msg *pmsg;
315 int ret, i;
316 int tptr;
317 int rptr;
318 cbd_t __iomem *tbdf;
319 cbd_t __iomem *rbdf;
320
321 if (num > CPM_MAXBD)
322 return -EINVAL;
323
324 /* Check if we have any oversized READ requests */
325 for (i = 0; i < num; i++) {
326 pmsg = &msgs[i];
327 if (pmsg->len >= CPM_MAX_READ)
328 return -EINVAL;
329 }
330
331 /* Reset to use first buffer */
332 out_be16(&i2c_ram->rbptr, in_be16(&i2c_ram->rbase));
333 out_be16(&i2c_ram->tbptr, in_be16(&i2c_ram->tbase));
334
335 tbdf = cpm->tbase;
336 rbdf = cpm->rbase;
337
338 tptr = 0;
339 rptr = 0;
340
341 while (tptr < num) {
342 pmsg = &msgs[tptr];
343 dev_dbg(&adap->dev, "R: %d T: %d\n", rptr, tptr);
344
345 cpm_i2c_parse_message(adap, pmsg, num, tptr, rptr);
346 if (pmsg->flags & I2C_M_RD)
347 rptr++;
348 tptr++;
349 }
350 /* Start transfer now */
351 /* Enable RX/TX/Error interupts */
352 out_8(&i2c_reg->i2cmr, I2CER_TXE | I2CER_TXB | I2CER_RXB);
353 out_8(&i2c_reg->i2cer, 0xff); /* Clear interrupt status */
354 /* Chip bug, set enable here */
355 setbits8(&i2c_reg->i2mod, I2MOD_EN); /* Enable */
356 /* Begin transmission */
357 setbits8(&i2c_reg->i2com, I2COM_START);
358
359 tptr = 0;
360 rptr = 0;
361
362 while (tptr < num) {
363 /* Check for outstanding messages */
364 dev_dbg(&adap->dev, "test ready.\n");
365 pmsg = &msgs[tptr];
366 if (pmsg->flags & I2C_M_RD)
367 ret = wait_event_interruptible_timeout(cpm->i2c_wait,
368 !(in_be16(&rbdf[rptr].cbd_sc) & BD_SC_EMPTY),
369 1 * HZ);
370 else
371 ret = wait_event_interruptible_timeout(cpm->i2c_wait,
372 !(in_be16(&tbdf[tptr].cbd_sc) & BD_SC_READY),
373 1 * HZ);
374 if (ret == 0) {
375 ret = -EREMOTEIO;
376 dev_err(&adap->dev, "I2C transfer: timeout\n");
377 goto out_err;
378 }
379 if (ret > 0) {
380 dev_dbg(&adap->dev, "ready.\n");
381 ret = cpm_i2c_check_message(adap, pmsg, tptr, rptr);
382 tptr++;
383 if (pmsg->flags & I2C_M_RD)
384 rptr++;
385 if (ret)
386 goto out_err;
387 }
388 }
389#ifdef I2C_CHIP_ERRATA
390 /*
391 * Chip errata, clear enable. This is not needed on rev D4 CPUs.
392 * Disabling I2C too early may cause too short stop condition
393 */
394 udelay(4);
395 clrbits8(&i2c_reg->i2mod, I2MOD_EN);
396#endif
397 return (num);
398
399out_err:
400 cpm_i2c_force_close(adap);
401#ifdef I2C_CHIP_ERRATA
402 /*
403 * Chip errata, clear enable. This is not needed on rev D4 CPUs.
404 */
405 clrbits8(&i2c_reg->i2mod, I2MOD_EN);
406#endif
407 return ret;
408}
409
410static u32 cpm_i2c_func(struct i2c_adapter *adap)
411{
412 return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);
413}
414
415/* -----exported algorithm data: ------------------------------------- */
416
417static const struct i2c_algorithm cpm_i2c_algo = {
418 .master_xfer = cpm_i2c_xfer,
419 .functionality = cpm_i2c_func,
420};
421
422static const struct i2c_adapter cpm_ops = {
423 .owner = THIS_MODULE,
424 .name = "i2c-cpm",
425 .algo = &cpm_i2c_algo,
426 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
427};
428
429static int __devinit cpm_i2c_setup(struct cpm_i2c *cpm)
430{
431 struct of_device *ofdev = cpm->ofdev;
432 const u32 *data;
433 int len, ret, i;
434 void __iomem *i2c_base;
435 cbd_t __iomem *tbdf;
436 cbd_t __iomem *rbdf;
437 unsigned char brg;
438
439 dev_dbg(&cpm->ofdev->dev, "cpm_i2c_setup()\n");
440
441 init_waitqueue_head(&cpm->i2c_wait);
442
443 cpm->irq = of_irq_to_resource(ofdev->node, 0, NULL);
444 if (cpm->irq == NO_IRQ)
445 return -EINVAL;
446
447 /* Install interrupt handler. */
448 ret = request_irq(cpm->irq, cpm_i2c_interrupt, 0, "cpm_i2c",
449 &cpm->adap);
450 if (ret)
451 return ret;
452
453 /* I2C parameter RAM */
454 i2c_base = of_iomap(ofdev->node, 1);
455 if (i2c_base == NULL) {
456 ret = -EINVAL;
457 goto out_irq;
458 }
459
460 if (of_device_is_compatible(ofdev->node, "fsl,cpm1-i2c")) {
461
462 /* Check for and use a microcode relocation patch. */
463 cpm->i2c_ram = i2c_base;
464 cpm->i2c_addr = in_be16(&cpm->i2c_ram->rpbase);
465
466 /*
467 * Maybe should use cpm_muram_alloc instead of hardcoding
468 * this in micropatch.c
469 */
470 if (cpm->i2c_addr) {
471 cpm->i2c_ram = cpm_muram_addr(cpm->i2c_addr);
472 iounmap(i2c_base);
473 }
474
475 cpm->version = 1;
476
477 } else if (of_device_is_compatible(ofdev->node, "fsl,cpm2-i2c")) {
478 cpm->i2c_addr = cpm_muram_alloc(sizeof(struct i2c_ram), 64);
479 cpm->i2c_ram = cpm_muram_addr(cpm->i2c_addr);
480 out_be16(i2c_base, cpm->i2c_addr);
481 iounmap(i2c_base);
482
483 cpm->version = 2;
484
485 } else {
486 iounmap(i2c_base);
487 ret = -EINVAL;
488 goto out_irq;
489 }
490
491 /* I2C control/status registers */
492 cpm->i2c_reg = of_iomap(ofdev->node, 0);
493 if (cpm->i2c_reg == NULL) {
494 ret = -EINVAL;
495 goto out_ram;
496 }
497
498 data = of_get_property(ofdev->node, "fsl,cpm-command", &len);
499 if (!data || len != 4) {
500 ret = -EINVAL;
501 goto out_reg;
502 }
503 cpm->cp_command = *data;
504
505 data = of_get_property(ofdev->node, "linux,i2c-class", &len);
506 if (data && len == 4)
507 cpm->adap.class = *data;
508
509 data = of_get_property(ofdev->node, "clock-frequency", &len);
510 if (data && len == 4)
511 cpm->freq = *data;
512 else
513 cpm->freq = 60000; /* use 60kHz i2c clock by default */
514
515 /*
516 * Allocate space for CPM_MAXBD transmit and receive buffer
517 * descriptors in the DP ram.
518 */
519 cpm->dp_addr = cpm_muram_alloc(sizeof(cbd_t) * 2 * CPM_MAXBD, 8);
520 if (!cpm->dp_addr) {
521 ret = -ENOMEM;
522 goto out_reg;
523 }
524
525 cpm->tbase = cpm_muram_addr(cpm->dp_addr);
526 cpm->rbase = cpm_muram_addr(cpm->dp_addr + sizeof(cbd_t) * CPM_MAXBD);
527
528 /* Allocate TX and RX buffers */
529
530 tbdf = cpm->tbase;
531 rbdf = cpm->rbase;
532
533 for (i = 0; i < CPM_MAXBD; i++) {
534 cpm->rxbuf[i] = dma_alloc_coherent(
535 NULL, CPM_MAX_READ + 1, &cpm->rxdma[i], GFP_KERNEL);
536 if (!cpm->rxbuf[i]) {
537 ret = -ENOMEM;
538 goto out_muram;
539 }
540 out_be32(&rbdf[i].cbd_bufaddr, ((cpm->rxdma[i] + 1) & ~1));
541
542 cpm->txbuf[i] = (unsigned char *)dma_alloc_coherent(
543 NULL, CPM_MAX_READ + 1, &cpm->txdma[i], GFP_KERNEL);
544 if (!cpm->txbuf[i]) {
545 ret = -ENOMEM;
546 goto out_muram;
547 }
548 out_be32(&tbdf[i].cbd_bufaddr, cpm->txdma[i]);
549 }
550
551 /* Initialize Tx/Rx parameters. */
552
553 cpm_reset_i2c_params(cpm);
554
555 dev_dbg(&cpm->ofdev->dev, "i2c_ram 0x%p, i2c_addr 0x%04x, freq %d\n",
556 cpm->i2c_ram, cpm->i2c_addr, cpm->freq);
557 dev_dbg(&cpm->ofdev->dev, "tbase 0x%04x, rbase 0x%04x\n",
558 (u8 __iomem *)cpm->tbase - DPRAM_BASE,
559 (u8 __iomem *)cpm->rbase - DPRAM_BASE);
560
561 cpm_command(cpm->cp_command, CPM_CR_INIT_TRX);
562
563 /*
564 * Select an invalid address. Just make sure we don't use loopback mode
565 */
566 out_8(&cpm->i2c_reg->i2add, 0x7f << 1);
567
568 /*
569 * PDIV is set to 00 in i2mod, so brgclk/32 is used as input to the
570 * i2c baud rate generator. This is divided by 2 x (DIV + 3) to get
571 * the actual i2c bus frequency.
572 */
573 brg = get_brgfreq() / (32 * 2 * cpm->freq) - 3;
574 out_8(&cpm->i2c_reg->i2brg, brg);
575
576 out_8(&cpm->i2c_reg->i2mod, 0x00);
577 out_8(&cpm->i2c_reg->i2com, I2COM_MASTER); /* Master mode */
578
579 /* Disable interrupts. */
580 out_8(&cpm->i2c_reg->i2cmr, 0);
581 out_8(&cpm->i2c_reg->i2cer, 0xff);
582
583 return 0;
584
585out_muram:
586 for (i = 0; i < CPM_MAXBD; i++) {
587 if (cpm->rxbuf[i])
588 dma_free_coherent(NULL, CPM_MAX_READ + 1,
589 cpm->rxbuf[i], cpm->rxdma[i]);
590 if (cpm->txbuf[i])
591 dma_free_coherent(NULL, CPM_MAX_READ + 1,
592 cpm->txbuf[i], cpm->txdma[i]);
593 }
594 cpm_muram_free(cpm->dp_addr);
595out_reg:
596 iounmap(cpm->i2c_reg);
597out_ram:
598 if ((cpm->version == 1) && (!cpm->i2c_addr))
599 iounmap(cpm->i2c_ram);
600 if (cpm->version == 2)
601 cpm_muram_free(cpm->i2c_addr);
602out_irq:
603 free_irq(cpm->irq, &cpm->adap);
604 return ret;
605}
606
607static void cpm_i2c_shutdown(struct cpm_i2c *cpm)
608{
609 int i;
610
611 /* Shut down I2C. */
612 clrbits8(&cpm->i2c_reg->i2mod, I2MOD_EN);
613
614 /* Disable interrupts */
615 out_8(&cpm->i2c_reg->i2cmr, 0);
616 out_8(&cpm->i2c_reg->i2cer, 0xff);
617
618 free_irq(cpm->irq, &cpm->adap);
619
620 /* Free all memory */
621 for (i = 0; i < CPM_MAXBD; i++) {
622 dma_free_coherent(NULL, CPM_MAX_READ + 1,
623 cpm->rxbuf[i], cpm->rxdma[i]);
624 dma_free_coherent(NULL, CPM_MAX_READ + 1,
625 cpm->txbuf[i], cpm->txdma[i]);
626 }
627
628 cpm_muram_free(cpm->dp_addr);
629 iounmap(cpm->i2c_reg);
630
631 if ((cpm->version == 1) && (!cpm->i2c_addr))
632 iounmap(cpm->i2c_ram);
633 if (cpm->version == 2)
634 cpm_muram_free(cpm->i2c_addr);
635}
636
637static int __devinit cpm_i2c_probe(struct of_device *ofdev,
638 const struct of_device_id *match)
639{
640 int result, len;
641 struct cpm_i2c *cpm;
642 const u32 *data;
643
644 cpm = kzalloc(sizeof(struct cpm_i2c), GFP_KERNEL);
645 if (!cpm)
646 return -ENOMEM;
647
648 cpm->ofdev = ofdev;
649
650 dev_set_drvdata(&ofdev->dev, cpm);
651
652 cpm->adap = cpm_ops;
653 i2c_set_adapdata(&cpm->adap, cpm);
654 cpm->adap.dev.parent = &ofdev->dev;
655
656 result = cpm_i2c_setup(cpm);
657 if (result) {
658 dev_err(&ofdev->dev, "Unable to init hardware\n");
659 goto out_free;
660 }
661
662 /* register new adapter to i2c module... */
663
664 data = of_get_property(ofdev->node, "linux,i2c-index", &len);
665 if (data && len == 4) {
666 cpm->adap.nr = *data;
667 result = i2c_add_numbered_adapter(&cpm->adap);
668 } else
669 result = i2c_add_adapter(&cpm->adap);
670
671 if (result < 0) {
672 dev_err(&ofdev->dev, "Unable to register with I2C\n");
673 goto out_shut;
674 }
675
676 dev_dbg(&ofdev->dev, "hw routines for %s registered.\n",
677 cpm->adap.name);
678
679 /*
680 * register OF I2C devices
681 */
682 of_register_i2c_devices(&cpm->adap, ofdev->node);
683
684 return 0;
685out_shut:
686 cpm_i2c_shutdown(cpm);
687out_free:
688 dev_set_drvdata(&ofdev->dev, NULL);
689 kfree(cpm);
690
691 return result;
692}
693
694static int __devexit cpm_i2c_remove(struct of_device *ofdev)
695{
696 struct cpm_i2c *cpm = dev_get_drvdata(&ofdev->dev);
697
698 i2c_del_adapter(&cpm->adap);
699
700 cpm_i2c_shutdown(cpm);
701
702 dev_set_drvdata(&ofdev->dev, NULL);
703 kfree(cpm);
704
705 return 0;
706}
707
708static const struct of_device_id cpm_i2c_match[] = {
709 {
710 .compatible = "fsl,cpm1-i2c",
711 },
712 {
713 .compatible = "fsl,cpm2-i2c",
714 },
715 {},
716};
717
718MODULE_DEVICE_TABLE(of, cpm_i2c_match);
719
720static struct of_platform_driver cpm_i2c_driver = {
721 .match_table = cpm_i2c_match,
722 .probe = cpm_i2c_probe,
723 .remove = __devexit_p(cpm_i2c_remove),
724 .driver = {
725 .name = "fsl-i2c-cpm",
726 .owner = THIS_MODULE,
727 }
728};
729
730static int __init cpm_i2c_init(void)
731{
732 return of_register_platform_driver(&cpm_i2c_driver);
733}
734
735static void __exit cpm_i2c_exit(void)
736{
737 of_unregister_platform_driver(&cpm_i2c_driver);
738}
739
740module_init(cpm_i2c_init);
741module_exit(cpm_i2c_exit);
742
743MODULE_AUTHOR("Jochen Friedrich <jochen@scram.de>");
744MODULE_DESCRIPTION("I2C-Bus adapter routines for CPM boards");
745MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index 7ecbfc429b19..af3846eda985 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -85,6 +85,7 @@
85#define DAVINCI_I2C_MDR_MST (1 << 10) 85#define DAVINCI_I2C_MDR_MST (1 << 10)
86#define DAVINCI_I2C_MDR_TRX (1 << 9) 86#define DAVINCI_I2C_MDR_TRX (1 << 9)
87#define DAVINCI_I2C_MDR_XA (1 << 8) 87#define DAVINCI_I2C_MDR_XA (1 << 8)
88#define DAVINCI_I2C_MDR_RM (1 << 7)
88#define DAVINCI_I2C_MDR_IRS (1 << 5) 89#define DAVINCI_I2C_MDR_IRS (1 << 5)
89 90
90#define DAVINCI_I2C_IMR_AAS (1 << 6) 91#define DAVINCI_I2C_IMR_AAS (1 << 6)
@@ -112,6 +113,7 @@ struct davinci_i2c_dev {
112 u8 *buf; 113 u8 *buf;
113 size_t buf_len; 114 size_t buf_len;
114 int irq; 115 int irq;
116 u8 terminate;
115 struct i2c_adapter adapter; 117 struct i2c_adapter adapter;
116}; 118};
117 119
@@ -142,6 +144,7 @@ static int i2c_davinci_init(struct davinci_i2c_dev *dev)
142 struct davinci_i2c_platform_data *pdata = dev->dev->platform_data; 144 struct davinci_i2c_platform_data *pdata = dev->dev->platform_data;
143 u16 psc; 145 u16 psc;
144 u32 clk; 146 u32 clk;
147 u32 d;
145 u32 clkh; 148 u32 clkh;
146 u32 clkl; 149 u32 clkl;
147 u32 input_clock = clk_get_rate(dev->clk); 150 u32 input_clock = clk_get_rate(dev->clk);
@@ -171,23 +174,29 @@ static int i2c_davinci_init(struct davinci_i2c_dev *dev)
171 * if PSC > 1 , d = 5 174 * if PSC > 1 , d = 5
172 */ 175 */
173 176
174 psc = 26; /* To get 1MHz clock */ 177 /* get minimum of 7 MHz clock, but max of 12 MHz */
178 psc = (input_clock / 7000000) - 1;
179 if ((input_clock / (psc + 1)) > 12000000)
180 psc++; /* better to run under spec than over */
181 d = (psc >= 2) ? 5 : 7 - psc;
175 182
176 clk = ((input_clock / (psc + 1)) / (pdata->bus_freq * 1000)) - 10; 183 clk = ((input_clock / (psc + 1)) / (pdata->bus_freq * 1000)) - (d << 1);
177 clkh = (50 * clk) / 100; 184 clkh = clk >> 1;
178 clkl = clk - clkh; 185 clkl = clk - clkh;
179 186
180 davinci_i2c_write_reg(dev, DAVINCI_I2C_PSC_REG, psc); 187 davinci_i2c_write_reg(dev, DAVINCI_I2C_PSC_REG, psc);
181 davinci_i2c_write_reg(dev, DAVINCI_I2C_CLKH_REG, clkh); 188 davinci_i2c_write_reg(dev, DAVINCI_I2C_CLKH_REG, clkh);
182 davinci_i2c_write_reg(dev, DAVINCI_I2C_CLKL_REG, clkl); 189 davinci_i2c_write_reg(dev, DAVINCI_I2C_CLKL_REG, clkl);
183 190
184 dev_dbg(dev->dev, "CLK = %d\n", clk); 191 dev_dbg(dev->dev, "input_clock = %d, CLK = %d\n", input_clock, clk);
185 dev_dbg(dev->dev, "PSC = %d\n", 192 dev_dbg(dev->dev, "PSC = %d\n",
186 davinci_i2c_read_reg(dev, DAVINCI_I2C_PSC_REG)); 193 davinci_i2c_read_reg(dev, DAVINCI_I2C_PSC_REG));
187 dev_dbg(dev->dev, "CLKL = %d\n", 194 dev_dbg(dev->dev, "CLKL = %d\n",
188 davinci_i2c_read_reg(dev, DAVINCI_I2C_CLKL_REG)); 195 davinci_i2c_read_reg(dev, DAVINCI_I2C_CLKL_REG));
189 dev_dbg(dev->dev, "CLKH = %d\n", 196 dev_dbg(dev->dev, "CLKH = %d\n",
190 davinci_i2c_read_reg(dev, DAVINCI_I2C_CLKH_REG)); 197 davinci_i2c_read_reg(dev, DAVINCI_I2C_CLKH_REG));
198 dev_dbg(dev->dev, "bus_freq = %dkHz, bus_delay = %d\n",
199 pdata->bus_freq, pdata->bus_delay);
191 200
192 /* Take the I2C module out of reset: */ 201 /* Take the I2C module out of reset: */
193 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG); 202 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG);
@@ -233,7 +242,6 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
233 struct davinci_i2c_dev *dev = i2c_get_adapdata(adap); 242 struct davinci_i2c_dev *dev = i2c_get_adapdata(adap);
234 struct davinci_i2c_platform_data *pdata = dev->dev->platform_data; 243 struct davinci_i2c_platform_data *pdata = dev->dev->platform_data;
235 u32 flag; 244 u32 flag;
236 u32 stat;
237 u16 w; 245 u16 w;
238 int r; 246 int r;
239 247
@@ -254,12 +262,9 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
254 262
255 davinci_i2c_write_reg(dev, DAVINCI_I2C_CNT_REG, dev->buf_len); 263 davinci_i2c_write_reg(dev, DAVINCI_I2C_CNT_REG, dev->buf_len);
256 264
257 init_completion(&dev->cmd_complete); 265 INIT_COMPLETION(dev->cmd_complete);
258 dev->cmd_err = 0; 266 dev->cmd_err = 0;
259 267
260 /* Clear any pending interrupts by reading the IVR */
261 stat = davinci_i2c_read_reg(dev, DAVINCI_I2C_IVR_REG);
262
263 /* Take I2C out of reset, configure it as master and set the 268 /* Take I2C out of reset, configure it as master and set the
264 * start bit */ 269 * start bit */
265 flag = DAVINCI_I2C_MDR_IRS | DAVINCI_I2C_MDR_MST | DAVINCI_I2C_MDR_STT; 270 flag = DAVINCI_I2C_MDR_IRS | DAVINCI_I2C_MDR_MST | DAVINCI_I2C_MDR_STT;
@@ -280,20 +285,34 @@ i2c_davinci_xfer_msg(struct i2c_adapter *adap, struct i2c_msg *msg, int stop)
280 MOD_REG_BIT(w, DAVINCI_I2C_IMR_XRDY, 1); 285 MOD_REG_BIT(w, DAVINCI_I2C_IMR_XRDY, 1);
281 davinci_i2c_write_reg(dev, DAVINCI_I2C_IMR_REG, w); 286 davinci_i2c_write_reg(dev, DAVINCI_I2C_IMR_REG, w);
282 287
288 dev->terminate = 0;
283 /* write the data into mode register */ 289 /* write the data into mode register */
284 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag); 290 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, flag);
285 291
286 r = wait_for_completion_interruptible_timeout(&dev->cmd_complete, 292 r = wait_for_completion_interruptible_timeout(&dev->cmd_complete,
287 DAVINCI_I2C_TIMEOUT); 293 DAVINCI_I2C_TIMEOUT);
288 dev->buf_len = 0;
289 if (r < 0)
290 return r;
291
292 if (r == 0) { 294 if (r == 0) {
293 dev_err(dev->dev, "controller timed out\n"); 295 dev_err(dev->dev, "controller timed out\n");
294 i2c_davinci_init(dev); 296 i2c_davinci_init(dev);
297 dev->buf_len = 0;
295 return -ETIMEDOUT; 298 return -ETIMEDOUT;
296 } 299 }
300 if (dev->buf_len) {
301 /* This should be 0 if all bytes were transferred
302 * or dev->cmd_err denotes an error.
303 * A signal may have aborted the transfer.
304 */
305 if (r >= 0) {
306 dev_err(dev->dev, "abnormal termination buf_len=%i\n",
307 dev->buf_len);
308 r = -EREMOTEIO;
309 }
310 dev->terminate = 1;
311 wmb();
312 dev->buf_len = 0;
313 }
314 if (r < 0)
315 return r;
297 316
298 /* no error */ 317 /* no error */
299 if (likely(!dev->cmd_err)) 318 if (likely(!dev->cmd_err))
@@ -338,12 +357,11 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
338 357
339 for (i = 0; i < num; i++) { 358 for (i = 0; i < num; i++) {
340 ret = i2c_davinci_xfer_msg(adap, &msgs[i], (i == (num - 1))); 359 ret = i2c_davinci_xfer_msg(adap, &msgs[i], (i == (num - 1)));
360 dev_dbg(dev->dev, "%s [%d/%d] ret: %d\n", __func__, i + 1, num,
361 ret);
341 if (ret < 0) 362 if (ret < 0)
342 return ret; 363 return ret;
343 } 364 }
344
345 dev_dbg(dev->dev, "%s:%d ret: %d\n", __func__, __LINE__, ret);
346
347 return num; 365 return num;
348} 366}
349 367
@@ -352,6 +370,27 @@ static u32 i2c_davinci_func(struct i2c_adapter *adap)
352 return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK); 370 return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);
353} 371}
354 372
373static void terminate_read(struct davinci_i2c_dev *dev)
374{
375 u16 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG);
376 w |= DAVINCI_I2C_MDR_NACK;
377 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w);
378
379 /* Throw away data */
380 davinci_i2c_read_reg(dev, DAVINCI_I2C_DRR_REG);
381 if (!dev->terminate)
382 dev_err(dev->dev, "RDR IRQ while no data requested\n");
383}
384static void terminate_write(struct davinci_i2c_dev *dev)
385{
386 u16 w = davinci_i2c_read_reg(dev, DAVINCI_I2C_MDR_REG);
387 w |= DAVINCI_I2C_MDR_RM | DAVINCI_I2C_MDR_STP;
388 davinci_i2c_write_reg(dev, DAVINCI_I2C_MDR_REG, w);
389
390 if (!dev->terminate)
391 dev_err(dev->dev, "TDR IRQ while no data to send\n");
392}
393
355/* 394/*
356 * Interrupt service routine. This gets called whenever an I2C interrupt 395 * Interrupt service routine. This gets called whenever an I2C interrupt
357 * occurs. 396 * occurs.
@@ -372,12 +411,15 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
372 411
373 switch (stat) { 412 switch (stat) {
374 case DAVINCI_I2C_IVR_AL: 413 case DAVINCI_I2C_IVR_AL:
414 /* Arbitration lost, must retry */
375 dev->cmd_err |= DAVINCI_I2C_STR_AL; 415 dev->cmd_err |= DAVINCI_I2C_STR_AL;
416 dev->buf_len = 0;
376 complete(&dev->cmd_complete); 417 complete(&dev->cmd_complete);
377 break; 418 break;
378 419
379 case DAVINCI_I2C_IVR_NACK: 420 case DAVINCI_I2C_IVR_NACK:
380 dev->cmd_err |= DAVINCI_I2C_STR_NACK; 421 dev->cmd_err |= DAVINCI_I2C_STR_NACK;
422 dev->buf_len = 0;
381 complete(&dev->cmd_complete); 423 complete(&dev->cmd_complete);
382 break; 424 break;
383 425
@@ -399,9 +441,10 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
399 davinci_i2c_write_reg(dev, 441 davinci_i2c_write_reg(dev,
400 DAVINCI_I2C_STR_REG, 442 DAVINCI_I2C_STR_REG,
401 DAVINCI_I2C_IMR_RRDY); 443 DAVINCI_I2C_IMR_RRDY);
402 } else 444 } else {
403 dev_err(dev->dev, "RDR IRQ while no " 445 /* signal can terminate transfer */
404 "data requested\n"); 446 terminate_read(dev);
447 }
405 break; 448 break;
406 449
407 case DAVINCI_I2C_IVR_XRDY: 450 case DAVINCI_I2C_IVR_XRDY:
@@ -418,9 +461,10 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
418 davinci_i2c_write_reg(dev, 461 davinci_i2c_write_reg(dev,
419 DAVINCI_I2C_IMR_REG, 462 DAVINCI_I2C_IMR_REG,
420 w); 463 w);
421 } else 464 } else {
422 dev_err(dev->dev, "TDR IRQ while no data to " 465 /* signal can terminate transfer */
423 "send\n"); 466 terminate_write(dev);
467 }
424 break; 468 break;
425 469
426 case DAVINCI_I2C_IVR_SCD: 470 case DAVINCI_I2C_IVR_SCD:
@@ -475,6 +519,7 @@ static int davinci_i2c_probe(struct platform_device *pdev)
475 goto err_release_region; 519 goto err_release_region;
476 } 520 }
477 521
522 init_completion(&dev->cmd_complete);
478 dev->dev = get_device(&pdev->dev); 523 dev->dev = get_device(&pdev->dev);
479 dev->irq = irq->start; 524 dev->irq = irq->start;
480 platform_set_drvdata(pdev, dev); 525 platform_set_drvdata(pdev, dev);
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c
index b7a9977b025f..7f38c01fb3a0 100644
--- a/drivers/i2c/busses/i2c-elektor.c
+++ b/drivers/i2c/busses/i2c-elektor.c
@@ -196,13 +196,11 @@ static struct i2c_algo_pcf_data pcf_isa_data = {
196 .getown = pcf_isa_getown, 196 .getown = pcf_isa_getown,
197 .getclock = pcf_isa_getclock, 197 .getclock = pcf_isa_getclock,
198 .waitforpin = pcf_isa_waitforpin, 198 .waitforpin = pcf_isa_waitforpin,
199 .udelay = 10,
200 .timeout = 100,
201}; 199};
202 200
203static struct i2c_adapter pcf_isa_ops = { 201static struct i2c_adapter pcf_isa_ops = {
204 .owner = THIS_MODULE, 202 .owner = THIS_MODULE,
205 .class = I2C_CLASS_HWMON, 203 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
206 .id = I2C_HW_P_ELEK, 204 .id = I2C_HW_P_ELEK,
207 .algo_data = &pcf_isa_data, 205 .algo_data = &pcf_isa_data,
208 .name = "i2c-elektor", 206 .name = "i2c-elektor",
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
index 7c1b762aa681..32104eac8d3d 100644
--- a/drivers/i2c/busses/i2c-gpio.c
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -77,7 +77,7 @@ static int i2c_gpio_getscl(void *data)
77 return gpio_get_value(pdata->scl_pin); 77 return gpio_get_value(pdata->scl_pin);
78} 78}
79 79
80static int __init i2c_gpio_probe(struct platform_device *pdev) 80static int __devinit i2c_gpio_probe(struct platform_device *pdev)
81{ 81{
82 struct i2c_gpio_platform_data *pdata; 82 struct i2c_gpio_platform_data *pdata;
83 struct i2c_algo_bit_data *bit_data; 83 struct i2c_algo_bit_data *bit_data;
@@ -140,7 +140,7 @@ static int __init i2c_gpio_probe(struct platform_device *pdev)
140 adap->owner = THIS_MODULE; 140 adap->owner = THIS_MODULE;
141 snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id); 141 snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id);
142 adap->algo_data = bit_data; 142 adap->algo_data = bit_data;
143 adap->class = I2C_CLASS_HWMON; 143 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
144 adap->dev.parent = &pdev->dev; 144 adap->dev.parent = &pdev->dev;
145 145
146 /* 146 /*
@@ -174,7 +174,7 @@ err_alloc_adap:
174 return ret; 174 return ret;
175} 175}
176 176
177static int __exit i2c_gpio_remove(struct platform_device *pdev) 177static int __devexit i2c_gpio_remove(struct platform_device *pdev)
178{ 178{
179 struct i2c_gpio_platform_data *pdata; 179 struct i2c_gpio_platform_data *pdata;
180 struct i2c_adapter *adap; 180 struct i2c_adapter *adap;
@@ -196,14 +196,15 @@ static struct platform_driver i2c_gpio_driver = {
196 .name = "i2c-gpio", 196 .name = "i2c-gpio",
197 .owner = THIS_MODULE, 197 .owner = THIS_MODULE,
198 }, 198 },
199 .remove = __exit_p(i2c_gpio_remove), 199 .probe = i2c_gpio_probe,
200 .remove = __devexit_p(i2c_gpio_remove),
200}; 201};
201 202
202static int __init i2c_gpio_init(void) 203static int __init i2c_gpio_init(void)
203{ 204{
204 int ret; 205 int ret;
205 206
206 ret = platform_driver_probe(&i2c_gpio_driver, i2c_gpio_probe); 207 ret = platform_driver_register(&i2c_gpio_driver);
207 if (ret) 208 if (ret)
208 printk(KERN_ERR "i2c-gpio: probe failed: %d\n", ret); 209 printk(KERN_ERR "i2c-gpio: probe failed: %d\n", ret);
209 210
diff --git a/drivers/i2c/busses/i2c-hydra.c b/drivers/i2c/busses/i2c-hydra.c
index f9972f9651e4..1098f21ace13 100644
--- a/drivers/i2c/busses/i2c-hydra.c
+++ b/drivers/i2c/busses/i2c-hydra.c
@@ -1,7 +1,4 @@
1/* 1/*
2 i2c-hydra.c - Part of lm_sensors, Linux kernel modules
3 for hardware monitoring
4
5 i2c Support for the Apple `Hydra' Mac I/O 2 i2c Support for the Apple `Hydra' Mac I/O
6 3
7 Copyright (c) 1999-2004 Geert Uytterhoeven <geert@linux-m68k.org> 4 Copyright (c) 1999-2004 Geert Uytterhoeven <geert@linux-m68k.org>
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index b0f771fe4326..dc7ea32b69a8 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -1,10 +1,8 @@
1/* 1/*
2 i2c-i801.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>, 2 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>,
5 Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker 3 Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker
6 <mdsxyz123@yahoo.com> 4 <mdsxyz123@yahoo.com>
7 Copyright (C) 2007 Jean Delvare <khali@linux-fr.org> 5 Copyright (C) 2007, 2008 Jean Delvare <khali@linux-fr.org>
8 6
9 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
@@ -64,6 +62,7 @@
64#include <linux/ioport.h> 62#include <linux/ioport.h>
65#include <linux/init.h> 63#include <linux/init.h>
66#include <linux/i2c.h> 64#include <linux/i2c.h>
65#include <linux/acpi.h>
67#include <asm/io.h> 66#include <asm/io.h>
68 67
69/* I801 SMBus address offsets */ 68/* I801 SMBus address offsets */
@@ -121,6 +120,10 @@
121#define SMBHSTSTS_INTR 0x02 120#define SMBHSTSTS_INTR 0x02
122#define SMBHSTSTS_HOST_BUSY 0x01 121#define SMBHSTSTS_HOST_BUSY 0x01
123 122
123#define STATUS_FLAGS (SMBHSTSTS_BYTE_DONE | SMBHSTSTS_FAILED | \
124 SMBHSTSTS_BUS_ERR | SMBHSTSTS_DEV_ERR | \
125 SMBHSTSTS_INTR)
126
124static unsigned long i801_smba; 127static unsigned long i801_smba;
125static unsigned char i801_original_hstcfg; 128static unsigned char i801_original_hstcfg;
126static struct pci_driver i801_driver; 129static struct pci_driver i801_driver;
@@ -132,105 +135,137 @@ static struct pci_dev *I801_dev;
132#define FEATURE_I2C_BLOCK_READ (1 << 3) 135#define FEATURE_I2C_BLOCK_READ (1 << 3)
133static unsigned int i801_features; 136static unsigned int i801_features;
134 137
135static int i801_transaction(int xact) 138/* Make sure the SMBus host is ready to start transmitting.
139 Return 0 if it is, -EBUSY if it is not. */
140static int i801_check_pre(void)
136{ 141{
137 int temp; 142 int status;
138 int result = 0;
139 int timeout = 0;
140 143
141 dev_dbg(&I801_dev->dev, "Transaction (pre): CNT=%02x, CMD=%02x, " 144 status = inb_p(SMBHSTSTS);
142 "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), 145 if (status & SMBHSTSTS_HOST_BUSY) {
143 inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), 146 dev_err(&I801_dev->dev, "SMBus is busy, can't use it!\n");
144 inb_p(SMBHSTDAT1)); 147 return -EBUSY;
145 148 }
146 /* Make sure the SMBus host is ready to start transmitting */ 149
147 /* 0x1f = Failed, Bus_Err, Dev_Err, Intr, Host_Busy */ 150 status &= STATUS_FLAGS;
148 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { 151 if (status) {
149 dev_dbg(&I801_dev->dev, "SMBus busy (%02x). Resetting...\n", 152 dev_dbg(&I801_dev->dev, "Clearing status flags (%02x)\n",
150 temp); 153 status);
151 outb_p(temp, SMBHSTSTS); 154 outb_p(status, SMBHSTSTS);
152 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { 155 status = inb_p(SMBHSTSTS) & STATUS_FLAGS;
153 dev_dbg(&I801_dev->dev, "Failed! (%02x)\n", temp); 156 if (status) {
154 return -1; 157 dev_err(&I801_dev->dev,
155 } else { 158 "Failed clearing status flags (%02x)\n",
156 dev_dbg(&I801_dev->dev, "Successful!\n"); 159 status);
160 return -EBUSY;
157 } 161 }
158 } 162 }
159 163
160 /* the current contents of SMBHSTCNT can be overwritten, since PEC, 164 return 0;
161 * INTREN, SMBSCMD are passed in xact */ 165}
162 outb_p(xact | I801_START, SMBHSTCNT);
163 166
164 /* We will always wait for a fraction of a second! */ 167/* Convert the status register to an error code, and clear it. */
165 do { 168static int i801_check_post(int status, int timeout)
166 msleep(1); 169{
167 temp = inb_p(SMBHSTSTS); 170 int result = 0;
168 } while ((temp & SMBHSTSTS_HOST_BUSY) && (timeout++ < MAX_TIMEOUT));
169 171
170 /* If the SMBus is still busy, we give up */ 172 /* If the SMBus is still busy, we give up */
171 if (timeout >= MAX_TIMEOUT) { 173 if (timeout) {
172 dev_dbg(&I801_dev->dev, "SMBus Timeout!\n"); 174 dev_err(&I801_dev->dev, "Transaction timeout\n");
173 result = -1;
174 /* try to stop the current command */ 175 /* try to stop the current command */
175 dev_dbg(&I801_dev->dev, "Terminating the current operation\n"); 176 dev_dbg(&I801_dev->dev, "Terminating the current operation\n");
176 outb_p(inb_p(SMBHSTCNT) | SMBHSTCNT_KILL, SMBHSTCNT); 177 outb_p(inb_p(SMBHSTCNT) | SMBHSTCNT_KILL, SMBHSTCNT);
177 msleep(1); 178 msleep(1);
178 outb_p(inb_p(SMBHSTCNT) & (~SMBHSTCNT_KILL), SMBHSTCNT); 179 outb_p(inb_p(SMBHSTCNT) & (~SMBHSTCNT_KILL), SMBHSTCNT);
179 }
180 180
181 if (temp & SMBHSTSTS_FAILED) { 181 /* Check if it worked */
182 result = -1; 182 status = inb_p(SMBHSTSTS);
183 dev_dbg(&I801_dev->dev, "Error: Failed bus transaction\n"); 183 if ((status & SMBHSTSTS_HOST_BUSY) ||
184 !(status & SMBHSTSTS_FAILED))
185 dev_err(&I801_dev->dev,
186 "Failed terminating the transaction\n");
187 outb_p(STATUS_FLAGS, SMBHSTSTS);
188 return -ETIMEDOUT;
184 } 189 }
185 190
186 if (temp & SMBHSTSTS_BUS_ERR) { 191 if (status & SMBHSTSTS_FAILED) {
187 result = -1; 192 result = -EIO;
188 dev_err(&I801_dev->dev, "Bus collision! SMBus may be locked " 193 dev_err(&I801_dev->dev, "Transaction failed\n");
189 "until next hard reset. (sorry!)\n");
190 /* Clock stops and slave is stuck in mid-transmission */
191 } 194 }
192 195 if (status & SMBHSTSTS_DEV_ERR) {
193 if (temp & SMBHSTSTS_DEV_ERR) { 196 result = -ENXIO;
194 result = -1; 197 dev_dbg(&I801_dev->dev, "No response\n");
195 dev_dbg(&I801_dev->dev, "Error: no response!\n"); 198 }
199 if (status & SMBHSTSTS_BUS_ERR) {
200 result = -EAGAIN;
201 dev_dbg(&I801_dev->dev, "Lost arbitration\n");
196 } 202 }
197 203
198 if ((inb_p(SMBHSTSTS) & 0x1f) != 0x00) 204 if (result) {
199 outb_p(inb(SMBHSTSTS), SMBHSTSTS); 205 /* Clear error flags */
200 206 outb_p(status & STATUS_FLAGS, SMBHSTSTS);
201 if ((temp = (0x1f & inb_p(SMBHSTSTS))) != 0x00) { 207 status = inb_p(SMBHSTSTS) & STATUS_FLAGS;
202 dev_dbg(&I801_dev->dev, "Failed reset at end of transaction " 208 if (status) {
203 "(%02x)\n", temp); 209 dev_warn(&I801_dev->dev, "Failed clearing status "
210 "flags at end of transaction (%02x)\n",
211 status);
212 }
204 } 213 }
205 dev_dbg(&I801_dev->dev, "Transaction (post): CNT=%02x, CMD=%02x, " 214
206 "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT),
207 inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
208 inb_p(SMBHSTDAT1));
209 return result; 215 return result;
210} 216}
211 217
218static int i801_transaction(int xact)
219{
220 int status;
221 int result;
222 int timeout = 0;
223
224 result = i801_check_pre();
225 if (result < 0)
226 return result;
227
228 /* the current contents of SMBHSTCNT can be overwritten, since PEC,
229 * INTREN, SMBSCMD are passed in xact */
230 outb_p(xact | I801_START, SMBHSTCNT);
231
232 /* We will always wait for a fraction of a second! */
233 do {
234 msleep(1);
235 status = inb_p(SMBHSTSTS);
236 } while ((status & SMBHSTSTS_HOST_BUSY) && (timeout++ < MAX_TIMEOUT));
237
238 result = i801_check_post(status, timeout >= MAX_TIMEOUT);
239 if (result < 0)
240 return result;
241
242 outb_p(SMBHSTSTS_INTR, SMBHSTSTS);
243 return 0;
244}
245
212/* wait for INTR bit as advised by Intel */ 246/* wait for INTR bit as advised by Intel */
213static void i801_wait_hwpec(void) 247static void i801_wait_hwpec(void)
214{ 248{
215 int timeout = 0; 249 int timeout = 0;
216 int temp; 250 int status;
217 251
218 do { 252 do {
219 msleep(1); 253 msleep(1);
220 temp = inb_p(SMBHSTSTS); 254 status = inb_p(SMBHSTSTS);
221 } while ((!(temp & SMBHSTSTS_INTR)) 255 } while ((!(status & SMBHSTSTS_INTR))
222 && (timeout++ < MAX_TIMEOUT)); 256 && (timeout++ < MAX_TIMEOUT));
223 257
224 if (timeout >= MAX_TIMEOUT) { 258 if (timeout >= MAX_TIMEOUT) {
225 dev_dbg(&I801_dev->dev, "PEC Timeout!\n"); 259 dev_dbg(&I801_dev->dev, "PEC Timeout!\n");
226 } 260 }
227 outb_p(temp, SMBHSTSTS); 261 outb_p(status, SMBHSTSTS);
228} 262}
229 263
230static int i801_block_transaction_by_block(union i2c_smbus_data *data, 264static int i801_block_transaction_by_block(union i2c_smbus_data *data,
231 char read_write, int hwpec) 265 char read_write, int hwpec)
232{ 266{
233 int i, len; 267 int i, len;
268 int status;
234 269
235 inb_p(SMBHSTCNT); /* reset the data buffer index */ 270 inb_p(SMBHSTCNT); /* reset the data buffer index */
236 271
@@ -242,14 +277,15 @@ static int i801_block_transaction_by_block(union i2c_smbus_data *data,
242 outb_p(data->block[i+1], SMBBLKDAT); 277 outb_p(data->block[i+1], SMBBLKDAT);
243 } 278 }
244 279
245 if (i801_transaction(I801_BLOCK_DATA | ENABLE_INT9 | 280 status = i801_transaction(I801_BLOCK_DATA | ENABLE_INT9 |
246 I801_PEC_EN * hwpec)) 281 I801_PEC_EN * hwpec);
247 return -1; 282 if (status)
283 return status;
248 284
249 if (read_write == I2C_SMBUS_READ) { 285 if (read_write == I2C_SMBUS_READ) {
250 len = inb_p(SMBHSTDAT0); 286 len = inb_p(SMBHSTDAT0);
251 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) 287 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX)
252 return -1; 288 return -EPROTO;
253 289
254 data->block[0] = len; 290 data->block[0] = len;
255 for (i = 0; i < len; i++) 291 for (i = 0; i < len; i++)
@@ -264,10 +300,13 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
264{ 300{
265 int i, len; 301 int i, len;
266 int smbcmd; 302 int smbcmd;
267 int temp; 303 int status;
268 int result = 0; 304 int result;
269 int timeout; 305 int timeout;
270 unsigned char errmask; 306
307 result = i801_check_pre();
308 if (result < 0)
309 return result;
271 310
272 len = data->block[0]; 311 len = data->block[0];
273 312
@@ -291,36 +330,6 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
291 } 330 }
292 outb_p(smbcmd | ENABLE_INT9, SMBHSTCNT); 331 outb_p(smbcmd | ENABLE_INT9, SMBHSTCNT);
293 332
294 dev_dbg(&I801_dev->dev, "Block (pre %d): CNT=%02x, CMD=%02x, "
295 "ADD=%02x, DAT0=%02x, DAT1=%02x, BLKDAT=%02x\n", i,
296 inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), inb_p(SMBHSTADD),
297 inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1), inb_p(SMBBLKDAT));
298
299 /* Make sure the SMBus host is ready to start transmitting */
300 temp = inb_p(SMBHSTSTS);
301 if (i == 1) {
302 /* Erroneous conditions before transaction:
303 * Byte_Done, Failed, Bus_Err, Dev_Err, Intr, Host_Busy */
304 errmask = 0x9f;
305 } else {
306 /* Erroneous conditions during transaction:
307 * Failed, Bus_Err, Dev_Err, Intr */
308 errmask = 0x1e;
309 }
310 if (temp & errmask) {
311 dev_dbg(&I801_dev->dev, "SMBus busy (%02x). "
312 "Resetting...\n", temp);
313 outb_p(temp, SMBHSTSTS);
314 if (((temp = inb_p(SMBHSTSTS)) & errmask) != 0x00) {
315 dev_err(&I801_dev->dev,
316 "Reset failed! (%02x)\n", temp);
317 return -1;
318 }
319 if (i != 1)
320 /* if die in middle of block transaction, fail */
321 return -1;
322 }
323
324 if (i == 1) 333 if (i == 1)
325 outb_p(inb(SMBHSTCNT) | I801_START, SMBHSTCNT); 334 outb_p(inb(SMBHSTCNT) | I801_START, SMBHSTCNT);
326 335
@@ -328,41 +337,28 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
328 timeout = 0; 337 timeout = 0;
329 do { 338 do {
330 msleep(1); 339 msleep(1);
331 temp = inb_p(SMBHSTSTS); 340 status = inb_p(SMBHSTSTS);
332 } 341 }
333 while ((!(temp & SMBHSTSTS_BYTE_DONE)) 342 while ((!(status & SMBHSTSTS_BYTE_DONE))
334 && (timeout++ < MAX_TIMEOUT)); 343 && (timeout++ < MAX_TIMEOUT));
335 344
336 /* If the SMBus is still busy, we give up */ 345 result = i801_check_post(status, timeout >= MAX_TIMEOUT);
337 if (timeout >= MAX_TIMEOUT) { 346 if (result < 0)
338 /* try to stop the current command */ 347 return result;
339 dev_dbg(&I801_dev->dev, "Terminating the current "
340 "operation\n");
341 outb_p(inb_p(SMBHSTCNT) | SMBHSTCNT_KILL, SMBHSTCNT);
342 msleep(1);
343 outb_p(inb_p(SMBHSTCNT) & (~SMBHSTCNT_KILL),
344 SMBHSTCNT);
345 result = -1;
346 dev_dbg(&I801_dev->dev, "SMBus Timeout!\n");
347 }
348
349 if (temp & SMBHSTSTS_FAILED) {
350 result = -1;
351 dev_dbg(&I801_dev->dev,
352 "Error: Failed bus transaction\n");
353 } else if (temp & SMBHSTSTS_BUS_ERR) {
354 result = -1;
355 dev_err(&I801_dev->dev, "Bus collision!\n");
356 } else if (temp & SMBHSTSTS_DEV_ERR) {
357 result = -1;
358 dev_dbg(&I801_dev->dev, "Error: no response!\n");
359 }
360 348
361 if (i == 1 && read_write == I2C_SMBUS_READ 349 if (i == 1 && read_write == I2C_SMBUS_READ
362 && command != I2C_SMBUS_I2C_BLOCK_DATA) { 350 && command != I2C_SMBUS_I2C_BLOCK_DATA) {
363 len = inb_p(SMBHSTDAT0); 351 len = inb_p(SMBHSTDAT0);
364 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) 352 if (len < 1 || len > I2C_SMBUS_BLOCK_MAX) {
365 return -1; 353 dev_err(&I801_dev->dev,
354 "Illegal SMBus block read size %d\n",
355 len);
356 /* Recover */
357 while (inb_p(SMBHSTSTS) & SMBHSTSTS_HOST_BUSY)
358 outb_p(SMBHSTSTS_BYTE_DONE, SMBHSTSTS);
359 outb_p(SMBHSTSTS_INTR, SMBHSTSTS);
360 return -EPROTO;
361 }
366 data->block[0] = len; 362 data->block[0] = len;
367 } 363 }
368 364
@@ -371,30 +367,19 @@ static int i801_block_transaction_byte_by_byte(union i2c_smbus_data *data,
371 data->block[i] = inb_p(SMBBLKDAT); 367 data->block[i] = inb_p(SMBBLKDAT);
372 if (read_write == I2C_SMBUS_WRITE && i+1 <= len) 368 if (read_write == I2C_SMBUS_WRITE && i+1 <= len)
373 outb_p(data->block[i+1], SMBBLKDAT); 369 outb_p(data->block[i+1], SMBBLKDAT);
374 if ((temp & 0x9e) != 0x00)
375 outb_p(temp, SMBHSTSTS); /* signals SMBBLKDAT ready */
376
377 if ((temp = (0x1e & inb_p(SMBHSTSTS))) != 0x00) {
378 dev_dbg(&I801_dev->dev,
379 "Bad status (%02x) at end of transaction\n",
380 temp);
381 }
382 dev_dbg(&I801_dev->dev, "Block (post %d): CNT=%02x, CMD=%02x, "
383 "ADD=%02x, DAT0=%02x, DAT1=%02x, BLKDAT=%02x\n", i,
384 inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), inb_p(SMBHSTADD),
385 inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1), inb_p(SMBBLKDAT));
386 370
387 if (result < 0) 371 /* signals SMBBLKDAT ready */
388 return result; 372 outb_p(SMBHSTSTS_BYTE_DONE | SMBHSTSTS_INTR, SMBHSTSTS);
389 } 373 }
390 return result; 374
375 return 0;
391} 376}
392 377
393static int i801_set_block_buffer_mode(void) 378static int i801_set_block_buffer_mode(void)
394{ 379{
395 outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_E32B, SMBAUXCTL); 380 outb_p(inb_p(SMBAUXCTL) | SMBAUXCTL_E32B, SMBAUXCTL);
396 if ((inb_p(SMBAUXCTL) & SMBAUXCTL_E32B) == 0) 381 if ((inb_p(SMBAUXCTL) & SMBAUXCTL_E32B) == 0)
397 return -1; 382 return -EIO;
398 return 0; 383 return 0;
399} 384}
400 385
@@ -414,7 +399,7 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
414 } else if (!(i801_features & FEATURE_I2C_BLOCK_READ)) { 399 } else if (!(i801_features & FEATURE_I2C_BLOCK_READ)) {
415 dev_err(&I801_dev->dev, 400 dev_err(&I801_dev->dev,
416 "I2C block read is unsupported!\n"); 401 "I2C block read is unsupported!\n");
417 return -1; 402 return -EOPNOTSUPP;
418 } 403 }
419 } 404 }
420 405
@@ -449,7 +434,7 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
449 return result; 434 return result;
450} 435}
451 436
452/* Return -1 on error. */ 437/* Return negative errno on error. */
453static s32 i801_access(struct i2c_adapter * adap, u16 addr, 438static s32 i801_access(struct i2c_adapter * adap, u16 addr,
454 unsigned short flags, char read_write, u8 command, 439 unsigned short flags, char read_write, u8 command,
455 int size, union i2c_smbus_data * data) 440 int size, union i2c_smbus_data * data)
@@ -511,10 +496,9 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
511 outb_p(command, SMBHSTCMD); 496 outb_p(command, SMBHSTCMD);
512 block = 1; 497 block = 1;
513 break; 498 break;
514 case I2C_SMBUS_PROC_CALL:
515 default: 499 default:
516 dev_err(&I801_dev->dev, "Unsupported transaction %d\n", size); 500 dev_err(&I801_dev->dev, "Unsupported transaction %d\n", size);
517 return -1; 501 return -EOPNOTSUPP;
518 } 502 }
519 503
520 if (hwpec) /* enable/disable hardware PEC */ 504 if (hwpec) /* enable/disable hardware PEC */
@@ -537,7 +521,7 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
537 if(block) 521 if(block)
538 return ret; 522 return ret;
539 if(ret) 523 if(ret)
540 return -1; 524 return ret;
541 if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK)) 525 if ((read_write == I2C_SMBUS_WRITE) || (xact == I801_QUICK))
542 return 0; 526 return 0;
543 527
@@ -572,7 +556,7 @@ static const struct i2c_algorithm smbus_algorithm = {
572static struct i2c_adapter i801_adapter = { 556static struct i2c_adapter i801_adapter = {
573 .owner = THIS_MODULE, 557 .owner = THIS_MODULE,
574 .id = I2C_HW_SMBUS_I801, 558 .id = I2C_HW_SMBUS_I801,
575 .class = I2C_CLASS_HWMON, 559 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
576 .algo = &smbus_algorithm, 560 .algo = &smbus_algorithm,
577}; 561};
578 562
@@ -639,6 +623,10 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
639 goto exit; 623 goto exit;
640 } 624 }
641 625
626 err = acpi_check_resource_conflict(&dev->resource[SMBBAR]);
627 if (err)
628 goto exit;
629
642 err = pci_request_region(dev, SMBBAR, i801_driver.name); 630 err = pci_request_region(dev, SMBBAR, i801_driver.name);
643 if (err) { 631 if (err) {
644 dev_err(&dev->dev, "Failed to request SMBus region " 632 dev_err(&dev->dev, "Failed to request SMBus region "
diff --git a/drivers/i2c/busses/i2c-i810.c b/drivers/i2c/busses/i2c-i810.c
deleted file mode 100644
index 42e8d94c276f..000000000000
--- a/drivers/i2c/busses/i2c-i810.c
+++ /dev/null
@@ -1,260 +0,0 @@
1/*
2 i2c-i810.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 1998, 1999, 2000 Frodo Looijaard <frodol@dds.nl>,
5 Philip Edelbrock <phil@netroedge.com>,
6 Ralph Metzler <rjkm@thp.uni-koeln.de>, and
7 Mark D. Studebaker <mdsxyz123@yahoo.com>
8
9 Based on code written by Ralph Metzler <rjkm@thp.uni-koeln.de> and
10 Simon Vogl
11
12 This program is free software; you can redistribute it and/or modify
13 it under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 2 of the License, or
15 (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25*/
26/*
27 This interfaces to the I810/I815 to provide access to
28 the DDC Bus and the I2C Bus.
29
30 SUPPORTED DEVICES PCI ID
31 i810AA 7121
32 i810AB 7123
33 i810E 7125
34 i815 1132
35 i845G 2562
36*/
37
38#include <linux/kernel.h>
39#include <linux/module.h>
40#include <linux/init.h>
41#include <linux/pci.h>
42#include <linux/i2c.h>
43#include <linux/i2c-algo-bit.h>
44#include <asm/io.h>
45
46/* GPIO register locations */
47#define I810_IOCONTROL_OFFSET 0x5000
48#define I810_HVSYNC 0x00 /* not used */
49#define I810_GPIOA 0x10
50#define I810_GPIOB 0x14
51
52/* bit locations in the registers */
53#define SCL_DIR_MASK 0x0001
54#define SCL_DIR 0x0002
55#define SCL_VAL_MASK 0x0004
56#define SCL_VAL_OUT 0x0008
57#define SCL_VAL_IN 0x0010
58#define SDA_DIR_MASK 0x0100
59#define SDA_DIR 0x0200
60#define SDA_VAL_MASK 0x0400
61#define SDA_VAL_OUT 0x0800
62#define SDA_VAL_IN 0x1000
63
64/* initialization states */
65#define INIT1 0x1
66#define INIT2 0x2
67#define INIT3 0x4
68
69/* delays */
70#define CYCLE_DELAY 10
71#define TIMEOUT (HZ / 2)
72
73static void __iomem *ioaddr;
74
75/* The i810 GPIO registers have individual masks for each bit
76 so we never have to read before writing. Nice. */
77
78static void bit_i810i2c_setscl(void *data, int val)
79{
80 writel((val ? SCL_VAL_OUT : 0) | SCL_DIR | SCL_DIR_MASK | SCL_VAL_MASK,
81 ioaddr + I810_GPIOB);
82 readl(ioaddr + I810_GPIOB); /* flush posted write */
83}
84
85static void bit_i810i2c_setsda(void *data, int val)
86{
87 writel((val ? SDA_VAL_OUT : 0) | SDA_DIR | SDA_DIR_MASK | SDA_VAL_MASK,
88 ioaddr + I810_GPIOB);
89 readl(ioaddr + I810_GPIOB); /* flush posted write */
90}
91
92/* The GPIO pins are open drain, so the pins could always remain outputs.
93 However, some chip versions don't latch the inputs unless they
94 are set as inputs.
95 We rely on the i2c-algo-bit routines to set the pins high before
96 reading the input from other chips. Following guidance in the 815
97 prog. ref. guide, we do a "dummy write" of 0 to the register before
98 reading which forces the input value to be latched. We presume this
99 applies to the 810 as well; shouldn't hurt anyway. This is necessary to get
100 i2c_algo_bit bit_test=1 to pass. */
101
102static int bit_i810i2c_getscl(void *data)
103{
104 writel(SCL_DIR_MASK, ioaddr + I810_GPIOB);
105 writel(0, ioaddr + I810_GPIOB);
106 return (0 != (readl(ioaddr + I810_GPIOB) & SCL_VAL_IN));
107}
108
109static int bit_i810i2c_getsda(void *data)
110{
111 writel(SDA_DIR_MASK, ioaddr + I810_GPIOB);
112 writel(0, ioaddr + I810_GPIOB);
113 return (0 != (readl(ioaddr + I810_GPIOB) & SDA_VAL_IN));
114}
115
116static void bit_i810ddc_setscl(void *data, int val)
117{
118 writel((val ? SCL_VAL_OUT : 0) | SCL_DIR | SCL_DIR_MASK | SCL_VAL_MASK,
119 ioaddr + I810_GPIOA);
120 readl(ioaddr + I810_GPIOA); /* flush posted write */
121}
122
123static void bit_i810ddc_setsda(void *data, int val)
124{
125 writel((val ? SDA_VAL_OUT : 0) | SDA_DIR | SDA_DIR_MASK | SDA_VAL_MASK,
126 ioaddr + I810_GPIOA);
127 readl(ioaddr + I810_GPIOA); /* flush posted write */
128}
129
130static int bit_i810ddc_getscl(void *data)
131{
132 writel(SCL_DIR_MASK, ioaddr + I810_GPIOA);
133 writel(0, ioaddr + I810_GPIOA);
134 return (0 != (readl(ioaddr + I810_GPIOA) & SCL_VAL_IN));
135}
136
137static int bit_i810ddc_getsda(void *data)
138{
139 writel(SDA_DIR_MASK, ioaddr + I810_GPIOA);
140 writel(0, ioaddr + I810_GPIOA);
141 return (0 != (readl(ioaddr + I810_GPIOA) & SDA_VAL_IN));
142}
143
144static int config_i810(struct pci_dev *dev)
145{
146 unsigned long cadr;
147
148 /* map I810 memory */
149 cadr = dev->resource[1].start;
150 cadr += I810_IOCONTROL_OFFSET;
151 cadr &= PCI_BASE_ADDRESS_MEM_MASK;
152 ioaddr = ioremap_nocache(cadr, 0x1000);
153 if (ioaddr) {
154 bit_i810i2c_setscl(NULL, 1);
155 bit_i810i2c_setsda(NULL, 1);
156 bit_i810ddc_setscl(NULL, 1);
157 bit_i810ddc_setsda(NULL, 1);
158 return 0;
159 }
160 return -ENODEV;
161}
162
163static struct i2c_algo_bit_data i810_i2c_bit_data = {
164 .setsda = bit_i810i2c_setsda,
165 .setscl = bit_i810i2c_setscl,
166 .getsda = bit_i810i2c_getsda,
167 .getscl = bit_i810i2c_getscl,
168 .udelay = CYCLE_DELAY,
169 .timeout = TIMEOUT,
170};
171
172static struct i2c_adapter i810_i2c_adapter = {
173 .owner = THIS_MODULE,
174 .id = I2C_HW_B_I810,
175 .name = "I810/I815 I2C Adapter",
176 .algo_data = &i810_i2c_bit_data,
177};
178
179static struct i2c_algo_bit_data i810_ddc_bit_data = {
180 .setsda = bit_i810ddc_setsda,
181 .setscl = bit_i810ddc_setscl,
182 .getsda = bit_i810ddc_getsda,
183 .getscl = bit_i810ddc_getscl,
184 .udelay = CYCLE_DELAY,
185 .timeout = TIMEOUT,
186};
187
188static struct i2c_adapter i810_ddc_adapter = {
189 .owner = THIS_MODULE,
190 .id = I2C_HW_B_I810,
191 .name = "I810/I815 DDC Adapter",
192 .algo_data = &i810_ddc_bit_data,
193};
194
195static struct pci_device_id i810_ids[] __devinitdata = {
196 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG1) },
197 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG3) },
198 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810E_IG) },
199 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC) },
200 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845G_IG) },
201 { 0, },
202};
203
204MODULE_DEVICE_TABLE (pci, i810_ids);
205
206static int __devinit i810_probe(struct pci_dev *dev, const struct pci_device_id *id)
207{
208 int retval;
209
210 retval = config_i810(dev);
211 if (retval)
212 return retval;
213 dev_info(&dev->dev, "i810/i815 i2c device found.\n");
214
215 /* set up the sysfs linkage to our parent device */
216 i810_i2c_adapter.dev.parent = &dev->dev;
217 i810_ddc_adapter.dev.parent = &dev->dev;
218
219 retval = i2c_bit_add_bus(&i810_i2c_adapter);
220 if (retval)
221 return retval;
222 retval = i2c_bit_add_bus(&i810_ddc_adapter);
223 if (retval)
224 i2c_del_adapter(&i810_i2c_adapter);
225 return retval;
226}
227
228static void __devexit i810_remove(struct pci_dev *dev)
229{
230 i2c_del_adapter(&i810_ddc_adapter);
231 i2c_del_adapter(&i810_i2c_adapter);
232 iounmap(ioaddr);
233}
234
235static struct pci_driver i810_driver = {
236 .name = "i810_smbus",
237 .id_table = i810_ids,
238 .probe = i810_probe,
239 .remove = __devexit_p(i810_remove),
240};
241
242static int __init i2c_i810_init(void)
243{
244 return pci_register_driver(&i810_driver);
245}
246
247static void __exit i2c_i810_exit(void)
248{
249 pci_unregister_driver(&i810_driver);
250}
251
252MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, "
253 "Philip Edelbrock <phil@netroedge.com>, "
254 "Ralph Metzler <rjkm@thp.uni-koeln.de>, "
255 "and Mark D. Studebaker <mdsxyz123@yahoo.com>");
256MODULE_DESCRIPTION("I810/I815 I2C/DDC driver");
257MODULE_LICENSE("GPL");
258
259module_init(i2c_i810_init);
260module_exit(i2c_i810_exit);
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index 85dbf34382e1..651f2f1ae5b7 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -42,13 +42,8 @@
42#include <asm/io.h> 42#include <asm/io.h>
43#include <linux/i2c.h> 43#include <linux/i2c.h>
44#include <linux/i2c-id.h> 44#include <linux/i2c-id.h>
45
46#ifdef CONFIG_IBM_OCP
47#include <asm/ocp.h>
48#include <asm/ibm4xx.h>
49#else
50#include <linux/of_platform.h> 45#include <linux/of_platform.h>
51#endif 46#include <linux/of_i2c.h>
52 47
53#include "i2c-ibm_iic.h" 48#include "i2c-ibm_iic.h"
54 49
@@ -665,180 +660,6 @@ static inline u8 iic_clckdiv(unsigned int opb)
665 return (u8)((opb + 9) / 10 - 1); 660 return (u8)((opb + 9) / 10 - 1);
666} 661}
667 662
668#ifdef CONFIG_IBM_OCP
669/*
670 * Register single IIC interface
671 */
672static int __devinit iic_probe(struct ocp_device *ocp){
673
674 struct ibm_iic_private* dev;
675 struct i2c_adapter* adap;
676 struct ocp_func_iic_data* iic_data = ocp->def->additions;
677 int ret;
678
679 if (!iic_data)
680 printk(KERN_WARNING"ibm-iic%d: missing additional data!\n",
681 ocp->def->index);
682
683 if (!(dev = kzalloc(sizeof(*dev), GFP_KERNEL))) {
684 printk(KERN_ERR "ibm-iic%d: failed to allocate device data\n",
685 ocp->def->index);
686 return -ENOMEM;
687 }
688
689 dev->idx = ocp->def->index;
690 ocp_set_drvdata(ocp, dev);
691
692 if (!request_mem_region(ocp->def->paddr, sizeof(struct iic_regs),
693 "ibm_iic")) {
694 ret = -EBUSY;
695 goto fail1;
696 }
697
698 if (!(dev->vaddr = ioremap(ocp->def->paddr, sizeof(struct iic_regs)))){
699 printk(KERN_ERR "ibm-iic%d: failed to ioremap device registers\n",
700 dev->idx);
701 ret = -ENXIO;
702 goto fail2;
703 }
704
705 init_waitqueue_head(&dev->wq);
706
707 dev->irq = iic_force_poll ? -1 : ocp->def->irq;
708 if (dev->irq >= 0){
709 /* Disable interrupts until we finish initialization,
710 assumes level-sensitive IRQ setup...
711 */
712 iic_interrupt_mode(dev, 0);
713 if (request_irq(dev->irq, iic_handler, 0, "IBM IIC", dev)){
714 printk(KERN_ERR "ibm-iic%d: request_irq %d failed\n",
715 dev->idx, dev->irq);
716 /* Fallback to the polling mode */
717 dev->irq = -1;
718 }
719 }
720
721 if (dev->irq < 0)
722 printk(KERN_WARNING "ibm-iic%d: using polling mode\n",
723 dev->idx);
724
725 /* Board specific settings */
726 dev->fast_mode = iic_force_fast ? 1 : (iic_data ? iic_data->fast_mode : 0);
727
728 /* clckdiv is the same for *all* IIC interfaces,
729 * but I'd rather make a copy than introduce another global. --ebs
730 */
731 dev->clckdiv = iic_clckdiv(ocp_sys_info.opb_bus_freq);
732 DBG("%d: clckdiv = %d\n", dev->idx, dev->clckdiv);
733
734 /* Initialize IIC interface */
735 iic_dev_init(dev);
736
737 /* Register it with i2c layer */
738 adap = &dev->adap;
739 adap->dev.parent = &ocp->dev;
740 strcpy(adap->name, "IBM IIC");
741 i2c_set_adapdata(adap, dev);
742 adap->id = I2C_HW_OCP;
743 adap->class = I2C_CLASS_HWMON;
744 adap->algo = &iic_algo;
745 adap->client_register = NULL;
746 adap->client_unregister = NULL;
747 adap->timeout = 1;
748
749 /*
750 * If "dev->idx" is negative we consider it as zero.
751 * The reason to do so is to avoid sysfs names that only make
752 * sense when there are multiple adapters.
753 */
754 adap->nr = dev->idx >= 0 ? dev->idx : 0;
755
756 if ((ret = i2c_add_numbered_adapter(adap)) < 0) {
757 printk(KERN_ERR "ibm-iic%d: failed to register i2c adapter\n",
758 dev->idx);
759 goto fail;
760 }
761
762 printk(KERN_INFO "ibm-iic%d: using %s mode\n", dev->idx,
763 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)");
764
765 return 0;
766
767fail:
768 if (dev->irq >= 0){
769 iic_interrupt_mode(dev, 0);
770 free_irq(dev->irq, dev);
771 }
772
773 iounmap(dev->vaddr);
774fail2:
775 release_mem_region(ocp->def->paddr, sizeof(struct iic_regs));
776fail1:
777 ocp_set_drvdata(ocp, NULL);
778 kfree(dev);
779 return ret;
780}
781
782/*
783 * Cleanup initialized IIC interface
784 */
785static void __devexit iic_remove(struct ocp_device *ocp)
786{
787 struct ibm_iic_private* dev = (struct ibm_iic_private*)ocp_get_drvdata(ocp);
788 BUG_ON(dev == NULL);
789 if (i2c_del_adapter(&dev->adap)){
790 printk(KERN_ERR "ibm-iic%d: failed to delete i2c adapter :(\n",
791 dev->idx);
792 /* That's *very* bad, just shutdown IRQ ... */
793 if (dev->irq >= 0){
794 iic_interrupt_mode(dev, 0);
795 free_irq(dev->irq, dev);
796 dev->irq = -1;
797 }
798 } else {
799 if (dev->irq >= 0){
800 iic_interrupt_mode(dev, 0);
801 free_irq(dev->irq, dev);
802 }
803 iounmap(dev->vaddr);
804 release_mem_region(ocp->def->paddr, sizeof(struct iic_regs));
805 kfree(dev);
806 }
807}
808
809static struct ocp_device_id ibm_iic_ids[] __devinitdata =
810{
811 { .vendor = OCP_VENDOR_IBM, .function = OCP_FUNC_IIC },
812 { .vendor = OCP_VENDOR_INVALID }
813};
814
815MODULE_DEVICE_TABLE(ocp, ibm_iic_ids);
816
817static struct ocp_driver ibm_iic_driver =
818{
819 .name = "iic",
820 .id_table = ibm_iic_ids,
821 .probe = iic_probe,
822 .remove = __devexit_p(iic_remove),
823#if defined(CONFIG_PM)
824 .suspend = NULL,
825 .resume = NULL,
826#endif
827};
828
829static int __init iic_init(void)
830{
831 printk(KERN_INFO "IBM IIC driver v" DRIVER_VERSION "\n");
832 return ocp_register_driver(&ibm_iic_driver);
833}
834
835static void __exit iic_exit(void)
836{
837 ocp_unregister_driver(&ibm_iic_driver);
838}
839
840#else /* !CONFIG_IBM_OCP */
841
842static int __devinit iic_request_irq(struct of_device *ofdev, 663static int __devinit iic_request_irq(struct of_device *ofdev,
843 struct ibm_iic_private *dev) 664 struct ibm_iic_private *dev)
844{ 665{
@@ -876,7 +697,7 @@ static int __devinit iic_probe(struct of_device *ofdev,
876 struct device_node *np = ofdev->node; 697 struct device_node *np = ofdev->node;
877 struct ibm_iic_private *dev; 698 struct ibm_iic_private *dev;
878 struct i2c_adapter *adap; 699 struct i2c_adapter *adap;
879 const u32 *indexp, *freq; 700 const u32 *freq;
880 int ret; 701 int ret;
881 702
882 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 703 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
@@ -887,14 +708,6 @@ static int __devinit iic_probe(struct of_device *ofdev,
887 708
888 dev_set_drvdata(&ofdev->dev, dev); 709 dev_set_drvdata(&ofdev->dev, dev);
889 710
890 indexp = of_get_property(np, "index", NULL);
891 if (!indexp) {
892 dev_err(&ofdev->dev, "no index specified\n");
893 ret = -EINVAL;
894 goto error_cleanup;
895 }
896 dev->idx = *indexp;
897
898 dev->vaddr = of_iomap(np, 0); 711 dev->vaddr = of_iomap(np, 0);
899 if (dev->vaddr == NULL) { 712 if (dev->vaddr == NULL) {
900 dev_err(&ofdev->dev, "failed to iomap device\n"); 713 dev_err(&ofdev->dev, "failed to iomap device\n");
@@ -934,17 +747,19 @@ static int __devinit iic_probe(struct of_device *ofdev,
934 strlcpy(adap->name, "IBM IIC", sizeof(adap->name)); 747 strlcpy(adap->name, "IBM IIC", sizeof(adap->name));
935 i2c_set_adapdata(adap, dev); 748 i2c_set_adapdata(adap, dev);
936 adap->id = I2C_HW_OCP; 749 adap->id = I2C_HW_OCP;
937 adap->class = I2C_CLASS_HWMON; 750 adap->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
938 adap->algo = &iic_algo; 751 adap->algo = &iic_algo;
939 adap->timeout = 1; 752 adap->timeout = 1;
940 adap->nr = dev->idx;
941 753
942 ret = i2c_add_numbered_adapter(adap); 754 ret = i2c_add_adapter(adap);
943 if (ret < 0) { 755 if (ret < 0) {
944 dev_err(&ofdev->dev, "failed to register i2c adapter\n"); 756 dev_err(&ofdev->dev, "failed to register i2c adapter\n");
945 goto error_cleanup; 757 goto error_cleanup;
946 } 758 }
947 759
760 /* Now register all the child nodes */
761 of_register_i2c_devices(adap, np);
762
948 dev_info(&ofdev->dev, "using %s mode\n", 763 dev_info(&ofdev->dev, "using %s mode\n",
949 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)"); 764 dev->fast_mode ? "fast (400 kHz)" : "standard (100 kHz)");
950 765
@@ -987,11 +802,7 @@ static int __devexit iic_remove(struct of_device *ofdev)
987} 802}
988 803
989static const struct of_device_id ibm_iic_match[] = { 804static const struct of_device_id ibm_iic_match[] = {
990 { .compatible = "ibm,iic-405ex", }, 805 { .compatible = "ibm,iic", },
991 { .compatible = "ibm,iic-405gp", },
992 { .compatible = "ibm,iic-440gp", },
993 { .compatible = "ibm,iic-440gpx", },
994 { .compatible = "ibm,iic-440grx", },
995 {} 806 {}
996}; 807};
997 808
@@ -1011,7 +822,6 @@ static void __exit iic_exit(void)
1011{ 822{
1012 of_unregister_platform_driver(&ibm_iic_driver); 823 of_unregister_platform_driver(&ibm_iic_driver);
1013} 824}
1014#endif /* CONFIG_IBM_OCP */
1015 825
1016module_init(iic_init); 826module_init(iic_init);
1017module_exit(iic_exit); 827module_exit(iic_exit);
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index 39884e797594..fc2714ac0c0f 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -482,7 +482,7 @@ iop3xx_i2c_probe(struct platform_device *pdev)
482 memcpy(new_adapter->name, pdev->name, strlen(pdev->name)); 482 memcpy(new_adapter->name, pdev->name, strlen(pdev->name));
483 new_adapter->id = I2C_HW_IOP3XX; 483 new_adapter->id = I2C_HW_IOP3XX;
484 new_adapter->owner = THIS_MODULE; 484 new_adapter->owner = THIS_MODULE;
485 new_adapter->class = I2C_CLASS_HWMON; 485 new_adapter->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
486 new_adapter->dev.parent = &pdev->dev; 486 new_adapter->dev.parent = &pdev->dev;
487 new_adapter->nr = pdev->id; 487 new_adapter->nr = pdev->id;
488 488
diff --git a/drivers/i2c/busses/i2c-isch.c b/drivers/i2c/busses/i2c-isch.c
new file mode 100644
index 000000000000..b9c01aa90036
--- /dev/null
+++ b/drivers/i2c/busses/i2c-isch.c
@@ -0,0 +1,339 @@
1/*
2 i2c-isch.c - Linux kernel driver for Intel SCH chipset SMBus
3 - Based on i2c-piix4.c
4 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl> and
5 Philip Edelbrock <phil@netroedge.com>
6 - Intel SCH support
7 Copyright (c) 2007 - 2008 Jacob Jun Pan <jacob.jun.pan@intel.com>
8
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License version 2 as
11 published by the Free Software Foundation.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/
22
23/*
24 Supports:
25 Intel SCH chipsets (AF82US15W, AF82US15L, AF82UL11L)
26 Note: we assume there can only be one device, with one SMBus interface.
27*/
28
29#include <linux/module.h>
30#include <linux/pci.h>
31#include <linux/kernel.h>
32#include <linux/delay.h>
33#include <linux/stddef.h>
34#include <linux/ioport.h>
35#include <linux/i2c.h>
36#include <linux/init.h>
37#include <linux/io.h>
38#include <linux/acpi.h>
39
40/* SCH SMBus address offsets */
41#define SMBHSTCNT (0 + sch_smba)
42#define SMBHSTSTS (1 + sch_smba)
43#define SMBHSTADD (4 + sch_smba) /* TSA */
44#define SMBHSTCMD (5 + sch_smba)
45#define SMBHSTDAT0 (6 + sch_smba)
46#define SMBHSTDAT1 (7 + sch_smba)
47#define SMBBLKDAT (0x20 + sch_smba)
48
49/* count for request_region */
50#define SMBIOSIZE 64
51
52/* PCI Address Constants */
53#define SMBBA_SCH 0x40
54
55/* Other settings */
56#define MAX_TIMEOUT 500
57
58/* I2C constants */
59#define SCH_QUICK 0x00
60#define SCH_BYTE 0x01
61#define SCH_BYTE_DATA 0x02
62#define SCH_WORD_DATA 0x03
63#define SCH_BLOCK_DATA 0x05
64
65static unsigned short sch_smba;
66static struct pci_driver sch_driver;
67static struct i2c_adapter sch_adapter;
68
69/*
70 * Start the i2c transaction -- the i2c_access will prepare the transaction
71 * and this function will execute it.
72 * return 0 for success and others for failure.
73 */
74static int sch_transaction(void)
75{
76 int temp;
77 int result = 0;
78 int timeout = 0;
79
80 dev_dbg(&sch_adapter.dev, "Transaction (pre): CNT=%02x, CMD=%02x, "
81 "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb(SMBHSTCNT),
82 inb(SMBHSTCMD), inb(SMBHSTADD), inb(SMBHSTDAT0),
83 inb(SMBHSTDAT1));
84
85 /* Make sure the SMBus host is ready to start transmitting */
86 temp = inb(SMBHSTSTS) & 0x0f;
87 if (temp) {
88 /* Can not be busy since we checked it in sch_access */
89 if (temp & 0x01) {
90 dev_dbg(&sch_adapter.dev, "Completion (%02x). "
91 "Clear...\n", temp);
92 }
93 if (temp & 0x06) {
94 dev_dbg(&sch_adapter.dev, "SMBus error (%02x). "
95 "Resetting...\n", temp);
96 }
97 outb(temp, SMBHSTSTS);
98 temp = inb(SMBHSTSTS) & 0x0f;
99 if (temp) {
100 dev_err(&sch_adapter.dev,
101 "SMBus is not ready: (%02x)\n", temp);
102 return -EAGAIN;
103 }
104 }
105
106 /* start the transaction by setting bit 4 */
107 outb(inb(SMBHSTCNT) | 0x10, SMBHSTCNT);
108
109 do {
110 msleep(1);
111 temp = inb(SMBHSTSTS) & 0x0f;
112 } while ((temp & 0x08) && (timeout++ < MAX_TIMEOUT));
113
114 /* If the SMBus is still busy, we give up */
115 if (timeout >= MAX_TIMEOUT) {
116 dev_err(&sch_adapter.dev, "SMBus Timeout!\n");
117 result = -ETIMEDOUT;
118 }
119 if (temp & 0x04) {
120 result = -EIO;
121 dev_dbg(&sch_adapter.dev, "Bus collision! SMBus may be "
122 "locked until next hard reset. (sorry!)\n");
123 /* Clock stops and slave is stuck in mid-transmission */
124 } else if (temp & 0x02) {
125 result = -EIO;
126 dev_err(&sch_adapter.dev, "Error: no response!\n");
127 } else if (temp & 0x01) {
128 dev_dbg(&sch_adapter.dev, "Post complete!\n");
129 outb(temp, SMBHSTSTS);
130 temp = inb(SMBHSTSTS) & 0x07;
131 if (temp & 0x06) {
132 /* Completion clear failed */
133 dev_dbg(&sch_adapter.dev, "Failed reset at end of "
134 "transaction (%02x), Bus error!\n", temp);
135 }
136 } else {
137 result = -ENXIO;
138 dev_dbg(&sch_adapter.dev, "No such address.\n");
139 }
140 dev_dbg(&sch_adapter.dev, "Transaction (post): CNT=%02x, CMD=%02x, "
141 "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb(SMBHSTCNT),
142 inb(SMBHSTCMD), inb(SMBHSTADD), inb(SMBHSTDAT0),
143 inb(SMBHSTDAT1));
144 return result;
145}
146
147/*
148 * This is the main access entry for i2c-sch access
149 * adap is i2c_adapter pointer, addr is the i2c device bus address, read_write
150 * (0 for read and 1 for write), size is i2c transaction type and data is the
151 * union of transaction for data to be transfered or data read from bus.
152 * return 0 for success and others for failure.
153 */
154static s32 sch_access(struct i2c_adapter *adap, u16 addr,
155 unsigned short flags, char read_write,
156 u8 command, int size, union i2c_smbus_data *data)
157{
158 int i, len, temp, rc;
159
160 /* Make sure the SMBus host is not busy */
161 temp = inb(SMBHSTSTS) & 0x0f;
162 if (temp & 0x08) {
163 dev_dbg(&sch_adapter.dev, "SMBus busy (%02x)\n", temp);
164 return -EAGAIN;
165 }
166 dev_dbg(&sch_adapter.dev, "access size: %d %s\n", size,
167 (read_write)?"READ":"WRITE");
168 switch (size) {
169 case I2C_SMBUS_QUICK:
170 outb((addr << 1) | read_write, SMBHSTADD);
171 size = SCH_QUICK;
172 break;
173 case I2C_SMBUS_BYTE:
174 outb((addr << 1) | read_write, SMBHSTADD);
175 if (read_write == I2C_SMBUS_WRITE)
176 outb(command, SMBHSTCMD);
177 size = SCH_BYTE;
178 break;
179 case I2C_SMBUS_BYTE_DATA:
180 outb((addr << 1) | read_write, SMBHSTADD);
181 outb(command, SMBHSTCMD);
182 if (read_write == I2C_SMBUS_WRITE)
183 outb(data->byte, SMBHSTDAT0);
184 size = SCH_BYTE_DATA;
185 break;
186 case I2C_SMBUS_WORD_DATA:
187 outb((addr << 1) | read_write, SMBHSTADD);
188 outb(command, SMBHSTCMD);
189 if (read_write == I2C_SMBUS_WRITE) {
190 outb(data->word & 0xff, SMBHSTDAT0);
191 outb((data->word & 0xff00) >> 8, SMBHSTDAT1);
192 }
193 size = SCH_WORD_DATA;
194 break;
195 case I2C_SMBUS_BLOCK_DATA:
196 outb((addr << 1) | read_write, SMBHSTADD);
197 outb(command, SMBHSTCMD);
198 if (read_write == I2C_SMBUS_WRITE) {
199 len = data->block[0];
200 if (len == 0 || len > I2C_SMBUS_BLOCK_MAX)
201 return -EINVAL;
202 outb(len, SMBHSTDAT0);
203 for (i = 1; i <= len; i++)
204 outb(data->block[i], SMBBLKDAT+i-1);
205 }
206 size = SCH_BLOCK_DATA;
207 break;
208 default:
209 dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
210 return -EOPNOTSUPP;
211 }
212 dev_dbg(&sch_adapter.dev, "write size %d to 0x%04x\n", size, SMBHSTCNT);
213 outb((inb(SMBHSTCNT) & 0xb0) | (size & 0x7), SMBHSTCNT);
214
215 rc = sch_transaction();
216 if (rc) /* Error in transaction */
217 return rc;
218
219 if ((read_write == I2C_SMBUS_WRITE) || (size == SCH_QUICK))
220 return 0;
221
222 switch (size) {
223 case SCH_BYTE:
224 case SCH_BYTE_DATA:
225 data->byte = inb(SMBHSTDAT0);
226 break;
227 case SCH_WORD_DATA:
228 data->word = inb(SMBHSTDAT0) + (inb(SMBHSTDAT1) << 8);
229 break;
230 case SCH_BLOCK_DATA:
231 data->block[0] = inb(SMBHSTDAT0);
232 if (data->block[0] == 0 || data->block[0] > I2C_SMBUS_BLOCK_MAX)
233 return -EPROTO;
234 for (i = 1; i <= data->block[0]; i++)
235 data->block[i] = inb(SMBBLKDAT+i-1);
236 break;
237 }
238 return 0;
239}
240
241static u32 sch_func(struct i2c_adapter *adapter)
242{
243 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
244 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
245 I2C_FUNC_SMBUS_BLOCK_DATA;
246}
247
248static const struct i2c_algorithm smbus_algorithm = {
249 .smbus_xfer = sch_access,
250 .functionality = sch_func,
251};
252
253static struct i2c_adapter sch_adapter = {
254 .owner = THIS_MODULE,
255 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
256 .algo = &smbus_algorithm,
257};
258
259static struct pci_device_id sch_ids[] = {
260 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_SCH_LPC) },
261 { 0, }
262};
263
264MODULE_DEVICE_TABLE(pci, sch_ids);
265
266static int __devinit sch_probe(struct pci_dev *dev,
267 const struct pci_device_id *id)
268{
269 int retval;
270 unsigned int smba;
271
272 pci_read_config_dword(dev, SMBBA_SCH, &smba);
273 if (!(smba & (1 << 31))) {
274 dev_err(&dev->dev, "SMBus I/O space disabled!\n");
275 return -ENODEV;
276 }
277
278 sch_smba = (unsigned short)smba;
279 if (sch_smba == 0) {
280 dev_err(&dev->dev, "SMBus base address uninitialized!\n");
281 return -ENODEV;
282 }
283 if (acpi_check_region(sch_smba, SMBIOSIZE, sch_driver.name))
284 return -EBUSY;
285 if (!request_region(sch_smba, SMBIOSIZE, sch_driver.name)) {
286 dev_err(&dev->dev, "SMBus region 0x%x already in use!\n",
287 sch_smba);
288 return -EBUSY;
289 }
290 dev_dbg(&dev->dev, "SMBA = 0x%X\n", sch_smba);
291
292 /* set up the sysfs linkage to our parent device */
293 sch_adapter.dev.parent = &dev->dev;
294
295 snprintf(sch_adapter.name, sizeof(sch_adapter.name),
296 "SMBus SCH adapter at %04x", sch_smba);
297
298 retval = i2c_add_adapter(&sch_adapter);
299 if (retval) {
300 dev_err(&dev->dev, "Couldn't register adapter!\n");
301 release_region(sch_smba, SMBIOSIZE);
302 sch_smba = 0;
303 }
304
305 return retval;
306}
307
308static void __devexit sch_remove(struct pci_dev *dev)
309{
310 if (sch_smba) {
311 i2c_del_adapter(&sch_adapter);
312 release_region(sch_smba, SMBIOSIZE);
313 sch_smba = 0;
314 }
315}
316
317static struct pci_driver sch_driver = {
318 .name = "isch_smbus",
319 .id_table = sch_ids,
320 .probe = sch_probe,
321 .remove = __devexit_p(sch_remove),
322};
323
324static int __init i2c_sch_init(void)
325{
326 return pci_register_driver(&sch_driver);
327}
328
329static void __exit i2c_sch_exit(void)
330{
331 pci_unregister_driver(&sch_driver);
332}
333
334MODULE_AUTHOR("Jacob Pan <jacob.jun.pan@intel.com>");
335MODULE_DESCRIPTION("Intel SCH SMBus driver");
336MODULE_LICENSE("GPL");
337
338module_init(i2c_sch_init);
339module_exit(i2c_sch_exit);
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 18beb0ad7bf3..27443f073bc9 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -17,7 +17,8 @@
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/sched.h> 18#include <linux/sched.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/platform_device.h> 20#include <linux/of_platform.h>
21#include <linux/of_i2c.h>
21 22
22#include <asm/io.h> 23#include <asm/io.h>
23#include <linux/fsl_devices.h> 24#include <linux/fsl_devices.h>
@@ -25,13 +26,13 @@
25#include <linux/interrupt.h> 26#include <linux/interrupt.h>
26#include <linux/delay.h> 27#include <linux/delay.h>
27 28
28#define MPC_I2C_ADDR 0x00 29#define DRV_NAME "mpc-i2c"
30
29#define MPC_I2C_FDR 0x04 31#define MPC_I2C_FDR 0x04
30#define MPC_I2C_CR 0x08 32#define MPC_I2C_CR 0x08
31#define MPC_I2C_SR 0x0c 33#define MPC_I2C_SR 0x0c
32#define MPC_I2C_DR 0x10 34#define MPC_I2C_DR 0x10
33#define MPC_I2C_DFSRR 0x14 35#define MPC_I2C_DFSRR 0x14
34#define MPC_I2C_REGION 0x20
35 36
36#define CCR_MEN 0x80 37#define CCR_MEN 0x80
37#define CCR_MIEN 0x40 38#define CCR_MIEN 0x40
@@ -99,7 +100,7 @@ static int i2c_wait(struct mpc_i2c *i2c, unsigned timeout, int writing)
99 u32 x; 100 u32 x;
100 int result = 0; 101 int result = 0;
101 102
102 if (i2c->irq == 0) 103 if (i2c->irq == NO_IRQ)
103 { 104 {
104 while (!(readb(i2c->base + MPC_I2C_SR) & CSR_MIF)) { 105 while (!(readb(i2c->base + MPC_I2C_SR) & CSR_MIF)) {
105 schedule(); 106 schedule();
@@ -311,108 +312,121 @@ static struct i2c_adapter mpc_ops = {
311 .name = "MPC adapter", 312 .name = "MPC adapter",
312 .id = I2C_HW_MPC107, 313 .id = I2C_HW_MPC107,
313 .algo = &mpc_algo, 314 .algo = &mpc_algo,
314 .class = I2C_CLASS_HWMON, 315 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
315 .timeout = 1, 316 .timeout = 1,
316}; 317};
317 318
318static int fsl_i2c_probe(struct platform_device *pdev) 319static int __devinit fsl_i2c_probe(struct of_device *op, const struct of_device_id *match)
319{ 320{
320 int result = 0; 321 int result = 0;
321 struct mpc_i2c *i2c; 322 struct mpc_i2c *i2c;
322 struct fsl_i2c_platform_data *pdata;
323 struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
324
325 pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data;
326 323
327 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL); 324 i2c = kzalloc(sizeof(*i2c), GFP_KERNEL);
328 if (!i2c) 325 if (!i2c)
329 return -ENOMEM; 326 return -ENOMEM;
330 327
331 i2c->irq = platform_get_irq(pdev, 0); 328 if (of_get_property(op->node, "dfsrr", NULL))
332 if (i2c->irq < 0) { 329 i2c->flags |= FSL_I2C_DEV_SEPARATE_DFSRR;
333 result = -ENXIO;
334 goto fail_get_irq;
335 }
336 i2c->flags = pdata->device_flags;
337 init_waitqueue_head(&i2c->queue);
338 330
339 i2c->base = ioremap((phys_addr_t)r->start, MPC_I2C_REGION); 331 if (of_device_is_compatible(op->node, "fsl,mpc5200-i2c") ||
332 of_device_is_compatible(op->node, "mpc5200-i2c"))
333 i2c->flags |= FSL_I2C_DEV_CLOCK_5200;
340 334
335 init_waitqueue_head(&i2c->queue);
336
337 i2c->base = of_iomap(op->node, 0);
341 if (!i2c->base) { 338 if (!i2c->base) {
342 printk(KERN_ERR "i2c-mpc - failed to map controller\n"); 339 printk(KERN_ERR "i2c-mpc - failed to map controller\n");
343 result = -ENOMEM; 340 result = -ENOMEM;
344 goto fail_map; 341 goto fail_map;
345 } 342 }
346 343
347 if (i2c->irq != 0) 344 i2c->irq = irq_of_parse_and_map(op->node, 0);
348 if ((result = request_irq(i2c->irq, mpc_i2c_isr, 345 if (i2c->irq != NO_IRQ) { /* i2c->irq = NO_IRQ implies polling */
349 IRQF_SHARED, "i2c-mpc", i2c)) < 0) { 346 result = request_irq(i2c->irq, mpc_i2c_isr,
350 printk(KERN_ERR 347 IRQF_SHARED, "i2c-mpc", i2c);
351 "i2c-mpc - failed to attach interrupt\n"); 348 if (result < 0) {
352 goto fail_irq; 349 printk(KERN_ERR "i2c-mpc - failed to attach interrupt\n");
350 goto fail_request;
353 } 351 }
354 352 }
353
355 mpc_i2c_setclock(i2c); 354 mpc_i2c_setclock(i2c);
356 platform_set_drvdata(pdev, i2c); 355
356 dev_set_drvdata(&op->dev, i2c);
357 357
358 i2c->adap = mpc_ops; 358 i2c->adap = mpc_ops;
359 i2c->adap.nr = pdev->id;
360 i2c_set_adapdata(&i2c->adap, i2c); 359 i2c_set_adapdata(&i2c->adap, i2c);
361 i2c->adap.dev.parent = &pdev->dev; 360 i2c->adap.dev.parent = &op->dev;
362 if ((result = i2c_add_numbered_adapter(&i2c->adap)) < 0) { 361
362 result = i2c_add_adapter(&i2c->adap);
363 if (result < 0) {
363 printk(KERN_ERR "i2c-mpc - failed to add adapter\n"); 364 printk(KERN_ERR "i2c-mpc - failed to add adapter\n");
364 goto fail_add; 365 goto fail_add;
365 } 366 }
367 of_register_i2c_devices(&i2c->adap, op->node);
366 368
367 return result; 369 return result;
368 370
369 fail_add: 371 fail_add:
370 if (i2c->irq != 0) 372 dev_set_drvdata(&op->dev, NULL);
371 free_irq(i2c->irq, i2c); 373 free_irq(i2c->irq, i2c);
372 fail_irq: 374 fail_request:
373 iounmap(i2c->base); 375 irq_dispose_mapping(i2c->irq);
374 fail_map: 376 iounmap(i2c->base);
375 fail_get_irq: 377 fail_map:
376 kfree(i2c); 378 kfree(i2c);
377 return result; 379 return result;
378}; 380};
379 381
380static int fsl_i2c_remove(struct platform_device *pdev) 382static int __devexit fsl_i2c_remove(struct of_device *op)
381{ 383{
382 struct mpc_i2c *i2c = platform_get_drvdata(pdev); 384 struct mpc_i2c *i2c = dev_get_drvdata(&op->dev);
383 385
384 i2c_del_adapter(&i2c->adap); 386 i2c_del_adapter(&i2c->adap);
385 platform_set_drvdata(pdev, NULL); 387 dev_set_drvdata(&op->dev, NULL);
386 388
387 if (i2c->irq != 0) 389 if (i2c->irq != NO_IRQ)
388 free_irq(i2c->irq, i2c); 390 free_irq(i2c->irq, i2c);
389 391
392 irq_dispose_mapping(i2c->irq);
390 iounmap(i2c->base); 393 iounmap(i2c->base);
391 kfree(i2c); 394 kfree(i2c);
392 return 0; 395 return 0;
393}; 396};
394 397
395/* work with hotplug and coldplug */ 398static const struct of_device_id mpc_i2c_of_match[] = {
396MODULE_ALIAS("platform:fsl-i2c"); 399 {.compatible = "fsl-i2c",},
400 {},
401};
402MODULE_DEVICE_TABLE(of, mpc_i2c_of_match);
403
397 404
398/* Structure for a device driver */ 405/* Structure for a device driver */
399static struct platform_driver fsl_i2c_driver = { 406static struct of_platform_driver mpc_i2c_driver = {
400 .probe = fsl_i2c_probe, 407 .match_table = mpc_i2c_of_match,
401 .remove = fsl_i2c_remove, 408 .probe = fsl_i2c_probe,
402 .driver = { 409 .remove = __devexit_p(fsl_i2c_remove),
403 .owner = THIS_MODULE, 410 .driver = {
404 .name = "fsl-i2c", 411 .owner = THIS_MODULE,
412 .name = DRV_NAME,
405 }, 413 },
406}; 414};
407 415
408static int __init fsl_i2c_init(void) 416static int __init fsl_i2c_init(void)
409{ 417{
410 return platform_driver_register(&fsl_i2c_driver); 418 int rv;
419
420 rv = of_register_platform_driver(&mpc_i2c_driver);
421 if (rv)
422 printk(KERN_ERR DRV_NAME
423 " of_register_platform_driver failed (%i)\n", rv);
424 return rv;
411} 425}
412 426
413static void __exit fsl_i2c_exit(void) 427static void __exit fsl_i2c_exit(void)
414{ 428{
415 platform_driver_unregister(&fsl_i2c_driver); 429 of_unregister_platform_driver(&mpc_i2c_driver);
416} 430}
417 431
418module_init(fsl_i2c_init); 432module_init(fsl_i2c_init);
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index 036e6a883e67..9e8118d2fe64 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -530,7 +530,7 @@ mv64xxx_i2c_probe(struct platform_device *pd)
530 drv_data->adapter.id = I2C_HW_MV64XXX; 530 drv_data->adapter.id = I2C_HW_MV64XXX;
531 drv_data->adapter.algo = &mv64xxx_i2c_algo; 531 drv_data->adapter.algo = &mv64xxx_i2c_algo;
532 drv_data->adapter.owner = THIS_MODULE; 532 drv_data->adapter.owner = THIS_MODULE;
533 drv_data->adapter.class = I2C_CLASS_HWMON; 533 drv_data->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
534 drv_data->adapter.timeout = pdata->timeout; 534 drv_data->adapter.timeout = pdata->timeout;
535 drv_data->adapter.nr = pd->id; 535 drv_data->adapter.nr = pd->id;
536 platform_set_drvdata(pd, drv_data); 536 platform_set_drvdata(pd, drv_data);
diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
new file mode 100644
index 000000000000..d1a4cbcf2aa4
--- /dev/null
+++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
@@ -0,0 +1,256 @@
1/*
2 * i2c-nforce2-s4985.c - i2c-nforce2 extras for the Tyan S4985 motherboard
3 *
4 * Copyright (C) 2008 Jean Delvare <khali@linux-fr.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21/*
22 * We select the channels by sending commands to the Philips
23 * PCA9556 chip at I2C address 0x18. The main adapter is used for
24 * the non-multiplexed part of the bus, and 4 virtual adapters
25 * are defined for the multiplexed addresses: 0x50-0x53 (memory
26 * module EEPROM) located on channels 1-4. We define one virtual
27 * adapter per CPU, which corresponds to one multiplexed channel:
28 * CPU0: virtual adapter 1, channel 1
29 * CPU1: virtual adapter 2, channel 2
30 * CPU2: virtual adapter 3, channel 3
31 * CPU3: virtual adapter 4, channel 4
32 */
33
34#include <linux/module.h>
35#include <linux/kernel.h>
36#include <linux/slab.h>
37#include <linux/init.h>
38#include <linux/i2c.h>
39#include <linux/mutex.h>
40
41extern struct i2c_adapter *nforce2_smbus;
42
43static struct i2c_adapter *s4985_adapter;
44static struct i2c_algorithm *s4985_algo;
45
46/* Wrapper access functions for multiplexed SMBus */
47static DEFINE_MUTEX(nforce2_lock);
48
49static s32 nforce2_access_virt0(struct i2c_adapter *adap, u16 addr,
50 unsigned short flags, char read_write,
51 u8 command, int size,
52 union i2c_smbus_data *data)
53{
54 int error;
55
56 /* We exclude the multiplexed addresses */
57 if ((addr & 0xfc) == 0x50 || (addr & 0xfc) == 0x30
58 || addr == 0x18)
59 return -ENXIO;
60
61 mutex_lock(&nforce2_lock);
62 error = nforce2_smbus->algo->smbus_xfer(adap, addr, flags, read_write,
63 command, size, data);
64 mutex_unlock(&nforce2_lock);
65
66 return error;
67}
68
69/* We remember the last used channels combination so as to only switch
70 channels when it is really needed. This greatly reduces the SMBus
71 overhead, but also assumes that nobody will be writing to the PCA9556
72 in our back. */
73static u8 last_channels;
74
75static inline s32 nforce2_access_channel(struct i2c_adapter *adap, u16 addr,
76 unsigned short flags, char read_write,
77 u8 command, int size,
78 union i2c_smbus_data *data,
79 u8 channels)
80{
81 int error;
82
83 /* We exclude the non-multiplexed addresses */
84 if ((addr & 0xfc) != 0x50 && (addr & 0xfc) != 0x30)
85 return -ENXIO;
86
87 mutex_lock(&nforce2_lock);
88 if (last_channels != channels) {
89 union i2c_smbus_data mplxdata;
90 mplxdata.byte = channels;
91
92 error = nforce2_smbus->algo->smbus_xfer(adap, 0x18, 0,
93 I2C_SMBUS_WRITE, 0x01,
94 I2C_SMBUS_BYTE_DATA,
95 &mplxdata);
96 if (error)
97 goto UNLOCK;
98 last_channels = channels;
99 }
100 error = nforce2_smbus->algo->smbus_xfer(adap, addr, flags, read_write,
101 command, size, data);
102
103UNLOCK:
104 mutex_unlock(&nforce2_lock);
105 return error;
106}
107
108static s32 nforce2_access_virt1(struct i2c_adapter *adap, u16 addr,
109 unsigned short flags, char read_write,
110 u8 command, int size,
111 union i2c_smbus_data *data)
112{
113 /* CPU0: channel 1 enabled */
114 return nforce2_access_channel(adap, addr, flags, read_write, command,
115 size, data, 0x02);
116}
117
118static s32 nforce2_access_virt2(struct i2c_adapter *adap, u16 addr,
119 unsigned short flags, char read_write,
120 u8 command, int size,
121 union i2c_smbus_data *data)
122{
123 /* CPU1: channel 2 enabled */
124 return nforce2_access_channel(adap, addr, flags, read_write, command,
125 size, data, 0x04);
126}
127
128static s32 nforce2_access_virt3(struct i2c_adapter *adap, u16 addr,
129 unsigned short flags, char read_write,
130 u8 command, int size,
131 union i2c_smbus_data *data)
132{
133 /* CPU2: channel 3 enabled */
134 return nforce2_access_channel(adap, addr, flags, read_write, command,
135 size, data, 0x08);
136}
137
138static s32 nforce2_access_virt4(struct i2c_adapter *adap, u16 addr,
139 unsigned short flags, char read_write,
140 u8 command, int size,
141 union i2c_smbus_data *data)
142{
143 /* CPU3: channel 4 enabled */
144 return nforce2_access_channel(adap, addr, flags, read_write, command,
145 size, data, 0x10);
146}
147
148static int __init nforce2_s4985_init(void)
149{
150 int i, error;
151 union i2c_smbus_data ioconfig;
152
153 /* Configure the PCA9556 multiplexer */
154 ioconfig.byte = 0x00; /* All I/O to output mode */
155 error = i2c_smbus_xfer(nforce2_smbus, 0x18, 0, I2C_SMBUS_WRITE, 0x03,
156 I2C_SMBUS_BYTE_DATA, &ioconfig);
157 if (error) {
158 dev_err(&nforce2_smbus->dev, "PCA9556 configuration failed\n");
159 error = -EIO;
160 goto ERROR0;
161 }
162
163 /* Unregister physical bus */
164 if (!nforce2_smbus)
165 return -ENODEV;
166 error = i2c_del_adapter(nforce2_smbus);
167 if (error) {
168 dev_err(&nforce2_smbus->dev, "Physical bus removal failed\n");
169 goto ERROR0;
170 }
171
172 printk(KERN_INFO "Enabling SMBus multiplexing for Tyan S4985\n");
173 /* Define the 5 virtual adapters and algorithms structures */
174 s4985_adapter = kzalloc(5 * sizeof(struct i2c_adapter), GFP_KERNEL);
175 if (!s4985_adapter) {
176 error = -ENOMEM;
177 goto ERROR1;
178 }
179 s4985_algo = kzalloc(5 * sizeof(struct i2c_algorithm), GFP_KERNEL);
180 if (!s4985_algo) {
181 error = -ENOMEM;
182 goto ERROR2;
183 }
184
185 /* Fill in the new structures */
186 s4985_algo[0] = *(nforce2_smbus->algo);
187 s4985_algo[0].smbus_xfer = nforce2_access_virt0;
188 s4985_adapter[0] = *nforce2_smbus;
189 s4985_adapter[0].algo = s4985_algo;
190 s4985_adapter[0].dev.parent = nforce2_smbus->dev.parent;
191 for (i = 1; i < 5; i++) {
192 s4985_algo[i] = *(nforce2_smbus->algo);
193 s4985_adapter[i] = *nforce2_smbus;
194 snprintf(s4985_adapter[i].name, sizeof(s4985_adapter[i].name),
195 "SMBus nForce2 adapter (CPU%d)", i - 1);
196 s4985_adapter[i].algo = s4985_algo + i;
197 s4985_adapter[i].dev.parent = nforce2_smbus->dev.parent;
198 }
199 s4985_algo[1].smbus_xfer = nforce2_access_virt1;
200 s4985_algo[2].smbus_xfer = nforce2_access_virt2;
201 s4985_algo[3].smbus_xfer = nforce2_access_virt3;
202 s4985_algo[4].smbus_xfer = nforce2_access_virt4;
203
204 /* Register virtual adapters */
205 for (i = 0; i < 5; i++) {
206 error = i2c_add_adapter(s4985_adapter + i);
207 if (error) {
208 printk(KERN_ERR "i2c-nforce2-s4985: "
209 "Virtual adapter %d registration "
210 "failed, module not inserted\n", i);
211 for (i--; i >= 0; i--)
212 i2c_del_adapter(s4985_adapter + i);
213 goto ERROR3;
214 }
215 }
216
217 return 0;
218
219ERROR3:
220 kfree(s4985_algo);
221 s4985_algo = NULL;
222ERROR2:
223 kfree(s4985_adapter);
224 s4985_adapter = NULL;
225ERROR1:
226 /* Restore physical bus */
227 i2c_add_adapter(nforce2_smbus);
228ERROR0:
229 return error;
230}
231
232static void __exit nforce2_s4985_exit(void)
233{
234 if (s4985_adapter) {
235 int i;
236
237 for (i = 0; i < 5; i++)
238 i2c_del_adapter(s4985_adapter+i);
239 kfree(s4985_adapter);
240 s4985_adapter = NULL;
241 }
242 kfree(s4985_algo);
243 s4985_algo = NULL;
244
245 /* Restore physical bus */
246 if (i2c_add_adapter(nforce2_smbus))
247 printk(KERN_ERR "i2c-nforce2-s4985: "
248 "Physical bus restoration failed\n");
249}
250
251MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
252MODULE_DESCRIPTION("S4985 SMBus multiplexing");
253MODULE_LICENSE("GPL");
254
255module_init(nforce2_s4985_init);
256module_exit(nforce2_s4985_exit);
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index 3dac920e53ea..3b19bc41a60b 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -50,6 +50,8 @@
50#include <linux/init.h> 50#include <linux/init.h>
51#include <linux/i2c.h> 51#include <linux/i2c.h>
52#include <linux/delay.h> 52#include <linux/delay.h>
53#include <linux/dmi.h>
54#include <linux/acpi.h>
53#include <asm/io.h> 55#include <asm/io.h>
54 56
55MODULE_LICENSE("GPL"); 57MODULE_LICENSE("GPL");
@@ -109,8 +111,34 @@ struct nforce2_smbus {
109/* Misc definitions */ 111/* Misc definitions */
110#define MAX_TIMEOUT 100 112#define MAX_TIMEOUT 100
111 113
114/* We disable the second SMBus channel on these boards */
115static struct dmi_system_id __devinitdata nforce2_dmi_blacklist2[] = {
116 {
117 .ident = "DFI Lanparty NF4 Expert",
118 .matches = {
119 DMI_MATCH(DMI_BOARD_VENDOR, "DFI Corp,LTD"),
120 DMI_MATCH(DMI_BOARD_NAME, "LP UT NF4 Expert"),
121 },
122 },
123 { }
124};
125
112static struct pci_driver nforce2_driver; 126static struct pci_driver nforce2_driver;
113 127
128/* For multiplexing support, we need a global reference to the 1st
129 SMBus channel */
130#if defined CONFIG_I2C_NFORCE2_S4985 || defined CONFIG_I2C_NFORCE2_S4985_MODULE
131struct i2c_adapter *nforce2_smbus;
132EXPORT_SYMBOL_GPL(nforce2_smbus);
133
134static void nforce2_set_reference(struct i2c_adapter *adap)
135{
136 nforce2_smbus = adap;
137}
138#else
139static inline void nforce2_set_reference(struct i2c_adapter *adap) { }
140#endif
141
114static void nforce2_abort(struct i2c_adapter *adap) 142static void nforce2_abort(struct i2c_adapter *adap)
115{ 143{
116 struct nforce2_smbus *smbus = adap->algo_data; 144 struct nforce2_smbus *smbus = adap->algo_data;
@@ -145,16 +173,16 @@ static int nforce2_check_status(struct i2c_adapter *adap)
145 dev_dbg(&adap->dev, "SMBus Timeout!\n"); 173 dev_dbg(&adap->dev, "SMBus Timeout!\n");
146 if (smbus->can_abort) 174 if (smbus->can_abort)
147 nforce2_abort(adap); 175 nforce2_abort(adap);
148 return -1; 176 return -ETIMEDOUT;
149 } 177 }
150 if (!(temp & NVIDIA_SMB_STS_DONE) || (temp & NVIDIA_SMB_STS_STATUS)) { 178 if (!(temp & NVIDIA_SMB_STS_DONE) || (temp & NVIDIA_SMB_STS_STATUS)) {
151 dev_dbg(&adap->dev, "Transaction failed (0x%02x)!\n", temp); 179 dev_dbg(&adap->dev, "Transaction failed (0x%02x)!\n", temp);
152 return -1; 180 return -EIO;
153 } 181 }
154 return 0; 182 return 0;
155} 183}
156 184
157/* Return -1 on error */ 185/* Return negative errno on error */
158static s32 nforce2_access(struct i2c_adapter * adap, u16 addr, 186static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
159 unsigned short flags, char read_write, 187 unsigned short flags, char read_write,
160 u8 command, int size, union i2c_smbus_data * data) 188 u8 command, int size, union i2c_smbus_data * data)
@@ -162,7 +190,7 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
162 struct nforce2_smbus *smbus = adap->algo_data; 190 struct nforce2_smbus *smbus = adap->algo_data;
163 unsigned char protocol, pec; 191 unsigned char protocol, pec;
164 u8 len; 192 u8 len;
165 int i; 193 int i, status;
166 194
167 protocol = (read_write == I2C_SMBUS_READ) ? NVIDIA_SMB_PRTCL_READ : 195 protocol = (read_write == I2C_SMBUS_READ) ? NVIDIA_SMB_PRTCL_READ :
168 NVIDIA_SMB_PRTCL_WRITE; 196 NVIDIA_SMB_PRTCL_WRITE;
@@ -206,7 +234,7 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
206 "Transaction failed " 234 "Transaction failed "
207 "(requested block size: %d)\n", 235 "(requested block size: %d)\n",
208 len); 236 len);
209 return -1; 237 return -EINVAL;
210 } 238 }
211 outb_p(len, NVIDIA_SMB_BCNT); 239 outb_p(len, NVIDIA_SMB_BCNT);
212 for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++) 240 for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++)
@@ -218,14 +246,15 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
218 246
219 default: 247 default:
220 dev_err(&adap->dev, "Unsupported transaction %d\n", size); 248 dev_err(&adap->dev, "Unsupported transaction %d\n", size);
221 return -1; 249 return -EOPNOTSUPP;
222 } 250 }
223 251
224 outb_p((addr & 0x7f) << 1, NVIDIA_SMB_ADDR); 252 outb_p((addr & 0x7f) << 1, NVIDIA_SMB_ADDR);
225 outb_p(protocol, NVIDIA_SMB_PRTCL); 253 outb_p(protocol, NVIDIA_SMB_PRTCL);
226 254
227 if (nforce2_check_status(adap)) 255 status = nforce2_check_status(adap);
228 return -1; 256 if (status)
257 return status;
229 258
230 if (read_write == I2C_SMBUS_WRITE) 259 if (read_write == I2C_SMBUS_WRITE)
231 return 0; 260 return 0;
@@ -247,7 +276,7 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
247 dev_err(&adap->dev, "Transaction failed " 276 dev_err(&adap->dev, "Transaction failed "
248 "(received block size: 0x%02x)\n", 277 "(received block size: 0x%02x)\n",
249 len); 278 len);
250 return -1; 279 return -EPROTO;
251 } 280 }
252 for (i = 0; i < len; i++) 281 for (i = 0; i < len; i++)
253 data->block[i+1] = inb_p(NVIDIA_SMB_DATA + i); 282 data->block[i+1] = inb_p(NVIDIA_SMB_DATA + i);
@@ -308,21 +337,26 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar,
308 != PCIBIOS_SUCCESSFUL) { 337 != PCIBIOS_SUCCESSFUL) {
309 dev_err(&dev->dev, "Error reading PCI config for %s\n", 338 dev_err(&dev->dev, "Error reading PCI config for %s\n",
310 name); 339 name);
311 return -1; 340 return -EIO;
312 } 341 }
313 342
314 smbus->base = iobase & PCI_BASE_ADDRESS_IO_MASK; 343 smbus->base = iobase & PCI_BASE_ADDRESS_IO_MASK;
315 smbus->size = 64; 344 smbus->size = 64;
316 } 345 }
317 346
347 error = acpi_check_region(smbus->base, smbus->size,
348 nforce2_driver.name);
349 if (error)
350 return -1;
351
318 if (!request_region(smbus->base, smbus->size, nforce2_driver.name)) { 352 if (!request_region(smbus->base, smbus->size, nforce2_driver.name)) {
319 dev_err(&smbus->adapter.dev, "Error requesting region %02x .. %02X for %s\n", 353 dev_err(&smbus->adapter.dev, "Error requesting region %02x .. %02X for %s\n",
320 smbus->base, smbus->base+smbus->size-1, name); 354 smbus->base, smbus->base+smbus->size-1, name);
321 return -1; 355 return -EBUSY;
322 } 356 }
323 smbus->adapter.owner = THIS_MODULE; 357 smbus->adapter.owner = THIS_MODULE;
324 smbus->adapter.id = I2C_HW_SMBUS_NFORCE2; 358 smbus->adapter.id = I2C_HW_SMBUS_NFORCE2;
325 smbus->adapter.class = I2C_CLASS_HWMON; 359 smbus->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
326 smbus->adapter.algo = &smbus_algorithm; 360 smbus->adapter.algo = &smbus_algorithm;
327 smbus->adapter.algo_data = smbus; 361 smbus->adapter.algo_data = smbus;
328 smbus->adapter.dev.parent = &dev->dev; 362 smbus->adapter.dev.parent = &dev->dev;
@@ -333,7 +367,7 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar,
333 if (error) { 367 if (error) {
334 dev_err(&smbus->adapter.dev, "Failed to register adapter.\n"); 368 dev_err(&smbus->adapter.dev, "Failed to register adapter.\n");
335 release_region(smbus->base, smbus->size); 369 release_region(smbus->base, smbus->size);
336 return -1; 370 return error;
337 } 371 }
338 dev_info(&smbus->adapter.dev, "nForce2 SMBus adapter at %#x\n", smbus->base); 372 dev_info(&smbus->adapter.dev, "nForce2 SMBus adapter at %#x\n", smbus->base);
339 return 0; 373 return 0;
@@ -367,10 +401,17 @@ static int __devinit nforce2_probe(struct pci_dev *dev, const struct pci_device_
367 smbuses[0].base = 0; /* to have a check value */ 401 smbuses[0].base = 0; /* to have a check value */
368 } 402 }
369 /* SMBus adapter 2 */ 403 /* SMBus adapter 2 */
370 res2 = nforce2_probe_smb(dev, 5, NFORCE_PCI_SMB2, &smbuses[1], "SMB2"); 404 if (dmi_check_system(nforce2_dmi_blacklist2)) {
371 if (res2 < 0) { 405 dev_err(&dev->dev, "Disabling SMB2 for safety reasons.\n");
372 dev_err(&dev->dev, "Error probing SMB2.\n"); 406 res2 = -EPERM;
373 smbuses[1].base = 0; /* to have a check value */ 407 smbuses[1].base = 0;
408 } else {
409 res2 = nforce2_probe_smb(dev, 5, NFORCE_PCI_SMB2, &smbuses[1],
410 "SMB2");
411 if (res2 < 0) {
412 dev_err(&dev->dev, "Error probing SMB2.\n");
413 smbuses[1].base = 0; /* to have a check value */
414 }
374 } 415 }
375 if ((res1 < 0) && (res2 < 0)) { 416 if ((res1 < 0) && (res2 < 0)) {
376 /* we did not find even one of the SMBuses, so we give up */ 417 /* we did not find even one of the SMBuses, so we give up */
@@ -378,6 +419,7 @@ static int __devinit nforce2_probe(struct pci_dev *dev, const struct pci_device_
378 return -ENODEV; 419 return -ENODEV;
379 } 420 }
380 421
422 nforce2_set_reference(&smbuses[0].adapter);
381 return 0; 423 return 0;
382} 424}
383 425
@@ -386,6 +428,7 @@ static void __devexit nforce2_remove(struct pci_dev *dev)
386{ 428{
387 struct nforce2_smbus *smbuses = (void*) pci_get_drvdata(dev); 429 struct nforce2_smbus *smbuses = (void*) pci_get_drvdata(dev);
388 430
431 nforce2_set_reference(NULL);
389 if (smbuses[0].base) { 432 if (smbuses[0].base) {
390 i2c_del_adapter(&smbuses[0].adapter); 433 i2c_del_adapter(&smbuses[0].adapter);
391 release_region(smbuses[0].base, smbuses[0].size); 434 release_region(smbuses[0].base, smbuses[0].size);
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index f145692cbb76..e5193bf75483 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -29,6 +29,7 @@ struct ocores_i2c {
29 int pos; 29 int pos;
30 int nmsgs; 30 int nmsgs;
31 int state; /* see STATE_ */ 31 int state; /* see STATE_ */
32 int clock_khz;
32}; 33};
33 34
34/* registers */ 35/* registers */
@@ -173,8 +174,7 @@ static int ocores_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num)
173 return -ETIMEDOUT; 174 return -ETIMEDOUT;
174} 175}
175 176
176static void ocores_init(struct ocores_i2c *i2c, 177static void ocores_init(struct ocores_i2c *i2c)
177 struct ocores_i2c_platform_data *pdata)
178{ 178{
179 int prescale; 179 int prescale;
180 u8 ctrl = oc_getreg(i2c, OCI2C_CONTROL); 180 u8 ctrl = oc_getreg(i2c, OCI2C_CONTROL);
@@ -182,7 +182,7 @@ static void ocores_init(struct ocores_i2c *i2c,
182 /* make sure the device is disabled */ 182 /* make sure the device is disabled */
183 oc_setreg(i2c, OCI2C_CONTROL, ctrl & ~(OCI2C_CTRL_EN|OCI2C_CTRL_IEN)); 183 oc_setreg(i2c, OCI2C_CONTROL, ctrl & ~(OCI2C_CTRL_EN|OCI2C_CTRL_IEN));
184 184
185 prescale = (pdata->clock_khz / (5*100)) - 1; 185 prescale = (i2c->clock_khz / (5*100)) - 1;
186 oc_setreg(i2c, OCI2C_PRELOW, prescale & 0xff); 186 oc_setreg(i2c, OCI2C_PRELOW, prescale & 0xff);
187 oc_setreg(i2c, OCI2C_PREHIGH, prescale >> 8); 187 oc_setreg(i2c, OCI2C_PREHIGH, prescale >> 8);
188 188
@@ -205,7 +205,7 @@ static const struct i2c_algorithm ocores_algorithm = {
205static struct i2c_adapter ocores_adapter = { 205static struct i2c_adapter ocores_adapter = {
206 .owner = THIS_MODULE, 206 .owner = THIS_MODULE,
207 .name = "i2c-ocores", 207 .name = "i2c-ocores",
208 .class = I2C_CLASS_HWMON, 208 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
209 .algo = &ocores_algorithm, 209 .algo = &ocores_algorithm,
210}; 210};
211 211
@@ -248,7 +248,8 @@ static int __devinit ocores_i2c_probe(struct platform_device *pdev)
248 } 248 }
249 249
250 i2c->regstep = pdata->regstep; 250 i2c->regstep = pdata->regstep;
251 ocores_init(i2c, pdata); 251 i2c->clock_khz = pdata->clock_khz;
252 ocores_init(i2c);
252 253
253 init_waitqueue_head(&i2c->wait); 254 init_waitqueue_head(&i2c->wait);
254 ret = request_irq(res2->start, ocores_isr, 0, pdev->name, i2c); 255 ret = request_irq(res2->start, ocores_isr, 0, pdev->name, i2c);
@@ -312,13 +313,40 @@ static int __devexit ocores_i2c_remove(struct platform_device* pdev)
312 return 0; 313 return 0;
313} 314}
314 315
316#ifdef CONFIG_PM
317static int ocores_i2c_suspend(struct platform_device *pdev, pm_message_t state)
318{
319 struct ocores_i2c *i2c = platform_get_drvdata(pdev);
320 u8 ctrl = oc_getreg(i2c, OCI2C_CONTROL);
321
322 /* make sure the device is disabled */
323 oc_setreg(i2c, OCI2C_CONTROL, ctrl & ~(OCI2C_CTRL_EN|OCI2C_CTRL_IEN));
324
325 return 0;
326}
327
328static int ocores_i2c_resume(struct platform_device *pdev)
329{
330 struct ocores_i2c *i2c = platform_get_drvdata(pdev);
331
332 ocores_init(i2c);
333
334 return 0;
335}
336#else
337#define ocores_i2c_suspend NULL
338#define ocores_i2c_resume NULL
339#endif
340
315/* work with hotplug and coldplug */ 341/* work with hotplug and coldplug */
316MODULE_ALIAS("platform:ocores-i2c"); 342MODULE_ALIAS("platform:ocores-i2c");
317 343
318static struct platform_driver ocores_i2c_driver = { 344static struct platform_driver ocores_i2c_driver = {
319 .probe = ocores_i2c_probe, 345 .probe = ocores_i2c_probe,
320 .remove = __devexit_p(ocores_i2c_remove), 346 .remove = __devexit_p(ocores_i2c_remove),
321 .driver = { 347 .suspend = ocores_i2c_suspend,
348 .resume = ocores_i2c_resume,
349 .driver = {
322 .owner = THIS_MODULE, 350 .owner = THIS_MODULE,
323 .name = "ocores-i2c", 351 .name = "ocores-i2c",
324 }, 352 },
diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c
index 1603c81e39d4..adf0fbb902f0 100644
--- a/drivers/i2c/busses/i2c-pasemi.c
+++ b/drivers/i2c/busses/i2c-pasemi.c
@@ -365,7 +365,7 @@ static int __devinit pasemi_smb_probe(struct pci_dev *dev,
365 smbus->adapter.owner = THIS_MODULE; 365 smbus->adapter.owner = THIS_MODULE;
366 snprintf(smbus->adapter.name, sizeof(smbus->adapter.name), 366 snprintf(smbus->adapter.name, sizeof(smbus->adapter.name),
367 "PA Semi SMBus adapter at 0x%lx", smbus->base); 367 "PA Semi SMBus adapter at 0x%lx", smbus->base);
368 smbus->adapter.class = I2C_CLASS_HWMON; 368 smbus->adapter.class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
369 smbus->adapter.algo = &smbus_algorithm; 369 smbus->adapter.algo = &smbus_algorithm;
370 smbus->adapter.algo_data = smbus; 370 smbus->adapter.algo_data = smbus;
371 smbus->adapter.nr = PCI_FUNC(dev->devfn); 371 smbus->adapter.nr = PCI_FUNC(dev->devfn);
diff --git a/drivers/i2c/busses/i2c-pca-platform.c b/drivers/i2c/busses/i2c-pca-platform.c
index 9d75f51e8f0e..6bb15ad0a6b6 100644
--- a/drivers/i2c/busses/i2c-pca-platform.c
+++ b/drivers/i2c/busses/i2c-pca-platform.c
@@ -163,7 +163,7 @@ static int __devinit i2c_pca_pf_probe(struct platform_device *pdev)
163 163
164 i2c->reg_base = ioremap(res->start, res_len(res)); 164 i2c->reg_base = ioremap(res->start, res_len(res));
165 if (!i2c->reg_base) { 165 if (!i2c->reg_base) {
166 ret = -EIO; 166 ret = -ENOMEM;
167 goto e_remap; 167 goto e_remap;
168 } 168 }
169 i2c->io_base = res->start; 169 i2c->io_base = res->start;
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index fdc9ad805e35..eaa9b387543e 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -1,6 +1,4 @@
1/* 1/*
2 piix4.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl> and 2 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl> and
5 Philip Edelbrock <phil@netroedge.com> 3 Philip Edelbrock <phil@netroedge.com>
6 4
@@ -39,16 +37,10 @@
39#include <linux/i2c.h> 37#include <linux/i2c.h>
40#include <linux/init.h> 38#include <linux/init.h>
41#include <linux/dmi.h> 39#include <linux/dmi.h>
40#include <linux/acpi.h>
42#include <asm/io.h> 41#include <asm/io.h>
43 42
44 43
45struct sd {
46 const unsigned short mfr;
47 const unsigned short dev;
48 const unsigned char fn;
49 const char *name;
50};
51
52/* PIIX4 SMBus address offsets */ 44/* PIIX4 SMBus address offsets */
53#define SMBHSTSTS (0 + piix4_smba) 45#define SMBHSTSTS (0 + piix4_smba)
54#define SMBHSLVSTS (1 + piix4_smba) 46#define SMBHSLVSTS (1 + piix4_smba)
@@ -101,13 +93,32 @@ MODULE_PARM_DESC(force_addr,
101 "Forcibly enable the PIIX4 at the given address. " 93 "Forcibly enable the PIIX4 at the given address. "
102 "EXTREMELY DANGEROUS!"); 94 "EXTREMELY DANGEROUS!");
103 95
104static int piix4_transaction(void);
105
106static unsigned short piix4_smba; 96static unsigned short piix4_smba;
97static int srvrworks_csb5_delay;
107static struct pci_driver piix4_driver; 98static struct pci_driver piix4_driver;
108static struct i2c_adapter piix4_adapter; 99static struct i2c_adapter piix4_adapter;
109 100
110static struct dmi_system_id __devinitdata piix4_dmi_table[] = { 101static struct dmi_system_id __devinitdata piix4_dmi_blacklist[] = {
102 {
103 .ident = "Sapphire AM2RD790",
104 .matches = {
105 DMI_MATCH(DMI_BOARD_VENDOR, "SAPPHIRE Inc."),
106 DMI_MATCH(DMI_BOARD_NAME, "PC-AM2RD790"),
107 },
108 },
109 {
110 .ident = "DFI Lanparty UT 790FX",
111 .matches = {
112 DMI_MATCH(DMI_BOARD_VENDOR, "DFI Inc."),
113 DMI_MATCH(DMI_BOARD_NAME, "LP UT 790FX"),
114 },
115 },
116 { }
117};
118
119/* The IBM entry is in a separate table because we only check it
120 on Intel-based systems */
121static struct dmi_system_id __devinitdata piix4_dmi_ibm[] = {
111 { 122 {
112 .ident = "IBM", 123 .ident = "IBM",
113 .matches = { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), }, 124 .matches = { DMI_MATCH(DMI_SYS_VENDOR, "IBM"), },
@@ -120,10 +131,20 @@ static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
120{ 131{
121 unsigned char temp; 132 unsigned char temp;
122 133
123 dev_info(&PIIX4_dev->dev, "Found %s device\n", pci_name(PIIX4_dev)); 134 if ((PIIX4_dev->vendor == PCI_VENDOR_ID_SERVERWORKS) &&
135 (PIIX4_dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5))
136 srvrworks_csb5_delay = 1;
137
138 /* On some motherboards, it was reported that accessing the SMBus
139 caused severe hardware problems */
140 if (dmi_check_system(piix4_dmi_blacklist)) {
141 dev_err(&PIIX4_dev->dev,
142 "Accessing the SMBus on this system is unsafe!\n");
143 return -EPERM;
144 }
124 145
125 /* Don't access SMBus on IBM systems which get corrupted eeproms */ 146 /* Don't access SMBus on IBM systems which get corrupted eeproms */
126 if (dmi_check_system(piix4_dmi_table) && 147 if (dmi_check_system(piix4_dmi_ibm) &&
127 PIIX4_dev->vendor == PCI_VENDOR_ID_INTEL) { 148 PIIX4_dev->vendor == PCI_VENDOR_ID_INTEL) {
128 dev_err(&PIIX4_dev->dev, "IBM system detected; this module " 149 dev_err(&PIIX4_dev->dev, "IBM system detected; this module "
129 "may corrupt your serial eeprom! Refusing to load " 150 "may corrupt your serial eeprom! Refusing to load "
@@ -139,17 +160,20 @@ static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
139 pci_read_config_word(PIIX4_dev, SMBBA, &piix4_smba); 160 pci_read_config_word(PIIX4_dev, SMBBA, &piix4_smba);
140 piix4_smba &= 0xfff0; 161 piix4_smba &= 0xfff0;
141 if(piix4_smba == 0) { 162 if(piix4_smba == 0) {
142 dev_err(&PIIX4_dev->dev, "SMB base address " 163 dev_err(&PIIX4_dev->dev, "SMBus base address "
143 "uninitialized - upgrade BIOS or use " 164 "uninitialized - upgrade BIOS or use "
144 "force_addr=0xaddr\n"); 165 "force_addr=0xaddr\n");
145 return -ENODEV; 166 return -ENODEV;
146 } 167 }
147 } 168 }
148 169
170 if (acpi_check_region(piix4_smba, SMBIOSIZE, piix4_driver.name))
171 return -EBUSY;
172
149 if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) { 173 if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) {
150 dev_err(&PIIX4_dev->dev, "SMB region 0x%x already in use!\n", 174 dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n",
151 piix4_smba); 175 piix4_smba);
152 return -ENODEV; 176 return -EBUSY;
153 } 177 }
154 178
155 pci_read_config_byte(PIIX4_dev, SMBHSTCFG, &temp); 179 pci_read_config_byte(PIIX4_dev, SMBHSTCFG, &temp);
@@ -195,13 +219,13 @@ static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
195 "(or code out of date)!\n"); 219 "(or code out of date)!\n");
196 220
197 pci_read_config_byte(PIIX4_dev, SMBREV, &temp); 221 pci_read_config_byte(PIIX4_dev, SMBREV, &temp);
198 dev_dbg(&PIIX4_dev->dev, "SMBREV = 0x%X\n", temp); 222 dev_info(&PIIX4_dev->dev,
199 dev_dbg(&PIIX4_dev->dev, "SMBA = 0x%X\n", piix4_smba); 223 "SMBus Host Controller at 0x%x, revision %d\n",
224 piix4_smba, temp);
200 225
201 return 0; 226 return 0;
202} 227}
203 228
204/* Another internally used function */
205static int piix4_transaction(void) 229static int piix4_transaction(void)
206{ 230{
207 int temp; 231 int temp;
@@ -220,7 +244,7 @@ static int piix4_transaction(void)
220 outb_p(temp, SMBHSTSTS); 244 outb_p(temp, SMBHSTSTS);
221 if ((temp = inb_p(SMBHSTSTS)) != 0x00) { 245 if ((temp = inb_p(SMBHSTSTS)) != 0x00) {
222 dev_err(&piix4_adapter.dev, "Failed! (%02x)\n", temp); 246 dev_err(&piix4_adapter.dev, "Failed! (%02x)\n", temp);
223 return -1; 247 return -EBUSY;
224 } else { 248 } else {
225 dev_dbg(&piix4_adapter.dev, "Successful!\n"); 249 dev_dbg(&piix4_adapter.dev, "Successful!\n");
226 } 250 }
@@ -230,31 +254,35 @@ static int piix4_transaction(void)
230 outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); 254 outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT);
231 255
232 /* We will always wait for a fraction of a second! (See PIIX4 docs errata) */ 256 /* We will always wait for a fraction of a second! (See PIIX4 docs errata) */
233 do { 257 if (srvrworks_csb5_delay) /* Extra delay for SERVERWORKS_CSB5 */
258 msleep(2);
259 else
260 msleep(1);
261
262 while ((timeout++ < MAX_TIMEOUT) &&
263 ((temp = inb_p(SMBHSTSTS)) & 0x01))
234 msleep(1); 264 msleep(1);
235 temp = inb_p(SMBHSTSTS);
236 } while ((temp & 0x01) && (timeout++ < MAX_TIMEOUT));
237 265
238 /* If the SMBus is still busy, we give up */ 266 /* If the SMBus is still busy, we give up */
239 if (timeout >= MAX_TIMEOUT) { 267 if (timeout >= MAX_TIMEOUT) {
240 dev_err(&piix4_adapter.dev, "SMBus Timeout!\n"); 268 dev_err(&piix4_adapter.dev, "SMBus Timeout!\n");
241 result = -1; 269 result = -ETIMEDOUT;
242 } 270 }
243 271
244 if (temp & 0x10) { 272 if (temp & 0x10) {
245 result = -1; 273 result = -EIO;
246 dev_err(&piix4_adapter.dev, "Error: Failed bus transaction\n"); 274 dev_err(&piix4_adapter.dev, "Error: Failed bus transaction\n");
247 } 275 }
248 276
249 if (temp & 0x08) { 277 if (temp & 0x08) {
250 result = -1; 278 result = -EIO;
251 dev_dbg(&piix4_adapter.dev, "Bus collision! SMBus may be " 279 dev_dbg(&piix4_adapter.dev, "Bus collision! SMBus may be "
252 "locked until next hard reset. (sorry!)\n"); 280 "locked until next hard reset. (sorry!)\n");
253 /* Clock stops and slave is stuck in mid-transmission */ 281 /* Clock stops and slave is stuck in mid-transmission */
254 } 282 }
255 283
256 if (temp & 0x04) { 284 if (temp & 0x04) {
257 result = -1; 285 result = -ENXIO;
258 dev_dbg(&piix4_adapter.dev, "Error: no response!\n"); 286 dev_dbg(&piix4_adapter.dev, "Error: no response!\n");
259 } 287 }
260 288
@@ -272,31 +300,29 @@ static int piix4_transaction(void)
272 return result; 300 return result;
273} 301}
274 302
275/* Return -1 on error. */ 303/* Return negative errno on error. */
276static s32 piix4_access(struct i2c_adapter * adap, u16 addr, 304static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
277 unsigned short flags, char read_write, 305 unsigned short flags, char read_write,
278 u8 command, int size, union i2c_smbus_data * data) 306 u8 command, int size, union i2c_smbus_data * data)
279{ 307{
280 int i, len; 308 int i, len;
309 int status;
281 310
282 switch (size) { 311 switch (size) {
283 case I2C_SMBUS_PROC_CALL:
284 dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n");
285 return -1;
286 case I2C_SMBUS_QUICK: 312 case I2C_SMBUS_QUICK:
287 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 313 outb_p((addr << 1) | read_write,
288 SMBHSTADD); 314 SMBHSTADD);
289 size = PIIX4_QUICK; 315 size = PIIX4_QUICK;
290 break; 316 break;
291 case I2C_SMBUS_BYTE: 317 case I2C_SMBUS_BYTE:
292 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 318 outb_p((addr << 1) | read_write,
293 SMBHSTADD); 319 SMBHSTADD);
294 if (read_write == I2C_SMBUS_WRITE) 320 if (read_write == I2C_SMBUS_WRITE)
295 outb_p(command, SMBHSTCMD); 321 outb_p(command, SMBHSTCMD);
296 size = PIIX4_BYTE; 322 size = PIIX4_BYTE;
297 break; 323 break;
298 case I2C_SMBUS_BYTE_DATA: 324 case I2C_SMBUS_BYTE_DATA:
299 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 325 outb_p((addr << 1) | read_write,
300 SMBHSTADD); 326 SMBHSTADD);
301 outb_p(command, SMBHSTCMD); 327 outb_p(command, SMBHSTCMD);
302 if (read_write == I2C_SMBUS_WRITE) 328 if (read_write == I2C_SMBUS_WRITE)
@@ -304,7 +330,7 @@ static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
304 size = PIIX4_BYTE_DATA; 330 size = PIIX4_BYTE_DATA;
305 break; 331 break;
306 case I2C_SMBUS_WORD_DATA: 332 case I2C_SMBUS_WORD_DATA:
307 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 333 outb_p((addr << 1) | read_write,
308 SMBHSTADD); 334 SMBHSTADD);
309 outb_p(command, SMBHSTCMD); 335 outb_p(command, SMBHSTCMD);
310 if (read_write == I2C_SMBUS_WRITE) { 336 if (read_write == I2C_SMBUS_WRITE) {
@@ -314,15 +340,13 @@ static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
314 size = PIIX4_WORD_DATA; 340 size = PIIX4_WORD_DATA;
315 break; 341 break;
316 case I2C_SMBUS_BLOCK_DATA: 342 case I2C_SMBUS_BLOCK_DATA:
317 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 343 outb_p((addr << 1) | read_write,
318 SMBHSTADD); 344 SMBHSTADD);
319 outb_p(command, SMBHSTCMD); 345 outb_p(command, SMBHSTCMD);
320 if (read_write == I2C_SMBUS_WRITE) { 346 if (read_write == I2C_SMBUS_WRITE) {
321 len = data->block[0]; 347 len = data->block[0];
322 if (len < 0) 348 if (len == 0 || len > I2C_SMBUS_BLOCK_MAX)
323 len = 0; 349 return -EINVAL;
324 if (len > 32)
325 len = 32;
326 outb_p(len, SMBHSTDAT0); 350 outb_p(len, SMBHSTDAT0);
327 i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ 351 i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
328 for (i = 1; i <= len; i++) 352 for (i = 1; i <= len; i++)
@@ -330,12 +354,16 @@ static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
330 } 354 }
331 size = PIIX4_BLOCK_DATA; 355 size = PIIX4_BLOCK_DATA;
332 break; 356 break;
357 default:
358 dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
359 return -EOPNOTSUPP;
333 } 360 }
334 361
335 outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); 362 outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT);
336 363
337 if (piix4_transaction()) /* Error in transaction */ 364 status = piix4_transaction();
338 return -1; 365 if (status)
366 return status;
339 367
340 if ((read_write == I2C_SMBUS_WRITE) || (size == PIIX4_QUICK)) 368 if ((read_write == I2C_SMBUS_WRITE) || (size == PIIX4_QUICK))
341 return 0; 369 return 0;
@@ -351,6 +379,8 @@ static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
351 break; 379 break;
352 case PIIX4_BLOCK_DATA: 380 case PIIX4_BLOCK_DATA:
353 data->block[0] = inb_p(SMBHSTDAT0); 381 data->block[0] = inb_p(SMBHSTDAT0);
382 if (data->block[0] == 0 || data->block[0] > I2C_SMBUS_BLOCK_MAX)
383 return -EPROTO;
354 i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ 384 i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
355 for (i = 1; i <= data->block[0]; i++) 385 for (i = 1; i <= data->block[0]; i++)
356 data->block[i] = inb_p(SMBBLKDAT); 386 data->block[i] = inb_p(SMBBLKDAT);
@@ -374,7 +404,7 @@ static const struct i2c_algorithm smbus_algorithm = {
374static struct i2c_adapter piix4_adapter = { 404static struct i2c_adapter piix4_adapter = {
375 .owner = THIS_MODULE, 405 .owner = THIS_MODULE,
376 .id = I2C_HW_SMBUS_PIIX4, 406 .id = I2C_HW_SMBUS_PIIX4,
377 .class = I2C_CLASS_HWMON, 407 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
378 .algo = &smbus_algorithm, 408 .algo = &smbus_algorithm,
379}; 409};
380 410
diff --git a/drivers/i2c/busses/i2c-pmcmsp.c b/drivers/i2c/busses/i2c-pmcmsp.c
index 63b3e2c11cff..dcf2045b5222 100644
--- a/drivers/i2c/busses/i2c-pmcmsp.c
+++ b/drivers/i2c/busses/i2c-pmcmsp.c
@@ -622,7 +622,7 @@ static struct i2c_algorithm pmcmsptwi_algo = {
622 622
623static struct i2c_adapter pmcmsptwi_adapter = { 623static struct i2c_adapter pmcmsptwi_adapter = {
624 .owner = THIS_MODULE, 624 .owner = THIS_MODULE,
625 .class = I2C_CLASS_HWMON, 625 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
626 .algo = &pmcmsptwi_algo, 626 .algo = &pmcmsptwi_algo,
627 .name = DRV_NAME, 627 .name = DRV_NAME,
628}; 628};
diff --git a/drivers/i2c/busses/i2c-prosavage.c b/drivers/i2c/busses/i2c-prosavage.c
deleted file mode 100644
index 07c1f1e27df1..000000000000
--- a/drivers/i2c/busses/i2c-prosavage.c
+++ /dev/null
@@ -1,325 +0,0 @@
1/*
2 * kernel/busses/i2c-prosavage.c
3 *
4 * i2c bus driver for S3/VIA 8365/8375 graphics processor.
5 * Copyright (c) 2003 Henk Vergonet <henk@god.dyndns.org>
6 * Based on code written by:
7 * Frodo Looijaard <frodol@dds.nl>,
8 * Philip Edelbrock <phil@netroedge.com>,
9 * Ralph Metzler <rjkm@thp.uni-koeln.de>, and
10 * Mark D. Studebaker <mdsxyz123@yahoo.com>
11 * Simon Vogl
12 * and others
13 *
14 * Please read the lm_sensors documentation for details on use.
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 *
30 */
31/* 18-05-2003 HVE - created
32 * 14-06-2003 HVE - adapted for lm_sensors2
33 * 17-06-2003 HVE - linux 2.5.xx compatible
34 * 18-06-2003 HVE - codingstyle
35 * 21-06-2003 HVE - compatibility lm_sensors2 and linux 2.5.xx
36 * codingstyle, mmio enabled
37 *
38 * This driver interfaces to the I2C bus of the VIA north bridge embedded
39 * ProSavage4/8 devices. Usefull for gaining access to the TV Encoder chips.
40 *
41 * Graphics cores:
42 * S3/VIA KM266/VT8375 aka ProSavage8
43 * S3/VIA KM133/VT8365 aka Savage4
44 *
45 * Two serial busses are implemented:
46 * SERIAL1 - I2C serial communications interface
47 * SERIAL2 - DDC2 monitor communications interface
48 *
49 * Tested on a FX41 mainboard, see http://www.shuttle.com
50 *
51 *
52 * TODO:
53 * - integration with prosavage framebuffer device
54 * (Additional documentation needed :(
55 */
56
57#include <linux/module.h>
58#include <linux/init.h>
59#include <linux/pci.h>
60#include <linux/i2c.h>
61#include <linux/i2c-algo-bit.h>
62#include <asm/io.h>
63
64/*
65 * driver configuration
66 */
67#define MAX_BUSSES 2
68
69struct s_i2c_bus {
70 void __iomem *mmvga;
71 int i2c_reg;
72 int adap_ok;
73 struct i2c_adapter adap;
74 struct i2c_algo_bit_data algo;
75};
76
77struct s_i2c_chip {
78 void __iomem *mmio;
79 struct s_i2c_bus i2c_bus[MAX_BUSSES];
80};
81
82
83/*
84 * i2c configuration
85 */
86#define CYCLE_DELAY 10
87#define TIMEOUT (HZ / 2)
88
89
90/*
91 * S3/VIA 8365/8375 registers
92 */
93#define VGA_CR_IX 0x3d4
94#define VGA_CR_DATA 0x3d5
95
96#define CR_SERIAL1 0xa0 /* I2C serial communications interface */
97#define MM_SERIAL1 0xff20
98#define CR_SERIAL2 0xb1 /* DDC2 monitor communications interface */
99
100/* based on vt8365 documentation */
101#define I2C_ENAB 0x10
102#define I2C_SCL_OUT 0x01
103#define I2C_SDA_OUT 0x02
104#define I2C_SCL_IN 0x04
105#define I2C_SDA_IN 0x08
106
107#define SET_CR_IX(p, val) writeb((val), (p)->mmvga + VGA_CR_IX)
108#define SET_CR_DATA(p, val) writeb((val), (p)->mmvga + VGA_CR_DATA)
109#define GET_CR_DATA(p) readb((p)->mmvga + VGA_CR_DATA)
110
111
112/*
113 * Serial bus line handling
114 *
115 * serial communications register as parameter in private data
116 *
117 * TODO: locks with other code sections accessing video registers?
118 */
119static void bit_s3via_setscl(void *bus, int val)
120{
121 struct s_i2c_bus *p = (struct s_i2c_bus *)bus;
122 unsigned int r;
123
124 SET_CR_IX(p, p->i2c_reg);
125 r = GET_CR_DATA(p);
126 r |= I2C_ENAB;
127 if (val) {
128 r |= I2C_SCL_OUT;
129 } else {
130 r &= ~I2C_SCL_OUT;
131 }
132 SET_CR_DATA(p, r);
133}
134
135static void bit_s3via_setsda(void *bus, int val)
136{
137 struct s_i2c_bus *p = (struct s_i2c_bus *)bus;
138 unsigned int r;
139
140 SET_CR_IX(p, p->i2c_reg);
141 r = GET_CR_DATA(p);
142 r |= I2C_ENAB;
143 if (val) {
144 r |= I2C_SDA_OUT;
145 } else {
146 r &= ~I2C_SDA_OUT;
147 }
148 SET_CR_DATA(p, r);
149}
150
151static int bit_s3via_getscl(void *bus)
152{
153 struct s_i2c_bus *p = (struct s_i2c_bus *)bus;
154
155 SET_CR_IX(p, p->i2c_reg);
156 return (0 != (GET_CR_DATA(p) & I2C_SCL_IN));
157}
158
159static int bit_s3via_getsda(void *bus)
160{
161 struct s_i2c_bus *p = (struct s_i2c_bus *)bus;
162
163 SET_CR_IX(p, p->i2c_reg);
164 return (0 != (GET_CR_DATA(p) & I2C_SDA_IN));
165}
166
167
168/*
169 * adapter initialisation
170 */
171static int i2c_register_bus(struct pci_dev *dev, struct s_i2c_bus *p, void __iomem *mmvga, u32 i2c_reg)
172{
173 int ret;
174 p->adap.owner = THIS_MODULE;
175 p->adap.id = I2C_HW_B_S3VIA;
176 p->adap.algo_data = &p->algo;
177 p->adap.dev.parent = &dev->dev;
178 p->algo.setsda = bit_s3via_setsda;
179 p->algo.setscl = bit_s3via_setscl;
180 p->algo.getsda = bit_s3via_getsda;
181 p->algo.getscl = bit_s3via_getscl;
182 p->algo.udelay = CYCLE_DELAY;
183 p->algo.timeout = TIMEOUT;
184 p->algo.data = p;
185 p->mmvga = mmvga;
186 p->i2c_reg = i2c_reg;
187
188 ret = i2c_bit_add_bus(&p->adap);
189 if (ret) {
190 return ret;
191 }
192
193 p->adap_ok = 1;
194 return 0;
195}
196
197
198/*
199 * Cleanup stuff
200 */
201static void prosavage_remove(struct pci_dev *dev)
202{
203 struct s_i2c_chip *chip;
204 int i, ret;
205
206 chip = (struct s_i2c_chip *)pci_get_drvdata(dev);
207
208 if (!chip) {
209 return;
210 }
211 for (i = MAX_BUSSES - 1; i >= 0; i--) {
212 if (chip->i2c_bus[i].adap_ok == 0)
213 continue;
214
215 ret = i2c_del_adapter(&chip->i2c_bus[i].adap);
216 if (ret) {
217 dev_err(&dev->dev, "%s not removed\n",
218 chip->i2c_bus[i].adap.name);
219 }
220 }
221 if (chip->mmio) {
222 iounmap(chip->mmio);
223 }
224 kfree(chip);
225}
226
227
228/*
229 * Detect chip and initialize it
230 */
231static int __devinit prosavage_probe(struct pci_dev *dev, const struct pci_device_id *id)
232{
233 int ret;
234 unsigned long base, len;
235 struct s_i2c_chip *chip;
236 struct s_i2c_bus *bus;
237
238 pci_set_drvdata(dev, kzalloc(sizeof(struct s_i2c_chip), GFP_KERNEL));
239 chip = (struct s_i2c_chip *)pci_get_drvdata(dev);
240 if (chip == NULL) {
241 return -ENOMEM;
242 }
243
244 base = dev->resource[0].start & PCI_BASE_ADDRESS_MEM_MASK;
245 len = dev->resource[0].end - base + 1;
246 chip->mmio = ioremap_nocache(base, len);
247
248 if (chip->mmio == NULL) {
249 dev_err(&dev->dev, "ioremap failed\n");
250 prosavage_remove(dev);
251 return -ENODEV;
252 }
253
254
255 /*
256 * Chip initialisation
257 */
258 /* Unlock Extended IO Space ??? */
259
260
261 /*
262 * i2c bus registration
263 */
264 bus = &chip->i2c_bus[0];
265 snprintf(bus->adap.name, sizeof(bus->adap.name),
266 "ProSavage I2C bus at %02x:%02x.%x",
267 dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
268 ret = i2c_register_bus(dev, bus, chip->mmio + 0x8000, CR_SERIAL1);
269 if (ret) {
270 goto err_adap;
271 }
272 /*
273 * ddc bus registration
274 */
275 bus = &chip->i2c_bus[1];
276 snprintf(bus->adap.name, sizeof(bus->adap.name),
277 "ProSavage DDC bus at %02x:%02x.%x",
278 dev->bus->number, PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn));
279 ret = i2c_register_bus(dev, bus, chip->mmio + 0x8000, CR_SERIAL2);
280 if (ret) {
281 goto err_adap;
282 }
283 return 0;
284err_adap:
285 dev_err(&dev->dev, "%s failed\n", bus->adap.name);
286 prosavage_remove(dev);
287 return ret;
288}
289
290
291/*
292 * Data for PCI driver interface
293 */
294static struct pci_device_id prosavage_pci_tbl[] = {
295 { PCI_DEVICE(PCI_VENDOR_ID_S3, PCI_DEVICE_ID_S3_SAVAGE4) },
296 { PCI_DEVICE(PCI_VENDOR_ID_S3, PCI_DEVICE_ID_S3_PROSAVAGE8) },
297 { 0, },
298};
299
300MODULE_DEVICE_TABLE (pci, prosavage_pci_tbl);
301
302static struct pci_driver prosavage_driver = {
303 .name = "prosavage_smbus",
304 .id_table = prosavage_pci_tbl,
305 .probe = prosavage_probe,
306 .remove = prosavage_remove,
307};
308
309static int __init i2c_prosavage_init(void)
310{
311 return pci_register_driver(&prosavage_driver);
312}
313
314static void __exit i2c_prosavage_exit(void)
315{
316 pci_unregister_driver(&prosavage_driver);
317}
318
319MODULE_DEVICE_TABLE(pci, prosavage_pci_tbl);
320MODULE_AUTHOR("Henk Vergonet");
321MODULE_DESCRIPTION("ProSavage VIA 8365/8375 smbus driver");
322MODULE_LICENSE("GPL");
323
324module_init (i2c_prosavage_init);
325module_exit (i2c_prosavage_exit);
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index eb69fbadc9cb..af9e6034d7fb 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -39,7 +39,6 @@
39#include <asm/io.h> 39#include <asm/io.h>
40#include <asm/arch/i2c.h> 40#include <asm/arch/i2c.h>
41#include <asm/arch/pxa-regs.h> 41#include <asm/arch/pxa-regs.h>
42#include <asm/arch/pxa2xx-gpio.h>
43 42
44struct pxa_i2c { 43struct pxa_i2c {
45 spinlock_t lock; 44 spinlock_t lock;
@@ -945,32 +944,6 @@ static const struct i2c_algorithm i2c_pxa_pio_algorithm = {
945 .functionality = i2c_pxa_functionality, 944 .functionality = i2c_pxa_functionality,
946}; 945};
947 946
948static void i2c_pxa_enable(struct platform_device *dev)
949{
950 if (cpu_is_pxa27x()) {
951 switch (dev->id) {
952 case 0:
953 pxa_gpio_mode(GPIO117_I2CSCL_MD);
954 pxa_gpio_mode(GPIO118_I2CSDA_MD);
955 break;
956 case 1:
957 local_irq_disable();
958 PCFR |= PCFR_PI2CEN;
959 local_irq_enable();
960 break;
961 }
962 }
963}
964
965static void i2c_pxa_disable(struct platform_device *dev)
966{
967 if (cpu_is_pxa27x() && dev->id == 1) {
968 local_irq_disable();
969 PCFR &= ~PCFR_PI2CEN;
970 local_irq_enable();
971 }
972}
973
974#define res_len(r) ((r)->end - (r)->start + 1) 947#define res_len(r) ((r)->end - (r)->start + 1)
975static int i2c_pxa_probe(struct platform_device *dev) 948static int i2c_pxa_probe(struct platform_device *dev)
976{ 949{
@@ -1036,7 +1009,6 @@ static int i2c_pxa_probe(struct platform_device *dev)
1036#endif 1009#endif
1037 1010
1038 clk_enable(i2c->clk); 1011 clk_enable(i2c->clk);
1039 i2c_pxa_enable(dev);
1040 1012
1041 if (plat) { 1013 if (plat) {
1042 i2c->adap.class = plat->class; 1014 i2c->adap.class = plat->class;
@@ -1080,7 +1052,6 @@ eadapt:
1080 free_irq(irq, i2c); 1052 free_irq(irq, i2c);
1081ereqirq: 1053ereqirq:
1082 clk_disable(i2c->clk); 1054 clk_disable(i2c->clk);
1083 i2c_pxa_disable(dev);
1084 iounmap(i2c->reg_base); 1055 iounmap(i2c->reg_base);
1085eremap: 1056eremap:
1086 clk_put(i2c->clk); 1057 clk_put(i2c->clk);
@@ -1103,7 +1074,6 @@ static int __exit i2c_pxa_remove(struct platform_device *dev)
1103 1074
1104 clk_disable(i2c->clk); 1075 clk_disable(i2c->clk);
1105 clk_put(i2c->clk); 1076 clk_put(i2c->clk);
1106 i2c_pxa_disable(dev);
1107 1077
1108 iounmap(i2c->reg_base); 1078 iounmap(i2c->reg_base);
1109 release_mem_region(i2c->iobase, i2c->iosize); 1079 release_mem_region(i2c->iobase, i2c->iosize);
@@ -1134,5 +1104,5 @@ static void __exit i2c_adap_pxa_exit(void)
1134MODULE_LICENSE("GPL"); 1104MODULE_LICENSE("GPL");
1135MODULE_ALIAS("platform:pxa2xx-i2c"); 1105MODULE_ALIAS("platform:pxa2xx-i2c");
1136 1106
1137module_init(i2c_adap_pxa_init); 1107subsys_initcall(i2c_adap_pxa_init);
1138module_exit(i2c_adap_pxa_exit); 1108module_exit(i2c_adap_pxa_exit);
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 1305ef190fc1..4864723c7425 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -33,6 +33,7 @@
33#include <linux/err.h> 33#include <linux/err.h>
34#include <linux/platform_device.h> 34#include <linux/platform_device.h>
35#include <linux/clk.h> 35#include <linux/clk.h>
36#include <linux/cpufreq.h>
36 37
37#include <asm/hardware.h> 38#include <asm/hardware.h>
38#include <asm/irq.h> 39#include <asm/irq.h>
@@ -64,6 +65,7 @@ struct s3c24xx_i2c {
64 unsigned int tx_setup; 65 unsigned int tx_setup;
65 66
66 enum s3c24xx_i2c_state state; 67 enum s3c24xx_i2c_state state;
68 unsigned long clkrate;
67 69
68 void __iomem *regs; 70 void __iomem *regs;
69 struct clk *clk; 71 struct clk *clk;
@@ -71,6 +73,10 @@ struct s3c24xx_i2c {
71 struct resource *irq; 73 struct resource *irq;
72 struct resource *ioarea; 74 struct resource *ioarea;
73 struct i2c_adapter adap; 75 struct i2c_adapter adap;
76
77#ifdef CONFIG_CPU_FREQ
78 struct notifier_block freq_transition;
79#endif
74}; 80};
75 81
76/* default platform data to use if not supplied in the platform_device 82/* default platform data to use if not supplied in the platform_device
@@ -290,12 +296,12 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
290 * bus, or started a new i2c message 296 * bus, or started a new i2c message
291 */ 297 */
292 298
293 if (iicstat & S3C2410_IICSTAT_LASTBIT && 299 if (iicstat & S3C2410_IICSTAT_LASTBIT &&
294 !(i2c->msg->flags & I2C_M_IGNORE_NAK)) { 300 !(i2c->msg->flags & I2C_M_IGNORE_NAK)) {
295 /* ack was not received... */ 301 /* ack was not received... */
296 302
297 dev_dbg(i2c->dev, "ack was not received\n"); 303 dev_dbg(i2c->dev, "ack was not received\n");
298 s3c24xx_i2c_stop(i2c, -EREMOTEIO); 304 s3c24xx_i2c_stop(i2c, -ENXIO);
299 goto out_ack; 305 goto out_ack;
300 } 306 }
301 307
@@ -305,7 +311,7 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
305 i2c->state = STATE_WRITE; 311 i2c->state = STATE_WRITE;
306 312
307 /* terminate the transfer if there is nothing to do 313 /* terminate the transfer if there is nothing to do
308 * (used by the i2c probe to find devices */ 314 * as this is used by the i2c probe to find devices. */
309 315
310 if (is_lastmsg(i2c) && i2c->msg->len == 0) { 316 if (is_lastmsg(i2c) && i2c->msg->len == 0) {
311 s3c24xx_i2c_stop(i2c, 0); 317 s3c24xx_i2c_stop(i2c, 0);
@@ -323,7 +329,17 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
323 * end of the message, and if so, work out what to do 329 * end of the message, and if so, work out what to do
324 */ 330 */
325 331
332 if (!(i2c->msg->flags & I2C_M_IGNORE_NAK)) {
333 if (iicstat & S3C2410_IICSTAT_LASTBIT) {
334 dev_dbg(i2c->dev, "WRITE: No Ack\n");
335
336 s3c24xx_i2c_stop(i2c, -ECONNREFUSED);
337 goto out_ack;
338 }
339 }
340
326 retry_write: 341 retry_write:
342
327 if (!is_msgend(i2c)) { 343 if (!is_msgend(i2c)) {
328 byte = i2c->msg->buf[i2c->msg_ptr++]; 344 byte = i2c->msg->buf[i2c->msg_ptr++];
329 writeb(byte, i2c->regs + S3C2410_IICDS); 345 writeb(byte, i2c->regs + S3C2410_IICDS);
@@ -377,17 +393,6 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
377 * going to do any more read/write 393 * going to do any more read/write
378 */ 394 */
379 395
380 if (!(i2c->msg->flags & I2C_M_IGNORE_NAK) &&
381 !(is_msglast(i2c) && is_lastmsg(i2c))) {
382
383 if (iicstat & S3C2410_IICSTAT_LASTBIT) {
384 dev_dbg(i2c->dev, "READ: No Ack\n");
385
386 s3c24xx_i2c_stop(i2c, -ECONNREFUSED);
387 goto out_ack;
388 }
389 }
390
391 byte = readb(i2c->regs + S3C2410_IICDS); 396 byte = readb(i2c->regs + S3C2410_IICDS);
392 i2c->msg->buf[i2c->msg_ptr++] = byte; 397 i2c->msg->buf[i2c->msg_ptr++] = byte;
393 398
@@ -502,6 +507,9 @@ static int s3c24xx_i2c_doxfer(struct s3c24xx_i2c *i2c, struct i2c_msg *msgs, int
502 unsigned long timeout; 507 unsigned long timeout;
503 int ret; 508 int ret;
504 509
510 if (!readl(i2c->regs + S3C2410_IICCON) & S3C2410_IICCON_IRQEN)
511 return -EIO;
512
505 ret = s3c24xx_i2c_set_master(i2c); 513 ret = s3c24xx_i2c_set_master(i2c);
506 if (ret != 0) { 514 if (ret != 0) {
507 dev_err(i2c->dev, "cannot get bus (error %d)\n", ret); 515 dev_err(i2c->dev, "cannot get bus (error %d)\n", ret);
@@ -591,7 +599,7 @@ static struct s3c24xx_i2c s3c24xx_i2c = {
591 .owner = THIS_MODULE, 599 .owner = THIS_MODULE,
592 .algo = &s3c24xx_i2c_algorithm, 600 .algo = &s3c24xx_i2c_algorithm,
593 .retries = 2, 601 .retries = 2,
594 .class = I2C_CLASS_HWMON, 602 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
595 }, 603 },
596}; 604};
597 605
@@ -637,27 +645,28 @@ static inline int freq_acceptable(unsigned int freq, unsigned int wanted)
637 return (diff >= -2 && diff <= 2); 645 return (diff >= -2 && diff <= 2);
638} 646}
639 647
640/* s3c24xx_i2c_getdivisor 648/* s3c24xx_i2c_clockrate
641 * 649 *
642 * work out a divisor for the user requested frequency setting, 650 * work out a divisor for the user requested frequency setting,
643 * either by the requested frequency, or scanning the acceptable 651 * either by the requested frequency, or scanning the acceptable
644 * range of frequencies until something is found 652 * range of frequencies until something is found
645*/ 653*/
646 654
647static int s3c24xx_i2c_getdivisor(struct s3c24xx_i2c *i2c, 655static int s3c24xx_i2c_clockrate(struct s3c24xx_i2c *i2c, unsigned int *got)
648 struct s3c2410_platform_i2c *pdata,
649 unsigned long *iicon,
650 unsigned int *got)
651{ 656{
657 struct s3c2410_platform_i2c *pdata;
652 unsigned long clkin = clk_get_rate(i2c->clk); 658 unsigned long clkin = clk_get_rate(i2c->clk);
653
654 unsigned int divs, div1; 659 unsigned int divs, div1;
660 u32 iiccon;
655 int freq; 661 int freq;
656 int start, end; 662 int start, end;
657 663
664 i2c->clkrate = clkin;
665
666 pdata = s3c24xx_i2c_get_platformdata(i2c->adap.dev.parent);
658 clkin /= 1000; /* clkin now in KHz */ 667 clkin /= 1000; /* clkin now in KHz */
659 668
660 dev_dbg(i2c->dev, "pdata %p, freq %lu %lu..%lu\n", 669 dev_dbg(i2c->dev, "pdata %p, freq %lu %lu..%lu\n",
661 pdata, pdata->bus_freq, pdata->min_freq, pdata->max_freq); 670 pdata, pdata->bus_freq, pdata->min_freq, pdata->max_freq);
662 671
663 if (pdata->bus_freq != 0) { 672 if (pdata->bus_freq != 0) {
@@ -689,11 +698,79 @@ static int s3c24xx_i2c_getdivisor(struct s3c24xx_i2c *i2c,
689 698
690 found: 699 found:
691 *got = freq; 700 *got = freq;
692 *iicon |= (divs-1); 701
693 *iicon |= (div1 == 512) ? S3C2410_IICCON_TXDIV_512 : 0; 702 iiccon = readl(i2c->regs + S3C2410_IICCON);
703 iiccon &= ~(S3C2410_IICCON_SCALEMASK | S3C2410_IICCON_TXDIV_512);
704 iiccon |= (divs-1);
705
706 if (div1 == 512)
707 iiccon |= S3C2410_IICCON_TXDIV_512;
708
709 writel(iiccon, i2c->regs + S3C2410_IICCON);
710
711 return 0;
712}
713
714#ifdef CONFIG_CPU_FREQ
715
716#define freq_to_i2c(_n) container_of(_n, struct s3c24xx_i2c, freq_transition)
717
718static int s3c24xx_i2c_cpufreq_transition(struct notifier_block *nb,
719 unsigned long val, void *data)
720{
721 struct s3c24xx_i2c *i2c = freq_to_i2c(nb);
722 unsigned long flags;
723 unsigned int got;
724 int delta_f;
725 int ret;
726
727 delta_f = clk_get_rate(i2c->clk) - i2c->clkrate;
728
729 /* if we're post-change and the input clock has slowed down
730 * or at pre-change and the clock is about to speed up, then
731 * adjust our clock rate. <0 is slow, >0 speedup.
732 */
733
734 if ((val == CPUFREQ_POSTCHANGE && delta_f < 0) ||
735 (val == CPUFREQ_PRECHANGE && delta_f > 0)) {
736 spin_lock_irqsave(&i2c->lock, flags);
737 ret = s3c24xx_i2c_clockrate(i2c, &got);
738 spin_unlock_irqrestore(&i2c->lock, flags);
739
740 if (ret < 0)
741 dev_err(i2c->dev, "cannot find frequency\n");
742 else
743 dev_info(i2c->dev, "setting freq %d\n", got);
744 }
745
694 return 0; 746 return 0;
695} 747}
696 748
749static inline int s3c24xx_i2c_register_cpufreq(struct s3c24xx_i2c *i2c)
750{
751 i2c->freq_transition.notifier_call = s3c24xx_i2c_cpufreq_transition;
752
753 return cpufreq_register_notifier(&i2c->freq_transition,
754 CPUFREQ_TRANSITION_NOTIFIER);
755}
756
757static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c)
758{
759 cpufreq_unregister_notifier(&i2c->freq_transition,
760 CPUFREQ_TRANSITION_NOTIFIER);
761}
762
763#else
764static inline int s3c24xx_i2c_register_cpufreq(struct s3c24xx_i2c *i2c)
765{
766 return 0;
767}
768
769static inline void s3c24xx_i2c_deregister_cpufreq(struct s3c24xx_i2c *i2c)
770{
771}
772#endif
773
697/* s3c24xx_i2c_init 774/* s3c24xx_i2c_init
698 * 775 *
699 * initialise the controller, set the IO lines and frequency 776 * initialise the controller, set the IO lines and frequency
@@ -720,9 +797,12 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
720 797
721 dev_info(i2c->dev, "slave address 0x%02x\n", pdata->slave_addr); 798 dev_info(i2c->dev, "slave address 0x%02x\n", pdata->slave_addr);
722 799
800 writel(iicon, i2c->regs + S3C2410_IICCON);
801
723 /* we need to work out the divisors for the clock... */ 802 /* we need to work out the divisors for the clock... */
724 803
725 if (s3c24xx_i2c_getdivisor(i2c, pdata, &iicon, &freq) != 0) { 804 if (s3c24xx_i2c_clockrate(i2c, &freq) != 0) {
805 writel(0, i2c->regs + S3C2410_IICCON);
726 dev_err(i2c->dev, "cannot meet bus frequency required\n"); 806 dev_err(i2c->dev, "cannot meet bus frequency required\n");
727 return -EINVAL; 807 return -EINVAL;
728 } 808 }
@@ -731,8 +811,6 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
731 811
732 dev_info(i2c->dev, "bus frequency set to %d KHz\n", freq); 812 dev_info(i2c->dev, "bus frequency set to %d KHz\n", freq);
733 dev_dbg(i2c->dev, "S3C2410_IICCON=0x%02lx\n", iicon); 813 dev_dbg(i2c->dev, "S3C2410_IICCON=0x%02lx\n", iicon);
734
735 writel(iicon, i2c->regs + S3C2410_IICCON);
736 814
737 /* check for s3c2440 i2c controller */ 815 /* check for s3c2440 i2c controller */
738 816
@@ -753,9 +831,12 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
753static int s3c24xx_i2c_probe(struct platform_device *pdev) 831static int s3c24xx_i2c_probe(struct platform_device *pdev)
754{ 832{
755 struct s3c24xx_i2c *i2c = &s3c24xx_i2c; 833 struct s3c24xx_i2c *i2c = &s3c24xx_i2c;
834 struct s3c2410_platform_i2c *pdata;
756 struct resource *res; 835 struct resource *res;
757 int ret; 836 int ret;
758 837
838 pdata = s3c24xx_i2c_get_platformdata(&pdev->dev);
839
759 /* find the clock and enable it */ 840 /* find the clock and enable it */
760 841
761 i2c->dev = &pdev->dev; 842 i2c->dev = &pdev->dev;
@@ -833,17 +914,34 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
833 dev_dbg(&pdev->dev, "irq resource %p (%lu)\n", res, 914 dev_dbg(&pdev->dev, "irq resource %p (%lu)\n", res,
834 (unsigned long)res->start); 915 (unsigned long)res->start);
835 916
836 ret = i2c_add_adapter(&i2c->adap); 917 ret = s3c24xx_i2c_register_cpufreq(i2c);
837 if (ret < 0) { 918 if (ret < 0) {
838 dev_err(&pdev->dev, "failed to add bus to i2c core\n"); 919 dev_err(&pdev->dev, "failed to register cpufreq notifier\n");
839 goto err_irq; 920 goto err_irq;
840 } 921 }
841 922
923 /* Note, previous versions of the driver used i2c_add_adapter()
924 * to add the bus at any number. We now pass the bus number via
925 * the platform data, so if unset it will now default to always
926 * being bus 0.
927 */
928
929 i2c->adap.nr = pdata->bus_num;
930
931 ret = i2c_add_numbered_adapter(&i2c->adap);
932 if (ret < 0) {
933 dev_err(&pdev->dev, "failed to add bus to i2c core\n");
934 goto err_cpufreq;
935 }
936
842 platform_set_drvdata(pdev, i2c); 937 platform_set_drvdata(pdev, i2c);
843 938
844 dev_info(&pdev->dev, "%s: S3C I2C adapter\n", i2c->adap.dev.bus_id); 939 dev_info(&pdev->dev, "%s: S3C I2C adapter\n", i2c->adap.dev.bus_id);
845 return 0; 940 return 0;
846 941
942 err_cpufreq:
943 s3c24xx_i2c_deregister_cpufreq(i2c);
944
847 err_irq: 945 err_irq:
848 free_irq(i2c->irq->start, i2c); 946 free_irq(i2c->irq->start, i2c);
849 947
@@ -871,6 +969,8 @@ static int s3c24xx_i2c_remove(struct platform_device *pdev)
871{ 969{
872 struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev); 970 struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev);
873 971
972 s3c24xx_i2c_deregister_cpufreq(i2c);
973
874 i2c_del_adapter(&i2c->adap); 974 i2c_del_adapter(&i2c->adap);
875 free_irq(i2c->irq->start, i2c); 975 free_irq(i2c->irq->start, i2c);
876 976
@@ -949,3 +1049,4 @@ MODULE_DESCRIPTION("S3C24XX I2C Bus driver");
949MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>"); 1049MODULE_AUTHOR("Ben Dooks, <ben@simtec.co.uk>");
950MODULE_LICENSE("GPL"); 1050MODULE_LICENSE("GPL");
951MODULE_ALIAS("platform:s3c2410-i2c"); 1051MODULE_ALIAS("platform:s3c2410-i2c");
1052MODULE_ALIAS("platform:s3c2440-i2c");
diff --git a/drivers/i2c/busses/i2c-savage4.c b/drivers/i2c/busses/i2c-savage4.c
deleted file mode 100644
index 8adf4abaa035..000000000000
--- a/drivers/i2c/busses/i2c-savage4.c
+++ /dev/null
@@ -1,185 +0,0 @@
1/*
2 i2c-savage4.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (C) 1998-2003 The LM Sensors Team
5 Alexander Wold <awold@bigfoot.com>
6 Mark D. Studebaker <mdsxyz123@yahoo.com>
7
8 Based on i2c-voodoo3.c.
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 Savage4 to gain access to
26 the BT869 and possibly other I2C devices. The DDC bus is not
27 yet supported because its register is not memory-mapped.
28*/
29
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/init.h>
33#include <linux/pci.h>
34#include <linux/i2c.h>
35#include <linux/i2c-algo-bit.h>
36#include <asm/io.h>
37
38/* device IDs */
39#define PCI_CHIP_SAVAGE4 0x8A22
40#define PCI_CHIP_SAVAGE2000 0x9102
41
42#define REG 0xff20 /* Serial Port 1 Register */
43
44/* bit locations in the register */
45#define I2C_ENAB 0x00000020
46#define I2C_SCL_OUT 0x00000001
47#define I2C_SDA_OUT 0x00000002
48#define I2C_SCL_IN 0x00000008
49#define I2C_SDA_IN 0x00000010
50
51/* delays */
52#define CYCLE_DELAY 10
53#define TIMEOUT (HZ / 2)
54
55
56static void __iomem *ioaddr;
57
58/* The sav GPIO registers don't have individual masks for each bit
59 so we always have to read before writing. */
60
61static void bit_savi2c_setscl(void *data, int val)
62{
63 unsigned int r;
64 r = readl(ioaddr + REG);
65 if(val)
66 r |= I2C_SCL_OUT;
67 else
68 r &= ~I2C_SCL_OUT;
69 writel(r, ioaddr + REG);
70 readl(ioaddr + REG); /* flush posted write */
71}
72
73static void bit_savi2c_setsda(void *data, int val)
74{
75 unsigned int r;
76 r = readl(ioaddr + REG);
77 if(val)
78 r |= I2C_SDA_OUT;
79 else
80 r &= ~I2C_SDA_OUT;
81 writel(r, ioaddr + REG);
82 readl(ioaddr + REG); /* flush posted write */
83}
84
85/* The GPIO pins are open drain, so the pins always remain outputs.
86 We rely on the i2c-algo-bit routines to set the pins high before
87 reading the input from other chips. */
88
89static int bit_savi2c_getscl(void *data)
90{
91 return (0 != (readl(ioaddr + REG) & I2C_SCL_IN));
92}
93
94static int bit_savi2c_getsda(void *data)
95{
96 return (0 != (readl(ioaddr + REG) & I2C_SDA_IN));
97}
98
99/* Configures the chip */
100
101static int config_s4(struct pci_dev *dev)
102{
103 unsigned long cadr;
104
105 /* map memory */
106 cadr = dev->resource[0].start;
107 cadr &= PCI_BASE_ADDRESS_MEM_MASK;
108 ioaddr = ioremap_nocache(cadr, 0x0080000);
109 if (ioaddr) {
110 /* writel(0x8160, ioaddr + REG2); */
111 writel(0x00000020, ioaddr + REG);
112 dev_info(&dev->dev, "Using Savage4 at %p\n", ioaddr);
113 return 0;
114 }
115 return -ENODEV;
116}
117
118static struct i2c_algo_bit_data sav_i2c_bit_data = {
119 .setsda = bit_savi2c_setsda,
120 .setscl = bit_savi2c_setscl,
121 .getsda = bit_savi2c_getsda,
122 .getscl = bit_savi2c_getscl,
123 .udelay = CYCLE_DELAY,
124 .timeout = TIMEOUT
125};
126
127static struct i2c_adapter savage4_i2c_adapter = {
128 .owner = THIS_MODULE,
129 .id = I2C_HW_B_SAVAGE,
130 .name = "I2C Savage4 adapter",
131 .algo_data = &sav_i2c_bit_data,
132};
133
134static struct pci_device_id savage4_ids[] __devinitdata = {
135 { PCI_DEVICE(PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE4) },
136 { PCI_DEVICE(PCI_VENDOR_ID_S3, PCI_CHIP_SAVAGE2000) },
137 { 0, }
138};
139
140MODULE_DEVICE_TABLE (pci, savage4_ids);
141
142static int __devinit savage4_probe(struct pci_dev *dev, const struct pci_device_id *id)
143{
144 int retval;
145
146 retval = config_s4(dev);
147 if (retval)
148 return retval;
149
150 /* set up the sysfs linkage to our parent device */
151 savage4_i2c_adapter.dev.parent = &dev->dev;
152
153 return i2c_bit_add_bus(&savage4_i2c_adapter);
154}
155
156static void __devexit savage4_remove(struct pci_dev *dev)
157{
158 i2c_del_adapter(&savage4_i2c_adapter);
159 iounmap(ioaddr);
160}
161
162static struct pci_driver savage4_driver = {
163 .name = "savage4_smbus",
164 .id_table = savage4_ids,
165 .probe = savage4_probe,
166 .remove = __devexit_p(savage4_remove),
167};
168
169static int __init i2c_savage4_init(void)
170{
171 return pci_register_driver(&savage4_driver);
172}
173
174static void __exit i2c_savage4_exit(void)
175{
176 pci_unregister_driver(&savage4_driver);
177}
178
179MODULE_AUTHOR("Alexander Wold <awold@bigfoot.com> "
180 "and Mark D. Studebaker <mdsxyz123@yahoo.com>");
181MODULE_DESCRIPTION("Savage4 I2C/SMBus driver");
182MODULE_LICENSE("GPL");
183
184module_init(i2c_savage4_init);
185module_exit(i2c_savage4_exit);
diff --git a/drivers/i2c/busses/i2c-sibyte.c b/drivers/i2c/busses/i2c-sibyte.c
index 8fbbdb4c2f35..4ddefbf238e9 100644
--- a/drivers/i2c/busses/i2c-sibyte.c
+++ b/drivers/i2c/busses/i2c-sibyte.c
@@ -132,18 +132,18 @@ static const struct i2c_algorithm i2c_sibyte_algo = {
132/* 132/*
133 * registering functions to load algorithms at runtime 133 * registering functions to load algorithms at runtime
134 */ 134 */
135int __init i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed) 135static int __init i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed)
136{ 136{
137 struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data; 137 struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
138 138
139 /* register new adapter to i2c module... */ 139 /* Register new adapter to i2c module... */
140 i2c_adap->algo = &i2c_sibyte_algo; 140 i2c_adap->algo = &i2c_sibyte_algo;
141 141
142 /* Set the frequency to 100 kHz */ 142 /* Set the requested frequency. */
143 csr_out32(speed, SMB_CSR(adap,R_SMB_FREQ)); 143 csr_out32(speed, SMB_CSR(adap,R_SMB_FREQ));
144 csr_out32(0, SMB_CSR(adap,R_SMB_CONTROL)); 144 csr_out32(0, SMB_CSR(adap,R_SMB_CONTROL));
145 145
146 return i2c_add_adapter(i2c_adap); 146 return i2c_add_numbered_adapter(i2c_adap);
147} 147}
148 148
149 149
@@ -156,17 +156,19 @@ static struct i2c_adapter sibyte_board_adapter[2] = {
156 { 156 {
157 .owner = THIS_MODULE, 157 .owner = THIS_MODULE,
158 .id = I2C_HW_SIBYTE, 158 .id = I2C_HW_SIBYTE,
159 .class = I2C_CLASS_HWMON, 159 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
160 .algo = NULL, 160 .algo = NULL,
161 .algo_data = &sibyte_board_data[0], 161 .algo_data = &sibyte_board_data[0],
162 .nr = 0,
162 .name = "SiByte SMBus 0", 163 .name = "SiByte SMBus 0",
163 }, 164 },
164 { 165 {
165 .owner = THIS_MODULE, 166 .owner = THIS_MODULE,
166 .id = I2C_HW_SIBYTE, 167 .id = I2C_HW_SIBYTE,
167 .class = I2C_CLASS_HWMON, 168 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
168 .algo = NULL, 169 .algo = NULL,
169 .algo_data = &sibyte_board_data[1], 170 .algo_data = &sibyte_board_data[1],
171 .nr = 1,
170 .name = "SiByte SMBus 1", 172 .name = "SiByte SMBus 1",
171 }, 173 },
172}; 174};
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index 9ca8f9155f95..dfc2d5eb6a68 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -1,6 +1,4 @@
1/* 1/*
2 sis5595.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> and 2 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl> and
5 Philip Edelbrock <phil@netroedge.com> 3 Philip Edelbrock <phil@netroedge.com>
6 4
@@ -62,6 +60,7 @@
62#include <linux/ioport.h> 60#include <linux/ioport.h>
63#include <linux/init.h> 61#include <linux/init.h>
64#include <linux/i2c.h> 62#include <linux/i2c.h>
63#include <linux/acpi.h>
65#include <asm/io.h> 64#include <asm/io.h>
66 65
67static int blacklist[] = { 66static int blacklist[] = {
@@ -174,6 +173,11 @@ static int sis5595_setup(struct pci_dev *SIS5595_dev)
174 173
175 /* NB: We grab just the two SMBus registers here, but this may still 174 /* NB: We grab just the two SMBus registers here, but this may still
176 * interfere with ACPI :-( */ 175 * interfere with ACPI :-( */
176 retval = acpi_check_region(sis5595_base + SMB_INDEX, 2,
177 sis5595_driver.name);
178 if (retval)
179 return retval;
180
177 if (!request_region(sis5595_base + SMB_INDEX, 2, 181 if (!request_region(sis5595_base + SMB_INDEX, 2,
178 sis5595_driver.name)) { 182 sis5595_driver.name)) {
179 dev_err(&SIS5595_dev->dev, "SMBus registers 0x%04x-0x%04x already in use!\n", 183 dev_err(&SIS5595_dev->dev, "SMBus registers 0x%04x-0x%04x already in use!\n",
@@ -236,7 +240,7 @@ static int sis5595_transaction(struct i2c_adapter *adap)
236 sis5595_write(SMB_STS_HI, temp >> 8); 240 sis5595_write(SMB_STS_HI, temp >> 8);
237 if ((temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) != 0x00) { 241 if ((temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8)) != 0x00) {
238 dev_dbg(&adap->dev, "Failed! (%02x)\n", temp); 242 dev_dbg(&adap->dev, "Failed! (%02x)\n", temp);
239 return -1; 243 return -EBUSY;
240 } else { 244 } else {
241 dev_dbg(&adap->dev, "Successful!\n"); 245 dev_dbg(&adap->dev, "Successful!\n");
242 } 246 }
@@ -254,19 +258,19 @@ static int sis5595_transaction(struct i2c_adapter *adap)
254 /* If the SMBus is still busy, we give up */ 258 /* If the SMBus is still busy, we give up */
255 if (timeout >= MAX_TIMEOUT) { 259 if (timeout >= MAX_TIMEOUT) {
256 dev_dbg(&adap->dev, "SMBus Timeout!\n"); 260 dev_dbg(&adap->dev, "SMBus Timeout!\n");
257 result = -1; 261 result = -ETIMEDOUT;
258 } 262 }
259 263
260 if (temp & 0x10) { 264 if (temp & 0x10) {
261 dev_dbg(&adap->dev, "Error: Failed bus transaction\n"); 265 dev_dbg(&adap->dev, "Error: Failed bus transaction\n");
262 result = -1; 266 result = -ENXIO;
263 } 267 }
264 268
265 if (temp & 0x20) { 269 if (temp & 0x20) {
266 dev_err(&adap->dev, "Bus collision! SMBus may be locked until " 270 dev_err(&adap->dev, "Bus collision! SMBus may be locked until "
267 "next hard reset (or not...)\n"); 271 "next hard reset (or not...)\n");
268 /* Clock stops and slave is stuck in mid-transmission */ 272 /* Clock stops and slave is stuck in mid-transmission */
269 result = -1; 273 result = -EIO;
270 } 274 }
271 275
272 temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8); 276 temp = sis5595_read(SMB_STS_LO) + (sis5595_read(SMB_STS_HI) << 8);
@@ -282,11 +286,13 @@ static int sis5595_transaction(struct i2c_adapter *adap)
282 return result; 286 return result;
283} 287}
284 288
285/* Return -1 on error. */ 289/* Return negative errno on error. */
286static s32 sis5595_access(struct i2c_adapter *adap, u16 addr, 290static s32 sis5595_access(struct i2c_adapter *adap, u16 addr,
287 unsigned short flags, char read_write, 291 unsigned short flags, char read_write,
288 u8 command, int size, union i2c_smbus_data *data) 292 u8 command, int size, union i2c_smbus_data *data)
289{ 293{
294 int status;
295
290 switch (size) { 296 switch (size) {
291 case I2C_SMBUS_QUICK: 297 case I2C_SMBUS_QUICK:
292 sis5595_write(SMB_ADDR, ((addr & 0x7f) << 1) | (read_write & 0x01)); 298 sis5595_write(SMB_ADDR, ((addr & 0x7f) << 1) | (read_write & 0x01));
@@ -318,13 +324,14 @@ static s32 sis5595_access(struct i2c_adapter *adap, u16 addr,
318 break; 324 break;
319 default: 325 default:
320 dev_warn(&adap->dev, "Unsupported transaction %d\n", size); 326 dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
321 return -1; 327 return -EOPNOTSUPP;
322 } 328 }
323 329
324 sis5595_write(SMB_CTL_LO, ((size & 0x0E))); 330 sis5595_write(SMB_CTL_LO, ((size & 0x0E)));
325 331
326 if (sis5595_transaction(adap)) 332 status = sis5595_transaction(adap);
327 return -1; 333 if (status)
334 return status;
328 335
329 if ((size != SIS5595_PROC_CALL) && 336 if ((size != SIS5595_PROC_CALL) &&
330 ((read_write == I2C_SMBUS_WRITE) || (size == SIS5595_QUICK))) 337 ((read_write == I2C_SMBUS_WRITE) || (size == SIS5595_QUICK)))
@@ -359,7 +366,7 @@ static const struct i2c_algorithm smbus_algorithm = {
359static struct i2c_adapter sis5595_adapter = { 366static struct i2c_adapter sis5595_adapter = {
360 .owner = THIS_MODULE, 367 .owner = THIS_MODULE,
361 .id = I2C_HW_SMBUS_SIS5595, 368 .id = I2C_HW_SMBUS_SIS5595,
362 .class = I2C_CLASS_HWMON, 369 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
363 .algo = &smbus_algorithm, 370 .algo = &smbus_algorithm,
364}; 371};
365 372
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c
index 3765dd7f450f..e7c4b790da54 100644
--- a/drivers/i2c/busses/i2c-sis630.c
+++ b/drivers/i2c/busses/i2c-sis630.c
@@ -1,7 +1,4 @@
1/* 1/*
2 i2c-sis630.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4
5 Copyright (c) 2002,2003 Alexander Malysh <amalysh@web.de> 2 Copyright (c) 2002,2003 Alexander Malysh <amalysh@web.de>
6 3
7 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
@@ -55,6 +52,7 @@
55#include <linux/ioport.h> 52#include <linux/ioport.h>
56#include <linux/init.h> 53#include <linux/init.h>
57#include <linux/i2c.h> 54#include <linux/i2c.h>
55#include <linux/acpi.h>
58#include <asm/io.h> 56#include <asm/io.h>
59 57
60/* SIS630 SMBus registers */ 58/* SIS630 SMBus registers */
@@ -134,7 +132,7 @@ static int sis630_transaction_start(struct i2c_adapter *adap, int size, u8 *oldc
134 132
135 if ((temp = sis630_read(SMB_CNT) & 0x03) != 0x00) { 133 if ((temp = sis630_read(SMB_CNT) & 0x03) != 0x00) {
136 dev_dbg(&adap->dev, "Failed! (%02x)\n", temp); 134 dev_dbg(&adap->dev, "Failed! (%02x)\n", temp);
137 return -1; 135 return -EBUSY;
138 } else { 136 } else {
139 dev_dbg(&adap->dev, "Successful!\n"); 137 dev_dbg(&adap->dev, "Successful!\n");
140 } 138 }
@@ -177,17 +175,17 @@ static int sis630_transaction_wait(struct i2c_adapter *adap, int size)
177 /* If the SMBus is still busy, we give up */ 175 /* If the SMBus is still busy, we give up */
178 if (timeout >= MAX_TIMEOUT) { 176 if (timeout >= MAX_TIMEOUT) {
179 dev_dbg(&adap->dev, "SMBus Timeout!\n"); 177 dev_dbg(&adap->dev, "SMBus Timeout!\n");
180 result = -1; 178 result = -ETIMEDOUT;
181 } 179 }
182 180
183 if (temp & 0x02) { 181 if (temp & 0x02) {
184 dev_dbg(&adap->dev, "Error: Failed bus transaction\n"); 182 dev_dbg(&adap->dev, "Error: Failed bus transaction\n");
185 result = -1; 183 result = -ENXIO;
186 } 184 }
187 185
188 if (temp & 0x04) { 186 if (temp & 0x04) {
189 dev_err(&adap->dev, "Bus collision!\n"); 187 dev_err(&adap->dev, "Bus collision!\n");
190 result = -1; 188 result = -EIO;
191 /* 189 /*
192 TBD: Datasheet say: 190 TBD: Datasheet say:
193 the software should clear this bit and restart SMBUS operation. 191 the software should clear this bit and restart SMBUS operation.
@@ -250,8 +248,10 @@ static int sis630_block_data(struct i2c_adapter *adap, union i2c_smbus_data *dat
250 if (i==8 || (len<8 && i==len)) { 248 if (i==8 || (len<8 && i==len)) {
251 dev_dbg(&adap->dev, "start trans len=%d i=%d\n",len ,i); 249 dev_dbg(&adap->dev, "start trans len=%d i=%d\n",len ,i);
252 /* first transaction */ 250 /* first transaction */
253 if (sis630_transaction_start(adap, SIS630_BLOCK_DATA, &oldclock)) 251 rc = sis630_transaction_start(adap,
254 return -1; 252 SIS630_BLOCK_DATA, &oldclock);
253 if (rc)
254 return rc;
255 } 255 }
256 else if ((i-1)%8 == 7 || i==len) { 256 else if ((i-1)%8 == 7 || i==len) {
257 dev_dbg(&adap->dev, "trans_wait len=%d i=%d\n",len,i); 257 dev_dbg(&adap->dev, "trans_wait len=%d i=%d\n",len,i);
@@ -264,9 +264,10 @@ static int sis630_block_data(struct i2c_adapter *adap, union i2c_smbus_data *dat
264 */ 264 */
265 sis630_write(SMB_STS,0x10); 265 sis630_write(SMB_STS,0x10);
266 } 266 }
267 if (sis630_transaction_wait(adap, SIS630_BLOCK_DATA)) { 267 rc = sis630_transaction_wait(adap,
268 SIS630_BLOCK_DATA);
269 if (rc) {
268 dev_dbg(&adap->dev, "trans_wait failed\n"); 270 dev_dbg(&adap->dev, "trans_wait failed\n");
269 rc = -1;
270 break; 271 break;
271 } 272 }
272 } 273 }
@@ -275,13 +276,14 @@ static int sis630_block_data(struct i2c_adapter *adap, union i2c_smbus_data *dat
275 else { 276 else {
276 /* read request */ 277 /* read request */
277 data->block[0] = len = 0; 278 data->block[0] = len = 0;
278 if (sis630_transaction_start(adap, SIS630_BLOCK_DATA, &oldclock)) { 279 rc = sis630_transaction_start(adap,
279 return -1; 280 SIS630_BLOCK_DATA, &oldclock);
280 } 281 if (rc)
282 return rc;
281 do { 283 do {
282 if (sis630_transaction_wait(adap, SIS630_BLOCK_DATA)) { 284 rc = sis630_transaction_wait(adap, SIS630_BLOCK_DATA);
285 if (rc) {
283 dev_dbg(&adap->dev, "trans_wait failed\n"); 286 dev_dbg(&adap->dev, "trans_wait failed\n");
284 rc = -1;
285 break; 287 break;
286 } 288 }
287 /* if this first transaction then read byte count */ 289 /* if this first transaction then read byte count */
@@ -311,11 +313,13 @@ static int sis630_block_data(struct i2c_adapter *adap, union i2c_smbus_data *dat
311 return rc; 313 return rc;
312} 314}
313 315
314/* Return -1 on error. */ 316/* Return negative errno on error. */
315static s32 sis630_access(struct i2c_adapter *adap, u16 addr, 317static s32 sis630_access(struct i2c_adapter *adap, u16 addr,
316 unsigned short flags, char read_write, 318 unsigned short flags, char read_write,
317 u8 command, int size, union i2c_smbus_data *data) 319 u8 command, int size, union i2c_smbus_data *data)
318{ 320{
321 int status;
322
319 switch (size) { 323 switch (size) {
320 case I2C_SMBUS_QUICK: 324 case I2C_SMBUS_QUICK:
321 sis630_write(SMB_ADDR, ((addr & 0x7f) << 1) | (read_write & 0x01)); 325 sis630_write(SMB_ADDR, ((addr & 0x7f) << 1) | (read_write & 0x01));
@@ -350,13 +354,14 @@ static s32 sis630_access(struct i2c_adapter *adap, u16 addr,
350 size = SIS630_BLOCK_DATA; 354 size = SIS630_BLOCK_DATA;
351 return sis630_block_data(adap, data, read_write); 355 return sis630_block_data(adap, data, read_write);
352 default: 356 default:
353 printk("Unsupported I2C size\n"); 357 dev_warn(&adap->dev, "Unsupported transaction %d\n",
354 return -1; 358 size);
355 break; 359 return -EOPNOTSUPP;
356 } 360 }
357 361
358 if (sis630_transaction(adap, size)) 362 status = sis630_transaction(adap, size);
359 return -1; 363 if (status)
364 return status;
360 365
361 if ((size != SIS630_PCALL) && 366 if ((size != SIS630_PCALL) &&
362 ((read_write == I2C_SMBUS_WRITE) || (size == SIS630_QUICK))) { 367 ((read_write == I2C_SMBUS_WRITE) || (size == SIS630_QUICK))) {
@@ -372,9 +377,6 @@ static s32 sis630_access(struct i2c_adapter *adap, u16 addr,
372 case SIS630_WORD_DATA: 377 case SIS630_WORD_DATA:
373 data->word = sis630_read(SMB_BYTE) + (sis630_read(SMB_BYTE + 1) << 8); 378 data->word = sis630_read(SMB_BYTE) + (sis630_read(SMB_BYTE + 1) << 8);
374 break; 379 break;
375 default:
376 return -1;
377 break;
378 } 380 }
379 381
380 return 0; 382 return 0;
@@ -433,6 +435,11 @@ static int sis630_setup(struct pci_dev *sis630_dev)
433 435
434 dev_dbg(&sis630_dev->dev, "ACPI base at 0x%04x\n", acpi_base); 436 dev_dbg(&sis630_dev->dev, "ACPI base at 0x%04x\n", acpi_base);
435 437
438 retval = acpi_check_region(acpi_base + SMB_STS, SIS630_SMB_IOREGION,
439 sis630_driver.name);
440 if (retval)
441 goto exit;
442
436 /* Everything is happy, let's grab the memory and set things up. */ 443 /* Everything is happy, let's grab the memory and set things up. */
437 if (!request_region(acpi_base + SMB_STS, SIS630_SMB_IOREGION, 444 if (!request_region(acpi_base + SMB_STS, SIS630_SMB_IOREGION,
438 sis630_driver.name)) { 445 sis630_driver.name)) {
@@ -458,7 +465,7 @@ static const struct i2c_algorithm smbus_algorithm = {
458static struct i2c_adapter sis630_adapter = { 465static struct i2c_adapter sis630_adapter = {
459 .owner = THIS_MODULE, 466 .owner = THIS_MODULE,
460 .id = I2C_HW_SMBUS_SIS630, 467 .id = I2C_HW_SMBUS_SIS630,
461 .class = I2C_CLASS_HWMON, 468 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
462 .algo = &smbus_algorithm, 469 .algo = &smbus_algorithm,
463}; 470};
464 471
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index dc235bb8e24d..f1bba6396641 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -1,7 +1,4 @@
1/* 1/*
2 sis96x.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4
5 Copyright (c) 2003 Mark M. Hoffman <mhoffman@lightlink.com> 2 Copyright (c) 2003 Mark M. Hoffman <mhoffman@lightlink.com>
6 3
7 This program is free software; you can redistribute it and/or modify 4 This program is free software; you can redistribute it and/or modify
@@ -40,6 +37,7 @@
40#include <linux/ioport.h> 37#include <linux/ioport.h>
41#include <linux/i2c.h> 38#include <linux/i2c.h>
42#include <linux/init.h> 39#include <linux/init.h>
40#include <linux/acpi.h>
43#include <asm/io.h> 41#include <asm/io.h>
44 42
45/* base address register in PCI config space */ 43/* base address register in PCI config space */
@@ -111,7 +109,7 @@ static int sis96x_transaction(int size)
111 /* check it again */ 109 /* check it again */
112 if (((temp = sis96x_read(SMB_CNT)) & 0x03) != 0x00) { 110 if (((temp = sis96x_read(SMB_CNT)) & 0x03) != 0x00) {
113 dev_dbg(&sis96x_adapter.dev, "Failed (0x%02x)\n", temp); 111 dev_dbg(&sis96x_adapter.dev, "Failed (0x%02x)\n", temp);
114 return -1; 112 return -EBUSY;
115 } else { 113 } else {
116 dev_dbg(&sis96x_adapter.dev, "Successful\n"); 114 dev_dbg(&sis96x_adapter.dev, "Successful\n");
117 } 115 }
@@ -136,19 +134,19 @@ static int sis96x_transaction(int size)
136 /* If the SMBus is still busy, we give up */ 134 /* If the SMBus is still busy, we give up */
137 if (timeout >= MAX_TIMEOUT) { 135 if (timeout >= MAX_TIMEOUT) {
138 dev_dbg(&sis96x_adapter.dev, "SMBus Timeout! (0x%02x)\n", temp); 136 dev_dbg(&sis96x_adapter.dev, "SMBus Timeout! (0x%02x)\n", temp);
139 result = -1; 137 result = -ETIMEDOUT;
140 } 138 }
141 139
142 /* device error - probably missing ACK */ 140 /* device error - probably missing ACK */
143 if (temp & 0x02) { 141 if (temp & 0x02) {
144 dev_dbg(&sis96x_adapter.dev, "Failed bus transaction!\n"); 142 dev_dbg(&sis96x_adapter.dev, "Failed bus transaction!\n");
145 result = -1; 143 result = -ENXIO;
146 } 144 }
147 145
148 /* bus collision */ 146 /* bus collision */
149 if (temp & 0x04) { 147 if (temp & 0x04) {
150 dev_dbg(&sis96x_adapter.dev, "Bus collision!\n"); 148 dev_dbg(&sis96x_adapter.dev, "Bus collision!\n");
151 result = -1; 149 result = -EIO;
152 } 150 }
153 151
154 /* Finish up by resetting the bus */ 152 /* Finish up by resetting the bus */
@@ -161,11 +159,12 @@ static int sis96x_transaction(int size)
161 return result; 159 return result;
162} 160}
163 161
164/* Return -1 on error. */ 162/* Return negative errno on error. */
165static s32 sis96x_access(struct i2c_adapter * adap, u16 addr, 163static s32 sis96x_access(struct i2c_adapter * adap, u16 addr,
166 unsigned short flags, char read_write, 164 unsigned short flags, char read_write,
167 u8 command, int size, union i2c_smbus_data * data) 165 u8 command, int size, union i2c_smbus_data * data)
168{ 166{
167 int status;
169 168
170 switch (size) { 169 switch (size) {
171 case I2C_SMBUS_QUICK: 170 case I2C_SMBUS_QUICK:
@@ -200,20 +199,14 @@ static s32 sis96x_access(struct i2c_adapter * adap, u16 addr,
200 SIS96x_PROC_CALL : SIS96x_WORD_DATA); 199 SIS96x_PROC_CALL : SIS96x_WORD_DATA);
201 break; 200 break;
202 201
203 case I2C_SMBUS_BLOCK_DATA:
204 /* TO DO: */
205 dev_info(&adap->dev, "SMBus block not implemented!\n");
206 return -1;
207 break;
208
209 default: 202 default:
210 dev_info(&adap->dev, "Unsupported I2C size\n"); 203 dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
211 return -1; 204 return -EOPNOTSUPP;
212 break;
213 } 205 }
214 206
215 if (sis96x_transaction(size)) 207 status = sis96x_transaction(size);
216 return -1; 208 if (status)
209 return status;
217 210
218 if ((size != SIS96x_PROC_CALL) && 211 if ((size != SIS96x_PROC_CALL) &&
219 ((read_write == I2C_SMBUS_WRITE) || (size == SIS96x_QUICK))) 212 ((read_write == I2C_SMBUS_WRITE) || (size == SIS96x_QUICK)))
@@ -249,7 +242,7 @@ static const struct i2c_algorithm smbus_algorithm = {
249static struct i2c_adapter sis96x_adapter = { 242static struct i2c_adapter sis96x_adapter = {
250 .owner = THIS_MODULE, 243 .owner = THIS_MODULE,
251 .id = I2C_HW_SMBUS_SIS96X, 244 .id = I2C_HW_SMBUS_SIS96X,
252 .class = I2C_CLASS_HWMON, 245 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
253 .algo = &smbus_algorithm, 246 .algo = &smbus_algorithm,
254}; 247};
255 248
@@ -286,6 +279,10 @@ static int __devinit sis96x_probe(struct pci_dev *dev,
286 dev_info(&dev->dev, "SiS96x SMBus base address: 0x%04x\n", 279 dev_info(&dev->dev, "SiS96x SMBus base address: 0x%04x\n",
287 sis96x_smbus_base); 280 sis96x_smbus_base);
288 281
282 retval = acpi_check_resource_conflict(&dev->resource[SIS96x_BAR]);
283 if (retval)
284 return retval;
285
289 /* Everything is happy, let's grab the memory and set things up. */ 286 /* Everything is happy, let's grab the memory and set things up. */
290 if (!request_region(sis96x_smbus_base, SMB_IOSIZE, 287 if (!request_region(sis96x_smbus_base, SMB_IOSIZE,
291 sis96x_driver.name)) { 288 sis96x_driver.name)) {
diff --git a/drivers/i2c/busses/i2c-stub.c b/drivers/i2c/busses/i2c-stub.c
index d08eeec53913..1b7b2af94036 100644
--- a/drivers/i2c/busses/i2c-stub.c
+++ b/drivers/i2c/busses/i2c-stub.c
@@ -43,7 +43,7 @@ struct stub_chip {
43 43
44static struct stub_chip *stub_chips; 44static struct stub_chip *stub_chips;
45 45
46/* Return -1 on error. */ 46/* Return negative errno on error. */
47static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags, 47static 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) 48 char read_write, u8 command, int size, union i2c_smbus_data * data)
49{ 49{
@@ -120,7 +120,7 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
120 120
121 default: 121 default:
122 dev_dbg(&adap->dev, "Unsupported I2C/SMBus command\n"); 122 dev_dbg(&adap->dev, "Unsupported I2C/SMBus command\n");
123 ret = -1; 123 ret = -EOPNOTSUPP;
124 break; 124 break;
125 } /* switch (size) */ 125 } /* switch (size) */
126 126
@@ -140,7 +140,7 @@ static const struct i2c_algorithm smbus_algorithm = {
140 140
141static struct i2c_adapter stub_adapter = { 141static struct i2c_adapter stub_adapter = {
142 .owner = THIS_MODULE, 142 .owner = THIS_MODULE,
143 .class = I2C_CLASS_HWMON, 143 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
144 .algo = &smbus_algorithm, 144 .algo = &smbus_algorithm,
145 .name = "SMBus stub driver", 145 .name = "SMBus stub driver",
146}; 146};
diff --git a/drivers/i2c/busses/i2c-taos-evm.c b/drivers/i2c/busses/i2c-taos-evm.c
index de9db49e54d9..224aa12ee7c8 100644
--- a/drivers/i2c/busses/i2c-taos-evm.c
+++ b/drivers/i2c/busses/i2c-taos-evm.c
@@ -96,9 +96,8 @@ static int taos_smbus_xfer(struct i2c_adapter *adapter, u16 addr,
96 sprintf(p, "$%02X", command); 96 sprintf(p, "$%02X", command);
97 break; 97 break;
98 default: 98 default:
99 dev_dbg(&adapter->dev, "Unsupported transaction size %d\n", 99 dev_warn(&adapter->dev, "Unsupported transaction %d\n", size);
100 size); 100 return -EOPNOTSUPP;
101 return -EINVAL;
102 } 101 }
103 102
104 /* Send the transaction to the TAOS EVM */ 103 /* Send the transaction to the TAOS EVM */
diff --git a/drivers/i2c/busses/i2c-via.c b/drivers/i2c/busses/i2c-via.c
index 61716f6b14dc..29cef0433f34 100644
--- a/drivers/i2c/busses/i2c-via.c
+++ b/drivers/i2c/busses/i2c-via.c
@@ -1,7 +1,4 @@
1/* 1/*
2 i2c-via.c - Part of lm_sensors, Linux kernel modules
3 for hardware monitoring
4
5 i2c Support for Via Technologies 82C586B South Bridge 2 i2c Support for Via Technologies 82C586B South Bridge
6 3
7 Copyright (c) 1998, 1999 Kyösti Mälkki <kmalkki@cc.hut.fi> 4 Copyright (c) 1998, 1999 Kyösti Mälkki <kmalkki@cc.hut.fi>
@@ -87,7 +84,7 @@ static struct i2c_algo_bit_data bit_data = {
87static struct i2c_adapter vt586b_adapter = { 84static struct i2c_adapter vt586b_adapter = {
88 .owner = THIS_MODULE, 85 .owner = THIS_MODULE,
89 .id = I2C_HW_B_VIA, 86 .id = I2C_HW_B_VIA,
90 .class = I2C_CLASS_HWMON, 87 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
91 .name = "VIA i2c", 88 .name = "VIA i2c",
92 .algo_data = &bit_data, 89 .algo_data = &bit_data,
93}; 90};
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 77b13d027f86..862eb352a2d9 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -1,6 +1,4 @@
1/* 1/*
2 i2c-viapro.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>, 2 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>,
5 Philip Edelbrock <phil@netroedge.com>, Kyösti Mälkki <kmalkki@cc.hut.fi>, 3 Philip Edelbrock <phil@netroedge.com>, Kyösti Mälkki <kmalkki@cc.hut.fi>,
6 Mark D. Studebaker <mdsxyz123@yahoo.com> 4 Mark D. Studebaker <mdsxyz123@yahoo.com>
@@ -50,6 +48,7 @@
50#include <linux/ioport.h> 48#include <linux/ioport.h>
51#include <linux/i2c.h> 49#include <linux/i2c.h>
52#include <linux/init.h> 50#include <linux/init.h>
51#include <linux/acpi.h>
53#include <asm/io.h> 52#include <asm/io.h>
54 53
55static struct pci_dev *vt596_pdev; 54static struct pci_dev *vt596_pdev;
@@ -152,7 +151,7 @@ static int vt596_transaction(u8 size)
152 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { 151 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) {
153 dev_err(&vt596_adapter.dev, "SMBus reset failed! " 152 dev_err(&vt596_adapter.dev, "SMBus reset failed! "
154 "(0x%02x)\n", temp); 153 "(0x%02x)\n", temp);
155 return -1; 154 return -EBUSY;
156 } 155 }
157 } 156 }
158 157
@@ -167,24 +166,24 @@ static int vt596_transaction(u8 size)
167 166
168 /* If the SMBus is still busy, we give up */ 167 /* If the SMBus is still busy, we give up */
169 if (timeout >= MAX_TIMEOUT) { 168 if (timeout >= MAX_TIMEOUT) {
170 result = -1; 169 result = -ETIMEDOUT;
171 dev_err(&vt596_adapter.dev, "SMBus timeout!\n"); 170 dev_err(&vt596_adapter.dev, "SMBus timeout!\n");
172 } 171 }
173 172
174 if (temp & 0x10) { 173 if (temp & 0x10) {
175 result = -1; 174 result = -EIO;
176 dev_err(&vt596_adapter.dev, "Transaction failed (0x%02x)\n", 175 dev_err(&vt596_adapter.dev, "Transaction failed (0x%02x)\n",
177 size); 176 size);
178 } 177 }
179 178
180 if (temp & 0x08) { 179 if (temp & 0x08) {
181 result = -1; 180 result = -EIO;
182 dev_err(&vt596_adapter.dev, "SMBus collision!\n"); 181 dev_err(&vt596_adapter.dev, "SMBus collision!\n");
183 } 182 }
184 183
185 if (temp & 0x04) { 184 if (temp & 0x04) {
186 int read = inb_p(SMBHSTADD) & 0x01; 185 int read = inb_p(SMBHSTADD) & 0x01;
187 result = -1; 186 result = -ENXIO;
188 /* The quick and receive byte commands are used to probe 187 /* The quick and receive byte commands are used to probe
189 for chips, so errors are expected, and we don't want 188 for chips, so errors are expected, and we don't want
190 to frighten the user. */ 189 to frighten the user. */
@@ -202,12 +201,13 @@ static int vt596_transaction(u8 size)
202 return result; 201 return result;
203} 202}
204 203
205/* Return -1 on error, 0 on success */ 204/* Return negative errno on error, 0 on success */
206static s32 vt596_access(struct i2c_adapter *adap, u16 addr, 205static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
207 unsigned short flags, char read_write, u8 command, 206 unsigned short flags, char read_write, u8 command,
208 int size, union i2c_smbus_data *data) 207 int size, union i2c_smbus_data *data)
209{ 208{
210 int i; 209 int i;
210 int status;
211 211
212 switch (size) { 212 switch (size) {
213 case I2C_SMBUS_QUICK: 213 case I2C_SMBUS_QUICK:
@@ -258,8 +258,9 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
258 258
259 outb_p(((addr & 0x7f) << 1) | read_write, SMBHSTADD); 259 outb_p(((addr & 0x7f) << 1) | read_write, SMBHSTADD);
260 260
261 if (vt596_transaction(size)) /* Error in transaction */ 261 status = vt596_transaction(size);
262 return -1; 262 if (status)
263 return status;
263 264
264 if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK)) 265 if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK))
265 return 0; 266 return 0;
@@ -285,9 +286,9 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
285 return 0; 286 return 0;
286 287
287exit_unsupported: 288exit_unsupported:
288 dev_warn(&vt596_adapter.dev, "Unsupported command invoked! (0x%02x)\n", 289 dev_warn(&vt596_adapter.dev, "Unsupported transaction %d\n",
289 size); 290 size);
290 return -1; 291 return -EOPNOTSUPP;
291} 292}
292 293
293static u32 vt596_func(struct i2c_adapter *adapter) 294static u32 vt596_func(struct i2c_adapter *adapter)
@@ -309,7 +310,7 @@ static const struct i2c_algorithm smbus_algorithm = {
309static struct i2c_adapter vt596_adapter = { 310static struct i2c_adapter vt596_adapter = {
310 .owner = THIS_MODULE, 311 .owner = THIS_MODULE,
311 .id = I2C_HW_SMBUS_VIA2, 312 .id = I2C_HW_SMBUS_VIA2,
312 .class = I2C_CLASS_HWMON, 313 .class = I2C_CLASS_HWMON | I2C_CLASS_SPD,
313 .algo = &smbus_algorithm, 314 .algo = &smbus_algorithm,
314}; 315};
315 316
@@ -354,6 +355,10 @@ static int __devinit vt596_probe(struct pci_dev *pdev,
354 } 355 }
355 356
356found: 357found:
358 error = acpi_check_region(vt596_smba, 8, vt596_driver.name);
359 if (error)
360 return error;
361
357 if (!request_region(vt596_smba, 8, vt596_driver.name)) { 362 if (!request_region(vt596_smba, 8, vt596_driver.name)) {
358 dev_err(&pdev->dev, "SMBus region 0x%x already in use!\n", 363 dev_err(&pdev->dev, "SMBus region 0x%x already in use!\n",
359 vt596_smba); 364 vt596_smba);
diff --git a/drivers/i2c/busses/i2c-voodoo3.c b/drivers/i2c/busses/i2c-voodoo3.c
index 88a3447e11e1..1d4ae26ba73d 100644
--- a/drivers/i2c/busses/i2c-voodoo3.c
+++ b/drivers/i2c/busses/i2c-voodoo3.c
@@ -1,6 +1,4 @@
1/* 1/*
2 voodoo3.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>, 2 Copyright (c) 1998, 1999 Frodo Looijaard <frodol@dds.nl>,
5 Philip Edelbrock <phil@netroedge.com>, 3 Philip Edelbrock <phil@netroedge.com>,
6 Ralph Metzler <rjkm@thp.uni-koeln.de>, and 4 Ralph Metzler <rjkm@thp.uni-koeln.de>, and
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index 61abe0f33255..ed794b145a11 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -442,7 +442,7 @@ static __init struct scx200_acb_iface *scx200_create_iface(const char *text,
442 adapter->owner = THIS_MODULE; 442 adapter->owner = THIS_MODULE;
443 adapter->id = I2C_HW_SMBUS_SCX200; 443 adapter->id = I2C_HW_SMBUS_SCX200;
444 adapter->algo = &scx200_acb_algorithm; 444 adapter->algo = &scx200_acb_algorithm;
445 adapter->class = I2C_CLASS_HWMON; 445 adapter->class = I2C_CLASS_HWMON | I2C_CLASS_SPD;
446 adapter->dev.parent = dev; 446 adapter->dev.parent = dev;
447 447
448 mutex_init(&iface->mutex); 448 mutex_init(&iface->mutex);
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index 2da2edfa68ec..a95cb9465d65 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -14,6 +14,32 @@ config DS1682
14 This driver can also be built as a module. If so, the module 14 This driver can also be built as a module. If so, the module
15 will be called ds1682. 15 will be called ds1682.
16 16
17config AT24
18 tristate "EEPROMs from most vendors"
19 depends on SYSFS && EXPERIMENTAL
20 help
21 Enable this driver to get read/write support to most I2C EEPROMs,
22 after you configure the driver to know about each EEPROM on
23 your target board. Use these generic chip names, instead of
24 vendor-specific ones like at24c64 or 24lc02:
25
26 24c00, 24c01, 24c02, spd (readonly 24c02), 24c04, 24c08,
27 24c16, 24c32, 24c64, 24c128, 24c256, 24c512, 24c1024
28
29 Unless you like data loss puzzles, always be sure that any chip
30 you configure as a 24c32 (32 kbit) or larger is NOT really a
31 24c16 (16 kbit) or smaller, and vice versa. Marking the chip
32 as read-only won't help recover from this. Also, if your chip
33 has any software write-protect mechanism you may want to review the
34 code to make sure this driver won't turn it on by accident.
35
36 If you use this with an SMBus adapter instead of an I2C adapter,
37 full functionality is not available. Only smaller devices are
38 supported (24c16 and below, max 4 kByte).
39
40 This driver can also be built as a module. If so, the module
41 will be called at24.
42
17config SENSORS_EEPROM 43config SENSORS_EEPROM
18 tristate "EEPROM reader" 44 tristate "EEPROM reader"
19 depends on EXPERIMENTAL 45 depends on EXPERIMENTAL
@@ -26,8 +52,8 @@ config SENSORS_EEPROM
26 will be called eeprom. 52 will be called eeprom.
27 53
28config SENSORS_PCF8574 54config SENSORS_PCF8574
29 tristate "Philips PCF8574 and PCF8574A" 55 tristate "Philips PCF8574 and PCF8574A (DEPRECATED)"
30 depends on EXPERIMENTAL 56 depends on EXPERIMENTAL && GPIO_PCF857X = "n"
31 default n 57 default n
32 help 58 help
33 If you say yes here you get support for Philips PCF8574 and 59 If you say yes here you get support for Philips PCF8574 and
@@ -36,12 +62,16 @@ config SENSORS_PCF8574
36 This driver can also be built as a module. If so, the module 62 This driver can also be built as a module. If so, the module
37 will be called pcf8574. 63 will be called pcf8574.
38 64
65 This driver is deprecated and will be dropped soon. Use
66 drivers/gpio/pcf857x.c instead.
67
39 These devices are hard to detect and rarely found on mainstream 68 These devices are hard to detect and rarely found on mainstream
40 hardware. If unsure, say N. 69 hardware. If unsure, say N.
41 70
42config PCF8575 71config PCF8575
43 tristate "Philips PCF8575" 72 tristate "Philips PCF8575 (DEPRECATED)"
44 default n 73 default n
74 depends on GPIO_PCF857X = "n"
45 help 75 help
46 If you say yes here you get support for Philips PCF8575 chip. 76 If you say yes here you get support for Philips PCF8575 chip.
47 This chip is a 16-bit I/O expander for the I2C bus. Several other 77 This chip is a 16-bit I/O expander for the I2C bus. Several other
@@ -50,12 +80,15 @@ config PCF8575
50 This driver can also be built as a module. If so, the module 80 This driver can also be built as a module. If so, the module
51 will be called pcf8575. 81 will be called pcf8575.
52 82
83 This driver is deprecated and will be dropped soon. Use
84 drivers/gpio/pcf857x.c instead.
85
53 This device is hard to detect and is rarely found on mainstream 86 This device is hard to detect and is rarely found on mainstream
54 hardware. If unsure, say N. 87 hardware. If unsure, say N.
55 88
56config SENSORS_PCA9539 89config SENSORS_PCA9539
57 tristate "Philips PCA9539 16-bit I/O port (DEPRECATED)" 90 tristate "Philips PCA9539 16-bit I/O port (DEPRECATED)"
58 depends on EXPERIMENTAL && GPIO_PCA9539 = "n" 91 depends on EXPERIMENTAL && GPIO_PCA953X = "n"
59 help 92 help
60 If you say yes here you get support for the Philips PCA9539 93 If you say yes here you get support for the Philips PCA9539
61 16-bit I/O port. 94 16-bit I/O port.
@@ -64,7 +97,7 @@ config SENSORS_PCA9539
64 will be called pca9539. 97 will be called pca9539.
65 98
66 This driver is deprecated and will be dropped soon. Use 99 This driver is deprecated and will be dropped soon. Use
67 drivers/gpio/pca9539.c instead. 100 drivers/gpio/pca953x.c instead.
68 101
69config SENSORS_PCF8591 102config SENSORS_PCF8591
70 tristate "Philips PCF8591" 103 tristate "Philips PCF8591"
@@ -93,7 +126,7 @@ config ISP1301_OMAP
93 126
94config TPS65010 127config TPS65010
95 tristate "TPS6501x Power Management chips" 128 tristate "TPS6501x Power Management chips"
96 depends on HAVE_GPIO_LIB 129 depends on GPIOLIB
97 default y if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_OSK 130 default y if MACH_OMAP_H2 || MACH_OMAP_H3 || MACH_OMAP_OSK
98 help 131 help
99 If you say yes here you get support for the TPS6501x series of 132 If you say yes here you get support for the TPS6501x series of
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile
index e47aca0ca5ae..39e3e69ed125 100644
--- a/drivers/i2c/chips/Makefile
+++ b/drivers/i2c/chips/Makefile
@@ -10,6 +10,7 @@
10# 10#
11 11
12obj-$(CONFIG_DS1682) += ds1682.o 12obj-$(CONFIG_DS1682) += ds1682.o
13obj-$(CONFIG_AT24) += at24.o
13obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o 14obj-$(CONFIG_SENSORS_EEPROM) += eeprom.o
14obj-$(CONFIG_SENSORS_MAX6875) += max6875.o 15obj-$(CONFIG_SENSORS_MAX6875) += max6875.o
15obj-$(CONFIG_SENSORS_PCA9539) += pca9539.o 16obj-$(CONFIG_SENSORS_PCA9539) += pca9539.o
diff --git a/drivers/i2c/chips/at24.c b/drivers/i2c/chips/at24.c
new file mode 100644
index 000000000000..e764c94f3e3d
--- /dev/null
+++ b/drivers/i2c/chips/at24.c
@@ -0,0 +1,583 @@
1/*
2 * at24.c - handle most I2C EEPROMs
3 *
4 * Copyright (C) 2005-2007 David Brownell
5 * Copyright (C) 2008 Wolfram Sang, Pengutronix
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/slab.h>
16#include <linux/delay.h>
17#include <linux/mutex.h>
18#include <linux/sysfs.h>
19#include <linux/mod_devicetable.h>
20#include <linux/log2.h>
21#include <linux/bitops.h>
22#include <linux/jiffies.h>
23#include <linux/i2c.h>
24#include <linux/i2c/at24.h>
25
26/*
27 * I2C EEPROMs from most vendors are inexpensive and mostly interchangeable.
28 * Differences between different vendor product lines (like Atmel AT24C or
29 * MicroChip 24LC, etc) won't much matter for typical read/write access.
30 * There are also I2C RAM chips, likewise interchangeable. One example
31 * would be the PCF8570, which acts like a 24c02 EEPROM (256 bytes).
32 *
33 * However, misconfiguration can lose data. "Set 16-bit memory address"
34 * to a part with 8-bit addressing will overwrite data. Writing with too
35 * big a page size also loses data. And it's not safe to assume that the
36 * conventional addresses 0x50..0x57 only hold eeproms; a PCF8563 RTC
37 * uses 0x51, for just one example.
38 *
39 * Accordingly, explicit board-specific configuration data should be used
40 * in almost all cases. (One partial exception is an SMBus used to access
41 * "SPD" data for DRAM sticks. Those only use 24c02 EEPROMs.)
42 *
43 * So this driver uses "new style" I2C driver binding, expecting to be
44 * told what devices exist. That may be in arch/X/mach-Y/board-Z.c or
45 * similar kernel-resident tables; or, configuration data coming from
46 * a bootloader.
47 *
48 * Other than binding model, current differences from "eeprom" driver are
49 * that this one handles write access and isn't restricted to 24c02 devices.
50 * It also handles larger devices (32 kbit and up) with two-byte addresses,
51 * which won't work on pure SMBus systems.
52 */
53
54struct at24_data {
55 struct at24_platform_data chip;
56 bool use_smbus;
57
58 /*
59 * Lock protects against activities from other Linux tasks,
60 * but not from changes by other I2C masters.
61 */
62 struct mutex lock;
63 struct bin_attribute bin;
64
65 u8 *writebuf;
66 unsigned write_max;
67 unsigned num_addresses;
68
69 /*
70 * Some chips tie up multiple I2C addresses; dummy devices reserve
71 * them for us, and we'll use them with SMBus calls.
72 */
73 struct i2c_client *client[];
74};
75
76/*
77 * This parameter is to help this driver avoid blocking other drivers out
78 * of I2C for potentially troublesome amounts of time. With a 100 kHz I2C
79 * clock, one 256 byte read takes about 1/43 second which is excessive;
80 * but the 1/170 second it takes at 400 kHz may be quite reasonable; and
81 * at 1 MHz (Fm+) a 1/430 second delay could easily be invisible.
82 *
83 * This value is forced to be a power of two so that writes align on pages.
84 */
85static unsigned io_limit = 128;
86module_param(io_limit, uint, 0);
87MODULE_PARM_DESC(io_limit, "Maximum bytes per I/O (default 128)");
88
89/*
90 * Specs often allow 5 msec for a page write, sometimes 20 msec;
91 * it's important to recover from write timeouts.
92 */
93static unsigned write_timeout = 25;
94module_param(write_timeout, uint, 0);
95MODULE_PARM_DESC(write_timeout, "Time (in ms) to try writes (default 25)");
96
97#define AT24_SIZE_BYTELEN 5
98#define AT24_SIZE_FLAGS 8
99
100#define AT24_BITMASK(x) (BIT(x) - 1)
101
102/* create non-zero magic value for given eeprom parameters */
103#define AT24_DEVICE_MAGIC(_len, _flags) \
104 ((1 << AT24_SIZE_FLAGS | (_flags)) \
105 << AT24_SIZE_BYTELEN | ilog2(_len))
106
107static const struct i2c_device_id at24_ids[] = {
108 /* needs 8 addresses as A0-A2 are ignored */
109 { "24c00", AT24_DEVICE_MAGIC(128 / 8, AT24_FLAG_TAKE8ADDR) },
110 /* old variants can't be handled with this generic entry! */
111 { "24c01", AT24_DEVICE_MAGIC(1024 / 8, 0) },
112 { "24c02", AT24_DEVICE_MAGIC(2048 / 8, 0) },
113 /* spd is a 24c02 in memory DIMMs */
114 { "spd", AT24_DEVICE_MAGIC(2048 / 8,
115 AT24_FLAG_READONLY | AT24_FLAG_IRUGO) },
116 { "24c04", AT24_DEVICE_MAGIC(4096 / 8, 0) },
117 /* 24rf08 quirk is handled at i2c-core */
118 { "24c08", AT24_DEVICE_MAGIC(8192 / 8, 0) },
119 { "24c16", AT24_DEVICE_MAGIC(16384 / 8, 0) },
120 { "24c32", AT24_DEVICE_MAGIC(32768 / 8, AT24_FLAG_ADDR16) },
121 { "24c64", AT24_DEVICE_MAGIC(65536 / 8, AT24_FLAG_ADDR16) },
122 { "24c128", AT24_DEVICE_MAGIC(131072 / 8, AT24_FLAG_ADDR16) },
123 { "24c256", AT24_DEVICE_MAGIC(262144 / 8, AT24_FLAG_ADDR16) },
124 { "24c512", AT24_DEVICE_MAGIC(524288 / 8, AT24_FLAG_ADDR16) },
125 { "24c1024", AT24_DEVICE_MAGIC(1048576 / 8, AT24_FLAG_ADDR16) },
126 { "at24", 0 },
127 { /* END OF LIST */ }
128};
129MODULE_DEVICE_TABLE(i2c, at24_ids);
130
131/*-------------------------------------------------------------------------*/
132
133/*
134 * This routine supports chips which consume multiple I2C addresses. It
135 * computes the addressing information to be used for a given r/w request.
136 * Assumes that sanity checks for offset happened at sysfs-layer.
137 */
138static struct i2c_client *at24_translate_offset(struct at24_data *at24,
139 unsigned *offset)
140{
141 unsigned i;
142
143 if (at24->chip.flags & AT24_FLAG_ADDR16) {
144 i = *offset >> 16;
145 *offset &= 0xffff;
146 } else {
147 i = *offset >> 8;
148 *offset &= 0xff;
149 }
150
151 return at24->client[i];
152}
153
154static ssize_t at24_eeprom_read(struct at24_data *at24, char *buf,
155 unsigned offset, size_t count)
156{
157 struct i2c_msg msg[2];
158 u8 msgbuf[2];
159 struct i2c_client *client;
160 int status, i;
161
162 memset(msg, 0, sizeof(msg));
163
164 /*
165 * REVISIT some multi-address chips don't rollover page reads to
166 * the next slave address, so we may need to truncate the count.
167 * Those chips might need another quirk flag.
168 *
169 * If the real hardware used four adjacent 24c02 chips and that
170 * were misconfigured as one 24c08, that would be a similar effect:
171 * one "eeprom" file not four, but larger reads would fail when
172 * they crossed certain pages.
173 */
174
175 /*
176 * Slave address and byte offset derive from the offset. Always
177 * set the byte address; on a multi-master board, another master
178 * may have changed the chip's "current" address pointer.
179 */
180 client = at24_translate_offset(at24, &offset);
181
182 if (count > io_limit)
183 count = io_limit;
184
185 /* Smaller eeproms can work given some SMBus extension calls */
186 if (at24->use_smbus) {
187 if (count > I2C_SMBUS_BLOCK_MAX)
188 count = I2C_SMBUS_BLOCK_MAX;
189 status = i2c_smbus_read_i2c_block_data(client, offset,
190 count, buf);
191 dev_dbg(&client->dev, "smbus read %zd@%d --> %d\n",
192 count, offset, status);
193 return (status < 0) ? -EIO : status;
194 }
195
196 /*
197 * When we have a better choice than SMBus calls, use a combined
198 * I2C message. Write address; then read up to io_limit data bytes.
199 * Note that read page rollover helps us here (unlike writes).
200 * msgbuf is u8 and will cast to our needs.
201 */
202 i = 0;
203 if (at24->chip.flags & AT24_FLAG_ADDR16)
204 msgbuf[i++] = offset >> 8;
205 msgbuf[i++] = offset;
206
207 msg[0].addr = client->addr;
208 msg[0].buf = msgbuf;
209 msg[0].len = i;
210
211 msg[1].addr = client->addr;
212 msg[1].flags = I2C_M_RD;
213 msg[1].buf = buf;
214 msg[1].len = count;
215
216 status = i2c_transfer(client->adapter, msg, 2);
217 dev_dbg(&client->dev, "i2c read %zd@%d --> %d\n",
218 count, offset, status);
219
220 if (status == 2)
221 return count;
222 else if (status >= 0)
223 return -EIO;
224 else
225 return status;
226}
227
228static ssize_t at24_bin_read(struct kobject *kobj, struct bin_attribute *attr,
229 char *buf, loff_t off, size_t count)
230{
231 struct at24_data *at24;
232 ssize_t retval = 0;
233
234 at24 = dev_get_drvdata(container_of(kobj, struct device, kobj));
235
236 if (unlikely(!count))
237 return count;
238
239 /*
240 * Read data from chip, protecting against concurrent updates
241 * from this host, but not from other I2C masters.
242 */
243 mutex_lock(&at24->lock);
244
245 while (count) {
246 ssize_t status;
247
248 status = at24_eeprom_read(at24, buf, off, count);
249 if (status <= 0) {
250 if (retval == 0)
251 retval = status;
252 break;
253 }
254 buf += status;
255 off += status;
256 count -= status;
257 retval += status;
258 }
259
260 mutex_unlock(&at24->lock);
261
262 return retval;
263}
264
265
266/*
267 * REVISIT: export at24_bin{read,write}() to let other kernel code use
268 * eeprom data. For example, it might hold a board's Ethernet address, or
269 * board-specific calibration data generated on the manufacturing floor.
270 */
271
272
273/*
274 * Note that if the hardware write-protect pin is pulled high, the whole
275 * chip is normally write protected. But there are plenty of product
276 * variants here, including OTP fuses and partial chip protect.
277 *
278 * We only use page mode writes; the alternative is sloooow. This routine
279 * writes at most one page.
280 */
281static ssize_t at24_eeprom_write(struct at24_data *at24, char *buf,
282 unsigned offset, size_t count)
283{
284 struct i2c_client *client;
285 struct i2c_msg msg;
286 ssize_t status;
287 unsigned long timeout, write_time;
288 unsigned next_page;
289
290 /* Get corresponding I2C address and adjust offset */
291 client = at24_translate_offset(at24, &offset);
292
293 /* write_max is at most a page */
294 if (count > at24->write_max)
295 count = at24->write_max;
296
297 /* Never roll over backwards, to the start of this page */
298 next_page = roundup(offset + 1, at24->chip.page_size);
299 if (offset + count > next_page)
300 count = next_page - offset;
301
302 /* If we'll use I2C calls for I/O, set up the message */
303 if (!at24->use_smbus) {
304 int i = 0;
305
306 msg.addr = client->addr;
307 msg.flags = 0;
308
309 /* msg.buf is u8 and casts will mask the values */
310 msg.buf = at24->writebuf;
311 if (at24->chip.flags & AT24_FLAG_ADDR16)
312 msg.buf[i++] = offset >> 8;
313
314 msg.buf[i++] = offset;
315 memcpy(&msg.buf[i], buf, count);
316 msg.len = i + count;
317 }
318
319 /*
320 * Writes fail if the previous one didn't complete yet. We may
321 * loop a few times until this one succeeds, waiting at least
322 * long enough for one entire page write to work.
323 */
324 timeout = jiffies + msecs_to_jiffies(write_timeout);
325 do {
326 write_time = jiffies;
327 if (at24->use_smbus) {
328 status = i2c_smbus_write_i2c_block_data(client,
329 offset, count, buf);
330 if (status == 0)
331 status = count;
332 } else {
333 status = i2c_transfer(client->adapter, &msg, 1);
334 if (status == 1)
335 status = count;
336 }
337 dev_dbg(&client->dev, "write %zd@%d --> %zd (%ld)\n",
338 count, offset, status, jiffies);
339
340 if (status == count)
341 return count;
342
343 /* REVISIT: at HZ=100, this is sloooow */
344 msleep(1);
345 } while (time_before(write_time, timeout));
346
347 return -ETIMEDOUT;
348}
349
350static ssize_t at24_bin_write(struct kobject *kobj, struct bin_attribute *attr,
351 char *buf, loff_t off, size_t count)
352{
353 struct at24_data *at24;
354 ssize_t retval = 0;
355
356 at24 = dev_get_drvdata(container_of(kobj, struct device, kobj));
357
358 if (unlikely(!count))
359 return count;
360
361 /*
362 * Write data to chip, protecting against concurrent updates
363 * from this host, but not from other I2C masters.
364 */
365 mutex_lock(&at24->lock);
366
367 while (count) {
368 ssize_t status;
369
370 status = at24_eeprom_write(at24, buf, off, count);
371 if (status <= 0) {
372 if (retval == 0)
373 retval = status;
374 break;
375 }
376 buf += status;
377 off += status;
378 count -= status;
379 retval += status;
380 }
381
382 mutex_unlock(&at24->lock);
383
384 return retval;
385}
386
387/*-------------------------------------------------------------------------*/
388
389static int at24_probe(struct i2c_client *client, const struct i2c_device_id *id)
390{
391 struct at24_platform_data chip;
392 bool writable;
393 bool use_smbus = false;
394 struct at24_data *at24;
395 int err;
396 unsigned i, num_addresses;
397 kernel_ulong_t magic;
398
399 if (client->dev.platform_data) {
400 chip = *(struct at24_platform_data *)client->dev.platform_data;
401 } else {
402 if (!id->driver_data) {
403 err = -ENODEV;
404 goto err_out;
405 }
406 magic = id->driver_data;
407 chip.byte_len = BIT(magic & AT24_BITMASK(AT24_SIZE_BYTELEN));
408 magic >>= AT24_SIZE_BYTELEN;
409 chip.flags = magic & AT24_BITMASK(AT24_SIZE_FLAGS);
410 /*
411 * This is slow, but we can't know all eeproms, so we better
412 * play safe. Specifying custom eeprom-types via platform_data
413 * is recommended anyhow.
414 */
415 chip.page_size = 1;
416 }
417
418 if (!is_power_of_2(chip.byte_len))
419 dev_warn(&client->dev,
420 "byte_len looks suspicious (no power of 2)!\n");
421 if (!is_power_of_2(chip.page_size))
422 dev_warn(&client->dev,
423 "page_size looks suspicious (no power of 2)!\n");
424
425 /* Use I2C operations unless we're stuck with SMBus extensions. */
426 if (!i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) {
427 if (chip.flags & AT24_FLAG_ADDR16) {
428 err = -EPFNOSUPPORT;
429 goto err_out;
430 }
431 if (!i2c_check_functionality(client->adapter,
432 I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
433 err = -EPFNOSUPPORT;
434 goto err_out;
435 }
436 use_smbus = true;
437 }
438
439 if (chip.flags & AT24_FLAG_TAKE8ADDR)
440 num_addresses = 8;
441 else
442 num_addresses = DIV_ROUND_UP(chip.byte_len,
443 (chip.flags & AT24_FLAG_ADDR16) ? 65536 : 256);
444
445 at24 = kzalloc(sizeof(struct at24_data) +
446 num_addresses * sizeof(struct i2c_client *), GFP_KERNEL);
447 if (!at24) {
448 err = -ENOMEM;
449 goto err_out;
450 }
451
452 mutex_init(&at24->lock);
453 at24->use_smbus = use_smbus;
454 at24->chip = chip;
455 at24->num_addresses = num_addresses;
456
457 /*
458 * Export the EEPROM bytes through sysfs, since that's convenient.
459 * By default, only root should see the data (maybe passwords etc)
460 */
461 at24->bin.attr.name = "eeprom";
462 at24->bin.attr.mode = chip.flags & AT24_FLAG_IRUGO ? S_IRUGO : S_IRUSR;
463 at24->bin.attr.owner = THIS_MODULE;
464 at24->bin.read = at24_bin_read;
465 at24->bin.size = chip.byte_len;
466
467 writable = !(chip.flags & AT24_FLAG_READONLY);
468 if (writable) {
469 if (!use_smbus || i2c_check_functionality(client->adapter,
470 I2C_FUNC_SMBUS_WRITE_I2C_BLOCK)) {
471
472 unsigned write_max = chip.page_size;
473
474 at24->bin.write = at24_bin_write;
475 at24->bin.attr.mode |= S_IWUSR;
476
477 if (write_max > io_limit)
478 write_max = io_limit;
479 if (use_smbus && write_max > I2C_SMBUS_BLOCK_MAX)
480 write_max = I2C_SMBUS_BLOCK_MAX;
481 at24->write_max = write_max;
482
483 /* buffer (data + address at the beginning) */
484 at24->writebuf = kmalloc(write_max + 2, GFP_KERNEL);
485 if (!at24->writebuf) {
486 err = -ENOMEM;
487 goto err_struct;
488 }
489 } else {
490 dev_warn(&client->dev,
491 "cannot write due to controller restrictions.");
492 }
493 }
494
495 at24->client[0] = client;
496
497 /* use dummy devices for multiple-address chips */
498 for (i = 1; i < num_addresses; i++) {
499 at24->client[i] = i2c_new_dummy(client->adapter,
500 client->addr + i);
501 if (!at24->client[i]) {
502 dev_err(&client->dev, "address 0x%02x unavailable\n",
503 client->addr + i);
504 err = -EADDRINUSE;
505 goto err_clients;
506 }
507 }
508
509 err = sysfs_create_bin_file(&client->dev.kobj, &at24->bin);
510 if (err)
511 goto err_clients;
512
513 i2c_set_clientdata(client, at24);
514
515 dev_info(&client->dev, "%Zd byte %s EEPROM %s\n",
516 at24->bin.size, client->name,
517 writable ? "(writable)" : "(read-only)");
518 dev_dbg(&client->dev,
519 "page_size %d, num_addresses %d, write_max %d%s\n",
520 chip.page_size, num_addresses,
521 at24->write_max,
522 use_smbus ? ", use_smbus" : "");
523
524 return 0;
525
526err_clients:
527 for (i = 1; i < num_addresses; i++)
528 if (at24->client[i])
529 i2c_unregister_device(at24->client[i]);
530
531 kfree(at24->writebuf);
532err_struct:
533 kfree(at24);
534err_out:
535 dev_dbg(&client->dev, "probe error %d\n", err);
536 return err;
537}
538
539static int __devexit at24_remove(struct i2c_client *client)
540{
541 struct at24_data *at24;
542 int i;
543
544 at24 = i2c_get_clientdata(client);
545 sysfs_remove_bin_file(&client->dev.kobj, &at24->bin);
546
547 for (i = 1; i < at24->num_addresses; i++)
548 i2c_unregister_device(at24->client[i]);
549
550 kfree(at24->writebuf);
551 kfree(at24);
552 i2c_set_clientdata(client, NULL);
553 return 0;
554}
555
556/*-------------------------------------------------------------------------*/
557
558static struct i2c_driver at24_driver = {
559 .driver = {
560 .name = "at24",
561 .owner = THIS_MODULE,
562 },
563 .probe = at24_probe,
564 .remove = __devexit_p(at24_remove),
565 .id_table = at24_ids,
566};
567
568static int __init at24_init(void)
569{
570 io_limit = rounddown_pow_of_two(io_limit);
571 return i2c_add_driver(&at24_driver);
572}
573module_init(at24_init);
574
575static void __exit at24_exit(void)
576{
577 i2c_del_driver(&at24_driver);
578}
579module_exit(at24_exit);
580
581MODULE_DESCRIPTION("Driver for most I2C EEPROMs");
582MODULE_AUTHOR("David Brownell and Wolfram Sang");
583MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c
index 7dee001e5133..2c27193aeaa0 100644
--- a/drivers/i2c/chips/eeprom.c
+++ b/drivers/i2c/chips/eeprom.c
@@ -1,15 +1,9 @@
1/* 1/*
2 eeprom.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl> and 2 Copyright (C) 1998, 1999 Frodo Looijaard <frodol@dds.nl> and
5 Philip Edelbrock <phil@netroedge.com> 3 Philip Edelbrock <phil@netroedge.com>
6 Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com> 4 Copyright (C) 2003 Greg Kroah-Hartman <greg@kroah.com>
7 Copyright (C) 2003 IBM Corp. 5 Copyright (C) 2003 IBM Corp.
8 6 Copyright (C) 2004 Jean Delvare <khali@linux-fr.org>
9 2004-01-16 Jean Delvare <khali@linux-fr.org>
10 Divide the eeprom in 32-byte (arbitrary) slices. This significantly
11 speeds sensors up, as well as various scripts using the eeprom
12 module.
13 7
14 This program is free software; you can redistribute it and/or modify 8 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by 9 it under the terms of the GNU General Public License as published by
@@ -53,7 +47,6 @@ enum eeprom_nature {
53 47
54/* Each client has this additional data */ 48/* Each client has this additional data */
55struct eeprom_data { 49struct eeprom_data {
56 struct i2c_client client;
57 struct mutex update_lock; 50 struct mutex update_lock;
58 u8 valid; /* bitfield, bit!=0 if slice is valid */ 51 u8 valid; /* bitfield, bit!=0 if slice is valid */
59 unsigned long last_updated[8]; /* In jiffies, 8 slices */ 52 unsigned long last_updated[8]; /* In jiffies, 8 slices */
@@ -62,23 +55,10 @@ struct eeprom_data {
62}; 55};
63 56
64 57
65static int eeprom_attach_adapter(struct i2c_adapter *adapter);
66static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind);
67static int eeprom_detach_client(struct i2c_client *client);
68
69/* This is the driver that will be inserted */
70static struct i2c_driver eeprom_driver = {
71 .driver = {
72 .name = "eeprom",
73 },
74 .attach_adapter = eeprom_attach_adapter,
75 .detach_client = eeprom_detach_client,
76};
77
78static void eeprom_update_client(struct i2c_client *client, u8 slice) 58static void eeprom_update_client(struct i2c_client *client, u8 slice)
79{ 59{
80 struct eeprom_data *data = i2c_get_clientdata(client); 60 struct eeprom_data *data = i2c_get_clientdata(client);
81 int i, j; 61 int i;
82 62
83 mutex_lock(&data->update_lock); 63 mutex_lock(&data->update_lock);
84 64
@@ -93,15 +73,12 @@ static void eeprom_update_client(struct i2c_client *client, u8 slice)
93 != 32) 73 != 32)
94 goto exit; 74 goto exit;
95 } else { 75 } else {
96 if (i2c_smbus_write_byte(client, slice << 5)) { 76 for (i = slice << 5; i < (slice + 1) << 5; i += 2) {
97 dev_dbg(&client->dev, "eeprom read start has failed!\n"); 77 int word = i2c_smbus_read_word_data(client, i);
98 goto exit; 78 if (word < 0)
99 }
100 for (i = slice << 5; i < (slice + 1) << 5; i++) {
101 j = i2c_smbus_read_byte(client);
102 if (j < 0)
103 goto exit; 79 goto exit;
104 data->data[i] = (u8) j; 80 data->data[i] = word & 0xff;
81 data->data[i + 1] = word >> 8;
105 } 82 }
106 } 83 }
107 data->last_updated[slice] = jiffies; 84 data->last_updated[slice] = jiffies;
@@ -157,98 +134,108 @@ static struct bin_attribute eeprom_attr = {
157 .read = eeprom_read, 134 .read = eeprom_read,
158}; 135};
159 136
160static int eeprom_attach_adapter(struct i2c_adapter *adapter) 137/* Return 0 if detection is successful, -ENODEV otherwise */
138static int eeprom_detect(struct i2c_client *client, int kind,
139 struct i2c_board_info *info)
161{ 140{
162 return i2c_probe(adapter, &addr_data, eeprom_detect); 141 struct i2c_adapter *adapter = client->adapter;
142
143 /* EDID EEPROMs are often 24C00 EEPROMs, which answer to all
144 addresses 0x50-0x57, but we only care about 0x50. So decline
145 attaching to addresses >= 0x51 on DDC buses */
146 if (!(adapter->class & I2C_CLASS_SPD) && client->addr >= 0x51)
147 return -ENODEV;
148
149 /* There are four ways we can read the EEPROM data:
150 (1) I2C block reads (faster, but unsupported by most adapters)
151 (2) Word reads (128% overhead)
152 (3) Consecutive byte reads (88% overhead, unsafe)
153 (4) Regular byte data reads (265% overhead)
154 The third and fourth methods are not implemented by this driver
155 because all known adapters support one of the first two. */
156 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA)
157 && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK))
158 return -ENODEV;
159
160 strlcpy(info->type, "eeprom", I2C_NAME_SIZE);
161
162 return 0;
163} 163}
164 164
165/* This function is called by i2c_probe */ 165static int eeprom_probe(struct i2c_client *client,
166static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) 166 const struct i2c_device_id *id)
167{ 167{
168 struct i2c_client *new_client; 168 struct i2c_adapter *adapter = client->adapter;
169 struct eeprom_data *data; 169 struct eeprom_data *data;
170 int err = 0; 170 int err;
171
172 /* There are three ways we can read the EEPROM data:
173 (1) I2C block reads (faster, but unsupported by most adapters)
174 (2) Consecutive byte reads (100% overhead)
175 (3) Regular byte data reads (200% overhead)
176 The third method is not implemented by this driver because all
177 known adapters support at least the second. */
178 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA
179 | I2C_FUNC_SMBUS_BYTE))
180 goto exit;
181 171
182 if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { 172 if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) {
183 err = -ENOMEM; 173 err = -ENOMEM;
184 goto exit; 174 goto exit;
185 } 175 }
186 176
187 new_client = &data->client;
188 memset(data->data, 0xff, EEPROM_SIZE); 177 memset(data->data, 0xff, EEPROM_SIZE);
189 i2c_set_clientdata(new_client, data); 178 i2c_set_clientdata(client, data);
190 new_client->addr = address;
191 new_client->adapter = adapter;
192 new_client->driver = &eeprom_driver;
193 new_client->flags = 0;
194
195 /* Fill in the remaining client fields */
196 strlcpy(new_client->name, "eeprom", I2C_NAME_SIZE);
197 data->valid = 0;
198 mutex_init(&data->update_lock); 179 mutex_init(&data->update_lock);
199 data->nature = UNKNOWN; 180 data->nature = UNKNOWN;
200 181
201 /* Tell the I2C layer a new client has arrived */
202 if ((err = i2c_attach_client(new_client)))
203 goto exit_kfree;
204
205 /* Detect the Vaio nature of EEPROMs. 182 /* Detect the Vaio nature of EEPROMs.
206 We use the "PCG-" or "VGN-" prefix as the signature. */ 183 We use the "PCG-" or "VGN-" prefix as the signature. */
207 if (address == 0x57) { 184 if (client->addr == 0x57
185 && i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_BYTE_DATA)) {
208 char name[4]; 186 char name[4];
209 187
210 name[0] = i2c_smbus_read_byte_data(new_client, 0x80); 188 name[0] = i2c_smbus_read_byte_data(client, 0x80);
211 name[1] = i2c_smbus_read_byte(new_client); 189 name[1] = i2c_smbus_read_byte_data(client, 0x81);
212 name[2] = i2c_smbus_read_byte(new_client); 190 name[2] = i2c_smbus_read_byte_data(client, 0x82);
213 name[3] = i2c_smbus_read_byte(new_client); 191 name[3] = i2c_smbus_read_byte_data(client, 0x83);
214 192
215 if (!memcmp(name, "PCG-", 4) || !memcmp(name, "VGN-", 4)) { 193 if (!memcmp(name, "PCG-", 4) || !memcmp(name, "VGN-", 4)) {
216 dev_info(&new_client->dev, "Vaio EEPROM detected, " 194 dev_info(&client->dev, "Vaio EEPROM detected, "
217 "enabling privacy protection\n"); 195 "enabling privacy protection\n");
218 data->nature = VAIO; 196 data->nature = VAIO;
219 } 197 }
220 } 198 }
221 199
222 /* create the sysfs eeprom file */ 200 /* create the sysfs eeprom file */
223 err = sysfs_create_bin_file(&new_client->dev.kobj, &eeprom_attr); 201 err = sysfs_create_bin_file(&client->dev.kobj, &eeprom_attr);
224 if (err) 202 if (err)
225 goto exit_detach; 203 goto exit_kfree;
226 204
227 return 0; 205 return 0;
228 206
229exit_detach:
230 i2c_detach_client(new_client);
231exit_kfree: 207exit_kfree:
232 kfree(data); 208 kfree(data);
233exit: 209exit:
234 return err; 210 return err;
235} 211}
236 212
237static int eeprom_detach_client(struct i2c_client *client) 213static int eeprom_remove(struct i2c_client *client)
238{ 214{
239 int err;
240
241 sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr); 215 sysfs_remove_bin_file(&client->dev.kobj, &eeprom_attr);
242
243 err = i2c_detach_client(client);
244 if (err)
245 return err;
246
247 kfree(i2c_get_clientdata(client)); 216 kfree(i2c_get_clientdata(client));
248 217
249 return 0; 218 return 0;
250} 219}
251 220
221static const struct i2c_device_id eeprom_id[] = {
222 { "eeprom", 0 },
223 { }
224};
225
226static struct i2c_driver eeprom_driver = {
227 .driver = {
228 .name = "eeprom",
229 },
230 .probe = eeprom_probe,
231 .remove = eeprom_remove,
232 .id_table = eeprom_id,
233
234 .class = I2C_CLASS_DDC | I2C_CLASS_SPD,
235 .detect = eeprom_detect,
236 .address_data = &addr_data,
237};
238
252static int __init eeprom_init(void) 239static int __init eeprom_init(void)
253{ 240{
254 return i2c_add_driver(&eeprom_driver); 241 return i2c_add_driver(&eeprom_driver);
diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c
index b1b45dddb17e..03a33f1b9cd3 100644
--- a/drivers/i2c/chips/isp1301_omap.c
+++ b/drivers/i2c/chips/isp1301_omap.c
@@ -72,7 +72,7 @@ struct isp1301 {
72}; 72};
73 73
74 74
75/* bits in OTG_CTRL_REG */ 75/* bits in OTG_CTRL */
76 76
77#define OTG_XCEIV_OUTPUTS \ 77#define OTG_XCEIV_OUTPUTS \
78 (OTG_ASESSVLD|OTG_BSESSEND|OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID) 78 (OTG_ASESSVLD|OTG_BSESSEND|OTG_BSESSVLD|OTG_VBUSVLD|OTG_ID)
@@ -186,8 +186,8 @@ isp1301_clear_bits(struct isp1301 *isp, u8 reg, u8 bits)
186 186
187/* operational registers */ 187/* operational registers */
188#define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */ 188#define ISP1301_MODE_CONTROL_1 0x04 /* u8 read, set, +1 clear */
189# define MC1_SPEED_REG (1 << 0) 189# define MC1_SPEED (1 << 0)
190# define MC1_SUSPEND_REG (1 << 1) 190# define MC1_SUSPEND (1 << 1)
191# define MC1_DAT_SE0 (1 << 2) 191# define MC1_DAT_SE0 (1 << 2)
192# define MC1_TRANSPARENT (1 << 3) 192# define MC1_TRANSPARENT (1 << 3)
193# define MC1_BDIS_ACON_EN (1 << 4) 193# define MC1_BDIS_ACON_EN (1 << 4)
@@ -274,7 +274,7 @@ static void power_down(struct isp1301 *isp)
274 isp->otg.state = OTG_STATE_UNDEFINED; 274 isp->otg.state = OTG_STATE_UNDEFINED;
275 275
276 // isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN); 276 // isp1301_set_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
277 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND_REG); 277 isp1301_set_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND);
278 278
279 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_ID_PULLDOWN); 279 isp1301_clear_bits(isp, ISP1301_OTG_CONTROL_1, OTG1_ID_PULLDOWN);
280 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0); 280 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_DAT_SE0);
@@ -283,7 +283,7 @@ static void power_down(struct isp1301 *isp)
283static void power_up(struct isp1301 *isp) 283static void power_up(struct isp1301 *isp)
284{ 284{
285 // isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN); 285 // isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_2, MC2_GLOBAL_PWR_DN);
286 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND_REG); 286 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, MC1_SUSPEND);
287 287
288 /* do this only when cpu is driving transceiver, 288 /* do this only when cpu is driving transceiver,
289 * so host won't see a low speed device... 289 * so host won't see a low speed device...
@@ -360,6 +360,8 @@ isp1301_defer_work(struct isp1301 *isp, int work)
360/* called from irq handlers */ 360/* called from irq handlers */
361static void a_idle(struct isp1301 *isp, const char *tag) 361static void a_idle(struct isp1301 *isp, const char *tag)
362{ 362{
363 u32 l;
364
363 if (isp->otg.state == OTG_STATE_A_IDLE) 365 if (isp->otg.state == OTG_STATE_A_IDLE)
364 return; 366 return;
365 367
@@ -373,13 +375,17 @@ static void a_idle(struct isp1301 *isp, const char *tag)
373 gadget_suspend(isp); 375 gadget_suspend(isp);
374 } 376 }
375 isp->otg.state = OTG_STATE_A_IDLE; 377 isp->otg.state = OTG_STATE_A_IDLE;
376 isp->last_otg_ctrl = OTG_CTRL_REG = OTG_CTRL_REG & OTG_XCEIV_OUTPUTS; 378 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
379 omap_writel(l, OTG_CTRL);
380 isp->last_otg_ctrl = l;
377 pr_debug(" --> %s/%s\n", state_name(isp), tag); 381 pr_debug(" --> %s/%s\n", state_name(isp), tag);
378} 382}
379 383
380/* called from irq handlers */ 384/* called from irq handlers */
381static void b_idle(struct isp1301 *isp, const char *tag) 385static void b_idle(struct isp1301 *isp, const char *tag)
382{ 386{
387 u32 l;
388
383 if (isp->otg.state == OTG_STATE_B_IDLE) 389 if (isp->otg.state == OTG_STATE_B_IDLE)
384 return; 390 return;
385 391
@@ -393,7 +399,9 @@ static void b_idle(struct isp1301 *isp, const char *tag)
393 gadget_suspend(isp); 399 gadget_suspend(isp);
394 } 400 }
395 isp->otg.state = OTG_STATE_B_IDLE; 401 isp->otg.state = OTG_STATE_B_IDLE;
396 isp->last_otg_ctrl = OTG_CTRL_REG = OTG_CTRL_REG & OTG_XCEIV_OUTPUTS; 402 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
403 omap_writel(l, OTG_CTRL);
404 isp->last_otg_ctrl = l;
397 pr_debug(" --> %s/%s\n", state_name(isp), tag); 405 pr_debug(" --> %s/%s\n", state_name(isp), tag);
398} 406}
399 407
@@ -406,7 +414,7 @@ dump_regs(struct isp1301 *isp, const char *label)
406 u8 src = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE); 414 u8 src = isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE);
407 415
408 pr_debug("otg: %06x, %s %s, otg/%02x stat/%02x.%02x\n", 416 pr_debug("otg: %06x, %s %s, otg/%02x stat/%02x.%02x\n",
409 OTG_CTRL_REG, label, state_name(isp), 417 omap_readl(OTG_CTRL), label, state_name(isp),
410 ctrl, status, src); 418 ctrl, status, src);
411 /* mode control and irq enables don't change much */ 419 /* mode control and irq enables don't change much */
412#endif 420#endif
@@ -429,7 +437,7 @@ dump_regs(struct isp1301 *isp, const char *label)
429static void check_state(struct isp1301 *isp, const char *tag) 437static void check_state(struct isp1301 *isp, const char *tag)
430{ 438{
431 enum usb_otg_state state = OTG_STATE_UNDEFINED; 439 enum usb_otg_state state = OTG_STATE_UNDEFINED;
432 u8 fsm = OTG_TEST_REG & 0x0ff; 440 u8 fsm = omap_readw(OTG_TEST) & 0x0ff;
433 unsigned extra = 0; 441 unsigned extra = 0;
434 442
435 switch (fsm) { 443 switch (fsm) {
@@ -494,7 +502,8 @@ static void check_state(struct isp1301 *isp, const char *tag)
494 if (isp->otg.state == state && !extra) 502 if (isp->otg.state == state && !extra)
495 return; 503 return;
496 pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag, 504 pr_debug("otg: %s FSM %s/%02x, %s, %06x\n", tag,
497 state_string(state), fsm, state_name(isp), OTG_CTRL_REG); 505 state_string(state), fsm, state_name(isp),
506 omap_readl(OTG_CTRL));
498} 507}
499 508
500#else 509#else
@@ -508,10 +517,11 @@ static void update_otg1(struct isp1301 *isp, u8 int_src)
508{ 517{
509 u32 otg_ctrl; 518 u32 otg_ctrl;
510 519
511 otg_ctrl = OTG_CTRL_REG 520 otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
512 & OTG_CTRL_MASK 521 otg_ctrl &= ~OTG_XCEIV_INPUTS;
513 & ~OTG_XCEIV_INPUTS 522 otg_ctrl &= ~(OTG_ID|OTG_ASESSVLD|OTG_VBUSVLD);
514 & ~(OTG_ID|OTG_ASESSVLD|OTG_VBUSVLD); 523
524
515 if (int_src & INTR_SESS_VLD) 525 if (int_src & INTR_SESS_VLD)
516 otg_ctrl |= OTG_ASESSVLD; 526 otg_ctrl |= OTG_ASESSVLD;
517 else if (isp->otg.state == OTG_STATE_A_WAIT_VFALL) { 527 else if (isp->otg.state == OTG_STATE_A_WAIT_VFALL) {
@@ -534,7 +544,7 @@ static void update_otg1(struct isp1301 *isp, u8 int_src)
534 return; 544 return;
535 } 545 }
536 } 546 }
537 OTG_CTRL_REG = otg_ctrl; 547 omap_writel(otg_ctrl, OTG_CTRL);
538} 548}
539 549
540/* outputs from ISP1301_OTG_STATUS */ 550/* outputs from ISP1301_OTG_STATUS */
@@ -542,15 +552,14 @@ static void update_otg2(struct isp1301 *isp, u8 otg_status)
542{ 552{
543 u32 otg_ctrl; 553 u32 otg_ctrl;
544 554
545 otg_ctrl = OTG_CTRL_REG 555 otg_ctrl = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
546 & OTG_CTRL_MASK 556 otg_ctrl &= ~OTG_XCEIV_INPUTS;
547 & ~OTG_XCEIV_INPUTS 557 otg_ctrl &= ~(OTG_BSESSVLD | OTG_BSESSEND);
548 & ~(OTG_BSESSVLD|OTG_BSESSEND);
549 if (otg_status & OTG_B_SESS_VLD) 558 if (otg_status & OTG_B_SESS_VLD)
550 otg_ctrl |= OTG_BSESSVLD; 559 otg_ctrl |= OTG_BSESSVLD;
551 else if (otg_status & OTG_B_SESS_END) 560 else if (otg_status & OTG_B_SESS_END)
552 otg_ctrl |= OTG_BSESSEND; 561 otg_ctrl |= OTG_BSESSEND;
553 OTG_CTRL_REG = otg_ctrl; 562 omap_writel(otg_ctrl, OTG_CTRL);
554} 563}
555 564
556/* inputs going to ISP1301 */ 565/* inputs going to ISP1301 */
@@ -559,7 +568,7 @@ static void otg_update_isp(struct isp1301 *isp)
559 u32 otg_ctrl, otg_change; 568 u32 otg_ctrl, otg_change;
560 u8 set = OTG1_DM_PULLDOWN, clr = OTG1_DM_PULLUP; 569 u8 set = OTG1_DM_PULLDOWN, clr = OTG1_DM_PULLUP;
561 570
562 otg_ctrl = OTG_CTRL_REG; 571 otg_ctrl = omap_readl(OTG_CTRL);
563 otg_change = otg_ctrl ^ isp->last_otg_ctrl; 572 otg_change = otg_ctrl ^ isp->last_otg_ctrl;
564 isp->last_otg_ctrl = otg_ctrl; 573 isp->last_otg_ctrl = otg_ctrl;
565 otg_ctrl = otg_ctrl & OTG_XCEIV_INPUTS; 574 otg_ctrl = otg_ctrl & OTG_XCEIV_INPUTS;
@@ -639,6 +648,8 @@ pulldown:
639 648
640 /* HNP switch to host or peripheral; and SRP */ 649 /* HNP switch to host or peripheral; and SRP */
641 if (otg_change & OTG_PULLUP) { 650 if (otg_change & OTG_PULLUP) {
651 u32 l;
652
642 switch (isp->otg.state) { 653 switch (isp->otg.state) {
643 case OTG_STATE_B_IDLE: 654 case OTG_STATE_B_IDLE:
644 if (clr & OTG1_DP_PULLUP) 655 if (clr & OTG1_DP_PULLUP)
@@ -655,7 +666,9 @@ pulldown:
655 default: 666 default:
656 break; 667 break;
657 } 668 }
658 OTG_CTRL_REG |= OTG_PULLUP; 669 l = omap_readl(OTG_CTRL);
670 l |= OTG_PULLUP;
671 omap_writel(l, OTG_CTRL);
659 } 672 }
660 673
661 check_state(isp, __func__); 674 check_state(isp, __func__);
@@ -664,20 +677,20 @@ pulldown:
664 677
665static irqreturn_t omap_otg_irq(int irq, void *_isp) 678static irqreturn_t omap_otg_irq(int irq, void *_isp)
666{ 679{
667 u16 otg_irq = OTG_IRQ_SRC_REG; 680 u16 otg_irq = omap_readw(OTG_IRQ_SRC);
668 u32 otg_ctrl; 681 u32 otg_ctrl;
669 int ret = IRQ_NONE; 682 int ret = IRQ_NONE;
670 struct isp1301 *isp = _isp; 683 struct isp1301 *isp = _isp;
671 684
672 /* update ISP1301 transciever from OTG controller */ 685 /* update ISP1301 transciever from OTG controller */
673 if (otg_irq & OPRT_CHG) { 686 if (otg_irq & OPRT_CHG) {
674 OTG_IRQ_SRC_REG = OPRT_CHG; 687 omap_writew(OPRT_CHG, OTG_IRQ_SRC);
675 isp1301_defer_work(isp, WORK_UPDATE_ISP); 688 isp1301_defer_work(isp, WORK_UPDATE_ISP);
676 ret = IRQ_HANDLED; 689 ret = IRQ_HANDLED;
677 690
678 /* SRP to become b_peripheral failed */ 691 /* SRP to become b_peripheral failed */
679 } else if (otg_irq & B_SRP_TMROUT) { 692 } else if (otg_irq & B_SRP_TMROUT) {
680 pr_debug("otg: B_SRP_TIMEOUT, %06x\n", OTG_CTRL_REG); 693 pr_debug("otg: B_SRP_TIMEOUT, %06x\n", omap_readl(OTG_CTRL));
681 notresponding(isp); 694 notresponding(isp);
682 695
683 /* gadget drivers that care should monitor all kinds of 696 /* gadget drivers that care should monitor all kinds of
@@ -687,31 +700,31 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
687 if (isp->otg.state == OTG_STATE_B_SRP_INIT) 700 if (isp->otg.state == OTG_STATE_B_SRP_INIT)
688 b_idle(isp, "srp_timeout"); 701 b_idle(isp, "srp_timeout");
689 702
690 OTG_IRQ_SRC_REG = B_SRP_TMROUT; 703 omap_writew(B_SRP_TMROUT, OTG_IRQ_SRC);
691 ret = IRQ_HANDLED; 704 ret = IRQ_HANDLED;
692 705
693 /* HNP to become b_host failed */ 706 /* HNP to become b_host failed */
694 } else if (otg_irq & B_HNP_FAIL) { 707 } else if (otg_irq & B_HNP_FAIL) {
695 pr_debug("otg: %s B_HNP_FAIL, %06x\n", 708 pr_debug("otg: %s B_HNP_FAIL, %06x\n",
696 state_name(isp), OTG_CTRL_REG); 709 state_name(isp), omap_readl(OTG_CTRL));
697 notresponding(isp); 710 notresponding(isp);
698 711
699 otg_ctrl = OTG_CTRL_REG; 712 otg_ctrl = omap_readl(OTG_CTRL);
700 otg_ctrl |= OTG_BUSDROP; 713 otg_ctrl |= OTG_BUSDROP;
701 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS; 714 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
702 OTG_CTRL_REG = otg_ctrl; 715 omap_writel(otg_ctrl, OTG_CTRL);
703 716
704 /* subset of b_peripheral()... */ 717 /* subset of b_peripheral()... */
705 isp->otg.state = OTG_STATE_B_PERIPHERAL; 718 isp->otg.state = OTG_STATE_B_PERIPHERAL;
706 pr_debug(" --> b_peripheral\n"); 719 pr_debug(" --> b_peripheral\n");
707 720
708 OTG_IRQ_SRC_REG = B_HNP_FAIL; 721 omap_writew(B_HNP_FAIL, OTG_IRQ_SRC);
709 ret = IRQ_HANDLED; 722 ret = IRQ_HANDLED;
710 723
711 /* detect SRP from B-device ... */ 724 /* detect SRP from B-device ... */
712 } else if (otg_irq & A_SRP_DETECT) { 725 } else if (otg_irq & A_SRP_DETECT) {
713 pr_debug("otg: %s SRP_DETECT, %06x\n", 726 pr_debug("otg: %s SRP_DETECT, %06x\n",
714 state_name(isp), OTG_CTRL_REG); 727 state_name(isp), omap_readl(OTG_CTRL));
715 728
716 isp1301_defer_work(isp, WORK_UPDATE_OTG); 729 isp1301_defer_work(isp, WORK_UPDATE_OTG);
717 switch (isp->otg.state) { 730 switch (isp->otg.state) {
@@ -719,49 +732,49 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
719 if (!isp->otg.host) 732 if (!isp->otg.host)
720 break; 733 break;
721 isp1301_defer_work(isp, WORK_HOST_RESUME); 734 isp1301_defer_work(isp, WORK_HOST_RESUME);
722 otg_ctrl = OTG_CTRL_REG; 735 otg_ctrl = omap_readl(OTG_CTRL);
723 otg_ctrl |= OTG_A_BUSREQ; 736 otg_ctrl |= OTG_A_BUSREQ;
724 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ) 737 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
725 & ~OTG_XCEIV_INPUTS 738 & ~OTG_XCEIV_INPUTS
726 & OTG_CTRL_MASK; 739 & OTG_CTRL_MASK;
727 OTG_CTRL_REG = otg_ctrl; 740 omap_writel(otg_ctrl, OTG_CTRL);
728 break; 741 break;
729 default: 742 default:
730 break; 743 break;
731 } 744 }
732 745
733 OTG_IRQ_SRC_REG = A_SRP_DETECT; 746 omap_writew(A_SRP_DETECT, OTG_IRQ_SRC);
734 ret = IRQ_HANDLED; 747 ret = IRQ_HANDLED;
735 748
736 /* timer expired: T(a_wait_bcon) and maybe T(a_wait_vrise) 749 /* timer expired: T(a_wait_bcon) and maybe T(a_wait_vrise)
737 * we don't track them separately 750 * we don't track them separately
738 */ 751 */
739 } else if (otg_irq & A_REQ_TMROUT) { 752 } else if (otg_irq & A_REQ_TMROUT) {
740 otg_ctrl = OTG_CTRL_REG; 753 otg_ctrl = omap_readl(OTG_CTRL);
741 pr_info("otg: BCON_TMOUT from %s, %06x\n", 754 pr_info("otg: BCON_TMOUT from %s, %06x\n",
742 state_name(isp), otg_ctrl); 755 state_name(isp), otg_ctrl);
743 notresponding(isp); 756 notresponding(isp);
744 757
745 otg_ctrl |= OTG_BUSDROP; 758 otg_ctrl |= OTG_BUSDROP;
746 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS; 759 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
747 OTG_CTRL_REG = otg_ctrl; 760 omap_writel(otg_ctrl, OTG_CTRL);
748 isp->otg.state = OTG_STATE_A_WAIT_VFALL; 761 isp->otg.state = OTG_STATE_A_WAIT_VFALL;
749 762
750 OTG_IRQ_SRC_REG = A_REQ_TMROUT; 763 omap_writew(A_REQ_TMROUT, OTG_IRQ_SRC);
751 ret = IRQ_HANDLED; 764 ret = IRQ_HANDLED;
752 765
753 /* A-supplied voltage fell too low; overcurrent */ 766 /* A-supplied voltage fell too low; overcurrent */
754 } else if (otg_irq & A_VBUS_ERR) { 767 } else if (otg_irq & A_VBUS_ERR) {
755 otg_ctrl = OTG_CTRL_REG; 768 otg_ctrl = omap_readl(OTG_CTRL);
756 printk(KERN_ERR "otg: %s, VBUS_ERR %04x ctrl %06x\n", 769 printk(KERN_ERR "otg: %s, VBUS_ERR %04x ctrl %06x\n",
757 state_name(isp), otg_irq, otg_ctrl); 770 state_name(isp), otg_irq, otg_ctrl);
758 771
759 otg_ctrl |= OTG_BUSDROP; 772 otg_ctrl |= OTG_BUSDROP;
760 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS; 773 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
761 OTG_CTRL_REG = otg_ctrl; 774 omap_writel(otg_ctrl, OTG_CTRL);
762 isp->otg.state = OTG_STATE_A_VBUS_ERR; 775 isp->otg.state = OTG_STATE_A_VBUS_ERR;
763 776
764 OTG_IRQ_SRC_REG = A_VBUS_ERR; 777 omap_writew(A_VBUS_ERR, OTG_IRQ_SRC);
765 ret = IRQ_HANDLED; 778 ret = IRQ_HANDLED;
766 779
767 /* switch driver; the transciever code activates it, 780 /* switch driver; the transciever code activates it,
@@ -770,7 +783,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
770 } else if (otg_irq & DRIVER_SWITCH) { 783 } else if (otg_irq & DRIVER_SWITCH) {
771 int kick = 0; 784 int kick = 0;
772 785
773 otg_ctrl = OTG_CTRL_REG; 786 otg_ctrl = omap_readl(OTG_CTRL);
774 printk(KERN_NOTICE "otg: %s, SWITCH to %s, ctrl %06x\n", 787 printk(KERN_NOTICE "otg: %s, SWITCH to %s, ctrl %06x\n",
775 state_name(isp), 788 state_name(isp),
776 (otg_ctrl & OTG_DRIVER_SEL) 789 (otg_ctrl & OTG_DRIVER_SEL)
@@ -793,7 +806,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
793 } else { 806 } else {
794 if (!(otg_ctrl & OTG_ID)) { 807 if (!(otg_ctrl & OTG_ID)) {
795 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS; 808 otg_ctrl &= OTG_CTRL_MASK & ~OTG_XCEIV_INPUTS;
796 OTG_CTRL_REG = otg_ctrl | OTG_A_BUSREQ; 809 omap_writel(otg_ctrl | OTG_A_BUSREQ, OTG_CTRL);
797 } 810 }
798 811
799 if (isp->otg.host) { 812 if (isp->otg.host) {
@@ -818,7 +831,7 @@ static irqreturn_t omap_otg_irq(int irq, void *_isp)
818 } 831 }
819 } 832 }
820 833
821 OTG_IRQ_SRC_REG = DRIVER_SWITCH; 834 omap_writew(DRIVER_SWITCH, OTG_IRQ_SRC);
822 ret = IRQ_HANDLED; 835 ret = IRQ_HANDLED;
823 836
824 if (kick) 837 if (kick)
@@ -834,12 +847,15 @@ static struct platform_device *otg_dev;
834 847
835static int otg_init(struct isp1301 *isp) 848static int otg_init(struct isp1301 *isp)
836{ 849{
850 u32 l;
851
837 if (!otg_dev) 852 if (!otg_dev)
838 return -ENODEV; 853 return -ENODEV;
839 854
840 dump_regs(isp, __func__); 855 dump_regs(isp, __func__);
841 /* some of these values are board-specific... */ 856 /* some of these values are board-specific... */
842 OTG_SYSCON_2_REG |= OTG_EN 857 l = omap_readl(OTG_SYSCON_2);
858 l |= OTG_EN
843 /* for B-device: */ 859 /* for B-device: */
844 | SRP_GPDATA /* 9msec Bdev D+ pulse */ 860 | SRP_GPDATA /* 9msec Bdev D+ pulse */
845 | SRP_GPDVBUS /* discharge after VBUS pulse */ 861 | SRP_GPDVBUS /* discharge after VBUS pulse */
@@ -849,18 +865,22 @@ static int otg_init(struct isp1301 *isp)
849 | SRP_DPW /* detect 167+ns SRP pulses */ 865 | SRP_DPW /* detect 167+ns SRP pulses */
850 | SRP_DATA | SRP_VBUS /* accept both kinds of SRP pulse */ 866 | SRP_DATA | SRP_VBUS /* accept both kinds of SRP pulse */
851 ; 867 ;
868 omap_writel(l, OTG_SYSCON_2);
852 869
853 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE)); 870 update_otg1(isp, isp1301_get_u8(isp, ISP1301_INTERRUPT_SOURCE));
854 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS)); 871 update_otg2(isp, isp1301_get_u8(isp, ISP1301_OTG_STATUS));
855 872
856 check_state(isp, __func__); 873 check_state(isp, __func__);
857 pr_debug("otg: %s, %s %06x\n", 874 pr_debug("otg: %s, %s %06x\n",
858 state_name(isp), __func__, OTG_CTRL_REG); 875 state_name(isp), __func__, omap_readl(OTG_CTRL));
859 876
860 OTG_IRQ_EN_REG = DRIVER_SWITCH | OPRT_CHG 877 omap_writew(DRIVER_SWITCH | OPRT_CHG
861 | B_SRP_TMROUT | B_HNP_FAIL 878 | B_SRP_TMROUT | B_HNP_FAIL
862 | A_VBUS_ERR | A_SRP_DETECT | A_REQ_TMROUT; 879 | A_VBUS_ERR | A_SRP_DETECT | A_REQ_TMROUT, OTG_IRQ_EN);
863 OTG_SYSCON_2_REG |= OTG_EN; 880
881 l = omap_readl(OTG_SYSCON_2);
882 l |= OTG_EN;
883 omap_writel(l, OTG_SYSCON_2);
864 884
865 return 0; 885 return 0;
866} 886}
@@ -927,7 +947,11 @@ static void otg_unbind(struct isp1301 *isp)
927 947
928static void b_peripheral(struct isp1301 *isp) 948static void b_peripheral(struct isp1301 *isp)
929{ 949{
930 OTG_CTRL_REG = OTG_CTRL_REG & OTG_XCEIV_OUTPUTS; 950 u32 l;
951
952 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
953 omap_writel(l, OTG_CTRL);
954
931 usb_gadget_vbus_connect(isp->otg.gadget); 955 usb_gadget_vbus_connect(isp->otg.gadget);
932 956
933#ifdef CONFIG_USB_OTG 957#ifdef CONFIG_USB_OTG
@@ -999,6 +1023,8 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
999 isp_bstat = 0; 1023 isp_bstat = 0;
1000 } 1024 }
1001 } else { 1025 } else {
1026 u32 l;
1027
1002 /* if user unplugged mini-A end of cable, 1028 /* if user unplugged mini-A end of cable,
1003 * don't bypass A_WAIT_VFALL. 1029 * don't bypass A_WAIT_VFALL.
1004 */ 1030 */
@@ -1019,8 +1045,9 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
1019 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1, 1045 isp1301_clear_bits(isp, ISP1301_MODE_CONTROL_1,
1020 MC1_BDIS_ACON_EN); 1046 MC1_BDIS_ACON_EN);
1021 isp->otg.state = OTG_STATE_B_IDLE; 1047 isp->otg.state = OTG_STATE_B_IDLE;
1022 OTG_CTRL_REG &= OTG_CTRL_REG & OTG_CTRL_MASK 1048 l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
1023 & ~OTG_CTRL_BITS; 1049 l &= ~OTG_CTRL_BITS;
1050 omap_writel(l, OTG_CTRL);
1024 break; 1051 break;
1025 case OTG_STATE_B_IDLE: 1052 case OTG_STATE_B_IDLE:
1026 break; 1053 break;
@@ -1046,7 +1073,8 @@ static void isp_update_otg(struct isp1301 *isp, u8 stat)
1046 /* FALLTHROUGH */ 1073 /* FALLTHROUGH */
1047 case OTG_STATE_B_SRP_INIT: 1074 case OTG_STATE_B_SRP_INIT:
1048 b_idle(isp, __func__); 1075 b_idle(isp, __func__);
1049 OTG_CTRL_REG &= OTG_CTRL_REG & OTG_XCEIV_OUTPUTS; 1076 l = omap_readl(OTG_CTRL) & OTG_XCEIV_OUTPUTS;
1077 omap_writel(l, OTG_CTRL);
1050 /* FALLTHROUGH */ 1078 /* FALLTHROUGH */
1051 case OTG_STATE_B_IDLE: 1079 case OTG_STATE_B_IDLE:
1052 if (isp->otg.gadget && (isp_bstat & OTG_B_SESS_VLD)) { 1080 if (isp->otg.gadget && (isp_bstat & OTG_B_SESS_VLD)) {
@@ -1130,11 +1158,11 @@ isp1301_work(struct work_struct *work)
1130 case OTG_STATE_A_WAIT_VRISE: 1158 case OTG_STATE_A_WAIT_VRISE:
1131 isp->otg.state = OTG_STATE_A_HOST; 1159 isp->otg.state = OTG_STATE_A_HOST;
1132 pr_debug(" --> a_host\n"); 1160 pr_debug(" --> a_host\n");
1133 otg_ctrl = OTG_CTRL_REG; 1161 otg_ctrl = omap_readl(OTG_CTRL);
1134 otg_ctrl |= OTG_A_BUSREQ; 1162 otg_ctrl |= OTG_A_BUSREQ;
1135 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ) 1163 otg_ctrl &= ~(OTG_BUSDROP|OTG_B_BUSREQ)
1136 & OTG_CTRL_MASK; 1164 & OTG_CTRL_MASK;
1137 OTG_CTRL_REG = otg_ctrl; 1165 omap_writel(otg_ctrl, OTG_CTRL);
1138 break; 1166 break;
1139 case OTG_STATE_B_WAIT_ACON: 1167 case OTG_STATE_B_WAIT_ACON:
1140 isp->otg.state = OTG_STATE_B_HOST; 1168 isp->otg.state = OTG_STATE_B_HOST;
@@ -1274,7 +1302,7 @@ isp1301_set_host(struct otg_transceiver *otg, struct usb_bus *host)
1274 return -ENODEV; 1302 return -ENODEV;
1275 1303
1276 if (!host) { 1304 if (!host) {
1277 OTG_IRQ_EN_REG = 0; 1305 omap_writew(0, OTG_IRQ_EN);
1278 power_down(isp); 1306 power_down(isp);
1279 isp->otg.host = 0; 1307 isp->otg.host = 0;
1280 return 0; 1308 return 0;
@@ -1325,12 +1353,13 @@ static int
1325isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget) 1353isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
1326{ 1354{
1327 struct isp1301 *isp = container_of(otg, struct isp1301, otg); 1355 struct isp1301 *isp = container_of(otg, struct isp1301, otg);
1356 u32 l;
1328 1357
1329 if (!otg || isp != the_transceiver) 1358 if (!otg || isp != the_transceiver)
1330 return -ENODEV; 1359 return -ENODEV;
1331 1360
1332 if (!gadget) { 1361 if (!gadget) {
1333 OTG_IRQ_EN_REG = 0; 1362 omap_writew(0, OTG_IRQ_EN);
1334 if (!isp->otg.default_a) 1363 if (!isp->otg.default_a)
1335 enable_vbus_draw(isp, 0); 1364 enable_vbus_draw(isp, 0);
1336 usb_gadget_vbus_disconnect(isp->otg.gadget); 1365 usb_gadget_vbus_disconnect(isp->otg.gadget);
@@ -1351,9 +1380,11 @@ isp1301_set_peripheral(struct otg_transceiver *otg, struct usb_gadget *gadget)
1351 isp->otg.gadget = gadget; 1380 isp->otg.gadget = gadget;
1352 // FIXME update its refcount 1381 // FIXME update its refcount
1353 1382
1354 OTG_CTRL_REG = (OTG_CTRL_REG & OTG_CTRL_MASK 1383 l = omap_readl(OTG_CTRL) & OTG_CTRL_MASK;
1355 & ~(OTG_XCEIV_OUTPUTS|OTG_CTRL_BITS)) 1384 l &= ~(OTG_XCEIV_OUTPUTS|OTG_CTRL_BITS);
1356 | OTG_ID; 1385 l |= OTG_ID;
1386 omap_writel(l, OTG_CTRL);
1387
1357 power_up(isp); 1388 power_up(isp);
1358 isp->otg.state = OTG_STATE_B_IDLE; 1389 isp->otg.state = OTG_STATE_B_IDLE;
1359 1390
@@ -1405,16 +1436,17 @@ isp1301_start_srp(struct otg_transceiver *dev)
1405 || isp->otg.state != OTG_STATE_B_IDLE) 1436 || isp->otg.state != OTG_STATE_B_IDLE)
1406 return -ENODEV; 1437 return -ENODEV;
1407 1438
1408 otg_ctrl = OTG_CTRL_REG; 1439 otg_ctrl = omap_readl(OTG_CTRL);
1409 if (!(otg_ctrl & OTG_BSESSEND)) 1440 if (!(otg_ctrl & OTG_BSESSEND))
1410 return -EINVAL; 1441 return -EINVAL;
1411 1442
1412 otg_ctrl |= OTG_B_BUSREQ; 1443 otg_ctrl |= OTG_B_BUSREQ;
1413 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK; 1444 otg_ctrl &= ~OTG_A_BUSREQ & OTG_CTRL_MASK;
1414 OTG_CTRL_REG = otg_ctrl; 1445 omap_writel(otg_ctrl, OTG_CTRL);
1415 isp->otg.state = OTG_STATE_B_SRP_INIT; 1446 isp->otg.state = OTG_STATE_B_SRP_INIT;
1416 1447
1417 pr_debug("otg: SRP, %s ... %06x\n", state_name(isp), OTG_CTRL_REG); 1448 pr_debug("otg: SRP, %s ... %06x\n", state_name(isp),
1449 omap_readl(OTG_CTRL));
1418#ifdef CONFIG_USB_OTG 1450#ifdef CONFIG_USB_OTG
1419 check_state(isp, __func__); 1451 check_state(isp, __func__);
1420#endif 1452#endif
@@ -1426,6 +1458,7 @@ isp1301_start_hnp(struct otg_transceiver *dev)
1426{ 1458{
1427#ifdef CONFIG_USB_OTG 1459#ifdef CONFIG_USB_OTG
1428 struct isp1301 *isp = container_of(dev, struct isp1301, otg); 1460 struct isp1301 *isp = container_of(dev, struct isp1301, otg);
1461 u32 l;
1429 1462
1430 if (!dev || isp != the_transceiver) 1463 if (!dev || isp != the_transceiver)
1431 return -ENODEV; 1464 return -ENODEV;
@@ -1452,7 +1485,9 @@ isp1301_start_hnp(struct otg_transceiver *dev)
1452#endif 1485#endif
1453 /* caller must suspend then clear A_BUSREQ */ 1486 /* caller must suspend then clear A_BUSREQ */
1454 usb_gadget_vbus_connect(isp->otg.gadget); 1487 usb_gadget_vbus_connect(isp->otg.gadget);
1455 OTG_CTRL_REG |= OTG_A_SETB_HNPEN; 1488 l = omap_readl(OTG_CTRL);
1489 l |= OTG_A_SETB_HNPEN;
1490 omap_writel(l, OTG_CTRL);
1456 1491
1457 break; 1492 break;
1458 case OTG_STATE_A_PERIPHERAL: 1493 case OTG_STATE_A_PERIPHERAL:
@@ -1462,7 +1497,7 @@ isp1301_start_hnp(struct otg_transceiver *dev)
1462 return -EILSEQ; 1497 return -EILSEQ;
1463 } 1498 }
1464 pr_debug("otg: HNP %s, %06x ...\n", 1499 pr_debug("otg: HNP %s, %06x ...\n",
1465 state_name(isp), OTG_CTRL_REG); 1500 state_name(isp), omap_readl(OTG_CTRL));
1466 check_state(isp, __func__); 1501 check_state(isp, __func__);
1467 return 0; 1502 return 0;
1468#else 1503#else
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c
index fb7ea5637eca..033d9d81ec8a 100644
--- a/drivers/i2c/chips/max6875.c
+++ b/drivers/i2c/chips/max6875.c
@@ -53,7 +53,7 @@ I2C_CLIENT_INSMOD_1(max6875);
53 53
54/* Each client has this additional data */ 54/* Each client has this additional data */
55struct max6875_data { 55struct max6875_data {
56 struct i2c_client client; 56 struct i2c_client *fake_client;
57 struct mutex update_lock; 57 struct mutex update_lock;
58 58
59 u32 valid; 59 u32 valid;
@@ -61,19 +61,6 @@ struct max6875_data {
61 unsigned long last_updated[USER_EEPROM_SLICES]; 61 unsigned long last_updated[USER_EEPROM_SLICES];
62}; 62};
63 63
64static int max6875_attach_adapter(struct i2c_adapter *adapter);
65static int max6875_detect(struct i2c_adapter *adapter, int address, int kind);
66static int max6875_detach_client(struct i2c_client *client);
67
68/* This is the driver that will be inserted */
69static struct i2c_driver max6875_driver = {
70 .driver = {
71 .name = "max6875",
72 },
73 .attach_adapter = max6875_attach_adapter,
74 .detach_client = max6875_detach_client,
75};
76
77static void max6875_update_slice(struct i2c_client *client, int slice) 64static void max6875_update_slice(struct i2c_client *client, int slice)
78{ 65{
79 struct max6875_data *data = i2c_get_clientdata(client); 66 struct max6875_data *data = i2c_get_clientdata(client);
@@ -159,101 +146,87 @@ static struct bin_attribute user_eeprom_attr = {
159 .read = max6875_read, 146 .read = max6875_read,
160}; 147};
161 148
162static int max6875_attach_adapter(struct i2c_adapter *adapter) 149/* Return 0 if detection is successful, -ENODEV otherwise */
150static int max6875_detect(struct i2c_client *client, int kind,
151 struct i2c_board_info *info)
163{ 152{
164 return i2c_probe(adapter, &addr_data, max6875_detect); 153 struct i2c_adapter *adapter = client->adapter;
165}
166
167/* This function is called by i2c_probe */
168static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
169{
170 struct i2c_client *real_client;
171 struct i2c_client *fake_client;
172 struct max6875_data *data;
173 int err = 0;
174 154
175 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA 155 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE_DATA
176 | I2C_FUNC_SMBUS_READ_BYTE)) 156 | I2C_FUNC_SMBUS_READ_BYTE))
177 return 0; 157 return -ENODEV;
178 158
179 /* Only check even addresses */ 159 /* Only check even addresses */
180 if (address & 1) 160 if (client->addr & 1)
181 return 0; 161 return -ENODEV;
162
163 strlcpy(info->type, "max6875", I2C_NAME_SIZE);
164
165 return 0;
166}
167
168static int max6875_probe(struct i2c_client *client,
169 const struct i2c_device_id *id)
170{
171 struct max6875_data *data;
172 int err;
182 173
183 if (!(data = kzalloc(sizeof(struct max6875_data), GFP_KERNEL))) 174 if (!(data = kzalloc(sizeof(struct max6875_data), GFP_KERNEL)))
184 return -ENOMEM; 175 return -ENOMEM;
185 176
186 /* A fake client is created on the odd address */ 177 /* A fake client is created on the odd address */
187 if (!(fake_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) { 178 data->fake_client = i2c_new_dummy(client->adapter, client->addr + 1);
179 if (!data->fake_client) {
188 err = -ENOMEM; 180 err = -ENOMEM;
189 goto exit_kfree1; 181 goto exit_kfree;
190 } 182 }
191 183
192 /* Init real i2c_client */ 184 /* Init real i2c_client */
193 real_client = &data->client; 185 i2c_set_clientdata(client, data);
194 i2c_set_clientdata(real_client, data);
195 real_client->addr = address;
196 real_client->adapter = adapter;
197 real_client->driver = &max6875_driver;
198 real_client->flags = 0;
199 strlcpy(real_client->name, "max6875", I2C_NAME_SIZE);
200 mutex_init(&data->update_lock); 186 mutex_init(&data->update_lock);
201 187
202 /* Init fake client data */ 188 err = sysfs_create_bin_file(&client->dev.kobj, &user_eeprom_attr);
203 i2c_set_clientdata(fake_client, NULL);
204 fake_client->addr = address | 1;
205 fake_client->adapter = adapter;
206 fake_client->driver = &max6875_driver;
207 fake_client->flags = 0;
208 strlcpy(fake_client->name, "max6875 subclient", I2C_NAME_SIZE);
209
210 /* Prevent 24RF08 corruption (in case of user error) */
211 i2c_smbus_write_quick(real_client, 0);
212
213 if ((err = i2c_attach_client(real_client)) != 0)
214 goto exit_kfree2;
215
216 if ((err = i2c_attach_client(fake_client)) != 0)
217 goto exit_detach1;
218
219 err = sysfs_create_bin_file(&real_client->dev.kobj, &user_eeprom_attr);
220 if (err) 189 if (err)
221 goto exit_detach2; 190 goto exit_remove_fake;
222 191
223 return 0; 192 return 0;
224 193
225exit_detach2: 194exit_remove_fake:
226 i2c_detach_client(fake_client); 195 i2c_unregister_device(data->fake_client);
227exit_detach1: 196exit_kfree:
228 i2c_detach_client(real_client);
229exit_kfree2:
230 kfree(fake_client);
231exit_kfree1:
232 kfree(data); 197 kfree(data);
233 return err; 198 return err;
234} 199}
235 200
236/* Will be called for both the real client and the fake client */ 201static int max6875_remove(struct i2c_client *client)
237static int max6875_detach_client(struct i2c_client *client)
238{ 202{
239 int err;
240 struct max6875_data *data = i2c_get_clientdata(client); 203 struct max6875_data *data = i2c_get_clientdata(client);
241 204
242 /* data is NULL for the fake client */ 205 i2c_unregister_device(data->fake_client);
243 if (data)
244 sysfs_remove_bin_file(&client->dev.kobj, &user_eeprom_attr);
245 206
246 err = i2c_detach_client(client); 207 sysfs_remove_bin_file(&client->dev.kobj, &user_eeprom_attr);
247 if (err) 208 kfree(data);
248 return err;
249 209
250 if (data) /* real client */
251 kfree(data);
252 else /* fake client */
253 kfree(client);
254 return 0; 210 return 0;
255} 211}
256 212
213static const struct i2c_device_id max6875_id[] = {
214 { "max6875", 0 },
215 { }
216};
217
218static struct i2c_driver max6875_driver = {
219 .driver = {
220 .name = "max6875",
221 },
222 .probe = max6875_probe,
223 .remove = max6875_remove,
224 .id_table = max6875_id,
225
226 .detect = max6875_detect,
227 .address_data = &addr_data,
228};
229
257static int __init max6875_init(void) 230static int __init max6875_init(void)
258{ 231{
259 return i2c_add_driver(&max6875_driver); 232 return i2c_add_driver(&max6875_driver);
diff --git a/drivers/i2c/chips/pca9539.c b/drivers/i2c/chips/pca9539.c
index f43c4e79b55e..270de4e56a81 100644
--- a/drivers/i2c/chips/pca9539.c
+++ b/drivers/i2c/chips/pca9539.c
@@ -14,8 +14,8 @@
14#include <linux/i2c.h> 14#include <linux/i2c.h>
15#include <linux/hwmon-sysfs.h> 15#include <linux/hwmon-sysfs.h>
16 16
17/* Addresses to scan */ 17/* Addresses to scan: none, device is not autodetected */
18static unsigned short normal_i2c[] = {0x74, 0x75, 0x76, 0x77, I2C_CLIENT_END}; 18static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
19 19
20/* Insmod parameters */ 20/* Insmod parameters */
21I2C_CLIENT_INSMOD_1(pca9539); 21I2C_CLIENT_INSMOD_1(pca9539);
@@ -32,23 +32,6 @@ enum pca9539_cmd
32 PCA9539_DIRECTION_1 = 7, 32 PCA9539_DIRECTION_1 = 7,
33}; 33};
34 34
35static int pca9539_attach_adapter(struct i2c_adapter *adapter);
36static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind);
37static int pca9539_detach_client(struct i2c_client *client);
38
39/* This is the driver that will be inserted */
40static struct i2c_driver pca9539_driver = {
41 .driver = {
42 .name = "pca9539",
43 },
44 .attach_adapter = pca9539_attach_adapter,
45 .detach_client = pca9539_detach_client,
46};
47
48struct pca9539_data {
49 struct i2c_client client;
50};
51
52/* following are the sysfs callback functions */ 35/* following are the sysfs callback functions */
53static ssize_t pca9539_show(struct device *dev, struct device_attribute *attr, 36static ssize_t pca9539_show(struct device *dev, struct device_attribute *attr,
54 char *buf) 37 char *buf)
@@ -105,78 +88,51 @@ static struct attribute_group pca9539_defattr_group = {
105 .attrs = pca9539_attributes, 88 .attrs = pca9539_attributes,
106}; 89};
107 90
108static int pca9539_attach_adapter(struct i2c_adapter *adapter) 91/* Return 0 if detection is successful, -ENODEV otherwise */
92static int pca9539_detect(struct i2c_client *client, int kind,
93 struct i2c_board_info *info)
109{ 94{
110 return i2c_probe(adapter, &addr_data, pca9539_detect); 95 struct i2c_adapter *adapter = client->adapter;
111}
112
113/* This function is called by i2c_probe */
114static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind)
115{
116 struct i2c_client *new_client;
117 struct pca9539_data *data;
118 int err = 0;
119 96
120 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 97 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
121 goto exit; 98 return -ENODEV;
122
123 /* OK. For now, we presume we have a valid client. We now create the
124 client structure, even though we cannot fill it completely yet. */
125 if (!(data = kzalloc(sizeof(struct pca9539_data), GFP_KERNEL))) {
126 err = -ENOMEM;
127 goto exit;
128 }
129
130 new_client = &data->client;
131 i2c_set_clientdata(new_client, data);
132 new_client->addr = address;
133 new_client->adapter = adapter;
134 new_client->driver = &pca9539_driver;
135 new_client->flags = 0;
136
137 if (kind < 0) {
138 /* Detection: the pca9539 only has 8 registers (0-7).
139 A read of 7 should succeed, but a read of 8 should fail. */
140 if ((i2c_smbus_read_byte_data(new_client, 7) < 0) ||
141 (i2c_smbus_read_byte_data(new_client, 8) >= 0))
142 goto exit_kfree;
143 }
144
145 strlcpy(new_client->name, "pca9539", I2C_NAME_SIZE);
146
147 /* Tell the I2C layer a new client has arrived */
148 if ((err = i2c_attach_client(new_client)))
149 goto exit_kfree;
150 99
151 /* Register sysfs hooks */ 100 strlcpy(info->type, "pca9539", I2C_NAME_SIZE);
152 err = sysfs_create_group(&new_client->dev.kobj,
153 &pca9539_defattr_group);
154 if (err)
155 goto exit_detach;
156 101
157 return 0; 102 return 0;
158
159exit_detach:
160 i2c_detach_client(new_client);
161exit_kfree:
162 kfree(data);
163exit:
164 return err;
165} 103}
166 104
167static int pca9539_detach_client(struct i2c_client *client) 105static int pca9539_probe(struct i2c_client *client,
106 const struct i2c_device_id *id)
168{ 107{
169 int err; 108 /* Register sysfs hooks */
109 return sysfs_create_group(&client->dev.kobj,
110 &pca9539_defattr_group);
111}
170 112
113static int pca9539_remove(struct i2c_client *client)
114{
171 sysfs_remove_group(&client->dev.kobj, &pca9539_defattr_group); 115 sysfs_remove_group(&client->dev.kobj, &pca9539_defattr_group);
172
173 if ((err = i2c_detach_client(client)))
174 return err;
175
176 kfree(i2c_get_clientdata(client));
177 return 0; 116 return 0;
178} 117}
179 118
119static const struct i2c_device_id pca9539_id[] = {
120 { "pca9539", 0 },
121 { }
122};
123
124static struct i2c_driver pca9539_driver = {
125 .driver = {
126 .name = "pca9539",
127 },
128 .probe = pca9539_probe,
129 .remove = pca9539_remove,
130 .id_table = pca9539_id,
131
132 .detect = pca9539_detect,
133 .address_data = &addr_data,
134};
135
180static int __init pca9539_init(void) 136static int __init pca9539_init(void)
181{ 137{
182 return i2c_add_driver(&pca9539_driver); 138 return i2c_add_driver(&pca9539_driver);
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c
index e5b31329b56e..6ec309894c88 100644
--- a/drivers/i2c/chips/pcf8574.c
+++ b/drivers/i2c/chips/pcf8574.c
@@ -1,6 +1,4 @@
1/* 1/*
2 pcf8574.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl>, 2 Copyright (c) 2000 Frodo Looijaard <frodol@dds.nl>,
5 Philip Edelbrock <phil@netroedge.com>, 3 Philip Edelbrock <phil@netroedge.com>,
6 Dan Eaton <dan.eaton@rocketlogix.com> 4 Dan Eaton <dan.eaton@rocketlogix.com>
@@ -40,37 +38,19 @@
40#include <linux/slab.h> 38#include <linux/slab.h>
41#include <linux/i2c.h> 39#include <linux/i2c.h>
42 40
43/* Addresses to scan */ 41/* Addresses to scan: none, device can't be detected */
44static const unsigned short normal_i2c[] = { 42static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
45 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
46 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
47 I2C_CLIENT_END
48};
49 43
50/* Insmod parameters */ 44/* Insmod parameters */
51I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a); 45I2C_CLIENT_INSMOD_2(pcf8574, pcf8574a);
52 46
53/* Each client has this additional data */ 47/* Each client has this additional data */
54struct pcf8574_data { 48struct pcf8574_data {
55 struct i2c_client client;
56
57 int write; /* Remember last written value */ 49 int write; /* Remember last written value */
58}; 50};
59 51
60static int pcf8574_attach_adapter(struct i2c_adapter *adapter);
61static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind);
62static int pcf8574_detach_client(struct i2c_client *client);
63static void pcf8574_init_client(struct i2c_client *client); 52static void pcf8574_init_client(struct i2c_client *client);
64 53
65/* This is the driver that will be inserted */
66static struct i2c_driver pcf8574_driver = {
67 .driver = {
68 .name = "pcf8574",
69 },
70 .attach_adapter = pcf8574_attach_adapter,
71 .detach_client = pcf8574_detach_client,
72};
73
74/* following are the sysfs callback functions */ 54/* following are the sysfs callback functions */
75static ssize_t show_read(struct device *dev, struct device_attribute *attr, char *buf) 55static ssize_t show_read(struct device *dev, struct device_attribute *attr, char *buf)
76{ 56{
@@ -121,42 +101,22 @@ static const struct attribute_group pcf8574_attr_group = {
121 * Real code 101 * Real code
122 */ 102 */
123 103
124static int pcf8574_attach_adapter(struct i2c_adapter *adapter) 104/* Return 0 if detection is successful, -ENODEV otherwise */
125{ 105static int pcf8574_detect(struct i2c_client *client, int kind,
126 return i2c_probe(adapter, &addr_data, pcf8574_detect); 106 struct i2c_board_info *info)
127}
128
129/* This function is called by i2c_probe */
130static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
131{ 107{
132 struct i2c_client *new_client; 108 struct i2c_adapter *adapter = client->adapter;
133 struct pcf8574_data *data; 109 const char *client_name;
134 int err = 0;
135 const char *client_name = "";
136 110
137 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE)) 111 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE))
138 goto exit; 112 return -ENODEV;
139
140 /* OK. For now, we presume we have a valid client. We now create the
141 client structure, even though we cannot fill it completely yet. */
142 if (!(data = kzalloc(sizeof(struct pcf8574_data), GFP_KERNEL))) {
143 err = -ENOMEM;
144 goto exit;
145 }
146
147 new_client = &data->client;
148 i2c_set_clientdata(new_client, data);
149 new_client->addr = address;
150 new_client->adapter = adapter;
151 new_client->driver = &pcf8574_driver;
152 new_client->flags = 0;
153 113
154 /* Now, we would do the remaining detection. But the PCF8574 is plainly 114 /* Now, we would do the remaining detection. But the PCF8574 is plainly
155 impossible to detect! Stupid chip. */ 115 impossible to detect! Stupid chip. */
156 116
157 /* Determine the chip type */ 117 /* Determine the chip type */
158 if (kind <= 0) { 118 if (kind <= 0) {
159 if (address >= 0x38 && address <= 0x3f) 119 if (client->addr >= 0x38 && client->addr <= 0x3f)
160 kind = pcf8574a; 120 kind = pcf8574a;
161 else 121 else
162 kind = pcf8574; 122 kind = pcf8574;
@@ -166,40 +126,43 @@ static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
166 client_name = "pcf8574a"; 126 client_name = "pcf8574a";
167 else 127 else
168 client_name = "pcf8574"; 128 client_name = "pcf8574";
129 strlcpy(info->type, client_name, I2C_NAME_SIZE);
169 130
170 /* Fill in the remaining client fields and put it into the global list */ 131 return 0;
171 strlcpy(new_client->name, client_name, I2C_NAME_SIZE); 132}
133
134static int pcf8574_probe(struct i2c_client *client,
135 const struct i2c_device_id *id)
136{
137 struct pcf8574_data *data;
138 int err;
139
140 data = kzalloc(sizeof(struct pcf8574_data), GFP_KERNEL);
141 if (!data) {
142 err = -ENOMEM;
143 goto exit;
144 }
145
146 i2c_set_clientdata(client, data);
172 147
173 /* Tell the I2C layer a new client has arrived */
174 if ((err = i2c_attach_client(new_client)))
175 goto exit_free;
176
177 /* Initialize the PCF8574 chip */ 148 /* Initialize the PCF8574 chip */
178 pcf8574_init_client(new_client); 149 pcf8574_init_client(client);
179 150
180 /* Register sysfs hooks */ 151 /* Register sysfs hooks */
181 err = sysfs_create_group(&new_client->dev.kobj, &pcf8574_attr_group); 152 err = sysfs_create_group(&client->dev.kobj, &pcf8574_attr_group);
182 if (err) 153 if (err)
183 goto exit_detach; 154 goto exit_free;
184 return 0; 155 return 0;
185 156
186 exit_detach:
187 i2c_detach_client(new_client);
188 exit_free: 157 exit_free:
189 kfree(data); 158 kfree(data);
190 exit: 159 exit:
191 return err; 160 return err;
192} 161}
193 162
194static int pcf8574_detach_client(struct i2c_client *client) 163static int pcf8574_remove(struct i2c_client *client)
195{ 164{
196 int err;
197
198 sysfs_remove_group(&client->dev.kobj, &pcf8574_attr_group); 165 sysfs_remove_group(&client->dev.kobj, &pcf8574_attr_group);
199
200 if ((err = i2c_detach_client(client)))
201 return err;
202
203 kfree(i2c_get_clientdata(client)); 166 kfree(i2c_get_clientdata(client));
204 return 0; 167 return 0;
205} 168}
@@ -211,6 +174,24 @@ static void pcf8574_init_client(struct i2c_client *client)
211 data->write = -EAGAIN; 174 data->write = -EAGAIN;
212} 175}
213 176
177static const struct i2c_device_id pcf8574_id[] = {
178 { "pcf8574", 0 },
179 { "pcf8574a", 0 },
180 { }
181};
182
183static struct i2c_driver pcf8574_driver = {
184 .driver = {
185 .name = "pcf8574",
186 },
187 .probe = pcf8574_probe,
188 .remove = pcf8574_remove,
189 .id_table = pcf8574_id,
190
191 .detect = pcf8574_detect,
192 .address_data = &addr_data,
193};
194
214static int __init pcf8574_init(void) 195static int __init pcf8574_init(void)
215{ 196{
216 return i2c_add_driver(&pcf8574_driver); 197 return i2c_add_driver(&pcf8574_driver);
diff --git a/drivers/i2c/chips/pcf8575.c b/drivers/i2c/chips/pcf8575.c
index 3ea08ac0bfa3..07fd7cb3c57d 100644
--- a/drivers/i2c/chips/pcf8575.c
+++ b/drivers/i2c/chips/pcf8575.c
@@ -32,11 +32,8 @@
32#include <linux/slab.h> /* kzalloc() */ 32#include <linux/slab.h> /* kzalloc() */
33#include <linux/sysfs.h> /* sysfs_create_group() */ 33#include <linux/sysfs.h> /* sysfs_create_group() */
34 34
35/* Addresses to scan */ 35/* Addresses to scan: none, device can't be detected */
36static const unsigned short normal_i2c[] = { 36static const unsigned short normal_i2c[] = { I2C_CLIENT_END };
37 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
38 I2C_CLIENT_END
39};
40 37
41/* Insmod parameters */ 38/* Insmod parameters */
42I2C_CLIENT_INSMOD; 39I2C_CLIENT_INSMOD;
@@ -44,24 +41,9 @@ I2C_CLIENT_INSMOD;
44 41
45/* Each client has this additional data */ 42/* Each client has this additional data */
46struct pcf8575_data { 43struct pcf8575_data {
47 struct i2c_client client;
48 int write; /* last written value, or error code */ 44 int write; /* last written value, or error code */
49}; 45};
50 46
51static int pcf8575_attach_adapter(struct i2c_adapter *adapter);
52static int pcf8575_detect(struct i2c_adapter *adapter, int address, int kind);
53static int pcf8575_detach_client(struct i2c_client *client);
54
55/* This is the driver that will be inserted */
56static struct i2c_driver pcf8575_driver = {
57 .driver = {
58 .owner = THIS_MODULE,
59 .name = "pcf8575",
60 },
61 .attach_adapter = pcf8575_attach_adapter,
62 .detach_client = pcf8575_detach_client,
63};
64
65/* following are the sysfs callback functions */ 47/* following are the sysfs callback functions */
66static ssize_t show_read(struct device *dev, struct device_attribute *attr, 48static ssize_t show_read(struct device *dev, struct device_attribute *attr,
67 char *buf) 49 char *buf)
@@ -126,75 +108,77 @@ static const struct attribute_group pcf8575_attr_group = {
126 * Real code 108 * Real code
127 */ 109 */
128 110
129static int pcf8575_attach_adapter(struct i2c_adapter *adapter) 111/* Return 0 if detection is successful, -ENODEV otherwise */
112static int pcf8575_detect(struct i2c_client *client, int kind,
113 struct i2c_board_info *info)
130{ 114{
131 return i2c_probe(adapter, &addr_data, pcf8575_detect); 115 struct i2c_adapter *adapter = client->adapter;
116
117 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
118 return -ENODEV;
119
120 /* This is the place to detect whether the chip at the specified
121 address really is a PCF8575 chip. However, there is no method known
122 to detect whether an I2C chip is a PCF8575 or any other I2C chip. */
123
124 strlcpy(info->type, "pcf8575", I2C_NAME_SIZE);
125
126 return 0;
132} 127}
133 128
134/* This function is called by i2c_probe */ 129static int pcf8575_probe(struct i2c_client *client,
135static int pcf8575_detect(struct i2c_adapter *adapter, int address, int kind) 130 const struct i2c_device_id *id)
136{ 131{
137 struct i2c_client *client;
138 struct pcf8575_data *data; 132 struct pcf8575_data *data;
139 int err = 0; 133 int err;
140
141 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C))
142 goto exit;
143 134
144 /* OK. For now, we presume we have a valid client. We now create the
145 client structure, even though we cannot fill it completely yet. */
146 data = kzalloc(sizeof(struct pcf8575_data), GFP_KERNEL); 135 data = kzalloc(sizeof(struct pcf8575_data), GFP_KERNEL);
147 if (!data) { 136 if (!data) {
148 err = -ENOMEM; 137 err = -ENOMEM;
149 goto exit; 138 goto exit;
150 } 139 }
151 140
152 client = &data->client;
153 i2c_set_clientdata(client, data); 141 i2c_set_clientdata(client, data);
154 client->addr = address;
155 client->adapter = adapter;
156 client->driver = &pcf8575_driver;
157 strlcpy(client->name, "pcf8575", I2C_NAME_SIZE);
158 data->write = -EAGAIN; 142 data->write = -EAGAIN;
159 143
160 /* This is the place to detect whether the chip at the specified
161 address really is a PCF8575 chip. However, there is no method known
162 to detect whether an I2C chip is a PCF8575 or any other I2C chip. */
163
164 /* Tell the I2C layer a new client has arrived */
165 err = i2c_attach_client(client);
166 if (err)
167 goto exit_free;
168
169 /* Register sysfs hooks */ 144 /* Register sysfs hooks */
170 err = sysfs_create_group(&client->dev.kobj, &pcf8575_attr_group); 145 err = sysfs_create_group(&client->dev.kobj, &pcf8575_attr_group);
171 if (err) 146 if (err)
172 goto exit_detach; 147 goto exit_free;
173 148
174 return 0; 149 return 0;
175 150
176exit_detach:
177 i2c_detach_client(client);
178exit_free: 151exit_free:
179 kfree(data); 152 kfree(data);
180exit: 153exit:
181 return err; 154 return err;
182} 155}
183 156
184static int pcf8575_detach_client(struct i2c_client *client) 157static int pcf8575_remove(struct i2c_client *client)
185{ 158{
186 int err;
187
188 sysfs_remove_group(&client->dev.kobj, &pcf8575_attr_group); 159 sysfs_remove_group(&client->dev.kobj, &pcf8575_attr_group);
189
190 err = i2c_detach_client(client);
191 if (err)
192 return err;
193
194 kfree(i2c_get_clientdata(client)); 160 kfree(i2c_get_clientdata(client));
195 return 0; 161 return 0;
196} 162}
197 163
164static const struct i2c_device_id pcf8575_id[] = {
165 { "pcf8575", 0 },
166 { }
167};
168
169static struct i2c_driver pcf8575_driver = {
170 .driver = {
171 .owner = THIS_MODULE,
172 .name = "pcf8575",
173 },
174 .probe = pcf8575_probe,
175 .remove = pcf8575_remove,
176 .id_table = pcf8575_id,
177
178 .detect = pcf8575_detect,
179 .address_data = &addr_data,
180};
181
198static int __init pcf8575_init(void) 182static int __init pcf8575_init(void)
199{ 183{
200 return i2c_add_driver(&pcf8575_driver); 184 return i2c_add_driver(&pcf8575_driver);
diff --git a/drivers/i2c/chips/pcf8591.c b/drivers/i2c/chips/pcf8591.c
index 66c7c3bb9429..16ce3e193776 100644
--- a/drivers/i2c/chips/pcf8591.c
+++ b/drivers/i2c/chips/pcf8591.c
@@ -1,6 +1,4 @@
1/* 1/*
2 pcf8591.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring
4 Copyright (C) 2001-2004 Aurelien Jarno <aurelien@aurel32.net> 2 Copyright (C) 2001-2004 Aurelien Jarno <aurelien@aurel32.net>
5 Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with 3 Ported to Linux 2.6 by Aurelien Jarno <aurelien@aurel32.net> with
6 the help of Jean Delvare <khali@linux-fr.org> 4 the help of Jean Delvare <khali@linux-fr.org>
@@ -74,28 +72,15 @@ MODULE_PARM_DESC(input_mode,
74#define REG_TO_SIGNED(reg) (((reg) & 0x80)?((reg) - 256):(reg)) 72#define REG_TO_SIGNED(reg) (((reg) & 0x80)?((reg) - 256):(reg))
75 73
76struct pcf8591_data { 74struct pcf8591_data {
77 struct i2c_client client;
78 struct mutex update_lock; 75 struct mutex update_lock;
79 76
80 u8 control; 77 u8 control;
81 u8 aout; 78 u8 aout;
82}; 79};
83 80
84static int pcf8591_attach_adapter(struct i2c_adapter *adapter);
85static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind);
86static int pcf8591_detach_client(struct i2c_client *client);
87static void pcf8591_init_client(struct i2c_client *client); 81static void pcf8591_init_client(struct i2c_client *client);
88static int pcf8591_read_channel(struct device *dev, int channel); 82static int pcf8591_read_channel(struct device *dev, int channel);
89 83
90/* This is the driver that will be inserted */
91static struct i2c_driver pcf8591_driver = {
92 .driver = {
93 .name = "pcf8591",
94 },
95 .attach_adapter = pcf8591_attach_adapter,
96 .detach_client = pcf8591_detach_client,
97};
98
99/* following are the sysfs callback functions */ 84/* following are the sysfs callback functions */
100#define show_in_channel(channel) \ 85#define show_in_channel(channel) \
101static ssize_t show_in##channel##_input(struct device *dev, struct device_attribute *attr, char *buf) \ 86static ssize_t show_in##channel##_input(struct device *dev, struct device_attribute *attr, char *buf) \
@@ -182,70 +167,57 @@ static const struct attribute_group pcf8591_attr_group_opt = {
182/* 167/*
183 * Real code 168 * Real code
184 */ 169 */
185static int pcf8591_attach_adapter(struct i2c_adapter *adapter)
186{
187 return i2c_probe(adapter, &addr_data, pcf8591_detect);
188}
189 170
190/* This function is called by i2c_probe */ 171/* Return 0 if detection is successful, -ENODEV otherwise */
191static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) 172static int pcf8591_detect(struct i2c_client *client, int kind,
173 struct i2c_board_info *info)
192{ 174{
193 struct i2c_client *new_client; 175 struct i2c_adapter *adapter = client->adapter;
194 struct pcf8591_data *data;
195 int err = 0;
196 176
197 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE 177 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE
198 | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) 178 | I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
199 goto exit; 179 return -ENODEV;
180
181 /* Now, we would do the remaining detection. But the PCF8591 is plainly
182 impossible to detect! Stupid chip. */
183
184 strlcpy(info->type, "pcf8591", I2C_NAME_SIZE);
185
186 return 0;
187}
188
189static int pcf8591_probe(struct i2c_client *client,
190 const struct i2c_device_id *id)
191{
192 struct pcf8591_data *data;
193 int err;
200 194
201 /* OK. For now, we presume we have a valid client. We now create the
202 client structure, even though we cannot fill it completely yet. */
203 if (!(data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) { 195 if (!(data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) {
204 err = -ENOMEM; 196 err = -ENOMEM;
205 goto exit; 197 goto exit;
206 } 198 }
207 199
208 new_client = &data->client; 200 i2c_set_clientdata(client, data);
209 i2c_set_clientdata(new_client, data);
210 new_client->addr = address;
211 new_client->adapter = adapter;
212 new_client->driver = &pcf8591_driver;
213 new_client->flags = 0;
214
215 /* Now, we would do the remaining detection. But the PCF8591 is plainly
216 impossible to detect! Stupid chip. */
217
218 /* Determine the chip type - only one kind supported! */
219 if (kind <= 0)
220 kind = pcf8591;
221
222 /* Fill in the remaining client fields and put it into the global
223 list */
224 strlcpy(new_client->name, "pcf8591", I2C_NAME_SIZE);
225 mutex_init(&data->update_lock); 201 mutex_init(&data->update_lock);
226 202
227 /* Tell the I2C layer a new client has arrived */
228 if ((err = i2c_attach_client(new_client)))
229 goto exit_kfree;
230
231 /* Initialize the PCF8591 chip */ 203 /* Initialize the PCF8591 chip */
232 pcf8591_init_client(new_client); 204 pcf8591_init_client(client);
233 205
234 /* Register sysfs hooks */ 206 /* Register sysfs hooks */
235 err = sysfs_create_group(&new_client->dev.kobj, &pcf8591_attr_group); 207 err = sysfs_create_group(&client->dev.kobj, &pcf8591_attr_group);
236 if (err) 208 if (err)
237 goto exit_detach; 209 goto exit_kfree;
238 210
239 /* Register input2 if not in "two differential inputs" mode */ 211 /* Register input2 if not in "two differential inputs" mode */
240 if (input_mode != 3) { 212 if (input_mode != 3) {
241 if ((err = device_create_file(&new_client->dev, 213 if ((err = device_create_file(&client->dev,
242 &dev_attr_in2_input))) 214 &dev_attr_in2_input)))
243 goto exit_sysfs_remove; 215 goto exit_sysfs_remove;
244 } 216 }
245 217
246 /* Register input3 only in "four single ended inputs" mode */ 218 /* Register input3 only in "four single ended inputs" mode */
247 if (input_mode == 0) { 219 if (input_mode == 0) {
248 if ((err = device_create_file(&new_client->dev, 220 if ((err = device_create_file(&client->dev,
249 &dev_attr_in3_input))) 221 &dev_attr_in3_input)))
250 goto exit_sysfs_remove; 222 goto exit_sysfs_remove;
251 } 223 }
@@ -253,26 +225,18 @@ static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind)
253 return 0; 225 return 0;
254 226
255exit_sysfs_remove: 227exit_sysfs_remove:
256 sysfs_remove_group(&new_client->dev.kobj, &pcf8591_attr_group_opt); 228 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt);
257 sysfs_remove_group(&new_client->dev.kobj, &pcf8591_attr_group); 229 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group);
258exit_detach:
259 i2c_detach_client(new_client);
260exit_kfree: 230exit_kfree:
261 kfree(data); 231 kfree(data);
262exit: 232exit:
263 return err; 233 return err;
264} 234}
265 235
266static int pcf8591_detach_client(struct i2c_client *client) 236static int pcf8591_remove(struct i2c_client *client)
267{ 237{
268 int err;
269
270 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt); 238 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group_opt);
271 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group); 239 sysfs_remove_group(&client->dev.kobj, &pcf8591_attr_group);
272
273 if ((err = i2c_detach_client(client)))
274 return err;
275
276 kfree(i2c_get_clientdata(client)); 240 kfree(i2c_get_clientdata(client));
277 return 0; 241 return 0;
278} 242}
@@ -319,6 +283,25 @@ static int pcf8591_read_channel(struct device *dev, int channel)
319 return (10 * value); 283 return (10 * value);
320} 284}
321 285
286static const struct i2c_device_id pcf8591_id[] = {
287 { "pcf8591", 0 },
288 { }
289};
290MODULE_DEVICE_TABLE(i2c, pcf8591_id);
291
292static struct i2c_driver pcf8591_driver = {
293 .driver = {
294 .name = "pcf8591",
295 },
296 .probe = pcf8591_probe,
297 .remove = pcf8591_remove,
298 .id_table = pcf8591_id,
299
300 .class = I2C_CLASS_HWMON, /* Nearest choice */
301 .detect = pcf8591_detect,
302 .address_data = &addr_data,
303};
304
322static int __init pcf8591_init(void) 305static int __init pcf8591_init(void)
323{ 306{
324 if (input_mode < 0 || input_mode > 3) { 307 if (input_mode < 0 || input_mode > 3) {
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
index 85949685191b..cf02e8fceb42 100644
--- a/drivers/i2c/chips/tps65010.c
+++ b/drivers/i2c/chips/tps65010.c
@@ -636,6 +636,8 @@ static int tps65010_probe(struct i2c_client *client,
636 tps->outmask = board->outmask; 636 tps->outmask = board->outmask;
637 637
638 tps->chip.label = client->name; 638 tps->chip.label = client->name;
639 tps->chip.dev = &client->dev;
640 tps->chip.owner = THIS_MODULE;
639 641
640 tps->chip.set = tps65010_gpio_set; 642 tps->chip.set = tps65010_gpio_set;
641 tps->chip.direction_output = tps65010_output; 643 tps->chip.direction_output = tps65010_output;
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 26384daccb96..7bf38c418086 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -29,13 +29,11 @@
29#include <linux/i2c.h> 29#include <linux/i2c.h>
30#include <linux/init.h> 30#include <linux/init.h>
31#include <linux/idr.h> 31#include <linux/idr.h>
32#include <linux/seq_file.h>
33#include <linux/platform_device.h> 32#include <linux/platform_device.h>
34#include <linux/mutex.h> 33#include <linux/mutex.h>
35#include <linux/completion.h> 34#include <linux/completion.h>
36#include <linux/hardirq.h> 35#include <linux/hardirq.h>
37#include <linux/irqflags.h> 36#include <linux/irqflags.h>
38#include <linux/semaphore.h>
39#include <asm/uaccess.h> 37#include <asm/uaccess.h>
40 38
41#include "i2c-core.h" 39#include "i2c-core.h"
@@ -44,7 +42,9 @@
44static DEFINE_MUTEX(core_lock); 42static DEFINE_MUTEX(core_lock);
45static DEFINE_IDR(i2c_adapter_idr); 43static DEFINE_IDR(i2c_adapter_idr);
46 44
47#define is_newstyle_driver(d) ((d)->probe || (d)->remove) 45#define is_newstyle_driver(d) ((d)->probe || (d)->remove || (d)->detect)
46
47static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver);
48 48
49/* ------------------------------------------------------------------------- */ 49/* ------------------------------------------------------------------------- */
50 50
@@ -74,10 +74,7 @@ static int i2c_device_match(struct device *dev, struct device_driver *drv)
74 if (driver->id_table) 74 if (driver->id_table)
75 return i2c_match_id(driver->id_table, client) != NULL; 75 return i2c_match_id(driver->id_table, client) != NULL;
76 76
77 /* new style drivers use the same kind of driver matching policy 77 return 0;
78 * as platform devices or SPI: compare device and driver IDs.
79 */
80 return strcmp(client->driver_name, drv->name) == 0;
81} 78}
82 79
83#ifdef CONFIG_HOTPLUG 80#ifdef CONFIG_HOTPLUG
@@ -91,14 +88,9 @@ static int i2c_device_uevent(struct device *dev, struct kobj_uevent_env *env)
91 if (dev->driver) 88 if (dev->driver)
92 return 0; 89 return 0;
93 90
94 if (client->driver_name[0]) { 91 if (add_uevent_var(env, "MODALIAS=%s%s",
95 if (add_uevent_var(env, "MODALIAS=%s", client->driver_name)) 92 I2C_MODULE_PREFIX, client->name))
96 return -ENOMEM; 93 return -ENOMEM;
97 } else {
98 if (add_uevent_var(env, "MODALIAS=%s%s",
99 I2C_MODULE_PREFIX, client->name))
100 return -ENOMEM;
101 }
102 dev_dbg(dev, "uevent\n"); 94 dev_dbg(dev, "uevent\n");
103 return 0; 95 return 0;
104} 96}
@@ -111,19 +103,14 @@ static int i2c_device_probe(struct device *dev)
111{ 103{
112 struct i2c_client *client = to_i2c_client(dev); 104 struct i2c_client *client = to_i2c_client(dev);
113 struct i2c_driver *driver = to_i2c_driver(dev->driver); 105 struct i2c_driver *driver = to_i2c_driver(dev->driver);
114 const struct i2c_device_id *id;
115 int status; 106 int status;
116 107
117 if (!driver->probe) 108 if (!driver->probe || !driver->id_table)
118 return -ENODEV; 109 return -ENODEV;
119 client->driver = driver; 110 client->driver = driver;
120 dev_dbg(dev, "probe\n"); 111 dev_dbg(dev, "probe\n");
121 112
122 if (driver->id_table) 113 status = driver->probe(client, i2c_match_id(driver->id_table, client));
123 id = i2c_match_id(driver->id_table, client);
124 else
125 id = NULL;
126 status = driver->probe(client, id);
127 if (status) 114 if (status)
128 client->driver = NULL; 115 client->driver = NULL;
129 return status; 116 return status;
@@ -206,9 +193,7 @@ static ssize_t show_client_name(struct device *dev, struct device_attribute *att
206static ssize_t show_modalias(struct device *dev, struct device_attribute *attr, char *buf) 193static ssize_t show_modalias(struct device *dev, struct device_attribute *attr, char *buf)
207{ 194{
208 struct i2c_client *client = to_i2c_client(dev); 195 struct i2c_client *client = to_i2c_client(dev);
209 return client->driver_name[0] 196 return sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name);
210 ? sprintf(buf, "%s\n", client->driver_name)
211 : sprintf(buf, "%s%s\n", I2C_MODULE_PREFIX, client->name);
212} 197}
213 198
214static struct device_attribute i2c_dev_attrs[] = { 199static struct device_attribute i2c_dev_attrs[] = {
@@ -218,7 +203,7 @@ static struct device_attribute i2c_dev_attrs[] = {
218 { }, 203 { },
219}; 204};
220 205
221static struct bus_type i2c_bus_type = { 206struct bus_type i2c_bus_type = {
222 .name = "i2c", 207 .name = "i2c",
223 .dev_attrs = i2c_dev_attrs, 208 .dev_attrs = i2c_dev_attrs,
224 .match = i2c_device_match, 209 .match = i2c_device_match,
@@ -229,6 +214,7 @@ static struct bus_type i2c_bus_type = {
229 .suspend = i2c_device_suspend, 214 .suspend = i2c_device_suspend,
230 .resume = i2c_device_resume, 215 .resume = i2c_device_resume,
231}; 216};
217EXPORT_SYMBOL_GPL(i2c_bus_type);
232 218
233 219
234/** 220/**
@@ -282,8 +268,6 @@ i2c_new_device(struct i2c_adapter *adap, struct i2c_board_info const *info)
282 client->addr = info->addr; 268 client->addr = info->addr;
283 client->irq = info->irq; 269 client->irq = info->irq;
284 270
285 strlcpy(client->driver_name, info->driver_name,
286 sizeof(client->driver_name));
287 strlcpy(client->name, info->type, sizeof(client->name)); 271 strlcpy(client->name, info->type, sizeof(client->name));
288 272
289 /* a new style driver may be bound to this device when we 273 /* a new style driver may be bound to this device when we
@@ -318,6 +302,14 @@ void i2c_unregister_device(struct i2c_client *client)
318 return; 302 return;
319 } 303 }
320 304
305 if (adapter->client_unregister) {
306 if (adapter->client_unregister(client)) {
307 dev_warn(&client->dev,
308 "client_unregister [%s] failed\n",
309 client->name);
310 }
311 }
312
321 mutex_lock(&adapter->clist_lock); 313 mutex_lock(&adapter->clist_lock);
322 list_del(&client->list); 314 list_del(&client->list);
323 mutex_unlock(&adapter->clist_lock); 315 mutex_unlock(&adapter->clist_lock);
@@ -327,6 +319,11 @@ void i2c_unregister_device(struct i2c_client *client)
327EXPORT_SYMBOL_GPL(i2c_unregister_device); 319EXPORT_SYMBOL_GPL(i2c_unregister_device);
328 320
329 321
322static const struct i2c_device_id dummy_id[] = {
323 { "dummy", 0 },
324 { },
325};
326
330static int dummy_probe(struct i2c_client *client, 327static int dummy_probe(struct i2c_client *client,
331 const struct i2c_device_id *id) 328 const struct i2c_device_id *id)
332{ 329{
@@ -342,13 +339,13 @@ static struct i2c_driver dummy_driver = {
342 .driver.name = "dummy", 339 .driver.name = "dummy",
343 .probe = dummy_probe, 340 .probe = dummy_probe,
344 .remove = dummy_remove, 341 .remove = dummy_remove,
342 .id_table = dummy_id,
345}; 343};
346 344
347/** 345/**
348 * i2c_new_dummy - return a new i2c device bound to a dummy driver 346 * i2c_new_dummy - return a new i2c device bound to a dummy driver
349 * @adapter: the adapter managing the device 347 * @adapter: the adapter managing the device
350 * @address: seven bit address to be used 348 * @address: seven bit address to be used
351 * @type: optional label used for i2c_client.name
352 * Context: can sleep 349 * Context: can sleep
353 * 350 *
354 * This returns an I2C client bound to the "dummy" driver, intended for use 351 * This returns an I2C client bound to the "dummy" driver, intended for use
@@ -364,15 +361,12 @@ static struct i2c_driver dummy_driver = {
364 * i2c_unregister_device(); or NULL to indicate an error. 361 * i2c_unregister_device(); or NULL to indicate an error.
365 */ 362 */
366struct i2c_client * 363struct i2c_client *
367i2c_new_dummy(struct i2c_adapter *adapter, u16 address, const char *type) 364i2c_new_dummy(struct i2c_adapter *adapter, u16 address)
368{ 365{
369 struct i2c_board_info info = { 366 struct i2c_board_info info = {
370 .driver_name = "dummy", 367 I2C_BOARD_INFO("dummy", address),
371 .addr = address,
372 }; 368 };
373 369
374 if (type)
375 strlcpy(info.type, type, sizeof info.type);
376 return i2c_new_device(adapter, &info); 370 return i2c_new_device(adapter, &info);
377} 371}
378EXPORT_SYMBOL_GPL(i2c_new_dummy); 372EXPORT_SYMBOL_GPL(i2c_new_dummy);
@@ -426,6 +420,10 @@ static int i2c_do_add_adapter(struct device_driver *d, void *data)
426 struct i2c_driver *driver = to_i2c_driver(d); 420 struct i2c_driver *driver = to_i2c_driver(d);
427 struct i2c_adapter *adap = data; 421 struct i2c_adapter *adap = data;
428 422
423 /* Detect supported devices on that bus, and instantiate them */
424 i2c_detect(adap, driver);
425
426 /* Let legacy drivers scan this bus for matching devices */
429 if (driver->attach_adapter) { 427 if (driver->attach_adapter) {
430 /* We ignore the return code; if it fails, too bad */ 428 /* We ignore the return code; if it fails, too bad */
431 driver->attach_adapter(adap); 429 driver->attach_adapter(adap);
@@ -465,7 +463,7 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
465 if (adap->nr < __i2c_first_dynamic_bus_num) 463 if (adap->nr < __i2c_first_dynamic_bus_num)
466 i2c_scan_static_board_info(adap); 464 i2c_scan_static_board_info(adap);
467 465
468 /* let legacy drivers scan this bus for matching devices */ 466 /* Notify drivers */
469 dummy = bus_for_each_drv(&i2c_bus_type, NULL, adap, 467 dummy = bus_for_each_drv(&i2c_bus_type, NULL, adap,
470 i2c_do_add_adapter); 468 i2c_do_add_adapter);
471 469
@@ -571,8 +569,19 @@ static int i2c_do_del_adapter(struct device_driver *d, void *data)
571{ 569{
572 struct i2c_driver *driver = to_i2c_driver(d); 570 struct i2c_driver *driver = to_i2c_driver(d);
573 struct i2c_adapter *adapter = data; 571 struct i2c_adapter *adapter = data;
572 struct i2c_client *client, *_n;
574 int res; 573 int res;
575 574
575 /* Remove the devices we created ourselves */
576 list_for_each_entry_safe(client, _n, &driver->clients, detected) {
577 if (client->adapter == adapter) {
578 dev_dbg(&adapter->dev, "Removing %s at 0x%x\n",
579 client->name, client->addr);
580 list_del(&client->detected);
581 i2c_unregister_device(client);
582 }
583 }
584
576 if (!driver->detach_adapter) 585 if (!driver->detach_adapter)
577 return 0; 586 return 0;
578 res = driver->detach_adapter(adapter); 587 res = driver->detach_adapter(adapter);
@@ -592,8 +601,7 @@ static int i2c_do_del_adapter(struct device_driver *d, void *data)
592 */ 601 */
593int i2c_del_adapter(struct i2c_adapter *adap) 602int i2c_del_adapter(struct i2c_adapter *adap)
594{ 603{
595 struct list_head *item, *_n; 604 struct i2c_client *client, *_n;
596 struct i2c_client *client;
597 int res = 0; 605 int res = 0;
598 606
599 mutex_lock(&core_lock); 607 mutex_lock(&core_lock);
@@ -614,10 +622,9 @@ int i2c_del_adapter(struct i2c_adapter *adap)
614 622
615 /* detach any active clients. This must be done first, because 623 /* detach any active clients. This must be done first, because
616 * it can fail; in which case we give up. */ 624 * it can fail; in which case we give up. */
617 list_for_each_safe(item, _n, &adap->clients) { 625 list_for_each_entry_safe(client, _n, &adap->clients, list) {
618 struct i2c_driver *driver; 626 struct i2c_driver *driver;
619 627
620 client = list_entry(item, struct i2c_client, list);
621 driver = client->driver; 628 driver = client->driver;
622 629
623 /* new style, follow standard driver model */ 630 /* new style, follow standard driver model */
@@ -647,6 +654,10 @@ int i2c_del_adapter(struct i2c_adapter *adap)
647 654
648 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name); 655 dev_dbg(&adap->dev, "adapter [%s] unregistered\n", adap->name);
649 656
657 /* Clear the device structure in case this adapter is ever going to be
658 added again */
659 memset(&adap->dev, 0, sizeof(adap->dev));
660
650 out_unlock: 661 out_unlock:
651 mutex_unlock(&core_lock); 662 mutex_unlock(&core_lock);
652 return res; 663 return res;
@@ -656,6 +667,20 @@ EXPORT_SYMBOL(i2c_del_adapter);
656 667
657/* ------------------------------------------------------------------------- */ 668/* ------------------------------------------------------------------------- */
658 669
670static int __attach_adapter(struct device *dev, void *data)
671{
672 struct i2c_adapter *adapter = to_i2c_adapter(dev);
673 struct i2c_driver *driver = data;
674
675 i2c_detect(adapter, driver);
676
677 /* Legacy drivers scan i2c busses directly */
678 if (driver->attach_adapter)
679 driver->attach_adapter(adapter);
680
681 return 0;
682}
683
659/* 684/*
660 * An i2c_driver is used with one or more i2c_client (device) nodes to access 685 * An i2c_driver is used with one or more i2c_client (device) nodes to access
661 * i2c slave chips, on a bus instance associated with some i2c_adapter. There 686 * i2c slave chips, on a bus instance associated with some i2c_adapter. There
@@ -695,72 +720,72 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
695 720
696 pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name); 721 pr_debug("i2c-core: driver [%s] registered\n", driver->driver.name);
697 722
698 /* legacy drivers scan i2c busses directly */ 723 INIT_LIST_HEAD(&driver->clients);
699 if (driver->attach_adapter) { 724 /* Walk the adapters that are already present */
700 struct i2c_adapter *adapter; 725 class_for_each_device(&i2c_adapter_class, NULL, driver,
701 726 __attach_adapter);
702 down(&i2c_adapter_class.sem);
703 list_for_each_entry(adapter, &i2c_adapter_class.devices,
704 dev.node) {
705 driver->attach_adapter(adapter);
706 }
707 up(&i2c_adapter_class.sem);
708 }
709 727
710 mutex_unlock(&core_lock); 728 mutex_unlock(&core_lock);
711 return 0; 729 return 0;
712} 730}
713EXPORT_SYMBOL(i2c_register_driver); 731EXPORT_SYMBOL(i2c_register_driver);
714 732
715/** 733static int __detach_adapter(struct device *dev, void *data)
716 * i2c_del_driver - unregister I2C driver
717 * @driver: the driver being unregistered
718 * Context: can sleep
719 */
720void i2c_del_driver(struct i2c_driver *driver)
721{ 734{
722 struct list_head *item2, *_n; 735 struct i2c_adapter *adapter = to_i2c_adapter(dev);
723 struct i2c_client *client; 736 struct i2c_driver *driver = data;
724 struct i2c_adapter *adap; 737 struct i2c_client *client, *_n;
725 738
726 mutex_lock(&core_lock); 739 list_for_each_entry_safe(client, _n, &driver->clients, detected) {
740 dev_dbg(&adapter->dev, "Removing %s at 0x%x\n",
741 client->name, client->addr);
742 list_del(&client->detected);
743 i2c_unregister_device(client);
744 }
727 745
728 /* new-style driver? */
729 if (is_newstyle_driver(driver)) 746 if (is_newstyle_driver(driver))
730 goto unregister; 747 return 0;
731 748
732 /* Have a look at each adapter, if clients of this driver are still 749 /* Have a look at each adapter, if clients of this driver are still
733 * attached. If so, detach them to be able to kill the driver 750 * attached. If so, detach them to be able to kill the driver
734 * afterwards. 751 * afterwards.
735 */ 752 */
736 down(&i2c_adapter_class.sem); 753 if (driver->detach_adapter) {
737 list_for_each_entry(adap, &i2c_adapter_class.devices, dev.node) { 754 if (driver->detach_adapter(adapter))
738 if (driver->detach_adapter) { 755 dev_err(&adapter->dev,
739 if (driver->detach_adapter(adap)) { 756 "detach_adapter failed for driver [%s]\n",
740 dev_err(&adap->dev, "detach_adapter failed " 757 driver->driver.name);
741 "for driver [%s]\n", 758 } else {
742 driver->driver.name); 759 struct i2c_client *client, *_n;
743 } 760
744 } else { 761 list_for_each_entry_safe(client, _n, &adapter->clients, list) {
745 list_for_each_safe(item2, _n, &adap->clients) { 762 if (client->driver != driver)
746 client = list_entry(item2, struct i2c_client, list); 763 continue;
747 if (client->driver != driver) 764 dev_dbg(&adapter->dev,
748 continue; 765 "detaching client [%s] at 0x%02x\n",
749 dev_dbg(&adap->dev, "detaching client [%s] " 766 client->name, client->addr);
750 "at 0x%02x\n", client->name, 767 if (driver->detach_client(client))
751 client->addr); 768 dev_err(&adapter->dev, "detach_client "
752 if (driver->detach_client(client)) { 769 "failed for client [%s] at 0x%02x\n",
753 dev_err(&adap->dev, "detach_client " 770 client->name, client->addr);
754 "failed for client [%s] at "
755 "0x%02x\n", client->name,
756 client->addr);
757 }
758 }
759 } 771 }
760 } 772 }
761 up(&i2c_adapter_class.sem);
762 773
763 unregister: 774 return 0;
775}
776
777/**
778 * i2c_del_driver - unregister I2C driver
779 * @driver: the driver being unregistered
780 * Context: can sleep
781 */
782void i2c_del_driver(struct i2c_driver *driver)
783{
784 mutex_lock(&core_lock);
785
786 class_for_each_device(&i2c_adapter_class, NULL, driver,
787 __detach_adapter);
788
764 driver_unregister(&driver->driver); 789 driver_unregister(&driver->driver);
765 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name); 790 pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
766 791
@@ -873,8 +898,9 @@ EXPORT_SYMBOL(i2c_detach_client);
873 */ 898 */
874struct i2c_client *i2c_use_client(struct i2c_client *client) 899struct i2c_client *i2c_use_client(struct i2c_client *client)
875{ 900{
876 get_device(&client->dev); 901 if (client && get_device(&client->dev))
877 return client; 902 return client;
903 return NULL;
878} 904}
879EXPORT_SYMBOL(i2c_use_client); 905EXPORT_SYMBOL(i2c_use_client);
880 906
@@ -886,7 +912,8 @@ EXPORT_SYMBOL(i2c_use_client);
886 */ 912 */
887void i2c_release_client(struct i2c_client *client) 913void i2c_release_client(struct i2c_client *client)
888{ 914{
889 put_device(&client->dev); 915 if (client)
916 put_device(&client->dev);
890} 917}
891EXPORT_SYMBOL(i2c_release_client); 918EXPORT_SYMBOL(i2c_release_client);
892 919
@@ -952,10 +979,39 @@ module_exit(i2c_exit);
952 * ---------------------------------------------------- 979 * ----------------------------------------------------
953 */ 980 */
954 981
982/**
983 * i2c_transfer - execute a single or combined I2C message
984 * @adap: Handle to I2C bus
985 * @msgs: One or more messages to execute before STOP is issued to
986 * terminate the operation; each message begins with a START.
987 * @num: Number of messages to be executed.
988 *
989 * Returns negative errno, else the number of messages executed.
990 *
991 * Note that there is no requirement that each message be sent to
992 * the same slave address, although that is the most common model.
993 */
955int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num) 994int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num)
956{ 995{
957 int ret; 996 int ret;
958 997
998 /* REVISIT the fault reporting model here is weak:
999 *
1000 * - When we get an error after receiving N bytes from a slave,
1001 * there is no way to report "N".
1002 *
1003 * - When we get a NAK after transmitting N bytes to a slave,
1004 * there is no way to report "N" ... or to let the master
1005 * continue executing the rest of this combined message, if
1006 * that's the appropriate response.
1007 *
1008 * - When for example "num" is two and we successfully complete
1009 * the first message but get an error part way through the
1010 * second, it's unclear whether that should be reported as
1011 * one (discarding status on the second message) or errno
1012 * (discarding status on the first one).
1013 */
1014
959 if (adap->algo->master_xfer) { 1015 if (adap->algo->master_xfer) {
960#ifdef DEBUG 1016#ifdef DEBUG
961 for (ret = 0; ret < num; ret++) { 1017 for (ret = 0; ret < num; ret++) {
@@ -981,11 +1037,19 @@ int i2c_transfer(struct i2c_adapter * adap, struct i2c_msg *msgs, int num)
981 return ret; 1037 return ret;
982 } else { 1038 } else {
983 dev_dbg(&adap->dev, "I2C level transfers not supported\n"); 1039 dev_dbg(&adap->dev, "I2C level transfers not supported\n");
984 return -ENOSYS; 1040 return -EOPNOTSUPP;
985 } 1041 }
986} 1042}
987EXPORT_SYMBOL(i2c_transfer); 1043EXPORT_SYMBOL(i2c_transfer);
988 1044
1045/**
1046 * i2c_master_send - issue a single I2C message in master transmit mode
1047 * @client: Handle to slave device
1048 * @buf: Data that will be written to the slave
1049 * @count: How many bytes to write
1050 *
1051 * Returns negative errno, or else the number of bytes written.
1052 */
989int i2c_master_send(struct i2c_client *client,const char *buf ,int count) 1053int i2c_master_send(struct i2c_client *client,const char *buf ,int count)
990{ 1054{
991 int ret; 1055 int ret;
@@ -1005,6 +1069,14 @@ int i2c_master_send(struct i2c_client *client,const char *buf ,int count)
1005} 1069}
1006EXPORT_SYMBOL(i2c_master_send); 1070EXPORT_SYMBOL(i2c_master_send);
1007 1071
1072/**
1073 * i2c_master_recv - issue a single I2C message in master receive mode
1074 * @client: Handle to slave device
1075 * @buf: Where to store data read from slave
1076 * @count: How many bytes to read
1077 *
1078 * Returns negative errno, or else the number of bytes read.
1079 */
1008int i2c_master_recv(struct i2c_client *client, char *buf ,int count) 1080int i2c_master_recv(struct i2c_client *client, char *buf ,int count)
1009{ 1081{
1010 struct i2c_adapter *adap=client->adapter; 1082 struct i2c_adapter *adap=client->adapter;
@@ -1113,7 +1185,7 @@ int i2c_probe(struct i2c_adapter *adapter,
1113 1185
1114 dev_warn(&adapter->dev, "SMBus Quick command not supported, " 1186 dev_warn(&adapter->dev, "SMBus Quick command not supported, "
1115 "can't probe for chips\n"); 1187 "can't probe for chips\n");
1116 return -1; 1188 return -EOPNOTSUPP;
1117 } 1189 }
1118 1190
1119 /* Probe entries are done second, and are not affected by ignore 1191 /* Probe entries are done second, and are not affected by ignore
@@ -1167,6 +1239,179 @@ int i2c_probe(struct i2c_adapter *adapter,
1167} 1239}
1168EXPORT_SYMBOL(i2c_probe); 1240EXPORT_SYMBOL(i2c_probe);
1169 1241
1242/* Separate detection function for new-style drivers */
1243static int i2c_detect_address(struct i2c_client *temp_client, int kind,
1244 struct i2c_driver *driver)
1245{
1246 struct i2c_board_info info;
1247 struct i2c_adapter *adapter = temp_client->adapter;
1248 int addr = temp_client->addr;
1249 int err;
1250
1251 /* Make sure the address is valid */
1252 if (addr < 0x03 || addr > 0x77) {
1253 dev_warn(&adapter->dev, "Invalid probe address 0x%02x\n",
1254 addr);
1255 return -EINVAL;
1256 }
1257
1258 /* Skip if already in use */
1259 if (i2c_check_addr(adapter, addr))
1260 return 0;
1261
1262 /* Make sure there is something at this address, unless forced */
1263 if (kind < 0) {
1264 if (i2c_smbus_xfer(adapter, addr, 0, 0, 0,
1265 I2C_SMBUS_QUICK, NULL) < 0)
1266 return 0;
1267
1268 /* prevent 24RF08 corruption */
1269 if ((addr & ~0x0f) == 0x50)
1270 i2c_smbus_xfer(adapter, addr, 0, 0, 0,
1271 I2C_SMBUS_QUICK, NULL);
1272 }
1273
1274 /* Finally call the custom detection function */
1275 memset(&info, 0, sizeof(struct i2c_board_info));
1276 info.addr = addr;
1277 err = driver->detect(temp_client, kind, &info);
1278 if (err) {
1279 /* -ENODEV is returned if the detection fails. We catch it
1280 here as this isn't an error. */
1281 return err == -ENODEV ? 0 : err;
1282 }
1283
1284 /* Consistency check */
1285 if (info.type[0] == '\0') {
1286 dev_err(&adapter->dev, "%s detection function provided "
1287 "no name for 0x%x\n", driver->driver.name,
1288 addr);
1289 } else {
1290 struct i2c_client *client;
1291
1292 /* Detection succeeded, instantiate the device */
1293 dev_dbg(&adapter->dev, "Creating %s at 0x%02x\n",
1294 info.type, info.addr);
1295 client = i2c_new_device(adapter, &info);
1296 if (client)
1297 list_add_tail(&client->detected, &driver->clients);
1298 else
1299 dev_err(&adapter->dev, "Failed creating %s at 0x%02x\n",
1300 info.type, info.addr);
1301 }
1302 return 0;
1303}
1304
1305static int i2c_detect(struct i2c_adapter *adapter, struct i2c_driver *driver)
1306{
1307 const struct i2c_client_address_data *address_data;
1308 struct i2c_client *temp_client;
1309 int i, err = 0;
1310 int adap_id = i2c_adapter_id(adapter);
1311
1312 address_data = driver->address_data;
1313 if (!driver->detect || !address_data)
1314 return 0;
1315
1316 /* Set up a temporary client to help detect callback */
1317 temp_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
1318 if (!temp_client)
1319 return -ENOMEM;
1320 temp_client->adapter = adapter;
1321
1322 /* Force entries are done first, and are not affected by ignore
1323 entries */
1324 if (address_data->forces) {
1325 const unsigned short * const *forces = address_data->forces;
1326 int kind;
1327
1328 for (kind = 0; forces[kind]; kind++) {
1329 for (i = 0; forces[kind][i] != I2C_CLIENT_END;
1330 i += 2) {
1331 if (forces[kind][i] == adap_id
1332 || forces[kind][i] == ANY_I2C_BUS) {
1333 dev_dbg(&adapter->dev, "found force "
1334 "parameter for adapter %d, "
1335 "addr 0x%02x, kind %d\n",
1336 adap_id, forces[kind][i + 1],
1337 kind);
1338 temp_client->addr = forces[kind][i + 1];
1339 err = i2c_detect_address(temp_client,
1340 kind, driver);
1341 if (err)
1342 goto exit_free;
1343 }
1344 }
1345 }
1346 }
1347
1348 /* Stop here if we can't use SMBUS_QUICK */
1349 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) {
1350 if (address_data->probe[0] == I2C_CLIENT_END
1351 && address_data->normal_i2c[0] == I2C_CLIENT_END)
1352 goto exit_free;
1353
1354 dev_warn(&adapter->dev, "SMBus Quick command not supported, "
1355 "can't probe for chips\n");
1356 err = -EOPNOTSUPP;
1357 goto exit_free;
1358 }
1359
1360 /* Stop here if the classes do not match */
1361 if (!(adapter->class & driver->class))
1362 goto exit_free;
1363
1364 /* Probe entries are done second, and are not affected by ignore
1365 entries either */
1366 for (i = 0; address_data->probe[i] != I2C_CLIENT_END; i += 2) {
1367 if (address_data->probe[i] == adap_id
1368 || address_data->probe[i] == ANY_I2C_BUS) {
1369 dev_dbg(&adapter->dev, "found probe parameter for "
1370 "adapter %d, addr 0x%02x\n", adap_id,
1371 address_data->probe[i + 1]);
1372 temp_client->addr = address_data->probe[i + 1];
1373 err = i2c_detect_address(temp_client, -1, driver);
1374 if (err)
1375 goto exit_free;
1376 }
1377 }
1378
1379 /* Normal entries are done last, unless shadowed by an ignore entry */
1380 for (i = 0; address_data->normal_i2c[i] != I2C_CLIENT_END; i += 1) {
1381 int j, ignore;
1382
1383 ignore = 0;
1384 for (j = 0; address_data->ignore[j] != I2C_CLIENT_END;
1385 j += 2) {
1386 if ((address_data->ignore[j] == adap_id ||
1387 address_data->ignore[j] == ANY_I2C_BUS)
1388 && address_data->ignore[j + 1]
1389 == address_data->normal_i2c[i]) {
1390 dev_dbg(&adapter->dev, "found ignore "
1391 "parameter for adapter %d, "
1392 "addr 0x%02x\n", adap_id,
1393 address_data->ignore[j + 1]);
1394 ignore = 1;
1395 break;
1396 }
1397 }
1398 if (ignore)
1399 continue;
1400
1401 dev_dbg(&adapter->dev, "found normal entry for adapter %d, "
1402 "addr 0x%02x\n", adap_id,
1403 address_data->normal_i2c[i]);
1404 temp_client->addr = address_data->normal_i2c[i];
1405 err = i2c_detect_address(temp_client, -1, driver);
1406 if (err)
1407 goto exit_free;
1408 }
1409
1410 exit_free:
1411 kfree(temp_client);
1412 return err;
1413}
1414
1170struct i2c_client * 1415struct i2c_client *
1171i2c_new_probed_device(struct i2c_adapter *adap, 1416i2c_new_probed_device(struct i2c_adapter *adap,
1172 struct i2c_board_info *info, 1417 struct i2c_board_info *info,
@@ -1305,29 +1550,38 @@ static int i2c_smbus_check_pec(u8 cpec, struct i2c_msg *msg)
1305 if (rpec != cpec) { 1550 if (rpec != cpec) {
1306 pr_debug("i2c-core: Bad PEC 0x%02x vs. 0x%02x\n", 1551 pr_debug("i2c-core: Bad PEC 0x%02x vs. 0x%02x\n",
1307 rpec, cpec); 1552 rpec, cpec);
1308 return -1; 1553 return -EBADMSG;
1309 } 1554 }
1310 return 0; 1555 return 0;
1311} 1556}
1312 1557
1313s32 i2c_smbus_write_quick(struct i2c_client *client, u8 value) 1558/**
1314{ 1559 * i2c_smbus_read_byte - SMBus "receive byte" protocol
1315 return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 1560 * @client: Handle to slave device
1316 value,0,I2C_SMBUS_QUICK,NULL); 1561 *
1317} 1562 * This executes the SMBus "receive byte" protocol, returning negative errno
1318EXPORT_SYMBOL(i2c_smbus_write_quick); 1563 * else the byte received from the device.
1319 1564 */
1320s32 i2c_smbus_read_byte(struct i2c_client *client) 1565s32 i2c_smbus_read_byte(struct i2c_client *client)
1321{ 1566{
1322 union i2c_smbus_data data; 1567 union i2c_smbus_data data;
1323 if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, 1568 int status;
1324 I2C_SMBUS_READ,0,I2C_SMBUS_BYTE, &data)) 1569
1325 return -1; 1570 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
1326 else 1571 I2C_SMBUS_READ, 0,
1327 return data.byte; 1572 I2C_SMBUS_BYTE, &data);
1573 return (status < 0) ? status : data.byte;
1328} 1574}
1329EXPORT_SYMBOL(i2c_smbus_read_byte); 1575EXPORT_SYMBOL(i2c_smbus_read_byte);
1330 1576
1577/**
1578 * i2c_smbus_write_byte - SMBus "send byte" protocol
1579 * @client: Handle to slave device
1580 * @value: Byte to be sent
1581 *
1582 * This executes the SMBus "send byte" protocol, returning negative errno
1583 * else zero on success.
1584 */
1331s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) 1585s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value)
1332{ 1586{
1333 return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 1587 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
@@ -1335,17 +1589,35 @@ s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value)
1335} 1589}
1336EXPORT_SYMBOL(i2c_smbus_write_byte); 1590EXPORT_SYMBOL(i2c_smbus_write_byte);
1337 1591
1592/**
1593 * i2c_smbus_read_byte_data - SMBus "read byte" protocol
1594 * @client: Handle to slave device
1595 * @command: Byte interpreted by slave
1596 *
1597 * This executes the SMBus "read byte" protocol, returning negative errno
1598 * else a data byte received from the device.
1599 */
1338s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command) 1600s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command)
1339{ 1601{
1340 union i2c_smbus_data data; 1602 union i2c_smbus_data data;
1341 if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, 1603 int status;
1342 I2C_SMBUS_READ,command, I2C_SMBUS_BYTE_DATA,&data)) 1604
1343 return -1; 1605 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
1344 else 1606 I2C_SMBUS_READ, command,
1345 return data.byte; 1607 I2C_SMBUS_BYTE_DATA, &data);
1608 return (status < 0) ? status : data.byte;
1346} 1609}
1347EXPORT_SYMBOL(i2c_smbus_read_byte_data); 1610EXPORT_SYMBOL(i2c_smbus_read_byte_data);
1348 1611
1612/**
1613 * i2c_smbus_write_byte_data - SMBus "write byte" protocol
1614 * @client: Handle to slave device
1615 * @command: Byte interpreted by slave
1616 * @value: Byte being written
1617 *
1618 * This executes the SMBus "write byte" protocol, returning negative errno
1619 * else zero on success.
1620 */
1349s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value) 1621s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value)
1350{ 1622{
1351 union i2c_smbus_data data; 1623 union i2c_smbus_data data;
@@ -1356,17 +1628,35 @@ s32 i2c_smbus_write_byte_data(struct i2c_client *client, u8 command, u8 value)
1356} 1628}
1357EXPORT_SYMBOL(i2c_smbus_write_byte_data); 1629EXPORT_SYMBOL(i2c_smbus_write_byte_data);
1358 1630
1631/**
1632 * i2c_smbus_read_word_data - SMBus "read word" protocol
1633 * @client: Handle to slave device
1634 * @command: Byte interpreted by slave
1635 *
1636 * This executes the SMBus "read word" protocol, returning negative errno
1637 * else a 16-bit unsigned "word" received from the device.
1638 */
1359s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command) 1639s32 i2c_smbus_read_word_data(struct i2c_client *client, u8 command)
1360{ 1640{
1361 union i2c_smbus_data data; 1641 union i2c_smbus_data data;
1362 if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, 1642 int status;
1363 I2C_SMBUS_READ,command, I2C_SMBUS_WORD_DATA, &data)) 1643
1364 return -1; 1644 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
1365 else 1645 I2C_SMBUS_READ, command,
1366 return data.word; 1646 I2C_SMBUS_WORD_DATA, &data);
1647 return (status < 0) ? status : data.word;
1367} 1648}
1368EXPORT_SYMBOL(i2c_smbus_read_word_data); 1649EXPORT_SYMBOL(i2c_smbus_read_word_data);
1369 1650
1651/**
1652 * i2c_smbus_write_word_data - SMBus "write word" protocol
1653 * @client: Handle to slave device
1654 * @command: Byte interpreted by slave
1655 * @value: 16-bit "word" being written
1656 *
1657 * This executes the SMBus "write word" protocol, returning negative errno
1658 * else zero on success.
1659 */
1370s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value) 1660s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
1371{ 1661{
1372 union i2c_smbus_data data; 1662 union i2c_smbus_data data;
@@ -1378,15 +1668,14 @@ s32 i2c_smbus_write_word_data(struct i2c_client *client, u8 command, u16 value)
1378EXPORT_SYMBOL(i2c_smbus_write_word_data); 1668EXPORT_SYMBOL(i2c_smbus_write_word_data);
1379 1669
1380/** 1670/**
1381 * i2c_smbus_read_block_data - SMBus block read request 1671 * i2c_smbus_read_block_data - SMBus "block read" protocol
1382 * @client: Handle to slave device 1672 * @client: Handle to slave device
1383 * @command: Command byte issued to let the slave know what data should 1673 * @command: Byte interpreted by slave
1384 * be returned
1385 * @values: Byte array into which data will be read; big enough to hold 1674 * @values: Byte array into which data will be read; big enough to hold
1386 * the data returned by the slave. SMBus allows at most 32 bytes. 1675 * the data returned by the slave. SMBus allows at most 32 bytes.
1387 * 1676 *
1388 * Returns the number of bytes read in the slave's response, else a 1677 * This executes the SMBus "block read" protocol, returning negative errno
1389 * negative number to indicate some kind of error. 1678 * else the number of data bytes in the slave's response.
1390 * 1679 *
1391 * Note that using this function requires that the client's adapter support 1680 * Note that using this function requires that the client's adapter support
1392 * the I2C_FUNC_SMBUS_READ_BLOCK_DATA functionality. Not all adapter drivers 1681 * the I2C_FUNC_SMBUS_READ_BLOCK_DATA functionality. Not all adapter drivers
@@ -1397,17 +1686,29 @@ s32 i2c_smbus_read_block_data(struct i2c_client *client, u8 command,
1397 u8 *values) 1686 u8 *values)
1398{ 1687{
1399 union i2c_smbus_data data; 1688 union i2c_smbus_data data;
1689 int status;
1400 1690
1401 if (i2c_smbus_xfer(client->adapter, client->addr, client->flags, 1691 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
1402 I2C_SMBUS_READ, command, 1692 I2C_SMBUS_READ, command,
1403 I2C_SMBUS_BLOCK_DATA, &data)) 1693 I2C_SMBUS_BLOCK_DATA, &data);
1404 return -1; 1694 if (status)
1695 return status;
1405 1696
1406 memcpy(values, &data.block[1], data.block[0]); 1697 memcpy(values, &data.block[1], data.block[0]);
1407 return data.block[0]; 1698 return data.block[0];
1408} 1699}
1409EXPORT_SYMBOL(i2c_smbus_read_block_data); 1700EXPORT_SYMBOL(i2c_smbus_read_block_data);
1410 1701
1702/**
1703 * i2c_smbus_write_block_data - SMBus "block write" protocol
1704 * @client: Handle to slave device
1705 * @command: Byte interpreted by slave
1706 * @length: Size of data block; SMBus allows at most 32 bytes
1707 * @values: Byte array which will be written.
1708 *
1709 * This executes the SMBus "block write" protocol, returning negative errno
1710 * else zero on success.
1711 */
1411s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command, 1712s32 i2c_smbus_write_block_data(struct i2c_client *client, u8 command,
1412 u8 length, const u8 *values) 1713 u8 length, const u8 *values)
1413{ 1714{
@@ -1428,14 +1729,16 @@ s32 i2c_smbus_read_i2c_block_data(struct i2c_client *client, u8 command,
1428 u8 length, u8 *values) 1729 u8 length, u8 *values)
1429{ 1730{
1430 union i2c_smbus_data data; 1731 union i2c_smbus_data data;
1732 int status;
1431 1733
1432 if (length > I2C_SMBUS_BLOCK_MAX) 1734 if (length > I2C_SMBUS_BLOCK_MAX)
1433 length = I2C_SMBUS_BLOCK_MAX; 1735 length = I2C_SMBUS_BLOCK_MAX;
1434 data.block[0] = length; 1736 data.block[0] = length;
1435 if (i2c_smbus_xfer(client->adapter,client->addr,client->flags, 1737 status = i2c_smbus_xfer(client->adapter, client->addr, client->flags,
1436 I2C_SMBUS_READ,command, 1738 I2C_SMBUS_READ, command,
1437 I2C_SMBUS_I2C_BLOCK_DATA,&data)) 1739 I2C_SMBUS_I2C_BLOCK_DATA, &data);
1438 return -1; 1740 if (status < 0)
1741 return status;
1439 1742
1440 memcpy(values, &data.block[1], data.block[0]); 1743 memcpy(values, &data.block[1], data.block[0]);
1441 return data.block[0]; 1744 return data.block[0];
@@ -1476,6 +1779,7 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1476 }; 1779 };
1477 int i; 1780 int i;
1478 u8 partial_pec = 0; 1781 u8 partial_pec = 0;
1782 int status;
1479 1783
1480 msgbuf0[0] = command; 1784 msgbuf0[0] = command;
1481 switch(size) { 1785 switch(size) {
@@ -1525,10 +1829,10 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1525 } else { 1829 } else {
1526 msg[0].len = data->block[0] + 2; 1830 msg[0].len = data->block[0] + 2;
1527 if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) { 1831 if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 2) {
1528 dev_err(&adapter->dev, "smbus_access called with " 1832 dev_err(&adapter->dev,
1529 "invalid block write size (%d)\n", 1833 "Invalid block write size %d\n",
1530 data->block[0]); 1834 data->block[0]);
1531 return -1; 1835 return -EINVAL;
1532 } 1836 }
1533 for (i = 1; i < msg[0].len; i++) 1837 for (i = 1; i < msg[0].len; i++)
1534 msgbuf0[i] = data->block[i-1]; 1838 msgbuf0[i] = data->block[i-1];
@@ -1538,10 +1842,10 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1538 num = 2; /* Another special case */ 1842 num = 2; /* Another special case */
1539 read_write = I2C_SMBUS_READ; 1843 read_write = I2C_SMBUS_READ;
1540 if (data->block[0] > I2C_SMBUS_BLOCK_MAX) { 1844 if (data->block[0] > I2C_SMBUS_BLOCK_MAX) {
1541 dev_err(&adapter->dev, "%s called with invalid " 1845 dev_err(&adapter->dev,
1542 "block proc call size (%d)\n", __func__, 1846 "Invalid block write size %d\n",
1543 data->block[0]); 1847 data->block[0]);
1544 return -1; 1848 return -EINVAL;
1545 } 1849 }
1546 msg[0].len = data->block[0] + 2; 1850 msg[0].len = data->block[0] + 2;
1547 for (i = 1; i < msg[0].len; i++) 1851 for (i = 1; i < msg[0].len; i++)
@@ -1556,19 +1860,18 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1556 } else { 1860 } else {
1557 msg[0].len = data->block[0] + 1; 1861 msg[0].len = data->block[0] + 1;
1558 if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 1) { 1862 if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 1) {
1559 dev_err(&adapter->dev, "i2c_smbus_xfer_emulated called with " 1863 dev_err(&adapter->dev,
1560 "invalid block write size (%d)\n", 1864 "Invalid block write size %d\n",
1561 data->block[0]); 1865 data->block[0]);
1562 return -1; 1866 return -EINVAL;
1563 } 1867 }
1564 for (i = 1; i <= data->block[0]; i++) 1868 for (i = 1; i <= data->block[0]; i++)
1565 msgbuf0[i] = data->block[i]; 1869 msgbuf0[i] = data->block[i];
1566 } 1870 }
1567 break; 1871 break;
1568 default: 1872 default:
1569 dev_err(&adapter->dev, "smbus_access called with invalid size (%d)\n", 1873 dev_err(&adapter->dev, "Unsupported transaction %d\n", size);
1570 size); 1874 return -EOPNOTSUPP;
1571 return -1;
1572 } 1875 }
1573 1876
1574 i = ((flags & I2C_CLIENT_PEC) && size != I2C_SMBUS_QUICK 1877 i = ((flags & I2C_CLIENT_PEC) && size != I2C_SMBUS_QUICK
@@ -1586,13 +1889,15 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1586 msg[num-1].len++; 1889 msg[num-1].len++;
1587 } 1890 }
1588 1891
1589 if (i2c_transfer(adapter, msg, num) < 0) 1892 status = i2c_transfer(adapter, msg, num);
1590 return -1; 1893 if (status < 0)
1894 return status;
1591 1895
1592 /* Check PEC if last message is a read */ 1896 /* Check PEC if last message is a read */
1593 if (i && (msg[num-1].flags & I2C_M_RD)) { 1897 if (i && (msg[num-1].flags & I2C_M_RD)) {
1594 if (i2c_smbus_check_pec(partial_pec, &msg[num-1]) < 0) 1898 status = i2c_smbus_check_pec(partial_pec, &msg[num-1]);
1595 return -1; 1899 if (status < 0)
1900 return status;
1596 } 1901 }
1597 1902
1598 if (read_write == I2C_SMBUS_READ) 1903 if (read_write == I2C_SMBUS_READ)
@@ -1620,9 +1925,21 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1620 return 0; 1925 return 0;
1621} 1926}
1622 1927
1623 1928/**
1929 * i2c_smbus_xfer - execute SMBus protocol operations
1930 * @adapter: Handle to I2C bus
1931 * @addr: Address of SMBus slave on that bus
1932 * @flags: I2C_CLIENT_* flags (usually zero or I2C_CLIENT_PEC)
1933 * @read_write: I2C_SMBUS_READ or I2C_SMBUS_WRITE
1934 * @command: Byte interpreted by slave, for protocols which use such bytes
1935 * @protocol: SMBus protocol operation to execute, such as I2C_SMBUS_PROC_CALL
1936 * @data: Data to be read or written
1937 *
1938 * This executes an SMBus protocol operation, and returns a negative
1939 * errno code else zero on success.
1940 */
1624s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags, 1941s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
1625 char read_write, u8 command, int size, 1942 char read_write, u8 command, int protocol,
1626 union i2c_smbus_data * data) 1943 union i2c_smbus_data * data)
1627{ 1944{
1628 s32 res; 1945 s32 res;
@@ -1632,11 +1949,11 @@ s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
1632 if (adapter->algo->smbus_xfer) { 1949 if (adapter->algo->smbus_xfer) {
1633 mutex_lock(&adapter->bus_lock); 1950 mutex_lock(&adapter->bus_lock);
1634 res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write, 1951 res = adapter->algo->smbus_xfer(adapter,addr,flags,read_write,
1635 command,size,data); 1952 command, protocol, data);
1636 mutex_unlock(&adapter->bus_lock); 1953 mutex_unlock(&adapter->bus_lock);
1637 } else 1954 } else
1638 res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write, 1955 res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write,
1639 command,size,data); 1956 command, protocol, data);
1640 1957
1641 return res; 1958 return res;
1642} 1959}
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index d34c14c81c29..9d55c6383b23 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -34,6 +34,7 @@
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>
37#include <asm/uaccess.h> 38#include <asm/uaccess.h>
38 39
39static struct i2c_driver i2cdev_driver; 40static struct i2c_driver i2cdev_driver;
@@ -366,8 +367,7 @@ static noinline int i2cdev_ioctl_smbus(struct i2c_client *client,
366 return res; 367 return res;
367} 368}
368 369
369static int i2cdev_ioctl(struct inode *inode, struct file *file, 370static long i2cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
370 unsigned int cmd, unsigned long arg)
371{ 371{
372 struct i2c_client *client = (struct i2c_client *)file->private_data; 372 struct i2c_client *client = (struct i2c_client *)file->private_data;
373 unsigned long funcs; 373 unsigned long funcs;
@@ -441,14 +441,20 @@ static int i2cdev_open(struct inode *inode, struct file *file)
441 struct i2c_client *client; 441 struct i2c_client *client;
442 struct i2c_adapter *adap; 442 struct i2c_adapter *adap;
443 struct i2c_dev *i2c_dev; 443 struct i2c_dev *i2c_dev;
444 int ret = 0;
444 445
446 lock_kernel();
445 i2c_dev = i2c_dev_get_by_minor(minor); 447 i2c_dev = i2c_dev_get_by_minor(minor);
446 if (!i2c_dev) 448 if (!i2c_dev) {
447 return -ENODEV; 449 ret = -ENODEV;
450 goto out;
451 }
448 452
449 adap = i2c_get_adapter(i2c_dev->adap->nr); 453 adap = i2c_get_adapter(i2c_dev->adap->nr);
450 if (!adap) 454 if (!adap) {
451 return -ENODEV; 455 ret = -ENODEV;
456 goto out;
457 }
452 458
453 /* This creates an anonymous i2c_client, which may later be 459 /* This creates an anonymous i2c_client, which may later be
454 * pointed to some address using I2C_SLAVE or I2C_SLAVE_FORCE. 460 * pointed to some address using I2C_SLAVE or I2C_SLAVE_FORCE.
@@ -460,7 +466,8 @@ static int i2cdev_open(struct inode *inode, struct file *file)
460 client = kzalloc(sizeof(*client), GFP_KERNEL); 466 client = kzalloc(sizeof(*client), GFP_KERNEL);
461 if (!client) { 467 if (!client) {
462 i2c_put_adapter(adap); 468 i2c_put_adapter(adap);
463 return -ENOMEM; 469 ret = -ENOMEM;
470 goto out;
464 } 471 }
465 snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr); 472 snprintf(client->name, I2C_NAME_SIZE, "i2c-dev %d", adap->nr);
466 client->driver = &i2cdev_driver; 473 client->driver = &i2cdev_driver;
@@ -468,7 +475,9 @@ static int i2cdev_open(struct inode *inode, struct file *file)
468 client->adapter = adap; 475 client->adapter = adap;
469 file->private_data = client; 476 file->private_data = client;
470 477
471 return 0; 478out:
479 unlock_kernel();
480 return ret;
472} 481}
473 482
474static int i2cdev_release(struct inode *inode, struct file *file) 483static int i2cdev_release(struct inode *inode, struct file *file)
@@ -487,7 +496,7 @@ static const struct file_operations i2cdev_fops = {
487 .llseek = no_llseek, 496 .llseek = no_llseek,
488 .read = i2cdev_read, 497 .read = i2cdev_read,
489 .write = i2cdev_write, 498 .write = i2cdev_write,
490 .ioctl = i2cdev_ioctl, 499 .unlocked_ioctl = i2cdev_ioctl,
491 .open = i2cdev_open, 500 .open = i2cdev_open,
492 .release = i2cdev_release, 501 .release = i2cdev_release,
493}; 502};
@@ -512,9 +521,9 @@ static int i2cdev_attach_adapter(struct i2c_adapter *adap)
512 return PTR_ERR(i2c_dev); 521 return PTR_ERR(i2c_dev);
513 522
514 /* register this i2c device with the driver core */ 523 /* register this i2c device with the driver core */
515 i2c_dev->dev = device_create(i2c_dev_class, &adap->dev, 524 i2c_dev->dev = device_create_drvdata(i2c_dev_class, &adap->dev,
516 MKDEV(I2C_MAJOR, adap->nr), 525 MKDEV(I2C_MAJOR, adap->nr),
517 "i2c-%d", adap->nr); 526 NULL, "i2c-%d", adap->nr);
518 if (IS_ERR(i2c_dev->dev)) { 527 if (IS_ERR(i2c_dev->dev)) {
519 res = PTR_ERR(i2c_dev->dev); 528 res = PTR_ERR(i2c_dev->dev);
520 goto error; 529 goto error;
@@ -549,19 +558,12 @@ static int i2cdev_detach_adapter(struct i2c_adapter *adap)
549 return 0; 558 return 0;
550} 559}
551 560
552static int i2cdev_detach_client(struct i2c_client *client)
553{
554 return 0;
555}
556
557static struct i2c_driver i2cdev_driver = { 561static struct i2c_driver i2cdev_driver = {
558 .driver = { 562 .driver = {
559 .name = "dev_driver", 563 .name = "dev_driver",
560 }, 564 },
561 .id = I2C_DRIVERID_I2CDEV,
562 .attach_adapter = i2cdev_attach_adapter, 565 .attach_adapter = i2cdev_attach_adapter,
563 .detach_adapter = i2cdev_detach_adapter, 566 .detach_adapter = i2cdev_detach_adapter,
564 .detach_client = i2cdev_detach_client,
565}; 567};
566 568
567/* ------------------------------------------------------------------------- */ 569/* ------------------------------------------------------------------------- */