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