blob: 7675632691824878485b32bac3cf023d12f0c052 [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
Jean Delvare44c1bcd2010-10-28 20:31:51 +020018 * IT8721F Super I/O chip w/LPC interface
Jean Delvare5f2dc792010-03-05 22:17:18 +010019 * IT8726F Super I/O chip w/LPC interface
Jean Delvare16b5dda2012-01-16 22:51:48 +010020 * IT8728F Super I/O chip w/LPC interface
Jean Delvare44c1bcd2010-10-28 20:31:51 +020021 * IT8758E Super I/O chip w/LPC interface
Guenter Roeck0531d982012-03-02 11:46:44 -080022 * IT8782F Super I/O chip w/LPC interface
23 * IT8783E/F Super I/O chip w/LPC interface
Jean Delvare5f2dc792010-03-05 22:17:18 +010024 * Sis950 A clone of the IT8705F
25 *
26 * Copyright (C) 2001 Chris Gauthron
27 * Copyright (C) 2005-2010 Jean Delvare <khali@linux-fr.org>
28 *
29 * This program is free software; you can redistribute it and/or modify
30 * it under the terms of the GNU General Public License as published by
31 * the Free Software Foundation; either version 2 of the License, or
32 * (at your option) any later version.
33 *
34 * This program is distributed in the hope that it will be useful,
35 * but WITHOUT ANY WARRANTY; without even the implied warranty of
36 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37 * GNU General Public License for more details.
38 *
39 * You should have received a copy of the GNU General Public License
40 * along with this program; if not, write to the Free Software
41 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
42 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Joe Perchesa8ca1032011-01-12 21:55:10 +010044#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
45
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#include <linux/module.h>
47#include <linux/init.h>
48#include <linux/slab.h>
49#include <linux/jiffies.h>
corentin.labbeb74f3fd2007-06-13 20:27:36 +020050#include <linux/platform_device.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040051#include <linux/hwmon.h>
Jean Delvare303760b2005-07-31 21:52:01 +020052#include <linux/hwmon-sysfs.h>
53#include <linux/hwmon-vid.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040054#include <linux/err.h>
Ingo Molnar9a61bf62006-01-18 23:19:26 +010055#include <linux/mutex.h>
Jean Delvare87808be2006-09-24 21:17:13 +020056#include <linux/sysfs.h>
Jean Delvare98dd22c2008-10-09 15:33:58 +020057#include <linux/string.h>
58#include <linux/dmi.h>
Jean Delvareb9acb642009-01-07 16:37:35 +010059#include <linux/acpi.h>
H Hartley Sweeten6055fae2009-09-15 17:18:13 +020060#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
corentin.labbeb74f3fd2007-06-13 20:27:36 +020062#define DRVNAME "it87"
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Guenter Roeck0531d982012-03-02 11:46:44 -080064enum chips { it87, it8712, it8716, it8718, it8720, it8721, it8728, it8782,
65 it8783 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
Jean Delvare67b671b2007-12-06 23:13:42 +010067static unsigned short force_id;
68module_param(force_id, ushort, 0);
69MODULE_PARM_DESC(force_id, "Override the detected device ID");
70
corentin.labbeb74f3fd2007-06-13 20:27:36 +020071static struct platform_device *pdev;
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073#define REG 0x2e /* The register to read/write */
74#define DEV 0x07 /* Register: Logical device select */
75#define VAL 0x2f /* The value to read/write */
76#define PME 0x04 /* The device with the fan registers in it */
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +010077
78/* The device with the IT8718F/IT8720F VID value in it */
79#define GPIO 0x07
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081#define DEVID 0x20 /* Register: Device ID */
82#define DEVREV 0x22 /* Register: Device Revision */
83
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +020084static inline int superio_inb(int reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
86 outb(reg, REG);
87 return inb(VAL);
88}
89
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +020090static inline void superio_outb(int reg, int val)
Jean Delvare436cad22010-07-09 16:22:48 +020091{
92 outb(reg, REG);
93 outb(val, VAL);
94}
95
Linus Torvalds1da177e2005-04-16 15:20:36 -070096static int superio_inw(int reg)
97{
98 int val;
99 outb(reg++, REG);
100 val = inb(VAL) << 8;
101 outb(reg, REG);
102 val |= inb(VAL);
103 return val;
104}
105
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +0200106static inline void superio_select(int ldn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107{
108 outb(DEV, REG);
Jean Delvare87673dd2006-08-28 14:37:19 +0200109 outb(ldn, VAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110}
111
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +0200112static inline int superio_enter(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +0200114 /*
115 * Try to reserve REG and REG + 1 for exclusive access.
116 */
117 if (!request_muxed_region(REG, 2, DRVNAME))
118 return -EBUSY;
119
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 outb(0x87, REG);
121 outb(0x01, REG);
122 outb(0x55, REG);
123 outb(0x55, REG);
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +0200124 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125}
126
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +0200127static inline void superio_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
129 outb(0x02, REG);
130 outb(0x02, VAL);
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +0200131 release_region(REG, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
133
Jean Delvare87673dd2006-08-28 14:37:19 +0200134/* Logical device 4 registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135#define IT8712F_DEVID 0x8712
136#define IT8705F_DEVID 0x8705
Jean Delvare17d648b2006-08-28 14:23:46 +0200137#define IT8716F_DEVID 0x8716
Jean Delvare87673dd2006-08-28 14:37:19 +0200138#define IT8718F_DEVID 0x8718
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +0100139#define IT8720F_DEVID 0x8720
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200140#define IT8721F_DEVID 0x8721
Rudolf Marek08a8f6e2007-06-09 10:11:16 -0400141#define IT8726F_DEVID 0x8726
Jean Delvare16b5dda2012-01-16 22:51:48 +0100142#define IT8728F_DEVID 0x8728
Guenter Roeck0531d982012-03-02 11:46:44 -0800143#define IT8782F_DEVID 0x8782
144#define IT8783E_DEVID 0x8783
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#define IT87_ACT_REG 0x30
146#define IT87_BASE_REG 0x60
147
Jean Delvare87673dd2006-08-28 14:37:19 +0200148/* Logical device 7 registers (IT8712F and later) */
Guenter Roeck0531d982012-03-02 11:46:44 -0800149#define IT87_SIO_GPIO1_REG 0x25
Jean Delvare895ff262009-12-09 20:35:47 +0100150#define IT87_SIO_GPIO3_REG 0x27
Jean Delvare591ec652009-12-09 20:35:48 +0100151#define IT87_SIO_GPIO5_REG 0x29
Guenter Roeck0531d982012-03-02 11:46:44 -0800152#define IT87_SIO_PINX1_REG 0x2a /* Pin selection */
Jean Delvare87673dd2006-08-28 14:37:19 +0200153#define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
Guenter Roeck0531d982012-03-02 11:46:44 -0800154#define IT87_SIO_SPI_REG 0xef /* SPI function pin select */
Jean Delvare87673dd2006-08-28 14:37:19 +0200155#define IT87_SIO_VID_REG 0xfc /* VID value */
Jean Delvared9b327c2010-03-05 22:17:17 +0100156#define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */
Jean Delvare87673dd2006-08-28 14:37:19 +0200157
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158/* Update battery voltage after every reading if true */
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030159static bool update_vbat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
161/* Not all BIOSes properly configure the PWM registers */
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030162static bool fix_pwm_polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164/* Many IT87 constants specified below */
165
166/* Length of ISA address segment */
167#define IT87_EXTENT 8
168
Bjorn Helgaas87b4b662008-01-22 07:21:03 -0500169/* Length of ISA address segment for Environmental Controller */
170#define IT87_EC_EXTENT 2
171
172/* Offset of EC registers from ISA base address */
173#define IT87_EC_OFFSET 5
174
175/* Where are the ISA address/data registers relative to the EC base address */
176#define IT87_ADDR_REG_OFFSET 0
177#define IT87_DATA_REG_OFFSET 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179/*----- The IT87 registers -----*/
180
181#define IT87_REG_CONFIG 0x00
182
183#define IT87_REG_ALARM1 0x01
184#define IT87_REG_ALARM2 0x02
185#define IT87_REG_ALARM3 0x03
186
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800187/*
188 * The IT8718F and IT8720F have the VID value in a different register, in
189 * Super-I/O configuration space.
190 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191#define IT87_REG_VID 0x0a
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800192/*
193 * The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
194 * for fan divisors. Later IT8712F revisions must use 16-bit tachometer
195 * mode.
196 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197#define IT87_REG_FAN_DIV 0x0b
Jean Delvare17d648b2006-08-28 14:23:46 +0200198#define IT87_REG_FAN_16BIT 0x0c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200/* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
201
Jean Delvarec7f1f712007-09-03 17:11:46 +0200202static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
203static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 };
204static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 };
205static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
Guenter Roeck161d8982012-12-19 22:17:01 +0100206static const u8 IT87_REG_TEMP_OFFSET[] = { 0x56, 0x57, 0x59 };
207
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208#define IT87_REG_FAN_MAIN_CTRL 0x13
209#define IT87_REG_FAN_CTL 0x14
210#define IT87_REG_PWM(nr) (0x15 + (nr))
Jean Delvare6229cdb2010-12-08 16:27:22 +0100211#define IT87_REG_PWM_DUTY(nr) (0x63 + (nr) * 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213#define IT87_REG_VIN(nr) (0x20 + (nr))
214#define IT87_REG_TEMP(nr) (0x29 + (nr))
215
216#define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
217#define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
218#define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
219#define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
220
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221#define IT87_REG_VIN_ENABLE 0x50
222#define IT87_REG_TEMP_ENABLE 0x51
Guenter Roeck4573acb2012-03-26 16:17:41 -0700223#define IT87_REG_TEMP_EXTRA 0x55
Jean Delvared9b327c2010-03-05 22:17:17 +0100224#define IT87_REG_BEEP_ENABLE 0x5c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226#define IT87_REG_CHIPID 0x58
227
Jean Delvare4f3f51b2010-03-05 22:17:21 +0100228#define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i))
229#define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i))
230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200232struct it87_sio_data {
233 enum chips type;
234 /* Values read from Super-I/O config space */
Andrew Paprocki04751692008-08-06 22:41:06 +0200235 u8 revision;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200236 u8 vid_value;
Jean Delvared9b327c2010-03-05 22:17:17 +0100237 u8 beep_pin;
Jean Delvare738e5e02010-08-14 21:08:50 +0200238 u8 internal; /* Internal sensors can be labeled */
Jean Delvare591ec652009-12-09 20:35:48 +0100239 /* Features skipped based on config or DMI */
Guenter Roeck9172b5d2012-03-24 21:49:54 -0700240 u16 skip_in;
Jean Delvare895ff262009-12-09 20:35:47 +0100241 u8 skip_vid;
Jean Delvare591ec652009-12-09 20:35:48 +0100242 u8 skip_fan;
Jean Delvare98dd22c2008-10-09 15:33:58 +0200243 u8 skip_pwm;
Guenter Roeck4573acb2012-03-26 16:17:41 -0700244 u8 skip_temp;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200245};
246
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800247/*
248 * For each registered chip, we need to keep some data in memory.
249 * The structure is dynamically allocated.
250 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251struct it87_data {
Tony Jones1beeffe2007-08-20 13:46:20 -0700252 struct device *hwmon_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 enum chips type;
Andrew Paprocki04751692008-08-06 22:41:06 +0200254 u8 revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200256 unsigned short addr;
257 const char *name;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100258 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 char valid; /* !=0 if following fields are valid */
260 unsigned long last_updated; /* In jiffies */
261
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200262 u16 in_scaled; /* Internal voltage sensors are scaled */
Guenter Roeck929c6a52012-12-19 22:17:00 +0100263 u8 in[9][3]; /* [nr][0]=in, [1]=min, [2]=max */
Jean Delvare9060f8b2006-08-28 14:24:17 +0200264 u8 has_fan; /* Bitfield, fans enabled */
Jean Delvarec7f1f712007-09-03 17:11:46 +0200265 u16 fan[5]; /* Register values, possibly combined */
266 u16 fan_min[5]; /* Register values, possibly combined */
Guenter Roeck4573acb2012-03-26 16:17:41 -0700267 u8 has_temp; /* Bitfield, temp sensors enabled */
Guenter Roeck161d8982012-12-19 22:17:01 +0100268 s8 temp[3][4]; /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 u8 sensor; /* Register value */
270 u8 fan_div[3]; /* Register encoding, shifted right */
271 u8 vid; /* Register encoding, combined */
Jean Delvarea7be58a2005-12-18 16:40:14 +0100272 u8 vrm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 u32 alarms; /* Register encoding, combined */
Jean Delvared9b327c2010-03-05 22:17:17 +0100274 u8 beeps; /* Register encoding */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 u8 fan_main_ctrl; /* Register value */
Jean Delvaref8d0c192007-02-14 21:15:02 +0100276 u8 fan_ctl; /* Register value */
Jean Delvareb99883d2010-03-05 22:17:15 +0100277
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800278 /*
279 * The following 3 arrays correspond to the same registers up to
Jean Delvare6229cdb2010-12-08 16:27:22 +0100280 * the IT8720F. The meaning of bits 6-0 depends on the value of bit
281 * 7, and we want to preserve settings on mode changes, so we have
282 * to track all values separately.
283 * Starting with the IT8721F, the manual PWM duty cycles are stored
284 * in separate registers (8-bit values), so the separate tracking
285 * is no longer needed, but it is still done to keep the driver
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800286 * simple.
287 */
Jean Delvareb99883d2010-03-05 22:17:15 +0100288 u8 pwm_ctrl[3]; /* Register value */
Jean Delvare6229cdb2010-12-08 16:27:22 +0100289 u8 pwm_duty[3]; /* Manual PWM value set by user */
Jean Delvareb99883d2010-03-05 22:17:15 +0100290 u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */
Jean Delvare4f3f51b2010-03-05 22:17:21 +0100291
292 /* Automatic fan speed control registers */
293 u8 auto_pwm[3][4]; /* [nr][3] is hard-coded */
294 s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295};
296
Jean Delvare16b5dda2012-01-16 22:51:48 +0100297static inline int has_12mv_adc(const struct it87_data *data)
298{
299 /*
300 * IT8721F and later have a 12 mV ADC, also with internal scaling
301 * on selected inputs.
302 */
303 return data->type == it8721
304 || data->type == it8728;
305}
306
307static inline int has_newer_autopwm(const struct it87_data *data)
308{
309 /*
310 * IT8721F and later have separate registers for the temperature
311 * mapping and the manual duty cycle.
312 */
313 return data->type == it8721
314 || data->type == it8728;
315}
316
Guenter Roeck161d8982012-12-19 22:17:01 +0100317static inline int has_temp_offset(const struct it87_data *data)
318{
319 return data->type == it8716
320 || data->type == it8718
321 || data->type == it8720
322 || data->type == it8721
323 || data->type == it8728
324 || data->type == it8782
325 || data->type == it8783;
326}
327
Guenter Roeck0531d982012-03-02 11:46:44 -0800328static int adc_lsb(const struct it87_data *data, int nr)
329{
330 int lsb = has_12mv_adc(data) ? 12 : 16;
331 if (data->in_scaled & (1 << nr))
332 lsb <<= 1;
333 return lsb;
334}
335
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200336static u8 in_to_reg(const struct it87_data *data, int nr, long val)
337{
Guenter Roeck0531d982012-03-02 11:46:44 -0800338 val = DIV_ROUND_CLOSEST(val, adc_lsb(data, nr));
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200339 return SENSORS_LIMIT(val, 0, 255);
340}
341
342static int in_from_reg(const struct it87_data *data, int nr, int val)
343{
Guenter Roeck0531d982012-03-02 11:46:44 -0800344 return val * adc_lsb(data, nr);
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200345}
Jean Delvare0df6454d2010-10-28 20:31:51 +0200346
347static inline u8 FAN_TO_REG(long rpm, int div)
348{
349 if (rpm == 0)
350 return 255;
351 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
352 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1,
353 254);
354}
355
356static inline u16 FAN16_TO_REG(long rpm)
357{
358 if (rpm == 0)
359 return 0xffff;
360 return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
361}
362
363#define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \
364 1350000 / ((val) * (div)))
365/* The divider is fixed to 2 in 16-bit mode */
366#define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
367 1350000 / ((val) * 2))
368
369#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (((val) - 500) / 1000) : \
370 ((val) + 500) / 1000), -128, 127))
371#define TEMP_FROM_REG(val) ((val) * 1000)
372
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200373static u8 pwm_to_reg(const struct it87_data *data, long val)
374{
Jean Delvare16b5dda2012-01-16 22:51:48 +0100375 if (has_newer_autopwm(data))
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200376 return val;
377 else
378 return val >> 1;
379}
380
381static int pwm_from_reg(const struct it87_data *data, u8 reg)
382{
Jean Delvare16b5dda2012-01-16 22:51:48 +0100383 if (has_newer_autopwm(data))
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200384 return reg;
385 else
386 return (reg & 0x7f) << 1;
387}
388
Jean Delvare0df6454d2010-10-28 20:31:51 +0200389
390static int DIV_TO_REG(int val)
391{
392 int answer = 0;
393 while (answer < 7 && (val >>= 1))
394 answer++;
395 return answer;
396}
397#define DIV_FROM_REG(val) (1 << (val))
398
399static const unsigned int pwm_freq[8] = {
400 48000000 / 128,
401 24000000 / 128,
402 12000000 / 128,
403 8000000 / 128,
404 6000000 / 128,
405 3000000 / 128,
406 1500000 / 128,
407 750000 / 128,
408};
409
Andrew Paprocki04751692008-08-06 22:41:06 +0200410static inline int has_16bit_fans(const struct it87_data *data)
411{
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800412 /*
413 * IT8705F Datasheet 0.4.1, 3h == Version G.
414 * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
415 * These are the first revisions with 16-bit tachometer support.
416 */
Andrew Paprocki816d8c62008-08-06 22:41:06 +0200417 return (data->type == it87 && data->revision >= 0x03)
Andrew Paprocki859b9ef2008-09-20 10:25:19 +0200418 || (data->type == it8712 && data->revision >= 0x08)
Andrew Paprocki04751692008-08-06 22:41:06 +0200419 || data->type == it8716
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +0100420 || data->type == it8718
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200421 || data->type == it8720
Jean Delvare16b5dda2012-01-16 22:51:48 +0100422 || data->type == it8721
Guenter Roeck0531d982012-03-02 11:46:44 -0800423 || data->type == it8728
424 || data->type == it8782
425 || data->type == it8783;
Andrew Paprocki04751692008-08-06 22:41:06 +0200426}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Jean Delvare4f3f51b2010-03-05 22:17:21 +0100428static inline int has_old_autopwm(const struct it87_data *data)
429{
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800430 /*
431 * The old automatic fan speed control interface is implemented
432 * by IT8705F chips up to revision F and IT8712F chips up to
433 * revision G.
434 */
Jean Delvare4f3f51b2010-03-05 22:17:21 +0100435 return (data->type == it87 && data->revision < 0x03)
436 || (data->type == it8712 && data->revision < 0x08);
437}
438
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200439static int it87_probe(struct platform_device *pdev);
Bill Pemberton281dfd02012-11-19 13:25:51 -0500440static int it87_remove(struct platform_device *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200442static int it87_read_value(struct it87_data *data, u8 reg);
443static void it87_write_value(struct it87_data *data, u8 reg, u8 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444static struct it87_data *it87_update_device(struct device *dev);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200445static int it87_check_pwm(struct device *dev);
446static void it87_init_device(struct platform_device *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200449static struct platform_driver it87_driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100450 .driver = {
Jean Delvare87218842006-09-03 22:36:14 +0200451 .owner = THIS_MODULE,
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200452 .name = DRVNAME,
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100453 },
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200454 .probe = it87_probe,
Bill Pemberton9e5e9b72012-11-19 13:21:20 -0500455 .remove = it87_remove,
Jean Delvarefde09502005-07-19 23:51:07 +0200456};
457
Jean Delvare20ad93d2005-06-05 11:53:25 +0200458static ssize_t show_in(struct device *dev, struct device_attribute *attr,
Guenter Roeck929c6a52012-12-19 22:17:00 +0100459 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460{
Guenter Roeck929c6a52012-12-19 22:17:00 +0100461 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
462 int nr = sattr->nr;
463 int index = sattr->index;
Jean Delvare20ad93d2005-06-05 11:53:25 +0200464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 struct it87_data *data = it87_update_device(dev);
Guenter Roeck929c6a52012-12-19 22:17:00 +0100466 return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467}
468
Guenter Roeck929c6a52012-12-19 22:17:00 +0100469static ssize_t set_in(struct device *dev, struct device_attribute *attr,
470 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
Guenter Roeck929c6a52012-12-19 22:17:00 +0100472 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
473 int nr = sattr->nr;
474 int index = sattr->index;
Jean Delvare20ad93d2005-06-05 11:53:25 +0200475
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200476 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100477 unsigned long val;
478
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100479 if (kstrtoul(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +0100480 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100482 mutex_lock(&data->update_lock);
Guenter Roeck929c6a52012-12-19 22:17:00 +0100483 data->in[nr][index] = in_to_reg(data, nr, val);
484 it87_write_value(data,
485 index == 1 ? IT87_REG_VIN_MIN(nr)
486 : IT87_REG_VIN_MAX(nr),
487 data->in[nr][index]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100488 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489 return count;
490}
491
Guenter Roeck929c6a52012-12-19 22:17:00 +0100492static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0);
493static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in,
494 0, 1);
495static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in,
496 0, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
Guenter Roeck929c6a52012-12-19 22:17:00 +0100498static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0);
499static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in,
500 1, 1);
501static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in,
502 1, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503
Guenter Roeck929c6a52012-12-19 22:17:00 +0100504static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0);
505static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in,
506 2, 1);
507static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in,
508 2, 2);
509
510static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0);
511static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in,
512 3, 1);
513static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in,
514 3, 2);
515
516static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0);
517static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in,
518 4, 1);
519static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in,
520 4, 2);
521
522static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, 0);
523static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in,
524 5, 1);
525static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in,
526 5, 2);
527
528static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 6, 0);
529static SENSOR_DEVICE_ATTR_2(in6_min, S_IRUGO | S_IWUSR, show_in, set_in,
530 6, 1);
531static SENSOR_DEVICE_ATTR_2(in6_max, S_IRUGO | S_IWUSR, show_in, set_in,
532 6, 2);
533
534static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 7, 0);
535static SENSOR_DEVICE_ATTR_2(in7_min, S_IRUGO | S_IWUSR, show_in, set_in,
536 7, 1);
537static SENSOR_DEVICE_ATTR_2(in7_max, S_IRUGO | S_IWUSR, show_in, set_in,
538 7, 2);
539
540static SENSOR_DEVICE_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 8, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
542/* 3 temperatures */
Jean Delvare20ad93d2005-06-05 11:53:25 +0200543static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
Guenter Roeck60ca3852012-12-19 22:17:00 +0100544 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545{
Guenter Roeck60ca3852012-12-19 22:17:00 +0100546 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
547 int nr = sattr->nr;
548 int index = sattr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 struct it87_data *data = it87_update_device(dev);
Jean Delvare20ad93d2005-06-05 11:53:25 +0200550
Guenter Roeck60ca3852012-12-19 22:17:00 +0100551 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200553
Guenter Roeck60ca3852012-12-19 22:17:00 +0100554static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
555 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556{
Guenter Roeck60ca3852012-12-19 22:17:00 +0100557 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
558 int nr = sattr->nr;
559 int index = sattr->index;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200560 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100561 long val;
Guenter Roeck161d8982012-12-19 22:17:01 +0100562 u8 reg, regval;
Jean Delvaref5f64502010-03-05 22:17:19 +0100563
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100564 if (kstrtol(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +0100565 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100567 mutex_lock(&data->update_lock);
Guenter Roeck161d8982012-12-19 22:17:01 +0100568
569 switch (index) {
570 default:
571 case 1:
572 reg = IT87_REG_TEMP_LOW(nr);
573 break;
574 case 2:
575 reg = IT87_REG_TEMP_HIGH(nr);
576 break;
577 case 3:
578 regval = it87_read_value(data, IT87_REG_BEEP_ENABLE);
579 if (!(regval & 0x80)) {
580 regval |= 0x80;
581 it87_write_value(data, IT87_REG_BEEP_ENABLE, regval);
582 }
583 data->valid = 0;
584 reg = IT87_REG_TEMP_OFFSET[nr];
585 break;
586 }
587
Guenter Roeck60ca3852012-12-19 22:17:00 +0100588 data->temp[nr][index] = TEMP_TO_REG(val);
Guenter Roeck161d8982012-12-19 22:17:01 +0100589 it87_write_value(data, reg, data->temp[nr][index]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100590 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 return count;
592}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200593
Guenter Roeck60ca3852012-12-19 22:17:00 +0100594static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0);
595static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
596 0, 1);
597static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
598 0, 2);
Guenter Roeck161d8982012-12-19 22:17:01 +0100599static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp,
600 set_temp, 0, 3);
Guenter Roeck60ca3852012-12-19 22:17:00 +0100601static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0);
602static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
603 1, 1);
604static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
605 1, 2);
Guenter Roeck161d8982012-12-19 22:17:01 +0100606static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp,
607 set_temp, 1, 3);
Guenter Roeck60ca3852012-12-19 22:17:00 +0100608static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, 0);
609static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
610 2, 1);
611static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
612 2, 2);
Guenter Roeck161d8982012-12-19 22:17:01 +0100613static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp,
614 set_temp, 2, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Guenter Roeck2cece012012-12-19 22:17:01 +0100616static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr,
617 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200619 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
620 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 struct it87_data *data = it87_update_device(dev);
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800622 u8 reg = data->sensor; /* In case value is updated while used */
Jean Delvare5f2dc792010-03-05 22:17:18 +0100623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 if (reg & (1 << nr))
625 return sprintf(buf, "3\n"); /* thermal diode */
626 if (reg & (8 << nr))
Jean Delvare4ed10772008-10-17 17:51:16 +0200627 return sprintf(buf, "4\n"); /* thermistor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 return sprintf(buf, "0\n"); /* disabled */
629}
Guenter Roeck2cece012012-12-19 22:17:01 +0100630
631static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr,
632 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200634 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
635 int nr = sensor_attr->index;
636
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200637 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100638 long val;
Jean Delvare8acf07c2010-04-14 16:14:09 +0200639 u8 reg;
Jean Delvaref5f64502010-03-05 22:17:19 +0100640
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100641 if (kstrtol(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +0100642 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
Jean Delvare8acf07c2010-04-14 16:14:09 +0200644 reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
645 reg &= ~(1 << nr);
646 reg &= ~(8 << nr);
Jean Delvare4ed10772008-10-17 17:51:16 +0200647 if (val == 2) { /* backwards compatibility */
648 dev_warn(dev, "Sensor type 2 is deprecated, please use 4 "
649 "instead\n");
650 val = 4;
651 }
652 /* 3 = thermal diode; 4 = thermistor; 0 = disabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 if (val == 3)
Jean Delvare8acf07c2010-04-14 16:14:09 +0200654 reg |= 1 << nr;
Jean Delvare4ed10772008-10-17 17:51:16 +0200655 else if (val == 4)
Jean Delvare8acf07c2010-04-14 16:14:09 +0200656 reg |= 8 << nr;
657 else if (val != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658 return -EINVAL;
Jean Delvare8acf07c2010-04-14 16:14:09 +0200659
660 mutex_lock(&data->update_lock);
661 data->sensor = reg;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200662 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
Jean Delvare2b3d1d82010-04-14 16:14:10 +0200663 data->valid = 0; /* Force cache refresh */
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100664 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 return count;
666}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Guenter Roeck2cece012012-12-19 22:17:01 +0100668static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR, show_temp_type,
669 set_temp_type, 0);
670static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type,
671 set_temp_type, 1);
672static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type,
673 set_temp_type, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
675/* 3 Fans */
Jean Delvareb99883d2010-03-05 22:17:15 +0100676
677static int pwm_mode(const struct it87_data *data, int nr)
678{
679 int ctrl = data->fan_main_ctrl & (1 << nr);
680
681 if (ctrl == 0) /* Full speed */
682 return 0;
683 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
684 return 2;
685 else /* Manual mode */
686 return 1;
687}
688
Jean Delvare20ad93d2005-06-05 11:53:25 +0200689static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
690 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200692 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
693 int nr = sensor_attr->index;
694
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 struct it87_data *data = it87_update_device(dev);
Jean Delvare5f2dc792010-03-05 22:17:18 +0100696 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 DIV_FROM_REG(data->fan_div[nr])));
698}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200699static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr,
700 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200702 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
703 int nr = sensor_attr->index;
704
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 struct it87_data *data = it87_update_device(dev);
Jean Delvare5f2dc792010-03-05 22:17:18 +0100706 return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr],
707 DIV_FROM_REG(data->fan_div[nr])));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200709static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
710 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200712 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
713 int nr = sensor_attr->index;
714
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 struct it87_data *data = it87_update_device(dev);
716 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
717}
Jean Delvare5f2dc792010-03-05 22:17:18 +0100718static ssize_t show_pwm_enable(struct device *dev,
719 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200721 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
722 int nr = sensor_attr->index;
723
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 struct it87_data *data = it87_update_device(dev);
Jean Delvareb99883d2010-03-05 22:17:15 +0100725 return sprintf(buf, "%d\n", pwm_mode(data, nr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200727static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
728 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200730 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
731 int nr = sensor_attr->index;
732
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 struct it87_data *data = it87_update_device(dev);
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200734 return sprintf(buf, "%d\n",
735 pwm_from_reg(data, data->pwm_duty[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736}
Jean Delvaref8d0c192007-02-14 21:15:02 +0100737static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
738 char *buf)
739{
740 struct it87_data *data = it87_update_device(dev);
741 int index = (data->fan_ctl >> 4) & 0x07;
742
743 return sprintf(buf, "%u\n", pwm_freq[index]);
744}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200745static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr,
746 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200748 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
749 int nr = sensor_attr->index;
750
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200751 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100752 long val;
Jean Delvare7f999aa2007-02-14 21:15:03 +0100753 u8 reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100755 if (kstrtol(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +0100756 return -EINVAL;
757
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100758 mutex_lock(&data->update_lock);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200759 reg = it87_read_value(data, IT87_REG_FAN_DIV);
Jean Delvare07eab462005-11-23 15:44:31 -0800760 switch (nr) {
Jean Delvare5f2dc792010-03-05 22:17:18 +0100761 case 0:
762 data->fan_div[nr] = reg & 0x07;
763 break;
764 case 1:
765 data->fan_div[nr] = (reg >> 3) & 0x07;
766 break;
767 case 2:
768 data->fan_div[nr] = (reg & 0x40) ? 3 : 1;
769 break;
Jean Delvare07eab462005-11-23 15:44:31 -0800770 }
771
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
Jean Delvarec7f1f712007-09-03 17:11:46 +0200773 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100774 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775 return count;
776}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200777static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
778 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200780 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
781 int nr = sensor_attr->index;
782
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200783 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100784 unsigned long val;
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200785 int min;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 u8 old;
787
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100788 if (kstrtoul(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +0100789 return -EINVAL;
790
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100791 mutex_lock(&data->update_lock);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200792 old = it87_read_value(data, IT87_REG_FAN_DIV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200794 /* Save fan min limit */
795 min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796
797 switch (nr) {
798 case 0:
799 case 1:
800 data->fan_div[nr] = DIV_TO_REG(val);
801 break;
802 case 2:
803 if (val < 8)
804 data->fan_div[nr] = 1;
805 else
806 data->fan_div[nr] = 3;
807 }
808 val = old & 0x80;
809 val |= (data->fan_div[0] & 0x07);
810 val |= (data->fan_div[1] & 0x07) << 3;
811 if (data->fan_div[2] == 3)
812 val |= 0x1 << 6;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200813 it87_write_value(data, IT87_REG_FAN_DIV, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200815 /* Restore fan min limit */
816 data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
Jean Delvarec7f1f712007-09-03 17:11:46 +0200817 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]);
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200818
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100819 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 return count;
821}
Jean Delvarecccfc9c2010-03-05 22:17:21 +0100822
823/* Returns 0 if OK, -EINVAL otherwise */
824static int check_trip_points(struct device *dev, int nr)
825{
826 const struct it87_data *data = dev_get_drvdata(dev);
827 int i, err = 0;
828
829 if (has_old_autopwm(data)) {
830 for (i = 0; i < 3; i++) {
831 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
832 err = -EINVAL;
833 }
834 for (i = 0; i < 2; i++) {
835 if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1])
836 err = -EINVAL;
837 }
838 }
839
840 if (err) {
841 dev_err(dev, "Inconsistent trip points, not switching to "
842 "automatic mode\n");
843 dev_err(dev, "Adjust the trip points and try again\n");
844 }
845 return err;
846}
847
Jean Delvare20ad93d2005-06-05 11:53:25 +0200848static ssize_t set_pwm_enable(struct device *dev,
849 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200851 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
852 int nr = sensor_attr->index;
853
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200854 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100855 long val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100857 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 2)
Jean Delvareb99883d2010-03-05 22:17:15 +0100858 return -EINVAL;
859
Jean Delvarecccfc9c2010-03-05 22:17:21 +0100860 /* Check trip points before switching to automatic mode */
861 if (val == 2) {
862 if (check_trip_points(dev, nr) < 0)
863 return -EINVAL;
864 }
865
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100866 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867
868 if (val == 0) {
869 int tmp;
870 /* make sure the fan is on when in on/off mode */
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200871 tmp = it87_read_value(data, IT87_REG_FAN_CTL);
872 it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 /* set on/off mode */
874 data->fan_main_ctrl &= ~(1 << nr);
Jean Delvare5f2dc792010-03-05 22:17:18 +0100875 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
876 data->fan_main_ctrl);
Jean Delvareb99883d2010-03-05 22:17:15 +0100877 } else {
878 if (val == 1) /* Manual mode */
Jean Delvare16b5dda2012-01-16 22:51:48 +0100879 data->pwm_ctrl[nr] = has_newer_autopwm(data) ?
Jean Delvare6229cdb2010-12-08 16:27:22 +0100880 data->pwm_temp_map[nr] :
881 data->pwm_duty[nr];
Jean Delvareb99883d2010-03-05 22:17:15 +0100882 else /* Automatic mode */
883 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
884 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 /* set SmartGuardian mode */
886 data->fan_main_ctrl |= (1 << nr);
Jean Delvare5f2dc792010-03-05 22:17:18 +0100887 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
888 data->fan_main_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 }
890
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100891 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 return count;
893}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200894static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
895 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200897 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
898 int nr = sensor_attr->index;
899
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200900 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100901 long val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100903 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 return -EINVAL;
905
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100906 mutex_lock(&data->update_lock);
Jean Delvare16b5dda2012-01-16 22:51:48 +0100907 if (has_newer_autopwm(data)) {
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800908 /*
909 * If we are in automatic mode, the PWM duty cycle register
910 * is read-only so we can't write the value.
911 */
Jean Delvare6229cdb2010-12-08 16:27:22 +0100912 if (data->pwm_ctrl[nr] & 0x80) {
913 mutex_unlock(&data->update_lock);
914 return -EBUSY;
915 }
916 data->pwm_duty[nr] = pwm_to_reg(data, val);
917 it87_write_value(data, IT87_REG_PWM_DUTY(nr),
918 data->pwm_duty[nr]);
919 } else {
920 data->pwm_duty[nr] = pwm_to_reg(data, val);
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800921 /*
922 * If we are in manual mode, write the duty cycle immediately;
923 * otherwise, just store it for later use.
924 */
Jean Delvare6229cdb2010-12-08 16:27:22 +0100925 if (!(data->pwm_ctrl[nr] & 0x80)) {
926 data->pwm_ctrl[nr] = data->pwm_duty[nr];
927 it87_write_value(data, IT87_REG_PWM(nr),
928 data->pwm_ctrl[nr]);
929 }
Jean Delvareb99883d2010-03-05 22:17:15 +0100930 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100931 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 return count;
933}
Jean Delvaref8d0c192007-02-14 21:15:02 +0100934static ssize_t set_pwm_freq(struct device *dev,
935 struct device_attribute *attr, const char *buf, size_t count)
936{
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200937 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100938 unsigned long val;
Jean Delvaref8d0c192007-02-14 21:15:02 +0100939 int i;
940
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100941 if (kstrtoul(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +0100942 return -EINVAL;
943
Jean Delvaref8d0c192007-02-14 21:15:02 +0100944 /* Search for the nearest available frequency */
945 for (i = 0; i < 7; i++) {
946 if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
947 break;
948 }
949
950 mutex_lock(&data->update_lock);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200951 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
Jean Delvaref8d0c192007-02-14 21:15:02 +0100952 data->fan_ctl |= i << 4;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200953 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
Jean Delvaref8d0c192007-02-14 21:15:02 +0100954 mutex_unlock(&data->update_lock);
955
956 return count;
957}
Jean Delvare94ac7ee2010-03-05 22:17:16 +0100958static ssize_t show_pwm_temp_map(struct device *dev,
959 struct device_attribute *attr, char *buf)
960{
961 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
962 int nr = sensor_attr->index;
963
964 struct it87_data *data = it87_update_device(dev);
965 int map;
966
967 if (data->pwm_temp_map[nr] < 3)
968 map = 1 << data->pwm_temp_map[nr];
969 else
970 map = 0; /* Should never happen */
971 return sprintf(buf, "%d\n", map);
972}
973static ssize_t set_pwm_temp_map(struct device *dev,
974 struct device_attribute *attr, const char *buf, size_t count)
975{
976 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
977 int nr = sensor_attr->index;
978
979 struct it87_data *data = dev_get_drvdata(dev);
980 long val;
981 u8 reg;
982
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800983 /*
984 * This check can go away if we ever support automatic fan speed
985 * control on newer chips.
986 */
Jean Delvare4f3f51b2010-03-05 22:17:21 +0100987 if (!has_old_autopwm(data)) {
988 dev_notice(dev, "Mapping change disabled for safety reasons\n");
989 return -EINVAL;
990 }
991
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100992 if (kstrtol(buf, 10, &val) < 0)
Jean Delvare94ac7ee2010-03-05 22:17:16 +0100993 return -EINVAL;
994
995 switch (val) {
996 case (1 << 0):
997 reg = 0x00;
998 break;
999 case (1 << 1):
1000 reg = 0x01;
1001 break;
1002 case (1 << 2):
1003 reg = 0x02;
1004 break;
1005 default:
1006 return -EINVAL;
1007 }
1008
1009 mutex_lock(&data->update_lock);
1010 data->pwm_temp_map[nr] = reg;
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08001011 /*
1012 * If we are in automatic mode, write the temp mapping immediately;
1013 * otherwise, just store it for later use.
1014 */
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001015 if (data->pwm_ctrl[nr] & 0x80) {
1016 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
1017 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
1018 }
1019 mutex_unlock(&data->update_lock);
1020 return count;
1021}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001023static ssize_t show_auto_pwm(struct device *dev,
1024 struct device_attribute *attr, char *buf)
1025{
1026 struct it87_data *data = it87_update_device(dev);
1027 struct sensor_device_attribute_2 *sensor_attr =
1028 to_sensor_dev_attr_2(attr);
1029 int nr = sensor_attr->nr;
1030 int point = sensor_attr->index;
1031
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001032 return sprintf(buf, "%d\n",
1033 pwm_from_reg(data, data->auto_pwm[nr][point]));
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001034}
1035
1036static ssize_t set_auto_pwm(struct device *dev,
1037 struct device_attribute *attr, const char *buf, size_t count)
1038{
1039 struct it87_data *data = dev_get_drvdata(dev);
1040 struct sensor_device_attribute_2 *sensor_attr =
1041 to_sensor_dev_attr_2(attr);
1042 int nr = sensor_attr->nr;
1043 int point = sensor_attr->index;
1044 long val;
1045
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001046 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001047 return -EINVAL;
1048
1049 mutex_lock(&data->update_lock);
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001050 data->auto_pwm[nr][point] = pwm_to_reg(data, val);
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001051 it87_write_value(data, IT87_REG_AUTO_PWM(nr, point),
1052 data->auto_pwm[nr][point]);
1053 mutex_unlock(&data->update_lock);
1054 return count;
1055}
1056
1057static ssize_t show_auto_temp(struct device *dev,
1058 struct device_attribute *attr, char *buf)
1059{
1060 struct it87_data *data = it87_update_device(dev);
1061 struct sensor_device_attribute_2 *sensor_attr =
1062 to_sensor_dev_attr_2(attr);
1063 int nr = sensor_attr->nr;
1064 int point = sensor_attr->index;
1065
1066 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->auto_temp[nr][point]));
1067}
1068
1069static ssize_t set_auto_temp(struct device *dev,
1070 struct device_attribute *attr, const char *buf, size_t count)
1071{
1072 struct it87_data *data = dev_get_drvdata(dev);
1073 struct sensor_device_attribute_2 *sensor_attr =
1074 to_sensor_dev_attr_2(attr);
1075 int nr = sensor_attr->nr;
1076 int point = sensor_attr->index;
1077 long val;
1078
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001079 if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001080 return -EINVAL;
1081
1082 mutex_lock(&data->update_lock);
1083 data->auto_temp[nr][point] = TEMP_TO_REG(val);
1084 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point),
1085 data->auto_temp[nr][point]);
1086 mutex_unlock(&data->update_lock);
1087 return count;
1088}
1089
Jean Delvare20ad93d2005-06-05 11:53:25 +02001090#define show_fan_offset(offset) \
1091static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
1092 show_fan, NULL, offset - 1); \
1093static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
1094 show_fan_min, set_fan_min, offset - 1); \
1095static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \
1096 show_fan_div, set_fan_div, offset - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097
1098show_fan_offset(1);
1099show_fan_offset(2);
1100show_fan_offset(3);
1101
1102#define show_pwm_offset(offset) \
Jean Delvare20ad93d2005-06-05 11:53:25 +02001103static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \
1104 show_pwm_enable, set_pwm_enable, offset - 1); \
1105static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \
Jean Delvaref8d0c192007-02-14 21:15:02 +01001106 show_pwm, set_pwm, offset - 1); \
1107static DEVICE_ATTR(pwm##offset##_freq, \
1108 (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001109 show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL)); \
1110static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels_temp, \
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001111 S_IRUGO | S_IWUSR, show_pwm_temp_map, set_pwm_temp_map, \
1112 offset - 1); \
1113static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_pwm, \
1114 S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
1115 offset - 1, 0); \
1116static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_pwm, \
1117 S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
1118 offset - 1, 1); \
1119static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_pwm, \
1120 S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \
1121 offset - 1, 2); \
1122static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_pwm, \
1123 S_IRUGO, show_auto_pwm, NULL, offset - 1, 3); \
1124static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp, \
1125 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1126 offset - 1, 1); \
1127static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp_hyst, \
1128 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1129 offset - 1, 0); \
1130static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_temp, \
1131 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1132 offset - 1, 2); \
1133static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_temp, \
1134 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1135 offset - 1, 3); \
1136static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_temp, \
1137 S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \
1138 offset - 1, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
1140show_pwm_offset(1);
1141show_pwm_offset(2);
1142show_pwm_offset(3);
1143
Jean Delvare17d648b2006-08-28 14:23:46 +02001144/* A different set of callbacks for 16-bit fans */
1145static ssize_t show_fan16(struct device *dev, struct device_attribute *attr,
1146 char *buf)
1147{
1148 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1149 int nr = sensor_attr->index;
1150 struct it87_data *data = it87_update_device(dev);
1151 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan[nr]));
1152}
1153
1154static ssize_t show_fan16_min(struct device *dev, struct device_attribute *attr,
1155 char *buf)
1156{
1157 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1158 int nr = sensor_attr->index;
1159 struct it87_data *data = it87_update_device(dev);
1160 return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan_min[nr]));
1161}
1162
1163static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr,
1164 const char *buf, size_t count)
1165{
1166 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1167 int nr = sensor_attr->index;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001168 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +01001169 long val;
1170
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001171 if (kstrtol(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +01001172 return -EINVAL;
Jean Delvare17d648b2006-08-28 14:23:46 +02001173
1174 mutex_lock(&data->update_lock);
1175 data->fan_min[nr] = FAN16_TO_REG(val);
Jean Delvarec7f1f712007-09-03 17:11:46 +02001176 it87_write_value(data, IT87_REG_FAN_MIN[nr],
Jean Delvare17d648b2006-08-28 14:23:46 +02001177 data->fan_min[nr] & 0xff);
Jean Delvarec7f1f712007-09-03 17:11:46 +02001178 it87_write_value(data, IT87_REG_FANX_MIN[nr],
Jean Delvare17d648b2006-08-28 14:23:46 +02001179 data->fan_min[nr] >> 8);
1180 mutex_unlock(&data->update_lock);
1181 return count;
1182}
1183
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08001184/*
1185 * We want to use the same sysfs file names as 8-bit fans, but we need
1186 * different variable names, so we have to use SENSOR_ATTR instead of
1187 * SENSOR_DEVICE_ATTR.
1188 */
Jean Delvare17d648b2006-08-28 14:23:46 +02001189#define show_fan16_offset(offset) \
1190static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \
1191 = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \
1192 show_fan16, NULL, offset - 1); \
1193static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \
1194 = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \
1195 show_fan16_min, set_fan16_min, offset - 1)
1196
1197show_fan16_offset(1);
1198show_fan16_offset(2);
1199show_fan16_offset(3);
Jean Delvarec7f1f712007-09-03 17:11:46 +02001200show_fan16_offset(4);
1201show_fan16_offset(5);
Jean Delvare17d648b2006-08-28 14:23:46 +02001202
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203/* Alarms */
Jean Delvare5f2dc792010-03-05 22:17:18 +01001204static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
1205 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206{
1207 struct it87_data *data = it87_update_device(dev);
Jean Delvare68188ba2005-05-16 18:52:38 +02001208 return sprintf(buf, "%u\n", data->alarms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209}
Jean Delvare1d66c642005-04-18 21:16:59 -07001210static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211
Jean Delvare0124dd72007-11-25 16:16:41 +01001212static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
1213 char *buf)
1214{
1215 int bitnr = to_sensor_dev_attr(attr)->index;
1216 struct it87_data *data = it87_update_device(dev);
1217 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
1218}
Jean Delvare3d30f9e2011-07-25 21:46:10 +02001219
1220static ssize_t clear_intrusion(struct device *dev, struct device_attribute
1221 *attr, const char *buf, size_t count)
1222{
1223 struct it87_data *data = dev_get_drvdata(dev);
1224 long val;
1225 int config;
1226
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001227 if (kstrtol(buf, 10, &val) < 0 || val != 0)
Jean Delvare3d30f9e2011-07-25 21:46:10 +02001228 return -EINVAL;
1229
1230 mutex_lock(&data->update_lock);
1231 config = it87_read_value(data, IT87_REG_CONFIG);
1232 if (config < 0) {
1233 count = config;
1234 } else {
1235 config |= 1 << 5;
1236 it87_write_value(data, IT87_REG_CONFIG, config);
1237 /* Invalidate cache to force re-read */
1238 data->valid = 0;
1239 }
1240 mutex_unlock(&data->update_lock);
1241
1242 return count;
1243}
1244
Jean Delvare0124dd72007-11-25 16:16:41 +01001245static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
1246static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
1247static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
1248static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
1249static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
1250static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
1251static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
1252static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
1253static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
1254static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
1255static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
1256static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
1257static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
1258static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
1259static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
1260static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
Jean Delvare3d30f9e2011-07-25 21:46:10 +02001261static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR,
1262 show_alarm, clear_intrusion, 4);
Jean Delvare0124dd72007-11-25 16:16:41 +01001263
Jean Delvared9b327c2010-03-05 22:17:17 +01001264static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
1265 char *buf)
1266{
1267 int bitnr = to_sensor_dev_attr(attr)->index;
1268 struct it87_data *data = it87_update_device(dev);
1269 return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1);
1270}
1271static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
1272 const char *buf, size_t count)
1273{
1274 int bitnr = to_sensor_dev_attr(attr)->index;
1275 struct it87_data *data = dev_get_drvdata(dev);
1276 long val;
1277
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001278 if (kstrtol(buf, 10, &val) < 0
Jean Delvared9b327c2010-03-05 22:17:17 +01001279 || (val != 0 && val != 1))
1280 return -EINVAL;
1281
1282 mutex_lock(&data->update_lock);
1283 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
1284 if (val)
1285 data->beeps |= (1 << bitnr);
1286 else
1287 data->beeps &= ~(1 << bitnr);
1288 it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps);
1289 mutex_unlock(&data->update_lock);
1290 return count;
1291}
1292
1293static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
1294 show_beep, set_beep, 1);
1295static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1);
1296static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1);
1297static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1);
1298static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1);
1299static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1);
1300static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1);
1301static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1);
1302/* fanX_beep writability is set later */
1303static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0);
1304static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0);
1305static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0);
1306static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0);
1307static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0);
1308static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
1309 show_beep, set_beep, 2);
1310static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
1311static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2);
1312
Jean Delvare5f2dc792010-03-05 22:17:18 +01001313static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
1314 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315{
Jean Delvare90d66192007-10-08 18:24:35 +02001316 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvarea7be58a2005-12-18 16:40:14 +01001317 return sprintf(buf, "%u\n", data->vrm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318}
Jean Delvare5f2dc792010-03-05 22:17:18 +01001319static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
1320 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001322 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +01001323 unsigned long val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001325 if (kstrtoul(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +01001326 return -EINVAL;
1327
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 data->vrm = val;
1329
1330 return count;
1331}
1332static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
Jean Delvare5f2dc792010-03-05 22:17:18 +01001334static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
1335 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336{
1337 struct it87_data *data = it87_update_device(dev);
1338 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
1339}
1340static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
Jean Delvare87808be2006-09-24 21:17:13 +02001341
Jean Delvare738e5e02010-08-14 21:08:50 +02001342static ssize_t show_label(struct device *dev, struct device_attribute *attr,
1343 char *buf)
1344{
Guenter Roeck3c4c4972012-01-20 09:29:44 -08001345 static const char * const labels[] = {
Jean Delvare738e5e02010-08-14 21:08:50 +02001346 "+5V",
1347 "5VSB",
1348 "Vbat",
1349 };
Guenter Roeck3c4c4972012-01-20 09:29:44 -08001350 static const char * const labels_it8721[] = {
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001351 "+3.3V",
1352 "3VSB",
1353 "Vbat",
1354 };
1355 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvare738e5e02010-08-14 21:08:50 +02001356 int nr = to_sensor_dev_attr(attr)->index;
1357
Jean Delvare16b5dda2012-01-16 22:51:48 +01001358 return sprintf(buf, "%s\n", has_12mv_adc(data) ? labels_it8721[nr]
1359 : labels[nr]);
Jean Delvare738e5e02010-08-14 21:08:50 +02001360}
1361static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0);
1362static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1);
1363static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2);
1364
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001365static ssize_t show_name(struct device *dev, struct device_attribute
1366 *devattr, char *buf)
1367{
1368 struct it87_data *data = dev_get_drvdata(dev);
1369 return sprintf(buf, "%s\n", data->name);
1370}
1371static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
1372
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001373static struct attribute *it87_attributes_in[9][5] = {
1374{
Jean Delvare87808be2006-09-24 21:17:13 +02001375 &sensor_dev_attr_in0_input.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001376 &sensor_dev_attr_in0_min.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001377 &sensor_dev_attr_in0_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001378 &sensor_dev_attr_in0_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001379 NULL
1380}, {
1381 &sensor_dev_attr_in1_input.dev_attr.attr,
1382 &sensor_dev_attr_in1_min.dev_attr.attr,
1383 &sensor_dev_attr_in1_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001384 &sensor_dev_attr_in1_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001385 NULL
1386}, {
1387 &sensor_dev_attr_in2_input.dev_attr.attr,
1388 &sensor_dev_attr_in2_min.dev_attr.attr,
1389 &sensor_dev_attr_in2_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001390 &sensor_dev_attr_in2_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001391 NULL
1392}, {
1393 &sensor_dev_attr_in3_input.dev_attr.attr,
1394 &sensor_dev_attr_in3_min.dev_attr.attr,
1395 &sensor_dev_attr_in3_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001396 &sensor_dev_attr_in3_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001397 NULL
1398}, {
1399 &sensor_dev_attr_in4_input.dev_attr.attr,
1400 &sensor_dev_attr_in4_min.dev_attr.attr,
1401 &sensor_dev_attr_in4_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001402 &sensor_dev_attr_in4_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001403 NULL
1404}, {
1405 &sensor_dev_attr_in5_input.dev_attr.attr,
1406 &sensor_dev_attr_in5_min.dev_attr.attr,
1407 &sensor_dev_attr_in5_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001408 &sensor_dev_attr_in5_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001409 NULL
1410}, {
1411 &sensor_dev_attr_in6_input.dev_attr.attr,
1412 &sensor_dev_attr_in6_min.dev_attr.attr,
1413 &sensor_dev_attr_in6_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001414 &sensor_dev_attr_in6_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001415 NULL
1416}, {
1417 &sensor_dev_attr_in7_input.dev_attr.attr,
1418 &sensor_dev_attr_in7_min.dev_attr.attr,
1419 &sensor_dev_attr_in7_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001420 &sensor_dev_attr_in7_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001421 NULL
1422}, {
1423 &sensor_dev_attr_in8_input.dev_attr.attr,
1424 NULL
1425} };
Jean Delvare87808be2006-09-24 21:17:13 +02001426
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001427static const struct attribute_group it87_group_in[9] = {
1428 { .attrs = it87_attributes_in[0] },
1429 { .attrs = it87_attributes_in[1] },
1430 { .attrs = it87_attributes_in[2] },
1431 { .attrs = it87_attributes_in[3] },
1432 { .attrs = it87_attributes_in[4] },
1433 { .attrs = it87_attributes_in[5] },
1434 { .attrs = it87_attributes_in[6] },
1435 { .attrs = it87_attributes_in[7] },
1436 { .attrs = it87_attributes_in[8] },
1437};
1438
Guenter Roeck4573acb2012-03-26 16:17:41 -07001439static struct attribute *it87_attributes_temp[3][6] = {
1440{
Jean Delvare87808be2006-09-24 21:17:13 +02001441 &sensor_dev_attr_temp1_input.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001442 &sensor_dev_attr_temp1_max.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001443 &sensor_dev_attr_temp1_min.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001444 &sensor_dev_attr_temp1_type.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001445 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
Guenter Roeck4573acb2012-03-26 16:17:41 -07001446 NULL
1447} , {
1448 &sensor_dev_attr_temp2_input.dev_attr.attr,
1449 &sensor_dev_attr_temp2_max.dev_attr.attr,
1450 &sensor_dev_attr_temp2_min.dev_attr.attr,
1451 &sensor_dev_attr_temp2_type.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001452 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
Guenter Roeck4573acb2012-03-26 16:17:41 -07001453 NULL
1454} , {
1455 &sensor_dev_attr_temp3_input.dev_attr.attr,
1456 &sensor_dev_attr_temp3_max.dev_attr.attr,
1457 &sensor_dev_attr_temp3_min.dev_attr.attr,
1458 &sensor_dev_attr_temp3_type.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001459 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
Guenter Roeck4573acb2012-03-26 16:17:41 -07001460 NULL
1461} };
Jean Delvare87808be2006-09-24 21:17:13 +02001462
Guenter Roeck4573acb2012-03-26 16:17:41 -07001463static const struct attribute_group it87_group_temp[3] = {
1464 { .attrs = it87_attributes_temp[0] },
1465 { .attrs = it87_attributes_temp[1] },
1466 { .attrs = it87_attributes_temp[2] },
1467};
1468
Guenter Roeck161d8982012-12-19 22:17:01 +01001469static struct attribute *it87_attributes_temp_offset[] = {
1470 &sensor_dev_attr_temp1_offset.dev_attr.attr,
1471 &sensor_dev_attr_temp2_offset.dev_attr.attr,
1472 &sensor_dev_attr_temp3_offset.dev_attr.attr,
1473};
1474
Guenter Roeck4573acb2012-03-26 16:17:41 -07001475static struct attribute *it87_attributes[] = {
Jean Delvare87808be2006-09-24 21:17:13 +02001476 &dev_attr_alarms.attr,
Jean Delvare3d30f9e2011-07-25 21:46:10 +02001477 &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001478 &dev_attr_name.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001479 NULL
1480};
1481
1482static const struct attribute_group it87_group = {
1483 .attrs = it87_attributes,
1484};
1485
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001486static struct attribute *it87_attributes_in_beep[] = {
Jean Delvared9b327c2010-03-05 22:17:17 +01001487 &sensor_dev_attr_in0_beep.dev_attr.attr,
1488 &sensor_dev_attr_in1_beep.dev_attr.attr,
1489 &sensor_dev_attr_in2_beep.dev_attr.attr,
1490 &sensor_dev_attr_in3_beep.dev_attr.attr,
1491 &sensor_dev_attr_in4_beep.dev_attr.attr,
1492 &sensor_dev_attr_in5_beep.dev_attr.attr,
1493 &sensor_dev_attr_in6_beep.dev_attr.attr,
1494 &sensor_dev_attr_in7_beep.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001495 NULL
1496};
Jean Delvared9b327c2010-03-05 22:17:17 +01001497
Guenter Roeck4573acb2012-03-26 16:17:41 -07001498static struct attribute *it87_attributes_temp_beep[] = {
Jean Delvared9b327c2010-03-05 22:17:17 +01001499 &sensor_dev_attr_temp1_beep.dev_attr.attr,
1500 &sensor_dev_attr_temp2_beep.dev_attr.attr,
1501 &sensor_dev_attr_temp3_beep.dev_attr.attr,
Jean Delvared9b327c2010-03-05 22:17:17 +01001502};
1503
Jean Delvare723a0aa2010-03-05 22:17:16 +01001504static struct attribute *it87_attributes_fan16[5][3+1] = { {
Jean Delvare87808be2006-09-24 21:17:13 +02001505 &sensor_dev_attr_fan1_input16.dev_attr.attr,
1506 &sensor_dev_attr_fan1_min16.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001507 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1508 NULL
1509}, {
Jean Delvare87808be2006-09-24 21:17:13 +02001510 &sensor_dev_attr_fan2_input16.dev_attr.attr,
1511 &sensor_dev_attr_fan2_min16.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001512 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1513 NULL
1514}, {
Jean Delvare87808be2006-09-24 21:17:13 +02001515 &sensor_dev_attr_fan3_input16.dev_attr.attr,
1516 &sensor_dev_attr_fan3_min16.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001517 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
1518 NULL
1519}, {
Jean Delvarec7f1f712007-09-03 17:11:46 +02001520 &sensor_dev_attr_fan4_input16.dev_attr.attr,
1521 &sensor_dev_attr_fan4_min16.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001522 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1523 NULL
1524}, {
Jean Delvarec7f1f712007-09-03 17:11:46 +02001525 &sensor_dev_attr_fan5_input16.dev_attr.attr,
1526 &sensor_dev_attr_fan5_min16.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001527 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
1528 NULL
1529} };
Jean Delvare87808be2006-09-24 21:17:13 +02001530
Jean Delvare723a0aa2010-03-05 22:17:16 +01001531static const struct attribute_group it87_group_fan16[5] = {
1532 { .attrs = it87_attributes_fan16[0] },
1533 { .attrs = it87_attributes_fan16[1] },
1534 { .attrs = it87_attributes_fan16[2] },
1535 { .attrs = it87_attributes_fan16[3] },
1536 { .attrs = it87_attributes_fan16[4] },
1537};
1538
1539static struct attribute *it87_attributes_fan[3][4+1] = { {
Jean Delvare87808be2006-09-24 21:17:13 +02001540 &sensor_dev_attr_fan1_input.dev_attr.attr,
1541 &sensor_dev_attr_fan1_min.dev_attr.attr,
1542 &sensor_dev_attr_fan1_div.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001543 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1544 NULL
1545}, {
Jean Delvare87808be2006-09-24 21:17:13 +02001546 &sensor_dev_attr_fan2_input.dev_attr.attr,
1547 &sensor_dev_attr_fan2_min.dev_attr.attr,
1548 &sensor_dev_attr_fan2_div.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001549 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1550 NULL
1551}, {
Jean Delvare87808be2006-09-24 21:17:13 +02001552 &sensor_dev_attr_fan3_input.dev_attr.attr,
1553 &sensor_dev_attr_fan3_min.dev_attr.attr,
1554 &sensor_dev_attr_fan3_div.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001555 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001556 NULL
1557} };
Jean Delvare0124dd72007-11-25 16:16:41 +01001558
Jean Delvare723a0aa2010-03-05 22:17:16 +01001559static const struct attribute_group it87_group_fan[3] = {
1560 { .attrs = it87_attributes_fan[0] },
1561 { .attrs = it87_attributes_fan[1] },
1562 { .attrs = it87_attributes_fan[2] },
1563};
1564
1565static const struct attribute_group *
1566it87_get_fan_group(const struct it87_data *data)
1567{
1568 return has_16bit_fans(data) ? it87_group_fan16 : it87_group_fan;
1569}
1570
1571static struct attribute *it87_attributes_pwm[3][4+1] = { {
Jean Delvare87808be2006-09-24 21:17:13 +02001572 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001573 &sensor_dev_attr_pwm1.dev_attr.attr,
Jean Delvared5b0b5d2007-12-14 14:41:53 +01001574 &dev_attr_pwm1_freq.attr,
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001575 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001576 NULL
1577}, {
1578 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1579 &sensor_dev_attr_pwm2.dev_attr.attr,
1580 &dev_attr_pwm2_freq.attr,
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001581 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001582 NULL
1583}, {
1584 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1585 &sensor_dev_attr_pwm3.dev_attr.attr,
1586 &dev_attr_pwm3_freq.attr,
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001587 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001588 NULL
1589} };
Jean Delvare87808be2006-09-24 21:17:13 +02001590
Jean Delvare723a0aa2010-03-05 22:17:16 +01001591static const struct attribute_group it87_group_pwm[3] = {
1592 { .attrs = it87_attributes_pwm[0] },
1593 { .attrs = it87_attributes_pwm[1] },
1594 { .attrs = it87_attributes_pwm[2] },
1595};
1596
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001597static struct attribute *it87_attributes_autopwm[3][9+1] = { {
1598 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1599 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
1600 &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
1601 &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
1602 &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
1603 &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
1604 &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
1605 &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
1606 &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
1607 NULL
1608}, {
1609 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1610 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
1611 &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr,
1612 &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr,
1613 &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
1614 &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr,
1615 &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
1616 &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr,
1617 &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr,
1618 NULL
1619}, {
1620 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1621 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
1622 &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr,
1623 &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr,
1624 &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
1625 &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr,
1626 &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
1627 &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr,
1628 &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr,
1629 NULL
1630} };
1631
1632static const struct attribute_group it87_group_autopwm[3] = {
1633 { .attrs = it87_attributes_autopwm[0] },
1634 { .attrs = it87_attributes_autopwm[1] },
1635 { .attrs = it87_attributes_autopwm[2] },
1636};
1637
Jean Delvared9b327c2010-03-05 22:17:17 +01001638static struct attribute *it87_attributes_fan_beep[] = {
1639 &sensor_dev_attr_fan1_beep.dev_attr.attr,
1640 &sensor_dev_attr_fan2_beep.dev_attr.attr,
1641 &sensor_dev_attr_fan3_beep.dev_attr.attr,
1642 &sensor_dev_attr_fan4_beep.dev_attr.attr,
1643 &sensor_dev_attr_fan5_beep.dev_attr.attr,
1644};
1645
Jean Delvare6a8d7ac2010-03-05 22:17:16 +01001646static struct attribute *it87_attributes_vid[] = {
Jean Delvare87808be2006-09-24 21:17:13 +02001647 &dev_attr_vrm.attr,
1648 &dev_attr_cpu0_vid.attr,
1649 NULL
1650};
1651
Jean Delvare6a8d7ac2010-03-05 22:17:16 +01001652static const struct attribute_group it87_group_vid = {
1653 .attrs = it87_attributes_vid,
Jean Delvare87808be2006-09-24 21:17:13 +02001654};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655
Jean Delvare738e5e02010-08-14 21:08:50 +02001656static struct attribute *it87_attributes_label[] = {
1657 &sensor_dev_attr_in3_label.dev_attr.attr,
1658 &sensor_dev_attr_in7_label.dev_attr.attr,
1659 &sensor_dev_attr_in8_label.dev_attr.attr,
1660 NULL
1661};
1662
1663static const struct attribute_group it87_group_label = {
Jean Delvarefa8b6972011-07-17 18:39:19 +02001664 .attrs = it87_attributes_label,
Jean Delvare738e5e02010-08-14 21:08:50 +02001665};
1666
Jean Delvare2d8672c2005-07-19 23:56:35 +02001667/* SuperIO detection - will change isa_address if a chip is found */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001668static int __init it87_find(unsigned short *address,
1669 struct it87_sio_data *sio_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670{
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +02001671 int err;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001672 u16 chip_type;
Jean Delvare98dd22c2008-10-09 15:33:58 +02001673 const char *board_vendor, *board_name;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +02001675 err = superio_enter();
1676 if (err)
1677 return err;
1678
1679 err = -ENODEV;
Jean Delvare67b671b2007-12-06 23:13:42 +01001680 chip_type = force_id ? force_id : superio_inw(DEVID);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001681
1682 switch (chip_type) {
1683 case IT8705F_DEVID:
1684 sio_data->type = it87;
1685 break;
1686 case IT8712F_DEVID:
1687 sio_data->type = it8712;
1688 break;
1689 case IT8716F_DEVID:
1690 case IT8726F_DEVID:
1691 sio_data->type = it8716;
1692 break;
1693 case IT8718F_DEVID:
1694 sio_data->type = it8718;
1695 break;
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +01001696 case IT8720F_DEVID:
1697 sio_data->type = it8720;
1698 break;
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001699 case IT8721F_DEVID:
1700 sio_data->type = it8721;
1701 break;
Jean Delvare16b5dda2012-01-16 22:51:48 +01001702 case IT8728F_DEVID:
1703 sio_data->type = it8728;
1704 break;
Guenter Roeck0531d982012-03-02 11:46:44 -08001705 case IT8782F_DEVID:
1706 sio_data->type = it8782;
1707 break;
1708 case IT8783E_DEVID:
1709 sio_data->type = it8783;
1710 break;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001711 case 0xffff: /* No device at all */
1712 goto exit;
1713 default:
Joe Perchesa8ca1032011-01-12 21:55:10 +01001714 pr_debug("Unsupported chip (DEVID=0x%x)\n", chip_type);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001715 goto exit;
1716 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717
Jean Delvare87673dd2006-08-28 14:37:19 +02001718 superio_select(PME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
Joe Perchesa8ca1032011-01-12 21:55:10 +01001720 pr_info("Device not activated, skipping\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 goto exit;
1722 }
1723
1724 *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
1725 if (*address == 0) {
Joe Perchesa8ca1032011-01-12 21:55:10 +01001726 pr_info("Base address not set, skipping\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727 goto exit;
1728 }
1729
1730 err = 0;
Andrew Paprocki04751692008-08-06 22:41:06 +02001731 sio_data->revision = superio_inb(DEVREV) & 0x0f;
Joe Perchesa8ca1032011-01-12 21:55:10 +01001732 pr_info("Found IT%04xF chip at 0x%x, revision %d\n",
Andrew Paprocki04751692008-08-06 22:41:06 +02001733 chip_type, *address, sio_data->revision);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
Jean Delvare738e5e02010-08-14 21:08:50 +02001735 /* in8 (Vbat) is always internal */
1736 sio_data->internal = (1 << 2);
1737
Jean Delvare87673dd2006-08-28 14:37:19 +02001738 /* Read GPIO config and VID value from LDN 7 (GPIO) */
Jean Delvare895ff262009-12-09 20:35:47 +01001739 if (sio_data->type == it87) {
1740 /* The IT8705F doesn't have VID pins at all */
1741 sio_data->skip_vid = 1;
Jean Delvared9b327c2010-03-05 22:17:17 +01001742
1743 /* The IT8705F has a different LD number for GPIO */
1744 superio_select(5);
1745 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
Guenter Roeck0531d982012-03-02 11:46:44 -08001746 } else if (sio_data->type == it8783) {
1747 int reg25, reg27, reg2A, reg2C, regEF;
Guenter Roeck0531d982012-03-02 11:46:44 -08001748
1749 sio_data->skip_vid = 1; /* No VID */
1750
1751 superio_select(GPIO);
1752
1753 reg25 = superio_inb(IT87_SIO_GPIO1_REG);
1754 reg27 = superio_inb(IT87_SIO_GPIO3_REG);
1755 reg2A = superio_inb(IT87_SIO_PINX1_REG);
1756 reg2C = superio_inb(IT87_SIO_PINX2_REG);
1757 regEF = superio_inb(IT87_SIO_SPI_REG);
1758
Guenter Roeck0531d982012-03-02 11:46:44 -08001759 /* Check if fan3 is there or not */
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001760 if ((reg27 & (1 << 0)) || !(reg2C & (1 << 2)))
Guenter Roeck0531d982012-03-02 11:46:44 -08001761 sio_data->skip_fan |= (1 << 2);
1762 if ((reg25 & (1 << 4))
1763 || (!(reg2A & (1 << 1)) && (regEF & (1 << 0))))
1764 sio_data->skip_pwm |= (1 << 2);
1765
1766 /* Check if fan2 is there or not */
1767 if (reg27 & (1 << 7))
1768 sio_data->skip_fan |= (1 << 1);
1769 if (reg27 & (1 << 3))
1770 sio_data->skip_pwm |= (1 << 1);
1771
1772 /* VIN5 */
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001773 if ((reg27 & (1 << 0)) || (reg2C & (1 << 2)))
1774 sio_data->skip_in |= (1 << 5); /* No VIN5 */
Guenter Roeck0531d982012-03-02 11:46:44 -08001775
1776 /* VIN6 */
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001777 if (reg27 & (1 << 1))
1778 sio_data->skip_in |= (1 << 6); /* No VIN6 */
Guenter Roeck0531d982012-03-02 11:46:44 -08001779
1780 /*
1781 * VIN7
1782 * Does not depend on bit 2 of Reg2C, contrary to datasheet.
1783 */
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001784 if (reg27 & (1 << 2)) {
1785 /*
1786 * The data sheet is a bit unclear regarding the
1787 * internal voltage divider for VCCH5V. It says
1788 * "This bit enables and switches VIN7 (pin 91) to the
1789 * internal voltage divider for VCCH5V".
1790 * This is different to other chips, where the internal
1791 * voltage divider would connect VIN7 to an internal
1792 * voltage source. Maybe that is the case here as well.
1793 *
1794 * Since we don't know for sure, re-route it if that is
1795 * not the case, and ask the user to report if the
1796 * resulting voltage is sane.
1797 */
1798 if (!(reg2C & (1 << 1))) {
1799 reg2C |= (1 << 1);
1800 superio_outb(IT87_SIO_PINX2_REG, reg2C);
1801 pr_notice("Routing internal VCCH5V to in7.\n");
1802 }
1803 pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n");
1804 pr_notice("Please report if it displays a reasonable voltage.\n");
1805 }
Guenter Roeck0531d982012-03-02 11:46:44 -08001806
1807 if (reg2C & (1 << 0))
1808 sio_data->internal |= (1 << 0);
1809 if (reg2C & (1 << 1))
1810 sio_data->internal |= (1 << 1);
1811
1812 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
1813
Jean Delvare895ff262009-12-09 20:35:47 +01001814 } else {
Jean Delvare87673dd2006-08-28 14:37:19 +02001815 int reg;
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001816 bool uart6;
Jean Delvare87673dd2006-08-28 14:37:19 +02001817
1818 superio_select(GPIO);
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001819
Jean Delvare895ff262009-12-09 20:35:47 +01001820 reg = superio_inb(IT87_SIO_GPIO3_REG);
Guenter Roeck0531d982012-03-02 11:46:44 -08001821 if (sio_data->type == it8721 || sio_data->type == it8728 ||
1822 sio_data->type == it8782) {
Jean Delvare16b5dda2012-01-16 22:51:48 +01001823 /*
Guenter Roeck0531d982012-03-02 11:46:44 -08001824 * IT8721F/IT8758E, and IT8782F don't have VID pins
1825 * at all, not sure about the IT8728F.
Jean Delvare16b5dda2012-01-16 22:51:48 +01001826 */
Jean Delvare895ff262009-12-09 20:35:47 +01001827 sio_data->skip_vid = 1;
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001828 } else {
1829 /* We need at least 4 VID pins */
1830 if (reg & 0x0f) {
Joe Perchesa8ca1032011-01-12 21:55:10 +01001831 pr_info("VID is disabled (pins used for GPIO)\n");
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001832 sio_data->skip_vid = 1;
1833 }
Jean Delvare895ff262009-12-09 20:35:47 +01001834 }
1835
Jean Delvare591ec652009-12-09 20:35:48 +01001836 /* Check if fan3 is there or not */
1837 if (reg & (1 << 6))
1838 sio_data->skip_pwm |= (1 << 2);
1839 if (reg & (1 << 7))
1840 sio_data->skip_fan |= (1 << 2);
1841
1842 /* Check if fan2 is there or not */
1843 reg = superio_inb(IT87_SIO_GPIO5_REG);
1844 if (reg & (1 << 1))
1845 sio_data->skip_pwm |= (1 << 1);
1846 if (reg & (1 << 2))
1847 sio_data->skip_fan |= (1 << 1);
1848
Jean Delvare895ff262009-12-09 20:35:47 +01001849 if ((sio_data->type == it8718 || sio_data->type == it8720)
1850 && !(sio_data->skip_vid))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001851 sio_data->vid_value = superio_inb(IT87_SIO_VID_REG);
Jean Delvare87673dd2006-08-28 14:37:19 +02001852
1853 reg = superio_inb(IT87_SIO_PINX2_REG);
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001854
1855 uart6 = sio_data->type == it8782 && (reg & (1 << 2));
1856
Jean Delvare436cad22010-07-09 16:22:48 +02001857 /*
1858 * The IT8720F has no VIN7 pin, so VCCH should always be
1859 * routed internally to VIN7 with an internal divider.
1860 * Curiously, there still is a configuration bit to control
1861 * this, which means it can be set incorrectly. And even
1862 * more curiously, many boards out there are improperly
1863 * configured, even though the IT8720F datasheet claims
1864 * that the internal routing of VCCH to VIN7 is the default
1865 * setting. So we force the internal routing in this case.
Guenter Roeck0531d982012-03-02 11:46:44 -08001866 *
1867 * On IT8782F, VIN7 is multiplexed with one of the UART6 pins.
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001868 * If UART6 is enabled, re-route VIN7 to the internal divider
1869 * if that is not already the case.
Jean Delvare436cad22010-07-09 16:22:48 +02001870 */
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001871 if ((sio_data->type == it8720 || uart6) && !(reg & (1 << 1))) {
Jean Delvare436cad22010-07-09 16:22:48 +02001872 reg |= (1 << 1);
1873 superio_outb(IT87_SIO_PINX2_REG, reg);
Joe Perchesa8ca1032011-01-12 21:55:10 +01001874 pr_notice("Routing internal VCCH to in7\n");
Jean Delvare436cad22010-07-09 16:22:48 +02001875 }
Jean Delvare87673dd2006-08-28 14:37:19 +02001876 if (reg & (1 << 0))
Jean Delvare738e5e02010-08-14 21:08:50 +02001877 sio_data->internal |= (1 << 0);
Jean Delvare16b5dda2012-01-16 22:51:48 +01001878 if ((reg & (1 << 1)) || sio_data->type == it8721 ||
1879 sio_data->type == it8728)
Jean Delvare738e5e02010-08-14 21:08:50 +02001880 sio_data->internal |= (1 << 1);
Jean Delvared9b327c2010-03-05 22:17:17 +01001881
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001882 /*
1883 * On IT8782F, UART6 pins overlap with VIN5, VIN6, and VIN7.
1884 * While VIN7 can be routed to the internal voltage divider,
1885 * VIN5 and VIN6 are not available if UART6 is enabled.
Guenter Roeck4573acb2012-03-26 16:17:41 -07001886 *
1887 * Also, temp3 is not available if UART6 is enabled and TEMPIN3
1888 * is the temperature source. Since we can not read the
1889 * temperature source here, skip_temp is preliminary.
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001890 */
Guenter Roeck4573acb2012-03-26 16:17:41 -07001891 if (uart6) {
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001892 sio_data->skip_in |= (1 << 5) | (1 << 6);
Guenter Roeck4573acb2012-03-26 16:17:41 -07001893 sio_data->skip_temp |= (1 << 2);
1894 }
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001895
Jean Delvared9b327c2010-03-05 22:17:17 +01001896 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
Jean Delvare87673dd2006-08-28 14:37:19 +02001897 }
Jean Delvared9b327c2010-03-05 22:17:17 +01001898 if (sio_data->beep_pin)
Joe Perchesa8ca1032011-01-12 21:55:10 +01001899 pr_info("Beeping is supported\n");
Jean Delvare87673dd2006-08-28 14:37:19 +02001900
Jean Delvare98dd22c2008-10-09 15:33:58 +02001901 /* Disable specific features based on DMI strings */
1902 board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
1903 board_name = dmi_get_system_info(DMI_BOARD_NAME);
1904 if (board_vendor && board_name) {
1905 if (strcmp(board_vendor, "nVIDIA") == 0
1906 && strcmp(board_name, "FN68PT") == 0) {
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08001907 /*
1908 * On the Shuttle SN68PT, FAN_CTL2 is apparently not
1909 * connected to a fan, but to something else. One user
1910 * has reported instant system power-off when changing
1911 * the PWM2 duty cycle, so we disable it.
1912 * I use the board name string as the trigger in case
1913 * the same board is ever used in other systems.
1914 */
Joe Perchesa8ca1032011-01-12 21:55:10 +01001915 pr_info("Disabling pwm2 due to hardware constraints\n");
Jean Delvare98dd22c2008-10-09 15:33:58 +02001916 sio_data->skip_pwm = (1 << 1);
1917 }
1918 }
1919
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920exit:
1921 superio_exit();
1922 return err;
1923}
1924
Jean Delvare723a0aa2010-03-05 22:17:16 +01001925static void it87_remove_files(struct device *dev)
1926{
1927 struct it87_data *data = platform_get_drvdata(pdev);
1928 struct it87_sio_data *sio_data = dev->platform_data;
1929 const struct attribute_group *fan_group = it87_get_fan_group(data);
1930 int i;
1931
1932 sysfs_remove_group(&dev->kobj, &it87_group);
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001933 for (i = 0; i < 9; i++) {
1934 if (sio_data->skip_in & (1 << i))
1935 continue;
1936 sysfs_remove_group(&dev->kobj, &it87_group_in[i]);
1937 if (it87_attributes_in_beep[i])
1938 sysfs_remove_file(&dev->kobj,
1939 it87_attributes_in_beep[i]);
1940 }
Guenter Roeck4573acb2012-03-26 16:17:41 -07001941 for (i = 0; i < 3; i++) {
1942 if (!(data->has_temp & (1 << i)))
1943 continue;
1944 sysfs_remove_group(&dev->kobj, &it87_group_temp[i]);
Guenter Roeck161d8982012-12-19 22:17:01 +01001945 if (has_temp_offset(data))
1946 sysfs_remove_file(&dev->kobj,
1947 it87_attributes_temp_offset[i]);
Guenter Roeck4573acb2012-03-26 16:17:41 -07001948 if (sio_data->beep_pin)
1949 sysfs_remove_file(&dev->kobj,
1950 it87_attributes_temp_beep[i]);
1951 }
Jean Delvare723a0aa2010-03-05 22:17:16 +01001952 for (i = 0; i < 5; i++) {
1953 if (!(data->has_fan & (1 << i)))
1954 continue;
1955 sysfs_remove_group(&dev->kobj, &fan_group[i]);
Jean Delvared9b327c2010-03-05 22:17:17 +01001956 if (sio_data->beep_pin)
1957 sysfs_remove_file(&dev->kobj,
1958 it87_attributes_fan_beep[i]);
Jean Delvare723a0aa2010-03-05 22:17:16 +01001959 }
1960 for (i = 0; i < 3; i++) {
1961 if (sio_data->skip_pwm & (1 << 0))
1962 continue;
1963 sysfs_remove_group(&dev->kobj, &it87_group_pwm[i]);
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001964 if (has_old_autopwm(data))
1965 sysfs_remove_group(&dev->kobj,
1966 &it87_group_autopwm[i]);
Jean Delvare723a0aa2010-03-05 22:17:16 +01001967 }
Jean Delvare6a8d7ac2010-03-05 22:17:16 +01001968 if (!sio_data->skip_vid)
1969 sysfs_remove_group(&dev->kobj, &it87_group_vid);
Jean Delvare738e5e02010-08-14 21:08:50 +02001970 sysfs_remove_group(&dev->kobj, &it87_group_label);
Jean Delvare723a0aa2010-03-05 22:17:16 +01001971}
1972
Bill Pemberton6c931ae2012-11-19 13:22:35 -05001973static int it87_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 struct it87_data *data;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001976 struct resource *res;
1977 struct device *dev = &pdev->dev;
1978 struct it87_sio_data *sio_data = dev->platform_data;
Jean Delvare723a0aa2010-03-05 22:17:16 +01001979 const struct attribute_group *fan_group;
1980 int err = 0, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 int enable_pwm_interface;
Jean Delvared9b327c2010-03-05 22:17:17 +01001982 int fan_beep_need_rw;
Guenter Roeck3c4c4972012-01-20 09:29:44 -08001983 static const char * const names[] = {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001984 "it87",
1985 "it8712",
1986 "it8716",
1987 "it8718",
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +01001988 "it8720",
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001989 "it8721",
Jean Delvare16b5dda2012-01-16 22:51:48 +01001990 "it8728",
Guenter Roeck0531d982012-03-02 11:46:44 -08001991 "it8782",
1992 "it8783",
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001993 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001995 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
Guenter Roeck62a1d052012-03-24 21:54:41 -07001996 if (!devm_request_region(&pdev->dev, res->start, IT87_EC_EXTENT,
1997 DRVNAME)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001998 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
1999 (unsigned long)res->start,
Bjorn Helgaas87b4b662008-01-22 07:21:03 -05002000 (unsigned long)(res->start + IT87_EC_EXTENT - 1));
Guenter Roeck62a1d052012-03-24 21:54:41 -07002001 return -EBUSY;
Jean Delvare8e9afcb2006-12-12 18:18:28 +01002002 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003
Guenter Roeck62a1d052012-03-24 21:54:41 -07002004 data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL);
2005 if (!data)
2006 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002008 data->addr = res->start;
2009 data->type = sio_data->type;
Andrew Paprocki04751692008-08-06 22:41:06 +02002010 data->revision = sio_data->revision;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002011 data->name = names[sio_data->type];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012
2013 /* Now, we do the remaining detection. */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002014 if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002015 || it87_read_value(data, IT87_REG_CHIPID) != 0x90)
2016 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002018 platform_set_drvdata(pdev, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019
Ingo Molnar9a61bf62006-01-18 23:19:26 +01002020 mutex_init(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 /* Check PWM configuration */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002023 enable_pwm_interface = it87_check_pwm(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024
Jean Delvare44c1bcd2010-10-28 20:31:51 +02002025 /* Starting with IT8721F, we handle scaling of internal voltages */
Jean Delvare16b5dda2012-01-16 22:51:48 +01002026 if (has_12mv_adc(data)) {
Jean Delvare44c1bcd2010-10-28 20:31:51 +02002027 if (sio_data->internal & (1 << 0))
2028 data->in_scaled |= (1 << 3); /* in3 is AVCC */
2029 if (sio_data->internal & (1 << 1))
2030 data->in_scaled |= (1 << 7); /* in7 is VSB */
2031 if (sio_data->internal & (1 << 2))
2032 data->in_scaled |= (1 << 8); /* in8 is Vbat */
Guenter Roeck0531d982012-03-02 11:46:44 -08002033 } else if (sio_data->type == it8782 || sio_data->type == it8783) {
2034 if (sio_data->internal & (1 << 0))
2035 data->in_scaled |= (1 << 3); /* in3 is VCC5V */
2036 if (sio_data->internal & (1 << 1))
2037 data->in_scaled |= (1 << 7); /* in7 is VCCH5V */
Jean Delvare44c1bcd2010-10-28 20:31:51 +02002038 }
2039
Guenter Roeck4573acb2012-03-26 16:17:41 -07002040 data->has_temp = 0x07;
2041 if (sio_data->skip_temp & (1 << 2)) {
2042 if (sio_data->type == it8782
2043 && !(it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x80))
2044 data->has_temp &= ~(1 << 2);
2045 }
2046
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 /* Initialize the IT87 chip */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002048 it87_init_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
2050 /* Register sysfs hooks */
Jean Delvare5f2dc792010-03-05 22:17:18 +01002051 err = sysfs_create_group(&dev->kobj, &it87_group);
2052 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002053 return err;
Jean Delvare17d648b2006-08-28 14:23:46 +02002054
Guenter Roeck9172b5d2012-03-24 21:49:54 -07002055 for (i = 0; i < 9; i++) {
2056 if (sio_data->skip_in & (1 << i))
2057 continue;
2058 err = sysfs_create_group(&dev->kobj, &it87_group_in[i]);
2059 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002060 goto error;
Guenter Roeck9172b5d2012-03-24 21:49:54 -07002061 if (sio_data->beep_pin && it87_attributes_in_beep[i]) {
2062 err = sysfs_create_file(&dev->kobj,
2063 it87_attributes_in_beep[i]);
2064 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002065 goto error;
Guenter Roeck9172b5d2012-03-24 21:49:54 -07002066 }
2067 }
2068
Guenter Roeck4573acb2012-03-26 16:17:41 -07002069 for (i = 0; i < 3; i++) {
2070 if (!(data->has_temp & (1 << i)))
2071 continue;
2072 err = sysfs_create_group(&dev->kobj, &it87_group_temp[i]);
Jean Delvared9b327c2010-03-05 22:17:17 +01002073 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002074 goto error;
Guenter Roeck161d8982012-12-19 22:17:01 +01002075 if (has_temp_offset(data)) {
2076 err = sysfs_create_file(&dev->kobj,
2077 it87_attributes_temp_offset[i]);
2078 if (err)
2079 goto error;
2080 }
Guenter Roeck4573acb2012-03-26 16:17:41 -07002081 if (sio_data->beep_pin) {
2082 err = sysfs_create_file(&dev->kobj,
2083 it87_attributes_temp_beep[i]);
2084 if (err)
2085 goto error;
2086 }
Jean Delvared9b327c2010-03-05 22:17:17 +01002087 }
2088
Jean Delvare9060f8b2006-08-28 14:24:17 +02002089 /* Do not create fan files for disabled fans */
Jean Delvare723a0aa2010-03-05 22:17:16 +01002090 fan_group = it87_get_fan_group(data);
Jean Delvared9b327c2010-03-05 22:17:17 +01002091 fan_beep_need_rw = 1;
Jean Delvare723a0aa2010-03-05 22:17:16 +01002092 for (i = 0; i < 5; i++) {
2093 if (!(data->has_fan & (1 << i)))
2094 continue;
2095 err = sysfs_create_group(&dev->kobj, &fan_group[i]);
2096 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002097 goto error;
Jean Delvared9b327c2010-03-05 22:17:17 +01002098
2099 if (sio_data->beep_pin) {
2100 err = sysfs_create_file(&dev->kobj,
2101 it87_attributes_fan_beep[i]);
2102 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002103 goto error;
Jean Delvared9b327c2010-03-05 22:17:17 +01002104 if (!fan_beep_need_rw)
2105 continue;
2106
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002107 /*
2108 * As we have a single beep enable bit for all fans,
Jean Delvared9b327c2010-03-05 22:17:17 +01002109 * only the first enabled fan has a writable attribute
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002110 * for it.
2111 */
Jean Delvared9b327c2010-03-05 22:17:17 +01002112 if (sysfs_chmod_file(&dev->kobj,
2113 it87_attributes_fan_beep[i],
2114 S_IRUGO | S_IWUSR))
2115 dev_dbg(dev, "chmod +w fan%d_beep failed\n",
2116 i + 1);
2117 fan_beep_need_rw = 0;
2118 }
Jean Delvare17d648b2006-08-28 14:23:46 +02002119 }
2120
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 if (enable_pwm_interface) {
Jean Delvare723a0aa2010-03-05 22:17:16 +01002122 for (i = 0; i < 3; i++) {
2123 if (sio_data->skip_pwm & (1 << i))
2124 continue;
2125 err = sysfs_create_group(&dev->kobj,
2126 &it87_group_pwm[i]);
2127 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002128 goto error;
Jean Delvare4f3f51b2010-03-05 22:17:21 +01002129
2130 if (!has_old_autopwm(data))
2131 continue;
2132 err = sysfs_create_group(&dev->kobj,
2133 &it87_group_autopwm[i]);
2134 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002135 goto error;
Jean Delvare98dd22c2008-10-09 15:33:58 +02002136 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 }
2138
Jean Delvare895ff262009-12-09 20:35:47 +01002139 if (!sio_data->skip_vid) {
Jean Delvare303760b2005-07-31 21:52:01 +02002140 data->vrm = vid_which_vrm();
Jean Delvare87673dd2006-08-28 14:37:19 +02002141 /* VID reading from Super-I/O config space if available */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002142 data->vid = sio_data->vid_value;
Jean Delvare6a8d7ac2010-03-05 22:17:16 +01002143 err = sysfs_create_group(&dev->kobj, &it87_group_vid);
2144 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002145 goto error;
Jean Delvare87808be2006-09-24 21:17:13 +02002146 }
2147
Jean Delvare738e5e02010-08-14 21:08:50 +02002148 /* Export labels for internal sensors */
2149 for (i = 0; i < 3; i++) {
2150 if (!(sio_data->internal & (1 << i)))
2151 continue;
2152 err = sysfs_create_file(&dev->kobj,
2153 it87_attributes_label[i]);
2154 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002155 goto error;
Jean Delvare738e5e02010-08-14 21:08:50 +02002156 }
2157
Tony Jones1beeffe2007-08-20 13:46:20 -07002158 data->hwmon_dev = hwmon_device_register(dev);
2159 if (IS_ERR(data->hwmon_dev)) {
2160 err = PTR_ERR(data->hwmon_dev);
Guenter Roeck62a1d052012-03-24 21:54:41 -07002161 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 }
2163
2164 return 0;
2165
Guenter Roeck62a1d052012-03-24 21:54:41 -07002166error:
Jean Delvare723a0aa2010-03-05 22:17:16 +01002167 it87_remove_files(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 return err;
2169}
2170
Bill Pemberton281dfd02012-11-19 13:25:51 -05002171static int it87_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002173 struct it87_data *data = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174
Tony Jones1beeffe2007-08-20 13:46:20 -07002175 hwmon_device_unregister(data->hwmon_dev);
Jean Delvare723a0aa2010-03-05 22:17:16 +01002176 it87_remove_files(&pdev->dev);
Mark M. Hoffman943b0832005-07-15 21:39:18 -04002177
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 return 0;
2179}
2180
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002181/*
2182 * Must be called with data->update_lock held, except during initialization.
2183 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
2184 * would slow down the IT87 access and should not be necessary.
2185 */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002186static int it87_read_value(struct it87_data *data, u8 reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002188 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
2189 return inb_p(data->addr + IT87_DATA_REG_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190}
2191
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002192/*
2193 * Must be called with data->update_lock held, except during initialization.
2194 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
2195 * would slow down the IT87 access and should not be necessary.
2196 */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002197static void it87_write_value(struct it87_data *data, u8 reg, u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002199 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
2200 outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201}
2202
2203/* Return 1 if and only if the PWM interface is safe to use */
Bill Pemberton6c931ae2012-11-19 13:22:35 -05002204static int it87_check_pwm(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002206 struct it87_data *data = dev_get_drvdata(dev);
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002207 /*
2208 * Some BIOSes fail to correctly configure the IT87 fans. All fans off
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 * and polarity set to active low is sign that this is the case so we
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002210 * disable pwm control to protect the user.
2211 */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002212 int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 if ((tmp & 0x87) == 0) {
2214 if (fix_pwm_polarity) {
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002215 /*
2216 * The user asks us to attempt a chip reconfiguration.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 * This means switching to active high polarity and
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002218 * inverting all fan speed values.
2219 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 int i;
2221 u8 pwm[3];
2222
2223 for (i = 0; i < 3; i++)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002224 pwm[i] = it87_read_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 IT87_REG_PWM(i));
2226
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002227 /*
2228 * If any fan is in automatic pwm mode, the polarity
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 * might be correct, as suspicious as it seems, so we
2230 * better don't change anything (but still disable the
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002231 * PWM interface).
2232 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002234 dev_info(dev, "Reconfiguring PWM to "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 "active high polarity\n");
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002236 it87_write_value(data, IT87_REG_FAN_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 tmp | 0x87);
2238 for (i = 0; i < 3; i++)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002239 it87_write_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 IT87_REG_PWM(i),
2241 0x7f & ~pwm[i]);
2242 return 1;
2243 }
2244
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002245 dev_info(dev, "PWM configuration is "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246 "too broken to be fixed\n");
2247 }
2248
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002249 dev_info(dev, "Detected broken BIOS "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 "defaults, disabling PWM interface\n");
2251 return 0;
2252 } else if (fix_pwm_polarity) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002253 dev_info(dev, "PWM configuration looks "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254 "sane, won't touch\n");
2255 }
2256
2257 return 1;
2258}
2259
2260/* Called when we have found a new IT87. */
Bill Pemberton6c931ae2012-11-19 13:22:35 -05002261static void it87_init_device(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262{
Jean Delvare591ec652009-12-09 20:35:48 +01002263 struct it87_sio_data *sio_data = pdev->dev.platform_data;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002264 struct it87_data *data = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 int tmp, i;
Jean Delvare591ec652009-12-09 20:35:48 +01002266 u8 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002268 /*
2269 * For each PWM channel:
Jean Delvareb99883d2010-03-05 22:17:15 +01002270 * - If it is in automatic mode, setting to manual mode should set
2271 * the fan to full speed by default.
2272 * - If it is in manual mode, we need a mapping to temperature
2273 * channels to use when later setting to automatic mode later.
2274 * Use a 1:1 mapping by default (we are clueless.)
2275 * In both cases, the value can (and should) be changed by the user
Jean Delvare6229cdb2010-12-08 16:27:22 +01002276 * prior to switching to a different mode.
2277 * Note that this is no longer needed for the IT8721F and later, as
2278 * these have separate registers for the temperature mapping and the
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002279 * manual duty cycle.
2280 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 for (i = 0; i < 3; i++) {
Jean Delvareb99883d2010-03-05 22:17:15 +01002282 data->pwm_temp_map[i] = i;
2283 data->pwm_duty[i] = 0x7f; /* Full speed */
Jean Delvare4f3f51b2010-03-05 22:17:21 +01002284 data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002285 }
2286
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002287 /*
2288 * Some chips seem to have default value 0xff for all limit
Jean Delvarec5df9b72006-08-28 14:37:54 +02002289 * registers. For low voltage limits it makes no sense and triggers
2290 * alarms, so change to 0 instead. For high temperature limits, it
2291 * means -1 degree C, which surprisingly doesn't trigger an alarm,
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002292 * but is still confusing, so change to 127 degrees C.
2293 */
Jean Delvarec5df9b72006-08-28 14:37:54 +02002294 for (i = 0; i < 8; i++) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002295 tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
Jean Delvarec5df9b72006-08-28 14:37:54 +02002296 if (tmp == 0xff)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002297 it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
Jean Delvarec5df9b72006-08-28 14:37:54 +02002298 }
2299 for (i = 0; i < 3; i++) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002300 tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i));
Jean Delvarec5df9b72006-08-28 14:37:54 +02002301 if (tmp == 0xff)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002302 it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127);
Jean Delvarec5df9b72006-08-28 14:37:54 +02002303 }
2304
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002305 /*
2306 * Temperature channels are not forcibly enabled, as they can be
Jean Delvarea00afb92010-04-14 16:14:09 +02002307 * set to two different sensor types and we can't guess which one
2308 * is correct for a given system. These channels can be enabled at
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002309 * run-time through the temp{1-3}_type sysfs accessors if needed.
2310 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311
2312 /* Check if voltage monitors are reset manually or by some reason */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002313 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 if ((tmp & 0xff) == 0) {
2315 /* Enable all voltage monitors */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002316 it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 }
2318
2319 /* Check if tachometers are reset manually or by some reason */
Jean Delvare591ec652009-12-09 20:35:48 +01002320 mask = 0x70 & ~(sio_data->skip_fan << 4);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002321 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
Jean Delvare591ec652009-12-09 20:35:48 +01002322 if ((data->fan_main_ctrl & mask) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323 /* Enable all fan tachometers */
Jean Delvare591ec652009-12-09 20:35:48 +01002324 data->fan_main_ctrl |= mask;
Jean Delvare5f2dc792010-03-05 22:17:18 +01002325 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
2326 data->fan_main_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 }
Jean Delvare9060f8b2006-08-28 14:24:17 +02002328 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329
Jean Delvare17d648b2006-08-28 14:23:46 +02002330 /* Set tachometers to 16-bit mode if needed */
Andrew Paprocki04751692008-08-06 22:41:06 +02002331 if (has_16bit_fans(data)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002332 tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
Jean Delvare9060f8b2006-08-28 14:24:17 +02002333 if (~tmp & 0x07 & data->has_fan) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002334 dev_dbg(&pdev->dev,
Jean Delvare17d648b2006-08-28 14:23:46 +02002335 "Setting fan1-3 to 16-bit mode\n");
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002336 it87_write_value(data, IT87_REG_FAN_16BIT,
Jean Delvare17d648b2006-08-28 14:23:46 +02002337 tmp | 0x07);
2338 }
Guenter Roeck0531d982012-03-02 11:46:44 -08002339 /* IT8705F, IT8782F, and IT8783E/F only support three fans. */
2340 if (data->type != it87 && data->type != it8782 &&
2341 data->type != it8783) {
Andrew Paprocki816d8c62008-08-06 22:41:06 +02002342 if (tmp & (1 << 4))
2343 data->has_fan |= (1 << 3); /* fan4 enabled */
2344 if (tmp & (1 << 5))
2345 data->has_fan |= (1 << 4); /* fan5 enabled */
2346 }
Jean Delvare17d648b2006-08-28 14:23:46 +02002347 }
2348
Jean Delvare591ec652009-12-09 20:35:48 +01002349 /* Fan input pins may be used for alternative functions */
2350 data->has_fan &= ~sio_data->skip_fan;
2351
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 /* Start monitoring */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002353 it87_write_value(data, IT87_REG_CONFIG,
Jean Delvare41002f82012-07-12 22:47:37 +02002354 (it87_read_value(data, IT87_REG_CONFIG) & 0x3e)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 | (update_vbat ? 0x41 : 0x01));
2356}
2357
Jean Delvareb99883d2010-03-05 22:17:15 +01002358static void it87_update_pwm_ctrl(struct it87_data *data, int nr)
2359{
2360 data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM(nr));
Jean Delvare16b5dda2012-01-16 22:51:48 +01002361 if (has_newer_autopwm(data)) {
Jean Delvareb99883d2010-03-05 22:17:15 +01002362 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
Jean Delvare6229cdb2010-12-08 16:27:22 +01002363 data->pwm_duty[nr] = it87_read_value(data,
2364 IT87_REG_PWM_DUTY(nr));
2365 } else {
2366 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
2367 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
2368 else /* Manual mode */
2369 data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f;
2370 }
Jean Delvare4f3f51b2010-03-05 22:17:21 +01002371
2372 if (has_old_autopwm(data)) {
2373 int i;
2374
2375 for (i = 0; i < 5 ; i++)
2376 data->auto_temp[nr][i] = it87_read_value(data,
2377 IT87_REG_AUTO_TEMP(nr, i));
2378 for (i = 0; i < 3 ; i++)
2379 data->auto_pwm[nr][i] = it87_read_value(data,
2380 IT87_REG_AUTO_PWM(nr, i));
2381 }
Jean Delvareb99883d2010-03-05 22:17:15 +01002382}
2383
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384static struct it87_data *it87_update_device(struct device *dev)
2385{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002386 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 int i;
2388
Ingo Molnar9a61bf62006-01-18 23:19:26 +01002389 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390
2391 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
2392 || !data->valid) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 if (update_vbat) {
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002394 /*
2395 * Cleared after each update, so reenable. Value
2396 * returned by this read will be previous value
2397 */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002398 it87_write_value(data, IT87_REG_CONFIG,
Jean Delvare5f2dc792010-03-05 22:17:18 +01002399 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 }
2401 for (i = 0; i <= 7; i++) {
Guenter Roeck929c6a52012-12-19 22:17:00 +01002402 data->in[i][0] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01002403 it87_read_value(data, IT87_REG_VIN(i));
Guenter Roeck929c6a52012-12-19 22:17:00 +01002404 data->in[i][1] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01002405 it87_read_value(data, IT87_REG_VIN_MIN(i));
Guenter Roeck929c6a52012-12-19 22:17:00 +01002406 data->in[i][2] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01002407 it87_read_value(data, IT87_REG_VIN_MAX(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 }
Jean Delvare3543a532006-08-28 14:27:25 +02002409 /* in8 (battery) has no limit registers */
Guenter Roeck929c6a52012-12-19 22:17:00 +01002410 data->in[8][0] = it87_read_value(data, IT87_REG_VIN(8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411
Jean Delvarec7f1f712007-09-03 17:11:46 +02002412 for (i = 0; i < 5; i++) {
Jean Delvare9060f8b2006-08-28 14:24:17 +02002413 /* Skip disabled fans */
2414 if (!(data->has_fan & (1 << i)))
2415 continue;
2416
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 data->fan_min[i] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01002418 it87_read_value(data, IT87_REG_FAN_MIN[i]);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002419 data->fan[i] = it87_read_value(data,
Jean Delvarec7f1f712007-09-03 17:11:46 +02002420 IT87_REG_FAN[i]);
Jean Delvare17d648b2006-08-28 14:23:46 +02002421 /* Add high byte if in 16-bit mode */
Andrew Paprocki04751692008-08-06 22:41:06 +02002422 if (has_16bit_fans(data)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002423 data->fan[i] |= it87_read_value(data,
Jean Delvarec7f1f712007-09-03 17:11:46 +02002424 IT87_REG_FANX[i]) << 8;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002425 data->fan_min[i] |= it87_read_value(data,
Jean Delvarec7f1f712007-09-03 17:11:46 +02002426 IT87_REG_FANX_MIN[i]) << 8;
Jean Delvare17d648b2006-08-28 14:23:46 +02002427 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 }
2429 for (i = 0; i < 3; i++) {
Guenter Roeck4573acb2012-03-26 16:17:41 -07002430 if (!(data->has_temp & (1 << i)))
2431 continue;
Guenter Roeck60ca3852012-12-19 22:17:00 +01002432 data->temp[i][0] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01002433 it87_read_value(data, IT87_REG_TEMP(i));
Guenter Roeck60ca3852012-12-19 22:17:00 +01002434 data->temp[i][1] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01002435 it87_read_value(data, IT87_REG_TEMP_LOW(i));
Guenter Roeck60ca3852012-12-19 22:17:00 +01002436 data->temp[i][2] =
2437 it87_read_value(data, IT87_REG_TEMP_HIGH(i));
Guenter Roeck161d8982012-12-19 22:17:01 +01002438 if (has_temp_offset(data))
2439 data->temp[i][3] =
2440 it87_read_value(data,
2441 IT87_REG_TEMP_OFFSET[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 }
2443
Jean Delvare17d648b2006-08-28 14:23:46 +02002444 /* Newer chips don't have clock dividers */
Andrew Paprocki04751692008-08-06 22:41:06 +02002445 if ((data->has_fan & 0x07) && !has_16bit_fans(data)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002446 i = it87_read_value(data, IT87_REG_FAN_DIV);
Jean Delvare17d648b2006-08-28 14:23:46 +02002447 data->fan_div[0] = i & 0x07;
2448 data->fan_div[1] = (i >> 3) & 0x07;
2449 data->fan_div[2] = (i & 0x40) ? 3 : 1;
2450 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451
2452 data->alarms =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002453 it87_read_value(data, IT87_REG_ALARM1) |
2454 (it87_read_value(data, IT87_REG_ALARM2) << 8) |
2455 (it87_read_value(data, IT87_REG_ALARM3) << 16);
Jean Delvared9b327c2010-03-05 22:17:17 +01002456 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
Jean Delvareb99883d2010-03-05 22:17:15 +01002457
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002458 data->fan_main_ctrl = it87_read_value(data,
2459 IT87_REG_FAN_MAIN_CTRL);
2460 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
Jean Delvareb99883d2010-03-05 22:17:15 +01002461 for (i = 0; i < 3; i++)
2462 it87_update_pwm_ctrl(data, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002464 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002465 /*
2466 * The IT8705F does not have VID capability.
2467 * The IT8718F and later don't use IT87_REG_VID for the
2468 * same purpose.
2469 */
Jean Delvare17d648b2006-08-28 14:23:46 +02002470 if (data->type == it8712 || data->type == it8716) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002471 data->vid = it87_read_value(data, IT87_REG_VID);
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002472 /*
2473 * The older IT8712F revisions had only 5 VID pins,
2474 * but we assume it is always safe to read 6 bits.
2475 */
Jean Delvare17d648b2006-08-28 14:23:46 +02002476 data->vid &= 0x3f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 }
2478 data->last_updated = jiffies;
2479 data->valid = 1;
2480 }
2481
Ingo Molnar9a61bf62006-01-18 23:19:26 +01002482 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483
2484 return data;
2485}
2486
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002487static int __init it87_device_add(unsigned short address,
2488 const struct it87_sio_data *sio_data)
2489{
2490 struct resource res = {
Bjorn Helgaas87b4b662008-01-22 07:21:03 -05002491 .start = address + IT87_EC_OFFSET,
2492 .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1,
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002493 .name = DRVNAME,
2494 .flags = IORESOURCE_IO,
2495 };
2496 int err;
2497
Jean Delvareb9acb642009-01-07 16:37:35 +01002498 err = acpi_check_resource_conflict(&res);
2499 if (err)
2500 goto exit;
2501
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002502 pdev = platform_device_alloc(DRVNAME, address);
2503 if (!pdev) {
2504 err = -ENOMEM;
Joe Perchesa8ca1032011-01-12 21:55:10 +01002505 pr_err("Device allocation failed\n");
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002506 goto exit;
2507 }
2508
2509 err = platform_device_add_resources(pdev, &res, 1);
2510 if (err) {
Joe Perchesa8ca1032011-01-12 21:55:10 +01002511 pr_err("Device resource addition failed (%d)\n", err);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002512 goto exit_device_put;
2513 }
2514
2515 err = platform_device_add_data(pdev, sio_data,
2516 sizeof(struct it87_sio_data));
2517 if (err) {
Joe Perchesa8ca1032011-01-12 21:55:10 +01002518 pr_err("Platform data allocation failed\n");
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002519 goto exit_device_put;
2520 }
2521
2522 err = platform_device_add(pdev);
2523 if (err) {
Joe Perchesa8ca1032011-01-12 21:55:10 +01002524 pr_err("Device addition failed (%d)\n", err);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002525 goto exit_device_put;
2526 }
2527
2528 return 0;
2529
2530exit_device_put:
2531 platform_device_put(pdev);
2532exit:
2533 return err;
2534}
2535
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536static int __init sm_it87_init(void)
2537{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002538 int err;
Jean Delvare5f2dc792010-03-05 22:17:18 +01002539 unsigned short isa_address = 0;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002540 struct it87_sio_data sio_data;
Jean Delvarefde09502005-07-19 23:51:07 +02002541
Jean Delvare98dd22c2008-10-09 15:33:58 +02002542 memset(&sio_data, 0, sizeof(struct it87_sio_data));
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002543 err = it87_find(&isa_address, &sio_data);
2544 if (err)
2545 return err;
2546 err = platform_driver_register(&it87_driver);
2547 if (err)
2548 return err;
2549
2550 err = it87_device_add(isa_address, &sio_data);
Jean Delvare5f2dc792010-03-05 22:17:18 +01002551 if (err) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002552 platform_driver_unregister(&it87_driver);
2553 return err;
2554 }
2555
2556 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557}
2558
2559static void __exit sm_it87_exit(void)
2560{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002561 platform_device_unregister(pdev);
2562 platform_driver_unregister(&it87_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563}
2564
2565
Jean Delvaref1d8e332007-11-25 16:14:44 +01002566MODULE_AUTHOR("Chris Gauthron, "
Jean Delvareb19367c2006-08-28 14:39:26 +02002567 "Jean Delvare <khali@linux-fr.org>");
Jean Delvare44c1bcd2010-10-28 20:31:51 +02002568MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569module_param(update_vbat, bool, 0);
2570MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
2571module_param(fix_pwm_polarity, bool, 0);
Jean Delvare5f2dc792010-03-05 22:17:18 +01002572MODULE_PARM_DESC(fix_pwm_polarity,
2573 "Force PWM polarity to active high (DANGEROUS)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574MODULE_LICENSE("GPL");
2575
2576module_init(sm_it87_init);
2577module_exit(sm_it87_exit);