aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c/busses')
-rw-r--r--drivers/i2c/busses/Kconfig34
-rw-r--r--drivers/i2c/busses/Makefile1
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c2
-rw-r--r--drivers/i2c/busses/i2c-ali1563.c2
-rw-r--r--drivers/i2c/busses/i2c-ali15x3.c2
-rw-r--r--drivers/i2c/busses/i2c-amd756.c2
-rw-r--r--drivers/i2c/busses/i2c-amd8111.c2
-rw-r--r--drivers/i2c/busses/i2c-au1550.c21
-rw-r--r--drivers/i2c/busses/i2c-elektor.c1
-rw-r--r--drivers/i2c/busses/i2c-hydra.c1
-rw-r--r--drivers/i2c/busses/i2c-i801.c2
-rw-r--r--drivers/i2c/busses/i2c-i810.c2
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c2
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c2
-rw-r--r--drivers/i2c/busses/i2c-isa.c42
-rw-r--r--drivers/i2c/busses/i2c-ixp2000.c1
-rw-r--r--drivers/i2c/busses/i2c-ixp4xx.c1
-rw-r--r--drivers/i2c/busses/i2c-mpc.c2
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c2
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c2
-rw-r--r--drivers/i2c/busses/i2c-ocores.c2
-rw-r--r--drivers/i2c/busses/i2c-omap.c676
-rw-r--r--drivers/i2c/busses/i2c-parport-light.c1
-rw-r--r--drivers/i2c/busses/i2c-parport.c1
-rw-r--r--drivers/i2c/busses/i2c-piix4.c2
-rw-r--r--drivers/i2c/busses/i2c-powermac.c2
-rw-r--r--drivers/i2c/busses/i2c-prosavage.c1
-rw-r--r--drivers/i2c/busses/i2c-pxa.c2
-rw-r--r--drivers/i2c/busses/i2c-s3c2410.c2
-rw-r--r--drivers/i2c/busses/i2c-savage4.c1
-rw-r--r--drivers/i2c/busses/i2c-sibyte.c160
-rw-r--r--drivers/i2c/busses/i2c-sis5595.c2
-rw-r--r--drivers/i2c/busses/i2c-sis630.c2
-rw-r--r--drivers/i2c/busses/i2c-sis96x.c2
-rw-r--r--drivers/i2c/busses/i2c-stub.c21
-rw-r--r--drivers/i2c/busses/i2c-via.c1
-rw-r--r--drivers/i2c/busses/i2c-viapro.c10
-rw-r--r--drivers/i2c/busses/i2c-voodoo3.c2
-rw-r--r--drivers/i2c/busses/scx200_acb.c2
-rw-r--r--drivers/i2c/busses/scx200_i2c.c12
40 files changed, 957 insertions, 73 deletions
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 884320e70403..9e56c3989d68 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -75,11 +75,11 @@ config I2C_AMD8111
75 will be called i2c-amd8111. 75 will be called i2c-amd8111.
76 76
77config I2C_AU1550 77config I2C_AU1550
78 tristate "Au1550 SMBus interface" 78 tristate "Au1550/Au1200 SMBus interface"
79 depends on I2C && SOC_AU1550 79 depends on I2C && (SOC_AU1550 || SOC_AU1200)
80 help 80 help
81 If you say yes to this option, support will be included for the 81 If you say yes to this option, support will be included for the
82 Au1550 SMBus interface. 82 Au1550 and Au1200 SMBus interface.
83 83
84 This driver can also be built as a module. If so, the module 84 This driver can also be built as a module. If so, the module
85 will be called i2c-au1550. 85 will be called i2c-au1550.
@@ -287,6 +287,16 @@ config I2C_OCORES
287 This driver can also be built as a module. If so, the module 287 This driver can also be built as a module. If so, the module
288 will be called i2c-ocores. 288 will be called i2c-ocores.
289 289
290config I2C_OMAP
291 tristate "OMAP I2C adapter"
292 depends on I2C && ARCH_OMAP
293 default y if MACH_OMAP_H3 || MACH_OMAP_OSK
294 help
295 If you say yes to this option, support will be included for the
296 I2C interface on the Texas Instruments OMAP1/2 family of processors.
297 Like OMAP1510/1610/1710/5912 and OMAP242x.
298 For details see http://www.ti.com/omap.
299
290config I2C_PARPORT 300config I2C_PARPORT
291 tristate "Parallel port adapter" 301 tristate "Parallel port adapter"
292 depends on I2C && PARPORT 302 depends on I2C && PARPORT
@@ -482,19 +492,19 @@ config I2C_VIA
482 will be called i2c-via. 492 will be called i2c-via.
483 493
484config I2C_VIAPRO 494config I2C_VIAPRO
485 tristate "VIA 82C596/82C686/823x" 495 tristate "VIA 82C596/82C686/82xx"
486 depends on I2C && PCI 496 depends on I2C && PCI
487 help 497 help
488 If you say yes to this option, support will be included for the VIA 498 If you say yes to this option, support will be included for the VIA
489 82C596/82C686/823x I2C interfaces. Specifically, the following 499 82C596/82C686/82xx I2C interfaces. Specifically, the following
490 chipsets are supported: 500 chipsets are supported:
491 82C596A/B 501 VT82C596A/B
492 82C686A/B 502 VT82C686A/B
493 8231 503 VT8231
494 8233 504 VT8233/A
495 8233A 505 VT8235
496 8235 506 VT8237R/A
497 8237 507 VT8251
498 508
499 This driver can also be built as a module. If so, the module 509 This driver can also be built as a module. If so, the module
500 will be called i2c-viapro. 510 will be called i2c-viapro.
diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile
index ac56df53155b..493c87289b62 100644
--- a/drivers/i2c/busses/Makefile
+++ b/drivers/i2c/busses/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_I2C_MPC) += i2c-mpc.o
24obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o 24obj-$(CONFIG_I2C_MV64XXX) += i2c-mv64xxx.o
25obj-$(CONFIG_I2C_NFORCE2) += i2c-nforce2.o 25obj-$(CONFIG_I2C_NFORCE2) += i2c-nforce2.o
26obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o 26obj-$(CONFIG_I2C_OCORES) += i2c-ocores.o
27obj-$(CONFIG_I2C_OMAP) += i2c-omap.o
27obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o 28obj-$(CONFIG_I2C_PARPORT) += i2c-parport.o
28obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o 29obj-$(CONFIG_I2C_PARPORT_LIGHT) += i2c-parport-light.o
29obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o 30obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index d3ef46aeeb3c..e75d339a3481 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -468,7 +468,7 @@ static u32 ali1535_func(struct i2c_adapter *adapter)
468 I2C_FUNC_SMBUS_BLOCK_DATA; 468 I2C_FUNC_SMBUS_BLOCK_DATA;
469} 469}
470 470
471static struct i2c_algorithm smbus_algorithm = { 471static const struct i2c_algorithm smbus_algorithm = {
472 .smbus_xfer = ali1535_access, 472 .smbus_xfer = ali1535_access,
473 .functionality = ali1535_func, 473 .functionality = ali1535_func,
474}; 474};
diff --git a/drivers/i2c/busses/i2c-ali1563.c b/drivers/i2c/busses/i2c-ali1563.c
index e6f63208fc4a..33fbb47100a3 100644
--- a/drivers/i2c/busses/i2c-ali1563.c
+++ b/drivers/i2c/busses/i2c-ali1563.c
@@ -367,7 +367,7 @@ static void ali1563_shutdown(struct pci_dev *dev)
367 release_region(ali1563_smba,ALI1563_SMB_IOSIZE); 367 release_region(ali1563_smba,ALI1563_SMB_IOSIZE);
368} 368}
369 369
370static struct i2c_algorithm ali1563_algorithm = { 370static const struct i2c_algorithm ali1563_algorithm = {
371 .smbus_xfer = ali1563_access, 371 .smbus_xfer = ali1563_access,
372 .functionality = ali1563_func, 372 .functionality = ali1563_func,
373}; 373};
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index 7a5c0941dbc1..3f11b6e1a341 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -463,7 +463,7 @@ static u32 ali15x3_func(struct i2c_adapter *adapter)
463 I2C_FUNC_SMBUS_BLOCK_DATA; 463 I2C_FUNC_SMBUS_BLOCK_DATA;
464} 464}
465 465
466static struct i2c_algorithm smbus_algorithm = { 466static const struct i2c_algorithm smbus_algorithm = {
467 .smbus_xfer = ali15x3_access, 467 .smbus_xfer = ali15x3_access,
468 .functionality = ali15x3_func, 468 .functionality = ali15x3_func,
469}; 469};
diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index 1750dedaf4b5..2d21afdc5b1c 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -294,7 +294,7 @@ static u32 amd756_func(struct i2c_adapter *adapter)
294 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL; 294 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_PROC_CALL;
295} 295}
296 296
297static struct i2c_algorithm smbus_algorithm = { 297static const struct i2c_algorithm smbus_algorithm = {
298 .smbus_xfer = amd756_access, 298 .smbus_xfer = amd756_access,
299 .functionality = amd756_func, 299 .functionality = amd756_func,
300}; 300};
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c
index e5ef560e686a..0fbc7186c91a 100644
--- a/drivers/i2c/busses/i2c-amd8111.c
+++ b/drivers/i2c/busses/i2c-amd8111.c
@@ -316,7 +316,7 @@ static u32 amd8111_func(struct i2c_adapter *adapter)
316 I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_HWPEC_CALC; 316 I2C_FUNC_SMBUS_I2C_BLOCK | I2C_FUNC_SMBUS_HWPEC_CALC;
317} 317}
318 318
319static struct i2c_algorithm smbus_algorithm = { 319static const struct i2c_algorithm smbus_algorithm = {
320 .smbus_xfer = amd8111_access, 320 .smbus_xfer = amd8111_access,
321 .functionality = amd8111_func, 321 .functionality = amd8111_func,
322}; 322};
diff --git a/drivers/i2c/busses/i2c-au1550.c b/drivers/i2c/busses/i2c-au1550.c
index d06edce03bf4..d7e7c359fc36 100644
--- a/drivers/i2c/busses/i2c-au1550.c
+++ b/drivers/i2c/busses/i2c-au1550.c
@@ -34,8 +34,7 @@
34#include <linux/errno.h> 34#include <linux/errno.h>
35#include <linux/i2c.h> 35#include <linux/i2c.h>
36 36
37#include <asm/mach-au1x00/au1000.h> 37#include <asm/mach-au1x00/au1xxx.h>
38#include <asm/mach-pb1x00/pb1550.h>
39#include <asm/mach-au1x00/au1xxx_psc.h> 38#include <asm/mach-au1x00/au1xxx_psc.h>
40 39
41#include "i2c-au1550.h" 40#include "i2c-au1550.h"
@@ -118,13 +117,19 @@ do_address(struct i2c_au1550_data *adap, unsigned int addr, int rd)
118 117
119 /* Reset the FIFOs, clear events. 118 /* Reset the FIFOs, clear events.
120 */ 119 */
121 sp->psc_smbpcr = PSC_SMBPCR_DC; 120 stat = sp->psc_smbstat;
122 sp->psc_smbevnt = PSC_SMBEVNT_ALLCLR; 121 sp->psc_smbevnt = PSC_SMBEVNT_ALLCLR;
123 au_sync(); 122 au_sync();
124 do { 123
125 stat = sp->psc_smbpcr; 124 if (!(stat & PSC_SMBSTAT_TE) || !(stat & PSC_SMBSTAT_RE)) {
125 sp->psc_smbpcr = PSC_SMBPCR_DC;
126 au_sync(); 126 au_sync();
127 } while ((stat & PSC_SMBPCR_DC) != 0); 127 do {
128 stat = sp->psc_smbpcr;
129 au_sync();
130 } while ((stat & PSC_SMBPCR_DC) != 0);
131 udelay(50);
132 }
128 133
129 /* Write out the i2c chip address and specify operation 134 /* Write out the i2c chip address and specify operation
130 */ 135 */
@@ -279,10 +284,10 @@ au1550_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs, int num)
279static u32 284static u32
280au1550_func(struct i2c_adapter *adap) 285au1550_func(struct i2c_adapter *adap)
281{ 286{
282 return I2C_FUNC_I2C; 287 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
283} 288}
284 289
285static struct i2c_algorithm au1550_algo = { 290static const struct i2c_algorithm au1550_algo = {
286 .master_xfer = au1550_xfer, 291 .master_xfer = au1550_xfer,
287 .functionality = au1550_func, 292 .functionality = au1550_func,
288}; 293};
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c
index 59f8308c2356..caa8e5c8bfbb 100644
--- a/drivers/i2c/busses/i2c-elektor.c
+++ b/drivers/i2c/busses/i2c-elektor.c
@@ -196,7 +196,6 @@ static struct i2c_algo_pcf_data pcf_isa_data = {
196 .getclock = pcf_isa_getclock, 196 .getclock = pcf_isa_getclock,
197 .waitforpin = pcf_isa_waitforpin, 197 .waitforpin = pcf_isa_waitforpin,
198 .udelay = 10, 198 .udelay = 10,
199 .mdelay = 10,
200 .timeout = 100, 199 .timeout = 100,
201}; 200};
202 201
diff --git a/drivers/i2c/busses/i2c-hydra.c b/drivers/i2c/busses/i2c-hydra.c
index e0cb3b0f92fa..457d48a0ab9d 100644
--- a/drivers/i2c/busses/i2c-hydra.c
+++ b/drivers/i2c/busses/i2c-hydra.c
@@ -99,7 +99,6 @@ static struct i2c_algo_bit_data hydra_bit_data = {
99 .getsda = hydra_bit_getsda, 99 .getsda = hydra_bit_getsda,
100 .getscl = hydra_bit_getscl, 100 .getscl = hydra_bit_getscl,
101 .udelay = 5, 101 .udelay = 5,
102 .mdelay = 5,
103 .timeout = HZ 102 .timeout = HZ
104}; 103};
105 104
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 7be1d0a3e8f8..bbb2fbee836f 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -434,7 +434,7 @@ static u32 i801_func(struct i2c_adapter *adapter)
434 | (isich4 ? I2C_FUNC_SMBUS_HWPEC_CALC : 0); 434 | (isich4 ? I2C_FUNC_SMBUS_HWPEC_CALC : 0);
435} 435}
436 436
437static struct i2c_algorithm smbus_algorithm = { 437static const struct i2c_algorithm smbus_algorithm = {
438 .smbus_xfer = i801_access, 438 .smbus_xfer = i801_access,
439 .functionality = i801_func, 439 .functionality = i801_func,
440}; 440};
diff --git a/drivers/i2c/busses/i2c-i810.c b/drivers/i2c/busses/i2c-i810.c
index 748be30f2bae..b66fb6bb1870 100644
--- a/drivers/i2c/busses/i2c-i810.c
+++ b/drivers/i2c/busses/i2c-i810.c
@@ -166,7 +166,6 @@ static struct i2c_algo_bit_data i810_i2c_bit_data = {
166 .getsda = bit_i810i2c_getsda, 166 .getsda = bit_i810i2c_getsda,
167 .getscl = bit_i810i2c_getscl, 167 .getscl = bit_i810i2c_getscl,
168 .udelay = CYCLE_DELAY, 168 .udelay = CYCLE_DELAY,
169 .mdelay = CYCLE_DELAY,
170 .timeout = TIMEOUT, 169 .timeout = TIMEOUT,
171}; 170};
172 171
@@ -182,7 +181,6 @@ static struct i2c_algo_bit_data i810_ddc_bit_data = {
182 .getsda = bit_i810ddc_getsda, 181 .getsda = bit_i810ddc_getsda,
183 .getscl = bit_i810ddc_getscl, 182 .getscl = bit_i810ddc_getscl,
184 .udelay = CYCLE_DELAY, 183 .udelay = CYCLE_DELAY,
185 .mdelay = CYCLE_DELAY,
186 .timeout = TIMEOUT, 184 .timeout = TIMEOUT,
187}; 185};
188 186
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index 0599bbd65d93..5bccb5d68318 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -625,7 +625,7 @@ static u32 iic_func(struct i2c_adapter *adap)
625 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR; 625 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_10BIT_ADDR;
626} 626}
627 627
628static struct i2c_algorithm iic_algo = { 628static const struct i2c_algorithm iic_algo = {
629 .master_xfer = iic_xfer, 629 .master_xfer = iic_xfer,
630 .functionality = iic_func 630 .functionality = iic_func
631}; 631};
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index 48c56939c861..8e413150af37 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -401,7 +401,7 @@ iop3xx_i2c_func(struct i2c_adapter *adap)
401 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 401 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
402} 402}
403 403
404static struct i2c_algorithm iop3xx_i2c_algo = { 404static const struct i2c_algorithm iop3xx_i2c_algo = {
405 .master_xfer = iop3xx_i2c_master_xfer, 405 .master_xfer = iop3xx_i2c_master_xfer,
406 .algo_control = iop3xx_i2c_algo_control, 406 .algo_control = iop3xx_i2c_algo_control,
407 .functionality = iop3xx_i2c_func, 407 .functionality = iop3xx_i2c_func,
diff --git a/drivers/i2c/busses/i2c-isa.c b/drivers/i2c/busses/i2c-isa.c
index c3e1d3e888d7..4380653748a4 100644
--- a/drivers/i2c/busses/i2c-isa.c
+++ b/drivers/i2c/busses/i2c-isa.c
@@ -43,7 +43,7 @@
43static u32 isa_func(struct i2c_adapter *adapter); 43static u32 isa_func(struct i2c_adapter *adapter);
44 44
45/* This is the actual algorithm we define */ 45/* This is the actual algorithm we define */
46static struct i2c_algorithm isa_algorithm = { 46static const struct i2c_algorithm isa_algorithm = {
47 .functionality = isa_func, 47 .functionality = isa_func,
48}; 48};
49 49
@@ -89,9 +89,14 @@ int i2c_isa_add_driver(struct i2c_driver *driver)
89 dev_dbg(&isa_adapter.dev, "Driver %s registered\n", driver->driver.name); 89 dev_dbg(&isa_adapter.dev, "Driver %s registered\n", driver->driver.name);
90 90
91 /* Now look for clients */ 91 /* Now look for clients */
92 driver->attach_adapter(&isa_adapter); 92 res = driver->attach_adapter(&isa_adapter);
93 93 if (res) {
94 return 0; 94 dev_err(&isa_adapter.dev,
95 "Driver %s failed to attach adapter, unregistering\n",
96 driver->driver.name);
97 driver_unregister(&driver->driver);
98 }
99 return res;
95} 100}
96 101
97int i2c_isa_del_driver(struct i2c_driver *driver) 102int i2c_isa_del_driver(struct i2c_driver *driver)
@@ -125,6 +130,8 @@ int i2c_isa_del_driver(struct i2c_driver *driver)
125 130
126static int __init i2c_isa_init(void) 131static int __init i2c_isa_init(void)
127{ 132{
133 int err;
134
128 mutex_init(&isa_adapter.clist_lock); 135 mutex_init(&isa_adapter.clist_lock);
129 INIT_LIST_HEAD(&isa_adapter.clients); 136 INIT_LIST_HEAD(&isa_adapter.clients);
130 137
@@ -133,8 +140,16 @@ static int __init i2c_isa_init(void)
133 sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr); 140 sprintf(isa_adapter.dev.bus_id, "i2c-%d", isa_adapter.nr);
134 isa_adapter.dev.driver = &i2c_adapter_driver; 141 isa_adapter.dev.driver = &i2c_adapter_driver;
135 isa_adapter.dev.release = &i2c_adapter_dev_release; 142 isa_adapter.dev.release = &i2c_adapter_dev_release;
136 device_register(&isa_adapter.dev); 143 err = device_register(&isa_adapter.dev);
137 device_create_file(&isa_adapter.dev, &dev_attr_name); 144 if (err) {
145 printk(KERN_ERR "i2c-isa: Failed to register device\n");
146 goto exit;
147 }
148 err = device_create_file(&isa_adapter.dev, &dev_attr_name);
149 if (err) {
150 printk(KERN_ERR "i2c-isa: Failed to create name file\n");
151 goto exit_unregister;
152 }
138 153
139 /* Add this adapter to the i2c_adapter class */ 154 /* Add this adapter to the i2c_adapter class */
140 memset(&isa_adapter.class_dev, 0x00, sizeof(struct class_device)); 155 memset(&isa_adapter.class_dev, 0x00, sizeof(struct class_device));
@@ -142,11 +157,24 @@ static int __init i2c_isa_init(void)
142 isa_adapter.class_dev.class = &i2c_adapter_class; 157 isa_adapter.class_dev.class = &i2c_adapter_class;
143 strlcpy(isa_adapter.class_dev.class_id, isa_adapter.dev.bus_id, 158 strlcpy(isa_adapter.class_dev.class_id, isa_adapter.dev.bus_id,
144 BUS_ID_SIZE); 159 BUS_ID_SIZE);
145 class_device_register(&isa_adapter.class_dev); 160 err = class_device_register(&isa_adapter.class_dev);
161 if (err) {
162 printk(KERN_ERR "i2c-isa: Failed to register class device\n");
163 goto exit_remove_name;
164 }
146 165
147 dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name); 166 dev_dbg(&isa_adapter.dev, "%s registered\n", isa_adapter.name);
148 167
149 return 0; 168 return 0;
169
170exit_remove_name:
171 device_remove_file(&isa_adapter.dev, &dev_attr_name);
172exit_unregister:
173 init_completion(&isa_adapter.dev_released); /* Needed? */
174 device_unregister(&isa_adapter.dev);
175 wait_for_completion(&isa_adapter.dev_released);
176exit:
177 return err;
150} 178}
151 179
152static void __exit i2c_isa_exit(void) 180static void __exit i2c_isa_exit(void)
diff --git a/drivers/i2c/busses/i2c-ixp2000.c b/drivers/i2c/busses/i2c-ixp2000.c
index cd6f45d186ab..dd3f4cd3aa68 100644
--- a/drivers/i2c/busses/i2c-ixp2000.c
+++ b/drivers/i2c/busses/i2c-ixp2000.c
@@ -114,7 +114,6 @@ static int ixp2000_i2c_probe(struct platform_device *plat_dev)
114 drv_data->algo_data.getsda = ixp2000_bit_getsda; 114 drv_data->algo_data.getsda = ixp2000_bit_getsda;
115 drv_data->algo_data.getscl = ixp2000_bit_getscl; 115 drv_data->algo_data.getscl = ixp2000_bit_getscl;
116 drv_data->algo_data.udelay = 6; 116 drv_data->algo_data.udelay = 6;
117 drv_data->algo_data.mdelay = 6;
118 drv_data->algo_data.timeout = 100; 117 drv_data->algo_data.timeout = 100;
119 118
120 drv_data->adapter.id = I2C_HW_B_IXP2000, 119 drv_data->adapter.id = I2C_HW_B_IXP2000,
diff --git a/drivers/i2c/busses/i2c-ixp4xx.c b/drivers/i2c/busses/i2c-ixp4xx.c
index 2ed07112d683..ab573254a8aa 100644
--- a/drivers/i2c/busses/i2c-ixp4xx.c
+++ b/drivers/i2c/busses/i2c-ixp4xx.c
@@ -122,7 +122,6 @@ static int ixp4xx_i2c_probe(struct platform_device *plat_dev)
122 drv_data->algo_data.getsda = ixp4xx_bit_getsda; 122 drv_data->algo_data.getsda = ixp4xx_bit_getsda;
123 drv_data->algo_data.getscl = ixp4xx_bit_getscl; 123 drv_data->algo_data.getscl = ixp4xx_bit_getscl;
124 drv_data->algo_data.udelay = 10; 124 drv_data->algo_data.udelay = 10;
125 drv_data->algo_data.mdelay = 10;
126 drv_data->algo_data.timeout = 100; 125 drv_data->algo_data.timeout = 100;
127 126
128 drv_data->adapter.id = I2C_HW_B_IXP4XX; 127 drv_data->adapter.id = I2C_HW_B_IXP4XX;
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index 377ab40944b8..155a986de516 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -272,7 +272,7 @@ static u32 mpc_functionality(struct i2c_adapter *adap)
272 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 272 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
273} 273}
274 274
275static struct i2c_algorithm mpc_algo = { 275static const struct i2c_algorithm mpc_algo = {
276 .master_xfer = mpc_xfer, 276 .master_xfer = mpc_xfer,
277 .functionality = mpc_functionality, 277 .functionality = mpc_functionality,
278}; 278};
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index ac5cde1bbd2b..eacbaf745b64 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -431,7 +431,7 @@ mv64xxx_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
431 return num; 431 return num;
432} 432}
433 433
434static struct i2c_algorithm mv64xxx_i2c_algo = { 434static const struct i2c_algorithm mv64xxx_i2c_algo = {
435 .master_xfer = mv64xxx_i2c_xfer, 435 .master_xfer = mv64xxx_i2c_xfer,
436 .functionality = mv64xxx_i2c_functionality, 436 .functionality = mv64xxx_i2c_functionality,
437}; 437};
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index 604b49e22df1..e0292e414ab2 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -109,7 +109,7 @@ static s32 nforce2_access(struct i2c_adapter *adap, u16 addr,
109static u32 nforce2_func(struct i2c_adapter *adapter); 109static u32 nforce2_func(struct i2c_adapter *adapter);
110 110
111 111
112static struct i2c_algorithm smbus_algorithm = { 112static const struct i2c_algorithm smbus_algorithm = {
113 .smbus_xfer = nforce2_access, 113 .smbus_xfer = nforce2_access,
114 .functionality = nforce2_func, 114 .functionality = nforce2_func,
115}; 115};
diff --git a/drivers/i2c/busses/i2c-ocores.c b/drivers/i2c/busses/i2c-ocores.c
index 592824087c49..952a28d485ce 100644
--- a/drivers/i2c/busses/i2c-ocores.c
+++ b/drivers/i2c/busses/i2c-ocores.c
@@ -199,7 +199,7 @@ static u32 ocores_func(struct i2c_adapter *adap)
199 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 199 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
200} 200}
201 201
202static struct i2c_algorithm ocores_algorithm = { 202static const struct i2c_algorithm ocores_algorithm = {
203 .master_xfer = ocores_xfer, 203 .master_xfer = ocores_xfer,
204 .functionality = ocores_func, 204 .functionality = ocores_func,
205}; 205};
diff --git a/drivers/i2c/busses/i2c-omap.c b/drivers/i2c/busses/i2c-omap.c
new file mode 100644
index 000000000000..81d87d2c2a2d
--- /dev/null
+++ b/drivers/i2c/busses/i2c-omap.c
@@ -0,0 +1,676 @@
1/*
2 * TI OMAP I2C master mode driver
3 *
4 * Copyright (C) 2003 MontaVista Software, Inc.
5 * Copyright (C) 2004 Texas Instruments.
6 *
7 * Updated to work with multiple I2C interfaces on 24xx by
8 * Tony Lindgren <tony@atomide.com> and Imre Deak <imre.deak@nokia.com>
9 * Copyright (C) 2005 Nokia Corporation
10 *
11 * Cleaned up by Juha Yrjölä <juha.yrjola@nokia.com>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27
28#include <linux/module.h>
29#include <linux/delay.h>
30#include <linux/i2c.h>
31#include <linux/err.h>
32#include <linux/interrupt.h>
33#include <linux/completion.h>
34#include <linux/platform_device.h>
35#include <linux/clk.h>
36
37#include <asm/io.h>
38
39/* timeout waiting for the controller to respond */
40#define OMAP_I2C_TIMEOUT (msecs_to_jiffies(1000))
41
42#define OMAP_I2C_REV_REG 0x00
43#define OMAP_I2C_IE_REG 0x04
44#define OMAP_I2C_STAT_REG 0x08
45#define OMAP_I2C_IV_REG 0x0c
46#define OMAP_I2C_SYSS_REG 0x10
47#define OMAP_I2C_BUF_REG 0x14
48#define OMAP_I2C_CNT_REG 0x18
49#define OMAP_I2C_DATA_REG 0x1c
50#define OMAP_I2C_SYSC_REG 0x20
51#define OMAP_I2C_CON_REG 0x24
52#define OMAP_I2C_OA_REG 0x28
53#define OMAP_I2C_SA_REG 0x2c
54#define OMAP_I2C_PSC_REG 0x30
55#define OMAP_I2C_SCLL_REG 0x34
56#define OMAP_I2C_SCLH_REG 0x38
57#define OMAP_I2C_SYSTEST_REG 0x3c
58
59/* I2C Interrupt Enable Register (OMAP_I2C_IE): */
60#define OMAP_I2C_IE_XRDY (1 << 4) /* TX data ready int enable */
61#define OMAP_I2C_IE_RRDY (1 << 3) /* RX data ready int enable */
62#define OMAP_I2C_IE_ARDY (1 << 2) /* Access ready int enable */
63#define OMAP_I2C_IE_NACK (1 << 1) /* No ack interrupt enable */
64#define OMAP_I2C_IE_AL (1 << 0) /* Arbitration lost int ena */
65
66/* I2C Status Register (OMAP_I2C_STAT): */
67#define OMAP_I2C_STAT_SBD (1 << 15) /* Single byte data */
68#define OMAP_I2C_STAT_BB (1 << 12) /* Bus busy */
69#define OMAP_I2C_STAT_ROVR (1 << 11) /* Receive overrun */
70#define OMAP_I2C_STAT_XUDF (1 << 10) /* Transmit underflow */
71#define OMAP_I2C_STAT_AAS (1 << 9) /* Address as slave */
72#define OMAP_I2C_STAT_AD0 (1 << 8) /* Address zero */
73#define OMAP_I2C_STAT_XRDY (1 << 4) /* Transmit data ready */
74#define OMAP_I2C_STAT_RRDY (1 << 3) /* Receive data ready */
75#define OMAP_I2C_STAT_ARDY (1 << 2) /* Register access ready */
76#define OMAP_I2C_STAT_NACK (1 << 1) /* No ack interrupt enable */
77#define OMAP_I2C_STAT_AL (1 << 0) /* Arbitration lost int ena */
78
79/* I2C Buffer Configuration Register (OMAP_I2C_BUF): */
80#define OMAP_I2C_BUF_RDMA_EN (1 << 15) /* RX DMA channel enable */
81#define OMAP_I2C_BUF_XDMA_EN (1 << 7) /* TX DMA channel enable */
82
83/* I2C Configuration Register (OMAP_I2C_CON): */
84#define OMAP_I2C_CON_EN (1 << 15) /* I2C module enable */
85#define OMAP_I2C_CON_BE (1 << 14) /* Big endian mode */
86#define OMAP_I2C_CON_STB (1 << 11) /* Start byte mode (master) */
87#define OMAP_I2C_CON_MST (1 << 10) /* Master/slave mode */
88#define OMAP_I2C_CON_TRX (1 << 9) /* TX/RX mode (master only) */
89#define OMAP_I2C_CON_XA (1 << 8) /* Expand address */
90#define OMAP_I2C_CON_RM (1 << 2) /* Repeat mode (master only) */
91#define OMAP_I2C_CON_STP (1 << 1) /* Stop cond (master only) */
92#define OMAP_I2C_CON_STT (1 << 0) /* Start condition (master) */
93
94/* I2C System Test Register (OMAP_I2C_SYSTEST): */
95#ifdef DEBUG
96#define OMAP_I2C_SYSTEST_ST_EN (1 << 15) /* System test enable */
97#define OMAP_I2C_SYSTEST_FREE (1 << 14) /* Free running mode */
98#define OMAP_I2C_SYSTEST_TMODE_MASK (3 << 12) /* Test mode select */
99#define OMAP_I2C_SYSTEST_TMODE_SHIFT (12) /* Test mode select */
100#define OMAP_I2C_SYSTEST_SCL_I (1 << 3) /* SCL line sense in */
101#define OMAP_I2C_SYSTEST_SCL_O (1 << 2) /* SCL line drive out */
102#define OMAP_I2C_SYSTEST_SDA_I (1 << 1) /* SDA line sense in */
103#define OMAP_I2C_SYSTEST_SDA_O (1 << 0) /* SDA line drive out */
104#endif
105
106/* I2C System Status register (OMAP_I2C_SYSS): */
107#define OMAP_I2C_SYSS_RDONE (1 << 0) /* Reset Done */
108
109/* I2C System Configuration Register (OMAP_I2C_SYSC): */
110#define OMAP_I2C_SYSC_SRST (1 << 1) /* Soft Reset */
111
112/* REVISIT: Use platform_data instead of module parameters */
113/* Fast Mode = 400 kHz, Standard = 100 kHz */
114static int clock = 100; /* Default: 100 kHz */
115module_param(clock, int, 0);
116MODULE_PARM_DESC(clock, "Set I2C clock in kHz: 400=fast mode (default == 100)");
117
118struct omap_i2c_dev {
119 struct device *dev;
120 void __iomem *base; /* virtual */
121 int irq;
122 struct clk *iclk; /* Interface clock */
123 struct clk *fclk; /* Functional clock */
124 struct completion cmd_complete;
125 struct resource *ioarea;
126 u16 cmd_err;
127 u8 *buf;
128 size_t buf_len;
129 struct i2c_adapter adapter;
130 unsigned rev1:1;
131};
132
133static inline void omap_i2c_write_reg(struct omap_i2c_dev *i2c_dev,
134 int reg, u16 val)
135{
136 __raw_writew(val, i2c_dev->base + reg);
137}
138
139static inline u16 omap_i2c_read_reg(struct omap_i2c_dev *i2c_dev, int reg)
140{
141 return __raw_readw(i2c_dev->base + reg);
142}
143
144static int omap_i2c_get_clocks(struct omap_i2c_dev *dev)
145{
146 if (cpu_is_omap16xx() || cpu_is_omap24xx()) {
147 dev->iclk = clk_get(dev->dev, "i2c_ick");
148 if (IS_ERR(dev->iclk)) {
149 dev->iclk = NULL;
150 return -ENODEV;
151 }
152 }
153
154 dev->fclk = clk_get(dev->dev, "i2c_fck");
155 if (IS_ERR(dev->fclk)) {
156 if (dev->iclk != NULL) {
157 clk_put(dev->iclk);
158 dev->iclk = NULL;
159 }
160 dev->fclk = NULL;
161 return -ENODEV;
162 }
163
164 return 0;
165}
166
167static void omap_i2c_put_clocks(struct omap_i2c_dev *dev)
168{
169 clk_put(dev->fclk);
170 dev->fclk = NULL;
171 if (dev->iclk != NULL) {
172 clk_put(dev->iclk);
173 dev->iclk = NULL;
174 }
175}
176
177static void omap_i2c_enable_clocks(struct omap_i2c_dev *dev)
178{
179 if (dev->iclk != NULL)
180 clk_enable(dev->iclk);
181 clk_enable(dev->fclk);
182}
183
184static void omap_i2c_disable_clocks(struct omap_i2c_dev *dev)
185{
186 if (dev->iclk != NULL)
187 clk_disable(dev->iclk);
188 clk_disable(dev->fclk);
189}
190
191static int omap_i2c_init(struct omap_i2c_dev *dev)
192{
193 u16 psc = 0;
194 unsigned long fclk_rate = 12000000;
195 unsigned long timeout;
196
197 if (!dev->rev1) {
198 omap_i2c_write_reg(dev, OMAP_I2C_SYSC_REG, OMAP_I2C_SYSC_SRST);
199 /* For some reason we need to set the EN bit before the
200 * reset done bit gets set. */
201 timeout = jiffies + OMAP_I2C_TIMEOUT;
202 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
203 while (!(omap_i2c_read_reg(dev, OMAP_I2C_SYSS_REG) &
204 OMAP_I2C_SYSS_RDONE)) {
205 if (time_after(jiffies, timeout)) {
206 dev_warn(dev->dev, "timeout waiting"
207 "for controller reset\n");
208 return -ETIMEDOUT;
209 }
210 msleep(1);
211 }
212 }
213 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
214
215 if (cpu_class_is_omap1()) {
216 struct clk *armxor_ck;
217
218 armxor_ck = clk_get(NULL, "armxor_ck");
219 if (IS_ERR(armxor_ck))
220 dev_warn(dev->dev, "Could not get armxor_ck\n");
221 else {
222 fclk_rate = clk_get_rate(armxor_ck);
223 clk_put(armxor_ck);
224 }
225 /* TRM for 5912 says the I2C clock must be prescaled to be
226 * between 7 - 12 MHz. The XOR input clock is typically
227 * 12, 13 or 19.2 MHz. So we should have code that produces:
228 *
229 * XOR MHz Divider Prescaler
230 * 12 1 0
231 * 13 2 1
232 * 19.2 2 1
233 */
234 if (fclk_rate > 16000000)
235 psc = (fclk_rate + 8000000) / 12000000;
236 }
237
238 /* Setup clock prescaler to obtain approx 12MHz I2C module clock: */
239 omap_i2c_write_reg(dev, OMAP_I2C_PSC_REG, psc);
240
241 /* Program desired operating rate */
242 fclk_rate /= (psc + 1) * 1000;
243 if (psc > 2)
244 psc = 2;
245
246 omap_i2c_write_reg(dev, OMAP_I2C_SCLL_REG,
247 fclk_rate / (clock * 2) - 7 + psc);
248 omap_i2c_write_reg(dev, OMAP_I2C_SCLH_REG,
249 fclk_rate / (clock * 2) - 7 + psc);
250
251 /* Take the I2C module out of reset: */
252 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_EN);
253
254 /* Enable interrupts */
255 omap_i2c_write_reg(dev, OMAP_I2C_IE_REG,
256 (OMAP_I2C_IE_XRDY | OMAP_I2C_IE_RRDY |
257 OMAP_I2C_IE_ARDY | OMAP_I2C_IE_NACK |
258 OMAP_I2C_IE_AL));
259 return 0;
260}
261
262/*
263 * Waiting on Bus Busy
264 */
265static int omap_i2c_wait_for_bb(struct omap_i2c_dev *dev)
266{
267 unsigned long timeout;
268
269 timeout = jiffies + OMAP_I2C_TIMEOUT;
270 while (omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG) & OMAP_I2C_STAT_BB) {
271 if (time_after(jiffies, timeout)) {
272 dev_warn(dev->dev, "timeout waiting for bus ready\n");
273 return -ETIMEDOUT;
274 }
275 msleep(1);
276 }
277
278 return 0;
279}
280
281/*
282 * Low level master read/write transaction.
283 */
284static int omap_i2c_xfer_msg(struct i2c_adapter *adap,
285 struct i2c_msg *msg, int stop)
286{
287 struct omap_i2c_dev *dev = i2c_get_adapdata(adap);
288 int r;
289 u16 w;
290
291 dev_dbg(dev->dev, "addr: 0x%04x, len: %d, flags: 0x%x, stop: %d\n",
292 msg->addr, msg->len, msg->flags, stop);
293
294 if (msg->len == 0)
295 return -EINVAL;
296
297 omap_i2c_write_reg(dev, OMAP_I2C_SA_REG, msg->addr);
298
299 /* REVISIT: Could the STB bit of I2C_CON be used with probing? */
300 dev->buf = msg->buf;
301 dev->buf_len = msg->len;
302
303 omap_i2c_write_reg(dev, OMAP_I2C_CNT_REG, dev->buf_len);
304
305 init_completion(&dev->cmd_complete);
306 dev->cmd_err = 0;
307
308 w = OMAP_I2C_CON_EN | OMAP_I2C_CON_MST | OMAP_I2C_CON_STT;
309 if (msg->flags & I2C_M_TEN)
310 w |= OMAP_I2C_CON_XA;
311 if (!(msg->flags & I2C_M_RD))
312 w |= OMAP_I2C_CON_TRX;
313 if (stop)
314 w |= OMAP_I2C_CON_STP;
315 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w);
316
317 r = wait_for_completion_interruptible_timeout(&dev->cmd_complete,
318 OMAP_I2C_TIMEOUT);
319 dev->buf_len = 0;
320 if (r < 0)
321 return r;
322 if (r == 0) {
323 dev_err(dev->dev, "controller timed out\n");
324 omap_i2c_init(dev);
325 return -ETIMEDOUT;
326 }
327
328 if (likely(!dev->cmd_err))
329 return 0;
330
331 /* We have an error */
332 if (dev->cmd_err & (OMAP_I2C_STAT_AL | OMAP_I2C_STAT_ROVR |
333 OMAP_I2C_STAT_XUDF)) {
334 omap_i2c_init(dev);
335 return -EIO;
336 }
337
338 if (dev->cmd_err & OMAP_I2C_STAT_NACK) {
339 if (msg->flags & I2C_M_IGNORE_NAK)
340 return 0;
341 if (stop) {
342 w = omap_i2c_read_reg(dev, OMAP_I2C_CON_REG);
343 w |= OMAP_I2C_CON_STP;
344 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, w);
345 }
346 return -EREMOTEIO;
347 }
348 return -EIO;
349}
350
351
352/*
353 * Prepare controller for a transaction and call omap_i2c_xfer_msg
354 * to do the work during IRQ processing.
355 */
356static int
357omap_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
358{
359 struct omap_i2c_dev *dev = i2c_get_adapdata(adap);
360 int i;
361 int r;
362
363 omap_i2c_enable_clocks(dev);
364
365 /* REVISIT: initialize and use adap->retries. This is an optional
366 * feature */
367 if ((r = omap_i2c_wait_for_bb(dev)) < 0)
368 goto out;
369
370 for (i = 0; i < num; i++) {
371 r = omap_i2c_xfer_msg(adap, &msgs[i], (i == (num - 1)));
372 if (r != 0)
373 break;
374 }
375
376 if (r == 0)
377 r = num;
378out:
379 omap_i2c_disable_clocks(dev);
380 return r;
381}
382
383static u32
384omap_i2c_func(struct i2c_adapter *adap)
385{
386 return I2C_FUNC_I2C | (I2C_FUNC_SMBUS_EMUL & ~I2C_FUNC_SMBUS_QUICK);
387}
388
389static inline void
390omap_i2c_complete_cmd(struct omap_i2c_dev *dev, u16 err)
391{
392 dev->cmd_err |= err;
393 complete(&dev->cmd_complete);
394}
395
396static inline void
397omap_i2c_ack_stat(struct omap_i2c_dev *dev, u16 stat)
398{
399 omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat);
400}
401
402static irqreturn_t
403omap_i2c_rev1_isr(int this_irq, void *dev_id, struct pt_regs *regs)
404{
405 struct omap_i2c_dev *dev = dev_id;
406 u16 iv, w;
407
408 iv = omap_i2c_read_reg(dev, OMAP_I2C_IV_REG);
409 switch (iv) {
410 case 0x00: /* None */
411 break;
412 case 0x01: /* Arbitration lost */
413 dev_err(dev->dev, "Arbitration lost\n");
414 omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_AL);
415 break;
416 case 0x02: /* No acknowledgement */
417 omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_NACK);
418 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, OMAP_I2C_CON_STP);
419 break;
420 case 0x03: /* Register access ready */
421 omap_i2c_complete_cmd(dev, 0);
422 break;
423 case 0x04: /* Receive data ready */
424 if (dev->buf_len) {
425 w = omap_i2c_read_reg(dev, OMAP_I2C_DATA_REG);
426 *dev->buf++ = w;
427 dev->buf_len--;
428 if (dev->buf_len) {
429 *dev->buf++ = w >> 8;
430 dev->buf_len--;
431 }
432 } else
433 dev_err(dev->dev, "RRDY IRQ while no data requested\n");
434 break;
435 case 0x05: /* Transmit data ready */
436 if (dev->buf_len) {
437 w = *dev->buf++;
438 dev->buf_len--;
439 if (dev->buf_len) {
440 w |= *dev->buf++ << 8;
441 dev->buf_len--;
442 }
443 omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w);
444 } else
445 dev_err(dev->dev, "XRDY IRQ while no data to send\n");
446 break;
447 default:
448 return IRQ_NONE;
449 }
450
451 return IRQ_HANDLED;
452}
453
454static irqreturn_t
455omap_i2c_isr(int this_irq, void *dev_id, struct pt_regs *regs)
456{
457 struct omap_i2c_dev *dev = dev_id;
458 u16 bits;
459 u16 stat, w;
460 int count = 0;
461
462 bits = omap_i2c_read_reg(dev, OMAP_I2C_IE_REG);
463 while ((stat = (omap_i2c_read_reg(dev, OMAP_I2C_STAT_REG))) & bits) {
464 dev_dbg(dev->dev, "IRQ (ISR = 0x%04x)\n", stat);
465 if (count++ == 100) {
466 dev_warn(dev->dev, "Too much work in one IRQ\n");
467 break;
468 }
469
470 omap_i2c_write_reg(dev, OMAP_I2C_STAT_REG, stat);
471
472 if (stat & OMAP_I2C_STAT_ARDY) {
473 omap_i2c_complete_cmd(dev, 0);
474 continue;
475 }
476 if (stat & OMAP_I2C_STAT_RRDY) {
477 w = omap_i2c_read_reg(dev, OMAP_I2C_DATA_REG);
478 if (dev->buf_len) {
479 *dev->buf++ = w;
480 dev->buf_len--;
481 if (dev->buf_len) {
482 *dev->buf++ = w >> 8;
483 dev->buf_len--;
484 }
485 } else
486 dev_err(dev->dev, "RRDY IRQ while no data"
487 "requested\n");
488 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_RRDY);
489 continue;
490 }
491 if (stat & OMAP_I2C_STAT_XRDY) {
492 w = 0;
493 if (dev->buf_len) {
494 w = *dev->buf++;
495 dev->buf_len--;
496 if (dev->buf_len) {
497 w |= *dev->buf++ << 8;
498 dev->buf_len--;
499 }
500 } else
501 dev_err(dev->dev, "XRDY IRQ while no"
502 "data to send\n");
503 omap_i2c_write_reg(dev, OMAP_I2C_DATA_REG, w);
504 omap_i2c_ack_stat(dev, OMAP_I2C_STAT_XRDY);
505 continue;
506 }
507 if (stat & OMAP_I2C_STAT_ROVR) {
508 dev_err(dev->dev, "Receive overrun\n");
509 dev->cmd_err |= OMAP_I2C_STAT_ROVR;
510 }
511 if (stat & OMAP_I2C_STAT_XUDF) {
512 dev_err(dev->dev, "Transmit overflow\n");
513 dev->cmd_err |= OMAP_I2C_STAT_XUDF;
514 }
515 if (stat & OMAP_I2C_STAT_NACK) {
516 omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_NACK);
517 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG,
518 OMAP_I2C_CON_STP);
519 }
520 if (stat & OMAP_I2C_STAT_AL) {
521 dev_err(dev->dev, "Arbitration lost\n");
522 omap_i2c_complete_cmd(dev, OMAP_I2C_STAT_AL);
523 }
524 }
525
526 return count ? IRQ_HANDLED : IRQ_NONE;
527}
528
529static const struct i2c_algorithm omap_i2c_algo = {
530 .master_xfer = omap_i2c_xfer,
531 .functionality = omap_i2c_func,
532};
533
534static int
535omap_i2c_probe(struct platform_device *pdev)
536{
537 struct omap_i2c_dev *dev;
538 struct i2c_adapter *adap;
539 struct resource *mem, *irq, *ioarea;
540 int r;
541
542 /* NOTE: driver uses the static register mapping */
543 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
544 if (!mem) {
545 dev_err(&pdev->dev, "no mem resource?\n");
546 return -ENODEV;
547 }
548 irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
549 if (!irq) {
550 dev_err(&pdev->dev, "no irq resource?\n");
551 return -ENODEV;
552 }
553
554 ioarea = request_mem_region(mem->start, (mem->end - mem->start) + 1,
555 pdev->name);
556 if (!ioarea) {
557 dev_err(&pdev->dev, "I2C region already claimed\n");
558 return -EBUSY;
559 }
560
561 if (clock > 200)
562 clock = 400; /* Fast mode */
563 else
564 clock = 100; /* Standard mode */
565
566 dev = kzalloc(sizeof(struct omap_i2c_dev), GFP_KERNEL);
567 if (!dev) {
568 r = -ENOMEM;
569 goto err_release_region;
570 }
571
572 dev->dev = &pdev->dev;
573 dev->irq = irq->start;
574 dev->base = (void __iomem *) IO_ADDRESS(mem->start);
575 platform_set_drvdata(pdev, dev);
576
577 if ((r = omap_i2c_get_clocks(dev)) != 0)
578 goto err_free_mem;
579
580 omap_i2c_enable_clocks(dev);
581
582 if (cpu_is_omap15xx())
583 dev->rev1 = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) < 0x20;
584
585 /* reset ASAP, clearing any IRQs */
586 omap_i2c_init(dev);
587
588 r = request_irq(dev->irq, dev->rev1 ? omap_i2c_rev1_isr : omap_i2c_isr,
589 0, pdev->name, dev);
590
591 if (r) {
592 dev_err(dev->dev, "failure requesting irq %i\n", dev->irq);
593 goto err_unuse_clocks;
594 }
595 r = omap_i2c_read_reg(dev, OMAP_I2C_REV_REG) & 0xff;
596 dev_info(dev->dev, "bus %d rev%d.%d at %d kHz\n",
597 pdev->id, r >> 4, r & 0xf, clock);
598
599 adap = &dev->adapter;
600 i2c_set_adapdata(adap, dev);
601 adap->owner = THIS_MODULE;
602 adap->class = I2C_CLASS_HWMON;
603 strncpy(adap->name, "OMAP I2C adapter", sizeof(adap->name));
604 adap->algo = &omap_i2c_algo;
605 adap->dev.parent = &pdev->dev;
606
607 /* i2c device drivers may be active on return from add_adapter() */
608 r = i2c_add_adapter(adap);
609 if (r) {
610 dev_err(dev->dev, "failure adding adapter\n");
611 goto err_free_irq;
612 }
613
614 omap_i2c_disable_clocks(dev);
615
616 return 0;
617
618err_free_irq:
619 free_irq(dev->irq, dev);
620err_unuse_clocks:
621 omap_i2c_disable_clocks(dev);
622 omap_i2c_put_clocks(dev);
623err_free_mem:
624 platform_set_drvdata(pdev, NULL);
625 kfree(dev);
626err_release_region:
627 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
628 release_mem_region(mem->start, (mem->end - mem->start) + 1);
629
630 return r;
631}
632
633static int
634omap_i2c_remove(struct platform_device *pdev)
635{
636 struct omap_i2c_dev *dev = platform_get_drvdata(pdev);
637 struct resource *mem;
638
639 platform_set_drvdata(pdev, NULL);
640
641 free_irq(dev->irq, dev);
642 i2c_del_adapter(&dev->adapter);
643 omap_i2c_write_reg(dev, OMAP_I2C_CON_REG, 0);
644 omap_i2c_put_clocks(dev);
645 kfree(dev);
646 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
647 release_mem_region(mem->start, (mem->end - mem->start) + 1);
648 return 0;
649}
650
651static struct platform_driver omap_i2c_driver = {
652 .probe = omap_i2c_probe,
653 .remove = omap_i2c_remove,
654 .driver = {
655 .name = "i2c_omap",
656 .owner = THIS_MODULE,
657 },
658};
659
660/* I2C may be needed to bring up other drivers */
661static int __init
662omap_i2c_init_driver(void)
663{
664 return platform_driver_register(&omap_i2c_driver);
665}
666subsys_initcall(omap_i2c_init_driver);
667
668static void __exit omap_i2c_exit_driver(void)
669{
670 platform_driver_unregister(&omap_i2c_driver);
671}
672module_exit(omap_i2c_exit_driver);
673
674MODULE_AUTHOR("MontaVista Software, Inc. (and others)");
675MODULE_DESCRIPTION("TI OMAP I2C bus adapter");
676MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-parport-light.c b/drivers/i2c/busses/i2c-parport-light.c
index e09ebbb2f9f0..5eb2bd294fd9 100644
--- a/drivers/i2c/busses/i2c-parport-light.c
+++ b/drivers/i2c/busses/i2c-parport-light.c
@@ -103,7 +103,6 @@ static struct i2c_algo_bit_data parport_algo_data = {
103 .getsda = parport_getsda, 103 .getsda = parport_getsda,
104 .getscl = parport_getscl, 104 .getscl = parport_getscl,
105 .udelay = 50, 105 .udelay = 50,
106 .mdelay = 50,
107 .timeout = HZ, 106 .timeout = HZ,
108}; 107};
109 108
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c
index 934bd55bae15..48a829431c7b 100644
--- a/drivers/i2c/busses/i2c-parport.c
+++ b/drivers/i2c/busses/i2c-parport.c
@@ -138,7 +138,6 @@ static struct i2c_algo_bit_data parport_algo_data = {
138 .getsda = parport_getsda, 138 .getsda = parport_getsda,
139 .getscl = parport_getscl, 139 .getscl = parport_getscl,
140 .udelay = 60, 140 .udelay = 60,
141 .mdelay = 60,
142 .timeout = HZ, 141 .timeout = HZ,
143}; 142};
144 143
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 8f2f65b793b9..30c7a1b38cbd 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -376,7 +376,7 @@ static u32 piix4_func(struct i2c_adapter *adapter)
376 I2C_FUNC_SMBUS_BLOCK_DATA; 376 I2C_FUNC_SMBUS_BLOCK_DATA;
377} 377}
378 378
379static struct i2c_algorithm smbus_algorithm = { 379static const struct i2c_algorithm smbus_algorithm = {
380 .smbus_xfer = piix4_access, 380 .smbus_xfer = piix4_access,
381 .functionality = piix4_func, 381 .functionality = piix4_func,
382}; 382};
diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c
index d658d9107955..a508cb962d24 100644
--- a/drivers/i2c/busses/i2c-powermac.c
+++ b/drivers/i2c/busses/i2c-powermac.c
@@ -175,7 +175,7 @@ static u32 i2c_powermac_func(struct i2c_adapter * adapter)
175} 175}
176 176
177/* For now, we only handle smbus */ 177/* For now, we only handle smbus */
178static struct i2c_algorithm i2c_powermac_algorithm = { 178static const struct i2c_algorithm i2c_powermac_algorithm = {
179 .smbus_xfer = i2c_powermac_smbus_xfer, 179 .smbus_xfer = i2c_powermac_smbus_xfer,
180 .master_xfer = i2c_powermac_master_xfer, 180 .master_xfer = i2c_powermac_master_xfer,
181 .functionality = i2c_powermac_func, 181 .functionality = i2c_powermac_func,
diff --git a/drivers/i2c/busses/i2c-prosavage.c b/drivers/i2c/busses/i2c-prosavage.c
index 9479525892e3..7745e21874a8 100644
--- a/drivers/i2c/busses/i2c-prosavage.c
+++ b/drivers/i2c/busses/i2c-prosavage.c
@@ -180,7 +180,6 @@ static int i2c_register_bus(struct pci_dev *dev, struct s_i2c_bus *p, void __iom
180 p->algo.getsda = bit_s3via_getsda; 180 p->algo.getsda = bit_s3via_getsda;
181 p->algo.getscl = bit_s3via_getscl; 181 p->algo.getscl = bit_s3via_getscl;
182 p->algo.udelay = CYCLE_DELAY; 182 p->algo.udelay = CYCLE_DELAY;
183 p->algo.mdelay = CYCLE_DELAY;
184 p->algo.timeout = TIMEOUT; 183 p->algo.timeout = TIMEOUT;
185 p->algo.data = p; 184 p->algo.data = p;
186 p->mmvga = mmvga; 185 p->mmvga = mmvga;
diff --git a/drivers/i2c/busses/i2c-pxa.c b/drivers/i2c/busses/i2c-pxa.c
index ee114b48face..cd4ad98ad517 100644
--- a/drivers/i2c/busses/i2c-pxa.c
+++ b/drivers/i2c/busses/i2c-pxa.c
@@ -926,7 +926,7 @@ static u32 i2c_pxa_functionality(struct i2c_adapter *adap)
926 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; 926 return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL;
927} 927}
928 928
929static struct i2c_algorithm i2c_pxa_algorithm = { 929static const struct i2c_algorithm i2c_pxa_algorithm = {
930 .master_xfer = i2c_pxa_xfer, 930 .master_xfer = i2c_pxa_xfer,
931 .functionality = i2c_pxa_functionality, 931 .functionality = i2c_pxa_functionality,
932}; 932};
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 5d2950e91fc5..9ebe429a0a0f 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -566,7 +566,7 @@ static u32 s3c24xx_i2c_func(struct i2c_adapter *adap)
566 566
567/* i2c bus registration info */ 567/* i2c bus registration info */
568 568
569static struct i2c_algorithm s3c24xx_i2c_algorithm = { 569static const struct i2c_algorithm s3c24xx_i2c_algorithm = {
570 .master_xfer = s3c24xx_i2c_xfer, 570 .master_xfer = s3c24xx_i2c_xfer,
571 .functionality = s3c24xx_i2c_func, 571 .functionality = s3c24xx_i2c_func,
572}; 572};
diff --git a/drivers/i2c/busses/i2c-savage4.c b/drivers/i2c/busses/i2c-savage4.c
index 0c8518298e4d..209f47ea1750 100644
--- a/drivers/i2c/busses/i2c-savage4.c
+++ b/drivers/i2c/busses/i2c-savage4.c
@@ -140,7 +140,6 @@ static struct i2c_algo_bit_data sav_i2c_bit_data = {
140 .getsda = bit_savi2c_getsda, 140 .getsda = bit_savi2c_getsda,
141 .getscl = bit_savi2c_getscl, 141 .getscl = bit_savi2c_getscl,
142 .udelay = CYCLE_DELAY, 142 .udelay = CYCLE_DELAY,
143 .mdelay = CYCLE_DELAY,
144 .timeout = TIMEOUT 143 .timeout = TIMEOUT
145}; 144};
146 145
diff --git a/drivers/i2c/busses/i2c-sibyte.c b/drivers/i2c/busses/i2c-sibyte.c
index fa503ed9f86d..8f2b1f0deb81 100644
--- a/drivers/i2c/busses/i2c-sibyte.c
+++ b/drivers/i2c/busses/i2c-sibyte.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * Copyright (C) 2004 Steven J. Hill 2 * Copyright (C) 2004 Steven J. Hill
3 * Copyright (C) 2001,2002,2003 Broadcom Corporation 3 * Copyright (C) 2001,2002,2003 Broadcom Corporation
4 * Copyright (C) 1995-2000 Simon G. Vogl
4 * 5 *
5 * This program is free software; you can redistribute it and/or 6 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License 7 * modify it under the terms of the GNU General Public License
@@ -17,11 +18,162 @@
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 */ 19 */
19 20
21#include <linux/kernel.h>
20#include <linux/module.h> 22#include <linux/module.h>
21#include <linux/i2c-algo-sibyte.h> 23#include <linux/init.h>
24#include <linux/i2c.h>
25#include <asm/io.h>
22#include <asm/sibyte/sb1250_regs.h> 26#include <asm/sibyte/sb1250_regs.h>
23#include <asm/sibyte/sb1250_smbus.h> 27#include <asm/sibyte/sb1250_smbus.h>
24 28
29
30struct i2c_algo_sibyte_data {
31 void *data; /* private data */
32 int bus; /* which bus */
33 void *reg_base; /* CSR base */
34};
35
36/* ----- global defines ----------------------------------------------- */
37#define SMB_CSR(a,r) ((long)(a->reg_base + r))
38
39/* ----- global variables --------------------------------------------- */
40
41/* module parameters:
42 */
43static int bit_scan; /* have a look at what's hanging 'round */
44module_param(bit_scan, int, 0);
45MODULE_PARM_DESC(bit_scan, "Scan for active chips on the bus");
46
47
48static int smbus_xfer(struct i2c_adapter *i2c_adap, u16 addr,
49 unsigned short flags, char read_write,
50 u8 command, int size, union i2c_smbus_data * data)
51{
52 struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
53 int data_bytes = 0;
54 int error;
55
56 while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY)
57 ;
58
59 switch (size) {
60 case I2C_SMBUS_QUICK:
61 csr_out32((V_SMB_ADDR(addr) |
62 (read_write == I2C_SMBUS_READ ? M_SMB_QDATA : 0) |
63 V_SMB_TT_QUICKCMD), SMB_CSR(adap, R_SMB_START));
64 break;
65 case I2C_SMBUS_BYTE:
66 if (read_write == I2C_SMBUS_READ) {
67 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_RD1BYTE),
68 SMB_CSR(adap, R_SMB_START));
69 data_bytes = 1;
70 } else {
71 csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
72 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR1BYTE),
73 SMB_CSR(adap, R_SMB_START));
74 }
75 break;
76 case I2C_SMBUS_BYTE_DATA:
77 csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
78 if (read_write == I2C_SMBUS_READ) {
79 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_CMD_RD1BYTE),
80 SMB_CSR(adap, R_SMB_START));
81 data_bytes = 1;
82 } else {
83 csr_out32(V_SMB_LB(data->byte),
84 SMB_CSR(adap, R_SMB_DATA));
85 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR2BYTE),
86 SMB_CSR(adap, R_SMB_START));
87 }
88 break;
89 case I2C_SMBUS_WORD_DATA:
90 csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
91 if (read_write == I2C_SMBUS_READ) {
92 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_CMD_RD2BYTE),
93 SMB_CSR(adap, R_SMB_START));
94 data_bytes = 2;
95 } else {
96 csr_out32(V_SMB_LB(data->word & 0xff),
97 SMB_CSR(adap, R_SMB_DATA));
98 csr_out32(V_SMB_MB(data->word >> 8),
99 SMB_CSR(adap, R_SMB_DATA));
100 csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR2BYTE),
101 SMB_CSR(adap, R_SMB_START));
102 }
103 break;
104 default:
105 return -1; /* XXXKW better error code? */
106 }
107
108 while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY)
109 ;
110
111 error = csr_in32(SMB_CSR(adap, R_SMB_STATUS));
112 if (error & M_SMB_ERROR) {
113 /* Clear error bit by writing a 1 */
114 csr_out32(M_SMB_ERROR, SMB_CSR(adap, R_SMB_STATUS));
115 return -1; /* XXXKW better error code? */
116 }
117
118 if (data_bytes == 1)
119 data->byte = csr_in32(SMB_CSR(adap, R_SMB_DATA)) & 0xff;
120 if (data_bytes == 2)
121 data->word = csr_in32(SMB_CSR(adap, R_SMB_DATA)) & 0xffff;
122
123 return 0;
124}
125
126static u32 bit_func(struct i2c_adapter *adap)
127{
128 return (I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
129 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA);
130}
131
132
133/* -----exported algorithm data: ------------------------------------- */
134
135static const struct i2c_algorithm i2c_sibyte_algo = {
136 .smbus_xfer = smbus_xfer,
137 .functionality = bit_func,
138};
139
140/*
141 * registering functions to load algorithms at runtime
142 */
143int i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed)
144{
145 int i;
146 struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
147
148 /* register new adapter to i2c module... */
149 i2c_adap->algo = &i2c_sibyte_algo;
150
151 /* Set the frequency to 100 kHz */
152 csr_out32(speed, SMB_CSR(adap,R_SMB_FREQ));
153 csr_out32(0, SMB_CSR(adap,R_SMB_CONTROL));
154
155 /* scan bus */
156 if (bit_scan) {
157 union i2c_smbus_data data;
158 int rc;
159 printk(KERN_INFO " i2c-algo-sibyte.o: scanning bus %s.\n",
160 i2c_adap->name);
161 for (i = 0x00; i < 0x7f; i++) {
162 /* XXXKW is this a realistic probe? */
163 rc = smbus_xfer(i2c_adap, i, 0, I2C_SMBUS_READ, 0,
164 I2C_SMBUS_BYTE_DATA, &data);
165 if (!rc) {
166 printk("(%02x)",i);
167 } else
168 printk(".");
169 }
170 printk("\n");
171 }
172
173 return i2c_add_adapter(i2c_adap);
174}
175
176
25static struct i2c_algo_sibyte_data sibyte_board_data[2] = { 177static struct i2c_algo_sibyte_data sibyte_board_data[2] = {
26 { NULL, 0, (void *) (CKSEG1+A_SMB_BASE(0)) }, 178 { NULL, 0, (void *) (CKSEG1+A_SMB_BASE(0)) },
27 { NULL, 1, (void *) (CKSEG1+A_SMB_BASE(1)) } 179 { NULL, 1, (void *) (CKSEG1+A_SMB_BASE(1)) }
@@ -58,13 +210,13 @@ static int __init i2c_sibyte_init(void)
58 210
59static void __exit i2c_sibyte_exit(void) 211static void __exit i2c_sibyte_exit(void)
60{ 212{
61 i2c_sibyte_del_bus(&sibyte_board_adapter[0]); 213 i2c_del_bus(&sibyte_board_adapter[0]);
62 i2c_sibyte_del_bus(&sibyte_board_adapter[1]); 214 i2c_del_bus(&sibyte_board_adapter[1]);
63} 215}
64 216
65module_init(i2c_sibyte_init); 217module_init(i2c_sibyte_init);
66module_exit(i2c_sibyte_exit); 218module_exit(i2c_sibyte_exit);
67 219
68MODULE_AUTHOR("Kip Walker <kwalker@broadcom.com>, Steven J. Hill <sjhill@realitydiluted.com>"); 220MODULE_AUTHOR("Kip Walker (Broadcom Corp.), Steven J. Hill <sjhill@realitydiluted.com>");
69MODULE_DESCRIPTION("SMBus adapter routines for SiByte boards"); 221MODULE_DESCRIPTION("SMBus adapter routines for SiByte boards");
70MODULE_LICENSE("GPL"); 222MODULE_LICENSE("GPL");
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index b57ab74d23ec..38bbfd840b6b 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -358,7 +358,7 @@ static u32 sis5595_func(struct i2c_adapter *adapter)
358 I2C_FUNC_SMBUS_PROC_CALL; 358 I2C_FUNC_SMBUS_PROC_CALL;
359} 359}
360 360
361static struct i2c_algorithm smbus_algorithm = { 361static const struct i2c_algorithm smbus_algorithm = {
362 .smbus_xfer = sis5595_access, 362 .smbus_xfer = sis5595_access,
363 .functionality = sis5595_func, 363 .functionality = sis5595_func,
364}; 364};
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c
index acb75e282414..dec0bafb52ab 100644
--- a/drivers/i2c/busses/i2c-sis630.c
+++ b/drivers/i2c/busses/i2c-sis630.c
@@ -450,7 +450,7 @@ exit:
450} 450}
451 451
452 452
453static struct i2c_algorithm smbus_algorithm = { 453static const struct i2c_algorithm smbus_algorithm = {
454 .smbus_xfer = sis630_access, 454 .smbus_xfer = sis630_access,
455 .functionality = sis630_func, 455 .functionality = sis630_func,
456}; 456};
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index 1a73c0532fc7..7fd07fbac336 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -242,7 +242,7 @@ static u32 sis96x_func(struct i2c_adapter *adapter)
242 I2C_FUNC_SMBUS_PROC_CALL; 242 I2C_FUNC_SMBUS_PROC_CALL;
243} 243}
244 244
245static struct i2c_algorithm smbus_algorithm = { 245static const struct i2c_algorithm smbus_algorithm = {
246 .smbus_xfer = sis96x_access, 246 .smbus_xfer = sis96x_access,
247 .functionality = sis96x_func, 247 .functionality = sis96x_func,
248}; 248};
diff --git a/drivers/i2c/busses/i2c-stub.c b/drivers/i2c/busses/i2c-stub.c
index 73f481e93a36..a54adc50d162 100644
--- a/drivers/i2c/busses/i2c-stub.c
+++ b/drivers/i2c/busses/i2c-stub.c
@@ -27,6 +27,10 @@
27#include <linux/errno.h> 27#include <linux/errno.h>
28#include <linux/i2c.h> 28#include <linux/i2c.h>
29 29
30static unsigned short chip_addr;
31module_param(chip_addr, ushort, S_IRUGO);
32MODULE_PARM_DESC(chip_addr, "Chip address (between 0x03 and 0x77)\n");
33
30static u8 stub_pointer; 34static u8 stub_pointer;
31static u8 stub_bytes[256]; 35static u8 stub_bytes[256];
32static u16 stub_words[256]; 36static u16 stub_words[256];
@@ -37,6 +41,9 @@ static s32 stub_xfer(struct i2c_adapter * adap, u16 addr, unsigned short flags,
37{ 41{
38 s32 ret; 42 s32 ret;
39 43
44 if (addr != chip_addr)
45 return -ENODEV;
46
40 switch (size) { 47 switch (size) {
41 48
42 case I2C_SMBUS_QUICK: 49 case I2C_SMBUS_QUICK:
@@ -108,7 +115,7 @@ static u32 stub_func(struct i2c_adapter *adapter)
108 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA; 115 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA;
109} 116}
110 117
111static struct i2c_algorithm smbus_algorithm = { 118static const struct i2c_algorithm smbus_algorithm = {
112 .functionality = stub_func, 119 .functionality = stub_func,
113 .smbus_xfer = stub_xfer, 120 .smbus_xfer = stub_xfer,
114}; 121};
@@ -122,7 +129,17 @@ static struct i2c_adapter stub_adapter = {
122 129
123static int __init i2c_stub_init(void) 130static int __init i2c_stub_init(void)
124{ 131{
125 printk(KERN_INFO "i2c-stub loaded\n"); 132 if (!chip_addr) {
133 printk(KERN_ERR "i2c-stub: Please specify a chip address\n");
134 return -ENODEV;
135 }
136 if (chip_addr < 0x03 || chip_addr > 0x77) {
137 printk(KERN_ERR "i2c-stub: Invalid chip address 0x%02x\n",
138 chip_addr);
139 return -EINVAL;
140 }
141
142 printk(KERN_INFO "i2c-stub: Virtual chip at 0x%02x\n", chip_addr);
126 return i2c_add_adapter(&stub_adapter); 143 return i2c_add_adapter(&stub_adapter);
127} 144}
128 145
diff --git a/drivers/i2c/busses/i2c-via.c b/drivers/i2c/busses/i2c-via.c
index 484bbacfce6b..910e200ad500 100644
--- a/drivers/i2c/busses/i2c-via.c
+++ b/drivers/i2c/busses/i2c-via.c
@@ -81,7 +81,6 @@ static struct i2c_algo_bit_data bit_data = {
81 .getsda = bit_via_getsda, 81 .getsda = bit_via_getsda,
82 .getscl = bit_via_getscl, 82 .getscl = bit_via_getscl,
83 .udelay = 5, 83 .udelay = 5,
84 .mdelay = 5,
85 .timeout = HZ 84 .timeout = HZ
86}; 85};
87 86
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 47e52bf2c5ec..efc6bbf0cc0a 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -34,6 +34,8 @@
34 VT8233A 0x3147 yes? 34 VT8233A 0x3147 yes?
35 VT8235 0x3177 yes 35 VT8235 0x3177 yes
36 VT8237R 0x3227 yes 36 VT8237R 0x3227 yes
37 VT8237A 0x3337 yes
38 VT8251 0x3287 yes
37 39
38 Note: we assume there can only be one device, with one SMBus interface. 40 Note: we assume there can only be one device, with one SMBus interface.
39*/ 41*/
@@ -297,7 +299,7 @@ static u32 vt596_func(struct i2c_adapter *adapter)
297 return func; 299 return func;
298} 300}
299 301
300static struct i2c_algorithm smbus_algorithm = { 302static const struct i2c_algorithm smbus_algorithm = {
301 .smbus_xfer = vt596_access, 303 .smbus_xfer = vt596_access,
302 .functionality = vt596_func, 304 .functionality = vt596_func,
303}; 305};
@@ -381,7 +383,9 @@ found:
381 dev_dbg(&pdev->dev, "VT596_smba = 0x%X\n", vt596_smba); 383 dev_dbg(&pdev->dev, "VT596_smba = 0x%X\n", vt596_smba);
382 384
383 switch (pdev->device) { 385 switch (pdev->device) {
386 case PCI_DEVICE_ID_VIA_8251:
384 case PCI_DEVICE_ID_VIA_8237: 387 case PCI_DEVICE_ID_VIA_8237:
388 case PCI_DEVICE_ID_VIA_8237A:
385 case PCI_DEVICE_ID_VIA_8235: 389 case PCI_DEVICE_ID_VIA_8235:
386 case PCI_DEVICE_ID_VIA_8233A: 390 case PCI_DEVICE_ID_VIA_8233A:
387 case PCI_DEVICE_ID_VIA_8233_0: 391 case PCI_DEVICE_ID_VIA_8233_0:
@@ -432,8 +436,12 @@ static struct pci_device_id vt596_ids[] = {
432 .driver_data = SMBBA3 }, 436 .driver_data = SMBBA3 },
433 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237), 437 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237),
434 .driver_data = SMBBA3 }, 438 .driver_data = SMBBA3 },
439 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237A),
440 .driver_data = SMBBA3 },
435 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4), 441 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4),
436 .driver_data = SMBBA1 }, 442 .driver_data = SMBBA1 },
443 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8251),
444 .driver_data = SMBBA3 },
437 { 0, } 445 { 0, }
438}; 446};
439 447
diff --git a/drivers/i2c/busses/i2c-voodoo3.c b/drivers/i2c/busses/i2c-voodoo3.c
index b675773b0cc1..6c8d25183382 100644
--- a/drivers/i2c/busses/i2c-voodoo3.c
+++ b/drivers/i2c/busses/i2c-voodoo3.c
@@ -160,7 +160,6 @@ static struct i2c_algo_bit_data voo_i2c_bit_data = {
160 .getsda = bit_vooi2c_getsda, 160 .getsda = bit_vooi2c_getsda,
161 .getscl = bit_vooi2c_getscl, 161 .getscl = bit_vooi2c_getscl,
162 .udelay = CYCLE_DELAY, 162 .udelay = CYCLE_DELAY,
163 .mdelay = CYCLE_DELAY,
164 .timeout = TIMEOUT 163 .timeout = TIMEOUT
165}; 164};
166 165
@@ -177,7 +176,6 @@ static struct i2c_algo_bit_data voo_ddc_bit_data = {
177 .getsda = bit_vooddc_getsda, 176 .getsda = bit_vooddc_getsda,
178 .getscl = bit_vooddc_getscl, 177 .getscl = bit_vooddc_getscl,
179 .udelay = CYCLE_DELAY, 178 .udelay = CYCLE_DELAY,
180 .mdelay = CYCLE_DELAY,
181 .timeout = TIMEOUT 179 .timeout = TIMEOUT
182}; 180};
183 181
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index eae9e81be375..32aab0d34ee9 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -383,7 +383,7 @@ static u32 scx200_acb_func(struct i2c_adapter *adapter)
383} 383}
384 384
385/* For now, we only handle combined mode (smbus) */ 385/* For now, we only handle combined mode (smbus) */
386static struct i2c_algorithm scx200_acb_algorithm = { 386static const struct i2c_algorithm scx200_acb_algorithm = {
387 .smbus_xfer = scx200_acb_smbus_xfer, 387 .smbus_xfer = scx200_acb_smbus_xfer,
388 .functionality = scx200_acb_func, 388 .functionality = scx200_acb_func,
389}; 389};
diff --git a/drivers/i2c/busses/scx200_i2c.c b/drivers/i2c/busses/scx200_i2c.c
index cb3ef5ac99fd..8b65a5cf8251 100644
--- a/drivers/i2c/busses/scx200_i2c.c
+++ b/drivers/i2c/busses/scx200_i2c.c
@@ -71,12 +71,12 @@ static int scx200_i2c_getsda(void *data)
71 */ 71 */
72 72
73static struct i2c_algo_bit_data scx200_i2c_data = { 73static struct i2c_algo_bit_data scx200_i2c_data = {
74 NULL, 74 .setsda = scx200_i2c_setsda,
75 scx200_i2c_setsda, 75 .setscl = scx200_i2c_setscl,
76 scx200_i2c_setscl, 76 .getsda = scx200_i2c_getsda,
77 scx200_i2c_getsda, 77 .getscl = scx200_i2c_getscl,
78 scx200_i2c_getscl, 78 .udelay = 10,
79 10, 10, 100, /* waits, timeout */ 79 .timeout = 100,
80}; 80};
81 81
82static struct i2c_adapter scx200_i2c_ops = { 82static struct i2c_adapter scx200_i2c_ops = {