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