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