2 * pc87360.c - Part of lm_sensors, Linux kernel modules
3 * for hardware monitoring
4 * Copyright (C) 2004, 2007 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 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
38 #include <linux/module.h>
39 #include <linux/init.h>
40 #include <linux/slab.h>
41 #include <linux/jiffies.h>
42 #include <linux/platform_device.h>
43 #include <linux/hwmon.h>
44 #include <linux/hwmon-sysfs.h>
45 #include <linux/hwmon-vid.h>
46 #include <linux/err.h>
47 #include <linux/mutex.h>
48 #include <linux/acpi.h>
52 static struct platform_device
*pdev
;
53 static unsigned short extra_isa
[3];
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");
65 static unsigned short force_id
;
66 module_param(force_id
, ushort
, 0);
67 MODULE_PARM_DESC(force_id
, "Override the detected device ID");
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 */
82 static const u8 logdev
[LDNI_MAX
] = { FSCM
, VLM
, TMS
};
88 static inline void superio_outb(int sioaddr
, int reg
, int val
)
91 outb(val
, sioaddr
+ 1);
94 static inline int superio_inb(int sioaddr
, int reg
)
97 return inb(sioaddr
+ 1);
100 static inline void superio_exit(int sioaddr
)
103 outb(0x02, sioaddr
+ 1);
110 #define PC87360_EXTENT 0x10
111 #define PC87365_REG_BANK 0x09
115 * Fan registers and conversions
118 /* nr has to be 0 or 1 (PC87360/87363) or 2 (PC87364/87365/87366) */
119 #define PC87360_REG_PRESCALE(nr) (0x00 + 2 * (nr))
120 #define PC87360_REG_PWM(nr) (0x01 + 2 * (nr))
121 #define PC87360_REG_FAN_MIN(nr) (0x06 + 3 * (nr))
122 #define PC87360_REG_FAN(nr) (0x07 + 3 * (nr))
123 #define PC87360_REG_FAN_STATUS(nr) (0x08 + 3 * (nr))
125 #define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : \
126 480000 / ((val) * (div)))
127 #define FAN_TO_REG(val, div) ((val) <= 100 ? 0 : \
128 480000 / ((val) * (div)))
129 #define FAN_DIV_FROM_REG(val) (1 << (((val) >> 5) & 0x03))
130 #define FAN_STATUS_FROM_REG(val) ((val) & 0x07)
132 #define FAN_CONFIG_MONITOR(val, nr) (((val) >> (2 + (nr) * 3)) & 1)
133 #define FAN_CONFIG_CONTROL(val, nr) (((val) >> (3 + (nr) * 3)) & 1)
134 #define FAN_CONFIG_INVERT(val, nr) (((val) >> (4 + (nr) * 3)) & 1)
136 #define PWM_FROM_REG(val, inv) ((inv) ? 255 - (val) : (val))
137 static inline u8
PWM_TO_REG(int val
, int inv
)
149 * Voltage registers and conversions
152 #define PC87365_REG_IN_CONVRATE 0x07
153 #define PC87365_REG_IN_CONFIG 0x08
154 #define PC87365_REG_IN 0x0B
155 #define PC87365_REG_IN_MIN 0x0D
156 #define PC87365_REG_IN_MAX 0x0C
157 #define PC87365_REG_IN_STATUS 0x0A
158 #define PC87365_REG_IN_ALARMS1 0x00
159 #define PC87365_REG_IN_ALARMS2 0x01
160 #define PC87365_REG_VID 0x06
162 #define IN_FROM_REG(val, ref) (((val) * (ref) + 128) / 256)
163 #define IN_TO_REG(val, ref) ((val) < 0 ? 0 : \
164 (val) * 256 >= (ref) * 255 ? 255 : \
165 ((val) * 256 + (ref) / 2) / (ref))
168 * Temperature registers and conversions
171 #define PC87365_REG_TEMP_CONFIG 0x08
172 #define PC87365_REG_TEMP 0x0B
173 #define PC87365_REG_TEMP_MIN 0x0D
174 #define PC87365_REG_TEMP_MAX 0x0C
175 #define PC87365_REG_TEMP_CRIT 0x0E
176 #define PC87365_REG_TEMP_STATUS 0x0A
177 #define PC87365_REG_TEMP_ALARMS 0x00
179 #define TEMP_FROM_REG(val) ((val) * 1000)
180 #define TEMP_TO_REG(val) ((val) < -55000 ? -55 : \
181 (val) > 127000 ? 127 : \
182 (val) < 0 ? ((val) - 500) / 1000 : \
183 ((val) + 500) / 1000)
189 struct pc87360_data
{
191 struct device
*hwmon_dev
;
193 struct mutex update_lock
;
194 char valid
; /* !=0 if following fields are valid */
195 unsigned long last_updated
; /* In jiffies */
199 u8 fannr
, innr
, tempnr
;
201 u8 fan
[3]; /* Register value */
202 u8 fan_min
[3]; /* Register value */
203 u8 fan_status
[3]; /* Register value */
204 u8 pwm
[3]; /* Register value */
205 u16 fan_conf
; /* Configuration register values, combined */
207 u16 in_vref
; /* 1 mV/bit */
208 u8 in
[14]; /* Register value */
209 u8 in_min
[14]; /* Register value */
210 u8 in_max
[14]; /* Register value */
211 u8 in_crit
[3]; /* Register value */
212 u8 in_status
[14]; /* Register value */
213 u16 in_alarms
; /* Register values, combined, masked */
214 u8 vid_conf
; /* Configuration register value */
216 u8 vid
; /* Register value */
218 s8 temp
[3]; /* Register value */
219 s8 temp_min
[3]; /* Register value */
220 s8 temp_max
[3]; /* Register value */
221 s8 temp_crit
[3]; /* Register value */
222 u8 temp_status
[3]; /* Register value */
223 u8 temp_alarms
; /* Register value, masked */
227 * Functions declaration
230 static int pc87360_probe(struct platform_device
*pdev
);
231 static int __devexit
pc87360_remove(struct platform_device
*pdev
);
233 static int pc87360_read_value(struct pc87360_data
*data
, u8 ldi
, u8 bank
,
235 static void pc87360_write_value(struct pc87360_data
*data
, u8 ldi
, u8 bank
,
237 static void pc87360_init_device(struct platform_device
*pdev
,
238 int use_thermistors
);
239 static struct pc87360_data
*pc87360_update_device(struct device
*dev
);
245 static struct platform_driver pc87360_driver
= {
247 .owner
= THIS_MODULE
,
250 .probe
= pc87360_probe
,
251 .remove
= __devexit_p(pc87360_remove
),
258 static ssize_t
show_fan_input(struct device
*dev
,
259 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
[attr
->index
],
264 FAN_DIV_FROM_REG(data
->fan_status
[attr
->index
])));
266 static ssize_t
show_fan_min(struct device
*dev
,
267 struct device_attribute
*devattr
, char *buf
)
269 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
270 struct pc87360_data
*data
= pc87360_update_device(dev
);
271 return sprintf(buf
, "%u\n", FAN_FROM_REG(data
->fan_min
[attr
->index
],
272 FAN_DIV_FROM_REG(data
->fan_status
[attr
->index
])));
274 static ssize_t
show_fan_div(struct device
*dev
,
275 struct device_attribute
*devattr
, char *buf
)
277 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
278 struct pc87360_data
*data
= pc87360_update_device(dev
);
279 return sprintf(buf
, "%u\n",
280 FAN_DIV_FROM_REG(data
->fan_status
[attr
->index
]));
282 static ssize_t
show_fan_status(struct device
*dev
,
283 struct device_attribute
*devattr
, char *buf
)
285 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
286 struct pc87360_data
*data
= pc87360_update_device(dev
);
287 return sprintf(buf
, "%u\n",
288 FAN_STATUS_FROM_REG(data
->fan_status
[attr
->index
]));
290 static ssize_t
set_fan_min(struct device
*dev
,
291 struct device_attribute
*devattr
, const char *buf
,
294 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
295 struct pc87360_data
*data
= dev_get_drvdata(dev
);
299 err
= kstrtol(buf
, 10, &fan_min
);
303 mutex_lock(&data
->update_lock
);
304 fan_min
= FAN_TO_REG(fan_min
,
305 FAN_DIV_FROM_REG(data
->fan_status
[attr
->index
]));
307 /* If it wouldn't fit, change clock divisor */
309 && (data
->fan_status
[attr
->index
] & 0x60) != 0x60) {
311 data
->fan
[attr
->index
] >>= 1;
312 data
->fan_status
[attr
->index
] += 0x20;
314 data
->fan_min
[attr
->index
] = fan_min
> 255 ? 255 : fan_min
;
315 pc87360_write_value(data
, LD_FAN
, NO_BANK
,
316 PC87360_REG_FAN_MIN(attr
->index
),
317 data
->fan_min
[attr
->index
]);
319 /* Write new divider, preserve alarm bits */
320 pc87360_write_value(data
, LD_FAN
, NO_BANK
,
321 PC87360_REG_FAN_STATUS(attr
->index
),
322 data
->fan_status
[attr
->index
] & 0xF9);
323 mutex_unlock(&data
->update_lock
);
328 static struct sensor_device_attribute fan_input
[] = {
329 SENSOR_ATTR(fan1_input
, S_IRUGO
, show_fan_input
, NULL
, 0),
330 SENSOR_ATTR(fan2_input
, S_IRUGO
, show_fan_input
, NULL
, 1),
331 SENSOR_ATTR(fan3_input
, S_IRUGO
, show_fan_input
, NULL
, 2),
333 static struct sensor_device_attribute fan_status
[] = {
334 SENSOR_ATTR(fan1_status
, S_IRUGO
, show_fan_status
, NULL
, 0),
335 SENSOR_ATTR(fan2_status
, S_IRUGO
, show_fan_status
, NULL
, 1),
336 SENSOR_ATTR(fan3_status
, S_IRUGO
, show_fan_status
, NULL
, 2),
338 static struct sensor_device_attribute fan_div
[] = {
339 SENSOR_ATTR(fan1_div
, S_IRUGO
, show_fan_div
, NULL
, 0),
340 SENSOR_ATTR(fan2_div
, S_IRUGO
, show_fan_div
, NULL
, 1),
341 SENSOR_ATTR(fan3_div
, S_IRUGO
, show_fan_div
, NULL
, 2),
343 static struct sensor_device_attribute fan_min
[] = {
344 SENSOR_ATTR(fan1_min
, S_IWUSR
| S_IRUGO
, show_fan_min
, set_fan_min
, 0),
345 SENSOR_ATTR(fan2_min
, S_IWUSR
| S_IRUGO
, show_fan_min
, set_fan_min
, 1),
346 SENSOR_ATTR(fan3_min
, S_IWUSR
| S_IRUGO
, show_fan_min
, set_fan_min
, 2),
349 #define FAN_UNIT_ATTRS(X) \
350 { &fan_input[X].dev_attr.attr, \
351 &fan_status[X].dev_attr.attr, \
352 &fan_div[X].dev_attr.attr, \
353 &fan_min[X].dev_attr.attr, \
357 static ssize_t
show_pwm(struct device
*dev
, struct device_attribute
*devattr
,
360 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
361 struct pc87360_data
*data
= pc87360_update_device(dev
);
362 return sprintf(buf
, "%u\n",
363 PWM_FROM_REG(data
->pwm
[attr
->index
],
364 FAN_CONFIG_INVERT(data
->fan_conf
,
367 static ssize_t
set_pwm(struct device
*dev
, struct device_attribute
*devattr
,
368 const char *buf
, size_t count
)
370 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
371 struct pc87360_data
*data
= dev_get_drvdata(dev
);
375 err
= kstrtol(buf
, 10, &val
);
379 mutex_lock(&data
->update_lock
);
380 data
->pwm
[attr
->index
] = PWM_TO_REG(val
,
381 FAN_CONFIG_INVERT(data
->fan_conf
, attr
->index
));
382 pc87360_write_value(data
, LD_FAN
, NO_BANK
, PC87360_REG_PWM(attr
->index
),
383 data
->pwm
[attr
->index
]);
384 mutex_unlock(&data
->update_lock
);
388 static struct sensor_device_attribute pwm
[] = {
389 SENSOR_ATTR(pwm1
, S_IWUSR
| S_IRUGO
, show_pwm
, set_pwm
, 0),
390 SENSOR_ATTR(pwm2
, S_IWUSR
| S_IRUGO
, show_pwm
, set_pwm
, 1),
391 SENSOR_ATTR(pwm3
, S_IWUSR
| S_IRUGO
, show_pwm
, set_pwm
, 2),
394 static struct attribute
*pc8736x_fan_attr
[][5] = {
400 static const struct attribute_group pc8736x_fan_attr_group
[] = {
401 { .attrs
= pc8736x_fan_attr
[0], },
402 { .attrs
= pc8736x_fan_attr
[1], },
403 { .attrs
= pc8736x_fan_attr
[2], },
406 static ssize_t
show_in_input(struct device
*dev
,
407 struct device_attribute
*devattr
, char *buf
)
409 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
410 struct pc87360_data
*data
= pc87360_update_device(dev
);
411 return sprintf(buf
, "%u\n", IN_FROM_REG(data
->in
[attr
->index
],
414 static ssize_t
show_in_min(struct device
*dev
,
415 struct device_attribute
*devattr
, char *buf
)
417 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
418 struct pc87360_data
*data
= pc87360_update_device(dev
);
419 return sprintf(buf
, "%u\n", IN_FROM_REG(data
->in_min
[attr
->index
],
422 static ssize_t
show_in_max(struct device
*dev
,
423 struct device_attribute
*devattr
, char *buf
)
425 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
426 struct pc87360_data
*data
= pc87360_update_device(dev
);
427 return sprintf(buf
, "%u\n", IN_FROM_REG(data
->in_max
[attr
->index
],
430 static ssize_t
show_in_status(struct device
*dev
,
431 struct device_attribute
*devattr
, char *buf
)
433 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
434 struct pc87360_data
*data
= pc87360_update_device(dev
);
435 return sprintf(buf
, "%u\n", data
->in_status
[attr
->index
]);
437 static ssize_t
set_in_min(struct device
*dev
, struct device_attribute
*devattr
,
438 const char *buf
, size_t count
)
440 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
441 struct pc87360_data
*data
= dev_get_drvdata(dev
);
445 err
= kstrtol(buf
, 10, &val
);
449 mutex_lock(&data
->update_lock
);
450 data
->in_min
[attr
->index
] = IN_TO_REG(val
, data
->in_vref
);
451 pc87360_write_value(data
, LD_IN
, attr
->index
, PC87365_REG_IN_MIN
,
452 data
->in_min
[attr
->index
]);
453 mutex_unlock(&data
->update_lock
);
456 static ssize_t
set_in_max(struct device
*dev
, struct device_attribute
*devattr
,
457 const char *buf
, size_t count
)
459 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
460 struct pc87360_data
*data
= dev_get_drvdata(dev
);
464 err
= kstrtol(buf
, 10, &val
);
468 mutex_lock(&data
->update_lock
);
469 data
->in_max
[attr
->index
] = IN_TO_REG(val
,
471 pc87360_write_value(data
, LD_IN
, attr
->index
, PC87365_REG_IN_MAX
,
472 data
->in_max
[attr
->index
]);
473 mutex_unlock(&data
->update_lock
);
477 static struct sensor_device_attribute in_input
[] = {
478 SENSOR_ATTR(in0_input
, S_IRUGO
, show_in_input
, NULL
, 0),
479 SENSOR_ATTR(in1_input
, S_IRUGO
, show_in_input
, NULL
, 1),
480 SENSOR_ATTR(in2_input
, S_IRUGO
, show_in_input
, NULL
, 2),
481 SENSOR_ATTR(in3_input
, S_IRUGO
, show_in_input
, NULL
, 3),
482 SENSOR_ATTR(in4_input
, S_IRUGO
, show_in_input
, NULL
, 4),
483 SENSOR_ATTR(in5_input
, S_IRUGO
, show_in_input
, NULL
, 5),
484 SENSOR_ATTR(in6_input
, S_IRUGO
, show_in_input
, NULL
, 6),
485 SENSOR_ATTR(in7_input
, S_IRUGO
, show_in_input
, NULL
, 7),
486 SENSOR_ATTR(in8_input
, S_IRUGO
, show_in_input
, NULL
, 8),
487 SENSOR_ATTR(in9_input
, S_IRUGO
, show_in_input
, NULL
, 9),
488 SENSOR_ATTR(in10_input
, S_IRUGO
, show_in_input
, NULL
, 10),
490 static struct sensor_device_attribute in_status
[] = {
491 SENSOR_ATTR(in0_status
, S_IRUGO
, show_in_status
, NULL
, 0),
492 SENSOR_ATTR(in1_status
, S_IRUGO
, show_in_status
, NULL
, 1),
493 SENSOR_ATTR(in2_status
, S_IRUGO
, show_in_status
, NULL
, 2),
494 SENSOR_ATTR(in3_status
, S_IRUGO
, show_in_status
, NULL
, 3),
495 SENSOR_ATTR(in4_status
, S_IRUGO
, show_in_status
, NULL
, 4),
496 SENSOR_ATTR(in5_status
, S_IRUGO
, show_in_status
, NULL
, 5),
497 SENSOR_ATTR(in6_status
, S_IRUGO
, show_in_status
, NULL
, 6),
498 SENSOR_ATTR(in7_status
, S_IRUGO
, show_in_status
, NULL
, 7),
499 SENSOR_ATTR(in8_status
, S_IRUGO
, show_in_status
, NULL
, 8),
500 SENSOR_ATTR(in9_status
, S_IRUGO
, show_in_status
, NULL
, 9),
501 SENSOR_ATTR(in10_status
, S_IRUGO
, show_in_status
, NULL
, 10),
503 static struct sensor_device_attribute in_min
[] = {
504 SENSOR_ATTR(in0_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 0),
505 SENSOR_ATTR(in1_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 1),
506 SENSOR_ATTR(in2_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 2),
507 SENSOR_ATTR(in3_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 3),
508 SENSOR_ATTR(in4_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 4),
509 SENSOR_ATTR(in5_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 5),
510 SENSOR_ATTR(in6_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 6),
511 SENSOR_ATTR(in7_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 7),
512 SENSOR_ATTR(in8_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 8),
513 SENSOR_ATTR(in9_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 9),
514 SENSOR_ATTR(in10_min
, S_IWUSR
| S_IRUGO
, show_in_min
, set_in_min
, 10),
516 static struct sensor_device_attribute in_max
[] = {
517 SENSOR_ATTR(in0_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 0),
518 SENSOR_ATTR(in1_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 1),
519 SENSOR_ATTR(in2_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 2),
520 SENSOR_ATTR(in3_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 3),
521 SENSOR_ATTR(in4_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 4),
522 SENSOR_ATTR(in5_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 5),
523 SENSOR_ATTR(in6_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 6),
524 SENSOR_ATTR(in7_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 7),
525 SENSOR_ATTR(in8_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 8),
526 SENSOR_ATTR(in9_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 9),
527 SENSOR_ATTR(in10_max
, S_IWUSR
| S_IRUGO
, show_in_max
, set_in_max
, 10),
530 /* (temp & vin) channel status register alarm bits (pdf sec.11.5.12) */
531 #define CHAN_ALM_MIN 0x02 /* min limit crossed */
532 #define CHAN_ALM_MAX 0x04 /* max limit exceeded */
533 #define TEMP_ALM_CRIT 0x08 /* temp crit exceeded (temp only) */
536 * show_in_min/max_alarm() reads data from the per-channel status
537 * register (sec 11.5.12), not the vin event status registers (sec
538 * 11.5.2) that (legacy) show_in_alarm() resds (via data->in_alarms)
541 static ssize_t
show_in_min_alarm(struct device
*dev
,
542 struct device_attribute
*devattr
, char *buf
)
544 struct pc87360_data
*data
= pc87360_update_device(dev
);
545 unsigned nr
= to_sensor_dev_attr(devattr
)->index
;
547 return sprintf(buf
, "%u\n", !!(data
->in_status
[nr
] & CHAN_ALM_MIN
));
549 static ssize_t
show_in_max_alarm(struct device
*dev
,
550 struct device_attribute
*devattr
, char *buf
)
552 struct pc87360_data
*data
= pc87360_update_device(dev
);
553 unsigned nr
= to_sensor_dev_attr(devattr
)->index
;
555 return sprintf(buf
, "%u\n", !!(data
->in_status
[nr
] & CHAN_ALM_MAX
));
558 static struct sensor_device_attribute in_min_alarm
[] = {
559 SENSOR_ATTR(in0_min_alarm
, S_IRUGO
, show_in_min_alarm
, NULL
, 0),
560 SENSOR_ATTR(in1_min_alarm
, S_IRUGO
, show_in_min_alarm
, NULL
, 1),
561 SENSOR_ATTR(in2_min_alarm
, S_IRUGO
, show_in_min_alarm
, NULL
, 2),
562 SENSOR_ATTR(in3_min_alarm
, S_IRUGO
, show_in_min_alarm
, NULL
, 3),
563 SENSOR_ATTR(in4_min_alarm
, S_IRUGO
, show_in_min_alarm
, NULL
, 4),
564 SENSOR_ATTR(in5_min_alarm
, S_IRUGO
, show_in_min_alarm
, NULL
, 5),
565 SENSOR_ATTR(in6_min_alarm
, S_IRUGO
, show_in_min_alarm
, NULL
, 6),
566 SENSOR_ATTR(in7_min_alarm
, S_IRUGO
, show_in_min_alarm
, NULL
, 7),
567 SENSOR_ATTR(in8_min_alarm
, S_IRUGO
, show_in_min_alarm
, NULL
, 8),
568 SENSOR_ATTR(in9_min_alarm
, S_IRUGO
, show_in_min_alarm
, NULL
, 9),
569 SENSOR_ATTR(in10_min_alarm
, S_IRUGO
, show_in_min_alarm
, NULL
, 10),
571 static struct sensor_device_attribute in_max_alarm
[] = {
572 SENSOR_ATTR(in0_max_alarm
, S_IRUGO
, show_in_max_alarm
, NULL
, 0),
573 SENSOR_ATTR(in1_max_alarm
, S_IRUGO
, show_in_max_alarm
, NULL
, 1),
574 SENSOR_ATTR(in2_max_alarm
, S_IRUGO
, show_in_max_alarm
, NULL
, 2),
575 SENSOR_ATTR(in3_max_alarm
, S_IRUGO
, show_in_max_alarm
, NULL
, 3),
576 SENSOR_ATTR(in4_max_alarm
, S_IRUGO
, show_in_max_alarm
, NULL
, 4),
577 SENSOR_ATTR(in5_max_alarm
, S_IRUGO
, show_in_max_alarm
, NULL
, 5),
578 SENSOR_ATTR(in6_max_alarm
, S_IRUGO
, show_in_max_alarm
, NULL
, 6),
579 SENSOR_ATTR(in7_max_alarm
, S_IRUGO
, show_in_max_alarm
, NULL
, 7),
580 SENSOR_ATTR(in8_max_alarm
, S_IRUGO
, show_in_max_alarm
, NULL
, 8),
581 SENSOR_ATTR(in9_max_alarm
, S_IRUGO
, show_in_max_alarm
, NULL
, 9),
582 SENSOR_ATTR(in10_max_alarm
, S_IRUGO
, show_in_max_alarm
, NULL
, 10),
585 #define VIN_UNIT_ATTRS(X) \
586 &in_input[X].dev_attr.attr, \
587 &in_status[X].dev_attr.attr, \
588 &in_min[X].dev_attr.attr, \
589 &in_max[X].dev_attr.attr, \
590 &in_min_alarm[X].dev_attr.attr, \
591 &in_max_alarm[X].dev_attr.attr
593 static ssize_t
show_vid(struct device
*dev
, struct device_attribute
*attr
,
596 struct pc87360_data
*data
= pc87360_update_device(dev
);
597 return sprintf(buf
, "%u\n", vid_from_reg(data
->vid
, data
->vrm
));
599 static DEVICE_ATTR(cpu0_vid
, S_IRUGO
, show_vid
, NULL
);
601 static ssize_t
show_vrm(struct device
*dev
, struct device_attribute
*attr
,
604 struct pc87360_data
*data
= dev_get_drvdata(dev
);
605 return sprintf(buf
, "%u\n", data
->vrm
);
607 static ssize_t
set_vrm(struct device
*dev
, struct device_attribute
*attr
,
608 const char *buf
, size_t count
)
610 struct pc87360_data
*data
= dev_get_drvdata(dev
);
614 err
= kstrtoul(buf
, 10, &val
);
621 static DEVICE_ATTR(vrm
, S_IRUGO
| S_IWUSR
, show_vrm
, set_vrm
);
623 static ssize_t
show_in_alarms(struct device
*dev
,
624 struct device_attribute
*attr
, char *buf
)
626 struct pc87360_data
*data
= pc87360_update_device(dev
);
627 return sprintf(buf
, "%u\n", data
->in_alarms
);
629 static DEVICE_ATTR(alarms_in
, S_IRUGO
, show_in_alarms
, NULL
);
631 static struct attribute
*pc8736x_vin_attr_array
[] = {
643 &dev_attr_cpu0_vid
.attr
,
645 &dev_attr_alarms_in
.attr
,
648 static const struct attribute_group pc8736x_vin_group
= {
649 .attrs
= pc8736x_vin_attr_array
,
652 static ssize_t
show_therm_input(struct device
*dev
,
653 struct device_attribute
*devattr
, char *buf
)
655 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
656 struct pc87360_data
*data
= pc87360_update_device(dev
);
657 return sprintf(buf
, "%u\n", IN_FROM_REG(data
->in
[attr
->index
],
660 static ssize_t
show_therm_min(struct device
*dev
,
661 struct device_attribute
*devattr
, char *buf
)
663 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
664 struct pc87360_data
*data
= pc87360_update_device(dev
);
665 return sprintf(buf
, "%u\n", IN_FROM_REG(data
->in_min
[attr
->index
],
668 static ssize_t
show_therm_max(struct device
*dev
,
669 struct device_attribute
*devattr
, char *buf
)
671 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
672 struct pc87360_data
*data
= pc87360_update_device(dev
);
673 return sprintf(buf
, "%u\n", IN_FROM_REG(data
->in_max
[attr
->index
],
676 static ssize_t
show_therm_crit(struct device
*dev
,
677 struct device_attribute
*devattr
, char *buf
)
679 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
680 struct pc87360_data
*data
= pc87360_update_device(dev
);
681 return sprintf(buf
, "%u\n", IN_FROM_REG(data
->in_crit
[attr
->index
-11],
684 static ssize_t
show_therm_status(struct device
*dev
,
685 struct device_attribute
*devattr
, char *buf
)
687 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
688 struct pc87360_data
*data
= pc87360_update_device(dev
);
689 return sprintf(buf
, "%u\n", data
->in_status
[attr
->index
]);
692 static ssize_t
set_therm_min(struct device
*dev
,
693 struct device_attribute
*devattr
,
694 const char *buf
, size_t count
)
696 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
697 struct pc87360_data
*data
= dev_get_drvdata(dev
);
701 err
= kstrtol(buf
, 10, &val
);
705 mutex_lock(&data
->update_lock
);
706 data
->in_min
[attr
->index
] = IN_TO_REG(val
, data
->in_vref
);
707 pc87360_write_value(data
, LD_IN
, attr
->index
, PC87365_REG_TEMP_MIN
,
708 data
->in_min
[attr
->index
]);
709 mutex_unlock(&data
->update_lock
);
713 static ssize_t
set_therm_max(struct device
*dev
,
714 struct device_attribute
*devattr
,
715 const char *buf
, size_t count
)
717 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
718 struct pc87360_data
*data
= dev_get_drvdata(dev
);
722 err
= kstrtol(buf
, 10, &val
);
726 mutex_lock(&data
->update_lock
);
727 data
->in_max
[attr
->index
] = IN_TO_REG(val
, data
->in_vref
);
728 pc87360_write_value(data
, LD_IN
, attr
->index
, PC87365_REG_TEMP_MAX
,
729 data
->in_max
[attr
->index
]);
730 mutex_unlock(&data
->update_lock
);
733 static ssize_t
set_therm_crit(struct device
*dev
,
734 struct device_attribute
*devattr
,
735 const char *buf
, size_t count
)
737 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
738 struct pc87360_data
*data
= dev_get_drvdata(dev
);
742 err
= kstrtol(buf
, 10, &val
);
746 mutex_lock(&data
->update_lock
);
747 data
->in_crit
[attr
->index
-11] = IN_TO_REG(val
, data
->in_vref
);
748 pc87360_write_value(data
, LD_IN
, attr
->index
, PC87365_REG_TEMP_CRIT
,
749 data
->in_crit
[attr
->index
-11]);
750 mutex_unlock(&data
->update_lock
);
755 * the +11 term below reflects the fact that VLM units 11,12,13 are
756 * used in the chip to measure voltage across the thermistors
758 static struct sensor_device_attribute therm_input
[] = {
759 SENSOR_ATTR(temp4_input
, S_IRUGO
, show_therm_input
, NULL
, 0 + 11),
760 SENSOR_ATTR(temp5_input
, S_IRUGO
, show_therm_input
, NULL
, 1 + 11),
761 SENSOR_ATTR(temp6_input
, S_IRUGO
, show_therm_input
, NULL
, 2 + 11),
763 static struct sensor_device_attribute therm_status
[] = {
764 SENSOR_ATTR(temp4_status
, S_IRUGO
, show_therm_status
, NULL
, 0 + 11),
765 SENSOR_ATTR(temp5_status
, S_IRUGO
, show_therm_status
, NULL
, 1 + 11),
766 SENSOR_ATTR(temp6_status
, S_IRUGO
, show_therm_status
, NULL
, 2 + 11),
768 static struct sensor_device_attribute therm_min
[] = {
769 SENSOR_ATTR(temp4_min
, S_IRUGO
| S_IWUSR
,
770 show_therm_min
, set_therm_min
, 0 + 11),
771 SENSOR_ATTR(temp5_min
, S_IRUGO
| S_IWUSR
,
772 show_therm_min
, set_therm_min
, 1 + 11),
773 SENSOR_ATTR(temp6_min
, S_IRUGO
| S_IWUSR
,
774 show_therm_min
, set_therm_min
, 2 + 11),
776 static struct sensor_device_attribute therm_max
[] = {
777 SENSOR_ATTR(temp4_max
, S_IRUGO
| S_IWUSR
,
778 show_therm_max
, set_therm_max
, 0 + 11),
779 SENSOR_ATTR(temp5_max
, S_IRUGO
| S_IWUSR
,
780 show_therm_max
, set_therm_max
, 1 + 11),
781 SENSOR_ATTR(temp6_max
, S_IRUGO
| S_IWUSR
,
782 show_therm_max
, set_therm_max
, 2 + 11),
784 static struct sensor_device_attribute therm_crit
[] = {
785 SENSOR_ATTR(temp4_crit
, S_IRUGO
| S_IWUSR
,
786 show_therm_crit
, set_therm_crit
, 0 + 11),
787 SENSOR_ATTR(temp5_crit
, S_IRUGO
| S_IWUSR
,
788 show_therm_crit
, set_therm_crit
, 1 + 11),
789 SENSOR_ATTR(temp6_crit
, S_IRUGO
| S_IWUSR
,
790 show_therm_crit
, set_therm_crit
, 2 + 11),
794 * show_therm_min/max_alarm() reads data from the per-channel voltage
795 * status register (sec 11.5.12)
798 static ssize_t
show_therm_min_alarm(struct device
*dev
,
799 struct device_attribute
*devattr
, char *buf
)
801 struct pc87360_data
*data
= pc87360_update_device(dev
);
802 unsigned nr
= to_sensor_dev_attr(devattr
)->index
;
804 return sprintf(buf
, "%u\n", !!(data
->in_status
[nr
] & CHAN_ALM_MIN
));
806 static ssize_t
show_therm_max_alarm(struct device
*dev
,
807 struct device_attribute
*devattr
, char *buf
)
809 struct pc87360_data
*data
= pc87360_update_device(dev
);
810 unsigned nr
= to_sensor_dev_attr(devattr
)->index
;
812 return sprintf(buf
, "%u\n", !!(data
->in_status
[nr
] & CHAN_ALM_MAX
));
814 static ssize_t
show_therm_crit_alarm(struct device
*dev
,
815 struct device_attribute
*devattr
, char *buf
)
817 struct pc87360_data
*data
= pc87360_update_device(dev
);
818 unsigned nr
= to_sensor_dev_attr(devattr
)->index
;
820 return sprintf(buf
, "%u\n", !!(data
->in_status
[nr
] & TEMP_ALM_CRIT
));
823 static struct sensor_device_attribute therm_min_alarm
[] = {
824 SENSOR_ATTR(temp4_min_alarm
, S_IRUGO
,
825 show_therm_min_alarm
, NULL
, 0 + 11),
826 SENSOR_ATTR(temp5_min_alarm
, S_IRUGO
,
827 show_therm_min_alarm
, NULL
, 1 + 11),
828 SENSOR_ATTR(temp6_min_alarm
, S_IRUGO
,
829 show_therm_min_alarm
, NULL
, 2 + 11),
831 static struct sensor_device_attribute therm_max_alarm
[] = {
832 SENSOR_ATTR(temp4_max_alarm
, S_IRUGO
,
833 show_therm_max_alarm
, NULL
, 0 + 11),
834 SENSOR_ATTR(temp5_max_alarm
, S_IRUGO
,
835 show_therm_max_alarm
, NULL
, 1 + 11),
836 SENSOR_ATTR(temp6_max_alarm
, S_IRUGO
,
837 show_therm_max_alarm
, NULL
, 2 + 11),
839 static struct sensor_device_attribute therm_crit_alarm
[] = {
840 SENSOR_ATTR(temp4_crit_alarm
, S_IRUGO
,
841 show_therm_crit_alarm
, NULL
, 0 + 11),
842 SENSOR_ATTR(temp5_crit_alarm
, S_IRUGO
,
843 show_therm_crit_alarm
, NULL
, 1 + 11),
844 SENSOR_ATTR(temp6_crit_alarm
, S_IRUGO
,
845 show_therm_crit_alarm
, NULL
, 2 + 11),
848 #define THERM_UNIT_ATTRS(X) \
849 &therm_input[X].dev_attr.attr, \
850 &therm_status[X].dev_attr.attr, \
851 &therm_min[X].dev_attr.attr, \
852 &therm_max[X].dev_attr.attr, \
853 &therm_crit[X].dev_attr.attr, \
854 &therm_min_alarm[X].dev_attr.attr, \
855 &therm_max_alarm[X].dev_attr.attr, \
856 &therm_crit_alarm[X].dev_attr.attr
858 static struct attribute
*pc8736x_therm_attr_array
[] = {
864 static const struct attribute_group pc8736x_therm_group
= {
865 .attrs
= pc8736x_therm_attr_array
,
868 static ssize_t
show_temp_input(struct device
*dev
,
869 struct device_attribute
*devattr
, char *buf
)
871 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
872 struct pc87360_data
*data
= pc87360_update_device(dev
);
873 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp
[attr
->index
]));
876 static ssize_t
show_temp_min(struct device
*dev
,
877 struct device_attribute
*devattr
, char *buf
)
879 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
880 struct pc87360_data
*data
= pc87360_update_device(dev
);
881 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_min
[attr
->index
]));
884 static ssize_t
show_temp_max(struct device
*dev
,
885 struct device_attribute
*devattr
, char *buf
)
887 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
888 struct pc87360_data
*data
= pc87360_update_device(dev
);
889 return sprintf(buf
, "%d\n", TEMP_FROM_REG(data
->temp_max
[attr
->index
]));
892 static ssize_t
show_temp_crit(struct device
*dev
,
893 struct device_attribute
*devattr
, char *buf
)
895 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
896 struct pc87360_data
*data
= pc87360_update_device(dev
);
897 return sprintf(buf
, "%d\n",
898 TEMP_FROM_REG(data
->temp_crit
[attr
->index
]));
901 static ssize_t
show_temp_status(struct device
*dev
,
902 struct device_attribute
*devattr
, char *buf
)
904 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
905 struct pc87360_data
*data
= pc87360_update_device(dev
);
906 return sprintf(buf
, "%d\n", data
->temp_status
[attr
->index
]);
909 static ssize_t
set_temp_min(struct device
*dev
,
910 struct device_attribute
*devattr
,
911 const char *buf
, size_t count
)
913 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
914 struct pc87360_data
*data
= dev_get_drvdata(dev
);
918 err
= kstrtol(buf
, 10, &val
);
922 mutex_lock(&data
->update_lock
);
923 data
->temp_min
[attr
->index
] = TEMP_TO_REG(val
);
924 pc87360_write_value(data
, LD_TEMP
, attr
->index
, PC87365_REG_TEMP_MIN
,
925 data
->temp_min
[attr
->index
]);
926 mutex_unlock(&data
->update_lock
);
930 static ssize_t
set_temp_max(struct device
*dev
,
931 struct device_attribute
*devattr
,
932 const char *buf
, size_t count
)
934 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
935 struct pc87360_data
*data
= dev_get_drvdata(dev
);
939 err
= kstrtol(buf
, 10, &val
);
943 mutex_lock(&data
->update_lock
);
944 data
->temp_max
[attr
->index
] = TEMP_TO_REG(val
);
945 pc87360_write_value(data
, LD_TEMP
, attr
->index
, PC87365_REG_TEMP_MAX
,
946 data
->temp_max
[attr
->index
]);
947 mutex_unlock(&data
->update_lock
);
951 static ssize_t
set_temp_crit(struct device
*dev
,
952 struct device_attribute
*devattr
, const char *buf
,
955 struct sensor_device_attribute
*attr
= to_sensor_dev_attr(devattr
);
956 struct pc87360_data
*data
= dev_get_drvdata(dev
);
960 err
= kstrtol(buf
, 10, &val
);
964 mutex_lock(&data
->update_lock
);
965 data
->temp_crit
[attr
->index
] = TEMP_TO_REG(val
);
966 pc87360_write_value(data
, LD_TEMP
, attr
->index
, PC87365_REG_TEMP_CRIT
,
967 data
->temp_crit
[attr
->index
]);
968 mutex_unlock(&data
->update_lock
);
972 static struct sensor_device_attribute temp_input
[] = {
973 SENSOR_ATTR(temp1_input
, S_IRUGO
, show_temp_input
, NULL
, 0),
974 SENSOR_ATTR(temp2_input
, S_IRUGO
, show_temp_input
, NULL
, 1),
975 SENSOR_ATTR(temp3_input
, S_IRUGO
, show_temp_input
, NULL
, 2),
977 static struct sensor_device_attribute temp_status
[] = {
978 SENSOR_ATTR(temp1_status
, S_IRUGO
, show_temp_status
, NULL
, 0),
979 SENSOR_ATTR(temp2_status
, S_IRUGO
, show_temp_status
, NULL
, 1),
980 SENSOR_ATTR(temp3_status
, S_IRUGO
, show_temp_status
, NULL
, 2),
982 static struct sensor_device_attribute temp_min
[] = {
983 SENSOR_ATTR(temp1_min
, S_IRUGO
| S_IWUSR
,
984 show_temp_min
, set_temp_min
, 0),
985 SENSOR_ATTR(temp2_min
, S_IRUGO
| S_IWUSR
,
986 show_temp_min
, set_temp_min
, 1),
987 SENSOR_ATTR(temp3_min
, S_IRUGO
| S_IWUSR
,
988 show_temp_min
, set_temp_min
, 2),
990 static struct sensor_device_attribute temp_max
[] = {
991 SENSOR_ATTR(temp1_max
, S_IRUGO
| S_IWUSR
,
992 show_temp_max
, set_temp_max
, 0),
993 SENSOR_ATTR(temp2_max
, S_IRUGO
| S_IWUSR
,
994 show_temp_max
, set_temp_max
, 1),
995 SENSOR_ATTR(temp3_max
, S_IRUGO
| S_IWUSR
,
996 show_temp_max
, set_temp_max
, 2),
998 static struct sensor_device_attribute temp_crit
[] = {
999 SENSOR_ATTR(temp1_crit
, S_IRUGO
| S_IWUSR
,
1000 show_temp_crit
, set_temp_crit
, 0),
1001 SENSOR_ATTR(temp2_crit
, S_IRUGO
| S_IWUSR
,
1002 show_temp_crit
, set_temp_crit
, 1),
1003 SENSOR_ATTR(temp3_crit
, S_IRUGO
| S_IWUSR
,
1004 show_temp_crit
, set_temp_crit
, 2),
1007 static ssize_t
show_temp_alarms(struct device
*dev
,
1008 struct device_attribute
*attr
, char *buf
)
1010 struct pc87360_data
*data
= pc87360_update_device(dev
);
1011 return sprintf(buf
, "%u\n", data
->temp_alarms
);
1014 static DEVICE_ATTR(alarms_temp
, S_IRUGO
, show_temp_alarms
, NULL
);
1017 * show_temp_min/max_alarm() reads data from the per-channel status
1018 * register (sec 12.3.7), not the temp event status registers (sec
1019 * 12.3.2) that show_temp_alarm() reads (via data->temp_alarms)
1022 static ssize_t
show_temp_min_alarm(struct device
*dev
,
1023 struct device_attribute
*devattr
, char *buf
)
1025 struct pc87360_data
*data
= pc87360_update_device(dev
);
1026 unsigned nr
= to_sensor_dev_attr(devattr
)->index
;
1028 return sprintf(buf
, "%u\n", !!(data
->temp_status
[nr
] & CHAN_ALM_MIN
));
1031 static ssize_t
show_temp_max_alarm(struct device
*dev
,
1032 struct device_attribute
*devattr
, char *buf
)
1034 struct pc87360_data
*data
= pc87360_update_device(dev
);
1035 unsigned nr
= to_sensor_dev_attr(devattr
)->index
;
1037 return sprintf(buf
, "%u\n", !!(data
->temp_status
[nr
] & CHAN_ALM_MAX
));
1040 static ssize_t
show_temp_crit_alarm(struct device
*dev
,
1041 struct device_attribute
*devattr
, char *buf
)
1043 struct pc87360_data
*data
= pc87360_update_device(dev
);
1044 unsigned nr
= to_sensor_dev_attr(devattr
)->index
;
1046 return sprintf(buf
, "%u\n", !!(data
->temp_status
[nr
] & TEMP_ALM_CRIT
));
1049 static struct sensor_device_attribute temp_min_alarm
[] = {
1050 SENSOR_ATTR(temp1_min_alarm
, S_IRUGO
, show_temp_min_alarm
, NULL
, 0),
1051 SENSOR_ATTR(temp2_min_alarm
, S_IRUGO
, show_temp_min_alarm
, NULL
, 1),
1052 SENSOR_ATTR(temp3_min_alarm
, S_IRUGO
, show_temp_min_alarm
, NULL
, 2),
1055 static struct sensor_device_attribute temp_max_alarm
[] = {
1056 SENSOR_ATTR(temp1_max_alarm
, S_IRUGO
, show_temp_max_alarm
, NULL
, 0),
1057 SENSOR_ATTR(temp2_max_alarm
, S_IRUGO
, show_temp_max_alarm
, NULL
, 1),
1058 SENSOR_ATTR(temp3_max_alarm
, S_IRUGO
, show_temp_max_alarm
, NULL
, 2),
1061 static struct sensor_device_attribute temp_crit_alarm
[] = {
1062 SENSOR_ATTR(temp1_crit_alarm
, S_IRUGO
, show_temp_crit_alarm
, NULL
, 0),
1063 SENSOR_ATTR(temp2_crit_alarm
, S_IRUGO
, show_temp_crit_alarm
, NULL
, 1),
1064 SENSOR_ATTR(temp3_crit_alarm
, S_IRUGO
, show_temp_crit_alarm
, NULL
, 2),
1067 #define TEMP_FAULT 0x40 /* open diode */
1068 static ssize_t
show_temp_fault(struct device
*dev
,
1069 struct device_attribute
*devattr
, char *buf
)
1071 struct pc87360_data
*data
= pc87360_update_device(dev
);
1072 unsigned nr
= to_sensor_dev_attr(devattr
)->index
;
1074 return sprintf(buf
, "%u\n", !!(data
->temp_status
[nr
] & TEMP_FAULT
));
1076 static struct sensor_device_attribute temp_fault
[] = {
1077 SENSOR_ATTR(temp1_fault
, S_IRUGO
, show_temp_fault
, NULL
, 0),
1078 SENSOR_ATTR(temp2_fault
, S_IRUGO
, show_temp_fault
, NULL
, 1),
1079 SENSOR_ATTR(temp3_fault
, S_IRUGO
, show_temp_fault
, NULL
, 2),
1082 #define TEMP_UNIT_ATTRS(X) \
1083 { &temp_input[X].dev_attr.attr, \
1084 &temp_status[X].dev_attr.attr, \
1085 &temp_min[X].dev_attr.attr, \
1086 &temp_max[X].dev_attr.attr, \
1087 &temp_crit[X].dev_attr.attr, \
1088 &temp_min_alarm[X].dev_attr.attr, \
1089 &temp_max_alarm[X].dev_attr.attr, \
1090 &temp_crit_alarm[X].dev_attr.attr, \
1091 &temp_fault[X].dev_attr.attr, \
1095 static struct attribute
*pc8736x_temp_attr
[][10] = {
1101 static const struct attribute_group pc8736x_temp_attr_group
[] = {
1102 { .attrs
= pc8736x_temp_attr
[0] },
1103 { .attrs
= pc8736x_temp_attr
[1] },
1104 { .attrs
= pc8736x_temp_attr
[2] }
1107 static ssize_t
show_name(struct device
*dev
,
1108 struct device_attribute
*devattr
, char *buf
)
1110 struct pc87360_data
*data
= dev_get_drvdata(dev
);
1111 return sprintf(buf
, "%s\n", data
->name
);
1114 static DEVICE_ATTR(name
, S_IRUGO
, show_name
, NULL
);
1117 * Device detection, registration and update
1120 static int __init
pc87360_find(int sioaddr
, u8
*devid
,
1121 unsigned short *addresses
)
1125 int nrdev
; /* logical device count */
1127 /* No superio_enter */
1129 /* Identify device */
1130 val
= force_id
? force_id
: superio_inb(sioaddr
, DEVID
);
1132 case 0xE1: /* PC87360 */
1133 case 0xE8: /* PC87363 */
1134 case 0xE4: /* PC87364 */
1137 case 0xE5: /* PC87365 */
1138 case 0xE9: /* PC87366 */
1142 superio_exit(sioaddr
);
1145 /* Remember the device id */
1148 for (i
= 0; i
< nrdev
; i
++) {
1149 /* select logical device */
1150 superio_outb(sioaddr
, DEV
, logdev
[i
]);
1152 val
= superio_inb(sioaddr
, ACT
);
1153 if (!(val
& 0x01)) {
1154 pr_info("Device 0x%02x not activated\n", logdev
[i
]);
1158 val
= (superio_inb(sioaddr
, BASE
) << 8)
1159 | superio_inb(sioaddr
, BASE
+ 1);
1161 pr_info("Base address not set for device 0x%02x\n",
1168 if (i
== 0) { /* Fans */
1169 confreg
[0] = superio_inb(sioaddr
, 0xF0);
1170 confreg
[1] = superio_inb(sioaddr
, 0xF1);
1172 pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 1,
1173 (confreg
[0] >> 2) & 1, (confreg
[0] >> 3) & 1,
1174 (confreg
[0] >> 4) & 1);
1175 pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 2,
1176 (confreg
[0] >> 5) & 1, (confreg
[0] >> 6) & 1,
1177 (confreg
[0] >> 7) & 1);
1178 pr_debug("Fan %d: mon=%d ctrl=%d inv=%d\n", 3,
1179 confreg
[1] & 1, (confreg
[1] >> 1) & 1,
1180 (confreg
[1] >> 2) & 1);
1181 } else if (i
== 1) { /* Voltages */
1182 /* Are we using thermistors? */
1183 if (*devid
== 0xE9) { /* PC87366 */
1185 * These registers are not logical-device
1186 * specific, just that we won't need them if
1187 * we don't use the VLM device
1189 confreg
[2] = superio_inb(sioaddr
, 0x2B);
1190 confreg
[3] = superio_inb(sioaddr
, 0x25);
1192 if (confreg
[2] & 0x40) {
1193 pr_info("Using thermistors for "
1194 "temperature monitoring\n");
1196 if (confreg
[3] & 0xE0) {
1197 pr_info("VID inputs routed (mode %u)\n",
1204 superio_exit(sioaddr
);
1208 static void pc87360_remove_files(struct device
*dev
)
1212 device_remove_file(dev
, &dev_attr_name
);
1213 device_remove_file(dev
, &dev_attr_alarms_temp
);
1214 for (i
= 0; i
< ARRAY_SIZE(pc8736x_temp_attr_group
); i
++)
1215 sysfs_remove_group(&dev
->kobj
, &pc8736x_temp_attr_group
[i
]);
1216 for (i
= 0; i
< ARRAY_SIZE(pc8736x_fan_attr_group
); i
++) {
1217 sysfs_remove_group(&pdev
->dev
.kobj
, &pc8736x_fan_attr_group
[i
]);
1218 device_remove_file(dev
, &pwm
[i
].dev_attr
);
1220 sysfs_remove_group(&dev
->kobj
, &pc8736x_therm_group
);
1221 sysfs_remove_group(&dev
->kobj
, &pc8736x_vin_group
);
1224 static int __devinit
pc87360_probe(struct platform_device
*pdev
)
1227 struct pc87360_data
*data
;
1229 const char *name
= "pc87360";
1230 int use_thermistors
= 0;
1231 struct device
*dev
= &pdev
->dev
;
1233 data
= kzalloc(sizeof(struct pc87360_data
), GFP_KERNEL
);
1251 data
->fannr
= extra_isa
[0] ? 3 : 0;
1252 data
->innr
= extra_isa
[1] ? 11 : 0;
1253 data
->tempnr
= extra_isa
[2] ? 2 : 0;
1257 data
->fannr
= extra_isa
[0] ? 3 : 0;
1258 data
->innr
= extra_isa
[1] ? 14 : 0;
1259 data
->tempnr
= extra_isa
[2] ? 3 : 0;
1265 mutex_init(&data
->lock
);
1266 mutex_init(&data
->update_lock
);
1267 platform_set_drvdata(pdev
, data
);
1269 for (i
= 0; i
< LDNI_MAX
; i
++) {
1270 data
->address
[i
] = extra_isa
[i
];
1271 if (data
->address
[i
]
1272 && !request_region(extra_isa
[i
], PC87360_EXTENT
,
1273 pc87360_driver
.driver
.name
)) {
1274 dev_err(dev
, "Region 0x%x-0x%x already "
1275 "in use!\n", extra_isa
[i
],
1276 extra_isa
[i
]+PC87360_EXTENT
-1);
1277 for (i
--; i
>= 0; i
--)
1278 release_region(extra_isa
[i
], PC87360_EXTENT
);
1284 /* Retrieve the fans configuration from Super-I/O space */
1286 data
->fan_conf
= confreg
[0] | (confreg
[1] << 8);
1289 * Use the correct reference voltage
1290 * Unless both the VLM and the TMS logical devices agree to
1291 * use an external Vref, the internal one is used.
1294 i
= pc87360_read_value(data
, LD_IN
, NO_BANK
,
1295 PC87365_REG_IN_CONFIG
);
1297 i
&= pc87360_read_value(data
, LD_TEMP
, NO_BANK
,
1298 PC87365_REG_TEMP_CONFIG
);
1300 data
->in_vref
= (i
&0x02) ? 3025 : 2966;
1301 dev_dbg(dev
, "Using %s reference voltage\n",
1302 (i
&0x02) ? "external" : "internal");
1304 data
->vid_conf
= confreg
[3];
1305 data
->vrm
= vid_which_vrm();
1308 /* Fan clock dividers may be needed before any data is read */
1309 for (i
= 0; i
< data
->fannr
; i
++) {
1310 if (FAN_CONFIG_MONITOR(data
->fan_conf
, i
))
1311 data
->fan_status
[i
] = pc87360_read_value(data
,
1313 PC87360_REG_FAN_STATUS(i
));
1317 if (devid
== 0xe9 && data
->address
[1]) /* PC87366 */
1318 use_thermistors
= confreg
[2] & 0x40;
1320 pc87360_init_device(pdev
, use_thermistors
);
1323 /* Register all-or-nothing sysfs groups */
1326 err
= sysfs_create_group(&dev
->kobj
, &pc8736x_vin_group
);
1331 if (data
->innr
== 14) {
1332 err
= sysfs_create_group(&dev
->kobj
, &pc8736x_therm_group
);
1337 /* create device attr-files for varying sysfs groups */
1340 for (i
= 0; i
< data
->tempnr
; i
++) {
1341 err
= sysfs_create_group(&dev
->kobj
,
1342 &pc8736x_temp_attr_group
[i
]);
1346 err
= device_create_file(dev
, &dev_attr_alarms_temp
);
1351 for (i
= 0; i
< data
->fannr
; i
++) {
1352 if (FAN_CONFIG_MONITOR(data
->fan_conf
, i
)) {
1353 err
= sysfs_create_group(&dev
->kobj
,
1354 &pc8736x_fan_attr_group
[i
]);
1358 if (FAN_CONFIG_CONTROL(data
->fan_conf
, i
)) {
1359 err
= device_create_file(dev
, &pwm
[i
].dev_attr
);
1365 err
= device_create_file(dev
, &dev_attr_name
);
1369 data
->hwmon_dev
= hwmon_device_register(dev
);
1370 if (IS_ERR(data
->hwmon_dev
)) {
1371 err
= PTR_ERR(data
->hwmon_dev
);
1377 pc87360_remove_files(dev
);
1378 for (i
= 0; i
< 3; i
++) {
1379 if (data
->address
[i
])
1380 release_region(data
->address
[i
], PC87360_EXTENT
);
1387 static int __devexit
pc87360_remove(struct platform_device
*pdev
)
1389 struct pc87360_data
*data
= platform_get_drvdata(pdev
);
1392 hwmon_device_unregister(data
->hwmon_dev
);
1393 pc87360_remove_files(&pdev
->dev
);
1394 for (i
= 0; i
< 3; i
++) {
1395 if (data
->address
[i
])
1396 release_region(data
->address
[i
], PC87360_EXTENT
);
1404 * ldi is the logical device index
1405 * bank is for voltages and temperatures only
1407 static int pc87360_read_value(struct pc87360_data
*data
, u8 ldi
, u8 bank
,
1412 mutex_lock(&(data
->lock
));
1413 if (bank
!= NO_BANK
)
1414 outb_p(bank
, data
->address
[ldi
] + PC87365_REG_BANK
);
1415 res
= inb_p(data
->address
[ldi
] + reg
);
1416 mutex_unlock(&(data
->lock
));
1421 static void pc87360_write_value(struct pc87360_data
*data
, u8 ldi
, u8 bank
,
1424 mutex_lock(&(data
->lock
));
1425 if (bank
!= NO_BANK
)
1426 outb_p(bank
, data
->address
[ldi
] + PC87365_REG_BANK
);
1427 outb_p(value
, data
->address
[ldi
] + reg
);
1428 mutex_unlock(&(data
->lock
));
1431 /* (temp & vin) channel conversion status register flags (pdf sec.11.5.12) */
1432 #define CHAN_CNVRTD 0x80 /* new data ready */
1433 #define CHAN_ENA 0x01 /* enabled channel (temp or vin) */
1434 #define CHAN_ALM_ENA 0x10 /* propagate to alarms-reg ?? (chk val!) */
1435 #define CHAN_READY (CHAN_ENA|CHAN_CNVRTD) /* sample ready mask */
1437 #define TEMP_OTS_OE 0x20 /* OTS Output Enable */
1438 #define VIN_RW1C_MASK (CHAN_READY|CHAN_ALM_MAX|CHAN_ALM_MIN) /* 0x87 */
1439 #define TEMP_RW1C_MASK (VIN_RW1C_MASK|TEMP_ALM_CRIT|TEMP_FAULT) /* 0xCF */
1441 static void pc87360_init_device(struct platform_device
*pdev
,
1442 int use_thermistors
)
1444 struct pc87360_data
*data
= platform_get_drvdata(pdev
);
1446 const u8 init_in
[14] = { 2, 2, 2, 2, 2, 2, 2, 1, 1, 3, 1, 2, 2, 2 };
1447 const u8 init_temp
[3] = { 2, 2, 1 };
1450 if (init
>= 2 && data
->innr
) {
1451 reg
= pc87360_read_value(data
, LD_IN
, NO_BANK
,
1452 PC87365_REG_IN_CONVRATE
);
1453 dev_info(&pdev
->dev
, "VLM conversion set to "
1454 "1s period, 160us delay\n");
1455 pc87360_write_value(data
, LD_IN
, NO_BANK
,
1456 PC87365_REG_IN_CONVRATE
,
1457 (reg
& 0xC0) | 0x11);
1460 nr
= data
->innr
< 11 ? data
->innr
: 11;
1461 for (i
= 0; i
< nr
; i
++) {
1462 reg
= pc87360_read_value(data
, LD_IN
, i
,
1463 PC87365_REG_IN_STATUS
);
1464 dev_dbg(&pdev
->dev
, "bios in%d status:0x%02x\n", i
, reg
);
1465 if (init
>= init_in
[i
]) {
1466 /* Forcibly enable voltage channel */
1467 if (!(reg
& CHAN_ENA
)) {
1468 dev_dbg(&pdev
->dev
, "Forcibly "
1469 "enabling in%d\n", i
);
1470 pc87360_write_value(data
, LD_IN
, i
,
1471 PC87365_REG_IN_STATUS
,
1472 (reg
& 0x68) | 0x87);
1478 * We can't blindly trust the Super-I/O space configuration bit,
1479 * most BIOS won't set it properly
1481 dev_dbg(&pdev
->dev
, "bios thermistors:%d\n", use_thermistors
);
1482 for (i
= 11; i
< data
->innr
; i
++) {
1483 reg
= pc87360_read_value(data
, LD_IN
, i
,
1484 PC87365_REG_TEMP_STATUS
);
1485 use_thermistors
= use_thermistors
|| (reg
& CHAN_ENA
);
1486 /* thermistors are temp[4-6], measured on vin[11-14] */
1487 dev_dbg(&pdev
->dev
, "bios temp%d_status:0x%02x\n", i
-7, reg
);
1489 dev_dbg(&pdev
->dev
, "using thermistors:%d\n", use_thermistors
);
1491 i
= use_thermistors
? 2 : 0;
1492 for (; i
< data
->tempnr
; i
++) {
1493 reg
= pc87360_read_value(data
, LD_TEMP
, i
,
1494 PC87365_REG_TEMP_STATUS
);
1495 dev_dbg(&pdev
->dev
, "bios temp%d_status:0x%02x\n", i
+ 1, reg
);
1496 if (init
>= init_temp
[i
]) {
1497 /* Forcibly enable temperature channel */
1498 if (!(reg
& CHAN_ENA
)) {
1500 "Forcibly enabling temp%d\n", i
+ 1);
1501 pc87360_write_value(data
, LD_TEMP
, i
,
1502 PC87365_REG_TEMP_STATUS
,
1508 if (use_thermistors
) {
1509 for (i
= 11; i
< data
->innr
; i
++) {
1510 if (init
>= init_in
[i
]) {
1512 * The pin may already be used by thermal
1515 reg
= pc87360_read_value(data
, LD_TEMP
,
1516 (i
- 11) / 2, PC87365_REG_TEMP_STATUS
);
1517 if (reg
& CHAN_ENA
) {
1519 "Skipping temp%d, pin already in use by temp%d\n",
1520 i
- 7, (i
- 11) / 2);
1524 /* Forcibly enable thermistor channel */
1525 reg
= pc87360_read_value(data
, LD_IN
, i
,
1526 PC87365_REG_IN_STATUS
);
1527 if (!(reg
& CHAN_ENA
)) {
1529 "Forcibly enabling temp%d\n",
1531 pc87360_write_value(data
, LD_IN
, i
,
1532 PC87365_REG_TEMP_STATUS
,
1533 (reg
& 0x60) | 0x8F);
1540 reg
= pc87360_read_value(data
, LD_IN
, NO_BANK
,
1541 PC87365_REG_IN_CONFIG
);
1542 dev_dbg(&pdev
->dev
, "bios vin-cfg:0x%02x\n", reg
);
1543 if (reg
& CHAN_ENA
) {
1545 "Forcibly enabling monitoring (VLM)\n");
1546 pc87360_write_value(data
, LD_IN
, NO_BANK
,
1547 PC87365_REG_IN_CONFIG
,
1553 reg
= pc87360_read_value(data
, LD_TEMP
, NO_BANK
,
1554 PC87365_REG_TEMP_CONFIG
);
1555 dev_dbg(&pdev
->dev
, "bios temp-cfg:0x%02x\n", reg
);
1556 if (reg
& CHAN_ENA
) {
1558 "Forcibly enabling monitoring (TMS)\n");
1559 pc87360_write_value(data
, LD_TEMP
, NO_BANK
,
1560 PC87365_REG_TEMP_CONFIG
,
1565 /* Chip config as documented by National Semi. */
1566 pc87360_write_value(data
, LD_TEMP
, 0xF, 0xA, 0x08);
1568 * We voluntarily omit the bank here, in case the
1569 * sequence itself matters. It shouldn't be a problem,
1570 * since nobody else is supposed to access the
1571 * device at that point.
1573 pc87360_write_value(data
, LD_TEMP
, NO_BANK
, 0xB, 0x04);
1574 pc87360_write_value(data
, LD_TEMP
, NO_BANK
, 0xC, 0x35);
1575 pc87360_write_value(data
, LD_TEMP
, NO_BANK
, 0xD, 0x05);
1576 pc87360_write_value(data
, LD_TEMP
, NO_BANK
, 0xE, 0x05);
1581 static void pc87360_autodiv(struct device
*dev
, int nr
)
1583 struct pc87360_data
*data
= dev_get_drvdata(dev
);
1584 u8 old_min
= data
->fan_min
[nr
];
1586 /* Increase clock divider if needed and possible */
1587 if ((data
->fan_status
[nr
] & 0x04) /* overflow flag */
1588 || (data
->fan
[nr
] >= 224)) { /* next to overflow */
1589 if ((data
->fan_status
[nr
] & 0x60) != 0x60) {
1590 data
->fan_status
[nr
] += 0x20;
1591 data
->fan_min
[nr
] >>= 1;
1592 data
->fan
[nr
] >>= 1;
1593 dev_dbg(dev
, "Increasing "
1594 "clock divider to %d for fan %d\n",
1595 FAN_DIV_FROM_REG(data
->fan_status
[nr
]), nr
+ 1);
1598 /* Decrease clock divider if possible */
1599 while (!(data
->fan_min
[nr
] & 0x80) /* min "nails" divider */
1600 && data
->fan
[nr
] < 85 /* bad accuracy */
1601 && (data
->fan_status
[nr
] & 0x60) != 0x00) {
1602 data
->fan_status
[nr
] -= 0x20;
1603 data
->fan_min
[nr
] <<= 1;
1604 data
->fan
[nr
] <<= 1;
1605 dev_dbg(dev
, "Decreasing "
1606 "clock divider to %d for fan %d\n",
1607 FAN_DIV_FROM_REG(data
->fan_status
[nr
]),
1612 /* Write new fan min if it changed */
1613 if (old_min
!= data
->fan_min
[nr
]) {
1614 pc87360_write_value(data
, LD_FAN
, NO_BANK
,
1615 PC87360_REG_FAN_MIN(nr
),
1620 static struct pc87360_data
*pc87360_update_device(struct device
*dev
)
1622 struct pc87360_data
*data
= dev_get_drvdata(dev
);
1625 mutex_lock(&data
->update_lock
);
1627 if (time_after(jiffies
, data
->last_updated
+ HZ
* 2) || !data
->valid
) {
1628 dev_dbg(dev
, "Data update\n");
1631 for (i
= 0; i
< data
->fannr
; i
++) {
1632 if (FAN_CONFIG_MONITOR(data
->fan_conf
, i
)) {
1633 data
->fan_status
[i
] =
1634 pc87360_read_value(data
, LD_FAN
,
1635 NO_BANK
, PC87360_REG_FAN_STATUS(i
));
1636 data
->fan
[i
] = pc87360_read_value(data
, LD_FAN
,
1637 NO_BANK
, PC87360_REG_FAN(i
));
1638 data
->fan_min
[i
] = pc87360_read_value(data
,
1640 PC87360_REG_FAN_MIN(i
));
1641 /* Change clock divider if needed */
1642 pc87360_autodiv(dev
, i
);
1643 /* Clear bits and write new divider */
1644 pc87360_write_value(data
, LD_FAN
, NO_BANK
,
1645 PC87360_REG_FAN_STATUS(i
),
1646 data
->fan_status
[i
]);
1648 if (FAN_CONFIG_CONTROL(data
->fan_conf
, i
))
1649 data
->pwm
[i
] = pc87360_read_value(data
, LD_FAN
,
1650 NO_BANK
, PC87360_REG_PWM(i
));
1654 for (i
= 0; i
< data
->innr
; i
++) {
1655 data
->in_status
[i
] = pc87360_read_value(data
, LD_IN
, i
,
1656 PC87365_REG_IN_STATUS
);
1658 pc87360_write_value(data
, LD_IN
, i
,
1659 PC87365_REG_IN_STATUS
,
1660 data
->in_status
[i
]);
1661 if ((data
->in_status
[i
] & CHAN_READY
) == CHAN_READY
) {
1662 data
->in
[i
] = pc87360_read_value(data
, LD_IN
,
1665 if (data
->in_status
[i
] & CHAN_ENA
) {
1666 data
->in_min
[i
] = pc87360_read_value(data
,
1668 PC87365_REG_IN_MIN
);
1669 data
->in_max
[i
] = pc87360_read_value(data
,
1671 PC87365_REG_IN_MAX
);
1673 data
->in_crit
[i
-11] =
1674 pc87360_read_value(data
, LD_IN
,
1675 i
, PC87365_REG_TEMP_CRIT
);
1679 data
->in_alarms
= pc87360_read_value(data
, LD_IN
,
1680 NO_BANK
, PC87365_REG_IN_ALARMS1
)
1681 | ((pc87360_read_value(data
, LD_IN
,
1682 NO_BANK
, PC87365_REG_IN_ALARMS2
)
1684 data
->vid
= (data
->vid_conf
& 0xE0) ?
1685 pc87360_read_value(data
, LD_IN
,
1686 NO_BANK
, PC87365_REG_VID
) : 0x1F;
1690 for (i
= 0; i
< data
->tempnr
; i
++) {
1691 data
->temp_status
[i
] = pc87360_read_value(data
,
1693 PC87365_REG_TEMP_STATUS
);
1695 pc87360_write_value(data
, LD_TEMP
, i
,
1696 PC87365_REG_TEMP_STATUS
,
1697 data
->temp_status
[i
]);
1698 if ((data
->temp_status
[i
] & CHAN_READY
) == CHAN_READY
) {
1699 data
->temp
[i
] = pc87360_read_value(data
,
1703 if (data
->temp_status
[i
] & CHAN_ENA
) {
1704 data
->temp_min
[i
] = pc87360_read_value(data
,
1706 PC87365_REG_TEMP_MIN
);
1707 data
->temp_max
[i
] = pc87360_read_value(data
,
1709 PC87365_REG_TEMP_MAX
);
1710 data
->temp_crit
[i
] = pc87360_read_value(data
,
1712 PC87365_REG_TEMP_CRIT
);
1716 data
->temp_alarms
= pc87360_read_value(data
, LD_TEMP
,
1717 NO_BANK
, PC87365_REG_TEMP_ALARMS
)
1721 data
->last_updated
= jiffies
;
1725 mutex_unlock(&data
->update_lock
);
1730 static int __init
pc87360_device_add(unsigned short address
)
1732 struct resource res
[3];
1733 int err
, i
, res_count
;
1735 pdev
= platform_device_alloc("pc87360", address
);
1738 pr_err("Device allocation failed\n");
1742 memset(res
, 0, 3 * sizeof(struct resource
));
1744 for (i
= 0; i
< 3; i
++) {
1747 res
[res_count
].start
= extra_isa
[i
];
1748 res
[res_count
].end
= extra_isa
[i
] + PC87360_EXTENT
- 1;
1749 res
[res_count
].name
= "pc87360",
1750 res
[res_count
].flags
= IORESOURCE_IO
,
1752 err
= acpi_check_resource_conflict(&res
[res_count
]);
1754 goto exit_device_put
;
1759 err
= platform_device_add_resources(pdev
, res
, res_count
);
1761 pr_err("Device resources addition failed (%d)\n", err
);
1762 goto exit_device_put
;
1765 err
= platform_device_add(pdev
);
1767 pr_err("Device addition failed (%d)\n", err
);
1768 goto exit_device_put
;
1774 platform_device_put(pdev
);
1779 static int __init
pc87360_init(void)
1782 unsigned short address
= 0;
1784 if (pc87360_find(0x2e, &devid
, extra_isa
)
1785 && pc87360_find(0x4e, &devid
, extra_isa
)) {
1786 pr_warn("PC8736x not detected, module not inserted\n");
1790 /* Arbitrarily pick one of the addresses */
1791 for (i
= 0; i
< 3; i
++) {
1792 if (extra_isa
[i
] != 0x0000) {
1793 address
= extra_isa
[i
];
1798 if (address
== 0x0000) {
1799 pr_warn("No active logical device, module not inserted\n");
1803 err
= platform_driver_register(&pc87360_driver
);
1807 /* Sets global pdev as a side effect */
1808 err
= pc87360_device_add(address
);
1815 platform_driver_unregister(&pc87360_driver
);
1820 static void __exit
pc87360_exit(void)
1822 platform_device_unregister(pdev
);
1823 platform_driver_unregister(&pc87360_driver
);
1827 MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
1828 MODULE_DESCRIPTION("PC8736x hardware monitor");
1829 MODULE_LICENSE("GPL");
1831 module_init(pc87360_init
);
1832 module_exit(pc87360_exit
);