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