Changeset 1704
- Timestamp:
- 01/21/03 05:53:16 (10 years ago)
- Files:
-
- 1 modified
-
lm-sensors/trunk/kernel/busses/i2c-sis645.c (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/kernel/busses/i2c-sis645.c
r1700 r1704 47 47 #include <linux/init.h> 48 48 49 MODULE_LICENSE("GPL"); 49 #define DRV_NAME "i2c-sis645" 50 50 51 51 /* PCI identifiers */ … … 90 90 91 91 /* base address register in PCI config space */ 92 #define BASE_IO_REG0x0492 #define SIS645_BAR 0x04 93 93 94 94 /* SiS645 SMBus registers */ … … 121 121 #define SIS645_BLOCK_DATA 0x05 122 122 123 static int sis645_enable_smbus(struct pci_dev *dev);124 static int sis645_build_dev(struct pci_dev **smbus_dev,125 struct pci_dev *bridge_dev);126 127 123 static void sis645_do_pause(unsigned int amount); 128 124 static int sis645_transaction(int size); 129 125 130 126 static struct i2c_adapter sis645_adapter; 131 127 132 128 static unsigned short sis645_smbus_base = 0; … … 146 142 /* Turns on SMBus device if it is not; return 0 iff successful 147 143 */ 148 static int sis645_enable_smbus(struct pci_dev *dev)144 static int __devinit sis645_enable_smbus(struct pci_dev *dev) 149 145 { 150 146 u8 val = 0; … … 153 149 154 150 #ifdef DEBUG 155 printk( "i2c-sis645.o: Config byte was 0x%02x.\n", val);151 printk(KERN_DEBUG DRV_NAME ": Config byte was 0x%02x.\n", val); 156 152 #endif 157 153 … … 162 158 if (val & 0x10) { 163 159 #ifdef DEBUG 164 printk( "i2c-sis645.o: Error: Config byte stuck!\n");160 printk(KERN_DEBUG DRV_NAME ": Config byte stuck!\n"); 165 161 #endif 166 162 return -1; … … 172 168 /* Builds the basic pci_dev for SiS645 SMBus 173 169 */ 174 static int sis645_build_dev(struct pci_dev **smbus_dev,170 static int __devinit sis645_build_dev(struct pci_dev **smbus_dev, 175 171 struct pci_dev *bridge_dev) 176 172 { … … 191 187 ret = pci_read_config_word(&temp_dev, PCI_VENDOR_ID, &vid); 192 188 if (ret || PCI_VENDOR_ID_SI != vid) { 193 printk( "i2c-sis645.o: Couldn't find SMBus device!\n");189 printk(KERN_ERR DRV_NAME ": Couldn't find SMBus device!\n"); 194 190 return ret; 195 191 } … … 198 194 ret = pci_read_config_word(&temp_dev, PCI_DEVICE_ID, &did); 199 195 if (ret || PCI_DEVICE_ID_SI_SMBUS != did) { 200 printk( "i2c-sis645.o: Couldn't find SMBus device!\n");196 printk(KERN_ERR DRV_NAME ": Couldn't find SMBus device!\n"); 201 197 return ret; 202 198 } … … 206 202 *smbus_dev = kmalloc(sizeof(**smbus_dev), GFP_ATOMIC); 207 203 if (NULL == *smbus_dev) { 208 printk( "i2c-sis645.o: Error: Out of memory!\n");204 printk(KERN_ERR DRV_NAME ": Out of memory!\n"); 209 205 return -ENOMEM; 210 206 } … … 214 210 ret = pci_setup_device(*smbus_dev); 215 211 if (ret) { 216 printk( "i2c-sis645.o: pci_setup_device failed (0x%08x)\n",ret);212 printk(KERN_ERR DRV_NAME ": pci_setup_device failed (0x%08x)\n",ret); 217 213 } 218 214 return ret; … … 223 219 /* Detect whether a SiS645 can be found, and initialize it, where necessary. 224 220 */ 225 static int sis645_setup(void) 226 { 227 struct pci_dev *SIS645_ISA_dev; 221 static int __devinit sis645_probe(struct pci_dev *dev, const struct pci_device_id *id) 222 { 228 223 struct pci_dev *SIS645_SMBUS_dev; 229 224 int ret; 230 225 u16 ww = 0; 231 226 232 if (pci_present() == 0) { 233 printk("i2c-sis645.o: Error: No PCI-bus found!\n"); 234 return -ENODEV; 235 } 236 237 if (SIS645_ISA_dev = pci_find_device(PCI_VENDOR_ID_SI, 238 PCI_DEVICE_ID_SI_961, NULL)) { 239 printk("i2c-sis645.o: Found SiS961 south bridge.\n"); 240 } 241 242 else if (SIS645_ISA_dev = pci_find_device(PCI_VENDOR_ID_SI, 243 PCI_DEVICE_ID_SI_962, NULL)) { 244 printk("i2c-sis645.o: Found SiS962 [MuTIOL Media IO].\n"); 245 } 246 247 else if (SIS645_ISA_dev = pci_find_device(PCI_VENDOR_ID_SI, 248 PCI_DEVICE_ID_SI_503, NULL)) { 249 printk("i2c-sis645.o: Found SiS south bridge in compatability mode(?)\n"); 227 if (sis645_smbus_base) { 228 printk(KERN_ERR DRV_NAME ": Only one device supported.\n"); 229 return -EBUSY; 230 } 231 232 switch (dev->device) { 233 case PCI_DEVICE_ID_SI_961: 234 printk(KERN_INFO DRV_NAME ": Found SiS961 south bridge.\n"); 235 break; 236 237 case PCI_DEVICE_ID_SI_962: 238 printk(KERN_INFO DRV_NAME ": Found SiS962 [MuTIOL Media IO].\n"); 239 break; 240 241 case PCI_DEVICE_ID_SI_503: 242 printk(KERN_INFO DRV_NAME ": Found SiS south bridge in compatability mode(?)\n"); 250 243 251 244 /* look for known compatible north bridges */ … … 260 253 && (NULL == pci_find_device(PCI_VENDOR_ID_SI, 261 254 PCI_DEVICE_ID_SI_735, NULL))) { 262 printk( "i2c-sis645.o: Error: Can't find suitable host bridge!\n");255 printk(KERN_ERR DRV_NAME ": Can't find suitable host bridge!\n"); 263 256 return -ENODEV; 264 257 } 265 }266 267 else {268 printk( "i2c-sis645.o: Error: Can't find suitable south bridge!\n");258 break ; 259 260 default: 261 printk(KERN_ERR DRV_NAME ": Can't find suitable south bridge!\n"); 269 262 return -ENODEV; 270 263 } … … 273 266 PCI_DEVICE_ID_SI_SMBUS, NULL))) { 274 267 275 printk( "i2c-sis645.o: "268 printk(KERN_INFO DRV_NAME ": " 276 269 "Attempting to enable SiS645 SMBus device\n"); 277 270 278 271 #ifndef CONFIG_HOTPLUG 279 printk( "i2c-sis645.o: "272 printk(KERN_INFO DRV_NAME ": " 280 273 "Requires kernel >= 2.4 with CONFIG_HOTPLUG, sorry!\n"); 281 274 return -ENODEV; 282 275 283 276 #else /* CONFIG_HOTPLUG */ 284 if (ret = sis645_enable_smbus( SIS645_ISA_dev)) {277 if (ret = sis645_enable_smbus(dev)) { 285 278 return ret; 286 279 } 287 280 288 if (ret = sis645_build_dev(&SIS645_SMBUS_dev, SIS645_ISA_dev)) {281 if (ret = sis645_build_dev(&SIS645_SMBUS_dev, dev)) { 289 282 return ret; 290 283 } 291 284 292 285 if (ret = pci_enable_device(SIS645_SMBUS_dev)) { 293 printk( "i2c-sis645.o: Can't pci_enable SMBus device!"286 printk(KERN_ERR DRV_NAME ": Can't pci_enable SMBus device!" 294 287 " (0x%08x)\n", ret); 295 288 return ret; … … 304 297 pci_read_config_word(SIS645_SMBUS_dev, PCI_CLASS_DEVICE, &ww); 305 298 if (PCI_CLASS_SERIAL_SMBUS != ww) { 306 printk( "i2c-sis645.o: Error: Unsupported device class 0x%04x!\n", ww);299 printk(KERN_ERR DRV_NAME ": Unsupported device class 0x%04x!\n", ww); 307 300 return -ENODEV; 308 301 } 309 302 310 303 /* get the IO base address */ 311 sis645_smbus_base = SIS645_SMBUS_dev->resource[BASE_IO_REG].start;304 sis645_smbus_base = pci_resource_start(SIS645_SMBUS_dev, SIS645_BAR); 312 305 if (!sis645_smbus_base) { 313 printk( "i2c-sis645.o: SiS645 SMBus base address not initialized!\n");306 printk(KERN_ERR DRV_NAME ": SiS645 SMBus base address not initialized!\n"); 314 307 return -EINVAL; 315 308 } 316 printk( "i2c-sis645.o: SiS645 SMBus base address: 0x%04x\n", sis645_smbus_base);309 printk(KERN_INFO DRV_NAME ": SiS645 SMBus base address: 0x%04x\n", sis645_smbus_base); 317 310 318 311 /* Everything is happy, let's grab the memory and set things up. */ 319 312 if (!request_region(sis645_smbus_base, SIS645_SMB_IOREGION, "sis645-smbus")) { 320 printk 321 ("i2c-sis645.o: SMBus registers 0x%04x-0x%04x already in use!\n", 313 printk(KERN_ERR DRV_NAME ": SMBus registers 0x%04x-0x%04x already in use!\n", 322 314 sis645_smbus_base, sis645_smbus_base + SIS645_SMB_IOREGION - 1); 323 315 return -EINVAL; 324 316 } 325 317 318 sprintf(sis645_adapter.name, "SMBus SiS645 adapter at 0x%04x", sis645_smbus_base); 319 i2c_add_adapter(&sis645_adapter); 320 326 321 return(0); 327 322 } 328 329 323 330 324 /* Internally used pause function */ … … 347 341 if (((temp = sis645_read(SMB_CNT)) & 0x03) != 0x00) { 348 342 #ifdef DEBUG 349 printk( "i2c-sis645.o: SMBus busy (0x%02x). Resetting...\n",343 printk(KERN_DEBUG DRV_NAME ": SMBus busy (0x%02x). Resetting...\n", 350 344 temp); 351 345 #endif … … 357 351 if (((temp = sis645_read(SMB_CNT)) & 0x03) != 0x00) { 358 352 #ifdef DEBUG 359 printk( "i2c-sis645.o: Failed! (0x%02x)\n", temp);353 printk(KERN_DEBUG DRV_NAME ": Failed! (0x%02x)\n", temp); 360 354 #endif 361 355 return -1; 362 356 } else { 363 357 #ifdef DEBUG 364 printk( "i2c-sis645.o: Successful!\n");358 printk(KERN_DEBUG DRV_NAME ": Successful!\n"); 365 359 #endif 366 360 } … … 385 379 /* If the SMBus is still busy, we give up */ 386 380 if (timeout >= MAX_TIMEOUT) { 387 printk( "i2c-sis645.o: SMBus Timeout! (0x%02x)\n",temp);381 printk(KERN_DEBUG DRV_NAME ": SMBus Timeout! (0x%02x)\n",temp); 388 382 result = -1; 389 383 } … … 392 386 if (temp & 0x02) { 393 387 #ifdef DEBUG 394 printk( "i2c-sis645.o: Error: Failed bus transaction!\n");388 printk(KERN_DEBUG DRV_NAME ": Failed bus transaction!\n"); 395 389 #endif 396 390 result = -1; … … 400 394 if (temp & 0x04) { 401 395 #ifdef DEBUG 402 printk( "i2c-sis645.o: Error: Bus collision!\n");396 printk(KERN_DEBUG DRV_NAME ": Bus collision!\n"); 403 397 #endif 404 398 result = -1; … … 409 403 if (temp = sis645_read(SMB_STS)) { 410 404 #ifdef DEBUG 411 printk( "i2c-sis645.o: Failed reset at end of transaction!"405 printk(KERN_DEBUG DRV_NAME ": Failed reset at end of transaction!" 412 406 " (0x%02x)\n", temp); 413 407 #endif … … 457 451 case I2C_SMBUS_BLOCK_DATA: 458 452 /* TO DO: */ 459 printk( "sis645.o: SMBus block not implemented!\n");453 printk(KERN_INFO DRV_NAME ": SMBus block not implemented!\n"); 460 454 return -1; 461 455 break; 462 456 463 457 default: 464 printk( "sis645.o: unsupported I2C size\n");458 printk(KERN_INFO DRV_NAME ": Unsupported I2C size\n"); 465 459 return -1; 466 460 break; … … 523 517 }; 524 518 525 static int __devinit sis645_probe(struct pci_dev *dev, const struct pci_device_id *id)526 {527 528 if (sis645_setup()) {529 printk ("i2c-sis645.o: SiS645 not detected, module not inserted.\n");530 531 return -ENODEV;532 }533 534 sprintf(sis645_adapter.name, "SMBus SiS645 adapter at 0x%04x", sis645_smbus_base);535 i2c_add_adapter(&sis645_adapter);536 }537 538 519 static void __devexit sis645_remove(struct pci_dev *dev) 539 520 { … … 551 532 static int __init i2c_sis645_init(void) 552 533 { 553 printk( "i2c-sis645.o:version %s (%s)\n", LM_VERSION, LM_DATE);534 printk(KERN_INFO DRV_NAME ".o version %s (%s)\n", LM_VERSION, LM_DATE); 554 535 return pci_module_init(&sis645_driver); 555 536 } … … 566 547 MODULE_AUTHOR("Mark M. Hoffman <mhoffman@lightlink.com>"); 567 548 MODULE_DESCRIPTION("SiS645 SMBus driver"); 549 MODULE_LICENSE("GPL"); 568 550 569 551 /* Register initialization functions using helper macros */
