blob: 80580cdf9a155a9dd6c7dbc7614851d03f139a8e [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 *
Rudolf Marekc145d5c2014-01-29 20:40:08 +010013 * Supports: IT8603E Super I/O chip w/LPC interface
Rudolf Marek574e9bd2014-04-04 18:01:35 +020014 * IT8623E Super I/O chip w/LPC interface
Rudolf Marekc145d5c2014-01-29 20:40:08 +010015 * IT8705F Super I/O chip w/LPC interface
Jean Delvare5f2dc792010-03-05 22:17:18 +010016 * IT8712F Super I/O chip w/LPC interface
17 * IT8716F Super I/O chip w/LPC interface
18 * IT8718F Super I/O chip w/LPC interface
19 * IT8720F Super I/O chip w/LPC interface
Jean Delvare44c1bcd2010-10-28 20:31:51 +020020 * IT8721F Super I/O chip w/LPC interface
Jean Delvare5f2dc792010-03-05 22:17:18 +010021 * IT8726F Super I/O chip w/LPC interface
Jean Delvare16b5dda2012-01-16 22:51:48 +010022 * IT8728F Super I/O chip w/LPC interface
Jean Delvare44c1bcd2010-10-28 20:31:51 +020023 * IT8758E Super I/O chip w/LPC interface
Guenter Roeckb0636702012-09-07 17:34:41 -060024 * IT8771E Super I/O chip w/LPC interface
25 * IT8772E Super I/O chip w/LPC interface
Guenter Roeck7bc32d22015-01-17 14:10:24 -080026 * IT8781F Super I/O chip w/LPC interface
Guenter Roeck0531d982012-03-02 11:46:44 -080027 * IT8782F Super I/O chip w/LPC interface
28 * IT8783E/F Super I/O chip w/LPC interface
Thomas Lorblanchesa0c14242015-02-13 13:19:06 +010029 * IT8786E Super I/O chip w/LPC interface
Guenter Roeck4ee07152015-03-25 23:26:28 -070030 * IT8790E Super I/O chip w/LPC interface
Jean Delvare5f2dc792010-03-05 22:17:18 +010031 * Sis950 A clone of the IT8705F
32 *
33 * Copyright (C) 2001 Chris Gauthron
Jean Delvare7c81c602014-01-29 20:40:08 +010034 * Copyright (C) 2005-2010 Jean Delvare <jdelvare@suse.de>
Jean Delvare5f2dc792010-03-05 22:17:18 +010035 *
36 * This program is free software; you can redistribute it and/or modify
37 * it under the terms of the GNU General Public License as published by
38 * the Free Software Foundation; either version 2 of the License, or
39 * (at your option) any later version.
40 *
41 * This program is distributed in the hope that it will be useful,
42 * but WITHOUT ANY WARRANTY; without even the implied warranty of
43 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
44 * GNU General Public License for more details.
45 *
46 * You should have received a copy of the GNU General Public License
47 * along with this program; if not, write to the Free Software
48 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
49 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Joe Perchesa8ca1032011-01-12 21:55:10 +010051#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
52
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include <linux/module.h>
54#include <linux/init.h>
55#include <linux/slab.h>
56#include <linux/jiffies.h>
corentin.labbeb74f3fd2007-06-13 20:27:36 +020057#include <linux/platform_device.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040058#include <linux/hwmon.h>
Jean Delvare303760b2005-07-31 21:52:01 +020059#include <linux/hwmon-sysfs.h>
60#include <linux/hwmon-vid.h>
Mark M. Hoffman943b0832005-07-15 21:39:18 -040061#include <linux/err.h>
Ingo Molnar9a61bf62006-01-18 23:19:26 +010062#include <linux/mutex.h>
Jean Delvare87808be2006-09-24 21:17:13 +020063#include <linux/sysfs.h>
Jean Delvare98dd22c2008-10-09 15:33:58 +020064#include <linux/string.h>
65#include <linux/dmi.h>
Jean Delvareb9acb642009-01-07 16:37:35 +010066#include <linux/acpi.h>
H Hartley Sweeten6055fae2009-09-15 17:18:13 +020067#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
corentin.labbeb74f3fd2007-06-13 20:27:36 +020069#define DRVNAME "it87"
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
Guenter Roeckb0636702012-09-07 17:34:41 -060071enum chips { it87, it8712, it8716, it8718, it8720, it8721, it8728, it8771,
Guenter Roeck4ee07152015-03-25 23:26:28 -070072 it8772, it8781, it8782, it8783, it8786, it8790, it8603 };
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Jean Delvare67b671b2007-12-06 23:13:42 +010074static unsigned short force_id;
75module_param(force_id, ushort, 0);
76MODULE_PARM_DESC(force_id, "Override the detected device ID");
77
corentin.labbeb74f3fd2007-06-13 20:27:36 +020078static struct platform_device *pdev;
79
Linus Torvalds1da177e2005-04-16 15:20:36 -070080#define REG 0x2e /* The register to read/write */
81#define DEV 0x07 /* Register: Logical device select */
82#define VAL 0x2f /* The value to read/write */
83#define PME 0x04 /* The device with the fan registers in it */
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +010084
85/* The device with the IT8718F/IT8720F VID value in it */
86#define GPIO 0x07
87
Linus Torvalds1da177e2005-04-16 15:20:36 -070088#define DEVID 0x20 /* Register: Device ID */
89#define DEVREV 0x22 /* Register: Device Revision */
90
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +020091static inline int superio_inb(int reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
93 outb(reg, REG);
94 return inb(VAL);
95}
96
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +020097static inline void superio_outb(int reg, int val)
Jean Delvare436cad22010-07-09 16:22:48 +020098{
99 outb(reg, REG);
100 outb(val, VAL);
101}
102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103static int superio_inw(int reg)
104{
105 int val;
106 outb(reg++, REG);
107 val = inb(VAL) << 8;
108 outb(reg, REG);
109 val |= inb(VAL);
110 return val;
111}
112
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +0200113static inline void superio_select(int ldn)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
115 outb(DEV, REG);
Jean Delvare87673dd2006-08-28 14:37:19 +0200116 outb(ldn, VAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117}
118
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +0200119static inline int superio_enter(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120{
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +0200121 /*
122 * Try to reserve REG and REG + 1 for exclusive access.
123 */
124 if (!request_muxed_region(REG, 2, DRVNAME))
125 return -EBUSY;
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 outb(0x87, REG);
128 outb(0x01, REG);
129 outb(0x55, REG);
130 outb(0x55, REG);
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +0200131 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132}
133
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +0200134static inline void superio_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135{
136 outb(0x02, REG);
137 outb(0x02, VAL);
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +0200138 release_region(REG, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139}
140
Jean Delvare87673dd2006-08-28 14:37:19 +0200141/* Logical device 4 registers */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142#define IT8712F_DEVID 0x8712
143#define IT8705F_DEVID 0x8705
Jean Delvare17d648b2006-08-28 14:23:46 +0200144#define IT8716F_DEVID 0x8716
Jean Delvare87673dd2006-08-28 14:37:19 +0200145#define IT8718F_DEVID 0x8718
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +0100146#define IT8720F_DEVID 0x8720
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200147#define IT8721F_DEVID 0x8721
Rudolf Marek08a8f6e2007-06-09 10:11:16 -0400148#define IT8726F_DEVID 0x8726
Jean Delvare16b5dda2012-01-16 22:51:48 +0100149#define IT8728F_DEVID 0x8728
Guenter Roeckb0636702012-09-07 17:34:41 -0600150#define IT8771E_DEVID 0x8771
151#define IT8772E_DEVID 0x8772
Guenter Roeck7bc32d22015-01-17 14:10:24 -0800152#define IT8781F_DEVID 0x8781
Guenter Roeck0531d982012-03-02 11:46:44 -0800153#define IT8782F_DEVID 0x8782
154#define IT8783E_DEVID 0x8783
Thomas Lorblanchesa0c14242015-02-13 13:19:06 +0100155#define IT8786E_DEVID 0x8786
Guenter Roeck4ee07152015-03-25 23:26:28 -0700156#define IT8790E_DEVID 0x8790
Rudolf Marek7183ae82014-04-04 18:01:35 +0200157#define IT8603E_DEVID 0x8603
Rudolf Marek574e9bd2014-04-04 18:01:35 +0200158#define IT8623E_DEVID 0x8623
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159#define IT87_ACT_REG 0x30
160#define IT87_BASE_REG 0x60
161
Jean Delvare87673dd2006-08-28 14:37:19 +0200162/* Logical device 7 registers (IT8712F and later) */
Guenter Roeck0531d982012-03-02 11:46:44 -0800163#define IT87_SIO_GPIO1_REG 0x25
Jean Delvare895ff262009-12-09 20:35:47 +0100164#define IT87_SIO_GPIO3_REG 0x27
Jean Delvare591ec652009-12-09 20:35:48 +0100165#define IT87_SIO_GPIO5_REG 0x29
Guenter Roeck0531d982012-03-02 11:46:44 -0800166#define IT87_SIO_PINX1_REG 0x2a /* Pin selection */
Jean Delvare87673dd2006-08-28 14:37:19 +0200167#define IT87_SIO_PINX2_REG 0x2c /* Pin selection */
Guenter Roeck0531d982012-03-02 11:46:44 -0800168#define IT87_SIO_SPI_REG 0xef /* SPI function pin select */
Jean Delvare87673dd2006-08-28 14:37:19 +0200169#define IT87_SIO_VID_REG 0xfc /* VID value */
Jean Delvared9b327c2010-03-05 22:17:17 +0100170#define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */
Jean Delvare87673dd2006-08-28 14:37:19 +0200171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172/* Update battery voltage after every reading if true */
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030173static bool update_vbat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175/* Not all BIOSes properly configure the PWM registers */
Rusty Russell90ab5ee2012-01-13 09:32:20 +1030176static bool fix_pwm_polarity;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178/* Many IT87 constants specified below */
179
180/* Length of ISA address segment */
181#define IT87_EXTENT 8
182
Bjorn Helgaas87b4b662008-01-22 07:21:03 -0500183/* Length of ISA address segment for Environmental Controller */
184#define IT87_EC_EXTENT 2
185
186/* Offset of EC registers from ISA base address */
187#define IT87_EC_OFFSET 5
188
189/* Where are the ISA address/data registers relative to the EC base address */
190#define IT87_ADDR_REG_OFFSET 0
191#define IT87_DATA_REG_OFFSET 1
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193/*----- The IT87 registers -----*/
194
195#define IT87_REG_CONFIG 0x00
196
197#define IT87_REG_ALARM1 0x01
198#define IT87_REG_ALARM2 0x02
199#define IT87_REG_ALARM3 0x03
200
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800201/*
202 * The IT8718F and IT8720F have the VID value in a different register, in
203 * Super-I/O configuration space.
204 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205#define IT87_REG_VID 0x0a
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800206/*
207 * The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b
208 * for fan divisors. Later IT8712F revisions must use 16-bit tachometer
209 * mode.
210 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211#define IT87_REG_FAN_DIV 0x0b
Jean Delvare17d648b2006-08-28 14:23:46 +0200212#define IT87_REG_FAN_16BIT 0x0c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214/* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */
215
Jean Delvarec7f1f712007-09-03 17:11:46 +0200216static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 };
217static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 };
218static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 };
219static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 };
Guenter Roeck161d8982012-12-19 22:17:01 +0100220static const u8 IT87_REG_TEMP_OFFSET[] = { 0x56, 0x57, 0x59 };
221
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222#define IT87_REG_FAN_MAIN_CTRL 0x13
223#define IT87_REG_FAN_CTL 0x14
224#define IT87_REG_PWM(nr) (0x15 + (nr))
Jean Delvare6229cdb2010-12-08 16:27:22 +0100225#define IT87_REG_PWM_DUTY(nr) (0x63 + (nr) * 8)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227#define IT87_REG_VIN(nr) (0x20 + (nr))
228#define IT87_REG_TEMP(nr) (0x29 + (nr))
229
230#define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2)
231#define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2)
232#define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2)
233#define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2)
234
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235#define IT87_REG_VIN_ENABLE 0x50
236#define IT87_REG_TEMP_ENABLE 0x51
Guenter Roeck4573acb2012-03-26 16:17:41 -0700237#define IT87_REG_TEMP_EXTRA 0x55
Jean Delvared9b327c2010-03-05 22:17:17 +0100238#define IT87_REG_BEEP_ENABLE 0x5c
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240#define IT87_REG_CHIPID 0x58
241
Jean Delvare4f3f51b2010-03-05 22:17:21 +0100242#define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i))
243#define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i))
244
Guenter Roeck483db432012-12-19 22:17:02 +0100245struct it87_devices {
246 const char *name;
Guenter Roeckfaf392f2015-03-26 08:36:18 -0700247 const char * const suffix;
Guenter Roeck483db432012-12-19 22:17:02 +0100248 u16 features;
Guenter Roeck19529782012-12-19 22:17:02 +0100249 u8 peci_mask;
250 u8 old_peci_mask;
Guenter Roeck483db432012-12-19 22:17:02 +0100251};
252
253#define FEAT_12MV_ADC (1 << 0)
254#define FEAT_NEWER_AUTOPWM (1 << 1)
255#define FEAT_OLD_AUTOPWM (1 << 2)
256#define FEAT_16BIT_FANS (1 << 3)
257#define FEAT_TEMP_OFFSET (1 << 4)
Guenter Roeck5d8d2f22012-12-19 22:17:02 +0100258#define FEAT_TEMP_PECI (1 << 5)
Guenter Roeck19529782012-12-19 22:17:02 +0100259#define FEAT_TEMP_OLD_PECI (1 << 6)
Guenter Roeck9faf28c2015-02-12 07:11:38 -0800260#define FEAT_FAN16_CONFIG (1 << 7) /* Need to enable 16-bit fans */
261#define FEAT_FIVE_FANS (1 << 8) /* Supports five fans */
Guenter Roeck32dd7c42015-02-12 07:40:23 -0800262#define FEAT_VID (1 << 9) /* Set if chip supports VID */
Guenter Roeck7f5726c2015-03-26 08:49:18 -0700263#define FEAT_IN7_INTERNAL (1 << 10) /* Set if in7 is internal */
Guenter Roeck483db432012-12-19 22:17:02 +0100264
265static const struct it87_devices it87_devices[] = {
266 [it87] = {
267 .name = "it87",
Guenter Roeckfaf392f2015-03-26 08:36:18 -0700268 .suffix = "F",
Guenter Roeck483db432012-12-19 22:17:02 +0100269 .features = FEAT_OLD_AUTOPWM, /* may need to overwrite */
270 },
271 [it8712] = {
272 .name = "it8712",
Guenter Roeckfaf392f2015-03-26 08:36:18 -0700273 .suffix = "F",
Guenter Roeck32dd7c42015-02-12 07:40:23 -0800274 .features = FEAT_OLD_AUTOPWM | FEAT_VID,
275 /* may need to overwrite */
Guenter Roeck483db432012-12-19 22:17:02 +0100276 },
277 [it8716] = {
278 .name = "it8716",
Guenter Roeckfaf392f2015-03-26 08:36:18 -0700279 .suffix = "F",
Guenter Roeck32dd7c42015-02-12 07:40:23 -0800280 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID
Guenter Roeck9faf28c2015-02-12 07:11:38 -0800281 | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS,
Guenter Roeck483db432012-12-19 22:17:02 +0100282 },
283 [it8718] = {
284 .name = "it8718",
Guenter Roeckfaf392f2015-03-26 08:36:18 -0700285 .suffix = "F",
Guenter Roeck32dd7c42015-02-12 07:40:23 -0800286 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID
Guenter Roeck9faf28c2015-02-12 07:11:38 -0800287 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS,
Guenter Roeck19529782012-12-19 22:17:02 +0100288 .old_peci_mask = 0x4,
Guenter Roeck483db432012-12-19 22:17:02 +0100289 },
290 [it8720] = {
291 .name = "it8720",
Guenter Roeckfaf392f2015-03-26 08:36:18 -0700292 .suffix = "F",
Guenter Roeck32dd7c42015-02-12 07:40:23 -0800293 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID
Guenter Roeck9faf28c2015-02-12 07:11:38 -0800294 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS,
Guenter Roeck19529782012-12-19 22:17:02 +0100295 .old_peci_mask = 0x4,
Guenter Roeck483db432012-12-19 22:17:02 +0100296 },
297 [it8721] = {
298 .name = "it8721",
Guenter Roeckfaf392f2015-03-26 08:36:18 -0700299 .suffix = "F",
Guenter Roeck483db432012-12-19 22:17:02 +0100300 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
Guenter Roeck9faf28c2015-02-12 07:11:38 -0800301 | FEAT_TEMP_OFFSET | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI
Guenter Roeck7f5726c2015-03-26 08:49:18 -0700302 | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS | FEAT_IN7_INTERNAL,
Guenter Roeck5d8d2f22012-12-19 22:17:02 +0100303 .peci_mask = 0x05,
Guenter Roeck19529782012-12-19 22:17:02 +0100304 .old_peci_mask = 0x02, /* Actually reports PCH */
Guenter Roeck483db432012-12-19 22:17:02 +0100305 },
306 [it8728] = {
307 .name = "it8728",
Guenter Roeckfaf392f2015-03-26 08:36:18 -0700308 .suffix = "F",
Guenter Roeck483db432012-12-19 22:17:02 +0100309 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
Guenter Roeck7f5726c2015-03-26 08:49:18 -0700310 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_FIVE_FANS
311 | FEAT_IN7_INTERNAL,
Guenter Roeck5d8d2f22012-12-19 22:17:02 +0100312 .peci_mask = 0x07,
Guenter Roeck483db432012-12-19 22:17:02 +0100313 },
Guenter Roeckb0636702012-09-07 17:34:41 -0600314 [it8771] = {
315 .name = "it8771",
Guenter Roeckfaf392f2015-03-26 08:36:18 -0700316 .suffix = "E",
Guenter Roeckb0636702012-09-07 17:34:41 -0600317 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
Guenter Roeck7f5726c2015-03-26 08:49:18 -0700318 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL,
Guenter Roeck9faf28c2015-02-12 07:11:38 -0800319 /* PECI: guesswork */
320 /* 12mV ADC (OHM) */
321 /* 16 bit fans (OHM) */
322 /* three fans, always 16 bit (guesswork) */
Guenter Roeckb0636702012-09-07 17:34:41 -0600323 .peci_mask = 0x07,
324 },
325 [it8772] = {
326 .name = "it8772",
Guenter Roeckfaf392f2015-03-26 08:36:18 -0700327 .suffix = "E",
Guenter Roeckb0636702012-09-07 17:34:41 -0600328 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
Guenter Roeck7f5726c2015-03-26 08:49:18 -0700329 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL,
Guenter Roeck9faf28c2015-02-12 07:11:38 -0800330 /* PECI (coreboot) */
331 /* 12mV ADC (HWSensors4, OHM) */
332 /* 16 bit fans (HWSensors4, OHM) */
333 /* three fans, always 16 bit (datasheet) */
Guenter Roeckb0636702012-09-07 17:34:41 -0600334 .peci_mask = 0x07,
335 },
Guenter Roeck7bc32d22015-01-17 14:10:24 -0800336 [it8781] = {
337 .name = "it8781",
Guenter Roeckfaf392f2015-03-26 08:36:18 -0700338 .suffix = "F",
Guenter Roeck7bc32d22015-01-17 14:10:24 -0800339 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
Guenter Roeck9faf28c2015-02-12 07:11:38 -0800340 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG,
Guenter Roeck7bc32d22015-01-17 14:10:24 -0800341 .old_peci_mask = 0x4,
342 },
Guenter Roeck483db432012-12-19 22:17:02 +0100343 [it8782] = {
344 .name = "it8782",
Guenter Roeckfaf392f2015-03-26 08:36:18 -0700345 .suffix = "F",
Guenter Roeck19529782012-12-19 22:17:02 +0100346 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
Guenter Roeck9faf28c2015-02-12 07:11:38 -0800347 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG,
Guenter Roeck19529782012-12-19 22:17:02 +0100348 .old_peci_mask = 0x4,
Guenter Roeck483db432012-12-19 22:17:02 +0100349 },
350 [it8783] = {
351 .name = "it8783",
Guenter Roeckfaf392f2015-03-26 08:36:18 -0700352 .suffix = "E/F",
Guenter Roeck19529782012-12-19 22:17:02 +0100353 .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET
Guenter Roeck9faf28c2015-02-12 07:11:38 -0800354 | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG,
Guenter Roeck19529782012-12-19 22:17:02 +0100355 .old_peci_mask = 0x4,
Guenter Roeck483db432012-12-19 22:17:02 +0100356 },
Thomas Lorblanchesa0c14242015-02-13 13:19:06 +0100357 [it8786] = {
358 .name = "it8786",
Guenter Roeckfaf392f2015-03-26 08:36:18 -0700359 .suffix = "E",
Thomas Lorblanchesa0c14242015-02-13 13:19:06 +0100360 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
Guenter Roeck7f5726c2015-03-26 08:49:18 -0700361 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL,
Thomas Lorblanchesa0c14242015-02-13 13:19:06 +0100362 .peci_mask = 0x07,
363 },
Guenter Roeck4ee07152015-03-25 23:26:28 -0700364 [it8790] = {
365 .name = "it8790",
366 .suffix = "E",
367 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
368 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL,
369 .peci_mask = 0x07,
370 },
Rudolf Marekc145d5c2014-01-29 20:40:08 +0100371 [it8603] = {
372 .name = "it8603",
Guenter Roeckfaf392f2015-03-26 08:36:18 -0700373 .suffix = "E",
Rudolf Marekc145d5c2014-01-29 20:40:08 +0100374 .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS
Guenter Roeck7f5726c2015-03-26 08:49:18 -0700375 | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL,
Rudolf Marekc145d5c2014-01-29 20:40:08 +0100376 .peci_mask = 0x07,
377 },
Guenter Roeck483db432012-12-19 22:17:02 +0100378};
379
380#define has_16bit_fans(data) ((data)->features & FEAT_16BIT_FANS)
381#define has_12mv_adc(data) ((data)->features & FEAT_12MV_ADC)
382#define has_newer_autopwm(data) ((data)->features & FEAT_NEWER_AUTOPWM)
383#define has_old_autopwm(data) ((data)->features & FEAT_OLD_AUTOPWM)
384#define has_temp_offset(data) ((data)->features & FEAT_TEMP_OFFSET)
Guenter Roeck5d8d2f22012-12-19 22:17:02 +0100385#define has_temp_peci(data, nr) (((data)->features & FEAT_TEMP_PECI) && \
386 ((data)->peci_mask & (1 << nr)))
Guenter Roeck19529782012-12-19 22:17:02 +0100387#define has_temp_old_peci(data, nr) \
388 (((data)->features & FEAT_TEMP_OLD_PECI) && \
389 ((data)->old_peci_mask & (1 << nr)))
Guenter Roeck9faf28c2015-02-12 07:11:38 -0800390#define has_fan16_config(data) ((data)->features & FEAT_FAN16_CONFIG)
391#define has_five_fans(data) ((data)->features & FEAT_FIVE_FANS)
Guenter Roeck32dd7c42015-02-12 07:40:23 -0800392#define has_vid(data) ((data)->features & FEAT_VID)
Guenter Roeck7f5726c2015-03-26 08:49:18 -0700393#define has_in7_internal(data) ((data)->features & FEAT_IN7_INTERNAL)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200395struct it87_sio_data {
396 enum chips type;
397 /* Values read from Super-I/O config space */
Andrew Paprocki04751692008-08-06 22:41:06 +0200398 u8 revision;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200399 u8 vid_value;
Jean Delvared9b327c2010-03-05 22:17:17 +0100400 u8 beep_pin;
Jean Delvare738e5e02010-08-14 21:08:50 +0200401 u8 internal; /* Internal sensors can be labeled */
Jean Delvare591ec652009-12-09 20:35:48 +0100402 /* Features skipped based on config or DMI */
Guenter Roeck9172b5d2012-03-24 21:49:54 -0700403 u16 skip_in;
Jean Delvare895ff262009-12-09 20:35:47 +0100404 u8 skip_vid;
Jean Delvare591ec652009-12-09 20:35:48 +0100405 u8 skip_fan;
Jean Delvare98dd22c2008-10-09 15:33:58 +0200406 u8 skip_pwm;
Guenter Roeck4573acb2012-03-26 16:17:41 -0700407 u8 skip_temp;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200408};
409
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800410/*
411 * For each registered chip, we need to keep some data in memory.
412 * The structure is dynamically allocated.
413 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414struct it87_data {
Tony Jones1beeffe2007-08-20 13:46:20 -0700415 struct device *hwmon_dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 enum chips type;
Guenter Roeck483db432012-12-19 22:17:02 +0100417 u16 features;
Guenter Roeck19529782012-12-19 22:17:02 +0100418 u8 peci_mask;
419 u8 old_peci_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200421 unsigned short addr;
422 const char *name;
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100423 struct mutex update_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 char valid; /* !=0 if following fields are valid */
425 unsigned long last_updated; /* In jiffies */
426
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200427 u16 in_scaled; /* Internal voltage sensors are scaled */
Rudolf Marekc145d5c2014-01-29 20:40:08 +0100428 u8 in[10][3]; /* [nr][0]=in, [1]=min, [2]=max */
Jean Delvare9060f8b2006-08-28 14:24:17 +0200429 u8 has_fan; /* Bitfield, fans enabled */
Guenter Roecke1169ba2012-12-19 22:17:01 +0100430 u16 fan[5][2]; /* Register values, [nr][0]=fan, [1]=min */
Guenter Roeck4573acb2012-03-26 16:17:41 -0700431 u8 has_temp; /* Bitfield, temp sensors enabled */
Guenter Roeck161d8982012-12-19 22:17:01 +0100432 s8 temp[3][4]; /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */
Guenter Roeck19529782012-12-19 22:17:02 +0100433 u8 sensor; /* Register value (IT87_REG_TEMP_ENABLE) */
434 u8 extra; /* Register value (IT87_REG_TEMP_EXTRA) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435 u8 fan_div[3]; /* Register encoding, shifted right */
436 u8 vid; /* Register encoding, combined */
Jean Delvarea7be58a2005-12-18 16:40:14 +0100437 u8 vrm;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 u32 alarms; /* Register encoding, combined */
Jean Delvared9b327c2010-03-05 22:17:17 +0100439 u8 beeps; /* Register encoding */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 u8 fan_main_ctrl; /* Register value */
Jean Delvaref8d0c192007-02-14 21:15:02 +0100441 u8 fan_ctl; /* Register value */
Jean Delvareb99883d2010-03-05 22:17:15 +0100442
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800443 /*
444 * The following 3 arrays correspond to the same registers up to
Jean Delvare6229cdb2010-12-08 16:27:22 +0100445 * the IT8720F. The meaning of bits 6-0 depends on the value of bit
446 * 7, and we want to preserve settings on mode changes, so we have
447 * to track all values separately.
448 * Starting with the IT8721F, the manual PWM duty cycles are stored
449 * in separate registers (8-bit values), so the separate tracking
450 * is no longer needed, but it is still done to keep the driver
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800451 * simple.
452 */
Jean Delvareb99883d2010-03-05 22:17:15 +0100453 u8 pwm_ctrl[3]; /* Register value */
Jean Delvare6229cdb2010-12-08 16:27:22 +0100454 u8 pwm_duty[3]; /* Manual PWM value set by user */
Jean Delvareb99883d2010-03-05 22:17:15 +0100455 u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */
Jean Delvare4f3f51b2010-03-05 22:17:21 +0100456
457 /* Automatic fan speed control registers */
458 u8 auto_pwm[3][4]; /* [nr][3] is hard-coded */
459 s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460};
461
Guenter Roeck0531d982012-03-02 11:46:44 -0800462static int adc_lsb(const struct it87_data *data, int nr)
463{
464 int lsb = has_12mv_adc(data) ? 12 : 16;
465 if (data->in_scaled & (1 << nr))
466 lsb <<= 1;
467 return lsb;
468}
469
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200470static u8 in_to_reg(const struct it87_data *data, int nr, long val)
471{
Guenter Roeck0531d982012-03-02 11:46:44 -0800472 val = DIV_ROUND_CLOSEST(val, adc_lsb(data, nr));
Guenter Roeck2a844c12013-01-09 08:09:34 -0800473 return clamp_val(val, 0, 255);
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200474}
475
476static int in_from_reg(const struct it87_data *data, int nr, int val)
477{
Guenter Roeck0531d982012-03-02 11:46:44 -0800478 return val * adc_lsb(data, nr);
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200479}
Jean Delvare0df6454d2010-10-28 20:31:51 +0200480
481static inline u8 FAN_TO_REG(long rpm, int div)
482{
483 if (rpm == 0)
484 return 255;
Guenter Roeck2a844c12013-01-09 08:09:34 -0800485 rpm = clamp_val(rpm, 1, 1000000);
486 return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254);
Jean Delvare0df6454d2010-10-28 20:31:51 +0200487}
488
489static inline u16 FAN16_TO_REG(long rpm)
490{
491 if (rpm == 0)
492 return 0xffff;
Guenter Roeck2a844c12013-01-09 08:09:34 -0800493 return clamp_val((1350000 + rpm) / (rpm * 2), 1, 0xfffe);
Jean Delvare0df6454d2010-10-28 20:31:51 +0200494}
495
496#define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \
497 1350000 / ((val) * (div)))
498/* The divider is fixed to 2 in 16-bit mode */
499#define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \
500 1350000 / ((val) * 2))
501
Guenter Roeck2a844c12013-01-09 08:09:34 -0800502#define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (((val) - 500) / 1000) : \
503 ((val) + 500) / 1000), -128, 127))
Jean Delvare0df6454d2010-10-28 20:31:51 +0200504#define TEMP_FROM_REG(val) ((val) * 1000)
505
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200506static u8 pwm_to_reg(const struct it87_data *data, long val)
507{
Jean Delvare16b5dda2012-01-16 22:51:48 +0100508 if (has_newer_autopwm(data))
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200509 return val;
510 else
511 return val >> 1;
512}
513
514static int pwm_from_reg(const struct it87_data *data, u8 reg)
515{
Jean Delvare16b5dda2012-01-16 22:51:48 +0100516 if (has_newer_autopwm(data))
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200517 return reg;
518 else
519 return (reg & 0x7f) << 1;
520}
521
Jean Delvare0df6454d2010-10-28 20:31:51 +0200522
523static int DIV_TO_REG(int val)
524{
525 int answer = 0;
526 while (answer < 7 && (val >>= 1))
527 answer++;
528 return answer;
529}
530#define DIV_FROM_REG(val) (1 << (val))
531
Guenter Roeckf56c9c02015-03-26 20:01:24 -0700532/*
533 * PWM base frequencies. The frequency has to be divided by either 128 or 256,
534 * depending on the chip type, to calculate the actual PWM frequency.
535 *
536 * Some of the chip datasheets suggest a base frequency of 51 kHz instead
537 * of 750 kHz for the slowest base frequency, resulting in a PWM frequency
538 * of 200 Hz. Sometimes both PWM frequency select registers are affected,
539 * sometimes just one. It is unknown if this is a datasheet error or real,
540 * so this is ignored for now.
541 */
Jean Delvare0df6454d2010-10-28 20:31:51 +0200542static const unsigned int pwm_freq[8] = {
Guenter Roeckf56c9c02015-03-26 20:01:24 -0700543 48000000,
544 24000000,
545 12000000,
546 8000000,
547 6000000,
548 3000000,
549 1500000,
550 750000,
Jean Delvare0df6454d2010-10-28 20:31:51 +0200551};
552
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200553static int it87_probe(struct platform_device *pdev);
Bill Pemberton281dfd02012-11-19 13:25:51 -0500554static int it87_remove(struct platform_device *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200556static int it87_read_value(struct it87_data *data, u8 reg);
557static void it87_write_value(struct it87_data *data, u8 reg, u8 value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558static struct it87_data *it87_update_device(struct device *dev);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200559static int it87_check_pwm(struct device *dev);
560static void it87_init_device(struct platform_device *pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
562
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200563static struct platform_driver it87_driver = {
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100564 .driver = {
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200565 .name = DRVNAME,
Laurent Riffardcdaf7932005-11-26 20:37:41 +0100566 },
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200567 .probe = it87_probe,
Bill Pemberton9e5e9b72012-11-19 13:21:20 -0500568 .remove = it87_remove,
Jean Delvarefde09502005-07-19 23:51:07 +0200569};
570
Jean Delvare20ad93d2005-06-05 11:53:25 +0200571static ssize_t show_in(struct device *dev, struct device_attribute *attr,
Guenter Roeck929c6a52012-12-19 22:17:00 +0100572 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573{
Guenter Roeck929c6a52012-12-19 22:17:00 +0100574 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
575 int nr = sattr->nr;
576 int index = sattr->index;
Jean Delvare20ad93d2005-06-05 11:53:25 +0200577
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578 struct it87_data *data = it87_update_device(dev);
Guenter Roeck929c6a52012-12-19 22:17:00 +0100579 return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580}
581
Guenter Roeck929c6a52012-12-19 22:17:00 +0100582static ssize_t set_in(struct device *dev, struct device_attribute *attr,
583 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
Guenter Roeck929c6a52012-12-19 22:17:00 +0100585 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
586 int nr = sattr->nr;
587 int index = sattr->index;
Jean Delvare20ad93d2005-06-05 11:53:25 +0200588
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200589 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100590 unsigned long val;
591
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100592 if (kstrtoul(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +0100593 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100595 mutex_lock(&data->update_lock);
Guenter Roeck929c6a52012-12-19 22:17:00 +0100596 data->in[nr][index] = in_to_reg(data, nr, val);
597 it87_write_value(data,
598 index == 1 ? IT87_REG_VIN_MIN(nr)
599 : IT87_REG_VIN_MAX(nr),
600 data->in[nr][index]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100601 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 return count;
603}
604
Guenter Roeck929c6a52012-12-19 22:17:00 +0100605static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0);
606static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in,
607 0, 1);
608static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in,
609 0, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Guenter Roeck929c6a52012-12-19 22:17:00 +0100611static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0);
612static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in,
613 1, 1);
614static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in,
615 1, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Guenter Roeck929c6a52012-12-19 22:17:00 +0100617static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0);
618static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in,
619 2, 1);
620static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in,
621 2, 2);
622
623static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0);
624static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in,
625 3, 1);
626static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in,
627 3, 2);
628
629static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0);
630static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in,
631 4, 1);
632static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in,
633 4, 2);
634
635static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, 0);
636static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in,
637 5, 1);
638static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in,
639 5, 2);
640
641static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 6, 0);
642static SENSOR_DEVICE_ATTR_2(in6_min, S_IRUGO | S_IWUSR, show_in, set_in,
643 6, 1);
644static SENSOR_DEVICE_ATTR_2(in6_max, S_IRUGO | S_IWUSR, show_in, set_in,
645 6, 2);
646
647static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 7, 0);
648static SENSOR_DEVICE_ATTR_2(in7_min, S_IRUGO | S_IWUSR, show_in, set_in,
649 7, 1);
650static SENSOR_DEVICE_ATTR_2(in7_max, S_IRUGO | S_IWUSR, show_in, set_in,
651 7, 2);
652
653static SENSOR_DEVICE_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 8, 0);
Rudolf Marekc145d5c2014-01-29 20:40:08 +0100654static SENSOR_DEVICE_ATTR_2(in9_input, S_IRUGO, show_in, NULL, 9, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655
656/* 3 temperatures */
Jean Delvare20ad93d2005-06-05 11:53:25 +0200657static ssize_t show_temp(struct device *dev, struct device_attribute *attr,
Guenter Roeck60ca3852012-12-19 22:17:00 +0100658 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659{
Guenter Roeck60ca3852012-12-19 22:17:00 +0100660 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
661 int nr = sattr->nr;
662 int index = sattr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 struct it87_data *data = it87_update_device(dev);
Jean Delvare20ad93d2005-06-05 11:53:25 +0200664
Guenter Roeck60ca3852012-12-19 22:17:00 +0100665 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200667
Guenter Roeck60ca3852012-12-19 22:17:00 +0100668static ssize_t set_temp(struct device *dev, struct device_attribute *attr,
669 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670{
Guenter Roeck60ca3852012-12-19 22:17:00 +0100671 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
672 int nr = sattr->nr;
673 int index = sattr->index;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200674 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100675 long val;
Guenter Roeck161d8982012-12-19 22:17:01 +0100676 u8 reg, regval;
Jean Delvaref5f64502010-03-05 22:17:19 +0100677
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100678 if (kstrtol(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +0100679 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100681 mutex_lock(&data->update_lock);
Guenter Roeck161d8982012-12-19 22:17:01 +0100682
683 switch (index) {
684 default:
685 case 1:
686 reg = IT87_REG_TEMP_LOW(nr);
687 break;
688 case 2:
689 reg = IT87_REG_TEMP_HIGH(nr);
690 break;
691 case 3:
692 regval = it87_read_value(data, IT87_REG_BEEP_ENABLE);
693 if (!(regval & 0x80)) {
694 regval |= 0x80;
695 it87_write_value(data, IT87_REG_BEEP_ENABLE, regval);
696 }
697 data->valid = 0;
698 reg = IT87_REG_TEMP_OFFSET[nr];
699 break;
700 }
701
Guenter Roeck60ca3852012-12-19 22:17:00 +0100702 data->temp[nr][index] = TEMP_TO_REG(val);
Guenter Roeck161d8982012-12-19 22:17:01 +0100703 it87_write_value(data, reg, data->temp[nr][index]);
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100704 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 return count;
706}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200707
Guenter Roeck60ca3852012-12-19 22:17:00 +0100708static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0);
709static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
710 0, 1);
711static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
712 0, 2);
Guenter Roeck161d8982012-12-19 22:17:01 +0100713static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp,
714 set_temp, 0, 3);
Guenter Roeck60ca3852012-12-19 22:17:00 +0100715static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0);
716static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
717 1, 1);
718static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
719 1, 2);
Guenter Roeck161d8982012-12-19 22:17:01 +0100720static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp,
721 set_temp, 1, 3);
Guenter Roeck60ca3852012-12-19 22:17:00 +0100722static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, 0);
723static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp,
724 2, 1);
725static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp,
726 2, 2);
Guenter Roeck161d8982012-12-19 22:17:01 +0100727static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp,
728 set_temp, 2, 3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729
Guenter Roeck2cece012012-12-19 22:17:01 +0100730static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr,
731 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200733 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
734 int nr = sensor_attr->index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 struct it87_data *data = it87_update_device(dev);
Guenter Roeck4a0d71c2012-01-19 11:02:18 -0800736 u8 reg = data->sensor; /* In case value is updated while used */
Guenter Roeck19529782012-12-19 22:17:02 +0100737 u8 extra = data->extra;
Jean Delvare5f2dc792010-03-05 22:17:18 +0100738
Guenter Roeck19529782012-12-19 22:17:02 +0100739 if ((has_temp_peci(data, nr) && (reg >> 6 == nr + 1))
740 || (has_temp_old_peci(data, nr) && (extra & 0x80)))
Guenter Roeck5d8d2f22012-12-19 22:17:02 +0100741 return sprintf(buf, "6\n"); /* Intel PECI */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742 if (reg & (1 << nr))
743 return sprintf(buf, "3\n"); /* thermal diode */
744 if (reg & (8 << nr))
Jean Delvare4ed10772008-10-17 17:51:16 +0200745 return sprintf(buf, "4\n"); /* thermistor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 return sprintf(buf, "0\n"); /* disabled */
747}
Guenter Roeck2cece012012-12-19 22:17:01 +0100748
749static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr,
750 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200752 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
753 int nr = sensor_attr->index;
754
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200755 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100756 long val;
Guenter Roeck19529782012-12-19 22:17:02 +0100757 u8 reg, extra;
Jean Delvaref5f64502010-03-05 22:17:19 +0100758
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100759 if (kstrtol(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +0100760 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761
Jean Delvare8acf07c2010-04-14 16:14:09 +0200762 reg = it87_read_value(data, IT87_REG_TEMP_ENABLE);
763 reg &= ~(1 << nr);
764 reg &= ~(8 << nr);
Guenter Roeck5d8d2f22012-12-19 22:17:02 +0100765 if (has_temp_peci(data, nr) && (reg >> 6 == nr + 1 || val == 6))
766 reg &= 0x3f;
Guenter Roeck19529782012-12-19 22:17:02 +0100767 extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
768 if (has_temp_old_peci(data, nr) && ((extra & 0x80) || val == 6))
769 extra &= 0x7f;
Jean Delvare4ed10772008-10-17 17:51:16 +0200770 if (val == 2) { /* backwards compatibility */
Guenter Roeck1d9bcf62012-12-19 22:17:01 +0100771 dev_warn(dev,
772 "Sensor type 2 is deprecated, please use 4 instead\n");
Jean Delvare4ed10772008-10-17 17:51:16 +0200773 val = 4;
774 }
Guenter Roeck5d8d2f22012-12-19 22:17:02 +0100775 /* 3 = thermal diode; 4 = thermistor; 6 = Intel PECI; 0 = disabled */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776 if (val == 3)
Jean Delvare8acf07c2010-04-14 16:14:09 +0200777 reg |= 1 << nr;
Jean Delvare4ed10772008-10-17 17:51:16 +0200778 else if (val == 4)
Jean Delvare8acf07c2010-04-14 16:14:09 +0200779 reg |= 8 << nr;
Guenter Roeck5d8d2f22012-12-19 22:17:02 +0100780 else if (has_temp_peci(data, nr) && val == 6)
781 reg |= (nr + 1) << 6;
Guenter Roeck19529782012-12-19 22:17:02 +0100782 else if (has_temp_old_peci(data, nr) && val == 6)
783 extra |= 0x80;
Jean Delvare8acf07c2010-04-14 16:14:09 +0200784 else if (val != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 return -EINVAL;
Jean Delvare8acf07c2010-04-14 16:14:09 +0200786
787 mutex_lock(&data->update_lock);
788 data->sensor = reg;
Guenter Roeck19529782012-12-19 22:17:02 +0100789 data->extra = extra;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200790 it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor);
Guenter Roeck19529782012-12-19 22:17:02 +0100791 if (has_temp_old_peci(data, nr))
792 it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra);
Jean Delvare2b3d1d82010-04-14 16:14:10 +0200793 data->valid = 0; /* Force cache refresh */
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100794 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 return count;
796}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
Guenter Roeck2cece012012-12-19 22:17:01 +0100798static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR, show_temp_type,
799 set_temp_type, 0);
800static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type,
801 set_temp_type, 1);
802static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type,
803 set_temp_type, 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804
805/* 3 Fans */
Jean Delvareb99883d2010-03-05 22:17:15 +0100806
807static int pwm_mode(const struct it87_data *data, int nr)
808{
809 int ctrl = data->fan_main_ctrl & (1 << nr);
810
Rudolf Marekc145d5c2014-01-29 20:40:08 +0100811 if (ctrl == 0 && data->type != it8603) /* Full speed */
Jean Delvareb99883d2010-03-05 22:17:15 +0100812 return 0;
813 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
814 return 2;
815 else /* Manual mode */
816 return 1;
817}
818
Jean Delvare20ad93d2005-06-05 11:53:25 +0200819static ssize_t show_fan(struct device *dev, struct device_attribute *attr,
Guenter Roecke1169ba2012-12-19 22:17:01 +0100820 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
Guenter Roecke1169ba2012-12-19 22:17:01 +0100822 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
823 int nr = sattr->nr;
824 int index = sattr->index;
825 int speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 struct it87_data *data = it87_update_device(dev);
Jean Delvare20ad93d2005-06-05 11:53:25 +0200827
Guenter Roecke1169ba2012-12-19 22:17:01 +0100828 speed = has_16bit_fans(data) ?
829 FAN16_FROM_REG(data->fan[nr][index]) :
830 FAN_FROM_REG(data->fan[nr][index],
831 DIV_FROM_REG(data->fan_div[nr]));
832 return sprintf(buf, "%d\n", speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833}
Guenter Roecke1169ba2012-12-19 22:17:01 +0100834
Jean Delvare20ad93d2005-06-05 11:53:25 +0200835static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr,
836 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200838 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
839 int nr = sensor_attr->index;
840
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 struct it87_data *data = it87_update_device(dev);
842 return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr]));
843}
Jean Delvare5f2dc792010-03-05 22:17:18 +0100844static ssize_t show_pwm_enable(struct device *dev,
845 struct device_attribute *attr, char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200847 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
848 int nr = sensor_attr->index;
849
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 struct it87_data *data = it87_update_device(dev);
Jean Delvareb99883d2010-03-05 22:17:15 +0100851 return sprintf(buf, "%d\n", pwm_mode(data, nr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852}
Jean Delvare20ad93d2005-06-05 11:53:25 +0200853static ssize_t show_pwm(struct device *dev, struct device_attribute *attr,
854 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200856 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
857 int nr = sensor_attr->index;
858
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 struct it87_data *data = it87_update_device(dev);
Jean Delvare44c1bcd2010-10-28 20:31:51 +0200860 return sprintf(buf, "%d\n",
861 pwm_from_reg(data, data->pwm_duty[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862}
Jean Delvaref8d0c192007-02-14 21:15:02 +0100863static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr,
864 char *buf)
865{
866 struct it87_data *data = it87_update_device(dev);
867 int index = (data->fan_ctl >> 4) & 0x07;
Guenter Roeckf56c9c02015-03-26 20:01:24 -0700868 unsigned int freq;
Jean Delvaref8d0c192007-02-14 21:15:02 +0100869
Guenter Roeckf56c9c02015-03-26 20:01:24 -0700870 freq = pwm_freq[index] / (has_newer_autopwm(data) ? 256 : 128);
871
872 return sprintf(buf, "%u\n", freq);
Jean Delvaref8d0c192007-02-14 21:15:02 +0100873}
Guenter Roecke1169ba2012-12-19 22:17:01 +0100874
875static ssize_t set_fan(struct device *dev, struct device_attribute *attr,
876 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877{
Guenter Roecke1169ba2012-12-19 22:17:01 +0100878 struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
879 int nr = sattr->nr;
880 int index = sattr->index;
Jean Delvare20ad93d2005-06-05 11:53:25 +0200881
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200882 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100883 long val;
Jean Delvare7f999aa2007-02-14 21:15:03 +0100884 u8 reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100886 if (kstrtol(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +0100887 return -EINVAL;
888
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100889 mutex_lock(&data->update_lock);
Guenter Roecke1169ba2012-12-19 22:17:01 +0100890
891 if (has_16bit_fans(data)) {
892 data->fan[nr][index] = FAN16_TO_REG(val);
893 it87_write_value(data, IT87_REG_FAN_MIN[nr],
894 data->fan[nr][index] & 0xff);
895 it87_write_value(data, IT87_REG_FANX_MIN[nr],
896 data->fan[nr][index] >> 8);
897 } else {
898 reg = it87_read_value(data, IT87_REG_FAN_DIV);
899 switch (nr) {
900 case 0:
901 data->fan_div[nr] = reg & 0x07;
902 break;
903 case 1:
904 data->fan_div[nr] = (reg >> 3) & 0x07;
905 break;
906 case 2:
907 data->fan_div[nr] = (reg & 0x40) ? 3 : 1;
908 break;
909 }
910 data->fan[nr][index] =
911 FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr]));
912 it87_write_value(data, IT87_REG_FAN_MIN[nr],
913 data->fan[nr][index]);
Jean Delvare07eab462005-11-23 15:44:31 -0800914 }
915
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100916 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 return count;
918}
Guenter Roecke1169ba2012-12-19 22:17:01 +0100919
Jean Delvare20ad93d2005-06-05 11:53:25 +0200920static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr,
921 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200923 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
924 int nr = sensor_attr->index;
925
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200926 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100927 unsigned long val;
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200928 int min;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 u8 old;
930
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +0100931 if (kstrtoul(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +0100932 return -EINVAL;
933
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100934 mutex_lock(&data->update_lock);
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200935 old = it87_read_value(data, IT87_REG_FAN_DIV);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200937 /* Save fan min limit */
Guenter Roecke1169ba2012-12-19 22:17:01 +0100938 min = FAN_FROM_REG(data->fan[nr][1], DIV_FROM_REG(data->fan_div[nr]));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939
940 switch (nr) {
941 case 0:
942 case 1:
943 data->fan_div[nr] = DIV_TO_REG(val);
944 break;
945 case 2:
946 if (val < 8)
947 data->fan_div[nr] = 1;
948 else
949 data->fan_div[nr] = 3;
950 }
951 val = old & 0x80;
952 val |= (data->fan_div[0] & 0x07);
953 val |= (data->fan_div[1] & 0x07) << 3;
954 if (data->fan_div[2] == 3)
955 val |= 0x1 << 6;
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200956 it87_write_value(data, IT87_REG_FAN_DIV, val);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200958 /* Restore fan min limit */
Guenter Roecke1169ba2012-12-19 22:17:01 +0100959 data->fan[nr][1] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr]));
960 it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan[nr][1]);
Jean Delvare8ab4ec32006-08-28 14:35:46 +0200961
Ingo Molnar9a61bf62006-01-18 23:19:26 +0100962 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963 return count;
964}
Jean Delvarecccfc9c2010-03-05 22:17:21 +0100965
966/* Returns 0 if OK, -EINVAL otherwise */
967static int check_trip_points(struct device *dev, int nr)
968{
969 const struct it87_data *data = dev_get_drvdata(dev);
970 int i, err = 0;
971
972 if (has_old_autopwm(data)) {
973 for (i = 0; i < 3; i++) {
974 if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1])
975 err = -EINVAL;
976 }
977 for (i = 0; i < 2; i++) {
978 if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1])
979 err = -EINVAL;
980 }
981 }
982
983 if (err) {
Guenter Roeck1d9bcf62012-12-19 22:17:01 +0100984 dev_err(dev,
985 "Inconsistent trip points, not switching to automatic mode\n");
Jean Delvarecccfc9c2010-03-05 22:17:21 +0100986 dev_err(dev, "Adjust the trip points and try again\n");
987 }
988 return err;
989}
990
Jean Delvare20ad93d2005-06-05 11:53:25 +0200991static ssize_t set_pwm_enable(struct device *dev,
992 struct device_attribute *attr, const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993{
Jean Delvare20ad93d2005-06-05 11:53:25 +0200994 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
995 int nr = sensor_attr->index;
996
corentin.labbeb74f3fd2007-06-13 20:27:36 +0200997 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +0100998 long val;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700999
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001000 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 2)
Jean Delvareb99883d2010-03-05 22:17:15 +01001001 return -EINVAL;
1002
Jean Delvarecccfc9c2010-03-05 22:17:21 +01001003 /* Check trip points before switching to automatic mode */
1004 if (val == 2) {
1005 if (check_trip_points(dev, nr) < 0)
1006 return -EINVAL;
1007 }
1008
Rudolf Marekc145d5c2014-01-29 20:40:08 +01001009 /* IT8603E does not have on/off mode */
1010 if (val == 0 && data->type == it8603)
1011 return -EINVAL;
1012
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001013 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
1015 if (val == 0) {
1016 int tmp;
1017 /* make sure the fan is on when in on/off mode */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001018 tmp = it87_read_value(data, IT87_REG_FAN_CTL);
1019 it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 /* set on/off mode */
1021 data->fan_main_ctrl &= ~(1 << nr);
Jean Delvare5f2dc792010-03-05 22:17:18 +01001022 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
1023 data->fan_main_ctrl);
Jean Delvareb99883d2010-03-05 22:17:15 +01001024 } else {
1025 if (val == 1) /* Manual mode */
Jean Delvare16b5dda2012-01-16 22:51:48 +01001026 data->pwm_ctrl[nr] = has_newer_autopwm(data) ?
Jean Delvare6229cdb2010-12-08 16:27:22 +01001027 data->pwm_temp_map[nr] :
1028 data->pwm_duty[nr];
Jean Delvareb99883d2010-03-05 22:17:15 +01001029 else /* Automatic mode */
1030 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
1031 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
Rudolf Marekc145d5c2014-01-29 20:40:08 +01001032
1033 if (data->type != it8603) {
1034 /* set SmartGuardian mode */
1035 data->fan_main_ctrl |= (1 << nr);
1036 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
1037 data->fan_main_ctrl);
1038 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039 }
1040
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001041 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 return count;
1043}
Jean Delvare20ad93d2005-06-05 11:53:25 +02001044static ssize_t set_pwm(struct device *dev, struct device_attribute *attr,
1045 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046{
Jean Delvare20ad93d2005-06-05 11:53:25 +02001047 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1048 int nr = sensor_attr->index;
1049
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001050 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +01001051 long val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001053 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 return -EINVAL;
1055
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001056 mutex_lock(&data->update_lock);
Jean Delvare16b5dda2012-01-16 22:51:48 +01001057 if (has_newer_autopwm(data)) {
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08001058 /*
1059 * If we are in automatic mode, the PWM duty cycle register
1060 * is read-only so we can't write the value.
1061 */
Jean Delvare6229cdb2010-12-08 16:27:22 +01001062 if (data->pwm_ctrl[nr] & 0x80) {
1063 mutex_unlock(&data->update_lock);
1064 return -EBUSY;
1065 }
1066 data->pwm_duty[nr] = pwm_to_reg(data, val);
1067 it87_write_value(data, IT87_REG_PWM_DUTY(nr),
1068 data->pwm_duty[nr]);
1069 } else {
1070 data->pwm_duty[nr] = pwm_to_reg(data, val);
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08001071 /*
1072 * If we are in manual mode, write the duty cycle immediately;
1073 * otherwise, just store it for later use.
1074 */
Jean Delvare6229cdb2010-12-08 16:27:22 +01001075 if (!(data->pwm_ctrl[nr] & 0x80)) {
1076 data->pwm_ctrl[nr] = data->pwm_duty[nr];
1077 it87_write_value(data, IT87_REG_PWM(nr),
1078 data->pwm_ctrl[nr]);
1079 }
Jean Delvareb99883d2010-03-05 22:17:15 +01001080 }
Ingo Molnar9a61bf62006-01-18 23:19:26 +01001081 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 return count;
1083}
Jean Delvaref8d0c192007-02-14 21:15:02 +01001084static ssize_t set_pwm_freq(struct device *dev,
1085 struct device_attribute *attr, const char *buf, size_t count)
1086{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001087 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +01001088 unsigned long val;
Jean Delvaref8d0c192007-02-14 21:15:02 +01001089 int i;
1090
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001091 if (kstrtoul(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +01001092 return -EINVAL;
1093
Guenter Roeckf56c9c02015-03-26 20:01:24 -07001094 val = clamp_val(val, 0, 1000000);
1095 val *= has_newer_autopwm(data) ? 256 : 128;
1096
Jean Delvaref8d0c192007-02-14 21:15:02 +01001097 /* Search for the nearest available frequency */
1098 for (i = 0; i < 7; i++) {
1099 if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2)
1100 break;
1101 }
1102
1103 mutex_lock(&data->update_lock);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001104 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f;
Jean Delvaref8d0c192007-02-14 21:15:02 +01001105 data->fan_ctl |= i << 4;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001106 it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl);
Jean Delvaref8d0c192007-02-14 21:15:02 +01001107 mutex_unlock(&data->update_lock);
1108
1109 return count;
1110}
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001111static ssize_t show_pwm_temp_map(struct device *dev,
1112 struct device_attribute *attr, char *buf)
1113{
1114 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1115 int nr = sensor_attr->index;
1116
1117 struct it87_data *data = it87_update_device(dev);
1118 int map;
1119
1120 if (data->pwm_temp_map[nr] < 3)
1121 map = 1 << data->pwm_temp_map[nr];
1122 else
1123 map = 0; /* Should never happen */
1124 return sprintf(buf, "%d\n", map);
1125}
1126static ssize_t set_pwm_temp_map(struct device *dev,
1127 struct device_attribute *attr, const char *buf, size_t count)
1128{
1129 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
1130 int nr = sensor_attr->index;
1131
1132 struct it87_data *data = dev_get_drvdata(dev);
1133 long val;
1134 u8 reg;
1135
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08001136 /*
1137 * This check can go away if we ever support automatic fan speed
1138 * control on newer chips.
1139 */
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001140 if (!has_old_autopwm(data)) {
1141 dev_notice(dev, "Mapping change disabled for safety reasons\n");
1142 return -EINVAL;
1143 }
1144
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001145 if (kstrtol(buf, 10, &val) < 0)
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001146 return -EINVAL;
1147
1148 switch (val) {
1149 case (1 << 0):
1150 reg = 0x00;
1151 break;
1152 case (1 << 1):
1153 reg = 0x01;
1154 break;
1155 case (1 << 2):
1156 reg = 0x02;
1157 break;
1158 default:
1159 return -EINVAL;
1160 }
1161
1162 mutex_lock(&data->update_lock);
1163 data->pwm_temp_map[nr] = reg;
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08001164 /*
1165 * If we are in automatic mode, write the temp mapping immediately;
1166 * otherwise, just store it for later use.
1167 */
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001168 if (data->pwm_ctrl[nr] & 0x80) {
1169 data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr];
1170 it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]);
1171 }
1172 mutex_unlock(&data->update_lock);
1173 return count;
1174}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001176static ssize_t show_auto_pwm(struct device *dev,
1177 struct device_attribute *attr, char *buf)
1178{
1179 struct it87_data *data = it87_update_device(dev);
1180 struct sensor_device_attribute_2 *sensor_attr =
1181 to_sensor_dev_attr_2(attr);
1182 int nr = sensor_attr->nr;
1183 int point = sensor_attr->index;
1184
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001185 return sprintf(buf, "%d\n",
1186 pwm_from_reg(data, data->auto_pwm[nr][point]));
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001187}
1188
1189static ssize_t set_auto_pwm(struct device *dev,
1190 struct device_attribute *attr, const char *buf, size_t count)
1191{
1192 struct it87_data *data = dev_get_drvdata(dev);
1193 struct sensor_device_attribute_2 *sensor_attr =
1194 to_sensor_dev_attr_2(attr);
1195 int nr = sensor_attr->nr;
1196 int point = sensor_attr->index;
1197 long val;
1198
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001199 if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255)
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001200 return -EINVAL;
1201
1202 mutex_lock(&data->update_lock);
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001203 data->auto_pwm[nr][point] = pwm_to_reg(data, val);
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001204 it87_write_value(data, IT87_REG_AUTO_PWM(nr, point),
1205 data->auto_pwm[nr][point]);
1206 mutex_unlock(&data->update_lock);
1207 return count;
1208}
1209
1210static ssize_t show_auto_temp(struct device *dev,
1211 struct device_attribute *attr, char *buf)
1212{
1213 struct it87_data *data = it87_update_device(dev);
1214 struct sensor_device_attribute_2 *sensor_attr =
1215 to_sensor_dev_attr_2(attr);
1216 int nr = sensor_attr->nr;
1217 int point = sensor_attr->index;
1218
1219 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->auto_temp[nr][point]));
1220}
1221
1222static ssize_t set_auto_temp(struct device *dev,
1223 struct device_attribute *attr, const char *buf, size_t count)
1224{
1225 struct it87_data *data = dev_get_drvdata(dev);
1226 struct sensor_device_attribute_2 *sensor_attr =
1227 to_sensor_dev_attr_2(attr);
1228 int nr = sensor_attr->nr;
1229 int point = sensor_attr->index;
1230 long val;
1231
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001232 if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000)
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001233 return -EINVAL;
1234
1235 mutex_lock(&data->update_lock);
1236 data->auto_temp[nr][point] = TEMP_TO_REG(val);
1237 it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point),
1238 data->auto_temp[nr][point]);
1239 mutex_unlock(&data->update_lock);
1240 return count;
1241}
1242
Guenter Roecke1169ba2012-12-19 22:17:01 +01001243static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0);
1244static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1245 0, 1);
1246static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, show_fan_div,
1247 set_fan_div, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
Guenter Roecke1169ba2012-12-19 22:17:01 +01001249static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 1, 0);
1250static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1251 1, 1);
1252static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, show_fan_div,
1253 set_fan_div, 1);
1254
1255static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 2, 0);
1256static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1257 2, 1);
1258static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR, show_fan_div,
1259 set_fan_div, 2);
1260
1261static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 3, 0);
1262static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1263 3, 1);
1264
1265static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, 0);
1266static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan,
1267 4, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
Guenter Roeckc4458db2012-12-19 22:17:02 +01001269static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR,
1270 show_pwm_enable, set_pwm_enable, 0);
1271static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0);
1272static DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR, show_pwm_freq, set_pwm_freq);
1273static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO | S_IWUSR,
1274 show_pwm_temp_map, set_pwm_temp_map, 0);
1275static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR,
1276 show_auto_pwm, set_auto_pwm, 0, 0);
1277static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR,
1278 show_auto_pwm, set_auto_pwm, 0, 1);
1279static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR,
1280 show_auto_pwm, set_auto_pwm, 0, 2);
1281static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO,
1282 show_auto_pwm, NULL, 0, 3);
1283static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR,
1284 show_auto_temp, set_auto_temp, 0, 1);
1285static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1286 show_auto_temp, set_auto_temp, 0, 0);
1287static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR,
1288 show_auto_temp, set_auto_temp, 0, 2);
1289static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR,
1290 show_auto_temp, set_auto_temp, 0, 3);
1291static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR,
1292 show_auto_temp, set_auto_temp, 0, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
Guenter Roeckc4458db2012-12-19 22:17:02 +01001294static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR,
1295 show_pwm_enable, set_pwm_enable, 1);
1296static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1);
1297static DEVICE_ATTR(pwm2_freq, S_IRUGO, show_pwm_freq, NULL);
1298static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IRUGO | S_IWUSR,
1299 show_pwm_temp_map, set_pwm_temp_map, 1);
1300static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR,
1301 show_auto_pwm, set_auto_pwm, 1, 0);
1302static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR,
1303 show_auto_pwm, set_auto_pwm, 1, 1);
1304static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR,
1305 show_auto_pwm, set_auto_pwm, 1, 2);
1306static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO,
1307 show_auto_pwm, NULL, 1, 3);
1308static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR,
1309 show_auto_temp, set_auto_temp, 1, 1);
1310static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1311 show_auto_temp, set_auto_temp, 1, 0);
1312static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR,
1313 show_auto_temp, set_auto_temp, 1, 2);
1314static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR,
1315 show_auto_temp, set_auto_temp, 1, 3);
1316static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR,
1317 show_auto_temp, set_auto_temp, 1, 4);
1318
1319static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR,
1320 show_pwm_enable, set_pwm_enable, 2);
1321static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 2);
1322static DEVICE_ATTR(pwm3_freq, S_IRUGO, show_pwm_freq, NULL);
1323static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IRUGO | S_IWUSR,
1324 show_pwm_temp_map, set_pwm_temp_map, 2);
1325static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR,
1326 show_auto_pwm, set_auto_pwm, 2, 0);
1327static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR,
1328 show_auto_pwm, set_auto_pwm, 2, 1);
1329static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO | S_IWUSR,
1330 show_auto_pwm, set_auto_pwm, 2, 2);
1331static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO,
1332 show_auto_pwm, NULL, 2, 3);
1333static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp, S_IRUGO | S_IWUSR,
1334 show_auto_temp, set_auto_temp, 2, 1);
1335static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO | S_IWUSR,
1336 show_auto_temp, set_auto_temp, 2, 0);
1337static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp, S_IRUGO | S_IWUSR,
1338 show_auto_temp, set_auto_temp, 2, 2);
1339static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp, S_IRUGO | S_IWUSR,
1340 show_auto_temp, set_auto_temp, 2, 3);
1341static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_temp, S_IRUGO | S_IWUSR,
1342 show_auto_temp, set_auto_temp, 2, 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
1344/* Alarms */
Jean Delvare5f2dc792010-03-05 22:17:18 +01001345static ssize_t show_alarms(struct device *dev, struct device_attribute *attr,
1346 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347{
1348 struct it87_data *data = it87_update_device(dev);
Jean Delvare68188ba2005-05-16 18:52:38 +02001349 return sprintf(buf, "%u\n", data->alarms);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350}
Jean Delvare1d66c642005-04-18 21:16:59 -07001351static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352
Jean Delvare0124dd72007-11-25 16:16:41 +01001353static ssize_t show_alarm(struct device *dev, struct device_attribute *attr,
1354 char *buf)
1355{
1356 int bitnr = to_sensor_dev_attr(attr)->index;
1357 struct it87_data *data = it87_update_device(dev);
1358 return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1);
1359}
Jean Delvare3d30f9e2011-07-25 21:46:10 +02001360
1361static ssize_t clear_intrusion(struct device *dev, struct device_attribute
1362 *attr, const char *buf, size_t count)
1363{
1364 struct it87_data *data = dev_get_drvdata(dev);
1365 long val;
1366 int config;
1367
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001368 if (kstrtol(buf, 10, &val) < 0 || val != 0)
Jean Delvare3d30f9e2011-07-25 21:46:10 +02001369 return -EINVAL;
1370
1371 mutex_lock(&data->update_lock);
1372 config = it87_read_value(data, IT87_REG_CONFIG);
1373 if (config < 0) {
1374 count = config;
1375 } else {
1376 config |= 1 << 5;
1377 it87_write_value(data, IT87_REG_CONFIG, config);
1378 /* Invalidate cache to force re-read */
1379 data->valid = 0;
1380 }
1381 mutex_unlock(&data->update_lock);
1382
1383 return count;
1384}
1385
Jean Delvare0124dd72007-11-25 16:16:41 +01001386static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8);
1387static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9);
1388static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10);
1389static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11);
1390static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12);
1391static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13);
1392static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14);
1393static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15);
1394static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0);
1395static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1);
1396static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2);
1397static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3);
1398static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6);
1399static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16);
1400static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17);
1401static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18);
Jean Delvare3d30f9e2011-07-25 21:46:10 +02001402static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR,
1403 show_alarm, clear_intrusion, 4);
Jean Delvare0124dd72007-11-25 16:16:41 +01001404
Jean Delvared9b327c2010-03-05 22:17:17 +01001405static ssize_t show_beep(struct device *dev, struct device_attribute *attr,
1406 char *buf)
1407{
1408 int bitnr = to_sensor_dev_attr(attr)->index;
1409 struct it87_data *data = it87_update_device(dev);
1410 return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1);
1411}
1412static ssize_t set_beep(struct device *dev, struct device_attribute *attr,
1413 const char *buf, size_t count)
1414{
1415 int bitnr = to_sensor_dev_attr(attr)->index;
1416 struct it87_data *data = dev_get_drvdata(dev);
1417 long val;
1418
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001419 if (kstrtol(buf, 10, &val) < 0
Jean Delvared9b327c2010-03-05 22:17:17 +01001420 || (val != 0 && val != 1))
1421 return -EINVAL;
1422
1423 mutex_lock(&data->update_lock);
1424 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
1425 if (val)
1426 data->beeps |= (1 << bitnr);
1427 else
1428 data->beeps &= ~(1 << bitnr);
1429 it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps);
1430 mutex_unlock(&data->update_lock);
1431 return count;
1432}
1433
1434static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR,
1435 show_beep, set_beep, 1);
1436static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1);
1437static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1);
1438static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1);
1439static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1);
1440static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1);
1441static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1);
1442static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1);
1443/* fanX_beep writability is set later */
1444static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0);
1445static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0);
1446static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0);
1447static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0);
1448static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0);
1449static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR,
1450 show_beep, set_beep, 2);
1451static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2);
1452static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2);
1453
Jean Delvare5f2dc792010-03-05 22:17:18 +01001454static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr,
1455 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456{
Jean Delvare90d66192007-10-08 18:24:35 +02001457 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvarea7be58a2005-12-18 16:40:14 +01001458 return sprintf(buf, "%u\n", data->vrm);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459}
Jean Delvare5f2dc792010-03-05 22:17:18 +01001460static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr,
1461 const char *buf, size_t count)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001463 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvaref5f64502010-03-05 22:17:19 +01001464 unsigned long val;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001466 if (kstrtoul(buf, 10, &val) < 0)
Jean Delvaref5f64502010-03-05 22:17:19 +01001467 return -EINVAL;
1468
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 data->vrm = val;
1470
1471 return count;
1472}
1473static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
Jean Delvare5f2dc792010-03-05 22:17:18 +01001475static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr,
1476 char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477{
1478 struct it87_data *data = it87_update_device(dev);
1479 return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm));
1480}
1481static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL);
Jean Delvare87808be2006-09-24 21:17:13 +02001482
Jean Delvare738e5e02010-08-14 21:08:50 +02001483static ssize_t show_label(struct device *dev, struct device_attribute *attr,
1484 char *buf)
1485{
Guenter Roeck3c4c4972012-01-20 09:29:44 -08001486 static const char * const labels[] = {
Jean Delvare738e5e02010-08-14 21:08:50 +02001487 "+5V",
1488 "5VSB",
1489 "Vbat",
1490 };
Guenter Roeck3c4c4972012-01-20 09:29:44 -08001491 static const char * const labels_it8721[] = {
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001492 "+3.3V",
1493 "3VSB",
1494 "Vbat",
1495 };
1496 struct it87_data *data = dev_get_drvdata(dev);
Jean Delvare738e5e02010-08-14 21:08:50 +02001497 int nr = to_sensor_dev_attr(attr)->index;
1498
Jean Delvare16b5dda2012-01-16 22:51:48 +01001499 return sprintf(buf, "%s\n", has_12mv_adc(data) ? labels_it8721[nr]
1500 : labels[nr]);
Jean Delvare738e5e02010-08-14 21:08:50 +02001501}
1502static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0);
1503static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1);
1504static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2);
Rudolf Marek7183ae82014-04-04 18:01:35 +02001505/* special AVCC3 IT8603E in9 */
Rudolf Marekc145d5c2014-01-29 20:40:08 +01001506static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_label, NULL, 0);
Jean Delvare738e5e02010-08-14 21:08:50 +02001507
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001508static ssize_t show_name(struct device *dev, struct device_attribute
1509 *devattr, char *buf)
1510{
1511 struct it87_data *data = dev_get_drvdata(dev);
1512 return sprintf(buf, "%s\n", data->name);
1513}
1514static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
1515
Rudolf Marekc145d5c2014-01-29 20:40:08 +01001516static struct attribute *it87_attributes_in[10][5] = {
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001517{
Jean Delvare87808be2006-09-24 21:17:13 +02001518 &sensor_dev_attr_in0_input.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001519 &sensor_dev_attr_in0_min.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001520 &sensor_dev_attr_in0_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001521 &sensor_dev_attr_in0_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001522 NULL
1523}, {
1524 &sensor_dev_attr_in1_input.dev_attr.attr,
1525 &sensor_dev_attr_in1_min.dev_attr.attr,
1526 &sensor_dev_attr_in1_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001527 &sensor_dev_attr_in1_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001528 NULL
1529}, {
1530 &sensor_dev_attr_in2_input.dev_attr.attr,
1531 &sensor_dev_attr_in2_min.dev_attr.attr,
1532 &sensor_dev_attr_in2_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001533 &sensor_dev_attr_in2_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001534 NULL
1535}, {
1536 &sensor_dev_attr_in3_input.dev_attr.attr,
1537 &sensor_dev_attr_in3_min.dev_attr.attr,
1538 &sensor_dev_attr_in3_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001539 &sensor_dev_attr_in3_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001540 NULL
1541}, {
1542 &sensor_dev_attr_in4_input.dev_attr.attr,
1543 &sensor_dev_attr_in4_min.dev_attr.attr,
1544 &sensor_dev_attr_in4_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001545 &sensor_dev_attr_in4_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001546 NULL
1547}, {
1548 &sensor_dev_attr_in5_input.dev_attr.attr,
1549 &sensor_dev_attr_in5_min.dev_attr.attr,
1550 &sensor_dev_attr_in5_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001551 &sensor_dev_attr_in5_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001552 NULL
1553}, {
1554 &sensor_dev_attr_in6_input.dev_attr.attr,
1555 &sensor_dev_attr_in6_min.dev_attr.attr,
1556 &sensor_dev_attr_in6_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001557 &sensor_dev_attr_in6_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001558 NULL
1559}, {
1560 &sensor_dev_attr_in7_input.dev_attr.attr,
1561 &sensor_dev_attr_in7_min.dev_attr.attr,
1562 &sensor_dev_attr_in7_max.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001563 &sensor_dev_attr_in7_alarm.dev_attr.attr,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001564 NULL
1565}, {
1566 &sensor_dev_attr_in8_input.dev_attr.attr,
1567 NULL
Rudolf Marekc145d5c2014-01-29 20:40:08 +01001568}, {
1569 &sensor_dev_attr_in9_input.dev_attr.attr,
1570 NULL
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001571} };
Jean Delvare87808be2006-09-24 21:17:13 +02001572
Rudolf Marekc145d5c2014-01-29 20:40:08 +01001573static const struct attribute_group it87_group_in[10] = {
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001574 { .attrs = it87_attributes_in[0] },
1575 { .attrs = it87_attributes_in[1] },
1576 { .attrs = it87_attributes_in[2] },
1577 { .attrs = it87_attributes_in[3] },
1578 { .attrs = it87_attributes_in[4] },
1579 { .attrs = it87_attributes_in[5] },
1580 { .attrs = it87_attributes_in[6] },
1581 { .attrs = it87_attributes_in[7] },
1582 { .attrs = it87_attributes_in[8] },
Rudolf Marekc145d5c2014-01-29 20:40:08 +01001583 { .attrs = it87_attributes_in[9] },
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001584};
1585
Guenter Roeck4573acb2012-03-26 16:17:41 -07001586static struct attribute *it87_attributes_temp[3][6] = {
1587{
Jean Delvare87808be2006-09-24 21:17:13 +02001588 &sensor_dev_attr_temp1_input.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001589 &sensor_dev_attr_temp1_max.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001590 &sensor_dev_attr_temp1_min.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001591 &sensor_dev_attr_temp1_type.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001592 &sensor_dev_attr_temp1_alarm.dev_attr.attr,
Guenter Roeck4573acb2012-03-26 16:17:41 -07001593 NULL
1594} , {
1595 &sensor_dev_attr_temp2_input.dev_attr.attr,
1596 &sensor_dev_attr_temp2_max.dev_attr.attr,
1597 &sensor_dev_attr_temp2_min.dev_attr.attr,
1598 &sensor_dev_attr_temp2_type.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001599 &sensor_dev_attr_temp2_alarm.dev_attr.attr,
Guenter Roeck4573acb2012-03-26 16:17:41 -07001600 NULL
1601} , {
1602 &sensor_dev_attr_temp3_input.dev_attr.attr,
1603 &sensor_dev_attr_temp3_max.dev_attr.attr,
1604 &sensor_dev_attr_temp3_min.dev_attr.attr,
1605 &sensor_dev_attr_temp3_type.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001606 &sensor_dev_attr_temp3_alarm.dev_attr.attr,
Guenter Roeck4573acb2012-03-26 16:17:41 -07001607 NULL
1608} };
Jean Delvare87808be2006-09-24 21:17:13 +02001609
Guenter Roeck4573acb2012-03-26 16:17:41 -07001610static const struct attribute_group it87_group_temp[3] = {
1611 { .attrs = it87_attributes_temp[0] },
1612 { .attrs = it87_attributes_temp[1] },
1613 { .attrs = it87_attributes_temp[2] },
1614};
1615
Guenter Roeck161d8982012-12-19 22:17:01 +01001616static struct attribute *it87_attributes_temp_offset[] = {
1617 &sensor_dev_attr_temp1_offset.dev_attr.attr,
1618 &sensor_dev_attr_temp2_offset.dev_attr.attr,
1619 &sensor_dev_attr_temp3_offset.dev_attr.attr,
1620};
1621
Guenter Roeck4573acb2012-03-26 16:17:41 -07001622static struct attribute *it87_attributes[] = {
Jean Delvare87808be2006-09-24 21:17:13 +02001623 &dev_attr_alarms.attr,
Jean Delvare3d30f9e2011-07-25 21:46:10 +02001624 &sensor_dev_attr_intrusion0_alarm.dev_attr.attr,
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001625 &dev_attr_name.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001626 NULL
1627};
1628
1629static const struct attribute_group it87_group = {
1630 .attrs = it87_attributes,
1631};
1632
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001633static struct attribute *it87_attributes_in_beep[] = {
Jean Delvared9b327c2010-03-05 22:17:17 +01001634 &sensor_dev_attr_in0_beep.dev_attr.attr,
1635 &sensor_dev_attr_in1_beep.dev_attr.attr,
1636 &sensor_dev_attr_in2_beep.dev_attr.attr,
1637 &sensor_dev_attr_in3_beep.dev_attr.attr,
1638 &sensor_dev_attr_in4_beep.dev_attr.attr,
1639 &sensor_dev_attr_in5_beep.dev_attr.attr,
1640 &sensor_dev_attr_in6_beep.dev_attr.attr,
1641 &sensor_dev_attr_in7_beep.dev_attr.attr,
Rudolf Marekc145d5c2014-01-29 20:40:08 +01001642 NULL,
1643 NULL,
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001644};
Jean Delvared9b327c2010-03-05 22:17:17 +01001645
Guenter Roeck4573acb2012-03-26 16:17:41 -07001646static struct attribute *it87_attributes_temp_beep[] = {
Jean Delvared9b327c2010-03-05 22:17:17 +01001647 &sensor_dev_attr_temp1_beep.dev_attr.attr,
1648 &sensor_dev_attr_temp2_beep.dev_attr.attr,
1649 &sensor_dev_attr_temp3_beep.dev_attr.attr,
Jean Delvared9b327c2010-03-05 22:17:17 +01001650};
1651
Guenter Roecke1169ba2012-12-19 22:17:01 +01001652static struct attribute *it87_attributes_fan[5][3+1] = { {
Jean Delvare87808be2006-09-24 21:17:13 +02001653 &sensor_dev_attr_fan1_input.dev_attr.attr,
1654 &sensor_dev_attr_fan1_min.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001655 &sensor_dev_attr_fan1_alarm.dev_attr.attr,
1656 NULL
1657}, {
Jean Delvare87808be2006-09-24 21:17:13 +02001658 &sensor_dev_attr_fan2_input.dev_attr.attr,
1659 &sensor_dev_attr_fan2_min.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001660 &sensor_dev_attr_fan2_alarm.dev_attr.attr,
1661 NULL
1662}, {
Jean Delvare87808be2006-09-24 21:17:13 +02001663 &sensor_dev_attr_fan3_input.dev_attr.attr,
1664 &sensor_dev_attr_fan3_min.dev_attr.attr,
Jean Delvare0124dd72007-11-25 16:16:41 +01001665 &sensor_dev_attr_fan3_alarm.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001666 NULL
Guenter Roecke1169ba2012-12-19 22:17:01 +01001667}, {
1668 &sensor_dev_attr_fan4_input.dev_attr.attr,
1669 &sensor_dev_attr_fan4_min.dev_attr.attr,
1670 &sensor_dev_attr_fan4_alarm.dev_attr.attr,
1671 NULL
1672}, {
1673 &sensor_dev_attr_fan5_input.dev_attr.attr,
1674 &sensor_dev_attr_fan5_min.dev_attr.attr,
1675 &sensor_dev_attr_fan5_alarm.dev_attr.attr,
1676 NULL
Jean Delvare723a0aa2010-03-05 22:17:16 +01001677} };
Jean Delvare0124dd72007-11-25 16:16:41 +01001678
Guenter Roecke1169ba2012-12-19 22:17:01 +01001679static const struct attribute_group it87_group_fan[5] = {
Jean Delvare723a0aa2010-03-05 22:17:16 +01001680 { .attrs = it87_attributes_fan[0] },
1681 { .attrs = it87_attributes_fan[1] },
1682 { .attrs = it87_attributes_fan[2] },
Guenter Roecke1169ba2012-12-19 22:17:01 +01001683 { .attrs = it87_attributes_fan[3] },
1684 { .attrs = it87_attributes_fan[4] },
Jean Delvare723a0aa2010-03-05 22:17:16 +01001685};
1686
Guenter Roecke1169ba2012-12-19 22:17:01 +01001687static const struct attribute *it87_attributes_fan_div[] = {
1688 &sensor_dev_attr_fan1_div.dev_attr.attr,
1689 &sensor_dev_attr_fan2_div.dev_attr.attr,
1690 &sensor_dev_attr_fan3_div.dev_attr.attr,
1691};
Jean Delvare723a0aa2010-03-05 22:17:16 +01001692
1693static struct attribute *it87_attributes_pwm[3][4+1] = { {
Jean Delvare87808be2006-09-24 21:17:13 +02001694 &sensor_dev_attr_pwm1_enable.dev_attr.attr,
Jean Delvare87808be2006-09-24 21:17:13 +02001695 &sensor_dev_attr_pwm1.dev_attr.attr,
Jean Delvared5b0b5d2007-12-14 14:41:53 +01001696 &dev_attr_pwm1_freq.attr,
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001697 &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001698 NULL
1699}, {
1700 &sensor_dev_attr_pwm2_enable.dev_attr.attr,
1701 &sensor_dev_attr_pwm2.dev_attr.attr,
1702 &dev_attr_pwm2_freq.attr,
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001703 &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001704 NULL
1705}, {
1706 &sensor_dev_attr_pwm3_enable.dev_attr.attr,
1707 &sensor_dev_attr_pwm3.dev_attr.attr,
1708 &dev_attr_pwm3_freq.attr,
Jean Delvare94ac7ee2010-03-05 22:17:16 +01001709 &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr,
Jean Delvare723a0aa2010-03-05 22:17:16 +01001710 NULL
1711} };
Jean Delvare87808be2006-09-24 21:17:13 +02001712
Jean Delvare723a0aa2010-03-05 22:17:16 +01001713static const struct attribute_group it87_group_pwm[3] = {
1714 { .attrs = it87_attributes_pwm[0] },
1715 { .attrs = it87_attributes_pwm[1] },
1716 { .attrs = it87_attributes_pwm[2] },
1717};
1718
Jean Delvare4f3f51b2010-03-05 22:17:21 +01001719static struct attribute *it87_attributes_autopwm[3][9+1] = { {
1720 &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
1721 &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
1722 &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
1723 &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
1724 &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
1725 &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr,
1726 &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
1727 &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
1728 &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
1729 NULL
1730}, {
1731 &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr,
1732 &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr,
1733 &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr,
1734 &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr,
1735 &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr,
1736 &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr,
1737 &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr,
1738 &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr,
1739 &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr,
1740 NULL
1741}, {
1742 &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr,
1743 &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr,
1744 &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr,
1745 &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr,
1746 &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr,
1747 &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr,
1748 &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr,
1749 &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr,
1750 &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr,
1751 NULL
1752} };
1753
1754static const struct attribute_group it87_group_autopwm[3] = {
1755 { .attrs = it87_attributes_autopwm[0] },
1756 { .attrs = it87_attributes_autopwm[1] },
1757 { .attrs = it87_attributes_autopwm[2] },
1758};
1759
Jean Delvared9b327c2010-03-05 22:17:17 +01001760static struct attribute *it87_attributes_fan_beep[] = {
1761 &sensor_dev_attr_fan1_beep.dev_attr.attr,
1762 &sensor_dev_attr_fan2_beep.dev_attr.attr,
1763 &sensor_dev_attr_fan3_beep.dev_attr.attr,
1764 &sensor_dev_attr_fan4_beep.dev_attr.attr,
1765 &sensor_dev_attr_fan5_beep.dev_attr.attr,
1766};
1767
Jean Delvare6a8d7ac2010-03-05 22:17:16 +01001768static struct attribute *it87_attributes_vid[] = {
Jean Delvare87808be2006-09-24 21:17:13 +02001769 &dev_attr_vrm.attr,
1770 &dev_attr_cpu0_vid.attr,
1771 NULL
1772};
1773
Jean Delvare6a8d7ac2010-03-05 22:17:16 +01001774static const struct attribute_group it87_group_vid = {
1775 .attrs = it87_attributes_vid,
Jean Delvare87808be2006-09-24 21:17:13 +02001776};
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777
Jean Delvare738e5e02010-08-14 21:08:50 +02001778static struct attribute *it87_attributes_label[] = {
1779 &sensor_dev_attr_in3_label.dev_attr.attr,
1780 &sensor_dev_attr_in7_label.dev_attr.attr,
1781 &sensor_dev_attr_in8_label.dev_attr.attr,
Rudolf Marekc145d5c2014-01-29 20:40:08 +01001782 &sensor_dev_attr_in9_label.dev_attr.attr,
Jean Delvare738e5e02010-08-14 21:08:50 +02001783 NULL
1784};
1785
1786static const struct attribute_group it87_group_label = {
Jean Delvarefa8b6972011-07-17 18:39:19 +02001787 .attrs = it87_attributes_label,
Jean Delvare738e5e02010-08-14 21:08:50 +02001788};
1789
Jean Delvare2d8672c2005-07-19 23:56:35 +02001790/* SuperIO detection - will change isa_address if a chip is found */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001791static int __init it87_find(unsigned short *address,
1792 struct it87_sio_data *sio_data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793{
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +02001794 int err;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001795 u16 chip_type;
Jean Delvare98dd22c2008-10-09 15:33:58 +02001796 const char *board_vendor, *board_name;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797
Nat Gurumoorthy5b0380c2011-05-25 20:43:33 +02001798 err = superio_enter();
1799 if (err)
1800 return err;
1801
1802 err = -ENODEV;
Jean Delvare67b671b2007-12-06 23:13:42 +01001803 chip_type = force_id ? force_id : superio_inw(DEVID);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001804
1805 switch (chip_type) {
1806 case IT8705F_DEVID:
1807 sio_data->type = it87;
1808 break;
1809 case IT8712F_DEVID:
1810 sio_data->type = it8712;
1811 break;
1812 case IT8716F_DEVID:
1813 case IT8726F_DEVID:
1814 sio_data->type = it8716;
1815 break;
1816 case IT8718F_DEVID:
1817 sio_data->type = it8718;
1818 break;
Jean-Marc Spaggiarib4da93e2009-01-07 16:37:32 +01001819 case IT8720F_DEVID:
1820 sio_data->type = it8720;
1821 break;
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001822 case IT8721F_DEVID:
1823 sio_data->type = it8721;
1824 break;
Jean Delvare16b5dda2012-01-16 22:51:48 +01001825 case IT8728F_DEVID:
1826 sio_data->type = it8728;
1827 break;
Guenter Roeckb0636702012-09-07 17:34:41 -06001828 case IT8771E_DEVID:
1829 sio_data->type = it8771;
1830 break;
1831 case IT8772E_DEVID:
1832 sio_data->type = it8772;
1833 break;
Guenter Roeck7bc32d22015-01-17 14:10:24 -08001834 case IT8781F_DEVID:
1835 sio_data->type = it8781;
1836 break;
Guenter Roeck0531d982012-03-02 11:46:44 -08001837 case IT8782F_DEVID:
1838 sio_data->type = it8782;
1839 break;
1840 case IT8783E_DEVID:
1841 sio_data->type = it8783;
1842 break;
Thomas Lorblanchesa0c14242015-02-13 13:19:06 +01001843 case IT8786E_DEVID:
1844 sio_data->type = it8786;
1845 break;
Guenter Roeck4ee07152015-03-25 23:26:28 -07001846 case IT8790E_DEVID:
1847 sio_data->type = it8790;
1848 break;
Rudolf Marek7183ae82014-04-04 18:01:35 +02001849 case IT8603E_DEVID:
Rudolf Marek574e9bd2014-04-04 18:01:35 +02001850 case IT8623E_DEVID:
Rudolf Marekc145d5c2014-01-29 20:40:08 +01001851 sio_data->type = it8603;
1852 break;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001853 case 0xffff: /* No device at all */
1854 goto exit;
1855 default:
Joe Perchesa8ca1032011-01-12 21:55:10 +01001856 pr_debug("Unsupported chip (DEVID=0x%x)\n", chip_type);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02001857 goto exit;
1858 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859
Jean Delvare87673dd2006-08-28 14:37:19 +02001860 superio_select(PME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 if (!(superio_inb(IT87_ACT_REG) & 0x01)) {
Joe Perchesa8ca1032011-01-12 21:55:10 +01001862 pr_info("Device not activated, skipping\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 goto exit;
1864 }
1865
1866 *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1);
1867 if (*address == 0) {
Joe Perchesa8ca1032011-01-12 21:55:10 +01001868 pr_info("Base address not set, skipping\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 goto exit;
1870 }
1871
1872 err = 0;
Andrew Paprocki04751692008-08-06 22:41:06 +02001873 sio_data->revision = superio_inb(DEVREV) & 0x0f;
Guenter Roeckfaf392f2015-03-26 08:36:18 -07001874 pr_info("Found IT%04x%s chip at 0x%x, revision %d\n", chip_type,
1875 it87_devices[sio_data->type].suffix,
Thomas Lorblanchesa0c14242015-02-13 13:19:06 +01001876 *address, sio_data->revision);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877
Guenter Roeck7f5726c2015-03-26 08:49:18 -07001878 /* in7 (VSB or VCCH5V) is always internal on some chips */
1879 if (it87_devices[sio_data->type].features & FEAT_IN7_INTERNAL)
1880 sio_data->internal |= (1 << 1);
1881
Jean Delvare738e5e02010-08-14 21:08:50 +02001882 /* in8 (Vbat) is always internal */
Guenter Roeck7f5726c2015-03-26 08:49:18 -07001883 sio_data->internal |= (1 << 2);
1884
Rudolf Marekc145d5c2014-01-29 20:40:08 +01001885 /* Only the IT8603E has in9 */
1886 if (sio_data->type != it8603)
1887 sio_data->skip_in |= (1 << 9);
Jean Delvare738e5e02010-08-14 21:08:50 +02001888
Guenter Roeck32dd7c42015-02-12 07:40:23 -08001889 if (!(it87_devices[sio_data->type].features & FEAT_VID))
Jean Delvare895ff262009-12-09 20:35:47 +01001890 sio_data->skip_vid = 1;
Jean Delvared9b327c2010-03-05 22:17:17 +01001891
Guenter Roeck32dd7c42015-02-12 07:40:23 -08001892 /* Read GPIO config and VID value from LDN 7 (GPIO) */
1893 if (sio_data->type == it87) {
Jean Delvared9b327c2010-03-05 22:17:17 +01001894 /* The IT8705F has a different LD number for GPIO */
1895 superio_select(5);
1896 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
Guenter Roeck0531d982012-03-02 11:46:44 -08001897 } else if (sio_data->type == it8783) {
Guenter Roeck088ce2a2013-03-13 16:40:39 -07001898 int reg25, reg27, reg2a, reg2c, regef;
Guenter Roeck0531d982012-03-02 11:46:44 -08001899
Guenter Roeck0531d982012-03-02 11:46:44 -08001900 superio_select(GPIO);
1901
1902 reg25 = superio_inb(IT87_SIO_GPIO1_REG);
1903 reg27 = superio_inb(IT87_SIO_GPIO3_REG);
Guenter Roeck088ce2a2013-03-13 16:40:39 -07001904 reg2a = superio_inb(IT87_SIO_PINX1_REG);
1905 reg2c = superio_inb(IT87_SIO_PINX2_REG);
1906 regef = superio_inb(IT87_SIO_SPI_REG);
Guenter Roeck0531d982012-03-02 11:46:44 -08001907
Guenter Roeck0531d982012-03-02 11:46:44 -08001908 /* Check if fan3 is there or not */
Guenter Roeck088ce2a2013-03-13 16:40:39 -07001909 if ((reg27 & (1 << 0)) || !(reg2c & (1 << 2)))
Guenter Roeck0531d982012-03-02 11:46:44 -08001910 sio_data->skip_fan |= (1 << 2);
1911 if ((reg25 & (1 << 4))
Guenter Roeck088ce2a2013-03-13 16:40:39 -07001912 || (!(reg2a & (1 << 1)) && (regef & (1 << 0))))
Guenter Roeck0531d982012-03-02 11:46:44 -08001913 sio_data->skip_pwm |= (1 << 2);
1914
1915 /* Check if fan2 is there or not */
1916 if (reg27 & (1 << 7))
1917 sio_data->skip_fan |= (1 << 1);
1918 if (reg27 & (1 << 3))
1919 sio_data->skip_pwm |= (1 << 1);
1920
1921 /* VIN5 */
Guenter Roeck088ce2a2013-03-13 16:40:39 -07001922 if ((reg27 & (1 << 0)) || (reg2c & (1 << 2)))
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001923 sio_data->skip_in |= (1 << 5); /* No VIN5 */
Guenter Roeck0531d982012-03-02 11:46:44 -08001924
1925 /* VIN6 */
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001926 if (reg27 & (1 << 1))
1927 sio_data->skip_in |= (1 << 6); /* No VIN6 */
Guenter Roeck0531d982012-03-02 11:46:44 -08001928
1929 /*
1930 * VIN7
1931 * Does not depend on bit 2 of Reg2C, contrary to datasheet.
1932 */
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001933 if (reg27 & (1 << 2)) {
1934 /*
1935 * The data sheet is a bit unclear regarding the
1936 * internal voltage divider for VCCH5V. It says
1937 * "This bit enables and switches VIN7 (pin 91) to the
1938 * internal voltage divider for VCCH5V".
1939 * This is different to other chips, where the internal
1940 * voltage divider would connect VIN7 to an internal
1941 * voltage source. Maybe that is the case here as well.
1942 *
1943 * Since we don't know for sure, re-route it if that is
1944 * not the case, and ask the user to report if the
1945 * resulting voltage is sane.
1946 */
Guenter Roeck088ce2a2013-03-13 16:40:39 -07001947 if (!(reg2c & (1 << 1))) {
1948 reg2c |= (1 << 1);
1949 superio_outb(IT87_SIO_PINX2_REG, reg2c);
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001950 pr_notice("Routing internal VCCH5V to in7.\n");
1951 }
1952 pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n");
1953 pr_notice("Please report if it displays a reasonable voltage.\n");
1954 }
Guenter Roeck0531d982012-03-02 11:46:44 -08001955
Guenter Roeck088ce2a2013-03-13 16:40:39 -07001956 if (reg2c & (1 << 0))
Guenter Roeck0531d982012-03-02 11:46:44 -08001957 sio_data->internal |= (1 << 0);
Guenter Roeck088ce2a2013-03-13 16:40:39 -07001958 if (reg2c & (1 << 1))
Guenter Roeck0531d982012-03-02 11:46:44 -08001959 sio_data->internal |= (1 << 1);
1960
1961 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
Rudolf Marekc145d5c2014-01-29 20:40:08 +01001962 } else if (sio_data->type == it8603) {
1963 int reg27, reg29;
Guenter Roeck0531d982012-03-02 11:46:44 -08001964
Rudolf Marekc145d5c2014-01-29 20:40:08 +01001965 superio_select(GPIO);
1966
1967 reg27 = superio_inb(IT87_SIO_GPIO3_REG);
1968
1969 /* Check if fan3 is there or not */
1970 if (reg27 & (1 << 6))
1971 sio_data->skip_pwm |= (1 << 2);
1972 if (reg27 & (1 << 7))
1973 sio_data->skip_fan |= (1 << 2);
1974
1975 /* Check if fan2 is there or not */
1976 reg29 = superio_inb(IT87_SIO_GPIO5_REG);
1977 if (reg29 & (1 << 1))
1978 sio_data->skip_pwm |= (1 << 1);
1979 if (reg29 & (1 << 2))
1980 sio_data->skip_fan |= (1 << 1);
1981
1982 sio_data->skip_in |= (1 << 5); /* No VIN5 */
1983 sio_data->skip_in |= (1 << 6); /* No VIN6 */
1984
Rudolf Marekc145d5c2014-01-29 20:40:08 +01001985 sio_data->internal |= (1 << 3); /* in9 is AVCC */
1986
1987 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
Jean Delvare895ff262009-12-09 20:35:47 +01001988 } else {
Jean Delvare87673dd2006-08-28 14:37:19 +02001989 int reg;
Guenter Roeck9172b5d2012-03-24 21:49:54 -07001990 bool uart6;
Jean Delvare87673dd2006-08-28 14:37:19 +02001991
1992 superio_select(GPIO);
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001993
Jean Delvare895ff262009-12-09 20:35:47 +01001994 reg = superio_inb(IT87_SIO_GPIO3_REG);
Guenter Roeck32dd7c42015-02-12 07:40:23 -08001995 if (!sio_data->skip_vid) {
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001996 /* We need at least 4 VID pins */
1997 if (reg & 0x0f) {
Joe Perchesa8ca1032011-01-12 21:55:10 +01001998 pr_info("VID is disabled (pins used for GPIO)\n");
Jean Delvare44c1bcd2010-10-28 20:31:51 +02001999 sio_data->skip_vid = 1;
2000 }
Jean Delvare895ff262009-12-09 20:35:47 +01002001 }
2002
Jean Delvare591ec652009-12-09 20:35:48 +01002003 /* Check if fan3 is there or not */
2004 if (reg & (1 << 6))
2005 sio_data->skip_pwm |= (1 << 2);
2006 if (reg & (1 << 7))
2007 sio_data->skip_fan |= (1 << 2);
2008
2009 /* Check if fan2 is there or not */
2010 reg = superio_inb(IT87_SIO_GPIO5_REG);
2011 if (reg & (1 << 1))
2012 sio_data->skip_pwm |= (1 << 1);
2013 if (reg & (1 << 2))
2014 sio_data->skip_fan |= (1 << 1);
2015
Jean Delvare895ff262009-12-09 20:35:47 +01002016 if ((sio_data->type == it8718 || sio_data->type == it8720)
2017 && !(sio_data->skip_vid))
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002018 sio_data->vid_value = superio_inb(IT87_SIO_VID_REG);
Jean Delvare87673dd2006-08-28 14:37:19 +02002019
2020 reg = superio_inb(IT87_SIO_PINX2_REG);
Guenter Roeck9172b5d2012-03-24 21:49:54 -07002021
2022 uart6 = sio_data->type == it8782 && (reg & (1 << 2));
2023
Jean Delvare436cad22010-07-09 16:22:48 +02002024 /*
2025 * The IT8720F has no VIN7 pin, so VCCH should always be
2026 * routed internally to VIN7 with an internal divider.
2027 * Curiously, there still is a configuration bit to control
2028 * this, which means it can be set incorrectly. And even
2029 * more curiously, many boards out there are improperly
2030 * configured, even though the IT8720F datasheet claims
2031 * that the internal routing of VCCH to VIN7 is the default
2032 * setting. So we force the internal routing in this case.
Guenter Roeck0531d982012-03-02 11:46:44 -08002033 *
2034 * On IT8782F, VIN7 is multiplexed with one of the UART6 pins.
Guenter Roeck9172b5d2012-03-24 21:49:54 -07002035 * If UART6 is enabled, re-route VIN7 to the internal divider
2036 * if that is not already the case.
Jean Delvare436cad22010-07-09 16:22:48 +02002037 */
Guenter Roeck9172b5d2012-03-24 21:49:54 -07002038 if ((sio_data->type == it8720 || uart6) && !(reg & (1 << 1))) {
Jean Delvare436cad22010-07-09 16:22:48 +02002039 reg |= (1 << 1);
2040 superio_outb(IT87_SIO_PINX2_REG, reg);
Joe Perchesa8ca1032011-01-12 21:55:10 +01002041 pr_notice("Routing internal VCCH to in7\n");
Jean Delvare436cad22010-07-09 16:22:48 +02002042 }
Jean Delvare87673dd2006-08-28 14:37:19 +02002043 if (reg & (1 << 0))
Jean Delvare738e5e02010-08-14 21:08:50 +02002044 sio_data->internal |= (1 << 0);
Guenter Roeck7f5726c2015-03-26 08:49:18 -07002045 if (reg & (1 << 1))
Jean Delvare738e5e02010-08-14 21:08:50 +02002046 sio_data->internal |= (1 << 1);
Jean Delvared9b327c2010-03-05 22:17:17 +01002047
Guenter Roeck9172b5d2012-03-24 21:49:54 -07002048 /*
2049 * On IT8782F, UART6 pins overlap with VIN5, VIN6, and VIN7.
2050 * While VIN7 can be routed to the internal voltage divider,
2051 * VIN5 and VIN6 are not available if UART6 is enabled.
Guenter Roeck4573acb2012-03-26 16:17:41 -07002052 *
2053 * Also, temp3 is not available if UART6 is enabled and TEMPIN3
2054 * is the temperature source. Since we can not read the
2055 * temperature source here, skip_temp is preliminary.
Guenter Roeck9172b5d2012-03-24 21:49:54 -07002056 */
Guenter Roeck4573acb2012-03-26 16:17:41 -07002057 if (uart6) {
Guenter Roeck9172b5d2012-03-24 21:49:54 -07002058 sio_data->skip_in |= (1 << 5) | (1 << 6);
Guenter Roeck4573acb2012-03-26 16:17:41 -07002059 sio_data->skip_temp |= (1 << 2);
2060 }
Guenter Roeck9172b5d2012-03-24 21:49:54 -07002061
Jean Delvared9b327c2010-03-05 22:17:17 +01002062 sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f;
Jean Delvare87673dd2006-08-28 14:37:19 +02002063 }
Jean Delvared9b327c2010-03-05 22:17:17 +01002064 if (sio_data->beep_pin)
Joe Perchesa8ca1032011-01-12 21:55:10 +01002065 pr_info("Beeping is supported\n");
Jean Delvare87673dd2006-08-28 14:37:19 +02002066
Jean Delvare98dd22c2008-10-09 15:33:58 +02002067 /* Disable specific features based on DMI strings */
2068 board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR);
2069 board_name = dmi_get_system_info(DMI_BOARD_NAME);
2070 if (board_vendor && board_name) {
2071 if (strcmp(board_vendor, "nVIDIA") == 0
2072 && strcmp(board_name, "FN68PT") == 0) {
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002073 /*
2074 * On the Shuttle SN68PT, FAN_CTL2 is apparently not
2075 * connected to a fan, but to something else. One user
2076 * has reported instant system power-off when changing
2077 * the PWM2 duty cycle, so we disable it.
2078 * I use the board name string as the trigger in case
2079 * the same board is ever used in other systems.
2080 */
Joe Perchesa8ca1032011-01-12 21:55:10 +01002081 pr_info("Disabling pwm2 due to hardware constraints\n");
Jean Delvare98dd22c2008-10-09 15:33:58 +02002082 sio_data->skip_pwm = (1 << 1);
2083 }
2084 }
2085
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086exit:
2087 superio_exit();
2088 return err;
2089}
2090
Jean Delvare723a0aa2010-03-05 22:17:16 +01002091static void it87_remove_files(struct device *dev)
2092{
2093 struct it87_data *data = platform_get_drvdata(pdev);
Jingoo Hana8b3a3a2013-07-30 17:13:06 +09002094 struct it87_sio_data *sio_data = dev_get_platdata(dev);
Jean Delvare723a0aa2010-03-05 22:17:16 +01002095 int i;
2096
2097 sysfs_remove_group(&dev->kobj, &it87_group);
Rudolf Marekc145d5c2014-01-29 20:40:08 +01002098 for (i = 0; i < 10; i++) {
Guenter Roeck9172b5d2012-03-24 21:49:54 -07002099 if (sio_data->skip_in & (1 << i))
2100 continue;
2101 sysfs_remove_group(&dev->kobj, &it87_group_in[i]);
2102 if (it87_attributes_in_beep[i])
2103 sysfs_remove_file(&dev->kobj,
2104 it87_attributes_in_beep[i]);
2105 }
Guenter Roeck4573acb2012-03-26 16:17:41 -07002106 for (i = 0; i < 3; i++) {
2107 if (!(data->has_temp & (1 << i)))
2108 continue;
2109 sysfs_remove_group(&dev->kobj, &it87_group_temp[i]);
Guenter Roeck161d8982012-12-19 22:17:01 +01002110 if (has_temp_offset(data))
2111 sysfs_remove_file(&dev->kobj,
2112 it87_attributes_temp_offset[i]);
Guenter Roeck4573acb2012-03-26 16:17:41 -07002113 if (sio_data->beep_pin)
2114 sysfs_remove_file(&dev->kobj,
2115 it87_attributes_temp_beep[i]);
2116 }
Jean Delvare723a0aa2010-03-05 22:17:16 +01002117 for (i = 0; i < 5; i++) {
2118 if (!(data->has_fan & (1 << i)))
2119 continue;
Guenter Roecke1169ba2012-12-19 22:17:01 +01002120 sysfs_remove_group(&dev->kobj, &it87_group_fan[i]);
Jean Delvared9b327c2010-03-05 22:17:17 +01002121 if (sio_data->beep_pin)
2122 sysfs_remove_file(&dev->kobj,
2123 it87_attributes_fan_beep[i]);
Guenter Roecke1169ba2012-12-19 22:17:01 +01002124 if (i < 3 && !has_16bit_fans(data))
2125 sysfs_remove_file(&dev->kobj,
2126 it87_attributes_fan_div[i]);
Jean Delvare723a0aa2010-03-05 22:17:16 +01002127 }
2128 for (i = 0; i < 3; i++) {
Guenter Roeck1696d1d2015-03-27 06:03:41 -07002129 if (sio_data->skip_pwm & (1 << i))
Jean Delvare723a0aa2010-03-05 22:17:16 +01002130 continue;
2131 sysfs_remove_group(&dev->kobj, &it87_group_pwm[i]);
Jean Delvare4f3f51b2010-03-05 22:17:21 +01002132 if (has_old_autopwm(data))
2133 sysfs_remove_group(&dev->kobj,
2134 &it87_group_autopwm[i]);
Jean Delvare723a0aa2010-03-05 22:17:16 +01002135 }
Jean Delvare6a8d7ac2010-03-05 22:17:16 +01002136 if (!sio_data->skip_vid)
2137 sysfs_remove_group(&dev->kobj, &it87_group_vid);
Jean Delvare738e5e02010-08-14 21:08:50 +02002138 sysfs_remove_group(&dev->kobj, &it87_group_label);
Jean Delvare723a0aa2010-03-05 22:17:16 +01002139}
2140
Bill Pemberton6c931ae2012-11-19 13:22:35 -05002141static int it87_probe(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 struct it87_data *data;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002144 struct resource *res;
2145 struct device *dev = &pdev->dev;
Jingoo Hana8b3a3a2013-07-30 17:13:06 +09002146 struct it87_sio_data *sio_data = dev_get_platdata(dev);
Jean Delvare723a0aa2010-03-05 22:17:16 +01002147 int err = 0, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 int enable_pwm_interface;
Jean Delvared9b327c2010-03-05 22:17:17 +01002149 int fan_beep_need_rw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002150
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002151 res = platform_get_resource(pdev, IORESOURCE_IO, 0);
Guenter Roeck62a1d052012-03-24 21:54:41 -07002152 if (!devm_request_region(&pdev->dev, res->start, IT87_EC_EXTENT,
2153 DRVNAME)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002154 dev_err(dev, "Failed to request region 0x%lx-0x%lx\n",
2155 (unsigned long)res->start,
Bjorn Helgaas87b4b662008-01-22 07:21:03 -05002156 (unsigned long)(res->start + IT87_EC_EXTENT - 1));
Guenter Roeck62a1d052012-03-24 21:54:41 -07002157 return -EBUSY;
Jean Delvare8e9afcb2006-12-12 18:18:28 +01002158 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159
Guenter Roeck62a1d052012-03-24 21:54:41 -07002160 data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL);
2161 if (!data)
2162 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002164 data->addr = res->start;
2165 data->type = sio_data->type;
Guenter Roeck483db432012-12-19 22:17:02 +01002166 data->features = it87_devices[sio_data->type].features;
Guenter Roeck5d8d2f22012-12-19 22:17:02 +01002167 data->peci_mask = it87_devices[sio_data->type].peci_mask;
Guenter Roeck19529782012-12-19 22:17:02 +01002168 data->old_peci_mask = it87_devices[sio_data->type].old_peci_mask;
Guenter Roeck483db432012-12-19 22:17:02 +01002169 data->name = it87_devices[sio_data->type].name;
2170 /*
2171 * IT8705F Datasheet 0.4.1, 3h == Version G.
2172 * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J.
2173 * These are the first revisions with 16-bit tachometer support.
2174 */
2175 switch (data->type) {
2176 case it87:
2177 if (sio_data->revision >= 0x03) {
2178 data->features &= ~FEAT_OLD_AUTOPWM;
Guenter Roeck9faf28c2015-02-12 07:11:38 -08002179 data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS;
Guenter Roeck483db432012-12-19 22:17:02 +01002180 }
2181 break;
2182 case it8712:
2183 if (sio_data->revision >= 0x08) {
2184 data->features &= ~FEAT_OLD_AUTOPWM;
Guenter Roeck9faf28c2015-02-12 07:11:38 -08002185 data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS |
2186 FEAT_FIVE_FANS;
Guenter Roeck483db432012-12-19 22:17:02 +01002187 }
2188 break;
2189 default:
2190 break;
2191 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192
2193 /* Now, we do the remaining detection. */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002194 if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002195 || it87_read_value(data, IT87_REG_CHIPID) != 0x90)
2196 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002197
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002198 platform_set_drvdata(pdev, data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199
Ingo Molnar9a61bf62006-01-18 23:19:26 +01002200 mutex_init(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 /* Check PWM configuration */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002203 enable_pwm_interface = it87_check_pwm(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204
Jean Delvare44c1bcd2010-10-28 20:31:51 +02002205 /* Starting with IT8721F, we handle scaling of internal voltages */
Jean Delvare16b5dda2012-01-16 22:51:48 +01002206 if (has_12mv_adc(data)) {
Jean Delvare44c1bcd2010-10-28 20:31:51 +02002207 if (sio_data->internal & (1 << 0))
2208 data->in_scaled |= (1 << 3); /* in3 is AVCC */
2209 if (sio_data->internal & (1 << 1))
2210 data->in_scaled |= (1 << 7); /* in7 is VSB */
2211 if (sio_data->internal & (1 << 2))
2212 data->in_scaled |= (1 << 8); /* in8 is Vbat */
Rudolf Marekc145d5c2014-01-29 20:40:08 +01002213 if (sio_data->internal & (1 << 3))
2214 data->in_scaled |= (1 << 9); /* in9 is AVCC */
Guenter Roeck7bc32d22015-01-17 14:10:24 -08002215 } else if (sio_data->type == it8781 || sio_data->type == it8782 ||
2216 sio_data->type == it8783) {
Guenter Roeck0531d982012-03-02 11:46:44 -08002217 if (sio_data->internal & (1 << 0))
2218 data->in_scaled |= (1 << 3); /* in3 is VCC5V */
2219 if (sio_data->internal & (1 << 1))
2220 data->in_scaled |= (1 << 7); /* in7 is VCCH5V */
Jean Delvare44c1bcd2010-10-28 20:31:51 +02002221 }
2222
Guenter Roeck4573acb2012-03-26 16:17:41 -07002223 data->has_temp = 0x07;
2224 if (sio_data->skip_temp & (1 << 2)) {
2225 if (sio_data->type == it8782
2226 && !(it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x80))
2227 data->has_temp &= ~(1 << 2);
2228 }
2229
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 /* Initialize the IT87 chip */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002231 it87_init_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
2233 /* Register sysfs hooks */
Jean Delvare5f2dc792010-03-05 22:17:18 +01002234 err = sysfs_create_group(&dev->kobj, &it87_group);
2235 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002236 return err;
Jean Delvare17d648b2006-08-28 14:23:46 +02002237
Rudolf Marekc145d5c2014-01-29 20:40:08 +01002238 for (i = 0; i < 10; i++) {
Guenter Roeck9172b5d2012-03-24 21:49:54 -07002239 if (sio_data->skip_in & (1 << i))
2240 continue;
2241 err = sysfs_create_group(&dev->kobj, &it87_group_in[i]);
2242 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002243 goto error;
Guenter Roeck9172b5d2012-03-24 21:49:54 -07002244 if (sio_data->beep_pin && it87_attributes_in_beep[i]) {
2245 err = sysfs_create_file(&dev->kobj,
2246 it87_attributes_in_beep[i]);
2247 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002248 goto error;
Guenter Roeck9172b5d2012-03-24 21:49:54 -07002249 }
2250 }
2251
Guenter Roeck4573acb2012-03-26 16:17:41 -07002252 for (i = 0; i < 3; i++) {
2253 if (!(data->has_temp & (1 << i)))
2254 continue;
2255 err = sysfs_create_group(&dev->kobj, &it87_group_temp[i]);
Jean Delvared9b327c2010-03-05 22:17:17 +01002256 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002257 goto error;
Guenter Roeck161d8982012-12-19 22:17:01 +01002258 if (has_temp_offset(data)) {
2259 err = sysfs_create_file(&dev->kobj,
2260 it87_attributes_temp_offset[i]);
2261 if (err)
2262 goto error;
2263 }
Guenter Roeck4573acb2012-03-26 16:17:41 -07002264 if (sio_data->beep_pin) {
2265 err = sysfs_create_file(&dev->kobj,
2266 it87_attributes_temp_beep[i]);
2267 if (err)
2268 goto error;
2269 }
Jean Delvared9b327c2010-03-05 22:17:17 +01002270 }
2271
Jean Delvare9060f8b2006-08-28 14:24:17 +02002272 /* Do not create fan files for disabled fans */
Jean Delvared9b327c2010-03-05 22:17:17 +01002273 fan_beep_need_rw = 1;
Jean Delvare723a0aa2010-03-05 22:17:16 +01002274 for (i = 0; i < 5; i++) {
2275 if (!(data->has_fan & (1 << i)))
2276 continue;
Guenter Roecke1169ba2012-12-19 22:17:01 +01002277 err = sysfs_create_group(&dev->kobj, &it87_group_fan[i]);
Jean Delvare723a0aa2010-03-05 22:17:16 +01002278 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002279 goto error;
Jean Delvared9b327c2010-03-05 22:17:17 +01002280
Guenter Roecke1169ba2012-12-19 22:17:01 +01002281 if (i < 3 && !has_16bit_fans(data)) {
2282 err = sysfs_create_file(&dev->kobj,
2283 it87_attributes_fan_div[i]);
2284 if (err)
2285 goto error;
2286 }
2287
Jean Delvared9b327c2010-03-05 22:17:17 +01002288 if (sio_data->beep_pin) {
2289 err = sysfs_create_file(&dev->kobj,
2290 it87_attributes_fan_beep[i]);
2291 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002292 goto error;
Jean Delvared9b327c2010-03-05 22:17:17 +01002293 if (!fan_beep_need_rw)
2294 continue;
2295
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002296 /*
2297 * As we have a single beep enable bit for all fans,
Jean Delvared9b327c2010-03-05 22:17:17 +01002298 * only the first enabled fan has a writable attribute
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002299 * for it.
2300 */
Jean Delvared9b327c2010-03-05 22:17:17 +01002301 if (sysfs_chmod_file(&dev->kobj,
2302 it87_attributes_fan_beep[i],
2303 S_IRUGO | S_IWUSR))
2304 dev_dbg(dev, "chmod +w fan%d_beep failed\n",
2305 i + 1);
2306 fan_beep_need_rw = 0;
2307 }
Jean Delvare17d648b2006-08-28 14:23:46 +02002308 }
2309
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310 if (enable_pwm_interface) {
Jean Delvare723a0aa2010-03-05 22:17:16 +01002311 for (i = 0; i < 3; i++) {
2312 if (sio_data->skip_pwm & (1 << i))
2313 continue;
2314 err = sysfs_create_group(&dev->kobj,
2315 &it87_group_pwm[i]);
2316 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002317 goto error;
Jean Delvare4f3f51b2010-03-05 22:17:21 +01002318
2319 if (!has_old_autopwm(data))
2320 continue;
2321 err = sysfs_create_group(&dev->kobj,
2322 &it87_group_autopwm[i]);
2323 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002324 goto error;
Jean Delvare98dd22c2008-10-09 15:33:58 +02002325 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 }
2327
Jean Delvare895ff262009-12-09 20:35:47 +01002328 if (!sio_data->skip_vid) {
Jean Delvare303760b2005-07-31 21:52:01 +02002329 data->vrm = vid_which_vrm();
Jean Delvare87673dd2006-08-28 14:37:19 +02002330 /* VID reading from Super-I/O config space if available */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002331 data->vid = sio_data->vid_value;
Jean Delvare6a8d7ac2010-03-05 22:17:16 +01002332 err = sysfs_create_group(&dev->kobj, &it87_group_vid);
2333 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002334 goto error;
Jean Delvare87808be2006-09-24 21:17:13 +02002335 }
2336
Jean Delvare738e5e02010-08-14 21:08:50 +02002337 /* Export labels for internal sensors */
Rudolf Marekc145d5c2014-01-29 20:40:08 +01002338 for (i = 0; i < 4; i++) {
Jean Delvare738e5e02010-08-14 21:08:50 +02002339 if (!(sio_data->internal & (1 << i)))
2340 continue;
2341 err = sysfs_create_file(&dev->kobj,
2342 it87_attributes_label[i]);
2343 if (err)
Guenter Roeck62a1d052012-03-24 21:54:41 -07002344 goto error;
Jean Delvare738e5e02010-08-14 21:08:50 +02002345 }
2346
Tony Jones1beeffe2007-08-20 13:46:20 -07002347 data->hwmon_dev = hwmon_device_register(dev);
2348 if (IS_ERR(data->hwmon_dev)) {
2349 err = PTR_ERR(data->hwmon_dev);
Guenter Roeck62a1d052012-03-24 21:54:41 -07002350 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351 }
2352
2353 return 0;
2354
Guenter Roeck62a1d052012-03-24 21:54:41 -07002355error:
Jean Delvare723a0aa2010-03-05 22:17:16 +01002356 it87_remove_files(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 return err;
2358}
2359
Bill Pemberton281dfd02012-11-19 13:25:51 -05002360static int it87_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002362 struct it87_data *data = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363
Tony Jones1beeffe2007-08-20 13:46:20 -07002364 hwmon_device_unregister(data->hwmon_dev);
Jean Delvare723a0aa2010-03-05 22:17:16 +01002365 it87_remove_files(&pdev->dev);
Mark M. Hoffman943b0832005-07-15 21:39:18 -04002366
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 return 0;
2368}
2369
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002370/*
2371 * Must be called with data->update_lock held, except during initialization.
2372 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
2373 * would slow down the IT87 access and should not be necessary.
2374 */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002375static int it87_read_value(struct it87_data *data, u8 reg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002377 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
2378 return inb_p(data->addr + IT87_DATA_REG_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379}
2380
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002381/*
2382 * Must be called with data->update_lock held, except during initialization.
2383 * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks,
2384 * would slow down the IT87 access and should not be necessary.
2385 */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002386static void it87_write_value(struct it87_data *data, u8 reg, u8 value)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002388 outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET);
2389 outb_p(value, data->addr + IT87_DATA_REG_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390}
2391
2392/* Return 1 if and only if the PWM interface is safe to use */
Bill Pemberton6c931ae2012-11-19 13:22:35 -05002393static int it87_check_pwm(struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002395 struct it87_data *data = dev_get_drvdata(dev);
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002396 /*
2397 * Some BIOSes fail to correctly configure the IT87 fans. All fans off
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 * and polarity set to active low is sign that this is the case so we
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002399 * disable pwm control to protect the user.
2400 */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002401 int tmp = it87_read_value(data, IT87_REG_FAN_CTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 if ((tmp & 0x87) == 0) {
2403 if (fix_pwm_polarity) {
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002404 /*
2405 * The user asks us to attempt a chip reconfiguration.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 * This means switching to active high polarity and
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002407 * inverting all fan speed values.
2408 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 int i;
2410 u8 pwm[3];
2411
2412 for (i = 0; i < 3; i++)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002413 pwm[i] = it87_read_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 IT87_REG_PWM(i));
2415
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002416 /*
2417 * If any fan is in automatic pwm mode, the polarity
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 * might be correct, as suspicious as it seems, so we
2419 * better don't change anything (but still disable the
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002420 * PWM interface).
2421 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) {
Guenter Roeck1d9bcf62012-12-19 22:17:01 +01002423 dev_info(dev,
2424 "Reconfiguring PWM to active high polarity\n");
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002425 it87_write_value(data, IT87_REG_FAN_CTL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 tmp | 0x87);
2427 for (i = 0; i < 3; i++)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002428 it87_write_value(data,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 IT87_REG_PWM(i),
2430 0x7f & ~pwm[i]);
2431 return 1;
2432 }
2433
Guenter Roeck1d9bcf62012-12-19 22:17:01 +01002434 dev_info(dev,
2435 "PWM configuration is too broken to be fixed\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 }
2437
Guenter Roeck1d9bcf62012-12-19 22:17:01 +01002438 dev_info(dev,
2439 "Detected broken BIOS defaults, disabling PWM interface\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 return 0;
2441 } else if (fix_pwm_polarity) {
Guenter Roeck1d9bcf62012-12-19 22:17:01 +01002442 dev_info(dev,
2443 "PWM configuration looks sane, won't touch\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 }
2445
2446 return 1;
2447}
2448
2449/* Called when we have found a new IT87. */
Bill Pemberton6c931ae2012-11-19 13:22:35 -05002450static void it87_init_device(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451{
Jingoo Hana8b3a3a2013-07-30 17:13:06 +09002452 struct it87_sio_data *sio_data = dev_get_platdata(&pdev->dev);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002453 struct it87_data *data = platform_get_drvdata(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 int tmp, i;
Jean Delvare591ec652009-12-09 20:35:48 +01002455 u8 mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002457 /*
2458 * For each PWM channel:
Jean Delvareb99883d2010-03-05 22:17:15 +01002459 * - If it is in automatic mode, setting to manual mode should set
2460 * the fan to full speed by default.
2461 * - If it is in manual mode, we need a mapping to temperature
2462 * channels to use when later setting to automatic mode later.
2463 * Use a 1:1 mapping by default (we are clueless.)
2464 * In both cases, the value can (and should) be changed by the user
Jean Delvare6229cdb2010-12-08 16:27:22 +01002465 * prior to switching to a different mode.
2466 * Note that this is no longer needed for the IT8721F and later, as
2467 * these have separate registers for the temperature mapping and the
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002468 * manual duty cycle.
2469 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 for (i = 0; i < 3; i++) {
Jean Delvareb99883d2010-03-05 22:17:15 +01002471 data->pwm_temp_map[i] = i;
2472 data->pwm_duty[i] = 0x7f; /* Full speed */
Jean Delvare4f3f51b2010-03-05 22:17:21 +01002473 data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 }
2475
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002476 /*
2477 * Some chips seem to have default value 0xff for all limit
Jean Delvarec5df9b72006-08-28 14:37:54 +02002478 * registers. For low voltage limits it makes no sense and triggers
2479 * alarms, so change to 0 instead. For high temperature limits, it
2480 * means -1 degree C, which surprisingly doesn't trigger an alarm,
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002481 * but is still confusing, so change to 127 degrees C.
2482 */
Jean Delvarec5df9b72006-08-28 14:37:54 +02002483 for (i = 0; i < 8; i++) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002484 tmp = it87_read_value(data, IT87_REG_VIN_MIN(i));
Jean Delvarec5df9b72006-08-28 14:37:54 +02002485 if (tmp == 0xff)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002486 it87_write_value(data, IT87_REG_VIN_MIN(i), 0);
Jean Delvarec5df9b72006-08-28 14:37:54 +02002487 }
2488 for (i = 0; i < 3; i++) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002489 tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i));
Jean Delvarec5df9b72006-08-28 14:37:54 +02002490 if (tmp == 0xff)
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002491 it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127);
Jean Delvarec5df9b72006-08-28 14:37:54 +02002492 }
2493
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002494 /*
2495 * Temperature channels are not forcibly enabled, as they can be
Jean Delvarea00afb92010-04-14 16:14:09 +02002496 * set to two different sensor types and we can't guess which one
2497 * is correct for a given system. These channels can be enabled at
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002498 * run-time through the temp{1-3}_type sysfs accessors if needed.
2499 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500
2501 /* Check if voltage monitors are reset manually or by some reason */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002502 tmp = it87_read_value(data, IT87_REG_VIN_ENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 if ((tmp & 0xff) == 0) {
2504 /* Enable all voltage monitors */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002505 it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 }
2507
2508 /* Check if tachometers are reset manually or by some reason */
Jean Delvare591ec652009-12-09 20:35:48 +01002509 mask = 0x70 & ~(sio_data->skip_fan << 4);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002510 data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL);
Jean Delvare591ec652009-12-09 20:35:48 +01002511 if ((data->fan_main_ctrl & mask) == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 /* Enable all fan tachometers */
Jean Delvare591ec652009-12-09 20:35:48 +01002513 data->fan_main_ctrl |= mask;
Jean Delvare5f2dc792010-03-05 22:17:18 +01002514 it87_write_value(data, IT87_REG_FAN_MAIN_CTRL,
2515 data->fan_main_ctrl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 }
Jean Delvare9060f8b2006-08-28 14:24:17 +02002517 data->has_fan = (data->fan_main_ctrl >> 4) & 0x07;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518
Guenter Roeck9faf28c2015-02-12 07:11:38 -08002519 /* Set tachometers to 16-bit mode if needed */
2520 if (has_fan16_config(data)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002521 tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
Jean Delvare9060f8b2006-08-28 14:24:17 +02002522 if (~tmp & 0x07 & data->has_fan) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002523 dev_dbg(&pdev->dev,
Jean Delvare17d648b2006-08-28 14:23:46 +02002524 "Setting fan1-3 to 16-bit mode\n");
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002525 it87_write_value(data, IT87_REG_FAN_16BIT,
Jean Delvare17d648b2006-08-28 14:23:46 +02002526 tmp | 0x07);
2527 }
Guenter Roeck9faf28c2015-02-12 07:11:38 -08002528 }
2529
2530 /* Check for additional fans */
2531 if (has_five_fans(data)) {
2532 tmp = it87_read_value(data, IT87_REG_FAN_16BIT);
2533 if (tmp & (1 << 4))
2534 data->has_fan |= (1 << 3); /* fan4 enabled */
2535 if (tmp & (1 << 5))
2536 data->has_fan |= (1 << 4); /* fan5 enabled */
Jean Delvare17d648b2006-08-28 14:23:46 +02002537 }
2538
Jean Delvare591ec652009-12-09 20:35:48 +01002539 /* Fan input pins may be used for alternative functions */
2540 data->has_fan &= ~sio_data->skip_fan;
2541
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 /* Start monitoring */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002543 it87_write_value(data, IT87_REG_CONFIG,
Jean Delvare41002f82012-07-12 22:47:37 +02002544 (it87_read_value(data, IT87_REG_CONFIG) & 0x3e)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 | (update_vbat ? 0x41 : 0x01));
2546}
2547
Jean Delvareb99883d2010-03-05 22:17:15 +01002548static void it87_update_pwm_ctrl(struct it87_data *data, int nr)
2549{
2550 data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM(nr));
Jean Delvare16b5dda2012-01-16 22:51:48 +01002551 if (has_newer_autopwm(data)) {
Jean Delvareb99883d2010-03-05 22:17:15 +01002552 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
Jean Delvare6229cdb2010-12-08 16:27:22 +01002553 data->pwm_duty[nr] = it87_read_value(data,
2554 IT87_REG_PWM_DUTY(nr));
2555 } else {
2556 if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */
2557 data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03;
2558 else /* Manual mode */
2559 data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f;
2560 }
Jean Delvare4f3f51b2010-03-05 22:17:21 +01002561
2562 if (has_old_autopwm(data)) {
2563 int i;
2564
2565 for (i = 0; i < 5 ; i++)
2566 data->auto_temp[nr][i] = it87_read_value(data,
2567 IT87_REG_AUTO_TEMP(nr, i));
2568 for (i = 0; i < 3 ; i++)
2569 data->auto_pwm[nr][i] = it87_read_value(data,
2570 IT87_REG_AUTO_PWM(nr, i));
2571 }
Jean Delvareb99883d2010-03-05 22:17:15 +01002572}
2573
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574static struct it87_data *it87_update_device(struct device *dev)
2575{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002576 struct it87_data *data = dev_get_drvdata(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 int i;
2578
Ingo Molnar9a61bf62006-01-18 23:19:26 +01002579 mutex_lock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580
2581 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
2582 || !data->valid) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 if (update_vbat) {
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002584 /*
2585 * Cleared after each update, so reenable. Value
2586 * returned by this read will be previous value
2587 */
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002588 it87_write_value(data, IT87_REG_CONFIG,
Jean Delvare5f2dc792010-03-05 22:17:18 +01002589 it87_read_value(data, IT87_REG_CONFIG) | 0x40);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 }
2591 for (i = 0; i <= 7; i++) {
Guenter Roeck929c6a52012-12-19 22:17:00 +01002592 data->in[i][0] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01002593 it87_read_value(data, IT87_REG_VIN(i));
Guenter Roeck929c6a52012-12-19 22:17:00 +01002594 data->in[i][1] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01002595 it87_read_value(data, IT87_REG_VIN_MIN(i));
Guenter Roeck929c6a52012-12-19 22:17:00 +01002596 data->in[i][2] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01002597 it87_read_value(data, IT87_REG_VIN_MAX(i));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 }
Jean Delvare3543a532006-08-28 14:27:25 +02002599 /* in8 (battery) has no limit registers */
Guenter Roeck929c6a52012-12-19 22:17:00 +01002600 data->in[8][0] = it87_read_value(data, IT87_REG_VIN(8));
Rudolf Marekc145d5c2014-01-29 20:40:08 +01002601 if (data->type == it8603)
2602 data->in[9][0] = it87_read_value(data, 0x2f);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603
Jean Delvarec7f1f712007-09-03 17:11:46 +02002604 for (i = 0; i < 5; i++) {
Jean Delvare9060f8b2006-08-28 14:24:17 +02002605 /* Skip disabled fans */
2606 if (!(data->has_fan & (1 << i)))
2607 continue;
2608
Guenter Roecke1169ba2012-12-19 22:17:01 +01002609 data->fan[i][1] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01002610 it87_read_value(data, IT87_REG_FAN_MIN[i]);
Guenter Roecke1169ba2012-12-19 22:17:01 +01002611 data->fan[i][0] = it87_read_value(data,
Jean Delvarec7f1f712007-09-03 17:11:46 +02002612 IT87_REG_FAN[i]);
Jean Delvare17d648b2006-08-28 14:23:46 +02002613 /* Add high byte if in 16-bit mode */
Andrew Paprocki04751692008-08-06 22:41:06 +02002614 if (has_16bit_fans(data)) {
Guenter Roecke1169ba2012-12-19 22:17:01 +01002615 data->fan[i][0] |= it87_read_value(data,
Jean Delvarec7f1f712007-09-03 17:11:46 +02002616 IT87_REG_FANX[i]) << 8;
Guenter Roecke1169ba2012-12-19 22:17:01 +01002617 data->fan[i][1] |= it87_read_value(data,
Jean Delvarec7f1f712007-09-03 17:11:46 +02002618 IT87_REG_FANX_MIN[i]) << 8;
Jean Delvare17d648b2006-08-28 14:23:46 +02002619 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 }
2621 for (i = 0; i < 3; i++) {
Guenter Roeck4573acb2012-03-26 16:17:41 -07002622 if (!(data->has_temp & (1 << i)))
2623 continue;
Guenter Roeck60ca3852012-12-19 22:17:00 +01002624 data->temp[i][0] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01002625 it87_read_value(data, IT87_REG_TEMP(i));
Guenter Roeck60ca3852012-12-19 22:17:00 +01002626 data->temp[i][1] =
Jean Delvare5f2dc792010-03-05 22:17:18 +01002627 it87_read_value(data, IT87_REG_TEMP_LOW(i));
Guenter Roeck60ca3852012-12-19 22:17:00 +01002628 data->temp[i][2] =
2629 it87_read_value(data, IT87_REG_TEMP_HIGH(i));
Guenter Roeck161d8982012-12-19 22:17:01 +01002630 if (has_temp_offset(data))
2631 data->temp[i][3] =
2632 it87_read_value(data,
2633 IT87_REG_TEMP_OFFSET[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 }
2635
Jean Delvare17d648b2006-08-28 14:23:46 +02002636 /* Newer chips don't have clock dividers */
Andrew Paprocki04751692008-08-06 22:41:06 +02002637 if ((data->has_fan & 0x07) && !has_16bit_fans(data)) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002638 i = it87_read_value(data, IT87_REG_FAN_DIV);
Jean Delvare17d648b2006-08-28 14:23:46 +02002639 data->fan_div[0] = i & 0x07;
2640 data->fan_div[1] = (i >> 3) & 0x07;
2641 data->fan_div[2] = (i & 0x40) ? 3 : 1;
2642 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643
2644 data->alarms =
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002645 it87_read_value(data, IT87_REG_ALARM1) |
2646 (it87_read_value(data, IT87_REG_ALARM2) << 8) |
2647 (it87_read_value(data, IT87_REG_ALARM3) << 16);
Jean Delvared9b327c2010-03-05 22:17:17 +01002648 data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE);
Jean Delvareb99883d2010-03-05 22:17:15 +01002649
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002650 data->fan_main_ctrl = it87_read_value(data,
2651 IT87_REG_FAN_MAIN_CTRL);
2652 data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL);
Jean Delvareb99883d2010-03-05 22:17:15 +01002653 for (i = 0; i < 3; i++)
2654 it87_update_pwm_ctrl(data, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002656 data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE);
Guenter Roeck19529782012-12-19 22:17:02 +01002657 data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA);
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002658 /*
2659 * The IT8705F does not have VID capability.
2660 * The IT8718F and later don't use IT87_REG_VID for the
2661 * same purpose.
2662 */
Jean Delvare17d648b2006-08-28 14:23:46 +02002663 if (data->type == it8712 || data->type == it8716) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002664 data->vid = it87_read_value(data, IT87_REG_VID);
Guenter Roeck4a0d71c2012-01-19 11:02:18 -08002665 /*
2666 * The older IT8712F revisions had only 5 VID pins,
2667 * but we assume it is always safe to read 6 bits.
2668 */
Jean Delvare17d648b2006-08-28 14:23:46 +02002669 data->vid &= 0x3f;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 }
2671 data->last_updated = jiffies;
2672 data->valid = 1;
2673 }
2674
Ingo Molnar9a61bf62006-01-18 23:19:26 +01002675 mutex_unlock(&data->update_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676
2677 return data;
2678}
2679
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002680static int __init it87_device_add(unsigned short address,
2681 const struct it87_sio_data *sio_data)
2682{
2683 struct resource res = {
Bjorn Helgaas87b4b662008-01-22 07:21:03 -05002684 .start = address + IT87_EC_OFFSET,
2685 .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1,
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002686 .name = DRVNAME,
2687 .flags = IORESOURCE_IO,
2688 };
2689 int err;
2690
Jean Delvareb9acb642009-01-07 16:37:35 +01002691 err = acpi_check_resource_conflict(&res);
2692 if (err)
2693 goto exit;
2694
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002695 pdev = platform_device_alloc(DRVNAME, address);
2696 if (!pdev) {
2697 err = -ENOMEM;
Joe Perchesa8ca1032011-01-12 21:55:10 +01002698 pr_err("Device allocation failed\n");
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002699 goto exit;
2700 }
2701
2702 err = platform_device_add_resources(pdev, &res, 1);
2703 if (err) {
Joe Perchesa8ca1032011-01-12 21:55:10 +01002704 pr_err("Device resource addition failed (%d)\n", err);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002705 goto exit_device_put;
2706 }
2707
2708 err = platform_device_add_data(pdev, sio_data,
2709 sizeof(struct it87_sio_data));
2710 if (err) {
Joe Perchesa8ca1032011-01-12 21:55:10 +01002711 pr_err("Platform data allocation failed\n");
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002712 goto exit_device_put;
2713 }
2714
2715 err = platform_device_add(pdev);
2716 if (err) {
Joe Perchesa8ca1032011-01-12 21:55:10 +01002717 pr_err("Device addition failed (%d)\n", err);
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002718 goto exit_device_put;
2719 }
2720
2721 return 0;
2722
2723exit_device_put:
2724 platform_device_put(pdev);
2725exit:
2726 return err;
2727}
2728
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729static int __init sm_it87_init(void)
2730{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002731 int err;
Jean Delvare5f2dc792010-03-05 22:17:18 +01002732 unsigned short isa_address = 0;
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002733 struct it87_sio_data sio_data;
Jean Delvarefde09502005-07-19 23:51:07 +02002734
Jean Delvare98dd22c2008-10-09 15:33:58 +02002735 memset(&sio_data, 0, sizeof(struct it87_sio_data));
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002736 err = it87_find(&isa_address, &sio_data);
2737 if (err)
2738 return err;
2739 err = platform_driver_register(&it87_driver);
2740 if (err)
2741 return err;
2742
2743 err = it87_device_add(isa_address, &sio_data);
Jean Delvare5f2dc792010-03-05 22:17:18 +01002744 if (err) {
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002745 platform_driver_unregister(&it87_driver);
2746 return err;
2747 }
2748
2749 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750}
2751
2752static void __exit sm_it87_exit(void)
2753{
corentin.labbeb74f3fd2007-06-13 20:27:36 +02002754 platform_device_unregister(pdev);
2755 platform_driver_unregister(&it87_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756}
2757
2758
Jean Delvare7c81c602014-01-29 20:40:08 +01002759MODULE_AUTHOR("Chris Gauthron, Jean Delvare <jdelvare@suse.de>");
Jean Delvare44c1bcd2010-10-28 20:31:51 +02002760MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761module_param(update_vbat, bool, 0);
2762MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value");
2763module_param(fix_pwm_polarity, bool, 0);
Jean Delvare5f2dc792010-03-05 22:17:18 +01002764MODULE_PARM_DESC(fix_pwm_polarity,
2765 "Force PWM polarity to active high (DANGEROUS)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766MODULE_LICENSE("GPL");
2767
2768module_init(sm_it87_init);
2769module_exit(sm_it87_exit);