Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1 | /* |
| 2 | w83627ehf - Driver for the hardware monitoring functionality of |
| 3 | the Winbond W83627EHF Super-I/O chip |
| 4 | Copyright (C) 2005 Jean Delvare <khali@linux-fr.org> |
Jean Delvare | 3379cee | 2006-09-24 21:25:52 +0200 | [diff] [blame] | 5 | Copyright (C) 2006 Yuan Mu (Winbond), |
Jean Delvare | 7188cc6 | 2006-12-12 18:18:30 +0100 | [diff] [blame] | 6 | Rudolf Marek <r.marek@assembler.cz> |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 7 | David Hubbard <david.c.hubbard@gmail.com> |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 8 | Daniel J Blueman <daniel.blueman@gmail.com> |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 9 | |
| 10 | Shamelessly ripped from the w83627hf driver |
| 11 | Copyright (C) 2003 Mark Studebaker |
| 12 | |
| 13 | Thanks to Leon Moonen, Steve Cliffe and Grant Coady for their help |
| 14 | in testing and debugging this driver. |
| 15 | |
Jean Delvare | 8dd2d2c | 2005-07-27 21:33:15 +0200 | [diff] [blame] | 16 | This driver also supports the W83627EHG, which is the lead-free |
| 17 | version of the W83627EHF. |
| 18 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 19 | This program is free software; you can redistribute it and/or modify |
| 20 | it under the terms of the GNU General Public License as published by |
| 21 | the Free Software Foundation; either version 2 of the License, or |
| 22 | (at your option) any later version. |
| 23 | |
| 24 | This program is distributed in the hope that it will be useful, |
| 25 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 | GNU General Public License for more details. |
| 28 | |
| 29 | You should have received a copy of the GNU General Public License |
| 30 | along with this program; if not, write to the Free Software |
| 31 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 32 | |
| 33 | |
| 34 | Supports the following chips: |
| 35 | |
David Hubbard | 657c93b | 2007-02-14 21:15:04 +0100 | [diff] [blame] | 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 |
Jean Delvare | c1e48dc | 2009-06-15 18:39:50 +0200 | [diff] [blame] | 40 | w83627dhg-p 9 5 4 3 0xb070 0xc1 0x5ca3 |
Gong Jun | 237c8d2f | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 41 | w83667hg 9 5 3 3 0xa510 0xc1 0x5ca3 |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 42 | w83667hg-b 9 5 3 3 0xb350 0xc1 0x5ca3 |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 43 | */ |
| 44 | |
Joe Perches | abdc6fd | 2010-10-20 06:51:54 +0000 | [diff] [blame] | 45 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 46 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 47 | #include <linux/module.h> |
| 48 | #include <linux/init.h> |
| 49 | #include <linux/slab.h> |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 50 | #include <linux/jiffies.h> |
| 51 | #include <linux/platform_device.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 52 | #include <linux/hwmon.h> |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 53 | #include <linux/hwmon-sysfs.h> |
Jean Delvare | fc18d6c | 2007-06-24 11:19:42 +0200 | [diff] [blame] | 54 | #include <linux/hwmon-vid.h> |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 55 | #include <linux/err.h> |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 56 | #include <linux/mutex.h> |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 57 | #include <linux/acpi.h> |
H Hartley Sweeten | 6055fae | 2009-09-15 17:18:13 +0200 | [diff] [blame] | 58 | #include <linux/io.h> |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 59 | #include "lm75.h" |
| 60 | |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 61 | enum kinds { w83627ehf, w83627dhg, w83627dhg_p, w83667hg, w83667hg_b }; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 62 | |
| 63 | /* used to set data->name = w83627ehf_device_names[data->sio_kind] */ |
| 64 | static const char * w83627ehf_device_names[] = { |
| 65 | "w83627ehf", |
| 66 | "w83627dhg", |
Jean Delvare | c1e48dc | 2009-06-15 18:39:50 +0200 | [diff] [blame] | 67 | "w83627dhg", |
Gong Jun | 237c8d2f | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 68 | "w83667hg", |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 69 | "w83667hg", |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 70 | }; |
| 71 | |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 72 | static unsigned short force_id; |
| 73 | module_param(force_id, ushort, 0); |
| 74 | MODULE_PARM_DESC(force_id, "Override the detected device ID"); |
| 75 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 76 | #define DRVNAME "w83627ehf" |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * Super-I/O constants and functions |
| 80 | */ |
| 81 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 82 | #define W83627EHF_LD_HWM 0x0b |
Gong Jun | 237c8d2f | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 83 | #define W83667HG_LD_VID 0x0d |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 84 | |
| 85 | #define SIO_REG_LDSEL 0x07 /* Logical device select */ |
| 86 | #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */ |
Jean Delvare | fc18d6c | 2007-06-24 11:19:42 +0200 | [diff] [blame] | 87 | #define SIO_REG_EN_VRM10 0x2C /* GPIO3, GPIO4 selection */ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 88 | #define SIO_REG_ENABLE 0x30 /* Logical device enable */ |
| 89 | #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */ |
Jean Delvare | fc18d6c | 2007-06-24 11:19:42 +0200 | [diff] [blame] | 90 | #define SIO_REG_VID_CTRL 0xF0 /* VID control */ |
| 91 | #define SIO_REG_VID_DATA 0xF1 /* VID data */ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 92 | |
David Hubbard | 657c93b | 2007-02-14 21:15:04 +0100 | [diff] [blame] | 93 | #define SIO_W83627EHF_ID 0x8850 |
| 94 | #define SIO_W83627EHG_ID 0x8860 |
| 95 | #define SIO_W83627DHG_ID 0xa020 |
Jean Delvare | c1e48dc | 2009-06-15 18:39:50 +0200 | [diff] [blame] | 96 | #define SIO_W83627DHG_P_ID 0xb070 |
Gong Jun | 237c8d2f | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 97 | #define SIO_W83667HG_ID 0xa510 |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 98 | #define SIO_W83667HG_B_ID 0xb350 |
David Hubbard | 657c93b | 2007-02-14 21:15:04 +0100 | [diff] [blame] | 99 | #define SIO_ID_MASK 0xFFF0 |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 100 | |
| 101 | static inline void |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 102 | superio_outb(int ioreg, int reg, int val) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 103 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 104 | outb(reg, ioreg); |
| 105 | outb(val, ioreg + 1); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | static inline int |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 109 | superio_inb(int ioreg, int reg) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 110 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 111 | outb(reg, ioreg); |
| 112 | return inb(ioreg + 1); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static inline void |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 116 | superio_select(int ioreg, int ld) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 117 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 118 | outb(SIO_REG_LDSEL, ioreg); |
| 119 | outb(ld, ioreg + 1); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 120 | } |
| 121 | |
| 122 | static inline void |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 123 | superio_enter(int ioreg) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 124 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 125 | outb(0x87, ioreg); |
| 126 | outb(0x87, ioreg); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | static inline void |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 130 | superio_exit(int ioreg) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 131 | { |
Jonas Jonsson | 022b75a | 2010-09-17 17:24:13 +0200 | [diff] [blame] | 132 | outb(0xaa, ioreg); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 133 | outb(0x02, ioreg); |
| 134 | outb(0x02, ioreg + 1); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | /* |
| 138 | * ISA constants |
| 139 | */ |
| 140 | |
Jean Delvare | 1a641fc | 2007-04-23 14:41:16 -0700 | [diff] [blame] | 141 | #define IOREGION_ALIGNMENT ~7 |
| 142 | #define IOREGION_OFFSET 5 |
| 143 | #define IOREGION_LENGTH 2 |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 144 | #define ADDR_REG_OFFSET 0 |
| 145 | #define DATA_REG_OFFSET 1 |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 146 | |
| 147 | #define W83627EHF_REG_BANK 0x4E |
| 148 | #define W83627EHF_REG_CONFIG 0x40 |
David Hubbard | 657c93b | 2007-02-14 21:15:04 +0100 | [diff] [blame] | 149 | |
| 150 | /* Not currently used: |
| 151 | * REG_MAN_ID has the value 0x5ca3 for all supported chips. |
| 152 | * REG_CHIP_ID == 0x88/0xa1/0xc1 depending on chip model. |
| 153 | * REG_MAN_ID is at port 0x4f |
| 154 | * REG_CHIP_ID is at port 0x58 */ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 155 | |
| 156 | static const u16 W83627EHF_REG_FAN[] = { 0x28, 0x29, 0x2a, 0x3f, 0x553 }; |
| 157 | static const u16 W83627EHF_REG_FAN_MIN[] = { 0x3b, 0x3c, 0x3d, 0x3e, 0x55c }; |
| 158 | |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 159 | /* The W83627EHF registers for nr=7,8,9 are in bank 5 */ |
| 160 | #define W83627EHF_REG_IN_MAX(nr) ((nr < 7) ? (0x2b + (nr) * 2) : \ |
| 161 | (0x554 + (((nr) - 7) * 2))) |
| 162 | #define W83627EHF_REG_IN_MIN(nr) ((nr < 7) ? (0x2c + (nr) * 2) : \ |
| 163 | (0x555 + (((nr) - 7) * 2))) |
| 164 | #define W83627EHF_REG_IN(nr) ((nr < 7) ? (0x20 + (nr)) : \ |
| 165 | (0x550 + (nr) - 7)) |
| 166 | |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 167 | static const u16 W83627EHF_REG_TEMP[] = { 0x27, 0x150, 0x250 }; |
| 168 | static const u16 W83627EHF_REG_TEMP_HYST[] = { 0x3a, 0x153, 0x253 }; |
| 169 | static const u16 W83627EHF_REG_TEMP_OVER[] = { 0x39, 0x155, 0x255 }; |
| 170 | static const u16 W83627EHF_REG_TEMP_CONFIG[] = { 0, 0x152, 0x252 }; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 171 | |
| 172 | /* Fan clock dividers are spread over the following five registers */ |
| 173 | #define W83627EHF_REG_FANDIV1 0x47 |
| 174 | #define W83627EHF_REG_FANDIV2 0x4B |
| 175 | #define W83627EHF_REG_VBAT 0x5D |
| 176 | #define W83627EHF_REG_DIODE 0x59 |
| 177 | #define W83627EHF_REG_SMI_OVT 0x4C |
| 178 | |
Jean Delvare | a4589db | 2006-03-23 16:30:29 +0100 | [diff] [blame] | 179 | #define W83627EHF_REG_ALARM1 0x459 |
| 180 | #define W83627EHF_REG_ALARM2 0x45A |
| 181 | #define W83627EHF_REG_ALARM3 0x45B |
| 182 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 183 | /* SmartFan registers */ |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 184 | #define W83627EHF_REG_FAN_STEPUP_TIME 0x0f |
| 185 | #define W83627EHF_REG_FAN_STEPDOWN_TIME 0x0e |
| 186 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 187 | /* DC or PWM output fan configuration */ |
| 188 | static const u8 W83627EHF_REG_PWM_ENABLE[] = { |
| 189 | 0x04, /* SYS FAN0 output mode and PWM mode */ |
| 190 | 0x04, /* CPU FAN0 output mode and PWM mode */ |
| 191 | 0x12, /* AUX FAN mode */ |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 192 | 0x62, /* CPU FAN1 mode */ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 193 | }; |
| 194 | |
| 195 | static const u8 W83627EHF_PWM_MODE_SHIFT[] = { 0, 1, 0, 6 }; |
| 196 | static const u8 W83627EHF_PWM_ENABLE_SHIFT[] = { 2, 4, 1, 4 }; |
| 197 | |
| 198 | /* FAN Duty Cycle, be used to control */ |
| 199 | static const u8 W83627EHF_REG_PWM[] = { 0x01, 0x03, 0x11, 0x61 }; |
| 200 | static const u8 W83627EHF_REG_TARGET[] = { 0x05, 0x06, 0x13, 0x63 }; |
| 201 | static const u8 W83627EHF_REG_TOLERANCE[] = { 0x07, 0x07, 0x14, 0x62 }; |
| 202 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 203 | /* Advanced Fan control, some values are common for all fans */ |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 204 | static const u8 W83627EHF_REG_FAN_START_OUTPUT[] = { 0x0a, 0x0b, 0x16, 0x65 }; |
| 205 | static const u8 W83627EHF_REG_FAN_STOP_OUTPUT[] = { 0x08, 0x09, 0x15, 0x64 }; |
| 206 | static const u8 W83627EHF_REG_FAN_STOP_TIME[] = { 0x0c, 0x0d, 0x17, 0x66 }; |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 207 | |
| 208 | static const u8 W83627EHF_REG_FAN_MAX_OUTPUT_COMMON[] |
| 209 | = { 0xff, 0x67, 0xff, 0x69 }; |
| 210 | static const u8 W83627EHF_REG_FAN_STEP_OUTPUT_COMMON[] |
| 211 | = { 0xff, 0x68, 0xff, 0x6a }; |
| 212 | |
| 213 | static const u8 W83627EHF_REG_FAN_MAX_OUTPUT_W83667_B[] = { 0x67, 0x69, 0x6b }; |
| 214 | static const u8 W83627EHF_REG_FAN_STEP_OUTPUT_W83667_B[] = { 0x68, 0x6a, 0x6c }; |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 215 | |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 216 | static inline int is_word_sized(u16 reg) |
| 217 | { |
| 218 | return (((reg & 0xff00) == 0x100 |
| 219 | || (reg & 0xff00) == 0x200) |
| 220 | && ((reg & 0x00ff) == 0x50 |
| 221 | || (reg & 0x00ff) == 0x53 |
| 222 | || (reg & 0x00ff) == 0x55)); |
| 223 | } |
| 224 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 225 | /* |
| 226 | * Conversions |
| 227 | */ |
| 228 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 229 | /* 1 is PWM mode, output in ms */ |
| 230 | static inline unsigned int step_time_from_reg(u8 reg, u8 mode) |
| 231 | { |
| 232 | return mode ? 100 * reg : 400 * reg; |
| 233 | } |
| 234 | |
| 235 | static inline u8 step_time_to_reg(unsigned int msec, u8 mode) |
| 236 | { |
| 237 | return SENSORS_LIMIT((mode ? (msec + 50) / 100 : |
| 238 | (msec + 200) / 400), 1, 255); |
| 239 | } |
| 240 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 241 | static inline unsigned int |
| 242 | fan_from_reg(u8 reg, unsigned int div) |
| 243 | { |
| 244 | if (reg == 0 || reg == 255) |
| 245 | return 0; |
| 246 | return 1350000U / (reg * div); |
| 247 | } |
| 248 | |
| 249 | static inline unsigned int |
| 250 | div_from_reg(u8 reg) |
| 251 | { |
| 252 | return 1 << reg; |
| 253 | } |
| 254 | |
| 255 | static inline int |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 256 | temp_from_reg(u16 reg, s16 regval) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 257 | { |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 258 | if (is_word_sized(reg)) |
| 259 | return LM75_TEMP_FROM_REG(regval); |
| 260 | return regval * 1000; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 261 | } |
| 262 | |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 263 | static inline s16 |
| 264 | temp_to_reg(u16 reg, long temp) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 265 | { |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 266 | if (is_word_sized(reg)) |
| 267 | return LM75_TEMP_TO_REG(temp); |
| 268 | return DIV_ROUND_CLOSEST(SENSORS_LIMIT(temp, -127000, 128000), 1000); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 269 | } |
| 270 | |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 271 | /* Some of analog inputs have internal scaling (2x), 8mV is ADC LSB */ |
| 272 | |
| 273 | static u8 scale_in[10] = { 8, 8, 16, 16, 8, 8, 8, 16, 16, 8 }; |
| 274 | |
| 275 | static inline long in_from_reg(u8 reg, u8 nr) |
| 276 | { |
| 277 | return reg * scale_in[nr]; |
| 278 | } |
| 279 | |
| 280 | static inline u8 in_to_reg(u32 val, u8 nr) |
| 281 | { |
| 282 | return SENSORS_LIMIT(((val + (scale_in[nr] / 2)) / scale_in[nr]), 0, 255); |
| 283 | } |
| 284 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 285 | /* |
| 286 | * Data structures and manipulation thereof |
| 287 | */ |
| 288 | |
| 289 | struct w83627ehf_data { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 290 | int addr; /* IO base of hw monitor block */ |
| 291 | const char *name; |
| 292 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 293 | struct device *hwmon_dev; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 294 | struct mutex lock; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 295 | |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 296 | const u8 *REG_FAN_START_OUTPUT; |
| 297 | const u8 *REG_FAN_STOP_OUTPUT; |
| 298 | const u8 *REG_FAN_MAX_OUTPUT; |
| 299 | const u8 *REG_FAN_STEP_OUTPUT; |
| 300 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 301 | struct mutex update_lock; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 302 | char valid; /* !=0 if following fields are valid */ |
| 303 | unsigned long last_updated; /* In jiffies */ |
| 304 | |
| 305 | /* Register values */ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 306 | u8 in_num; /* number of in inputs we have */ |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 307 | u8 in[10]; /* Register value */ |
| 308 | u8 in_max[10]; /* Register value */ |
| 309 | u8 in_min[10]; /* Register value */ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 310 | u8 fan[5]; |
| 311 | u8 fan_min[5]; |
| 312 | u8 fan_div[5]; |
| 313 | u8 has_fan; /* some fan inputs can be disabled */ |
Jean Delvare | da66736 | 2007-06-24 11:21:02 +0200 | [diff] [blame] | 314 | u8 temp_type[3]; |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 315 | s16 temp[3]; |
| 316 | s16 temp_max[3]; |
| 317 | s16 temp_max_hyst[3]; |
Jean Delvare | a4589db | 2006-03-23 16:30:29 +0100 | [diff] [blame] | 318 | u32 alarms; |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 319 | |
| 320 | u8 pwm_mode[4]; /* 0->DC variable voltage, 1->PWM variable duty cycle */ |
| 321 | u8 pwm_enable[4]; /* 1->manual |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 322 | 2->thermal cruise mode (also called SmartFan I) |
| 323 | 3->fan speed cruise mode |
| 324 | 4->variable thermal cruise (also called SmartFan III) */ |
Gong Jun | 237c8d2f | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 325 | u8 pwm_num; /* number of pwm */ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 326 | u8 pwm[4]; |
| 327 | u8 target_temp[4]; |
| 328 | u8 tolerance[4]; |
| 329 | |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 330 | u8 fan_start_output[4]; /* minimum fan speed when spinning up */ |
| 331 | u8 fan_stop_output[4]; /* minimum fan speed when spinning down */ |
| 332 | u8 fan_stop_time[4]; /* time at minimum before disabling fan */ |
| 333 | u8 fan_max_output[4]; /* maximum fan speed */ |
| 334 | u8 fan_step_output[4]; /* rate of change output value */ |
Jean Delvare | fc18d6c | 2007-06-24 11:19:42 +0200 | [diff] [blame] | 335 | |
| 336 | u8 vid; |
| 337 | u8 vrm; |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 338 | |
| 339 | u8 temp3_disable; |
| 340 | u8 in6_skip; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 341 | }; |
| 342 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 343 | struct w83627ehf_sio_data { |
| 344 | int sioreg; |
| 345 | enum kinds kind; |
| 346 | }; |
| 347 | |
Jean Delvare | 0956895 | 2007-08-11 13:57:05 +0200 | [diff] [blame] | 348 | /* Registers 0x50-0x5f are banked */ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 349 | static inline void w83627ehf_set_bank(struct w83627ehf_data *data, u16 reg) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 350 | { |
Jean Delvare | 0956895 | 2007-08-11 13:57:05 +0200 | [diff] [blame] | 351 | if ((reg & 0x00f0) == 0x50) { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 352 | outb_p(W83627EHF_REG_BANK, data->addr + ADDR_REG_OFFSET); |
| 353 | outb_p(reg >> 8, data->addr + DATA_REG_OFFSET); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | |
Jean Delvare | 0956895 | 2007-08-11 13:57:05 +0200 | [diff] [blame] | 357 | /* Not strictly necessary, but play it safe for now */ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 358 | static inline void w83627ehf_reset_bank(struct w83627ehf_data *data, u16 reg) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 359 | { |
| 360 | if (reg & 0xff00) { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 361 | outb_p(W83627EHF_REG_BANK, data->addr + ADDR_REG_OFFSET); |
| 362 | outb_p(0, data->addr + DATA_REG_OFFSET); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 363 | } |
| 364 | } |
| 365 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 366 | static u16 w83627ehf_read_value(struct w83627ehf_data *data, u16 reg) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 367 | { |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 368 | int res, word_sized = is_word_sized(reg); |
| 369 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 370 | mutex_lock(&data->lock); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 371 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 372 | w83627ehf_set_bank(data, reg); |
| 373 | outb_p(reg & 0xff, data->addr + ADDR_REG_OFFSET); |
| 374 | res = inb_p(data->addr + DATA_REG_OFFSET); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 375 | if (word_sized) { |
| 376 | outb_p((reg & 0xff) + 1, |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 377 | data->addr + ADDR_REG_OFFSET); |
| 378 | res = (res << 8) + inb_p(data->addr + DATA_REG_OFFSET); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 379 | } |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 380 | w83627ehf_reset_bank(data, reg); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 381 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 382 | mutex_unlock(&data->lock); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 383 | |
| 384 | return res; |
| 385 | } |
| 386 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 387 | static int w83627ehf_write_value(struct w83627ehf_data *data, u16 reg, u16 value) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 388 | { |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 389 | int word_sized = is_word_sized(reg); |
| 390 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 391 | mutex_lock(&data->lock); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 392 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 393 | w83627ehf_set_bank(data, reg); |
| 394 | outb_p(reg & 0xff, data->addr + ADDR_REG_OFFSET); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 395 | if (word_sized) { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 396 | outb_p(value >> 8, data->addr + DATA_REG_OFFSET); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 397 | outb_p((reg & 0xff) + 1, |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 398 | data->addr + ADDR_REG_OFFSET); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 399 | } |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 400 | outb_p(value & 0xff, data->addr + DATA_REG_OFFSET); |
| 401 | w83627ehf_reset_bank(data, reg); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 402 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 403 | mutex_unlock(&data->lock); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 404 | return 0; |
| 405 | } |
| 406 | |
| 407 | /* This function assumes that the caller holds data->update_lock */ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 408 | static void w83627ehf_write_fan_div(struct w83627ehf_data *data, int nr) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 409 | { |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 410 | u8 reg; |
| 411 | |
| 412 | switch (nr) { |
| 413 | case 0: |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 414 | reg = (w83627ehf_read_value(data, W83627EHF_REG_FANDIV1) & 0xcf) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 415 | | ((data->fan_div[0] & 0x03) << 4); |
Rudolf Marek | 14992c7 | 2006-10-08 22:02:09 +0200 | [diff] [blame] | 416 | /* fan5 input control bit is write only, compute the value */ |
| 417 | reg |= (data->has_fan & (1 << 4)) ? 1 : 0; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 418 | w83627ehf_write_value(data, W83627EHF_REG_FANDIV1, reg); |
| 419 | reg = (w83627ehf_read_value(data, W83627EHF_REG_VBAT) & 0xdf) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 420 | | ((data->fan_div[0] & 0x04) << 3); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 421 | w83627ehf_write_value(data, W83627EHF_REG_VBAT, reg); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 422 | break; |
| 423 | case 1: |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 424 | reg = (w83627ehf_read_value(data, W83627EHF_REG_FANDIV1) & 0x3f) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 425 | | ((data->fan_div[1] & 0x03) << 6); |
Rudolf Marek | 14992c7 | 2006-10-08 22:02:09 +0200 | [diff] [blame] | 426 | /* fan5 input control bit is write only, compute the value */ |
| 427 | reg |= (data->has_fan & (1 << 4)) ? 1 : 0; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 428 | w83627ehf_write_value(data, W83627EHF_REG_FANDIV1, reg); |
| 429 | reg = (w83627ehf_read_value(data, W83627EHF_REG_VBAT) & 0xbf) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 430 | | ((data->fan_div[1] & 0x04) << 4); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 431 | w83627ehf_write_value(data, W83627EHF_REG_VBAT, reg); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 432 | break; |
| 433 | case 2: |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 434 | reg = (w83627ehf_read_value(data, W83627EHF_REG_FANDIV2) & 0x3f) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 435 | | ((data->fan_div[2] & 0x03) << 6); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 436 | w83627ehf_write_value(data, W83627EHF_REG_FANDIV2, reg); |
| 437 | reg = (w83627ehf_read_value(data, W83627EHF_REG_VBAT) & 0x7f) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 438 | | ((data->fan_div[2] & 0x04) << 5); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 439 | w83627ehf_write_value(data, W83627EHF_REG_VBAT, reg); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 440 | break; |
| 441 | case 3: |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 442 | reg = (w83627ehf_read_value(data, W83627EHF_REG_DIODE) & 0xfc) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 443 | | (data->fan_div[3] & 0x03); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 444 | w83627ehf_write_value(data, W83627EHF_REG_DIODE, reg); |
| 445 | reg = (w83627ehf_read_value(data, W83627EHF_REG_SMI_OVT) & 0x7f) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 446 | | ((data->fan_div[3] & 0x04) << 5); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 447 | w83627ehf_write_value(data, W83627EHF_REG_SMI_OVT, reg); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 448 | break; |
| 449 | case 4: |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 450 | reg = (w83627ehf_read_value(data, W83627EHF_REG_DIODE) & 0x73) |
Jean Delvare | 33725ad | 2007-04-17 00:32:27 -0700 | [diff] [blame] | 451 | | ((data->fan_div[4] & 0x03) << 2) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 452 | | ((data->fan_div[4] & 0x04) << 5); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 453 | w83627ehf_write_value(data, W83627EHF_REG_DIODE, reg); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 454 | break; |
| 455 | } |
| 456 | } |
| 457 | |
Mark M. Hoffman | ea7be66 | 2007-08-05 12:19:01 -0400 | [diff] [blame] | 458 | static void w83627ehf_update_fan_div(struct w83627ehf_data *data) |
| 459 | { |
| 460 | int i; |
| 461 | |
| 462 | i = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1); |
| 463 | data->fan_div[0] = (i >> 4) & 0x03; |
| 464 | data->fan_div[1] = (i >> 6) & 0x03; |
| 465 | i = w83627ehf_read_value(data, W83627EHF_REG_FANDIV2); |
| 466 | data->fan_div[2] = (i >> 6) & 0x03; |
| 467 | i = w83627ehf_read_value(data, W83627EHF_REG_VBAT); |
| 468 | data->fan_div[0] |= (i >> 3) & 0x04; |
| 469 | data->fan_div[1] |= (i >> 4) & 0x04; |
| 470 | data->fan_div[2] |= (i >> 5) & 0x04; |
| 471 | if (data->has_fan & ((1 << 3) | (1 << 4))) { |
| 472 | i = w83627ehf_read_value(data, W83627EHF_REG_DIODE); |
| 473 | data->fan_div[3] = i & 0x03; |
| 474 | data->fan_div[4] = ((i >> 2) & 0x03) |
| 475 | | ((i >> 5) & 0x04); |
| 476 | } |
| 477 | if (data->has_fan & (1 << 3)) { |
| 478 | i = w83627ehf_read_value(data, W83627EHF_REG_SMI_OVT); |
| 479 | data->fan_div[3] |= (i >> 5) & 0x04; |
| 480 | } |
| 481 | } |
| 482 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 483 | static struct w83627ehf_data *w83627ehf_update_device(struct device *dev) |
| 484 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 485 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 486 | int pwmcfg = 0, tolerance = 0; /* shut up the compiler */ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 487 | int i; |
| 488 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 489 | mutex_lock(&data->update_lock); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 490 | |
Jean Delvare | 6b3e464 | 2007-06-24 11:19:01 +0200 | [diff] [blame] | 491 | if (time_after(jiffies, data->last_updated + HZ + HZ/2) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 492 | || !data->valid) { |
| 493 | /* Fan clock dividers */ |
Mark M. Hoffman | ea7be66 | 2007-08-05 12:19:01 -0400 | [diff] [blame] | 494 | w83627ehf_update_fan_div(data); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 495 | |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 496 | /* Measured voltages and limits */ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 497 | for (i = 0; i < data->in_num; i++) { |
| 498 | data->in[i] = w83627ehf_read_value(data, |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 499 | W83627EHF_REG_IN(i)); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 500 | data->in_min[i] = w83627ehf_read_value(data, |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 501 | W83627EHF_REG_IN_MIN(i)); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 502 | data->in_max[i] = w83627ehf_read_value(data, |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 503 | W83627EHF_REG_IN_MAX(i)); |
| 504 | } |
| 505 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 506 | /* Measured fan speeds and limits */ |
| 507 | for (i = 0; i < 5; i++) { |
| 508 | if (!(data->has_fan & (1 << i))) |
| 509 | continue; |
| 510 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 511 | data->fan[i] = w83627ehf_read_value(data, |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 512 | W83627EHF_REG_FAN[i]); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 513 | data->fan_min[i] = w83627ehf_read_value(data, |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 514 | W83627EHF_REG_FAN_MIN[i]); |
| 515 | |
| 516 | /* If we failed to measure the fan speed and clock |
| 517 | divider can be increased, let's try that for next |
| 518 | time */ |
| 519 | if (data->fan[i] == 0xff |
| 520 | && data->fan_div[i] < 0x07) { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 521 | dev_dbg(dev, "Increasing fan%d " |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 522 | "clock divider from %u to %u\n", |
Jean Delvare | 33725ad | 2007-04-17 00:32:27 -0700 | [diff] [blame] | 523 | i + 1, div_from_reg(data->fan_div[i]), |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 524 | div_from_reg(data->fan_div[i] + 1)); |
| 525 | data->fan_div[i]++; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 526 | w83627ehf_write_fan_div(data, i); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 527 | /* Preserve min limit if possible */ |
| 528 | if (data->fan_min[i] >= 2 |
| 529 | && data->fan_min[i] != 255) |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 530 | w83627ehf_write_value(data, |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 531 | W83627EHF_REG_FAN_MIN[i], |
| 532 | (data->fan_min[i] /= 2)); |
| 533 | } |
| 534 | } |
| 535 | |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 536 | for (i = 0; i < data->pwm_num; i++) { |
| 537 | if (!(data->has_fan & (1 << i))) |
| 538 | continue; |
| 539 | |
Jean Delvare | 77fa49d | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 540 | /* pwmcfg, tolerance mapped for i=0, i=1 to same reg */ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 541 | if (i != 1) { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 542 | pwmcfg = w83627ehf_read_value(data, |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 543 | W83627EHF_REG_PWM_ENABLE[i]); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 544 | tolerance = w83627ehf_read_value(data, |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 545 | W83627EHF_REG_TOLERANCE[i]); |
| 546 | } |
| 547 | data->pwm_mode[i] = |
| 548 | ((pwmcfg >> W83627EHF_PWM_MODE_SHIFT[i]) & 1) |
| 549 | ? 0 : 1; |
| 550 | data->pwm_enable[i] = |
| 551 | ((pwmcfg >> W83627EHF_PWM_ENABLE_SHIFT[i]) |
| 552 | & 3) + 1; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 553 | data->pwm[i] = w83627ehf_read_value(data, |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 554 | W83627EHF_REG_PWM[i]); |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 555 | data->fan_start_output[i] = w83627ehf_read_value(data, |
| 556 | W83627EHF_REG_FAN_START_OUTPUT[i]); |
| 557 | data->fan_stop_output[i] = w83627ehf_read_value(data, |
| 558 | W83627EHF_REG_FAN_STOP_OUTPUT[i]); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 559 | data->fan_stop_time[i] = w83627ehf_read_value(data, |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 560 | W83627EHF_REG_FAN_STOP_TIME[i]); |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 561 | |
| 562 | if (data->REG_FAN_MAX_OUTPUT[i] != 0xff) |
| 563 | data->fan_max_output[i] = |
| 564 | w83627ehf_read_value(data, |
| 565 | data->REG_FAN_MAX_OUTPUT[i]); |
| 566 | |
| 567 | if (data->REG_FAN_STEP_OUTPUT[i] != 0xff) |
| 568 | data->fan_step_output[i] = |
| 569 | w83627ehf_read_value(data, |
| 570 | data->REG_FAN_STEP_OUTPUT[i]); |
| 571 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 572 | data->target_temp[i] = |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 573 | w83627ehf_read_value(data, |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 574 | W83627EHF_REG_TARGET[i]) & |
| 575 | (data->pwm_mode[i] == 1 ? 0x7f : 0xff); |
| 576 | data->tolerance[i] = (tolerance >> (i == 1 ? 4 : 0)) |
| 577 | & 0x0f; |
| 578 | } |
| 579 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 580 | /* Measured temperatures and limits */ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 581 | for (i = 0; i < 3; i++) { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 582 | data->temp[i] = w83627ehf_read_value(data, |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 583 | W83627EHF_REG_TEMP[i]); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 584 | data->temp_max[i] = w83627ehf_read_value(data, |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 585 | W83627EHF_REG_TEMP_OVER[i]); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 586 | data->temp_max_hyst[i] = w83627ehf_read_value(data, |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 587 | W83627EHF_REG_TEMP_HYST[i]); |
| 588 | } |
| 589 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 590 | data->alarms = w83627ehf_read_value(data, |
Jean Delvare | a4589db | 2006-03-23 16:30:29 +0100 | [diff] [blame] | 591 | W83627EHF_REG_ALARM1) | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 592 | (w83627ehf_read_value(data, |
Jean Delvare | a4589db | 2006-03-23 16:30:29 +0100 | [diff] [blame] | 593 | W83627EHF_REG_ALARM2) << 8) | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 594 | (w83627ehf_read_value(data, |
Jean Delvare | a4589db | 2006-03-23 16:30:29 +0100 | [diff] [blame] | 595 | W83627EHF_REG_ALARM3) << 16); |
| 596 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 597 | data->last_updated = jiffies; |
| 598 | data->valid = 1; |
| 599 | } |
| 600 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 601 | mutex_unlock(&data->update_lock); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 602 | return data; |
| 603 | } |
| 604 | |
| 605 | /* |
| 606 | * Sysfs callback functions |
| 607 | */ |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 608 | #define show_in_reg(reg) \ |
| 609 | static ssize_t \ |
| 610 | show_##reg(struct device *dev, struct device_attribute *attr, \ |
| 611 | char *buf) \ |
| 612 | { \ |
| 613 | struct w83627ehf_data *data = w83627ehf_update_device(dev); \ |
| 614 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ |
| 615 | int nr = sensor_attr->index; \ |
| 616 | return sprintf(buf, "%ld\n", in_from_reg(data->reg[nr], nr)); \ |
| 617 | } |
| 618 | show_in_reg(in) |
| 619 | show_in_reg(in_min) |
| 620 | show_in_reg(in_max) |
| 621 | |
| 622 | #define store_in_reg(REG, reg) \ |
| 623 | static ssize_t \ |
| 624 | store_in_##reg (struct device *dev, struct device_attribute *attr, \ |
| 625 | const char *buf, size_t count) \ |
| 626 | { \ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 627 | struct w83627ehf_data *data = dev_get_drvdata(dev); \ |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 628 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ |
| 629 | int nr = sensor_attr->index; \ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 630 | unsigned long val; \ |
| 631 | int err; \ |
| 632 | err = strict_strtoul(buf, 10, &val); \ |
| 633 | if (err < 0) \ |
| 634 | return err; \ |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 635 | mutex_lock(&data->update_lock); \ |
| 636 | data->in_##reg[nr] = in_to_reg(val, nr); \ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 637 | w83627ehf_write_value(data, W83627EHF_REG_IN_##REG(nr), \ |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 638 | data->in_##reg[nr]); \ |
| 639 | mutex_unlock(&data->update_lock); \ |
| 640 | return count; \ |
| 641 | } |
| 642 | |
| 643 | store_in_reg(MIN, min) |
| 644 | store_in_reg(MAX, max) |
| 645 | |
Jean Delvare | a4589db | 2006-03-23 16:30:29 +0100 | [diff] [blame] | 646 | static ssize_t show_alarm(struct device *dev, struct device_attribute *attr, char *buf) |
| 647 | { |
| 648 | struct w83627ehf_data *data = w83627ehf_update_device(dev); |
| 649 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 650 | int nr = sensor_attr->index; |
| 651 | return sprintf(buf, "%u\n", (data->alarms >> nr) & 0x01); |
| 652 | } |
| 653 | |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 654 | static struct sensor_device_attribute sda_in_input[] = { |
| 655 | SENSOR_ATTR(in0_input, S_IRUGO, show_in, NULL, 0), |
| 656 | SENSOR_ATTR(in1_input, S_IRUGO, show_in, NULL, 1), |
| 657 | SENSOR_ATTR(in2_input, S_IRUGO, show_in, NULL, 2), |
| 658 | SENSOR_ATTR(in3_input, S_IRUGO, show_in, NULL, 3), |
| 659 | SENSOR_ATTR(in4_input, S_IRUGO, show_in, NULL, 4), |
| 660 | SENSOR_ATTR(in5_input, S_IRUGO, show_in, NULL, 5), |
| 661 | SENSOR_ATTR(in6_input, S_IRUGO, show_in, NULL, 6), |
| 662 | SENSOR_ATTR(in7_input, S_IRUGO, show_in, NULL, 7), |
| 663 | SENSOR_ATTR(in8_input, S_IRUGO, show_in, NULL, 8), |
| 664 | SENSOR_ATTR(in9_input, S_IRUGO, show_in, NULL, 9), |
| 665 | }; |
| 666 | |
Jean Delvare | a4589db | 2006-03-23 16:30:29 +0100 | [diff] [blame] | 667 | static struct sensor_device_attribute sda_in_alarm[] = { |
| 668 | SENSOR_ATTR(in0_alarm, S_IRUGO, show_alarm, NULL, 0), |
| 669 | SENSOR_ATTR(in1_alarm, S_IRUGO, show_alarm, NULL, 1), |
| 670 | SENSOR_ATTR(in2_alarm, S_IRUGO, show_alarm, NULL, 2), |
| 671 | SENSOR_ATTR(in3_alarm, S_IRUGO, show_alarm, NULL, 3), |
| 672 | SENSOR_ATTR(in4_alarm, S_IRUGO, show_alarm, NULL, 8), |
| 673 | SENSOR_ATTR(in5_alarm, S_IRUGO, show_alarm, NULL, 21), |
| 674 | SENSOR_ATTR(in6_alarm, S_IRUGO, show_alarm, NULL, 20), |
| 675 | SENSOR_ATTR(in7_alarm, S_IRUGO, show_alarm, NULL, 16), |
| 676 | SENSOR_ATTR(in8_alarm, S_IRUGO, show_alarm, NULL, 17), |
| 677 | SENSOR_ATTR(in9_alarm, S_IRUGO, show_alarm, NULL, 19), |
| 678 | }; |
| 679 | |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 680 | static struct sensor_device_attribute sda_in_min[] = { |
| 681 | SENSOR_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 0), |
| 682 | SENSOR_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 1), |
| 683 | SENSOR_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 2), |
| 684 | SENSOR_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 3), |
| 685 | SENSOR_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 4), |
| 686 | SENSOR_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 5), |
| 687 | SENSOR_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 6), |
| 688 | SENSOR_ATTR(in7_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 7), |
| 689 | SENSOR_ATTR(in8_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 8), |
| 690 | SENSOR_ATTR(in9_min, S_IWUSR | S_IRUGO, show_in_min, store_in_min, 9), |
| 691 | }; |
| 692 | |
| 693 | static struct sensor_device_attribute sda_in_max[] = { |
| 694 | SENSOR_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 0), |
| 695 | SENSOR_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 1), |
| 696 | SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 2), |
| 697 | SENSOR_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 3), |
| 698 | SENSOR_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 4), |
| 699 | SENSOR_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 5), |
| 700 | SENSOR_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 6), |
| 701 | SENSOR_ATTR(in7_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 7), |
| 702 | SENSOR_ATTR(in8_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 8), |
| 703 | SENSOR_ATTR(in9_max, S_IWUSR | S_IRUGO, show_in_max, store_in_max, 9), |
| 704 | }; |
| 705 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 706 | #define show_fan_reg(reg) \ |
| 707 | static ssize_t \ |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 708 | show_##reg(struct device *dev, struct device_attribute *attr, \ |
| 709 | char *buf) \ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 710 | { \ |
| 711 | struct w83627ehf_data *data = w83627ehf_update_device(dev); \ |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 712 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ |
| 713 | int nr = sensor_attr->index; \ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 714 | return sprintf(buf, "%d\n", \ |
| 715 | fan_from_reg(data->reg[nr], \ |
| 716 | div_from_reg(data->fan_div[nr]))); \ |
| 717 | } |
| 718 | show_fan_reg(fan); |
| 719 | show_fan_reg(fan_min); |
| 720 | |
| 721 | static ssize_t |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 722 | show_fan_div(struct device *dev, struct device_attribute *attr, |
| 723 | char *buf) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 724 | { |
| 725 | struct w83627ehf_data *data = w83627ehf_update_device(dev); |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 726 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 727 | int nr = sensor_attr->index; |
| 728 | return sprintf(buf, "%u\n", div_from_reg(data->fan_div[nr])); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 729 | } |
| 730 | |
| 731 | static ssize_t |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 732 | store_fan_min(struct device *dev, struct device_attribute *attr, |
| 733 | const char *buf, size_t count) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 734 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 735 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 736 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 737 | int nr = sensor_attr->index; |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 738 | unsigned long val; |
| 739 | int err; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 740 | unsigned int reg; |
| 741 | u8 new_div; |
| 742 | |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 743 | err = strict_strtoul(buf, 10, &val); |
| 744 | if (err < 0) |
| 745 | return err; |
| 746 | |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 747 | mutex_lock(&data->update_lock); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 748 | if (!val) { |
| 749 | /* No min limit, alarm disabled */ |
| 750 | data->fan_min[nr] = 255; |
| 751 | new_div = data->fan_div[nr]; /* No change */ |
| 752 | dev_info(dev, "fan%u low limit and alarm disabled\n", nr + 1); |
| 753 | } else if ((reg = 1350000U / val) >= 128 * 255) { |
| 754 | /* Speed below this value cannot possibly be represented, |
| 755 | even with the highest divider (128) */ |
| 756 | data->fan_min[nr] = 254; |
| 757 | new_div = 7; /* 128 == (1 << 7) */ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 758 | dev_warn(dev, "fan%u low limit %lu below minimum %u, set to " |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 759 | "minimum\n", nr + 1, val, fan_from_reg(254, 128)); |
| 760 | } else if (!reg) { |
| 761 | /* Speed above this value cannot possibly be represented, |
| 762 | even with the lowest divider (1) */ |
| 763 | data->fan_min[nr] = 1; |
| 764 | new_div = 0; /* 1 == (1 << 0) */ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 765 | dev_warn(dev, "fan%u low limit %lu above maximum %u, set to " |
Jean Delvare | b9110b1 | 2005-05-02 23:08:22 +0200 | [diff] [blame] | 766 | "maximum\n", nr + 1, val, fan_from_reg(1, 1)); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 767 | } else { |
| 768 | /* Automatically pick the best divider, i.e. the one such |
| 769 | that the min limit will correspond to a register value |
| 770 | in the 96..192 range */ |
| 771 | new_div = 0; |
| 772 | while (reg > 192 && new_div < 7) { |
| 773 | reg >>= 1; |
| 774 | new_div++; |
| 775 | } |
| 776 | data->fan_min[nr] = reg; |
| 777 | } |
| 778 | |
| 779 | /* Write both the fan clock divider (if it changed) and the new |
| 780 | fan min (unconditionally) */ |
| 781 | if (new_div != data->fan_div[nr]) { |
Jean Delvare | 158ce07 | 2007-06-17 16:09:12 +0200 | [diff] [blame] | 782 | /* Preserve the fan speed reading */ |
| 783 | if (data->fan[nr] != 0xff) { |
| 784 | if (new_div > data->fan_div[nr]) |
| 785 | data->fan[nr] >>= new_div - data->fan_div[nr]; |
| 786 | else if (data->fan[nr] & 0x80) |
| 787 | data->fan[nr] = 0xff; |
| 788 | else |
| 789 | data->fan[nr] <<= data->fan_div[nr] - new_div; |
| 790 | } |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 791 | |
| 792 | dev_dbg(dev, "fan%u clock divider changed from %u to %u\n", |
| 793 | nr + 1, div_from_reg(data->fan_div[nr]), |
| 794 | div_from_reg(new_div)); |
| 795 | data->fan_div[nr] = new_div; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 796 | w83627ehf_write_fan_div(data, nr); |
Jean Delvare | 6b3e464 | 2007-06-24 11:19:01 +0200 | [diff] [blame] | 797 | /* Give the chip time to sample a new speed value */ |
| 798 | data->last_updated = jiffies; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 799 | } |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 800 | w83627ehf_write_value(data, W83627EHF_REG_FAN_MIN[nr], |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 801 | data->fan_min[nr]); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 802 | mutex_unlock(&data->update_lock); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 803 | |
| 804 | return count; |
| 805 | } |
| 806 | |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 807 | static struct sensor_device_attribute sda_fan_input[] = { |
| 808 | SENSOR_ATTR(fan1_input, S_IRUGO, show_fan, NULL, 0), |
| 809 | SENSOR_ATTR(fan2_input, S_IRUGO, show_fan, NULL, 1), |
| 810 | SENSOR_ATTR(fan3_input, S_IRUGO, show_fan, NULL, 2), |
| 811 | SENSOR_ATTR(fan4_input, S_IRUGO, show_fan, NULL, 3), |
| 812 | SENSOR_ATTR(fan5_input, S_IRUGO, show_fan, NULL, 4), |
| 813 | }; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 814 | |
Jean Delvare | a4589db | 2006-03-23 16:30:29 +0100 | [diff] [blame] | 815 | static struct sensor_device_attribute sda_fan_alarm[] = { |
| 816 | SENSOR_ATTR(fan1_alarm, S_IRUGO, show_alarm, NULL, 6), |
| 817 | SENSOR_ATTR(fan2_alarm, S_IRUGO, show_alarm, NULL, 7), |
| 818 | SENSOR_ATTR(fan3_alarm, S_IRUGO, show_alarm, NULL, 11), |
| 819 | SENSOR_ATTR(fan4_alarm, S_IRUGO, show_alarm, NULL, 10), |
| 820 | SENSOR_ATTR(fan5_alarm, S_IRUGO, show_alarm, NULL, 23), |
| 821 | }; |
| 822 | |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 823 | static struct sensor_device_attribute sda_fan_min[] = { |
| 824 | SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, |
| 825 | store_fan_min, 0), |
| 826 | SENSOR_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min, |
| 827 | store_fan_min, 1), |
| 828 | SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, |
| 829 | store_fan_min, 2), |
| 830 | SENSOR_ATTR(fan4_min, S_IWUSR | S_IRUGO, show_fan_min, |
| 831 | store_fan_min, 3), |
| 832 | SENSOR_ATTR(fan5_min, S_IWUSR | S_IRUGO, show_fan_min, |
| 833 | store_fan_min, 4), |
| 834 | }; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 835 | |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 836 | static struct sensor_device_attribute sda_fan_div[] = { |
| 837 | SENSOR_ATTR(fan1_div, S_IRUGO, show_fan_div, NULL, 0), |
| 838 | SENSOR_ATTR(fan2_div, S_IRUGO, show_fan_div, NULL, 1), |
| 839 | SENSOR_ATTR(fan3_div, S_IRUGO, show_fan_div, NULL, 2), |
| 840 | SENSOR_ATTR(fan4_div, S_IRUGO, show_fan_div, NULL, 3), |
| 841 | SENSOR_ATTR(fan5_div, S_IRUGO, show_fan_div, NULL, 4), |
| 842 | }; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 843 | |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 844 | #define show_temp_reg(REG, reg) \ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 845 | static ssize_t \ |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 846 | show_##reg(struct device *dev, struct device_attribute *attr, \ |
| 847 | char *buf) \ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 848 | { \ |
| 849 | struct w83627ehf_data *data = w83627ehf_update_device(dev); \ |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 850 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ |
| 851 | int nr = sensor_attr->index; \ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 852 | return sprintf(buf, "%d\n", \ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 853 | temp_from_reg(W83627EHF_REG_##REG[nr], data->reg[nr])); \ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 854 | } |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 855 | show_temp_reg(TEMP, temp); |
| 856 | show_temp_reg(TEMP_OVER, temp_max); |
| 857 | show_temp_reg(TEMP_HYST, temp_max_hyst); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 858 | |
| 859 | #define store_temp_reg(REG, reg) \ |
| 860 | static ssize_t \ |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 861 | store_##reg(struct device *dev, struct device_attribute *attr, \ |
| 862 | const char *buf, size_t count) \ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 863 | { \ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 864 | struct w83627ehf_data *data = dev_get_drvdata(dev); \ |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 865 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ |
| 866 | int nr = sensor_attr->index; \ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 867 | int err; \ |
| 868 | long val; \ |
| 869 | err = strict_strtol(buf, 10, &val); \ |
| 870 | if (err < 0) \ |
| 871 | return err; \ |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 872 | mutex_lock(&data->update_lock); \ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 873 | data->reg[nr] = temp_to_reg(W83627EHF_REG_TEMP_##REG[nr], val); \ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 874 | w83627ehf_write_value(data, W83627EHF_REG_TEMP_##REG[nr], \ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 875 | data->reg[nr]); \ |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 876 | mutex_unlock(&data->update_lock); \ |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 877 | return count; \ |
| 878 | } |
| 879 | store_temp_reg(OVER, temp_max); |
| 880 | store_temp_reg(HYST, temp_max_hyst); |
| 881 | |
Jean Delvare | da66736 | 2007-06-24 11:21:02 +0200 | [diff] [blame] | 882 | static ssize_t |
| 883 | show_temp_type(struct device *dev, struct device_attribute *attr, char *buf) |
| 884 | { |
| 885 | struct w83627ehf_data *data = w83627ehf_update_device(dev); |
| 886 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 887 | int nr = sensor_attr->index; |
| 888 | return sprintf(buf, "%d\n", (int)data->temp_type[nr]); |
| 889 | } |
| 890 | |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 891 | static struct sensor_device_attribute sda_temp_input[] = { |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 892 | SENSOR_ATTR(temp1_input, S_IRUGO, show_temp, NULL, 0), |
| 893 | SENSOR_ATTR(temp2_input, S_IRUGO, show_temp, NULL, 1), |
| 894 | SENSOR_ATTR(temp3_input, S_IRUGO, show_temp, NULL, 2), |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 895 | }; |
| 896 | |
| 897 | static struct sensor_device_attribute sda_temp_max[] = { |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 898 | SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR, show_temp_max, |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 899 | store_temp_max, 0), |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 900 | SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR, show_temp_max, |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 901 | store_temp_max, 1), |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 902 | SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR, show_temp_max, |
| 903 | store_temp_max, 2), |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 904 | }; |
| 905 | |
| 906 | static struct sensor_device_attribute sda_temp_max_hyst[] = { |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 907 | 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] | 908 | store_temp_max_hyst, 0), |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 909 | 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] | 910 | store_temp_max_hyst, 1), |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 911 | SENSOR_ATTR(temp3_max_hyst, S_IRUGO | S_IWUSR, show_temp_max_hyst, |
| 912 | store_temp_max_hyst, 2), |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 913 | }; |
| 914 | |
| 915 | static struct sensor_device_attribute sda_temp_alarm[] = { |
Jean Delvare | a4589db | 2006-03-23 16:30:29 +0100 | [diff] [blame] | 916 | SENSOR_ATTR(temp1_alarm, S_IRUGO, show_alarm, NULL, 4), |
| 917 | SENSOR_ATTR(temp2_alarm, S_IRUGO, show_alarm, NULL, 5), |
| 918 | SENSOR_ATTR(temp3_alarm, S_IRUGO, show_alarm, NULL, 13), |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 919 | }; |
| 920 | |
| 921 | static struct sensor_device_attribute sda_temp_type[] = { |
Jean Delvare | da66736 | 2007-06-24 11:21:02 +0200 | [diff] [blame] | 922 | SENSOR_ATTR(temp1_type, S_IRUGO, show_temp_type, NULL, 0), |
| 923 | SENSOR_ATTR(temp2_type, S_IRUGO, show_temp_type, NULL, 1), |
| 924 | SENSOR_ATTR(temp3_type, S_IRUGO, show_temp_type, NULL, 2), |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 925 | }; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 926 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 927 | #define show_pwm_reg(reg) \ |
| 928 | static ssize_t show_##reg (struct device *dev, struct device_attribute *attr, \ |
| 929 | char *buf) \ |
| 930 | { \ |
| 931 | struct w83627ehf_data *data = w83627ehf_update_device(dev); \ |
| 932 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ |
| 933 | int nr = sensor_attr->index; \ |
| 934 | return sprintf(buf, "%d\n", data->reg[nr]); \ |
| 935 | } |
| 936 | |
| 937 | show_pwm_reg(pwm_mode) |
| 938 | show_pwm_reg(pwm_enable) |
| 939 | show_pwm_reg(pwm) |
| 940 | |
| 941 | static ssize_t |
| 942 | store_pwm_mode(struct device *dev, struct device_attribute *attr, |
| 943 | const char *buf, size_t count) |
| 944 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 945 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 946 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 947 | int nr = sensor_attr->index; |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 948 | unsigned long val; |
| 949 | int err; |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 950 | u16 reg; |
| 951 | |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 952 | err = strict_strtoul(buf, 10, &val); |
| 953 | if (err < 0) |
| 954 | return err; |
| 955 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 956 | if (val > 1) |
| 957 | return -EINVAL; |
| 958 | mutex_lock(&data->update_lock); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 959 | reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[nr]); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 960 | data->pwm_mode[nr] = val; |
| 961 | reg &= ~(1 << W83627EHF_PWM_MODE_SHIFT[nr]); |
| 962 | if (!val) |
| 963 | reg |= 1 << W83627EHF_PWM_MODE_SHIFT[nr]; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 964 | w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[nr], reg); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 965 | mutex_unlock(&data->update_lock); |
| 966 | return count; |
| 967 | } |
| 968 | |
| 969 | static ssize_t |
| 970 | store_pwm(struct device *dev, struct device_attribute *attr, |
| 971 | const char *buf, size_t count) |
| 972 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 973 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 974 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 975 | int nr = sensor_attr->index; |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 976 | unsigned long val; |
| 977 | int err; |
| 978 | |
| 979 | err = strict_strtoul(buf, 10, &val); |
| 980 | if (err < 0) |
| 981 | return err; |
| 982 | |
| 983 | val = SENSORS_LIMIT(val, 0, 255); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 984 | |
| 985 | mutex_lock(&data->update_lock); |
| 986 | data->pwm[nr] = val; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 987 | w83627ehf_write_value(data, W83627EHF_REG_PWM[nr], val); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 988 | mutex_unlock(&data->update_lock); |
| 989 | return count; |
| 990 | } |
| 991 | |
| 992 | static ssize_t |
| 993 | store_pwm_enable(struct device *dev, struct device_attribute *attr, |
| 994 | const char *buf, size_t count) |
| 995 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 996 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 997 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 998 | int nr = sensor_attr->index; |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 999 | unsigned long val; |
| 1000 | int err; |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1001 | u16 reg; |
| 1002 | |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 1003 | err = strict_strtoul(buf, 10, &val); |
| 1004 | if (err < 0) |
| 1005 | return err; |
| 1006 | |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 1007 | if (!val || (val > 4)) |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1008 | return -EINVAL; |
| 1009 | mutex_lock(&data->update_lock); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1010 | reg = w83627ehf_read_value(data, W83627EHF_REG_PWM_ENABLE[nr]); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1011 | data->pwm_enable[nr] = val; |
| 1012 | reg &= ~(0x03 << W83627EHF_PWM_ENABLE_SHIFT[nr]); |
| 1013 | reg |= (val - 1) << W83627EHF_PWM_ENABLE_SHIFT[nr]; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1014 | w83627ehf_write_value(data, W83627EHF_REG_PWM_ENABLE[nr], reg); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1015 | mutex_unlock(&data->update_lock); |
| 1016 | return count; |
| 1017 | } |
| 1018 | |
| 1019 | |
| 1020 | #define show_tol_temp(reg) \ |
| 1021 | static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ |
| 1022 | 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 | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 1027 | return sprintf(buf, "%d\n", data->reg[nr] * 1000); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | show_tol_temp(tolerance) |
| 1031 | show_tol_temp(target_temp) |
| 1032 | |
| 1033 | static ssize_t |
| 1034 | store_target_temp(struct device *dev, struct device_attribute *attr, |
| 1035 | const char *buf, size_t count) |
| 1036 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1037 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1038 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1039 | int nr = sensor_attr->index; |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 1040 | long val; |
| 1041 | int err; |
| 1042 | |
| 1043 | err = strict_strtol(buf, 10, &val); |
| 1044 | if (err < 0) |
| 1045 | return err; |
| 1046 | |
| 1047 | val = SENSORS_LIMIT(DIV_ROUND_CLOSEST(val, 1000), 0, 127); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1048 | |
| 1049 | mutex_lock(&data->update_lock); |
| 1050 | data->target_temp[nr] = val; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1051 | w83627ehf_write_value(data, W83627EHF_REG_TARGET[nr], val); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1052 | mutex_unlock(&data->update_lock); |
| 1053 | return count; |
| 1054 | } |
| 1055 | |
| 1056 | static ssize_t |
| 1057 | store_tolerance(struct device *dev, struct device_attribute *attr, |
| 1058 | const char *buf, size_t count) |
| 1059 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1060 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1061 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); |
| 1062 | int nr = sensor_attr->index; |
| 1063 | u16 reg; |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 1064 | long val; |
| 1065 | int err; |
| 1066 | |
| 1067 | err = strict_strtol(buf, 10, &val); |
| 1068 | if (err < 0) |
| 1069 | return err; |
| 1070 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1071 | /* Limit the temp to 0C - 15C */ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 1072 | val = SENSORS_LIMIT(DIV_ROUND_CLOSEST(val, 1000), 0, 15); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1073 | |
| 1074 | mutex_lock(&data->update_lock); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1075 | reg = w83627ehf_read_value(data, W83627EHF_REG_TOLERANCE[nr]); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1076 | data->tolerance[nr] = val; |
| 1077 | if (nr == 1) |
| 1078 | reg = (reg & 0x0f) | (val << 4); |
| 1079 | else |
| 1080 | reg = (reg & 0xf0) | val; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1081 | w83627ehf_write_value(data, W83627EHF_REG_TOLERANCE[nr], reg); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1082 | mutex_unlock(&data->update_lock); |
| 1083 | return count; |
| 1084 | } |
| 1085 | |
| 1086 | static struct sensor_device_attribute sda_pwm[] = { |
| 1087 | SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 0), |
| 1088 | SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 1), |
| 1089 | SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 2), |
| 1090 | SENSOR_ATTR(pwm4, S_IWUSR | S_IRUGO, show_pwm, store_pwm, 3), |
| 1091 | }; |
| 1092 | |
| 1093 | static struct sensor_device_attribute sda_pwm_mode[] = { |
| 1094 | SENSOR_ATTR(pwm1_mode, S_IWUSR | S_IRUGO, show_pwm_mode, |
| 1095 | store_pwm_mode, 0), |
| 1096 | SENSOR_ATTR(pwm2_mode, S_IWUSR | S_IRUGO, show_pwm_mode, |
| 1097 | store_pwm_mode, 1), |
| 1098 | SENSOR_ATTR(pwm3_mode, S_IWUSR | S_IRUGO, show_pwm_mode, |
| 1099 | store_pwm_mode, 2), |
| 1100 | SENSOR_ATTR(pwm4_mode, S_IWUSR | S_IRUGO, show_pwm_mode, |
| 1101 | store_pwm_mode, 3), |
| 1102 | }; |
| 1103 | |
| 1104 | static struct sensor_device_attribute sda_pwm_enable[] = { |
| 1105 | SENSOR_ATTR(pwm1_enable, S_IWUSR | S_IRUGO, show_pwm_enable, |
| 1106 | store_pwm_enable, 0), |
| 1107 | SENSOR_ATTR(pwm2_enable, S_IWUSR | S_IRUGO, show_pwm_enable, |
| 1108 | store_pwm_enable, 1), |
| 1109 | SENSOR_ATTR(pwm3_enable, S_IWUSR | S_IRUGO, show_pwm_enable, |
| 1110 | store_pwm_enable, 2), |
| 1111 | SENSOR_ATTR(pwm4_enable, S_IWUSR | S_IRUGO, show_pwm_enable, |
| 1112 | store_pwm_enable, 3), |
| 1113 | }; |
| 1114 | |
| 1115 | static struct sensor_device_attribute sda_target_temp[] = { |
| 1116 | SENSOR_ATTR(pwm1_target, S_IWUSR | S_IRUGO, show_target_temp, |
| 1117 | store_target_temp, 0), |
| 1118 | SENSOR_ATTR(pwm2_target, S_IWUSR | S_IRUGO, show_target_temp, |
| 1119 | store_target_temp, 1), |
| 1120 | SENSOR_ATTR(pwm3_target, S_IWUSR | S_IRUGO, show_target_temp, |
| 1121 | store_target_temp, 2), |
| 1122 | SENSOR_ATTR(pwm4_target, S_IWUSR | S_IRUGO, show_target_temp, |
| 1123 | store_target_temp, 3), |
| 1124 | }; |
| 1125 | |
| 1126 | static struct sensor_device_attribute sda_tolerance[] = { |
| 1127 | SENSOR_ATTR(pwm1_tolerance, S_IWUSR | S_IRUGO, show_tolerance, |
| 1128 | store_tolerance, 0), |
| 1129 | SENSOR_ATTR(pwm2_tolerance, S_IWUSR | S_IRUGO, show_tolerance, |
| 1130 | store_tolerance, 1), |
| 1131 | SENSOR_ATTR(pwm3_tolerance, S_IWUSR | S_IRUGO, show_tolerance, |
| 1132 | store_tolerance, 2), |
| 1133 | SENSOR_ATTR(pwm4_tolerance, S_IWUSR | S_IRUGO, show_tolerance, |
| 1134 | store_tolerance, 3), |
| 1135 | }; |
| 1136 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1137 | /* Smart Fan registers */ |
| 1138 | |
| 1139 | #define fan_functions(reg, REG) \ |
| 1140 | static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ |
| 1141 | char *buf) \ |
| 1142 | { \ |
| 1143 | struct w83627ehf_data *data = w83627ehf_update_device(dev); \ |
| 1144 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ |
| 1145 | int nr = sensor_attr->index; \ |
| 1146 | return sprintf(buf, "%d\n", data->reg[nr]); \ |
| 1147 | }\ |
| 1148 | static ssize_t \ |
| 1149 | store_##reg(struct device *dev, struct device_attribute *attr, \ |
| 1150 | const char *buf, size_t count) \ |
| 1151 | {\ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1152 | struct w83627ehf_data *data = dev_get_drvdata(dev); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1153 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ |
| 1154 | int nr = sensor_attr->index; \ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 1155 | unsigned long val; \ |
| 1156 | int err; \ |
| 1157 | err = strict_strtoul(buf, 10, &val); \ |
| 1158 | if (err < 0) \ |
| 1159 | return err; \ |
| 1160 | val = SENSORS_LIMIT(val, 1, 255); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1161 | mutex_lock(&data->update_lock); \ |
| 1162 | data->reg[nr] = val; \ |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1163 | w83627ehf_write_value(data, data->REG_##REG[nr], val); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1164 | mutex_unlock(&data->update_lock); \ |
| 1165 | return count; \ |
| 1166 | } |
| 1167 | |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 1168 | fan_functions(fan_start_output, FAN_START_OUTPUT) |
| 1169 | fan_functions(fan_stop_output, FAN_STOP_OUTPUT) |
| 1170 | fan_functions(fan_max_output, FAN_MAX_OUTPUT) |
| 1171 | fan_functions(fan_step_output, FAN_STEP_OUTPUT) |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1172 | |
| 1173 | #define fan_time_functions(reg, REG) \ |
| 1174 | static ssize_t show_##reg(struct device *dev, struct device_attribute *attr, \ |
| 1175 | char *buf) \ |
| 1176 | { \ |
| 1177 | struct w83627ehf_data *data = w83627ehf_update_device(dev); \ |
| 1178 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ |
| 1179 | int nr = sensor_attr->index; \ |
| 1180 | return sprintf(buf, "%d\n", \ |
| 1181 | step_time_from_reg(data->reg[nr], data->pwm_mode[nr])); \ |
| 1182 | } \ |
| 1183 | \ |
| 1184 | static ssize_t \ |
| 1185 | store_##reg(struct device *dev, struct device_attribute *attr, \ |
| 1186 | const char *buf, size_t count) \ |
| 1187 | { \ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1188 | struct w83627ehf_data *data = dev_get_drvdata(dev); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1189 | struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); \ |
| 1190 | int nr = sensor_attr->index; \ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 1191 | unsigned long val; \ |
| 1192 | int err; \ |
| 1193 | err = strict_strtoul(buf, 10, &val); \ |
| 1194 | if (err < 0) \ |
| 1195 | return err; \ |
| 1196 | val = step_time_to_reg(val, data->pwm_mode[nr]); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1197 | mutex_lock(&data->update_lock); \ |
| 1198 | data->reg[nr] = val; \ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1199 | w83627ehf_write_value(data, W83627EHF_REG_##REG[nr], val); \ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1200 | mutex_unlock(&data->update_lock); \ |
| 1201 | return count; \ |
| 1202 | } \ |
| 1203 | |
| 1204 | fan_time_functions(fan_stop_time, FAN_STOP_TIME) |
| 1205 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1206 | static ssize_t show_name(struct device *dev, struct device_attribute *attr, |
| 1207 | char *buf) |
| 1208 | { |
| 1209 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
| 1210 | |
| 1211 | return sprintf(buf, "%s\n", data->name); |
| 1212 | } |
| 1213 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1214 | |
| 1215 | static struct sensor_device_attribute sda_sf3_arrays_fan4[] = { |
| 1216 | SENSOR_ATTR(pwm4_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time, |
| 1217 | store_fan_stop_time, 3), |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 1218 | SENSOR_ATTR(pwm4_start_output, S_IWUSR | S_IRUGO, show_fan_start_output, |
| 1219 | store_fan_start_output, 3), |
| 1220 | SENSOR_ATTR(pwm4_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output, |
| 1221 | store_fan_stop_output, 3), |
| 1222 | SENSOR_ATTR(pwm4_max_output, S_IWUSR | S_IRUGO, show_fan_max_output, |
| 1223 | store_fan_max_output, 3), |
| 1224 | SENSOR_ATTR(pwm4_step_output, S_IWUSR | S_IRUGO, show_fan_step_output, |
| 1225 | store_fan_step_output, 3), |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1226 | }; |
| 1227 | |
| 1228 | static struct sensor_device_attribute sda_sf3_arrays[] = { |
| 1229 | SENSOR_ATTR(pwm1_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time, |
| 1230 | store_fan_stop_time, 0), |
| 1231 | SENSOR_ATTR(pwm2_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time, |
| 1232 | store_fan_stop_time, 1), |
| 1233 | SENSOR_ATTR(pwm3_stop_time, S_IWUSR | S_IRUGO, show_fan_stop_time, |
| 1234 | store_fan_stop_time, 2), |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 1235 | SENSOR_ATTR(pwm1_start_output, S_IWUSR | S_IRUGO, show_fan_start_output, |
| 1236 | store_fan_start_output, 0), |
| 1237 | SENSOR_ATTR(pwm2_start_output, S_IWUSR | S_IRUGO, show_fan_start_output, |
| 1238 | store_fan_start_output, 1), |
| 1239 | SENSOR_ATTR(pwm3_start_output, S_IWUSR | S_IRUGO, show_fan_start_output, |
| 1240 | store_fan_start_output, 2), |
| 1241 | SENSOR_ATTR(pwm1_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output, |
| 1242 | store_fan_stop_output, 0), |
| 1243 | SENSOR_ATTR(pwm2_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output, |
| 1244 | store_fan_stop_output, 1), |
| 1245 | SENSOR_ATTR(pwm3_stop_output, S_IWUSR | S_IRUGO, show_fan_stop_output, |
| 1246 | store_fan_stop_output, 2), |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1247 | }; |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 1248 | |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1249 | |
| 1250 | /* |
| 1251 | * pwm1 and pwm3 don't support max and step settings on all chips. |
| 1252 | * Need to check support while generating/removing attribute files. |
| 1253 | */ |
| 1254 | static struct sensor_device_attribute sda_sf3_max_step_arrays[] = { |
| 1255 | SENSOR_ATTR(pwm1_max_output, S_IWUSR | S_IRUGO, show_fan_max_output, |
| 1256 | store_fan_max_output, 0), |
| 1257 | SENSOR_ATTR(pwm1_step_output, S_IWUSR | S_IRUGO, show_fan_step_output, |
| 1258 | store_fan_step_output, 0), |
Daniel J Blueman | 41e9a06 | 2009-12-14 18:01:37 -0800 | [diff] [blame] | 1259 | SENSOR_ATTR(pwm2_max_output, S_IWUSR | S_IRUGO, show_fan_max_output, |
| 1260 | store_fan_max_output, 1), |
| 1261 | SENSOR_ATTR(pwm2_step_output, S_IWUSR | S_IRUGO, show_fan_step_output, |
| 1262 | store_fan_step_output, 1), |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1263 | SENSOR_ATTR(pwm3_max_output, S_IWUSR | S_IRUGO, show_fan_max_output, |
| 1264 | store_fan_max_output, 2), |
| 1265 | SENSOR_ATTR(pwm3_step_output, S_IWUSR | S_IRUGO, show_fan_step_output, |
| 1266 | store_fan_step_output, 2), |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1267 | }; |
| 1268 | |
Jean Delvare | fc18d6c | 2007-06-24 11:19:42 +0200 | [diff] [blame] | 1269 | static ssize_t |
| 1270 | show_vid(struct device *dev, struct device_attribute *attr, char *buf) |
| 1271 | { |
| 1272 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
| 1273 | return sprintf(buf, "%d\n", vid_from_reg(data->vid, data->vrm)); |
| 1274 | } |
| 1275 | static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL); |
| 1276 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1277 | /* |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1278 | * Driver and device management |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1279 | */ |
| 1280 | |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1281 | static void w83627ehf_device_remove_files(struct device *dev) |
| 1282 | { |
| 1283 | /* some entries in the following arrays may not have been used in |
| 1284 | * device_create_file(), but device_remove_file() will ignore them */ |
| 1285 | int i; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1286 | struct w83627ehf_data *data = dev_get_drvdata(dev); |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1287 | |
| 1288 | for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++) |
| 1289 | device_remove_file(dev, &sda_sf3_arrays[i].dev_attr); |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1290 | for (i = 0; i < ARRAY_SIZE(sda_sf3_max_step_arrays); i++) { |
| 1291 | struct sensor_device_attribute *attr = |
| 1292 | &sda_sf3_max_step_arrays[i]; |
| 1293 | if (data->REG_FAN_STEP_OUTPUT[attr->index] != 0xff) |
| 1294 | device_remove_file(dev, &attr->dev_attr); |
| 1295 | } |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1296 | for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) |
| 1297 | device_remove_file(dev, &sda_sf3_arrays_fan4[i].dev_attr); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1298 | for (i = 0; i < data->in_num; i++) { |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1299 | if ((i == 6) && data->in6_skip) |
| 1300 | continue; |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1301 | device_remove_file(dev, &sda_in_input[i].dev_attr); |
| 1302 | device_remove_file(dev, &sda_in_alarm[i].dev_attr); |
| 1303 | device_remove_file(dev, &sda_in_min[i].dev_attr); |
| 1304 | device_remove_file(dev, &sda_in_max[i].dev_attr); |
| 1305 | } |
| 1306 | for (i = 0; i < 5; i++) { |
| 1307 | device_remove_file(dev, &sda_fan_input[i].dev_attr); |
| 1308 | device_remove_file(dev, &sda_fan_alarm[i].dev_attr); |
| 1309 | device_remove_file(dev, &sda_fan_div[i].dev_attr); |
| 1310 | device_remove_file(dev, &sda_fan_min[i].dev_attr); |
| 1311 | } |
Gong Jun | 237c8d2f | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 1312 | for (i = 0; i < data->pwm_num; i++) { |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1313 | device_remove_file(dev, &sda_pwm[i].dev_attr); |
| 1314 | device_remove_file(dev, &sda_pwm_mode[i].dev_attr); |
| 1315 | device_remove_file(dev, &sda_pwm_enable[i].dev_attr); |
| 1316 | device_remove_file(dev, &sda_target_temp[i].dev_attr); |
| 1317 | device_remove_file(dev, &sda_tolerance[i].dev_attr); |
| 1318 | } |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1319 | for (i = 0; i < 3; i++) { |
| 1320 | if ((i == 2) && data->temp3_disable) |
| 1321 | continue; |
| 1322 | device_remove_file(dev, &sda_temp_input[i].dev_attr); |
| 1323 | device_remove_file(dev, &sda_temp_max[i].dev_attr); |
| 1324 | device_remove_file(dev, &sda_temp_max_hyst[i].dev_attr); |
| 1325 | device_remove_file(dev, &sda_temp_alarm[i].dev_attr); |
| 1326 | device_remove_file(dev, &sda_temp_type[i].dev_attr); |
| 1327 | } |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1328 | |
| 1329 | device_remove_file(dev, &dev_attr_name); |
Jean Delvare | cbe311f | 2008-01-03 21:22:44 +0100 | [diff] [blame] | 1330 | device_remove_file(dev, &dev_attr_cpu0_vid); |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1331 | } |
| 1332 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1333 | /* Get the monitoring functions started */ |
| 1334 | static inline void __devinit w83627ehf_init_device(struct w83627ehf_data *data) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1335 | { |
| 1336 | int i; |
Jean Delvare | da66736 | 2007-06-24 11:21:02 +0200 | [diff] [blame] | 1337 | u8 tmp, diode; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1338 | |
| 1339 | /* Start monitoring is needed */ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1340 | tmp = w83627ehf_read_value(data, W83627EHF_REG_CONFIG); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1341 | if (!(tmp & 0x01)) |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1342 | w83627ehf_write_value(data, W83627EHF_REG_CONFIG, |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1343 | tmp | 0x01); |
| 1344 | |
| 1345 | /* Enable temp2 and temp3 if needed */ |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 1346 | for (i = 1; i < 3; i++) { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1347 | tmp = w83627ehf_read_value(data, |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1348 | W83627EHF_REG_TEMP_CONFIG[i]); |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 1349 | if ((i == 2) && data->temp3_disable) |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1350 | continue; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1351 | if (tmp & 0x01) |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1352 | w83627ehf_write_value(data, |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1353 | W83627EHF_REG_TEMP_CONFIG[i], |
| 1354 | tmp & 0xfe); |
| 1355 | } |
Jean Delvare | d3130f0 | 2007-06-24 11:20:13 +0200 | [diff] [blame] | 1356 | |
| 1357 | /* Enable VBAT monitoring if needed */ |
| 1358 | tmp = w83627ehf_read_value(data, W83627EHF_REG_VBAT); |
| 1359 | if (!(tmp & 0x01)) |
| 1360 | w83627ehf_write_value(data, W83627EHF_REG_VBAT, tmp | 0x01); |
Jean Delvare | da66736 | 2007-06-24 11:21:02 +0200 | [diff] [blame] | 1361 | |
| 1362 | /* Get thermal sensor types */ |
| 1363 | diode = w83627ehf_read_value(data, W83627EHF_REG_DIODE); |
| 1364 | for (i = 0; i < 3; i++) { |
| 1365 | if ((tmp & (0x02 << i))) |
| 1366 | data->temp_type[i] = (diode & (0x10 << i)) ? 1 : 2; |
| 1367 | else |
| 1368 | data->temp_type[i] = 4; /* thermistor */ |
| 1369 | } |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1370 | } |
| 1371 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1372 | static int __devinit w83627ehf_probe(struct platform_device *pdev) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1373 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1374 | struct device *dev = &pdev->dev; |
| 1375 | struct w83627ehf_sio_data *sio_data = dev->platform_data; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1376 | struct w83627ehf_data *data; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1377 | struct resource *res; |
Jean Delvare | fc18d6c | 2007-06-24 11:19:42 +0200 | [diff] [blame] | 1378 | u8 fan4pin, fan5pin, en_vrm10; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1379 | int i, err = 0; |
| 1380 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1381 | res = platform_get_resource(pdev, IORESOURCE_IO, 0); |
| 1382 | if (!request_region(res->start, IOREGION_LENGTH, DRVNAME)) { |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1383 | err = -EBUSY; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1384 | dev_err(dev, "Failed to request region 0x%lx-0x%lx\n", |
| 1385 | (unsigned long)res->start, |
| 1386 | (unsigned long)res->start + IOREGION_LENGTH - 1); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1387 | goto exit; |
| 1388 | } |
| 1389 | |
Deepak Saxena | ba9c2e8 | 2005-10-17 23:08:32 +0200 | [diff] [blame] | 1390 | if (!(data = kzalloc(sizeof(struct w83627ehf_data), GFP_KERNEL))) { |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1391 | err = -ENOMEM; |
| 1392 | goto exit_release; |
| 1393 | } |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1394 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1395 | data->addr = res->start; |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1396 | mutex_init(&data->lock); |
Ingo Molnar | 9a61bf6 | 2006-01-18 23:19:26 +0100 | [diff] [blame] | 1397 | mutex_init(&data->update_lock); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1398 | data->name = w83627ehf_device_names[sio_data->kind]; |
| 1399 | platform_set_drvdata(pdev, data); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1400 | |
Gong Jun | 237c8d2f | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 1401 | /* 627EHG and 627EHF have 10 voltage inputs; 627DHG and 667HG have 9 */ |
| 1402 | data->in_num = (sio_data->kind == w83627ehf) ? 10 : 9; |
| 1403 | /* 667HG has 3 pwms */ |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1404 | data->pwm_num = (sio_data->kind == w83667hg |
| 1405 | || sio_data->kind == w83667hg_b) ? 3 : 4; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1406 | |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1407 | /* Check temp3 configuration bit for 667HG */ |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1408 | if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) { |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1409 | data->temp3_disable = w83627ehf_read_value(data, |
Guenter Roeck | bce26c5 | 2011-02-04 12:54:14 -0800 | [diff] [blame^] | 1410 | W83627EHF_REG_TEMP_CONFIG[2]) & 0x01; |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1411 | data->in6_skip = !data->temp3_disable; |
| 1412 | } |
| 1413 | |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1414 | data->REG_FAN_START_OUTPUT = W83627EHF_REG_FAN_START_OUTPUT; |
| 1415 | data->REG_FAN_STOP_OUTPUT = W83627EHF_REG_FAN_STOP_OUTPUT; |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1416 | if (sio_data->kind == w83667hg_b) { |
| 1417 | data->REG_FAN_MAX_OUTPUT = |
| 1418 | W83627EHF_REG_FAN_MAX_OUTPUT_W83667_B; |
| 1419 | data->REG_FAN_STEP_OUTPUT = |
| 1420 | W83627EHF_REG_FAN_STEP_OUTPUT_W83667_B; |
| 1421 | } else { |
| 1422 | data->REG_FAN_MAX_OUTPUT = |
| 1423 | W83627EHF_REG_FAN_MAX_OUTPUT_COMMON; |
| 1424 | data->REG_FAN_STEP_OUTPUT = |
| 1425 | W83627EHF_REG_FAN_STEP_OUTPUT_COMMON; |
| 1426 | } |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1427 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1428 | /* Initialize the chip */ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1429 | w83627ehf_init_device(data); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1430 | |
Jean Delvare | fc18d6c | 2007-06-24 11:19:42 +0200 | [diff] [blame] | 1431 | data->vrm = vid_which_vrm(); |
| 1432 | superio_enter(sio_data->sioreg); |
Jean Delvare | fc18d6c | 2007-06-24 11:19:42 +0200 | [diff] [blame] | 1433 | /* Read VID value */ |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1434 | if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) { |
Gong Jun | 237c8d2f | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 1435 | /* W83667HG has different pins for VID input and output, so |
| 1436 | we can get the VID input values directly at logical device D |
| 1437 | 0xe3. */ |
| 1438 | superio_select(sio_data->sioreg, W83667HG_LD_VID); |
| 1439 | data->vid = superio_inb(sio_data->sioreg, 0xe3); |
Jean Delvare | cbe311f | 2008-01-03 21:22:44 +0100 | [diff] [blame] | 1440 | err = device_create_file(dev, &dev_attr_cpu0_vid); |
| 1441 | if (err) |
| 1442 | goto exit_release; |
Jean Delvare | 58e6e78 | 2008-01-03 07:33:31 -0500 | [diff] [blame] | 1443 | } else { |
Gong Jun | 237c8d2f | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 1444 | superio_select(sio_data->sioreg, W83627EHF_LD_HWM); |
| 1445 | if (superio_inb(sio_data->sioreg, SIO_REG_VID_CTRL) & 0x80) { |
| 1446 | /* Set VID input sensibility if needed. In theory the |
| 1447 | BIOS should have set it, but in practice it's not |
| 1448 | always the case. We only do it for the W83627EHF/EHG |
| 1449 | because the W83627DHG is more complex in this |
| 1450 | respect. */ |
| 1451 | if (sio_data->kind == w83627ehf) { |
| 1452 | en_vrm10 = superio_inb(sio_data->sioreg, |
| 1453 | SIO_REG_EN_VRM10); |
| 1454 | if ((en_vrm10 & 0x08) && data->vrm == 90) { |
| 1455 | dev_warn(dev, "Setting VID input " |
| 1456 | "voltage to TTL\n"); |
| 1457 | superio_outb(sio_data->sioreg, |
| 1458 | SIO_REG_EN_VRM10, |
| 1459 | en_vrm10 & ~0x08); |
| 1460 | } else if (!(en_vrm10 & 0x08) |
| 1461 | && data->vrm == 100) { |
| 1462 | dev_warn(dev, "Setting VID input " |
| 1463 | "voltage to VRM10\n"); |
| 1464 | superio_outb(sio_data->sioreg, |
| 1465 | SIO_REG_EN_VRM10, |
| 1466 | en_vrm10 | 0x08); |
| 1467 | } |
| 1468 | } |
| 1469 | |
| 1470 | data->vid = superio_inb(sio_data->sioreg, |
| 1471 | SIO_REG_VID_DATA); |
| 1472 | if (sio_data->kind == w83627ehf) /* 6 VID pins only */ |
| 1473 | data->vid &= 0x3f; |
| 1474 | |
| 1475 | err = device_create_file(dev, &dev_attr_cpu0_vid); |
| 1476 | if (err) |
| 1477 | goto exit_release; |
| 1478 | } else { |
| 1479 | dev_info(dev, "VID pins in output mode, CPU VID not " |
| 1480 | "available\n"); |
| 1481 | } |
Jean Delvare | fc18d6c | 2007-06-24 11:19:42 +0200 | [diff] [blame] | 1482 | } |
| 1483 | |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1484 | /* fan4 and fan5 share some pins with the GPIO and serial flash */ |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1485 | if (sio_data->kind == w83667hg || sio_data->kind == w83667hg_b) { |
Gong Jun | 237c8d2f | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 1486 | fan5pin = superio_inb(sio_data->sioreg, 0x27) & 0x20; |
| 1487 | fan4pin = superio_inb(sio_data->sioreg, 0x27) & 0x40; |
| 1488 | } else { |
| 1489 | fan5pin = !(superio_inb(sio_data->sioreg, 0x24) & 0x02); |
| 1490 | fan4pin = !(superio_inb(sio_data->sioreg, 0x29) & 0x06); |
| 1491 | } |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1492 | superio_exit(sio_data->sioreg); |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1493 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1494 | /* It looks like fan4 and fan5 pins can be alternatively used |
Rudolf Marek | 14992c7 | 2006-10-08 22:02:09 +0200 | [diff] [blame] | 1495 | as fan on/off switches, but fan5 control is write only :/ |
| 1496 | We assume that if the serial interface is disabled, designers |
| 1497 | connected fan5 as input unless they are emitting log 1, which |
| 1498 | is not the default. */ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1499 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1500 | data->has_fan = 0x07; /* fan1, fan2 and fan3 */ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1501 | i = w83627ehf_read_value(data, W83627EHF_REG_FANDIV1); |
Jean Delvare | 1704b26 | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 1502 | if ((i & (1 << 2)) && fan4pin) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1503 | data->has_fan |= (1 << 3); |
Jean Delvare | 1704b26 | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 1504 | if (!(i & (1 << 1)) && fan5pin) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1505 | data->has_fan |= (1 << 4); |
| 1506 | |
Mark M. Hoffman | ea7be66 | 2007-08-05 12:19:01 -0400 | [diff] [blame] | 1507 | /* Read fan clock dividers immediately */ |
| 1508 | w83627ehf_update_fan_div(data); |
| 1509 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1510 | /* Register sysfs hooks */ |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1511 | for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays); i++) |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1512 | if ((err = device_create_file(dev, |
| 1513 | &sda_sf3_arrays[i].dev_attr))) |
| 1514 | goto exit_remove; |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1515 | |
Guenter Roeck | da2e025 | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1516 | for (i = 0; i < ARRAY_SIZE(sda_sf3_max_step_arrays); i++) { |
| 1517 | struct sensor_device_attribute *attr = |
| 1518 | &sda_sf3_max_step_arrays[i]; |
| 1519 | if (data->REG_FAN_STEP_OUTPUT[attr->index] != 0xff) { |
| 1520 | err = device_create_file(dev, &attr->dev_attr); |
| 1521 | if (err) |
| 1522 | goto exit_remove; |
| 1523 | } |
| 1524 | } |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1525 | /* if fan4 is enabled create the sf3 files for it */ |
Gong Jun | 237c8d2f | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 1526 | if ((data->has_fan & (1 << 3)) && data->pwm_num >= 4) |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1527 | for (i = 0; i < ARRAY_SIZE(sda_sf3_arrays_fan4); i++) { |
| 1528 | if ((err = device_create_file(dev, |
| 1529 | &sda_sf3_arrays_fan4[i].dev_attr))) |
| 1530 | goto exit_remove; |
| 1531 | } |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1532 | |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1533 | for (i = 0; i < data->in_num; i++) { |
| 1534 | if ((i == 6) && data->in6_skip) |
| 1535 | continue; |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1536 | if ((err = device_create_file(dev, &sda_in_input[i].dev_attr)) |
| 1537 | || (err = device_create_file(dev, |
| 1538 | &sda_in_alarm[i].dev_attr)) |
| 1539 | || (err = device_create_file(dev, |
| 1540 | &sda_in_min[i].dev_attr)) |
| 1541 | || (err = device_create_file(dev, |
| 1542 | &sda_in_max[i].dev_attr))) |
| 1543 | goto exit_remove; |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1544 | } |
Rudolf Marek | cf0676f | 2006-03-23 16:25:22 +0100 | [diff] [blame] | 1545 | |
Yuan Mu | 412fec8 | 2006-02-05 23:24:16 +0100 | [diff] [blame] | 1546 | for (i = 0; i < 5; i++) { |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1547 | if (data->has_fan & (1 << i)) { |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1548 | if ((err = device_create_file(dev, |
| 1549 | &sda_fan_input[i].dev_attr)) |
| 1550 | || (err = device_create_file(dev, |
| 1551 | &sda_fan_alarm[i].dev_attr)) |
| 1552 | || (err = device_create_file(dev, |
| 1553 | &sda_fan_div[i].dev_attr)) |
| 1554 | || (err = device_create_file(dev, |
| 1555 | &sda_fan_min[i].dev_attr))) |
| 1556 | goto exit_remove; |
Gong Jun | 237c8d2f | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 1557 | if (i < data->pwm_num && |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1558 | ((err = device_create_file(dev, |
| 1559 | &sda_pwm[i].dev_attr)) |
| 1560 | || (err = device_create_file(dev, |
| 1561 | &sda_pwm_mode[i].dev_attr)) |
| 1562 | || (err = device_create_file(dev, |
| 1563 | &sda_pwm_enable[i].dev_attr)) |
| 1564 | || (err = device_create_file(dev, |
| 1565 | &sda_target_temp[i].dev_attr)) |
| 1566 | || (err = device_create_file(dev, |
| 1567 | &sda_tolerance[i].dev_attr)))) |
| 1568 | goto exit_remove; |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1569 | } |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1570 | } |
Rudolf Marek | 08c7995 | 2006-07-05 18:14:31 +0200 | [diff] [blame] | 1571 | |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1572 | for (i = 0; i < 3; i++) { |
| 1573 | if ((i == 2) && data->temp3_disable) |
| 1574 | continue; |
| 1575 | if ((err = device_create_file(dev, |
| 1576 | &sda_temp_input[i].dev_attr)) |
| 1577 | || (err = device_create_file(dev, |
| 1578 | &sda_temp_max[i].dev_attr)) |
| 1579 | || (err = device_create_file(dev, |
| 1580 | &sda_temp_max_hyst[i].dev_attr)) |
| 1581 | || (err = device_create_file(dev, |
| 1582 | &sda_temp_alarm[i].dev_attr)) |
| 1583 | || (err = device_create_file(dev, |
| 1584 | &sda_temp_type[i].dev_attr))) |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1585 | goto exit_remove; |
Gong Jun | a157d06 | 2009-03-30 21:46:43 +0200 | [diff] [blame] | 1586 | } |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1587 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1588 | err = device_create_file(dev, &dev_attr_name); |
| 1589 | if (err) |
| 1590 | goto exit_remove; |
| 1591 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1592 | data->hwmon_dev = hwmon_device_register(dev); |
| 1593 | if (IS_ERR(data->hwmon_dev)) { |
| 1594 | err = PTR_ERR(data->hwmon_dev); |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1595 | goto exit_remove; |
| 1596 | } |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1597 | |
| 1598 | return 0; |
| 1599 | |
David Hubbard | c18beb5 | 2006-09-24 21:04:38 +0200 | [diff] [blame] | 1600 | exit_remove: |
| 1601 | w83627ehf_device_remove_files(dev); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1602 | kfree(data); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1603 | platform_set_drvdata(pdev, NULL); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1604 | exit_release: |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1605 | release_region(res->start, IOREGION_LENGTH); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1606 | exit: |
| 1607 | return err; |
| 1608 | } |
| 1609 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1610 | static int __devexit w83627ehf_remove(struct platform_device *pdev) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1611 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1612 | struct w83627ehf_data *data = platform_get_drvdata(pdev); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1613 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 1614 | hwmon_device_unregister(data->hwmon_dev); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1615 | w83627ehf_device_remove_files(&pdev->dev); |
| 1616 | release_region(data->addr, IOREGION_LENGTH); |
| 1617 | platform_set_drvdata(pdev, NULL); |
Mark M. Hoffman | 943b083 | 2005-07-15 21:39:18 -0400 | [diff] [blame] | 1618 | kfree(data); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1619 | |
| 1620 | return 0; |
| 1621 | } |
| 1622 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1623 | static struct platform_driver w83627ehf_driver = { |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 1624 | .driver = { |
Jean Delvare | 8721884 | 2006-09-03 22:36:14 +0200 | [diff] [blame] | 1625 | .owner = THIS_MODULE, |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1626 | .name = DRVNAME, |
Laurent Riffard | cdaf793 | 2005-11-26 20:37:41 +0100 | [diff] [blame] | 1627 | }, |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1628 | .probe = w83627ehf_probe, |
| 1629 | .remove = __devexit_p(w83627ehf_remove), |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1630 | }; |
| 1631 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1632 | /* w83627ehf_find() looks for a '627 in the Super-I/O config space */ |
| 1633 | static int __init w83627ehf_find(int sioaddr, unsigned short *addr, |
| 1634 | struct w83627ehf_sio_data *sio_data) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1635 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1636 | static const char __initdata sio_name_W83627EHF[] = "W83627EHF"; |
| 1637 | static const char __initdata sio_name_W83627EHG[] = "W83627EHG"; |
| 1638 | static const char __initdata sio_name_W83627DHG[] = "W83627DHG"; |
Jean Delvare | c1e48dc | 2009-06-15 18:39:50 +0200 | [diff] [blame] | 1639 | static const char __initdata sio_name_W83627DHG_P[] = "W83627DHG-P"; |
Gong Jun | 237c8d2f | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 1640 | static const char __initdata sio_name_W83667HG[] = "W83667HG"; |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1641 | static const char __initdata sio_name_W83667HG_B[] = "W83667HG-B"; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1642 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1643 | u16 val; |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1644 | const char *sio_name; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1645 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1646 | superio_enter(sioaddr); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1647 | |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 1648 | if (force_id) |
| 1649 | val = force_id; |
| 1650 | else |
| 1651 | val = (superio_inb(sioaddr, SIO_REG_DEVID) << 8) |
| 1652 | | superio_inb(sioaddr, SIO_REG_DEVID + 1); |
David Hubbard | 657c93b | 2007-02-14 21:15:04 +0100 | [diff] [blame] | 1653 | switch (val & SIO_ID_MASK) { |
David Hubbard | 657c93b | 2007-02-14 21:15:04 +0100 | [diff] [blame] | 1654 | case SIO_W83627EHF_ID: |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1655 | sio_data->kind = w83627ehf; |
| 1656 | sio_name = sio_name_W83627EHF; |
| 1657 | break; |
David Hubbard | 657c93b | 2007-02-14 21:15:04 +0100 | [diff] [blame] | 1658 | case SIO_W83627EHG_ID: |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1659 | sio_data->kind = w83627ehf; |
| 1660 | sio_name = sio_name_W83627EHG; |
| 1661 | break; |
| 1662 | case SIO_W83627DHG_ID: |
| 1663 | sio_data->kind = w83627dhg; |
| 1664 | sio_name = sio_name_W83627DHG; |
David Hubbard | 657c93b | 2007-02-14 21:15:04 +0100 | [diff] [blame] | 1665 | break; |
Jean Delvare | c1e48dc | 2009-06-15 18:39:50 +0200 | [diff] [blame] | 1666 | case SIO_W83627DHG_P_ID: |
| 1667 | sio_data->kind = w83627dhg_p; |
| 1668 | sio_name = sio_name_W83627DHG_P; |
| 1669 | break; |
Gong Jun | 237c8d2f | 2009-03-30 21:46:42 +0200 | [diff] [blame] | 1670 | case SIO_W83667HG_ID: |
| 1671 | sio_data->kind = w83667hg; |
| 1672 | sio_name = sio_name_W83667HG; |
| 1673 | break; |
Guenter Roeck | c39aeda | 2010-08-14 21:08:55 +0200 | [diff] [blame] | 1674 | case SIO_W83667HG_B_ID: |
| 1675 | sio_data->kind = w83667hg_b; |
| 1676 | sio_name = sio_name_W83667HG_B; |
| 1677 | break; |
David Hubbard | 657c93b | 2007-02-14 21:15:04 +0100 | [diff] [blame] | 1678 | default: |
Jean Delvare | 9f66036 | 2007-06-24 11:23:41 +0200 | [diff] [blame] | 1679 | if (val != 0xffff) |
Joe Perches | abdc6fd | 2010-10-20 06:51:54 +0000 | [diff] [blame] | 1680 | pr_debug("unsupported chip ID: 0x%04x\n", val); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1681 | superio_exit(sioaddr); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1682 | return -ENODEV; |
| 1683 | } |
| 1684 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1685 | /* We have a known chip, find the HWM I/O address */ |
| 1686 | superio_select(sioaddr, W83627EHF_LD_HWM); |
| 1687 | val = (superio_inb(sioaddr, SIO_REG_ADDR) << 8) |
| 1688 | | superio_inb(sioaddr, SIO_REG_ADDR + 1); |
Jean Delvare | 1a641fc | 2007-04-23 14:41:16 -0700 | [diff] [blame] | 1689 | *addr = val & IOREGION_ALIGNMENT; |
Jean Delvare | 2d8672c | 2005-07-19 23:56:35 +0200 | [diff] [blame] | 1690 | if (*addr == 0) { |
Joe Perches | abdc6fd | 2010-10-20 06:51:54 +0000 | [diff] [blame] | 1691 | 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] | 1692 | superio_exit(sioaddr); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1693 | return -ENODEV; |
| 1694 | } |
| 1695 | |
| 1696 | /* Activate logical device if needed */ |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1697 | val = superio_inb(sioaddr, SIO_REG_ENABLE); |
David Hubbard | 475ef85 | 2007-06-24 11:17:09 +0200 | [diff] [blame] | 1698 | if (!(val & 0x01)) { |
Joe Perches | abdc6fd | 2010-10-20 06:51:54 +0000 | [diff] [blame] | 1699 | pr_warn("Forcibly enabling Super-I/O. Sensor is probably unusable.\n"); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1700 | superio_outb(sioaddr, SIO_REG_ENABLE, val | 0x01); |
David Hubbard | 475ef85 | 2007-06-24 11:17:09 +0200 | [diff] [blame] | 1701 | } |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1702 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1703 | superio_exit(sioaddr); |
Joe Perches | abdc6fd | 2010-10-20 06:51:54 +0000 | [diff] [blame] | 1704 | pr_info("Found %s chip at %#x\n", sio_name, *addr); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1705 | sio_data->sioreg = sioaddr; |
| 1706 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1707 | return 0; |
| 1708 | } |
| 1709 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1710 | /* when Super-I/O functions move to a separate file, the Super-I/O |
| 1711 | * bus will manage the lifetime of the device and this module will only keep |
| 1712 | * track of the w83627ehf driver. But since we platform_device_alloc(), we |
| 1713 | * must keep track of the device */ |
| 1714 | static struct platform_device *pdev; |
| 1715 | |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1716 | static int __init sensors_w83627ehf_init(void) |
| 1717 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1718 | int err; |
| 1719 | unsigned short address; |
| 1720 | struct resource res; |
| 1721 | struct w83627ehf_sio_data sio_data; |
| 1722 | |
| 1723 | /* initialize sio_data->kind and sio_data->sioreg. |
| 1724 | * |
| 1725 | * when Super-I/O functions move to a separate file, the Super-I/O |
| 1726 | * driver will probe 0x2e and 0x4e and auto-detect the presence of a |
| 1727 | * w83627ehf hardware monitor, and call probe() */ |
| 1728 | if (w83627ehf_find(0x2e, &address, &sio_data) && |
| 1729 | w83627ehf_find(0x4e, &address, &sio_data)) |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1730 | return -ENODEV; |
| 1731 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1732 | err = platform_driver_register(&w83627ehf_driver); |
| 1733 | if (err) |
| 1734 | goto exit; |
| 1735 | |
| 1736 | if (!(pdev = platform_device_alloc(DRVNAME, address))) { |
| 1737 | err = -ENOMEM; |
Joe Perches | abdc6fd | 2010-10-20 06:51:54 +0000 | [diff] [blame] | 1738 | pr_err("Device allocation failed\n"); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1739 | goto exit_unregister; |
| 1740 | } |
| 1741 | |
| 1742 | err = platform_device_add_data(pdev, &sio_data, |
| 1743 | sizeof(struct w83627ehf_sio_data)); |
| 1744 | if (err) { |
Joe Perches | abdc6fd | 2010-10-20 06:51:54 +0000 | [diff] [blame] | 1745 | pr_err("Platform data allocation failed\n"); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1746 | goto exit_device_put; |
| 1747 | } |
| 1748 | |
| 1749 | memset(&res, 0, sizeof(res)); |
| 1750 | res.name = DRVNAME; |
| 1751 | res.start = address + IOREGION_OFFSET; |
| 1752 | res.end = address + IOREGION_OFFSET + IOREGION_LENGTH - 1; |
| 1753 | res.flags = IORESOURCE_IO; |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 1754 | |
| 1755 | err = acpi_check_resource_conflict(&res); |
| 1756 | if (err) |
Hans de Goede | 18632f8 | 2009-02-17 19:59:54 +0100 | [diff] [blame] | 1757 | goto exit_device_put; |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 1758 | |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1759 | err = platform_device_add_resources(pdev, &res, 1); |
| 1760 | if (err) { |
Joe Perches | abdc6fd | 2010-10-20 06:51:54 +0000 | [diff] [blame] | 1761 | pr_err("Device resource addition failed (%d)\n", err); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1762 | goto exit_device_put; |
| 1763 | } |
| 1764 | |
| 1765 | /* platform_device_add calls probe() */ |
| 1766 | err = platform_device_add(pdev); |
| 1767 | if (err) { |
Joe Perches | abdc6fd | 2010-10-20 06:51:54 +0000 | [diff] [blame] | 1768 | pr_err("Device addition failed (%d)\n", err); |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1769 | goto exit_device_put; |
| 1770 | } |
| 1771 | |
| 1772 | return 0; |
| 1773 | |
| 1774 | exit_device_put: |
| 1775 | platform_device_put(pdev); |
| 1776 | exit_unregister: |
| 1777 | platform_driver_unregister(&w83627ehf_driver); |
| 1778 | exit: |
| 1779 | return err; |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1780 | } |
| 1781 | |
| 1782 | static void __exit sensors_w83627ehf_exit(void) |
| 1783 | { |
David Hubbard | 1ea6dd3 | 2007-06-24 11:16:15 +0200 | [diff] [blame] | 1784 | platform_device_unregister(pdev); |
| 1785 | platform_driver_unregister(&w83627ehf_driver); |
Jean Delvare | 08e7e27 | 2005-04-25 22:43:25 +0200 | [diff] [blame] | 1786 | } |
| 1787 | |
| 1788 | MODULE_AUTHOR("Jean Delvare <khali@linux-fr.org>"); |
| 1789 | MODULE_DESCRIPTION("W83627EHF driver"); |
| 1790 | MODULE_LICENSE("GPL"); |
| 1791 | |
| 1792 | module_init(sensors_w83627ehf_init); |
| 1793 | module_exit(sensors_w83627ehf_exit); |