blob: ad6c8a319903eeb8bf9fcd08950b0b58ddeba605 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 it87.c - Part of lm_sensors, Linux kernel modules for hardware
3 monitoring.
4
Bjorn Helgaas87b4b662008-01-22 07:21:03 -05005 The IT8705F is an LPC-based Super I/O part that contains UARTs, a
6 parallel port, an IR port, a MIDI port, a floppy controller, etc., in
7 addition to an Environment Controller (Enhanced Hardware Monitor and
8 Fan Controller)
9
10 This driver supports only the Environment Controller in the IT8705F and
11 similar parts. The other devices are supported by different drivers.
12
Jean Delvare91749992005-10-08 00:10:00 +020013 Supports: IT8705F Super I/O chip w/LPC interface
Jean Delvare8e9afcb2006-12-12 18:18:28 +010014 IT8712F Super I/O chip w/LPC interface
Jean Delvare17d648b2006-08-28 14:23:46 +020015 IT8716F Super I/O chip w/LPC interface
Jean Delvare87673dd2006-08-28 14:37:19 +020016 IT8718F Super I/O chip w/LPC interface
Rudolf Marek08a8f6e2007-06-09 10:11:16 -040017 IT8726F Super I/O chip w/LPC interface
Linus Torvalds1da177e2005-04-16 15:20:36 -070018 Sis950 A clone of the IT8705F
19
20 Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com>
Jean Delvareb19367c2006-08-28 14:39:26 +020021 Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
23 This program is free software; you can redistribute it and/or modify
24 it under the terms of the GNU General Public License as published by
25 the Free Software Foundation; either version 2 of the License, or
26 (at your option) any later version.
27
28 This program is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU General Public License for more details.
32
33 You should have received a copy of the GNU General Public License
34 along with this program; if not, write to the Free Software
35 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
36*/
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038#include <linux/module.h>
39#include <linux/init.h>
40#include <linux/slab.h>
41#include <linux/jiffies.h>
corentin.labbeb74f3fd2007-06-13 20:27:36 +020042#include <linux/platform_device.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040043#include <linux/hwmon.h>
Jean Delvare303760b2005-07-31 21:52:01 +020044#include <linux/hwmon-sysfs.h>
45#include <linux/hwmon-vid.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040046#include <linux/err.h>
Ingo Molnar9a61bf62006-01-18 23:19:26 +010047#include <linux/mutex.h>
Jean Delvare87808be2006-09-24 21:17:13 +020048#include <linux/sysfs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#include <asm/io.h>
50
corentin.labbeb74f3fd2007-06-13 20:27:36 +020051#define DRVNAME "it87"
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Jean Delvare8e9afcb2006-12-12 18:18:28 +010053enum chips { it87, it8712, it8716, it8718 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
corentin.labbeb74f3fd2007-06-13 20:27:36 +020055static struct platform_device *pdev;
56
Linus Torvalds1da177e2005-04-16 15:20:36 -070057#define REG 0x2e /* The register to read/write */
58#define DEV 0x07 /* Register: Logical device select */
59#define VAL 0x2f /* The value to read/write */
60#define PME 0x04 /* The device with the fan registers in it */
Jean Delvare87673dd2006-08-28 14:37:19 +020061#define GPIO 0x07 /* The device with the IT8718F VID value in it */
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#define DEVID 0x20 /* Register: Device ID */
63#define DEVREV 0x22 /* Register: Device Revision */
64
65static inline int
66superio_inb(int reg)
67{
68 outb(reg, REG);
69 return inb(VAL);
70}
71
72static int superio_inw(int reg)
73{
74 int val;
75 outb(reg++, REG);
76 val = inb(VAL) << 8;
77 outb(reg, REG);
78 val |= inb(VAL);
79 return val;
80}
81
82static inline void
Jean Delvare87673dd2006-08-28 14:37:19 +020083superio_select(int ldn)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084{
85 outb(DEV, REG);
Jean Delvare87673dd2006-08-28 14:37:19 +020086 outb(ldn, VAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087}
88
89static inline void
90superio_enter(void)
91{
92 outb(0x87, REG);
93 outb(0x01, REG);
94 outb(0x55, REG);
95 outb(0x55, REG);
96}
97
98static inline void
99superio_exit(void)
100{
101 outb(0x02, REG);
102 outb(0x02, VAL);
103}
104
Jean Delvare87673dd2006-08-28 14:37:19 +0200105/* Logical device 4 registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106#define IT8712F_DEVID 0x8712
107#define IT8705F_DEVID 0x8705
Jean Delvare17d648b2006-08-28 14:23:46 +0200108#define IT8716F_DEVID 0x8716
Jean Delvare87673dd2006-08-28 14:37:19 +0200109#define IT8718F_DEVID 0x8718
Rudolf Marek08a8f6e2007-06-09 10:11:16 -0400110#define IT8726F_DEVID 0x8726
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#define IT87_ACT_REG 0x30
112#define IT87_BASE_REG 0x60
113
Jean Delvare87673dd2006-08-28 14:37:19 +0200114/* Logical device 7 registers (IT8712F and later) */
115#define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
116#define IT87_SIO_VID_REG 0xfc /* VID value */
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118/* Update battery voltage after every reading if true */
119static int update_vbat;
120
121/* Not all BIOSes properly configure the PWM registers */
122static int fix_pwm_polarity;
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124/* Many IT87 constants specified below */
125
126/* Length of ISA address segment */
127#define IT87_EXTENT 8
128
Bjorn Helgaas87b4b662008-01-22 07:21:03 -0500129/* Length of ISA address segment for Environmental Controller */
130#define IT87_EC_EXTENT 2
131
132/* Offset of EC registers from ISA base address */
133#define IT87_EC_OFFSET 5
134
135/* Where are the ISA address/data registers relative to the EC base address */
136#define IT87_ADDR_REG_OFFSET 0
137#define IT87_DATA_REG_OFFSET 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139/*----- The IT87 registers -----*/
140
141#define IT87_REG_CONFIG 0x00
142
143#define IT87_REG_ALARM1 0x01
144#define IT87_REG_ALARM2 0x02
145#define IT87_REG_ALARM3 0x03
146
Jean Delvare87673dd2006-08-28 14:37:19 +0200147/* The IT8718F has the VID value in a different register, in Super-I/O
148 configuration space. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#define IT87_REG_VID 0x0a
Jean Delvare17d648b2006-08-28 14:23:46 +0200150/* Warning: register 0x0b is used for something completely different in
151 new chips/revisions. I suspect only 16-bit tachometer mode will work
152 for these. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153#define IT87_REG_FAN_DIV 0x0b
Jean Delvare17d648b2006-08-28 14:23:46 +0200154#define IT87_REG_FAN_16BIT 0x0c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156/* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
157
Jean Delvarec7f1f712007-09-03 17:11:46 +0200158static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
159static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 };
160static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 };
161static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162#define IT87_REG_FAN_MAIN_CTRL 0x13
163#define IT87_REG_FAN_CTL 0x14
164#define IT87_REG_PWM(nr) (0x15 + (nr))
165
166#define IT87_REG_VIN(nr) (0x20 + (nr))
167#define IT87_REG_TEMP(nr) (0x29 + (nr))
168
169#define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
170#define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
171#define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
172#define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174#define IT87_REG_VIN_ENABLE 0x50
175#define IT87_REG_TEMP_ENABLE 0x51
176
177#define IT87_REG_CHIPID 0x58
178
179#define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255))
180#define IN_FROM_REG(val) ((val) * 16)
181
182static inline u8 FAN_TO_REG(long rpm, int div)
183{
184 if (rpm == 0)
185 return 255;
186 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
187 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1,
188 254);
189}
190
Jean Delvare17d648b2006-08-28 14:23:46 +0200191static inline u16 FAN16_TO_REG(long rpm)
192{
193 if (rpm == 0)
194 return 0xffff;
195 return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
196}
197
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
Jean Delvare17d648b2006-08-28 14:23:46 +0200199/* The divider is fixed to 2 in 16-bit mode */
200#define FAN16_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:1350000/((val)*2))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\
203 ((val)+500)/1000),-128,127))
204#define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*1000)
205
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206#define PWM_TO_REG(val) ((val) >> 1)
207#define PWM_FROM_REG(val) (((val)&0x7f) << 1)
208
209static int DIV_TO_REG(int val)
210{
211 int answer = 0;
Jean Delvareb9e349f2006-08-28 14:26:22 +0200212 while (answer < 7 && (val >>= 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 answer++;
214 return answer;
215}
216#define DIV_FROM_REG(val) (1 << (val))
217
Jean Delvaref8d0c192007-02-14 21:15:02 +0100218static const unsigned int pwm_freq[8] = {
219 48000000 / 128,
220 24000000 / 128,
221 12000000 / 128,
222 8000000 / 128,
223 6000000 / 128,
224 3000000 / 128,
225 1500000 / 128,
226 750000 / 128,
227};
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200230struct it87_sio_data {
231 enum chips type;
232 /* Values read from Super-I/O config space */
233 u8 vid_value;
234};
235
Jean Delvareed6bafb2007-02-14 21:15:03 +0100236/* For each registered chip, we need to keep some data in memory.
237 The structure is dynamically allocated. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238struct it87_data {
Tony Jones1beeffe2007-08-20 13:46:20 -0700239 struct device *hwmon_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 enum chips type;
241
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200242 unsigned short addr;
243 const char *name;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100244 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 char valid; /* !=0 if following fields are valid */
246 unsigned long last_updated; /* In jiffies */
247
248 u8 in[9]; /* Register value */
Jean Delvare3543a532006-08-28 14:27:25 +0200249 u8 in_max[8]; /* Register value */
250 u8 in_min[8]; /* Register value */
Jean Delvare9060f8b2006-08-28 14:24:17 +0200251 u8 has_fan; /* Bitfield, fans enabled */
Jean Delvarec7f1f712007-09-03 17:11:46 +0200252 u16 fan[5]; /* Register values, possibly combined */
253 u16 fan_min[5]; /* Register values, possibly combined */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 u8 temp[3]; /* Register value */
255 u8 temp_high[3]; /* Register value */
256 u8 temp_low[3]; /* Register value */
257 u8 sensor; /* Register value */
258 u8 fan_div[3]; /* Register encoding, shifted right */
259 u8 vid; /* Register encoding, combined */
Jean Delvarea7be58a2005-12-18 16:40:14 +0100260 u8 vrm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 u32 alarms; /* Register encoding, combined */
262 u8 fan_main_ctrl; /* Register value */
Jean Delvaref8d0c192007-02-14 21:15:02 +0100263 u8 fan_ctl; /* Register value */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 u8 manual_pwm_ctl[3]; /* manual PWM value set by user */
265};
266
267
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200268static int it87_probe(struct platform_device *pdev);
Jean Delvared0546122007-07-22 12:09:48 +0200269static int __devexit it87_remove(struct platform_device *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200271static int it87_read_value(struct it87_data *data, u8 reg);
272static void it87_write_value(struct it87_data *data, u8 reg, u8 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273static struct it87_data *it87_update_device(struct device *dev);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200274static int it87_check_pwm(struct device *dev);
275static void it87_init_device(struct platform_device *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200278static struct platform_driver it87_driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100279 .driver = {
Jean Delvare87218842006-09-03 22:36:14 +0200280 .owner = THIS_MODULE,
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200281 .name = DRVNAME,
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100282 },
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200283 .probe = it87_probe,
284 .remove = __devexit_p(it87_remove),
Jean Delvarefde09502005-07-19 23:51:07 +0200285};
286
Jean Delvare20ad93d2005-06-05 11:53:25 +0200287static ssize_t show_in(struct device *dev, struct device_attribute *attr,
288 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200290 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
291 int nr = sensor_attr->index;
292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 struct it87_data *data = it87_update_device(dev);
294 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
295}
296
Jean Delvare20ad93d2005-06-05 11:53:25 +0200297static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
298 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200300 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
301 int nr = sensor_attr->index;
302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 struct it87_data *data = it87_update_device(dev);
304 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
305}
306
Jean Delvare20ad93d2005-06-05 11:53:25 +0200307static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
308 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200310 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
311 int nr = sensor_attr->index;
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 struct it87_data *data = it87_update_device(dev);
314 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
315}
316
Jean Delvare20ad93d2005-06-05 11:53:25 +0200317static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
318 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200320 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
321 int nr = sensor_attr->index;
322
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200323 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 unsigned long val = simple_strtoul(buf, NULL, 10);
325
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100326 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 data->in_min[nr] = IN_TO_REG(val);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200328 it87_write_value(data, IT87_REG_VIN_MIN(nr),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 data->in_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100330 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 return count;
332}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200333static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
334 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200336 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
337 int nr = sensor_attr->index;
338
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200339 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 unsigned long val = simple_strtoul(buf, NULL, 10);
341
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100342 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 data->in_max[nr] = IN_TO_REG(val);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200344 it87_write_value(data, IT87_REG_VIN_MAX(nr),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 data->in_max[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100346 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 return count;
348}
349
350#define show_in_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200351static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
352 show_in, NULL, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353
354#define limit_in_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200355static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
356 show_in_min, set_in_min, offset); \
357static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
358 show_in_max, set_in_max, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
360show_in_offset(0);
361limit_in_offset(0);
362show_in_offset(1);
363limit_in_offset(1);
364show_in_offset(2);
365limit_in_offset(2);
366show_in_offset(3);
367limit_in_offset(3);
368show_in_offset(4);
369limit_in_offset(4);
370show_in_offset(5);
371limit_in_offset(5);
372show_in_offset(6);
373limit_in_offset(6);
374show_in_offset(7);
375limit_in_offset(7);
376show_in_offset(8);
377
378/* 3 temperatures */
Jean Delvare20ad93d2005-06-05 11:53:25 +0200379static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
380 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200382 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
383 int nr = sensor_attr->index;
384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 struct it87_data *data = it87_update_device(dev);
386 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
387}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200388static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
389 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200391 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
392 int nr = sensor_attr->index;
393
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 struct it87_data *data = it87_update_device(dev);
395 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr]));
396}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200397static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
398 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200400 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
401 int nr = sensor_attr->index;
402
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 struct it87_data *data = it87_update_device(dev);
404 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr]));
405}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200406static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
407 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200409 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
410 int nr = sensor_attr->index;
411
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200412 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 int val = simple_strtol(buf, NULL, 10);
414
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100415 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 data->temp_high[nr] = TEMP_TO_REG(val);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200417 it87_write_value(data, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100418 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 return count;
420}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200421static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
422 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200424 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
425 int nr = sensor_attr->index;
426
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200427 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428 int val = simple_strtol(buf, NULL, 10);
429
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100430 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 data->temp_low[nr] = TEMP_TO_REG(val);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200432 it87_write_value(data, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100433 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 return count;
435}
436#define show_temp_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200437static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
438 show_temp, NULL, offset - 1); \
439static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
440 show_temp_max, set_temp_max, offset - 1); \
441static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
442 show_temp_min, set_temp_min, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
444show_temp_offset(1);
445show_temp_offset(2);
446show_temp_offset(3);
447
Jean Delvare20ad93d2005-06-05 11:53:25 +0200448static ssize_t show_sensor(struct device *dev, struct device_attribute *attr,
449 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200451 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
452 int nr = sensor_attr->index;
453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 struct it87_data *data = it87_update_device(dev);
455 u8 reg = data->sensor; /* In case the value is updated while we use it */
456
457 if (reg & (1 << nr))
458 return sprintf(buf, "3\n"); /* thermal diode */
459 if (reg & (8 << nr))
460 return sprintf(buf, "2\n"); /* thermistor */
461 return sprintf(buf, "0\n"); /* disabled */
462}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200463static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
464 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200466 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
467 int nr = sensor_attr->index;
468
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200469 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 int val = simple_strtol(buf, NULL, 10);
471
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100472 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473
474 data->sensor &= ~(1 << nr);
475 data->sensor &= ~(8 << nr);
476 /* 3 = thermal diode; 2 = thermistor; 0 = disabled */
477 if (val == 3)
478 data->sensor |= 1 << nr;
479 else if (val == 2)
480 data->sensor |= 8 << nr;
481 else if (val != 0) {
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100482 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 return -EINVAL;
484 }
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200485 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100486 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 return count;
488}
489#define show_sensor_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200490static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
491 show_sensor, set_sensor, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
493show_sensor_offset(1);
494show_sensor_offset(2);
495show_sensor_offset(3);
496
497/* 3 Fans */
Jean Delvare20ad93d2005-06-05 11:53:25 +0200498static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
499 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200501 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
502 int nr = sensor_attr->index;
503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 struct it87_data *data = it87_update_device(dev);
505 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
506 DIV_FROM_REG(data->fan_div[nr])));
507}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200508static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
509 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200511 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
512 int nr = sensor_attr->index;
513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 struct it87_data *data = it87_update_device(dev);
515 return sprintf(buf,"%d\n",
516 FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])));
517}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200518static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
519 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200521 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
522 int nr = sensor_attr->index;
523
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 struct it87_data *data = it87_update_device(dev);
525 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
526}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200527static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr,
528 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200530 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
531 int nr = sensor_attr->index;
532
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 struct it87_data *data = it87_update_device(dev);
534 return sprintf(buf,"%d\n", (data->fan_main_ctrl & (1 << nr)) ? 1 : 0);
535}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200536static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
537 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200539 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
540 int nr = sensor_attr->index;
541
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 struct it87_data *data = it87_update_device(dev);
543 return sprintf(buf,"%d\n", data->manual_pwm_ctl[nr]);
544}
Jean Delvaref8d0c192007-02-14 21:15:02 +0100545static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
546 char *buf)
547{
548 struct it87_data *data = it87_update_device(dev);
549 int index = (data->fan_ctl >> 4) & 0x07;
550
551 return sprintf(buf, "%u\n", pwm_freq[index]);
552}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200553static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
554 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200556 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
557 int nr = sensor_attr->index;
558
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200559 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 int val = simple_strtol(buf, NULL, 10);
Jean Delvare7f999aa2007-02-14 21:15:03 +0100561 u8 reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100563 mutex_lock(&data->update_lock);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200564 reg = it87_read_value(data, IT87_REG_FAN_DIV);
Jean Delvare07eab462005-11-23 15:44:31 -0800565 switch (nr) {
566 case 0: data->fan_div[nr] = reg & 0x07; break;
567 case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break;
568 case 2: data->fan_div[nr] = (reg & 0x40) ? 3 : 1; break;
569 }
570
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
Jean Delvarec7f1f712007-09-03 17:11:46 +0200572 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100573 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 return count;
575}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200576static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
577 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200579 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
580 int nr = sensor_attr->index;
581
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200582 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvareb9e349f2006-08-28 14:26:22 +0200583 unsigned long val = simple_strtoul(buf, NULL, 10);
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200584 int min;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 u8 old;
586
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100587 mutex_lock(&data->update_lock);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200588 old = it87_read_value(data, IT87_REG_FAN_DIV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200590 /* Save fan min limit */
591 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
593 switch (nr) {
594 case 0:
595 case 1:
596 data->fan_div[nr] = DIV_TO_REG(val);
597 break;
598 case 2:
599 if (val < 8)
600 data->fan_div[nr] = 1;
601 else
602 data->fan_div[nr] = 3;
603 }
604 val = old & 0x80;
605 val |= (data->fan_div[0] & 0x07);
606 val |= (data->fan_div[1] & 0x07) << 3;
607 if (data->fan_div[2] == 3)
608 val |= 0x1 << 6;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200609 it87_write_value(data, IT87_REG_FAN_DIV, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200611 /* Restore fan min limit */
612 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
Jean Delvarec7f1f712007-09-03 17:11:46 +0200613 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]);
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200614
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100615 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 return count;
617}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200618static ssize_t set_pwm_enable(struct device *dev,
619 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200621 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
622 int nr = sensor_attr->index;
623
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200624 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 int val = simple_strtol(buf, NULL, 10);
626
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100627 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
629 if (val == 0) {
630 int tmp;
631 /* make sure the fan is on when in on/off mode */
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200632 tmp = it87_read_value(data, IT87_REG_FAN_CTL);
633 it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 /* set on/off mode */
635 data->fan_main_ctrl &= ~(1 << nr);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200636 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 } else if (val == 1) {
638 /* set SmartGuardian mode */
639 data->fan_main_ctrl |= (1 << nr);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200640 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 /* set saved pwm value, clear FAN_CTLX PWM mode bit */
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200642 it87_write_value(data, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 } else {
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100644 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 return -EINVAL;
646 }
647
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100648 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 return count;
650}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200651static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
652 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200654 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
655 int nr = sensor_attr->index;
656
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200657 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 int val = simple_strtol(buf, NULL, 10);
659
660 if (val < 0 || val > 255)
661 return -EINVAL;
662
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100663 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 data->manual_pwm_ctl[nr] = val;
665 if (data->fan_main_ctrl & (1 << nr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200666 it87_write_value(data, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100667 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 return count;
669}
Jean Delvaref8d0c192007-02-14 21:15:02 +0100670static ssize_t set_pwm_freq(struct device *dev,
671 struct device_attribute *attr, const char *buf, size_t count)
672{
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200673 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref8d0c192007-02-14 21:15:02 +0100674 unsigned long val = simple_strtoul(buf, NULL, 10);
675 int i;
676
677 /* Search for the nearest available frequency */
678 for (i = 0; i < 7; i++) {
679 if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
680 break;
681 }
682
683 mutex_lock(&data->update_lock);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200684 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
Jean Delvaref8d0c192007-02-14 21:15:02 +0100685 data->fan_ctl |= i << 4;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200686 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
Jean Delvaref8d0c192007-02-14 21:15:02 +0100687 mutex_unlock(&data->update_lock);
688
689 return count;
690}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691
Jean Delvare20ad93d2005-06-05 11:53:25 +0200692#define show_fan_offset(offset) \
693static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
694 show_fan, NULL, offset - 1); \
695static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
696 show_fan_min, set_fan_min, offset - 1); \
697static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
698 show_fan_div, set_fan_div, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699
700show_fan_offset(1);
701show_fan_offset(2);
702show_fan_offset(3);
703
704#define show_pwm_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200705static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
706 show_pwm_enable, set_pwm_enable, offset - 1); \
707static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
Jean Delvaref8d0c192007-02-14 21:15:02 +0100708 show_pwm, set_pwm, offset - 1); \
709static DEVICE_ATTR(pwm##offset##_freq, \
710 (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \
711 show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712
713show_pwm_offset(1);
714show_pwm_offset(2);
715show_pwm_offset(3);
716
Jean Delvare17d648b2006-08-28 14:23:46 +0200717/* A different set of callbacks for 16-bit fans */
718static ssize_t show_fan16(struct device *dev, struct device_attribute *attr,
719 char *buf)
720{
721 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
722 int nr = sensor_attr->index;
723 struct it87_data *data = it87_update_device(dev);
724 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan[nr]));
725}
726
727static ssize_t show_fan16_min(struct device *dev, struct device_attribute *attr,
728 char *buf)
729{
730 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
731 int nr = sensor_attr->index;
732 struct it87_data *data = it87_update_device(dev);
733 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan_min[nr]));
734}
735
736static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
737 const char *buf, size_t count)
738{
739 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
740 int nr = sensor_attr->index;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200741 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvare17d648b2006-08-28 14:23:46 +0200742 int val = simple_strtol(buf, NULL, 10);
743
744 mutex_lock(&data->update_lock);
745 data->fan_min[nr] = FAN16_TO_REG(val);
Jean Delvarec7f1f712007-09-03 17:11:46 +0200746 it87_write_value(data, IT87_REG_FAN_MIN[nr],
Jean Delvare17d648b2006-08-28 14:23:46 +0200747 data->fan_min[nr] & 0xff);
Jean Delvarec7f1f712007-09-03 17:11:46 +0200748 it87_write_value(data, IT87_REG_FANX_MIN[nr],
Jean Delvare17d648b2006-08-28 14:23:46 +0200749 data->fan_min[nr] >> 8);
750 mutex_unlock(&data->update_lock);
751 return count;
752}
753
754/* We want to use the same sysfs file names as 8-bit fans, but we need
755 different variable names, so we have to use SENSOR_ATTR instead of
756 SENSOR_DEVICE_ATTR. */
757#define show_fan16_offset(offset) \
758static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
759 = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
760 show_fan16, NULL, offset - 1); \
761static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \
762 = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
763 show_fan16_min, set_fan16_min, offset - 1)
764
765show_fan16_offset(1);
766show_fan16_offset(2);
767show_fan16_offset(3);
Jean Delvarec7f1f712007-09-03 17:11:46 +0200768show_fan16_offset(4);
769show_fan16_offset(5);
Jean Delvare17d648b2006-08-28 14:23:46 +0200770
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771/* Alarms */
Yani Ioannou30f74292005-05-17 06:41:35 -0400772static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773{
774 struct it87_data *data = it87_update_device(dev);
Jean Delvare68188ba2005-05-16 18:52:38 +0200775 return sprintf(buf, "%u\n", data->alarms);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776}
Jean Delvare1d66c642005-04-18 21:16:59 -0700777static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779static ssize_t
Yani Ioannou30f74292005-05-17 06:41:35 -0400780show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781{
Jean Delvare90d66192007-10-08 18:24:35 +0200782 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvarea7be58a2005-12-18 16:40:14 +0100783 return sprintf(buf, "%u\n", data->vrm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784}
785static ssize_t
Yani Ioannou30f74292005-05-17 06:41:35 -0400786store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787{
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200788 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 u32 val;
790
791 val = simple_strtoul(buf, NULL, 10);
792 data->vrm = val;
793
794 return count;
795}
796static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
798static ssize_t
Yani Ioannou30f74292005-05-17 06:41:35 -0400799show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800{
801 struct it87_data *data = it87_update_device(dev);
802 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
803}
804static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
Jean Delvare87808be2006-09-24 21:17:13 +0200805
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200806static ssize_t show_name(struct device *dev, struct device_attribute
807 *devattr, char *buf)
808{
809 struct it87_data *data = dev_get_drvdata(dev);
810 return sprintf(buf, "%s\n", data->name);
811}
812static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
813
Jean Delvare87808be2006-09-24 21:17:13 +0200814static struct attribute *it87_attributes[] = {
815 &sensor_dev_attr_in0_input.dev_attr.attr,
816 &sensor_dev_attr_in1_input.dev_attr.attr,
817 &sensor_dev_attr_in2_input.dev_attr.attr,
818 &sensor_dev_attr_in3_input.dev_attr.attr,
819 &sensor_dev_attr_in4_input.dev_attr.attr,
820 &sensor_dev_attr_in5_input.dev_attr.attr,
821 &sensor_dev_attr_in6_input.dev_attr.attr,
822 &sensor_dev_attr_in7_input.dev_attr.attr,
823 &sensor_dev_attr_in8_input.dev_attr.attr,
824 &sensor_dev_attr_in0_min.dev_attr.attr,
825 &sensor_dev_attr_in1_min.dev_attr.attr,
826 &sensor_dev_attr_in2_min.dev_attr.attr,
827 &sensor_dev_attr_in3_min.dev_attr.attr,
828 &sensor_dev_attr_in4_min.dev_attr.attr,
829 &sensor_dev_attr_in5_min.dev_attr.attr,
830 &sensor_dev_attr_in6_min.dev_attr.attr,
831 &sensor_dev_attr_in7_min.dev_attr.attr,
832 &sensor_dev_attr_in0_max.dev_attr.attr,
833 &sensor_dev_attr_in1_max.dev_attr.attr,
834 &sensor_dev_attr_in2_max.dev_attr.attr,
835 &sensor_dev_attr_in3_max.dev_attr.attr,
836 &sensor_dev_attr_in4_max.dev_attr.attr,
837 &sensor_dev_attr_in5_max.dev_attr.attr,
838 &sensor_dev_attr_in6_max.dev_attr.attr,
839 &sensor_dev_attr_in7_max.dev_attr.attr,
840
841 &sensor_dev_attr_temp1_input.dev_attr.attr,
842 &sensor_dev_attr_temp2_input.dev_attr.attr,
843 &sensor_dev_attr_temp3_input.dev_attr.attr,
844 &sensor_dev_attr_temp1_max.dev_attr.attr,
845 &sensor_dev_attr_temp2_max.dev_attr.attr,
846 &sensor_dev_attr_temp3_max.dev_attr.attr,
847 &sensor_dev_attr_temp1_min.dev_attr.attr,
848 &sensor_dev_attr_temp2_min.dev_attr.attr,
849 &sensor_dev_attr_temp3_min.dev_attr.attr,
850 &sensor_dev_attr_temp1_type.dev_attr.attr,
851 &sensor_dev_attr_temp2_type.dev_attr.attr,
852 &sensor_dev_attr_temp3_type.dev_attr.attr,
853
854 &dev_attr_alarms.attr,
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200855 &dev_attr_name.attr,
Jean Delvare87808be2006-09-24 21:17:13 +0200856 NULL
857};
858
859static const struct attribute_group it87_group = {
860 .attrs = it87_attributes,
861};
862
863static struct attribute *it87_attributes_opt[] = {
864 &sensor_dev_attr_fan1_input16.dev_attr.attr,
865 &sensor_dev_attr_fan1_min16.dev_attr.attr,
866 &sensor_dev_attr_fan2_input16.dev_attr.attr,
867 &sensor_dev_attr_fan2_min16.dev_attr.attr,
868 &sensor_dev_attr_fan3_input16.dev_attr.attr,
869 &sensor_dev_attr_fan3_min16.dev_attr.attr,
Jean Delvarec7f1f712007-09-03 17:11:46 +0200870 &sensor_dev_attr_fan4_input16.dev_attr.attr,
871 &sensor_dev_attr_fan4_min16.dev_attr.attr,
872 &sensor_dev_attr_fan5_input16.dev_attr.attr,
873 &sensor_dev_attr_fan5_min16.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +0200874
875 &sensor_dev_attr_fan1_input.dev_attr.attr,
876 &sensor_dev_attr_fan1_min.dev_attr.attr,
877 &sensor_dev_attr_fan1_div.dev_attr.attr,
878 &sensor_dev_attr_fan2_input.dev_attr.attr,
879 &sensor_dev_attr_fan2_min.dev_attr.attr,
880 &sensor_dev_attr_fan2_div.dev_attr.attr,
881 &sensor_dev_attr_fan3_input.dev_attr.attr,
882 &sensor_dev_attr_fan3_min.dev_attr.attr,
883 &sensor_dev_attr_fan3_div.dev_attr.attr,
884
885 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
886 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
887 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
888 &sensor_dev_attr_pwm1.dev_attr.attr,
889 &sensor_dev_attr_pwm2.dev_attr.attr,
890 &sensor_dev_attr_pwm3.dev_attr.attr,
891
892 &dev_attr_vrm.attr,
893 &dev_attr_cpu0_vid.attr,
894 NULL
895};
896
897static const struct attribute_group it87_group_opt = {
898 .attrs = it87_attributes_opt,
899};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900
Jean Delvare2d8672c2005-07-19 23:56:35 +0200901/* SuperIO detection - will change isa_address if a chip is found */
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200902static int __init it87_find(unsigned short *address,
903 struct it87_sio_data *sio_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904{
905 int err = -ENODEV;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200906 u16 chip_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907
908 superio_enter();
909 chip_type = superio_inw(DEVID);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200910
911 switch (chip_type) {
912 case IT8705F_DEVID:
913 sio_data->type = it87;
914 break;
915 case IT8712F_DEVID:
916 sio_data->type = it8712;
917 break;
918 case IT8716F_DEVID:
919 case IT8726F_DEVID:
920 sio_data->type = it8716;
921 break;
922 case IT8718F_DEVID:
923 sio_data->type = it8718;
924 break;
925 case 0xffff: /* No device at all */
926 goto exit;
927 default:
928 pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%x)\n",
929 chip_type);
930 goto exit;
931 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
Jean Delvare87673dd2006-08-28 14:37:19 +0200933 superio_select(PME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
935 pr_info("it87: Device not activated, skipping\n");
936 goto exit;
937 }
938
939 *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
940 if (*address == 0) {
941 pr_info("it87: Base address not set, skipping\n");
942 goto exit;
943 }
944
945 err = 0;
946 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n",
947 chip_type, *address, superio_inb(DEVREV) & 0x0f);
948
Jean Delvare87673dd2006-08-28 14:37:19 +0200949 /* Read GPIO config and VID value from LDN 7 (GPIO) */
950 if (chip_type != IT8705F_DEVID) {
951 int reg;
952
953 superio_select(GPIO);
954 if (chip_type == it8718)
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200955 sio_data->vid_value = superio_inb(IT87_SIO_VID_REG);
Jean Delvare87673dd2006-08-28 14:37:19 +0200956
957 reg = superio_inb(IT87_SIO_PINX2_REG);
958 if (reg & (1 << 0))
959 pr_info("it87: in3 is VCC (+5V)\n");
960 if (reg & (1 << 1))
961 pr_info("it87: in7 is VCCH (+5V Stand-By)\n");
962 }
963
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964exit:
965 superio_exit();
966 return err;
967}
968
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200969static int __devinit it87_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 struct it87_data *data;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200972 struct resource *res;
973 struct device *dev = &pdev->dev;
974 struct it87_sio_data *sio_data = dev->platform_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 int enable_pwm_interface;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200977 static const char *names[] = {
978 "it87",
979 "it8712",
980 "it8716",
981 "it8718",
982 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200984 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
Bjorn Helgaas87b4b662008-01-22 07:21:03 -0500985 if (!request_region(res->start, IT87_EC_EXTENT, DRVNAME)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200986 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
987 (unsigned long)res->start,
Bjorn Helgaas87b4b662008-01-22 07:21:03 -0500988 (unsigned long)(res->start + IT87_EC_EXTENT - 1));
Jean Delvare8e9afcb2006-12-12 18:18:28 +0100989 err = -EBUSY;
990 goto ERROR0;
991 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992
Deepak Saxenaba9c2e82005-10-17 23:08:32 +0200993 if (!(data = kzalloc(sizeof(struct it87_data), GFP_KERNEL))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 err = -ENOMEM;
995 goto ERROR1;
996 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200998 data->addr = res->start;
999 data->type = sio_data->type;
1000 data->name = names[sio_data->type];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
1002 /* Now, we do the remaining detection. */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001003 if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)
1004 || it87_read_value(data, IT87_REG_CHIPID) != 0x90) {
Jean Delvare8e9afcb2006-12-12 18:18:28 +01001005 err = -ENODEV;
1006 goto ERROR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007 }
1008
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001009 platform_set_drvdata(pdev, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001011 mutex_init(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 /* Check PWM configuration */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001014 enable_pwm_interface = it87_check_pwm(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
1016 /* Initialize the IT87 chip */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001017 it87_init_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018
1019 /* Register sysfs hooks */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001020 if ((err = sysfs_create_group(&dev->kobj, &it87_group)))
1021 goto ERROR2;
Jean Delvare17d648b2006-08-28 14:23:46 +02001022
Jean Delvare9060f8b2006-08-28 14:24:17 +02001023 /* Do not create fan files for disabled fans */
Jean Delvare87673dd2006-08-28 14:37:19 +02001024 if (data->type == it8716 || data->type == it8718) {
1025 /* 16-bit tachometers */
Jean Delvare9060f8b2006-08-28 14:24:17 +02001026 if (data->has_fan & (1 << 0)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001027 if ((err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001028 &sensor_dev_attr_fan1_input16.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001029 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001030 &sensor_dev_attr_fan1_min16.dev_attr)))
1031 goto ERROR4;
Jean Delvare9060f8b2006-08-28 14:24:17 +02001032 }
1033 if (data->has_fan & (1 << 1)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001034 if ((err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001035 &sensor_dev_attr_fan2_input16.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001036 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001037 &sensor_dev_attr_fan2_min16.dev_attr)))
1038 goto ERROR4;
Jean Delvare9060f8b2006-08-28 14:24:17 +02001039 }
1040 if (data->has_fan & (1 << 2)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001041 if ((err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001042 &sensor_dev_attr_fan3_input16.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001043 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001044 &sensor_dev_attr_fan3_min16.dev_attr)))
1045 goto ERROR4;
Jean Delvare9060f8b2006-08-28 14:24:17 +02001046 }
Jean Delvarec7f1f712007-09-03 17:11:46 +02001047 if (data->has_fan & (1 << 3)) {
1048 if ((err = device_create_file(dev,
1049 &sensor_dev_attr_fan4_input16.dev_attr))
1050 || (err = device_create_file(dev,
1051 &sensor_dev_attr_fan4_min16.dev_attr)))
1052 goto ERROR4;
1053 }
1054 if (data->has_fan & (1 << 4)) {
1055 if ((err = device_create_file(dev,
1056 &sensor_dev_attr_fan5_input16.dev_attr))
1057 || (err = device_create_file(dev,
1058 &sensor_dev_attr_fan5_min16.dev_attr)))
1059 goto ERROR4;
1060 }
Jean Delvare17d648b2006-08-28 14:23:46 +02001061 } else {
Jean Delvare87673dd2006-08-28 14:37:19 +02001062 /* 8-bit tachometers with clock divider */
Jean Delvare9060f8b2006-08-28 14:24:17 +02001063 if (data->has_fan & (1 << 0)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001064 if ((err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001065 &sensor_dev_attr_fan1_input.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001066 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001067 &sensor_dev_attr_fan1_min.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001068 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001069 &sensor_dev_attr_fan1_div.dev_attr)))
1070 goto ERROR4;
Jean Delvare9060f8b2006-08-28 14:24:17 +02001071 }
1072 if (data->has_fan & (1 << 1)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001073 if ((err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001074 &sensor_dev_attr_fan2_input.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001075 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001076 &sensor_dev_attr_fan2_min.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001077 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001078 &sensor_dev_attr_fan2_div.dev_attr)))
1079 goto ERROR4;
Jean Delvare9060f8b2006-08-28 14:24:17 +02001080 }
1081 if (data->has_fan & (1 << 2)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001082 if ((err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001083 &sensor_dev_attr_fan3_input.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001084 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001085 &sensor_dev_attr_fan3_min.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001086 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001087 &sensor_dev_attr_fan3_div.dev_attr)))
1088 goto ERROR4;
Jean Delvare9060f8b2006-08-28 14:24:17 +02001089 }
Jean Delvare17d648b2006-08-28 14:23:46 +02001090 }
1091
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 if (enable_pwm_interface) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001093 if ((err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001094 &sensor_dev_attr_pwm1_enable.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001095 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001096 &sensor_dev_attr_pwm2_enable.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001097 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001098 &sensor_dev_attr_pwm3_enable.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001099 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001100 &sensor_dev_attr_pwm1.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001101 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001102 &sensor_dev_attr_pwm2.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001103 || (err = device_create_file(dev,
Jean Delvaref8d0c192007-02-14 21:15:02 +01001104 &sensor_dev_attr_pwm3.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001105 || (err = device_create_file(dev,
Jean Delvaref8d0c192007-02-14 21:15:02 +01001106 &dev_attr_pwm1_freq))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001107 || (err = device_create_file(dev,
Jean Delvaref8d0c192007-02-14 21:15:02 +01001108 &dev_attr_pwm2_freq))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001109 || (err = device_create_file(dev,
Jean Delvaref8d0c192007-02-14 21:15:02 +01001110 &dev_attr_pwm3_freq)))
Jean Delvare87808be2006-09-24 21:17:13 +02001111 goto ERROR4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112 }
1113
Jean Delvare87673dd2006-08-28 14:37:19 +02001114 if (data->type == it8712 || data->type == it8716
1115 || data->type == it8718) {
Jean Delvare303760b2005-07-31 21:52:01 +02001116 data->vrm = vid_which_vrm();
Jean Delvare87673dd2006-08-28 14:37:19 +02001117 /* VID reading from Super-I/O config space if available */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001118 data->vid = sio_data->vid_value;
1119 if ((err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001120 &dev_attr_vrm))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001121 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001122 &dev_attr_cpu0_vid)))
1123 goto ERROR4;
1124 }
1125
Tony Jones1beeffe2007-08-20 13:46:20 -07001126 data->hwmon_dev = hwmon_device_register(dev);
1127 if (IS_ERR(data->hwmon_dev)) {
1128 err = PTR_ERR(data->hwmon_dev);
Jean Delvare87808be2006-09-24 21:17:13 +02001129 goto ERROR4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 }
1131
1132 return 0;
1133
Jean Delvare87808be2006-09-24 21:17:13 +02001134ERROR4:
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001135 sysfs_remove_group(&dev->kobj, &it87_group);
1136 sysfs_remove_group(&dev->kobj, &it87_group_opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137ERROR2:
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001138 platform_set_drvdata(pdev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 kfree(data);
1140ERROR1:
Bjorn Helgaas87b4b662008-01-22 07:21:03 -05001141 release_region(res->start, IT87_EC_EXTENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142ERROR0:
1143 return err;
1144}
1145
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001146static int __devexit it87_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001148 struct it87_data *data = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
Tony Jones1beeffe2007-08-20 13:46:20 -07001150 hwmon_device_unregister(data->hwmon_dev);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001151 sysfs_remove_group(&pdev->dev.kobj, &it87_group);
1152 sysfs_remove_group(&pdev->dev.kobj, &it87_group_opt);
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001153
Bjorn Helgaas87b4b662008-01-22 07:21:03 -05001154 release_region(data->addr, IT87_EC_EXTENT);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001155 platform_set_drvdata(pdev, NULL);
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001156 kfree(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
1158 return 0;
1159}
1160
Jean Delvare7f999aa2007-02-14 21:15:03 +01001161/* Must be called with data->update_lock held, except during initialization.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1163 would slow down the IT87 access and should not be necessary. */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001164static int it87_read_value(struct it87_data *data, u8 reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001166 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
1167 return inb_p(data->addr + IT87_DATA_REG_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168}
1169
Jean Delvare7f999aa2007-02-14 21:15:03 +01001170/* Must be called with data->update_lock held, except during initialization.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1172 would slow down the IT87 access and should not be necessary. */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001173static void it87_write_value(struct it87_data *data, u8 reg, u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001175 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
1176 outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177}
1178
1179/* Return 1 if and only if the PWM interface is safe to use */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001180static int __devinit it87_check_pwm(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001182 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 /* Some BIOSes fail to correctly configure the IT87 fans. All fans off
1184 * and polarity set to active low is sign that this is the case so we
1185 * disable pwm control to protect the user. */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001186 int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 if ((tmp & 0x87) == 0) {
1188 if (fix_pwm_polarity) {
1189 /* The user asks us to attempt a chip reconfiguration.
1190 * This means switching to active high polarity and
1191 * inverting all fan speed values. */
1192 int i;
1193 u8 pwm[3];
1194
1195 for (i = 0; i < 3; i++)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001196 pwm[i] = it87_read_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197 IT87_REG_PWM(i));
1198
1199 /* If any fan is in automatic pwm mode, the polarity
1200 * might be correct, as suspicious as it seems, so we
1201 * better don't change anything (but still disable the
1202 * PWM interface). */
1203 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001204 dev_info(dev, "Reconfiguring PWM to "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 "active high polarity\n");
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001206 it87_write_value(data, IT87_REG_FAN_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 tmp | 0x87);
1208 for (i = 0; i < 3; i++)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001209 it87_write_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 IT87_REG_PWM(i),
1211 0x7f & ~pwm[i]);
1212 return 1;
1213 }
1214
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001215 dev_info(dev, "PWM configuration is "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216 "too broken to be fixed\n");
1217 }
1218
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001219 dev_info(dev, "Detected broken BIOS "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 "defaults, disabling PWM interface\n");
1221 return 0;
1222 } else if (fix_pwm_polarity) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001223 dev_info(dev, "PWM configuration looks "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 "sane, won't touch\n");
1225 }
1226
1227 return 1;
1228}
1229
1230/* Called when we have found a new IT87. */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001231static void __devinit it87_init_device(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001233 struct it87_data *data = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234 int tmp, i;
1235
1236 /* initialize to sane defaults:
1237 * - if the chip is in manual pwm mode, this will be overwritten with
1238 * the actual settings on the chip (so in this case, initialization
1239 * is not needed)
1240 * - if in automatic or on/off mode, we could switch to manual mode,
1241 * read the registers and set manual_pwm_ctl accordingly, but currently
1242 * this is not implemented, so we initialize to something sane */
1243 for (i = 0; i < 3; i++) {
1244 data->manual_pwm_ctl[i] = 0xff;
1245 }
1246
Jean Delvarec5df9b72006-08-28 14:37:54 +02001247 /* Some chips seem to have default value 0xff for all limit
1248 * registers. For low voltage limits it makes no sense and triggers
1249 * alarms, so change to 0 instead. For high temperature limits, it
1250 * means -1 degree C, which surprisingly doesn't trigger an alarm,
1251 * but is still confusing, so change to 127 degrees C. */
1252 for (i = 0; i < 8; i++) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001253 tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
Jean Delvarec5df9b72006-08-28 14:37:54 +02001254 if (tmp == 0xff)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001255 it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
Jean Delvarec5df9b72006-08-28 14:37:54 +02001256 }
1257 for (i = 0; i < 3; i++) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001258 tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i));
Jean Delvarec5df9b72006-08-28 14:37:54 +02001259 if (tmp == 0xff)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001260 it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127);
Jean Delvarec5df9b72006-08-28 14:37:54 +02001261 }
1262
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 /* Check if temperature channnels are reset manually or by some reason */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001264 tmp = it87_read_value(data, IT87_REG_TEMP_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 if ((tmp & 0x3f) == 0) {
1266 /* Temp1,Temp3=thermistor; Temp2=thermal diode */
1267 tmp = (tmp & 0xc0) | 0x2a;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001268 it87_write_value(data, IT87_REG_TEMP_ENABLE, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 }
1270 data->sensor = tmp;
1271
1272 /* Check if voltage monitors are reset manually or by some reason */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001273 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 if ((tmp & 0xff) == 0) {
1275 /* Enable all voltage monitors */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001276 it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 }
1278
1279 /* Check if tachometers are reset manually or by some reason */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001280 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 if ((data->fan_main_ctrl & 0x70) == 0) {
1282 /* Enable all fan tachometers */
1283 data->fan_main_ctrl |= 0x70;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001284 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 }
Jean Delvare9060f8b2006-08-28 14:24:17 +02001286 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
Jean Delvare17d648b2006-08-28 14:23:46 +02001288 /* Set tachometers to 16-bit mode if needed */
Jean Delvare87673dd2006-08-28 14:37:19 +02001289 if (data->type == it8716 || data->type == it8718) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001290 tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
Jean Delvare9060f8b2006-08-28 14:24:17 +02001291 if (~tmp & 0x07 & data->has_fan) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001292 dev_dbg(&pdev->dev,
Jean Delvare17d648b2006-08-28 14:23:46 +02001293 "Setting fan1-3 to 16-bit mode\n");
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001294 it87_write_value(data, IT87_REG_FAN_16BIT,
Jean Delvare17d648b2006-08-28 14:23:46 +02001295 tmp | 0x07);
1296 }
Jean Delvarec7f1f712007-09-03 17:11:46 +02001297 if (tmp & (1 << 4))
1298 data->has_fan |= (1 << 3); /* fan4 enabled */
1299 if (tmp & (1 << 5))
1300 data->has_fan |= (1 << 4); /* fan5 enabled */
Jean Delvare17d648b2006-08-28 14:23:46 +02001301 }
1302
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 /* Set current fan mode registers and the default settings for the
1304 * other mode registers */
1305 for (i = 0; i < 3; i++) {
1306 if (data->fan_main_ctrl & (1 << i)) {
1307 /* pwm mode */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001308 tmp = it87_read_value(data, IT87_REG_PWM(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 if (tmp & 0x80) {
1310 /* automatic pwm - not yet implemented, but
1311 * leave the settings made by the BIOS alone
1312 * until a change is requested via the sysfs
1313 * interface */
1314 } else {
1315 /* manual pwm */
1316 data->manual_pwm_ctl[i] = PWM_FROM_REG(tmp);
1317 }
1318 }
1319 }
1320
1321 /* Start monitoring */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001322 it87_write_value(data, IT87_REG_CONFIG,
1323 (it87_read_value(data, IT87_REG_CONFIG) & 0x36)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 | (update_vbat ? 0x41 : 0x01));
1325}
1326
1327static struct it87_data *it87_update_device(struct device *dev)
1328{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001329 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 int i;
1331
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001332 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
1334 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
1335 || !data->valid) {
1336
1337 if (update_vbat) {
1338 /* Cleared after each update, so reenable. Value
1339 returned by this read will be previous value */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001340 it87_write_value(data, IT87_REG_CONFIG,
1341 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001342 }
1343 for (i = 0; i <= 7; i++) {
1344 data->in[i] =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001345 it87_read_value(data, IT87_REG_VIN(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 data->in_min[i] =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001347 it87_read_value(data, IT87_REG_VIN_MIN(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348 data->in_max[i] =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001349 it87_read_value(data, IT87_REG_VIN_MAX(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350 }
Jean Delvare3543a532006-08-28 14:27:25 +02001351 /* in8 (battery) has no limit registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 data->in[8] =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001353 it87_read_value(data, IT87_REG_VIN(8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354
Jean Delvarec7f1f712007-09-03 17:11:46 +02001355 for (i = 0; i < 5; i++) {
Jean Delvare9060f8b2006-08-28 14:24:17 +02001356 /* Skip disabled fans */
1357 if (!(data->has_fan & (1 << i)))
1358 continue;
1359
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 data->fan_min[i] =
Jean Delvarec7f1f712007-09-03 17:11:46 +02001361 it87_read_value(data, IT87_REG_FAN_MIN[i]);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001362 data->fan[i] = it87_read_value(data,
Jean Delvarec7f1f712007-09-03 17:11:46 +02001363 IT87_REG_FAN[i]);
Jean Delvare17d648b2006-08-28 14:23:46 +02001364 /* Add high byte if in 16-bit mode */
Jean Delvare87673dd2006-08-28 14:37:19 +02001365 if (data->type == it8716 || data->type == it8718) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001366 data->fan[i] |= it87_read_value(data,
Jean Delvarec7f1f712007-09-03 17:11:46 +02001367 IT87_REG_FANX[i]) << 8;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001368 data->fan_min[i] |= it87_read_value(data,
Jean Delvarec7f1f712007-09-03 17:11:46 +02001369 IT87_REG_FANX_MIN[i]) << 8;
Jean Delvare17d648b2006-08-28 14:23:46 +02001370 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371 }
1372 for (i = 0; i < 3; i++) {
1373 data->temp[i] =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001374 it87_read_value(data, IT87_REG_TEMP(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 data->temp_high[i] =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001376 it87_read_value(data, IT87_REG_TEMP_HIGH(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377 data->temp_low[i] =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001378 it87_read_value(data, IT87_REG_TEMP_LOW(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 }
1380
Jean Delvare17d648b2006-08-28 14:23:46 +02001381 /* Newer chips don't have clock dividers */
Jean Delvare87673dd2006-08-28 14:37:19 +02001382 if ((data->has_fan & 0x07) && data->type != it8716
1383 && data->type != it8718) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001384 i = it87_read_value(data, IT87_REG_FAN_DIV);
Jean Delvare17d648b2006-08-28 14:23:46 +02001385 data->fan_div[0] = i & 0x07;
1386 data->fan_div[1] = (i >> 3) & 0x07;
1387 data->fan_div[2] = (i & 0x40) ? 3 : 1;
1388 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389
1390 data->alarms =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001391 it87_read_value(data, IT87_REG_ALARM1) |
1392 (it87_read_value(data, IT87_REG_ALARM2) << 8) |
1393 (it87_read_value(data, IT87_REG_ALARM3) << 16);
1394 data->fan_main_ctrl = it87_read_value(data,
1395 IT87_REG_FAN_MAIN_CTRL);
1396 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001398 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 /* The 8705 does not have VID capability */
Jean Delvare17d648b2006-08-28 14:23:46 +02001400 if (data->type == it8712 || data->type == it8716) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001401 data->vid = it87_read_value(data, IT87_REG_VID);
Jean Delvare17d648b2006-08-28 14:23:46 +02001402 /* The older IT8712F revisions had only 5 VID pins,
1403 but we assume it is always safe to read 6 bits. */
1404 data->vid &= 0x3f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 }
1406 data->last_updated = jiffies;
1407 data->valid = 1;
1408 }
1409
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001410 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411
1412 return data;
1413}
1414
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001415static int __init it87_device_add(unsigned short address,
1416 const struct it87_sio_data *sio_data)
1417{
1418 struct resource res = {
Bjorn Helgaas87b4b662008-01-22 07:21:03 -05001419 .start = address + IT87_EC_OFFSET,
1420 .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1,
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001421 .name = DRVNAME,
1422 .flags = IORESOURCE_IO,
1423 };
1424 int err;
1425
1426 pdev = platform_device_alloc(DRVNAME, address);
1427 if (!pdev) {
1428 err = -ENOMEM;
1429 printk(KERN_ERR DRVNAME ": Device allocation failed\n");
1430 goto exit;
1431 }
1432
1433 err = platform_device_add_resources(pdev, &res, 1);
1434 if (err) {
1435 printk(KERN_ERR DRVNAME ": Device resource addition failed "
1436 "(%d)\n", err);
1437 goto exit_device_put;
1438 }
1439
1440 err = platform_device_add_data(pdev, sio_data,
1441 sizeof(struct it87_sio_data));
1442 if (err) {
1443 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n");
1444 goto exit_device_put;
1445 }
1446
1447 err = platform_device_add(pdev);
1448 if (err) {
1449 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
1450 err);
1451 goto exit_device_put;
1452 }
1453
1454 return 0;
1455
1456exit_device_put:
1457 platform_device_put(pdev);
1458exit:
1459 return err;
1460}
1461
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462static int __init sm_it87_init(void)
1463{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001464 int err;
1465 unsigned short isa_address=0;
1466 struct it87_sio_data sio_data;
Jean Delvarefde09502005-07-19 23:51:07 +02001467
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001468 err = it87_find(&isa_address, &sio_data);
1469 if (err)
1470 return err;
1471 err = platform_driver_register(&it87_driver);
1472 if (err)
1473 return err;
1474
1475 err = it87_device_add(isa_address, &sio_data);
1476 if (err){
1477 platform_driver_unregister(&it87_driver);
1478 return err;
1479 }
1480
1481 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482}
1483
1484static void __exit sm_it87_exit(void)
1485{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001486 platform_device_unregister(pdev);
1487 platform_driver_unregister(&it87_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488}
1489
1490
Jean Delvareb19367c2006-08-28 14:39:26 +02001491MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>, "
1492 "Jean Delvare <khali@linux-fr.org>");
Rudolf Marek08a8f6e2007-06-09 10:11:16 -04001493MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8726F, SiS950 driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494module_param(update_vbat, bool, 0);
1495MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
1496module_param(fix_pwm_polarity, bool, 0);
1497MODULE_PARM_DESC(fix_pwm_polarity, "Force PWM polarity to active high (DANGEROUS)");
1498MODULE_LICENSE("GPL");
1499
1500module_init(sm_it87_init);
1501module_exit(sm_it87_exit);