Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | w83627hf.c - Part of lm_sensors, Linux kernel modules for hardware |
| 3 | monitoring |
| 4 | Copyright (c) 1998 - 2003 Frodo Looijaard <frodol@dds.nl>, |
| 5 | Philip Edelbrock <phil@netroedge.com>, |
| 6 | and Mark Studebaker <mdsxyz123@yahoo.com> |
| 7 | Ported to 2.6 by Bernhard C. Schrenk <clemy@clemy.org> |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 8 | Copyright (c) 2007 Jean Delvare <khali@linux-fr.org> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
| 10 | This program is free software; you can redistribute it and/or modify |
| 11 | it under the terms of the GNU General Public License as published by |
| 12 | the Free Software Foundation; either version 2 of the License, or |
| 13 | (at your option) any later version. |
| 14 | |
| 15 | This program is distributed in the hope that it will be useful, |
| 16 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | GNU General Public License for more details. |
| 19 | |
| 20 | You should have received a copy of the GNU General Public License |
| 21 | along with this program; if not, write to the Free Software |
| 22 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | */ |
| 24 | |
| 25 | /* |
| 26 | Supports following chips: |
| 27 | |
| 28 | Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA |
| 29 | w83627hf 9 3 2 3 0x20 0x5ca3 no yes(LPC) |
| 30 | w83627thf 7 3 3 3 0x90 0x5ca3 no yes(LPC) |
| 31 | w83637hf 7 3 3 3 0x80 0x5ca3 no yes(LPC) |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 32 | w83687thf 7 3 3 3 0x90 0x5ca3 no yes(LPC) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | w83697hf 8 2 2 2 0x60 0x5ca3 no yes(LPC) |
| 34 | |
| 35 | For other winbond chips, and for i2c support in the above chips, |
| 36 | use w83781d.c. |
| 37 | |
| 38 | Note: automatic ("cruise") fan control for 697, 637 & 627thf not |
| 39 | supported yet. |
| 40 | */ |
| 41 | |
| 42 | #include <linux/module.h> |
| 43 | #include <linux/init.h> |
| 44 | #include <linux/slab.h> |
| 45 | #include <linux/jiffies.h> |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 46 | #include <linux/platform_device.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 47 | #include <linux/hwmon.h> |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 48 | #include <linux/hwmon-vid.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 49 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 50 | #include <linux/mutex.h> |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 51 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #include <asm/io.h> |
| 53 | #include "lm75.h" |
| 54 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 55 | static struct platform_device *pdev; |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 56 | |
| 57 | #define DRVNAME "w83627hf" |
| 58 | enum chips { w83627hf, w83627thf, w83697hf, w83637hf, w83687thf }; |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | static u16 force_addr; |
| 61 | module_param(force_addr, ushort, 0); |
| 62 | MODULE_PARM_DESC(force_addr, |
| 63 | "Initialize the base address of the sensors"); |
| 64 | static u8 force_i2c = 0x1f; |
| 65 | module_param(force_i2c, byte, 0); |
| 66 | MODULE_PARM_DESC(force_i2c, |
| 67 | "Initialize the i2c address of the sensors"); |
| 68 | |
Jean Delvare | 2251cf1 | 2005-09-04 22:52:17 +0200 | [diff] [blame] | 69 | static int reset; |
| 70 | module_param(reset, bool, 0); |
| 71 | MODULE_PARM_DESC(reset, "Set to one to reset chip on load"); |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | static int init = 1; |
| 74 | module_param(init, bool, 0); |
| 75 | MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization"); |
| 76 | |
| 77 | /* modified from kernel/include/traps.c */ |
| 78 | static int REG; /* The register to read/write */ |
| 79 | #define DEV 0x07 /* Register: Logical device select */ |
| 80 | static int VAL; /* The value to read/write */ |
| 81 | |
| 82 | /* logical device numbers for superio_select (below) */ |
| 83 | #define W83627HF_LD_FDC 0x00 |
| 84 | #define W83627HF_LD_PRT 0x01 |
| 85 | #define W83627HF_LD_UART1 0x02 |
| 86 | #define W83627HF_LD_UART2 0x03 |
| 87 | #define W83627HF_LD_KBC 0x05 |
| 88 | #define W83627HF_LD_CIR 0x06 /* w83627hf only */ |
| 89 | #define W83627HF_LD_GAME 0x07 |
| 90 | #define W83627HF_LD_MIDI 0x07 |
| 91 | #define W83627HF_LD_GPIO1 0x07 |
| 92 | #define W83627HF_LD_GPIO5 0x07 /* w83627thf only */ |
| 93 | #define W83627HF_LD_GPIO2 0x08 |
| 94 | #define W83627HF_LD_GPIO3 0x09 |
| 95 | #define W83627HF_LD_GPIO4 0x09 /* w83627thf only */ |
| 96 | #define W83627HF_LD_ACPI 0x0a |
| 97 | #define W83627HF_LD_HWM 0x0b |
| 98 | |
| 99 | #define DEVID 0x20 /* Register: Device ID */ |
| 100 | |
| 101 | #define W83627THF_GPIO5_EN 0x30 /* w83627thf only */ |
| 102 | #define W83627THF_GPIO5_IOSR 0xf3 /* w83627thf only */ |
| 103 | #define W83627THF_GPIO5_DR 0xf4 /* w83627thf only */ |
| 104 | |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 105 | #define W83687THF_VID_EN 0x29 /* w83687thf only */ |
| 106 | #define W83687THF_VID_CFG 0xF0 /* w83687thf only */ |
| 107 | #define W83687THF_VID_DATA 0xF1 /* w83687thf only */ |
| 108 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | static inline void |
| 110 | superio_outb(int reg, int val) |
| 111 | { |
| 112 | outb(reg, REG); |
| 113 | outb(val, VAL); |
| 114 | } |
| 115 | |
| 116 | static inline int |
| 117 | superio_inb(int reg) |
| 118 | { |
| 119 | outb(reg, REG); |
| 120 | return inb(VAL); |
| 121 | } |
| 122 | |
| 123 | static inline void |
| 124 | superio_select(int ld) |
| 125 | { |
| 126 | outb(DEV, REG); |
| 127 | outb(ld, VAL); |
| 128 | } |
| 129 | |
| 130 | static inline void |
| 131 | superio_enter(void) |
| 132 | { |
| 133 | outb(0x87, REG); |
| 134 | outb(0x87, REG); |
| 135 | } |
| 136 | |
| 137 | static inline void |
| 138 | superio_exit(void) |
| 139 | { |
| 140 | outb(0xAA, REG); |
| 141 | } |
| 142 | |
| 143 | #define W627_DEVID 0x52 |
| 144 | #define W627THF_DEVID 0x82 |
| 145 | #define W697_DEVID 0x60 |
| 146 | #define W637_DEVID 0x70 |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 147 | #define W687THF_DEVID 0x85 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | #define WINB_ACT_REG 0x30 |
| 149 | #define WINB_BASE_REG 0x60 |
| 150 | /* Constants specified below */ |
| 151 | |
Petr Vandrovec | ada0c2f | 2005-10-07 23:11:03 +0200 | [diff] [blame] | 152 | /* Alignment of the base address */ |
| 153 | #define WINB_ALIGNMENT ~7 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
Petr Vandrovec | ada0c2f | 2005-10-07 23:11:03 +0200 | [diff] [blame] | 155 | /* Offset & size of I/O region we are interested in */ |
| 156 | #define WINB_REGION_OFFSET 5 |
| 157 | #define WINB_REGION_SIZE 2 |
| 158 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 159 | /* Where are the sensors address/data registers relative to the region offset */ |
| 160 | #define W83781D_ADDR_REG_OFFSET 0 |
| 161 | #define W83781D_DATA_REG_OFFSET 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | /* The W83781D registers */ |
| 164 | /* The W83782D registers for nr=7,8 are in bank 5 */ |
| 165 | #define W83781D_REG_IN_MAX(nr) ((nr < 7) ? (0x2b + (nr) * 2) : \ |
| 166 | (0x554 + (((nr) - 7) * 2))) |
| 167 | #define W83781D_REG_IN_MIN(nr) ((nr < 7) ? (0x2c + (nr) * 2) : \ |
| 168 | (0x555 + (((nr) - 7) * 2))) |
| 169 | #define W83781D_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \ |
| 170 | (0x550 + (nr) - 7)) |
| 171 | |
| 172 | #define W83781D_REG_FAN_MIN(nr) (0x3a + (nr)) |
| 173 | #define W83781D_REG_FAN(nr) (0x27 + (nr)) |
| 174 | |
| 175 | #define W83781D_REG_TEMP2_CONFIG 0x152 |
| 176 | #define W83781D_REG_TEMP3_CONFIG 0x252 |
| 177 | #define W83781D_REG_TEMP(nr) ((nr == 3) ? (0x0250) : \ |
| 178 | ((nr == 2) ? (0x0150) : \ |
| 179 | (0x27))) |
| 180 | #define W83781D_REG_TEMP_HYST(nr) ((nr == 3) ? (0x253) : \ |
| 181 | ((nr == 2) ? (0x153) : \ |
| 182 | (0x3A))) |
| 183 | #define W83781D_REG_TEMP_OVER(nr) ((nr == 3) ? (0x255) : \ |
| 184 | ((nr == 2) ? (0x155) : \ |
| 185 | (0x39))) |
| 186 | |
| 187 | #define W83781D_REG_BANK 0x4E |
| 188 | |
| 189 | #define W83781D_REG_CONFIG 0x40 |
Yuan Mu | 4a1c4447 | 2005-11-07 22:19:04 +0100 | [diff] [blame] | 190 | #define W83781D_REG_ALARM1 0x459 |
| 191 | #define W83781D_REG_ALARM2 0x45A |
| 192 | #define W83781D_REG_ALARM3 0x45B |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | #define W83781D_REG_BEEP_CONFIG 0x4D |
| 195 | #define W83781D_REG_BEEP_INTS1 0x56 |
| 196 | #define W83781D_REG_BEEP_INTS2 0x57 |
| 197 | #define W83781D_REG_BEEP_INTS3 0x453 |
| 198 | |
| 199 | #define W83781D_REG_VID_FANDIV 0x47 |
| 200 | |
| 201 | #define W83781D_REG_CHIPID 0x49 |
| 202 | #define W83781D_REG_WCHIPID 0x58 |
| 203 | #define W83781D_REG_CHIPMAN 0x4F |
| 204 | #define W83781D_REG_PIN 0x4B |
| 205 | |
| 206 | #define W83781D_REG_VBAT 0x5D |
| 207 | |
| 208 | #define W83627HF_REG_PWM1 0x5A |
| 209 | #define W83627HF_REG_PWM2 0x5B |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 211 | #define W83627THF_REG_PWM1 0x01 /* 697HF/637HF/687THF too */ |
| 212 | #define W83627THF_REG_PWM2 0x03 /* 697HF/637HF/687THF too */ |
| 213 | #define W83627THF_REG_PWM3 0x11 /* 637HF/687THF too */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 215 | #define W83627THF_REG_VRM_OVT_CFG 0x18 /* 637HF/687THF too */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | static const u8 regpwm_627hf[] = { W83627HF_REG_PWM1, W83627HF_REG_PWM2 }; |
| 218 | static const u8 regpwm[] = { W83627THF_REG_PWM1, W83627THF_REG_PWM2, |
| 219 | W83627THF_REG_PWM3 }; |
| 220 | #define W836X7HF_REG_PWM(type, nr) (((type) == w83627hf) ? \ |
| 221 | regpwm_627hf[(nr) - 1] : regpwm[(nr) - 1]) |
| 222 | |
| 223 | #define W83781D_REG_I2C_ADDR 0x48 |
| 224 | #define W83781D_REG_I2C_SUBADDR 0x4A |
| 225 | |
| 226 | /* Sensor selection */ |
| 227 | #define W83781D_REG_SCFG1 0x5D |
| 228 | static const u8 BIT_SCFG1[] = { 0x02, 0x04, 0x08 }; |
| 229 | #define W83781D_REG_SCFG2 0x59 |
| 230 | static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 }; |
| 231 | #define W83781D_DEFAULT_BETA 3435 |
| 232 | |
| 233 | /* Conversions. Limit checking is only done on the TO_REG |
| 234 | variants. Note that you should be a bit careful with which arguments |
| 235 | these macros are called: arguments may be evaluated more than once. |
| 236 | Fixing this is just not worth it. */ |
| 237 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255)) |
| 238 | #define IN_FROM_REG(val) ((val) * 16) |
| 239 | |
| 240 | static inline u8 FAN_TO_REG(long rpm, int div) |
| 241 | { |
| 242 | if (rpm == 0) |
| 243 | return 255; |
| 244 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); |
| 245 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, |
| 246 | 254); |
| 247 | } |
| 248 | |
| 249 | #define TEMP_MIN (-128000) |
| 250 | #define TEMP_MAX ( 127000) |
| 251 | |
| 252 | /* TEMP: 0.001C/bit (-128C to +127C) |
| 253 | REG: 1C/bit, two's complement */ |
| 254 | static u8 TEMP_TO_REG(int temp) |
| 255 | { |
| 256 | int ntemp = SENSORS_LIMIT(temp, TEMP_MIN, TEMP_MAX); |
| 257 | ntemp += (ntemp<0 ? -500 : 500); |
| 258 | return (u8)(ntemp / 1000); |
| 259 | } |
| 260 | |
| 261 | static int TEMP_FROM_REG(u8 reg) |
| 262 | { |
| 263 | return (s8)reg * 1000; |
| 264 | } |
| 265 | |
| 266 | #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) |
| 267 | |
| 268 | #define PWM_TO_REG(val) (SENSORS_LIMIT((val),0,255)) |
| 269 | |
| 270 | #define BEEP_MASK_FROM_REG(val) (val) |
| 271 | #define BEEP_MASK_TO_REG(val) ((val) & 0xffffff) |
| 272 | #define BEEP_ENABLE_TO_REG(val) ((val)?1:0) |
| 273 | #define BEEP_ENABLE_FROM_REG(val) ((val)?1:0) |
| 274 | |
| 275 | #define DIV_FROM_REG(val) (1 << (val)) |
| 276 | |
| 277 | static inline u8 DIV_TO_REG(long val) |
| 278 | { |
| 279 | int i; |
| 280 | val = SENSORS_LIMIT(val, 1, 128) >> 1; |
Grant Coady | abc0192 | 2005-05-12 13:41:51 +1000 | [diff] [blame] | 281 | for (i = 0; i < 7; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | if (val == 0) |
| 283 | break; |
| 284 | val >>= 1; |
| 285 | } |
| 286 | return ((u8) i); |
| 287 | } |
| 288 | |
Jean Delvare | ed6bafb | 2007-02-14 21:15:03 +0100 | [diff] [blame] | 289 | /* For each registered chip, we need to keep some data in memory. |
| 290 | The structure is dynamically allocated. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | struct w83627hf_data { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 292 | unsigned short addr; |
| 293 | const char *name; |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 294 | struct class_device *class_dev; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 295 | struct mutex lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | enum chips type; |
| 297 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 298 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | char valid; /* !=0 if following fields are valid */ |
| 300 | unsigned long last_updated; /* In jiffies */ |
| 301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | u8 in[9]; /* Register value */ |
| 303 | u8 in_max[9]; /* Register value */ |
| 304 | u8 in_min[9]; /* Register value */ |
| 305 | u8 fan[3]; /* Register value */ |
| 306 | u8 fan_min[3]; /* Register value */ |
| 307 | u8 temp; |
| 308 | u8 temp_max; /* Register value */ |
| 309 | u8 temp_max_hyst; /* Register value */ |
| 310 | u16 temp_add[2]; /* Register value */ |
| 311 | u16 temp_max_add[2]; /* Register value */ |
| 312 | u16 temp_max_hyst_add[2]; /* Register value */ |
| 313 | u8 fan_div[3]; /* Register encoding, shifted right */ |
| 314 | u8 vid; /* Register encoding, combined */ |
| 315 | u32 alarms; /* Register encoding, combined */ |
| 316 | u32 beep_mask; /* Register encoding, combined */ |
| 317 | u8 beep_enable; /* Boolean */ |
| 318 | u8 pwm[3]; /* Register value */ |
| 319 | u16 sens[3]; /* 782D/783S only. |
| 320 | 1 = pentium diode; 2 = 3904 diode; |
| 321 | 3000-5000 = thermistor beta. |
| 322 | Default = 3435. |
| 323 | Other Betas unimplemented */ |
| 324 | u8 vrm; |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 325 | u8 vrm_ovt; /* Register value, 627THF/637HF/687THF only */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | }; |
| 327 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 328 | struct w83627hf_sio_data { |
| 329 | enum chips type; |
| 330 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 333 | static int w83627hf_probe(struct platform_device *pdev); |
| 334 | static int w83627hf_remove(struct platform_device *pdev); |
| 335 | |
| 336 | static int w83627hf_read_value(struct w83627hf_data *data, u16 reg); |
| 337 | static int w83627hf_write_value(struct w83627hf_data *data, u16 reg, u16 value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | static struct w83627hf_data *w83627hf_update_device(struct device *dev); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 339 | static void w83627hf_init_device(struct platform_device *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 341 | static struct platform_driver w83627hf_driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 342 | .driver = { |
Jean Delvare | 8721884 | 2006-09-03 22:36:14 +0200 | [diff] [blame] | 343 | .owner = THIS_MODULE, |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 344 | .name = DRVNAME, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 345 | }, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 346 | .probe = w83627hf_probe, |
| 347 | .remove = __devexit_p(w83627hf_remove), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | }; |
| 349 | |
| 350 | /* following are the sysfs callback functions */ |
| 351 | #define show_in_reg(reg) \ |
| 352 | static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ |
| 353 | { \ |
| 354 | struct w83627hf_data *data = w83627hf_update_device(dev); \ |
| 355 | return sprintf(buf,"%ld\n", (long)IN_FROM_REG(data->reg[nr])); \ |
| 356 | } |
| 357 | show_in_reg(in) |
| 358 | show_in_reg(in_min) |
| 359 | show_in_reg(in_max) |
| 360 | |
| 361 | #define store_in_reg(REG, reg) \ |
| 362 | static ssize_t \ |
| 363 | store_in_##reg (struct device *dev, const char *buf, size_t count, int nr) \ |
| 364 | { \ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 365 | struct w83627hf_data *data = dev_get_drvdata(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | u32 val; \ |
| 367 | \ |
| 368 | val = simple_strtoul(buf, NULL, 10); \ |
| 369 | \ |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 370 | mutex_lock(&data->update_lock); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | data->in_##reg[nr] = IN_TO_REG(val); \ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 372 | w83627hf_write_value(data, W83781D_REG_IN_##REG(nr), \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | data->in_##reg[nr]); \ |
| 374 | \ |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 375 | mutex_unlock(&data->update_lock); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | return count; \ |
| 377 | } |
| 378 | store_in_reg(MIN, min) |
| 379 | store_in_reg(MAX, max) |
| 380 | |
| 381 | #define sysfs_in_offset(offset) \ |
| 382 | static ssize_t \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 383 | show_regs_in_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | { \ |
| 385 | return show_in(dev, buf, offset); \ |
| 386 | } \ |
| 387 | static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_regs_in_##offset, NULL); |
| 388 | |
| 389 | #define sysfs_in_reg_offset(reg, offset) \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 390 | static ssize_t show_regs_in_##reg##offset (struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { \ |
| 392 | return show_in_##reg (dev, buf, offset); \ |
| 393 | } \ |
| 394 | static ssize_t \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 395 | store_regs_in_##reg##offset (struct device *dev, struct device_attribute *attr, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | const char *buf, size_t count) \ |
| 397 | { \ |
| 398 | return store_in_##reg (dev, buf, count, offset); \ |
| 399 | } \ |
| 400 | static DEVICE_ATTR(in##offset##_##reg, S_IRUGO| S_IWUSR, \ |
| 401 | show_regs_in_##reg##offset, store_regs_in_##reg##offset); |
| 402 | |
| 403 | #define sysfs_in_offsets(offset) \ |
| 404 | sysfs_in_offset(offset) \ |
| 405 | sysfs_in_reg_offset(min, offset) \ |
| 406 | sysfs_in_reg_offset(max, offset) |
| 407 | |
| 408 | sysfs_in_offsets(1); |
| 409 | sysfs_in_offsets(2); |
| 410 | sysfs_in_offsets(3); |
| 411 | sysfs_in_offsets(4); |
| 412 | sysfs_in_offsets(5); |
| 413 | sysfs_in_offsets(6); |
| 414 | sysfs_in_offsets(7); |
| 415 | sysfs_in_offsets(8); |
| 416 | |
| 417 | /* use a different set of functions for in0 */ |
| 418 | static ssize_t show_in_0(struct w83627hf_data *data, char *buf, u8 reg) |
| 419 | { |
| 420 | long in0; |
| 421 | |
| 422 | if ((data->vrm_ovt & 0x01) && |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 423 | (w83627thf == data->type || w83637hf == data->type |
| 424 | || w83687thf == data->type)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
| 426 | /* use VRM9 calculation */ |
| 427 | in0 = (long)((reg * 488 + 70000 + 50) / 100); |
| 428 | else |
| 429 | /* use VRM8 (standard) calculation */ |
| 430 | in0 = (long)IN_FROM_REG(reg); |
| 431 | |
| 432 | return sprintf(buf,"%ld\n", in0); |
| 433 | } |
| 434 | |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 435 | static ssize_t show_regs_in_0(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | { |
| 437 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 438 | return show_in_0(data, buf, data->in[0]); |
| 439 | } |
| 440 | |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 441 | static ssize_t show_regs_in_min0(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | { |
| 443 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 444 | return show_in_0(data, buf, data->in_min[0]); |
| 445 | } |
| 446 | |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 447 | static ssize_t show_regs_in_max0(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | { |
| 449 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 450 | return show_in_0(data, buf, data->in_max[0]); |
| 451 | } |
| 452 | |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 453 | static ssize_t store_regs_in_min0(struct device *dev, struct device_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | const char *buf, size_t count) |
| 455 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 456 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | u32 val; |
| 458 | |
| 459 | val = simple_strtoul(buf, NULL, 10); |
| 460 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 461 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
| 463 | if ((data->vrm_ovt & 0x01) && |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 464 | (w83627thf == data->type || w83637hf == data->type |
| 465 | || w83687thf == data->type)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
| 467 | /* use VRM9 calculation */ |
Yuan Mu | 2723ab9 | 2005-11-23 15:44:21 -0800 | [diff] [blame] | 468 | data->in_min[0] = |
| 469 | SENSORS_LIMIT(((val * 100) - 70000 + 244) / 488, 0, |
| 470 | 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | else |
| 472 | /* use VRM8 (standard) calculation */ |
| 473 | data->in_min[0] = IN_TO_REG(val); |
| 474 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 475 | w83627hf_write_value(data, W83781D_REG_IN_MIN(0), data->in_min[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 count; |
| 478 | } |
| 479 | |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 480 | static ssize_t store_regs_in_max0(struct device *dev, struct device_attribute *attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | const char *buf, size_t count) |
| 482 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 483 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | u32 val; |
| 485 | |
| 486 | val = simple_strtoul(buf, NULL, 10); |
| 487 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 488 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
| 490 | if ((data->vrm_ovt & 0x01) && |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 491 | (w83627thf == data->type || w83637hf == data->type |
| 492 | || w83687thf == data->type)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | |
| 494 | /* use VRM9 calculation */ |
Yuan Mu | 2723ab9 | 2005-11-23 15:44:21 -0800 | [diff] [blame] | 495 | data->in_max[0] = |
| 496 | SENSORS_LIMIT(((val * 100) - 70000 + 244) / 488, 0, |
| 497 | 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | else |
| 499 | /* use VRM8 (standard) calculation */ |
| 500 | data->in_max[0] = IN_TO_REG(val); |
| 501 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 502 | w83627hf_write_value(data, W83781D_REG_IN_MAX(0), data->in_max[0]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 503 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | return count; |
| 505 | } |
| 506 | |
| 507 | static DEVICE_ATTR(in0_input, S_IRUGO, show_regs_in_0, NULL); |
| 508 | static DEVICE_ATTR(in0_min, S_IRUGO | S_IWUSR, |
| 509 | show_regs_in_min0, store_regs_in_min0); |
| 510 | static DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR, |
| 511 | show_regs_in_max0, store_regs_in_max0); |
| 512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | #define show_fan_reg(reg) \ |
| 514 | static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ |
| 515 | { \ |
| 516 | struct w83627hf_data *data = w83627hf_update_device(dev); \ |
| 517 | return sprintf(buf,"%ld\n", \ |
| 518 | FAN_FROM_REG(data->reg[nr-1], \ |
| 519 | (long)DIV_FROM_REG(data->fan_div[nr-1]))); \ |
| 520 | } |
| 521 | show_fan_reg(fan); |
| 522 | show_fan_reg(fan_min); |
| 523 | |
| 524 | static ssize_t |
| 525 | store_fan_min(struct device *dev, const char *buf, size_t count, int nr) |
| 526 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 527 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | u32 val; |
| 529 | |
| 530 | val = simple_strtoul(buf, NULL, 10); |
| 531 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 532 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | data->fan_min[nr - 1] = |
| 534 | FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr - 1])); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 535 | w83627hf_write_value(data, W83781D_REG_FAN_MIN(nr), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | data->fan_min[nr - 1]); |
| 537 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 538 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | return count; |
| 540 | } |
| 541 | |
| 542 | #define sysfs_fan_offset(offset) \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 543 | static ssize_t show_regs_fan_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | { \ |
| 545 | return show_fan(dev, buf, offset); \ |
| 546 | } \ |
| 547 | static DEVICE_ATTR(fan##offset##_input, S_IRUGO, show_regs_fan_##offset, NULL); |
| 548 | |
| 549 | #define sysfs_fan_min_offset(offset) \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 550 | static ssize_t show_regs_fan_min##offset (struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | { \ |
| 552 | return show_fan_min(dev, buf, offset); \ |
| 553 | } \ |
| 554 | static ssize_t \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 555 | store_regs_fan_min##offset (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] | 556 | { \ |
| 557 | return store_fan_min(dev, buf, count, offset); \ |
| 558 | } \ |
| 559 | static DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
| 560 | show_regs_fan_min##offset, store_regs_fan_min##offset); |
| 561 | |
| 562 | sysfs_fan_offset(1); |
| 563 | sysfs_fan_min_offset(1); |
| 564 | sysfs_fan_offset(2); |
| 565 | sysfs_fan_min_offset(2); |
| 566 | sysfs_fan_offset(3); |
| 567 | sysfs_fan_min_offset(3); |
| 568 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | #define show_temp_reg(reg) \ |
| 570 | static ssize_t show_##reg (struct device *dev, char *buf, int nr) \ |
| 571 | { \ |
| 572 | struct w83627hf_data *data = w83627hf_update_device(dev); \ |
| 573 | if (nr >= 2) { /* TEMP2 and TEMP3 */ \ |
| 574 | return sprintf(buf,"%ld\n", \ |
| 575 | (long)LM75_TEMP_FROM_REG(data->reg##_add[nr-2])); \ |
| 576 | } else { /* TEMP1 */ \ |
| 577 | return sprintf(buf,"%ld\n", (long)TEMP_FROM_REG(data->reg)); \ |
| 578 | } \ |
| 579 | } |
| 580 | show_temp_reg(temp); |
| 581 | show_temp_reg(temp_max); |
| 582 | show_temp_reg(temp_max_hyst); |
| 583 | |
| 584 | #define store_temp_reg(REG, reg) \ |
| 585 | static ssize_t \ |
| 586 | store_temp_##reg (struct device *dev, const char *buf, size_t count, int nr) \ |
| 587 | { \ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 588 | struct w83627hf_data *data = dev_get_drvdata(dev); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | u32 val; \ |
| 590 | \ |
| 591 | val = simple_strtoul(buf, NULL, 10); \ |
| 592 | \ |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 593 | mutex_lock(&data->update_lock); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | \ |
| 595 | if (nr >= 2) { /* TEMP2 and TEMP3 */ \ |
| 596 | data->temp_##reg##_add[nr-2] = LM75_TEMP_TO_REG(val); \ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 597 | w83627hf_write_value(data, W83781D_REG_TEMP_##REG(nr), \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | data->temp_##reg##_add[nr-2]); \ |
| 599 | } else { /* TEMP1 */ \ |
| 600 | data->temp_##reg = TEMP_TO_REG(val); \ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 601 | w83627hf_write_value(data, W83781D_REG_TEMP_##REG(nr), \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | data->temp_##reg); \ |
| 603 | } \ |
| 604 | \ |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 605 | mutex_unlock(&data->update_lock); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | return count; \ |
| 607 | } |
| 608 | store_temp_reg(OVER, max); |
| 609 | store_temp_reg(HYST, max_hyst); |
| 610 | |
| 611 | #define sysfs_temp_offset(offset) \ |
| 612 | static ssize_t \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 613 | show_regs_temp_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | { \ |
| 615 | return show_temp(dev, buf, offset); \ |
| 616 | } \ |
| 617 | static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_regs_temp_##offset, NULL); |
| 618 | |
| 619 | #define sysfs_temp_reg_offset(reg, offset) \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 620 | static ssize_t show_regs_temp_##reg##offset (struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | { \ |
| 622 | return show_temp_##reg (dev, buf, offset); \ |
| 623 | } \ |
| 624 | static ssize_t \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 625 | store_regs_temp_##reg##offset (struct device *dev, struct device_attribute *attr, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | const char *buf, size_t count) \ |
| 627 | { \ |
| 628 | return store_temp_##reg (dev, buf, count, offset); \ |
| 629 | } \ |
| 630 | static DEVICE_ATTR(temp##offset##_##reg, S_IRUGO| S_IWUSR, \ |
| 631 | show_regs_temp_##reg##offset, store_regs_temp_##reg##offset); |
| 632 | |
| 633 | #define sysfs_temp_offsets(offset) \ |
| 634 | sysfs_temp_offset(offset) \ |
| 635 | sysfs_temp_reg_offset(max, offset) \ |
| 636 | sysfs_temp_reg_offset(max_hyst, offset) |
| 637 | |
| 638 | sysfs_temp_offsets(1); |
| 639 | sysfs_temp_offsets(2); |
| 640 | sysfs_temp_offsets(3); |
| 641 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | static ssize_t |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 643 | show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | { |
| 645 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 646 | return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); |
| 647 | } |
| 648 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
| 650 | static ssize_t |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 651 | show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | { |
| 653 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 654 | return sprintf(buf, "%ld\n", (long) data->vrm); |
| 655 | } |
| 656 | static ssize_t |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 657 | 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] | 658 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 659 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | u32 val; |
| 661 | |
| 662 | val = simple_strtoul(buf, NULL, 10); |
| 663 | data->vrm = val; |
| 664 | |
| 665 | return count; |
| 666 | } |
| 667 | 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] | 668 | |
| 669 | static ssize_t |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 670 | show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | { |
| 672 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 673 | return sprintf(buf, "%ld\n", (long) data->alarms); |
| 674 | } |
| 675 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
| 677 | #define show_beep_reg(REG, reg) \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 678 | static ssize_t show_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | { \ |
| 680 | struct w83627hf_data *data = w83627hf_update_device(dev); \ |
| 681 | return sprintf(buf,"%ld\n", \ |
| 682 | (long)BEEP_##REG##_FROM_REG(data->beep_##reg)); \ |
| 683 | } |
| 684 | show_beep_reg(ENABLE, enable) |
| 685 | show_beep_reg(MASK, mask) |
| 686 | |
| 687 | #define BEEP_ENABLE 0 /* Store beep_enable */ |
| 688 | #define BEEP_MASK 1 /* Store beep_mask */ |
| 689 | |
| 690 | static ssize_t |
| 691 | store_beep_reg(struct device *dev, const char *buf, size_t count, |
| 692 | int update_mask) |
| 693 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 694 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | u32 val, val2; |
| 696 | |
| 697 | val = simple_strtoul(buf, NULL, 10); |
| 698 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 699 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
| 701 | if (update_mask == BEEP_MASK) { /* We are storing beep_mask */ |
| 702 | data->beep_mask = BEEP_MASK_TO_REG(val); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 703 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | data->beep_mask & 0xff); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 705 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS3, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | ((data->beep_mask) >> 16) & 0xff); |
| 707 | val2 = (data->beep_mask >> 8) & 0x7f; |
| 708 | } else { /* We are storing beep_enable */ |
| 709 | val2 = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 710 | w83627hf_read_value(data, W83781D_REG_BEEP_INTS2) & 0x7f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | data->beep_enable = BEEP_ENABLE_TO_REG(val); |
| 712 | } |
| 713 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 714 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | val2 | data->beep_enable << 7); |
| 716 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 717 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | return count; |
| 719 | } |
| 720 | |
| 721 | #define sysfs_beep(REG, reg) \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 722 | static ssize_t show_regs_beep_##reg (struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | { \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 724 | return show_beep_##reg(dev, attr, buf); \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | } \ |
| 726 | static ssize_t \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 727 | store_regs_beep_##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] | 728 | { \ |
| 729 | return store_beep_reg(dev, buf, count, BEEP_##REG); \ |
| 730 | } \ |
| 731 | static DEVICE_ATTR(beep_##reg, S_IRUGO | S_IWUSR, \ |
| 732 | show_regs_beep_##reg, store_regs_beep_##reg); |
| 733 | |
| 734 | sysfs_beep(ENABLE, enable); |
| 735 | sysfs_beep(MASK, mask); |
| 736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | static ssize_t |
| 738 | show_fan_div_reg(struct device *dev, char *buf, int nr) |
| 739 | { |
| 740 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 741 | return sprintf(buf, "%ld\n", |
| 742 | (long) DIV_FROM_REG(data->fan_div[nr - 1])); |
| 743 | } |
| 744 | |
| 745 | /* Note: we save and restore the fan minimum here, because its value is |
| 746 | determined in part by the fan divisor. This follows the principle of |
Andreas Mohr | d6e05ed | 2006-06-26 18:35:02 +0200 | [diff] [blame] | 747 | least surprise; the user doesn't expect the fan minimum to change just |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | because the divisor changed. */ |
| 749 | static ssize_t |
| 750 | store_fan_div_reg(struct device *dev, const char *buf, size_t count, int nr) |
| 751 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 752 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | unsigned long min; |
| 754 | u8 reg; |
| 755 | unsigned long val = simple_strtoul(buf, NULL, 10); |
| 756 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 757 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | |
| 759 | /* Save fan_min */ |
| 760 | min = FAN_FROM_REG(data->fan_min[nr], |
| 761 | DIV_FROM_REG(data->fan_div[nr])); |
| 762 | |
| 763 | data->fan_div[nr] = DIV_TO_REG(val); |
| 764 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 765 | reg = (w83627hf_read_value(data, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | & (nr==0 ? 0xcf : 0x3f)) |
| 767 | | ((data->fan_div[nr] & 0x03) << (nr==0 ? 4 : 6)); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 768 | w83627hf_write_value(data, nr==2 ? W83781D_REG_PIN : W83781D_REG_VID_FANDIV, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 770 | reg = (w83627hf_read_value(data, W83781D_REG_VBAT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | & ~(1 << (5 + nr))) |
| 772 | | ((data->fan_div[nr] & 0x04) << (3 + nr)); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 773 | w83627hf_write_value(data, W83781D_REG_VBAT, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | |
| 775 | /* Restore fan_min */ |
| 776 | data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 777 | w83627hf_write_value(data, W83781D_REG_FAN_MIN(nr+1), data->fan_min[nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 779 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | return count; |
| 781 | } |
| 782 | |
| 783 | #define sysfs_fan_div(offset) \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 784 | static ssize_t show_regs_fan_div_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | { \ |
| 786 | return show_fan_div_reg(dev, buf, offset); \ |
| 787 | } \ |
| 788 | static ssize_t \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 789 | store_regs_fan_div_##offset (struct device *dev, struct device_attribute *attr, \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | const char *buf, size_t count) \ |
| 791 | { \ |
| 792 | return store_fan_div_reg(dev, buf, count, offset - 1); \ |
| 793 | } \ |
| 794 | static DEVICE_ATTR(fan##offset##_div, S_IRUGO | S_IWUSR, \ |
| 795 | show_regs_fan_div_##offset, store_regs_fan_div_##offset); |
| 796 | |
| 797 | sysfs_fan_div(1); |
| 798 | sysfs_fan_div(2); |
| 799 | sysfs_fan_div(3); |
| 800 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | static ssize_t |
| 802 | show_pwm_reg(struct device *dev, char *buf, int nr) |
| 803 | { |
| 804 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 805 | return sprintf(buf, "%ld\n", (long) data->pwm[nr - 1]); |
| 806 | } |
| 807 | |
| 808 | static ssize_t |
| 809 | store_pwm_reg(struct device *dev, const char *buf, size_t count, int nr) |
| 810 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 811 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | u32 val; |
| 813 | |
| 814 | val = simple_strtoul(buf, NULL, 10); |
| 815 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 816 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | |
| 818 | if (data->type == w83627thf) { |
| 819 | /* bits 0-3 are reserved in 627THF */ |
| 820 | data->pwm[nr - 1] = PWM_TO_REG(val) & 0xf0; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 821 | w83627hf_write_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | W836X7HF_REG_PWM(data->type, nr), |
| 823 | data->pwm[nr - 1] | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 824 | (w83627hf_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | W836X7HF_REG_PWM(data->type, nr)) & 0x0f)); |
| 826 | } else { |
| 827 | data->pwm[nr - 1] = PWM_TO_REG(val); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 828 | w83627hf_write_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | W836X7HF_REG_PWM(data->type, nr), |
| 830 | data->pwm[nr - 1]); |
| 831 | } |
| 832 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 833 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | return count; |
| 835 | } |
| 836 | |
| 837 | #define sysfs_pwm(offset) \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 838 | static ssize_t show_regs_pwm_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | { \ |
| 840 | return show_pwm_reg(dev, buf, offset); \ |
| 841 | } \ |
| 842 | static ssize_t \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 843 | store_regs_pwm_##offset (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] | 844 | { \ |
| 845 | return store_pwm_reg(dev, buf, count, offset); \ |
| 846 | } \ |
| 847 | static DEVICE_ATTR(pwm##offset, S_IRUGO | S_IWUSR, \ |
| 848 | show_regs_pwm_##offset, store_regs_pwm_##offset); |
| 849 | |
| 850 | sysfs_pwm(1); |
| 851 | sysfs_pwm(2); |
| 852 | sysfs_pwm(3); |
| 853 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 854 | static ssize_t |
| 855 | show_sensor_reg(struct device *dev, char *buf, int nr) |
| 856 | { |
| 857 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 858 | return sprintf(buf, "%ld\n", (long) data->sens[nr - 1]); |
| 859 | } |
| 860 | |
| 861 | static ssize_t |
| 862 | store_sensor_reg(struct device *dev, const char *buf, size_t count, int nr) |
| 863 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 864 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | u32 val, tmp; |
| 866 | |
| 867 | val = simple_strtoul(buf, NULL, 10); |
| 868 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 869 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | |
| 871 | switch (val) { |
| 872 | case 1: /* PII/Celeron diode */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 873 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); |
| 874 | w83627hf_write_value(data, W83781D_REG_SCFG1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | tmp | BIT_SCFG1[nr - 1]); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 876 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG2); |
| 877 | w83627hf_write_value(data, W83781D_REG_SCFG2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | tmp | BIT_SCFG2[nr - 1]); |
| 879 | data->sens[nr - 1] = val; |
| 880 | break; |
| 881 | case 2: /* 3904 */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 882 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); |
| 883 | w83627hf_write_value(data, W83781D_REG_SCFG1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 884 | tmp | BIT_SCFG1[nr - 1]); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 885 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG2); |
| 886 | w83627hf_write_value(data, W83781D_REG_SCFG2, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 887 | tmp & ~BIT_SCFG2[nr - 1]); |
| 888 | data->sens[nr - 1] = val; |
| 889 | break; |
| 890 | case W83781D_DEFAULT_BETA: /* thermistor */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 891 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); |
| 892 | w83627hf_write_value(data, W83781D_REG_SCFG1, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | tmp & ~BIT_SCFG1[nr - 1]); |
| 894 | data->sens[nr - 1] = val; |
| 895 | break; |
| 896 | default: |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 897 | dev_err(dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | "Invalid sensor type %ld; must be 1, 2, or %d\n", |
| 899 | (long) val, W83781D_DEFAULT_BETA); |
| 900 | break; |
| 901 | } |
| 902 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 903 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 904 | return count; |
| 905 | } |
| 906 | |
| 907 | #define sysfs_sensor(offset) \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 908 | static ssize_t show_regs_sensor_##offset (struct device *dev, struct device_attribute *attr, char *buf) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | { \ |
| 910 | return show_sensor_reg(dev, buf, offset); \ |
| 911 | } \ |
| 912 | static ssize_t \ |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 913 | store_regs_sensor_##offset (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] | 914 | { \ |
| 915 | return store_sensor_reg(dev, buf, count, offset); \ |
| 916 | } \ |
| 917 | static DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \ |
| 918 | show_regs_sensor_##offset, store_regs_sensor_##offset); |
| 919 | |
| 920 | sysfs_sensor(1); |
| 921 | sysfs_sensor(2); |
| 922 | sysfs_sensor(3); |
| 923 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 924 | static ssize_t show_name(struct device *dev, struct device_attribute |
| 925 | *devattr, char *buf) |
| 926 | { |
| 927 | struct w83627hf_data *data = dev_get_drvdata(dev); |
| 928 | |
| 929 | return sprintf(buf, "%s\n", data->name); |
| 930 | } |
| 931 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
| 932 | |
| 933 | static int __init w83627hf_find(int sioaddr, unsigned short *addr, |
| 934 | struct w83627hf_sio_data *sio_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | { |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 936 | int err = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | u16 val; |
| 938 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 939 | static const __initdata char *names[] = { |
| 940 | "W83627HF", |
| 941 | "W83627THF", |
| 942 | "W83697HF", |
| 943 | "W83637HF", |
| 944 | "W83687THF", |
| 945 | }; |
| 946 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | REG = sioaddr; |
| 948 | VAL = sioaddr + 1; |
| 949 | |
| 950 | superio_enter(); |
| 951 | val= superio_inb(DEVID); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 952 | switch (val) { |
| 953 | case W627_DEVID: |
| 954 | sio_data->type = w83627hf; |
| 955 | break; |
| 956 | case W627THF_DEVID: |
| 957 | sio_data->type = w83627thf; |
| 958 | break; |
| 959 | case W697_DEVID: |
| 960 | sio_data->type = w83697hf; |
| 961 | break; |
| 962 | case W637_DEVID: |
| 963 | sio_data->type = w83637hf; |
| 964 | break; |
| 965 | case W687THF_DEVID: |
| 966 | sio_data->type = w83687thf; |
| 967 | break; |
| 968 | default: |
| 969 | pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%x)\n", val); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 970 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | } |
| 972 | |
| 973 | superio_select(W83627HF_LD_HWM); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 974 | force_addr &= WINB_ALIGNMENT; |
| 975 | if (force_addr) { |
| 976 | printk(KERN_WARNING DRVNAME ": Forcing address 0x%x\n", |
| 977 | force_addr); |
| 978 | superio_outb(WINB_BASE_REG, force_addr >> 8); |
| 979 | superio_outb(WINB_BASE_REG + 1, force_addr & 0xff); |
| 980 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | val = (superio_inb(WINB_BASE_REG) << 8) | |
| 982 | superio_inb(WINB_BASE_REG + 1); |
Petr Vandrovec | ada0c2f | 2005-10-07 23:11:03 +0200 | [diff] [blame] | 983 | *addr = val & WINB_ALIGNMENT; |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 984 | if (*addr == 0) { |
| 985 | printk(KERN_WARNING DRVNAME ": Base address not set, " |
| 986 | "skipping\n"); |
| 987 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 990 | val = superio_inb(WINB_ACT_REG); |
| 991 | if (!(val & 0x01)) { |
| 992 | printk(KERN_WARNING DRVNAME ": Enabling HWM logical device\n"); |
| 993 | superio_outb(WINB_ACT_REG, val | 0x01); |
| 994 | } |
| 995 | |
| 996 | err = 0; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 997 | pr_info(DRVNAME ": Found %s chip at %#x\n", |
| 998 | names[sio_data->type], *addr); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 999 | |
| 1000 | exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | superio_exit(); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1002 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | } |
| 1004 | |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1005 | static struct attribute *w83627hf_attributes[] = { |
| 1006 | &dev_attr_in0_input.attr, |
| 1007 | &dev_attr_in0_min.attr, |
| 1008 | &dev_attr_in0_max.attr, |
| 1009 | &dev_attr_in2_input.attr, |
| 1010 | &dev_attr_in2_min.attr, |
| 1011 | &dev_attr_in2_max.attr, |
| 1012 | &dev_attr_in3_input.attr, |
| 1013 | &dev_attr_in3_min.attr, |
| 1014 | &dev_attr_in3_max.attr, |
| 1015 | &dev_attr_in4_input.attr, |
| 1016 | &dev_attr_in4_min.attr, |
| 1017 | &dev_attr_in4_max.attr, |
| 1018 | &dev_attr_in7_input.attr, |
| 1019 | &dev_attr_in7_min.attr, |
| 1020 | &dev_attr_in7_max.attr, |
| 1021 | &dev_attr_in8_input.attr, |
| 1022 | &dev_attr_in8_min.attr, |
| 1023 | &dev_attr_in8_max.attr, |
| 1024 | |
| 1025 | &dev_attr_fan1_input.attr, |
| 1026 | &dev_attr_fan1_min.attr, |
| 1027 | &dev_attr_fan1_div.attr, |
| 1028 | &dev_attr_fan2_input.attr, |
| 1029 | &dev_attr_fan2_min.attr, |
| 1030 | &dev_attr_fan2_div.attr, |
| 1031 | |
| 1032 | &dev_attr_temp1_input.attr, |
| 1033 | &dev_attr_temp1_max.attr, |
| 1034 | &dev_attr_temp1_max_hyst.attr, |
| 1035 | &dev_attr_temp1_type.attr, |
| 1036 | &dev_attr_temp2_input.attr, |
| 1037 | &dev_attr_temp2_max.attr, |
| 1038 | &dev_attr_temp2_max_hyst.attr, |
| 1039 | &dev_attr_temp2_type.attr, |
| 1040 | |
| 1041 | &dev_attr_alarms.attr, |
| 1042 | &dev_attr_beep_enable.attr, |
| 1043 | &dev_attr_beep_mask.attr, |
| 1044 | |
| 1045 | &dev_attr_pwm1.attr, |
| 1046 | &dev_attr_pwm2.attr, |
| 1047 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1048 | &dev_attr_name.attr, |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1049 | NULL |
| 1050 | }; |
| 1051 | |
| 1052 | static const struct attribute_group w83627hf_group = { |
| 1053 | .attrs = w83627hf_attributes, |
| 1054 | }; |
| 1055 | |
| 1056 | static struct attribute *w83627hf_attributes_opt[] = { |
| 1057 | &dev_attr_in1_input.attr, |
| 1058 | &dev_attr_in1_min.attr, |
| 1059 | &dev_attr_in1_max.attr, |
| 1060 | &dev_attr_in5_input.attr, |
| 1061 | &dev_attr_in5_min.attr, |
| 1062 | &dev_attr_in5_max.attr, |
| 1063 | &dev_attr_in6_input.attr, |
| 1064 | &dev_attr_in6_min.attr, |
| 1065 | &dev_attr_in6_max.attr, |
| 1066 | |
| 1067 | &dev_attr_fan3_input.attr, |
| 1068 | &dev_attr_fan3_min.attr, |
| 1069 | &dev_attr_fan3_div.attr, |
| 1070 | |
| 1071 | &dev_attr_temp3_input.attr, |
| 1072 | &dev_attr_temp3_max.attr, |
| 1073 | &dev_attr_temp3_max_hyst.attr, |
| 1074 | &dev_attr_temp3_type.attr, |
| 1075 | |
| 1076 | &dev_attr_pwm3.attr, |
| 1077 | |
| 1078 | NULL |
| 1079 | }; |
| 1080 | |
| 1081 | static const struct attribute_group w83627hf_group_opt = { |
| 1082 | .attrs = w83627hf_attributes_opt, |
| 1083 | }; |
| 1084 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1085 | static int __devinit w83627hf_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1087 | struct device *dev = &pdev->dev; |
| 1088 | struct w83627hf_sio_data *sio_data = dev->platform_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | struct w83627hf_data *data; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1090 | struct resource *res; |
| 1091 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1093 | static const char *names[] = { |
| 1094 | "w83627hf", |
| 1095 | "w83627thf", |
| 1096 | "w83697hf", |
| 1097 | "w83637hf", |
| 1098 | "w83687thf", |
| 1099 | }; |
| 1100 | |
| 1101 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
| 1102 | if (!request_region(res->start, WINB_REGION_SIZE, DRVNAME)) { |
| 1103 | dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", |
| 1104 | (unsigned long)res->start, |
| 1105 | (unsigned long)(res->start + WINB_REGION_SIZE - 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | err = -EBUSY; |
| 1107 | goto ERROR0; |
| 1108 | } |
| 1109 | |
Deepak Saxena | ba9c2e8 | 2005-10-17 23:08:32 +0200 | [diff] [blame] | 1110 | if (!(data = kzalloc(sizeof(struct w83627hf_data), GFP_KERNEL))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | err = -ENOMEM; |
| 1112 | goto ERROR1; |
| 1113 | } |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1114 | data->addr = res->start; |
| 1115 | data->type = sio_data->type; |
| 1116 | data->name = names[sio_data->type]; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1117 | mutex_init(&data->lock); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1118 | mutex_init(&data->update_lock); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1119 | platform_set_drvdata(pdev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | /* Initialize the chip */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1122 | w83627hf_init_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | |
| 1124 | /* A few vars need to be filled upon startup */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1125 | data->fan_min[0] = w83627hf_read_value(data, W83781D_REG_FAN_MIN(1)); |
| 1126 | data->fan_min[1] = w83627hf_read_value(data, W83781D_REG_FAN_MIN(2)); |
| 1127 | data->fan_min[2] = w83627hf_read_value(data, W83781D_REG_FAN_MIN(3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1128 | |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1129 | /* Register common device attributes */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1130 | if ((err = sysfs_create_group(&dev->kobj, &w83627hf_group))) |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1131 | goto ERROR3; |
| 1132 | |
| 1133 | /* Register chip-specific device attributes */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1134 | if (data->type == w83627hf || data->type == w83697hf) |
| 1135 | if ((err = device_create_file(dev, &dev_attr_in5_input)) |
| 1136 | || (err = device_create_file(dev, &dev_attr_in5_min)) |
| 1137 | || (err = device_create_file(dev, &dev_attr_in5_max)) |
| 1138 | || (err = device_create_file(dev, &dev_attr_in6_input)) |
| 1139 | || (err = device_create_file(dev, &dev_attr_in6_min)) |
| 1140 | || (err = device_create_file(dev, &dev_attr_in6_max))) |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1141 | goto ERROR4; |
| 1142 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1143 | if (data->type != w83697hf) |
| 1144 | if ((err = device_create_file(dev, &dev_attr_in1_input)) |
| 1145 | || (err = device_create_file(dev, &dev_attr_in1_min)) |
| 1146 | || (err = device_create_file(dev, &dev_attr_in1_max)) |
| 1147 | || (err = device_create_file(dev, &dev_attr_fan3_input)) |
| 1148 | || (err = device_create_file(dev, &dev_attr_fan3_min)) |
| 1149 | || (err = device_create_file(dev, &dev_attr_fan3_div)) |
| 1150 | || (err = device_create_file(dev, &dev_attr_temp3_input)) |
| 1151 | || (err = device_create_file(dev, &dev_attr_temp3_max)) |
| 1152 | || (err = device_create_file(dev, &dev_attr_temp3_max_hyst)) |
| 1153 | || (err = device_create_file(dev, &dev_attr_temp3_type))) |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1154 | goto ERROR4; |
| 1155 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1156 | if (data->type != w83697hf && data->vid != 0xff) { |
Jean Delvare | 8a665a0 | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1157 | /* Convert VID to voltage based on VRM */ |
| 1158 | data->vrm = vid_which_vrm(); |
| 1159 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1160 | if ((err = device_create_file(dev, &dev_attr_cpu0_vid)) |
| 1161 | || (err = device_create_file(dev, &dev_attr_vrm))) |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1162 | goto ERROR4; |
Jean Delvare | 8a665a0 | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1163 | } |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1164 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1165 | if (data->type == w83627thf || data->type == w83637hf |
| 1166 | || data->type == w83687thf) |
| 1167 | if ((err = device_create_file(dev, &dev_attr_pwm3))) |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1168 | goto ERROR4; |
| 1169 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1170 | data->class_dev = hwmon_device_register(dev); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1171 | if (IS_ERR(data->class_dev)) { |
| 1172 | err = PTR_ERR(data->class_dev); |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1173 | goto ERROR4; |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1174 | } |
| 1175 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | return 0; |
| 1177 | |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1178 | ERROR4: |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1179 | sysfs_remove_group(&dev->kobj, &w83627hf_group); |
| 1180 | sysfs_remove_group(&dev->kobj, &w83627hf_group_opt); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1181 | ERROR3: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | kfree(data); |
| 1183 | ERROR1: |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1184 | release_region(res->start, WINB_REGION_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | ERROR0: |
| 1186 | return err; |
| 1187 | } |
| 1188 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1189 | static int __devexit w83627hf_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1191 | struct w83627hf_data *data = platform_get_drvdata(pdev); |
| 1192 | struct resource *res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1194 | platform_set_drvdata(pdev, NULL); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1195 | hwmon_device_unregister(data->class_dev); |
| 1196 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1197 | sysfs_remove_group(&pdev->dev.kobj, &w83627hf_group); |
| 1198 | sysfs_remove_group(&pdev->dev.kobj, &w83627hf_group_opt); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1199 | kfree(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1201 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
| 1202 | release_region(res->start, WINB_REGION_SIZE); |
| 1203 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | return 0; |
| 1205 | } |
| 1206 | |
| 1207 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1208 | static int w83627hf_read_value(struct w83627hf_data *data, u16 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | int res, word_sized; |
| 1211 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1212 | mutex_lock(&data->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1213 | word_sized = (((reg & 0xff00) == 0x100) |
| 1214 | || ((reg & 0xff00) == 0x200)) |
| 1215 | && (((reg & 0x00ff) == 0x50) |
| 1216 | || ((reg & 0x00ff) == 0x53) |
| 1217 | || ((reg & 0x00ff) == 0x55)); |
| 1218 | if (reg & 0xff00) { |
| 1219 | outb_p(W83781D_REG_BANK, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1220 | data->addr + W83781D_ADDR_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1221 | outb_p(reg >> 8, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1222 | data->addr + W83781D_DATA_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | } |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1224 | outb_p(reg & 0xff, data->addr + W83781D_ADDR_REG_OFFSET); |
| 1225 | res = inb_p(data->addr + W83781D_DATA_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1226 | if (word_sized) { |
| 1227 | outb_p((reg & 0xff) + 1, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1228 | data->addr + W83781D_ADDR_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | res = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1230 | (res << 8) + inb_p(data->addr + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1231 | W83781D_DATA_REG_OFFSET); |
| 1232 | } |
| 1233 | if (reg & 0xff00) { |
| 1234 | outb_p(W83781D_REG_BANK, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1235 | data->addr + W83781D_ADDR_REG_OFFSET); |
| 1236 | outb_p(0, data->addr + W83781D_DATA_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | } |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1238 | mutex_unlock(&data->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | return res; |
| 1240 | } |
| 1241 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1242 | static int __devinit w83627thf_read_gpio5(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | { |
| 1244 | int res = 0xff, sel; |
| 1245 | |
| 1246 | superio_enter(); |
| 1247 | superio_select(W83627HF_LD_GPIO5); |
| 1248 | |
| 1249 | /* Make sure these GPIO pins are enabled */ |
| 1250 | if (!(superio_inb(W83627THF_GPIO5_EN) & (1<<3))) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1251 | dev_dbg(&pdev->dev, "GPIO5 disabled, no VID function\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | goto exit; |
| 1253 | } |
| 1254 | |
| 1255 | /* Make sure the pins are configured for input |
| 1256 | There must be at least five (VRM 9), and possibly 6 (VRM 10) */ |
Yuan Mu | dd149c5 | 2005-11-26 20:13:18 +0100 | [diff] [blame] | 1257 | sel = superio_inb(W83627THF_GPIO5_IOSR) & 0x3f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | if ((sel & 0x1f) != 0x1f) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1259 | dev_dbg(&pdev->dev, "GPIO5 not configured for VID " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | "function\n"); |
| 1261 | goto exit; |
| 1262 | } |
| 1263 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1264 | dev_info(&pdev->dev, "Reading VID from GPIO5\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1265 | res = superio_inb(W83627THF_GPIO5_DR) & sel; |
| 1266 | |
| 1267 | exit: |
| 1268 | superio_exit(); |
| 1269 | return res; |
| 1270 | } |
| 1271 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1272 | static int __devinit w83687thf_read_vid(struct platform_device *pdev) |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 1273 | { |
| 1274 | int res = 0xff; |
| 1275 | |
| 1276 | superio_enter(); |
| 1277 | superio_select(W83627HF_LD_HWM); |
| 1278 | |
| 1279 | /* Make sure these GPIO pins are enabled */ |
| 1280 | if (!(superio_inb(W83687THF_VID_EN) & (1 << 2))) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1281 | dev_dbg(&pdev->dev, "VID disabled, no VID function\n"); |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 1282 | goto exit; |
| 1283 | } |
| 1284 | |
| 1285 | /* Make sure the pins are configured for input */ |
| 1286 | if (!(superio_inb(W83687THF_VID_CFG) & (1 << 4))) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1287 | dev_dbg(&pdev->dev, "VID configured as output, " |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 1288 | "no VID function\n"); |
| 1289 | goto exit; |
| 1290 | } |
| 1291 | |
| 1292 | res = superio_inb(W83687THF_VID_DATA) & 0x3f; |
| 1293 | |
| 1294 | exit: |
| 1295 | superio_exit(); |
| 1296 | return res; |
| 1297 | } |
| 1298 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1299 | static int w83627hf_write_value(struct w83627hf_data *data, u16 reg, u16 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | int word_sized; |
| 1302 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1303 | mutex_lock(&data->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | word_sized = (((reg & 0xff00) == 0x100) |
| 1305 | || ((reg & 0xff00) == 0x200)) |
| 1306 | && (((reg & 0x00ff) == 0x53) |
| 1307 | || ((reg & 0x00ff) == 0x55)); |
| 1308 | if (reg & 0xff00) { |
| 1309 | outb_p(W83781D_REG_BANK, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1310 | data->addr + W83781D_ADDR_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1311 | outb_p(reg >> 8, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1312 | data->addr + W83781D_DATA_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | } |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1314 | outb_p(reg & 0xff, data->addr + W83781D_ADDR_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | if (word_sized) { |
| 1316 | outb_p(value >> 8, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1317 | data->addr + W83781D_DATA_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | outb_p((reg & 0xff) + 1, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1319 | data->addr + W83781D_ADDR_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | } |
| 1321 | outb_p(value & 0xff, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1322 | data->addr + W83781D_DATA_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | if (reg & 0xff00) { |
| 1324 | outb_p(W83781D_REG_BANK, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1325 | data->addr + W83781D_ADDR_REG_OFFSET); |
| 1326 | outb_p(0, data->addr + W83781D_DATA_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | } |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1328 | mutex_unlock(&data->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | return 0; |
| 1330 | } |
| 1331 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1332 | static void __devinit w83627hf_init_device(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1334 | struct w83627hf_data *data = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | int i; |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1336 | enum chips type = data->type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | u8 tmp; |
| 1338 | |
Jean Delvare | 2251cf1 | 2005-09-04 22:52:17 +0200 | [diff] [blame] | 1339 | if (reset) { |
| 1340 | /* Resetting the chip has been the default for a long time, |
| 1341 | but repeatedly caused problems (fans going to full |
| 1342 | speed...) so it is now optional. It might even go away if |
| 1343 | nobody reports it as being useful, as I see very little |
| 1344 | reason why this would be needed at all. */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1345 | dev_info(&pdev->dev, "If reset=1 solved a problem you were " |
Jean Delvare | 2251cf1 | 2005-09-04 22:52:17 +0200 | [diff] [blame] | 1346 | "having, please report!\n"); |
| 1347 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | /* save this register */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1349 | i = w83627hf_read_value(data, W83781D_REG_BEEP_CONFIG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1350 | /* Reset all except Watchdog values and last conversion values |
| 1351 | This sets fan-divs to 2, among others */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1352 | w83627hf_write_value(data, W83781D_REG_CONFIG, 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | /* Restore the register and disable power-on abnormal beep. |
| 1354 | This saves FAN 1/2/3 input/output values set by BIOS. */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1355 | w83627hf_write_value(data, W83781D_REG_BEEP_CONFIG, i | 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | /* Disable master beep-enable (reset turns it on). |
| 1357 | Individual beeps should be reset to off but for some reason |
| 1358 | disabling this bit helps some people not get beeped */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1359 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS2, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | } |
| 1361 | |
| 1362 | /* Minimize conflicts with other winbond i2c-only clients... */ |
| 1363 | /* disable i2c subclients... how to disable main i2c client?? */ |
| 1364 | /* force i2c address to relatively uncommon address */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1365 | w83627hf_write_value(data, W83781D_REG_I2C_SUBADDR, 0x89); |
| 1366 | w83627hf_write_value(data, W83781D_REG_I2C_ADDR, force_i2c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1367 | |
| 1368 | /* Read VID only once */ |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1369 | if (type == w83627hf || type == w83637hf) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1370 | int lo = w83627hf_read_value(data, W83781D_REG_VID_FANDIV); |
| 1371 | int hi = w83627hf_read_value(data, W83781D_REG_CHIPID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | data->vid = (lo & 0x0f) | ((hi & 0x01) << 4); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1373 | } else if (type == w83627thf) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1374 | data->vid = w83627thf_read_gpio5(pdev); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1375 | } else if (type == w83687thf) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1376 | data->vid = w83687thf_read_vid(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | } |
| 1378 | |
| 1379 | /* Read VRM & OVT Config only once */ |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1380 | if (type == w83627thf || type == w83637hf || type == w83687thf) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | data->vrm_ovt = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1382 | w83627hf_read_value(data, W83627THF_REG_VRM_OVT_CFG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | } |
| 1384 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1385 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | for (i = 1; i <= 3; i++) { |
| 1387 | if (!(tmp & BIT_SCFG1[i - 1])) { |
| 1388 | data->sens[i - 1] = W83781D_DEFAULT_BETA; |
| 1389 | } else { |
| 1390 | if (w83627hf_read_value |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1391 | (data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1392 | W83781D_REG_SCFG2) & BIT_SCFG2[i - 1]) |
| 1393 | data->sens[i - 1] = 1; |
| 1394 | else |
| 1395 | data->sens[i - 1] = 2; |
| 1396 | } |
| 1397 | if ((type == w83697hf) && (i == 2)) |
| 1398 | break; |
| 1399 | } |
| 1400 | |
| 1401 | if(init) { |
| 1402 | /* Enable temp2 */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1403 | tmp = w83627hf_read_value(data, W83781D_REG_TEMP2_CONFIG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | if (tmp & 0x01) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1405 | dev_warn(&pdev->dev, "Enabling temp2, readings " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | "might not make sense\n"); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1407 | w83627hf_write_value(data, W83781D_REG_TEMP2_CONFIG, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | tmp & 0xfe); |
| 1409 | } |
| 1410 | |
| 1411 | /* Enable temp3 */ |
| 1412 | if (type != w83697hf) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1413 | tmp = w83627hf_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | W83781D_REG_TEMP3_CONFIG); |
| 1415 | if (tmp & 0x01) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1416 | dev_warn(&pdev->dev, "Enabling temp3, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | "readings might not make sense\n"); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1418 | w83627hf_write_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1419 | W83781D_REG_TEMP3_CONFIG, tmp & 0xfe); |
| 1420 | } |
| 1421 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | /* Start monitoring */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1425 | w83627hf_write_value(data, W83781D_REG_CONFIG, |
| 1426 | (w83627hf_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | W83781D_REG_CONFIG) & 0xf7) |
| 1428 | | 0x01); |
| 1429 | } |
| 1430 | |
| 1431 | static struct w83627hf_data *w83627hf_update_device(struct device *dev) |
| 1432 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1433 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | int i; |
| 1435 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1436 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | |
| 1438 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
| 1439 | || !data->valid) { |
| 1440 | for (i = 0; i <= 8; i++) { |
| 1441 | /* skip missing sensors */ |
| 1442 | if (((data->type == w83697hf) && (i == 1)) || |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 1443 | ((data->type != w83627hf && data->type != w83697hf) |
Yuan Mu | 4a1c4447 | 2005-11-07 22:19:04 +0100 | [diff] [blame] | 1444 | && (i == 5 || i == 6))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | continue; |
| 1446 | data->in[i] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1447 | w83627hf_read_value(data, W83781D_REG_IN(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | data->in_min[i] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1449 | w83627hf_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1450 | W83781D_REG_IN_MIN(i)); |
| 1451 | data->in_max[i] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1452 | w83627hf_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | W83781D_REG_IN_MAX(i)); |
| 1454 | } |
| 1455 | for (i = 1; i <= 3; i++) { |
| 1456 | data->fan[i - 1] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1457 | w83627hf_read_value(data, W83781D_REG_FAN(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | data->fan_min[i - 1] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1459 | w83627hf_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1460 | W83781D_REG_FAN_MIN(i)); |
| 1461 | } |
| 1462 | for (i = 1; i <= 3; i++) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1463 | u8 tmp = w83627hf_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | W836X7HF_REG_PWM(data->type, i)); |
| 1465 | /* bits 0-3 are reserved in 627THF */ |
| 1466 | if (data->type == w83627thf) |
| 1467 | tmp &= 0xf0; |
| 1468 | data->pwm[i - 1] = tmp; |
| 1469 | if(i == 2 && |
| 1470 | (data->type == w83627hf || data->type == w83697hf)) |
| 1471 | break; |
| 1472 | } |
| 1473 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1474 | data->temp = w83627hf_read_value(data, W83781D_REG_TEMP(1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | data->temp_max = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1476 | w83627hf_read_value(data, W83781D_REG_TEMP_OVER(1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | data->temp_max_hyst = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1478 | w83627hf_read_value(data, W83781D_REG_TEMP_HYST(1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | data->temp_add[0] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1480 | w83627hf_read_value(data, W83781D_REG_TEMP(2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1481 | data->temp_max_add[0] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1482 | w83627hf_read_value(data, W83781D_REG_TEMP_OVER(2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | data->temp_max_hyst_add[0] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1484 | w83627hf_read_value(data, W83781D_REG_TEMP_HYST(2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | if (data->type != w83697hf) { |
| 1486 | data->temp_add[1] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1487 | w83627hf_read_value(data, W83781D_REG_TEMP(3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1488 | data->temp_max_add[1] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1489 | w83627hf_read_value(data, W83781D_REG_TEMP_OVER(3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | data->temp_max_hyst_add[1] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1491 | w83627hf_read_value(data, W83781D_REG_TEMP_HYST(3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1494 | i = w83627hf_read_value(data, W83781D_REG_VID_FANDIV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | data->fan_div[0] = (i >> 4) & 0x03; |
| 1496 | data->fan_div[1] = (i >> 6) & 0x03; |
| 1497 | if (data->type != w83697hf) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1498 | data->fan_div[2] = (w83627hf_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | W83781D_REG_PIN) >> 6) & 0x03; |
| 1500 | } |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1501 | i = w83627hf_read_value(data, W83781D_REG_VBAT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1502 | data->fan_div[0] |= (i >> 3) & 0x04; |
| 1503 | data->fan_div[1] |= (i >> 4) & 0x04; |
| 1504 | if (data->type != w83697hf) |
| 1505 | data->fan_div[2] |= (i >> 5) & 0x04; |
| 1506 | data->alarms = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1507 | w83627hf_read_value(data, W83781D_REG_ALARM1) | |
| 1508 | (w83627hf_read_value(data, W83781D_REG_ALARM2) << 8) | |
| 1509 | (w83627hf_read_value(data, W83781D_REG_ALARM3) << 16); |
| 1510 | i = w83627hf_read_value(data, W83781D_REG_BEEP_INTS2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1511 | data->beep_enable = i >> 7; |
| 1512 | data->beep_mask = ((i & 0x7f) << 8) | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1513 | w83627hf_read_value(data, W83781D_REG_BEEP_INTS1) | |
| 1514 | w83627hf_read_value(data, W83781D_REG_BEEP_INTS3) << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | data->last_updated = jiffies; |
| 1516 | data->valid = 1; |
| 1517 | } |
| 1518 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1519 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | |
| 1521 | return data; |
| 1522 | } |
| 1523 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1524 | static int __init w83627hf_device_add(unsigned short address, |
| 1525 | const struct w83627hf_sio_data *sio_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1527 | struct resource res = { |
| 1528 | .start = address + WINB_REGION_OFFSET, |
| 1529 | .end = address + WINB_REGION_OFFSET + WINB_REGION_SIZE - 1, |
| 1530 | .name = DRVNAME, |
| 1531 | .flags = IORESOURCE_IO, |
| 1532 | }; |
| 1533 | int err; |
| 1534 | |
| 1535 | pdev = platform_device_alloc(DRVNAME, address); |
| 1536 | if (!pdev) { |
| 1537 | err = -ENOMEM; |
| 1538 | printk(KERN_ERR DRVNAME ": Device allocation failed\n"); |
| 1539 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1542 | err = platform_device_add_resources(pdev, &res, 1); |
| 1543 | if (err) { |
| 1544 | printk(KERN_ERR DRVNAME ": Device resource addition failed " |
| 1545 | "(%d)\n", err); |
| 1546 | goto exit_device_put; |
| 1547 | } |
| 1548 | |
| 1549 | pdev->dev.platform_data = kmalloc(sizeof(struct w83627hf_sio_data), |
| 1550 | GFP_KERNEL); |
| 1551 | if (!pdev->dev.platform_data) { |
| 1552 | err = -ENOMEM; |
| 1553 | printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); |
| 1554 | goto exit_device_put; |
| 1555 | } |
| 1556 | memcpy(pdev->dev.platform_data, sio_data, |
| 1557 | sizeof(struct w83627hf_sio_data)); |
| 1558 | |
| 1559 | err = platform_device_add(pdev); |
| 1560 | if (err) { |
| 1561 | printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", |
| 1562 | err); |
| 1563 | goto exit_device_put; |
| 1564 | } |
| 1565 | |
| 1566 | return 0; |
| 1567 | |
| 1568 | exit_device_put: |
| 1569 | platform_device_put(pdev); |
| 1570 | exit: |
| 1571 | return err; |
| 1572 | } |
| 1573 | |
| 1574 | static int __init sensors_w83627hf_init(void) |
| 1575 | { |
| 1576 | int err; |
| 1577 | unsigned short address; |
| 1578 | struct w83627hf_sio_data sio_data; |
| 1579 | |
| 1580 | if (w83627hf_find(0x2e, &address, &sio_data) |
| 1581 | && w83627hf_find(0x4e, &address, &sio_data)) |
| 1582 | return -ENODEV; |
| 1583 | |
| 1584 | err = platform_driver_register(&w83627hf_driver); |
| 1585 | if (err) |
| 1586 | goto exit; |
| 1587 | |
| 1588 | /* Sets global pdev as a side effect */ |
| 1589 | err = w83627hf_device_add(address, &sio_data); |
| 1590 | if (err) |
| 1591 | goto exit_driver; |
| 1592 | |
| 1593 | return 0; |
| 1594 | |
| 1595 | exit_driver: |
| 1596 | platform_driver_unregister(&w83627hf_driver); |
| 1597 | exit: |
| 1598 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | } |
| 1600 | |
| 1601 | static void __exit sensors_w83627hf_exit(void) |
| 1602 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1603 | platform_device_unregister(pdev); |
| 1604 | platform_driver_unregister(&w83627hf_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | } |
| 1606 | |
| 1607 | MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, " |
| 1608 | "Philip Edelbrock <phil@netroedge.com>, " |
| 1609 | "and Mark Studebaker <mdsxyz123@yahoo.com>"); |
| 1610 | MODULE_DESCRIPTION("W83627HF driver"); |
| 1611 | MODULE_LICENSE("GPL"); |
| 1612 | |
| 1613 | module_init(sensors_w83627hf_init); |
| 1614 | module_exit(sensors_w83627hf_exit); |