blob: fc75fcb6bffdb0bd543ea24e0bdfbb67bdf859be [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;
Jean Delvareb9e349f2006-08-28 14:26:22 +0200201 while (answer < 7 && (val >>= 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 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 Delvare9060f8b2006-08-28 14:24:17 +0200225 u8 has_fan; /* Bitfield, fans enabled */
Jean Delvare17d648b2006-08-28 14:23:46 +0200226 u16 fan[3]; /* Register values, possibly combined */
227 u16 fan_min[3]; /* Register values, possibly combined */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 u8 temp[3]; /* Register value */
229 u8 temp_high[3]; /* Register value */
230 u8 temp_low[3]; /* Register value */
231 u8 sensor; /* Register value */
232 u8 fan_div[3]; /* Register encoding, shifted right */
233 u8 vid; /* Register encoding, combined */
Jean Delvarea7be58a2005-12-18 16:40:14 +0100234 u8 vrm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235 u32 alarms; /* Register encoding, combined */
236 u8 fan_main_ctrl; /* Register value */
237 u8 manual_pwm_ctl[3]; /* manual PWM value set by user */
238};
239
240
241static int it87_attach_adapter(struct i2c_adapter *adapter);
Jean Delvare2d8672c2005-07-19 23:56:35 +0200242static int it87_isa_attach_adapter(struct i2c_adapter *adapter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243static int it87_detect(struct i2c_adapter *adapter, int address, int kind);
244static int it87_detach_client(struct i2c_client *client);
245
Darren Jenkinsf6c27fc2006-02-27 23:14:58 +0100246static int it87_read_value(struct i2c_client *client, u8 reg);
247static int it87_write_value(struct i2c_client *client, u8 reg, u8 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248static struct it87_data *it87_update_device(struct device *dev);
249static int it87_check_pwm(struct i2c_client *client);
250static void it87_init_client(struct i2c_client *client, struct it87_data *data);
251
252
253static struct i2c_driver it87_driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100254 .driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100255 .name = "it87",
256 },
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 .id = I2C_DRIVERID_IT87,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 .attach_adapter = it87_attach_adapter,
259 .detach_client = it87_detach_client,
260};
261
Jean Delvarefde09502005-07-19 23:51:07 +0200262static struct i2c_driver it87_isa_driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100263 .driver = {
Jean Delvare87218842006-09-03 22:36:14 +0200264 .owner = THIS_MODULE,
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100265 .name = "it87-isa",
266 },
Jean Delvare2d8672c2005-07-19 23:56:35 +0200267 .attach_adapter = it87_isa_attach_adapter,
Jean Delvarefde09502005-07-19 23:51:07 +0200268 .detach_client = it87_detach_client,
269};
270
271
Jean Delvare20ad93d2005-06-05 11:53:25 +0200272static ssize_t show_in(struct device *dev, struct device_attribute *attr,
273 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200275 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
276 int nr = sensor_attr->index;
277
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 struct it87_data *data = it87_update_device(dev);
279 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
280}
281
Jean Delvare20ad93d2005-06-05 11:53:25 +0200282static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
283 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200285 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
286 int nr = sensor_attr->index;
287
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 struct it87_data *data = it87_update_device(dev);
289 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
290}
291
Jean Delvare20ad93d2005-06-05 11:53:25 +0200292static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
293 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200295 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
296 int nr = sensor_attr->index;
297
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 struct it87_data *data = it87_update_device(dev);
299 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
300}
301
Jean Delvare20ad93d2005-06-05 11:53:25 +0200302static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
303 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200305 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
306 int nr = sensor_attr->index;
307
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 struct i2c_client *client = to_i2c_client(dev);
309 struct it87_data *data = i2c_get_clientdata(client);
310 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);
314 it87_write_value(client, IT87_REG_VIN_MIN(nr),
315 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 struct i2c_client *client = to_i2c_client(dev);
326 struct it87_data *data = i2c_get_clientdata(client);
327 unsigned long val = simple_strtoul(buf, NULL, 10);
328
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100329 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 data->in_max[nr] = IN_TO_REG(val);
331 it87_write_value(client, IT87_REG_VIN_MAX(nr),
332 data->in_max[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100333 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 return count;
335}
336
337#define show_in_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200338static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
339 show_in, NULL, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
341#define limit_in_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200342static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
343 show_in_min, set_in_min, offset); \
344static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
345 show_in_max, set_in_max, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347show_in_offset(0);
348limit_in_offset(0);
349show_in_offset(1);
350limit_in_offset(1);
351show_in_offset(2);
352limit_in_offset(2);
353show_in_offset(3);
354limit_in_offset(3);
355show_in_offset(4);
356limit_in_offset(4);
357show_in_offset(5);
358limit_in_offset(5);
359show_in_offset(6);
360limit_in_offset(6);
361show_in_offset(7);
362limit_in_offset(7);
363show_in_offset(8);
364
365/* 3 temperatures */
Jean Delvare20ad93d2005-06-05 11:53:25 +0200366static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
367 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200369 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
370 int nr = sensor_attr->index;
371
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 struct it87_data *data = it87_update_device(dev);
373 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
374}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200375static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr,
376 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200378 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
379 int nr = sensor_attr->index;
380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 struct it87_data *data = it87_update_device(dev);
382 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr]));
383}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200384static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
385 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200387 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
388 int nr = sensor_attr->index;
389
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 struct it87_data *data = it87_update_device(dev);
391 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr]));
392}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200393static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
394 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200396 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
397 int nr = sensor_attr->index;
398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 struct i2c_client *client = to_i2c_client(dev);
400 struct it87_data *data = i2c_get_clientdata(client);
401 int val = simple_strtol(buf, NULL, 10);
402
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100403 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 data->temp_high[nr] = TEMP_TO_REG(val);
405 it87_write_value(client, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100406 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 return count;
408}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200409static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
410 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200412 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
413 int nr = sensor_attr->index;
414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 struct i2c_client *client = to_i2c_client(dev);
416 struct it87_data *data = i2c_get_clientdata(client);
417 int val = simple_strtol(buf, NULL, 10);
418
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100419 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 data->temp_low[nr] = TEMP_TO_REG(val);
421 it87_write_value(client, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100422 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 return count;
424}
425#define show_temp_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200426static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
427 show_temp, NULL, offset - 1); \
428static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
429 show_temp_max, set_temp_max, offset - 1); \
430static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
431 show_temp_min, set_temp_min, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
433show_temp_offset(1);
434show_temp_offset(2);
435show_temp_offset(3);
436
Jean Delvare20ad93d2005-06-05 11:53:25 +0200437static ssize_t show_sensor(struct device *dev, struct device_attribute *attr,
438 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200440 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
441 int nr = sensor_attr->index;
442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 struct it87_data *data = it87_update_device(dev);
444 u8 reg = data->sensor; /* In case the value is updated while we use it */
445
446 if (reg & (1 << nr))
447 return sprintf(buf, "3\n"); /* thermal diode */
448 if (reg & (8 << nr))
449 return sprintf(buf, "2\n"); /* thermistor */
450 return sprintf(buf, "0\n"); /* disabled */
451}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200452static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
453 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200455 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
456 int nr = sensor_attr->index;
457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 struct i2c_client *client = to_i2c_client(dev);
459 struct it87_data *data = i2c_get_clientdata(client);
460 int val = simple_strtol(buf, NULL, 10);
461
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100462 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463
464 data->sensor &= ~(1 << nr);
465 data->sensor &= ~(8 << nr);
466 /* 3 = thermal diode; 2 = thermistor; 0 = disabled */
467 if (val == 3)
468 data->sensor |= 1 << nr;
469 else if (val == 2)
470 data->sensor |= 8 << nr;
471 else if (val != 0) {
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100472 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 return -EINVAL;
474 }
475 it87_write_value(client, IT87_REG_TEMP_ENABLE, data->sensor);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100476 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 return count;
478}
479#define show_sensor_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200480static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
481 show_sensor, set_sensor, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483show_sensor_offset(1);
484show_sensor_offset(2);
485show_sensor_offset(3);
486
487/* 3 Fans */
Jean Delvare20ad93d2005-06-05 11:53:25 +0200488static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
489 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200491 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
492 int nr = sensor_attr->index;
493
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 struct it87_data *data = it87_update_device(dev);
495 return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr],
496 DIV_FROM_REG(data->fan_div[nr])));
497}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200498static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
499 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200501 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
502 int nr = sensor_attr->index;
503
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 struct it87_data *data = it87_update_device(dev);
505 return sprintf(buf,"%d\n",
506 FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])));
507}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200508static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
509 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200511 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
512 int nr = sensor_attr->index;
513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514 struct it87_data *data = it87_update_device(dev);
515 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
516}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200517static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr,
518 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200520 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
521 int nr = sensor_attr->index;
522
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 struct it87_data *data = it87_update_device(dev);
524 return sprintf(buf,"%d\n", (data->fan_main_ctrl & (1 << nr)) ? 1 : 0);
525}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200526static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
527 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200529 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
530 int nr = sensor_attr->index;
531
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 struct it87_data *data = it87_update_device(dev);
533 return sprintf(buf,"%d\n", data->manual_pwm_ctl[nr]);
534}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200535static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
536 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200538 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
539 int nr = sensor_attr->index;
540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 struct i2c_client *client = to_i2c_client(dev);
542 struct it87_data *data = i2c_get_clientdata(client);
543 int val = simple_strtol(buf, NULL, 10);
Jean Delvare07eab462005-11-23 15:44:31 -0800544 u8 reg = it87_read_value(client, IT87_REG_FAN_DIV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100546 mutex_lock(&data->update_lock);
Jean Delvare07eab462005-11-23 15:44:31 -0800547 switch (nr) {
548 case 0: data->fan_div[nr] = reg & 0x07; break;
549 case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break;
550 case 2: data->fan_div[nr] = (reg & 0x40) ? 3 : 1; break;
551 }
552
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
554 it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100555 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 return count;
557}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200558static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
559 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200561 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
562 int nr = sensor_attr->index;
563
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 struct i2c_client *client = to_i2c_client(dev);
565 struct it87_data *data = i2c_get_clientdata(client);
Jean Delvareb9e349f2006-08-28 14:26:22 +0200566 unsigned long val = simple_strtoul(buf, NULL, 10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 int i, min[3];
568 u8 old;
569
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100570 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 old = it87_read_value(client, IT87_REG_FAN_DIV);
572
573 for (i = 0; i < 3; i++)
574 min[i] = FAN_FROM_REG(data->fan_min[i], DIV_FROM_REG(data->fan_div[i]));
575
576 switch (nr) {
577 case 0:
578 case 1:
579 data->fan_div[nr] = DIV_TO_REG(val);
580 break;
581 case 2:
582 if (val < 8)
583 data->fan_div[nr] = 1;
584 else
585 data->fan_div[nr] = 3;
586 }
587 val = old & 0x80;
588 val |= (data->fan_div[0] & 0x07);
589 val |= (data->fan_div[1] & 0x07) << 3;
590 if (data->fan_div[2] == 3)
591 val |= 0x1 << 6;
592 it87_write_value(client, IT87_REG_FAN_DIV, val);
593
594 for (i = 0; i < 3; i++) {
595 data->fan_min[i]=FAN_TO_REG(min[i], DIV_FROM_REG(data->fan_div[i]));
596 it87_write_value(client, IT87_REG_FAN_MIN(i), data->fan_min[i]);
597 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100598 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 return count;
600}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200601static ssize_t set_pwm_enable(struct device *dev,
602 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200604 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
605 int nr = sensor_attr->index;
606
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 struct i2c_client *client = to_i2c_client(dev);
608 struct it87_data *data = i2c_get_clientdata(client);
609 int val = simple_strtol(buf, NULL, 10);
610
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100611 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613 if (val == 0) {
614 int tmp;
615 /* make sure the fan is on when in on/off mode */
616 tmp = it87_read_value(client, IT87_REG_FAN_CTL);
617 it87_write_value(client, IT87_REG_FAN_CTL, tmp | (1 << nr));
618 /* set on/off mode */
619 data->fan_main_ctrl &= ~(1 << nr);
620 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
621 } else if (val == 1) {
622 /* set SmartGuardian mode */
623 data->fan_main_ctrl |= (1 << nr);
624 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
625 /* set saved pwm value, clear FAN_CTLX PWM mode bit */
626 it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
627 } else {
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100628 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 return -EINVAL;
630 }
631
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100632 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 return count;
634}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200635static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
636 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200638 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
639 int nr = sensor_attr->index;
640
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 struct i2c_client *client = to_i2c_client(dev);
642 struct it87_data *data = i2c_get_clientdata(client);
643 int val = simple_strtol(buf, NULL, 10);
644
645 if (val < 0 || val > 255)
646 return -EINVAL;
647
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100648 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 data->manual_pwm_ctl[nr] = val;
650 if (data->fan_main_ctrl & (1 << nr))
651 it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr]));
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100652 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 return count;
654}
655
Jean Delvare20ad93d2005-06-05 11:53:25 +0200656#define show_fan_offset(offset) \
657static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
658 show_fan, NULL, offset - 1); \
659static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
660 show_fan_min, set_fan_min, offset - 1); \
661static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
662 show_fan_div, set_fan_div, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
664show_fan_offset(1);
665show_fan_offset(2);
666show_fan_offset(3);
667
668#define show_pwm_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200669static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
670 show_pwm_enable, set_pwm_enable, offset - 1); \
671static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
672 show_pwm, set_pwm, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
674show_pwm_offset(1);
675show_pwm_offset(2);
676show_pwm_offset(3);
677
Jean Delvare17d648b2006-08-28 14:23:46 +0200678/* A different set of callbacks for 16-bit fans */
679static ssize_t show_fan16(struct device *dev, struct device_attribute *attr,
680 char *buf)
681{
682 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
683 int nr = sensor_attr->index;
684 struct it87_data *data = it87_update_device(dev);
685 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan[nr]));
686}
687
688static ssize_t show_fan16_min(struct device *dev, struct device_attribute *attr,
689 char *buf)
690{
691 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
692 int nr = sensor_attr->index;
693 struct it87_data *data = it87_update_device(dev);
694 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan_min[nr]));
695}
696
697static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
698 const char *buf, size_t count)
699{
700 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
701 int nr = sensor_attr->index;
702 struct i2c_client *client = to_i2c_client(dev);
703 struct it87_data *data = i2c_get_clientdata(client);
704 int val = simple_strtol(buf, NULL, 10);
705
706 mutex_lock(&data->update_lock);
707 data->fan_min[nr] = FAN16_TO_REG(val);
708 it87_write_value(client, IT87_REG_FAN_MIN(nr),
709 data->fan_min[nr] & 0xff);
710 it87_write_value(client, IT87_REG_FANX_MIN(nr),
711 data->fan_min[nr] >> 8);
712 mutex_unlock(&data->update_lock);
713 return count;
714}
715
716/* We want to use the same sysfs file names as 8-bit fans, but we need
717 different variable names, so we have to use SENSOR_ATTR instead of
718 SENSOR_DEVICE_ATTR. */
719#define show_fan16_offset(offset) \
720static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
721 = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
722 show_fan16, NULL, offset - 1); \
723static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \
724 = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
725 show_fan16_min, set_fan16_min, offset - 1)
726
727show_fan16_offset(1);
728show_fan16_offset(2);
729show_fan16_offset(3);
730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731/* Alarms */
Yani Ioannou30f74292005-05-17 06:41:35 -0400732static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733{
734 struct it87_data *data = it87_update_device(dev);
Jean Delvare68188ba2005-05-16 18:52:38 +0200735 return sprintf(buf, "%u\n", data->alarms);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736}
Jean Delvare1d66c642005-04-18 21:16:59 -0700737static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
739static ssize_t
Yani Ioannou30f74292005-05-17 06:41:35 -0400740show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741{
742 struct it87_data *data = it87_update_device(dev);
Jean Delvarea7be58a2005-12-18 16:40:14 +0100743 return sprintf(buf, "%u\n", data->vrm);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700744}
745static ssize_t
Yani Ioannou30f74292005-05-17 06:41:35 -0400746store_vrm_reg(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747{
748 struct i2c_client *client = to_i2c_client(dev);
749 struct it87_data *data = i2c_get_clientdata(client);
750 u32 val;
751
752 val = simple_strtoul(buf, NULL, 10);
753 data->vrm = val;
754
755 return count;
756}
757static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
758#define device_create_file_vrm(client) \
759device_create_file(&client->dev, &dev_attr_vrm)
760
761static ssize_t
Yani Ioannou30f74292005-05-17 06:41:35 -0400762show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763{
764 struct it87_data *data = it87_update_device(dev);
765 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
766}
767static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
768#define device_create_file_vid(client) \
769device_create_file(&client->dev, &dev_attr_cpu0_vid)
770
771/* This function is called when:
772 * it87_driver is inserted (when this module is loaded), for each
773 available adapter
774 * when a new adapter is inserted (and it87_driver is still present) */
775static int it87_attach_adapter(struct i2c_adapter *adapter)
776{
777 if (!(adapter->class & I2C_CLASS_HWMON))
778 return 0;
Jean Delvare2ed2dc32005-07-31 21:42:02 +0200779 return i2c_probe(adapter, &addr_data, it87_detect);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780}
781
Jean Delvare2d8672c2005-07-19 23:56:35 +0200782static int it87_isa_attach_adapter(struct i2c_adapter *adapter)
783{
784 return it87_detect(adapter, isa_address, -1);
785}
786
787/* SuperIO detection - will change isa_address if a chip is found */
Jean Delvare91749992005-10-08 00:10:00 +0200788static int __init it87_find(unsigned short *address)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789{
790 int err = -ENODEV;
791
792 superio_enter();
793 chip_type = superio_inw(DEVID);
794 if (chip_type != IT8712F_DEVID
Jean Delvare17d648b2006-08-28 14:23:46 +0200795 && chip_type != IT8716F_DEVID
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 && chip_type != IT8705F_DEVID)
797 goto exit;
798
799 superio_select();
800 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
801 pr_info("it87: Device not activated, skipping\n");
802 goto exit;
803 }
804
805 *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
806 if (*address == 0) {
807 pr_info("it87: Base address not set, skipping\n");
808 goto exit;
809 }
810
811 err = 0;
812 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n",
813 chip_type, *address, superio_inb(DEVREV) & 0x0f);
814
815exit:
816 superio_exit();
817 return err;
818}
819
Jean Delvare2ed2dc32005-07-31 21:42:02 +0200820/* This function is called by i2c_probe */
Ben Dooksc49efce2005-10-26 21:07:25 +0200821static int it87_detect(struct i2c_adapter *adapter, int address, int kind)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822{
823 int i;
824 struct i2c_client *new_client;
825 struct it87_data *data;
826 int err = 0;
827 const char *name = "";
828 int is_isa = i2c_is_isa_adapter(adapter);
829 int enable_pwm_interface;
830
831 if (!is_isa &&
832 !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
833 goto ERROR0;
834
835 /* Reserve the ISA region */
836 if (is_isa)
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100837 if (!request_region(address, IT87_EXTENT,
838 it87_isa_driver.driver.name))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 goto ERROR0;
840
Jean Delvare91749992005-10-08 00:10:00 +0200841 /* For now, we presume we have a valid client. We create the
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 client structure, even though we cannot fill it completely yet.
843 But it allows us to access it87_{read,write}_value. */
844
Deepak Saxenaba9c2e82005-10-17 23:08:32 +0200845 if (!(data = kzalloc(sizeof(struct it87_data), GFP_KERNEL))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846 err = -ENOMEM;
847 goto ERROR1;
848 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
850 new_client = &data->client;
851 if (is_isa)
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100852 mutex_init(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 i2c_set_clientdata(new_client, data);
854 new_client->addr = address;
855 new_client->adapter = adapter;
Jean Delvarefde09502005-07-19 23:51:07 +0200856 new_client->driver = is_isa ? &it87_isa_driver : &it87_driver;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 new_client->flags = 0;
858
859 /* Now, we do the remaining detection. */
860
861 if (kind < 0) {
862 if ((it87_read_value(new_client, IT87_REG_CONFIG) & 0x80)
863 || (!is_isa
864 && it87_read_value(new_client, IT87_REG_I2C_ADDR) != address)) {
865 err = -ENODEV;
866 goto ERROR2;
867 }
868 }
869
870 /* Determine the chip type. */
871 if (kind <= 0) {
872 i = it87_read_value(new_client, IT87_REG_CHIPID);
873 if (i == 0x90) {
874 kind = it87;
Jean Delvare17d648b2006-08-28 14:23:46 +0200875 if (is_isa) {
876 switch (chip_type) {
877 case IT8712F_DEVID:
878 kind = it8712;
879 break;
880 case IT8716F_DEVID:
881 kind = it8716;
882 break;
883 }
884 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 }
886 else {
887 if (kind == 0)
888 dev_info(&adapter->dev,
889 "Ignoring 'force' parameter for unknown chip at "
890 "adapter %d, address 0x%02x\n",
891 i2c_adapter_id(adapter), address);
892 err = -ENODEV;
893 goto ERROR2;
894 }
895 }
896
897 if (kind == it87) {
898 name = "it87";
899 } else if (kind == it8712) {
900 name = "it8712";
Jean Delvare17d648b2006-08-28 14:23:46 +0200901 } else if (kind == it8716) {
902 name = "it8716";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 }
904
905 /* Fill in the remaining client fields and put it into the global list */
906 strlcpy(new_client->name, name, I2C_NAME_SIZE);
907 data->type = kind;
908 data->valid = 0;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100909 mutex_init(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
911 /* Tell the I2C layer a new client has arrived */
912 if ((err = i2c_attach_client(new_client)))
913 goto ERROR2;
914
Jean Delvarec5e3fbf2006-01-18 22:39:48 +0100915 if (!is_isa)
916 dev_info(&new_client->dev, "The I2C interface to IT87xxF "
917 "hardware monitoring chips is deprecated. Please "
918 "report if you still rely on it.\n");
919
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 /* Check PWM configuration */
921 enable_pwm_interface = it87_check_pwm(new_client);
922
923 /* Initialize the IT87 chip */
924 it87_init_client(new_client, data);
925
926 /* Register sysfs hooks */
Mark M. Hoffman943b0832005-07-15 21:39:18 -0400927 data->class_dev = hwmon_device_register(&new_client->dev);
928 if (IS_ERR(data->class_dev)) {
929 err = PTR_ERR(data->class_dev);
930 goto ERROR3;
931 }
932
Jean Delvare20ad93d2005-06-05 11:53:25 +0200933 device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr);
934 device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr);
935 device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr);
936 device_create_file(&new_client->dev, &sensor_dev_attr_in3_input.dev_attr);
937 device_create_file(&new_client->dev, &sensor_dev_attr_in4_input.dev_attr);
938 device_create_file(&new_client->dev, &sensor_dev_attr_in5_input.dev_attr);
939 device_create_file(&new_client->dev, &sensor_dev_attr_in6_input.dev_attr);
940 device_create_file(&new_client->dev, &sensor_dev_attr_in7_input.dev_attr);
941 device_create_file(&new_client->dev, &sensor_dev_attr_in8_input.dev_attr);
942 device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr);
943 device_create_file(&new_client->dev, &sensor_dev_attr_in1_min.dev_attr);
944 device_create_file(&new_client->dev, &sensor_dev_attr_in2_min.dev_attr);
945 device_create_file(&new_client->dev, &sensor_dev_attr_in3_min.dev_attr);
946 device_create_file(&new_client->dev, &sensor_dev_attr_in4_min.dev_attr);
947 device_create_file(&new_client->dev, &sensor_dev_attr_in5_min.dev_attr);
948 device_create_file(&new_client->dev, &sensor_dev_attr_in6_min.dev_attr);
949 device_create_file(&new_client->dev, &sensor_dev_attr_in7_min.dev_attr);
950 device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr);
951 device_create_file(&new_client->dev, &sensor_dev_attr_in1_max.dev_attr);
952 device_create_file(&new_client->dev, &sensor_dev_attr_in2_max.dev_attr);
953 device_create_file(&new_client->dev, &sensor_dev_attr_in3_max.dev_attr);
954 device_create_file(&new_client->dev, &sensor_dev_attr_in4_max.dev_attr);
955 device_create_file(&new_client->dev, &sensor_dev_attr_in5_max.dev_attr);
956 device_create_file(&new_client->dev, &sensor_dev_attr_in6_max.dev_attr);
957 device_create_file(&new_client->dev, &sensor_dev_attr_in7_max.dev_attr);
958 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_input.dev_attr);
959 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_input.dev_attr);
960 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_input.dev_attr);
961 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_max.dev_attr);
962 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_max.dev_attr);
963 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_max.dev_attr);
964 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_min.dev_attr);
965 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_min.dev_attr);
966 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_min.dev_attr);
967 device_create_file(&new_client->dev, &sensor_dev_attr_temp1_type.dev_attr);
968 device_create_file(&new_client->dev, &sensor_dev_attr_temp2_type.dev_attr);
969 device_create_file(&new_client->dev, &sensor_dev_attr_temp3_type.dev_attr);
Jean Delvare17d648b2006-08-28 14:23:46 +0200970
Jean Delvare9060f8b2006-08-28 14:24:17 +0200971 /* Do not create fan files for disabled fans */
Jean Delvare17d648b2006-08-28 14:23:46 +0200972 if (data->type == it8716) { /* 16-bit tachometers */
Jean Delvare9060f8b2006-08-28 14:24:17 +0200973 if (data->has_fan & (1 << 0)) {
974 device_create_file(&new_client->dev,
975 &sensor_dev_attr_fan1_input16.dev_attr);
976 device_create_file(&new_client->dev,
977 &sensor_dev_attr_fan1_min16.dev_attr);
978 }
979 if (data->has_fan & (1 << 1)) {
980 device_create_file(&new_client->dev,
981 &sensor_dev_attr_fan2_input16.dev_attr);
982 device_create_file(&new_client->dev,
983 &sensor_dev_attr_fan2_min16.dev_attr);
984 }
985 if (data->has_fan & (1 << 2)) {
986 device_create_file(&new_client->dev,
987 &sensor_dev_attr_fan3_input16.dev_attr);
988 device_create_file(&new_client->dev,
989 &sensor_dev_attr_fan3_min16.dev_attr);
990 }
Jean Delvare17d648b2006-08-28 14:23:46 +0200991 } else {
Jean Delvare9060f8b2006-08-28 14:24:17 +0200992 if (data->has_fan & (1 << 0)) {
993 device_create_file(&new_client->dev,
994 &sensor_dev_attr_fan1_input.dev_attr);
995 device_create_file(&new_client->dev,
996 &sensor_dev_attr_fan1_min.dev_attr);
997 device_create_file(&new_client->dev,
998 &sensor_dev_attr_fan1_div.dev_attr);
999 }
1000 if (data->has_fan & (1 << 1)) {
1001 device_create_file(&new_client->dev,
1002 &sensor_dev_attr_fan2_input.dev_attr);
1003 device_create_file(&new_client->dev,
1004 &sensor_dev_attr_fan2_min.dev_attr);
1005 device_create_file(&new_client->dev,
1006 &sensor_dev_attr_fan2_div.dev_attr);
1007 }
1008 if (data->has_fan & (1 << 2)) {
1009 device_create_file(&new_client->dev,
1010 &sensor_dev_attr_fan3_input.dev_attr);
1011 device_create_file(&new_client->dev,
1012 &sensor_dev_attr_fan3_min.dev_attr);
1013 device_create_file(&new_client->dev,
1014 &sensor_dev_attr_fan3_div.dev_attr);
1015 }
Jean Delvare17d648b2006-08-28 14:23:46 +02001016 }
1017
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 device_create_file(&new_client->dev, &dev_attr_alarms);
1019 if (enable_pwm_interface) {
Jean Delvare20ad93d2005-06-05 11:53:25 +02001020 device_create_file(&new_client->dev, &sensor_dev_attr_pwm1_enable.dev_attr);
1021 device_create_file(&new_client->dev, &sensor_dev_attr_pwm2_enable.dev_attr);
1022 device_create_file(&new_client->dev, &sensor_dev_attr_pwm3_enable.dev_attr);
1023 device_create_file(&new_client->dev, &sensor_dev_attr_pwm1.dev_attr);
1024 device_create_file(&new_client->dev, &sensor_dev_attr_pwm2.dev_attr);
1025 device_create_file(&new_client->dev, &sensor_dev_attr_pwm3.dev_attr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026 }
1027
Jean Delvare17d648b2006-08-28 14:23:46 +02001028 if (data->type == it8712 || data->type == it8716) {
Jean Delvare303760b2005-07-31 21:52:01 +02001029 data->vrm = vid_which_vrm();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 device_create_file_vrm(new_client);
1031 device_create_file_vid(new_client);
1032 }
1033
1034 return 0;
1035
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001036ERROR3:
1037 i2c_detach_client(new_client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038ERROR2:
1039 kfree(data);
1040ERROR1:
1041 if (is_isa)
1042 release_region(address, IT87_EXTENT);
1043ERROR0:
1044 return err;
1045}
1046
1047static int it87_detach_client(struct i2c_client *client)
1048{
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001049 struct it87_data *data = i2c_get_clientdata(client);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 int err;
1051
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001052 hwmon_device_unregister(data->class_dev);
1053
Jean Delvare7bef5592005-07-27 22:14:49 +02001054 if ((err = i2c_detach_client(client)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056
1057 if(i2c_is_isa_client(client))
1058 release_region(client->addr, IT87_EXTENT);
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001059 kfree(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
1061 return 0;
1062}
1063
Steven Cole44bbe872005-05-03 18:21:25 -06001064/* The SMBus locks itself, but ISA access must be locked explicitly!
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065 We don't want to lock the whole ISA bus, so we lock each client
1066 separately.
1067 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1068 would slow down the IT87 access and should not be necessary. */
1069static int it87_read_value(struct i2c_client *client, u8 reg)
1070{
1071 struct it87_data *data = i2c_get_clientdata(client);
1072
1073 int res;
1074 if (i2c_is_isa_client(client)) {
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001075 mutex_lock(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET);
1077 res = inb_p(client->addr + IT87_DATA_REG_OFFSET);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001078 mutex_unlock(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 return res;
1080 } else
1081 return i2c_smbus_read_byte_data(client, reg);
1082}
1083
Steven Cole44bbe872005-05-03 18:21:25 -06001084/* The SMBus locks itself, but ISA access muse be locked explicitly!
Linus Torvalds1da177e2005-04-16 15:20:36 -07001085 We don't want to lock the whole ISA bus, so we lock each client
1086 separately.
1087 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1088 would slow down the IT87 access and should not be necessary. */
1089static int it87_write_value(struct i2c_client *client, u8 reg, u8 value)
1090{
1091 struct it87_data *data = i2c_get_clientdata(client);
1092
1093 if (i2c_is_isa_client(client)) {
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001094 mutex_lock(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET);
1096 outb_p(value, client->addr + IT87_DATA_REG_OFFSET);
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001097 mutex_unlock(&data->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 return 0;
1099 } else
1100 return i2c_smbus_write_byte_data(client, reg, value);
1101}
1102
1103/* Return 1 if and only if the PWM interface is safe to use */
1104static int it87_check_pwm(struct i2c_client *client)
1105{
1106 /* Some BIOSes fail to correctly configure the IT87 fans. All fans off
1107 * and polarity set to active low is sign that this is the case so we
1108 * disable pwm control to protect the user. */
1109 int tmp = it87_read_value(client, IT87_REG_FAN_CTL);
1110 if ((tmp & 0x87) == 0) {
1111 if (fix_pwm_polarity) {
1112 /* The user asks us to attempt a chip reconfiguration.
1113 * This means switching to active high polarity and
1114 * inverting all fan speed values. */
1115 int i;
1116 u8 pwm[3];
1117
1118 for (i = 0; i < 3; i++)
1119 pwm[i] = it87_read_value(client,
1120 IT87_REG_PWM(i));
1121
1122 /* If any fan is in automatic pwm mode, the polarity
1123 * might be correct, as suspicious as it seems, so we
1124 * better don't change anything (but still disable the
1125 * PWM interface). */
1126 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
1127 dev_info(&client->dev, "Reconfiguring PWM to "
1128 "active high polarity\n");
1129 it87_write_value(client, IT87_REG_FAN_CTL,
1130 tmp | 0x87);
1131 for (i = 0; i < 3; i++)
1132 it87_write_value(client,
1133 IT87_REG_PWM(i),
1134 0x7f & ~pwm[i]);
1135 return 1;
1136 }
1137
1138 dev_info(&client->dev, "PWM configuration is "
1139 "too broken to be fixed\n");
1140 }
1141
1142 dev_info(&client->dev, "Detected broken BIOS "
1143 "defaults, disabling PWM interface\n");
1144 return 0;
1145 } else if (fix_pwm_polarity) {
1146 dev_info(&client->dev, "PWM configuration looks "
1147 "sane, won't touch\n");
1148 }
1149
1150 return 1;
1151}
1152
1153/* Called when we have found a new IT87. */
1154static void it87_init_client(struct i2c_client *client, struct it87_data *data)
1155{
1156 int tmp, i;
1157
1158 /* initialize to sane defaults:
1159 * - if the chip is in manual pwm mode, this will be overwritten with
1160 * the actual settings on the chip (so in this case, initialization
1161 * is not needed)
1162 * - if in automatic or on/off mode, we could switch to manual mode,
1163 * read the registers and set manual_pwm_ctl accordingly, but currently
1164 * this is not implemented, so we initialize to something sane */
1165 for (i = 0; i < 3; i++) {
1166 data->manual_pwm_ctl[i] = 0xff;
1167 }
1168
1169 /* Check if temperature channnels are reset manually or by some reason */
1170 tmp = it87_read_value(client, IT87_REG_TEMP_ENABLE);
1171 if ((tmp & 0x3f) == 0) {
1172 /* Temp1,Temp3=thermistor; Temp2=thermal diode */
1173 tmp = (tmp & 0xc0) | 0x2a;
1174 it87_write_value(client, IT87_REG_TEMP_ENABLE, tmp);
1175 }
1176 data->sensor = tmp;
1177
1178 /* Check if voltage monitors are reset manually or by some reason */
1179 tmp = it87_read_value(client, IT87_REG_VIN_ENABLE);
1180 if ((tmp & 0xff) == 0) {
1181 /* Enable all voltage monitors */
1182 it87_write_value(client, IT87_REG_VIN_ENABLE, 0xff);
1183 }
1184
1185 /* Check if tachometers are reset manually or by some reason */
1186 data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL);
1187 if ((data->fan_main_ctrl & 0x70) == 0) {
1188 /* Enable all fan tachometers */
1189 data->fan_main_ctrl |= 0x70;
1190 it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl);
1191 }
Jean Delvare9060f8b2006-08-28 14:24:17 +02001192 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
Jean Delvare17d648b2006-08-28 14:23:46 +02001194 /* Set tachometers to 16-bit mode if needed */
1195 if (data->type == it8716) {
1196 tmp = it87_read_value(client, IT87_REG_FAN_16BIT);
Jean Delvare9060f8b2006-08-28 14:24:17 +02001197 if (~tmp & 0x07 & data->has_fan) {
Jean Delvare17d648b2006-08-28 14:23:46 +02001198 dev_dbg(&client->dev,
1199 "Setting fan1-3 to 16-bit mode\n");
1200 it87_write_value(client, IT87_REG_FAN_16BIT,
1201 tmp | 0x07);
1202 }
1203 }
1204
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 /* Set current fan mode registers and the default settings for the
1206 * other mode registers */
1207 for (i = 0; i < 3; i++) {
1208 if (data->fan_main_ctrl & (1 << i)) {
1209 /* pwm mode */
1210 tmp = it87_read_value(client, IT87_REG_PWM(i));
1211 if (tmp & 0x80) {
1212 /* automatic pwm - not yet implemented, but
1213 * leave the settings made by the BIOS alone
1214 * until a change is requested via the sysfs
1215 * interface */
1216 } else {
1217 /* manual pwm */
1218 data->manual_pwm_ctl[i] = PWM_FROM_REG(tmp);
1219 }
1220 }
1221 }
1222
1223 /* Start monitoring */
1224 it87_write_value(client, IT87_REG_CONFIG,
1225 (it87_read_value(client, IT87_REG_CONFIG) & 0x36)
1226 | (update_vbat ? 0x41 : 0x01));
1227}
1228
1229static struct it87_data *it87_update_device(struct device *dev)
1230{
1231 struct i2c_client *client = to_i2c_client(dev);
1232 struct it87_data *data = i2c_get_clientdata(client);
1233 int i;
1234
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001235 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236
1237 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
1238 || !data->valid) {
1239
1240 if (update_vbat) {
1241 /* Cleared after each update, so reenable. Value
1242 returned by this read will be previous value */
1243 it87_write_value(client, IT87_REG_CONFIG,
1244 it87_read_value(client, IT87_REG_CONFIG) | 0x40);
1245 }
1246 for (i = 0; i <= 7; i++) {
1247 data->in[i] =
1248 it87_read_value(client, IT87_REG_VIN(i));
1249 data->in_min[i] =
1250 it87_read_value(client, IT87_REG_VIN_MIN(i));
1251 data->in_max[i] =
1252 it87_read_value(client, IT87_REG_VIN_MAX(i));
1253 }
1254 data->in[8] =
1255 it87_read_value(client, IT87_REG_VIN(8));
1256 /* Temperature sensor doesn't have limit registers, set
1257 to min and max value */
1258 data->in_min[8] = 0;
1259 data->in_max[8] = 255;
1260
1261 for (i = 0; i < 3; i++) {
Jean Delvare9060f8b2006-08-28 14:24:17 +02001262 /* Skip disabled fans */
1263 if (!(data->has_fan & (1 << i)))
1264 continue;
1265
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266 data->fan_min[i] =
1267 it87_read_value(client, IT87_REG_FAN_MIN(i));
Jean Delvare17d648b2006-08-28 14:23:46 +02001268 data->fan[i] = it87_read_value(client,
1269 IT87_REG_FAN(i));
1270 /* Add high byte if in 16-bit mode */
1271 if (data->type == it8716) {
1272 data->fan[i] |= it87_read_value(client,
1273 IT87_REG_FANX(i)) << 8;
1274 data->fan_min[i] |= it87_read_value(client,
1275 IT87_REG_FANX_MIN(i)) << 8;
1276 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 }
1278 for (i = 0; i < 3; i++) {
1279 data->temp[i] =
1280 it87_read_value(client, IT87_REG_TEMP(i));
1281 data->temp_high[i] =
1282 it87_read_value(client, IT87_REG_TEMP_HIGH(i));
1283 data->temp_low[i] =
1284 it87_read_value(client, IT87_REG_TEMP_LOW(i));
1285 }
1286
Jean Delvare17d648b2006-08-28 14:23:46 +02001287 /* Newer chips don't have clock dividers */
Jean Delvare9060f8b2006-08-28 14:24:17 +02001288 if ((data->has_fan & 0x07) && data->type != it8716) {
Jean Delvare17d648b2006-08-28 14:23:46 +02001289 i = it87_read_value(client, IT87_REG_FAN_DIV);
1290 data->fan_div[0] = i & 0x07;
1291 data->fan_div[1] = (i >> 3) & 0x07;
1292 data->fan_div[2] = (i & 0x40) ? 3 : 1;
1293 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001294
1295 data->alarms =
1296 it87_read_value(client, IT87_REG_ALARM1) |
1297 (it87_read_value(client, IT87_REG_ALARM2) << 8) |
1298 (it87_read_value(client, IT87_REG_ALARM3) << 16);
1299 data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL);
1300
1301 data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE);
1302 /* The 8705 does not have VID capability */
Jean Delvare17d648b2006-08-28 14:23:46 +02001303 if (data->type == it8712 || data->type == it8716) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 data->vid = it87_read_value(client, IT87_REG_VID);
Jean Delvare17d648b2006-08-28 14:23:46 +02001305 /* The older IT8712F revisions had only 5 VID pins,
1306 but we assume it is always safe to read 6 bits. */
1307 data->vid &= 0x3f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 }
1309 data->last_updated = jiffies;
1310 data->valid = 1;
1311 }
1312
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001313 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
1315 return data;
1316}
1317
1318static int __init sm_it87_init(void)
1319{
Jean Delvare91749992005-10-08 00:10:00 +02001320 int res;
Jean Delvarefde09502005-07-19 23:51:07 +02001321
1322 res = i2c_add_driver(&it87_driver);
1323 if (res)
1324 return res;
1325
Jean Delvare91749992005-10-08 00:10:00 +02001326 if (!it87_find(&isa_address)) {
1327 res = i2c_isa_add_driver(&it87_isa_driver);
1328 if (res) {
1329 i2c_del_driver(&it87_driver);
1330 return res;
1331 }
Jean Delvarefde09502005-07-19 23:51:07 +02001332 }
1333
1334 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335}
1336
1337static void __exit sm_it87_exit(void)
1338{
Jean Delvarebe79c382006-02-07 17:53:32 +01001339 if (isa_address)
1340 i2c_isa_del_driver(&it87_isa_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 i2c_del_driver(&it87_driver);
1342}
1343
1344
1345MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>");
Jean Delvare17d648b2006-08-28 14:23:46 +02001346MODULE_DESCRIPTION("IT8705F/8712F/8716F, SiS950 driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347module_param(update_vbat, bool, 0);
1348MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
1349module_param(fix_pwm_polarity, bool, 0);
1350MODULE_PARM_DESC(fix_pwm_polarity, "Force PWM polarity to active high (DANGEROUS)");
1351MODULE_LICENSE("GPL");
1352
1353module_init(sm_it87_init);
1354module_exit(sm_it87_exit);