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