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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | IT8712F Super I/O chip w/LPC interface & SMBus |
| 7 | Sis950 A clone of the IT8705F |
| 8 | |
| 9 | Copyright (C) 2001 Chris Gauthron <chrisg@0-in.com> |
| 10 | Largely inspired by lm78.c of the same package |
| 11 | |
| 12 | This program is free software; you can redistribute it and/or modify |
| 13 | it under the terms of the GNU General Public License as published by |
| 14 | the Free Software Foundation; either version 2 of the License, or |
| 15 | (at your option) any later version. |
| 16 | |
| 17 | This program is distributed in the hope that it will be useful, |
| 18 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | GNU General Public License for more details. |
| 21 | |
| 22 | You should have received a copy of the GNU General Public License |
| 23 | along with this program; if not, write to the Free Software |
| 24 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 | */ |
| 26 | |
| 27 | /* |
| 28 | djg@pdp8.net David Gesswein 7/18/01 |
| 29 | Modified to fix bug with not all alarms enabled. |
| 30 | Added ability to read battery voltage and select temperature sensor |
| 31 | type at module load time. |
| 32 | */ |
| 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <linux/module.h> |
| 35 | #include <linux/init.h> |
| 36 | #include <linux/slab.h> |
| 37 | #include <linux/jiffies.h> |
| 38 | #include <linux/i2c.h> |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 39 | #include <linux/i2c-isa.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 40 | #include <linux/hwmon.h> |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 41 | #include <linux/hwmon-sysfs.h> |
| 42 | #include <linux/hwmon-vid.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 43 | #include <linux/err.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <asm/io.h> |
| 45 | |
| 46 | |
| 47 | /* Addresses to scan */ |
| 48 | static unsigned short normal_i2c[] = { 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, |
| 49 | 0x2e, 0x2f, I2C_CLIENT_END }; |
Jean Delvare | 9174999 | 2005-10-08 00:10:00 +0200 | [diff] [blame] | 50 | static unsigned short isa_address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
| 52 | /* Insmod parameters */ |
Jean Delvare | f4b5026 | 2005-07-31 21:49:03 +0200 | [diff] [blame] | 53 | I2C_CLIENT_INSMOD_2(it87, it8712); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | #define REG 0x2e /* The register to read/write */ |
| 56 | #define DEV 0x07 /* Register: Logical device select */ |
| 57 | #define VAL 0x2f /* The value to read/write */ |
| 58 | #define PME 0x04 /* The device with the fan registers in it */ |
| 59 | #define DEVID 0x20 /* Register: Device ID */ |
| 60 | #define DEVREV 0x22 /* Register: Device Revision */ |
| 61 | |
| 62 | static inline int |
| 63 | superio_inb(int reg) |
| 64 | { |
| 65 | outb(reg, REG); |
| 66 | return inb(VAL); |
| 67 | } |
| 68 | |
| 69 | static int superio_inw(int reg) |
| 70 | { |
| 71 | int val; |
| 72 | outb(reg++, REG); |
| 73 | val = inb(VAL) << 8; |
| 74 | outb(reg, REG); |
| 75 | val |= inb(VAL); |
| 76 | return val; |
| 77 | } |
| 78 | |
| 79 | static inline void |
| 80 | superio_select(void) |
| 81 | { |
| 82 | outb(DEV, REG); |
| 83 | outb(PME, VAL); |
| 84 | } |
| 85 | |
| 86 | static inline void |
| 87 | superio_enter(void) |
| 88 | { |
| 89 | outb(0x87, REG); |
| 90 | outb(0x01, REG); |
| 91 | outb(0x55, REG); |
| 92 | outb(0x55, REG); |
| 93 | } |
| 94 | |
| 95 | static inline void |
| 96 | superio_exit(void) |
| 97 | { |
| 98 | outb(0x02, REG); |
| 99 | outb(0x02, VAL); |
| 100 | } |
| 101 | |
| 102 | #define IT8712F_DEVID 0x8712 |
| 103 | #define IT8705F_DEVID 0x8705 |
| 104 | #define IT87_ACT_REG 0x30 |
| 105 | #define IT87_BASE_REG 0x60 |
| 106 | |
| 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 | |
| 113 | /* Chip Type */ |
| 114 | |
| 115 | static u16 chip_type; |
| 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 | |
| 134 | #define IT87_REG_VID 0x0a |
| 135 | #define IT87_REG_FAN_DIV 0x0b |
| 136 | |
| 137 | /* Monitors: 9 voltage (0 to 7, battery), 3 temp (1 to 3), 3 fan (1 to 3) */ |
| 138 | |
| 139 | #define IT87_REG_FAN(nr) (0x0d + (nr)) |
| 140 | #define IT87_REG_FAN_MIN(nr) (0x10 + (nr)) |
| 141 | #define IT87_REG_FAN_MAIN_CTRL 0x13 |
| 142 | #define IT87_REG_FAN_CTL 0x14 |
| 143 | #define IT87_REG_PWM(nr) (0x15 + (nr)) |
| 144 | |
| 145 | #define IT87_REG_VIN(nr) (0x20 + (nr)) |
| 146 | #define IT87_REG_TEMP(nr) (0x29 + (nr)) |
| 147 | |
| 148 | #define IT87_REG_VIN_MAX(nr) (0x30 + (nr) * 2) |
| 149 | #define IT87_REG_VIN_MIN(nr) (0x31 + (nr) * 2) |
| 150 | #define IT87_REG_TEMP_HIGH(nr) (0x40 + (nr) * 2) |
| 151 | #define IT87_REG_TEMP_LOW(nr) (0x41 + (nr) * 2) |
| 152 | |
| 153 | #define IT87_REG_I2C_ADDR 0x48 |
| 154 | |
| 155 | #define IT87_REG_VIN_ENABLE 0x50 |
| 156 | #define IT87_REG_TEMP_ENABLE 0x51 |
| 157 | |
| 158 | #define IT87_REG_CHIPID 0x58 |
| 159 | |
| 160 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255)) |
| 161 | #define IN_FROM_REG(val) ((val) * 16) |
| 162 | |
| 163 | static inline u8 FAN_TO_REG(long rpm, int div) |
| 164 | { |
| 165 | if (rpm == 0) |
| 166 | return 255; |
| 167 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); |
| 168 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, |
| 169 | 254); |
| 170 | } |
| 171 | |
| 172 | #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) |
| 173 | |
| 174 | #define TEMP_TO_REG(val) (SENSORS_LIMIT(((val)<0?(((val)-500)/1000):\ |
| 175 | ((val)+500)/1000),-128,127)) |
| 176 | #define TEMP_FROM_REG(val) (((val)>0x80?(val)-0x100:(val))*1000) |
| 177 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | #define PWM_TO_REG(val) ((val) >> 1) |
| 179 | #define PWM_FROM_REG(val) (((val)&0x7f) << 1) |
| 180 | |
| 181 | static int DIV_TO_REG(int val) |
| 182 | { |
| 183 | int answer = 0; |
| 184 | while ((val >>= 1) != 0) |
| 185 | answer++; |
| 186 | return answer; |
| 187 | } |
| 188 | #define DIV_FROM_REG(val) (1 << (val)) |
| 189 | |
| 190 | |
| 191 | /* For each registered IT87, we need to keep some data in memory. That |
| 192 | data is pointed to by it87_list[NR]->data. The structure itself is |
| 193 | dynamically allocated, at the same time when a new it87 client is |
| 194 | allocated. */ |
| 195 | struct it87_data { |
| 196 | struct i2c_client client; |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 197 | struct class_device *class_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | struct semaphore lock; |
| 199 | enum chips type; |
| 200 | |
| 201 | struct semaphore update_lock; |
| 202 | char valid; /* !=0 if following fields are valid */ |
| 203 | unsigned long last_updated; /* In jiffies */ |
| 204 | |
| 205 | u8 in[9]; /* Register value */ |
| 206 | u8 in_max[9]; /* Register value */ |
| 207 | u8 in_min[9]; /* Register value */ |
| 208 | u8 fan[3]; /* Register value */ |
| 209 | u8 fan_min[3]; /* Register value */ |
| 210 | u8 temp[3]; /* Register value */ |
| 211 | u8 temp_high[3]; /* Register value */ |
| 212 | u8 temp_low[3]; /* Register value */ |
| 213 | u8 sensor; /* Register value */ |
| 214 | u8 fan_div[3]; /* Register encoding, shifted right */ |
| 215 | u8 vid; /* Register encoding, combined */ |
| 216 | int vrm; |
| 217 | u32 alarms; /* Register encoding, combined */ |
| 218 | u8 fan_main_ctrl; /* Register value */ |
| 219 | u8 manual_pwm_ctl[3]; /* manual PWM value set by user */ |
| 220 | }; |
| 221 | |
| 222 | |
| 223 | static int it87_attach_adapter(struct i2c_adapter *adapter); |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 224 | static int it87_isa_attach_adapter(struct i2c_adapter *adapter); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | static int it87_detect(struct i2c_adapter *adapter, int address, int kind); |
| 226 | static int it87_detach_client(struct i2c_client *client); |
| 227 | |
| 228 | static int it87_read_value(struct i2c_client *client, u8 register); |
| 229 | static int it87_write_value(struct i2c_client *client, u8 register, |
| 230 | u8 value); |
| 231 | static struct it87_data *it87_update_device(struct device *dev); |
| 232 | static int it87_check_pwm(struct i2c_client *client); |
| 233 | static void it87_init_client(struct i2c_client *client, struct it87_data *data); |
| 234 | |
| 235 | |
| 236 | static struct i2c_driver it87_driver = { |
| 237 | .owner = THIS_MODULE, |
| 238 | .name = "it87", |
| 239 | .id = I2C_DRIVERID_IT87, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | .attach_adapter = it87_attach_adapter, |
| 241 | .detach_client = it87_detach_client, |
| 242 | }; |
| 243 | |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 244 | static struct i2c_driver it87_isa_driver = { |
| 245 | .owner = THIS_MODULE, |
| 246 | .name = "it87-isa", |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 247 | .attach_adapter = it87_isa_attach_adapter, |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 248 | .detach_client = it87_detach_client, |
| 249 | }; |
| 250 | |
| 251 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 252 | static ssize_t show_in(struct device *dev, struct device_attribute *attr, |
| 253 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 255 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 256 | int nr = sensor_attr->index; |
| 257 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | struct it87_data *data = it87_update_device(dev); |
| 259 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in[nr])); |
| 260 | } |
| 261 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 262 | static ssize_t show_in_min(struct device *dev, struct device_attribute *attr, |
| 263 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 265 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 266 | int nr = sensor_attr->index; |
| 267 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | struct it87_data *data = it87_update_device(dev); |
| 269 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_min[nr])); |
| 270 | } |
| 271 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 272 | static ssize_t show_in_max(struct device *dev, struct device_attribute *attr, |
| 273 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 275 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 276 | int nr = sensor_attr->index; |
| 277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | struct it87_data *data = it87_update_device(dev); |
| 279 | return sprintf(buf, "%d\n", IN_FROM_REG(data->in_max[nr])); |
| 280 | } |
| 281 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 282 | static ssize_t set_in_min(struct device *dev, struct device_attribute *attr, |
| 283 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 285 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 286 | int nr = sensor_attr->index; |
| 287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | struct i2c_client *client = to_i2c_client(dev); |
| 289 | struct it87_data *data = i2c_get_clientdata(client); |
| 290 | unsigned long val = simple_strtoul(buf, NULL, 10); |
| 291 | |
| 292 | down(&data->update_lock); |
| 293 | data->in_min[nr] = IN_TO_REG(val); |
| 294 | it87_write_value(client, IT87_REG_VIN_MIN(nr), |
| 295 | data->in_min[nr]); |
| 296 | up(&data->update_lock); |
| 297 | return count; |
| 298 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 299 | static ssize_t set_in_max(struct device *dev, struct device_attribute *attr, |
| 300 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 302 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 303 | int nr = sensor_attr->index; |
| 304 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | struct i2c_client *client = to_i2c_client(dev); |
| 306 | struct it87_data *data = i2c_get_clientdata(client); |
| 307 | unsigned long val = simple_strtoul(buf, NULL, 10); |
| 308 | |
| 309 | down(&data->update_lock); |
| 310 | data->in_max[nr] = IN_TO_REG(val); |
| 311 | it87_write_value(client, IT87_REG_VIN_MAX(nr), |
| 312 | data->in_max[nr]); |
| 313 | up(&data->update_lock); |
| 314 | return count; |
| 315 | } |
| 316 | |
| 317 | #define show_in_offset(offset) \ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 318 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
| 319 | show_in, NULL, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | |
| 321 | #define limit_in_offset(offset) \ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 322 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO | S_IWUSR, \ |
| 323 | show_in_min, set_in_min, offset); \ |
| 324 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO | S_IWUSR, \ |
| 325 | show_in_max, set_in_max, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | |
| 327 | show_in_offset(0); |
| 328 | limit_in_offset(0); |
| 329 | show_in_offset(1); |
| 330 | limit_in_offset(1); |
| 331 | show_in_offset(2); |
| 332 | limit_in_offset(2); |
| 333 | show_in_offset(3); |
| 334 | limit_in_offset(3); |
| 335 | show_in_offset(4); |
| 336 | limit_in_offset(4); |
| 337 | show_in_offset(5); |
| 338 | limit_in_offset(5); |
| 339 | show_in_offset(6); |
| 340 | limit_in_offset(6); |
| 341 | show_in_offset(7); |
| 342 | limit_in_offset(7); |
| 343 | show_in_offset(8); |
| 344 | |
| 345 | /* 3 temperatures */ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 346 | static ssize_t show_temp(struct device *dev, struct device_attribute *attr, |
| 347 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 349 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 350 | int nr = sensor_attr->index; |
| 351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | struct it87_data *data = it87_update_device(dev); |
| 353 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[nr])); |
| 354 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 355 | static ssize_t show_temp_max(struct device *dev, struct device_attribute *attr, |
| 356 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 358 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 359 | int nr = sensor_attr->index; |
| 360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | struct it87_data *data = it87_update_device(dev); |
| 362 | return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_high[nr])); |
| 363 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 364 | static ssize_t show_temp_min(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_low[nr])); |
| 372 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 373 | static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr, |
| 374 | const char *buf, size_t count) |
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 i2c_client *client = to_i2c_client(dev); |
| 380 | struct it87_data *data = i2c_get_clientdata(client); |
| 381 | int val = simple_strtol(buf, NULL, 10); |
| 382 | |
| 383 | down(&data->update_lock); |
| 384 | data->temp_high[nr] = TEMP_TO_REG(val); |
| 385 | it87_write_value(client, IT87_REG_TEMP_HIGH(nr), data->temp_high[nr]); |
| 386 | up(&data->update_lock); |
| 387 | return count; |
| 388 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 389 | static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr, |
| 390 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 392 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 393 | int nr = sensor_attr->index; |
| 394 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | struct i2c_client *client = to_i2c_client(dev); |
| 396 | struct it87_data *data = i2c_get_clientdata(client); |
| 397 | int val = simple_strtol(buf, NULL, 10); |
| 398 | |
| 399 | down(&data->update_lock); |
| 400 | data->temp_low[nr] = TEMP_TO_REG(val); |
| 401 | it87_write_value(client, IT87_REG_TEMP_LOW(nr), data->temp_low[nr]); |
| 402 | up(&data->update_lock); |
| 403 | return count; |
| 404 | } |
| 405 | #define show_temp_offset(offset) \ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 406 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
| 407 | show_temp, NULL, offset - 1); \ |
| 408 | static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO | S_IWUSR, \ |
| 409 | show_temp_max, set_temp_max, offset - 1); \ |
| 410 | static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IRUGO | S_IWUSR, \ |
| 411 | show_temp_min, set_temp_min, offset - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
| 413 | show_temp_offset(1); |
| 414 | show_temp_offset(2); |
| 415 | show_temp_offset(3); |
| 416 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 417 | static ssize_t show_sensor(struct device *dev, struct device_attribute *attr, |
| 418 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 420 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 421 | int nr = sensor_attr->index; |
| 422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | struct it87_data *data = it87_update_device(dev); |
| 424 | u8 reg = data->sensor; /* In case the value is updated while we use it */ |
| 425 | |
| 426 | if (reg & (1 << nr)) |
| 427 | return sprintf(buf, "3\n"); /* thermal diode */ |
| 428 | if (reg & (8 << nr)) |
| 429 | return sprintf(buf, "2\n"); /* thermistor */ |
| 430 | return sprintf(buf, "0\n"); /* disabled */ |
| 431 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 432 | static ssize_t set_sensor(struct device *dev, struct device_attribute *attr, |
| 433 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 435 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 436 | int nr = sensor_attr->index; |
| 437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | struct i2c_client *client = to_i2c_client(dev); |
| 439 | struct it87_data *data = i2c_get_clientdata(client); |
| 440 | int val = simple_strtol(buf, NULL, 10); |
| 441 | |
| 442 | down(&data->update_lock); |
| 443 | |
| 444 | data->sensor &= ~(1 << nr); |
| 445 | data->sensor &= ~(8 << nr); |
| 446 | /* 3 = thermal diode; 2 = thermistor; 0 = disabled */ |
| 447 | if (val == 3) |
| 448 | data->sensor |= 1 << nr; |
| 449 | else if (val == 2) |
| 450 | data->sensor |= 8 << nr; |
| 451 | else if (val != 0) { |
| 452 | up(&data->update_lock); |
| 453 | return -EINVAL; |
| 454 | } |
| 455 | it87_write_value(client, IT87_REG_TEMP_ENABLE, data->sensor); |
| 456 | up(&data->update_lock); |
| 457 | return count; |
| 458 | } |
| 459 | #define show_sensor_offset(offset) \ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 460 | static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \ |
| 461 | show_sensor, set_sensor, offset - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
| 463 | show_sensor_offset(1); |
| 464 | show_sensor_offset(2); |
| 465 | show_sensor_offset(3); |
| 466 | |
| 467 | /* 3 Fans */ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 468 | static ssize_t show_fan(struct device *dev, struct device_attribute *attr, |
| 469 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 471 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 472 | int nr = sensor_attr->index; |
| 473 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | struct it87_data *data = it87_update_device(dev); |
| 475 | return sprintf(buf,"%d\n", FAN_FROM_REG(data->fan[nr], |
| 476 | DIV_FROM_REG(data->fan_div[nr]))); |
| 477 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 478 | static ssize_t show_fan_min(struct device *dev, struct device_attribute *attr, |
| 479 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 481 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 482 | int nr = sensor_attr->index; |
| 483 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | struct it87_data *data = it87_update_device(dev); |
| 485 | return sprintf(buf,"%d\n", |
| 486 | FAN_FROM_REG(data->fan_min[nr], DIV_FROM_REG(data->fan_div[nr]))); |
| 487 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 488 | static ssize_t show_fan_div(struct device *dev, struct device_attribute *attr, |
| 489 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 491 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 492 | int nr = sensor_attr->index; |
| 493 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | struct it87_data *data = it87_update_device(dev); |
| 495 | return sprintf(buf, "%d\n", DIV_FROM_REG(data->fan_div[nr])); |
| 496 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 497 | static ssize_t show_pwm_enable(struct device *dev, struct device_attribute *attr, |
| 498 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 500 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 501 | int nr = sensor_attr->index; |
| 502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | struct it87_data *data = it87_update_device(dev); |
| 504 | return sprintf(buf,"%d\n", (data->fan_main_ctrl & (1 << nr)) ? 1 : 0); |
| 505 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 506 | static ssize_t show_pwm(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", data->manual_pwm_ctl[nr]); |
| 514 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 515 | static ssize_t set_fan_min(struct device *dev, struct device_attribute *attr, |
| 516 | const char *buf, size_t count) |
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 i2c_client *client = to_i2c_client(dev); |
| 522 | struct it87_data *data = i2c_get_clientdata(client); |
| 523 | int val = simple_strtol(buf, NULL, 10); |
Jean Delvare | 07eab46 | 2005-11-23 15:44:31 -0800 | [diff] [blame] | 524 | u8 reg = it87_read_value(client, IT87_REG_FAN_DIV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
| 526 | down(&data->update_lock); |
Jean Delvare | 07eab46 | 2005-11-23 15:44:31 -0800 | [diff] [blame] | 527 | switch (nr) { |
| 528 | case 0: data->fan_div[nr] = reg & 0x07; break; |
| 529 | case 1: data->fan_div[nr] = (reg >> 3) & 0x07; break; |
| 530 | case 2: data->fan_div[nr] = (reg & 0x40) ? 3 : 1; break; |
| 531 | } |
| 532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
| 534 | it87_write_value(client, IT87_REG_FAN_MIN(nr), data->fan_min[nr]); |
| 535 | up(&data->update_lock); |
| 536 | return count; |
| 537 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 538 | static ssize_t set_fan_div(struct device *dev, struct device_attribute *attr, |
| 539 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 541 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 542 | int nr = sensor_attr->index; |
| 543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | struct i2c_client *client = to_i2c_client(dev); |
| 545 | struct it87_data *data = i2c_get_clientdata(client); |
| 546 | int val = simple_strtol(buf, NULL, 10); |
| 547 | int i, min[3]; |
| 548 | u8 old; |
| 549 | |
| 550 | down(&data->update_lock); |
| 551 | old = it87_read_value(client, IT87_REG_FAN_DIV); |
| 552 | |
| 553 | for (i = 0; i < 3; i++) |
| 554 | min[i] = FAN_FROM_REG(data->fan_min[i], DIV_FROM_REG(data->fan_div[i])); |
| 555 | |
| 556 | switch (nr) { |
| 557 | case 0: |
| 558 | case 1: |
| 559 | data->fan_div[nr] = DIV_TO_REG(val); |
| 560 | break; |
| 561 | case 2: |
| 562 | if (val < 8) |
| 563 | data->fan_div[nr] = 1; |
| 564 | else |
| 565 | data->fan_div[nr] = 3; |
| 566 | } |
| 567 | val = old & 0x80; |
| 568 | val |= (data->fan_div[0] & 0x07); |
| 569 | val |= (data->fan_div[1] & 0x07) << 3; |
| 570 | if (data->fan_div[2] == 3) |
| 571 | val |= 0x1 << 6; |
| 572 | it87_write_value(client, IT87_REG_FAN_DIV, val); |
| 573 | |
| 574 | for (i = 0; i < 3; i++) { |
| 575 | data->fan_min[i]=FAN_TO_REG(min[i], DIV_FROM_REG(data->fan_div[i])); |
| 576 | it87_write_value(client, IT87_REG_FAN_MIN(i), data->fan_min[i]); |
| 577 | } |
| 578 | up(&data->update_lock); |
| 579 | return count; |
| 580 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 581 | static ssize_t set_pwm_enable(struct device *dev, |
| 582 | struct device_attribute *attr, const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 584 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 585 | int nr = sensor_attr->index; |
| 586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | struct i2c_client *client = to_i2c_client(dev); |
| 588 | struct it87_data *data = i2c_get_clientdata(client); |
| 589 | int val = simple_strtol(buf, NULL, 10); |
| 590 | |
| 591 | down(&data->update_lock); |
| 592 | |
| 593 | if (val == 0) { |
| 594 | int tmp; |
| 595 | /* make sure the fan is on when in on/off mode */ |
| 596 | tmp = it87_read_value(client, IT87_REG_FAN_CTL); |
| 597 | it87_write_value(client, IT87_REG_FAN_CTL, tmp | (1 << nr)); |
| 598 | /* set on/off mode */ |
| 599 | data->fan_main_ctrl &= ~(1 << nr); |
| 600 | it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); |
| 601 | } else if (val == 1) { |
| 602 | /* set SmartGuardian mode */ |
| 603 | data->fan_main_ctrl |= (1 << nr); |
| 604 | it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); |
| 605 | /* set saved pwm value, clear FAN_CTLX PWM mode bit */ |
| 606 | it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); |
| 607 | } else { |
| 608 | up(&data->update_lock); |
| 609 | return -EINVAL; |
| 610 | } |
| 611 | |
| 612 | up(&data->update_lock); |
| 613 | return count; |
| 614 | } |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 615 | static ssize_t set_pwm(struct device *dev, struct device_attribute *attr, |
| 616 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 618 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 619 | int nr = sensor_attr->index; |
| 620 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | struct i2c_client *client = to_i2c_client(dev); |
| 622 | struct it87_data *data = i2c_get_clientdata(client); |
| 623 | int val = simple_strtol(buf, NULL, 10); |
| 624 | |
| 625 | if (val < 0 || val > 255) |
| 626 | return -EINVAL; |
| 627 | |
| 628 | down(&data->update_lock); |
| 629 | data->manual_pwm_ctl[nr] = val; |
| 630 | if (data->fan_main_ctrl & (1 << nr)) |
| 631 | it87_write_value(client, IT87_REG_PWM(nr), PWM_TO_REG(data->manual_pwm_ctl[nr])); |
| 632 | up(&data->update_lock); |
| 633 | return count; |
| 634 | } |
| 635 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 636 | #define show_fan_offset(offset) \ |
| 637 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
| 638 | show_fan, NULL, offset - 1); \ |
| 639 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
| 640 | show_fan_min, set_fan_min, offset - 1); \ |
| 641 | static SENSOR_DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ |
| 642 | show_fan_div, set_fan_div, offset - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
| 644 | show_fan_offset(1); |
| 645 | show_fan_offset(2); |
| 646 | show_fan_offset(3); |
| 647 | |
| 648 | #define show_pwm_offset(offset) \ |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 649 | static SENSOR_DEVICE_ATTR(pwm##offset##_enable, S_IRUGO | S_IWUSR, \ |
| 650 | show_pwm_enable, set_pwm_enable, offset - 1); \ |
| 651 | static SENSOR_DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ |
| 652 | show_pwm, set_pwm, offset - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | |
| 654 | show_pwm_offset(1); |
| 655 | show_pwm_offset(2); |
| 656 | show_pwm_offset(3); |
| 657 | |
| 658 | /* Alarms */ |
Yani Ioannou | 30f7429 | 2005-05-17 06:41:35 -0400 | [diff] [blame] | 659 | 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] | 660 | { |
| 661 | struct it87_data *data = it87_update_device(dev); |
Jean Delvare | 68188ba | 2005-05-16 18:52:38 +0200 | [diff] [blame] | 662 | return sprintf(buf, "%u\n", data->alarms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | } |
Jean Delvare | 1d66c64 | 2005-04-18 21:16:59 -0700 | [diff] [blame] | 664 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | |
| 666 | static ssize_t |
Yani Ioannou | 30f7429 | 2005-05-17 06:41:35 -0400 | [diff] [blame] | 667 | show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | { |
| 669 | struct it87_data *data = it87_update_device(dev); |
| 670 | return sprintf(buf, "%ld\n", (long) data->vrm); |
| 671 | } |
| 672 | static ssize_t |
Yani Ioannou | 30f7429 | 2005-05-17 06:41:35 -0400 | [diff] [blame] | 673 | 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] | 674 | { |
| 675 | struct i2c_client *client = to_i2c_client(dev); |
| 676 | struct it87_data *data = i2c_get_clientdata(client); |
| 677 | u32 val; |
| 678 | |
| 679 | val = simple_strtoul(buf, NULL, 10); |
| 680 | data->vrm = val; |
| 681 | |
| 682 | return count; |
| 683 | } |
| 684 | static DEVICE_ATTR(vrm, S_IRUGO | S_IWUSR, show_vrm_reg, store_vrm_reg); |
| 685 | #define device_create_file_vrm(client) \ |
| 686 | device_create_file(&client->dev, &dev_attr_vrm) |
| 687 | |
| 688 | static ssize_t |
Yani Ioannou | 30f7429 | 2005-05-17 06:41:35 -0400 | [diff] [blame] | 689 | show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | { |
| 691 | struct it87_data *data = it87_update_device(dev); |
| 692 | return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); |
| 693 | } |
| 694 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); |
| 695 | #define device_create_file_vid(client) \ |
| 696 | device_create_file(&client->dev, &dev_attr_cpu0_vid) |
| 697 | |
| 698 | /* This function is called when: |
| 699 | * it87_driver is inserted (when this module is loaded), for each |
| 700 | available adapter |
| 701 | * when a new adapter is inserted (and it87_driver is still present) */ |
| 702 | static int it87_attach_adapter(struct i2c_adapter *adapter) |
| 703 | { |
| 704 | if (!(adapter->class & I2C_CLASS_HWMON)) |
| 705 | return 0; |
Jean Delvare | 2ed2dc3 | 2005-07-31 21:42:02 +0200 | [diff] [blame] | 706 | return i2c_probe(adapter, &addr_data, it87_detect); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | } |
| 708 | |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 709 | static int it87_isa_attach_adapter(struct i2c_adapter *adapter) |
| 710 | { |
| 711 | return it87_detect(adapter, isa_address, -1); |
| 712 | } |
| 713 | |
| 714 | /* SuperIO detection - will change isa_address if a chip is found */ |
Jean Delvare | 9174999 | 2005-10-08 00:10:00 +0200 | [diff] [blame] | 715 | static int __init it87_find(unsigned short *address) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | { |
| 717 | int err = -ENODEV; |
| 718 | |
| 719 | superio_enter(); |
| 720 | chip_type = superio_inw(DEVID); |
| 721 | if (chip_type != IT8712F_DEVID |
| 722 | && chip_type != IT8705F_DEVID) |
| 723 | goto exit; |
| 724 | |
| 725 | superio_select(); |
| 726 | if (!(superio_inb(IT87_ACT_REG) & 0x01)) { |
| 727 | pr_info("it87: Device not activated, skipping\n"); |
| 728 | goto exit; |
| 729 | } |
| 730 | |
| 731 | *address = superio_inw(IT87_BASE_REG) & ~(IT87_EXTENT - 1); |
| 732 | if (*address == 0) { |
| 733 | pr_info("it87: Base address not set, skipping\n"); |
| 734 | goto exit; |
| 735 | } |
| 736 | |
| 737 | err = 0; |
| 738 | pr_info("it87: Found IT%04xF chip at 0x%x, revision %d\n", |
| 739 | chip_type, *address, superio_inb(DEVREV) & 0x0f); |
| 740 | |
| 741 | exit: |
| 742 | superio_exit(); |
| 743 | return err; |
| 744 | } |
| 745 | |
Jean Delvare | 2ed2dc3 | 2005-07-31 21:42:02 +0200 | [diff] [blame] | 746 | /* This function is called by i2c_probe */ |
Ben Dooks | c49efce | 2005-10-26 21:07:25 +0200 | [diff] [blame] | 747 | static int it87_detect(struct i2c_adapter *adapter, int address, int kind) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | { |
| 749 | int i; |
| 750 | struct i2c_client *new_client; |
| 751 | struct it87_data *data; |
| 752 | int err = 0; |
| 753 | const char *name = ""; |
| 754 | int is_isa = i2c_is_isa_adapter(adapter); |
| 755 | int enable_pwm_interface; |
| 756 | |
| 757 | if (!is_isa && |
| 758 | !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
| 759 | goto ERROR0; |
| 760 | |
| 761 | /* Reserve the ISA region */ |
| 762 | if (is_isa) |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 763 | if (!request_region(address, IT87_EXTENT, it87_isa_driver.name)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | goto ERROR0; |
| 765 | |
Jean Delvare | 9174999 | 2005-10-08 00:10:00 +0200 | [diff] [blame] | 766 | /* For now, we presume we have a valid client. We create the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | client structure, even though we cannot fill it completely yet. |
| 768 | But it allows us to access it87_{read,write}_value. */ |
| 769 | |
Deepak Saxena | ba9c2e8 | 2005-10-17 23:08:32 +0200 | [diff] [blame] | 770 | if (!(data = kzalloc(sizeof(struct it87_data), GFP_KERNEL))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | err = -ENOMEM; |
| 772 | goto ERROR1; |
| 773 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
| 775 | new_client = &data->client; |
| 776 | if (is_isa) |
| 777 | init_MUTEX(&data->lock); |
| 778 | i2c_set_clientdata(new_client, data); |
| 779 | new_client->addr = address; |
| 780 | new_client->adapter = adapter; |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 781 | new_client->driver = is_isa ? &it87_isa_driver : &it87_driver; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | new_client->flags = 0; |
| 783 | |
| 784 | /* Now, we do the remaining detection. */ |
| 785 | |
| 786 | if (kind < 0) { |
| 787 | if ((it87_read_value(new_client, IT87_REG_CONFIG) & 0x80) |
| 788 | || (!is_isa |
| 789 | && it87_read_value(new_client, IT87_REG_I2C_ADDR) != address)) { |
| 790 | err = -ENODEV; |
| 791 | goto ERROR2; |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | /* Determine the chip type. */ |
| 796 | if (kind <= 0) { |
| 797 | i = it87_read_value(new_client, IT87_REG_CHIPID); |
| 798 | if (i == 0x90) { |
| 799 | kind = it87; |
| 800 | if ((is_isa) && (chip_type == IT8712F_DEVID)) |
| 801 | kind = it8712; |
| 802 | } |
| 803 | else { |
| 804 | if (kind == 0) |
| 805 | dev_info(&adapter->dev, |
| 806 | "Ignoring 'force' parameter for unknown chip at " |
| 807 | "adapter %d, address 0x%02x\n", |
| 808 | i2c_adapter_id(adapter), address); |
| 809 | err = -ENODEV; |
| 810 | goto ERROR2; |
| 811 | } |
| 812 | } |
| 813 | |
| 814 | if (kind == it87) { |
| 815 | name = "it87"; |
| 816 | } else if (kind == it8712) { |
| 817 | name = "it8712"; |
| 818 | } |
| 819 | |
| 820 | /* Fill in the remaining client fields and put it into the global list */ |
| 821 | strlcpy(new_client->name, name, I2C_NAME_SIZE); |
| 822 | data->type = kind; |
| 823 | data->valid = 0; |
| 824 | init_MUTEX(&data->update_lock); |
| 825 | |
| 826 | /* Tell the I2C layer a new client has arrived */ |
| 827 | if ((err = i2c_attach_client(new_client))) |
| 828 | goto ERROR2; |
| 829 | |
| 830 | /* Check PWM configuration */ |
| 831 | enable_pwm_interface = it87_check_pwm(new_client); |
| 832 | |
| 833 | /* Initialize the IT87 chip */ |
| 834 | it87_init_client(new_client, data); |
| 835 | |
| 836 | /* Register sysfs hooks */ |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 837 | data->class_dev = hwmon_device_register(&new_client->dev); |
| 838 | if (IS_ERR(data->class_dev)) { |
| 839 | err = PTR_ERR(data->class_dev); |
| 840 | goto ERROR3; |
| 841 | } |
| 842 | |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 843 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_input.dev_attr); |
| 844 | device_create_file(&new_client->dev, &sensor_dev_attr_in1_input.dev_attr); |
| 845 | device_create_file(&new_client->dev, &sensor_dev_attr_in2_input.dev_attr); |
| 846 | device_create_file(&new_client->dev, &sensor_dev_attr_in3_input.dev_attr); |
| 847 | device_create_file(&new_client->dev, &sensor_dev_attr_in4_input.dev_attr); |
| 848 | device_create_file(&new_client->dev, &sensor_dev_attr_in5_input.dev_attr); |
| 849 | device_create_file(&new_client->dev, &sensor_dev_attr_in6_input.dev_attr); |
| 850 | device_create_file(&new_client->dev, &sensor_dev_attr_in7_input.dev_attr); |
| 851 | device_create_file(&new_client->dev, &sensor_dev_attr_in8_input.dev_attr); |
| 852 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_min.dev_attr); |
| 853 | device_create_file(&new_client->dev, &sensor_dev_attr_in1_min.dev_attr); |
| 854 | device_create_file(&new_client->dev, &sensor_dev_attr_in2_min.dev_attr); |
| 855 | device_create_file(&new_client->dev, &sensor_dev_attr_in3_min.dev_attr); |
| 856 | device_create_file(&new_client->dev, &sensor_dev_attr_in4_min.dev_attr); |
| 857 | device_create_file(&new_client->dev, &sensor_dev_attr_in5_min.dev_attr); |
| 858 | device_create_file(&new_client->dev, &sensor_dev_attr_in6_min.dev_attr); |
| 859 | device_create_file(&new_client->dev, &sensor_dev_attr_in7_min.dev_attr); |
| 860 | device_create_file(&new_client->dev, &sensor_dev_attr_in0_max.dev_attr); |
| 861 | device_create_file(&new_client->dev, &sensor_dev_attr_in1_max.dev_attr); |
| 862 | device_create_file(&new_client->dev, &sensor_dev_attr_in2_max.dev_attr); |
| 863 | device_create_file(&new_client->dev, &sensor_dev_attr_in3_max.dev_attr); |
| 864 | device_create_file(&new_client->dev, &sensor_dev_attr_in4_max.dev_attr); |
| 865 | device_create_file(&new_client->dev, &sensor_dev_attr_in5_max.dev_attr); |
| 866 | device_create_file(&new_client->dev, &sensor_dev_attr_in6_max.dev_attr); |
| 867 | device_create_file(&new_client->dev, &sensor_dev_attr_in7_max.dev_attr); |
| 868 | device_create_file(&new_client->dev, &sensor_dev_attr_temp1_input.dev_attr); |
| 869 | device_create_file(&new_client->dev, &sensor_dev_attr_temp2_input.dev_attr); |
| 870 | device_create_file(&new_client->dev, &sensor_dev_attr_temp3_input.dev_attr); |
| 871 | device_create_file(&new_client->dev, &sensor_dev_attr_temp1_max.dev_attr); |
| 872 | device_create_file(&new_client->dev, &sensor_dev_attr_temp2_max.dev_attr); |
| 873 | device_create_file(&new_client->dev, &sensor_dev_attr_temp3_max.dev_attr); |
| 874 | device_create_file(&new_client->dev, &sensor_dev_attr_temp1_min.dev_attr); |
| 875 | device_create_file(&new_client->dev, &sensor_dev_attr_temp2_min.dev_attr); |
| 876 | device_create_file(&new_client->dev, &sensor_dev_attr_temp3_min.dev_attr); |
| 877 | device_create_file(&new_client->dev, &sensor_dev_attr_temp1_type.dev_attr); |
| 878 | device_create_file(&new_client->dev, &sensor_dev_attr_temp2_type.dev_attr); |
| 879 | device_create_file(&new_client->dev, &sensor_dev_attr_temp3_type.dev_attr); |
| 880 | device_create_file(&new_client->dev, &sensor_dev_attr_fan1_input.dev_attr); |
| 881 | device_create_file(&new_client->dev, &sensor_dev_attr_fan2_input.dev_attr); |
| 882 | device_create_file(&new_client->dev, &sensor_dev_attr_fan3_input.dev_attr); |
| 883 | device_create_file(&new_client->dev, &sensor_dev_attr_fan1_min.dev_attr); |
| 884 | device_create_file(&new_client->dev, &sensor_dev_attr_fan2_min.dev_attr); |
| 885 | device_create_file(&new_client->dev, &sensor_dev_attr_fan3_min.dev_attr); |
| 886 | device_create_file(&new_client->dev, &sensor_dev_attr_fan1_div.dev_attr); |
| 887 | device_create_file(&new_client->dev, &sensor_dev_attr_fan2_div.dev_attr); |
| 888 | device_create_file(&new_client->dev, &sensor_dev_attr_fan3_div.dev_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | device_create_file(&new_client->dev, &dev_attr_alarms); |
| 890 | if (enable_pwm_interface) { |
Jean Delvare | 20ad93d | 2005-06-05 11:53:25 +0200 | [diff] [blame] | 891 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm1_enable.dev_attr); |
| 892 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm2_enable.dev_attr); |
| 893 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm3_enable.dev_attr); |
| 894 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm1.dev_attr); |
| 895 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm2.dev_attr); |
| 896 | device_create_file(&new_client->dev, &sensor_dev_attr_pwm3.dev_attr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 897 | } |
| 898 | |
| 899 | if (data->type == it8712) { |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 900 | data->vrm = vid_which_vrm(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | device_create_file_vrm(new_client); |
| 902 | device_create_file_vid(new_client); |
| 903 | } |
| 904 | |
| 905 | return 0; |
| 906 | |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 907 | ERROR3: |
| 908 | i2c_detach_client(new_client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | ERROR2: |
| 910 | kfree(data); |
| 911 | ERROR1: |
| 912 | if (is_isa) |
| 913 | release_region(address, IT87_EXTENT); |
| 914 | ERROR0: |
| 915 | return err; |
| 916 | } |
| 917 | |
| 918 | static int it87_detach_client(struct i2c_client *client) |
| 919 | { |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 920 | struct it87_data *data = i2c_get_clientdata(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | int err; |
| 922 | |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 923 | hwmon_device_unregister(data->class_dev); |
| 924 | |
Jean Delvare | 7bef559 | 2005-07-27 22:14:49 +0200 | [diff] [blame] | 925 | if ((err = i2c_detach_client(client))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | |
| 928 | if(i2c_is_isa_client(client)) |
| 929 | release_region(client->addr, IT87_EXTENT); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 930 | kfree(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | |
| 932 | return 0; |
| 933 | } |
| 934 | |
Steven Cole | 44bbe87 | 2005-05-03 18:21:25 -0600 | [diff] [blame] | 935 | /* The SMBus locks itself, but ISA access must be locked explicitly! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | We don't want to lock the whole ISA bus, so we lock each client |
| 937 | separately. |
| 938 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
| 939 | would slow down the IT87 access and should not be necessary. */ |
| 940 | static int it87_read_value(struct i2c_client *client, u8 reg) |
| 941 | { |
| 942 | struct it87_data *data = i2c_get_clientdata(client); |
| 943 | |
| 944 | int res; |
| 945 | if (i2c_is_isa_client(client)) { |
| 946 | down(&data->lock); |
| 947 | outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); |
| 948 | res = inb_p(client->addr + IT87_DATA_REG_OFFSET); |
| 949 | up(&data->lock); |
| 950 | return res; |
| 951 | } else |
| 952 | return i2c_smbus_read_byte_data(client, reg); |
| 953 | } |
| 954 | |
Steven Cole | 44bbe87 | 2005-05-03 18:21:25 -0600 | [diff] [blame] | 955 | /* The SMBus locks itself, but ISA access muse be locked explicitly! |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | We don't want to lock the whole ISA bus, so we lock each client |
| 957 | separately. |
| 958 | We ignore the IT87 BUSY flag at this moment - it could lead to deadlocks, |
| 959 | would slow down the IT87 access and should not be necessary. */ |
| 960 | static int it87_write_value(struct i2c_client *client, u8 reg, u8 value) |
| 961 | { |
| 962 | struct it87_data *data = i2c_get_clientdata(client); |
| 963 | |
| 964 | if (i2c_is_isa_client(client)) { |
| 965 | down(&data->lock); |
| 966 | outb_p(reg, client->addr + IT87_ADDR_REG_OFFSET); |
| 967 | outb_p(value, client->addr + IT87_DATA_REG_OFFSET); |
| 968 | up(&data->lock); |
| 969 | return 0; |
| 970 | } else |
| 971 | return i2c_smbus_write_byte_data(client, reg, value); |
| 972 | } |
| 973 | |
| 974 | /* Return 1 if and only if the PWM interface is safe to use */ |
| 975 | static int it87_check_pwm(struct i2c_client *client) |
| 976 | { |
| 977 | /* Some BIOSes fail to correctly configure the IT87 fans. All fans off |
| 978 | * and polarity set to active low is sign that this is the case so we |
| 979 | * disable pwm control to protect the user. */ |
| 980 | int tmp = it87_read_value(client, IT87_REG_FAN_CTL); |
| 981 | if ((tmp & 0x87) == 0) { |
| 982 | if (fix_pwm_polarity) { |
| 983 | /* The user asks us to attempt a chip reconfiguration. |
| 984 | * This means switching to active high polarity and |
| 985 | * inverting all fan speed values. */ |
| 986 | int i; |
| 987 | u8 pwm[3]; |
| 988 | |
| 989 | for (i = 0; i < 3; i++) |
| 990 | pwm[i] = it87_read_value(client, |
| 991 | IT87_REG_PWM(i)); |
| 992 | |
| 993 | /* If any fan is in automatic pwm mode, the polarity |
| 994 | * might be correct, as suspicious as it seems, so we |
| 995 | * better don't change anything (but still disable the |
| 996 | * PWM interface). */ |
| 997 | if (!((pwm[0] | pwm[1] | pwm[2]) & 0x80)) { |
| 998 | dev_info(&client->dev, "Reconfiguring PWM to " |
| 999 | "active high polarity\n"); |
| 1000 | it87_write_value(client, IT87_REG_FAN_CTL, |
| 1001 | tmp | 0x87); |
| 1002 | for (i = 0; i < 3; i++) |
| 1003 | it87_write_value(client, |
| 1004 | IT87_REG_PWM(i), |
| 1005 | 0x7f & ~pwm[i]); |
| 1006 | return 1; |
| 1007 | } |
| 1008 | |
| 1009 | dev_info(&client->dev, "PWM configuration is " |
| 1010 | "too broken to be fixed\n"); |
| 1011 | } |
| 1012 | |
| 1013 | dev_info(&client->dev, "Detected broken BIOS " |
| 1014 | "defaults, disabling PWM interface\n"); |
| 1015 | return 0; |
| 1016 | } else if (fix_pwm_polarity) { |
| 1017 | dev_info(&client->dev, "PWM configuration looks " |
| 1018 | "sane, won't touch\n"); |
| 1019 | } |
| 1020 | |
| 1021 | return 1; |
| 1022 | } |
| 1023 | |
| 1024 | /* Called when we have found a new IT87. */ |
| 1025 | static void it87_init_client(struct i2c_client *client, struct it87_data *data) |
| 1026 | { |
| 1027 | int tmp, i; |
| 1028 | |
| 1029 | /* initialize to sane defaults: |
| 1030 | * - if the chip is in manual pwm mode, this will be overwritten with |
| 1031 | * the actual settings on the chip (so in this case, initialization |
| 1032 | * is not needed) |
| 1033 | * - if in automatic or on/off mode, we could switch to manual mode, |
| 1034 | * read the registers and set manual_pwm_ctl accordingly, but currently |
| 1035 | * this is not implemented, so we initialize to something sane */ |
| 1036 | for (i = 0; i < 3; i++) { |
| 1037 | data->manual_pwm_ctl[i] = 0xff; |
| 1038 | } |
| 1039 | |
| 1040 | /* Check if temperature channnels are reset manually or by some reason */ |
| 1041 | tmp = it87_read_value(client, IT87_REG_TEMP_ENABLE); |
| 1042 | if ((tmp & 0x3f) == 0) { |
| 1043 | /* Temp1,Temp3=thermistor; Temp2=thermal diode */ |
| 1044 | tmp = (tmp & 0xc0) | 0x2a; |
| 1045 | it87_write_value(client, IT87_REG_TEMP_ENABLE, tmp); |
| 1046 | } |
| 1047 | data->sensor = tmp; |
| 1048 | |
| 1049 | /* Check if voltage monitors are reset manually or by some reason */ |
| 1050 | tmp = it87_read_value(client, IT87_REG_VIN_ENABLE); |
| 1051 | if ((tmp & 0xff) == 0) { |
| 1052 | /* Enable all voltage monitors */ |
| 1053 | it87_write_value(client, IT87_REG_VIN_ENABLE, 0xff); |
| 1054 | } |
| 1055 | |
| 1056 | /* Check if tachometers are reset manually or by some reason */ |
| 1057 | data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL); |
| 1058 | if ((data->fan_main_ctrl & 0x70) == 0) { |
| 1059 | /* Enable all fan tachometers */ |
| 1060 | data->fan_main_ctrl |= 0x70; |
| 1061 | it87_write_value(client, IT87_REG_FAN_MAIN_CTRL, data->fan_main_ctrl); |
| 1062 | } |
| 1063 | |
| 1064 | /* Set current fan mode registers and the default settings for the |
| 1065 | * other mode registers */ |
| 1066 | for (i = 0; i < 3; i++) { |
| 1067 | if (data->fan_main_ctrl & (1 << i)) { |
| 1068 | /* pwm mode */ |
| 1069 | tmp = it87_read_value(client, IT87_REG_PWM(i)); |
| 1070 | if (tmp & 0x80) { |
| 1071 | /* automatic pwm - not yet implemented, but |
| 1072 | * leave the settings made by the BIOS alone |
| 1073 | * until a change is requested via the sysfs |
| 1074 | * interface */ |
| 1075 | } else { |
| 1076 | /* manual pwm */ |
| 1077 | data->manual_pwm_ctl[i] = PWM_FROM_REG(tmp); |
| 1078 | } |
| 1079 | } |
| 1080 | } |
| 1081 | |
| 1082 | /* Start monitoring */ |
| 1083 | it87_write_value(client, IT87_REG_CONFIG, |
| 1084 | (it87_read_value(client, IT87_REG_CONFIG) & 0x36) |
| 1085 | | (update_vbat ? 0x41 : 0x01)); |
| 1086 | } |
| 1087 | |
| 1088 | static struct it87_data *it87_update_device(struct device *dev) |
| 1089 | { |
| 1090 | struct i2c_client *client = to_i2c_client(dev); |
| 1091 | struct it87_data *data = i2c_get_clientdata(client); |
| 1092 | int i; |
| 1093 | |
| 1094 | down(&data->update_lock); |
| 1095 | |
| 1096 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
| 1097 | || !data->valid) { |
| 1098 | |
| 1099 | if (update_vbat) { |
| 1100 | /* Cleared after each update, so reenable. Value |
| 1101 | returned by this read will be previous value */ |
| 1102 | it87_write_value(client, IT87_REG_CONFIG, |
| 1103 | it87_read_value(client, IT87_REG_CONFIG) | 0x40); |
| 1104 | } |
| 1105 | for (i = 0; i <= 7; i++) { |
| 1106 | data->in[i] = |
| 1107 | it87_read_value(client, IT87_REG_VIN(i)); |
| 1108 | data->in_min[i] = |
| 1109 | it87_read_value(client, IT87_REG_VIN_MIN(i)); |
| 1110 | data->in_max[i] = |
| 1111 | it87_read_value(client, IT87_REG_VIN_MAX(i)); |
| 1112 | } |
| 1113 | data->in[8] = |
| 1114 | it87_read_value(client, IT87_REG_VIN(8)); |
| 1115 | /* Temperature sensor doesn't have limit registers, set |
| 1116 | to min and max value */ |
| 1117 | data->in_min[8] = 0; |
| 1118 | data->in_max[8] = 255; |
| 1119 | |
| 1120 | for (i = 0; i < 3; i++) { |
| 1121 | data->fan[i] = |
| 1122 | it87_read_value(client, IT87_REG_FAN(i)); |
| 1123 | data->fan_min[i] = |
| 1124 | it87_read_value(client, IT87_REG_FAN_MIN(i)); |
| 1125 | } |
| 1126 | for (i = 0; i < 3; i++) { |
| 1127 | data->temp[i] = |
| 1128 | it87_read_value(client, IT87_REG_TEMP(i)); |
| 1129 | data->temp_high[i] = |
| 1130 | it87_read_value(client, IT87_REG_TEMP_HIGH(i)); |
| 1131 | data->temp_low[i] = |
| 1132 | it87_read_value(client, IT87_REG_TEMP_LOW(i)); |
| 1133 | } |
| 1134 | |
| 1135 | i = it87_read_value(client, IT87_REG_FAN_DIV); |
| 1136 | data->fan_div[0] = i & 0x07; |
| 1137 | data->fan_div[1] = (i >> 3) & 0x07; |
| 1138 | data->fan_div[2] = (i & 0x40) ? 3 : 1; |
| 1139 | |
| 1140 | data->alarms = |
| 1141 | it87_read_value(client, IT87_REG_ALARM1) | |
| 1142 | (it87_read_value(client, IT87_REG_ALARM2) << 8) | |
| 1143 | (it87_read_value(client, IT87_REG_ALARM3) << 16); |
| 1144 | data->fan_main_ctrl = it87_read_value(client, IT87_REG_FAN_MAIN_CTRL); |
| 1145 | |
| 1146 | data->sensor = it87_read_value(client, IT87_REG_TEMP_ENABLE); |
| 1147 | /* The 8705 does not have VID capability */ |
| 1148 | if (data->type == it8712) { |
| 1149 | data->vid = it87_read_value(client, IT87_REG_VID); |
| 1150 | data->vid &= 0x1f; |
| 1151 | } |
| 1152 | data->last_updated = jiffies; |
| 1153 | data->valid = 1; |
| 1154 | } |
| 1155 | |
| 1156 | up(&data->update_lock); |
| 1157 | |
| 1158 | return data; |
| 1159 | } |
| 1160 | |
| 1161 | static int __init sm_it87_init(void) |
| 1162 | { |
Jean Delvare | 9174999 | 2005-10-08 00:10:00 +0200 | [diff] [blame] | 1163 | int res; |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 1164 | |
| 1165 | res = i2c_add_driver(&it87_driver); |
| 1166 | if (res) |
| 1167 | return res; |
| 1168 | |
Jean Delvare | 9174999 | 2005-10-08 00:10:00 +0200 | [diff] [blame] | 1169 | if (!it87_find(&isa_address)) { |
| 1170 | res = i2c_isa_add_driver(&it87_isa_driver); |
| 1171 | if (res) { |
| 1172 | i2c_del_driver(&it87_driver); |
| 1173 | return res; |
| 1174 | } |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | } |
| 1179 | |
| 1180 | static void __exit sm_it87_exit(void) |
| 1181 | { |
Jean Delvare | fde0950 | 2005-07-19 23:51:07 +0200 | [diff] [blame] | 1182 | i2c_isa_del_driver(&it87_isa_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | i2c_del_driver(&it87_driver); |
| 1184 | } |
| 1185 | |
| 1186 | |
| 1187 | MODULE_AUTHOR("Chris Gauthron <chrisg@0-in.com>"); |
| 1188 | MODULE_DESCRIPTION("IT8705F, IT8712F, Sis950 driver"); |
| 1189 | module_param(update_vbat, bool, 0); |
| 1190 | MODULE_PARM_DESC(update_vbat, "Update vbat if set else return powerup value"); |
| 1191 | module_param(fix_pwm_polarity, bool, 0); |
| 1192 | MODULE_PARM_DESC(fix_pwm_polarity, "Force PWM polarity to active high (DANGEROUS)"); |
| 1193 | MODULE_LICENSE("GPL"); |
| 1194 | |
| 1195 | module_init(sm_it87_init); |
| 1196 | module_exit(sm_it87_exit); |