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