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