Changeset 1756
- Timestamp:
- 06/04/03 04:41:15 (10 years ago)
- Files:
-
- 1 modified
-
lm-sensors/trunk/kernel/busses/i2c-ali15x3.c (modified) (22 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/kernel/busses/i2c-ali15x3.c
r1705 r1756 61 61 /* Note: we assume there can only be one ALI15X3, with one SMBus interface */ 62 62 63 /* #define DEBUG 1 */ 64 63 65 #include <linux/module.h> 64 66 #include <linux/pci.h> … … 70 72 #include <linux/init.h> 71 73 #include <asm/io.h> 72 #include " version.h"74 #include "sensors_compat.h" 73 75 74 76 /* ALI15X3 SMBus address offsets */ 75 #define SMBHSTSTS (0 + ali15x3_smba)76 #define SMBHSTCNT (1 + ali15x3_smba)77 #define SMBHSTSTART (2 + ali15x3_smba)78 #define SMBHSTCMD (7 + ali15x3_smba)79 #define SMBHSTADD (3 + ali15x3_smba)80 #define SMBHSTDAT0 (4 + ali15x3_smba)81 #define SMBHSTDAT1 (5 + ali15x3_smba)82 #define SMBBLKDAT (6 + ali15x3_smba)77 #define SMBHSTSTS (0 + ali15x3_smba) 78 #define SMBHSTCNT (1 + ali15x3_smba) 79 #define SMBHSTSTART (2 + ali15x3_smba) 80 #define SMBHSTCMD (7 + ali15x3_smba) 81 #define SMBHSTADD (3 + ali15x3_smba) 82 #define SMBHSTDAT0 (4 + ali15x3_smba) 83 #define SMBHSTDAT1 (5 + ali15x3_smba) 84 #define SMBBLKDAT (6 + ali15x3_smba) 83 85 84 86 /* PCI Address Constants */ 85 #define SMBCOM 0x00486 #define SMBBA 0x01487 #define SMBATPC 0x05B/* used to unlock xxxBA registers */88 #define SMBHSTCFG 0x0E089 #define SMBSLVC 0x0E190 #define SMBCLK 0x0E291 #define SMBREV 0x00887 #define SMBCOM 0x004 88 #define SMBBA 0x014 89 #define SMBATPC 0x05B /* used to unlock xxxBA registers */ 90 #define SMBHSTCFG 0x0E0 91 #define SMBSLVC 0x0E1 92 #define SMBCLK 0x0E2 93 #define SMBREV 0x008 92 94 93 95 /* Other settings */ 94 #define MAX_TIMEOUT 200/* times 1/100 sec */95 #define ALI15X3_SMB_IOSIZE 3296 #define MAX_TIMEOUT 200 /* times 1/100 sec */ 97 #define ALI15X3_SMB_IOSIZE 32 96 98 97 99 /* this is what the Award 1004 BIOS sets them to on a ASUS P5A MB. … … 99 101 tell user to upgrade BIOS and we fail. 100 102 */ 101 #define ALI15X3_SMB_DEFAULTBASE 0xE800103 #define ALI15X3_SMB_DEFAULTBASE 0xE800 102 104 103 105 /* ALI15X3 address lock bits */ 104 #define ALI15X3_LOCK 0x06106 #define ALI15X3_LOCK 0x06 105 107 106 108 /* ALI15X3 command constants */ 107 #define ALI15X3_ABORT 0x02108 #define ALI15X3_T_OUT 0x04109 #define ALI15X3_QUICK 0x00110 #define ALI15X3_BYTE 0x10111 #define ALI15X3_BYTE_DATA 0x20112 #define ALI15X3_WORD_DATA 0x30113 #define ALI15X3_BLOCK_DATA 0x40114 #define ALI15X3_BLOCK_CLR 0x80109 #define ALI15X3_ABORT 0x02 110 #define ALI15X3_T_OUT 0x04 111 #define ALI15X3_QUICK 0x00 112 #define ALI15X3_BYTE 0x10 113 #define ALI15X3_BYTE_DATA 0x20 114 #define ALI15X3_WORD_DATA 0x30 115 #define ALI15X3_BLOCK_DATA 0x40 116 #define ALI15X3_BLOCK_CLR 0x80 115 117 116 118 /* ALI15X3 status register bits */ … … 131 133 "Initialize the base address of the i2c controller"); 132 134 133 134 static void ali15x3_do_pause(unsigned int amount);135 static int ali15x3_transaction(void);136 137 135 static unsigned short ali15x3_smba = 0; 138 static int locked=0; 139 140 /* Detect whether a ALI15X3 can be found, and initialize it, where necessary. 141 Note the differences between kernels with the old PCI BIOS interface and 142 newer kernels with the real PCI interface. In compat.h some things are 143 defined to make the transition easier. */ 144 int ali15x3_setup(void) 136 137 static int ali15x3_setup(struct pci_dev *ALI15X3_dev) 145 138 { 146 139 u16 a; 147 140 unsigned char temp; 148 141 149 struct pci_dev *ALI15X3_dev; 150 151 /* First check whether we can access PCI at all */ 152 if (pci_present() == 0) { 153 printk("i2c-ali15x3.o: Error: No PCI-bus found!\n"); 154 return -ENODEV; 155 } 156 157 /* Look for the ALI15X3, M7101 device */ 158 ALI15X3_dev = NULL; 159 ALI15X3_dev = pci_find_device(PCI_VENDOR_ID_AL, 160 PCI_DEVICE_ID_AL_M7101, ALI15X3_dev); 161 if (ALI15X3_dev == NULL) { 162 printk("i2c-ali15x3.o: Error: Can't detect ali15x3!\n"); 163 return -ENODEV; 164 } 165 166 /* Check the following things: 167 - SMB I/O address is initialized 168 - Device is enabled 169 - We can use the addresses 170 */ 171 172 /* Unlock the register. 173 The data sheet says that the address registers are read-only 174 if the lock bits are 1, but in fact the address registers 175 are zero unless you clear the lock bits. 176 */ 142 /* Check the following things: 143 - SMB I/O address is initialized 144 - Device is enabled 145 - We can use the addresses 146 */ 147 148 /* Unlock the register. 149 The data sheet says that the address registers are read-only 150 if the lock bits are 1, but in fact the address registers 151 are zero unless you clear the lock bits. 152 */ 177 153 pci_read_config_byte(ALI15X3_dev, SMBATPC, &temp); 178 154 if (temp & ALI15X3_LOCK) { … … 181 157 } 182 158 183 /* Determine the address of the SMBus area */159 /* Determine the address of the SMBus area */ 184 160 pci_read_config_word(ALI15X3_dev, SMBBA, &ali15x3_smba); 185 161 ali15x3_smba &= (0xffff & ~(ALI15X3_SMB_IOSIZE - 1)); 186 162 if (ali15x3_smba == 0 && force_addr == 0) { 187 printk188 ("i2c-ali15x3.o: ALI15X3_smb region uninitialized- upgrade BIOS or use force_addr=0xaddr\n");163 dev_err(ALI15X3_dev, "ALI15X3_smb region uninitialized " 164 "- upgrade BIOS or use force_addr=0xaddr\n"); 189 165 return -ENODEV; 190 166 } … … 193 169 ali15x3_smba = force_addr & ~(ALI15X3_SMB_IOSIZE - 1); 194 170 195 if ( check_region(ali15x3_smba, ALI15X3_SMB_IOSIZE)) {196 printk197 ("i2c-ali15x3.o:ALI15X3_smb region 0x%x already in use!\n",198 ali15x3_smba);171 if (!request_region(ali15x3_smba, ALI15X3_SMB_IOSIZE, "ali15x3-smb")) { 172 dev_err(ALI15X3_dev, 173 "ALI15X3_smb region 0x%x already in use!\n", 174 ali15x3_smba); 199 175 return -ENODEV; 200 176 } 201 177 202 178 if(force_addr) { 203 printk("i2c-ali15x3.o: forcing ISA address 0x%04X\n", ali15x3_smba); 179 dev_info(ALI15X3_dev, "forcing ISA address 0x%04X\n", 180 ali15x3_smba); 204 181 if (PCIBIOS_SUCCESSFUL != 205 182 pci_write_config_word(ALI15X3_dev, SMBBA, ali15x3_smba)) … … 210 187 if ((a & ~(ALI15X3_SMB_IOSIZE - 1)) != ali15x3_smba) { 211 188 /* make sure it works */ 212 printk("i2c-ali15x3.o: force address failed - not supported?\n"); 189 dev_err(ALI15X3_dev, 190 "force address failed - not supported?\n"); 213 191 return -ENODEV; 214 192 } 215 193 } 216 /* check if whole device is enabled */194 /* check if whole device is enabled */ 217 195 pci_read_config_byte(ALI15X3_dev, SMBCOM, &temp); 218 196 if ((temp & 1) == 0) { 219 printk("i2c-ali15x3:enabling SMBus device\n");197 dev_info(ALI15X3_dev, "enabling SMBus device\n"); 220 198 pci_write_config_byte(ALI15X3_dev, SMBCOM, temp | 0x01); 221 199 } 222 200 223 /* Is SMB Host controller enabled? */201 /* Is SMB Host controller enabled? */ 224 202 pci_read_config_byte(ALI15X3_dev, SMBHSTCFG, &temp); 225 203 if ((temp & 1) == 0) { 226 printk("i2c-ali15x3:enabling SMBus controller\n");204 dev_info(ALI15X3_dev, "enabling SMBus controller\n"); 227 205 pci_write_config_byte(ALI15X3_dev, SMBHSTCFG, temp | 0x01); 228 206 } 229 207 230 /* set SMB clock to 74KHz as recommended in data sheet */208 /* set SMB clock to 74KHz as recommended in data sheet */ 231 209 pci_write_config_byte(ALI15X3_dev, SMBCLK, 0x20); 232 210 233 /* Everything is happy, let's grab the memory and set things up. */ 234 request_region(ali15x3_smba, ALI15X3_SMB_IOSIZE, "ali15x3-smb"); 235 236 #ifdef DEBUG 237 /* 238 The interrupt routing for SMB is set up in register 0x77 in the 239 1533 ISA Bridge device, NOT in the 7101 device. 240 Don't bother with finding the 1533 device and reading the register. 241 if ((....... & 0x0F) == 1) 242 printk("i2c-ali15x3.o: ALI15X3 using Interrupt 9 for SMBus.\n"); 243 */ 211 /* 212 The interrupt routing for SMB is set up in register 0x77 in the 213 1533 ISA Bridge device, NOT in the 7101 device. 214 Don't bother with finding the 1533 device and reading the register. 215 if ((....... & 0x0F) == 1) 216 dev_dbg(&ALI15X3_dev, "ALI15X3 using Interrupt 9 for SMBus.\n"); 217 */ 244 218 pci_read_config_byte(ALI15X3_dev, SMBREV, &temp); 245 printk("i2c-ali15x3.o: SMBREV = 0x%X\n", temp); 246 printk("i2c-ali15x3.o: ALI15X3_smba = 0x%X\n", ali15x3_smba); 247 #endif /* DEBUG */ 219 dev_dbg(&ALI15X3_dev, "SMBREV = 0x%X\n", temp); 220 dev_dbg(&ALI15X3_dev, "iALI15X3_smba = 0x%X\n", ali15x3_smba); 248 221 249 222 return 0; 250 223 } 251 224 252 253 225 /* Internally used pause function */ 254 void ali15x3_do_pause(unsigned int amount)226 static void ali15x3_do_pause(unsigned int amount) 255 227 { 256 228 current->state = TASK_INTERRUPTIBLE; … … 259 231 260 232 /* Another internally used function */ 261 int ali15x3_transaction(void)233 static int ali15x3_transaction(struct i2c_adapter *adap) 262 234 { 263 235 int temp; … … 265 237 int timeout = 0; 266 238 267 #ifdef DEBUG 268 printk 269 ("i2c-ali15x3.o: Transaction (pre): STS=%02x, CNT=%02x, CMD=%02x, ADD=%02x, DAT0=%02x, " 270 "DAT1=%02x\n", inb_p(SMBHSTSTS), inb_p(SMBHSTCNT), 271 inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), 272 inb_p(SMBHSTDAT1)); 273 #endif 239 dev_dbg(&adap, "Transaction (pre): STS=%02x, CNT=%02x, CMD=%02x, " 240 "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTSTS), 241 inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), inb_p(SMBHSTADD), 242 inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1)); 274 243 275 244 /* get status */ … … 279 248 /* Check the busy bit first */ 280 249 if (temp & ALI15X3_STS_BUSY) { 281 /* 282 If the host controller is still busy, it may have timed out in the previous transaction, 283 resulting in a "SMBus Timeout" printk. 284 I've tried the following to reset a stuck busy bit. 285 1. Reset the controller with an ABORT command. 286 (this doesn't seem to clear the controller if an external device is hung) 287 2. Reset the controller and the other SMBus devices with a T_OUT command. 288 (this clears the host busy bit if an external device is hung, 289 but it comes back upon a new access to a device) 290 3. Disable and reenable the controller in SMBHSTCFG 291 Worst case, nothing seems to work except power reset. 292 */ 293 /* Abort - reset the host controller */ 294 /* 295 #ifdef DEBUG 296 printk("i2c-ali15x3.o: Resetting host controller to clear busy condition\n",temp); 297 #endif 298 outb_p(ALI15X3_ABORT, SMBHSTCNT); 299 temp = inb_p(SMBHSTSTS); 300 if (temp & ALI15X3_STS_BUSY) { 301 */ 302 303 /* 304 Try resetting entire SMB bus, including other devices - 305 This may not work either - it clears the BUSY bit but 306 then the BUSY bit may come back on when you try and use the chip again. 307 If that's the case you are stuck. 308 */ 309 printk 310 ("i2c-ali15x3.o: Resetting entire SMB Bus to clear busy condition (%02x)\n", 311 temp); 250 /* 251 If the host controller is still busy, it may have timed out in the 252 previous transaction, resulting in a "SMBus Timeout" Dev. 253 I've tried the following to reset a stuck busy bit. 254 1. Reset the controller with an ABORT command. 255 (this doesn't seem to clear the controller if an external 256 device is hung) 257 2. Reset the controller and the other SMBus devices with a 258 T_OUT command. (this clears the host busy bit if an 259 external device is hung, but it comes back upon a new access 260 to a device) 261 3. Disable and reenable the controller in SMBHSTCFG 262 Worst case, nothing seems to work except power reset. 263 */ 264 /* Abort - reset the host controller */ 265 /* 266 Try resetting entire SMB bus, including other devices - 267 This may not work either - it clears the BUSY bit but 268 then the BUSY bit may come back on when you try and use the chip again. 269 If that's the case you are stuck. 270 */ 271 dev_info(adap, "Resetting entire SMB Bus to " 272 "clear busy condition (%02x)\n", temp); 312 273 outb_p(ALI15X3_T_OUT, SMBHSTCNT); 313 274 temp = inb_p(SMBHSTSTS); 314 275 } 315 /*316 }317 */318 276 319 277 /* now check the error bits and the busy bit */ … … 326 284 as one of the bits now appears to be stuck */ 327 285 /* This may be a bus or device with electrical problems. */ 328 printk329 ("i2c-ali15x3.o: SMBus reset failed! (0x%02x) -controller or device on bus is probably hung\n",330 temp);286 dev_err(adap, "SMBus reset failed! (0x%02x) - " 287 "controller or device on bus is probably hung\n", 288 temp); 331 289 return -1; 332 290 } … … 352 310 if (timeout >= MAX_TIMEOUT) { 353 311 result = -1; 354 printk("i2c-ali15x3.o:SMBus Timeout!\n");312 dev_err(adap, "SMBus Timeout!\n"); 355 313 } 356 314 357 315 if (temp & ALI15X3_STS_TERM) { 358 316 result = -1; 359 #ifdef DEBUG 360 printk("i2c-ali15x3.o: Error: Failed bus transaction\n"); 361 #endif 362 } 363 364 /* 365 Unfortunately the ALI SMB controller maps "no response" and "bus collision" 366 into a single bit. No reponse is the usual case so don't 367 do a printk. 368 This means that bus collisions go unreported. 369 */ 317 dev_dbg(&adap, "Error: Failed bus transaction\n"); 318 } 319 320 /* 321 Unfortunately the ALI SMB controller maps "no response" and "bus 322 collision" into a single bit. No reponse is the usual case so don't 323 do a printk. 324 This means that bus collisions go unreported. 325 */ 370 326 if (temp & ALI15X3_STS_COLL) { 371 327 result = -1; 372 #ifdef DEBUG 373 printk 374 ("i2c-ali15x3.o: Error: no response or bus collision ADD=%02x\n", 375 inb_p(SMBHSTADD)); 376 #endif 377 } 378 379 /* haven't ever seen this */ 328 dev_dbg(&adap, 329 "Error: no response or bus collision ADD=%02x\n", 330 inb_p(SMBHSTADD)); 331 } 332 333 /* haven't ever seen this */ 380 334 if (temp & ALI15X3_STS_DEV) { 381 335 result = -1; 382 printk("i2c-ali15x3.o: Error: device error\n"); 383 } 384 #ifdef DEBUG 385 printk 386 ("i2c-ali15x3.o: Transaction (post): STS=%02x, CNT=%02x, CMD=%02x, ADD=%02x, " 387 "DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTSTS), inb_p(SMBHSTCNT), 388 inb_p(SMBHSTCMD), inb_p(SMBHSTADD), inb_p(SMBHSTDAT0), 389 inb_p(SMBHSTDAT1)); 390 #endif 336 dev_err(adap, "Error: device error\n"); 337 } 338 dev_dbg(&adap, "Transaction (post): STS=%02x, CNT=%02x, CMD=%02x, " 339 "ADD=%02x, DAT0=%02x, DAT1=%02x\n", inb_p(SMBHSTSTS), 340 inb_p(SMBHSTCNT), inb_p(SMBHSTCMD), inb_p(SMBHSTADD), 341 inb_p(SMBHSTDAT0), inb_p(SMBHSTDAT1)); 391 342 return result; 392 343 } 393 344 394 345 /* Return -1 on error. */ 395 s 32 ali15x3_access(struct i2c_adapter * adap, u16 addr,346 static s32 ali15x3_access(struct i2c_adapter * adap, u16 addr, 396 347 unsigned short flags, char read_write, u8 command, 397 348 int size, union i2c_smbus_data * data) … … 401 352 int timeout; 402 353 403 /* clear all the bits (clear-on-write) */354 /* clear all the bits (clear-on-write) */ 404 355 outb_p(0xFF, SMBHSTSTS); 405 /* make sure SMBus is idle */356 /* make sure SMBus is idle */ 406 357 temp = inb_p(SMBHSTSTS); 407 358 for (timeout = 0; … … 412 363 } 413 364 if (timeout >= MAX_TIMEOUT) { 414 printk("i2c-ali15x3.o: Idle wait Timeout! STS=0x%02x\n", 415 temp); 365 dev_err(adap, "Idle wait Timeout! STS=0x%02x\n", temp); 416 366 } 417 367 418 368 switch (size) { 419 369 case I2C_SMBUS_PROC_CALL: 420 printk 421 ("i2c-ali15x3.o: I2C_SMBUS_PROC_CALL not supported!\n"); 370 dev_err(adap, "I2C_SMBUS_PROC_CALL not supported!\n"); 422 371 return -1; 423 372 case I2C_SMBUS_QUICK: … … 466 415 } 467 416 outb_p(len, SMBHSTDAT0); 468 outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT); /* Reset SMBBLKDAT */ 417 /* Reset SMBBLKDAT */ 418 outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT); 469 419 for (i = 1; i <= len; i++) 470 420 outb_p(data->block[i], SMBBLKDAT); … … 476 426 outb_p(size, SMBHSTCNT); /* output command */ 477 427 478 if (ali15x3_transaction( )) /* Error in transaction */428 if (ali15x3_transaction(adap)) /* Error in transaction */ 479 429 return -1; 480 430 … … 498 448 len = 32; 499 449 data->block[0] = len; 500 outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT); /* Reset SMBBLKDAT */ 450 /* Reset SMBBLKDAT */ 451 outb_p(inb_p(SMBHSTCNT) | ALI15X3_BLOCK_CLR, SMBHSTCNT); 501 452 for (i = 1; i <= data->block[0]; i++) { 502 453 data->block[i] = inb_p(SMBBLKDAT); 503 #ifdef DEBUG 504 printk 505 ("i2c-ali15x3.o: Blk: len=%d, i=%d, data=%02x\n", 506 len, i, data->block[i]); 507 #endif /* DEBUG */ 454 dev_dbg(&adap, "Blk: len=%d, i=%d, data=%02x\n", 455 len, i, data->block[i]); 508 456 } 509 457 break; … … 512 460 } 513 461 514 515 u32 ali15x3_func(struct i2c_adapter *adapter) 462 static u32 ali15x3_func(struct i2c_adapter *adapter) 516 463 { 517 464 return I2C_FUNC_SMBUS_QUICK | I2C_FUNC_SMBUS_BYTE | … … 529 476 static struct i2c_adapter ali15x3_adapter = { 530 477 .owner = THIS_MODULE, 531 .name = "unset",532 478 .id = I2C_ALGO_SMBUS | I2C_HW_SMBUS_ALI15X3, 533 479 .algo = &smbus_algorithm, 480 .name = "unset", 534 481 }; 535 482 536 537 538 483 static struct pci_device_id ali15x3_ids[] __devinitdata = { 484 { 485 .vendor = PCI_VENDOR_ID_AL, 486 .device = PCI_DEVICE_ID_AL_M7101, 487 .subvendor = PCI_ANY_ID, 488 .subdevice = PCI_ANY_ID, 489 }, 539 490 { 0, } 540 491 }; … … 542 493 static int __devinit ali15x3_probe(struct pci_dev *dev, const struct pci_device_id *id) 543 494 { 544 if (ali15x3_setup()) { 545 printk 546 ("i2c-ali15x3.o: ALI15X3 not detected, module not inserted.\n"); 547 495 if (ali15x3_setup(dev)) { 496 dev_err(dev, 497 "ALI15X3 not detected, module not inserted.\n"); 548 498 return -ENODEV; 549 499 } 550 500 551 s printf(ali15x3_adapter.name, "SMBus ALI15X3 adapter at %04x",552 ali15x3_smba);553 i2c_add_adapter(&ali15x3_adapter);501 snprintf(ali15x3_adapter.name, 32, 502 "SMBus ALI15X3 adapter at %04x", ali15x3_smba); 503 return i2c_add_adapter(&ali15x3_adapter); 554 504 } 555 505 … … 568 518 static int __init i2c_ali15x3_init(void) 569 519 { 570 printk("i2c-ali15x3.o version %s (%s)\n", LM_VERSION, LM_DATE);520 printk("i2c-ali15x3.o version %s (%s)\n", I2C_VERSION, I2C_DATE); 571 521 return pci_module_init(&ali15x3_driver); 572 522 } 573 574 523 575 524 static void __exit i2c_ali15x3_exit(void) … … 579 528 } 580 529 581 582 583 MODULE_AUTHOR 584 ("Frodo Looijaard <frodol@dds.nl>, Philip Edelbrock <phil@netroedge.com>, and Mark D. Studebaker <mdsxyz123@yahoo.com>"); 530 MODULE_AUTHOR ("Frodo Looijaard <frodol@dds.nl>, " 531 "Philip Edelbrock <phil@netroedge.com>, " 532 "and Mark D. Studebaker <mdsxyz123@yahoo.com>"); 585 533 MODULE_DESCRIPTION("ALI15X3 SMBus driver"); 586 534 MODULE_LICENSE("GPL");
