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