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