Changeset 27
- Timestamp:
- 12/03/98 19:20:59 (14 years ago)
- Location:
- lm-sensors/trunk
- Files:
-
- 4 modified
-
kernel/chips/lm78.c (modified) (21 diffs)
-
kernel/include/sensors.h (modified) (2 diffs)
-
src/lm78.c (modified) (21 diffs)
-
src/sensors.h (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/kernel/chips/lm78.c
r20 r27 61 61 62 62 #define LM78_REG_CONFIG 0x40 63 #define LM78_REG_CHIPID 0x49 63 64 64 65 … … 66 67 static int lm78_in_conv[7] = {10000, 10000, 10000, 16892, 38000, 67 68 -34768, -15050 }; 68 #define IN_TO_REG(val,nr) ((((val) * 100000 / lm78_in_conv[nr]) + 8) / 16) 69 #define IN_TO_REG(val,nr) (((((val) * 100000 / lm78_in_conv[nr]) + 8) / 16) \ 70 & 0xff) 69 71 #define IN_FROM_REG(val,nr) (((val) * 16 * lm78_in_conv[nr]) / 100000) 70 72 71 #define FAN_TO_REG(val) ((( val)==0)?255:((1350000+(val))/((val)*2)))73 #define FAN_TO_REG(val) ((((val)==0)?255:((1350000+(val))/((val)*2))) & 0xff) 72 74 #define FAN_FROM_REG(val) (((val)==0)?-1:\ 73 75 ((val)==255)?0:(1350000 + (val))/((val)*2)) 74 76 75 #define TEMP_TO_REG(val) (( val)<0?(val)&0xff:(val))76 #define TEMP_FROM_REG(val) (( val)>0x80?(val)-0x100:(val));77 78 #define VID_FROM_REG(val) ((val) == 0x0f?0:350-(val)*10)79 77 #define TEMP_TO_REG(val) (((val)<0?(val/10)&0xff:(val/10)) & 0xff) 78 #define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*10) 79 80 #define VID_FROM_REG(val) ((val)==0x1f?0:(val)>=0x10?510-(val)*10:\ 81 (val)>=0x06?0:205-(val)*5) 80 82 #define ALARMS_FROM_REG(val) (val) 81 83 82 84 #define DIV_FROM_REG(val) (1 >> (val)) 83 #define DIV_TO_REG(val) ((val)==8?3:(val)==4?2:(val)==1? 1:2)85 #define DIV_TO_REG(val) ((val)==8?3:(val)==4?2:(val)==1?0:1) 84 86 85 87 /* Initial limits */ 86 #define LM78_INIT_IN_0 28087 #define LM78_INIT_IN_1 28088 #define LM78_INIT_IN_0 (vid==350?280:vid) 89 #define LM78_INIT_IN_1 (vid==350?280:vid) 88 90 #define LM78_INIT_IN_2 330 89 91 #define LM78_INIT_IN_3 500 … … 127 129 #define LM78_INIT_FAN_MIN_3 3000 128 130 129 #define LM78_INIT_TEMP_OVER 60 130 #define LM78_INIT_TEMP_HYST 50 131 #define LM78_INIT_TEMP_OVER 600 132 #define LM78_INIT_TEMP_HYST 500 131 133 132 134 #ifdef MODULE … … 150 152 some corners. */ 151 153 154 /* Types of chips supported */ 155 enum lm78_type { lm78, lm78j, lm79 }; 156 152 157 /* For each registered LM78, we need to keep some data in memory. That 153 158 data is pointed to by lm78_list[NR]->data. The structure itself is … … 157 162 struct semaphore lock; 158 163 int sysctl_id; 164 enum lm78_type type; 159 165 160 166 struct semaphore update_lock; … … 297 303 int address,err; 298 304 struct isa_client *new_client; 305 enum lm78_type type; 306 const char *type_name; 307 const char *client_name; 299 308 300 309 /* OK, this is no detection. I know. It will do for now, though. */ … … 303 312 for (address = 0x290; (! err) && (address <= 0x290); address += 0x08) { 304 313 if (check_region(address, LM78_EXTENT)) 314 continue; 315 316 /* Awful, but true: unused port addresses should return 0xff */ 317 if ((inb_p(address + 1) != 0xff) || (inb_p(address + 2) != 0xff) || 318 (inb_p(address + 3) != 0xff) || (inb_p(address + 7) != 0xff)) 305 319 continue; 306 320 … … 312 326 313 327 /* Real detection code goes here */ 314 315 request_region(address, LM78_EXTENT, "lm78"); 328 329 /* Determine exact type */ 330 outb_p(LM78_REG_CHIPID,address + LM78_ADDR_REG_OFFSET); 331 err = inb_p(address + LM78_DATA_REG_OFFSET); 332 if (err == 0x00) { 333 type = lm78; 334 type_name = "lm78"; 335 client_name = "LM78 chip"; 336 } else if (err == 0x40) { 337 type = lm78j; 338 type_name = "lm78-j"; 339 client_name = "LM78-J chip"; 340 } else if (err == 0x80) { 341 type = lm79; 342 type_name = "lm79"; 343 client_name = "LM79 chip"; 344 } 345 else 346 continue; 347 348 349 request_region(address, LM78_EXTENT, type_name); 316 350 317 351 /* Allocate space for a new client structure */ … … 327 361 new_client->data = (struct lm78_data *) (new_client + 1); 328 362 new_client->addr = 0; 363 strcpy(new_client->name,client_name); 364 ((struct lm78_data *) (new_client->data))->type = type; 329 365 new_client->isa_addr = address; 330 366 if ((err = lm78_new_client((struct i2c_adapter *) adapter, … … 337 373 338 374 /* Register a new directory entry with module sensors */ 339 if ((err = sensors_register_entry((struct i2c_client *) new_client,"lm78", 375 if ((err = sensors_register_entry((struct i2c_client *) new_client, 376 type_name, 340 377 lm78_dir_table_template)) < 0) 341 378 goto ERROR4; … … 390 427 int address,err; 391 428 struct i2c_client *new_client; 429 enum lm78_type type; 430 const char *type_name,*client_name; 392 431 393 432 /* OK, this is no detection. I know. It will do for now, though. */ … … 402 441 403 442 /* Real detection code goes here */ 443 444 /* Determine exact type */ 445 err = smbus_read_byte_data(adapter,address,LM78_REG_CHIPID); 446 if (err == 0x00) { 447 type = lm78; 448 type_name = "lm78"; 449 client_name = "LM78 chip"; 450 } else if (err == 0x40) { 451 type = lm78j; 452 type_name = "lm78-j"; 453 client_name = "LM78-J chip"; 454 } else if (err == 0x80) { 455 type = lm79; 456 type_name = "lm79"; 457 client_name = "LM79 chip"; 458 } else 459 continue; 460 404 461 405 462 /* Allocate space for a new client structure */ … … 414 471 new_client->data = (struct lm78_data *) (new_client + 1); 415 472 new_client->addr = address; 473 strcpy(new_client->name,client_name); 474 ((struct lm78_data *) (new_client->data))->type = type; 416 475 if ((err = lm78_new_client(adapter,new_client))) 417 476 goto ERROR2; … … 422 481 423 482 /* Register a new directory entry with module sensors */ 424 if ((err = sensors_register_entry(new_client, "lm78",483 if ((err = sensors_register_entry(new_client,type_name, 425 484 lm78_dir_table_template)) < 0) 426 485 goto ERROR4; … … 484 543 485 544 lm78_list[i] = new_client; 486 strcpy(new_client->name,"LM78 chip");487 545 new_client->id = i; 488 546 new_client->adapter = adapter; … … 561 619 void lm78_init_client(struct i2c_client *client) 562 620 { 621 int vid; 622 563 623 /* Reset all except Watchdog values and last conversion values 564 624 This sets fan-divs to 2, among others */ 565 625 lm78_write_value(client,LM78_REG_CONFIG,0x80); 626 627 vid = lm78_read_value(client,LM78_REG_VID_FANDIV) & 0x0f; 628 if (((struct lm78_data *) (client->data))->type == lm79) 629 vid |= (lm78_read_value(client,LM78_REG_CHIPID) & 0x01) >> 4; 630 else 631 vid |= 0x10; 632 vid = VID_FROM_REG(vid); 566 633 567 634 lm78_write_value(client,LM78_REG_IN_MIN(0),IN_TO_REG(LM78_INIT_IN_MIN_0,0)); … … 618 685 i = lm78_read_value(client,LM78_REG_VID_FANDIV); 619 686 data->vid = i & 0x0f; 687 if (data->type == lm79) 688 data->vid |= (lm78_read_value(client,LM78_REG_CHIPID) & 0x01) >> 4; 689 else 690 data->vid |= 0x10; 620 691 data->fan_div[0] = (i >> 4) & 0x03; 621 692 data->fan_div[1] = i >> 6; … … 656 727 case LM78_SYSCTL_TEMP: 657 728 nrels=3; 729 mag=1; 730 break; 731 case LM78_SYSCTL_FAN_DIV: 732 nrels=3; 658 733 mag=0; 659 734 break; 660 735 case LM78_SYSCTL_FAN1: case LM78_SYSCTL_FAN2: case LM78_SYSCTL_FAN3: 661 case LM78_SYSCTL_FAN_DIV:662 736 nrels=2; 663 737 mag=0; … … 742 816 case LM78_SYSCTL_IN3: case LM78_SYSCTL_IN4: case LM78_SYSCTL_IN5: 743 817 case LM78_SYSCTL_IN6: case LM78_SYSCTL_TEMP: 818 case LM78_SYSCTL_FAN_DIV: 744 819 nrels=3; 745 820 break; 746 821 case LM78_SYSCTL_FAN1: case LM78_SYSCTL_FAN2: case LM78_SYSCTL_FAN3: 747 case LM78_SYSCTL_FAN_DIV:748 822 nrels=2; 749 823 break; … … 859 933 } 860 934 if (nrels >= 2) { 861 data->temp_hyst = TEMP_TO_REG(results[ 0]);935 data->temp_hyst = TEMP_TO_REG(results[1]); 862 936 lm78_write_value(client,LM78_REG_TEMP_HYST,data->temp_hyst); 863 937 } … … 889 963 results[0] = DIV_FROM_REG(data->fan_div[0]); 890 964 results[1] = DIV_FROM_REG(data->fan_div[1]); 965 results[2] = 2; 891 966 } 892 967 -
lm-sensors/trunk/kernel/include/sensors.h
r19 r27 47 47 #endif /* def DEV_HWMON */ 48 48 49 #define LM78_SYSCTL_IN0 1000 49 #define LM78_SYSCTL_IN0 1000 /* Volts * 100 */ 50 50 #define LM78_SYSCTL_IN1 1001 51 51 #define LM78_SYSCTL_IN2 1002 … … 54 54 #define LM78_SYSCTL_IN5 1005 55 55 #define LM78_SYSCTL_IN6 1006 56 #define LM78_SYSCTL_FAN1 1101 56 #define LM78_SYSCTL_FAN1 1101 /* Rotations/min */ 57 57 #define LM78_SYSCTL_FAN2 1102 58 58 #define LM78_SYSCTL_FAN3 1103 59 #define LM78_SYSCTL_TEMP 1200 60 #define LM78_SYSCTL_VID 1300 61 #define LM78_SYSCTL_FAN_DIV 2000 62 #define LM78_SYSCTL_ALARMS 2001 59 #define LM78_SYSCTL_TEMP 1200 /* Degrees Celcius * 10 */ 60 #define LM78_SYSCTL_VID 1300 /* Volts * 100 */ 61 #define LM78_SYSCTL_FAN_DIV 2000 /* 1, 2, 4 or 8 */ 62 #define LM78_SYSCTL_ALARMS 2001 /* bitvector */ 63 63 64 64 #endif /* def SENSORS_SENSORS_H */ -
lm-sensors/trunk/src/lm78.c
r20 r27 61 61 62 62 #define LM78_REG_CONFIG 0x40 63 #define LM78_REG_CHIPID 0x49 63 64 64 65 … … 66 67 static int lm78_in_conv[7] = {10000, 10000, 10000, 16892, 38000, 67 68 -34768, -15050 }; 68 #define IN_TO_REG(val,nr) ((((val) * 100000 / lm78_in_conv[nr]) + 8) / 16) 69 #define IN_TO_REG(val,nr) (((((val) * 100000 / lm78_in_conv[nr]) + 8) / 16) \ 70 & 0xff) 69 71 #define IN_FROM_REG(val,nr) (((val) * 16 * lm78_in_conv[nr]) / 100000) 70 72 71 #define FAN_TO_REG(val) ((( val)==0)?255:((1350000+(val))/((val)*2)))73 #define FAN_TO_REG(val) ((((val)==0)?255:((1350000+(val))/((val)*2))) & 0xff) 72 74 #define FAN_FROM_REG(val) (((val)==0)?-1:\ 73 75 ((val)==255)?0:(1350000 + (val))/((val)*2)) 74 76 75 #define TEMP_TO_REG(val) (( val)<0?(val)&0xff:(val))76 #define TEMP_FROM_REG(val) (( val)>0x80?(val)-0x100:(val));77 78 #define VID_FROM_REG(val) ((val) == 0x0f?0:350-(val)*10)79 77 #define TEMP_TO_REG(val) (((val)<0?(val/10)&0xff:(val/10)) & 0xff) 78 #define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*10) 79 80 #define VID_FROM_REG(val) ((val)==0x1f?0:(val)>=0x10?510-(val)*10:\ 81 (val)>=0x06?0:205-(val)*5) 80 82 #define ALARMS_FROM_REG(val) (val) 81 83 82 84 #define DIV_FROM_REG(val) (1 >> (val)) 83 #define DIV_TO_REG(val) ((val)==8?3:(val)==4?2:(val)==1? 1:2)85 #define DIV_TO_REG(val) ((val)==8?3:(val)==4?2:(val)==1?0:1) 84 86 85 87 /* Initial limits */ 86 #define LM78_INIT_IN_0 28087 #define LM78_INIT_IN_1 28088 #define LM78_INIT_IN_0 (vid==350?280:vid) 89 #define LM78_INIT_IN_1 (vid==350?280:vid) 88 90 #define LM78_INIT_IN_2 330 89 91 #define LM78_INIT_IN_3 500 … … 127 129 #define LM78_INIT_FAN_MIN_3 3000 128 130 129 #define LM78_INIT_TEMP_OVER 60 130 #define LM78_INIT_TEMP_HYST 50 131 #define LM78_INIT_TEMP_OVER 600 132 #define LM78_INIT_TEMP_HYST 500 131 133 132 134 #ifdef MODULE … … 150 152 some corners. */ 151 153 154 /* Types of chips supported */ 155 enum lm78_type { lm78, lm78j, lm79 }; 156 152 157 /* For each registered LM78, we need to keep some data in memory. That 153 158 data is pointed to by lm78_list[NR]->data. The structure itself is … … 157 162 struct semaphore lock; 158 163 int sysctl_id; 164 enum lm78_type type; 159 165 160 166 struct semaphore update_lock; … … 297 303 int address,err; 298 304 struct isa_client *new_client; 305 enum lm78_type type; 306 const char *type_name; 307 const char *client_name; 299 308 300 309 /* OK, this is no detection. I know. It will do for now, though. */ … … 303 312 for (address = 0x290; (! err) && (address <= 0x290); address += 0x08) { 304 313 if (check_region(address, LM78_EXTENT)) 314 continue; 315 316 /* Awful, but true: unused port addresses should return 0xff */ 317 if ((inb_p(address + 1) != 0xff) || (inb_p(address + 2) != 0xff) || 318 (inb_p(address + 3) != 0xff) || (inb_p(address + 7) != 0xff)) 305 319 continue; 306 320 … … 312 326 313 327 /* Real detection code goes here */ 314 315 request_region(address, LM78_EXTENT, "lm78"); 328 329 /* Determine exact type */ 330 outb_p(LM78_REG_CHIPID,address + LM78_ADDR_REG_OFFSET); 331 err = inb_p(address + LM78_DATA_REG_OFFSET); 332 if (err == 0x00) { 333 type = lm78; 334 type_name = "lm78"; 335 client_name = "LM78 chip"; 336 } else if (err == 0x40) { 337 type = lm78j; 338 type_name = "lm78-j"; 339 client_name = "LM78-J chip"; 340 } else if (err == 0x80) { 341 type = lm79; 342 type_name = "lm79"; 343 client_name = "LM79 chip"; 344 } 345 else 346 continue; 347 348 349 request_region(address, LM78_EXTENT, type_name); 316 350 317 351 /* Allocate space for a new client structure */ … … 327 361 new_client->data = (struct lm78_data *) (new_client + 1); 328 362 new_client->addr = 0; 363 strcpy(new_client->name,client_name); 364 ((struct lm78_data *) (new_client->data))->type = type; 329 365 new_client->isa_addr = address; 330 366 if ((err = lm78_new_client((struct i2c_adapter *) adapter, … … 337 373 338 374 /* Register a new directory entry with module sensors */ 339 if ((err = sensors_register_entry((struct i2c_client *) new_client,"lm78", 375 if ((err = sensors_register_entry((struct i2c_client *) new_client, 376 type_name, 340 377 lm78_dir_table_template)) < 0) 341 378 goto ERROR4; … … 390 427 int address,err; 391 428 struct i2c_client *new_client; 429 enum lm78_type type; 430 const char *type_name,*client_name; 392 431 393 432 /* OK, this is no detection. I know. It will do for now, though. */ … … 402 441 403 442 /* Real detection code goes here */ 443 444 /* Determine exact type */ 445 err = smbus_read_byte_data(adapter,address,LM78_REG_CHIPID); 446 if (err == 0x00) { 447 type = lm78; 448 type_name = "lm78"; 449 client_name = "LM78 chip"; 450 } else if (err == 0x40) { 451 type = lm78j; 452 type_name = "lm78-j"; 453 client_name = "LM78-J chip"; 454 } else if (err == 0x80) { 455 type = lm79; 456 type_name = "lm79"; 457 client_name = "LM79 chip"; 458 } else 459 continue; 460 404 461 405 462 /* Allocate space for a new client structure */ … … 414 471 new_client->data = (struct lm78_data *) (new_client + 1); 415 472 new_client->addr = address; 473 strcpy(new_client->name,client_name); 474 ((struct lm78_data *) (new_client->data))->type = type; 416 475 if ((err = lm78_new_client(adapter,new_client))) 417 476 goto ERROR2; … … 422 481 423 482 /* Register a new directory entry with module sensors */ 424 if ((err = sensors_register_entry(new_client, "lm78",483 if ((err = sensors_register_entry(new_client,type_name, 425 484 lm78_dir_table_template)) < 0) 426 485 goto ERROR4; … … 484 543 485 544 lm78_list[i] = new_client; 486 strcpy(new_client->name,"LM78 chip");487 545 new_client->id = i; 488 546 new_client->adapter = adapter; … … 561 619 void lm78_init_client(struct i2c_client *client) 562 620 { 621 int vid; 622 563 623 /* Reset all except Watchdog values and last conversion values 564 624 This sets fan-divs to 2, among others */ 565 625 lm78_write_value(client,LM78_REG_CONFIG,0x80); 626 627 vid = lm78_read_value(client,LM78_REG_VID_FANDIV) & 0x0f; 628 if (((struct lm78_data *) (client->data))->type == lm79) 629 vid |= (lm78_read_value(client,LM78_REG_CHIPID) & 0x01) >> 4; 630 else 631 vid |= 0x10; 632 vid = VID_FROM_REG(vid); 566 633 567 634 lm78_write_value(client,LM78_REG_IN_MIN(0),IN_TO_REG(LM78_INIT_IN_MIN_0,0)); … … 618 685 i = lm78_read_value(client,LM78_REG_VID_FANDIV); 619 686 data->vid = i & 0x0f; 687 if (data->type == lm79) 688 data->vid |= (lm78_read_value(client,LM78_REG_CHIPID) & 0x01) >> 4; 689 else 690 data->vid |= 0x10; 620 691 data->fan_div[0] = (i >> 4) & 0x03; 621 692 data->fan_div[1] = i >> 6; … … 656 727 case LM78_SYSCTL_TEMP: 657 728 nrels=3; 729 mag=1; 730 break; 731 case LM78_SYSCTL_FAN_DIV: 732 nrels=3; 658 733 mag=0; 659 734 break; 660 735 case LM78_SYSCTL_FAN1: case LM78_SYSCTL_FAN2: case LM78_SYSCTL_FAN3: 661 case LM78_SYSCTL_FAN_DIV:662 736 nrels=2; 663 737 mag=0; … … 742 816 case LM78_SYSCTL_IN3: case LM78_SYSCTL_IN4: case LM78_SYSCTL_IN5: 743 817 case LM78_SYSCTL_IN6: case LM78_SYSCTL_TEMP: 818 case LM78_SYSCTL_FAN_DIV: 744 819 nrels=3; 745 820 break; 746 821 case LM78_SYSCTL_FAN1: case LM78_SYSCTL_FAN2: case LM78_SYSCTL_FAN3: 747 case LM78_SYSCTL_FAN_DIV:748 822 nrels=2; 749 823 break; … … 859 933 } 860 934 if (nrels >= 2) { 861 data->temp_hyst = TEMP_TO_REG(results[ 0]);935 data->temp_hyst = TEMP_TO_REG(results[1]); 862 936 lm78_write_value(client,LM78_REG_TEMP_HYST,data->temp_hyst); 863 937 } … … 889 963 results[0] = DIV_FROM_REG(data->fan_div[0]); 890 964 results[1] = DIV_FROM_REG(data->fan_div[1]); 965 results[2] = 2; 891 966 } 892 967 -
lm-sensors/trunk/src/sensors.h
r19 r27 47 47 #endif /* def DEV_HWMON */ 48 48 49 #define LM78_SYSCTL_IN0 1000 49 #define LM78_SYSCTL_IN0 1000 /* Volts * 100 */ 50 50 #define LM78_SYSCTL_IN1 1001 51 51 #define LM78_SYSCTL_IN2 1002 … … 54 54 #define LM78_SYSCTL_IN5 1005 55 55 #define LM78_SYSCTL_IN6 1006 56 #define LM78_SYSCTL_FAN1 1101 56 #define LM78_SYSCTL_FAN1 1101 /* Rotations/min */ 57 57 #define LM78_SYSCTL_FAN2 1102 58 58 #define LM78_SYSCTL_FAN3 1103 59 #define LM78_SYSCTL_TEMP 1200 60 #define LM78_SYSCTL_VID 1300 61 #define LM78_SYSCTL_FAN_DIV 2000 62 #define LM78_SYSCTL_ALARMS 2001 59 #define LM78_SYSCTL_TEMP 1200 /* Degrees Celcius * 10 */ 60 #define LM78_SYSCTL_VID 1300 /* Volts * 100 */ 61 #define LM78_SYSCTL_FAN_DIV 2000 /* 1, 2, 4 or 8 */ 62 #define LM78_SYSCTL_ALARMS 2001 /* bitvector */ 63 63 64 64 #endif /* def SENSORS_SENSORS_H */
