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