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-sensor.h>
42 #include <linux/i2c-vid.h>
45 static unsigned short normal_i2c
[] = { I2C_CLIENT_END
};
46 static unsigned int normal_isa
[] = { 0, I2C_CLIENT_ISA_END
};
47 static struct i2c_force_data forces
[] = {{ NULL
}};
49 static unsigned int extra_isa
[3];
52 enum chips
{ any_chip
, pc87360
, pc87363
, pc87364
, pc87365
, pc87366
};
53 static struct i2c_address_data addr_data
= {
54 .normal_i2c
= normal_i2c
,
55 .normal_isa
= normal_isa
,
60 module_param(init
, int, 0);
61 MODULE_PARM_DESC(init
,
62 "Chip initialization level:\n"
64 "*1: Forcibly enable internal voltage and temperature channels, except in9\n"
65 " 2: Forcibly enable all voltage and temperature channels, except in9\n"
66 " 3: Forcibly enable all voltage and temperature channels, including in9");
69 * Super-I/O registers and operations
72 #define DEV 0x07 /* Register: Logical device select */
73 #define DEVID 0x20 /* Register: Device ID */
74 #define ACT 0x30 /* Register: Device activation */
75 #define BASE 0x60 /* Register: Base address */
77 #define FSCM 0x09 /* Logical device: fans */
78 #define VLM 0x0d /* Logical device: voltages */
79 #define TMS 0x0e /* Logical device: temperatures */
80 static const u8 logdev
[3] = { FSCM
, VLM
, TMS
};
86 static inline void superio_outb(int sioaddr
, int reg
, int val
)
92 static inline int superio_inb(int sioaddr
, int reg
)
95 return inb(sioaddr
+1);
98 static inline void superio_exit(int sioaddr
)
101 outb(0x02, sioaddr
+1);
108 #define PC87360_EXTENT 0x10
109 #define PC87365_REG_BANK 0x09
113 * Fan registers and conversions
116 /* nr has to be 0 or 1 (PC87360/87363) or 2 (PC87364/87365/87366) */
117 #define PC87360_REG_PRESCALE(nr) (0x00 + 2 * (nr))
118 #define PC87360_REG_PWM(nr) (0x01 + 2 * (nr))
119 #define PC87360_REG_FAN_MIN(nr) (0x06 + 3 * (nr))
120 #define PC87360_REG_FAN(nr) (0x07 + 3 * (nr))
121 #define PC87360_REG_FAN_STATUS(nr) (0x08 + 3 * (nr))
123 #define FAN_FROM_REG(val,div) ((val) == 0 ? 0: \
124 480000 / ((val)*(div)))
125 #define FAN_TO_REG(val,div) ((val) <= 100 ? 0 : \
126 480000 / ((val)*(div)))
127 #define FAN_DIV_FROM_REG(val) (1 << ((val >> 5) & 0x03))
128 #define FAN_STATUS_FROM_REG(val) ((val) & 0x07)
130 #define FAN_CONFIG_MONITOR(val,nr) (((val) >> (2 + nr * 3)) & 1)
131 #define FAN_CONFIG_CONTROL(val,nr) (((val) >> (3 + nr * 3)) & 1)
132 #define FAN_CONFIG_INVERT(val,nr) (((val) >> (4 + nr * 3)) & 1)
134 #define PWM_FROM_REG(val,inv) ((inv) ? 255 - (val) : (val))
135 static inline u8
PWM_TO_REG(int val
, int inv
)
147 * Voltage registers and conversions
150 #define PC87365_REG_IN_CONVRATE 0x07
151 #define PC87365_REG_IN_CONFIG 0x08
152 #define PC87365_REG_IN 0x0B
153 #define PC87365_REG_IN_MIN 0x0D
154 #define PC87365_REG_IN_MAX 0x0C
155 #define PC87365_REG_IN_STATUS 0x0A
156 #define PC87365_REG_IN_ALARMS1 0x00
157 #define PC87365_REG_IN_ALARMS2 0x01
158 #define PC87365_REG_VID 0x06
160 #define IN_FROM_REG(val,ref) (((val) * (ref) + 128) / 256)
161 #define IN_TO_REG(val,ref) ((val) < 0 ? 0 : \
162 (val)*256 >= (ref)*255 ? 255: \
163 ((val) * 256 + (ref)/2) / (ref))
166 * Temperature registers and conversions
169 #define PC87365_REG_TEMP_CONFIG 0x08
170 #define PC87365_REG_TEMP 0x0B
171 #define PC87365_REG_TEMP_MIN 0x0D
172 #define PC87365_REG_TEMP_MAX 0x0C
173 #define PC87365_REG_TEMP_CRIT 0x0E
174 #define PC87365_REG_TEMP_STATUS 0x0A
175 #define PC87365_REG_TEMP_ALARMS 0x00
177 #define TEMP_FROM_REG(val) ((val) * 1000)
178 #define TEMP_TO_REG(val) ((val) < -55000 ? -55 : \
179 (val) > 127000 ? 127 : \
180 (val) < 0 ? ((val) - 500) / 1000 : \
181 ((val) + 500) / 1000)
184 * Client data (each client gets its own)
187 struct pc87360_data
{
188 struct i2c_client client
;
189 struct semaphore lock
;
190 struct semaphore update_lock
;
191 char valid
; /* !=0 if following fields are valid */
192 unsigned long last_updated
; /* In jiffies */
196 u8 fannr
, innr
, tempnr
;
198 u8 fan
[3]; /* Register value */
199 u8 fan_min
[3]; /* Register value */
200 u8 fan_status
[3]; /* Register value */
201 u8 pwm
[3]; /* Register value */
202 u16 fan_conf
; /* Configuration register values, combined */
204 u16 in_vref
; /* 1 mV/bit */
205 u8 in
[14]; /* Register value */
206 u8 in_min
[14]; /* Register value */
207 u8 in_max
[14]; /* Register value */
208 u8 in_crit
[3]; /* Register value */
209 u8 in_status
[14]; /* Register value */
210 u16 in_alarms
; /* Register values, combined, masked */
211 u8 vid_conf
; /* Configuration register value */
213 u8 vid
; /* Register value */
215 s8 temp
[3]; /* Register value */
216 s8 temp_min
[3]; /* Register value */
217 s8 temp_max
[3]; /* Register value */
218 s8 temp_crit
[3]; /* Register value */
219 u8 temp_status
[3]; /* Register value */
220 u8 temp_alarms
; /* Register value, masked */
224 * Functions declaration
227 static int pc87360_attach_adapter(struct i2c_adapter
*adapter
);
228 static int pc87360_detect(struct i2c_adapter
*adapter
, int address
, int kind
);
229 static int pc87360_detach_client(struct i2c_client
*client
);
231 static int pc87360_read_value(struct pc87360_data
*data
, u8 ldi
, u8 bank
,
233 static void pc87360_write_value(struct pc87360_data
*data
, u8 ldi
, u8 bank
,
235 static void pc87360_init_client(struct i2c_client
*client
, int use_thermistors
);
236 static struct pc87360_data
*pc87360_update_device(struct device
*dev
);
239 * Driver data (common to all clients)
242 static struct i2c_driver pc87360_driver
= {
243 .owner
= THIS_MODULE
,
245 .flags
= I2C_DF_NOTIFY
,
246 .attach_adapter
= pc87360_attach_adapter
,
247 .detach_client
= pc87360_detach_client
,
254 static ssize_t
set_fan_min(struct device
*dev
, const char *buf
,
255 size_t count
, int nr
)
257 struct i2c_client
*client
= to_i2c_client(dev
);
258 struct pc87360_data
*data
= i2c_get_clientdata(client
);
259 long fan_min
= simple_strtol(buf
, NULL
, 10);
261 down(&data
->update_lock
);
262 fan_min
= FAN_TO_REG(fan_min
, FAN_DIV_FROM_REG(data
->fan_status
[nr
]));
264 /* If it wouldn't fit, change clock divisor */
266 && (data
->fan_status
[nr
] & 0x60) != 0x60) {
269 data
->fan_status
[nr
] += 0x20;
271 data
->fan_min
[nr
] = fan_min
> 255 ? 255 : fan_min
;
272 pc87360_write_value(data
, LD_FAN
, NO_BANK
, PC87360_REG_FAN_MIN(nr
),
275 /* Write new divider, preserve alarm bits */
276 pc87360_write_value(data
, LD_FAN
, NO_BANK
, PC87360_REG_FAN_STATUS(nr
),
277 data
->fan_status
[nr
] & 0xF9);
278 up(&data
->update_lock
);
283 #define show_and_set_fan(offset) \
284 static ssize_t show_fan##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \
286 struct pc87360_data *data = pc87360_update_device(dev); \
287 return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan[offset-1], \
288 FAN_DIV_FROM_REG(data->fan_status[offset-1]))); \
290 static ssize_t show_fan##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \
292 struct pc87360_data *data = pc87360_update_device(dev); \
293 return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan_min[offset-1], \
294 FAN_DIV_FROM_REG(data->fan_status[offset-1]))); \
296 static ssize_t show_fan##offset##_div(struct device *dev, struct device_attribute *attr, char *buf) \
298 struct pc87360_data *data = pc87360_update_device(dev); \
299 return sprintf(buf, "%u\n", \
300 FAN_DIV_FROM_REG(data->fan_status[offset-1])); \
302 static ssize_t show_fan##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \
304 struct pc87360_data *data = pc87360_update_device(dev); \
305 return sprintf(buf, "%u\n", \
306 FAN_STATUS_FROM_REG(data->fan_status[offset-1])); \
308 static ssize_t set_fan##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
311 return set_fan_min(dev, buf, count, offset-1); \
313 static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
314 show_fan##offset##_input, NULL); \
315 static DEVICE_ATTR(fan##offset##_min, S_IWUSR | S_IRUGO, \
316 show_fan##offset##_min, set_fan##offset##_min); \
317 static DEVICE_ATTR(fan##offset##_div, S_IRUGO, \
318 show_fan##offset##_div, NULL); \
319 static DEVICE_ATTR(fan##offset##_status, S_IRUGO, \
320 show_fan##offset##_status, NULL);
325 #define show_and_set_pwm(offset) \
326 static ssize_t show_pwm##offset(struct device *dev, struct device_attribute *attr, char *buf) \
328 struct pc87360_data *data = pc87360_update_device(dev); \
329 return sprintf(buf, "%u\n", \
330 PWM_FROM_REG(data->pwm[offset-1], \
331 FAN_CONFIG_INVERT(data->fan_conf, \
334 static ssize_t set_pwm##offset(struct device *dev, struct device_attribute *attr, const char *buf, \
337 struct i2c_client *client = to_i2c_client(dev); \
338 struct pc87360_data *data = i2c_get_clientdata(client); \
339 long val = simple_strtol(buf, NULL, 10); \
341 down(&data->update_lock); \
342 data->pwm[offset-1] = PWM_TO_REG(val, \
343 FAN_CONFIG_INVERT(data->fan_conf, offset-1)); \
344 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_PWM(offset-1), \
345 data->pwm[offset-1]); \
346 up(&data->update_lock); \
349 static DEVICE_ATTR(pwm##offset, S_IWUSR | S_IRUGO, \
350 show_pwm##offset, set_pwm##offset);
355 #define show_and_set_in(offset) \
356 static ssize_t show_in##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \
358 struct pc87360_data *data = pc87360_update_device(dev); \
359 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \
362 static ssize_t show_in##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \
364 struct pc87360_data *data = pc87360_update_device(dev); \
365 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \
368 static ssize_t show_in##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \
370 struct pc87360_data *data = pc87360_update_device(dev); \
371 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \
374 static ssize_t show_in##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \
376 struct pc87360_data *data = pc87360_update_device(dev); \
377 return sprintf(buf, "%u\n", data->in_status[offset]); \
379 static ssize_t set_in##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
382 struct i2c_client *client = to_i2c_client(dev); \
383 struct pc87360_data *data = i2c_get_clientdata(client); \
384 long val = simple_strtol(buf, NULL, 10); \
386 down(&data->update_lock); \
387 data->in_min[offset] = IN_TO_REG(val, data->in_vref); \
388 pc87360_write_value(data, LD_IN, offset, PC87365_REG_IN_MIN, \
389 data->in_min[offset]); \
390 up(&data->update_lock); \
393 static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
396 struct i2c_client *client = to_i2c_client(dev); \
397 struct pc87360_data *data = i2c_get_clientdata(client); \
398 long val = simple_strtol(buf, NULL, 10); \
400 down(&data->update_lock); \
401 data->in_max[offset] = IN_TO_REG(val, \
403 pc87360_write_value(data, LD_IN, offset, PC87365_REG_IN_MAX, \
404 data->in_max[offset]); \
405 up(&data->update_lock); \
408 static DEVICE_ATTR(in##offset##_input, S_IRUGO, \
409 show_in##offset##_input, NULL); \
410 static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
411 show_in##offset##_min, set_in##offset##_min); \
412 static DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
413 show_in##offset##_max, set_in##offset##_max); \
414 static DEVICE_ATTR(in##offset##_status, S_IRUGO, \
415 show_in##offset##_status, NULL);
428 #define show_and_set_therm(offset) \
429 static ssize_t show_temp##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \
431 struct pc87360_data *data = pc87360_update_device(dev); \
432 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset+7], \
435 static ssize_t show_temp##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \
437 struct pc87360_data *data = pc87360_update_device(dev); \
438 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset+7], \
441 static ssize_t show_temp##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \
443 struct pc87360_data *data = pc87360_update_device(dev); \
444 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset+7], \
447 static ssize_t show_temp##offset##_crit(struct device *dev, struct device_attribute *attr, char *buf) \
449 struct pc87360_data *data = pc87360_update_device(dev); \
450 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[offset-4], \
453 static ssize_t show_temp##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \
455 struct pc87360_data *data = pc87360_update_device(dev); \
456 return sprintf(buf, "%u\n", data->in_status[offset+7]); \
458 static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
461 struct i2c_client *client = to_i2c_client(dev); \
462 struct pc87360_data *data = i2c_get_clientdata(client); \
463 long val = simple_strtol(buf, NULL, 10); \
465 down(&data->update_lock); \
466 data->in_min[offset+7] = IN_TO_REG(val, data->in_vref); \
467 pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_MIN, \
468 data->in_min[offset+7]); \
469 up(&data->update_lock); \
472 static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
475 struct i2c_client *client = to_i2c_client(dev); \
476 struct pc87360_data *data = i2c_get_clientdata(client); \
477 long val = simple_strtol(buf, NULL, 10); \
479 down(&data->update_lock); \
480 data->in_max[offset+7] = IN_TO_REG(val, data->in_vref); \
481 pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_MAX, \
482 data->in_max[offset+7]); \
483 up(&data->update_lock); \
486 static ssize_t set_temp##offset##_crit(struct device *dev, struct device_attribute *attr, const char *buf, \
489 struct i2c_client *client = to_i2c_client(dev); \
490 struct pc87360_data *data = i2c_get_clientdata(client); \
491 long val = simple_strtol(buf, NULL, 10); \
493 down(&data->update_lock); \
494 data->in_crit[offset-4] = IN_TO_REG(val, data->in_vref); \
495 pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_CRIT, \
496 data->in_crit[offset-4]); \
497 up(&data->update_lock); \
500 static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
501 show_temp##offset##_input, NULL); \
502 static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
503 show_temp##offset##_min, set_temp##offset##_min); \
504 static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
505 show_temp##offset##_max, set_temp##offset##_max); \
506 static DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \
507 show_temp##offset##_crit, set_temp##offset##_crit); \
508 static DEVICE_ATTR(temp##offset##_status, S_IRUGO, \
509 show_temp##offset##_status, NULL);
510 show_and_set_therm(4)
511 show_and_set_therm(5)
512 show_and_set_therm(6)
514 static ssize_t
show_vid(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
516 struct pc87360_data
*data
= pc87360_update_device(dev
);
517 return sprintf(buf
, "%u\n", vid_from_reg(data
->vid
, data
->vrm
));
519 static DEVICE_ATTR(cpu0_vid
, S_IRUGO
, show_vid
, NULL
);
521 static ssize_t
show_vrm(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
523 struct pc87360_data
*data
= pc87360_update_device(dev
);
524 return sprintf(buf
, "%u\n", data
->vrm
);
526 static ssize_t
set_vrm(struct device
*dev
, struct device_attribute
*attr
, const char *buf
, size_t count
)
528 struct i2c_client
*client
= to_i2c_client(dev
);
529 struct pc87360_data
*data
= i2c_get_clientdata(client
);
530 data
->vrm
= simple_strtoul(buf
, NULL
, 10);
533 static DEVICE_ATTR(vrm
, S_IRUGO
| S_IWUSR
, show_vrm
, set_vrm
);
535 static ssize_t
show_in_alarms(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
537 struct pc87360_data
*data
= pc87360_update_device(dev
);
538 return sprintf(buf
, "%u\n", data
->in_alarms
);
540 static DEVICE_ATTR(alarms_in
, S_IRUGO
, show_in_alarms
, NULL
);
542 #define show_and_set_temp(offset) \
543 static ssize_t show_temp##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \
545 struct pc87360_data *data = pc87360_update_device(dev); \
546 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \
548 static ssize_t show_temp##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \
550 struct pc87360_data *data = pc87360_update_device(dev); \
551 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[offset-1])); \
553 static ssize_t show_temp##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \
555 struct pc87360_data *data = pc87360_update_device(dev); \
556 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[offset-1])); \
558 static ssize_t show_temp##offset##_crit(struct device *dev, struct device_attribute *attr, char *buf) \
560 struct pc87360_data *data = pc87360_update_device(dev); \
561 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[offset-1])); \
563 static ssize_t show_temp##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \
565 struct pc87360_data *data = pc87360_update_device(dev); \
566 return sprintf(buf, "%d\n", data->temp_status[offset-1]); \
568 static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
571 struct i2c_client *client = to_i2c_client(dev); \
572 struct pc87360_data *data = i2c_get_clientdata(client); \
573 long val = simple_strtol(buf, NULL, 10); \
575 down(&data->update_lock); \
576 data->temp_min[offset-1] = TEMP_TO_REG(val); \
577 pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_MIN, \
578 data->temp_min[offset-1]); \
579 up(&data->update_lock); \
582 static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
585 struct i2c_client *client = to_i2c_client(dev); \
586 struct pc87360_data *data = i2c_get_clientdata(client); \
587 long val = simple_strtol(buf, NULL, 10); \
589 down(&data->update_lock); \
590 data->temp_max[offset-1] = TEMP_TO_REG(val); \
591 pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_MAX, \
592 data->temp_max[offset-1]); \
593 up(&data->update_lock); \
596 static ssize_t set_temp##offset##_crit(struct device *dev, struct device_attribute *attr, const char *buf, \
599 struct i2c_client *client = to_i2c_client(dev); \
600 struct pc87360_data *data = i2c_get_clientdata(client); \
601 long val = simple_strtol(buf, NULL, 10); \
603 down(&data->update_lock); \
604 data->temp_crit[offset-1] = TEMP_TO_REG(val); \
605 pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_CRIT, \
606 data->temp_crit[offset-1]); \
607 up(&data->update_lock); \
610 static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
611 show_temp##offset##_input, NULL); \
612 static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
613 show_temp##offset##_min, set_temp##offset##_min); \
614 static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
615 show_temp##offset##_max, set_temp##offset##_max); \
616 static DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \
617 show_temp##offset##_crit, set_temp##offset##_crit); \
618 static DEVICE_ATTR(temp##offset##_status, S_IRUGO, \
619 show_temp##offset##_status, NULL);
624 static ssize_t
show_temp_alarms(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
626 struct pc87360_data
*data
= pc87360_update_device(dev
);
627 return sprintf(buf
, "%u\n", data
->temp_alarms
);
629 static DEVICE_ATTR(alarms_temp
, S_IRUGO
, show_temp_alarms
, NULL
);
632 * Device detection, registration and update
635 static int pc87360_attach_adapter(struct i2c_adapter
*adapter
)
637 return i2c_detect(adapter
, &addr_data
, pc87360_detect
);
640 static int pc87360_find(int sioaddr
, u8
*devid
, int *address
)
644 int nrdev
; /* logical device count */
646 /* No superio_enter */
648 /* Identify device */
649 val
= superio_inb(sioaddr
, DEVID
);
651 case 0xE1: /* PC87360 */
652 case 0xE8: /* PC87363 */
653 case 0xE4: /* PC87364 */
656 case 0xE5: /* PC87365 */
657 case 0xE9: /* PC87366 */
661 superio_exit(sioaddr
);
664 /* Remember the device id */
667 for (i
= 0; i
< nrdev
; i
++) {
668 /* select logical device */
669 superio_outb(sioaddr
, DEV
, logdev
[i
]);
671 val
= superio_inb(sioaddr
, ACT
);
673 printk(KERN_INFO
"pc87360: Device 0x%02x not "
674 "activated\n", logdev
[i
]);
678 val
= (superio_inb(sioaddr
, BASE
) << 8)
679 | superio_inb(sioaddr
, BASE
+ 1);
681 printk(KERN_INFO
"pc87360: Base address not set for "
682 "device 0x%02x\n", logdev
[i
]);
688 if (i
==0) { /* Fans */
689 confreg
[0] = superio_inb(sioaddr
, 0xF0);
690 confreg
[1] = superio_inb(sioaddr
, 0xF1);
693 printk(KERN_DEBUG
"pc87360: Fan 1: mon=%d "
694 "ctrl=%d inv=%d\n", (confreg
[0]>>2)&1,
695 (confreg
[0]>>3)&1, (confreg
[0]>>4)&1);
696 printk(KERN_DEBUG
"pc87360: Fan 2: mon=%d "
697 "ctrl=%d inv=%d\n", (confreg
[0]>>5)&1,
698 (confreg
[0]>>6)&1, (confreg
[0]>>7)&1);
699 printk(KERN_DEBUG
"pc87360: Fan 3: mon=%d "
700 "ctrl=%d inv=%d\n", confreg
[1]&1,
701 (confreg
[1]>>1)&1, (confreg
[1]>>2)&1);
703 } else if (i
==1) { /* Voltages */
704 /* Are we using thermistors? */
705 if (*devid
== 0xE9) { /* PC87366 */
706 /* These registers are not logical-device
707 specific, just that we won't need them if
708 we don't use the VLM device */
709 confreg
[2] = superio_inb(sioaddr
, 0x2B);
710 confreg
[3] = superio_inb(sioaddr
, 0x25);
712 if (confreg
[2] & 0x40) {
713 printk(KERN_INFO
"pc87360: Using "
714 "thermistors for temperature "
717 if (confreg
[3] & 0xE0) {
718 printk(KERN_INFO
"pc87360: VID "
719 "inputs routed (mode %u)\n",
726 superio_exit(sioaddr
);
730 /* We don't really care about the address.
731 Read from extra_isa instead. */
732 int pc87360_detect(struct i2c_adapter
*adapter
, int address
, int kind
)
735 struct i2c_client
*new_client
;
736 struct pc87360_data
*data
;
738 const char *name
= "pc87360";
739 int use_thermistors
= 0;
741 if (!i2c_is_isa_adapter(adapter
))
744 if (!(data
= kmalloc(sizeof(struct pc87360_data
), GFP_KERNEL
)))
746 memset(data
, 0x00, sizeof(struct pc87360_data
));
748 new_client
= &data
->client
;
749 i2c_set_clientdata(new_client
, data
);
750 new_client
->addr
= address
;
751 init_MUTEX(&data
->lock
);
752 new_client
->adapter
= adapter
;
753 new_client
->driver
= &pc87360_driver
;
754 new_client
->flags
= 0;
770 data
->fannr
= extra_isa
[0] ? 3 : 0;
771 data
->innr
= extra_isa
[1] ? 11 : 0;
772 data
->tempnr
= extra_isa
[2] ? 2 : 0;
776 data
->fannr
= extra_isa
[0] ? 3 : 0;
777 data
->innr
= extra_isa
[1] ? 14 : 0;
778 data
->tempnr
= extra_isa
[2] ? 3 : 0;
782 strcpy(new_client
->name
, name
);
784 init_MUTEX(&data
->update_lock
);
786 for (i
= 0; i
< 3; i
++) {
787 if (((data
->address
[i
] = extra_isa
[i
]))
788 && !request_region(extra_isa
[i
], PC87360_EXTENT
,
789 pc87360_driver
.name
)) {
790 dev_err(&new_client
->dev
, "Region 0x%x-0x%x already "
791 "in use!\n", extra_isa
[i
],
792 extra_isa
[i
]+PC87360_EXTENT
-1);
793 for (i
--; i
>= 0; i
--)
794 release_region(extra_isa
[i
], PC87360_EXTENT
);
800 /* Retrieve the fans configuration from Super-I/O space */
802 data
->fan_conf
= confreg
[0] | (confreg
[1] << 8);
804 if ((err
= i2c_attach_client(new_client
)))
807 /* Use the correct reference voltage
808 Unless both the VLM and the TMS logical devices agree to
809 use an external Vref, the internal one is used. */
811 i
= pc87360_read_value(data
, LD_IN
, NO_BANK
,
812 PC87365_REG_IN_CONFIG
);
814 i
&= pc87360_read_value(data
, LD_TEMP
, NO_BANK
,
815 PC87365_REG_TEMP_CONFIG
);
817 data
->in_vref
= (i
&0x02) ? 3025 : 2966;
818 dev_dbg(&new_client
->dev
, "Using %s reference voltage\n",
819 (i
&0x02) ? "external" : "internal");
821 data
->vid_conf
= confreg
[3];
825 /* Fan clock dividers may be needed before any data is read */
826 for (i
= 0; i
< data
->fannr
; i
++) {
827 if (FAN_CONFIG_MONITOR(data
->fan_conf
, i
))
828 data
->fan_status
[i
] = pc87360_read_value(data
,
830 PC87360_REG_FAN_STATUS(i
));
834 if (devid
== 0xe9 && data
->address
[1]) /* PC87366 */
835 use_thermistors
= confreg
[2] & 0x40;
837 pc87360_init_client(new_client
, use_thermistors
);
840 /* Register sysfs hooks */
842 device_create_file(&new_client
->dev
, &dev_attr_in0_input
);
843 device_create_file(&new_client
->dev
, &dev_attr_in1_input
);
844 device_create_file(&new_client
->dev
, &dev_attr_in2_input
);
845 device_create_file(&new_client
->dev
, &dev_attr_in3_input
);
846 device_create_file(&new_client
->dev
, &dev_attr_in4_input
);
847 device_create_file(&new_client
->dev
, &dev_attr_in5_input
);
848 device_create_file(&new_client
->dev
, &dev_attr_in6_input
);
849 device_create_file(&new_client
->dev
, &dev_attr_in7_input
);
850 device_create_file(&new_client
->dev
, &dev_attr_in8_input
);
851 device_create_file(&new_client
->dev
, &dev_attr_in9_input
);
852 device_create_file(&new_client
->dev
, &dev_attr_in10_input
);
853 device_create_file(&new_client
->dev
, &dev_attr_in0_min
);
854 device_create_file(&new_client
->dev
, &dev_attr_in1_min
);
855 device_create_file(&new_client
->dev
, &dev_attr_in2_min
);
856 device_create_file(&new_client
->dev
, &dev_attr_in3_min
);
857 device_create_file(&new_client
->dev
, &dev_attr_in4_min
);
858 device_create_file(&new_client
->dev
, &dev_attr_in5_min
);
859 device_create_file(&new_client
->dev
, &dev_attr_in6_min
);
860 device_create_file(&new_client
->dev
, &dev_attr_in7_min
);
861 device_create_file(&new_client
->dev
, &dev_attr_in8_min
);
862 device_create_file(&new_client
->dev
, &dev_attr_in9_min
);
863 device_create_file(&new_client
->dev
, &dev_attr_in10_min
);
864 device_create_file(&new_client
->dev
, &dev_attr_in0_max
);
865 device_create_file(&new_client
->dev
, &dev_attr_in1_max
);
866 device_create_file(&new_client
->dev
, &dev_attr_in2_max
);
867 device_create_file(&new_client
->dev
, &dev_attr_in3_max
);
868 device_create_file(&new_client
->dev
, &dev_attr_in4_max
);
869 device_create_file(&new_client
->dev
, &dev_attr_in5_max
);
870 device_create_file(&new_client
->dev
, &dev_attr_in6_max
);
871 device_create_file(&new_client
->dev
, &dev_attr_in7_max
);
872 device_create_file(&new_client
->dev
, &dev_attr_in8_max
);
873 device_create_file(&new_client
->dev
, &dev_attr_in9_max
);
874 device_create_file(&new_client
->dev
, &dev_attr_in10_max
);
875 device_create_file(&new_client
->dev
, &dev_attr_in0_status
);
876 device_create_file(&new_client
->dev
, &dev_attr_in1_status
);
877 device_create_file(&new_client
->dev
, &dev_attr_in2_status
);
878 device_create_file(&new_client
->dev
, &dev_attr_in3_status
);
879 device_create_file(&new_client
->dev
, &dev_attr_in4_status
);
880 device_create_file(&new_client
->dev
, &dev_attr_in5_status
);
881 device_create_file(&new_client
->dev
, &dev_attr_in6_status
);
882 device_create_file(&new_client
->dev
, &dev_attr_in7_status
);
883 device_create_file(&new_client
->dev
, &dev_attr_in8_status
);
884 device_create_file(&new_client
->dev
, &dev_attr_in9_status
);
885 device_create_file(&new_client
->dev
, &dev_attr_in10_status
);
887 device_create_file(&new_client
->dev
, &dev_attr_cpu0_vid
);
888 device_create_file(&new_client
->dev
, &dev_attr_vrm
);
889 device_create_file(&new_client
->dev
, &dev_attr_alarms_in
);
893 device_create_file(&new_client
->dev
, &dev_attr_temp1_input
);
894 device_create_file(&new_client
->dev
, &dev_attr_temp2_input
);
895 device_create_file(&new_client
->dev
, &dev_attr_temp1_min
);
896 device_create_file(&new_client
->dev
, &dev_attr_temp2_min
);
897 device_create_file(&new_client
->dev
, &dev_attr_temp1_max
);
898 device_create_file(&new_client
->dev
, &dev_attr_temp2_max
);
899 device_create_file(&new_client
->dev
, &dev_attr_temp1_crit
);
900 device_create_file(&new_client
->dev
, &dev_attr_temp2_crit
);
901 device_create_file(&new_client
->dev
, &dev_attr_temp1_status
);
902 device_create_file(&new_client
->dev
, &dev_attr_temp2_status
);
904 device_create_file(&new_client
->dev
, &dev_attr_alarms_temp
);
906 if (data
->tempnr
== 3) {
907 device_create_file(&new_client
->dev
, &dev_attr_temp3_input
);
908 device_create_file(&new_client
->dev
, &dev_attr_temp3_min
);
909 device_create_file(&new_client
->dev
, &dev_attr_temp3_max
);
910 device_create_file(&new_client
->dev
, &dev_attr_temp3_crit
);
911 device_create_file(&new_client
->dev
, &dev_attr_temp3_status
);
913 if (data
->innr
== 14) {
914 device_create_file(&new_client
->dev
, &dev_attr_temp4_input
);
915 device_create_file(&new_client
->dev
, &dev_attr_temp5_input
);
916 device_create_file(&new_client
->dev
, &dev_attr_temp6_input
);
917 device_create_file(&new_client
->dev
, &dev_attr_temp4_min
);
918 device_create_file(&new_client
->dev
, &dev_attr_temp5_min
);
919 device_create_file(&new_client
->dev
, &dev_attr_temp6_min
);
920 device_create_file(&new_client
->dev
, &dev_attr_temp4_max
);
921 device_create_file(&new_client
->dev
, &dev_attr_temp5_max
);
922 device_create_file(&new_client
->dev
, &dev_attr_temp6_max
);
923 device_create_file(&new_client
->dev
, &dev_attr_temp4_crit
);
924 device_create_file(&new_client
->dev
, &dev_attr_temp5_crit
);
925 device_create_file(&new_client
->dev
, &dev_attr_temp6_crit
);
926 device_create_file(&new_client
->dev
, &dev_attr_temp4_status
);
927 device_create_file(&new_client
->dev
, &dev_attr_temp5_status
);
928 device_create_file(&new_client
->dev
, &dev_attr_temp6_status
);
932 if (FAN_CONFIG_MONITOR(data
->fan_conf
, 0)) {
933 device_create_file(&new_client
->dev
,
934 &dev_attr_fan1_input
);
935 device_create_file(&new_client
->dev
,
937 device_create_file(&new_client
->dev
,
939 device_create_file(&new_client
->dev
,
940 &dev_attr_fan1_status
);
943 if (FAN_CONFIG_MONITOR(data
->fan_conf
, 1)) {
944 device_create_file(&new_client
->dev
,
945 &dev_attr_fan2_input
);
946 device_create_file(&new_client
->dev
,
948 device_create_file(&new_client
->dev
,
950 device_create_file(&new_client
->dev
,
951 &dev_attr_fan2_status
);
954 if (FAN_CONFIG_CONTROL(data
->fan_conf
, 0))
955 device_create_file(&new_client
->dev
, &dev_attr_pwm1
);
956 if (FAN_CONFIG_CONTROL(data
->fan_conf
, 1))
957 device_create_file(&new_client
->dev
, &dev_attr_pwm2
);
959 if (data
->fannr
== 3) {
960 if (FAN_CONFIG_MONITOR(data
->fan_conf
, 2)) {
961 device_create_file(&new_client
->dev
,
962 &dev_attr_fan3_input
);
963 device_create_file(&new_client
->dev
,
965 device_create_file(&new_client
->dev
,
967 device_create_file(&new_client
->dev
,
968 &dev_attr_fan3_status
);
971 if (FAN_CONFIG_CONTROL(data
->fan_conf
, 2))
972 device_create_file(&new_client
->dev
, &dev_attr_pwm3
);
978 for (i
= 0; i
< 3; i
++) {
979 if (data
->address
[i
]) {
980 release_region(data
->address
[i
], PC87360_EXTENT
);
988 static int pc87360_detach_client(struct i2c_client
*client
)
990 struct pc87360_data
*data
= i2c_get_clientdata(client
);
993 if ((i
= i2c_detach_client(client
))) {
994 dev_err(&client
->dev
, "Client deregistration failed, "
995 "client not detached.\n");
999 for (i
= 0; i
< 3; i
++) {
1000 if (data
->address
[i
]) {
1001 release_region(data
->address
[i
], PC87360_EXTENT
);
1009 /* ldi is the logical device index
1010 bank is for voltages and temperatures only */
1011 static int pc87360_read_value(struct pc87360_data
*data
, u8 ldi
, u8 bank
,
1016 down(&(data
->lock
));
1017 if (bank
!= NO_BANK
)
1018 outb_p(bank
, data
->address
[ldi
] + PC87365_REG_BANK
);
1019 res
= inb_p(data
->address
[ldi
] + reg
);
1025 static void pc87360_write_value(struct pc87360_data
*data
, u8 ldi
, u8 bank
,
1028 down(&(data
->lock
));
1029 if (bank
!= NO_BANK
)
1030 outb_p(bank
, data
->address
[ldi
] + PC87365_REG_BANK
);
1031 outb_p(value
, data
->address
[ldi
] + reg
);
1035 static void pc87360_init_client(struct i2c_client
*client
, int use_thermistors
)
1037 struct pc87360_data
*data
= i2c_get_clientdata(client
);
1039 const u8 init_in
[14] = { 2, 2, 2, 2, 2, 2, 2, 1, 1, 3, 1, 2, 2, 2 };
1040 const u8 init_temp
[3] = { 2, 2, 1 };
1043 if (init
>= 2 && data
->innr
) {
1044 reg
= pc87360_read_value(data
, LD_IN
, NO_BANK
,
1045 PC87365_REG_IN_CONVRATE
);
1046 dev_info(&client
->dev
, "VLM conversion set to "
1047 "1s period, 160us delay\n");
1048 pc87360_write_value(data
, LD_IN
, NO_BANK
,
1049 PC87365_REG_IN_CONVRATE
,
1050 (reg
& 0xC0) | 0x11);
1053 nr
= data
->innr
< 11 ? data
->innr
: 11;
1054 for (i
=0; i
<nr
; i
++) {
1055 if (init
>= init_in
[i
]) {
1056 /* Forcibly enable voltage channel */
1057 reg
= pc87360_read_value(data
, LD_IN
, i
,
1058 PC87365_REG_IN_STATUS
);
1059 if (!(reg
& 0x01)) {
1060 dev_dbg(&client
->dev
, "Forcibly "
1061 "enabling in%d\n", i
);
1062 pc87360_write_value(data
, LD_IN
, i
,
1063 PC87365_REG_IN_STATUS
,
1064 (reg
& 0x68) | 0x87);
1069 /* We can't blindly trust the Super-I/O space configuration bit,
1070 most BIOS won't set it properly */
1071 for (i
=11; i
<data
->innr
; i
++) {
1072 reg
= pc87360_read_value(data
, LD_IN
, i
,
1073 PC87365_REG_TEMP_STATUS
);
1074 use_thermistors
= use_thermistors
|| (reg
& 0x01);
1077 i
= use_thermistors
? 2 : 0;
1078 for (; i
<data
->tempnr
; i
++) {
1079 if (init
>= init_temp
[i
]) {
1080 /* Forcibly enable temperature channel */
1081 reg
= pc87360_read_value(data
, LD_TEMP
, i
,
1082 PC87365_REG_TEMP_STATUS
);
1083 if (!(reg
& 0x01)) {
1084 dev_dbg(&client
->dev
, "Forcibly "
1085 "enabling temp%d\n", i
+1);
1086 pc87360_write_value(data
, LD_TEMP
, i
,
1087 PC87365_REG_TEMP_STATUS
,
1093 if (use_thermistors
) {
1094 for (i
=11; i
<data
->innr
; i
++) {
1095 if (init
>= init_in
[i
]) {
1096 /* The pin may already be used by thermal
1098 reg
= pc87360_read_value(data
, LD_TEMP
,
1099 (i
-11)/2, PC87365_REG_TEMP_STATUS
);
1101 dev_dbg(&client
->dev
, "Skipping "
1102 "temp%d, pin already in use "
1103 "by temp%d\n", i
-7, (i
-11)/2);
1107 /* Forcibly enable thermistor channel */
1108 reg
= pc87360_read_value(data
, LD_IN
, i
,
1109 PC87365_REG_IN_STATUS
);
1110 if (!(reg
& 0x01)) {
1111 dev_dbg(&client
->dev
, "Forcibly "
1112 "enabling temp%d\n", i
-7);
1113 pc87360_write_value(data
, LD_IN
, i
,
1114 PC87365_REG_TEMP_STATUS
,
1115 (reg
& 0x60) | 0x8F);
1122 reg
= pc87360_read_value(data
, LD_IN
, NO_BANK
,
1123 PC87365_REG_IN_CONFIG
);
1125 dev_dbg(&client
->dev
, "Forcibly "
1126 "enabling monitoring (VLM)\n");
1127 pc87360_write_value(data
, LD_IN
, NO_BANK
,
1128 PC87365_REG_IN_CONFIG
,
1134 reg
= pc87360_read_value(data
, LD_TEMP
, NO_BANK
,
1135 PC87365_REG_TEMP_CONFIG
);
1137 dev_dbg(&client
->dev
, "Forcibly enabling "
1138 "monitoring (TMS)\n");
1139 pc87360_write_value(data
, LD_TEMP
, NO_BANK
,
1140 PC87365_REG_TEMP_CONFIG
,
1145 /* Chip config as documented by National Semi. */
1146 pc87360_write_value(data
, LD_TEMP
, 0xF, 0xA, 0x08);
1147 /* We voluntarily omit the bank here, in case the
1148 sequence itself matters. It shouldn't be a problem,
1149 since nobody else is supposed to access the
1150 device at that point. */
1151 pc87360_write_value(data
, LD_TEMP
, NO_BANK
, 0xB, 0x04);
1152 pc87360_write_value(data
, LD_TEMP
, NO_BANK
, 0xC, 0x35);
1153 pc87360_write_value(data
, LD_TEMP
, NO_BANK
, 0xD, 0x05);
1154 pc87360_write_value(data
, LD_TEMP
, NO_BANK
, 0xE, 0x05);
1159 static void pc87360_autodiv(struct i2c_client
*client
, int nr
)
1161 struct pc87360_data
*data
= i2c_get_clientdata(client
);
1162 u8 old_min
= data
->fan_min
[nr
];
1164 /* Increase clock divider if needed and possible */
1165 if ((data
->fan_status
[nr
] & 0x04) /* overflow flag */
1166 || (data
->fan
[nr
] >= 224)) { /* next to overflow */
1167 if ((data
->fan_status
[nr
] & 0x60) != 0x60) {
1168 data
->fan_status
[nr
] += 0x20;
1169 data
->fan_min
[nr
] >>= 1;
1170 data
->fan
[nr
] >>= 1;
1171 dev_dbg(&client
->dev
, "Increasing "
1172 "clock divider to %d for fan %d\n",
1173 FAN_DIV_FROM_REG(data
->fan_status
[nr
]), nr
+1);
1176 /* Decrease clock divider if possible */
1177 while (!(data
->fan_min
[nr
] & 0x80) /* min "nails" divider */
1178 && data
->fan
[nr
] < 85 /* bad accuracy */
1179 && (data
->fan_status
[nr
] & 0x60) != 0x00) {
1180 data
->fan_status
[nr
] -= 0x20;
1181 data
->fan_min
[nr
] <<= 1;
1182 data
->fan
[nr
] <<= 1;
1183 dev_dbg(&client
->dev
, "Decreasing "
1184 "clock divider to %d for fan %d\n",
1185 FAN_DIV_FROM_REG(data
->fan_status
[nr
]),
1190 /* Write new fan min if it changed */
1191 if (old_min
!= data
->fan_min
[nr
]) {
1192 pc87360_write_value(data
, LD_FAN
, NO_BANK
,
1193 PC87360_REG_FAN_MIN(nr
),
1198 static struct pc87360_data
*pc87360_update_device(struct device
*dev
)
1200 struct i2c_client
*client
= to_i2c_client(dev
);
1201 struct pc87360_data
*data
= i2c_get_clientdata(client
);
1204 down(&data
->update_lock
);
1206 if (time_after(jiffies
, data
->last_updated
+ HZ
* 2) || !data
->valid
) {
1207 dev_dbg(&client
->dev
, "Data update\n");
1210 for (i
= 0; i
< data
->fannr
; i
++) {
1211 if (FAN_CONFIG_MONITOR(data
->fan_conf
, i
)) {
1212 data
->fan_status
[i
] =
1213 pc87360_read_value(data
, LD_FAN
,
1214 NO_BANK
, PC87360_REG_FAN_STATUS(i
));
1215 data
->fan
[i
] = pc87360_read_value(data
, LD_FAN
,
1216 NO_BANK
, PC87360_REG_FAN(i
));
1217 data
->fan_min
[i
] = pc87360_read_value(data
,
1219 PC87360_REG_FAN_MIN(i
));
1220 /* Change clock divider if needed */
1221 pc87360_autodiv(client
, i
);
1222 /* Clear bits and write new divider */
1223 pc87360_write_value(data
, LD_FAN
, NO_BANK
,
1224 PC87360_REG_FAN_STATUS(i
),
1225 data
->fan_status
[i
]);
1227 if (FAN_CONFIG_CONTROL(data
->fan_conf
, i
))
1228 data
->pwm
[i
] = pc87360_read_value(data
, LD_FAN
,
1229 NO_BANK
, PC87360_REG_PWM(i
));
1233 for (i
= 0; i
< data
->innr
; i
++) {
1234 data
->in_status
[i
] = pc87360_read_value(data
, LD_IN
, i
,
1235 PC87365_REG_IN_STATUS
);
1237 pc87360_write_value(data
, LD_IN
, i
,
1238 PC87365_REG_IN_STATUS
,
1239 data
->in_status
[i
]);
1240 if ((data
->in_status
[i
] & 0x81) == 0x81) {
1241 data
->in
[i
] = pc87360_read_value(data
, LD_IN
,
1244 if (data
->in_status
[i
] & 0x01) {
1245 data
->in_min
[i
] = pc87360_read_value(data
,
1247 PC87365_REG_IN_MIN
);
1248 data
->in_max
[i
] = pc87360_read_value(data
,
1250 PC87365_REG_IN_MAX
);
1252 data
->in_crit
[i
-11] =
1253 pc87360_read_value(data
, LD_IN
,
1254 i
, PC87365_REG_TEMP_CRIT
);
1258 data
->in_alarms
= pc87360_read_value(data
, LD_IN
,
1259 NO_BANK
, PC87365_REG_IN_ALARMS1
)
1260 | ((pc87360_read_value(data
, LD_IN
,
1261 NO_BANK
, PC87365_REG_IN_ALARMS2
)
1263 data
->vid
= (data
->vid_conf
& 0xE0) ?
1264 pc87360_read_value(data
, LD_IN
,
1265 NO_BANK
, PC87365_REG_VID
) : 0x1F;
1269 for (i
= 0; i
< data
->tempnr
; i
++) {
1270 data
->temp_status
[i
] = pc87360_read_value(data
,
1272 PC87365_REG_TEMP_STATUS
);
1274 pc87360_write_value(data
, LD_TEMP
, i
,
1275 PC87365_REG_TEMP_STATUS
,
1276 data
->temp_status
[i
]);
1277 if ((data
->temp_status
[i
] & 0x81) == 0x81) {
1278 data
->temp
[i
] = pc87360_read_value(data
,
1282 if (data
->temp_status
[i
] & 0x01) {
1283 data
->temp_min
[i
] = pc87360_read_value(data
,
1285 PC87365_REG_TEMP_MIN
);
1286 data
->temp_max
[i
] = pc87360_read_value(data
,
1288 PC87365_REG_TEMP_MAX
);
1289 data
->temp_crit
[i
] = pc87360_read_value(data
,
1291 PC87365_REG_TEMP_CRIT
);
1295 data
->temp_alarms
= pc87360_read_value(data
, LD_TEMP
,
1296 NO_BANK
, PC87365_REG_TEMP_ALARMS
)
1300 data
->last_updated
= jiffies
;
1304 up(&data
->update_lock
);
1309 static int __init
pc87360_init(void)
1313 if (pc87360_find(0x2e, &devid
, extra_isa
)
1314 && pc87360_find(0x4e, &devid
, extra_isa
)) {
1315 printk(KERN_WARNING
"pc87360: PC8736x not detected, "
1316 "module not inserted.\n");
1320 /* Arbitrarily pick one of the addresses */
1321 for (i
= 0; i
< 3; i
++) {
1322 if (extra_isa
[i
] != 0x0000) {
1323 normal_isa
[0] = extra_isa
[i
];
1328 if (normal_isa
[0] == 0x0000) {
1329 printk(KERN_WARNING
"pc87360: No active logical device, "
1330 "module not inserted.\n");
1334 return i2c_add_driver(&pc87360_driver
);
1337 static void __exit
pc87360_exit(void)
1339 i2c_del_driver(&pc87360_driver
);
1343 MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
1344 MODULE_DESCRIPTION("PC8736x hardware monitor");
1345 MODULE_LICENSE("GPL");
1347 module_init(pc87360_init
);
1348 module_exit(pc87360_exit
);