Changeset 2496

Show
Ignore:
Timestamp:
04/30/04 19:37:09 (9 years ago)
Author:
khali
Message:

Simplify temperature conversions.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/kernel/chips/via686a.c

    r2478 r2496  
    270270}; 
    271271 
    272 /* Converting temps to (8-bit) hyst and over registers */ 
    273 // No interpolation here.  Just check the limits and go. 
    274 // The +5 effectively rounds off properly and the +50 is because  
    275 // the temps start at -50 
     272/* Converting temps to (8-bit) hyst and over registers 
     273   No interpolation here. 
     274   The +50 is because the temps start at -50 */ 
    276275static inline u8 TEMP_TO_REG(long val) 
    277276{ 
    278         return (u8) 
    279             SENSORS_LIMIT(viaLUT[((val <= -500) ? 0 : (val >= 1100) ? 160 :  
    280                                   ((val + 5) / 10 + 50))], 0, 255); 
     277        return viaLUT[val <= -500 ? 0 : val >= 1100 ? 160 :  
     278                      (val < 0 ? val - 5 : val + 5) / 10 + 50]; 
    281279} 
    282280 
    283281/* for 8-bit temperature hyst and over registers */ 
    284 // The temp values are already *10, so we don't need to do that. 
    285 // But we _will_ round these off to the nearest degree with (...*10+5)/10 
    286 #define TEMP_FROM_REG(val) ((tempLUT[(val)]*10+5)/10) 
     282#define TEMP_FROM_REG(val) (tempLUT[(val)]) 
    287283 
    288284/* for 10-bit temperature readings */ 
     
    296292        u16 twoBits = val & 3; 
    297293 
    298         // handle the extremes first (they won't interpolate well! ;-) 
    299         if (val == 0) 
    300                 return (long) tempLUT[0]; 
    301         if (val == 1023) 
    302                 return (long) tempLUT[255]; 
    303  
    304         if (twoBits == 0) 
     294        /* no interpolation for these */ 
     295        if (twoBits == 0 || eightBits == 255) 
    305296                return (long) tempLUT[eightBits]; 
    306         else { 
    307                 // do some interpolation by multipying the lower and upper 
    308                 // bounds by 25, 50 or 75, then /100. 
    309                 temp = ((25 * (4 - twoBits)) * tempLUT[eightBits] 
    310                         + (25 * twoBits) * tempLUT[eightBits + 1]); 
    311                 // increase the magnitude by 50 to achieve rounding. 
    312                 if (temp > 0) 
    313                         temp += 50; 
    314                 else 
    315                         temp -= 50; 
    316                 return (temp / 100); 
    317         } 
     297 
     298        /* do some linear interpolation */ 
     299        temp = (4 - twoBits) * tempLUT[eightBits] 
     300             + twoBits * tempLUT[eightBits + 1]; 
     301        /* achieve rounding */ 
     302        return (temp < 0 ? temp - 2 : temp + 2) / 4; 
    318303} 
    319304