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