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> |
Jean Delvare | 7c81c60f | 2014-01-29 20:40:08 +0100 | [diff] [blame] | 8 | * Copyright (c) 2007 - 1012 Jean Delvare <jdelvare@suse.de> |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License as published by |
| 12 | * the Free Software Foundation; either version 2 of the License, or |
| 13 | * (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 23 | */ |
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 | * |
Jean Delvare | 4101ece | 2012-11-05 21:54:40 +0100 | [diff] [blame] | 28 | * Chip #vin #fanin #pwm #temp wchipid vendid i2c ISA |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 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 | */ |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 257 | #define IN_TO_REG(val) (clamp_val((((val) + 8) / 16), 0, 255)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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; |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 264 | rpm = clamp_val(rpm, 1, 1000000); |
| 265 | return clamp_val((1350000 + rpm * div / 2) / (rpm * div), 1, 254); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | #define TEMP_MIN (-128000) |
| 269 | #define TEMP_MAX ( 127000) |
| 270 | |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 271 | /* |
| 272 | * TEMP: 0.001C/bit (-128C to +127C) |
| 273 | * REG: 1C/bit, two's complement |
| 274 | */ |
Christian Hohnstaedt | 5bfedac | 2007-08-16 11:40:10 +0200 | [diff] [blame] | 275 | static u8 TEMP_TO_REG(long temp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | { |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 277 | int ntemp = clamp_val(temp, TEMP_MIN, TEMP_MAX); |
| 278 | ntemp += (ntemp < 0 ? -500 : 500); |
| 279 | return (u8)(ntemp / 1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | static int TEMP_FROM_REG(u8 reg) |
| 283 | { |
| 284 | return (s8)reg * 1000; |
| 285 | } |
| 286 | |
| 287 | #define FAN_FROM_REG(val,div) ((val)==0?-1:(val)==255?0:1350000/((val)*(div))) |
| 288 | |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 289 | #define PWM_TO_REG(val) (clamp_val((val), 0, 255)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 291 | static inline unsigned long pwm_freq_from_reg_627hf(u8 reg) |
| 292 | { |
| 293 | unsigned long freq; |
| 294 | freq = W83627HF_BASE_PWM_FREQ >> reg; |
| 295 | return freq; |
| 296 | } |
| 297 | static inline u8 pwm_freq_to_reg_627hf(unsigned long val) |
| 298 | { |
| 299 | u8 i; |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 300 | /* |
| 301 | * Only 5 dividers (1 2 4 8 16) |
| 302 | * Search for the nearest available frequency |
| 303 | */ |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 304 | for (i = 0; i < 4; i++) { |
| 305 | if (val > (((W83627HF_BASE_PWM_FREQ >> i) + |
| 306 | (W83627HF_BASE_PWM_FREQ >> (i+1))) / 2)) |
| 307 | break; |
| 308 | } |
| 309 | return i; |
| 310 | } |
| 311 | |
| 312 | static inline unsigned long pwm_freq_from_reg(u8 reg) |
| 313 | { |
| 314 | /* Clock bit 8 -> 180 kHz or 24 MHz */ |
| 315 | unsigned long clock = (reg & 0x80) ? 180000UL : 24000000UL; |
| 316 | |
| 317 | reg &= 0x7f; |
| 318 | /* This should not happen but anyway... */ |
| 319 | if (reg == 0) |
| 320 | reg++; |
Frans Meulenbroeks | 7fe83ad | 2012-01-05 19:50:18 +0100 | [diff] [blame] | 321 | return clock / (reg << 8); |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 322 | } |
| 323 | static inline u8 pwm_freq_to_reg(unsigned long val) |
| 324 | { |
| 325 | /* Minimum divider value is 0x01 and maximum is 0x7F */ |
| 326 | if (val >= 93750) /* The highest we can do */ |
| 327 | return 0x01; |
| 328 | if (val >= 720) /* Use 24 MHz clock */ |
Frans Meulenbroeks | 7fe83ad | 2012-01-05 19:50:18 +0100 | [diff] [blame] | 329 | return 24000000UL / (val << 8); |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 330 | if (val < 6) /* The lowest we can do */ |
| 331 | return 0xFF; |
| 332 | else /* Use 180 kHz clock */ |
Frans Meulenbroeks | 7fe83ad | 2012-01-05 19:50:18 +0100 | [diff] [blame] | 333 | return 0x80 | (180000UL / (val << 8)); |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 334 | } |
| 335 | |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 336 | #define BEEP_MASK_FROM_REG(val) ((val) & 0xff7fff) |
| 337 | #define BEEP_MASK_TO_REG(val) ((val) & 0xff7fff) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
| 339 | #define DIV_FROM_REG(val) (1 << (val)) |
| 340 | |
| 341 | static inline u8 DIV_TO_REG(long val) |
| 342 | { |
| 343 | int i; |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 344 | val = clamp_val(val, 1, 128) >> 1; |
Grant Coady | abc0192 | 2005-05-12 13:41:51 +1000 | [diff] [blame] | 345 | for (i = 0; i < 7; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | if (val == 0) |
| 347 | break; |
| 348 | val >>= 1; |
| 349 | } |
Frans Meulenbroeks | 7fe83ad | 2012-01-05 19:50:18 +0100 | [diff] [blame] | 350 | return (u8)i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 353 | /* |
| 354 | * For each registered chip, we need to keep some data in memory. |
| 355 | * The structure is dynamically allocated. |
| 356 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | struct w83627hf_data { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 358 | unsigned short addr; |
| 359 | const char *name; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 360 | struct device *hwmon_dev; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 361 | struct mutex lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | enum chips type; |
| 363 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 364 | struct mutex update_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | char valid; /* !=0 if following fields are valid */ |
| 366 | unsigned long last_updated; /* In jiffies */ |
| 367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | u8 in[9]; /* Register value */ |
| 369 | u8 in_max[9]; /* Register value */ |
| 370 | u8 in_min[9]; /* Register value */ |
| 371 | u8 fan[3]; /* Register value */ |
| 372 | u8 fan_min[3]; /* Register value */ |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 373 | u16 temp[3]; /* Register value */ |
| 374 | u16 temp_max[3]; /* Register value */ |
| 375 | u16 temp_max_hyst[3]; /* Register value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | u8 fan_div[3]; /* Register encoding, shifted right */ |
| 377 | u8 vid; /* Register encoding, combined */ |
| 378 | u32 alarms; /* Register encoding, combined */ |
| 379 | u32 beep_mask; /* Register encoding, combined */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | u8 pwm[3]; /* Register value */ |
Dominik Geyer | a95a5ed | 2008-08-06 22:41:04 +0200 | [diff] [blame] | 381 | u8 pwm_enable[3]; /* 1 = manual |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 382 | * 2 = thermal cruise (also called SmartFan I) |
| 383 | * 3 = fan speed cruise |
| 384 | */ |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 385 | u8 pwm_freq[3]; /* Register value */ |
Jean Delvare | b26f933 | 2007-08-16 14:30:01 +0200 | [diff] [blame] | 386 | u16 sens[3]; /* 1 = pentium diode; 2 = 3904 diode; |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 387 | * 4 = thermistor |
| 388 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | u8 vrm; |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 390 | u8 vrm_ovt; /* Register value, 627THF/637HF/687THF only */ |
Jean Delvare | 275b7d6 | 2012-12-19 22:16:59 +0100 | [diff] [blame] | 391 | |
| 392 | #ifdef CONFIG_PM |
| 393 | /* Remember extra register values over suspend/resume */ |
| 394 | u8 scfg1; |
| 395 | u8 scfg2; |
| 396 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | }; |
| 398 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 399 | static int w83627hf_probe(struct platform_device *pdev); |
Bill Pemberton | 281dfd0 | 2012-11-19 13:25:51 -0500 | [diff] [blame] | 400 | static int w83627hf_remove(struct platform_device *pdev); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 401 | |
| 402 | static int w83627hf_read_value(struct w83627hf_data *data, u16 reg); |
| 403 | 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] | 404 | static void w83627hf_update_fan_div(struct w83627hf_data *data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | static struct w83627hf_data *w83627hf_update_device(struct device *dev); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 406 | static void w83627hf_init_device(struct platform_device *pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
Jean Delvare | 275b7d6 | 2012-12-19 22:16:59 +0100 | [diff] [blame] | 408 | #ifdef CONFIG_PM |
| 409 | static int w83627hf_suspend(struct device *dev) |
| 410 | { |
| 411 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 412 | |
| 413 | mutex_lock(&data->update_lock); |
| 414 | data->scfg1 = w83627hf_read_value(data, W83781D_REG_SCFG1); |
| 415 | data->scfg2 = w83627hf_read_value(data, W83781D_REG_SCFG2); |
| 416 | mutex_unlock(&data->update_lock); |
| 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | static int w83627hf_resume(struct device *dev) |
| 422 | { |
| 423 | struct w83627hf_data *data = dev_get_drvdata(dev); |
| 424 | int i, num_temps = (data->type == w83697hf) ? 2 : 3; |
| 425 | |
| 426 | /* Restore limits */ |
| 427 | mutex_lock(&data->update_lock); |
| 428 | for (i = 0; i <= 8; i++) { |
| 429 | /* skip missing sensors */ |
| 430 | if (((data->type == w83697hf) && (i == 1)) || |
| 431 | ((data->type != w83627hf && data->type != w83697hf) |
| 432 | && (i == 5 || i == 6))) |
| 433 | continue; |
| 434 | w83627hf_write_value(data, W83781D_REG_IN_MAX(i), |
| 435 | data->in_max[i]); |
| 436 | w83627hf_write_value(data, W83781D_REG_IN_MIN(i), |
| 437 | data->in_min[i]); |
| 438 | } |
| 439 | for (i = 0; i <= 2; i++) |
| 440 | w83627hf_write_value(data, W83627HF_REG_FAN_MIN(i), |
| 441 | data->fan_min[i]); |
| 442 | for (i = 0; i < num_temps; i++) { |
| 443 | w83627hf_write_value(data, w83627hf_reg_temp_over[i], |
| 444 | data->temp_max[i]); |
| 445 | w83627hf_write_value(data, w83627hf_reg_temp_hyst[i], |
| 446 | data->temp_max_hyst[i]); |
| 447 | } |
| 448 | |
| 449 | /* Fixup BIOS bugs */ |
| 450 | if (data->type == w83627thf || data->type == w83637hf || |
| 451 | data->type == w83687thf) |
| 452 | w83627hf_write_value(data, W83627THF_REG_VRM_OVT_CFG, |
| 453 | data->vrm_ovt); |
| 454 | w83627hf_write_value(data, W83781D_REG_SCFG1, data->scfg1); |
| 455 | w83627hf_write_value(data, W83781D_REG_SCFG2, data->scfg2); |
| 456 | |
| 457 | /* Force re-reading all values */ |
| 458 | data->valid = 0; |
| 459 | mutex_unlock(&data->update_lock); |
| 460 | |
| 461 | return 0; |
| 462 | } |
| 463 | |
| 464 | static const struct dev_pm_ops w83627hf_dev_pm_ops = { |
| 465 | .suspend = w83627hf_suspend, |
| 466 | .resume = w83627hf_resume, |
| 467 | }; |
| 468 | |
| 469 | #define W83627HF_DEV_PM_OPS (&w83627hf_dev_pm_ops) |
| 470 | #else |
| 471 | #define W83627HF_DEV_PM_OPS NULL |
| 472 | #endif /* CONFIG_PM */ |
| 473 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 474 | static struct platform_driver w83627hf_driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 475 | .driver = { |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 476 | .name = DRVNAME, |
Jean Delvare | 275b7d6 | 2012-12-19 22:16:59 +0100 | [diff] [blame] | 477 | .pm = W83627HF_DEV_PM_OPS, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 478 | }, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 479 | .probe = w83627hf_probe, |
Bill Pemberton | 9e5e9b7 | 2012-11-19 13:21:20 -0500 | [diff] [blame] | 480 | .remove = w83627hf_remove, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | }; |
| 482 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 483 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 484 | in_input_show(struct device *dev, struct device_attribute *devattr, char *buf) |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 485 | { |
| 486 | int nr = to_sensor_dev_attr(devattr)->index; |
| 487 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 488 | return sprintf(buf, "%ld\n", (long)IN_FROM_REG(data->in[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | } |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 490 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 491 | in_min_show(struct device *dev, struct device_attribute *devattr, char *buf) |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 492 | { |
| 493 | int nr = to_sensor_dev_attr(devattr)->index; |
| 494 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 495 | 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] | 496 | } |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 497 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 498 | in_max_show(struct device *dev, struct device_attribute *devattr, char *buf) |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 499 | { |
| 500 | int nr = to_sensor_dev_attr(devattr)->index; |
| 501 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 502 | return sprintf(buf, "%ld\n", (long)IN_FROM_REG(data->in_max[nr])); |
| 503 | } |
| 504 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 505 | in_min_store(struct device *dev, struct device_attribute *devattr, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 506 | const char *buf, size_t count) |
| 507 | { |
| 508 | int nr = to_sensor_dev_attr(devattr)->index; |
| 509 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 510 | long val; |
| 511 | int err; |
| 512 | |
| 513 | err = kstrtol(buf, 10, &val); |
| 514 | if (err) |
| 515 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 517 | mutex_lock(&data->update_lock); |
| 518 | data->in_min[nr] = IN_TO_REG(val); |
| 519 | w83627hf_write_value(data, W83781D_REG_IN_MIN(nr), data->in_min[nr]); |
| 520 | mutex_unlock(&data->update_lock); |
| 521 | return count; |
| 522 | } |
| 523 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 524 | in_max_store(struct device *dev, struct device_attribute *devattr, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 525 | const char *buf, size_t count) |
| 526 | { |
| 527 | int nr = to_sensor_dev_attr(devattr)->index; |
| 528 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 529 | long val; |
| 530 | int err; |
| 531 | |
| 532 | err = kstrtol(buf, 10, &val); |
| 533 | if (err) |
| 534 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 536 | mutex_lock(&data->update_lock); |
| 537 | data->in_max[nr] = IN_TO_REG(val); |
| 538 | w83627hf_write_value(data, W83781D_REG_IN_MAX(nr), data->in_max[nr]); |
| 539 | mutex_unlock(&data->update_lock); |
| 540 | return count; |
| 541 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 543 | static SENSOR_DEVICE_ATTR_RO(in1_input, in_input, 1); |
| 544 | static SENSOR_DEVICE_ATTR_RW(in1_min, in_min, 1); |
| 545 | static SENSOR_DEVICE_ATTR_RW(in1_max, in_max, 1); |
| 546 | static SENSOR_DEVICE_ATTR_RO(in2_input, in_input, 2); |
| 547 | static SENSOR_DEVICE_ATTR_RW(in2_min, in_min, 2); |
| 548 | static SENSOR_DEVICE_ATTR_RW(in2_max, in_max, 2); |
| 549 | static SENSOR_DEVICE_ATTR_RO(in3_input, in_input, 3); |
| 550 | static SENSOR_DEVICE_ATTR_RW(in3_min, in_min, 3); |
| 551 | static SENSOR_DEVICE_ATTR_RW(in3_max, in_max, 3); |
| 552 | static SENSOR_DEVICE_ATTR_RO(in4_input, in_input, 4); |
| 553 | static SENSOR_DEVICE_ATTR_RW(in4_min, in_min, 4); |
| 554 | static SENSOR_DEVICE_ATTR_RW(in4_max, in_max, 4); |
| 555 | static SENSOR_DEVICE_ATTR_RO(in5_input, in_input, 5); |
| 556 | static SENSOR_DEVICE_ATTR_RW(in5_min, in_min, 5); |
| 557 | static SENSOR_DEVICE_ATTR_RW(in5_max, in_max, 5); |
| 558 | static SENSOR_DEVICE_ATTR_RO(in6_input, in_input, 6); |
| 559 | static SENSOR_DEVICE_ATTR_RW(in6_min, in_min, 6); |
| 560 | static SENSOR_DEVICE_ATTR_RW(in6_max, in_max, 6); |
| 561 | static SENSOR_DEVICE_ATTR_RO(in7_input, in_input, 7); |
| 562 | static SENSOR_DEVICE_ATTR_RW(in7_min, in_min, 7); |
| 563 | static SENSOR_DEVICE_ATTR_RW(in7_max, in_max, 7); |
| 564 | static SENSOR_DEVICE_ATTR_RO(in8_input, in_input, 8); |
| 565 | static SENSOR_DEVICE_ATTR_RW(in8_min, in_min, 8); |
| 566 | static SENSOR_DEVICE_ATTR_RW(in8_max, in_max, 8); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
| 568 | /* use a different set of functions for in0 */ |
| 569 | static ssize_t show_in_0(struct w83627hf_data *data, char *buf, u8 reg) |
| 570 | { |
| 571 | long in0; |
| 572 | |
| 573 | if ((data->vrm_ovt & 0x01) && |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 574 | (w83627thf == data->type || w83637hf == data->type |
| 575 | || w83687thf == data->type)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | |
| 577 | /* use VRM9 calculation */ |
| 578 | in0 = (long)((reg * 488 + 70000 + 50) / 100); |
| 579 | else |
| 580 | /* use VRM8 (standard) calculation */ |
| 581 | in0 = (long)IN_FROM_REG(reg); |
| 582 | |
| 583 | return sprintf(buf,"%ld\n", in0); |
| 584 | } |
| 585 | |
Julia Lawall | 8dfcdfc | 2016-12-22 13:05:11 +0100 | [diff] [blame] | 586 | static ssize_t in0_input_show(struct device *dev, |
| 587 | struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | { |
| 589 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 590 | return show_in_0(data, buf, data->in[0]); |
| 591 | } |
| 592 | |
Julia Lawall | 8dfcdfc | 2016-12-22 13:05:11 +0100 | [diff] [blame] | 593 | static ssize_t in0_min_show(struct device *dev, struct device_attribute *attr, |
| 594 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | { |
| 596 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 597 | return show_in_0(data, buf, data->in_min[0]); |
| 598 | } |
| 599 | |
Julia Lawall | 8dfcdfc | 2016-12-22 13:05:11 +0100 | [diff] [blame] | 600 | static ssize_t in0_max_show(struct device *dev, struct device_attribute *attr, |
| 601 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | { |
| 603 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 604 | return show_in_0(data, buf, data->in_max[0]); |
| 605 | } |
| 606 | |
Julia Lawall | 8dfcdfc | 2016-12-22 13:05:11 +0100 | [diff] [blame] | 607 | static ssize_t in0_min_store(struct device *dev, |
| 608 | struct device_attribute *attr, const char *buf, |
| 609 | size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 611 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 612 | unsigned long val; |
| 613 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 615 | err = kstrtoul(buf, 10, &val); |
| 616 | if (err) |
| 617 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 619 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | |
| 621 | if ((data->vrm_ovt & 0x01) && |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 622 | (w83627thf == data->type || w83637hf == data->type |
| 623 | || w83687thf == data->type)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
| 625 | /* use VRM9 calculation */ |
Yuan Mu | 2723ab9 | 2005-11-23 15:44:21 -0800 | [diff] [blame] | 626 | data->in_min[0] = |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 627 | clamp_val(((val * 100) - 70000 + 244) / 488, 0, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | else |
| 629 | /* use VRM8 (standard) calculation */ |
| 630 | data->in_min[0] = IN_TO_REG(val); |
| 631 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 632 | 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] | 633 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | return count; |
| 635 | } |
| 636 | |
Julia Lawall | 8dfcdfc | 2016-12-22 13:05:11 +0100 | [diff] [blame] | 637 | static ssize_t in0_max_store(struct device *dev, |
| 638 | struct device_attribute *attr, const char *buf, |
| 639 | size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 641 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 642 | unsigned long val; |
| 643 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 645 | err = kstrtoul(buf, 10, &val); |
| 646 | if (err) |
| 647 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 649 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | |
| 651 | if ((data->vrm_ovt & 0x01) && |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 652 | (w83627thf == data->type || w83637hf == data->type |
| 653 | || w83687thf == data->type)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | |
| 655 | /* use VRM9 calculation */ |
Yuan Mu | 2723ab9 | 2005-11-23 15:44:21 -0800 | [diff] [blame] | 656 | data->in_max[0] = |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 657 | clamp_val(((val * 100) - 70000 + 244) / 488, 0, 255); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | else |
| 659 | /* use VRM8 (standard) calculation */ |
| 660 | data->in_max[0] = IN_TO_REG(val); |
| 661 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 662 | 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] | 663 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | return count; |
| 665 | } |
| 666 | |
Julia Lawall | 8dfcdfc | 2016-12-22 13:05:11 +0100 | [diff] [blame] | 667 | static DEVICE_ATTR_RO(in0_input); |
| 668 | static DEVICE_ATTR_RW(in0_min); |
| 669 | static DEVICE_ATTR_RW(in0_max); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 671 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 672 | fan_input_show(struct device *dev, struct device_attribute *devattr, |
| 673 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 675 | int nr = to_sensor_dev_attr(devattr)->index; |
| 676 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 677 | return sprintf(buf, "%ld\n", FAN_FROM_REG(data->fan[nr], |
| 678 | (long)DIV_FROM_REG(data->fan_div[nr]))); |
| 679 | } |
| 680 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 681 | fan_min_show(struct device *dev, struct device_attribute *devattr, char *buf) |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 682 | { |
| 683 | int nr = to_sensor_dev_attr(devattr)->index; |
| 684 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 685 | return sprintf(buf, "%ld\n", FAN_FROM_REG(data->fan_min[nr], |
| 686 | (long)DIV_FROM_REG(data->fan_div[nr]))); |
| 687 | } |
| 688 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 689 | fan_min_store(struct device *dev, struct device_attribute *devattr, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 690 | const char *buf, size_t count) |
| 691 | { |
| 692 | int nr = to_sensor_dev_attr(devattr)->index; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 693 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 694 | unsigned long val; |
| 695 | int err; |
| 696 | |
| 697 | err = kstrtoul(buf, 10, &val); |
| 698 | if (err) |
| 699 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 701 | mutex_lock(&data->update_lock); |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 702 | 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] | 703 | w83627hf_write_value(data, W83627HF_REG_FAN_MIN(nr), |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 704 | data->fan_min[nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 706 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | return count; |
| 708 | } |
| 709 | |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 710 | static SENSOR_DEVICE_ATTR_RO(fan1_input, fan_input, 0); |
| 711 | static SENSOR_DEVICE_ATTR_RW(fan1_min, fan_min, 0); |
| 712 | static SENSOR_DEVICE_ATTR_RO(fan2_input, fan_input, 1); |
| 713 | static SENSOR_DEVICE_ATTR_RW(fan2_min, fan_min, 1); |
| 714 | static SENSOR_DEVICE_ATTR_RO(fan3_input, fan_input, 2); |
| 715 | static SENSOR_DEVICE_ATTR_RW(fan3_min, fan_min, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 716 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 717 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 718 | temp_show(struct device *dev, struct device_attribute *devattr, char *buf) |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 719 | { |
| 720 | int nr = to_sensor_dev_attr(devattr)->index; |
| 721 | struct w83627hf_data *data = w83627hf_update_device(dev); |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 722 | |
| 723 | u16 tmp = data->temp[nr]; |
| 724 | return sprintf(buf, "%ld\n", (nr) ? (long) LM75_TEMP_FROM_REG(tmp) |
| 725 | : (long) TEMP_FROM_REG(tmp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 728 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 729 | temp_max_show(struct device *dev, struct device_attribute *devattr, char *buf) |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 730 | { |
| 731 | int nr = to_sensor_dev_attr(devattr)->index; |
| 732 | struct w83627hf_data *data = w83627hf_update_device(dev); |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 733 | |
| 734 | u16 tmp = data->temp_max[nr]; |
| 735 | return sprintf(buf, "%ld\n", (nr) ? (long) LM75_TEMP_FROM_REG(tmp) |
| 736 | : (long) TEMP_FROM_REG(tmp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 739 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 740 | temp_max_hyst_show(struct device *dev, struct device_attribute *devattr, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 741 | char *buf) |
| 742 | { |
| 743 | int nr = to_sensor_dev_attr(devattr)->index; |
| 744 | struct w83627hf_data *data = w83627hf_update_device(dev); |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 745 | |
| 746 | u16 tmp = data->temp_max_hyst[nr]; |
| 747 | return sprintf(buf, "%ld\n", (nr) ? (long) LM75_TEMP_FROM_REG(tmp) |
| 748 | : (long) TEMP_FROM_REG(tmp)); |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 749 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 751 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 752 | temp_max_store(struct device *dev, struct device_attribute *devattr, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 753 | const char *buf, size_t count) |
| 754 | { |
| 755 | int nr = to_sensor_dev_attr(devattr)->index; |
| 756 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 757 | u16 tmp; |
| 758 | long val; |
| 759 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 761 | err = kstrtol(buf, 10, &val); |
| 762 | if (err) |
| 763 | return err; |
| 764 | |
| 765 | tmp = (nr) ? LM75_TEMP_TO_REG(val) : TEMP_TO_REG(val); |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 766 | mutex_lock(&data->update_lock); |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 767 | data->temp_max[nr] = tmp; |
| 768 | w83627hf_write_value(data, w83627hf_reg_temp_over[nr], tmp); |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 769 | mutex_unlock(&data->update_lock); |
| 770 | return count; |
| 771 | } |
| 772 | |
| 773 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 774 | temp_max_hyst_store(struct device *dev, struct device_attribute *devattr, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 775 | const char *buf, size_t count) |
| 776 | { |
| 777 | int nr = to_sensor_dev_attr(devattr)->index; |
| 778 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 779 | u16 tmp; |
| 780 | long val; |
| 781 | int err; |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 782 | |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 783 | err = kstrtol(buf, 10, &val); |
| 784 | if (err) |
| 785 | return err; |
| 786 | |
| 787 | tmp = (nr) ? LM75_TEMP_TO_REG(val) : TEMP_TO_REG(val); |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 788 | mutex_lock(&data->update_lock); |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 789 | data->temp_max_hyst[nr] = tmp; |
| 790 | w83627hf_write_value(data, w83627hf_reg_temp_hyst[nr], tmp); |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 791 | mutex_unlock(&data->update_lock); |
| 792 | return count; |
| 793 | } |
| 794 | |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 795 | static SENSOR_DEVICE_ATTR_RO(temp1_input, temp, 0); |
| 796 | static SENSOR_DEVICE_ATTR_RW(temp1_max, temp_max, 0); |
| 797 | static SENSOR_DEVICE_ATTR_RW(temp1_max_hyst, temp_max_hyst, 0); |
| 798 | static SENSOR_DEVICE_ATTR_RO(temp2_input, temp, 1); |
| 799 | static SENSOR_DEVICE_ATTR_RW(temp2_max, temp_max, 1); |
| 800 | static SENSOR_DEVICE_ATTR_RW(temp2_max_hyst, temp_max_hyst, 1); |
| 801 | static SENSOR_DEVICE_ATTR_RO(temp3_input, temp, 2); |
| 802 | static SENSOR_DEVICE_ATTR_RW(temp3_max, temp_max, 2); |
| 803 | static SENSOR_DEVICE_ATTR_RW(temp3_max_hyst, temp_max_hyst, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | static ssize_t |
Julia Lawall | 8dfcdfc | 2016-12-22 13:05:11 +0100 | [diff] [blame] | 806 | cpu0_vid_show(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | { |
| 808 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 809 | return sprintf(buf, "%ld\n", (long) vid_from_reg(data->vid, data->vrm)); |
| 810 | } |
Julia Lawall | 8dfcdfc | 2016-12-22 13:05:11 +0100 | [diff] [blame] | 811 | static DEVICE_ATTR_RO(cpu0_vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | |
| 813 | static ssize_t |
Julia Lawall | 8dfcdfc | 2016-12-22 13:05:11 +0100 | [diff] [blame] | 814 | vrm_show(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | { |
Jean Delvare | 90d6619 | 2007-10-08 18:24:35 +0200 | [diff] [blame] | 816 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | return sprintf(buf, "%ld\n", (long) data->vrm); |
| 818 | } |
| 819 | static ssize_t |
Julia Lawall | 8dfcdfc | 2016-12-22 13:05:11 +0100 | [diff] [blame] | 820 | vrm_store(struct device *dev, struct device_attribute *attr, const char *buf, |
| 821 | size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 823 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 824 | unsigned long val; |
| 825 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 827 | err = kstrtoul(buf, 10, &val); |
| 828 | if (err) |
| 829 | return err; |
Axel Lin | 970255b | 2014-08-06 08:27:11 +0800 | [diff] [blame] | 830 | |
| 831 | if (val > 255) |
| 832 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | data->vrm = val; |
| 834 | |
| 835 | return count; |
| 836 | } |
Julia Lawall | 8dfcdfc | 2016-12-22 13:05:11 +0100 | [diff] [blame] | 837 | static DEVICE_ATTR_RW(vrm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | |
| 839 | static ssize_t |
Julia Lawall | 8dfcdfc | 2016-12-22 13:05:11 +0100 | [diff] [blame] | 840 | alarms_show(struct device *dev, struct device_attribute *attr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | { |
| 842 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 843 | return sprintf(buf, "%ld\n", (long) data->alarms); |
| 844 | } |
Julia Lawall | 8dfcdfc | 2016-12-22 13:05:11 +0100 | [diff] [blame] | 845 | static DEVICE_ATTR_RO(alarms); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 847 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 848 | alarm_show(struct device *dev, struct device_attribute *attr, char *buf) |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 849 | { |
| 850 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 851 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 852 | return sprintf(buf, "%u\n", (data->alarms >> bitnr) & 1); |
| 853 | } |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 854 | static SENSOR_DEVICE_ATTR_RO(in0_alarm, alarm, 0); |
| 855 | static SENSOR_DEVICE_ATTR_RO(in1_alarm, alarm, 1); |
| 856 | static SENSOR_DEVICE_ATTR_RO(in2_alarm, alarm, 2); |
| 857 | static SENSOR_DEVICE_ATTR_RO(in3_alarm, alarm, 3); |
| 858 | static SENSOR_DEVICE_ATTR_RO(in4_alarm, alarm, 8); |
| 859 | static SENSOR_DEVICE_ATTR_RO(in5_alarm, alarm, 9); |
| 860 | static SENSOR_DEVICE_ATTR_RO(in6_alarm, alarm, 10); |
| 861 | static SENSOR_DEVICE_ATTR_RO(in7_alarm, alarm, 16); |
| 862 | static SENSOR_DEVICE_ATTR_RO(in8_alarm, alarm, 17); |
| 863 | static SENSOR_DEVICE_ATTR_RO(fan1_alarm, alarm, 6); |
| 864 | static SENSOR_DEVICE_ATTR_RO(fan2_alarm, alarm, 7); |
| 865 | static SENSOR_DEVICE_ATTR_RO(fan3_alarm, alarm, 11); |
| 866 | static SENSOR_DEVICE_ATTR_RO(temp1_alarm, alarm, 4); |
| 867 | static SENSOR_DEVICE_ATTR_RO(temp2_alarm, alarm, 5); |
| 868 | static SENSOR_DEVICE_ATTR_RO(temp3_alarm, alarm, 13); |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 869 | |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 870 | static ssize_t |
Julia Lawall | 8dfcdfc | 2016-12-22 13:05:11 +0100 | [diff] [blame] | 871 | beep_mask_show(struct device *dev, struct device_attribute *attr, char *buf) |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 872 | { |
| 873 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 874 | return sprintf(buf, "%ld\n", |
| 875 | (long)BEEP_MASK_FROM_REG(data->beep_mask)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 877 | |
| 878 | static ssize_t |
Julia Lawall | 8dfcdfc | 2016-12-22 13:05:11 +0100 | [diff] [blame] | 879 | beep_mask_store(struct device *dev, struct device_attribute *attr, |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 880 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 881 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 882 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 883 | unsigned long val; |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 884 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 886 | err = kstrtoul(buf, 10, &val); |
| 887 | if (err) |
| 888 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 890 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 892 | /* preserve beep enable */ |
| 893 | data->beep_mask = (data->beep_mask & 0x8000) |
| 894 | | BEEP_MASK_TO_REG(val); |
| 895 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS1, |
| 896 | data->beep_mask & 0xff); |
| 897 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS3, |
| 898 | ((data->beep_mask) >> 16) & 0xff); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 899 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS2, |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 900 | (data->beep_mask >> 8) & 0xff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 902 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | return count; |
| 904 | } |
| 905 | |
Julia Lawall | 8dfcdfc | 2016-12-22 13:05:11 +0100 | [diff] [blame] | 906 | static DEVICE_ATTR_RW(beep_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 909 | beep_show(struct device *dev, struct device_attribute *attr, char *buf) |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 910 | { |
| 911 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 912 | int bitnr = to_sensor_dev_attr(attr)->index; |
| 913 | return sprintf(buf, "%u\n", (data->beep_mask >> bitnr) & 1); |
| 914 | } |
| 915 | |
| 916 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 917 | beep_store(struct device *dev, struct device_attribute *attr, const char *buf, |
| 918 | size_t count) |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 919 | { |
| 920 | struct w83627hf_data *data = dev_get_drvdata(dev); |
| 921 | int bitnr = to_sensor_dev_attr(attr)->index; |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 922 | u8 reg; |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 923 | unsigned long bit; |
| 924 | int err; |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 925 | |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 926 | err = kstrtoul(buf, 10, &bit); |
| 927 | if (err) |
| 928 | return err; |
| 929 | |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 930 | if (bit & ~1) |
| 931 | return -EINVAL; |
| 932 | |
| 933 | mutex_lock(&data->update_lock); |
| 934 | if (bit) |
| 935 | data->beep_mask |= (1 << bitnr); |
| 936 | else |
| 937 | data->beep_mask &= ~(1 << bitnr); |
| 938 | |
| 939 | if (bitnr < 8) { |
| 940 | reg = w83627hf_read_value(data, W83781D_REG_BEEP_INTS1); |
| 941 | if (bit) |
| 942 | reg |= (1 << bitnr); |
| 943 | else |
| 944 | reg &= ~(1 << bitnr); |
| 945 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS1, reg); |
| 946 | } else if (bitnr < 16) { |
| 947 | reg = w83627hf_read_value(data, W83781D_REG_BEEP_INTS2); |
| 948 | if (bit) |
| 949 | reg |= (1 << (bitnr - 8)); |
| 950 | else |
| 951 | reg &= ~(1 << (bitnr - 8)); |
| 952 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS2, reg); |
| 953 | } else { |
| 954 | reg = w83627hf_read_value(data, W83781D_REG_BEEP_INTS3); |
| 955 | if (bit) |
| 956 | reg |= (1 << (bitnr - 16)); |
| 957 | else |
| 958 | reg &= ~(1 << (bitnr - 16)); |
| 959 | w83627hf_write_value(data, W83781D_REG_BEEP_INTS3, reg); |
| 960 | } |
| 961 | mutex_unlock(&data->update_lock); |
| 962 | |
| 963 | return count; |
| 964 | } |
| 965 | |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 966 | static SENSOR_DEVICE_ATTR_RW(in0_beep, beep, 0); |
| 967 | static SENSOR_DEVICE_ATTR_RW(in1_beep, beep, 1); |
| 968 | static SENSOR_DEVICE_ATTR_RW(in2_beep, beep, 2); |
| 969 | static SENSOR_DEVICE_ATTR_RW(in3_beep, beep, 3); |
| 970 | static SENSOR_DEVICE_ATTR_RW(in4_beep, beep, 8); |
| 971 | static SENSOR_DEVICE_ATTR_RW(in5_beep, beep, 9); |
| 972 | static SENSOR_DEVICE_ATTR_RW(in6_beep, beep, 10); |
| 973 | static SENSOR_DEVICE_ATTR_RW(in7_beep, beep, 16); |
| 974 | static SENSOR_DEVICE_ATTR_RW(in8_beep, beep, 17); |
| 975 | static SENSOR_DEVICE_ATTR_RW(fan1_beep, beep, 6); |
| 976 | static SENSOR_DEVICE_ATTR_RW(fan2_beep, beep, 7); |
| 977 | static SENSOR_DEVICE_ATTR_RW(fan3_beep, beep, 11); |
| 978 | static SENSOR_DEVICE_ATTR_RW(temp1_beep, beep, 4); |
| 979 | static SENSOR_DEVICE_ATTR_RW(temp2_beep, beep, 5); |
| 980 | static SENSOR_DEVICE_ATTR_RW(temp3_beep, beep, 13); |
| 981 | static SENSOR_DEVICE_ATTR_RW(beep_enable, beep, 15); |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 982 | |
| 983 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 984 | fan_div_show(struct device *dev, struct device_attribute *devattr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 985 | { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 986 | int nr = to_sensor_dev_attr(devattr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 988 | return sprintf(buf, "%ld\n", |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 989 | (long) DIV_FROM_REG(data->fan_div[nr])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 990 | } |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 991 | /* |
| 992 | * Note: we save and restore the fan minimum here, because its value is |
| 993 | * determined in part by the fan divisor. This follows the principle of |
| 994 | * least surprise; the user doesn't expect the fan minimum to change just |
| 995 | * because the divisor changed. |
| 996 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 998 | fan_div_store(struct device *dev, struct device_attribute *devattr, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 999 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1001 | int nr = to_sensor_dev_attr(devattr)->index; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1002 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | unsigned long min; |
| 1004 | u8 reg; |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 1005 | unsigned long val; |
| 1006 | int err; |
| 1007 | |
| 1008 | err = kstrtoul(buf, 10, &val); |
| 1009 | if (err) |
| 1010 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1012 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | |
| 1014 | /* Save fan_min */ |
| 1015 | min = FAN_FROM_REG(data->fan_min[nr], |
| 1016 | DIV_FROM_REG(data->fan_div[nr])); |
| 1017 | |
| 1018 | data->fan_div[nr] = DIV_TO_REG(val); |
| 1019 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1020 | 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] | 1021 | & (nr==0 ? 0xcf : 0x3f)) |
| 1022 | | ((data->fan_div[nr] & 0x03) << (nr==0 ? 4 : 6)); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1023 | 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] | 1024 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1025 | reg = (w83627hf_read_value(data, W83781D_REG_VBAT) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1026 | & ~(1 << (5 + nr))) |
| 1027 | | ((data->fan_div[nr] & 0x04) << (3 + nr)); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1028 | w83627hf_write_value(data, W83781D_REG_VBAT, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1029 | |
| 1030 | /* Restore fan_min */ |
| 1031 | 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] | 1032 | 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] | 1033 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1034 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1035 | return count; |
| 1036 | } |
| 1037 | |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 1038 | static SENSOR_DEVICE_ATTR_RW(fan1_div, fan_div, 0); |
| 1039 | static SENSOR_DEVICE_ATTR_RW(fan2_div, fan_div, 1); |
| 1040 | static SENSOR_DEVICE_ATTR_RW(fan3_div, fan_div, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1042 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 1043 | pwm_show(struct device *dev, struct device_attribute *devattr, char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1045 | int nr = to_sensor_dev_attr(devattr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | struct w83627hf_data *data = w83627hf_update_device(dev); |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1047 | return sprintf(buf, "%ld\n", (long) data->pwm[nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 1051 | pwm_store(struct device *dev, struct device_attribute *devattr, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1052 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1053 | { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1054 | int nr = to_sensor_dev_attr(devattr)->index; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1055 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 1056 | unsigned long val; |
| 1057 | int err; |
| 1058 | |
| 1059 | err = kstrtoul(buf, 10, &val); |
| 1060 | if (err) |
| 1061 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1063 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | |
| 1065 | if (data->type == w83627thf) { |
| 1066 | /* bits 0-3 are reserved in 627THF */ |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1067 | data->pwm[nr] = PWM_TO_REG(val) & 0xf0; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1068 | w83627hf_write_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1069 | W836X7HF_REG_PWM(data->type, nr), |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1070 | data->pwm[nr] | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1071 | (w83627hf_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1072 | W836X7HF_REG_PWM(data->type, nr)) & 0x0f)); |
| 1073 | } else { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1074 | data->pwm[nr] = PWM_TO_REG(val); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1075 | w83627hf_write_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | W836X7HF_REG_PWM(data->type, nr), |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1077 | data->pwm[nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1080 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | return count; |
| 1082 | } |
| 1083 | |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 1084 | static SENSOR_DEVICE_ATTR_RW(pwm1, pwm, 0); |
| 1085 | static SENSOR_DEVICE_ATTR_RW(pwm2, pwm, 1); |
| 1086 | static SENSOR_DEVICE_ATTR_RW(pwm3, pwm, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 1089 | pwm_enable_show(struct device *dev, struct device_attribute *devattr, |
| 1090 | char *buf) |
Dominik Geyer | a95a5ed | 2008-08-06 22:41:04 +0200 | [diff] [blame] | 1091 | { |
| 1092 | int nr = to_sensor_dev_attr(devattr)->index; |
| 1093 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 1094 | return sprintf(buf, "%d\n", data->pwm_enable[nr]); |
| 1095 | } |
| 1096 | |
| 1097 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 1098 | pwm_enable_store(struct device *dev, struct device_attribute *devattr, |
| 1099 | const char *buf, size_t count) |
Dominik Geyer | a95a5ed | 2008-08-06 22:41:04 +0200 | [diff] [blame] | 1100 | { |
| 1101 | int nr = to_sensor_dev_attr(devattr)->index; |
| 1102 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Dominik Geyer | a95a5ed | 2008-08-06 22:41:04 +0200 | [diff] [blame] | 1103 | u8 reg; |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 1104 | unsigned long val; |
| 1105 | int err; |
Dominik Geyer | a95a5ed | 2008-08-06 22:41:04 +0200 | [diff] [blame] | 1106 | |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 1107 | err = kstrtoul(buf, 10, &val); |
| 1108 | if (err) |
| 1109 | return err; |
| 1110 | |
| 1111 | if (!val || val > 3) /* modes 1, 2 and 3 are supported */ |
Dominik Geyer | a95a5ed | 2008-08-06 22:41:04 +0200 | [diff] [blame] | 1112 | return -EINVAL; |
| 1113 | mutex_lock(&data->update_lock); |
| 1114 | data->pwm_enable[nr] = val; |
| 1115 | reg = w83627hf_read_value(data, W83627THF_REG_PWM_ENABLE[nr]); |
| 1116 | reg &= ~(0x03 << W83627THF_PWM_ENABLE_SHIFT[nr]); |
| 1117 | reg |= (val - 1) << W83627THF_PWM_ENABLE_SHIFT[nr]; |
| 1118 | w83627hf_write_value(data, W83627THF_REG_PWM_ENABLE[nr], reg); |
| 1119 | mutex_unlock(&data->update_lock); |
| 1120 | return count; |
| 1121 | } |
| 1122 | |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 1123 | static SENSOR_DEVICE_ATTR_RW(pwm1_enable, pwm_enable, 0); |
| 1124 | static SENSOR_DEVICE_ATTR_RW(pwm2_enable, pwm_enable, 1); |
| 1125 | static SENSOR_DEVICE_ATTR_RW(pwm3_enable, pwm_enable, 2); |
Dominik Geyer | a95a5ed | 2008-08-06 22:41:04 +0200 | [diff] [blame] | 1126 | |
| 1127 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 1128 | pwm_freq_show(struct device *dev, struct device_attribute *devattr, char *buf) |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1129 | { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1130 | int nr = to_sensor_dev_attr(devattr)->index; |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1131 | struct w83627hf_data *data = w83627hf_update_device(dev); |
| 1132 | if (data->type == w83627hf) |
| 1133 | return sprintf(buf, "%ld\n", |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1134 | pwm_freq_from_reg_627hf(data->pwm_freq[nr])); |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1135 | else |
| 1136 | return sprintf(buf, "%ld\n", |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1137 | pwm_freq_from_reg(data->pwm_freq[nr])); |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1138 | } |
| 1139 | |
| 1140 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 1141 | pwm_freq_store(struct device *dev, struct device_attribute *devattr, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1142 | const char *buf, size_t count) |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1143 | { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1144 | int nr = to_sensor_dev_attr(devattr)->index; |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1145 | struct w83627hf_data *data = dev_get_drvdata(dev); |
| 1146 | static const u8 mask[]={0xF8, 0x8F}; |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 1147 | unsigned long val; |
| 1148 | int err; |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1149 | |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 1150 | err = kstrtoul(buf, 10, &val); |
| 1151 | if (err) |
| 1152 | return err; |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1153 | |
| 1154 | mutex_lock(&data->update_lock); |
| 1155 | |
| 1156 | if (data->type == w83627hf) { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1157 | data->pwm_freq[nr] = pwm_freq_to_reg_627hf(val); |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1158 | w83627hf_write_value(data, W83627HF_REG_PWM_FREQ, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1159 | (data->pwm_freq[nr] << (nr*4)) | |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1160 | (w83627hf_read_value(data, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1161 | W83627HF_REG_PWM_FREQ) & mask[nr])); |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1162 | } else { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1163 | data->pwm_freq[nr] = pwm_freq_to_reg(val); |
| 1164 | w83627hf_write_value(data, W83637HF_REG_PWM_FREQ[nr], |
| 1165 | data->pwm_freq[nr]); |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1166 | } |
| 1167 | |
| 1168 | mutex_unlock(&data->update_lock); |
| 1169 | return count; |
| 1170 | } |
| 1171 | |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 1172 | static SENSOR_DEVICE_ATTR_RW(pwm1_freq, pwm_freq, 0); |
| 1173 | static SENSOR_DEVICE_ATTR_RW(pwm2_freq, pwm_freq, 1); |
| 1174 | static SENSOR_DEVICE_ATTR_RW(pwm3_freq, pwm_freq, 2); |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1175 | |
| 1176 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 1177 | temp_type_show(struct device *dev, struct device_attribute *devattr, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1178 | char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1180 | int nr = to_sensor_dev_attr(devattr)->index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | struct w83627hf_data *data = w83627hf_update_device(dev); |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1182 | return sprintf(buf, "%ld\n", (long) data->sens[nr]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | static ssize_t |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 1186 | temp_type_store(struct device *dev, struct device_attribute *devattr, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1187 | const char *buf, size_t count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1189 | int nr = to_sensor_dev_attr(devattr)->index; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1190 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 1191 | unsigned long val; |
| 1192 | u32 tmp; |
| 1193 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 1195 | err = kstrtoul(buf, 10, &val); |
| 1196 | if (err) |
| 1197 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1198 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1199 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | |
| 1201 | switch (val) { |
| 1202 | case 1: /* PII/Celeron diode */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1203 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); |
| 1204 | w83627hf_write_value(data, W83781D_REG_SCFG1, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1205 | tmp | BIT_SCFG1[nr]); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1206 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG2); |
| 1207 | w83627hf_write_value(data, W83781D_REG_SCFG2, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1208 | tmp | BIT_SCFG2[nr]); |
| 1209 | data->sens[nr] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1210 | break; |
| 1211 | case 2: /* 3904 */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1212 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); |
| 1213 | w83627hf_write_value(data, W83781D_REG_SCFG1, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1214 | tmp | BIT_SCFG1[nr]); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1215 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG2); |
| 1216 | w83627hf_write_value(data, W83781D_REG_SCFG2, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1217 | tmp & ~BIT_SCFG2[nr]); |
| 1218 | data->sens[nr] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | break; |
Jean Delvare | b26f933 | 2007-08-16 14:30:01 +0200 | [diff] [blame] | 1220 | case W83781D_DEFAULT_BETA: |
| 1221 | dev_warn(dev, "Sensor type %d is deprecated, please use 4 " |
| 1222 | "instead\n", W83781D_DEFAULT_BETA); |
| 1223 | /* fall through */ |
| 1224 | case 4: /* thermistor */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1225 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); |
| 1226 | w83627hf_write_value(data, W83781D_REG_SCFG1, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1227 | tmp & ~BIT_SCFG1[nr]); |
| 1228 | data->sens[nr] = val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | break; |
| 1230 | default: |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1231 | dev_err(dev, |
Jean Delvare | b26f933 | 2007-08-16 14:30:01 +0200 | [diff] [blame] | 1232 | "Invalid sensor type %ld; must be 1, 2, or 4\n", |
| 1233 | (long) val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | break; |
| 1235 | } |
| 1236 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1237 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | return count; |
| 1239 | } |
| 1240 | |
Guenter Roeck | 502a92f | 2019-01-22 15:25:47 -0800 | [diff] [blame] | 1241 | static SENSOR_DEVICE_ATTR_RW(temp1_type, temp_type, 0); |
| 1242 | static SENSOR_DEVICE_ATTR_RW(temp2_type, temp_type, 1); |
| 1243 | static SENSOR_DEVICE_ATTR_RW(temp3_type, temp_type, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1245 | static ssize_t |
Julia Lawall | 8dfcdfc | 2016-12-22 13:05:11 +0100 | [diff] [blame] | 1246 | name_show(struct device *dev, struct device_attribute *devattr, char *buf) |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1247 | { |
| 1248 | struct w83627hf_data *data = dev_get_drvdata(dev); |
| 1249 | |
| 1250 | return sprintf(buf, "%s\n", data->name); |
| 1251 | } |
Julia Lawall | 8dfcdfc | 2016-12-22 13:05:11 +0100 | [diff] [blame] | 1252 | static DEVICE_ATTR_RO(name); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1253 | |
| 1254 | static int __init w83627hf_find(int sioaddr, unsigned short *addr, |
| 1255 | struct w83627hf_sio_data *sio_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | { |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1257 | int err = -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1258 | u16 val; |
| 1259 | |
Andi Kleen | 64f5030 | 2012-08-18 10:30:05 -0700 | [diff] [blame] | 1260 | static __initconst char *const names[] = { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1261 | "W83627HF", |
| 1262 | "W83627THF", |
| 1263 | "W83697HF", |
| 1264 | "W83637HF", |
| 1265 | "W83687THF", |
| 1266 | }; |
| 1267 | |
Christian Schulte | c46c0e9 | 2009-12-16 21:38:29 +0100 | [diff] [blame] | 1268 | sio_data->sioaddr = sioaddr; |
Jean Delvare | b72656d | 2009-12-09 20:35:49 +0100 | [diff] [blame] | 1269 | superio_enter(sio_data); |
| 1270 | val = force_id ? force_id : superio_inb(sio_data, DEVID); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1271 | switch (val) { |
| 1272 | case W627_DEVID: |
| 1273 | sio_data->type = w83627hf; |
| 1274 | break; |
| 1275 | case W627THF_DEVID: |
| 1276 | sio_data->type = w83627thf; |
| 1277 | break; |
| 1278 | case W697_DEVID: |
| 1279 | sio_data->type = w83697hf; |
| 1280 | break; |
| 1281 | case W637_DEVID: |
| 1282 | sio_data->type = w83637hf; |
| 1283 | break; |
| 1284 | case W687THF_DEVID: |
| 1285 | sio_data->type = w83687thf; |
| 1286 | break; |
Jean Delvare | e142e2a | 2007-05-27 22:17:43 +0200 | [diff] [blame] | 1287 | case 0xff: /* No device at all */ |
| 1288 | goto exit; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1289 | default: |
Jean Delvare | e142e2a | 2007-05-27 22:17:43 +0200 | [diff] [blame] | 1290 | pr_debug(DRVNAME ": Unsupported chip (DEVID=0x%02x)\n", val); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1291 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1292 | } |
| 1293 | |
Jean Delvare | b72656d | 2009-12-09 20:35:49 +0100 | [diff] [blame] | 1294 | superio_select(sio_data, W83627HF_LD_HWM); |
| 1295 | val = (superio_inb(sio_data, WINB_BASE_REG) << 8) | |
| 1296 | superio_inb(sio_data, WINB_BASE_REG + 1); |
Petr Vandrovec | ada0c2f | 2005-10-07 23:11:03 +0200 | [diff] [blame] | 1297 | *addr = val & WINB_ALIGNMENT; |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1298 | if (*addr == 0) { |
Joe Perches | 18de030 | 2010-10-20 06:51:55 +0000 | [diff] [blame] | 1299 | pr_warn("Base address not set, skipping\n"); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1300 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | |
Jean Delvare | b72656d | 2009-12-09 20:35:49 +0100 | [diff] [blame] | 1303 | val = superio_inb(sio_data, WINB_ACT_REG); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1304 | if (!(val & 0x01)) { |
Joe Perches | 18de030 | 2010-10-20 06:51:55 +0000 | [diff] [blame] | 1305 | pr_warn("Enabling HWM logical device\n"); |
Jean Delvare | b72656d | 2009-12-09 20:35:49 +0100 | [diff] [blame] | 1306 | superio_outb(sio_data, WINB_ACT_REG, val | 0x01); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1307 | } |
| 1308 | |
| 1309 | err = 0; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1310 | pr_info(DRVNAME ": Found %s chip at %#x\n", |
| 1311 | names[sio_data->type], *addr); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1312 | |
| 1313 | exit: |
Jean Delvare | b72656d | 2009-12-09 20:35:49 +0100 | [diff] [blame] | 1314 | superio_exit(sio_data); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1315 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | } |
| 1317 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1318 | #define VIN_UNIT_ATTRS(_X_) \ |
| 1319 | &sensor_dev_attr_in##_X_##_input.dev_attr.attr, \ |
| 1320 | &sensor_dev_attr_in##_X_##_min.dev_attr.attr, \ |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 1321 | &sensor_dev_attr_in##_X_##_max.dev_attr.attr, \ |
| 1322 | &sensor_dev_attr_in##_X_##_alarm.dev_attr.attr, \ |
| 1323 | &sensor_dev_attr_in##_X_##_beep.dev_attr.attr |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1324 | |
| 1325 | #define FAN_UNIT_ATTRS(_X_) \ |
| 1326 | &sensor_dev_attr_fan##_X_##_input.dev_attr.attr, \ |
| 1327 | &sensor_dev_attr_fan##_X_##_min.dev_attr.attr, \ |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 1328 | &sensor_dev_attr_fan##_X_##_div.dev_attr.attr, \ |
| 1329 | &sensor_dev_attr_fan##_X_##_alarm.dev_attr.attr, \ |
| 1330 | &sensor_dev_attr_fan##_X_##_beep.dev_attr.attr |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1331 | |
| 1332 | #define TEMP_UNIT_ATTRS(_X_) \ |
| 1333 | &sensor_dev_attr_temp##_X_##_input.dev_attr.attr, \ |
| 1334 | &sensor_dev_attr_temp##_X_##_max.dev_attr.attr, \ |
| 1335 | &sensor_dev_attr_temp##_X_##_max_hyst.dev_attr.attr, \ |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 1336 | &sensor_dev_attr_temp##_X_##_type.dev_attr.attr, \ |
| 1337 | &sensor_dev_attr_temp##_X_##_alarm.dev_attr.attr, \ |
| 1338 | &sensor_dev_attr_temp##_X_##_beep.dev_attr.attr |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1339 | |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1340 | static struct attribute *w83627hf_attributes[] = { |
| 1341 | &dev_attr_in0_input.attr, |
| 1342 | &dev_attr_in0_min.attr, |
| 1343 | &dev_attr_in0_max.attr, |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 1344 | &sensor_dev_attr_in0_alarm.dev_attr.attr, |
| 1345 | &sensor_dev_attr_in0_beep.dev_attr.attr, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1346 | VIN_UNIT_ATTRS(2), |
| 1347 | VIN_UNIT_ATTRS(3), |
| 1348 | VIN_UNIT_ATTRS(4), |
| 1349 | VIN_UNIT_ATTRS(7), |
| 1350 | VIN_UNIT_ATTRS(8), |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1351 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1352 | FAN_UNIT_ATTRS(1), |
| 1353 | FAN_UNIT_ATTRS(2), |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1354 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1355 | TEMP_UNIT_ATTRS(1), |
| 1356 | TEMP_UNIT_ATTRS(2), |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1357 | |
| 1358 | &dev_attr_alarms.attr, |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 1359 | &sensor_dev_attr_beep_enable.dev_attr.attr, |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1360 | &dev_attr_beep_mask.attr, |
| 1361 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1362 | &sensor_dev_attr_pwm1.dev_attr.attr, |
| 1363 | &sensor_dev_attr_pwm2.dev_attr.attr, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1364 | &dev_attr_name.attr, |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1365 | NULL |
| 1366 | }; |
| 1367 | |
| 1368 | static const struct attribute_group w83627hf_group = { |
| 1369 | .attrs = w83627hf_attributes, |
| 1370 | }; |
| 1371 | |
| 1372 | static struct attribute *w83627hf_attributes_opt[] = { |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1373 | VIN_UNIT_ATTRS(1), |
| 1374 | VIN_UNIT_ATTRS(5), |
| 1375 | VIN_UNIT_ATTRS(6), |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1376 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1377 | FAN_UNIT_ATTRS(3), |
| 1378 | TEMP_UNIT_ATTRS(3), |
| 1379 | &sensor_dev_attr_pwm3.dev_attr.attr, |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1380 | |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1381 | &sensor_dev_attr_pwm1_freq.dev_attr.attr, |
| 1382 | &sensor_dev_attr_pwm2_freq.dev_attr.attr, |
| 1383 | &sensor_dev_attr_pwm3_freq.dev_attr.attr, |
Dominik Geyer | a95a5ed | 2008-08-06 22:41:04 +0200 | [diff] [blame] | 1384 | |
| 1385 | &sensor_dev_attr_pwm1_enable.dev_attr.attr, |
| 1386 | &sensor_dev_attr_pwm2_enable.dev_attr.attr, |
| 1387 | &sensor_dev_attr_pwm3_enable.dev_attr.attr, |
| 1388 | |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1389 | NULL |
| 1390 | }; |
| 1391 | |
| 1392 | static const struct attribute_group w83627hf_group_opt = { |
| 1393 | .attrs = w83627hf_attributes_opt, |
| 1394 | }; |
| 1395 | |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 1396 | static int w83627hf_probe(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1397 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1398 | struct device *dev = &pdev->dev; |
Jingoo Han | a8b3a3a | 2013-07-30 17:13:06 +0900 | [diff] [blame] | 1399 | struct w83627hf_sio_data *sio_data = dev_get_platdata(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | struct w83627hf_data *data; |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1401 | struct resource *res; |
Jim Cromie | 2ca2fcd | 2007-10-14 17:20:50 -0600 | [diff] [blame] | 1402 | int err, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1404 | static const char *names[] = { |
| 1405 | "w83627hf", |
| 1406 | "w83627thf", |
| 1407 | "w83697hf", |
| 1408 | "w83637hf", |
| 1409 | "w83687thf", |
| 1410 | }; |
| 1411 | |
| 1412 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
Guenter Roeck | 0cf4699 | 2012-06-02 11:47:59 -0700 | [diff] [blame] | 1413 | if (!devm_request_region(dev, res->start, WINB_REGION_SIZE, DRVNAME)) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1414 | dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", |
| 1415 | (unsigned long)res->start, |
| 1416 | (unsigned long)(res->start + WINB_REGION_SIZE - 1)); |
Guenter Roeck | 0cf4699 | 2012-06-02 11:47:59 -0700 | [diff] [blame] | 1417 | return -EBUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1418 | } |
| 1419 | |
Guenter Roeck | 0cf4699 | 2012-06-02 11:47:59 -0700 | [diff] [blame] | 1420 | data = devm_kzalloc(dev, sizeof(struct w83627hf_data), GFP_KERNEL); |
| 1421 | if (!data) |
| 1422 | return -ENOMEM; |
| 1423 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1424 | data->addr = res->start; |
| 1425 | data->type = sio_data->type; |
| 1426 | data->name = names[sio_data->type]; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1427 | mutex_init(&data->lock); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1428 | mutex_init(&data->update_lock); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1429 | platform_set_drvdata(pdev, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | /* Initialize the chip */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1432 | w83627hf_init_device(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | |
| 1434 | /* A few vars need to be filled upon startup */ |
Jim Cromie | 2ca2fcd | 2007-10-14 17:20:50 -0600 | [diff] [blame] | 1435 | for (i = 0; i <= 2; i++) |
| 1436 | data->fan_min[i] = w83627hf_read_value( |
| 1437 | data, W83627HF_REG_FAN_MIN(i)); |
Jean Delvare | c09c518 | 2007-10-12 21:53:07 +0200 | [diff] [blame] | 1438 | w83627hf_update_fan_div(data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1439 | |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1440 | /* Register common device attributes */ |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 1441 | err = sysfs_create_group(&dev->kobj, &w83627hf_group); |
| 1442 | if (err) |
Guenter Roeck | 0cf4699 | 2012-06-02 11:47:59 -0700 | [diff] [blame] | 1443 | return err; |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1444 | |
| 1445 | /* Register chip-specific device attributes */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1446 | if (data->type == w83627hf || data->type == w83697hf) |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1447 | if ((err = device_create_file(dev, |
| 1448 | &sensor_dev_attr_in5_input.dev_attr)) |
| 1449 | || (err = device_create_file(dev, |
| 1450 | &sensor_dev_attr_in5_min.dev_attr)) |
| 1451 | || (err = device_create_file(dev, |
| 1452 | &sensor_dev_attr_in5_max.dev_attr)) |
| 1453 | || (err = device_create_file(dev, |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 1454 | &sensor_dev_attr_in5_alarm.dev_attr)) |
| 1455 | || (err = device_create_file(dev, |
| 1456 | &sensor_dev_attr_in5_beep.dev_attr)) |
| 1457 | || (err = device_create_file(dev, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1458 | &sensor_dev_attr_in6_input.dev_attr)) |
| 1459 | || (err = device_create_file(dev, |
| 1460 | &sensor_dev_attr_in6_min.dev_attr)) |
| 1461 | || (err = device_create_file(dev, |
| 1462 | &sensor_dev_attr_in6_max.dev_attr)) |
| 1463 | || (err = device_create_file(dev, |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 1464 | &sensor_dev_attr_in6_alarm.dev_attr)) |
| 1465 | || (err = device_create_file(dev, |
| 1466 | &sensor_dev_attr_in6_beep.dev_attr)) |
| 1467 | || (err = device_create_file(dev, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1468 | &sensor_dev_attr_pwm1_freq.dev_attr)) |
| 1469 | || (err = device_create_file(dev, |
| 1470 | &sensor_dev_attr_pwm2_freq.dev_attr))) |
Guenter Roeck | 0cf4699 | 2012-06-02 11:47:59 -0700 | [diff] [blame] | 1471 | goto error; |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1472 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1473 | if (data->type != w83697hf) |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1474 | if ((err = device_create_file(dev, |
| 1475 | &sensor_dev_attr_in1_input.dev_attr)) |
| 1476 | || (err = device_create_file(dev, |
| 1477 | &sensor_dev_attr_in1_min.dev_attr)) |
| 1478 | || (err = device_create_file(dev, |
| 1479 | &sensor_dev_attr_in1_max.dev_attr)) |
| 1480 | || (err = device_create_file(dev, |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 1481 | &sensor_dev_attr_in1_alarm.dev_attr)) |
| 1482 | || (err = device_create_file(dev, |
| 1483 | &sensor_dev_attr_in1_beep.dev_attr)) |
| 1484 | || (err = device_create_file(dev, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1485 | &sensor_dev_attr_fan3_input.dev_attr)) |
| 1486 | || (err = device_create_file(dev, |
| 1487 | &sensor_dev_attr_fan3_min.dev_attr)) |
| 1488 | || (err = device_create_file(dev, |
| 1489 | &sensor_dev_attr_fan3_div.dev_attr)) |
| 1490 | || (err = device_create_file(dev, |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 1491 | &sensor_dev_attr_fan3_alarm.dev_attr)) |
| 1492 | || (err = device_create_file(dev, |
| 1493 | &sensor_dev_attr_fan3_beep.dev_attr)) |
| 1494 | || (err = device_create_file(dev, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1495 | &sensor_dev_attr_temp3_input.dev_attr)) |
| 1496 | || (err = device_create_file(dev, |
| 1497 | &sensor_dev_attr_temp3_max.dev_attr)) |
| 1498 | || (err = device_create_file(dev, |
| 1499 | &sensor_dev_attr_temp3_max_hyst.dev_attr)) |
| 1500 | || (err = device_create_file(dev, |
Jean Delvare | e3604c6 | 2008-01-03 23:00:30 +0100 | [diff] [blame] | 1501 | &sensor_dev_attr_temp3_alarm.dev_attr)) |
| 1502 | || (err = device_create_file(dev, |
| 1503 | &sensor_dev_attr_temp3_beep.dev_attr)) |
| 1504 | || (err = device_create_file(dev, |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1505 | &sensor_dev_attr_temp3_type.dev_attr))) |
Guenter Roeck | 0cf4699 | 2012-06-02 11:47:59 -0700 | [diff] [blame] | 1506 | goto error; |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1507 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1508 | if (data->type != w83697hf && data->vid != 0xff) { |
Jean Delvare | 8a665a0 | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1509 | /* Convert VID to voltage based on VRM */ |
| 1510 | data->vrm = vid_which_vrm(); |
| 1511 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1512 | if ((err = device_create_file(dev, &dev_attr_cpu0_vid)) |
| 1513 | || (err = device_create_file(dev, &dev_attr_vrm))) |
Guenter Roeck | 0cf4699 | 2012-06-02 11:47:59 -0700 | [diff] [blame] | 1514 | goto error; |
Jean Delvare | 8a665a0 | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1515 | } |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1516 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1517 | if (data->type == w83627thf || data->type == w83637hf |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 1518 | || data->type == w83687thf) { |
| 1519 | err = device_create_file(dev, &sensor_dev_attr_pwm3.dev_attr); |
| 1520 | if (err) |
Guenter Roeck | 0cf4699 | 2012-06-02 11:47:59 -0700 | [diff] [blame] | 1521 | goto error; |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 1522 | } |
Mark M. Hoffman | c1685f6 | 2006-09-24 20:59:49 +0200 | [diff] [blame] | 1523 | |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1524 | if (data->type == w83637hf || data->type == w83687thf) |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1525 | if ((err = device_create_file(dev, |
| 1526 | &sensor_dev_attr_pwm1_freq.dev_attr)) |
| 1527 | || (err = device_create_file(dev, |
| 1528 | &sensor_dev_attr_pwm2_freq.dev_attr)) |
| 1529 | || (err = device_create_file(dev, |
| 1530 | &sensor_dev_attr_pwm3_freq.dev_attr))) |
Guenter Roeck | 0cf4699 | 2012-06-02 11:47:59 -0700 | [diff] [blame] | 1531 | goto error; |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1532 | |
Dominik Geyer | a95a5ed | 2008-08-06 22:41:04 +0200 | [diff] [blame] | 1533 | if (data->type != w83627hf) |
| 1534 | if ((err = device_create_file(dev, |
| 1535 | &sensor_dev_attr_pwm1_enable.dev_attr)) |
| 1536 | || (err = device_create_file(dev, |
| 1537 | &sensor_dev_attr_pwm2_enable.dev_attr))) |
Guenter Roeck | 0cf4699 | 2012-06-02 11:47:59 -0700 | [diff] [blame] | 1538 | goto error; |
Dominik Geyer | a95a5ed | 2008-08-06 22:41:04 +0200 | [diff] [blame] | 1539 | |
| 1540 | if (data->type == w83627thf || data->type == w83637hf |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 1541 | || data->type == w83687thf) { |
| 1542 | err = device_create_file(dev, |
| 1543 | &sensor_dev_attr_pwm3_enable.dev_attr); |
| 1544 | if (err) |
Guenter Roeck | 0cf4699 | 2012-06-02 11:47:59 -0700 | [diff] [blame] | 1545 | goto error; |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 1546 | } |
Dominik Geyer | a95a5ed | 2008-08-06 22:41:04 +0200 | [diff] [blame] | 1547 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1548 | data->hwmon_dev = hwmon_device_register(dev); |
| 1549 | if (IS_ERR(data->hwmon_dev)) { |
| 1550 | err = PTR_ERR(data->hwmon_dev); |
Guenter Roeck | 0cf4699 | 2012-06-02 11:47:59 -0700 | [diff] [blame] | 1551 | goto error; |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1552 | } |
| 1553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | return 0; |
| 1555 | |
Guenter Roeck | 0cf4699 | 2012-06-02 11:47:59 -0700 | [diff] [blame] | 1556 | error: |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1557 | sysfs_remove_group(&dev->kobj, &w83627hf_group); |
| 1558 | sysfs_remove_group(&dev->kobj, &w83627hf_group_opt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | return err; |
| 1560 | } |
| 1561 | |
Bill Pemberton | 281dfd0 | 2012-11-19 13:25:51 -0500 | [diff] [blame] | 1562 | static int w83627hf_remove(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1564 | struct w83627hf_data *data = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1566 | hwmon_device_unregister(data->hwmon_dev); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1567 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1568 | sysfs_remove_group(&pdev->dev.kobj, &w83627hf_group); |
| 1569 | sysfs_remove_group(&pdev->dev.kobj, &w83627hf_group_opt); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1571 | return 0; |
| 1572 | } |
| 1573 | |
Jean Delvare | d58df9c | 2007-10-10 16:30:23 +0200 | [diff] [blame] | 1574 | /* Registers 0x50-0x5f are banked */ |
| 1575 | static inline void w83627hf_set_bank(struct w83627hf_data *data, u16 reg) |
| 1576 | { |
| 1577 | if ((reg & 0x00f0) == 0x50) { |
| 1578 | outb_p(W83781D_REG_BANK, data->addr + W83781D_ADDR_REG_OFFSET); |
| 1579 | outb_p(reg >> 8, data->addr + W83781D_DATA_REG_OFFSET); |
| 1580 | } |
| 1581 | } |
| 1582 | |
| 1583 | /* Not strictly necessary, but play it safe for now */ |
| 1584 | static inline void w83627hf_reset_bank(struct w83627hf_data *data, u16 reg) |
| 1585 | { |
| 1586 | if (reg & 0xff00) { |
| 1587 | outb_p(W83781D_REG_BANK, data->addr + W83781D_ADDR_REG_OFFSET); |
| 1588 | outb_p(0, data->addr + W83781D_DATA_REG_OFFSET); |
| 1589 | } |
| 1590 | } |
| 1591 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1592 | static int w83627hf_read_value(struct w83627hf_data *data, u16 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | int res, word_sized; |
| 1595 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1596 | mutex_lock(&data->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | word_sized = (((reg & 0xff00) == 0x100) |
| 1598 | || ((reg & 0xff00) == 0x200)) |
| 1599 | && (((reg & 0x00ff) == 0x50) |
| 1600 | || ((reg & 0x00ff) == 0x53) |
| 1601 | || ((reg & 0x00ff) == 0x55)); |
Jean Delvare | d58df9c | 2007-10-10 16:30:23 +0200 | [diff] [blame] | 1602 | w83627hf_set_bank(data, reg); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1603 | outb_p(reg & 0xff, data->addr + W83781D_ADDR_REG_OFFSET); |
| 1604 | res = inb_p(data->addr + W83781D_DATA_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | if (word_sized) { |
| 1606 | outb_p((reg & 0xff) + 1, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1607 | data->addr + W83781D_ADDR_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | res = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1609 | (res << 8) + inb_p(data->addr + |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | W83781D_DATA_REG_OFFSET); |
| 1611 | } |
Jean Delvare | d58df9c | 2007-10-10 16:30:23 +0200 | [diff] [blame] | 1612 | w83627hf_reset_bank(data, reg); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1613 | mutex_unlock(&data->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1614 | return res; |
| 1615 | } |
| 1616 | |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 1617 | static int w83627thf_read_gpio5(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | { |
Jingoo Han | a8b3a3a | 2013-07-30 17:13:06 +0900 | [diff] [blame] | 1619 | struct w83627hf_sio_data *sio_data = dev_get_platdata(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | int res = 0xff, sel; |
| 1621 | |
Jean Delvare | b72656d | 2009-12-09 20:35:49 +0100 | [diff] [blame] | 1622 | superio_enter(sio_data); |
| 1623 | superio_select(sio_data, W83627HF_LD_GPIO5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | |
| 1625 | /* Make sure these GPIO pins are enabled */ |
Jean Delvare | b72656d | 2009-12-09 20:35:49 +0100 | [diff] [blame] | 1626 | if (!(superio_inb(sio_data, W83627THF_GPIO5_EN) & (1<<3))) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1627 | dev_dbg(&pdev->dev, "GPIO5 disabled, no VID function\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | goto exit; |
| 1629 | } |
| 1630 | |
Guenter Roeck | 27b9de3 | 2012-01-15 11:07:26 -0800 | [diff] [blame] | 1631 | /* |
| 1632 | * Make sure the pins are configured for input |
| 1633 | * There must be at least five (VRM 9), and possibly 6 (VRM 10) |
| 1634 | */ |
Jean Delvare | b72656d | 2009-12-09 20:35:49 +0100 | [diff] [blame] | 1635 | sel = superio_inb(sio_data, W83627THF_GPIO5_IOSR) & 0x3f; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | if ((sel & 0x1f) != 0x1f) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1637 | dev_dbg(&pdev->dev, "GPIO5 not configured for VID " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1638 | "function\n"); |
| 1639 | goto exit; |
| 1640 | } |
| 1641 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1642 | dev_info(&pdev->dev, "Reading VID from GPIO5\n"); |
Jean Delvare | b72656d | 2009-12-09 20:35:49 +0100 | [diff] [blame] | 1643 | res = superio_inb(sio_data, W83627THF_GPIO5_DR) & sel; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | |
| 1645 | exit: |
Jean Delvare | b72656d | 2009-12-09 20:35:49 +0100 | [diff] [blame] | 1646 | superio_exit(sio_data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1647 | return res; |
| 1648 | } |
| 1649 | |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 1650 | static int w83687thf_read_vid(struct platform_device *pdev) |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 1651 | { |
Jingoo Han | a8b3a3a | 2013-07-30 17:13:06 +0900 | [diff] [blame] | 1652 | struct w83627hf_sio_data *sio_data = dev_get_platdata(&pdev->dev); |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 1653 | int res = 0xff; |
| 1654 | |
Jean Delvare | b72656d | 2009-12-09 20:35:49 +0100 | [diff] [blame] | 1655 | superio_enter(sio_data); |
| 1656 | superio_select(sio_data, W83627HF_LD_HWM); |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 1657 | |
| 1658 | /* Make sure these GPIO pins are enabled */ |
Jean Delvare | b72656d | 2009-12-09 20:35:49 +0100 | [diff] [blame] | 1659 | if (!(superio_inb(sio_data, W83687THF_VID_EN) & (1 << 2))) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1660 | dev_dbg(&pdev->dev, "VID disabled, no VID function\n"); |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 1661 | goto exit; |
| 1662 | } |
| 1663 | |
| 1664 | /* Make sure the pins are configured for input */ |
Jean Delvare | b72656d | 2009-12-09 20:35:49 +0100 | [diff] [blame] | 1665 | if (!(superio_inb(sio_data, W83687THF_VID_CFG) & (1 << 4))) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1666 | dev_dbg(&pdev->dev, "VID configured as output, " |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 1667 | "no VID function\n"); |
| 1668 | goto exit; |
| 1669 | } |
| 1670 | |
Jean Delvare | b72656d | 2009-12-09 20:35:49 +0100 | [diff] [blame] | 1671 | res = superio_inb(sio_data, W83687THF_VID_DATA) & 0x3f; |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 1672 | |
| 1673 | exit: |
Jean Delvare | b72656d | 2009-12-09 20:35:49 +0100 | [diff] [blame] | 1674 | superio_exit(sio_data); |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 1675 | return res; |
| 1676 | } |
| 1677 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1678 | 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] | 1679 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | int word_sized; |
| 1681 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1682 | mutex_lock(&data->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | word_sized = (((reg & 0xff00) == 0x100) |
| 1684 | || ((reg & 0xff00) == 0x200)) |
| 1685 | && (((reg & 0x00ff) == 0x53) |
| 1686 | || ((reg & 0x00ff) == 0x55)); |
Jean Delvare | d58df9c | 2007-10-10 16:30:23 +0200 | [diff] [blame] | 1687 | w83627hf_set_bank(data, reg); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1688 | outb_p(reg & 0xff, data->addr + W83781D_ADDR_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | if (word_sized) { |
| 1690 | outb_p(value >> 8, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1691 | data->addr + W83781D_DATA_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1692 | outb_p((reg & 0xff) + 1, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1693 | data->addr + W83781D_ADDR_REG_OFFSET); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1694 | } |
| 1695 | outb_p(value & 0xff, |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1696 | data->addr + W83781D_DATA_REG_OFFSET); |
Jean Delvare | d58df9c | 2007-10-10 16:30:23 +0200 | [diff] [blame] | 1697 | w83627hf_reset_bank(data, reg); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1698 | mutex_unlock(&data->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1699 | return 0; |
| 1700 | } |
| 1701 | |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 1702 | static void w83627hf_init_device(struct platform_device *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1704 | struct w83627hf_data *data = platform_get_drvdata(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | int i; |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1706 | enum chips type = data->type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1707 | u8 tmp; |
| 1708 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | /* Minimize conflicts with other winbond i2c-only clients... */ |
| 1710 | /* disable i2c subclients... how to disable main i2c client?? */ |
| 1711 | /* force i2c address to relatively uncommon address */ |
Jean Delvare | 8f3c7c5 | 2012-12-19 22:17:00 +0100 | [diff] [blame] | 1712 | if (type == w83627hf) { |
| 1713 | w83627hf_write_value(data, W83781D_REG_I2C_SUBADDR, 0x89); |
| 1714 | w83627hf_write_value(data, W83781D_REG_I2C_ADDR, force_i2c); |
| 1715 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | |
| 1717 | /* Read VID only once */ |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1718 | if (type == w83627hf || type == w83637hf) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1719 | int lo = w83627hf_read_value(data, W83781D_REG_VID_FANDIV); |
| 1720 | int hi = w83627hf_read_value(data, W83781D_REG_CHIPID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | data->vid = (lo & 0x0f) | ((hi & 0x01) << 4); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1722 | } else if (type == w83627thf) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1723 | data->vid = w83627thf_read_gpio5(pdev); |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1724 | } else if (type == w83687thf) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1725 | data->vid = w83687thf_read_vid(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | } |
| 1727 | |
| 1728 | /* Read VRM & OVT Config only once */ |
Jean Delvare | d27c37c | 2007-05-08 17:21:59 +0200 | [diff] [blame] | 1729 | if (type == w83627thf || type == w83637hf || type == w83687thf) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | data->vrm_ovt = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1731 | w83627hf_read_value(data, W83627THF_REG_VRM_OVT_CFG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1732 | } |
| 1733 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1734 | tmp = w83627hf_read_value(data, W83781D_REG_SCFG1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | for (i = 1; i <= 3; i++) { |
| 1736 | if (!(tmp & BIT_SCFG1[i - 1])) { |
Jean Delvare | b26f933 | 2007-08-16 14:30:01 +0200 | [diff] [blame] | 1737 | data->sens[i - 1] = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1738 | } else { |
| 1739 | if (w83627hf_read_value |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1740 | (data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | W83781D_REG_SCFG2) & BIT_SCFG2[i - 1]) |
| 1742 | data->sens[i - 1] = 1; |
| 1743 | else |
| 1744 | data->sens[i - 1] = 2; |
| 1745 | } |
| 1746 | if ((type == w83697hf) && (i == 2)) |
| 1747 | break; |
| 1748 | } |
| 1749 | |
| 1750 | if(init) { |
| 1751 | /* Enable temp2 */ |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 1752 | tmp = w83627hf_read_value(data, W83627HF_REG_TEMP2_CONFIG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1753 | if (tmp & 0x01) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1754 | dev_warn(&pdev->dev, "Enabling temp2, readings " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1755 | "might not make sense\n"); |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 1756 | w83627hf_write_value(data, W83627HF_REG_TEMP2_CONFIG, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1757 | tmp & 0xfe); |
| 1758 | } |
| 1759 | |
| 1760 | /* Enable temp3 */ |
| 1761 | if (type != w83697hf) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1762 | tmp = w83627hf_read_value(data, |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 1763 | W83627HF_REG_TEMP3_CONFIG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1764 | if (tmp & 0x01) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1765 | dev_warn(&pdev->dev, "Enabling temp3, " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1766 | "readings might not make sense\n"); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1767 | w83627hf_write_value(data, |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 1768 | W83627HF_REG_TEMP3_CONFIG, tmp & 0xfe); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1769 | } |
| 1770 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | /* Start monitoring */ |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1774 | w83627hf_write_value(data, W83781D_REG_CONFIG, |
| 1775 | (w83627hf_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1776 | W83781D_REG_CONFIG) & 0xf7) |
| 1777 | | 0x01); |
Jean Delvare | ef878b1 | 2008-01-03 22:54:13 +0100 | [diff] [blame] | 1778 | |
| 1779 | /* Enable VBAT monitoring if needed */ |
| 1780 | tmp = w83627hf_read_value(data, W83781D_REG_VBAT); |
| 1781 | if (!(tmp & 0x01)) |
| 1782 | w83627hf_write_value(data, W83781D_REG_VBAT, tmp | 0x01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | } |
| 1784 | |
Jean Delvare | c09c518 | 2007-10-12 21:53:07 +0200 | [diff] [blame] | 1785 | static void w83627hf_update_fan_div(struct w83627hf_data *data) |
| 1786 | { |
| 1787 | int reg; |
| 1788 | |
| 1789 | reg = w83627hf_read_value(data, W83781D_REG_VID_FANDIV); |
| 1790 | data->fan_div[0] = (reg >> 4) & 0x03; |
| 1791 | data->fan_div[1] = (reg >> 6) & 0x03; |
| 1792 | if (data->type != w83697hf) { |
| 1793 | data->fan_div[2] = (w83627hf_read_value(data, |
| 1794 | W83781D_REG_PIN) >> 6) & 0x03; |
| 1795 | } |
| 1796 | reg = w83627hf_read_value(data, W83781D_REG_VBAT); |
| 1797 | data->fan_div[0] |= (reg >> 3) & 0x04; |
| 1798 | data->fan_div[1] |= (reg >> 4) & 0x04; |
| 1799 | if (data->type != w83697hf) |
| 1800 | data->fan_div[2] |= (reg >> 5) & 0x04; |
| 1801 | } |
| 1802 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1803 | static struct w83627hf_data *w83627hf_update_device(struct device *dev) |
| 1804 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1805 | struct w83627hf_data *data = dev_get_drvdata(dev); |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 1806 | int i, num_temps = (data->type == w83697hf) ? 2 : 3; |
Dominik Geyer | a95a5ed | 2008-08-06 22:41:04 +0200 | [diff] [blame] | 1807 | int num_pwms = (data->type == w83697hf) ? 2 : 3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1809 | mutex_lock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | |
| 1811 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
| 1812 | || !data->valid) { |
| 1813 | for (i = 0; i <= 8; i++) { |
| 1814 | /* skip missing sensors */ |
| 1815 | if (((data->type == w83697hf) && (i == 1)) || |
Jean Delvare | c2db6ce | 2006-01-18 23:22:12 +0100 | [diff] [blame] | 1816 | ((data->type != w83627hf && data->type != w83697hf) |
Yuan Mu | 4a1c4447 | 2005-11-07 22:19:04 +0100 | [diff] [blame] | 1817 | && (i == 5 || i == 6))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | continue; |
| 1819 | data->in[i] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1820 | w83627hf_read_value(data, W83781D_REG_IN(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | data->in_min[i] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1822 | w83627hf_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1823 | W83781D_REG_IN_MIN(i)); |
| 1824 | data->in_max[i] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1825 | w83627hf_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | W83781D_REG_IN_MAX(i)); |
| 1827 | } |
Jim Cromie | 2ca2fcd | 2007-10-14 17:20:50 -0600 | [diff] [blame] | 1828 | for (i = 0; i <= 2; i++) { |
| 1829 | data->fan[i] = |
| 1830 | w83627hf_read_value(data, W83627HF_REG_FAN(i)); |
| 1831 | data->fan_min[i] = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1832 | w83627hf_read_value(data, |
Jim Cromie | 2ca2fcd | 2007-10-14 17:20:50 -0600 | [diff] [blame] | 1833 | W83627HF_REG_FAN_MIN(i)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | } |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1835 | for (i = 0; i <= 2; i++) { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1836 | u8 tmp = w83627hf_read_value(data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | W836X7HF_REG_PWM(data->type, i)); |
| 1838 | /* bits 0-3 are reserved in 627THF */ |
| 1839 | if (data->type == w83627thf) |
| 1840 | tmp &= 0xf0; |
Jim Cromie | 07584c7 | 2007-10-12 21:08:00 +0200 | [diff] [blame] | 1841 | data->pwm[i] = tmp; |
| 1842 | if (i == 1 && |
| 1843 | (data->type == w83627hf || data->type == w83697hf)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | break; |
| 1845 | } |
Carlos Olalla Martinez | 1550cb6 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1846 | if (data->type == w83627hf) { |
| 1847 | u8 tmp = w83627hf_read_value(data, |
| 1848 | W83627HF_REG_PWM_FREQ); |
| 1849 | data->pwm_freq[0] = tmp & 0x07; |
| 1850 | data->pwm_freq[1] = (tmp >> 4) & 0x07; |
| 1851 | } else if (data->type != w83627thf) { |
| 1852 | for (i = 1; i <= 3; i++) { |
| 1853 | data->pwm_freq[i - 1] = |
| 1854 | w83627hf_read_value(data, |
| 1855 | W83637HF_REG_PWM_FREQ[i - 1]); |
| 1856 | if (i == 2 && (data->type == w83697hf)) |
| 1857 | break; |
| 1858 | } |
| 1859 | } |
Dominik Geyer | a95a5ed | 2008-08-06 22:41:04 +0200 | [diff] [blame] | 1860 | if (data->type != w83627hf) { |
| 1861 | for (i = 0; i < num_pwms; i++) { |
| 1862 | u8 tmp = w83627hf_read_value(data, |
| 1863 | W83627THF_REG_PWM_ENABLE[i]); |
| 1864 | data->pwm_enable[i] = |
| 1865 | ((tmp >> W83627THF_PWM_ENABLE_SHIFT[i]) |
| 1866 | & 0x03) + 1; |
| 1867 | } |
| 1868 | } |
Jim Cromie | df48ed8 | 2007-10-14 17:10:52 -0600 | [diff] [blame] | 1869 | for (i = 0; i < num_temps; i++) { |
| 1870 | data->temp[i] = w83627hf_read_value( |
| 1871 | data, w83627hf_reg_temp[i]); |
| 1872 | data->temp_max[i] = w83627hf_read_value( |
| 1873 | data, w83627hf_reg_temp_over[i]); |
| 1874 | data->temp_max_hyst[i] = w83627hf_read_value( |
| 1875 | data, w83627hf_reg_temp_hyst[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | } |
| 1877 | |
Jean Delvare | c09c518 | 2007-10-12 21:53:07 +0200 | [diff] [blame] | 1878 | w83627hf_update_fan_div(data); |
| 1879 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | data->alarms = |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1881 | w83627hf_read_value(data, W83781D_REG_ALARM1) | |
| 1882 | (w83627hf_read_value(data, W83781D_REG_ALARM2) << 8) | |
| 1883 | (w83627hf_read_value(data, W83781D_REG_ALARM3) << 16); |
| 1884 | i = w83627hf_read_value(data, W83781D_REG_BEEP_INTS2); |
Jean Delvare | 1c13810 | 2008-01-03 23:04:55 +0100 | [diff] [blame] | 1885 | data->beep_mask = (i << 8) | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1886 | w83627hf_read_value(data, W83781D_REG_BEEP_INTS1) | |
| 1887 | w83627hf_read_value(data, W83781D_REG_BEEP_INTS3) << 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1888 | data->last_updated = jiffies; |
| 1889 | data->valid = 1; |
| 1890 | } |
| 1891 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1892 | mutex_unlock(&data->update_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | |
| 1894 | return data; |
| 1895 | } |
| 1896 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1897 | static int __init w83627hf_device_add(unsigned short address, |
| 1898 | const struct w83627hf_sio_data *sio_data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1900 | struct resource res = { |
| 1901 | .start = address + WINB_REGION_OFFSET, |
| 1902 | .end = address + WINB_REGION_OFFSET + WINB_REGION_SIZE - 1, |
| 1903 | .name = DRVNAME, |
| 1904 | .flags = IORESOURCE_IO, |
| 1905 | }; |
| 1906 | int err; |
| 1907 | |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 1908 | err = acpi_check_resource_conflict(&res); |
| 1909 | if (err) |
| 1910 | goto exit; |
| 1911 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1912 | pdev = platform_device_alloc(DRVNAME, address); |
| 1913 | if (!pdev) { |
| 1914 | err = -ENOMEM; |
Joe Perches | 18de030 | 2010-10-20 06:51:55 +0000 | [diff] [blame] | 1915 | pr_err("Device allocation failed\n"); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1916 | goto exit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1919 | err = platform_device_add_resources(pdev, &res, 1); |
| 1920 | if (err) { |
Joe Perches | 18de030 | 2010-10-20 06:51:55 +0000 | [diff] [blame] | 1921 | pr_err("Device resource addition failed (%d)\n", err); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1922 | goto exit_device_put; |
| 1923 | } |
| 1924 | |
Jean Delvare | 2df6d81 | 2007-06-09 10:11:16 -0400 | [diff] [blame] | 1925 | err = platform_device_add_data(pdev, sio_data, |
| 1926 | sizeof(struct w83627hf_sio_data)); |
| 1927 | if (err) { |
Joe Perches | 18de030 | 2010-10-20 06:51:55 +0000 | [diff] [blame] | 1928 | pr_err("Platform data allocation failed\n"); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1929 | goto exit_device_put; |
| 1930 | } |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1931 | |
| 1932 | err = platform_device_add(pdev); |
| 1933 | if (err) { |
Joe Perches | 18de030 | 2010-10-20 06:51:55 +0000 | [diff] [blame] | 1934 | pr_err("Device addition failed (%d)\n", err); |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1935 | goto exit_device_put; |
| 1936 | } |
| 1937 | |
| 1938 | return 0; |
| 1939 | |
| 1940 | exit_device_put: |
| 1941 | platform_device_put(pdev); |
| 1942 | exit: |
| 1943 | return err; |
| 1944 | } |
| 1945 | |
| 1946 | static int __init sensors_w83627hf_init(void) |
| 1947 | { |
| 1948 | int err; |
| 1949 | unsigned short address; |
| 1950 | struct w83627hf_sio_data sio_data; |
| 1951 | |
| 1952 | if (w83627hf_find(0x2e, &address, &sio_data) |
| 1953 | && w83627hf_find(0x4e, &address, &sio_data)) |
| 1954 | return -ENODEV; |
| 1955 | |
| 1956 | err = platform_driver_register(&w83627hf_driver); |
| 1957 | if (err) |
| 1958 | goto exit; |
| 1959 | |
| 1960 | /* Sets global pdev as a side effect */ |
| 1961 | err = w83627hf_device_add(address, &sio_data); |
| 1962 | if (err) |
| 1963 | goto exit_driver; |
| 1964 | |
| 1965 | return 0; |
| 1966 | |
| 1967 | exit_driver: |
| 1968 | platform_driver_unregister(&w83627hf_driver); |
| 1969 | exit: |
| 1970 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | static void __exit sensors_w83627hf_exit(void) |
| 1974 | { |
Jean Delvare | 787c72b | 2007-05-08 17:22:00 +0200 | [diff] [blame] | 1975 | platform_device_unregister(pdev); |
| 1976 | platform_driver_unregister(&w83627hf_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | MODULE_AUTHOR("Frodo Looijaard <frodol@dds.nl>, " |
| 1980 | "Philip Edelbrock <phil@netroedge.com>, " |
| 1981 | "and Mark Studebaker <mdsxyz123@yahoo.com>"); |
| 1982 | MODULE_DESCRIPTION("W83627HF driver"); |
| 1983 | MODULE_LICENSE("GPL"); |
| 1984 | |
| 1985 | module_init(sensors_w83627hf_init); |
| 1986 | module_exit(sensors_w83627hf_exit); |