Changeset 2458 for lm-sensors/trunk/kernel/chips/via686a.c
- Timestamp:
- 04/20/04 19:12:55 (9 years ago)
- Files:
-
- 1 modified
-
lm-sensors/trunk/kernel/chips/via686a.c (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lm-sensors/trunk/kernel/chips/via686a.c
r2445 r2458 126 126 // (These conversions were contributed by Jonathan Teh Soon Yew 127 127 // <j.teh@iname.com>) 128 //129 // These get us close, but they don't completely agree with what my BIOS130 // says- they are all a bit low. But, it all we have to go on...131 128 static inline u8 IN_TO_REG(long val, int inNum) 132 129 { 133 // to avoid floating point, we multiply everything by 100. 134 // val is guaranteed to be positive, so we can achieve the effect of 135 // rounding by (...*10+5)/10. Note that the *10 is hidden in the 136 // /250 (which should really be /2500). 137 // At the end, we need to /100 because we *100 everything and we need 138 // to /10 because of the rounding thing, so we /1000. 130 /* To avoid floating point, we multiply constants by 10 (100 for +12V). 131 Rounding is done (1205000 is actually 1330000 - 125000). 132 Remember that val is expressed in 0.01V/bit, which is why we divide 133 by an additional 1000 (10000 for +12V): 100 for val and 10 (100) 134 for the constants. */ 139 135 if (inNum <= 1) 140 136 return (u8) 141 SENSORS_LIMIT(((val * 210240 - 13300) / 250 + 5) / 1000, 142 0, 255); 137 SENSORS_LIMIT((val * 21024 - 1205000) / 250000, 0, 255); 143 138 else if (inNum == 2) 144 139 return (u8) 145 SENSORS_LIMIT(((val * 157370 - 13300) / 250 + 5) / 1000, 146 0, 255); 140 SENSORS_LIMIT((val * 15737 - 1205000) / 250000, 0, 255); 147 141 else if (inNum == 3) 148 142 return (u8) 149 SENSORS_LIMIT(((val * 101080 - 13300) / 250 + 5) / 1000, 150 0, 255); 143 SENSORS_LIMIT((val * 10108 - 1205000) / 250000, 0, 255); 151 144 else 152 return (u8) SENSORS_LIMIT(((val * 41714 - 13300) / 250 + 5)153 / 1000, 0, 255);145 return (u8) 146 SENSORS_LIMIT((val * 41714 - 12050000) / 2500000, 0, 255); 154 147 } 155 148 156 149 static inline long IN_FROM_REG(u8 val, int inNum) 157 150 { 158 // to avoid floating point, we multiply everything by 100. 159 // val is guaranteed to be positive, so we can achieve the effect of 160 // rounding by adding 0.5. Or, to avoid fp math, we do (...*10+5)/10. 161 // We need to scale with *100 anyway, so no need to /100 at the end. 151 /* To avoid floating point, we multiply constants by 10 (100 for +12V). 152 We also multiply them by 100 because we want 0.01V/bit for the 153 output value. Rounding is done. */ 162 154 if (inNum <= 1) 163 return (long) (( (250000 * val + 13300) / 210240 * 10 + 5) /10);155 return (long) ((25000 * val + 133000 + 21024 / 2) / 21024); 164 156 else if (inNum == 2) 165 return (long) (( (250000 * val + 13300) / 157370 * 10 + 5) /10);157 return (long) ((25000 * val + 133000 + 15737 / 2) / 15737); 166 158 else if (inNum == 3) 167 return (long) (( (250000 * val + 13300) / 101080 * 10 + 5) /10);159 return (long) ((25000 * val + 133000 + 10108 / 2) / 10108); 168 160 else 169 return (long) (( (250000 * val + 13300) / 41714 * 10 + 5) /10);161 return (long) ((250000 * val + 1330000 + 41714 / 2) / 41714); 170 162 } 171 163
