aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c/busses')
-rw-r--r--drivers/i2c/busses/Kconfig151
-rw-r--r--drivers/i2c/busses/Makefile4
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c2
-rw-r--r--drivers/i2c/busses/i2c-ali15x3.c2
-rw-r--r--drivers/i2c/busses/i2c-amd8111.c2
-rw-r--r--drivers/i2c/busses/i2c-at91.c1
-rw-r--r--drivers/i2c/busses/i2c-bfin-twi.c644
-rw-r--r--drivers/i2c/busses/i2c-elektor.c51
-rw-r--r--drivers/i2c/busses/i2c-gpio.c215
-rw-r--r--drivers/i2c/busses/i2c-i801.c2
-rw-r--r--drivers/i2c/busses/i2c-isa.c43
-rw-r--r--drivers/i2c/busses/i2c-ixp2000.c2
-rw-r--r--drivers/i2c/busses/i2c-ixp4xx.c2
-rw-r--r--drivers/i2c/busses/i2c-mpc.c1
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c2
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c6
-rw-r--r--drivers/i2c/busses/i2c-omap.c3
-rw-r--r--drivers/i2c/busses/i2c-parport-light.c144
-rw-r--r--drivers/i2c/busses/i2c-parport.c25
-rw-r--r--drivers/i2c/busses/i2c-pasemi.c2
-rw-r--r--drivers/i2c/busses/i2c-pca-isa.c36
-rw-r--r--drivers/i2c/busses/i2c-piix4.c2
-rw-r--r--drivers/i2c/busses/i2c-pxa.c33
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c96
-rw-r--r--drivers/i2c/busses/i2c-simtec.c186
-rw-r--r--drivers/i2c/busses/i2c-sis96x.c2
-rw-r--r--drivers/i2c/busses/i2c-tiny-usb.c277
-rw-r--r--drivers/i2c/busses/i2c-viapro.c2
-rw-r--r--drivers/i2c/busses/scx200_acb.c3
29 files changed, 1728 insertions, 213 deletions
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index ece31d2c6c64..838dc1c19d61 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -3,11 +3,10 @@
3# 3#
4 4
5menu "I2C Hardware Bus support" 5menu "I2C Hardware Bus support"
6 depends on I2C
7 6
8config I2C_ALI1535 7config I2C_ALI1535
9 tristate "ALI 1535" 8 tristate "ALI 1535"
10 depends on I2C && PCI 9 depends on PCI
11 help 10 help
12 If you say yes to this option, support will be included for the SMB 11 If you say yes to this option, support will be included for the SMB
13 Host controller on Acer Labs Inc. (ALI) M1535 South Bridges. The SMB 12 Host controller on Acer Labs Inc. (ALI) M1535 South Bridges. The SMB
@@ -19,7 +18,7 @@ config I2C_ALI1535
19 18
20config I2C_ALI1563 19config I2C_ALI1563
21 tristate "ALI 1563" 20 tristate "ALI 1563"
22 depends on I2C && PCI && EXPERIMENTAL 21 depends on PCI && EXPERIMENTAL
23 help 22 help
24 If you say yes to this option, support will be included for the SMB 23 If you say yes to this option, support will be included for the SMB
25 Host controller on Acer Labs Inc. (ALI) M1563 South Bridges. The SMB 24 Host controller on Acer Labs Inc. (ALI) M1563 South Bridges. The SMB
@@ -31,7 +30,7 @@ config I2C_ALI1563
31 30
32config I2C_ALI15X3 31config I2C_ALI15X3
33 tristate "ALI 15x3" 32 tristate "ALI 15x3"
34 depends on I2C && PCI 33 depends on PCI
35 help 34 help
36 If you say yes to this option, support will be included for the 35 If you say yes to this option, support will be included for the
37 Acer Labs Inc. (ALI) M1514 and M1543 motherboard I2C interfaces. 36 Acer Labs Inc. (ALI) M1514 and M1543 motherboard I2C interfaces.
@@ -41,7 +40,7 @@ config I2C_ALI15X3
41 40
42config I2C_AMD756 41config I2C_AMD756
43 tristate "AMD 756/766/768/8111 and nVidia nForce" 42 tristate "AMD 756/766/768/8111 and nVidia nForce"
44 depends on I2C && PCI 43 depends on PCI
45 help 44 help
46 If you say yes to this option, support will be included for the AMD 45 If you say yes to this option, support will be included for the AMD
47 756/766/768 mainboard I2C interfaces. The driver also includes 46 756/766/768 mainboard I2C interfaces. The driver also includes
@@ -66,7 +65,7 @@ config I2C_AMD756_S4882
66 65
67config I2C_AMD8111 66config I2C_AMD8111
68 tristate "AMD 8111" 67 tristate "AMD 8111"
69 depends on I2C && PCI 68 depends on PCI
70 help 69 help
71 If you say yes to this option, support will be included for the 70 If you say yes to this option, support will be included for the
72 second (SMBus 2.0) AMD 8111 mainboard I2C interface. 71 second (SMBus 2.0) AMD 8111 mainboard I2C interface.
@@ -76,14 +75,14 @@ config I2C_AMD8111
76 75
77config I2C_AT91 76config I2C_AT91
78 tristate "Atmel AT91 I2C Two-Wire interface (TWI)" 77 tristate "Atmel AT91 I2C Two-Wire interface (TWI)"
79 depends on I2C && ARCH_AT91 && EXPERIMENTAL 78 depends on ARCH_AT91 && EXPERIMENTAL
80 help 79 help
81 This supports the use of the I2C interface on Atmel AT91 80 This supports the use of the I2C interface on Atmel AT91
82 processors. 81 processors.
83 82
84config I2C_AU1550 83config I2C_AU1550
85 tristate "Au1550/Au1200 SMBus interface" 84 tristate "Au1550/Au1200 SMBus interface"
86 depends on I2C && (SOC_AU1550 || SOC_AU1200) 85 depends on SOC_AU1550 || SOC_AU1200
87 help 86 help
88 If you say yes to this option, support will be included for the 87 If you say yes to this option, support will be included for the
89 Au1550 and Au1200 SMBus interface. 88 Au1550 and Au1200 SMBus interface.
@@ -91,9 +90,25 @@ config I2C_AU1550
91 This driver can also be built as a module. If so, the module 90 This driver can also be built as a module. If so, the module
92 will be called i2c-au1550. 91 will be called i2c-au1550.
93 92
93config I2C_BLACKFIN_TWI
94 tristate "Blackfin TWI I2C support"
95 depends on BF534 || BF536 || BF537
96 help
97 This is the TWI I2C device driver for Blackfin 534/536/537.
98 This driver can also be built as a module. If so, the module
99 will be called i2c-bfin-twi.
100
101config I2C_BLACKFIN_TWI_CLK_KHZ
102 int "Blackfin TWI I2C clock (kHz)"
103 depends on I2C_BLACKFIN_TWI
104 range 10 400
105 default 50
106 help
107 The unit of the TWI clock is kHz.
108
94config I2C_ELEKTOR 109config I2C_ELEKTOR
95 tristate "Elektor ISA card" 110 tristate "Elektor ISA card"
96 depends on I2C && ISA && BROKEN_ON_SMP 111 depends on ISA && BROKEN_ON_SMP
97 select I2C_ALGOPCF 112 select I2C_ALGOPCF
98 help 113 help
99 This supports the PCF8584 ISA bus I2C adapter. Say Y if you own 114 This supports the PCF8584 ISA bus I2C adapter. Say Y if you own
@@ -102,9 +117,17 @@ config I2C_ELEKTOR
102 This support is also available as a module. If so, the module 117 This support is also available as a module. If so, the module
103 will be called i2c-elektor. 118 will be called i2c-elektor.
104 119
120config I2C_GPIO
121 tristate "GPIO-based bitbanging I2C"
122 depends on GENERIC_GPIO
123 select I2C_ALGOBIT
124 help
125 This is a very simple bitbanging I2C driver utilizing the
126 arch-neutral GPIO API to control the SCL and SDA lines.
127
105config I2C_HYDRA 128config I2C_HYDRA
106 tristate "CHRP Apple Hydra Mac I/O I2C interface" 129 tristate "CHRP Apple Hydra Mac I/O I2C interface"
107 depends on I2C && PCI && PPC_CHRP && EXPERIMENTAL 130 depends on PCI && PPC_CHRP && EXPERIMENTAL
108 select I2C_ALGOBIT 131 select I2C_ALGOBIT
109 help 132 help
110 This supports the use of the I2C interface in the Apple Hydra Mac 133 This supports the use of the I2C interface in the Apple Hydra Mac
@@ -116,7 +139,7 @@ config I2C_HYDRA
116 139
117config I2C_I801 140config I2C_I801
118 tristate "Intel 82801 (ICH)" 141 tristate "Intel 82801 (ICH)"
119 depends on I2C && PCI 142 depends on PCI
120 help 143 help
121 If you say yes to this option, support will be included for the Intel 144 If you say yes to this option, support will be included for the Intel
122 801 family of mainboard I2C interfaces. Specifically, the following 145 801 family of mainboard I2C interfaces. Specifically, the following
@@ -139,7 +162,7 @@ config I2C_I801
139 162
140config I2C_I810 163config I2C_I810
141 tristate "Intel 810/815" 164 tristate "Intel 810/815"
142 depends on I2C && PCI 165 depends on PCI
143 select I2C_ALGOBIT 166 select I2C_ALGOBIT
144 help 167 help
145 If you say yes to this option, support will be included for the Intel 168 If you say yes to this option, support will be included for the Intel
@@ -156,7 +179,7 @@ config I2C_I810
156 179
157config I2C_PXA 180config I2C_PXA
158 tristate "Intel PXA2XX I2C adapter (EXPERIMENTAL)" 181 tristate "Intel PXA2XX I2C adapter (EXPERIMENTAL)"
159 depends on I2C && EXPERIMENTAL && ARCH_PXA 182 depends on EXPERIMENTAL && ARCH_PXA
160 help 183 help
161 If you have devices in the PXA I2C bus, say yes to this option. 184 If you have devices in the PXA I2C bus, say yes to this option.
162 This driver can also be built as a module. If so, the module 185 This driver can also be built as a module. If so, the module
@@ -172,7 +195,7 @@ config I2C_PXA_SLAVE
172 195
173config I2C_PIIX4 196config I2C_PIIX4
174 tristate "Intel PIIX4 and compatible (ATI/Serverworks/Broadcom/SMSC)" 197 tristate "Intel PIIX4 and compatible (ATI/Serverworks/Broadcom/SMSC)"
175 depends on I2C && PCI 198 depends on PCI
176 help 199 help
177 If you say yes to this option, support will be included for the Intel 200 If you say yes to this option, support will be included for the Intel
178 PIIX4 family of mainboard I2C interfaces. Specifically, the following 201 PIIX4 family of mainboard I2C interfaces. Specifically, the following
@@ -195,7 +218,7 @@ config I2C_PIIX4
195 218
196config I2C_IBM_IIC 219config I2C_IBM_IIC
197 tristate "IBM PPC 4xx on-chip I2C interface" 220 tristate "IBM PPC 4xx on-chip I2C interface"
198 depends on IBM_OCP && I2C 221 depends on IBM_OCP
199 help 222 help
200 Say Y here if you want to use IIC peripheral found on 223 Say Y here if you want to use IIC peripheral found on
201 embedded IBM PPC 4xx based systems. 224 embedded IBM PPC 4xx based systems.
@@ -205,7 +228,7 @@ config I2C_IBM_IIC
205 228
206config I2C_IOP3XX 229config I2C_IOP3XX
207 tristate "Intel IOPx3xx and IXP4xx on-chip I2C interface" 230 tristate "Intel IOPx3xx and IXP4xx on-chip I2C interface"
208 depends on (ARCH_IOP32X || ARCH_IOP33X || ARCH_IXP4XX || ARCH_IOP13XX) && I2C 231 depends on ARCH_IOP32X || ARCH_IOP33X || ARCH_IXP4XX || ARCH_IOP13XX
209 help 232 help
210 Say Y here if you want to use the IIC bus controller on 233 Say Y here if you want to use the IIC bus controller on
211 the Intel IOPx3xx I/O Processors or IXP4xx Network Processors. 234 the Intel IOPx3xx I/O Processors or IXP4xx Network Processors.
@@ -215,11 +238,10 @@ config I2C_IOP3XX
215 238
216config I2C_ISA 239config I2C_ISA
217 tristate 240 tristate
218 depends on I2C
219 241
220config I2C_IXP4XX 242config I2C_IXP4XX
221 tristate "IXP4xx GPIO-Based I2C Interface" 243 tristate "IXP4xx GPIO-Based I2C Interface (DEPRECATED)"
222 depends on I2C && ARCH_IXP4XX 244 depends on ARCH_IXP4XX
223 select I2C_ALGOBIT 245 select I2C_ALGOBIT
224 help 246 help
225 Say Y here if you have an Intel IXP4xx(420,421,422,425) based 247 Say Y here if you have an Intel IXP4xx(420,421,422,425) based
@@ -228,9 +250,12 @@ config I2C_IXP4XX
228 This support is also available as a module. If so, the module 250 This support is also available as a module. If so, the module
229 will be called i2c-ixp4xx. 251 will be called i2c-ixp4xx.
230 252
253 This driver is deprecated and will be dropped soon. Use i2c-gpio
254 instead.
255
231config I2C_IXP2000 256config I2C_IXP2000
232 tristate "IXP2000 GPIO-Based I2C Interface" 257 tristate "IXP2000 GPIO-Based I2C Interface (DEPRECATED)"
233 depends on I2C && ARCH_IXP2000 258 depends on ARCH_IXP2000
234 select I2C_ALGOBIT 259 select I2C_ALGOBIT
235 help 260 help
236 Say Y here if you have an Intel IXP2000(2400, 2800, 2850) based 261 Say Y here if you have an Intel IXP2000(2400, 2800, 2850) based
@@ -239,9 +264,12 @@ config I2C_IXP2000
239 This support is also available as a module. If so, the module 264 This support is also available as a module. If so, the module
240 will be called i2c-ixp2000. 265 will be called i2c-ixp2000.
241 266
267 This driver is deprecated and will be dropped soon. Use i2c-gpio
268 instead.
269
242config I2C_POWERMAC 270config I2C_POWERMAC
243 tristate "Powermac I2C interface" 271 tristate "Powermac I2C interface"
244 depends on I2C && PPC_PMAC 272 depends on PPC_PMAC
245 default y 273 default y
246 help 274 help
247 This exposes the various PowerMac i2c interfaces to the linux i2c 275 This exposes the various PowerMac i2c interfaces to the linux i2c
@@ -253,7 +281,7 @@ config I2C_POWERMAC
253 281
254config I2C_MPC 282config I2C_MPC
255 tristate "MPC107/824x/85xx/52xx/86xx" 283 tristate "MPC107/824x/85xx/52xx/86xx"
256 depends on I2C && PPC32 284 depends on PPC32
257 help 285 help
258 If you say yes to this option, support will be included for the 286 If you say yes to this option, support will be included for the
259 built-in I2C interface on the MPC107/Tsi107/MPC8240/MPC8245 and 287 built-in I2C interface on the MPC107/Tsi107/MPC8240/MPC8245 and
@@ -265,7 +293,7 @@ config I2C_MPC
265 293
266config I2C_NFORCE2 294config I2C_NFORCE2
267 tristate "Nvidia nForce2, nForce3 and nForce4" 295 tristate "Nvidia nForce2, nForce3 and nForce4"
268 depends on I2C && PCI 296 depends on PCI
269 help 297 help
270 If you say yes to this option, support will be included for the Nvidia 298 If you say yes to this option, support will be included for the Nvidia
271 nForce2, nForce3 and nForce4 families of mainboard I2C interfaces. 299 nForce2, nForce3 and nForce4 families of mainboard I2C interfaces.
@@ -275,7 +303,7 @@ config I2C_NFORCE2
275 303
276config I2C_OCORES 304config I2C_OCORES
277 tristate "OpenCores I2C Controller" 305 tristate "OpenCores I2C Controller"
278 depends on I2C && EXPERIMENTAL 306 depends on EXPERIMENTAL
279 help 307 help
280 If you say yes to this option, support will be included for the 308 If you say yes to this option, support will be included for the
281 OpenCores I2C controller. For details see 309 OpenCores I2C controller. For details see
@@ -286,7 +314,7 @@ config I2C_OCORES
286 314
287config I2C_OMAP 315config I2C_OMAP
288 tristate "OMAP I2C adapter" 316 tristate "OMAP I2C adapter"
289 depends on I2C && ARCH_OMAP 317 depends on ARCH_OMAP
290 default y if MACH_OMAP_H3 || MACH_OMAP_OSK 318 default y if MACH_OMAP_H3 || MACH_OMAP_OSK
291 help 319 help
292 If you say yes to this option, support will be included for the 320 If you say yes to this option, support will be included for the
@@ -296,7 +324,7 @@ config I2C_OMAP
296 324
297config I2C_PARPORT 325config I2C_PARPORT
298 tristate "Parallel port adapter" 326 tristate "Parallel port adapter"
299 depends on I2C && PARPORT 327 depends on PARPORT
300 select I2C_ALGOBIT 328 select I2C_ALGOBIT
301 help 329 help
302 This supports parallel port I2C adapters such as the ones made by 330 This supports parallel port I2C adapters such as the ones made by
@@ -320,7 +348,6 @@ config I2C_PARPORT
320 348
321config I2C_PARPORT_LIGHT 349config I2C_PARPORT_LIGHT
322 tristate "Parallel port adapter (light)" 350 tristate "Parallel port adapter (light)"
323 depends on I2C
324 select I2C_ALGOBIT 351 select I2C_ALGOBIT
325 help 352 help
326 This supports parallel port I2C adapters such as the ones made by 353 This supports parallel port I2C adapters such as the ones made by
@@ -344,13 +371,13 @@ config I2C_PARPORT_LIGHT
344 371
345config I2C_PASEMI 372config I2C_PASEMI
346 tristate "PA Semi SMBus interface" 373 tristate "PA Semi SMBus interface"
347 depends on PPC_PASEMI && I2C && PCI 374 depends on PPC_PASEMI && PCI
348 help 375 help
349 Supports the PA Semi PWRficient on-chip SMBus interfaces. 376 Supports the PA Semi PWRficient on-chip SMBus interfaces.
350 377
351config I2C_PROSAVAGE 378config I2C_PROSAVAGE
352 tristate "S3/VIA (Pro)Savage" 379 tristate "S3/VIA (Pro)Savage"
353 depends on I2C && PCI 380 depends on PCI
354 select I2C_ALGOBIT 381 select I2C_ALGOBIT
355 help 382 help
356 If you say yes to this option, support will be included for the 383 If you say yes to this option, support will be included for the
@@ -365,19 +392,19 @@ config I2C_PROSAVAGE
365 392
366config I2C_RPXLITE 393config I2C_RPXLITE
367 tristate "Embedded Planet RPX Lite/Classic support" 394 tristate "Embedded Planet RPX Lite/Classic support"
368 depends on (RPXLITE || RPXCLASSIC) && I2C 395 depends on RPXLITE || RPXCLASSIC
369 select I2C_ALGO8XX 396 select I2C_ALGO8XX
370 397
371config I2C_S3C2410 398config I2C_S3C2410
372 tristate "S3C2410 I2C Driver" 399 tristate "S3C2410 I2C Driver"
373 depends on I2C && ARCH_S3C2410 400 depends on ARCH_S3C2410
374 help 401 help
375 Say Y here to include support for I2C controller in the 402 Say Y here to include support for I2C controller in the
376 Samsung S3C2410 based System-on-Chip devices. 403 Samsung S3C2410 based System-on-Chip devices.
377 404
378config I2C_SAVAGE4 405config I2C_SAVAGE4
379 tristate "S3 Savage 4" 406 tristate "S3 Savage 4"
380 depends on I2C && PCI && EXPERIMENTAL 407 depends on PCI && EXPERIMENTAL
381 select I2C_ALGOBIT 408 select I2C_ALGOBIT
382 help 409 help
383 If you say yes to this option, support will be included for the 410 If you say yes to this option, support will be included for the
@@ -388,13 +415,25 @@ config I2C_SAVAGE4
388 415
389config I2C_SIBYTE 416config I2C_SIBYTE
390 tristate "SiByte SMBus interface" 417 tristate "SiByte SMBus interface"
391 depends on SIBYTE_SB1xxx_SOC && I2C 418 depends on SIBYTE_SB1xxx_SOC
392 help 419 help
393 Supports the SiByte SOC on-chip I2C interfaces (2 channels). 420 Supports the SiByte SOC on-chip I2C interfaces (2 channels).
394 421
422config I2C_SIMTEC
423 tristate "Simtec Generic I2C interface"
424 select I2C_ALGOBIT
425 help
426 If you say yes to this option, support will be inclyded for
427 the Simtec Generic I2C interface. This driver is for the
428 simple I2C bus used on newer Simtec products for general
429 I2C, such as DDC on the Simtec BBD2016A.
430
431 This driver can also be build as a module. If so, the module
432 will be called i2c-simtec.
433
395config SCx200_I2C 434config SCx200_I2C
396 tristate "NatSemi SCx200 I2C using GPIO pins" 435 tristate "NatSemi SCx200 I2C using GPIO pins (DEPRECATED)"
397 depends on SCx200_GPIO && I2C 436 depends on SCx200_GPIO
398 select I2C_ALGOBIT 437 select I2C_ALGOBIT
399 help 438 help
400 Enable the use of two GPIO pins of a SCx200 processor as an I2C bus. 439 Enable the use of two GPIO pins of a SCx200 processor as an I2C bus.
@@ -404,6 +443,9 @@ config SCx200_I2C
404 This support is also available as a module. If so, the module 443 This support is also available as a module. If so, the module
405 will be called scx200_i2c. 444 will be called scx200_i2c.
406 445
446 This driver is deprecated and will be dropped soon. Use i2c-gpio
447 (or scx200_acb) instead.
448
407config SCx200_I2C_SCL 449config SCx200_I2C_SCL
408 int "GPIO pin used for SCL" 450 int "GPIO pin used for SCL"
409 depends on SCx200_I2C 451 depends on SCx200_I2C
@@ -422,7 +464,7 @@ config SCx200_I2C_SDA
422 464
423config SCx200_ACB 465config SCx200_ACB
424 tristate "Geode ACCESS.bus support" 466 tristate "Geode ACCESS.bus support"
425 depends on X86_32 && I2C && PCI 467 depends on X86_32 && PCI
426 help 468 help
427 Enable the use of the ACCESS.bus controllers on the Geode SCx200 and 469 Enable the use of the ACCESS.bus controllers on the Geode SCx200 and
428 SC1100 processors and the CS5535 and CS5536 Geode companion devices. 470 SC1100 processors and the CS5535 and CS5536 Geode companion devices.
@@ -434,7 +476,7 @@ config SCx200_ACB
434 476
435config I2C_SIS5595 477config I2C_SIS5595
436 tristate "SiS 5595" 478 tristate "SiS 5595"
437 depends on I2C && PCI 479 depends on PCI
438 help 480 help
439 If you say yes to this option, support will be included for the 481 If you say yes to this option, support will be included for the
440 SiS5595 SMBus (a subset of I2C) interface. 482 SiS5595 SMBus (a subset of I2C) interface.
@@ -444,7 +486,7 @@ config I2C_SIS5595
444 486
445config I2C_SIS630 487config I2C_SIS630
446 tristate "SiS 630/730" 488 tristate "SiS 630/730"
447 depends on I2C && PCI 489 depends on PCI
448 help 490 help
449 If you say yes to this option, support will be included for the 491 If you say yes to this option, support will be included for the
450 SiS630 and SiS730 SMBus (a subset of I2C) interface. 492 SiS630 and SiS730 SMBus (a subset of I2C) interface.
@@ -454,7 +496,7 @@ config I2C_SIS630
454 496
455config I2C_SIS96X 497config I2C_SIS96X
456 tristate "SiS 96x" 498 tristate "SiS 96x"
457 depends on I2C && PCI 499 depends on PCI
458 help 500 help
459 If you say yes to this option, support will be included for the SiS 501 If you say yes to this option, support will be included for the SiS
460 96x SMBus (a subset of I2C) interfaces. Specifically, the following 502 96x SMBus (a subset of I2C) interfaces. Specifically, the following
@@ -472,7 +514,7 @@ config I2C_SIS96X
472 514
473config I2C_STUB 515config I2C_STUB
474 tristate "I2C/SMBus Test Stub" 516 tristate "I2C/SMBus Test Stub"
475 depends on I2C && EXPERIMENTAL && 'm' 517 depends on EXPERIMENTAL && m
476 default 'n' 518 default 'n'
477 help 519 help
478 This module may be useful to developers of SMBus client drivers, 520 This module may be useful to developers of SMBus client drivers,
@@ -483,9 +525,20 @@ config I2C_STUB
483 525
484 If you don't know what to do here, definitely say N. 526 If you don't know what to do here, definitely say N.
485 527
528config I2C_TINY_USB
529 tristate "I2C-Tiny-USB"
530 depends on USB
531 help
532 If you say yes to this option, support will be included for the
533 i2c-tiny-usb, a simple do-it-yourself USB to I2C interface. See
534 http://www.harbaum.org/till/i2c_tiny_usb for hardware details.
535
536 This driver can also be built as a module. If so, the module
537 will be called i2c-tiny-usb.
538
486config I2C_VERSATILE 539config I2C_VERSATILE
487 tristate "ARM Versatile/Realview I2C bus support" 540 tristate "ARM Versatile/Realview I2C bus support"
488 depends on I2C && (ARCH_VERSATILE || ARCH_REALVIEW) 541 depends on ARCH_VERSATILE || ARCH_REALVIEW
489 select I2C_ALGOBIT 542 select I2C_ALGOBIT
490 help 543 help
491 Say yes if you want to support the I2C serial bus on ARMs Versatile 544 Say yes if you want to support the I2C serial bus on ARMs Versatile
@@ -496,7 +549,7 @@ config I2C_VERSATILE
496 549
497config I2C_ACORN 550config I2C_ACORN
498 bool "Acorn IOC/IOMD I2C bus support" 551 bool "Acorn IOC/IOMD I2C bus support"
499 depends on I2C && ARCH_ACORN 552 depends on ARCH_ACORN
500 default y 553 default y
501 select I2C_ALGOBIT 554 select I2C_ALGOBIT
502 help 555 help
@@ -506,7 +559,7 @@ config I2C_ACORN
506 559
507config I2C_VIA 560config I2C_VIA
508 tristate "VIA 82C586B" 561 tristate "VIA 82C586B"
509 depends on I2C && PCI && EXPERIMENTAL 562 depends on PCI && EXPERIMENTAL
510 select I2C_ALGOBIT 563 select I2C_ALGOBIT
511 help 564 help
512 If you say yes to this option, support will be included for the VIA 565 If you say yes to this option, support will be included for the VIA
@@ -517,7 +570,7 @@ config I2C_VIA
517 570
518config I2C_VIAPRO 571config I2C_VIAPRO
519 tristate "VIA VT82C596/82C686/82xx and CX700" 572 tristate "VIA VT82C596/82C686/82xx and CX700"
520 depends on I2C && PCI 573 depends on PCI
521 help 574 help
522 If you say yes to this option, support will be included for the VIA 575 If you say yes to this option, support will be included for the VIA
523 VT82C596 and later SMBus interface. Specifically, the following 576 VT82C596 and later SMBus interface. Specifically, the following
@@ -536,7 +589,7 @@ config I2C_VIAPRO
536 589
537config I2C_VOODOO3 590config I2C_VOODOO3
538 tristate "Voodoo 3" 591 tristate "Voodoo 3"
539 depends on I2C && PCI 592 depends on PCI
540 select I2C_ALGOBIT 593 select I2C_ALGOBIT
541 help 594 help
542 If you say yes to this option, support will be included for the 595 If you say yes to this option, support will be included for the
@@ -547,7 +600,7 @@ config I2C_VOODOO3
547 600
548config I2C_PCA_ISA 601config I2C_PCA_ISA
549 tristate "PCA9564 on an ISA bus" 602 tristate "PCA9564 on an ISA bus"
550 depends on I2C 603 depends on ISA
551 select I2C_ALGOPCA 604 select I2C_ALGOPCA
552 default n 605 default n
553 help 606 help
@@ -564,7 +617,7 @@ config I2C_PCA_ISA
564 617
565config I2C_MV64XXX 618config I2C_MV64XXX
566 tristate "Marvell mv64xxx I2C Controller" 619 tristate "Marvell mv64xxx I2C Controller"
567 depends on I2C && MV64X60 && EXPERIMENTAL 620 depends on MV64X60 && EXPERIMENTAL
568 help 621 help
569 If you say yes to this option, support will be included for the 622 If you say yes to this option, support will be included for the
570 built-in I2C interface on the Marvell 64xxx line of host bridges. 623 built-in I2C interface on the Marvell 64xxx line of host bridges.
@@ -574,7 +627,7 @@ config I2C_MV64XXX
574 627
575config I2C_PNX 628config I2C_PNX
576 tristate "I2C bus support for Philips PNX targets" 629 tristate "I2C bus support for Philips PNX targets"
577 depends on ARCH_PNX4008 && I2C 630 depends on ARCH_PNX4008
578 help 631 help
579 This driver supports the Philips IP3204 I2C IP block master and/or 632 This driver supports the Philips IP3204 I2C IP block master and/or
580 slave controller 633 slave controller
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index 290b54018354..14d1432f698b 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -10,7 +10,9 @@ obj-$(CONFIG_I2C_AMD756_S4882) += i2c-amd756-s4882.o
10obj-$(CONFIG_I2C_AMD8111) += i2c-amd8111.o 10obj-$(CONFIG_I2C_AMD8111) += i2c-amd8111.o
11obj-$(CONFIG_I2C_AT91) += i2c-at91.o 11obj-$(CONFIG_I2C_AT91) += i2c-at91.o
12obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o 12obj-$(CONFIG_I2C_AU1550) += i2c-au1550.o
13obj-$(CONFIG_I2C_BLACKFIN_TWI) += i2c-bfin-twi.o
13obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o 14obj-$(CONFIG_I2C_ELEKTOR) += i2c-elektor.o
15obj-$(CONFIG_I2C_GPIO) += i2c-gpio.o
14obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o 16obj-$(CONFIG_I2C_HYDRA) += i2c-hydra.o
15obj-$(CONFIG_I2C_I801) += i2c-i801.o 17obj-$(CONFIG_I2C_I801) += i2c-i801.o
16obj-$(CONFIG_I2C_I810) += i2c-i810.o 18obj-$(CONFIG_I2C_I810) += i2c-i810.o
@@ -37,10 +39,12 @@ obj-$(CONFIG_I2C_RPXLITE) += i2c-rpx.o
37obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o 39obj-$(CONFIG_I2C_S3C2410) += i2c-s3c2410.o
38obj-$(CONFIG_I2C_SAVAGE4) += i2c-savage4.o 40obj-$(CONFIG_I2C_SAVAGE4) += i2c-savage4.o
39obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o 41obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o
42obj-$(CONFIG_I2C_SIMTEC) += i2c-simtec.o
40obj-$(CONFIG_I2C_SIS5595) += i2c-sis5595.o 43obj-$(CONFIG_I2C_SIS5595) += i2c-sis5595.o
41obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o 44obj-$(CONFIG_I2C_SIS630) += i2c-sis630.o
42obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o 45obj-$(CONFIG_I2C_SIS96X) += i2c-sis96x.o
43obj-$(CONFIG_I2C_STUB) += i2c-stub.o 46obj-$(CONFIG_I2C_STUB) += i2c-stub.o
47obj-$(CONFIG_I2C_TINY_USB) += i2c-tiny-usb.o
44obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o 48obj-$(CONFIG_I2C_VERSATILE) += i2c-versatile.o
45obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o 49obj-$(CONFIG_I2C_ACORN) += i2c-acorn.o
46obj-$(CONFIG_I2C_VIA) += i2c-via.o 50obj-$(CONFIG_I2C_VIA) += i2c-via.o
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index 1e277ba5a9f3..f14372ac2fc5 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -497,7 +497,7 @@ static int __devinit ali1535_probe(struct pci_dev *dev, const struct pci_device_
497 /* set up the sysfs linkage to our parent device */ 497 /* set up the sysfs linkage to our parent device */
498 ali1535_adapter.dev.parent = &dev->dev; 498 ali1535_adapter.dev.parent = &dev->dev;
499 499
500 snprintf(ali1535_adapter.name, I2C_NAME_SIZE, 500 snprintf(ali1535_adapter.name, sizeof(ali1535_adapter.name),
501 "SMBus ALI1535 adapter at %04x", ali1535_smba); 501 "SMBus ALI1535 adapter at %04x", ali1535_smba);
502 return i2c_add_adapter(&ali1535_adapter); 502 return i2c_add_adapter(&ali1535_adapter);
503} 503}
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index e47fe01bf42a..93bf87d70961 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -492,7 +492,7 @@ static int __devinit ali15x3_probe(struct pci_dev *dev, const struct pci_device_
492 /* set up the sysfs linkage to our parent device */ 492 /* set up the sysfs linkage to our parent device */
493 ali15x3_adapter.dev.parent = &dev->dev; 493 ali15x3_adapter.dev.parent = &dev->dev;
494 494
495 snprintf(ali15x3_adapter.name, I2C_NAME_SIZE, 495 snprintf(ali15x3_adapter.name, sizeof(ali15x3_adapter.name),
496 "SMBus ALI15X3 adapter at %04x", ali15x3_smba); 496 "SMBus ALI15X3 adapter at %04x", ali15x3_smba);
497 return i2c_add_adapter(&ali15x3_adapter); 497 return i2c_add_adapter(&ali15x3_adapter);
498} 498}
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c
index 0c70f8293341..c9fca7b49267 100644
--- a/drivers/i2c/busses/i2c-amd8111.c
+++ b/drivers/i2c/busses/i2c-amd8111.c
@@ -365,7 +365,7 @@ static int __devinit amd8111_probe(struct pci_dev *dev,
365 } 365 }
366 366
367 smbus->adapter.owner = THIS_MODULE; 367 smbus->adapter.owner = THIS_MODULE;
368 snprintf(smbus->adapter.name, I2C_NAME_SIZE, 368 snprintf(smbus->adapter.name, sizeof(smbus->adapter.name),
369 "SMBus2 AMD8111 adapter at %04x", smbus->base); 369 "SMBus2 AMD8111 adapter at %04x", smbus->base);
370 smbus->adapter.id = I2C_HW_SMBUS_AMD8111; 370 smbus->adapter.id = I2C_HW_SMBUS_AMD8111;
371 smbus->adapter.class = I2C_CLASS_HWMON; 371 smbus->adapter.class = I2C_CLASS_HWMON;
diff --git a/drivers/i2c/busses/i2c-at91.c b/drivers/i2c/busses/i2c-at91.c
index 67f91bdda089..f35156c58922 100644
--- a/drivers/i2c/busses/i2c-at91.c
+++ b/drivers/i2c/busses/i2c-at91.c
@@ -17,7 +17,6 @@
17#include <linux/version.h> 17#include <linux/version.h>
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/slab.h> 19#include <linux/slab.h>
20#include <linux/pci.h>
21#include <linux/types.h> 20#include <linux/types.h>
22#include <linux/delay.h> 21#include <linux/delay.h>
23#include <linux/i2c.h> 22#include <linux/i2c.h>
diff --git a/drivers/i2c/busses/i2c-bfin-twi.c b/drivers/i2c/busses/i2c-bfin-twi.c
new file mode 100644
index 000000000000..6311039dfe60
--- /dev/null
+++ b/drivers/i2c/busses/i2c-bfin-twi.c
@@ -0,0 +1,644 @@
1/*
2 * drivers/i2c/busses/i2c-bfin-twi.c
3 *
4 * Description: Driver for Blackfin Two Wire Interface
5 *
6 * Author: sonicz <sonic.zhang@analog.com>
7 *
8 * Copyright (c) 2005-2007 Analog Devices, Inc.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 */
24
25#include <linux/module.h>
26#include <linux/kernel.h>
27#include <linux/init.h>
28#include <linux/i2c.h>
29#include <linux/mm.h>
30#include <linux/timer.h>
31#include <linux/spinlock.h>
32#include <linux/completion.h>
33#include <linux/interrupt.h>
34#include <linux/platform_device.h>
35
36#include <asm/blackfin.h>
37#include <asm/irq.h>
38
39#define POLL_TIMEOUT (2 * HZ)
40
41/* SMBus mode*/
42#define TWI_I2C_MODE_STANDARD 0x01
43#define TWI_I2C_MODE_STANDARDSUB 0x02
44#define TWI_I2C_MODE_COMBINED 0x04
45
46struct bfin_twi_iface {
47 struct mutex twi_lock;
48 int irq;
49 spinlock_t lock;
50 char read_write;
51 u8 command;
52 u8 *transPtr;
53 int readNum;
54 int writeNum;
55 int cur_mode;
56 int manual_stop;
57 int result;
58 int timeout_count;
59 struct timer_list timeout_timer;
60 struct i2c_adapter adap;
61 struct completion complete;
62};
63
64static struct bfin_twi_iface twi_iface;
65
66static void bfin_twi_handle_interrupt(struct bfin_twi_iface *iface)
67{
68 unsigned short twi_int_status = bfin_read_TWI_INT_STAT();
69 unsigned short mast_stat = bfin_read_TWI_MASTER_STAT();
70
71 if (twi_int_status & XMTSERV) {
72 /* Transmit next data */
73 if (iface->writeNum > 0) {
74 bfin_write_TWI_XMT_DATA8(*(iface->transPtr++));
75 iface->writeNum--;
76 }
77 /* start receive immediately after complete sending in
78 * combine mode.
79 */
80 else if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
81 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL()
82 | MDIR | RSTART);
83 } else if (iface->manual_stop)
84 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL()
85 | STOP);
86 SSYNC();
87 /* Clear status */
88 bfin_write_TWI_INT_STAT(XMTSERV);
89 SSYNC();
90 }
91 if (twi_int_status & RCVSERV) {
92 if (iface->readNum > 0) {
93 /* Receive next data */
94 *(iface->transPtr) = bfin_read_TWI_RCV_DATA8();
95 if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
96 /* Change combine mode into sub mode after
97 * read first data.
98 */
99 iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
100 /* Get read number from first byte in block
101 * combine mode.
102 */
103 if (iface->readNum == 1 && iface->manual_stop)
104 iface->readNum = *iface->transPtr + 1;
105 }
106 iface->transPtr++;
107 iface->readNum--;
108 } else if (iface->manual_stop) {
109 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL()
110 | STOP);
111 SSYNC();
112 }
113 /* Clear interrupt source */
114 bfin_write_TWI_INT_STAT(RCVSERV);
115 SSYNC();
116 }
117 if (twi_int_status & MERR) {
118 bfin_write_TWI_INT_STAT(MERR);
119 bfin_write_TWI_INT_MASK(0);
120 bfin_write_TWI_MASTER_STAT(0x3e);
121 bfin_write_TWI_MASTER_CTL(0);
122 SSYNC();
123 iface->result = -1;
124 /* if both err and complete int stats are set, return proper
125 * results.
126 */
127 if (twi_int_status & MCOMP) {
128 bfin_write_TWI_INT_STAT(MCOMP);
129 bfin_write_TWI_INT_MASK(0);
130 bfin_write_TWI_MASTER_CTL(0);
131 SSYNC();
132 /* If it is a quick transfer, only address bug no data,
133 * not an err, return 1.
134 */
135 if (iface->writeNum == 0 && (mast_stat & BUFRDERR))
136 iface->result = 1;
137 /* If address not acknowledged return -1,
138 * else return 0.
139 */
140 else if (!(mast_stat & ANAK))
141 iface->result = 0;
142 }
143 complete(&iface->complete);
144 return;
145 }
146 if (twi_int_status & MCOMP) {
147 bfin_write_TWI_INT_STAT(MCOMP);
148 SSYNC();
149 if (iface->cur_mode == TWI_I2C_MODE_COMBINED) {
150 if (iface->readNum == 0) {
151 /* set the read number to 1 and ask for manual
152 * stop in block combine mode
153 */
154 iface->readNum = 1;
155 iface->manual_stop = 1;
156 bfin_write_TWI_MASTER_CTL(
157 bfin_read_TWI_MASTER_CTL()
158 | (0xff << 6));
159 } else {
160 /* set the readd number in other
161 * combine mode.
162 */
163 bfin_write_TWI_MASTER_CTL(
164 (bfin_read_TWI_MASTER_CTL() &
165 (~(0xff << 6))) |
166 ( iface->readNum << 6));
167 }
168 /* remove restart bit and enable master receive */
169 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() &
170 ~RSTART);
171 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() |
172 MEN | MDIR);
173 SSYNC();
174 } else {
175 iface->result = 1;
176 bfin_write_TWI_INT_MASK(0);
177 bfin_write_TWI_MASTER_CTL(0);
178 SSYNC();
179 complete(&iface->complete);
180 }
181 }
182}
183
184/* Interrupt handler */
185static irqreturn_t bfin_twi_interrupt_entry(int irq, void *dev_id)
186{
187 struct bfin_twi_iface *iface = dev_id;
188 unsigned long flags;
189
190 spin_lock_irqsave(&iface->lock, flags);
191 del_timer(&iface->timeout_timer);
192 bfin_twi_handle_interrupt(iface);
193 spin_unlock_irqrestore(&iface->lock, flags);
194 return IRQ_HANDLED;
195}
196
197static void bfin_twi_timeout(unsigned long data)
198{
199 struct bfin_twi_iface *iface = (struct bfin_twi_iface *)data;
200 unsigned long flags;
201
202 spin_lock_irqsave(&iface->lock, flags);
203 bfin_twi_handle_interrupt(iface);
204 if (iface->result == 0) {
205 iface->timeout_count--;
206 if (iface->timeout_count > 0) {
207 iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
208 add_timer(&iface->timeout_timer);
209 } else {
210 iface->result = -1;
211 complete(&iface->complete);
212 }
213 }
214 spin_unlock_irqrestore(&iface->lock, flags);
215}
216
217/*
218 * Generic i2c master transfer entrypoint
219 */
220static int bfin_twi_master_xfer(struct i2c_adapter *adap,
221 struct i2c_msg *msgs, int num)
222{
223 struct bfin_twi_iface *iface = adap->algo_data;
224 struct i2c_msg *pmsg;
225 int i, ret;
226 int rc = 0;
227
228 if (!(bfin_read_TWI_CONTROL() & TWI_ENA))
229 return -ENXIO;
230
231 mutex_lock(&iface->twi_lock);
232
233 while (bfin_read_TWI_MASTER_STAT() & BUSBUSY) {
234 mutex_unlock(&iface->twi_lock);
235 yield();
236 mutex_lock(&iface->twi_lock);
237 }
238
239 ret = 0;
240 for (i = 0; rc >= 0 && i < num; i++) {
241 pmsg = &msgs[i];
242 if (pmsg->flags & I2C_M_TEN) {
243 dev_err(&(adap->dev), "i2c-bfin-twi: 10 bits addr "
244 "not supported !\n");
245 rc = -EINVAL;
246 break;
247 }
248
249 iface->cur_mode = TWI_I2C_MODE_STANDARD;
250 iface->manual_stop = 0;
251 iface->transPtr = pmsg->buf;
252 iface->writeNum = iface->readNum = pmsg->len;
253 iface->result = 0;
254 iface->timeout_count = 10;
255 /* Set Transmit device address */
256 bfin_write_TWI_MASTER_ADDR(pmsg->addr);
257
258 /* FIFO Initiation. Data in FIFO should be
259 * discarded before start a new operation.
260 */
261 bfin_write_TWI_FIFO_CTL(0x3);
262 SSYNC();
263 bfin_write_TWI_FIFO_CTL(0);
264 SSYNC();
265
266 if (pmsg->flags & I2C_M_RD)
267 iface->read_write = I2C_SMBUS_READ;
268 else {
269 iface->read_write = I2C_SMBUS_WRITE;
270 /* Transmit first data */
271 if (iface->writeNum > 0) {
272 bfin_write_TWI_XMT_DATA8(*(iface->transPtr++));
273 iface->writeNum--;
274 SSYNC();
275 }
276 }
277
278 /* clear int stat */
279 bfin_write_TWI_INT_STAT(MERR|MCOMP|XMTSERV|RCVSERV);
280
281 /* Interrupt mask . Enable XMT, RCV interrupt */
282 bfin_write_TWI_INT_MASK(MCOMP | MERR |
283 ((iface->read_write == I2C_SMBUS_READ)?
284 RCVSERV : XMTSERV));
285 SSYNC();
286
287 if (pmsg->len > 0 && pmsg->len <= 255)
288 bfin_write_TWI_MASTER_CTL(pmsg->len << 6);
289 else if (pmsg->len > 255) {
290 bfin_write_TWI_MASTER_CTL(0xff << 6);
291 iface->manual_stop = 1;
292 } else
293 break;
294
295 iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
296 add_timer(&iface->timeout_timer);
297
298 /* Master enable */
299 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN |
300 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) |
301 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0));
302 SSYNC();
303
304 wait_for_completion(&iface->complete);
305
306 rc = iface->result;
307 if (rc == 1)
308 ret++;
309 else if (rc == -1)
310 break;
311 }
312
313 /* Release mutex */
314 mutex_unlock(&iface->twi_lock);
315
316 return ret;
317}
318
319/*
320 * SMBus type transfer entrypoint
321 */
322
323int bfin_twi_smbus_xfer(struct i2c_adapter *adap, u16 addr,
324 unsigned short flags, char read_write,
325 u8 command, int size, union i2c_smbus_data *data)
326{
327 struct bfin_twi_iface *iface = adap->algo_data;
328 int rc = 0;
329
330 if (!(bfin_read_TWI_CONTROL() & TWI_ENA))
331 return -ENXIO;
332
333 mutex_lock(&iface->twi_lock);
334
335 while (bfin_read_TWI_MASTER_STAT() & BUSBUSY) {
336 mutex_unlock(&iface->twi_lock);
337 yield();
338 mutex_lock(&iface->twi_lock);
339 }
340
341 iface->writeNum = 0;
342 iface->readNum = 0;
343
344 /* Prepare datas & select mode */
345 switch (size) {
346 case I2C_SMBUS_QUICK:
347 iface->transPtr = NULL;
348 iface->cur_mode = TWI_I2C_MODE_STANDARD;
349 break;
350 case I2C_SMBUS_BYTE:
351 if (data == NULL)
352 iface->transPtr = NULL;
353 else {
354 if (read_write == I2C_SMBUS_READ)
355 iface->readNum = 1;
356 else
357 iface->writeNum = 1;
358 iface->transPtr = &data->byte;
359 }
360 iface->cur_mode = TWI_I2C_MODE_STANDARD;
361 break;
362 case I2C_SMBUS_BYTE_DATA:
363 if (read_write == I2C_SMBUS_READ) {
364 iface->readNum = 1;
365 iface->cur_mode = TWI_I2C_MODE_COMBINED;
366 } else {
367 iface->writeNum = 1;
368 iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
369 }
370 iface->transPtr = &data->byte;
371 break;
372 case I2C_SMBUS_WORD_DATA:
373 if (read_write == I2C_SMBUS_READ) {
374 iface->readNum = 2;
375 iface->cur_mode = TWI_I2C_MODE_COMBINED;
376 } else {
377 iface->writeNum = 2;
378 iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
379 }
380 iface->transPtr = (u8 *)&data->word;
381 break;
382 case I2C_SMBUS_PROC_CALL:
383 iface->writeNum = 2;
384 iface->readNum = 2;
385 iface->cur_mode = TWI_I2C_MODE_COMBINED;
386 iface->transPtr = (u8 *)&data->word;
387 break;
388 case I2C_SMBUS_BLOCK_DATA:
389 if (read_write == I2C_SMBUS_READ) {
390 iface->readNum = 0;
391 iface->cur_mode = TWI_I2C_MODE_COMBINED;
392 } else {
393 iface->writeNum = data->block[0] + 1;
394 iface->cur_mode = TWI_I2C_MODE_STANDARDSUB;
395 }
396 iface->transPtr = data->block;
397 break;
398 default:
399 return -1;
400 }
401
402 iface->result = 0;
403 iface->manual_stop = 0;
404 iface->read_write = read_write;
405 iface->command = command;
406 iface->timeout_count = 10;
407
408 /* FIFO Initiation. Data in FIFO should be discarded before
409 * start a new operation.
410 */
411 bfin_write_TWI_FIFO_CTL(0x3);
412 SSYNC();
413 bfin_write_TWI_FIFO_CTL(0);
414
415 /* clear int stat */
416 bfin_write_TWI_INT_STAT(MERR|MCOMP|XMTSERV|RCVSERV);
417
418 /* Set Transmit device address */
419 bfin_write_TWI_MASTER_ADDR(addr);
420 SSYNC();
421
422 iface->timeout_timer.expires = jiffies + POLL_TIMEOUT;
423 add_timer(&iface->timeout_timer);
424
425 switch (iface->cur_mode) {
426 case TWI_I2C_MODE_STANDARDSUB:
427 bfin_write_TWI_XMT_DATA8(iface->command);
428 bfin_write_TWI_INT_MASK(MCOMP | MERR |
429 ((iface->read_write == I2C_SMBUS_READ) ?
430 RCVSERV : XMTSERV));
431 SSYNC();
432
433 if (iface->writeNum + 1 <= 255)
434 bfin_write_TWI_MASTER_CTL((iface->writeNum + 1) << 6);
435 else {
436 bfin_write_TWI_MASTER_CTL(0xff << 6);
437 iface->manual_stop = 1;
438 }
439 /* Master enable */
440 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN |
441 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0));
442 break;
443 case TWI_I2C_MODE_COMBINED:
444 bfin_write_TWI_XMT_DATA8(iface->command);
445 bfin_write_TWI_INT_MASK(MCOMP | MERR | RCVSERV | XMTSERV);
446 SSYNC();
447
448 if (iface->writeNum > 0)
449 bfin_write_TWI_MASTER_CTL((iface->writeNum + 1) << 6);
450 else
451 bfin_write_TWI_MASTER_CTL(0x1 << 6);
452 /* Master enable */
453 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN |
454 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ>100) ? FAST : 0));
455 break;
456 default:
457 bfin_write_TWI_MASTER_CTL(0);
458 if (size != I2C_SMBUS_QUICK) {
459 /* Don't access xmit data register when this is a
460 * read operation.
461 */
462 if (iface->read_write != I2C_SMBUS_READ) {
463 if (iface->writeNum > 0) {
464 bfin_write_TWI_XMT_DATA8(*(iface->transPtr++));
465 if (iface->writeNum <= 255)
466 bfin_write_TWI_MASTER_CTL(iface->writeNum << 6);
467 else {
468 bfin_write_TWI_MASTER_CTL(0xff << 6);
469 iface->manual_stop = 1;
470 }
471 iface->writeNum--;
472 } else {
473 bfin_write_TWI_XMT_DATA8(iface->command);
474 bfin_write_TWI_MASTER_CTL(1 << 6);
475 }
476 } else {
477 if (iface->readNum > 0 && iface->readNum <= 255)
478 bfin_write_TWI_MASTER_CTL(iface->readNum << 6);
479 else if (iface->readNum > 255) {
480 bfin_write_TWI_MASTER_CTL(0xff << 6);
481 iface->manual_stop = 1;
482 } else {
483 del_timer(&iface->timeout_timer);
484 break;
485 }
486 }
487 }
488 bfin_write_TWI_INT_MASK(MCOMP | MERR |
489 ((iface->read_write == I2C_SMBUS_READ) ?
490 RCVSERV : XMTSERV));
491 SSYNC();
492
493 /* Master enable */
494 bfin_write_TWI_MASTER_CTL(bfin_read_TWI_MASTER_CTL() | MEN |
495 ((iface->read_write == I2C_SMBUS_READ) ? MDIR : 0) |
496 ((CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ > 100) ? FAST : 0));
497 break;
498 }
499 SSYNC();
500
501 wait_for_completion(&iface->complete);
502
503 rc = (iface->result >= 0) ? 0 : -1;
504
505 /* Release mutex */
506 mutex_unlock(&iface->twi_lock);
507
508 return rc;
509}
510
511/*
512 * Return what the adapter supports
513 */
514static u32 bfin_twi_functionality(struct i2c_adapter *adap)
515{
516 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
517 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
518 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL |
519 I2C_FUNC_I2C;
520}
521
522
523static struct i2c_algorithm bfin_twi_algorithm = {
524 .master_xfer = bfin_twi_master_xfer,
525 .smbus_xfer = bfin_twi_smbus_xfer,
526 .functionality = bfin_twi_functionality,
527};
528
529
530static int i2c_bfin_twi_suspend(struct platform_device *dev, pm_message_t state)
531{
532/* struct bfin_twi_iface *iface = platform_get_drvdata(dev);*/
533
534 /* Disable TWI */
535 bfin_write_TWI_CONTROL(bfin_read_TWI_CONTROL() & ~TWI_ENA);
536 SSYNC();
537
538 return 0;
539}
540
541static int i2c_bfin_twi_resume(struct platform_device *dev)
542{
543/* struct bfin_twi_iface *iface = platform_get_drvdata(dev);*/
544
545 /* Enable TWI */
546 bfin_write_TWI_CONTROL(bfin_read_TWI_CONTROL() | TWI_ENA);
547 SSYNC();
548
549 return 0;
550}
551
552static int i2c_bfin_twi_probe(struct platform_device *dev)
553{
554 struct bfin_twi_iface *iface = &twi_iface;
555 struct i2c_adapter *p_adap;
556 int rc;
557
558 mutex_init(&(iface->twi_lock));
559 spin_lock_init(&(iface->lock));
560 init_completion(&(iface->complete));
561 iface->irq = IRQ_TWI;
562
563 init_timer(&(iface->timeout_timer));
564 iface->timeout_timer.function = bfin_twi_timeout;
565 iface->timeout_timer.data = (unsigned long)iface;
566
567 p_adap = &iface->adap;
568 p_adap->id = I2C_HW_BLACKFIN;
569 strlcpy(p_adap->name, dev->name, sizeof(p_adap->name));
570 p_adap->algo = &bfin_twi_algorithm;
571 p_adap->algo_data = iface;
572 p_adap->class = I2C_CLASS_ALL;
573 p_adap->dev.parent = &dev->dev;
574
575 rc = request_irq(iface->irq, bfin_twi_interrupt_entry,
576 IRQF_DISABLED, dev->name, iface);
577 if (rc) {
578 dev_err(&(p_adap->dev), "i2c-bfin-twi: can't get IRQ %d !\n",
579 iface->irq);
580 return -ENODEV;
581 }
582
583 /* Set TWI internal clock as 10MHz */
584 bfin_write_TWI_CONTROL(((get_sclk() / 1024 / 1024 + 5) / 10) & 0x7F);
585
586 /* Set Twi interface clock as specified */
587 bfin_write_TWI_CLKDIV((( 5*1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ )
588 << 8) | (( 5*1024 / CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ )
589 & 0xFF));
590
591 /* Enable TWI */
592 bfin_write_TWI_CONTROL(bfin_read_TWI_CONTROL() | TWI_ENA);
593 SSYNC();
594
595 rc = i2c_add_adapter(p_adap);
596 if (rc < 0)
597 free_irq(iface->irq, iface);
598 else
599 platform_set_drvdata(dev, iface);
600
601 return rc;
602}
603
604static int i2c_bfin_twi_remove(struct platform_device *pdev)
605{
606 struct bfin_twi_iface *iface = platform_get_drvdata(pdev);
607
608 platform_set_drvdata(pdev, NULL);
609
610 i2c_del_adapter(&(iface->adap));
611 free_irq(iface->irq, iface);
612
613 return 0;
614}
615
616static struct platform_driver i2c_bfin_twi_driver = {
617 .probe = i2c_bfin_twi_probe,
618 .remove = i2c_bfin_twi_remove,
619 .suspend = i2c_bfin_twi_suspend,
620 .resume = i2c_bfin_twi_resume,
621 .driver = {
622 .name = "i2c-bfin-twi",
623 .owner = THIS_MODULE,
624 },
625};
626
627static int __init i2c_bfin_twi_init(void)
628{
629 pr_info("I2C: Blackfin I2C TWI driver\n");
630
631 return platform_driver_register(&i2c_bfin_twi_driver);
632}
633
634static void __exit i2c_bfin_twi_exit(void)
635{
636 platform_driver_unregister(&i2c_bfin_twi_driver);
637}
638
639MODULE_AUTHOR("Sonic Zhang <sonic.zhang@analog.com>");
640MODULE_DESCRIPTION("I2C-Bus adapter routines for Blackfin TWI");
641MODULE_LICENSE("GPL");
642
643module_init(i2c_bfin_twi_init);
644module_exit(i2c_bfin_twi_exit);
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c
index 834967464814..804f0a551c05 100644
--- a/drivers/i2c/busses/i2c-elektor.c
+++ b/drivers/i2c/busses/i2c-elektor.c
@@ -35,6 +35,7 @@
35#include <linux/pci.h> 35#include <linux/pci.h>
36#include <linux/wait.h> 36#include <linux/wait.h>
37 37
38#include <linux/isa.h>
38#include <linux/i2c.h> 39#include <linux/i2c.h>
39#include <linux/i2c-algo-pcf.h> 40#include <linux/i2c-algo-pcf.h>
40 41
@@ -207,7 +208,7 @@ static struct i2c_adapter pcf_isa_ops = {
207 .name = "i2c-elektor", 208 .name = "i2c-elektor",
208}; 209};
209 210
210static int __init i2c_pcfisa_init(void) 211static int __devinit elektor_match(struct device *dev, unsigned int id)
211{ 212{
212#ifdef __alpha__ 213#ifdef __alpha__
213 /* check to see we have memory mapped PCF8584 connected to the 214 /* check to see we have memory mapped PCF8584 connected to the
@@ -222,9 +223,8 @@ static int __init i2c_pcfisa_init(void)
222 /* yeap, we've found cypress, let's check config */ 223 /* yeap, we've found cypress, let's check config */
223 if (!pci_read_config_byte(cy693_dev, 0x47, &config)) { 224 if (!pci_read_config_byte(cy693_dev, 0x47, &config)) {
224 225
225 pr_debug("%s: found cy82c693, config " 226 dev_dbg(dev, "found cy82c693, config "
226 "register 0x47 = 0x%02x\n", 227 "register 0x47 = 0x%02x\n", config);
227 pcf_isa_ops.name, config);
228 228
229 /* UP2000 board has this register set to 0xe1, 229 /* UP2000 board has this register set to 0xe1,
230 but the most significant bit as seems can be 230 but the most significant bit as seems can be
@@ -244,9 +244,9 @@ static int __init i2c_pcfisa_init(void)
244 8.25 MHz (PCI/4) clock 244 8.25 MHz (PCI/4) clock
245 (this can be read from cypress) */ 245 (this can be read from cypress) */
246 clock = I2C_PCF_CLK | I2C_PCF_TRNS90; 246 clock = I2C_PCF_CLK | I2C_PCF_TRNS90;
247 pr_info("%s: found API UP2000 like " 247 dev_info(dev, "found API UP2000 like "
248 "board, will probe PCF8584 " 248 "board, will probe PCF8584 "
249 "later\n", pcf_isa_ops.name); 249 "later\n");
250 } 250 }
251 } 251 }
252 pci_dev_put(cy693_dev); 252 pci_dev_put(cy693_dev);
@@ -256,22 +256,27 @@ static int __init i2c_pcfisa_init(void)
256 256
257 /* sanity checks for mmapped I/O */ 257 /* sanity checks for mmapped I/O */
258 if (mmapped && base < 0xc8000) { 258 if (mmapped && base < 0xc8000) {
259 printk(KERN_ERR "%s: incorrect base address (%#x) specified " 259 dev_err(dev, "incorrect base address (%#x) specified "
260 "for mmapped I/O\n", pcf_isa_ops.name, base); 260 "for mmapped I/O\n", base);
261 return -ENODEV; 261 return 0;
262 } 262 }
263 263
264 if (base == 0) { 264 if (base == 0) {
265 base = DEFAULT_BASE; 265 base = DEFAULT_BASE;
266 } 266 }
267 return 1;
268}
267 269
270static int __devinit elektor_probe(struct device *dev, unsigned int id)
271{
268 init_waitqueue_head(&pcf_wait); 272 init_waitqueue_head(&pcf_wait);
269 if (pcf_isa_init()) 273 if (pcf_isa_init())
270 return -ENODEV; 274 return -ENODEV;
275 pcf_isa_ops.dev.parent = dev;
271 if (i2c_pcf_add_bus(&pcf_isa_ops) < 0) 276 if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
272 goto fail; 277 goto fail;
273 278
274 dev_info(&pcf_isa_ops.dev, "found device at %#x\n", base); 279 dev_info(dev, "found device at %#x\n", base);
275 280
276 return 0; 281 return 0;
277 282
@@ -291,7 +296,7 @@ static int __init i2c_pcfisa_init(void)
291 return -ENODEV; 296 return -ENODEV;
292} 297}
293 298
294static void i2c_pcfisa_exit(void) 299static int __devexit elektor_remove(struct device *dev, unsigned int id)
295{ 300{
296 i2c_del_adapter(&pcf_isa_ops); 301 i2c_del_adapter(&pcf_isa_ops);
297 302
@@ -307,6 +312,28 @@ static void i2c_pcfisa_exit(void)
307 iounmap(base_iomem); 312 iounmap(base_iomem);
308 release_mem_region(base, 2); 313 release_mem_region(base, 2);
309 } 314 }
315
316 return 0;
317}
318
319static struct isa_driver i2c_elektor_driver = {
320 .match = elektor_match,
321 .probe = elektor_probe,
322 .remove = __devexit_p(elektor_remove),
323 .driver = {
324 .owner = THIS_MODULE,
325 .name = "i2c-elektor",
326 },
327};
328
329static int __init i2c_pcfisa_init(void)
330{
331 return isa_register_driver(&i2c_elektor_driver, 1);
332}
333
334static void __exit i2c_pcfisa_exit(void)
335{
336 isa_unregister_driver(&i2c_elektor_driver);
310} 337}
311 338
312MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>"); 339MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
diff --git a/drivers/i2c/busses/i2c-gpio.c b/drivers/i2c/busses/i2c-gpio.c
new file mode 100644
index 000000000000..a7dd54654a9a
--- /dev/null
+++ b/drivers/i2c/busses/i2c-gpio.c
@@ -0,0 +1,215 @@
1/*
2 * Bitbanging I2C bus driver using the GPIO API
3 *
4 * Copyright (C) 2007 Atmel Corporation
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 version 2 as
8 * published by the Free Software Foundation.
9 */
10#include <linux/i2c.h>
11#include <linux/i2c-algo-bit.h>
12#include <linux/i2c-gpio.h>
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/platform_device.h>
16
17#include <asm/gpio.h>
18
19/* Toggle SDA by changing the direction of the pin */
20static void i2c_gpio_setsda_dir(void *data, int state)
21{
22 struct i2c_gpio_platform_data *pdata = data;
23
24 if (state)
25 gpio_direction_input(pdata->sda_pin);
26 else
27 gpio_direction_output(pdata->sda_pin, 0);
28}
29
30/*
31 * Toggle SDA by changing the output value of the pin. This is only
32 * valid for pins configured as open drain (i.e. setting the value
33 * high effectively turns off the output driver.)
34 */
35static void i2c_gpio_setsda_val(void *data, int state)
36{
37 struct i2c_gpio_platform_data *pdata = data;
38
39 gpio_set_value(pdata->sda_pin, state);
40}
41
42/* Toggle SCL by changing the direction of the pin. */
43static void i2c_gpio_setscl_dir(void *data, int state)
44{
45 struct i2c_gpio_platform_data *pdata = data;
46
47 if (state)
48 gpio_direction_input(pdata->scl_pin);
49 else
50 gpio_direction_output(pdata->scl_pin, 0);
51}
52
53/*
54 * Toggle SCL by changing the output value of the pin. This is used
55 * for pins that are configured as open drain and for output-only
56 * pins. The latter case will break the i2c protocol, but it will
57 * often work in practice.
58 */
59static void i2c_gpio_setscl_val(void *data, int state)
60{
61 struct i2c_gpio_platform_data *pdata = data;
62
63 gpio_set_value(pdata->scl_pin, state);
64}
65
66int i2c_gpio_getsda(void *data)
67{
68 struct i2c_gpio_platform_data *pdata = data;
69
70 return gpio_get_value(pdata->sda_pin);
71}
72
73int i2c_gpio_getscl(void *data)
74{
75 struct i2c_gpio_platform_data *pdata = data;
76
77 return gpio_get_value(pdata->scl_pin);
78}
79
80static int __init i2c_gpio_probe(struct platform_device *pdev)
81{
82 struct i2c_gpio_platform_data *pdata;
83 struct i2c_algo_bit_data *bit_data;
84 struct i2c_adapter *adap;
85 int ret;
86
87 pdata = pdev->dev.platform_data;
88 if (!pdata)
89 return -ENXIO;
90
91 ret = -ENOMEM;
92 adap = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
93 if (!adap)
94 goto err_alloc_adap;
95 bit_data = kzalloc(sizeof(struct i2c_algo_bit_data), GFP_KERNEL);
96 if (!bit_data)
97 goto err_alloc_bit_data;
98
99 ret = gpio_request(pdata->sda_pin, "sda");
100 if (ret)
101 goto err_request_sda;
102 ret = gpio_request(pdata->scl_pin, "scl");
103 if (ret)
104 goto err_request_scl;
105
106 if (pdata->sda_is_open_drain) {
107 gpio_direction_output(pdata->sda_pin, 1);
108 bit_data->setsda = i2c_gpio_setsda_val;
109 } else {
110 gpio_direction_input(pdata->sda_pin);
111 bit_data->setsda = i2c_gpio_setsda_dir;
112 }
113
114 if (pdata->scl_is_open_drain || pdata->scl_is_output_only) {
115 gpio_direction_output(pdata->scl_pin, 1);
116 bit_data->setscl = i2c_gpio_setscl_val;
117 } else {
118 gpio_direction_input(pdata->scl_pin);
119 bit_data->setscl = i2c_gpio_setscl_dir;
120 }
121
122 if (!pdata->scl_is_output_only)
123 bit_data->getscl = i2c_gpio_getscl;
124 bit_data->getsda = i2c_gpio_getsda;
125
126 if (pdata->udelay)
127 bit_data->udelay = pdata->udelay;
128 else if (pdata->scl_is_output_only)
129 bit_data->udelay = 50; /* 10 kHz */
130 else
131 bit_data->udelay = 5; /* 100 kHz */
132
133 if (pdata->timeout)
134 bit_data->timeout = pdata->timeout;
135 else
136 bit_data->timeout = HZ / 10; /* 100 ms */
137
138 bit_data->data = pdata;
139
140 adap->owner = THIS_MODULE;
141 snprintf(adap->name, sizeof(adap->name), "i2c-gpio%d", pdev->id);
142 adap->algo_data = bit_data;
143 adap->dev.parent = &pdev->dev;
144
145 ret = i2c_bit_add_bus(adap);
146 if (ret)
147 goto err_add_bus;
148
149 platform_set_drvdata(pdev, adap);
150
151 dev_info(&pdev->dev, "using pins %u (SDA) and %u (SCL%s)\n",
152 pdata->sda_pin, pdata->scl_pin,
153 pdata->scl_is_output_only
154 ? ", no clock stretching" : "");
155
156 return 0;
157
158err_add_bus:
159 gpio_free(pdata->scl_pin);
160err_request_scl:
161 gpio_free(pdata->sda_pin);
162err_request_sda:
163 kfree(bit_data);
164err_alloc_bit_data:
165 kfree(adap);
166err_alloc_adap:
167 return ret;
168}
169
170static int __exit i2c_gpio_remove(struct platform_device *pdev)
171{
172 struct i2c_gpio_platform_data *pdata;
173 struct i2c_adapter *adap;
174
175 adap = platform_get_drvdata(pdev);
176 pdata = pdev->dev.platform_data;
177
178 i2c_del_adapter(adap);
179 gpio_free(pdata->scl_pin);
180 gpio_free(pdata->sda_pin);
181 kfree(adap->algo_data);
182 kfree(adap);
183
184 return 0;
185}
186
187static struct platform_driver i2c_gpio_driver = {
188 .driver = {
189 .name = "i2c-gpio",
190 .owner = THIS_MODULE,
191 },
192 .remove = __exit_p(i2c_gpio_remove),
193};
194
195static int __init i2c_gpio_init(void)
196{
197 int ret;
198
199 ret = platform_driver_probe(&i2c_gpio_driver, i2c_gpio_probe);
200 if (ret)
201 printk(KERN_ERR "i2c-gpio: probe failed: %d\n", ret);
202
203 return ret;
204}
205module_init(i2c_gpio_init);
206
207static void __exit i2c_gpio_exit(void)
208{
209 platform_driver_unregister(&i2c_gpio_driver);
210}
211module_exit(i2c_gpio_exit);
212
213MODULE_AUTHOR("Haavard Skinnemoen <hskinnemoen@atmel.com>");
214MODULE_DESCRIPTION("Platform-independent bitbanging I2C driver");
215MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index a320e7d82c1f..611b57192c96 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -527,7 +527,7 @@ static int __devinit i801_probe(struct pci_dev *dev, const struct pci_device_id
527 /* set up the sysfs linkage to our parent device */ 527 /* set up the sysfs linkage to our parent device */
528 i801_adapter.dev.parent = &dev->dev; 528 i801_adapter.dev.parent = &dev->dev;
529 529
530 snprintf(i801_adapter.name, I2C_NAME_SIZE, 530 snprintf(i801_adapter.name, sizeof(i801_adapter.name),
531 "SMBus I801 adapter at %04lx", i801_smba); 531 "SMBus I801 adapter at %04lx", i801_smba);
532 err = i2c_add_adapter(&i801_adapter); 532 err = i2c_add_adapter(&i801_adapter);
533 if (err) { 533 if (err) {
diff --git a/drivers/i2c/busses/i2c-isa.c b/drivers/i2c/busses/i2c-isa.c
index 5f33bc9c1e02..b0e1370075de 100644
--- a/drivers/i2c/busses/i2c-isa.c
+++ b/drivers/i2c/busses/i2c-isa.c
@@ -41,6 +41,10 @@
41#include <linux/platform_device.h> 41#include <linux/platform_device.h>
42#include <linux/completion.h> 42#include <linux/completion.h>
43 43
44/* Exported by i2c-core for i2c-isa only */
45extern void i2c_adapter_dev_release(struct device *dev);
46extern struct class i2c_adapter_class;
47
44static u32 isa_func(struct i2c_adapter *adapter); 48static u32 isa_func(struct i2c_adapter *adapter);
45 49
46/* This is the actual algorithm we define */ 50/* This is the actual algorithm we define */
@@ -64,16 +68,6 @@ static u32 isa_func(struct i2c_adapter *adapter)
64} 68}
65 69
66 70
67/* Copied from i2c-core */
68static ssize_t show_adapter_name(struct device *dev,
69 struct device_attribute *attr, char *buf)
70{
71 struct i2c_adapter *adap = dev_to_i2c_adapter(dev);
72 return sprintf(buf, "%s\n", adap->name);
73}
74static DEVICE_ATTR(name, S_IRUGO, show_adapter_name, NULL);
75
76
77/* We implement an interface which resembles i2c_{add,del}_driver, 71/* We implement an interface which resembles i2c_{add,del}_driver,
78 but for i2c-isa drivers. We don't have to remember and handle lists 72 but for i2c-isa drivers. We don't have to remember and handle lists
79 of drivers and adapters so this is much more simple, of course. */ 73 of drivers and adapters so this is much more simple, of course. */
@@ -139,41 +133,18 @@ static int __init i2c_isa_init(void)
139 isa_adapter.nr = ANY_I2C_ISA_BUS; 133 isa_adapter.nr = ANY_I2C_ISA_BUS;
140 isa_adapter.dev.parent = &platform_bus; 134 isa_adapter.dev.parent = &platform_bus;
141 sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr); 135 sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr);
142 isa_adapter.dev.driver = &i2c_adapter_driver;
143 isa_adapter.dev.release = &i2c_adapter_dev_release; 136 isa_adapter.dev.release = &i2c_adapter_dev_release;
137 isa_adapter.dev.class = &i2c_adapter_class;
144 err = device_register(&isa_adapter.dev); 138 err = device_register(&isa_adapter.dev);
145 if (err) { 139 if (err) {
146 printk(KERN_ERR "i2c-isa: Failed to register device\n"); 140 printk(KERN_ERR "i2c-isa: Failed to register device\n");
147 goto exit; 141 goto exit;
148 } 142 }
149 err = device_create_file(&isa_adapter.dev, &dev_attr_name);
150 if (err) {
151 printk(KERN_ERR "i2c-isa: Failed to create name file\n");
152 goto exit_unregister;
153 }
154
155 /* Add this adapter to the i2c_adapter class */
156 memset(&isa_adapter.class_dev, 0x00, sizeof(struct class_device));
157 isa_adapter.class_dev.dev = &isa_adapter.dev;
158 isa_adapter.class_dev.class = &i2c_adapter_class;
159 strlcpy(isa_adapter.class_dev.class_id, isa_adapter.dev.bus_id,
160 BUS_ID_SIZE);
161 err = class_device_register(&isa_adapter.class_dev);
162 if (err) {
163 printk(KERN_ERR "i2c-isa: Failed to register class device\n");
164 goto exit_remove_name;
165 }
166 143
167 dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name); 144 dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name);
168 145
169 return 0; 146 return 0;
170 147
171exit_remove_name:
172 device_remove_file(&isa_adapter.dev, &dev_attr_name);
173exit_unregister:
174 init_completion(&isa_adapter.dev_released); /* Needed? */
175 device_unregister(&isa_adapter.dev);
176 wait_for_completion(&isa_adapter.dev_released);
177exit: 148exit:
178 return err; 149 return err;
179} 150}
@@ -201,15 +172,11 @@ static void __exit i2c_isa_exit(void)
201 /* Clean up the sysfs representation */ 172 /* Clean up the sysfs representation */
202 dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n"); 173 dev_dbg(&isa_adapter.dev, "Unregistering from sysfs\n");
203 init_completion(&isa_adapter.dev_released); 174 init_completion(&isa_adapter.dev_released);
204 init_completion(&isa_adapter.class_dev_released);
205 class_device_unregister(&isa_adapter.class_dev);
206 device_remove_file(&isa_adapter.dev, &dev_attr_name);
207 device_unregister(&isa_adapter.dev); 175 device_unregister(&isa_adapter.dev);
208 176
209 /* Wait for sysfs to drop all references */ 177 /* Wait for sysfs to drop all references */
210 dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n"); 178 dev_dbg(&isa_adapter.dev, "Waiting for sysfs completion\n");
211 wait_for_completion(&isa_adapter.dev_released); 179 wait_for_completion(&isa_adapter.dev_released);
212 wait_for_completion(&isa_adapter.class_dev_released);
213 180
214 dev_dbg(&isa_adapter.dev, "%s unregistered\n", isa_adapter.name); 181 dev_dbg(&isa_adapter.dev, "%s unregistered\n", isa_adapter.name);
215} 182}
diff --git a/drivers/i2c/busses/i2c-ixp2000.c b/drivers/i2c/busses/i2c-ixp2000.c
index efa3ecc5522a..6352121a2827 100644
--- a/drivers/i2c/busses/i2c-ixp2000.c
+++ b/drivers/i2c/busses/i2c-ixp2000.c
@@ -118,7 +118,7 @@ static int ixp2000_i2c_probe(struct platform_device *plat_dev)
118 118
119 drv_data->adapter.id = I2C_HW_B_IXP2000, 119 drv_data->adapter.id = I2C_HW_B_IXP2000,
120 strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name, 120 strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name,
121 I2C_NAME_SIZE); 121 sizeof(drv_data->adapter.name));
122 drv_data->adapter.algo_data = &drv_data->algo_data, 122 drv_data->adapter.algo_data = &drv_data->algo_data,
123 123
124 drv_data->adapter.dev.parent = &plat_dev->dev; 124 drv_data->adapter.dev.parent = &plat_dev->dev;
diff --git a/drivers/i2c/busses/i2c-ixp4xx.c b/drivers/i2c/busses/i2c-ixp4xx.c
index 08e89b83984a..069ed7f3b395 100644
--- a/drivers/i2c/busses/i2c-ixp4xx.c
+++ b/drivers/i2c/busses/i2c-ixp4xx.c
@@ -127,7 +127,7 @@ static int ixp4xx_i2c_probe(struct platform_device *plat_dev)
127 drv_data->adapter.id = I2C_HW_B_IXP4XX; 127 drv_data->adapter.id = I2C_HW_B_IXP4XX;
128 drv_data->adapter.class = I2C_CLASS_HWMON; 128 drv_data->adapter.class = I2C_CLASS_HWMON;
129 strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name, 129 strlcpy(drv_data->adapter.name, plat_dev->dev.driver->name,
130 I2C_NAME_SIZE); 130 sizeof(drv_data->adapter.name));
131 drv_data->adapter.algo_data = &drv_data->algo_data; 131 drv_data->adapter.algo_data = &drv_data->algo_data;
132 132
133 drv_data->adapter.dev.parent = &plat_dev->dev; 133 drv_data->adapter.dev.parent = &plat_dev->dev;
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index ee65aa1be13a..c6b6898592b1 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -17,7 +17,6 @@
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/pci.h>
21#include <linux/platform_device.h> 20#include <linux/platform_device.h>
22 21
23#include <asm/io.h> 22#include <asm/io.h>
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index a3283b907eb8..a55b3335d1be 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -508,7 +508,7 @@ mv64xxx_i2c_probe(struct platform_device *pd)
508 } 508 }
509 509
510 strlcpy(drv_data->adapter.name, MV64XXX_I2C_CTLR_NAME " adapter", 510 strlcpy(drv_data->adapter.name, MV64XXX_I2C_CTLR_NAME " adapter",
511 I2C_NAME_SIZE); 511 sizeof(drv_data->adapter.name));
512 512
513 init_waitqueue_head(&drv_data->waitq); 513 init_waitqueue_head(&drv_data->waitq);
514 spin_lock_init(&drv_data->lock); 514 spin_lock_init(&drv_data->lock);
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index 1514ec5b77f8..3cd0d63e7b50 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -33,6 +33,8 @@
33 nForce4 MCP-04 0034 33 nForce4 MCP-04 0034
34 nForce4 MCP51 0264 34 nForce4 MCP51 0264
35 nForce4 MCP55 0368 35 nForce4 MCP55 0368
36 nForce MCP61 03EB
37 nForce MCP65 0446
36 38
37 This driver supports the 2 SMBuses that are included in the MCP of the 39 This driver supports the 2 SMBuses that are included in the MCP of the
38 nForce2/3/4/5xx chipsets. 40 nForce2/3/4/5xx chipsets.
@@ -200,6 +202,8 @@ static struct pci_device_id nforce2_ids[] = {
200 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SMBUS) }, 202 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP04_SMBUS) },
201 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SMBUS) }, 203 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP51_SMBUS) },
202 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS) }, 204 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP55_SMBUS) },
205 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP61_SMBUS) },
206 { PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NFORCE_MCP65_SMBUS) },
203 { 0 } 207 { 0 }
204}; 208};
205 209
@@ -240,7 +244,7 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int bar,
240 smbus->adapter.algo = &smbus_algorithm; 244 smbus->adapter.algo = &smbus_algorithm;
241 smbus->adapter.algo_data = smbus; 245 smbus->adapter.algo_data = smbus;
242 smbus->adapter.dev.parent = &dev->dev; 246 smbus->adapter.dev.parent = &dev->dev;
243 snprintf(smbus->adapter.name, I2C_NAME_SIZE, 247 snprintf(smbus->adapter.name, sizeof(smbus->adapter.name),
244 "SMBus nForce2 adapter at %04x", smbus->base); 248 "SMBus nForce2 adapter at %04x", smbus->base);
245 249
246 error = i2c_add_adapter(&smbus->adapter); 250 error = i2c_add_adapter(&smbus->adapter);
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
index bcd8367cede1..e471e3bfdc1e 100644
--- a/drivers/i2c/busses/i2c-omap.c
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -605,7 +605,8 @@ omap_i2c_probe(struct platform_device *pdev)
605 adap->dev.parent = &pdev->dev; 605 adap->dev.parent = &pdev->dev;
606 606
607 /* i2c device drivers may be active on return from add_adapter() */ 607 /* i2c device drivers may be active on return from add_adapter() */
608 r = i2c_add_adapter(adap); 608 adap->nr = pdev->id;
609 r = i2c_add_numbered_adapter(adap);
609 if (r) { 610 if (r) {
610 dev_err(dev->dev, "failure adding adapter\n"); 611 dev_err(dev->dev, "failure adding adapter\n");
611 goto err_free_irq; 612 goto err_free_irq;
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c
index 4bc42810b9aa..49a95e2887bc 100644
--- a/drivers/i2c/busses/i2c-parport-light.c
+++ b/drivers/i2c/busses/i2c-parport-light.c
@@ -1,7 +1,7 @@
1/* ------------------------------------------------------------------------ * 1/* ------------------------------------------------------------------------ *
2 * i2c-parport.c I2C bus over parallel port * 2 * i2c-parport-light.c I2C bus over parallel port *
3 * ------------------------------------------------------------------------ * 3 * ------------------------------------------------------------------------ *
4 Copyright (C) 2003-2004 Jean Delvare <khali@linux-fr.org> 4 Copyright (C) 2003-2007 Jean Delvare <khali@linux-fr.org>
5 5
6 Based on older i2c-velleman.c driver 6 Based on older i2c-velleman.c driver
7 Copyright (C) 1995-2000 Simon G. Vogl 7 Copyright (C) 1995-2000 Simon G. Vogl
@@ -27,6 +27,7 @@
27#include <linux/kernel.h> 27#include <linux/kernel.h>
28#include <linux/module.h> 28#include <linux/module.h>
29#include <linux/init.h> 29#include <linux/init.h>
30#include <linux/platform_device.h>
30#include <linux/ioport.h> 31#include <linux/ioport.h>
31#include <linux/i2c.h> 32#include <linux/i2c.h>
32#include <linux/i2c-algo-bit.h> 33#include <linux/i2c-algo-bit.h>
@@ -34,6 +35,9 @@
34#include "i2c-parport.h" 35#include "i2c-parport.h"
35 36
36#define DEFAULT_BASE 0x378 37#define DEFAULT_BASE 0x378
38#define DRVNAME "i2c-parport-light"
39
40static struct platform_device *pdev;
37 41
38static u16 base; 42static u16 base;
39module_param(base, ushort, 0); 43module_param(base, ushort, 0);
@@ -106,7 +110,7 @@ static struct i2c_algo_bit_data parport_algo_data = {
106 .timeout = HZ, 110 .timeout = HZ,
107}; 111};
108 112
109/* ----- I2c structure ---------------------------------------------------- */ 113/* ----- Driver registration ---------------------------------------------- */
110 114
111static struct i2c_adapter parport_adapter = { 115static struct i2c_adapter parport_adapter = {
112 .owner = THIS_MODULE, 116 .owner = THIS_MODULE,
@@ -116,55 +120,141 @@ static struct i2c_adapter parport_adapter = {
116 .name = "Parallel port adapter (light)", 120 .name = "Parallel port adapter (light)",
117}; 121};
118 122
119/* ----- Module loading, unloading and information ------------------------ */ 123static int __devinit i2c_parport_probe(struct platform_device *pdev)
124{
125 int err;
126 struct resource *res;
127
128 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
129 if (!request_region(res->start, res->end - res->start + 1, DRVNAME))
130 return -EBUSY;
131
132 /* Reset hardware to a sane state (SCL and SDA high) */
133 parport_setsda(NULL, 1);
134 parport_setscl(NULL, 1);
135 /* Other init if needed (power on...) */
136 if (adapter_parm[type].init.val)
137 line_set(1, &adapter_parm[type].init);
138
139 parport_adapter.dev.parent = &pdev->dev;
140 err = i2c_bit_add_bus(&parport_adapter);
141 if (err) {
142 dev_err(&pdev->dev, "Unable to register with I2C\n");
143 goto exit_region;
144 }
145 return 0;
146
147exit_region:
148 release_region(res->start, res->end - res->start + 1);
149 return err;
150}
151
152static int __devexit i2c_parport_remove(struct platform_device *pdev)
153{
154 struct resource *res;
155
156 i2c_del_adapter(&parport_adapter);
157
158 /* Un-init if needed (power off...) */
159 if (adapter_parm[type].init.val)
160 line_set(0, &adapter_parm[type].init);
161
162 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
163 release_region(res->start, res->end - res->start + 1);
164 return 0;
165}
166
167static struct platform_driver i2c_parport_driver = {
168 .driver = {
169 .owner = THIS_MODULE,
170 .name = DRVNAME,
171 },
172 .probe = i2c_parport_probe,
173 .remove = __devexit_p(i2c_parport_remove),
174};
175
176static int __init i2c_parport_device_add(u16 address)
177{
178 struct resource res = {
179 .start = address,
180 .end = address + 2,
181 .name = DRVNAME,
182 .flags = IORESOURCE_IO,
183 };
184 int err;
185
186 pdev = platform_device_alloc(DRVNAME, -1);
187 if (!pdev) {
188 err = -ENOMEM;
189 printk(KERN_ERR DRVNAME ": Device allocation failed\n");
190 goto exit;
191 }
192
193 err = platform_device_add_resources(pdev, &res, 1);
194 if (err) {
195 printk(KERN_ERR DRVNAME ": Device resource addition failed "
196 "(%d)\n", err);
197 goto exit_device_put;
198 }
199
200 err = platform_device_add(pdev);
201 if (err) {
202 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
203 err);
204 goto exit_device_put;
205 }
206
207 return 0;
208
209exit_device_put:
210 platform_device_put(pdev);
211exit:
212 return err;
213}
120 214
121static int __init i2c_parport_init(void) 215static int __init i2c_parport_init(void)
122{ 216{
217 int err;
218
123 if (type < 0) { 219 if (type < 0) {
124 printk(KERN_WARNING "i2c-parport: adapter type unspecified\n"); 220 printk(KERN_ERR DRVNAME ": adapter type unspecified\n");
125 return -ENODEV; 221 return -ENODEV;
126 } 222 }
127 223
128 if (type >= ARRAY_SIZE(adapter_parm)) { 224 if (type >= ARRAY_SIZE(adapter_parm)) {
129 printk(KERN_WARNING "i2c-parport: invalid type (%d)\n", type); 225 printk(KERN_ERR DRVNAME ": invalid type (%d)\n", type);
130 return -ENODEV; 226 return -ENODEV;
131 } 227 }
132 228
133 if (base == 0) { 229 if (base == 0) {
134 printk(KERN_INFO "i2c-parport: using default base 0x%x\n", DEFAULT_BASE); 230 pr_info(DRVNAME ": using default base 0x%x\n", DEFAULT_BASE);
135 base = DEFAULT_BASE; 231 base = DEFAULT_BASE;
136 } 232 }
137 233
138 if (!request_region(base, 3, "i2c-parport"))
139 return -ENODEV;
140
141 if (!adapter_parm[type].getscl.val) 234 if (!adapter_parm[type].getscl.val)
142 parport_algo_data.getscl = NULL; 235 parport_algo_data.getscl = NULL;
143 236
144 /* Reset hardware to a sane state (SCL and SDA high) */ 237 /* Sets global pdev as a side effect */
145 parport_setsda(NULL, 1); 238 err = i2c_parport_device_add(base);
146 parport_setscl(NULL, 1); 239 if (err)
147 /* Other init if needed (power on...) */ 240 goto exit;
148 if (adapter_parm[type].init.val)
149 line_set(1, &adapter_parm[type].init);
150 241
151 if (i2c_bit_add_bus(&parport_adapter) < 0) { 242 err = platform_driver_register(&i2c_parport_driver);
152 printk(KERN_ERR "i2c-parport: Unable to register with I2C\n"); 243 if (err)
153 release_region(base, 3); 244 goto exit_device;
154 return -ENODEV;
155 }
156 245
157 return 0; 246 return 0;
247
248exit_device:
249 platform_device_unregister(pdev);
250exit:
251 return err;
158} 252}
159 253
160static void __exit i2c_parport_exit(void) 254static void __exit i2c_parport_exit(void)
161{ 255{
162 /* Un-init if needed (power off...) */ 256 platform_driver_unregister(&i2c_parport_driver);
163 if (adapter_parm[type].init.val) 257 platform_device_unregister(pdev);
164 line_set(0, &adapter_parm[type].init);
165
166 i2c_del_adapter(&parport_adapter);
167 release_region(base, 3);
168} 258}
169 259
170MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 260MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c
index 66696a40c7b5..8c953707253f 100644
--- a/drivers/i2c/busses/i2c-parport.c
+++ b/drivers/i2c/busses/i2c-parport.c
@@ -1,7 +1,7 @@
1/* ------------------------------------------------------------------------ * 1/* ------------------------------------------------------------------------ *
2 * i2c-parport.c I2C bus over parallel port * 2 * i2c-parport.c I2C bus over parallel port *
3 * ------------------------------------------------------------------------ * 3 * ------------------------------------------------------------------------ *
4 Copyright (C) 2003-2004 Jean Delvare <khali@linux-fr.org> 4 Copyright (C) 2003-2007 Jean Delvare <khali@linux-fr.org>
5 5
6 Based on older i2c-philips-par.c driver 6 Based on older i2c-philips-par.c driver
7 Copyright (C) 1995-2000 Simon G. Vogl 7 Copyright (C) 1995-2000 Simon G. Vogl
@@ -137,19 +137,12 @@ static struct i2c_algo_bit_data parport_algo_data = {
137 .setscl = parport_setscl, 137 .setscl = parport_setscl,
138 .getsda = parport_getsda, 138 .getsda = parport_getsda,
139 .getscl = parport_getscl, 139 .getscl = parport_getscl,
140 .udelay = 60, 140 .udelay = 10, /* ~50 kbps */
141 .timeout = HZ, 141 .timeout = HZ,
142}; 142};
143 143
144/* ----- I2c and parallel port call-back functions and structures --------- */ 144/* ----- I2c and parallel port call-back functions and structures --------- */
145 145
146static struct i2c_adapter parport_adapter = {
147 .owner = THIS_MODULE,
148 .class = I2C_CLASS_HWMON,
149 .id = I2C_HW_B_LP,
150 .name = "Parallel port adapter",
151};
152
153static void i2c_parport_attach (struct parport *port) 146static void i2c_parport_attach (struct parport *port)
154{ 147{
155 struct i2c_par *adapter; 148 struct i2c_par *adapter;
@@ -169,10 +162,17 @@ static void i2c_parport_attach (struct parport *port)
169 } 162 }
170 163
171 /* Fill the rest of the structure */ 164 /* Fill the rest of the structure */
172 adapter->adapter = parport_adapter; 165 adapter->adapter.owner = THIS_MODULE;
166 adapter->adapter.class = I2C_CLASS_HWMON;
167 adapter->adapter.id = I2C_HW_B_LP;
168 strlcpy(adapter->adapter.name, "Parallel port adapter",
169 sizeof(adapter->adapter.name));
173 adapter->algo_data = parport_algo_data; 170 adapter->algo_data = parport_algo_data;
174 if (!adapter_parm[type].getscl.val) 171 /* Slow down if we can't sense SCL */
172 if (!adapter_parm[type].getscl.val) {
175 adapter->algo_data.getscl = NULL; 173 adapter->algo_data.getscl = NULL;
174 adapter->algo_data.udelay = 50; /* ~10 kbps */
175 }
176 adapter->algo_data.data = port; 176 adapter->algo_data.data = port;
177 adapter->adapter.algo_data = &adapter->algo_data; 177 adapter->adapter.algo_data = &adapter->algo_data;
178 178
@@ -214,11 +214,12 @@ static void i2c_parport_detach (struct parport *port)
214 for (prev = NULL, adapter = adapter_list; adapter; 214 for (prev = NULL, adapter = adapter_list; adapter;
215 prev = adapter, adapter = adapter->next) { 215 prev = adapter, adapter = adapter->next) {
216 if (adapter->pdev->port == port) { 216 if (adapter->pdev->port == port) {
217 i2c_del_adapter(&adapter->adapter);
218
217 /* Un-init if needed (power off...) */ 219 /* Un-init if needed (power off...) */
218 if (adapter_parm[type].init.val) 220 if (adapter_parm[type].init.val)
219 line_set(port, 0, &adapter_parm[type].init); 221 line_set(port, 0, &adapter_parm[type].init);
220 222
221 i2c_del_adapter(&adapter->adapter);
222 parport_unregister_device(adapter->pdev); 223 parport_unregister_device(adapter->pdev);
223 if (prev) 224 if (prev)
224 prev->next = adapter->next; 225 prev->next = adapter->next;
diff --git a/drivers/i2c/busses/i2c-pasemi.c b/drivers/i2c/busses/i2c-pasemi.c
index bf89eeef74e9..58e32714afb5 100644
--- a/drivers/i2c/busses/i2c-pasemi.c
+++ b/drivers/i2c/busses/i2c-pasemi.c
@@ -358,7 +358,7 @@ static int __devinit pasemi_smb_probe(struct pci_dev *dev,
358 } 358 }
359 359
360 smbus->adapter.owner = THIS_MODULE; 360 smbus->adapter.owner = THIS_MODULE;
361 snprintf(smbus->adapter.name, I2C_NAME_SIZE, 361 snprintf(smbus->adapter.name, sizeof(smbus->adapter.name),
362 "PA Semi SMBus adapter at 0x%lx", smbus->base); 362 "PA Semi SMBus adapter at 0x%lx", smbus->base);
363 smbus->adapter.class = I2C_CLASS_HWMON; 363 smbus->adapter.class = I2C_CLASS_HWMON;
364 smbus->adapter.algo = &smbus_algorithm; 364 smbus->adapter.algo = &smbus_algorithm;
diff --git a/drivers/i2c/busses/i2c-pca-isa.c b/drivers/i2c/busses/i2c-pca-isa.c
index cc6536a19eca..5161aaf9341b 100644
--- a/drivers/i2c/busses/i2c-pca-isa.c
+++ b/drivers/i2c/busses/i2c-pca-isa.c
@@ -25,9 +25,9 @@
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <linux/init.h> 26#include <linux/init.h>
27#include <linux/interrupt.h> 27#include <linux/interrupt.h>
28#include <linux/pci.h>
29#include <linux/wait.h> 28#include <linux/wait.h>
30 29
30#include <linux/isa.h>
31#include <linux/i2c.h> 31#include <linux/i2c.h>
32#include <linux/i2c-algo-pca.h> 32#include <linux/i2c-algo-pca.h>
33 33
@@ -119,27 +119,26 @@ static struct i2c_adapter pca_isa_ops = {
119 .name = "PCA9564 ISA Adapter", 119 .name = "PCA9564 ISA Adapter",
120}; 120};
121 121
122static int __init pca_isa_init(void) 122static int __devinit pca_isa_probe(struct device *dev, unsigned int id)
123{ 123{
124
125 init_waitqueue_head(&pca_wait); 124 init_waitqueue_head(&pca_wait);
126 125
127 printk(KERN_INFO "i2c-pca-isa: i/o base %#08lx. irq %d\n", base, irq); 126 dev_info(dev, "i/o base %#08lx. irq %d\n", base, irq);
128 127
129 if (!request_region(base, IO_SIZE, "i2c-pca-isa")) { 128 if (!request_region(base, IO_SIZE, "i2c-pca-isa")) {
130 printk(KERN_ERR "i2c-pca-isa: I/O address %#08lx is in use.\n", base); 129 dev_err(dev, "I/O address %#08lx is in use\n", base);
131 goto out; 130 goto out;
132 } 131 }
133 132
134 if (irq > -1) { 133 if (irq > -1) {
135 if (request_irq(irq, pca_handler, 0, "i2c-pca-isa", &pca_isa_ops) < 0) { 134 if (request_irq(irq, pca_handler, 0, "i2c-pca-isa", &pca_isa_ops) < 0) {
136 printk(KERN_ERR "i2c-pca-isa: Request irq%d failed\n", irq); 135 dev_err(dev, "Request irq%d failed\n", irq);
137 goto out_region; 136 goto out_region;
138 } 137 }
139 } 138 }
140 139
141 if (i2c_pca_add_bus(&pca_isa_ops) < 0) { 140 if (i2c_pca_add_bus(&pca_isa_ops) < 0) {
142 printk(KERN_ERR "i2c-pca-isa: Failed to add i2c bus\n"); 141 dev_err(dev, "Failed to add i2c bus\n");
143 goto out_irq; 142 goto out_irq;
144 } 143 }
145 144
@@ -154,7 +153,7 @@ static int __init pca_isa_init(void)
154 return -ENODEV; 153 return -ENODEV;
155} 154}
156 155
157static void pca_isa_exit(void) 156static int __devexit pca_isa_remove(struct device *dev, unsigned int id)
158{ 157{
159 i2c_del_adapter(&pca_isa_ops); 158 i2c_del_adapter(&pca_isa_ops);
160 159
@@ -163,6 +162,27 @@ static void pca_isa_exit(void)
163 free_irq(irq, &pca_isa_ops); 162 free_irq(irq, &pca_isa_ops);
164 } 163 }
165 release_region(base, IO_SIZE); 164 release_region(base, IO_SIZE);
165
166 return 0;
167}
168
169static struct isa_driver pca_isa_driver = {
170 .probe = pca_isa_probe,
171 .remove = __devexit_p(pca_isa_remove),
172 .driver = {
173 .owner = THIS_MODULE,
174 .name = "i2c-pca-isa",
175 }
176};
177
178static int __init pca_isa_init(void)
179{
180 return isa_register_driver(&pca_isa_driver, 1);
181}
182
183static void __exit pca_isa_exit(void)
184{
185 isa_unregister_driver(&pca_isa_driver);
166} 186}
167 187
168MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>"); 188MODULE_AUTHOR("Ian Campbell <icampbell@arcom.com>");
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 21b180904085..5a52bf5e3fb0 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -428,7 +428,7 @@ static int __devinit piix4_probe(struct pci_dev *dev,
428 /* set up the sysfs linkage to our parent device */ 428 /* set up the sysfs linkage to our parent device */
429 piix4_adapter.dev.parent = &dev->dev; 429 piix4_adapter.dev.parent = &dev->dev;
430 430
431 snprintf(piix4_adapter.name, I2C_NAME_SIZE, 431 snprintf(piix4_adapter.name, sizeof(piix4_adapter.name),
432 "SMBus PIIX4 adapter at %04x", piix4_smba); 432 "SMBus PIIX4 adapter at %04x", piix4_smba);
433 433
434 if ((retval = i2c_add_adapter(&piix4_adapter))) { 434 if ((retval = i2c_add_adapter(&piix4_adapter))) {
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index 14e83d0aac8c..873544ab598e 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -539,6 +539,18 @@ static inline void i2c_pxa_start_message(struct pxa_i2c *i2c)
539 writel(icr | ICR_START | ICR_TB, _ICR(i2c)); 539 writel(icr | ICR_START | ICR_TB, _ICR(i2c));
540} 540}
541 541
542static inline void i2c_pxa_stop_message(struct pxa_i2c *i2c)
543{
544 u32 icr;
545
546 /*
547 * Clear the STOP and ACK flags
548 */
549 icr = readl(_ICR(i2c));
550 icr &= ~(ICR_STOP | ICR_ACKNAK);
551 writel(icr, _IRC(i2c));
552}
553
542/* 554/*
543 * We are protected by the adapter bus mutex. 555 * We are protected by the adapter bus mutex.
544 */ 556 */
@@ -581,6 +593,7 @@ static int i2c_pxa_do_xfer(struct pxa_i2c *i2c, struct i2c_msg *msg, int num)
581 * The rest of the processing occurs in the interrupt handler. 593 * The rest of the processing occurs in the interrupt handler.
582 */ 594 */
583 timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5); 595 timeout = wait_event_timeout(i2c->wait, i2c->msg_num == 0, HZ * 5);
596 i2c_pxa_stop_message(i2c);
584 597
585 /* 598 /*
586 * We place the return code in i2c->msg_idx. 599 * We place the return code in i2c->msg_idx.
@@ -825,7 +838,7 @@ static const struct i2c_algorithm i2c_pxa_algorithm = {
825}; 838};
826 839
827static struct pxa_i2c i2c_pxa = { 840static struct pxa_i2c i2c_pxa = {
828 .lock = SPIN_LOCK_UNLOCKED, 841 .lock = __SPIN_LOCK_UNLOCKED(i2c_pxa.lock),
829 .adap = { 842 .adap = {
830 .owner = THIS_MODULE, 843 .owner = THIS_MODULE,
831 .algo = &i2c_pxa_algorithm, 844 .algo = &i2c_pxa_algorithm,
@@ -839,9 +852,7 @@ static int i2c_pxa_probe(struct platform_device *dev)
839{ 852{
840 struct pxa_i2c *i2c = &i2c_pxa; 853 struct pxa_i2c *i2c = &i2c_pxa;
841 struct resource *res; 854 struct resource *res;
842#ifdef CONFIG_I2C_PXA_SLAVE
843 struct i2c_pxa_platform_data *plat = dev->dev.platform_data; 855 struct i2c_pxa_platform_data *plat = dev->dev.platform_data;
844#endif
845 int ret; 856 int ret;
846 int irq; 857 int irq;
847 858
@@ -889,14 +900,14 @@ static int i2c_pxa_probe(struct platform_device *dev)
889 pxa_gpio_mode(GPIO117_I2CSCL_MD); 900 pxa_gpio_mode(GPIO117_I2CSCL_MD);
890 pxa_gpio_mode(GPIO118_I2CSDA_MD); 901 pxa_gpio_mode(GPIO118_I2CSDA_MD);
891#endif 902#endif
892 pxa_set_cken(CKEN14_I2C, 1); 903 pxa_set_cken(CKEN_I2C, 1);
893 break; 904 break;
894#ifdef CONFIG_PXA27x 905#ifdef CONFIG_PXA27x
895 case 1: 906 case 1:
896 local_irq_disable(); 907 local_irq_disable();
897 PCFR |= PCFR_PI2CEN; 908 PCFR |= PCFR_PI2CEN;
898 local_irq_enable(); 909 local_irq_enable();
899 pxa_set_cken(CKEN15_PWRI2C, 1); 910 pxa_set_cken(CKEN_PWRI2C, 1);
900#endif 911#endif
901 } 912 }
902 913
@@ -911,6 +922,10 @@ static int i2c_pxa_probe(struct platform_device *dev)
911 i2c->adap.algo_data = i2c; 922 i2c->adap.algo_data = i2c;
912 i2c->adap.dev.parent = &dev->dev; 923 i2c->adap.dev.parent = &dev->dev;
913 924
925 if (plat) {
926 i2c->adap.class = plat->class;
927 }
928
914 ret = i2c_add_adapter(&i2c->adap); 929 ret = i2c_add_adapter(&i2c->adap);
915 if (ret < 0) { 930 if (ret < 0) {
916 printk(KERN_INFO "I2C: Failed to add bus\n"); 931 printk(KERN_INFO "I2C: Failed to add bus\n");
@@ -933,11 +948,11 @@ eadapt:
933ereqirq: 948ereqirq:
934 switch (dev->id) { 949 switch (dev->id) {
935 case 0: 950 case 0:
936 pxa_set_cken(CKEN14_I2C, 0); 951 pxa_set_cken(CKEN_I2C, 0);
937 break; 952 break;
938#ifdef CONFIG_PXA27x 953#ifdef CONFIG_PXA27x
939 case 1: 954 case 1:
940 pxa_set_cken(CKEN15_PWRI2C, 0); 955 pxa_set_cken(CKEN_PWRI2C, 0);
941 local_irq_disable(); 956 local_irq_disable();
942 PCFR &= ~PCFR_PI2CEN; 957 PCFR &= ~PCFR_PI2CEN;
943 local_irq_enable(); 958 local_irq_enable();
@@ -960,11 +975,11 @@ static int i2c_pxa_remove(struct platform_device *dev)
960 free_irq(i2c->irq, i2c); 975 free_irq(i2c->irq, i2c);
961 switch (dev->id) { 976 switch (dev->id) {
962 case 0: 977 case 0:
963 pxa_set_cken(CKEN14_I2C, 0); 978 pxa_set_cken(CKEN_I2C, 0);
964 break; 979 break;
965#ifdef CONFIG_PXA27x 980#ifdef CONFIG_PXA27x
966 case 1: 981 case 1:
967 pxa_set_cken(CKEN15_PWRI2C, 0); 982 pxa_set_cken(CKEN_PWRI2C, 0);
968 local_irq_disable(); 983 local_irq_disable();
969 PCFR &= ~PCFR_PI2CEN; 984 PCFR &= ~PCFR_PI2CEN;
970 local_irq_enable(); 985 local_irq_enable();
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 556f244aae76..e68a96f589fd 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -61,6 +61,8 @@ struct s3c24xx_i2c {
61 unsigned int msg_idx; 61 unsigned int msg_idx;
62 unsigned int msg_ptr; 62 unsigned int msg_ptr;
63 63
64 unsigned int tx_setup;
65
64 enum s3c24xx_i2c_state state; 66 enum s3c24xx_i2c_state state;
65 67
66 void __iomem *regs; 68 void __iomem *regs;
@@ -199,8 +201,11 @@ static void s3c24xx_i2c_message_start(struct s3c24xx_i2c *i2c,
199 dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr); 201 dev_dbg(i2c->dev, "START: %08lx to IICSTAT, %02x to DS\n", stat, addr);
200 writeb(addr, i2c->regs + S3C2410_IICDS); 202 writeb(addr, i2c->regs + S3C2410_IICDS);
201 203
202 // delay a bit and reset iiccon before setting start (per samsung) 204 /* delay here to ensure the data byte has gotten onto the bus
203 udelay(1); 205 * before the transaction is started */
206
207 ndelay(i2c->tx_setup);
208
204 dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon); 209 dev_dbg(i2c->dev, "iiccon, %08lx\n", iiccon);
205 writel(iiccon, i2c->regs + S3C2410_IICCON); 210 writel(iiccon, i2c->regs + S3C2410_IICCON);
206 211
@@ -322,7 +327,15 @@ static int i2s_s3c_irq_nextbyte(struct s3c24xx_i2c *i2c, unsigned long iicstat)
322 if (!is_msgend(i2c)) { 327 if (!is_msgend(i2c)) {
323 byte = i2c->msg->buf[i2c->msg_ptr++]; 328 byte = i2c->msg->buf[i2c->msg_ptr++];
324 writeb(byte, i2c->regs + S3C2410_IICDS); 329 writeb(byte, i2c->regs + S3C2410_IICDS);
325 330
331 /* delay after writing the byte to allow the
332 * data setup time on the bus, as writing the
333 * data to the register causes the first bit
334 * to appear on SDA, and SCL will change as
335 * soon as the interrupt is acknowledged */
336
337 ndelay(i2c->tx_setup);
338
326 } else if (!is_lastmsg(i2c)) { 339 } else if (!is_lastmsg(i2c)) {
327 /* we need to go to the next i2c message */ 340 /* we need to go to the next i2c message */
328 341
@@ -570,9 +583,10 @@ static const struct i2c_algorithm s3c24xx_i2c_algorithm = {
570}; 583};
571 584
572static struct s3c24xx_i2c s3c24xx_i2c = { 585static struct s3c24xx_i2c s3c24xx_i2c = {
573 .lock = SPIN_LOCK_UNLOCKED, 586 .lock = __SPIN_LOCK_UNLOCKED(s3c24xx_i2c.lock),
574 .wait = __WAIT_QUEUE_HEAD_INITIALIZER(s3c24xx_i2c.wait), 587 .wait = __WAIT_QUEUE_HEAD_INITIALIZER(s3c24xx_i2c.wait),
575 .adap = { 588 .tx_setup = 50,
589 .adap = {
576 .name = "s3c2410-i2c", 590 .name = "s3c2410-i2c",
577 .owner = THIS_MODULE, 591 .owner = THIS_MODULE,
578 .algo = &s3c24xx_i2c_algorithm, 592 .algo = &s3c24xx_i2c_algorithm,
@@ -731,26 +745,6 @@ static int s3c24xx_i2c_init(struct s3c24xx_i2c *i2c)
731 return 0; 745 return 0;
732} 746}
733 747
734static void s3c24xx_i2c_free(struct s3c24xx_i2c *i2c)
735{
736 if (i2c->clk != NULL && !IS_ERR(i2c->clk)) {
737 clk_disable(i2c->clk);
738 clk_put(i2c->clk);
739 i2c->clk = NULL;
740 }
741
742 if (i2c->regs != NULL) {
743 iounmap(i2c->regs);
744 i2c->regs = NULL;
745 }
746
747 if (i2c->ioarea != NULL) {
748 release_resource(i2c->ioarea);
749 kfree(i2c->ioarea);
750 i2c->ioarea = NULL;
751 }
752}
753
754/* s3c24xx_i2c_probe 748/* s3c24xx_i2c_probe
755 * 749 *
756 * called by the bus driver when a suitable device is found 750 * called by the bus driver when a suitable device is found
@@ -769,7 +763,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
769 if (IS_ERR(i2c->clk)) { 763 if (IS_ERR(i2c->clk)) {
770 dev_err(&pdev->dev, "cannot get clock\n"); 764 dev_err(&pdev->dev, "cannot get clock\n");
771 ret = -ENOENT; 765 ret = -ENOENT;
772 goto out; 766 goto err_noclk;
773 } 767 }
774 768
775 dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk); 769 dev_dbg(&pdev->dev, "clock source %p\n", i2c->clk);
@@ -782,7 +776,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
782 if (res == NULL) { 776 if (res == NULL) {
783 dev_err(&pdev->dev, "cannot find IO resource\n"); 777 dev_err(&pdev->dev, "cannot find IO resource\n");
784 ret = -ENOENT; 778 ret = -ENOENT;
785 goto out; 779 goto err_clk;
786 } 780 }
787 781
788 i2c->ioarea = request_mem_region(res->start, (res->end-res->start)+1, 782 i2c->ioarea = request_mem_region(res->start, (res->end-res->start)+1,
@@ -791,7 +785,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
791 if (i2c->ioarea == NULL) { 785 if (i2c->ioarea == NULL) {
792 dev_err(&pdev->dev, "cannot request IO\n"); 786 dev_err(&pdev->dev, "cannot request IO\n");
793 ret = -ENXIO; 787 ret = -ENXIO;
794 goto out; 788 goto err_clk;
795 } 789 }
796 790
797 i2c->regs = ioremap(res->start, (res->end-res->start)+1); 791 i2c->regs = ioremap(res->start, (res->end-res->start)+1);
@@ -799,7 +793,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
799 if (i2c->regs == NULL) { 793 if (i2c->regs == NULL) {
800 dev_err(&pdev->dev, "cannot map IO\n"); 794 dev_err(&pdev->dev, "cannot map IO\n");
801 ret = -ENXIO; 795 ret = -ENXIO;
802 goto out; 796 goto err_ioarea;
803 } 797 }
804 798
805 dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", i2c->regs, i2c->ioarea, res); 799 dev_dbg(&pdev->dev, "registers %p (%p, %p)\n", i2c->regs, i2c->ioarea, res);
@@ -813,7 +807,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
813 807
814 ret = s3c24xx_i2c_init(i2c); 808 ret = s3c24xx_i2c_init(i2c);
815 if (ret != 0) 809 if (ret != 0)
816 goto out; 810 goto err_iomap;
817 811
818 /* find the IRQ for this unit (note, this relies on the init call to 812 /* find the IRQ for this unit (note, this relies on the init call to
819 * ensure no current IRQs pending 813 * ensure no current IRQs pending
@@ -823,7 +817,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
823 if (res == NULL) { 817 if (res == NULL) {
824 dev_err(&pdev->dev, "cannot find IRQ\n"); 818 dev_err(&pdev->dev, "cannot find IRQ\n");
825 ret = -ENOENT; 819 ret = -ENOENT;
826 goto out; 820 goto err_iomap;
827 } 821 }
828 822
829 ret = request_irq(res->start, s3c24xx_i2c_irq, IRQF_DISABLED, 823 ret = request_irq(res->start, s3c24xx_i2c_irq, IRQF_DISABLED,
@@ -831,7 +825,7 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
831 825
832 if (ret != 0) { 826 if (ret != 0) {
833 dev_err(&pdev->dev, "cannot claim IRQ\n"); 827 dev_err(&pdev->dev, "cannot claim IRQ\n");
834 goto out; 828 goto err_iomap;
835 } 829 }
836 830
837 i2c->irq = res; 831 i2c->irq = res;
@@ -841,17 +835,29 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
841 ret = i2c_add_adapter(&i2c->adap); 835 ret = i2c_add_adapter(&i2c->adap);
842 if (ret < 0) { 836 if (ret < 0) {
843 dev_err(&pdev->dev, "failed to add bus to i2c core\n"); 837 dev_err(&pdev->dev, "failed to add bus to i2c core\n");
844 goto out; 838 goto err_irq;
845 } 839 }
846 840
847 platform_set_drvdata(pdev, i2c); 841 platform_set_drvdata(pdev, i2c);
848 842
849 dev_info(&pdev->dev, "%s: S3C I2C adapter\n", i2c->adap.dev.bus_id); 843 dev_info(&pdev->dev, "%s: S3C I2C adapter\n", i2c->adap.dev.bus_id);
844 return 0;
850 845
851 out: 846 err_irq:
852 if (ret < 0) 847 free_irq(i2c->irq->start, i2c);
853 s3c24xx_i2c_free(i2c); 848
849 err_iomap:
850 iounmap(i2c->regs);
854 851
852 err_ioarea:
853 release_resource(i2c->ioarea);
854 kfree(i2c->ioarea);
855
856 err_clk:
857 clk_disable(i2c->clk);
858 clk_put(i2c->clk);
859
860 err_noclk:
855 return ret; 861 return ret;
856} 862}
857 863
@@ -863,11 +869,17 @@ static int s3c24xx_i2c_probe(struct platform_device *pdev)
863static int s3c24xx_i2c_remove(struct platform_device *pdev) 869static int s3c24xx_i2c_remove(struct platform_device *pdev)
864{ 870{
865 struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev); 871 struct s3c24xx_i2c *i2c = platform_get_drvdata(pdev);
866 872
867 if (i2c != NULL) { 873 i2c_del_adapter(&i2c->adap);
868 s3c24xx_i2c_free(i2c); 874 free_irq(i2c->irq->start, i2c);
869 platform_set_drvdata(pdev, NULL); 875
870 } 876 clk_disable(i2c->clk);
877 clk_put(i2c->clk);
878
879 iounmap(i2c->regs);
880
881 release_resource(i2c->ioarea);
882 kfree(i2c->ioarea);
871 883
872 return 0; 884 return 0;
873} 885}
diff --git a/drivers/i2c/busses/i2c-simtec.c b/drivers/i2c/busses/i2c-simtec.c
new file mode 100644
index 000000000000..10af8d31e12a
--- /dev/null
+++ b/drivers/i2c/busses/i2c-simtec.c
@@ -0,0 +1,186 @@
1/*
2 * Copyright (C) 2005 Simtec Electronics
3 * Ben Dooks <ben@simtec.co.uk>
4 *
5 * Simtec Generic I2C Controller
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
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19*/
20
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/delay.h>
25#include <linux/platform_device.h>
26
27#include <linux/i2c.h>
28#include <linux/i2c-algo-bit.h>
29
30#include <asm/io.h>
31
32struct simtec_i2c_data {
33 struct resource *ioarea;
34 void __iomem *reg;
35 struct i2c_adapter adap;
36 struct i2c_algo_bit_data bit;
37};
38
39#define CMD_SET_SDA (1<<2)
40#define CMD_SET_SCL (1<<3)
41
42#define STATE_SDA (1<<0)
43#define STATE_SCL (1<<1)
44
45/* i2c bit-bus functions */
46
47static void simtec_i2c_setsda(void *pw, int state)
48{
49 struct simtec_i2c_data *pd = pw;
50 writeb(CMD_SET_SDA | (state ? STATE_SDA : 0), pd->reg);
51}
52
53static void simtec_i2c_setscl(void *pw, int state)
54{
55 struct simtec_i2c_data *pd = pw;
56 writeb(CMD_SET_SCL | (state ? STATE_SCL : 0), pd->reg);
57}
58
59static int simtec_i2c_getsda(void *pw)
60{
61 struct simtec_i2c_data *pd = pw;
62 return readb(pd->reg) & STATE_SDA ? 1 : 0;
63}
64
65static int simtec_i2c_getscl(void *pw)
66{
67 struct simtec_i2c_data *pd = pw;
68 return readb(pd->reg) & STATE_SCL ? 1 : 0;
69}
70
71/* device registration */
72
73static int simtec_i2c_probe(struct platform_device *dev)
74{
75 struct simtec_i2c_data *pd;
76 struct resource *res;
77 int size;
78 int ret;
79
80 pd = kzalloc(sizeof(struct simtec_i2c_data), GFP_KERNEL);
81 if (pd == NULL) {
82 dev_err(&dev->dev, "cannot allocate private data\n");
83 return -ENOMEM;
84 }
85
86 platform_set_drvdata(dev, pd);
87
88 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
89 if (res == NULL) {
90 dev_err(&dev->dev, "cannot find IO resource\n");
91 ret = -ENOENT;
92 goto err;
93 }
94
95 size = (res->end-res->start)+1;
96
97 pd->ioarea = request_mem_region(res->start, size, dev->name);
98 if (pd->ioarea == NULL) {
99 dev_err(&dev->dev, "cannot request IO\n");
100 ret = -ENXIO;
101 goto err;
102 }
103
104 pd->reg = ioremap(res->start, size);
105 if (pd->reg == NULL) {
106 dev_err(&dev->dev, "cannot map IO\n");
107 ret = -ENXIO;
108 goto err_res;
109 }
110
111 /* setup the private data */
112
113 pd->adap.owner = THIS_MODULE;
114 pd->adap.algo_data = &pd->bit;
115 pd->adap.dev.parent = &dev->dev;
116
117 strlcpy(pd->adap.name, "Simtec I2C", sizeof(pd->adap.name));
118
119 pd->bit.data = pd;
120 pd->bit.setsda = simtec_i2c_setsda;
121 pd->bit.setscl = simtec_i2c_setscl;
122 pd->bit.getsda = simtec_i2c_getsda;
123 pd->bit.getscl = simtec_i2c_getscl;
124 pd->bit.timeout = HZ;
125 pd->bit.udelay = 20;
126
127 ret = i2c_bit_add_bus(&pd->adap);
128 if (ret)
129 goto err_all;
130
131 return 0;
132
133 err_all:
134 iounmap(pd->reg);
135
136 err_res:
137 release_resource(pd->ioarea);
138 kfree(pd->ioarea);
139
140 err:
141 kfree(pd);
142 return ret;
143}
144
145static int simtec_i2c_remove(struct platform_device *dev)
146{
147 struct simtec_i2c_data *pd = platform_get_drvdata(dev);
148
149 i2c_del_adapter(&pd->adap);
150
151 iounmap(pd->reg);
152 release_resource(pd->ioarea);
153 kfree(pd->ioarea);
154 kfree(pd);
155
156 return 0;
157}
158
159
160/* device driver */
161
162static struct platform_driver simtec_i2c_driver = {
163 .driver = {
164 .name = "simtec-i2c",
165 .owner = THIS_MODULE,
166 },
167 .probe = simtec_i2c_probe,
168 .remove = simtec_i2c_remove,
169};
170
171static int __init i2c_adap_simtec_init(void)
172{
173 return platform_driver_register(&simtec_i2c_driver);
174}
175
176static void __exit i2c_adap_simtec_exit(void)
177{
178 platform_driver_unregister(&simtec_i2c_driver);
179}
180
181module_init(i2c_adap_simtec_init);
182module_exit(i2c_adap_simtec_exit);
183
184MODULE_DESCRIPTION("Simtec Generic I2C Bus driver");
185MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
186MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index 4157b0cd604c..dc235bb8e24d 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -300,7 +300,7 @@ static int __devinit sis96x_probe(struct pci_dev *dev,
300 /* set up the sysfs linkage to our parent device */ 300 /* set up the sysfs linkage to our parent device */
301 sis96x_adapter.dev.parent = &dev->dev; 301 sis96x_adapter.dev.parent = &dev->dev;
302 302
303 snprintf(sis96x_adapter.name, I2C_NAME_SIZE, 303 snprintf(sis96x_adapter.name, sizeof(sis96x_adapter.name),
304 "SiS96x SMBus adapter at 0x%04x", sis96x_smbus_base); 304 "SiS96x SMBus adapter at 0x%04x", sis96x_smbus_base);
305 305
306 if ((retval = i2c_add_adapter(&sis96x_adapter))) { 306 if ((retval = i2c_add_adapter(&sis96x_adapter))) {
diff --git a/drivers/i2c/busses/i2c-tiny-usb.c b/drivers/i2c/busses/i2c-tiny-usb.c
new file mode 100644
index 000000000000..907999049d50
--- /dev/null
+++ b/drivers/i2c/busses/i2c-tiny-usb.c
@@ -0,0 +1,277 @@
1/*
2 * driver for the i2c-tiny-usb adapter - 1.0
3 * http://www.harbaum.org/till/i2c_tiny_usb
4 *
5 * Copyright (C) 2006-2007 Till Harbaum (Till@Harbaum.org)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation, version 2.
10 *
11 */
12
13#include <linux/kernel.h>
14#include <linux/errno.h>
15#include <linux/module.h>
16
17/* include interfaces to usb layer */
18#include <linux/usb.h>
19
20/* include interface to i2c layer */
21#include <linux/i2c.h>
22
23/* commands via USB, must match command ids in the firmware */
24#define CMD_ECHO 0
25#define CMD_GET_FUNC 1
26#define CMD_SET_DELAY 2
27#define CMD_GET_STATUS 3
28
29#define CMD_I2C_IO 4
30#define CMD_I2C_IO_BEGIN (1<<0)
31#define CMD_I2C_IO_END (1<<1)
32
33/* i2c bit delay, default is 10us -> 100kHz */
34static int delay = 10;
35module_param(delay, int, 0);
36MODULE_PARM_DESC(delay, "bit delay in microseconds, "
37 "e.g. 10 for 100kHz (default is 100kHz)");
38
39static int usb_read(struct i2c_adapter *adapter, int cmd,
40 int value, int index, void *data, int len);
41
42static int usb_write(struct i2c_adapter *adapter, int cmd,
43 int value, int index, void *data, int len);
44
45/* ----- begin of i2c layer ---------------------------------------------- */
46
47#define STATUS_IDLE 0
48#define STATUS_ADDRESS_ACK 1
49#define STATUS_ADDRESS_NAK 2
50
51static int usb_xfer(struct i2c_adapter *adapter, struct i2c_msg *msgs, int num)
52{
53 unsigned char status;
54 struct i2c_msg *pmsg;
55 int i;
56
57 dev_dbg(&adapter->dev, "master xfer %d messages:\n", num);
58
59 for (i = 0 ; i < num ; i++) {
60 int cmd = CMD_I2C_IO;
61
62 if (i == 0)
63 cmd |= CMD_I2C_IO_BEGIN;
64
65 if (i == num-1)
66 cmd |= CMD_I2C_IO_END;
67
68 pmsg = &msgs[i];
69
70 dev_dbg(&adapter->dev,
71 " %d: %s (flags %d) %d bytes to 0x%02x\n",
72 i, pmsg->flags & I2C_M_RD ? "read" : "write",
73 pmsg->flags, pmsg->len, pmsg->addr);
74
75 /* and directly send the message */
76 if (pmsg->flags & I2C_M_RD) {
77 /* read data */
78 if (usb_read(adapter, cmd,
79 pmsg->flags, pmsg->addr,
80 pmsg->buf, pmsg->len) != pmsg->len) {
81 dev_err(&adapter->dev,
82 "failure reading data\n");
83 return -EREMOTEIO;
84 }
85 } else {
86 /* write data */
87 if (usb_write(adapter, cmd,
88 pmsg->flags, pmsg->addr,
89 pmsg->buf, pmsg->len) != pmsg->len) {
90 dev_err(&adapter->dev,
91 "failure writing data\n");
92 return -EREMOTEIO;
93 }
94 }
95
96 /* read status */
97 if (usb_read(adapter, CMD_GET_STATUS, 0, 0, &status, 1) != 1) {
98 dev_err(&adapter->dev, "failure reading status\n");
99 return -EREMOTEIO;
100 }
101
102 dev_dbg(&adapter->dev, " status = %d\n", status);
103 if (status == STATUS_ADDRESS_NAK)
104 return -EREMOTEIO;
105 }
106
107 return i;
108}
109
110static u32 usb_func(struct i2c_adapter *adapter)
111{
112 u32 func;
113
114 /* get functionality from adapter */
115 if (usb_read(adapter, CMD_GET_FUNC, 0, 0, &func, sizeof(func)) !=
116 sizeof(func)) {
117 dev_err(&adapter->dev, "failure reading functionality\n");
118 return 0;
119 }
120
121 return func;
122}
123
124/* This is the actual algorithm we define */
125static const struct i2c_algorithm usb_algorithm = {
126 .master_xfer = usb_xfer,
127 .functionality = usb_func,
128};
129
130/* ----- end of i2c layer ------------------------------------------------ */
131
132/* ----- begin of usb layer ---------------------------------------------- */
133
134/* The usb i2c interface uses a vid/pid pair donated by */
135/* Future Technology Devices International Ltd. */
136static struct usb_device_id i2c_tiny_usb_table [] = {
137 { USB_DEVICE(0x0403, 0xc631) },
138 { } /* Terminating entry */
139};
140
141MODULE_DEVICE_TABLE(usb, i2c_tiny_usb_table);
142
143/* Structure to hold all of our device specific stuff */
144struct i2c_tiny_usb {
145 struct usb_device *usb_dev; /* the usb device for this device */
146 struct usb_interface *interface; /* the interface for this device */
147 struct i2c_adapter adapter; /* i2c related things */
148};
149
150static int usb_read(struct i2c_adapter *adapter, int cmd,
151 int value, int index, void *data, int len)
152{
153 struct i2c_tiny_usb *dev = (struct i2c_tiny_usb *)adapter->algo_data;
154
155 /* do control transfer */
156 return usb_control_msg(dev->usb_dev, usb_rcvctrlpipe(dev->usb_dev, 0),
157 cmd, USB_TYPE_VENDOR | USB_RECIP_INTERFACE |
158 USB_DIR_IN, value, index, data, len, 2000);
159}
160
161static int usb_write(struct i2c_adapter *adapter, int cmd,
162 int value, int index, void *data, int len)
163{
164 struct i2c_tiny_usb *dev = (struct i2c_tiny_usb *)adapter->algo_data;
165
166 /* do control transfer */
167 return usb_control_msg(dev->usb_dev, usb_sndctrlpipe(dev->usb_dev, 0),
168 cmd, USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
169 value, index, data, len, 2000);
170}
171
172static void i2c_tiny_usb_free(struct i2c_tiny_usb *dev)
173{
174 usb_put_dev(dev->usb_dev);
175 kfree(dev);
176}
177
178static int i2c_tiny_usb_probe(struct usb_interface *interface,
179 const struct usb_device_id *id)
180{
181 struct i2c_tiny_usb *dev;
182 int retval = -ENOMEM;
183 u16 version;
184
185 dev_dbg(&interface->dev, "probing usb device\n");
186
187 /* allocate memory for our device state and initialize it */
188 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
189 if (dev == NULL) {
190 dev_err(&interface->dev, "Out of memory\n");
191 goto error;
192 }
193
194 dev->usb_dev = usb_get_dev(interface_to_usbdev(interface));
195 dev->interface = interface;
196
197 /* save our data pointer in this interface device */
198 usb_set_intfdata(interface, dev);
199
200 version = le16_to_cpu(dev->usb_dev->descriptor.bcdDevice);
201 dev_info(&interface->dev,
202 "version %x.%02x found at bus %03d address %03d\n",
203 version >> 8, version & 0xff,
204 dev->usb_dev->bus->busnum, dev->usb_dev->devnum);
205
206 /* setup i2c adapter description */
207 dev->adapter.owner = THIS_MODULE;
208 dev->adapter.class = I2C_CLASS_HWMON;
209 dev->adapter.algo = &usb_algorithm;
210 dev->adapter.algo_data = dev;
211 snprintf(dev->adapter.name, I2C_NAME_SIZE,
212 "i2c-tiny-usb at bus %03d device %03d",
213 dev->usb_dev->bus->busnum, dev->usb_dev->devnum);
214
215 if (usb_write(&dev->adapter, CMD_SET_DELAY,
216 cpu_to_le16(delay), 0, NULL, 0) != 0) {
217 dev_err(&dev->adapter.dev,
218 "failure setting delay to %dus\n", delay);
219 retval = -EIO;
220 goto error;
221 }
222
223 dev->adapter.dev.parent = &dev->interface->dev;
224
225 /* and finally attach to i2c layer */
226 i2c_add_adapter(&dev->adapter);
227
228 /* inform user about successful attachment to i2c layer */
229 dev_info(&dev->adapter.dev, "connected i2c-tiny-usb device\n");
230
231 return 0;
232
233 error:
234 if (dev)
235 i2c_tiny_usb_free(dev);
236
237 return retval;
238}
239
240static void i2c_tiny_usb_disconnect(struct usb_interface *interface)
241{
242 struct i2c_tiny_usb *dev = usb_get_intfdata(interface);
243
244 i2c_del_adapter(&dev->adapter);
245 usb_set_intfdata(interface, NULL);
246 i2c_tiny_usb_free(dev);
247
248 dev_dbg(&interface->dev, "disconnected\n");
249}
250
251static struct usb_driver i2c_tiny_usb_driver = {
252 .name = "i2c-tiny-usb",
253 .probe = i2c_tiny_usb_probe,
254 .disconnect = i2c_tiny_usb_disconnect,
255 .id_table = i2c_tiny_usb_table,
256};
257
258static int __init usb_i2c_tiny_usb_init(void)
259{
260 /* register this driver with the USB subsystem */
261 return usb_register(&i2c_tiny_usb_driver);
262}
263
264static void __exit usb_i2c_tiny_usb_exit(void)
265{
266 /* deregister this driver with the USB subsystem */
267 usb_deregister(&i2c_tiny_usb_driver);
268}
269
270module_init(usb_i2c_tiny_usb_init);
271module_exit(usb_i2c_tiny_usb_exit);
272
273/* ----- end of usb layer ------------------------------------------------ */
274
275MODULE_AUTHOR("Till Harbaum <Till@Harbaum.org>");
276MODULE_DESCRIPTION("i2c-tiny-usb driver v1.0");
277MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 03c5fc868548..7a2bc06304fc 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -404,7 +404,7 @@ found:
404 } 404 }
405 405
406 vt596_adapter.dev.parent = &pdev->dev; 406 vt596_adapter.dev.parent = &pdev->dev;
407 snprintf(vt596_adapter.name, I2C_NAME_SIZE, 407 snprintf(vt596_adapter.name, sizeof(vt596_adapter.name),
408 "SMBus Via Pro adapter at %04x", vt596_smba); 408 "SMBus Via Pro adapter at %04x", vt596_smba);
409 409
410 vt596_pdev = pci_dev_get(pdev); 410 vt596_pdev = pci_dev_get(pdev);
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index 0b082c5a0195..0db56e7bc34e 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -441,7 +441,7 @@ static __init struct scx200_acb_iface *scx200_create_iface(const char *text,
441 441
442 adapter = &iface->adapter; 442 adapter = &iface->adapter;
443 i2c_set_adapdata(adapter, iface); 443 i2c_set_adapdata(adapter, iface);
444 snprintf(adapter->name, I2C_NAME_SIZE, "%s ACB%d", text, index); 444 snprintf(adapter->name, sizeof(adapter->name), "%s ACB%d", text, index);
445 adapter->owner = THIS_MODULE; 445 adapter->owner = THIS_MODULE;
446 adapter->id = I2C_HW_SMBUS_SCX200; 446 adapter->id = I2C_HW_SMBUS_SCX200;
447 adapter->algo = &scx200_acb_algorithm; 447 adapter->algo = &scx200_acb_algorithm;
@@ -599,6 +599,7 @@ static __init int scx200_scan_pci(void)
599 else { 599 else {
600 int i; 600 int i;
601 601
602 pci_dev_put(pdev);
602 for (i = 0; i < MAX_DEVICES; ++i) { 603 for (i = 0; i < MAX_DEVICES; ++i) {
603 if (base[i] == 0) 604 if (base[i] == 0)
604 continue; 605 continue;