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