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