Merge tag 'usb-3.10-rc5' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / hwmon / vt8231.c
CommitLineData
1de9e371 1/*
61ba0318
GR
2 * vt8231.c - Part of lm_sensors, Linux kernel modules
3 * for hardware monitoring
4 *
5 * Copyright (c) 2005 Roger Lucas <vt8231@hiddenengine.co.uk>
6 * Copyright (c) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com>
7 * Aaron M. Marsh <amarsh@sdf.lonestar.org>
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 */
1de9e371 23
61ba0318
GR
24/*
25 * Supports VIA VT8231 South Bridge embedded sensors
26 */
1de9e371 27
9d72be0d
JP
28#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
29
1de9e371
RL
30#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/slab.h>
33#include <linux/pci.h>
34#include <linux/jiffies.h>
ec5e1a4b 35#include <linux/platform_device.h>
1de9e371
RL
36#include <linux/hwmon.h>
37#include <linux/hwmon-sysfs.h>
38#include <linux/hwmon-vid.h>
39#include <linux/err.h>
9a61bf63 40#include <linux/mutex.h>
b9acb64a 41#include <linux/acpi.h>
6055fae8 42#include <linux/io.h>
1de9e371
RL
43
44static int force_addr;
45module_param(force_addr, int, 0);
46MODULE_PARM_DESC(force_addr, "Initialize the base address of the sensors");
47
ec5e1a4b 48static struct platform_device *pdev;
1de9e371
RL
49
50#define VT8231_EXTENT 0x80
51#define VT8231_BASE_REG 0x70
52#define VT8231_ENABLE_REG 0x74
53
61ba0318
GR
54/*
55 * The VT8231 registers
56 *
57 * The reset value for the input channel configuration is used (Reg 0x4A=0x07)
58 * which sets the selected inputs marked with '*' below if multiple options are
59 * possible:
60 *
61 * Voltage Mode Temperature Mode
62 * Sensor Linux Id Linux Id VIA Id
63 * -------- -------- -------- ------
64 * CPU Diode N/A temp1 0
65 * UIC1 in0 temp2 * 1
66 * UIC2 in1 * temp3 2
67 * UIC3 in2 * temp4 3
68 * UIC4 in3 * temp5 4
69 * UIC5 in4 * temp6 5
70 * 3.3V in5 N/A
71 *
72 * Note that the BIOS may set the configuration register to a different value
73 * to match the motherboard configuration.
74 */
1de9e371
RL
75
76/* fans numbered 0-1 */
77#define VT8231_REG_FAN_MIN(nr) (0x3b + (nr))
78#define VT8231_REG_FAN(nr) (0x29 + (nr))
79
80/* Voltage inputs numbered 0-5 */
81
82static const u8 regvolt[] = { 0x21, 0x22, 0x23, 0x24, 0x25, 0x26 };
83static const u8 regvoltmax[] = { 0x3d, 0x2b, 0x2d, 0x2f, 0x31, 0x33 };
84static const u8 regvoltmin[] = { 0x3e, 0x2c, 0x2e, 0x30, 0x32, 0x34 };
85
61ba0318
GR
86/*
87 * Temperatures are numbered 1-6 according to the Linux kernel specification.
88 *
89 * In the VIA datasheet, however, the temperatures are numbered from zero.
90 * Since it is important that this driver can easily be compared to the VIA
91 * datasheet, we will use the VIA numbering within this driver and map the
92 * kernel sysfs device name to the VIA number in the sysfs callback.
93 */
1de9e371
RL
94
95#define VT8231_REG_TEMP_LOW01 0x49
96#define VT8231_REG_TEMP_LOW25 0x4d
97
98static const u8 regtemp[] = { 0x1f, 0x21, 0x22, 0x23, 0x24, 0x25 };
99static const u8 regtempmax[] = { 0x39, 0x3d, 0x2b, 0x2d, 0x2f, 0x31 };
100static const u8 regtempmin[] = { 0x3a, 0x3e, 0x2c, 0x2e, 0x30, 0x32 };
101
102#define TEMP_FROM_REG(reg) (((253 * 4 - (reg)) * 550 + 105) / 210)
103#define TEMP_MAXMIN_FROM_REG(reg) (((253 - (reg)) * 2200 + 105) / 210)
104#define TEMP_MAXMIN_TO_REG(val) (253 - ((val) * 210 + 1100) / 2200)
105
106#define VT8231_REG_CONFIG 0x40
107#define VT8231_REG_ALARM1 0x41
108#define VT8231_REG_ALARM2 0x42
109#define VT8231_REG_FANDIV 0x47
110#define VT8231_REG_UCH_CONFIG 0x4a
111#define VT8231_REG_TEMP1_CONFIG 0x4b
112#define VT8231_REG_TEMP2_CONFIG 0x4c
113
61ba0318
GR
114/*
115 * temps 0-5 as numbered in VIA datasheet - see later for mapping to Linux
116 * numbering
117 */
1de9e371
RL
118#define ISTEMP(i, ch_config) ((i) == 0 ? 1 : \
119 ((ch_config) >> ((i)+1)) & 0x01)
120/* voltages 0-5 */
121#define ISVOLT(i, ch_config) ((i) == 5 ? 1 : \
122 !(((ch_config) >> ((i)+2)) & 0x01))
123
124#define DIV_FROM_REG(val) (1 << (val))
125
61ba0318
GR
126/*
127 * NB The values returned here are NOT temperatures. The calibration curves
128 * for the thermistor curves are board-specific and must go in the
129 * sensors.conf file. Temperature sensors are actually ten bits, but the
130 * VIA datasheet only considers the 8 MSBs obtained from the regtemp[]
131 * register. The temperature value returned should have a magnitude of 3,
132 * so we use the VIA scaling as the "true" scaling and use the remaining 2
133 * LSBs as fractional precision.
134 *
135 * All the on-chip hardware temperature comparisons for the alarms are only
136 * 8-bits wide, and compare against the 8 MSBs of the temperature. The bits
137 * in the registers VT8231_REG_TEMP_LOW01 and VT8231_REG_TEMP_LOW25 are
138 * ignored.
139 */
140
141/*
142 ****** FAN RPM CONVERSIONS ********
143 * This chip saturates back at 0, not at 255 like many the other chips.
144 * So, 0 means 0 RPM
145 */
1de9e371
RL
146static inline u8 FAN_TO_REG(long rpm, int div)
147{
148 if (rpm == 0)
149 return 0;
2a844c14 150 return clamp_val(1310720 / (rpm * div), 1, 255);
1de9e371
RL
151}
152
153#define FAN_FROM_REG(val, div) ((val) == 0 ? 0 : 1310720 / ((val) * (div)))
154
155struct vt8231_data {
ec5e1a4b
RL
156 unsigned short addr;
157 const char *name;
158
9a61bf63 159 struct mutex update_lock;
1beeffe4 160 struct device *hwmon_dev;
1de9e371
RL
161 char valid; /* !=0 if following fields are valid */
162 unsigned long last_updated; /* In jiffies */
163
164 u8 in[6]; /* Register value */
165 u8 in_max[6]; /* Register value */
166 u8 in_min[6]; /* Register value */
167 u16 temp[6]; /* Register value 10 bit, right aligned */
168 u8 temp_max[6]; /* Register value */
169 u8 temp_min[6]; /* Register value */
170 u8 fan[2]; /* Register value */
171 u8 fan_min[2]; /* Register value */
172 u8 fan_div[2]; /* Register encoding, shifted right */
173 u16 alarms; /* Register encoding */
174 u8 uch_config;
175};
176
177static struct pci_dev *s_bridge;
ec5e1a4b 178static int vt8231_probe(struct platform_device *pdev);
281dfd0b 179static int vt8231_remove(struct platform_device *pdev);
1de9e371 180static struct vt8231_data *vt8231_update_device(struct device *dev);
ec5e1a4b 181static void vt8231_init_device(struct vt8231_data *data);
1de9e371 182
ec5e1a4b 183static inline int vt8231_read_value(struct vt8231_data *data, u8 reg)
1de9e371 184{
ec5e1a4b 185 return inb_p(data->addr + reg);
1de9e371
RL
186}
187
ec5e1a4b 188static inline void vt8231_write_value(struct vt8231_data *data, u8 reg,
1de9e371
RL
189 u8 value)
190{
ec5e1a4b 191 outb_p(value, data->addr + reg);
1de9e371
RL
192}
193
194/* following are the sysfs callback functions */
195static ssize_t show_in(struct device *dev, struct device_attribute *attr,
196 char *buf)
197{
198 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
199 int nr = sensor_attr->index;
200 struct vt8231_data *data = vt8231_update_device(dev);
201
202 return sprintf(buf, "%d\n", ((data->in[nr] - 3) * 10000) / 958);
203}
204
205static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
206 char *buf)
207{
208 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
209 int nr = sensor_attr->index;
210 struct vt8231_data *data = vt8231_update_device(dev);
211
212 return sprintf(buf, "%d\n", ((data->in_min[nr] - 3) * 10000) / 958);
213}
214
215static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
216 char *buf)
217{
218 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
219 int nr = sensor_attr->index;
220 struct vt8231_data *data = vt8231_update_device(dev);
221
222 return sprintf(buf, "%d\n", (((data->in_max[nr] - 3) * 10000) / 958));
223}
224
225static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
226 const char *buf, size_t count)
227{
228 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
229 int nr = sensor_attr->index;
ec5e1a4b 230 struct vt8231_data *data = dev_get_drvdata(dev);
65fe5c79
GR
231 unsigned long val;
232 int err;
233
234 err = kstrtoul(buf, 10, &val);
235 if (err)
236 return err;
1de9e371 237
9a61bf63 238 mutex_lock(&data->update_lock);
2a844c14 239 data->in_min[nr] = clamp_val(((val * 958) / 10000) + 3, 0, 255);
ec5e1a4b 240 vt8231_write_value(data, regvoltmin[nr], data->in_min[nr]);
9a61bf63 241 mutex_unlock(&data->update_lock);
1de9e371
RL
242 return count;
243}
244
245static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
246 const char *buf, size_t count)
247{
248 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
249 int nr = sensor_attr->index;
ec5e1a4b 250 struct vt8231_data *data = dev_get_drvdata(dev);
65fe5c79
GR
251 unsigned long val;
252 int err;
253
254 err = kstrtoul(buf, 10, &val);
255 if (err)
256 return err;
1de9e371 257
9a61bf63 258 mutex_lock(&data->update_lock);
2a844c14 259 data->in_max[nr] = clamp_val(((val * 958) / 10000) + 3, 0, 255);
ec5e1a4b 260 vt8231_write_value(data, regvoltmax[nr], data->in_max[nr]);
9a61bf63 261 mutex_unlock(&data->update_lock);
1de9e371
RL
262 return count;
263}
264
265/* Special case for input 5 as this has 3.3V scaling built into the chip */
266static ssize_t show_in5(struct device *dev, struct device_attribute *attr,
267 char *buf)
268{
269 struct vt8231_data *data = vt8231_update_device(dev);
270
271 return sprintf(buf, "%d\n",
272 (((data->in[5] - 3) * 10000 * 54) / (958 * 34)));
273}
274
275static ssize_t show_in5_min(struct device *dev, struct device_attribute *attr,
276 char *buf)
277{
278 struct vt8231_data *data = vt8231_update_device(dev);
279
280 return sprintf(buf, "%d\n",
281 (((data->in_min[5] - 3) * 10000 * 54) / (958 * 34)));
282}
283
284static ssize_t show_in5_max(struct device *dev, struct device_attribute *attr,
285 char *buf)
286{
287 struct vt8231_data *data = vt8231_update_device(dev);
288
289 return sprintf(buf, "%d\n",
290 (((data->in_max[5] - 3) * 10000 * 54) / (958 * 34)));
291}
292
293static ssize_t set_in5_min(struct device *dev, struct device_attribute *attr,
294 const char *buf, size_t count)
295{
ec5e1a4b 296 struct vt8231_data *data = dev_get_drvdata(dev);
65fe5c79
GR
297 unsigned long val;
298 int err;
299
300 err = kstrtoul(buf, 10, &val);
301 if (err)
302 return err;
1de9e371 303
9a61bf63 304 mutex_lock(&data->update_lock);
2a844c14
GR
305 data->in_min[5] = clamp_val(((val * 958 * 34) / (10000 * 54)) + 3,
306 0, 255);
ec5e1a4b 307 vt8231_write_value(data, regvoltmin[5], data->in_min[5]);
9a61bf63 308 mutex_unlock(&data->update_lock);
1de9e371
RL
309 return count;
310}
311
312static ssize_t set_in5_max(struct device *dev, struct device_attribute *attr,
313 const char *buf, size_t count)
314{
ec5e1a4b 315 struct vt8231_data *data = dev_get_drvdata(dev);
65fe5c79
GR
316 unsigned long val;
317 int err;
318
319 err = kstrtoul(buf, 10, &val);
320 if (err)
321 return err;
1de9e371 322
9a61bf63 323 mutex_lock(&data->update_lock);
2a844c14
GR
324 data->in_max[5] = clamp_val(((val * 958 * 34) / (10000 * 54)) + 3,
325 0, 255);
ec5e1a4b 326 vt8231_write_value(data, regvoltmax[5], data->in_max[5]);
9a61bf63 327 mutex_unlock(&data->update_lock);
1de9e371
RL
328 return count;
329}
330
331#define define_voltage_sysfs(offset) \
332static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
333 show_in, NULL, offset); \
334static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
335 show_in_min, set_in_min, offset); \
336static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
337 show_in_max, set_in_max, offset)
338
339define_voltage_sysfs(0);
340define_voltage_sysfs(1);
341define_voltage_sysfs(2);
342define_voltage_sysfs(3);
343define_voltage_sysfs(4);
344
345static DEVICE_ATTR(in5_input, S_IRUGO, show_in5, NULL);
346static DEVICE_ATTR(in5_min, S_IRUGO | S_IWUSR, show_in5_min, set_in5_min);
347static DEVICE_ATTR(in5_max, S_IRUGO | S_IWUSR, show_in5_max, set_in5_max);
348
349/* Temperatures */
350static ssize_t show_temp0(struct device *dev, struct device_attribute *attr,
351 char *buf)
352{
353 struct vt8231_data *data = vt8231_update_device(dev);
354 return sprintf(buf, "%d\n", data->temp[0] * 250);
355}
356
357static ssize_t show_temp0_max(struct device *dev, struct device_attribute *attr,
358 char *buf)
359{
360 struct vt8231_data *data = vt8231_update_device(dev);
361 return sprintf(buf, "%d\n", data->temp_max[0] * 1000);
362}
363
364static ssize_t show_temp0_min(struct device *dev, struct device_attribute *attr,
365 char *buf)
366{
367 struct vt8231_data *data = vt8231_update_device(dev);
368 return sprintf(buf, "%d\n", data->temp_min[0] * 1000);
369}
370
371static ssize_t set_temp0_max(struct device *dev, struct device_attribute *attr,
372 const char *buf, size_t count)
373{
ec5e1a4b 374 struct vt8231_data *data = dev_get_drvdata(dev);
65fe5c79
GR
375 long val;
376 int err;
377
378 err = kstrtol(buf, 10, &val);
379 if (err)
380 return err;
1de9e371 381
9a61bf63 382 mutex_lock(&data->update_lock);
2a844c14 383 data->temp_max[0] = clamp_val((val + 500) / 1000, 0, 255);
ec5e1a4b 384 vt8231_write_value(data, regtempmax[0], data->temp_max[0]);
9a61bf63 385 mutex_unlock(&data->update_lock);
1de9e371
RL
386 return count;
387}
388static ssize_t set_temp0_min(struct device *dev, struct device_attribute *attr,
389 const char *buf, size_t count)
390{
ec5e1a4b 391 struct vt8231_data *data = dev_get_drvdata(dev);
65fe5c79
GR
392 long val;
393 int err;
394
395 err = kstrtol(buf, 10, &val);
396 if (err)
397 return err;
1de9e371 398
9a61bf63 399 mutex_lock(&data->update_lock);
2a844c14 400 data->temp_min[0] = clamp_val((val + 500) / 1000, 0, 255);
ec5e1a4b 401 vt8231_write_value(data, regtempmin[0], data->temp_min[0]);
9a61bf63 402 mutex_unlock(&data->update_lock);
1de9e371
RL
403 return count;
404}
405
406static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
407 char *buf)
408{
409 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
410 int nr = sensor_attr->index;
411 struct vt8231_data *data = vt8231_update_device(dev);
412 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
413}
414
415static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
416 char *buf)
417{
418 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
419 int nr = sensor_attr->index;
420 struct vt8231_data *data = vt8231_update_device(dev);
421 return sprintf(buf, "%d\n", TEMP_MAXMIN_FROM_REG(data->temp_max[nr]));
422}
423
424static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
425 char *buf)
426{
427 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
428 int nr = sensor_attr->index;
429 struct vt8231_data *data = vt8231_update_device(dev);
430 return sprintf(buf, "%d\n", TEMP_MAXMIN_FROM_REG(data->temp_min[nr]));
431}
432
433static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
434 const char *buf, size_t count)
435{
436 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
437 int nr = sensor_attr->index;
ec5e1a4b 438 struct vt8231_data *data = dev_get_drvdata(dev);
65fe5c79
GR
439 long val;
440 int err;
441
442 err = kstrtol(buf, 10, &val);
443 if (err)
444 return err;
1de9e371 445
9a61bf63 446 mutex_lock(&data->update_lock);
2a844c14 447 data->temp_max[nr] = clamp_val(TEMP_MAXMIN_TO_REG(val), 0, 255);
ec5e1a4b 448 vt8231_write_value(data, regtempmax[nr], data->temp_max[nr]);
9a61bf63 449 mutex_unlock(&data->update_lock);
1de9e371
RL
450 return count;
451}
452static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
453 const char *buf, size_t count)
454{
455 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
456 int nr = sensor_attr->index;
ec5e1a4b 457 struct vt8231_data *data = dev_get_drvdata(dev);
65fe5c79
GR
458 long val;
459 int err;
460
461 err = kstrtol(buf, 10, &val);
462 if (err)
463 return err;
1de9e371 464
9a61bf63 465 mutex_lock(&data->update_lock);
2a844c14 466 data->temp_min[nr] = clamp_val(TEMP_MAXMIN_TO_REG(val), 0, 255);
ec5e1a4b 467 vt8231_write_value(data, regtempmin[nr], data->temp_min[nr]);
9a61bf63 468 mutex_unlock(&data->update_lock);
1de9e371
RL
469 return count;
470}
471
61ba0318
GR
472/*
473 * Note that these map the Linux temperature sensor numbering (1-6) to the VIA
474 * temperature sensor numbering (0-5)
475 */
1de9e371
RL
476#define define_temperature_sysfs(offset) \
477static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
478 show_temp, NULL, offset - 1); \
479static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
480 show_temp_max, set_temp_max, offset - 1); \
e3efa5a7 481static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO | S_IWUSR, \
1de9e371
RL
482 show_temp_min, set_temp_min, offset - 1)
483
484static DEVICE_ATTR(temp1_input, S_IRUGO, show_temp0, NULL);
485static DEVICE_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp0_max, set_temp0_max);
65fe5c79
GR
486static DEVICE_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp0_min,
487 set_temp0_min);
1de9e371
RL
488
489define_temperature_sysfs(2);
490define_temperature_sysfs(3);
491define_temperature_sysfs(4);
492define_temperature_sysfs(5);
493define_temperature_sysfs(6);
494
1de9e371
RL
495/* Fans */
496static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
497 char *buf)
498{
499 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
500 int nr = sensor_attr->index;
501 struct vt8231_data *data = vt8231_update_device(dev);
502 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
503 DIV_FROM_REG(data->fan_div[nr])));
504}
505
506static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
507 char *buf)
508{
509 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
510 int nr = sensor_attr->index;
511 struct vt8231_data *data = vt8231_update_device(dev);
512 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
513 DIV_FROM_REG(data->fan_div[nr])));
514}
515
516static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
517 char *buf)
518{
519 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
520 int nr = sensor_attr->index;
521 struct vt8231_data *data = vt8231_update_device(dev);
522 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
523}
524
525static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
526 const char *buf, size_t count)
527{
528 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
529 int nr = sensor_attr->index;
ec5e1a4b 530 struct vt8231_data *data = dev_get_drvdata(dev);
65fe5c79
GR
531 unsigned long val;
532 int err;
533
534 err = kstrtoul(buf, 10, &val);
535 if (err)
536 return err;
1de9e371 537
9a61bf63 538 mutex_lock(&data->update_lock);
1de9e371 539 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
ec5e1a4b 540 vt8231_write_value(data, VT8231_REG_FAN_MIN(nr), data->fan_min[nr]);
9a61bf63 541 mutex_unlock(&data->update_lock);
1de9e371
RL
542 return count;
543}
544
545static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
546 const char *buf, size_t count)
547{
ec5e1a4b 548 struct vt8231_data *data = dev_get_drvdata(dev);
1de9e371 549 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
65fe5c79 550 unsigned long val;
1de9e371 551 int nr = sensor_attr->index;
ec5e1a4b 552 int old = vt8231_read_value(data, VT8231_REG_FANDIV);
1de9e371
RL
553 long min = FAN_FROM_REG(data->fan_min[nr],
554 DIV_FROM_REG(data->fan_div[nr]));
65fe5c79
GR
555 int err;
556
557 err = kstrtoul(buf, 10, &val);
558 if (err)
559 return err;
1de9e371 560
9a61bf63 561 mutex_lock(&data->update_lock);
1de9e371 562 switch (val) {
65fe5c79
GR
563 case 1:
564 data->fan_div[nr] = 0;
565 break;
566 case 2:
567 data->fan_div[nr] = 1;
568 break;
569 case 4:
570 data->fan_div[nr] = 2;
571 break;
572 case 8:
573 data->fan_div[nr] = 3;
574 break;
1de9e371 575 default:
b55f3757
GR
576 dev_err(dev,
577 "fan_div value %ld not supported. Choose one of 1, 2, 4 or 8!\n",
578 val);
9a61bf63 579 mutex_unlock(&data->update_lock);
1de9e371
RL
580 return -EINVAL;
581 }
582
583 /* Correct the fan minimum speed */
584 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
ec5e1a4b 585 vt8231_write_value(data, VT8231_REG_FAN_MIN(nr), data->fan_min[nr]);
1de9e371
RL
586
587 old = (old & 0x0f) | (data->fan_div[1] << 6) | (data->fan_div[0] << 4);
ec5e1a4b 588 vt8231_write_value(data, VT8231_REG_FANDIV, old);
9a61bf63 589 mutex_unlock(&data->update_lock);
1de9e371
RL
590 return count;
591}
592
593
594#define define_fan_sysfs(offset) \
595static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
596 show_fan, NULL, offset - 1); \
597static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
598 show_fan_div, set_fan_div, offset - 1); \
599static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
600 show_fan_min, set_fan_min, offset - 1)
601
602define_fan_sysfs(1);
603define_fan_sysfs(2);
604
605/* Alarms */
606static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
607 char *buf)
608{
609 struct vt8231_data *data = vt8231_update_device(dev);
610 return sprintf(buf, "%d\n", data->alarms);
611}
1de9e371
RL
612static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
613
2d1374ca
JD
614static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
615 char *buf)
616{
617 int bitnr = to_sensor_dev_attr(attr)->index;
618 struct vt8231_data *data = vt8231_update_device(dev);
619 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
620}
621static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4);
622static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 11);
623static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 0);
624static SENSOR_DEVICE_ATTR(temp4_alarm, S_IRUGO, show_alarm, NULL, 1);
625static SENSOR_DEVICE_ATTR(temp5_alarm, S_IRUGO, show_alarm, NULL, 3);
626static SENSOR_DEVICE_ATTR(temp6_alarm, S_IRUGO, show_alarm, NULL, 8);
627static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 11);
628static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 0);
629static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 1);
630static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3);
631static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8);
632static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 2);
633static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6);
634static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7);
635
ec5e1a4b
RL
636static ssize_t show_name(struct device *dev, struct device_attribute
637 *devattr, char *buf)
638{
639 struct vt8231_data *data = dev_get_drvdata(dev);
640 return sprintf(buf, "%s\n", data->name);
641}
642static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
643
2d1374ca 644static struct attribute *vt8231_attributes_temps[6][5] = {
cbeeb5b7
RL
645 {
646 &dev_attr_temp1_input.attr,
647 &dev_attr_temp1_max_hyst.attr,
648 &dev_attr_temp1_max.attr,
2d1374ca 649 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
cbeeb5b7
RL
650 NULL
651 }, {
652 &sensor_dev_attr_temp2_input.dev_attr.attr,
653 &sensor_dev_attr_temp2_max_hyst.dev_attr.attr,
654 &sensor_dev_attr_temp2_max.dev_attr.attr,
2d1374ca 655 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
cbeeb5b7
RL
656 NULL
657 }, {
658 &sensor_dev_attr_temp3_input.dev_attr.attr,
659 &sensor_dev_attr_temp3_max_hyst.dev_attr.attr,
660 &sensor_dev_attr_temp3_max.dev_attr.attr,
2d1374ca 661 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
cbeeb5b7
RL
662 NULL
663 }, {
664 &sensor_dev_attr_temp4_input.dev_attr.attr,
665 &sensor_dev_attr_temp4_max_hyst.dev_attr.attr,
666 &sensor_dev_attr_temp4_max.dev_attr.attr,
2d1374ca 667 &sensor_dev_attr_temp4_alarm.dev_attr.attr,
cbeeb5b7
RL
668 NULL
669 }, {
670 &sensor_dev_attr_temp5_input.dev_attr.attr,
671 &sensor_dev_attr_temp5_max_hyst.dev_attr.attr,
672 &sensor_dev_attr_temp5_max.dev_attr.attr,
2d1374ca 673 &sensor_dev_attr_temp5_alarm.dev_attr.attr,
cbeeb5b7
RL
674 NULL
675 }, {
676 &sensor_dev_attr_temp6_input.dev_attr.attr,
677 &sensor_dev_attr_temp6_max_hyst.dev_attr.attr,
678 &sensor_dev_attr_temp6_max.dev_attr.attr,
2d1374ca 679 &sensor_dev_attr_temp6_alarm.dev_attr.attr,
cbeeb5b7
RL
680 NULL
681 }
682};
683
684static const struct attribute_group vt8231_group_temps[6] = {
685 { .attrs = vt8231_attributes_temps[0] },
686 { .attrs = vt8231_attributes_temps[1] },
687 { .attrs = vt8231_attributes_temps[2] },
688 { .attrs = vt8231_attributes_temps[3] },
689 { .attrs = vt8231_attributes_temps[4] },
690 { .attrs = vt8231_attributes_temps[5] },
691};
692
2d1374ca 693static struct attribute *vt8231_attributes_volts[6][5] = {
cbeeb5b7
RL
694 {
695 &sensor_dev_attr_in0_input.dev_attr.attr,
696 &sensor_dev_attr_in0_min.dev_attr.attr,
697 &sensor_dev_attr_in0_max.dev_attr.attr,
2d1374ca 698 &sensor_dev_attr_in0_alarm.dev_attr.attr,
cbeeb5b7
RL
699 NULL
700 }, {
701 &sensor_dev_attr_in1_input.dev_attr.attr,
702 &sensor_dev_attr_in1_min.dev_attr.attr,
703 &sensor_dev_attr_in1_max.dev_attr.attr,
2d1374ca 704 &sensor_dev_attr_in1_alarm.dev_attr.attr,
cbeeb5b7
RL
705 NULL
706 }, {
707 &sensor_dev_attr_in2_input.dev_attr.attr,
708 &sensor_dev_attr_in2_min.dev_attr.attr,
709 &sensor_dev_attr_in2_max.dev_attr.attr,
2d1374ca 710 &sensor_dev_attr_in2_alarm.dev_attr.attr,
cbeeb5b7
RL
711 NULL
712 }, {
713 &sensor_dev_attr_in3_input.dev_attr.attr,
714 &sensor_dev_attr_in3_min.dev_attr.attr,
715 &sensor_dev_attr_in3_max.dev_attr.attr,
2d1374ca 716 &sensor_dev_attr_in3_alarm.dev_attr.attr,
cbeeb5b7
RL
717 NULL
718 }, {
719 &sensor_dev_attr_in4_input.dev_attr.attr,
720 &sensor_dev_attr_in4_min.dev_attr.attr,
721 &sensor_dev_attr_in4_max.dev_attr.attr,
2d1374ca 722 &sensor_dev_attr_in4_alarm.dev_attr.attr,
cbeeb5b7
RL
723 NULL
724 }, {
725 &dev_attr_in5_input.attr,
726 &dev_attr_in5_min.attr,
727 &dev_attr_in5_max.attr,
2d1374ca 728 &sensor_dev_attr_in5_alarm.dev_attr.attr,
cbeeb5b7
RL
729 NULL
730 }
731};
732
733static const struct attribute_group vt8231_group_volts[6] = {
734 { .attrs = vt8231_attributes_volts[0] },
735 { .attrs = vt8231_attributes_volts[1] },
736 { .attrs = vt8231_attributes_volts[2] },
737 { .attrs = vt8231_attributes_volts[3] },
738 { .attrs = vt8231_attributes_volts[4] },
739 { .attrs = vt8231_attributes_volts[5] },
740};
741
742static struct attribute *vt8231_attributes[] = {
743 &sensor_dev_attr_fan1_input.dev_attr.attr,
744 &sensor_dev_attr_fan2_input.dev_attr.attr,
745 &sensor_dev_attr_fan1_min.dev_attr.attr,
746 &sensor_dev_attr_fan2_min.dev_attr.attr,
747 &sensor_dev_attr_fan1_div.dev_attr.attr,
748 &sensor_dev_attr_fan2_div.dev_attr.attr,
2d1374ca
JD
749 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
750 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
cbeeb5b7 751 &dev_attr_alarms.attr,
ec5e1a4b 752 &dev_attr_name.attr,
cbeeb5b7
RL
753 NULL
754};
755
756static const struct attribute_group vt8231_group = {
757 .attrs = vt8231_attributes,
758};
759
ec5e1a4b 760static struct platform_driver vt8231_driver = {
cdaf7934 761 .driver = {
87218842 762 .owner = THIS_MODULE,
cdaf7934
LR
763 .name = "vt8231",
764 },
ec5e1a4b 765 .probe = vt8231_probe,
9e5e9b7a 766 .remove = vt8231_remove,
1de9e371
RL
767};
768
600151b9 769static DEFINE_PCI_DEVICE_TABLE(vt8231_pci_ids) = {
1de9e371
RL
770 { PCI_DEVICE(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231_4) },
771 { 0, }
772};
773
774MODULE_DEVICE_TABLE(pci, vt8231_pci_ids);
775
6c931ae1 776static int vt8231_pci_probe(struct pci_dev *dev,
65fe5c79 777 const struct pci_device_id *id);
1de9e371
RL
778
779static struct pci_driver vt8231_pci_driver = {
780 .name = "vt8231",
781 .id_table = vt8231_pci_ids,
782 .probe = vt8231_pci_probe,
783};
784
a022fef5 785static int vt8231_probe(struct platform_device *pdev)
1de9e371 786{
ec5e1a4b 787 struct resource *res;
1de9e371
RL
788 struct vt8231_data *data;
789 int err = 0, i;
1de9e371
RL
790
791 /* Reserve the ISA region */
ec5e1a4b 792 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
7711f1bd
GR
793 if (!devm_request_region(&pdev->dev, res->start, VT8231_EXTENT,
794 vt8231_driver.driver.name)) {
ec5e1a4b
RL
795 dev_err(&pdev->dev, "Region 0x%lx-0x%lx already in use!\n",
796 (unsigned long)res->start, (unsigned long)res->end);
1de9e371
RL
797 return -ENODEV;
798 }
799
7711f1bd
GR
800 data = devm_kzalloc(&pdev->dev, sizeof(struct vt8231_data), GFP_KERNEL);
801 if (!data)
802 return -ENOMEM;
1de9e371 803
ec5e1a4b
RL
804 platform_set_drvdata(pdev, data);
805 data->addr = res->start;
806 data->name = "vt8231";
1de9e371 807
9a61bf63 808 mutex_init(&data->update_lock);
ec5e1a4b 809 vt8231_init_device(data);
1de9e371
RL
810
811 /* Register sysfs hooks */
65fe5c79
GR
812 err = sysfs_create_group(&pdev->dev.kobj, &vt8231_group);
813 if (err)
7711f1bd 814 return err;
1de9e371
RL
815
816 /* Must update device information to find out the config field */
ec5e1a4b 817 data->uch_config = vt8231_read_value(data, VT8231_REG_UCH_CONFIG);
1de9e371 818
cbeeb5b7 819 for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++) {
1de9e371 820 if (ISTEMP(i, data->uch_config)) {
65fe5c79
GR
821 err = sysfs_create_group(&pdev->dev.kobj,
822 &vt8231_group_temps[i]);
823 if (err)
cbeeb5b7 824 goto exit_remove_files;
1de9e371
RL
825 }
826 }
827
cbeeb5b7 828 for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++) {
1de9e371 829 if (ISVOLT(i, data->uch_config)) {
65fe5c79
GR
830 err = sysfs_create_group(&pdev->dev.kobj,
831 &vt8231_group_volts[i]);
832 if (err)
cbeeb5b7 833 goto exit_remove_files;
1de9e371
RL
834 }
835 }
836
1beeffe4
TJ
837 data->hwmon_dev = hwmon_device_register(&pdev->dev);
838 if (IS_ERR(data->hwmon_dev)) {
839 err = PTR_ERR(data->hwmon_dev);
cbeeb5b7
RL
840 goto exit_remove_files;
841 }
1de9e371
RL
842 return 0;
843
cbeeb5b7
RL
844exit_remove_files:
845 for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++)
ec5e1a4b 846 sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_volts[i]);
cbeeb5b7
RL
847
848 for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++)
ec5e1a4b
RL
849 sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_temps[i]);
850
851 sysfs_remove_group(&pdev->dev.kobj, &vt8231_group);
1de9e371
RL
852 return err;
853}
854
281dfd0b 855static int vt8231_remove(struct platform_device *pdev)
1de9e371 856{
ec5e1a4b
RL
857 struct vt8231_data *data = platform_get_drvdata(pdev);
858 int i;
1de9e371 859
1beeffe4 860 hwmon_device_unregister(data->hwmon_dev);
1de9e371 861
cbeeb5b7 862 for (i = 0; i < ARRAY_SIZE(vt8231_group_volts); i++)
ec5e1a4b 863 sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_volts[i]);
cbeeb5b7
RL
864
865 for (i = 0; i < ARRAY_SIZE(vt8231_group_temps); i++)
ec5e1a4b 866 sysfs_remove_group(&pdev->dev.kobj, &vt8231_group_temps[i]);
cbeeb5b7 867
ec5e1a4b 868 sysfs_remove_group(&pdev->dev.kobj, &vt8231_group);
cbeeb5b7 869
1de9e371
RL
870 return 0;
871}
872
ec5e1a4b 873static void vt8231_init_device(struct vt8231_data *data)
1de9e371 874{
ec5e1a4b
RL
875 vt8231_write_value(data, VT8231_REG_TEMP1_CONFIG, 0);
876 vt8231_write_value(data, VT8231_REG_TEMP2_CONFIG, 0);
1de9e371
RL
877}
878
879static struct vt8231_data *vt8231_update_device(struct device *dev)
880{
ec5e1a4b 881 struct vt8231_data *data = dev_get_drvdata(dev);
1de9e371
RL
882 int i;
883 u16 low;
884
9a61bf63 885 mutex_lock(&data->update_lock);
1de9e371
RL
886
887 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
888 || !data->valid) {
889 for (i = 0; i < 6; i++) {
890 if (ISVOLT(i, data->uch_config)) {
ec5e1a4b 891 data->in[i] = vt8231_read_value(data,
1de9e371 892 regvolt[i]);
ec5e1a4b 893 data->in_min[i] = vt8231_read_value(data,
1de9e371 894 regvoltmin[i]);
ec5e1a4b 895 data->in_max[i] = vt8231_read_value(data,
1de9e371
RL
896 regvoltmax[i]);
897 }
898 }
899 for (i = 0; i < 2; i++) {
ec5e1a4b 900 data->fan[i] = vt8231_read_value(data,
1de9e371 901 VT8231_REG_FAN(i));
ec5e1a4b 902 data->fan_min[i] = vt8231_read_value(data,
1de9e371
RL
903 VT8231_REG_FAN_MIN(i));
904 }
905
ec5e1a4b 906 low = vt8231_read_value(data, VT8231_REG_TEMP_LOW01);
1de9e371 907 low = (low >> 6) | ((low & 0x30) >> 2)
ec5e1a4b 908 | (vt8231_read_value(data, VT8231_REG_TEMP_LOW25) << 4);
1de9e371
RL
909 for (i = 0; i < 6; i++) {
910 if (ISTEMP(i, data->uch_config)) {
ec5e1a4b 911 data->temp[i] = (vt8231_read_value(data,
1de9e371
RL
912 regtemp[i]) << 2)
913 | ((low >> (2 * i)) & 0x03);
ec5e1a4b 914 data->temp_max[i] = vt8231_read_value(data,
1de9e371 915 regtempmax[i]);
ec5e1a4b 916 data->temp_min[i] = vt8231_read_value(data,
1de9e371
RL
917 regtempmin[i]);
918 }
919 }
920
ec5e1a4b 921 i = vt8231_read_value(data, VT8231_REG_FANDIV);
1de9e371
RL
922 data->fan_div[0] = (i >> 4) & 0x03;
923 data->fan_div[1] = i >> 6;
ec5e1a4b
RL
924 data->alarms = vt8231_read_value(data, VT8231_REG_ALARM1) |
925 (vt8231_read_value(data, VT8231_REG_ALARM2) << 8);
1de9e371
RL
926
927 /* Set alarm flags correctly */
65fe5c79 928 if (!data->fan[0] && data->fan_min[0])
1de9e371 929 data->alarms |= 0x40;
65fe5c79 930 else if (data->fan[0] && !data->fan_min[0])
1de9e371 931 data->alarms &= ~0x40;
1de9e371 932
65fe5c79 933 if (!data->fan[1] && data->fan_min[1])
1de9e371 934 data->alarms |= 0x80;
65fe5c79 935 else if (data->fan[1] && !data->fan_min[1])
1de9e371 936 data->alarms &= ~0x80;
1de9e371
RL
937
938 data->last_updated = jiffies;
939 data->valid = 1;
940 }
941
9a61bf63 942 mutex_unlock(&data->update_lock);
1de9e371
RL
943
944 return data;
945}
946
6c931ae1 947static int vt8231_device_add(unsigned short address)
ec5e1a4b
RL
948{
949 struct resource res = {
950 .start = address,
951 .end = address + VT8231_EXTENT - 1,
952 .name = "vt8231",
953 .flags = IORESOURCE_IO,
954 };
955 int err;
956
b9acb64a
JD
957 err = acpi_check_resource_conflict(&res);
958 if (err)
959 goto exit;
960
ec5e1a4b
RL
961 pdev = platform_device_alloc("vt8231", address);
962 if (!pdev) {
963 err = -ENOMEM;
9d72be0d 964 pr_err("Device allocation failed\n");
ec5e1a4b
RL
965 goto exit;
966 }
967
968 err = platform_device_add_resources(pdev, &res, 1);
969 if (err) {
9d72be0d 970 pr_err("Device resource addition failed (%d)\n", err);
ec5e1a4b
RL
971 goto exit_device_put;
972 }
973
974 err = platform_device_add(pdev);
975 if (err) {
9d72be0d 976 pr_err("Device addition failed (%d)\n", err);
ec5e1a4b
RL
977 goto exit_device_put;
978 }
979
980 return 0;
981
982exit_device_put:
983 platform_device_put(pdev);
984exit:
985 return err;
986}
987
6c931ae1 988static int vt8231_pci_probe(struct pci_dev *dev,
1de9e371
RL
989 const struct pci_device_id *id)
990{
ec5e1a4b
RL
991 u16 address, val;
992 if (force_addr) {
993 address = force_addr & 0xff00;
994 dev_warn(&dev->dev, "Forcing ISA address 0x%x\n",
995 address);
996
997 if (PCIBIOS_SUCCESSFUL !=
998 pci_write_config_word(dev, VT8231_BASE_REG, address | 1))
999 return -ENODEV;
1000 }
1de9e371
RL
1001
1002 if (PCIBIOS_SUCCESSFUL != pci_read_config_word(dev, VT8231_BASE_REG,
1003 &val))
1004 return -ENODEV;
1005
ec5e1a4b
RL
1006 address = val & ~(VT8231_EXTENT - 1);
1007 if (address == 0) {
4cae7878 1008 dev_err(&dev->dev, "base address not set - upgrade BIOS or use force_addr=0xaddr\n");
1de9e371
RL
1009 return -ENODEV;
1010 }
1011
ec5e1a4b
RL
1012 if (PCIBIOS_SUCCESSFUL != pci_read_config_word(dev, VT8231_ENABLE_REG,
1013 &val))
1014 return -ENODEV;
1de9e371 1015
ec5e1a4b
RL
1016 if (!(val & 0x0001)) {
1017 dev_warn(&dev->dev, "enabling sensors\n");
1018 if (PCIBIOS_SUCCESSFUL !=
1019 pci_write_config_word(dev, VT8231_ENABLE_REG,
1020 val | 0x0001))
1021 return -ENODEV;
1de9e371
RL
1022 }
1023
ec5e1a4b
RL
1024 if (platform_driver_register(&vt8231_driver))
1025 goto exit;
1026
1027 /* Sets global pdev as a side effect */
1028 if (vt8231_device_add(address))
1029 goto exit_unregister;
1030
61ba0318
GR
1031 /*
1032 * Always return failure here. This is to allow other drivers to bind
1de9e371
RL
1033 * to this pci device. We don't really want to have control over the
1034 * pci device, we only wanted to read as few register values from it.
1035 */
ec5e1a4b 1036
61ba0318
GR
1037 /*
1038 * We do, however, mark ourselves as using the PCI device to stop it
1039 * getting unloaded.
1040 */
ec5e1a4b
RL
1041 s_bridge = pci_dev_get(dev);
1042 return -ENODEV;
1043
1044exit_unregister:
1045 platform_driver_unregister(&vt8231_driver);
1046exit:
1de9e371
RL
1047 return -ENODEV;
1048}
1049
1050static int __init sm_vt8231_init(void)
1051{
93b47684 1052 return pci_register_driver(&vt8231_pci_driver);
1de9e371
RL
1053}
1054
1055static void __exit sm_vt8231_exit(void)
1056{
1057 pci_unregister_driver(&vt8231_pci_driver);
1058 if (s_bridge != NULL) {
ec5e1a4b
RL
1059 platform_device_unregister(pdev);
1060 platform_driver_unregister(&vt8231_driver);
1de9e371
RL
1061 pci_dev_put(s_bridge);
1062 s_bridge = NULL;
1063 }
1064}
1065
af865765 1066MODULE_AUTHOR("Roger Lucas <vt8231@hiddenengine.co.uk>");
1de9e371
RL
1067MODULE_DESCRIPTION("VT8231 sensors");
1068MODULE_LICENSE("GPL");
1069
1070module_init(sm_vt8231_init);
1071module_exit(sm_vt8231_exit);