Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1 | /* |
Guenter Roeck | 8969e84 | 2012-01-19 11:02:27 -0800 | [diff] [blame^] | 2 | * w83627ehf - Driver for the hardware monitoring functionality of |
| 3 | * the Winbond W83627EHF Super-I/O chip |
| 4 | * Copyright (C) 2005-2011 Jean Delvare <khali@linux-fr.org> |
| 5 | * Copyright (C) 2006 Yuan Mu (Winbond), |
| 6 | * Rudolf Marek <r.marek@assembler.cz> |
| 7 | * David Hubbard <david.c.hubbard@gmail.com> |
| 8 | * Daniel J Blueman <daniel.blueman@gmail.com> |
| 9 | * Copyright (C) 2010 Sheng-Yuan Huang (Nuvoton) (PS00) |
| 10 | * |
| 11 | * Shamelessly ripped from the w83627hf driver |
| 12 | * Copyright (C) 2003 Mark Studebaker |
| 13 | * |
| 14 | * Thanks to Leon Moonen, Steve Cliffe and Grant Coady for their help |
| 15 | * in testing and debugging this driver. |
| 16 | * |
| 17 | * This driver also supports the W83627EHG, which is the lead-free |
| 18 | * version of the W83627EHF. |
| 19 | * |
| 20 | * This program is free software; you can redistribute it and/or modify |
| 21 | * it under the terms of the GNU General Public License as published by |
| 22 | * the Free Software Foundation; either version 2 of the License, or |
| 23 | * (at your option) any later version. |
| 24 | * |
| 25 | * This program is distributed in the hope that it will be useful, |
| 26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 28 | * GNU General Public License for more details. |
| 29 | * |
| 30 | * You should have received a copy of the GNU General Public License |
| 31 | * along with this program; if not, write to the Free Software |
| 32 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 33 | * |
| 34 | * Supports the following chips: |
| 35 | * |
| 36 | * Chip #vin #fan #pwm #temp chip IDs man ID |
| 37 | * w83627ehf 10 5 4 3 0x8850 0x88 0x5ca3 |
| 38 | * 0x8860 0xa1 |
| 39 | * w83627dhg 9 5 4 3 0xa020 0xc1 0x5ca3 |
| 40 | * w83627dhg-p 9 5 4 3 0xb070 0xc1 0x5ca3 |
| 41 | * w83627uhg 8 2 2 3 0xa230 0xc1 0x5ca3 |
| 42 | * w83667hg 9 5 3 3 0xa510 0xc1 0x5ca3 |
| 43 | * w83667hg-b 9 5 3 4 0xb350 0xc1 0x5ca3 |
| 44 | * nct6775f 9 4 3 9 0xb470 0xc1 0x5ca3 |
| 45 | * nct6776f 9 5 3 9 0xC330 0xc1 0x5ca3 |
| 46 | */ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 47 | |
Joe Perches | abdc6fd | 2010-10-20 06:51:54 +0000 | [diff] [blame] | 48 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 49 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 50 | #include <linux/module.h> |
| 51 | #include <linux/init.h> |
| 52 | #include <linux/slab.h> |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 53 | #include <linux/jiffies.h> |
| 54 | #include <linux/platform_device.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 55 | #include <linux/hwmon.h> |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 56 | #include <linux/hwmon-sysfs.h> |
Jean Delvare | fc18d6c | 2007-06-24 11:19:42 +0200 | [diff] [blame] | 57 | #include <linux/hwmon-vid.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 58 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 59 | #include <linux/mutex.h> |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 60 | #include <linux/acpi.h> |
H Hartley Sweeten | 6055fae | 2009-09-15 17:18:13 +0200 | [diff] [blame] | 61 | #include <linux/io.h> |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 62 | #include "lm75.h" |
| 63 | |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 64 | enum kinds { |
| 65 | w83627ehf, w83627dhg, w83627dhg_p, w83627uhg, |
| 66 | w83667hg, w83667hg_b, nct6775, nct6776, |
| 67 | }; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 68 | |
| 69 | /* used to set data->name = w83627ehf_device_names[data->sio_kind] */ |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 70 | static const char * const w83627ehf_device_names[] = { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 71 | "w83627ehf", |
| 72 | "w83627dhg", |
Jean Delvare | c1e48dc | 2009-06-15 18:39:50 +0200 | [diff] [blame] | 73 | "w83627dhg", |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 74 | "w83627uhg", |
Gong Jun | 237c8d2 | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 75 | "w83667hg", |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 76 | "w83667hg", |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 77 | "nct6775", |
| 78 | "nct6776", |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 79 | }; |
| 80 | |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 81 | static unsigned short force_id; |
| 82 | module_param(force_id, ushort, 0); |
| 83 | MODULE_PARM_DESC(force_id, "Override the detected device ID"); |
| 84 | |
Ian Dobson | d42e869 | 2011-03-07 14:21:12 -0800 | [diff] [blame] | 85 | static unsigned short fan_debounce; |
| 86 | module_param(fan_debounce, ushort, 0); |
| 87 | MODULE_PARM_DESC(fan_debounce, "Enable debouncing for fan RPM signal"); |
| 88 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 89 | #define DRVNAME "w83627ehf" |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 90 | |
| 91 | /* |
| 92 | * Super-I/O constants and functions |
| 93 | */ |
| 94 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 95 | #define W83627EHF_LD_HWM 0x0b |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 96 | #define W83667HG_LD_VID 0x0d |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 97 | |
| 98 | #define SIO_REG_LDSEL 0x07 /* Logical device select */ |
| 99 | #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */ |
Jean Delvare | fc18d6c | 2007-06-24 11:19:42 +0200 | [diff] [blame] | 100 | #define SIO_REG_EN_VRM10 0x2C /* GPIO3, GPIO4 selection */ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 101 | #define SIO_REG_ENABLE 0x30 /* Logical device enable */ |
| 102 | #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */ |
Jean Delvare | fc18d6c | 2007-06-24 11:19:42 +0200 | [diff] [blame] | 103 | #define SIO_REG_VID_CTRL 0xF0 /* VID control */ |
| 104 | #define SIO_REG_VID_DATA 0xF1 /* VID data */ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 105 | |
David Hubbard | 657c93b | 2007-02-14 21:15:04 +0100 | [diff] [blame] | 106 | #define SIO_W83627EHF_ID 0x8850 |
| 107 | #define SIO_W83627EHG_ID 0x8860 |
| 108 | #define SIO_W83627DHG_ID 0xa020 |
Jean Delvare | c1e48dc | 2009-06-15 18:39:50 +0200 | [diff] [blame] | 109 | #define SIO_W83627DHG_P_ID 0xb070 |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 110 | #define SIO_W83627UHG_ID 0xa230 |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 111 | #define SIO_W83667HG_ID 0xa510 |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 112 | #define SIO_W83667HG_B_ID 0xb350 |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 113 | #define SIO_NCT6775_ID 0xb470 |
| 114 | #define SIO_NCT6776_ID 0xc330 |
David Hubbard | 657c93b | 2007-02-14 21:15:04 +0100 | [diff] [blame] | 115 | #define SIO_ID_MASK 0xFFF0 |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 116 | |
| 117 | static inline void |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 118 | superio_outb(int ioreg, int reg, int val) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 119 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 120 | outb(reg, ioreg); |
| 121 | outb(val, ioreg + 1); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static inline int |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 125 | superio_inb(int ioreg, int reg) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 126 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 127 | outb(reg, ioreg); |
| 128 | return inb(ioreg + 1); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | static inline void |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 132 | superio_select(int ioreg, int ld) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 133 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 134 | outb(SIO_REG_LDSEL, ioreg); |
| 135 | outb(ld, ioreg + 1); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 136 | } |
| 137 | |
| 138 | static inline void |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 139 | superio_enter(int ioreg) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 140 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 141 | outb(0x87, ioreg); |
| 142 | outb(0x87, ioreg); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | static inline void |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 146 | superio_exit(int ioreg) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 147 | { |
Jonas Jonsson | 022b75a | 2010-09-17 17:24:13 +0200 | [diff] [blame] | 148 | outb(0xaa, ioreg); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 149 | outb(0x02, ioreg); |
| 150 | outb(0x02, ioreg + 1); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /* |
| 154 | * ISA constants |
| 155 | */ |
| 156 | |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 157 | #define IOREGION_ALIGNMENT (~7) |
Jean Delvare | 1a641fc | 2007-04-23 14:41:16 -0700 | [diff] [blame] | 158 | #define IOREGION_OFFSET 5 |
| 159 | #define IOREGION_LENGTH 2 |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 160 | #define ADDR_REG_OFFSET 0 |
| 161 | #define DATA_REG_OFFSET 1 |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 162 | |
| 163 | #define W83627EHF_REG_BANK 0x4E |
| 164 | #define W83627EHF_REG_CONFIG 0x40 |
David Hubbard | 657c93b | 2007-02-14 21:15:04 +0100 | [diff] [blame] | 165 | |
Guenter Roeck | 8969e84 | 2012-01-19 11:02:27 -0800 | [diff] [blame^] | 166 | /* |
| 167 | * Not currently used: |
David Hubbard | 657c93b | 2007-02-14 21:15:04 +0100 | [diff] [blame] | 168 | * REG_MAN_ID has the value 0x5ca3 for all supported chips. |
| 169 | * REG_CHIP_ID == 0x88/0xa1/0xc1 depending on chip model. |
| 170 | * REG_MAN_ID is at port 0x4f |
Guenter Roeck | 8969e84 | 2012-01-19 11:02:27 -0800 | [diff] [blame^] | 171 | * REG_CHIP_ID is at port 0x58 |
| 172 | */ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 173 | |
| 174 | static const u16 W83627EHF_REG_FAN[] = { 0x28, 0x29, 0x2a, 0x3f, 0x553 }; |
| 175 | static const u16 W83627EHF_REG_FAN_MIN[] = { 0x3b, 0x3c, 0x3d, 0x3e, 0x55c }; |
| 176 | |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 177 | /* The W83627EHF registers for nr=7,8,9 are in bank 5 */ |
| 178 | #define W83627EHF_REG_IN_MAX(nr) ((nr < 7) ? (0x2b + (nr) * 2) : \ |
| 179 | (0x554 + (((nr) - 7) * 2))) |
| 180 | #define W83627EHF_REG_IN_MIN(nr) ((nr < 7) ? (0x2c + (nr) * 2) : \ |
| 181 | (0x555 + (((nr) - 7) * 2))) |
| 182 | #define W83627EHF_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \ |
| 183 | (0x550 + (nr) - 7)) |
| 184 | |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 185 | static const u16 W83627EHF_REG_TEMP[] = { 0x27, 0x150, 0x250, 0x7e }; |
| 186 | static const u16 W83627EHF_REG_TEMP_HYST[] = { 0x3a, 0x153, 0x253, 0 }; |
| 187 | static const u16 W83627EHF_REG_TEMP_OVER[] = { 0x39, 0x155, 0x255, 0 }; |
| 188 | static const u16 W83627EHF_REG_TEMP_CONFIG[] = { 0, 0x152, 0x252, 0 }; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 189 | |
| 190 | /* Fan clock dividers are spread over the following five registers */ |
| 191 | #define W83627EHF_REG_FANDIV1 0x47 |
| 192 | #define W83627EHF_REG_FANDIV2 0x4B |
| 193 | #define W83627EHF_REG_VBAT 0x5D |
| 194 | #define W83627EHF_REG_DIODE 0x59 |
| 195 | #define W83627EHF_REG_SMI_OVT 0x4C |
| 196 | |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 197 | /* NCT6775F has its own fan divider registers */ |
| 198 | #define NCT6775_REG_FANDIV1 0x506 |
| 199 | #define NCT6775_REG_FANDIV2 0x507 |
Ian Dobson | d42e869 | 2011-03-07 14:21:12 -0800 | [diff] [blame] | 200 | #define NCT6775_REG_FAN_DEBOUNCE 0xf0 |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 201 | |
Jean Delvare | a4589db | 2006-03-23 16:30:29 +0100 | [diff] [blame] | 202 | #define W83627EHF_REG_ALARM1 0x459 |
| 203 | #define W83627EHF_REG_ALARM2 0x45A |
| 204 | #define W83627EHF_REG_ALARM3 0x45B |
| 205 | |
Dmitry Artamonow | 363a12a | 2011-08-12 16:41:11 -0400 | [diff] [blame] | 206 | #define W83627EHF_REG_CASEOPEN_DET 0x42 /* SMI STATUS #2 */ |
| 207 | #define W83627EHF_REG_CASEOPEN_CLR 0x46 /* SMI MASK #3 */ |
| 208 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 209 | /* SmartFan registers */ |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 210 | #define W83627EHF_REG_FAN_STEPUP_TIME 0x0f |
| 211 | #define W83627EHF_REG_FAN_STEPDOWN_TIME 0x0e |
| 212 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 213 | /* DC or PWM output fan configuration */ |
| 214 | static const u8 W83627EHF_REG_PWM_ENABLE[] = { |
| 215 | 0x04, /* SYS FAN0 output mode and PWM mode */ |
| 216 | 0x04, /* CPU FAN0 output mode and PWM mode */ |
| 217 | 0x12, /* AUX FAN mode */ |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 218 | 0x62, /* CPU FAN1 mode */ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | static const u8 W83627EHF_PWM_MODE_SHIFT[] = { 0, 1, 0, 6 }; |
| 222 | static const u8 W83627EHF_PWM_ENABLE_SHIFT[] = { 2, 4, 1, 4 }; |
| 223 | |
| 224 | /* FAN Duty Cycle, be used to control */ |
Guenter Roeck | 279af1a | 2011-02-13 22:34:47 -0800 | [diff] [blame] | 225 | static const u16 W83627EHF_REG_PWM[] = { 0x01, 0x03, 0x11, 0x61 }; |
| 226 | static const u16 W83627EHF_REG_TARGET[] = { 0x05, 0x06, 0x13, 0x63 }; |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 227 | static const u8 W83627EHF_REG_TOLERANCE[] = { 0x07, 0x07, 0x14, 0x62 }; |
| 228 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 229 | /* Advanced Fan control, some values are common for all fans */ |
Guenter Roeck | 279af1a | 2011-02-13 22:34:47 -0800 | [diff] [blame] | 230 | static const u16 W83627EHF_REG_FAN_START_OUTPUT[] = { 0x0a, 0x0b, 0x16, 0x65 }; |
| 231 | static const u16 W83627EHF_REG_FAN_STOP_OUTPUT[] = { 0x08, 0x09, 0x15, 0x64 }; |
| 232 | static const u16 W83627EHF_REG_FAN_STOP_TIME[] = { 0x0c, 0x0d, 0x17, 0x66 }; |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 233 | |
Guenter Roeck | 279af1a | 2011-02-13 22:34:47 -0800 | [diff] [blame] | 234 | static const u16 W83627EHF_REG_FAN_MAX_OUTPUT_COMMON[] |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 235 | = { 0xff, 0x67, 0xff, 0x69 }; |
Guenter Roeck | 279af1a | 2011-02-13 22:34:47 -0800 | [diff] [blame] | 236 | static const u16 W83627EHF_REG_FAN_STEP_OUTPUT_COMMON[] |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 237 | = { 0xff, 0x68, 0xff, 0x6a }; |
| 238 | |
Guenter Roeck | 279af1a | 2011-02-13 22:34:47 -0800 | [diff] [blame] | 239 | static const u16 W83627EHF_REG_FAN_MAX_OUTPUT_W83667_B[] = { 0x67, 0x69, 0x6b }; |
| 240 | static const u16 W83627EHF_REG_FAN_STEP_OUTPUT_W83667_B[] |
| 241 | = { 0x68, 0x6a, 0x6c }; |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 242 | |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 243 | static const u16 NCT6775_REG_TARGET[] = { 0x101, 0x201, 0x301 }; |
| 244 | static const u16 NCT6775_REG_FAN_MODE[] = { 0x102, 0x202, 0x302 }; |
| 245 | static const u16 NCT6775_REG_FAN_STOP_OUTPUT[] = { 0x105, 0x205, 0x305 }; |
| 246 | static const u16 NCT6775_REG_FAN_START_OUTPUT[] = { 0x106, 0x206, 0x306 }; |
| 247 | static const u16 NCT6775_REG_FAN_STOP_TIME[] = { 0x107, 0x207, 0x307 }; |
| 248 | static const u16 NCT6775_REG_PWM[] = { 0x109, 0x209, 0x309 }; |
| 249 | static const u16 NCT6775_REG_FAN_MAX_OUTPUT[] = { 0x10a, 0x20a, 0x30a }; |
| 250 | static const u16 NCT6775_REG_FAN_STEP_OUTPUT[] = { 0x10b, 0x20b, 0x30b }; |
Guenter Roeck | 26bc440 | 2011-02-11 08:00:58 -0800 | [diff] [blame] | 251 | static const u16 NCT6775_REG_FAN[] = { 0x630, 0x632, 0x634, 0x636, 0x638 }; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 252 | static const u16 NCT6776_REG_FAN_MIN[] = { 0x63a, 0x63c, 0x63e, 0x640, 0x642}; |
| 253 | |
| 254 | static const u16 NCT6775_REG_TEMP[] |
| 255 | = { 0x27, 0x150, 0x250, 0x73, 0x75, 0x77, 0x62b, 0x62c, 0x62d }; |
| 256 | static const u16 NCT6775_REG_TEMP_CONFIG[] |
| 257 | = { 0, 0x152, 0x252, 0, 0, 0, 0x628, 0x629, 0x62A }; |
| 258 | static const u16 NCT6775_REG_TEMP_HYST[] |
| 259 | = { 0x3a, 0x153, 0x253, 0, 0, 0, 0x673, 0x678, 0x67D }; |
| 260 | static const u16 NCT6775_REG_TEMP_OVER[] |
| 261 | = { 0x39, 0x155, 0x255, 0, 0, 0, 0x672, 0x677, 0x67C }; |
| 262 | static const u16 NCT6775_REG_TEMP_SOURCE[] |
| 263 | = { 0x621, 0x622, 0x623, 0x100, 0x200, 0x300, 0x624, 0x625, 0x626 }; |
| 264 | |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 265 | static const char *const w83667hg_b_temp_label[] = { |
| 266 | "SYSTIN", |
| 267 | "CPUTIN", |
| 268 | "AUXTIN", |
| 269 | "AMDTSI", |
| 270 | "PECI Agent 1", |
| 271 | "PECI Agent 2", |
| 272 | "PECI Agent 3", |
| 273 | "PECI Agent 4" |
| 274 | }; |
| 275 | |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 276 | static const char *const nct6775_temp_label[] = { |
| 277 | "", |
| 278 | "SYSTIN", |
| 279 | "CPUTIN", |
| 280 | "AUXTIN", |
| 281 | "AMD SB-TSI", |
| 282 | "PECI Agent 0", |
| 283 | "PECI Agent 1", |
| 284 | "PECI Agent 2", |
| 285 | "PECI Agent 3", |
| 286 | "PECI Agent 4", |
| 287 | "PECI Agent 5", |
| 288 | "PECI Agent 6", |
| 289 | "PECI Agent 7", |
| 290 | "PCH_CHIP_CPU_MAX_TEMP", |
| 291 | "PCH_CHIP_TEMP", |
| 292 | "PCH_CPU_TEMP", |
| 293 | "PCH_MCH_TEMP", |
| 294 | "PCH_DIM0_TEMP", |
| 295 | "PCH_DIM1_TEMP", |
| 296 | "PCH_DIM2_TEMP", |
| 297 | "PCH_DIM3_TEMP" |
| 298 | }; |
| 299 | |
| 300 | static const char *const nct6776_temp_label[] = { |
| 301 | "", |
| 302 | "SYSTIN", |
| 303 | "CPUTIN", |
| 304 | "AUXTIN", |
| 305 | "SMBUSMASTER 0", |
| 306 | "SMBUSMASTER 1", |
| 307 | "SMBUSMASTER 2", |
| 308 | "SMBUSMASTER 3", |
| 309 | "SMBUSMASTER 4", |
| 310 | "SMBUSMASTER 5", |
| 311 | "SMBUSMASTER 6", |
| 312 | "SMBUSMASTER 7", |
| 313 | "PECI Agent 0", |
| 314 | "PECI Agent 1", |
| 315 | "PCH_CHIP_CPU_MAX_TEMP", |
| 316 | "PCH_CHIP_TEMP", |
| 317 | "PCH_CPU_TEMP", |
| 318 | "PCH_MCH_TEMP", |
| 319 | "PCH_DIM0_TEMP", |
| 320 | "PCH_DIM1_TEMP", |
| 321 | "PCH_DIM2_TEMP", |
| 322 | "PCH_DIM3_TEMP", |
| 323 | "BYTE_TEMP" |
| 324 | }; |
| 325 | |
| 326 | #define NUM_REG_TEMP ARRAY_SIZE(NCT6775_REG_TEMP) |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 327 | |
Jean Delvare | 17296fe | 2011-10-20 03:08:27 -0400 | [diff] [blame] | 328 | static int is_word_sized(u16 reg) |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 329 | { |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 330 | return ((((reg & 0xff00) == 0x100 |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 331 | || (reg & 0xff00) == 0x200) |
| 332 | && ((reg & 0x00ff) == 0x50 |
| 333 | || (reg & 0x00ff) == 0x53 |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 334 | || (reg & 0x00ff) == 0x55)) |
| 335 | || (reg & 0xfff0) == 0x630 |
| 336 | || reg == 0x640 || reg == 0x642 |
| 337 | || ((reg & 0xfff0) == 0x650 |
| 338 | && (reg & 0x000f) >= 0x06) |
| 339 | || reg == 0x73 || reg == 0x75 || reg == 0x77 |
| 340 | ); |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 341 | } |
| 342 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 343 | /* |
| 344 | * Conversions |
| 345 | */ |
| 346 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 347 | /* 1 is PWM mode, output in ms */ |
| 348 | static inline unsigned int step_time_from_reg(u8 reg, u8 mode) |
| 349 | { |
| 350 | return mode ? 100 * reg : 400 * reg; |
| 351 | } |
| 352 | |
| 353 | static inline u8 step_time_to_reg(unsigned int msec, u8 mode) |
| 354 | { |
| 355 | return SENSORS_LIMIT((mode ? (msec + 50) / 100 : |
| 356 | (msec + 200) / 400), 1, 255); |
| 357 | } |
| 358 | |
Guenter Roeck | 26bc440 | 2011-02-11 08:00:58 -0800 | [diff] [blame] | 359 | static unsigned int fan_from_reg8(u16 reg, unsigned int divreg) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 360 | { |
Guenter Roeck | 26bc440 | 2011-02-11 08:00:58 -0800 | [diff] [blame] | 361 | if (reg == 0 || reg == 255) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 362 | return 0; |
Guenter Roeck | 26bc440 | 2011-02-11 08:00:58 -0800 | [diff] [blame] | 363 | return 1350000U / (reg << divreg); |
| 364 | } |
| 365 | |
| 366 | static unsigned int fan_from_reg13(u16 reg, unsigned int divreg) |
| 367 | { |
| 368 | if ((reg & 0xff1f) == 0xff1f) |
| 369 | return 0; |
| 370 | |
| 371 | reg = (reg & 0x1f) | ((reg & 0xff00) >> 3); |
| 372 | |
| 373 | if (reg == 0) |
| 374 | return 0; |
| 375 | |
| 376 | return 1350000U / reg; |
| 377 | } |
| 378 | |
| 379 | static unsigned int fan_from_reg16(u16 reg, unsigned int divreg) |
| 380 | { |
| 381 | if (reg == 0 || reg == 0xffff) |
| 382 | return 0; |
| 383 | |
| 384 | /* |
| 385 | * Even though the registers are 16 bit wide, the fan divisor |
| 386 | * still applies. |
| 387 | */ |
| 388 | return 1350000U / (reg << divreg); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | static inline unsigned int |
| 392 | div_from_reg(u8 reg) |
| 393 | { |
| 394 | return 1 << reg; |
| 395 | } |
| 396 | |
Guenter Roeck | 8969e84 | 2012-01-19 11:02:27 -0800 | [diff] [blame^] | 397 | /* |
| 398 | * Some of the voltage inputs have internal scaling, the tables below |
| 399 | * contain 8 (the ADC LSB in mV) * scaling factor * 100 |
| 400 | */ |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 401 | static const u16 scale_in_common[10] = { |
| 402 | 800, 800, 1600, 1600, 800, 800, 800, 1600, 1600, 800 |
| 403 | }; |
| 404 | static const u16 scale_in_w83627uhg[9] = { |
| 405 | 800, 800, 3328, 3424, 800, 800, 0, 3328, 3400 |
| 406 | }; |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 407 | |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 408 | static inline long in_from_reg(u8 reg, u8 nr, const u16 *scale_in) |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 409 | { |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 410 | return DIV_ROUND_CLOSEST(reg * scale_in[nr], 100); |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 411 | } |
| 412 | |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 413 | static inline u8 in_to_reg(u32 val, u8 nr, const u16 *scale_in) |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 414 | { |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 415 | return SENSORS_LIMIT(DIV_ROUND_CLOSEST(val * 100, scale_in[nr]), 0, |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 416 | 255); |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 417 | } |
| 418 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 419 | /* |
| 420 | * Data structures and manipulation thereof |
| 421 | */ |
| 422 | |
| 423 | struct w83627ehf_data { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 424 | int addr; /* IO base of hw monitor block */ |
| 425 | const char *name; |
| 426 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 427 | struct device *hwmon_dev; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 428 | struct mutex lock; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 429 | |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 430 | u16 reg_temp[NUM_REG_TEMP]; |
| 431 | u16 reg_temp_over[NUM_REG_TEMP]; |
| 432 | u16 reg_temp_hyst[NUM_REG_TEMP]; |
| 433 | u16 reg_temp_config[NUM_REG_TEMP]; |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 434 | u8 temp_src[NUM_REG_TEMP]; |
| 435 | const char * const *temp_label; |
| 436 | |
Guenter Roeck | 279af1a | 2011-02-13 22:34:47 -0800 | [diff] [blame] | 437 | const u16 *REG_PWM; |
| 438 | const u16 *REG_TARGET; |
| 439 | const u16 *REG_FAN; |
| 440 | const u16 *REG_FAN_MIN; |
| 441 | const u16 *REG_FAN_START_OUTPUT; |
| 442 | const u16 *REG_FAN_STOP_OUTPUT; |
| 443 | const u16 *REG_FAN_STOP_TIME; |
| 444 | const u16 *REG_FAN_MAX_OUTPUT; |
| 445 | const u16 *REG_FAN_STEP_OUTPUT; |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 446 | const u16 *scale_in; |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 447 | |
Guenter Roeck | 26bc440 | 2011-02-11 08:00:58 -0800 | [diff] [blame] | 448 | unsigned int (*fan_from_reg)(u16 reg, unsigned int divreg); |
| 449 | unsigned int (*fan_from_reg_min)(u16 reg, unsigned int divreg); |
| 450 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 451 | struct mutex update_lock; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 452 | char valid; /* !=0 if following fields are valid */ |
| 453 | unsigned long last_updated; /* In jiffies */ |
| 454 | |
| 455 | /* Register values */ |
Guenter Roeck | 83cc898 | 2011-02-06 08:10:15 -0800 | [diff] [blame] | 456 | u8 bank; /* current register bank */ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 457 | u8 in_num; /* number of in inputs we have */ |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 458 | u8 in[10]; /* Register value */ |
| 459 | u8 in_max[10]; /* Register value */ |
| 460 | u8 in_min[10]; /* Register value */ |
Guenter Roeck | 3382a91 | 2011-02-13 13:08:23 -0800 | [diff] [blame] | 461 | unsigned int rpm[5]; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 462 | u16 fan_min[5]; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 463 | u8 fan_div[5]; |
| 464 | u8 has_fan; /* some fan inputs can be disabled */ |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 465 | u8 has_fan_min; /* some fans don't have min register */ |
Guenter Roeck | 26bc440 | 2011-02-11 08:00:58 -0800 | [diff] [blame] | 466 | bool has_fan_div; |
Jean Delvare | da66736 | 2007-06-24 11:21:02 +0200 | [diff] [blame] | 467 | u8 temp_type[3]; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 468 | s16 temp[9]; |
| 469 | s16 temp_max[9]; |
| 470 | s16 temp_max_hyst[9]; |
Jean Delvare | a4589db | 2006-03-23 16:30:29 +0100 | [diff] [blame] | 471 | u32 alarms; |
Dmitry Artamonow | 363a12a | 2011-08-12 16:41:11 -0400 | [diff] [blame] | 472 | u8 caseopen; |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 473 | |
| 474 | u8 pwm_mode[4]; /* 0->DC variable voltage, 1->PWM variable duty cycle */ |
| 475 | u8 pwm_enable[4]; /* 1->manual |
Guenter Roeck | 8969e84 | 2012-01-19 11:02:27 -0800 | [diff] [blame^] | 476 | * 2->thermal cruise mode (also called SmartFan I) |
| 477 | * 3->fan speed cruise mode |
| 478 | * 4->variable thermal cruise (also called |
| 479 | * SmartFan III) |
| 480 | * 5->enhanced variable thermal cruise (also called |
| 481 | * SmartFan IV) |
| 482 | */ |
Guenter Roeck | b84bb51 | 2011-02-13 23:01:25 -0800 | [diff] [blame] | 483 | u8 pwm_enable_orig[4]; /* original value of pwm_enable */ |
Gong Jun | 237c8d2 | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 484 | u8 pwm_num; /* number of pwm */ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 485 | u8 pwm[4]; |
| 486 | u8 target_temp[4]; |
| 487 | u8 tolerance[4]; |
| 488 | |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 489 | u8 fan_start_output[4]; /* minimum fan speed when spinning up */ |
| 490 | u8 fan_stop_output[4]; /* minimum fan speed when spinning down */ |
| 491 | u8 fan_stop_time[4]; /* time at minimum before disabling fan */ |
| 492 | u8 fan_max_output[4]; /* maximum fan speed */ |
| 493 | u8 fan_step_output[4]; /* rate of change output value */ |
Jean Delvare | fc18d6c | 2007-06-24 11:19:42 +0200 | [diff] [blame] | 494 | |
| 495 | u8 vid; |
| 496 | u8 vrm; |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 497 | |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 498 | u16 have_temp; |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 499 | u8 in6_skip:1; |
| 500 | u8 temp3_val_only:1; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 501 | }; |
| 502 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 503 | struct w83627ehf_sio_data { |
| 504 | int sioreg; |
| 505 | enum kinds kind; |
| 506 | }; |
| 507 | |
Guenter Roeck | 83cc898 | 2011-02-06 08:10:15 -0800 | [diff] [blame] | 508 | /* |
| 509 | * On older chips, only registers 0x50-0x5f are banked. |
| 510 | * On more recent chips, all registers are banked. |
| 511 | * Assume that is the case and set the bank number for each access. |
| 512 | * Cache the bank number so it only needs to be set if it changes. |
| 513 | */ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 514 | static inline void w83627ehf_set_bank(struct w83627ehf_data *data, u16 reg) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 515 | { |
Guenter Roeck | 83cc898 | 2011-02-06 08:10:15 -0800 | [diff] [blame] | 516 | u8 bank = reg >> 8; |
| 517 | if (data->bank != bank) { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 518 | outb_p(W83627EHF_REG_BANK, data->addr + ADDR_REG_OFFSET); |
Guenter Roeck | 83cc898 | 2011-02-06 08:10:15 -0800 | [diff] [blame] | 519 | outb_p(bank, data->addr + DATA_REG_OFFSET); |
| 520 | data->bank = bank; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 521 | } |
| 522 | } |
| 523 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 524 | static u16 w83627ehf_read_value(struct w83627ehf_data *data, u16 reg) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 525 | { |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 526 | int res, word_sized = is_word_sized(reg); |
| 527 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 528 | mutex_lock(&data->lock); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 529 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 530 | w83627ehf_set_bank(data, reg); |
| 531 | outb_p(reg & 0xff, data->addr + ADDR_REG_OFFSET); |
| 532 | res = inb_p(data->addr + DATA_REG_OFFSET); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 533 | if (word_sized) { |
| 534 | outb_p((reg & 0xff) + 1, |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 535 | data->addr + ADDR_REG_OFFSET); |
| 536 | res = (res << 8) + inb_p(data->addr + DATA_REG_OFFSET); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 537 | } |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 538 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 539 | mutex_unlock(&data->lock); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 540 | return res; |
| 541 | } |
| 542 | |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 543 | static int w83627ehf_write_value(struct w83627ehf_data *data, u16 reg, |
| 544 | u16 value) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 545 | { |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 546 | int word_sized = is_word_sized(reg); |
| 547 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 548 | mutex_lock(&data->lock); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 549 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 550 | w83627ehf_set_bank(data, reg); |
| 551 | outb_p(reg & 0xff, data->addr + ADDR_REG_OFFSET); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 552 | if (word_sized) { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 553 | outb_p(value >> 8, data->addr + DATA_REG_OFFSET); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 554 | outb_p((reg & 0xff) + 1, |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 555 | data->addr + ADDR_REG_OFFSET); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 556 | } |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 557 | outb_p(value & 0xff, data->addr + DATA_REG_OFFSET); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 558 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 559 | mutex_unlock(&data->lock); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 560 | return 0; |
| 561 | } |
| 562 | |
Jean Delvare | c5794cf | 2011-10-20 03:13:31 -0400 | [diff] [blame] | 563 | /* We left-align 8-bit temperature values to make the code simpler */ |
| 564 | static u16 w83627ehf_read_temp(struct w83627ehf_data *data, u16 reg) |
| 565 | { |
| 566 | u16 res; |
| 567 | |
| 568 | res = w83627ehf_read_value(data, reg); |
| 569 | if (!is_word_sized(reg)) |
| 570 | res <<= 8; |
| 571 | |
| 572 | return res; |
| 573 | } |
| 574 | |
| 575 | static int w83627ehf_write_temp(struct w83627ehf_data *data, u16 reg, |
| 576 | u16 value) |
| 577 | { |
| 578 | if (!is_word_sized(reg)) |
| 579 | value >>= 8; |
| 580 | return w83627ehf_write_value(data, reg, value); |
| 581 | } |
| 582 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 583 | /* This function assumes that the caller holds data->update_lock */ |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 584 | static void nct6775_write_fan_div(struct w83627ehf_data *data, int nr) |
| 585 | { |
| 586 | u8 reg; |
| 587 | |
| 588 | switch (nr) { |
| 589 | case 0: |
| 590 | reg = (w83627ehf_read_value(data, NCT6775_REG_FANDIV1) & 0x70) |
| 591 | | (data->fan_div[0] & 0x7); |
| 592 | w83627ehf_write_value(data, NCT6775_REG_FANDIV1, reg); |
| 593 | break; |
| 594 | case 1: |
| 595 | reg = (w83627ehf_read_value(data, NCT6775_REG_FANDIV1) & 0x7) |
| 596 | | ((data->fan_div[1] << 4) & 0x70); |
| 597 | w83627ehf_write_value(data, NCT6775_REG_FANDIV1, reg); |
| 598 | case 2: |
| 599 | reg = (w83627ehf_read_value(data, NCT6775_REG_FANDIV2) & 0x70) |
| 600 | | (data->fan_div[2] & 0x7); |
| 601 | w83627ehf_write_value(data, NCT6775_REG_FANDIV2, reg); |
| 602 | break; |
| 603 | case 3: |
| 604 | reg = (w83627ehf_read_value(data, NCT6775_REG_FANDIV2) & 0x7) |
| 605 | | ((data->fan_div[3] << 4) & 0x70); |
| 606 | w83627ehf_write_value(data, NCT6775_REG_FANDIV2, reg); |
| 607 | break; |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | /* This function assumes that the caller holds data->update_lock */ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 612 | static void w83627ehf_write_fan_div(struct w83627ehf_data *data, int nr) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 613 | { |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 614 | u8 reg; |
| 615 | |
| 616 | switch (nr) { |
| 617 | case 0: |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 618 | reg = (w83627ehf_read_value(data, W83627EHF_REG_FANDIV1) & 0xcf) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 619 | | ((data->fan_div[0] & 0x03) << 4); |
Rudolf Marek | 14992c7 | 2006-10-08 22:02:09 +0200 | [diff] [blame] | 620 | /* fan5 input control bit is write only, compute the value */ |
| 621 | reg |= (data->has_fan & (1 << 4)) ? 1 : 0; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 622 | w83627ehf_write_value(data, W83627EHF_REG_FANDIV1, reg); |
| 623 | reg = (w83627ehf_read_value(data, W83627EHF_REG_VBAT) & 0xdf) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 624 | | ((data->fan_div[0] & 0x04) << 3); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 625 | w83627ehf_write_value(data, W83627EHF_REG_VBAT, reg); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 626 | break; |
| 627 | case 1: |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 628 | reg = (w83627ehf_read_value(data, W83627EHF_REG_FANDIV1) & 0x3f) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 629 | | ((data->fan_div[1] & 0x03) << 6); |
Rudolf Marek | 14992c7 | 2006-10-08 22:02:09 +0200 | [diff] [blame] | 630 | /* fan5 input control bit is write only, compute the value */ |
| 631 | reg |= (data->has_fan & (1 << 4)) ? 1 : 0; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 632 | w83627ehf_write_value(data, W83627EHF_REG_FANDIV1, reg); |
| 633 | reg = (w83627ehf_read_value(data, W83627EHF_REG_VBAT) & 0xbf) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 634 | | ((data->fan_div[1] & 0x04) << 4); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 635 | w83627ehf_write_value(data, W83627EHF_REG_VBAT, reg); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 636 | break; |
| 637 | case 2: |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 638 | reg = (w83627ehf_read_value(data, W83627EHF_REG_FANDIV2) & 0x3f) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 639 | | ((data->fan_div[2] & 0x03) << 6); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 640 | w83627ehf_write_value(data, W83627EHF_REG_FANDIV2, reg); |
| 641 | reg = (w83627ehf_read_value(data, W83627EHF_REG_VBAT) & 0x7f) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 642 | | ((data->fan_div[2] & 0x04) << 5); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 643 | w83627ehf_write_value(data, W83627EHF_REG_VBAT, reg); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 644 | break; |
| 645 | case 3: |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 646 | reg = (w83627ehf_read_value(data, W83627EHF_REG_DIODE) & 0xfc) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 647 | | (data->fan_div[3] & 0x03); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 648 | w83627ehf_write_value(data, W83627EHF_REG_DIODE, reg); |
| 649 | reg = (w83627ehf_read_value(data, W83627EHF_REG_SMI_OVT) & 0x7f) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 650 | | ((data->fan_div[3] & 0x04) << 5); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 651 | w83627ehf_write_value(data, W83627EHF_REG_SMI_OVT, reg); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 652 | break; |
| 653 | case 4: |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 654 | reg = (w83627ehf_read_value(data, W83627EHF_REG_DIODE) & 0x73) |
Jean Delvare | 33725ad | 2007-04-17 00:32:27 -0700 | [diff] [blame] | 655 | | ((data->fan_div[4] & 0x03) << 2) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 656 | | ((data->fan_div[4] & 0x04) << 5); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 657 | w83627ehf_write_value(data, W83627EHF_REG_DIODE, reg); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 658 | break; |
| 659 | } |
| 660 | } |
| 661 | |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 662 | static void w83627ehf_write_fan_div_common(struct device *dev, |
| 663 | struct w83627ehf_data *data, int nr) |
| 664 | { |
| 665 | struct w83627ehf_sio_data *sio_data = dev->platform_data; |
| 666 | |
| 667 | if (sio_data->kind == nct6776) |
| 668 | ; /* no dividers, do nothing */ |
| 669 | else if (sio_data->kind == nct6775) |
| 670 | nct6775_write_fan_div(data, nr); |
| 671 | else |
| 672 | w83627ehf_write_fan_div(data, nr); |
| 673 | } |
| 674 | |
| 675 | static void nct6775_update_fan_div(struct w83627ehf_data *data) |
| 676 | { |
| 677 | u8 i; |
| 678 | |
| 679 | i = w83627ehf_read_value(data, NCT6775_REG_FANDIV1); |
| 680 | data->fan_div[0] = i & 0x7; |
| 681 | data->fan_div[1] = (i & 0x70) >> 4; |
| 682 | i = w83627ehf_read_value(data, NCT6775_REG_FANDIV2); |
| 683 | data->fan_div[2] = i & 0x7; |
| 684 | if (data->has_fan & (1<<3)) |
| 685 | data->fan_div[3] = (i & 0x70) >> 4; |
| 686 | } |
| 687 | |
Mark M. Hoffman | ea7be66 | 2007-08-05 12:19:01 -0400 | [diff] [blame] | 688 | static void w83627ehf_update_fan_div(struct w83627ehf_data *data) |
| 689 | { |
| 690 | int i; |
| 691 | |
| 692 | i = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1); |
| 693 | data->fan_div[0] = (i >> 4) & 0x03; |
| 694 | data->fan_div[1] = (i >> 6) & 0x03; |
| 695 | i = w83627ehf_read_value(data, W83627EHF_REG_FANDIV2); |
| 696 | data->fan_div[2] = (i >> 6) & 0x03; |
| 697 | i = w83627ehf_read_value(data, W83627EHF_REG_VBAT); |
| 698 | data->fan_div[0] |= (i >> 3) & 0x04; |
| 699 | data->fan_div[1] |= (i >> 4) & 0x04; |
| 700 | data->fan_div[2] |= (i >> 5) & 0x04; |
| 701 | if (data->has_fan & ((1 << 3) | (1 << 4))) { |
| 702 | i = w83627ehf_read_value(data, W83627EHF_REG_DIODE); |
| 703 | data->fan_div[3] = i & 0x03; |
| 704 | data->fan_div[4] = ((i >> 2) & 0x03) |
| 705 | | ((i >> 5) & 0x04); |
| 706 | } |
| 707 | if (data->has_fan & (1 << 3)) { |
| 708 | i = w83627ehf_read_value(data, W83627EHF_REG_SMI_OVT); |
| 709 | data->fan_div[3] |= (i >> 5) & 0x04; |
| 710 | } |
| 711 | } |
| 712 | |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 713 | static void w83627ehf_update_fan_div_common(struct device *dev, |
| 714 | struct w83627ehf_data *data) |
| 715 | { |
| 716 | struct w83627ehf_sio_data *sio_data = dev->platform_data; |
| 717 | |
| 718 | if (sio_data->kind == nct6776) |
| 719 | ; /* no dividers, do nothing */ |
| 720 | else if (sio_data->kind == nct6775) |
| 721 | nct6775_update_fan_div(data); |
| 722 | else |
| 723 | w83627ehf_update_fan_div(data); |
| 724 | } |
| 725 | |
| 726 | static void nct6775_update_pwm(struct w83627ehf_data *data) |
| 727 | { |
| 728 | int i; |
| 729 | int pwmcfg, fanmodecfg; |
| 730 | |
| 731 | for (i = 0; i < data->pwm_num; i++) { |
| 732 | pwmcfg = w83627ehf_read_value(data, |
| 733 | W83627EHF_REG_PWM_ENABLE[i]); |
| 734 | fanmodecfg = w83627ehf_read_value(data, |
| 735 | NCT6775_REG_FAN_MODE[i]); |
| 736 | data->pwm_mode[i] = |
| 737 | ((pwmcfg >> W83627EHF_PWM_MODE_SHIFT[i]) & 1) ? 0 : 1; |
| 738 | data->pwm_enable[i] = ((fanmodecfg >> 4) & 7) + 1; |
| 739 | data->tolerance[i] = fanmodecfg & 0x0f; |
| 740 | data->pwm[i] = w83627ehf_read_value(data, data->REG_PWM[i]); |
| 741 | } |
| 742 | } |
| 743 | |
| 744 | static void w83627ehf_update_pwm(struct w83627ehf_data *data) |
| 745 | { |
| 746 | int i; |
| 747 | int pwmcfg = 0, tolerance = 0; /* shut up the compiler */ |
| 748 | |
| 749 | for (i = 0; i < data->pwm_num; i++) { |
| 750 | if (!(data->has_fan & (1 << i))) |
| 751 | continue; |
| 752 | |
| 753 | /* pwmcfg, tolerance mapped for i=0, i=1 to same reg */ |
| 754 | if (i != 1) { |
| 755 | pwmcfg = w83627ehf_read_value(data, |
| 756 | W83627EHF_REG_PWM_ENABLE[i]); |
| 757 | tolerance = w83627ehf_read_value(data, |
| 758 | W83627EHF_REG_TOLERANCE[i]); |
| 759 | } |
| 760 | data->pwm_mode[i] = |
| 761 | ((pwmcfg >> W83627EHF_PWM_MODE_SHIFT[i]) & 1) ? 0 : 1; |
| 762 | data->pwm_enable[i] = ((pwmcfg >> W83627EHF_PWM_ENABLE_SHIFT[i]) |
| 763 | & 3) + 1; |
| 764 | data->pwm[i] = w83627ehf_read_value(data, data->REG_PWM[i]); |
| 765 | |
| 766 | data->tolerance[i] = (tolerance >> (i == 1 ? 4 : 0)) & 0x0f; |
| 767 | } |
| 768 | } |
| 769 | |
| 770 | static void w83627ehf_update_pwm_common(struct device *dev, |
| 771 | struct w83627ehf_data *data) |
| 772 | { |
| 773 | struct w83627ehf_sio_data *sio_data = dev->platform_data; |
| 774 | |
| 775 | if (sio_data->kind == nct6775 || sio_data->kind == nct6776) |
| 776 | nct6775_update_pwm(data); |
| 777 | else |
| 778 | w83627ehf_update_pwm(data); |
| 779 | } |
| 780 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 781 | static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) |
| 782 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 783 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 784 | struct w83627ehf_sio_data *sio_data = dev->platform_data; |
| 785 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 786 | int i; |
| 787 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 788 | mutex_lock(&data->update_lock); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 789 | |
Jean Delvare | 6b3e464 | 2007-06-24 11:19:01 +0200 | [diff] [blame] | 790 | if (time_after(jiffies, data->last_updated + HZ + HZ/2) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 791 | || !data->valid) { |
| 792 | /* Fan clock dividers */ |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 793 | w83627ehf_update_fan_div_common(dev, data); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 794 | |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 795 | /* Measured voltages and limits */ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 796 | for (i = 0; i < data->in_num; i++) { |
Jean Delvare | 389ef65 | 2011-10-13 10:40:53 -0400 | [diff] [blame] | 797 | if ((i == 6) && data->in6_skip) |
| 798 | continue; |
| 799 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 800 | data->in[i] = w83627ehf_read_value(data, |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 801 | W83627EHF_REG_IN(i)); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 802 | data->in_min[i] = w83627ehf_read_value(data, |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 803 | W83627EHF_REG_IN_MIN(i)); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 804 | data->in_max[i] = w83627ehf_read_value(data, |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 805 | W83627EHF_REG_IN_MAX(i)); |
| 806 | } |
| 807 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 808 | /* Measured fan speeds and limits */ |
| 809 | for (i = 0; i < 5; i++) { |
Guenter Roeck | 3382a91 | 2011-02-13 13:08:23 -0800 | [diff] [blame] | 810 | u16 reg; |
| 811 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 812 | if (!(data->has_fan & (1 << i))) |
| 813 | continue; |
| 814 | |
Guenter Roeck | 3382a91 | 2011-02-13 13:08:23 -0800 | [diff] [blame] | 815 | reg = w83627ehf_read_value(data, data->REG_FAN[i]); |
| 816 | data->rpm[i] = data->fan_from_reg(reg, |
| 817 | data->fan_div[i]); |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 818 | |
| 819 | if (data->has_fan_min & (1 << i)) |
| 820 | data->fan_min[i] = w83627ehf_read_value(data, |
Guenter Roeck | 279af1a | 2011-02-13 22:34:47 -0800 | [diff] [blame] | 821 | data->REG_FAN_MIN[i]); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 822 | |
Guenter Roeck | 8969e84 | 2012-01-19 11:02:27 -0800 | [diff] [blame^] | 823 | /* |
| 824 | * If we failed to measure the fan speed and clock |
| 825 | * divider can be increased, let's try that for next |
| 826 | * time |
| 827 | */ |
Guenter Roeck | 26bc440 | 2011-02-11 08:00:58 -0800 | [diff] [blame] | 828 | if (data->has_fan_div |
Guenter Roeck | 3382a91 | 2011-02-13 13:08:23 -0800 | [diff] [blame] | 829 | && (reg >= 0xff || (sio_data->kind == nct6775 |
| 830 | && reg == 0x00)) |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 831 | && data->fan_div[i] < 0x07) { |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 832 | dev_dbg(dev, "Increasing fan%d " |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 833 | "clock divider from %u to %u\n", |
Jean Delvare | 33725ad | 2007-04-17 00:32:27 -0700 | [diff] [blame] | 834 | i + 1, div_from_reg(data->fan_div[i]), |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 835 | div_from_reg(data->fan_div[i] + 1)); |
| 836 | data->fan_div[i]++; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 837 | w83627ehf_write_fan_div_common(dev, data, i); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 838 | /* Preserve min limit if possible */ |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 839 | if ((data->has_fan_min & (1 << i)) |
| 840 | && data->fan_min[i] >= 2 |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 841 | && data->fan_min[i] != 255) |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 842 | w83627ehf_write_value(data, |
Guenter Roeck | 279af1a | 2011-02-13 22:34:47 -0800 | [diff] [blame] | 843 | data->REG_FAN_MIN[i], |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 844 | (data->fan_min[i] /= 2)); |
| 845 | } |
| 846 | } |
| 847 | |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 848 | w83627ehf_update_pwm_common(dev, data); |
| 849 | |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 850 | for (i = 0; i < data->pwm_num; i++) { |
| 851 | if (!(data->has_fan & (1 << i))) |
| 852 | continue; |
| 853 | |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 854 | data->fan_start_output[i] = |
| 855 | w83627ehf_read_value(data, |
| 856 | data->REG_FAN_START_OUTPUT[i]); |
| 857 | data->fan_stop_output[i] = |
| 858 | w83627ehf_read_value(data, |
| 859 | data->REG_FAN_STOP_OUTPUT[i]); |
| 860 | data->fan_stop_time[i] = |
| 861 | w83627ehf_read_value(data, |
| 862 | data->REG_FAN_STOP_TIME[i]); |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 863 | |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 864 | if (data->REG_FAN_MAX_OUTPUT && |
| 865 | data->REG_FAN_MAX_OUTPUT[i] != 0xff) |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 866 | data->fan_max_output[i] = |
| 867 | w83627ehf_read_value(data, |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 868 | data->REG_FAN_MAX_OUTPUT[i]); |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 869 | |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 870 | if (data->REG_FAN_STEP_OUTPUT && |
| 871 | data->REG_FAN_STEP_OUTPUT[i] != 0xff) |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 872 | data->fan_step_output[i] = |
| 873 | w83627ehf_read_value(data, |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 874 | data->REG_FAN_STEP_OUTPUT[i]); |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 875 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 876 | data->target_temp[i] = |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 877 | w83627ehf_read_value(data, |
Guenter Roeck | 279af1a | 2011-02-13 22:34:47 -0800 | [diff] [blame] | 878 | data->REG_TARGET[i]) & |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 879 | (data->pwm_mode[i] == 1 ? 0x7f : 0xff); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 880 | } |
| 881 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 882 | /* Measured temperatures and limits */ |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 883 | for (i = 0; i < NUM_REG_TEMP; i++) { |
| 884 | if (!(data->have_temp & (1 << i))) |
| 885 | continue; |
Jean Delvare | c5794cf | 2011-10-20 03:13:31 -0400 | [diff] [blame] | 886 | data->temp[i] = w83627ehf_read_temp(data, |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 887 | data->reg_temp[i]); |
| 888 | if (data->reg_temp_over[i]) |
| 889 | data->temp_max[i] |
Jean Delvare | c5794cf | 2011-10-20 03:13:31 -0400 | [diff] [blame] | 890 | = w83627ehf_read_temp(data, |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 891 | data->reg_temp_over[i]); |
| 892 | if (data->reg_temp_hyst[i]) |
| 893 | data->temp_max_hyst[i] |
Jean Delvare | c5794cf | 2011-10-20 03:13:31 -0400 | [diff] [blame] | 894 | = w83627ehf_read_temp(data, |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 895 | data->reg_temp_hyst[i]); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 896 | } |
| 897 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 898 | data->alarms = w83627ehf_read_value(data, |
Jean Delvare | a4589db | 2006-03-23 16:30:29 +0100 | [diff] [blame] | 899 | W83627EHF_REG_ALARM1) | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 900 | (w83627ehf_read_value(data, |
Jean Delvare | a4589db | 2006-03-23 16:30:29 +0100 | [diff] [blame] | 901 | W83627EHF_REG_ALARM2) << 8) | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 902 | (w83627ehf_read_value(data, |
Jean Delvare | a4589db | 2006-03-23 16:30:29 +0100 | [diff] [blame] | 903 | W83627EHF_REG_ALARM3) << 16); |
| 904 | |
Dmitry Artamonow | 363a12a | 2011-08-12 16:41:11 -0400 | [diff] [blame] | 905 | data->caseopen = w83627ehf_read_value(data, |
| 906 | W83627EHF_REG_CASEOPEN_DET); |
| 907 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 908 | data->last_updated = jiffies; |
| 909 | data->valid = 1; |
| 910 | } |
| 911 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 912 | mutex_unlock(&data->update_lock); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 913 | return data; |
| 914 | } |
| 915 | |
| 916 | /* |
| 917 | * Sysfs callback functions |
| 918 | */ |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 919 | #define show_in_reg(reg) \ |
| 920 | static ssize_t \ |
| 921 | show_##reg(struct device *dev, struct device_attribute *attr, \ |
| 922 | char *buf) \ |
| 923 | { \ |
| 924 | struct w83627ehf_data *data = w83627ehf_update_device(dev); \ |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 925 | struct sensor_device_attribute *sensor_attr = \ |
| 926 | to_sensor_dev_attr(attr); \ |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 927 | int nr = sensor_attr->index; \ |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 928 | return sprintf(buf, "%ld\n", in_from_reg(data->reg[nr], nr, \ |
| 929 | data->scale_in)); \ |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 930 | } |
| 931 | show_in_reg(in) |
| 932 | show_in_reg(in_min) |
| 933 | show_in_reg(in_max) |
| 934 | |
| 935 | #define store_in_reg(REG, reg) \ |
| 936 | static ssize_t \ |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 937 | store_in_##reg(struct device *dev, struct device_attribute *attr, \ |
| 938 | const char *buf, size_t count) \ |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 939 | { \ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 940 | struct w83627ehf_data *data = dev_get_drvdata(dev); \ |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 941 | struct sensor_device_attribute *sensor_attr = \ |
| 942 | to_sensor_dev_attr(attr); \ |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 943 | int nr = sensor_attr->index; \ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 944 | unsigned long val; \ |
| 945 | int err; \ |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 946 | err = kstrtoul(buf, 10, &val); \ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 947 | if (err < 0) \ |
| 948 | return err; \ |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 949 | mutex_lock(&data->update_lock); \ |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 950 | data->in_##reg[nr] = in_to_reg(val, nr, data->scale_in); \ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 951 | w83627ehf_write_value(data, W83627EHF_REG_IN_##REG(nr), \ |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 952 | data->in_##reg[nr]); \ |
| 953 | mutex_unlock(&data->update_lock); \ |
| 954 | return count; \ |
| 955 | } |
| 956 | |
| 957 | store_in_reg(MIN, min) |
| 958 | store_in_reg(MAX, max) |
| 959 | |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 960 | static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, |
| 961 | char *buf) |
Jean Delvare | a4589db | 2006-03-23 16:30:29 +0100 | [diff] [blame] | 962 | { |
| 963 | struct w83627ehf_data *data = w83627ehf_update_device(dev); |
| 964 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 965 | int nr = sensor_attr->index; |
| 966 | return sprintf(buf, "%u\n", (data->alarms >> nr) & 0x01); |
| 967 | } |
| 968 | |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 969 | static struct sensor_device_attribute sda_in_input[] = { |
| 970 | SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0), |
| 971 | SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1), |
| 972 | SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2), |
| 973 | SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3), |
| 974 | SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4), |
| 975 | SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5), |
| 976 | SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6), |
| 977 | SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7), |
| 978 | SENSOR_ATTR(in8_input, S_IRUGO, show_in, NULL, 8), |
| 979 | SENSOR_ATTR(in9_input, S_IRUGO, show_in, NULL, 9), |
| 980 | }; |
| 981 | |
Jean Delvare | a4589db | 2006-03-23 16:30:29 +0100 | [diff] [blame] | 982 | static struct sensor_device_attribute sda_in_alarm[] = { |
| 983 | SENSOR_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0), |
| 984 | SENSOR_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1), |
| 985 | SENSOR_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2), |
| 986 | SENSOR_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3), |
| 987 | SENSOR_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8), |
| 988 | SENSOR_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 21), |
| 989 | SENSOR_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 20), |
| 990 | SENSOR_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 16), |
| 991 | SENSOR_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 17), |
| 992 | SENSOR_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL, 19), |
| 993 | }; |
| 994 | |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 995 | static struct sensor_device_attribute sda_in_min[] = { |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 996 | SENSOR_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 0), |
| 997 | SENSOR_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 1), |
| 998 | SENSOR_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 2), |
| 999 | SENSOR_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 3), |
| 1000 | SENSOR_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 4), |
| 1001 | SENSOR_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 5), |
| 1002 | SENSOR_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 6), |
| 1003 | SENSOR_ATTR(in7_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 7), |
| 1004 | SENSOR_ATTR(in8_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 8), |
| 1005 | SENSOR_ATTR(in9_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 9), |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 1006 | }; |
| 1007 | |
| 1008 | static struct sensor_device_attribute sda_in_max[] = { |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 1009 | SENSOR_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 0), |
| 1010 | SENSOR_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 1), |
| 1011 | SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 2), |
| 1012 | SENSOR_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 3), |
| 1013 | SENSOR_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 4), |
| 1014 | SENSOR_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 5), |
| 1015 | SENSOR_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 6), |
| 1016 | SENSOR_ATTR(in7_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 7), |
| 1017 | SENSOR_ATTR(in8_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 8), |
| 1018 | SENSOR_ATTR(in9_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 9), |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 1019 | }; |
| 1020 | |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1021 | static ssize_t |
| 1022 | show_fan(struct device *dev, struct device_attribute *attr, char *buf) |
| 1023 | { |
| 1024 | struct w83627ehf_data *data = w83627ehf_update_device(dev); |
| 1025 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1026 | int nr = sensor_attr->index; |
Guenter Roeck | 3382a91 | 2011-02-13 13:08:23 -0800 | [diff] [blame] | 1027 | return sprintf(buf, "%d\n", data->rpm[nr]); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1028 | } |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1029 | |
| 1030 | static ssize_t |
| 1031 | show_fan_min(struct device *dev, struct device_attribute *attr, char *buf) |
| 1032 | { |
| 1033 | struct w83627ehf_data *data = w83627ehf_update_device(dev); |
| 1034 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1035 | int nr = sensor_attr->index; |
| 1036 | return sprintf(buf, "%d\n", |
Guenter Roeck | 26bc440 | 2011-02-11 08:00:58 -0800 | [diff] [blame] | 1037 | data->fan_from_reg_min(data->fan_min[nr], |
| 1038 | data->fan_div[nr])); |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1039 | } |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1040 | |
| 1041 | static ssize_t |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 1042 | show_fan_div(struct device *dev, struct device_attribute *attr, |
| 1043 | char *buf) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1044 | { |
| 1045 | struct w83627ehf_data *data = w83627ehf_update_device(dev); |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 1046 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1047 | int nr = sensor_attr->index; |
| 1048 | return sprintf(buf, "%u\n", div_from_reg(data->fan_div[nr])); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1049 | } |
| 1050 | |
| 1051 | static ssize_t |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 1052 | store_fan_min(struct device *dev, struct device_attribute *attr, |
| 1053 | const char *buf, size_t count) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1054 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1055 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 1056 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1057 | int nr = sensor_attr->index; |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1058 | unsigned long val; |
| 1059 | int err; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1060 | unsigned int reg; |
| 1061 | u8 new_div; |
| 1062 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1063 | err = kstrtoul(buf, 10, &val); |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1064 | if (err < 0) |
| 1065 | return err; |
| 1066 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1067 | mutex_lock(&data->update_lock); |
Guenter Roeck | 26bc440 | 2011-02-11 08:00:58 -0800 | [diff] [blame] | 1068 | if (!data->has_fan_div) { |
| 1069 | /* |
| 1070 | * Only NCT6776F for now, so we know that this is a 13 bit |
| 1071 | * register |
| 1072 | */ |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1073 | if (!val) { |
| 1074 | val = 0xff1f; |
| 1075 | } else { |
| 1076 | if (val > 1350000U) |
| 1077 | val = 135000U; |
| 1078 | val = 1350000U / val; |
| 1079 | val = (val & 0x1f) | ((val << 3) & 0xff00); |
| 1080 | } |
| 1081 | data->fan_min[nr] = val; |
| 1082 | goto done; /* Leave fan divider alone */ |
| 1083 | } |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1084 | if (!val) { |
| 1085 | /* No min limit, alarm disabled */ |
| 1086 | data->fan_min[nr] = 255; |
| 1087 | new_div = data->fan_div[nr]; /* No change */ |
| 1088 | dev_info(dev, "fan%u low limit and alarm disabled\n", nr + 1); |
| 1089 | } else if ((reg = 1350000U / val) >= 128 * 255) { |
Guenter Roeck | 8969e84 | 2012-01-19 11:02:27 -0800 | [diff] [blame^] | 1090 | /* |
| 1091 | * Speed below this value cannot possibly be represented, |
| 1092 | * even with the highest divider (128) |
| 1093 | */ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1094 | data->fan_min[nr] = 254; |
| 1095 | new_div = 7; /* 128 == (1 << 7) */ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1096 | dev_warn(dev, "fan%u low limit %lu below minimum %u, set to " |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1097 | "minimum\n", nr + 1, val, |
Guenter Roeck | 26bc440 | 2011-02-11 08:00:58 -0800 | [diff] [blame] | 1098 | data->fan_from_reg_min(254, 7)); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1099 | } else if (!reg) { |
Guenter Roeck | 8969e84 | 2012-01-19 11:02:27 -0800 | [diff] [blame^] | 1100 | /* |
| 1101 | * Speed above this value cannot possibly be represented, |
| 1102 | * even with the lowest divider (1) |
| 1103 | */ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1104 | data->fan_min[nr] = 1; |
| 1105 | new_div = 0; /* 1 == (1 << 0) */ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1106 | dev_warn(dev, "fan%u low limit %lu above maximum %u, set to " |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1107 | "maximum\n", nr + 1, val, |
Guenter Roeck | 26bc440 | 2011-02-11 08:00:58 -0800 | [diff] [blame] | 1108 | data->fan_from_reg_min(1, 0)); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1109 | } else { |
Guenter Roeck | 8969e84 | 2012-01-19 11:02:27 -0800 | [diff] [blame^] | 1110 | /* |
| 1111 | * Automatically pick the best divider, i.e. the one such |
| 1112 | * that the min limit will correspond to a register value |
| 1113 | * in the 96..192 range |
| 1114 | */ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1115 | new_div = 0; |
| 1116 | while (reg > 192 && new_div < 7) { |
| 1117 | reg >>= 1; |
| 1118 | new_div++; |
| 1119 | } |
| 1120 | data->fan_min[nr] = reg; |
| 1121 | } |
| 1122 | |
Guenter Roeck | 8969e84 | 2012-01-19 11:02:27 -0800 | [diff] [blame^] | 1123 | /* |
| 1124 | * Write both the fan clock divider (if it changed) and the new |
| 1125 | * fan min (unconditionally) |
| 1126 | */ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1127 | if (new_div != data->fan_div[nr]) { |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1128 | dev_dbg(dev, "fan%u clock divider changed from %u to %u\n", |
| 1129 | nr + 1, div_from_reg(data->fan_div[nr]), |
| 1130 | div_from_reg(new_div)); |
| 1131 | data->fan_div[nr] = new_div; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1132 | w83627ehf_write_fan_div_common(dev, data, nr); |
Jean Delvare | 6b3e464 | 2007-06-24 11:19:01 +0200 | [diff] [blame] | 1133 | /* Give the chip time to sample a new speed value */ |
| 1134 | data->last_updated = jiffies; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1135 | } |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1136 | done: |
Guenter Roeck | 279af1a | 2011-02-13 22:34:47 -0800 | [diff] [blame] | 1137 | w83627ehf_write_value(data, data->REG_FAN_MIN[nr], |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1138 | data->fan_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1139 | mutex_unlock(&data->update_lock); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1140 | |
| 1141 | return count; |
| 1142 | } |
| 1143 | |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 1144 | static struct sensor_device_attribute sda_fan_input[] = { |
| 1145 | SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0), |
| 1146 | SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1), |
| 1147 | SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2), |
| 1148 | SENSOR_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3), |
| 1149 | SENSOR_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 4), |
| 1150 | }; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1151 | |
Jean Delvare | a4589db | 2006-03-23 16:30:29 +0100 | [diff] [blame] | 1152 | static struct sensor_device_attribute sda_fan_alarm[] = { |
| 1153 | SENSOR_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6), |
| 1154 | SENSOR_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7), |
| 1155 | SENSOR_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11), |
| 1156 | SENSOR_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 10), |
| 1157 | SENSOR_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 23), |
| 1158 | }; |
| 1159 | |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 1160 | static struct sensor_device_attribute sda_fan_min[] = { |
| 1161 | SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, |
| 1162 | store_fan_min, 0), |
| 1163 | SENSOR_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min, |
| 1164 | store_fan_min, 1), |
| 1165 | SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, |
| 1166 | store_fan_min, 2), |
| 1167 | SENSOR_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min, |
| 1168 | store_fan_min, 3), |
| 1169 | SENSOR_ATTR(fan5_min, S_IWUSR | S_IRUGO, show_fan_min, |
| 1170 | store_fan_min, 4), |
| 1171 | }; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1172 | |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 1173 | static struct sensor_device_attribute sda_fan_div[] = { |
| 1174 | SENSOR_ATTR(fan1_div, S_IRUGO, show_fan_div, NULL, 0), |
| 1175 | SENSOR_ATTR(fan2_div, S_IRUGO, show_fan_div, NULL, 1), |
| 1176 | SENSOR_ATTR(fan3_div, S_IRUGO, show_fan_div, NULL, 2), |
| 1177 | SENSOR_ATTR(fan4_div, S_IRUGO, show_fan_div, NULL, 3), |
| 1178 | SENSOR_ATTR(fan5_div, S_IRUGO, show_fan_div, NULL, 4), |
| 1179 | }; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1180 | |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 1181 | static ssize_t |
| 1182 | show_temp_label(struct device *dev, struct device_attribute *attr, char *buf) |
| 1183 | { |
| 1184 | struct w83627ehf_data *data = w83627ehf_update_device(dev); |
| 1185 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1186 | int nr = sensor_attr->index; |
| 1187 | return sprintf(buf, "%s\n", data->temp_label[data->temp_src[nr]]); |
| 1188 | } |
| 1189 | |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1190 | #define show_temp_reg(addr, reg) \ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1191 | static ssize_t \ |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 1192 | show_##reg(struct device *dev, struct device_attribute *attr, \ |
| 1193 | char *buf) \ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1194 | { \ |
| 1195 | struct w83627ehf_data *data = w83627ehf_update_device(dev); \ |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 1196 | struct sensor_device_attribute *sensor_attr = \ |
| 1197 | to_sensor_dev_attr(attr); \ |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 1198 | int nr = sensor_attr->index; \ |
Jean Delvare | c5794cf | 2011-10-20 03:13:31 -0400 | [diff] [blame] | 1199 | return sprintf(buf, "%d\n", LM75_TEMP_FROM_REG(data->reg[nr])); \ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1200 | } |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1201 | show_temp_reg(reg_temp, temp); |
| 1202 | show_temp_reg(reg_temp_over, temp_max); |
| 1203 | show_temp_reg(reg_temp_hyst, temp_max_hyst); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1204 | |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1205 | #define store_temp_reg(addr, reg) \ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1206 | static ssize_t \ |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 1207 | store_##reg(struct device *dev, struct device_attribute *attr, \ |
| 1208 | const char *buf, size_t count) \ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1209 | { \ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1210 | struct w83627ehf_data *data = dev_get_drvdata(dev); \ |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 1211 | struct sensor_device_attribute *sensor_attr = \ |
| 1212 | to_sensor_dev_attr(attr); \ |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 1213 | int nr = sensor_attr->index; \ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1214 | int err; \ |
| 1215 | long val; \ |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1216 | err = kstrtol(buf, 10, &val); \ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1217 | if (err < 0) \ |
| 1218 | return err; \ |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1219 | mutex_lock(&data->update_lock); \ |
Jean Delvare | c5794cf | 2011-10-20 03:13:31 -0400 | [diff] [blame] | 1220 | data->reg[nr] = LM75_TEMP_TO_REG(val); \ |
| 1221 | w83627ehf_write_temp(data, data->addr[nr], data->reg[nr]); \ |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1222 | mutex_unlock(&data->update_lock); \ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1223 | return count; \ |
| 1224 | } |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1225 | store_temp_reg(reg_temp_over, temp_max); |
| 1226 | store_temp_reg(reg_temp_hyst, temp_max_hyst); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1227 | |
Jean Delvare | da66736 | 2007-06-24 11:21:02 +0200 | [diff] [blame] | 1228 | static ssize_t |
| 1229 | show_temp_type(struct device *dev, struct device_attribute *attr, char *buf) |
| 1230 | { |
| 1231 | struct w83627ehf_data *data = w83627ehf_update_device(dev); |
| 1232 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1233 | int nr = sensor_attr->index; |
| 1234 | return sprintf(buf, "%d\n", (int)data->temp_type[nr]); |
| 1235 | } |
| 1236 | |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1237 | static struct sensor_device_attribute sda_temp_input[] = { |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1238 | SENSOR_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0), |
| 1239 | SENSOR_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1), |
| 1240 | SENSOR_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2), |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 1241 | SENSOR_ATTR(temp4_input, S_IRUGO, show_temp, NULL, 3), |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1242 | SENSOR_ATTR(temp5_input, S_IRUGO, show_temp, NULL, 4), |
| 1243 | SENSOR_ATTR(temp6_input, S_IRUGO, show_temp, NULL, 5), |
| 1244 | SENSOR_ATTR(temp7_input, S_IRUGO, show_temp, NULL, 6), |
| 1245 | SENSOR_ATTR(temp8_input, S_IRUGO, show_temp, NULL, 7), |
| 1246 | SENSOR_ATTR(temp9_input, S_IRUGO, show_temp, NULL, 8), |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 1247 | }; |
| 1248 | |
| 1249 | static struct sensor_device_attribute sda_temp_label[] = { |
| 1250 | SENSOR_ATTR(temp1_label, S_IRUGO, show_temp_label, NULL, 0), |
| 1251 | SENSOR_ATTR(temp2_label, S_IRUGO, show_temp_label, NULL, 1), |
| 1252 | SENSOR_ATTR(temp3_label, S_IRUGO, show_temp_label, NULL, 2), |
| 1253 | SENSOR_ATTR(temp4_label, S_IRUGO, show_temp_label, NULL, 3), |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1254 | SENSOR_ATTR(temp5_label, S_IRUGO, show_temp_label, NULL, 4), |
| 1255 | SENSOR_ATTR(temp6_label, S_IRUGO, show_temp_label, NULL, 5), |
| 1256 | SENSOR_ATTR(temp7_label, S_IRUGO, show_temp_label, NULL, 6), |
| 1257 | SENSOR_ATTR(temp8_label, S_IRUGO, show_temp_label, NULL, 7), |
| 1258 | SENSOR_ATTR(temp9_label, S_IRUGO, show_temp_label, NULL, 8), |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1259 | }; |
| 1260 | |
| 1261 | static struct sensor_device_attribute sda_temp_max[] = { |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1262 | SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp_max, |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 1263 | store_temp_max, 0), |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1264 | SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR, show_temp_max, |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 1265 | store_temp_max, 1), |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1266 | SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR, show_temp_max, |
| 1267 | store_temp_max, 2), |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1268 | SENSOR_ATTR(temp4_max, S_IRUGO | S_IWUSR, show_temp_max, |
| 1269 | store_temp_max, 3), |
| 1270 | SENSOR_ATTR(temp5_max, S_IRUGO | S_IWUSR, show_temp_max, |
| 1271 | store_temp_max, 4), |
| 1272 | SENSOR_ATTR(temp6_max, S_IRUGO | S_IWUSR, show_temp_max, |
| 1273 | store_temp_max, 5), |
| 1274 | SENSOR_ATTR(temp7_max, S_IRUGO | S_IWUSR, show_temp_max, |
| 1275 | store_temp_max, 6), |
| 1276 | SENSOR_ATTR(temp8_max, S_IRUGO | S_IWUSR, show_temp_max, |
| 1277 | store_temp_max, 7), |
| 1278 | SENSOR_ATTR(temp9_max, S_IRUGO | S_IWUSR, show_temp_max, |
| 1279 | store_temp_max, 8), |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1280 | }; |
| 1281 | |
| 1282 | static struct sensor_device_attribute sda_temp_max_hyst[] = { |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1283 | SENSOR_ATTR(temp1_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst, |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 1284 | store_temp_max_hyst, 0), |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1285 | SENSOR_ATTR(temp2_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst, |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 1286 | store_temp_max_hyst, 1), |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1287 | SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst, |
| 1288 | store_temp_max_hyst, 2), |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1289 | SENSOR_ATTR(temp4_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst, |
| 1290 | store_temp_max_hyst, 3), |
| 1291 | SENSOR_ATTR(temp5_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst, |
| 1292 | store_temp_max_hyst, 4), |
| 1293 | SENSOR_ATTR(temp6_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst, |
| 1294 | store_temp_max_hyst, 5), |
| 1295 | SENSOR_ATTR(temp7_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst, |
| 1296 | store_temp_max_hyst, 6), |
| 1297 | SENSOR_ATTR(temp8_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst, |
| 1298 | store_temp_max_hyst, 7), |
| 1299 | SENSOR_ATTR(temp9_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst, |
| 1300 | store_temp_max_hyst, 8), |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1301 | }; |
| 1302 | |
| 1303 | static struct sensor_device_attribute sda_temp_alarm[] = { |
Jean Delvare | a4589db | 2006-03-23 16:30:29 +0100 | [diff] [blame] | 1304 | SENSOR_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4), |
| 1305 | SENSOR_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5), |
| 1306 | SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13), |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1307 | }; |
| 1308 | |
| 1309 | static struct sensor_device_attribute sda_temp_type[] = { |
Jean Delvare | da66736 | 2007-06-24 11:21:02 +0200 | [diff] [blame] | 1310 | SENSOR_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0), |
| 1311 | SENSOR_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1), |
| 1312 | SENSOR_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2), |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 1313 | }; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1314 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1315 | #define show_pwm_reg(reg) \ |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 1316 | static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ |
| 1317 | char *buf) \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1318 | { \ |
| 1319 | struct w83627ehf_data *data = w83627ehf_update_device(dev); \ |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 1320 | struct sensor_device_attribute *sensor_attr = \ |
| 1321 | to_sensor_dev_attr(attr); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1322 | int nr = sensor_attr->index; \ |
| 1323 | return sprintf(buf, "%d\n", data->reg[nr]); \ |
| 1324 | } |
| 1325 | |
| 1326 | show_pwm_reg(pwm_mode) |
| 1327 | show_pwm_reg(pwm_enable) |
| 1328 | show_pwm_reg(pwm) |
| 1329 | |
| 1330 | static ssize_t |
| 1331 | store_pwm_mode(struct device *dev, struct device_attribute *attr, |
| 1332 | const char *buf, size_t count) |
| 1333 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1334 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1335 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
Guenter Roeck | ad77c3e | 2012-01-27 17:56:06 -0800 | [diff] [blame] | 1336 | struct w83627ehf_sio_data *sio_data = dev->platform_data; |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1337 | int nr = sensor_attr->index; |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1338 | unsigned long val; |
| 1339 | int err; |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1340 | u16 reg; |
| 1341 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1342 | err = kstrtoul(buf, 10, &val); |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1343 | if (err < 0) |
| 1344 | return err; |
| 1345 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1346 | if (val > 1) |
| 1347 | return -EINVAL; |
Guenter Roeck | ad77c3e | 2012-01-27 17:56:06 -0800 | [diff] [blame] | 1348 | |
| 1349 | /* On NCT67766F, DC mode is only supported for pwm1 */ |
| 1350 | if (sio_data->kind == nct6776 && nr && val != 1) |
| 1351 | return -EINVAL; |
| 1352 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1353 | mutex_lock(&data->update_lock); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1354 | reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[nr]); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1355 | data->pwm_mode[nr] = val; |
| 1356 | reg &= ~(1 << W83627EHF_PWM_MODE_SHIFT[nr]); |
| 1357 | if (!val) |
| 1358 | reg |= 1 << W83627EHF_PWM_MODE_SHIFT[nr]; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1359 | w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[nr], reg); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1360 | mutex_unlock(&data->update_lock); |
| 1361 | return count; |
| 1362 | } |
| 1363 | |
| 1364 | static ssize_t |
| 1365 | store_pwm(struct device *dev, struct device_attribute *attr, |
| 1366 | const char *buf, size_t count) |
| 1367 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1368 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1369 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1370 | int nr = sensor_attr->index; |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1371 | unsigned long val; |
| 1372 | int err; |
| 1373 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1374 | err = kstrtoul(buf, 10, &val); |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1375 | if (err < 0) |
| 1376 | return err; |
| 1377 | |
| 1378 | val = SENSORS_LIMIT(val, 0, 255); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1379 | |
| 1380 | mutex_lock(&data->update_lock); |
| 1381 | data->pwm[nr] = val; |
Guenter Roeck | 279af1a | 2011-02-13 22:34:47 -0800 | [diff] [blame] | 1382 | w83627ehf_write_value(data, data->REG_PWM[nr], val); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1383 | mutex_unlock(&data->update_lock); |
| 1384 | return count; |
| 1385 | } |
| 1386 | |
| 1387 | static ssize_t |
| 1388 | store_pwm_enable(struct device *dev, struct device_attribute *attr, |
| 1389 | const char *buf, size_t count) |
| 1390 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1391 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1392 | struct w83627ehf_sio_data *sio_data = dev->platform_data; |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1393 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1394 | int nr = sensor_attr->index; |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1395 | unsigned long val; |
| 1396 | int err; |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1397 | u16 reg; |
| 1398 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1399 | err = kstrtoul(buf, 10, &val); |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1400 | if (err < 0) |
| 1401 | return err; |
| 1402 | |
Guenter Roeck | b84bb51 | 2011-02-13 23:01:25 -0800 | [diff] [blame] | 1403 | if (!val || (val > 4 && val != data->pwm_enable_orig[nr])) |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1404 | return -EINVAL; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1405 | /* SmartFan III mode is not supported on NCT6776F */ |
| 1406 | if (sio_data->kind == nct6776 && val == 4) |
| 1407 | return -EINVAL; |
| 1408 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1409 | mutex_lock(&data->update_lock); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1410 | data->pwm_enable[nr] = val; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1411 | if (sio_data->kind == nct6775 || sio_data->kind == nct6776) { |
| 1412 | reg = w83627ehf_read_value(data, |
| 1413 | NCT6775_REG_FAN_MODE[nr]); |
| 1414 | reg &= 0x0f; |
| 1415 | reg |= (val - 1) << 4; |
| 1416 | w83627ehf_write_value(data, |
| 1417 | NCT6775_REG_FAN_MODE[nr], reg); |
| 1418 | } else { |
| 1419 | reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[nr]); |
| 1420 | reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[nr]); |
| 1421 | reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[nr]; |
| 1422 | w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[nr], reg); |
| 1423 | } |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1424 | mutex_unlock(&data->update_lock); |
| 1425 | return count; |
| 1426 | } |
| 1427 | |
| 1428 | |
| 1429 | #define show_tol_temp(reg) \ |
| 1430 | static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ |
| 1431 | char *buf) \ |
| 1432 | { \ |
| 1433 | struct w83627ehf_data *data = w83627ehf_update_device(dev); \ |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 1434 | struct sensor_device_attribute *sensor_attr = \ |
| 1435 | to_sensor_dev_attr(attr); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1436 | int nr = sensor_attr->index; \ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1437 | return sprintf(buf, "%d\n", data->reg[nr] * 1000); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | show_tol_temp(tolerance) |
| 1441 | show_tol_temp(target_temp) |
| 1442 | |
| 1443 | static ssize_t |
| 1444 | store_target_temp(struct device *dev, struct device_attribute *attr, |
| 1445 | const char *buf, size_t count) |
| 1446 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1447 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1448 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1449 | int nr = sensor_attr->index; |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1450 | long val; |
| 1451 | int err; |
| 1452 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1453 | err = kstrtol(buf, 10, &val); |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1454 | if (err < 0) |
| 1455 | return err; |
| 1456 | |
| 1457 | val = SENSORS_LIMIT(DIV_ROUND_CLOSEST(val, 1000), 0, 127); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1458 | |
| 1459 | mutex_lock(&data->update_lock); |
| 1460 | data->target_temp[nr] = val; |
Guenter Roeck | 279af1a | 2011-02-13 22:34:47 -0800 | [diff] [blame] | 1461 | w83627ehf_write_value(data, data->REG_TARGET[nr], val); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1462 | mutex_unlock(&data->update_lock); |
| 1463 | return count; |
| 1464 | } |
| 1465 | |
| 1466 | static ssize_t |
| 1467 | store_tolerance(struct device *dev, struct device_attribute *attr, |
| 1468 | const char *buf, size_t count) |
| 1469 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1470 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1471 | struct w83627ehf_sio_data *sio_data = dev->platform_data; |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1472 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1473 | int nr = sensor_attr->index; |
| 1474 | u16 reg; |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1475 | long val; |
| 1476 | int err; |
| 1477 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1478 | err = kstrtol(buf, 10, &val); |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1479 | if (err < 0) |
| 1480 | return err; |
| 1481 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1482 | /* Limit the temp to 0C - 15C */ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1483 | val = SENSORS_LIMIT(DIV_ROUND_CLOSEST(val, 1000), 0, 15); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1484 | |
| 1485 | mutex_lock(&data->update_lock); |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1486 | if (sio_data->kind == nct6775 || sio_data->kind == nct6776) { |
| 1487 | /* Limit tolerance further for NCT6776F */ |
| 1488 | if (sio_data->kind == nct6776 && val > 7) |
| 1489 | val = 7; |
| 1490 | reg = w83627ehf_read_value(data, NCT6775_REG_FAN_MODE[nr]); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1491 | reg = (reg & 0xf0) | val; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1492 | w83627ehf_write_value(data, NCT6775_REG_FAN_MODE[nr], reg); |
| 1493 | } else { |
| 1494 | reg = w83627ehf_read_value(data, W83627EHF_REG_TOLERANCE[nr]); |
| 1495 | if (nr == 1) |
| 1496 | reg = (reg & 0x0f) | (val << 4); |
| 1497 | else |
| 1498 | reg = (reg & 0xf0) | val; |
| 1499 | w83627ehf_write_value(data, W83627EHF_REG_TOLERANCE[nr], reg); |
| 1500 | } |
| 1501 | data->tolerance[nr] = val; |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1502 | mutex_unlock(&data->update_lock); |
| 1503 | return count; |
| 1504 | } |
| 1505 | |
| 1506 | static struct sensor_device_attribute sda_pwm[] = { |
| 1507 | SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0), |
| 1508 | SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1), |
| 1509 | SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2), |
| 1510 | SENSOR_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 3), |
| 1511 | }; |
| 1512 | |
| 1513 | static struct sensor_device_attribute sda_pwm_mode[] = { |
| 1514 | SENSOR_ATTR(pwm1_mode, S_IWUSR | S_IRUGO, show_pwm_mode, |
| 1515 | store_pwm_mode, 0), |
| 1516 | SENSOR_ATTR(pwm2_mode, S_IWUSR | S_IRUGO, show_pwm_mode, |
| 1517 | store_pwm_mode, 1), |
| 1518 | SENSOR_ATTR(pwm3_mode, S_IWUSR | S_IRUGO, show_pwm_mode, |
| 1519 | store_pwm_mode, 2), |
| 1520 | SENSOR_ATTR(pwm4_mode, S_IWUSR | S_IRUGO, show_pwm_mode, |
| 1521 | store_pwm_mode, 3), |
| 1522 | }; |
| 1523 | |
| 1524 | static struct sensor_device_attribute sda_pwm_enable[] = { |
| 1525 | SENSOR_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_enable, |
| 1526 | store_pwm_enable, 0), |
| 1527 | SENSOR_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_enable, |
| 1528 | store_pwm_enable, 1), |
| 1529 | SENSOR_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_enable, |
| 1530 | store_pwm_enable, 2), |
| 1531 | SENSOR_ATTR(pwm4_enable, S_IWUSR | S_IRUGO, show_pwm_enable, |
| 1532 | store_pwm_enable, 3), |
| 1533 | }; |
| 1534 | |
| 1535 | static struct sensor_device_attribute sda_target_temp[] = { |
| 1536 | SENSOR_ATTR(pwm1_target, S_IWUSR | S_IRUGO, show_target_temp, |
| 1537 | store_target_temp, 0), |
| 1538 | SENSOR_ATTR(pwm2_target, S_IWUSR | S_IRUGO, show_target_temp, |
| 1539 | store_target_temp, 1), |
| 1540 | SENSOR_ATTR(pwm3_target, S_IWUSR | S_IRUGO, show_target_temp, |
| 1541 | store_target_temp, 2), |
| 1542 | SENSOR_ATTR(pwm4_target, S_IWUSR | S_IRUGO, show_target_temp, |
| 1543 | store_target_temp, 3), |
| 1544 | }; |
| 1545 | |
| 1546 | static struct sensor_device_attribute sda_tolerance[] = { |
| 1547 | SENSOR_ATTR(pwm1_tolerance, S_IWUSR | S_IRUGO, show_tolerance, |
| 1548 | store_tolerance, 0), |
| 1549 | SENSOR_ATTR(pwm2_tolerance, S_IWUSR | S_IRUGO, show_tolerance, |
| 1550 | store_tolerance, 1), |
| 1551 | SENSOR_ATTR(pwm3_tolerance, S_IWUSR | S_IRUGO, show_tolerance, |
| 1552 | store_tolerance, 2), |
| 1553 | SENSOR_ATTR(pwm4_tolerance, S_IWUSR | S_IRUGO, show_tolerance, |
| 1554 | store_tolerance, 3), |
| 1555 | }; |
| 1556 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1557 | /* Smart Fan registers */ |
| 1558 | |
| 1559 | #define fan_functions(reg, REG) \ |
| 1560 | static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ |
| 1561 | char *buf) \ |
| 1562 | { \ |
| 1563 | struct w83627ehf_data *data = w83627ehf_update_device(dev); \ |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 1564 | struct sensor_device_attribute *sensor_attr = \ |
| 1565 | to_sensor_dev_attr(attr); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1566 | int nr = sensor_attr->index; \ |
| 1567 | return sprintf(buf, "%d\n", data->reg[nr]); \ |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 1568 | } \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1569 | static ssize_t \ |
| 1570 | store_##reg(struct device *dev, struct device_attribute *attr, \ |
| 1571 | const char *buf, size_t count) \ |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 1572 | { \ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1573 | struct w83627ehf_data *data = dev_get_drvdata(dev); \ |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 1574 | struct sensor_device_attribute *sensor_attr = \ |
| 1575 | to_sensor_dev_attr(attr); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1576 | int nr = sensor_attr->index; \ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1577 | unsigned long val; \ |
| 1578 | int err; \ |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1579 | err = kstrtoul(buf, 10, &val); \ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1580 | if (err < 0) \ |
| 1581 | return err; \ |
| 1582 | val = SENSORS_LIMIT(val, 1, 255); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1583 | mutex_lock(&data->update_lock); \ |
| 1584 | data->reg[nr] = val; \ |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1585 | w83627ehf_write_value(data, data->REG_##REG[nr], val); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1586 | mutex_unlock(&data->update_lock); \ |
| 1587 | return count; \ |
| 1588 | } |
| 1589 | |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 1590 | fan_functions(fan_start_output, FAN_START_OUTPUT) |
| 1591 | fan_functions(fan_stop_output, FAN_STOP_OUTPUT) |
| 1592 | fan_functions(fan_max_output, FAN_MAX_OUTPUT) |
| 1593 | fan_functions(fan_step_output, FAN_STEP_OUTPUT) |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1594 | |
| 1595 | #define fan_time_functions(reg, REG) \ |
| 1596 | static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ |
| 1597 | char *buf) \ |
| 1598 | { \ |
| 1599 | struct w83627ehf_data *data = w83627ehf_update_device(dev); \ |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 1600 | struct sensor_device_attribute *sensor_attr = \ |
| 1601 | to_sensor_dev_attr(attr); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1602 | int nr = sensor_attr->index; \ |
| 1603 | return sprintf(buf, "%d\n", \ |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 1604 | step_time_from_reg(data->reg[nr], \ |
| 1605 | data->pwm_mode[nr])); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1606 | } \ |
| 1607 | \ |
| 1608 | static ssize_t \ |
| 1609 | store_##reg(struct device *dev, struct device_attribute *attr, \ |
| 1610 | const char *buf, size_t count) \ |
| 1611 | { \ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1612 | struct w83627ehf_data *data = dev_get_drvdata(dev); \ |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 1613 | struct sensor_device_attribute *sensor_attr = \ |
| 1614 | to_sensor_dev_attr(attr); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1615 | int nr = sensor_attr->index; \ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1616 | unsigned long val; \ |
| 1617 | int err; \ |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1618 | err = kstrtoul(buf, 10, &val); \ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame] | 1619 | if (err < 0) \ |
| 1620 | return err; \ |
| 1621 | val = step_time_to_reg(val, data->pwm_mode[nr]); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1622 | mutex_lock(&data->update_lock); \ |
| 1623 | data->reg[nr] = val; \ |
Guenter Roeck | 33fa9b6 | 2012-03-12 08:21:16 -0700 | [diff] [blame] | 1624 | w83627ehf_write_value(data, data->REG_##REG[nr], val); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1625 | mutex_unlock(&data->update_lock); \ |
| 1626 | return count; \ |
| 1627 | } \ |
| 1628 | |
| 1629 | fan_time_functions(fan_stop_time, FAN_STOP_TIME) |
| 1630 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1631 | static ssize_t show_name(struct device *dev, struct device_attribute *attr, |
| 1632 | char *buf) |
| 1633 | { |
| 1634 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
| 1635 | |
| 1636 | return sprintf(buf, "%s\n", data->name); |
| 1637 | } |
| 1638 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1639 | |
| 1640 | static struct sensor_device_attribute sda_sf3_arrays_fan4[] = { |
| 1641 | SENSOR_ATTR(pwm4_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time, |
| 1642 | store_fan_stop_time, 3), |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 1643 | SENSOR_ATTR(pwm4_start_output, S_IWUSR | S_IRUGO, show_fan_start_output, |
| 1644 | store_fan_start_output, 3), |
| 1645 | SENSOR_ATTR(pwm4_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output, |
| 1646 | store_fan_stop_output, 3), |
| 1647 | SENSOR_ATTR(pwm4_max_output, S_IWUSR | S_IRUGO, show_fan_max_output, |
| 1648 | store_fan_max_output, 3), |
| 1649 | SENSOR_ATTR(pwm4_step_output, S_IWUSR | S_IRUGO, show_fan_step_output, |
| 1650 | store_fan_step_output, 3), |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1651 | }; |
| 1652 | |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 1653 | static struct sensor_device_attribute sda_sf3_arrays_fan3[] = { |
| 1654 | SENSOR_ATTR(pwm3_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time, |
| 1655 | store_fan_stop_time, 2), |
| 1656 | SENSOR_ATTR(pwm3_start_output, S_IWUSR | S_IRUGO, show_fan_start_output, |
| 1657 | store_fan_start_output, 2), |
| 1658 | SENSOR_ATTR(pwm3_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output, |
| 1659 | store_fan_stop_output, 2), |
| 1660 | }; |
| 1661 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1662 | static struct sensor_device_attribute sda_sf3_arrays[] = { |
| 1663 | SENSOR_ATTR(pwm1_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time, |
| 1664 | store_fan_stop_time, 0), |
| 1665 | SENSOR_ATTR(pwm2_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time, |
| 1666 | store_fan_stop_time, 1), |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 1667 | SENSOR_ATTR(pwm1_start_output, S_IWUSR | S_IRUGO, show_fan_start_output, |
| 1668 | store_fan_start_output, 0), |
| 1669 | SENSOR_ATTR(pwm2_start_output, S_IWUSR | S_IRUGO, show_fan_start_output, |
| 1670 | store_fan_start_output, 1), |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 1671 | SENSOR_ATTR(pwm1_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output, |
| 1672 | store_fan_stop_output, 0), |
| 1673 | SENSOR_ATTR(pwm2_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output, |
| 1674 | store_fan_stop_output, 1), |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1675 | }; |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 1676 | |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1677 | |
| 1678 | /* |
| 1679 | * pwm1 and pwm3 don't support max and step settings on all chips. |
| 1680 | * Need to check support while generating/removing attribute files. |
| 1681 | */ |
| 1682 | static struct sensor_device_attribute sda_sf3_max_step_arrays[] = { |
| 1683 | SENSOR_ATTR(pwm1_max_output, S_IWUSR | S_IRUGO, show_fan_max_output, |
| 1684 | store_fan_max_output, 0), |
| 1685 | SENSOR_ATTR(pwm1_step_output, S_IWUSR | S_IRUGO, show_fan_step_output, |
| 1686 | store_fan_step_output, 0), |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 1687 | SENSOR_ATTR(pwm2_max_output, S_IWUSR | S_IRUGO, show_fan_max_output, |
| 1688 | store_fan_max_output, 1), |
| 1689 | SENSOR_ATTR(pwm2_step_output, S_IWUSR | S_IRUGO, show_fan_step_output, |
| 1690 | store_fan_step_output, 1), |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1691 | SENSOR_ATTR(pwm3_max_output, S_IWUSR | S_IRUGO, show_fan_max_output, |
| 1692 | store_fan_max_output, 2), |
| 1693 | SENSOR_ATTR(pwm3_step_output, S_IWUSR | S_IRUGO, show_fan_step_output, |
| 1694 | store_fan_step_output, 2), |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1695 | }; |
| 1696 | |
Jean Delvare | fc18d6c | 2007-06-24 11:19:42 +0200 | [diff] [blame] | 1697 | static ssize_t |
| 1698 | show_vid(struct device *dev, struct device_attribute *attr, char *buf) |
| 1699 | { |
| 1700 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
| 1701 | return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); |
| 1702 | } |
| 1703 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); |
| 1704 | |
Dmitry Artamonow | 363a12a | 2011-08-12 16:41:11 -0400 | [diff] [blame] | 1705 | |
| 1706 | /* Case open detection */ |
| 1707 | |
| 1708 | static ssize_t |
| 1709 | show_caseopen(struct device *dev, struct device_attribute *attr, char *buf) |
| 1710 | { |
| 1711 | struct w83627ehf_data *data = w83627ehf_update_device(dev); |
| 1712 | |
| 1713 | return sprintf(buf, "%d\n", |
| 1714 | !!(data->caseopen & to_sensor_dev_attr_2(attr)->index)); |
| 1715 | } |
| 1716 | |
| 1717 | static ssize_t |
| 1718 | clear_caseopen(struct device *dev, struct device_attribute *attr, |
| 1719 | const char *buf, size_t count) |
| 1720 | { |
| 1721 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
| 1722 | unsigned long val; |
| 1723 | u16 reg, mask; |
| 1724 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1725 | if (kstrtoul(buf, 10, &val) || val != 0) |
Dmitry Artamonow | 363a12a | 2011-08-12 16:41:11 -0400 | [diff] [blame] | 1726 | return -EINVAL; |
| 1727 | |
| 1728 | mask = to_sensor_dev_attr_2(attr)->nr; |
| 1729 | |
| 1730 | mutex_lock(&data->update_lock); |
| 1731 | reg = w83627ehf_read_value(data, W83627EHF_REG_CASEOPEN_CLR); |
| 1732 | w83627ehf_write_value(data, W83627EHF_REG_CASEOPEN_CLR, reg | mask); |
| 1733 | w83627ehf_write_value(data, W83627EHF_REG_CASEOPEN_CLR, reg & ~mask); |
| 1734 | data->valid = 0; /* Force cache refresh */ |
| 1735 | mutex_unlock(&data->update_lock); |
| 1736 | |
| 1737 | return count; |
| 1738 | } |
| 1739 | |
| 1740 | static struct sensor_device_attribute_2 sda_caseopen[] = { |
| 1741 | SENSOR_ATTR_2(intrusion0_alarm, S_IWUSR | S_IRUGO, show_caseopen, |
| 1742 | clear_caseopen, 0x80, 0x10), |
| 1743 | SENSOR_ATTR_2(intrusion1_alarm, S_IWUSR | S_IRUGO, show_caseopen, |
| 1744 | clear_caseopen, 0x40, 0x40), |
| 1745 | }; |
| 1746 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1747 | /* |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1748 | * Driver and device management |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1749 | */ |
| 1750 | |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1751 | static void w83627ehf_device_remove_files(struct device *dev) |
| 1752 | { |
Guenter Roeck | 8969e84 | 2012-01-19 11:02:27 -0800 | [diff] [blame^] | 1753 | /* |
| 1754 | * some entries in the following arrays may not have been used in |
| 1755 | * device_create_file(), but device_remove_file() will ignore them |
| 1756 | */ |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1757 | int i; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1758 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1759 | |
| 1760 | for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++) |
| 1761 | device_remove_file(dev, &sda_sf3_arrays[i].dev_attr); |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1762 | for (i = 0; i < ARRAY_SIZE(sda_sf3_max_step_arrays); i++) { |
| 1763 | struct sensor_device_attribute *attr = |
| 1764 | &sda_sf3_max_step_arrays[i]; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1765 | if (data->REG_FAN_STEP_OUTPUT && |
| 1766 | data->REG_FAN_STEP_OUTPUT[attr->index] != 0xff) |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1767 | device_remove_file(dev, &attr->dev_attr); |
| 1768 | } |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 1769 | for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan3); i++) |
| 1770 | device_remove_file(dev, &sda_sf3_arrays_fan3[i].dev_attr); |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1771 | for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) |
| 1772 | device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1773 | for (i = 0; i < data->in_num; i++) { |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1774 | if ((i == 6) && data->in6_skip) |
| 1775 | continue; |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1776 | device_remove_file(dev, &sda_in_input[i].dev_attr); |
| 1777 | device_remove_file(dev, &sda_in_alarm[i].dev_attr); |
| 1778 | device_remove_file(dev, &sda_in_min[i].dev_attr); |
| 1779 | device_remove_file(dev, &sda_in_max[i].dev_attr); |
| 1780 | } |
| 1781 | for (i = 0; i < 5; i++) { |
| 1782 | device_remove_file(dev, &sda_fan_input[i].dev_attr); |
| 1783 | device_remove_file(dev, &sda_fan_alarm[i].dev_attr); |
| 1784 | device_remove_file(dev, &sda_fan_div[i].dev_attr); |
| 1785 | device_remove_file(dev, &sda_fan_min[i].dev_attr); |
| 1786 | } |
Gong Jun | 237c8d2 | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 1787 | for (i = 0; i < data->pwm_num; i++) { |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1788 | device_remove_file(dev, &sda_pwm[i].dev_attr); |
| 1789 | device_remove_file(dev, &sda_pwm_mode[i].dev_attr); |
| 1790 | device_remove_file(dev, &sda_pwm_enable[i].dev_attr); |
| 1791 | device_remove_file(dev, &sda_target_temp[i].dev_attr); |
| 1792 | device_remove_file(dev, &sda_tolerance[i].dev_attr); |
| 1793 | } |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 1794 | for (i = 0; i < NUM_REG_TEMP; i++) { |
| 1795 | if (!(data->have_temp & (1 << i))) |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1796 | continue; |
| 1797 | device_remove_file(dev, &sda_temp_input[i].dev_attr); |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 1798 | device_remove_file(dev, &sda_temp_label[i].dev_attr); |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 1799 | if (i == 2 && data->temp3_val_only) |
| 1800 | continue; |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1801 | device_remove_file(dev, &sda_temp_max[i].dev_attr); |
| 1802 | device_remove_file(dev, &sda_temp_max_hyst[i].dev_attr); |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1803 | if (i > 2) |
| 1804 | continue; |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1805 | device_remove_file(dev, &sda_temp_alarm[i].dev_attr); |
| 1806 | device_remove_file(dev, &sda_temp_type[i].dev_attr); |
| 1807 | } |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1808 | |
Dmitry Artamonow | 363a12a | 2011-08-12 16:41:11 -0400 | [diff] [blame] | 1809 | device_remove_file(dev, &sda_caseopen[0].dev_attr); |
| 1810 | device_remove_file(dev, &sda_caseopen[1].dev_attr); |
| 1811 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1812 | device_remove_file(dev, &dev_attr_name); |
Jean Delvare | cbe311f | 2008-01-03 21:22:44 +0100 | [diff] [blame] | 1813 | device_remove_file(dev, &dev_attr_cpu0_vid); |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1814 | } |
| 1815 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1816 | /* Get the monitoring functions started */ |
Jean Delvare | bf164c5 | 2011-10-13 15:49:08 -0400 | [diff] [blame] | 1817 | static inline void __devinit w83627ehf_init_device(struct w83627ehf_data *data, |
| 1818 | enum kinds kind) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1819 | { |
| 1820 | int i; |
Jean Delvare | da66736 | 2007-06-24 11:21:02 +0200 | [diff] [blame] | 1821 | u8 tmp, diode; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1822 | |
| 1823 | /* Start monitoring is needed */ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1824 | tmp = w83627ehf_read_value(data, W83627EHF_REG_CONFIG); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1825 | if (!(tmp & 0x01)) |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1826 | w83627ehf_write_value(data, W83627EHF_REG_CONFIG, |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1827 | tmp | 0x01); |
| 1828 | |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 1829 | /* Enable temperature sensors if needed */ |
| 1830 | for (i = 0; i < NUM_REG_TEMP; i++) { |
| 1831 | if (!(data->have_temp & (1 << i))) |
| 1832 | continue; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1833 | if (!data->reg_temp_config[i]) |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 1834 | continue; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1835 | tmp = w83627ehf_read_value(data, |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1836 | data->reg_temp_config[i]); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1837 | if (tmp & 0x01) |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1838 | w83627ehf_write_value(data, |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1839 | data->reg_temp_config[i], |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1840 | tmp & 0xfe); |
| 1841 | } |
Jean Delvare | d3130f0 | 2007-06-24 11:20:13 +0200 | [diff] [blame] | 1842 | |
| 1843 | /* Enable VBAT monitoring if needed */ |
| 1844 | tmp = w83627ehf_read_value(data, W83627EHF_REG_VBAT); |
| 1845 | if (!(tmp & 0x01)) |
| 1846 | w83627ehf_write_value(data, W83627EHF_REG_VBAT, tmp | 0x01); |
Jean Delvare | da66736 | 2007-06-24 11:21:02 +0200 | [diff] [blame] | 1847 | |
| 1848 | /* Get thermal sensor types */ |
Jean Delvare | bf164c5 | 2011-10-13 15:49:08 -0400 | [diff] [blame] | 1849 | switch (kind) { |
| 1850 | case w83627ehf: |
| 1851 | diode = w83627ehf_read_value(data, W83627EHF_REG_DIODE); |
| 1852 | break; |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 1853 | case w83627uhg: |
| 1854 | diode = 0x00; |
| 1855 | break; |
Jean Delvare | bf164c5 | 2011-10-13 15:49:08 -0400 | [diff] [blame] | 1856 | default: |
| 1857 | diode = 0x70; |
| 1858 | } |
Jean Delvare | da66736 | 2007-06-24 11:21:02 +0200 | [diff] [blame] | 1859 | for (i = 0; i < 3; i++) { |
Guenter Roeck | bfa02b0 | 2011-11-06 20:25:18 +0100 | [diff] [blame] | 1860 | const char *label = NULL; |
| 1861 | |
| 1862 | if (data->temp_label) |
| 1863 | label = data->temp_label[data->temp_src[i]]; |
Jean Delvare | 2265cef | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1864 | |
| 1865 | /* Digital source overrides analog type */ |
Guenter Roeck | bfa02b0 | 2011-11-06 20:25:18 +0100 | [diff] [blame] | 1866 | if (label && strncmp(label, "PECI", 4) == 0) |
Jean Delvare | 2265cef | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1867 | data->temp_type[i] = 6; |
Guenter Roeck | bfa02b0 | 2011-11-06 20:25:18 +0100 | [diff] [blame] | 1868 | else if (label && strncmp(label, "AMD", 3) == 0) |
Jean Delvare | 2265cef | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1869 | data->temp_type[i] = 5; |
| 1870 | else if ((tmp & (0x02 << i))) |
Jean Delvare | bf164c5 | 2011-10-13 15:49:08 -0400 | [diff] [blame] | 1871 | data->temp_type[i] = (diode & (0x10 << i)) ? 1 : 3; |
Jean Delvare | da66736 | 2007-06-24 11:21:02 +0200 | [diff] [blame] | 1872 | else |
| 1873 | data->temp_type[i] = 4; /* thermistor */ |
| 1874 | } |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1875 | } |
| 1876 | |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 1877 | static void w82627ehf_swap_tempreg(struct w83627ehf_data *data, |
| 1878 | int r1, int r2) |
| 1879 | { |
| 1880 | u16 tmp; |
| 1881 | |
| 1882 | tmp = data->temp_src[r1]; |
| 1883 | data->temp_src[r1] = data->temp_src[r2]; |
| 1884 | data->temp_src[r2] = tmp; |
| 1885 | |
| 1886 | tmp = data->reg_temp[r1]; |
| 1887 | data->reg_temp[r1] = data->reg_temp[r2]; |
| 1888 | data->reg_temp[r2] = tmp; |
| 1889 | |
| 1890 | tmp = data->reg_temp_over[r1]; |
| 1891 | data->reg_temp_over[r1] = data->reg_temp_over[r2]; |
| 1892 | data->reg_temp_over[r2] = tmp; |
| 1893 | |
| 1894 | tmp = data->reg_temp_hyst[r1]; |
| 1895 | data->reg_temp_hyst[r1] = data->reg_temp_hyst[r2]; |
| 1896 | data->reg_temp_hyst[r2] = tmp; |
| 1897 | |
| 1898 | tmp = data->reg_temp_config[r1]; |
| 1899 | data->reg_temp_config[r1] = data->reg_temp_config[r2]; |
| 1900 | data->reg_temp_config[r2] = tmp; |
| 1901 | } |
| 1902 | |
Jean Delvare | 03f5de2 | 2011-10-13 10:43:14 -0400 | [diff] [blame] | 1903 | static void __devinit |
Jean Delvare | 6ba71de | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 1904 | w83627ehf_set_temp_reg_ehf(struct w83627ehf_data *data, int n_temp) |
| 1905 | { |
| 1906 | int i; |
| 1907 | |
| 1908 | for (i = 0; i < n_temp; i++) { |
| 1909 | data->reg_temp[i] = W83627EHF_REG_TEMP[i]; |
| 1910 | data->reg_temp_over[i] = W83627EHF_REG_TEMP_OVER[i]; |
| 1911 | data->reg_temp_hyst[i] = W83627EHF_REG_TEMP_HYST[i]; |
| 1912 | data->reg_temp_config[i] = W83627EHF_REG_TEMP_CONFIG[i]; |
| 1913 | } |
| 1914 | } |
| 1915 | |
| 1916 | static void __devinit |
Jean Delvare | 03f5de2 | 2011-10-13 10:43:14 -0400 | [diff] [blame] | 1917 | w83627ehf_check_fan_inputs(const struct w83627ehf_sio_data *sio_data, |
| 1918 | struct w83627ehf_data *data) |
| 1919 | { |
| 1920 | int fan3pin, fan4pin, fan4min, fan5pin, regval; |
| 1921 | |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 1922 | /* The W83627UHG is simple, only two fan inputs, no config */ |
| 1923 | if (sio_data->kind == w83627uhg) { |
| 1924 | data->has_fan = 0x03; /* fan1 and fan2 */ |
| 1925 | data->has_fan_min = 0x03; |
| 1926 | return; |
| 1927 | } |
| 1928 | |
Jean Delvare | 03f5de2 | 2011-10-13 10:43:14 -0400 | [diff] [blame] | 1929 | superio_enter(sio_data->sioreg); |
| 1930 | |
| 1931 | /* fan4 and fan5 share some pins with the GPIO and serial flash */ |
| 1932 | if (sio_data->kind == nct6775) { |
| 1933 | /* On NCT6775, fan4 shares pins with the fdc interface */ |
| 1934 | fan3pin = 1; |
| 1935 | fan4pin = !(superio_inb(sio_data->sioreg, 0x2A) & 0x80); |
| 1936 | fan4min = 0; |
| 1937 | fan5pin = 0; |
| 1938 | } else if (sio_data->kind == nct6776) { |
Guenter Roeck | 585c0fd | 2012-01-27 05:43:59 -0800 | [diff] [blame] | 1939 | bool gpok = superio_inb(sio_data->sioreg, 0x27) & 0x80; |
| 1940 | |
| 1941 | superio_select(sio_data->sioreg, W83627EHF_LD_HWM); |
| 1942 | regval = superio_inb(sio_data->sioreg, SIO_REG_ENABLE); |
| 1943 | |
| 1944 | if (regval & 0x80) |
| 1945 | fan3pin = gpok; |
| 1946 | else |
| 1947 | fan3pin = !(superio_inb(sio_data->sioreg, 0x24) & 0x40); |
| 1948 | |
| 1949 | if (regval & 0x40) |
| 1950 | fan4pin = gpok; |
| 1951 | else |
| 1952 | fan4pin = !!(superio_inb(sio_data->sioreg, 0x1C) & 0x01); |
| 1953 | |
| 1954 | if (regval & 0x20) |
| 1955 | fan5pin = gpok; |
| 1956 | else |
| 1957 | fan5pin = !!(superio_inb(sio_data->sioreg, 0x1C) & 0x02); |
| 1958 | |
Jean Delvare | 03f5de2 | 2011-10-13 10:43:14 -0400 | [diff] [blame] | 1959 | fan4min = fan4pin; |
| 1960 | } else if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) { |
| 1961 | fan3pin = 1; |
| 1962 | fan4pin = superio_inb(sio_data->sioreg, 0x27) & 0x40; |
| 1963 | fan5pin = superio_inb(sio_data->sioreg, 0x27) & 0x20; |
| 1964 | fan4min = fan4pin; |
| 1965 | } else { |
| 1966 | fan3pin = 1; |
| 1967 | fan4pin = !(superio_inb(sio_data->sioreg, 0x29) & 0x06); |
| 1968 | fan5pin = !(superio_inb(sio_data->sioreg, 0x24) & 0x02); |
| 1969 | fan4min = fan4pin; |
| 1970 | } |
| 1971 | |
| 1972 | superio_exit(sio_data->sioreg); |
| 1973 | |
| 1974 | data->has_fan = data->has_fan_min = 0x03; /* fan1 and fan2 */ |
| 1975 | data->has_fan |= (fan3pin << 2); |
| 1976 | data->has_fan_min |= (fan3pin << 2); |
| 1977 | |
| 1978 | if (sio_data->kind == nct6775 || sio_data->kind == nct6776) { |
| 1979 | /* |
| 1980 | * NCT6775F and NCT6776F don't have the W83627EHF_REG_FANDIV1 |
| 1981 | * register |
| 1982 | */ |
| 1983 | data->has_fan |= (fan4pin << 3) | (fan5pin << 4); |
| 1984 | data->has_fan_min |= (fan4min << 3) | (fan5pin << 4); |
| 1985 | } else { |
| 1986 | /* |
| 1987 | * It looks like fan4 and fan5 pins can be alternatively used |
| 1988 | * as fan on/off switches, but fan5 control is write only :/ |
| 1989 | * We assume that if the serial interface is disabled, designers |
| 1990 | * connected fan5 as input unless they are emitting log 1, which |
| 1991 | * is not the default. |
| 1992 | */ |
| 1993 | regval = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1); |
| 1994 | if ((regval & (1 << 2)) && fan4pin) { |
| 1995 | data->has_fan |= (1 << 3); |
| 1996 | data->has_fan_min |= (1 << 3); |
| 1997 | } |
| 1998 | if (!(regval & (1 << 1)) && fan5pin) { |
| 1999 | data->has_fan |= (1 << 4); |
| 2000 | data->has_fan_min |= (1 << 4); |
| 2001 | } |
| 2002 | } |
| 2003 | } |
| 2004 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2005 | static int __devinit w83627ehf_probe(struct platform_device *pdev) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2006 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2007 | struct device *dev = &pdev->dev; |
| 2008 | struct w83627ehf_sio_data *sio_data = dev->platform_data; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2009 | struct w83627ehf_data *data; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2010 | struct resource *res; |
Jean Delvare | 03f5de2 | 2011-10-13 10:43:14 -0400 | [diff] [blame] | 2011 | u8 en_vrm10; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2012 | int i, err = 0; |
| 2013 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2014 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
| 2015 | if (!request_region(res->start, IOREGION_LENGTH, DRVNAME)) { |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2016 | err = -EBUSY; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2017 | dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", |
| 2018 | (unsigned long)res->start, |
| 2019 | (unsigned long)res->start + IOREGION_LENGTH - 1); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2020 | goto exit; |
| 2021 | } |
| 2022 | |
Guenter Roeck | 32260d9 | 2012-03-12 08:33:10 -0700 | [diff] [blame] | 2023 | data = devm_kzalloc(&pdev->dev, sizeof(struct w83627ehf_data), |
| 2024 | GFP_KERNEL); |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 2025 | if (!data) { |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2026 | err = -ENOMEM; |
| 2027 | goto exit_release; |
| 2028 | } |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2029 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2030 | data->addr = res->start; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 2031 | mutex_init(&data->lock); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 2032 | mutex_init(&data->update_lock); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2033 | data->name = w83627ehf_device_names[sio_data->kind]; |
| 2034 | platform_set_drvdata(pdev, data); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2035 | |
Gong Jun | 237c8d2 | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 2036 | /* 627EHG and 627EHF have 10 voltage inputs; 627DHG and 667HG have 9 */ |
| 2037 | data->in_num = (sio_data->kind == w83627ehf) ? 10 : 9; |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 2038 | /* 667HG, NCT6775F, and NCT6776F have 3 pwms, and 627UHG has only 2 */ |
| 2039 | switch (sio_data->kind) { |
| 2040 | default: |
| 2041 | data->pwm_num = 4; |
| 2042 | break; |
| 2043 | case w83667hg: |
| 2044 | case w83667hg_b: |
| 2045 | case nct6775: |
| 2046 | case nct6776: |
| 2047 | data->pwm_num = 3; |
| 2048 | break; |
| 2049 | case w83627uhg: |
| 2050 | data->pwm_num = 2; |
| 2051 | break; |
| 2052 | } |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2053 | |
Jean Delvare | 6ba71de | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 2054 | /* Default to 3 temperature inputs, code below will adjust as needed */ |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 2055 | data->have_temp = 0x07; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2056 | |
| 2057 | /* Deal with temperature register setup first. */ |
| 2058 | if (sio_data->kind == nct6775 || sio_data->kind == nct6776) { |
| 2059 | int mask = 0; |
| 2060 | |
| 2061 | /* |
| 2062 | * Display temperature sensor output only if it monitors |
| 2063 | * a source other than one already reported. Always display |
| 2064 | * first three temperature registers, though. |
| 2065 | */ |
| 2066 | for (i = 0; i < NUM_REG_TEMP; i++) { |
| 2067 | u8 src; |
| 2068 | |
| 2069 | data->reg_temp[i] = NCT6775_REG_TEMP[i]; |
| 2070 | data->reg_temp_over[i] = NCT6775_REG_TEMP_OVER[i]; |
| 2071 | data->reg_temp_hyst[i] = NCT6775_REG_TEMP_HYST[i]; |
| 2072 | data->reg_temp_config[i] = NCT6775_REG_TEMP_CONFIG[i]; |
| 2073 | |
| 2074 | src = w83627ehf_read_value(data, |
| 2075 | NCT6775_REG_TEMP_SOURCE[i]); |
| 2076 | src &= 0x1f; |
| 2077 | if (src && !(mask & (1 << src))) { |
| 2078 | data->have_temp |= 1 << i; |
| 2079 | mask |= 1 << src; |
| 2080 | } |
| 2081 | |
| 2082 | data->temp_src[i] = src; |
| 2083 | |
| 2084 | /* |
| 2085 | * Now do some register swapping if index 0..2 don't |
| 2086 | * point to SYSTIN(1), CPUIN(2), and AUXIN(3). |
| 2087 | * Idea is to have the first three attributes |
| 2088 | * report SYSTIN, CPUIN, and AUXIN if possible |
| 2089 | * without overriding the basic system configuration. |
| 2090 | */ |
| 2091 | if (i > 0 && data->temp_src[0] != 1 |
| 2092 | && data->temp_src[i] == 1) |
| 2093 | w82627ehf_swap_tempreg(data, 0, i); |
| 2094 | if (i > 1 && data->temp_src[1] != 2 |
| 2095 | && data->temp_src[i] == 2) |
| 2096 | w82627ehf_swap_tempreg(data, 1, i); |
| 2097 | if (i > 2 && data->temp_src[2] != 3 |
| 2098 | && data->temp_src[i] == 3) |
| 2099 | w82627ehf_swap_tempreg(data, 2, i); |
| 2100 | } |
| 2101 | if (sio_data->kind == nct6776) { |
| 2102 | /* |
| 2103 | * On NCT6776, AUXTIN and VIN3 pins are shared. |
| 2104 | * Only way to detect it is to check if AUXTIN is used |
| 2105 | * as a temperature source, and if that source is |
| 2106 | * enabled. |
| 2107 | * |
| 2108 | * If that is the case, disable in6, which reports VIN3. |
| 2109 | * Otherwise disable temp3. |
| 2110 | */ |
| 2111 | if (data->temp_src[2] == 3) { |
| 2112 | u8 reg; |
| 2113 | |
| 2114 | if (data->reg_temp_config[2]) |
| 2115 | reg = w83627ehf_read_value(data, |
| 2116 | data->reg_temp_config[2]); |
| 2117 | else |
| 2118 | reg = 0; /* Assume AUXTIN is used */ |
| 2119 | |
| 2120 | if (reg & 0x01) |
| 2121 | data->have_temp &= ~(1 << 2); |
| 2122 | else |
| 2123 | data->in6_skip = 1; |
| 2124 | } |
Guenter Roeck | 02309ad | 2011-03-10 15:47:14 -0800 | [diff] [blame] | 2125 | data->temp_label = nct6776_temp_label; |
| 2126 | } else { |
| 2127 | data->temp_label = nct6775_temp_label; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2128 | } |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 2129 | } else if (sio_data->kind == w83667hg_b) { |
| 2130 | u8 reg; |
| 2131 | |
Jean Delvare | 6ba71de | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 2132 | w83627ehf_set_temp_reg_ehf(data, 4); |
| 2133 | |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2134 | /* |
| 2135 | * Temperature sources are selected with bank 0, registers 0x49 |
| 2136 | * and 0x4a. |
| 2137 | */ |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 2138 | reg = w83627ehf_read_value(data, 0x4a); |
| 2139 | data->temp_src[0] = reg >> 5; |
| 2140 | reg = w83627ehf_read_value(data, 0x49); |
| 2141 | data->temp_src[1] = reg & 0x07; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2142 | data->temp_src[2] = (reg >> 4) & 0x07; |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 2143 | |
| 2144 | /* |
| 2145 | * W83667HG-B has another temperature register at 0x7e. |
| 2146 | * The temperature source is selected with register 0x7d. |
| 2147 | * Support it if the source differs from already reported |
| 2148 | * sources. |
| 2149 | */ |
| 2150 | reg = w83627ehf_read_value(data, 0x7d); |
| 2151 | reg &= 0x07; |
| 2152 | if (reg != data->temp_src[0] && reg != data->temp_src[1] |
| 2153 | && reg != data->temp_src[2]) { |
| 2154 | data->temp_src[3] = reg; |
| 2155 | data->have_temp |= 1 << 3; |
| 2156 | } |
| 2157 | |
| 2158 | /* |
| 2159 | * Chip supports either AUXTIN or VIN3. Try to find out which |
| 2160 | * one. |
| 2161 | */ |
| 2162 | reg = w83627ehf_read_value(data, W83627EHF_REG_TEMP_CONFIG[2]); |
| 2163 | if (data->temp_src[2] == 2 && (reg & 0x01)) |
| 2164 | data->have_temp &= ~(1 << 2); |
| 2165 | |
| 2166 | if ((data->temp_src[2] == 2 && (data->have_temp & (1 << 2))) |
| 2167 | || (data->temp_src[3] == 2 && (data->have_temp & (1 << 3)))) |
| 2168 | data->in6_skip = 1; |
| 2169 | |
| 2170 | data->temp_label = w83667hg_b_temp_label; |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 2171 | } else if (sio_data->kind == w83627uhg) { |
| 2172 | u8 reg; |
| 2173 | |
| 2174 | w83627ehf_set_temp_reg_ehf(data, 3); |
| 2175 | |
| 2176 | /* |
Jean Delvare | aacb6b0 | 2012-03-13 04:03:27 -0400 | [diff] [blame] | 2177 | * Temperature sources for temp2 and temp3 are selected with |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 2178 | * bank 0, registers 0x49 and 0x4a. |
| 2179 | */ |
| 2180 | data->temp_src[0] = 0; /* SYSTIN */ |
| 2181 | reg = w83627ehf_read_value(data, 0x49) & 0x07; |
| 2182 | /* Adjust to have the same mapping as other source registers */ |
| 2183 | if (reg == 0) |
Jean Delvare | aacb6b0 | 2012-03-13 04:03:27 -0400 | [diff] [blame] | 2184 | data->temp_src[1] = 1; |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 2185 | else if (reg >= 2 && reg <= 5) |
Jean Delvare | aacb6b0 | 2012-03-13 04:03:27 -0400 | [diff] [blame] | 2186 | data->temp_src[1] = reg + 2; |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 2187 | else /* should never happen */ |
| 2188 | data->have_temp &= ~(1 << 1); |
| 2189 | reg = w83627ehf_read_value(data, 0x4a); |
| 2190 | data->temp_src[2] = reg >> 5; |
| 2191 | |
| 2192 | /* |
| 2193 | * Skip temp3 if source is invalid or the same as temp1 |
| 2194 | * or temp2. |
| 2195 | */ |
| 2196 | if (data->temp_src[2] == 2 || data->temp_src[2] == 3 || |
| 2197 | data->temp_src[2] == data->temp_src[0] || |
| 2198 | ((data->have_temp & (1 << 1)) && |
| 2199 | data->temp_src[2] == data->temp_src[1])) |
| 2200 | data->have_temp &= ~(1 << 2); |
| 2201 | else |
| 2202 | data->temp3_val_only = 1; /* No limit regs */ |
| 2203 | |
| 2204 | data->in6_skip = 1; /* No VIN3 */ |
| 2205 | |
| 2206 | data->temp_label = w83667hg_b_temp_label; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2207 | } else { |
Jean Delvare | 6ba71de | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 2208 | w83627ehf_set_temp_reg_ehf(data, 3); |
| 2209 | |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2210 | /* Temperature sources are fixed */ |
Jean Delvare | 6ba71de | 2011-11-04 12:00:47 +0100 | [diff] [blame] | 2211 | |
| 2212 | if (sio_data->kind == w83667hg) { |
| 2213 | u8 reg; |
| 2214 | |
| 2215 | /* |
| 2216 | * Chip supports either AUXTIN or VIN3. Try to find |
| 2217 | * out which one. |
| 2218 | */ |
| 2219 | reg = w83627ehf_read_value(data, |
| 2220 | W83627EHF_REG_TEMP_CONFIG[2]); |
| 2221 | if (reg & 0x01) |
| 2222 | data->have_temp &= ~(1 << 2); |
| 2223 | else |
| 2224 | data->in6_skip = 1; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2225 | } |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 2226 | } |
| 2227 | |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2228 | if (sio_data->kind == nct6775) { |
Guenter Roeck | 26bc440 | 2011-02-11 08:00:58 -0800 | [diff] [blame] | 2229 | data->has_fan_div = true; |
| 2230 | data->fan_from_reg = fan_from_reg16; |
| 2231 | data->fan_from_reg_min = fan_from_reg8; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2232 | data->REG_PWM = NCT6775_REG_PWM; |
| 2233 | data->REG_TARGET = NCT6775_REG_TARGET; |
Guenter Roeck | 26bc440 | 2011-02-11 08:00:58 -0800 | [diff] [blame] | 2234 | data->REG_FAN = NCT6775_REG_FAN; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2235 | data->REG_FAN_MIN = W83627EHF_REG_FAN_MIN; |
| 2236 | data->REG_FAN_START_OUTPUT = NCT6775_REG_FAN_START_OUTPUT; |
| 2237 | data->REG_FAN_STOP_OUTPUT = NCT6775_REG_FAN_STOP_OUTPUT; |
| 2238 | data->REG_FAN_STOP_TIME = NCT6775_REG_FAN_STOP_TIME; |
| 2239 | data->REG_FAN_MAX_OUTPUT = NCT6775_REG_FAN_MAX_OUTPUT; |
| 2240 | data->REG_FAN_STEP_OUTPUT = NCT6775_REG_FAN_STEP_OUTPUT; |
| 2241 | } else if (sio_data->kind == nct6776) { |
Guenter Roeck | 26bc440 | 2011-02-11 08:00:58 -0800 | [diff] [blame] | 2242 | data->has_fan_div = false; |
| 2243 | data->fan_from_reg = fan_from_reg13; |
| 2244 | data->fan_from_reg_min = fan_from_reg13; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2245 | data->REG_PWM = NCT6775_REG_PWM; |
| 2246 | data->REG_TARGET = NCT6775_REG_TARGET; |
Guenter Roeck | 26bc440 | 2011-02-11 08:00:58 -0800 | [diff] [blame] | 2247 | data->REG_FAN = NCT6775_REG_FAN; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2248 | data->REG_FAN_MIN = NCT6776_REG_FAN_MIN; |
| 2249 | data->REG_FAN_START_OUTPUT = NCT6775_REG_FAN_START_OUTPUT; |
| 2250 | data->REG_FAN_STOP_OUTPUT = NCT6775_REG_FAN_STOP_OUTPUT; |
| 2251 | data->REG_FAN_STOP_TIME = NCT6775_REG_FAN_STOP_TIME; |
| 2252 | } else if (sio_data->kind == w83667hg_b) { |
Guenter Roeck | 26bc440 | 2011-02-11 08:00:58 -0800 | [diff] [blame] | 2253 | data->has_fan_div = true; |
| 2254 | data->fan_from_reg = fan_from_reg8; |
| 2255 | data->fan_from_reg_min = fan_from_reg8; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2256 | data->REG_PWM = W83627EHF_REG_PWM; |
| 2257 | data->REG_TARGET = W83627EHF_REG_TARGET; |
| 2258 | data->REG_FAN = W83627EHF_REG_FAN; |
| 2259 | data->REG_FAN_MIN = W83627EHF_REG_FAN_MIN; |
| 2260 | data->REG_FAN_START_OUTPUT = W83627EHF_REG_FAN_START_OUTPUT; |
| 2261 | data->REG_FAN_STOP_OUTPUT = W83627EHF_REG_FAN_STOP_OUTPUT; |
| 2262 | data->REG_FAN_STOP_TIME = W83627EHF_REG_FAN_STOP_TIME; |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 2263 | data->REG_FAN_MAX_OUTPUT = |
| 2264 | W83627EHF_REG_FAN_MAX_OUTPUT_W83667_B; |
| 2265 | data->REG_FAN_STEP_OUTPUT = |
| 2266 | W83627EHF_REG_FAN_STEP_OUTPUT_W83667_B; |
| 2267 | } else { |
Guenter Roeck | 26bc440 | 2011-02-11 08:00:58 -0800 | [diff] [blame] | 2268 | data->has_fan_div = true; |
| 2269 | data->fan_from_reg = fan_from_reg8; |
| 2270 | data->fan_from_reg_min = fan_from_reg8; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2271 | data->REG_PWM = W83627EHF_REG_PWM; |
| 2272 | data->REG_TARGET = W83627EHF_REG_TARGET; |
| 2273 | data->REG_FAN = W83627EHF_REG_FAN; |
| 2274 | data->REG_FAN_MIN = W83627EHF_REG_FAN_MIN; |
| 2275 | data->REG_FAN_START_OUTPUT = W83627EHF_REG_FAN_START_OUTPUT; |
| 2276 | data->REG_FAN_STOP_OUTPUT = W83627EHF_REG_FAN_STOP_OUTPUT; |
| 2277 | data->REG_FAN_STOP_TIME = W83627EHF_REG_FAN_STOP_TIME; |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 2278 | data->REG_FAN_MAX_OUTPUT = |
| 2279 | W83627EHF_REG_FAN_MAX_OUTPUT_COMMON; |
| 2280 | data->REG_FAN_STEP_OUTPUT = |
| 2281 | W83627EHF_REG_FAN_STEP_OUTPUT_COMMON; |
| 2282 | } |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 2283 | |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 2284 | /* Setup input voltage scaling factors */ |
| 2285 | if (sio_data->kind == w83627uhg) |
| 2286 | data->scale_in = scale_in_w83627uhg; |
| 2287 | else |
| 2288 | data->scale_in = scale_in_common; |
| 2289 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2290 | /* Initialize the chip */ |
Jean Delvare | bf164c5 | 2011-10-13 15:49:08 -0400 | [diff] [blame] | 2291 | w83627ehf_init_device(data, sio_data->kind); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2292 | |
Jean Delvare | fc18d6c | 2007-06-24 11:19:42 +0200 | [diff] [blame] | 2293 | data->vrm = vid_which_vrm(); |
| 2294 | superio_enter(sio_data->sioreg); |
Jean Delvare | fc18d6c | 2007-06-24 11:19:42 +0200 | [diff] [blame] | 2295 | /* Read VID value */ |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2296 | if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b || |
| 2297 | sio_data->kind == nct6775 || sio_data->kind == nct6776) { |
Guenter Roeck | 8969e84 | 2012-01-19 11:02:27 -0800 | [diff] [blame^] | 2298 | /* |
| 2299 | * W83667HG has different pins for VID input and output, so |
| 2300 | * we can get the VID input values directly at logical device D |
| 2301 | * 0xe3. |
| 2302 | */ |
Gong Jun | 237c8d2 | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 2303 | superio_select(sio_data->sioreg, W83667HG_LD_VID); |
| 2304 | data->vid = superio_inb(sio_data->sioreg, 0xe3); |
Jean Delvare | cbe311f | 2008-01-03 21:22:44 +0100 | [diff] [blame] | 2305 | err = device_create_file(dev, &dev_attr_cpu0_vid); |
| 2306 | if (err) |
| 2307 | goto exit_release; |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 2308 | } else if (sio_data->kind != w83627uhg) { |
Gong Jun | 237c8d2 | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 2309 | superio_select(sio_data->sioreg, W83627EHF_LD_HWM); |
| 2310 | if (superio_inb(sio_data->sioreg, SIO_REG_VID_CTRL) & 0x80) { |
Guenter Roeck | 8969e84 | 2012-01-19 11:02:27 -0800 | [diff] [blame^] | 2311 | /* |
| 2312 | * Set VID input sensibility if needed. In theory the |
| 2313 | * BIOS should have set it, but in practice it's not |
| 2314 | * always the case. We only do it for the W83627EHF/EHG |
| 2315 | * because the W83627DHG is more complex in this |
| 2316 | * respect. |
| 2317 | */ |
Gong Jun | 237c8d2 | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 2318 | if (sio_data->kind == w83627ehf) { |
| 2319 | en_vrm10 = superio_inb(sio_data->sioreg, |
| 2320 | SIO_REG_EN_VRM10); |
| 2321 | if ((en_vrm10 & 0x08) && data->vrm == 90) { |
| 2322 | dev_warn(dev, "Setting VID input " |
| 2323 | "voltage to TTL\n"); |
| 2324 | superio_outb(sio_data->sioreg, |
| 2325 | SIO_REG_EN_VRM10, |
| 2326 | en_vrm10 & ~0x08); |
| 2327 | } else if (!(en_vrm10 & 0x08) |
| 2328 | && data->vrm == 100) { |
| 2329 | dev_warn(dev, "Setting VID input " |
| 2330 | "voltage to VRM10\n"); |
| 2331 | superio_outb(sio_data->sioreg, |
| 2332 | SIO_REG_EN_VRM10, |
| 2333 | en_vrm10 | 0x08); |
| 2334 | } |
| 2335 | } |
| 2336 | |
| 2337 | data->vid = superio_inb(sio_data->sioreg, |
| 2338 | SIO_REG_VID_DATA); |
| 2339 | if (sio_data->kind == w83627ehf) /* 6 VID pins only */ |
| 2340 | data->vid &= 0x3f; |
| 2341 | |
| 2342 | err = device_create_file(dev, &dev_attr_cpu0_vid); |
| 2343 | if (err) |
| 2344 | goto exit_release; |
| 2345 | } else { |
| 2346 | dev_info(dev, "VID pins in output mode, CPU VID not " |
| 2347 | "available\n"); |
| 2348 | } |
Jean Delvare | fc18d6c | 2007-06-24 11:19:42 +0200 | [diff] [blame] | 2349 | } |
| 2350 | |
Ian Dobson | d42e869 | 2011-03-07 14:21:12 -0800 | [diff] [blame] | 2351 | if (fan_debounce && |
| 2352 | (sio_data->kind == nct6775 || sio_data->kind == nct6776)) { |
| 2353 | u8 tmp; |
| 2354 | |
| 2355 | superio_select(sio_data->sioreg, W83627EHF_LD_HWM); |
| 2356 | tmp = superio_inb(sio_data->sioreg, NCT6775_REG_FAN_DEBOUNCE); |
| 2357 | if (sio_data->kind == nct6776) |
| 2358 | superio_outb(sio_data->sioreg, NCT6775_REG_FAN_DEBOUNCE, |
| 2359 | 0x3e | tmp); |
| 2360 | else |
| 2361 | superio_outb(sio_data->sioreg, NCT6775_REG_FAN_DEBOUNCE, |
| 2362 | 0x1e | tmp); |
| 2363 | pr_info("Enabled fan debounce for chip %s\n", data->name); |
| 2364 | } |
| 2365 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2366 | superio_exit(sio_data->sioreg); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 2367 | |
Jean Delvare | 03f5de2 | 2011-10-13 10:43:14 -0400 | [diff] [blame] | 2368 | w83627ehf_check_fan_inputs(sio_data, data); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2369 | |
Mark M. Hoffman | ea7be66 | 2007-08-05 12:19:01 -0400 | [diff] [blame] | 2370 | /* Read fan clock dividers immediately */ |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2371 | w83627ehf_update_fan_div_common(dev, data); |
| 2372 | |
| 2373 | /* Read pwm data to save original values */ |
| 2374 | w83627ehf_update_pwm_common(dev, data); |
| 2375 | for (i = 0; i < data->pwm_num; i++) |
| 2376 | data->pwm_enable_orig[i] = data->pwm_enable[i]; |
Mark M. Hoffman | ea7be66 | 2007-08-05 12:19:01 -0400 | [diff] [blame] | 2377 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2378 | /* Register sysfs hooks */ |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 2379 | for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++) { |
| 2380 | err = device_create_file(dev, &sda_sf3_arrays[i].dev_attr); |
| 2381 | if (err) |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 2382 | goto exit_remove; |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 2383 | } |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 2384 | |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 2385 | for (i = 0; i < ARRAY_SIZE(sda_sf3_max_step_arrays); i++) { |
| 2386 | struct sensor_device_attribute *attr = |
| 2387 | &sda_sf3_max_step_arrays[i]; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2388 | if (data->REG_FAN_STEP_OUTPUT && |
| 2389 | data->REG_FAN_STEP_OUTPUT[attr->index] != 0xff) { |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 2390 | err = device_create_file(dev, &attr->dev_attr); |
| 2391 | if (err) |
| 2392 | goto exit_remove; |
| 2393 | } |
| 2394 | } |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 2395 | /* if fan3 and fan4 are enabled create the sf3 files for them */ |
| 2396 | if ((data->has_fan & (1 << 2)) && data->pwm_num >= 3) |
| 2397 | for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan3); i++) { |
| 2398 | err = device_create_file(dev, |
| 2399 | &sda_sf3_arrays_fan3[i].dev_attr); |
| 2400 | if (err) |
| 2401 | goto exit_remove; |
| 2402 | } |
Gong Jun | 237c8d2 | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 2403 | if ((data->has_fan & (1 << 3)) && data->pwm_num >= 4) |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 2404 | for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) { |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 2405 | err = device_create_file(dev, |
| 2406 | &sda_sf3_arrays_fan4[i].dev_attr); |
| 2407 | if (err) |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 2408 | goto exit_remove; |
| 2409 | } |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 2410 | |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 2411 | for (i = 0; i < data->in_num; i++) { |
| 2412 | if ((i == 6) && data->in6_skip) |
| 2413 | continue; |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 2414 | if ((err = device_create_file(dev, &sda_in_input[i].dev_attr)) |
| 2415 | || (err = device_create_file(dev, |
| 2416 | &sda_in_alarm[i].dev_attr)) |
| 2417 | || (err = device_create_file(dev, |
| 2418 | &sda_in_min[i].dev_attr)) |
| 2419 | || (err = device_create_file(dev, |
| 2420 | &sda_in_max[i].dev_attr))) |
| 2421 | goto exit_remove; |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 2422 | } |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 2423 | |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 2424 | for (i = 0; i < 5; i++) { |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 2425 | if (data->has_fan & (1 << i)) { |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 2426 | if ((err = device_create_file(dev, |
| 2427 | &sda_fan_input[i].dev_attr)) |
| 2428 | || (err = device_create_file(dev, |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2429 | &sda_fan_alarm[i].dev_attr))) |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 2430 | goto exit_remove; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2431 | if (sio_data->kind != nct6776) { |
| 2432 | err = device_create_file(dev, |
| 2433 | &sda_fan_div[i].dev_attr); |
| 2434 | if (err) |
| 2435 | goto exit_remove; |
| 2436 | } |
| 2437 | if (data->has_fan_min & (1 << i)) { |
| 2438 | err = device_create_file(dev, |
| 2439 | &sda_fan_min[i].dev_attr); |
| 2440 | if (err) |
| 2441 | goto exit_remove; |
| 2442 | } |
Gong Jun | 237c8d2 | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 2443 | if (i < data->pwm_num && |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 2444 | ((err = device_create_file(dev, |
| 2445 | &sda_pwm[i].dev_attr)) |
| 2446 | || (err = device_create_file(dev, |
| 2447 | &sda_pwm_mode[i].dev_attr)) |
| 2448 | || (err = device_create_file(dev, |
| 2449 | &sda_pwm_enable[i].dev_attr)) |
| 2450 | || (err = device_create_file(dev, |
| 2451 | &sda_target_temp[i].dev_attr)) |
| 2452 | || (err = device_create_file(dev, |
| 2453 | &sda_tolerance[i].dev_attr)))) |
| 2454 | goto exit_remove; |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 2455 | } |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2456 | } |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 2457 | |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 2458 | for (i = 0; i < NUM_REG_TEMP; i++) { |
| 2459 | if (!(data->have_temp & (1 << i))) |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 2460 | continue; |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 2461 | err = device_create_file(dev, &sda_temp_input[i].dev_attr); |
| 2462 | if (err) |
| 2463 | goto exit_remove; |
| 2464 | if (data->temp_label) { |
| 2465 | err = device_create_file(dev, |
| 2466 | &sda_temp_label[i].dev_attr); |
| 2467 | if (err) |
| 2468 | goto exit_remove; |
| 2469 | } |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 2470 | if (i == 2 && data->temp3_val_only) |
| 2471 | continue; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2472 | if (data->reg_temp_over[i]) { |
| 2473 | err = device_create_file(dev, |
| 2474 | &sda_temp_max[i].dev_attr); |
| 2475 | if (err) |
| 2476 | goto exit_remove; |
| 2477 | } |
| 2478 | if (data->reg_temp_hyst[i]) { |
| 2479 | err = device_create_file(dev, |
| 2480 | &sda_temp_max_hyst[i].dev_attr); |
| 2481 | if (err) |
| 2482 | goto exit_remove; |
| 2483 | } |
Guenter Roeck | d36cf32 | 2011-02-07 15:08:54 -0800 | [diff] [blame] | 2484 | if (i > 2) |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2485 | continue; |
| 2486 | if ((err = device_create_file(dev, |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 2487 | &sda_temp_alarm[i].dev_attr)) |
| 2488 | || (err = device_create_file(dev, |
| 2489 | &sda_temp_type[i].dev_attr))) |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 2490 | goto exit_remove; |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 2491 | } |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 2492 | |
Dmitry Artamonow | 363a12a | 2011-08-12 16:41:11 -0400 | [diff] [blame] | 2493 | err = device_create_file(dev, &sda_caseopen[0].dev_attr); |
| 2494 | if (err) |
| 2495 | goto exit_remove; |
| 2496 | |
| 2497 | if (sio_data->kind == nct6776) { |
| 2498 | err = device_create_file(dev, &sda_caseopen[1].dev_attr); |
| 2499 | if (err) |
| 2500 | goto exit_remove; |
| 2501 | } |
| 2502 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2503 | err = device_create_file(dev, &dev_attr_name); |
| 2504 | if (err) |
| 2505 | goto exit_remove; |
| 2506 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 2507 | data->hwmon_dev = hwmon_device_register(dev); |
| 2508 | if (IS_ERR(data->hwmon_dev)) { |
| 2509 | err = PTR_ERR(data->hwmon_dev); |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 2510 | goto exit_remove; |
| 2511 | } |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2512 | |
| 2513 | return 0; |
| 2514 | |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 2515 | exit_remove: |
| 2516 | w83627ehf_device_remove_files(dev); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2517 | exit_release: |
Guenter Roeck | 32260d9 | 2012-03-12 08:33:10 -0700 | [diff] [blame] | 2518 | platform_set_drvdata(pdev, NULL); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2519 | release_region(res->start, IOREGION_LENGTH); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2520 | exit: |
| 2521 | return err; |
| 2522 | } |
| 2523 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2524 | static int __devexit w83627ehf_remove(struct platform_device *pdev) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2525 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2526 | struct w83627ehf_data *data = platform_get_drvdata(pdev); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2527 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 2528 | hwmon_device_unregister(data->hwmon_dev); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2529 | w83627ehf_device_remove_files(&pdev->dev); |
| 2530 | release_region(data->addr, IOREGION_LENGTH); |
| 2531 | platform_set_drvdata(pdev, NULL); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2532 | |
| 2533 | return 0; |
| 2534 | } |
| 2535 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2536 | static struct platform_driver w83627ehf_driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 2537 | .driver = { |
Jean Delvare | 8721884 | 2006-09-03 22:36:14 +0200 | [diff] [blame] | 2538 | .owner = THIS_MODULE, |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2539 | .name = DRVNAME, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 2540 | }, |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2541 | .probe = w83627ehf_probe, |
| 2542 | .remove = __devexit_p(w83627ehf_remove), |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2543 | }; |
| 2544 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2545 | /* w83627ehf_find() looks for a '627 in the Super-I/O config space */ |
| 2546 | static int __init w83627ehf_find(int sioaddr, unsigned short *addr, |
| 2547 | struct w83627ehf_sio_data *sio_data) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2548 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2549 | static const char __initdata sio_name_W83627EHF[] = "W83627EHF"; |
| 2550 | static const char __initdata sio_name_W83627EHG[] = "W83627EHG"; |
| 2551 | static const char __initdata sio_name_W83627DHG[] = "W83627DHG"; |
Jean Delvare | c1e48dc | 2009-06-15 18:39:50 +0200 | [diff] [blame] | 2552 | static const char __initdata sio_name_W83627DHG_P[] = "W83627DHG-P"; |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 2553 | static const char __initdata sio_name_W83627UHG[] = "W83627UHG"; |
Gong Jun | 237c8d2 | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 2554 | static const char __initdata sio_name_W83667HG[] = "W83667HG"; |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 2555 | static const char __initdata sio_name_W83667HG_B[] = "W83667HG-B"; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2556 | static const char __initdata sio_name_NCT6775[] = "NCT6775F"; |
| 2557 | static const char __initdata sio_name_NCT6776[] = "NCT6776F"; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2558 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2559 | u16 val; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2560 | const char *sio_name; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2561 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2562 | superio_enter(sioaddr); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2563 | |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 2564 | if (force_id) |
| 2565 | val = force_id; |
| 2566 | else |
| 2567 | val = (superio_inb(sioaddr, SIO_REG_DEVID) << 8) |
| 2568 | | superio_inb(sioaddr, SIO_REG_DEVID + 1); |
David Hubbard | 657c93b | 2007-02-14 21:15:04 +0100 | [diff] [blame] | 2569 | switch (val & SIO_ID_MASK) { |
David Hubbard | 657c93b | 2007-02-14 21:15:04 +0100 | [diff] [blame] | 2570 | case SIO_W83627EHF_ID: |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2571 | sio_data->kind = w83627ehf; |
| 2572 | sio_name = sio_name_W83627EHF; |
| 2573 | break; |
David Hubbard | 657c93b | 2007-02-14 21:15:04 +0100 | [diff] [blame] | 2574 | case SIO_W83627EHG_ID: |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2575 | sio_data->kind = w83627ehf; |
| 2576 | sio_name = sio_name_W83627EHG; |
| 2577 | break; |
| 2578 | case SIO_W83627DHG_ID: |
| 2579 | sio_data->kind = w83627dhg; |
| 2580 | sio_name = sio_name_W83627DHG; |
David Hubbard | 657c93b | 2007-02-14 21:15:04 +0100 | [diff] [blame] | 2581 | break; |
Jean Delvare | c1e48dc | 2009-06-15 18:39:50 +0200 | [diff] [blame] | 2582 | case SIO_W83627DHG_P_ID: |
| 2583 | sio_data->kind = w83627dhg_p; |
| 2584 | sio_name = sio_name_W83627DHG_P; |
| 2585 | break; |
Jean Delvare | eff7687 | 2011-11-04 12:00:48 +0100 | [diff] [blame] | 2586 | case SIO_W83627UHG_ID: |
| 2587 | sio_data->kind = w83627uhg; |
| 2588 | sio_name = sio_name_W83627UHG; |
| 2589 | break; |
Gong Jun | 237c8d2 | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 2590 | case SIO_W83667HG_ID: |
| 2591 | sio_data->kind = w83667hg; |
| 2592 | sio_name = sio_name_W83667HG; |
| 2593 | break; |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 2594 | case SIO_W83667HG_B_ID: |
| 2595 | sio_data->kind = w83667hg_b; |
| 2596 | sio_name = sio_name_W83667HG_B; |
| 2597 | break; |
Guenter Roeck | ec3e5a1 | 2011-02-02 08:46:49 -0800 | [diff] [blame] | 2598 | case SIO_NCT6775_ID: |
| 2599 | sio_data->kind = nct6775; |
| 2600 | sio_name = sio_name_NCT6775; |
| 2601 | break; |
| 2602 | case SIO_NCT6776_ID: |
| 2603 | sio_data->kind = nct6776; |
| 2604 | sio_name = sio_name_NCT6776; |
| 2605 | break; |
David Hubbard | 657c93b | 2007-02-14 21:15:04 +0100 | [diff] [blame] | 2606 | default: |
Jean Delvare | 9f66036 | 2007-06-24 11:23:41 +0200 | [diff] [blame] | 2607 | if (val != 0xffff) |
Joe Perches | abdc6fd | 2010-10-20 06:51:54 +0000 | [diff] [blame] | 2608 | pr_debug("unsupported chip ID: 0x%04x\n", val); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2609 | superio_exit(sioaddr); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2610 | return -ENODEV; |
| 2611 | } |
| 2612 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2613 | /* We have a known chip, find the HWM I/O address */ |
| 2614 | superio_select(sioaddr, W83627EHF_LD_HWM); |
| 2615 | val = (superio_inb(sioaddr, SIO_REG_ADDR) << 8) |
| 2616 | | superio_inb(sioaddr, SIO_REG_ADDR + 1); |
Jean Delvare | 1a641fc | 2007-04-23 14:41:16 -0700 | [diff] [blame] | 2617 | *addr = val & IOREGION_ALIGNMENT; |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 2618 | if (*addr == 0) { |
Joe Perches | abdc6fd | 2010-10-20 06:51:54 +0000 | [diff] [blame] | 2619 | pr_err("Refusing to enable a Super-I/O device with a base I/O port 0\n"); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2620 | superio_exit(sioaddr); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2621 | return -ENODEV; |
| 2622 | } |
| 2623 | |
| 2624 | /* Activate logical device if needed */ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2625 | val = superio_inb(sioaddr, SIO_REG_ENABLE); |
David Hubbard | 475ef85 | 2007-06-24 11:17:09 +0200 | [diff] [blame] | 2626 | if (!(val & 0x01)) { |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 2627 | pr_warn("Forcibly enabling Super-I/O. " |
| 2628 | "Sensor is probably unusable.\n"); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2629 | superio_outb(sioaddr, SIO_REG_ENABLE, val | 0x01); |
David Hubbard | 475ef85 | 2007-06-24 11:17:09 +0200 | [diff] [blame] | 2630 | } |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2631 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2632 | superio_exit(sioaddr); |
Joe Perches | abdc6fd | 2010-10-20 06:51:54 +0000 | [diff] [blame] | 2633 | pr_info("Found %s chip at %#x\n", sio_name, *addr); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2634 | sio_data->sioreg = sioaddr; |
| 2635 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2636 | return 0; |
| 2637 | } |
| 2638 | |
Guenter Roeck | 8969e84 | 2012-01-19 11:02:27 -0800 | [diff] [blame^] | 2639 | /* |
| 2640 | * when Super-I/O functions move to a separate file, the Super-I/O |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2641 | * bus will manage the lifetime of the device and this module will only keep |
| 2642 | * track of the w83627ehf driver. But since we platform_device_alloc(), we |
Guenter Roeck | 8969e84 | 2012-01-19 11:02:27 -0800 | [diff] [blame^] | 2643 | * must keep track of the device |
| 2644 | */ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2645 | static struct platform_device *pdev; |
| 2646 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2647 | static int __init sensors_w83627ehf_init(void) |
| 2648 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2649 | int err; |
| 2650 | unsigned short address; |
| 2651 | struct resource res; |
| 2652 | struct w83627ehf_sio_data sio_data; |
| 2653 | |
Guenter Roeck | 8969e84 | 2012-01-19 11:02:27 -0800 | [diff] [blame^] | 2654 | /* |
| 2655 | * initialize sio_data->kind and sio_data->sioreg. |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2656 | * |
| 2657 | * when Super-I/O functions move to a separate file, the Super-I/O |
| 2658 | * driver will probe 0x2e and 0x4e and auto-detect the presence of a |
Guenter Roeck | 8969e84 | 2012-01-19 11:02:27 -0800 | [diff] [blame^] | 2659 | * w83627ehf hardware monitor, and call probe() |
| 2660 | */ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2661 | if (w83627ehf_find(0x2e, &address, &sio_data) && |
| 2662 | w83627ehf_find(0x4e, &address, &sio_data)) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2663 | return -ENODEV; |
| 2664 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2665 | err = platform_driver_register(&w83627ehf_driver); |
| 2666 | if (err) |
| 2667 | goto exit; |
| 2668 | |
Guenter Roeck | e7e1ca6 | 2011-02-04 13:24:30 -0800 | [diff] [blame] | 2669 | pdev = platform_device_alloc(DRVNAME, address); |
| 2670 | if (!pdev) { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2671 | err = -ENOMEM; |
Joe Perches | abdc6fd | 2010-10-20 06:51:54 +0000 | [diff] [blame] | 2672 | pr_err("Device allocation failed\n"); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2673 | goto exit_unregister; |
| 2674 | } |
| 2675 | |
| 2676 | err = platform_device_add_data(pdev, &sio_data, |
| 2677 | sizeof(struct w83627ehf_sio_data)); |
| 2678 | if (err) { |
Joe Perches | abdc6fd | 2010-10-20 06:51:54 +0000 | [diff] [blame] | 2679 | pr_err("Platform data allocation failed\n"); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2680 | goto exit_device_put; |
| 2681 | } |
| 2682 | |
| 2683 | memset(&res, 0, sizeof(res)); |
| 2684 | res.name = DRVNAME; |
| 2685 | res.start = address + IOREGION_OFFSET; |
| 2686 | res.end = address + IOREGION_OFFSET + IOREGION_LENGTH - 1; |
| 2687 | res.flags = IORESOURCE_IO; |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 2688 | |
| 2689 | err = acpi_check_resource_conflict(&res); |
| 2690 | if (err) |
Hans de Goede | 18632f8 | 2009-02-17 19:59:54 +0100 | [diff] [blame] | 2691 | goto exit_device_put; |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 2692 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2693 | err = platform_device_add_resources(pdev, &res, 1); |
| 2694 | if (err) { |
Joe Perches | abdc6fd | 2010-10-20 06:51:54 +0000 | [diff] [blame] | 2695 | pr_err("Device resource addition failed (%d)\n", err); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2696 | goto exit_device_put; |
| 2697 | } |
| 2698 | |
| 2699 | /* platform_device_add calls probe() */ |
| 2700 | err = platform_device_add(pdev); |
| 2701 | if (err) { |
Joe Perches | abdc6fd | 2010-10-20 06:51:54 +0000 | [diff] [blame] | 2702 | pr_err("Device addition failed (%d)\n", err); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2703 | goto exit_device_put; |
| 2704 | } |
| 2705 | |
| 2706 | return 0; |
| 2707 | |
| 2708 | exit_device_put: |
| 2709 | platform_device_put(pdev); |
| 2710 | exit_unregister: |
| 2711 | platform_driver_unregister(&w83627ehf_driver); |
| 2712 | exit: |
| 2713 | return err; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2714 | } |
| 2715 | |
| 2716 | static void __exit sensors_w83627ehf_exit(void) |
| 2717 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 2718 | platform_device_unregister(pdev); |
| 2719 | platform_driver_unregister(&w83627ehf_driver); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 2720 | } |
| 2721 | |
| 2722 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); |
| 2723 | MODULE_DESCRIPTION("W83627EHF driver"); |
| 2724 | MODULE_LICENSE("GPL"); |
| 2725 | |
| 2726 | module_init(sensors_w83627ehf_init); |
| 2727 | module_exit(sensors_w83627ehf_exit); |