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