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