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