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> |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 48 | #include <linux/hwmon-sysfs.h> |
Jean Delvare | 303760b | 2005-07-31 21:52:01 +0200 | [diff] [blame] | 49 | #include <linux/hwmon-vid.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 50 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 51 | #include <linux/mutex.h> |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 52 | #include <linux/ioport.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #include <asm/io.h> |
| 54 | #include "lm75.h" |
| 55 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 56 | static struct platform_device *pdev; |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 57 | |
| 58 | #define DRVNAME "w83627hf" |
| 59 | enum chips { w83627hf, w83627thf, w83697hf, w83637hf, w83687thf }; |
| 60 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | static u16 force_addr; |
| 62 | module_param(force_addr, ushort, 0); |
| 63 | MODULE_PARM_DESC(force_addr, |
| 64 | "Initialize the base address of the sensors"); |
| 65 | static u8 force_i2c = 0x1f; |
| 66 | module_param(force_i2c, byte, 0); |
| 67 | MODULE_PARM_DESC(force_i2c, |
| 68 | "Initialize the i2c address of the sensors"); |
| 69 | |
Jean Delvare | 2251cf1 | 2005-09-04 22:52:17 +0200 | [diff] [blame] | 70 | static int reset; |
| 71 | module_param(reset, bool, 0); |
| 72 | MODULE_PARM_DESC(reset, "Set to one to reset chip on load"); |
| 73 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | static int init = 1; |
| 75 | module_param(init, bool, 0); |
| 76 | MODULE_PARM_DESC(init, "Set to zero to bypass chip initialization"); |
| 77 | |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 78 | static unsigned short force_id; |
| 79 | module_param(force_id, ushort, 0); |
| 80 | MODULE_PARM_DESC(force_id, "Override the detected device ID"); |
| 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /* modified from kernel/include/traps.c */ |
| 83 | static int REG; /* The register to read/write */ |
| 84 | #define DEV 0x07 /* Register: Logical device select */ |
| 85 | static int VAL; /* The value to read/write */ |
| 86 | |
| 87 | /* logical device numbers for superio_select (below) */ |
| 88 | #define W83627HF_LD_FDC 0x00 |
| 89 | #define W83627HF_LD_PRT 0x01 |
| 90 | #define W83627HF_LD_UART1 0x02 |
| 91 | #define W83627HF_LD_UART2 0x03 |
| 92 | #define W83627HF_LD_KBC 0x05 |
| 93 | #define W83627HF_LD_CIR 0x06 /* w83627hf only */ |
| 94 | #define W83627HF_LD_GAME 0x07 |
| 95 | #define W83627HF_LD_MIDI 0x07 |
| 96 | #define W83627HF_LD_GPIO1 0x07 |
| 97 | #define W83627HF_LD_GPIO5 0x07 /* w83627thf only */ |
| 98 | #define W83627HF_LD_GPIO2 0x08 |
| 99 | #define W83627HF_LD_GPIO3 0x09 |
| 100 | #define W83627HF_LD_GPIO4 0x09 /* w83627thf only */ |
| 101 | #define W83627HF_LD_ACPI 0x0a |
| 102 | #define W83627HF_LD_HWM 0x0b |
| 103 | |
| 104 | #define DEVID 0x20 /* Register: Device ID */ |
| 105 | |
| 106 | #define W83627THF_GPIO5_EN 0x30 /* w83627thf only */ |
| 107 | #define W83627THF_GPIO5_IOSR 0xf3 /* w83627thf only */ |
| 108 | #define W83627THF_GPIO5_DR 0xf4 /* w83627thf only */ |
| 109 | |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 110 | #define W83687THF_VID_EN 0x29 /* w83687thf only */ |
| 111 | #define W83687THF_VID_CFG 0xF0 /* w83687thf only */ |
| 112 | #define W83687THF_VID_DATA 0xF1 /* w83687thf only */ |
| 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | static inline void |
| 115 | superio_outb(int reg, int val) |
| 116 | { |
| 117 | outb(reg, REG); |
| 118 | outb(val, VAL); |
| 119 | } |
| 120 | |
| 121 | static inline int |
| 122 | superio_inb(int reg) |
| 123 | { |
| 124 | outb(reg, REG); |
| 125 | return inb(VAL); |
| 126 | } |
| 127 | |
| 128 | static inline void |
| 129 | superio_select(int ld) |
| 130 | { |
| 131 | outb(DEV, REG); |
| 132 | outb(ld, VAL); |
| 133 | } |
| 134 | |
| 135 | static inline void |
| 136 | superio_enter(void) |
| 137 | { |
| 138 | outb(0x87, REG); |
| 139 | outb(0x87, REG); |
| 140 | } |
| 141 | |
| 142 | static inline void |
| 143 | superio_exit(void) |
| 144 | { |
| 145 | outb(0xAA, REG); |
| 146 | } |
| 147 | |
| 148 | #define W627_DEVID 0x52 |
| 149 | #define W627THF_DEVID 0x82 |
| 150 | #define W697_DEVID 0x60 |
| 151 | #define W637_DEVID 0x70 |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 152 | #define W687THF_DEVID 0x85 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | #define WINB_ACT_REG 0x30 |
| 154 | #define WINB_BASE_REG 0x60 |
| 155 | /* Constants specified below */ |
| 156 | |
Petr Vandrovec | ada0c2f | 2005-10-07 23:11:03 +0200 | [diff] [blame] | 157 | /* Alignment of the base address */ |
| 158 | #define WINB_ALIGNMENT ~7 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | |
Petr Vandrovec | ada0c2f | 2005-10-07 23:11:03 +0200 | [diff] [blame] | 160 | /* Offset & size of I/O region we are interested in */ |
| 161 | #define WINB_REGION_OFFSET 5 |
| 162 | #define WINB_REGION_SIZE 2 |
| 163 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 164 | /* Where are the sensors address/data registers relative to the region offset */ |
| 165 | #define W83781D_ADDR_REG_OFFSET 0 |
| 166 | #define W83781D_DATA_REG_OFFSET 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | |
| 168 | /* The W83781D registers */ |
| 169 | /* The W83782D registers for nr=7,8 are in bank 5 */ |
| 170 | #define W83781D_REG_IN_MAX(nr) ((nr < 7) ? (0x2b + (nr) * 2) : \ |
| 171 | (0x554 + (((nr) - 7) * 2))) |
| 172 | #define W83781D_REG_IN_MIN(nr) ((nr < 7) ? (0x2c + (nr) * 2) : \ |
| 173 | (0x555 + (((nr) - 7) * 2))) |
| 174 | #define W83781D_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \ |
| 175 | (0x550 + (nr) - 7)) |
| 176 | |
Jim Cromie | 2ca2fcd | 2007-10-14 17:20:50 -0600 | [diff] [blame] | 177 | /* nr:0-2 for fans:1-3 */ |
| 178 | #define W83627HF_REG_FAN_MIN(nr) (0x3b + (nr)) |
| 179 | #define W83627HF_REG_FAN(nr) (0x28 + (nr)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 181 | #define W83627HF_REG_TEMP2_CONFIG 0x152 |
| 182 | #define W83627HF_REG_TEMP3_CONFIG 0x252 |
| 183 | /* these are zero-based, unlike config constants above */ |
| 184 | static const u16 w83627hf_reg_temp[] = { 0x27, 0x150, 0x250 }; |
| 185 | static const u16 w83627hf_reg_temp_hyst[] = { 0x3A, 0x153, 0x253 }; |
| 186 | static const u16 w83627hf_reg_temp_over[] = { 0x39, 0x155, 0x255 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | #define W83781D_REG_BANK 0x4E |
| 189 | |
| 190 | #define W83781D_REG_CONFIG 0x40 |
Yuan Mu | 4a1c4447 | 2005-11-07 22:19:04 +0100 | [diff] [blame] | 191 | #define W83781D_REG_ALARM1 0x459 |
| 192 | #define W83781D_REG_ALARM2 0x45A |
| 193 | #define W83781D_REG_ALARM3 0x45B |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | #define W83781D_REG_BEEP_CONFIG 0x4D |
| 196 | #define W83781D_REG_BEEP_INTS1 0x56 |
| 197 | #define W83781D_REG_BEEP_INTS2 0x57 |
| 198 | #define W83781D_REG_BEEP_INTS3 0x453 |
| 199 | |
| 200 | #define W83781D_REG_VID_FANDIV 0x47 |
| 201 | |
| 202 | #define W83781D_REG_CHIPID 0x49 |
| 203 | #define W83781D_REG_WCHIPID 0x58 |
| 204 | #define W83781D_REG_CHIPMAN 0x4F |
| 205 | #define W83781D_REG_PIN 0x4B |
| 206 | |
| 207 | #define W83781D_REG_VBAT 0x5D |
| 208 | |
| 209 | #define W83627HF_REG_PWM1 0x5A |
| 210 | #define W83627HF_REG_PWM2 0x5B |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 212 | #define W83627THF_REG_PWM1 0x01 /* 697HF/637HF/687THF too */ |
| 213 | #define W83627THF_REG_PWM2 0x03 /* 697HF/637HF/687THF too */ |
| 214 | #define W83627THF_REG_PWM3 0x11 /* 637HF/687THF too */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 216 | #define W83627THF_REG_VRM_OVT_CFG 0x18 /* 637HF/687THF too */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
| 218 | static const u8 regpwm_627hf[] = { W83627HF_REG_PWM1, W83627HF_REG_PWM2 }; |
| 219 | static const u8 regpwm[] = { W83627THF_REG_PWM1, W83627THF_REG_PWM2, |
| 220 | W83627THF_REG_PWM3 }; |
| 221 | #define W836X7HF_REG_PWM(type, nr) (((type) == w83627hf) ? \ |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 222 | regpwm_627hf[nr] : regpwm[nr]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 224 | #define W83627HF_REG_PWM_FREQ 0x5C /* Only for the 627HF */ |
| 225 | |
| 226 | #define W83637HF_REG_PWM_FREQ1 0x00 /* 697HF/687THF too */ |
| 227 | #define W83637HF_REG_PWM_FREQ2 0x02 /* 697HF/687THF too */ |
| 228 | #define W83637HF_REG_PWM_FREQ3 0x10 /* 687THF too */ |
| 229 | |
| 230 | static const u8 W83637HF_REG_PWM_FREQ[] = { W83637HF_REG_PWM_FREQ1, |
| 231 | W83637HF_REG_PWM_FREQ2, |
| 232 | W83637HF_REG_PWM_FREQ3 }; |
| 233 | |
| 234 | #define W83627HF_BASE_PWM_FREQ 46870 |
| 235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | #define W83781D_REG_I2C_ADDR 0x48 |
| 237 | #define W83781D_REG_I2C_SUBADDR 0x4A |
| 238 | |
| 239 | /* Sensor selection */ |
| 240 | #define W83781D_REG_SCFG1 0x5D |
| 241 | static const u8 BIT_SCFG1[] = { 0x02, 0x04, 0x08 }; |
| 242 | #define W83781D_REG_SCFG2 0x59 |
| 243 | static const u8 BIT_SCFG2[] = { 0x10, 0x20, 0x40 }; |
| 244 | #define W83781D_DEFAULT_BETA 3435 |
| 245 | |
| 246 | /* Conversions. Limit checking is only done on the TO_REG |
| 247 | variants. Note that you should be a bit careful with which arguments |
| 248 | these macros are called: arguments may be evaluated more than once. |
| 249 | Fixing this is just not worth it. */ |
| 250 | #define IN_TO_REG(val) (SENSORS_LIMIT((((val) + 8)/16),0,255)) |
| 251 | #define IN_FROM_REG(val) ((val) * 16) |
| 252 | |
| 253 | static inline u8 FAN_TO_REG(long rpm, int div) |
| 254 | { |
| 255 | if (rpm == 0) |
| 256 | return 255; |
| 257 | rpm = SENSORS_LIMIT(rpm, 1, 1000000); |
| 258 | return SENSORS_LIMIT((1350000 + rpm * div / 2) / (rpm * div), 1, |
| 259 | 254); |
| 260 | } |
| 261 | |
| 262 | #define TEMP_MIN (-128000) |
| 263 | #define TEMP_MAX ( 127000) |
| 264 | |
| 265 | /* TEMP: 0.001C/bit (-128C to +127C) |
| 266 | REG: 1C/bit, two's complement */ |
Christian Hohnstaedt | 5bfedac | 2007-08-16 11:40:10 +0200 | [diff] [blame] | 267 | static u8 TEMP_TO_REG(long temp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | { |
| 269 | int ntemp = SENSORS_LIMIT(temp, TEMP_MIN, TEMP_MAX); |
| 270 | ntemp += (ntemp<0 ? -500 : 500); |
| 271 | return (u8)(ntemp / 1000); |
| 272 | } |
| 273 | |
| 274 | static int TEMP_FROM_REG(u8 reg) |
| 275 | { |
| 276 | return (s8)reg * 1000; |
| 277 | } |
| 278 | |
| 279 | #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) |
| 280 | |
| 281 | #define PWM_TO_REG(val) (SENSORS_LIMIT((val),0,255)) |
| 282 | |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 283 | static inline unsigned long pwm_freq_from_reg_627hf(u8 reg) |
| 284 | { |
| 285 | unsigned long freq; |
| 286 | freq = W83627HF_BASE_PWM_FREQ >> reg; |
| 287 | return freq; |
| 288 | } |
| 289 | static inline u8 pwm_freq_to_reg_627hf(unsigned long val) |
| 290 | { |
| 291 | u8 i; |
| 292 | /* Only 5 dividers (1 2 4 8 16) |
| 293 | Search for the nearest available frequency */ |
| 294 | for (i = 0; i < 4; i++) { |
| 295 | if (val > (((W83627HF_BASE_PWM_FREQ >> i) + |
| 296 | (W83627HF_BASE_PWM_FREQ >> (i+1))) / 2)) |
| 297 | break; |
| 298 | } |
| 299 | return i; |
| 300 | } |
| 301 | |
| 302 | static inline unsigned long pwm_freq_from_reg(u8 reg) |
| 303 | { |
| 304 | /* Clock bit 8 -> 180 kHz or 24 MHz */ |
| 305 | unsigned long clock = (reg & 0x80) ? 180000UL : 24000000UL; |
| 306 | |
| 307 | reg &= 0x7f; |
| 308 | /* This should not happen but anyway... */ |
| 309 | if (reg == 0) |
| 310 | reg++; |
| 311 | return (clock / (reg << 8)); |
| 312 | } |
| 313 | static inline u8 pwm_freq_to_reg(unsigned long val) |
| 314 | { |
| 315 | /* Minimum divider value is 0x01 and maximum is 0x7F */ |
| 316 | if (val >= 93750) /* The highest we can do */ |
| 317 | return 0x01; |
| 318 | if (val >= 720) /* Use 24 MHz clock */ |
| 319 | return (24000000UL / (val << 8)); |
| 320 | if (val < 6) /* The lowest we can do */ |
| 321 | return 0xFF; |
| 322 | else /* Use 180 kHz clock */ |
| 323 | return (0x80 | (180000UL / (val << 8))); |
| 324 | } |
| 325 | |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 326 | #define BEEP_MASK_FROM_REG(val) ((val) & 0xff7fff) |
| 327 | #define BEEP_MASK_TO_REG(val) ((val) & 0xff7fff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
| 329 | #define DIV_FROM_REG(val) (1 << (val)) |
| 330 | |
| 331 | static inline u8 DIV_TO_REG(long val) |
| 332 | { |
| 333 | int i; |
| 334 | val = SENSORS_LIMIT(val, 1, 128) >> 1; |
Grant Coady | abc0192 | 2005-05-12 13:41:51 +1000 | [diff] [blame] | 335 | for (i = 0; i < 7; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | if (val == 0) |
| 337 | break; |
| 338 | val >>= 1; |
| 339 | } |
| 340 | return ((u8) i); |
| 341 | } |
| 342 | |
Jean Delvare | ed6bafb | 2007-02-14 21:15:03 +0100 | [diff] [blame] | 343 | /* For each registered chip, we need to keep some data in memory. |
| 344 | The structure is dynamically allocated. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | struct w83627hf_data { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 346 | unsigned short addr; |
| 347 | const char *name; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 348 | struct device *hwmon_dev; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 349 | struct mutex lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | enum chips type; |
| 351 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 352 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | char valid; /* !=0 if following fields are valid */ |
| 354 | unsigned long last_updated; /* In jiffies */ |
| 355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | u8 in[9]; /* Register value */ |
| 357 | u8 in_max[9]; /* Register value */ |
| 358 | u8 in_min[9]; /* Register value */ |
| 359 | u8 fan[3]; /* Register value */ |
| 360 | u8 fan_min[3]; /* Register value */ |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 361 | u16 temp[3]; /* Register value */ |
| 362 | u16 temp_max[3]; /* Register value */ |
| 363 | u16 temp_max_hyst[3]; /* Register value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | u8 fan_div[3]; /* Register encoding, shifted right */ |
| 365 | u8 vid; /* Register encoding, combined */ |
| 366 | u32 alarms; /* Register encoding, combined */ |
| 367 | u32 beep_mask; /* Register encoding, combined */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | u8 pwm[3]; /* Register value */ |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 369 | u8 pwm_freq[3]; /* Register value */ |
Jean Delvare | b26f933 | 2007-08-16 14:30:01 +0200 | [diff] [blame] | 370 | u16 sens[3]; /* 1 = pentium diode; 2 = 3904 diode; |
| 371 | 4 = thermistor */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | u8 vrm; |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 373 | u8 vrm_ovt; /* Register value, 627THF/637HF/687THF only */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | }; |
| 375 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 376 | struct w83627hf_sio_data { |
| 377 | enum chips type; |
| 378 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 381 | static int w83627hf_probe(struct platform_device *pdev); |
Jean Delvare | d054612 | 2007-07-22 12:09:48 +0200 | [diff] [blame] | 382 | static int __devexit w83627hf_remove(struct platform_device *pdev); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 383 | |
| 384 | static int w83627hf_read_value(struct w83627hf_data *data, u16 reg); |
| 385 | static int w83627hf_write_value(struct w83627hf_data *data, u16 reg, u16 value); |
Jean Delvare | c09c518 | 2007-10-12 21:53:07 +0200 | [diff] [blame] | 386 | static void w83627hf_update_fan_div(struct w83627hf_data *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | static struct w83627hf_data *w83627hf_update_device(struct device *dev); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 388 | static void w83627hf_init_device(struct platform_device *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 390 | static struct platform_driver w83627hf_driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 391 | .driver = { |
Jean Delvare | 8721884 | 2006-09-03 22:36:14 +0200 | [diff] [blame] | 392 | .owner = THIS_MODULE, |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 393 | .name = DRVNAME, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 394 | }, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 395 | .probe = w83627hf_probe, |
| 396 | .remove = __devexit_p(w83627hf_remove), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | }; |
| 398 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 399 | static ssize_t |
| 400 | show_in_input(struct device *dev, struct device_attribute *devattr, char *buf) |
| 401 | { |
| 402 | int nr = to_sensor_dev_attr(devattr)->index; |
| 403 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 404 | return sprintf(buf, "%ld\n", (long)IN_FROM_REG(data->in[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | } |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 406 | static ssize_t |
| 407 | show_in_min(struct device *dev, struct device_attribute *devattr, char *buf) |
| 408 | { |
| 409 | int nr = to_sensor_dev_attr(devattr)->index; |
| 410 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 411 | return sprintf(buf, "%ld\n", (long)IN_FROM_REG(data->in_min[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 413 | static ssize_t |
| 414 | show_in_max(struct device *dev, struct device_attribute *devattr, char *buf) |
| 415 | { |
| 416 | int nr = to_sensor_dev_attr(devattr)->index; |
| 417 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 418 | return sprintf(buf, "%ld\n", (long)IN_FROM_REG(data->in_max[nr])); |
| 419 | } |
| 420 | static ssize_t |
| 421 | store_in_min(struct device *dev, struct device_attribute *devattr, |
| 422 | const char *buf, size_t count) |
| 423 | { |
| 424 | int nr = to_sensor_dev_attr(devattr)->index; |
| 425 | struct w83627hf_data *data = dev_get_drvdata(dev); |
| 426 | long val = simple_strtol(buf, NULL, 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 428 | mutex_lock(&data->update_lock); |
| 429 | data->in_min[nr] = IN_TO_REG(val); |
| 430 | w83627hf_write_value(data, W83781D_REG_IN_MIN(nr), data->in_min[nr]); |
| 431 | mutex_unlock(&data->update_lock); |
| 432 | return count; |
| 433 | } |
| 434 | static ssize_t |
| 435 | store_in_max(struct device *dev, struct device_attribute *devattr, |
| 436 | const char *buf, size_t count) |
| 437 | { |
| 438 | int nr = to_sensor_dev_attr(devattr)->index; |
| 439 | struct w83627hf_data *data = dev_get_drvdata(dev); |
| 440 | long val = simple_strtol(buf, NULL, 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 442 | mutex_lock(&data->update_lock); |
| 443 | data->in_max[nr] = IN_TO_REG(val); |
| 444 | w83627hf_write_value(data, W83781D_REG_IN_MAX(nr), data->in_max[nr]); |
| 445 | mutex_unlock(&data->update_lock); |
| 446 | return count; |
| 447 | } |
| 448 | #define sysfs_vin_decl(offset) \ |
| 449 | static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \ |
| 450 | show_in_input, NULL, offset); \ |
| 451 | static SENSOR_DEVICE_ATTR(in##offset##_min, S_IRUGO|S_IWUSR, \ |
| 452 | show_in_min, store_in_min, offset); \ |
| 453 | static SENSOR_DEVICE_ATTR(in##offset##_max, S_IRUGO|S_IWUSR, \ |
| 454 | show_in_max, store_in_max, offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 456 | sysfs_vin_decl(1); |
| 457 | sysfs_vin_decl(2); |
| 458 | sysfs_vin_decl(3); |
| 459 | sysfs_vin_decl(4); |
| 460 | sysfs_vin_decl(5); |
| 461 | sysfs_vin_decl(6); |
| 462 | sysfs_vin_decl(7); |
| 463 | sysfs_vin_decl(8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
| 465 | /* use a different set of functions for in0 */ |
| 466 | static ssize_t show_in_0(struct w83627hf_data *data, char *buf, u8 reg) |
| 467 | { |
| 468 | long in0; |
| 469 | |
| 470 | if ((data->vrm_ovt & 0x01) && |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 471 | (w83627thf == data->type || w83637hf == data->type |
| 472 | || w83687thf == data->type)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | |
| 474 | /* use VRM9 calculation */ |
| 475 | in0 = (long)((reg * 488 + 70000 + 50) / 100); |
| 476 | else |
| 477 | /* use VRM8 (standard) calculation */ |
| 478 | in0 = (long)IN_FROM_REG(reg); |
| 479 | |
| 480 | return sprintf(buf,"%ld\n", in0); |
| 481 | } |
| 482 | |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 483 | 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] | 484 | { |
| 485 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 486 | return show_in_0(data, buf, data->in[0]); |
| 487 | } |
| 488 | |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 489 | 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] | 490 | { |
| 491 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 492 | return show_in_0(data, buf, data->in_min[0]); |
| 493 | } |
| 494 | |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 495 | 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] | 496 | { |
| 497 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 498 | return show_in_0(data, buf, data->in_max[0]); |
| 499 | } |
| 500 | |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 501 | 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] | 502 | const char *buf, size_t count) |
| 503 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 504 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | u32 val; |
| 506 | |
| 507 | val = simple_strtoul(buf, NULL, 10); |
| 508 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 509 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
| 511 | if ((data->vrm_ovt & 0x01) && |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 512 | (w83627thf == data->type || w83637hf == data->type |
| 513 | || w83687thf == data->type)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | |
| 515 | /* use VRM9 calculation */ |
Yuan Mu | 2723ab9 | 2005-11-23 15:44:21 -0800 | [diff] [blame] | 516 | data->in_min[0] = |
| 517 | SENSORS_LIMIT(((val * 100) - 70000 + 244) / 488, 0, |
| 518 | 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | else |
| 520 | /* use VRM8 (standard) calculation */ |
| 521 | data->in_min[0] = IN_TO_REG(val); |
| 522 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 523 | 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] | 524 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | return count; |
| 526 | } |
| 527 | |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 528 | 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] | 529 | const char *buf, size_t count) |
| 530 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 531 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | u32 val; |
| 533 | |
| 534 | val = simple_strtoul(buf, NULL, 10); |
| 535 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 536 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | |
| 538 | if ((data->vrm_ovt & 0x01) && |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 539 | (w83627thf == data->type || w83637hf == data->type |
| 540 | || w83687thf == data->type)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
| 542 | /* use VRM9 calculation */ |
Yuan Mu | 2723ab9 | 2005-11-23 15:44:21 -0800 | [diff] [blame] | 543 | data->in_max[0] = |
| 544 | SENSORS_LIMIT(((val * 100) - 70000 + 244) / 488, 0, |
| 545 | 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | else |
| 547 | /* use VRM8 (standard) calculation */ |
| 548 | data->in_max[0] = IN_TO_REG(val); |
| 549 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 550 | 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] | 551 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | return count; |
| 553 | } |
| 554 | |
| 555 | static DEVICE_ATTR(in0_input, S_IRUGO, show_regs_in_0, NULL); |
| 556 | static DEVICE_ATTR(in0_min, S_IRUGO | S_IWUSR, |
| 557 | show_regs_in_min0, store_regs_in_min0); |
| 558 | static DEVICE_ATTR(in0_max, S_IRUGO | S_IWUSR, |
| 559 | show_regs_in_max0, store_regs_in_max0); |
| 560 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | static ssize_t |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 562 | show_fan_input(struct device *dev, struct device_attribute *devattr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 564 | int nr = to_sensor_dev_attr(devattr)->index; |
| 565 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 566 | return sprintf(buf, "%ld\n", FAN_FROM_REG(data->fan[nr], |
| 567 | (long)DIV_FROM_REG(data->fan_div[nr]))); |
| 568 | } |
| 569 | static ssize_t |
| 570 | show_fan_min(struct device *dev, struct device_attribute *devattr, char *buf) |
| 571 | { |
| 572 | int nr = to_sensor_dev_attr(devattr)->index; |
| 573 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 574 | return sprintf(buf, "%ld\n", FAN_FROM_REG(data->fan_min[nr], |
| 575 | (long)DIV_FROM_REG(data->fan_div[nr]))); |
| 576 | } |
| 577 | static ssize_t |
| 578 | store_fan_min(struct device *dev, struct device_attribute *devattr, |
| 579 | const char *buf, size_t count) |
| 580 | { |
| 581 | int nr = to_sensor_dev_attr(devattr)->index; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 582 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 583 | u32 val = simple_strtoul(buf, NULL, 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 585 | mutex_lock(&data->update_lock); |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 586 | data->fan_min[nr] = FAN_TO_REG(val, DIV_FROM_REG(data->fan_div[nr])); |
Jim Cromie | 2ca2fcd | 2007-10-14 17:20:50 -0600 | [diff] [blame] | 587 | w83627hf_write_value(data, W83627HF_REG_FAN_MIN(nr), |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 588 | data->fan_min[nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 590 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | return count; |
| 592 | } |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 593 | #define sysfs_fan_decl(offset) \ |
| 594 | static SENSOR_DEVICE_ATTR(fan##offset##_input, S_IRUGO, \ |
| 595 | show_fan_input, NULL, offset - 1); \ |
| 596 | static SENSOR_DEVICE_ATTR(fan##offset##_min, S_IRUGO | S_IWUSR, \ |
| 597 | show_fan_min, store_fan_min, offset - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 599 | sysfs_fan_decl(1); |
| 600 | sysfs_fan_decl(2); |
| 601 | sysfs_fan_decl(3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 603 | static ssize_t |
| 604 | show_temp(struct device *dev, struct device_attribute *devattr, char *buf) |
| 605 | { |
| 606 | int nr = to_sensor_dev_attr(devattr)->index; |
| 607 | struct w83627hf_data *data = w83627hf_update_device(dev); |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 608 | |
| 609 | u16 tmp = data->temp[nr]; |
| 610 | return sprintf(buf, "%ld\n", (nr) ? (long) LM75_TEMP_FROM_REG(tmp) |
| 611 | : (long) TEMP_FROM_REG(tmp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 614 | static ssize_t |
| 615 | show_temp_max(struct device *dev, struct device_attribute *devattr, |
| 616 | char *buf) |
| 617 | { |
| 618 | int nr = to_sensor_dev_attr(devattr)->index; |
| 619 | struct w83627hf_data *data = w83627hf_update_device(dev); |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 620 | |
| 621 | u16 tmp = data->temp_max[nr]; |
| 622 | return sprintf(buf, "%ld\n", (nr) ? (long) LM75_TEMP_FROM_REG(tmp) |
| 623 | : (long) TEMP_FROM_REG(tmp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 626 | static ssize_t |
| 627 | show_temp_max_hyst(struct device *dev, struct device_attribute *devattr, |
| 628 | char *buf) |
| 629 | { |
| 630 | int nr = to_sensor_dev_attr(devattr)->index; |
| 631 | struct w83627hf_data *data = w83627hf_update_device(dev); |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 632 | |
| 633 | u16 tmp = data->temp_max_hyst[nr]; |
| 634 | return sprintf(buf, "%ld\n", (nr) ? (long) LM75_TEMP_FROM_REG(tmp) |
| 635 | : (long) TEMP_FROM_REG(tmp)); |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 636 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 638 | static ssize_t |
| 639 | store_temp_max(struct device *dev, struct device_attribute *devattr, |
| 640 | const char *buf, size_t count) |
| 641 | { |
| 642 | int nr = to_sensor_dev_attr(devattr)->index; |
| 643 | struct w83627hf_data *data = dev_get_drvdata(dev); |
| 644 | long val = simple_strtol(buf, NULL, 10); |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 645 | u16 tmp = (nr) ? LM75_TEMP_TO_REG(val) : TEMP_TO_REG(val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 647 | mutex_lock(&data->update_lock); |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 648 | data->temp_max[nr] = tmp; |
| 649 | w83627hf_write_value(data, w83627hf_reg_temp_over[nr], tmp); |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 650 | mutex_unlock(&data->update_lock); |
| 651 | return count; |
| 652 | } |
| 653 | |
| 654 | static ssize_t |
| 655 | store_temp_max_hyst(struct device *dev, struct device_attribute *devattr, |
| 656 | const char *buf, size_t count) |
| 657 | { |
| 658 | int nr = to_sensor_dev_attr(devattr)->index; |
| 659 | struct w83627hf_data *data = dev_get_drvdata(dev); |
| 660 | long val = simple_strtol(buf, NULL, 10); |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 661 | u16 tmp = (nr) ? LM75_TEMP_TO_REG(val) : TEMP_TO_REG(val); |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 662 | |
| 663 | mutex_lock(&data->update_lock); |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 664 | data->temp_max_hyst[nr] = tmp; |
| 665 | w83627hf_write_value(data, w83627hf_reg_temp_hyst[nr], tmp); |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 666 | mutex_unlock(&data->update_lock); |
| 667 | return count; |
| 668 | } |
| 669 | |
| 670 | #define sysfs_temp_decl(offset) \ |
| 671 | static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \ |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 672 | show_temp, NULL, offset - 1); \ |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 673 | static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IRUGO|S_IWUSR, \ |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 674 | show_temp_max, store_temp_max, offset - 1); \ |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 675 | static SENSOR_DEVICE_ATTR(temp##offset##_max_hyst, S_IRUGO|S_IWUSR, \ |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 676 | show_temp_max_hyst, store_temp_max_hyst, offset - 1); |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 677 | |
| 678 | sysfs_temp_decl(1); |
| 679 | sysfs_temp_decl(2); |
| 680 | sysfs_temp_decl(3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | static ssize_t |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 683 | show_vid_reg(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | { |
| 685 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 686 | return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); |
| 687 | } |
| 688 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid_reg, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
| 690 | static ssize_t |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 691 | show_vrm_reg(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | { |
Jean Delvare | 90d6619 | 2007-10-08 18:24:35 +0200 | [diff] [blame] | 693 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | return sprintf(buf, "%ld\n", (long) data->vrm); |
| 695 | } |
| 696 | static ssize_t |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 697 | 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] | 698 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 699 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | u32 val; |
| 701 | |
| 702 | val = simple_strtoul(buf, NULL, 10); |
| 703 | data->vrm = val; |
| 704 | |
| 705 | return count; |
| 706 | } |
| 707 | 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] | 708 | |
| 709 | static ssize_t |
Yani Ioannou | a5099cf | 2005-05-17 06:42:25 -0400 | [diff] [blame] | 710 | show_alarms_reg(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | { |
| 712 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 713 | return sprintf(buf, "%ld\n", (long) data->alarms); |
| 714 | } |
| 715 | static DEVICE_ATTR(alarms, S_IRUGO, show_alarms_reg, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 717 | static ssize_t |
| 718 | show_alarm(struct device *dev, struct device_attribute *attr, char *buf) |
| 719 | { |
| 720 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 721 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 722 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); |
| 723 | } |
| 724 | static SENSOR_DEVICE_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0); |
| 725 | static SENSOR_DEVICE_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1); |
| 726 | static SENSOR_DEVICE_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2); |
| 727 | static SENSOR_DEVICE_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3); |
| 728 | static SENSOR_DEVICE_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8); |
| 729 | static SENSOR_DEVICE_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 9); |
| 730 | static SENSOR_DEVICE_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 10); |
| 731 | static SENSOR_DEVICE_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 16); |
| 732 | static SENSOR_DEVICE_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 17); |
| 733 | static SENSOR_DEVICE_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6); |
| 734 | static SENSOR_DEVICE_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7); |
| 735 | static SENSOR_DEVICE_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11); |
| 736 | static SENSOR_DEVICE_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4); |
| 737 | static SENSOR_DEVICE_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5); |
| 738 | static SENSOR_DEVICE_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13); |
| 739 | |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 740 | static ssize_t |
| 741 | show_beep_mask(struct device *dev, struct device_attribute *attr, char *buf) |
| 742 | { |
| 743 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 744 | return sprintf(buf, "%ld\n", |
| 745 | (long)BEEP_MASK_FROM_REG(data->beep_mask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | |
| 748 | static ssize_t |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 749 | store_beep_mask(struct device *dev, struct device_attribute *attr, |
| 750 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 752 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 753 | unsigned long val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | |
| 755 | 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 | |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 759 | /* preserve beep enable */ |
| 760 | data->beep_mask = (data->beep_mask & 0x8000) |
| 761 | | BEEP_MASK_TO_REG(val); |
| 762 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS1, |
| 763 | data->beep_mask & 0xff); |
| 764 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS3, |
| 765 | ((data->beep_mask) >> 16) & 0xff); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 766 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS2, |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 767 | (data->beep_mask >> 8) & 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 769 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | return count; |
| 771 | } |
| 772 | |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 773 | static DEVICE_ATTR(beep_mask, S_IRUGO | S_IWUSR, |
| 774 | show_beep_mask, store_beep_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | static ssize_t |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 777 | show_beep(struct device *dev, struct device_attribute *attr, char *buf) |
| 778 | { |
| 779 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 780 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 781 | return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1); |
| 782 | } |
| 783 | |
| 784 | static ssize_t |
| 785 | store_beep(struct device *dev, struct device_attribute *attr, |
| 786 | const char *buf, size_t count) |
| 787 | { |
| 788 | struct w83627hf_data *data = dev_get_drvdata(dev); |
| 789 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 790 | unsigned long bit; |
| 791 | u8 reg; |
| 792 | |
| 793 | bit = simple_strtoul(buf, NULL, 10); |
| 794 | if (bit & ~1) |
| 795 | return -EINVAL; |
| 796 | |
| 797 | mutex_lock(&data->update_lock); |
| 798 | if (bit) |
| 799 | data->beep_mask |= (1 << bitnr); |
| 800 | else |
| 801 | data->beep_mask &= ~(1 << bitnr); |
| 802 | |
| 803 | if (bitnr < 8) { |
| 804 | reg = w83627hf_read_value(data, W83781D_REG_BEEP_INTS1); |
| 805 | if (bit) |
| 806 | reg |= (1 << bitnr); |
| 807 | else |
| 808 | reg &= ~(1 << bitnr); |
| 809 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS1, reg); |
| 810 | } else if (bitnr < 16) { |
| 811 | reg = w83627hf_read_value(data, W83781D_REG_BEEP_INTS2); |
| 812 | if (bit) |
| 813 | reg |= (1 << (bitnr - 8)); |
| 814 | else |
| 815 | reg &= ~(1 << (bitnr - 8)); |
| 816 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS2, reg); |
| 817 | } else { |
| 818 | reg = w83627hf_read_value(data, W83781D_REG_BEEP_INTS3); |
| 819 | if (bit) |
| 820 | reg |= (1 << (bitnr - 16)); |
| 821 | else |
| 822 | reg &= ~(1 << (bitnr - 16)); |
| 823 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS3, reg); |
| 824 | } |
| 825 | mutex_unlock(&data->update_lock); |
| 826 | |
| 827 | return count; |
| 828 | } |
| 829 | |
| 830 | static SENSOR_DEVICE_ATTR(in0_beep, S_IRUGO | S_IWUSR, |
| 831 | show_beep, store_beep, 0); |
| 832 | static SENSOR_DEVICE_ATTR(in1_beep, S_IRUGO | S_IWUSR, |
| 833 | show_beep, store_beep, 1); |
| 834 | static SENSOR_DEVICE_ATTR(in2_beep, S_IRUGO | S_IWUSR, |
| 835 | show_beep, store_beep, 2); |
| 836 | static SENSOR_DEVICE_ATTR(in3_beep, S_IRUGO | S_IWUSR, |
| 837 | show_beep, store_beep, 3); |
| 838 | static SENSOR_DEVICE_ATTR(in4_beep, S_IRUGO | S_IWUSR, |
| 839 | show_beep, store_beep, 8); |
| 840 | static SENSOR_DEVICE_ATTR(in5_beep, S_IRUGO | S_IWUSR, |
| 841 | show_beep, store_beep, 9); |
| 842 | static SENSOR_DEVICE_ATTR(in6_beep, S_IRUGO | S_IWUSR, |
| 843 | show_beep, store_beep, 10); |
| 844 | static SENSOR_DEVICE_ATTR(in7_beep, S_IRUGO | S_IWUSR, |
| 845 | show_beep, store_beep, 16); |
| 846 | static SENSOR_DEVICE_ATTR(in8_beep, S_IRUGO | S_IWUSR, |
| 847 | show_beep, store_beep, 17); |
| 848 | static SENSOR_DEVICE_ATTR(fan1_beep, S_IRUGO | S_IWUSR, |
| 849 | show_beep, store_beep, 6); |
| 850 | static SENSOR_DEVICE_ATTR(fan2_beep, S_IRUGO | S_IWUSR, |
| 851 | show_beep, store_beep, 7); |
| 852 | static SENSOR_DEVICE_ATTR(fan3_beep, S_IRUGO | S_IWUSR, |
| 853 | show_beep, store_beep, 11); |
| 854 | static SENSOR_DEVICE_ATTR(temp1_beep, S_IRUGO | S_IWUSR, |
| 855 | show_beep, store_beep, 4); |
| 856 | static SENSOR_DEVICE_ATTR(temp2_beep, S_IRUGO | S_IWUSR, |
| 857 | show_beep, store_beep, 5); |
| 858 | static SENSOR_DEVICE_ATTR(temp3_beep, S_IRUGO | S_IWUSR, |
| 859 | show_beep, store_beep, 13); |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 860 | static SENSOR_DEVICE_ATTR(beep_enable, S_IRUGO | S_IWUSR, |
| 861 | show_beep, store_beep, 15); |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 862 | |
| 863 | static ssize_t |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 864 | show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 866 | int nr = to_sensor_dev_attr(devattr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 868 | return sprintf(buf, "%ld\n", |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 869 | (long) DIV_FROM_REG(data->fan_div[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 870 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | /* Note: we save and restore the fan minimum here, because its value is |
| 872 | determined in part by the fan divisor. This follows the principle of |
Andreas Mohr | d6e05ed | 2006-06-26 18:35:02 +0200 | [diff] [blame] | 873 | 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] | 874 | because the divisor changed. */ |
| 875 | static ssize_t |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 876 | store_fan_div(struct device *dev, struct device_attribute *devattr, |
| 877 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 879 | int nr = to_sensor_dev_attr(devattr)->index; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 880 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | unsigned long min; |
| 882 | u8 reg; |
| 883 | unsigned long val = simple_strtoul(buf, NULL, 10); |
| 884 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 885 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | |
| 887 | /* Save fan_min */ |
| 888 | min = FAN_FROM_REG(data->fan_min[nr], |
| 889 | DIV_FROM_REG(data->fan_div[nr])); |
| 890 | |
| 891 | data->fan_div[nr] = DIV_TO_REG(val); |
| 892 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 893 | 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] | 894 | & (nr==0 ? 0xcf : 0x3f)) |
| 895 | | ((data->fan_div[nr] & 0x03) << (nr==0 ? 4 : 6)); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 896 | 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] | 897 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 898 | reg = (w83627hf_read_value(data, W83781D_REG_VBAT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | & ~(1 << (5 + nr))) |
| 900 | | ((data->fan_div[nr] & 0x04) << (3 + nr)); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 901 | w83627hf_write_value(data, W83781D_REG_VBAT, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | |
| 903 | /* Restore fan_min */ |
| 904 | data->fan_min[nr] = FAN_TO_REG(min, DIV_FROM_REG(data->fan_div[nr])); |
Jim Cromie | 2ca2fcd | 2007-10-14 17:20:50 -0600 | [diff] [blame] | 905 | w83627hf_write_value(data, W83627HF_REG_FAN_MIN(nr), data->fan_min[nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 907 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | return count; |
| 909 | } |
| 910 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 911 | static SENSOR_DEVICE_ATTR(fan1_div, S_IRUGO|S_IWUSR, |
| 912 | show_fan_div, store_fan_div, 0); |
| 913 | static SENSOR_DEVICE_ATTR(fan2_div, S_IRUGO|S_IWUSR, |
| 914 | show_fan_div, store_fan_div, 1); |
| 915 | static SENSOR_DEVICE_ATTR(fan3_div, S_IRUGO|S_IWUSR, |
| 916 | show_fan_div, store_fan_div, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | static ssize_t |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 919 | show_pwm(struct device *dev, struct device_attribute *devattr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 921 | int nr = to_sensor_dev_attr(devattr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | struct w83627hf_data *data = w83627hf_update_device(dev); |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 923 | return sprintf(buf, "%ld\n", (long) data->pwm[nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | static ssize_t |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 927 | store_pwm(struct device *dev, struct device_attribute *devattr, |
| 928 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 930 | int nr = to_sensor_dev_attr(devattr)->index; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 931 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 932 | u32 val = simple_strtoul(buf, NULL, 10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 934 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | |
| 936 | if (data->type == w83627thf) { |
| 937 | /* bits 0-3 are reserved in 627THF */ |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 938 | data->pwm[nr] = PWM_TO_REG(val) & 0xf0; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 939 | w83627hf_write_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | W836X7HF_REG_PWM(data->type, nr), |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 941 | data->pwm[nr] | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 942 | (w83627hf_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 943 | W836X7HF_REG_PWM(data->type, nr)) & 0x0f)); |
| 944 | } else { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 945 | data->pwm[nr] = PWM_TO_REG(val); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 946 | w83627hf_write_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | W836X7HF_REG_PWM(data->type, nr), |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 948 | data->pwm[nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | } |
| 950 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 951 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | return count; |
| 953 | } |
| 954 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 955 | static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0); |
| 956 | static SENSOR_DEVICE_ATTR(pwm2, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 1); |
| 957 | static SENSOR_DEVICE_ATTR(pwm3, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 958 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | static ssize_t |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 960 | show_pwm_freq(struct device *dev, struct device_attribute *devattr, char *buf) |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 961 | { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 962 | int nr = to_sensor_dev_attr(devattr)->index; |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 963 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 964 | if (data->type == w83627hf) |
| 965 | return sprintf(buf, "%ld\n", |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 966 | pwm_freq_from_reg_627hf(data->pwm_freq[nr])); |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 967 | else |
| 968 | return sprintf(buf, "%ld\n", |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 969 | pwm_freq_from_reg(data->pwm_freq[nr])); |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 970 | } |
| 971 | |
| 972 | static ssize_t |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 973 | store_pwm_freq(struct device *dev, struct device_attribute *devattr, |
| 974 | const char *buf, size_t count) |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 975 | { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 976 | int nr = to_sensor_dev_attr(devattr)->index; |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 977 | struct w83627hf_data *data = dev_get_drvdata(dev); |
| 978 | static const u8 mask[]={0xF8, 0x8F}; |
| 979 | u32 val; |
| 980 | |
| 981 | val = simple_strtoul(buf, NULL, 10); |
| 982 | |
| 983 | mutex_lock(&data->update_lock); |
| 984 | |
| 985 | if (data->type == w83627hf) { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 986 | data->pwm_freq[nr] = pwm_freq_to_reg_627hf(val); |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 987 | w83627hf_write_value(data, W83627HF_REG_PWM_FREQ, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 988 | (data->pwm_freq[nr] << (nr*4)) | |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 989 | (w83627hf_read_value(data, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 990 | W83627HF_REG_PWM_FREQ) & mask[nr])); |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 991 | } else { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 992 | data->pwm_freq[nr] = pwm_freq_to_reg(val); |
| 993 | w83627hf_write_value(data, W83637HF_REG_PWM_FREQ[nr], |
| 994 | data->pwm_freq[nr]); |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | mutex_unlock(&data->update_lock); |
| 998 | return count; |
| 999 | } |
| 1000 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1001 | static SENSOR_DEVICE_ATTR(pwm1_freq, S_IRUGO|S_IWUSR, |
| 1002 | show_pwm_freq, store_pwm_freq, 0); |
| 1003 | static SENSOR_DEVICE_ATTR(pwm2_freq, S_IRUGO|S_IWUSR, |
| 1004 | show_pwm_freq, store_pwm_freq, 1); |
| 1005 | static SENSOR_DEVICE_ATTR(pwm3_freq, S_IRUGO|S_IWUSR, |
| 1006 | show_pwm_freq, store_pwm_freq, 2); |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1007 | |
| 1008 | static ssize_t |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1009 | show_temp_type(struct device *dev, struct device_attribute *devattr, |
| 1010 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1012 | int nr = to_sensor_dev_attr(devattr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | struct w83627hf_data *data = w83627hf_update_device(dev); |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1014 | return sprintf(buf, "%ld\n", (long) data->sens[nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | } |
| 1016 | |
| 1017 | static ssize_t |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1018 | store_temp_type(struct device *dev, struct device_attribute *devattr, |
| 1019 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1021 | int nr = to_sensor_dev_attr(devattr)->index; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1022 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1023 | u32 val, tmp; |
| 1024 | |
| 1025 | val = simple_strtoul(buf, NULL, 10); |
| 1026 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1027 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | |
| 1029 | switch (val) { |
| 1030 | case 1: /* PII/Celeron diode */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1031 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); |
| 1032 | w83627hf_write_value(data, W83781D_REG_SCFG1, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1033 | tmp | BIT_SCFG1[nr]); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1034 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG2); |
| 1035 | w83627hf_write_value(data, W83781D_REG_SCFG2, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1036 | tmp | BIT_SCFG2[nr]); |
| 1037 | data->sens[nr] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | break; |
| 1039 | case 2: /* 3904 */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1040 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); |
| 1041 | w83627hf_write_value(data, W83781D_REG_SCFG1, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1042 | tmp | BIT_SCFG1[nr]); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1043 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG2); |
| 1044 | w83627hf_write_value(data, W83781D_REG_SCFG2, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1045 | tmp & ~BIT_SCFG2[nr]); |
| 1046 | data->sens[nr] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1047 | break; |
Jean Delvare | b26f933 | 2007-08-16 14:30:01 +0200 | [diff] [blame] | 1048 | case W83781D_DEFAULT_BETA: |
| 1049 | dev_warn(dev, "Sensor type %d is deprecated, please use 4 " |
| 1050 | "instead\n", W83781D_DEFAULT_BETA); |
| 1051 | /* fall through */ |
| 1052 | case 4: /* thermistor */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1053 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); |
| 1054 | w83627hf_write_value(data, W83781D_REG_SCFG1, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1055 | tmp & ~BIT_SCFG1[nr]); |
| 1056 | data->sens[nr] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | break; |
| 1058 | default: |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1059 | dev_err(dev, |
Jean Delvare | b26f933 | 2007-08-16 14:30:01 +0200 | [diff] [blame] | 1060 | "Invalid sensor type %ld; must be 1, 2, or 4\n", |
| 1061 | (long) val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | break; |
| 1063 | } |
| 1064 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1065 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | return count; |
| 1067 | } |
| 1068 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1069 | #define sysfs_temp_type(offset) \ |
| 1070 | static SENSOR_DEVICE_ATTR(temp##offset##_type, S_IRUGO | S_IWUSR, \ |
| 1071 | show_temp_type, store_temp_type, offset - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1073 | sysfs_temp_type(1); |
| 1074 | sysfs_temp_type(2); |
| 1075 | sysfs_temp_type(3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1077 | static ssize_t |
| 1078 | show_name(struct device *dev, struct device_attribute *devattr, char *buf) |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1079 | { |
| 1080 | struct w83627hf_data *data = dev_get_drvdata(dev); |
| 1081 | |
| 1082 | return sprintf(buf, "%s\n", data->name); |
| 1083 | } |
| 1084 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
| 1085 | |
| 1086 | static int __init w83627hf_find(int sioaddr, unsigned short *addr, |
| 1087 | struct w83627hf_sio_data *sio_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | { |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1089 | int err = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | u16 val; |
| 1091 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1092 | static const __initdata char *names[] = { |
| 1093 | "W83627HF", |
| 1094 | "W83627THF", |
| 1095 | "W83697HF", |
| 1096 | "W83637HF", |
| 1097 | "W83687THF", |
| 1098 | }; |
| 1099 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | REG = sioaddr; |
| 1101 | VAL = sioaddr + 1; |
| 1102 | |
| 1103 | superio_enter(); |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 1104 | val = force_id ? force_id : superio_inb(DEVID); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1105 | switch (val) { |
| 1106 | case W627_DEVID: |
| 1107 | sio_data->type = w83627hf; |
| 1108 | break; |
| 1109 | case W627THF_DEVID: |
| 1110 | sio_data->type = w83627thf; |
| 1111 | break; |
| 1112 | case W697_DEVID: |
| 1113 | sio_data->type = w83697hf; |
| 1114 | break; |
| 1115 | case W637_DEVID: |
| 1116 | sio_data->type = w83637hf; |
| 1117 | break; |
| 1118 | case W687THF_DEVID: |
| 1119 | sio_data->type = w83687thf; |
| 1120 | break; |
Jean Delvare | e142e2a | 2007-05-27 22:17:43 +0200 | [diff] [blame] | 1121 | case 0xff: /* No device at all */ |
| 1122 | goto exit; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1123 | default: |
Jean Delvare | e142e2a | 2007-05-27 22:17:43 +0200 | [diff] [blame] | 1124 | pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%02x)\n", val); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1125 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | superio_select(W83627HF_LD_HWM); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1129 | force_addr &= WINB_ALIGNMENT; |
| 1130 | if (force_addr) { |
| 1131 | printk(KERN_WARNING DRVNAME ": Forcing address 0x%x\n", |
| 1132 | force_addr); |
| 1133 | superio_outb(WINB_BASE_REG, force_addr >> 8); |
| 1134 | superio_outb(WINB_BASE_REG + 1, force_addr & 0xff); |
| 1135 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | val = (superio_inb(WINB_BASE_REG) << 8) | |
| 1137 | superio_inb(WINB_BASE_REG + 1); |
Petr Vandrovec | ada0c2f | 2005-10-07 23:11:03 +0200 | [diff] [blame] | 1138 | *addr = val & WINB_ALIGNMENT; |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1139 | if (*addr == 0) { |
| 1140 | printk(KERN_WARNING DRVNAME ": Base address not set, " |
| 1141 | "skipping\n"); |
| 1142 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1143 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1145 | val = superio_inb(WINB_ACT_REG); |
| 1146 | if (!(val & 0x01)) { |
| 1147 | printk(KERN_WARNING DRVNAME ": Enabling HWM logical device\n"); |
| 1148 | superio_outb(WINB_ACT_REG, val | 0x01); |
| 1149 | } |
| 1150 | |
| 1151 | err = 0; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1152 | pr_info(DRVNAME ": Found %s chip at %#x\n", |
| 1153 | names[sio_data->type], *addr); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1154 | |
| 1155 | exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | superio_exit(); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1157 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | } |
| 1159 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1160 | #define VIN_UNIT_ATTRS(_X_) \ |
| 1161 | &sensor_dev_attr_in##_X_##_input.dev_attr.attr, \ |
| 1162 | &sensor_dev_attr_in##_X_##_min.dev_attr.attr, \ |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 1163 | &sensor_dev_attr_in##_X_##_max.dev_attr.attr, \ |
| 1164 | &sensor_dev_attr_in##_X_##_alarm.dev_attr.attr, \ |
| 1165 | &sensor_dev_attr_in##_X_##_beep.dev_attr.attr |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1166 | |
| 1167 | #define FAN_UNIT_ATTRS(_X_) \ |
| 1168 | &sensor_dev_attr_fan##_X_##_input.dev_attr.attr, \ |
| 1169 | &sensor_dev_attr_fan##_X_##_min.dev_attr.attr, \ |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 1170 | &sensor_dev_attr_fan##_X_##_div.dev_attr.attr, \ |
| 1171 | &sensor_dev_attr_fan##_X_##_alarm.dev_attr.attr, \ |
| 1172 | &sensor_dev_attr_fan##_X_##_beep.dev_attr.attr |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1173 | |
| 1174 | #define TEMP_UNIT_ATTRS(_X_) \ |
| 1175 | &sensor_dev_attr_temp##_X_##_input.dev_attr.attr, \ |
| 1176 | &sensor_dev_attr_temp##_X_##_max.dev_attr.attr, \ |
| 1177 | &sensor_dev_attr_temp##_X_##_max_hyst.dev_attr.attr, \ |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 1178 | &sensor_dev_attr_temp##_X_##_type.dev_attr.attr, \ |
| 1179 | &sensor_dev_attr_temp##_X_##_alarm.dev_attr.attr, \ |
| 1180 | &sensor_dev_attr_temp##_X_##_beep.dev_attr.attr |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1181 | |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1182 | static struct attribute *w83627hf_attributes[] = { |
| 1183 | &dev_attr_in0_input.attr, |
| 1184 | &dev_attr_in0_min.attr, |
| 1185 | &dev_attr_in0_max.attr, |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 1186 | &sensor_dev_attr_in0_alarm.dev_attr.attr, |
| 1187 | &sensor_dev_attr_in0_beep.dev_attr.attr, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1188 | VIN_UNIT_ATTRS(2), |
| 1189 | VIN_UNIT_ATTRS(3), |
| 1190 | VIN_UNIT_ATTRS(4), |
| 1191 | VIN_UNIT_ATTRS(7), |
| 1192 | VIN_UNIT_ATTRS(8), |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1193 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1194 | FAN_UNIT_ATTRS(1), |
| 1195 | FAN_UNIT_ATTRS(2), |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1196 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1197 | TEMP_UNIT_ATTRS(1), |
| 1198 | TEMP_UNIT_ATTRS(2), |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1199 | |
| 1200 | &dev_attr_alarms.attr, |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 1201 | &sensor_dev_attr_beep_enable.dev_attr.attr, |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1202 | &dev_attr_beep_mask.attr, |
| 1203 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1204 | &sensor_dev_attr_pwm1.dev_attr.attr, |
| 1205 | &sensor_dev_attr_pwm2.dev_attr.attr, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1206 | &dev_attr_name.attr, |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1207 | NULL |
| 1208 | }; |
| 1209 | |
| 1210 | static const struct attribute_group w83627hf_group = { |
| 1211 | .attrs = w83627hf_attributes, |
| 1212 | }; |
| 1213 | |
| 1214 | static struct attribute *w83627hf_attributes_opt[] = { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1215 | VIN_UNIT_ATTRS(1), |
| 1216 | VIN_UNIT_ATTRS(5), |
| 1217 | VIN_UNIT_ATTRS(6), |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1218 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1219 | FAN_UNIT_ATTRS(3), |
| 1220 | TEMP_UNIT_ATTRS(3), |
| 1221 | &sensor_dev_attr_pwm3.dev_attr.attr, |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1222 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1223 | &sensor_dev_attr_pwm1_freq.dev_attr.attr, |
| 1224 | &sensor_dev_attr_pwm2_freq.dev_attr.attr, |
| 1225 | &sensor_dev_attr_pwm3_freq.dev_attr.attr, |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1226 | NULL |
| 1227 | }; |
| 1228 | |
| 1229 | static const struct attribute_group w83627hf_group_opt = { |
| 1230 | .attrs = w83627hf_attributes_opt, |
| 1231 | }; |
| 1232 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1233 | static int __devinit w83627hf_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1235 | struct device *dev = &pdev->dev; |
| 1236 | struct w83627hf_sio_data *sio_data = dev->platform_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | struct w83627hf_data *data; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1238 | struct resource *res; |
Jim Cromie | 2ca2fcd | 2007-10-14 17:20:50 -0600 | [diff] [blame] | 1239 | int err, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1241 | static const char *names[] = { |
| 1242 | "w83627hf", |
| 1243 | "w83627thf", |
| 1244 | "w83697hf", |
| 1245 | "w83637hf", |
| 1246 | "w83687thf", |
| 1247 | }; |
| 1248 | |
| 1249 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
| 1250 | if (!request_region(res->start, WINB_REGION_SIZE, DRVNAME)) { |
| 1251 | dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", |
| 1252 | (unsigned long)res->start, |
| 1253 | (unsigned long)(res->start + WINB_REGION_SIZE - 1)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | err = -EBUSY; |
| 1255 | goto ERROR0; |
| 1256 | } |
| 1257 | |
Deepak Saxena | ba9c2e8 | 2005-10-17 23:08:32 +0200 | [diff] [blame] | 1258 | if (!(data = kzalloc(sizeof(struct w83627hf_data), GFP_KERNEL))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | err = -ENOMEM; |
| 1260 | goto ERROR1; |
| 1261 | } |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1262 | data->addr = res->start; |
| 1263 | data->type = sio_data->type; |
| 1264 | data->name = names[sio_data->type]; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1265 | mutex_init(&data->lock); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1266 | mutex_init(&data->update_lock); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1267 | platform_set_drvdata(pdev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1268 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | /* Initialize the chip */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1270 | w83627hf_init_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1271 | |
| 1272 | /* A few vars need to be filled upon startup */ |
Jim Cromie | 2ca2fcd | 2007-10-14 17:20:50 -0600 | [diff] [blame] | 1273 | for (i = 0; i <= 2; i++) |
| 1274 | data->fan_min[i] = w83627hf_read_value( |
| 1275 | data, W83627HF_REG_FAN_MIN(i)); |
Jean Delvare | c09c518 | 2007-10-12 21:53:07 +0200 | [diff] [blame] | 1276 | w83627hf_update_fan_div(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1278 | /* Register common device attributes */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1279 | if ((err = sysfs_create_group(&dev->kobj, &w83627hf_group))) |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1280 | goto ERROR3; |
| 1281 | |
| 1282 | /* Register chip-specific device attributes */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1283 | if (data->type == w83627hf || data->type == w83697hf) |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1284 | if ((err = device_create_file(dev, |
| 1285 | &sensor_dev_attr_in5_input.dev_attr)) |
| 1286 | || (err = device_create_file(dev, |
| 1287 | &sensor_dev_attr_in5_min.dev_attr)) |
| 1288 | || (err = device_create_file(dev, |
| 1289 | &sensor_dev_attr_in5_max.dev_attr)) |
| 1290 | || (err = device_create_file(dev, |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 1291 | &sensor_dev_attr_in5_alarm.dev_attr)) |
| 1292 | || (err = device_create_file(dev, |
| 1293 | &sensor_dev_attr_in5_beep.dev_attr)) |
| 1294 | || (err = device_create_file(dev, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1295 | &sensor_dev_attr_in6_input.dev_attr)) |
| 1296 | || (err = device_create_file(dev, |
| 1297 | &sensor_dev_attr_in6_min.dev_attr)) |
| 1298 | || (err = device_create_file(dev, |
| 1299 | &sensor_dev_attr_in6_max.dev_attr)) |
| 1300 | || (err = device_create_file(dev, |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 1301 | &sensor_dev_attr_in6_alarm.dev_attr)) |
| 1302 | || (err = device_create_file(dev, |
| 1303 | &sensor_dev_attr_in6_beep.dev_attr)) |
| 1304 | || (err = device_create_file(dev, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1305 | &sensor_dev_attr_pwm1_freq.dev_attr)) |
| 1306 | || (err = device_create_file(dev, |
| 1307 | &sensor_dev_attr_pwm2_freq.dev_attr))) |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1308 | goto ERROR4; |
| 1309 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1310 | if (data->type != w83697hf) |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1311 | if ((err = device_create_file(dev, |
| 1312 | &sensor_dev_attr_in1_input.dev_attr)) |
| 1313 | || (err = device_create_file(dev, |
| 1314 | &sensor_dev_attr_in1_min.dev_attr)) |
| 1315 | || (err = device_create_file(dev, |
| 1316 | &sensor_dev_attr_in1_max.dev_attr)) |
| 1317 | || (err = device_create_file(dev, |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 1318 | &sensor_dev_attr_in1_alarm.dev_attr)) |
| 1319 | || (err = device_create_file(dev, |
| 1320 | &sensor_dev_attr_in1_beep.dev_attr)) |
| 1321 | || (err = device_create_file(dev, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1322 | &sensor_dev_attr_fan3_input.dev_attr)) |
| 1323 | || (err = device_create_file(dev, |
| 1324 | &sensor_dev_attr_fan3_min.dev_attr)) |
| 1325 | || (err = device_create_file(dev, |
| 1326 | &sensor_dev_attr_fan3_div.dev_attr)) |
| 1327 | || (err = device_create_file(dev, |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 1328 | &sensor_dev_attr_fan3_alarm.dev_attr)) |
| 1329 | || (err = device_create_file(dev, |
| 1330 | &sensor_dev_attr_fan3_beep.dev_attr)) |
| 1331 | || (err = device_create_file(dev, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1332 | &sensor_dev_attr_temp3_input.dev_attr)) |
| 1333 | || (err = device_create_file(dev, |
| 1334 | &sensor_dev_attr_temp3_max.dev_attr)) |
| 1335 | || (err = device_create_file(dev, |
| 1336 | &sensor_dev_attr_temp3_max_hyst.dev_attr)) |
| 1337 | || (err = device_create_file(dev, |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 1338 | &sensor_dev_attr_temp3_alarm.dev_attr)) |
| 1339 | || (err = device_create_file(dev, |
| 1340 | &sensor_dev_attr_temp3_beep.dev_attr)) |
| 1341 | || (err = device_create_file(dev, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1342 | &sensor_dev_attr_temp3_type.dev_attr))) |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1343 | goto ERROR4; |
| 1344 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1345 | if (data->type != w83697hf && data->vid != 0xff) { |
Jean Delvare | 8a665a0 | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1346 | /* Convert VID to voltage based on VRM */ |
| 1347 | data->vrm = vid_which_vrm(); |
| 1348 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1349 | if ((err = device_create_file(dev, &dev_attr_cpu0_vid)) |
| 1350 | || (err = device_create_file(dev, &dev_attr_vrm))) |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1351 | goto ERROR4; |
Jean Delvare | 8a665a0 | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1352 | } |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1353 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1354 | if (data->type == w83627thf || data->type == w83637hf |
| 1355 | || data->type == w83687thf) |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1356 | if ((err = device_create_file(dev, |
| 1357 | &sensor_dev_attr_pwm3.dev_attr))) |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1358 | goto ERROR4; |
| 1359 | |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1360 | if (data->type == w83637hf || data->type == w83687thf) |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1361 | if ((err = device_create_file(dev, |
| 1362 | &sensor_dev_attr_pwm1_freq.dev_attr)) |
| 1363 | || (err = device_create_file(dev, |
| 1364 | &sensor_dev_attr_pwm2_freq.dev_attr)) |
| 1365 | || (err = device_create_file(dev, |
| 1366 | &sensor_dev_attr_pwm3_freq.dev_attr))) |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1367 | goto ERROR4; |
| 1368 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1369 | data->hwmon_dev = hwmon_device_register(dev); |
| 1370 | if (IS_ERR(data->hwmon_dev)) { |
| 1371 | err = PTR_ERR(data->hwmon_dev); |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1372 | goto ERROR4; |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1373 | } |
| 1374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | return 0; |
| 1376 | |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1377 | ERROR4: |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1378 | sysfs_remove_group(&dev->kobj, &w83627hf_group); |
| 1379 | sysfs_remove_group(&dev->kobj, &w83627hf_group_opt); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1380 | ERROR3: |
Jean Delvare | 04a6217 | 2007-06-12 13:57:19 +0200 | [diff] [blame] | 1381 | platform_set_drvdata(pdev, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | kfree(data); |
| 1383 | ERROR1: |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1384 | release_region(res->start, WINB_REGION_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | ERROR0: |
| 1386 | return err; |
| 1387 | } |
| 1388 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1389 | static int __devexit w83627hf_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1391 | struct w83627hf_data *data = platform_get_drvdata(pdev); |
| 1392 | struct resource *res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1394 | hwmon_device_unregister(data->hwmon_dev); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1395 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1396 | sysfs_remove_group(&pdev->dev.kobj, &w83627hf_group); |
| 1397 | sysfs_remove_group(&pdev->dev.kobj, &w83627hf_group_opt); |
Jean Delvare | 04a6217 | 2007-06-12 13:57:19 +0200 | [diff] [blame] | 1398 | platform_set_drvdata(pdev, NULL); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1399 | kfree(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1401 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
| 1402 | release_region(res->start, WINB_REGION_SIZE); |
| 1403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | return 0; |
| 1405 | } |
| 1406 | |
| 1407 | |
Jean Delvare | d58df9c | 2007-10-10 16:30:23 +0200 | [diff] [blame] | 1408 | /* Registers 0x50-0x5f are banked */ |
| 1409 | static inline void w83627hf_set_bank(struct w83627hf_data *data, u16 reg) |
| 1410 | { |
| 1411 | if ((reg & 0x00f0) == 0x50) { |
| 1412 | outb_p(W83781D_REG_BANK, data->addr + W83781D_ADDR_REG_OFFSET); |
| 1413 | outb_p(reg >> 8, data->addr + W83781D_DATA_REG_OFFSET); |
| 1414 | } |
| 1415 | } |
| 1416 | |
| 1417 | /* Not strictly necessary, but play it safe for now */ |
| 1418 | static inline void w83627hf_reset_bank(struct w83627hf_data *data, u16 reg) |
| 1419 | { |
| 1420 | if (reg & 0xff00) { |
| 1421 | outb_p(W83781D_REG_BANK, data->addr + W83781D_ADDR_REG_OFFSET); |
| 1422 | outb_p(0, data->addr + W83781D_DATA_REG_OFFSET); |
| 1423 | } |
| 1424 | } |
| 1425 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1426 | static int w83627hf_read_value(struct w83627hf_data *data, u16 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1428 | int res, word_sized; |
| 1429 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1430 | mutex_lock(&data->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | word_sized = (((reg & 0xff00) == 0x100) |
| 1432 | || ((reg & 0xff00) == 0x200)) |
| 1433 | && (((reg & 0x00ff) == 0x50) |
| 1434 | || ((reg & 0x00ff) == 0x53) |
| 1435 | || ((reg & 0x00ff) == 0x55)); |
Jean Delvare | d58df9c | 2007-10-10 16:30:23 +0200 | [diff] [blame] | 1436 | w83627hf_set_bank(data, reg); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1437 | outb_p(reg & 0xff, data->addr + W83781D_ADDR_REG_OFFSET); |
| 1438 | res = inb_p(data->addr + W83781D_DATA_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | if (word_sized) { |
| 1440 | outb_p((reg & 0xff) + 1, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1441 | data->addr + W83781D_ADDR_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | res = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1443 | (res << 8) + inb_p(data->addr + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | W83781D_DATA_REG_OFFSET); |
| 1445 | } |
Jean Delvare | d58df9c | 2007-10-10 16:30:23 +0200 | [diff] [blame] | 1446 | w83627hf_reset_bank(data, reg); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1447 | mutex_unlock(&data->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1448 | return res; |
| 1449 | } |
| 1450 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1451 | static int __devinit w83627thf_read_gpio5(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | { |
| 1453 | int res = 0xff, sel; |
| 1454 | |
| 1455 | superio_enter(); |
| 1456 | superio_select(W83627HF_LD_GPIO5); |
| 1457 | |
| 1458 | /* Make sure these GPIO pins are enabled */ |
| 1459 | if (!(superio_inb(W83627THF_GPIO5_EN) & (1<<3))) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1460 | dev_dbg(&pdev->dev, "GPIO5 disabled, no VID function\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | goto exit; |
| 1462 | } |
| 1463 | |
| 1464 | /* Make sure the pins are configured for input |
| 1465 | 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] | 1466 | sel = superio_inb(W83627THF_GPIO5_IOSR) & 0x3f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1467 | if ((sel & 0x1f) != 0x1f) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1468 | dev_dbg(&pdev->dev, "GPIO5 not configured for VID " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | "function\n"); |
| 1470 | goto exit; |
| 1471 | } |
| 1472 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1473 | dev_info(&pdev->dev, "Reading VID from GPIO5\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | res = superio_inb(W83627THF_GPIO5_DR) & sel; |
| 1475 | |
| 1476 | exit: |
| 1477 | superio_exit(); |
| 1478 | return res; |
| 1479 | } |
| 1480 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1481 | static int __devinit w83687thf_read_vid(struct platform_device *pdev) |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 1482 | { |
| 1483 | int res = 0xff; |
| 1484 | |
| 1485 | superio_enter(); |
| 1486 | superio_select(W83627HF_LD_HWM); |
| 1487 | |
| 1488 | /* Make sure these GPIO pins are enabled */ |
| 1489 | if (!(superio_inb(W83687THF_VID_EN) & (1 << 2))) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1490 | dev_dbg(&pdev->dev, "VID disabled, no VID function\n"); |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 1491 | goto exit; |
| 1492 | } |
| 1493 | |
| 1494 | /* Make sure the pins are configured for input */ |
| 1495 | if (!(superio_inb(W83687THF_VID_CFG) & (1 << 4))) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1496 | dev_dbg(&pdev->dev, "VID configured as output, " |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 1497 | "no VID function\n"); |
| 1498 | goto exit; |
| 1499 | } |
| 1500 | |
| 1501 | res = superio_inb(W83687THF_VID_DATA) & 0x3f; |
| 1502 | |
| 1503 | exit: |
| 1504 | superio_exit(); |
| 1505 | return res; |
| 1506 | } |
| 1507 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1508 | 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] | 1509 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | int word_sized; |
| 1511 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1512 | mutex_lock(&data->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | word_sized = (((reg & 0xff00) == 0x100) |
| 1514 | || ((reg & 0xff00) == 0x200)) |
| 1515 | && (((reg & 0x00ff) == 0x53) |
| 1516 | || ((reg & 0x00ff) == 0x55)); |
Jean Delvare | d58df9c | 2007-10-10 16:30:23 +0200 | [diff] [blame] | 1517 | w83627hf_set_bank(data, reg); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1518 | outb_p(reg & 0xff, data->addr + W83781D_ADDR_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | if (word_sized) { |
| 1520 | outb_p(value >> 8, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1521 | data->addr + W83781D_DATA_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | outb_p((reg & 0xff) + 1, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1523 | data->addr + W83781D_ADDR_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | } |
| 1525 | outb_p(value & 0xff, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1526 | data->addr + W83781D_DATA_REG_OFFSET); |
Jean Delvare | d58df9c | 2007-10-10 16:30:23 +0200 | [diff] [blame] | 1527 | w83627hf_reset_bank(data, reg); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1528 | mutex_unlock(&data->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1529 | return 0; |
| 1530 | } |
| 1531 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1532 | static void __devinit w83627hf_init_device(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1534 | struct w83627hf_data *data = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | int i; |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1536 | enum chips type = data->type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | u8 tmp; |
| 1538 | |
Jean Delvare | 2251cf1 | 2005-09-04 22:52:17 +0200 | [diff] [blame] | 1539 | if (reset) { |
| 1540 | /* Resetting the chip has been the default for a long time, |
| 1541 | but repeatedly caused problems (fans going to full |
| 1542 | speed...) so it is now optional. It might even go away if |
| 1543 | nobody reports it as being useful, as I see very little |
| 1544 | reason why this would be needed at all. */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1545 | dev_info(&pdev->dev, "If reset=1 solved a problem you were " |
Jean Delvare | 2251cf1 | 2005-09-04 22:52:17 +0200 | [diff] [blame] | 1546 | "having, please report!\n"); |
| 1547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | /* save this register */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1549 | i = w83627hf_read_value(data, W83781D_REG_BEEP_CONFIG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | /* Reset all except Watchdog values and last conversion values |
| 1551 | This sets fan-divs to 2, among others */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1552 | w83627hf_write_value(data, W83781D_REG_CONFIG, 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | /* Restore the register and disable power-on abnormal beep. |
| 1554 | This saves FAN 1/2/3 input/output values set by BIOS. */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1555 | w83627hf_write_value(data, W83781D_REG_BEEP_CONFIG, i | 0x80); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | /* Disable master beep-enable (reset turns it on). |
| 1557 | Individual beeps should be reset to off but for some reason |
| 1558 | disabling this bit helps some people not get beeped */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1559 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS2, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | /* Minimize conflicts with other winbond i2c-only clients... */ |
| 1563 | /* disable i2c subclients... how to disable main i2c client?? */ |
| 1564 | /* force i2c address to relatively uncommon address */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1565 | w83627hf_write_value(data, W83781D_REG_I2C_SUBADDR, 0x89); |
| 1566 | w83627hf_write_value(data, W83781D_REG_I2C_ADDR, force_i2c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | |
| 1568 | /* Read VID only once */ |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1569 | if (type == w83627hf || type == w83637hf) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1570 | int lo = w83627hf_read_value(data, W83781D_REG_VID_FANDIV); |
| 1571 | int hi = w83627hf_read_value(data, W83781D_REG_CHIPID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | data->vid = (lo & 0x0f) | ((hi & 0x01) << 4); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1573 | } else if (type == w83627thf) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1574 | data->vid = w83627thf_read_gpio5(pdev); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1575 | } else if (type == w83687thf) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1576 | data->vid = w83687thf_read_vid(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | /* Read VRM & OVT Config only once */ |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1580 | if (type == w83627thf || type == w83637hf || type == w83687thf) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 | data->vrm_ovt = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1582 | w83627hf_read_value(data, W83627THF_REG_VRM_OVT_CFG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1583 | } |
| 1584 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1585 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | for (i = 1; i <= 3; i++) { |
| 1587 | if (!(tmp & BIT_SCFG1[i - 1])) { |
Jean Delvare | b26f933 | 2007-08-16 14:30:01 +0200 | [diff] [blame] | 1588 | data->sens[i - 1] = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | } else { |
| 1590 | if (w83627hf_read_value |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1591 | (data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | W83781D_REG_SCFG2) & BIT_SCFG2[i - 1]) |
| 1593 | data->sens[i - 1] = 1; |
| 1594 | else |
| 1595 | data->sens[i - 1] = 2; |
| 1596 | } |
| 1597 | if ((type == w83697hf) && (i == 2)) |
| 1598 | break; |
| 1599 | } |
| 1600 | |
| 1601 | if(init) { |
| 1602 | /* Enable temp2 */ |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 1603 | tmp = w83627hf_read_value(data, W83627HF_REG_TEMP2_CONFIG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1604 | if (tmp & 0x01) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1605 | dev_warn(&pdev->dev, "Enabling temp2, readings " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | "might not make sense\n"); |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 1607 | w83627hf_write_value(data, W83627HF_REG_TEMP2_CONFIG, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | tmp & 0xfe); |
| 1609 | } |
| 1610 | |
| 1611 | /* Enable temp3 */ |
| 1612 | if (type != w83697hf) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1613 | tmp = w83627hf_read_value(data, |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 1614 | W83627HF_REG_TEMP3_CONFIG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1615 | if (tmp & 0x01) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1616 | dev_warn(&pdev->dev, "Enabling temp3, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | "readings might not make sense\n"); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1618 | w83627hf_write_value(data, |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 1619 | W83627HF_REG_TEMP3_CONFIG, tmp & 0xfe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | } |
| 1621 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | /* Start monitoring */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1625 | w83627hf_write_value(data, W83781D_REG_CONFIG, |
| 1626 | (w83627hf_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | W83781D_REG_CONFIG) & 0xf7) |
| 1628 | | 0x01); |
Jean Delvare | ef878b1 | 2008-01-03 22:54:13 +0100 | [diff] [blame] | 1629 | |
| 1630 | /* Enable VBAT monitoring if needed */ |
| 1631 | tmp = w83627hf_read_value(data, W83781D_REG_VBAT); |
| 1632 | if (!(tmp & 0x01)) |
| 1633 | w83627hf_write_value(data, W83781D_REG_VBAT, tmp | 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | } |
| 1635 | |
Jean Delvare | c09c518 | 2007-10-12 21:53:07 +0200 | [diff] [blame] | 1636 | static void w83627hf_update_fan_div(struct w83627hf_data *data) |
| 1637 | { |
| 1638 | int reg; |
| 1639 | |
| 1640 | reg = w83627hf_read_value(data, W83781D_REG_VID_FANDIV); |
| 1641 | data->fan_div[0] = (reg >> 4) & 0x03; |
| 1642 | data->fan_div[1] = (reg >> 6) & 0x03; |
| 1643 | if (data->type != w83697hf) { |
| 1644 | data->fan_div[2] = (w83627hf_read_value(data, |
| 1645 | W83781D_REG_PIN) >> 6) & 0x03; |
| 1646 | } |
| 1647 | reg = w83627hf_read_value(data, W83781D_REG_VBAT); |
| 1648 | data->fan_div[0] |= (reg >> 3) & 0x04; |
| 1649 | data->fan_div[1] |= (reg >> 4) & 0x04; |
| 1650 | if (data->type != w83697hf) |
| 1651 | data->fan_div[2] |= (reg >> 5) & 0x04; |
| 1652 | } |
| 1653 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1654 | static struct w83627hf_data *w83627hf_update_device(struct device *dev) |
| 1655 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1656 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 1657 | int i, num_temps = (data->type == w83697hf) ? 2 : 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1659 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | |
| 1661 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
| 1662 | || !data->valid) { |
| 1663 | for (i = 0; i <= 8; i++) { |
| 1664 | /* skip missing sensors */ |
| 1665 | if (((data->type == w83697hf) && (i == 1)) || |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 1666 | ((data->type != w83627hf && data->type != w83697hf) |
Yuan Mu | 4a1c4447 | 2005-11-07 22:19:04 +0100 | [diff] [blame] | 1667 | && (i == 5 || i == 6))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | continue; |
| 1669 | data->in[i] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1670 | w83627hf_read_value(data, W83781D_REG_IN(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | data->in_min[i] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1672 | w83627hf_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1673 | W83781D_REG_IN_MIN(i)); |
| 1674 | data->in_max[i] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1675 | w83627hf_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1676 | W83781D_REG_IN_MAX(i)); |
| 1677 | } |
Jim Cromie | 2ca2fcd | 2007-10-14 17:20:50 -0600 | [diff] [blame] | 1678 | for (i = 0; i <= 2; i++) { |
| 1679 | data->fan[i] = |
| 1680 | w83627hf_read_value(data, W83627HF_REG_FAN(i)); |
| 1681 | data->fan_min[i] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1682 | w83627hf_read_value(data, |
Jim Cromie | 2ca2fcd | 2007-10-14 17:20:50 -0600 | [diff] [blame] | 1683 | W83627HF_REG_FAN_MIN(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1684 | } |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1685 | for (i = 0; i <= 2; i++) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1686 | u8 tmp = w83627hf_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1687 | W836X7HF_REG_PWM(data->type, i)); |
| 1688 | /* bits 0-3 are reserved in 627THF */ |
| 1689 | if (data->type == w83627thf) |
| 1690 | tmp &= 0xf0; |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1691 | data->pwm[i] = tmp; |
| 1692 | if (i == 1 && |
| 1693 | (data->type == w83627hf || data->type == w83697hf)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | break; |
| 1695 | } |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1696 | if (data->type == w83627hf) { |
| 1697 | u8 tmp = w83627hf_read_value(data, |
| 1698 | W83627HF_REG_PWM_FREQ); |
| 1699 | data->pwm_freq[0] = tmp & 0x07; |
| 1700 | data->pwm_freq[1] = (tmp >> 4) & 0x07; |
| 1701 | } else if (data->type != w83627thf) { |
| 1702 | for (i = 1; i <= 3; i++) { |
| 1703 | data->pwm_freq[i - 1] = |
| 1704 | w83627hf_read_value(data, |
| 1705 | W83637HF_REG_PWM_FREQ[i - 1]); |
| 1706 | if (i == 2 && (data->type == w83697hf)) |
| 1707 | break; |
| 1708 | } |
| 1709 | } |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 1710 | for (i = 0; i < num_temps; i++) { |
| 1711 | data->temp[i] = w83627hf_read_value( |
| 1712 | data, w83627hf_reg_temp[i]); |
| 1713 | data->temp_max[i] = w83627hf_read_value( |
| 1714 | data, w83627hf_reg_temp_over[i]); |
| 1715 | data->temp_max_hyst[i] = w83627hf_read_value( |
| 1716 | data, w83627hf_reg_temp_hyst[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1717 | } |
| 1718 | |
Jean Delvare | c09c518 | 2007-10-12 21:53:07 +0200 | [diff] [blame] | 1719 | w83627hf_update_fan_div(data); |
| 1720 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | data->alarms = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1722 | w83627hf_read_value(data, W83781D_REG_ALARM1) | |
| 1723 | (w83627hf_read_value(data, W83781D_REG_ALARM2) << 8) | |
| 1724 | (w83627hf_read_value(data, W83781D_REG_ALARM3) << 16); |
| 1725 | i = w83627hf_read_value(data, W83781D_REG_BEEP_INTS2); |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 1726 | data->beep_mask = (i << 8) | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1727 | w83627hf_read_value(data, W83781D_REG_BEEP_INTS1) | |
| 1728 | w83627hf_read_value(data, W83781D_REG_BEEP_INTS3) << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | data->last_updated = jiffies; |
| 1730 | data->valid = 1; |
| 1731 | } |
| 1732 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1733 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1734 | |
| 1735 | return data; |
| 1736 | } |
| 1737 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1738 | static int __init w83627hf_device_add(unsigned short address, |
| 1739 | const struct w83627hf_sio_data *sio_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1741 | struct resource res = { |
| 1742 | .start = address + WINB_REGION_OFFSET, |
| 1743 | .end = address + WINB_REGION_OFFSET + WINB_REGION_SIZE - 1, |
| 1744 | .name = DRVNAME, |
| 1745 | .flags = IORESOURCE_IO, |
| 1746 | }; |
| 1747 | int err; |
| 1748 | |
| 1749 | pdev = platform_device_alloc(DRVNAME, address); |
| 1750 | if (!pdev) { |
| 1751 | err = -ENOMEM; |
| 1752 | printk(KERN_ERR DRVNAME ": Device allocation failed\n"); |
| 1753 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1756 | err = platform_device_add_resources(pdev, &res, 1); |
| 1757 | if (err) { |
| 1758 | printk(KERN_ERR DRVNAME ": Device resource addition failed " |
| 1759 | "(%d)\n", err); |
| 1760 | goto exit_device_put; |
| 1761 | } |
| 1762 | |
Jean Delvare | 2df6d81 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1763 | err = platform_device_add_data(pdev, sio_data, |
| 1764 | sizeof(struct w83627hf_sio_data)); |
| 1765 | if (err) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1766 | printk(KERN_ERR DRVNAME ": Platform data allocation failed\n"); |
| 1767 | goto exit_device_put; |
| 1768 | } |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1769 | |
| 1770 | err = platform_device_add(pdev); |
| 1771 | if (err) { |
| 1772 | printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", |
| 1773 | err); |
| 1774 | goto exit_device_put; |
| 1775 | } |
| 1776 | |
| 1777 | return 0; |
| 1778 | |
| 1779 | exit_device_put: |
| 1780 | platform_device_put(pdev); |
| 1781 | exit: |
| 1782 | return err; |
| 1783 | } |
| 1784 | |
| 1785 | static int __init sensors_w83627hf_init(void) |
| 1786 | { |
| 1787 | int err; |
| 1788 | unsigned short address; |
| 1789 | struct w83627hf_sio_data sio_data; |
| 1790 | |
| 1791 | if (w83627hf_find(0x2e, &address, &sio_data) |
| 1792 | && w83627hf_find(0x4e, &address, &sio_data)) |
| 1793 | return -ENODEV; |
| 1794 | |
| 1795 | err = platform_driver_register(&w83627hf_driver); |
| 1796 | if (err) |
| 1797 | goto exit; |
| 1798 | |
| 1799 | /* Sets global pdev as a side effect */ |
| 1800 | err = w83627hf_device_add(address, &sio_data); |
| 1801 | if (err) |
| 1802 | goto exit_driver; |
| 1803 | |
| 1804 | return 0; |
| 1805 | |
| 1806 | exit_driver: |
| 1807 | platform_driver_unregister(&w83627hf_driver); |
| 1808 | exit: |
| 1809 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | } |
| 1811 | |
| 1812 | static void __exit sensors_w83627hf_exit(void) |
| 1813 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1814 | platform_device_unregister(pdev); |
| 1815 | platform_driver_unregister(&w83627hf_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1816 | } |
| 1817 | |
| 1818 | MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, " |
| 1819 | "Philip Edelbrock <phil@netroedge.com>, " |
| 1820 | "and Mark Studebaker <mdsxyz123@yahoo.com>"); |
| 1821 | MODULE_DESCRIPTION("W83627HF driver"); |
| 1822 | MODULE_LICENSE("GPL"); |
| 1823 | |
| 1824 | module_init(sensors_w83627hf_init); |
| 1825 | module_exit(sensors_w83627hf_exit); |