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