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 Largely inspired by lm78.c of the same package
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.
30 djg@pdp8.net David Gesswein 7/18/01
31 Modified to fix bug with not all alarms enabled.
32 Added ability to read battery voltage and select temperature sensor
33 type at module load time.
36 #include <linux/module.h>
37 #include <linux/init.h>
38 #include <linux/slab.h>
39 #include <linux/jiffies.h>
40 #include <linux/i2c.h>
41 #include <linux/i2c-isa.h>
42 #include <linux/hwmon.h>
43 #include <linux/hwmon-sysfs.h>
44 #include <linux/hwmon-vid.h>
45 #include <linux/err.h>
46 #include <linux/mutex.h>
50 /* Addresses to scan */
51 static unsigned short normal_i2c
[] = { 0x2d, I2C_CLIENT_END
};
52 static unsigned short isa_address
;
54 /* Insmod parameters */
55 I2C_CLIENT_INSMOD_4(it87
, it8712
, it8716
, it8718
);
57 #define REG 0x2e /* The register to read/write */
58 #define DEV 0x07 /* Register: Logical device select */
59 #define VAL 0x2f /* The value to read/write */
60 #define PME 0x04 /* The device with the fan registers in it */
61 #define GPIO 0x07 /* The device with the IT8718F VID value in it */
62 #define DEVID 0x20 /* Register: Device ID */
63 #define DEVREV 0x22 /* Register: Device Revision */
72 static int superio_inw(int reg
)
83 superio_select(int ldn
)
105 /* Logical device 4 registers */
106 #define IT8712F_DEVID 0x8712
107 #define IT8705F_DEVID 0x8705
108 #define IT8716F_DEVID 0x8716
109 #define IT8718F_DEVID 0x8718
110 #define IT87_ACT_REG 0x30
111 #define IT87_BASE_REG 0x60
113 /* Logical device 7 registers (IT8712F and later) */
114 #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
115 #define IT87_SIO_VID_REG 0xfc /* VID value */
117 /* Update battery voltage after every reading if true */
118 static int update_vbat
;
120 /* Not all BIOSes properly configure the PWM registers */
121 static int fix_pwm_polarity
;
123 /* Values read from Super-I/O config space */
124 static u16 chip_type
;
127 /* Many IT87 constants specified below */
129 /* Length of ISA address segment */
130 #define IT87_EXTENT 8
132 /* Where are the ISA address/data registers relative to the base address */
133 #define IT87_ADDR_REG_OFFSET 5
134 #define IT87_DATA_REG_OFFSET 6
136 /*----- The IT87 registers -----*/
138 #define IT87_REG_CONFIG 0x00
140 #define IT87_REG_ALARM1 0x01
141 #define IT87_REG_ALARM2 0x02
142 #define IT87_REG_ALARM3 0x03
144 /* The IT8718F has the VID value in a different register, in Super-I/O
145 configuration space. */
146 #define IT87_REG_VID 0x0a
147 /* Warning: register 0x0b is used for something completely different in
148 new chips/revisions. I suspect only 16-bit tachometer mode will work
150 #define IT87_REG_FAN_DIV 0x0b
151 #define IT87_REG_FAN_16BIT 0x0c
153 /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
155 #define IT87_REG_FAN(nr) (0x0d + (nr))
156 #define IT87_REG_FAN_MIN(nr) (0x10 + (nr))
157 #define IT87_REG_FANX(nr) (0x18 + (nr))
158 #define IT87_REG_FANX_MIN(nr) (0x1b + (nr))
159 #define IT87_REG_FAN_MAIN_CTRL 0x13
160 #define IT87_REG_FAN_CTL 0x14
161 #define IT87_REG_PWM(nr) (0x15 + (nr))
163 #define IT87_REG_VIN(nr) (0x20 + (nr))
164 #define IT87_REG_TEMP(nr) (0x29 + (nr))
166 #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
167 #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
168 #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
169 #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
171 #define IT87_REG_I2C_ADDR 0x48
173 #define IT87_REG_VIN_ENABLE 0x50
174 #define IT87_REG_TEMP_ENABLE 0x51
176 #define IT87_REG_CHIPID 0x58
178 #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255))
179 #define IN_FROM_REG(val) ((val) * 16)
181 static inline u8
FAN_TO_REG(long rpm
, int div
)
185 rpm
= SENSORS_LIMIT(rpm
, 1, 1000000);
186 return SENSORS_LIMIT((1350000 + rpm
* div
/ 2) / (rpm
* div
), 1,
190 static inline u16
FAN16_TO_REG(long rpm
)
194 return SENSORS_LIMIT((1350000 + rpm
) / (rpm
* 2), 1, 0xfffe);
197 #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
198 /* The divider is fixed to 2 in 16-bit mode */
199 #define FAN16_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:1350000/((val)*2))
201 #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\
202 ((val)+500)/1000),-128,127))
203 #define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*1000)
205 #define PWM_TO_REG(val) ((val) >> 1)
206 #define PWM_FROM_REG(val) (((val)&0x7f) << 1)
208 static int DIV_TO_REG(int val
)
211 while (answer
< 7 && (val
>>= 1))
215 #define DIV_FROM_REG(val) (1 << (val))
218 /* For each registered IT87, we need to keep some data in memory. That
219 data is pointed to by it87_list[NR]->data. The structure itself is
220 dynamically allocated, at the same time when a new it87 client is
223 struct i2c_client client
;
224 struct class_device
*class_dev
;
228 struct mutex update_lock
;
229 char valid
; /* !=0 if following fields are valid */
230 unsigned long last_updated
; /* In jiffies */
232 u8 in
[9]; /* Register value */
233 u8 in_max
[8]; /* Register value */
234 u8 in_min
[8]; /* Register value */
235 u8 has_fan
; /* Bitfield, fans enabled */
236 u16 fan
[3]; /* Register values, possibly combined */
237 u16 fan_min
[3]; /* Register values, possibly combined */
238 u8 temp
[3]; /* Register value */
239 u8 temp_high
[3]; /* Register value */
240 u8 temp_low
[3]; /* Register value */
241 u8 sensor
; /* Register value */
242 u8 fan_div
[3]; /* Register encoding, shifted right */
243 u8 vid
; /* Register encoding, combined */
245 u32 alarms
; /* Register encoding, combined */
246 u8 fan_main_ctrl
; /* Register value */
247 u8 manual_pwm_ctl
[3]; /* manual PWM value set by user */
251 static int it87_attach_adapter(struct i2c_adapter
*adapter
);
252 static int it87_isa_attach_adapter(struct i2c_adapter
*adapter
);
253 static int it87_detect(struct i2c_adapter
*adapter
, int address
, int kind
);
254 static int it87_detach_client(struct i2c_client
*client
);
256 static int it87_read_value(struct i2c_client
*client
, u8 reg
);
257 static int it87_write_value(struct i2c_client
*client
, u8 reg
, u8 value
);
258 static struct it87_data
*it87_update_device(struct device
*dev
);
259 static int it87_check_pwm(struct i2c_client
*client
);
260 static void it87_init_client(struct i2c_client
*client
, struct it87_data
*data
);
263 static struct i2c_driver it87_driver
= {
267 .id
= I2C_DRIVERID_IT87
,
268 .attach_adapter
= it87_attach_adapter
,
269 .detach_client
= it87_detach_client
,
272 static struct i2c_driver it87_isa_driver
= {
274 .owner
= THIS_MODULE
,
277 .attach_adapter
= it87_isa_attach_adapter
,
278 .detach_client
= it87_detach_client
,
282 static ssize_t
show_in(struct device
*dev
, struct device_attribute
*attr
,
285 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
286 int nr
= sensor_attr
->index
;
288 struct it87_data
*data
= it87_update_device(dev
);
289 return sprintf(buf
, "%d\n", IN_FROM_REG(data
->in
[nr
]));
292 static ssize_t
show_in_min(struct device
*dev
, struct device_attribute
*attr
,
295 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
296 int nr
= sensor_attr
->index
;
298 struct it87_data
*data
= it87_update_device(dev
);
299 return sprintf(buf
, "%d\n", IN_FROM_REG(data
->in_min
[nr
]));
302 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
*attr
,
305 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
306 int nr
= sensor_attr
->index
;
308 struct it87_data
*data
= it87_update_device(dev
);
309 return sprintf(buf
, "%d\n", IN_FROM_REG(data
->in_max
[nr
]));
312 static ssize_t
set_in_min(struct device
*dev
, struct device_attribute
*attr
,
313 const char *buf
, size_t count
)
315 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
316 int nr
= sensor_attr
->index
;
318 struct i2c_client
*client
= to_i2c_client(dev
);
319 struct it87_data
*data
= i2c_get_clientdata(client
);
320 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
322 mutex_lock(&data
->update_lock
);
323 data
->in_min
[nr
] = IN_TO_REG(val
);
324 it87_write_value(client
, IT87_REG_VIN_MIN(nr
),
326 mutex_unlock(&data
->update_lock
);
329 static ssize_t
set_in_max(struct device
*dev
, struct device_attribute
*attr
,
330 const char *buf
, size_t count
)
332 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
333 int nr
= sensor_attr
->index
;
335 struct i2c_client
*client
= to_i2c_client(dev
);
336 struct it87_data
*data
= i2c_get_clientdata(client
);
337 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
339 mutex_lock(&data
->update_lock
);
340 data
->in_max
[nr
] = IN_TO_REG(val
);
341 it87_write_value(client
, IT87_REG_VIN_MAX(nr
),
343 mutex_unlock(&data
->update_lock
);
347 #define show_in_offset(offset) \
348 static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
349 show_in, NULL, offset);
351 #define limit_in_offset(offset) \
352 static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
353 show_in_min, set_in_min, offset); \
354 static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
355 show_in_max, set_in_max, offset);
376 static ssize_t
show_temp(struct device
*dev
, struct device_attribute
*attr
,
379 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
380 int nr
= sensor_attr
->index
;
382 struct it87_data
*data
= it87_update_device(dev
);
383 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp
[nr
]));
385 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
*attr
,
388 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
389 int nr
= sensor_attr
->index
;
391 struct it87_data
*data
= it87_update_device(dev
);
392 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_high
[nr
]));
394 static ssize_t
show_temp_min(struct device
*dev
, struct device_attribute
*attr
,
397 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
398 int nr
= sensor_attr
->index
;
400 struct it87_data
*data
= it87_update_device(dev
);
401 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_low
[nr
]));
403 static ssize_t
set_temp_max(struct device
*dev
, struct device_attribute
*attr
,
404 const char *buf
, size_t count
)
406 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
407 int nr
= sensor_attr
->index
;
409 struct i2c_client
*client
= to_i2c_client(dev
);
410 struct it87_data
*data
= i2c_get_clientdata(client
);
411 int val
= simple_strtol(buf
, NULL
, 10);
413 mutex_lock(&data
->update_lock
);
414 data
->temp_high
[nr
] = TEMP_TO_REG(val
);
415 it87_write_value(client
, IT87_REG_TEMP_HIGH(nr
), data
->temp_high
[nr
]);
416 mutex_unlock(&data
->update_lock
);
419 static ssize_t
set_temp_min(struct device
*dev
, struct device_attribute
*attr
,
420 const char *buf
, size_t count
)
422 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
423 int nr
= sensor_attr
->index
;
425 struct i2c_client
*client
= to_i2c_client(dev
);
426 struct it87_data
*data
= i2c_get_clientdata(client
);
427 int val
= simple_strtol(buf
, NULL
, 10);
429 mutex_lock(&data
->update_lock
);
430 data
->temp_low
[nr
] = TEMP_TO_REG(val
);
431 it87_write_value(client
, IT87_REG_TEMP_LOW(nr
), data
->temp_low
[nr
]);
432 mutex_unlock(&data
->update_lock
);
435 #define show_temp_offset(offset) \
436 static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
437 show_temp, NULL, offset - 1); \
438 static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
439 show_temp_max, set_temp_max, offset - 1); \
440 static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
441 show_temp_min, set_temp_min, offset - 1);
447 static ssize_t
show_sensor(struct device
*dev
, struct device_attribute
*attr
,
450 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
451 int nr
= sensor_attr
->index
;
453 struct it87_data
*data
= it87_update_device(dev
);
454 u8 reg
= data
->sensor
; /* In case the value is updated while we use it */
457 return sprintf(buf
, "3\n"); /* thermal diode */
459 return sprintf(buf
, "2\n"); /* thermistor */
460 return sprintf(buf
, "0\n"); /* disabled */
462 static ssize_t
set_sensor(struct device
*dev
, struct device_attribute
*attr
,
463 const char *buf
, size_t count
)
465 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
466 int nr
= sensor_attr
->index
;
468 struct i2c_client
*client
= to_i2c_client(dev
);
469 struct it87_data
*data
= i2c_get_clientdata(client
);
470 int val
= simple_strtol(buf
, NULL
, 10);
472 mutex_lock(&data
->update_lock
);
474 data
->sensor
&= ~(1 << nr
);
475 data
->sensor
&= ~(8 << nr
);
476 /* 3 = thermal diode; 2 = thermistor; 0 = disabled */
478 data
->sensor
|= 1 << nr
;
480 data
->sensor
|= 8 << nr
;
482 mutex_unlock(&data
->update_lock
);
485 it87_write_value(client
, IT87_REG_TEMP_ENABLE
, data
->sensor
);
486 mutex_unlock(&data
->update_lock
);
489 #define show_sensor_offset(offset) \
490 static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
491 show_sensor, set_sensor, offset - 1);
493 show_sensor_offset(1);
494 show_sensor_offset(2);
495 show_sensor_offset(3);
498 static ssize_t
show_fan(struct device
*dev
, struct device_attribute
*attr
,
501 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
502 int nr
= sensor_attr
->index
;
504 struct it87_data
*data
= it87_update_device(dev
);
505 return sprintf(buf
,"%d\n", FAN_FROM_REG(data
->fan
[nr
],
506 DIV_FROM_REG(data
->fan_div
[nr
])));
508 static ssize_t
show_fan_min(struct device
*dev
, struct device_attribute
*attr
,
511 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
512 int nr
= sensor_attr
->index
;
514 struct it87_data
*data
= it87_update_device(dev
);
515 return sprintf(buf
,"%d\n",
516 FAN_FROM_REG(data
->fan_min
[nr
], DIV_FROM_REG(data
->fan_div
[nr
])));
518 static ssize_t
show_fan_div(struct device
*dev
, struct device_attribute
*attr
,
521 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
522 int nr
= sensor_attr
->index
;
524 struct it87_data
*data
= it87_update_device(dev
);
525 return sprintf(buf
, "%d\n", DIV_FROM_REG(data
->fan_div
[nr
]));
527 static ssize_t
show_pwm_enable(struct device
*dev
, struct device_attribute
*attr
,
530 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
531 int nr
= sensor_attr
->index
;
533 struct it87_data
*data
= it87_update_device(dev
);
534 return sprintf(buf
,"%d\n", (data
->fan_main_ctrl
& (1 << nr
)) ? 1 : 0);
536 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
*attr
,
539 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
540 int nr
= sensor_attr
->index
;
542 struct it87_data
*data
= it87_update_device(dev
);
543 return sprintf(buf
,"%d\n", data
->manual_pwm_ctl
[nr
]);
545 static ssize_t
set_fan_min(struct device
*dev
, struct device_attribute
*attr
,
546 const char *buf
, size_t count
)
548 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
549 int nr
= sensor_attr
->index
;
551 struct i2c_client
*client
= to_i2c_client(dev
);
552 struct it87_data
*data
= i2c_get_clientdata(client
);
553 int val
= simple_strtol(buf
, NULL
, 10);
554 u8 reg
= it87_read_value(client
, IT87_REG_FAN_DIV
);
556 mutex_lock(&data
->update_lock
);
558 case 0: data
->fan_div
[nr
] = reg
& 0x07; break;
559 case 1: data
->fan_div
[nr
] = (reg
>> 3) & 0x07; break;
560 case 2: data
->fan_div
[nr
] = (reg
& 0x40) ? 3 : 1; break;
563 data
->fan_min
[nr
] = FAN_TO_REG(val
, DIV_FROM_REG(data
->fan_div
[nr
]));
564 it87_write_value(client
, IT87_REG_FAN_MIN(nr
), data
->fan_min
[nr
]);
565 mutex_unlock(&data
->update_lock
);
568 static ssize_t
set_fan_div(struct device
*dev
, struct device_attribute
*attr
,
569 const char *buf
, size_t count
)
571 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
572 int nr
= sensor_attr
->index
;
574 struct i2c_client
*client
= to_i2c_client(dev
);
575 struct it87_data
*data
= i2c_get_clientdata(client
);
576 unsigned long val
= simple_strtoul(buf
, NULL
, 10);
580 mutex_lock(&data
->update_lock
);
581 old
= it87_read_value(client
, IT87_REG_FAN_DIV
);
583 /* Save fan min limit */
584 min
= FAN_FROM_REG(data
->fan_min
[nr
], DIV_FROM_REG(data
->fan_div
[nr
]));
589 data
->fan_div
[nr
] = DIV_TO_REG(val
);
593 data
->fan_div
[nr
] = 1;
595 data
->fan_div
[nr
] = 3;
598 val
|= (data
->fan_div
[0] & 0x07);
599 val
|= (data
->fan_div
[1] & 0x07) << 3;
600 if (data
->fan_div
[2] == 3)
602 it87_write_value(client
, IT87_REG_FAN_DIV
, val
);
604 /* Restore fan min limit */
605 data
->fan_min
[nr
] = FAN_TO_REG(min
, DIV_FROM_REG(data
->fan_div
[nr
]));
606 it87_write_value(client
, IT87_REG_FAN_MIN(nr
), data
->fan_min
[nr
]);
608 mutex_unlock(&data
->update_lock
);
611 static ssize_t
set_pwm_enable(struct device
*dev
,
612 struct device_attribute
*attr
, const char *buf
, size_t count
)
614 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
615 int nr
= sensor_attr
->index
;
617 struct i2c_client
*client
= to_i2c_client(dev
);
618 struct it87_data
*data
= i2c_get_clientdata(client
);
619 int val
= simple_strtol(buf
, NULL
, 10);
621 mutex_lock(&data
->update_lock
);
625 /* make sure the fan is on when in on/off mode */
626 tmp
= it87_read_value(client
, IT87_REG_FAN_CTL
);
627 it87_write_value(client
, IT87_REG_FAN_CTL
, tmp
| (1 << nr
));
628 /* set on/off mode */
629 data
->fan_main_ctrl
&= ~(1 << nr
);
630 it87_write_value(client
, IT87_REG_FAN_MAIN_CTRL
, data
->fan_main_ctrl
);
631 } else if (val
== 1) {
632 /* set SmartGuardian mode */
633 data
->fan_main_ctrl
|= (1 << nr
);
634 it87_write_value(client
, IT87_REG_FAN_MAIN_CTRL
, data
->fan_main_ctrl
);
635 /* set saved pwm value, clear FAN_CTLX PWM mode bit */
636 it87_write_value(client
, IT87_REG_PWM(nr
), PWM_TO_REG(data
->manual_pwm_ctl
[nr
]));
638 mutex_unlock(&data
->update_lock
);
642 mutex_unlock(&data
->update_lock
);
645 static ssize_t
set_pwm(struct device
*dev
, struct device_attribute
*attr
,
646 const char *buf
, size_t count
)
648 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
649 int nr
= sensor_attr
->index
;
651 struct i2c_client
*client
= to_i2c_client(dev
);
652 struct it87_data
*data
= i2c_get_clientdata(client
);
653 int val
= simple_strtol(buf
, NULL
, 10);
655 if (val
< 0 || val
> 255)
658 mutex_lock(&data
->update_lock
);
659 data
->manual_pwm_ctl
[nr
] = val
;
660 if (data
->fan_main_ctrl
& (1 << nr
))
661 it87_write_value(client
, IT87_REG_PWM(nr
), PWM_TO_REG(data
->manual_pwm_ctl
[nr
]));
662 mutex_unlock(&data
->update_lock
);
666 #define show_fan_offset(offset) \
667 static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
668 show_fan, NULL, offset - 1); \
669 static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
670 show_fan_min, set_fan_min, offset - 1); \
671 static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
672 show_fan_div, set_fan_div, offset - 1);
678 #define show_pwm_offset(offset) \
679 static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
680 show_pwm_enable, set_pwm_enable, offset - 1); \
681 static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
682 show_pwm, set_pwm, offset - 1);
688 /* A different set of callbacks for 16-bit fans */
689 static ssize_t
show_fan16(struct device
*dev
, struct device_attribute
*attr
,
692 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
693 int nr
= sensor_attr
->index
;
694 struct it87_data
*data
= it87_update_device(dev
);
695 return sprintf(buf
, "%d\n", FAN16_FROM_REG(data
->fan
[nr
]));
698 static ssize_t
show_fan16_min(struct device
*dev
, struct device_attribute
*attr
,
701 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
702 int nr
= sensor_attr
->index
;
703 struct it87_data
*data
= it87_update_device(dev
);
704 return sprintf(buf
, "%d\n", FAN16_FROM_REG(data
->fan_min
[nr
]));
707 static ssize_t
set_fan16_min(struct device
*dev
, struct device_attribute
*attr
,
708 const char *buf
, size_t count
)
710 struct sensor_device_attribute
*sensor_attr
= to_sensor_dev_attr(attr
);
711 int nr
= sensor_attr
->index
;
712 struct i2c_client
*client
= to_i2c_client(dev
);
713 struct it87_data
*data
= i2c_get_clientdata(client
);
714 int val
= simple_strtol(buf
, NULL
, 10);
716 mutex_lock(&data
->update_lock
);
717 data
->fan_min
[nr
] = FAN16_TO_REG(val
);
718 it87_write_value(client
, IT87_REG_FAN_MIN(nr
),
719 data
->fan_min
[nr
] & 0xff);
720 it87_write_value(client
, IT87_REG_FANX_MIN(nr
),
721 data
->fan_min
[nr
] >> 8);
722 mutex_unlock(&data
->update_lock
);
726 /* We want to use the same sysfs file names as 8-bit fans, but we need
727 different variable names, so we have to use SENSOR_ATTR instead of
728 SENSOR_DEVICE_ATTR. */
729 #define show_fan16_offset(offset) \
730 static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
731 = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
732 show_fan16, NULL, offset - 1); \
733 static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \
734 = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
735 show_fan16_min, set_fan16_min, offset - 1)
737 show_fan16_offset(1);
738 show_fan16_offset(2);
739 show_fan16_offset(3);
742 static ssize_t
show_alarms(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
744 struct it87_data
*data
= it87_update_device(dev
);
745 return sprintf(buf
, "%u\n", data
->alarms
);
747 static DEVICE_ATTR(alarms
, S_IRUGO
, show_alarms
, NULL
);
750 show_vrm_reg(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
752 struct it87_data
*data
= it87_update_device(dev
);
753 return sprintf(buf
, "%u\n", data
->vrm
);
756 store_vrm_reg(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
758 struct i2c_client
*client
= to_i2c_client(dev
);
759 struct it87_data
*data
= i2c_get_clientdata(client
);
762 val
= simple_strtoul(buf
, NULL
, 10);
767 static DEVICE_ATTR(vrm
, S_IRUGO
| S_IWUSR
, show_vrm_reg
, store_vrm_reg
);
768 #define device_create_file_vrm(client) \
769 device_create_file(&client->dev, &dev_attr_vrm)
772 show_vid_reg(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
774 struct it87_data
*data
= it87_update_device(dev
);
775 return sprintf(buf
, "%ld\n", (long) vid_from_reg(data
->vid
, data
->vrm
));
777 static DEVICE_ATTR(cpu0_vid
, S_IRUGO
, show_vid_reg
, NULL
);
778 #define device_create_file_vid(client) \
779 device_create_file(&client->dev, &dev_attr_cpu0_vid)
781 /* This function is called when:
782 * it87_driver is inserted (when this module is loaded), for each
784 * when a new adapter is inserted (and it87_driver is still present) */
785 static int it87_attach_adapter(struct i2c_adapter
*adapter
)
787 if (!(adapter
->class & I2C_CLASS_HWMON
))
789 return i2c_probe(adapter
, &addr_data
, it87_detect
);
792 static int it87_isa_attach_adapter(struct i2c_adapter
*adapter
)
794 return it87_detect(adapter
, isa_address
, -1);
797 /* SuperIO detection - will change isa_address if a chip is found */
798 static int __init
it87_find(unsigned short *address
)
803 chip_type
= superio_inw(DEVID
);
804 if (chip_type
!= IT8712F_DEVID
805 && chip_type
!= IT8716F_DEVID
806 && chip_type
!= IT8718F_DEVID
807 && chip_type
!= IT8705F_DEVID
)
811 if (!(superio_inb(IT87_ACT_REG
) & 0x01)) {
812 pr_info("it87: Device not activated, skipping\n");
816 *address
= superio_inw(IT87_BASE_REG
) & ~(IT87_EXTENT
- 1);
818 pr_info("it87: Base address not set, skipping\n");
823 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n",
824 chip_type
, *address
, superio_inb(DEVREV
) & 0x0f);
826 /* Read GPIO config and VID value from LDN 7 (GPIO) */
827 if (chip_type
!= IT8705F_DEVID
) {
830 superio_select(GPIO
);
831 if (chip_type
== it8718
)
832 vid_value
= superio_inb(IT87_SIO_VID_REG
);
834 reg
= superio_inb(IT87_SIO_PINX2_REG
);
836 pr_info("it87: in3 is VCC (+5V)\n");
838 pr_info("it87: in7 is VCCH (+5V Stand-By)\n");
846 /* This function is called by i2c_probe */
847 static int it87_detect(struct i2c_adapter
*adapter
, int address
, int kind
)
850 struct i2c_client
*new_client
;
851 struct it87_data
*data
;
853 const char *name
= "";
854 int is_isa
= i2c_is_isa_adapter(adapter
);
855 int enable_pwm_interface
;
858 !i2c_check_functionality(adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
861 /* Reserve the ISA region */
863 if (!request_region(address
, IT87_EXTENT
,
864 it87_isa_driver
.driver
.name
))
867 /* For now, we presume we have a valid client. We create the
868 client structure, even though we cannot fill it completely yet.
869 But it allows us to access it87_{read,write}_value. */
871 if (!(data
= kzalloc(sizeof(struct it87_data
), GFP_KERNEL
))) {
876 new_client
= &data
->client
;
878 mutex_init(&data
->lock
);
879 i2c_set_clientdata(new_client
, data
);
880 new_client
->addr
= address
;
881 new_client
->adapter
= adapter
;
882 new_client
->driver
= is_isa
? &it87_isa_driver
: &it87_driver
;
883 new_client
->flags
= 0;
885 /* Now, we do the remaining detection. */
888 if ((it87_read_value(new_client
, IT87_REG_CONFIG
) & 0x80)
890 && it87_read_value(new_client
, IT87_REG_I2C_ADDR
) != address
)) {
896 /* Determine the chip type. */
898 i
= it87_read_value(new_client
, IT87_REG_CHIPID
);
917 dev_info(&adapter
->dev
,
918 "Ignoring 'force' parameter for unknown chip at "
919 "adapter %d, address 0x%02x\n",
920 i2c_adapter_id(adapter
), address
);
928 } else if (kind
== it8712
) {
930 } else if (kind
== it8716
) {
932 } else if (kind
== it8718
) {
936 /* Fill in the remaining client fields and put it into the global list */
937 strlcpy(new_client
->name
, name
, I2C_NAME_SIZE
);
940 mutex_init(&data
->update_lock
);
942 /* Tell the I2C layer a new client has arrived */
943 if ((err
= i2c_attach_client(new_client
)))
947 dev_info(&new_client
->dev
, "The I2C interface to IT87xxF "
948 "hardware monitoring chips is deprecated. Please "
949 "report if you still rely on it.\n");
951 /* Check PWM configuration */
952 enable_pwm_interface
= it87_check_pwm(new_client
);
954 /* Initialize the IT87 chip */
955 it87_init_client(new_client
, data
);
957 /* Register sysfs hooks */
958 data
->class_dev
= hwmon_device_register(&new_client
->dev
);
959 if (IS_ERR(data
->class_dev
)) {
960 err
= PTR_ERR(data
->class_dev
);
964 device_create_file(&new_client
->dev
, &sensor_dev_attr_in0_input
.dev_attr
);
965 device_create_file(&new_client
->dev
, &sensor_dev_attr_in1_input
.dev_attr
);
966 device_create_file(&new_client
->dev
, &sensor_dev_attr_in2_input
.dev_attr
);
967 device_create_file(&new_client
->dev
, &sensor_dev_attr_in3_input
.dev_attr
);
968 device_create_file(&new_client
->dev
, &sensor_dev_attr_in4_input
.dev_attr
);
969 device_create_file(&new_client
->dev
, &sensor_dev_attr_in5_input
.dev_attr
);
970 device_create_file(&new_client
->dev
, &sensor_dev_attr_in6_input
.dev_attr
);
971 device_create_file(&new_client
->dev
, &sensor_dev_attr_in7_input
.dev_attr
);
972 device_create_file(&new_client
->dev
, &sensor_dev_attr_in8_input
.dev_attr
);
973 device_create_file(&new_client
->dev
, &sensor_dev_attr_in0_min
.dev_attr
);
974 device_create_file(&new_client
->dev
, &sensor_dev_attr_in1_min
.dev_attr
);
975 device_create_file(&new_client
->dev
, &sensor_dev_attr_in2_min
.dev_attr
);
976 device_create_file(&new_client
->dev
, &sensor_dev_attr_in3_min
.dev_attr
);
977 device_create_file(&new_client
->dev
, &sensor_dev_attr_in4_min
.dev_attr
);
978 device_create_file(&new_client
->dev
, &sensor_dev_attr_in5_min
.dev_attr
);
979 device_create_file(&new_client
->dev
, &sensor_dev_attr_in6_min
.dev_attr
);
980 device_create_file(&new_client
->dev
, &sensor_dev_attr_in7_min
.dev_attr
);
981 device_create_file(&new_client
->dev
, &sensor_dev_attr_in0_max
.dev_attr
);
982 device_create_file(&new_client
->dev
, &sensor_dev_attr_in1_max
.dev_attr
);
983 device_create_file(&new_client
->dev
, &sensor_dev_attr_in2_max
.dev_attr
);
984 device_create_file(&new_client
->dev
, &sensor_dev_attr_in3_max
.dev_attr
);
985 device_create_file(&new_client
->dev
, &sensor_dev_attr_in4_max
.dev_attr
);
986 device_create_file(&new_client
->dev
, &sensor_dev_attr_in5_max
.dev_attr
);
987 device_create_file(&new_client
->dev
, &sensor_dev_attr_in6_max
.dev_attr
);
988 device_create_file(&new_client
->dev
, &sensor_dev_attr_in7_max
.dev_attr
);
989 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp1_input
.dev_attr
);
990 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp2_input
.dev_attr
);
991 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp3_input
.dev_attr
);
992 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp1_max
.dev_attr
);
993 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp2_max
.dev_attr
);
994 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp3_max
.dev_attr
);
995 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp1_min
.dev_attr
);
996 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp2_min
.dev_attr
);
997 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp3_min
.dev_attr
);
998 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp1_type
.dev_attr
);
999 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp2_type
.dev_attr
);
1000 device_create_file(&new_client
->dev
, &sensor_dev_attr_temp3_type
.dev_attr
);
1002 /* Do not create fan files for disabled fans */
1003 if (data
->type
== it8716
|| data
->type
== it8718
) {
1004 /* 16-bit tachometers */
1005 if (data
->has_fan
& (1 << 0)) {
1006 device_create_file(&new_client
->dev
,
1007 &sensor_dev_attr_fan1_input16
.dev_attr
);
1008 device_create_file(&new_client
->dev
,
1009 &sensor_dev_attr_fan1_min16
.dev_attr
);
1011 if (data
->has_fan
& (1 << 1)) {
1012 device_create_file(&new_client
->dev
,
1013 &sensor_dev_attr_fan2_input16
.dev_attr
);
1014 device_create_file(&new_client
->dev
,
1015 &sensor_dev_attr_fan2_min16
.dev_attr
);
1017 if (data
->has_fan
& (1 << 2)) {
1018 device_create_file(&new_client
->dev
,
1019 &sensor_dev_attr_fan3_input16
.dev_attr
);
1020 device_create_file(&new_client
->dev
,
1021 &sensor_dev_attr_fan3_min16
.dev_attr
);
1024 /* 8-bit tachometers with clock divider */
1025 if (data
->has_fan
& (1 << 0)) {
1026 device_create_file(&new_client
->dev
,
1027 &sensor_dev_attr_fan1_input
.dev_attr
);
1028 device_create_file(&new_client
->dev
,
1029 &sensor_dev_attr_fan1_min
.dev_attr
);
1030 device_create_file(&new_client
->dev
,
1031 &sensor_dev_attr_fan1_div
.dev_attr
);
1033 if (data
->has_fan
& (1 << 1)) {
1034 device_create_file(&new_client
->dev
,
1035 &sensor_dev_attr_fan2_input
.dev_attr
);
1036 device_create_file(&new_client
->dev
,
1037 &sensor_dev_attr_fan2_min
.dev_attr
);
1038 device_create_file(&new_client
->dev
,
1039 &sensor_dev_attr_fan2_div
.dev_attr
);
1041 if (data
->has_fan
& (1 << 2)) {
1042 device_create_file(&new_client
->dev
,
1043 &sensor_dev_attr_fan3_input
.dev_attr
);
1044 device_create_file(&new_client
->dev
,
1045 &sensor_dev_attr_fan3_min
.dev_attr
);
1046 device_create_file(&new_client
->dev
,
1047 &sensor_dev_attr_fan3_div
.dev_attr
);
1051 device_create_file(&new_client
->dev
, &dev_attr_alarms
);
1052 if (enable_pwm_interface
) {
1053 device_create_file(&new_client
->dev
, &sensor_dev_attr_pwm1_enable
.dev_attr
);
1054 device_create_file(&new_client
->dev
, &sensor_dev_attr_pwm2_enable
.dev_attr
);
1055 device_create_file(&new_client
->dev
, &sensor_dev_attr_pwm3_enable
.dev_attr
);
1056 device_create_file(&new_client
->dev
, &sensor_dev_attr_pwm1
.dev_attr
);
1057 device_create_file(&new_client
->dev
, &sensor_dev_attr_pwm2
.dev_attr
);
1058 device_create_file(&new_client
->dev
, &sensor_dev_attr_pwm3
.dev_attr
);
1061 if (data
->type
== it8712
|| data
->type
== it8716
1062 || data
->type
== it8718
) {
1063 data
->vrm
= vid_which_vrm();
1064 /* VID reading from Super-I/O config space if available */
1065 data
->vid
= vid_value
;
1066 device_create_file_vrm(new_client
);
1067 device_create_file_vid(new_client
);
1073 i2c_detach_client(new_client
);
1078 release_region(address
, IT87_EXTENT
);
1083 static int it87_detach_client(struct i2c_client
*client
)
1085 struct it87_data
*data
= i2c_get_clientdata(client
);
1088 hwmon_device_unregister(data
->class_dev
);
1090 if ((err
= i2c_detach_client(client
)))
1093 if(i2c_is_isa_client(client
))
1094 release_region(client
->addr
, IT87_EXTENT
);
1100 /* The SMBus locks itself, but ISA access must be locked explicitly!
1101 We don't want to lock the whole ISA bus, so we lock each client
1103 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1104 would slow down the IT87 access and should not be necessary. */
1105 static int it87_read_value(struct i2c_client
*client
, u8 reg
)
1107 struct it87_data
*data
= i2c_get_clientdata(client
);
1110 if (i2c_is_isa_client(client
)) {
1111 mutex_lock(&data
->lock
);
1112 outb_p(reg
, client
->addr
+ IT87_ADDR_REG_OFFSET
);
1113 res
= inb_p(client
->addr
+ IT87_DATA_REG_OFFSET
);
1114 mutex_unlock(&data
->lock
);
1117 return i2c_smbus_read_byte_data(client
, reg
);
1120 /* The SMBus locks itself, but ISA access muse be locked explicitly!
1121 We don't want to lock the whole ISA bus, so we lock each client
1123 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1124 would slow down the IT87 access and should not be necessary. */
1125 static int it87_write_value(struct i2c_client
*client
, u8 reg
, u8 value
)
1127 struct it87_data
*data
= i2c_get_clientdata(client
);
1129 if (i2c_is_isa_client(client
)) {
1130 mutex_lock(&data
->lock
);
1131 outb_p(reg
, client
->addr
+ IT87_ADDR_REG_OFFSET
);
1132 outb_p(value
, client
->addr
+ IT87_DATA_REG_OFFSET
);
1133 mutex_unlock(&data
->lock
);
1136 return i2c_smbus_write_byte_data(client
, reg
, value
);
1139 /* Return 1 if and only if the PWM interface is safe to use */
1140 static int it87_check_pwm(struct i2c_client
*client
)
1142 /* Some BIOSes fail to correctly configure the IT87 fans. All fans off
1143 * and polarity set to active low is sign that this is the case so we
1144 * disable pwm control to protect the user. */
1145 int tmp
= it87_read_value(client
, IT87_REG_FAN_CTL
);
1146 if ((tmp
& 0x87) == 0) {
1147 if (fix_pwm_polarity
) {
1148 /* The user asks us to attempt a chip reconfiguration.
1149 * This means switching to active high polarity and
1150 * inverting all fan speed values. */
1154 for (i
= 0; i
< 3; i
++)
1155 pwm
[i
] = it87_read_value(client
,
1158 /* If any fan is in automatic pwm mode, the polarity
1159 * might be correct, as suspicious as it seems, so we
1160 * better don't change anything (but still disable the
1161 * PWM interface). */
1162 if (!((pwm
[0] | pwm
[1] | pwm
[2]) & 0x80)) {
1163 dev_info(&client
->dev
, "Reconfiguring PWM to "
1164 "active high polarity\n");
1165 it87_write_value(client
, IT87_REG_FAN_CTL
,
1167 for (i
= 0; i
< 3; i
++)
1168 it87_write_value(client
,
1174 dev_info(&client
->dev
, "PWM configuration is "
1175 "too broken to be fixed\n");
1178 dev_info(&client
->dev
, "Detected broken BIOS "
1179 "defaults, disabling PWM interface\n");
1181 } else if (fix_pwm_polarity
) {
1182 dev_info(&client
->dev
, "PWM configuration looks "
1183 "sane, won't touch\n");
1189 /* Called when we have found a new IT87. */
1190 static void it87_init_client(struct i2c_client
*client
, struct it87_data
*data
)
1194 /* initialize to sane defaults:
1195 * - if the chip is in manual pwm mode, this will be overwritten with
1196 * the actual settings on the chip (so in this case, initialization
1198 * - if in automatic or on/off mode, we could switch to manual mode,
1199 * read the registers and set manual_pwm_ctl accordingly, but currently
1200 * this is not implemented, so we initialize to something sane */
1201 for (i
= 0; i
< 3; i
++) {
1202 data
->manual_pwm_ctl
[i
] = 0xff;
1205 /* Check if temperature channnels are reset manually or by some reason */
1206 tmp
= it87_read_value(client
, IT87_REG_TEMP_ENABLE
);
1207 if ((tmp
& 0x3f) == 0) {
1208 /* Temp1,Temp3=thermistor; Temp2=thermal diode */
1209 tmp
= (tmp
& 0xc0) | 0x2a;
1210 it87_write_value(client
, IT87_REG_TEMP_ENABLE
, tmp
);
1214 /* Check if voltage monitors are reset manually or by some reason */
1215 tmp
= it87_read_value(client
, IT87_REG_VIN_ENABLE
);
1216 if ((tmp
& 0xff) == 0) {
1217 /* Enable all voltage monitors */
1218 it87_write_value(client
, IT87_REG_VIN_ENABLE
, 0xff);
1221 /* Check if tachometers are reset manually or by some reason */
1222 data
->fan_main_ctrl
= it87_read_value(client
, IT87_REG_FAN_MAIN_CTRL
);
1223 if ((data
->fan_main_ctrl
& 0x70) == 0) {
1224 /* Enable all fan tachometers */
1225 data
->fan_main_ctrl
|= 0x70;
1226 it87_write_value(client
, IT87_REG_FAN_MAIN_CTRL
, data
->fan_main_ctrl
);
1228 data
->has_fan
= (data
->fan_main_ctrl
>> 4) & 0x07;
1230 /* Set tachometers to 16-bit mode if needed */
1231 if (data
->type
== it8716
|| data
->type
== it8718
) {
1232 tmp
= it87_read_value(client
, IT87_REG_FAN_16BIT
);
1233 if (~tmp
& 0x07 & data
->has_fan
) {
1234 dev_dbg(&client
->dev
,
1235 "Setting fan1-3 to 16-bit mode\n");
1236 it87_write_value(client
, IT87_REG_FAN_16BIT
,
1241 /* Set current fan mode registers and the default settings for the
1242 * other mode registers */
1243 for (i
= 0; i
< 3; i
++) {
1244 if (data
->fan_main_ctrl
& (1 << i
)) {
1246 tmp
= it87_read_value(client
, IT87_REG_PWM(i
));
1248 /* automatic pwm - not yet implemented, but
1249 * leave the settings made by the BIOS alone
1250 * until a change is requested via the sysfs
1254 data
->manual_pwm_ctl
[i
] = PWM_FROM_REG(tmp
);
1259 /* Start monitoring */
1260 it87_write_value(client
, IT87_REG_CONFIG
,
1261 (it87_read_value(client
, IT87_REG_CONFIG
) & 0x36)
1262 | (update_vbat
? 0x41 : 0x01));
1265 static struct it87_data
*it87_update_device(struct device
*dev
)
1267 struct i2c_client
*client
= to_i2c_client(dev
);
1268 struct it87_data
*data
= i2c_get_clientdata(client
);
1271 mutex_lock(&data
->update_lock
);
1273 if (time_after(jiffies
, data
->last_updated
+ HZ
+ HZ
/ 2)
1277 /* Cleared after each update, so reenable. Value
1278 returned by this read will be previous value */
1279 it87_write_value(client
, IT87_REG_CONFIG
,
1280 it87_read_value(client
, IT87_REG_CONFIG
) | 0x40);
1282 for (i
= 0; i
<= 7; i
++) {
1284 it87_read_value(client
, IT87_REG_VIN(i
));
1286 it87_read_value(client
, IT87_REG_VIN_MIN(i
));
1288 it87_read_value(client
, IT87_REG_VIN_MAX(i
));
1290 /* in8 (battery) has no limit registers */
1292 it87_read_value(client
, IT87_REG_VIN(8));
1294 for (i
= 0; i
< 3; i
++) {
1295 /* Skip disabled fans */
1296 if (!(data
->has_fan
& (1 << i
)))
1300 it87_read_value(client
, IT87_REG_FAN_MIN(i
));
1301 data
->fan
[i
] = it87_read_value(client
,
1303 /* Add high byte if in 16-bit mode */
1304 if (data
->type
== it8716
|| data
->type
== it8718
) {
1305 data
->fan
[i
] |= it87_read_value(client
,
1306 IT87_REG_FANX(i
)) << 8;
1307 data
->fan_min
[i
] |= it87_read_value(client
,
1308 IT87_REG_FANX_MIN(i
)) << 8;
1311 for (i
= 0; i
< 3; i
++) {
1313 it87_read_value(client
, IT87_REG_TEMP(i
));
1314 data
->temp_high
[i
] =
1315 it87_read_value(client
, IT87_REG_TEMP_HIGH(i
));
1317 it87_read_value(client
, IT87_REG_TEMP_LOW(i
));
1320 /* Newer chips don't have clock dividers */
1321 if ((data
->has_fan
& 0x07) && data
->type
!= it8716
1322 && data
->type
!= it8718
) {
1323 i
= it87_read_value(client
, IT87_REG_FAN_DIV
);
1324 data
->fan_div
[0] = i
& 0x07;
1325 data
->fan_div
[1] = (i
>> 3) & 0x07;
1326 data
->fan_div
[2] = (i
& 0x40) ? 3 : 1;
1330 it87_read_value(client
, IT87_REG_ALARM1
) |
1331 (it87_read_value(client
, IT87_REG_ALARM2
) << 8) |
1332 (it87_read_value(client
, IT87_REG_ALARM3
) << 16);
1333 data
->fan_main_ctrl
= it87_read_value(client
, IT87_REG_FAN_MAIN_CTRL
);
1335 data
->sensor
= it87_read_value(client
, IT87_REG_TEMP_ENABLE
);
1336 /* The 8705 does not have VID capability */
1337 if (data
->type
== it8712
|| data
->type
== it8716
) {
1338 data
->vid
= it87_read_value(client
, IT87_REG_VID
);
1339 /* The older IT8712F revisions had only 5 VID pins,
1340 but we assume it is always safe to read 6 bits. */
1343 data
->last_updated
= jiffies
;
1347 mutex_unlock(&data
->update_lock
);
1352 static int __init
sm_it87_init(void)
1356 res
= i2c_add_driver(&it87_driver
);
1360 if (!it87_find(&isa_address
)) {
1361 res
= i2c_isa_add_driver(&it87_isa_driver
);
1363 i2c_del_driver(&it87_driver
);
1371 static void __exit
sm_it87_exit(void)
1374 i2c_isa_del_driver(&it87_isa_driver
);
1375 i2c_del_driver(&it87_driver
);
1379 MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>");
1380 MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F, SiS950 driver");
1381 module_param(update_vbat
, bool, 0);
1382 MODULE_PARM_DESC(update_vbat
, "Update vbat if set else return powerup value");
1383 module_param(fix_pwm_polarity
, bool, 0);
1384 MODULE_PARM_DESC(fix_pwm_polarity
, "Force PWM polarity to active high (DANGEROUS)");
1385 MODULE_LICENSE("GPL");
1387 module_init(sm_it87_init
);
1388 module_exit(sm_it87_exit
);