diff options
author | Jean Delvare <khali@linux-fr.org> | 2010-10-28 14:31:51 -0400 |
---|---|---|
committer | Jean Delvare <khali@endymion.delvare> | 2010-10-28 14:31:51 -0400 |
commit | 0df6454da937548594774788b009616ed27607ed (patch) | |
tree | af7ccc62c7d0732dc5934059f959c0b31d34b3ec /drivers/hwmon/it87.c | |
parent | 0b22ce3b7de718882e2c2ca979490a50d798a838 (diff) |
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>
Diffstat (limited to 'drivers/hwmon/it87.c')
-rw-r--r-- | drivers/hwmon/it87.c | 102 |
1 files changed, 52 insertions, 50 deletions
diff --git a/drivers/hwmon/it87.c b/drivers/hwmon/it87.c index f7701295937d..7a3616ccbf05 100644 --- a/drivers/hwmon/it87.c +++ b/drivers/hwmon/it87.c | |||
@@ -202,56 +202,6 @@ static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 }; | |||
202 | #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i)) | 202 | #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i)) |
203 | #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i)) | 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 | struct it87_sio_data { | 206 | struct it87_sio_data { |
257 | enum chips type; | 207 | enum chips type; |
@@ -310,6 +260,58 @@ struct it87_data { | |||
310 | s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */ | 260 | s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */ |
311 | }; | 261 | }; |
312 | 262 | ||
263 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8) / 16), 0, 255)) | ||
264 | #define IN_FROM_REG(val) ((val) * 16) | ||
265 | |||
266 | static inline u8 FAN_TO_REG(long rpm, int div) | ||
267 | { | ||
268 | if (rpm == 0) | ||
269 | return 255; | ||
270 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); | ||
271 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, | ||
272 | 254); | ||
273 | } | ||
274 | |||
275 | static inline u16 FAN16_TO_REG(long rpm) | ||
276 | { | ||
277 | if (rpm == 0) | ||
278 | return 0xffff; | ||
279 | return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe); | ||
280 | } | ||
281 | |||
282 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \ | ||
283 | 1350000 / ((val) * (div))) | ||
284 | /* The divider is fixed to 2 in 16-bit mode */ | ||
285 | #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \ | ||
286 | 1350000 / ((val) * 2)) | ||
287 | |||
288 | #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (((val) - 500) / 1000) : \ | ||
289 | ((val) + 500) / 1000), -128, 127)) | ||
290 | #define TEMP_FROM_REG(val) ((val) * 1000) | ||
291 | |||
292 | #define PWM_TO_REG(val) ((val) >> 1) | ||
293 | #define PWM_FROM_REG(val) (((val) & 0x7f) << 1) | ||
294 | |||
295 | static int DIV_TO_REG(int val) | ||
296 | { | ||
297 | int answer = 0; | ||
298 | while (answer < 7 && (val >>= 1)) | ||
299 | answer++; | ||
300 | return answer; | ||
301 | } | ||
302 | #define DIV_FROM_REG(val) (1 << (val)) | ||
303 | |||
304 | static const unsigned int pwm_freq[8] = { | ||
305 | 48000000 / 128, | ||
306 | 24000000 / 128, | ||
307 | 12000000 / 128, | ||
308 | 8000000 / 128, | ||
309 | 6000000 / 128, | ||
310 | 3000000 / 128, | ||
311 | 1500000 / 128, | ||
312 | 750000 / 128, | ||
313 | }; | ||
314 | |||
313 | static inline int has_16bit_fans(const struct it87_data *data) | 315 | static inline int has_16bit_fans(const struct it87_data *data) |
314 | { | 316 | { |
315 | /* IT8705F Datasheet 0.4.1, 3h == Version G. | 317 | /* IT8705F Datasheet 0.4.1, 3h == Version G. |