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/config.h>
37 #include <linux/module.h>
38 #include <linux/init.h>
39 #include <linux/slab.h>
40 #include <linux/jiffies.h>
41 #include <linux/i2c.h>
42 #include <linux/i2c-sensor.h>
43 #include <linux/i2c-vid.h>
46 static unsigned short normal_i2c
[] = { I2C_CLIENT_END
};
47 static unsigned int normal_isa
[] = { 0, I2C_CLIENT_ISA_END
};
48 static struct i2c_force_data forces
[] = {{ NULL
}};
50 static unsigned int extra_isa
[3];
53 enum chips
{ any_chip
, pc87360
, pc87363
, pc87364
, pc87365
, pc87366
};
54 static struct i2c_address_data addr_data
= {
55 .normal_i2c
= normal_i2c
,
56 .normal_isa
= normal_isa
,
61 module_param(init
, int, 0);
62 MODULE_PARM_DESC(init
,
63 "Chip initialization level:\n"
65 "*1: Forcibly enable internal voltage and temperature channels, except in9\n"
66 " 2: Forcibly enable all voltage and temperature channels, except in9\n"
67 " 3: Forcibly enable all voltage and temperature channels, including in9");
70 * Super-I/O registers and operations
73 #define DEV 0x07 /* Register: Logical device select */
74 #define DEVID 0x20 /* Register: Device ID */
75 #define ACT 0x30 /* Register: Device activation */
76 #define BASE 0x60 /* Register: Base address */
78 #define FSCM 0x09 /* Logical device: fans */
79 #define VLM 0x0d /* Logical device: voltages */
80 #define TMS 0x0e /* Logical device: temperatures */
81 static const u8 logdev
[3] = { FSCM
, VLM
, TMS
};
87 static inline void superio_outb(int sioaddr
, int reg
, int val
)
93 static inline int superio_inb(int sioaddr
, int reg
)
96 return inb(sioaddr
+1);
99 static inline void superio_exit(int sioaddr
)
102 outb(0x02, sioaddr
+1);
109 #define PC87360_EXTENT 0x10
110 #define PC87365_REG_BANK 0x09
114 * Fan registers and conversions
117 /* nr has to be 0 or 1 (PC87360/87363) or 2 (PC87364/87365/87366) */
118 #define PC87360_REG_PRESCALE(nr) (0x00 + 2 * (nr))
119 #define PC87360_REG_PWM(nr) (0x01 + 2 * (nr))
120 #define PC87360_REG_FAN_MIN(nr) (0x06 + 3 * (nr))
121 #define PC87360_REG_FAN(nr) (0x07 + 3 * (nr))
122 #define PC87360_REG_FAN_STATUS(nr) (0x08 + 3 * (nr))
124 #define FAN_FROM_REG(val,div) ((val) == 0 ? 0: \
125 480000 / ((val)*(div)))
126 #define FAN_TO_REG(val,div) ((val) <= 100 ? 0 : \
127 480000 / ((val)*(div)))
128 #define FAN_DIV_FROM_REG(val) (1 << ((val >> 5) & 0x03))
129 #define FAN_STATUS_FROM_REG(val) ((val) & 0x07)
131 #define FAN_CONFIG_MONITOR(val,nr) (((val) >> (2 + nr * 3)) & 1)
132 #define FAN_CONFIG_CONTROL(val,nr) (((val) >> (3 + nr * 3)) & 1)
133 #define FAN_CONFIG_INVERT(val,nr) (((val) >> (4 + nr * 3)) & 1)
135 #define PWM_FROM_REG(val,inv) ((inv) ? 255 - (val) : (val))
136 static inline u8
PWM_TO_REG(int val
, int inv
)
148 * Voltage registers and conversions
151 #define PC87365_REG_IN_CONVRATE 0x07
152 #define PC87365_REG_IN_CONFIG 0x08
153 #define PC87365_REG_IN 0x0B
154 #define PC87365_REG_IN_MIN 0x0D
155 #define PC87365_REG_IN_MAX 0x0C
156 #define PC87365_REG_IN_STATUS 0x0A
157 #define PC87365_REG_IN_ALARMS1 0x00
158 #define PC87365_REG_IN_ALARMS2 0x01
159 #define PC87365_REG_VID 0x06
161 #define IN_FROM_REG(val,ref) (((val) * (ref) + 128) / 256)
162 #define IN_TO_REG(val,ref) ((val) < 0 ? 0 : \
163 (val)*256 >= (ref)*255 ? 255: \
164 ((val) * 256 + (ref)/2) / (ref))
167 * Temperature registers and conversions
170 #define PC87365_REG_TEMP_CONFIG 0x08
171 #define PC87365_REG_TEMP 0x0B
172 #define PC87365_REG_TEMP_MIN 0x0D
173 #define PC87365_REG_TEMP_MAX 0x0C
174 #define PC87365_REG_TEMP_CRIT 0x0E
175 #define PC87365_REG_TEMP_STATUS 0x0A
176 #define PC87365_REG_TEMP_ALARMS 0x00
178 #define TEMP_FROM_REG(val) ((val) * 1000)
179 #define TEMP_TO_REG(val) ((val) < -55000 ? -55 : \
180 (val) > 127000 ? 127 : \
181 (val) < 0 ? ((val) - 500) / 1000 : \
182 ((val) + 500) / 1000)
185 * Client data (each client gets its own)
188 struct pc87360_data
{
189 struct i2c_client client
;
190 struct semaphore lock
;
191 struct semaphore update_lock
;
192 char valid
; /* !=0 if following fields are valid */
193 unsigned long last_updated
; /* In jiffies */
197 u8 fannr
, innr
, tempnr
;
199 u8 fan
[3]; /* Register value */
200 u8 fan_min
[3]; /* Register value */
201 u8 fan_status
[3]; /* Register value */
202 u8 pwm
[3]; /* Register value */
203 u16 fan_conf
; /* Configuration register values, combined */
205 u16 in_vref
; /* 1 mV/bit */
206 u8 in
[14]; /* Register value */
207 u8 in_min
[14]; /* Register value */
208 u8 in_max
[14]; /* Register value */
209 u8 in_crit
[3]; /* Register value */
210 u8 in_status
[14]; /* Register value */
211 u16 in_alarms
; /* Register values, combined, masked */
212 u8 vid_conf
; /* Configuration register value */
214 u8 vid
; /* Register value */
216 s8 temp
[3]; /* Register value */
217 s8 temp_min
[3]; /* Register value */
218 s8 temp_max
[3]; /* Register value */
219 s8 temp_crit
[3]; /* Register value */
220 u8 temp_status
[3]; /* Register value */
221 u8 temp_alarms
; /* Register value, masked */
225 * Functions declaration
228 static int pc87360_attach_adapter(struct i2c_adapter
*adapter
);
229 static int pc87360_detect(struct i2c_adapter
*adapter
, int address
, int kind
);
230 static int pc87360_detach_client(struct i2c_client
*client
);
232 static int pc87360_read_value(struct pc87360_data
*data
, u8 ldi
, u8 bank
,
234 static void pc87360_write_value(struct pc87360_data
*data
, u8 ldi
, u8 bank
,
236 static void pc87360_init_client(struct i2c_client
*client
, int use_thermistors
);
237 static struct pc87360_data
*pc87360_update_device(struct device
*dev
);
240 * Driver data (common to all clients)
243 static struct i2c_driver pc87360_driver
= {
244 .owner
= THIS_MODULE
,
246 .flags
= I2C_DF_NOTIFY
,
247 .attach_adapter
= pc87360_attach_adapter
,
248 .detach_client
= pc87360_detach_client
,
255 static ssize_t
set_fan_min(struct device
*dev
, const char *buf
,
256 size_t count
, int nr
)
258 struct i2c_client
*client
= to_i2c_client(dev
);
259 struct pc87360_data
*data
= i2c_get_clientdata(client
);
260 long fan_min
= simple_strtol(buf
, NULL
, 10);
262 down(&data
->update_lock
);
263 fan_min
= FAN_TO_REG(fan_min
, FAN_DIV_FROM_REG(data
->fan_status
[nr
]));
265 /* If it wouldn't fit, change clock divisor */
267 && (data
->fan_status
[nr
] & 0x60) != 0x60) {
270 data
->fan_status
[nr
] += 0x20;
272 data
->fan_min
[nr
] = fan_min
> 255 ? 255 : fan_min
;
273 pc87360_write_value(data
, LD_FAN
, NO_BANK
, PC87360_REG_FAN_MIN(nr
),
276 /* Write new divider, preserve alarm bits */
277 pc87360_write_value(data
, LD_FAN
, NO_BANK
, PC87360_REG_FAN_STATUS(nr
),
278 data
->fan_status
[nr
] & 0xF9);
279 up(&data
->update_lock
);
284 #define show_and_set_fan(offset) \
285 static ssize_t show_fan##offset##_input(struct device *dev, char *buf) \
287 struct pc87360_data *data = pc87360_update_device(dev); \
288 return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan[offset-1], \
289 FAN_DIV_FROM_REG(data->fan_status[offset-1]))); \
291 static ssize_t show_fan##offset##_min(struct device *dev, char *buf) \
293 struct pc87360_data *data = pc87360_update_device(dev); \
294 return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan_min[offset-1], \
295 FAN_DIV_FROM_REG(data->fan_status[offset-1]))); \
297 static ssize_t show_fan##offset##_div(struct device *dev, char *buf) \
299 struct pc87360_data *data = pc87360_update_device(dev); \
300 return sprintf(buf, "%u\n", \
301 FAN_DIV_FROM_REG(data->fan_status[offset-1])); \
303 static ssize_t show_fan##offset##_status(struct device *dev, char *buf) \
305 struct pc87360_data *data = pc87360_update_device(dev); \
306 return sprintf(buf, "%u\n", \
307 FAN_STATUS_FROM_REG(data->fan_status[offset-1])); \
309 static ssize_t set_fan##offset##_min(struct device *dev, const char *buf, \
312 return set_fan_min(dev, buf, count, offset-1); \
314 static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
315 show_fan##offset##_input, NULL); \
316 static DEVICE_ATTR(fan##offset##_min, S_IWUSR | S_IRUGO, \
317 show_fan##offset##_min, set_fan##offset##_min); \
318 static DEVICE_ATTR(fan##offset##_div, S_IRUGO, \
319 show_fan##offset##_div, NULL); \
320 static DEVICE_ATTR(fan##offset##_status, S_IRUGO, \
321 show_fan##offset##_status, NULL);
326 #define show_and_set_pwm(offset) \
327 static ssize_t show_pwm##offset(struct device *dev, char *buf) \
329 struct pc87360_data *data = pc87360_update_device(dev); \
330 return sprintf(buf, "%u\n", \
331 PWM_FROM_REG(data->pwm[offset-1], \
332 FAN_CONFIG_INVERT(data->fan_conf, \
335 static ssize_t set_pwm##offset(struct device *dev, const char *buf, \
338 struct i2c_client *client = to_i2c_client(dev); \
339 struct pc87360_data *data = i2c_get_clientdata(client); \
340 long val = simple_strtol(buf, NULL, 10); \
342 down(&data->update_lock); \
343 data->pwm[offset-1] = PWM_TO_REG(val, \
344 FAN_CONFIG_INVERT(data->fan_conf, offset-1)); \
345 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_PWM(offset-1), \
346 data->pwm[offset-1]); \
347 up(&data->update_lock); \
350 static DEVICE_ATTR(pwm##offset, S_IWUSR | S_IRUGO, \
351 show_pwm##offset, set_pwm##offset);
356 #define show_and_set_in(offset) \
357 static ssize_t show_in##offset##_input(struct device *dev, char *buf) \
359 struct pc87360_data *data = pc87360_update_device(dev); \
360 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \
363 static ssize_t show_in##offset##_min(struct device *dev, char *buf) \
365 struct pc87360_data *data = pc87360_update_device(dev); \
366 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \
369 static ssize_t show_in##offset##_max(struct device *dev, char *buf) \
371 struct pc87360_data *data = pc87360_update_device(dev); \
372 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \
375 static ssize_t show_in##offset##_status(struct device *dev, char *buf) \
377 struct pc87360_data *data = pc87360_update_device(dev); \
378 return sprintf(buf, "%u\n", data->in_status[offset]); \
380 static ssize_t set_in##offset##_min(struct device *dev, const char *buf, \
383 struct i2c_client *client = to_i2c_client(dev); \
384 struct pc87360_data *data = i2c_get_clientdata(client); \
385 long val = simple_strtol(buf, NULL, 10); \
387 down(&data->update_lock); \
388 data->in_min[offset] = IN_TO_REG(val, data->in_vref); \
389 pc87360_write_value(data, LD_IN, offset, PC87365_REG_IN_MIN, \
390 data->in_min[offset]); \
391 up(&data->update_lock); \
394 static ssize_t set_in##offset##_max(struct device *dev, const char *buf, \
397 struct i2c_client *client = to_i2c_client(dev); \
398 struct pc87360_data *data = i2c_get_clientdata(client); \
399 long val = simple_strtol(buf, NULL, 10); \
401 down(&data->update_lock); \
402 data->in_max[offset] = IN_TO_REG(val, \
404 pc87360_write_value(data, LD_IN, offset, PC87365_REG_IN_MAX, \
405 data->in_max[offset]); \
406 up(&data->update_lock); \
409 static DEVICE_ATTR(in##offset##_input, S_IRUGO, \
410 show_in##offset##_input, NULL); \
411 static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
412 show_in##offset##_min, set_in##offset##_min); \
413 static DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
414 show_in##offset##_max, set_in##offset##_max); \
415 static DEVICE_ATTR(in##offset##_status, S_IRUGO, \
416 show_in##offset##_status, NULL);
429 #define show_and_set_therm(offset) \
430 static ssize_t show_temp##offset##_input(struct device *dev, char *buf) \
432 struct pc87360_data *data = pc87360_update_device(dev); \
433 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset+7], \
436 static ssize_t show_temp##offset##_min(struct device *dev, char *buf) \
438 struct pc87360_data *data = pc87360_update_device(dev); \
439 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset+7], \
442 static ssize_t show_temp##offset##_max(struct device *dev, char *buf) \
444 struct pc87360_data *data = pc87360_update_device(dev); \
445 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset+7], \
448 static ssize_t show_temp##offset##_crit(struct device *dev, char *buf) \
450 struct pc87360_data *data = pc87360_update_device(dev); \
451 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[offset-4], \
454 static ssize_t show_temp##offset##_status(struct device *dev, char *buf) \
456 struct pc87360_data *data = pc87360_update_device(dev); \
457 return sprintf(buf, "%u\n", data->in_status[offset+7]); \
459 static ssize_t set_temp##offset##_min(struct device *dev, const char *buf, \
462 struct i2c_client *client = to_i2c_client(dev); \
463 struct pc87360_data *data = i2c_get_clientdata(client); \
464 long val = simple_strtol(buf, NULL, 10); \
466 down(&data->update_lock); \
467 data->in_min[offset+7] = IN_TO_REG(val, data->in_vref); \
468 pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_MIN, \
469 data->in_min[offset+7]); \
470 up(&data->update_lock); \
473 static ssize_t set_temp##offset##_max(struct device *dev, const char *buf, \
476 struct i2c_client *client = to_i2c_client(dev); \
477 struct pc87360_data *data = i2c_get_clientdata(client); \
478 long val = simple_strtol(buf, NULL, 10); \
480 down(&data->update_lock); \
481 data->in_max[offset+7] = IN_TO_REG(val, data->in_vref); \
482 pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_MAX, \
483 data->in_max[offset+7]); \
484 up(&data->update_lock); \
487 static ssize_t set_temp##offset##_crit(struct device *dev, const char *buf, \
490 struct i2c_client *client = to_i2c_client(dev); \
491 struct pc87360_data *data = i2c_get_clientdata(client); \
492 long val = simple_strtol(buf, NULL, 10); \
494 down(&data->update_lock); \
495 data->in_crit[offset-4] = IN_TO_REG(val, data->in_vref); \
496 pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_CRIT, \
497 data->in_crit[offset-4]); \
498 up(&data->update_lock); \
501 static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
502 show_temp##offset##_input, NULL); \
503 static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
504 show_temp##offset##_min, set_temp##offset##_min); \
505 static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
506 show_temp##offset##_max, set_temp##offset##_max); \
507 static DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \
508 show_temp##offset##_crit, set_temp##offset##_crit); \
509 static DEVICE_ATTR(temp##offset##_status, S_IRUGO, \
510 show_temp##offset##_status, NULL);
511 show_and_set_therm(4)
512 show_and_set_therm(5)
513 show_and_set_therm(6)
515 static ssize_t
show_vid(struct device
*dev
, char *buf
)
517 struct pc87360_data
*data
= pc87360_update_device(dev
);
518 return sprintf(buf
, "%u\n", vid_from_reg(data
->vid
, data
->vrm
));
520 static DEVICE_ATTR(cpu0_vid
, S_IRUGO
, show_vid
, NULL
);
522 static ssize_t
show_vrm(struct device
*dev
, char *buf
)
524 struct pc87360_data
*data
= pc87360_update_device(dev
);
525 return sprintf(buf
, "%u\n", data
->vrm
);
527 static ssize_t
set_vrm(struct device
*dev
, const char *buf
, size_t count
)
529 struct i2c_client
*client
= to_i2c_client(dev
);
530 struct pc87360_data
*data
= i2c_get_clientdata(client
);
531 data
->vrm
= simple_strtoul(buf
, NULL
, 10);
534 static DEVICE_ATTR(vrm
, S_IRUGO
| S_IWUSR
, show_vrm
, set_vrm
);
536 static ssize_t
show_in_alarms(struct device
*dev
, char *buf
)
538 struct pc87360_data
*data
= pc87360_update_device(dev
);
539 return sprintf(buf
, "%u\n", data
->in_alarms
);
541 static DEVICE_ATTR(alarms_in
, S_IRUGO
, show_in_alarms
, NULL
);
543 #define show_and_set_temp(offset) \
544 static ssize_t show_temp##offset##_input(struct device *dev, char *buf) \
546 struct pc87360_data *data = pc87360_update_device(dev); \
547 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \
549 static ssize_t show_temp##offset##_min(struct device *dev, char *buf) \
551 struct pc87360_data *data = pc87360_update_device(dev); \
552 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[offset-1])); \
554 static ssize_t show_temp##offset##_max(struct device *dev, char *buf) \
556 struct pc87360_data *data = pc87360_update_device(dev); \
557 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[offset-1])); \
559 static ssize_t show_temp##offset##_crit(struct device *dev, char *buf) \
561 struct pc87360_data *data = pc87360_update_device(dev); \
562 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[offset-1])); \
564 static ssize_t show_temp##offset##_status(struct device *dev, char *buf) \
566 struct pc87360_data *data = pc87360_update_device(dev); \
567 return sprintf(buf, "%d\n", data->temp_status[offset-1]); \
569 static ssize_t set_temp##offset##_min(struct device *dev, const char *buf, \
572 struct i2c_client *client = to_i2c_client(dev); \
573 struct pc87360_data *data = i2c_get_clientdata(client); \
574 long val = simple_strtol(buf, NULL, 10); \
576 down(&data->update_lock); \
577 data->temp_min[offset-1] = TEMP_TO_REG(val); \
578 pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_MIN, \
579 data->temp_min[offset-1]); \
580 up(&data->update_lock); \
583 static ssize_t set_temp##offset##_max(struct device *dev, const char *buf, \
586 struct i2c_client *client = to_i2c_client(dev); \
587 struct pc87360_data *data = i2c_get_clientdata(client); \
588 long val = simple_strtol(buf, NULL, 10); \
590 down(&data->update_lock); \
591 data->temp_max[offset-1] = TEMP_TO_REG(val); \
592 pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_MAX, \
593 data->temp_max[offset-1]); \
594 up(&data->update_lock); \
597 static ssize_t set_temp##offset##_crit(struct device *dev, const char *buf, \
600 struct i2c_client *client = to_i2c_client(dev); \
601 struct pc87360_data *data = i2c_get_clientdata(client); \
602 long val = simple_strtol(buf, NULL, 10); \
604 down(&data->update_lock); \
605 data->temp_crit[offset-1] = TEMP_TO_REG(val); \
606 pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_CRIT, \
607 data->temp_crit[offset-1]); \
608 up(&data->update_lock); \
611 static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
612 show_temp##offset##_input, NULL); \
613 static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
614 show_temp##offset##_min, set_temp##offset##_min); \
615 static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
616 show_temp##offset##_max, set_temp##offset##_max); \
617 static DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \
618 show_temp##offset##_crit, set_temp##offset##_crit); \
619 static DEVICE_ATTR(temp##offset##_status, S_IRUGO, \
620 show_temp##offset##_status, NULL);
625 static ssize_t
show_temp_alarms(struct device
*dev
, char *buf
)
627 struct pc87360_data
*data
= pc87360_update_device(dev
);
628 return sprintf(buf
, "%u\n", data
->temp_alarms
);
630 static DEVICE_ATTR(alarms_temp
, S_IRUGO
, show_temp_alarms
, NULL
);
633 * Device detection, registration and update
636 static int pc87360_attach_adapter(struct i2c_adapter
*adapter
)
638 return i2c_detect(adapter
, &addr_data
, pc87360_detect
);
641 static int pc87360_find(int sioaddr
, u8
*devid
, int *address
)
645 int nrdev
; /* logical device count */
647 /* No superio_enter */
649 /* Identify device */
650 val
= superio_inb(sioaddr
, DEVID
);
652 case 0xE1: /* PC87360 */
653 case 0xE8: /* PC87363 */
654 case 0xE4: /* PC87364 */
657 case 0xE5: /* PC87365 */
658 case 0xE9: /* PC87366 */
662 superio_exit(sioaddr
);
665 /* Remember the device id */
668 for (i
= 0; i
< nrdev
; i
++) {
669 /* select logical device */
670 superio_outb(sioaddr
, DEV
, logdev
[i
]);
672 val
= superio_inb(sioaddr
, ACT
);
674 printk(KERN_INFO
"pc87360: Device 0x%02x not "
675 "activated\n", logdev
[i
]);
679 val
= (superio_inb(sioaddr
, BASE
) << 8)
680 | superio_inb(sioaddr
, BASE
+ 1);
682 printk(KERN_INFO
"pc87360: Base address not set for "
683 "device 0x%02x\n", logdev
[i
]);
689 if (i
==0) { /* Fans */
690 confreg
[0] = superio_inb(sioaddr
, 0xF0);
691 confreg
[1] = superio_inb(sioaddr
, 0xF1);
694 printk(KERN_DEBUG
"pc87360: Fan 1: mon=%d "
695 "ctrl=%d inv=%d\n", (confreg
[0]>>2)&1,
696 (confreg
[0]>>3)&1, (confreg
[0]>>4)&1);
697 printk(KERN_DEBUG
"pc87360: Fan 2: mon=%d "
698 "ctrl=%d inv=%d\n", (confreg
[0]>>5)&1,
699 (confreg
[0]>>6)&1, (confreg
[0]>>7)&1);
700 printk(KERN_DEBUG
"pc87360: Fan 3: mon=%d "
701 "ctrl=%d inv=%d\n", confreg
[1]&1,
702 (confreg
[1]>>1)&1, (confreg
[1]>>2)&1);
704 } else if (i
==1) { /* Voltages */
705 /* Are we using thermistors? */
706 if (*devid
== 0xE9) { /* PC87366 */
707 /* These registers are not logical-device
708 specific, just that we won't need them if
709 we don't use the VLM device */
710 confreg
[2] = superio_inb(sioaddr
, 0x2B);
711 confreg
[3] = superio_inb(sioaddr
, 0x25);
713 if (confreg
[2] & 0x40) {
714 printk(KERN_INFO
"pc87360: Using "
715 "thermistors for temperature "
718 if (confreg
[3] & 0xE0) {
719 printk(KERN_INFO
"pc87360: VID "
720 "inputs routed (mode %u)\n",
727 superio_exit(sioaddr
);
731 /* We don't really care about the address.
732 Read from extra_isa instead. */
733 int pc87360_detect(struct i2c_adapter
*adapter
, int address
, int kind
)
736 struct i2c_client
*new_client
;
737 struct pc87360_data
*data
;
739 const char *name
= "pc87360";
740 int use_thermistors
= 0;
742 if (!i2c_is_isa_adapter(adapter
))
745 if (!(data
= kmalloc(sizeof(struct pc87360_data
), GFP_KERNEL
)))
747 memset(data
, 0x00, sizeof(struct pc87360_data
));
749 new_client
= &data
->client
;
750 i2c_set_clientdata(new_client
, data
);
751 new_client
->addr
= address
;
752 init_MUTEX(&data
->lock
);
753 new_client
->adapter
= adapter
;
754 new_client
->driver
= &pc87360_driver
;
755 new_client
->flags
= 0;
771 data
->fannr
= extra_isa
[0] ? 3 : 0;
772 data
->innr
= extra_isa
[1] ? 11 : 0;
773 data
->tempnr
= extra_isa
[2] ? 2 : 0;
777 data
->fannr
= extra_isa
[0] ? 3 : 0;
778 data
->innr
= extra_isa
[1] ? 14 : 0;
779 data
->tempnr
= extra_isa
[2] ? 3 : 0;
783 strcpy(new_client
->name
, name
);
785 init_MUTEX(&data
->update_lock
);
787 for (i
= 0; i
< 3; i
++) {
788 if (((data
->address
[i
] = extra_isa
[i
]))
789 && !request_region(extra_isa
[i
], PC87360_EXTENT
,
790 pc87360_driver
.name
)) {
791 dev_err(&new_client
->dev
, "Region 0x%x-0x%x already "
792 "in use!\n", extra_isa
[i
],
793 extra_isa
[i
]+PC87360_EXTENT
-1);
794 for (i
--; i
>= 0; i
--)
795 release_region(extra_isa
[i
], PC87360_EXTENT
);
801 /* Retrieve the fans configuration from Super-I/O space */
803 data
->fan_conf
= confreg
[0] | (confreg
[1] << 8);
805 if ((err
= i2c_attach_client(new_client
)))
808 /* Use the correct reference voltage
809 Unless both the VLM and the TMS logical devices agree to
810 use an external Vref, the internal one is used. */
812 i
= pc87360_read_value(data
, LD_IN
, NO_BANK
,
813 PC87365_REG_IN_CONFIG
);
815 i
&= pc87360_read_value(data
, LD_TEMP
, NO_BANK
,
816 PC87365_REG_TEMP_CONFIG
);
818 data
->in_vref
= (i
&0x02) ? 3025 : 2966;
819 dev_dbg(&new_client
->dev
, "Using %s reference voltage\n",
820 (i
&0x02) ? "external" : "internal");
822 data
->vid_conf
= confreg
[3];
826 /* Fan clock dividers may be needed before any data is read */
827 for (i
= 0; i
< data
->fannr
; i
++) {
828 if (FAN_CONFIG_MONITOR(data
->fan_conf
, i
))
829 data
->fan_status
[i
] = pc87360_read_value(data
,
831 PC87360_REG_FAN_STATUS(i
));
835 if (devid
== 0xe9 && data
->address
[1]) /* PC87366 */
836 use_thermistors
= confreg
[2] & 0x40;
838 pc87360_init_client(new_client
, use_thermistors
);
841 /* Register sysfs hooks */
843 device_create_file(&new_client
->dev
, &dev_attr_in0_input
);
844 device_create_file(&new_client
->dev
, &dev_attr_in1_input
);
845 device_create_file(&new_client
->dev
, &dev_attr_in2_input
);
846 device_create_file(&new_client
->dev
, &dev_attr_in3_input
);
847 device_create_file(&new_client
->dev
, &dev_attr_in4_input
);
848 device_create_file(&new_client
->dev
, &dev_attr_in5_input
);
849 device_create_file(&new_client
->dev
, &dev_attr_in6_input
);
850 device_create_file(&new_client
->dev
, &dev_attr_in7_input
);
851 device_create_file(&new_client
->dev
, &dev_attr_in8_input
);
852 device_create_file(&new_client
->dev
, &dev_attr_in9_input
);
853 device_create_file(&new_client
->dev
, &dev_attr_in10_input
);
854 device_create_file(&new_client
->dev
, &dev_attr_in0_min
);
855 device_create_file(&new_client
->dev
, &dev_attr_in1_min
);
856 device_create_file(&new_client
->dev
, &dev_attr_in2_min
);
857 device_create_file(&new_client
->dev
, &dev_attr_in3_min
);
858 device_create_file(&new_client
->dev
, &dev_attr_in4_min
);
859 device_create_file(&new_client
->dev
, &dev_attr_in5_min
);
860 device_create_file(&new_client
->dev
, &dev_attr_in6_min
);
861 device_create_file(&new_client
->dev
, &dev_attr_in7_min
);
862 device_create_file(&new_client
->dev
, &dev_attr_in8_min
);
863 device_create_file(&new_client
->dev
, &dev_attr_in9_min
);
864 device_create_file(&new_client
->dev
, &dev_attr_in10_min
);
865 device_create_file(&new_client
->dev
, &dev_attr_in0_max
);
866 device_create_file(&new_client
->dev
, &dev_attr_in1_max
);
867 device_create_file(&new_client
->dev
, &dev_attr_in2_max
);
868 device_create_file(&new_client
->dev
, &dev_attr_in3_max
);
869 device_create_file(&new_client
->dev
, &dev_attr_in4_max
);
870 device_create_file(&new_client
->dev
, &dev_attr_in5_max
);
871 device_create_file(&new_client
->dev
, &dev_attr_in6_max
);
872 device_create_file(&new_client
->dev
, &dev_attr_in7_max
);
873 device_create_file(&new_client
->dev
, &dev_attr_in8_max
);
874 device_create_file(&new_client
->dev
, &dev_attr_in9_max
);
875 device_create_file(&new_client
->dev
, &dev_attr_in10_max
);
876 device_create_file(&new_client
->dev
, &dev_attr_in0_status
);
877 device_create_file(&new_client
->dev
, &dev_attr_in1_status
);
878 device_create_file(&new_client
->dev
, &dev_attr_in2_status
);
879 device_create_file(&new_client
->dev
, &dev_attr_in3_status
);
880 device_create_file(&new_client
->dev
, &dev_attr_in4_status
);
881 device_create_file(&new_client
->dev
, &dev_attr_in5_status
);
882 device_create_file(&new_client
->dev
, &dev_attr_in6_status
);
883 device_create_file(&new_client
->dev
, &dev_attr_in7_status
);
884 device_create_file(&new_client
->dev
, &dev_attr_in8_status
);
885 device_create_file(&new_client
->dev
, &dev_attr_in9_status
);
886 device_create_file(&new_client
->dev
, &dev_attr_in10_status
);
888 device_create_file(&new_client
->dev
, &dev_attr_cpu0_vid
);
889 device_create_file(&new_client
->dev
, &dev_attr_vrm
);
890 device_create_file(&new_client
->dev
, &dev_attr_alarms_in
);
894 device_create_file(&new_client
->dev
, &dev_attr_temp1_input
);
895 device_create_file(&new_client
->dev
, &dev_attr_temp2_input
);
896 device_create_file(&new_client
->dev
, &dev_attr_temp1_min
);
897 device_create_file(&new_client
->dev
, &dev_attr_temp2_min
);
898 device_create_file(&new_client
->dev
, &dev_attr_temp1_max
);
899 device_create_file(&new_client
->dev
, &dev_attr_temp2_max
);
900 device_create_file(&new_client
->dev
, &dev_attr_temp1_crit
);
901 device_create_file(&new_client
->dev
, &dev_attr_temp2_crit
);
902 device_create_file(&new_client
->dev
, &dev_attr_temp1_status
);
903 device_create_file(&new_client
->dev
, &dev_attr_temp2_status
);
905 device_create_file(&new_client
->dev
, &dev_attr_alarms_temp
);
907 if (data
->tempnr
== 3) {
908 device_create_file(&new_client
->dev
, &dev_attr_temp3_input
);
909 device_create_file(&new_client
->dev
, &dev_attr_temp3_min
);
910 device_create_file(&new_client
->dev
, &dev_attr_temp3_max
);
911 device_create_file(&new_client
->dev
, &dev_attr_temp3_crit
);
912 device_create_file(&new_client
->dev
, &dev_attr_temp3_status
);
914 if (data
->innr
== 14) {
915 device_create_file(&new_client
->dev
, &dev_attr_temp4_input
);
916 device_create_file(&new_client
->dev
, &dev_attr_temp5_input
);
917 device_create_file(&new_client
->dev
, &dev_attr_temp6_input
);
918 device_create_file(&new_client
->dev
, &dev_attr_temp4_min
);
919 device_create_file(&new_client
->dev
, &dev_attr_temp5_min
);
920 device_create_file(&new_client
->dev
, &dev_attr_temp6_min
);
921 device_create_file(&new_client
->dev
, &dev_attr_temp4_max
);
922 device_create_file(&new_client
->dev
, &dev_attr_temp5_max
);
923 device_create_file(&new_client
->dev
, &dev_attr_temp6_max
);
924 device_create_file(&new_client
->dev
, &dev_attr_temp4_crit
);
925 device_create_file(&new_client
->dev
, &dev_attr_temp5_crit
);
926 device_create_file(&new_client
->dev
, &dev_attr_temp6_crit
);
927 device_create_file(&new_client
->dev
, &dev_attr_temp4_status
);
928 device_create_file(&new_client
->dev
, &dev_attr_temp5_status
);
929 device_create_file(&new_client
->dev
, &dev_attr_temp6_status
);
933 if (FAN_CONFIG_MONITOR(data
->fan_conf
, 0)) {
934 device_create_file(&new_client
->dev
,
935 &dev_attr_fan1_input
);
936 device_create_file(&new_client
->dev
,
938 device_create_file(&new_client
->dev
,
940 device_create_file(&new_client
->dev
,
941 &dev_attr_fan1_status
);
944 if (FAN_CONFIG_MONITOR(data
->fan_conf
, 1)) {
945 device_create_file(&new_client
->dev
,
946 &dev_attr_fan2_input
);
947 device_create_file(&new_client
->dev
,
949 device_create_file(&new_client
->dev
,
951 device_create_file(&new_client
->dev
,
952 &dev_attr_fan2_status
);
955 if (FAN_CONFIG_CONTROL(data
->fan_conf
, 0))
956 device_create_file(&new_client
->dev
, &dev_attr_pwm1
);
957 if (FAN_CONFIG_CONTROL(data
->fan_conf
, 1))
958 device_create_file(&new_client
->dev
, &dev_attr_pwm2
);
960 if (data
->fannr
== 3) {
961 if (FAN_CONFIG_MONITOR(data
->fan_conf
, 2)) {
962 device_create_file(&new_client
->dev
,
963 &dev_attr_fan3_input
);
964 device_create_file(&new_client
->dev
,
966 device_create_file(&new_client
->dev
,
968 device_create_file(&new_client
->dev
,
969 &dev_attr_fan3_status
);
972 if (FAN_CONFIG_CONTROL(data
->fan_conf
, 2))
973 device_create_file(&new_client
->dev
, &dev_attr_pwm3
);
979 for (i
= 0; i
< 3; i
++) {
980 if (data
->address
[i
]) {
981 release_region(data
->address
[i
], PC87360_EXTENT
);
989 static int pc87360_detach_client(struct i2c_client
*client
)
991 struct pc87360_data
*data
= i2c_get_clientdata(client
);
994 if ((i
= i2c_detach_client(client
))) {
995 dev_err(&client
->dev
, "Client deregistration failed, "
996 "client not detached.\n");
1000 for (i
= 0; i
< 3; i
++) {
1001 if (data
->address
[i
]) {
1002 release_region(data
->address
[i
], PC87360_EXTENT
);
1010 /* ldi is the logical device index
1011 bank is for voltages and temperatures only */
1012 static int pc87360_read_value(struct pc87360_data
*data
, u8 ldi
, u8 bank
,
1017 down(&(data
->lock
));
1018 if (bank
!= NO_BANK
)
1019 outb_p(bank
, data
->address
[ldi
] + PC87365_REG_BANK
);
1020 res
= inb_p(data
->address
[ldi
] + reg
);
1026 static void pc87360_write_value(struct pc87360_data
*data
, u8 ldi
, u8 bank
,
1029 down(&(data
->lock
));
1030 if (bank
!= NO_BANK
)
1031 outb_p(bank
, data
->address
[ldi
] + PC87365_REG_BANK
);
1032 outb_p(value
, data
->address
[ldi
] + reg
);
1036 static void pc87360_init_client(struct i2c_client
*client
, int use_thermistors
)
1038 struct pc87360_data
*data
= i2c_get_clientdata(client
);
1040 const u8 init_in
[14] = { 2, 2, 2, 2, 2, 2, 2, 1, 1, 3, 1, 2, 2, 2 };
1041 const u8 init_temp
[3] = { 2, 2, 1 };
1044 if (init
>= 2 && data
->innr
) {
1045 reg
= pc87360_read_value(data
, LD_IN
, NO_BANK
,
1046 PC87365_REG_IN_CONVRATE
);
1047 dev_info(&client
->dev
, "VLM conversion set to"
1048 "1s period, 160us delay\n");
1049 pc87360_write_value(data
, LD_IN
, NO_BANK
,
1050 PC87365_REG_IN_CONVRATE
,
1051 (reg
& 0xC0) | 0x11);
1054 nr
= data
->innr
< 11 ? data
->innr
: 11;
1055 for (i
=0; i
<nr
; i
++) {
1056 if (init
>= init_in
[i
]) {
1057 /* Forcibly enable voltage channel */
1058 reg
= pc87360_read_value(data
, LD_IN
, i
,
1059 PC87365_REG_IN_STATUS
);
1060 if (!(reg
& 0x01)) {
1061 dev_dbg(&client
->dev
, "Forcibly "
1062 "enabling in%d\n", i
);
1063 pc87360_write_value(data
, LD_IN
, i
,
1064 PC87365_REG_IN_STATUS
,
1065 (reg
& 0x68) | 0x87);
1070 /* We can't blindly trust the Super-I/O space configuration bit,
1071 most BIOS won't set it properly */
1072 for (i
=11; i
<data
->innr
; i
++) {
1073 reg
= pc87360_read_value(data
, LD_IN
, i
,
1074 PC87365_REG_TEMP_STATUS
);
1075 use_thermistors
= use_thermistors
|| (reg
& 0x01);
1078 i
= use_thermistors
? 2 : 0;
1079 for (; i
<data
->tempnr
; i
++) {
1080 if (init
>= init_temp
[i
]) {
1081 /* Forcibly enable temperature channel */
1082 reg
= pc87360_read_value(data
, LD_TEMP
, i
,
1083 PC87365_REG_TEMP_STATUS
);
1084 if (!(reg
& 0x01)) {
1085 dev_dbg(&client
->dev
, "Forcibly "
1086 "enabling temp%d\n", i
+1);
1087 pc87360_write_value(data
, LD_TEMP
, i
,
1088 PC87365_REG_TEMP_STATUS
,
1094 if (use_thermistors
) {
1095 for (i
=11; i
<data
->innr
; i
++) {
1096 if (init
>= init_in
[i
]) {
1097 /* The pin may already be used by thermal
1099 reg
= pc87360_read_value(data
, LD_TEMP
,
1100 (i
-11)/2, PC87365_REG_TEMP_STATUS
);
1102 dev_dbg(&client
->dev
, "Skipping "
1103 "temp%d, pin already in use "
1104 "by temp%d\n", i
-7, (i
-11)/2);
1108 /* Forcibly enable thermistor channel */
1109 reg
= pc87360_read_value(data
, LD_IN
, i
,
1110 PC87365_REG_IN_STATUS
);
1111 if (!(reg
& 0x01)) {
1112 dev_dbg(&client
->dev
, "Forcibly "
1113 "enabling temp%d\n", i
-7);
1114 pc87360_write_value(data
, LD_IN
, i
,
1115 PC87365_REG_TEMP_STATUS
,
1116 (reg
& 0x60) | 0x8F);
1123 reg
= pc87360_read_value(data
, LD_IN
, NO_BANK
,
1124 PC87365_REG_IN_CONFIG
);
1126 dev_dbg(&client
->dev
, "Forcibly "
1127 "enabling monitoring (VLM)\n");
1128 pc87360_write_value(data
, LD_IN
, NO_BANK
,
1129 PC87365_REG_IN_CONFIG
,
1135 reg
= pc87360_read_value(data
, LD_TEMP
, NO_BANK
,
1136 PC87365_REG_TEMP_CONFIG
);
1138 dev_dbg(&client
->dev
, "Forcibly enabling "
1139 "monitoring (TMS)\n");
1140 pc87360_write_value(data
, LD_TEMP
, NO_BANK
,
1141 PC87365_REG_TEMP_CONFIG
,
1146 /* Chip config as documented by National Semi. */
1147 pc87360_write_value(data
, LD_TEMP
, 0xF, 0xA, 0x08);
1148 /* We voluntarily omit the bank here, in case the
1149 sequence itself matters. It shouldn't be a problem,
1150 since nobody else is supposed to access the
1151 device at that point. */
1152 pc87360_write_value(data
, LD_TEMP
, NO_BANK
, 0xB, 0x04);
1153 pc87360_write_value(data
, LD_TEMP
, NO_BANK
, 0xC, 0x35);
1154 pc87360_write_value(data
, LD_TEMP
, NO_BANK
, 0xD, 0x05);
1155 pc87360_write_value(data
, LD_TEMP
, NO_BANK
, 0xE, 0x05);
1160 static void pc87360_autodiv(struct i2c_client
*client
, int nr
)
1162 struct pc87360_data
*data
= i2c_get_clientdata(client
);
1163 u8 old_min
= data
->fan_min
[nr
];
1165 /* Increase clock divider if needed and possible */
1166 if ((data
->fan_status
[nr
] & 0x04) /* overflow flag */
1167 || (data
->fan
[nr
] >= 224)) { /* next to overflow */
1168 if ((data
->fan_status
[nr
] & 0x60) != 0x60) {
1169 data
->fan_status
[nr
] += 0x20;
1170 data
->fan_min
[nr
] >>= 1;
1171 data
->fan
[nr
] >>= 1;
1172 dev_dbg(&client
->dev
, "Increasing "
1173 "clock divider to %d for fan %d\n",
1174 FAN_DIV_FROM_REG(data
->fan_status
[nr
]), nr
+1);
1177 /* Decrease clock divider if possible */
1178 while (!(data
->fan_min
[nr
] & 0x80) /* min "nails" divider */
1179 && data
->fan
[nr
] < 85 /* bad accuracy */
1180 && (data
->fan_status
[nr
] & 0x60) != 0x00) {
1181 data
->fan_status
[nr
] -= 0x20;
1182 data
->fan_min
[nr
] <<= 1;
1183 data
->fan
[nr
] <<= 1;
1184 dev_dbg(&client
->dev
, "Decreasing "
1185 "clock divider to %d for fan %d\n",
1186 FAN_DIV_FROM_REG(data
->fan_status
[nr
]),
1191 /* Write new fan min if it changed */
1192 if (old_min
!= data
->fan_min
[nr
]) {
1193 pc87360_write_value(data
, LD_FAN
, NO_BANK
,
1194 PC87360_REG_FAN_MIN(nr
),
1199 static struct pc87360_data
*pc87360_update_device(struct device
*dev
)
1201 struct i2c_client
*client
= to_i2c_client(dev
);
1202 struct pc87360_data
*data
= i2c_get_clientdata(client
);
1205 down(&data
->update_lock
);
1207 if (time_after(jiffies
, data
->last_updated
+ HZ
* 2) || !data
->valid
) {
1208 dev_dbg(&client
->dev
, "Data update\n");
1211 for (i
= 0; i
< data
->fannr
; i
++) {
1212 if (FAN_CONFIG_MONITOR(data
->fan_conf
, i
)) {
1213 data
->fan_status
[i
] =
1214 pc87360_read_value(data
, LD_FAN
,
1215 NO_BANK
, PC87360_REG_FAN_STATUS(i
));
1216 data
->fan
[i
] = pc87360_read_value(data
, LD_FAN
,
1217 NO_BANK
, PC87360_REG_FAN(i
));
1218 data
->fan_min
[i
] = pc87360_read_value(data
,
1220 PC87360_REG_FAN_MIN(i
));
1221 /* Change clock divider if needed */
1222 pc87360_autodiv(client
, i
);
1223 /* Clear bits and write new divider */
1224 pc87360_write_value(data
, LD_FAN
, NO_BANK
,
1225 PC87360_REG_FAN_STATUS(i
),
1226 data
->fan_status
[i
]);
1228 if (FAN_CONFIG_CONTROL(data
->fan_conf
, i
))
1229 data
->pwm
[i
] = pc87360_read_value(data
, LD_FAN
,
1230 NO_BANK
, PC87360_REG_PWM(i
));
1234 for (i
= 0; i
< data
->innr
; i
++) {
1235 data
->in_status
[i
] = pc87360_read_value(data
, LD_IN
, i
,
1236 PC87365_REG_IN_STATUS
);
1238 pc87360_write_value(data
, LD_IN
, i
,
1239 PC87365_REG_IN_STATUS
,
1240 data
->in_status
[i
]);
1241 if ((data
->in_status
[i
] & 0x81) == 0x81) {
1242 data
->in
[i
] = pc87360_read_value(data
, LD_IN
,
1245 if (data
->in_status
[i
] & 0x01) {
1246 data
->in_min
[i
] = pc87360_read_value(data
,
1248 PC87365_REG_IN_MIN
);
1249 data
->in_max
[i
] = pc87360_read_value(data
,
1251 PC87365_REG_IN_MAX
);
1253 data
->in_crit
[i
-11] =
1254 pc87360_read_value(data
, LD_IN
,
1255 i
, PC87365_REG_TEMP_CRIT
);
1259 data
->in_alarms
= pc87360_read_value(data
, LD_IN
,
1260 NO_BANK
, PC87365_REG_IN_ALARMS1
)
1261 | ((pc87360_read_value(data
, LD_IN
,
1262 NO_BANK
, PC87365_REG_IN_ALARMS2
)
1264 data
->vid
= (data
->vid_conf
& 0xE0) ?
1265 pc87360_read_value(data
, LD_IN
,
1266 NO_BANK
, PC87365_REG_VID
) : 0x1F;
1270 for (i
= 0; i
< data
->tempnr
; i
++) {
1271 data
->temp_status
[i
] = pc87360_read_value(data
,
1273 PC87365_REG_TEMP_STATUS
);
1275 pc87360_write_value(data
, LD_TEMP
, i
,
1276 PC87365_REG_TEMP_STATUS
,
1277 data
->temp_status
[i
]);
1278 if ((data
->temp_status
[i
] & 0x81) == 0x81) {
1279 data
->temp
[i
] = pc87360_read_value(data
,
1283 if (data
->temp_status
[i
] & 0x01) {
1284 data
->temp_min
[i
] = pc87360_read_value(data
,
1286 PC87365_REG_TEMP_MIN
);
1287 data
->temp_max
[i
] = pc87360_read_value(data
,
1289 PC87365_REG_TEMP_MAX
);
1290 data
->temp_crit
[i
] = pc87360_read_value(data
,
1292 PC87365_REG_TEMP_CRIT
);
1296 data
->temp_alarms
= pc87360_read_value(data
, LD_TEMP
,
1297 NO_BANK
, PC87365_REG_TEMP_ALARMS
)
1301 data
->last_updated
= jiffies
;
1305 up(&data
->update_lock
);
1310 static int __init
pc87360_init(void)
1314 if (pc87360_find(0x2e, &devid
, extra_isa
)
1315 && pc87360_find(0x4e, &devid
, extra_isa
)) {
1316 printk(KERN_WARNING
"pc87360: PC8736x not detected, "
1317 "module not inserted.\n");
1321 /* Arbitrarily pick one of the addresses */
1322 for (i
= 0; i
< 3; i
++) {
1323 if (extra_isa
[i
] != 0x0000) {
1324 normal_isa
[0] = extra_isa
[i
];
1329 if (normal_isa
[0] == 0x0000) {
1330 printk(KERN_WARNING
"pc87360: No active logical device, "
1331 "module not inserted.\n");
1335 return i2c_add_driver(&pc87360_driver
);
1338 static void __exit
pc87360_exit(void)
1340 i2c_del_driver(&pc87360_driver
);
1344 MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
1345 MODULE_DESCRIPTION("PC8736x hardware monitor");
1346 MODULE_LICENSE("GPL");
1348 module_init(pc87360_init
);
1349 module_exit(pc87360_exit
);