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