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 |
| 18 | * IT8726F Super I/O chip w/LPC interface |
| 19 | * Sis950 A clone of the IT8705F |
| 20 | * |
| 21 | * Copyright (C) 2001 Chris Gauthron |
| 22 | * Copyright (C) 2005-2010 Jean Delvare <khali@linux-fr.org> |
| 23 | * |
| 24 | * This program is free software; you can redistribute it and/or modify |
| 25 | * it under the terms of the GNU General Public License as published by |
| 26 | * the Free Software Foundation; either version 2 of the License, or |
| 27 | * (at your option) any later version. |
| 28 | * |
| 29 | * This program is distributed in the hope that it will be useful, |
| 30 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 31 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 32 | * GNU General Public License for more details. |
| 33 | * |
| 34 | * You should have received a copy of the GNU General Public License |
| 35 | * along with this program; if not, write to the Free Software |
| 36 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 37 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/module.h> |
| 40 | #include <linux/init.h> |
| 41 | #include <linux/slab.h> |
| 42 | #include <linux/jiffies.h> |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 43 | #include <linux/platform_device.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 44 | #include <linux/hwmon.h> |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 45 | #include <linux/hwmon-sysfs.h> |
| 46 | #include <linux/hwmon-vid.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 47 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 48 | #include <linux/mutex.h> |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 49 | #include <linux/sysfs.h> |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 50 | #include <linux/string.h> |
| 51 | #include <linux/dmi.h> |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 52 | #include <linux/acpi.h> |
H Hartley Sweeten | 6055fae | 2009-09-15 17:18:13 +0200 | [diff] [blame] | 53 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 55 | #define DRVNAME "it87" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 57 | enum chips { it87, it8712, it8716, it8718, it8720 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 59 | static unsigned short force_id; |
| 60 | module_param(force_id, ushort, 0); |
| 61 | MODULE_PARM_DESC(force_id, "Override the detected device ID"); |
| 62 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 63 | static struct platform_device *pdev; |
| 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #define REG 0x2e /* The register to read/write */ |
| 66 | #define DEV 0x07 /* Register: Logical device select */ |
| 67 | #define VAL 0x2f /* The value to read/write */ |
| 68 | #define PME 0x04 /* The device with the fan registers in it */ |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 69 | |
| 70 | /* The device with the IT8718F/IT8720F VID value in it */ |
| 71 | #define GPIO 0x07 |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #define DEVID 0x20 /* Register: Device ID */ |
| 74 | #define DEVREV 0x22 /* Register: Device Revision */ |
| 75 | |
| 76 | static inline int |
| 77 | superio_inb(int reg) |
| 78 | { |
| 79 | outb(reg, REG); |
| 80 | return inb(VAL); |
| 81 | } |
| 82 | |
Jean Delvare | 436cad2 | 2010-07-09 16:22:48 +0200 | [diff] [blame] | 83 | static inline void |
| 84 | superio_outb(int reg, int val) |
| 85 | { |
| 86 | outb(reg, REG); |
| 87 | outb(val, VAL); |
| 88 | } |
| 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | static int superio_inw(int reg) |
| 91 | { |
| 92 | int val; |
| 93 | outb(reg++, REG); |
| 94 | val = inb(VAL) << 8; |
| 95 | outb(reg, REG); |
| 96 | val |= inb(VAL); |
| 97 | return val; |
| 98 | } |
| 99 | |
| 100 | static inline void |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 101 | superio_select(int ldn) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | { |
| 103 | outb(DEV, REG); |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 104 | outb(ldn, VAL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static inline void |
| 108 | superio_enter(void) |
| 109 | { |
| 110 | outb(0x87, REG); |
| 111 | outb(0x01, REG); |
| 112 | outb(0x55, REG); |
| 113 | outb(0x55, REG); |
| 114 | } |
| 115 | |
| 116 | static inline void |
| 117 | superio_exit(void) |
| 118 | { |
| 119 | outb(0x02, REG); |
| 120 | outb(0x02, VAL); |
| 121 | } |
| 122 | |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 123 | /* Logical device 4 registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | #define IT8712F_DEVID 0x8712 |
| 125 | #define IT8705F_DEVID 0x8705 |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 126 | #define IT8716F_DEVID 0x8716 |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 127 | #define IT8718F_DEVID 0x8718 |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 128 | #define IT8720F_DEVID 0x8720 |
Rudolf Marek | 08a8f6e | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 129 | #define IT8726F_DEVID 0x8726 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | #define IT87_ACT_REG 0x30 |
| 131 | #define IT87_BASE_REG 0x60 |
| 132 | |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 133 | /* Logical device 7 registers (IT8712F and later) */ |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 134 | #define IT87_SIO_GPIO3_REG 0x27 |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 135 | #define IT87_SIO_GPIO5_REG 0x29 |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 136 | #define IT87_SIO_PINX2_REG 0x2c /* Pin selection */ |
| 137 | #define IT87_SIO_VID_REG 0xfc /* VID value */ |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 138 | #define IT87_SIO_BEEP_PIN_REG 0xf6 /* Beep pin mapping */ |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | /* Update battery voltage after every reading if true */ |
| 141 | static int update_vbat; |
| 142 | |
| 143 | /* Not all BIOSes properly configure the PWM registers */ |
| 144 | static int fix_pwm_polarity; |
| 145 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | /* Many IT87 constants specified below */ |
| 147 | |
| 148 | /* Length of ISA address segment */ |
| 149 | #define IT87_EXTENT 8 |
| 150 | |
Bjorn Helgaas | 87b4b66 | 2008-01-22 07:21:03 -0500 | [diff] [blame] | 151 | /* Length of ISA address segment for Environmental Controller */ |
| 152 | #define IT87_EC_EXTENT 2 |
| 153 | |
| 154 | /* Offset of EC registers from ISA base address */ |
| 155 | #define IT87_EC_OFFSET 5 |
| 156 | |
| 157 | /* Where are the ISA address/data registers relative to the EC base address */ |
| 158 | #define IT87_ADDR_REG_OFFSET 0 |
| 159 | #define IT87_DATA_REG_OFFSET 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
| 161 | /*----- The IT87 registers -----*/ |
| 162 | |
| 163 | #define IT87_REG_CONFIG 0x00 |
| 164 | |
| 165 | #define IT87_REG_ALARM1 0x01 |
| 166 | #define IT87_REG_ALARM2 0x02 |
| 167 | #define IT87_REG_ALARM3 0x03 |
| 168 | |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 169 | /* The IT8718F and IT8720F have the VID value in a different register, in |
| 170 | Super-I/O configuration space. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | #define IT87_REG_VID 0x0a |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 172 | /* The IT8705F and IT8712F earlier than revision 0x08 use register 0x0b |
| 173 | for fan divisors. Later IT8712F revisions must use 16-bit tachometer |
| 174 | mode. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | #define IT87_REG_FAN_DIV 0x0b |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 176 | #define IT87_REG_FAN_16BIT 0x0c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
| 178 | /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */ |
| 179 | |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 180 | static const u8 IT87_REG_FAN[] = { 0x0d, 0x0e, 0x0f, 0x80, 0x82 }; |
| 181 | static const u8 IT87_REG_FAN_MIN[] = { 0x10, 0x11, 0x12, 0x84, 0x86 }; |
| 182 | static const u8 IT87_REG_FANX[] = { 0x18, 0x19, 0x1a, 0x81, 0x83 }; |
| 183 | static const u8 IT87_REG_FANX_MIN[] = { 0x1b, 0x1c, 0x1d, 0x85, 0x87 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | #define IT87_REG_FAN_MAIN_CTRL 0x13 |
| 185 | #define IT87_REG_FAN_CTL 0x14 |
| 186 | #define IT87_REG_PWM(nr) (0x15 + (nr)) |
| 187 | |
| 188 | #define IT87_REG_VIN(nr) (0x20 + (nr)) |
| 189 | #define IT87_REG_TEMP(nr) (0x29 + (nr)) |
| 190 | |
| 191 | #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2) |
| 192 | #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2) |
| 193 | #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2) |
| 194 | #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2) |
| 195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | #define IT87_REG_VIN_ENABLE 0x50 |
| 197 | #define IT87_REG_TEMP_ENABLE 0x51 |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 198 | #define IT87_REG_BEEP_ENABLE 0x5c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | #define IT87_REG_CHIPID 0x58 |
| 201 | |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 202 | #define IT87_REG_AUTO_TEMP(nr, i) (0x60 + (nr) * 8 + (i)) |
| 203 | #define IT87_REG_AUTO_PWM(nr, i) (0x65 + (nr) * 8 + (i)) |
| 204 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255)) |
| 206 | #define IN_FROM_REG(val) ((val) * 16) |
| 207 | |
| 208 | static inline u8 FAN_TO_REG(long rpm, int div) |
| 209 | { |
| 210 | if (rpm == 0) |
| 211 | return 255; |
| 212 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); |
| 213 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, |
| 214 | 254); |
| 215 | } |
| 216 | |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 217 | static inline u16 FAN16_TO_REG(long rpm) |
| 218 | { |
| 219 | if (rpm == 0) |
| 220 | return 0xffff; |
| 221 | return SENSORS_LIMIT((1350000 + rpm) / (rpm * 2), 1, 0xfffe); |
| 222 | } |
| 223 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 225 | /* The divider is fixed to 2 in 16-bit mode */ |
| 226 | #define FAN16_FROM_REG(val) ((val)==0?-1:(val)==0xffff?0:1350000/((val)*2)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
| 228 | #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\ |
| 229 | ((val)+500)/1000),-128,127)) |
Jean Delvare | e267d25 | 2009-03-12 13:36:39 +0100 | [diff] [blame] | 230 | #define TEMP_FROM_REG(val) ((val) * 1000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | #define PWM_TO_REG(val) ((val) >> 1) |
| 233 | #define PWM_FROM_REG(val) (((val)&0x7f) << 1) |
| 234 | |
| 235 | static int DIV_TO_REG(int val) |
| 236 | { |
| 237 | int answer = 0; |
Jean Delvare | b9e349f | 2006-08-28 14:26:22 +0200 | [diff] [blame] | 238 | while (answer < 7 && (val >>= 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | answer++; |
| 240 | return answer; |
| 241 | } |
| 242 | #define DIV_FROM_REG(val) (1 << (val)) |
| 243 | |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 244 | static const unsigned int pwm_freq[8] = { |
| 245 | 48000000 / 128, |
| 246 | 24000000 / 128, |
| 247 | 12000000 / 128, |
| 248 | 8000000 / 128, |
| 249 | 6000000 / 128, |
| 250 | 3000000 / 128, |
| 251 | 1500000 / 128, |
| 252 | 750000 / 128, |
| 253 | }; |
| 254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 256 | struct it87_sio_data { |
| 257 | enum chips type; |
| 258 | /* Values read from Super-I/O config space */ |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 259 | u8 revision; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 260 | u8 vid_value; |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 261 | u8 beep_pin; |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 262 | u8 internal; /* Internal sensors can be labeled */ |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 263 | /* Features skipped based on config or DMI */ |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 264 | u8 skip_vid; |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 265 | u8 skip_fan; |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 266 | u8 skip_pwm; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 267 | }; |
| 268 | |
Jean Delvare | ed6bafb | 2007-02-14 21:15:03 +0100 | [diff] [blame] | 269 | /* For each registered chip, we need to keep some data in memory. |
| 270 | The structure is dynamically allocated. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | struct it87_data { |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 272 | struct device *hwmon_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | enum chips type; |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 274 | u8 revision; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 276 | unsigned short addr; |
| 277 | const char *name; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 278 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | char valid; /* !=0 if following fields are valid */ |
| 280 | unsigned long last_updated; /* In jiffies */ |
| 281 | |
| 282 | u8 in[9]; /* Register value */ |
Jean Delvare | 3543a53 | 2006-08-28 14:27:25 +0200 | [diff] [blame] | 283 | u8 in_max[8]; /* Register value */ |
| 284 | u8 in_min[8]; /* Register value */ |
Jean Delvare | 9060f8b | 2006-08-28 14:24:17 +0200 | [diff] [blame] | 285 | u8 has_fan; /* Bitfield, fans enabled */ |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 286 | u16 fan[5]; /* Register values, possibly combined */ |
| 287 | u16 fan_min[5]; /* Register values, possibly combined */ |
Jean Delvare | e267d25 | 2009-03-12 13:36:39 +0100 | [diff] [blame] | 288 | s8 temp[3]; /* Register value */ |
| 289 | s8 temp_high[3]; /* Register value */ |
| 290 | s8 temp_low[3]; /* Register value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | u8 sensor; /* Register value */ |
| 292 | u8 fan_div[3]; /* Register encoding, shifted right */ |
| 293 | u8 vid; /* Register encoding, combined */ |
Jean Delvare | a7be58a | 2005-12-18 16:40:14 +0100 | [diff] [blame] | 294 | u8 vrm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | u32 alarms; /* Register encoding, combined */ |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 296 | u8 beeps; /* Register encoding */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | u8 fan_main_ctrl; /* Register value */ |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 298 | u8 fan_ctl; /* Register value */ |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 299 | |
| 300 | /* The following 3 arrays correspond to the same registers. The |
| 301 | * meaning of bits 6-0 depends on the value of bit 7, and we want |
| 302 | * to preserve settings on mode changes, so we have to track all |
| 303 | * values separately. */ |
| 304 | u8 pwm_ctrl[3]; /* Register value */ |
| 305 | u8 pwm_duty[3]; /* Manual PWM value set by user (bit 6-0) */ |
| 306 | 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] | 307 | |
| 308 | /* Automatic fan speed control registers */ |
| 309 | u8 auto_pwm[3][4]; /* [nr][3] is hard-coded */ |
| 310 | s8 auto_temp[3][5]; /* [nr][0] is point1_temp_hyst */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | }; |
| 312 | |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 313 | static inline int has_16bit_fans(const struct it87_data *data) |
| 314 | { |
Andrew Paprocki | 816d8c6 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 315 | /* IT8705F Datasheet 0.4.1, 3h == Version G. |
Andrew Paprocki | 859b9ef | 2008-09-20 10:25:19 +0200 | [diff] [blame] | 316 | IT8712F Datasheet 0.9.1, section 8.3.5 indicates 8h == Version J. |
Andrew Paprocki | 816d8c6 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 317 | These are the first revisions with 16bit tachometer support. */ |
| 318 | return (data->type == it87 && data->revision >= 0x03) |
Andrew Paprocki | 859b9ef | 2008-09-20 10:25:19 +0200 | [diff] [blame] | 319 | || (data->type == it8712 && data->revision >= 0x08) |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 320 | || data->type == it8716 |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 321 | || data->type == it8718 |
| 322 | || data->type == it8720; |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 323 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 325 | static inline int has_old_autopwm(const struct it87_data *data) |
| 326 | { |
| 327 | /* The old automatic fan speed control interface is implemented |
| 328 | by IT8705F chips up to revision F and IT8712F chips up to |
| 329 | revision G. */ |
| 330 | return (data->type == it87 && data->revision < 0x03) |
| 331 | || (data->type == it8712 && data->revision < 0x08); |
| 332 | } |
| 333 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 334 | static int it87_probe(struct platform_device *pdev); |
Jean Delvare | d054612 | 2007-07-22 12:09:48 +0200 | [diff] [blame] | 335 | static int __devexit it87_remove(struct platform_device *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 337 | static int it87_read_value(struct it87_data *data, u8 reg); |
| 338 | 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] | 339 | static struct it87_data *it87_update_device(struct device *dev); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 340 | static int it87_check_pwm(struct device *dev); |
| 341 | static void it87_init_device(struct platform_device *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 344 | static struct platform_driver it87_driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 345 | .driver = { |
Jean Delvare | 8721884 | 2006-09-03 22:36:14 +0200 | [diff] [blame] | 346 | .owner = THIS_MODULE, |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 347 | .name = DRVNAME, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 348 | }, |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 349 | .probe = it87_probe, |
| 350 | .remove = __devexit_p(it87_remove), |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 351 | }; |
| 352 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 353 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, |
| 354 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 356 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 357 | int nr = sensor_attr->index; |
| 358 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | struct it87_data *data = it87_update_device(dev); |
| 360 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); |
| 361 | } |
| 362 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 363 | static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, |
| 364 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 366 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 367 | int nr = sensor_attr->index; |
| 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | struct it87_data *data = it87_update_device(dev); |
| 370 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); |
| 371 | } |
| 372 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 373 | static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, |
| 374 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 376 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 377 | int nr = sensor_attr->index; |
| 378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | struct it87_data *data = it87_update_device(dev); |
| 380 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); |
| 381 | } |
| 382 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 383 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, |
| 384 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 386 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 387 | int nr = sensor_attr->index; |
| 388 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 389 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 390 | unsigned long val; |
| 391 | |
| 392 | if (strict_strtoul(buf, 10, &val) < 0) |
| 393 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 395 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | data->in_min[nr] = IN_TO_REG(val); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 397 | it87_write_value(data, IT87_REG_VIN_MIN(nr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | data->in_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 399 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | return count; |
| 401 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 402 | static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, |
| 403 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 405 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 406 | int nr = sensor_attr->index; |
| 407 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 408 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 409 | unsigned long val; |
| 410 | |
| 411 | if (strict_strtoul(buf, 10, &val) < 0) |
| 412 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 414 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | data->in_max[nr] = IN_TO_REG(val); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 416 | it87_write_value(data, IT87_REG_VIN_MAX(nr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | data->in_max[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 418 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | return count; |
| 420 | } |
| 421 | |
| 422 | #define show_in_offset(offset) \ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 423 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
| 424 | show_in, NULL, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
| 426 | #define limit_in_offset(offset) \ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 427 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ |
| 428 | show_in_min, set_in_min, offset); \ |
| 429 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ |
| 430 | show_in_max, set_in_max, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
| 432 | show_in_offset(0); |
| 433 | limit_in_offset(0); |
| 434 | show_in_offset(1); |
| 435 | limit_in_offset(1); |
| 436 | show_in_offset(2); |
| 437 | limit_in_offset(2); |
| 438 | show_in_offset(3); |
| 439 | limit_in_offset(3); |
| 440 | show_in_offset(4); |
| 441 | limit_in_offset(4); |
| 442 | show_in_offset(5); |
| 443 | limit_in_offset(5); |
| 444 | show_in_offset(6); |
| 445 | limit_in_offset(6); |
| 446 | show_in_offset(7); |
| 447 | limit_in_offset(7); |
| 448 | show_in_offset(8); |
| 449 | |
| 450 | /* 3 temperatures */ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 451 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, |
| 452 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 454 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 455 | int nr = sensor_attr->index; |
| 456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | struct it87_data *data = it87_update_device(dev); |
| 458 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr])); |
| 459 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 460 | static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, |
| 461 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 463 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 464 | int nr = sensor_attr->index; |
| 465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | struct it87_data *data = it87_update_device(dev); |
| 467 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr])); |
| 468 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 469 | static ssize_t show_temp_min(struct device *dev, struct device_attribute *attr, |
| 470 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 472 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 473 | int nr = sensor_attr->index; |
| 474 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | struct it87_data *data = it87_update_device(dev); |
| 476 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_low[nr])); |
| 477 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 478 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
| 479 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 481 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 482 | int nr = sensor_attr->index; |
| 483 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 484 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 485 | long val; |
| 486 | |
| 487 | if (strict_strtol(buf, 10, &val) < 0) |
| 488 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 490 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | data->temp_high[nr] = TEMP_TO_REG(val); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 492 | it87_write_value(data, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 493 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | return count; |
| 495 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 496 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, |
| 497 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 499 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 500 | int nr = sensor_attr->index; |
| 501 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 502 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 503 | long val; |
| 504 | |
| 505 | if (strict_strtol(buf, 10, &val) < 0) |
| 506 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 508 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | data->temp_low[nr] = TEMP_TO_REG(val); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 510 | it87_write_value(data, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 511 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | return count; |
| 513 | } |
| 514 | #define show_temp_offset(offset) \ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 515 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
| 516 | show_temp, NULL, offset - 1); \ |
| 517 | static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ |
| 518 | show_temp_max, set_temp_max, offset - 1); \ |
| 519 | static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ |
| 520 | show_temp_min, set_temp_min, offset - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
| 522 | show_temp_offset(1); |
| 523 | show_temp_offset(2); |
| 524 | show_temp_offset(3); |
| 525 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 526 | static ssize_t show_sensor(struct device *dev, struct device_attribute *attr, |
| 527 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 529 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 530 | int nr = sensor_attr->index; |
| 531 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 533 | u8 reg = data->sensor; /* In case the value is updated while |
| 534 | we use it */ |
| 535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | if (reg & (1 << nr)) |
| 537 | return sprintf(buf, "3\n"); /* thermal diode */ |
| 538 | if (reg & (8 << nr)) |
Jean Delvare | 4ed1077 | 2008-10-17 17:51:16 +0200 | [diff] [blame] | 539 | return sprintf(buf, "4\n"); /* thermistor */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | return sprintf(buf, "0\n"); /* disabled */ |
| 541 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 542 | static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, |
| 543 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 545 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 546 | int nr = sensor_attr->index; |
| 547 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 548 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 549 | long val; |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 550 | u8 reg; |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 551 | |
| 552 | if (strict_strtol(buf, 10, &val) < 0) |
| 553 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 555 | reg = it87_read_value(data, IT87_REG_TEMP_ENABLE); |
| 556 | reg &= ~(1 << nr); |
| 557 | reg &= ~(8 << nr); |
Jean Delvare | 4ed1077 | 2008-10-17 17:51:16 +0200 | [diff] [blame] | 558 | if (val == 2) { /* backwards compatibility */ |
| 559 | dev_warn(dev, "Sensor type 2 is deprecated, please use 4 " |
| 560 | "instead\n"); |
| 561 | val = 4; |
| 562 | } |
| 563 | /* 3 = thermal diode; 4 = thermistor; 0 = disabled */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | if (val == 3) |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 565 | reg |= 1 << nr; |
Jean Delvare | 4ed1077 | 2008-10-17 17:51:16 +0200 | [diff] [blame] | 566 | else if (val == 4) |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 567 | reg |= 8 << nr; |
| 568 | else if (val != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | return -EINVAL; |
Jean Delvare | 8acf07c | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 570 | |
| 571 | mutex_lock(&data->update_lock); |
| 572 | data->sensor = reg; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 573 | it87_write_value(data, IT87_REG_TEMP_ENABLE, data->sensor); |
Jean Delvare | 2b3d1d8 | 2010-04-14 16:14:10 +0200 | [diff] [blame] | 574 | data->valid = 0; /* Force cache refresh */ |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 575 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | return count; |
| 577 | } |
| 578 | #define show_sensor_offset(offset) \ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 579 | static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \ |
| 580 | show_sensor, set_sensor, offset - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
| 582 | show_sensor_offset(1); |
| 583 | show_sensor_offset(2); |
| 584 | show_sensor_offset(3); |
| 585 | |
| 586 | /* 3 Fans */ |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 587 | |
| 588 | static int pwm_mode(const struct it87_data *data, int nr) |
| 589 | { |
| 590 | int ctrl = data->fan_main_ctrl & (1 << nr); |
| 591 | |
| 592 | if (ctrl == 0) /* Full speed */ |
| 593 | return 0; |
| 594 | if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */ |
| 595 | return 2; |
| 596 | else /* Manual mode */ |
| 597 | return 1; |
| 598 | } |
| 599 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 600 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, |
| 601 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 603 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 604 | int nr = sensor_attr->index; |
| 605 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 607 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan[nr], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | DIV_FROM_REG(data->fan_div[nr]))); |
| 609 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 610 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, |
| 611 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 613 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 614 | int nr = sensor_attr->index; |
| 615 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 617 | return sprintf(buf, "%d\n", FAN_FROM_REG(data->fan_min[nr], |
| 618 | DIV_FROM_REG(data->fan_div[nr]))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 620 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, |
| 621 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 623 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 624 | int nr = sensor_attr->index; |
| 625 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | struct it87_data *data = it87_update_device(dev); |
| 627 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); |
| 628 | } |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 629 | static ssize_t show_pwm_enable(struct device *dev, |
| 630 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 632 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 633 | int nr = sensor_attr->index; |
| 634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 636 | return sprintf(buf, "%d\n", pwm_mode(data, nr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 638 | static ssize_t show_pwm(struct device *dev, struct device_attribute *attr, |
| 639 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 641 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 642 | int nr = sensor_attr->index; |
| 643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 645 | return sprintf(buf, "%d\n", PWM_FROM_REG(data->pwm_duty[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | } |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 647 | static ssize_t show_pwm_freq(struct device *dev, struct device_attribute *attr, |
| 648 | char *buf) |
| 649 | { |
| 650 | struct it87_data *data = it87_update_device(dev); |
| 651 | int index = (data->fan_ctl >> 4) & 0x07; |
| 652 | |
| 653 | return sprintf(buf, "%u\n", pwm_freq[index]); |
| 654 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 655 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
| 656 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 658 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 659 | int nr = sensor_attr->index; |
| 660 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 661 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 662 | long val; |
Jean Delvare | 7f999aa | 2007-02-14 21:15:03 +0100 | [diff] [blame] | 663 | u8 reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 665 | if (strict_strtol(buf, 10, &val) < 0) |
| 666 | return -EINVAL; |
| 667 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 668 | mutex_lock(&data->update_lock); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 669 | reg = it87_read_value(data, IT87_REG_FAN_DIV); |
Jean Delvare | 07eab46 | 2005-11-23 15:44:31 -0800 | [diff] [blame] | 670 | switch (nr) { |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 671 | case 0: |
| 672 | data->fan_div[nr] = reg & 0x07; |
| 673 | break; |
| 674 | case 1: |
| 675 | data->fan_div[nr] = (reg >> 3) & 0x07; |
| 676 | break; |
| 677 | case 2: |
| 678 | data->fan_div[nr] = (reg & 0x40) ? 3 : 1; |
| 679 | break; |
Jean Delvare | 07eab46 | 2005-11-23 15:44:31 -0800 | [diff] [blame] | 680 | } |
| 681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 683 | it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 684 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | return count; |
| 686 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 687 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
| 688 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 690 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 691 | int nr = sensor_attr->index; |
| 692 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 693 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 694 | unsigned long val; |
Jean Delvare | 8ab4ec3 | 2006-08-28 14:35:46 +0200 | [diff] [blame] | 695 | int min; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | u8 old; |
| 697 | |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 698 | if (strict_strtoul(buf, 10, &val) < 0) |
| 699 | return -EINVAL; |
| 700 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 701 | mutex_lock(&data->update_lock); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 702 | old = it87_read_value(data, IT87_REG_FAN_DIV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | |
Jean Delvare | 8ab4ec3 | 2006-08-28 14:35:46 +0200 | [diff] [blame] | 704 | /* Save fan min limit */ |
| 705 | min = FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | |
| 707 | switch (nr) { |
| 708 | case 0: |
| 709 | case 1: |
| 710 | data->fan_div[nr] = DIV_TO_REG(val); |
| 711 | break; |
| 712 | case 2: |
| 713 | if (val < 8) |
| 714 | data->fan_div[nr] = 1; |
| 715 | else |
| 716 | data->fan_div[nr] = 3; |
| 717 | } |
| 718 | val = old & 0x80; |
| 719 | val |= (data->fan_div[0] & 0x07); |
| 720 | val |= (data->fan_div[1] & 0x07) << 3; |
| 721 | if (data->fan_div[2] == 3) |
| 722 | val |= 0x1 << 6; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 723 | it87_write_value(data, IT87_REG_FAN_DIV, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | |
Jean Delvare | 8ab4ec3 | 2006-08-28 14:35:46 +0200 | [diff] [blame] | 725 | /* Restore fan min limit */ |
| 726 | data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 727 | it87_write_value(data, IT87_REG_FAN_MIN[nr], data->fan_min[nr]); |
Jean Delvare | 8ab4ec3 | 2006-08-28 14:35:46 +0200 | [diff] [blame] | 728 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 729 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | return count; |
| 731 | } |
Jean Delvare | cccfc9c | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 732 | |
| 733 | /* Returns 0 if OK, -EINVAL otherwise */ |
| 734 | static int check_trip_points(struct device *dev, int nr) |
| 735 | { |
| 736 | const struct it87_data *data = dev_get_drvdata(dev); |
| 737 | int i, err = 0; |
| 738 | |
| 739 | if (has_old_autopwm(data)) { |
| 740 | for (i = 0; i < 3; i++) { |
| 741 | if (data->auto_temp[nr][i] > data->auto_temp[nr][i + 1]) |
| 742 | err = -EINVAL; |
| 743 | } |
| 744 | for (i = 0; i < 2; i++) { |
| 745 | if (data->auto_pwm[nr][i] > data->auto_pwm[nr][i + 1]) |
| 746 | err = -EINVAL; |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | if (err) { |
| 751 | dev_err(dev, "Inconsistent trip points, not switching to " |
| 752 | "automatic mode\n"); |
| 753 | dev_err(dev, "Adjust the trip points and try again\n"); |
| 754 | } |
| 755 | return err; |
| 756 | } |
| 757 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 758 | static ssize_t set_pwm_enable(struct device *dev, |
| 759 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 761 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 762 | int nr = sensor_attr->index; |
| 763 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 764 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 765 | long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 767 | if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 2) |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 768 | return -EINVAL; |
| 769 | |
Jean Delvare | cccfc9c | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 770 | /* Check trip points before switching to automatic mode */ |
| 771 | if (val == 2) { |
| 772 | if (check_trip_points(dev, nr) < 0) |
| 773 | return -EINVAL; |
| 774 | } |
| 775 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 776 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
| 778 | if (val == 0) { |
| 779 | int tmp; |
| 780 | /* make sure the fan is on when in on/off mode */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 781 | tmp = it87_read_value(data, IT87_REG_FAN_CTL); |
| 782 | it87_write_value(data, IT87_REG_FAN_CTL, tmp | (1 << nr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | /* set on/off mode */ |
| 784 | data->fan_main_ctrl &= ~(1 << nr); |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 785 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, |
| 786 | data->fan_main_ctrl); |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 787 | } else { |
| 788 | if (val == 1) /* Manual mode */ |
| 789 | data->pwm_ctrl[nr] = data->pwm_duty[nr]; |
| 790 | else /* Automatic mode */ |
| 791 | data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr]; |
| 792 | it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | /* set SmartGuardian mode */ |
| 794 | data->fan_main_ctrl |= (1 << nr); |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 795 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, |
| 796 | data->fan_main_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | } |
| 798 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 799 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | return count; |
| 801 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 802 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, |
| 803 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 805 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 806 | int nr = sensor_attr->index; |
| 807 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 808 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 809 | long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 811 | if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | return -EINVAL; |
| 813 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 814 | mutex_lock(&data->update_lock); |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 815 | data->pwm_duty[nr] = PWM_TO_REG(val); |
| 816 | /* If we are in manual mode, write the duty cycle immediately; |
| 817 | * otherwise, just store it for later use. */ |
| 818 | if (!(data->pwm_ctrl[nr] & 0x80)) { |
| 819 | data->pwm_ctrl[nr] = data->pwm_duty[nr]; |
| 820 | it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]); |
| 821 | } |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 822 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | return count; |
| 824 | } |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 825 | static ssize_t set_pwm_freq(struct device *dev, |
| 826 | struct device_attribute *attr, const char *buf, size_t count) |
| 827 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 828 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 829 | unsigned long val; |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 830 | int i; |
| 831 | |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 832 | if (strict_strtoul(buf, 10, &val) < 0) |
| 833 | return -EINVAL; |
| 834 | |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 835 | /* Search for the nearest available frequency */ |
| 836 | for (i = 0; i < 7; i++) { |
| 837 | if (val > (pwm_freq[i] + pwm_freq[i+1]) / 2) |
| 838 | break; |
| 839 | } |
| 840 | |
| 841 | mutex_lock(&data->update_lock); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 842 | data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL) & 0x8f; |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 843 | data->fan_ctl |= i << 4; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 844 | it87_write_value(data, IT87_REG_FAN_CTL, data->fan_ctl); |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 845 | mutex_unlock(&data->update_lock); |
| 846 | |
| 847 | return count; |
| 848 | } |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 849 | static ssize_t show_pwm_temp_map(struct device *dev, |
| 850 | struct device_attribute *attr, char *buf) |
| 851 | { |
| 852 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 853 | int nr = sensor_attr->index; |
| 854 | |
| 855 | struct it87_data *data = it87_update_device(dev); |
| 856 | int map; |
| 857 | |
| 858 | if (data->pwm_temp_map[nr] < 3) |
| 859 | map = 1 << data->pwm_temp_map[nr]; |
| 860 | else |
| 861 | map = 0; /* Should never happen */ |
| 862 | return sprintf(buf, "%d\n", map); |
| 863 | } |
| 864 | static ssize_t set_pwm_temp_map(struct device *dev, |
| 865 | struct device_attribute *attr, const char *buf, size_t count) |
| 866 | { |
| 867 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 868 | int nr = sensor_attr->index; |
| 869 | |
| 870 | struct it87_data *data = dev_get_drvdata(dev); |
| 871 | long val; |
| 872 | u8 reg; |
| 873 | |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 874 | /* This check can go away if we ever support automatic fan speed |
| 875 | control on newer chips. */ |
| 876 | if (!has_old_autopwm(data)) { |
| 877 | dev_notice(dev, "Mapping change disabled for safety reasons\n"); |
| 878 | return -EINVAL; |
| 879 | } |
| 880 | |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 881 | if (strict_strtol(buf, 10, &val) < 0) |
| 882 | return -EINVAL; |
| 883 | |
| 884 | switch (val) { |
| 885 | case (1 << 0): |
| 886 | reg = 0x00; |
| 887 | break; |
| 888 | case (1 << 1): |
| 889 | reg = 0x01; |
| 890 | break; |
| 891 | case (1 << 2): |
| 892 | reg = 0x02; |
| 893 | break; |
| 894 | default: |
| 895 | return -EINVAL; |
| 896 | } |
| 897 | |
| 898 | mutex_lock(&data->update_lock); |
| 899 | data->pwm_temp_map[nr] = reg; |
| 900 | /* If we are in automatic mode, write the temp mapping immediately; |
| 901 | * otherwise, just store it for later use. */ |
| 902 | if (data->pwm_ctrl[nr] & 0x80) { |
| 903 | data->pwm_ctrl[nr] = 0x80 | data->pwm_temp_map[nr]; |
| 904 | it87_write_value(data, IT87_REG_PWM(nr), data->pwm_ctrl[nr]); |
| 905 | } |
| 906 | mutex_unlock(&data->update_lock); |
| 907 | return count; |
| 908 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 910 | static ssize_t show_auto_pwm(struct device *dev, |
| 911 | struct device_attribute *attr, char *buf) |
| 912 | { |
| 913 | struct it87_data *data = it87_update_device(dev); |
| 914 | struct sensor_device_attribute_2 *sensor_attr = |
| 915 | to_sensor_dev_attr_2(attr); |
| 916 | int nr = sensor_attr->nr; |
| 917 | int point = sensor_attr->index; |
| 918 | |
| 919 | return sprintf(buf, "%d\n", PWM_FROM_REG(data->auto_pwm[nr][point])); |
| 920 | } |
| 921 | |
| 922 | static ssize_t set_auto_pwm(struct device *dev, |
| 923 | struct device_attribute *attr, const char *buf, size_t count) |
| 924 | { |
| 925 | struct it87_data *data = dev_get_drvdata(dev); |
| 926 | struct sensor_device_attribute_2 *sensor_attr = |
| 927 | to_sensor_dev_attr_2(attr); |
| 928 | int nr = sensor_attr->nr; |
| 929 | int point = sensor_attr->index; |
| 930 | long val; |
| 931 | |
| 932 | if (strict_strtol(buf, 10, &val) < 0 || val < 0 || val > 255) |
| 933 | return -EINVAL; |
| 934 | |
| 935 | mutex_lock(&data->update_lock); |
| 936 | data->auto_pwm[nr][point] = PWM_TO_REG(val); |
| 937 | it87_write_value(data, IT87_REG_AUTO_PWM(nr, point), |
| 938 | data->auto_pwm[nr][point]); |
| 939 | mutex_unlock(&data->update_lock); |
| 940 | return count; |
| 941 | } |
| 942 | |
| 943 | static ssize_t show_auto_temp(struct device *dev, |
| 944 | struct device_attribute *attr, char *buf) |
| 945 | { |
| 946 | struct it87_data *data = it87_update_device(dev); |
| 947 | struct sensor_device_attribute_2 *sensor_attr = |
| 948 | to_sensor_dev_attr_2(attr); |
| 949 | int nr = sensor_attr->nr; |
| 950 | int point = sensor_attr->index; |
| 951 | |
| 952 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->auto_temp[nr][point])); |
| 953 | } |
| 954 | |
| 955 | static ssize_t set_auto_temp(struct device *dev, |
| 956 | struct device_attribute *attr, const char *buf, size_t count) |
| 957 | { |
| 958 | struct it87_data *data = dev_get_drvdata(dev); |
| 959 | struct sensor_device_attribute_2 *sensor_attr = |
| 960 | to_sensor_dev_attr_2(attr); |
| 961 | int nr = sensor_attr->nr; |
| 962 | int point = sensor_attr->index; |
| 963 | long val; |
| 964 | |
| 965 | if (strict_strtol(buf, 10, &val) < 0 || val < -128000 || val > 127000) |
| 966 | return -EINVAL; |
| 967 | |
| 968 | mutex_lock(&data->update_lock); |
| 969 | data->auto_temp[nr][point] = TEMP_TO_REG(val); |
| 970 | it87_write_value(data, IT87_REG_AUTO_TEMP(nr, point), |
| 971 | data->auto_temp[nr][point]); |
| 972 | mutex_unlock(&data->update_lock); |
| 973 | return count; |
| 974 | } |
| 975 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 976 | #define show_fan_offset(offset) \ |
| 977 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
| 978 | show_fan, NULL, offset - 1); \ |
| 979 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
| 980 | show_fan_min, set_fan_min, offset - 1); \ |
| 981 | static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ |
| 982 | show_fan_div, set_fan_div, offset - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
| 984 | show_fan_offset(1); |
| 985 | show_fan_offset(2); |
| 986 | show_fan_offset(3); |
| 987 | |
| 988 | #define show_pwm_offset(offset) \ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 989 | static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ |
| 990 | show_pwm_enable, set_pwm_enable, offset - 1); \ |
| 991 | static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ |
Jean Delvare | f8d0c19 | 2007-02-14 21:15:02 +0100 | [diff] [blame] | 992 | show_pwm, set_pwm, offset - 1); \ |
| 993 | static DEVICE_ATTR(pwm##offset##_freq, \ |
| 994 | (offset == 1 ? S_IRUGO | S_IWUSR : S_IRUGO), \ |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 995 | show_pwm_freq, (offset == 1 ? set_pwm_freq : NULL)); \ |
| 996 | static SENSOR_DEVICE_ATTR(pwm##offset##_auto_channels_temp, \ |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 997 | S_IRUGO | S_IWUSR, show_pwm_temp_map, set_pwm_temp_map, \ |
| 998 | offset - 1); \ |
| 999 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_pwm, \ |
| 1000 | S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \ |
| 1001 | offset - 1, 0); \ |
| 1002 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_pwm, \ |
| 1003 | S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \ |
| 1004 | offset - 1, 1); \ |
| 1005 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_pwm, \ |
| 1006 | S_IRUGO | S_IWUSR, show_auto_pwm, set_auto_pwm, \ |
| 1007 | offset - 1, 2); \ |
| 1008 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_pwm, \ |
| 1009 | S_IRUGO, show_auto_pwm, NULL, offset - 1, 3); \ |
| 1010 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp, \ |
| 1011 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ |
| 1012 | offset - 1, 1); \ |
| 1013 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point1_temp_hyst, \ |
| 1014 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ |
| 1015 | offset - 1, 0); \ |
| 1016 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point2_temp, \ |
| 1017 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ |
| 1018 | offset - 1, 2); \ |
| 1019 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point3_temp, \ |
| 1020 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ |
| 1021 | offset - 1, 3); \ |
| 1022 | static SENSOR_DEVICE_ATTR_2(pwm##offset##_auto_point4_temp, \ |
| 1023 | S_IRUGO | S_IWUSR, show_auto_temp, set_auto_temp, \ |
| 1024 | offset - 1, 4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | |
| 1026 | show_pwm_offset(1); |
| 1027 | show_pwm_offset(2); |
| 1028 | show_pwm_offset(3); |
| 1029 | |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 1030 | /* A different set of callbacks for 16-bit fans */ |
| 1031 | static ssize_t show_fan16(struct device *dev, struct device_attribute *attr, |
| 1032 | char *buf) |
| 1033 | { |
| 1034 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1035 | int nr = sensor_attr->index; |
| 1036 | struct it87_data *data = it87_update_device(dev); |
| 1037 | return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan[nr])); |
| 1038 | } |
| 1039 | |
| 1040 | static ssize_t show_fan16_min(struct device *dev, struct device_attribute *attr, |
| 1041 | char *buf) |
| 1042 | { |
| 1043 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1044 | int nr = sensor_attr->index; |
| 1045 | struct it87_data *data = it87_update_device(dev); |
| 1046 | return sprintf(buf, "%d\n", FAN16_FROM_REG(data->fan_min[nr])); |
| 1047 | } |
| 1048 | |
| 1049 | static ssize_t set_fan16_min(struct device *dev, struct device_attribute *attr, |
| 1050 | const char *buf, size_t count) |
| 1051 | { |
| 1052 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1053 | int nr = sensor_attr->index; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1054 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1055 | long val; |
| 1056 | |
| 1057 | if (strict_strtol(buf, 10, &val) < 0) |
| 1058 | return -EINVAL; |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 1059 | |
| 1060 | mutex_lock(&data->update_lock); |
| 1061 | data->fan_min[nr] = FAN16_TO_REG(val); |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 1062 | it87_write_value(data, IT87_REG_FAN_MIN[nr], |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 1063 | data->fan_min[nr] & 0xff); |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 1064 | it87_write_value(data, IT87_REG_FANX_MIN[nr], |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 1065 | data->fan_min[nr] >> 8); |
| 1066 | mutex_unlock(&data->update_lock); |
| 1067 | return count; |
| 1068 | } |
| 1069 | |
| 1070 | /* We want to use the same sysfs file names as 8-bit fans, but we need |
| 1071 | different variable names, so we have to use SENSOR_ATTR instead of |
| 1072 | SENSOR_DEVICE_ATTR. */ |
| 1073 | #define show_fan16_offset(offset) \ |
| 1074 | static struct sensor_device_attribute sensor_dev_attr_fan##offset##_input16 \ |
| 1075 | = SENSOR_ATTR(fan##offset##_input, S_IRUGO, \ |
| 1076 | show_fan16, NULL, offset - 1); \ |
| 1077 | static struct sensor_device_attribute sensor_dev_attr_fan##offset##_min16 \ |
| 1078 | = SENSOR_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
| 1079 | show_fan16_min, set_fan16_min, offset - 1) |
| 1080 | |
| 1081 | show_fan16_offset(1); |
| 1082 | show_fan16_offset(2); |
| 1083 | show_fan16_offset(3); |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 1084 | show_fan16_offset(4); |
| 1085 | show_fan16_offset(5); |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 1086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | /* Alarms */ |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1088 | static ssize_t show_alarms(struct device *dev, struct device_attribute *attr, |
| 1089 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | { |
| 1091 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 68188ba | 2005-05-16 18:52:38 +0200 | [diff] [blame] | 1092 | return sprintf(buf, "%u\n", data->alarms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | } |
Jean Delvare | 1d66c64 | 2005-04-18 21:16:59 -0700 | [diff] [blame] | 1094 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1096 | static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, |
| 1097 | char *buf) |
| 1098 | { |
| 1099 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 1100 | struct it87_data *data = it87_update_device(dev); |
| 1101 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); |
| 1102 | } |
| 1103 | static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 8); |
| 1104 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 9); |
| 1105 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 10); |
| 1106 | static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 11); |
| 1107 | static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 12); |
| 1108 | static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 13); |
| 1109 | static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 14); |
| 1110 | static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 15); |
| 1111 | static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 0); |
| 1112 | static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 1); |
| 1113 | static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 2); |
| 1114 | static SENSOR_DEVICE_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 3); |
| 1115 | static SENSOR_DEVICE_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 6); |
| 1116 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 16); |
| 1117 | static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 17); |
| 1118 | static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 18); |
| 1119 | |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1120 | static ssize_t show_beep(struct device *dev, struct device_attribute *attr, |
| 1121 | char *buf) |
| 1122 | { |
| 1123 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 1124 | struct it87_data *data = it87_update_device(dev); |
| 1125 | return sprintf(buf, "%u\n", (data->beeps >> bitnr) & 1); |
| 1126 | } |
| 1127 | static ssize_t set_beep(struct device *dev, struct device_attribute *attr, |
| 1128 | const char *buf, size_t count) |
| 1129 | { |
| 1130 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 1131 | struct it87_data *data = dev_get_drvdata(dev); |
| 1132 | long val; |
| 1133 | |
| 1134 | if (strict_strtol(buf, 10, &val) < 0 |
| 1135 | || (val != 0 && val != 1)) |
| 1136 | return -EINVAL; |
| 1137 | |
| 1138 | mutex_lock(&data->update_lock); |
| 1139 | data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE); |
| 1140 | if (val) |
| 1141 | data->beeps |= (1 << bitnr); |
| 1142 | else |
| 1143 | data->beeps &= ~(1 << bitnr); |
| 1144 | it87_write_value(data, IT87_REG_BEEP_ENABLE, data->beeps); |
| 1145 | mutex_unlock(&data->update_lock); |
| 1146 | return count; |
| 1147 | } |
| 1148 | |
| 1149 | static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR, |
| 1150 | show_beep, set_beep, 1); |
| 1151 | static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO, show_beep, NULL, 1); |
| 1152 | static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO, show_beep, NULL, 1); |
| 1153 | static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO, show_beep, NULL, 1); |
| 1154 | static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO, show_beep, NULL, 1); |
| 1155 | static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO, show_beep, NULL, 1); |
| 1156 | static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO, show_beep, NULL, 1); |
| 1157 | static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO, show_beep, NULL, 1); |
| 1158 | /* fanX_beep writability is set later */ |
| 1159 | static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1160 | static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1161 | static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1162 | static SENSOR_DEVICE_ATTR(fan4_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1163 | static SENSOR_DEVICE_ATTR(fan5_beep, S_IRUGO, show_beep, set_beep, 0); |
| 1164 | static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR, |
| 1165 | show_beep, set_beep, 2); |
| 1166 | static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO, show_beep, NULL, 2); |
| 1167 | static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO, show_beep, NULL, 2); |
| 1168 | |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1169 | static ssize_t show_vrm_reg(struct device *dev, struct device_attribute *attr, |
| 1170 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | { |
Jean Delvare | 90d6619 | 2007-10-08 18:24:35 +0200 | [diff] [blame] | 1172 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | a7be58a | 2005-12-18 16:40:14 +0100 | [diff] [blame] | 1173 | return sprintf(buf, "%u\n", data->vrm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1174 | } |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1175 | static ssize_t store_vrm_reg(struct device *dev, struct device_attribute *attr, |
| 1176 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1178 | struct it87_data *data = dev_get_drvdata(dev); |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1179 | unsigned long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | |
Jean Delvare | f5f6450 | 2010-03-05 22:17:19 +0100 | [diff] [blame] | 1181 | if (strict_strtoul(buf, 10, &val) < 0) |
| 1182 | return -EINVAL; |
| 1183 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1184 | data->vrm = val; |
| 1185 | |
| 1186 | return count; |
| 1187 | } |
| 1188 | 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] | 1189 | |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1190 | static ssize_t show_vid_reg(struct device *dev, struct device_attribute *attr, |
| 1191 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | { |
| 1193 | struct it87_data *data = it87_update_device(dev); |
| 1194 | return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); |
| 1195 | } |
| 1196 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1197 | |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1198 | static ssize_t show_label(struct device *dev, struct device_attribute *attr, |
| 1199 | char *buf) |
| 1200 | { |
| 1201 | static const char *labels[] = { |
| 1202 | "+5V", |
| 1203 | "5VSB", |
| 1204 | "Vbat", |
| 1205 | }; |
| 1206 | int nr = to_sensor_dev_attr(attr)->index; |
| 1207 | |
| 1208 | return sprintf(buf, "%s\n", labels[nr]); |
| 1209 | } |
| 1210 | static SENSOR_DEVICE_ATTR(in3_label, S_IRUGO, show_label, NULL, 0); |
| 1211 | static SENSOR_DEVICE_ATTR(in7_label, S_IRUGO, show_label, NULL, 1); |
| 1212 | static SENSOR_DEVICE_ATTR(in8_label, S_IRUGO, show_label, NULL, 2); |
| 1213 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1214 | static ssize_t show_name(struct device *dev, struct device_attribute |
| 1215 | *devattr, char *buf) |
| 1216 | { |
| 1217 | struct it87_data *data = dev_get_drvdata(dev); |
| 1218 | return sprintf(buf, "%s\n", data->name); |
| 1219 | } |
| 1220 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
| 1221 | |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1222 | static struct attribute *it87_attributes[] = { |
| 1223 | &sensor_dev_attr_in0_input.dev_attr.attr, |
| 1224 | &sensor_dev_attr_in1_input.dev_attr.attr, |
| 1225 | &sensor_dev_attr_in2_input.dev_attr.attr, |
| 1226 | &sensor_dev_attr_in3_input.dev_attr.attr, |
| 1227 | &sensor_dev_attr_in4_input.dev_attr.attr, |
| 1228 | &sensor_dev_attr_in5_input.dev_attr.attr, |
| 1229 | &sensor_dev_attr_in6_input.dev_attr.attr, |
| 1230 | &sensor_dev_attr_in7_input.dev_attr.attr, |
| 1231 | &sensor_dev_attr_in8_input.dev_attr.attr, |
| 1232 | &sensor_dev_attr_in0_min.dev_attr.attr, |
| 1233 | &sensor_dev_attr_in1_min.dev_attr.attr, |
| 1234 | &sensor_dev_attr_in2_min.dev_attr.attr, |
| 1235 | &sensor_dev_attr_in3_min.dev_attr.attr, |
| 1236 | &sensor_dev_attr_in4_min.dev_attr.attr, |
| 1237 | &sensor_dev_attr_in5_min.dev_attr.attr, |
| 1238 | &sensor_dev_attr_in6_min.dev_attr.attr, |
| 1239 | &sensor_dev_attr_in7_min.dev_attr.attr, |
| 1240 | &sensor_dev_attr_in0_max.dev_attr.attr, |
| 1241 | &sensor_dev_attr_in1_max.dev_attr.attr, |
| 1242 | &sensor_dev_attr_in2_max.dev_attr.attr, |
| 1243 | &sensor_dev_attr_in3_max.dev_attr.attr, |
| 1244 | &sensor_dev_attr_in4_max.dev_attr.attr, |
| 1245 | &sensor_dev_attr_in5_max.dev_attr.attr, |
| 1246 | &sensor_dev_attr_in6_max.dev_attr.attr, |
| 1247 | &sensor_dev_attr_in7_max.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1248 | &sensor_dev_attr_in0_alarm.dev_attr.attr, |
| 1249 | &sensor_dev_attr_in1_alarm.dev_attr.attr, |
| 1250 | &sensor_dev_attr_in2_alarm.dev_attr.attr, |
| 1251 | &sensor_dev_attr_in3_alarm.dev_attr.attr, |
| 1252 | &sensor_dev_attr_in4_alarm.dev_attr.attr, |
| 1253 | &sensor_dev_attr_in5_alarm.dev_attr.attr, |
| 1254 | &sensor_dev_attr_in6_alarm.dev_attr.attr, |
| 1255 | &sensor_dev_attr_in7_alarm.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1256 | |
| 1257 | &sensor_dev_attr_temp1_input.dev_attr.attr, |
| 1258 | &sensor_dev_attr_temp2_input.dev_attr.attr, |
| 1259 | &sensor_dev_attr_temp3_input.dev_attr.attr, |
| 1260 | &sensor_dev_attr_temp1_max.dev_attr.attr, |
| 1261 | &sensor_dev_attr_temp2_max.dev_attr.attr, |
| 1262 | &sensor_dev_attr_temp3_max.dev_attr.attr, |
| 1263 | &sensor_dev_attr_temp1_min.dev_attr.attr, |
| 1264 | &sensor_dev_attr_temp2_min.dev_attr.attr, |
| 1265 | &sensor_dev_attr_temp3_min.dev_attr.attr, |
| 1266 | &sensor_dev_attr_temp1_type.dev_attr.attr, |
| 1267 | &sensor_dev_attr_temp2_type.dev_attr.attr, |
| 1268 | &sensor_dev_attr_temp3_type.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1269 | &sensor_dev_attr_temp1_alarm.dev_attr.attr, |
| 1270 | &sensor_dev_attr_temp2_alarm.dev_attr.attr, |
| 1271 | &sensor_dev_attr_temp3_alarm.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1272 | |
| 1273 | &dev_attr_alarms.attr, |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1274 | &dev_attr_name.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1275 | NULL |
| 1276 | }; |
| 1277 | |
| 1278 | static const struct attribute_group it87_group = { |
| 1279 | .attrs = it87_attributes, |
| 1280 | }; |
| 1281 | |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1282 | static struct attribute *it87_attributes_beep[] = { |
| 1283 | &sensor_dev_attr_in0_beep.dev_attr.attr, |
| 1284 | &sensor_dev_attr_in1_beep.dev_attr.attr, |
| 1285 | &sensor_dev_attr_in2_beep.dev_attr.attr, |
| 1286 | &sensor_dev_attr_in3_beep.dev_attr.attr, |
| 1287 | &sensor_dev_attr_in4_beep.dev_attr.attr, |
| 1288 | &sensor_dev_attr_in5_beep.dev_attr.attr, |
| 1289 | &sensor_dev_attr_in6_beep.dev_attr.attr, |
| 1290 | &sensor_dev_attr_in7_beep.dev_attr.attr, |
| 1291 | |
| 1292 | &sensor_dev_attr_temp1_beep.dev_attr.attr, |
| 1293 | &sensor_dev_attr_temp2_beep.dev_attr.attr, |
| 1294 | &sensor_dev_attr_temp3_beep.dev_attr.attr, |
| 1295 | NULL |
| 1296 | }; |
| 1297 | |
| 1298 | static const struct attribute_group it87_group_beep = { |
| 1299 | .attrs = it87_attributes_beep, |
| 1300 | }; |
| 1301 | |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1302 | static struct attribute *it87_attributes_fan16[5][3+1] = { { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1303 | &sensor_dev_attr_fan1_input16.dev_attr.attr, |
| 1304 | &sensor_dev_attr_fan1_min16.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1305 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
| 1306 | NULL |
| 1307 | }, { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1308 | &sensor_dev_attr_fan2_input16.dev_attr.attr, |
| 1309 | &sensor_dev_attr_fan2_min16.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1310 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
| 1311 | NULL |
| 1312 | }, { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1313 | &sensor_dev_attr_fan3_input16.dev_attr.attr, |
| 1314 | &sensor_dev_attr_fan3_min16.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1315 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, |
| 1316 | NULL |
| 1317 | }, { |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 1318 | &sensor_dev_attr_fan4_input16.dev_attr.attr, |
| 1319 | &sensor_dev_attr_fan4_min16.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1320 | &sensor_dev_attr_fan4_alarm.dev_attr.attr, |
| 1321 | NULL |
| 1322 | }, { |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 1323 | &sensor_dev_attr_fan5_input16.dev_attr.attr, |
| 1324 | &sensor_dev_attr_fan5_min16.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1325 | &sensor_dev_attr_fan5_alarm.dev_attr.attr, |
| 1326 | NULL |
| 1327 | } }; |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1328 | |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1329 | static const struct attribute_group it87_group_fan16[5] = { |
| 1330 | { .attrs = it87_attributes_fan16[0] }, |
| 1331 | { .attrs = it87_attributes_fan16[1] }, |
| 1332 | { .attrs = it87_attributes_fan16[2] }, |
| 1333 | { .attrs = it87_attributes_fan16[3] }, |
| 1334 | { .attrs = it87_attributes_fan16[4] }, |
| 1335 | }; |
| 1336 | |
| 1337 | static struct attribute *it87_attributes_fan[3][4+1] = { { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1338 | &sensor_dev_attr_fan1_input.dev_attr.attr, |
| 1339 | &sensor_dev_attr_fan1_min.dev_attr.attr, |
| 1340 | &sensor_dev_attr_fan1_div.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1341 | &sensor_dev_attr_fan1_alarm.dev_attr.attr, |
| 1342 | NULL |
| 1343 | }, { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1344 | &sensor_dev_attr_fan2_input.dev_attr.attr, |
| 1345 | &sensor_dev_attr_fan2_min.dev_attr.attr, |
| 1346 | &sensor_dev_attr_fan2_div.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1347 | &sensor_dev_attr_fan2_alarm.dev_attr.attr, |
| 1348 | NULL |
| 1349 | }, { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1350 | &sensor_dev_attr_fan3_input.dev_attr.attr, |
| 1351 | &sensor_dev_attr_fan3_min.dev_attr.attr, |
| 1352 | &sensor_dev_attr_fan3_div.dev_attr.attr, |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1353 | &sensor_dev_attr_fan3_alarm.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1354 | NULL |
| 1355 | } }; |
Jean Delvare | 0124dd7 | 2007-11-25 16:16:41 +0100 | [diff] [blame] | 1356 | |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1357 | static const struct attribute_group it87_group_fan[3] = { |
| 1358 | { .attrs = it87_attributes_fan[0] }, |
| 1359 | { .attrs = it87_attributes_fan[1] }, |
| 1360 | { .attrs = it87_attributes_fan[2] }, |
| 1361 | }; |
| 1362 | |
| 1363 | static const struct attribute_group * |
| 1364 | it87_get_fan_group(const struct it87_data *data) |
| 1365 | { |
| 1366 | return has_16bit_fans(data) ? it87_group_fan16 : it87_group_fan; |
| 1367 | } |
| 1368 | |
| 1369 | static struct attribute *it87_attributes_pwm[3][4+1] = { { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1370 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1371 | &sensor_dev_attr_pwm1.dev_attr.attr, |
Jean Delvare | d5b0b5d | 2007-12-14 14:41:53 +0100 | [diff] [blame] | 1372 | &dev_attr_pwm1_freq.attr, |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1373 | &sensor_dev_attr_pwm1_auto_channels_temp.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1374 | NULL |
| 1375 | }, { |
| 1376 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, |
| 1377 | &sensor_dev_attr_pwm2.dev_attr.attr, |
| 1378 | &dev_attr_pwm2_freq.attr, |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1379 | &sensor_dev_attr_pwm2_auto_channels_temp.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1380 | NULL |
| 1381 | }, { |
| 1382 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, |
| 1383 | &sensor_dev_attr_pwm3.dev_attr.attr, |
| 1384 | &dev_attr_pwm3_freq.attr, |
Jean Delvare | 94ac7ee | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1385 | &sensor_dev_attr_pwm3_auto_channels_temp.dev_attr.attr, |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1386 | NULL |
| 1387 | } }; |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1388 | |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1389 | static const struct attribute_group it87_group_pwm[3] = { |
| 1390 | { .attrs = it87_attributes_pwm[0] }, |
| 1391 | { .attrs = it87_attributes_pwm[1] }, |
| 1392 | { .attrs = it87_attributes_pwm[2] }, |
| 1393 | }; |
| 1394 | |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1395 | static struct attribute *it87_attributes_autopwm[3][9+1] = { { |
| 1396 | &sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr, |
| 1397 | &sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr, |
| 1398 | &sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr, |
| 1399 | &sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr, |
| 1400 | &sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr, |
| 1401 | &sensor_dev_attr_pwm1_auto_point1_temp_hyst.dev_attr.attr, |
| 1402 | &sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr, |
| 1403 | &sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr, |
| 1404 | &sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr, |
| 1405 | NULL |
| 1406 | }, { |
| 1407 | &sensor_dev_attr_pwm2_auto_point1_pwm.dev_attr.attr, |
| 1408 | &sensor_dev_attr_pwm2_auto_point2_pwm.dev_attr.attr, |
| 1409 | &sensor_dev_attr_pwm2_auto_point3_pwm.dev_attr.attr, |
| 1410 | &sensor_dev_attr_pwm2_auto_point4_pwm.dev_attr.attr, |
| 1411 | &sensor_dev_attr_pwm2_auto_point1_temp.dev_attr.attr, |
| 1412 | &sensor_dev_attr_pwm2_auto_point1_temp_hyst.dev_attr.attr, |
| 1413 | &sensor_dev_attr_pwm2_auto_point2_temp.dev_attr.attr, |
| 1414 | &sensor_dev_attr_pwm2_auto_point3_temp.dev_attr.attr, |
| 1415 | &sensor_dev_attr_pwm2_auto_point4_temp.dev_attr.attr, |
| 1416 | NULL |
| 1417 | }, { |
| 1418 | &sensor_dev_attr_pwm3_auto_point1_pwm.dev_attr.attr, |
| 1419 | &sensor_dev_attr_pwm3_auto_point2_pwm.dev_attr.attr, |
| 1420 | &sensor_dev_attr_pwm3_auto_point3_pwm.dev_attr.attr, |
| 1421 | &sensor_dev_attr_pwm3_auto_point4_pwm.dev_attr.attr, |
| 1422 | &sensor_dev_attr_pwm3_auto_point1_temp.dev_attr.attr, |
| 1423 | &sensor_dev_attr_pwm3_auto_point1_temp_hyst.dev_attr.attr, |
| 1424 | &sensor_dev_attr_pwm3_auto_point2_temp.dev_attr.attr, |
| 1425 | &sensor_dev_attr_pwm3_auto_point3_temp.dev_attr.attr, |
| 1426 | &sensor_dev_attr_pwm3_auto_point4_temp.dev_attr.attr, |
| 1427 | NULL |
| 1428 | } }; |
| 1429 | |
| 1430 | static const struct attribute_group it87_group_autopwm[3] = { |
| 1431 | { .attrs = it87_attributes_autopwm[0] }, |
| 1432 | { .attrs = it87_attributes_autopwm[1] }, |
| 1433 | { .attrs = it87_attributes_autopwm[2] }, |
| 1434 | }; |
| 1435 | |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1436 | static struct attribute *it87_attributes_fan_beep[] = { |
| 1437 | &sensor_dev_attr_fan1_beep.dev_attr.attr, |
| 1438 | &sensor_dev_attr_fan2_beep.dev_attr.attr, |
| 1439 | &sensor_dev_attr_fan3_beep.dev_attr.attr, |
| 1440 | &sensor_dev_attr_fan4_beep.dev_attr.attr, |
| 1441 | &sensor_dev_attr_fan5_beep.dev_attr.attr, |
| 1442 | }; |
| 1443 | |
Jean Delvare | 6a8d7ac | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1444 | static struct attribute *it87_attributes_vid[] = { |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1445 | &dev_attr_vrm.attr, |
| 1446 | &dev_attr_cpu0_vid.attr, |
| 1447 | NULL |
| 1448 | }; |
| 1449 | |
Jean Delvare | 6a8d7ac | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1450 | static const struct attribute_group it87_group_vid = { |
| 1451 | .attrs = it87_attributes_vid, |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1452 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1454 | static struct attribute *it87_attributes_label[] = { |
| 1455 | &sensor_dev_attr_in3_label.dev_attr.attr, |
| 1456 | &sensor_dev_attr_in7_label.dev_attr.attr, |
| 1457 | &sensor_dev_attr_in8_label.dev_attr.attr, |
| 1458 | NULL |
| 1459 | }; |
| 1460 | |
| 1461 | static const struct attribute_group it87_group_label = { |
| 1462 | .attrs = it87_attributes_vid, |
| 1463 | }; |
| 1464 | |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 1465 | /* SuperIO detection - will change isa_address if a chip is found */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1466 | static int __init it87_find(unsigned short *address, |
| 1467 | struct it87_sio_data *sio_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | { |
| 1469 | int err = -ENODEV; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1470 | u16 chip_type; |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 1471 | const char *board_vendor, *board_name; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | |
| 1473 | superio_enter(); |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 1474 | chip_type = force_id ? force_id : superio_inw(DEVID); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1475 | |
| 1476 | switch (chip_type) { |
| 1477 | case IT8705F_DEVID: |
| 1478 | sio_data->type = it87; |
| 1479 | break; |
| 1480 | case IT8712F_DEVID: |
| 1481 | sio_data->type = it8712; |
| 1482 | break; |
| 1483 | case IT8716F_DEVID: |
| 1484 | case IT8726F_DEVID: |
| 1485 | sio_data->type = it8716; |
| 1486 | break; |
| 1487 | case IT8718F_DEVID: |
| 1488 | sio_data->type = it8718; |
| 1489 | break; |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 1490 | case IT8720F_DEVID: |
| 1491 | sio_data->type = it8720; |
| 1492 | break; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1493 | case 0xffff: /* No device at all */ |
| 1494 | goto exit; |
| 1495 | default: |
| 1496 | pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%x)\n", |
| 1497 | chip_type); |
| 1498 | goto exit; |
| 1499 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1501 | superio_select(PME); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | if (!(superio_inb(IT87_ACT_REG) & 0x01)) { |
| 1503 | pr_info("it87: Device not activated, skipping\n"); |
| 1504 | goto exit; |
| 1505 | } |
| 1506 | |
| 1507 | *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1); |
| 1508 | if (*address == 0) { |
| 1509 | pr_info("it87: Base address not set, skipping\n"); |
| 1510 | goto exit; |
| 1511 | } |
| 1512 | |
| 1513 | err = 0; |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 1514 | sio_data->revision = superio_inb(DEVREV) & 0x0f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n", |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 1516 | chip_type, *address, sio_data->revision); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1518 | /* in8 (Vbat) is always internal */ |
| 1519 | sio_data->internal = (1 << 2); |
| 1520 | |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1521 | /* Read GPIO config and VID value from LDN 7 (GPIO) */ |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 1522 | if (sio_data->type == it87) { |
| 1523 | /* The IT8705F doesn't have VID pins at all */ |
| 1524 | sio_data->skip_vid = 1; |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1525 | |
| 1526 | /* The IT8705F has a different LD number for GPIO */ |
| 1527 | superio_select(5); |
| 1528 | sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 1529 | } else { |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1530 | int reg; |
| 1531 | |
| 1532 | superio_select(GPIO); |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 1533 | /* We need at least 4 VID pins */ |
| 1534 | reg = superio_inb(IT87_SIO_GPIO3_REG); |
| 1535 | if (reg & 0x0f) { |
| 1536 | pr_info("it87: VID is disabled (pins used for GPIO)\n"); |
| 1537 | sio_data->skip_vid = 1; |
| 1538 | } |
| 1539 | |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 1540 | /* Check if fan3 is there or not */ |
| 1541 | if (reg & (1 << 6)) |
| 1542 | sio_data->skip_pwm |= (1 << 2); |
| 1543 | if (reg & (1 << 7)) |
| 1544 | sio_data->skip_fan |= (1 << 2); |
| 1545 | |
| 1546 | /* Check if fan2 is there or not */ |
| 1547 | reg = superio_inb(IT87_SIO_GPIO5_REG); |
| 1548 | if (reg & (1 << 1)) |
| 1549 | sio_data->skip_pwm |= (1 << 1); |
| 1550 | if (reg & (1 << 2)) |
| 1551 | sio_data->skip_fan |= (1 << 1); |
| 1552 | |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 1553 | if ((sio_data->type == it8718 || sio_data->type == it8720) |
| 1554 | && !(sio_data->skip_vid)) |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1555 | sio_data->vid_value = superio_inb(IT87_SIO_VID_REG); |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1556 | |
| 1557 | reg = superio_inb(IT87_SIO_PINX2_REG); |
Jean Delvare | 436cad2 | 2010-07-09 16:22:48 +0200 | [diff] [blame] | 1558 | /* |
| 1559 | * The IT8720F has no VIN7 pin, so VCCH should always be |
| 1560 | * routed internally to VIN7 with an internal divider. |
| 1561 | * Curiously, there still is a configuration bit to control |
| 1562 | * this, which means it can be set incorrectly. And even |
| 1563 | * more curiously, many boards out there are improperly |
| 1564 | * configured, even though the IT8720F datasheet claims |
| 1565 | * that the internal routing of VCCH to VIN7 is the default |
| 1566 | * setting. So we force the internal routing in this case. |
| 1567 | */ |
| 1568 | if (sio_data->type == it8720 && !(reg & (1 << 1))) { |
| 1569 | reg |= (1 << 1); |
| 1570 | superio_outb(IT87_SIO_PINX2_REG, reg); |
| 1571 | pr_notice("it87: Routing internal VCCH to in7\n"); |
| 1572 | } |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1573 | if (reg & (1 << 0)) |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1574 | sio_data->internal |= (1 << 0); |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1575 | if (reg & (1 << 1)) |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1576 | sio_data->internal |= (1 << 1); |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1577 | |
| 1578 | sio_data->beep_pin = superio_inb(IT87_SIO_BEEP_PIN_REG) & 0x3f; |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1579 | } |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1580 | if (sio_data->beep_pin) |
| 1581 | pr_info("it87: Beeping is supported\n"); |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1582 | |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 1583 | /* Disable specific features based on DMI strings */ |
| 1584 | board_vendor = dmi_get_system_info(DMI_BOARD_VENDOR); |
| 1585 | board_name = dmi_get_system_info(DMI_BOARD_NAME); |
| 1586 | if (board_vendor && board_name) { |
| 1587 | if (strcmp(board_vendor, "nVIDIA") == 0 |
| 1588 | && strcmp(board_name, "FN68PT") == 0) { |
| 1589 | /* On the Shuttle SN68PT, FAN_CTL2 is apparently not |
| 1590 | connected to a fan, but to something else. One user |
| 1591 | has reported instant system power-off when changing |
| 1592 | the PWM2 duty cycle, so we disable it. |
| 1593 | I use the board name string as the trigger in case |
| 1594 | the same board is ever used in other systems. */ |
| 1595 | pr_info("it87: Disabling pwm2 due to " |
| 1596 | "hardware constraints\n"); |
| 1597 | sio_data->skip_pwm = (1 << 1); |
| 1598 | } |
| 1599 | } |
| 1600 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1601 | exit: |
| 1602 | superio_exit(); |
| 1603 | return err; |
| 1604 | } |
| 1605 | |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1606 | static void it87_remove_files(struct device *dev) |
| 1607 | { |
| 1608 | struct it87_data *data = platform_get_drvdata(pdev); |
| 1609 | struct it87_sio_data *sio_data = dev->platform_data; |
| 1610 | const struct attribute_group *fan_group = it87_get_fan_group(data); |
| 1611 | int i; |
| 1612 | |
| 1613 | sysfs_remove_group(&dev->kobj, &it87_group); |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1614 | if (sio_data->beep_pin) |
| 1615 | sysfs_remove_group(&dev->kobj, &it87_group_beep); |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1616 | for (i = 0; i < 5; i++) { |
| 1617 | if (!(data->has_fan & (1 << i))) |
| 1618 | continue; |
| 1619 | sysfs_remove_group(&dev->kobj, &fan_group[i]); |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1620 | if (sio_data->beep_pin) |
| 1621 | sysfs_remove_file(&dev->kobj, |
| 1622 | it87_attributes_fan_beep[i]); |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1623 | } |
| 1624 | for (i = 0; i < 3; i++) { |
| 1625 | if (sio_data->skip_pwm & (1 << 0)) |
| 1626 | continue; |
| 1627 | sysfs_remove_group(&dev->kobj, &it87_group_pwm[i]); |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1628 | if (has_old_autopwm(data)) |
| 1629 | sysfs_remove_group(&dev->kobj, |
| 1630 | &it87_group_autopwm[i]); |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1631 | } |
Jean Delvare | 6a8d7ac | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1632 | if (!sio_data->skip_vid) |
| 1633 | sysfs_remove_group(&dev->kobj, &it87_group_vid); |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1634 | sysfs_remove_group(&dev->kobj, &it87_group_label); |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1635 | } |
| 1636 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1637 | static int __devinit it87_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | struct it87_data *data; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1640 | struct resource *res; |
| 1641 | struct device *dev = &pdev->dev; |
| 1642 | struct it87_sio_data *sio_data = dev->platform_data; |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1643 | const struct attribute_group *fan_group; |
| 1644 | int err = 0, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | int enable_pwm_interface; |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1646 | int fan_beep_need_rw; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1647 | static const char *names[] = { |
| 1648 | "it87", |
| 1649 | "it8712", |
| 1650 | "it8716", |
| 1651 | "it8718", |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 1652 | "it8720", |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1653 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1655 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
Bjorn Helgaas | 87b4b66 | 2008-01-22 07:21:03 -0500 | [diff] [blame] | 1656 | if (!request_region(res->start, IT87_EC_EXTENT, DRVNAME)) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1657 | dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", |
| 1658 | (unsigned long)res->start, |
Bjorn Helgaas | 87b4b66 | 2008-01-22 07:21:03 -0500 | [diff] [blame] | 1659 | (unsigned long)(res->start + IT87_EC_EXTENT - 1)); |
Jean Delvare | 8e9afcb | 2006-12-12 18:18:28 +0100 | [diff] [blame] | 1660 | err = -EBUSY; |
| 1661 | goto ERROR0; |
| 1662 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1664 | data = kzalloc(sizeof(struct it87_data), GFP_KERNEL); |
| 1665 | if (!data) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1666 | err = -ENOMEM; |
| 1667 | goto ERROR1; |
| 1668 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1670 | data->addr = res->start; |
| 1671 | data->type = sio_data->type; |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 1672 | data->revision = sio_data->revision; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1673 | data->name = names[sio_data->type]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | |
| 1675 | /* Now, we do the remaining detection. */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1676 | if ((it87_read_value(data, IT87_REG_CONFIG) & 0x80) |
| 1677 | || it87_read_value(data, IT87_REG_CHIPID) != 0x90) { |
Jean Delvare | 8e9afcb | 2006-12-12 18:18:28 +0100 | [diff] [blame] | 1678 | err = -ENODEV; |
| 1679 | goto ERROR2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | } |
| 1681 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1682 | platform_set_drvdata(pdev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1684 | mutex_init(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1686 | /* Check PWM configuration */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1687 | enable_pwm_interface = it87_check_pwm(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | |
| 1689 | /* Initialize the IT87 chip */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1690 | it87_init_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1691 | |
| 1692 | /* Register sysfs hooks */ |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1693 | err = sysfs_create_group(&dev->kobj, &it87_group); |
| 1694 | if (err) |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1695 | goto ERROR2; |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 1696 | |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1697 | if (sio_data->beep_pin) { |
| 1698 | err = sysfs_create_group(&dev->kobj, &it87_group_beep); |
| 1699 | if (err) |
| 1700 | goto ERROR4; |
| 1701 | } |
| 1702 | |
Jean Delvare | 9060f8b | 2006-08-28 14:24:17 +0200 | [diff] [blame] | 1703 | /* Do not create fan files for disabled fans */ |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1704 | fan_group = it87_get_fan_group(data); |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1705 | fan_beep_need_rw = 1; |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1706 | for (i = 0; i < 5; i++) { |
| 1707 | if (!(data->has_fan & (1 << i))) |
| 1708 | continue; |
| 1709 | err = sysfs_create_group(&dev->kobj, &fan_group[i]); |
| 1710 | if (err) |
| 1711 | goto ERROR4; |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 1712 | |
| 1713 | if (sio_data->beep_pin) { |
| 1714 | err = sysfs_create_file(&dev->kobj, |
| 1715 | it87_attributes_fan_beep[i]); |
| 1716 | if (err) |
| 1717 | goto ERROR4; |
| 1718 | if (!fan_beep_need_rw) |
| 1719 | continue; |
| 1720 | |
| 1721 | /* As we have a single beep enable bit for all fans, |
| 1722 | * only the first enabled fan has a writable attribute |
| 1723 | * for it. */ |
| 1724 | if (sysfs_chmod_file(&dev->kobj, |
| 1725 | it87_attributes_fan_beep[i], |
| 1726 | S_IRUGO | S_IWUSR)) |
| 1727 | dev_dbg(dev, "chmod +w fan%d_beep failed\n", |
| 1728 | i + 1); |
| 1729 | fan_beep_need_rw = 0; |
| 1730 | } |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 1731 | } |
| 1732 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | if (enable_pwm_interface) { |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1734 | for (i = 0; i < 3; i++) { |
| 1735 | if (sio_data->skip_pwm & (1 << i)) |
| 1736 | continue; |
| 1737 | err = sysfs_create_group(&dev->kobj, |
| 1738 | &it87_group_pwm[i]); |
| 1739 | if (err) |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 1740 | goto ERROR4; |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1741 | |
| 1742 | if (!has_old_autopwm(data)) |
| 1743 | continue; |
| 1744 | err = sysfs_create_group(&dev->kobj, |
| 1745 | &it87_group_autopwm[i]); |
| 1746 | if (err) |
| 1747 | goto ERROR4; |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 1748 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | } |
| 1750 | |
Jean Delvare | 895ff26 | 2009-12-09 20:35:47 +0100 | [diff] [blame] | 1751 | if (!sio_data->skip_vid) { |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 1752 | data->vrm = vid_which_vrm(); |
Jean Delvare | 87673dd | 2006-08-28 14:37:19 +0200 | [diff] [blame] | 1753 | /* VID reading from Super-I/O config space if available */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1754 | data->vid = sio_data->vid_value; |
Jean Delvare | 6a8d7ac | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1755 | err = sysfs_create_group(&dev->kobj, &it87_group_vid); |
| 1756 | if (err) |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1757 | goto ERROR4; |
| 1758 | } |
| 1759 | |
Jean Delvare | 738e5e0 | 2010-08-14 21:08:50 +0200 | [diff] [blame] | 1760 | /* Export labels for internal sensors */ |
| 1761 | for (i = 0; i < 3; i++) { |
| 1762 | if (!(sio_data->internal & (1 << i))) |
| 1763 | continue; |
| 1764 | err = sysfs_create_file(&dev->kobj, |
| 1765 | it87_attributes_label[i]); |
| 1766 | if (err) |
| 1767 | goto ERROR4; |
| 1768 | } |
| 1769 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1770 | data->hwmon_dev = hwmon_device_register(dev); |
| 1771 | if (IS_ERR(data->hwmon_dev)) { |
| 1772 | err = PTR_ERR(data->hwmon_dev); |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1773 | goto ERROR4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1774 | } |
| 1775 | |
| 1776 | return 0; |
| 1777 | |
Jean Delvare | 87808be | 2006-09-24 21:17:13 +0200 | [diff] [blame] | 1778 | ERROR4: |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1779 | it87_remove_files(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1780 | ERROR2: |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1781 | platform_set_drvdata(pdev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1782 | kfree(data); |
| 1783 | ERROR1: |
Bjorn Helgaas | 87b4b66 | 2008-01-22 07:21:03 -0500 | [diff] [blame] | 1784 | release_region(res->start, IT87_EC_EXTENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | ERROR0: |
| 1786 | return err; |
| 1787 | } |
| 1788 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1789 | static int __devexit it87_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1791 | struct it87_data *data = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1793 | hwmon_device_unregister(data->hwmon_dev); |
Jean Delvare | 723a0aa | 2010-03-05 22:17:16 +0100 | [diff] [blame] | 1794 | it87_remove_files(&pdev->dev); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1795 | |
Bjorn Helgaas | 87b4b66 | 2008-01-22 07:21:03 -0500 | [diff] [blame] | 1796 | release_region(data->addr, IT87_EC_EXTENT); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1797 | platform_set_drvdata(pdev, NULL); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1798 | kfree(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | |
| 1800 | return 0; |
| 1801 | } |
| 1802 | |
Jean Delvare | 7f999aa | 2007-02-14 21:15:03 +0100 | [diff] [blame] | 1803 | /* Must be called with data->update_lock held, except during initialization. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1804 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
| 1805 | would slow down the IT87 access and should not be necessary. */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1806 | static int it87_read_value(struct it87_data *data, u8 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1808 | outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); |
| 1809 | return inb_p(data->addr + IT87_DATA_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | } |
| 1811 | |
Jean Delvare | 7f999aa | 2007-02-14 21:15:03 +0100 | [diff] [blame] | 1812 | /* Must be called with data->update_lock held, except during initialization. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
| 1814 | would slow down the IT87 access and should not be necessary. */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1815 | 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] | 1816 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1817 | outb_p(reg, data->addr + IT87_ADDR_REG_OFFSET); |
| 1818 | outb_p(value, data->addr + IT87_DATA_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | /* Return 1 if and only if the PWM interface is safe to use */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1822 | static int __devinit it87_check_pwm(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1824 | struct it87_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1825 | /* Some BIOSes fail to correctly configure the IT87 fans. All fans off |
| 1826 | * and polarity set to active low is sign that this is the case so we |
| 1827 | * disable pwm control to protect the user. */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1828 | int tmp = it87_read_value(data, IT87_REG_FAN_CTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1829 | if ((tmp & 0x87) == 0) { |
| 1830 | if (fix_pwm_polarity) { |
| 1831 | /* The user asks us to attempt a chip reconfiguration. |
| 1832 | * This means switching to active high polarity and |
| 1833 | * inverting all fan speed values. */ |
| 1834 | int i; |
| 1835 | u8 pwm[3]; |
| 1836 | |
| 1837 | for (i = 0; i < 3; i++) |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1838 | pwm[i] = it87_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | IT87_REG_PWM(i)); |
| 1840 | |
| 1841 | /* If any fan is in automatic pwm mode, the polarity |
| 1842 | * might be correct, as suspicious as it seems, so we |
| 1843 | * better don't change anything (but still disable the |
| 1844 | * PWM interface). */ |
| 1845 | if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1846 | dev_info(dev, "Reconfiguring PWM to " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | "active high polarity\n"); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1848 | it87_write_value(data, IT87_REG_FAN_CTL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | tmp | 0x87); |
| 1850 | for (i = 0; i < 3; i++) |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1851 | it87_write_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | IT87_REG_PWM(i), |
| 1853 | 0x7f & ~pwm[i]); |
| 1854 | return 1; |
| 1855 | } |
| 1856 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1857 | dev_info(dev, "PWM configuration is " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1858 | "too broken to be fixed\n"); |
| 1859 | } |
| 1860 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1861 | dev_info(dev, "Detected broken BIOS " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | "defaults, disabling PWM interface\n"); |
| 1863 | return 0; |
| 1864 | } else if (fix_pwm_polarity) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1865 | dev_info(dev, "PWM configuration looks " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | "sane, won't touch\n"); |
| 1867 | } |
| 1868 | |
| 1869 | return 1; |
| 1870 | } |
| 1871 | |
| 1872 | /* Called when we have found a new IT87. */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1873 | static void __devinit it87_init_device(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | { |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 1875 | struct it87_sio_data *sio_data = pdev->dev.platform_data; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1876 | struct it87_data *data = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | int tmp, i; |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 1878 | u8 mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1880 | /* For each PWM channel: |
| 1881 | * - If it is in automatic mode, setting to manual mode should set |
| 1882 | * the fan to full speed by default. |
| 1883 | * - If it is in manual mode, we need a mapping to temperature |
| 1884 | * channels to use when later setting to automatic mode later. |
| 1885 | * Use a 1:1 mapping by default (we are clueless.) |
| 1886 | * In both cases, the value can (and should) be changed by the user |
| 1887 | * prior to switching to a different mode. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | for (i = 0; i < 3; i++) { |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1889 | data->pwm_temp_map[i] = i; |
| 1890 | data->pwm_duty[i] = 0x7f; /* Full speed */ |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1891 | data->auto_pwm[i][3] = 0x7f; /* Full speed, hard-coded */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1892 | } |
| 1893 | |
Jean Delvare | c5df9b7 | 2006-08-28 14:37:54 +0200 | [diff] [blame] | 1894 | /* Some chips seem to have default value 0xff for all limit |
| 1895 | * registers. For low voltage limits it makes no sense and triggers |
| 1896 | * alarms, so change to 0 instead. For high temperature limits, it |
| 1897 | * means -1 degree C, which surprisingly doesn't trigger an alarm, |
| 1898 | * but is still confusing, so change to 127 degrees C. */ |
| 1899 | for (i = 0; i < 8; i++) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1900 | tmp = it87_read_value(data, IT87_REG_VIN_MIN(i)); |
Jean Delvare | c5df9b7 | 2006-08-28 14:37:54 +0200 | [diff] [blame] | 1901 | if (tmp == 0xff) |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1902 | it87_write_value(data, IT87_REG_VIN_MIN(i), 0); |
Jean Delvare | c5df9b7 | 2006-08-28 14:37:54 +0200 | [diff] [blame] | 1903 | } |
| 1904 | for (i = 0; i < 3; i++) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1905 | tmp = it87_read_value(data, IT87_REG_TEMP_HIGH(i)); |
Jean Delvare | c5df9b7 | 2006-08-28 14:37:54 +0200 | [diff] [blame] | 1906 | if (tmp == 0xff) |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1907 | it87_write_value(data, IT87_REG_TEMP_HIGH(i), 127); |
Jean Delvare | c5df9b7 | 2006-08-28 14:37:54 +0200 | [diff] [blame] | 1908 | } |
| 1909 | |
Jean Delvare | a00afb9 | 2010-04-14 16:14:09 +0200 | [diff] [blame] | 1910 | /* Temperature channels are not forcibly enabled, as they can be |
| 1911 | * set to two different sensor types and we can't guess which one |
| 1912 | * is correct for a given system. These channels can be enabled at |
| 1913 | * run-time through the temp{1-3}_type sysfs accessors if needed. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | |
| 1915 | /* Check if voltage monitors are reset manually or by some reason */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1916 | tmp = it87_read_value(data, IT87_REG_VIN_ENABLE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | if ((tmp & 0xff) == 0) { |
| 1918 | /* Enable all voltage monitors */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1919 | it87_write_value(data, IT87_REG_VIN_ENABLE, 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | } |
| 1921 | |
| 1922 | /* Check if tachometers are reset manually or by some reason */ |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 1923 | mask = 0x70 & ~(sio_data->skip_fan << 4); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1924 | 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] | 1925 | if ((data->fan_main_ctrl & mask) == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | /* Enable all fan tachometers */ |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 1927 | data->fan_main_ctrl |= mask; |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1928 | it87_write_value(data, IT87_REG_FAN_MAIN_CTRL, |
| 1929 | data->fan_main_ctrl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | } |
Jean Delvare | 9060f8b | 2006-08-28 14:24:17 +0200 | [diff] [blame] | 1931 | data->has_fan = (data->fan_main_ctrl >> 4) & 0x07; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 1933 | /* Set tachometers to 16-bit mode if needed */ |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 1934 | if (has_16bit_fans(data)) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1935 | tmp = it87_read_value(data, IT87_REG_FAN_16BIT); |
Jean Delvare | 9060f8b | 2006-08-28 14:24:17 +0200 | [diff] [blame] | 1936 | if (~tmp & 0x07 & data->has_fan) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1937 | dev_dbg(&pdev->dev, |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 1938 | "Setting fan1-3 to 16-bit mode\n"); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1939 | it87_write_value(data, IT87_REG_FAN_16BIT, |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 1940 | tmp | 0x07); |
| 1941 | } |
Andrew Paprocki | 816d8c6 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 1942 | /* IT8705F only supports three fans. */ |
| 1943 | if (data->type != it87) { |
| 1944 | if (tmp & (1 << 4)) |
| 1945 | data->has_fan |= (1 << 3); /* fan4 enabled */ |
| 1946 | if (tmp & (1 << 5)) |
| 1947 | data->has_fan |= (1 << 4); /* fan5 enabled */ |
| 1948 | } |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 1949 | } |
| 1950 | |
Jean Delvare | 591ec65 | 2009-12-09 20:35:48 +0100 | [diff] [blame] | 1951 | /* Fan input pins may be used for alternative functions */ |
| 1952 | data->has_fan &= ~sio_data->skip_fan; |
| 1953 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | /* Start monitoring */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1955 | it87_write_value(data, IT87_REG_CONFIG, |
| 1956 | (it87_read_value(data, IT87_REG_CONFIG) & 0x36) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | | (update_vbat ? 0x41 : 0x01)); |
| 1958 | } |
| 1959 | |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1960 | static void it87_update_pwm_ctrl(struct it87_data *data, int nr) |
| 1961 | { |
| 1962 | data->pwm_ctrl[nr] = it87_read_value(data, IT87_REG_PWM(nr)); |
| 1963 | if (data->pwm_ctrl[nr] & 0x80) /* Automatic mode */ |
| 1964 | data->pwm_temp_map[nr] = data->pwm_ctrl[nr] & 0x03; |
| 1965 | else /* Manual mode */ |
| 1966 | data->pwm_duty[nr] = data->pwm_ctrl[nr] & 0x7f; |
Jean Delvare | 4f3f51b | 2010-03-05 22:17:21 +0100 | [diff] [blame] | 1967 | |
| 1968 | if (has_old_autopwm(data)) { |
| 1969 | int i; |
| 1970 | |
| 1971 | for (i = 0; i < 5 ; i++) |
| 1972 | data->auto_temp[nr][i] = it87_read_value(data, |
| 1973 | IT87_REG_AUTO_TEMP(nr, i)); |
| 1974 | for (i = 0; i < 3 ; i++) |
| 1975 | data->auto_pwm[nr][i] = it87_read_value(data, |
| 1976 | IT87_REG_AUTO_PWM(nr, i)); |
| 1977 | } |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 1978 | } |
| 1979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | static struct it87_data *it87_update_device(struct device *dev) |
| 1981 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1982 | struct it87_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | int i; |
| 1984 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1985 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1986 | |
| 1987 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
| 1988 | || !data->valid) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | if (update_vbat) { |
| 1990 | /* Cleared after each update, so reenable. Value |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1991 | returned by this read will be previous value */ |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 1992 | it87_write_value(data, IT87_REG_CONFIG, |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1993 | it87_read_value(data, IT87_REG_CONFIG) | 0x40); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1994 | } |
| 1995 | for (i = 0; i <= 7; i++) { |
| 1996 | data->in[i] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1997 | it87_read_value(data, IT87_REG_VIN(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | data->in_min[i] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 1999 | it87_read_value(data, IT87_REG_VIN_MIN(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2000 | data->in_max[i] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2001 | it87_read_value(data, IT87_REG_VIN_MAX(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | } |
Jean Delvare | 3543a53 | 2006-08-28 14:27:25 +0200 | [diff] [blame] | 2003 | /* in8 (battery) has no limit registers */ |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2004 | data->in[8] = it87_read_value(data, IT87_REG_VIN(8)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 2006 | for (i = 0; i < 5; i++) { |
Jean Delvare | 9060f8b | 2006-08-28 14:24:17 +0200 | [diff] [blame] | 2007 | /* Skip disabled fans */ |
| 2008 | if (!(data->has_fan & (1 << i))) |
| 2009 | continue; |
| 2010 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | data->fan_min[i] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2012 | it87_read_value(data, IT87_REG_FAN_MIN[i]); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2013 | data->fan[i] = it87_read_value(data, |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 2014 | IT87_REG_FAN[i]); |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2015 | /* Add high byte if in 16-bit mode */ |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 2016 | if (has_16bit_fans(data)) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2017 | data->fan[i] |= it87_read_value(data, |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 2018 | IT87_REG_FANX[i]) << 8; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2019 | data->fan_min[i] |= it87_read_value(data, |
Jean Delvare | c7f1f71 | 2007-09-03 17:11:46 +0200 | [diff] [blame] | 2020 | IT87_REG_FANX_MIN[i]) << 8; |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2021 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2022 | } |
| 2023 | for (i = 0; i < 3; i++) { |
| 2024 | data->temp[i] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2025 | it87_read_value(data, IT87_REG_TEMP(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | data->temp_high[i] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2027 | it87_read_value(data, IT87_REG_TEMP_HIGH(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | data->temp_low[i] = |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2029 | it87_read_value(data, IT87_REG_TEMP_LOW(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | } |
| 2031 | |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2032 | /* Newer chips don't have clock dividers */ |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 2033 | if ((data->has_fan & 0x07) && !has_16bit_fans(data)) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2034 | i = it87_read_value(data, IT87_REG_FAN_DIV); |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2035 | data->fan_div[0] = i & 0x07; |
| 2036 | data->fan_div[1] = (i >> 3) & 0x07; |
| 2037 | data->fan_div[2] = (i & 0x40) ? 3 : 1; |
| 2038 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | |
| 2040 | data->alarms = |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2041 | it87_read_value(data, IT87_REG_ALARM1) | |
| 2042 | (it87_read_value(data, IT87_REG_ALARM2) << 8) | |
| 2043 | (it87_read_value(data, IT87_REG_ALARM3) << 16); |
Jean Delvare | d9b327c | 2010-03-05 22:17:17 +0100 | [diff] [blame] | 2044 | data->beeps = it87_read_value(data, IT87_REG_BEEP_ENABLE); |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 2045 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2046 | data->fan_main_ctrl = it87_read_value(data, |
| 2047 | IT87_REG_FAN_MAIN_CTRL); |
| 2048 | data->fan_ctl = it87_read_value(data, IT87_REG_FAN_CTL); |
Jean Delvare | b99883d | 2010-03-05 22:17:15 +0100 | [diff] [blame] | 2049 | for (i = 0; i < 3; i++) |
| 2050 | it87_update_pwm_ctrl(data, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2052 | data->sensor = it87_read_value(data, IT87_REG_TEMP_ENABLE); |
Andrew Paprocki | 0475169 | 2008-08-06 22:41:06 +0200 | [diff] [blame] | 2053 | /* The 8705 does not have VID capability. |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 2054 | The 8718 and the 8720 don't use IT87_REG_VID for the |
| 2055 | same purpose. */ |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2056 | if (data->type == it8712 || data->type == it8716) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2057 | data->vid = it87_read_value(data, IT87_REG_VID); |
Jean Delvare | 17d648b | 2006-08-28 14:23:46 +0200 | [diff] [blame] | 2058 | /* The older IT8712F revisions had only 5 VID pins, |
| 2059 | but we assume it is always safe to read 6 bits. */ |
| 2060 | data->vid &= 0x3f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2061 | } |
| 2062 | data->last_updated = jiffies; |
| 2063 | data->valid = 1; |
| 2064 | } |
| 2065 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 2066 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | |
| 2068 | return data; |
| 2069 | } |
| 2070 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2071 | static int __init it87_device_add(unsigned short address, |
| 2072 | const struct it87_sio_data *sio_data) |
| 2073 | { |
| 2074 | struct resource res = { |
Bjorn Helgaas | 87b4b66 | 2008-01-22 07:21:03 -0500 | [diff] [blame] | 2075 | .start = address + IT87_EC_OFFSET, |
| 2076 | .end = address + IT87_EC_OFFSET + IT87_EC_EXTENT - 1, |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2077 | .name = DRVNAME, |
| 2078 | .flags = IORESOURCE_IO, |
| 2079 | }; |
| 2080 | int err; |
| 2081 | |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 2082 | err = acpi_check_resource_conflict(&res); |
| 2083 | if (err) |
| 2084 | goto exit; |
| 2085 | |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2086 | pdev = platform_device_alloc(DRVNAME, address); |
| 2087 | if (!pdev) { |
| 2088 | err = -ENOMEM; |
| 2089 | printk(KERN_ERR DRVNAME ": Device allocation failed\n"); |
| 2090 | goto exit; |
| 2091 | } |
| 2092 | |
| 2093 | err = platform_device_add_resources(pdev, &res, 1); |
| 2094 | if (err) { |
| 2095 | printk(KERN_ERR DRVNAME ": Device resource addition failed " |
| 2096 | "(%d)\n", err); |
| 2097 | goto exit_device_put; |
| 2098 | } |
| 2099 | |
| 2100 | err = platform_device_add_data(pdev, sio_data, |
| 2101 | sizeof(struct it87_sio_data)); |
| 2102 | if (err) { |
| 2103 | printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); |
| 2104 | goto exit_device_put; |
| 2105 | } |
| 2106 | |
| 2107 | err = platform_device_add(pdev); |
| 2108 | if (err) { |
| 2109 | printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", |
| 2110 | err); |
| 2111 | goto exit_device_put; |
| 2112 | } |
| 2113 | |
| 2114 | return 0; |
| 2115 | |
| 2116 | exit_device_put: |
| 2117 | platform_device_put(pdev); |
| 2118 | exit: |
| 2119 | return err; |
| 2120 | } |
| 2121 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2122 | static int __init sm_it87_init(void) |
| 2123 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2124 | int err; |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2125 | unsigned short isa_address = 0; |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2126 | struct it87_sio_data sio_data; |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 2127 | |
Jean Delvare | 98dd22c | 2008-10-09 15:33:58 +0200 | [diff] [blame] | 2128 | memset(&sio_data, 0, sizeof(struct it87_sio_data)); |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2129 | err = it87_find(&isa_address, &sio_data); |
| 2130 | if (err) |
| 2131 | return err; |
| 2132 | err = platform_driver_register(&it87_driver); |
| 2133 | if (err) |
| 2134 | return err; |
| 2135 | |
| 2136 | err = it87_device_add(isa_address, &sio_data); |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2137 | if (err) { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2138 | platform_driver_unregister(&it87_driver); |
| 2139 | return err; |
| 2140 | } |
| 2141 | |
| 2142 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
| 2145 | static void __exit sm_it87_exit(void) |
| 2146 | { |
corentin.labbe | b74f3fd | 2007-06-13 20:27:36 +0200 | [diff] [blame] | 2147 | platform_device_unregister(pdev); |
| 2148 | platform_driver_unregister(&it87_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2149 | } |
| 2150 | |
| 2151 | |
Jean Delvare | f1d8e33 | 2007-11-25 16:14:44 +0100 | [diff] [blame] | 2152 | MODULE_AUTHOR("Chris Gauthron, " |
Jean Delvare | b19367c | 2006-08-28 14:39:26 +0200 | [diff] [blame] | 2153 | "Jean Delvare <khali@linux-fr.org>"); |
Jean-Marc Spaggiari | b4da93e | 2009-01-07 16:37:32 +0100 | [diff] [blame] | 2154 | MODULE_DESCRIPTION("IT8705F/8712F/8716F/8718F/8720F/8726F, SiS950 driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2155 | module_param(update_vbat, bool, 0); |
| 2156 | MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); |
| 2157 | module_param(fix_pwm_polarity, bool, 0); |
Jean Delvare | 5f2dc79 | 2010-03-05 22:17:18 +0100 | [diff] [blame] | 2158 | MODULE_PARM_DESC(fix_pwm_polarity, |
| 2159 | "Force PWM polarity to active high (DANGEROUS)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2160 | MODULE_LICENSE("GPL"); |
| 2161 | |
| 2162 | module_init(sm_it87_init); |
| 2163 | module_exit(sm_it87_exit); |