2 it87.c - Part of lm_sensors, Linux kernel modules for hardware
5 Supports: IT8705F Super I/O chip w/LPC interface
6 IT8712F Super I/O chip w/LPC interface & SMBus
7 IT8716F Super I/O chip w/LPC interface
8 IT8718F Super I/O chip w/LPC interface
9 Sis950 A clone of the IT8705F
11 Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com>
12 Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org>
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 2 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program; if not, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <linux/module.h>
30 #include <linux/init.h>
31 #include <linux/slab.h>
32 #include <linux/jiffies.h>
33 #include <linux/i2c.h>
34 #include <linux/i2c-isa.h>
35 #include <linux/hwmon.h>
36 #include <linux/hwmon-sysfs.h>
37 #include <linux/hwmon-vid.h>
38 #include <linux/err.h>
39 #include <linux/mutex.h>
43 /* Addresses to scan */
44 static unsigned short normal_i2c
[] = { 0x2d, I2C_CLIENT_END
};
45 static unsigned short isa_address
;
47 /* Insmod parameters */
48 I2C_CLIENT_INSMOD_4(it87
, it8712
, it8716
, it8718
);
50 #define REG 0x2e /* The register to read/write */
51 #define DEV 0x07 /* Register: Logical device select */
52 #define VAL 0x2f /* The value to read/write */
53 #define PME 0x04 /* The device with the fan registers in it */
54 #define GPIO 0x07 /* The device with the IT8718F VID value in it */
55 #define DEVID 0x20 /* Register: Device ID */
56 #define DEVREV 0x22 /* Register: Device Revision */
65 static int superio_inw(int reg
)
76 superio_select(int ldn
)
98 /* Logical device 4 registers */
99 #define IT8712F_DEVID 0x8712
100 #define IT8705F_DEVID 0x8705
101 #define IT8716F_DEVID 0x8716
102 #define IT8718F_DEVID 0x8718
103 #define IT87_ACT_REG 0x30
104 #define IT87_BASE_REG 0x60
106 /* Logical device 7 registers (IT8712F and later) */
107 #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
108 #define IT87_SIO_VID_REG 0xfc /* VID value */
110 /* Update battery voltage after every reading if true */
111 static int update_vbat
;
113 /* Not all BIOSes properly configure the PWM registers */
114 static int fix_pwm_polarity
;
116 /* Values read from Super-I/O config space */
117 static u16 chip_type
;
120 /* Many IT87 constants specified below */
122 /* Length of ISA address segment */
123 #define IT87_EXTENT 8
125 /* Where are the ISA address/data registers relative to the base address */
126 #define IT87_ADDR_REG_OFFSET 5
127 #define IT87_DATA_REG_OFFSET 6
129 /*----- The IT87 registers -----*/
131 #define IT87_REG_CONFIG 0x00
133 #define IT87_REG_ALARM1 0x01
134 #define IT87_REG_ALARM2 0x02
135 #define IT87_REG_ALARM3 0x03
137 /* The IT8718F has the VID value in a different register, in Super-I/O
138 configuration space. */
139 #define IT87_REG_VID 0x0a
140 /* Warning: register 0x0b is used for something completely different in
141 new chips/revisions. I suspect only 16-bit tachometer mode will work
143 #define IT87_REG_FAN_DIV 0x0b
144 #define IT87_REG_FAN_16BIT 0x0c
146 /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
148 #define IT87_REG_FAN(nr) (0x0d + (nr))
149 #define IT87_REG_FAN_MIN(nr) (0x10 + (nr))
150 #define IT87_REG_FANX(nr) (0x18 + (nr))
151 #define IT87_REG_FANX_MIN(nr) (0x1b + (nr))
152 #define IT87_REG_FAN_MAIN_CTRL 0x13
153 #define IT87_REG_FAN_CTL 0x14
154 #define IT87_REG_PWM(nr) (0x15 + (nr))
156 #define IT87_REG_VIN(nr) (0x20 + (nr))
157 #define IT87_REG_TEMP(nr) (0x29 + (nr))
159 #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
160 #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
161 #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
162 #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
164 #define IT87_REG_I2C_ADDR 0x48
166 #define IT87_REG_VIN_ENABLE 0x50
167 #define IT87_REG_TEMP_ENABLE 0x51
169 #define IT87_REG_CHIPID 0x58
171 #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255))
172 #define IN_FROM_REG(val) ((val) * 16)
174 static inline u8
FAN_TO_REG(long rpm
, int div
)
178 rpm
= SENSORS_LIMIT(rpm
, 1, 1000000);
179 return SENSORS_LIMIT((1350000 + rpm
* div
/ 2) / (rpm
* div
), 1,
183 static inline u16
FAN16_TO_REG(long rpm
)
187 return SENSORS_LIMIT((1350000 + rpm
) / (rpm
* 2), 1, 0xfffe);
190 #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
191 /* The divider is fixed to 2 in 16-bit mode */
192 #define FAN16_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:1350000/((val)*2))
194 #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\
195 ((val)+500)/1000),-128,127))
196 #define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*1000)
198 #define PWM_TO_REG(val) ((val) >> 1)
199 #define PWM_FROM_REG(val) (((val)&0x7f) << 1)
201 static int DIV_TO_REG(int val
)
204 while (answer
< 7 && (val
>>= 1))
208 #define DIV_FROM_REG(val) (1 << (val))
211 /* For each registered IT87, we need to keep some data in memory. That
212 data is pointed to by it87_list[NR]->data. The structure itself is
213 dynamically allocated, at the same time when a new it87 client is
216 struct i2c_client client
;
217 struct class_device
*class_dev
;
221 struct mutex update_lock
;
222 char valid
; /* !=0 if following fields are valid */
223 unsigned long last_updated
; /* In jiffies */
225 u8 in
[9]; /* Register value */
226 u8 in_max
[8]; /* Register value */
227 u8 in_min
[8]; /* Register value */
228 u8 has_fan
; /* Bitfield, fans enabled */
229 u16 fan
[3]; /* Register values, possibly combined */
230 u16 fan_min
[3]; /* Register values, possibly combined */
231 u8 temp
[3]; /* Register value */
232 u8 temp_high
[3]; /* Register value */
233 u8 temp_low
[3]; /* Register value */
234 u8 sensor
; /* Register value */
235 u8 fan_div
[3]; /* Register encoding, shifted right */
236 u8 vid
; /* Register encoding, combined */
238 u32 alarms
; /* Register encoding, combined */
239 u8 fan_main_ctrl
; /* Register value */
240 u8 manual_pwm_ctl
[3]; /* manual PWM value set by user */
244 static int it87_attach_adapter(struct i2c_adapter
*adapter
);
245 static int it87_isa_attach_adapter(struct i2c_adapter
*adapter
);
246 static int it87_detect(struct i2c_adapter
*adapter
, int address
, int kind
);
247 static int it87_detach_client(struct i2c_client
*client
);
249 static int it87_read_value(struct i2c_client
*client
, u8 reg
);
250 static int it87_write_value(struct i2c_client
*client
, u8 reg
, u8 value
);
251 static struct it87_data
*it87_update_device(struct device
*dev
);
252 static int it87_check_pwm(struct i2c_client
*client
);
253 static void it87_init_client(struct i2c_client
*client
, struct it87_data
*data
);
256 static struct i2c_driver it87_driver
= {
260 .id
= I2C_DRIVERID_IT87
,
261 .attach_adapter
= it87_attach_adapter
,
262 .detach_client
= it87_detach_client
,
265 static struct i2c_driver it87_isa_driver
= {
267 .owner
= THIS_MODULE
,
270 .attach_adapter
= it87_isa_attach_adapter
,
271 .detach_client
= it87_detach_client
,
275 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*attr
,
278 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
279 int nr
= sensor_attr
->index
;
281 struct it87_data
*data
= it87_update_device(dev
);
282 return sprintf(buf
, "%d\n", IN_FROM_REG(data
->in
[nr
]));
285 static ssize_t
show_in_min(struct device
*dev
, struct device_attribute
*attr
,
288 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
289 int nr
= sensor_attr
->index
;
291 struct it87_data
*data
= it87_update_device(dev
);
292 return sprintf(buf
, "%d\n", IN_FROM_REG(data
->in_min
[nr
]));
295 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
*attr
,
298 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
299 int nr
= sensor_attr
->index
;
301 struct it87_data
*data
= it87_update_device(dev
);
302 return sprintf(buf
, "%d\n", IN_FROM_REG(data
->in_max
[nr
]));
305 static ssize_t
set_in_min(struct device
*dev
, struct device_attribute
*attr
,
306 const char *buf
, size_t count
)
308 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
309 int nr
= sensor_attr
->index
;
311 struct i2c_client
*client
= to_i2c_client(dev
);
312 struct it87_data
*data
= i2c_get_clientdata(client
);
313 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
315 mutex_lock(&data
->update_lock
);
316 data
->in_min
[nr
] = IN_TO_REG(val
);
317 it87_write_value(client
, IT87_REG_VIN_MIN(nr
),
319 mutex_unlock(&data
->update_lock
);
322 static ssize_t
set_in_max(struct device
*dev
, struct device_attribute
*attr
,
323 const char *buf
, size_t count
)
325 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
326 int nr
= sensor_attr
->index
;
328 struct i2c_client
*client
= to_i2c_client(dev
);
329 struct it87_data
*data
= i2c_get_clientdata(client
);
330 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
332 mutex_lock(&data
->update_lock
);
333 data
->in_max
[nr
] = IN_TO_REG(val
);
334 it87_write_value(client
, IT87_REG_VIN_MAX(nr
),
336 mutex_unlock(&data
->update_lock
);
340 #define show_in_offset(offset) \
341 static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
342 show_in, NULL, offset);
344 #define limit_in_offset(offset) \
345 static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
346 show_in_min, set_in_min, offset); \
347 static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
348 show_in_max, set_in_max, offset);
369 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*attr
,
372 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
373 int nr
= sensor_attr
->index
;
375 struct it87_data
*data
= it87_update_device(dev
);
376 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp
[nr
]));
378 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
*attr
,
381 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
382 int nr
= sensor_attr
->index
;
384 struct it87_data
*data
= it87_update_device(dev
);
385 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_high
[nr
]));
387 static ssize_t
show_temp_min(struct device
*dev
, struct device_attribute
*attr
,
390 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
391 int nr
= sensor_attr
->index
;
393 struct it87_data
*data
= it87_update_device(dev
);
394 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_low
[nr
]));
396 static ssize_t
set_temp_max(struct device
*dev
, struct device_attribute
*attr
,
397 const char *buf
, size_t count
)
399 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
400 int nr
= sensor_attr
->index
;
402 struct i2c_client
*client
= to_i2c_client(dev
);
403 struct it87_data
*data
= i2c_get_clientdata(client
);
404 int val
= simple_strtol(buf
, NULL
, 10);
406 mutex_lock(&data
->update_lock
);
407 data
->temp_high
[nr
] = TEMP_TO_REG(val
);
408 it87_write_value(client
, IT87_REG_TEMP_HIGH(nr
), data
->temp_high
[nr
]);
409 mutex_unlock(&data
->update_lock
);
412 static ssize_t
set_temp_min(struct device
*dev
, struct device_attribute
*attr
,
413 const char *buf
, size_t count
)
415 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
416 int nr
= sensor_attr
->index
;
418 struct i2c_client
*client
= to_i2c_client(dev
);
419 struct it87_data
*data
= i2c_get_clientdata(client
);
420 int val
= simple_strtol(buf
, NULL
, 10);
422 mutex_lock(&data
->update_lock
);
423 data
->temp_low
[nr
] = TEMP_TO_REG(val
);
424 it87_write_value(client
, IT87_REG_TEMP_LOW(nr
), data
->temp_low
[nr
]);
425 mutex_unlock(&data
->update_lock
);
428 #define show_temp_offset(offset) \
429 static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
430 show_temp, NULL, offset - 1); \
431 static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
432 show_temp_max, set_temp_max, offset - 1); \
433 static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
434 show_temp_min, set_temp_min, offset - 1);
440 static ssize_t
show_sensor(struct device
*dev
, struct device_attribute
*attr
,
443 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
444 int nr
= sensor_attr
->index
;
446 struct it87_data
*data
= it87_update_device(dev
);
447 u8 reg
= data
->sensor
; /* In case the value is updated while we use it */
450 return sprintf(buf
, "3\n"); /* thermal diode */
452 return sprintf(buf
, "2\n"); /* thermistor */
453 return sprintf(buf
, "0\n"); /* disabled */
455 static ssize_t
set_sensor(struct device
*dev
, struct device_attribute
*attr
,
456 const char *buf
, size_t count
)
458 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
459 int nr
= sensor_attr
->index
;
461 struct i2c_client
*client
= to_i2c_client(dev
);
462 struct it87_data
*data
= i2c_get_clientdata(client
);
463 int val
= simple_strtol(buf
, NULL
, 10);
465 mutex_lock(&data
->update_lock
);
467 data
->sensor
&= ~(1 << nr
);
468 data
->sensor
&= ~(8 << nr
);
469 /* 3 = thermal diode; 2 = thermistor; 0 = disabled */
471 data
->sensor
|= 1 << nr
;
473 data
->sensor
|= 8 << nr
;
475 mutex_unlock(&data
->update_lock
);
478 it87_write_value(client
, IT87_REG_TEMP_ENABLE
, data
->sensor
);
479 mutex_unlock(&data
->update_lock
);
482 #define show_sensor_offset(offset) \
483 static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
484 show_sensor, set_sensor, offset - 1);
486 show_sensor_offset(1);
487 show_sensor_offset(2);
488 show_sensor_offset(3);
491 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*attr
,
494 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
495 int nr
= sensor_attr
->index
;
497 struct it87_data
*data
= it87_update_device(dev
);
498 return sprintf(buf
,"%d\n", FAN_FROM_REG(data
->fan
[nr
],
499 DIV_FROM_REG(data
->fan_div
[nr
])));
501 static ssize_t
show_fan_min(struct device
*dev
, struct device_attribute
*attr
,
504 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
505 int nr
= sensor_attr
->index
;
507 struct it87_data
*data
= it87_update_device(dev
);
508 return sprintf(buf
,"%d\n",
509 FAN_FROM_REG(data
->fan_min
[nr
], DIV_FROM_REG(data
->fan_div
[nr
])));
511 static ssize_t
show_fan_div(struct device
*dev
, struct device_attribute
*attr
,
514 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
515 int nr
= sensor_attr
->index
;
517 struct it87_data
*data
= it87_update_device(dev
);
518 return sprintf(buf
, "%d\n", DIV_FROM_REG(data
->fan_div
[nr
]));
520 static ssize_t
show_pwm_enable(struct device
*dev
, struct device_attribute
*attr
,
523 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
524 int nr
= sensor_attr
->index
;
526 struct it87_data
*data
= it87_update_device(dev
);
527 return sprintf(buf
,"%d\n", (data
->fan_main_ctrl
& (1 << nr
)) ? 1 : 0);
529 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
*attr
,
532 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
533 int nr
= sensor_attr
->index
;
535 struct it87_data
*data
= it87_update_device(dev
);
536 return sprintf(buf
,"%d\n", data
->manual_pwm_ctl
[nr
]);
538 static ssize_t
set_fan_min(struct device
*dev
, struct device_attribute
*attr
,
539 const char *buf
, size_t count
)
541 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
542 int nr
= sensor_attr
->index
;
544 struct i2c_client
*client
= to_i2c_client(dev
);
545 struct it87_data
*data
= i2c_get_clientdata(client
);
546 int val
= simple_strtol(buf
, NULL
, 10);
547 u8 reg
= it87_read_value(client
, IT87_REG_FAN_DIV
);
549 mutex_lock(&data
->update_lock
);
551 case 0: data
->fan_div
[nr
] = reg
& 0x07; break;
552 case 1: data
->fan_div
[nr
] = (reg
>> 3) & 0x07; break;
553 case 2: data
->fan_div
[nr
] = (reg
& 0x40) ? 3 : 1; break;
556 data
->fan_min
[nr
] = FAN_TO_REG(val
, DIV_FROM_REG(data
->fan_div
[nr
]));
557 it87_write_value(client
, IT87_REG_FAN_MIN(nr
), data
->fan_min
[nr
]);
558 mutex_unlock(&data
->update_lock
);
561 static ssize_t
set_fan_div(struct device
*dev
, struct device_attribute
*attr
,
562 const char *buf
, size_t count
)
564 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
565 int nr
= sensor_attr
->index
;
567 struct i2c_client
*client
= to_i2c_client(dev
);
568 struct it87_data
*data
= i2c_get_clientdata(client
);
569 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
573 mutex_lock(&data
->update_lock
);
574 old
= it87_read_value(client
, IT87_REG_FAN_DIV
);
576 /* Save fan min limit */
577 min
= FAN_FROM_REG(data
->fan_min
[nr
], DIV_FROM_REG(data
->fan_div
[nr
]));
582 data
->fan_div
[nr
] = DIV_TO_REG(val
);
586 data
->fan_div
[nr
] = 1;
588 data
->fan_div
[nr
] = 3;
591 val
|= (data
->fan_div
[0] & 0x07);
592 val
|= (data
->fan_div
[1] & 0x07) << 3;
593 if (data
->fan_div
[2] == 3)
595 it87_write_value(client
, IT87_REG_FAN_DIV
, val
);
597 /* Restore fan min limit */
598 data
->fan_min
[nr
] = FAN_TO_REG(min
, DIV_FROM_REG(data
->fan_div
[nr
]));
599 it87_write_value(client
, IT87_REG_FAN_MIN(nr
), data
->fan_min
[nr
]);
601 mutex_unlock(&data
->update_lock
);
604 static ssize_t
set_pwm_enable(struct device
*dev
,
605 struct device_attribute
*attr
, const char *buf
, size_t count
)
607 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
608 int nr
= sensor_attr
->index
;
610 struct i2c_client
*client
= to_i2c_client(dev
);
611 struct it87_data
*data
= i2c_get_clientdata(client
);
612 int val
= simple_strtol(buf
, NULL
, 10);
614 mutex_lock(&data
->update_lock
);
618 /* make sure the fan is on when in on/off mode */
619 tmp
= it87_read_value(client
, IT87_REG_FAN_CTL
);
620 it87_write_value(client
, IT87_REG_FAN_CTL
, tmp
| (1 << nr
));
621 /* set on/off mode */
622 data
->fan_main_ctrl
&= ~(1 << nr
);
623 it87_write_value(client
, IT87_REG_FAN_MAIN_CTRL
, data
->fan_main_ctrl
);
624 } else if (val
== 1) {
625 /* set SmartGuardian mode */
626 data
->fan_main_ctrl
|= (1 << nr
);
627 it87_write_value(client
, IT87_REG_FAN_MAIN_CTRL
, data
->fan_main_ctrl
);
628 /* set saved pwm value, clear FAN_CTLX PWM mode bit */
629 it87_write_value(client
, IT87_REG_PWM(nr
), PWM_TO_REG(data
->manual_pwm_ctl
[nr
]));
631 mutex_unlock(&data
->update_lock
);
635 mutex_unlock(&data
->update_lock
);
638 static ssize_t
set_pwm(struct device
*dev
, struct device_attribute
*attr
,
639 const char *buf
, size_t count
)
641 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
642 int nr
= sensor_attr
->index
;
644 struct i2c_client
*client
= to_i2c_client(dev
);
645 struct it87_data
*data
= i2c_get_clientdata(client
);
646 int val
= simple_strtol(buf
, NULL
, 10);
648 if (val
< 0 || val
> 255)
651 mutex_lock(&data
->update_lock
);
652 data
->manual_pwm_ctl
[nr
] = val
;
653 if (data
->fan_main_ctrl
& (1 << nr
))
654 it87_write_value(client
, IT87_REG_PWM(nr
), PWM_TO_REG(data
->manual_pwm_ctl
[nr
]));
655 mutex_unlock(&data
->update_lock
);
659 #define show_fan_offset(offset) \
660 static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
661 show_fan, NULL, offset - 1); \
662 static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
663 show_fan_min, set_fan_min, offset - 1); \
664 static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
665 show_fan_div, set_fan_div, offset - 1);
671 #define show_pwm_offset(offset) \
672 static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
673 show_pwm_enable, set_pwm_enable, offset - 1); \
674 static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
675 show_pwm, set_pwm, offset - 1);
681 /* A different set of callbacks for 16-bit fans */
682 static ssize_t
show_fan16(struct device
*dev
, struct device_attribute
*attr
,
685 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
686 int nr
= sensor_attr
->index
;
687 struct it87_data
*data
= it87_update_device(dev
);
688 return sprintf(buf
, "%d\n", FAN16_FROM_REG(data
->fan
[nr
]));
691 static ssize_t
show_fan16_min(struct device
*dev
, struct device_attribute
*attr
,
694 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
695 int nr
= sensor_attr
->index
;
696 struct it87_data
*data
= it87_update_device(dev
);
697 return sprintf(buf
, "%d\n", FAN16_FROM_REG(data
->fan_min
[nr
]));
700 static ssize_t
set_fan16_min(struct device
*dev
, struct device_attribute
*attr
,
701 const char *buf
, size_t count
)
703 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
704 int nr
= sensor_attr
->index
;
705 struct i2c_client
*client
= to_i2c_client(dev
);
706 struct it87_data
*data
= i2c_get_clientdata(client
);
707 int val
= simple_strtol(buf
, NULL
, 10);
709 mutex_lock(&data
->update_lock
);
710 data
->fan_min
[nr
] = FAN16_TO_REG(val
);
711 it87_write_value(client
, IT87_REG_FAN_MIN(nr
),
712 data
->fan_min
[nr
] & 0xff);
713 it87_write_value(client
, IT87_REG_FANX_MIN(nr
),
714 data
->fan_min
[nr
] >> 8);
715 mutex_unlock(&data
->update_lock
);
719 /* We want to use the same sysfs file names as 8-bit fans, but we need
720 different variable names, so we have to use SENSOR_ATTR instead of
721 SENSOR_DEVICE_ATTR. */
722 #define show_fan16_offset(offset) \
723 static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
724 = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
725 show_fan16, NULL, offset - 1); \
726 static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \
727 = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
728 show_fan16_min, set_fan16_min, offset - 1)
730 show_fan16_offset(1);
731 show_fan16_offset(2);
732 show_fan16_offset(3);
735 static ssize_t
show_alarms(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
737 struct it87_data
*data
= it87_update_device(dev
);
738 return sprintf(buf
, "%u\n", data
->alarms
);
740 static DEVICE_ATTR(alarms
, S_IRUGO
, show_alarms
, NULL
);
743 show_vrm_reg(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
745 struct it87_data
*data
= it87_update_device(dev
);
746 return sprintf(buf
, "%u\n", data
->vrm
);
749 store_vrm_reg(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
751 struct i2c_client
*client
= to_i2c_client(dev
);
752 struct it87_data
*data
= i2c_get_clientdata(client
);
755 val
= simple_strtoul(buf
, NULL
, 10);
760 static DEVICE_ATTR(vrm
, S_IRUGO
| S_IWUSR
, show_vrm_reg
, store_vrm_reg
);
761 #define device_create_file_vrm(client) \
762 device_create_file(&client->dev, &dev_attr_vrm)
765 show_vid_reg(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
767 struct it87_data
*data
= it87_update_device(dev
);
768 return sprintf(buf
, "%ld\n", (long) vid_from_reg(data
->vid
, data
->vrm
));
770 static DEVICE_ATTR(cpu0_vid
, S_IRUGO
, show_vid_reg
, NULL
);
771 #define device_create_file_vid(client) \
772 device_create_file(&client->dev, &dev_attr_cpu0_vid)
774 /* This function is called when:
775 * it87_driver is inserted (when this module is loaded), for each
777 * when a new adapter is inserted (and it87_driver is still present) */
778 static int it87_attach_adapter(struct i2c_adapter
*adapter
)
780 if (!(adapter
->class & I2C_CLASS_HWMON
))
782 return i2c_probe(adapter
, &addr_data
, it87_detect
);
785 static int it87_isa_attach_adapter(struct i2c_adapter
*adapter
)
787 return it87_detect(adapter
, isa_address
, -1);
790 /* SuperIO detection - will change isa_address if a chip is found */
791 static int __init
it87_find(unsigned short *address
)
796 chip_type
= superio_inw(DEVID
);
797 if (chip_type
!= IT8712F_DEVID
798 && chip_type
!= IT8716F_DEVID
799 && chip_type
!= IT8718F_DEVID
800 && chip_type
!= IT8705F_DEVID
)
804 if (!(superio_inb(IT87_ACT_REG
) & 0x01)) {
805 pr_info("it87: Device not activated, skipping\n");
809 *address
= superio_inw(IT87_BASE_REG
) & ~(IT87_EXTENT
- 1);
811 pr_info("it87: Base address not set, skipping\n");
816 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n",
817 chip_type
, *address
, superio_inb(DEVREV
) & 0x0f);
819 /* Read GPIO config and VID value from LDN 7 (GPIO) */
820 if (chip_type
!= IT8705F_DEVID
) {
823 superio_select(GPIO
);
824 if (chip_type
== it8718
)
825 vid_value
= superio_inb(IT87_SIO_VID_REG
);
827 reg
= superio_inb(IT87_SIO_PINX2_REG
);
829 pr_info("it87: in3 is VCC (+5V)\n");
831 pr_info("it87: in7 is VCCH (+5V Stand-By)\n");
839 /* This function is called by i2c_probe */
840 static int it87_detect(struct i2c_adapter
*adapter
, int address
, int kind
)
843 struct i2c_client
*new_client
;
844 struct it87_data
*data
;
846 const char *name
= "";
847 int is_isa
= i2c_is_isa_adapter(adapter
);
848 int enable_pwm_interface
;
851 !i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
854 /* Reserve the ISA region */
856 if (!request_region(address
, IT87_EXTENT
,
857 it87_isa_driver
.driver
.name
))
860 /* For now, we presume we have a valid client. We create the
861 client structure, even though we cannot fill it completely yet.
862 But it allows us to access it87_{read,write}_value. */
864 if (!(data
= kzalloc(sizeof(struct it87_data
), GFP_KERNEL
))) {
869 new_client
= &data
->client
;
871 mutex_init(&data
->lock
);
872 i2c_set_clientdata(new_client
, data
);
873 new_client
->addr
= address
;
874 new_client
->adapter
= adapter
;
875 new_client
->driver
= is_isa
? &it87_isa_driver
: &it87_driver
;
876 new_client
->flags
= 0;
878 /* Now, we do the remaining detection. */
881 if ((it87_read_value(new_client
, IT87_REG_CONFIG
) & 0x80)
883 && it87_read_value(new_client
, IT87_REG_I2C_ADDR
) != address
)) {
889 /* Determine the chip type. */
891 i
= it87_read_value(new_client
, IT87_REG_CHIPID
);
910 dev_info(&adapter
->dev
,
911 "Ignoring 'force' parameter for unknown chip at "
912 "adapter %d, address 0x%02x\n",
913 i2c_adapter_id(adapter
), address
);
921 } else if (kind
== it8712
) {
923 } else if (kind
== it8716
) {
925 } else if (kind
== it8718
) {
929 /* Fill in the remaining client fields and put it into the global list */
930 strlcpy(new_client
->name
, name
, I2C_NAME_SIZE
);
933 mutex_init(&data
->update_lock
);
935 /* Tell the I2C layer a new client has arrived */
936 if ((err
= i2c_attach_client(new_client
)))
940 dev_info(&new_client
->dev
, "The I2C interface to IT87xxF "
941 "hardware monitoring chips is deprecated. Please "
942 "report if you still rely on it.\n");
944 /* Check PWM configuration */
945 enable_pwm_interface
= it87_check_pwm(new_client
);
947 /* Initialize the IT87 chip */
948 it87_init_client(new_client
, data
);
950 /* Register sysfs hooks */
951 data
->class_dev
= hwmon_device_register(&new_client
->dev
);
952 if (IS_ERR(data
->class_dev
)) {
953 err
= PTR_ERR(data
->class_dev
);
957 device_create_file(&new_client
->dev
, &sensor_dev_attr_in0_input
.dev_attr
);
958 device_create_file(&new_client
->dev
, &sensor_dev_attr_in1_input
.dev_attr
);
959 device_create_file(&new_client
->dev
, &sensor_dev_attr_in2_input
.dev_attr
);
960 device_create_file(&new_client
->dev
, &sensor_dev_attr_in3_input
.dev_attr
);
961 device_create_file(&new_client
->dev
, &sensor_dev_attr_in4_input
.dev_attr
);
962 device_create_file(&new_client
->dev
, &sensor_dev_attr_in5_input
.dev_attr
);
963 device_create_file(&new_client
->dev
, &sensor_dev_attr_in6_input
.dev_attr
);
964 device_create_file(&new_client
->dev
, &sensor_dev_attr_in7_input
.dev_attr
);
965 device_create_file(&new_client
->dev
, &sensor_dev_attr_in8_input
.dev_attr
);
966 device_create_file(&new_client
->dev
, &sensor_dev_attr_in0_min
.dev_attr
);
967 device_create_file(&new_client
->dev
, &sensor_dev_attr_in1_min
.dev_attr
);
968 device_create_file(&new_client
->dev
, &sensor_dev_attr_in2_min
.dev_attr
);
969 device_create_file(&new_client
->dev
, &sensor_dev_attr_in3_min
.dev_attr
);
970 device_create_file(&new_client
->dev
, &sensor_dev_attr_in4_min
.dev_attr
);
971 device_create_file(&new_client
->dev
, &sensor_dev_attr_in5_min
.dev_attr
);
972 device_create_file(&new_client
->dev
, &sensor_dev_attr_in6_min
.dev_attr
);
973 device_create_file(&new_client
->dev
, &sensor_dev_attr_in7_min
.dev_attr
);
974 device_create_file(&new_client
->dev
, &sensor_dev_attr_in0_max
.dev_attr
);
975 device_create_file(&new_client
->dev
, &sensor_dev_attr_in1_max
.dev_attr
);
976 device_create_file(&new_client
->dev
, &sensor_dev_attr_in2_max
.dev_attr
);
977 device_create_file(&new_client
->dev
, &sensor_dev_attr_in3_max
.dev_attr
);
978 device_create_file(&new_client
->dev
, &sensor_dev_attr_in4_max
.dev_attr
);
979 device_create_file(&new_client
->dev
, &sensor_dev_attr_in5_max
.dev_attr
);
980 device_create_file(&new_client
->dev
, &sensor_dev_attr_in6_max
.dev_attr
);
981 device_create_file(&new_client
->dev
, &sensor_dev_attr_in7_max
.dev_attr
);
982 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp1_input
.dev_attr
);
983 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp2_input
.dev_attr
);
984 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp3_input
.dev_attr
);
985 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp1_max
.dev_attr
);
986 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp2_max
.dev_attr
);
987 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp3_max
.dev_attr
);
988 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp1_min
.dev_attr
);
989 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp2_min
.dev_attr
);
990 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp3_min
.dev_attr
);
991 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp1_type
.dev_attr
);
992 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp2_type
.dev_attr
);
993 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp3_type
.dev_attr
);
995 /* Do not create fan files for disabled fans */
996 if (data
->type
== it8716
|| data
->type
== it8718
) {
997 /* 16-bit tachometers */
998 if (data
->has_fan
& (1 << 0)) {
999 device_create_file(&new_client
->dev
,
1000 &sensor_dev_attr_fan1_input16
.dev_attr
);
1001 device_create_file(&new_client
->dev
,
1002 &sensor_dev_attr_fan1_min16
.dev_attr
);
1004 if (data
->has_fan
& (1 << 1)) {
1005 device_create_file(&new_client
->dev
,
1006 &sensor_dev_attr_fan2_input16
.dev_attr
);
1007 device_create_file(&new_client
->dev
,
1008 &sensor_dev_attr_fan2_min16
.dev_attr
);
1010 if (data
->has_fan
& (1 << 2)) {
1011 device_create_file(&new_client
->dev
,
1012 &sensor_dev_attr_fan3_input16
.dev_attr
);
1013 device_create_file(&new_client
->dev
,
1014 &sensor_dev_attr_fan3_min16
.dev_attr
);
1017 /* 8-bit tachometers with clock divider */
1018 if (data
->has_fan
& (1 << 0)) {
1019 device_create_file(&new_client
->dev
,
1020 &sensor_dev_attr_fan1_input
.dev_attr
);
1021 device_create_file(&new_client
->dev
,
1022 &sensor_dev_attr_fan1_min
.dev_attr
);
1023 device_create_file(&new_client
->dev
,
1024 &sensor_dev_attr_fan1_div
.dev_attr
);
1026 if (data
->has_fan
& (1 << 1)) {
1027 device_create_file(&new_client
->dev
,
1028 &sensor_dev_attr_fan2_input
.dev_attr
);
1029 device_create_file(&new_client
->dev
,
1030 &sensor_dev_attr_fan2_min
.dev_attr
);
1031 device_create_file(&new_client
->dev
,
1032 &sensor_dev_attr_fan2_div
.dev_attr
);
1034 if (data
->has_fan
& (1 << 2)) {
1035 device_create_file(&new_client
->dev
,
1036 &sensor_dev_attr_fan3_input
.dev_attr
);
1037 device_create_file(&new_client
->dev
,
1038 &sensor_dev_attr_fan3_min
.dev_attr
);
1039 device_create_file(&new_client
->dev
,
1040 &sensor_dev_attr_fan3_div
.dev_attr
);
1044 device_create_file(&new_client
->dev
, &dev_attr_alarms
);
1045 if (enable_pwm_interface
) {
1046 device_create_file(&new_client
->dev
, &sensor_dev_attr_pwm1_enable
.dev_attr
);
1047 device_create_file(&new_client
->dev
, &sensor_dev_attr_pwm2_enable
.dev_attr
);
1048 device_create_file(&new_client
->dev
, &sensor_dev_attr_pwm3_enable
.dev_attr
);
1049 device_create_file(&new_client
->dev
, &sensor_dev_attr_pwm1
.dev_attr
);
1050 device_create_file(&new_client
->dev
, &sensor_dev_attr_pwm2
.dev_attr
);
1051 device_create_file(&new_client
->dev
, &sensor_dev_attr_pwm3
.dev_attr
);
1054 if (data
->type
== it8712
|| data
->type
== it8716
1055 || data
->type
== it8718
) {
1056 data
->vrm
= vid_which_vrm();
1057 /* VID reading from Super-I/O config space if available */
1058 data
->vid
= vid_value
;
1059 device_create_file_vrm(new_client
);
1060 device_create_file_vid(new_client
);
1066 i2c_detach_client(new_client
);
1071 release_region(address
, IT87_EXTENT
);
1076 static int it87_detach_client(struct i2c_client
*client
)
1078 struct it87_data
*data
= i2c_get_clientdata(client
);
1081 hwmon_device_unregister(data
->class_dev
);
1083 if ((err
= i2c_detach_client(client
)))
1086 if(i2c_is_isa_client(client
))
1087 release_region(client
->addr
, IT87_EXTENT
);
1093 /* The SMBus locks itself, but ISA access must be locked explicitly!
1094 We don't want to lock the whole ISA bus, so we lock each client
1096 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1097 would slow down the IT87 access and should not be necessary. */
1098 static int it87_read_value(struct i2c_client
*client
, u8 reg
)
1100 struct it87_data
*data
= i2c_get_clientdata(client
);
1103 if (i2c_is_isa_client(client
)) {
1104 mutex_lock(&data
->lock
);
1105 outb_p(reg
, client
->addr
+ IT87_ADDR_REG_OFFSET
);
1106 res
= inb_p(client
->addr
+ IT87_DATA_REG_OFFSET
);
1107 mutex_unlock(&data
->lock
);
1110 return i2c_smbus_read_byte_data(client
, reg
);
1113 /* The SMBus locks itself, but ISA access muse be locked explicitly!
1114 We don't want to lock the whole ISA bus, so we lock each client
1116 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1117 would slow down the IT87 access and should not be necessary. */
1118 static int it87_write_value(struct i2c_client
*client
, u8 reg
, u8 value
)
1120 struct it87_data
*data
= i2c_get_clientdata(client
);
1122 if (i2c_is_isa_client(client
)) {
1123 mutex_lock(&data
->lock
);
1124 outb_p(reg
, client
->addr
+ IT87_ADDR_REG_OFFSET
);
1125 outb_p(value
, client
->addr
+ IT87_DATA_REG_OFFSET
);
1126 mutex_unlock(&data
->lock
);
1129 return i2c_smbus_write_byte_data(client
, reg
, value
);
1132 /* Return 1 if and only if the PWM interface is safe to use */
1133 static int it87_check_pwm(struct i2c_client
*client
)
1135 /* Some BIOSes fail to correctly configure the IT87 fans. All fans off
1136 * and polarity set to active low is sign that this is the case so we
1137 * disable pwm control to protect the user. */
1138 int tmp
= it87_read_value(client
, IT87_REG_FAN_CTL
);
1139 if ((tmp
& 0x87) == 0) {
1140 if (fix_pwm_polarity
) {
1141 /* The user asks us to attempt a chip reconfiguration.
1142 * This means switching to active high polarity and
1143 * inverting all fan speed values. */
1147 for (i
= 0; i
< 3; i
++)
1148 pwm
[i
] = it87_read_value(client
,
1151 /* If any fan is in automatic pwm mode, the polarity
1152 * might be correct, as suspicious as it seems, so we
1153 * better don't change anything (but still disable the
1154 * PWM interface). */
1155 if (!((pwm
[0] | pwm
[1] | pwm
[2]) & 0x80)) {
1156 dev_info(&client
->dev
, "Reconfiguring PWM to "
1157 "active high polarity\n");
1158 it87_write_value(client
, IT87_REG_FAN_CTL
,
1160 for (i
= 0; i
< 3; i
++)
1161 it87_write_value(client
,
1167 dev_info(&client
->dev
, "PWM configuration is "
1168 "too broken to be fixed\n");
1171 dev_info(&client
->dev
, "Detected broken BIOS "
1172 "defaults, disabling PWM interface\n");
1174 } else if (fix_pwm_polarity
) {
1175 dev_info(&client
->dev
, "PWM configuration looks "
1176 "sane, won't touch\n");
1182 /* Called when we have found a new IT87. */
1183 static void it87_init_client(struct i2c_client
*client
, struct it87_data
*data
)
1187 /* initialize to sane defaults:
1188 * - if the chip is in manual pwm mode, this will be overwritten with
1189 * the actual settings on the chip (so in this case, initialization
1191 * - if in automatic or on/off mode, we could switch to manual mode,
1192 * read the registers and set manual_pwm_ctl accordingly, but currently
1193 * this is not implemented, so we initialize to something sane */
1194 for (i
= 0; i
< 3; i
++) {
1195 data
->manual_pwm_ctl
[i
] = 0xff;
1198 /* Some chips seem to have default value 0xff for all limit
1199 * registers. For low voltage limits it makes no sense and triggers
1200 * alarms, so change to 0 instead. For high temperature limits, it
1201 * means -1 degree C, which surprisingly doesn't trigger an alarm,
1202 * but is still confusing, so change to 127 degrees C. */
1203 for (i
= 0; i
< 8; i
++) {
1204 tmp
= it87_read_value(client
, IT87_REG_VIN_MIN(i
));
1206 it87_write_value(client
, IT87_REG_VIN_MIN(i
), 0);
1208 for (i
= 0; i
< 3; i
++) {
1209 tmp
= it87_read_value(client
, IT87_REG_TEMP_HIGH(i
));
1211 it87_write_value(client
, IT87_REG_TEMP_HIGH(i
), 127);
1214 /* Check if temperature channnels are reset manually or by some reason */
1215 tmp
= it87_read_value(client
, IT87_REG_TEMP_ENABLE
);
1216 if ((tmp
& 0x3f) == 0) {
1217 /* Temp1,Temp3=thermistor; Temp2=thermal diode */
1218 tmp
= (tmp
& 0xc0) | 0x2a;
1219 it87_write_value(client
, IT87_REG_TEMP_ENABLE
, tmp
);
1223 /* Check if voltage monitors are reset manually or by some reason */
1224 tmp
= it87_read_value(client
, IT87_REG_VIN_ENABLE
);
1225 if ((tmp
& 0xff) == 0) {
1226 /* Enable all voltage monitors */
1227 it87_write_value(client
, IT87_REG_VIN_ENABLE
, 0xff);
1230 /* Check if tachometers are reset manually or by some reason */
1231 data
->fan_main_ctrl
= it87_read_value(client
, IT87_REG_FAN_MAIN_CTRL
);
1232 if ((data
->fan_main_ctrl
& 0x70) == 0) {
1233 /* Enable all fan tachometers */
1234 data
->fan_main_ctrl
|= 0x70;
1235 it87_write_value(client
, IT87_REG_FAN_MAIN_CTRL
, data
->fan_main_ctrl
);
1237 data
->has_fan
= (data
->fan_main_ctrl
>> 4) & 0x07;
1239 /* Set tachometers to 16-bit mode if needed */
1240 if (data
->type
== it8716
|| data
->type
== it8718
) {
1241 tmp
= it87_read_value(client
, IT87_REG_FAN_16BIT
);
1242 if (~tmp
& 0x07 & data
->has_fan
) {
1243 dev_dbg(&client
->dev
,
1244 "Setting fan1-3 to 16-bit mode\n");
1245 it87_write_value(client
, IT87_REG_FAN_16BIT
,
1250 /* Set current fan mode registers and the default settings for the
1251 * other mode registers */
1252 for (i
= 0; i
< 3; i
++) {
1253 if (data
->fan_main_ctrl
& (1 << i
)) {
1255 tmp
= it87_read_value(client
, IT87_REG_PWM(i
));
1257 /* automatic pwm - not yet implemented, but
1258 * leave the settings made by the BIOS alone
1259 * until a change is requested via the sysfs
1263 data
->manual_pwm_ctl
[i
] = PWM_FROM_REG(tmp
);
1268 /* Start monitoring */
1269 it87_write_value(client
, IT87_REG_CONFIG
,
1270 (it87_read_value(client
, IT87_REG_CONFIG
) & 0x36)
1271 | (update_vbat
? 0x41 : 0x01));
1274 static struct it87_data
*it87_update_device(struct device
*dev
)
1276 struct i2c_client
*client
= to_i2c_client(dev
);
1277 struct it87_data
*data
= i2c_get_clientdata(client
);
1280 mutex_lock(&data
->update_lock
);
1282 if (time_after(jiffies
, data
->last_updated
+ HZ
+ HZ
/ 2)
1286 /* Cleared after each update, so reenable. Value
1287 returned by this read will be previous value */
1288 it87_write_value(client
, IT87_REG_CONFIG
,
1289 it87_read_value(client
, IT87_REG_CONFIG
) | 0x40);
1291 for (i
= 0; i
<= 7; i
++) {
1293 it87_read_value(client
, IT87_REG_VIN(i
));
1295 it87_read_value(client
, IT87_REG_VIN_MIN(i
));
1297 it87_read_value(client
, IT87_REG_VIN_MAX(i
));
1299 /* in8 (battery) has no limit registers */
1301 it87_read_value(client
, IT87_REG_VIN(8));
1303 for (i
= 0; i
< 3; i
++) {
1304 /* Skip disabled fans */
1305 if (!(data
->has_fan
& (1 << i
)))
1309 it87_read_value(client
, IT87_REG_FAN_MIN(i
));
1310 data
->fan
[i
] = it87_read_value(client
,
1312 /* Add high byte if in 16-bit mode */
1313 if (data
->type
== it8716
|| data
->type
== it8718
) {
1314 data
->fan
[i
] |= it87_read_value(client
,
1315 IT87_REG_FANX(i
)) << 8;
1316 data
->fan_min
[i
] |= it87_read_value(client
,
1317 IT87_REG_FANX_MIN(i
)) << 8;
1320 for (i
= 0; i
< 3; i
++) {
1322 it87_read_value(client
, IT87_REG_TEMP(i
));
1323 data
->temp_high
[i
] =
1324 it87_read_value(client
, IT87_REG_TEMP_HIGH(i
));
1326 it87_read_value(client
, IT87_REG_TEMP_LOW(i
));
1329 /* Newer chips don't have clock dividers */
1330 if ((data
->has_fan
& 0x07) && data
->type
!= it8716
1331 && data
->type
!= it8718
) {
1332 i
= it87_read_value(client
, IT87_REG_FAN_DIV
);
1333 data
->fan_div
[0] = i
& 0x07;
1334 data
->fan_div
[1] = (i
>> 3) & 0x07;
1335 data
->fan_div
[2] = (i
& 0x40) ? 3 : 1;
1339 it87_read_value(client
, IT87_REG_ALARM1
) |
1340 (it87_read_value(client
, IT87_REG_ALARM2
) << 8) |
1341 (it87_read_value(client
, IT87_REG_ALARM3
) << 16);
1342 data
->fan_main_ctrl
= it87_read_value(client
, IT87_REG_FAN_MAIN_CTRL
);
1344 data
->sensor
= it87_read_value(client
, IT87_REG_TEMP_ENABLE
);
1345 /* The 8705 does not have VID capability */
1346 if (data
->type
== it8712
|| data
->type
== it8716
) {
1347 data
->vid
= it87_read_value(client
, IT87_REG_VID
);
1348 /* The older IT8712F revisions had only 5 VID pins,
1349 but we assume it is always safe to read 6 bits. */
1352 data
->last_updated
= jiffies
;
1356 mutex_unlock(&data
->update_lock
);
1361 static int __init
sm_it87_init(void)
1365 res
= i2c_add_driver(&it87_driver
);
1369 if (!it87_find(&isa_address
)) {
1370 res
= i2c_isa_add_driver(&it87_isa_driver
);
1372 i2c_del_driver(&it87_driver
);
1380 static void __exit
sm_it87_exit(void)
1383 i2c_isa_del_driver(&it87_isa_driver
);
1384 i2c_del_driver(&it87_driver
);
1388 MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>, "
1389 "Jean Delvare <khali@linux-fr.org>");
1390 MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F, SiS950 driver");
1391 module_param(update_vbat
, bool, 0);
1392 MODULE_PARM_DESC(update_vbat
, "Update vbat if set else return powerup value");
1393 module_param(fix_pwm_polarity
, bool, 0);
1394 MODULE_PARM_DESC(fix_pwm_polarity
, "Force PWM polarity to active high (DANGEROUS)");
1395 MODULE_LICENSE("GPL");
1397 module_init(sm_it87_init
);
1398 module_exit(sm_it87_exit
);