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