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