Changeset 341
- Timestamp:
- 03/24/99 22:28:22 (10 years ago)
- Files:
-
- lm-sensors/trunk/kernel/chips/lm78.c (modified) (2 diffs)
- lm-sensors/trunk/kernel/chips/w83781d.c (modified) (35 diffs)
- lm-sensors/trunk/prog/detect/sensors-detect (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
lm-sensors/trunk/kernel/chips/lm78.c
r338 r341 42 42 /* Insmod parameters */ 43 43 SENSORS_INSMOD_3(lm78,lm78j,lm79); 44 44 45 /* Many LM78 constants specified below */ 45 46 … … 323 324 /* We need the timeouts for at least some LM78-like chips. But only 324 325 if we read 'undefined' registers. */ 325 if (check_region(address,LM78_EXTENT))326 goto ERROR0;327 326 i = inb_p(address + 1); 328 327 if (inb_p(address + 2) != i) lm-sensors/trunk/kernel/chips/w83781d.c
r339 r341 49 49 #undef W83781D_RT 50 50 51 /* Addresses to scan */ 52 static unsigned short normal_i2c[] = {SENSORS_I2C_END}; 53 static unsigned short normal_i2c_range[] = {0x20,0x2f,SENSORS_I2C_END}; 54 static unsigned int normal_isa[] = {0x0290,SENSORS_ISA_END}; 55 static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; 56 57 /* Insmod parameters */ 58 SENSORS_INSMOD_3(w83781d,w83782d,w83783s); 59 51 60 /* Many W83781D constants specified below */ 52 61 … … 106 115 #define W83781D_REG_PWMCLK12 0x5C 107 116 #define W83781D_REG_PWMCLK34 0x45C 108 const u8 regpwm[] = {W83781D_REG_PWM1, W83781D_REG_PWM2, W83781D_REG_PWM3, W83781D_REG_PWM4}; 117 static const u8 regpwm[] = {W83781D_REG_PWM1, W83781D_REG_PWM2, 118 W83781D_REG_PWM3, W83781D_REG_PWM4}; 109 119 #define W83781D_REG_PWM(nr) (regpwm[(nr) - 1]) 120 121 #define W83781D_REG_I2C_ADDR 0x48 110 122 111 123 /* The following are undocumented in the data sheets however we … … 121 133 #define W83781D_REG_RT_IDX 0x50 122 134 #define W83781D_REG_RT_VAL 0x51 123 124 #define W83781D_WCHIPID 0x10125 #define W83782D_WCHIPID 0x30126 #define W83783S_WCHIPID 0x40127 128 135 129 136 /* Conversions. Rounding is only done on the TO_REG variants. */ … … 291 298 struct semaphore lock; 292 299 int sysctl_id; 300 enum chips type; 293 301 294 302 struct semaphore update_lock; … … 296 304 unsigned long last_updated; /* In jiffies */ 297 305 298 u8 in[9]; /* Register value - 8 and9 for 782D only */299 u8 in_max[9]; /* Register value - 8 and9 for 782D only */300 u8 in_min[9]; /* Register value - 8 and9 for 782D only */306 u8 in[9]; /* Register value - 8 & 9 for 782D only */ 307 u8 in_max[9]; /* Register value - 8 & 9 for 782D only */ 308 u8 in_min[9]; /* Register value - 8 & 9 for 782D only */ 301 309 u8 fan[3]; /* Register value */ 302 310 u8 fan_min[3]; /* Register value */ … … 304 312 u8 temp_over; /* Register value */ 305 313 u8 temp_hyst; /* Register value */ 306 u16 temp_add[2]; /* Register value */314 u16 temp_add[2]; /* Register value */ 307 315 u16 temp_add_over[2]; /* Register value */ 308 316 u16 temp_add_hyst[2]; /* Register value */ … … 312 320 u16 beeps; /* Register encoding, combined */ 313 321 u8 beep_enable; /* Boolean */ 314 u8 wchipid; /* Register value */315 322 u8 pwm[4]; /* Register value */ 316 323 u16 sens[3]; /* 782D/783S only. 317 324 1 = pentium diode; 2 = 3904 diode; 318 325 3000-5000 = thermistor beta. 319 Default = 3435. Other Betas unimplemented */ 326 Default = 3435. 327 Other Betas unimplemented */ 320 328 #ifdef W83781D_RT 321 329 u8 rt[3][32]; /* Register value */ … … 328 336 329 337 static int w83781d_attach_adapter(struct i2c_adapter *adapter); 330 static int w83781d_detect_isa(struct isa_adapter *adapter); 331 static int w83781d_detect_smbus(struct i2c_adapter *adapter); 338 static int w83781d_detect(struct i2c_adapter *adapter, int address, int kind); 332 339 static int w83781d_detach_client(struct i2c_client *client); 333 static int w83781d_detach_isa(struct isa_client *client);334 static int w83781d_detach_smbus(struct i2c_client *client);335 static int w83781d_new_client(struct i2c_adapter *adapter,336 struct i2c_client *new_client);337 static void w83781d_remove_client(struct i2c_client *client);338 340 static int w83781d_command(struct i2c_client *client, unsigned int cmd, 339 341 void *arg); … … 376 378 allocation could also be used; the code needed for this would probably 377 379 take more memory than the datastructure takes now. */ 378 #define MAX_W83781D_NR 4380 #define MAX_W83781D_NR 8 379 381 static struct i2c_client *w83781d_list[MAX_W83781D_NR]; 380 382 … … 607 609 int w83781d_attach_adapter(struct i2c_adapter *adapter) 608 610 { 609 if (i2c_is_isa_adapter(adapter)) 610 return w83781d_detect_isa((struct isa_adapter *) adapter); 611 else 612 return w83781d_detect_smbus(adapter); 613 } 614 615 /* This function is called whenever a client should be removed: 616 * w83781d_driver is removed (when this module is unloaded) 617 * when an adapter is removed which has a w83781d client (and w83781d_driver 618 is still present). */ 619 int w83781d_detach_client(struct i2c_client *client) 620 { 621 if (i2c_is_isa_client(client)) 622 return w83781d_detach_isa((struct isa_client *) client); 623 else 624 return w83781d_detach_smbus(client); 625 } 626 627 /* Detect whether there is a W83781D on the ISA bus, register and initialize 628 it. */ 629 int w83781d_detect_isa(struct isa_adapter *adapter) 630 { 631 int address,err,temp,wchipid; 632 struct isa_client *new_client; 633 const char *type_name; 634 const char *client_name; 635 636 /* OK, this is no detection. I know. It will do for now, though. */ 637 638 err = 0; 639 for (address = 0x290; (! err) && (address <= 0x290); address += 0x08) { 640 if (check_region(address, W83781D_EXTENT)) 641 continue; 642 643 if (inb_p(address + W83781D_ADDR_REG_OFFSET) == 0xff) { 644 outb_p(0x00,address + W83781D_ADDR_REG_OFFSET); 645 if (inb_p(address + W83781D_ADDR_REG_OFFSET) == 0xff) 646 continue; 647 } 648 649 /* Real detection code goes here */ 650 651 /* The Winbond may be stuck in bank 1 or 2. This should reset it. 652 We really need some nifty detection code, because this can lead 653 to a lot of problems if there is no Winbond present! */ 654 outb_p(W83781D_REG_BANK,address + W83781D_ADDR_REG_OFFSET); 655 outb_p(0x00,address + W83781D_DATA_REG_OFFSET); 656 657 /* Detection -- To bad we can't do this before setting to bank 0 */ 658 outb_p(W83781D_REG_CHIPMAN,address + W83781D_ADDR_REG_OFFSET); 659 temp=inb_p(address + W83781D_DATA_REG_OFFSET); 660 #ifdef DEBUG 661 printk("w83781d.o: Detect byte: 0x%X\n",temp); 662 #endif 663 if (temp != 0x0A3) { 664 #ifdef DEBUG 665 printk("w83781d.o: Winbond W8378xx detection failed (ISA at 0x%X)\n",address); 666 #endif 667 continue; 668 } 669 outb_p(W83781D_REG_WCHIPID,address + W83781D_ADDR_REG_OFFSET); 611 return sensors_detect(adapter,&addr_data,w83781d_detect); 612 } 613 614 int w83781d_detect(struct i2c_adapter *adapter, int address, int kind) 615 { 616 int i,val1,val2; 617 struct i2c_client *new_client; 618 struct w83781d_data *data; 619 int err=0; 620 const char *type_name = ""; 621 const char *client_name = ""; 622 int is_isa = i2c_is_isa_adapter(adapter); 623 624 /* We need address registration for the I2C bus too. That is not yet 625 implemented. */ 626 if (is_isa) { 627 if (check_region(address,W83781D_EXTENT)) 628 goto ERROR0; 629 } 630 631 /* Probe whether there is anything available on this address. Already 632 done for SMBus clients */ 633 if (kind < 0) { 634 if (is_isa) { 635 636 #define REALLY_SLOW_IO 637 /* We need the timeouts for at least some LM78-like chips. But only 638 if we read 'undefined' registers. */ 639 i = inb_p(address + 1); 640 if (inb_p(address + 2) != i) 641 goto ERROR0; 642 if (inb_p(address + 3) != i) 643 goto ERROR0; 644 if (inb_p(address + 7) != i) 645 goto ERROR0; 646 #undef REALLY_SLOW_IO 647 648 /* Let's just hope nothing breaks here */ 649 i = inb_p(address + 5) & 0x7f; 650 outb_p(~i & 0x7f,address+5); 651 if ((inb_p(address + 5) & 0x7f) != (~i & 0x7f)) { 652 outb_p(i,address+5); 653 return 0; 654 } 655 } 656 } 657 658 /* OK. For now, we presume we have a valid client. We now create the 659 client structure, even though we cannot fill it completely yet. 660 But it allows us to access w83781d_{read,write}_value. */ 661 662 if (! (new_client = kmalloc((is_isa?sizeof(struct isa_client): 663 sizeof(struct i2c_client)) + 664 sizeof(struct w83781d_data), 665 GFP_KERNEL))) { 666 err = -ENOMEM; 667 goto ERROR0; 668 } 669 670 if (is_isa) { 671 data = (struct w83781d_data *) (((struct isa_client *) new_client) + 1); 672 new_client->addr = 0; 673 ((struct isa_client *) new_client)->isa_addr = address; 674 data->lock = MUTEX; 675 } else { 676 data = (struct w83781d_data *) (((struct i2c_client *) new_client) + 1); 677 new_client->addr = address; 678 } 679 new_client->data = data; 680 new_client->adapter = adapter; 681 new_client->driver = &w83781d_driver; 682 683 /* Now, we do the remaining detection. */ 684 685 /* The w8378?d may be stuck in some other bank than bank 0. This may 686 make reading other information impossible. Specify a force=... or 687 force_*=... parameter, and the Winbond will be reset to the right 688 bank. */ 689 if (kind < 0) { 690 if (w83781d_read_value(new_client,W83781D_REG_CONFIG) & 0x80) 691 goto ERROR1; 692 if (!is_isa && 693 (w83781d_read_value(new_client,W83781D_REG_I2C_ADDR) != address)) 694 goto ERROR1; 695 val1 = w83781d_read_value(new_client,W83781D_REG_BANK); 696 val2 = w83781d_read_value(new_client,W83781D_REG_CHIPMAN); 697 if (!(val1 & 0x07) && 698 ((!(val1 & 0x80) && (val2 != 0xa3)) || 699 ((val1 & 0x80) && (val2 != 0x5c)))) 700 goto ERROR1; 701 } 702 703 /* We have either had a force parameter, or we have already detected the 704 Winbond. Put it now into bank 0 */ 705 w83781d_write_value(new_client,W83781D_REG_BANK, 706 w83781d_read_value(new_client,W83781D_REG_BANK) & 0xf8); 707 708 /* Determine the chip type. */ 709 if (kind <= 0) { 670 710 /* mask off lower bit, not reliable */ 671 wchipid = 0xFE & inb_p(address + W83781D_DATA_REG_OFFSET); 672 if(wchipid == W83782D_WCHIPID) { 673 printk("w83781d.o: Winbond W83782D detected (ISA addr=0x%X)\n",address); 674 type_name = "w83782d"; 675 client_name = "Winbond W83782D chip"; 676 } else { 677 printk("w83781d.o: Winbond W83781D detected (ISA addr=0x%X)\n",address); 678 type_name = "w83781d"; 679 client_name = "Winbond W83781D chip"; 680 } 681 711 val1 = w83781d_read_value(new_client,W83781D_REG_WCHIPID) & 0xfe; 712 if (val1 == 0x10) 713 kind = w83781d; 714 else if (val1 == 0x30) 715 kind = w83782d; 716 else if (val1 == 0x40) 717 kind = w83783s; 718 else 719 goto ERROR1; 720 } 721 722 if (kind == w83781d) { 723 type_name = "w83781d"; 724 client_name = "W83781D chip"; 725 } else if (kind == w83782d) { 726 type_name = "w83782d"; 727 client_name = "W83782D chip"; 728 } else if (kind == w83783s) { 729 type_name = "w83783s"; 730 client_name = "W83783S chip"; 731 } else { 732 #ifdef DEBUG 733 printk("w83781d.o: Internal error: unknown kind (%d)?!?",kind); 734 #endif 735 goto ERROR1; 736 } 737 738 /* Reserve the ISA region */ 739 if (is_isa) 682 740 request_region(address, W83781D_EXTENT, type_name); 683 741 684 /* Allocate space for a new client structure */ 685 if (! (new_client = kmalloc(sizeof(struct isa_client) + 686 sizeof(struct w83781d_data), 687 GFP_KERNEL))) 688 { 689 err=-ENOMEM; 690 goto ERROR1; 691 } 692 693 /* Fill the new client structure with data */ 694 new_client->data = (struct w83781d_data *) (new_client + 1); 695 new_client->addr = 0; 696 strcpy(new_client->name,client_name); 697 new_client->isa_addr = address; 698 if ((err = w83781d_new_client((struct i2c_adapter *) adapter, 699 (struct i2c_client *) new_client))) 700 goto ERROR2; 701 702 /* Tell i2c-core a new client has arrived */ 703 if ((err = isa_attach_client(new_client))) 704 goto ERROR3; 705 706 /* Register a new directory entry with module sensors */ 707 if ((err = sensors_register_entry((struct i2c_client *) new_client, 708 type_name, 709 (wchipid == W83782D_WCHIPID) ? w83782d_isa_dir_table_template : 710 w83781d_dir_table_template)) < 0) 711 goto ERROR4; 712 ((struct w83781d_data *) (new_client->data)) -> sysctl_id = err; 713 ((struct w83781d_data *) (new_client->data))->wchipid = wchipid; 714 err = 0; 715 716 /* Initialize the W83781D chip */ 717 w83781d_init_client((struct i2c_client *) new_client); 718 continue; 719 720 /* OK, this is not exactly good programming practice, usually. But it is 721 very code-efficient in this case. */ 722 723 ERROR4: 724 isa_detach_client(new_client); 725 ERROR3: 726 w83781d_remove_client((struct i2c_client *) new_client); 727 ERROR2: 728 kfree(new_client); 729 ERROR1: 730 release_region(address, W83781D_EXTENT); 731 } 732 return err; 733 734 } 735 736 /* Deregister and remove a W83781D client */ 737 int w83781d_detach_isa(struct isa_client *client) 738 { 739 int err,i; 740 for (i = 0; i < MAX_W83781D_NR; i++) 741 if ((client == (struct isa_client *) (w83781d_list[i]))) 742 break; 743 if (i == MAX_W83781D_NR) { 744 printk("w83781d.o: Client to detach not found.\n"); 745 return -ENOENT; 746 } 747 748 sensors_deregister_entry(((struct w83781d_data *)(client->data))->sysctl_id); 749 750 if ((err = isa_detach_client(client))) { 751 printk("w83781d.o: Client deregistration failed, client not detached.\n"); 752 return err; 753 } 754 w83781d_remove_client((struct i2c_client *) client); 755 release_region(client->isa_addr,W83781D_EXTENT); 756 kfree(client); 757 return 0; 758 } 759 760 int w83781d_detect_smbus(struct i2c_adapter *adapter) 761 { 762 int address,err,wchipid; 763 struct i2c_client *new_client; 764 const char *type_name,*client_name; 765 766 /* OK, this is no detection. I know. It will do for now, though. */ 767 err = 0; 768 for (address = 0x20; (! err) && (address <= 0x2f); address ++) { 769 770 /* Later on, we will keep a list of registered addresses for each 771 adapter, and check whether they are used here */ 772 773 if (smbus_read_byte_data(adapter,address,W83781D_REG_CONFIG) < 0) 774 continue; 775 776 smbus_write_byte_data(adapter,address,W83781D_REG_BANK,0x00); 777 778 err = smbus_read_byte_data(adapter,address,W83781D_REG_CHIPMAN); 779 #ifdef DEBUG 780 printk("w83781d.o: Detect byte: 0x%X\n",err); 781 #endif 782 if (err == 0x0A3) { 783 /* mask off lower bit, not reliable */ 784 wchipid = 0xFE & smbus_read_byte_data(adapter,address,W83781D_REG_WCHIPID); 785 if(wchipid == W83783S_WCHIPID) { 786 printk("w83781d.o: Winbond W83783S detected (SMBus addr 0x%X)\n",address); 787 type_name = "w83783s"; 788 client_name = "Winbond W83783S chip"; 789 } else if (wchipid == W83782D_WCHIPID) { 790 printk("w83781d.o: Winbond W83782D detected (SMBus addr 0x%X)\n",address); 791 type_name = "w83782d"; 792 client_name = "Winbond W83782D chip"; 793 } else { 794 printk("w83781d.o: Winbond W83781D detected (SMBus addr 0x%X)\n",address); 795 type_name = "w83781d"; 796 client_name = "Winbond W83781D chip"; 797 } 798 err=0; 799 } else { 800 #ifdef DEBUG 801 printk("w83781d.o: Winbond W8378xx detection failed (SMBus/I2C at 0x%X)\n",address); 802 #endif 803 continue; 804 } 805 806 807 /* Allocate space for a new client structure. To counter memory 808 ragmentation somewhat, we only do one kmalloc. */ 809 if (! (new_client = kmalloc(sizeof(struct i2c_client) + 810 sizeof(struct w83781d_data), 811 GFP_KERNEL))) { 812 err = -ENOMEM; 813 continue; 814 } 815 816 /* Fill the new client structure with data */ 817 new_client->data = (struct w83781d_data *) (new_client + 1); 818 new_client->addr = address; 819 strcpy(new_client->name,client_name); 820 if ((err = w83781d_new_client(adapter,new_client))) 821 goto ERROR2; 822 823 /* Tell i2c-core a new client has arrived */ 824 if ((err = i2c_attach_client(new_client))) 825 goto ERROR3; 826 827 /* Register a new directory entry with module sensors */ 828 if ((err = sensors_register_entry(new_client,type_name, 829 (wchipid == W83783S_WCHIPID) ? w83783s_dir_table_template : 830 ((wchipid == W83782D_WCHIPID) ? w83782d_i2c_dir_table_template : 831 w83781d_dir_table_template))) < 0) 832 goto ERROR4; 833 ((struct w83781d_data *) (new_client->data))->sysctl_id = err; 834 ((struct w83781d_data *) (new_client->data))->wchipid = wchipid; 835 err = 0; 836 837 /* Initialize the W83781D chip */ 838 w83781d_init_client(new_client); 839 continue; 840 841 /* OK, this is not exactly good programming practice, usually. But it is 842 very code-efficient in this case. */ 843 ERROR4: 844 i2c_detach_client(new_client); 845 ERROR3: 846 w83781d_remove_client((struct i2c_client *) new_client); 847 ERROR2: 848 kfree(new_client); 849 } 850 return err; 851 } 852 853 int w83781d_detach_smbus(struct i2c_client *client) 854 { 855 int err,i; 856 for (i = 0; i < MAX_W83781D_NR; i++) 857 if (client == w83781d_list[i]) 858 break; 859 if ((i == MAX_W83781D_NR)) { 860 printk("w83781d.o: Client to detach not found.\n"); 861 return -ENOENT; 862 } 863 864 sensors_deregister_entry(((struct w83781d_data *)(client->data))->sysctl_id); 865 866 if ((err = i2c_detach_client(client))) { 867 printk("w83781d.o: Client deregistration failed, client not detached.\n"); 868 return err; 869 } 870 w83781d_remove_client(client); 871 kfree(client); 872 return 0; 873 } 874 875 876 /* Find a free slot, and initialize most of the fields */ 877 int w83781d_new_client(struct i2c_adapter *adapter, 878 struct i2c_client *new_client) 879 { 880 int i; 881 struct w83781d_data *data; 882 883 /* First, seek out an empty slot */ 742 /* Fill in the remaining client fields and put it into the global list */ 743 strcpy(new_client->name,client_name); 744 data->type = kind; 745 884 746 for(i = 0; i < MAX_W83781D_NR; i++) 885 747 if (! w83781d_list[i]) … … 888 750 printk("w83781d.o: No empty slots left, recompile and heighten " 889 751 "MAX_W83781D_NR!\n"); 890 return-ENOMEM;891 }892 752 err = -ENOMEM; 753 goto ERROR2; 754 } 893 755 w83781d_list[i] = new_client; 894 756 new_client->id = i; 895 new_client->adapter = adapter;896 new_client->driver = &w83781d_driver;897 data = new_client->data;898 757 data->valid = 0; 899 data->lock = MUTEX;900 758 data->update_lock = MUTEX; 759 760 /* Tell the I2C layer a new client has arrived */ 761 if ((err = i2c_attach_client(new_client))) 762 goto ERROR3; 763 764 /* Register a new directory entry with module sensors */ 765 if ((i = sensors_register_entry((struct i2c_client *) new_client, 766 type_name, 767 kind == w83781d?w83781d_dir_table_template: 768 kind == w83783s?w83783s_dir_table_template: 769 is_isa?w83782d_i2c_dir_table_template: 770 w83782d_isa_dir_table_template)) < 0) { 771 err = i; 772 goto ERROR4; 773 } 774 data->sysctl_id = i; 775 776 /* Initialize the Winbond chip */ 777 w83781d_init_client(new_client); 901 778 return 0; 902 } 903 904 /* Inverse of w83781d_new_client */ 905 void w83781d_remove_client(struct i2c_client *client) 906 { 907 int i; 779 780 /* OK, this is not exactly good programming practice, usually. But it is 781 very code-efficient in this case. */ 782 783 ERROR4: 784 i2c_detach_client(new_client); 785 ERROR3: 908 786 for (i = 0; i < MAX_W83781D_NR; i++) 909 if ( client == w83781d_list[i])787 if (new_client == w83781d_list[i]) 910 788 w83781d_list[i] = NULL; 789 ERROR2: 790 if (is_isa) 791 release_region(address,W83781D_EXTENT); 792 ERROR1: 793 kfree(new_client); 794 ERROR0: 795 return err; 796 } 797 798 int w83781d_detach_client(struct i2c_client *client) 799 { 800 int err,i; 801 802 sensors_deregister_entry(((struct w83781d_data *)(client->data))->sysctl_id); 803 804 if ((err = i2c_detach_client(client))) { 805 printk("w83781d.o: Client deregistration failed, client not detached.\n"); 806 return err; 807 } 808 809 for (i = 0; i < MAX_W83781D_NR; i++) 810 if (client == w83781d_list[i]) 811 break; 812 if (i == MAX_W83781D_NR) { 813 printk("w83781d.o: Client to detach not found.\n"); 814 return -ENOENT; 815 } 816 w83781d_list[i] = NULL; 817 818 if i2c_is_isa_client(client) 819 release_region(((struct isa_client *)client)->isa_addr,W83781D_EXTENT); 820 kfree(client); 821 822 return 0; 911 823 } 912 824 … … 931 843 } 932 844 933 934 845 /* The SMBus locks itself, usually, but nothing may access the Winbond between 935 846 bank switches. ISA access must always be locked explicitely! … … 946 857 ((reg & 0x00ff) == 0x53) || 947 858 ((reg & 0x00ff) == 0x55)); 948 down( (struct semaphore *) (client->data));859 down(& (((struct w83781d_data *) (client->data)) -> lock)); 949 860 if (i2c_is_isa_client(client)) { 950 861 if (reg & 0xff00) { … … 981 892 smbus_write_byte_data(client->adapter,client->addr,W83781D_REG_BANK,0); 982 893 } 983 up( (struct semaphore *) (client->data));894 up( & (((struct w83781d_data *) (client->data)) -> lock)); 984 895 return res; 985 896 } … … 999 910 ((reg & 0x00ff) == 0x53) || 1000 911 ((reg & 0x00ff) == 0x55)); 1001 down( (struct semaphore *) (client->data));912 down( & (((struct w83781d_data *) (client->data)) -> lock)); 1002 913 if (i2c_is_isa_client(client)) { 1003 914 if (reg & 0xff00) { … … 1035 946 smbus_write_byte_data(client->adapter,client->addr,W83781D_REG_BANK,0); 1036 947 } 1037 up( (struct semaphore *) (client->data));948 up( & (((struct w83781d_data *) (client->data)) -> lock)); 1038 949 return 0; 1039 950 } … … 1043 954 { 1044 955 struct w83781d_data *data = client->data; 1045 int vid, wchipid;1046 int i;956 int vid,i; 957 int type = data->type; 1047 958 u8 tmp; 1048 959 1049 wchipid = data->wchipid;1050 960 /* Reset all except Watchdog values and last conversion values 1051 961 This sets fan-divs to 2, among others */ … … 1056 966 vid = VID_FROM_REG(vid); 1057 967 1058 if (wchipid != W83781D_WCHIPID) {968 if (type != w83781d) { 1059 969 tmp = w83781d_read_value(client,W83781D_REG_SCFG1); 1060 970 for (i = 1; i <= 3; i++) { … … 1067 977 data->sens[i-1] = 2; 1068 978 } 1069 if( data->wchipid == W83783S_WCHIPID && i == 2)979 if((type == w83783s) && (i == 2)) 1070 980 break; 1071 981 } … … 1081 991 */ 1082 992 1083 if( wchipid == W83781D_WCHIPID) {993 if(type == w83781d) { 1084 994 u16 k = 0; 1085 995 /* … … 1101 1011 w83781d_write_value(client,W83781D_REG_IN_MAX(0), 1102 1012 IN_TO_REG(W83781D_INIT_IN_MAX_0,0)); 1103 if( wchipid != W83783S_WCHIPID) {1013 if(type != w83783s) { 1104 1014 w83781d_write_value(client,W83781D_REG_IN_MIN(1), 1105 1015 IN_TO_REG(W83781D_INIT_IN_MIN_1,1)); … … 1107 1017 IN_TO_REG(W83781D_INIT_IN_MAX_1,1)); 1108 1018 } 1019 1109 1020 w83781d_write_value(client,W83781D_REG_IN_MIN(2), 1110 1021 IN_TO_REG(W83781D_INIT_IN_MIN_2,2)); … … 1119 1030 w83781d_write_value(client,W83781D_REG_IN_MAX(4), 1120 1031 IN_TO_REG(W83781D_INIT_IN_MAX_4,4)); 1121 if (wchipid == W83781D_WCHIPID) {1032 if (type == w83781d) { 1122 1033 w83781d_write_value(client,W83781D_REG_IN_MIN(5), 1123 1034 IN_TO_REG(W83781D_INIT_IN_MIN_5,5)); … … 1130 1041 IN_TO_REG(W83782D_INIT_IN_MAX_5,5)); 1131 1042 } 1132 if (wchipid == W83781D_WCHIPID) {1043 if (type == w83781d) { 1133 1044 w83781d_write_value(client,W83781D_REG_IN_MIN(6), 1134 1045 IN_TO_REG(W83781D_INIT_IN_MIN_6,6)); … … 1141 1052 IN_TO_REG(W83782D_INIT_IN_MAX_6,6)); 1142 1053 } 1143 if (wchipid == W83782D_WCHIPID) {1054 if (type == w83782d) { 1144 1055 w83781d_write_value(client,W83781D_REG_IN_MIN(7), 1145 1056 IN_TO_REG(W83781D_INIT_IN_MIN_7,7)); … … 1170 1081 w83781d_write_value(client,W83781D_REG_TEMP2_CONFIG,0x00); 1171 1082 1172 if (wchipid != W83783S_WCHIPID) {1083 if (type != w83783s) { 1173 1084 w83781d_write_value(client,W83781D_REG_TEMP3_OVER, 1174 1085 TEMP_ADD_TO_REG(W83781D_INIT_TEMP3_OVER)); … … 1198 1109 #endif 1199 1110 for (i = 0; i <= 8; i++) { 1200 if( data->wchipid == W83783S_WCHIPID && i == 1)1111 if((data->type == w83783s) && (i == 1)) 1201 1112 continue; /* 783S has no in1 */ 1202 1113 data->in[i] = w83781d_read_value(client,W83781D_REG_IN(i)); 1203 1114 data->in_min[i] = w83781d_read_value(client,W83781D_REG_IN_MIN(i)); 1204 1115 data->in_max[i] = w83781d_read_value(client,W83781D_REG_IN_MAX(i)); 1205 if( data->wchipid != W83782D_WCHIPID && i == 6)1116 if((data->type != w83782d) && (i == 6)) 1206 1117 break; 1207 1118 } … … 1210 1121 data->fan_min[i-1] = w83781d_read_value(client,W83781D_REG_FAN_MIN(i)); 1211 1122 } 1212 if(data-> wchipid != W83781D_WCHIPID) {1123 if(data->type != w83781d) { 1213 1124 for (i = 1; i <= 4; i++) { 1214 1125 data->pwm[i-1] = w83781d_read_value(client,W83781D_REG_PWM(i)); 1215 if(( data->wchipid == W83783S_WCHIPID||1216 ( data->wchipid == W83782D_WCHIPID&& i2c_is_isa_client(client)))1126 if(((data->type == w83783s) || 1127 ((data->type == w83782d) && i2c_is_isa_client(client))) 1217 1128 && i == 2) 1218 1129 break; 1219 1130 } 1220 1131 } 1132 1221 1133 data->temp = w83781d_read_value(client,W83781D_REG_TEMP); 1222 1134 data->temp_over = w83781d_read_value(client,W83781D_REG_TEMP_OVER); … … 1233 1145 data->fan_div[0] = (i >> 4) & 0x03; 1234 1146 data->fan_div[1] = i >> 6; 1235 if(data->wchipid != W83782D_WCHIPID) { 1236 data->fan_div[2] = (w83781d_read_value(client,W83781D_REG_PIN) >> 6) & 0x03; 1147 if (data->type != w83782d) { 1148 data->fan_div[2] = (w83781d_read_value(client, 1149 W83781D_REG_PIN) >> 6) & 0x03; 1237 1150 } 1238 1151 data->alarms = w83781d_read_value(client,W83781D_REG_ALARM1) + 1239 1152 (w83781d_read_value(client,W83781D_REG_ALARM2) << 8); 1240 if (data->wchipid == W83782D_WCHIPID) {1153 if (data->type == w83782d) { 1241 1154 data->alarms |= w83781d_read_value(client,W83781D_REG_ALARM3) << 16; 1242 1155 } … … 1316 1229 } 1317 1230 1318 1319 1231 void w83781d_temp(struct i2c_client *client, int operation, int ctl_name, 1320 1232 int *nrels_mag, long *results) … … 1340 1252 } 1341 1253 } 1342 1343 1254 1344 1255 void w83781d_temp_add(struct i2c_client *client, int operation, int ctl_name, … … 1495 1406 if (*nrels_mag >= 1) { 1496 1407 switch(results[0]) { 1497 case 1: /* PII/Celeron diode */1408 case 1: /* PII/Celeron diode */ 1498 1409 tmp = w83781d_read_value(client,W83781D_REG_SCFG1); 1499 1410 w83781d_write_value(client,W83781D_REG_SCFG1, tmp | BIT_SCFG2[nr-1]); … … 1502 1413 data->sens[nr-1] = results[0]; 1503 1414 break; 1504 case 2: /* 3904 */1415 case 2: /* 3904 */ 1505 1416 tmp = w83781d_read_value(client,W83781D_REG_SCFG1); 1506 1417 w83781d_write_value(client,W83781D_REG_SCFG1, tmp | BIT_SCFG2[nr-1]); 1507 1418 tmp = w83781d_read_value(client,W83781D_REG_SCFG2); 1508 w83781d_write_value(client,W83781D_REG_SCFG2, tmp & ~ BIT_SCFG2[nr-1]); 1419 w83781d_write_value(client,W83781D_REG_SCFG2, tmp & ~ BIT_SCFG2[nr-1]) 1420 ; 1509 1421 data->sens[nr-1] = results[0]; 1510 1422 break; 1511 case W83781D_DEFAULT_BETA: /* thermistor */1423 case W83781D_DEFAULT_BETA: /* thermistor */ 1512 1424 tmp = w83781d_read_value(client,W83781D_REG_SCFG1); 1513 w83781d_write_value(client,W83781D_REG_SCFG1, tmp & ~ BIT_SCFG2[nr-1]); 1425 w83781d_write_value(client,W83781D_REG_SCFG1, tmp & ~ BIT_SCFG2[nr-1]) 1426 ; 1514 1427 data->sens[nr-1] = results[0]; 1515 1428 break; 1516 1429 default: 1517 printk("w83781d.o: Invalid sensor type %ld; must be 1, 2, or %d\n", results[0], W83781D_DEFAULT_BETA); 1430 printk("w83781d.o: Invalid sensor type %ld; must be 1, 2, or %d\n", 1431 results[0], W83781D_DEFAULT_BETA); 1518 1432 break; 1519 1433 } … … 1574 1488 #ifdef MODULE 1575 1489 1576 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, Philip Edelbrock <phil@netroedge.com>, and Mark Studebaker <mds@eng.paradyne.com>"); 1490 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, Philip Edelbrock <phil@netroedge 1491 .com>, and Mark Studebaker <mds@eng.paradyne.com>"); 1577 1492 MODULE_DESCRIPTION("W83781D driver"); 1578 1493 … … 1589 1504 #endif /* MODULE */ 1590 1505 1506 1507 1508 lm-sensors/trunk/prog/detect/sensors-detect
r336 r341 157 157 i2c_addrs => [0x00..0x7f], 158 158 i2c_detect => sub { w83781d_detect 0, @_}, 159 i2c_driver_addrs => [0x20..0x2f], 159 160 isa_addrs => [0x290], 160 161 isa_detect => sub { w83781d_isa_detect 0, @_ }, … … 165 166 driver => "w83781d", 166 167 i2c_addrs => [0x00..0x7f], 168 i2c_driver_addrs => [0x20..0x2f], 167 169 i2c_detect => sub { w83781d_detect 1, @_}, 168 170 } , … … 171 173 driver => "w83781d", 172 174 i2c_addrs => [0x00..0x7f], 175 i2c_driver_addrs => [0x20..0x2f], 173 176 i2c_detect => sub { w83781d_detect 2, @_}, 174 177 isa_addrs => [0x290], … … 1175 1178 (($reg1 & 0x80) == 0x80 and $reg2 == 0x5c); 1176 1179 return unless ($reg1 & 0x07) == 0x00; 1177 $reg1 = i2c_smbus_read_byte_data($file,0x58) & 0xfe;1180 $reg1 = i2c_smbus_read_byte_data($file,0x58) & 0xfe; 1178 1181 return if $chip == 0 and $reg1 != 0x10; 1179 1182 return if $chip == 1 and $reg1 != 0x30; … … 1208 1211 { 1209 1212 my ($chip,$addr) = @_ ; 1210 my ($reg1,$reg2);1211 1213 my $val = inb ($addr + 1); 1212 return if inb ($addr + 2) != $val or inb ($addr + 3) != $val or 1214 return if inb ($addr + 2) != $val or inb ($addr + 3) != $val or 1213 1215 inb ($addr + 7) != $val; 1214 1216 … … 1226 1228 (($reg1 & 0x80) == 0x80 and $reg2 == 0x5c); 1227 1229 return unless ($reg1 & 0x07) == 0x00; 1228 $reg1 = &$read_proc(0x58) ;1229 return if $chip == 0 and ($reg1 & 0xfe)!= 0x10;1230 $reg1 = &$read_proc(0x58) & 0xfe; 1231 return if $chip == 0 and $reg1 != 0x10; 1230 1232 return if $chip == 1 and $reg1 != 0x30; 1231 1233 return if $chip == 2 and $reg1 != 0x40;
