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