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