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