blob: 59c147b9b9763966f346dc63460ab3181687eb15 [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 */
Guenter Roecke1169ba2012-12-19 22:17:01 +0100265 u16 fan[5][2]; /* Register values, [nr][0]=fan, [1]=min */
Guenter Roeck4573acb2012-03-26 16:17:41 -0700266 u8 has_temp; /* Bitfield, temp sensors enabled */
Guenter Roeck161d8982012-12-19 22:17:01 +0100267 s8 temp[3][4]; /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 u8 sensor; /* Register value */
269 u8 fan_div[3]; /* Register encoding, shifted right */
270 u8 vid; /* Register encoding, combined */
Jean Delvarea7be58a2005-12-18 16:40:14 +0100271 u8 vrm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272 u32 alarms; /* Register encoding, combined */
Jean Delvared9b327c2010-03-05 22:17:17 +0100273 u8 beeps; /* Register encoding */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 u8 fan_main_ctrl; /* Register value */
Jean Delvaref8d0c192007-02-14 21:15:02 +0100275 u8 fan_ctl; /* Register value */
Jean Delvareb99883d2010-03-05 22:17:15 +0100276
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800277 /*
278 * The following 3 arrays correspond to the same registers up to
Jean Delvare6229cdb2010-12-08 16:27:22 +0100279 * the IT8720F. The meaning of bits 6-0 depends on the value of bit
280 * 7, and we want to preserve settings on mode changes, so we have
281 * to track all values separately.
282 * Starting with the IT8721F, the manual PWM duty cycles are stored
283 * in separate registers (8-bit values), so the separate tracking
284 * is no longer needed, but it is still done to keep the driver
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800285 * simple.
286 */
Jean Delvareb99883d2010-03-05 22:17:15 +0100287 u8 pwm_ctrl[3]; /* Register value */
Jean Delvare6229cdb2010-12-08 16:27:22 +0100288 u8 pwm_duty[3]; /* Manual PWM value set by user */
Jean Delvareb99883d2010-03-05 22:17:15 +0100289 u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */
Jean Delvare4f3f51b2010-03-05 22:17:21 +0100290
291 /* Automatic fan speed control registers */
292 u8 auto_pwm[3][4]; /* [nr][3] is hard-coded */
293 s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294};
295
Jean Delvare16b5dda2012-01-16 22:51:48 +0100296static inline int has_12mv_adc(const struct it87_data *data)
297{
298 /*
299 * IT8721F and later have a 12 mV ADC, also with internal scaling
300 * on selected inputs.
301 */
302 return data->type == it8721
303 || data->type == it8728;
304}
305
306static inline int has_newer_autopwm(const struct it87_data *data)
307{
308 /*
309 * IT8721F and later have separate registers for the temperature
310 * mapping and the manual duty cycle.
311 */
312 return data->type == it8721
313 || data->type == it8728;
314}
315
Guenter Roeck161d8982012-12-19 22:17:01 +0100316static inline int has_temp_offset(const struct it87_data *data)
317{
318 return data->type == it8716
319 || data->type == it8718
320 || data->type == it8720
321 || data->type == it8721
322 || data->type == it8728
323 || data->type == it8782
324 || data->type == it8783;
325}
326
Guenter Roeck0531d982012-03-02 11:46:44 -0800327static int adc_lsb(const struct it87_data *data, int nr)
328{
329 int lsb = has_12mv_adc(data) ? 12 : 16;
330 if (data->in_scaled & (1 << nr))
331 lsb <<= 1;
332 return lsb;
333}
334
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200335static u8 in_to_reg(const struct it87_data *data, int nr, long val)
336{
Guenter Roeck0531d982012-03-02 11:46:44 -0800337 val = DIV_ROUND_CLOSEST(val, adc_lsb(data, nr));
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200338 return SENSORS_LIMIT(val, 0, 255);
339}
340
341static int in_from_reg(const struct it87_data *data, int nr, int val)
342{
Guenter Roeck0531d982012-03-02 11:46:44 -0800343 return val * adc_lsb(data, nr);
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200344}
Jean Delvare0df6454d2010-10-28 20:31:51 +0200345
346static inline u8 FAN_TO_REG(long rpm, int div)
347{
348 if (rpm == 0)
349 return 255;
350 rpm = SENSORS_LIMIT(rpm, 1, 1000000);
351 return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1,
352 254);
353}
354
355static inline u16 FAN16_TO_REG(long rpm)
356{
357 if (rpm == 0)
358 return 0xffff;
359 return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
360}
361
362#define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \
363 1350000 / ((val) * (div)))
364/* The divider is fixed to 2 in 16-bit mode */
365#define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
366 1350000 / ((val) * 2))
367
368#define TEMP_TO_REG(val) (SENSORS_LIMIT(((val) < 0 ? (((val) - 500) / 1000) : \
369 ((val) + 500) / 1000), -128, 127))
370#define TEMP_FROM_REG(val) ((val) * 1000)
371
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200372static u8 pwm_to_reg(const struct it87_data *data, long val)
373{
Jean Delvare16b5dda2012-01-16 22:51:48 +0100374 if (has_newer_autopwm(data))
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200375 return val;
376 else
377 return val >> 1;
378}
379
380static int pwm_from_reg(const struct it87_data *data, u8 reg)
381{
Jean Delvare16b5dda2012-01-16 22:51:48 +0100382 if (has_newer_autopwm(data))
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200383 return reg;
384 else
385 return (reg & 0x7f) << 1;
386}
387
Jean Delvare0df6454d2010-10-28 20:31:51 +0200388
389static int DIV_TO_REG(int val)
390{
391 int answer = 0;
392 while (answer < 7 && (val >>= 1))
393 answer++;
394 return answer;
395}
396#define DIV_FROM_REG(val) (1 << (val))
397
398static const unsigned int pwm_freq[8] = {
399 48000000 / 128,
400 24000000 / 128,
401 12000000 / 128,
402 8000000 / 128,
403 6000000 / 128,
404 3000000 / 128,
405 1500000 / 128,
406 750000 / 128,
407};
408
Andrew Paprocki04751692008-08-06 22:41:06 +0200409static inline int has_16bit_fans(const struct it87_data *data)
410{
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800411 /*
412 * IT8705F Datasheet 0.4.1, 3h == Version G.
413 * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
414 * These are the first revisions with 16-bit tachometer support.
415 */
Andrew Paprocki816d8c62008-08-06 22:41:06 +0200416 return (data->type == it87 && data->revision >= 0x03)
Andrew Paprocki859b9ef2008-09-20 10:25:19 +0200417 || (data->type == it8712 && data->revision >= 0x08)
Andrew Paprocki04751692008-08-06 22:41:06 +0200418 || data->type == it8716
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +0100419 || data->type == it8718
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200420 || data->type == it8720
Jean Delvare16b5dda2012-01-16 22:51:48 +0100421 || data->type == it8721
Guenter Roeck0531d982012-03-02 11:46:44 -0800422 || data->type == it8728
423 || data->type == it8782
424 || data->type == it8783;
Andrew Paprocki04751692008-08-06 22:41:06 +0200425}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Jean Delvare4f3f51b2010-03-05 22:17:21 +0100427static inline int has_old_autopwm(const struct it87_data *data)
428{
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800429 /*
430 * The old automatic fan speed control interface is implemented
431 * by IT8705F chips up to revision F and IT8712F chips up to
432 * revision G.
433 */
Jean Delvare4f3f51b2010-03-05 22:17:21 +0100434 return (data->type == it87 && data->revision < 0x03)
435 || (data->type == it8712 && data->revision < 0x08);
436}
437
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200438static int it87_probe(struct platform_device *pdev);
Bill Pemberton281dfd02012-11-19 13:25:51 -0500439static int it87_remove(struct platform_device *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200441static int it87_read_value(struct it87_data *data, u8 reg);
442static void it87_write_value(struct it87_data *data, u8 reg, u8 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443static struct it87_data *it87_update_device(struct device *dev);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200444static int it87_check_pwm(struct device *dev);
445static void it87_init_device(struct platform_device *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200448static struct platform_driver it87_driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100449 .driver = {
Jean Delvare87218842006-09-03 22:36:14 +0200450 .owner = THIS_MODULE,
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200451 .name = DRVNAME,
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100452 },
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200453 .probe = it87_probe,
Bill Pemberton9e5e9b72012-11-19 13:21:20 -0500454 .remove = it87_remove,
Jean Delvarefde09502005-07-19 23:51:07 +0200455};
456
Jean Delvare20ad93d2005-06-05 11:53:25 +0200457static ssize_t show_in(struct device *dev, struct device_attribute *attr,
Guenter Roeck929c6a52012-12-19 22:17:00 +0100458 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459{
Guenter Roeck929c6a52012-12-19 22:17:00 +0100460 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
461 int nr = sattr->nr;
462 int index = sattr->index;
Jean Delvare20ad93d2005-06-05 11:53:25 +0200463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 struct it87_data *data = it87_update_device(dev);
Guenter Roeck929c6a52012-12-19 22:17:00 +0100465 return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466}
467
Guenter Roeck929c6a52012-12-19 22:17:00 +0100468static ssize_t set_in(struct device *dev, struct device_attribute *attr,
469 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470{
Guenter Roeck929c6a52012-12-19 22:17:00 +0100471 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
472 int nr = sattr->nr;
473 int index = sattr->index;
Jean Delvare20ad93d2005-06-05 11:53:25 +0200474
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200475 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100476 unsigned long val;
477
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100478 if (kstrtoul(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +0100479 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100481 mutex_lock(&data->update_lock);
Guenter Roeck929c6a52012-12-19 22:17:00 +0100482 data->in[nr][index] = in_to_reg(data, nr, val);
483 it87_write_value(data,
484 index == 1 ? IT87_REG_VIN_MIN(nr)
485 : IT87_REG_VIN_MAX(nr),
486 data->in[nr][index]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100487 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 return count;
489}
490
Guenter Roeck929c6a52012-12-19 22:17:00 +0100491static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0);
492static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in,
493 0, 1);
494static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in,
495 0, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
Guenter Roeck929c6a52012-12-19 22:17:00 +0100497static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0);
498static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in,
499 1, 1);
500static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in,
501 1, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502
Guenter Roeck929c6a52012-12-19 22:17:00 +0100503static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0);
504static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in,
505 2, 1);
506static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in,
507 2, 2);
508
509static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0);
510static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in,
511 3, 1);
512static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in,
513 3, 2);
514
515static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0);
516static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in,
517 4, 1);
518static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in,
519 4, 2);
520
521static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, 0);
522static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in,
523 5, 1);
524static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in,
525 5, 2);
526
527static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 6, 0);
528static SENSOR_DEVICE_ATTR_2(in6_min, S_IRUGO | S_IWUSR, show_in, set_in,
529 6, 1);
530static SENSOR_DEVICE_ATTR_2(in6_max, S_IRUGO | S_IWUSR, show_in, set_in,
531 6, 2);
532
533static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 7, 0);
534static SENSOR_DEVICE_ATTR_2(in7_min, S_IRUGO | S_IWUSR, show_in, set_in,
535 7, 1);
536static SENSOR_DEVICE_ATTR_2(in7_max, S_IRUGO | S_IWUSR, show_in, set_in,
537 7, 2);
538
539static SENSOR_DEVICE_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 8, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
541/* 3 temperatures */
Jean Delvare20ad93d2005-06-05 11:53:25 +0200542static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
Guenter Roeck60ca3852012-12-19 22:17:00 +0100543 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544{
Guenter Roeck60ca3852012-12-19 22:17:00 +0100545 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
546 int nr = sattr->nr;
547 int index = sattr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548 struct it87_data *data = it87_update_device(dev);
Jean Delvare20ad93d2005-06-05 11:53:25 +0200549
Guenter Roeck60ca3852012-12-19 22:17:00 +0100550 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200552
Guenter Roeck60ca3852012-12-19 22:17:00 +0100553static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
554 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555{
Guenter Roeck60ca3852012-12-19 22:17:00 +0100556 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
557 int nr = sattr->nr;
558 int index = sattr->index;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200559 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100560 long val;
Guenter Roeck161d8982012-12-19 22:17:01 +0100561 u8 reg, regval;
Jean Delvaref5f64502010-03-05 22:17:19 +0100562
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100563 if (kstrtol(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +0100564 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100566 mutex_lock(&data->update_lock);
Guenter Roeck161d8982012-12-19 22:17:01 +0100567
568 switch (index) {
569 default:
570 case 1:
571 reg = IT87_REG_TEMP_LOW(nr);
572 break;
573 case 2:
574 reg = IT87_REG_TEMP_HIGH(nr);
575 break;
576 case 3:
577 regval = it87_read_value(data, IT87_REG_BEEP_ENABLE);
578 if (!(regval & 0x80)) {
579 regval |= 0x80;
580 it87_write_value(data, IT87_REG_BEEP_ENABLE, regval);
581 }
582 data->valid = 0;
583 reg = IT87_REG_TEMP_OFFSET[nr];
584 break;
585 }
586
Guenter Roeck60ca3852012-12-19 22:17:00 +0100587 data->temp[nr][index] = TEMP_TO_REG(val);
Guenter Roeck161d8982012-12-19 22:17:01 +0100588 it87_write_value(data, reg, data->temp[nr][index]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100589 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 return count;
591}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200592
Guenter Roeck60ca3852012-12-19 22:17:00 +0100593static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0);
594static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
595 0, 1);
596static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
597 0, 2);
Guenter Roeck161d8982012-12-19 22:17:01 +0100598static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp,
599 set_temp, 0, 3);
Guenter Roeck60ca3852012-12-19 22:17:00 +0100600static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0);
601static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
602 1, 1);
603static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
604 1, 2);
Guenter Roeck161d8982012-12-19 22:17:01 +0100605static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp,
606 set_temp, 1, 3);
Guenter Roeck60ca3852012-12-19 22:17:00 +0100607static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, 0);
608static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
609 2, 1);
610static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
611 2, 2);
Guenter Roeck161d8982012-12-19 22:17:01 +0100612static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp,
613 set_temp, 2, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Guenter Roeck2cece012012-12-19 22:17:01 +0100615static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr,
616 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200618 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
619 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 struct it87_data *data = it87_update_device(dev);
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800621 u8 reg = data->sensor; /* In case value is updated while used */
Jean Delvare5f2dc792010-03-05 22:17:18 +0100622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 if (reg & (1 << nr))
624 return sprintf(buf, "3\n"); /* thermal diode */
625 if (reg & (8 << nr))
Jean Delvare4ed10772008-10-17 17:51:16 +0200626 return sprintf(buf, "4\n"); /* thermistor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 return sprintf(buf, "0\n"); /* disabled */
628}
Guenter Roeck2cece012012-12-19 22:17:01 +0100629
630static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr,
631 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200633 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
634 int nr = sensor_attr->index;
635
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200636 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100637 long val;
Jean Delvare8acf07c2010-04-14 16:14:09 +0200638 u8 reg;
Jean Delvaref5f64502010-03-05 22:17:19 +0100639
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100640 if (kstrtol(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +0100641 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
Jean Delvare8acf07c2010-04-14 16:14:09 +0200643 reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
644 reg &= ~(1 << nr);
645 reg &= ~(8 << nr);
Jean Delvare4ed10772008-10-17 17:51:16 +0200646 if (val == 2) { /* backwards compatibility */
Guenter Roeck1d9bcf62012-12-19 22:17:01 +0100647 dev_warn(dev,
648 "Sensor type 2 is deprecated, please use 4 instead\n");
Jean Delvare4ed10772008-10-17 17:51:16 +0200649 val = 4;
650 }
651 /* 3 = thermal diode; 4 = thermistor; 0 = disabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 if (val == 3)
Jean Delvare8acf07c2010-04-14 16:14:09 +0200653 reg |= 1 << nr;
Jean Delvare4ed10772008-10-17 17:51:16 +0200654 else if (val == 4)
Jean Delvare8acf07c2010-04-14 16:14:09 +0200655 reg |= 8 << nr;
656 else if (val != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 return -EINVAL;
Jean Delvare8acf07c2010-04-14 16:14:09 +0200658
659 mutex_lock(&data->update_lock);
660 data->sensor = reg;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200661 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
Jean Delvare2b3d1d82010-04-14 16:14:10 +0200662 data->valid = 0; /* Force cache refresh */
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100663 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 return count;
665}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
Guenter Roeck2cece012012-12-19 22:17:01 +0100667static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR, show_temp_type,
668 set_temp_type, 0);
669static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type,
670 set_temp_type, 1);
671static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type,
672 set_temp_type, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
674/* 3 Fans */
Jean Delvareb99883d2010-03-05 22:17:15 +0100675
676static int pwm_mode(const struct it87_data *data, int nr)
677{
678 int ctrl = data->fan_main_ctrl & (1 << nr);
679
680 if (ctrl == 0) /* Full speed */
681 return 0;
682 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
683 return 2;
684 else /* Manual mode */
685 return 1;
686}
687
Jean Delvare20ad93d2005-06-05 11:53:25 +0200688static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
Guenter Roecke1169ba2012-12-19 22:17:01 +0100689 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
Guenter Roecke1169ba2012-12-19 22:17:01 +0100691 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
692 int nr = sattr->nr;
693 int index = sattr->index;
694 int speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 struct it87_data *data = it87_update_device(dev);
Jean Delvare20ad93d2005-06-05 11:53:25 +0200696
Guenter Roecke1169ba2012-12-19 22:17:01 +0100697 speed = has_16bit_fans(data) ?
698 FAN16_FROM_REG(data->fan[nr][index]) :
699 FAN_FROM_REG(data->fan[nr][index],
700 DIV_FROM_REG(data->fan_div[nr]));
701 return sprintf(buf, "%d\n", speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702}
Guenter Roecke1169ba2012-12-19 22:17:01 +0100703
Jean Delvare20ad93d2005-06-05 11:53:25 +0200704static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
705 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200707 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
708 int nr = sensor_attr->index;
709
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 struct it87_data *data = it87_update_device(dev);
711 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
712}
Jean Delvare5f2dc792010-03-05 22:17:18 +0100713static ssize_t show_pwm_enable(struct device *dev,
714 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200716 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
717 int nr = sensor_attr->index;
718
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 struct it87_data *data = it87_update_device(dev);
Jean Delvareb99883d2010-03-05 22:17:15 +0100720 return sprintf(buf, "%d\n", pwm_mode(data, nr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200722static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
723 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200725 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
726 int nr = sensor_attr->index;
727
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 struct it87_data *data = it87_update_device(dev);
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200729 return sprintf(buf, "%d\n",
730 pwm_from_reg(data, data->pwm_duty[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731}
Jean Delvaref8d0c192007-02-14 21:15:02 +0100732static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
733 char *buf)
734{
735 struct it87_data *data = it87_update_device(dev);
736 int index = (data->fan_ctl >> 4) & 0x07;
737
738 return sprintf(buf, "%u\n", pwm_freq[index]);
739}
Guenter Roecke1169ba2012-12-19 22:17:01 +0100740
741static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
742 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743{
Guenter Roecke1169ba2012-12-19 22:17:01 +0100744 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
745 int nr = sattr->nr;
746 int index = sattr->index;
Jean Delvare20ad93d2005-06-05 11:53:25 +0200747
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200748 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100749 long val;
Jean Delvare7f999aa2007-02-14 21:15:03 +0100750 u8 reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100752 if (kstrtol(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +0100753 return -EINVAL;
754
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100755 mutex_lock(&data->update_lock);
Guenter Roecke1169ba2012-12-19 22:17:01 +0100756
757 if (has_16bit_fans(data)) {
758 data->fan[nr][index] = FAN16_TO_REG(val);
759 it87_write_value(data, IT87_REG_FAN_MIN[nr],
760 data->fan[nr][index] & 0xff);
761 it87_write_value(data, IT87_REG_FANX_MIN[nr],
762 data->fan[nr][index] >> 8);
763 } else {
764 reg = it87_read_value(data, IT87_REG_FAN_DIV);
765 switch (nr) {
766 case 0:
767 data->fan_div[nr] = reg & 0x07;
768 break;
769 case 1:
770 data->fan_div[nr] = (reg >> 3) & 0x07;
771 break;
772 case 2:
773 data->fan_div[nr] = (reg & 0x40) ? 3 : 1;
774 break;
775 }
776 data->fan[nr][index] =
777 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
778 it87_write_value(data, IT87_REG_FAN_MIN[nr],
779 data->fan[nr][index]);
Jean Delvare07eab462005-11-23 15:44:31 -0800780 }
781
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100782 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 return count;
784}
Guenter Roecke1169ba2012-12-19 22:17:01 +0100785
Jean Delvare20ad93d2005-06-05 11:53:25 +0200786static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
787 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200789 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
790 int nr = sensor_attr->index;
791
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200792 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100793 unsigned long val;
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200794 int min;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 u8 old;
796
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100797 if (kstrtoul(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +0100798 return -EINVAL;
799
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100800 mutex_lock(&data->update_lock);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200801 old = it87_read_value(data, IT87_REG_FAN_DIV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200803 /* Save fan min limit */
Guenter Roecke1169ba2012-12-19 22:17:01 +0100804 min = FAN_FROM_REG(data->fan[nr][1], DIV_FROM_REG(data->fan_div[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
806 switch (nr) {
807 case 0:
808 case 1:
809 data->fan_div[nr] = DIV_TO_REG(val);
810 break;
811 case 2:
812 if (val < 8)
813 data->fan_div[nr] = 1;
814 else
815 data->fan_div[nr] = 3;
816 }
817 val = old & 0x80;
818 val |= (data->fan_div[0] & 0x07);
819 val |= (data->fan_div[1] & 0x07) << 3;
820 if (data->fan_div[2] == 3)
821 val |= 0x1 << 6;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200822 it87_write_value(data, IT87_REG_FAN_DIV, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200824 /* Restore fan min limit */
Guenter Roecke1169ba2012-12-19 22:17:01 +0100825 data->fan[nr][1] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
826 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan[nr][1]);
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200827
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100828 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829 return count;
830}
Jean Delvarecccfc9c2010-03-05 22:17:21 +0100831
832/* Returns 0 if OK, -EINVAL otherwise */
833static int check_trip_points(struct device *dev, int nr)
834{
835 const struct it87_data *data = dev_get_drvdata(dev);
836 int i, err = 0;
837
838 if (has_old_autopwm(data)) {
839 for (i = 0; i < 3; i++) {
840 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
841 err = -EINVAL;
842 }
843 for (i = 0; i < 2; i++) {
844 if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1])
845 err = -EINVAL;
846 }
847 }
848
849 if (err) {
Guenter Roeck1d9bcf62012-12-19 22:17:01 +0100850 dev_err(dev,
851 "Inconsistent trip points, not switching to automatic mode\n");
Jean Delvarecccfc9c2010-03-05 22:17:21 +0100852 dev_err(dev, "Adjust the trip points and try again\n");
853 }
854 return err;
855}
856
Jean Delvare20ad93d2005-06-05 11:53:25 +0200857static ssize_t set_pwm_enable(struct device *dev,
858 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200860 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
861 int nr = sensor_attr->index;
862
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200863 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100864 long val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100866 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 2)
Jean Delvareb99883d2010-03-05 22:17:15 +0100867 return -EINVAL;
868
Jean Delvarecccfc9c2010-03-05 22:17:21 +0100869 /* Check trip points before switching to automatic mode */
870 if (val == 2) {
871 if (check_trip_points(dev, nr) < 0)
872 return -EINVAL;
873 }
874
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100875 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700876
877 if (val == 0) {
878 int tmp;
879 /* make sure the fan is on when in on/off mode */
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200880 tmp = it87_read_value(data, IT87_REG_FAN_CTL);
881 it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 /* set on/off mode */
883 data->fan_main_ctrl &= ~(1 << nr);
Jean Delvare5f2dc792010-03-05 22:17:18 +0100884 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
885 data->fan_main_ctrl);
Jean Delvareb99883d2010-03-05 22:17:15 +0100886 } else {
887 if (val == 1) /* Manual mode */
Jean Delvare16b5dda2012-01-16 22:51:48 +0100888 data->pwm_ctrl[nr] = has_newer_autopwm(data) ?
Jean Delvare6229cdb2010-12-08 16:27:22 +0100889 data->pwm_temp_map[nr] :
890 data->pwm_duty[nr];
Jean Delvareb99883d2010-03-05 22:17:15 +0100891 else /* Automatic mode */
892 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
893 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 /* set SmartGuardian mode */
895 data->fan_main_ctrl |= (1 << nr);
Jean Delvare5f2dc792010-03-05 22:17:18 +0100896 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
897 data->fan_main_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 }
899
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100900 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 return count;
902}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200903static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
904 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200906 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
907 int nr = sensor_attr->index;
908
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200909 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100910 long val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100912 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 return -EINVAL;
914
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100915 mutex_lock(&data->update_lock);
Jean Delvare16b5dda2012-01-16 22:51:48 +0100916 if (has_newer_autopwm(data)) {
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800917 /*
918 * If we are in automatic mode, the PWM duty cycle register
919 * is read-only so we can't write the value.
920 */
Jean Delvare6229cdb2010-12-08 16:27:22 +0100921 if (data->pwm_ctrl[nr] & 0x80) {
922 mutex_unlock(&data->update_lock);
923 return -EBUSY;
924 }
925 data->pwm_duty[nr] = pwm_to_reg(data, val);
926 it87_write_value(data, IT87_REG_PWM_DUTY(nr),
927 data->pwm_duty[nr]);
928 } else {
929 data->pwm_duty[nr] = pwm_to_reg(data, val);
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800930 /*
931 * If we are in manual mode, write the duty cycle immediately;
932 * otherwise, just store it for later use.
933 */
Jean Delvare6229cdb2010-12-08 16:27:22 +0100934 if (!(data->pwm_ctrl[nr] & 0x80)) {
935 data->pwm_ctrl[nr] = data->pwm_duty[nr];
936 it87_write_value(data, IT87_REG_PWM(nr),
937 data->pwm_ctrl[nr]);
938 }
Jean Delvareb99883d2010-03-05 22:17:15 +0100939 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100940 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 return count;
942}
Jean Delvaref8d0c192007-02-14 21:15:02 +0100943static ssize_t set_pwm_freq(struct device *dev,
944 struct device_attribute *attr, const char *buf, size_t count)
945{
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200946 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100947 unsigned long val;
Jean Delvaref8d0c192007-02-14 21:15:02 +0100948 int i;
949
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100950 if (kstrtoul(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +0100951 return -EINVAL;
952
Jean Delvaref8d0c192007-02-14 21:15:02 +0100953 /* Search for the nearest available frequency */
954 for (i = 0; i < 7; i++) {
955 if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
956 break;
957 }
958
959 mutex_lock(&data->update_lock);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200960 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
Jean Delvaref8d0c192007-02-14 21:15:02 +0100961 data->fan_ctl |= i << 4;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200962 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
Jean Delvaref8d0c192007-02-14 21:15:02 +0100963 mutex_unlock(&data->update_lock);
964
965 return count;
966}
Jean Delvare94ac7ee2010-03-05 22:17:16 +0100967static ssize_t show_pwm_temp_map(struct device *dev,
968 struct device_attribute *attr, char *buf)
969{
970 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
971 int nr = sensor_attr->index;
972
973 struct it87_data *data = it87_update_device(dev);
974 int map;
975
976 if (data->pwm_temp_map[nr] < 3)
977 map = 1 << data->pwm_temp_map[nr];
978 else
979 map = 0; /* Should never happen */
980 return sprintf(buf, "%d\n", map);
981}
982static ssize_t set_pwm_temp_map(struct device *dev,
983 struct device_attribute *attr, const char *buf, size_t count)
984{
985 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
986 int nr = sensor_attr->index;
987
988 struct it87_data *data = dev_get_drvdata(dev);
989 long val;
990 u8 reg;
991
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800992 /*
993 * This check can go away if we ever support automatic fan speed
994 * control on newer chips.
995 */
Jean Delvare4f3f51b2010-03-05 22:17:21 +0100996 if (!has_old_autopwm(data)) {
997 dev_notice(dev, "Mapping change disabled for safety reasons\n");
998 return -EINVAL;
999 }
1000
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001001 if (kstrtol(buf, 10, &val) < 0)
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001002 return -EINVAL;
1003
1004 switch (val) {
1005 case (1 << 0):
1006 reg = 0x00;
1007 break;
1008 case (1 << 1):
1009 reg = 0x01;
1010 break;
1011 case (1 << 2):
1012 reg = 0x02;
1013 break;
1014 default:
1015 return -EINVAL;
1016 }
1017
1018 mutex_lock(&data->update_lock);
1019 data->pwm_temp_map[nr] = reg;
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08001020 /*
1021 * If we are in automatic mode, write the temp mapping immediately;
1022 * otherwise, just store it for later use.
1023 */
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001024 if (data->pwm_ctrl[nr] & 0x80) {
1025 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
1026 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
1027 }
1028 mutex_unlock(&data->update_lock);
1029 return count;
1030}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001032static ssize_t show_auto_pwm(struct device *dev,
1033 struct device_attribute *attr, char *buf)
1034{
1035 struct it87_data *data = it87_update_device(dev);
1036 struct sensor_device_attribute_2 *sensor_attr =
1037 to_sensor_dev_attr_2(attr);
1038 int nr = sensor_attr->nr;
1039 int point = sensor_attr->index;
1040
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001041 return sprintf(buf, "%d\n",
1042 pwm_from_reg(data, data->auto_pwm[nr][point]));
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001043}
1044
1045static ssize_t set_auto_pwm(struct device *dev,
1046 struct device_attribute *attr, const char *buf, size_t count)
1047{
1048 struct it87_data *data = dev_get_drvdata(dev);
1049 struct sensor_device_attribute_2 *sensor_attr =
1050 to_sensor_dev_attr_2(attr);
1051 int nr = sensor_attr->nr;
1052 int point = sensor_attr->index;
1053 long val;
1054
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001055 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001056 return -EINVAL;
1057
1058 mutex_lock(&data->update_lock);
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001059 data->auto_pwm[nr][point] = pwm_to_reg(data, val);
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001060 it87_write_value(data, IT87_REG_AUTO_PWM(nr, point),
1061 data->auto_pwm[nr][point]);
1062 mutex_unlock(&data->update_lock);
1063 return count;
1064}
1065
1066static ssize_t show_auto_temp(struct device *dev,
1067 struct device_attribute *attr, char *buf)
1068{
1069 struct it87_data *data = it87_update_device(dev);
1070 struct sensor_device_attribute_2 *sensor_attr =
1071 to_sensor_dev_attr_2(attr);
1072 int nr = sensor_attr->nr;
1073 int point = sensor_attr->index;
1074
1075 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->auto_temp[nr][point]));
1076}
1077
1078static ssize_t set_auto_temp(struct device *dev,
1079 struct device_attribute *attr, const char *buf, size_t count)
1080{
1081 struct it87_data *data = dev_get_drvdata(dev);
1082 struct sensor_device_attribute_2 *sensor_attr =
1083 to_sensor_dev_attr_2(attr);
1084 int nr = sensor_attr->nr;
1085 int point = sensor_attr->index;
1086 long val;
1087
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001088 if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001089 return -EINVAL;
1090
1091 mutex_lock(&data->update_lock);
1092 data->auto_temp[nr][point] = TEMP_TO_REG(val);
1093 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point),
1094 data->auto_temp[nr][point]);
1095 mutex_unlock(&data->update_lock);
1096 return count;
1097}
1098
Guenter Roecke1169ba2012-12-19 22:17:01 +01001099static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0);
1100static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1101 0, 1);
1102static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, show_fan_div,
1103 set_fan_div, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
Guenter Roecke1169ba2012-12-19 22:17:01 +01001105static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 1, 0);
1106static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1107 1, 1);
1108static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, show_fan_div,
1109 set_fan_div, 1);
1110
1111static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 2, 0);
1112static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1113 2, 1);
1114static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR, show_fan_div,
1115 set_fan_div, 2);
1116
1117static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 3, 0);
1118static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1119 3, 1);
1120
1121static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, 0);
1122static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1123 4, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001124
Guenter Roeckc4458db2012-12-19 22:17:02 +01001125static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
1126 show_pwm_enable, set_pwm_enable, 0);
1127static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0);
1128static DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR, show_pwm_freq, set_pwm_freq);
1129static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO | S_IWUSR,
1130 show_pwm_temp_map, set_pwm_temp_map, 0);
1131static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
1132 show_auto_pwm, set_auto_pwm, 0, 0);
1133static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
1134 show_auto_pwm, set_auto_pwm, 0, 1);
1135static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
1136 show_auto_pwm, set_auto_pwm, 0, 2);
1137static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO,
1138 show_auto_pwm, NULL, 0, 3);
1139static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
1140 show_auto_temp, set_auto_temp, 0, 1);
1141static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1142 show_auto_temp, set_auto_temp, 0, 0);
1143static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
1144 show_auto_temp, set_auto_temp, 0, 2);
1145static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
1146 show_auto_temp, set_auto_temp, 0, 3);
1147static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
1148 show_auto_temp, set_auto_temp, 0, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
Guenter Roeckc4458db2012-12-19 22:17:02 +01001150static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR,
1151 show_pwm_enable, set_pwm_enable, 1);
1152static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1);
1153static DEVICE_ATTR(pwm2_freq, S_IRUGO, show_pwm_freq, NULL);
1154static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IRUGO | S_IWUSR,
1155 show_pwm_temp_map, set_pwm_temp_map, 1);
1156static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR,
1157 show_auto_pwm, set_auto_pwm, 1, 0);
1158static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR,
1159 show_auto_pwm, set_auto_pwm, 1, 1);
1160static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR,
1161 show_auto_pwm, set_auto_pwm, 1, 2);
1162static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO,
1163 show_auto_pwm, NULL, 1, 3);
1164static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR,
1165 show_auto_temp, set_auto_temp, 1, 1);
1166static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1167 show_auto_temp, set_auto_temp, 1, 0);
1168static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR,
1169 show_auto_temp, set_auto_temp, 1, 2);
1170static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
1171 show_auto_temp, set_auto_temp, 1, 3);
1172static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR,
1173 show_auto_temp, set_auto_temp, 1, 4);
1174
1175static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR,
1176 show_pwm_enable, set_pwm_enable, 2);
1177static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 2);
1178static DEVICE_ATTR(pwm3_freq, S_IRUGO, show_pwm_freq, NULL);
1179static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IRUGO | S_IWUSR,
1180 show_pwm_temp_map, set_pwm_temp_map, 2);
1181static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR,
1182 show_auto_pwm, set_auto_pwm, 2, 0);
1183static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR,
1184 show_auto_pwm, set_auto_pwm, 2, 1);
1185static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO | S_IWUSR,
1186 show_auto_pwm, set_auto_pwm, 2, 2);
1187static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO,
1188 show_auto_pwm, NULL, 2, 3);
1189static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp, S_IRUGO | S_IWUSR,
1190 show_auto_temp, set_auto_temp, 2, 1);
1191static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1192 show_auto_temp, set_auto_temp, 2, 0);
1193static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp, S_IRUGO | S_IWUSR,
1194 show_auto_temp, set_auto_temp, 2, 2);
1195static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp, S_IRUGO | S_IWUSR,
1196 show_auto_temp, set_auto_temp, 2, 3);
1197static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_temp, S_IRUGO | S_IWUSR,
1198 show_auto_temp, set_auto_temp, 2, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
1200/* Alarms */
Jean Delvare5f2dc792010-03-05 22:17:18 +01001201static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
1202 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203{
1204 struct it87_data *data = it87_update_device(dev);
Jean Delvare68188ba2005-05-16 18:52:38 +02001205 return sprintf(buf, "%u\n", data->alarms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206}
Jean Delvare1d66c642005-04-18 21:16:59 -07001207static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208
Jean Delvare0124dd72007-11-25 16:16:41 +01001209static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
1210 char *buf)
1211{
1212 int bitnr = to_sensor_dev_attr(attr)->index;
1213 struct it87_data *data = it87_update_device(dev);
1214 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
1215}
Jean Delvare3d30f9e2011-07-25 21:46:10 +02001216
1217static ssize_t clear_intrusion(struct device *dev, struct device_attribute
1218 *attr, const char *buf, size_t count)
1219{
1220 struct it87_data *data = dev_get_drvdata(dev);
1221 long val;
1222 int config;
1223
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001224 if (kstrtol(buf, 10, &val) < 0 || val != 0)
Jean Delvare3d30f9e2011-07-25 21:46:10 +02001225 return -EINVAL;
1226
1227 mutex_lock(&data->update_lock);
1228 config = it87_read_value(data, IT87_REG_CONFIG);
1229 if (config < 0) {
1230 count = config;
1231 } else {
1232 config |= 1 << 5;
1233 it87_write_value(data, IT87_REG_CONFIG, config);
1234 /* Invalidate cache to force re-read */
1235 data->valid = 0;
1236 }
1237 mutex_unlock(&data->update_lock);
1238
1239 return count;
1240}
1241
Jean Delvare0124dd72007-11-25 16:16:41 +01001242static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
1243static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
1244static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
1245static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
1246static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
1247static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
1248static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
1249static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
1250static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
1251static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
1252static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
1253static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
1254static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
1255static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
1256static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
1257static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
Jean Delvare3d30f9e2011-07-25 21:46:10 +02001258static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR,
1259 show_alarm, clear_intrusion, 4);
Jean Delvare0124dd72007-11-25 16:16:41 +01001260
Jean Delvared9b327c2010-03-05 22:17:17 +01001261static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
1262 char *buf)
1263{
1264 int bitnr = to_sensor_dev_attr(attr)->index;
1265 struct it87_data *data = it87_update_device(dev);
1266 return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1);
1267}
1268static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
1269 const char *buf, size_t count)
1270{
1271 int bitnr = to_sensor_dev_attr(attr)->index;
1272 struct it87_data *data = dev_get_drvdata(dev);
1273 long val;
1274
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001275 if (kstrtol(buf, 10, &val) < 0
Jean Delvared9b327c2010-03-05 22:17:17 +01001276 || (val != 0 && val != 1))
1277 return -EINVAL;
1278
1279 mutex_lock(&data->update_lock);
1280 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
1281 if (val)
1282 data->beeps |= (1 << bitnr);
1283 else
1284 data->beeps &= ~(1 << bitnr);
1285 it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps);
1286 mutex_unlock(&data->update_lock);
1287 return count;
1288}
1289
1290static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
1291 show_beep, set_beep, 1);
1292static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1);
1293static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1);
1294static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1);
1295static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1);
1296static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1);
1297static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1);
1298static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1);
1299/* fanX_beep writability is set later */
1300static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0);
1301static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0);
1302static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0);
1303static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0);
1304static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0);
1305static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
1306 show_beep, set_beep, 2);
1307static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
1308static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2);
1309
Jean Delvare5f2dc792010-03-05 22:17:18 +01001310static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
1311 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312{
Jean Delvare90d66192007-10-08 18:24:35 +02001313 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvarea7be58a2005-12-18 16:40:14 +01001314 return sprintf(buf, "%u\n", data->vrm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315}
Jean Delvare5f2dc792010-03-05 22:17:18 +01001316static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
1317 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001319 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +01001320 unsigned long val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001322 if (kstrtoul(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +01001323 return -EINVAL;
1324
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325 data->vrm = val;
1326
1327 return count;
1328}
1329static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330
Jean Delvare5f2dc792010-03-05 22:17:18 +01001331static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
1332 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333{
1334 struct it87_data *data = it87_update_device(dev);
1335 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
1336}
1337static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
Jean Delvare87808be2006-09-24 21:17:13 +02001338
Jean Delvare738e5e02010-08-14 21:08:50 +02001339static ssize_t show_label(struct device *dev, struct device_attribute *attr,
1340 char *buf)
1341{
Guenter Roeck3c4c4972012-01-20 09:29:44 -08001342 static const char * const labels[] = {
Jean Delvare738e5e02010-08-14 21:08:50 +02001343 "+5V",
1344 "5VSB",
1345 "Vbat",
1346 };
Guenter Roeck3c4c4972012-01-20 09:29:44 -08001347 static const char * const labels_it8721[] = {
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001348 "+3.3V",
1349 "3VSB",
1350 "Vbat",
1351 };
1352 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvare738e5e02010-08-14 21:08:50 +02001353 int nr = to_sensor_dev_attr(attr)->index;
1354
Jean Delvare16b5dda2012-01-16 22:51:48 +01001355 return sprintf(buf, "%s\n", has_12mv_adc(data) ? labels_it8721[nr]
1356 : labels[nr]);
Jean Delvare738e5e02010-08-14 21:08:50 +02001357}
1358static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0);
1359static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1);
1360static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2);
1361
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001362static ssize_t show_name(struct device *dev, struct device_attribute
1363 *devattr, char *buf)
1364{
1365 struct it87_data *data = dev_get_drvdata(dev);
1366 return sprintf(buf, "%s\n", data->name);
1367}
1368static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
1369
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001370static struct attribute *it87_attributes_in[9][5] = {
1371{
Jean Delvare87808be2006-09-24 21:17:13 +02001372 &sensor_dev_attr_in0_input.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001373 &sensor_dev_attr_in0_min.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001374 &sensor_dev_attr_in0_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001375 &sensor_dev_attr_in0_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001376 NULL
1377}, {
1378 &sensor_dev_attr_in1_input.dev_attr.attr,
1379 &sensor_dev_attr_in1_min.dev_attr.attr,
1380 &sensor_dev_attr_in1_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001381 &sensor_dev_attr_in1_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001382 NULL
1383}, {
1384 &sensor_dev_attr_in2_input.dev_attr.attr,
1385 &sensor_dev_attr_in2_min.dev_attr.attr,
1386 &sensor_dev_attr_in2_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001387 &sensor_dev_attr_in2_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001388 NULL
1389}, {
1390 &sensor_dev_attr_in3_input.dev_attr.attr,
1391 &sensor_dev_attr_in3_min.dev_attr.attr,
1392 &sensor_dev_attr_in3_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001393 &sensor_dev_attr_in3_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001394 NULL
1395}, {
1396 &sensor_dev_attr_in4_input.dev_attr.attr,
1397 &sensor_dev_attr_in4_min.dev_attr.attr,
1398 &sensor_dev_attr_in4_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001399 &sensor_dev_attr_in4_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001400 NULL
1401}, {
1402 &sensor_dev_attr_in5_input.dev_attr.attr,
1403 &sensor_dev_attr_in5_min.dev_attr.attr,
1404 &sensor_dev_attr_in5_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001405 &sensor_dev_attr_in5_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001406 NULL
1407}, {
1408 &sensor_dev_attr_in6_input.dev_attr.attr,
1409 &sensor_dev_attr_in6_min.dev_attr.attr,
1410 &sensor_dev_attr_in6_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001411 &sensor_dev_attr_in6_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001412 NULL
1413}, {
1414 &sensor_dev_attr_in7_input.dev_attr.attr,
1415 &sensor_dev_attr_in7_min.dev_attr.attr,
1416 &sensor_dev_attr_in7_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001417 &sensor_dev_attr_in7_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001418 NULL
1419}, {
1420 &sensor_dev_attr_in8_input.dev_attr.attr,
1421 NULL
1422} };
Jean Delvare87808be2006-09-24 21:17:13 +02001423
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001424static const struct attribute_group it87_group_in[9] = {
1425 { .attrs = it87_attributes_in[0] },
1426 { .attrs = it87_attributes_in[1] },
1427 { .attrs = it87_attributes_in[2] },
1428 { .attrs = it87_attributes_in[3] },
1429 { .attrs = it87_attributes_in[4] },
1430 { .attrs = it87_attributes_in[5] },
1431 { .attrs = it87_attributes_in[6] },
1432 { .attrs = it87_attributes_in[7] },
1433 { .attrs = it87_attributes_in[8] },
1434};
1435
Guenter Roeck4573acb2012-03-26 16:17:41 -07001436static struct attribute *it87_attributes_temp[3][6] = {
1437{
Jean Delvare87808be2006-09-24 21:17:13 +02001438 &sensor_dev_attr_temp1_input.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001439 &sensor_dev_attr_temp1_max.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001440 &sensor_dev_attr_temp1_min.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001441 &sensor_dev_attr_temp1_type.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001442 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
Guenter Roeck4573acb2012-03-26 16:17:41 -07001443 NULL
1444} , {
1445 &sensor_dev_attr_temp2_input.dev_attr.attr,
1446 &sensor_dev_attr_temp2_max.dev_attr.attr,
1447 &sensor_dev_attr_temp2_min.dev_attr.attr,
1448 &sensor_dev_attr_temp2_type.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001449 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
Guenter Roeck4573acb2012-03-26 16:17:41 -07001450 NULL
1451} , {
1452 &sensor_dev_attr_temp3_input.dev_attr.attr,
1453 &sensor_dev_attr_temp3_max.dev_attr.attr,
1454 &sensor_dev_attr_temp3_min.dev_attr.attr,
1455 &sensor_dev_attr_temp3_type.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001456 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
Guenter Roeck4573acb2012-03-26 16:17:41 -07001457 NULL
1458} };
Jean Delvare87808be2006-09-24 21:17:13 +02001459
Guenter Roeck4573acb2012-03-26 16:17:41 -07001460static const struct attribute_group it87_group_temp[3] = {
1461 { .attrs = it87_attributes_temp[0] },
1462 { .attrs = it87_attributes_temp[1] },
1463 { .attrs = it87_attributes_temp[2] },
1464};
1465
Guenter Roeck161d8982012-12-19 22:17:01 +01001466static struct attribute *it87_attributes_temp_offset[] = {
1467 &sensor_dev_attr_temp1_offset.dev_attr.attr,
1468 &sensor_dev_attr_temp2_offset.dev_attr.attr,
1469 &sensor_dev_attr_temp3_offset.dev_attr.attr,
1470};
1471
Guenter Roeck4573acb2012-03-26 16:17:41 -07001472static struct attribute *it87_attributes[] = {
Jean Delvare87808be2006-09-24 21:17:13 +02001473 &dev_attr_alarms.attr,
Jean Delvare3d30f9e2011-07-25 21:46:10 +02001474 &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001475 &dev_attr_name.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001476 NULL
1477};
1478
1479static const struct attribute_group it87_group = {
1480 .attrs = it87_attributes,
1481};
1482
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001483static struct attribute *it87_attributes_in_beep[] = {
Jean Delvared9b327c2010-03-05 22:17:17 +01001484 &sensor_dev_attr_in0_beep.dev_attr.attr,
1485 &sensor_dev_attr_in1_beep.dev_attr.attr,
1486 &sensor_dev_attr_in2_beep.dev_attr.attr,
1487 &sensor_dev_attr_in3_beep.dev_attr.attr,
1488 &sensor_dev_attr_in4_beep.dev_attr.attr,
1489 &sensor_dev_attr_in5_beep.dev_attr.attr,
1490 &sensor_dev_attr_in6_beep.dev_attr.attr,
1491 &sensor_dev_attr_in7_beep.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001492 NULL
1493};
Jean Delvared9b327c2010-03-05 22:17:17 +01001494
Guenter Roeck4573acb2012-03-26 16:17:41 -07001495static struct attribute *it87_attributes_temp_beep[] = {
Jean Delvared9b327c2010-03-05 22:17:17 +01001496 &sensor_dev_attr_temp1_beep.dev_attr.attr,
1497 &sensor_dev_attr_temp2_beep.dev_attr.attr,
1498 &sensor_dev_attr_temp3_beep.dev_attr.attr,
Jean Delvared9b327c2010-03-05 22:17:17 +01001499};
1500
Guenter Roecke1169ba2012-12-19 22:17:01 +01001501static struct attribute *it87_attributes_fan[5][3+1] = { {
Jean Delvare87808be2006-09-24 21:17:13 +02001502 &sensor_dev_attr_fan1_input.dev_attr.attr,
1503 &sensor_dev_attr_fan1_min.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001504 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1505 NULL
1506}, {
Jean Delvare87808be2006-09-24 21:17:13 +02001507 &sensor_dev_attr_fan2_input.dev_attr.attr,
1508 &sensor_dev_attr_fan2_min.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001509 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1510 NULL
1511}, {
Jean Delvare87808be2006-09-24 21:17:13 +02001512 &sensor_dev_attr_fan3_input.dev_attr.attr,
1513 &sensor_dev_attr_fan3_min.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001514 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001515 NULL
Guenter Roecke1169ba2012-12-19 22:17:01 +01001516}, {
1517 &sensor_dev_attr_fan4_input.dev_attr.attr,
1518 &sensor_dev_attr_fan4_min.dev_attr.attr,
1519 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1520 NULL
1521}, {
1522 &sensor_dev_attr_fan5_input.dev_attr.attr,
1523 &sensor_dev_attr_fan5_min.dev_attr.attr,
1524 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
1525 NULL
Jean Delvare723a0aa2010-03-05 22:17:16 +01001526} };
Jean Delvare0124dd72007-11-25 16:16:41 +01001527
Guenter Roecke1169ba2012-12-19 22:17:01 +01001528static const struct attribute_group it87_group_fan[5] = {
Jean Delvare723a0aa2010-03-05 22:17:16 +01001529 { .attrs = it87_attributes_fan[0] },
1530 { .attrs = it87_attributes_fan[1] },
1531 { .attrs = it87_attributes_fan[2] },
Guenter Roecke1169ba2012-12-19 22:17:01 +01001532 { .attrs = it87_attributes_fan[3] },
1533 { .attrs = it87_attributes_fan[4] },
Jean Delvare723a0aa2010-03-05 22:17:16 +01001534};
1535
Guenter Roecke1169ba2012-12-19 22:17:01 +01001536static const struct attribute *it87_attributes_fan_div[] = {
1537 &sensor_dev_attr_fan1_div.dev_attr.attr,
1538 &sensor_dev_attr_fan2_div.dev_attr.attr,
1539 &sensor_dev_attr_fan3_div.dev_attr.attr,
1540};
Jean Delvare723a0aa2010-03-05 22:17:16 +01001541
1542static struct attribute *it87_attributes_pwm[3][4+1] = { {
Jean Delvare87808be2006-09-24 21:17:13 +02001543 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001544 &sensor_dev_attr_pwm1.dev_attr.attr,
Jean Delvared5b0b5d2007-12-14 14:41:53 +01001545 &dev_attr_pwm1_freq.attr,
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001546 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001547 NULL
1548}, {
1549 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1550 &sensor_dev_attr_pwm2.dev_attr.attr,
1551 &dev_attr_pwm2_freq.attr,
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001552 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001553 NULL
1554}, {
1555 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1556 &sensor_dev_attr_pwm3.dev_attr.attr,
1557 &dev_attr_pwm3_freq.attr,
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001558 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001559 NULL
1560} };
Jean Delvare87808be2006-09-24 21:17:13 +02001561
Jean Delvare723a0aa2010-03-05 22:17:16 +01001562static const struct attribute_group it87_group_pwm[3] = {
1563 { .attrs = it87_attributes_pwm[0] },
1564 { .attrs = it87_attributes_pwm[1] },
1565 { .attrs = it87_attributes_pwm[2] },
1566};
1567
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001568static struct attribute *it87_attributes_autopwm[3][9+1] = { {
1569 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1570 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
1571 &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
1572 &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
1573 &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
1574 &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
1575 &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
1576 &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
1577 &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
1578 NULL
1579}, {
1580 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1581 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
1582 &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr,
1583 &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr,
1584 &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
1585 &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr,
1586 &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
1587 &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr,
1588 &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr,
1589 NULL
1590}, {
1591 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1592 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
1593 &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr,
1594 &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr,
1595 &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
1596 &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr,
1597 &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
1598 &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr,
1599 &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr,
1600 NULL
1601} };
1602
1603static const struct attribute_group it87_group_autopwm[3] = {
1604 { .attrs = it87_attributes_autopwm[0] },
1605 { .attrs = it87_attributes_autopwm[1] },
1606 { .attrs = it87_attributes_autopwm[2] },
1607};
1608
Jean Delvared9b327c2010-03-05 22:17:17 +01001609static struct attribute *it87_attributes_fan_beep[] = {
1610 &sensor_dev_attr_fan1_beep.dev_attr.attr,
1611 &sensor_dev_attr_fan2_beep.dev_attr.attr,
1612 &sensor_dev_attr_fan3_beep.dev_attr.attr,
1613 &sensor_dev_attr_fan4_beep.dev_attr.attr,
1614 &sensor_dev_attr_fan5_beep.dev_attr.attr,
1615};
1616
Jean Delvare6a8d7ac2010-03-05 22:17:16 +01001617static struct attribute *it87_attributes_vid[] = {
Jean Delvare87808be2006-09-24 21:17:13 +02001618 &dev_attr_vrm.attr,
1619 &dev_attr_cpu0_vid.attr,
1620 NULL
1621};
1622
Jean Delvare6a8d7ac2010-03-05 22:17:16 +01001623static const struct attribute_group it87_group_vid = {
1624 .attrs = it87_attributes_vid,
Jean Delvare87808be2006-09-24 21:17:13 +02001625};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626
Jean Delvare738e5e02010-08-14 21:08:50 +02001627static struct attribute *it87_attributes_label[] = {
1628 &sensor_dev_attr_in3_label.dev_attr.attr,
1629 &sensor_dev_attr_in7_label.dev_attr.attr,
1630 &sensor_dev_attr_in8_label.dev_attr.attr,
1631 NULL
1632};
1633
1634static const struct attribute_group it87_group_label = {
Jean Delvarefa8b6972011-07-17 18:39:19 +02001635 .attrs = it87_attributes_label,
Jean Delvare738e5e02010-08-14 21:08:50 +02001636};
1637
Jean Delvare2d8672c2005-07-19 23:56:35 +02001638/* SuperIO detection - will change isa_address if a chip is found */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001639static int __init it87_find(unsigned short *address,
1640 struct it87_sio_data *sio_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641{
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +02001642 int err;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001643 u16 chip_type;
Jean Delvare98dd22c2008-10-09 15:33:58 +02001644 const char *board_vendor, *board_name;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +02001646 err = superio_enter();
1647 if (err)
1648 return err;
1649
1650 err = -ENODEV;
Jean Delvare67b671b2007-12-06 23:13:42 +01001651 chip_type = force_id ? force_id : superio_inw(DEVID);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001652
1653 switch (chip_type) {
1654 case IT8705F_DEVID:
1655 sio_data->type = it87;
1656 break;
1657 case IT8712F_DEVID:
1658 sio_data->type = it8712;
1659 break;
1660 case IT8716F_DEVID:
1661 case IT8726F_DEVID:
1662 sio_data->type = it8716;
1663 break;
1664 case IT8718F_DEVID:
1665 sio_data->type = it8718;
1666 break;
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +01001667 case IT8720F_DEVID:
1668 sio_data->type = it8720;
1669 break;
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001670 case IT8721F_DEVID:
1671 sio_data->type = it8721;
1672 break;
Jean Delvare16b5dda2012-01-16 22:51:48 +01001673 case IT8728F_DEVID:
1674 sio_data->type = it8728;
1675 break;
Guenter Roeck0531d982012-03-02 11:46:44 -08001676 case IT8782F_DEVID:
1677 sio_data->type = it8782;
1678 break;
1679 case IT8783E_DEVID:
1680 sio_data->type = it8783;
1681 break;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001682 case 0xffff: /* No device at all */
1683 goto exit;
1684 default:
Joe Perchesa8ca1032011-01-12 21:55:10 +01001685 pr_debug("Unsupported chip (DEVID=0x%x)\n", chip_type);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001686 goto exit;
1687 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
Jean Delvare87673dd2006-08-28 14:37:19 +02001689 superio_select(PME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
Joe Perchesa8ca1032011-01-12 21:55:10 +01001691 pr_info("Device not activated, skipping\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001692 goto exit;
1693 }
1694
1695 *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
1696 if (*address == 0) {
Joe Perchesa8ca1032011-01-12 21:55:10 +01001697 pr_info("Base address not set, skipping\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 goto exit;
1699 }
1700
1701 err = 0;
Andrew Paprocki04751692008-08-06 22:41:06 +02001702 sio_data->revision = superio_inb(DEVREV) & 0x0f;
Joe Perchesa8ca1032011-01-12 21:55:10 +01001703 pr_info("Found IT%04xF chip at 0x%x, revision %d\n",
Andrew Paprocki04751692008-08-06 22:41:06 +02001704 chip_type, *address, sio_data->revision);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001705
Jean Delvare738e5e02010-08-14 21:08:50 +02001706 /* in8 (Vbat) is always internal */
1707 sio_data->internal = (1 << 2);
1708
Jean Delvare87673dd2006-08-28 14:37:19 +02001709 /* Read GPIO config and VID value from LDN 7 (GPIO) */
Jean Delvare895ff262009-12-09 20:35:47 +01001710 if (sio_data->type == it87) {
1711 /* The IT8705F doesn't have VID pins at all */
1712 sio_data->skip_vid = 1;
Jean Delvared9b327c2010-03-05 22:17:17 +01001713
1714 /* The IT8705F has a different LD number for GPIO */
1715 superio_select(5);
1716 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
Guenter Roeck0531d982012-03-02 11:46:44 -08001717 } else if (sio_data->type == it8783) {
1718 int reg25, reg27, reg2A, reg2C, regEF;
Guenter Roeck0531d982012-03-02 11:46:44 -08001719
1720 sio_data->skip_vid = 1; /* No VID */
1721
1722 superio_select(GPIO);
1723
1724 reg25 = superio_inb(IT87_SIO_GPIO1_REG);
1725 reg27 = superio_inb(IT87_SIO_GPIO3_REG);
1726 reg2A = superio_inb(IT87_SIO_PINX1_REG);
1727 reg2C = superio_inb(IT87_SIO_PINX2_REG);
1728 regEF = superio_inb(IT87_SIO_SPI_REG);
1729
Guenter Roeck0531d982012-03-02 11:46:44 -08001730 /* Check if fan3 is there or not */
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001731 if ((reg27 & (1 << 0)) || !(reg2C & (1 << 2)))
Guenter Roeck0531d982012-03-02 11:46:44 -08001732 sio_data->skip_fan |= (1 << 2);
1733 if ((reg25 & (1 << 4))
1734 || (!(reg2A & (1 << 1)) && (regEF & (1 << 0))))
1735 sio_data->skip_pwm |= (1 << 2);
1736
1737 /* Check if fan2 is there or not */
1738 if (reg27 & (1 << 7))
1739 sio_data->skip_fan |= (1 << 1);
1740 if (reg27 & (1 << 3))
1741 sio_data->skip_pwm |= (1 << 1);
1742
1743 /* VIN5 */
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001744 if ((reg27 & (1 << 0)) || (reg2C & (1 << 2)))
1745 sio_data->skip_in |= (1 << 5); /* No VIN5 */
Guenter Roeck0531d982012-03-02 11:46:44 -08001746
1747 /* VIN6 */
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001748 if (reg27 & (1 << 1))
1749 sio_data->skip_in |= (1 << 6); /* No VIN6 */
Guenter Roeck0531d982012-03-02 11:46:44 -08001750
1751 /*
1752 * VIN7
1753 * Does not depend on bit 2 of Reg2C, contrary to datasheet.
1754 */
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001755 if (reg27 & (1 << 2)) {
1756 /*
1757 * The data sheet is a bit unclear regarding the
1758 * internal voltage divider for VCCH5V. It says
1759 * "This bit enables and switches VIN7 (pin 91) to the
1760 * internal voltage divider for VCCH5V".
1761 * This is different to other chips, where the internal
1762 * voltage divider would connect VIN7 to an internal
1763 * voltage source. Maybe that is the case here as well.
1764 *
1765 * Since we don't know for sure, re-route it if that is
1766 * not the case, and ask the user to report if the
1767 * resulting voltage is sane.
1768 */
1769 if (!(reg2C & (1 << 1))) {
1770 reg2C |= (1 << 1);
1771 superio_outb(IT87_SIO_PINX2_REG, reg2C);
1772 pr_notice("Routing internal VCCH5V to in7.\n");
1773 }
1774 pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n");
1775 pr_notice("Please report if it displays a reasonable voltage.\n");
1776 }
Guenter Roeck0531d982012-03-02 11:46:44 -08001777
1778 if (reg2C & (1 << 0))
1779 sio_data->internal |= (1 << 0);
1780 if (reg2C & (1 << 1))
1781 sio_data->internal |= (1 << 1);
1782
1783 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
1784
Jean Delvare895ff262009-12-09 20:35:47 +01001785 } else {
Jean Delvare87673dd2006-08-28 14:37:19 +02001786 int reg;
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001787 bool uart6;
Jean Delvare87673dd2006-08-28 14:37:19 +02001788
1789 superio_select(GPIO);
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001790
Jean Delvare895ff262009-12-09 20:35:47 +01001791 reg = superio_inb(IT87_SIO_GPIO3_REG);
Guenter Roeck0531d982012-03-02 11:46:44 -08001792 if (sio_data->type == it8721 || sio_data->type == it8728 ||
1793 sio_data->type == it8782) {
Jean Delvare16b5dda2012-01-16 22:51:48 +01001794 /*
Guenter Roeck0531d982012-03-02 11:46:44 -08001795 * IT8721F/IT8758E, and IT8782F don't have VID pins
1796 * at all, not sure about the IT8728F.
Jean Delvare16b5dda2012-01-16 22:51:48 +01001797 */
Jean Delvare895ff262009-12-09 20:35:47 +01001798 sio_data->skip_vid = 1;
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001799 } else {
1800 /* We need at least 4 VID pins */
1801 if (reg & 0x0f) {
Joe Perchesa8ca1032011-01-12 21:55:10 +01001802 pr_info("VID is disabled (pins used for GPIO)\n");
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001803 sio_data->skip_vid = 1;
1804 }
Jean Delvare895ff262009-12-09 20:35:47 +01001805 }
1806
Jean Delvare591ec652009-12-09 20:35:48 +01001807 /* Check if fan3 is there or not */
1808 if (reg & (1 << 6))
1809 sio_data->skip_pwm |= (1 << 2);
1810 if (reg & (1 << 7))
1811 sio_data->skip_fan |= (1 << 2);
1812
1813 /* Check if fan2 is there or not */
1814 reg = superio_inb(IT87_SIO_GPIO5_REG);
1815 if (reg & (1 << 1))
1816 sio_data->skip_pwm |= (1 << 1);
1817 if (reg & (1 << 2))
1818 sio_data->skip_fan |= (1 << 1);
1819
Jean Delvare895ff262009-12-09 20:35:47 +01001820 if ((sio_data->type == it8718 || sio_data->type == it8720)
1821 && !(sio_data->skip_vid))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001822 sio_data->vid_value = superio_inb(IT87_SIO_VID_REG);
Jean Delvare87673dd2006-08-28 14:37:19 +02001823
1824 reg = superio_inb(IT87_SIO_PINX2_REG);
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001825
1826 uart6 = sio_data->type == it8782 && (reg & (1 << 2));
1827
Jean Delvare436cad22010-07-09 16:22:48 +02001828 /*
1829 * The IT8720F has no VIN7 pin, so VCCH should always be
1830 * routed internally to VIN7 with an internal divider.
1831 * Curiously, there still is a configuration bit to control
1832 * this, which means it can be set incorrectly. And even
1833 * more curiously, many boards out there are improperly
1834 * configured, even though the IT8720F datasheet claims
1835 * that the internal routing of VCCH to VIN7 is the default
1836 * setting. So we force the internal routing in this case.
Guenter Roeck0531d982012-03-02 11:46:44 -08001837 *
1838 * On IT8782F, VIN7 is multiplexed with one of the UART6 pins.
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001839 * If UART6 is enabled, re-route VIN7 to the internal divider
1840 * if that is not already the case.
Jean Delvare436cad22010-07-09 16:22:48 +02001841 */
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001842 if ((sio_data->type == it8720 || uart6) && !(reg & (1 << 1))) {
Jean Delvare436cad22010-07-09 16:22:48 +02001843 reg |= (1 << 1);
1844 superio_outb(IT87_SIO_PINX2_REG, reg);
Joe Perchesa8ca1032011-01-12 21:55:10 +01001845 pr_notice("Routing internal VCCH to in7\n");
Jean Delvare436cad22010-07-09 16:22:48 +02001846 }
Jean Delvare87673dd2006-08-28 14:37:19 +02001847 if (reg & (1 << 0))
Jean Delvare738e5e02010-08-14 21:08:50 +02001848 sio_data->internal |= (1 << 0);
Jean Delvare16b5dda2012-01-16 22:51:48 +01001849 if ((reg & (1 << 1)) || sio_data->type == it8721 ||
1850 sio_data->type == it8728)
Jean Delvare738e5e02010-08-14 21:08:50 +02001851 sio_data->internal |= (1 << 1);
Jean Delvared9b327c2010-03-05 22:17:17 +01001852
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001853 /*
1854 * On IT8782F, UART6 pins overlap with VIN5, VIN6, and VIN7.
1855 * While VIN7 can be routed to the internal voltage divider,
1856 * VIN5 and VIN6 are not available if UART6 is enabled.
Guenter Roeck4573acb2012-03-26 16:17:41 -07001857 *
1858 * Also, temp3 is not available if UART6 is enabled and TEMPIN3
1859 * is the temperature source. Since we can not read the
1860 * temperature source here, skip_temp is preliminary.
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001861 */
Guenter Roeck4573acb2012-03-26 16:17:41 -07001862 if (uart6) {
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001863 sio_data->skip_in |= (1 << 5) | (1 << 6);
Guenter Roeck4573acb2012-03-26 16:17:41 -07001864 sio_data->skip_temp |= (1 << 2);
1865 }
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001866
Jean Delvared9b327c2010-03-05 22:17:17 +01001867 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
Jean Delvare87673dd2006-08-28 14:37:19 +02001868 }
Jean Delvared9b327c2010-03-05 22:17:17 +01001869 if (sio_data->beep_pin)
Joe Perchesa8ca1032011-01-12 21:55:10 +01001870 pr_info("Beeping is supported\n");
Jean Delvare87673dd2006-08-28 14:37:19 +02001871
Jean Delvare98dd22c2008-10-09 15:33:58 +02001872 /* Disable specific features based on DMI strings */
1873 board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
1874 board_name = dmi_get_system_info(DMI_BOARD_NAME);
1875 if (board_vendor && board_name) {
1876 if (strcmp(board_vendor, "nVIDIA") == 0
1877 && strcmp(board_name, "FN68PT") == 0) {
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08001878 /*
1879 * On the Shuttle SN68PT, FAN_CTL2 is apparently not
1880 * connected to a fan, but to something else. One user
1881 * has reported instant system power-off when changing
1882 * the PWM2 duty cycle, so we disable it.
1883 * I use the board name string as the trigger in case
1884 * the same board is ever used in other systems.
1885 */
Joe Perchesa8ca1032011-01-12 21:55:10 +01001886 pr_info("Disabling pwm2 due to hardware constraints\n");
Jean Delvare98dd22c2008-10-09 15:33:58 +02001887 sio_data->skip_pwm = (1 << 1);
1888 }
1889 }
1890
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891exit:
1892 superio_exit();
1893 return err;
1894}
1895
Jean Delvare723a0aa2010-03-05 22:17:16 +01001896static void it87_remove_files(struct device *dev)
1897{
1898 struct it87_data *data = platform_get_drvdata(pdev);
1899 struct it87_sio_data *sio_data = dev->platform_data;
Jean Delvare723a0aa2010-03-05 22:17:16 +01001900 int i;
1901
1902 sysfs_remove_group(&dev->kobj, &it87_group);
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001903 for (i = 0; i < 9; i++) {
1904 if (sio_data->skip_in & (1 << i))
1905 continue;
1906 sysfs_remove_group(&dev->kobj, &it87_group_in[i]);
1907 if (it87_attributes_in_beep[i])
1908 sysfs_remove_file(&dev->kobj,
1909 it87_attributes_in_beep[i]);
1910 }
Guenter Roeck4573acb2012-03-26 16:17:41 -07001911 for (i = 0; i < 3; i++) {
1912 if (!(data->has_temp & (1 << i)))
1913 continue;
1914 sysfs_remove_group(&dev->kobj, &it87_group_temp[i]);
Guenter Roeck161d8982012-12-19 22:17:01 +01001915 if (has_temp_offset(data))
1916 sysfs_remove_file(&dev->kobj,
1917 it87_attributes_temp_offset[i]);
Guenter Roeck4573acb2012-03-26 16:17:41 -07001918 if (sio_data->beep_pin)
1919 sysfs_remove_file(&dev->kobj,
1920 it87_attributes_temp_beep[i]);
1921 }
Jean Delvare723a0aa2010-03-05 22:17:16 +01001922 for (i = 0; i < 5; i++) {
1923 if (!(data->has_fan & (1 << i)))
1924 continue;
Guenter Roecke1169ba2012-12-19 22:17:01 +01001925 sysfs_remove_group(&dev->kobj, &it87_group_fan[i]);
Jean Delvared9b327c2010-03-05 22:17:17 +01001926 if (sio_data->beep_pin)
1927 sysfs_remove_file(&dev->kobj,
1928 it87_attributes_fan_beep[i]);
Guenter Roecke1169ba2012-12-19 22:17:01 +01001929 if (i < 3 && !has_16bit_fans(data))
1930 sysfs_remove_file(&dev->kobj,
1931 it87_attributes_fan_div[i]);
Jean Delvare723a0aa2010-03-05 22:17:16 +01001932 }
1933 for (i = 0; i < 3; i++) {
1934 if (sio_data->skip_pwm & (1 << 0))
1935 continue;
1936 sysfs_remove_group(&dev->kobj, &it87_group_pwm[i]);
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001937 if (has_old_autopwm(data))
1938 sysfs_remove_group(&dev->kobj,
1939 &it87_group_autopwm[i]);
Jean Delvare723a0aa2010-03-05 22:17:16 +01001940 }
Jean Delvare6a8d7ac2010-03-05 22:17:16 +01001941 if (!sio_data->skip_vid)
1942 sysfs_remove_group(&dev->kobj, &it87_group_vid);
Jean Delvare738e5e02010-08-14 21:08:50 +02001943 sysfs_remove_group(&dev->kobj, &it87_group_label);
Jean Delvare723a0aa2010-03-05 22:17:16 +01001944}
1945
Bill Pemberton6c931ae2012-11-19 13:22:35 -05001946static int it87_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 struct it87_data *data;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001949 struct resource *res;
1950 struct device *dev = &pdev->dev;
1951 struct it87_sio_data *sio_data = dev->platform_data;
Jean Delvare723a0aa2010-03-05 22:17:16 +01001952 int err = 0, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 int enable_pwm_interface;
Jean Delvared9b327c2010-03-05 22:17:17 +01001954 int fan_beep_need_rw;
Guenter Roeck3c4c4972012-01-20 09:29:44 -08001955 static const char * const names[] = {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001956 "it87",
1957 "it8712",
1958 "it8716",
1959 "it8718",
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +01001960 "it8720",
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001961 "it8721",
Jean Delvare16b5dda2012-01-16 22:51:48 +01001962 "it8728",
Guenter Roeck0531d982012-03-02 11:46:44 -08001963 "it8782",
1964 "it8783",
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001965 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001967 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
Guenter Roeck62a1d052012-03-24 21:54:41 -07001968 if (!devm_request_region(&pdev->dev, res->start, IT87_EC_EXTENT,
1969 DRVNAME)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001970 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
1971 (unsigned long)res->start,
Bjorn Helgaas87b4b662008-01-22 07:21:03 -05001972 (unsigned long)(res->start + IT87_EC_EXTENT - 1));
Guenter Roeck62a1d052012-03-24 21:54:41 -07001973 return -EBUSY;
Jean Delvare8e9afcb2006-12-12 18:18:28 +01001974 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975
Guenter Roeck62a1d052012-03-24 21:54:41 -07001976 data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL);
1977 if (!data)
1978 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001980 data->addr = res->start;
1981 data->type = sio_data->type;
Andrew Paprocki04751692008-08-06 22:41:06 +02001982 data->revision = sio_data->revision;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001983 data->name = names[sio_data->type];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984
1985 /* Now, we do the remaining detection. */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001986 if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)
Guenter Roeck62a1d052012-03-24 21:54:41 -07001987 || it87_read_value(data, IT87_REG_CHIPID) != 0x90)
1988 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001990 platform_set_drvdata(pdev, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001992 mutex_init(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 /* Check PWM configuration */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001995 enable_pwm_interface = it87_check_pwm(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001997 /* Starting with IT8721F, we handle scaling of internal voltages */
Jean Delvare16b5dda2012-01-16 22:51:48 +01001998 if (has_12mv_adc(data)) {
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001999 if (sio_data->internal & (1 << 0))
2000 data->in_scaled |= (1 << 3); /* in3 is AVCC */
2001 if (sio_data->internal & (1 << 1))
2002 data->in_scaled |= (1 << 7); /* in7 is VSB */
2003 if (sio_data->internal & (1 << 2))
2004 data->in_scaled |= (1 << 8); /* in8 is Vbat */
Guenter Roeck0531d982012-03-02 11:46:44 -08002005 } else if (sio_data->type == it8782 || sio_data->type == it8783) {
2006 if (sio_data->internal & (1 << 0))
2007 data->in_scaled |= (1 << 3); /* in3 is VCC5V */
2008 if (sio_data->internal & (1 << 1))
2009 data->in_scaled |= (1 << 7); /* in7 is VCCH5V */
Jean Delvare44c1bcd2010-10-28 20:31:51 +02002010 }
2011
Guenter Roeck4573acb2012-03-26 16:17:41 -07002012 data->has_temp = 0x07;
2013 if (sio_data->skip_temp & (1 << 2)) {
2014 if (sio_data->type == it8782
2015 && !(it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x80))
2016 data->has_temp &= ~(1 << 2);
2017 }
2018
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 /* Initialize the IT87 chip */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002020 it87_init_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021
2022 /* Register sysfs hooks */
Jean Delvare5f2dc792010-03-05 22:17:18 +01002023 err = sysfs_create_group(&dev->kobj, &it87_group);
2024 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002025 return err;
Jean Delvare17d648b2006-08-28 14:23:46 +02002026
Guenter Roeck9172b5d2012-03-24 21:49:54 -07002027 for (i = 0; i < 9; i++) {
2028 if (sio_data->skip_in & (1 << i))
2029 continue;
2030 err = sysfs_create_group(&dev->kobj, &it87_group_in[i]);
2031 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002032 goto error;
Guenter Roeck9172b5d2012-03-24 21:49:54 -07002033 if (sio_data->beep_pin && it87_attributes_in_beep[i]) {
2034 err = sysfs_create_file(&dev->kobj,
2035 it87_attributes_in_beep[i]);
2036 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002037 goto error;
Guenter Roeck9172b5d2012-03-24 21:49:54 -07002038 }
2039 }
2040
Guenter Roeck4573acb2012-03-26 16:17:41 -07002041 for (i = 0; i < 3; i++) {
2042 if (!(data->has_temp & (1 << i)))
2043 continue;
2044 err = sysfs_create_group(&dev->kobj, &it87_group_temp[i]);
Jean Delvared9b327c2010-03-05 22:17:17 +01002045 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002046 goto error;
Guenter Roeck161d8982012-12-19 22:17:01 +01002047 if (has_temp_offset(data)) {
2048 err = sysfs_create_file(&dev->kobj,
2049 it87_attributes_temp_offset[i]);
2050 if (err)
2051 goto error;
2052 }
Guenter Roeck4573acb2012-03-26 16:17:41 -07002053 if (sio_data->beep_pin) {
2054 err = sysfs_create_file(&dev->kobj,
2055 it87_attributes_temp_beep[i]);
2056 if (err)
2057 goto error;
2058 }
Jean Delvared9b327c2010-03-05 22:17:17 +01002059 }
2060
Jean Delvare9060f8b2006-08-28 14:24:17 +02002061 /* Do not create fan files for disabled fans */
Jean Delvared9b327c2010-03-05 22:17:17 +01002062 fan_beep_need_rw = 1;
Jean Delvare723a0aa2010-03-05 22:17:16 +01002063 for (i = 0; i < 5; i++) {
2064 if (!(data->has_fan & (1 << i)))
2065 continue;
Guenter Roecke1169ba2012-12-19 22:17:01 +01002066 err = sysfs_create_group(&dev->kobj, &it87_group_fan[i]);
Jean Delvare723a0aa2010-03-05 22:17:16 +01002067 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002068 goto error;
Jean Delvared9b327c2010-03-05 22:17:17 +01002069
Guenter Roecke1169ba2012-12-19 22:17:01 +01002070 if (i < 3 && !has_16bit_fans(data)) {
2071 err = sysfs_create_file(&dev->kobj,
2072 it87_attributes_fan_div[i]);
2073 if (err)
2074 goto error;
2075 }
2076
Jean Delvared9b327c2010-03-05 22:17:17 +01002077 if (sio_data->beep_pin) {
2078 err = sysfs_create_file(&dev->kobj,
2079 it87_attributes_fan_beep[i]);
2080 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002081 goto error;
Jean Delvared9b327c2010-03-05 22:17:17 +01002082 if (!fan_beep_need_rw)
2083 continue;
2084
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002085 /*
2086 * As we have a single beep enable bit for all fans,
Jean Delvared9b327c2010-03-05 22:17:17 +01002087 * only the first enabled fan has a writable attribute
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002088 * for it.
2089 */
Jean Delvared9b327c2010-03-05 22:17:17 +01002090 if (sysfs_chmod_file(&dev->kobj,
2091 it87_attributes_fan_beep[i],
2092 S_IRUGO | S_IWUSR))
2093 dev_dbg(dev, "chmod +w fan%d_beep failed\n",
2094 i + 1);
2095 fan_beep_need_rw = 0;
2096 }
Jean Delvare17d648b2006-08-28 14:23:46 +02002097 }
2098
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 if (enable_pwm_interface) {
Jean Delvare723a0aa2010-03-05 22:17:16 +01002100 for (i = 0; i < 3; i++) {
2101 if (sio_data->skip_pwm & (1 << i))
2102 continue;
2103 err = sysfs_create_group(&dev->kobj,
2104 &it87_group_pwm[i]);
2105 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002106 goto error;
Jean Delvare4f3f51b2010-03-05 22:17:21 +01002107
2108 if (!has_old_autopwm(data))
2109 continue;
2110 err = sysfs_create_group(&dev->kobj,
2111 &it87_group_autopwm[i]);
2112 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002113 goto error;
Jean Delvare98dd22c2008-10-09 15:33:58 +02002114 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 }
2116
Jean Delvare895ff262009-12-09 20:35:47 +01002117 if (!sio_data->skip_vid) {
Jean Delvare303760b2005-07-31 21:52:01 +02002118 data->vrm = vid_which_vrm();
Jean Delvare87673dd2006-08-28 14:37:19 +02002119 /* VID reading from Super-I/O config space if available */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002120 data->vid = sio_data->vid_value;
Jean Delvare6a8d7ac2010-03-05 22:17:16 +01002121 err = sysfs_create_group(&dev->kobj, &it87_group_vid);
2122 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002123 goto error;
Jean Delvare87808be2006-09-24 21:17:13 +02002124 }
2125
Jean Delvare738e5e02010-08-14 21:08:50 +02002126 /* Export labels for internal sensors */
2127 for (i = 0; i < 3; i++) {
2128 if (!(sio_data->internal & (1 << i)))
2129 continue;
2130 err = sysfs_create_file(&dev->kobj,
2131 it87_attributes_label[i]);
2132 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002133 goto error;
Jean Delvare738e5e02010-08-14 21:08:50 +02002134 }
2135
Tony Jones1beeffe2007-08-20 13:46:20 -07002136 data->hwmon_dev = hwmon_device_register(dev);
2137 if (IS_ERR(data->hwmon_dev)) {
2138 err = PTR_ERR(data->hwmon_dev);
Guenter Roeck62a1d052012-03-24 21:54:41 -07002139 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 }
2141
2142 return 0;
2143
Guenter Roeck62a1d052012-03-24 21:54:41 -07002144error:
Jean Delvare723a0aa2010-03-05 22:17:16 +01002145 it87_remove_files(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002146 return err;
2147}
2148
Bill Pemberton281dfd02012-11-19 13:25:51 -05002149static int it87_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002151 struct it87_data *data = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152
Tony Jones1beeffe2007-08-20 13:46:20 -07002153 hwmon_device_unregister(data->hwmon_dev);
Jean Delvare723a0aa2010-03-05 22:17:16 +01002154 it87_remove_files(&pdev->dev);
Mark M. Hoffman943b0832005-07-15 21:39:18 -04002155
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 return 0;
2157}
2158
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002159/*
2160 * Must be called with data->update_lock held, except during initialization.
2161 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
2162 * would slow down the IT87 access and should not be necessary.
2163 */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002164static int it87_read_value(struct it87_data *data, u8 reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002166 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
2167 return inb_p(data->addr + IT87_DATA_REG_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168}
2169
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002170/*
2171 * Must be called with data->update_lock held, except during initialization.
2172 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
2173 * would slow down the IT87 access and should not be necessary.
2174 */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002175static void it87_write_value(struct it87_data *data, u8 reg, u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002177 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
2178 outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179}
2180
2181/* Return 1 if and only if the PWM interface is safe to use */
Bill Pemberton6c931ae2012-11-19 13:22:35 -05002182static int it87_check_pwm(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002184 struct it87_data *data = dev_get_drvdata(dev);
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002185 /*
2186 * Some BIOSes fail to correctly configure the IT87 fans. All fans off
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 * and polarity set to active low is sign that this is the case so we
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002188 * disable pwm control to protect the user.
2189 */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002190 int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 if ((tmp & 0x87) == 0) {
2192 if (fix_pwm_polarity) {
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002193 /*
2194 * The user asks us to attempt a chip reconfiguration.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 * This means switching to active high polarity and
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002196 * inverting all fan speed values.
2197 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 int i;
2199 u8 pwm[3];
2200
2201 for (i = 0; i < 3; i++)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002202 pwm[i] = it87_read_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 IT87_REG_PWM(i));
2204
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002205 /*
2206 * If any fan is in automatic pwm mode, the polarity
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 * might be correct, as suspicious as it seems, so we
2208 * better don't change anything (but still disable the
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002209 * PWM interface).
2210 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
Guenter Roeck1d9bcf62012-12-19 22:17:01 +01002212 dev_info(dev,
2213 "Reconfiguring PWM to active high polarity\n");
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002214 it87_write_value(data, IT87_REG_FAN_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 tmp | 0x87);
2216 for (i = 0; i < 3; i++)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002217 it87_write_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 IT87_REG_PWM(i),
2219 0x7f & ~pwm[i]);
2220 return 1;
2221 }
2222
Guenter Roeck1d9bcf62012-12-19 22:17:01 +01002223 dev_info(dev,
2224 "PWM configuration is too broken to be fixed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 }
2226
Guenter Roeck1d9bcf62012-12-19 22:17:01 +01002227 dev_info(dev,
2228 "Detected broken BIOS defaults, disabling PWM interface\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229 return 0;
2230 } else if (fix_pwm_polarity) {
Guenter Roeck1d9bcf62012-12-19 22:17:01 +01002231 dev_info(dev,
2232 "PWM configuration looks sane, won't touch\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 }
2234
2235 return 1;
2236}
2237
2238/* Called when we have found a new IT87. */
Bill Pemberton6c931ae2012-11-19 13:22:35 -05002239static void it87_init_device(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240{
Jean Delvare591ec652009-12-09 20:35:48 +01002241 struct it87_sio_data *sio_data = pdev->dev.platform_data;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002242 struct it87_data *data = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002243 int tmp, i;
Jean Delvare591ec652009-12-09 20:35:48 +01002244 u8 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002246 /*
2247 * For each PWM channel:
Jean Delvareb99883d2010-03-05 22:17:15 +01002248 * - If it is in automatic mode, setting to manual mode should set
2249 * the fan to full speed by default.
2250 * - If it is in manual mode, we need a mapping to temperature
2251 * channels to use when later setting to automatic mode later.
2252 * Use a 1:1 mapping by default (we are clueless.)
2253 * In both cases, the value can (and should) be changed by the user
Jean Delvare6229cdb2010-12-08 16:27:22 +01002254 * prior to switching to a different mode.
2255 * Note that this is no longer needed for the IT8721F and later, as
2256 * these have separate registers for the temperature mapping and the
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002257 * manual duty cycle.
2258 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259 for (i = 0; i < 3; i++) {
Jean Delvareb99883d2010-03-05 22:17:15 +01002260 data->pwm_temp_map[i] = i;
2261 data->pwm_duty[i] = 0x7f; /* Full speed */
Jean Delvare4f3f51b2010-03-05 22:17:21 +01002262 data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 }
2264
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002265 /*
2266 * Some chips seem to have default value 0xff for all limit
Jean Delvarec5df9b72006-08-28 14:37:54 +02002267 * registers. For low voltage limits it makes no sense and triggers
2268 * alarms, so change to 0 instead. For high temperature limits, it
2269 * means -1 degree C, which surprisingly doesn't trigger an alarm,
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002270 * but is still confusing, so change to 127 degrees C.
2271 */
Jean Delvarec5df9b72006-08-28 14:37:54 +02002272 for (i = 0; i < 8; i++) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002273 tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
Jean Delvarec5df9b72006-08-28 14:37:54 +02002274 if (tmp == 0xff)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002275 it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
Jean Delvarec5df9b72006-08-28 14:37:54 +02002276 }
2277 for (i = 0; i < 3; i++) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002278 tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i));
Jean Delvarec5df9b72006-08-28 14:37:54 +02002279 if (tmp == 0xff)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002280 it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127);
Jean Delvarec5df9b72006-08-28 14:37:54 +02002281 }
2282
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002283 /*
2284 * Temperature channels are not forcibly enabled, as they can be
Jean Delvarea00afb92010-04-14 16:14:09 +02002285 * set to two different sensor types and we can't guess which one
2286 * is correct for a given system. These channels can be enabled at
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002287 * run-time through the temp{1-3}_type sysfs accessors if needed.
2288 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289
2290 /* Check if voltage monitors are reset manually or by some reason */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002291 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 if ((tmp & 0xff) == 0) {
2293 /* Enable all voltage monitors */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002294 it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 }
2296
2297 /* Check if tachometers are reset manually or by some reason */
Jean Delvare591ec652009-12-09 20:35:48 +01002298 mask = 0x70 & ~(sio_data->skip_fan << 4);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002299 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
Jean Delvare591ec652009-12-09 20:35:48 +01002300 if ((data->fan_main_ctrl & mask) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 /* Enable all fan tachometers */
Jean Delvare591ec652009-12-09 20:35:48 +01002302 data->fan_main_ctrl |= mask;
Jean Delvare5f2dc792010-03-05 22:17:18 +01002303 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
2304 data->fan_main_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 }
Jean Delvare9060f8b2006-08-28 14:24:17 +02002306 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307
Jean Delvare17d648b2006-08-28 14:23:46 +02002308 /* Set tachometers to 16-bit mode if needed */
Andrew Paprocki04751692008-08-06 22:41:06 +02002309 if (has_16bit_fans(data)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002310 tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
Jean Delvare9060f8b2006-08-28 14:24:17 +02002311 if (~tmp & 0x07 & data->has_fan) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002312 dev_dbg(&pdev->dev,
Jean Delvare17d648b2006-08-28 14:23:46 +02002313 "Setting fan1-3 to 16-bit mode\n");
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002314 it87_write_value(data, IT87_REG_FAN_16BIT,
Jean Delvare17d648b2006-08-28 14:23:46 +02002315 tmp | 0x07);
2316 }
Guenter Roeck0531d982012-03-02 11:46:44 -08002317 /* IT8705F, IT8782F, and IT8783E/F only support three fans. */
2318 if (data->type != it87 && data->type != it8782 &&
2319 data->type != it8783) {
Andrew Paprocki816d8c62008-08-06 22:41:06 +02002320 if (tmp & (1 << 4))
2321 data->has_fan |= (1 << 3); /* fan4 enabled */
2322 if (tmp & (1 << 5))
2323 data->has_fan |= (1 << 4); /* fan5 enabled */
2324 }
Jean Delvare17d648b2006-08-28 14:23:46 +02002325 }
2326
Jean Delvare591ec652009-12-09 20:35:48 +01002327 /* Fan input pins may be used for alternative functions */
2328 data->has_fan &= ~sio_data->skip_fan;
2329
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 /* Start monitoring */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002331 it87_write_value(data, IT87_REG_CONFIG,
Jean Delvare41002f82012-07-12 22:47:37 +02002332 (it87_read_value(data, IT87_REG_CONFIG) & 0x3e)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 | (update_vbat ? 0x41 : 0x01));
2334}
2335
Jean Delvareb99883d2010-03-05 22:17:15 +01002336static void it87_update_pwm_ctrl(struct it87_data *data, int nr)
2337{
2338 data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM(nr));
Jean Delvare16b5dda2012-01-16 22:51:48 +01002339 if (has_newer_autopwm(data)) {
Jean Delvareb99883d2010-03-05 22:17:15 +01002340 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
Jean Delvare6229cdb2010-12-08 16:27:22 +01002341 data->pwm_duty[nr] = it87_read_value(data,
2342 IT87_REG_PWM_DUTY(nr));
2343 } else {
2344 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
2345 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
2346 else /* Manual mode */
2347 data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f;
2348 }
Jean Delvare4f3f51b2010-03-05 22:17:21 +01002349
2350 if (has_old_autopwm(data)) {
2351 int i;
2352
2353 for (i = 0; i < 5 ; i++)
2354 data->auto_temp[nr][i] = it87_read_value(data,
2355 IT87_REG_AUTO_TEMP(nr, i));
2356 for (i = 0; i < 3 ; i++)
2357 data->auto_pwm[nr][i] = it87_read_value(data,
2358 IT87_REG_AUTO_PWM(nr, i));
2359 }
Jean Delvareb99883d2010-03-05 22:17:15 +01002360}
2361
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362static struct it87_data *it87_update_device(struct device *dev)
2363{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002364 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 int i;
2366
Ingo Molnar9a61bf62006-01-18 23:19:26 +01002367 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368
2369 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
2370 || !data->valid) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 if (update_vbat) {
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002372 /*
2373 * Cleared after each update, so reenable. Value
2374 * returned by this read will be previous value
2375 */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002376 it87_write_value(data, IT87_REG_CONFIG,
Jean Delvare5f2dc792010-03-05 22:17:18 +01002377 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 }
2379 for (i = 0; i <= 7; i++) {
Guenter Roeck929c6a52012-12-19 22:17:00 +01002380 data->in[i][0] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01002381 it87_read_value(data, IT87_REG_VIN(i));
Guenter Roeck929c6a52012-12-19 22:17:00 +01002382 data->in[i][1] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01002383 it87_read_value(data, IT87_REG_VIN_MIN(i));
Guenter Roeck929c6a52012-12-19 22:17:00 +01002384 data->in[i][2] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01002385 it87_read_value(data, IT87_REG_VIN_MAX(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 }
Jean Delvare3543a532006-08-28 14:27:25 +02002387 /* in8 (battery) has no limit registers */
Guenter Roeck929c6a52012-12-19 22:17:00 +01002388 data->in[8][0] = it87_read_value(data, IT87_REG_VIN(8));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389
Jean Delvarec7f1f712007-09-03 17:11:46 +02002390 for (i = 0; i < 5; i++) {
Jean Delvare9060f8b2006-08-28 14:24:17 +02002391 /* Skip disabled fans */
2392 if (!(data->has_fan & (1 << i)))
2393 continue;
2394
Guenter Roecke1169ba2012-12-19 22:17:01 +01002395 data->fan[i][1] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01002396 it87_read_value(data, IT87_REG_FAN_MIN[i]);
Guenter Roecke1169ba2012-12-19 22:17:01 +01002397 data->fan[i][0] = it87_read_value(data,
Jean Delvarec7f1f712007-09-03 17:11:46 +02002398 IT87_REG_FAN[i]);
Jean Delvare17d648b2006-08-28 14:23:46 +02002399 /* Add high byte if in 16-bit mode */
Andrew Paprocki04751692008-08-06 22:41:06 +02002400 if (has_16bit_fans(data)) {
Guenter Roecke1169ba2012-12-19 22:17:01 +01002401 data->fan[i][0] |= it87_read_value(data,
Jean Delvarec7f1f712007-09-03 17:11:46 +02002402 IT87_REG_FANX[i]) << 8;
Guenter Roecke1169ba2012-12-19 22:17:01 +01002403 data->fan[i][1] |= it87_read_value(data,
Jean Delvarec7f1f712007-09-03 17:11:46 +02002404 IT87_REG_FANX_MIN[i]) << 8;
Jean Delvare17d648b2006-08-28 14:23:46 +02002405 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 }
2407 for (i = 0; i < 3; i++) {
Guenter Roeck4573acb2012-03-26 16:17:41 -07002408 if (!(data->has_temp & (1 << i)))
2409 continue;
Guenter Roeck60ca3852012-12-19 22:17:00 +01002410 data->temp[i][0] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01002411 it87_read_value(data, IT87_REG_TEMP(i));
Guenter Roeck60ca3852012-12-19 22:17:00 +01002412 data->temp[i][1] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01002413 it87_read_value(data, IT87_REG_TEMP_LOW(i));
Guenter Roeck60ca3852012-12-19 22:17:00 +01002414 data->temp[i][2] =
2415 it87_read_value(data, IT87_REG_TEMP_HIGH(i));
Guenter Roeck161d8982012-12-19 22:17:01 +01002416 if (has_temp_offset(data))
2417 data->temp[i][3] =
2418 it87_read_value(data,
2419 IT87_REG_TEMP_OFFSET[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 }
2421
Jean Delvare17d648b2006-08-28 14:23:46 +02002422 /* Newer chips don't have clock dividers */
Andrew Paprocki04751692008-08-06 22:41:06 +02002423 if ((data->has_fan & 0x07) && !has_16bit_fans(data)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002424 i = it87_read_value(data, IT87_REG_FAN_DIV);
Jean Delvare17d648b2006-08-28 14:23:46 +02002425 data->fan_div[0] = i & 0x07;
2426 data->fan_div[1] = (i >> 3) & 0x07;
2427 data->fan_div[2] = (i & 0x40) ? 3 : 1;
2428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429
2430 data->alarms =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002431 it87_read_value(data, IT87_REG_ALARM1) |
2432 (it87_read_value(data, IT87_REG_ALARM2) << 8) |
2433 (it87_read_value(data, IT87_REG_ALARM3) << 16);
Jean Delvared9b327c2010-03-05 22:17:17 +01002434 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
Jean Delvareb99883d2010-03-05 22:17:15 +01002435
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002436 data->fan_main_ctrl = it87_read_value(data,
2437 IT87_REG_FAN_MAIN_CTRL);
2438 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
Jean Delvareb99883d2010-03-05 22:17:15 +01002439 for (i = 0; i < 3; i++)
2440 it87_update_pwm_ctrl(data, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002442 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002443 /*
2444 * The IT8705F does not have VID capability.
2445 * The IT8718F and later don't use IT87_REG_VID for the
2446 * same purpose.
2447 */
Jean Delvare17d648b2006-08-28 14:23:46 +02002448 if (data->type == it8712 || data->type == it8716) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002449 data->vid = it87_read_value(data, IT87_REG_VID);
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002450 /*
2451 * The older IT8712F revisions had only 5 VID pins,
2452 * but we assume it is always safe to read 6 bits.
2453 */
Jean Delvare17d648b2006-08-28 14:23:46 +02002454 data->vid &= 0x3f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 }
2456 data->last_updated = jiffies;
2457 data->valid = 1;
2458 }
2459
Ingo Molnar9a61bf62006-01-18 23:19:26 +01002460 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461
2462 return data;
2463}
2464
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002465static int __init it87_device_add(unsigned short address,
2466 const struct it87_sio_data *sio_data)
2467{
2468 struct resource res = {
Bjorn Helgaas87b4b662008-01-22 07:21:03 -05002469 .start = address + IT87_EC_OFFSET,
2470 .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1,
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002471 .name = DRVNAME,
2472 .flags = IORESOURCE_IO,
2473 };
2474 int err;
2475
Jean Delvareb9acb642009-01-07 16:37:35 +01002476 err = acpi_check_resource_conflict(&res);
2477 if (err)
2478 goto exit;
2479
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002480 pdev = platform_device_alloc(DRVNAME, address);
2481 if (!pdev) {
2482 err = -ENOMEM;
Joe Perchesa8ca1032011-01-12 21:55:10 +01002483 pr_err("Device allocation failed\n");
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002484 goto exit;
2485 }
2486
2487 err = platform_device_add_resources(pdev, &res, 1);
2488 if (err) {
Joe Perchesa8ca1032011-01-12 21:55:10 +01002489 pr_err("Device resource addition failed (%d)\n", err);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002490 goto exit_device_put;
2491 }
2492
2493 err = platform_device_add_data(pdev, sio_data,
2494 sizeof(struct it87_sio_data));
2495 if (err) {
Joe Perchesa8ca1032011-01-12 21:55:10 +01002496 pr_err("Platform data allocation failed\n");
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002497 goto exit_device_put;
2498 }
2499
2500 err = platform_device_add(pdev);
2501 if (err) {
Joe Perchesa8ca1032011-01-12 21:55:10 +01002502 pr_err("Device addition failed (%d)\n", err);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002503 goto exit_device_put;
2504 }
2505
2506 return 0;
2507
2508exit_device_put:
2509 platform_device_put(pdev);
2510exit:
2511 return err;
2512}
2513
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514static int __init sm_it87_init(void)
2515{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002516 int err;
Jean Delvare5f2dc792010-03-05 22:17:18 +01002517 unsigned short isa_address = 0;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002518 struct it87_sio_data sio_data;
Jean Delvarefde09502005-07-19 23:51:07 +02002519
Jean Delvare98dd22c2008-10-09 15:33:58 +02002520 memset(&sio_data, 0, sizeof(struct it87_sio_data));
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002521 err = it87_find(&isa_address, &sio_data);
2522 if (err)
2523 return err;
2524 err = platform_driver_register(&it87_driver);
2525 if (err)
2526 return err;
2527
2528 err = it87_device_add(isa_address, &sio_data);
Jean Delvare5f2dc792010-03-05 22:17:18 +01002529 if (err) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002530 platform_driver_unregister(&it87_driver);
2531 return err;
2532 }
2533
2534 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535}
2536
2537static void __exit sm_it87_exit(void)
2538{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002539 platform_device_unregister(pdev);
2540 platform_driver_unregister(&it87_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541}
2542
2543
Guenter Roeck1d9bcf62012-12-19 22:17:01 +01002544MODULE_AUTHOR("Chris Gauthron, Jean Delvare <khali@linux-fr.org>");
Jean Delvare44c1bcd2010-10-28 20:31:51 +02002545MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546module_param(update_vbat, bool, 0);
2547MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
2548module_param(fix_pwm_polarity, bool, 0);
Jean Delvare5f2dc792010-03-05 22:17:18 +01002549MODULE_PARM_DESC(fix_pwm_polarity,
2550 "Force PWM polarity to active high (DANGEROUS)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551MODULE_LICENSE("GPL");
2552
2553module_init(sm_it87_init);
2554module_exit(sm_it87_exit);