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