aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/i2c')
-rw-r--r--drivers/i2c/algos/i2c-algo-pca.c2
-rw-r--r--drivers/i2c/algos/i2c-algo-sibyte.c2
-rw-r--r--drivers/i2c/busses/Kconfig3
-rw-r--r--drivers/i2c/busses/i2c-ali1535.c7
-rw-r--r--drivers/i2c/busses/i2c-ali1563.c7
-rw-r--r--drivers/i2c/busses/i2c-ali15x3.c10
-rw-r--r--drivers/i2c/busses/i2c-amd756-s4882.c4
-rw-r--r--drivers/i2c/busses/i2c-amd756.c8
-rw-r--r--drivers/i2c/busses/i2c-amd8111.c16
-rw-r--r--drivers/i2c/busses/i2c-elektor.c138
-rw-r--r--drivers/i2c/busses/i2c-hydra.c1
-rw-r--r--drivers/i2c/busses/i2c-i801.c61
-rw-r--r--drivers/i2c/busses/i2c-i810.c2
-rw-r--r--drivers/i2c/busses/i2c-ibm_iic.c3
-rw-r--r--drivers/i2c/busses/i2c-iop3xx.c9
-rw-r--r--drivers/i2c/busses/i2c-isa.c1
-rw-r--r--drivers/i2c/busses/i2c-ixp2000.c8
-rw-r--r--drivers/i2c/busses/i2c-ixp4xx.c8
-rw-r--r--drivers/i2c/busses/i2c-keywest.c5
-rw-r--r--drivers/i2c/busses/i2c-mpc.c4
-rw-r--r--drivers/i2c/busses/i2c-mv64xxx.c6
-rw-r--r--drivers/i2c/busses/i2c-nforce2.c16
-rw-r--r--drivers/i2c/busses/i2c-parport.c11
-rw-r--r--drivers/i2c/busses/i2c-piix4.c13
-rw-r--r--drivers/i2c/busses/i2c-pmac-smu.c3
-rw-r--r--drivers/i2c/busses/i2c-prosavage.c10
-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-sis5595.c10
-rw-r--r--drivers/i2c/busses/i2c-sis630.c9
-rw-r--r--drivers/i2c/busses/i2c-sis96x.c8
-rw-r--r--drivers/i2c/busses/i2c-via.c7
-rw-r--r--drivers/i2c/busses/i2c-viapro.c271
-rw-r--r--drivers/i2c/busses/i2c-voodoo3.c1
-rw-r--r--drivers/i2c/busses/scx200_acb.c3
-rw-r--r--drivers/i2c/chips/Kconfig9
-rw-r--r--drivers/i2c/chips/Makefile1
-rw-r--r--drivers/i2c/chips/ds1337.c3
-rw-r--r--drivers/i2c/chips/ds1374.c7
-rw-r--r--drivers/i2c/chips/eeprom.c9
-rw-r--r--drivers/i2c/chips/isp1301_omap.c1
-rw-r--r--drivers/i2c/chips/m41t00.c4
-rw-r--r--drivers/i2c/chips/max6875.c6
-rw-r--r--drivers/i2c/chips/pca9539.c3
-rw-r--r--drivers/i2c/chips/pcf8574.c5
-rw-r--r--drivers/i2c/chips/pcf8591.c5
-rw-r--r--drivers/i2c/chips/rtc8564.c5
-rw-r--r--drivers/i2c/chips/tps65010.c3
-rw-r--r--drivers/i2c/chips/x1205.c698
-rw-r--r--drivers/i2c/i2c-core.c194
-rw-r--r--drivers/i2c/i2c-dev.c17
51 files changed, 1149 insertions, 491 deletions
diff --git a/drivers/i2c/algos/i2c-algo-pca.c b/drivers/i2c/algos/i2c-algo-pca.c
index beb10edfe9c1..82946acab4c7 100644
--- a/drivers/i2c/algos/i2c-algo-pca.c
+++ b/drivers/i2c/algos/i2c-algo-pca.c
@@ -34,7 +34,7 @@
34#define DEB2(fmt, args...) do { if (i2c_debug>=2) printk(fmt, ## args); } while(0) 34#define DEB2(fmt, args...) do { if (i2c_debug>=2) printk(fmt, ## args); } while(0)
35#define DEB3(fmt, args...) do { if (i2c_debug>=3) printk(fmt, ## args); } while(0) 35#define DEB3(fmt, args...) do { if (i2c_debug>=3) printk(fmt, ## args); } while(0)
36 36
37static int i2c_debug=0; 37static int i2c_debug;
38 38
39#define pca_outw(adap, reg, val) adap->write_byte(adap, reg, val) 39#define pca_outw(adap, reg, val) adap->write_byte(adap, reg, val)
40#define pca_inw(adap, reg) adap->read_byte(adap, reg) 40#define pca_inw(adap, reg) adap->read_byte(adap, reg)
diff --git a/drivers/i2c/algos/i2c-algo-sibyte.c b/drivers/i2c/algos/i2c-algo-sibyte.c
index 8ed5ad12552f..938848ae162d 100644
--- a/drivers/i2c/algos/i2c-algo-sibyte.c
+++ b/drivers/i2c/algos/i2c-algo-sibyte.c
@@ -42,7 +42,7 @@
42 42
43/* module parameters: 43/* module parameters:
44 */ 44 */
45static int bit_scan=0; /* have a look at what's hanging 'round */ 45static int bit_scan; /* have a look at what's hanging 'round */
46 46
47 47
48static int smbus_xfer(struct i2c_adapter *i2c_adap, u16 addr, 48static int smbus_xfer(struct i2c_adapter *i2c_adap, u16 addr,
diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
index 3badfec75b1c..4010fe92e72b 100644
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -135,11 +135,12 @@ config I2C_I810
135 help 135 help
136 If you say yes to this option, support will be included for the Intel 136 If you say yes to this option, support will be included for the Intel
137 810/815 family of mainboard I2C interfaces. Specifically, the 137 810/815 family of mainboard I2C interfaces. Specifically, the
138 following versions of the chipset is supported: 138 following versions of the chipset are supported:
139 i810AA 139 i810AA
140 i810AB 140 i810AB
141 i810E 141 i810E
142 i815 142 i815
143 i845G
143 144
144 This driver can also be built as a module. If so, the module 145 This driver can also be built as a module. If so, the module
145 will be called i2c-i810. 146 will be called i2c-i810.
diff --git a/drivers/i2c/busses/i2c-ali1535.c b/drivers/i2c/busses/i2c-ali1535.c
index f021acd2674e..ba90f5140af6 100644
--- a/drivers/i2c/busses/i2c-ali1535.c
+++ b/drivers/i2c/busses/i2c-ali1535.c
@@ -134,7 +134,7 @@
134 /* -> Read = 1 */ 134 /* -> Read = 1 */
135#define ALI1535_SMBIO_EN 0x04 /* SMB I/O Space enable */ 135#define ALI1535_SMBIO_EN 0x04 /* SMB I/O Space enable */
136 136
137 137static struct pci_driver ali1535_driver;
138static unsigned short ali1535_smba; 138static unsigned short ali1535_smba;
139static DECLARE_MUTEX(i2c_ali1535_sem); 139static DECLARE_MUTEX(i2c_ali1535_sem);
140 140
@@ -162,7 +162,8 @@ static int ali1535_setup(struct pci_dev *dev)
162 goto exit; 162 goto exit;
163 } 163 }
164 164
165 if (!request_region(ali1535_smba, ALI1535_SMB_IOSIZE, "ali1535-smb")) { 165 if (!request_region(ali1535_smba, ALI1535_SMB_IOSIZE,
166 ali1535_driver.name)) {
166 dev_err(&dev->dev, "ALI1535_smb region 0x%x already in use!\n", 167 dev_err(&dev->dev, "ALI1535_smb region 0x%x already in use!\n",
167 ali1535_smba); 168 ali1535_smba);
168 goto exit; 169 goto exit;
@@ -480,7 +481,6 @@ static struct i2c_adapter ali1535_adapter = {
480 .owner = THIS_MODULE, 481 .owner = THIS_MODULE,
481 .class = I2C_CLASS_HWMON, 482 .class = I2C_CLASS_HWMON,
482 .algo = &smbus_algorithm, 483 .algo = &smbus_algorithm,
483 .name = "unset",
484}; 484};
485 485
486static struct pci_device_id ali1535_ids[] = { 486static struct pci_device_id ali1535_ids[] = {
@@ -513,6 +513,7 @@ static void __devexit ali1535_remove(struct pci_dev *dev)
513} 513}
514 514
515static struct pci_driver ali1535_driver = { 515static struct pci_driver ali1535_driver = {
516 .owner = THIS_MODULE,
516 .name = "ali1535_smbus", 517 .name = "ali1535_smbus",
517 .id_table = ali1535_ids, 518 .id_table = ali1535_ids,
518 .probe = ali1535_probe, 519 .probe = ali1535_probe,
diff --git a/drivers/i2c/busses/i2c-ali1563.c b/drivers/i2c/busses/i2c-ali1563.c
index 86947504aea1..f1a62d892425 100644
--- a/drivers/i2c/busses/i2c-ali1563.c
+++ b/drivers/i2c/busses/i2c-ali1563.c
@@ -60,6 +60,7 @@
60 60
61#define HST_CNTL2_SIZEMASK 0x38 61#define HST_CNTL2_SIZEMASK 0x38
62 62
63static struct pci_driver ali1563_pci_driver;
63static unsigned short ali1563_smba; 64static unsigned short ali1563_smba;
64 65
65static int ali1563_transaction(struct i2c_adapter * a, int size) 66static int ali1563_transaction(struct i2c_adapter * a, int size)
@@ -350,7 +351,8 @@ static int __devinit ali1563_setup(struct pci_dev * dev)
350 dev_warn(&dev->dev,"ali1563_smba Uninitialized\n"); 351 dev_warn(&dev->dev,"ali1563_smba Uninitialized\n");
351 goto Err; 352 goto Err;
352 } 353 }
353 if (!request_region(ali1563_smba,ALI1563_SMB_IOSIZE,"i2c-ali1563")) { 354 if (!request_region(ali1563_smba, ALI1563_SMB_IOSIZE,
355 ali1563_pci_driver.name)) {
354 dev_warn(&dev->dev,"Could not allocate I/O space"); 356 dev_warn(&dev->dev,"Could not allocate I/O space");
355 goto Err; 357 goto Err;
356 } 358 }
@@ -406,7 +408,8 @@ static struct pci_device_id __devinitdata ali1563_id_table[] = {
406MODULE_DEVICE_TABLE (pci, ali1563_id_table); 408MODULE_DEVICE_TABLE (pci, ali1563_id_table);
407 409
408static struct pci_driver ali1563_pci_driver = { 410static struct pci_driver ali1563_pci_driver = {
409 .name = "ali1563_i2c", 411 .owner = THIS_MODULE,
412 .name = "ali1563_smbus",
410 .id_table = ali1563_id_table, 413 .id_table = ali1563_id_table,
411 .probe = ali1563_probe, 414 .probe = ali1563_probe,
412 .remove = __devexit_p(ali1563_remove), 415 .remove = __devexit_p(ali1563_remove),
diff --git a/drivers/i2c/busses/i2c-ali15x3.c b/drivers/i2c/busses/i2c-ali15x3.c
index b3f50bff39a0..400b08ed4299 100644
--- a/drivers/i2c/busses/i2c-ali15x3.c
+++ b/drivers/i2c/busses/i2c-ali15x3.c
@@ -125,12 +125,13 @@
125 125
126/* If force_addr is set to anything different from 0, we forcibly enable 126/* If force_addr is set to anything different from 0, we forcibly enable
127 the device at the given address. */ 127 the device at the given address. */
128static u16 force_addr = 0; 128static u16 force_addr;
129module_param(force_addr, ushort, 0); 129module_param(force_addr, ushort, 0);
130MODULE_PARM_DESC(force_addr, 130MODULE_PARM_DESC(force_addr,
131 "Initialize the base address of the i2c controller"); 131 "Initialize the base address of the i2c controller");
132 132
133static unsigned short ali15x3_smba = 0; 133static struct pci_driver ali15x3_driver;
134static unsigned short ali15x3_smba;
134 135
135static int ali15x3_setup(struct pci_dev *ALI15X3_dev) 136static int ali15x3_setup(struct pci_dev *ALI15X3_dev)
136{ 137{
@@ -166,7 +167,8 @@ static int ali15x3_setup(struct pci_dev *ALI15X3_dev)
166 if(force_addr) 167 if(force_addr)
167 ali15x3_smba = force_addr & ~(ALI15X3_SMB_IOSIZE - 1); 168 ali15x3_smba = force_addr & ~(ALI15X3_SMB_IOSIZE - 1);
168 169
169 if (!request_region(ali15x3_smba, ALI15X3_SMB_IOSIZE, "ali15x3-smb")) { 170 if (!request_region(ali15x3_smba, ALI15X3_SMB_IOSIZE,
171 ali15x3_driver.name)) {
170 dev_err(&ALI15X3_dev->dev, 172 dev_err(&ALI15X3_dev->dev,
171 "ALI15X3_smb region 0x%x already in use!\n", 173 "ALI15X3_smb region 0x%x already in use!\n",
172 ali15x3_smba); 174 ali15x3_smba);
@@ -470,7 +472,6 @@ static struct i2c_adapter ali15x3_adapter = {
470 .owner = THIS_MODULE, 472 .owner = THIS_MODULE,
471 .class = I2C_CLASS_HWMON, 473 .class = I2C_CLASS_HWMON,
472 .algo = &smbus_algorithm, 474 .algo = &smbus_algorithm,
473 .name = "unset",
474}; 475};
475 476
476static struct pci_device_id ali15x3_ids[] = { 477static struct pci_device_id ali15x3_ids[] = {
@@ -503,6 +504,7 @@ static void __devexit ali15x3_remove(struct pci_dev *dev)
503} 504}
504 505
505static struct pci_driver ali15x3_driver = { 506static struct pci_driver ali15x3_driver = {
507 .owner = THIS_MODULE,
506 .name = "ali15x3_smbus", 508 .name = "ali15x3_smbus",
507 .id_table = ali15x3_ids, 509 .id_table = ali15x3_ids,
508 .probe = ali15x3_probe, 510 .probe = ali15x3_probe,
diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
index 4e553e8c5cba..f51ab652300a 100644
--- a/drivers/i2c/busses/i2c-amd756-s4882.c
+++ b/drivers/i2c/busses/i2c-amd756-s4882.c
@@ -169,12 +169,12 @@ static int __init amd756_s4882_init(void)
169 init_MUTEX(&amd756_lock); 169 init_MUTEX(&amd756_lock);
170 170
171 /* Define the 5 virtual adapters and algorithms structures */ 171 /* Define the 5 virtual adapters and algorithms structures */
172 if (!(s4882_adapter = kmalloc(5 * sizeof(struct i2c_adapter), 172 if (!(s4882_adapter = kzalloc(5 * sizeof(struct i2c_adapter),
173 GFP_KERNEL))) { 173 GFP_KERNEL))) {
174 error = -ENOMEM; 174 error = -ENOMEM;
175 goto ERROR1; 175 goto ERROR1;
176 } 176 }
177 if (!(s4882_algo = kmalloc(5 * sizeof(struct i2c_algorithm), 177 if (!(s4882_algo = kzalloc(5 * sizeof(struct i2c_algorithm),
178 GFP_KERNEL))) { 178 GFP_KERNEL))) {
179 error = -ENOMEM; 179 error = -ENOMEM;
180 goto ERROR2; 180 goto ERROR2;
diff --git a/drivers/i2c/busses/i2c-amd756.c b/drivers/i2c/busses/i2c-amd756.c
index 6ad0603384b8..de035d137c3f 100644
--- a/drivers/i2c/busses/i2c-amd756.c
+++ b/drivers/i2c/busses/i2c-amd756.c
@@ -85,8 +85,8 @@
85#define AMD756_PROCESS_CALL 0x04 85#define AMD756_PROCESS_CALL 0x04
86#define AMD756_BLOCK_DATA 0x05 86#define AMD756_BLOCK_DATA 0x05
87 87
88 88static struct pci_driver amd756_driver;
89static unsigned short amd756_ioport = 0; 89static unsigned short amd756_ioport;
90 90
91/* 91/*
92 SMBUS event = I/O 28-29 bit 11 92 SMBUS event = I/O 28-29 bit 11
@@ -303,7 +303,6 @@ struct i2c_adapter amd756_smbus = {
303 .owner = THIS_MODULE, 303 .owner = THIS_MODULE,
304 .class = I2C_CLASS_HWMON, 304 .class = I2C_CLASS_HWMON,
305 .algo = &smbus_algorithm, 305 .algo = &smbus_algorithm,
306 .name = "unset",
307}; 306};
308 307
309enum chiptype { AMD756, AMD766, AMD768, NFORCE, AMD8111 }; 308enum chiptype { AMD756, AMD766, AMD768, NFORCE, AMD8111 };
@@ -365,7 +364,7 @@ static int __devinit amd756_probe(struct pci_dev *pdev,
365 amd756_ioport += SMB_ADDR_OFFSET; 364 amd756_ioport += SMB_ADDR_OFFSET;
366 } 365 }
367 366
368 if (!request_region(amd756_ioport, SMB_IOSIZE, "amd756-smbus")) { 367 if (!request_region(amd756_ioport, SMB_IOSIZE, amd756_driver.name)) {
369 dev_err(&pdev->dev, "SMB region 0x%x already in use!\n", 368 dev_err(&pdev->dev, "SMB region 0x%x already in use!\n",
370 amd756_ioport); 369 amd756_ioport);
371 return -ENODEV; 370 return -ENODEV;
@@ -402,6 +401,7 @@ static void __devexit amd756_remove(struct pci_dev *dev)
402} 401}
403 402
404static struct pci_driver amd756_driver = { 403static struct pci_driver amd756_driver = {
404 .owner = THIS_MODULE,
405 .name = "amd756_smbus", 405 .name = "amd756_smbus",
406 .id_table = amd756_ids, 406 .id_table = amd756_ids,
407 .probe = amd756_probe, 407 .probe = amd756_probe,
diff --git a/drivers/i2c/busses/i2c-amd8111.c b/drivers/i2c/busses/i2c-amd8111.c
index 45ea24ba14d5..f3b79a68dbec 100644
--- a/drivers/i2c/busses/i2c-amd8111.c
+++ b/drivers/i2c/busses/i2c-amd8111.c
@@ -30,6 +30,8 @@ struct amd_smbus {
30 int size; 30 int size;
31}; 31};
32 32
33static struct pci_driver amd8111_driver;
34
33/* 35/*
34 * AMD PCI control registers definitions. 36 * AMD PCI control registers definitions.
35 */ 37 */
@@ -242,7 +244,6 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, unsigned short fl
242 break; 244 break;
243 245
244 case I2C_SMBUS_BLOCK_PROC_CALL: 246 case I2C_SMBUS_BLOCK_PROC_CALL:
245 protocol |= pec;
246 len = min_t(u8, data->block[0], 31); 247 len = min_t(u8, data->block[0], 31);
247 amd_ec_write(smbus, AMD_SMB_CMD, command); 248 amd_ec_write(smbus, AMD_SMB_CMD, command);
248 amd_ec_write(smbus, AMD_SMB_BCNT, len); 249 amd_ec_write(smbus, AMD_SMB_BCNT, len);
@@ -252,13 +253,6 @@ static s32 amd8111_access(struct i2c_adapter * adap, u16 addr, unsigned short fl
252 read_write = I2C_SMBUS_READ; 253 read_write = I2C_SMBUS_READ;
253 break; 254 break;
254 255
255 case I2C_SMBUS_WORD_DATA_PEC:
256 case I2C_SMBUS_BLOCK_DATA_PEC:
257 case I2C_SMBUS_PROC_CALL_PEC:
258 case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
259 dev_warn(&adap->dev, "Unexpected software PEC transaction %d\n.", size);
260 return -1;
261
262 default: 256 default:
263 dev_warn(&adap->dev, "Unsupported transaction %d\n", size); 257 dev_warn(&adap->dev, "Unsupported transaction %d\n", size);
264 return -1; 258 return -1;
@@ -343,16 +337,15 @@ static int __devinit amd8111_probe(struct pci_dev *dev, const struct pci_device_
343 if (~pci_resource_flags(dev, 0) & IORESOURCE_IO) 337 if (~pci_resource_flags(dev, 0) & IORESOURCE_IO)
344 return -ENODEV; 338 return -ENODEV;
345 339
346 smbus = kmalloc(sizeof(struct amd_smbus), GFP_KERNEL); 340 smbus = kzalloc(sizeof(struct amd_smbus), GFP_KERNEL);
347 if (!smbus) 341 if (!smbus)
348 return -ENOMEM; 342 return -ENOMEM;
349 memset(smbus, 0, sizeof(struct amd_smbus));
350 343
351 smbus->dev = dev; 344 smbus->dev = dev;
352 smbus->base = pci_resource_start(dev, 0); 345 smbus->base = pci_resource_start(dev, 0);
353 smbus->size = pci_resource_len(dev, 0); 346 smbus->size = pci_resource_len(dev, 0);
354 347
355 if (!request_region(smbus->base, smbus->size, "amd8111 SMBus 2.0")) 348 if (!request_region(smbus->base, smbus->size, amd8111_driver.name))
356 goto out_kfree; 349 goto out_kfree;
357 350
358 smbus->adapter.owner = THIS_MODULE; 351 smbus->adapter.owner = THIS_MODULE;
@@ -391,6 +384,7 @@ static void __devexit amd8111_remove(struct pci_dev *dev)
391} 384}
392 385
393static struct pci_driver amd8111_driver = { 386static struct pci_driver amd8111_driver = {
387 .owner = THIS_MODULE,
394 .name = "amd8111_smbus2", 388 .name = "amd8111_smbus2",
395 .id_table = amd8111_ids, 389 .id_table = amd8111_ids,
396 .probe = amd8111_probe, 390 .probe = amd8111_probe,
diff --git a/drivers/i2c/busses/i2c-elektor.c b/drivers/i2c/busses/i2c-elektor.c
index 6930b660e508..59f8308c2356 100644
--- a/drivers/i2c/busses/i2c-elektor.c
+++ b/drivers/i2c/busses/i2c-elektor.c
@@ -22,7 +22,7 @@
22/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even 22/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi> and even
23 Frodo Looijaard <frodol@dds.nl> */ 23 Frodo Looijaard <frodol@dds.nl> */
24 24
25/* Partialy rewriten by Oleg I. Vdovikin for mmapped support of 25/* Partialy rewriten by Oleg I. Vdovikin for mmapped support of
26 for Alpha Processor Inc. UP-2000(+) boards */ 26 for Alpha Processor Inc. UP-2000(+) boards */
27 27
28#include <linux/kernel.h> 28#include <linux/kernel.h>
@@ -46,12 +46,14 @@
46#define DEFAULT_BASE 0x330 46#define DEFAULT_BASE 0x330
47 47
48static int base; 48static int base;
49static u8 __iomem *base_iomem;
50
49static int irq; 51static int irq;
50static int clock = 0x1c; 52static int clock = 0x1c;
51static int own = 0x55; 53static int own = 0x55;
52static int mmapped; 54static int mmapped;
53 55
54/* vdovikin: removed static struct i2c_pcf_isa gpi; code - 56/* vdovikin: removed static struct i2c_pcf_isa gpi; code -
55 this module in real supports only one device, due to missing arguments 57 this module in real supports only one device, due to missing arguments
56 in some functions, called from the algo-pcf module. Sometimes it's 58 in some functions, called from the algo-pcf module. Sometimes it's
57 need to be rewriten - but for now just remove this for simpler reading */ 59 need to be rewriten - but for now just remove this for simpler reading */
@@ -60,40 +62,33 @@ static wait_queue_head_t pcf_wait;
60static int pcf_pending; 62static int pcf_pending;
61static spinlock_t lock; 63static spinlock_t lock;
62 64
65static struct i2c_adapter pcf_isa_ops;
66
63/* ----- local functions ---------------------------------------------- */ 67/* ----- local functions ---------------------------------------------- */
64 68
65static void pcf_isa_setbyte(void *data, int ctl, int val) 69static void pcf_isa_setbyte(void *data, int ctl, int val)
66{ 70{
67 int address = ctl ? (base + 1) : base; 71 u8 __iomem *address = ctl ? (base_iomem + 1) : base_iomem;
68 72
69 /* enable irq if any specified for serial operation */ 73 /* enable irq if any specified for serial operation */
70 if (ctl && irq && (val & I2C_PCF_ESO)) { 74 if (ctl && irq && (val & I2C_PCF_ESO)) {
71 val |= I2C_PCF_ENI; 75 val |= I2C_PCF_ENI;
72 } 76 }
73 77
74 pr_debug("i2c-elektor: Write 0x%X 0x%02X\n", address, val & 255); 78 pr_debug("%s: Write %p 0x%02X\n", pcf_isa_ops.name, address, val);
75 79 iowrite8(val, address);
76 switch (mmapped) { 80#ifdef __alpha__
77 case 0: /* regular I/O */ 81 /* API UP2000 needs some hardware fudging to make the write stick */
78 outb(val, address); 82 iowrite8(val, address);
79 break; 83#endif
80 case 2: /* double mapped I/O needed for UP2000 board,
81 I don't know why this... */
82 writeb(val, (void *)address);
83 /* fall */
84 case 1: /* memory mapped I/O */
85 writeb(val, (void *)address);
86 break;
87 }
88} 84}
89 85
90static int pcf_isa_getbyte(void *data, int ctl) 86static int pcf_isa_getbyte(void *data, int ctl)
91{ 87{
92 int address = ctl ? (base + 1) : base; 88 u8 __iomem *address = ctl ? (base_iomem + 1) : base_iomem;
93 int val = mmapped ? readb((void *)address) : inb(address); 89 int val = ioread8(address);
94
95 pr_debug("i2c-elektor: Read 0x%X 0x%02X\n", address, val);
96 90
91 pr_debug("%s: Read %p 0x%02X\n", pcf_isa_ops.name, address, val);
97 return (val); 92 return (val);
98} 93}
99 94
@@ -149,16 +144,40 @@ static int pcf_isa_init(void)
149{ 144{
150 spin_lock_init(&lock); 145 spin_lock_init(&lock);
151 if (!mmapped) { 146 if (!mmapped) {
152 if (!request_region(base, 2, "i2c (isa bus adapter)")) { 147 if (!request_region(base, 2, pcf_isa_ops.name)) {
153 printk(KERN_ERR 148 printk(KERN_ERR "%s: requested I/O region (%#x:2) is "
154 "i2c-elektor: requested I/O region (0x%X:2) " 149 "in use\n", pcf_isa_ops.name, base);
155 "is in use.\n", base); 150 return -ENODEV;
151 }
152 base_iomem = ioport_map(base, 2);
153 if (!base_iomem) {
154 printk(KERN_ERR "%s: remap of I/O region %#x failed\n",
155 pcf_isa_ops.name, base);
156 release_region(base, 2);
157 return -ENODEV;
158 }
159 } else {
160 if (!request_mem_region(base, 2, pcf_isa_ops.name)) {
161 printk(KERN_ERR "%s: requested memory region (%#x:2) "
162 "is in use\n", pcf_isa_ops.name, base);
163 return -ENODEV;
164 }
165 base_iomem = ioremap(base, 2);
166 if (base_iomem == NULL) {
167 printk(KERN_ERR "%s: remap of memory region %#x "
168 "failed\n", pcf_isa_ops.name, base);
169 release_mem_region(base, 2);
156 return -ENODEV; 170 return -ENODEV;
157 } 171 }
158 } 172 }
173 pr_debug("%s: registers %#x remapped to %p\n", pcf_isa_ops.name, base,
174 base_iomem);
175
159 if (irq > 0) { 176 if (irq > 0) {
160 if (request_irq(irq, pcf_isa_handler, 0, "PCF8584", NULL) < 0) { 177 if (request_irq(irq, pcf_isa_handler, 0, pcf_isa_ops.name,
161 printk(KERN_ERR "i2c-elektor: Request irq%d failed\n", irq); 178 NULL) < 0) {
179 printk(KERN_ERR "%s: Request irq%d failed\n",
180 pcf_isa_ops.name, irq);
162 irq = 0; 181 irq = 0;
163 } else 182 } else
164 enable_irq(irq); 183 enable_irq(irq);
@@ -186,47 +205,49 @@ static struct i2c_adapter pcf_isa_ops = {
186 .class = I2C_CLASS_HWMON, 205 .class = I2C_CLASS_HWMON,
187 .id = I2C_HW_P_ELEK, 206 .id = I2C_HW_P_ELEK,
188 .algo_data = &pcf_isa_data, 207 .algo_data = &pcf_isa_data,
189 .name = "PCF8584 ISA adapter", 208 .name = "i2c-elektor",
190}; 209};
191 210
192static int __init i2c_pcfisa_init(void) 211static int __init i2c_pcfisa_init(void)
193{ 212{
194#ifdef __alpha__ 213#ifdef __alpha__
195 /* check to see we have memory mapped PCF8584 connected to the 214 /* check to see we have memory mapped PCF8584 connected to the
196 Cypress cy82c693 PCI-ISA bridge as on UP2000 board */ 215 Cypress cy82c693 PCI-ISA bridge as on UP2000 board */
197 if (base == 0) { 216 if (base == 0) {
198 struct pci_dev *cy693_dev; 217 struct pci_dev *cy693_dev;
199 218
200 cy693_dev = pci_get_device(PCI_VENDOR_ID_CONTAQ, 219 cy693_dev = pci_get_device(PCI_VENDOR_ID_CONTAQ,
201 PCI_DEVICE_ID_CONTAQ_82C693, NULL); 220 PCI_DEVICE_ID_CONTAQ_82C693, NULL);
202 if (cy693_dev) { 221 if (cy693_dev) {
203 char config; 222 unsigned char config;
204 /* yeap, we've found cypress, let's check config */ 223 /* yeap, we've found cypress, let's check config */
205 if (!pci_read_config_byte(cy693_dev, 0x47, &config)) { 224 if (!pci_read_config_byte(cy693_dev, 0x47, &config)) {
206 225
207 pr_debug("i2c-elektor: found cy82c693, config register 0x47 = 0x%02x.\n", config); 226 pr_debug("%s: found cy82c693, config "
227 "register 0x47 = 0x%02x\n",
228 pcf_isa_ops.name, config);
208 229
209 /* UP2000 board has this register set to 0xe1, 230 /* UP2000 board has this register set to 0xe1,
210 but the most significant bit as seems can be 231 but the most significant bit as seems can be
211 reset during the proper initialisation 232 reset during the proper initialisation
212 sequence if guys from API decides to do that 233 sequence if guys from API decides to do that
213 (so, we can even enable Tsunami Pchip 234 (so, we can even enable Tsunami Pchip
214 window for the upper 1 Gb) */ 235 window for the upper 1 Gb) */
215 236
216 /* so just check for ROMCS at 0xe0000, 237 /* so just check for ROMCS at 0xe0000,
217 ROMCS enabled for writes 238 ROMCS enabled for writes
218 and external XD Bus buffer in use. */ 239 and external XD Bus buffer in use. */
219 if ((config & 0x7f) == 0x61) { 240 if ((config & 0x7f) == 0x61) {
220 /* seems to be UP2000 like board */ 241 /* seems to be UP2000 like board */
221 base = 0xe0000; 242 base = 0xe0000;
222 /* I don't know why we need to 243 mmapped = 1;
223 write twice */ 244 /* UP2000 drives ISA with
224 mmapped = 2;
225 /* UP2000 drives ISA with
226 8.25 MHz (PCI/4) clock 245 8.25 MHz (PCI/4) clock
227 (this can be read from cypress) */ 246 (this can be read from cypress) */
228 clock = I2C_PCF_CLK | I2C_PCF_TRNS90; 247 clock = I2C_PCF_CLK | I2C_PCF_TRNS90;
229 printk(KERN_INFO "i2c-elektor: found API UP2000 like board, will probe PCF8584 later.\n"); 248 pr_info("%s: found API UP2000 like "
249 "board, will probe PCF8584 "
250 "later\n", pcf_isa_ops.name);
230 } 251 }
231 } 252 }
232 pci_dev_put(cy693_dev); 253 pci_dev_put(cy693_dev);
@@ -236,12 +257,11 @@ static int __init i2c_pcfisa_init(void)
236 257
237 /* sanity checks for mmapped I/O */ 258 /* sanity checks for mmapped I/O */
238 if (mmapped && base < 0xc8000) { 259 if (mmapped && base < 0xc8000) {
239 printk(KERN_ERR "i2c-elektor: incorrect base address (0x%0X) specified for mmapped I/O.\n", base); 260 printk(KERN_ERR "%s: incorrect base address (%#x) specified "
261 "for mmapped I/O\n", pcf_isa_ops.name, base);
240 return -ENODEV; 262 return -ENODEV;
241 } 263 }
242 264
243 printk(KERN_INFO "i2c-elektor: i2c pcf8584-isa adapter driver\n");
244
245 if (base == 0) { 265 if (base == 0) {
246 base = DEFAULT_BASE; 266 base = DEFAULT_BASE;
247 } 267 }
@@ -251,8 +271,8 @@ static int __init i2c_pcfisa_init(void)
251 return -ENODEV; 271 return -ENODEV;
252 if (i2c_pcf_add_bus(&pcf_isa_ops) < 0) 272 if (i2c_pcf_add_bus(&pcf_isa_ops) < 0)
253 goto fail; 273 goto fail;
254 274
255 printk(KERN_ERR "i2c-elektor: found device at %#x.\n", base); 275 dev_info(&pcf_isa_ops.dev, "found device at %#x\n", base);
256 276
257 return 0; 277 return 0;
258 278
@@ -262,8 +282,13 @@ static int __init i2c_pcfisa_init(void)
262 free_irq(irq, NULL); 282 free_irq(irq, NULL);
263 } 283 }
264 284
265 if (!mmapped) 285 if (!mmapped) {
266 release_region(base , 2); 286 ioport_unmap(base_iomem);
287 release_region(base, 2);
288 } else {
289 iounmap(base_iomem);
290 release_mem_region(base, 2);
291 }
267 return -ENODEV; 292 return -ENODEV;
268} 293}
269 294
@@ -276,8 +301,13 @@ static void i2c_pcfisa_exit(void)
276 free_irq(irq, NULL); 301 free_irq(irq, NULL);
277 } 302 }
278 303
279 if (!mmapped) 304 if (!mmapped) {
280 release_region(base , 2); 305 ioport_unmap(base_iomem);
306 release_region(base, 2);
307 } else {
308 iounmap(base_iomem);
309 release_mem_region(base, 2);
310 }
281} 311}
282 312
283MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>"); 313MODULE_AUTHOR("Hans Berglund <hb@spacetec.no>");
diff --git a/drivers/i2c/busses/i2c-hydra.c b/drivers/i2c/busses/i2c-hydra.c
index e0cb3b0f92fa..1b5354e24bf5 100644
--- a/drivers/i2c/busses/i2c-hydra.c
+++ b/drivers/i2c/busses/i2c-hydra.c
@@ -155,6 +155,7 @@ static void __devexit hydra_remove(struct pci_dev *dev)
155 155
156 156
157static struct pci_driver hydra_driver = { 157static struct pci_driver hydra_driver = {
158 .owner = THIS_MODULE,
158 .name = "hydra_smbus", 159 .name = "hydra_smbus",
159 .id_table = hydra_ids, 160 .id_table = hydra_ids,
160 .probe = hydra_probe, 161 .probe = hydra_probe,
diff --git a/drivers/i2c/busses/i2c-i801.c b/drivers/i2c/busses/i2c-i801.c
index 709beab76609..4f63195069da 100644
--- a/drivers/i2c/busses/i2c-i801.c
+++ b/drivers/i2c/busses/i2c-i801.c
@@ -52,10 +52,6 @@
52#include <linux/i2c.h> 52#include <linux/i2c.h>
53#include <asm/io.h> 53#include <asm/io.h>
54 54
55#ifdef I2C_FUNC_SMBUS_BLOCK_DATA_PEC
56#define HAVE_PEC
57#endif
58
59/* I801 SMBus address offsets */ 55/* I801 SMBus address offsets */
60#define SMBHSTSTS (0 + i801_smba) 56#define SMBHSTSTS (0 + i801_smba)
61#define SMBHSTCNT (2 + i801_smba) 57#define SMBHSTCNT (2 + i801_smba)
@@ -106,10 +102,11 @@ MODULE_PARM_DESC(force_addr,
106 "EXTREMELY DANGEROUS!"); 102 "EXTREMELY DANGEROUS!");
107 103
108static int i801_transaction(void); 104static int i801_transaction(void);
109static int i801_block_transaction(union i2c_smbus_data *data, 105static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
110 char read_write, int command); 106 int command, int hwpec);
111 107
112static unsigned short i801_smba; 108static unsigned short i801_smba;
109static struct pci_driver i801_driver;
113static struct pci_dev *I801_dev; 110static struct pci_dev *I801_dev;
114static int isich4; 111static int isich4;
115 112
@@ -143,7 +140,7 @@ static int i801_setup(struct pci_dev *dev)
143 } 140 }
144 } 141 }
145 142
146 if (!request_region(i801_smba, (isich4 ? 16 : 8), "i801-smbus")) { 143 if (!request_region(i801_smba, (isich4 ? 16 : 8), i801_driver.name)) {
147 dev_err(&dev->dev, "I801_smb region 0x%x already in use!\n", 144 dev_err(&dev->dev, "I801_smb region 0x%x already in use!\n",
148 i801_smba); 145 i801_smba);
149 error_return = -EBUSY; 146 error_return = -EBUSY;
@@ -252,7 +249,7 @@ static int i801_transaction(void)
252 249
253/* All-inclusive block transaction function */ 250/* All-inclusive block transaction function */
254static int i801_block_transaction(union i2c_smbus_data *data, char read_write, 251static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
255 int command) 252 int command, int hwpec)
256{ 253{
257 int i, len; 254 int i, len;
258 int smbcmd; 255 int smbcmd;
@@ -391,8 +388,7 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
391 goto END; 388 goto END;
392 } 389 }
393 390
394#ifdef HAVE_PEC 391 if (hwpec) {
395 if(isich4 && command == I2C_SMBUS_BLOCK_DATA_PEC) {
396 /* wait for INTR bit as advised by Intel */ 392 /* wait for INTR bit as advised by Intel */
397 timeout = 0; 393 timeout = 0;
398 do { 394 do {
@@ -406,7 +402,6 @@ static int i801_block_transaction(union i2c_smbus_data *data, char read_write,
406 } 402 }
407 outb_p(temp, SMBHSTSTS); 403 outb_p(temp, SMBHSTSTS);
408 } 404 }
409#endif
410 result = 0; 405 result = 0;
411END: 406END:
412 if (command == I2C_SMBUS_I2C_BLOCK_DATA) { 407 if (command == I2C_SMBUS_I2C_BLOCK_DATA) {
@@ -421,14 +416,13 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
421 unsigned short flags, char read_write, u8 command, 416 unsigned short flags, char read_write, u8 command,
422 int size, union i2c_smbus_data * data) 417 int size, union i2c_smbus_data * data)
423{ 418{
424 int hwpec = 0; 419 int hwpec;
425 int block = 0; 420 int block = 0;
426 int ret, xact = 0; 421 int ret, xact = 0;
427 422
428#ifdef HAVE_PEC 423 hwpec = isich4 && (flags & I2C_CLIENT_PEC)
429 if(isich4) 424 && size != I2C_SMBUS_QUICK
430 hwpec = (flags & I2C_CLIENT_PEC) != 0; 425 && size != I2C_SMBUS_I2C_BLOCK_DATA;
431#endif
432 426
433 switch (size) { 427 switch (size) {
434 case I2C_SMBUS_QUICK: 428 case I2C_SMBUS_QUICK:
@@ -463,11 +457,6 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
463 break; 457 break;
464 case I2C_SMBUS_BLOCK_DATA: 458 case I2C_SMBUS_BLOCK_DATA:
465 case I2C_SMBUS_I2C_BLOCK_DATA: 459 case I2C_SMBUS_I2C_BLOCK_DATA:
466#ifdef HAVE_PEC
467 case I2C_SMBUS_BLOCK_DATA_PEC:
468 if(hwpec && size == I2C_SMBUS_BLOCK_DATA)
469 size = I2C_SMBUS_BLOCK_DATA_PEC;
470#endif
471 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 460 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
472 SMBHSTADD); 461 SMBHSTADD);
473 outb_p(command, SMBHSTCMD); 462 outb_p(command, SMBHSTCMD);
@@ -479,27 +468,18 @@ static s32 i801_access(struct i2c_adapter * adap, u16 addr,
479 return -1; 468 return -1;
480 } 469 }
481 470
482#ifdef HAVE_PEC 471 if (hwpec)
483 if(isich4 && hwpec) { 472 outb_p(1, SMBAUXCTL); /* enable hardware PEC */
484 if(size != I2C_SMBUS_QUICK && 473
485 size != I2C_SMBUS_I2C_BLOCK_DATA)
486 outb_p(1, SMBAUXCTL); /* enable HW PEC */
487 }
488#endif
489 if(block) 474 if(block)
490 ret = i801_block_transaction(data, read_write, size); 475 ret = i801_block_transaction(data, read_write, size, hwpec);
491 else { 476 else {
492 outb_p(xact | ENABLE_INT9, SMBHSTCNT); 477 outb_p(xact | ENABLE_INT9, SMBHSTCNT);
493 ret = i801_transaction(); 478 ret = i801_transaction();
494 } 479 }
495 480
496#ifdef HAVE_PEC 481 if (hwpec)
497 if(isich4 && hwpec) { 482 outb_p(0, SMBAUXCTL); /* disable hardware PEC */
498 if(size != I2C_SMBUS_QUICK &&
499 size != I2C_SMBUS_I2C_BLOCK_DATA)
500 outb_p(0, SMBAUXCTL);
501 }
502#endif
503 483
504 if(block) 484 if(block)
505 return ret; 485 return ret;
@@ -526,12 +506,7 @@ static u32 i801_func(struct i2c_adapter *adapter)
526 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 506 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
527 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 507 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
528 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK 508 I2C_FUNC_SMBUS_BLOCK_DATA | I2C_FUNC_SMBUS_WRITE_I2C_BLOCK
529#ifdef HAVE_PEC 509 | (isich4 ? I2C_FUNC_SMBUS_HWPEC_CALC : 0);
530 | (isich4 ? I2C_FUNC_SMBUS_BLOCK_DATA_PEC |
531 I2C_FUNC_SMBUS_HWPEC_CALC
532 : 0)
533#endif
534 ;
535} 510}
536 511
537static struct i2c_algorithm smbus_algorithm = { 512static struct i2c_algorithm smbus_algorithm = {
@@ -543,7 +518,6 @@ static struct i2c_adapter i801_adapter = {
543 .owner = THIS_MODULE, 518 .owner = THIS_MODULE,
544 .class = I2C_CLASS_HWMON, 519 .class = I2C_CLASS_HWMON,
545 .algo = &smbus_algorithm, 520 .algo = &smbus_algorithm,
546 .name = "unset",
547}; 521};
548 522
549static struct pci_device_id i801_ids[] = { 523static struct pci_device_id i801_ids[] = {
@@ -586,6 +560,7 @@ static void __devexit i801_remove(struct pci_dev *dev)
586} 560}
587 561
588static struct pci_driver i801_driver = { 562static struct pci_driver i801_driver = {
563 .owner = THIS_MODULE,
589 .name = "i801_smbus", 564 .name = "i801_smbus",
590 .id_table = i801_ids, 565 .id_table = i801_ids,
591 .probe = i801_probe, 566 .probe = i801_probe,
diff --git a/drivers/i2c/busses/i2c-i810.c b/drivers/i2c/busses/i2c-i810.c
index 0ff7016e0629..52bc30593bd7 100644
--- a/drivers/i2c/busses/i2c-i810.c
+++ b/drivers/i2c/busses/i2c-i810.c
@@ -32,6 +32,7 @@
32 i810AB 7123 32 i810AB 7123
33 i810E 7125 33 i810E 7125
34 i815 1132 34 i815 1132
35 i845G 2562
35*/ 36*/
36 37
37#include <linux/kernel.h> 38#include <linux/kernel.h>
@@ -232,6 +233,7 @@ static void __devexit i810_remove(struct pci_dev *dev)
232} 233}
233 234
234static struct pci_driver i810_driver = { 235static struct pci_driver i810_driver = {
236 .owner = THIS_MODULE,
235 .name = "i810_smbus", 237 .name = "i810_smbus",
236 .id_table = i810_ids, 238 .id_table = i810_ids,
237 .probe = i810_probe, 239 .probe = i810_probe,
diff --git a/drivers/i2c/busses/i2c-ibm_iic.c b/drivers/i2c/busses/i2c-ibm_iic.c
index a3ed9590f028..1a587253d716 100644
--- a/drivers/i2c/busses/i2c-ibm_iic.c
+++ b/drivers/i2c/busses/i2c-ibm_iic.c
@@ -672,13 +672,12 @@ static int __devinit iic_probe(struct ocp_device *ocp){
672 printk(KERN_WARNING"ibm-iic%d: missing additional data!\n", 672 printk(KERN_WARNING"ibm-iic%d: missing additional data!\n",
673 ocp->def->index); 673 ocp->def->index);
674 674
675 if (!(dev = kmalloc(sizeof(*dev), GFP_KERNEL))){ 675 if (!(dev = kzalloc(sizeof(*dev), GFP_KERNEL))) {
676 printk(KERN_CRIT "ibm-iic%d: failed to allocate device data\n", 676 printk(KERN_CRIT "ibm-iic%d: failed to allocate device data\n",
677 ocp->def->index); 677 ocp->def->index);
678 return -ENOMEM; 678 return -ENOMEM;
679 } 679 }
680 680
681 memset(dev, 0, sizeof(*dev));
682 dev->idx = ocp->def->index; 681 dev->idx = ocp->def->index;
683 ocp_set_drvdata(ocp, dev); 682 ocp_set_drvdata(ocp, dev);
684 683
diff --git a/drivers/i2c/busses/i2c-iop3xx.c b/drivers/i2c/busses/i2c-iop3xx.c
index 7bd9102db701..9888fae1f37a 100644
--- a/drivers/i2c/busses/i2c-iop3xx.c
+++ b/drivers/i2c/busses/i2c-iop3xx.c
@@ -43,7 +43,7 @@
43#include "i2c-iop3xx.h" 43#include "i2c-iop3xx.h"
44 44
45/* global unit counter */ 45/* global unit counter */
46static int i2c_id = 0; 46static int i2c_id;
47 47
48static inline unsigned char 48static inline unsigned char
49iic_cook_addr(struct i2c_msg *msg) 49iic_cook_addr(struct i2c_msg *msg)
@@ -440,19 +440,17 @@ iop3xx_i2c_probe(struct device *dev)
440 struct i2c_adapter *new_adapter; 440 struct i2c_adapter *new_adapter;
441 struct i2c_algo_iop3xx_data *adapter_data; 441 struct i2c_algo_iop3xx_data *adapter_data;
442 442
443 new_adapter = kmalloc(sizeof(struct i2c_adapter), GFP_KERNEL); 443 new_adapter = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL);
444 if (!new_adapter) { 444 if (!new_adapter) {
445 ret = -ENOMEM; 445 ret = -ENOMEM;
446 goto out; 446 goto out;
447 } 447 }
448 memset((void*)new_adapter, 0, sizeof(*new_adapter));
449 448
450 adapter_data = kmalloc(sizeof(struct i2c_algo_iop3xx_data), GFP_KERNEL); 449 adapter_data = kzalloc(sizeof(struct i2c_algo_iop3xx_data), GFP_KERNEL);
451 if (!adapter_data) { 450 if (!adapter_data) {
452 ret = -ENOMEM; 451 ret = -ENOMEM;
453 goto free_adapter; 452 goto free_adapter;
454 } 453 }
455 memset((void*)adapter_data, 0, sizeof(*adapter_data));
456 454
457 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 455 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
458 if (!res) { 456 if (!res) {
@@ -525,6 +523,7 @@ out:
525 523
526 524
527static struct device_driver iop3xx_i2c_driver = { 525static struct device_driver iop3xx_i2c_driver = {
526 .owner = THIS_MODULE,
528 .name = "IOP3xx-I2C", 527 .name = "IOP3xx-I2C",
529 .bus = &platform_bus_type, 528 .bus = &platform_bus_type,
530 .probe = iop3xx_i2c_probe, 529 .probe = iop3xx_i2c_probe,
diff --git a/drivers/i2c/busses/i2c-isa.c b/drivers/i2c/busses/i2c-isa.c
index bdc6806dafae..4fdc02411609 100644
--- a/drivers/i2c/busses/i2c-isa.c
+++ b/drivers/i2c/busses/i2c-isa.c
@@ -92,6 +92,7 @@ int i2c_isa_add_driver(struct i2c_driver *driver)
92 92
93 /* Add the driver to the list of i2c drivers in the driver core */ 93 /* Add the driver to the list of i2c drivers in the driver core */
94 driver->driver.name = driver->name; 94 driver->driver.name = driver->name;
95 driver->driver.owner = driver->owner;
95 driver->driver.bus = &i2c_bus_type; 96 driver->driver.bus = &i2c_bus_type;
96 driver->driver.probe = i2c_isa_device_probe; 97 driver->driver.probe = i2c_isa_device_probe;
97 driver->driver.remove = i2c_isa_device_remove; 98 driver->driver.remove = i2c_isa_device_remove;
diff --git a/drivers/i2c/busses/i2c-ixp2000.c b/drivers/i2c/busses/i2c-ixp2000.c
index 1956af382cd8..42016ee6ef13 100644
--- a/drivers/i2c/busses/i2c-ixp2000.c
+++ b/drivers/i2c/busses/i2c-ixp2000.c
@@ -36,6 +36,8 @@
36#include <asm/hardware.h> /* Pick up IXP2000-specific bits */ 36#include <asm/hardware.h> /* Pick up IXP2000-specific bits */
37#include <asm/arch/gpio.h> 37#include <asm/arch/gpio.h>
38 38
39static struct device_driver ixp2000_i2c_driver;
40
39static inline int ixp2000_scl_pin(void *data) 41static inline int ixp2000_scl_pin(void *data)
40{ 42{
41 return ((struct ixp2000_i2c_pins*)data)->scl_pin; 43 return ((struct ixp2000_i2c_pins*)data)->scl_pin;
@@ -104,11 +106,10 @@ static int ixp2000_i2c_probe(struct device *dev)
104 struct platform_device *plat_dev = to_platform_device(dev); 106 struct platform_device *plat_dev = to_platform_device(dev);
105 struct ixp2000_i2c_pins *gpio = plat_dev->dev.platform_data; 107 struct ixp2000_i2c_pins *gpio = plat_dev->dev.platform_data;
106 struct ixp2000_i2c_data *drv_data = 108 struct ixp2000_i2c_data *drv_data =
107 kmalloc(sizeof(struct ixp2000_i2c_data), GFP_KERNEL); 109 kzalloc(sizeof(struct ixp2000_i2c_data), GFP_KERNEL);
108 110
109 if (!drv_data) 111 if (!drv_data)
110 return -ENOMEM; 112 return -ENOMEM;
111 memzero(drv_data, sizeof(*drv_data));
112 drv_data->gpio_pins = gpio; 113 drv_data->gpio_pins = gpio;
113 114
114 drv_data->algo_data.data = gpio; 115 drv_data->algo_data.data = gpio;
@@ -121,6 +122,8 @@ static int ixp2000_i2c_probe(struct device *dev)
121 drv_data->algo_data.timeout = 100; 122 drv_data->algo_data.timeout = 100;
122 123
123 drv_data->adapter.id = I2C_HW_B_IXP2000, 124 drv_data->adapter.id = I2C_HW_B_IXP2000,
125 strlcpy(drv_data->adapter.name, ixp2000_i2c_driver.name,
126 I2C_NAME_SIZE);
124 drv_data->adapter.algo_data = &drv_data->algo_data, 127 drv_data->adapter.algo_data = &drv_data->algo_data,
125 128
126 drv_data->adapter.dev.parent = &plat_dev->dev; 129 drv_data->adapter.dev.parent = &plat_dev->dev;
@@ -142,6 +145,7 @@ static int ixp2000_i2c_probe(struct device *dev)
142} 145}
143 146
144static struct device_driver ixp2000_i2c_driver = { 147static struct device_driver ixp2000_i2c_driver = {
148 .owner = THIS_MODULE,
145 .name = "IXP2000-I2C", 149 .name = "IXP2000-I2C",
146 .bus = &platform_bus_type, 150 .bus = &platform_bus_type,
147 .probe = ixp2000_i2c_probe, 151 .probe = ixp2000_i2c_probe,
diff --git a/drivers/i2c/busses/i2c-ixp4xx.c b/drivers/i2c/busses/i2c-ixp4xx.c
index f6f5ca31fdba..69303ab65e04 100644
--- a/drivers/i2c/busses/i2c-ixp4xx.c
+++ b/drivers/i2c/busses/i2c-ixp4xx.c
@@ -35,6 +35,8 @@
35 35
36#include <asm/hardware.h> /* Pick up IXP4xx-specific bits */ 36#include <asm/hardware.h> /* Pick up IXP4xx-specific bits */
37 37
38static struct device_driver ixp4xx_i2c_driver;
39
38static inline int ixp4xx_scl_pin(void *data) 40static inline int ixp4xx_scl_pin(void *data)
39{ 41{
40 return ((struct ixp4xx_i2c_pins*)data)->scl_pin; 42 return ((struct ixp4xx_i2c_pins*)data)->scl_pin;
@@ -105,12 +107,11 @@ static int ixp4xx_i2c_probe(struct device *dev)
105 struct platform_device *plat_dev = to_platform_device(dev); 107 struct platform_device *plat_dev = to_platform_device(dev);
106 struct ixp4xx_i2c_pins *gpio = plat_dev->dev.platform_data; 108 struct ixp4xx_i2c_pins *gpio = plat_dev->dev.platform_data;
107 struct ixp4xx_i2c_data *drv_data = 109 struct ixp4xx_i2c_data *drv_data =
108 kmalloc(sizeof(struct ixp4xx_i2c_data), GFP_KERNEL); 110 kzalloc(sizeof(struct ixp4xx_i2c_data), GFP_KERNEL);
109 111
110 if(!drv_data) 112 if(!drv_data)
111 return -ENOMEM; 113 return -ENOMEM;
112 114
113 memzero(drv_data, sizeof(struct ixp4xx_i2c_data));
114 drv_data->gpio_pins = gpio; 115 drv_data->gpio_pins = gpio;
115 116
116 /* 117 /*
@@ -129,6 +130,8 @@ static int ixp4xx_i2c_probe(struct device *dev)
129 drv_data->algo_data.timeout = 100; 130 drv_data->algo_data.timeout = 100;
130 131
131 drv_data->adapter.id = I2C_HW_B_IXP4XX; 132 drv_data->adapter.id = I2C_HW_B_IXP4XX;
133 strlcpy(drv_data->adapter.name, ixp4xx_i2c_driver.name,
134 I2C_NAME_SIZE);
132 drv_data->adapter.algo_data = &drv_data->algo_data; 135 drv_data->adapter.algo_data = &drv_data->algo_data;
133 136
134 drv_data->adapter.dev.parent = &plat_dev->dev; 137 drv_data->adapter.dev.parent = &plat_dev->dev;
@@ -151,6 +154,7 @@ static int ixp4xx_i2c_probe(struct device *dev)
151} 154}
152 155
153static struct device_driver ixp4xx_i2c_driver = { 156static struct device_driver ixp4xx_i2c_driver = {
157 .owner = THIS_MODULE,
154 .name = "IXP4XX-I2C", 158 .name = "IXP4XX-I2C",
155 .bus = &platform_bus_type, 159 .bus = &platform_bus_type,
156 .probe = ixp4xx_i2c_probe, 160 .probe = ixp4xx_i2c_probe,
diff --git a/drivers/i2c/busses/i2c-keywest.c b/drivers/i2c/busses/i2c-keywest.c
index eff5896ce865..d61f748278fc 100644
--- a/drivers/i2c/busses/i2c-keywest.c
+++ b/drivers/i2c/busses/i2c-keywest.c
@@ -535,13 +535,12 @@ create_iface(struct device_node *np, struct device *dev)
535 535
536 tsize = sizeof(struct keywest_iface) + 536 tsize = sizeof(struct keywest_iface) +
537 (sizeof(struct keywest_chan) + 4) * nchan; 537 (sizeof(struct keywest_chan) + 4) * nchan;
538 iface = (struct keywest_iface *) kmalloc(tsize, GFP_KERNEL); 538 iface = kzalloc(tsize, GFP_KERNEL);
539 if (iface == NULL) { 539 if (iface == NULL) {
540 printk(KERN_ERR "i2c-keywest: can't allocate inteface !\n"); 540 printk(KERN_ERR "i2c-keywest: can't allocate inteface !\n");
541 pmac_low_i2c_unlock(np); 541 pmac_low_i2c_unlock(np);
542 return -ENOMEM; 542 return -ENOMEM;
543 } 543 }
544 memset(iface, 0, tsize);
545 spin_lock_init(&iface->lock); 544 spin_lock_init(&iface->lock);
546 init_completion(&iface->complete); 545 init_completion(&iface->complete);
547 iface->node = of_node_get(np); 546 iface->node = of_node_get(np);
@@ -716,6 +715,7 @@ static struct of_device_id i2c_keywest_match[] =
716 715
717static struct macio_driver i2c_keywest_macio_driver = 716static struct macio_driver i2c_keywest_macio_driver =
718{ 717{
718 .owner = THIS_MODULE,
719 .name = "i2c-keywest", 719 .name = "i2c-keywest",
720 .match_table = i2c_keywest_match, 720 .match_table = i2c_keywest_match,
721 .probe = create_iface_macio, 721 .probe = create_iface_macio,
@@ -724,6 +724,7 @@ static struct macio_driver i2c_keywest_macio_driver =
724 724
725static struct of_platform_driver i2c_keywest_of_platform_driver = 725static struct of_platform_driver i2c_keywest_of_platform_driver =
726{ 726{
727 .owner = THIS_MODULE,
727 .name = "i2c-keywest", 728 .name = "i2c-keywest",
728 .match_table = i2c_keywest_match, 729 .match_table = i2c_keywest_match,
729 .probe = create_iface_of_platform, 730 .probe = create_iface_of_platform,
diff --git a/drivers/i2c/busses/i2c-mpc.c b/drivers/i2c/busses/i2c-mpc.c
index f065583ddcf1..8491633005b8 100644
--- a/drivers/i2c/busses/i2c-mpc.c
+++ b/drivers/i2c/busses/i2c-mpc.c
@@ -296,10 +296,9 @@ static int fsl_i2c_probe(struct device *device)
296 296
297 pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data; 297 pdata = (struct fsl_i2c_platform_data *) pdev->dev.platform_data;
298 298
299 if (!(i2c = kmalloc(sizeof(*i2c), GFP_KERNEL))) { 299 if (!(i2c = kzalloc(sizeof(*i2c), GFP_KERNEL))) {
300 return -ENOMEM; 300 return -ENOMEM;
301 } 301 }
302 memset(i2c, 0, sizeof(*i2c));
303 302
304 i2c->irq = platform_get_irq(pdev, 0); 303 i2c->irq = platform_get_irq(pdev, 0);
305 i2c->flags = pdata->device_flags; 304 i2c->flags = pdata->device_flags;
@@ -361,6 +360,7 @@ static int fsl_i2c_remove(struct device *device)
361 360
362/* Structure for a device driver */ 361/* Structure for a device driver */
363static struct device_driver fsl_i2c_driver = { 362static struct device_driver fsl_i2c_driver = {
363 .owner = THIS_MODULE,
364 .name = "fsl-i2c", 364 .name = "fsl-i2c",
365 .bus = &platform_bus_type, 365 .bus = &platform_bus_type,
366 .probe = fsl_i2c_probe, 366 .probe = fsl_i2c_probe,
diff --git a/drivers/i2c/busses/i2c-mv64xxx.c b/drivers/i2c/busses/i2c-mv64xxx.c
index 99abca45fece..d0d2a6f1386e 100644
--- a/drivers/i2c/busses/i2c-mv64xxx.c
+++ b/drivers/i2c/busses/i2c-mv64xxx.c
@@ -500,13 +500,10 @@ mv64xxx_i2c_probe(struct device *dev)
500 if ((pd->id != 0) || !pdata) 500 if ((pd->id != 0) || !pdata)
501 return -ENODEV; 501 return -ENODEV;
502 502
503 drv_data = kmalloc(sizeof(struct mv64xxx_i2c_data), GFP_KERNEL); 503 drv_data = kzalloc(sizeof(struct mv64xxx_i2c_data), GFP_KERNEL);
504
505 if (!drv_data) 504 if (!drv_data)
506 return -ENOMEM; 505 return -ENOMEM;
507 506
508 memset(drv_data, 0, sizeof(struct mv64xxx_i2c_data));
509
510 if (mv64xxx_i2c_map_regs(pd, drv_data)) { 507 if (mv64xxx_i2c_map_regs(pd, drv_data)) {
511 rc = -ENODEV; 508 rc = -ENODEV;
512 goto exit_kfree; 509 goto exit_kfree;
@@ -570,6 +567,7 @@ mv64xxx_i2c_remove(struct device *dev)
570} 567}
571 568
572static struct device_driver mv64xxx_i2c_driver = { 569static struct device_driver mv64xxx_i2c_driver = {
570 .owner = THIS_MODULE,
573 .name = MV64XXX_I2C_CTLR_NAME, 571 .name = MV64XXX_I2C_CTLR_NAME,
574 .bus = &platform_bus_type, 572 .bus = &platform_bus_type,
575 .probe = mv64xxx_i2c_probe, 573 .probe = mv64xxx_i2c_probe,
diff --git a/drivers/i2c/busses/i2c-nforce2.c b/drivers/i2c/busses/i2c-nforce2.c
index fe9c0f42a2b7..fd26036e68a3 100644
--- a/drivers/i2c/busses/i2c-nforce2.c
+++ b/drivers/i2c/busses/i2c-nforce2.c
@@ -97,6 +97,7 @@ struct nforce2_smbus {
97#define NVIDIA_SMB_PRTCL_I2C_BLOCK_DATA 0x4a 97#define NVIDIA_SMB_PRTCL_I2C_BLOCK_DATA 0x4a
98#define NVIDIA_SMB_PRTCL_PEC 0x80 98#define NVIDIA_SMB_PRTCL_PEC 0x80
99 99
100static struct pci_driver nforce2_driver;
100 101
101static s32 nforce2_access(struct i2c_adapter *adap, u16 addr, 102static s32 nforce2_access(struct i2c_adapter *adap, u16 addr,
102 unsigned short flags, char read_write, 103 unsigned short flags, char read_write,
@@ -113,7 +114,6 @@ static struct i2c_adapter nforce2_adapter = {
113 .owner = THIS_MODULE, 114 .owner = THIS_MODULE,
114 .class = I2C_CLASS_HWMON, 115 .class = I2C_CLASS_HWMON,
115 .algo = &smbus_algorithm, 116 .algo = &smbus_algorithm,
116 .name = "unset",
117}; 117};
118 118
119/* Return -1 on error. See smbus.h for more information */ 119/* Return -1 on error. See smbus.h for more information */
@@ -188,13 +188,6 @@ static s32 nforce2_access(struct i2c_adapter * adap, u16 addr,
188 dev_err(&adap->dev, "I2C_SMBUS_BLOCK_PROC_CALL not supported!\n"); 188 dev_err(&adap->dev, "I2C_SMBUS_BLOCK_PROC_CALL not supported!\n");
189 return -1; 189 return -1;
190 190
191 case I2C_SMBUS_WORD_DATA_PEC:
192 case I2C_SMBUS_BLOCK_DATA_PEC:
193 case I2C_SMBUS_PROC_CALL_PEC:
194 case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
195 dev_err(&adap->dev, "Unexpected software PEC transaction %d\n.", size);
196 return -1;
197
198 default: 191 default:
199 dev_err(&adap->dev, "Unsupported transaction %d\n", size); 192 dev_err(&adap->dev, "Unsupported transaction %d\n", size);
200 return -1; 193 return -1;
@@ -285,7 +278,7 @@ static int __devinit nforce2_probe_smb (struct pci_dev *dev, int reg,
285 smbus->base = iobase & 0xfffc; 278 smbus->base = iobase & 0xfffc;
286 smbus->size = 8; 279 smbus->size = 8;
287 280
288 if (!request_region(smbus->base, smbus->size, "nForce2 SMBus")) { 281 if (!request_region(smbus->base, smbus->size, nforce2_driver.name)) {
289 dev_err(&smbus->adapter.dev, "Error requesting region %02x .. %02X for %s\n", 282 dev_err(&smbus->adapter.dev, "Error requesting region %02x .. %02X for %s\n",
290 smbus->base, smbus->base+smbus->size-1, name); 283 smbus->base, smbus->base+smbus->size-1, name);
291 return -1; 284 return -1;
@@ -313,10 +306,8 @@ static int __devinit nforce2_probe(struct pci_dev *dev, const struct pci_device_
313 int res1, res2; 306 int res1, res2;
314 307
315 /* we support 2 SMBus adapters */ 308 /* we support 2 SMBus adapters */
316 if (!(smbuses = (void *)kmalloc(2*sizeof(struct nforce2_smbus), 309 if (!(smbuses = kzalloc(2*sizeof(struct nforce2_smbus), GFP_KERNEL)))
317 GFP_KERNEL)))
318 return -ENOMEM; 310 return -ENOMEM;
319 memset (smbuses, 0, 2*sizeof(struct nforce2_smbus));
320 pci_set_drvdata(dev, smbuses); 311 pci_set_drvdata(dev, smbuses);
321 312
322 /* SMBus adapter 1 */ 313 /* SMBus adapter 1 */
@@ -356,6 +347,7 @@ static void __devexit nforce2_remove(struct pci_dev *dev)
356} 347}
357 348
358static struct pci_driver nforce2_driver = { 349static struct pci_driver nforce2_driver = {
350 .owner = THIS_MODULE,
359 .name = "nForce2_smbus", 351 .name = "nForce2_smbus",
360 .id_table = nforce2_ids, 352 .id_table = nforce2_ids,
361 .probe = nforce2_probe, 353 .probe = nforce2_probe,
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c
index 71a2502fe069..2854d858fc9b 100644
--- a/drivers/i2c/busses/i2c-parport.c
+++ b/drivers/i2c/busses/i2c-parport.c
@@ -155,12 +155,11 @@ static void i2c_parport_attach (struct parport *port)
155{ 155{
156 struct i2c_par *adapter; 156 struct i2c_par *adapter;
157 157
158 adapter = kmalloc(sizeof(struct i2c_par), GFP_KERNEL); 158 adapter = kzalloc(sizeof(struct i2c_par), GFP_KERNEL);
159 if (adapter == NULL) { 159 if (adapter == NULL) {
160 printk(KERN_ERR "i2c-parport: Failed to kmalloc\n"); 160 printk(KERN_ERR "i2c-parport: Failed to kzalloc\n");
161 return; 161 return;
162 } 162 }
163 memset(adapter, 0x00, sizeof(struct i2c_par));
164 163
165 pr_debug("i2c-parport: attaching to %s\n", port->name); 164 pr_debug("i2c-parport: attaching to %s\n", port->name);
166 adapter->pdev = parport_register_device(port, "i2c-parport", 165 adapter->pdev = parport_register_device(port, "i2c-parport",
@@ -232,7 +231,7 @@ static void i2c_parport_detach (struct parport *port)
232 } 231 }
233} 232}
234 233
235static struct parport_driver i2c_driver = { 234static struct parport_driver i2c_parport_driver = {
236 .name = "i2c-parport", 235 .name = "i2c-parport",
237 .attach = i2c_parport_attach, 236 .attach = i2c_parport_attach,
238 .detach = i2c_parport_detach, 237 .detach = i2c_parport_detach,
@@ -250,12 +249,12 @@ static int __init i2c_parport_init(void)
250 type = 0; 249 type = 0;
251 } 250 }
252 251
253 return parport_register_driver(&i2c_driver); 252 return parport_register_driver(&i2c_parport_driver);
254} 253}
255 254
256static void __exit i2c_parport_exit(void) 255static void __exit i2c_parport_exit(void)
257{ 256{
258 parport_unregister_driver(&i2c_driver); 257 parport_unregister_driver(&i2c_parport_driver);
259} 258}
260 259
261MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); 260MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index 6d48a4da7bed..7d63eec423fe 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -90,13 +90,13 @@ struct sd {
90 90
91/* If force is set to anything different from 0, we forcibly enable the 91/* If force is set to anything different from 0, we forcibly enable the
92 PIIX4. DANGEROUS! */ 92 PIIX4. DANGEROUS! */
93static int force = 0; 93static int force;
94module_param (force, int, 0); 94module_param (force, int, 0);
95MODULE_PARM_DESC(force, "Forcibly enable the PIIX4. DANGEROUS!"); 95MODULE_PARM_DESC(force, "Forcibly enable the PIIX4. DANGEROUS!");
96 96
97/* If force_addr is set to anything different from 0, we forcibly enable 97/* If force_addr is set to anything different from 0, we forcibly enable
98 the PIIX4 at the given address. VERY DANGEROUS! */ 98 the PIIX4 at the given address. VERY DANGEROUS! */
99static int force_addr = 0; 99static int force_addr;
100module_param (force_addr, int, 0); 100module_param (force_addr, int, 0);
101MODULE_PARM_DESC(force_addr, 101MODULE_PARM_DESC(force_addr,
102 "Forcibly enable the PIIX4 at the given address. " 102 "Forcibly enable the PIIX4 at the given address. "
@@ -104,14 +104,15 @@ MODULE_PARM_DESC(force_addr,
104 104
105/* If fix_hstcfg is set to anything different from 0, we reset one of the 105/* If fix_hstcfg is set to anything different from 0, we reset one of the
106 registers to be a valid value. */ 106 registers to be a valid value. */
107static int fix_hstcfg = 0; 107static int fix_hstcfg;
108module_param (fix_hstcfg, int, 0); 108module_param (fix_hstcfg, int, 0);
109MODULE_PARM_DESC(fix_hstcfg, 109MODULE_PARM_DESC(fix_hstcfg,
110 "Fix config register. Needed on some boards (Force CPCI735)."); 110 "Fix config register. Needed on some boards (Force CPCI735).");
111 111
112static int piix4_transaction(void); 112static int piix4_transaction(void);
113 113
114static unsigned short piix4_smba = 0; 114static unsigned short piix4_smba;
115static struct pci_driver piix4_driver;
115static struct i2c_adapter piix4_adapter; 116static struct i2c_adapter piix4_adapter;
116 117
117static struct dmi_system_id __devinitdata piix4_dmi_table[] = { 118static struct dmi_system_id __devinitdata piix4_dmi_table[] = {
@@ -157,7 +158,7 @@ static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
157 } 158 }
158 } 159 }
159 160
160 if (!request_region(piix4_smba, SMBIOSIZE, "piix4-smbus")) { 161 if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) {
161 dev_err(&PIIX4_dev->dev, "SMB region 0x%x already in use!\n", 162 dev_err(&PIIX4_dev->dev, "SMB region 0x%x already in use!\n",
162 piix4_smba); 163 piix4_smba);
163 return -ENODEV; 164 return -ENODEV;
@@ -407,7 +408,6 @@ static struct i2c_adapter piix4_adapter = {
407 .owner = THIS_MODULE, 408 .owner = THIS_MODULE,
408 .class = I2C_CLASS_HWMON, 409 .class = I2C_CLASS_HWMON,
409 .algo = &smbus_algorithm, 410 .algo = &smbus_algorithm,
410 .name = "unset",
411}; 411};
412 412
413static struct pci_device_id piix4_ids[] = { 413static struct pci_device_id piix4_ids[] = {
@@ -462,6 +462,7 @@ static void __devexit piix4_remove(struct pci_dev *dev)
462} 462}
463 463
464static struct pci_driver piix4_driver = { 464static struct pci_driver piix4_driver = {
465 .owner = THIS_MODULE,
465 .name = "piix4_smbus", 466 .name = "piix4_smbus",
466 .id_table = piix4_ids, 467 .id_table = piix4_ids,
467 .probe = piix4_probe, 468 .probe = piix4_probe,
diff --git a/drivers/i2c/busses/i2c-pmac-smu.c b/drivers/i2c/busses/i2c-pmac-smu.c
index 8a9f5648a23d..bfefe7f7a53d 100644
--- a/drivers/i2c/busses/i2c-pmac-smu.c
+++ b/drivers/i2c/busses/i2c-pmac-smu.c
@@ -211,12 +211,11 @@ static int create_iface(struct device_node *np, struct device *dev)
211 } 211 }
212 busid = *reg; 212 busid = *reg;
213 213
214 iface = kmalloc(sizeof(struct smu_iface), GFP_KERNEL); 214 iface = kzalloc(sizeof(struct smu_iface), GFP_KERNEL);
215 if (iface == NULL) { 215 if (iface == NULL) {
216 printk(KERN_ERR "i2c-pmac-smu: can't allocate inteface !\n"); 216 printk(KERN_ERR "i2c-pmac-smu: can't allocate inteface !\n");
217 return -ENOMEM; 217 return -ENOMEM;
218 } 218 }
219 memset(iface, 0, sizeof(struct smu_iface));
220 init_completion(&iface->complete); 219 init_completion(&iface->complete);
221 iface->busid = busid; 220 iface->busid = busid;
222 221
diff --git a/drivers/i2c/busses/i2c-prosavage.c b/drivers/i2c/busses/i2c-prosavage.c
index 83fd16d61ce5..42cb1d8ca659 100644
--- a/drivers/i2c/busses/i2c-prosavage.c
+++ b/drivers/i2c/busses/i2c-prosavage.c
@@ -83,11 +83,6 @@ struct s_i2c_chip {
83/* 83/*
84 * i2c configuration 84 * i2c configuration
85 */ 85 */
86#ifndef I2C_HW_B_S3VIA
87#define I2C_HW_B_S3VIA 0x18 /* S3VIA ProSavage adapter */
88#endif
89
90/* delays */
91#define CYCLE_DELAY 10 86#define CYCLE_DELAY 10
92#define TIMEOUT (HZ / 2) 87#define TIMEOUT (HZ / 2)
93 88
@@ -241,14 +236,12 @@ static int __devinit prosavage_probe(struct pci_dev *dev, const struct pci_devic
241 struct s_i2c_chip *chip; 236 struct s_i2c_chip *chip;
242 struct s_i2c_bus *bus; 237 struct s_i2c_bus *bus;
243 238
244 pci_set_drvdata(dev, kmalloc(sizeof(struct s_i2c_chip), GFP_KERNEL)); 239 pci_set_drvdata(dev, kzalloc(sizeof(struct s_i2c_chip), GFP_KERNEL));
245 chip = (struct s_i2c_chip *)pci_get_drvdata(dev); 240 chip = (struct s_i2c_chip *)pci_get_drvdata(dev);
246 if (chip == NULL) { 241 if (chip == NULL) {
247 return -ENOMEM; 242 return -ENOMEM;
248 } 243 }
249 244
250 memset(chip, 0, sizeof(struct s_i2c_chip));
251
252 base = dev->resource[0].start & PCI_BASE_ADDRESS_MEM_MASK; 245 base = dev->resource[0].start & PCI_BASE_ADDRESS_MEM_MASK;
253 len = dev->resource[0].end - base + 1; 246 len = dev->resource[0].end - base + 1;
254 chip->mmio = ioremap_nocache(base, len); 247 chip->mmio = ioremap_nocache(base, len);
@@ -308,6 +301,7 @@ static struct pci_device_id prosavage_pci_tbl[] = {
308MODULE_DEVICE_TABLE (pci, prosavage_pci_tbl); 301MODULE_DEVICE_TABLE (pci, prosavage_pci_tbl);
309 302
310static struct pci_driver prosavage_driver = { 303static struct pci_driver prosavage_driver = {
304 .owner = THIS_MODULE,
311 .name = "prosavage_smbus", 305 .name = "prosavage_smbus",
312 .id_table = prosavage_pci_tbl, 306 .id_table = prosavage_pci_tbl,
313 .probe = prosavage_probe, 307 .probe = prosavage_probe,
diff --git a/drivers/i2c/busses/i2c-s3c2410.c b/drivers/i2c/busses/i2c-s3c2410.c
index 69fa282df2d5..6ced28e90070 100644
--- a/drivers/i2c/busses/i2c-s3c2410.c
+++ b/drivers/i2c/busses/i2c-s3c2410.c
@@ -896,6 +896,7 @@ static int s3c24xx_i2c_resume(struct device *dev)
896/* device driver for platform bus bits */ 896/* device driver for platform bus bits */
897 897
898static struct device_driver s3c2410_i2c_driver = { 898static struct device_driver s3c2410_i2c_driver = {
899 .owner = THIS_MODULE,
899 .name = "s3c2410-i2c", 900 .name = "s3c2410-i2c",
900 .bus = &platform_bus_type, 901 .bus = &platform_bus_type,
901 .probe = s3c24xx_i2c_probe, 902 .probe = s3c24xx_i2c_probe,
@@ -904,6 +905,7 @@ static struct device_driver s3c2410_i2c_driver = {
904}; 905};
905 906
906static struct device_driver s3c2440_i2c_driver = { 907static struct device_driver s3c2440_i2c_driver = {
908 .owner = THIS_MODULE,
907 .name = "s3c2440-i2c", 909 .name = "s3c2440-i2c",
908 .bus = &platform_bus_type, 910 .bus = &platform_bus_type,
909 .probe = s3c24xx_i2c_probe, 911 .probe = s3c24xx_i2c_probe,
diff --git a/drivers/i2c/busses/i2c-savage4.c b/drivers/i2c/busses/i2c-savage4.c
index 0c8518298e4d..aebe87ba4033 100644
--- a/drivers/i2c/busses/i2c-savage4.c
+++ b/drivers/i2c/busses/i2c-savage4.c
@@ -179,6 +179,7 @@ static void __devexit savage4_remove(struct pci_dev *dev)
179} 179}
180 180
181static struct pci_driver savage4_driver = { 181static struct pci_driver savage4_driver = {
182 .owner = THIS_MODULE,
182 .name = "savage4_smbus", 183 .name = "savage4_smbus",
183 .id_table = savage4_ids, 184 .id_table = savage4_ids,
184 .probe = savage4_probe, 185 .probe = savage4_probe,
diff --git a/drivers/i2c/busses/i2c-sis5595.c b/drivers/i2c/busses/i2c-sis5595.c
index 080318d6f54b..3ad27c3ba15b 100644
--- a/drivers/i2c/busses/i2c-sis5595.c
+++ b/drivers/i2c/busses/i2c-sis5595.c
@@ -123,11 +123,12 @@ static int blacklist[] = {
123 123
124/* If force_addr is set to anything different from 0, we forcibly enable 124/* If force_addr is set to anything different from 0, we forcibly enable
125 the device at the given address. */ 125 the device at the given address. */
126static u16 force_addr = 0; 126static u16 force_addr;
127module_param(force_addr, ushort, 0); 127module_param(force_addr, ushort, 0);
128MODULE_PARM_DESC(force_addr, "Initialize the base address of the i2c controller"); 128MODULE_PARM_DESC(force_addr, "Initialize the base address of the i2c controller");
129 129
130static unsigned short sis5595_base = 0; 130static struct pci_driver sis5595_driver;
131static unsigned short sis5595_base;
131 132
132static u8 sis5595_read(u8 reg) 133static u8 sis5595_read(u8 reg)
133{ 134{
@@ -172,7 +173,8 @@ static int sis5595_setup(struct pci_dev *SIS5595_dev)
172 173
173 /* NB: We grab just the two SMBus registers here, but this may still 174 /* NB: We grab just the two SMBus registers here, but this may still
174 * interfere with ACPI :-( */ 175 * interfere with ACPI :-( */
175 if (!request_region(sis5595_base + SMB_INDEX, 2, "sis5595-smbus")) { 176 if (!request_region(sis5595_base + SMB_INDEX, 2,
177 sis5595_driver.name)) {
176 dev_err(&SIS5595_dev->dev, "SMBus registers 0x%04x-0x%04x already in use!\n", 178 dev_err(&SIS5595_dev->dev, "SMBus registers 0x%04x-0x%04x already in use!\n",
177 sis5595_base + SMB_INDEX, sis5595_base + SMB_INDEX + 1); 179 sis5595_base + SMB_INDEX, sis5595_base + SMB_INDEX + 1);
178 return -ENODEV; 180 return -ENODEV;
@@ -364,7 +366,6 @@ static struct i2c_algorithm smbus_algorithm = {
364static struct i2c_adapter sis5595_adapter = { 366static struct i2c_adapter sis5595_adapter = {
365 .owner = THIS_MODULE, 367 .owner = THIS_MODULE,
366 .class = I2C_CLASS_HWMON, 368 .class = I2C_CLASS_HWMON,
367 .name = "unset",
368 .algo = &smbus_algorithm, 369 .algo = &smbus_algorithm,
369}; 370};
370 371
@@ -397,6 +398,7 @@ static void __devexit sis5595_remove(struct pci_dev *dev)
397} 398}
398 399
399static struct pci_driver sis5595_driver = { 400static struct pci_driver sis5595_driver = {
401 .owner = THIS_MODULE,
400 .name = "sis5595_smbus", 402 .name = "sis5595_smbus",
401 .id_table = sis5595_ids, 403 .id_table = sis5595_ids,
402 .probe = sis5595_probe, 404 .probe = sis5595_probe,
diff --git a/drivers/i2c/busses/i2c-sis630.c b/drivers/i2c/busses/i2c-sis630.c
index 86f0f448fa0b..7f49e5fd3ff0 100644
--- a/drivers/i2c/busses/i2c-sis630.c
+++ b/drivers/i2c/busses/i2c-sis630.c
@@ -92,6 +92,8 @@
92#define SIS630_PCALL 0x04 92#define SIS630_PCALL 0x04
93#define SIS630_BLOCK_DATA 0x05 93#define SIS630_BLOCK_DATA 0x05
94 94
95static struct pci_driver sis630_driver;
96
95/* insmod parameters */ 97/* insmod parameters */
96static int high_clock; 98static int high_clock;
97static int force; 99static int force;
@@ -101,7 +103,7 @@ module_param(force, bool, 0);
101MODULE_PARM_DESC(force, "Forcibly enable the SIS630. DANGEROUS!"); 103MODULE_PARM_DESC(force, "Forcibly enable the SIS630. DANGEROUS!");
102 104
103/* acpi base address */ 105/* acpi base address */
104static unsigned short acpi_base = 0; 106static unsigned short acpi_base;
105 107
106/* supported chips */ 108/* supported chips */
107static int supported[] = { 109static int supported[] = {
@@ -432,7 +434,8 @@ static int sis630_setup(struct pci_dev *sis630_dev)
432 dev_dbg(&sis630_dev->dev, "ACPI base at 0x%04x\n", acpi_base); 434 dev_dbg(&sis630_dev->dev, "ACPI base at 0x%04x\n", acpi_base);
433 435
434 /* Everything is happy, let's grab the memory and set things up. */ 436 /* Everything is happy, let's grab the memory and set things up. */
435 if (!request_region(acpi_base + SMB_STS, SIS630_SMB_IOREGION, "sis630-smbus")) { 437 if (!request_region(acpi_base + SMB_STS, SIS630_SMB_IOREGION,
438 sis630_driver.name)) {
436 dev_err(&sis630_dev->dev, "SMBus registers 0x%04x-0x%04x already " 439 dev_err(&sis630_dev->dev, "SMBus registers 0x%04x-0x%04x already "
437 "in use!\n", acpi_base + SMB_STS, acpi_base + SMB_SAA); 440 "in use!\n", acpi_base + SMB_STS, acpi_base + SMB_SAA);
438 goto exit; 441 goto exit;
@@ -455,7 +458,6 @@ static struct i2c_algorithm smbus_algorithm = {
455static struct i2c_adapter sis630_adapter = { 458static struct i2c_adapter sis630_adapter = {
456 .owner = THIS_MODULE, 459 .owner = THIS_MODULE,
457 .class = I2C_CLASS_HWMON, 460 .class = I2C_CLASS_HWMON,
458 .name = "unset",
459 .algo = &smbus_algorithm, 461 .algo = &smbus_algorithm,
460}; 462};
461 463
@@ -494,6 +496,7 @@ static void __devexit sis630_remove(struct pci_dev *dev)
494 496
495 497
496static struct pci_driver sis630_driver = { 498static struct pci_driver sis630_driver = {
499 .owner = THIS_MODULE,
497 .name = "sis630_smbus", 500 .name = "sis630_smbus",
498 .id_table = sis630_ids, 501 .id_table = sis630_ids,
499 .probe = sis630_probe, 502 .probe = sis630_probe,
diff --git a/drivers/i2c/busses/i2c-sis96x.c b/drivers/i2c/busses/i2c-sis96x.c
index ead2ff3cf60e..6a134c091324 100644
--- a/drivers/i2c/busses/i2c-sis96x.c
+++ b/drivers/i2c/busses/i2c-sis96x.c
@@ -82,8 +82,9 @@
82#define SIS96x_PROC_CALL 0x04 82#define SIS96x_PROC_CALL 0x04
83#define SIS96x_BLOCK_DATA 0x05 83#define SIS96x_BLOCK_DATA 0x05
84 84
85static struct pci_driver sis96x_driver;
85static struct i2c_adapter sis96x_adapter; 86static struct i2c_adapter sis96x_adapter;
86static u16 sis96x_smbus_base = 0; 87static u16 sis96x_smbus_base;
87 88
88static inline u8 sis96x_read(u8 reg) 89static inline u8 sis96x_read(u8 reg)
89{ 90{
@@ -257,7 +258,6 @@ static struct i2c_adapter sis96x_adapter = {
257 .owner = THIS_MODULE, 258 .owner = THIS_MODULE,
258 .class = I2C_CLASS_HWMON, 259 .class = I2C_CLASS_HWMON,
259 .algo = &smbus_algorithm, 260 .algo = &smbus_algorithm,
260 .name = "unset",
261}; 261};
262 262
263static struct pci_device_id sis96x_ids[] = { 263static struct pci_device_id sis96x_ids[] = {
@@ -294,7 +294,8 @@ static int __devinit sis96x_probe(struct pci_dev *dev,
294 sis96x_smbus_base); 294 sis96x_smbus_base);
295 295
296 /* Everything is happy, let's grab the memory and set things up. */ 296 /* Everything is happy, let's grab the memory and set things up. */
297 if (!request_region(sis96x_smbus_base, SMB_IOSIZE, "sis96x-smbus")) { 297 if (!request_region(sis96x_smbus_base, SMB_IOSIZE,
298 sis96x_driver.name)) {
298 dev_err(&dev->dev, "SMBus registers 0x%04x-0x%04x " 299 dev_err(&dev->dev, "SMBus registers 0x%04x-0x%04x "
299 "already in use!\n", sis96x_smbus_base, 300 "already in use!\n", sis96x_smbus_base,
300 sis96x_smbus_base + SMB_IOSIZE - 1); 301 sis96x_smbus_base + SMB_IOSIZE - 1);
@@ -328,6 +329,7 @@ static void __devexit sis96x_remove(struct pci_dev *dev)
328} 329}
329 330
330static struct pci_driver sis96x_driver = { 331static struct pci_driver sis96x_driver = {
332 .owner = THIS_MODULE,
331 .name = "sis96x_smbus", 333 .name = "sis96x_smbus",
332 .id_table = sis96x_ids, 334 .id_table = sis96x_ids,
333 .probe = sis96x_probe, 335 .probe = sis96x_probe,
diff --git a/drivers/i2c/busses/i2c-via.c b/drivers/i2c/busses/i2c-via.c
index 040b8abeabba..544a38e64394 100644
--- a/drivers/i2c/busses/i2c-via.c
+++ b/drivers/i2c/busses/i2c-via.c
@@ -43,9 +43,9 @@
43 43
44/* io-region reservation */ 44/* io-region reservation */
45#define IOSPACE 0x06 45#define IOSPACE 0x06
46#define IOTEXT "via-i2c"
47 46
48static u16 pm_io_base = 0; 47static struct pci_driver vt586b_driver;
48static u16 pm_io_base;
49 49
50/* 50/*
51 It does not appear from the datasheet that the GPIO pins are 51 It does not appear from the datasheet that the GPIO pins are
@@ -130,7 +130,7 @@ static int __devinit vt586b_probe(struct pci_dev *dev, const struct pci_device_i
130 pci_read_config_word(dev, base, &pm_io_base); 130 pci_read_config_word(dev, base, &pm_io_base);
131 pm_io_base &= (0xff << 8); 131 pm_io_base &= (0xff << 8);
132 132
133 if (!request_region(I2C_DIR, IOSPACE, IOTEXT)) { 133 if (!request_region(I2C_DIR, IOSPACE, vt586b_driver.name)) {
134 dev_err(&dev->dev, "IO 0x%x-0x%x already in use\n", I2C_DIR, I2C_DIR + IOSPACE); 134 dev_err(&dev->dev, "IO 0x%x-0x%x already in use\n", I2C_DIR, I2C_DIR + IOSPACE);
135 return -ENODEV; 135 return -ENODEV;
136 } 136 }
@@ -159,6 +159,7 @@ static void __devexit vt586b_remove(struct pci_dev *dev)
159 159
160 160
161static struct pci_driver vt586b_driver = { 161static struct pci_driver vt586b_driver = {
162 .owner = THIS_MODULE,
162 .name = "vt586b_smbus", 163 .name = "vt586b_smbus",
163 .id_table = vt586b_ids, 164 .id_table = vt586b_ids,
164 .probe = vt586b_probe, 165 .probe = vt586b_probe,
diff --git a/drivers/i2c/busses/i2c-viapro.c b/drivers/i2c/busses/i2c-viapro.c
index 99d209e0485a..c9366b504833 100644
--- a/drivers/i2c/busses/i2c-viapro.c
+++ b/drivers/i2c/busses/i2c-viapro.c
@@ -1,9 +1,10 @@
1/* 1/*
2 i2c-viapro.c - Part of lm_sensors, Linux kernel modules for hardware 2 i2c-viapro.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring 3 monitoring
4 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>, 4 Copyright (c) 1998 - 2002 Frodo Looijaard <frodol@dds.nl>,
5 Philip Edelbrock <phil@netroedge.com>, Kyösti Mälkki <kmalkki@cc.hut.fi>, 5 Philip Edelbrock <phil@netroedge.com>, Kyösti Mälkki <kmalkki@cc.hut.fi>,
6 Mark D. Studebaker <mdsxyz123@yahoo.com> 6 Mark D. Studebaker <mdsxyz123@yahoo.com>
7 Copyright (C) 2005 Jean Delvare <khali@linux-fr.org>
7 8
8 This program is free software; you can redistribute it and/or modify 9 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by 10 it under the terms of the GNU General Public License as published by
@@ -21,15 +22,19 @@
21*/ 22*/
22 23
23/* 24/*
24 Supports Via devices: 25 Supports the following VIA south bridges:
25 82C596A/B (0x3050) 26
26 82C596B (0x3051) 27 Chip name PCI ID REV I2C block
27 82C686A/B 28 VT82C596A 0x3050 no
28 8231 29 VT82C596B 0x3051 no
29 8233 30 VT82C686A 0x3057 0x30 no
30 8233A (0x3147 and 0x3177) 31 VT82C686B 0x3057 0x40 yes
31 8235 32 VT8231 0x8235 no?
32 8237 33 VT8233 0x3074 yes
34 VT8233A 0x3147 yes?
35 VT8235 0x3177 yes
36 VT8237R 0x3227 yes
37
33 Note: we assume there can only be one device, with one SMBus interface. 38 Note: we assume there can only be one device, with one SMBus interface.
34*/ 39*/
35 40
@@ -38,7 +43,6 @@
38#include <linux/pci.h> 43#include <linux/pci.h>
39#include <linux/kernel.h> 44#include <linux/kernel.h>
40#include <linux/stddef.h> 45#include <linux/stddef.h>
41#include <linux/sched.h>
42#include <linux/ioport.h> 46#include <linux/ioport.h>
43#include <linux/i2c.h> 47#include <linux/i2c.h>
44#include <linux/init.h> 48#include <linux/init.h>
@@ -46,48 +50,37 @@
46 50
47static struct pci_dev *vt596_pdev; 51static struct pci_dev *vt596_pdev;
48 52
49#define SMBBA1 0x90 53#define SMBBA1 0x90
50#define SMBBA2 0x80 54#define SMBBA2 0x80
51#define SMBBA3 0xD0 55#define SMBBA3 0xD0
52 56
53/* SMBus address offsets */ 57/* SMBus address offsets */
54static unsigned short vt596_smba; 58static unsigned short vt596_smba;
55#define SMBHSTSTS (vt596_smba + 0) 59#define SMBHSTSTS (vt596_smba + 0)
56#define SMBHSLVSTS (vt596_smba + 1)
57#define SMBHSTCNT (vt596_smba + 2) 60#define SMBHSTCNT (vt596_smba + 2)
58#define SMBHSTCMD (vt596_smba + 3) 61#define SMBHSTCMD (vt596_smba + 3)
59#define SMBHSTADD (vt596_smba + 4) 62#define SMBHSTADD (vt596_smba + 4)
60#define SMBHSTDAT0 (vt596_smba + 5) 63#define SMBHSTDAT0 (vt596_smba + 5)
61#define SMBHSTDAT1 (vt596_smba + 6) 64#define SMBHSTDAT1 (vt596_smba + 6)
62#define SMBBLKDAT (vt596_smba + 7) 65#define SMBBLKDAT (vt596_smba + 7)
63#define SMBSLVCNT (vt596_smba + 8)
64#define SMBSHDWCMD (vt596_smba + 9)
65#define SMBSLVEVT (vt596_smba + 0xA)
66#define SMBSLVDAT (vt596_smba + 0xC)
67 66
68/* PCI Address Constants */ 67/* PCI Address Constants */
69 68
70/* SMBus data in configuration space can be found in two places, 69/* SMBus data in configuration space can be found in two places,
71 We try to select the better one*/ 70 We try to select the better one */
72
73static unsigned short smb_cf_hstcfg = 0xD2;
74 71
75#define SMBHSTCFG (smb_cf_hstcfg) 72static unsigned short SMBHSTCFG = 0xD2;
76#define SMBSLVC (smb_cf_hstcfg + 1)
77#define SMBSHDW1 (smb_cf_hstcfg + 2)
78#define SMBSHDW2 (smb_cf_hstcfg + 3)
79#define SMBREV (smb_cf_hstcfg + 4)
80 73
81/* Other settings */ 74/* Other settings */
82#define MAX_TIMEOUT 500 75#define MAX_TIMEOUT 500
83#define ENABLE_INT9 0
84 76
85/* VT82C596 constants */ 77/* VT82C596 constants */
86#define VT596_QUICK 0x00 78#define VT596_QUICK 0x00
87#define VT596_BYTE 0x04 79#define VT596_BYTE 0x04
88#define VT596_BYTE_DATA 0x08 80#define VT596_BYTE_DATA 0x08
89#define VT596_WORD_DATA 0x0C 81#define VT596_WORD_DATA 0x0C
90#define VT596_BLOCK_DATA 0x14 82#define VT596_BLOCK_DATA 0x14
83#define VT596_I2C_BLOCK_DATA 0x34
91 84
92 85
93/* If force is set to anything different from 0, we forcibly enable the 86/* If force is set to anything different from 0, we forcibly enable the
@@ -105,40 +98,65 @@ MODULE_PARM_DESC(force_addr,
105 "EXTREMELY DANGEROUS!"); 98 "EXTREMELY DANGEROUS!");
106 99
107 100
101static struct pci_driver vt596_driver;
108static struct i2c_adapter vt596_adapter; 102static struct i2c_adapter vt596_adapter;
109 103
110/* Another internally used function */ 104#define FEATURE_I2CBLOCK (1<<0)
111static int vt596_transaction(void) 105static unsigned int vt596_features;
106
107#ifdef DEBUG
108static void vt596_dump_regs(const char *msg, u8 size)
109{
110 dev_dbg(&vt596_adapter.dev, "%s: STS=%02x CNT=%02x CMD=%02x ADD=%02x "
111 "DAT=%02x,%02x\n", msg, inb_p(SMBHSTSTS), inb_p(SMBHSTCNT),
112 inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
113 inb_p(SMBHSTDAT1));
114
115 if (size == VT596_BLOCK_DATA
116 || size == VT596_I2C_BLOCK_DATA) {
117 int i;
118
119 dev_dbg(&vt596_adapter.dev, "BLK=");
120 for (i = 0; i < I2C_SMBUS_BLOCK_MAX / 2; i++)
121 printk("%02x,", inb_p(SMBBLKDAT));
122 printk("\n");
123 dev_dbg(&vt596_adapter.dev, " ");
124 for (; i < I2C_SMBUS_BLOCK_MAX - 1; i++)
125 printk("%02x,", inb_p(SMBBLKDAT));
126 printk("%02x\n", inb_p(SMBBLKDAT));
127 }
128}
129#else
130static inline void vt596_dump_regs(const char *msg, u8 size) { }
131#endif
132
133/* Return -1 on error, 0 on success */
134static int vt596_transaction(u8 size)
112{ 135{
113 int temp; 136 int temp;
114 int result = 0; 137 int result = 0;
115 int timeout = 0; 138 int timeout = 0;
116 139
117 dev_dbg(&vt596_adapter.dev, "Transaction (pre): CNT=%02x, CMD=%02x, " 140 vt596_dump_regs("Transaction (pre)", size);
118 "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT),
119 inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
120 inb_p(SMBHSTDAT1));
121 141
122 /* Make sure the SMBus host is ready to start transmitting */ 142 /* Make sure the SMBus host is ready to start transmitting */
123 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { 143 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) {
124 dev_dbg(&vt596_adapter.dev, "SMBus busy (0x%02x). " 144 dev_dbg(&vt596_adapter.dev, "SMBus busy (0x%02x). "
125 "Resetting...\n", temp); 145 "Resetting... ", temp);
126 146
127 outb_p(temp, SMBHSTSTS); 147 outb_p(temp, SMBHSTSTS);
128 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { 148 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) {
129 dev_dbg(&vt596_adapter.dev, "Failed! (0x%02x)\n", temp); 149 printk("Failed! (0x%02x)\n", temp);
130
131 return -1; 150 return -1;
132 } else { 151 } else {
133 dev_dbg(&vt596_adapter.dev, "Successfull!\n"); 152 printk("Successful!\n");
134 } 153 }
135 } 154 }
136 155
137 /* start the transaction by setting bit 6 */ 156 /* Start the transaction by setting bit 6 */
138 outb_p(inb(SMBHSTCNT) | 0x040, SMBHSTCNT); 157 outb_p(0x40 | (size & 0x3C), SMBHSTCNT);
139 158
140 /* We will always wait for a fraction of a second! 159 /* We will always wait for a fraction of a second */
141 I don't know if VIA needs this, Intel did */
142 do { 160 do {
143 msleep(1); 161 msleep(1);
144 temp = inb_p(SMBHSTSTS); 162 temp = inb_p(SMBHSTSTS);
@@ -147,77 +165,61 @@ static int vt596_transaction(void)
147 /* If the SMBus is still busy, we give up */ 165 /* If the SMBus is still busy, we give up */
148 if (timeout >= MAX_TIMEOUT) { 166 if (timeout >= MAX_TIMEOUT) {
149 result = -1; 167 result = -1;
150 dev_dbg(&vt596_adapter.dev, "SMBus Timeout!\n"); 168 dev_err(&vt596_adapter.dev, "SMBus timeout!\n");
151 } 169 }
152 170
153 if (temp & 0x10) { 171 if (temp & 0x10) {
154 result = -1; 172 result = -1;
155 dev_dbg(&vt596_adapter.dev, "Error: Failed bus transaction\n"); 173 dev_err(&vt596_adapter.dev, "Transaction failed (0x%02x)\n",
174 inb_p(SMBHSTCNT) & 0x3C);
156 } 175 }
157 176
158 if (temp & 0x08) { 177 if (temp & 0x08) {
159 result = -1; 178 result = -1;
160 dev_info(&vt596_adapter.dev, "Bus collision! SMBus may be " 179 dev_err(&vt596_adapter.dev, "SMBus collision!\n");
161 "locked until next hard\nreset. (sorry!)\n");
162 /* Clock stops and slave is stuck in mid-transmission */
163 } 180 }
164 181
165 if (temp & 0x04) { 182 if (temp & 0x04) {
166 result = -1; 183 result = -1;
167 dev_dbg(&vt596_adapter.dev, "Error: no response!\n"); 184 /* Quick commands are used to probe for chips, so
185 errors are expected, and we don't want to frighten the
186 user. */
187 if ((inb_p(SMBHSTCNT) & 0x3C) != VT596_QUICK)
188 dev_err(&vt596_adapter.dev, "Transaction error!\n");
168 } 189 }
169 190
170 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) { 191 /* Resetting status register */
192 if (temp & 0x1F)
171 outb_p(temp, SMBHSTSTS); 193 outb_p(temp, SMBHSTSTS);
172 if ((temp = inb_p(SMBHSTSTS)) & 0x1F) {
173 dev_warn(&vt596_adapter.dev, "Failed reset at end "
174 "of transaction (%02x)\n", temp);
175 }
176 }
177 194
178 dev_dbg(&vt596_adapter.dev, "Transaction (post): CNT=%02x, CMD=%02x, " 195 vt596_dump_regs("Transaction (post)", size);
179 "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTCNT), 196
180 inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0),
181 inb_p(SMBHSTDAT1));
182
183 return result; 197 return result;
184} 198}
185 199
186/* Return -1 on error. */ 200/* Return -1 on error, 0 on success */
187static s32 vt596_access(struct i2c_adapter *adap, u16 addr, 201static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
188 unsigned short flags, char read_write, u8 command, 202 unsigned short flags, char read_write, u8 command,
189 int size, union i2c_smbus_data *data) 203 int size, union i2c_smbus_data *data)
190{ 204{
191 int i, len; 205 int i;
192 206
193 switch (size) { 207 switch (size) {
194 case I2C_SMBUS_PROC_CALL:
195 dev_info(&vt596_adapter.dev,
196 "I2C_SMBUS_PROC_CALL not supported!\n");
197 return -1;
198 case I2C_SMBUS_QUICK: 208 case I2C_SMBUS_QUICK:
199 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
200 SMBHSTADD);
201 size = VT596_QUICK; 209 size = VT596_QUICK;
202 break; 210 break;
203 case I2C_SMBUS_BYTE: 211 case I2C_SMBUS_BYTE:
204 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
205 SMBHSTADD);
206 if (read_write == I2C_SMBUS_WRITE) 212 if (read_write == I2C_SMBUS_WRITE)
207 outb_p(command, SMBHSTCMD); 213 outb_p(command, SMBHSTCMD);
208 size = VT596_BYTE; 214 size = VT596_BYTE;
209 break; 215 break;
210 case I2C_SMBUS_BYTE_DATA: 216 case I2C_SMBUS_BYTE_DATA:
211 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
212 SMBHSTADD);
213 outb_p(command, SMBHSTCMD); 217 outb_p(command, SMBHSTCMD);
214 if (read_write == I2C_SMBUS_WRITE) 218 if (read_write == I2C_SMBUS_WRITE)
215 outb_p(data->byte, SMBHSTDAT0); 219 outb_p(data->byte, SMBHSTDAT0);
216 size = VT596_BYTE_DATA; 220 size = VT596_BYTE_DATA;
217 break; 221 break;
218 case I2C_SMBUS_WORD_DATA: 222 case I2C_SMBUS_WORD_DATA:
219 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
220 SMBHSTADD);
221 outb_p(command, SMBHSTCMD); 223 outb_p(command, SMBHSTCMD);
222 if (read_write == I2C_SMBUS_WRITE) { 224 if (read_write == I2C_SMBUS_WRITE) {
223 outb_p(data->word & 0xff, SMBHSTDAT0); 225 outb_p(data->word & 0xff, SMBHSTDAT0);
@@ -225,28 +227,33 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
225 } 227 }
226 size = VT596_WORD_DATA; 228 size = VT596_WORD_DATA;
227 break; 229 break;
230 case I2C_SMBUS_I2C_BLOCK_DATA:
231 if (!(vt596_features & FEATURE_I2CBLOCK))
232 goto exit_unsupported;
233 if (read_write == I2C_SMBUS_READ)
234 outb_p(I2C_SMBUS_BLOCK_MAX, SMBHSTDAT0);
235 /* Fall through */
228 case I2C_SMBUS_BLOCK_DATA: 236 case I2C_SMBUS_BLOCK_DATA:
229 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01),
230 SMBHSTADD);
231 outb_p(command, SMBHSTCMD); 237 outb_p(command, SMBHSTCMD);
232 if (read_write == I2C_SMBUS_WRITE) { 238 if (read_write == I2C_SMBUS_WRITE) {
233 len = data->block[0]; 239 u8 len = data->block[0];
234 if (len < 0)
235 len = 0;
236 if (len > I2C_SMBUS_BLOCK_MAX) 240 if (len > I2C_SMBUS_BLOCK_MAX)
237 len = I2C_SMBUS_BLOCK_MAX; 241 len = I2C_SMBUS_BLOCK_MAX;
238 outb_p(len, SMBHSTDAT0); 242 outb_p(len, SMBHSTDAT0);
239 i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ 243 inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
240 for (i = 1; i <= len; i++) 244 for (i = 1; i <= len; i++)
241 outb_p(data->block[i], SMBBLKDAT); 245 outb_p(data->block[i], SMBBLKDAT);
242 } 246 }
243 size = VT596_BLOCK_DATA; 247 size = (size == I2C_SMBUS_I2C_BLOCK_DATA) ?
248 VT596_I2C_BLOCK_DATA : VT596_BLOCK_DATA;
244 break; 249 break;
250 default:
251 goto exit_unsupported;
245 } 252 }
246 253
247 outb_p((size & 0x1C) + (ENABLE_INT9 & 1), SMBHSTCNT); 254 outb_p(((addr & 0x7f) << 1) | read_write, SMBHSTADD);
248 255
249 if (vt596_transaction()) /* Error in transaction */ 256 if (vt596_transaction(size)) /* Error in transaction */
250 return -1; 257 return -1;
251 258
252 if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK)) 259 if ((read_write == I2C_SMBUS_WRITE) || (size == VT596_QUICK))
@@ -254,35 +261,39 @@ static s32 vt596_access(struct i2c_adapter *adap, u16 addr,
254 261
255 switch (size) { 262 switch (size) {
256 case VT596_BYTE: 263 case VT596_BYTE:
257 /* Where is the result put? I assume here it is in
258 * SMBHSTDAT0 but it might just as well be in the
259 * SMBHSTCMD. No clue in the docs
260 */
261 data->byte = inb_p(SMBHSTDAT0);
262 break;
263 case VT596_BYTE_DATA: 264 case VT596_BYTE_DATA:
264 data->byte = inb_p(SMBHSTDAT0); 265 data->byte = inb_p(SMBHSTDAT0);
265 break; 266 break;
266 case VT596_WORD_DATA: 267 case VT596_WORD_DATA:
267 data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8); 268 data->word = inb_p(SMBHSTDAT0) + (inb_p(SMBHSTDAT1) << 8);
268 break; 269 break;
270 case VT596_I2C_BLOCK_DATA:
269 case VT596_BLOCK_DATA: 271 case VT596_BLOCK_DATA:
270 data->block[0] = inb_p(SMBHSTDAT0); 272 data->block[0] = inb_p(SMBHSTDAT0);
271 if (data->block[0] > I2C_SMBUS_BLOCK_MAX) 273 if (data->block[0] > I2C_SMBUS_BLOCK_MAX)
272 data->block[0] = I2C_SMBUS_BLOCK_MAX; 274 data->block[0] = I2C_SMBUS_BLOCK_MAX;
273 i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ 275 inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
274 for (i = 1; i <= data->block[0]; i++) 276 for (i = 1; i <= data->block[0]; i++)
275 data->block[i] = inb_p(SMBBLKDAT); 277 data->block[i] = inb_p(SMBBLKDAT);
276 break; 278 break;
277 } 279 }
278 return 0; 280 return 0;
281
282exit_unsupported:
283 dev_warn(&vt596_adapter.dev, "Unsupported command invoked! (0x%02x)\n",
284 size);
285 return -1;
279} 286}
280 287
281static u32 vt596_func(struct i2c_adapter *adapter) 288static u32 vt596_func(struct i2c_adapter *adapter)
282{ 289{
283 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | 290 u32 func = I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE |
284 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA | 291 I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA |
285 I2C_FUNC_SMBUS_BLOCK_DATA; 292 I2C_FUNC_SMBUS_BLOCK_DATA;
293
294 if (vt596_features & FEATURE_I2CBLOCK)
295 func |= I2C_FUNC_SMBUS_I2C_BLOCK;
296 return func;
286} 297}
287 298
288static struct i2c_algorithm smbus_algorithm = { 299static struct i2c_algorithm smbus_algorithm = {
@@ -294,7 +305,6 @@ static struct i2c_adapter vt596_adapter = {
294 .owner = THIS_MODULE, 305 .owner = THIS_MODULE,
295 .class = I2C_CLASS_HWMON, 306 .class = I2C_CLASS_HWMON,
296 .algo = &smbus_algorithm, 307 .algo = &smbus_algorithm,
297 .name = "unset",
298}; 308};
299 309
300static int __devinit vt596_probe(struct pci_dev *pdev, 310static int __devinit vt596_probe(struct pci_dev *pdev,
@@ -302,7 +312,7 @@ static int __devinit vt596_probe(struct pci_dev *pdev,
302{ 312{
303 unsigned char temp; 313 unsigned char temp;
304 int error = -ENODEV; 314 int error = -ENODEV;
305 315
306 /* Determine the address of the SMBus areas */ 316 /* Determine the address of the SMBus areas */
307 if (force_addr) { 317 if (force_addr) {
308 vt596_smba = force_addr & 0xfff0; 318 vt596_smba = force_addr & 0xfff0;
@@ -311,12 +321,12 @@ static int __devinit vt596_probe(struct pci_dev *pdev,
311 } 321 }
312 322
313 if ((pci_read_config_word(pdev, id->driver_data, &vt596_smba)) || 323 if ((pci_read_config_word(pdev, id->driver_data, &vt596_smba)) ||
314 !(vt596_smba & 0x1)) { 324 !(vt596_smba & 0x0001)) {
315 /* try 2nd address and config reg. for 596 */ 325 /* try 2nd address and config reg. for 596 */
316 if (id->device == PCI_DEVICE_ID_VIA_82C596_3 && 326 if (id->device == PCI_DEVICE_ID_VIA_82C596_3 &&
317 !pci_read_config_word(pdev, SMBBA2, &vt596_smba) && 327 !pci_read_config_word(pdev, SMBBA2, &vt596_smba) &&
318 (vt596_smba & 0x1)) { 328 (vt596_smba & 0x0001)) {
319 smb_cf_hstcfg = 0x84; 329 SMBHSTCFG = 0x84;
320 } else { 330 } else {
321 /* no matches at all */ 331 /* no matches at all */
322 dev_err(&pdev->dev, "Cannot configure " 332 dev_err(&pdev->dev, "Cannot configure "
@@ -333,10 +343,10 @@ static int __devinit vt596_probe(struct pci_dev *pdev,
333 return -ENODEV; 343 return -ENODEV;
334 } 344 }
335 345
336 found: 346found:
337 if (!request_region(vt596_smba, 8, "viapro-smbus")) { 347 if (!request_region(vt596_smba, 8, vt596_driver.name)) {
338 dev_err(&pdev->dev, "SMBus region 0x%x already in use!\n", 348 dev_err(&pdev->dev, "SMBus region 0x%x already in use!\n",
339 vt596_smba); 349 vt596_smba);
340 return -ENODEV; 350 return -ENODEV;
341 } 351 }
342 352
@@ -348,16 +358,16 @@ static int __devinit vt596_probe(struct pci_dev *pdev,
348 pci_write_config_word(pdev, id->driver_data, vt596_smba); 358 pci_write_config_word(pdev, id->driver_data, vt596_smba);
349 pci_write_config_byte(pdev, SMBHSTCFG, temp | 0x01); 359 pci_write_config_byte(pdev, SMBHSTCFG, temp | 0x01);
350 dev_warn(&pdev->dev, "WARNING: SMBus interface set to new " 360 dev_warn(&pdev->dev, "WARNING: SMBus interface set to new "
351 "address 0x%04x!\n", vt596_smba); 361 "address 0x%04x!\n", vt596_smba);
352 } else if ((temp & 1) == 0) { 362 } else if (!(temp & 0x01)) {
353 if (force) { 363 if (force) {
354 /* NOTE: This assumes I/O space and other allocations 364 /* NOTE: This assumes I/O space and other allocations
355 * WERE done by the Bios! Don't complain if your 365 * WERE done by the Bios! Don't complain if your
356 * hardware does weird things after enabling this. 366 * hardware does weird things after enabling this.
357 * :') Check for Bios updates before resorting to 367 * :') Check for Bios updates before resorting to
358 * this. 368 * this.
359 */ 369 */
360 pci_write_config_byte(pdev, SMBHSTCFG, temp | 1); 370 pci_write_config_byte(pdev, SMBHSTCFG, temp | 0x01);
361 dev_info(&pdev->dev, "Enabling SMBus device\n"); 371 dev_info(&pdev->dev, "Enabling SMBus device\n");
362 } else { 372 } else {
363 dev_err(&pdev->dev, "SMBUS: Error: Host SMBus " 373 dev_err(&pdev->dev, "SMBUS: Error: Host SMBus "
@@ -367,22 +377,28 @@ static int __devinit vt596_probe(struct pci_dev *pdev,
367 } 377 }
368 } 378 }
369 379
370 if ((temp & 0x0E) == 8)
371 dev_dbg(&pdev->dev, "using Interrupt 9 for SMBus.\n");
372 else if ((temp & 0x0E) == 0)
373 dev_dbg(&pdev->dev, "using Interrupt SMI# for SMBus.\n");
374 else
375 dev_dbg(&pdev->dev, "Illegal Interrupt configuration "
376 "(or code out of date)!\n");
377
378 pci_read_config_byte(pdev, SMBREV, &temp);
379 dev_dbg(&pdev->dev, "SMBREV = 0x%X\n", temp);
380 dev_dbg(&pdev->dev, "VT596_smba = 0x%X\n", vt596_smba); 380 dev_dbg(&pdev->dev, "VT596_smba = 0x%X\n", vt596_smba);
381 381
382 switch (pdev->device) {
383 case PCI_DEVICE_ID_VIA_8237:
384 case PCI_DEVICE_ID_VIA_8235:
385 case PCI_DEVICE_ID_VIA_8233A:
386 case PCI_DEVICE_ID_VIA_8233_0:
387 vt596_features |= FEATURE_I2CBLOCK;
388 break;
389 case PCI_DEVICE_ID_VIA_82C686_4:
390 /* The VT82C686B (rev 0x40) does support I2C block
391 transactions, but the VT82C686A (rev 0x30) doesn't */
392 if (!pci_read_config_byte(pdev, PCI_REVISION_ID, &temp)
393 && temp >= 0x40)
394 vt596_features |= FEATURE_I2CBLOCK;
395 break;
396 }
397
382 vt596_adapter.dev.parent = &pdev->dev; 398 vt596_adapter.dev.parent = &pdev->dev;
383 snprintf(vt596_adapter.name, I2C_NAME_SIZE, 399 snprintf(vt596_adapter.name, I2C_NAME_SIZE,
384 "SMBus Via Pro adapter at %04x", vt596_smba); 400 "SMBus Via Pro adapter at %04x", vt596_smba);
385 401
386 vt596_pdev = pci_dev_get(pdev); 402 vt596_pdev = pci_dev_get(pdev);
387 if (i2c_add_adapter(&vt596_adapter)) { 403 if (i2c_add_adapter(&vt596_adapter)) {
388 pci_dev_put(vt596_pdev); 404 pci_dev_put(vt596_pdev);
@@ -395,7 +411,7 @@ static int __devinit vt596_probe(struct pci_dev *pdev,
395 */ 411 */
396 return -ENODEV; 412 return -ENODEV;
397 413
398 release_region: 414release_region:
399 release_region(vt596_smba, 8); 415 release_region(vt596_smba, 8);
400 return error; 416 return error;
401} 417}
@@ -420,9 +436,10 @@ static struct pci_device_id vt596_ids[] = {
420 { 0, } 436 { 0, }
421}; 437};
422 438
423MODULE_DEVICE_TABLE (pci, vt596_ids); 439MODULE_DEVICE_TABLE(pci, vt596_ids);
424 440
425static struct pci_driver vt596_driver = { 441static struct pci_driver vt596_driver = {
442 .owner = THIS_MODULE,
426 .name = "vt596_smbus", 443 .name = "vt596_smbus",
427 .id_table = vt596_ids, 444 .id_table = vt596_ids,
428 .probe = vt596_probe, 445 .probe = vt596_probe,
diff --git a/drivers/i2c/busses/i2c-voodoo3.c b/drivers/i2c/busses/i2c-voodoo3.c
index b675773b0cc1..650c3ebde84c 100644
--- a/drivers/i2c/busses/i2c-voodoo3.c
+++ b/drivers/i2c/busses/i2c-voodoo3.c
@@ -225,6 +225,7 @@ static void __devexit voodoo3_remove(struct pci_dev *dev)
225} 225}
226 226
227static struct pci_driver voodoo3_driver = { 227static struct pci_driver voodoo3_driver = {
228 .owner = THIS_MODULE,
228 .name = "voodoo3_smbus", 229 .name = "voodoo3_smbus",
229 .id_table = voodoo3_ids, 230 .id_table = voodoo3_ids,
230 .probe = voodoo3_probe, 231 .probe = voodoo3_probe,
diff --git a/drivers/i2c/busses/scx200_acb.c b/drivers/i2c/busses/scx200_acb.c
index a1d580e05361..d3478e084522 100644
--- a/drivers/i2c/busses/scx200_acb.c
+++ b/drivers/i2c/busses/scx200_acb.c
@@ -442,14 +442,13 @@ static int __init scx200_acb_create(int base, int index)
442 int rc = 0; 442 int rc = 0;
443 char description[64]; 443 char description[64];
444 444
445 iface = kmalloc(sizeof(*iface), GFP_KERNEL); 445 iface = kzalloc(sizeof(*iface), GFP_KERNEL);
446 if (!iface) { 446 if (!iface) {
447 printk(KERN_ERR NAME ": can't allocate memory\n"); 447 printk(KERN_ERR NAME ": can't allocate memory\n");
448 rc = -ENOMEM; 448 rc = -ENOMEM;
449 goto errout; 449 goto errout;
450 } 450 }
451 451
452 memset(iface, 0, sizeof(*iface));
453 adapter = &iface->adapter; 452 adapter = &iface->adapter;
454 i2c_set_adapdata(adapter, iface); 453 i2c_set_adapdata(adapter, iface);
455 snprintf(adapter->name, I2C_NAME_SIZE, "SCx200 ACB%d", index); 454 snprintf(adapter->name, I2C_NAME_SIZE, "SCx200 ACB%d", index);
diff --git a/drivers/i2c/chips/Kconfig b/drivers/i2c/chips/Kconfig
index 6bd44a44cd28..f9fae28f5612 100644
--- a/drivers/i2c/chips/Kconfig
+++ b/drivers/i2c/chips/Kconfig
@@ -126,4 +126,13 @@ config SENSORS_MAX6875
126 This driver can also be built as a module. If so, the module 126 This driver can also be built as a module. If so, the module
127 will be called max6875. 127 will be called max6875.
128 128
129config RTC_X1205_I2C
130 tristate "Xicor X1205 RTC chip"
131 depends on I2C && EXPERIMENTAL
132 help
133 If you say yes here you get support for the Xicor X1205 RTC chip.
134
135 This driver can also be built as a module. If so, the module
136 will be called x1205.
137
129endmenu 138endmenu
diff --git a/drivers/i2c/chips/Makefile b/drivers/i2c/chips/Makefile
index a876dd42b860..46178b57b1f1 100644
--- a/drivers/i2c/chips/Makefile
+++ b/drivers/i2c/chips/Makefile
@@ -13,6 +13,7 @@ obj-$(CONFIG_SENSORS_PCF8591) += pcf8591.o
13obj-$(CONFIG_SENSORS_RTC8564) += rtc8564.o 13obj-$(CONFIG_SENSORS_RTC8564) += rtc8564.o
14obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o 14obj-$(CONFIG_ISP1301_OMAP) += isp1301_omap.o
15obj-$(CONFIG_TPS65010) += tps65010.o 15obj-$(CONFIG_TPS65010) += tps65010.o
16obj-$(CONFIG_RTC_X1205_I2C) += x1205.o
16 17
17ifeq ($(CONFIG_I2C_DEBUG_CHIP),y) 18ifeq ($(CONFIG_I2C_DEBUG_CHIP),y)
18EXTRA_CFLAGS += -DDEBUG 19EXTRA_CFLAGS += -DDEBUG
diff --git a/drivers/i2c/chips/ds1337.c b/drivers/i2c/chips/ds1337.c
index 9d3175c03395..01b037007410 100644
--- a/drivers/i2c/chips/ds1337.c
+++ b/drivers/i2c/chips/ds1337.c
@@ -243,11 +243,10 @@ static int ds1337_detect(struct i2c_adapter *adapter, int address, int kind)
243 I2C_FUNC_I2C)) 243 I2C_FUNC_I2C))
244 goto exit; 244 goto exit;
245 245
246 if (!(data = kmalloc(sizeof(struct ds1337_data), GFP_KERNEL))) { 246 if (!(data = kzalloc(sizeof(struct ds1337_data), GFP_KERNEL))) {
247 err = -ENOMEM; 247 err = -ENOMEM;
248 goto exit; 248 goto exit;
249 } 249 }
250 memset(data, 0, sizeof(struct ds1337_data));
251 INIT_LIST_HEAD(&data->list); 250 INIT_LIST_HEAD(&data->list);
252 251
253 /* The common I2C client data is placed right before the 252 /* The common I2C client data is placed right before the
diff --git a/drivers/i2c/chips/ds1374.c b/drivers/i2c/chips/ds1374.c
index 0936327a946d..da488b735abf 100644
--- a/drivers/i2c/chips/ds1374.c
+++ b/drivers/i2c/chips/ds1374.c
@@ -167,7 +167,8 @@ static void ds1374_set_tlet(ulong arg)
167 167
168static ulong new_time; 168static ulong new_time;
169 169
170DECLARE_TASKLET_DISABLED(ds1374_tasklet, ds1374_set_tlet, (ulong) & new_time); 170static DECLARE_TASKLET_DISABLED(ds1374_tasklet, ds1374_set_tlet,
171 (ulong) & new_time);
171 172
172int ds1374_set_rtc_time(ulong nowtime) 173int ds1374_set_rtc_time(ulong nowtime)
173{ 174{
@@ -193,13 +194,11 @@ static int ds1374_probe(struct i2c_adapter *adap, int addr, int kind)
193 struct i2c_client *client; 194 struct i2c_client *client;
194 int rc; 195 int rc;
195 196
196 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); 197 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
197 if (!client) 198 if (!client)
198 return -ENOMEM; 199 return -ENOMEM;
199 200
200 memset(client, 0, sizeof(struct i2c_client));
201 strncpy(client->name, DS1374_DRV_NAME, I2C_NAME_SIZE); 201 strncpy(client->name, DS1374_DRV_NAME, I2C_NAME_SIZE);
202 client->flags = I2C_DF_NOTIFY;
203 client->addr = addr; 202 client->addr = addr;
204 client->adapter = adap; 203 client->adapter = adap;
205 client->driver = &ds1374_driver; 204 client->driver = &ds1374_driver;
diff --git a/drivers/i2c/chips/eeprom.c b/drivers/i2c/chips/eeprom.c
index d58403a47908..4baf573fa04f 100644
--- a/drivers/i2c/chips/eeprom.c
+++ b/drivers/i2c/chips/eeprom.c
@@ -88,8 +88,8 @@ static void eeprom_update_client(struct i2c_client *client, u8 slice)
88 dev_dbg(&client->dev, "Starting eeprom update, slice %u\n", slice); 88 dev_dbg(&client->dev, "Starting eeprom update, slice %u\n", slice);
89 89
90 if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) { 90 if (i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_READ_I2C_BLOCK)) {
91 for (i = slice << 5; i < (slice + 1) << 5; i += I2C_SMBUS_I2C_BLOCK_MAX) 91 for (i = slice << 5; i < (slice + 1) << 5; i += I2C_SMBUS_BLOCK_MAX)
92 if (i2c_smbus_read_i2c_block_data(client, i, data->data + i) != I2C_SMBUS_I2C_BLOCK_MAX) 92 if (i2c_smbus_read_i2c_block_data(client, i, data->data + i) != I2C_SMBUS_BLOCK_MAX)
93 goto exit; 93 goto exit;
94 } else { 94 } else {
95 if (i2c_smbus_write_byte(client, slice << 5)) { 95 if (i2c_smbus_write_byte(client, slice << 5)) {
@@ -155,7 +155,7 @@ static int eeprom_attach_adapter(struct i2c_adapter *adapter)
155} 155}
156 156
157/* This function is called by i2c_probe */ 157/* This function is called by i2c_probe */
158int eeprom_detect(struct i2c_adapter *adapter, int address, int kind) 158static int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
159{ 159{
160 struct i2c_client *new_client; 160 struct i2c_client *new_client;
161 struct eeprom_data *data; 161 struct eeprom_data *data;
@@ -171,11 +171,10 @@ int eeprom_detect(struct i2c_adapter *adapter, int address, int kind)
171 | I2C_FUNC_SMBUS_BYTE)) 171 | I2C_FUNC_SMBUS_BYTE))
172 goto exit; 172 goto exit;
173 173
174 if (!(data = kmalloc(sizeof(struct eeprom_data), GFP_KERNEL))) { 174 if (!(data = kzalloc(sizeof(struct eeprom_data), GFP_KERNEL))) {
175 err = -ENOMEM; 175 err = -ENOMEM;
176 goto exit; 176 goto exit;
177 } 177 }
178 memset(data, 0, sizeof(struct eeprom_data));
179 178
180 new_client = &data->client; 179 new_client = &data->client;
181 memset(data->data, 0xff, EEPROM_SIZE); 180 memset(data->data, 0xff, EEPROM_SIZE);
diff --git a/drivers/i2c/chips/isp1301_omap.c b/drivers/i2c/chips/isp1301_omap.c
index 8ee56d4b3891..eaa4742e04fa 100644
--- a/drivers/i2c/chips/isp1301_omap.c
+++ b/drivers/i2c/chips/isp1301_omap.c
@@ -888,6 +888,7 @@ static int otg_remove(struct device *dev)
888} 888}
889 889
890struct device_driver omap_otg_driver = { 890struct device_driver omap_otg_driver = {
891 .owner = THIS_MODULE,
891 .name = "omap_otg", 892 .name = "omap_otg",
892 .bus = &platform_bus_type, 893 .bus = &platform_bus_type,
893 .probe = otg_probe, 894 .probe = otg_probe,
diff --git a/drivers/i2c/chips/m41t00.c b/drivers/i2c/chips/m41t00.c
index 3f14528a52a9..3df309ae44a6 100644
--- a/drivers/i2c/chips/m41t00.c
+++ b/drivers/i2c/chips/m41t00.c
@@ -174,13 +174,11 @@ m41t00_probe(struct i2c_adapter *adap, int addr, int kind)
174 struct i2c_client *client; 174 struct i2c_client *client;
175 int rc; 175 int rc;
176 176
177 client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); 177 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
178 if (!client) 178 if (!client)
179 return -ENOMEM; 179 return -ENOMEM;
180 180
181 memset(client, 0, sizeof(struct i2c_client));
182 strncpy(client->name, M41T00_DRV_NAME, I2C_NAME_SIZE); 181 strncpy(client->name, M41T00_DRV_NAME, I2C_NAME_SIZE);
183 client->flags = I2C_DF_NOTIFY;
184 client->addr = addr; 182 client->addr = addr;
185 client->adapter = adap; 183 client->adapter = adap;
186 client->driver = &m41t00_driver; 184 client->driver = &m41t00_driver;
diff --git a/drivers/i2c/chips/max6875.c b/drivers/i2c/chips/max6875.c
index 9e1aeb69abf9..b376a006883c 100644
--- a/drivers/i2c/chips/max6875.c
+++ b/drivers/i2c/chips/max6875.c
@@ -179,16 +179,14 @@ static int max6875_detect(struct i2c_adapter *adapter, int address, int kind)
179 if (address & 1) 179 if (address & 1)
180 return 0; 180 return 0;
181 181
182 if (!(data = kmalloc(sizeof(struct max6875_data), GFP_KERNEL))) 182 if (!(data = kzalloc(sizeof(struct max6875_data), GFP_KERNEL)))
183 return -ENOMEM; 183 return -ENOMEM;
184 memset(data, 0, sizeof(struct max6875_data));
185 184
186 /* A fake client is created on the odd address */ 185 /* A fake client is created on the odd address */
187 if (!(fake_client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL))) { 186 if (!(fake_client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL))) {
188 err = -ENOMEM; 187 err = -ENOMEM;
189 goto exit_kfree1; 188 goto exit_kfree1;
190 } 189 }
191 memset(fake_client, 0, sizeof(struct i2c_client));
192 190
193 /* Init real i2c_client */ 191 /* Init real i2c_client */
194 real_client = &data->client; 192 real_client = &data->client;
diff --git a/drivers/i2c/chips/pca9539.c b/drivers/i2c/chips/pca9539.c
index 225577fdda4d..59a930346229 100644
--- a/drivers/i2c/chips/pca9539.c
+++ b/drivers/i2c/chips/pca9539.c
@@ -122,11 +122,10 @@ static int pca9539_detect(struct i2c_adapter *adapter, int address, int kind)
122 122
123 /* OK. For now, we presume we have a valid client. We now create the 123 /* OK. For now, we presume we have a valid client. We now create the
124 client structure, even though we cannot fill it completely yet. */ 124 client structure, even though we cannot fill it completely yet. */
125 if (!(data = kmalloc(sizeof(struct pca9539_data), GFP_KERNEL))) { 125 if (!(data = kzalloc(sizeof(struct pca9539_data), GFP_KERNEL))) {
126 err = -ENOMEM; 126 err = -ENOMEM;
127 goto exit; 127 goto exit;
128 } 128 }
129 memset(data, 0, sizeof(struct pca9539_data));
130 129
131 new_client = &data->client; 130 new_client = &data->client;
132 i2c_set_clientdata(new_client, data); 131 i2c_set_clientdata(new_client, data);
diff --git a/drivers/i2c/chips/pcf8574.c b/drivers/i2c/chips/pcf8574.c
index 6525743ff9fd..c323c2de236c 100644
--- a/drivers/i2c/chips/pcf8574.c
+++ b/drivers/i2c/chips/pcf8574.c
@@ -115,7 +115,7 @@ static int pcf8574_attach_adapter(struct i2c_adapter *adapter)
115} 115}
116 116
117/* This function is called by i2c_probe */ 117/* This function is called by i2c_probe */
118int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind) 118static int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
119{ 119{
120 struct i2c_client *new_client; 120 struct i2c_client *new_client;
121 struct pcf8574_data *data; 121 struct pcf8574_data *data;
@@ -127,11 +127,10 @@ int pcf8574_detect(struct i2c_adapter *adapter, int address, int kind)
127 127
128 /* OK. For now, we presume we have a valid client. We now create the 128 /* OK. For now, we presume we have a valid client. We now create the
129 client structure, even though we cannot fill it completely yet. */ 129 client structure, even though we cannot fill it completely yet. */
130 if (!(data = kmalloc(sizeof(struct pcf8574_data), GFP_KERNEL))) { 130 if (!(data = kzalloc(sizeof(struct pcf8574_data), GFP_KERNEL))) {
131 err = -ENOMEM; 131 err = -ENOMEM;
132 goto exit; 132 goto exit;
133 } 133 }
134 memset(data, 0, sizeof(struct pcf8574_data));
135 134
136 new_client = &data->client; 135 new_client = &data->client;
137 i2c_set_clientdata(new_client, data); 136 i2c_set_clientdata(new_client, data);
diff --git a/drivers/i2c/chips/pcf8591.c b/drivers/i2c/chips/pcf8591.c
index 80f1df9a4500..ce420a67560b 100644
--- a/drivers/i2c/chips/pcf8591.c
+++ b/drivers/i2c/chips/pcf8591.c
@@ -166,7 +166,7 @@ static int pcf8591_attach_adapter(struct i2c_adapter *adapter)
166} 166}
167 167
168/* This function is called by i2c_probe */ 168/* This function is called by i2c_probe */
169int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind) 169static int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind)
170{ 170{
171 struct i2c_client *new_client; 171 struct i2c_client *new_client;
172 struct pcf8591_data *data; 172 struct pcf8591_data *data;
@@ -178,11 +178,10 @@ int pcf8591_detect(struct i2c_adapter *adapter, int address, int kind)
178 178
179 /* OK. For now, we presume we have a valid client. We now create the 179 /* OK. For now, we presume we have a valid client. We now create the
180 client structure, even though we cannot fill it completely yet. */ 180 client structure, even though we cannot fill it completely yet. */
181 if (!(data = kmalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) { 181 if (!(data = kzalloc(sizeof(struct pcf8591_data), GFP_KERNEL))) {
182 err = -ENOMEM; 182 err = -ENOMEM;
183 goto exit; 183 goto exit;
184 } 184 }
185 memset(data, 0, sizeof(struct pcf8591_data));
186 185
187 new_client = &data->client; 186 new_client = &data->client;
188 i2c_set_clientdata(new_client, data); 187 i2c_set_clientdata(new_client, data);
diff --git a/drivers/i2c/chips/rtc8564.c b/drivers/i2c/chips/rtc8564.c
index 0b5385c892b1..916cdc1af23c 100644
--- a/drivers/i2c/chips/rtc8564.c
+++ b/drivers/i2c/chips/rtc8564.c
@@ -148,17 +148,16 @@ static int rtc8564_attach(struct i2c_adapter *adap, int addr, int kind)
148 {addr, I2C_M_RD, 2, data} 148 {addr, I2C_M_RD, 2, data}
149 }; 149 };
150 150
151 d = kmalloc(sizeof(struct rtc8564_data), GFP_KERNEL); 151 d = kzalloc(sizeof(struct rtc8564_data), GFP_KERNEL);
152 if (!d) { 152 if (!d) {
153 ret = -ENOMEM; 153 ret = -ENOMEM;
154 goto done; 154 goto done;
155 } 155 }
156 memset(d, 0, sizeof(struct rtc8564_data));
157 new_client = &d->client; 156 new_client = &d->client;
158 157
159 strlcpy(new_client->name, "RTC8564", I2C_NAME_SIZE); 158 strlcpy(new_client->name, "RTC8564", I2C_NAME_SIZE);
160 i2c_set_clientdata(new_client, d); 159 i2c_set_clientdata(new_client, d);
161 new_client->flags = I2C_CLIENT_ALLOW_USE | I2C_DF_NOTIFY; 160 new_client->flags = I2C_CLIENT_ALLOW_USE;
162 new_client->addr = addr; 161 new_client->addr = addr;
163 new_client->adapter = adap; 162 new_client->adapter = adap;
164 new_client->driver = &rtc8564_driver; 163 new_client->driver = &rtc8564_driver;
diff --git a/drivers/i2c/chips/tps65010.c b/drivers/i2c/chips/tps65010.c
index 280e9638c0f8..280dd7a45db6 100644
--- a/drivers/i2c/chips/tps65010.c
+++ b/drivers/i2c/chips/tps65010.c
@@ -500,11 +500,10 @@ tps65010_probe(struct i2c_adapter *bus, int address, int kind)
500 return 0; 500 return 0;
501 } 501 }
502 502
503 tps = kmalloc(sizeof *tps, GFP_KERNEL); 503 tps = kzalloc(sizeof *tps, GFP_KERNEL);
504 if (!tps) 504 if (!tps)
505 return 0; 505 return 0;
506 506
507 memset(tps, 0, sizeof *tps);
508 init_MUTEX(&tps->lock); 507 init_MUTEX(&tps->lock);
509 INIT_WORK(&tps->work, tps65010_work, tps); 508 INIT_WORK(&tps->work, tps65010_work, tps);
510 tps->irq = -1; 509 tps->irq = -1;
diff --git a/drivers/i2c/chips/x1205.c b/drivers/i2c/chips/x1205.c
new file mode 100644
index 000000000000..7da366cdc18c
--- /dev/null
+++ b/drivers/i2c/chips/x1205.c
@@ -0,0 +1,698 @@
1/*
2 * x1205.c - An i2c driver for the Xicor X1205 RTC
3 * Copyright 2004 Karen Spearel
4 * Copyright 2005 Alessandro Zummo
5 *
6 * please send all reports to:
7 * kas11 at tampabay dot rr dot com
8 * a dot zummo at towertech dot it
9 *
10 * based on the other drivers in this same directory.
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 */
17
18#include <linux/module.h>
19#include <linux/init.h>
20#include <linux/slab.h>
21#include <linux/i2c.h>
22#include <linux/string.h>
23#include <linux/bcd.h>
24#include <linux/rtc.h>
25#include <linux/list.h>
26
27#include <linux/x1205.h>
28
29#define DRV_VERSION "0.9.9"
30
31/* Addresses to scan: none. This chip is located at
32 * 0x6f and uses a two bytes register addressing.
33 * Two bytes need to be written to read a single register,
34 * while most other chips just require one and take the second
35 * one as the data to be written. To prevent corrupting
36 * unknown chips, the user must explicitely set the probe parameter.
37 */
38
39static unsigned short normal_i2c[] = { I2C_CLIENT_END };
40
41/* Insmod parameters */
42I2C_CLIENT_INSMOD;
43I2C_CLIENT_MODULE_PARM(hctosys,
44 "Set the system time from the hardware clock upon initialization");
45
46/* offsets into CCR area */
47
48#define CCR_SEC 0
49#define CCR_MIN 1
50#define CCR_HOUR 2
51#define CCR_MDAY 3
52#define CCR_MONTH 4
53#define CCR_YEAR 5
54#define CCR_WDAY 6
55#define CCR_Y2K 7
56
57#define X1205_REG_SR 0x3F /* status register */
58#define X1205_REG_Y2K 0x37
59#define X1205_REG_DW 0x36
60#define X1205_REG_YR 0x35
61#define X1205_REG_MO 0x34
62#define X1205_REG_DT 0x33
63#define X1205_REG_HR 0x32
64#define X1205_REG_MN 0x31
65#define X1205_REG_SC 0x30
66#define X1205_REG_DTR 0x13
67#define X1205_REG_ATR 0x12
68#define X1205_REG_INT 0x11
69#define X1205_REG_0 0x10
70#define X1205_REG_Y2K1 0x0F
71#define X1205_REG_DWA1 0x0E
72#define X1205_REG_YRA1 0x0D
73#define X1205_REG_MOA1 0x0C
74#define X1205_REG_DTA1 0x0B
75#define X1205_REG_HRA1 0x0A
76#define X1205_REG_MNA1 0x09
77#define X1205_REG_SCA1 0x08
78#define X1205_REG_Y2K0 0x07
79#define X1205_REG_DWA0 0x06
80#define X1205_REG_YRA0 0x05
81#define X1205_REG_MOA0 0x04
82#define X1205_REG_DTA0 0x03
83#define X1205_REG_HRA0 0x02
84#define X1205_REG_MNA0 0x01
85#define X1205_REG_SCA0 0x00
86
87#define X1205_CCR_BASE 0x30 /* Base address of CCR */
88#define X1205_ALM0_BASE 0x00 /* Base address of ALARM0 */
89
90#define X1205_SR_RTCF 0x01 /* Clock failure */
91#define X1205_SR_WEL 0x02 /* Write Enable Latch */
92#define X1205_SR_RWEL 0x04 /* Register Write Enable */
93
94#define X1205_DTR_DTR0 0x01
95#define X1205_DTR_DTR1 0x02
96#define X1205_DTR_DTR2 0x04
97
98#define X1205_HR_MIL 0x80 /* Set in ccr.hour for 24 hr mode */
99
100/* Prototypes */
101static int x1205_attach(struct i2c_adapter *adapter);
102static int x1205_detach(struct i2c_client *client);
103static int x1205_probe(struct i2c_adapter *adapter, int address, int kind);
104static int x1205_command(struct i2c_client *client, unsigned int cmd,
105 void *arg);
106
107static struct i2c_driver x1205_driver = {
108 .owner = THIS_MODULE,
109 .name = "x1205",
110 .flags = I2C_DF_NOTIFY,
111 .attach_adapter = &x1205_attach,
112 .detach_client = &x1205_detach,
113};
114
115struct x1205_data {
116 struct i2c_client client;
117 struct list_head list;
118 unsigned int epoch;
119};
120
121static const unsigned char days_in_mo[] =
122 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
123
124static LIST_HEAD(x1205_clients);
125
126/* Workaround until the I2C subsytem will allow to send
127 * commands to a specific client. This function will send the command
128 * to the first client.
129 */
130int x1205_do_command(unsigned int cmd, void *arg)
131{
132 struct list_head *walk;
133 struct list_head *tmp;
134 struct x1205_data *data;
135
136 list_for_each_safe(walk, tmp, &x1205_clients) {
137 data = list_entry(walk, struct x1205_data, list);
138 return x1205_command(&data->client, cmd, arg);
139 }
140
141 return -ENODEV;
142}
143
144#define is_leap(year) \
145 ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
146
147/* make sure the rtc_time values are in bounds */
148static int x1205_validate_tm(struct rtc_time *tm)
149{
150 int year = tm->tm_year + 1900;
151
152 if ((tm->tm_year < 70) || (tm->tm_year > 255))
153 return -EINVAL;
154
155 if ((tm->tm_mon > 11) || (tm->tm_mday == 0))
156 return -EINVAL;
157
158 if (tm->tm_mday > days_in_mo[tm->tm_mon]
159 + ((tm->tm_mon == 1) && is_leap(year)))
160 return -EINVAL;
161
162 if ((tm->tm_hour >= 24) || (tm->tm_min >= 60) || (tm->tm_sec >= 60))
163 return -EINVAL;
164
165 return 0;
166}
167
168/*
169 * In the routines that deal directly with the x1205 hardware, we use
170 * rtc_time -- month 0-11, hour 0-23, yr = calendar year-epoch
171 * Epoch is initialized as 2000. Time is set to UTC.
172 */
173static int x1205_get_datetime(struct i2c_client *client, struct rtc_time *tm,
174 u8 reg_base)
175{
176 unsigned char dt_addr[2] = { 0, reg_base };
177 static unsigned char sr_addr[2] = { 0, X1205_REG_SR };
178
179 unsigned char buf[8], sr;
180
181 struct i2c_msg msgs[] = {
182 { client->addr, 0, 2, sr_addr }, /* setup read ptr */
183 { client->addr, I2C_M_RD, 1, &sr }, /* read status */
184 { client->addr, 0, 2, dt_addr }, /* setup read ptr */
185 { client->addr, I2C_M_RD, 8, buf }, /* read date */
186 };
187
188 struct x1205_data *data = i2c_get_clientdata(client);
189
190 /* read status register */
191 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
192 dev_err(&client->dev, "%s: read error\n", __FUNCTION__);
193 return -EIO;
194 }
195
196 /* check for battery failure */
197 if (sr & X1205_SR_RTCF) {
198 dev_warn(&client->dev,
199 "Clock had a power failure, you must set the date.\n");
200 return -EINVAL;
201 }
202
203 /* read date registers */
204 if ((i2c_transfer(client->adapter, &msgs[2], 2)) != 2) {
205 dev_err(&client->dev, "%s: read error\n", __FUNCTION__);
206 return -EIO;
207 }
208
209 dev_dbg(&client->dev,
210 "%s: raw read data - sec=%02x, min=%02x, hr=%02x, "
211 "mday=%02x, mon=%02x, year=%02x, wday=%02x, y2k=%02x\n",
212 __FUNCTION__,
213 buf[0], buf[1], buf[2], buf[3],
214 buf[4], buf[5], buf[6], buf[7]);
215
216 tm->tm_sec = BCD2BIN(buf[CCR_SEC]);
217 tm->tm_min = BCD2BIN(buf[CCR_MIN]);
218 tm->tm_hour = BCD2BIN(buf[CCR_HOUR] & 0x3F); /* hr is 0-23 */
219 tm->tm_mday = BCD2BIN(buf[CCR_MDAY]);
220 tm->tm_mon = BCD2BIN(buf[CCR_MONTH]);
221 data->epoch = BCD2BIN(buf[CCR_Y2K]) * 100;
222 tm->tm_year = BCD2BIN(buf[CCR_YEAR]) + data->epoch - 1900;
223 tm->tm_wday = buf[CCR_WDAY];
224
225 dev_dbg(&client->dev, "%s: tm is secs=%d, mins=%d, hours=%d, "
226 "mday=%d, mon=%d, year=%d, wday=%d\n",
227 __FUNCTION__,
228 tm->tm_sec, tm->tm_min, tm->tm_hour,
229 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
230
231 return 0;
232}
233
234static int x1205_set_datetime(struct i2c_client *client, struct rtc_time *tm,
235 int datetoo, u8 reg_base)
236{
237 int i, err, xfer;
238
239 unsigned char buf[8];
240
241 static const unsigned char wel[3] = { 0, X1205_REG_SR,
242 X1205_SR_WEL };
243
244 static const unsigned char rwel[3] = { 0, X1205_REG_SR,
245 X1205_SR_WEL | X1205_SR_RWEL };
246
247 static const unsigned char diswe[3] = { 0, X1205_REG_SR, 0 };
248
249 struct x1205_data *data = i2c_get_clientdata(client);
250
251 /* check if all values in the tm struct are correct */
252 if ((err = x1205_validate_tm(tm)) < 0)
253 return err;
254
255 dev_dbg(&client->dev, "%s: secs=%d, mins=%d, hours=%d, "
256 "mday=%d, mon=%d, year=%d, wday=%d\n",
257 __FUNCTION__,
258 tm->tm_sec, tm->tm_min, tm->tm_hour,
259 tm->tm_mday, tm->tm_mon, tm->tm_year, tm->tm_wday);
260
261 buf[CCR_SEC] = BIN2BCD(tm->tm_sec);
262 buf[CCR_MIN] = BIN2BCD(tm->tm_min);
263
264 /* set hour and 24hr bit */
265 buf[CCR_HOUR] = BIN2BCD(tm->tm_hour) | X1205_HR_MIL;
266
267 /* should we also set the date? */
268 if (datetoo) {
269 buf[CCR_MDAY] = BIN2BCD(tm->tm_mday);
270
271 /* month, 0 - 11 */
272 buf[CCR_MONTH] = BIN2BCD(tm->tm_mon);
273
274 /* year, since 1900 */
275 buf[CCR_YEAR] = BIN2BCD(tm->tm_year + 1900 - data->epoch);
276 buf[CCR_WDAY] = tm->tm_wday & 0x07;
277 buf[CCR_Y2K] = BIN2BCD(data->epoch / 100);
278 }
279
280 /* this sequence is required to unlock the chip */
281 xfer = i2c_master_send(client, wel, 3);
282 if (xfer != 3) {
283 dev_err(&client->dev, "%s: wel - %d\n", __FUNCTION__, xfer);
284 return -EIO;
285 }
286
287 xfer = i2c_master_send(client, rwel, 3);
288 if (xfer != 3) {
289 dev_err(&client->dev, "%s: rwel - %d\n", __FUNCTION__, xfer);
290 return -EIO;
291 }
292
293 /* write register's data */
294 for (i = 0; i < (datetoo ? 8 : 3); i++) {
295 unsigned char rdata[3] = { 0, reg_base + i, buf[i] };
296
297 xfer = i2c_master_send(client, rdata, 3);
298 if (xfer != 3) {
299 dev_err(&client->dev,
300 "%s: xfer=%d addr=%02x, data=%02x\n",
301 __FUNCTION__,
302 xfer, rdata[1], rdata[2]);
303 return -EIO;
304 }
305 };
306
307 /* disable further writes */
308 xfer = i2c_master_send(client, diswe, 3);
309 if (xfer != 3) {
310 dev_err(&client->dev, "%s: diswe - %d\n", __FUNCTION__, xfer);
311 return -EIO;
312 }
313
314 return 0;
315}
316
317static int x1205_get_dtrim(struct i2c_client *client, int *trim)
318{
319 unsigned char dtr;
320 static unsigned char dtr_addr[2] = { 0, X1205_REG_DTR };
321
322 struct i2c_msg msgs[] = {
323 { client->addr, 0, 2, dtr_addr }, /* setup read ptr */
324 { client->addr, I2C_M_RD, 1, &dtr }, /* read dtr */
325 };
326
327 /* read dtr register */
328 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
329 dev_err(&client->dev, "%s: read error\n", __FUNCTION__);
330 return -EIO;
331 }
332
333 dev_dbg(&client->dev, "%s: raw dtr=%x\n", __FUNCTION__, dtr);
334
335 *trim = 0;
336
337 if (dtr & X1205_DTR_DTR0)
338 *trim += 20;
339
340 if (dtr & X1205_DTR_DTR1)
341 *trim += 10;
342
343 if (dtr & X1205_DTR_DTR2)
344 *trim = -*trim;
345
346 return 0;
347}
348
349static int x1205_get_atrim(struct i2c_client *client, int *trim)
350{
351 s8 atr;
352 static unsigned char atr_addr[2] = { 0, X1205_REG_ATR };
353
354 struct i2c_msg msgs[] = {
355 { client->addr, 0, 2, atr_addr }, /* setup read ptr */
356 { client->addr, I2C_M_RD, 1, &atr }, /* read atr */
357 };
358
359 /* read atr register */
360 if ((i2c_transfer(client->adapter, &msgs[0], 2)) != 2) {
361 dev_err(&client->dev, "%s: read error\n", __FUNCTION__);
362 return -EIO;
363 }
364
365 dev_dbg(&client->dev, "%s: raw atr=%x\n", __FUNCTION__, atr);
366
367 /* atr is a two's complement value on 6 bits,
368 * perform sign extension. The formula is
369 * Catr = (atr * 0.25pF) + 11.00pF.
370 */
371 if (atr & 0x20)
372 atr |= 0xC0;
373
374 dev_dbg(&client->dev, "%s: raw atr=%x (%d)\n", __FUNCTION__, atr, atr);
375
376 *trim = (atr * 250) + 11000;
377
378 dev_dbg(&client->dev, "%s: real=%d\n", __FUNCTION__, *trim);
379
380 return 0;
381}
382
383static int x1205_hctosys(struct i2c_client *client)
384{
385 int err;
386
387 struct rtc_time tm;
388 struct timespec tv;
389
390 err = x1205_command(client, X1205_CMD_GETDATETIME, &tm);
391
392 if (err) {
393 dev_err(&client->dev,
394 "Unable to set the system clock\n");
395 return err;
396 }
397
398 /* IMPORTANT: the RTC only stores whole seconds. It is arbitrary
399 * whether it stores the most close value or the value with partial
400 * seconds truncated. However, it is important that we use it to store
401 * the truncated value. This is because otherwise it is necessary,
402 * in an rtc sync function, to read both xtime.tv_sec and
403 * xtime.tv_nsec. On some processors (i.e. ARM), an atomic read
404 * of >32bits is not possible. So storing the most close value would
405 * slow down the sync API. So here we have the truncated value and
406 * the best guess is to add 0.5s.
407 */
408
409 tv.tv_nsec = NSEC_PER_SEC >> 1;
410
411 /* WARNING: this is not the C library 'mktime' call, it is a built in
412 * inline function from include/linux/time.h. It expects (requires)
413 * the month to be in the range 1-12
414 */
415
416 tv.tv_sec = mktime(tm.tm_year + 1900, tm.tm_mon + 1,
417 tm.tm_mday, tm.tm_hour,
418 tm.tm_min, tm.tm_sec);
419
420 do_settimeofday(&tv);
421
422 dev_info(&client->dev,
423 "setting the system clock to %d-%d-%d %d:%d:%d\n",
424 tm.tm_year + 1900, tm.tm_mon + 1,
425 tm.tm_mday, tm.tm_hour, tm.tm_min,
426 tm.tm_sec);
427
428 return 0;
429}
430
431struct x1205_limit
432{
433 unsigned char reg;
434 unsigned char mask;
435 unsigned char min;
436 unsigned char max;
437};
438
439static int x1205_validate_client(struct i2c_client *client)
440{
441 int i, xfer;
442
443 /* Probe array. We will read the register at the specified
444 * address and check if the given bits are zero.
445 */
446 static const unsigned char probe_zero_pattern[] = {
447 /* register, mask */
448 X1205_REG_SR, 0x18,
449 X1205_REG_DTR, 0xF8,
450 X1205_REG_ATR, 0xC0,
451 X1205_REG_INT, 0x18,
452 X1205_REG_0, 0xFF,
453 };
454
455 static const struct x1205_limit probe_limits_pattern[] = {
456 /* register, mask, min, max */
457 { X1205_REG_Y2K, 0xFF, 19, 20 },
458 { X1205_REG_DW, 0xFF, 0, 6 },
459 { X1205_REG_YR, 0xFF, 0, 99 },
460 { X1205_REG_MO, 0xFF, 0, 12 },
461 { X1205_REG_DT, 0xFF, 0, 31 },
462 { X1205_REG_HR, 0x7F, 0, 23 },
463 { X1205_REG_MN, 0xFF, 0, 59 },
464 { X1205_REG_SC, 0xFF, 0, 59 },
465 { X1205_REG_Y2K1, 0xFF, 19, 20 },
466 { X1205_REG_Y2K0, 0xFF, 19, 20 },
467 };
468
469 /* check that registers have bits a 0 where expected */
470 for (i = 0; i < ARRAY_SIZE(probe_zero_pattern); i += 2) {
471 unsigned char buf;
472
473 unsigned char addr[2] = { 0, probe_zero_pattern[i] };
474
475 struct i2c_msg msgs[2] = {
476 { client->addr, 0, 2, addr },
477 { client->addr, I2C_M_RD, 1, &buf },
478 };
479
480 xfer = i2c_transfer(client->adapter, msgs, 2);
481 if (xfer != 2) {
482 dev_err(&client->adapter->dev,
483 "%s: could not read register %x\n",
484 __FUNCTION__, addr[1]);
485
486 return -EIO;
487 }
488
489 if ((buf & probe_zero_pattern[i+1]) != 0) {
490 dev_err(&client->adapter->dev,
491 "%s: register=%02x, zero pattern=%d, value=%x\n",
492 __FUNCTION__, addr[1], i, buf);
493
494 return -ENODEV;
495 }
496 }
497
498 /* check limits (only registers with bcd values) */
499 for (i = 0; i < ARRAY_SIZE(probe_limits_pattern); i++) {
500 unsigned char reg, value;
501
502 unsigned char addr[2] = { 0, probe_limits_pattern[i].reg };
503
504 struct i2c_msg msgs[2] = {
505 { client->addr, 0, 2, addr },
506 { client->addr, I2C_M_RD, 1, &reg },
507 };
508
509 xfer = i2c_transfer(client->adapter, msgs, 2);
510
511 if (xfer != 2) {
512 dev_err(&client->adapter->dev,
513 "%s: could not read register %x\n",
514 __FUNCTION__, addr[1]);
515
516 return -EIO;
517 }
518
519 value = BCD2BIN(reg & probe_limits_pattern[i].mask);
520
521 if (value > probe_limits_pattern[i].max ||
522 value < probe_limits_pattern[i].min) {
523 dev_dbg(&client->adapter->dev,
524 "%s: register=%x, lim pattern=%d, value=%d\n",
525 __FUNCTION__, addr[1], i, value);
526
527 return -ENODEV;
528 }
529 }
530
531 return 0;
532}
533
534static int x1205_attach(struct i2c_adapter *adapter)
535{
536 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
537
538 return i2c_probe(adapter, &addr_data, x1205_probe);
539}
540
541int x1205_direct_attach(int adapter_id,
542 struct i2c_client_address_data *address_data)
543{
544 int err;
545 struct i2c_adapter *adapter = i2c_get_adapter(adapter_id);
546
547 if (adapter) {
548 err = i2c_probe(adapter,
549 address_data, x1205_probe);
550
551 i2c_put_adapter(adapter);
552
553 return err;
554 }
555
556 return -ENODEV;
557}
558
559static int x1205_probe(struct i2c_adapter *adapter, int address, int kind)
560{
561 struct i2c_client *client;
562 struct x1205_data *data;
563
564 int err = 0;
565
566 dev_dbg(&adapter->dev, "%s\n", __FUNCTION__);
567
568 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
569 err = -ENODEV;
570 goto exit;
571 }
572
573 if (!(data = kzalloc(sizeof(struct x1205_data), GFP_KERNEL))) {
574 err = -ENOMEM;
575 goto exit;
576 }
577
578 /* Initialize our structures */
579 data->epoch = 2000;
580
581 client = &data->client;
582 client->addr = address;
583 client->driver = &x1205_driver;
584 client->adapter = adapter;
585
586 strlcpy(client->name, "x1205", I2C_NAME_SIZE);
587
588 i2c_set_clientdata(client, data);
589
590 /* Verify the chip is really an X1205 */
591 if (kind < 0) {
592 if (x1205_validate_client(client) < 0) {
593 err = -ENODEV;
594 goto exit_kfree;
595 }
596 }
597
598 /* Inform the i2c layer */
599 if ((err = i2c_attach_client(client)))
600 goto exit_kfree;
601
602 list_add(&data->list, &x1205_clients);
603
604 dev_info(&client->dev, "chip found, driver version " DRV_VERSION "\n");
605
606 /* If requested, set the system time */
607 if (hctosys)
608 x1205_hctosys(client);
609
610 return 0;
611
612exit_kfree:
613 kfree(data);
614
615exit:
616 return err;
617}
618
619static int x1205_detach(struct i2c_client *client)
620{
621 int err;
622 struct x1205_data *data = i2c_get_clientdata(client);
623
624 dev_dbg(&client->dev, "%s\n", __FUNCTION__);
625
626 if ((err = i2c_detach_client(client)))
627 return err;
628
629 list_del(&data->list);
630
631 kfree(data);
632
633 return 0;
634}
635
636static int x1205_command(struct i2c_client *client, unsigned int cmd,
637 void *param)
638{
639 if (param == NULL)
640 return -EINVAL;
641
642 if (!capable(CAP_SYS_TIME))
643 return -EACCES;
644
645 dev_dbg(&client->dev, "%s: cmd=%d\n", __FUNCTION__, cmd);
646
647 switch (cmd) {
648 case X1205_CMD_GETDATETIME:
649 return x1205_get_datetime(client, param, X1205_CCR_BASE);
650
651 case X1205_CMD_SETTIME:
652 return x1205_set_datetime(client, param, 0,
653 X1205_CCR_BASE);
654
655 case X1205_CMD_SETDATETIME:
656 return x1205_set_datetime(client, param, 1,
657 X1205_CCR_BASE);
658
659 case X1205_CMD_GETALARM:
660 return x1205_get_datetime(client, param, X1205_ALM0_BASE);
661
662 case X1205_CMD_SETALARM:
663 return x1205_set_datetime(client, param, 1,
664 X1205_ALM0_BASE);
665
666 case X1205_CMD_GETDTRIM:
667 return x1205_get_dtrim(client, param);
668
669 case X1205_CMD_GETATRIM:
670 return x1205_get_atrim(client, param);
671
672 default:
673 return -EINVAL;
674 }
675}
676
677static int __init x1205_init(void)
678{
679 return i2c_add_driver(&x1205_driver);
680}
681
682static void __exit x1205_exit(void)
683{
684 i2c_del_driver(&x1205_driver);
685}
686
687MODULE_AUTHOR(
688 "Karen Spearel <kas11@tampabay.rr.com>, "
689 "Alessandro Zummo <a.zummo@towertech.it>");
690MODULE_DESCRIPTION("Xicor X1205 RTC driver");
691MODULE_LICENSE("GPL");
692MODULE_VERSION(DRV_VERSION);
693
694EXPORT_SYMBOL_GPL(x1205_do_command);
695EXPORT_SYMBOL_GPL(x1205_direct_attach);
696
697module_init(x1205_init);
698module_exit(x1205_exit);
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 45aa0e54e297..02e335a04f09 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -19,7 +19,8 @@
19 19
20/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>. 20/* With some changes from Kyösti Mälkki <kmalkki@cc.hut.fi>.
21 All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl> 21 All SMBus-related things are written by Frodo Looijaard <frodol@dds.nl>
22 SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> */ 22 SMBus 2.0 support by Mark Studebaker <mdsxyz123@yahoo.com> and
23 Jean Delvare <khali@linux-fr.org> */
23 24
24#include <linux/module.h> 25#include <linux/module.h>
25#include <linux/kernel.h> 26#include <linux/kernel.h>
@@ -85,6 +86,7 @@ void i2c_adapter_dev_release(struct device *dev)
85} 86}
86 87
87struct device_driver i2c_adapter_driver = { 88struct device_driver i2c_adapter_driver = {
89 .owner = THIS_MODULE,
88 .name = "i2c_adapter", 90 .name = "i2c_adapter",
89 .bus = &i2c_bus_type, 91 .bus = &i2c_bus_type,
90 .probe = i2c_device_probe, 92 .probe = i2c_device_probe,
@@ -98,6 +100,7 @@ static void i2c_adapter_class_dev_release(struct class_device *dev)
98} 100}
99 101
100struct class i2c_adapter_class = { 102struct class i2c_adapter_class = {
103 .owner = THIS_MODULE,
101 .name = "i2c-adapter", 104 .name = "i2c-adapter",
102 .release = &i2c_adapter_class_dev_release, 105 .release = &i2c_adapter_class_dev_release,
103}; 106};
@@ -291,6 +294,7 @@ int i2c_add_driver(struct i2c_driver *driver)
291 down(&core_lists); 294 down(&core_lists);
292 295
293 /* add the driver to the list of i2c drivers in the driver core */ 296 /* add the driver to the list of i2c drivers in the driver core */
297 driver->driver.owner = driver->owner;
294 driver->driver.name = driver->name; 298 driver->driver.name = driver->name;
295 driver->driver.bus = &i2c_bus_type; 299 driver->driver.bus = &i2c_bus_type;
296 driver->driver.probe = i2c_device_probe; 300 driver->driver.probe = i2c_device_probe;
@@ -706,10 +710,6 @@ int i2c_probe(struct i2c_adapter *adapter,
706 int i, err; 710 int i, err;
707 int adap_id = i2c_adapter_id(adapter); 711 int adap_id = i2c_adapter_id(adapter);
708 712
709 /* Forget it if we can't probe using SMBUS_QUICK */
710 if (! i2c_check_functionality(adapter,I2C_FUNC_SMBUS_QUICK))
711 return -1;
712
713 /* Force entries are done first, and are not affected by ignore 713 /* Force entries are done first, and are not affected by ignore
714 entries */ 714 entries */
715 if (address_data->forces) { 715 if (address_data->forces) {
@@ -736,6 +736,17 @@ int i2c_probe(struct i2c_adapter *adapter,
736 } 736 }
737 } 737 }
738 738
739 /* Stop here if we can't use SMBUS_QUICK */
740 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_QUICK)) {
741 if (address_data->probe[0] == I2C_CLIENT_END
742 && address_data->normal_i2c[0] == I2C_CLIENT_END)
743 return 0;
744
745 dev_warn(&adapter->dev, "SMBus Quick command not supported, "
746 "can't probe for chips\n");
747 return -1;
748 }
749
739 /* Probe entries are done second, and are not affected by ignore 750 /* Probe entries are done second, and are not affected by ignore
740 entries either */ 751 entries either */
741 for (i = 0; address_data->probe[i] != I2C_CLIENT_END; i += 2) { 752 for (i = 0; address_data->probe[i] != I2C_CLIENT_END; i += 2) {
@@ -820,101 +831,44 @@ crc8(u16 data)
820 return (u8)(data >> 8); 831 return (u8)(data >> 8);
821} 832}
822 833
823/* CRC over count bytes in the first array plus the bytes in the rest 834/* Incremental CRC8 over count bytes in the array pointed to by p */
824 array if it is non-null. rest[0] is the (length of rest) - 1 835static u8 i2c_smbus_pec(u8 crc, u8 *p, size_t count)
825 and is included. */
826static u8 i2c_smbus_partial_pec(u8 crc, int count, u8 *first, u8 *rest)
827{ 836{
828 int i; 837 int i;
829 838
830 for(i = 0; i < count; i++) 839 for(i = 0; i < count; i++)
831 crc = crc8((crc ^ first[i]) << 8); 840 crc = crc8((crc ^ p[i]) << 8);
832 if(rest != NULL)
833 for(i = 0; i <= rest[0]; i++)
834 crc = crc8((crc ^ rest[i]) << 8);
835 return crc; 841 return crc;
836} 842}
837 843
838static u8 i2c_smbus_pec(int count, u8 *first, u8 *rest) 844/* Assume a 7-bit address, which is reasonable for SMBus */
845static u8 i2c_smbus_msg_pec(u8 pec, struct i2c_msg *msg)
839{ 846{
840 return i2c_smbus_partial_pec(0, count, first, rest); 847 /* The address will be sent first */
848 u8 addr = (msg->addr << 1) | !!(msg->flags & I2C_M_RD);
849 pec = i2c_smbus_pec(pec, &addr, 1);
850
851 /* The data buffer follows */
852 return i2c_smbus_pec(pec, msg->buf, msg->len);
841} 853}
842 854
843/* Returns new "size" (transaction type) 855/* Used for write only transactions */
844 Note that we convert byte to byte_data and byte_data to word_data 856static inline void i2c_smbus_add_pec(struct i2c_msg *msg)
845 rather than invent new xxx_PEC transactions. */
846static int i2c_smbus_add_pec(u16 addr, u8 command, int size,
847 union i2c_smbus_data *data)
848{ 857{
849 u8 buf[3]; 858 msg->buf[msg->len] = i2c_smbus_msg_pec(0, msg);
850 859 msg->len++;
851 buf[0] = addr << 1;
852 buf[1] = command;
853 switch(size) {
854 case I2C_SMBUS_BYTE:
855 data->byte = i2c_smbus_pec(2, buf, NULL);
856 size = I2C_SMBUS_BYTE_DATA;
857 break;
858 case I2C_SMBUS_BYTE_DATA:
859 buf[2] = data->byte;
860 data->word = buf[2] ||
861 (i2c_smbus_pec(3, buf, NULL) << 8);
862 size = I2C_SMBUS_WORD_DATA;
863 break;
864 case I2C_SMBUS_WORD_DATA:
865 /* unsupported */
866 break;
867 case I2C_SMBUS_BLOCK_DATA:
868 data->block[data->block[0] + 1] =
869 i2c_smbus_pec(2, buf, data->block);
870 size = I2C_SMBUS_BLOCK_DATA_PEC;
871 break;
872 }
873 return size;
874} 860}
875 861
876static int i2c_smbus_check_pec(u16 addr, u8 command, int size, u8 partial, 862/* Return <0 on CRC error
877 union i2c_smbus_data *data) 863 If there was a write before this read (most cases) we need to take the
864 partial CRC from the write part into account.
865 Note that this function does modify the message (we need to decrease the
866 message length to hide the CRC byte from the caller). */
867static int i2c_smbus_check_pec(u8 cpec, struct i2c_msg *msg)
878{ 868{
879 u8 buf[3], rpec, cpec; 869 u8 rpec = msg->buf[--msg->len];
870 cpec = i2c_smbus_msg_pec(cpec, msg);
880 871
881 buf[1] = command;
882 switch(size) {
883 case I2C_SMBUS_BYTE_DATA:
884 buf[0] = (addr << 1) | 1;
885 cpec = i2c_smbus_pec(2, buf, NULL);
886 rpec = data->byte;
887 break;
888 case I2C_SMBUS_WORD_DATA:
889 buf[0] = (addr << 1) | 1;
890 buf[2] = data->word & 0xff;
891 cpec = i2c_smbus_pec(3, buf, NULL);
892 rpec = data->word >> 8;
893 break;
894 case I2C_SMBUS_WORD_DATA_PEC:
895 /* unsupported */
896 cpec = rpec = 0;
897 break;
898 case I2C_SMBUS_PROC_CALL_PEC:
899 /* unsupported */
900 cpec = rpec = 0;
901 break;
902 case I2C_SMBUS_BLOCK_DATA_PEC:
903 buf[0] = (addr << 1);
904 buf[2] = (addr << 1) | 1;
905 cpec = i2c_smbus_pec(3, buf, data->block);
906 rpec = data->block[data->block[0] + 1];
907 break;
908 case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
909 buf[0] = (addr << 1) | 1;
910 rpec = i2c_smbus_partial_pec(partial, 1,
911 buf, data->block);
912 cpec = data->block[data->block[0] + 1];
913 break;
914 default:
915 cpec = rpec = 0;
916 break;
917 }
918 if (rpec != cpec) { 872 if (rpec != cpec) {
919 pr_debug("i2c-core: Bad PEC 0x%02x vs. 0x%02x\n", 873 pr_debug("i2c-core: Bad PEC 0x%02x vs. 0x%02x\n",
920 rpec, cpec); 874 rpec, cpec);
@@ -941,9 +895,8 @@ s32 i2c_smbus_read_byte(struct i2c_client *client)
941 895
942s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value) 896s32 i2c_smbus_write_byte(struct i2c_client *client, u8 value)
943{ 897{
944 union i2c_smbus_data data; /* only for PEC */
945 return i2c_smbus_xfer(client->adapter,client->addr,client->flags, 898 return i2c_smbus_xfer(client->adapter,client->addr,client->flags,
946 I2C_SMBUS_WRITE,value, I2C_SMBUS_BYTE,&data); 899 I2C_SMBUS_WRITE, value, I2C_SMBUS_BYTE, NULL);
947} 900}
948 901
949s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command) 902s32 i2c_smbus_read_byte_data(struct i2c_client *client, u8 command)
@@ -1026,13 +979,14 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1026 need to use only one message; when reading, we need two. We initialize 979 need to use only one message; when reading, we need two. We initialize
1027 most things with sane defaults, to keep the code below somewhat 980 most things with sane defaults, to keep the code below somewhat
1028 simpler. */ 981 simpler. */
1029 unsigned char msgbuf0[34]; 982 unsigned char msgbuf0[I2C_SMBUS_BLOCK_MAX+3];
1030 unsigned char msgbuf1[34]; 983 unsigned char msgbuf1[I2C_SMBUS_BLOCK_MAX+2];
1031 int num = read_write == I2C_SMBUS_READ?2:1; 984 int num = read_write == I2C_SMBUS_READ?2:1;
1032 struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 }, 985 struct i2c_msg msg[2] = { { addr, flags, 1, msgbuf0 },
1033 { addr, flags | I2C_M_RD, 0, msgbuf1 } 986 { addr, flags | I2C_M_RD, 0, msgbuf1 }
1034 }; 987 };
1035 int i; 988 int i;
989 u8 partial_pec = 0;
1036 990
1037 msgbuf0[0] = command; 991 msgbuf0[0] = command;
1038 switch(size) { 992 switch(size) {
@@ -1075,7 +1029,6 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1075 msgbuf0[2] = (data->word >> 8) & 0xff; 1029 msgbuf0[2] = (data->word >> 8) & 0xff;
1076 break; 1030 break;
1077 case I2C_SMBUS_BLOCK_DATA: 1031 case I2C_SMBUS_BLOCK_DATA:
1078 case I2C_SMBUS_BLOCK_DATA_PEC:
1079 if (read_write == I2C_SMBUS_READ) { 1032 if (read_write == I2C_SMBUS_READ) {
1080 dev_err(&adapter->dev, "Block read not supported " 1033 dev_err(&adapter->dev, "Block read not supported "
1081 "under I2C emulation!\n"); 1034 "under I2C emulation!\n");
@@ -1088,23 +1041,20 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1088 data->block[0]); 1041 data->block[0]);
1089 return -1; 1042 return -1;
1090 } 1043 }
1091 if(size == I2C_SMBUS_BLOCK_DATA_PEC) 1044 for (i = 1; i < msg[0].len; i++)
1092 (msg[0].len)++;
1093 for (i = 1; i <= msg[0].len; i++)
1094 msgbuf0[i] = data->block[i-1]; 1045 msgbuf0[i] = data->block[i-1];
1095 } 1046 }
1096 break; 1047 break;
1097 case I2C_SMBUS_BLOCK_PROC_CALL: 1048 case I2C_SMBUS_BLOCK_PROC_CALL:
1098 case I2C_SMBUS_BLOCK_PROC_CALL_PEC:
1099 dev_dbg(&adapter->dev, "Block process call not supported " 1049 dev_dbg(&adapter->dev, "Block process call not supported "
1100 "under I2C emulation!\n"); 1050 "under I2C emulation!\n");
1101 return -1; 1051 return -1;
1102 case I2C_SMBUS_I2C_BLOCK_DATA: 1052 case I2C_SMBUS_I2C_BLOCK_DATA:
1103 if (read_write == I2C_SMBUS_READ) { 1053 if (read_write == I2C_SMBUS_READ) {
1104 msg[1].len = I2C_SMBUS_I2C_BLOCK_MAX; 1054 msg[1].len = I2C_SMBUS_BLOCK_MAX;
1105 } else { 1055 } else {
1106 msg[0].len = data->block[0] + 1; 1056 msg[0].len = data->block[0] + 1;
1107 if (msg[0].len > I2C_SMBUS_I2C_BLOCK_MAX + 1) { 1057 if (msg[0].len > I2C_SMBUS_BLOCK_MAX + 1) {
1108 dev_err(&adapter->dev, "i2c_smbus_xfer_emulated called with " 1058 dev_err(&adapter->dev, "i2c_smbus_xfer_emulated called with "
1109 "invalid block write size (%d)\n", 1059 "invalid block write size (%d)\n",
1110 data->block[0]); 1060 data->block[0]);
@@ -1120,9 +1070,30 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1120 return -1; 1070 return -1;
1121 } 1071 }
1122 1072
1073 i = ((flags & I2C_CLIENT_PEC) && size != I2C_SMBUS_QUICK
1074 && size != I2C_SMBUS_I2C_BLOCK_DATA);
1075 if (i) {
1076 /* Compute PEC if first message is a write */
1077 if (!(msg[0].flags & I2C_M_RD)) {
1078 if (num == 1) /* Write only */
1079 i2c_smbus_add_pec(&msg[0]);
1080 else /* Write followed by read */
1081 partial_pec = i2c_smbus_msg_pec(0, &msg[0]);
1082 }
1083 /* Ask for PEC if last message is a read */
1084 if (msg[num-1].flags & I2C_M_RD)
1085 msg[num-1].len++;
1086 }
1087
1123 if (i2c_transfer(adapter, msg, num) < 0) 1088 if (i2c_transfer(adapter, msg, num) < 0)
1124 return -1; 1089 return -1;
1125 1090
1091 /* Check PEC if last message is a read */
1092 if (i && (msg[num-1].flags & I2C_M_RD)) {
1093 if (i2c_smbus_check_pec(partial_pec, &msg[num-1]) < 0)
1094 return -1;
1095 }
1096
1126 if (read_write == I2C_SMBUS_READ) 1097 if (read_write == I2C_SMBUS_READ)
1127 switch(size) { 1098 switch(size) {
1128 case I2C_SMBUS_BYTE: 1099 case I2C_SMBUS_BYTE:
@@ -1137,8 +1108,8 @@ static s32 i2c_smbus_xfer_emulated(struct i2c_adapter * adapter, u16 addr,
1137 break; 1108 break;
1138 case I2C_SMBUS_I2C_BLOCK_DATA: 1109 case I2C_SMBUS_I2C_BLOCK_DATA:
1139 /* fixed at 32 for now */ 1110 /* fixed at 32 for now */
1140 data->block[0] = I2C_SMBUS_I2C_BLOCK_MAX; 1111 data->block[0] = I2C_SMBUS_BLOCK_MAX;
1141 for (i = 0; i < I2C_SMBUS_I2C_BLOCK_MAX; i++) 1112 for (i = 0; i < I2C_SMBUS_BLOCK_MAX; i++)
1142 data->block[i+1] = msgbuf1[i]; 1113 data->block[i+1] = msgbuf1[i];
1143 break; 1114 break;
1144 } 1115 }
@@ -1151,28 +1122,8 @@ s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
1151 union i2c_smbus_data * data) 1122 union i2c_smbus_data * data)
1152{ 1123{
1153 s32 res; 1124 s32 res;
1154 int swpec = 0;
1155 u8 partial = 0;
1156 1125
1157 flags &= I2C_M_TEN | I2C_CLIENT_PEC; 1126 flags &= I2C_M_TEN | I2C_CLIENT_PEC;
1158 if((flags & I2C_CLIENT_PEC) &&
1159 !(i2c_check_functionality(adapter, I2C_FUNC_SMBUS_HWPEC_CALC))) {
1160 swpec = 1;
1161 if(read_write == I2C_SMBUS_READ &&
1162 size == I2C_SMBUS_BLOCK_DATA)
1163 size = I2C_SMBUS_BLOCK_DATA_PEC;
1164 else if(size == I2C_SMBUS_PROC_CALL)
1165 size = I2C_SMBUS_PROC_CALL_PEC;
1166 else if(size == I2C_SMBUS_BLOCK_PROC_CALL) {
1167 i2c_smbus_add_pec(addr, command,
1168 I2C_SMBUS_BLOCK_DATA, data);
1169 partial = data->block[data->block[0] + 1];
1170 size = I2C_SMBUS_BLOCK_PROC_CALL_PEC;
1171 } else if(read_write == I2C_SMBUS_WRITE &&
1172 size != I2C_SMBUS_QUICK &&
1173 size != I2C_SMBUS_I2C_BLOCK_DATA)
1174 size = i2c_smbus_add_pec(addr, command, size, data);
1175 }
1176 1127
1177 if (adapter->algo->smbus_xfer) { 1128 if (adapter->algo->smbus_xfer) {
1178 down(&adapter->bus_lock); 1129 down(&adapter->bus_lock);
@@ -1183,13 +1134,6 @@ s32 i2c_smbus_xfer(struct i2c_adapter * adapter, u16 addr, unsigned short flags,
1183 res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write, 1134 res = i2c_smbus_xfer_emulated(adapter,addr,flags,read_write,
1184 command,size,data); 1135 command,size,data);
1185 1136
1186 if(res >= 0 && swpec &&
1187 size != I2C_SMBUS_QUICK && size != I2C_SMBUS_I2C_BLOCK_DATA &&
1188 (read_write == I2C_SMBUS_READ || size == I2C_SMBUS_PROC_CALL_PEC ||
1189 size == I2C_SMBUS_BLOCK_PROC_CALL_PEC)) {
1190 if(i2c_smbus_check_pec(addr, command, size, partial, data))
1191 return -1;
1192 }
1193 return res; 1137 return res;
1194} 1138}
1195 1139
diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
index aa7a4fadef64..ea14c8f1c82b 100644
--- a/drivers/i2c/i2c-dev.c
+++ b/drivers/i2c/i2c-dev.c
@@ -26,15 +26,11 @@
26 26
27/* The I2C_RDWR ioctl code is written by Kolja Waschk <waschk@telos.de> */ 27/* The I2C_RDWR ioctl code is written by Kolja Waschk <waschk@telos.de> */
28 28
29/* The devfs code is contributed by Philipp Matthias Hahn
30 <pmhahn@titan.lahn.de> */
31
32#include <linux/kernel.h> 29#include <linux/kernel.h>
33#include <linux/module.h> 30#include <linux/module.h>
34#include <linux/fs.h> 31#include <linux/fs.h>
35#include <linux/slab.h> 32#include <linux/slab.h>
36#include <linux/smp_lock.h> 33#include <linux/smp_lock.h>
37#include <linux/devfs_fs_kernel.h>
38#include <linux/init.h> 34#include <linux/init.h>
39#include <linux/i2c.h> 35#include <linux/i2c.h>
40#include <linux/i2c-dev.h> 36#include <linux/i2c-dev.h>
@@ -80,10 +76,9 @@ static struct i2c_dev *get_free_i2c_dev(struct i2c_adapter *adap)
80{ 76{
81 struct i2c_dev *i2c_dev; 77 struct i2c_dev *i2c_dev;
82 78
83 i2c_dev = kmalloc(sizeof(*i2c_dev), GFP_KERNEL); 79 i2c_dev = kzalloc(sizeof(*i2c_dev), GFP_KERNEL);
84 if (!i2c_dev) 80 if (!i2c_dev)
85 return ERR_PTR(-ENOMEM); 81 return ERR_PTR(-ENOMEM);
86 memset(i2c_dev, 0x00, sizeof(*i2c_dev));
87 82
88 spin_lock(&i2c_dev_array_lock); 83 spin_lock(&i2c_dev_array_lock);
89 if (i2c_dev_array[adap->nr]) { 84 if (i2c_dev_array[adap->nr]) {
@@ -177,8 +172,8 @@ static int i2cdev_ioctl(struct inode *inode, struct file *file,
177 int i,datasize,res; 172 int i,datasize,res;
178 unsigned long funcs; 173 unsigned long funcs;
179 174
180 dev_dbg(&client->adapter->dev, "i2c-%d ioctl, cmd: 0x%x, arg: %lx.\n", 175 dev_dbg(&client->adapter->dev, "ioctl, cmd=0x%02x, arg=0x%02lx\n",
181 iminor(inode),cmd, arg); 176 cmd, arg);
182 177
183 switch ( cmd ) { 178 switch ( cmd ) {
184 case I2C_SLAVE: 179 case I2C_SLAVE:
@@ -432,8 +427,6 @@ static int i2cdev_attach_adapter(struct i2c_adapter *adap)
432 if (IS_ERR(i2c_dev)) 427 if (IS_ERR(i2c_dev))
433 return PTR_ERR(i2c_dev); 428 return PTR_ERR(i2c_dev);
434 429
435 devfs_mk_cdev(MKDEV(I2C_MAJOR, i2c_dev->minor),
436 S_IFCHR|S_IRUSR|S_IWUSR, "i2c/%d", i2c_dev->minor);
437 pr_debug("i2c-dev: adapter [%s] registered as minor %d\n", 430 pr_debug("i2c-dev: adapter [%s] registered as minor %d\n",
438 adap->name, i2c_dev->minor); 431 adap->name, i2c_dev->minor);
439 432
@@ -466,7 +459,6 @@ static int i2cdev_detach_adapter(struct i2c_adapter *adap)
466 return -ENODEV; 459 return -ENODEV;
467 460
468 init_completion(&i2c_dev->released); 461 init_completion(&i2c_dev->released);
469 devfs_remove("i2c/%d", i2c_dev->minor);
470 return_i2c_dev(i2c_dev); 462 return_i2c_dev(i2c_dev);
471 class_device_unregister(&i2c_dev->class_dev); 463 class_device_unregister(&i2c_dev->class_dev);
472 wait_for_completion(&i2c_dev->released); 464 wait_for_completion(&i2c_dev->released);
@@ -522,8 +514,6 @@ static int __init i2c_dev_init(void)
522 if (res) 514 if (res)
523 goto out_unreg_class; 515 goto out_unreg_class;
524 516
525 devfs_mk_dir("i2c");
526
527 return 0; 517 return 0;
528 518
529out_unreg_class: 519out_unreg_class:
@@ -539,7 +529,6 @@ static void __exit i2c_dev_exit(void)
539{ 529{
540 i2c_del_driver(&i2cdev_driver); 530 i2c_del_driver(&i2cdev_driver);
541 class_unregister(&i2c_dev_class); 531 class_unregister(&i2c_dev_class);
542 devfs_remove("i2c");
543 unregister_chrdev(I2C_MAJOR,"i2c"); 532 unregister_chrdev(I2C_MAJOR,"i2c");
544} 533}
545 534