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