blob: 8282282eb4caa709484e60419b285aa0bb16f3d2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Jean Delvare5f2dc792010-03-05 22:17:18 +01002 * it87.c - Part of lm_sensors, Linux kernel modules for hardware
3 * monitoring.
4 *
5 * The IT8705F is an LPC-based Super I/O part that contains UARTs, a
6 * parallel port, an IR port, a MIDI port, a floppy controller, etc., in
7 * addition to an Environment Controller (Enhanced Hardware Monitor and
8 * Fan Controller)
9 *
10 * This driver supports only the Environment Controller in the IT8705F and
11 * similar parts. The other devices are supported by different drivers.
12 *
13 * Supports: IT8705F Super I/O chip w/LPC interface
14 * IT8712F Super I/O chip w/LPC interface
15 * IT8716F Super I/O chip w/LPC interface
16 * IT8718F Super I/O chip w/LPC interface
17 * IT8720F Super I/O chip w/LPC interface
18 * IT8726F Super I/O chip w/LPC interface
19 * Sis950 A clone of the IT8705F
20 *
21 * Copyright (C) 2001 Chris Gauthron
22 * Copyright (C) 2005-2010 Jean Delvare <khali@linux-fr.org>
23 *
24 * This program is free software; you can redistribute it and/or modify
25 * it under the terms of the GNU General Public License as published by
26 * the Free Software Foundation; either version 2 of the License, or
27 * (at your option) any later version.
28 *
29 * This program is distributed in the hope that it will be useful,
30 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
32 * GNU General Public License for more details.
33 *
34 * You should have received a copy of the GNU General Public License
35 * along with this program; if not, write to the Free Software
36 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
37 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Linus Torvalds1da177e2005-04-16 15:20:36 -070039#include <linux/module.h>
40#include <linux/init.h>
41#include <linux/slab.h>
42#include <linux/jiffies.h>
corentin.labbeb74f3fd2007-06-13 20:27:36 +020043#include <linux/platform_device.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040044#include <linux/hwmon.h>
Jean Delvare303760b2005-07-31 21:52:01 +020045#include <linux/hwmon-sysfs.h>
46#include <linux/hwmon-vid.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040047#include <linux/err.h>
Ingo Molnar9a61bf62006-01-18 23:19:26 +010048#include <linux/mutex.h>
Jean Delvare87808be2006-09-24 21:17:13 +020049#include <linux/sysfs.h>
Jean Delvare98dd22c2008-10-09 15:33:58 +020050#include <linux/string.h>
51#include <linux/dmi.h>
Jean Delvareb9acb642009-01-07 16:37:35 +010052#include <linux/acpi.h>
H Hartley Sweeten6055fae2009-09-15 17:18:13 +020053#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
corentin.labbeb74f3fd2007-06-13 20:27:36 +020055#define DRVNAME "it87"
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +010057enum chips { it87, it8712, it8716, it8718, it8720 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Jean Delvare67b671b2007-12-06 23:13:42 +010059static unsigned short force_id;
60module_param(force_id, ushort, 0);
61MODULE_PARM_DESC(force_id, "Override the detected device ID");
62
corentin.labbeb74f3fd2007-06-13 20:27:36 +020063static struct platform_device *pdev;
64
Linus Torvalds1da177e2005-04-16 15:20:36 -070065#define REG 0x2e /* The register to read/write */
66#define DEV 0x07 /* Register: Logical device select */
67#define VAL 0x2f /* The value to read/write */
68#define PME 0x04 /* The device with the fan registers in it */
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +010069
70/* The device with the IT8718F/IT8720F VID value in it */
71#define GPIO 0x07
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#define DEVID 0x20 /* Register: Device ID */
74#define DEVREV 0x22 /* Register: Device Revision */
75
76static inline int
77superio_inb(int reg)
78{
79 outb(reg, REG);
80 return inb(VAL);
81}
82
83static int superio_inw(int reg)
84{
85 int val;
86 outb(reg++, REG);
87 val = inb(VAL) << 8;
88 outb(reg, REG);
89 val |= inb(VAL);
90 return val;
91}
92
93static inline void
Jean Delvare87673dd2006-08-28 14:37:19 +020094superio_select(int ldn)
Linus Torvalds1da177e2005-04-16 15:20:36 -070095{
96 outb(DEV, REG);
Jean Delvare87673dd2006-08-28 14:37:19 +020097 outb(ldn, VAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
99
100static inline void
101superio_enter(void)
102{
103 outb(0x87, REG);
104 outb(0x01, REG);
105 outb(0x55, REG);
106 outb(0x55, REG);
107}
108
109static inline void
110superio_exit(void)
111{
112 outb(0x02, REG);
113 outb(0x02, VAL);
114}
115
Jean Delvare87673dd2006-08-28 14:37:19 +0200116/* Logical device 4 registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117#define IT8712F_DEVID 0x8712
118#define IT8705F_DEVID 0x8705
Jean Delvare17d648b2006-08-28 14:23:46 +0200119#define IT8716F_DEVID 0x8716
Jean Delvare87673dd2006-08-28 14:37:19 +0200120#define IT8718F_DEVID 0x8718
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +0100121#define IT8720F_DEVID 0x8720
Rudolf Marek08a8f6e2007-06-09 10:11:16 -0400122#define IT8726F_DEVID 0x8726
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123#define IT87_ACT_REG 0x30
124#define IT87_BASE_REG 0x60
125
Jean Delvare87673dd2006-08-28 14:37:19 +0200126/* Logical device 7 registers (IT8712F and later) */
Jean Delvare895ff262009-12-09 20:35:47 +0100127#define IT87_SIO_GPIO3_REG 0x27
Jean Delvare591ec652009-12-09 20:35:48 +0100128#define IT87_SIO_GPIO5_REG 0x29
Jean Delvare87673dd2006-08-28 14:37:19 +0200129#define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
130#define IT87_SIO_VID_REG 0xfc /* VID value */
Jean Delvared9b327c2010-03-05 22:17:17 +0100131#define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */
Jean Delvare87673dd2006-08-28 14:37:19 +0200132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133/* Update battery voltage after every reading if true */
134static int update_vbat;
135
136/* Not all BIOSes properly configure the PWM registers */
137static int fix_pwm_polarity;
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139/* Many IT87 constants specified below */
140
141/* Length of ISA address segment */
142#define IT87_EXTENT 8
143
Bjorn Helgaas87b4b662008-01-22 07:21:03 -0500144/* Length of ISA address segment for Environmental Controller */
145#define IT87_EC_EXTENT 2
146
147/* Offset of EC registers from ISA base address */
148#define IT87_EC_OFFSET 5
149
150/* Where are the ISA address/data registers relative to the EC base address */
151#define IT87_ADDR_REG_OFFSET 0
152#define IT87_DATA_REG_OFFSET 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154/*----- The IT87 registers -----*/
155
156#define IT87_REG_CONFIG 0x00
157
158#define IT87_REG_ALARM1 0x01
159#define IT87_REG_ALARM2 0x02
160#define IT87_REG_ALARM3 0x03
161
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +0100162/* The IT8718F and IT8720F have the VID value in a different register, in
163 Super-I/O configuration space. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164#define IT87_REG_VID 0x0a
Andrew Paprocki04751692008-08-06 22:41:06 +0200165/* The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
166 for fan divisors. Later IT8712F revisions must use 16-bit tachometer
167 mode. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168#define IT87_REG_FAN_DIV 0x0b
Jean Delvare17d648b2006-08-28 14:23:46 +0200169#define IT87_REG_FAN_16BIT 0x0c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170
171/* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
172
Jean Delvarec7f1f712007-09-03 17:11:46 +0200173static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
174static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 };
175static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 };
176static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177#define IT87_REG_FAN_MAIN_CTRL 0x13
178#define IT87_REG_FAN_CTL 0x14
179#define IT87_REG_PWM(nr) (0x15 + (nr))
180
181#define IT87_REG_VIN(nr) (0x20 + (nr))
182#define IT87_REG_TEMP(nr) (0x29 + (nr))
183
184#define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
185#define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
186#define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
187#define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
188
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189#define IT87_REG_VIN_ENABLE 0x50
190#define IT87_REG_TEMP_ENABLE 0x51
Jean Delvared9b327c2010-03-05 22:17:17 +0100191#define IT87_REG_BEEP_ENABLE 0x5c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193#define IT87_REG_CHIPID 0x58
194
195#define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255))
196#define IN_FROM_REG(val) ((val) * 16)
197
198static inline u8 FAN_TO_REG(long rpm, int div)
199{
200 if (rpm == 0)
201 return 255;
202 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
203 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1,
204 254);
205}
206
Jean Delvare17d648b2006-08-28 14:23:46 +0200207static inline u16 FAN16_TO_REG(long rpm)
208{
209 if (rpm == 0)
210 return 0xffff;
211 return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
212}
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214#define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div)))
Jean Delvare17d648b2006-08-28 14:23:46 +0200215/* The divider is fixed to 2 in 16-bit mode */
216#define FAN16_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:1350000/((val)*2))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217
218#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\
219 ((val)+500)/1000),-128,127))
Jean Delvaree267d252009-03-12 13:36:39 +0100220#define TEMP_FROM_REG(val) ((val) * 1000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222#define PWM_TO_REG(val) ((val) >> 1)
223#define PWM_FROM_REG(val) (((val)&0x7f) << 1)
224
225static int DIV_TO_REG(int val)
226{
227 int answer = 0;
Jean Delvareb9e349f2006-08-28 14:26:22 +0200228 while (answer < 7 && (val >>= 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 answer++;
230 return answer;
231}
232#define DIV_FROM_REG(val) (1 << (val))
233
Jean Delvaref8d0c192007-02-14 21:15:02 +0100234static const unsigned int pwm_freq[8] = {
235 48000000 / 128,
236 24000000 / 128,
237 12000000 / 128,
238 8000000 / 128,
239 6000000 / 128,
240 3000000 / 128,
241 1500000 / 128,
242 750000 / 128,
243};
244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200246struct it87_sio_data {
247 enum chips type;
248 /* Values read from Super-I/O config space */
Andrew Paprocki04751692008-08-06 22:41:06 +0200249 u8 revision;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200250 u8 vid_value;
Jean Delvared9b327c2010-03-05 22:17:17 +0100251 u8 beep_pin;
Jean Delvare591ec652009-12-09 20:35:48 +0100252 /* Features skipped based on config or DMI */
Jean Delvare895ff262009-12-09 20:35:47 +0100253 u8 skip_vid;
Jean Delvare591ec652009-12-09 20:35:48 +0100254 u8 skip_fan;
Jean Delvare98dd22c2008-10-09 15:33:58 +0200255 u8 skip_pwm;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200256};
257
Jean Delvareed6bafb2007-02-14 21:15:03 +0100258/* For each registered chip, we need to keep some data in memory.
259 The structure is dynamically allocated. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260struct it87_data {
Tony Jones1beeffe2007-08-20 13:46:20 -0700261 struct device *hwmon_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 enum chips type;
Andrew Paprocki04751692008-08-06 22:41:06 +0200263 u8 revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200265 unsigned short addr;
266 const char *name;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100267 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 char valid; /* !=0 if following fields are valid */
269 unsigned long last_updated; /* In jiffies */
270
271 u8 in[9]; /* Register value */
Jean Delvare3543a532006-08-28 14:27:25 +0200272 u8 in_max[8]; /* Register value */
273 u8 in_min[8]; /* Register value */
Jean Delvare9060f8b2006-08-28 14:24:17 +0200274 u8 has_fan; /* Bitfield, fans enabled */
Jean Delvarec7f1f712007-09-03 17:11:46 +0200275 u16 fan[5]; /* Register values, possibly combined */
276 u16 fan_min[5]; /* Register values, possibly combined */
Jean Delvaree267d252009-03-12 13:36:39 +0100277 s8 temp[3]; /* Register value */
278 s8 temp_high[3]; /* Register value */
279 s8 temp_low[3]; /* Register value */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 u8 sensor; /* Register value */
281 u8 fan_div[3]; /* Register encoding, shifted right */
282 u8 vid; /* Register encoding, combined */
Jean Delvarea7be58a2005-12-18 16:40:14 +0100283 u8 vrm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 u32 alarms; /* Register encoding, combined */
Jean Delvared9b327c2010-03-05 22:17:17 +0100285 u8 beeps; /* Register encoding */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 u8 fan_main_ctrl; /* Register value */
Jean Delvaref8d0c192007-02-14 21:15:02 +0100287 u8 fan_ctl; /* Register value */
Jean Delvareb99883d2010-03-05 22:17:15 +0100288
289 /* The following 3 arrays correspond to the same registers. The
290 * meaning of bits 6-0 depends on the value of bit 7, and we want
291 * to preserve settings on mode changes, so we have to track all
292 * values separately. */
293 u8 pwm_ctrl[3]; /* Register value */
294 u8 pwm_duty[3]; /* Manual PWM value set by user (bit 6-0) */
295 u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296};
297
Andrew Paprocki04751692008-08-06 22:41:06 +0200298static inline int has_16bit_fans(const struct it87_data *data)
299{
Andrew Paprocki816d8c62008-08-06 22:41:06 +0200300 /* IT8705F Datasheet 0.4.1, 3h == Version G.
Andrew Paprocki859b9ef2008-09-20 10:25:19 +0200301 IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
Andrew Paprocki816d8c62008-08-06 22:41:06 +0200302 These are the first revisions with 16bit tachometer support. */
303 return (data->type == it87 && data->revision >= 0x03)
Andrew Paprocki859b9ef2008-09-20 10:25:19 +0200304 || (data->type == it8712 && data->revision >= 0x08)
Andrew Paprocki04751692008-08-06 22:41:06 +0200305 || data->type == it8716
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +0100306 || data->type == it8718
307 || data->type == it8720;
Andrew Paprocki04751692008-08-06 22:41:06 +0200308}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200310static int it87_probe(struct platform_device *pdev);
Jean Delvared0546122007-07-22 12:09:48 +0200311static int __devexit it87_remove(struct platform_device *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200313static int it87_read_value(struct it87_data *data, u8 reg);
314static void it87_write_value(struct it87_data *data, u8 reg, u8 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315static struct it87_data *it87_update_device(struct device *dev);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200316static int it87_check_pwm(struct device *dev);
317static void it87_init_device(struct platform_device *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
319
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200320static struct platform_driver it87_driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100321 .driver = {
Jean Delvare87218842006-09-03 22:36:14 +0200322 .owner = THIS_MODULE,
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200323 .name = DRVNAME,
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100324 },
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200325 .probe = it87_probe,
326 .remove = __devexit_p(it87_remove),
Jean Delvarefde09502005-07-19 23:51:07 +0200327};
328
Jean Delvare20ad93d2005-06-05 11:53:25 +0200329static ssize_t show_in(struct device *dev, struct device_attribute *attr,
330 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200332 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
333 int nr = sensor_attr->index;
334
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 struct it87_data *data = it87_update_device(dev);
336 return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr]));
337}
338
Jean Delvare20ad93d2005-06-05 11:53:25 +0200339static ssize_t show_in_min(struct device *dev, struct device_attribute *attr,
340 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200342 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
343 int nr = sensor_attr->index;
344
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 struct it87_data *data = it87_update_device(dev);
346 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr]));
347}
348
Jean Delvare20ad93d2005-06-05 11:53:25 +0200349static ssize_t show_in_max(struct device *dev, struct device_attribute *attr,
350 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200352 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
353 int nr = sensor_attr->index;
354
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 struct it87_data *data = it87_update_device(dev);
356 return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr]));
357}
358
Jean Delvare20ad93d2005-06-05 11:53:25 +0200359static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
360 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200362 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
363 int nr = sensor_attr->index;
364
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200365 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100366 unsigned long val;
367
368 if (strict_strtoul(buf, 10, &val) < 0)
369 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100371 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 data->in_min[nr] = IN_TO_REG(val);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200373 it87_write_value(data, IT87_REG_VIN_MIN(nr),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374 data->in_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100375 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 return count;
377}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200378static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
379 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200381 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
382 int nr = sensor_attr->index;
383
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200384 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100385 unsigned long val;
386
387 if (strict_strtoul(buf, 10, &val) < 0)
388 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100390 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 data->in_max[nr] = IN_TO_REG(val);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200392 it87_write_value(data, IT87_REG_VIN_MAX(nr),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 data->in_max[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100394 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 return count;
396}
397
398#define show_in_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200399static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
400 show_in, NULL, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
402#define limit_in_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200403static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \
404 show_in_min, set_in_min, offset); \
405static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \
406 show_in_max, set_in_max, offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
408show_in_offset(0);
409limit_in_offset(0);
410show_in_offset(1);
411limit_in_offset(1);
412show_in_offset(2);
413limit_in_offset(2);
414show_in_offset(3);
415limit_in_offset(3);
416show_in_offset(4);
417limit_in_offset(4);
418show_in_offset(5);
419limit_in_offset(5);
420show_in_offset(6);
421limit_in_offset(6);
422show_in_offset(7);
423limit_in_offset(7);
424show_in_offset(8);
425
426/* 3 temperatures */
Jean Delvare20ad93d2005-06-05 11:53:25 +0200427static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
428 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200430 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
431 int nr = sensor_attr->index;
432
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 struct it87_data *data = it87_update_device(dev);
434 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr]));
435}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200436static ssize_t show_temp_max(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 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr]));
444}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200445static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr,
446 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200448 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
449 int nr = sensor_attr->index;
450
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 struct it87_data *data = it87_update_device(dev);
452 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr]));
453}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200454static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
455 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200457 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
458 int nr = sensor_attr->index;
459
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200460 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100461 long val;
462
463 if (strict_strtol(buf, 10, &val) < 0)
464 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100466 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 data->temp_high[nr] = TEMP_TO_REG(val);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200468 it87_write_value(data, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100469 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 return count;
471}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200472static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
473 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200475 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
476 int nr = sensor_attr->index;
477
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200478 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100479 long val;
480
481 if (strict_strtol(buf, 10, &val) < 0)
482 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100484 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 data->temp_low[nr] = TEMP_TO_REG(val);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200486 it87_write_value(data, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100487 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 return count;
489}
490#define show_temp_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200491static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
492 show_temp, NULL, offset - 1); \
493static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \
494 show_temp_max, set_temp_max, offset - 1); \
495static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \
496 show_temp_min, set_temp_min, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
498show_temp_offset(1);
499show_temp_offset(2);
500show_temp_offset(3);
501
Jean Delvare20ad93d2005-06-05 11:53:25 +0200502static ssize_t show_sensor(struct device *dev, struct device_attribute *attr,
503 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200505 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
506 int nr = sensor_attr->index;
507
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 struct it87_data *data = it87_update_device(dev);
Jean Delvare5f2dc792010-03-05 22:17:18 +0100509 u8 reg = data->sensor; /* In case the value is updated while
510 we use it */
511
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 if (reg & (1 << nr))
513 return sprintf(buf, "3\n"); /* thermal diode */
514 if (reg & (8 << nr))
Jean Delvare4ed10772008-10-17 17:51:16 +0200515 return sprintf(buf, "4\n"); /* thermistor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 return sprintf(buf, "0\n"); /* disabled */
517}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200518static ssize_t set_sensor(struct device *dev, struct device_attribute *attr,
519 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200521 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
522 int nr = sensor_attr->index;
523
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200524 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100525 long val;
526
527 if (strict_strtol(buf, 10, &val) < 0)
528 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100530 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
532 data->sensor &= ~(1 << nr);
533 data->sensor &= ~(8 << nr);
Jean Delvare4ed10772008-10-17 17:51:16 +0200534 if (val == 2) { /* backwards compatibility */
535 dev_warn(dev, "Sensor type 2 is deprecated, please use 4 "
536 "instead\n");
537 val = 4;
538 }
539 /* 3 = thermal diode; 4 = thermistor; 0 = disabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540 if (val == 3)
Jean Delvare5f2dc792010-03-05 22:17:18 +0100541 data->sensor |= 1 << nr;
Jean Delvare4ed10772008-10-17 17:51:16 +0200542 else if (val == 4)
Jean Delvare5f2dc792010-03-05 22:17:18 +0100543 data->sensor |= 8 << nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 else if (val != 0) {
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100545 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 return -EINVAL;
547 }
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200548 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100549 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550 return count;
551}
552#define show_sensor_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200553static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \
554 show_sensor, set_sensor, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
556show_sensor_offset(1);
557show_sensor_offset(2);
558show_sensor_offset(3);
559
560/* 3 Fans */
Jean Delvareb99883d2010-03-05 22:17:15 +0100561
562static int pwm_mode(const struct it87_data *data, int nr)
563{
564 int ctrl = data->fan_main_ctrl & (1 << nr);
565
566 if (ctrl == 0) /* Full speed */
567 return 0;
568 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
569 return 2;
570 else /* Manual mode */
571 return 1;
572}
573
Jean Delvare20ad93d2005-06-05 11:53:25 +0200574static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
575 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200577 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
578 int nr = sensor_attr->index;
579
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 struct it87_data *data = it87_update_device(dev);
Jean Delvare5f2dc792010-03-05 22:17:18 +0100581 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 DIV_FROM_REG(data->fan_div[nr])));
583}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200584static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
585 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200587 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
588 int nr = sensor_attr->index;
589
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 struct it87_data *data = it87_update_device(dev);
Jean Delvare5f2dc792010-03-05 22:17:18 +0100591 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
592 DIV_FROM_REG(data->fan_div[nr])));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200594static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
595 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200597 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
598 int nr = sensor_attr->index;
599
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 struct it87_data *data = it87_update_device(dev);
601 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
602}
Jean Delvare5f2dc792010-03-05 22:17:18 +0100603static ssize_t show_pwm_enable(struct device *dev,
604 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200606 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
607 int nr = sensor_attr->index;
608
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 struct it87_data *data = it87_update_device(dev);
Jean Delvareb99883d2010-03-05 22:17:15 +0100610 return sprintf(buf, "%d\n", pwm_mode(data, nr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200612static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
613 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200615 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
616 int nr = sensor_attr->index;
617
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 struct it87_data *data = it87_update_device(dev);
Jean Delvareb99883d2010-03-05 22:17:15 +0100619 return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm_duty[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620}
Jean Delvaref8d0c192007-02-14 21:15:02 +0100621static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
622 char *buf)
623{
624 struct it87_data *data = it87_update_device(dev);
625 int index = (data->fan_ctl >> 4) & 0x07;
626
627 return sprintf(buf, "%u\n", pwm_freq[index]);
628}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200629static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
630 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200632 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
633 int nr = sensor_attr->index;
634
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200635 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100636 long val;
Jean Delvare7f999aa2007-02-14 21:15:03 +0100637 u8 reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Jean Delvaref5f64502010-03-05 22:17:19 +0100639 if (strict_strtol(buf, 10, &val) < 0)
640 return -EINVAL;
641
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100642 mutex_lock(&data->update_lock);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200643 reg = it87_read_value(data, IT87_REG_FAN_DIV);
Jean Delvare07eab462005-11-23 15:44:31 -0800644 switch (nr) {
Jean Delvare5f2dc792010-03-05 22:17:18 +0100645 case 0:
646 data->fan_div[nr] = reg & 0x07;
647 break;
648 case 1:
649 data->fan_div[nr] = (reg >> 3) & 0x07;
650 break;
651 case 2:
652 data->fan_div[nr] = (reg & 0x40) ? 3 : 1;
653 break;
Jean Delvare07eab462005-11-23 15:44:31 -0800654 }
655
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
Jean Delvarec7f1f712007-09-03 17:11:46 +0200657 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100658 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 return count;
660}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200661static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
662 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200664 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
665 int nr = sensor_attr->index;
666
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200667 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100668 unsigned long val;
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200669 int min;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 u8 old;
671
Jean Delvaref5f64502010-03-05 22:17:19 +0100672 if (strict_strtoul(buf, 10, &val) < 0)
673 return -EINVAL;
674
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100675 mutex_lock(&data->update_lock);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200676 old = it87_read_value(data, IT87_REG_FAN_DIV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200678 /* Save fan min limit */
679 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
681 switch (nr) {
682 case 0:
683 case 1:
684 data->fan_div[nr] = DIV_TO_REG(val);
685 break;
686 case 2:
687 if (val < 8)
688 data->fan_div[nr] = 1;
689 else
690 data->fan_div[nr] = 3;
691 }
692 val = old & 0x80;
693 val |= (data->fan_div[0] & 0x07);
694 val |= (data->fan_div[1] & 0x07) << 3;
695 if (data->fan_div[2] == 3)
696 val |= 0x1 << 6;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200697 it87_write_value(data, IT87_REG_FAN_DIV, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200699 /* Restore fan min limit */
700 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
Jean Delvarec7f1f712007-09-03 17:11:46 +0200701 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]);
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200702
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100703 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 return count;
705}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200706static ssize_t set_pwm_enable(struct device *dev,
707 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200709 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
710 int nr = sensor_attr->index;
711
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200712 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100713 long val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
Jean Delvaref5f64502010-03-05 22:17:19 +0100715 if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 2)
Jean Delvareb99883d2010-03-05 22:17:15 +0100716 return -EINVAL;
717
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100718 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719
720 if (val == 0) {
721 int tmp;
722 /* make sure the fan is on when in on/off mode */
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200723 tmp = it87_read_value(data, IT87_REG_FAN_CTL);
724 it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 /* set on/off mode */
726 data->fan_main_ctrl &= ~(1 << nr);
Jean Delvare5f2dc792010-03-05 22:17:18 +0100727 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
728 data->fan_main_ctrl);
Jean Delvareb99883d2010-03-05 22:17:15 +0100729 } else {
730 if (val == 1) /* Manual mode */
731 data->pwm_ctrl[nr] = data->pwm_duty[nr];
732 else /* Automatic mode */
733 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
734 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 /* set SmartGuardian mode */
736 data->fan_main_ctrl |= (1 << nr);
Jean Delvare5f2dc792010-03-05 22:17:18 +0100737 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
738 data->fan_main_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 }
740
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100741 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 return count;
743}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200744static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
745 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200747 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
748 int nr = sensor_attr->index;
749
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200750 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100751 long val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Jean Delvaref5f64502010-03-05 22:17:19 +0100753 if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 return -EINVAL;
755
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100756 mutex_lock(&data->update_lock);
Jean Delvareb99883d2010-03-05 22:17:15 +0100757 data->pwm_duty[nr] = PWM_TO_REG(val);
758 /* If we are in manual mode, write the duty cycle immediately;
759 * otherwise, just store it for later use. */
760 if (!(data->pwm_ctrl[nr] & 0x80)) {
761 data->pwm_ctrl[nr] = data->pwm_duty[nr];
762 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
763 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100764 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 return count;
766}
Jean Delvaref8d0c192007-02-14 21:15:02 +0100767static ssize_t set_pwm_freq(struct device *dev,
768 struct device_attribute *attr, const char *buf, size_t count)
769{
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200770 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100771 unsigned long val;
Jean Delvaref8d0c192007-02-14 21:15:02 +0100772 int i;
773
Jean Delvaref5f64502010-03-05 22:17:19 +0100774 if (strict_strtoul(buf, 10, &val) < 0)
775 return -EINVAL;
776
Jean Delvaref8d0c192007-02-14 21:15:02 +0100777 /* Search for the nearest available frequency */
778 for (i = 0; i < 7; i++) {
779 if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
780 break;
781 }
782
783 mutex_lock(&data->update_lock);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200784 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
Jean Delvaref8d0c192007-02-14 21:15:02 +0100785 data->fan_ctl |= i << 4;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200786 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
Jean Delvaref8d0c192007-02-14 21:15:02 +0100787 mutex_unlock(&data->update_lock);
788
789 return count;
790}
Jean Delvare94ac7ee2010-03-05 22:17:16 +0100791static ssize_t show_pwm_temp_map(struct device *dev,
792 struct device_attribute *attr, char *buf)
793{
794 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
795 int nr = sensor_attr->index;
796
797 struct it87_data *data = it87_update_device(dev);
798 int map;
799
800 if (data->pwm_temp_map[nr] < 3)
801 map = 1 << data->pwm_temp_map[nr];
802 else
803 map = 0; /* Should never happen */
804 return sprintf(buf, "%d\n", map);
805}
806static ssize_t set_pwm_temp_map(struct device *dev,
807 struct device_attribute *attr, const char *buf, size_t count)
808{
809 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
810 int nr = sensor_attr->index;
811
812 struct it87_data *data = dev_get_drvdata(dev);
813 long val;
814 u8 reg;
815
816 if (strict_strtol(buf, 10, &val) < 0)
817 return -EINVAL;
818
819 switch (val) {
820 case (1 << 0):
821 reg = 0x00;
822 break;
823 case (1 << 1):
824 reg = 0x01;
825 break;
826 case (1 << 2):
827 reg = 0x02;
828 break;
829 default:
830 return -EINVAL;
831 }
832
833 mutex_lock(&data->update_lock);
834 data->pwm_temp_map[nr] = reg;
835 /* If we are in automatic mode, write the temp mapping immediately;
836 * otherwise, just store it for later use. */
837 if (data->pwm_ctrl[nr] & 0x80) {
838 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
839 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
840 }
841 mutex_unlock(&data->update_lock);
842 return count;
843}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844
Jean Delvare20ad93d2005-06-05 11:53:25 +0200845#define show_fan_offset(offset) \
846static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
847 show_fan, NULL, offset - 1); \
848static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
849 show_fan_min, set_fan_min, offset - 1); \
850static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
851 show_fan_div, set_fan_div, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
853show_fan_offset(1);
854show_fan_offset(2);
855show_fan_offset(3);
856
857#define show_pwm_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +0200858static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
859 show_pwm_enable, set_pwm_enable, offset - 1); \
860static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
Jean Delvaref8d0c192007-02-14 21:15:02 +0100861 show_pwm, set_pwm, offset - 1); \
862static DEVICE_ATTR(pwm##offset##_freq, \
863 (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \
Jean Delvare94ac7ee2010-03-05 22:17:16 +0100864 show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL)); \
865static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels_temp, \
866 S_IRUGO, show_pwm_temp_map, set_pwm_temp_map, \
867 offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
869show_pwm_offset(1);
870show_pwm_offset(2);
871show_pwm_offset(3);
872
Jean Delvare17d648b2006-08-28 14:23:46 +0200873/* A different set of callbacks for 16-bit fans */
874static ssize_t show_fan16(struct device *dev, struct device_attribute *attr,
875 char *buf)
876{
877 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
878 int nr = sensor_attr->index;
879 struct it87_data *data = it87_update_device(dev);
880 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan[nr]));
881}
882
883static ssize_t show_fan16_min(struct device *dev, struct device_attribute *attr,
884 char *buf)
885{
886 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
887 int nr = sensor_attr->index;
888 struct it87_data *data = it87_update_device(dev);
889 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan_min[nr]));
890}
891
892static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
893 const char *buf, size_t count)
894{
895 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
896 int nr = sensor_attr->index;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200897 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100898 long val;
899
900 if (strict_strtol(buf, 10, &val) < 0)
901 return -EINVAL;
Jean Delvare17d648b2006-08-28 14:23:46 +0200902
903 mutex_lock(&data->update_lock);
904 data->fan_min[nr] = FAN16_TO_REG(val);
Jean Delvarec7f1f712007-09-03 17:11:46 +0200905 it87_write_value(data, IT87_REG_FAN_MIN[nr],
Jean Delvare17d648b2006-08-28 14:23:46 +0200906 data->fan_min[nr] & 0xff);
Jean Delvarec7f1f712007-09-03 17:11:46 +0200907 it87_write_value(data, IT87_REG_FANX_MIN[nr],
Jean Delvare17d648b2006-08-28 14:23:46 +0200908 data->fan_min[nr] >> 8);
909 mutex_unlock(&data->update_lock);
910 return count;
911}
912
913/* We want to use the same sysfs file names as 8-bit fans, but we need
914 different variable names, so we have to use SENSOR_ATTR instead of
915 SENSOR_DEVICE_ATTR. */
916#define show_fan16_offset(offset) \
917static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
918 = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
919 show_fan16, NULL, offset - 1); \
920static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \
921 = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
922 show_fan16_min, set_fan16_min, offset - 1)
923
924show_fan16_offset(1);
925show_fan16_offset(2);
926show_fan16_offset(3);
Jean Delvarec7f1f712007-09-03 17:11:46 +0200927show_fan16_offset(4);
928show_fan16_offset(5);
Jean Delvare17d648b2006-08-28 14:23:46 +0200929
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930/* Alarms */
Jean Delvare5f2dc792010-03-05 22:17:18 +0100931static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
932 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933{
934 struct it87_data *data = it87_update_device(dev);
Jean Delvare68188ba2005-05-16 18:52:38 +0200935 return sprintf(buf, "%u\n", data->alarms);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936}
Jean Delvare1d66c642005-04-18 21:16:59 -0700937static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
Jean Delvare0124dd72007-11-25 16:16:41 +0100939static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
940 char *buf)
941{
942 int bitnr = to_sensor_dev_attr(attr)->index;
943 struct it87_data *data = it87_update_device(dev);
944 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
945}
946static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
947static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
948static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
949static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
950static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
951static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
952static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
953static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
954static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
955static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
956static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
957static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
958static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
959static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
960static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
961static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
962
Jean Delvared9b327c2010-03-05 22:17:17 +0100963static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
964 char *buf)
965{
966 int bitnr = to_sensor_dev_attr(attr)->index;
967 struct it87_data *data = it87_update_device(dev);
968 return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1);
969}
970static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
971 const char *buf, size_t count)
972{
973 int bitnr = to_sensor_dev_attr(attr)->index;
974 struct it87_data *data = dev_get_drvdata(dev);
975 long val;
976
977 if (strict_strtol(buf, 10, &val) < 0
978 || (val != 0 && val != 1))
979 return -EINVAL;
980
981 mutex_lock(&data->update_lock);
982 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
983 if (val)
984 data->beeps |= (1 << bitnr);
985 else
986 data->beeps &= ~(1 << bitnr);
987 it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps);
988 mutex_unlock(&data->update_lock);
989 return count;
990}
991
992static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
993 show_beep, set_beep, 1);
994static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1);
995static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1);
996static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1);
997static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1);
998static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1);
999static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1);
1000static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1);
1001/* fanX_beep writability is set later */
1002static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0);
1003static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0);
1004static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0);
1005static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0);
1006static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0);
1007static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
1008 show_beep, set_beep, 2);
1009static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
1010static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2);
1011
Jean Delvare5f2dc792010-03-05 22:17:18 +01001012static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
1013 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014{
Jean Delvare90d66192007-10-08 18:24:35 +02001015 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvarea7be58a2005-12-18 16:40:14 +01001016 return sprintf(buf, "%u\n", data->vrm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017}
Jean Delvare5f2dc792010-03-05 22:17:18 +01001018static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
1019 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001021 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +01001022 unsigned long val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001023
Jean Delvaref5f64502010-03-05 22:17:19 +01001024 if (strict_strtoul(buf, 10, &val) < 0)
1025 return -EINVAL;
1026
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 data->vrm = val;
1028
1029 return count;
1030}
1031static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032
Jean Delvare5f2dc792010-03-05 22:17:18 +01001033static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
1034 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035{
1036 struct it87_data *data = it87_update_device(dev);
1037 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
1038}
1039static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
Jean Delvare87808be2006-09-24 21:17:13 +02001040
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001041static ssize_t show_name(struct device *dev, struct device_attribute
1042 *devattr, char *buf)
1043{
1044 struct it87_data *data = dev_get_drvdata(dev);
1045 return sprintf(buf, "%s\n", data->name);
1046}
1047static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
1048
Jean Delvare87808be2006-09-24 21:17:13 +02001049static struct attribute *it87_attributes[] = {
1050 &sensor_dev_attr_in0_input.dev_attr.attr,
1051 &sensor_dev_attr_in1_input.dev_attr.attr,
1052 &sensor_dev_attr_in2_input.dev_attr.attr,
1053 &sensor_dev_attr_in3_input.dev_attr.attr,
1054 &sensor_dev_attr_in4_input.dev_attr.attr,
1055 &sensor_dev_attr_in5_input.dev_attr.attr,
1056 &sensor_dev_attr_in6_input.dev_attr.attr,
1057 &sensor_dev_attr_in7_input.dev_attr.attr,
1058 &sensor_dev_attr_in8_input.dev_attr.attr,
1059 &sensor_dev_attr_in0_min.dev_attr.attr,
1060 &sensor_dev_attr_in1_min.dev_attr.attr,
1061 &sensor_dev_attr_in2_min.dev_attr.attr,
1062 &sensor_dev_attr_in3_min.dev_attr.attr,
1063 &sensor_dev_attr_in4_min.dev_attr.attr,
1064 &sensor_dev_attr_in5_min.dev_attr.attr,
1065 &sensor_dev_attr_in6_min.dev_attr.attr,
1066 &sensor_dev_attr_in7_min.dev_attr.attr,
1067 &sensor_dev_attr_in0_max.dev_attr.attr,
1068 &sensor_dev_attr_in1_max.dev_attr.attr,
1069 &sensor_dev_attr_in2_max.dev_attr.attr,
1070 &sensor_dev_attr_in3_max.dev_attr.attr,
1071 &sensor_dev_attr_in4_max.dev_attr.attr,
1072 &sensor_dev_attr_in5_max.dev_attr.attr,
1073 &sensor_dev_attr_in6_max.dev_attr.attr,
1074 &sensor_dev_attr_in7_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001075 &sensor_dev_attr_in0_alarm.dev_attr.attr,
1076 &sensor_dev_attr_in1_alarm.dev_attr.attr,
1077 &sensor_dev_attr_in2_alarm.dev_attr.attr,
1078 &sensor_dev_attr_in3_alarm.dev_attr.attr,
1079 &sensor_dev_attr_in4_alarm.dev_attr.attr,
1080 &sensor_dev_attr_in5_alarm.dev_attr.attr,
1081 &sensor_dev_attr_in6_alarm.dev_attr.attr,
1082 &sensor_dev_attr_in7_alarm.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001083
1084 &sensor_dev_attr_temp1_input.dev_attr.attr,
1085 &sensor_dev_attr_temp2_input.dev_attr.attr,
1086 &sensor_dev_attr_temp3_input.dev_attr.attr,
1087 &sensor_dev_attr_temp1_max.dev_attr.attr,
1088 &sensor_dev_attr_temp2_max.dev_attr.attr,
1089 &sensor_dev_attr_temp3_max.dev_attr.attr,
1090 &sensor_dev_attr_temp1_min.dev_attr.attr,
1091 &sensor_dev_attr_temp2_min.dev_attr.attr,
1092 &sensor_dev_attr_temp3_min.dev_attr.attr,
1093 &sensor_dev_attr_temp1_type.dev_attr.attr,
1094 &sensor_dev_attr_temp2_type.dev_attr.attr,
1095 &sensor_dev_attr_temp3_type.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001096 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
1097 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
1098 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001099
1100 &dev_attr_alarms.attr,
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001101 &dev_attr_name.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001102 NULL
1103};
1104
1105static const struct attribute_group it87_group = {
1106 .attrs = it87_attributes,
1107};
1108
Jean Delvared9b327c2010-03-05 22:17:17 +01001109static struct attribute *it87_attributes_beep[] = {
1110 &sensor_dev_attr_in0_beep.dev_attr.attr,
1111 &sensor_dev_attr_in1_beep.dev_attr.attr,
1112 &sensor_dev_attr_in2_beep.dev_attr.attr,
1113 &sensor_dev_attr_in3_beep.dev_attr.attr,
1114 &sensor_dev_attr_in4_beep.dev_attr.attr,
1115 &sensor_dev_attr_in5_beep.dev_attr.attr,
1116 &sensor_dev_attr_in6_beep.dev_attr.attr,
1117 &sensor_dev_attr_in7_beep.dev_attr.attr,
1118
1119 &sensor_dev_attr_temp1_beep.dev_attr.attr,
1120 &sensor_dev_attr_temp2_beep.dev_attr.attr,
1121 &sensor_dev_attr_temp3_beep.dev_attr.attr,
1122 NULL
1123};
1124
1125static const struct attribute_group it87_group_beep = {
1126 .attrs = it87_attributes_beep,
1127};
1128
Jean Delvare723a0aa2010-03-05 22:17:16 +01001129static struct attribute *it87_attributes_fan16[5][3+1] = { {
Jean Delvare87808be2006-09-24 21:17:13 +02001130 &sensor_dev_attr_fan1_input16.dev_attr.attr,
1131 &sensor_dev_attr_fan1_min16.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001132 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1133 NULL
1134}, {
Jean Delvare87808be2006-09-24 21:17:13 +02001135 &sensor_dev_attr_fan2_input16.dev_attr.attr,
1136 &sensor_dev_attr_fan2_min16.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001137 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1138 NULL
1139}, {
Jean Delvare87808be2006-09-24 21:17:13 +02001140 &sensor_dev_attr_fan3_input16.dev_attr.attr,
1141 &sensor_dev_attr_fan3_min16.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001142 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
1143 NULL
1144}, {
Jean Delvarec7f1f712007-09-03 17:11:46 +02001145 &sensor_dev_attr_fan4_input16.dev_attr.attr,
1146 &sensor_dev_attr_fan4_min16.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001147 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1148 NULL
1149}, {
Jean Delvarec7f1f712007-09-03 17:11:46 +02001150 &sensor_dev_attr_fan5_input16.dev_attr.attr,
1151 &sensor_dev_attr_fan5_min16.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001152 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
1153 NULL
1154} };
Jean Delvare87808be2006-09-24 21:17:13 +02001155
Jean Delvare723a0aa2010-03-05 22:17:16 +01001156static const struct attribute_group it87_group_fan16[5] = {
1157 { .attrs = it87_attributes_fan16[0] },
1158 { .attrs = it87_attributes_fan16[1] },
1159 { .attrs = it87_attributes_fan16[2] },
1160 { .attrs = it87_attributes_fan16[3] },
1161 { .attrs = it87_attributes_fan16[4] },
1162};
1163
1164static struct attribute *it87_attributes_fan[3][4+1] = { {
Jean Delvare87808be2006-09-24 21:17:13 +02001165 &sensor_dev_attr_fan1_input.dev_attr.attr,
1166 &sensor_dev_attr_fan1_min.dev_attr.attr,
1167 &sensor_dev_attr_fan1_div.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001168 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1169 NULL
1170}, {
Jean Delvare87808be2006-09-24 21:17:13 +02001171 &sensor_dev_attr_fan2_input.dev_attr.attr,
1172 &sensor_dev_attr_fan2_min.dev_attr.attr,
1173 &sensor_dev_attr_fan2_div.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001174 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1175 NULL
1176}, {
Jean Delvare87808be2006-09-24 21:17:13 +02001177 &sensor_dev_attr_fan3_input.dev_attr.attr,
1178 &sensor_dev_attr_fan3_min.dev_attr.attr,
1179 &sensor_dev_attr_fan3_div.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001180 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001181 NULL
1182} };
Jean Delvare0124dd72007-11-25 16:16:41 +01001183
Jean Delvare723a0aa2010-03-05 22:17:16 +01001184static const struct attribute_group it87_group_fan[3] = {
1185 { .attrs = it87_attributes_fan[0] },
1186 { .attrs = it87_attributes_fan[1] },
1187 { .attrs = it87_attributes_fan[2] },
1188};
1189
1190static const struct attribute_group *
1191it87_get_fan_group(const struct it87_data *data)
1192{
1193 return has_16bit_fans(data) ? it87_group_fan16 : it87_group_fan;
1194}
1195
1196static struct attribute *it87_attributes_pwm[3][4+1] = { {
Jean Delvare87808be2006-09-24 21:17:13 +02001197 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001198 &sensor_dev_attr_pwm1.dev_attr.attr,
Jean Delvared5b0b5d2007-12-14 14:41:53 +01001199 &dev_attr_pwm1_freq.attr,
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001200 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001201 NULL
1202}, {
1203 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1204 &sensor_dev_attr_pwm2.dev_attr.attr,
1205 &dev_attr_pwm2_freq.attr,
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001206 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001207 NULL
1208}, {
1209 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1210 &sensor_dev_attr_pwm3.dev_attr.attr,
1211 &dev_attr_pwm3_freq.attr,
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001212 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001213 NULL
1214} };
Jean Delvare87808be2006-09-24 21:17:13 +02001215
Jean Delvare723a0aa2010-03-05 22:17:16 +01001216static const struct attribute_group it87_group_pwm[3] = {
1217 { .attrs = it87_attributes_pwm[0] },
1218 { .attrs = it87_attributes_pwm[1] },
1219 { .attrs = it87_attributes_pwm[2] },
1220};
1221
Jean Delvared9b327c2010-03-05 22:17:17 +01001222static struct attribute *it87_attributes_fan_beep[] = {
1223 &sensor_dev_attr_fan1_beep.dev_attr.attr,
1224 &sensor_dev_attr_fan2_beep.dev_attr.attr,
1225 &sensor_dev_attr_fan3_beep.dev_attr.attr,
1226 &sensor_dev_attr_fan4_beep.dev_attr.attr,
1227 &sensor_dev_attr_fan5_beep.dev_attr.attr,
1228};
1229
Jean Delvare6a8d7ac2010-03-05 22:17:16 +01001230static struct attribute *it87_attributes_vid[] = {
Jean Delvare87808be2006-09-24 21:17:13 +02001231 &dev_attr_vrm.attr,
1232 &dev_attr_cpu0_vid.attr,
1233 NULL
1234};
1235
Jean Delvare6a8d7ac2010-03-05 22:17:16 +01001236static const struct attribute_group it87_group_vid = {
1237 .attrs = it87_attributes_vid,
Jean Delvare87808be2006-09-24 21:17:13 +02001238};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
Jean Delvare2d8672c2005-07-19 23:56:35 +02001240/* SuperIO detection - will change isa_address if a chip is found */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001241static int __init it87_find(unsigned short *address,
1242 struct it87_sio_data *sio_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243{
1244 int err = -ENODEV;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001245 u16 chip_type;
Jean Delvare98dd22c2008-10-09 15:33:58 +02001246 const char *board_vendor, *board_name;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247
1248 superio_enter();
Jean Delvare67b671b2007-12-06 23:13:42 +01001249 chip_type = force_id ? force_id : superio_inw(DEVID);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001250
1251 switch (chip_type) {
1252 case IT8705F_DEVID:
1253 sio_data->type = it87;
1254 break;
1255 case IT8712F_DEVID:
1256 sio_data->type = it8712;
1257 break;
1258 case IT8716F_DEVID:
1259 case IT8726F_DEVID:
1260 sio_data->type = it8716;
1261 break;
1262 case IT8718F_DEVID:
1263 sio_data->type = it8718;
1264 break;
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +01001265 case IT8720F_DEVID:
1266 sio_data->type = it8720;
1267 break;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001268 case 0xffff: /* No device at all */
1269 goto exit;
1270 default:
1271 pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%x)\n",
1272 chip_type);
1273 goto exit;
1274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
Jean Delvare87673dd2006-08-28 14:37:19 +02001276 superio_select(PME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
1278 pr_info("it87: Device not activated, skipping\n");
1279 goto exit;
1280 }
1281
1282 *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
1283 if (*address == 0) {
1284 pr_info("it87: Base address not set, skipping\n");
1285 goto exit;
1286 }
1287
1288 err = 0;
Andrew Paprocki04751692008-08-06 22:41:06 +02001289 sio_data->revision = superio_inb(DEVREV) & 0x0f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n",
Andrew Paprocki04751692008-08-06 22:41:06 +02001291 chip_type, *address, sio_data->revision);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Jean Delvare87673dd2006-08-28 14:37:19 +02001293 /* Read GPIO config and VID value from LDN 7 (GPIO) */
Jean Delvare895ff262009-12-09 20:35:47 +01001294 if (sio_data->type == it87) {
1295 /* The IT8705F doesn't have VID pins at all */
1296 sio_data->skip_vid = 1;
Jean Delvared9b327c2010-03-05 22:17:17 +01001297
1298 /* The IT8705F has a different LD number for GPIO */
1299 superio_select(5);
1300 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
Jean Delvare895ff262009-12-09 20:35:47 +01001301 } else {
Jean Delvare87673dd2006-08-28 14:37:19 +02001302 int reg;
1303
1304 superio_select(GPIO);
Jean Delvare895ff262009-12-09 20:35:47 +01001305 /* We need at least 4 VID pins */
1306 reg = superio_inb(IT87_SIO_GPIO3_REG);
1307 if (reg & 0x0f) {
1308 pr_info("it87: VID is disabled (pins used for GPIO)\n");
1309 sio_data->skip_vid = 1;
1310 }
1311
Jean Delvare591ec652009-12-09 20:35:48 +01001312 /* Check if fan3 is there or not */
1313 if (reg & (1 << 6))
1314 sio_data->skip_pwm |= (1 << 2);
1315 if (reg & (1 << 7))
1316 sio_data->skip_fan |= (1 << 2);
1317
1318 /* Check if fan2 is there or not */
1319 reg = superio_inb(IT87_SIO_GPIO5_REG);
1320 if (reg & (1 << 1))
1321 sio_data->skip_pwm |= (1 << 1);
1322 if (reg & (1 << 2))
1323 sio_data->skip_fan |= (1 << 1);
1324
Jean Delvare895ff262009-12-09 20:35:47 +01001325 if ((sio_data->type == it8718 || sio_data->type == it8720)
1326 && !(sio_data->skip_vid))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001327 sio_data->vid_value = superio_inb(IT87_SIO_VID_REG);
Jean Delvare87673dd2006-08-28 14:37:19 +02001328
1329 reg = superio_inb(IT87_SIO_PINX2_REG);
1330 if (reg & (1 << 0))
1331 pr_info("it87: in3 is VCC (+5V)\n");
1332 if (reg & (1 << 1))
1333 pr_info("it87: in7 is VCCH (+5V Stand-By)\n");
Jean Delvared9b327c2010-03-05 22:17:17 +01001334
1335 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
Jean Delvare87673dd2006-08-28 14:37:19 +02001336 }
Jean Delvared9b327c2010-03-05 22:17:17 +01001337 if (sio_data->beep_pin)
1338 pr_info("it87: Beeping is supported\n");
Jean Delvare87673dd2006-08-28 14:37:19 +02001339
Jean Delvare98dd22c2008-10-09 15:33:58 +02001340 /* Disable specific features based on DMI strings */
1341 board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
1342 board_name = dmi_get_system_info(DMI_BOARD_NAME);
1343 if (board_vendor && board_name) {
1344 if (strcmp(board_vendor, "nVIDIA") == 0
1345 && strcmp(board_name, "FN68PT") == 0) {
1346 /* On the Shuttle SN68PT, FAN_CTL2 is apparently not
1347 connected to a fan, but to something else. One user
1348 has reported instant system power-off when changing
1349 the PWM2 duty cycle, so we disable it.
1350 I use the board name string as the trigger in case
1351 the same board is ever used in other systems. */
1352 pr_info("it87: Disabling pwm2 due to "
1353 "hardware constraints\n");
1354 sio_data->skip_pwm = (1 << 1);
1355 }
1356 }
1357
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358exit:
1359 superio_exit();
1360 return err;
1361}
1362
Jean Delvare723a0aa2010-03-05 22:17:16 +01001363static void it87_remove_files(struct device *dev)
1364{
1365 struct it87_data *data = platform_get_drvdata(pdev);
1366 struct it87_sio_data *sio_data = dev->platform_data;
1367 const struct attribute_group *fan_group = it87_get_fan_group(data);
1368 int i;
1369
1370 sysfs_remove_group(&dev->kobj, &it87_group);
Jean Delvared9b327c2010-03-05 22:17:17 +01001371 if (sio_data->beep_pin)
1372 sysfs_remove_group(&dev->kobj, &it87_group_beep);
Jean Delvare723a0aa2010-03-05 22:17:16 +01001373 for (i = 0; i < 5; i++) {
1374 if (!(data->has_fan & (1 << i)))
1375 continue;
1376 sysfs_remove_group(&dev->kobj, &fan_group[i]);
Jean Delvared9b327c2010-03-05 22:17:17 +01001377 if (sio_data->beep_pin)
1378 sysfs_remove_file(&dev->kobj,
1379 it87_attributes_fan_beep[i]);
Jean Delvare723a0aa2010-03-05 22:17:16 +01001380 }
1381 for (i = 0; i < 3; i++) {
1382 if (sio_data->skip_pwm & (1 << 0))
1383 continue;
1384 sysfs_remove_group(&dev->kobj, &it87_group_pwm[i]);
1385 }
Jean Delvare6a8d7ac2010-03-05 22:17:16 +01001386 if (!sio_data->skip_vid)
1387 sysfs_remove_group(&dev->kobj, &it87_group_vid);
Jean Delvare723a0aa2010-03-05 22:17:16 +01001388}
1389
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001390static int __devinit it87_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 struct it87_data *data;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001393 struct resource *res;
1394 struct device *dev = &pdev->dev;
1395 struct it87_sio_data *sio_data = dev->platform_data;
Jean Delvare723a0aa2010-03-05 22:17:16 +01001396 const struct attribute_group *fan_group;
1397 int err = 0, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398 int enable_pwm_interface;
Jean Delvared9b327c2010-03-05 22:17:17 +01001399 int fan_beep_need_rw;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001400 static const char *names[] = {
1401 "it87",
1402 "it8712",
1403 "it8716",
1404 "it8718",
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +01001405 "it8720",
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001406 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001408 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
Bjorn Helgaas87b4b662008-01-22 07:21:03 -05001409 if (!request_region(res->start, IT87_EC_EXTENT, DRVNAME)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001410 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
1411 (unsigned long)res->start,
Bjorn Helgaas87b4b662008-01-22 07:21:03 -05001412 (unsigned long)(res->start + IT87_EC_EXTENT - 1));
Jean Delvare8e9afcb2006-12-12 18:18:28 +01001413 err = -EBUSY;
1414 goto ERROR0;
1415 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416
Jean Delvare5f2dc792010-03-05 22:17:18 +01001417 data = kzalloc(sizeof(struct it87_data), GFP_KERNEL);
1418 if (!data) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 err = -ENOMEM;
1420 goto ERROR1;
1421 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001423 data->addr = res->start;
1424 data->type = sio_data->type;
Andrew Paprocki04751692008-08-06 22:41:06 +02001425 data->revision = sio_data->revision;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001426 data->name = names[sio_data->type];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427
1428 /* Now, we do the remaining detection. */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001429 if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)
1430 || it87_read_value(data, IT87_REG_CHIPID) != 0x90) {
Jean Delvare8e9afcb2006-12-12 18:18:28 +01001431 err = -ENODEV;
1432 goto ERROR2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 }
1434
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001435 platform_set_drvdata(pdev, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001437 mutex_init(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 /* Check PWM configuration */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001440 enable_pwm_interface = it87_check_pwm(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
1442 /* Initialize the IT87 chip */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001443 it87_init_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444
1445 /* Register sysfs hooks */
Jean Delvare5f2dc792010-03-05 22:17:18 +01001446 err = sysfs_create_group(&dev->kobj, &it87_group);
1447 if (err)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001448 goto ERROR2;
Jean Delvare17d648b2006-08-28 14:23:46 +02001449
Jean Delvared9b327c2010-03-05 22:17:17 +01001450 if (sio_data->beep_pin) {
1451 err = sysfs_create_group(&dev->kobj, &it87_group_beep);
1452 if (err)
1453 goto ERROR4;
1454 }
1455
Jean Delvare9060f8b2006-08-28 14:24:17 +02001456 /* Do not create fan files for disabled fans */
Jean Delvare723a0aa2010-03-05 22:17:16 +01001457 fan_group = it87_get_fan_group(data);
Jean Delvared9b327c2010-03-05 22:17:17 +01001458 fan_beep_need_rw = 1;
Jean Delvare723a0aa2010-03-05 22:17:16 +01001459 for (i = 0; i < 5; i++) {
1460 if (!(data->has_fan & (1 << i)))
1461 continue;
1462 err = sysfs_create_group(&dev->kobj, &fan_group[i]);
1463 if (err)
1464 goto ERROR4;
Jean Delvared9b327c2010-03-05 22:17:17 +01001465
1466 if (sio_data->beep_pin) {
1467 err = sysfs_create_file(&dev->kobj,
1468 it87_attributes_fan_beep[i]);
1469 if (err)
1470 goto ERROR4;
1471 if (!fan_beep_need_rw)
1472 continue;
1473
1474 /* As we have a single beep enable bit for all fans,
1475 * only the first enabled fan has a writable attribute
1476 * for it. */
1477 if (sysfs_chmod_file(&dev->kobj,
1478 it87_attributes_fan_beep[i],
1479 S_IRUGO | S_IWUSR))
1480 dev_dbg(dev, "chmod +w fan%d_beep failed\n",
1481 i + 1);
1482 fan_beep_need_rw = 0;
1483 }
Jean Delvare17d648b2006-08-28 14:23:46 +02001484 }
1485
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 if (enable_pwm_interface) {
Jean Delvare723a0aa2010-03-05 22:17:16 +01001487 for (i = 0; i < 3; i++) {
1488 if (sio_data->skip_pwm & (1 << i))
1489 continue;
1490 err = sysfs_create_group(&dev->kobj,
1491 &it87_group_pwm[i]);
1492 if (err)
Jean Delvare98dd22c2008-10-09 15:33:58 +02001493 goto ERROR4;
1494 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495 }
1496
Jean Delvare895ff262009-12-09 20:35:47 +01001497 if (!sio_data->skip_vid) {
Jean Delvare303760b2005-07-31 21:52:01 +02001498 data->vrm = vid_which_vrm();
Jean Delvare87673dd2006-08-28 14:37:19 +02001499 /* VID reading from Super-I/O config space if available */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001500 data->vid = sio_data->vid_value;
Jean Delvare6a8d7ac2010-03-05 22:17:16 +01001501 err = sysfs_create_group(&dev->kobj, &it87_group_vid);
1502 if (err)
Jean Delvare87808be2006-09-24 21:17:13 +02001503 goto ERROR4;
1504 }
1505
Tony Jones1beeffe2007-08-20 13:46:20 -07001506 data->hwmon_dev = hwmon_device_register(dev);
1507 if (IS_ERR(data->hwmon_dev)) {
1508 err = PTR_ERR(data->hwmon_dev);
Jean Delvare87808be2006-09-24 21:17:13 +02001509 goto ERROR4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 }
1511
1512 return 0;
1513
Jean Delvare87808be2006-09-24 21:17:13 +02001514ERROR4:
Jean Delvare723a0aa2010-03-05 22:17:16 +01001515 it87_remove_files(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516ERROR2:
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001517 platform_set_drvdata(pdev, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 kfree(data);
1519ERROR1:
Bjorn Helgaas87b4b662008-01-22 07:21:03 -05001520 release_region(res->start, IT87_EC_EXTENT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521ERROR0:
1522 return err;
1523}
1524
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001525static int __devexit it87_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001527 struct it87_data *data = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
Tony Jones1beeffe2007-08-20 13:46:20 -07001529 hwmon_device_unregister(data->hwmon_dev);
Jean Delvare723a0aa2010-03-05 22:17:16 +01001530 it87_remove_files(&pdev->dev);
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001531
Bjorn Helgaas87b4b662008-01-22 07:21:03 -05001532 release_region(data->addr, IT87_EC_EXTENT);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001533 platform_set_drvdata(pdev, NULL);
Mark M. Hoffman943b0832005-07-15 21:39:18 -04001534 kfree(data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
1536 return 0;
1537}
1538
Jean Delvare7f999aa2007-02-14 21:15:03 +01001539/* Must be called with data->update_lock held, except during initialization.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1541 would slow down the IT87 access and should not be necessary. */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001542static int it87_read_value(struct it87_data *data, u8 reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001544 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
1545 return inb_p(data->addr + IT87_DATA_REG_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546}
1547
Jean Delvare7f999aa2007-02-14 21:15:03 +01001548/* Must be called with data->update_lock held, except during initialization.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
1550 would slow down the IT87 access and should not be necessary. */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001551static void it87_write_value(struct it87_data *data, u8 reg, u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001553 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
1554 outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555}
1556
1557/* Return 1 if and only if the PWM interface is safe to use */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001558static int __devinit it87_check_pwm(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001560 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 /* Some BIOSes fail to correctly configure the IT87 fans. All fans off
1562 * and polarity set to active low is sign that this is the case so we
1563 * disable pwm control to protect the user. */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001564 int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565 if ((tmp & 0x87) == 0) {
1566 if (fix_pwm_polarity) {
1567 /* The user asks us to attempt a chip reconfiguration.
1568 * This means switching to active high polarity and
1569 * inverting all fan speed values. */
1570 int i;
1571 u8 pwm[3];
1572
1573 for (i = 0; i < 3; i++)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001574 pwm[i] = it87_read_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 IT87_REG_PWM(i));
1576
1577 /* If any fan is in automatic pwm mode, the polarity
1578 * might be correct, as suspicious as it seems, so we
1579 * better don't change anything (but still disable the
1580 * PWM interface). */
1581 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001582 dev_info(dev, "Reconfiguring PWM to "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 "active high polarity\n");
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001584 it87_write_value(data, IT87_REG_FAN_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001585 tmp | 0x87);
1586 for (i = 0; i < 3; i++)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001587 it87_write_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001588 IT87_REG_PWM(i),
1589 0x7f & ~pwm[i]);
1590 return 1;
1591 }
1592
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001593 dev_info(dev, "PWM configuration is "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 "too broken to be fixed\n");
1595 }
1596
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001597 dev_info(dev, "Detected broken BIOS "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598 "defaults, disabling PWM interface\n");
1599 return 0;
1600 } else if (fix_pwm_polarity) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001601 dev_info(dev, "PWM configuration looks "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 "sane, won't touch\n");
1603 }
1604
1605 return 1;
1606}
1607
1608/* Called when we have found a new IT87. */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001609static void __devinit it87_init_device(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610{
Jean Delvare591ec652009-12-09 20:35:48 +01001611 struct it87_sio_data *sio_data = pdev->dev.platform_data;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001612 struct it87_data *data = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 int tmp, i;
Jean Delvare591ec652009-12-09 20:35:48 +01001614 u8 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615
Jean Delvareb99883d2010-03-05 22:17:15 +01001616 /* For each PWM channel:
1617 * - If it is in automatic mode, setting to manual mode should set
1618 * the fan to full speed by default.
1619 * - If it is in manual mode, we need a mapping to temperature
1620 * channels to use when later setting to automatic mode later.
1621 * Use a 1:1 mapping by default (we are clueless.)
1622 * In both cases, the value can (and should) be changed by the user
1623 * prior to switching to a different mode. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 for (i = 0; i < 3; i++) {
Jean Delvareb99883d2010-03-05 22:17:15 +01001625 data->pwm_temp_map[i] = i;
1626 data->pwm_duty[i] = 0x7f; /* Full speed */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 }
1628
Jean Delvarec5df9b72006-08-28 14:37:54 +02001629 /* Some chips seem to have default value 0xff for all limit
1630 * registers. For low voltage limits it makes no sense and triggers
1631 * alarms, so change to 0 instead. For high temperature limits, it
1632 * means -1 degree C, which surprisingly doesn't trigger an alarm,
1633 * but is still confusing, so change to 127 degrees C. */
1634 for (i = 0; i < 8; i++) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001635 tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
Jean Delvarec5df9b72006-08-28 14:37:54 +02001636 if (tmp == 0xff)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001637 it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
Jean Delvarec5df9b72006-08-28 14:37:54 +02001638 }
1639 for (i = 0; i < 3; i++) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001640 tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i));
Jean Delvarec5df9b72006-08-28 14:37:54 +02001641 if (tmp == 0xff)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001642 it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127);
Jean Delvarec5df9b72006-08-28 14:37:54 +02001643 }
1644
Jean Delvare77fa49d2009-01-07 16:37:35 +01001645 /* Check if temperature channels are reset manually or by some reason */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001646 tmp = it87_read_value(data, IT87_REG_TEMP_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 if ((tmp & 0x3f) == 0) {
1648 /* Temp1,Temp3=thermistor; Temp2=thermal diode */
1649 tmp = (tmp & 0xc0) | 0x2a;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001650 it87_write_value(data, IT87_REG_TEMP_ENABLE, tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 }
1652 data->sensor = tmp;
1653
1654 /* Check if voltage monitors are reset manually or by some reason */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001655 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 if ((tmp & 0xff) == 0) {
1657 /* Enable all voltage monitors */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001658 it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 }
1660
1661 /* Check if tachometers are reset manually or by some reason */
Jean Delvare591ec652009-12-09 20:35:48 +01001662 mask = 0x70 & ~(sio_data->skip_fan << 4);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001663 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
Jean Delvare591ec652009-12-09 20:35:48 +01001664 if ((data->fan_main_ctrl & mask) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 /* Enable all fan tachometers */
Jean Delvare591ec652009-12-09 20:35:48 +01001666 data->fan_main_ctrl |= mask;
Jean Delvare5f2dc792010-03-05 22:17:18 +01001667 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
1668 data->fan_main_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 }
Jean Delvare9060f8b2006-08-28 14:24:17 +02001670 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
Jean Delvare17d648b2006-08-28 14:23:46 +02001672 /* Set tachometers to 16-bit mode if needed */
Andrew Paprocki04751692008-08-06 22:41:06 +02001673 if (has_16bit_fans(data)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001674 tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
Jean Delvare9060f8b2006-08-28 14:24:17 +02001675 if (~tmp & 0x07 & data->has_fan) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001676 dev_dbg(&pdev->dev,
Jean Delvare17d648b2006-08-28 14:23:46 +02001677 "Setting fan1-3 to 16-bit mode\n");
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001678 it87_write_value(data, IT87_REG_FAN_16BIT,
Jean Delvare17d648b2006-08-28 14:23:46 +02001679 tmp | 0x07);
1680 }
Andrew Paprocki816d8c62008-08-06 22:41:06 +02001681 /* IT8705F only supports three fans. */
1682 if (data->type != it87) {
1683 if (tmp & (1 << 4))
1684 data->has_fan |= (1 << 3); /* fan4 enabled */
1685 if (tmp & (1 << 5))
1686 data->has_fan |= (1 << 4); /* fan5 enabled */
1687 }
Jean Delvare17d648b2006-08-28 14:23:46 +02001688 }
1689
Jean Delvare591ec652009-12-09 20:35:48 +01001690 /* Fan input pins may be used for alternative functions */
1691 data->has_fan &= ~sio_data->skip_fan;
1692
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 /* Start monitoring */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001694 it87_write_value(data, IT87_REG_CONFIG,
1695 (it87_read_value(data, IT87_REG_CONFIG) & 0x36)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 | (update_vbat ? 0x41 : 0x01));
1697}
1698
Jean Delvareb99883d2010-03-05 22:17:15 +01001699static void it87_update_pwm_ctrl(struct it87_data *data, int nr)
1700{
1701 data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM(nr));
1702 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
1703 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
1704 else /* Manual mode */
1705 data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f;
1706}
1707
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708static struct it87_data *it87_update_device(struct device *dev)
1709{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001710 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 int i;
1712
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001713 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714
1715 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
1716 || !data->valid) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 if (update_vbat) {
1718 /* Cleared after each update, so reenable. Value
Jean Delvare5f2dc792010-03-05 22:17:18 +01001719 returned by this read will be previous value */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001720 it87_write_value(data, IT87_REG_CONFIG,
Jean Delvare5f2dc792010-03-05 22:17:18 +01001721 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722 }
1723 for (i = 0; i <= 7; i++) {
1724 data->in[i] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01001725 it87_read_value(data, IT87_REG_VIN(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 data->in_min[i] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01001727 it87_read_value(data, IT87_REG_VIN_MIN(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 data->in_max[i] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01001729 it87_read_value(data, IT87_REG_VIN_MAX(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 }
Jean Delvare3543a532006-08-28 14:27:25 +02001731 /* in8 (battery) has no limit registers */
Jean Delvare5f2dc792010-03-05 22:17:18 +01001732 data->in[8] = it87_read_value(data, IT87_REG_VIN(8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
Jean Delvarec7f1f712007-09-03 17:11:46 +02001734 for (i = 0; i < 5; i++) {
Jean Delvare9060f8b2006-08-28 14:24:17 +02001735 /* Skip disabled fans */
1736 if (!(data->has_fan & (1 << i)))
1737 continue;
1738
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 data->fan_min[i] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01001740 it87_read_value(data, IT87_REG_FAN_MIN[i]);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001741 data->fan[i] = it87_read_value(data,
Jean Delvarec7f1f712007-09-03 17:11:46 +02001742 IT87_REG_FAN[i]);
Jean Delvare17d648b2006-08-28 14:23:46 +02001743 /* Add high byte if in 16-bit mode */
Andrew Paprocki04751692008-08-06 22:41:06 +02001744 if (has_16bit_fans(data)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001745 data->fan[i] |= it87_read_value(data,
Jean Delvarec7f1f712007-09-03 17:11:46 +02001746 IT87_REG_FANX[i]) << 8;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001747 data->fan_min[i] |= it87_read_value(data,
Jean Delvarec7f1f712007-09-03 17:11:46 +02001748 IT87_REG_FANX_MIN[i]) << 8;
Jean Delvare17d648b2006-08-28 14:23:46 +02001749 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 }
1751 for (i = 0; i < 3; i++) {
1752 data->temp[i] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01001753 it87_read_value(data, IT87_REG_TEMP(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 data->temp_high[i] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01001755 it87_read_value(data, IT87_REG_TEMP_HIGH(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 data->temp_low[i] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01001757 it87_read_value(data, IT87_REG_TEMP_LOW(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 }
1759
Jean Delvare17d648b2006-08-28 14:23:46 +02001760 /* Newer chips don't have clock dividers */
Andrew Paprocki04751692008-08-06 22:41:06 +02001761 if ((data->has_fan & 0x07) && !has_16bit_fans(data)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001762 i = it87_read_value(data, IT87_REG_FAN_DIV);
Jean Delvare17d648b2006-08-28 14:23:46 +02001763 data->fan_div[0] = i & 0x07;
1764 data->fan_div[1] = (i >> 3) & 0x07;
1765 data->fan_div[2] = (i & 0x40) ? 3 : 1;
1766 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767
1768 data->alarms =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001769 it87_read_value(data, IT87_REG_ALARM1) |
1770 (it87_read_value(data, IT87_REG_ALARM2) << 8) |
1771 (it87_read_value(data, IT87_REG_ALARM3) << 16);
Jean Delvared9b327c2010-03-05 22:17:17 +01001772 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
Jean Delvareb99883d2010-03-05 22:17:15 +01001773
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001774 data->fan_main_ctrl = it87_read_value(data,
1775 IT87_REG_FAN_MAIN_CTRL);
1776 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
Jean Delvareb99883d2010-03-05 22:17:15 +01001777 for (i = 0; i < 3; i++)
1778 it87_update_pwm_ctrl(data, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001780 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
Andrew Paprocki04751692008-08-06 22:41:06 +02001781 /* The 8705 does not have VID capability.
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +01001782 The 8718 and the 8720 don't use IT87_REG_VID for the
1783 same purpose. */
Jean Delvare17d648b2006-08-28 14:23:46 +02001784 if (data->type == it8712 || data->type == it8716) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001785 data->vid = it87_read_value(data, IT87_REG_VID);
Jean Delvare17d648b2006-08-28 14:23:46 +02001786 /* The older IT8712F revisions had only 5 VID pins,
1787 but we assume it is always safe to read 6 bits. */
1788 data->vid &= 0x3f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 }
1790 data->last_updated = jiffies;
1791 data->valid = 1;
1792 }
1793
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001794 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795
1796 return data;
1797}
1798
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001799static int __init it87_device_add(unsigned short address,
1800 const struct it87_sio_data *sio_data)
1801{
1802 struct resource res = {
Bjorn Helgaas87b4b662008-01-22 07:21:03 -05001803 .start = address + IT87_EC_OFFSET,
1804 .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1,
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001805 .name = DRVNAME,
1806 .flags = IORESOURCE_IO,
1807 };
1808 int err;
1809
Jean Delvareb9acb642009-01-07 16:37:35 +01001810 err = acpi_check_resource_conflict(&res);
1811 if (err)
1812 goto exit;
1813
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001814 pdev = platform_device_alloc(DRVNAME, address);
1815 if (!pdev) {
1816 err = -ENOMEM;
1817 printk(KERN_ERR DRVNAME ": Device allocation failed\n");
1818 goto exit;
1819 }
1820
1821 err = platform_device_add_resources(pdev, &res, 1);
1822 if (err) {
1823 printk(KERN_ERR DRVNAME ": Device resource addition failed "
1824 "(%d)\n", err);
1825 goto exit_device_put;
1826 }
1827
1828 err = platform_device_add_data(pdev, sio_data,
1829 sizeof(struct it87_sio_data));
1830 if (err) {
1831 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n");
1832 goto exit_device_put;
1833 }
1834
1835 err = platform_device_add(pdev);
1836 if (err) {
1837 printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n",
1838 err);
1839 goto exit_device_put;
1840 }
1841
1842 return 0;
1843
1844exit_device_put:
1845 platform_device_put(pdev);
1846exit:
1847 return err;
1848}
1849
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850static int __init sm_it87_init(void)
1851{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001852 int err;
Jean Delvare5f2dc792010-03-05 22:17:18 +01001853 unsigned short isa_address = 0;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001854 struct it87_sio_data sio_data;
Jean Delvarefde09502005-07-19 23:51:07 +02001855
Jean Delvare98dd22c2008-10-09 15:33:58 +02001856 memset(&sio_data, 0, sizeof(struct it87_sio_data));
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001857 err = it87_find(&isa_address, &sio_data);
1858 if (err)
1859 return err;
1860 err = platform_driver_register(&it87_driver);
1861 if (err)
1862 return err;
1863
1864 err = it87_device_add(isa_address, &sio_data);
Jean Delvare5f2dc792010-03-05 22:17:18 +01001865 if (err) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001866 platform_driver_unregister(&it87_driver);
1867 return err;
1868 }
1869
1870 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871}
1872
1873static void __exit sm_it87_exit(void)
1874{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001875 platform_device_unregister(pdev);
1876 platform_driver_unregister(&it87_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877}
1878
1879
Jean Delvaref1d8e332007-11-25 16:14:44 +01001880MODULE_AUTHOR("Chris Gauthron, "
Jean Delvareb19367c2006-08-28 14:39:26 +02001881 "Jean Delvare <khali@linux-fr.org>");
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +01001882MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8720F/8726F, SiS950 driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883module_param(update_vbat, bool, 0);
1884MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
1885module_param(fix_pwm_polarity, bool, 0);
Jean Delvare5f2dc792010-03-05 22:17:18 +01001886MODULE_PARM_DESC(fix_pwm_polarity,
1887 "Force PWM polarity to active high (DANGEROUS)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888MODULE_LICENSE("GPL");
1889
1890module_init(sm_it87_init);
1891module_exit(sm_it87_exit);