blob: e7f14e61d6f2b1fb052ab42fd6ea5747c571eff8 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 IT8712F Super I/O chip w/LPC interface & SMBus
Jean Delvare17d648b2006-08-28 14:23:46 +02007 IT8716F Super I/O chip w/LPC interface
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 Sis950 A clone of the IT8705F
9
10 Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com>
11 Largely inspired by lm78.c of the same package
12
13 This program is free software; you can redistribute it and/or modify
14 it under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2 of the License, or
16 (at your option) any later version.
17
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26*/
27
28/*
29 djg@pdp8.net David Gesswein 7/18/01
30 Modified to fix bug with not all alarms enabled.
31 Added ability to read battery voltage and select temperature sensor
32 type at module load time.
33*/
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include <linux/module.h>
36#include <linux/init.h>
37#include <linux/slab.h>
38#include <linux/jiffies.h>
39#include <linux/i2c.h>
Jean Delvarefde09502005-07-19 23:51:07 +020040#include <linux/i2c-isa.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040041#include <linux/hwmon.h>
Jean Delvare303760b2005-07-31 21:52:01 +020042#include <linux/hwmon-sysfs.h>
43#include <linux/hwmon-vid.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040044#include <linux/err.h>
Ingo Molnar9a61bf62006-01-18 23:19:26 +010045#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <asm/io.h>
47
48
49/* Addresses to scan */
Jean Delvarec5e3fbf2006-01-18 22:39:48 +010050static unsigned short normal_i2c[] = { 0x2d, I2C_CLIENT_END };
Jean Delvare91749992005-10-08 00:10:00 +020051static unsigned short isa_address;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/* Insmod parameters */
Jean Delvare17d648b2006-08-28 14:23:46 +020054I2C_CLIENT_INSMOD_3(it87, it8712, it8716);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56#define REG 0x2e /* The register to read/write */
57#define DEV 0x07 /* Register: Logical device select */
58#define VAL 0x2f /* The value to read/write */
59#define PME 0x04 /* The device with the fan registers in it */
60#define DEVID 0x20 /* Register: Device ID */
61#define DEVREV 0x22 /* Register: Device Revision */
62
63static inline int
64superio_inb(int reg)
65{
66 outb(reg, REG);
67 return inb(VAL);
68}
69
70static int superio_inw(int reg)
71{
72 int val;
73 outb(reg++, REG);
74 val = inb(VAL) << 8;
75 outb(reg, REG);
76 val |= inb(VAL);
77 return val;
78}
79
80static inline void
81superio_select(void)
82{
83 outb(DEV, REG);
84 outb(PME, VAL);
85}
86
87static inline void
88superio_enter(void)
89{
90 outb(0x87, REG);
91 outb(0x01, REG);
92 outb(0x55, REG);
93 outb(0x55, REG);
94}
95
96static inline void
97superio_exit(void)
98{
99 outb(0x02, REG);
100 outb(0x02, VAL);
101}
102
103#define IT8712F_DEVID 0x8712
104#define IT8705F_DEVID 0x8705
Jean Delvare17d648b2006-08-28 14:23:46 +0200105#define IT8716F_DEVID 0x8716
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106#define IT87_ACT_REG 0x30
107#define IT87_BASE_REG 0x60
108
109/* Update battery voltage after every reading if true */
110static int update_vbat;
111
112/* Not all BIOSes properly configure the PWM registers */
113static int fix_pwm_polarity;
114
115/* Chip Type */
116
117static u16 chip_type;
118
119/* Many IT87 constants specified below */
120
121/* Length of ISA address segment */
122#define IT87_EXTENT 8
123
124/* Where are the ISA address/data registers relative to the base address */
125#define IT87_ADDR_REG_OFFSET 5
126#define IT87_DATA_REG_OFFSET 6
127
128/*----- The IT87 registers -----*/
129
130#define IT87_REG_CONFIG 0x00
131
132#define IT87_REG_ALARM1 0x01
133#define IT87_REG_ALARM2 0x02
134#define IT87_REG_ALARM3 0x03
135
136#define IT87_REG_VID 0x0a
Jean Delvare17d648b2006-08-28 14:23:46 +0200137/* Warning: register 0x0b is used for something completely different in
138 new chips/revisions. I suspect only 16-bit tachometer mode will work
139 for these. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140#define IT87_REG_FAN_DIV 0x0b
Jean Delvare17d648b2006-08-28 14:23:46 +0200141#define IT87_REG_FAN_16BIT 0x0c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143/* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
144
145#define IT87_REG_FAN(nr) (0x0d + (nr))
146#define IT87_REG_FAN_MIN(nr) (0x10 + (nr))
Jean Delvare17d648b2006-08-28 14:23:46 +0200147#define IT87_REG_FANX(nr) (0x18 + (nr))
148#define IT87_REG_FANX_MIN(nr) (0x1b + (nr))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149#define IT87_REG_FAN_MAIN_CTRL 0x13
150#define IT87_REG_FAN_CTL 0x14
151#define IT87_REG_PWM(nr) (0x15 + (nr))
152
153#define IT87_REG_VIN(nr) (0x20 + (nr))
154#define IT87_REG_TEMP(nr) (0x29 + (nr))
155
156#define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
157#define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
158#define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
159#define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
160
161#define IT87_REG_I2C_ADDR 0x48
162
163#define IT87_REG_VIN_ENABLE 0x50
164#define IT87_REG_TEMP_ENABLE 0x51
165
166#define IT87_REG_CHIPID 0x58
167
168#define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255))
169#define IN_FROM_REG(val) ((val) * 16)
170
171static inline u8 FAN_TO_REG(long rpm, int div)
172{
173 if (rpm == 0)
174 return 255;
175 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
176 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1,
177 254);
178}
179
Jean Delvare17d648b2006-08-28 14:23:46 +0200180static inline u16 FAN16_TO_REG(long rpm)
181{
182 if (rpm == 0)
183 return 0xffff;
184 return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
185}
186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
Jean Delvare17d648b2006-08-28 14:23:46 +0200188/* The divider is fixed to 2 in 16-bit mode */
189#define FAN16_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:1350000/((val)*2))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\
192 ((val)+500)/1000),-128,127))
193#define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*1000)
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195#define PWM_TO_REG(val) ((val) >> 1)
196#define PWM_FROM_REG(val) (((val)&0x7f) << 1)
197
198static int DIV_TO_REG(int val)
199{
200 int answer = 0;
201 while ((val >>= 1) != 0)
202 answer++;
203 return answer;
204}
205#define DIV_FROM_REG(val) (1 << (val))
206
207
208/* For each registered IT87, we need to keep some data in memory. That
209 data is pointed to by it87_list[NR]->data. The structure itself is
210 dynamically allocated, at the same time when a new it87 client is
211 allocated. */
212struct it87_data {
213 struct i2c_client client;
Mark M. Hoffman943b0832005-07-15 21:39:18 -0400214 struct class_device *class_dev;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100215 struct mutex lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 enum chips type;
217
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100218 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 char valid; /* !=0 if following fields are valid */
220 unsigned long last_updated; /* In jiffies */
221
222 u8 in[9]; /* Register value */
223 u8 in_max[9]; /* Register value */
224 u8 in_min[9]; /* Register value */
Jean Delvare17d648b2006-08-28 14:23:46 +0200225 u16 fan[3]; /* Register values, possibly combined */
226 u16 fan_min[3]; /* Register values, possibly combined */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 u8 temp[3]; /* Register value */
228 u8 temp_high[3]; /* Register value */
229 u8 temp_low[3]; /* Register value */
230 u8 sensor; /* Register value */
231 u8 fan_div[3]; /* Register encoding, shifted right */
232 u8 vid; /* Register encoding, combined */
Jean Delvarea7be58a2005-12-18 16:40:14 +0100233 u8 vrm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234 u32 alarms; /* Register encoding, combined */
235 u8 fan_main_ctrl; /* Register value */
236 u8 manual_pwm_ctl[3]; /* manual PWM value set by user */
237};
238
239
240static int it87_attach_adapter(struct i2c_adapter *adapter);
Jean Delvare2d8672c2005-07-19 23:56:35 +0200241static int it87_isa_attach_adapter(struct i2c_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242static int it87_detect(struct i2c_adapter *adapter, int address, int kind);
243static int it87_detach_client(struct i2c_client *client);
244
Darren Jenkinsf6c27fc2006-02-27 23:14:58 +0100245static int it87_read_value(struct i2c_client *client, u8 reg);
246static int it87_write_value(struct i2c_client *client, u8 reg, u8 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247static struct it87_data *it87_update_device(struct device *dev);
248static int it87_check_pwm(struct i2c_client *client);
249static void it87_init_client(struct i2c_client *client, struct it87_data *data);
250
251
252static struct i2c_driver it87_driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100253 .driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100254 .name = "it87",
255 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 .id = I2C_DRIVERID_IT87,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 .attach_adapter = it87_attach_adapter,
258 .detach_client = it87_detach_client,
259};
260
Jean Delvarefde09502005-07-19 23:51:07 +0200261static struct i2c_driver it87_isa_driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100262 .driver = {
Jean Delvare87218842006-09-03 22:36:14 +0200263 .owner = THIS_MODULE,
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100264 .name = "it87-isa",
265 },
Jean Delvare2d8672c2005-07-19 23:56:35 +0200266 .attach_adapter = it87_isa_attach_adapter,
Jean Delvarefde09502005-07-19 23:51:07 +0200267 .detach_client = it87_detach_client,
268};
269
270
Jean Delvare20ad93d2005-06-05 11:53:25 +0200271static ssize_t show_in(struct device *dev, struct device_attribute *attr,
272 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200274 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
275 int nr = sensor_attr->index;
276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 struct it87_data *data = it87_update_device(dev);
278 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
279}
280
Jean Delvare20ad93d2005-06-05 11:53:25 +0200281static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
282 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200284 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
285 int nr = sensor_attr->index;
286
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 struct it87_data *data = it87_update_device(dev);
288 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
289}
290
Jean Delvare20ad93d2005-06-05 11:53:25 +0200291static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
292 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200294 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
295 int nr = sensor_attr->index;
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 struct it87_data *data = it87_update_device(dev);
298 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
299}
300
Jean Delvare20ad93d2005-06-05 11:53:25 +0200301static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
302 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200304 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
305 int nr = sensor_attr->index;
306
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 struct i2c_client *client = to_i2c_client(dev);
308 struct it87_data *data = i2c_get_clientdata(client);
309 unsigned long val = simple_strtoul(buf, NULL, 10);
310
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100311 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 data->in_min[nr] = IN_TO_REG(val);
313 it87_write_value(client, IT87_REG_VIN_MIN(nr),
314 data->in_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100315 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 return count;
317}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200318static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
319 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200321 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
322 int nr = sensor_attr->index;
323
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 struct i2c_client *client = to_i2c_client(dev);
325 struct it87_data *data = i2c_get_clientdata(client);
326 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);
330 it87_write_value(client, IT87_REG_VIN_MAX(nr),
331 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 struct i2c_client *client = to_i2c_client(dev);
399 struct it87_data *data = i2c_get_clientdata(client);
400 int val = simple_strtol(buf, NULL, 10);
401
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100402 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 data->temp_high[nr] = TEMP_TO_REG(val);
404 it87_write_value(client, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100405 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 return count;
407}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200408static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
409 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200411 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
412 int nr = sensor_attr->index;
413
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 struct i2c_client *client = to_i2c_client(dev);
415 struct it87_data *data = i2c_get_clientdata(client);
416 int val = simple_strtol(buf, NULL, 10);
417
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100418 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419 data->temp_low[nr] = TEMP_TO_REG(val);
420 it87_write_value(client, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100421 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 return count;
423}
424#define show_temp_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200425static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
426 show_temp, NULL, offset - 1); \
427static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
428 show_temp_max, set_temp_max, offset - 1); \
429static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
430 show_temp_min, set_temp_min, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
432show_temp_offset(1);
433show_temp_offset(2);
434show_temp_offset(3);
435
Jean Delvare20ad93d2005-06-05 11:53:25 +0200436static ssize_t show_sensor(struct device *dev, struct device_attribute *attr,
437 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200439 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
440 int nr = sensor_attr->index;
441
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 struct it87_data *data = it87_update_device(dev);
443 u8 reg = data->sensor; /* In case the value is updated while we use it */
444
445 if (reg & (1 << nr))
446 return sprintf(buf, "3\n"); /* thermal diode */
447 if (reg & (8 << nr))
448 return sprintf(buf, "2\n"); /* thermistor */
449 return sprintf(buf, "0\n"); /* disabled */
450}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200451static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
452 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200454 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
455 int nr = sensor_attr->index;
456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457 struct i2c_client *client = to_i2c_client(dev);
458 struct it87_data *data = i2c_get_clientdata(client);
459 int val = simple_strtol(buf, NULL, 10);
460
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100461 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462
463 data->sensor &= ~(1 << nr);
464 data->sensor &= ~(8 << nr);
465 /* 3 = thermal diode; 2 = thermistor; 0 = disabled */
466 if (val == 3)
467 data->sensor |= 1 << nr;
468 else if (val == 2)
469 data->sensor |= 8 << nr;
470 else if (val != 0) {
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100471 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 return -EINVAL;
473 }
474 it87_write_value(client, IT87_REG_TEMP_ENABLE, data->sensor);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100475 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 return count;
477}
478#define show_sensor_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200479static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
480 show_sensor, set_sensor, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482show_sensor_offset(1);
483show_sensor_offset(2);
484show_sensor_offset(3);
485
486/* 3 Fans */
Jean Delvare20ad93d2005-06-05 11:53:25 +0200487static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
488 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200490 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
491 int nr = sensor_attr->index;
492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 struct it87_data *data = it87_update_device(dev);
494 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
495 DIV_FROM_REG(data->fan_div[nr])));
496}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200497static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
498 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200500 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
501 int nr = sensor_attr->index;
502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 struct it87_data *data = it87_update_device(dev);
504 return sprintf(buf,"%d\n",
505 FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])));
506}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200507static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
508 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200510 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
511 int nr = sensor_attr->index;
512
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 struct it87_data *data = it87_update_device(dev);
514 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
515}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200516static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr,
517 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200519 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
520 int nr = sensor_attr->index;
521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 struct it87_data *data = it87_update_device(dev);
523 return sprintf(buf,"%d\n", (data->fan_main_ctrl & (1 << nr)) ? 1 : 0);
524}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200525static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
526 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200528 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
529 int nr = sensor_attr->index;
530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 struct it87_data *data = it87_update_device(dev);
532 return sprintf(buf,"%d\n", data->manual_pwm_ctl[nr]);
533}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200534static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
535 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200537 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
538 int nr = sensor_attr->index;
539
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 struct i2c_client *client = to_i2c_client(dev);
541 struct it87_data *data = i2c_get_clientdata(client);
542 int val = simple_strtol(buf, NULL, 10);
Jean Delvare07eab462005-11-23 15:44:31 -0800543 u8 reg = it87_read_value(client, IT87_REG_FAN_DIV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100545 mutex_lock(&data->update_lock);
Jean Delvare07eab462005-11-23 15:44:31 -0800546 switch (nr) {
547 case 0: data->fan_div[nr] = reg & 0x07; break;
548 case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break;
549 case 2: data->fan_div[nr] = (reg & 0x40) ? 3 : 1; break;
550 }
551
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
553 it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100554 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 return count;
556}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200557static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
558 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200560 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
561 int nr = sensor_attr->index;
562
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 struct i2c_client *client = to_i2c_client(dev);
564 struct it87_data *data = i2c_get_clientdata(client);
565 int val = simple_strtol(buf, NULL, 10);
566 int i, min[3];
567 u8 old;
568
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100569 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 old = it87_read_value(client, IT87_REG_FAN_DIV);
571
572 for (i = 0; i < 3; i++)
573 min[i] = FAN_FROM_REG(data->fan_min[i], DIV_FROM_REG(data->fan_div[i]));
574
575 switch (nr) {
576 case 0:
577 case 1:
578 data->fan_div[nr] = DIV_TO_REG(val);
579 break;
580 case 2:
581 if (val < 8)
582 data->fan_div[nr] = 1;
583 else
584 data->fan_div[nr] = 3;
585 }
586 val = old & 0x80;
587 val |= (data->fan_div[0] & 0x07);
588 val |= (data->fan_div[1] & 0x07) << 3;
589 if (data->fan_div[2] == 3)
590 val |= 0x1 << 6;
591 it87_write_value(client, IT87_REG_FAN_DIV, val);
592
593 for (i = 0; i < 3; i++) {
594 data->fan_min[i]=FAN_TO_REG(min[i], DIV_FROM_REG(data->fan_div[i]));
595 it87_write_value(client, IT87_REG_FAN_MIN(i), data->fan_min[i]);
596 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100597 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 return count;
599}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200600static ssize_t set_pwm_enable(struct device *dev,
601 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200603 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
604 int nr = sensor_attr->index;
605
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 struct i2c_client *client = to_i2c_client(dev);
607 struct it87_data *data = i2c_get_clientdata(client);
608 int val = simple_strtol(buf, NULL, 10);
609
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100610 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
612 if (val == 0) {
613 int tmp;
614 /* make sure the fan is on when in on/off mode */
615 tmp = it87_read_value(client, IT87_REG_FAN_CTL);
616 it87_write_value(client, IT87_REG_FAN_CTL, tmp | (1 << nr));
617 /* set on/off mode */
618 data->fan_main_ctrl &= ~(1 << nr);
619 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
620 } else if (val == 1) {
621 /* set SmartGuardian mode */
622 data->fan_main_ctrl |= (1 << nr);
623 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
624 /* set saved pwm value, clear FAN_CTLX PWM mode bit */
625 it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
626 } else {
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100627 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 return -EINVAL;
629 }
630
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100631 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 return count;
633}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200634static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
635 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200637 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
638 int nr = sensor_attr->index;
639
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 struct i2c_client *client = to_i2c_client(dev);
641 struct it87_data *data = i2c_get_clientdata(client);
642 int val = simple_strtol(buf, NULL, 10);
643
644 if (val < 0 || val > 255)
645 return -EINVAL;
646
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100647 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 data->manual_pwm_ctl[nr] = val;
649 if (data->fan_main_ctrl & (1 << nr))
650 it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100651 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 return count;
653}
654
Jean Delvare20ad93d2005-06-05 11:53:25 +0200655#define show_fan_offset(offset) \
656static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
657 show_fan, NULL, offset - 1); \
658static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
659 show_fan_min, set_fan_min, offset - 1); \
660static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
661 show_fan_div, set_fan_div, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
663show_fan_offset(1);
664show_fan_offset(2);
665show_fan_offset(3);
666
667#define show_pwm_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200668static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
669 show_pwm_enable, set_pwm_enable, offset - 1); \
670static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
671 show_pwm, set_pwm, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672
673show_pwm_offset(1);
674show_pwm_offset(2);
675show_pwm_offset(3);
676
Jean Delvare17d648b2006-08-28 14:23:46 +0200677/* A different set of callbacks for 16-bit fans */
678static ssize_t show_fan16(struct device *dev, struct device_attribute *attr,
679 char *buf)
680{
681 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
682 int nr = sensor_attr->index;
683 struct it87_data *data = it87_update_device(dev);
684 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan[nr]));
685}
686
687static ssize_t show_fan16_min(struct device *dev, struct device_attribute *attr,
688 char *buf)
689{
690 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
691 int nr = sensor_attr->index;
692 struct it87_data *data = it87_update_device(dev);
693 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan_min[nr]));
694}
695
696static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
697 const char *buf, size_t count)
698{
699 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
700 int nr = sensor_attr->index;
701 struct i2c_client *client = to_i2c_client(dev);
702 struct it87_data *data = i2c_get_clientdata(client);
703 int val = simple_strtol(buf, NULL, 10);
704
705 mutex_lock(&data->update_lock);
706 data->fan_min[nr] = FAN16_TO_REG(val);
707 it87_write_value(client, IT87_REG_FAN_MIN(nr),
708 data->fan_min[nr] & 0xff);
709 it87_write_value(client, IT87_REG_FANX_MIN(nr),
710 data->fan_min[nr] >> 8);
711 mutex_unlock(&data->update_lock);
712 return count;
713}
714
715/* We want to use the same sysfs file names as 8-bit fans, but we need
716 different variable names, so we have to use SENSOR_ATTR instead of
717 SENSOR_DEVICE_ATTR. */
718#define show_fan16_offset(offset) \
719static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
720 = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
721 show_fan16, NULL, offset - 1); \
722static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \
723 = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
724 show_fan16_min, set_fan16_min, offset - 1)
725
726show_fan16_offset(1);
727show_fan16_offset(2);
728show_fan16_offset(3);
729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730/* Alarms */
Yani Ioannou30f74292005-05-17 06:41:35 -0400731static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732{
733 struct it87_data *data = it87_update_device(dev);
Jean Delvare68188ba2005-05-16 18:52:38 +0200734 return sprintf(buf, "%u\n", data->alarms);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735}
Jean Delvare1d66c642005-04-18 21:16:59 -0700736static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738static ssize_t
Yani Ioannou30f74292005-05-17 06:41:35 -0400739show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740{
741 struct it87_data *data = it87_update_device(dev);
Jean Delvarea7be58a2005-12-18 16:40:14 +0100742 return sprintf(buf, "%u\n", data->vrm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743}
744static ssize_t
Yani Ioannou30f74292005-05-17 06:41:35 -0400745store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746{
747 struct i2c_client *client = to_i2c_client(dev);
748 struct it87_data *data = i2c_get_clientdata(client);
749 u32 val;
750
751 val = simple_strtoul(buf, NULL, 10);
752 data->vrm = val;
753
754 return count;
755}
756static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
757#define device_create_file_vrm(client) \
758device_create_file(&client->dev, &dev_attr_vrm)
759
760static ssize_t
Yani Ioannou30f74292005-05-17 06:41:35 -0400761show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762{
763 struct it87_data *data = it87_update_device(dev);
764 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
765}
766static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
767#define device_create_file_vid(client) \
768device_create_file(&client->dev, &dev_attr_cpu0_vid)
769
770/* This function is called when:
771 * it87_driver is inserted (when this module is loaded), for each
772 available adapter
773 * when a new adapter is inserted (and it87_driver is still present) */
774static int it87_attach_adapter(struct i2c_adapter *adapter)
775{
776 if (!(adapter->class & I2C_CLASS_HWMON))
777 return 0;
Jean Delvare2ed2dc32005-07-31 21:42:02 +0200778 return i2c_probe(adapter, &addr_data, it87_detect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779}
780
Jean Delvare2d8672c2005-07-19 23:56:35 +0200781static int it87_isa_attach_adapter(struct i2c_adapter *adapter)
782{
783 return it87_detect(adapter, isa_address, -1);
784}
785
786/* SuperIO detection - will change isa_address if a chip is found */
Jean Delvare91749992005-10-08 00:10:00 +0200787static int __init it87_find(unsigned short *address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788{
789 int err = -ENODEV;
790
791 superio_enter();
792 chip_type = superio_inw(DEVID);
793 if (chip_type != IT8712F_DEVID
Jean Delvare17d648b2006-08-28 14:23:46 +0200794 && chip_type != IT8716F_DEVID
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 && chip_type != IT8705F_DEVID)
796 goto exit;
797
798 superio_select();
799 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
800 pr_info("it87: Device not activated, skipping\n");
801 goto exit;
802 }
803
804 *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
805 if (*address == 0) {
806 pr_info("it87: Base address not set, skipping\n");
807 goto exit;
808 }
809
810 err = 0;
811 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n",
812 chip_type, *address, superio_inb(DEVREV) & 0x0f);
813
814exit:
815 superio_exit();
816 return err;
817}
818
Jean Delvare2ed2dc32005-07-31 21:42:02 +0200819/* This function is called by i2c_probe */
Ben Dooksc49efce2005-10-26 21:07:25 +0200820static int it87_detect(struct i2c_adapter *adapter, int address, int kind)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
822 int i;
823 struct i2c_client *new_client;
824 struct it87_data *data;
825 int err = 0;
826 const char *name = "";
827 int is_isa = i2c_is_isa_adapter(adapter);
828 int enable_pwm_interface;
829
830 if (!is_isa &&
831 !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
832 goto ERROR0;
833
834 /* Reserve the ISA region */
835 if (is_isa)
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100836 if (!request_region(address, IT87_EXTENT,
837 it87_isa_driver.driver.name))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 goto ERROR0;
839
Jean Delvare91749992005-10-08 00:10:00 +0200840 /* For now, we presume we have a valid client. We create the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 client structure, even though we cannot fill it completely yet.
842 But it allows us to access it87_{read,write}_value. */
843
Deepak Saxenaba9c2e82005-10-17 23:08:32 +0200844 if (!(data = kzalloc(sizeof(struct it87_data), GFP_KERNEL))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 err = -ENOMEM;
846 goto ERROR1;
847 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848
849 new_client = &data->client;
850 if (is_isa)
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100851 mutex_init(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 i2c_set_clientdata(new_client, data);
853 new_client->addr = address;
854 new_client->adapter = adapter;
Jean Delvarefde09502005-07-19 23:51:07 +0200855 new_client->driver = is_isa ? &it87_isa_driver : &it87_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 new_client->flags = 0;
857
858 /* Now, we do the remaining detection. */
859
860 if (kind < 0) {
861 if ((it87_read_value(new_client, IT87_REG_CONFIG) & 0x80)
862 || (!is_isa
863 && it87_read_value(new_client, IT87_REG_I2C_ADDR) != address)) {
864 err = -ENODEV;
865 goto ERROR2;
866 }
867 }
868
869 /* Determine the chip type. */
870 if (kind <= 0) {
871 i = it87_read_value(new_client, IT87_REG_CHIPID);
872 if (i == 0x90) {
873 kind = it87;
Jean Delvare17d648b2006-08-28 14:23:46 +0200874 if (is_isa) {
875 switch (chip_type) {
876 case IT8712F_DEVID:
877 kind = it8712;
878 break;
879 case IT8716F_DEVID:
880 kind = it8716;
881 break;
882 }
883 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700884 }
885 else {
886 if (kind == 0)
887 dev_info(&adapter->dev,
888 "Ignoring 'force' parameter for unknown chip at "
889 "adapter %d, address 0x%02x\n",
890 i2c_adapter_id(adapter), address);
891 err = -ENODEV;
892 goto ERROR2;
893 }
894 }
895
896 if (kind == it87) {
897 name = "it87";
898 } else if (kind == it8712) {
899 name = "it8712";
Jean Delvare17d648b2006-08-28 14:23:46 +0200900 } else if (kind == it8716) {
901 name = "it8716";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 }
903
904 /* Fill in the remaining client fields and put it into the global list */
905 strlcpy(new_client->name, name, I2C_NAME_SIZE);
906 data->type = kind;
907 data->valid = 0;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100908 mutex_init(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
910 /* Tell the I2C layer a new client has arrived */
911 if ((err = i2c_attach_client(new_client)))
912 goto ERROR2;
913
Jean Delvarec5e3fbf2006-01-18 22:39:48 +0100914 if (!is_isa)
915 dev_info(&new_client->dev, "The I2C interface to IT87xxF "
916 "hardware monitoring chips is deprecated. Please "
917 "report if you still rely on it.\n");
918
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 /* Check PWM configuration */
920 enable_pwm_interface = it87_check_pwm(new_client);
921
922 /* Initialize the IT87 chip */
923 it87_init_client(new_client, data);
924
925 /* Register sysfs hooks */
Mark M. Hoffman943b0832005-07-15 21:39:18 -0400926 data->class_dev = hwmon_device_register(&new_client->dev);
927 if (IS_ERR(data->class_dev)) {
928 err = PTR_ERR(data->class_dev);
929 goto ERROR3;
930 }
931
Jean Delvare20ad93d2005-06-05 11:53:25 +0200932 device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr);
933 device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr);
934 device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr);
935 device_create_file(&new_client->dev, &sensor_dev_attr_in3_input.dev_attr);
936 device_create_file(&new_client->dev, &sensor_dev_attr_in4_input.dev_attr);
937 device_create_file(&new_client->dev, &sensor_dev_attr_in5_input.dev_attr);
938 device_create_file(&new_client->dev, &sensor_dev_attr_in6_input.dev_attr);
939 device_create_file(&new_client->dev, &sensor_dev_attr_in7_input.dev_attr);
940 device_create_file(&new_client->dev, &sensor_dev_attr_in8_input.dev_attr);
941 device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr);
942 device_create_file(&new_client->dev, &sensor_dev_attr_in1_min.dev_attr);
943 device_create_file(&new_client->dev, &sensor_dev_attr_in2_min.dev_attr);
944 device_create_file(&new_client->dev, &sensor_dev_attr_in3_min.dev_attr);
945 device_create_file(&new_client->dev, &sensor_dev_attr_in4_min.dev_attr);
946 device_create_file(&new_client->dev, &sensor_dev_attr_in5_min.dev_attr);
947 device_create_file(&new_client->dev, &sensor_dev_attr_in6_min.dev_attr);
948 device_create_file(&new_client->dev, &sensor_dev_attr_in7_min.dev_attr);
949 device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr);
950 device_create_file(&new_client->dev, &sensor_dev_attr_in1_max.dev_attr);
951 device_create_file(&new_client->dev, &sensor_dev_attr_in2_max.dev_attr);
952 device_create_file(&new_client->dev, &sensor_dev_attr_in3_max.dev_attr);
953 device_create_file(&new_client->dev, &sensor_dev_attr_in4_max.dev_attr);
954 device_create_file(&new_client->dev, &sensor_dev_attr_in5_max.dev_attr);
955 device_create_file(&new_client->dev, &sensor_dev_attr_in6_max.dev_attr);
956 device_create_file(&new_client->dev, &sensor_dev_attr_in7_max.dev_attr);
957 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_input.dev_attr);
958 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_input.dev_attr);
959 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_input.dev_attr);
960 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_max.dev_attr);
961 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_max.dev_attr);
962 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_max.dev_attr);
963 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_min.dev_attr);
964 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_min.dev_attr);
965 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_min.dev_attr);
966 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_type.dev_attr);
967 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_type.dev_attr);
968 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_type.dev_attr);
Jean Delvare17d648b2006-08-28 14:23:46 +0200969
970 if (data->type == it8716) { /* 16-bit tachometers */
971 device_create_file(&new_client->dev,
972 &sensor_dev_attr_fan1_input16.dev_attr);
973 device_create_file(&new_client->dev,
974 &sensor_dev_attr_fan2_input16.dev_attr);
975 device_create_file(&new_client->dev,
976 &sensor_dev_attr_fan3_input16.dev_attr);
977 device_create_file(&new_client->dev,
978 &sensor_dev_attr_fan1_min16.dev_attr);
979 device_create_file(&new_client->dev,
980 &sensor_dev_attr_fan2_min16.dev_attr);
981 device_create_file(&new_client->dev,
982 &sensor_dev_attr_fan3_min16.dev_attr);
983 } else {
984 device_create_file(&new_client->dev,
985 &sensor_dev_attr_fan1_input.dev_attr);
986 device_create_file(&new_client->dev,
987 &sensor_dev_attr_fan2_input.dev_attr);
988 device_create_file(&new_client->dev,
989 &sensor_dev_attr_fan3_input.dev_attr);
990 device_create_file(&new_client->dev,
991 &sensor_dev_attr_fan1_min.dev_attr);
992 device_create_file(&new_client->dev,
993 &sensor_dev_attr_fan2_min.dev_attr);
994 device_create_file(&new_client->dev,
995 &sensor_dev_attr_fan3_min.dev_attr);
996 device_create_file(&new_client->dev,
997 &sensor_dev_attr_fan1_div.dev_attr);
998 device_create_file(&new_client->dev,
999 &sensor_dev_attr_fan2_div.dev_attr);
1000 device_create_file(&new_client->dev,
1001 &sensor_dev_attr_fan3_div.dev_attr);
1002 }
1003
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 device_create_file(&new_client->dev, &dev_attr_alarms);
1005 if (enable_pwm_interface) {
Jean Delvare20ad93d2005-06-05 11:53:25 +02001006 device_create_file(&new_client->dev, &sensor_dev_attr_pwm1_enable.dev_attr);
1007 device_create_file(&new_client->dev, &sensor_dev_attr_pwm2_enable.dev_attr);
1008 device_create_file(&new_client->dev, &sensor_dev_attr_pwm3_enable.dev_attr);
1009 device_create_file(&new_client->dev, &sensor_dev_attr_pwm1.dev_attr);
1010 device_create_file(&new_client->dev, &sensor_dev_attr_pwm2.dev_attr);
1011 device_create_file(&new_client->dev, &sensor_dev_attr_pwm3.dev_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 }
1013
Jean Delvare17d648b2006-08-28 14:23:46 +02001014 if (data->type == it8712 || data->type == it8716) {
Jean Delvare303760b2005-07-31 21:52:01 +02001015 data->vrm = vid_which_vrm();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 device_create_file_vrm(new_client);
1017 device_create_file_vid(new_client);
1018 }
1019
1020 return 0;
1021
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001022ERROR3:
1023 i2c_detach_client(new_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024ERROR2:
1025 kfree(data);
1026ERROR1:
1027 if (is_isa)
1028 release_region(address, IT87_EXTENT);
1029ERROR0:
1030 return err;
1031}
1032
1033static int it87_detach_client(struct i2c_client *client)
1034{
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001035 struct it87_data *data = i2c_get_clientdata(client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 int err;
1037
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001038 hwmon_device_unregister(data->class_dev);
1039
Jean Delvare7bef5592005-07-27 22:14:49 +02001040 if ((err = i2c_detach_client(client)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042
1043 if(i2c_is_isa_client(client))
1044 release_region(client->addr, IT87_EXTENT);
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001045 kfree(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046
1047 return 0;
1048}
1049
Steven Cole44bbe872005-05-03 18:21:25 -06001050/* The SMBus locks itself, but ISA access must be locked explicitly!
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051 We don't want to lock the whole ISA bus, so we lock each client
1052 separately.
1053 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1054 would slow down the IT87 access and should not be necessary. */
1055static int it87_read_value(struct i2c_client *client, u8 reg)
1056{
1057 struct it87_data *data = i2c_get_clientdata(client);
1058
1059 int res;
1060 if (i2c_is_isa_client(client)) {
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001061 mutex_lock(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET);
1063 res = inb_p(client->addr + IT87_DATA_REG_OFFSET);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001064 mutex_unlock(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 return res;
1066 } else
1067 return i2c_smbus_read_byte_data(client, reg);
1068}
1069
Steven Cole44bbe872005-05-03 18:21:25 -06001070/* The SMBus locks itself, but ISA access muse be locked explicitly!
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071 We don't want to lock the whole ISA bus, so we lock each client
1072 separately.
1073 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1074 would slow down the IT87 access and should not be necessary. */
1075static int it87_write_value(struct i2c_client *client, u8 reg, u8 value)
1076{
1077 struct it87_data *data = i2c_get_clientdata(client);
1078
1079 if (i2c_is_isa_client(client)) {
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001080 mutex_lock(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001081 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET);
1082 outb_p(value, client->addr + IT87_DATA_REG_OFFSET);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001083 mutex_unlock(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084 return 0;
1085 } else
1086 return i2c_smbus_write_byte_data(client, reg, value);
1087}
1088
1089/* Return 1 if and only if the PWM interface is safe to use */
1090static int it87_check_pwm(struct i2c_client *client)
1091{
1092 /* Some BIOSes fail to correctly configure the IT87 fans. All fans off
1093 * and polarity set to active low is sign that this is the case so we
1094 * disable pwm control to protect the user. */
1095 int tmp = it87_read_value(client, IT87_REG_FAN_CTL);
1096 if ((tmp & 0x87) == 0) {
1097 if (fix_pwm_polarity) {
1098 /* The user asks us to attempt a chip reconfiguration.
1099 * This means switching to active high polarity and
1100 * inverting all fan speed values. */
1101 int i;
1102 u8 pwm[3];
1103
1104 for (i = 0; i < 3; i++)
1105 pwm[i] = it87_read_value(client,
1106 IT87_REG_PWM(i));
1107
1108 /* If any fan is in automatic pwm mode, the polarity
1109 * might be correct, as suspicious as it seems, so we
1110 * better don't change anything (but still disable the
1111 * PWM interface). */
1112 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
1113 dev_info(&client->dev, "Reconfiguring PWM to "
1114 "active high polarity\n");
1115 it87_write_value(client, IT87_REG_FAN_CTL,
1116 tmp | 0x87);
1117 for (i = 0; i < 3; i++)
1118 it87_write_value(client,
1119 IT87_REG_PWM(i),
1120 0x7f & ~pwm[i]);
1121 return 1;
1122 }
1123
1124 dev_info(&client->dev, "PWM configuration is "
1125 "too broken to be fixed\n");
1126 }
1127
1128 dev_info(&client->dev, "Detected broken BIOS "
1129 "defaults, disabling PWM interface\n");
1130 return 0;
1131 } else if (fix_pwm_polarity) {
1132 dev_info(&client->dev, "PWM configuration looks "
1133 "sane, won't touch\n");
1134 }
1135
1136 return 1;
1137}
1138
1139/* Called when we have found a new IT87. */
1140static void it87_init_client(struct i2c_client *client, struct it87_data *data)
1141{
1142 int tmp, i;
1143
1144 /* initialize to sane defaults:
1145 * - if the chip is in manual pwm mode, this will be overwritten with
1146 * the actual settings on the chip (so in this case, initialization
1147 * is not needed)
1148 * - if in automatic or on/off mode, we could switch to manual mode,
1149 * read the registers and set manual_pwm_ctl accordingly, but currently
1150 * this is not implemented, so we initialize to something sane */
1151 for (i = 0; i < 3; i++) {
1152 data->manual_pwm_ctl[i] = 0xff;
1153 }
1154
1155 /* Check if temperature channnels are reset manually or by some reason */
1156 tmp = it87_read_value(client, IT87_REG_TEMP_ENABLE);
1157 if ((tmp & 0x3f) == 0) {
1158 /* Temp1,Temp3=thermistor; Temp2=thermal diode */
1159 tmp = (tmp & 0xc0) | 0x2a;
1160 it87_write_value(client, IT87_REG_TEMP_ENABLE, tmp);
1161 }
1162 data->sensor = tmp;
1163
1164 /* Check if voltage monitors are reset manually or by some reason */
1165 tmp = it87_read_value(client, IT87_REG_VIN_ENABLE);
1166 if ((tmp & 0xff) == 0) {
1167 /* Enable all voltage monitors */
1168 it87_write_value(client, IT87_REG_VIN_ENABLE, 0xff);
1169 }
1170
1171 /* Check if tachometers are reset manually or by some reason */
1172 data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL);
1173 if ((data->fan_main_ctrl & 0x70) == 0) {
1174 /* Enable all fan tachometers */
1175 data->fan_main_ctrl |= 0x70;
1176 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
1177 }
1178
Jean Delvare17d648b2006-08-28 14:23:46 +02001179 /* Set tachometers to 16-bit mode if needed */
1180 if (data->type == it8716) {
1181 tmp = it87_read_value(client, IT87_REG_FAN_16BIT);
1182 if ((tmp & 0x07) != 0x07) {
1183 dev_dbg(&client->dev,
1184 "Setting fan1-3 to 16-bit mode\n");
1185 it87_write_value(client, IT87_REG_FAN_16BIT,
1186 tmp | 0x07);
1187 }
1188 }
1189
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 /* Set current fan mode registers and the default settings for the
1191 * other mode registers */
1192 for (i = 0; i < 3; i++) {
1193 if (data->fan_main_ctrl & (1 << i)) {
1194 /* pwm mode */
1195 tmp = it87_read_value(client, IT87_REG_PWM(i));
1196 if (tmp & 0x80) {
1197 /* automatic pwm - not yet implemented, but
1198 * leave the settings made by the BIOS alone
1199 * until a change is requested via the sysfs
1200 * interface */
1201 } else {
1202 /* manual pwm */
1203 data->manual_pwm_ctl[i] = PWM_FROM_REG(tmp);
1204 }
1205 }
1206 }
1207
1208 /* Start monitoring */
1209 it87_write_value(client, IT87_REG_CONFIG,
1210 (it87_read_value(client, IT87_REG_CONFIG) & 0x36)
1211 | (update_vbat ? 0x41 : 0x01));
1212}
1213
1214static struct it87_data *it87_update_device(struct device *dev)
1215{
1216 struct i2c_client *client = to_i2c_client(dev);
1217 struct it87_data *data = i2c_get_clientdata(client);
1218 int i;
1219
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001220 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
1222 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
1223 || !data->valid) {
1224
1225 if (update_vbat) {
1226 /* Cleared after each update, so reenable. Value
1227 returned by this read will be previous value */
1228 it87_write_value(client, IT87_REG_CONFIG,
1229 it87_read_value(client, IT87_REG_CONFIG) | 0x40);
1230 }
1231 for (i = 0; i <= 7; i++) {
1232 data->in[i] =
1233 it87_read_value(client, IT87_REG_VIN(i));
1234 data->in_min[i] =
1235 it87_read_value(client, IT87_REG_VIN_MIN(i));
1236 data->in_max[i] =
1237 it87_read_value(client, IT87_REG_VIN_MAX(i));
1238 }
1239 data->in[8] =
1240 it87_read_value(client, IT87_REG_VIN(8));
1241 /* Temperature sensor doesn't have limit registers, set
1242 to min and max value */
1243 data->in_min[8] = 0;
1244 data->in_max[8] = 255;
1245
1246 for (i = 0; i < 3; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 data->fan_min[i] =
1248 it87_read_value(client, IT87_REG_FAN_MIN(i));
Jean Delvare17d648b2006-08-28 14:23:46 +02001249 data->fan[i] = it87_read_value(client,
1250 IT87_REG_FAN(i));
1251 /* Add high byte if in 16-bit mode */
1252 if (data->type == it8716) {
1253 data->fan[i] |= it87_read_value(client,
1254 IT87_REG_FANX(i)) << 8;
1255 data->fan_min[i] |= it87_read_value(client,
1256 IT87_REG_FANX_MIN(i)) << 8;
1257 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 }
1259 for (i = 0; i < 3; i++) {
1260 data->temp[i] =
1261 it87_read_value(client, IT87_REG_TEMP(i));
1262 data->temp_high[i] =
1263 it87_read_value(client, IT87_REG_TEMP_HIGH(i));
1264 data->temp_low[i] =
1265 it87_read_value(client, IT87_REG_TEMP_LOW(i));
1266 }
1267
Jean Delvare17d648b2006-08-28 14:23:46 +02001268 /* Newer chips don't have clock dividers */
1269 if (data->type != it8716) {
1270 i = it87_read_value(client, IT87_REG_FAN_DIV);
1271 data->fan_div[0] = i & 0x07;
1272 data->fan_div[1] = (i >> 3) & 0x07;
1273 data->fan_div[2] = (i & 0x40) ? 3 : 1;
1274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
1276 data->alarms =
1277 it87_read_value(client, IT87_REG_ALARM1) |
1278 (it87_read_value(client, IT87_REG_ALARM2) << 8) |
1279 (it87_read_value(client, IT87_REG_ALARM3) << 16);
1280 data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL);
1281
1282 data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE);
1283 /* The 8705 does not have VID capability */
Jean Delvare17d648b2006-08-28 14:23:46 +02001284 if (data->type == it8712 || data->type == it8716) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285 data->vid = it87_read_value(client, IT87_REG_VID);
Jean Delvare17d648b2006-08-28 14:23:46 +02001286 /* The older IT8712F revisions had only 5 VID pins,
1287 but we assume it is always safe to read 6 bits. */
1288 data->vid &= 0x3f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 }
1290 data->last_updated = jiffies;
1291 data->valid = 1;
1292 }
1293
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001294 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001295
1296 return data;
1297}
1298
1299static int __init sm_it87_init(void)
1300{
Jean Delvare91749992005-10-08 00:10:00 +02001301 int res;
Jean Delvarefde09502005-07-19 23:51:07 +02001302
1303 res = i2c_add_driver(&it87_driver);
1304 if (res)
1305 return res;
1306
Jean Delvare91749992005-10-08 00:10:00 +02001307 if (!it87_find(&isa_address)) {
1308 res = i2c_isa_add_driver(&it87_isa_driver);
1309 if (res) {
1310 i2c_del_driver(&it87_driver);
1311 return res;
1312 }
Jean Delvarefde09502005-07-19 23:51:07 +02001313 }
1314
1315 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001316}
1317
1318static void __exit sm_it87_exit(void)
1319{
Jean Delvarebe79c382006-02-07 17:53:32 +01001320 if (isa_address)
1321 i2c_isa_del_driver(&it87_isa_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 i2c_del_driver(&it87_driver);
1323}
1324
1325
1326MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>");
Jean Delvare17d648b2006-08-28 14:23:46 +02001327MODULE_DESCRIPTION("IT8705F/8712F/8716F, SiS950 driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328module_param(update_vbat, bool, 0);
1329MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
1330module_param(fix_pwm_polarity, bool, 0);
1331MODULE_PARM_DESC(fix_pwm_polarity, "Force PWM polarity to active high (DANGEROUS)");
1332MODULE_LICENSE("GPL");
1333
1334module_init(sm_it87_init);
1335module_exit(sm_it87_exit);