blob: 6a182e14cf589d59f7a5d8e244b8aa9c34c0409d [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
Jean Delvare91749992005-10-08 00:10:00 +02005 Supports: IT8705F Super I/O chip w/LPC interface
Jean Delvare8e9afcb2006-12-12 18:18:28 +01006 IT8712F Super I/O chip w/LPC interface
Jean Delvare17d648b2006-08-28 14:23:46 +02007 IT8716F Super I/O chip w/LPC interface
Jean Delvare87673dd2006-08-28 14:37:19 +02008 IT8718F Super I/O chip w/LPC interface
Rudolf Marek08a8f6e2007-06-09 10:11:16 -04009 IT8726F Super I/O chip w/LPC interface
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 Sis950 A clone of the IT8705F
11
12 Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com>
Jean Delvareb19367c2006-08-28 14:39:26 +020013 Copyright (C) 2005-2006 Jean Delvare <khali@linux-fr.org>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License, or
18 (at your option) any later version.
19
20 This program is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 GNU General Public License for more details.
24
25 You should have received a copy of the GNU General Public License
26 along with this program; if not, write to the Free Software
27 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28*/
29
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/module.h>
31#include <linux/init.h>
32#include <linux/slab.h>
33#include <linux/jiffies.h>
corentin.labbeb74f3fd2007-06-13 20:27:36 +020034#include <linux/platform_device.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040035#include <linux/hwmon.h>
Jean Delvare303760b2005-07-31 21:52:01 +020036#include <linux/hwmon-sysfs.h>
37#include <linux/hwmon-vid.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040038#include <linux/err.h>
Ingo Molnar9a61bf62006-01-18 23:19:26 +010039#include <linux/mutex.h>
Jean Delvare87808be2006-09-24 21:17:13 +020040#include <linux/sysfs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070041#include <asm/io.h>
42
corentin.labbeb74f3fd2007-06-13 20:27:36 +020043#define DRVNAME "it87"
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Jean Delvare8e9afcb2006-12-12 18:18:28 +010045enum chips { it87, it8712, it8716, it8718 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
corentin.labbeb74f3fd2007-06-13 20:27:36 +020047static struct platform_device *pdev;
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define REG 0x2e /* The register to read/write */
50#define DEV 0x07 /* Register: Logical device select */
51#define VAL 0x2f /* The value to read/write */
52#define PME 0x04 /* The device with the fan registers in it */
Jean Delvare87673dd2006-08-28 14:37:19 +020053#define GPIO 0x07 /* The device with the IT8718F VID value in it */
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#define DEVID 0x20 /* Register: Device ID */
55#define DEVREV 0x22 /* Register: Device Revision */
56
57static inline int
58superio_inb(int reg)
59{
60 outb(reg, REG);
61 return inb(VAL);
62}
63
64static int superio_inw(int reg)
65{
66 int val;
67 outb(reg++, REG);
68 val = inb(VAL) << 8;
69 outb(reg, REG);
70 val |= inb(VAL);
71 return val;
72}
73
74static inline void
Jean Delvare87673dd2006-08-28 14:37:19 +020075superio_select(int ldn)
Linus Torvalds1da177e2005-04-16 15:20:36 -070076{
77 outb(DEV, REG);
Jean Delvare87673dd2006-08-28 14:37:19 +020078 outb(ldn, VAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079}
80
81static inline void
82superio_enter(void)
83{
84 outb(0x87, REG);
85 outb(0x01, REG);
86 outb(0x55, REG);
87 outb(0x55, REG);
88}
89
90static inline void
91superio_exit(void)
92{
93 outb(0x02, REG);
94 outb(0x02, VAL);
95}
96
Jean Delvare87673dd2006-08-28 14:37:19 +020097/* Logical device 4 registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#define IT8712F_DEVID 0x8712
99#define IT8705F_DEVID 0x8705
Jean Delvare17d648b2006-08-28 14:23:46 +0200100#define IT8716F_DEVID 0x8716
Jean Delvare87673dd2006-08-28 14:37:19 +0200101#define IT8718F_DEVID 0x8718
Rudolf Marek08a8f6e2007-06-09 10:11:16 -0400102#define IT8726F_DEVID 0x8726
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103#define IT87_ACT_REG 0x30
104#define IT87_BASE_REG 0x60
105
Jean Delvare87673dd2006-08-28 14:37:19 +0200106/* Logical device 7 registers (IT8712F and later) */
107#define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
108#define IT87_SIO_VID_REG 0xfc /* VID value */
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110/* Update battery voltage after every reading if true */
111static int update_vbat;
112
113/* Not all BIOSes properly configure the PWM registers */
114static int fix_pwm_polarity;
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116/* Many IT87 constants specified below */
117
118/* Length of ISA address segment */
119#define IT87_EXTENT 8
120
121/* Where are the ISA address/data registers relative to the base address */
122#define IT87_ADDR_REG_OFFSET 5
123#define IT87_DATA_REG_OFFSET 6
124
125/*----- The IT87 registers -----*/
126
127#define IT87_REG_CONFIG 0x00
128
129#define IT87_REG_ALARM1 0x01
130#define IT87_REG_ALARM2 0x02
131#define IT87_REG_ALARM3 0x03
132
Jean Delvare87673dd2006-08-28 14:37:19 +0200133/* The IT8718F has the VID value in a different register, in Super-I/O
134 configuration space. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135#define IT87_REG_VID 0x0a
Jean Delvare17d648b2006-08-28 14:23:46 +0200136/* Warning: register 0x0b is used for something completely different in
137 new chips/revisions. I suspect only 16-bit tachometer mode will work
138 for these. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139#define IT87_REG_FAN_DIV 0x0b
Jean Delvare17d648b2006-08-28 14:23:46 +0200140#define IT87_REG_FAN_16BIT 0x0c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
142/* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
143
Jean Delvarec7f1f712007-09-03 17:11:46 +0200144static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
145static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 };
146static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 };
147static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148#define IT87_REG_FAN_MAIN_CTRL 0x13
149#define IT87_REG_FAN_CTL 0x14
150#define IT87_REG_PWM(nr) (0x15 + (nr))
151
152#define IT87_REG_VIN(nr) (0x20 + (nr))
153#define IT87_REG_TEMP(nr) (0x29 + (nr))
154
155#define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
156#define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
157#define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
158#define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
159
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160#define IT87_REG_VIN_ENABLE 0x50
161#define IT87_REG_TEMP_ENABLE 0x51
162
163#define IT87_REG_CHIPID 0x58
164
165#define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255))
166#define IN_FROM_REG(val) ((val) * 16)
167
168static inline u8 FAN_TO_REG(long rpm, int div)
169{
170 if (rpm == 0)
171 return 255;
172 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
173 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1,
174 254);
175}
176
Jean Delvare17d648b2006-08-28 14:23:46 +0200177static inline u16 FAN16_TO_REG(long rpm)
178{
179 if (rpm == 0)
180 return 0xffff;
181 return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
182}
183
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
Jean Delvare17d648b2006-08-28 14:23:46 +0200185/* The divider is fixed to 2 in 16-bit mode */
186#define FAN16_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:1350000/((val)*2))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187
188#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\
189 ((val)+500)/1000),-128,127))
190#define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*1000)
191
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192#define PWM_TO_REG(val) ((val) >> 1)
193#define PWM_FROM_REG(val) (((val)&0x7f) << 1)
194
195static int DIV_TO_REG(int val)
196{
197 int answer = 0;
Jean Delvareb9e349f2006-08-28 14:26:22 +0200198 while (answer < 7 && (val >>= 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 answer++;
200 return answer;
201}
202#define DIV_FROM_REG(val) (1 << (val))
203
Jean Delvaref8d0c192007-02-14 21:15:02 +0100204static const unsigned int pwm_freq[8] = {
205 48000000 / 128,
206 24000000 / 128,
207 12000000 / 128,
208 8000000 / 128,
209 6000000 / 128,
210 3000000 / 128,
211 1500000 / 128,
212 750000 / 128,
213};
214
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200216struct it87_sio_data {
217 enum chips type;
218 /* Values read from Super-I/O config space */
219 u8 vid_value;
220};
221
Jean Delvareed6bafb2007-02-14 21:15:03 +0100222/* For each registered chip, we need to keep some data in memory.
223 The structure is dynamically allocated. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224struct it87_data {
Tony Jones1beeffe2007-08-20 13:46:20 -0700225 struct device *hwmon_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 enum chips type;
227
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200228 unsigned short addr;
229 const char *name;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100230 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 char valid; /* !=0 if following fields are valid */
232 unsigned long last_updated; /* In jiffies */
233
234 u8 in[9]; /* Register value */
Jean Delvare3543a532006-08-28 14:27:25 +0200235 u8 in_max[8]; /* Register value */
236 u8 in_min[8]; /* Register value */
Jean Delvare9060f8b2006-08-28 14:24:17 +0200237 u8 has_fan; /* Bitfield, fans enabled */
Jean Delvarec7f1f712007-09-03 17:11:46 +0200238 u16 fan[5]; /* Register values, possibly combined */
239 u16 fan_min[5]; /* Register values, possibly combined */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 u8 temp[3]; /* Register value */
241 u8 temp_high[3]; /* Register value */
242 u8 temp_low[3]; /* Register value */
243 u8 sensor; /* Register value */
244 u8 fan_div[3]; /* Register encoding, shifted right */
245 u8 vid; /* Register encoding, combined */
Jean Delvarea7be58a2005-12-18 16:40:14 +0100246 u8 vrm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 u32 alarms; /* Register encoding, combined */
248 u8 fan_main_ctrl; /* Register value */
Jean Delvaref8d0c192007-02-14 21:15:02 +0100249 u8 fan_ctl; /* Register value */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 u8 manual_pwm_ctl[3]; /* manual PWM value set by user */
251};
252
253
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200254static int it87_probe(struct platform_device *pdev);
Jean Delvared0546122007-07-22 12:09:48 +0200255static int __devexit it87_remove(struct platform_device *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200257static int it87_read_value(struct it87_data *data, u8 reg);
258static void it87_write_value(struct it87_data *data, u8 reg, u8 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259static struct it87_data *it87_update_device(struct device *dev);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200260static int it87_check_pwm(struct device *dev);
261static void it87_init_device(struct platform_device *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200264static struct platform_driver it87_driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100265 .driver = {
Jean Delvare87218842006-09-03 22:36:14 +0200266 .owner = THIS_MODULE,
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200267 .name = DRVNAME,
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100268 },
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200269 .probe = it87_probe,
270 .remove = __devexit_p(it87_remove),
Jean Delvarefde09502005-07-19 23:51:07 +0200271};
272
Jean Delvare20ad93d2005-06-05 11:53:25 +0200273static ssize_t show_in(struct device *dev, struct device_attribute *attr,
274 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200276 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
277 int nr = sensor_attr->index;
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 struct it87_data *data = it87_update_device(dev);
280 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
281}
282
Jean Delvare20ad93d2005-06-05 11:53:25 +0200283static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
284 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200286 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
287 int nr = sensor_attr->index;
288
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 struct it87_data *data = it87_update_device(dev);
290 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
291}
292
Jean Delvare20ad93d2005-06-05 11:53:25 +0200293static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
294 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200296 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
297 int nr = sensor_attr->index;
298
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 struct it87_data *data = it87_update_device(dev);
300 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
301}
302
Jean Delvare20ad93d2005-06-05 11:53:25 +0200303static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
304 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200306 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
307 int nr = sensor_attr->index;
308
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200309 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 unsigned long val = simple_strtoul(buf, NULL, 10);
311
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100312 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 data->in_min[nr] = IN_TO_REG(val);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200314 it87_write_value(data, IT87_REG_VIN_MIN(nr),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 data->in_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100316 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 return count;
318}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200319static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
320 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200322 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
323 int nr = sensor_attr->index;
324
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200325 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 unsigned long val = simple_strtoul(buf, NULL, 10);
327
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100328 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 data->in_max[nr] = IN_TO_REG(val);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200330 it87_write_value(data, IT87_REG_VIN_MAX(nr),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 data->in_max[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100332 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 return count;
334}
335
336#define show_in_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200337static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
338 show_in, NULL, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340#define limit_in_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200341static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
342 show_in_min, set_in_min, offset); \
343static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
344 show_in_max, set_in_max, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346show_in_offset(0);
347limit_in_offset(0);
348show_in_offset(1);
349limit_in_offset(1);
350show_in_offset(2);
351limit_in_offset(2);
352show_in_offset(3);
353limit_in_offset(3);
354show_in_offset(4);
355limit_in_offset(4);
356show_in_offset(5);
357limit_in_offset(5);
358show_in_offset(6);
359limit_in_offset(6);
360show_in_offset(7);
361limit_in_offset(7);
362show_in_offset(8);
363
364/* 3 temperatures */
Jean Delvare20ad93d2005-06-05 11:53:25 +0200365static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
366 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200368 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
369 int nr = sensor_attr->index;
370
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 struct it87_data *data = it87_update_device(dev);
372 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
373}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200374static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
375 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200377 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
378 int nr = sensor_attr->index;
379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 struct it87_data *data = it87_update_device(dev);
381 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr]));
382}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200383static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
384 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200386 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
387 int nr = sensor_attr->index;
388
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 struct it87_data *data = it87_update_device(dev);
390 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr]));
391}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200392static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
393 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200395 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
396 int nr = sensor_attr->index;
397
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200398 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 int val = simple_strtol(buf, NULL, 10);
400
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100401 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 data->temp_high[nr] = TEMP_TO_REG(val);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200403 it87_write_value(data, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100404 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 return count;
406}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200407static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
408 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200410 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
411 int nr = sensor_attr->index;
412
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200413 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 int val = simple_strtol(buf, NULL, 10);
415
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100416 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 data->temp_low[nr] = TEMP_TO_REG(val);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200418 it87_write_value(data, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100419 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 return count;
421}
422#define show_temp_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200423static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
424 show_temp, NULL, offset - 1); \
425static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
426 show_temp_max, set_temp_max, offset - 1); \
427static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
428 show_temp_min, set_temp_min, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
430show_temp_offset(1);
431show_temp_offset(2);
432show_temp_offset(3);
433
Jean Delvare20ad93d2005-06-05 11:53:25 +0200434static ssize_t show_sensor(struct device *dev, struct device_attribute *attr,
435 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200437 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
438 int nr = sensor_attr->index;
439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 struct it87_data *data = it87_update_device(dev);
441 u8 reg = data->sensor; /* In case the value is updated while we use it */
442
443 if (reg & (1 << nr))
444 return sprintf(buf, "3\n"); /* thermal diode */
445 if (reg & (8 << nr))
446 return sprintf(buf, "2\n"); /* thermistor */
447 return sprintf(buf, "0\n"); /* disabled */
448}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200449static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
450 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200452 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
453 int nr = sensor_attr->index;
454
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200455 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 int val = simple_strtol(buf, NULL, 10);
457
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100458 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460 data->sensor &= ~(1 << nr);
461 data->sensor &= ~(8 << nr);
462 /* 3 = thermal diode; 2 = thermistor; 0 = disabled */
463 if (val == 3)
464 data->sensor |= 1 << nr;
465 else if (val == 2)
466 data->sensor |= 8 << nr;
467 else if (val != 0) {
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100468 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 return -EINVAL;
470 }
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200471 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100472 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 return count;
474}
475#define show_sensor_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200476static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
477 show_sensor, set_sensor, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
479show_sensor_offset(1);
480show_sensor_offset(2);
481show_sensor_offset(3);
482
483/* 3 Fans */
Jean Delvare20ad93d2005-06-05 11:53:25 +0200484static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
485 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200487 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
488 int nr = sensor_attr->index;
489
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 struct it87_data *data = it87_update_device(dev);
491 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
492 DIV_FROM_REG(data->fan_div[nr])));
493}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200494static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
495 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200497 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
498 int nr = sensor_attr->index;
499
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 struct it87_data *data = it87_update_device(dev);
501 return sprintf(buf,"%d\n",
502 FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])));
503}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200504static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
505 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200507 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
508 int nr = sensor_attr->index;
509
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 struct it87_data *data = it87_update_device(dev);
511 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
512}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200513static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr,
514 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200516 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
517 int nr = sensor_attr->index;
518
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 struct it87_data *data = it87_update_device(dev);
520 return sprintf(buf,"%d\n", (data->fan_main_ctrl & (1 << nr)) ? 1 : 0);
521}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200522static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
523 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200525 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
526 int nr = sensor_attr->index;
527
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 struct it87_data *data = it87_update_device(dev);
529 return sprintf(buf,"%d\n", data->manual_pwm_ctl[nr]);
530}
Jean Delvaref8d0c192007-02-14 21:15:02 +0100531static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
532 char *buf)
533{
534 struct it87_data *data = it87_update_device(dev);
535 int index = (data->fan_ctl >> 4) & 0x07;
536
537 return sprintf(buf, "%u\n", pwm_freq[index]);
538}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200539static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
540 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200542 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
543 int nr = sensor_attr->index;
544
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200545 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 int val = simple_strtol(buf, NULL, 10);
Jean Delvare7f999aa2007-02-14 21:15:03 +0100547 u8 reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100549 mutex_lock(&data->update_lock);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200550 reg = it87_read_value(data, IT87_REG_FAN_DIV);
Jean Delvare07eab462005-11-23 15:44:31 -0800551 switch (nr) {
552 case 0: data->fan_div[nr] = reg & 0x07; break;
553 case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break;
554 case 2: data->fan_div[nr] = (reg & 0x40) ? 3 : 1; break;
555 }
556
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
Jean Delvarec7f1f712007-09-03 17:11:46 +0200558 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100559 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 return count;
561}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200562static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
563 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200565 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
566 int nr = sensor_attr->index;
567
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200568 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvareb9e349f2006-08-28 14:26:22 +0200569 unsigned long val = simple_strtoul(buf, NULL, 10);
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200570 int min;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 u8 old;
572
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100573 mutex_lock(&data->update_lock);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200574 old = it87_read_value(data, IT87_REG_FAN_DIV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200576 /* Save fan min limit */
577 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578
579 switch (nr) {
580 case 0:
581 case 1:
582 data->fan_div[nr] = DIV_TO_REG(val);
583 break;
584 case 2:
585 if (val < 8)
586 data->fan_div[nr] = 1;
587 else
588 data->fan_div[nr] = 3;
589 }
590 val = old & 0x80;
591 val |= (data->fan_div[0] & 0x07);
592 val |= (data->fan_div[1] & 0x07) << 3;
593 if (data->fan_div[2] == 3)
594 val |= 0x1 << 6;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200595 it87_write_value(data, IT87_REG_FAN_DIV, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200597 /* Restore fan min limit */
598 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
Jean Delvarec7f1f712007-09-03 17:11:46 +0200599 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]);
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200600
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100601 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 return count;
603}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200604static ssize_t set_pwm_enable(struct device *dev,
605 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200607 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
608 int nr = sensor_attr->index;
609
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200610 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 int val = simple_strtol(buf, NULL, 10);
612
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100613 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
615 if (val == 0) {
616 int tmp;
617 /* make sure the fan is on when in on/off mode */
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200618 tmp = it87_read_value(data, IT87_REG_FAN_CTL);
619 it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 /* set on/off mode */
621 data->fan_main_ctrl &= ~(1 << nr);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200622 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 } else if (val == 1) {
624 /* set SmartGuardian mode */
625 data->fan_main_ctrl |= (1 << nr);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200626 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 /* set saved pwm value, clear FAN_CTLX PWM mode bit */
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200628 it87_write_value(data, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 } else {
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100630 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 return -EINVAL;
632 }
633
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100634 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635 return count;
636}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200637static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
638 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200640 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
641 int nr = sensor_attr->index;
642
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200643 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 int val = simple_strtol(buf, NULL, 10);
645
646 if (val < 0 || val > 255)
647 return -EINVAL;
648
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100649 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 data->manual_pwm_ctl[nr] = val;
651 if (data->fan_main_ctrl & (1 << nr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200652 it87_write_value(data, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100653 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 return count;
655}
Jean Delvaref8d0c192007-02-14 21:15:02 +0100656static ssize_t set_pwm_freq(struct device *dev,
657 struct device_attribute *attr, const char *buf, size_t count)
658{
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200659 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref8d0c192007-02-14 21:15:02 +0100660 unsigned long val = simple_strtoul(buf, NULL, 10);
661 int i;
662
663 /* Search for the nearest available frequency */
664 for (i = 0; i < 7; i++) {
665 if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
666 break;
667 }
668
669 mutex_lock(&data->update_lock);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200670 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
Jean Delvaref8d0c192007-02-14 21:15:02 +0100671 data->fan_ctl |= i << 4;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200672 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
Jean Delvaref8d0c192007-02-14 21:15:02 +0100673 mutex_unlock(&data->update_lock);
674
675 return count;
676}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Jean Delvare20ad93d2005-06-05 11:53:25 +0200678#define show_fan_offset(offset) \
679static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
680 show_fan, NULL, offset - 1); \
681static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
682 show_fan_min, set_fan_min, offset - 1); \
683static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
684 show_fan_div, set_fan_div, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
686show_fan_offset(1);
687show_fan_offset(2);
688show_fan_offset(3);
689
690#define show_pwm_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200691static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
692 show_pwm_enable, set_pwm_enable, offset - 1); \
693static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
Jean Delvaref8d0c192007-02-14 21:15:02 +0100694 show_pwm, set_pwm, offset - 1); \
695static DEVICE_ATTR(pwm##offset##_freq, \
696 (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \
697 show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
699show_pwm_offset(1);
700show_pwm_offset(2);
701show_pwm_offset(3);
702
Jean Delvare17d648b2006-08-28 14:23:46 +0200703/* A different set of callbacks for 16-bit fans */
704static ssize_t show_fan16(struct device *dev, struct device_attribute *attr,
705 char *buf)
706{
707 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
708 int nr = sensor_attr->index;
709 struct it87_data *data = it87_update_device(dev);
710 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan[nr]));
711}
712
713static ssize_t show_fan16_min(struct device *dev, struct device_attribute *attr,
714 char *buf)
715{
716 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
717 int nr = sensor_attr->index;
718 struct it87_data *data = it87_update_device(dev);
719 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan_min[nr]));
720}
721
722static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
723 const char *buf, size_t count)
724{
725 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
726 int nr = sensor_attr->index;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200727 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvare17d648b2006-08-28 14:23:46 +0200728 int val = simple_strtol(buf, NULL, 10);
729
730 mutex_lock(&data->update_lock);
731 data->fan_min[nr] = FAN16_TO_REG(val);
Jean Delvarec7f1f712007-09-03 17:11:46 +0200732 it87_write_value(data, IT87_REG_FAN_MIN[nr],
Jean Delvare17d648b2006-08-28 14:23:46 +0200733 data->fan_min[nr] & 0xff);
Jean Delvarec7f1f712007-09-03 17:11:46 +0200734 it87_write_value(data, IT87_REG_FANX_MIN[nr],
Jean Delvare17d648b2006-08-28 14:23:46 +0200735 data->fan_min[nr] >> 8);
736 mutex_unlock(&data->update_lock);
737 return count;
738}
739
740/* We want to use the same sysfs file names as 8-bit fans, but we need
741 different variable names, so we have to use SENSOR_ATTR instead of
742 SENSOR_DEVICE_ATTR. */
743#define show_fan16_offset(offset) \
744static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
745 = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
746 show_fan16, NULL, offset - 1); \
747static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \
748 = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
749 show_fan16_min, set_fan16_min, offset - 1)
750
751show_fan16_offset(1);
752show_fan16_offset(2);
753show_fan16_offset(3);
Jean Delvarec7f1f712007-09-03 17:11:46 +0200754show_fan16_offset(4);
755show_fan16_offset(5);
Jean Delvare17d648b2006-08-28 14:23:46 +0200756
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757/* Alarms */
Yani Ioannou30f74292005-05-17 06:41:35 -0400758static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700759{
760 struct it87_data *data = it87_update_device(dev);
Jean Delvare68188ba2005-05-16 18:52:38 +0200761 return sprintf(buf, "%u\n", data->alarms);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762}
Jean Delvare1d66c642005-04-18 21:16:59 -0700763static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765static ssize_t
Yani Ioannou30f74292005-05-17 06:41:35 -0400766show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767{
Jean Delvare90d66192007-10-08 18:24:35 +0200768 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvarea7be58a2005-12-18 16:40:14 +0100769 return sprintf(buf, "%u\n", data->vrm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770}
771static ssize_t
Yani Ioannou30f74292005-05-17 06:41:35 -0400772store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773{
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200774 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 u32 val;
776
777 val = simple_strtoul(buf, NULL, 10);
778 data->vrm = val;
779
780 return count;
781}
782static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
784static ssize_t
Yani Ioannou30f74292005-05-17 06:41:35 -0400785show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786{
787 struct it87_data *data = it87_update_device(dev);
788 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
789}
790static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
Jean Delvare87808be2006-09-24 21:17:13 +0200791
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200792static ssize_t show_name(struct device *dev, struct device_attribute
793 *devattr, char *buf)
794{
795 struct it87_data *data = dev_get_drvdata(dev);
796 return sprintf(buf, "%s\n", data->name);
797}
798static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
799
Jean Delvare87808be2006-09-24 21:17:13 +0200800static struct attribute *it87_attributes[] = {
801 &sensor_dev_attr_in0_input.dev_attr.attr,
802 &sensor_dev_attr_in1_input.dev_attr.attr,
803 &sensor_dev_attr_in2_input.dev_attr.attr,
804 &sensor_dev_attr_in3_input.dev_attr.attr,
805 &sensor_dev_attr_in4_input.dev_attr.attr,
806 &sensor_dev_attr_in5_input.dev_attr.attr,
807 &sensor_dev_attr_in6_input.dev_attr.attr,
808 &sensor_dev_attr_in7_input.dev_attr.attr,
809 &sensor_dev_attr_in8_input.dev_attr.attr,
810 &sensor_dev_attr_in0_min.dev_attr.attr,
811 &sensor_dev_attr_in1_min.dev_attr.attr,
812 &sensor_dev_attr_in2_min.dev_attr.attr,
813 &sensor_dev_attr_in3_min.dev_attr.attr,
814 &sensor_dev_attr_in4_min.dev_attr.attr,
815 &sensor_dev_attr_in5_min.dev_attr.attr,
816 &sensor_dev_attr_in6_min.dev_attr.attr,
817 &sensor_dev_attr_in7_min.dev_attr.attr,
818 &sensor_dev_attr_in0_max.dev_attr.attr,
819 &sensor_dev_attr_in1_max.dev_attr.attr,
820 &sensor_dev_attr_in2_max.dev_attr.attr,
821 &sensor_dev_attr_in3_max.dev_attr.attr,
822 &sensor_dev_attr_in4_max.dev_attr.attr,
823 &sensor_dev_attr_in5_max.dev_attr.attr,
824 &sensor_dev_attr_in6_max.dev_attr.attr,
825 &sensor_dev_attr_in7_max.dev_attr.attr,
826
827 &sensor_dev_attr_temp1_input.dev_attr.attr,
828 &sensor_dev_attr_temp2_input.dev_attr.attr,
829 &sensor_dev_attr_temp3_input.dev_attr.attr,
830 &sensor_dev_attr_temp1_max.dev_attr.attr,
831 &sensor_dev_attr_temp2_max.dev_attr.attr,
832 &sensor_dev_attr_temp3_max.dev_attr.attr,
833 &sensor_dev_attr_temp1_min.dev_attr.attr,
834 &sensor_dev_attr_temp2_min.dev_attr.attr,
835 &sensor_dev_attr_temp3_min.dev_attr.attr,
836 &sensor_dev_attr_temp1_type.dev_attr.attr,
837 &sensor_dev_attr_temp2_type.dev_attr.attr,
838 &sensor_dev_attr_temp3_type.dev_attr.attr,
839
840 &dev_attr_alarms.attr,
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200841 &dev_attr_name.attr,
Jean Delvare87808be2006-09-24 21:17:13 +0200842 NULL
843};
844
845static const struct attribute_group it87_group = {
846 .attrs = it87_attributes,
847};
848
849static struct attribute *it87_attributes_opt[] = {
850 &sensor_dev_attr_fan1_input16.dev_attr.attr,
851 &sensor_dev_attr_fan1_min16.dev_attr.attr,
852 &sensor_dev_attr_fan2_input16.dev_attr.attr,
853 &sensor_dev_attr_fan2_min16.dev_attr.attr,
854 &sensor_dev_attr_fan3_input16.dev_attr.attr,
855 &sensor_dev_attr_fan3_min16.dev_attr.attr,
Jean Delvarec7f1f712007-09-03 17:11:46 +0200856 &sensor_dev_attr_fan4_input16.dev_attr.attr,
857 &sensor_dev_attr_fan4_min16.dev_attr.attr,
858 &sensor_dev_attr_fan5_input16.dev_attr.attr,
859 &sensor_dev_attr_fan5_min16.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +0200860
861 &sensor_dev_attr_fan1_input.dev_attr.attr,
862 &sensor_dev_attr_fan1_min.dev_attr.attr,
863 &sensor_dev_attr_fan1_div.dev_attr.attr,
864 &sensor_dev_attr_fan2_input.dev_attr.attr,
865 &sensor_dev_attr_fan2_min.dev_attr.attr,
866 &sensor_dev_attr_fan2_div.dev_attr.attr,
867 &sensor_dev_attr_fan3_input.dev_attr.attr,
868 &sensor_dev_attr_fan3_min.dev_attr.attr,
869 &sensor_dev_attr_fan3_div.dev_attr.attr,
870
871 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
872 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
873 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
874 &sensor_dev_attr_pwm1.dev_attr.attr,
875 &sensor_dev_attr_pwm2.dev_attr.attr,
876 &sensor_dev_attr_pwm3.dev_attr.attr,
877
878 &dev_attr_vrm.attr,
879 &dev_attr_cpu0_vid.attr,
880 NULL
881};
882
883static const struct attribute_group it87_group_opt = {
884 .attrs = it87_attributes_opt,
885};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
Jean Delvare2d8672c2005-07-19 23:56:35 +0200887/* SuperIO detection - will change isa_address if a chip is found */
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200888static int __init it87_find(unsigned short *address,
889 struct it87_sio_data *sio_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890{
891 int err = -ENODEV;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200892 u16 chip_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
894 superio_enter();
895 chip_type = superio_inw(DEVID);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200896
897 switch (chip_type) {
898 case IT8705F_DEVID:
899 sio_data->type = it87;
900 break;
901 case IT8712F_DEVID:
902 sio_data->type = it8712;
903 break;
904 case IT8716F_DEVID:
905 case IT8726F_DEVID:
906 sio_data->type = it8716;
907 break;
908 case IT8718F_DEVID:
909 sio_data->type = it8718;
910 break;
911 case 0xffff: /* No device at all */
912 goto exit;
913 default:
914 pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%x)\n",
915 chip_type);
916 goto exit;
917 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
Jean Delvare87673dd2006-08-28 14:37:19 +0200919 superio_select(PME);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
921 pr_info("it87: Device not activated, skipping\n");
922 goto exit;
923 }
924
925 *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
926 if (*address == 0) {
927 pr_info("it87: Base address not set, skipping\n");
928 goto exit;
929 }
930
931 err = 0;
932 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n",
933 chip_type, *address, superio_inb(DEVREV) & 0x0f);
934
Jean Delvare87673dd2006-08-28 14:37:19 +0200935 /* Read GPIO config and VID value from LDN 7 (GPIO) */
936 if (chip_type != IT8705F_DEVID) {
937 int reg;
938
939 superio_select(GPIO);
940 if (chip_type == it8718)
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200941 sio_data->vid_value = superio_inb(IT87_SIO_VID_REG);
Jean Delvare87673dd2006-08-28 14:37:19 +0200942
943 reg = superio_inb(IT87_SIO_PINX2_REG);
944 if (reg & (1 << 0))
945 pr_info("it87: in3 is VCC (+5V)\n");
946 if (reg & (1 << 1))
947 pr_info("it87: in7 is VCCH (+5V Stand-By)\n");
948 }
949
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950exit:
951 superio_exit();
952 return err;
953}
954
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200955static int __devinit it87_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 struct it87_data *data;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200958 struct resource *res;
959 struct device *dev = &pdev->dev;
960 struct it87_sio_data *sio_data = dev->platform_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961 int err = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 int enable_pwm_interface;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200963 static const char *names[] = {
964 "it87",
965 "it8712",
966 "it8716",
967 "it8718",
968 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200970 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
971 if (!request_region(res->start, IT87_EXTENT, DRVNAME)) {
972 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
973 (unsigned long)res->start,
974 (unsigned long)(res->start + IT87_EXTENT - 1));
Jean Delvare8e9afcb2006-12-12 18:18:28 +0100975 err = -EBUSY;
976 goto ERROR0;
977 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
Deepak Saxenaba9c2e82005-10-17 23:08:32 +0200979 if (!(data = kzalloc(sizeof(struct it87_data), GFP_KERNEL))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 err = -ENOMEM;
981 goto ERROR1;
982 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200984 data->addr = res->start;
985 data->type = sio_data->type;
986 data->name = names[sio_data->type];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
988 /* Now, we do the remaining detection. */
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200989 if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)
990 || it87_read_value(data, IT87_REG_CHIPID) != 0x90) {
Jean Delvare8e9afcb2006-12-12 18:18:28 +0100991 err = -ENODEV;
992 goto ERROR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 }
994
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200995 platform_set_drvdata(pdev, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100997 mutex_init(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999 /* Check PWM configuration */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001000 enable_pwm_interface = it87_check_pwm(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001
1002 /* Initialize the IT87 chip */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001003 it87_init_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004
1005 /* Register sysfs hooks */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001006 if ((err = sysfs_create_group(&dev->kobj, &it87_group)))
1007 goto ERROR2;
Jean Delvare17d648b2006-08-28 14:23:46 +02001008
Jean Delvare9060f8b2006-08-28 14:24:17 +02001009 /* Do not create fan files for disabled fans */
Jean Delvare87673dd2006-08-28 14:37:19 +02001010 if (data->type == it8716 || data->type == it8718) {
1011 /* 16-bit tachometers */
Jean Delvare9060f8b2006-08-28 14:24:17 +02001012 if (data->has_fan & (1 << 0)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001013 if ((err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001014 &sensor_dev_attr_fan1_input16.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001015 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001016 &sensor_dev_attr_fan1_min16.dev_attr)))
1017 goto ERROR4;
Jean Delvare9060f8b2006-08-28 14:24:17 +02001018 }
1019 if (data->has_fan & (1 << 1)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001020 if ((err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001021 &sensor_dev_attr_fan2_input16.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001022 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001023 &sensor_dev_attr_fan2_min16.dev_attr)))
1024 goto ERROR4;
Jean Delvare9060f8b2006-08-28 14:24:17 +02001025 }
1026 if (data->has_fan & (1 << 2)) {
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_fan3_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_fan3_min16.dev_attr)))
1031 goto ERROR4;
Jean Delvare9060f8b2006-08-28 14:24:17 +02001032 }
Jean Delvarec7f1f712007-09-03 17:11:46 +02001033 if (data->has_fan & (1 << 3)) {
1034 if ((err = device_create_file(dev,
1035 &sensor_dev_attr_fan4_input16.dev_attr))
1036 || (err = device_create_file(dev,
1037 &sensor_dev_attr_fan4_min16.dev_attr)))
1038 goto ERROR4;
1039 }
1040 if (data->has_fan & (1 << 4)) {
1041 if ((err = device_create_file(dev,
1042 &sensor_dev_attr_fan5_input16.dev_attr))
1043 || (err = device_create_file(dev,
1044 &sensor_dev_attr_fan5_min16.dev_attr)))
1045 goto ERROR4;
1046 }
Jean Delvare17d648b2006-08-28 14:23:46 +02001047 } else {
Jean Delvare87673dd2006-08-28 14:37:19 +02001048 /* 8-bit tachometers with clock divider */
Jean Delvare9060f8b2006-08-28 14:24:17 +02001049 if (data->has_fan & (1 << 0)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001050 if ((err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001051 &sensor_dev_attr_fan1_input.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001052 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001053 &sensor_dev_attr_fan1_min.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001054 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001055 &sensor_dev_attr_fan1_div.dev_attr)))
1056 goto ERROR4;
Jean Delvare9060f8b2006-08-28 14:24:17 +02001057 }
1058 if (data->has_fan & (1 << 1)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001059 if ((err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001060 &sensor_dev_attr_fan2_input.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001061 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001062 &sensor_dev_attr_fan2_min.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001063 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001064 &sensor_dev_attr_fan2_div.dev_attr)))
1065 goto ERROR4;
Jean Delvare9060f8b2006-08-28 14:24:17 +02001066 }
1067 if (data->has_fan & (1 << 2)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001068 if ((err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001069 &sensor_dev_attr_fan3_input.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001070 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001071 &sensor_dev_attr_fan3_min.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001072 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001073 &sensor_dev_attr_fan3_div.dev_attr)))
1074 goto ERROR4;
Jean Delvare9060f8b2006-08-28 14:24:17 +02001075 }
Jean Delvare17d648b2006-08-28 14:23:46 +02001076 }
1077
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 if (enable_pwm_interface) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001079 if ((err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001080 &sensor_dev_attr_pwm1_enable.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001081 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001082 &sensor_dev_attr_pwm2_enable.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001083 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001084 &sensor_dev_attr_pwm3_enable.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001085 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001086 &sensor_dev_attr_pwm1.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001087 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001088 &sensor_dev_attr_pwm2.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001089 || (err = device_create_file(dev,
Jean Delvaref8d0c192007-02-14 21:15:02 +01001090 &sensor_dev_attr_pwm3.dev_attr))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001091 || (err = device_create_file(dev,
Jean Delvaref8d0c192007-02-14 21:15:02 +01001092 &dev_attr_pwm1_freq))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001093 || (err = device_create_file(dev,
Jean Delvaref8d0c192007-02-14 21:15:02 +01001094 &dev_attr_pwm2_freq))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001095 || (err = device_create_file(dev,
Jean Delvaref8d0c192007-02-14 21:15:02 +01001096 &dev_attr_pwm3_freq)))
Jean Delvare87808be2006-09-24 21:17:13 +02001097 goto ERROR4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 }
1099
Jean Delvare87673dd2006-08-28 14:37:19 +02001100 if (data->type == it8712 || data->type == it8716
1101 || data->type == it8718) {
Jean Delvare303760b2005-07-31 21:52:01 +02001102 data->vrm = vid_which_vrm();
Jean Delvare87673dd2006-08-28 14:37:19 +02001103 /* VID reading from Super-I/O config space if available */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001104 data->vid = sio_data->vid_value;
1105 if ((err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001106 &dev_attr_vrm))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001107 || (err = device_create_file(dev,
Jean Delvare87808be2006-09-24 21:17:13 +02001108 &dev_attr_cpu0_vid)))
1109 goto ERROR4;
1110 }
1111
Tony Jones1beeffe2007-08-20 13:46:20 -07001112 data->hwmon_dev = hwmon_device_register(dev);
1113 if (IS_ERR(data->hwmon_dev)) {
1114 err = PTR_ERR(data->hwmon_dev);
Jean Delvare87808be2006-09-24 21:17:13 +02001115 goto ERROR4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116 }
1117
1118 return 0;
1119
Jean Delvare87808be2006-09-24 21:17:13 +02001120ERROR4:
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001121 sysfs_remove_group(&dev->kobj, &it87_group);
1122 sysfs_remove_group(&dev->kobj, &it87_group_opt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123ERROR2:
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001124 platform_set_drvdata(pdev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 kfree(data);
1126ERROR1:
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001127 release_region(res->start, IT87_EXTENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128ERROR0:
1129 return err;
1130}
1131
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001132static int __devexit it87_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001134 struct it87_data *data = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135
Tony Jones1beeffe2007-08-20 13:46:20 -07001136 hwmon_device_unregister(data->hwmon_dev);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001137 sysfs_remove_group(&pdev->dev.kobj, &it87_group);
1138 sysfs_remove_group(&pdev->dev.kobj, &it87_group_opt);
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001139
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001140 release_region(data->addr, IT87_EXTENT);
1141 platform_set_drvdata(pdev, NULL);
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001142 kfree(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
1144 return 0;
1145}
1146
Jean Delvare7f999aa2007-02-14 21:15:03 +01001147/* Must be called with data->update_lock held, except during initialization.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1149 would slow down the IT87 access and should not be necessary. */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001150static int it87_read_value(struct it87_data *data, u8 reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001152 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
1153 return inb_p(data->addr + IT87_DATA_REG_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154}
1155
Jean Delvare7f999aa2007-02-14 21:15:03 +01001156/* Must be called with data->update_lock held, except during initialization.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1158 would slow down the IT87 access and should not be necessary. */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001159static void it87_write_value(struct it87_data *data, u8 reg, u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001161 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
1162 outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163}
1164
1165/* Return 1 if and only if the PWM interface is safe to use */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001166static int __devinit it87_check_pwm(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001168 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 /* Some BIOSes fail to correctly configure the IT87 fans. All fans off
1170 * and polarity set to active low is sign that this is the case so we
1171 * disable pwm control to protect the user. */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001172 int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 if ((tmp & 0x87) == 0) {
1174 if (fix_pwm_polarity) {
1175 /* The user asks us to attempt a chip reconfiguration.
1176 * This means switching to active high polarity and
1177 * inverting all fan speed values. */
1178 int i;
1179 u8 pwm[3];
1180
1181 for (i = 0; i < 3; i++)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001182 pwm[i] = it87_read_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 IT87_REG_PWM(i));
1184
1185 /* If any fan is in automatic pwm mode, the polarity
1186 * might be correct, as suspicious as it seems, so we
1187 * better don't change anything (but still disable the
1188 * PWM interface). */
1189 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001190 dev_info(dev, "Reconfiguring PWM to "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 "active high polarity\n");
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001192 it87_write_value(data, IT87_REG_FAN_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 tmp | 0x87);
1194 for (i = 0; i < 3; i++)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001195 it87_write_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 IT87_REG_PWM(i),
1197 0x7f & ~pwm[i]);
1198 return 1;
1199 }
1200
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001201 dev_info(dev, "PWM configuration is "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 "too broken to be fixed\n");
1203 }
1204
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001205 dev_info(dev, "Detected broken BIOS "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 "defaults, disabling PWM interface\n");
1207 return 0;
1208 } else if (fix_pwm_polarity) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001209 dev_info(dev, "PWM configuration looks "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 "sane, won't touch\n");
1211 }
1212
1213 return 1;
1214}
1215
1216/* Called when we have found a new IT87. */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001217static void __devinit it87_init_device(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001218{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001219 struct it87_data *data = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 int tmp, i;
1221
1222 /* initialize to sane defaults:
1223 * - if the chip is in manual pwm mode, this will be overwritten with
1224 * the actual settings on the chip (so in this case, initialization
1225 * is not needed)
1226 * - if in automatic or on/off mode, we could switch to manual mode,
1227 * read the registers and set manual_pwm_ctl accordingly, but currently
1228 * this is not implemented, so we initialize to something sane */
1229 for (i = 0; i < 3; i++) {
1230 data->manual_pwm_ctl[i] = 0xff;
1231 }
1232
Jean Delvarec5df9b72006-08-28 14:37:54 +02001233 /* Some chips seem to have default value 0xff for all limit
1234 * registers. For low voltage limits it makes no sense and triggers
1235 * alarms, so change to 0 instead. For high temperature limits, it
1236 * means -1 degree C, which surprisingly doesn't trigger an alarm,
1237 * but is still confusing, so change to 127 degrees C. */
1238 for (i = 0; i < 8; i++) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001239 tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
Jean Delvarec5df9b72006-08-28 14:37:54 +02001240 if (tmp == 0xff)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001241 it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
Jean Delvarec5df9b72006-08-28 14:37:54 +02001242 }
1243 for (i = 0; i < 3; i++) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001244 tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i));
Jean Delvarec5df9b72006-08-28 14:37:54 +02001245 if (tmp == 0xff)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001246 it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127);
Jean Delvarec5df9b72006-08-28 14:37:54 +02001247 }
1248
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 /* Check if temperature channnels are reset manually or by some reason */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001250 tmp = it87_read_value(data, IT87_REG_TEMP_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 if ((tmp & 0x3f) == 0) {
1252 /* Temp1,Temp3=thermistor; Temp2=thermal diode */
1253 tmp = (tmp & 0xc0) | 0x2a;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001254 it87_write_value(data, IT87_REG_TEMP_ENABLE, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255 }
1256 data->sensor = tmp;
1257
1258 /* Check if voltage monitors are reset manually or by some reason */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001259 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 if ((tmp & 0xff) == 0) {
1261 /* Enable all voltage monitors */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001262 it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263 }
1264
1265 /* Check if tachometers are reset manually or by some reason */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001266 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267 if ((data->fan_main_ctrl & 0x70) == 0) {
1268 /* Enable all fan tachometers */
1269 data->fan_main_ctrl |= 0x70;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001270 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271 }
Jean Delvare9060f8b2006-08-28 14:24:17 +02001272 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273
Jean Delvare17d648b2006-08-28 14:23:46 +02001274 /* Set tachometers to 16-bit mode if needed */
Jean Delvare87673dd2006-08-28 14:37:19 +02001275 if (data->type == it8716 || data->type == it8718) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001276 tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
Jean Delvare9060f8b2006-08-28 14:24:17 +02001277 if (~tmp & 0x07 & data->has_fan) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001278 dev_dbg(&pdev->dev,
Jean Delvare17d648b2006-08-28 14:23:46 +02001279 "Setting fan1-3 to 16-bit mode\n");
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001280 it87_write_value(data, IT87_REG_FAN_16BIT,
Jean Delvare17d648b2006-08-28 14:23:46 +02001281 tmp | 0x07);
1282 }
Jean Delvarec7f1f712007-09-03 17:11:46 +02001283 if (tmp & (1 << 4))
1284 data->has_fan |= (1 << 3); /* fan4 enabled */
1285 if (tmp & (1 << 5))
1286 data->has_fan |= (1 << 4); /* fan5 enabled */
Jean Delvare17d648b2006-08-28 14:23:46 +02001287 }
1288
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 /* Set current fan mode registers and the default settings for the
1290 * other mode registers */
1291 for (i = 0; i < 3; i++) {
1292 if (data->fan_main_ctrl & (1 << i)) {
1293 /* pwm mode */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001294 tmp = it87_read_value(data, IT87_REG_PWM(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295 if (tmp & 0x80) {
1296 /* automatic pwm - not yet implemented, but
1297 * leave the settings made by the BIOS alone
1298 * until a change is requested via the sysfs
1299 * interface */
1300 } else {
1301 /* manual pwm */
1302 data->manual_pwm_ctl[i] = PWM_FROM_REG(tmp);
1303 }
1304 }
1305 }
1306
1307 /* Start monitoring */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001308 it87_write_value(data, IT87_REG_CONFIG,
1309 (it87_read_value(data, IT87_REG_CONFIG) & 0x36)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 | (update_vbat ? 0x41 : 0x01));
1311}
1312
1313static struct it87_data *it87_update_device(struct device *dev)
1314{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001315 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316 int i;
1317
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001318 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001319
1320 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
1321 || !data->valid) {
1322
1323 if (update_vbat) {
1324 /* Cleared after each update, so reenable. Value
1325 returned by this read will be previous value */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001326 it87_write_value(data, IT87_REG_CONFIG,
1327 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 }
1329 for (i = 0; i <= 7; i++) {
1330 data->in[i] =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001331 it87_read_value(data, IT87_REG_VIN(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 data->in_min[i] =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001333 it87_read_value(data, IT87_REG_VIN_MIN(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 data->in_max[i] =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001335 it87_read_value(data, IT87_REG_VIN_MAX(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 }
Jean Delvare3543a532006-08-28 14:27:25 +02001337 /* in8 (battery) has no limit registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 data->in[8] =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001339 it87_read_value(data, IT87_REG_VIN(8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
Jean Delvarec7f1f712007-09-03 17:11:46 +02001341 for (i = 0; i < 5; i++) {
Jean Delvare9060f8b2006-08-28 14:24:17 +02001342 /* Skip disabled fans */
1343 if (!(data->has_fan & (1 << i)))
1344 continue;
1345
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 data->fan_min[i] =
Jean Delvarec7f1f712007-09-03 17:11:46 +02001347 it87_read_value(data, IT87_REG_FAN_MIN[i]);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001348 data->fan[i] = it87_read_value(data,
Jean Delvarec7f1f712007-09-03 17:11:46 +02001349 IT87_REG_FAN[i]);
Jean Delvare17d648b2006-08-28 14:23:46 +02001350 /* Add high byte if in 16-bit mode */
Jean Delvare87673dd2006-08-28 14:37:19 +02001351 if (data->type == it8716 || data->type == it8718) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001352 data->fan[i] |= it87_read_value(data,
Jean Delvarec7f1f712007-09-03 17:11:46 +02001353 IT87_REG_FANX[i]) << 8;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001354 data->fan_min[i] |= it87_read_value(data,
Jean Delvarec7f1f712007-09-03 17:11:46 +02001355 IT87_REG_FANX_MIN[i]) << 8;
Jean Delvare17d648b2006-08-28 14:23:46 +02001356 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 }
1358 for (i = 0; i < 3; i++) {
1359 data->temp[i] =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001360 it87_read_value(data, IT87_REG_TEMP(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 data->temp_high[i] =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001362 it87_read_value(data, IT87_REG_TEMP_HIGH(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 data->temp_low[i] =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001364 it87_read_value(data, IT87_REG_TEMP_LOW(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 }
1366
Jean Delvare17d648b2006-08-28 14:23:46 +02001367 /* Newer chips don't have clock dividers */
Jean Delvare87673dd2006-08-28 14:37:19 +02001368 if ((data->has_fan & 0x07) && data->type != it8716
1369 && data->type != it8718) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001370 i = it87_read_value(data, IT87_REG_FAN_DIV);
Jean Delvare17d648b2006-08-28 14:23:46 +02001371 data->fan_div[0] = i & 0x07;
1372 data->fan_div[1] = (i >> 3) & 0x07;
1373 data->fan_div[2] = (i & 0x40) ? 3 : 1;
1374 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375
1376 data->alarms =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001377 it87_read_value(data, IT87_REG_ALARM1) |
1378 (it87_read_value(data, IT87_REG_ALARM2) << 8) |
1379 (it87_read_value(data, IT87_REG_ALARM3) << 16);
1380 data->fan_main_ctrl = it87_read_value(data,
1381 IT87_REG_FAN_MAIN_CTRL);
1382 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001384 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385 /* The 8705 does not have VID capability */
Jean Delvare17d648b2006-08-28 14:23:46 +02001386 if (data->type == it8712 || data->type == it8716) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001387 data->vid = it87_read_value(data, IT87_REG_VID);
Jean Delvare17d648b2006-08-28 14:23:46 +02001388 /* The older IT8712F revisions had only 5 VID pins,
1389 but we assume it is always safe to read 6 bits. */
1390 data->vid &= 0x3f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 }
1392 data->last_updated = jiffies;
1393 data->valid = 1;
1394 }
1395
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001396 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
1398 return data;
1399}
1400
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001401static int __init it87_device_add(unsigned short address,
1402 const struct it87_sio_data *sio_data)
1403{
1404 struct resource res = {
1405 .start = address ,
1406 .end = address + IT87_EXTENT - 1,
1407 .name = DRVNAME,
1408 .flags = IORESOURCE_IO,
1409 };
1410 int err;
1411
1412 pdev = platform_device_alloc(DRVNAME, address);
1413 if (!pdev) {
1414 err = -ENOMEM;
1415 printk(KERN_ERR DRVNAME ": Device allocation failed\n");
1416 goto exit;
1417 }
1418
1419 err = platform_device_add_resources(pdev, &res, 1);
1420 if (err) {
1421 printk(KERN_ERR DRVNAME ": Device resource addition failed "
1422 "(%d)\n", err);
1423 goto exit_device_put;
1424 }
1425
1426 err = platform_device_add_data(pdev, sio_data,
1427 sizeof(struct it87_sio_data));
1428 if (err) {
1429 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n");
1430 goto exit_device_put;
1431 }
1432
1433 err = platform_device_add(pdev);
1434 if (err) {
1435 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
1436 err);
1437 goto exit_device_put;
1438 }
1439
1440 return 0;
1441
1442exit_device_put:
1443 platform_device_put(pdev);
1444exit:
1445 return err;
1446}
1447
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448static int __init sm_it87_init(void)
1449{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001450 int err;
1451 unsigned short isa_address=0;
1452 struct it87_sio_data sio_data;
Jean Delvarefde09502005-07-19 23:51:07 +02001453
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001454 err = it87_find(&isa_address, &sio_data);
1455 if (err)
1456 return err;
1457 err = platform_driver_register(&it87_driver);
1458 if (err)
1459 return err;
1460
1461 err = it87_device_add(isa_address, &sio_data);
1462 if (err){
1463 platform_driver_unregister(&it87_driver);
1464 return err;
1465 }
1466
1467 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468}
1469
1470static void __exit sm_it87_exit(void)
1471{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001472 platform_device_unregister(pdev);
1473 platform_driver_unregister(&it87_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474}
1475
1476
Jean Delvareb19367c2006-08-28 14:39:26 +02001477MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>, "
1478 "Jean Delvare <khali@linux-fr.org>");
Rudolf Marek08a8f6e2007-06-09 10:11:16 -04001479MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8726F, SiS950 driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480module_param(update_vbat, bool, 0);
1481MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
1482module_param(fix_pwm_polarity, bool, 0);
1483MODULE_PARM_DESC(fix_pwm_polarity, "Force PWM polarity to active high (DANGEROUS)");
1484MODULE_LICENSE("GPL");
1485
1486module_init(sm_it87_init);
1487module_exit(sm_it87_exit);