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