Changeset 325
- Timestamp:
- 03/19/99 07:25:02 (14 years ago)
- Location:
- lm-sensors/trunk
- Files:
-
- 4 modified
-
kernel/chips/lm78.c (modified) (13 diffs)
-
kernel/include/sensors.h (modified) (2 diffs)
-
kernel/sensors.c (modified) (7 diffs)
-
prog/detect/sensors-detect (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/kernel/chips/lm78.c
r219 r325 34 34 #include "compat.h" 35 35 36 /* Addresses to scan */ 37 static unsigned short normal_i2c[] = {SENSORS_I2C_END}; 38 static unsigned short normal_i2c_range[] = {0x20,0x2f,SENSORS_I2C_END}; 39 static unsigned int normal_isa[] = {0x0290,SENSORS_ISA_END}; 40 static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; 41 42 /* Insmod parameters */ 43 SENSORS_INSMOD_3(lm78,lm78j,lm79); 36 44 /* Many LM78 constants specified below */ 37 45 … … 62 70 #define LM78_REG_CONFIG 0x40 63 71 #define LM78_REG_CHIPID 0x49 72 #define LM78_REG_I2C_ADDR 0x48 64 73 65 74 … … 150 159 some corners. */ 151 160 152 /* Types of chips supported */153 enum lm78_type { lm78, lm78j, lm79 };154 155 161 /* For each registered LM78, we need to keep some data in memory. That 156 162 data is pointed to by lm78_list[NR]->data. The structure itself is … … 160 166 struct semaphore lock; 161 167 int sysctl_id; 162 enum lm78_typetype;168 enum chips type; 163 169 164 170 struct semaphore update_lock; … … 184 190 185 191 static int lm78_attach_adapter(struct i2c_adapter *adapter); 186 static int lm78_detect_isa(struct isa_adapter *adapter); 187 static int lm78_detect_smbus(struct i2c_adapter *adapter); 192 static int lm78_detect(struct i2c_adapter *adapter, int address, int kind); 188 193 static int lm78_detach_client(struct i2c_client *client); 189 static int lm78_detach_isa(struct isa_client *client);190 static int lm78_detach_smbus(struct i2c_client *client);191 static int lm78_new_client(struct i2c_adapter *adapter,192 struct i2c_client *new_client);193 static void lm78_remove_client(struct i2c_client *client);194 194 static int lm78_command(struct i2c_client *client, unsigned int cmd, 195 195 void *arg); … … 219 219 allocation could also be used; the code needed for this would probably 220 220 take more memory than the datastructure takes now. */ 221 #define MAX_LM78_NR 4221 #define MAX_LM78_NR 8 222 222 static struct i2c_client *lm78_list[MAX_LM78_NR]; 223 223 … … 283 283 int lm78_attach_adapter(struct i2c_adapter *adapter) 284 284 { 285 if (i2c_is_isa_adapter(adapter)) 286 return lm78_detect_isa((struct isa_adapter *) adapter); 287 else 288 return lm78_detect_smbus(adapter); 289 } 290 291 /* This function is called whenever a client should be removed: 292 * lm78_driver is removed (when this module is unloaded) 293 * when an adapter is removed which has a lm78 client (and lm78_driver 294 is still present). */ 295 int lm78_detach_client(struct i2c_client *client) 296 { 297 if (i2c_is_isa_client(client)) 298 return lm78_detach_isa((struct isa_client *) client); 299 else 300 return lm78_detach_smbus(client); 301 } 302 303 /* Detect whether there is a LM78 on the ISA bus, register and initialize 304 it. */ 305 int lm78_detect_isa(struct isa_adapter *adapter) 306 { 307 int address,err; 308 struct isa_client *new_client; 309 enum lm78_type type; 310 const char *type_name; 311 const char *client_name; 312 313 /* OK, this is no detection. I know. It will do for now, though. */ 314 315 err = 0; 316 for (address = 0x290; (! err) && (address <= 0x290); address += 0x08) { 317 if (check_region(address, LM78_EXTENT)) 318 continue; 319 320 if (inb_p(address + LM78_ADDR_REG_OFFSET) == 0xff) { 321 outb_p(0x00,address + LM78_ADDR_REG_OFFSET); 322 if (inb_p(address + LM78_ADDR_REG_OFFSET) == 0xff) 323 continue; 285 return sensors_detect(adapter,&addr_data,lm78_detect); 286 } 287 288 /* This function is called by sensors_detect */ 289 int lm78_detect(struct i2c_adapter *adapter, int address, int kind) 290 { 291 int i; 292 struct i2c_client *new_client; 293 struct lm78_data *data; 294 int err=0; 295 const char *type_name = ""; 296 const char *client_name = ""; 297 298 299 if (kind < 0) { 300 /* We need address registration for the I2C bus too. That is not yet 301 implemented. */ 302 if (i2c_is_isa_adapter(adapter)) { 303 304 #define REALLY_SLOW_IO 305 /* We need the timeouts for at least some LM78-like chips. But only 306 if we read 'undefined' registers. */ 307 if (check_region(address,LM78_EXTENT)) 308 goto ERROR0; 309 i = inb_p(address + 1); 310 if (inb_p(address + 2) != i) 311 goto ERROR0; 312 if (inb_p(address + 3) != i) 313 goto ERROR0; 314 if (inb_p(address + 7) != i) 315 goto ERROR0; 316 #undef REALLY_SLOW_IO 317 318 /* Let's just hope nothing breaks here */ 319 i = inb_p(address + 5) & 0x7f; 320 outb_p(~i & 0x7f,address+5); 321 if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) { 322 outb_p(i,address+5); 323 return 0; 324 } 324 325 } 326 } 327 328 /* OK. For now, we presume we have a valid client. We now create the 329 client structure, even though we cannot fill it completely yet. 330 But it allows us to access lm78_{read,write}_value. */ 331 332 if (! (new_client = kmalloc((i2c_is_isa_adapter(adapter)? 333 sizeof(struct isa_client): 334 sizeof(struct i2c_client)) + 335 sizeof(struct lm78_data), 336 GFP_KERNEL))) { 337 err = -ENOMEM; 338 goto ERROR0; 339 } 340 341 if (i2c_is_isa_adapter(adapter)) { 342 data = (struct lm78_data *) (((struct isa_client *) new_client) + 1); 343 new_client->addr = 0; 344 ((struct isa_client *) new_client)->isa_addr = address; 345 data->lock = MUTEX; 346 } else { 347 data = (struct lm78_data *) (((struct i2c_client *) new_client) + 1); 348 new_client->addr = address; 349 } 350 new_client->data = data; 351 new_client->adapter = adapter; 352 new_client->driver = &lm78_driver; 353 354 /* Now, we do the remaining detection. */ 355 356 if (kind < 0) { 357 if (lm78_read_value(new_client,LM78_REG_CONFIG) & 0x80) 358 goto ERROR1; 359 if (!i2c_is_isa_adapter(adapter) && 360 (lm78_read_value(new_client,LM78_REG_I2C_ADDR) != address)) 361 goto ERROR1; 362 } 325 363 326 /* Real detection code goes here */ 327 328 /* Determine exact type */ 329 outb_p(LM78_REG_CHIPID,address + LM78_ADDR_REG_OFFSET); 330 err = inb_p(address + LM78_DATA_REG_OFFSET) & 0xfe; 331 if (err == 0x00) { 332 type = lm78; 364 /* Determine the chip type. */ 365 if (kind <= 0) { 366 i = lm78_read_value(new_client,LM78_REG_CHIPID); 367 if (i == 0x00) { 368 kind = lm78; 333 369 type_name = "lm78"; 334 370 client_name = "LM78 chip"; 335 } else if ( err== 0x40) {336 type= lm78j;371 } else if (i == 0x40) { 372 kind = lm78j; 337 373 type_name = "lm78-j"; 338 374 client_name = "LM78-J chip"; 339 } else if ( err== 0xc0) {340 type= lm79;375 } else if ((i & 0xfe) == 0xc0) { 376 kind = lm79; 341 377 type_name = "lm79"; 342 378 client_name = "LM79 chip"; 343 } else if (err == 0x02) { 344 printk("lm78.o: Warning: Winbond W83781D detected (treated as a LM79)\n"); 345 type = lm79; 346 type_name = "lm79"; 347 client_name = "LM79 chip"; 348 } else { 349 #ifdef DEBUG 350 printk("lm78.o: warning: probed non-lm78 chip?!? (%x)\n",err); 351 #endif 352 continue; 353 } 354 379 } else 380 goto ERROR1; 381 } 382 383 /* Reserve the ISA region */ 384 if i2c_is_isa_adapter(adapter) 355 385 request_region(address, LM78_EXTENT, type_name); 356 386 357 /* Allocate space for a new client structure*/358 if (! (new_client = kmalloc(sizeof(struct isa_client) +359 sizeof(struct lm78_data),360 GFP_KERNEL))) 361 {362 err=-ENOMEM;363 goto ERROR1;364 }365 366 /* Fill the new client structure with data */367 new_client->data = (struct lm78_data *) (new_client + 1);368 new_client->addr = 0;369 strcpy(new_client->name,client_name);370 ((struct lm78_data *) (new_client->data))->type = type;371 new_client->isa_addr = address;372 if ((err = lm78_new_client((struct i2c_adapter *) adapter,373 (struct i2c_client *) new_client)))374 goto ERROR2; 375 376 /* Tell i2c-core a new client has arrived */377 if ((err = isa_attach_client(new_client)))378 goto ERROR3; 379 380 /* Register a new directory entry with module sensors */381 if ((err = sensors_register_entry((struct i2c_client *) new_client,382 type_name,383 lm78_dir_table_template)) < 0)384 goto ERROR4;385 ((struct lm78_data *) (new_client->data)) -> sysctl_id = err;386 err = 0;387 388 /* Initialize the LM78 chip */389 lm78_init_client((struct i2c_client *) new_client);390 continue;387 /* Fill in the remaining client fields and put it into the global list */ 388 strcpy(new_client->name,client_name); 389 data->type = kind; 390 391 for(i = 0; i < MAX_LM78_NR; i++) 392 if (! lm78_list[i]) 393 break; 394 if (i == MAX_LM78_NR) { 395 printk("lm78.o: No empty slots left, recompile and heighten " 396 "MAX_LM78_NR!\n"); 397 err = -ENOMEM; 398 goto ERROR2; 399 } 400 lm78_list[i] = new_client; 401 new_client->id = i; 402 data->valid = 0; 403 data->update_lock = MUTEX; 404 405 /* Tell the I2C layer a new client has arrived */ 406 if ((err = i2c_attach_client(new_client))) 407 goto ERROR3; 408 409 /* Register a new directory entry with module sensors */ 410 if ((i = sensors_register_entry((struct i2c_client *) new_client, 411 type_name, 412 lm78_dir_table_template)) < 0) { 413 err = i; 414 goto ERROR4; 415 } 416 data->sysctl_id = i; 417 418 /* Initialize the LM78 chip */ 419 lm78_init_client((struct i2c_client *) new_client); 420 return 0; 391 421 392 422 /* OK, this is not exactly good programming practice, usually. But it is … … 394 424 395 425 ERROR4: 396 isa_detach_client(new_client);426 i2c_detach_client(new_client); 397 427 ERROR3: 398 lm78_remove_client((struct i2c_client *) new_client); 428 for (i = 0; i < MAX_LM78_NR; i++) 429 if (new_client == lm78_list[i]) 430 lm78_list[i] = NULL; 399 431 ERROR2: 400 kfree(new_client); 432 if i2c_is_isa_adapter(adapter) 433 release_region(address,LM78_EXTENT); 401 434 ERROR1: 402 release_region(address, LM78_EXTENT);403 } 435 kfree(new_client); 436 ERROR0: 404 437 return err; 405 406 } 407 408 /* Deregister and remove a LM78 client */ 409 int lm78_detach_isa(struct isa_client *client) 438 } 439 440 int lm78_detach_client(struct i2c_client *client) 410 441 { 411 442 int err,i; 412 for (i = 0; i < MAX_LM78_NR; i++)413 if ((client == (struct isa_client *) (lm78_list[i])))414 break;415 if (i == MAX_LM78_NR) {416 printk("lm78.o: Client to detach not found.\n");417 return -ENOENT;418 }419 443 420 444 sensors_deregister_entry(((struct lm78_data *)(client->data))->sysctl_id); 421 445 422 if ((err = i sa_detach_client(client))) {446 if ((err = i2c_detach_client(client))) { 423 447 printk("lm78.o: Client deregistration failed, client not detached.\n"); 424 448 return err; 425 449 } 426 lm78_remove_client((struct i2c_client *) client); 427 release_region(client->isa_addr,LM78_EXTENT); 428 kfree(client); 429 return 0; 430 } 431 432 int lm78_detect_smbus(struct i2c_adapter *adapter) 433 { 434 int address,err; 435 struct i2c_client *new_client; 436 enum lm78_type type; 437 const char *type_name,*client_name; 438 439 /* OK, this is no detection. I know. It will do for now, though. */ 440 err = 0; 441 for (address = 0x20; (! err) && (address <= 0x2f); address ++) { 442 443 /* Later on, we will keep a list of registered addresses for each 444 adapter, and check whether they are used here */ 445 446 if (smbus_read_byte_data(adapter,address,LM78_REG_CONFIG) < 0) 447 continue; 448 449 /* Real detection code goes here */ 450 451 /* Determine exact type */ 452 err = smbus_read_byte_data(adapter,address,LM78_REG_CHIPID) & 0xfe; 453 if (err == 0x00) { 454 type = lm78; 455 type_name = "lm78"; 456 client_name = "LM78 chip"; 457 } else if (err == 0x40) { 458 type = lm78j; 459 type_name = "lm78-j"; 460 client_name = "LM78-J chip"; 461 } else if (err == 0xc0) { 462 type = lm79; 463 type_name = "lm79"; 464 client_name = "LM79 chip"; 465 } else if (err == 0x02) { 466 printk("lm78.o: Warning: Winbond W83781D detected (treated as a LM79)\n"); 467 type = lm79; 468 type_name = "lm79"; 469 client_name = "LM79 chip"; 470 } else { 471 #ifdef DEBUG 472 printk("lm78.o: warning: probed non-lm78 chip?!? (%x)\n",err); 473 #endif 474 continue; 475 } 476 477 478 /* Allocate space for a new client structure. To counter memory 479 ragmentation somewhat, we only do one kmalloc. */ 480 if (! (new_client = kmalloc(sizeof(struct i2c_client) + 481 sizeof(struct lm78_data), 482 GFP_KERNEL))) { 483 err = -ENOMEM; 484 continue; 485 } 486 487 /* Fill the new client structure with data */ 488 new_client->data = (struct lm78_data *) (new_client + 1); 489 new_client->addr = address; 490 strcpy(new_client->name,client_name); 491 ((struct lm78_data *) (new_client->data))->type = type; 492 if ((err = lm78_new_client(adapter,new_client))) 493 goto ERROR2; 494 495 /* Tell i2c-core a new client has arrived */ 496 if ((err = i2c_attach_client(new_client))) 497 goto ERROR3; 498 499 /* Register a new directory entry with module sensors */ 500 if ((err = sensors_register_entry(new_client,type_name, 501 lm78_dir_table_template)) < 0) 502 goto ERROR4; 503 ((struct lm78_data *) (new_client->data))->sysctl_id = err; 504 err = 0; 505 506 /* Initialize the LM78 chip */ 507 lm78_init_client(new_client); 508 continue; 509 510 /* OK, this is not exactly good programming practice, usually. But it is 511 very code-efficient in this case. */ 512 ERROR4: 513 i2c_detach_client(new_client); 514 ERROR3: 515 lm78_remove_client((struct i2c_client *) new_client); 516 ERROR2: 517 kfree(new_client); 518 } 519 return err; 520 } 521 522 int lm78_detach_smbus(struct i2c_client *client) 523 { 524 int err,i; 450 525 451 for (i = 0; i < MAX_LM78_NR; i++) 526 452 if (client == lm78_list[i]) … … 530 456 return -ENOENT; 531 457 } 532 533 sensors_deregister_entry(((struct lm78_data *)(client->data))->sysctl_id); 534 535 if ((err = i2c_detach_client(client))) { 536 printk("lm78.o: Client deregistration failed, client not detached.\n"); 537 return err; 538 } 539 lm78_remove_client(client); 458 lm78_list[i] = NULL; 459 460 if i2c_is_isa_client(client) 461 release_region(((struct isa_client *)client)->isa_addr,LM78_EXTENT); 540 462 kfree(client); 463 541 464 return 0; 542 }543 544 545 /* Find a free slot, and initialize most of the fields */546 int lm78_new_client(struct i2c_adapter *adapter,547 struct i2c_client *new_client)548 {549 int i;550 struct lm78_data *data;551 552 /* First, seek out an empty slot */553 for(i = 0; i < MAX_LM78_NR; i++)554 if (! lm78_list[i])555 break;556 if (i == MAX_LM78_NR) {557 printk("lm78.o: No empty slots left, recompile and heighten "558 "MAX_LM78_NR!\n");559 return -ENOMEM;560 }561 562 lm78_list[i] = new_client;563 new_client->id = i;564 new_client->adapter = adapter;565 new_client->driver = &lm78_driver;566 data = new_client->data;567 data->valid = 0;568 data->lock = MUTEX;569 data->update_lock = MUTEX;570 return 0;571 }572 573 /* Inverse of lm78_new_client */574 void lm78_remove_client(struct i2c_client *client)575 {576 int i;577 for (i = 0; i < MAX_LM78_NR; i++)578 if (client == lm78_list[i])579 lm78_list[i] = NULL;580 465 } 581 466 … … 604 489 605 490 /* The SMBus locks itself, but ISA access must be locked explicitely! 491 We don't want to lock the whole ISA bus, so we lock each client 492 separately. 606 493 We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks, 607 494 would slow down the LM78 access and should not be necessary. … … 612 499 int res; 613 500 if (i2c_is_isa_client(client)) { 614 down( (struct semaphore *) (client->data));501 down(& (((struct lm78_data *) (client->data)) -> lock)); 615 502 outb_p(reg,(((struct isa_client *) client)->isa_addr) + 616 503 LM78_ADDR_REG_OFFSET); 617 504 res = inb_p((((struct isa_client *) client)->isa_addr) + 618 505 LM78_DATA_REG_OFFSET); 619 up( (struct semaphore *) (client->data));506 up( & (((struct lm78_data *) (client->data)) -> lock)); 620 507 return res; 621 508 } else … … 624 511 625 512 /* The SMBus locks itself, but ISA access muse be locked explicitely! 513 We don't want to lock the whole ISA bus, so we lock each client 514 separately. 626 515 We ignore the LM78 BUSY flag at this moment - it could lead to deadlocks, 627 516 would slow down the LM78 access and should not be necessary. … … 631 520 { 632 521 if (i2c_is_isa_client(client)) { 633 down( (struct semaphore *) (client->data));522 down(&(((struct lm78_data *) (client->data)) -> lock)); 634 523 outb_p(reg,((struct isa_client *) client)->isa_addr + LM78_ADDR_REG_OFFSET); 635 524 outb_p(value,((struct isa_client *) client)->isa_addr + LM78_DATA_REG_OFFSET); 636 up( (struct semaphore *) (client->data));525 up(&(((struct lm78_data *) (client->data)) -> lock)); 637 526 return 0; 638 527 } else -
lm-sensors/trunk/kernel/include/sensors.h
r324 r325 161 161 #define SENSORS_MAX_OPTS 48 162 162 163 typedef void sensors_found_addr_proc (struct i2c_adapter *adapter, 164 int addr, int kind); 163 /* Default fill of many variables */ 164 #define SENSORS_DEFAULTS {SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 165 SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 166 SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 167 SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 168 SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 169 SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 170 SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 171 SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 172 SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 173 SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 174 SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 175 SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 176 SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 177 SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 178 SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END, \ 179 SENSORS_I2C_END, SENSORS_I2C_END, SENSORS_I2C_END} 180 181 #define SENSORS_MODPARM_AUX1(x) "1-" #x "h" 182 #define SENSORS_MODPARM_AUX(x) SENSORS_MODPARM_AUX1(x) 183 #define SENSORS_MODPARM SENSORS_MODPARM_AUX(SENSORS_MAX_OPTS) 184 185 #define SENSORS_CONCAT(x,y) x ## y 186 #define MODULE_PARM1(x,y) MODULE_PARM(x,y) 187 188 /* This defines several insmod variables, and the addr_data structure */ 189 #define SENSORS_INSMOD \ 190 MODULE_PARM(probe,SENSORS_MODPARM); \ 191 static unsigned short probe[SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 192 MODULE_PARM(probe_range,SENSORS_MODPARM); \ 193 static unsigned short probe_range[SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 194 MODULE_PARM(ignore,SENSORS_MODPARM); \ 195 static unsigned short ignore[SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 196 MODULE_PARM(ignore_range,SENSORS_MODPARM); \ 197 static unsigned short ignore_range [SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 198 static struct sensors_address_data addr_data = \ 199 {normal_i2c, normal_i2c_range, \ 200 normal_isa, normal_isa_range, \ 201 probe, probe_range, \ 202 ignore, ignore_range, \ 203 forces} 204 205 /* The following functions assume the existence of an enum with the chip 206 names as elements. The first element of the enum should be any_chip */ 207 208 #define SENSORS_INSMOD_0 \ 209 enum chips { any_chip }; \ 210 MODULE_PARM(force,SENSORS_MODPARM); \ 211 static unsigned short force[SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 212 static struct sensors_force_data forces[] = {{force,any_chip},{NULL}}; \ 213 SENSORS_INSMOD 214 215 #define SENSORS_INSMOD_1(chip1) \ 216 enum chips { any_chip, chip1 }; \ 217 MODULE_PARM(force,SENSORS_MODPARM); \ 218 static unsigned short force[SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 219 MODULE_PARM1(SENSORS_CONCAT(force_,chip1),SENSORS_MODPARM); \ 220 static unsigned short force_ ## chip1 [SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 221 static struct sensors_force_data forces[] = {{force,any_chip},\ 222 {force_ ## chip1,chip1}, \ 223 {NULL}}; \ 224 SENSORS_INSMOD 225 226 #define SENSORS_INSMOD_2(chip1,chip2) \ 227 enum chips { any_chip, chip1, chip2 }; \ 228 MODULE_PARM(force,SENSORS_MODPARM); \ 229 static unsigned short force[SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 230 MODULE_PARM1(SENSORS_CONCAT(force_,chip1),SENSORS_MODPARM); \ 231 static unsigned short force_ ## chip1 [SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 232 MODULE_PARM1(SENSORS_CONCAT(force_,chip2),SENSORS_MODPARM); \ 233 static unsigned short force_ ## chip2 [SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 234 static struct sensors_force_data forces[] = {{force,any_chip}, \ 235 {force_ ## chip1,chip2}, \ 236 {force_ ## chip2,nr2}, \ 237 {NULL}}; \ 238 SENSORS_INSMOD 239 240 #define SENSORS_INSMOD_3(chip1,chip2,chip3) \ 241 enum chips { any_chip, chip1, chip2, chip3 }; \ 242 MODULE_PARM(force,SENSORS_MODPARM); \ 243 static unsigned short force[SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 244 MODULE_PARM1(SENSORS_CONCAT(force_,chip1),SENSORS_MODPARM); \ 245 static unsigned short force_ ## chip1 [SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 246 MODULE_PARM1(SENSORS_CONCAT(force_,chip2),SENSORS_MODPARM); \ 247 static unsigned short force_ ## chip2 [SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 248 MODULE_PARM1(SENSORS_CONCAT(force_,chip3),SENSORS_MODPARM); \ 249 static unsigned short force_ ## chip3 [SENSORS_MAX_OPTS] = SENSORS_DEFAULTS; \ 250 static struct sensors_force_data forces[] = {{force,any_chip}, \ 251 {force_ ## chip1,chip1}, \ 252 {force_ ## chip2,chip2}, \ 253 {force_ ## chip3,chip3}, \ 254 {NULL}}; \ 255 SENSORS_INSMOD 256 257 typedef int sensors_found_addr_proc (struct i2c_adapter *adapter, 258 int addr, int kind); 165 259 166 260 /* Detect function. It itterates over all possible addresses itself. For … … 168 262 to the SMBus (unless a 'force' matched); for ISA detections, this is not 169 263 done. */ 170 extern voidsensors_detect(struct i2c_adapter *adapter,171 struct sensors_address_data *address_data,172 sensors_found_addr_proc *found_proc);264 extern int sensors_detect(struct i2c_adapter *adapter, 265 struct sensors_address_data *address_data, 266 sensors_found_addr_proc *found_proc); 173 267 174 268 #endif /* def __KERNEL__ */ -
lm-sensors/trunk/kernel/sensors.c
r324 r325 583 583 584 584 /* Very inefficient for ISA detects! */ 585 voidsensors_detect(struct i2c_adapter *adapter,586 struct sensors_address_data *address_data,587 sensors_found_addr_proc *found_proc)588 { 589 int addr,i,found,j ;585 int sensors_detect(struct i2c_adapter *adapter, 586 struct sensors_address_data *address_data, 587 sensors_found_addr_proc *found_proc) 588 { 589 int addr,i,found,j,err; 590 590 struct sensors_force_data *this_force; 591 unsigned int end_marker = i2c_is_isa_adapter(adapter)?SENSORS_ISA_END:592 SENSORS_I2C_END;593 591 int adapter_id = i2c_is_isa_adapter(adapter)?SENSORS_ISA_BUS: 594 592 i2c_adapter_id(adapter); 595 593 596 for (addr = 0x00; addr <= i2c_is_isa_adapter(adapter)?0xfff:0x7f; addr ++) { 594 printk("IGNORE: %04hx %04hx %04hx %04hx %04hx %04hx\n",address_data->ignore[0],address_data->ignore[1],address_data->ignore[2],address_data->ignore[3],address_data->ignore[4],address_data->ignore[5]); 595 for (addr = 0x00; 596 addr <= (i2c_is_isa_adapter(adapter)?0xffff:0x7f); 597 addr ++) { 598 597 599 /* If it is in one of the force entries, we don't do any detection 598 600 at all */ … … 601 603 !found && (this_force = address_data->forces+i, this_force->force); 602 604 i++) { 603 for (j = 0; !found && (this_force->force[j] != end_marker) ; i += 2) { 605 for (j = 0; 606 !found && (this_force->force[j] != SENSORS_I2C_END) ; 607 i += 2) { 604 608 if (((adapter_id == this_force->force[j]) || 605 609 (this_force->force[j] == SENSORS_ANY_I2C_BUS)) && 606 610 (addr == this_force->force[j+1])) { 607 found_proc(adapter,addr,this_force->kind); 611 if ((err = found_proc(adapter,addr,this_force->kind))) 612 return err; 608 613 found = 1; 609 614 } 610 615 } 611 616 } 612 if (found) 617 if (found) 613 618 continue; 614 619 … … 616 621 right now */ 617 622 for (i = 0; 618 !found && (address_data->ignore[i] != end_marker);623 !found && (address_data->ignore[i] != SENSORS_I2C_END); 619 624 i += 2) { 620 625 if (((adapter_id == address_data->ignore[i]) || … … 625 630 } 626 631 for (i = 0; 627 !found && (address_data->ignore_range[i] != end_marker);632 !found && (address_data->ignore_range[i] != SENSORS_I2C_END); 628 633 i += 3) { 629 634 if (((adapter_id == address_data->ignore_range[i]) || … … 633 638 found = 1; 634 639 } 635 if (found) 640 if (found) 636 641 continue; 637 642 … … 646 651 } 647 652 for (i = 0; 648 !found && (address_data->normal_isa_range[i] != SENSORS_I 2C_END);653 !found && (address_data->normal_isa_range[i] != SENSORS_ISA_END); 649 654 i += 3) { 650 655 if ((addr >= address_data->normal_isa_range[i]) && … … 690 695 } 691 696 } 692 if (!found) 697 if (!found) 693 698 continue; 694 699 695 700 /* OK, so we really should examine this address. First check 696 701 whether there is some client here at all! */ 697 if ( !i2c_is_isa_adapter(adapter) ||702 if (i2c_is_isa_adapter(adapter) || 698 703 (smbus_read_byte(adapter,addr) >= 0)) 699 found_proc(adapter,addr,0); 700 } 704 if ((err = found_proc(adapter,addr,-1))) 705 return err; 706 } 707 return 0; 701 708 } 702 709 -
lm-sensors/trunk/prog/detect/sensors-detect
r323 r325 1044 1044 return if inb ($addr + 2) != $val or inb ($addr + 3) != $val or 1045 1045 inb ($addr + 7) != $val; 1046 1047 $val = inb($addr + 5) & 0x7f; 1048 outb($addr+5,~ $val); 1049 if ((inb ($addr+5) & 0x7f) != (~ $val & 0x7f)) { 1050 outb($addr+5,$val); 1051 return; 1052 } 1046 1053 my $readproc = sub { isa_read_byte $addr + 5, $addr + 6, @_ }; 1047 1054 return unless (&$readproc(0x40) & 0x80) == 0x00; … … 1184 1191 return if inb ($addr + 2) != $val or inb ($addr + 3) != $val or 1185 1192 inb ($addr + 7) != $val; 1193 1194 $val = inb($addr + 5) & 0x7f; 1195 outb($addr+5,~ $val); 1196 if ((inb ($addr+5) & 0x7f) != (~ $val & 0x7f)) { 1197 outb($addr+5,$val); 1198 return; 1199 } 1200 1186 1201 my $read_proc = sub { isa_read_byte $addr + 5, $addr + 6, @_ }; 1187 1202 $reg1 = &$read_proc(0x4e);
