blob: 5fbfa34c110e36e455e632363eaff7228f4b0aaf [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * pc87360.c - Part of lm_sensors, Linux kernel modules
3 * for hardware monitoring
Jean Delvaref641b582007-06-09 10:11:16 -04004 * Copyright (C) 2004, 2007 Jean Delvare <khali@linux-fr.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * Copied from smsc47m1.c:
7 * Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com>
8 *
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.
13 *
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.
18 *
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.
22 *
23 * Supports the following chips:
24 *
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
31 *
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).
34 */
35
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/module.h>
37#include <linux/init.h>
38#include <linux/slab.h>
39#include <linux/jiffies.h>
Jean Delvaref641b582007-06-09 10:11:16 -040040#include <linux/platform_device.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040041#include <linux/hwmon.h>
Jim Cromief0986bd2005-09-02 22:52:43 +020042#include <linux/hwmon-sysfs.h>
Jean Delvare303760b2005-07-31 21:52:01 +020043#include <linux/hwmon-vid.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040044#include <linux/err.h>
Ingo Molnar9a61bf62006-01-18 23:19:26 +010045#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <asm/io.h>
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048static u8 devid;
Jean Delvaref641b582007-06-09 10:11:16 -040049static struct platform_device *pdev;
Jean Delvare2d8672c2005-07-19 23:56:35 +020050static unsigned short extra_isa[3];
Linus Torvalds1da177e2005-04-16 15:20:36 -070051static u8 confreg[4];
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053static int init = 1;
54module_param(init, int, 0);
55MODULE_PARM_DESC(init,
56 "Chip initialization level:\n"
57 " 0: None\n"
58 "*1: Forcibly enable internal voltage and temperature channels, except in9\n"
59 " 2: Forcibly enable all voltage and temperature channels, except in9\n"
60 " 3: Forcibly enable all voltage and temperature channels, including in9");
61
Jean Delvare67b671b2007-12-06 23:13:42 +010062static unsigned short force_id;
63module_param(force_id, ushort, 0);
64MODULE_PARM_DESC(force_id, "Override the detected device ID");
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066/*
67 * Super-I/O registers and operations
68 */
69
70#define DEV 0x07 /* Register: Logical device select */
71#define DEVID 0x20 /* Register: Device ID */
72#define ACT 0x30 /* Register: Device activation */
73#define BASE 0x60 /* Register: Base address */
74
75#define FSCM 0x09 /* Logical device: fans */
76#define VLM 0x0d /* Logical device: voltages */
77#define TMS 0x0e /* Logical device: temperatures */
Jim Cromie2a32ec22008-10-18 20:27:33 -070078#define LDNI_MAX 3
79static const u8 logdev[LDNI_MAX] = { FSCM, VLM, TMS };
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
81#define LD_FAN 0
82#define LD_IN 1
83#define LD_TEMP 2
84
85static inline void superio_outb(int sioaddr, int reg, int val)
86{
87 outb(reg, sioaddr);
88 outb(val, sioaddr+1);
89}
90
91static inline int superio_inb(int sioaddr, int reg)
92{
93 outb(reg, sioaddr);
94 return inb(sioaddr+1);
95}
96
97static inline void superio_exit(int sioaddr)
98{
99 outb(0x02, sioaddr);
100 outb(0x02, sioaddr+1);
101}
102
103/*
104 * Logical devices
105 */
106
107#define PC87360_EXTENT 0x10
108#define PC87365_REG_BANK 0x09
109#define NO_BANK 0xff
110
111/*
112 * Fan registers and conversions
113 */
114
115/* nr has to be 0 or 1 (PC87360/87363) or 2 (PC87364/87365/87366) */
116#define PC87360_REG_PRESCALE(nr) (0x00 + 2 * (nr))
117#define PC87360_REG_PWM(nr) (0x01 + 2 * (nr))
118#define PC87360_REG_FAN_MIN(nr) (0x06 + 3 * (nr))
119#define PC87360_REG_FAN(nr) (0x07 + 3 * (nr))
120#define PC87360_REG_FAN_STATUS(nr) (0x08 + 3 * (nr))
121
122#define FAN_FROM_REG(val,div) ((val) == 0 ? 0: \
123 480000 / ((val)*(div)))
124#define FAN_TO_REG(val,div) ((val) <= 100 ? 0 : \
125 480000 / ((val)*(div)))
126#define FAN_DIV_FROM_REG(val) (1 << ((val >> 5) & 0x03))
127#define FAN_STATUS_FROM_REG(val) ((val) & 0x07)
128
129#define FAN_CONFIG_MONITOR(val,nr) (((val) >> (2 + nr * 3)) & 1)
130#define FAN_CONFIG_CONTROL(val,nr) (((val) >> (3 + nr * 3)) & 1)
131#define FAN_CONFIG_INVERT(val,nr) (((val) >> (4 + nr * 3)) & 1)
132
133#define PWM_FROM_REG(val,inv) ((inv) ? 255 - (val) : (val))
134static inline u8 PWM_TO_REG(int val, int inv)
135{
136 if (inv)
137 val = 255 - val;
138 if (val < 0)
139 return 0;
140 if (val > 255)
141 return 255;
142 return val;
143}
144
145/*
146 * Voltage registers and conversions
147 */
148
149#define PC87365_REG_IN_CONVRATE 0x07
150#define PC87365_REG_IN_CONFIG 0x08
151#define PC87365_REG_IN 0x0B
152#define PC87365_REG_IN_MIN 0x0D
153#define PC87365_REG_IN_MAX 0x0C
154#define PC87365_REG_IN_STATUS 0x0A
155#define PC87365_REG_IN_ALARMS1 0x00
156#define PC87365_REG_IN_ALARMS2 0x01
157#define PC87365_REG_VID 0x06
158
159#define IN_FROM_REG(val,ref) (((val) * (ref) + 128) / 256)
160#define IN_TO_REG(val,ref) ((val) < 0 ? 0 : \
161 (val)*256 >= (ref)*255 ? 255: \
162 ((val) * 256 + (ref)/2) / (ref))
163
164/*
165 * Temperature registers and conversions
166 */
167
168#define PC87365_REG_TEMP_CONFIG 0x08
169#define PC87365_REG_TEMP 0x0B
170#define PC87365_REG_TEMP_MIN 0x0D
171#define PC87365_REG_TEMP_MAX 0x0C
172#define PC87365_REG_TEMP_CRIT 0x0E
173#define PC87365_REG_TEMP_STATUS 0x0A
174#define PC87365_REG_TEMP_ALARMS 0x00
175
176#define TEMP_FROM_REG(val) ((val) * 1000)
177#define TEMP_TO_REG(val) ((val) < -55000 ? -55 : \
178 (val) > 127000 ? 127 : \
179 (val) < 0 ? ((val) - 500) / 1000 : \
180 ((val) + 500) / 1000)
181
182/*
Jean Delvaref641b582007-06-09 10:11:16 -0400183 * Device data
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 */
185
186struct pc87360_data {
Jean Delvaref641b582007-06-09 10:11:16 -0400187 const char *name;
Tony Jones1beeffe2007-08-20 13:46:20 -0700188 struct device *hwmon_dev;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100189 struct mutex lock;
190 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 char valid; /* !=0 if following fields are valid */
192 unsigned long last_updated; /* In jiffies */
193
194 int address[3];
195
196 u8 fannr, innr, tempnr;
197
198 u8 fan[3]; /* Register value */
199 u8 fan_min[3]; /* Register value */
200 u8 fan_status[3]; /* Register value */
201 u8 pwm[3]; /* Register value */
202 u16 fan_conf; /* Configuration register values, combined */
203
204 u16 in_vref; /* 1 mV/bit */
205 u8 in[14]; /* Register value */
206 u8 in_min[14]; /* Register value */
207 u8 in_max[14]; /* Register value */
208 u8 in_crit[3]; /* Register value */
209 u8 in_status[14]; /* Register value */
210 u16 in_alarms; /* Register values, combined, masked */
211 u8 vid_conf; /* Configuration register value */
212 u8 vrm;
213 u8 vid; /* Register value */
214
215 s8 temp[3]; /* Register value */
216 s8 temp_min[3]; /* Register value */
217 s8 temp_max[3]; /* Register value */
218 s8 temp_crit[3]; /* Register value */
219 u8 temp_status[3]; /* Register value */
220 u8 temp_alarms; /* Register value, masked */
221};
222
223/*
224 * Functions declaration
225 */
226
Jean Delvaref641b582007-06-09 10:11:16 -0400227static int pc87360_probe(struct platform_device *pdev);
Jean Delvared0546122007-07-22 12:09:48 +0200228static int __devexit pc87360_remove(struct platform_device *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank,
231 u8 reg);
232static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank,
233 u8 reg, u8 value);
Jean Delvaref641b582007-06-09 10:11:16 -0400234static void pc87360_init_device(struct platform_device *pdev,
235 int use_thermistors);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236static struct pc87360_data *pc87360_update_device(struct device *dev);
237
238/*
Jean Delvaref641b582007-06-09 10:11:16 -0400239 * Driver data
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 */
241
Jean Delvaref641b582007-06-09 10:11:16 -0400242static struct platform_driver pc87360_driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100243 .driver = {
Jean Delvare87218842006-09-03 22:36:14 +0200244 .owner = THIS_MODULE,
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100245 .name = "pc87360",
246 },
Jean Delvaref641b582007-06-09 10:11:16 -0400247 .probe = pc87360_probe,
248 .remove = __devexit_p(pc87360_remove),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249};
250
251/*
252 * Sysfs stuff
253 */
254
Jim Cromief0986bd2005-09-02 22:52:43 +0200255static ssize_t show_fan_input(struct device *dev, struct device_attribute *devattr, char *buf)
256{
257 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
258 struct pc87360_data *data = pc87360_update_device(dev);
Jim Cromie694fa052005-09-02 22:57:52 +0200259 return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan[attr->index],
260 FAN_DIV_FROM_REG(data->fan_status[attr->index])));
Jim Cromief0986bd2005-09-02 22:52:43 +0200261}
262static ssize_t show_fan_min(struct device *dev, struct device_attribute *devattr, char *buf)
263{
264 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
265 struct pc87360_data *data = pc87360_update_device(dev);
Jim Cromie694fa052005-09-02 22:57:52 +0200266 return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan_min[attr->index],
267 FAN_DIV_FROM_REG(data->fan_status[attr->index])));
Jim Cromief0986bd2005-09-02 22:52:43 +0200268}
269static ssize_t show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf)
270{
271 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
272 struct pc87360_data *data = pc87360_update_device(dev);
273 return sprintf(buf, "%u\n",
Jim Cromie694fa052005-09-02 22:57:52 +0200274 FAN_DIV_FROM_REG(data->fan_status[attr->index]));
Jim Cromief0986bd2005-09-02 22:52:43 +0200275}
276static ssize_t show_fan_status(struct device *dev, struct device_attribute *devattr, char *buf)
277{
278 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
279 struct pc87360_data *data = pc87360_update_device(dev);
280 return sprintf(buf, "%u\n",
Jim Cromie694fa052005-09-02 22:57:52 +0200281 FAN_STATUS_FROM_REG(data->fan_status[attr->index]));
Jim Cromief0986bd2005-09-02 22:52:43 +0200282}
283static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr, const char *buf,
284 size_t count)
285{
286 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Jean Delvaref641b582007-06-09 10:11:16 -0400287 struct pc87360_data *data = dev_get_drvdata(dev);
Jim Cromie11be27e2005-09-02 23:05:07 +0200288 long fan_min = simple_strtol(buf, NULL, 10);
289
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100290 mutex_lock(&data->update_lock);
Jim Cromie11be27e2005-09-02 23:05:07 +0200291 fan_min = FAN_TO_REG(fan_min, FAN_DIV_FROM_REG(data->fan_status[attr->index]));
292
293 /* If it wouldn't fit, change clock divisor */
294 while (fan_min > 255
295 && (data->fan_status[attr->index] & 0x60) != 0x60) {
296 fan_min >>= 1;
297 data->fan[attr->index] >>= 1;
298 data->fan_status[attr->index] += 0x20;
299 }
300 data->fan_min[attr->index] = fan_min > 255 ? 255 : fan_min;
301 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_MIN(attr->index),
302 data->fan_min[attr->index]);
303
304 /* Write new divider, preserve alarm bits */
305 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_STATUS(attr->index),
306 data->fan_status[attr->index] & 0xF9);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100307 mutex_unlock(&data->update_lock);
Jim Cromie11be27e2005-09-02 23:05:07 +0200308
309 return count;
Jim Cromief0986bd2005-09-02 22:52:43 +0200310}
311
Jim Cromiededc6a72006-01-09 23:24:41 +0100312static struct sensor_device_attribute fan_input[] = {
313 SENSOR_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0),
314 SENSOR_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1),
315 SENSOR_ATTR(fan3_input, S_IRUGO, show_fan_input, NULL, 2),
316};
317static struct sensor_device_attribute fan_status[] = {
318 SENSOR_ATTR(fan1_status, S_IRUGO, show_fan_status, NULL, 0),
319 SENSOR_ATTR(fan2_status, S_IRUGO, show_fan_status, NULL, 1),
320 SENSOR_ATTR(fan3_status, S_IRUGO, show_fan_status, NULL, 2),
321};
322static struct sensor_device_attribute fan_div[] = {
323 SENSOR_ATTR(fan1_div, S_IRUGO, show_fan_div, NULL, 0),
324 SENSOR_ATTR(fan2_div, S_IRUGO, show_fan_div, NULL, 1),
325 SENSOR_ATTR(fan3_div, S_IRUGO, show_fan_div, NULL, 2),
326};
327static struct sensor_device_attribute fan_min[] = {
328 SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 0),
329 SENSOR_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 1),
330 SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 2),
331};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Jim Cromie941c5c02006-09-24 21:02:44 +0200333#define FAN_UNIT_ATTRS(X) \
334 &fan_input[X].dev_attr.attr, \
335 &fan_status[X].dev_attr.attr, \
336 &fan_div[X].dev_attr.attr, \
337 &fan_min[X].dev_attr.attr
338
Jim Cromief0986bd2005-09-02 22:52:43 +0200339static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, char *buf)
340{
341 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
342 struct pc87360_data *data = pc87360_update_device(dev);
343 return sprintf(buf, "%u\n",
Jim Cromie694fa052005-09-02 22:57:52 +0200344 PWM_FROM_REG(data->pwm[attr->index],
Jim Cromief0986bd2005-09-02 22:52:43 +0200345 FAN_CONFIG_INVERT(data->fan_conf,
Jim Cromie694fa052005-09-02 22:57:52 +0200346 attr->index)));
Jim Cromief0986bd2005-09-02 22:52:43 +0200347}
348static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, const char *buf,
349 size_t count)
350{
351 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Jean Delvaref641b582007-06-09 10:11:16 -0400352 struct pc87360_data *data = dev_get_drvdata(dev);
Jim Cromief0986bd2005-09-02 22:52:43 +0200353 long val = simple_strtol(buf, NULL, 10);
354
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100355 mutex_lock(&data->update_lock);
Jim Cromie694fa052005-09-02 22:57:52 +0200356 data->pwm[attr->index] = PWM_TO_REG(val,
357 FAN_CONFIG_INVERT(data->fan_conf, attr->index));
358 pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_PWM(attr->index),
359 data->pwm[attr->index]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100360 mutex_unlock(&data->update_lock);
Jim Cromief0986bd2005-09-02 22:52:43 +0200361 return count;
362}
363
Jim Cromiededc6a72006-01-09 23:24:41 +0100364static struct sensor_device_attribute pwm[] = {
365 SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 0),
366 SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 1),
367 SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2),
368};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Jim Cromie941c5c02006-09-24 21:02:44 +0200370static struct attribute * pc8736x_fan_attr_array[] = {
371 FAN_UNIT_ATTRS(0),
372 FAN_UNIT_ATTRS(1),
373 FAN_UNIT_ATTRS(2),
374 &pwm[0].dev_attr.attr,
375 &pwm[1].dev_attr.attr,
376 &pwm[2].dev_attr.attr,
377 NULL
378};
379static const struct attribute_group pc8736x_fan_group = {
380 .attrs = pc8736x_fan_attr_array,
381};
382
Jim Cromief0986bd2005-09-02 22:52:43 +0200383static ssize_t show_in_input(struct device *dev, struct device_attribute *devattr, char *buf)
384{
385 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
386 struct pc87360_data *data = pc87360_update_device(dev);
387 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index],
388 data->in_vref));
389}
390static ssize_t show_in_min(struct device *dev, struct device_attribute *devattr, char *buf)
391{
392 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
393 struct pc87360_data *data = pc87360_update_device(dev);
394 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index],
395 data->in_vref));
396}
397static ssize_t show_in_max(struct device *dev, struct device_attribute *devattr, char *buf)
398{
399 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
400 struct pc87360_data *data = pc87360_update_device(dev);
401 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index],
402 data->in_vref));
403}
404static ssize_t show_in_status(struct device *dev, struct device_attribute *devattr, char *buf)
405{
406 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
407 struct pc87360_data *data = pc87360_update_device(dev);
408 return sprintf(buf, "%u\n", data->in_status[attr->index]);
409}
410static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr, const char *buf,
411 size_t count)
412{
413 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Jean Delvaref641b582007-06-09 10:11:16 -0400414 struct pc87360_data *data = dev_get_drvdata(dev);
Jim Cromief0986bd2005-09-02 22:52:43 +0200415 long val = simple_strtol(buf, NULL, 10);
416
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100417 mutex_lock(&data->update_lock);
Jim Cromief0986bd2005-09-02 22:52:43 +0200418 data->in_min[attr->index] = IN_TO_REG(val, data->in_vref);
419 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MIN,
420 data->in_min[attr->index]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100421 mutex_unlock(&data->update_lock);
Jim Cromief0986bd2005-09-02 22:52:43 +0200422 return count;
423}
424static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr, const char *buf,
425 size_t count)
426{
427 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Jean Delvaref641b582007-06-09 10:11:16 -0400428 struct pc87360_data *data = dev_get_drvdata(dev);
Jim Cromief0986bd2005-09-02 22:52:43 +0200429 long val = simple_strtol(buf, NULL, 10);
430
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100431 mutex_lock(&data->update_lock);
Jim Cromief0986bd2005-09-02 22:52:43 +0200432 data->in_max[attr->index] = IN_TO_REG(val,
433 data->in_vref);
434 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MAX,
435 data->in_max[attr->index]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100436 mutex_unlock(&data->update_lock);
Jim Cromief0986bd2005-09-02 22:52:43 +0200437 return count;
438}
439
Jim Cromiededc6a72006-01-09 23:24:41 +0100440static struct sensor_device_attribute in_input[] = {
441 SENSOR_ATTR(in0_input, S_IRUGO, show_in_input, NULL, 0),
442 SENSOR_ATTR(in1_input, S_IRUGO, show_in_input, NULL, 1),
443 SENSOR_ATTR(in2_input, S_IRUGO, show_in_input, NULL, 2),
444 SENSOR_ATTR(in3_input, S_IRUGO, show_in_input, NULL, 3),
445 SENSOR_ATTR(in4_input, S_IRUGO, show_in_input, NULL, 4),
446 SENSOR_ATTR(in5_input, S_IRUGO, show_in_input, NULL, 5),
447 SENSOR_ATTR(in6_input, S_IRUGO, show_in_input, NULL, 6),
448 SENSOR_ATTR(in7_input, S_IRUGO, show_in_input, NULL, 7),
449 SENSOR_ATTR(in8_input, S_IRUGO, show_in_input, NULL, 8),
450 SENSOR_ATTR(in9_input, S_IRUGO, show_in_input, NULL, 9),
451 SENSOR_ATTR(in10_input, S_IRUGO, show_in_input, NULL, 10),
452};
453static struct sensor_device_attribute in_status[] = {
454 SENSOR_ATTR(in0_status, S_IRUGO, show_in_status, NULL, 0),
455 SENSOR_ATTR(in1_status, S_IRUGO, show_in_status, NULL, 1),
456 SENSOR_ATTR(in2_status, S_IRUGO, show_in_status, NULL, 2),
457 SENSOR_ATTR(in3_status, S_IRUGO, show_in_status, NULL, 3),
458 SENSOR_ATTR(in4_status, S_IRUGO, show_in_status, NULL, 4),
459 SENSOR_ATTR(in5_status, S_IRUGO, show_in_status, NULL, 5),
460 SENSOR_ATTR(in6_status, S_IRUGO, show_in_status, NULL, 6),
461 SENSOR_ATTR(in7_status, S_IRUGO, show_in_status, NULL, 7),
462 SENSOR_ATTR(in8_status, S_IRUGO, show_in_status, NULL, 8),
463 SENSOR_ATTR(in9_status, S_IRUGO, show_in_status, NULL, 9),
464 SENSOR_ATTR(in10_status, S_IRUGO, show_in_status, NULL, 10),
465};
466static struct sensor_device_attribute in_min[] = {
467 SENSOR_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 0),
468 SENSOR_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 1),
469 SENSOR_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 2),
470 SENSOR_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 3),
471 SENSOR_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 4),
472 SENSOR_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 5),
473 SENSOR_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 6),
474 SENSOR_ATTR(in7_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 7),
475 SENSOR_ATTR(in8_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 8),
476 SENSOR_ATTR(in9_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 9),
477 SENSOR_ATTR(in10_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 10),
478};
479static struct sensor_device_attribute in_max[] = {
480 SENSOR_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 0),
481 SENSOR_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 1),
482 SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 2),
483 SENSOR_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 3),
484 SENSOR_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 4),
485 SENSOR_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 5),
486 SENSOR_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 6),
487 SENSOR_ATTR(in7_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 7),
488 SENSOR_ATTR(in8_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 8),
489 SENSOR_ATTR(in9_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 9),
490 SENSOR_ATTR(in10_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 10),
491};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Jim Cromie28f74e72008-10-18 20:27:30 -0700493/* (temp & vin) channel status register alarm bits (pdf sec.11.5.12) */
494#define CHAN_ALM_MIN 0x02 /* min limit crossed */
495#define CHAN_ALM_MAX 0x04 /* max limit exceeded */
496#define TEMP_ALM_CRIT 0x08 /* temp crit exceeded (temp only) */
497
Jim Cromie492e9652008-10-18 20:27:32 -0700498/* show_in_min/max_alarm() reads data from the per-channel status
499 register (sec 11.5.12), not the vin event status registers (sec
500 11.5.2) that (legacy) show_in_alarm() resds (via data->in_alarms) */
501
502static ssize_t show_in_min_alarm(struct device *dev,
503 struct device_attribute *devattr, char *buf)
504{
505 struct pc87360_data *data = pc87360_update_device(dev);
506 unsigned nr = to_sensor_dev_attr(devattr)->index;
507
508 return sprintf(buf, "%u\n", !!(data->in_status[nr] & CHAN_ALM_MIN));
509}
510static ssize_t show_in_max_alarm(struct device *dev,
511 struct device_attribute *devattr, char *buf)
512{
513 struct pc87360_data *data = pc87360_update_device(dev);
514 unsigned nr = to_sensor_dev_attr(devattr)->index;
515
516 return sprintf(buf, "%u\n", !!(data->in_status[nr] & CHAN_ALM_MAX));
517}
518
519static struct sensor_device_attribute in_min_alarm[] = {
520 SENSOR_ATTR(in0_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 0),
521 SENSOR_ATTR(in1_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 1),
522 SENSOR_ATTR(in2_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 2),
523 SENSOR_ATTR(in3_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 3),
524 SENSOR_ATTR(in4_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 4),
525 SENSOR_ATTR(in5_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 5),
526 SENSOR_ATTR(in6_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 6),
527 SENSOR_ATTR(in7_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 7),
528 SENSOR_ATTR(in8_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 8),
529 SENSOR_ATTR(in9_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 9),
530 SENSOR_ATTR(in10_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 10),
531};
532static struct sensor_device_attribute in_max_alarm[] = {
533 SENSOR_ATTR(in0_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 0),
534 SENSOR_ATTR(in1_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 1),
535 SENSOR_ATTR(in2_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 2),
536 SENSOR_ATTR(in3_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 3),
537 SENSOR_ATTR(in4_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 4),
538 SENSOR_ATTR(in5_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 5),
539 SENSOR_ATTR(in6_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 6),
540 SENSOR_ATTR(in7_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 7),
541 SENSOR_ATTR(in8_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 8),
542 SENSOR_ATTR(in9_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 9),
543 SENSOR_ATTR(in10_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 10),
544};
545
Jim Cromie941c5c02006-09-24 21:02:44 +0200546#define VIN_UNIT_ATTRS(X) \
547 &in_input[X].dev_attr.attr, \
548 &in_status[X].dev_attr.attr, \
549 &in_min[X].dev_attr.attr, \
Jim Cromie492e9652008-10-18 20:27:32 -0700550 &in_max[X].dev_attr.attr, \
551 &in_min_alarm[X].dev_attr.attr, \
552 &in_max_alarm[X].dev_attr.attr
Jim Cromie941c5c02006-09-24 21:02:44 +0200553
Jim Cromie44646c12006-09-24 21:01:56 +0200554static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf)
555{
556 struct pc87360_data *data = pc87360_update_device(dev);
557 return sprintf(buf, "%u\n", vid_from_reg(data->vid, data->vrm));
558}
559static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
560
561static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
562{
Jean Delvare90d66192007-10-08 18:24:35 +0200563 struct pc87360_data *data = dev_get_drvdata(dev);
Jim Cromie44646c12006-09-24 21:01:56 +0200564 return sprintf(buf, "%u\n", data->vrm);
565}
566static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
567{
Jean Delvaref641b582007-06-09 10:11:16 -0400568 struct pc87360_data *data = dev_get_drvdata(dev);
Jim Cromie44646c12006-09-24 21:01:56 +0200569 data->vrm = simple_strtoul(buf, NULL, 10);
570 return count;
571}
572static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm, set_vrm);
573
574static ssize_t show_in_alarms(struct device *dev, struct device_attribute *attr, char *buf)
575{
576 struct pc87360_data *data = pc87360_update_device(dev);
577 return sprintf(buf, "%u\n", data->in_alarms);
578}
579static DEVICE_ATTR(alarms_in, S_IRUGO, show_in_alarms, NULL);
580
Jim Cromie941c5c02006-09-24 21:02:44 +0200581static struct attribute *pc8736x_vin_attr_array[] = {
582 VIN_UNIT_ATTRS(0),
583 VIN_UNIT_ATTRS(1),
584 VIN_UNIT_ATTRS(2),
585 VIN_UNIT_ATTRS(3),
586 VIN_UNIT_ATTRS(4),
587 VIN_UNIT_ATTRS(5),
588 VIN_UNIT_ATTRS(6),
589 VIN_UNIT_ATTRS(7),
590 VIN_UNIT_ATTRS(8),
591 VIN_UNIT_ATTRS(9),
592 VIN_UNIT_ATTRS(10),
593 &dev_attr_cpu0_vid.attr,
594 &dev_attr_vrm.attr,
595 &dev_attr_alarms_in.attr,
596 NULL
597};
598static const struct attribute_group pc8736x_vin_group = {
599 .attrs = pc8736x_vin_attr_array,
600};
601
Jim Cromief0986bd2005-09-02 22:52:43 +0200602static ssize_t show_therm_input(struct device *dev, struct device_attribute *devattr, char *buf)
603{
604 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
605 struct pc87360_data *data = pc87360_update_device(dev);
Jim Cromie694fa052005-09-02 22:57:52 +0200606 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index],
Jim Cromief0986bd2005-09-02 22:52:43 +0200607 data->in_vref));
608}
609static ssize_t show_therm_min(struct device *dev, struct device_attribute *devattr, char *buf)
610{
611 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
612 struct pc87360_data *data = pc87360_update_device(dev);
Jim Cromie694fa052005-09-02 22:57:52 +0200613 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index],
Jim Cromief0986bd2005-09-02 22:52:43 +0200614 data->in_vref));
615}
616static ssize_t show_therm_max(struct device *dev, struct device_attribute *devattr, char *buf)
617{
618 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
619 struct pc87360_data *data = pc87360_update_device(dev);
Jim Cromie694fa052005-09-02 22:57:52 +0200620 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index],
Jim Cromief0986bd2005-09-02 22:52:43 +0200621 data->in_vref));
622}
623static ssize_t show_therm_crit(struct device *dev, struct device_attribute *devattr, char *buf)
624{
625 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
626 struct pc87360_data *data = pc87360_update_device(dev);
Jim Cromie694fa052005-09-02 22:57:52 +0200627 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[attr->index-11],
Jim Cromief0986bd2005-09-02 22:52:43 +0200628 data->in_vref));
629}
630static ssize_t show_therm_status(struct device *dev, struct device_attribute *devattr, char *buf)
631{
632 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
633 struct pc87360_data *data = pc87360_update_device(dev);
Jim Cromie694fa052005-09-02 22:57:52 +0200634 return sprintf(buf, "%u\n", data->in_status[attr->index]);
Jim Cromief0986bd2005-09-02 22:52:43 +0200635}
636static ssize_t set_therm_min(struct device *dev, struct device_attribute *devattr, const char *buf,
637 size_t count)
638{
639 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Jean Delvaref641b582007-06-09 10:11:16 -0400640 struct pc87360_data *data = dev_get_drvdata(dev);
Jim Cromief0986bd2005-09-02 22:52:43 +0200641 long val = simple_strtol(buf, NULL, 10);
642
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100643 mutex_lock(&data->update_lock);
Jim Cromie694fa052005-09-02 22:57:52 +0200644 data->in_min[attr->index] = IN_TO_REG(val, data->in_vref);
645 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MIN,
646 data->in_min[attr->index]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100647 mutex_unlock(&data->update_lock);
Jim Cromief0986bd2005-09-02 22:52:43 +0200648 return count;
649}
650static ssize_t set_therm_max(struct device *dev, struct device_attribute *devattr, const char *buf,
651 size_t count)
652{
653 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Jean Delvaref641b582007-06-09 10:11:16 -0400654 struct pc87360_data *data = dev_get_drvdata(dev);
Jim Cromief0986bd2005-09-02 22:52:43 +0200655 long val = simple_strtol(buf, NULL, 10);
656
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100657 mutex_lock(&data->update_lock);
Jim Cromie694fa052005-09-02 22:57:52 +0200658 data->in_max[attr->index] = IN_TO_REG(val, data->in_vref);
659 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MAX,
660 data->in_max[attr->index]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100661 mutex_unlock(&data->update_lock);
Jim Cromief0986bd2005-09-02 22:52:43 +0200662 return count;
663}
664static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devattr, const char *buf,
665 size_t count)
666{
667 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Jean Delvaref641b582007-06-09 10:11:16 -0400668 struct pc87360_data *data = dev_get_drvdata(dev);
Jim Cromief0986bd2005-09-02 22:52:43 +0200669 long val = simple_strtol(buf, NULL, 10);
670
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100671 mutex_lock(&data->update_lock);
Jim Cromie694fa052005-09-02 22:57:52 +0200672 data->in_crit[attr->index-11] = IN_TO_REG(val, data->in_vref);
673 pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_CRIT,
674 data->in_crit[attr->index-11]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100675 mutex_unlock(&data->update_lock);
Jim Cromief0986bd2005-09-02 22:52:43 +0200676 return count;
677}
678
Jim Cromiededc6a72006-01-09 23:24:41 +0100679/* the +11 term below reflects the fact that VLM units 11,12,13 are
680 used in the chip to measure voltage across the thermistors
681*/
682static struct sensor_device_attribute therm_input[] = {
683 SENSOR_ATTR(temp4_input, S_IRUGO, show_therm_input, NULL, 0+11),
684 SENSOR_ATTR(temp5_input, S_IRUGO, show_therm_input, NULL, 1+11),
685 SENSOR_ATTR(temp6_input, S_IRUGO, show_therm_input, NULL, 2+11),
686};
687static struct sensor_device_attribute therm_status[] = {
688 SENSOR_ATTR(temp4_status, S_IRUGO, show_therm_status, NULL, 0+11),
689 SENSOR_ATTR(temp5_status, S_IRUGO, show_therm_status, NULL, 1+11),
690 SENSOR_ATTR(temp6_status, S_IRUGO, show_therm_status, NULL, 2+11),
691};
692static struct sensor_device_attribute therm_min[] = {
693 SENSOR_ATTR(temp4_min, S_IRUGO | S_IWUSR,
694 show_therm_min, set_therm_min, 0+11),
695 SENSOR_ATTR(temp5_min, S_IRUGO | S_IWUSR,
696 show_therm_min, set_therm_min, 1+11),
697 SENSOR_ATTR(temp6_min, S_IRUGO | S_IWUSR,
698 show_therm_min, set_therm_min, 2+11),
699};
700static struct sensor_device_attribute therm_max[] = {
701 SENSOR_ATTR(temp4_max, S_IRUGO | S_IWUSR,
702 show_therm_max, set_therm_max, 0+11),
703 SENSOR_ATTR(temp5_max, S_IRUGO | S_IWUSR,
704 show_therm_max, set_therm_max, 1+11),
705 SENSOR_ATTR(temp6_max, S_IRUGO | S_IWUSR,
706 show_therm_max, set_therm_max, 2+11),
707};
708static struct sensor_device_attribute therm_crit[] = {
709 SENSOR_ATTR(temp4_crit, S_IRUGO | S_IWUSR,
710 show_therm_crit, set_therm_crit, 0+11),
711 SENSOR_ATTR(temp5_crit, S_IRUGO | S_IWUSR,
712 show_therm_crit, set_therm_crit, 1+11),
713 SENSOR_ATTR(temp6_crit, S_IRUGO | S_IWUSR,
714 show_therm_crit, set_therm_crit, 2+11),
715};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
Jim Cromie865c2952008-10-18 20:27:35 -0700717/* show_therm_min/max_alarm() reads data from the per-channel voltage
718 status register (sec 11.5.12) */
719
720static ssize_t show_therm_min_alarm(struct device *dev,
721 struct device_attribute *devattr, char *buf)
722{
723 struct pc87360_data *data = pc87360_update_device(dev);
724 unsigned nr = to_sensor_dev_attr(devattr)->index;
725
726 return sprintf(buf, "%u\n", !!(data->in_status[nr] & CHAN_ALM_MIN));
727}
728static ssize_t show_therm_max_alarm(struct device *dev,
729 struct device_attribute *devattr, char *buf)
730{
731 struct pc87360_data *data = pc87360_update_device(dev);
732 unsigned nr = to_sensor_dev_attr(devattr)->index;
733
734 return sprintf(buf, "%u\n", !!(data->in_status[nr] & CHAN_ALM_MAX));
735}
736static ssize_t show_therm_crit_alarm(struct device *dev,
737 struct device_attribute *devattr, char *buf)
738{
739 struct pc87360_data *data = pc87360_update_device(dev);
740 unsigned nr = to_sensor_dev_attr(devattr)->index;
741
742 return sprintf(buf, "%u\n", !!(data->in_status[nr] & TEMP_ALM_CRIT));
743}
744
745static struct sensor_device_attribute therm_min_alarm[] = {
746 SENSOR_ATTR(temp4_min_alarm, S_IRUGO,
747 show_therm_min_alarm, NULL, 0+11),
748 SENSOR_ATTR(temp5_min_alarm, S_IRUGO,
749 show_therm_min_alarm, NULL, 1+11),
750 SENSOR_ATTR(temp6_min_alarm, S_IRUGO,
751 show_therm_min_alarm, NULL, 2+11),
752};
753static struct sensor_device_attribute therm_max_alarm[] = {
754 SENSOR_ATTR(temp4_max_alarm, S_IRUGO,
755 show_therm_max_alarm, NULL, 0+11),
756 SENSOR_ATTR(temp5_max_alarm, S_IRUGO,
757 show_therm_max_alarm, NULL, 1+11),
758 SENSOR_ATTR(temp6_max_alarm, S_IRUGO,
759 show_therm_max_alarm, NULL, 2+11),
760};
761static struct sensor_device_attribute therm_crit_alarm[] = {
762 SENSOR_ATTR(temp4_crit_alarm, S_IRUGO,
763 show_therm_crit_alarm, NULL, 0+11),
764 SENSOR_ATTR(temp5_crit_alarm, S_IRUGO,
765 show_therm_crit_alarm, NULL, 1+11),
766 SENSOR_ATTR(temp6_crit_alarm, S_IRUGO,
767 show_therm_crit_alarm, NULL, 2+11),
768};
769
Jim Cromie941c5c02006-09-24 21:02:44 +0200770#define THERM_UNIT_ATTRS(X) \
771 &therm_input[X].dev_attr.attr, \
772 &therm_status[X].dev_attr.attr, \
773 &therm_min[X].dev_attr.attr, \
774 &therm_max[X].dev_attr.attr, \
Jim Cromie865c2952008-10-18 20:27:35 -0700775 &therm_crit[X].dev_attr.attr, \
776 &therm_min_alarm[X].dev_attr.attr, \
777 &therm_max_alarm[X].dev_attr.attr, \
778 &therm_crit_alarm[X].dev_attr.attr
Jim Cromie941c5c02006-09-24 21:02:44 +0200779
780static struct attribute * pc8736x_therm_attr_array[] = {
781 THERM_UNIT_ATTRS(0),
782 THERM_UNIT_ATTRS(1),
783 THERM_UNIT_ATTRS(2),
784 NULL
785};
786static const struct attribute_group pc8736x_therm_group = {
787 .attrs = pc8736x_therm_attr_array,
788};
789
Jim Cromief0986bd2005-09-02 22:52:43 +0200790static ssize_t show_temp_input(struct device *dev, struct device_attribute *devattr, char *buf)
791{
792 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
793 struct pc87360_data *data = pc87360_update_device(dev);
Jim Cromie694fa052005-09-02 22:57:52 +0200794 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index]));
Jim Cromief0986bd2005-09-02 22:52:43 +0200795}
796static ssize_t show_temp_min(struct device *dev, struct device_attribute *devattr, char *buf)
797{
798 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
799 struct pc87360_data *data = pc87360_update_device(dev);
Jim Cromie694fa052005-09-02 22:57:52 +0200800 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[attr->index]));
Jim Cromief0986bd2005-09-02 22:52:43 +0200801}
802static ssize_t show_temp_max(struct device *dev, struct device_attribute *devattr, char *buf)
803{
804 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
805 struct pc87360_data *data = pc87360_update_device(dev);
Jim Cromie694fa052005-09-02 22:57:52 +0200806 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[attr->index]));
Jim Cromief0986bd2005-09-02 22:52:43 +0200807}
808static ssize_t show_temp_crit(struct device *dev, struct device_attribute *devattr, char *buf)
809{
810 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
811 struct pc87360_data *data = pc87360_update_device(dev);
Jim Cromie694fa052005-09-02 22:57:52 +0200812 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[attr->index]));
Jim Cromief0986bd2005-09-02 22:52:43 +0200813}
814static ssize_t show_temp_status(struct device *dev, struct device_attribute *devattr, char *buf)
815{
816 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
817 struct pc87360_data *data = pc87360_update_device(dev);
Jim Cromie694fa052005-09-02 22:57:52 +0200818 return sprintf(buf, "%d\n", data->temp_status[attr->index]);
Jim Cromief0986bd2005-09-02 22:52:43 +0200819}
820static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr, const char *buf,
821 size_t count)
822{
823 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Jean Delvaref641b582007-06-09 10:11:16 -0400824 struct pc87360_data *data = dev_get_drvdata(dev);
Jim Cromief0986bd2005-09-02 22:52:43 +0200825 long val = simple_strtol(buf, NULL, 10);
826
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100827 mutex_lock(&data->update_lock);
Jim Cromie694fa052005-09-02 22:57:52 +0200828 data->temp_min[attr->index] = TEMP_TO_REG(val);
829 pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MIN,
830 data->temp_min[attr->index]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100831 mutex_unlock(&data->update_lock);
Jim Cromief0986bd2005-09-02 22:52:43 +0200832 return count;
833}
834static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr, const char *buf,
835 size_t count)
836{
837 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Jean Delvaref641b582007-06-09 10:11:16 -0400838 struct pc87360_data *data = dev_get_drvdata(dev);
Jim Cromief0986bd2005-09-02 22:52:43 +0200839 long val = simple_strtol(buf, NULL, 10);
840
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100841 mutex_lock(&data->update_lock);
Jim Cromie694fa052005-09-02 22:57:52 +0200842 data->temp_max[attr->index] = TEMP_TO_REG(val);
843 pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MAX,
844 data->temp_max[attr->index]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100845 mutex_unlock(&data->update_lock);
Jim Cromief0986bd2005-09-02 22:52:43 +0200846 return count;
847}
848static ssize_t set_temp_crit(struct device *dev, struct device_attribute *devattr, const char *buf,
849 size_t count)
850{
851 struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
Jean Delvaref641b582007-06-09 10:11:16 -0400852 struct pc87360_data *data = dev_get_drvdata(dev);
Jim Cromief0986bd2005-09-02 22:52:43 +0200853 long val = simple_strtol(buf, NULL, 10);
854
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100855 mutex_lock(&data->update_lock);
Jim Cromie694fa052005-09-02 22:57:52 +0200856 data->temp_crit[attr->index] = TEMP_TO_REG(val);
857 pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_CRIT,
858 data->temp_crit[attr->index]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100859 mutex_unlock(&data->update_lock);
Jim Cromief0986bd2005-09-02 22:52:43 +0200860 return count;
861}
862
Jim Cromiededc6a72006-01-09 23:24:41 +0100863static struct sensor_device_attribute temp_input[] = {
864 SENSOR_ATTR(temp1_input, S_IRUGO, show_temp_input, NULL, 0),
865 SENSOR_ATTR(temp2_input, S_IRUGO, show_temp_input, NULL, 1),
866 SENSOR_ATTR(temp3_input, S_IRUGO, show_temp_input, NULL, 2),
867};
868static struct sensor_device_attribute temp_status[] = {
869 SENSOR_ATTR(temp1_status, S_IRUGO, show_temp_status, NULL, 0),
870 SENSOR_ATTR(temp2_status, S_IRUGO, show_temp_status, NULL, 1),
871 SENSOR_ATTR(temp3_status, S_IRUGO, show_temp_status, NULL, 2),
872};
873static struct sensor_device_attribute temp_min[] = {
874 SENSOR_ATTR(temp1_min, S_IRUGO | S_IWUSR,
875 show_temp_min, set_temp_min, 0),
876 SENSOR_ATTR(temp2_min, S_IRUGO | S_IWUSR,
877 show_temp_min, set_temp_min, 1),
878 SENSOR_ATTR(temp3_min, S_IRUGO | S_IWUSR,
879 show_temp_min, set_temp_min, 2),
880};
881static struct sensor_device_attribute temp_max[] = {
882 SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR,
883 show_temp_max, set_temp_max, 0),
884 SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR,
885 show_temp_max, set_temp_max, 1),
886 SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR,
887 show_temp_max, set_temp_max, 2),
888};
889static struct sensor_device_attribute temp_crit[] = {
890 SENSOR_ATTR(temp1_crit, S_IRUGO | S_IWUSR,
891 show_temp_crit, set_temp_crit, 0),
892 SENSOR_ATTR(temp2_crit, S_IRUGO | S_IWUSR,
893 show_temp_crit, set_temp_crit, 1),
894 SENSOR_ATTR(temp3_crit, S_IRUGO | S_IWUSR,
895 show_temp_crit, set_temp_crit, 2),
896};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
Yani Ioannoua5099cf2005-05-17 06:42:25 -0400898static ssize_t show_temp_alarms(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899{
900 struct pc87360_data *data = pc87360_update_device(dev);
901 return sprintf(buf, "%u\n", data->temp_alarms);
902}
903static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL);
904
Jim Cromieb267e8c2008-10-18 20:27:32 -0700905/* show_temp_min/max_alarm() reads data from the per-channel status
906 register (sec 12.3.7), not the temp event status registers (sec
907 12.3.2) that show_temp_alarm() reads (via data->temp_alarms) */
908
909static ssize_t show_temp_min_alarm(struct device *dev,
910 struct device_attribute *devattr, char *buf)
911{
912 struct pc87360_data *data = pc87360_update_device(dev);
913 unsigned nr = to_sensor_dev_attr(devattr)->index;
914
915 return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MIN));
916}
917static ssize_t show_temp_max_alarm(struct device *dev,
918 struct device_attribute *devattr, char *buf)
919{
920 struct pc87360_data *data = pc87360_update_device(dev);
921 unsigned nr = to_sensor_dev_attr(devattr)->index;
922
923 return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MAX));
924}
925static ssize_t show_temp_crit_alarm(struct device *dev,
926 struct device_attribute *devattr, char *buf)
927{
928 struct pc87360_data *data = pc87360_update_device(dev);
929 unsigned nr = to_sensor_dev_attr(devattr)->index;
930
931 return sprintf(buf, "%u\n", !!(data->temp_status[nr] & TEMP_ALM_CRIT));
932}
933
934static struct sensor_device_attribute temp_min_alarm[] = {
935 SENSOR_ATTR(temp1_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 0),
936 SENSOR_ATTR(temp2_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 1),
937 SENSOR_ATTR(temp3_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 2),
938};
939static struct sensor_device_attribute temp_max_alarm[] = {
940 SENSOR_ATTR(temp1_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 0),
941 SENSOR_ATTR(temp2_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 1),
942 SENSOR_ATTR(temp3_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 2),
943};
944static struct sensor_device_attribute temp_crit_alarm[] = {
945 SENSOR_ATTR(temp1_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 0),
946 SENSOR_ATTR(temp2_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 1),
947 SENSOR_ATTR(temp3_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 2),
948};
949
950#define TEMP_FAULT 0x40 /* open diode */
951static ssize_t show_temp_fault(struct device *dev,
952 struct device_attribute *devattr, char *buf)
953{
954 struct pc87360_data *data = pc87360_update_device(dev);
955 unsigned nr = to_sensor_dev_attr(devattr)->index;
956
957 return sprintf(buf, "%u\n", !!(data->temp_status[nr] & TEMP_FAULT));
958}
959static struct sensor_device_attribute temp_fault[] = {
960 SENSOR_ATTR(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0),
961 SENSOR_ATTR(temp2_fault, S_IRUGO, show_temp_fault, NULL, 1),
962 SENSOR_ATTR(temp3_fault, S_IRUGO, show_temp_fault, NULL, 2),
963};
964
Jim Cromie941c5c02006-09-24 21:02:44 +0200965#define TEMP_UNIT_ATTRS(X) \
966 &temp_input[X].dev_attr.attr, \
967 &temp_status[X].dev_attr.attr, \
968 &temp_min[X].dev_attr.attr, \
969 &temp_max[X].dev_attr.attr, \
Jim Cromieb267e8c2008-10-18 20:27:32 -0700970 &temp_crit[X].dev_attr.attr, \
971 &temp_min_alarm[X].dev_attr.attr, \
972 &temp_max_alarm[X].dev_attr.attr, \
973 &temp_crit_alarm[X].dev_attr.attr, \
974 &temp_fault[X].dev_attr.attr
Jim Cromie941c5c02006-09-24 21:02:44 +0200975
976static struct attribute * pc8736x_temp_attr_array[] = {
977 TEMP_UNIT_ATTRS(0),
978 TEMP_UNIT_ATTRS(1),
979 TEMP_UNIT_ATTRS(2),
980 /* include the few miscellaneous atts here */
981 &dev_attr_alarms_temp.attr,
982 NULL
983};
984static const struct attribute_group pc8736x_temp_group = {
985 .attrs = pc8736x_temp_attr_array,
986};
987
Jim Cromieb267e8c2008-10-18 20:27:32 -0700988static ssize_t show_name(struct device *dev,
989 struct device_attribute *devattr, char *buf)
Jean Delvaref641b582007-06-09 10:11:16 -0400990{
991 struct pc87360_data *data = dev_get_drvdata(dev);
992 return sprintf(buf, "%s\n", data->name);
993}
994static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
995
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996/*
997 * Device detection, registration and update
998 */
999
Jean Delvaree6cfb3a2005-07-27 21:32:02 +02001000static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001{
1002 u16 val;
1003 int i;
1004 int nrdev; /* logical device count */
1005
1006 /* No superio_enter */
1007
1008 /* Identify device */
Jean Delvare67b671b2007-12-06 23:13:42 +01001009 val = force_id ? force_id : superio_inb(sioaddr, DEVID);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 switch (val) {
1011 case 0xE1: /* PC87360 */
1012 case 0xE8: /* PC87363 */
1013 case 0xE4: /* PC87364 */
1014 nrdev = 1;
1015 break;
1016 case 0xE5: /* PC87365 */
1017 case 0xE9: /* PC87366 */
1018 nrdev = 3;
1019 break;
1020 default:
1021 superio_exit(sioaddr);
1022 return -ENODEV;
1023 }
1024 /* Remember the device id */
1025 *devid = val;
1026
1027 for (i = 0; i < nrdev; i++) {
1028 /* select logical device */
1029 superio_outb(sioaddr, DEV, logdev[i]);
1030
1031 val = superio_inb(sioaddr, ACT);
1032 if (!(val & 0x01)) {
1033 printk(KERN_INFO "pc87360: Device 0x%02x not "
1034 "activated\n", logdev[i]);
1035 continue;
1036 }
1037
1038 val = (superio_inb(sioaddr, BASE) << 8)
1039 | superio_inb(sioaddr, BASE + 1);
1040 if (!val) {
1041 printk(KERN_INFO "pc87360: Base address not set for "
1042 "device 0x%02x\n", logdev[i]);
1043 continue;
1044 }
1045
Jean Delvare2d8672c2005-07-19 23:56:35 +02001046 addresses[i] = val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047
1048 if (i==0) { /* Fans */
1049 confreg[0] = superio_inb(sioaddr, 0xF0);
1050 confreg[1] = superio_inb(sioaddr, 0xF1);
1051
1052#ifdef DEBUG
1053 printk(KERN_DEBUG "pc87360: Fan 1: mon=%d "
1054 "ctrl=%d inv=%d\n", (confreg[0]>>2)&1,
1055 (confreg[0]>>3)&1, (confreg[0]>>4)&1);
1056 printk(KERN_DEBUG "pc87360: Fan 2: mon=%d "
1057 "ctrl=%d inv=%d\n", (confreg[0]>>5)&1,
1058 (confreg[0]>>6)&1, (confreg[0]>>7)&1);
1059 printk(KERN_DEBUG "pc87360: Fan 3: mon=%d "
1060 "ctrl=%d inv=%d\n", confreg[1]&1,
1061 (confreg[1]>>1)&1, (confreg[1]>>2)&1);
1062#endif
1063 } else if (i==1) { /* Voltages */
1064 /* Are we using thermistors? */
1065 if (*devid == 0xE9) { /* PC87366 */
1066 /* These registers are not logical-device
1067 specific, just that we won't need them if
1068 we don't use the VLM device */
1069 confreg[2] = superio_inb(sioaddr, 0x2B);
1070 confreg[3] = superio_inb(sioaddr, 0x25);
1071
1072 if (confreg[2] & 0x40) {
1073 printk(KERN_INFO "pc87360: Using "
1074 "thermistors for temperature "
1075 "monitoring\n");
1076 }
1077 if (confreg[3] & 0xE0) {
1078 printk(KERN_INFO "pc87360: VID "
1079 "inputs routed (mode %u)\n",
1080 confreg[3] >> 5);
1081 }
1082 }
1083 }
1084 }
1085
1086 superio_exit(sioaddr);
1087 return 0;
1088}
1089
Jean Delvaref641b582007-06-09 10:11:16 -04001090static int __devinit pc87360_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091{
1092 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093 struct pc87360_data *data;
1094 int err = 0;
1095 const char *name = "pc87360";
1096 int use_thermistors = 0;
Jean Delvaref641b582007-06-09 10:11:16 -04001097 struct device *dev = &pdev->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098
Deepak Saxenaba9c2e82005-10-17 23:08:32 +02001099 if (!(data = kzalloc(sizeof(struct pc87360_data), GFP_KERNEL)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 data->fannr = 2;
1103 data->innr = 0;
1104 data->tempnr = 0;
1105
1106 switch (devid) {
1107 case 0xe8:
1108 name = "pc87363";
1109 break;
1110 case 0xe4:
1111 name = "pc87364";
1112 data->fannr = 3;
1113 break;
1114 case 0xe5:
1115 name = "pc87365";
1116 data->fannr = extra_isa[0] ? 3 : 0;
1117 data->innr = extra_isa[1] ? 11 : 0;
1118 data->tempnr = extra_isa[2] ? 2 : 0;
1119 break;
1120 case 0xe9:
1121 name = "pc87366";
1122 data->fannr = extra_isa[0] ? 3 : 0;
1123 data->innr = extra_isa[1] ? 14 : 0;
1124 data->tempnr = extra_isa[2] ? 3 : 0;
1125 break;
1126 }
1127
Jean Delvaref641b582007-06-09 10:11:16 -04001128 data->name = name;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 data->valid = 0;
Jean Delvaref641b582007-06-09 10:11:16 -04001130 mutex_init(&data->lock);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001131 mutex_init(&data->update_lock);
Jean Delvaref641b582007-06-09 10:11:16 -04001132 platform_set_drvdata(pdev, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
Jim Cromie2a32ec22008-10-18 20:27:33 -07001134 for (i = 0; i < LDNI_MAX; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 if (((data->address[i] = extra_isa[i]))
1136 && !request_region(extra_isa[i], PC87360_EXTENT,
Laurent Riffardcdaf7932005-11-26 20:37:41 +01001137 pc87360_driver.driver.name)) {
Jean Delvaref641b582007-06-09 10:11:16 -04001138 dev_err(dev, "Region 0x%x-0x%x already "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 "in use!\n", extra_isa[i],
1140 extra_isa[i]+PC87360_EXTENT-1);
1141 for (i--; i >= 0; i--)
1142 release_region(extra_isa[i], PC87360_EXTENT);
1143 err = -EBUSY;
1144 goto ERROR1;
1145 }
1146 }
1147
1148 /* Retrieve the fans configuration from Super-I/O space */
1149 if (data->fannr)
1150 data->fan_conf = confreg[0] | (confreg[1] << 8);
1151
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 /* Use the correct reference voltage
1153 Unless both the VLM and the TMS logical devices agree to
1154 use an external Vref, the internal one is used. */
1155 if (data->innr) {
1156 i = pc87360_read_value(data, LD_IN, NO_BANK,
1157 PC87365_REG_IN_CONFIG);
1158 if (data->tempnr) {
1159 i &= pc87360_read_value(data, LD_TEMP, NO_BANK,
1160 PC87365_REG_TEMP_CONFIG);
1161 }
1162 data->in_vref = (i&0x02) ? 3025 : 2966;
Jean Delvaref641b582007-06-09 10:11:16 -04001163 dev_dbg(dev, "Using %s reference voltage\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164 (i&0x02) ? "external" : "internal");
1165
1166 data->vid_conf = confreg[3];
Jim Cromie3d7f9a82006-12-12 18:18:28 +01001167 data->vrm = vid_which_vrm();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 }
1169
1170 /* Fan clock dividers may be needed before any data is read */
1171 for (i = 0; i < data->fannr; i++) {
1172 if (FAN_CONFIG_MONITOR(data->fan_conf, i))
1173 data->fan_status[i] = pc87360_read_value(data,
1174 LD_FAN, NO_BANK,
1175 PC87360_REG_FAN_STATUS(i));
1176 }
1177
1178 if (init > 0) {
1179 if (devid == 0xe9 && data->address[1]) /* PC87366 */
1180 use_thermistors = confreg[2] & 0x40;
1181
Jean Delvaref641b582007-06-09 10:11:16 -04001182 pc87360_init_device(pdev, use_thermistors);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 }
1184
Jim Cromief3722d5b2006-09-24 21:03:25 +02001185 /* Register all-or-nothing sysfs groups */
1186
1187 if (data->innr &&
Jean Delvaref641b582007-06-09 10:11:16 -04001188 (err = sysfs_create_group(&dev->kobj,
Jim Cromief3722d5b2006-09-24 21:03:25 +02001189 &pc8736x_vin_group)))
1190 goto ERROR3;
1191
1192 if (data->innr == 14 &&
Jean Delvaref641b582007-06-09 10:11:16 -04001193 (err = sysfs_create_group(&dev->kobj,
Jim Cromief3722d5b2006-09-24 21:03:25 +02001194 &pc8736x_therm_group)))
1195 goto ERROR3;
1196
1197 /* create device attr-files for varying sysfs groups */
1198
1199 if (data->tempnr) {
1200 for (i = 0; i < data->tempnr; i++) {
1201 if ((err = device_create_file(dev,
1202 &temp_input[i].dev_attr))
1203 || (err = device_create_file(dev,
1204 &temp_min[i].dev_attr))
1205 || (err = device_create_file(dev,
1206 &temp_max[i].dev_attr))
1207 || (err = device_create_file(dev,
1208 &temp_crit[i].dev_attr))
1209 || (err = device_create_file(dev,
Jim Cromieb267e8c2008-10-18 20:27:32 -07001210 &temp_status[i].dev_attr))
1211 || (err = device_create_file(dev,
1212 &temp_min_alarm[i].dev_attr))
1213 || (err = device_create_file(dev,
1214 &temp_max_alarm[i].dev_attr))
1215 || (err = device_create_file(dev,
1216 &temp_crit_alarm[i].dev_attr))
1217 || (err = device_create_file(dev,
1218 &temp_fault[i].dev_attr)))
Jim Cromief3722d5b2006-09-24 21:03:25 +02001219 goto ERROR3;
1220 }
1221 if ((err = device_create_file(dev, &dev_attr_alarms_temp)))
1222 goto ERROR3;
1223 }
1224
1225 for (i = 0; i < data->fannr; i++) {
1226 if (FAN_CONFIG_MONITOR(data->fan_conf, i)
1227 && ((err = device_create_file(dev,
1228 &fan_input[i].dev_attr))
1229 || (err = device_create_file(dev,
1230 &fan_min[i].dev_attr))
1231 || (err = device_create_file(dev,
1232 &fan_div[i].dev_attr))
1233 || (err = device_create_file(dev,
1234 &fan_status[i].dev_attr))))
1235 goto ERROR3;
1236
1237 if (FAN_CONFIG_CONTROL(data->fan_conf, i)
1238 && (err = device_create_file(dev, &pwm[i].dev_attr)))
1239 goto ERROR3;
1240 }
1241
Jean Delvaref641b582007-06-09 10:11:16 -04001242 if ((err = device_create_file(dev, &dev_attr_name)))
1243 goto ERROR3;
1244
Tony Jones1beeffe2007-08-20 13:46:20 -07001245 data->hwmon_dev = hwmon_device_register(dev);
1246 if (IS_ERR(data->hwmon_dev)) {
1247 err = PTR_ERR(data->hwmon_dev);
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001248 goto ERROR3;
1249 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 return 0;
1251
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001252ERROR3:
Jean Delvaref641b582007-06-09 10:11:16 -04001253 device_remove_file(dev, &dev_attr_name);
Jim Cromief3722d5b2006-09-24 21:03:25 +02001254 /* can still remove groups whose members were added individually */
Jean Delvaref641b582007-06-09 10:11:16 -04001255 sysfs_remove_group(&dev->kobj, &pc8736x_temp_group);
1256 sysfs_remove_group(&dev->kobj, &pc8736x_fan_group);
1257 sysfs_remove_group(&dev->kobj, &pc8736x_therm_group);
1258 sysfs_remove_group(&dev->kobj, &pc8736x_vin_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 for (i = 0; i < 3; i++) {
1260 if (data->address[i]) {
1261 release_region(data->address[i], PC87360_EXTENT);
1262 }
1263 }
1264ERROR1:
1265 kfree(data);
1266 return err;
1267}
1268
Jean Delvaref641b582007-06-09 10:11:16 -04001269static int __devexit pc87360_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270{
Jean Delvaref641b582007-06-09 10:11:16 -04001271 struct pc87360_data *data = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272 int i;
1273
Tony Jones1beeffe2007-08-20 13:46:20 -07001274 hwmon_device_unregister(data->hwmon_dev);
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001275
Jean Delvaref641b582007-06-09 10:11:16 -04001276 device_remove_file(&pdev->dev, &dev_attr_name);
1277 sysfs_remove_group(&pdev->dev.kobj, &pc8736x_temp_group);
1278 sysfs_remove_group(&pdev->dev.kobj, &pc8736x_fan_group);
1279 sysfs_remove_group(&pdev->dev.kobj, &pc8736x_therm_group);
1280 sysfs_remove_group(&pdev->dev.kobj, &pc8736x_vin_group);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281
1282 for (i = 0; i < 3; i++) {
1283 if (data->address[i]) {
1284 release_region(data->address[i], PC87360_EXTENT);
1285 }
1286 }
1287 kfree(data);
1288
1289 return 0;
1290}
1291
1292/* ldi is the logical device index
1293 bank is for voltages and temperatures only */
1294static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank,
1295 u8 reg)
1296{
1297 int res;
1298
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001299 mutex_lock(&(data->lock));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 if (bank != NO_BANK)
1301 outb_p(bank, data->address[ldi] + PC87365_REG_BANK);
1302 res = inb_p(data->address[ldi] + reg);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001303 mutex_unlock(&(data->lock));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
1305 return res;
1306}
1307
1308static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank,
1309 u8 reg, u8 value)
1310{
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001311 mutex_lock(&(data->lock));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 if (bank != NO_BANK)
1313 outb_p(bank, data->address[ldi] + PC87365_REG_BANK);
1314 outb_p(value, data->address[ldi] + reg);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001315 mutex_unlock(&(data->lock));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316}
1317
Jim Cromie28f74e72008-10-18 20:27:30 -07001318/* (temp & vin) channel conversion status register flags (pdf sec.11.5.12) */
1319#define CHAN_CNVRTD 0x80 /* new data ready */
1320#define CHAN_ENA 0x01 /* enabled channel (temp or vin) */
1321#define CHAN_ALM_ENA 0x10 /* propagate to alarms-reg ?? (chk val!) */
1322#define CHAN_READY (CHAN_ENA|CHAN_CNVRTD) /* sample ready mask */
1323
Jim Cromieb267e8c2008-10-18 20:27:32 -07001324#define TEMP_OTS_OE 0x20 /* OTS Output Enable */
1325#define VIN_RW1C_MASK (CHAN_READY|CHAN_ALM_MAX|CHAN_ALM_MIN) /* 0x87 */
1326#define TEMP_RW1C_MASK (VIN_RW1C_MASK|TEMP_ALM_CRIT|TEMP_FAULT) /* 0xCF */
1327
Jean Delvaref641b582007-06-09 10:11:16 -04001328static void pc87360_init_device(struct platform_device *pdev,
1329 int use_thermistors)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330{
Jean Delvaref641b582007-06-09 10:11:16 -04001331 struct pc87360_data *data = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 int i, nr;
1333 const u8 init_in[14] = { 2, 2, 2, 2, 2, 2, 2, 1, 1, 3, 1, 2, 2, 2 };
1334 const u8 init_temp[3] = { 2, 2, 1 };
1335 u8 reg;
1336
1337 if (init >= 2 && data->innr) {
1338 reg = pc87360_read_value(data, LD_IN, NO_BANK,
1339 PC87365_REG_IN_CONVRATE);
Jean Delvaref641b582007-06-09 10:11:16 -04001340 dev_info(&pdev->dev, "VLM conversion set to "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 "1s period, 160us delay\n");
1342 pc87360_write_value(data, LD_IN, NO_BANK,
1343 PC87365_REG_IN_CONVRATE,
1344 (reg & 0xC0) | 0x11);
1345 }
1346
1347 nr = data->innr < 11 ? data->innr : 11;
Jim Cromiededc6a72006-01-09 23:24:41 +01001348 for (i = 0; i < nr; i++) {
Jim Cromie8ca13672008-10-18 20:27:34 -07001349 reg = pc87360_read_value(data, LD_IN, i,
1350 PC87365_REG_IN_STATUS);
1351 dev_dbg(&pdev->dev, "bios in%d status:0x%02x\n", i, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 if (init >= init_in[i]) {
1353 /* Forcibly enable voltage channel */
Jim Cromie28f74e72008-10-18 20:27:30 -07001354 if (!(reg & CHAN_ENA)) {
Jean Delvaref641b582007-06-09 10:11:16 -04001355 dev_dbg(&pdev->dev, "Forcibly "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 "enabling in%d\n", i);
1357 pc87360_write_value(data, LD_IN, i,
1358 PC87365_REG_IN_STATUS,
1359 (reg & 0x68) | 0x87);
1360 }
1361 }
1362 }
1363
1364 /* We can't blindly trust the Super-I/O space configuration bit,
1365 most BIOS won't set it properly */
Jim Cromie8ca13672008-10-18 20:27:34 -07001366 dev_dbg(&pdev->dev, "bios thermistors:%d\n", use_thermistors);
Jim Cromiededc6a72006-01-09 23:24:41 +01001367 for (i = 11; i < data->innr; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001368 reg = pc87360_read_value(data, LD_IN, i,
1369 PC87365_REG_TEMP_STATUS);
Jim Cromie28f74e72008-10-18 20:27:30 -07001370 use_thermistors = use_thermistors || (reg & CHAN_ENA);
Jim Cromie8ca13672008-10-18 20:27:34 -07001371 /* thermistors are temp[4-6], measured on vin[11-14] */
1372 dev_dbg(&pdev->dev, "bios temp%d_status:0x%02x\n", i-7, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 }
Jim Cromie8ca13672008-10-18 20:27:34 -07001374 dev_dbg(&pdev->dev, "using thermistors:%d\n", use_thermistors);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
1376 i = use_thermistors ? 2 : 0;
Jim Cromiededc6a72006-01-09 23:24:41 +01001377 for (; i < data->tempnr; i++) {
Jim Cromie8ca13672008-10-18 20:27:34 -07001378 reg = pc87360_read_value(data, LD_TEMP, i,
1379 PC87365_REG_TEMP_STATUS);
1380 dev_dbg(&pdev->dev, "bios temp%d_status:0x%02x\n", i+1, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 if (init >= init_temp[i]) {
1382 /* Forcibly enable temperature channel */
Jim Cromie28f74e72008-10-18 20:27:30 -07001383 if (!(reg & CHAN_ENA)) {
Jean Delvaref641b582007-06-09 10:11:16 -04001384 dev_dbg(&pdev->dev, "Forcibly "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 "enabling temp%d\n", i+1);
1386 pc87360_write_value(data, LD_TEMP, i,
1387 PC87365_REG_TEMP_STATUS,
1388 0xCF);
1389 }
1390 }
1391 }
1392
1393 if (use_thermistors) {
Jim Cromiededc6a72006-01-09 23:24:41 +01001394 for (i = 11; i < data->innr; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 if (init >= init_in[i]) {
1396 /* The pin may already be used by thermal
1397 diodes */
1398 reg = pc87360_read_value(data, LD_TEMP,
1399 (i-11)/2, PC87365_REG_TEMP_STATUS);
Jim Cromie28f74e72008-10-18 20:27:30 -07001400 if (reg & CHAN_ENA) {
Jean Delvaref641b582007-06-09 10:11:16 -04001401 dev_dbg(&pdev->dev, "Skipping "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402 "temp%d, pin already in use "
1403 "by temp%d\n", i-7, (i-11)/2);
1404 continue;
1405 }
1406
1407 /* Forcibly enable thermistor channel */
1408 reg = pc87360_read_value(data, LD_IN, i,
1409 PC87365_REG_IN_STATUS);
Jim Cromie28f74e72008-10-18 20:27:30 -07001410 if (!(reg & CHAN_ENA)) {
Jean Delvaref641b582007-06-09 10:11:16 -04001411 dev_dbg(&pdev->dev, "Forcibly "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 "enabling temp%d\n", i-7);
1413 pc87360_write_value(data, LD_IN, i,
1414 PC87365_REG_TEMP_STATUS,
1415 (reg & 0x60) | 0x8F);
1416 }
1417 }
1418 }
1419 }
1420
1421 if (data->innr) {
1422 reg = pc87360_read_value(data, LD_IN, NO_BANK,
1423 PC87365_REG_IN_CONFIG);
Jim Cromie8ca13672008-10-18 20:27:34 -07001424 dev_dbg(&pdev->dev, "bios vin-cfg:0x%02x\n", reg);
Jim Cromie28f74e72008-10-18 20:27:30 -07001425 if (reg & CHAN_ENA) {
Jean Delvaref641b582007-06-09 10:11:16 -04001426 dev_dbg(&pdev->dev, "Forcibly "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 "enabling monitoring (VLM)\n");
1428 pc87360_write_value(data, LD_IN, NO_BANK,
1429 PC87365_REG_IN_CONFIG,
1430 reg & 0xFE);
1431 }
1432 }
1433
1434 if (data->tempnr) {
1435 reg = pc87360_read_value(data, LD_TEMP, NO_BANK,
1436 PC87365_REG_TEMP_CONFIG);
Jim Cromie8ca13672008-10-18 20:27:34 -07001437 dev_dbg(&pdev->dev, "bios temp-cfg:0x%02x\n", reg);
Jim Cromie28f74e72008-10-18 20:27:30 -07001438 if (reg & CHAN_ENA) {
Jean Delvaref641b582007-06-09 10:11:16 -04001439 dev_dbg(&pdev->dev, "Forcibly enabling "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001440 "monitoring (TMS)\n");
1441 pc87360_write_value(data, LD_TEMP, NO_BANK,
1442 PC87365_REG_TEMP_CONFIG,
1443 reg & 0xFE);
1444 }
1445
1446 if (init >= 2) {
1447 /* Chip config as documented by National Semi. */
1448 pc87360_write_value(data, LD_TEMP, 0xF, 0xA, 0x08);
1449 /* We voluntarily omit the bank here, in case the
1450 sequence itself matters. It shouldn't be a problem,
1451 since nobody else is supposed to access the
1452 device at that point. */
1453 pc87360_write_value(data, LD_TEMP, NO_BANK, 0xB, 0x04);
1454 pc87360_write_value(data, LD_TEMP, NO_BANK, 0xC, 0x35);
1455 pc87360_write_value(data, LD_TEMP, NO_BANK, 0xD, 0x05);
1456 pc87360_write_value(data, LD_TEMP, NO_BANK, 0xE, 0x05);
1457 }
1458 }
1459}
1460
Jean Delvaref641b582007-06-09 10:11:16 -04001461static void pc87360_autodiv(struct device *dev, int nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462{
Jean Delvaref641b582007-06-09 10:11:16 -04001463 struct pc87360_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 u8 old_min = data->fan_min[nr];
1465
1466 /* Increase clock divider if needed and possible */
1467 if ((data->fan_status[nr] & 0x04) /* overflow flag */
1468 || (data->fan[nr] >= 224)) { /* next to overflow */
1469 if ((data->fan_status[nr] & 0x60) != 0x60) {
1470 data->fan_status[nr] += 0x20;
1471 data->fan_min[nr] >>= 1;
1472 data->fan[nr] >>= 1;
Jean Delvaref641b582007-06-09 10:11:16 -04001473 dev_dbg(dev, "Increasing "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 "clock divider to %d for fan %d\n",
1475 FAN_DIV_FROM_REG(data->fan_status[nr]), nr+1);
1476 }
1477 } else {
1478 /* Decrease clock divider if possible */
1479 while (!(data->fan_min[nr] & 0x80) /* min "nails" divider */
1480 && data->fan[nr] < 85 /* bad accuracy */
1481 && (data->fan_status[nr] & 0x60) != 0x00) {
1482 data->fan_status[nr] -= 0x20;
1483 data->fan_min[nr] <<= 1;
1484 data->fan[nr] <<= 1;
Jean Delvaref641b582007-06-09 10:11:16 -04001485 dev_dbg(dev, "Decreasing "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 "clock divider to %d for fan %d\n",
1487 FAN_DIV_FROM_REG(data->fan_status[nr]),
1488 nr+1);
1489 }
1490 }
1491
1492 /* Write new fan min if it changed */
1493 if (old_min != data->fan_min[nr]) {
1494 pc87360_write_value(data, LD_FAN, NO_BANK,
1495 PC87360_REG_FAN_MIN(nr),
1496 data->fan_min[nr]);
1497 }
1498}
1499
1500static struct pc87360_data *pc87360_update_device(struct device *dev)
1501{
Jean Delvaref641b582007-06-09 10:11:16 -04001502 struct pc87360_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 u8 i;
1504
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001505 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506
1507 if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
Jean Delvaref641b582007-06-09 10:11:16 -04001508 dev_dbg(dev, "Data update\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509
1510 /* Fans */
1511 for (i = 0; i < data->fannr; i++) {
1512 if (FAN_CONFIG_MONITOR(data->fan_conf, i)) {
1513 data->fan_status[i] =
1514 pc87360_read_value(data, LD_FAN,
1515 NO_BANK, PC87360_REG_FAN_STATUS(i));
1516 data->fan[i] = pc87360_read_value(data, LD_FAN,
1517 NO_BANK, PC87360_REG_FAN(i));
1518 data->fan_min[i] = pc87360_read_value(data,
1519 LD_FAN, NO_BANK,
1520 PC87360_REG_FAN_MIN(i));
1521 /* Change clock divider if needed */
Jean Delvaref641b582007-06-09 10:11:16 -04001522 pc87360_autodiv(dev, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 /* Clear bits and write new divider */
1524 pc87360_write_value(data, LD_FAN, NO_BANK,
1525 PC87360_REG_FAN_STATUS(i),
1526 data->fan_status[i]);
1527 }
1528 if (FAN_CONFIG_CONTROL(data->fan_conf, i))
1529 data->pwm[i] = pc87360_read_value(data, LD_FAN,
1530 NO_BANK, PC87360_REG_PWM(i));
1531 }
1532
1533 /* Voltages */
1534 for (i = 0; i < data->innr; i++) {
1535 data->in_status[i] = pc87360_read_value(data, LD_IN, i,
1536 PC87365_REG_IN_STATUS);
1537 /* Clear bits */
1538 pc87360_write_value(data, LD_IN, i,
1539 PC87365_REG_IN_STATUS,
1540 data->in_status[i]);
Jim Cromie28f74e72008-10-18 20:27:30 -07001541 if ((data->in_status[i] & CHAN_READY) == CHAN_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 data->in[i] = pc87360_read_value(data, LD_IN,
1543 i, PC87365_REG_IN);
1544 }
Jim Cromie28f74e72008-10-18 20:27:30 -07001545 if (data->in_status[i] & CHAN_ENA) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 data->in_min[i] = pc87360_read_value(data,
1547 LD_IN, i,
1548 PC87365_REG_IN_MIN);
1549 data->in_max[i] = pc87360_read_value(data,
1550 LD_IN, i,
1551 PC87365_REG_IN_MAX);
1552 if (i >= 11)
1553 data->in_crit[i-11] =
1554 pc87360_read_value(data, LD_IN,
1555 i, PC87365_REG_TEMP_CRIT);
1556 }
1557 }
1558 if (data->innr) {
1559 data->in_alarms = pc87360_read_value(data, LD_IN,
1560 NO_BANK, PC87365_REG_IN_ALARMS1)
1561 | ((pc87360_read_value(data, LD_IN,
1562 NO_BANK, PC87365_REG_IN_ALARMS2)
1563 & 0x07) << 8);
1564 data->vid = (data->vid_conf & 0xE0) ?
1565 pc87360_read_value(data, LD_IN,
1566 NO_BANK, PC87365_REG_VID) : 0x1F;
1567 }
1568
1569 /* Temperatures */
1570 for (i = 0; i < data->tempnr; i++) {
1571 data->temp_status[i] = pc87360_read_value(data,
1572 LD_TEMP, i,
1573 PC87365_REG_TEMP_STATUS);
1574 /* Clear bits */
1575 pc87360_write_value(data, LD_TEMP, i,
1576 PC87365_REG_TEMP_STATUS,
1577 data->temp_status[i]);
Jim Cromie28f74e72008-10-18 20:27:30 -07001578 if ((data->temp_status[i] & CHAN_READY) == CHAN_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 data->temp[i] = pc87360_read_value(data,
1580 LD_TEMP, i,
1581 PC87365_REG_TEMP);
1582 }
Jim Cromie28f74e72008-10-18 20:27:30 -07001583 if (data->temp_status[i] & CHAN_ENA) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 data->temp_min[i] = pc87360_read_value(data,
1585 LD_TEMP, i,
1586 PC87365_REG_TEMP_MIN);
1587 data->temp_max[i] = pc87360_read_value(data,
1588 LD_TEMP, i,
1589 PC87365_REG_TEMP_MAX);
1590 data->temp_crit[i] = pc87360_read_value(data,
1591 LD_TEMP, i,
1592 PC87365_REG_TEMP_CRIT);
1593 }
1594 }
1595 if (data->tempnr) {
1596 data->temp_alarms = pc87360_read_value(data, LD_TEMP,
1597 NO_BANK, PC87365_REG_TEMP_ALARMS)
1598 & 0x3F;
1599 }
1600
1601 data->last_updated = jiffies;
1602 data->valid = 1;
1603 }
1604
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001605 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606
1607 return data;
1608}
1609
Jean Delvaref641b582007-06-09 10:11:16 -04001610static int __init pc87360_device_add(unsigned short address)
1611{
1612 struct resource res = {
1613 .name = "pc87360",
1614 .flags = IORESOURCE_IO,
1615 };
1616 int err, i;
1617
1618 pdev = platform_device_alloc("pc87360", address);
1619 if (!pdev) {
1620 err = -ENOMEM;
1621 printk(KERN_ERR "pc87360: Device allocation failed\n");
1622 goto exit;
1623 }
1624
1625 for (i = 0; i < 3; i++) {
1626 if (!extra_isa[i])
1627 continue;
1628 res.start = extra_isa[i];
1629 res.end = extra_isa[i] + PC87360_EXTENT - 1;
1630 err = platform_device_add_resources(pdev, &res, 1);
1631 if (err) {
1632 printk(KERN_ERR "pc87360: Device resource[%d] "
1633 "addition failed (%d)\n", i, err);
1634 goto exit_device_put;
1635 }
1636 }
1637
1638 err = platform_device_add(pdev);
1639 if (err) {
1640 printk(KERN_ERR "pc87360: Device addition failed (%d)\n",
1641 err);
1642 goto exit_device_put;
1643 }
1644
1645 return 0;
1646
1647exit_device_put:
1648 platform_device_put(pdev);
1649exit:
1650 return err;
1651}
1652
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653static int __init pc87360_init(void)
1654{
Jean Delvaref641b582007-06-09 10:11:16 -04001655 int err, i;
1656 unsigned short address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657
1658 if (pc87360_find(0x2e, &devid, extra_isa)
1659 && pc87360_find(0x4e, &devid, extra_isa)) {
1660 printk(KERN_WARNING "pc87360: PC8736x not detected, "
1661 "module not inserted.\n");
1662 return -ENODEV;
1663 }
1664
1665 /* Arbitrarily pick one of the addresses */
1666 for (i = 0; i < 3; i++) {
1667 if (extra_isa[i] != 0x0000) {
Jean Delvare2d8672c2005-07-19 23:56:35 +02001668 address = extra_isa[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 break;
1670 }
1671 }
1672
Jean Delvare2d8672c2005-07-19 23:56:35 +02001673 if (address == 0x0000) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674 printk(KERN_WARNING "pc87360: No active logical device, "
1675 "module not inserted.\n");
1676 return -ENODEV;
1677 }
1678
Jean Delvaref641b582007-06-09 10:11:16 -04001679 err = platform_driver_register(&pc87360_driver);
1680 if (err)
1681 goto exit;
1682
1683 /* Sets global pdev as a side effect */
1684 err = pc87360_device_add(address);
1685 if (err)
1686 goto exit_driver;
1687
1688 return 0;
1689
1690 exit_driver:
1691 platform_driver_unregister(&pc87360_driver);
1692 exit:
1693 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694}
1695
1696static void __exit pc87360_exit(void)
1697{
Jean Delvaref641b582007-06-09 10:11:16 -04001698 platform_device_unregister(pdev);
1699 platform_driver_unregister(&pc87360_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700}
1701
1702
1703MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>");
1704MODULE_DESCRIPTION("PC8736x hardware monitor");
1705MODULE_LICENSE("GPL");
1706
1707module_init(pc87360_init);
1708module_exit(pc87360_exit);