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