Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hwmon: (it87) Move conversion functions

Move conversion functions until after structure defintions. This is
needed for future changes which make use of the structures in the
conversion funtcions.

Signed-off-by: Jean Delvare <khali@linux-fr.org>

authored by

Jean Delvare and committed by
Jean Delvare
0df6454d 0b22ce3b

+52 -50
+52 -50
drivers/hwmon/it87.c
··· 202 202 #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i)) 203 203 #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i)) 204 204 205 - #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255)) 206 - #define IN_FROM_REG(val) ((val) * 16) 207 - 208 - static inline u8 FAN_TO_REG(long rpm, int div) 209 - { 210 - if (rpm == 0) 211 - return 255; 212 - rpm = SENSORS_LIMIT(rpm, 1, 1000000); 213 - return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 214 - 254); 215 - } 216 - 217 - static inline u16 FAN16_TO_REG(long rpm) 218 - { 219 - if (rpm == 0) 220 - return 0xffff; 221 - return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe); 222 - } 223 - 224 - #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) 225 - /* The divider is fixed to 2 in 16-bit mode */ 226 - #define FAN16_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:1350000/((val)*2)) 227 - 228 - #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\ 229 - ((val)+500)/1000),-128,127)) 230 - #define TEMP_FROM_REG(val) ((val) * 1000) 231 - 232 - #define PWM_TO_REG(val) ((val) >> 1) 233 - #define PWM_FROM_REG(val) (((val)&0x7f) << 1) 234 - 235 - static int DIV_TO_REG(int val) 236 - { 237 - int answer = 0; 238 - while (answer < 7 && (val >>= 1)) 239 - answer++; 240 - return answer; 241 - } 242 - #define DIV_FROM_REG(val) (1 << (val)) 243 - 244 - static const unsigned int pwm_freq[8] = { 245 - 48000000 / 128, 246 - 24000000 / 128, 247 - 12000000 / 128, 248 - 8000000 / 128, 249 - 6000000 / 128, 250 - 3000000 / 128, 251 - 1500000 / 128, 252 - 750000 / 128, 253 - }; 254 - 255 205 256 206 struct it87_sio_data { 257 207 enum chips type; ··· 258 308 /* Automatic fan speed control registers */ 259 309 u8 auto_pwm[3][4]; /* [nr][3] is hard-coded */ 260 310 s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */ 311 + }; 312 + 313 + #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8) / 16), 0, 255)) 314 + #define IN_FROM_REG(val) ((val) * 16) 315 + 316 + static inline u8 FAN_TO_REG(long rpm, int div) 317 + { 318 + if (rpm == 0) 319 + return 255; 320 + rpm = SENSORS_LIMIT(rpm, 1, 1000000); 321 + return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, 322 + 254); 323 + } 324 + 325 + static inline u16 FAN16_TO_REG(long rpm) 326 + { 327 + if (rpm == 0) 328 + return 0xffff; 329 + return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe); 330 + } 331 + 332 + #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \ 333 + 1350000 / ((val) * (div))) 334 + /* The divider is fixed to 2 in 16-bit mode */ 335 + #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \ 336 + 1350000 / ((val) * 2)) 337 + 338 + #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (((val) - 500) / 1000) : \ 339 + ((val) + 500) / 1000), -128, 127)) 340 + #define TEMP_FROM_REG(val) ((val) * 1000) 341 + 342 + #define PWM_TO_REG(val) ((val) >> 1) 343 + #define PWM_FROM_REG(val) (((val) & 0x7f) << 1) 344 + 345 + static int DIV_TO_REG(int val) 346 + { 347 + int answer = 0; 348 + while (answer < 7 && (val >>= 1)) 349 + answer++; 350 + return answer; 351 + } 352 + #define DIV_FROM_REG(val) (1 << (val)) 353 + 354 + static const unsigned int pwm_freq[8] = { 355 + 48000000 / 128, 356 + 24000000 / 128, 357 + 12000000 / 128, 358 + 8000000 / 128, 359 + 6000000 / 128, 360 + 3000000 / 128, 361 + 1500000 / 128, 362 + 750000 / 128, 261 363 }; 262 364 263 365 static inline int has_16bit_fans(const struct it87_data *data)