Show
Ignore:
Timestamp:
09/23/06 11:32:29 (2 years ago)
Author:
khali
Message:

vt1211: Rework the voltage and temperature conversions and the temperature

input order to match the Linux 2.6 driver.

libsensors: Change vt1211 temp3-7 magnitude from 1 to 3.
sensors.conf.eg: Adjust the vt1211 section to match the new driver

interface.

Files:

Legend:

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

    r4154 r4168  
    100100        Sensor          Voltage Mode    Temp Mode 
    101101        --------        ------------    --------- 
    102         Reading 1                       temp3   Intel thermal diode 
    103         Reading 3                       temp1   VT1211 internal thermal diode 
    104         UCH1/Reading2   in0             temp2 
     102        Reading 1                       temp1   Intel thermal diode 
     103        Reading 3                       temp2   VT1211 internal thermal diode 
     104        UCH1/Reading2   in0             temp3 
    105105        UCH2            in1             temp4 
    106106        UCH3            in2             temp5 
     
    119119#define VT1211_REG_FAN(nr)     (0x28 + (nr)) 
    120120 
    121 static const u8 regtemp[] = { 0x20, 0x21, 0x1f, 0x22, 0x23, 0x24, 0x25 }; 
    122 static const u8 regover[] = { 0x39, 0x3d, 0x1d, 0x2b, 0x2d, 0x2f, 0x31 }; 
    123 static const u8 reghyst[] = { 0x3a, 0x3e, 0x1e, 0x2c, 0x2e, 0x30, 0x32 }; 
     121static const u8 regtemp[] = { 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25 }; 
     122static const u8 regover[] = { 0x39, 0x1d, 0x3d, 0x2b, 0x2d, 0x2f, 0x31 }; 
     123static const u8 reghyst[] = { 0x3a, 0x1e, 0x3e, 0x2c, 0x2e, 0x30, 0x32 }; 
    124124 
    125125/* temps numbered 1-7 */ 
     
    127127#define VT1211_REG_TEMP_OVER(nr)        (regover[(nr) - 1]) 
    128128#define VT1211_REG_TEMP_HYST(nr)        (reghyst[(nr) - 1]) 
    129 #define VT1211_REG_TEMP_LOW3  0x4b    /* bits 7-6 */ 
    130 #define VT1211_REG_TEMP_LOW2  0x49    /* bits 5-4 */ 
     129#define VT1211_REG_TEMP_LOW1  0x4b    /* bits 7-6 */ 
     130#define VT1211_REG_TEMP_LOW3  0x49    /* bits 5-4 */ 
    131131#define VT1211_REG_TEMP_LOW47   0x4d 
    132132 
     
    141141 
    142142/* temps 1-7; voltages 0-5 */ 
    143 #define ISTEMP(i, ch_config) ((i) == 1 ? 1 : \ 
    144                               (i) == 3 ? 1 : \ 
    145                               (i) == 2 ? ((ch_config) >> 1) & 0x01 : \ 
    146                                          ((ch_config) >> ((i)-1)) & 0x01) 
     143#define ISTEMP(i, ch_config) ((i) <= 2 ? 1 : \ 
     144                              ((ch_config) >> ((i)-1)) & 1) 
    147145#define ISVOLT(i, ch_config) ((i) > 4 ? 1 : !(((ch_config) >> ((i)+2)) & 0x01)) 
    148146 
     
    152150#define PWM_TO_REG(val) SENSORS_LIMIT((val), 0, 255) 
    153151 
    154 #define TEMP_FROM_REG(val) ((val)*10) 
    155 #define TEMP_FROM_REG10(val) (((val)*10)/4) 
    156 #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-5)/10):\ 
    157                                                  ((val)+5)/10),0,255)) 
    158 #define IN_FROM_REG(val) /*(((val)*10+5)/10)*/ (val) 
    159 #define IN_TO_REG(val)  (SENSORS_LIMIT((((val) * 10 + 5)/10),0,255)) 
    160  
     152/* temp1 (i = 1) is an Intel thermal diode which is scaled in user space. 
     153   temp2 (i = 2) is the internal temp diode so it's scaled in the driver 
     154   according to some measurements taken on an EPIA M10000. 
     155   temp3-7 are thermistor based so the driver returns the voltage measured at 
     156   the pin (range 0V - 2.2V). */ 
     157#define TEMP_FROM_REG(i, reg)   ((i) == 1 ? (reg) * 10 : \ 
     158                                 (i) == 2 ? (reg) < 51 ? 0 : \ 
     159                                 ((reg) - 51) * 10 : \ 
     160                                 ((253 - (reg)) * 2200 + 105) / 210) 
     161/* for 10-bit temp values */ 
     162#define TEMP_FROM_REG10(i, reg) ((i) == 1 ? (reg) * 10 / 4 : \ 
     163                                 (i) == 2 ? (reg) < 204 ? 0 : \ 
     164                                 ((reg) - 204) * 10 / 4 : \ 
     165                                 ((1012 - (reg)) * 550 + 105) / 210) 
     166#define TEMP_TO_REG(i, val)     SENSORS_LIMIT( \ 
     167                                 ((i) == 1 ? ((val) + 5) / 10 : \ 
     168                                  (i) == 2 ? ((val) + 5) / 10 + 51 : \ 
     169                                  253 - ((val) * 210 + 1100) / 2200), 0, 255) 
     170 
     171/* in5 (i = 5) is special. It's the internal 3.3V so it's scaled in the 
     172   driver according to the VT1211 BIOS porting guide */ 
     173#define IN_FROM_REG(i, reg)     ((reg) < 3 ? 0 : (i) == 5 ? \ 
     174                                 (((reg) - 3) * 15882 + 4790) / 9580 : \ 
     175                                 (((reg) - 3) * 10000 + 4790) / 9580) 
     176#define IN_TO_REG(i, val)       (SENSORS_LIMIT((i) == 5 ? \ 
     177                                 ((val) * 9580 + 7941) / 15882 + 3 : \ 
     178                                 ((val) * 9580 + 5000) / 10000 + 3, 0, 255)) 
    161179 
    162180/********* FAN RPM CONVERSIONS ********/ 
     
    271289#define VT1211_ALARM_FAN2 0x80 
    272290#define VT1211_ALARM_IN4 0x100 
    273 #define VT1211_ALARM_TEMP2 0x800 
     291#define VT1211_ALARM_TEMP3 0x800 
    274292#define VT1211_ALARM_CHAS 0x1000 
    275 #define VT1211_ALARM_TEMP3 0x8000 
     293#define VT1211_ALARM_TEMP2 0x8000 
    276294/* duplicates */ 
    277 #define VT1211_ALARM_IN0 VT1211_ALARM_TEMP2 
     295#define VT1211_ALARM_IN0 VT1211_ALARM_TEMP3 
    278296#define VT1211_ALARM_TEMP4 VT1211_ALARM_IN1 
    279297#define VT1211_ALARM_TEMP5 VT1211_ALARM_IN2 
     
    512530                                switch(i) { 
    513531                                        case 1: 
    514                                                 /* ? */ 
    515                                                 j = 0; 
     532                                                j = (vt_rdval(client, 
     533                                                  VT1211_REG_TEMP_LOW1) >> 
     534                                                        6) & 3; 
    516535                                                break; 
    517536                                        case 2: 
    518                                                 j = (vt_rdval(client, 
    519                                                   VT1211_REG_TEMP_LOW2) & 
    520                                                                     0x30) >> 4; 
     537                                                j = 0; 
    521538                                                break; 
    522539                                        case 3: 
    523540                                                j = (vt_rdval(client, 
    524                                                   VT1211_REG_TEMP_LOW3) & 
    525                                                                     0xc0) >> 6
     541                                                  VT1211_REG_TEMP_LOW3) >> 
     542                                                       4) & 3
    526543                                                break; 
    527                                         case 4: 
    528                                         case 5: 
    529                                         case 6: 
    530                                         case 7: 
    531544                                        default: 
    532545                                                j = (vt_rdval(client, 
    533546                                                  VT1211_REG_TEMP_LOW47) >> 
    534547                                                            ((i-4)*2)) & 0x03;   
    535                                                 break; 
    536          
    537548                                } 
    538549                                data->temp[i - 1] |= j; 
     
    580591        else if (operation == SENSORS_PROC_REAL_READ) { 
    581592                vt1211_update_client(client); 
    582                 results[0] = IN_FROM_REG(data->in_min[nr]); 
    583                 results[1] = IN_FROM_REG(data->in_max[nr]); 
    584                 results[2] = IN_FROM_REG(data->in[nr]); 
     593                results[0] = IN_FROM_REG(nr, data->in_min[nr]); 
     594                results[1] = IN_FROM_REG(nr, data->in_max[nr]); 
     595                results[2] = IN_FROM_REG(nr, data->in[nr]); 
    585596                *nrels_mag = 3; 
    586597        } else if (operation == SENSORS_PROC_REAL_WRITE) { 
    587598                if (*nrels_mag >= 1) { 
    588                         data->in_min[nr] = IN_TO_REG(results[0]); 
     599                        data->in_min[nr] = IN_TO_REG(nr, results[0]); 
    589600                        vt1211_write_value(client, VT1211_REG_IN_MIN(nr), 
    590601                                            data->in_min[nr]); 
    591602                } 
    592603                if (*nrels_mag >= 2) { 
    593                         data->in_max[nr] = IN_TO_REG(results[1]); 
     604                        data->in_max[nr] = IN_TO_REG(nr, results[1]); 
    594605                        vt1211_write_value(client, VT1211_REG_IN_MAX(nr), 
    595606                                            data->in_max[nr]); 
     
    634645 
    635646        if (operation == SENSORS_PROC_REAL_INFO) 
    636                 *nrels_mag = 1
     647                *nrels_mag = nr < 2 ? 1 : 3
    637648        else if (operation == SENSORS_PROC_REAL_READ) { 
    638649                vt1211_update_client(client); 
    639                 results[0] = TEMP_FROM_REG(data->temp_over[nr]); 
    640                 results[1] = TEMP_FROM_REG(data->temp_hyst[nr]); 
    641                 results[2] = TEMP_FROM_REG10(data->temp[nr]); 
     650                results[0] = TEMP_FROM_REG(nr + 1, data->temp_over[nr]); 
     651                results[1] = TEMP_FROM_REG(nr + 1, data->temp_hyst[nr]); 
     652                results[2] = TEMP_FROM_REG10(nr + 1, data->temp[nr]); 
    642653                *nrels_mag = 3; 
    643654        } else if (operation == SENSORS_PROC_REAL_WRITE) { 
    644655                if (*nrels_mag >= 1) { 
    645                         data->temp_over[nr] = TEMP_TO_REG(results[0]); 
     656                        data->temp_over[nr] = TEMP_TO_REG(nr + 1, results[0]); 
    646657                        vt1211_write_value(client, 
    647658                                            VT1211_REG_TEMP_OVER(nr + 1), 
     
    649660                } 
    650661                if (*nrels_mag >= 2) { 
    651                         data->temp_hyst[nr] = TEMP_TO_REG(results[1]); 
     662                        data->temp_hyst[nr] = TEMP_TO_REG(nr + 1, results[1]); 
    652663                        vt1211_write_value(client, 
    653664                                            VT1211_REG_TEMP_HYST(nr + 1),