2 * pc87360.c - Part of lm_sensors, Linux kernel modules
3 * for hardware monitoring
4 * Copyright (C) 2004 Jean Delvare <khali@linux-fr.org>
6 * Copied from smsc47m1.c:
7 * Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Supports the following chips:
25 * Chip #vin #fan #pwm #temp devid
26 * PC87360 - 2 2 - 0xE1
27 * PC87363 - 2 2 - 0xE8
28 * PC87364 - 3 3 - 0xE4
29 * PC87365 11 3 3 2 0xE5
30 * PC87366 11 3 3 3-4 0xE9
32 * This driver assumes that no more than one chip is present, and one of
33 * the standard Super-I/O addresses is used (0x2E/0x2F or 0x4E/0x4F).
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 static unsigned short address
;
51 static unsigned short extra_isa
[3];
54 enum chips
{ any_chip
, pc87360
, pc87363
, pc87364
, pc87365
, pc87366
};
57 module_param(init
, int, 0);
58 MODULE_PARM_DESC(init
,
59 "Chip initialization level:\n"
61 "*1: Forcibly enable internal voltage and temperature channels, except in9\n"
62 " 2: Forcibly enable all voltage and temperature channels, except in9\n"
63 " 3: Forcibly enable all voltage and temperature channels, including in9");
66 * Super-I/O registers and operations
69 #define DEV 0x07 /* Register: Logical device select */
70 #define DEVID 0x20 /* Register: Device ID */
71 #define ACT 0x30 /* Register: Device activation */
72 #define BASE 0x60 /* Register: Base address */
74 #define FSCM 0x09 /* Logical device: fans */
75 #define VLM 0x0d /* Logical device: voltages */
76 #define TMS 0x0e /* Logical device: temperatures */
77 static const u8 logdev
[3] = { FSCM
, VLM
, TMS
};
83 static inline void superio_outb(int sioaddr
, int reg
, int val
)
89 static inline int superio_inb(int sioaddr
, int reg
)
92 return inb(sioaddr
+1);
95 static inline void superio_exit(int sioaddr
)
98 outb(0x02, sioaddr
+1);
105 #define PC87360_EXTENT 0x10
106 #define PC87365_REG_BANK 0x09
110 * Fan registers and conversions
113 /* nr has to be 0 or 1 (PC87360/87363) or 2 (PC87364/87365/87366) */
114 #define PC87360_REG_PRESCALE(nr) (0x00 + 2 * (nr))
115 #define PC87360_REG_PWM(nr) (0x01 + 2 * (nr))
116 #define PC87360_REG_FAN_MIN(nr) (0x06 + 3 * (nr))
117 #define PC87360_REG_FAN(nr) (0x07 + 3 * (nr))
118 #define PC87360_REG_FAN_STATUS(nr) (0x08 + 3 * (nr))
120 #define FAN_FROM_REG(val,div) ((val) == 0 ? 0: \
121 480000 / ((val)*(div)))
122 #define FAN_TO_REG(val,div) ((val) <= 100 ? 0 : \
123 480000 / ((val)*(div)))
124 #define FAN_DIV_FROM_REG(val) (1 << ((val >> 5) & 0x03))
125 #define FAN_STATUS_FROM_REG(val) ((val) & 0x07)
127 #define FAN_CONFIG_MONITOR(val,nr) (((val) >> (2 + nr * 3)) & 1)
128 #define FAN_CONFIG_CONTROL(val,nr) (((val) >> (3 + nr * 3)) & 1)
129 #define FAN_CONFIG_INVERT(val,nr) (((val) >> (4 + nr * 3)) & 1)
131 #define PWM_FROM_REG(val,inv) ((inv) ? 255 - (val) : (val))
132 static inline u8
PWM_TO_REG(int val
, int inv
)
144 * Voltage registers and conversions
147 #define PC87365_REG_IN_CONVRATE 0x07
148 #define PC87365_REG_IN_CONFIG 0x08
149 #define PC87365_REG_IN 0x0B
150 #define PC87365_REG_IN_MIN 0x0D
151 #define PC87365_REG_IN_MAX 0x0C
152 #define PC87365_REG_IN_STATUS 0x0A
153 #define PC87365_REG_IN_ALARMS1 0x00
154 #define PC87365_REG_IN_ALARMS2 0x01
155 #define PC87365_REG_VID 0x06
157 #define IN_FROM_REG(val,ref) (((val) * (ref) + 128) / 256)
158 #define IN_TO_REG(val,ref) ((val) < 0 ? 0 : \
159 (val)*256 >= (ref)*255 ? 255: \
160 ((val) * 256 + (ref)/2) / (ref))
163 * Temperature registers and conversions
166 #define PC87365_REG_TEMP_CONFIG 0x08
167 #define PC87365_REG_TEMP 0x0B
168 #define PC87365_REG_TEMP_MIN 0x0D
169 #define PC87365_REG_TEMP_MAX 0x0C
170 #define PC87365_REG_TEMP_CRIT 0x0E
171 #define PC87365_REG_TEMP_STATUS 0x0A
172 #define PC87365_REG_TEMP_ALARMS 0x00
174 #define TEMP_FROM_REG(val) ((val) * 1000)
175 #define TEMP_TO_REG(val) ((val) < -55000 ? -55 : \
176 (val) > 127000 ? 127 : \
177 (val) < 0 ? ((val) - 500) / 1000 : \
178 ((val) + 500) / 1000)
181 * Client data (each client gets its own)
184 struct pc87360_data
{
185 struct i2c_client client
;
186 struct class_device
*class_dev
;
188 struct mutex update_lock
;
189 char valid
; /* !=0 if following fields are valid */
190 unsigned long last_updated
; /* In jiffies */
194 u8 fannr
, innr
, tempnr
;
196 u8 fan
[3]; /* Register value */
197 u8 fan_min
[3]; /* Register value */
198 u8 fan_status
[3]; /* Register value */
199 u8 pwm
[3]; /* Register value */
200 u16 fan_conf
; /* Configuration register values, combined */
202 u16 in_vref
; /* 1 mV/bit */
203 u8 in
[14]; /* Register value */
204 u8 in_min
[14]; /* Register value */
205 u8 in_max
[14]; /* Register value */
206 u8 in_crit
[3]; /* Register value */
207 u8 in_status
[14]; /* Register value */
208 u16 in_alarms
; /* Register values, combined, masked */
209 u8 vid_conf
; /* Configuration register value */
211 u8 vid
; /* Register value */
213 s8 temp
[3]; /* Register value */
214 s8 temp_min
[3]; /* Register value */
215 s8 temp_max
[3]; /* Register value */
216 s8 temp_crit
[3]; /* Register value */
217 u8 temp_status
[3]; /* Register value */
218 u8 temp_alarms
; /* Register value, masked */
222 * Functions declaration
225 static int pc87360_detect(struct i2c_adapter
*adapter
);
226 static int pc87360_detach_client(struct i2c_client
*client
);
228 static int pc87360_read_value(struct pc87360_data
*data
, u8 ldi
, u8 bank
,
230 static void pc87360_write_value(struct pc87360_data
*data
, u8 ldi
, u8 bank
,
232 static void pc87360_init_client(struct i2c_client
*client
, int use_thermistors
);
233 static struct pc87360_data
*pc87360_update_device(struct device
*dev
);
236 * Driver data (common to all clients)
239 static struct i2c_driver pc87360_driver
= {
241 .owner
= THIS_MODULE
,
244 .attach_adapter
= pc87360_detect
,
245 .detach_client
= pc87360_detach_client
,
252 static ssize_t
show_fan_input(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
254 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
255 struct pc87360_data
*data
= pc87360_update_device(dev
);
256 return sprintf(buf
, "%u\n", FAN_FROM_REG(data
->fan
[attr
->index
],
257 FAN_DIV_FROM_REG(data
->fan_status
[attr
->index
])));
259 static ssize_t
show_fan_min(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
261 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
262 struct pc87360_data
*data
= pc87360_update_device(dev
);
263 return sprintf(buf
, "%u\n", FAN_FROM_REG(data
->fan_min
[attr
->index
],
264 FAN_DIV_FROM_REG(data
->fan_status
[attr
->index
])));
266 static ssize_t
show_fan_div(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
268 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
269 struct pc87360_data
*data
= pc87360_update_device(dev
);
270 return sprintf(buf
, "%u\n",
271 FAN_DIV_FROM_REG(data
->fan_status
[attr
->index
]));
273 static ssize_t
show_fan_status(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
275 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
276 struct pc87360_data
*data
= pc87360_update_device(dev
);
277 return sprintf(buf
, "%u\n",
278 FAN_STATUS_FROM_REG(data
->fan_status
[attr
->index
]));
280 static ssize_t
set_fan_min(struct device
*dev
, struct device_attribute
*devattr
, const char *buf
,
283 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
284 struct i2c_client
*client
= to_i2c_client(dev
);
285 struct pc87360_data
*data
= i2c_get_clientdata(client
);
286 long fan_min
= simple_strtol(buf
, NULL
, 10);
288 mutex_lock(&data
->update_lock
);
289 fan_min
= FAN_TO_REG(fan_min
, FAN_DIV_FROM_REG(data
->fan_status
[attr
->index
]));
291 /* If it wouldn't fit, change clock divisor */
293 && (data
->fan_status
[attr
->index
] & 0x60) != 0x60) {
295 data
->fan
[attr
->index
] >>= 1;
296 data
->fan_status
[attr
->index
] += 0x20;
298 data
->fan_min
[attr
->index
] = fan_min
> 255 ? 255 : fan_min
;
299 pc87360_write_value(data
, LD_FAN
, NO_BANK
, PC87360_REG_FAN_MIN(attr
->index
),
300 data
->fan_min
[attr
->index
]);
302 /* Write new divider, preserve alarm bits */
303 pc87360_write_value(data
, LD_FAN
, NO_BANK
, PC87360_REG_FAN_STATUS(attr
->index
),
304 data
->fan_status
[attr
->index
] & 0xF9);
305 mutex_unlock(&data
->update_lock
);
310 static struct sensor_device_attribute fan_input
[] = {
311 SENSOR_ATTR(fan1_input
, S_IRUGO
, show_fan_input
, NULL
, 0),
312 SENSOR_ATTR(fan2_input
, S_IRUGO
, show_fan_input
, NULL
, 1),
313 SENSOR_ATTR(fan3_input
, S_IRUGO
, show_fan_input
, NULL
, 2),
315 static struct sensor_device_attribute fan_status
[] = {
316 SENSOR_ATTR(fan1_status
, S_IRUGO
, show_fan_status
, NULL
, 0),
317 SENSOR_ATTR(fan2_status
, S_IRUGO
, show_fan_status
, NULL
, 1),
318 SENSOR_ATTR(fan3_status
, S_IRUGO
, show_fan_status
, NULL
, 2),
320 static struct sensor_device_attribute fan_div
[] = {
321 SENSOR_ATTR(fan1_div
, S_IRUGO
, show_fan_div
, NULL
, 0),
322 SENSOR_ATTR(fan2_div
, S_IRUGO
, show_fan_div
, NULL
, 1),
323 SENSOR_ATTR(fan3_div
, S_IRUGO
, show_fan_div
, NULL
, 2),
325 static struct sensor_device_attribute fan_min
[] = {
326 SENSOR_ATTR(fan1_min
, S_IWUSR
| S_IRUGO
, show_fan_min
, set_fan_min
, 0),
327 SENSOR_ATTR(fan2_min
, S_IWUSR
| S_IRUGO
, show_fan_min
, set_fan_min
, 1),
328 SENSOR_ATTR(fan3_min
, S_IWUSR
| S_IRUGO
, show_fan_min
, set_fan_min
, 2),
331 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
333 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
334 struct pc87360_data
*data
= pc87360_update_device(dev
);
335 return sprintf(buf
, "%u\n",
336 PWM_FROM_REG(data
->pwm
[attr
->index
],
337 FAN_CONFIG_INVERT(data
->fan_conf
,
340 static ssize_t
set_pwm(struct device
*dev
, struct device_attribute
*devattr
, const char *buf
,
343 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
344 struct i2c_client
*client
= to_i2c_client(dev
);
345 struct pc87360_data
*data
= i2c_get_clientdata(client
);
346 long val
= simple_strtol(buf
, NULL
, 10);
348 mutex_lock(&data
->update_lock
);
349 data
->pwm
[attr
->index
] = PWM_TO_REG(val
,
350 FAN_CONFIG_INVERT(data
->fan_conf
, attr
->index
));
351 pc87360_write_value(data
, LD_FAN
, NO_BANK
, PC87360_REG_PWM(attr
->index
),
352 data
->pwm
[attr
->index
]);
353 mutex_unlock(&data
->update_lock
);
357 static struct sensor_device_attribute pwm
[] = {
358 SENSOR_ATTR(pwm1
, S_IWUSR
| S_IRUGO
, show_pwm
, set_pwm
, 0),
359 SENSOR_ATTR(pwm2
, S_IWUSR
| S_IRUGO
, show_pwm
, set_pwm
, 1),
360 SENSOR_ATTR(pwm3
, S_IWUSR
| S_IRUGO
, show_pwm
, set_pwm
, 2),
363 static ssize_t
show_in_input(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
365 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
366 struct pc87360_data
*data
= pc87360_update_device(dev
);
367 return sprintf(buf
, "%u\n", IN_FROM_REG(data
->in
[attr
->index
],
370 static ssize_t
show_in_min(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
372 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
373 struct pc87360_data
*data
= pc87360_update_device(dev
);
374 return sprintf(buf
, "%u\n", IN_FROM_REG(data
->in_min
[attr
->index
],
377 static ssize_t
show_in_max(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
379 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
380 struct pc87360_data
*data
= pc87360_update_device(dev
);
381 return sprintf(buf
, "%u\n", IN_FROM_REG(data
->in_max
[attr
->index
],
384 static ssize_t
show_in_status(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
386 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
387 struct pc87360_data
*data
= pc87360_update_device(dev
);
388 return sprintf(buf
, "%u\n", data
->in_status
[attr
->index
]);
390 static ssize_t
set_in_min(struct device
*dev
, struct device_attribute
*devattr
, const char *buf
,
393 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
394 struct i2c_client
*client
= to_i2c_client(dev
);
395 struct pc87360_data
*data
= i2c_get_clientdata(client
);
396 long val
= simple_strtol(buf
, NULL
, 10);
398 mutex_lock(&data
->update_lock
);
399 data
->in_min
[attr
->index
] = IN_TO_REG(val
, data
->in_vref
);
400 pc87360_write_value(data
, LD_IN
, attr
->index
, PC87365_REG_IN_MIN
,
401 data
->in_min
[attr
->index
]);
402 mutex_unlock(&data
->update_lock
);
405 static ssize_t
set_in_max(struct device
*dev
, struct device_attribute
*devattr
, const char *buf
,
408 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
409 struct i2c_client
*client
= to_i2c_client(dev
);
410 struct pc87360_data
*data
= i2c_get_clientdata(client
);
411 long val
= simple_strtol(buf
, NULL
, 10);
413 mutex_lock(&data
->update_lock
);
414 data
->in_max
[attr
->index
] = IN_TO_REG(val
,
416 pc87360_write_value(data
, LD_IN
, attr
->index
, PC87365_REG_IN_MAX
,
417 data
->in_max
[attr
->index
]);
418 mutex_unlock(&data
->update_lock
);
422 static struct sensor_device_attribute in_input
[] = {
423 SENSOR_ATTR(in0_input
, S_IRUGO
, show_in_input
, NULL
, 0),
424 SENSOR_ATTR(in1_input
, S_IRUGO
, show_in_input
, NULL
, 1),
425 SENSOR_ATTR(in2_input
, S_IRUGO
, show_in_input
, NULL
, 2),
426 SENSOR_ATTR(in3_input
, S_IRUGO
, show_in_input
, NULL
, 3),
427 SENSOR_ATTR(in4_input
, S_IRUGO
, show_in_input
, NULL
, 4),
428 SENSOR_ATTR(in5_input
, S_IRUGO
, show_in_input
, NULL
, 5),
429 SENSOR_ATTR(in6_input
, S_IRUGO
, show_in_input
, NULL
, 6),
430 SENSOR_ATTR(in7_input
, S_IRUGO
, show_in_input
, NULL
, 7),
431 SENSOR_ATTR(in8_input
, S_IRUGO
, show_in_input
, NULL
, 8),
432 SENSOR_ATTR(in9_input
, S_IRUGO
, show_in_input
, NULL
, 9),
433 SENSOR_ATTR(in10_input
, S_IRUGO
, show_in_input
, NULL
, 10),
435 static struct sensor_device_attribute in_status
[] = {
436 SENSOR_ATTR(in0_status
, S_IRUGO
, show_in_status
, NULL
, 0),
437 SENSOR_ATTR(in1_status
, S_IRUGO
, show_in_status
, NULL
, 1),
438 SENSOR_ATTR(in2_status
, S_IRUGO
, show_in_status
, NULL
, 2),
439 SENSOR_ATTR(in3_status
, S_IRUGO
, show_in_status
, NULL
, 3),
440 SENSOR_ATTR(in4_status
, S_IRUGO
, show_in_status
, NULL
, 4),
441 SENSOR_ATTR(in5_status
, S_IRUGO
, show_in_status
, NULL
, 5),
442 SENSOR_ATTR(in6_status
, S_IRUGO
, show_in_status
, NULL
, 6),
443 SENSOR_ATTR(in7_status
, S_IRUGO
, show_in_status
, NULL
, 7),
444 SENSOR_ATTR(in8_status
, S_IRUGO
, show_in_status
, NULL
, 8),
445 SENSOR_ATTR(in9_status
, S_IRUGO
, show_in_status
, NULL
, 9),
446 SENSOR_ATTR(in10_status
, S_IRUGO
, show_in_status
, NULL
, 10),
448 static struct sensor_device_attribute in_min
[] = {
449 SENSOR_ATTR(in0_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 0),
450 SENSOR_ATTR(in1_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 1),
451 SENSOR_ATTR(in2_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 2),
452 SENSOR_ATTR(in3_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 3),
453 SENSOR_ATTR(in4_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 4),
454 SENSOR_ATTR(in5_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 5),
455 SENSOR_ATTR(in6_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 6),
456 SENSOR_ATTR(in7_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 7),
457 SENSOR_ATTR(in8_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 8),
458 SENSOR_ATTR(in9_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 9),
459 SENSOR_ATTR(in10_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 10),
461 static struct sensor_device_attribute in_max
[] = {
462 SENSOR_ATTR(in0_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 0),
463 SENSOR_ATTR(in1_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 1),
464 SENSOR_ATTR(in2_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 2),
465 SENSOR_ATTR(in3_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 3),
466 SENSOR_ATTR(in4_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 4),
467 SENSOR_ATTR(in5_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 5),
468 SENSOR_ATTR(in6_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 6),
469 SENSOR_ATTR(in7_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 7),
470 SENSOR_ATTR(in8_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 8),
471 SENSOR_ATTR(in9_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 9),
472 SENSOR_ATTR(in10_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 10),
475 static ssize_t
show_therm_input(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
477 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
478 struct pc87360_data
*data
= pc87360_update_device(dev
);
479 return sprintf(buf
, "%u\n", IN_FROM_REG(data
->in
[attr
->index
],
482 static ssize_t
show_therm_min(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
484 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
485 struct pc87360_data
*data
= pc87360_update_device(dev
);
486 return sprintf(buf
, "%u\n", IN_FROM_REG(data
->in_min
[attr
->index
],
489 static ssize_t
show_therm_max(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
491 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
492 struct pc87360_data
*data
= pc87360_update_device(dev
);
493 return sprintf(buf
, "%u\n", IN_FROM_REG(data
->in_max
[attr
->index
],
496 static ssize_t
show_therm_crit(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
498 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
499 struct pc87360_data
*data
= pc87360_update_device(dev
);
500 return sprintf(buf
, "%u\n", IN_FROM_REG(data
->in_crit
[attr
->index
-11],
503 static ssize_t
show_therm_status(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
505 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
506 struct pc87360_data
*data
= pc87360_update_device(dev
);
507 return sprintf(buf
, "%u\n", data
->in_status
[attr
->index
]);
509 static ssize_t
set_therm_min(struct device
*dev
, struct device_attribute
*devattr
, const char *buf
,
512 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
513 struct i2c_client
*client
= to_i2c_client(dev
);
514 struct pc87360_data
*data
= i2c_get_clientdata(client
);
515 long val
= simple_strtol(buf
, NULL
, 10);
517 mutex_lock(&data
->update_lock
);
518 data
->in_min
[attr
->index
] = IN_TO_REG(val
, data
->in_vref
);
519 pc87360_write_value(data
, LD_IN
, attr
->index
, PC87365_REG_TEMP_MIN
,
520 data
->in_min
[attr
->index
]);
521 mutex_unlock(&data
->update_lock
);
524 static ssize_t
set_therm_max(struct device
*dev
, struct device_attribute
*devattr
, const char *buf
,
527 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
528 struct i2c_client
*client
= to_i2c_client(dev
);
529 struct pc87360_data
*data
= i2c_get_clientdata(client
);
530 long val
= simple_strtol(buf
, NULL
, 10);
532 mutex_lock(&data
->update_lock
);
533 data
->in_max
[attr
->index
] = IN_TO_REG(val
, data
->in_vref
);
534 pc87360_write_value(data
, LD_IN
, attr
->index
, PC87365_REG_TEMP_MAX
,
535 data
->in_max
[attr
->index
]);
536 mutex_unlock(&data
->update_lock
);
539 static ssize_t
set_therm_crit(struct device
*dev
, struct device_attribute
*devattr
, const char *buf
,
542 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
543 struct i2c_client
*client
= to_i2c_client(dev
);
544 struct pc87360_data
*data
= i2c_get_clientdata(client
);
545 long val
= simple_strtol(buf
, NULL
, 10);
547 mutex_lock(&data
->update_lock
);
548 data
->in_crit
[attr
->index
-11] = IN_TO_REG(val
, data
->in_vref
);
549 pc87360_write_value(data
, LD_IN
, attr
->index
, PC87365_REG_TEMP_CRIT
,
550 data
->in_crit
[attr
->index
-11]);
551 mutex_unlock(&data
->update_lock
);
555 /* the +11 term below reflects the fact that VLM units 11,12,13 are
556 used in the chip to measure voltage across the thermistors
558 static struct sensor_device_attribute therm_input
[] = {
559 SENSOR_ATTR(temp4_input
, S_IRUGO
, show_therm_input
, NULL
, 0+11),
560 SENSOR_ATTR(temp5_input
, S_IRUGO
, show_therm_input
, NULL
, 1+11),
561 SENSOR_ATTR(temp6_input
, S_IRUGO
, show_therm_input
, NULL
, 2+11),
563 static struct sensor_device_attribute therm_status
[] = {
564 SENSOR_ATTR(temp4_status
, S_IRUGO
, show_therm_status
, NULL
, 0+11),
565 SENSOR_ATTR(temp5_status
, S_IRUGO
, show_therm_status
, NULL
, 1+11),
566 SENSOR_ATTR(temp6_status
, S_IRUGO
, show_therm_status
, NULL
, 2+11),
568 static struct sensor_device_attribute therm_min
[] = {
569 SENSOR_ATTR(temp4_min
, S_IRUGO
| S_IWUSR
,
570 show_therm_min
, set_therm_min
, 0+11),
571 SENSOR_ATTR(temp5_min
, S_IRUGO
| S_IWUSR
,
572 show_therm_min
, set_therm_min
, 1+11),
573 SENSOR_ATTR(temp6_min
, S_IRUGO
| S_IWUSR
,
574 show_therm_min
, set_therm_min
, 2+11),
576 static struct sensor_device_attribute therm_max
[] = {
577 SENSOR_ATTR(temp4_max
, S_IRUGO
| S_IWUSR
,
578 show_therm_max
, set_therm_max
, 0+11),
579 SENSOR_ATTR(temp5_max
, S_IRUGO
| S_IWUSR
,
580 show_therm_max
, set_therm_max
, 1+11),
581 SENSOR_ATTR(temp6_max
, S_IRUGO
| S_IWUSR
,
582 show_therm_max
, set_therm_max
, 2+11),
584 static struct sensor_device_attribute therm_crit
[] = {
585 SENSOR_ATTR(temp4_crit
, S_IRUGO
| S_IWUSR
,
586 show_therm_crit
, set_therm_crit
, 0+11),
587 SENSOR_ATTR(temp5_crit
, S_IRUGO
| S_IWUSR
,
588 show_therm_crit
, set_therm_crit
, 1+11),
589 SENSOR_ATTR(temp6_crit
, S_IRUGO
| S_IWUSR
,
590 show_therm_crit
, set_therm_crit
, 2+11),
593 static ssize_t
show_vid(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
595 struct pc87360_data
*data
= pc87360_update_device(dev
);
596 return sprintf(buf
, "%u\n", vid_from_reg(data
->vid
, data
->vrm
));
598 static DEVICE_ATTR(cpu0_vid
, S_IRUGO
, show_vid
, NULL
);
600 static ssize_t
show_vrm(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
602 struct pc87360_data
*data
= pc87360_update_device(dev
);
603 return sprintf(buf
, "%u\n", data
->vrm
);
605 static ssize_t
set_vrm(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
607 struct i2c_client
*client
= to_i2c_client(dev
);
608 struct pc87360_data
*data
= i2c_get_clientdata(client
);
609 data
->vrm
= simple_strtoul(buf
, NULL
, 10);
612 static DEVICE_ATTR(vrm
, S_IRUGO
| S_IWUSR
, show_vrm
, set_vrm
);
614 static ssize_t
show_in_alarms(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
616 struct pc87360_data
*data
= pc87360_update_device(dev
);
617 return sprintf(buf
, "%u\n", data
->in_alarms
);
619 static DEVICE_ATTR(alarms_in
, S_IRUGO
, show_in_alarms
, NULL
);
621 static ssize_t
show_temp_input(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
623 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
624 struct pc87360_data
*data
= pc87360_update_device(dev
);
625 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp
[attr
->index
]));
627 static ssize_t
show_temp_min(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
629 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
630 struct pc87360_data
*data
= pc87360_update_device(dev
);
631 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_min
[attr
->index
]));
633 static ssize_t
show_temp_max(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
635 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
636 struct pc87360_data
*data
= pc87360_update_device(dev
);
637 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_max
[attr
->index
]));
639 static ssize_t
show_temp_crit(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
641 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
642 struct pc87360_data
*data
= pc87360_update_device(dev
);
643 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_crit
[attr
->index
]));
645 static ssize_t
show_temp_status(struct device
*dev
, struct device_attribute
*devattr
, char *buf
)
647 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
648 struct pc87360_data
*data
= pc87360_update_device(dev
);
649 return sprintf(buf
, "%d\n", data
->temp_status
[attr
->index
]);
651 static ssize_t
set_temp_min(struct device
*dev
, struct device_attribute
*devattr
, const char *buf
,
654 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
655 struct i2c_client
*client
= to_i2c_client(dev
);
656 struct pc87360_data
*data
= i2c_get_clientdata(client
);
657 long val
= simple_strtol(buf
, NULL
, 10);
659 mutex_lock(&data
->update_lock
);
660 data
->temp_min
[attr
->index
] = TEMP_TO_REG(val
);
661 pc87360_write_value(data
, LD_TEMP
, attr
->index
, PC87365_REG_TEMP_MIN
,
662 data
->temp_min
[attr
->index
]);
663 mutex_unlock(&data
->update_lock
);
666 static ssize_t
set_temp_max(struct device
*dev
, struct device_attribute
*devattr
, const char *buf
,
669 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
670 struct i2c_client
*client
= to_i2c_client(dev
);
671 struct pc87360_data
*data
= i2c_get_clientdata(client
);
672 long val
= simple_strtol(buf
, NULL
, 10);
674 mutex_lock(&data
->update_lock
);
675 data
->temp_max
[attr
->index
] = TEMP_TO_REG(val
);
676 pc87360_write_value(data
, LD_TEMP
, attr
->index
, PC87365_REG_TEMP_MAX
,
677 data
->temp_max
[attr
->index
]);
678 mutex_unlock(&data
->update_lock
);
681 static ssize_t
set_temp_crit(struct device
*dev
, struct device_attribute
*devattr
, const char *buf
,
684 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
685 struct i2c_client
*client
= to_i2c_client(dev
);
686 struct pc87360_data
*data
= i2c_get_clientdata(client
);
687 long val
= simple_strtol(buf
, NULL
, 10);
689 mutex_lock(&data
->update_lock
);
690 data
->temp_crit
[attr
->index
] = TEMP_TO_REG(val
);
691 pc87360_write_value(data
, LD_TEMP
, attr
->index
, PC87365_REG_TEMP_CRIT
,
692 data
->temp_crit
[attr
->index
]);
693 mutex_unlock(&data
->update_lock
);
697 static struct sensor_device_attribute temp_input
[] = {
698 SENSOR_ATTR(temp1_input
, S_IRUGO
, show_temp_input
, NULL
, 0),
699 SENSOR_ATTR(temp2_input
, S_IRUGO
, show_temp_input
, NULL
, 1),
700 SENSOR_ATTR(temp3_input
, S_IRUGO
, show_temp_input
, NULL
, 2),
702 static struct sensor_device_attribute temp_status
[] = {
703 SENSOR_ATTR(temp1_status
, S_IRUGO
, show_temp_status
, NULL
, 0),
704 SENSOR_ATTR(temp2_status
, S_IRUGO
, show_temp_status
, NULL
, 1),
705 SENSOR_ATTR(temp3_status
, S_IRUGO
, show_temp_status
, NULL
, 2),
707 static struct sensor_device_attribute temp_min
[] = {
708 SENSOR_ATTR(temp1_min
, S_IRUGO
| S_IWUSR
,
709 show_temp_min
, set_temp_min
, 0),
710 SENSOR_ATTR(temp2_min
, S_IRUGO
| S_IWUSR
,
711 show_temp_min
, set_temp_min
, 1),
712 SENSOR_ATTR(temp3_min
, S_IRUGO
| S_IWUSR
,
713 show_temp_min
, set_temp_min
, 2),
715 static struct sensor_device_attribute temp_max
[] = {
716 SENSOR_ATTR(temp1_max
, S_IRUGO
| S_IWUSR
,
717 show_temp_max
, set_temp_max
, 0),
718 SENSOR_ATTR(temp2_max
, S_IRUGO
| S_IWUSR
,
719 show_temp_max
, set_temp_max
, 1),
720 SENSOR_ATTR(temp3_max
, S_IRUGO
| S_IWUSR
,
721 show_temp_max
, set_temp_max
, 2),
723 static struct sensor_device_attribute temp_crit
[] = {
724 SENSOR_ATTR(temp1_crit
, S_IRUGO
| S_IWUSR
,
725 show_temp_crit
, set_temp_crit
, 0),
726 SENSOR_ATTR(temp2_crit
, S_IRUGO
| S_IWUSR
,
727 show_temp_crit
, set_temp_crit
, 1),
728 SENSOR_ATTR(temp3_crit
, S_IRUGO
| S_IWUSR
,
729 show_temp_crit
, set_temp_crit
, 2),
732 static ssize_t
show_temp_alarms(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
734 struct pc87360_data
*data
= pc87360_update_device(dev
);
735 return sprintf(buf
, "%u\n", data
->temp_alarms
);
737 static DEVICE_ATTR(alarms_temp
, S_IRUGO
, show_temp_alarms
, NULL
);
740 * Device detection, registration and update
743 static int __init
pc87360_find(int sioaddr
, u8
*devid
, unsigned short *addresses
)
747 int nrdev
; /* logical device count */
749 /* No superio_enter */
751 /* Identify device */
752 val
= superio_inb(sioaddr
, DEVID
);
754 case 0xE1: /* PC87360 */
755 case 0xE8: /* PC87363 */
756 case 0xE4: /* PC87364 */
759 case 0xE5: /* PC87365 */
760 case 0xE9: /* PC87366 */
764 superio_exit(sioaddr
);
767 /* Remember the device id */
770 for (i
= 0; i
< nrdev
; i
++) {
771 /* select logical device */
772 superio_outb(sioaddr
, DEV
, logdev
[i
]);
774 val
= superio_inb(sioaddr
, ACT
);
776 printk(KERN_INFO
"pc87360: Device 0x%02x not "
777 "activated\n", logdev
[i
]);
781 val
= (superio_inb(sioaddr
, BASE
) << 8)
782 | superio_inb(sioaddr
, BASE
+ 1);
784 printk(KERN_INFO
"pc87360: Base address not set for "
785 "device 0x%02x\n", logdev
[i
]);
791 if (i
==0) { /* Fans */
792 confreg
[0] = superio_inb(sioaddr
, 0xF0);
793 confreg
[1] = superio_inb(sioaddr
, 0xF1);
796 printk(KERN_DEBUG
"pc87360: Fan 1: mon=%d "
797 "ctrl=%d inv=%d\n", (confreg
[0]>>2)&1,
798 (confreg
[0]>>3)&1, (confreg
[0]>>4)&1);
799 printk(KERN_DEBUG
"pc87360: Fan 2: mon=%d "
800 "ctrl=%d inv=%d\n", (confreg
[0]>>5)&1,
801 (confreg
[0]>>6)&1, (confreg
[0]>>7)&1);
802 printk(KERN_DEBUG
"pc87360: Fan 3: mon=%d "
803 "ctrl=%d inv=%d\n", confreg
[1]&1,
804 (confreg
[1]>>1)&1, (confreg
[1]>>2)&1);
806 } else if (i
==1) { /* Voltages */
807 /* Are we using thermistors? */
808 if (*devid
== 0xE9) { /* PC87366 */
809 /* These registers are not logical-device
810 specific, just that we won't need them if
811 we don't use the VLM device */
812 confreg
[2] = superio_inb(sioaddr
, 0x2B);
813 confreg
[3] = superio_inb(sioaddr
, 0x25);
815 if (confreg
[2] & 0x40) {
816 printk(KERN_INFO
"pc87360: Using "
817 "thermistors for temperature "
820 if (confreg
[3] & 0xE0) {
821 printk(KERN_INFO
"pc87360: VID "
822 "inputs routed (mode %u)\n",
829 superio_exit(sioaddr
);
833 static int pc87360_detect(struct i2c_adapter
*adapter
)
836 struct i2c_client
*client
;
837 struct pc87360_data
*data
;
839 const char *name
= "pc87360";
840 int use_thermistors
= 0;
843 if (!(data
= kzalloc(sizeof(struct pc87360_data
), GFP_KERNEL
)))
846 client
= &data
->client
;
848 i2c_set_clientdata(client
, data
);
849 client
->addr
= address
;
850 mutex_init(&data
->lock
);
851 client
->adapter
= adapter
;
852 client
->driver
= &pc87360_driver
;
869 data
->fannr
= extra_isa
[0] ? 3 : 0;
870 data
->innr
= extra_isa
[1] ? 11 : 0;
871 data
->tempnr
= extra_isa
[2] ? 2 : 0;
875 data
->fannr
= extra_isa
[0] ? 3 : 0;
876 data
->innr
= extra_isa
[1] ? 14 : 0;
877 data
->tempnr
= extra_isa
[2] ? 3 : 0;
881 strlcpy(client
->name
, name
, sizeof(client
->name
));
883 mutex_init(&data
->update_lock
);
885 for (i
= 0; i
< 3; i
++) {
886 if (((data
->address
[i
] = extra_isa
[i
]))
887 && !request_region(extra_isa
[i
], PC87360_EXTENT
,
888 pc87360_driver
.driver
.name
)) {
889 dev_err(&client
->dev
, "Region 0x%x-0x%x already "
890 "in use!\n", extra_isa
[i
],
891 extra_isa
[i
]+PC87360_EXTENT
-1);
892 for (i
--; i
>= 0; i
--)
893 release_region(extra_isa
[i
], PC87360_EXTENT
);
899 /* Retrieve the fans configuration from Super-I/O space */
901 data
->fan_conf
= confreg
[0] | (confreg
[1] << 8);
903 if ((err
= i2c_attach_client(client
)))
906 /* Use the correct reference voltage
907 Unless both the VLM and the TMS logical devices agree to
908 use an external Vref, the internal one is used. */
910 i
= pc87360_read_value(data
, LD_IN
, NO_BANK
,
911 PC87365_REG_IN_CONFIG
);
913 i
&= pc87360_read_value(data
, LD_TEMP
, NO_BANK
,
914 PC87365_REG_TEMP_CONFIG
);
916 data
->in_vref
= (i
&0x02) ? 3025 : 2966;
917 dev_dbg(&client
->dev
, "Using %s reference voltage\n",
918 (i
&0x02) ? "external" : "internal");
920 data
->vid_conf
= confreg
[3];
924 /* Fan clock dividers may be needed before any data is read */
925 for (i
= 0; i
< data
->fannr
; i
++) {
926 if (FAN_CONFIG_MONITOR(data
->fan_conf
, i
))
927 data
->fan_status
[i
] = pc87360_read_value(data
,
929 PC87360_REG_FAN_STATUS(i
));
933 if (devid
== 0xe9 && data
->address
[1]) /* PC87366 */
934 use_thermistors
= confreg
[2] & 0x40;
936 pc87360_init_client(client
, use_thermistors
);
939 /* Register sysfs hooks */
940 data
->class_dev
= hwmon_device_register(&client
->dev
);
941 if (IS_ERR(data
->class_dev
)) {
942 err
= PTR_ERR(data
->class_dev
);
947 for (i
= 0; i
< 11; i
++) {
948 device_create_file(dev
, &in_input
[i
].dev_attr
);
949 device_create_file(dev
, &in_min
[i
].dev_attr
);
950 device_create_file(dev
, &in_max
[i
].dev_attr
);
951 device_create_file(dev
, &in_status
[i
].dev_attr
);
953 device_create_file(dev
, &dev_attr_cpu0_vid
);
954 device_create_file(dev
, &dev_attr_vrm
);
955 device_create_file(dev
, &dev_attr_alarms_in
);
959 for (i
= 0; i
< data
->tempnr
; i
++) {
960 device_create_file(dev
, &temp_input
[i
].dev_attr
);
961 device_create_file(dev
, &temp_min
[i
].dev_attr
);
962 device_create_file(dev
, &temp_max
[i
].dev_attr
);
963 device_create_file(dev
, &temp_crit
[i
].dev_attr
);
964 device_create_file(dev
, &temp_status
[i
].dev_attr
);
966 device_create_file(dev
, &dev_attr_alarms_temp
);
969 if (data
->innr
== 14) {
970 for (i
= 0; i
< 3; i
++) {
971 device_create_file(dev
, &therm_input
[i
].dev_attr
);
972 device_create_file(dev
, &therm_min
[i
].dev_attr
);
973 device_create_file(dev
, &therm_max
[i
].dev_attr
);
974 device_create_file(dev
, &therm_crit
[i
].dev_attr
);
975 device_create_file(dev
, &therm_status
[i
].dev_attr
);
979 for (i
= 0; i
< data
->fannr
; i
++) {
980 if (FAN_CONFIG_MONITOR(data
->fan_conf
, i
)) {
981 device_create_file(dev
, &fan_input
[i
].dev_attr
);
982 device_create_file(dev
, &fan_min
[i
].dev_attr
);
983 device_create_file(dev
, &fan_div
[i
].dev_attr
);
984 device_create_file(dev
, &fan_status
[i
].dev_attr
);
986 if (FAN_CONFIG_CONTROL(data
->fan_conf
, i
))
987 device_create_file(dev
, &pwm
[i
].dev_attr
);
993 i2c_detach_client(client
);
995 for (i
= 0; i
< 3; i
++) {
996 if (data
->address
[i
]) {
997 release_region(data
->address
[i
], PC87360_EXTENT
);
1005 static int pc87360_detach_client(struct i2c_client
*client
)
1007 struct pc87360_data
*data
= i2c_get_clientdata(client
);
1010 hwmon_device_unregister(data
->class_dev
);
1012 if ((i
= i2c_detach_client(client
)))
1015 for (i
= 0; i
< 3; i
++) {
1016 if (data
->address
[i
]) {
1017 release_region(data
->address
[i
], PC87360_EXTENT
);
1025 /* ldi is the logical device index
1026 bank is for voltages and temperatures only */
1027 static int pc87360_read_value(struct pc87360_data
*data
, u8 ldi
, u8 bank
,
1032 mutex_lock(&(data
->lock
));
1033 if (bank
!= NO_BANK
)
1034 outb_p(bank
, data
->address
[ldi
] + PC87365_REG_BANK
);
1035 res
= inb_p(data
->address
[ldi
] + reg
);
1036 mutex_unlock(&(data
->lock
));
1041 static void pc87360_write_value(struct pc87360_data
*data
, u8 ldi
, u8 bank
,
1044 mutex_lock(&(data
->lock
));
1045 if (bank
!= NO_BANK
)
1046 outb_p(bank
, data
->address
[ldi
] + PC87365_REG_BANK
);
1047 outb_p(value
, data
->address
[ldi
] + reg
);
1048 mutex_unlock(&(data
->lock
));
1051 static void pc87360_init_client(struct i2c_client
*client
, int use_thermistors
)
1053 struct pc87360_data
*data
= i2c_get_clientdata(client
);
1055 const u8 init_in
[14] = { 2, 2, 2, 2, 2, 2, 2, 1, 1, 3, 1, 2, 2, 2 };
1056 const u8 init_temp
[3] = { 2, 2, 1 };
1059 if (init
>= 2 && data
->innr
) {
1060 reg
= pc87360_read_value(data
, LD_IN
, NO_BANK
,
1061 PC87365_REG_IN_CONVRATE
);
1062 dev_info(&client
->dev
, "VLM conversion set to "
1063 "1s period, 160us delay\n");
1064 pc87360_write_value(data
, LD_IN
, NO_BANK
,
1065 PC87365_REG_IN_CONVRATE
,
1066 (reg
& 0xC0) | 0x11);
1069 nr
= data
->innr
< 11 ? data
->innr
: 11;
1070 for (i
= 0; i
< nr
; i
++) {
1071 if (init
>= init_in
[i
]) {
1072 /* Forcibly enable voltage channel */
1073 reg
= pc87360_read_value(data
, LD_IN
, i
,
1074 PC87365_REG_IN_STATUS
);
1075 if (!(reg
& 0x01)) {
1076 dev_dbg(&client
->dev
, "Forcibly "
1077 "enabling in%d\n", i
);
1078 pc87360_write_value(data
, LD_IN
, i
,
1079 PC87365_REG_IN_STATUS
,
1080 (reg
& 0x68) | 0x87);
1085 /* We can't blindly trust the Super-I/O space configuration bit,
1086 most BIOS won't set it properly */
1087 for (i
= 11; i
< data
->innr
; i
++) {
1088 reg
= pc87360_read_value(data
, LD_IN
, i
,
1089 PC87365_REG_TEMP_STATUS
);
1090 use_thermistors
= use_thermistors
|| (reg
& 0x01);
1093 i
= use_thermistors
? 2 : 0;
1094 for (; i
< data
->tempnr
; i
++) {
1095 if (init
>= init_temp
[i
]) {
1096 /* Forcibly enable temperature channel */
1097 reg
= pc87360_read_value(data
, LD_TEMP
, i
,
1098 PC87365_REG_TEMP_STATUS
);
1099 if (!(reg
& 0x01)) {
1100 dev_dbg(&client
->dev
, "Forcibly "
1101 "enabling temp%d\n", i
+1);
1102 pc87360_write_value(data
, LD_TEMP
, i
,
1103 PC87365_REG_TEMP_STATUS
,
1109 if (use_thermistors
) {
1110 for (i
= 11; i
< data
->innr
; i
++) {
1111 if (init
>= init_in
[i
]) {
1112 /* The pin may already be used by thermal
1114 reg
= pc87360_read_value(data
, LD_TEMP
,
1115 (i
-11)/2, PC87365_REG_TEMP_STATUS
);
1117 dev_dbg(&client
->dev
, "Skipping "
1118 "temp%d, pin already in use "
1119 "by temp%d\n", i
-7, (i
-11)/2);
1123 /* Forcibly enable thermistor channel */
1124 reg
= pc87360_read_value(data
, LD_IN
, i
,
1125 PC87365_REG_IN_STATUS
);
1126 if (!(reg
& 0x01)) {
1127 dev_dbg(&client
->dev
, "Forcibly "
1128 "enabling temp%d\n", i
-7);
1129 pc87360_write_value(data
, LD_IN
, i
,
1130 PC87365_REG_TEMP_STATUS
,
1131 (reg
& 0x60) | 0x8F);
1138 reg
= pc87360_read_value(data
, LD_IN
, NO_BANK
,
1139 PC87365_REG_IN_CONFIG
);
1141 dev_dbg(&client
->dev
, "Forcibly "
1142 "enabling monitoring (VLM)\n");
1143 pc87360_write_value(data
, LD_IN
, NO_BANK
,
1144 PC87365_REG_IN_CONFIG
,
1150 reg
= pc87360_read_value(data
, LD_TEMP
, NO_BANK
,
1151 PC87365_REG_TEMP_CONFIG
);
1153 dev_dbg(&client
->dev
, "Forcibly enabling "
1154 "monitoring (TMS)\n");
1155 pc87360_write_value(data
, LD_TEMP
, NO_BANK
,
1156 PC87365_REG_TEMP_CONFIG
,
1161 /* Chip config as documented by National Semi. */
1162 pc87360_write_value(data
, LD_TEMP
, 0xF, 0xA, 0x08);
1163 /* We voluntarily omit the bank here, in case the
1164 sequence itself matters. It shouldn't be a problem,
1165 since nobody else is supposed to access the
1166 device at that point. */
1167 pc87360_write_value(data
, LD_TEMP
, NO_BANK
, 0xB, 0x04);
1168 pc87360_write_value(data
, LD_TEMP
, NO_BANK
, 0xC, 0x35);
1169 pc87360_write_value(data
, LD_TEMP
, NO_BANK
, 0xD, 0x05);
1170 pc87360_write_value(data
, LD_TEMP
, NO_BANK
, 0xE, 0x05);
1175 static void pc87360_autodiv(struct i2c_client
*client
, int nr
)
1177 struct pc87360_data
*data
= i2c_get_clientdata(client
);
1178 u8 old_min
= data
->fan_min
[nr
];
1180 /* Increase clock divider if needed and possible */
1181 if ((data
->fan_status
[nr
] & 0x04) /* overflow flag */
1182 || (data
->fan
[nr
] >= 224)) { /* next to overflow */
1183 if ((data
->fan_status
[nr
] & 0x60) != 0x60) {
1184 data
->fan_status
[nr
] += 0x20;
1185 data
->fan_min
[nr
] >>= 1;
1186 data
->fan
[nr
] >>= 1;
1187 dev_dbg(&client
->dev
, "Increasing "
1188 "clock divider to %d for fan %d\n",
1189 FAN_DIV_FROM_REG(data
->fan_status
[nr
]), nr
+1);
1192 /* Decrease clock divider if possible */
1193 while (!(data
->fan_min
[nr
] & 0x80) /* min "nails" divider */
1194 && data
->fan
[nr
] < 85 /* bad accuracy */
1195 && (data
->fan_status
[nr
] & 0x60) != 0x00) {
1196 data
->fan_status
[nr
] -= 0x20;
1197 data
->fan_min
[nr
] <<= 1;
1198 data
->fan
[nr
] <<= 1;
1199 dev_dbg(&client
->dev
, "Decreasing "
1200 "clock divider to %d for fan %d\n",
1201 FAN_DIV_FROM_REG(data
->fan_status
[nr
]),
1206 /* Write new fan min if it changed */
1207 if (old_min
!= data
->fan_min
[nr
]) {
1208 pc87360_write_value(data
, LD_FAN
, NO_BANK
,
1209 PC87360_REG_FAN_MIN(nr
),
1214 static struct pc87360_data
*pc87360_update_device(struct device
*dev
)
1216 struct i2c_client
*client
= to_i2c_client(dev
);
1217 struct pc87360_data
*data
= i2c_get_clientdata(client
);
1220 mutex_lock(&data
->update_lock
);
1222 if (time_after(jiffies
, data
->last_updated
+ HZ
* 2) || !data
->valid
) {
1223 dev_dbg(&client
->dev
, "Data update\n");
1226 for (i
= 0; i
< data
->fannr
; i
++) {
1227 if (FAN_CONFIG_MONITOR(data
->fan_conf
, i
)) {
1228 data
->fan_status
[i
] =
1229 pc87360_read_value(data
, LD_FAN
,
1230 NO_BANK
, PC87360_REG_FAN_STATUS(i
));
1231 data
->fan
[i
] = pc87360_read_value(data
, LD_FAN
,
1232 NO_BANK
, PC87360_REG_FAN(i
));
1233 data
->fan_min
[i
] = pc87360_read_value(data
,
1235 PC87360_REG_FAN_MIN(i
));
1236 /* Change clock divider if needed */
1237 pc87360_autodiv(client
, i
);
1238 /* Clear bits and write new divider */
1239 pc87360_write_value(data
, LD_FAN
, NO_BANK
,
1240 PC87360_REG_FAN_STATUS(i
),
1241 data
->fan_status
[i
]);
1243 if (FAN_CONFIG_CONTROL(data
->fan_conf
, i
))
1244 data
->pwm
[i
] = pc87360_read_value(data
, LD_FAN
,
1245 NO_BANK
, PC87360_REG_PWM(i
));
1249 for (i
= 0; i
< data
->innr
; i
++) {
1250 data
->in_status
[i
] = pc87360_read_value(data
, LD_IN
, i
,
1251 PC87365_REG_IN_STATUS
);
1253 pc87360_write_value(data
, LD_IN
, i
,
1254 PC87365_REG_IN_STATUS
,
1255 data
->in_status
[i
]);
1256 if ((data
->in_status
[i
] & 0x81) == 0x81) {
1257 data
->in
[i
] = pc87360_read_value(data
, LD_IN
,
1260 if (data
->in_status
[i
] & 0x01) {
1261 data
->in_min
[i
] = pc87360_read_value(data
,
1263 PC87365_REG_IN_MIN
);
1264 data
->in_max
[i
] = pc87360_read_value(data
,
1266 PC87365_REG_IN_MAX
);
1268 data
->in_crit
[i
-11] =
1269 pc87360_read_value(data
, LD_IN
,
1270 i
, PC87365_REG_TEMP_CRIT
);
1274 data
->in_alarms
= pc87360_read_value(data
, LD_IN
,
1275 NO_BANK
, PC87365_REG_IN_ALARMS1
)
1276 | ((pc87360_read_value(data
, LD_IN
,
1277 NO_BANK
, PC87365_REG_IN_ALARMS2
)
1279 data
->vid
= (data
->vid_conf
& 0xE0) ?
1280 pc87360_read_value(data
, LD_IN
,
1281 NO_BANK
, PC87365_REG_VID
) : 0x1F;
1285 for (i
= 0; i
< data
->tempnr
; i
++) {
1286 data
->temp_status
[i
] = pc87360_read_value(data
,
1288 PC87365_REG_TEMP_STATUS
);
1290 pc87360_write_value(data
, LD_TEMP
, i
,
1291 PC87365_REG_TEMP_STATUS
,
1292 data
->temp_status
[i
]);
1293 if ((data
->temp_status
[i
] & 0x81) == 0x81) {
1294 data
->temp
[i
] = pc87360_read_value(data
,
1298 if (data
->temp_status
[i
] & 0x01) {
1299 data
->temp_min
[i
] = pc87360_read_value(data
,
1301 PC87365_REG_TEMP_MIN
);
1302 data
->temp_max
[i
] = pc87360_read_value(data
,
1304 PC87365_REG_TEMP_MAX
);
1305 data
->temp_crit
[i
] = pc87360_read_value(data
,
1307 PC87365_REG_TEMP_CRIT
);
1311 data
->temp_alarms
= pc87360_read_value(data
, LD_TEMP
,
1312 NO_BANK
, PC87365_REG_TEMP_ALARMS
)
1316 data
->last_updated
= jiffies
;
1320 mutex_unlock(&data
->update_lock
);
1325 static int __init
pc87360_init(void)
1329 if (pc87360_find(0x2e, &devid
, extra_isa
)
1330 && pc87360_find(0x4e, &devid
, extra_isa
)) {
1331 printk(KERN_WARNING
"pc87360: PC8736x not detected, "
1332 "module not inserted.\n");
1336 /* Arbitrarily pick one of the addresses */
1337 for (i
= 0; i
< 3; i
++) {
1338 if (extra_isa
[i
] != 0x0000) {
1339 address
= extra_isa
[i
];
1344 if (address
== 0x0000) {
1345 printk(KERN_WARNING
"pc87360: No active logical device, "
1346 "module not inserted.\n");
1350 return i2c_isa_add_driver(&pc87360_driver
);
1353 static void __exit
pc87360_exit(void)
1355 i2c_isa_del_driver(&pc87360_driver
);
1359 MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
1360 MODULE_DESCRIPTION("PC8736x hardware monitor");
1361 MODULE_LICENSE("GPL");
1363 module_init(pc87360_init
);
1364 module_exit(pc87360_exit
);