Changeset 341

Show
Ignore:
Timestamp:
03/24/99 22:28:22 (10 years ago)
Author:
frodo
Message:

Taught the w83781d module about insmod parameters

Also fixed a small lm78 problem and synchronised the detect script with
the Winbond detection.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • lm-sensors/trunk/kernel/chips/lm78.c

    r338 r341  
    4242/* Insmod parameters */ 
    4343SENSORS_INSMOD_3(lm78,lm78j,lm79); 
     44 
    4445/* Many LM78 constants specified below */ 
    4546 
     
    323324      /* We need the timeouts for at least some LM78-like chips. But only 
    324325         if we read 'undefined' registers. */ 
    325       if (check_region(address,LM78_EXTENT)) 
    326         goto ERROR0; 
    327326      i = inb_p(address + 1); 
    328327      if (inb_p(address + 2) != i) 
  • lm-sensors/trunk/kernel/chips/w83781d.c

    r339 r341  
    4949#undef W83781D_RT 
    5050 
     51/* Addresses to scan */ 
     52static unsigned short normal_i2c[] = {SENSORS_I2C_END}; 
     53static unsigned short normal_i2c_range[] = {0x20,0x2f,SENSORS_I2C_END}; 
     54static unsigned int normal_isa[] = {0x0290,SENSORS_ISA_END}; 
     55static unsigned int normal_isa_range[] = {SENSORS_ISA_END}; 
     56 
     57/* Insmod parameters */ 
     58SENSORS_INSMOD_3(w83781d,w83782d,w83783s); 
     59 
    5160/* Many W83781D constants specified below */ 
    5261 
     
    106115#define W83781D_REG_PWMCLK12 0x5C 
    107116#define W83781D_REG_PWMCLK34 0x45C 
    108 const u8 regpwm[] = {W83781D_REG_PWM1, W83781D_REG_PWM2, W83781D_REG_PWM3, W83781D_REG_PWM4}; 
     117static const u8 regpwm[] = {W83781D_REG_PWM1, W83781D_REG_PWM2,  
     118                            W83781D_REG_PWM3, W83781D_REG_PWM4}; 
    109119#define W83781D_REG_PWM(nr) (regpwm[(nr) - 1]) 
     120 
     121#define W83781D_REG_I2C_ADDR 0x48 
    110122 
    111123/* The following are undocumented in the data sheets however we 
     
    121133#define W83781D_REG_RT_IDX 0x50 
    122134#define W83781D_REG_RT_VAL 0x51 
    123  
    124 #define W83781D_WCHIPID 0x10 
    125 #define W83782D_WCHIPID 0x30 
    126 #define W83783S_WCHIPID 0x40 
    127  
    128135 
    129136/* Conversions. Rounding is only done on the TO_REG variants. */ 
     
    291298         struct semaphore lock; 
    292299         int sysctl_id; 
     300         enum chips type; 
    293301 
    294302         struct semaphore update_lock; 
     
    296304         unsigned long last_updated; /* In jiffies */ 
    297305 
    298          u8 in[9];                   /* Register value - 8 and 9 for 782D only */ 
    299          u8 in_max[9];               /* Register value - 8 and 9 for 782D only */ 
    300          u8 in_min[9];               /* Register value - 8 and 9 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 */ 
    301309         u8 fan[3];                  /* Register value */ 
    302310         u8 fan_min[3];              /* Register value */ 
     
    304312         u8 temp_over;               /* Register value */ 
    305313         u8 temp_hyst;               /* Register value */ 
    306          u16 temp_add[2];            /* Register value */ 
     314         u16 temp_add[2];            /* Register value */ 
    307315         u16 temp_add_over[2];       /* Register value */ 
    308316         u16 temp_add_hyst[2];       /* Register value */ 
     
    312320         u16 beeps;                  /* Register encoding, combined */ 
    313321         u8 beep_enable;             /* Boolean */ 
    314          u8 wchipid;                 /* Register value */ 
    315322         u8 pwm[4];                  /* Register value */                                
    316323         u16 sens[3];                /* 782D/783S only. 
    317324                                        1 = pentium diode; 2 = 3904 diode; 
    318325                                        3000-5000 = thermistor beta. 
    319                                         Default = 3435. Other Betas unimplemented */ 
     326                                        Default = 3435.  
     327                                        Other Betas unimplemented */ 
    320328#ifdef W83781D_RT 
    321329         u8 rt[3][32];               /* Register value */ 
     
    328336 
    329337static 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); 
     338static int w83781d_detect(struct i2c_adapter *adapter, int address, int kind); 
    332339static 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); 
    338340static int w83781d_command(struct i2c_client *client, unsigned int cmd,  
    339341                        void *arg); 
     
    376378   allocation could also be used; the code needed for this would probably 
    377379   take more memory than the datastructure takes now. */ 
    378 #define MAX_W83781D_NR 4 
     380#define MAX_W83781D_NR 8 
    379381static struct i2c_client *w83781d_list[MAX_W83781D_NR]; 
    380382 
     
    607609int w83781d_attach_adapter(struct i2c_adapter *adapter) 
    608610{ 
    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 
     614int 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) { 
    670710    /* 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) 
    682740    request_region(address, W83781D_EXTENT, type_name); 
    683741 
    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 
    884746  for(i = 0; i < MAX_W83781D_NR; i++) 
    885747    if (! w83781d_list[i]) 
     
    888750    printk("w83781d.o: No empty slots left, recompile and heighten " 
    889751           "MAX_W83781D_NR!\n"); 
    890     return -ENOMEM; 
    891   } 
    892    
     752    err = -ENOMEM; 
     753    goto ERROR2; 
     754  } 
    893755  w83781d_list[i] = new_client; 
    894756  new_client->id = i; 
    895   new_client->adapter = adapter; 
    896   new_client->driver = &w83781d_driver; 
    897   data = new_client->data; 
    898757  data->valid = 0; 
    899   data->lock = MUTEX; 
    900758  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); 
    901778  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 
     783ERROR4: 
     784  i2c_detach_client(new_client); 
     785ERROR3: 
    908786  for (i = 0; i < MAX_W83781D_NR; i++) 
    909     if (client == w83781d_list[i])  
     787    if (new_client == w83781d_list[i]) 
    910788      w83781d_list[i] = NULL; 
     789ERROR2: 
     790  if (is_isa) 
     791    release_region(address,W83781D_EXTENT); 
     792ERROR1: 
     793  kfree(new_client); 
     794ERROR0: 
     795  return err; 
     796} 
     797 
     798int 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; 
    911823} 
    912824 
     
    931843} 
    932844  
    933  
    934845/* The SMBus locks itself, usually, but nothing may access the Winbond between 
    935846   bank switches. ISA access must always be locked explicitely!  
     
    946857                                  ((reg & 0x00ff) == 0x53) ||  
    947858                                  ((reg & 0x00ff) == 0x55)); 
    948   down((struct semaphore *) (client->data)); 
     859  down(& (((struct w83781d_data *) (client->data)) -> lock)); 
    949860  if (i2c_is_isa_client(client)) { 
    950861    if (reg & 0xff00) { 
     
    981892      smbus_write_byte_data(client->adapter,client->addr,W83781D_REG_BANK,0); 
    982893  } 
    983   up((struct semaphore *) (client->data)); 
     894  up( & (((struct w83781d_data *) (client->data)) -> lock)); 
    984895  return res; 
    985896} 
     
    999910                                  ((reg & 0x00ff) == 0x53) ||  
    1000911                                  ((reg & 0x00ff) == 0x55)); 
    1001   down((struct semaphore *) (client->data)); 
     912  down( & (((struct w83781d_data *) (client->data)) -> lock)); 
    1002913  if (i2c_is_isa_client(client)) { 
    1003914    if (reg & 0xff00) { 
     
    1035946      smbus_write_byte_data(client->adapter,client->addr,W83781D_REG_BANK,0); 
    1036947  } 
    1037   up((struct semaphore *) (client->data)); 
     948  up( & (((struct w83781d_data *) (client->data)) -> lock)); 
    1038949  return 0; 
    1039950} 
     
    1043954{ 
    1044955  struct w83781d_data *data = client->data; 
    1045   int vid,wchipid
    1046   int i
     956  int vid,i
     957  int type = data->type
    1047958  u8 tmp; 
    1048959 
    1049   wchipid = data->wchipid; 
    1050960  /* Reset all except Watchdog values and last conversion values 
    1051961     This sets fan-divs to 2, among others */ 
     
    1056966  vid = VID_FROM_REG(vid); 
    1057967 
    1058   if(wchipid != W83781D_WCHIPID) { 
     968  if (type != w83781d) { 
    1059969    tmp = w83781d_read_value(client,W83781D_REG_SCFG1); 
    1060970    for (i = 1; i <= 3; i++) { 
     
    1067977          data->sens[i-1] = 2; 
    1068978      } 
    1069       if(data->wchipid == W83783S_WCHIPID && i == 2
     979      if((type == w83783s) && (i == 2)
    1070980        break; 
    1071981    } 
     
    1081991*/ 
    1082992 
    1083   if(wchipid == W83781D_WCHIPID) { 
     993  if(type == w83781d) { 
    1084994    u16 k = 0; 
    1085995/* 
     
    11011011  w83781d_write_value(client,W83781D_REG_IN_MAX(0), 
    11021012                      IN_TO_REG(W83781D_INIT_IN_MAX_0,0)); 
    1103   if(wchipid != W83783S_WCHIPID) { 
     1013  if(type != w83783s) { 
    11041014    w83781d_write_value(client,W83781D_REG_IN_MIN(1), 
    11051015                        IN_TO_REG(W83781D_INIT_IN_MIN_1,1)); 
     
    11071017                        IN_TO_REG(W83781D_INIT_IN_MAX_1,1)); 
    11081018  } 
     1019 
    11091020  w83781d_write_value(client,W83781D_REG_IN_MIN(2), 
    11101021                      IN_TO_REG(W83781D_INIT_IN_MIN_2,2)); 
     
    11191030  w83781d_write_value(client,W83781D_REG_IN_MAX(4), 
    11201031                      IN_TO_REG(W83781D_INIT_IN_MAX_4,4)); 
    1121   if(wchipid == W83781D_WCHIPID) { 
     1032  if (type == w83781d) { 
    11221033    w83781d_write_value(client,W83781D_REG_IN_MIN(5), 
    11231034                        IN_TO_REG(W83781D_INIT_IN_MIN_5,5)); 
     
    11301041                        IN_TO_REG(W83782D_INIT_IN_MAX_5,5)); 
    11311042  } 
    1132   if(wchipid == W83781D_WCHIPID) { 
     1043  if (type == w83781d) { 
    11331044    w83781d_write_value(client,W83781D_REG_IN_MIN(6), 
    11341045                        IN_TO_REG(W83781D_INIT_IN_MIN_6,6)); 
     
    11411052                        IN_TO_REG(W83782D_INIT_IN_MAX_6,6)); 
    11421053  } 
    1143   if(wchipid == W83782D_WCHIPID) { 
     1054  if (type == w83782d) { 
    11441055    w83781d_write_value(client,W83781D_REG_IN_MIN(7), 
    11451056                        IN_TO_REG(W83781D_INIT_IN_MIN_7,7)); 
     
    11701081  w83781d_write_value(client,W83781D_REG_TEMP2_CONFIG,0x00); 
    11711082 
    1172   if(wchipid != W83783S_WCHIPID) { 
     1083  if (type != w83783s) { 
    11731084    w83781d_write_value(client,W83781D_REG_TEMP3_OVER, 
    11741085                        TEMP_ADD_TO_REG(W83781D_INIT_TEMP3_OVER)); 
     
    11981109#endif 
    11991110    for (i = 0; i <= 8; i++) { 
    1200       if(data->wchipid == W83783S_WCHIPID  &&  i == 1
     1111      if((data->type == w83783s)  &&  (i == 1)
    12011112        continue; /* 783S has no in1 */ 
    12021113      data->in[i]     = w83781d_read_value(client,W83781D_REG_IN(i)); 
    12031114      data->in_min[i] = w83781d_read_value(client,W83781D_REG_IN_MIN(i)); 
    12041115      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)
    12061117        break; 
    12071118    } 
     
    12101121      data->fan_min[i-1] = w83781d_read_value(client,W83781D_REG_FAN_MIN(i)); 
    12111122    } 
    1212     if(data->wchipid != W83781D_WCHIPID) { 
     1123    if(data->type != w83781d) { 
    12131124      for (i = 1; i <= 4; i++) { 
    12141125        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))) 
    12171128          &&  i == 2) 
    12181129          break; 
    12191130      } 
    12201131    } 
     1132 
    12211133    data->temp = w83781d_read_value(client,W83781D_REG_TEMP); 
    12221134    data->temp_over = w83781d_read_value(client,W83781D_REG_TEMP_OVER); 
     
    12331145    data->fan_div[0] = (i >> 4) & 0x03; 
    12341146    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; 
    12371150    } 
    12381151    data->alarms = w83781d_read_value(client,W83781D_REG_ALARM1) + 
    12391152                   (w83781d_read_value(client,W83781D_REG_ALARM2) << 8); 
    1240     if(data->wchipid == W83782D_WCHIPID) { 
     1153    if (data->type == w83782d) { 
    12411154      data->alarms |= w83781d_read_value(client,W83781D_REG_ALARM3) << 16; 
    12421155    } 
     
    13161229} 
    13171230 
    1318  
    13191231void w83781d_temp(struct i2c_client *client, int operation, int ctl_name, 
    13201232               int *nrels_mag, long *results) 
     
    13401252  } 
    13411253} 
    1342  
    13431254 
    13441255void w83781d_temp_add(struct i2c_client *client, int operation, int ctl_name, 
     
    14951406    if (*nrels_mag >= 1) { 
    14961407      switch(results[0]) { 
    1497         case 1:                                /* PII/Celeron diode */ 
     1408        case 1:                         /* PII/Celeron diode */ 
    14981409          tmp = w83781d_read_value(client,W83781D_REG_SCFG1); 
    14991410          w83781d_write_value(client,W83781D_REG_SCFG1, tmp | BIT_SCFG2[nr-1]); 
     
    15021413          data->sens[nr-1] = results[0]; 
    15031414          break; 
    1504         case 2:                                /* 3904 */ 
     1415        case 2:                         /* 3904 */ 
    15051416          tmp = w83781d_read_value(client,W83781D_REG_SCFG1); 
    15061417          w83781d_write_value(client,W83781D_REG_SCFG1, tmp | BIT_SCFG2[nr-1]); 
    15071418          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
    15091421          data->sens[nr-1] = results[0]; 
    15101422          break; 
    1511         case W83781D_DEFAULT_BETA:     /* thermistor */ 
     1423        case W83781D_DEFAULT_BETA:      /* thermistor */ 
    15121424          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
    15141427          data->sens[nr-1] = results[0]; 
    15151428          break; 
    15161429        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); 
    15181432          break; 
    15191433      } 
     
    15741488#ifdef MODULE 
    15751489 
    1576 MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, Philip Edelbrock <phil@netroedge.com>, and Mark Studebaker <mds@eng.paradyne.com>"); 
     1490MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, Philip Edelbrock <phil@netroedge 
     1491.com>, and Mark Studebaker <mds@eng.paradyne.com>"); 
    15771492MODULE_DESCRIPTION("W83781D driver"); 
    15781493 
     
    15891504#endif /* MODULE */ 
    15901505 
     1506 
     1507 
     1508     
  • lm-sensors/trunk/prog/detect/sensors-detect

    r336 r341  
    157157       i2c_addrs => [0x00..0x7f],  
    158158       i2c_detect => sub { w83781d_detect 0, @_}, 
     159       i2c_driver_addrs => [0x20..0x2f],  
    159160       isa_addrs => [0x290], 
    160161       isa_detect => sub { w83781d_isa_detect 0, @_ }, 
     
    165166       driver => "w83781d", 
    166167       i2c_addrs => [0x00..0x7f],  
     168       i2c_driver_addrs => [0x20..0x2f],  
    167169       i2c_detect => sub { w83781d_detect 1, @_}, 
    168170     } , 
     
    171173       driver => "w83781d", 
    172174       i2c_addrs => [0x00..0x7f],  
     175       i2c_driver_addrs => [0x20..0x2f],  
    173176       i2c_detect => sub { w83781d_detect 2, @_}, 
    174177       isa_addrs => [0x290], 
     
    11751178                (($reg1 & 0x80) == 0x80 and $reg2 == 0x5c); 
    11761179  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; 
    11781181  return if $chip == 0 and  $reg1 != 0x10; 
    11791182  return if $chip == 1 and  $reg1 != 0x30; 
     
    12081211{ 
    12091212  my ($chip,$addr) = @_ ; 
    1210   my ($reg1,$reg2); 
    12111213  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 
    12131215            inb ($addr + 7) != $val; 
    12141216 
     
    12261228                (($reg1 & 0x80) == 0x80 and $reg2 == 0x5c); 
    12271229  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; 
    12301232  return if $chip == 1 and  $reg1 != 0x30; 
    12311233  return if $chip == 2 and  $reg1 != 0x40;