aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/i2c/busses/i2c-piix4.c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2008-07-14 16:38:25 -0400
committerJean Delvare <khali@mahadeva.delvare>2008-07-14 16:38:25 -0400
commitfa63cd56d2f09806169307d761e8f430e23bc09b (patch)
tree71a6f64e1f3d4774c6c074646aab82961c1727e8 /drivers/i2c/busses/i2c-piix4.c
parent97140342e69d479a3ad82bfd4c154c0b08fe3eea (diff)
i2c-piix4: Various cleanups and minor fixes
The i2c-piix4 driver was used recently as a model to write a new SMBus host controller driver and this made me realize that the code of this old driver wasn't exactly good. So, here are many cleanups and minor fixes to this driver, so that these minor mistakes aren't duplicated again: * Delete unused structure. * Delete needless forward function declaration. * Properly announce the SMBus host controller as we find it. * Spell it SMBus not SMB. * Return -EBUSY instead of -ENODEV when the I/O region is already in use. * Drop useless masks on the 7-bit address and the R/W bit. * Reject block transaction requests with an invalid block length. * Check and report block transaction replies with an invalid block length. * Delete a useless comment. Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/i2c/busses/i2c-piix4.c')
-rw-r--r--drivers/i2c/busses/i2c-piix4.c41
1 files changed, 15 insertions, 26 deletions
diff --git a/drivers/i2c/busses/i2c-piix4.c b/drivers/i2c/busses/i2c-piix4.c
index dc76c0e2dc6..77aaa5fe5e3 100644
--- a/drivers/i2c/busses/i2c-piix4.c
+++ b/drivers/i2c/busses/i2c-piix4.c
@@ -42,13 +42,6 @@
42#include <asm/io.h> 42#include <asm/io.h>
43 43
44 44
45struct sd {
46 const unsigned short mfr;
47 const unsigned short dev;
48 const unsigned char fn;
49 const char *name;
50};
51
52/* PIIX4 SMBus address offsets */ 45/* PIIX4 SMBus address offsets */
53#define SMBHSTSTS (0 + piix4_smba) 46#define SMBHSTSTS (0 + piix4_smba)
54#define SMBHSLVSTS (1 + piix4_smba) 47#define SMBHSLVSTS (1 + piix4_smba)
@@ -101,8 +94,6 @@ MODULE_PARM_DESC(force_addr,
101 "Forcibly enable the PIIX4 at the given address. " 94 "Forcibly enable the PIIX4 at the given address. "
102 "EXTREMELY DANGEROUS!"); 95 "EXTREMELY DANGEROUS!");
103 96
104static int piix4_transaction(void);
105
106static unsigned short piix4_smba; 97static unsigned short piix4_smba;
107static int srvrworks_csb5_delay; 98static int srvrworks_csb5_delay;
108static struct pci_driver piix4_driver; 99static struct pci_driver piix4_driver;
@@ -141,8 +132,6 @@ static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
141{ 132{
142 unsigned char temp; 133 unsigned char temp;
143 134
144 dev_info(&PIIX4_dev->dev, "Found %s device\n", pci_name(PIIX4_dev));
145
146 if ((PIIX4_dev->vendor == PCI_VENDOR_ID_SERVERWORKS) && 135 if ((PIIX4_dev->vendor == PCI_VENDOR_ID_SERVERWORKS) &&
147 (PIIX4_dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5)) 136 (PIIX4_dev->device == PCI_DEVICE_ID_SERVERWORKS_CSB5))
148 srvrworks_csb5_delay = 1; 137 srvrworks_csb5_delay = 1;
@@ -172,7 +161,7 @@ static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
172 pci_read_config_word(PIIX4_dev, SMBBA, &piix4_smba); 161 pci_read_config_word(PIIX4_dev, SMBBA, &piix4_smba);
173 piix4_smba &= 0xfff0; 162 piix4_smba &= 0xfff0;
174 if(piix4_smba == 0) { 163 if(piix4_smba == 0) {
175 dev_err(&PIIX4_dev->dev, "SMB base address " 164 dev_err(&PIIX4_dev->dev, "SMBus base address "
176 "uninitialized - upgrade BIOS or use " 165 "uninitialized - upgrade BIOS or use "
177 "force_addr=0xaddr\n"); 166 "force_addr=0xaddr\n");
178 return -ENODEV; 167 return -ENODEV;
@@ -180,9 +169,9 @@ static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
180 } 169 }
181 170
182 if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) { 171 if (!request_region(piix4_smba, SMBIOSIZE, piix4_driver.name)) {
183 dev_err(&PIIX4_dev->dev, "SMB region 0x%x already in use!\n", 172 dev_err(&PIIX4_dev->dev, "SMBus region 0x%x already in use!\n",
184 piix4_smba); 173 piix4_smba);
185 return -ENODEV; 174 return -EBUSY;
186 } 175 }
187 176
188 pci_read_config_byte(PIIX4_dev, SMBHSTCFG, &temp); 177 pci_read_config_byte(PIIX4_dev, SMBHSTCFG, &temp);
@@ -228,13 +217,13 @@ static int __devinit piix4_setup(struct pci_dev *PIIX4_dev,
228 "(or code out of date)!\n"); 217 "(or code out of date)!\n");
229 218
230 pci_read_config_byte(PIIX4_dev, SMBREV, &temp); 219 pci_read_config_byte(PIIX4_dev, SMBREV, &temp);
231 dev_dbg(&PIIX4_dev->dev, "SMBREV = 0x%X\n", temp); 220 dev_info(&PIIX4_dev->dev,
232 dev_dbg(&PIIX4_dev->dev, "SMBA = 0x%X\n", piix4_smba); 221 "SMBus Host Controller at 0x%x, revision %d\n",
222 piix4_smba, temp);
233 223
234 return 0; 224 return 0;
235} 225}
236 226
237/* Another internally used function */
238static int piix4_transaction(void) 227static int piix4_transaction(void)
239{ 228{
240 int temp; 229 int temp;
@@ -322,19 +311,19 @@ static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
322 dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n"); 311 dev_err(&adap->dev, "I2C_SMBUS_PROC_CALL not supported!\n");
323 return -EOPNOTSUPP; 312 return -EOPNOTSUPP;
324 case I2C_SMBUS_QUICK: 313 case I2C_SMBUS_QUICK:
325 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 314 outb_p((addr << 1) | read_write,
326 SMBHSTADD); 315 SMBHSTADD);
327 size = PIIX4_QUICK; 316 size = PIIX4_QUICK;
328 break; 317 break;
329 case I2C_SMBUS_BYTE: 318 case I2C_SMBUS_BYTE:
330 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 319 outb_p((addr << 1) | read_write,
331 SMBHSTADD); 320 SMBHSTADD);
332 if (read_write == I2C_SMBUS_WRITE) 321 if (read_write == I2C_SMBUS_WRITE)
333 outb_p(command, SMBHSTCMD); 322 outb_p(command, SMBHSTCMD);
334 size = PIIX4_BYTE; 323 size = PIIX4_BYTE;
335 break; 324 break;
336 case I2C_SMBUS_BYTE_DATA: 325 case I2C_SMBUS_BYTE_DATA:
337 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 326 outb_p((addr << 1) | read_write,
338 SMBHSTADD); 327 SMBHSTADD);
339 outb_p(command, SMBHSTCMD); 328 outb_p(command, SMBHSTCMD);
340 if (read_write == I2C_SMBUS_WRITE) 329 if (read_write == I2C_SMBUS_WRITE)
@@ -342,7 +331,7 @@ static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
342 size = PIIX4_BYTE_DATA; 331 size = PIIX4_BYTE_DATA;
343 break; 332 break;
344 case I2C_SMBUS_WORD_DATA: 333 case I2C_SMBUS_WORD_DATA:
345 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 334 outb_p((addr << 1) | read_write,
346 SMBHSTADD); 335 SMBHSTADD);
347 outb_p(command, SMBHSTCMD); 336 outb_p(command, SMBHSTCMD);
348 if (read_write == I2C_SMBUS_WRITE) { 337 if (read_write == I2C_SMBUS_WRITE) {
@@ -352,15 +341,13 @@ static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
352 size = PIIX4_WORD_DATA; 341 size = PIIX4_WORD_DATA;
353 break; 342 break;
354 case I2C_SMBUS_BLOCK_DATA: 343 case I2C_SMBUS_BLOCK_DATA:
355 outb_p(((addr & 0x7f) << 1) | (read_write & 0x01), 344 outb_p((addr << 1) | read_write,
356 SMBHSTADD); 345 SMBHSTADD);
357 outb_p(command, SMBHSTCMD); 346 outb_p(command, SMBHSTCMD);
358 if (read_write == I2C_SMBUS_WRITE) { 347 if (read_write == I2C_SMBUS_WRITE) {
359 len = data->block[0]; 348 len = data->block[0];
360 if (len < 0) 349 if (len == 0 || len > I2C_SMBUS_BLOCK_MAX)
361 len = 0; 350 return -EINVAL;
362 if (len > 32)
363 len = 32;
364 outb_p(len, SMBHSTDAT0); 351 outb_p(len, SMBHSTDAT0);
365 i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ 352 i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
366 for (i = 1; i <= len; i++) 353 for (i = 1; i <= len; i++)
@@ -390,6 +377,8 @@ static s32 piix4_access(struct i2c_adapter * adap, u16 addr,
390 break; 377 break;
391 case PIIX4_BLOCK_DATA: 378 case PIIX4_BLOCK_DATA:
392 data->block[0] = inb_p(SMBHSTDAT0); 379 data->block[0] = inb_p(SMBHSTDAT0);
380 if (data->block[0] == 0 || data->block[0] > I2C_SMBUS_BLOCK_MAX)
381 return -EPROTO;
393 i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */ 382 i = inb_p(SMBHSTCNT); /* Reset SMBBLKDAT */
394 for (i = 1; i <= data->block[0]; i++) 383 for (i = 1; i <= data->block[0]; i++)
395 data->block[i] = inb_p(SMBBLKDAT); 384 data->block[i] = inb_p(SMBBLKDAT);