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