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