Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2 | * 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 Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 13 | * Supports: IT8603E Super I/O chip w/LPC interface |
Rudolf Marek | 574e9bd | 2014-04-04 18:01:35 +0200 | [diff] [blame] | 14 | * IT8623E Super I/O chip w/LPC interface |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 15 | * IT8705F Super I/O chip w/LPC interface |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 16 | * 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 Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 20 | * IT8721F Super I/O chip w/LPC interface |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 21 | * IT8726F Super I/O chip w/LPC interface |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 22 | * IT8728F Super I/O chip w/LPC interface |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 23 | * IT8758E Super I/O chip w/LPC interface |
Guenter Roeck | b063670 | 2012-09-07 17:34:41 -0600 | [diff] [blame] | 24 | * IT8771E Super I/O chip w/LPC interface |
| 25 | * IT8772E Super I/O chip w/LPC interface |
Guenter Roeck | 7bc32d2 | 2015-01-17 14:10:24 -0800 | [diff] [blame] | 26 | * IT8781F Super I/O chip w/LPC interface |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 27 | * IT8782F Super I/O chip w/LPC interface |
| 28 | * IT8783E/F Super I/O chip w/LPC interface |
Thomas Lorblanches | a0c1424 | 2015-02-13 13:19:06 +0100 | [diff] [blame] | 29 | * IT8786E Super I/O chip w/LPC interface |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 30 | * Sis950 A clone of the IT8705F |
| 31 | * |
| 32 | * Copyright (C) 2001 Chris Gauthron |
Jean Delvare | 7c81c60 | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 33 | * Copyright (C) 2005-2010 Jean Delvare <jdelvare@suse.de> |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 34 | * |
| 35 | * This program is free software; you can redistribute it and/or modify |
| 36 | * it under the terms of the GNU General Public License as published by |
| 37 | * the Free Software Foundation; either version 2 of the License, or |
| 38 | * (at your option) any later version. |
| 39 | * |
| 40 | * This program is distributed in the hope that it will be useful, |
| 41 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 42 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 43 | * GNU General Public License for more details. |
| 44 | * |
| 45 | * You should have received a copy of the GNU General Public License |
| 46 | * along with this program; if not, write to the Free Software |
| 47 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 48 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 50 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <linux/module.h> |
| 53 | #include <linux/init.h> |
| 54 | #include <linux/slab.h> |
| 55 | #include <linux/jiffies.h> |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 56 | #include <linux/platform_device.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 57 | #include <linux/hwmon.h> |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 58 | #include <linux/hwmon-sysfs.h> |
| 59 | #include <linux/hwmon-vid.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 60 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 61 | #include <linux/mutex.h> |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 62 | #include <linux/sysfs.h> |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 63 | #include <linux/string.h> |
| 64 | #include <linux/dmi.h> |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 65 | #include <linux/acpi.h> |
H Hartley Sweeten | 6055fae | 2009-09-15 17:18:13 +0200 | [diff] [blame] | 66 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 68 | #define DRVNAME "it87" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Guenter Roeck | b063670 | 2012-09-07 17:34:41 -0600 | [diff] [blame] | 70 | enum chips { it87, it8712, it8716, it8718, it8720, it8721, it8728, it8771, |
Thomas Lorblanches | a0c1424 | 2015-02-13 13:19:06 +0100 | [diff] [blame] | 71 | it8772, it8781, it8782, it8783, it8786, it8603 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 73 | static unsigned short force_id; |
| 74 | module_param(force_id, ushort, 0); |
| 75 | MODULE_PARM_DESC(force_id, "Override the detected device ID"); |
| 76 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 77 | static struct platform_device *pdev; |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | #define REG 0x2e /* The register to read/write */ |
| 80 | #define DEV 0x07 /* Register: Logical device select */ |
| 81 | #define VAL 0x2f /* The value to read/write */ |
| 82 | #define PME 0x04 /* The device with the fan registers in it */ |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 83 | |
| 84 | /* The device with the IT8718F/IT8720F VID value in it */ |
| 85 | #define GPIO 0x07 |
| 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | #define DEVID 0x20 /* Register: Device ID */ |
| 88 | #define DEVREV 0x22 /* Register: Device Revision */ |
| 89 | |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 90 | static inline int superio_inb(int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
| 92 | outb(reg, REG); |
| 93 | return inb(VAL); |
| 94 | } |
| 95 | |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 96 | static inline void superio_outb(int reg, int val) |
Jean Delvare | 436cad2 | 2010-07-09 16:22:48 +0200 | [diff] [blame] | 97 | { |
| 98 | outb(reg, REG); |
| 99 | outb(val, VAL); |
| 100 | } |
| 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | static int superio_inw(int reg) |
| 103 | { |
| 104 | int val; |
| 105 | outb(reg++, REG); |
| 106 | val = inb(VAL) << 8; |
| 107 | outb(reg, REG); |
| 108 | val |= inb(VAL); |
| 109 | return val; |
| 110 | } |
| 111 | |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 112 | static inline void superio_select(int ldn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | { |
| 114 | outb(DEV, REG); |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 115 | outb(ldn, VAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 118 | static inline int superio_enter(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | { |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 120 | /* |
| 121 | * Try to reserve REG and REG + 1 for exclusive access. |
| 122 | */ |
| 123 | if (!request_muxed_region(REG, 2, DRVNAME)) |
| 124 | return -EBUSY; |
| 125 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | outb(0x87, REG); |
| 127 | outb(0x01, REG); |
| 128 | outb(0x55, REG); |
| 129 | outb(0x55, REG); |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 130 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 133 | static inline void superio_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | { |
| 135 | outb(0x02, REG); |
| 136 | outb(0x02, VAL); |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 137 | release_region(REG, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 140 | /* Logical device 4 registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | #define IT8712F_DEVID 0x8712 |
| 142 | #define IT8705F_DEVID 0x8705 |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 143 | #define IT8716F_DEVID 0x8716 |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 144 | #define IT8718F_DEVID 0x8718 |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 145 | #define IT8720F_DEVID 0x8720 |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 146 | #define IT8721F_DEVID 0x8721 |
Rudolf Marek | 08a8f6e | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 147 | #define IT8726F_DEVID 0x8726 |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 148 | #define IT8728F_DEVID 0x8728 |
Guenter Roeck | b063670 | 2012-09-07 17:34:41 -0600 | [diff] [blame] | 149 | #define IT8771E_DEVID 0x8771 |
| 150 | #define IT8772E_DEVID 0x8772 |
Guenter Roeck | 7bc32d2 | 2015-01-17 14:10:24 -0800 | [diff] [blame] | 151 | #define IT8781F_DEVID 0x8781 |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 152 | #define IT8782F_DEVID 0x8782 |
| 153 | #define IT8783E_DEVID 0x8783 |
Thomas Lorblanches | a0c1424 | 2015-02-13 13:19:06 +0100 | [diff] [blame] | 154 | #define IT8786E_DEVID 0x8786 |
Rudolf Marek | 7183ae8 | 2014-04-04 18:01:35 +0200 | [diff] [blame] | 155 | #define IT8603E_DEVID 0x8603 |
Rudolf Marek | 574e9bd | 2014-04-04 18:01:35 +0200 | [diff] [blame] | 156 | #define IT8623E_DEVID 0x8623 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | #define IT87_ACT_REG 0x30 |
| 158 | #define IT87_BASE_REG 0x60 |
| 159 | |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 160 | /* Logical device 7 registers (IT8712F and later) */ |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 161 | #define IT87_SIO_GPIO1_REG 0x25 |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 162 | #define IT87_SIO_GPIO3_REG 0x27 |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 163 | #define IT87_SIO_GPIO5_REG 0x29 |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 164 | #define IT87_SIO_PINX1_REG 0x2a /* Pin selection */ |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 165 | #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */ |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 166 | #define IT87_SIO_SPI_REG 0xef /* SPI function pin select */ |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 167 | #define IT87_SIO_VID_REG 0xfc /* VID value */ |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 168 | #define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */ |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | /* Update battery voltage after every reading if true */ |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 171 | static bool update_vbat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | |
| 173 | /* Not all BIOSes properly configure the PWM registers */ |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame] | 174 | static bool fix_pwm_polarity; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 | /* Many IT87 constants specified below */ |
| 177 | |
| 178 | /* Length of ISA address segment */ |
| 179 | #define IT87_EXTENT 8 |
| 180 | |
Bjorn Helgaas | 87b4b66 | 2008-01-22 07:21:03 -0500 | [diff] [blame] | 181 | /* Length of ISA address segment for Environmental Controller */ |
| 182 | #define IT87_EC_EXTENT 2 |
| 183 | |
| 184 | /* Offset of EC registers from ISA base address */ |
| 185 | #define IT87_EC_OFFSET 5 |
| 186 | |
| 187 | /* Where are the ISA address/data registers relative to the EC base address */ |
| 188 | #define IT87_ADDR_REG_OFFSET 0 |
| 189 | #define IT87_DATA_REG_OFFSET 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
| 191 | /*----- The IT87 registers -----*/ |
| 192 | |
| 193 | #define IT87_REG_CONFIG 0x00 |
| 194 | |
| 195 | #define IT87_REG_ALARM1 0x01 |
| 196 | #define IT87_REG_ALARM2 0x02 |
| 197 | #define IT87_REG_ALARM3 0x03 |
| 198 | |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 199 | /* |
| 200 | * The IT8718F and IT8720F have the VID value in a different register, in |
| 201 | * Super-I/O configuration space. |
| 202 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | #define IT87_REG_VID 0x0a |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 204 | /* |
| 205 | * The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b |
| 206 | * for fan divisors. Later IT8712F revisions must use 16-bit tachometer |
| 207 | * mode. |
| 208 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | #define IT87_REG_FAN_DIV 0x0b |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 210 | #define IT87_REG_FAN_16BIT 0x0c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
| 212 | /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */ |
| 213 | |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 214 | static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 }; |
| 215 | static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 }; |
| 216 | static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 }; |
| 217 | static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 }; |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 218 | static const u8 IT87_REG_TEMP_OFFSET[] = { 0x56, 0x57, 0x59 }; |
| 219 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | #define IT87_REG_FAN_MAIN_CTRL 0x13 |
| 221 | #define IT87_REG_FAN_CTL 0x14 |
| 222 | #define IT87_REG_PWM(nr) (0x15 + (nr)) |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 223 | #define IT87_REG_PWM_DUTY(nr) (0x63 + (nr) * 8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
| 225 | #define IT87_REG_VIN(nr) (0x20 + (nr)) |
| 226 | #define IT87_REG_TEMP(nr) (0x29 + (nr)) |
| 227 | |
| 228 | #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2) |
| 229 | #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2) |
| 230 | #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2) |
| 231 | #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2) |
| 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | #define IT87_REG_VIN_ENABLE 0x50 |
| 234 | #define IT87_REG_TEMP_ENABLE 0x51 |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 235 | #define IT87_REG_TEMP_EXTRA 0x55 |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 236 | #define IT87_REG_BEEP_ENABLE 0x5c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
| 238 | #define IT87_REG_CHIPID 0x58 |
| 239 | |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 240 | #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i)) |
| 241 | #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i)) |
| 242 | |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 243 | struct it87_devices { |
| 244 | const char *name; |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 245 | const char * const suffix; |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 246 | u16 features; |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 247 | u8 peci_mask; |
| 248 | u8 old_peci_mask; |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 249 | }; |
| 250 | |
| 251 | #define FEAT_12MV_ADC (1 << 0) |
| 252 | #define FEAT_NEWER_AUTOPWM (1 << 1) |
| 253 | #define FEAT_OLD_AUTOPWM (1 << 2) |
| 254 | #define FEAT_16BIT_FANS (1 << 3) |
| 255 | #define FEAT_TEMP_OFFSET (1 << 4) |
Guenter Roeck | 5d8d2f2 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 256 | #define FEAT_TEMP_PECI (1 << 5) |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 257 | #define FEAT_TEMP_OLD_PECI (1 << 6) |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 258 | #define FEAT_FAN16_CONFIG (1 << 7) /* Need to enable 16-bit fans */ |
| 259 | #define FEAT_FIVE_FANS (1 << 8) /* Supports five fans */ |
Guenter Roeck | 32dd7c4 | 2015-02-12 07:40:23 -0800 | [diff] [blame] | 260 | #define FEAT_VID (1 << 9) /* Set if chip supports VID */ |
Guenter Roeck | 7f5726c | 2015-03-26 08:49:18 -0700 | [diff] [blame^] | 261 | #define FEAT_IN7_INTERNAL (1 << 10) /* Set if in7 is internal */ |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 262 | |
| 263 | static const struct it87_devices it87_devices[] = { |
| 264 | [it87] = { |
| 265 | .name = "it87", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 266 | .suffix = "F", |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 267 | .features = FEAT_OLD_AUTOPWM, /* may need to overwrite */ |
| 268 | }, |
| 269 | [it8712] = { |
| 270 | .name = "it8712", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 271 | .suffix = "F", |
Guenter Roeck | 32dd7c4 | 2015-02-12 07:40:23 -0800 | [diff] [blame] | 272 | .features = FEAT_OLD_AUTOPWM | FEAT_VID, |
| 273 | /* may need to overwrite */ |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 274 | }, |
| 275 | [it8716] = { |
| 276 | .name = "it8716", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 277 | .suffix = "F", |
Guenter Roeck | 32dd7c4 | 2015-02-12 07:40:23 -0800 | [diff] [blame] | 278 | .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 279 | | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS, |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 280 | }, |
| 281 | [it8718] = { |
| 282 | .name = "it8718", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 283 | .suffix = "F", |
Guenter Roeck | 32dd7c4 | 2015-02-12 07:40:23 -0800 | [diff] [blame] | 284 | .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 285 | | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS, |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 286 | .old_peci_mask = 0x4, |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 287 | }, |
| 288 | [it8720] = { |
| 289 | .name = "it8720", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 290 | .suffix = "F", |
Guenter Roeck | 32dd7c4 | 2015-02-12 07:40:23 -0800 | [diff] [blame] | 291 | .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET | FEAT_VID |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 292 | | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS, |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 293 | .old_peci_mask = 0x4, |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 294 | }, |
| 295 | [it8721] = { |
| 296 | .name = "it8721", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 297 | .suffix = "F", |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 298 | .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 299 | | FEAT_TEMP_OFFSET | FEAT_TEMP_OLD_PECI | FEAT_TEMP_PECI |
Guenter Roeck | 7f5726c | 2015-03-26 08:49:18 -0700 | [diff] [blame^] | 300 | | FEAT_FAN16_CONFIG | FEAT_FIVE_FANS | FEAT_IN7_INTERNAL, |
Guenter Roeck | 5d8d2f2 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 301 | .peci_mask = 0x05, |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 302 | .old_peci_mask = 0x02, /* Actually reports PCH */ |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 303 | }, |
| 304 | [it8728] = { |
| 305 | .name = "it8728", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 306 | .suffix = "F", |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 307 | .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS |
Guenter Roeck | 7f5726c | 2015-03-26 08:49:18 -0700 | [diff] [blame^] | 308 | | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_FIVE_FANS |
| 309 | | FEAT_IN7_INTERNAL, |
Guenter Roeck | 5d8d2f2 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 310 | .peci_mask = 0x07, |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 311 | }, |
Guenter Roeck | b063670 | 2012-09-07 17:34:41 -0600 | [diff] [blame] | 312 | [it8771] = { |
| 313 | .name = "it8771", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 314 | .suffix = "E", |
Guenter Roeck | b063670 | 2012-09-07 17:34:41 -0600 | [diff] [blame] | 315 | .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS |
Guenter Roeck | 7f5726c | 2015-03-26 08:49:18 -0700 | [diff] [blame^] | 316 | | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL, |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 317 | /* PECI: guesswork */ |
| 318 | /* 12mV ADC (OHM) */ |
| 319 | /* 16 bit fans (OHM) */ |
| 320 | /* three fans, always 16 bit (guesswork) */ |
Guenter Roeck | b063670 | 2012-09-07 17:34:41 -0600 | [diff] [blame] | 321 | .peci_mask = 0x07, |
| 322 | }, |
| 323 | [it8772] = { |
| 324 | .name = "it8772", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 325 | .suffix = "E", |
Guenter Roeck | b063670 | 2012-09-07 17:34:41 -0600 | [diff] [blame] | 326 | .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS |
Guenter Roeck | 7f5726c | 2015-03-26 08:49:18 -0700 | [diff] [blame^] | 327 | | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL, |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 328 | /* PECI (coreboot) */ |
| 329 | /* 12mV ADC (HWSensors4, OHM) */ |
| 330 | /* 16 bit fans (HWSensors4, OHM) */ |
| 331 | /* three fans, always 16 bit (datasheet) */ |
Guenter Roeck | b063670 | 2012-09-07 17:34:41 -0600 | [diff] [blame] | 332 | .peci_mask = 0x07, |
| 333 | }, |
Guenter Roeck | 7bc32d2 | 2015-01-17 14:10:24 -0800 | [diff] [blame] | 334 | [it8781] = { |
| 335 | .name = "it8781", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 336 | .suffix = "F", |
Guenter Roeck | 7bc32d2 | 2015-01-17 14:10:24 -0800 | [diff] [blame] | 337 | .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 338 | | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG, |
Guenter Roeck | 7bc32d2 | 2015-01-17 14:10:24 -0800 | [diff] [blame] | 339 | .old_peci_mask = 0x4, |
| 340 | }, |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 341 | [it8782] = { |
| 342 | .name = "it8782", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 343 | .suffix = "F", |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 344 | .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 345 | | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG, |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 346 | .old_peci_mask = 0x4, |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 347 | }, |
| 348 | [it8783] = { |
| 349 | .name = "it8783", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 350 | .suffix = "E/F", |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 351 | .features = FEAT_16BIT_FANS | FEAT_TEMP_OFFSET |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 352 | | FEAT_TEMP_OLD_PECI | FEAT_FAN16_CONFIG, |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 353 | .old_peci_mask = 0x4, |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 354 | }, |
Thomas Lorblanches | a0c1424 | 2015-02-13 13:19:06 +0100 | [diff] [blame] | 355 | [it8786] = { |
| 356 | .name = "it8786", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 357 | .suffix = "E", |
Thomas Lorblanches | a0c1424 | 2015-02-13 13:19:06 +0100 | [diff] [blame] | 358 | .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS |
Guenter Roeck | 7f5726c | 2015-03-26 08:49:18 -0700 | [diff] [blame^] | 359 | | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL, |
Thomas Lorblanches | a0c1424 | 2015-02-13 13:19:06 +0100 | [diff] [blame] | 360 | .peci_mask = 0x07, |
| 361 | }, |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 362 | [it8603] = { |
| 363 | .name = "it8603", |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 364 | .suffix = "E", |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 365 | .features = FEAT_NEWER_AUTOPWM | FEAT_12MV_ADC | FEAT_16BIT_FANS |
Guenter Roeck | 7f5726c | 2015-03-26 08:49:18 -0700 | [diff] [blame^] | 366 | | FEAT_TEMP_OFFSET | FEAT_TEMP_PECI | FEAT_IN7_INTERNAL, |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 367 | .peci_mask = 0x07, |
| 368 | }, |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 369 | }; |
| 370 | |
| 371 | #define has_16bit_fans(data) ((data)->features & FEAT_16BIT_FANS) |
| 372 | #define has_12mv_adc(data) ((data)->features & FEAT_12MV_ADC) |
| 373 | #define has_newer_autopwm(data) ((data)->features & FEAT_NEWER_AUTOPWM) |
| 374 | #define has_old_autopwm(data) ((data)->features & FEAT_OLD_AUTOPWM) |
| 375 | #define has_temp_offset(data) ((data)->features & FEAT_TEMP_OFFSET) |
Guenter Roeck | 5d8d2f2 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 376 | #define has_temp_peci(data, nr) (((data)->features & FEAT_TEMP_PECI) && \ |
| 377 | ((data)->peci_mask & (1 << nr))) |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 378 | #define has_temp_old_peci(data, nr) \ |
| 379 | (((data)->features & FEAT_TEMP_OLD_PECI) && \ |
| 380 | ((data)->old_peci_mask & (1 << nr))) |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 381 | #define has_fan16_config(data) ((data)->features & FEAT_FAN16_CONFIG) |
| 382 | #define has_five_fans(data) ((data)->features & FEAT_FIVE_FANS) |
Guenter Roeck | 32dd7c4 | 2015-02-12 07:40:23 -0800 | [diff] [blame] | 383 | #define has_vid(data) ((data)->features & FEAT_VID) |
Guenter Roeck | 7f5726c | 2015-03-26 08:49:18 -0700 | [diff] [blame^] | 384 | #define has_in7_internal(data) ((data)->features & FEAT_IN7_INTERNAL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 386 | struct it87_sio_data { |
| 387 | enum chips type; |
| 388 | /* Values read from Super-I/O config space */ |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 389 | u8 revision; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 390 | u8 vid_value; |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 391 | u8 beep_pin; |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 392 | u8 internal; /* Internal sensors can be labeled */ |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 393 | /* Features skipped based on config or DMI */ |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 394 | u16 skip_in; |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 395 | u8 skip_vid; |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 396 | u8 skip_fan; |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 397 | u8 skip_pwm; |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 398 | u8 skip_temp; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 399 | }; |
| 400 | |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 401 | /* |
| 402 | * For each registered chip, we need to keep some data in memory. |
| 403 | * The structure is dynamically allocated. |
| 404 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | struct it87_data { |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 406 | struct device *hwmon_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | enum chips type; |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 408 | u16 features; |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 409 | u8 peci_mask; |
| 410 | u8 old_peci_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 412 | unsigned short addr; |
| 413 | const char *name; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 414 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | char valid; /* !=0 if following fields are valid */ |
| 416 | unsigned long last_updated; /* In jiffies */ |
| 417 | |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 418 | u16 in_scaled; /* Internal voltage sensors are scaled */ |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 419 | u8 in[10][3]; /* [nr][0]=in, [1]=min, [2]=max */ |
Jean Delvare | 9060f8b | 2006-08-28 14:24:17 +0200 | [diff] [blame] | 420 | u8 has_fan; /* Bitfield, fans enabled */ |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 421 | u16 fan[5][2]; /* Register values, [nr][0]=fan, [1]=min */ |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 422 | u8 has_temp; /* Bitfield, temp sensors enabled */ |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 423 | s8 temp[3][4]; /* [nr][0]=temp, [1]=min, [2]=max, [3]=offset */ |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 424 | u8 sensor; /* Register value (IT87_REG_TEMP_ENABLE) */ |
| 425 | u8 extra; /* Register value (IT87_REG_TEMP_EXTRA) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | u8 fan_div[3]; /* Register encoding, shifted right */ |
| 427 | u8 vid; /* Register encoding, combined */ |
Jean Delvare | a7be58a | 2005-12-18 16:40:14 +0100 | [diff] [blame] | 428 | u8 vrm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | u32 alarms; /* Register encoding, combined */ |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 430 | u8 beeps; /* Register encoding */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | u8 fan_main_ctrl; /* Register value */ |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 432 | u8 fan_ctl; /* Register value */ |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 433 | |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 434 | /* |
| 435 | * The following 3 arrays correspond to the same registers up to |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 436 | * the IT8720F. The meaning of bits 6-0 depends on the value of bit |
| 437 | * 7, and we want to preserve settings on mode changes, so we have |
| 438 | * to track all values separately. |
| 439 | * Starting with the IT8721F, the manual PWM duty cycles are stored |
| 440 | * in separate registers (8-bit values), so the separate tracking |
| 441 | * is no longer needed, but it is still done to keep the driver |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 442 | * simple. |
| 443 | */ |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 444 | u8 pwm_ctrl[3]; /* Register value */ |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 445 | u8 pwm_duty[3]; /* Manual PWM value set by user */ |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 446 | u8 pwm_temp_map[3]; /* PWM to temp. chan. mapping (bits 1-0) */ |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 447 | |
| 448 | /* Automatic fan speed control registers */ |
| 449 | u8 auto_pwm[3][4]; /* [nr][3] is hard-coded */ |
| 450 | s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | }; |
| 452 | |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 453 | static int adc_lsb(const struct it87_data *data, int nr) |
| 454 | { |
| 455 | int lsb = has_12mv_adc(data) ? 12 : 16; |
| 456 | if (data->in_scaled & (1 << nr)) |
| 457 | lsb <<= 1; |
| 458 | return lsb; |
| 459 | } |
| 460 | |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 461 | static u8 in_to_reg(const struct it87_data *data, int nr, long val) |
| 462 | { |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 463 | val = DIV_ROUND_CLOSEST(val, adc_lsb(data, nr)); |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 464 | return clamp_val(val, 0, 255); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 465 | } |
| 466 | |
| 467 | static int in_from_reg(const struct it87_data *data, int nr, int val) |
| 468 | { |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 469 | return val * adc_lsb(data, nr); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 470 | } |
Jean Delvare | 0df6454d | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 471 | |
| 472 | static inline u8 FAN_TO_REG(long rpm, int div) |
| 473 | { |
| 474 | if (rpm == 0) |
| 475 | return 255; |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 476 | rpm = clamp_val(rpm, 1, 1000000); |
| 477 | return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); |
Jean Delvare | 0df6454d | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | static inline u16 FAN16_TO_REG(long rpm) |
| 481 | { |
| 482 | if (rpm == 0) |
| 483 | return 0xffff; |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 484 | return clamp_val((1350000 + rpm) / (rpm * 2), 1, 0xfffe); |
Jean Delvare | 0df6454d | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | #define FAN_FROM_REG(val, div) ((val) == 0 ? -1 : (val) == 255 ? 0 : \ |
| 488 | 1350000 / ((val) * (div))) |
| 489 | /* The divider is fixed to 2 in 16-bit mode */ |
| 490 | #define FAN16_FROM_REG(val) ((val) == 0 ? -1 : (val) == 0xffff ? 0 : \ |
| 491 | 1350000 / ((val) * 2)) |
| 492 | |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 493 | #define TEMP_TO_REG(val) (clamp_val(((val) < 0 ? (((val) - 500) / 1000) : \ |
| 494 | ((val) + 500) / 1000), -128, 127)) |
Jean Delvare | 0df6454d | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 495 | #define TEMP_FROM_REG(val) ((val) * 1000) |
| 496 | |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 497 | static u8 pwm_to_reg(const struct it87_data *data, long val) |
| 498 | { |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 499 | if (has_newer_autopwm(data)) |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 500 | return val; |
| 501 | else |
| 502 | return val >> 1; |
| 503 | } |
| 504 | |
| 505 | static int pwm_from_reg(const struct it87_data *data, u8 reg) |
| 506 | { |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 507 | if (has_newer_autopwm(data)) |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 508 | return reg; |
| 509 | else |
| 510 | return (reg & 0x7f) << 1; |
| 511 | } |
| 512 | |
Jean Delvare | 0df6454d | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 513 | |
| 514 | static int DIV_TO_REG(int val) |
| 515 | { |
| 516 | int answer = 0; |
| 517 | while (answer < 7 && (val >>= 1)) |
| 518 | answer++; |
| 519 | return answer; |
| 520 | } |
| 521 | #define DIV_FROM_REG(val) (1 << (val)) |
| 522 | |
Guenter Roeck | f56c9c0 | 2015-03-26 20:01:24 -0700 | [diff] [blame] | 523 | /* |
| 524 | * PWM base frequencies. The frequency has to be divided by either 128 or 256, |
| 525 | * depending on the chip type, to calculate the actual PWM frequency. |
| 526 | * |
| 527 | * Some of the chip datasheets suggest a base frequency of 51 kHz instead |
| 528 | * of 750 kHz for the slowest base frequency, resulting in a PWM frequency |
| 529 | * of 200 Hz. Sometimes both PWM frequency select registers are affected, |
| 530 | * sometimes just one. It is unknown if this is a datasheet error or real, |
| 531 | * so this is ignored for now. |
| 532 | */ |
Jean Delvare | 0df6454d | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 533 | static const unsigned int pwm_freq[8] = { |
Guenter Roeck | f56c9c0 | 2015-03-26 20:01:24 -0700 | [diff] [blame] | 534 | 48000000, |
| 535 | 24000000, |
| 536 | 12000000, |
| 537 | 8000000, |
| 538 | 6000000, |
| 539 | 3000000, |
| 540 | 1500000, |
| 541 | 750000, |
Jean Delvare | 0df6454d | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 542 | }; |
| 543 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 544 | static int it87_probe(struct platform_device *pdev); |
Bill Pemberton | 281dfd0 | 2012-11-19 13:25:51 -0500 | [diff] [blame] | 545 | static int it87_remove(struct platform_device *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 547 | static int it87_read_value(struct it87_data *data, u8 reg); |
| 548 | static void it87_write_value(struct it87_data *data, u8 reg, u8 value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | static struct it87_data *it87_update_device(struct device *dev); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 550 | static int it87_check_pwm(struct device *dev); |
| 551 | static void it87_init_device(struct platform_device *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | |
| 553 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 554 | static struct platform_driver it87_driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 555 | .driver = { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 556 | .name = DRVNAME, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 557 | }, |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 558 | .probe = it87_probe, |
Bill Pemberton | 9e5e9b7 | 2012-11-19 13:21:20 -0500 | [diff] [blame] | 559 | .remove = it87_remove, |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 560 | }; |
| 561 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 562 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 563 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | { |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 565 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 566 | int nr = sattr->nr; |
| 567 | int index = sattr->index; |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | struct it87_data *data = it87_update_device(dev); |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 570 | return sprintf(buf, "%d\n", in_from_reg(data, nr, data->in[nr][index])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | } |
| 572 | |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 573 | static ssize_t set_in(struct device *dev, struct device_attribute *attr, |
| 574 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | { |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 576 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 577 | int nr = sattr->nr; |
| 578 | int index = sattr->index; |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 579 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 580 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 581 | unsigned long val; |
| 582 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 583 | if (kstrtoul(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 584 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 586 | mutex_lock(&data->update_lock); |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 587 | data->in[nr][index] = in_to_reg(data, nr, val); |
| 588 | it87_write_value(data, |
| 589 | index == 1 ? IT87_REG_VIN_MIN(nr) |
| 590 | : IT87_REG_VIN_MAX(nr), |
| 591 | data->in[nr][index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 592 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | return count; |
| 594 | } |
| 595 | |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 596 | static SENSOR_DEVICE_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0); |
| 597 | static SENSOR_DEVICE_ATTR_2(in0_min, S_IRUGO | S_IWUSR, show_in, set_in, |
| 598 | 0, 1); |
| 599 | static SENSOR_DEVICE_ATTR_2(in0_max, S_IRUGO | S_IWUSR, show_in, set_in, |
| 600 | 0, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 602 | static SENSOR_DEVICE_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 1, 0); |
| 603 | static SENSOR_DEVICE_ATTR_2(in1_min, S_IRUGO | S_IWUSR, show_in, set_in, |
| 604 | 1, 1); |
| 605 | static SENSOR_DEVICE_ATTR_2(in1_max, S_IRUGO | S_IWUSR, show_in, set_in, |
| 606 | 1, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 608 | static SENSOR_DEVICE_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 2, 0); |
| 609 | static SENSOR_DEVICE_ATTR_2(in2_min, S_IRUGO | S_IWUSR, show_in, set_in, |
| 610 | 2, 1); |
| 611 | static SENSOR_DEVICE_ATTR_2(in2_max, S_IRUGO | S_IWUSR, show_in, set_in, |
| 612 | 2, 2); |
| 613 | |
| 614 | static SENSOR_DEVICE_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 3, 0); |
| 615 | static SENSOR_DEVICE_ATTR_2(in3_min, S_IRUGO | S_IWUSR, show_in, set_in, |
| 616 | 3, 1); |
| 617 | static SENSOR_DEVICE_ATTR_2(in3_max, S_IRUGO | S_IWUSR, show_in, set_in, |
| 618 | 3, 2); |
| 619 | |
| 620 | static SENSOR_DEVICE_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 4, 0); |
| 621 | static SENSOR_DEVICE_ATTR_2(in4_min, S_IRUGO | S_IWUSR, show_in, set_in, |
| 622 | 4, 1); |
| 623 | static SENSOR_DEVICE_ATTR_2(in4_max, S_IRUGO | S_IWUSR, show_in, set_in, |
| 624 | 4, 2); |
| 625 | |
| 626 | static SENSOR_DEVICE_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 5, 0); |
| 627 | static SENSOR_DEVICE_ATTR_2(in5_min, S_IRUGO | S_IWUSR, show_in, set_in, |
| 628 | 5, 1); |
| 629 | static SENSOR_DEVICE_ATTR_2(in5_max, S_IRUGO | S_IWUSR, show_in, set_in, |
| 630 | 5, 2); |
| 631 | |
| 632 | static SENSOR_DEVICE_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 6, 0); |
| 633 | static SENSOR_DEVICE_ATTR_2(in6_min, S_IRUGO | S_IWUSR, show_in, set_in, |
| 634 | 6, 1); |
| 635 | static SENSOR_DEVICE_ATTR_2(in6_max, S_IRUGO | S_IWUSR, show_in, set_in, |
| 636 | 6, 2); |
| 637 | |
| 638 | static SENSOR_DEVICE_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 7, 0); |
| 639 | static SENSOR_DEVICE_ATTR_2(in7_min, S_IRUGO | S_IWUSR, show_in, set_in, |
| 640 | 7, 1); |
| 641 | static SENSOR_DEVICE_ATTR_2(in7_max, S_IRUGO | S_IWUSR, show_in, set_in, |
| 642 | 7, 2); |
| 643 | |
| 644 | static SENSOR_DEVICE_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 8, 0); |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 645 | static SENSOR_DEVICE_ATTR_2(in9_input, S_IRUGO, show_in, NULL, 9, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
| 647 | /* 3 temperatures */ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 648 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 649 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | { |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 651 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 652 | int nr = sattr->nr; |
| 653 | int index = sattr->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 655 | |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 656 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr][index])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 658 | |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 659 | static ssize_t set_temp(struct device *dev, struct device_attribute *attr, |
| 660 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | { |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 662 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 663 | int nr = sattr->nr; |
| 664 | int index = sattr->index; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 665 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 666 | long val; |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 667 | u8 reg, regval; |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 668 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 669 | if (kstrtol(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 670 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 672 | mutex_lock(&data->update_lock); |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 673 | |
| 674 | switch (index) { |
| 675 | default: |
| 676 | case 1: |
| 677 | reg = IT87_REG_TEMP_LOW(nr); |
| 678 | break; |
| 679 | case 2: |
| 680 | reg = IT87_REG_TEMP_HIGH(nr); |
| 681 | break; |
| 682 | case 3: |
| 683 | regval = it87_read_value(data, IT87_REG_BEEP_ENABLE); |
| 684 | if (!(regval & 0x80)) { |
| 685 | regval |= 0x80; |
| 686 | it87_write_value(data, IT87_REG_BEEP_ENABLE, regval); |
| 687 | } |
| 688 | data->valid = 0; |
| 689 | reg = IT87_REG_TEMP_OFFSET[nr]; |
| 690 | break; |
| 691 | } |
| 692 | |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 693 | data->temp[nr][index] = TEMP_TO_REG(val); |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 694 | it87_write_value(data, reg, data->temp[nr][index]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 695 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | return count; |
| 697 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 698 | |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 699 | static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0); |
| 700 | static SENSOR_DEVICE_ATTR_2(temp1_min, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 701 | 0, 1); |
| 702 | static SENSOR_DEVICE_ATTR_2(temp1_max, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 703 | 0, 2); |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 704 | static SENSOR_DEVICE_ATTR_2(temp1_offset, S_IRUGO | S_IWUSR, show_temp, |
| 705 | set_temp, 0, 3); |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 706 | static SENSOR_DEVICE_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 1, 0); |
| 707 | static SENSOR_DEVICE_ATTR_2(temp2_min, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 708 | 1, 1); |
| 709 | static SENSOR_DEVICE_ATTR_2(temp2_max, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 710 | 1, 2); |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 711 | static SENSOR_DEVICE_ATTR_2(temp2_offset, S_IRUGO | S_IWUSR, show_temp, |
| 712 | set_temp, 1, 3); |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 713 | static SENSOR_DEVICE_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 2, 0); |
| 714 | static SENSOR_DEVICE_ATTR_2(temp3_min, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 715 | 2, 1); |
| 716 | static SENSOR_DEVICE_ATTR_2(temp3_max, S_IRUGO | S_IWUSR, show_temp, set_temp, |
| 717 | 2, 2); |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 718 | static SENSOR_DEVICE_ATTR_2(temp3_offset, S_IRUGO | S_IWUSR, show_temp, |
| 719 | set_temp, 2, 3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | |
Guenter Roeck | 2cece01 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 721 | static ssize_t show_temp_type(struct device *dev, struct device_attribute *attr, |
| 722 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 724 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 725 | int nr = sensor_attr->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | struct it87_data *data = it87_update_device(dev); |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 727 | u8 reg = data->sensor; /* In case value is updated while used */ |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 728 | u8 extra = data->extra; |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 729 | |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 730 | if ((has_temp_peci(data, nr) && (reg >> 6 == nr + 1)) |
| 731 | || (has_temp_old_peci(data, nr) && (extra & 0x80))) |
Guenter Roeck | 5d8d2f2 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 732 | return sprintf(buf, "6\n"); /* Intel PECI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | if (reg & (1 << nr)) |
| 734 | return sprintf(buf, "3\n"); /* thermal diode */ |
| 735 | if (reg & (8 << nr)) |
Jean Delvare | 4ed1077 | 2008-10-17 17:51:16 +0200 | [diff] [blame] | 736 | return sprintf(buf, "4\n"); /* thermistor */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | return sprintf(buf, "0\n"); /* disabled */ |
| 738 | } |
Guenter Roeck | 2cece01 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 739 | |
| 740 | static ssize_t set_temp_type(struct device *dev, struct device_attribute *attr, |
| 741 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 743 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 744 | int nr = sensor_attr->index; |
| 745 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 746 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 747 | long val; |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 748 | u8 reg, extra; |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 749 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 750 | if (kstrtol(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 751 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 753 | reg = it87_read_value(data, IT87_REG_TEMP_ENABLE); |
| 754 | reg &= ~(1 << nr); |
| 755 | reg &= ~(8 << nr); |
Guenter Roeck | 5d8d2f2 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 756 | if (has_temp_peci(data, nr) && (reg >> 6 == nr + 1 || val == 6)) |
| 757 | reg &= 0x3f; |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 758 | extra = it87_read_value(data, IT87_REG_TEMP_EXTRA); |
| 759 | if (has_temp_old_peci(data, nr) && ((extra & 0x80) || val == 6)) |
| 760 | extra &= 0x7f; |
Jean Delvare | 4ed1077 | 2008-10-17 17:51:16 +0200 | [diff] [blame] | 761 | if (val == 2) { /* backwards compatibility */ |
Guenter Roeck | 1d9bcf6 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 762 | dev_warn(dev, |
| 763 | "Sensor type 2 is deprecated, please use 4 instead\n"); |
Jean Delvare | 4ed1077 | 2008-10-17 17:51:16 +0200 | [diff] [blame] | 764 | val = 4; |
| 765 | } |
Guenter Roeck | 5d8d2f2 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 766 | /* 3 = thermal diode; 4 = thermistor; 6 = Intel PECI; 0 = disabled */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | if (val == 3) |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 768 | reg |= 1 << nr; |
Jean Delvare | 4ed1077 | 2008-10-17 17:51:16 +0200 | [diff] [blame] | 769 | else if (val == 4) |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 770 | reg |= 8 << nr; |
Guenter Roeck | 5d8d2f2 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 771 | else if (has_temp_peci(data, nr) && val == 6) |
| 772 | reg |= (nr + 1) << 6; |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 773 | else if (has_temp_old_peci(data, nr) && val == 6) |
| 774 | extra |= 0x80; |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 775 | else if (val != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | return -EINVAL; |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 777 | |
| 778 | mutex_lock(&data->update_lock); |
| 779 | data->sensor = reg; |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 780 | data->extra = extra; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 781 | it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor); |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 782 | if (has_temp_old_peci(data, nr)) |
| 783 | it87_write_value(data, IT87_REG_TEMP_EXTRA, data->extra); |
Jean Delvare | 2b3d1d8 | 2010-04-14 16:14:10 +0200 | [diff] [blame] | 784 | data->valid = 0; /* Force cache refresh */ |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 785 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | return count; |
| 787 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | |
Guenter Roeck | 2cece01 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 789 | static SENSOR_DEVICE_ATTR(temp1_type, S_IRUGO | S_IWUSR, show_temp_type, |
| 790 | set_temp_type, 0); |
| 791 | static SENSOR_DEVICE_ATTR(temp2_type, S_IRUGO | S_IWUSR, show_temp_type, |
| 792 | set_temp_type, 1); |
| 793 | static SENSOR_DEVICE_ATTR(temp3_type, S_IRUGO | S_IWUSR, show_temp_type, |
| 794 | set_temp_type, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
| 796 | /* 3 Fans */ |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 797 | |
| 798 | static int pwm_mode(const struct it87_data *data, int nr) |
| 799 | { |
| 800 | int ctrl = data->fan_main_ctrl & (1 << nr); |
| 801 | |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 802 | if (ctrl == 0 && data->type != it8603) /* Full speed */ |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 803 | return 0; |
| 804 | if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */ |
| 805 | return 2; |
| 806 | else /* Manual mode */ |
| 807 | return 1; |
| 808 | } |
| 809 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 810 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 811 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | { |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 813 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 814 | int nr = sattr->nr; |
| 815 | int index = sattr->index; |
| 816 | int speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 818 | |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 819 | speed = has_16bit_fans(data) ? |
| 820 | FAN16_FROM_REG(data->fan[nr][index]) : |
| 821 | FAN_FROM_REG(data->fan[nr][index], |
| 822 | DIV_FROM_REG(data->fan_div[nr])); |
| 823 | return sprintf(buf, "%d\n", speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | } |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 825 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 826 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, |
| 827 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 829 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 830 | int nr = sensor_attr->index; |
| 831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | struct it87_data *data = it87_update_device(dev); |
| 833 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); |
| 834 | } |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 835 | static ssize_t show_pwm_enable(struct device *dev, |
| 836 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 837 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 838 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 839 | int nr = sensor_attr->index; |
| 840 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 842 | return sprintf(buf, "%d\n", pwm_mode(data, nr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 843 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 844 | static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, |
| 845 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 847 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 848 | int nr = sensor_attr->index; |
| 849 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 851 | return sprintf(buf, "%d\n", |
| 852 | pwm_from_reg(data, data->pwm_duty[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | } |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 854 | static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr, |
| 855 | char *buf) |
| 856 | { |
| 857 | struct it87_data *data = it87_update_device(dev); |
| 858 | int index = (data->fan_ctl >> 4) & 0x07; |
Guenter Roeck | f56c9c0 | 2015-03-26 20:01:24 -0700 | [diff] [blame] | 859 | unsigned int freq; |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 860 | |
Guenter Roeck | f56c9c0 | 2015-03-26 20:01:24 -0700 | [diff] [blame] | 861 | freq = pwm_freq[index] / (has_newer_autopwm(data) ? 256 : 128); |
| 862 | |
| 863 | return sprintf(buf, "%u\n", freq); |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 864 | } |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 865 | |
| 866 | static ssize_t set_fan(struct device *dev, struct device_attribute *attr, |
| 867 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | { |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 869 | struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr); |
| 870 | int nr = sattr->nr; |
| 871 | int index = sattr->index; |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 872 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 873 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 874 | long val; |
Jean Delvare | 7f999aa | 2007-02-14 21:15:03 +0100 | [diff] [blame] | 875 | u8 reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 877 | if (kstrtol(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 878 | return -EINVAL; |
| 879 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 880 | mutex_lock(&data->update_lock); |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 881 | |
| 882 | if (has_16bit_fans(data)) { |
| 883 | data->fan[nr][index] = FAN16_TO_REG(val); |
| 884 | it87_write_value(data, IT87_REG_FAN_MIN[nr], |
| 885 | data->fan[nr][index] & 0xff); |
| 886 | it87_write_value(data, IT87_REG_FANX_MIN[nr], |
| 887 | data->fan[nr][index] >> 8); |
| 888 | } else { |
| 889 | reg = it87_read_value(data, IT87_REG_FAN_DIV); |
| 890 | switch (nr) { |
| 891 | case 0: |
| 892 | data->fan_div[nr] = reg & 0x07; |
| 893 | break; |
| 894 | case 1: |
| 895 | data->fan_div[nr] = (reg >> 3) & 0x07; |
| 896 | break; |
| 897 | case 2: |
| 898 | data->fan_div[nr] = (reg & 0x40) ? 3 : 1; |
| 899 | break; |
| 900 | } |
| 901 | data->fan[nr][index] = |
| 902 | FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
| 903 | it87_write_value(data, IT87_REG_FAN_MIN[nr], |
| 904 | data->fan[nr][index]); |
Jean Delvare | 07eab46 | 2005-11-23 15:44:31 -0800 | [diff] [blame] | 905 | } |
| 906 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 907 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | return count; |
| 909 | } |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 910 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 911 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
| 912 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 914 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 915 | int nr = sensor_attr->index; |
| 916 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 917 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 918 | unsigned long val; |
Jean Delvare | 8ab4ec3 | 2006-08-28 14:35:46 +0200 | [diff] [blame] | 919 | int min; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | u8 old; |
| 921 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 922 | if (kstrtoul(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 923 | return -EINVAL; |
| 924 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 925 | mutex_lock(&data->update_lock); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 926 | old = it87_read_value(data, IT87_REG_FAN_DIV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | |
Jean Delvare | 8ab4ec3 | 2006-08-28 14:35:46 +0200 | [diff] [blame] | 928 | /* Save fan min limit */ |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 929 | min = FAN_FROM_REG(data->fan[nr][1], DIV_FROM_REG(data->fan_div[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | |
| 931 | switch (nr) { |
| 932 | case 0: |
| 933 | case 1: |
| 934 | data->fan_div[nr] = DIV_TO_REG(val); |
| 935 | break; |
| 936 | case 2: |
| 937 | if (val < 8) |
| 938 | data->fan_div[nr] = 1; |
| 939 | else |
| 940 | data->fan_div[nr] = 3; |
| 941 | } |
| 942 | val = old & 0x80; |
| 943 | val |= (data->fan_div[0] & 0x07); |
| 944 | val |= (data->fan_div[1] & 0x07) << 3; |
| 945 | if (data->fan_div[2] == 3) |
| 946 | val |= 0x1 << 6; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 947 | it87_write_value(data, IT87_REG_FAN_DIV, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | |
Jean Delvare | 8ab4ec3 | 2006-08-28 14:35:46 +0200 | [diff] [blame] | 949 | /* Restore fan min limit */ |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 950 | data->fan[nr][1] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); |
| 951 | it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan[nr][1]); |
Jean Delvare | 8ab4ec3 | 2006-08-28 14:35:46 +0200 | [diff] [blame] | 952 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 953 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | return count; |
| 955 | } |
Jean Delvare | cccfc9c | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 956 | |
| 957 | /* Returns 0 if OK, -EINVAL otherwise */ |
| 958 | static int check_trip_points(struct device *dev, int nr) |
| 959 | { |
| 960 | const struct it87_data *data = dev_get_drvdata(dev); |
| 961 | int i, err = 0; |
| 962 | |
| 963 | if (has_old_autopwm(data)) { |
| 964 | for (i = 0; i < 3; i++) { |
| 965 | if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1]) |
| 966 | err = -EINVAL; |
| 967 | } |
| 968 | for (i = 0; i < 2; i++) { |
| 969 | if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1]) |
| 970 | err = -EINVAL; |
| 971 | } |
| 972 | } |
| 973 | |
| 974 | if (err) { |
Guenter Roeck | 1d9bcf6 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 975 | dev_err(dev, |
| 976 | "Inconsistent trip points, not switching to automatic mode\n"); |
Jean Delvare | cccfc9c | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 977 | dev_err(dev, "Adjust the trip points and try again\n"); |
| 978 | } |
| 979 | return err; |
| 980 | } |
| 981 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 982 | static ssize_t set_pwm_enable(struct device *dev, |
| 983 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 984 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 985 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 986 | int nr = sensor_attr->index; |
| 987 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 988 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 989 | long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 991 | if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 2) |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 992 | return -EINVAL; |
| 993 | |
Jean Delvare | cccfc9c | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 994 | /* Check trip points before switching to automatic mode */ |
| 995 | if (val == 2) { |
| 996 | if (check_trip_points(dev, nr) < 0) |
| 997 | return -EINVAL; |
| 998 | } |
| 999 | |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1000 | /* IT8603E does not have on/off mode */ |
| 1001 | if (val == 0 && data->type == it8603) |
| 1002 | return -EINVAL; |
| 1003 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1004 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | |
| 1006 | if (val == 0) { |
| 1007 | int tmp; |
| 1008 | /* make sure the fan is on when in on/off mode */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1009 | tmp = it87_read_value(data, IT87_REG_FAN_CTL); |
| 1010 | it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | /* set on/off mode */ |
| 1012 | data->fan_main_ctrl &= ~(1 << nr); |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1013 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, |
| 1014 | data->fan_main_ctrl); |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1015 | } else { |
| 1016 | if (val == 1) /* Manual mode */ |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1017 | data->pwm_ctrl[nr] = has_newer_autopwm(data) ? |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 1018 | data->pwm_temp_map[nr] : |
| 1019 | data->pwm_duty[nr]; |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1020 | else /* Automatic mode */ |
| 1021 | data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr]; |
| 1022 | it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]); |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1023 | |
| 1024 | if (data->type != it8603) { |
| 1025 | /* set SmartGuardian mode */ |
| 1026 | data->fan_main_ctrl |= (1 << nr); |
| 1027 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, |
| 1028 | data->fan_main_ctrl); |
| 1029 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1032 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | return count; |
| 1034 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1035 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, |
| 1036 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 1038 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1039 | int nr = sensor_attr->index; |
| 1040 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1041 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1042 | long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1044 | if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1045 | return -EINVAL; |
| 1046 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1047 | mutex_lock(&data->update_lock); |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1048 | if (has_newer_autopwm(data)) { |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 1049 | /* |
| 1050 | * If we are in automatic mode, the PWM duty cycle register |
| 1051 | * is read-only so we can't write the value. |
| 1052 | */ |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 1053 | if (data->pwm_ctrl[nr] & 0x80) { |
| 1054 | mutex_unlock(&data->update_lock); |
| 1055 | return -EBUSY; |
| 1056 | } |
| 1057 | data->pwm_duty[nr] = pwm_to_reg(data, val); |
| 1058 | it87_write_value(data, IT87_REG_PWM_DUTY(nr), |
| 1059 | data->pwm_duty[nr]); |
| 1060 | } else { |
| 1061 | data->pwm_duty[nr] = pwm_to_reg(data, val); |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 1062 | /* |
| 1063 | * If we are in manual mode, write the duty cycle immediately; |
| 1064 | * otherwise, just store it for later use. |
| 1065 | */ |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 1066 | if (!(data->pwm_ctrl[nr] & 0x80)) { |
| 1067 | data->pwm_ctrl[nr] = data->pwm_duty[nr]; |
| 1068 | it87_write_value(data, IT87_REG_PWM(nr), |
| 1069 | data->pwm_ctrl[nr]); |
| 1070 | } |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1071 | } |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1072 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1073 | return count; |
| 1074 | } |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 1075 | static ssize_t set_pwm_freq(struct device *dev, |
| 1076 | struct device_attribute *attr, const char *buf, size_t count) |
| 1077 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1078 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1079 | unsigned long val; |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 1080 | int i; |
| 1081 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1082 | if (kstrtoul(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1083 | return -EINVAL; |
| 1084 | |
Guenter Roeck | f56c9c0 | 2015-03-26 20:01:24 -0700 | [diff] [blame] | 1085 | val = clamp_val(val, 0, 1000000); |
| 1086 | val *= has_newer_autopwm(data) ? 256 : 128; |
| 1087 | |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 1088 | /* Search for the nearest available frequency */ |
| 1089 | for (i = 0; i < 7; i++) { |
| 1090 | if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2) |
| 1091 | break; |
| 1092 | } |
| 1093 | |
| 1094 | mutex_lock(&data->update_lock); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1095 | data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f; |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 1096 | data->fan_ctl |= i << 4; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1097 | it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl); |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 1098 | mutex_unlock(&data->update_lock); |
| 1099 | |
| 1100 | return count; |
| 1101 | } |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1102 | static ssize_t show_pwm_temp_map(struct device *dev, |
| 1103 | struct device_attribute *attr, char *buf) |
| 1104 | { |
| 1105 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1106 | int nr = sensor_attr->index; |
| 1107 | |
| 1108 | struct it87_data *data = it87_update_device(dev); |
| 1109 | int map; |
| 1110 | |
| 1111 | if (data->pwm_temp_map[nr] < 3) |
| 1112 | map = 1 << data->pwm_temp_map[nr]; |
| 1113 | else |
| 1114 | map = 0; /* Should never happen */ |
| 1115 | return sprintf(buf, "%d\n", map); |
| 1116 | } |
| 1117 | static ssize_t set_pwm_temp_map(struct device *dev, |
| 1118 | struct device_attribute *attr, const char *buf, size_t count) |
| 1119 | { |
| 1120 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1121 | int nr = sensor_attr->index; |
| 1122 | |
| 1123 | struct it87_data *data = dev_get_drvdata(dev); |
| 1124 | long val; |
| 1125 | u8 reg; |
| 1126 | |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 1127 | /* |
| 1128 | * This check can go away if we ever support automatic fan speed |
| 1129 | * control on newer chips. |
| 1130 | */ |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1131 | if (!has_old_autopwm(data)) { |
| 1132 | dev_notice(dev, "Mapping change disabled for safety reasons\n"); |
| 1133 | return -EINVAL; |
| 1134 | } |
| 1135 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1136 | if (kstrtol(buf, 10, &val) < 0) |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1137 | return -EINVAL; |
| 1138 | |
| 1139 | switch (val) { |
| 1140 | case (1 << 0): |
| 1141 | reg = 0x00; |
| 1142 | break; |
| 1143 | case (1 << 1): |
| 1144 | reg = 0x01; |
| 1145 | break; |
| 1146 | case (1 << 2): |
| 1147 | reg = 0x02; |
| 1148 | break; |
| 1149 | default: |
| 1150 | return -EINVAL; |
| 1151 | } |
| 1152 | |
| 1153 | mutex_lock(&data->update_lock); |
| 1154 | data->pwm_temp_map[nr] = reg; |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 1155 | /* |
| 1156 | * If we are in automatic mode, write the temp mapping immediately; |
| 1157 | * otherwise, just store it for later use. |
| 1158 | */ |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1159 | if (data->pwm_ctrl[nr] & 0x80) { |
| 1160 | data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr]; |
| 1161 | it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]); |
| 1162 | } |
| 1163 | mutex_unlock(&data->update_lock); |
| 1164 | return count; |
| 1165 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1166 | |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1167 | static ssize_t show_auto_pwm(struct device *dev, |
| 1168 | struct device_attribute *attr, char *buf) |
| 1169 | { |
| 1170 | struct it87_data *data = it87_update_device(dev); |
| 1171 | struct sensor_device_attribute_2 *sensor_attr = |
| 1172 | to_sensor_dev_attr_2(attr); |
| 1173 | int nr = sensor_attr->nr; |
| 1174 | int point = sensor_attr->index; |
| 1175 | |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1176 | return sprintf(buf, "%d\n", |
| 1177 | pwm_from_reg(data, data->auto_pwm[nr][point])); |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | static ssize_t set_auto_pwm(struct device *dev, |
| 1181 | struct device_attribute *attr, const char *buf, size_t count) |
| 1182 | { |
| 1183 | struct it87_data *data = dev_get_drvdata(dev); |
| 1184 | struct sensor_device_attribute_2 *sensor_attr = |
| 1185 | to_sensor_dev_attr_2(attr); |
| 1186 | int nr = sensor_attr->nr; |
| 1187 | int point = sensor_attr->index; |
| 1188 | long val; |
| 1189 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1190 | if (kstrtol(buf, 10, &val) < 0 || val < 0 || val > 255) |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1191 | return -EINVAL; |
| 1192 | |
| 1193 | mutex_lock(&data->update_lock); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1194 | data->auto_pwm[nr][point] = pwm_to_reg(data, val); |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1195 | it87_write_value(data, IT87_REG_AUTO_PWM(nr, point), |
| 1196 | data->auto_pwm[nr][point]); |
| 1197 | mutex_unlock(&data->update_lock); |
| 1198 | return count; |
| 1199 | } |
| 1200 | |
| 1201 | static ssize_t show_auto_temp(struct device *dev, |
| 1202 | struct device_attribute *attr, char *buf) |
| 1203 | { |
| 1204 | struct it87_data *data = it87_update_device(dev); |
| 1205 | struct sensor_device_attribute_2 *sensor_attr = |
| 1206 | to_sensor_dev_attr_2(attr); |
| 1207 | int nr = sensor_attr->nr; |
| 1208 | int point = sensor_attr->index; |
| 1209 | |
| 1210 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->auto_temp[nr][point])); |
| 1211 | } |
| 1212 | |
| 1213 | static ssize_t set_auto_temp(struct device *dev, |
| 1214 | struct device_attribute *attr, const char *buf, size_t count) |
| 1215 | { |
| 1216 | struct it87_data *data = dev_get_drvdata(dev); |
| 1217 | struct sensor_device_attribute_2 *sensor_attr = |
| 1218 | to_sensor_dev_attr_2(attr); |
| 1219 | int nr = sensor_attr->nr; |
| 1220 | int point = sensor_attr->index; |
| 1221 | long val; |
| 1222 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1223 | if (kstrtol(buf, 10, &val) < 0 || val < -128000 || val > 127000) |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1224 | return -EINVAL; |
| 1225 | |
| 1226 | mutex_lock(&data->update_lock); |
| 1227 | data->auto_temp[nr][point] = TEMP_TO_REG(val); |
| 1228 | it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point), |
| 1229 | data->auto_temp[nr][point]); |
| 1230 | mutex_unlock(&data->update_lock); |
| 1231 | return count; |
| 1232 | } |
| 1233 | |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1234 | static SENSOR_DEVICE_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0); |
| 1235 | static SENSOR_DEVICE_ATTR_2(fan1_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
| 1236 | 0, 1); |
| 1237 | static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO | S_IWUSR, show_fan_div, |
| 1238 | set_fan_div, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1240 | static SENSOR_DEVICE_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 1, 0); |
| 1241 | static SENSOR_DEVICE_ATTR_2(fan2_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
| 1242 | 1, 1); |
| 1243 | static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO | S_IWUSR, show_fan_div, |
| 1244 | set_fan_div, 1); |
| 1245 | |
| 1246 | static SENSOR_DEVICE_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 2, 0); |
| 1247 | static SENSOR_DEVICE_ATTR_2(fan3_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
| 1248 | 2, 1); |
| 1249 | static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO | S_IWUSR, show_fan_div, |
| 1250 | set_fan_div, 2); |
| 1251 | |
| 1252 | static SENSOR_DEVICE_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 3, 0); |
| 1253 | static SENSOR_DEVICE_ATTR_2(fan4_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
| 1254 | 3, 1); |
| 1255 | |
| 1256 | static SENSOR_DEVICE_ATTR_2(fan5_input, S_IRUGO, show_fan, NULL, 4, 0); |
| 1257 | static SENSOR_DEVICE_ATTR_2(fan5_min, S_IRUGO | S_IWUSR, show_fan, set_fan, |
| 1258 | 4, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | |
Guenter Roeck | c4458db | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 1260 | static SENSOR_DEVICE_ATTR(pwm1_enable, S_IRUGO | S_IWUSR, |
| 1261 | show_pwm_enable, set_pwm_enable, 0); |
| 1262 | static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0); |
| 1263 | static DEVICE_ATTR(pwm1_freq, S_IRUGO | S_IWUSR, show_pwm_freq, set_pwm_freq); |
| 1264 | static SENSOR_DEVICE_ATTR(pwm1_auto_channels_temp, S_IRUGO | S_IWUSR, |
| 1265 | show_pwm_temp_map, set_pwm_temp_map, 0); |
| 1266 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO | S_IWUSR, |
| 1267 | show_auto_pwm, set_auto_pwm, 0, 0); |
| 1268 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO | S_IWUSR, |
| 1269 | show_auto_pwm, set_auto_pwm, 0, 1); |
| 1270 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO | S_IWUSR, |
| 1271 | show_auto_pwm, set_auto_pwm, 0, 2); |
| 1272 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO, |
| 1273 | show_auto_pwm, NULL, 0, 3); |
| 1274 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp, S_IRUGO | S_IWUSR, |
| 1275 | show_auto_temp, set_auto_temp, 0, 1); |
| 1276 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO | S_IWUSR, |
| 1277 | show_auto_temp, set_auto_temp, 0, 0); |
| 1278 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point2_temp, S_IRUGO | S_IWUSR, |
| 1279 | show_auto_temp, set_auto_temp, 0, 2); |
| 1280 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point3_temp, S_IRUGO | S_IWUSR, |
| 1281 | show_auto_temp, set_auto_temp, 0, 3); |
| 1282 | static SENSOR_DEVICE_ATTR_2(pwm1_auto_point4_temp, S_IRUGO | S_IWUSR, |
| 1283 | show_auto_temp, set_auto_temp, 0, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | |
Guenter Roeck | c4458db | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 1285 | static SENSOR_DEVICE_ATTR(pwm2_enable, S_IRUGO | S_IWUSR, |
| 1286 | show_pwm_enable, set_pwm_enable, 1); |
| 1287 | static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 1); |
| 1288 | static DEVICE_ATTR(pwm2_freq, S_IRUGO, show_pwm_freq, NULL); |
| 1289 | static SENSOR_DEVICE_ATTR(pwm2_auto_channels_temp, S_IRUGO | S_IWUSR, |
| 1290 | show_pwm_temp_map, set_pwm_temp_map, 1); |
| 1291 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO | S_IWUSR, |
| 1292 | show_auto_pwm, set_auto_pwm, 1, 0); |
| 1293 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO | S_IWUSR, |
| 1294 | show_auto_pwm, set_auto_pwm, 1, 1); |
| 1295 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO | S_IWUSR, |
| 1296 | show_auto_pwm, set_auto_pwm, 1, 2); |
| 1297 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO, |
| 1298 | show_auto_pwm, NULL, 1, 3); |
| 1299 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp, S_IRUGO | S_IWUSR, |
| 1300 | show_auto_temp, set_auto_temp, 1, 1); |
| 1301 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO | S_IWUSR, |
| 1302 | show_auto_temp, set_auto_temp, 1, 0); |
| 1303 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point2_temp, S_IRUGO | S_IWUSR, |
| 1304 | show_auto_temp, set_auto_temp, 1, 2); |
| 1305 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point3_temp, S_IRUGO | S_IWUSR, |
| 1306 | show_auto_temp, set_auto_temp, 1, 3); |
| 1307 | static SENSOR_DEVICE_ATTR_2(pwm2_auto_point4_temp, S_IRUGO | S_IWUSR, |
| 1308 | show_auto_temp, set_auto_temp, 1, 4); |
| 1309 | |
| 1310 | static SENSOR_DEVICE_ATTR(pwm3_enable, S_IRUGO | S_IWUSR, |
| 1311 | show_pwm_enable, set_pwm_enable, 2); |
| 1312 | static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 2); |
| 1313 | static DEVICE_ATTR(pwm3_freq, S_IRUGO, show_pwm_freq, NULL); |
| 1314 | static SENSOR_DEVICE_ATTR(pwm3_auto_channels_temp, S_IRUGO | S_IWUSR, |
| 1315 | show_pwm_temp_map, set_pwm_temp_map, 2); |
| 1316 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO | S_IWUSR, |
| 1317 | show_auto_pwm, set_auto_pwm, 2, 0); |
| 1318 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO | S_IWUSR, |
| 1319 | show_auto_pwm, set_auto_pwm, 2, 1); |
| 1320 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO | S_IWUSR, |
| 1321 | show_auto_pwm, set_auto_pwm, 2, 2); |
| 1322 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO, |
| 1323 | show_auto_pwm, NULL, 2, 3); |
| 1324 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp, S_IRUGO | S_IWUSR, |
| 1325 | show_auto_temp, set_auto_temp, 2, 1); |
| 1326 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO | S_IWUSR, |
| 1327 | show_auto_temp, set_auto_temp, 2, 0); |
| 1328 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point2_temp, S_IRUGO | S_IWUSR, |
| 1329 | show_auto_temp, set_auto_temp, 2, 2); |
| 1330 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point3_temp, S_IRUGO | S_IWUSR, |
| 1331 | show_auto_temp, set_auto_temp, 2, 3); |
| 1332 | static SENSOR_DEVICE_ATTR_2(pwm3_auto_point4_temp, S_IRUGO | S_IWUSR, |
| 1333 | show_auto_temp, set_auto_temp, 2, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | |
| 1335 | /* Alarms */ |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1336 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, |
| 1337 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | { |
| 1339 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 68188ba | 2005-05-16 18:52:38 +0200 | [diff] [blame] | 1340 | return sprintf(buf, "%u\n", data->alarms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1341 | } |
Jean Delvare | 1d66c64 | 2005-04-18 21:16:59 -0700 | [diff] [blame] | 1342 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1344 | static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, |
| 1345 | char *buf) |
| 1346 | { |
| 1347 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 1348 | struct it87_data *data = it87_update_device(dev); |
| 1349 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); |
| 1350 | } |
Jean Delvare | 3d30f9e | 2011-07-25 21:46:10 +0200 | [diff] [blame] | 1351 | |
| 1352 | static ssize_t clear_intrusion(struct device *dev, struct device_attribute |
| 1353 | *attr, const char *buf, size_t count) |
| 1354 | { |
| 1355 | struct it87_data *data = dev_get_drvdata(dev); |
| 1356 | long val; |
| 1357 | int config; |
| 1358 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1359 | if (kstrtol(buf, 10, &val) < 0 || val != 0) |
Jean Delvare | 3d30f9e | 2011-07-25 21:46:10 +0200 | [diff] [blame] | 1360 | return -EINVAL; |
| 1361 | |
| 1362 | mutex_lock(&data->update_lock); |
| 1363 | config = it87_read_value(data, IT87_REG_CONFIG); |
| 1364 | if (config < 0) { |
| 1365 | count = config; |
| 1366 | } else { |
| 1367 | config |= 1 << 5; |
| 1368 | it87_write_value(data, IT87_REG_CONFIG, config); |
| 1369 | /* Invalidate cache to force re-read */ |
| 1370 | data->valid = 0; |
| 1371 | } |
| 1372 | mutex_unlock(&data->update_lock); |
| 1373 | |
| 1374 | return count; |
| 1375 | } |
| 1376 | |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1377 | static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8); |
| 1378 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9); |
| 1379 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10); |
| 1380 | static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11); |
| 1381 | static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12); |
| 1382 | static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13); |
| 1383 | static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14); |
| 1384 | static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15); |
| 1385 | static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0); |
| 1386 | static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1); |
| 1387 | static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2); |
| 1388 | static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3); |
| 1389 | static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6); |
| 1390 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16); |
| 1391 | static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17); |
| 1392 | static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18); |
Jean Delvare | 3d30f9e | 2011-07-25 21:46:10 +0200 | [diff] [blame] | 1393 | static SENSOR_DEVICE_ATTR(intrusion0_alarm, S_IRUGO | S_IWUSR, |
| 1394 | show_alarm, clear_intrusion, 4); |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1395 | |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1396 | static ssize_t show_beep(struct device *dev, struct device_attribute *attr, |
| 1397 | char *buf) |
| 1398 | { |
| 1399 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 1400 | struct it87_data *data = it87_update_device(dev); |
| 1401 | return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1); |
| 1402 | } |
| 1403 | static ssize_t set_beep(struct device *dev, struct device_attribute *attr, |
| 1404 | const char *buf, size_t count) |
| 1405 | { |
| 1406 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 1407 | struct it87_data *data = dev_get_drvdata(dev); |
| 1408 | long val; |
| 1409 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1410 | if (kstrtol(buf, 10, &val) < 0 |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1411 | || (val != 0 && val != 1)) |
| 1412 | return -EINVAL; |
| 1413 | |
| 1414 | mutex_lock(&data->update_lock); |
| 1415 | data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE); |
| 1416 | if (val) |
| 1417 | data->beeps |= (1 << bitnr); |
| 1418 | else |
| 1419 | data->beeps &= ~(1 << bitnr); |
| 1420 | it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps); |
| 1421 | mutex_unlock(&data->update_lock); |
| 1422 | return count; |
| 1423 | } |
| 1424 | |
| 1425 | static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR, |
| 1426 | show_beep, set_beep, 1); |
| 1427 | static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1); |
| 1428 | static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1); |
| 1429 | static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1); |
| 1430 | static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1); |
| 1431 | static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1); |
| 1432 | static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1); |
| 1433 | static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1); |
| 1434 | /* fanX_beep writability is set later */ |
| 1435 | static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1436 | static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1437 | static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1438 | static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1439 | static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1440 | static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR, |
| 1441 | show_beep, set_beep, 2); |
| 1442 | static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2); |
| 1443 | static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2); |
| 1444 | |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1445 | static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, |
| 1446 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | { |
Jean Delvare | 90d6619 | 2007-10-08 18:24:35 +0200 | [diff] [blame] | 1448 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | a7be58a | 2005-12-18 16:40:14 +0100 | [diff] [blame] | 1449 | return sprintf(buf, "%u\n", data->vrm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | } |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1451 | static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, |
| 1452 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1454 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1455 | unsigned long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1457 | if (kstrtoul(buf, 10, &val) < 0) |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1458 | return -EINVAL; |
| 1459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | data->vrm = val; |
| 1461 | |
| 1462 | return count; |
| 1463 | } |
| 1464 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1466 | static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, |
| 1467 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | { |
| 1469 | struct it87_data *data = it87_update_device(dev); |
| 1470 | return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); |
| 1471 | } |
| 1472 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1473 | |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1474 | static ssize_t show_label(struct device *dev, struct device_attribute *attr, |
| 1475 | char *buf) |
| 1476 | { |
Guenter Roeck | 3c4c497 | 2012-01-20 09:29:44 -0800 | [diff] [blame] | 1477 | static const char * const labels[] = { |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1478 | "+5V", |
| 1479 | "5VSB", |
| 1480 | "Vbat", |
| 1481 | }; |
Guenter Roeck | 3c4c497 | 2012-01-20 09:29:44 -0800 | [diff] [blame] | 1482 | static const char * const labels_it8721[] = { |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1483 | "+3.3V", |
| 1484 | "3VSB", |
| 1485 | "Vbat", |
| 1486 | }; |
| 1487 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1488 | int nr = to_sensor_dev_attr(attr)->index; |
| 1489 | |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1490 | return sprintf(buf, "%s\n", has_12mv_adc(data) ? labels_it8721[nr] |
| 1491 | : labels[nr]); |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1492 | } |
| 1493 | static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0); |
| 1494 | static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1); |
| 1495 | static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2); |
Rudolf Marek | 7183ae8 | 2014-04-04 18:01:35 +0200 | [diff] [blame] | 1496 | /* special AVCC3 IT8603E in9 */ |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1497 | static SENSOR_DEVICE_ATTR(in9_label, S_IRUGO, show_label, NULL, 0); |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1498 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1499 | static ssize_t show_name(struct device *dev, struct device_attribute |
| 1500 | *devattr, char *buf) |
| 1501 | { |
| 1502 | struct it87_data *data = dev_get_drvdata(dev); |
| 1503 | return sprintf(buf, "%s\n", data->name); |
| 1504 | } |
| 1505 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
| 1506 | |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1507 | static struct attribute *it87_attributes_in[10][5] = { |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1508 | { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1509 | &sensor_dev_attr_in0_input.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1510 | &sensor_dev_attr_in0_min.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1511 | &sensor_dev_attr_in0_max.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1512 | &sensor_dev_attr_in0_alarm.dev_attr.attr, |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1513 | NULL |
| 1514 | }, { |
| 1515 | &sensor_dev_attr_in1_input.dev_attr.attr, |
| 1516 | &sensor_dev_attr_in1_min.dev_attr.attr, |
| 1517 | &sensor_dev_attr_in1_max.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1518 | &sensor_dev_attr_in1_alarm.dev_attr.attr, |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1519 | NULL |
| 1520 | }, { |
| 1521 | &sensor_dev_attr_in2_input.dev_attr.attr, |
| 1522 | &sensor_dev_attr_in2_min.dev_attr.attr, |
| 1523 | &sensor_dev_attr_in2_max.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1524 | &sensor_dev_attr_in2_alarm.dev_attr.attr, |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1525 | NULL |
| 1526 | }, { |
| 1527 | &sensor_dev_attr_in3_input.dev_attr.attr, |
| 1528 | &sensor_dev_attr_in3_min.dev_attr.attr, |
| 1529 | &sensor_dev_attr_in3_max.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1530 | &sensor_dev_attr_in3_alarm.dev_attr.attr, |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1531 | NULL |
| 1532 | }, { |
| 1533 | &sensor_dev_attr_in4_input.dev_attr.attr, |
| 1534 | &sensor_dev_attr_in4_min.dev_attr.attr, |
| 1535 | &sensor_dev_attr_in4_max.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1536 | &sensor_dev_attr_in4_alarm.dev_attr.attr, |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1537 | NULL |
| 1538 | }, { |
| 1539 | &sensor_dev_attr_in5_input.dev_attr.attr, |
| 1540 | &sensor_dev_attr_in5_min.dev_attr.attr, |
| 1541 | &sensor_dev_attr_in5_max.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1542 | &sensor_dev_attr_in5_alarm.dev_attr.attr, |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1543 | NULL |
| 1544 | }, { |
| 1545 | &sensor_dev_attr_in6_input.dev_attr.attr, |
| 1546 | &sensor_dev_attr_in6_min.dev_attr.attr, |
| 1547 | &sensor_dev_attr_in6_max.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1548 | &sensor_dev_attr_in6_alarm.dev_attr.attr, |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1549 | NULL |
| 1550 | }, { |
| 1551 | &sensor_dev_attr_in7_input.dev_attr.attr, |
| 1552 | &sensor_dev_attr_in7_min.dev_attr.attr, |
| 1553 | &sensor_dev_attr_in7_max.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1554 | &sensor_dev_attr_in7_alarm.dev_attr.attr, |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1555 | NULL |
| 1556 | }, { |
| 1557 | &sensor_dev_attr_in8_input.dev_attr.attr, |
| 1558 | NULL |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1559 | }, { |
| 1560 | &sensor_dev_attr_in9_input.dev_attr.attr, |
| 1561 | NULL |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1562 | } }; |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1563 | |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1564 | static const struct attribute_group it87_group_in[10] = { |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1565 | { .attrs = it87_attributes_in[0] }, |
| 1566 | { .attrs = it87_attributes_in[1] }, |
| 1567 | { .attrs = it87_attributes_in[2] }, |
| 1568 | { .attrs = it87_attributes_in[3] }, |
| 1569 | { .attrs = it87_attributes_in[4] }, |
| 1570 | { .attrs = it87_attributes_in[5] }, |
| 1571 | { .attrs = it87_attributes_in[6] }, |
| 1572 | { .attrs = it87_attributes_in[7] }, |
| 1573 | { .attrs = it87_attributes_in[8] }, |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1574 | { .attrs = it87_attributes_in[9] }, |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1575 | }; |
| 1576 | |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 1577 | static struct attribute *it87_attributes_temp[3][6] = { |
| 1578 | { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1579 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1580 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1581 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1582 | &sensor_dev_attr_temp1_type.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1583 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 1584 | NULL |
| 1585 | } , { |
| 1586 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
| 1587 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
| 1588 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
| 1589 | &sensor_dev_attr_temp2_type.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1590 | &sensor_dev_attr_temp2_alarm.dev_attr.attr, |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 1591 | NULL |
| 1592 | } , { |
| 1593 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
| 1594 | &sensor_dev_attr_temp3_max.dev_attr.attr, |
| 1595 | &sensor_dev_attr_temp3_min.dev_attr.attr, |
| 1596 | &sensor_dev_attr_temp3_type.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1597 | &sensor_dev_attr_temp3_alarm.dev_attr.attr, |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 1598 | NULL |
| 1599 | } }; |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1600 | |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 1601 | static const struct attribute_group it87_group_temp[3] = { |
| 1602 | { .attrs = it87_attributes_temp[0] }, |
| 1603 | { .attrs = it87_attributes_temp[1] }, |
| 1604 | { .attrs = it87_attributes_temp[2] }, |
| 1605 | }; |
| 1606 | |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1607 | static struct attribute *it87_attributes_temp_offset[] = { |
| 1608 | &sensor_dev_attr_temp1_offset.dev_attr.attr, |
| 1609 | &sensor_dev_attr_temp2_offset.dev_attr.attr, |
| 1610 | &sensor_dev_attr_temp3_offset.dev_attr.attr, |
| 1611 | }; |
| 1612 | |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 1613 | static struct attribute *it87_attributes[] = { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1614 | &dev_attr_alarms.attr, |
Jean Delvare | 3d30f9e | 2011-07-25 21:46:10 +0200 | [diff] [blame] | 1615 | &sensor_dev_attr_intrusion0_alarm.dev_attr.attr, |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1616 | &dev_attr_name.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1617 | NULL |
| 1618 | }; |
| 1619 | |
| 1620 | static const struct attribute_group it87_group = { |
| 1621 | .attrs = it87_attributes, |
| 1622 | }; |
| 1623 | |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1624 | static struct attribute *it87_attributes_in_beep[] = { |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1625 | &sensor_dev_attr_in0_beep.dev_attr.attr, |
| 1626 | &sensor_dev_attr_in1_beep.dev_attr.attr, |
| 1627 | &sensor_dev_attr_in2_beep.dev_attr.attr, |
| 1628 | &sensor_dev_attr_in3_beep.dev_attr.attr, |
| 1629 | &sensor_dev_attr_in4_beep.dev_attr.attr, |
| 1630 | &sensor_dev_attr_in5_beep.dev_attr.attr, |
| 1631 | &sensor_dev_attr_in6_beep.dev_attr.attr, |
| 1632 | &sensor_dev_attr_in7_beep.dev_attr.attr, |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1633 | NULL, |
| 1634 | NULL, |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1635 | }; |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1636 | |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 1637 | static struct attribute *it87_attributes_temp_beep[] = { |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1638 | &sensor_dev_attr_temp1_beep.dev_attr.attr, |
| 1639 | &sensor_dev_attr_temp2_beep.dev_attr.attr, |
| 1640 | &sensor_dev_attr_temp3_beep.dev_attr.attr, |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1641 | }; |
| 1642 | |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1643 | static struct attribute *it87_attributes_fan[5][3+1] = { { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1644 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 1645 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1646 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
| 1647 | NULL |
| 1648 | }, { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1649 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
| 1650 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1651 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
| 1652 | NULL |
| 1653 | }, { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1654 | &sensor_dev_attr_fan3_input.dev_attr.attr, |
| 1655 | &sensor_dev_attr_fan3_min.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1656 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1657 | NULL |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1658 | }, { |
| 1659 | &sensor_dev_attr_fan4_input.dev_attr.attr, |
| 1660 | &sensor_dev_attr_fan4_min.dev_attr.attr, |
| 1661 | &sensor_dev_attr_fan4_alarm.dev_attr.attr, |
| 1662 | NULL |
| 1663 | }, { |
| 1664 | &sensor_dev_attr_fan5_input.dev_attr.attr, |
| 1665 | &sensor_dev_attr_fan5_min.dev_attr.attr, |
| 1666 | &sensor_dev_attr_fan5_alarm.dev_attr.attr, |
| 1667 | NULL |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1668 | } }; |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1669 | |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1670 | static const struct attribute_group it87_group_fan[5] = { |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1671 | { .attrs = it87_attributes_fan[0] }, |
| 1672 | { .attrs = it87_attributes_fan[1] }, |
| 1673 | { .attrs = it87_attributes_fan[2] }, |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1674 | { .attrs = it87_attributes_fan[3] }, |
| 1675 | { .attrs = it87_attributes_fan[4] }, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1676 | }; |
| 1677 | |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 1678 | static const struct attribute *it87_attributes_fan_div[] = { |
| 1679 | &sensor_dev_attr_fan1_div.dev_attr.attr, |
| 1680 | &sensor_dev_attr_fan2_div.dev_attr.attr, |
| 1681 | &sensor_dev_attr_fan3_div.dev_attr.attr, |
| 1682 | }; |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1683 | |
| 1684 | static struct attribute *it87_attributes_pwm[3][4+1] = { { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1685 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1686 | &sensor_dev_attr_pwm1.dev_attr.attr, |
Jean Delvare | d5b0b5d | 2007-12-14 14:41:53 +0100 | [diff] [blame] | 1687 | &dev_attr_pwm1_freq.attr, |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1688 | &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1689 | NULL |
| 1690 | }, { |
| 1691 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, |
| 1692 | &sensor_dev_attr_pwm2.dev_attr.attr, |
| 1693 | &dev_attr_pwm2_freq.attr, |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1694 | &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1695 | NULL |
| 1696 | }, { |
| 1697 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, |
| 1698 | &sensor_dev_attr_pwm3.dev_attr.attr, |
| 1699 | &dev_attr_pwm3_freq.attr, |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1700 | &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1701 | NULL |
| 1702 | } }; |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1703 | |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1704 | static const struct attribute_group it87_group_pwm[3] = { |
| 1705 | { .attrs = it87_attributes_pwm[0] }, |
| 1706 | { .attrs = it87_attributes_pwm[1] }, |
| 1707 | { .attrs = it87_attributes_pwm[2] }, |
| 1708 | }; |
| 1709 | |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1710 | static struct attribute *it87_attributes_autopwm[3][9+1] = { { |
| 1711 | &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, |
| 1712 | &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, |
| 1713 | &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr, |
| 1714 | &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr, |
| 1715 | &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr, |
| 1716 | &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr, |
| 1717 | &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr, |
| 1718 | &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr, |
| 1719 | &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr, |
| 1720 | NULL |
| 1721 | }, { |
| 1722 | &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, |
| 1723 | &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr, |
| 1724 | &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr, |
| 1725 | &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr, |
| 1726 | &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr, |
| 1727 | &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr, |
| 1728 | &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr, |
| 1729 | &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr, |
| 1730 | &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr, |
| 1731 | NULL |
| 1732 | }, { |
| 1733 | &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, |
| 1734 | &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr, |
| 1735 | &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr, |
| 1736 | &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr, |
| 1737 | &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr, |
| 1738 | &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr, |
| 1739 | &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr, |
| 1740 | &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr, |
| 1741 | &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr, |
| 1742 | NULL |
| 1743 | } }; |
| 1744 | |
| 1745 | static const struct attribute_group it87_group_autopwm[3] = { |
| 1746 | { .attrs = it87_attributes_autopwm[0] }, |
| 1747 | { .attrs = it87_attributes_autopwm[1] }, |
| 1748 | { .attrs = it87_attributes_autopwm[2] }, |
| 1749 | }; |
| 1750 | |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1751 | static struct attribute *it87_attributes_fan_beep[] = { |
| 1752 | &sensor_dev_attr_fan1_beep.dev_attr.attr, |
| 1753 | &sensor_dev_attr_fan2_beep.dev_attr.attr, |
| 1754 | &sensor_dev_attr_fan3_beep.dev_attr.attr, |
| 1755 | &sensor_dev_attr_fan4_beep.dev_attr.attr, |
| 1756 | &sensor_dev_attr_fan5_beep.dev_attr.attr, |
| 1757 | }; |
| 1758 | |
Jean Delvare | 6a8d7ac | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1759 | static struct attribute *it87_attributes_vid[] = { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1760 | &dev_attr_vrm.attr, |
| 1761 | &dev_attr_cpu0_vid.attr, |
| 1762 | NULL |
| 1763 | }; |
| 1764 | |
Jean Delvare | 6a8d7ac | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1765 | static const struct attribute_group it87_group_vid = { |
| 1766 | .attrs = it87_attributes_vid, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1767 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1769 | static struct attribute *it87_attributes_label[] = { |
| 1770 | &sensor_dev_attr_in3_label.dev_attr.attr, |
| 1771 | &sensor_dev_attr_in7_label.dev_attr.attr, |
| 1772 | &sensor_dev_attr_in8_label.dev_attr.attr, |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1773 | &sensor_dev_attr_in9_label.dev_attr.attr, |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1774 | NULL |
| 1775 | }; |
| 1776 | |
| 1777 | static const struct attribute_group it87_group_label = { |
Jean Delvare | fa8b697 | 2011-07-17 18:39:19 +0200 | [diff] [blame] | 1778 | .attrs = it87_attributes_label, |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1779 | }; |
| 1780 | |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 1781 | /* SuperIO detection - will change isa_address if a chip is found */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1782 | static int __init it87_find(unsigned short *address, |
| 1783 | struct it87_sio_data *sio_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1784 | { |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 1785 | int err; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1786 | u16 chip_type; |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 1787 | const char *board_vendor, *board_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1788 | |
Nat Gurumoorthy | 5b0380c | 2011-05-25 20:43:33 +0200 | [diff] [blame] | 1789 | err = superio_enter(); |
| 1790 | if (err) |
| 1791 | return err; |
| 1792 | |
| 1793 | err = -ENODEV; |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 1794 | chip_type = force_id ? force_id : superio_inw(DEVID); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1795 | |
| 1796 | switch (chip_type) { |
| 1797 | case IT8705F_DEVID: |
| 1798 | sio_data->type = it87; |
| 1799 | break; |
| 1800 | case IT8712F_DEVID: |
| 1801 | sio_data->type = it8712; |
| 1802 | break; |
| 1803 | case IT8716F_DEVID: |
| 1804 | case IT8726F_DEVID: |
| 1805 | sio_data->type = it8716; |
| 1806 | break; |
| 1807 | case IT8718F_DEVID: |
| 1808 | sio_data->type = it8718; |
| 1809 | break; |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 1810 | case IT8720F_DEVID: |
| 1811 | sio_data->type = it8720; |
| 1812 | break; |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1813 | case IT8721F_DEVID: |
| 1814 | sio_data->type = it8721; |
| 1815 | break; |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 1816 | case IT8728F_DEVID: |
| 1817 | sio_data->type = it8728; |
| 1818 | break; |
Guenter Roeck | b063670 | 2012-09-07 17:34:41 -0600 | [diff] [blame] | 1819 | case IT8771E_DEVID: |
| 1820 | sio_data->type = it8771; |
| 1821 | break; |
| 1822 | case IT8772E_DEVID: |
| 1823 | sio_data->type = it8772; |
| 1824 | break; |
Guenter Roeck | 7bc32d2 | 2015-01-17 14:10:24 -0800 | [diff] [blame] | 1825 | case IT8781F_DEVID: |
| 1826 | sio_data->type = it8781; |
| 1827 | break; |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 1828 | case IT8782F_DEVID: |
| 1829 | sio_data->type = it8782; |
| 1830 | break; |
| 1831 | case IT8783E_DEVID: |
| 1832 | sio_data->type = it8783; |
| 1833 | break; |
Thomas Lorblanches | a0c1424 | 2015-02-13 13:19:06 +0100 | [diff] [blame] | 1834 | case IT8786E_DEVID: |
| 1835 | sio_data->type = it8786; |
| 1836 | break; |
Rudolf Marek | 7183ae8 | 2014-04-04 18:01:35 +0200 | [diff] [blame] | 1837 | case IT8603E_DEVID: |
Rudolf Marek | 574e9bd | 2014-04-04 18:01:35 +0200 | [diff] [blame] | 1838 | case IT8623E_DEVID: |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1839 | sio_data->type = it8603; |
| 1840 | break; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1841 | case 0xffff: /* No device at all */ |
| 1842 | goto exit; |
| 1843 | default: |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 1844 | pr_debug("Unsupported chip (DEVID=0x%x)\n", chip_type); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1845 | goto exit; |
| 1846 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1848 | superio_select(PME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | if (!(superio_inb(IT87_ACT_REG) & 0x01)) { |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 1850 | pr_info("Device not activated, skipping\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | goto exit; |
| 1852 | } |
| 1853 | |
| 1854 | *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1); |
| 1855 | if (*address == 0) { |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 1856 | pr_info("Base address not set, skipping\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | goto exit; |
| 1858 | } |
| 1859 | |
| 1860 | err = 0; |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 1861 | sio_data->revision = superio_inb(DEVREV) & 0x0f; |
Guenter Roeck | faf392f | 2015-03-26 08:36:18 -0700 | [diff] [blame] | 1862 | pr_info("Found IT%04x%s chip at 0x%x, revision %d\n", chip_type, |
| 1863 | it87_devices[sio_data->type].suffix, |
Thomas Lorblanches | a0c1424 | 2015-02-13 13:19:06 +0100 | [diff] [blame] | 1864 | *address, sio_data->revision); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1865 | |
Guenter Roeck | 7f5726c | 2015-03-26 08:49:18 -0700 | [diff] [blame^] | 1866 | /* in7 (VSB or VCCH5V) is always internal on some chips */ |
| 1867 | if (it87_devices[sio_data->type].features & FEAT_IN7_INTERNAL) |
| 1868 | sio_data->internal |= (1 << 1); |
| 1869 | |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1870 | /* in8 (Vbat) is always internal */ |
Guenter Roeck | 7f5726c | 2015-03-26 08:49:18 -0700 | [diff] [blame^] | 1871 | sio_data->internal |= (1 << 2); |
| 1872 | |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1873 | /* Only the IT8603E has in9 */ |
| 1874 | if (sio_data->type != it8603) |
| 1875 | sio_data->skip_in |= (1 << 9); |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1876 | |
Guenter Roeck | 32dd7c4 | 2015-02-12 07:40:23 -0800 | [diff] [blame] | 1877 | if (!(it87_devices[sio_data->type].features & FEAT_VID)) |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 1878 | sio_data->skip_vid = 1; |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1879 | |
Guenter Roeck | 32dd7c4 | 2015-02-12 07:40:23 -0800 | [diff] [blame] | 1880 | /* Read GPIO config and VID value from LDN 7 (GPIO) */ |
| 1881 | if (sio_data->type == it87) { |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1882 | /* The IT8705F has a different LD number for GPIO */ |
| 1883 | superio_select(5); |
| 1884 | sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 1885 | } else if (sio_data->type == it8783) { |
Guenter Roeck | 088ce2a | 2013-03-13 16:40:39 -0700 | [diff] [blame] | 1886 | int reg25, reg27, reg2a, reg2c, regef; |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 1887 | |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 1888 | superio_select(GPIO); |
| 1889 | |
| 1890 | reg25 = superio_inb(IT87_SIO_GPIO1_REG); |
| 1891 | reg27 = superio_inb(IT87_SIO_GPIO3_REG); |
Guenter Roeck | 088ce2a | 2013-03-13 16:40:39 -0700 | [diff] [blame] | 1892 | reg2a = superio_inb(IT87_SIO_PINX1_REG); |
| 1893 | reg2c = superio_inb(IT87_SIO_PINX2_REG); |
| 1894 | regef = superio_inb(IT87_SIO_SPI_REG); |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 1895 | |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 1896 | /* Check if fan3 is there or not */ |
Guenter Roeck | 088ce2a | 2013-03-13 16:40:39 -0700 | [diff] [blame] | 1897 | if ((reg27 & (1 << 0)) || !(reg2c & (1 << 2))) |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 1898 | sio_data->skip_fan |= (1 << 2); |
| 1899 | if ((reg25 & (1 << 4)) |
Guenter Roeck | 088ce2a | 2013-03-13 16:40:39 -0700 | [diff] [blame] | 1900 | || (!(reg2a & (1 << 1)) && (regef & (1 << 0)))) |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 1901 | sio_data->skip_pwm |= (1 << 2); |
| 1902 | |
| 1903 | /* Check if fan2 is there or not */ |
| 1904 | if (reg27 & (1 << 7)) |
| 1905 | sio_data->skip_fan |= (1 << 1); |
| 1906 | if (reg27 & (1 << 3)) |
| 1907 | sio_data->skip_pwm |= (1 << 1); |
| 1908 | |
| 1909 | /* VIN5 */ |
Guenter Roeck | 088ce2a | 2013-03-13 16:40:39 -0700 | [diff] [blame] | 1910 | if ((reg27 & (1 << 0)) || (reg2c & (1 << 2))) |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1911 | sio_data->skip_in |= (1 << 5); /* No VIN5 */ |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 1912 | |
| 1913 | /* VIN6 */ |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1914 | if (reg27 & (1 << 1)) |
| 1915 | sio_data->skip_in |= (1 << 6); /* No VIN6 */ |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 1916 | |
| 1917 | /* |
| 1918 | * VIN7 |
| 1919 | * Does not depend on bit 2 of Reg2C, contrary to datasheet. |
| 1920 | */ |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1921 | if (reg27 & (1 << 2)) { |
| 1922 | /* |
| 1923 | * The data sheet is a bit unclear regarding the |
| 1924 | * internal voltage divider for VCCH5V. It says |
| 1925 | * "This bit enables and switches VIN7 (pin 91) to the |
| 1926 | * internal voltage divider for VCCH5V". |
| 1927 | * This is different to other chips, where the internal |
| 1928 | * voltage divider would connect VIN7 to an internal |
| 1929 | * voltage source. Maybe that is the case here as well. |
| 1930 | * |
| 1931 | * Since we don't know for sure, re-route it if that is |
| 1932 | * not the case, and ask the user to report if the |
| 1933 | * resulting voltage is sane. |
| 1934 | */ |
Guenter Roeck | 088ce2a | 2013-03-13 16:40:39 -0700 | [diff] [blame] | 1935 | if (!(reg2c & (1 << 1))) { |
| 1936 | reg2c |= (1 << 1); |
| 1937 | superio_outb(IT87_SIO_PINX2_REG, reg2c); |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1938 | pr_notice("Routing internal VCCH5V to in7.\n"); |
| 1939 | } |
| 1940 | pr_notice("in7 routed to internal voltage divider, with external pin disabled.\n"); |
| 1941 | pr_notice("Please report if it displays a reasonable voltage.\n"); |
| 1942 | } |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 1943 | |
Guenter Roeck | 088ce2a | 2013-03-13 16:40:39 -0700 | [diff] [blame] | 1944 | if (reg2c & (1 << 0)) |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 1945 | sio_data->internal |= (1 << 0); |
Guenter Roeck | 088ce2a | 2013-03-13 16:40:39 -0700 | [diff] [blame] | 1946 | if (reg2c & (1 << 1)) |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 1947 | sio_data->internal |= (1 << 1); |
| 1948 | |
| 1949 | sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1950 | } else if (sio_data->type == it8603) { |
| 1951 | int reg27, reg29; |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 1952 | |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1953 | superio_select(GPIO); |
| 1954 | |
| 1955 | reg27 = superio_inb(IT87_SIO_GPIO3_REG); |
| 1956 | |
| 1957 | /* Check if fan3 is there or not */ |
| 1958 | if (reg27 & (1 << 6)) |
| 1959 | sio_data->skip_pwm |= (1 << 2); |
| 1960 | if (reg27 & (1 << 7)) |
| 1961 | sio_data->skip_fan |= (1 << 2); |
| 1962 | |
| 1963 | /* Check if fan2 is there or not */ |
| 1964 | reg29 = superio_inb(IT87_SIO_GPIO5_REG); |
| 1965 | if (reg29 & (1 << 1)) |
| 1966 | sio_data->skip_pwm |= (1 << 1); |
| 1967 | if (reg29 & (1 << 2)) |
| 1968 | sio_data->skip_fan |= (1 << 1); |
| 1969 | |
| 1970 | sio_data->skip_in |= (1 << 5); /* No VIN5 */ |
| 1971 | sio_data->skip_in |= (1 << 6); /* No VIN6 */ |
| 1972 | |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 1973 | sio_data->internal |= (1 << 3); /* in9 is AVCC */ |
| 1974 | |
| 1975 | sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 1976 | } else { |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1977 | int reg; |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 1978 | bool uart6; |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1979 | |
| 1980 | superio_select(GPIO); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1981 | |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 1982 | reg = superio_inb(IT87_SIO_GPIO3_REG); |
Guenter Roeck | 32dd7c4 | 2015-02-12 07:40:23 -0800 | [diff] [blame] | 1983 | if (!sio_data->skip_vid) { |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1984 | /* We need at least 4 VID pins */ |
| 1985 | if (reg & 0x0f) { |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 1986 | pr_info("VID is disabled (pins used for GPIO)\n"); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 1987 | sio_data->skip_vid = 1; |
| 1988 | } |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 1989 | } |
| 1990 | |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 1991 | /* Check if fan3 is there or not */ |
| 1992 | if (reg & (1 << 6)) |
| 1993 | sio_data->skip_pwm |= (1 << 2); |
| 1994 | if (reg & (1 << 7)) |
| 1995 | sio_data->skip_fan |= (1 << 2); |
| 1996 | |
| 1997 | /* Check if fan2 is there or not */ |
| 1998 | reg = superio_inb(IT87_SIO_GPIO5_REG); |
| 1999 | if (reg & (1 << 1)) |
| 2000 | sio_data->skip_pwm |= (1 << 1); |
| 2001 | if (reg & (1 << 2)) |
| 2002 | sio_data->skip_fan |= (1 << 1); |
| 2003 | |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 2004 | if ((sio_data->type == it8718 || sio_data->type == it8720) |
| 2005 | && !(sio_data->skip_vid)) |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2006 | sio_data->vid_value = superio_inb(IT87_SIO_VID_REG); |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 2007 | |
| 2008 | reg = superio_inb(IT87_SIO_PINX2_REG); |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2009 | |
| 2010 | uart6 = sio_data->type == it8782 && (reg & (1 << 2)); |
| 2011 | |
Jean Delvare | 436cad2 | 2010-07-09 16:22:48 +0200 | [diff] [blame] | 2012 | /* |
| 2013 | * The IT8720F has no VIN7 pin, so VCCH should always be |
| 2014 | * routed internally to VIN7 with an internal divider. |
| 2015 | * Curiously, there still is a configuration bit to control |
| 2016 | * this, which means it can be set incorrectly. And even |
| 2017 | * more curiously, many boards out there are improperly |
| 2018 | * configured, even though the IT8720F datasheet claims |
| 2019 | * that the internal routing of VCCH to VIN7 is the default |
| 2020 | * setting. So we force the internal routing in this case. |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 2021 | * |
| 2022 | * On IT8782F, VIN7 is multiplexed with one of the UART6 pins. |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2023 | * If UART6 is enabled, re-route VIN7 to the internal divider |
| 2024 | * if that is not already the case. |
Jean Delvare | 436cad2 | 2010-07-09 16:22:48 +0200 | [diff] [blame] | 2025 | */ |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2026 | if ((sio_data->type == it8720 || uart6) && !(reg & (1 << 1))) { |
Jean Delvare | 436cad2 | 2010-07-09 16:22:48 +0200 | [diff] [blame] | 2027 | reg |= (1 << 1); |
| 2028 | superio_outb(IT87_SIO_PINX2_REG, reg); |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2029 | pr_notice("Routing internal VCCH to in7\n"); |
Jean Delvare | 436cad2 | 2010-07-09 16:22:48 +0200 | [diff] [blame] | 2030 | } |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 2031 | if (reg & (1 << 0)) |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 2032 | sio_data->internal |= (1 << 0); |
Guenter Roeck | 7f5726c | 2015-03-26 08:49:18 -0700 | [diff] [blame^] | 2033 | if (reg & (1 << 1)) |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 2034 | sio_data->internal |= (1 << 1); |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2035 | |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2036 | /* |
| 2037 | * On IT8782F, UART6 pins overlap with VIN5, VIN6, and VIN7. |
| 2038 | * While VIN7 can be routed to the internal voltage divider, |
| 2039 | * VIN5 and VIN6 are not available if UART6 is enabled. |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 2040 | * |
| 2041 | * Also, temp3 is not available if UART6 is enabled and TEMPIN3 |
| 2042 | * is the temperature source. Since we can not read the |
| 2043 | * temperature source here, skip_temp is preliminary. |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2044 | */ |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 2045 | if (uart6) { |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2046 | sio_data->skip_in |= (1 << 5) | (1 << 6); |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 2047 | sio_data->skip_temp |= (1 << 2); |
| 2048 | } |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2049 | |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2050 | sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 2051 | } |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2052 | if (sio_data->beep_pin) |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2053 | pr_info("Beeping is supported\n"); |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 2054 | |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 2055 | /* Disable specific features based on DMI strings */ |
| 2056 | board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR); |
| 2057 | board_name = dmi_get_system_info(DMI_BOARD_NAME); |
| 2058 | if (board_vendor && board_name) { |
| 2059 | if (strcmp(board_vendor, "nVIDIA") == 0 |
| 2060 | && strcmp(board_name, "FN68PT") == 0) { |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2061 | /* |
| 2062 | * On the Shuttle SN68PT, FAN_CTL2 is apparently not |
| 2063 | * connected to a fan, but to something else. One user |
| 2064 | * has reported instant system power-off when changing |
| 2065 | * the PWM2 duty cycle, so we disable it. |
| 2066 | * I use the board name string as the trigger in case |
| 2067 | * the same board is ever used in other systems. |
| 2068 | */ |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2069 | pr_info("Disabling pwm2 due to hardware constraints\n"); |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 2070 | sio_data->skip_pwm = (1 << 1); |
| 2071 | } |
| 2072 | } |
| 2073 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | exit: |
| 2075 | superio_exit(); |
| 2076 | return err; |
| 2077 | } |
| 2078 | |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2079 | static void it87_remove_files(struct device *dev) |
| 2080 | { |
| 2081 | struct it87_data *data = platform_get_drvdata(pdev); |
Jingoo Han | a8b3a3a | 2013-07-30 17:13:06 +0900 | [diff] [blame] | 2082 | struct it87_sio_data *sio_data = dev_get_platdata(dev); |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2083 | int i; |
| 2084 | |
| 2085 | sysfs_remove_group(&dev->kobj, &it87_group); |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 2086 | for (i = 0; i < 10; i++) { |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2087 | if (sio_data->skip_in & (1 << i)) |
| 2088 | continue; |
| 2089 | sysfs_remove_group(&dev->kobj, &it87_group_in[i]); |
| 2090 | if (it87_attributes_in_beep[i]) |
| 2091 | sysfs_remove_file(&dev->kobj, |
| 2092 | it87_attributes_in_beep[i]); |
| 2093 | } |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 2094 | for (i = 0; i < 3; i++) { |
| 2095 | if (!(data->has_temp & (1 << i))) |
| 2096 | continue; |
| 2097 | sysfs_remove_group(&dev->kobj, &it87_group_temp[i]); |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 2098 | if (has_temp_offset(data)) |
| 2099 | sysfs_remove_file(&dev->kobj, |
| 2100 | it87_attributes_temp_offset[i]); |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 2101 | if (sio_data->beep_pin) |
| 2102 | sysfs_remove_file(&dev->kobj, |
| 2103 | it87_attributes_temp_beep[i]); |
| 2104 | } |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2105 | for (i = 0; i < 5; i++) { |
| 2106 | if (!(data->has_fan & (1 << i))) |
| 2107 | continue; |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 2108 | sysfs_remove_group(&dev->kobj, &it87_group_fan[i]); |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2109 | if (sio_data->beep_pin) |
| 2110 | sysfs_remove_file(&dev->kobj, |
| 2111 | it87_attributes_fan_beep[i]); |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 2112 | if (i < 3 && !has_16bit_fans(data)) |
| 2113 | sysfs_remove_file(&dev->kobj, |
| 2114 | it87_attributes_fan_div[i]); |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2115 | } |
| 2116 | for (i = 0; i < 3; i++) { |
Guenter Roeck | 1696d1d | 2015-03-27 06:03:41 -0700 | [diff] [blame] | 2117 | if (sio_data->skip_pwm & (1 << i)) |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2118 | continue; |
| 2119 | sysfs_remove_group(&dev->kobj, &it87_group_pwm[i]); |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 2120 | if (has_old_autopwm(data)) |
| 2121 | sysfs_remove_group(&dev->kobj, |
| 2122 | &it87_group_autopwm[i]); |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2123 | } |
Jean Delvare | 6a8d7ac | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2124 | if (!sio_data->skip_vid) |
| 2125 | sysfs_remove_group(&dev->kobj, &it87_group_vid); |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 2126 | sysfs_remove_group(&dev->kobj, &it87_group_label); |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2127 | } |
| 2128 | |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 2129 | static int it87_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2131 | struct it87_data *data; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2132 | struct resource *res; |
| 2133 | struct device *dev = &pdev->dev; |
Jingoo Han | a8b3a3a | 2013-07-30 17:13:06 +0900 | [diff] [blame] | 2134 | struct it87_sio_data *sio_data = dev_get_platdata(dev); |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2135 | int err = 0, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2136 | int enable_pwm_interface; |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2137 | int fan_beep_need_rw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2138 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2139 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2140 | if (!devm_request_region(&pdev->dev, res->start, IT87_EC_EXTENT, |
| 2141 | DRVNAME)) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2142 | dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", |
| 2143 | (unsigned long)res->start, |
Bjorn Helgaas | 87b4b66 | 2008-01-22 07:21:03 -0500 | [diff] [blame] | 2144 | (unsigned long)(res->start + IT87_EC_EXTENT - 1)); |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2145 | return -EBUSY; |
Jean Delvare | 8e9afcb | 2006-12-12 18:18:28 +0100 | [diff] [blame] | 2146 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2148 | data = devm_kzalloc(&pdev->dev, sizeof(struct it87_data), GFP_KERNEL); |
| 2149 | if (!data) |
| 2150 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2151 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2152 | data->addr = res->start; |
| 2153 | data->type = sio_data->type; |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 2154 | data->features = it87_devices[sio_data->type].features; |
Guenter Roeck | 5d8d2f2 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 2155 | data->peci_mask = it87_devices[sio_data->type].peci_mask; |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 2156 | data->old_peci_mask = it87_devices[sio_data->type].old_peci_mask; |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 2157 | data->name = it87_devices[sio_data->type].name; |
| 2158 | /* |
| 2159 | * IT8705F Datasheet 0.4.1, 3h == Version G. |
| 2160 | * IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J. |
| 2161 | * These are the first revisions with 16-bit tachometer support. |
| 2162 | */ |
| 2163 | switch (data->type) { |
| 2164 | case it87: |
| 2165 | if (sio_data->revision >= 0x03) { |
| 2166 | data->features &= ~FEAT_OLD_AUTOPWM; |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 2167 | data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS; |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 2168 | } |
| 2169 | break; |
| 2170 | case it8712: |
| 2171 | if (sio_data->revision >= 0x08) { |
| 2172 | data->features &= ~FEAT_OLD_AUTOPWM; |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 2173 | data->features |= FEAT_FAN16_CONFIG | FEAT_16BIT_FANS | |
| 2174 | FEAT_FIVE_FANS; |
Guenter Roeck | 483db43 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 2175 | } |
| 2176 | break; |
| 2177 | default: |
| 2178 | break; |
| 2179 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2180 | |
| 2181 | /* Now, we do the remaining detection. */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2182 | if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80) |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2183 | || it87_read_value(data, IT87_REG_CHIPID) != 0x90) |
| 2184 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2186 | platform_set_drvdata(pdev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 2188 | mutex_init(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | /* Check PWM configuration */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2191 | enable_pwm_interface = it87_check_pwm(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2192 | |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 2193 | /* Starting with IT8721F, we handle scaling of internal voltages */ |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 2194 | if (has_12mv_adc(data)) { |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 2195 | if (sio_data->internal & (1 << 0)) |
| 2196 | data->in_scaled |= (1 << 3); /* in3 is AVCC */ |
| 2197 | if (sio_data->internal & (1 << 1)) |
| 2198 | data->in_scaled |= (1 << 7); /* in7 is VSB */ |
| 2199 | if (sio_data->internal & (1 << 2)) |
| 2200 | data->in_scaled |= (1 << 8); /* in8 is Vbat */ |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 2201 | if (sio_data->internal & (1 << 3)) |
| 2202 | data->in_scaled |= (1 << 9); /* in9 is AVCC */ |
Guenter Roeck | 7bc32d2 | 2015-01-17 14:10:24 -0800 | [diff] [blame] | 2203 | } else if (sio_data->type == it8781 || sio_data->type == it8782 || |
| 2204 | sio_data->type == it8783) { |
Guenter Roeck | 0531d98 | 2012-03-02 11:46:44 -0800 | [diff] [blame] | 2205 | if (sio_data->internal & (1 << 0)) |
| 2206 | data->in_scaled |= (1 << 3); /* in3 is VCC5V */ |
| 2207 | if (sio_data->internal & (1 << 1)) |
| 2208 | data->in_scaled |= (1 << 7); /* in7 is VCCH5V */ |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 2209 | } |
| 2210 | |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 2211 | data->has_temp = 0x07; |
| 2212 | if (sio_data->skip_temp & (1 << 2)) { |
| 2213 | if (sio_data->type == it8782 |
| 2214 | && !(it87_read_value(data, IT87_REG_TEMP_EXTRA) & 0x80)) |
| 2215 | data->has_temp &= ~(1 << 2); |
| 2216 | } |
| 2217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | /* Initialize the IT87 chip */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2219 | it87_init_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | |
| 2221 | /* Register sysfs hooks */ |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2222 | err = sysfs_create_group(&dev->kobj, &it87_group); |
| 2223 | if (err) |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2224 | return err; |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2225 | |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 2226 | for (i = 0; i < 10; i++) { |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2227 | if (sio_data->skip_in & (1 << i)) |
| 2228 | continue; |
| 2229 | err = sysfs_create_group(&dev->kobj, &it87_group_in[i]); |
| 2230 | if (err) |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2231 | goto error; |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2232 | if (sio_data->beep_pin && it87_attributes_in_beep[i]) { |
| 2233 | err = sysfs_create_file(&dev->kobj, |
| 2234 | it87_attributes_in_beep[i]); |
| 2235 | if (err) |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2236 | goto error; |
Guenter Roeck | 9172b5d | 2012-03-24 21:49:54 -0700 | [diff] [blame] | 2237 | } |
| 2238 | } |
| 2239 | |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 2240 | for (i = 0; i < 3; i++) { |
| 2241 | if (!(data->has_temp & (1 << i))) |
| 2242 | continue; |
| 2243 | err = sysfs_create_group(&dev->kobj, &it87_group_temp[i]); |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2244 | if (err) |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2245 | goto error; |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 2246 | if (has_temp_offset(data)) { |
| 2247 | err = sysfs_create_file(&dev->kobj, |
| 2248 | it87_attributes_temp_offset[i]); |
| 2249 | if (err) |
| 2250 | goto error; |
| 2251 | } |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 2252 | if (sio_data->beep_pin) { |
| 2253 | err = sysfs_create_file(&dev->kobj, |
| 2254 | it87_attributes_temp_beep[i]); |
| 2255 | if (err) |
| 2256 | goto error; |
| 2257 | } |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2258 | } |
| 2259 | |
Jean Delvare | 9060f8b | 2006-08-28 14:24:17 +0200 | [diff] [blame] | 2260 | /* Do not create fan files for disabled fans */ |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2261 | fan_beep_need_rw = 1; |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2262 | for (i = 0; i < 5; i++) { |
| 2263 | if (!(data->has_fan & (1 << i))) |
| 2264 | continue; |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 2265 | err = sysfs_create_group(&dev->kobj, &it87_group_fan[i]); |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2266 | if (err) |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2267 | goto error; |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2268 | |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 2269 | if (i < 3 && !has_16bit_fans(data)) { |
| 2270 | err = sysfs_create_file(&dev->kobj, |
| 2271 | it87_attributes_fan_div[i]); |
| 2272 | if (err) |
| 2273 | goto error; |
| 2274 | } |
| 2275 | |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2276 | if (sio_data->beep_pin) { |
| 2277 | err = sysfs_create_file(&dev->kobj, |
| 2278 | it87_attributes_fan_beep[i]); |
| 2279 | if (err) |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2280 | goto error; |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2281 | if (!fan_beep_need_rw) |
| 2282 | continue; |
| 2283 | |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2284 | /* |
| 2285 | * As we have a single beep enable bit for all fans, |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2286 | * only the first enabled fan has a writable attribute |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2287 | * for it. |
| 2288 | */ |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2289 | if (sysfs_chmod_file(&dev->kobj, |
| 2290 | it87_attributes_fan_beep[i], |
| 2291 | S_IRUGO | S_IWUSR)) |
| 2292 | dev_dbg(dev, "chmod +w fan%d_beep failed\n", |
| 2293 | i + 1); |
| 2294 | fan_beep_need_rw = 0; |
| 2295 | } |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2296 | } |
| 2297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2298 | if (enable_pwm_interface) { |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2299 | for (i = 0; i < 3; i++) { |
| 2300 | if (sio_data->skip_pwm & (1 << i)) |
| 2301 | continue; |
| 2302 | err = sysfs_create_group(&dev->kobj, |
| 2303 | &it87_group_pwm[i]); |
| 2304 | if (err) |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2305 | goto error; |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 2306 | |
| 2307 | if (!has_old_autopwm(data)) |
| 2308 | continue; |
| 2309 | err = sysfs_create_group(&dev->kobj, |
| 2310 | &it87_group_autopwm[i]); |
| 2311 | if (err) |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2312 | goto error; |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 2313 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | } |
| 2315 | |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 2316 | if (!sio_data->skip_vid) { |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 2317 | data->vrm = vid_which_vrm(); |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 2318 | /* VID reading from Super-I/O config space if available */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2319 | data->vid = sio_data->vid_value; |
Jean Delvare | 6a8d7ac | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2320 | err = sysfs_create_group(&dev->kobj, &it87_group_vid); |
| 2321 | if (err) |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2322 | goto error; |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 2323 | } |
| 2324 | |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 2325 | /* Export labels for internal sensors */ |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 2326 | for (i = 0; i < 4; i++) { |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 2327 | if (!(sio_data->internal & (1 << i))) |
| 2328 | continue; |
| 2329 | err = sysfs_create_file(&dev->kobj, |
| 2330 | it87_attributes_label[i]); |
| 2331 | if (err) |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2332 | goto error; |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 2333 | } |
| 2334 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 2335 | data->hwmon_dev = hwmon_device_register(dev); |
| 2336 | if (IS_ERR(data->hwmon_dev)) { |
| 2337 | err = PTR_ERR(data->hwmon_dev); |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2338 | goto error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | } |
| 2340 | |
| 2341 | return 0; |
| 2342 | |
Guenter Roeck | 62a1d05 | 2012-03-24 21:54:41 -0700 | [diff] [blame] | 2343 | error: |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2344 | it87_remove_files(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2345 | return err; |
| 2346 | } |
| 2347 | |
Bill Pemberton | 281dfd0 | 2012-11-19 13:25:51 -0500 | [diff] [blame] | 2348 | static int it87_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2349 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2350 | struct it87_data *data = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 2352 | hwmon_device_unregister(data->hwmon_dev); |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 2353 | it87_remove_files(&pdev->dev); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 2354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | return 0; |
| 2356 | } |
| 2357 | |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2358 | /* |
| 2359 | * Must be called with data->update_lock held, except during initialization. |
| 2360 | * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
| 2361 | * would slow down the IT87 access and should not be necessary. |
| 2362 | */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2363 | static int it87_read_value(struct it87_data *data, u8 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2365 | outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); |
| 2366 | return inb_p(data->addr + IT87_DATA_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2367 | } |
| 2368 | |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2369 | /* |
| 2370 | * Must be called with data->update_lock held, except during initialization. |
| 2371 | * We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
| 2372 | * would slow down the IT87 access and should not be necessary. |
| 2373 | */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2374 | static void it87_write_value(struct it87_data *data, u8 reg, u8 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2376 | outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); |
| 2377 | outb_p(value, data->addr + IT87_DATA_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | } |
| 2379 | |
| 2380 | /* Return 1 if and only if the PWM interface is safe to use */ |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 2381 | static int it87_check_pwm(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2382 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2383 | struct it87_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2384 | /* |
| 2385 | * Some BIOSes fail to correctly configure the IT87 fans. All fans off |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | * and polarity set to active low is sign that this is the case so we |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2387 | * disable pwm control to protect the user. |
| 2388 | */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2389 | int tmp = it87_read_value(data, IT87_REG_FAN_CTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2390 | if ((tmp & 0x87) == 0) { |
| 2391 | if (fix_pwm_polarity) { |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2392 | /* |
| 2393 | * The user asks us to attempt a chip reconfiguration. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2394 | * This means switching to active high polarity and |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2395 | * inverting all fan speed values. |
| 2396 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2397 | int i; |
| 2398 | u8 pwm[3]; |
| 2399 | |
| 2400 | for (i = 0; i < 3; i++) |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2401 | pwm[i] = it87_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2402 | IT87_REG_PWM(i)); |
| 2403 | |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2404 | /* |
| 2405 | * If any fan is in automatic pwm mode, the polarity |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2406 | * might be correct, as suspicious as it seems, so we |
| 2407 | * better don't change anything (but still disable the |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2408 | * PWM interface). |
| 2409 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2410 | if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) { |
Guenter Roeck | 1d9bcf6 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 2411 | dev_info(dev, |
| 2412 | "Reconfiguring PWM to active high polarity\n"); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2413 | it87_write_value(data, IT87_REG_FAN_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2414 | tmp | 0x87); |
| 2415 | for (i = 0; i < 3; i++) |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2416 | it87_write_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | IT87_REG_PWM(i), |
| 2418 | 0x7f & ~pwm[i]); |
| 2419 | return 1; |
| 2420 | } |
| 2421 | |
Guenter Roeck | 1d9bcf6 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 2422 | dev_info(dev, |
| 2423 | "PWM configuration is too broken to be fixed\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | } |
| 2425 | |
Guenter Roeck | 1d9bcf6 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 2426 | dev_info(dev, |
| 2427 | "Detected broken BIOS defaults, disabling PWM interface\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2428 | return 0; |
| 2429 | } else if (fix_pwm_polarity) { |
Guenter Roeck | 1d9bcf6 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 2430 | dev_info(dev, |
| 2431 | "PWM configuration looks sane, won't touch\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2432 | } |
| 2433 | |
| 2434 | return 1; |
| 2435 | } |
| 2436 | |
| 2437 | /* Called when we have found a new IT87. */ |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 2438 | static void it87_init_device(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | { |
Jingoo Han | a8b3a3a | 2013-07-30 17:13:06 +0900 | [diff] [blame] | 2440 | struct it87_sio_data *sio_data = dev_get_platdata(&pdev->dev); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2441 | struct it87_data *data = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | int tmp, i; |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 2443 | u8 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2444 | |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2445 | /* |
| 2446 | * For each PWM channel: |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 2447 | * - If it is in automatic mode, setting to manual mode should set |
| 2448 | * the fan to full speed by default. |
| 2449 | * - If it is in manual mode, we need a mapping to temperature |
| 2450 | * channels to use when later setting to automatic mode later. |
| 2451 | * Use a 1:1 mapping by default (we are clueless.) |
| 2452 | * In both cases, the value can (and should) be changed by the user |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 2453 | * prior to switching to a different mode. |
| 2454 | * Note that this is no longer needed for the IT8721F and later, as |
| 2455 | * these have separate registers for the temperature mapping and the |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2456 | * manual duty cycle. |
| 2457 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2458 | for (i = 0; i < 3; i++) { |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 2459 | data->pwm_temp_map[i] = i; |
| 2460 | data->pwm_duty[i] = 0x7f; /* Full speed */ |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 2461 | data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | } |
| 2463 | |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2464 | /* |
| 2465 | * Some chips seem to have default value 0xff for all limit |
Jean Delvare | c5df9b7 | 2006-08-28 14:37:54 +0200 | [diff] [blame] | 2466 | * registers. For low voltage limits it makes no sense and triggers |
| 2467 | * alarms, so change to 0 instead. For high temperature limits, it |
| 2468 | * means -1 degree C, which surprisingly doesn't trigger an alarm, |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2469 | * but is still confusing, so change to 127 degrees C. |
| 2470 | */ |
Jean Delvare | c5df9b7 | 2006-08-28 14:37:54 +0200 | [diff] [blame] | 2471 | for (i = 0; i < 8; i++) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2472 | tmp = it87_read_value(data, IT87_REG_VIN_MIN(i)); |
Jean Delvare | c5df9b7 | 2006-08-28 14:37:54 +0200 | [diff] [blame] | 2473 | if (tmp == 0xff) |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2474 | it87_write_value(data, IT87_REG_VIN_MIN(i), 0); |
Jean Delvare | c5df9b7 | 2006-08-28 14:37:54 +0200 | [diff] [blame] | 2475 | } |
| 2476 | for (i = 0; i < 3; i++) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2477 | tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i)); |
Jean Delvare | c5df9b7 | 2006-08-28 14:37:54 +0200 | [diff] [blame] | 2478 | if (tmp == 0xff) |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2479 | it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127); |
Jean Delvare | c5df9b7 | 2006-08-28 14:37:54 +0200 | [diff] [blame] | 2480 | } |
| 2481 | |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2482 | /* |
| 2483 | * Temperature channels are not forcibly enabled, as they can be |
Jean Delvare | a00afb9 | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 2484 | * set to two different sensor types and we can't guess which one |
| 2485 | * is correct for a given system. These channels can be enabled at |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2486 | * run-time through the temp{1-3}_type sysfs accessors if needed. |
| 2487 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | |
| 2489 | /* Check if voltage monitors are reset manually or by some reason */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2490 | tmp = it87_read_value(data, IT87_REG_VIN_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2491 | if ((tmp & 0xff) == 0) { |
| 2492 | /* Enable all voltage monitors */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2493 | it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | } |
| 2495 | |
| 2496 | /* Check if tachometers are reset manually or by some reason */ |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 2497 | mask = 0x70 & ~(sio_data->skip_fan << 4); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2498 | data->fan_main_ctrl = it87_read_value(data, IT87_REG_FAN_MAIN_CTRL); |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 2499 | if ((data->fan_main_ctrl & mask) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | /* Enable all fan tachometers */ |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 2501 | data->fan_main_ctrl |= mask; |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2502 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, |
| 2503 | data->fan_main_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2504 | } |
Jean Delvare | 9060f8b | 2006-08-28 14:24:17 +0200 | [diff] [blame] | 2505 | data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 2507 | /* Set tachometers to 16-bit mode if needed */ |
| 2508 | if (has_fan16_config(data)) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2509 | tmp = it87_read_value(data, IT87_REG_FAN_16BIT); |
Jean Delvare | 9060f8b | 2006-08-28 14:24:17 +0200 | [diff] [blame] | 2510 | if (~tmp & 0x07 & data->has_fan) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2511 | dev_dbg(&pdev->dev, |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2512 | "Setting fan1-3 to 16-bit mode\n"); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2513 | it87_write_value(data, IT87_REG_FAN_16BIT, |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2514 | tmp | 0x07); |
| 2515 | } |
Guenter Roeck | 9faf28c | 2015-02-12 07:11:38 -0800 | [diff] [blame] | 2516 | } |
| 2517 | |
| 2518 | /* Check for additional fans */ |
| 2519 | if (has_five_fans(data)) { |
| 2520 | tmp = it87_read_value(data, IT87_REG_FAN_16BIT); |
| 2521 | if (tmp & (1 << 4)) |
| 2522 | data->has_fan |= (1 << 3); /* fan4 enabled */ |
| 2523 | if (tmp & (1 << 5)) |
| 2524 | data->has_fan |= (1 << 4); /* fan5 enabled */ |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2525 | } |
| 2526 | |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 2527 | /* Fan input pins may be used for alternative functions */ |
| 2528 | data->has_fan &= ~sio_data->skip_fan; |
| 2529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2530 | /* Start monitoring */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2531 | it87_write_value(data, IT87_REG_CONFIG, |
Jean Delvare | 41002f8 | 2012-07-12 22:47:37 +0200 | [diff] [blame] | 2532 | (it87_read_value(data, IT87_REG_CONFIG) & 0x3e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | | (update_vbat ? 0x41 : 0x01)); |
| 2534 | } |
| 2535 | |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 2536 | static void it87_update_pwm_ctrl(struct it87_data *data, int nr) |
| 2537 | { |
| 2538 | data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM(nr)); |
Jean Delvare | 16b5dda | 2012-01-16 22:51:48 +0100 | [diff] [blame] | 2539 | if (has_newer_autopwm(data)) { |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 2540 | data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03; |
Jean Delvare | 6229cdb | 2010-12-08 16:27:22 +0100 | [diff] [blame] | 2541 | data->pwm_duty[nr] = it87_read_value(data, |
| 2542 | IT87_REG_PWM_DUTY(nr)); |
| 2543 | } else { |
| 2544 | if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */ |
| 2545 | data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03; |
| 2546 | else /* Manual mode */ |
| 2547 | data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f; |
| 2548 | } |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 2549 | |
| 2550 | if (has_old_autopwm(data)) { |
| 2551 | int i; |
| 2552 | |
| 2553 | for (i = 0; i < 5 ; i++) |
| 2554 | data->auto_temp[nr][i] = it87_read_value(data, |
| 2555 | IT87_REG_AUTO_TEMP(nr, i)); |
| 2556 | for (i = 0; i < 3 ; i++) |
| 2557 | data->auto_pwm[nr][i] = it87_read_value(data, |
| 2558 | IT87_REG_AUTO_PWM(nr, i)); |
| 2559 | } |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 2560 | } |
| 2561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | static struct it87_data *it87_update_device(struct device *dev) |
| 2563 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2564 | struct it87_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | int i; |
| 2566 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 2567 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2568 | |
| 2569 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
| 2570 | || !data->valid) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2571 | if (update_vbat) { |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2572 | /* |
| 2573 | * Cleared after each update, so reenable. Value |
| 2574 | * returned by this read will be previous value |
| 2575 | */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2576 | it87_write_value(data, IT87_REG_CONFIG, |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2577 | it87_read_value(data, IT87_REG_CONFIG) | 0x40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2578 | } |
| 2579 | for (i = 0; i <= 7; i++) { |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 2580 | data->in[i][0] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2581 | it87_read_value(data, IT87_REG_VIN(i)); |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 2582 | data->in[i][1] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2583 | it87_read_value(data, IT87_REG_VIN_MIN(i)); |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 2584 | data->in[i][2] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2585 | it87_read_value(data, IT87_REG_VIN_MAX(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | } |
Jean Delvare | 3543a53 | 2006-08-28 14:27:25 +0200 | [diff] [blame] | 2587 | /* in8 (battery) has no limit registers */ |
Guenter Roeck | 929c6a5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 2588 | data->in[8][0] = it87_read_value(data, IT87_REG_VIN(8)); |
Rudolf Marek | c145d5c | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 2589 | if (data->type == it8603) |
| 2590 | data->in[9][0] = it87_read_value(data, 0x2f); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2591 | |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 2592 | for (i = 0; i < 5; i++) { |
Jean Delvare | 9060f8b | 2006-08-28 14:24:17 +0200 | [diff] [blame] | 2593 | /* Skip disabled fans */ |
| 2594 | if (!(data->has_fan & (1 << i))) |
| 2595 | continue; |
| 2596 | |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 2597 | data->fan[i][1] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2598 | it87_read_value(data, IT87_REG_FAN_MIN[i]); |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 2599 | data->fan[i][0] = it87_read_value(data, |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 2600 | IT87_REG_FAN[i]); |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2601 | /* Add high byte if in 16-bit mode */ |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 2602 | if (has_16bit_fans(data)) { |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 2603 | data->fan[i][0] |= it87_read_value(data, |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 2604 | IT87_REG_FANX[i]) << 8; |
Guenter Roeck | e1169ba | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 2605 | data->fan[i][1] |= it87_read_value(data, |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 2606 | IT87_REG_FANX_MIN[i]) << 8; |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2607 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 | } |
| 2609 | for (i = 0; i < 3; i++) { |
Guenter Roeck | 4573acb | 2012-03-26 16:17:41 -0700 | [diff] [blame] | 2610 | if (!(data->has_temp & (1 << i))) |
| 2611 | continue; |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 2612 | data->temp[i][0] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2613 | it87_read_value(data, IT87_REG_TEMP(i)); |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 2614 | data->temp[i][1] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2615 | it87_read_value(data, IT87_REG_TEMP_LOW(i)); |
Guenter Roeck | 60ca385 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 2616 | data->temp[i][2] = |
| 2617 | it87_read_value(data, IT87_REG_TEMP_HIGH(i)); |
Guenter Roeck | 161d898 | 2012-12-19 22:17:01 +0100 | [diff] [blame] | 2618 | if (has_temp_offset(data)) |
| 2619 | data->temp[i][3] = |
| 2620 | it87_read_value(data, |
| 2621 | IT87_REG_TEMP_OFFSET[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2622 | } |
| 2623 | |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2624 | /* Newer chips don't have clock dividers */ |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 2625 | if ((data->has_fan & 0x07) && !has_16bit_fans(data)) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2626 | i = it87_read_value(data, IT87_REG_FAN_DIV); |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2627 | data->fan_div[0] = i & 0x07; |
| 2628 | data->fan_div[1] = (i >> 3) & 0x07; |
| 2629 | data->fan_div[2] = (i & 0x40) ? 3 : 1; |
| 2630 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | |
| 2632 | data->alarms = |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2633 | it87_read_value(data, IT87_REG_ALARM1) | |
| 2634 | (it87_read_value(data, IT87_REG_ALARM2) << 8) | |
| 2635 | (it87_read_value(data, IT87_REG_ALARM3) << 16); |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2636 | data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE); |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 2637 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2638 | data->fan_main_ctrl = it87_read_value(data, |
| 2639 | IT87_REG_FAN_MAIN_CTRL); |
| 2640 | data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL); |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 2641 | for (i = 0; i < 3; i++) |
| 2642 | it87_update_pwm_ctrl(data, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2643 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2644 | data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); |
Guenter Roeck | 1952978 | 2012-12-19 22:17:02 +0100 | [diff] [blame] | 2645 | data->extra = it87_read_value(data, IT87_REG_TEMP_EXTRA); |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2646 | /* |
| 2647 | * The IT8705F does not have VID capability. |
| 2648 | * The IT8718F and later don't use IT87_REG_VID for the |
| 2649 | * same purpose. |
| 2650 | */ |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2651 | if (data->type == it8712 || data->type == it8716) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2652 | data->vid = it87_read_value(data, IT87_REG_VID); |
Guenter Roeck | 4a0d71c | 2012-01-19 11:02:18 -0800 | [diff] [blame] | 2653 | /* |
| 2654 | * The older IT8712F revisions had only 5 VID pins, |
| 2655 | * but we assume it is always safe to read 6 bits. |
| 2656 | */ |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2657 | data->vid &= 0x3f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2658 | } |
| 2659 | data->last_updated = jiffies; |
| 2660 | data->valid = 1; |
| 2661 | } |
| 2662 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 2663 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | |
| 2665 | return data; |
| 2666 | } |
| 2667 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2668 | static int __init it87_device_add(unsigned short address, |
| 2669 | const struct it87_sio_data *sio_data) |
| 2670 | { |
| 2671 | struct resource res = { |
Bjorn Helgaas | 87b4b66 | 2008-01-22 07:21:03 -0500 | [diff] [blame] | 2672 | .start = address + IT87_EC_OFFSET, |
| 2673 | .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1, |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2674 | .name = DRVNAME, |
| 2675 | .flags = IORESOURCE_IO, |
| 2676 | }; |
| 2677 | int err; |
| 2678 | |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 2679 | err = acpi_check_resource_conflict(&res); |
| 2680 | if (err) |
| 2681 | goto exit; |
| 2682 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2683 | pdev = platform_device_alloc(DRVNAME, address); |
| 2684 | if (!pdev) { |
| 2685 | err = -ENOMEM; |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2686 | pr_err("Device allocation failed\n"); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2687 | goto exit; |
| 2688 | } |
| 2689 | |
| 2690 | err = platform_device_add_resources(pdev, &res, 1); |
| 2691 | if (err) { |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2692 | pr_err("Device resource addition failed (%d)\n", err); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2693 | goto exit_device_put; |
| 2694 | } |
| 2695 | |
| 2696 | err = platform_device_add_data(pdev, sio_data, |
| 2697 | sizeof(struct it87_sio_data)); |
| 2698 | if (err) { |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2699 | pr_err("Platform data allocation failed\n"); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2700 | goto exit_device_put; |
| 2701 | } |
| 2702 | |
| 2703 | err = platform_device_add(pdev); |
| 2704 | if (err) { |
Joe Perches | a8ca103 | 2011-01-12 21:55:10 +0100 | [diff] [blame] | 2705 | pr_err("Device addition failed (%d)\n", err); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2706 | goto exit_device_put; |
| 2707 | } |
| 2708 | |
| 2709 | return 0; |
| 2710 | |
| 2711 | exit_device_put: |
| 2712 | platform_device_put(pdev); |
| 2713 | exit: |
| 2714 | return err; |
| 2715 | } |
| 2716 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2717 | static int __init sm_it87_init(void) |
| 2718 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2719 | int err; |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2720 | unsigned short isa_address = 0; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2721 | struct it87_sio_data sio_data; |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 2722 | |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 2723 | memset(&sio_data, 0, sizeof(struct it87_sio_data)); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2724 | err = it87_find(&isa_address, &sio_data); |
| 2725 | if (err) |
| 2726 | return err; |
| 2727 | err = platform_driver_register(&it87_driver); |
| 2728 | if (err) |
| 2729 | return err; |
| 2730 | |
| 2731 | err = it87_device_add(isa_address, &sio_data); |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2732 | if (err) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2733 | platform_driver_unregister(&it87_driver); |
| 2734 | return err; |
| 2735 | } |
| 2736 | |
| 2737 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | static void __exit sm_it87_exit(void) |
| 2741 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2742 | platform_device_unregister(pdev); |
| 2743 | platform_driver_unregister(&it87_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | } |
| 2745 | |
| 2746 | |
Jean Delvare | 7c81c60 | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 2747 | MODULE_AUTHOR("Chris Gauthron, Jean Delvare <jdelvare@suse.de>"); |
Jean Delvare | 44c1bcd | 2010-10-28 20:31:51 +0200 | [diff] [blame] | 2748 | MODULE_DESCRIPTION("IT8705F/IT871xF/IT872xF hardware monitoring driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | module_param(update_vbat, bool, 0); |
| 2750 | MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); |
| 2751 | module_param(fix_pwm_polarity, bool, 0); |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2752 | MODULE_PARM_DESC(fix_pwm_polarity, |
| 2753 | "Force PWM polarity to active high (DANGEROUS)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2754 | MODULE_LICENSE("GPL"); |
| 2755 | |
| 2756 | module_init(sm_it87_init); |
| 2757 | module_exit(sm_it87_exit); |