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