Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2006 by Hans Edgington <hans@edgington.nl> * |
Hans de Goede | 44c4dc5 | 2011-03-09 20:57:07 +0100 | [diff] [blame] | 3 | * Copyright (C) 2007-2011 Hans de Goede <hdegoede@redhat.com> * |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 4 | * * |
| 5 | * This program is free software; you can redistribute it and/or modify * |
| 6 | * it under the terms of the GNU General Public License as published by * |
| 7 | * the Free Software Foundation; either version 2 of the License, or * |
| 8 | * (at your option) any later version. * |
| 9 | * * |
| 10 | * This program is distributed in the hope that it will be useful, * |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | * GNU General Public License for more details. * |
| 14 | * * |
| 15 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program; if not, write to the * |
| 17 | * Free Software Foundation, Inc., * |
| 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 19 | ***************************************************************************/ |
| 20 | |
Joe Perches | 22d3b41 | 2010-10-20 06:51:34 +0000 | [diff] [blame] | 21 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 22 | |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 23 | #include <linux/module.h> |
| 24 | #include <linux/init.h> |
| 25 | #include <linux/slab.h> |
| 26 | #include <linux/jiffies.h> |
| 27 | #include <linux/platform_device.h> |
| 28 | #include <linux/hwmon.h> |
| 29 | #include <linux/hwmon-sysfs.h> |
| 30 | #include <linux/err.h> |
| 31 | #include <linux/mutex.h> |
Mark van Doesburg | 77a4a3e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 32 | #include <linux/io.h> |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 33 | #include <linux/acpi.h> |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 34 | |
| 35 | #define DRVNAME "f71882fg" |
| 36 | |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 37 | #define SIO_F71858FG_LD_HWM 0x02 /* Hardware monitor logical device */ |
Mark van Doesburg | 77a4a3e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 38 | #define SIO_F71882FG_LD_HWM 0x04 /* Hardware monitor logical device */ |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 39 | #define SIO_UNLOCK_KEY 0x87 /* Key to enable Super-I/O */ |
Hans de Goede | 14a4019 | 2011-03-13 13:50:32 +0100 | [diff] [blame] | 40 | #define SIO_LOCK_KEY 0xAA /* Key to disable Super-I/O */ |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 41 | |
| 42 | #define SIO_REG_LDSEL 0x07 /* Logical device select */ |
| 43 | #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */ |
| 44 | #define SIO_REG_DEVREV 0x22 /* Device revision */ |
| 45 | #define SIO_REG_MANID 0x23 /* Fintek ID (2 bytes) */ |
| 46 | #define SIO_REG_ENABLE 0x30 /* Logical device enable */ |
| 47 | #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */ |
| 48 | |
| 49 | #define SIO_FINTEK_ID 0x1934 /* Manufacturers ID */ |
Hans de Goede | e5e713c | 2011-03-10 08:54:02 +0100 | [diff] [blame] | 50 | #define SIO_F71808E_ID 0x0901 /* Chipset ID */ |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 51 | #define SIO_F71808A_ID 0x1001 /* Chipset ID */ |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 52 | #define SIO_F71858_ID 0x0507 /* Chipset ID */ |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 53 | #define SIO_F71862_ID 0x0601 /* Chipset ID */ |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 54 | #define SIO_F71868_ID 0x1106 /* Chipset ID */ |
Hans de Goede | c11bb99 | 2011-03-09 20:57:15 +0100 | [diff] [blame] | 55 | #define SIO_F71869_ID 0x0814 /* Chipset ID */ |
Hans de Goede | 5da556e | 2011-07-03 13:32:53 +0200 | [diff] [blame] | 56 | #define SIO_F71869A_ID 0x1007 /* Chipset ID */ |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 57 | #define SIO_F71882_ID 0x0541 /* Chipset ID */ |
Hans de Goede | 7669896 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 58 | #define SIO_F71889_ID 0x0723 /* Chipset ID */ |
Hans de Goede | 3cad402 | 2011-03-09 20:57:14 +0100 | [diff] [blame] | 59 | #define SIO_F71889E_ID 0x0909 /* Chipset ID */ |
Hans de Goede | a66c108 | 2011-03-26 10:45:02 +0100 | [diff] [blame] | 60 | #define SIO_F71889A_ID 0x1005 /* Chipset ID */ |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 61 | #define SIO_F8000_ID 0x0581 /* Chipset ID */ |
Jean Delvare | 383586b | 2011-03-26 10:45:02 +0100 | [diff] [blame] | 62 | #define SIO_F81865_ID 0x0704 /* Chipset ID */ |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 63 | #define SIO_F81866_ID 0x1010 /* Chipset ID */ |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 64 | |
| 65 | #define REGION_LENGTH 8 |
| 66 | #define ADDR_REG_OFFSET 5 |
| 67 | #define DATA_REG_OFFSET 6 |
| 68 | |
Hans de Goede | 3cad402 | 2011-03-09 20:57:14 +0100 | [diff] [blame] | 69 | #define F71882FG_REG_IN_STATUS 0x12 /* f7188x only */ |
| 70 | #define F71882FG_REG_IN_BEEP 0x13 /* f7188x only */ |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 71 | #define F71882FG_REG_IN(nr) (0x20 + (nr)) |
Hans de Goede | 3cad402 | 2011-03-09 20:57:14 +0100 | [diff] [blame] | 72 | #define F71882FG_REG_IN1_HIGH 0x32 /* f7188x only */ |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 73 | |
Peter Hung | 3e40b86 | 2015-07-07 16:22:38 +0800 | [diff] [blame^] | 74 | #define F81866_REG_IN_STATUS 0x16 /* F81866 only */ |
| 75 | #define F81866_REG_IN_BEEP 0x17 /* F81866 only */ |
| 76 | #define F81866_REG_IN1_HIGH 0x3a /* F81866 only */ |
| 77 | |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 78 | #define F71882FG_REG_FAN(nr) (0xA0 + (16 * (nr))) |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 79 | #define F71882FG_REG_FAN_TARGET(nr) (0xA2 + (16 * (nr))) |
| 80 | #define F71882FG_REG_FAN_FULL_SPEED(nr) (0xA4 + (16 * (nr))) |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 81 | #define F71882FG_REG_FAN_STATUS 0x92 |
| 82 | #define F71882FG_REG_FAN_BEEP 0x93 |
| 83 | |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 84 | #define F71882FG_REG_TEMP(nr) (0x70 + 2 * (nr)) |
| 85 | #define F71882FG_REG_TEMP_OVT(nr) (0x80 + 2 * (nr)) |
| 86 | #define F71882FG_REG_TEMP_HIGH(nr) (0x81 + 2 * (nr)) |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 87 | #define F71882FG_REG_TEMP_STATUS 0x62 |
| 88 | #define F71882FG_REG_TEMP_BEEP 0x63 |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 89 | #define F71882FG_REG_TEMP_CONFIG 0x69 |
Hans de Goede | bc27490 | 2009-01-07 16:37:29 +0100 | [diff] [blame] | 90 | #define F71882FG_REG_TEMP_HYST(nr) (0x6C + (nr)) |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 91 | #define F71882FG_REG_TEMP_TYPE 0x6B |
| 92 | #define F71882FG_REG_TEMP_DIODE_OPEN 0x6F |
| 93 | |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 94 | #define F71882FG_REG_PWM(nr) (0xA3 + (16 * (nr))) |
| 95 | #define F71882FG_REG_PWM_TYPE 0x94 |
| 96 | #define F71882FG_REG_PWM_ENABLE 0x96 |
| 97 | |
Hans de Goede | bc27490 | 2009-01-07 16:37:29 +0100 | [diff] [blame] | 98 | #define F71882FG_REG_FAN_HYST(nr) (0x98 + (nr)) |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 99 | |
Hans de Goede | 98f7ba1 | 2011-03-09 20:57:09 +0100 | [diff] [blame] | 100 | #define F71882FG_REG_FAN_FAULT_T 0x9F |
| 101 | #define F71882FG_FAN_NEG_TEMP_EN 0x20 |
Hans de Goede | 3cad402 | 2011-03-09 20:57:14 +0100 | [diff] [blame] | 102 | #define F71882FG_FAN_PROG_SEL 0x80 |
Hans de Goede | 98f7ba1 | 2011-03-09 20:57:09 +0100 | [diff] [blame] | 103 | |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 104 | #define F71882FG_REG_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm))) |
| 105 | #define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm))) |
| 106 | #define F71882FG_REG_POINT_MAPPING(nr) (0xAF + 16 * (nr)) |
| 107 | |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 108 | #define F71882FG_REG_START 0x01 |
| 109 | |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 110 | #define F71882FG_MAX_INS 10 |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 111 | |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 112 | #define FAN_MIN_DETECT 366 /* Lowest detectable fanspeed */ |
| 113 | |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 114 | static unsigned short force_id; |
| 115 | module_param(force_id, ushort, 0); |
| 116 | MODULE_PARM_DESC(force_id, "Override the detected device ID"); |
| 117 | |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 118 | enum chips { f71808e, f71808a, f71858fg, f71862fg, f71868a, f71869, f71869a, |
| 119 | f71882fg, f71889fg, f71889ed, f71889a, f8000, f81865f, f81866a}; |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 120 | |
Frans Meulenbroeks | 1dc3708 | 2012-01-08 19:34:10 +0100 | [diff] [blame] | 121 | static const char *const f71882fg_names[] = { |
Hans de Goede | e5e713c | 2011-03-10 08:54:02 +0100 | [diff] [blame] | 122 | "f71808e", |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 123 | "f71808a", |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 124 | "f71858fg", |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 125 | "f71862fg", |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 126 | "f71868a", |
Hans de Goede | c11bb99 | 2011-03-09 20:57:15 +0100 | [diff] [blame] | 127 | "f71869", /* Both f71869f and f71869e, reg. compatible and same id */ |
Hans de Goede | 5da556e | 2011-07-03 13:32:53 +0200 | [diff] [blame] | 128 | "f71869a", |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 129 | "f71882fg", |
Jean Delvare | 5d7f77b | 2011-03-26 10:45:02 +0100 | [diff] [blame] | 130 | "f71889fg", /* f81801u too, same id */ |
Hans de Goede | 3cad402 | 2011-03-09 20:57:14 +0100 | [diff] [blame] | 131 | "f71889ed", |
Hans de Goede | a66c108 | 2011-03-26 10:45:02 +0100 | [diff] [blame] | 132 | "f71889a", |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 133 | "f8000", |
Jean Delvare | 383586b | 2011-03-26 10:45:02 +0100 | [diff] [blame] | 134 | "f81865f", |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 135 | "f81866a", |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 136 | }; |
| 137 | |
Jean Delvare | 2740c60 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 138 | static const char f71882fg_has_in[][F71882FG_MAX_INS] = { |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 139 | [f71808e] = { 1, 1, 1, 1, 1, 1, 0, 1, 1, 0 }, |
| 140 | [f71808a] = { 1, 1, 1, 1, 0, 0, 0, 1, 1, 0 }, |
| 141 | [f71858fg] = { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }, |
| 142 | [f71862fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, |
| 143 | [f71868a] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 144 | [f71869] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, |
| 145 | [f71869a] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, |
| 146 | [f71882fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, |
| 147 | [f71889fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, |
| 148 | [f71889ed] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, |
| 149 | [f71889a] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 }, |
| 150 | [f8000] = { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 }, |
| 151 | [f81865f] = { 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 }, |
| 152 | [f81866a] = { 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 }, |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 153 | }; |
| 154 | |
Jean Delvare | 2740c60 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 155 | static const char f71882fg_has_in1_alarm[] = { |
| 156 | [f71808e] = 0, |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 157 | [f71808a] = 0, |
Jean Delvare | 2740c60 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 158 | [f71858fg] = 0, |
| 159 | [f71862fg] = 0, |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 160 | [f71868a] = 0, |
Jean Delvare | 2740c60 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 161 | [f71869] = 0, |
Hans de Goede | 5da556e | 2011-07-03 13:32:53 +0200 | [diff] [blame] | 162 | [f71869a] = 0, |
Jean Delvare | 2740c60 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 163 | [f71882fg] = 1, |
| 164 | [f71889fg] = 1, |
| 165 | [f71889ed] = 1, |
Hans de Goede | a66c108 | 2011-03-26 10:45:02 +0100 | [diff] [blame] | 166 | [f71889a] = 1, |
Jean Delvare | 2740c60 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 167 | [f8000] = 0, |
Jean Delvare | 383586b | 2011-03-26 10:45:02 +0100 | [diff] [blame] | 168 | [f81865f] = 1, |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 169 | [f81866a] = 1, |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 170 | }; |
| 171 | |
Hans de Goede | 4d53811 | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 172 | static const char f71882fg_fan_has_beep[] = { |
Jean Delvare | 2740c60 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 173 | [f71808e] = 0, |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 174 | [f71808a] = 0, |
Jean Delvare | 2740c60 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 175 | [f71858fg] = 0, |
| 176 | [f71862fg] = 1, |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 177 | [f71868a] = 1, |
Jean Delvare | 2740c60 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 178 | [f71869] = 1, |
Hans de Goede | 5da556e | 2011-07-03 13:32:53 +0200 | [diff] [blame] | 179 | [f71869a] = 1, |
Jean Delvare | 2740c60 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 180 | [f71882fg] = 1, |
| 181 | [f71889fg] = 1, |
| 182 | [f71889ed] = 1, |
Hans de Goede | a66c108 | 2011-03-26 10:45:02 +0100 | [diff] [blame] | 183 | [f71889a] = 1, |
Jean Delvare | 2740c60 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 184 | [f8000] = 0, |
Jean Delvare | 383586b | 2011-03-26 10:45:02 +0100 | [diff] [blame] | 185 | [f81865f] = 1, |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 186 | [f81866a] = 1, |
Hans de Goede | 78aa4f7 | 2011-03-09 20:57:12 +0100 | [diff] [blame] | 187 | }; |
| 188 | |
Jean Delvare | f27def0 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 189 | static const char f71882fg_nr_fans[] = { |
| 190 | [f71808e] = 3, |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 191 | [f71808a] = 2, /* +1 fan which is monitor + simple pwm only */ |
Jean Delvare | f27def0 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 192 | [f71858fg] = 3, |
| 193 | [f71862fg] = 3, |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 194 | [f71868a] = 3, |
Jean Delvare | f27def0 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 195 | [f71869] = 3, |
Hans de Goede | 5da556e | 2011-07-03 13:32:53 +0200 | [diff] [blame] | 196 | [f71869a] = 3, |
Jean Delvare | f27def0 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 197 | [f71882fg] = 4, |
| 198 | [f71889fg] = 3, |
| 199 | [f71889ed] = 3, |
Hans de Goede | a66c108 | 2011-03-26 10:45:02 +0100 | [diff] [blame] | 200 | [f71889a] = 3, |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 201 | [f8000] = 3, /* +1 fan which is monitor only */ |
Jean Delvare | 383586b | 2011-03-26 10:45:02 +0100 | [diff] [blame] | 202 | [f81865f] = 2, |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 203 | [f81866a] = 3, |
Jean Delvare | f27def0 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 204 | }; |
| 205 | |
Hans de Goede | 4d53811 | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 206 | static const char f71882fg_temp_has_beep[] = { |
| 207 | [f71808e] = 0, |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 208 | [f71808a] = 1, |
Hans de Goede | 4d53811 | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 209 | [f71858fg] = 0, |
| 210 | [f71862fg] = 1, |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 211 | [f71868a] = 1, |
Hans de Goede | 4d53811 | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 212 | [f71869] = 1, |
Hans de Goede | 5da556e | 2011-07-03 13:32:53 +0200 | [diff] [blame] | 213 | [f71869a] = 1, |
Hans de Goede | 4d53811 | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 214 | [f71882fg] = 1, |
| 215 | [f71889fg] = 1, |
| 216 | [f71889ed] = 1, |
| 217 | [f71889a] = 1, |
| 218 | [f8000] = 0, |
| 219 | [f81865f] = 1, |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 220 | [f81866a] = 1, |
Hans de Goede | 4d53811 | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 221 | }; |
| 222 | |
Jean Delvare | f27def0 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 223 | static const char f71882fg_nr_temps[] = { |
| 224 | [f71808e] = 2, |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 225 | [f71808a] = 2, |
Jean Delvare | f27def0 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 226 | [f71858fg] = 3, |
| 227 | [f71862fg] = 3, |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 228 | [f71868a] = 3, |
Jean Delvare | f27def0 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 229 | [f71869] = 3, |
Hans de Goede | 5da556e | 2011-07-03 13:32:53 +0200 | [diff] [blame] | 230 | [f71869a] = 3, |
Jean Delvare | f27def0 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 231 | [f71882fg] = 3, |
| 232 | [f71889fg] = 3, |
| 233 | [f71889ed] = 3, |
Hans de Goede | a66c108 | 2011-03-26 10:45:02 +0100 | [diff] [blame] | 234 | [f71889a] = 3, |
Jean Delvare | f27def0 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 235 | [f8000] = 3, |
Jean Delvare | 383586b | 2011-03-26 10:45:02 +0100 | [diff] [blame] | 236 | [f81865f] = 2, |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 237 | [f81866a] = 3, |
Jean Delvare | f27def0 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 238 | }; |
| 239 | |
Mark van Doesburg | 77a4a3e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 240 | static struct platform_device *f71882fg_pdev; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 241 | |
| 242 | /* Super-I/O Function prototypes */ |
| 243 | static inline int superio_inb(int base, int reg); |
| 244 | static inline int superio_inw(int base, int reg); |
Giel van Schijndel | cadb865 | 2010-10-03 08:09:49 -0400 | [diff] [blame] | 245 | static inline int superio_enter(int base); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 246 | static inline void superio_select(int base, int ld); |
| 247 | static inline void superio_exit(int base); |
| 248 | |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 249 | struct f71882fg_sio_data { |
| 250 | enum chips type; |
| 251 | }; |
| 252 | |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 253 | struct f71882fg_data { |
| 254 | unsigned short addr; |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 255 | enum chips type; |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 256 | struct device *hwmon_dev; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 257 | |
| 258 | struct mutex update_lock; |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 259 | int temp_start; /* temp numbering start (0 or 1) */ |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 260 | char valid; /* !=0 if following fields are valid */ |
Hans de Goede | 98f7ba1 | 2011-03-09 20:57:09 +0100 | [diff] [blame] | 261 | char auto_point_temp_signed; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 262 | unsigned long last_updated; /* In jiffies */ |
| 263 | unsigned long last_limits; /* In jiffies */ |
| 264 | |
| 265 | /* Register Values */ |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 266 | u8 in[F71882FG_MAX_INS]; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 267 | u8 in1_max; |
| 268 | u8 in_status; |
| 269 | u8 in_beep; |
| 270 | u16 fan[4]; |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 271 | u16 fan_target[4]; |
| 272 | u16 fan_full_speed[4]; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 273 | u8 fan_status; |
| 274 | u8 fan_beep; |
Guenter Roeck | 20eaf72 | 2012-01-19 11:02:17 -0800 | [diff] [blame] | 275 | /* |
| 276 | * Note: all models have max 3 temperature channels, but on some |
| 277 | * they are addressed as 0-2 and on others as 1-3, so for coding |
| 278 | * convenience we reserve space for 4 channels |
| 279 | */ |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 280 | u16 temp[4]; |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 281 | u8 temp_ovt[4]; |
| 282 | u8 temp_high[4]; |
Hans de Goede | bc27490 | 2009-01-07 16:37:29 +0100 | [diff] [blame] | 283 | u8 temp_hyst[2]; /* 2 hysts stored per reg */ |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 284 | u8 temp_type[4]; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 285 | u8 temp_status; |
| 286 | u8 temp_beep; |
| 287 | u8 temp_diode_open; |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 288 | u8 temp_config; |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 289 | u8 pwm[4]; |
| 290 | u8 pwm_enable; |
| 291 | u8 pwm_auto_point_hyst[2]; |
| 292 | u8 pwm_auto_point_mapping[4]; |
| 293 | u8 pwm_auto_point_pwm[4][5]; |
Hans de Goede | 7669896 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 294 | s8 pwm_auto_point_temp[4][4]; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 295 | }; |
| 296 | |
Mark van Doesburg | 77a4a3e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 297 | /* Sysfs in */ |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 298 | static ssize_t show_in(struct device *dev, struct device_attribute *devattr, |
| 299 | char *buf); |
| 300 | static ssize_t show_in_max(struct device *dev, struct device_attribute |
| 301 | *devattr, char *buf); |
| 302 | static ssize_t store_in_max(struct device *dev, struct device_attribute |
| 303 | *devattr, const char *buf, size_t count); |
| 304 | static ssize_t show_in_beep(struct device *dev, struct device_attribute |
| 305 | *devattr, char *buf); |
| 306 | static ssize_t store_in_beep(struct device *dev, struct device_attribute |
| 307 | *devattr, const char *buf, size_t count); |
| 308 | static ssize_t show_in_alarm(struct device *dev, struct device_attribute |
| 309 | *devattr, char *buf); |
| 310 | /* Sysfs Fan */ |
| 311 | static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, |
| 312 | char *buf); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 313 | static ssize_t show_fan_full_speed(struct device *dev, |
| 314 | struct device_attribute *devattr, char *buf); |
| 315 | static ssize_t store_fan_full_speed(struct device *dev, |
| 316 | struct device_attribute *devattr, const char *buf, size_t count); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 317 | static ssize_t show_fan_beep(struct device *dev, struct device_attribute |
| 318 | *devattr, char *buf); |
| 319 | static ssize_t store_fan_beep(struct device *dev, struct device_attribute |
| 320 | *devattr, const char *buf, size_t count); |
| 321 | static ssize_t show_fan_alarm(struct device *dev, struct device_attribute |
| 322 | *devattr, char *buf); |
| 323 | /* Sysfs Temp */ |
| 324 | static ssize_t show_temp(struct device *dev, struct device_attribute |
| 325 | *devattr, char *buf); |
| 326 | static ssize_t show_temp_max(struct device *dev, struct device_attribute |
| 327 | *devattr, char *buf); |
| 328 | static ssize_t store_temp_max(struct device *dev, struct device_attribute |
| 329 | *devattr, const char *buf, size_t count); |
| 330 | static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute |
| 331 | *devattr, char *buf); |
| 332 | static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute |
| 333 | *devattr, const char *buf, size_t count); |
| 334 | static ssize_t show_temp_crit(struct device *dev, struct device_attribute |
| 335 | *devattr, char *buf); |
| 336 | static ssize_t store_temp_crit(struct device *dev, struct device_attribute |
| 337 | *devattr, const char *buf, size_t count); |
| 338 | static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute |
| 339 | *devattr, char *buf); |
| 340 | static ssize_t show_temp_type(struct device *dev, struct device_attribute |
| 341 | *devattr, char *buf); |
| 342 | static ssize_t show_temp_beep(struct device *dev, struct device_attribute |
| 343 | *devattr, char *buf); |
| 344 | static ssize_t store_temp_beep(struct device *dev, struct device_attribute |
| 345 | *devattr, const char *buf, size_t count); |
| 346 | static ssize_t show_temp_alarm(struct device *dev, struct device_attribute |
| 347 | *devattr, char *buf); |
| 348 | static ssize_t show_temp_fault(struct device *dev, struct device_attribute |
| 349 | *devattr, char *buf); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 350 | /* PWM and Auto point control */ |
| 351 | static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, |
| 352 | char *buf); |
| 353 | static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr, |
| 354 | const char *buf, size_t count); |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 355 | static ssize_t show_simple_pwm(struct device *dev, |
| 356 | struct device_attribute *devattr, char *buf); |
| 357 | static ssize_t store_simple_pwm(struct device *dev, |
| 358 | struct device_attribute *devattr, const char *buf, size_t count); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 359 | static ssize_t show_pwm_enable(struct device *dev, |
| 360 | struct device_attribute *devattr, char *buf); |
| 361 | static ssize_t store_pwm_enable(struct device *dev, |
| 362 | struct device_attribute *devattr, const char *buf, size_t count); |
| 363 | static ssize_t show_pwm_interpolate(struct device *dev, |
| 364 | struct device_attribute *devattr, char *buf); |
| 365 | static ssize_t store_pwm_interpolate(struct device *dev, |
| 366 | struct device_attribute *devattr, const char *buf, size_t count); |
| 367 | static ssize_t show_pwm_auto_point_channel(struct device *dev, |
| 368 | struct device_attribute *devattr, char *buf); |
| 369 | static ssize_t store_pwm_auto_point_channel(struct device *dev, |
| 370 | struct device_attribute *devattr, const char *buf, size_t count); |
| 371 | static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev, |
| 372 | struct device_attribute *devattr, char *buf); |
| 373 | static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev, |
| 374 | struct device_attribute *devattr, const char *buf, size_t count); |
| 375 | static ssize_t show_pwm_auto_point_pwm(struct device *dev, |
| 376 | struct device_attribute *devattr, char *buf); |
| 377 | static ssize_t store_pwm_auto_point_pwm(struct device *dev, |
| 378 | struct device_attribute *devattr, const char *buf, size_t count); |
| 379 | static ssize_t show_pwm_auto_point_temp(struct device *dev, |
| 380 | struct device_attribute *devattr, char *buf); |
| 381 | static ssize_t store_pwm_auto_point_temp(struct device *dev, |
| 382 | struct device_attribute *devattr, const char *buf, size_t count); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 383 | /* Sysfs misc */ |
| 384 | static ssize_t show_name(struct device *dev, struct device_attribute *devattr, |
| 385 | char *buf); |
| 386 | |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 387 | static int f71882fg_probe(struct platform_device *pdev); |
Hans de Goede | c13548c | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 388 | static int f71882fg_remove(struct platform_device *pdev); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 389 | |
| 390 | static struct platform_driver f71882fg_driver = { |
| 391 | .driver = { |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 392 | .name = DRVNAME, |
| 393 | }, |
| 394 | .probe = f71882fg_probe, |
Jean Delvare | cd659fd | 2009-06-15 18:39:45 +0200 | [diff] [blame] | 395 | .remove = f71882fg_remove, |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 396 | }; |
| 397 | |
Hans de Goede | c13548c | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 398 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 399 | |
Guenter Roeck | 20eaf72 | 2012-01-19 11:02:17 -0800 | [diff] [blame] | 400 | /* |
| 401 | * Temp attr for the f71858fg, the f71858fg is special as it has its |
| 402 | * temperature indexes start at 0 (the others start at 1) |
| 403 | */ |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 404 | static struct sensor_device_attribute_2 f71858fg_temp_attr[] = { |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 405 | SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0), |
| 406 | SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max, |
| 407 | store_temp_max, 0, 0), |
| 408 | SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst, |
| 409 | store_temp_max_hyst, 0, 0), |
| 410 | SENSOR_ATTR_2(temp1_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 0), |
| 411 | SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit, |
| 412 | store_temp_crit, 0, 0), |
| 413 | SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL, |
| 414 | 0, 0), |
| 415 | SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4), |
| 416 | SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0), |
| 417 | SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1), |
| 418 | SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max, |
| 419 | store_temp_max, 0, 1), |
| 420 | SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst, |
| 421 | store_temp_max_hyst, 0, 1), |
| 422 | SENSOR_ATTR_2(temp2_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1), |
| 423 | SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit, |
| 424 | store_temp_crit, 0, 1), |
| 425 | SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL, |
| 426 | 0, 1), |
| 427 | SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5), |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 428 | SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1), |
| 429 | SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2), |
| 430 | SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max, |
| 431 | store_temp_max, 0, 2), |
| 432 | SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst, |
| 433 | store_temp_max_hyst, 0, 2), |
| 434 | SENSOR_ATTR_2(temp3_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2), |
| 435 | SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit, |
| 436 | store_temp_crit, 0, 2), |
| 437 | SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL, |
| 438 | 0, 2), |
| 439 | SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6), |
| 440 | SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2), |
| 441 | }; |
| 442 | |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 443 | /* Temp attr for the standard models */ |
Hans de Goede | 78aa4f7 | 2011-03-09 20:57:12 +0100 | [diff] [blame] | 444 | static struct sensor_device_attribute_2 fxxxx_temp_attr[3][9] = { { |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 445 | SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 1), |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 446 | SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max, |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 447 | store_temp_max, 0, 1), |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 448 | SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst, |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 449 | store_temp_max_hyst, 0, 1), |
Guenter Roeck | 20eaf72 | 2012-01-19 11:02:17 -0800 | [diff] [blame] | 450 | /* |
| 451 | * Should really be temp1_max_alarm, but older versions did not handle |
| 452 | * the max and crit alarms separately and lm_sensors v2 depends on the |
| 453 | * presence of temp#_alarm files. The same goes for temp2/3 _alarm. |
| 454 | */ |
Hans de Goede | 754a5907b | 2009-01-07 16:37:29 +0100 | [diff] [blame] | 455 | SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1), |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 456 | SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit, |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 457 | store_temp_crit, 0, 1), |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 458 | SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL, |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 459 | 0, 1), |
Hans de Goede | 754a5907b | 2009-01-07 16:37:29 +0100 | [diff] [blame] | 460 | SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5), |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 461 | SENSOR_ATTR_2(temp1_type, S_IRUGO, show_temp_type, NULL, 0, 1), |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 462 | SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 1), |
Hans de Goede | 60d2b37 | 2011-03-09 20:57:11 +0100 | [diff] [blame] | 463 | }, { |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 464 | SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 2), |
| 465 | SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max, |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 466 | store_temp_max, 0, 2), |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 467 | SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst, |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 468 | store_temp_max_hyst, 0, 2), |
Hans de Goede | 754a5907b | 2009-01-07 16:37:29 +0100 | [diff] [blame] | 469 | /* Should be temp2_max_alarm, see temp1_alarm note */ |
| 470 | SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2), |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 471 | SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit, |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 472 | store_temp_crit, 0, 2), |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 473 | SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL, |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 474 | 0, 2), |
Hans de Goede | 754a5907b | 2009-01-07 16:37:29 +0100 | [diff] [blame] | 475 | SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6), |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 476 | SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 2), |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 477 | SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 2), |
Hans de Goede | 60d2b37 | 2011-03-09 20:57:11 +0100 | [diff] [blame] | 478 | }, { |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 479 | SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 3), |
| 480 | SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max, |
| 481 | store_temp_max, 0, 3), |
| 482 | SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst, |
| 483 | store_temp_max_hyst, 0, 3), |
Hans de Goede | 754a5907b | 2009-01-07 16:37:29 +0100 | [diff] [blame] | 484 | /* Should be temp3_max_alarm, see temp1_alarm note */ |
| 485 | SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 3), |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 486 | SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit, |
| 487 | store_temp_crit, 0, 3), |
| 488 | SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL, |
| 489 | 0, 3), |
Hans de Goede | 754a5907b | 2009-01-07 16:37:29 +0100 | [diff] [blame] | 490 | SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 7), |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 491 | SENSOR_ATTR_2(temp3_type, S_IRUGO, show_temp_type, NULL, 0, 3), |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 492 | SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 3), |
Hans de Goede | 60d2b37 | 2011-03-09 20:57:11 +0100 | [diff] [blame] | 493 | } }; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 494 | |
Hans de Goede | 78aa4f7 | 2011-03-09 20:57:12 +0100 | [diff] [blame] | 495 | /* Temp attr for models which can beep on temp alarm */ |
| 496 | static struct sensor_device_attribute_2 fxxxx_temp_beep_attr[3][2] = { { |
| 497 | SENSOR_ATTR_2(temp1_max_beep, S_IRUGO|S_IWUSR, show_temp_beep, |
| 498 | store_temp_beep, 0, 1), |
| 499 | SENSOR_ATTR_2(temp1_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep, |
| 500 | store_temp_beep, 0, 5), |
| 501 | }, { |
| 502 | SENSOR_ATTR_2(temp2_max_beep, S_IRUGO|S_IWUSR, show_temp_beep, |
| 503 | store_temp_beep, 0, 2), |
| 504 | SENSOR_ATTR_2(temp2_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep, |
| 505 | store_temp_beep, 0, 6), |
| 506 | }, { |
| 507 | SENSOR_ATTR_2(temp3_max_beep, S_IRUGO|S_IWUSR, show_temp_beep, |
| 508 | store_temp_beep, 0, 3), |
| 509 | SENSOR_ATTR_2(temp3_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep, |
| 510 | store_temp_beep, 0, 7), |
| 511 | } }; |
| 512 | |
Peter Hung | dcd956f | 2015-07-07 16:22:37 +0800 | [diff] [blame] | 513 | static struct sensor_device_attribute_2 f81866_temp_beep_attr[3][2] = { { |
| 514 | SENSOR_ATTR_2(temp1_max_beep, S_IRUGO|S_IWUSR, show_temp_beep, |
| 515 | store_temp_beep, 0, 0), |
| 516 | SENSOR_ATTR_2(temp1_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep, |
| 517 | store_temp_beep, 0, 4), |
| 518 | }, { |
| 519 | SENSOR_ATTR_2(temp2_max_beep, S_IRUGO|S_IWUSR, show_temp_beep, |
| 520 | store_temp_beep, 0, 1), |
| 521 | SENSOR_ATTR_2(temp2_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep, |
| 522 | store_temp_beep, 0, 5), |
| 523 | }, { |
| 524 | SENSOR_ATTR_2(temp3_max_beep, S_IRUGO|S_IWUSR, show_temp_beep, |
| 525 | store_temp_beep, 0, 2), |
| 526 | SENSOR_ATTR_2(temp3_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep, |
| 527 | store_temp_beep, 0, 6), |
| 528 | } }; |
| 529 | |
Guenter Roeck | 20eaf72 | 2012-01-19 11:02:17 -0800 | [diff] [blame] | 530 | /* |
| 531 | * Temp attr for the f8000 |
| 532 | * Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max) |
| 533 | * is used as hysteresis value to clear alarms |
| 534 | * Also like the f71858fg its temperature indexes start at 0 |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 535 | */ |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 536 | static struct sensor_device_attribute_2 f8000_temp_attr[] = { |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 537 | SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0), |
| 538 | SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_crit, |
| 539 | store_temp_crit, 0, 0), |
| 540 | SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max, |
| 541 | store_temp_max, 0, 0), |
| 542 | SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4), |
Hans de Goede | b6858bc | 2009-06-15 18:39:51 +0200 | [diff] [blame] | 543 | SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0), |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 544 | SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1), |
| 545 | SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_crit, |
| 546 | store_temp_crit, 0, 1), |
| 547 | SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max, |
| 548 | store_temp_max, 0, 1), |
| 549 | SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5), |
Hans de Goede | b6858bc | 2009-06-15 18:39:51 +0200 | [diff] [blame] | 550 | SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1), |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 551 | SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2), |
| 552 | SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_crit, |
| 553 | store_temp_crit, 0, 2), |
| 554 | SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max, |
| 555 | store_temp_max, 0, 2), |
| 556 | SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6), |
Hans de Goede | b6858bc | 2009-06-15 18:39:51 +0200 | [diff] [blame] | 557 | SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2), |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 558 | }; |
| 559 | |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 560 | /* in attr for all models */ |
| 561 | static struct sensor_device_attribute_2 fxxxx_in_attr[] = { |
| 562 | SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0), |
| 563 | SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1), |
| 564 | SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2), |
| 565 | SENSOR_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 0, 3), |
| 566 | SENSOR_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 0, 4), |
| 567 | SENSOR_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 0, 5), |
| 568 | SENSOR_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 0, 6), |
| 569 | SENSOR_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 0, 7), |
| 570 | SENSOR_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 0, 8), |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 571 | SENSOR_ATTR_2(in9_input, S_IRUGO, show_in, NULL, 0, 9), |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 572 | }; |
| 573 | |
| 574 | /* For models with in1 alarm capability */ |
| 575 | static struct sensor_device_attribute_2 fxxxx_in1_alarm_attr[] = { |
| 576 | SENSOR_ATTR_2(in1_max, S_IRUGO|S_IWUSR, show_in_max, store_in_max, |
| 577 | 0, 1), |
| 578 | SENSOR_ATTR_2(in1_beep, S_IRUGO|S_IWUSR, show_in_beep, store_in_beep, |
| 579 | 0, 1), |
| 580 | SENSOR_ATTR_2(in1_alarm, S_IRUGO, show_in_alarm, NULL, 0, 1), |
| 581 | }; |
| 582 | |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 583 | /* Fan / PWM attr common to all models */ |
Hans de Goede | b69b039 | 2009-12-09 20:36:00 +0100 | [diff] [blame] | 584 | static struct sensor_device_attribute_2 fxxxx_fan_attr[4][6] = { { |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 585 | SENSOR_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0), |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 586 | SENSOR_ATTR_2(fan1_full_speed, S_IRUGO|S_IWUSR, |
| 587 | show_fan_full_speed, |
| 588 | store_fan_full_speed, 0, 0), |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 589 | SENSOR_ATTR_2(fan1_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 0), |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 590 | SENSOR_ATTR_2(pwm1, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 0), |
| 591 | SENSOR_ATTR_2(pwm1_enable, S_IRUGO|S_IWUSR, show_pwm_enable, |
| 592 | store_pwm_enable, 0, 0), |
| 593 | SENSOR_ATTR_2(pwm1_interpolate, S_IRUGO|S_IWUSR, |
| 594 | show_pwm_interpolate, store_pwm_interpolate, 0, 0), |
Hans de Goede | b69b039 | 2009-12-09 20:36:00 +0100 | [diff] [blame] | 595 | }, { |
| 596 | SENSOR_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 0, 1), |
| 597 | SENSOR_ATTR_2(fan2_full_speed, S_IRUGO|S_IWUSR, |
| 598 | show_fan_full_speed, |
| 599 | store_fan_full_speed, 0, 1), |
| 600 | SENSOR_ATTR_2(fan2_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 1), |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 601 | SENSOR_ATTR_2(pwm2, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 1), |
| 602 | SENSOR_ATTR_2(pwm2_enable, S_IRUGO|S_IWUSR, show_pwm_enable, |
| 603 | store_pwm_enable, 0, 1), |
| 604 | SENSOR_ATTR_2(pwm2_interpolate, S_IRUGO|S_IWUSR, |
| 605 | show_pwm_interpolate, store_pwm_interpolate, 0, 1), |
Hans de Goede | b69b039 | 2009-12-09 20:36:00 +0100 | [diff] [blame] | 606 | }, { |
| 607 | SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2), |
| 608 | SENSOR_ATTR_2(fan3_full_speed, S_IRUGO|S_IWUSR, |
| 609 | show_fan_full_speed, |
| 610 | store_fan_full_speed, 0, 2), |
| 611 | SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2), |
Hans de Goede | 3fc7838 | 2009-06-15 18:39:50 +0200 | [diff] [blame] | 612 | SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 2), |
| 613 | SENSOR_ATTR_2(pwm3_enable, S_IRUGO|S_IWUSR, show_pwm_enable, |
| 614 | store_pwm_enable, 0, 2), |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 615 | SENSOR_ATTR_2(pwm3_interpolate, S_IRUGO|S_IWUSR, |
| 616 | show_pwm_interpolate, store_pwm_interpolate, 0, 2), |
Hans de Goede | b69b039 | 2009-12-09 20:36:00 +0100 | [diff] [blame] | 617 | }, { |
| 618 | SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3), |
| 619 | SENSOR_ATTR_2(fan4_full_speed, S_IRUGO|S_IWUSR, |
| 620 | show_fan_full_speed, |
| 621 | store_fan_full_speed, 0, 3), |
| 622 | SENSOR_ATTR_2(fan4_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 3), |
| 623 | SENSOR_ATTR_2(pwm4, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 3), |
| 624 | SENSOR_ATTR_2(pwm4_enable, S_IRUGO|S_IWUSR, show_pwm_enable, |
| 625 | store_pwm_enable, 0, 3), |
| 626 | SENSOR_ATTR_2(pwm4_interpolate, S_IRUGO|S_IWUSR, |
| 627 | show_pwm_interpolate, store_pwm_interpolate, 0, 3), |
| 628 | } }; |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 629 | |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 630 | /* Attr for the third fan of the f71808a, which only has manual pwm */ |
| 631 | static struct sensor_device_attribute_2 f71808a_fan3_attr[] = { |
| 632 | SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2), |
| 633 | SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2), |
| 634 | SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR, |
| 635 | show_simple_pwm, store_simple_pwm, 0, 2), |
| 636 | }; |
| 637 | |
Hans de Goede | 66344aa | 2009-12-09 20:35:59 +0100 | [diff] [blame] | 638 | /* Attr for models which can beep on Fan alarm */ |
| 639 | static struct sensor_device_attribute_2 fxxxx_fan_beep_attr[] = { |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 640 | SENSOR_ATTR_2(fan1_beep, S_IRUGO|S_IWUSR, show_fan_beep, |
| 641 | store_fan_beep, 0, 0), |
| 642 | SENSOR_ATTR_2(fan2_beep, S_IRUGO|S_IWUSR, show_fan_beep, |
| 643 | store_fan_beep, 0, 1), |
| 644 | SENSOR_ATTR_2(fan3_beep, S_IRUGO|S_IWUSR, show_fan_beep, |
| 645 | store_fan_beep, 0, 2), |
Hans de Goede | b69b039 | 2009-12-09 20:36:00 +0100 | [diff] [blame] | 646 | SENSOR_ATTR_2(fan4_beep, S_IRUGO|S_IWUSR, show_fan_beep, |
| 647 | store_fan_beep, 0, 3), |
Hans de Goede | 66344aa | 2009-12-09 20:35:59 +0100 | [diff] [blame] | 648 | }; |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 649 | |
Guenter Roeck | 20eaf72 | 2012-01-19 11:02:17 -0800 | [diff] [blame] | 650 | /* |
| 651 | * PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the |
| 652 | * standard models |
| 653 | */ |
Hans de Goede | 5584014 | 2011-09-09 12:12:33 +0200 | [diff] [blame] | 654 | static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr[3][7] = { { |
Hans de Goede | 66344aa | 2009-12-09 20:35:59 +0100 | [diff] [blame] | 655 | SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR, |
| 656 | show_pwm_auto_point_channel, |
| 657 | store_pwm_auto_point_channel, 0, 0), |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 658 | SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR, |
| 659 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 660 | 1, 0), |
| 661 | SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR, |
| 662 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 663 | 4, 0), |
| 664 | SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR, |
| 665 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 666 | 0, 0), |
| 667 | SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR, |
| 668 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 669 | 3, 0), |
| 670 | SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR, |
| 671 | show_pwm_auto_point_temp_hyst, |
| 672 | store_pwm_auto_point_temp_hyst, |
| 673 | 0, 0), |
| 674 | SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO, |
| 675 | show_pwm_auto_point_temp_hyst, NULL, 3, 0), |
Hans de Goede | 5584014 | 2011-09-09 12:12:33 +0200 | [diff] [blame] | 676 | }, { |
Hans de Goede | 66344aa | 2009-12-09 20:35:59 +0100 | [diff] [blame] | 677 | SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR, |
| 678 | show_pwm_auto_point_channel, |
| 679 | store_pwm_auto_point_channel, 0, 1), |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 680 | SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR, |
| 681 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 682 | 1, 1), |
| 683 | SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR, |
| 684 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 685 | 4, 1), |
| 686 | SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR, |
| 687 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 688 | 0, 1), |
| 689 | SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR, |
| 690 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 691 | 3, 1), |
| 692 | SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR, |
| 693 | show_pwm_auto_point_temp_hyst, |
| 694 | store_pwm_auto_point_temp_hyst, |
| 695 | 0, 1), |
| 696 | SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO, |
| 697 | show_pwm_auto_point_temp_hyst, NULL, 3, 1), |
Hans de Goede | 5584014 | 2011-09-09 12:12:33 +0200 | [diff] [blame] | 698 | }, { |
Hans de Goede | 66344aa | 2009-12-09 20:35:59 +0100 | [diff] [blame] | 699 | SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR, |
| 700 | show_pwm_auto_point_channel, |
| 701 | store_pwm_auto_point_channel, 0, 2), |
Hans de Goede | 4901062 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 702 | SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR, |
| 703 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 704 | 1, 2), |
| 705 | SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR, |
| 706 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 707 | 4, 2), |
| 708 | SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR, |
| 709 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 710 | 0, 2), |
| 711 | SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR, |
| 712 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 713 | 3, 2), |
| 714 | SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR, |
| 715 | show_pwm_auto_point_temp_hyst, |
| 716 | store_pwm_auto_point_temp_hyst, |
| 717 | 0, 2), |
| 718 | SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO, |
| 719 | show_pwm_auto_point_temp_hyst, NULL, 3, 2), |
Hans de Goede | 5584014 | 2011-09-09 12:12:33 +0200 | [diff] [blame] | 720 | } }; |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 721 | |
Guenter Roeck | 20eaf72 | 2012-01-19 11:02:17 -0800 | [diff] [blame] | 722 | /* |
| 723 | * PWM attr for the f71808e/f71869, almost identical to the f71862fg, but the |
| 724 | * pwm setting when the temperature is above the pwmX_auto_point1_temp can be |
| 725 | * programmed instead of being hardcoded to 0xff |
| 726 | */ |
Hans de Goede | 5584014 | 2011-09-09 12:12:33 +0200 | [diff] [blame] | 727 | static struct sensor_device_attribute_2 f71869_auto_pwm_attr[3][8] = { { |
Hans de Goede | c11bb99 | 2011-03-09 20:57:15 +0100 | [diff] [blame] | 728 | SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR, |
| 729 | show_pwm_auto_point_channel, |
| 730 | store_pwm_auto_point_channel, 0, 0), |
| 731 | SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR, |
| 732 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 733 | 0, 0), |
| 734 | SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR, |
| 735 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 736 | 1, 0), |
| 737 | SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO|S_IWUSR, |
| 738 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 739 | 4, 0), |
| 740 | SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR, |
| 741 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 742 | 0, 0), |
| 743 | SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR, |
| 744 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 745 | 3, 0), |
| 746 | SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR, |
| 747 | show_pwm_auto_point_temp_hyst, |
| 748 | store_pwm_auto_point_temp_hyst, |
| 749 | 0, 0), |
| 750 | SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO, |
| 751 | show_pwm_auto_point_temp_hyst, NULL, 3, 0), |
Hans de Goede | 5584014 | 2011-09-09 12:12:33 +0200 | [diff] [blame] | 752 | }, { |
Hans de Goede | c11bb99 | 2011-03-09 20:57:15 +0100 | [diff] [blame] | 753 | SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR, |
| 754 | show_pwm_auto_point_channel, |
| 755 | store_pwm_auto_point_channel, 0, 1), |
| 756 | SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR, |
| 757 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 758 | 0, 1), |
| 759 | SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR, |
| 760 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 761 | 1, 1), |
| 762 | SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO|S_IWUSR, |
| 763 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 764 | 4, 1), |
| 765 | SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR, |
| 766 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 767 | 0, 1), |
| 768 | SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR, |
| 769 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 770 | 3, 1), |
| 771 | SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR, |
| 772 | show_pwm_auto_point_temp_hyst, |
| 773 | store_pwm_auto_point_temp_hyst, |
| 774 | 0, 1), |
| 775 | SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO, |
| 776 | show_pwm_auto_point_temp_hyst, NULL, 3, 1), |
Hans de Goede | 5584014 | 2011-09-09 12:12:33 +0200 | [diff] [blame] | 777 | }, { |
Hans de Goede | c11bb99 | 2011-03-09 20:57:15 +0100 | [diff] [blame] | 778 | SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR, |
| 779 | show_pwm_auto_point_channel, |
| 780 | store_pwm_auto_point_channel, 0, 2), |
| 781 | SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR, |
| 782 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 783 | 0, 2), |
| 784 | SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR, |
| 785 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 786 | 1, 2), |
| 787 | SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO|S_IWUSR, |
| 788 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 789 | 4, 2), |
| 790 | SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR, |
| 791 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 792 | 0, 2), |
| 793 | SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR, |
| 794 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 795 | 3, 2), |
| 796 | SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR, |
| 797 | show_pwm_auto_point_temp_hyst, |
| 798 | store_pwm_auto_point_temp_hyst, |
| 799 | 0, 2), |
| 800 | SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO, |
| 801 | show_pwm_auto_point_temp_hyst, NULL, 3, 2), |
Hans de Goede | 5584014 | 2011-09-09 12:12:33 +0200 | [diff] [blame] | 802 | } }; |
Hans de Goede | c11bb99 | 2011-03-09 20:57:15 +0100 | [diff] [blame] | 803 | |
Hans de Goede | 3cad402 | 2011-03-09 20:57:14 +0100 | [diff] [blame] | 804 | /* PWM attr for the standard models */ |
Hans de Goede | b69b039 | 2009-12-09 20:36:00 +0100 | [diff] [blame] | 805 | static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr[4][14] = { { |
Hans de Goede | 66344aa | 2009-12-09 20:35:59 +0100 | [diff] [blame] | 806 | SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR, |
| 807 | show_pwm_auto_point_channel, |
| 808 | store_pwm_auto_point_channel, 0, 0), |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 809 | SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR, |
| 810 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 811 | 0, 0), |
| 812 | SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR, |
| 813 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 814 | 1, 0), |
| 815 | SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO|S_IWUSR, |
| 816 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 817 | 2, 0), |
| 818 | SENSOR_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO|S_IWUSR, |
| 819 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 820 | 3, 0), |
| 821 | SENSOR_ATTR_2(pwm1_auto_point5_pwm, S_IRUGO|S_IWUSR, |
| 822 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 823 | 4, 0), |
| 824 | SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR, |
| 825 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 826 | 0, 0), |
| 827 | SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR, |
| 828 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 829 | 1, 0), |
| 830 | SENSOR_ATTR_2(pwm1_auto_point3_temp, S_IRUGO|S_IWUSR, |
| 831 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 832 | 2, 0), |
| 833 | SENSOR_ATTR_2(pwm1_auto_point4_temp, S_IRUGO|S_IWUSR, |
| 834 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 835 | 3, 0), |
| 836 | SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR, |
| 837 | show_pwm_auto_point_temp_hyst, |
| 838 | store_pwm_auto_point_temp_hyst, |
| 839 | 0, 0), |
| 840 | SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO, |
| 841 | show_pwm_auto_point_temp_hyst, NULL, 1, 0), |
| 842 | SENSOR_ATTR_2(pwm1_auto_point3_temp_hyst, S_IRUGO, |
| 843 | show_pwm_auto_point_temp_hyst, NULL, 2, 0), |
| 844 | SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst, S_IRUGO, |
| 845 | show_pwm_auto_point_temp_hyst, NULL, 3, 0), |
Hans de Goede | b69b039 | 2009-12-09 20:36:00 +0100 | [diff] [blame] | 846 | }, { |
Hans de Goede | 66344aa | 2009-12-09 20:35:59 +0100 | [diff] [blame] | 847 | SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR, |
| 848 | show_pwm_auto_point_channel, |
| 849 | store_pwm_auto_point_channel, 0, 1), |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 850 | SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR, |
| 851 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 852 | 0, 1), |
| 853 | SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR, |
| 854 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 855 | 1, 1), |
| 856 | SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO|S_IWUSR, |
| 857 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 858 | 2, 1), |
| 859 | SENSOR_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO|S_IWUSR, |
| 860 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 861 | 3, 1), |
| 862 | SENSOR_ATTR_2(pwm2_auto_point5_pwm, S_IRUGO|S_IWUSR, |
| 863 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 864 | 4, 1), |
| 865 | SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR, |
| 866 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 867 | 0, 1), |
| 868 | SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR, |
| 869 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 870 | 1, 1), |
| 871 | SENSOR_ATTR_2(pwm2_auto_point3_temp, S_IRUGO|S_IWUSR, |
| 872 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 873 | 2, 1), |
| 874 | SENSOR_ATTR_2(pwm2_auto_point4_temp, S_IRUGO|S_IWUSR, |
| 875 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 876 | 3, 1), |
| 877 | SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR, |
| 878 | show_pwm_auto_point_temp_hyst, |
| 879 | store_pwm_auto_point_temp_hyst, |
| 880 | 0, 1), |
| 881 | SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO, |
| 882 | show_pwm_auto_point_temp_hyst, NULL, 1, 1), |
| 883 | SENSOR_ATTR_2(pwm2_auto_point3_temp_hyst, S_IRUGO, |
| 884 | show_pwm_auto_point_temp_hyst, NULL, 2, 1), |
| 885 | SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst, S_IRUGO, |
| 886 | show_pwm_auto_point_temp_hyst, NULL, 3, 1), |
Hans de Goede | b69b039 | 2009-12-09 20:36:00 +0100 | [diff] [blame] | 887 | }, { |
Hans de Goede | 66344aa | 2009-12-09 20:35:59 +0100 | [diff] [blame] | 888 | SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR, |
| 889 | show_pwm_auto_point_channel, |
| 890 | store_pwm_auto_point_channel, 0, 2), |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 891 | SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR, |
| 892 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 893 | 0, 2), |
| 894 | SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR, |
| 895 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 896 | 1, 2), |
| 897 | SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO|S_IWUSR, |
| 898 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 899 | 2, 2), |
| 900 | SENSOR_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO|S_IWUSR, |
| 901 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 902 | 3, 2), |
| 903 | SENSOR_ATTR_2(pwm3_auto_point5_pwm, S_IRUGO|S_IWUSR, |
| 904 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 905 | 4, 2), |
| 906 | SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR, |
| 907 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 908 | 0, 2), |
| 909 | SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR, |
| 910 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 911 | 1, 2), |
| 912 | SENSOR_ATTR_2(pwm3_auto_point3_temp, S_IRUGO|S_IWUSR, |
| 913 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 914 | 2, 2), |
| 915 | SENSOR_ATTR_2(pwm3_auto_point4_temp, S_IRUGO|S_IWUSR, |
| 916 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 917 | 3, 2), |
| 918 | SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR, |
| 919 | show_pwm_auto_point_temp_hyst, |
| 920 | store_pwm_auto_point_temp_hyst, |
| 921 | 0, 2), |
| 922 | SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO, |
| 923 | show_pwm_auto_point_temp_hyst, NULL, 1, 2), |
| 924 | SENSOR_ATTR_2(pwm3_auto_point3_temp_hyst, S_IRUGO, |
| 925 | show_pwm_auto_point_temp_hyst, NULL, 2, 2), |
| 926 | SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst, S_IRUGO, |
| 927 | show_pwm_auto_point_temp_hyst, NULL, 3, 2), |
Hans de Goede | b69b039 | 2009-12-09 20:36:00 +0100 | [diff] [blame] | 928 | }, { |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 929 | SENSOR_ATTR_2(pwm4_auto_channels_temp, S_IRUGO|S_IWUSR, |
| 930 | show_pwm_auto_point_channel, |
| 931 | store_pwm_auto_point_channel, 0, 3), |
| 932 | SENSOR_ATTR_2(pwm4_auto_point1_pwm, S_IRUGO|S_IWUSR, |
| 933 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 934 | 0, 3), |
| 935 | SENSOR_ATTR_2(pwm4_auto_point2_pwm, S_IRUGO|S_IWUSR, |
| 936 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 937 | 1, 3), |
| 938 | SENSOR_ATTR_2(pwm4_auto_point3_pwm, S_IRUGO|S_IWUSR, |
| 939 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 940 | 2, 3), |
| 941 | SENSOR_ATTR_2(pwm4_auto_point4_pwm, S_IRUGO|S_IWUSR, |
| 942 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 943 | 3, 3), |
| 944 | SENSOR_ATTR_2(pwm4_auto_point5_pwm, S_IRUGO|S_IWUSR, |
| 945 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 946 | 4, 3), |
| 947 | SENSOR_ATTR_2(pwm4_auto_point1_temp, S_IRUGO|S_IWUSR, |
| 948 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 949 | 0, 3), |
| 950 | SENSOR_ATTR_2(pwm4_auto_point2_temp, S_IRUGO|S_IWUSR, |
| 951 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 952 | 1, 3), |
| 953 | SENSOR_ATTR_2(pwm4_auto_point3_temp, S_IRUGO|S_IWUSR, |
| 954 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 955 | 2, 3), |
| 956 | SENSOR_ATTR_2(pwm4_auto_point4_temp, S_IRUGO|S_IWUSR, |
| 957 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 958 | 3, 3), |
| 959 | SENSOR_ATTR_2(pwm4_auto_point1_temp_hyst, S_IRUGO|S_IWUSR, |
| 960 | show_pwm_auto_point_temp_hyst, |
| 961 | store_pwm_auto_point_temp_hyst, |
| 962 | 0, 3), |
| 963 | SENSOR_ATTR_2(pwm4_auto_point2_temp_hyst, S_IRUGO, |
| 964 | show_pwm_auto_point_temp_hyst, NULL, 1, 3), |
| 965 | SENSOR_ATTR_2(pwm4_auto_point3_temp_hyst, S_IRUGO, |
| 966 | show_pwm_auto_point_temp_hyst, NULL, 2, 3), |
| 967 | SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst, S_IRUGO, |
| 968 | show_pwm_auto_point_temp_hyst, NULL, 3, 3), |
Hans de Goede | b69b039 | 2009-12-09 20:36:00 +0100 | [diff] [blame] | 969 | } }; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 970 | |
Hans de Goede | 66344aa | 2009-12-09 20:35:59 +0100 | [diff] [blame] | 971 | /* Fan attr specific to the f8000 (4th fan input can only measure speed) */ |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 972 | static struct sensor_device_attribute_2 f8000_fan_attr[] = { |
| 973 | SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3), |
Hans de Goede | 66344aa | 2009-12-09 20:35:59 +0100 | [diff] [blame] | 974 | }; |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 975 | |
Guenter Roeck | 20eaf72 | 2012-01-19 11:02:17 -0800 | [diff] [blame] | 976 | /* |
| 977 | * PWM attr for the f8000, zones mapped to temp instead of to pwm! |
| 978 | * Also the register block at offset A0 maps to TEMP1 (so our temp2, as the |
| 979 | * F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0 |
| 980 | */ |
Hans de Goede | 5584014 | 2011-09-09 12:12:33 +0200 | [diff] [blame] | 981 | static struct sensor_device_attribute_2 f8000_auto_pwm_attr[3][14] = { { |
Hans de Goede | 66344aa | 2009-12-09 20:35:59 +0100 | [diff] [blame] | 982 | SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR, |
| 983 | show_pwm_auto_point_channel, |
| 984 | store_pwm_auto_point_channel, 0, 0), |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 985 | SENSOR_ATTR_2(temp1_auto_point1_pwm, S_IRUGO|S_IWUSR, |
| 986 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 987 | 0, 2), |
| 988 | SENSOR_ATTR_2(temp1_auto_point2_pwm, S_IRUGO|S_IWUSR, |
| 989 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 990 | 1, 2), |
| 991 | SENSOR_ATTR_2(temp1_auto_point3_pwm, S_IRUGO|S_IWUSR, |
| 992 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 993 | 2, 2), |
| 994 | SENSOR_ATTR_2(temp1_auto_point4_pwm, S_IRUGO|S_IWUSR, |
| 995 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 996 | 3, 2), |
| 997 | SENSOR_ATTR_2(temp1_auto_point5_pwm, S_IRUGO|S_IWUSR, |
| 998 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 999 | 4, 2), |
| 1000 | SENSOR_ATTR_2(temp1_auto_point1_temp, S_IRUGO|S_IWUSR, |
| 1001 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 1002 | 0, 2), |
| 1003 | SENSOR_ATTR_2(temp1_auto_point2_temp, S_IRUGO|S_IWUSR, |
| 1004 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 1005 | 1, 2), |
| 1006 | SENSOR_ATTR_2(temp1_auto_point3_temp, S_IRUGO|S_IWUSR, |
| 1007 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 1008 | 2, 2), |
| 1009 | SENSOR_ATTR_2(temp1_auto_point4_temp, S_IRUGO|S_IWUSR, |
| 1010 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 1011 | 3, 2), |
| 1012 | SENSOR_ATTR_2(temp1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR, |
| 1013 | show_pwm_auto_point_temp_hyst, |
| 1014 | store_pwm_auto_point_temp_hyst, |
| 1015 | 0, 2), |
| 1016 | SENSOR_ATTR_2(temp1_auto_point2_temp_hyst, S_IRUGO, |
| 1017 | show_pwm_auto_point_temp_hyst, NULL, 1, 2), |
| 1018 | SENSOR_ATTR_2(temp1_auto_point3_temp_hyst, S_IRUGO, |
| 1019 | show_pwm_auto_point_temp_hyst, NULL, 2, 2), |
| 1020 | SENSOR_ATTR_2(temp1_auto_point4_temp_hyst, S_IRUGO, |
| 1021 | show_pwm_auto_point_temp_hyst, NULL, 3, 2), |
Hans de Goede | 5584014 | 2011-09-09 12:12:33 +0200 | [diff] [blame] | 1022 | }, { |
Hans de Goede | 66344aa | 2009-12-09 20:35:59 +0100 | [diff] [blame] | 1023 | SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR, |
| 1024 | show_pwm_auto_point_channel, |
| 1025 | store_pwm_auto_point_channel, 0, 1), |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 1026 | SENSOR_ATTR_2(temp2_auto_point1_pwm, S_IRUGO|S_IWUSR, |
| 1027 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 1028 | 0, 0), |
| 1029 | SENSOR_ATTR_2(temp2_auto_point2_pwm, S_IRUGO|S_IWUSR, |
| 1030 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 1031 | 1, 0), |
| 1032 | SENSOR_ATTR_2(temp2_auto_point3_pwm, S_IRUGO|S_IWUSR, |
| 1033 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 1034 | 2, 0), |
| 1035 | SENSOR_ATTR_2(temp2_auto_point4_pwm, S_IRUGO|S_IWUSR, |
| 1036 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 1037 | 3, 0), |
| 1038 | SENSOR_ATTR_2(temp2_auto_point5_pwm, S_IRUGO|S_IWUSR, |
| 1039 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 1040 | 4, 0), |
| 1041 | SENSOR_ATTR_2(temp2_auto_point1_temp, S_IRUGO|S_IWUSR, |
| 1042 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 1043 | 0, 0), |
| 1044 | SENSOR_ATTR_2(temp2_auto_point2_temp, S_IRUGO|S_IWUSR, |
| 1045 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 1046 | 1, 0), |
| 1047 | SENSOR_ATTR_2(temp2_auto_point3_temp, S_IRUGO|S_IWUSR, |
| 1048 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 1049 | 2, 0), |
| 1050 | SENSOR_ATTR_2(temp2_auto_point4_temp, S_IRUGO|S_IWUSR, |
| 1051 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 1052 | 3, 0), |
| 1053 | SENSOR_ATTR_2(temp2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR, |
| 1054 | show_pwm_auto_point_temp_hyst, |
| 1055 | store_pwm_auto_point_temp_hyst, |
| 1056 | 0, 0), |
| 1057 | SENSOR_ATTR_2(temp2_auto_point2_temp_hyst, S_IRUGO, |
| 1058 | show_pwm_auto_point_temp_hyst, NULL, 1, 0), |
| 1059 | SENSOR_ATTR_2(temp2_auto_point3_temp_hyst, S_IRUGO, |
| 1060 | show_pwm_auto_point_temp_hyst, NULL, 2, 0), |
| 1061 | SENSOR_ATTR_2(temp2_auto_point4_temp_hyst, S_IRUGO, |
| 1062 | show_pwm_auto_point_temp_hyst, NULL, 3, 0), |
Hans de Goede | 5584014 | 2011-09-09 12:12:33 +0200 | [diff] [blame] | 1063 | }, { |
Hans de Goede | 66344aa | 2009-12-09 20:35:59 +0100 | [diff] [blame] | 1064 | SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR, |
| 1065 | show_pwm_auto_point_channel, |
| 1066 | store_pwm_auto_point_channel, 0, 2), |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 1067 | SENSOR_ATTR_2(temp3_auto_point1_pwm, S_IRUGO|S_IWUSR, |
| 1068 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 1069 | 0, 1), |
| 1070 | SENSOR_ATTR_2(temp3_auto_point2_pwm, S_IRUGO|S_IWUSR, |
| 1071 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 1072 | 1, 1), |
| 1073 | SENSOR_ATTR_2(temp3_auto_point3_pwm, S_IRUGO|S_IWUSR, |
| 1074 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 1075 | 2, 1), |
| 1076 | SENSOR_ATTR_2(temp3_auto_point4_pwm, S_IRUGO|S_IWUSR, |
| 1077 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 1078 | 3, 1), |
| 1079 | SENSOR_ATTR_2(temp3_auto_point5_pwm, S_IRUGO|S_IWUSR, |
| 1080 | show_pwm_auto_point_pwm, store_pwm_auto_point_pwm, |
| 1081 | 4, 1), |
| 1082 | SENSOR_ATTR_2(temp3_auto_point1_temp, S_IRUGO|S_IWUSR, |
| 1083 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 1084 | 0, 1), |
| 1085 | SENSOR_ATTR_2(temp3_auto_point2_temp, S_IRUGO|S_IWUSR, |
| 1086 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 1087 | 1, 1), |
| 1088 | SENSOR_ATTR_2(temp3_auto_point3_temp, S_IRUGO|S_IWUSR, |
| 1089 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 1090 | 2, 1), |
| 1091 | SENSOR_ATTR_2(temp3_auto_point4_temp, S_IRUGO|S_IWUSR, |
| 1092 | show_pwm_auto_point_temp, store_pwm_auto_point_temp, |
| 1093 | 3, 1), |
| 1094 | SENSOR_ATTR_2(temp3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR, |
| 1095 | show_pwm_auto_point_temp_hyst, |
| 1096 | store_pwm_auto_point_temp_hyst, |
| 1097 | 0, 1), |
| 1098 | SENSOR_ATTR_2(temp3_auto_point2_temp_hyst, S_IRUGO, |
| 1099 | show_pwm_auto_point_temp_hyst, NULL, 1, 1), |
| 1100 | SENSOR_ATTR_2(temp3_auto_point3_temp_hyst, S_IRUGO, |
| 1101 | show_pwm_auto_point_temp_hyst, NULL, 2, 1), |
| 1102 | SENSOR_ATTR_2(temp3_auto_point4_temp_hyst, S_IRUGO, |
| 1103 | show_pwm_auto_point_temp_hyst, NULL, 3, 1), |
Hans de Goede | 5584014 | 2011-09-09 12:12:33 +0200 | [diff] [blame] | 1104 | } }; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1105 | |
| 1106 | /* Super I/O functions */ |
| 1107 | static inline int superio_inb(int base, int reg) |
| 1108 | { |
| 1109 | outb(reg, base); |
| 1110 | return inb(base + 1); |
| 1111 | } |
| 1112 | |
| 1113 | static int superio_inw(int base, int reg) |
| 1114 | { |
| 1115 | int val; |
Giel van Schijndel | bd328ac | 2010-05-27 19:58:42 +0200 | [diff] [blame] | 1116 | val = superio_inb(base, reg) << 8; |
| 1117 | val |= superio_inb(base, reg + 1); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1118 | return val; |
| 1119 | } |
| 1120 | |
Giel van Schijndel | cadb865 | 2010-10-03 08:09:49 -0400 | [diff] [blame] | 1121 | static inline int superio_enter(int base) |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1122 | { |
Giel van Schijndel | cadb865 | 2010-10-03 08:09:49 -0400 | [diff] [blame] | 1123 | /* Don't step on other drivers' I/O space by accident */ |
| 1124 | if (!request_muxed_region(base, 2, DRVNAME)) { |
Joe Perches | 22d3b41 | 2010-10-20 06:51:34 +0000 | [diff] [blame] | 1125 | pr_err("I/O address 0x%04x already in use\n", base); |
Giel van Schijndel | cadb865 | 2010-10-03 08:09:49 -0400 | [diff] [blame] | 1126 | return -EBUSY; |
| 1127 | } |
| 1128 | |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1129 | /* according to the datasheet the key must be send twice! */ |
Giel van Schijndel | 162bb59 | 2010-05-27 19:58:40 +0200 | [diff] [blame] | 1130 | outb(SIO_UNLOCK_KEY, base); |
| 1131 | outb(SIO_UNLOCK_KEY, base); |
Giel van Schijndel | cadb865 | 2010-10-03 08:09:49 -0400 | [diff] [blame] | 1132 | |
| 1133 | return 0; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1134 | } |
| 1135 | |
Giel van Schijndel | 162bb59 | 2010-05-27 19:58:40 +0200 | [diff] [blame] | 1136 | static inline void superio_select(int base, int ld) |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1137 | { |
| 1138 | outb(SIO_REG_LDSEL, base); |
| 1139 | outb(ld, base + 1); |
| 1140 | } |
| 1141 | |
| 1142 | static inline void superio_exit(int base) |
| 1143 | { |
| 1144 | outb(SIO_LOCK_KEY, base); |
Giel van Schijndel | cadb865 | 2010-10-03 08:09:49 -0400 | [diff] [blame] | 1145 | release_region(base, 2); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1146 | } |
| 1147 | |
Hans de Goede | 2f65063 | 2009-01-07 16:37:31 +0100 | [diff] [blame] | 1148 | static inline int fan_from_reg(u16 reg) |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1149 | { |
| 1150 | return reg ? (1500000 / reg) : 0; |
| 1151 | } |
| 1152 | |
Hans de Goede | 2f65063 | 2009-01-07 16:37:31 +0100 | [diff] [blame] | 1153 | static inline u16 fan_to_reg(int fan) |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1154 | { |
| 1155 | return fan ? (1500000 / fan) : 0; |
| 1156 | } |
| 1157 | |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1158 | static u8 f71882fg_read8(struct f71882fg_data *data, u8 reg) |
| 1159 | { |
| 1160 | u8 val; |
| 1161 | |
| 1162 | outb(reg, data->addr + ADDR_REG_OFFSET); |
| 1163 | val = inb(data->addr + DATA_REG_OFFSET); |
| 1164 | |
| 1165 | return val; |
| 1166 | } |
| 1167 | |
| 1168 | static u16 f71882fg_read16(struct f71882fg_data *data, u8 reg) |
| 1169 | { |
| 1170 | u16 val; |
| 1171 | |
Giel van Schijndel | bd328ac | 2010-05-27 19:58:42 +0200 | [diff] [blame] | 1172 | val = f71882fg_read8(data, reg) << 8; |
| 1173 | val |= f71882fg_read8(data, reg + 1); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1174 | |
| 1175 | return val; |
| 1176 | } |
| 1177 | |
| 1178 | static void f71882fg_write8(struct f71882fg_data *data, u8 reg, u8 val) |
| 1179 | { |
| 1180 | outb(reg, data->addr + ADDR_REG_OFFSET); |
| 1181 | outb(val, data->addr + DATA_REG_OFFSET); |
| 1182 | } |
| 1183 | |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1184 | static void f71882fg_write16(struct f71882fg_data *data, u8 reg, u16 val) |
| 1185 | { |
Giel van Schijndel | bd328ac | 2010-05-27 19:58:42 +0200 | [diff] [blame] | 1186 | f71882fg_write8(data, reg, val >> 8); |
| 1187 | f71882fg_write8(data, reg + 1, val & 0xff); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1188 | } |
| 1189 | |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 1190 | static u16 f71882fg_read_temp(struct f71882fg_data *data, int nr) |
| 1191 | { |
| 1192 | if (data->type == f71858fg) |
| 1193 | return f71882fg_read16(data, F71882FG_REG_TEMP(nr)); |
| 1194 | else |
| 1195 | return f71882fg_read8(data, F71882FG_REG_TEMP(nr)); |
| 1196 | } |
| 1197 | |
Mark van Doesburg | 77a4a3e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1198 | static struct f71882fg_data *f71882fg_update_device(struct device *dev) |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1199 | { |
| 1200 | struct f71882fg_data *data = dev_get_drvdata(dev); |
Jean Delvare | f27def0 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 1201 | int nr_fans = f71882fg_nr_fans[data->type]; |
| 1202 | int nr_temps = f71882fg_nr_temps[data->type]; |
Hans de Goede | e5e713c | 2011-03-10 08:54:02 +0100 | [diff] [blame] | 1203 | int nr, reg, point; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1204 | |
| 1205 | mutex_lock(&data->update_lock); |
| 1206 | |
| 1207 | /* Update once every 60 seconds */ |
Giel van Schijndel | 162bb59 | 2010-05-27 19:58:40 +0200 | [diff] [blame] | 1208 | if (time_after(jiffies, data->last_limits + 60 * HZ) || |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1209 | !data->valid) { |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 1210 | if (f71882fg_has_in1_alarm[data->type]) { |
Peter Hung | 3e40b86 | 2015-07-07 16:22:38 +0800 | [diff] [blame^] | 1211 | if (data->type == f81866a) { |
| 1212 | data->in1_max = |
| 1213 | f71882fg_read8(data, |
| 1214 | F81866_REG_IN1_HIGH); |
| 1215 | data->in_beep = |
| 1216 | f71882fg_read8(data, |
| 1217 | F81866_REG_IN_BEEP); |
| 1218 | } else { |
| 1219 | data->in1_max = |
| 1220 | f71882fg_read8(data, |
| 1221 | F71882FG_REG_IN1_HIGH); |
| 1222 | data->in_beep = |
| 1223 | f71882fg_read8(data, |
| 1224 | F71882FG_REG_IN_BEEP); |
| 1225 | } |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1226 | } |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1227 | |
| 1228 | /* Get High & boundary temps*/ |
Hans de Goede | e5e713c | 2011-03-10 08:54:02 +0100 | [diff] [blame] | 1229 | for (nr = data->temp_start; nr < nr_temps + data->temp_start; |
| 1230 | nr++) { |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1231 | data->temp_ovt[nr] = f71882fg_read8(data, |
| 1232 | F71882FG_REG_TEMP_OVT(nr)); |
| 1233 | data->temp_high[nr] = f71882fg_read8(data, |
| 1234 | F71882FG_REG_TEMP_HIGH(nr)); |
| 1235 | } |
| 1236 | |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 1237 | if (data->type != f8000) { |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 1238 | data->temp_hyst[0] = f71882fg_read8(data, |
| 1239 | F71882FG_REG_TEMP_HYST(0)); |
| 1240 | data->temp_hyst[1] = f71882fg_read8(data, |
| 1241 | F71882FG_REG_TEMP_HYST(1)); |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 1242 | } |
Hans de Goede | 78aa4f7 | 2011-03-09 20:57:12 +0100 | [diff] [blame] | 1243 | /* All but the f71858fg / f8000 have this register */ |
| 1244 | if ((data->type != f71858fg) && (data->type != f8000)) { |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 1245 | reg = f71882fg_read8(data, F71882FG_REG_TEMP_TYPE); |
Hans de Goede | 44c4dc5 | 2011-03-09 20:57:07 +0100 | [diff] [blame] | 1246 | data->temp_type[1] = (reg & 0x02) ? 2 : 4; |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 1247 | data->temp_type[2] = (reg & 0x04) ? 2 : 4; |
| 1248 | data->temp_type[3] = (reg & 0x08) ? 2 : 4; |
| 1249 | } |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1250 | |
Hans de Goede | 4d53811 | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 1251 | if (f71882fg_fan_has_beep[data->type]) |
Hans de Goede | 78aa4f7 | 2011-03-09 20:57:12 +0100 | [diff] [blame] | 1252 | data->fan_beep = f71882fg_read8(data, |
| 1253 | F71882FG_REG_FAN_BEEP); |
Hans de Goede | 4d53811 | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 1254 | |
| 1255 | if (f71882fg_temp_has_beep[data->type]) |
Hans de Goede | 78aa4f7 | 2011-03-09 20:57:12 +0100 | [diff] [blame] | 1256 | data->temp_beep = f71882fg_read8(data, |
| 1257 | F71882FG_REG_TEMP_BEEP); |
Hans de Goede | 78aa4f7 | 2011-03-09 20:57:12 +0100 | [diff] [blame] | 1258 | |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1259 | data->pwm_enable = f71882fg_read8(data, |
| 1260 | F71882FG_REG_PWM_ENABLE); |
Hans de Goede | bc27490 | 2009-01-07 16:37:29 +0100 | [diff] [blame] | 1261 | data->pwm_auto_point_hyst[0] = |
| 1262 | f71882fg_read8(data, F71882FG_REG_FAN_HYST(0)); |
| 1263 | data->pwm_auto_point_hyst[1] = |
| 1264 | f71882fg_read8(data, F71882FG_REG_FAN_HYST(1)); |
| 1265 | |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1266 | for (nr = 0; nr < nr_fans; nr++) { |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1267 | data->pwm_auto_point_mapping[nr] = |
| 1268 | f71882fg_read8(data, |
| 1269 | F71882FG_REG_POINT_MAPPING(nr)); |
| 1270 | |
Hans de Goede | e5e713c | 2011-03-10 08:54:02 +0100 | [diff] [blame] | 1271 | switch (data->type) { |
| 1272 | default: |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1273 | for (point = 0; point < 5; point++) { |
| 1274 | data->pwm_auto_point_pwm[nr][point] = |
| 1275 | f71882fg_read8(data, |
| 1276 | F71882FG_REG_POINT_PWM |
| 1277 | (nr, point)); |
| 1278 | } |
| 1279 | for (point = 0; point < 4; point++) { |
| 1280 | data->pwm_auto_point_temp[nr][point] = |
| 1281 | f71882fg_read8(data, |
| 1282 | F71882FG_REG_POINT_TEMP |
| 1283 | (nr, point)); |
| 1284 | } |
Hans de Goede | e5e713c | 2011-03-10 08:54:02 +0100 | [diff] [blame] | 1285 | break; |
| 1286 | case f71808e: |
| 1287 | case f71869: |
| 1288 | data->pwm_auto_point_pwm[nr][0] = |
| 1289 | f71882fg_read8(data, |
| 1290 | F71882FG_REG_POINT_PWM(nr, 0)); |
| 1291 | /* Fall through */ |
| 1292 | case f71862fg: |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1293 | data->pwm_auto_point_pwm[nr][1] = |
| 1294 | f71882fg_read8(data, |
| 1295 | F71882FG_REG_POINT_PWM |
| 1296 | (nr, 1)); |
| 1297 | data->pwm_auto_point_pwm[nr][4] = |
| 1298 | f71882fg_read8(data, |
| 1299 | F71882FG_REG_POINT_PWM |
| 1300 | (nr, 4)); |
| 1301 | data->pwm_auto_point_temp[nr][0] = |
| 1302 | f71882fg_read8(data, |
| 1303 | F71882FG_REG_POINT_TEMP |
| 1304 | (nr, 0)); |
| 1305 | data->pwm_auto_point_temp[nr][3] = |
| 1306 | f71882fg_read8(data, |
| 1307 | F71882FG_REG_POINT_TEMP |
| 1308 | (nr, 3)); |
Hans de Goede | e5e713c | 2011-03-10 08:54:02 +0100 | [diff] [blame] | 1309 | break; |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1310 | } |
| 1311 | } |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1312 | data->last_limits = jiffies; |
| 1313 | } |
| 1314 | |
| 1315 | /* Update every second */ |
Mark M. Hoffman | 8afb104 | 2007-08-21 23:10:46 -0400 | [diff] [blame] | 1316 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1317 | data->temp_status = f71882fg_read8(data, |
| 1318 | F71882FG_REG_TEMP_STATUS); |
| 1319 | data->temp_diode_open = f71882fg_read8(data, |
| 1320 | F71882FG_REG_TEMP_DIODE_OPEN); |
Hans de Goede | e5e713c | 2011-03-10 08:54:02 +0100 | [diff] [blame] | 1321 | for (nr = data->temp_start; nr < nr_temps + data->temp_start; |
| 1322 | nr++) |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 1323 | data->temp[nr] = f71882fg_read_temp(data, nr); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1324 | |
| 1325 | data->fan_status = f71882fg_read8(data, |
| 1326 | F71882FG_REG_FAN_STATUS); |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1327 | for (nr = 0; nr < nr_fans; nr++) { |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1328 | data->fan[nr] = f71882fg_read16(data, |
| 1329 | F71882FG_REG_FAN(nr)); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1330 | data->fan_target[nr] = |
| 1331 | f71882fg_read16(data, F71882FG_REG_FAN_TARGET(nr)); |
| 1332 | data->fan_full_speed[nr] = |
| 1333 | f71882fg_read16(data, |
| 1334 | F71882FG_REG_FAN_FULL_SPEED(nr)); |
| 1335 | data->pwm[nr] = |
| 1336 | f71882fg_read8(data, F71882FG_REG_PWM(nr)); |
| 1337 | } |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 1338 | /* Some models have 1 more fan with limited capabilities */ |
| 1339 | if (data->type == f71808a) { |
| 1340 | data->fan[2] = f71882fg_read16(data, |
| 1341 | F71882FG_REG_FAN(2)); |
| 1342 | data->pwm[2] = f71882fg_read8(data, |
| 1343 | F71882FG_REG_PWM(2)); |
| 1344 | } |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 1345 | if (data->type == f8000) |
| 1346 | data->fan[3] = f71882fg_read16(data, |
| 1347 | F71882FG_REG_FAN(3)); |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 1348 | |
Peter Hung | 3e40b86 | 2015-07-07 16:22:38 +0800 | [diff] [blame^] | 1349 | if (f71882fg_has_in1_alarm[data->type]) { |
| 1350 | if (data->type == f81866a) |
| 1351 | data->in_status = f71882fg_read8(data, |
| 1352 | F81866_REG_IN_STATUS); |
| 1353 | |
| 1354 | else |
| 1355 | data->in_status = f71882fg_read8(data, |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1356 | F71882FG_REG_IN_STATUS); |
Peter Hung | 3e40b86 | 2015-07-07 16:22:38 +0800 | [diff] [blame^] | 1357 | } |
| 1358 | |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 1359 | for (nr = 0; nr < F71882FG_MAX_INS; nr++) |
| 1360 | if (f71882fg_has_in[data->type][nr]) |
| 1361 | data->in[nr] = f71882fg_read8(data, |
| 1362 | F71882FG_REG_IN(nr)); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1363 | |
| 1364 | data->last_updated = jiffies; |
| 1365 | data->valid = 1; |
| 1366 | } |
| 1367 | |
| 1368 | mutex_unlock(&data->update_lock); |
| 1369 | |
| 1370 | return data; |
| 1371 | } |
| 1372 | |
| 1373 | /* Sysfs Interface */ |
| 1374 | static ssize_t show_fan(struct device *dev, struct device_attribute *devattr, |
| 1375 | char *buf) |
| 1376 | { |
| 1377 | struct f71882fg_data *data = f71882fg_update_device(dev); |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1378 | int nr = to_sensor_dev_attr_2(devattr)->index; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1379 | int speed = fan_from_reg(data->fan[nr]); |
| 1380 | |
| 1381 | if (speed == FAN_MIN_DETECT) |
| 1382 | speed = 0; |
| 1383 | |
| 1384 | return sprintf(buf, "%d\n", speed); |
| 1385 | } |
| 1386 | |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1387 | static ssize_t show_fan_full_speed(struct device *dev, |
| 1388 | struct device_attribute *devattr, char *buf) |
| 1389 | { |
| 1390 | struct f71882fg_data *data = f71882fg_update_device(dev); |
| 1391 | int nr = to_sensor_dev_attr_2(devattr)->index; |
| 1392 | int speed = fan_from_reg(data->fan_full_speed[nr]); |
| 1393 | return sprintf(buf, "%d\n", speed); |
| 1394 | } |
| 1395 | |
| 1396 | static ssize_t store_fan_full_speed(struct device *dev, |
| 1397 | struct device_attribute *devattr, |
| 1398 | const char *buf, size_t count) |
| 1399 | { |
| 1400 | struct f71882fg_data *data = dev_get_drvdata(dev); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1401 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
| 1402 | long val; |
| 1403 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1404 | err = kstrtol(buf, 10, &val); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1405 | if (err) |
| 1406 | return err; |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1407 | |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 1408 | val = clamp_val(val, 23, 1500000); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1409 | val = fan_to_reg(val); |
| 1410 | |
| 1411 | mutex_lock(&data->update_lock); |
Hans de Goede | 4c82c38 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 1412 | f71882fg_write16(data, F71882FG_REG_FAN_FULL_SPEED(nr), val); |
| 1413 | data->fan_full_speed[nr] = val; |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1414 | mutex_unlock(&data->update_lock); |
| 1415 | |
| 1416 | return count; |
| 1417 | } |
| 1418 | |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1419 | static ssize_t show_fan_beep(struct device *dev, struct device_attribute |
| 1420 | *devattr, char *buf) |
| 1421 | { |
| 1422 | struct f71882fg_data *data = f71882fg_update_device(dev); |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1423 | int nr = to_sensor_dev_attr_2(devattr)->index; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1424 | |
| 1425 | if (data->fan_beep & (1 << nr)) |
| 1426 | return sprintf(buf, "1\n"); |
| 1427 | else |
| 1428 | return sprintf(buf, "0\n"); |
| 1429 | } |
| 1430 | |
| 1431 | static ssize_t store_fan_beep(struct device *dev, struct device_attribute |
| 1432 | *devattr, const char *buf, size_t count) |
| 1433 | { |
| 1434 | struct f71882fg_data *data = dev_get_drvdata(dev); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1435 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
| 1436 | unsigned long val; |
| 1437 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1438 | err = kstrtoul(buf, 10, &val); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1439 | if (err) |
| 1440 | return err; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1441 | |
| 1442 | mutex_lock(&data->update_lock); |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1443 | data->fan_beep = f71882fg_read8(data, F71882FG_REG_FAN_BEEP); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1444 | if (val) |
| 1445 | data->fan_beep |= 1 << nr; |
| 1446 | else |
| 1447 | data->fan_beep &= ~(1 << nr); |
| 1448 | |
| 1449 | f71882fg_write8(data, F71882FG_REG_FAN_BEEP, data->fan_beep); |
| 1450 | mutex_unlock(&data->update_lock); |
| 1451 | |
| 1452 | return count; |
| 1453 | } |
| 1454 | |
| 1455 | static ssize_t show_fan_alarm(struct device *dev, struct device_attribute |
| 1456 | *devattr, char *buf) |
| 1457 | { |
| 1458 | struct f71882fg_data *data = f71882fg_update_device(dev); |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1459 | int nr = to_sensor_dev_attr_2(devattr)->index; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1460 | |
| 1461 | if (data->fan_status & (1 << nr)) |
| 1462 | return sprintf(buf, "1\n"); |
| 1463 | else |
| 1464 | return sprintf(buf, "0\n"); |
| 1465 | } |
| 1466 | |
| 1467 | static ssize_t show_in(struct device *dev, struct device_attribute *devattr, |
| 1468 | char *buf) |
| 1469 | { |
| 1470 | struct f71882fg_data *data = f71882fg_update_device(dev); |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1471 | int nr = to_sensor_dev_attr_2(devattr)->index; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1472 | |
| 1473 | return sprintf(buf, "%d\n", data->in[nr] * 8); |
| 1474 | } |
| 1475 | |
| 1476 | static ssize_t show_in_max(struct device *dev, struct device_attribute |
| 1477 | *devattr, char *buf) |
| 1478 | { |
| 1479 | struct f71882fg_data *data = f71882fg_update_device(dev); |
| 1480 | |
| 1481 | return sprintf(buf, "%d\n", data->in1_max * 8); |
| 1482 | } |
| 1483 | |
| 1484 | static ssize_t store_in_max(struct device *dev, struct device_attribute |
| 1485 | *devattr, const char *buf, size_t count) |
| 1486 | { |
| 1487 | struct f71882fg_data *data = dev_get_drvdata(dev); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1488 | int err; |
| 1489 | long val; |
| 1490 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1491 | err = kstrtol(buf, 10, &val); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1492 | if (err) |
| 1493 | return err; |
| 1494 | |
| 1495 | val /= 8; |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 1496 | val = clamp_val(val, 0, 255); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1497 | |
| 1498 | mutex_lock(&data->update_lock); |
Peter Hung | 3e40b86 | 2015-07-07 16:22:38 +0800 | [diff] [blame^] | 1499 | if (data->type == f81866a) |
| 1500 | f71882fg_write8(data, F81866_REG_IN1_HIGH, val); |
| 1501 | else |
| 1502 | f71882fg_write8(data, F71882FG_REG_IN1_HIGH, val); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1503 | data->in1_max = val; |
| 1504 | mutex_unlock(&data->update_lock); |
| 1505 | |
| 1506 | return count; |
| 1507 | } |
| 1508 | |
| 1509 | static ssize_t show_in_beep(struct device *dev, struct device_attribute |
| 1510 | *devattr, char *buf) |
| 1511 | { |
| 1512 | struct f71882fg_data *data = f71882fg_update_device(dev); |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1513 | int nr = to_sensor_dev_attr_2(devattr)->index; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1514 | |
| 1515 | if (data->in_beep & (1 << nr)) |
| 1516 | return sprintf(buf, "1\n"); |
| 1517 | else |
| 1518 | return sprintf(buf, "0\n"); |
| 1519 | } |
| 1520 | |
| 1521 | static ssize_t store_in_beep(struct device *dev, struct device_attribute |
| 1522 | *devattr, const char *buf, size_t count) |
| 1523 | { |
| 1524 | struct f71882fg_data *data = dev_get_drvdata(dev); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1525 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
| 1526 | unsigned long val; |
| 1527 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1528 | err = kstrtoul(buf, 10, &val); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1529 | if (err) |
| 1530 | return err; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1531 | |
| 1532 | mutex_lock(&data->update_lock); |
Peter Hung | 3e40b86 | 2015-07-07 16:22:38 +0800 | [diff] [blame^] | 1533 | if (data->type == f81866a) |
| 1534 | data->in_beep = f71882fg_read8(data, F81866_REG_IN_BEEP); |
| 1535 | else |
| 1536 | data->in_beep = f71882fg_read8(data, F71882FG_REG_IN_BEEP); |
| 1537 | |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1538 | if (val) |
| 1539 | data->in_beep |= 1 << nr; |
| 1540 | else |
| 1541 | data->in_beep &= ~(1 << nr); |
| 1542 | |
Peter Hung | 3e40b86 | 2015-07-07 16:22:38 +0800 | [diff] [blame^] | 1543 | if (data->type == f81866a) |
| 1544 | f71882fg_write8(data, F81866_REG_IN_BEEP, data->in_beep); |
| 1545 | else |
| 1546 | f71882fg_write8(data, F71882FG_REG_IN_BEEP, data->in_beep); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1547 | mutex_unlock(&data->update_lock); |
| 1548 | |
| 1549 | return count; |
| 1550 | } |
| 1551 | |
| 1552 | static ssize_t show_in_alarm(struct device *dev, struct device_attribute |
| 1553 | *devattr, char *buf) |
| 1554 | { |
| 1555 | struct f71882fg_data *data = f71882fg_update_device(dev); |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1556 | int nr = to_sensor_dev_attr_2(devattr)->index; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1557 | |
| 1558 | if (data->in_status & (1 << nr)) |
| 1559 | return sprintf(buf, "1\n"); |
| 1560 | else |
| 1561 | return sprintf(buf, "0\n"); |
| 1562 | } |
| 1563 | |
| 1564 | static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, |
| 1565 | char *buf) |
| 1566 | { |
| 1567 | struct f71882fg_data *data = f71882fg_update_device(dev); |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1568 | int nr = to_sensor_dev_attr_2(devattr)->index; |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 1569 | int sign, temp; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1570 | |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 1571 | if (data->type == f71858fg) { |
| 1572 | /* TEMP_TABLE_SEL 1 or 3 ? */ |
| 1573 | if (data->temp_config & 1) { |
| 1574 | sign = data->temp[nr] & 0x0001; |
| 1575 | temp = (data->temp[nr] >> 5) & 0x7ff; |
| 1576 | } else { |
| 1577 | sign = data->temp[nr] & 0x8000; |
| 1578 | temp = (data->temp[nr] >> 5) & 0x3ff; |
| 1579 | } |
| 1580 | temp *= 125; |
| 1581 | if (sign) |
| 1582 | temp -= 128000; |
| 1583 | } else |
| 1584 | temp = data->temp[nr] * 1000; |
| 1585 | |
| 1586 | return sprintf(buf, "%d\n", temp); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1587 | } |
| 1588 | |
| 1589 | static ssize_t show_temp_max(struct device *dev, struct device_attribute |
| 1590 | *devattr, char *buf) |
| 1591 | { |
| 1592 | struct f71882fg_data *data = f71882fg_update_device(dev); |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1593 | int nr = to_sensor_dev_attr_2(devattr)->index; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1594 | |
| 1595 | return sprintf(buf, "%d\n", data->temp_high[nr] * 1000); |
| 1596 | } |
| 1597 | |
| 1598 | static ssize_t store_temp_max(struct device *dev, struct device_attribute |
| 1599 | *devattr, const char *buf, size_t count) |
| 1600 | { |
| 1601 | struct f71882fg_data *data = dev_get_drvdata(dev); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1602 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
| 1603 | long val; |
| 1604 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1605 | err = kstrtol(buf, 10, &val); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1606 | if (err) |
| 1607 | return err; |
| 1608 | |
| 1609 | val /= 1000; |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 1610 | val = clamp_val(val, 0, 255); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1611 | |
| 1612 | mutex_lock(&data->update_lock); |
| 1613 | f71882fg_write8(data, F71882FG_REG_TEMP_HIGH(nr), val); |
| 1614 | data->temp_high[nr] = val; |
| 1615 | mutex_unlock(&data->update_lock); |
| 1616 | |
| 1617 | return count; |
| 1618 | } |
| 1619 | |
| 1620 | static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute |
| 1621 | *devattr, char *buf) |
| 1622 | { |
| 1623 | struct f71882fg_data *data = f71882fg_update_device(dev); |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1624 | int nr = to_sensor_dev_attr_2(devattr)->index; |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1625 | int temp_max_hyst; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1626 | |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1627 | mutex_lock(&data->update_lock); |
Hans de Goede | bc27490 | 2009-01-07 16:37:29 +0100 | [diff] [blame] | 1628 | if (nr & 1) |
| 1629 | temp_max_hyst = data->temp_hyst[nr / 2] >> 4; |
| 1630 | else |
| 1631 | temp_max_hyst = data->temp_hyst[nr / 2] & 0x0f; |
| 1632 | temp_max_hyst = (data->temp_high[nr] - temp_max_hyst) * 1000; |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1633 | mutex_unlock(&data->update_lock); |
| 1634 | |
| 1635 | return sprintf(buf, "%d\n", temp_max_hyst); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1636 | } |
| 1637 | |
| 1638 | static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute |
| 1639 | *devattr, const char *buf, size_t count) |
| 1640 | { |
| 1641 | struct f71882fg_data *data = dev_get_drvdata(dev); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1642 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1643 | ssize_t ret = count; |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1644 | u8 reg; |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1645 | long val; |
| 1646 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1647 | err = kstrtol(buf, 10, &val); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1648 | if (err) |
| 1649 | return err; |
| 1650 | |
| 1651 | val /= 1000; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1652 | |
| 1653 | mutex_lock(&data->update_lock); |
| 1654 | |
| 1655 | /* convert abs to relative and check */ |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1656 | data->temp_high[nr] = f71882fg_read8(data, F71882FG_REG_TEMP_HIGH(nr)); |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 1657 | val = clamp_val(val, data->temp_high[nr] - 15, data->temp_high[nr]); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1658 | val = data->temp_high[nr] - val; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1659 | |
| 1660 | /* convert value to register contents */ |
Hans de Goede | bc27490 | 2009-01-07 16:37:29 +0100 | [diff] [blame] | 1661 | reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST(nr / 2)); |
| 1662 | if (nr & 1) |
| 1663 | reg = (reg & 0x0f) | (val << 4); |
| 1664 | else |
| 1665 | reg = (reg & 0xf0) | val; |
| 1666 | f71882fg_write8(data, F71882FG_REG_TEMP_HYST(nr / 2), reg); |
| 1667 | data->temp_hyst[nr / 2] = reg; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1668 | |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1669 | mutex_unlock(&data->update_lock); |
| 1670 | return ret; |
| 1671 | } |
| 1672 | |
| 1673 | static ssize_t show_temp_crit(struct device *dev, struct device_attribute |
| 1674 | *devattr, char *buf) |
| 1675 | { |
| 1676 | struct f71882fg_data *data = f71882fg_update_device(dev); |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1677 | int nr = to_sensor_dev_attr_2(devattr)->index; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1678 | |
| 1679 | return sprintf(buf, "%d\n", data->temp_ovt[nr] * 1000); |
| 1680 | } |
| 1681 | |
| 1682 | static ssize_t store_temp_crit(struct device *dev, struct device_attribute |
| 1683 | *devattr, const char *buf, size_t count) |
| 1684 | { |
| 1685 | struct f71882fg_data *data = dev_get_drvdata(dev); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1686 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
| 1687 | long val; |
| 1688 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1689 | err = kstrtol(buf, 10, &val); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1690 | if (err) |
| 1691 | return err; |
| 1692 | |
| 1693 | val /= 1000; |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 1694 | val = clamp_val(val, 0, 255); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1695 | |
| 1696 | mutex_lock(&data->update_lock); |
| 1697 | f71882fg_write8(data, F71882FG_REG_TEMP_OVT(nr), val); |
| 1698 | data->temp_ovt[nr] = val; |
| 1699 | mutex_unlock(&data->update_lock); |
| 1700 | |
| 1701 | return count; |
| 1702 | } |
| 1703 | |
| 1704 | static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute |
| 1705 | *devattr, char *buf) |
| 1706 | { |
| 1707 | struct f71882fg_data *data = f71882fg_update_device(dev); |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1708 | int nr = to_sensor_dev_attr_2(devattr)->index; |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1709 | int temp_crit_hyst; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1710 | |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1711 | mutex_lock(&data->update_lock); |
Hans de Goede | bc27490 | 2009-01-07 16:37:29 +0100 | [diff] [blame] | 1712 | if (nr & 1) |
| 1713 | temp_crit_hyst = data->temp_hyst[nr / 2] >> 4; |
| 1714 | else |
| 1715 | temp_crit_hyst = data->temp_hyst[nr / 2] & 0x0f; |
| 1716 | temp_crit_hyst = (data->temp_ovt[nr] - temp_crit_hyst) * 1000; |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1717 | mutex_unlock(&data->update_lock); |
| 1718 | |
| 1719 | return sprintf(buf, "%d\n", temp_crit_hyst); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | static ssize_t show_temp_type(struct device *dev, struct device_attribute |
| 1723 | *devattr, char *buf) |
| 1724 | { |
| 1725 | struct f71882fg_data *data = f71882fg_update_device(dev); |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1726 | int nr = to_sensor_dev_attr_2(devattr)->index; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1727 | |
| 1728 | return sprintf(buf, "%d\n", data->temp_type[nr]); |
| 1729 | } |
| 1730 | |
| 1731 | static ssize_t show_temp_beep(struct device *dev, struct device_attribute |
| 1732 | *devattr, char *buf) |
| 1733 | { |
| 1734 | struct f71882fg_data *data = f71882fg_update_device(dev); |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1735 | int nr = to_sensor_dev_attr_2(devattr)->index; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1736 | |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1737 | if (data->temp_beep & (1 << nr)) |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1738 | return sprintf(buf, "1\n"); |
| 1739 | else |
| 1740 | return sprintf(buf, "0\n"); |
| 1741 | } |
| 1742 | |
| 1743 | static ssize_t store_temp_beep(struct device *dev, struct device_attribute |
| 1744 | *devattr, const char *buf, size_t count) |
| 1745 | { |
| 1746 | struct f71882fg_data *data = dev_get_drvdata(dev); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1747 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
| 1748 | unsigned long val; |
| 1749 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1750 | err = kstrtoul(buf, 10, &val); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1751 | if (err) |
| 1752 | return err; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1753 | |
| 1754 | mutex_lock(&data->update_lock); |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1755 | data->temp_beep = f71882fg_read8(data, F71882FG_REG_TEMP_BEEP); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1756 | if (val) |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1757 | data->temp_beep |= 1 << nr; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1758 | else |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1759 | data->temp_beep &= ~(1 << nr); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1760 | |
| 1761 | f71882fg_write8(data, F71882FG_REG_TEMP_BEEP, data->temp_beep); |
| 1762 | mutex_unlock(&data->update_lock); |
| 1763 | |
| 1764 | return count; |
| 1765 | } |
| 1766 | |
| 1767 | static ssize_t show_temp_alarm(struct device *dev, struct device_attribute |
| 1768 | *devattr, char *buf) |
| 1769 | { |
| 1770 | struct f71882fg_data *data = f71882fg_update_device(dev); |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1771 | int nr = to_sensor_dev_attr_2(devattr)->index; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1772 | |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1773 | if (data->temp_status & (1 << nr)) |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1774 | return sprintf(buf, "1\n"); |
| 1775 | else |
| 1776 | return sprintf(buf, "0\n"); |
| 1777 | } |
| 1778 | |
| 1779 | static ssize_t show_temp_fault(struct device *dev, struct device_attribute |
| 1780 | *devattr, char *buf) |
| 1781 | { |
| 1782 | struct f71882fg_data *data = f71882fg_update_device(dev); |
Mark van Doesburg | bc37ae7 | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1783 | int nr = to_sensor_dev_attr_2(devattr)->index; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1784 | |
Hans de Goede | 7567a04 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1785 | if (data->temp_diode_open & (1 << nr)) |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 1786 | return sprintf(buf, "1\n"); |
| 1787 | else |
| 1788 | return sprintf(buf, "0\n"); |
| 1789 | } |
| 1790 | |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1791 | static ssize_t show_pwm(struct device *dev, |
| 1792 | struct device_attribute *devattr, char *buf) |
| 1793 | { |
| 1794 | struct f71882fg_data *data = f71882fg_update_device(dev); |
| 1795 | int val, nr = to_sensor_dev_attr_2(devattr)->index; |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1796 | mutex_lock(&data->update_lock); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1797 | if (data->pwm_enable & (1 << (2 * nr))) |
| 1798 | /* PWM mode */ |
| 1799 | val = data->pwm[nr]; |
| 1800 | else { |
| 1801 | /* RPM mode */ |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1802 | val = 255 * fan_from_reg(data->fan_target[nr]) |
| 1803 | / fan_from_reg(data->fan_full_speed[nr]); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1804 | } |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1805 | mutex_unlock(&data->update_lock); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1806 | return sprintf(buf, "%d\n", val); |
| 1807 | } |
| 1808 | |
| 1809 | static ssize_t store_pwm(struct device *dev, |
| 1810 | struct device_attribute *devattr, const char *buf, |
| 1811 | size_t count) |
| 1812 | { |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1813 | struct f71882fg_data *data = dev_get_drvdata(dev); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1814 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
| 1815 | long val; |
| 1816 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1817 | err = kstrtol(buf, 10, &val); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1818 | if (err) |
| 1819 | return err; |
| 1820 | |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 1821 | val = clamp_val(val, 0, 255); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1822 | |
| 1823 | mutex_lock(&data->update_lock); |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1824 | data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE); |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 1825 | if ((data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 3) != 2) || |
| 1826 | (data->type != f8000 && !((data->pwm_enable >> 2 * nr) & 2))) { |
| 1827 | count = -EROFS; |
| 1828 | goto leave; |
| 1829 | } |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1830 | if (data->pwm_enable & (1 << (2 * nr))) { |
| 1831 | /* PWM mode */ |
| 1832 | f71882fg_write8(data, F71882FG_REG_PWM(nr), val); |
| 1833 | data->pwm[nr] = val; |
| 1834 | } else { |
| 1835 | /* RPM mode */ |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1836 | int target, full_speed; |
| 1837 | full_speed = f71882fg_read16(data, |
| 1838 | F71882FG_REG_FAN_FULL_SPEED(nr)); |
| 1839 | target = fan_to_reg(val * fan_from_reg(full_speed) / 255); |
| 1840 | f71882fg_write16(data, F71882FG_REG_FAN_TARGET(nr), target); |
| 1841 | data->fan_target[nr] = target; |
| 1842 | data->fan_full_speed[nr] = full_speed; |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1843 | } |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 1844 | leave: |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1845 | mutex_unlock(&data->update_lock); |
| 1846 | |
| 1847 | return count; |
| 1848 | } |
| 1849 | |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 1850 | static ssize_t show_simple_pwm(struct device *dev, |
| 1851 | struct device_attribute *devattr, char *buf) |
| 1852 | { |
| 1853 | struct f71882fg_data *data = f71882fg_update_device(dev); |
| 1854 | int val, nr = to_sensor_dev_attr_2(devattr)->index; |
| 1855 | |
| 1856 | val = data->pwm[nr]; |
| 1857 | return sprintf(buf, "%d\n", val); |
| 1858 | } |
| 1859 | |
| 1860 | static ssize_t store_simple_pwm(struct device *dev, |
| 1861 | struct device_attribute *devattr, |
| 1862 | const char *buf, size_t count) |
| 1863 | { |
| 1864 | struct f71882fg_data *data = dev_get_drvdata(dev); |
| 1865 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
| 1866 | long val; |
| 1867 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1868 | err = kstrtol(buf, 10, &val); |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 1869 | if (err) |
| 1870 | return err; |
| 1871 | |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 1872 | val = clamp_val(val, 0, 255); |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 1873 | |
| 1874 | mutex_lock(&data->update_lock); |
| 1875 | f71882fg_write8(data, F71882FG_REG_PWM(nr), val); |
| 1876 | data->pwm[nr] = val; |
| 1877 | mutex_unlock(&data->update_lock); |
| 1878 | |
| 1879 | return count; |
| 1880 | } |
| 1881 | |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1882 | static ssize_t show_pwm_enable(struct device *dev, |
| 1883 | struct device_attribute *devattr, char *buf) |
| 1884 | { |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 1885 | int result = 0; |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1886 | struct f71882fg_data *data = f71882fg_update_device(dev); |
| 1887 | int nr = to_sensor_dev_attr_2(devattr)->index; |
| 1888 | |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 1889 | switch ((data->pwm_enable >> 2 * nr) & 3) { |
| 1890 | case 0: |
| 1891 | case 1: |
| 1892 | result = 2; /* Normal auto mode */ |
| 1893 | break; |
| 1894 | case 2: |
| 1895 | result = 1; /* Manual mode */ |
| 1896 | break; |
| 1897 | case 3: |
| 1898 | if (data->type == f8000) |
| 1899 | result = 3; /* Thermostat mode */ |
| 1900 | else |
| 1901 | result = 1; /* Manual mode */ |
| 1902 | break; |
| 1903 | } |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1904 | |
| 1905 | return sprintf(buf, "%d\n", result); |
| 1906 | } |
| 1907 | |
| 1908 | static ssize_t store_pwm_enable(struct device *dev, struct device_attribute |
| 1909 | *devattr, const char *buf, size_t count) |
| 1910 | { |
| 1911 | struct f71882fg_data *data = dev_get_drvdata(dev); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1912 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
| 1913 | long val; |
| 1914 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1915 | err = kstrtol(buf, 10, &val); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1916 | if (err) |
| 1917 | return err; |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1918 | |
Hans de Goede | 3fc7838 | 2009-06-15 18:39:50 +0200 | [diff] [blame] | 1919 | /* Special case for F8000 pwm channel 3 which only does auto mode */ |
| 1920 | if (data->type == f8000 && nr == 2 && val != 2) |
| 1921 | return -EINVAL; |
| 1922 | |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1923 | mutex_lock(&data->update_lock); |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1924 | data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE); |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 1925 | /* Special case for F8000 auto PWM mode / Thermostat mode */ |
| 1926 | if (data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 1)) { |
| 1927 | switch (val) { |
| 1928 | case 2: |
| 1929 | data->pwm_enable &= ~(2 << (2 * nr)); |
| 1930 | break; /* Normal auto mode */ |
| 1931 | case 3: |
| 1932 | data->pwm_enable |= 2 << (2 * nr); |
| 1933 | break; /* Thermostat mode */ |
| 1934 | default: |
| 1935 | count = -EINVAL; |
| 1936 | goto leave; |
| 1937 | } |
| 1938 | } else { |
| 1939 | switch (val) { |
| 1940 | case 1: |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 1941 | /* The f71858fg does not support manual RPM mode */ |
| 1942 | if (data->type == f71858fg && |
| 1943 | ((data->pwm_enable >> (2 * nr)) & 1)) { |
| 1944 | count = -EINVAL; |
| 1945 | goto leave; |
| 1946 | } |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 1947 | data->pwm_enable |= 2 << (2 * nr); |
| 1948 | break; /* Manual */ |
| 1949 | case 2: |
| 1950 | data->pwm_enable &= ~(2 << (2 * nr)); |
| 1951 | break; /* Normal auto mode */ |
| 1952 | default: |
| 1953 | count = -EINVAL; |
| 1954 | goto leave; |
| 1955 | } |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1956 | } |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1957 | f71882fg_write8(data, F71882FG_REG_PWM_ENABLE, data->pwm_enable); |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 1958 | leave: |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1959 | mutex_unlock(&data->update_lock); |
| 1960 | |
| 1961 | return count; |
| 1962 | } |
| 1963 | |
| 1964 | static ssize_t show_pwm_auto_point_pwm(struct device *dev, |
| 1965 | struct device_attribute *devattr, |
| 1966 | char *buf) |
| 1967 | { |
| 1968 | int result; |
| 1969 | struct f71882fg_data *data = f71882fg_update_device(dev); |
| 1970 | int pwm = to_sensor_dev_attr_2(devattr)->index; |
| 1971 | int point = to_sensor_dev_attr_2(devattr)->nr; |
| 1972 | |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1973 | mutex_lock(&data->update_lock); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1974 | if (data->pwm_enable & (1 << (2 * pwm))) { |
| 1975 | /* PWM mode */ |
| 1976 | result = data->pwm_auto_point_pwm[pwm][point]; |
| 1977 | } else { |
| 1978 | /* RPM mode */ |
| 1979 | result = 32 * 255 / (32 + data->pwm_auto_point_pwm[pwm][point]); |
| 1980 | } |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1981 | mutex_unlock(&data->update_lock); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1982 | |
| 1983 | return sprintf(buf, "%d\n", result); |
| 1984 | } |
| 1985 | |
| 1986 | static ssize_t store_pwm_auto_point_pwm(struct device *dev, |
| 1987 | struct device_attribute *devattr, |
| 1988 | const char *buf, size_t count) |
| 1989 | { |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 1990 | struct f71882fg_data *data = dev_get_drvdata(dev); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1991 | int err, pwm = to_sensor_dev_attr_2(devattr)->index; |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 1992 | int point = to_sensor_dev_attr_2(devattr)->nr; |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1993 | long val; |
| 1994 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 1995 | err = kstrtol(buf, 10, &val); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 1996 | if (err) |
| 1997 | return err; |
| 1998 | |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 1999 | val = clamp_val(val, 0, 255); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2000 | |
| 2001 | mutex_lock(&data->update_lock); |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2002 | data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2003 | if (data->pwm_enable & (1 << (2 * pwm))) { |
| 2004 | /* PWM mode */ |
| 2005 | } else { |
| 2006 | /* RPM mode */ |
| 2007 | if (val < 29) /* Prevent negative numbers */ |
| 2008 | val = 255; |
| 2009 | else |
| 2010 | val = (255 - val) * 32 / val; |
| 2011 | } |
| 2012 | f71882fg_write8(data, F71882FG_REG_POINT_PWM(pwm, point), val); |
| 2013 | data->pwm_auto_point_pwm[pwm][point] = val; |
| 2014 | mutex_unlock(&data->update_lock); |
| 2015 | |
| 2016 | return count; |
| 2017 | } |
| 2018 | |
| 2019 | static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev, |
| 2020 | struct device_attribute *devattr, |
| 2021 | char *buf) |
| 2022 | { |
| 2023 | int result = 0; |
| 2024 | struct f71882fg_data *data = f71882fg_update_device(dev); |
| 2025 | int nr = to_sensor_dev_attr_2(devattr)->index; |
| 2026 | int point = to_sensor_dev_attr_2(devattr)->nr; |
| 2027 | |
| 2028 | mutex_lock(&data->update_lock); |
Hans de Goede | bc27490 | 2009-01-07 16:37:29 +0100 | [diff] [blame] | 2029 | if (nr & 1) |
| 2030 | result = data->pwm_auto_point_hyst[nr / 2] >> 4; |
| 2031 | else |
| 2032 | result = data->pwm_auto_point_hyst[nr / 2] & 0x0f; |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2033 | result = 1000 * (data->pwm_auto_point_temp[nr][point] - result); |
| 2034 | mutex_unlock(&data->update_lock); |
| 2035 | |
| 2036 | return sprintf(buf, "%d\n", result); |
| 2037 | } |
| 2038 | |
| 2039 | static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev, |
| 2040 | struct device_attribute *devattr, |
| 2041 | const char *buf, size_t count) |
| 2042 | { |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2043 | struct f71882fg_data *data = dev_get_drvdata(dev); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 2044 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2045 | int point = to_sensor_dev_attr_2(devattr)->nr; |
Hans de Goede | bc27490 | 2009-01-07 16:37:29 +0100 | [diff] [blame] | 2046 | u8 reg; |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 2047 | long val; |
| 2048 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 2049 | err = kstrtol(buf, 10, &val); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 2050 | if (err) |
| 2051 | return err; |
| 2052 | |
| 2053 | val /= 1000; |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2054 | |
| 2055 | mutex_lock(&data->update_lock); |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2056 | data->pwm_auto_point_temp[nr][point] = |
| 2057 | f71882fg_read8(data, F71882FG_REG_POINT_TEMP(nr, point)); |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 2058 | val = clamp_val(val, data->pwm_auto_point_temp[nr][point] - 15, |
| 2059 | data->pwm_auto_point_temp[nr][point]); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2060 | val = data->pwm_auto_point_temp[nr][point] - val; |
| 2061 | |
Hans de Goede | bc27490 | 2009-01-07 16:37:29 +0100 | [diff] [blame] | 2062 | reg = f71882fg_read8(data, F71882FG_REG_FAN_HYST(nr / 2)); |
| 2063 | if (nr & 1) |
| 2064 | reg = (reg & 0x0f) | (val << 4); |
| 2065 | else |
| 2066 | reg = (reg & 0xf0) | val; |
| 2067 | |
| 2068 | f71882fg_write8(data, F71882FG_REG_FAN_HYST(nr / 2), reg); |
| 2069 | data->pwm_auto_point_hyst[nr / 2] = reg; |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2070 | mutex_unlock(&data->update_lock); |
| 2071 | |
| 2072 | return count; |
| 2073 | } |
| 2074 | |
| 2075 | static ssize_t show_pwm_interpolate(struct device *dev, |
| 2076 | struct device_attribute *devattr, char *buf) |
| 2077 | { |
| 2078 | int result; |
| 2079 | struct f71882fg_data *data = f71882fg_update_device(dev); |
| 2080 | int nr = to_sensor_dev_attr_2(devattr)->index; |
| 2081 | |
| 2082 | result = (data->pwm_auto_point_mapping[nr] >> 4) & 1; |
| 2083 | |
| 2084 | return sprintf(buf, "%d\n", result); |
| 2085 | } |
| 2086 | |
| 2087 | static ssize_t store_pwm_interpolate(struct device *dev, |
| 2088 | struct device_attribute *devattr, |
| 2089 | const char *buf, size_t count) |
| 2090 | { |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2091 | struct f71882fg_data *data = dev_get_drvdata(dev); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 2092 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
| 2093 | unsigned long val; |
| 2094 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 2095 | err = kstrtoul(buf, 10, &val); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 2096 | if (err) |
| 2097 | return err; |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2098 | |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2099 | mutex_lock(&data->update_lock); |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2100 | data->pwm_auto_point_mapping[nr] = |
| 2101 | f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr)); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2102 | if (val) |
| 2103 | val = data->pwm_auto_point_mapping[nr] | (1 << 4); |
| 2104 | else |
| 2105 | val = data->pwm_auto_point_mapping[nr] & (~(1 << 4)); |
| 2106 | f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val); |
| 2107 | data->pwm_auto_point_mapping[nr] = val; |
| 2108 | mutex_unlock(&data->update_lock); |
| 2109 | |
| 2110 | return count; |
| 2111 | } |
| 2112 | |
| 2113 | static ssize_t show_pwm_auto_point_channel(struct device *dev, |
| 2114 | struct device_attribute *devattr, |
| 2115 | char *buf) |
| 2116 | { |
| 2117 | int result; |
| 2118 | struct f71882fg_data *data = f71882fg_update_device(dev); |
| 2119 | int nr = to_sensor_dev_attr_2(devattr)->index; |
| 2120 | |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 2121 | result = 1 << ((data->pwm_auto_point_mapping[nr] & 3) - |
| 2122 | data->temp_start); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2123 | |
| 2124 | return sprintf(buf, "%d\n", result); |
| 2125 | } |
| 2126 | |
| 2127 | static ssize_t store_pwm_auto_point_channel(struct device *dev, |
| 2128 | struct device_attribute *devattr, |
| 2129 | const char *buf, size_t count) |
| 2130 | { |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2131 | struct f71882fg_data *data = dev_get_drvdata(dev); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 2132 | int err, nr = to_sensor_dev_attr_2(devattr)->index; |
| 2133 | long val; |
| 2134 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 2135 | err = kstrtol(buf, 10, &val); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 2136 | if (err) |
| 2137 | return err; |
Hans de Goede | 3045301 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 2138 | |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2139 | switch (val) { |
| 2140 | case 1: |
Hans de Goede | 3045301 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 2141 | val = 0; |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2142 | break; |
| 2143 | case 2: |
Hans de Goede | 3045301 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 2144 | val = 1; |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2145 | break; |
| 2146 | case 4: |
Hans de Goede | 3045301 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 2147 | val = 2; |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2148 | break; |
| 2149 | default: |
| 2150 | return -EINVAL; |
| 2151 | } |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 2152 | val += data->temp_start; |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2153 | mutex_lock(&data->update_lock); |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2154 | data->pwm_auto_point_mapping[nr] = |
| 2155 | f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr)); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2156 | val = (data->pwm_auto_point_mapping[nr] & 0xfc) | val; |
| 2157 | f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val); |
| 2158 | data->pwm_auto_point_mapping[nr] = val; |
| 2159 | mutex_unlock(&data->update_lock); |
| 2160 | |
| 2161 | return count; |
| 2162 | } |
| 2163 | |
| 2164 | static ssize_t show_pwm_auto_point_temp(struct device *dev, |
| 2165 | struct device_attribute *devattr, |
| 2166 | char *buf) |
| 2167 | { |
| 2168 | int result; |
| 2169 | struct f71882fg_data *data = f71882fg_update_device(dev); |
| 2170 | int pwm = to_sensor_dev_attr_2(devattr)->index; |
| 2171 | int point = to_sensor_dev_attr_2(devattr)->nr; |
| 2172 | |
| 2173 | result = data->pwm_auto_point_temp[pwm][point]; |
| 2174 | return sprintf(buf, "%d\n", 1000 * result); |
| 2175 | } |
| 2176 | |
| 2177 | static ssize_t store_pwm_auto_point_temp(struct device *dev, |
| 2178 | struct device_attribute *devattr, |
| 2179 | const char *buf, size_t count) |
| 2180 | { |
Hans de Goede | ce0bfa5 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2181 | struct f71882fg_data *data = dev_get_drvdata(dev); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 2182 | int err, pwm = to_sensor_dev_attr_2(devattr)->index; |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2183 | int point = to_sensor_dev_attr_2(devattr)->nr; |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 2184 | long val; |
| 2185 | |
Frans Meulenbroeks | 179c4fd | 2012-01-04 20:58:52 +0100 | [diff] [blame] | 2186 | err = kstrtol(buf, 10, &val); |
Giel van Schijndel | e8a4eac | 2010-05-27 19:58:41 +0200 | [diff] [blame] | 2187 | if (err) |
| 2188 | return err; |
| 2189 | |
| 2190 | val /= 1000; |
Hans de Goede | 7669896 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 2191 | |
Hans de Goede | 98f7ba1 | 2011-03-09 20:57:09 +0100 | [diff] [blame] | 2192 | if (data->auto_point_temp_signed) |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 2193 | val = clamp_val(val, -128, 127); |
Hans de Goede | 7669896 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 2194 | else |
Guenter Roeck | 2a844c1 | 2013-01-09 08:09:34 -0800 | [diff] [blame] | 2195 | val = clamp_val(val, 0, 127); |
Mark van Doesburg | 9ab796e | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2196 | |
| 2197 | mutex_lock(&data->update_lock); |
| 2198 | f71882fg_write8(data, F71882FG_REG_POINT_TEMP(pwm, point), val); |
| 2199 | data->pwm_auto_point_temp[pwm][point] = val; |
| 2200 | mutex_unlock(&data->update_lock); |
| 2201 | |
| 2202 | return count; |
| 2203 | } |
| 2204 | |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2205 | static ssize_t show_name(struct device *dev, struct device_attribute *devattr, |
| 2206 | char *buf) |
| 2207 | { |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2208 | struct f71882fg_data *data = dev_get_drvdata(dev); |
| 2209 | return sprintf(buf, "%s\n", f71882fg_names[data->type]); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2210 | } |
| 2211 | |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 2212 | static int f71882fg_create_sysfs_files(struct platform_device *pdev, |
Hans de Goede | c13548c | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2213 | struct sensor_device_attribute_2 *attr, int count) |
| 2214 | { |
| 2215 | int err, i; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2216 | |
Hans de Goede | c13548c | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2217 | for (i = 0; i < count; i++) { |
| 2218 | err = device_create_file(&pdev->dev, &attr[i].dev_attr); |
| 2219 | if (err) |
| 2220 | return err; |
| 2221 | } |
| 2222 | return 0; |
| 2223 | } |
| 2224 | |
Hans de Goede | fc16c56 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 2225 | static void f71882fg_remove_sysfs_files(struct platform_device *pdev, |
| 2226 | struct sensor_device_attribute_2 *attr, int count) |
| 2227 | { |
| 2228 | int i; |
| 2229 | |
| 2230 | for (i = 0; i < count; i++) |
| 2231 | device_remove_file(&pdev->dev, &attr[i].dev_attr); |
| 2232 | } |
| 2233 | |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 2234 | static int f71882fg_create_fan_sysfs_files( |
Hans de Goede | 6543439 | 2011-09-09 12:12:35 +0200 | [diff] [blame] | 2235 | struct platform_device *pdev, int idx) |
Hans de Goede | 9af0794 | 2011-09-09 12:12:34 +0200 | [diff] [blame] | 2236 | { |
| 2237 | struct f71882fg_data *data = platform_get_drvdata(pdev); |
| 2238 | int err; |
| 2239 | |
Hans de Goede | 6543439 | 2011-09-09 12:12:35 +0200 | [diff] [blame] | 2240 | /* Sanity check the pwm setting */ |
| 2241 | err = 0; |
| 2242 | switch (data->type) { |
| 2243 | case f71858fg: |
| 2244 | if (((data->pwm_enable >> (idx * 2)) & 3) == 3) |
| 2245 | err = 1; |
| 2246 | break; |
| 2247 | case f71862fg: |
| 2248 | if (((data->pwm_enable >> (idx * 2)) & 1) != 1) |
| 2249 | err = 1; |
| 2250 | break; |
| 2251 | case f8000: |
| 2252 | if (idx == 2) |
| 2253 | err = data->pwm_enable & 0x20; |
| 2254 | break; |
| 2255 | default: |
| 2256 | break; |
| 2257 | } |
| 2258 | if (err) { |
| 2259 | dev_err(&pdev->dev, |
| 2260 | "Invalid (reserved) pwm settings: 0x%02x, " |
| 2261 | "skipping fan %d\n", |
| 2262 | (data->pwm_enable >> (idx * 2)) & 3, idx + 1); |
| 2263 | return 0; /* This is a non fatal condition */ |
| 2264 | } |
| 2265 | |
Hans de Goede | 9af0794 | 2011-09-09 12:12:34 +0200 | [diff] [blame] | 2266 | err = f71882fg_create_sysfs_files(pdev, &fxxxx_fan_attr[idx][0], |
| 2267 | ARRAY_SIZE(fxxxx_fan_attr[0])); |
| 2268 | if (err) |
| 2269 | return err; |
| 2270 | |
| 2271 | if (f71882fg_fan_has_beep[data->type]) { |
| 2272 | err = f71882fg_create_sysfs_files(pdev, |
| 2273 | &fxxxx_fan_beep_attr[idx], |
| 2274 | 1); |
| 2275 | if (err) |
| 2276 | return err; |
| 2277 | } |
| 2278 | |
Hans de Goede | 6543439 | 2011-09-09 12:12:35 +0200 | [diff] [blame] | 2279 | dev_info(&pdev->dev, "Fan: %d is in %s mode\n", idx + 1, |
| 2280 | (data->pwm_enable & (1 << (2 * idx))) ? "duty-cycle" : "RPM"); |
| 2281 | |
| 2282 | /* Check for unsupported auto pwm settings */ |
| 2283 | switch (data->type) { |
| 2284 | case f71808e: |
| 2285 | case f71808a: |
| 2286 | case f71869: |
| 2287 | case f71869a: |
| 2288 | case f71889fg: |
| 2289 | case f71889ed: |
| 2290 | case f71889a: |
| 2291 | data->pwm_auto_point_mapping[idx] = |
| 2292 | f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(idx)); |
| 2293 | if ((data->pwm_auto_point_mapping[idx] & 0x80) || |
| 2294 | (data->pwm_auto_point_mapping[idx] & 3) == 0) { |
| 2295 | dev_warn(&pdev->dev, |
| 2296 | "Auto pwm controlled by raw digital " |
| 2297 | "data, disabling pwm auto_point " |
| 2298 | "sysfs attributes for fan %d\n", idx + 1); |
| 2299 | return 0; /* This is a non fatal condition */ |
| 2300 | } |
| 2301 | break; |
| 2302 | default: |
| 2303 | break; |
| 2304 | } |
Hans de Goede | 9af0794 | 2011-09-09 12:12:34 +0200 | [diff] [blame] | 2305 | |
| 2306 | switch (data->type) { |
| 2307 | case f71862fg: |
| 2308 | err = f71882fg_create_sysfs_files(pdev, |
| 2309 | &f71862fg_auto_pwm_attr[idx][0], |
| 2310 | ARRAY_SIZE(f71862fg_auto_pwm_attr[0])); |
| 2311 | break; |
| 2312 | case f71808e: |
| 2313 | case f71869: |
| 2314 | err = f71882fg_create_sysfs_files(pdev, |
| 2315 | &f71869_auto_pwm_attr[idx][0], |
| 2316 | ARRAY_SIZE(f71869_auto_pwm_attr[0])); |
| 2317 | break; |
| 2318 | case f8000: |
| 2319 | err = f71882fg_create_sysfs_files(pdev, |
| 2320 | &f8000_auto_pwm_attr[idx][0], |
| 2321 | ARRAY_SIZE(f8000_auto_pwm_attr[0])); |
| 2322 | break; |
| 2323 | default: |
| 2324 | err = f71882fg_create_sysfs_files(pdev, |
| 2325 | &fxxxx_auto_pwm_attr[idx][0], |
| 2326 | ARRAY_SIZE(fxxxx_auto_pwm_attr[0])); |
| 2327 | } |
| 2328 | |
| 2329 | return err; |
| 2330 | } |
| 2331 | |
Bill Pemberton | 6c931ae | 2012-11-19 13:22:35 -0500 | [diff] [blame] | 2332 | static int f71882fg_probe(struct platform_device *pdev) |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2333 | { |
| 2334 | struct f71882fg_data *data; |
Jingoo Han | a8b3a3a | 2013-07-30 17:13:06 +0900 | [diff] [blame] | 2335 | struct f71882fg_sio_data *sio_data = dev_get_platdata(&pdev->dev); |
Jean Delvare | f27def0 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 2336 | int nr_fans = f71882fg_nr_fans[sio_data->type]; |
| 2337 | int nr_temps = f71882fg_nr_temps[sio_data->type]; |
| 2338 | int err, i; |
Peter Hung | dcd956f | 2015-07-07 16:22:37 +0800 | [diff] [blame] | 2339 | int size; |
Hans de Goede | 98f7ba1 | 2011-03-09 20:57:09 +0100 | [diff] [blame] | 2340 | u8 start_reg, reg; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2341 | |
Guenter Roeck | 33cd66e | 2012-06-02 09:58:05 -0700 | [diff] [blame] | 2342 | data = devm_kzalloc(&pdev->dev, sizeof(struct f71882fg_data), |
| 2343 | GFP_KERNEL); |
Hans de Goede | c13548c | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2344 | if (!data) |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2345 | return -ENOMEM; |
| 2346 | |
| 2347 | data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start; |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2348 | data->type = sio_data->type; |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 2349 | data->temp_start = |
Peter Hung | dcd956f | 2015-07-07 16:22:37 +0800 | [diff] [blame] | 2350 | (data->type == f71858fg || data->type == f8000 || |
| 2351 | data->type == f81866a) ? 0 : 1; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2352 | mutex_init(&data->update_lock); |
| 2353 | platform_set_drvdata(pdev, data); |
| 2354 | |
Hans de Goede | 3cc7475 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2355 | start_reg = f71882fg_read8(data, F71882FG_REG_START); |
Hans de Goede | 12d66e8 | 2009-01-07 16:37:29 +0100 | [diff] [blame] | 2356 | if (start_reg & 0x04) { |
| 2357 | dev_warn(&pdev->dev, "Hardware monitor is powered down\n"); |
Guenter Roeck | 33cd66e | 2012-06-02 09:58:05 -0700 | [diff] [blame] | 2358 | return -ENODEV; |
Hans de Goede | 12d66e8 | 2009-01-07 16:37:29 +0100 | [diff] [blame] | 2359 | } |
Hans de Goede | 3cc7475 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2360 | if (!(start_reg & 0x03)) { |
| 2361 | dev_warn(&pdev->dev, "Hardware monitoring not activated\n"); |
Guenter Roeck | 33cd66e | 2012-06-02 09:58:05 -0700 | [diff] [blame] | 2362 | return -ENODEV; |
Hans de Goede | 3cc7475 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2363 | } |
| 2364 | |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2365 | /* Register sysfs interface files */ |
Hans de Goede | c13548c | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2366 | err = device_create_file(&pdev->dev, &dev_attr_name); |
| 2367 | if (err) |
| 2368 | goto exit_unregister_sysfs; |
| 2369 | |
Hans de Goede | c13548c | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2370 | if (start_reg & 0x01) { |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 2371 | switch (data->type) { |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 2372 | case f71858fg: |
| 2373 | data->temp_config = |
| 2374 | f71882fg_read8(data, F71882FG_REG_TEMP_CONFIG); |
| 2375 | if (data->temp_config & 0x10) |
Guenter Roeck | 20eaf72 | 2012-01-19 11:02:17 -0800 | [diff] [blame] | 2376 | /* |
| 2377 | * The f71858fg temperature alarms behave as |
| 2378 | * the f8000 alarms in this mode |
| 2379 | */ |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 2380 | err = f71882fg_create_sysfs_files(pdev, |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 2381 | f8000_temp_attr, |
| 2382 | ARRAY_SIZE(f8000_temp_attr)); |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 2383 | else |
| 2384 | err = f71882fg_create_sysfs_files(pdev, |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 2385 | f71858fg_temp_attr, |
| 2386 | ARRAY_SIZE(f71858fg_temp_attr)); |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 2387 | break; |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 2388 | case f8000: |
| 2389 | err = f71882fg_create_sysfs_files(pdev, |
| 2390 | f8000_temp_attr, |
| 2391 | ARRAY_SIZE(f8000_temp_attr)); |
| 2392 | break; |
Peter Hung | dcd956f | 2015-07-07 16:22:37 +0800 | [diff] [blame] | 2393 | case f81866a: |
| 2394 | err = f71882fg_create_sysfs_files(pdev, |
| 2395 | f71858fg_temp_attr, |
| 2396 | ARRAY_SIZE(f71858fg_temp_attr)); |
| 2397 | break; |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 2398 | default: |
| 2399 | err = f71882fg_create_sysfs_files(pdev, |
Hans de Goede | 60d2b37 | 2011-03-09 20:57:11 +0100 | [diff] [blame] | 2400 | &fxxxx_temp_attr[0][0], |
| 2401 | ARRAY_SIZE(fxxxx_temp_attr[0]) * nr_temps); |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 2402 | } |
| 2403 | if (err) |
| 2404 | goto exit_unregister_sysfs; |
| 2405 | |
Hans de Goede | 4d53811 | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 2406 | if (f71882fg_temp_has_beep[data->type]) { |
Peter Hung | dcd956f | 2015-07-07 16:22:37 +0800 | [diff] [blame] | 2407 | if (data->type == f81866a) { |
| 2408 | size = ARRAY_SIZE(f81866_temp_beep_attr[0]); |
| 2409 | err = f71882fg_create_sysfs_files(pdev, |
| 2410 | &f81866_temp_beep_attr[0][0], |
| 2411 | size * nr_temps); |
| 2412 | |
| 2413 | } else { |
| 2414 | size = ARRAY_SIZE(fxxxx_temp_beep_attr[0]); |
| 2415 | err = f71882fg_create_sysfs_files(pdev, |
| 2416 | &fxxxx_temp_beep_attr[0][0], |
| 2417 | size * nr_temps); |
| 2418 | } |
Hans de Goede | 78aa4f7 | 2011-03-09 20:57:12 +0100 | [diff] [blame] | 2419 | if (err) |
| 2420 | goto exit_unregister_sysfs; |
| 2421 | } |
| 2422 | |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 2423 | for (i = 0; i < F71882FG_MAX_INS; i++) { |
| 2424 | if (f71882fg_has_in[data->type][i]) { |
| 2425 | err = device_create_file(&pdev->dev, |
| 2426 | &fxxxx_in_attr[i].dev_attr); |
| 2427 | if (err) |
| 2428 | goto exit_unregister_sysfs; |
| 2429 | } |
| 2430 | } |
| 2431 | if (f71882fg_has_in1_alarm[data->type]) { |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2432 | err = f71882fg_create_sysfs_files(pdev, |
Hans de Goede | 66344aa | 2009-12-09 20:35:59 +0100 | [diff] [blame] | 2433 | fxxxx_in1_alarm_attr, |
| 2434 | ARRAY_SIZE(fxxxx_in1_alarm_attr)); |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2435 | if (err) |
| 2436 | goto exit_unregister_sysfs; |
| 2437 | } |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2438 | } |
| 2439 | |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2440 | if (start_reg & 0x02) { |
Hans de Goede | 98f7ba1 | 2011-03-09 20:57:09 +0100 | [diff] [blame] | 2441 | switch (data->type) { |
Hans de Goede | e5e713c | 2011-03-10 08:54:02 +0100 | [diff] [blame] | 2442 | case f71808e: |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 2443 | case f71808a: |
Hans de Goede | c11bb99 | 2011-03-09 20:57:15 +0100 | [diff] [blame] | 2444 | case f71869: |
Hans de Goede | 5da556e | 2011-07-03 13:32:53 +0200 | [diff] [blame] | 2445 | case f71869a: |
Hans de Goede | e5e713c | 2011-03-10 08:54:02 +0100 | [diff] [blame] | 2446 | /* These always have signed auto point temps */ |
Hans de Goede | c11bb99 | 2011-03-09 20:57:15 +0100 | [diff] [blame] | 2447 | data->auto_point_temp_signed = 1; |
| 2448 | /* Fall through to select correct fan/pwm reg bank! */ |
Hans de Goede | 98f7ba1 | 2011-03-09 20:57:09 +0100 | [diff] [blame] | 2449 | case f71889fg: |
Hans de Goede | 3cad402 | 2011-03-09 20:57:14 +0100 | [diff] [blame] | 2450 | case f71889ed: |
Hans de Goede | a66c108 | 2011-03-26 10:45:02 +0100 | [diff] [blame] | 2451 | case f71889a: |
Hans de Goede | 98f7ba1 | 2011-03-09 20:57:09 +0100 | [diff] [blame] | 2452 | reg = f71882fg_read8(data, F71882FG_REG_FAN_FAULT_T); |
| 2453 | if (reg & F71882FG_FAN_NEG_TEMP_EN) |
| 2454 | data->auto_point_temp_signed = 1; |
Hans de Goede | 3cad402 | 2011-03-09 20:57:14 +0100 | [diff] [blame] | 2455 | /* Ensure banked pwm registers point to right bank */ |
| 2456 | reg &= ~F71882FG_FAN_PROG_SEL; |
| 2457 | f71882fg_write8(data, F71882FG_REG_FAN_FAULT_T, reg); |
Hans de Goede | 98f7ba1 | 2011-03-09 20:57:09 +0100 | [diff] [blame] | 2458 | break; |
| 2459 | default: |
| 2460 | break; |
| 2461 | } |
| 2462 | |
Hans de Goede | 996cadb | 2009-06-15 18:39:51 +0200 | [diff] [blame] | 2463 | data->pwm_enable = |
| 2464 | f71882fg_read8(data, F71882FG_REG_PWM_ENABLE); |
| 2465 | |
Hans de Goede | 9af0794 | 2011-09-09 12:12:34 +0200 | [diff] [blame] | 2466 | for (i = 0; i < nr_fans; i++) { |
Hans de Goede | 6543439 | 2011-09-09 12:12:35 +0200 | [diff] [blame] | 2467 | err = f71882fg_create_fan_sysfs_files(pdev, i); |
Hans de Goede | 9af0794 | 2011-09-09 12:12:34 +0200 | [diff] [blame] | 2468 | if (err) |
| 2469 | goto exit_unregister_sysfs; |
Hans de Goede | 9af0794 | 2011-09-09 12:12:34 +0200 | [diff] [blame] | 2470 | } |
| 2471 | |
| 2472 | /* Some types have 1 extra fan with limited functionality */ |
Hans de Goede | e48a7f1 | 2011-03-09 20:57:13 +0100 | [diff] [blame] | 2473 | switch (data->type) { |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 2474 | case f71808a: |
| 2475 | err = f71882fg_create_sysfs_files(pdev, |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 2476 | f71808a_fan3_attr, |
| 2477 | ARRAY_SIZE(f71808a_fan3_attr)); |
| 2478 | break; |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 2479 | case f8000: |
| 2480 | err = f71882fg_create_sysfs_files(pdev, |
| 2481 | f8000_fan_attr, |
| 2482 | ARRAY_SIZE(f8000_fan_attr)); |
| 2483 | break; |
Hans de Goede | e48a7f1 | 2011-03-09 20:57:13 +0100 | [diff] [blame] | 2484 | default: |
Hans de Goede | 9af0794 | 2011-09-09 12:12:34 +0200 | [diff] [blame] | 2485 | break; |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2486 | } |
Hans de Goede | c13548c | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2487 | if (err) |
| 2488 | goto exit_unregister_sysfs; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2489 | } |
| 2490 | |
Tony Jones | 1beeffe | 2007-08-20 13:46:20 -0700 | [diff] [blame] | 2491 | data->hwmon_dev = hwmon_device_register(&pdev->dev); |
| 2492 | if (IS_ERR(data->hwmon_dev)) { |
| 2493 | err = PTR_ERR(data->hwmon_dev); |
Hans de Goede | c13548c | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2494 | data->hwmon_dev = NULL; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2495 | goto exit_unregister_sysfs; |
| 2496 | } |
| 2497 | |
| 2498 | return 0; |
| 2499 | |
| 2500 | exit_unregister_sysfs: |
Hans de Goede | c13548c | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2501 | f71882fg_remove(pdev); /* Will unregister the sysfs files for us */ |
Hans de Goede | 3cc7475 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2502 | return err; /* f71882fg_remove() also frees our data */ |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2503 | } |
| 2504 | |
Hans de Goede | c13548c | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2505 | static int f71882fg_remove(struct platform_device *pdev) |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2506 | { |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2507 | struct f71882fg_data *data = platform_get_drvdata(pdev); |
Jean Delvare | f27def0 | 2011-03-26 10:45:01 +0100 | [diff] [blame] | 2508 | int nr_fans = f71882fg_nr_fans[data->type]; |
| 2509 | int nr_temps = f71882fg_nr_temps[data->type]; |
| 2510 | int i; |
Hans de Goede | fc16c56 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 2511 | u8 start_reg = f71882fg_read8(data, F71882FG_REG_START); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2512 | |
Hans de Goede | c13548c | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2513 | if (data->hwmon_dev) |
| 2514 | hwmon_device_unregister(data->hwmon_dev); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2515 | |
Hans de Goede | c13548c | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2516 | device_remove_file(&pdev->dev, &dev_attr_name); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2517 | |
Hans de Goede | fc16c56 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 2518 | if (start_reg & 0x01) { |
| 2519 | switch (data->type) { |
| 2520 | case f71858fg: |
| 2521 | if (data->temp_config & 0x10) |
| 2522 | f71882fg_remove_sysfs_files(pdev, |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 2523 | f8000_temp_attr, |
| 2524 | ARRAY_SIZE(f8000_temp_attr)); |
Hans de Goede | fc16c56 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 2525 | else |
| 2526 | f71882fg_remove_sysfs_files(pdev, |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 2527 | f71858fg_temp_attr, |
| 2528 | ARRAY_SIZE(f71858fg_temp_attr)); |
Hans de Goede | fc16c56 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 2529 | break; |
| 2530 | case f8000: |
| 2531 | f71882fg_remove_sysfs_files(pdev, |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 2532 | f8000_temp_attr, |
| 2533 | ARRAY_SIZE(f8000_temp_attr)); |
Hans de Goede | fc16c56 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 2534 | break; |
Peter Hung | dcd956f | 2015-07-07 16:22:37 +0800 | [diff] [blame] | 2535 | case f81866a: |
| 2536 | f71882fg_remove_sysfs_files(pdev, |
| 2537 | f71858fg_temp_attr, |
| 2538 | ARRAY_SIZE(f71858fg_temp_attr)); |
| 2539 | break; |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 2540 | default: |
| 2541 | f71882fg_remove_sysfs_files(pdev, |
Hans de Goede | 60d2b37 | 2011-03-09 20:57:11 +0100 | [diff] [blame] | 2542 | &fxxxx_temp_attr[0][0], |
| 2543 | ARRAY_SIZE(fxxxx_temp_attr[0]) * nr_temps); |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 2544 | } |
Hans de Goede | 4d53811 | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 2545 | if (f71882fg_temp_has_beep[data->type]) { |
Peter Hung | dcd956f | 2015-07-07 16:22:37 +0800 | [diff] [blame] | 2546 | if (data->type == f81866a) |
| 2547 | f71882fg_remove_sysfs_files(pdev, |
| 2548 | &f81866_temp_beep_attr[0][0], |
| 2549 | ARRAY_SIZE(f81866_temp_beep_attr[0]) |
| 2550 | * nr_temps); |
| 2551 | else |
| 2552 | f71882fg_remove_sysfs_files(pdev, |
| 2553 | &fxxxx_temp_beep_attr[0][0], |
| 2554 | ARRAY_SIZE(fxxxx_temp_beep_attr[0]) |
| 2555 | * nr_temps); |
Hans de Goede | 78aa4f7 | 2011-03-09 20:57:12 +0100 | [diff] [blame] | 2556 | } |
| 2557 | |
Hans de Goede | 0bae640 | 2011-03-09 20:57:10 +0100 | [diff] [blame] | 2558 | for (i = 0; i < F71882FG_MAX_INS; i++) { |
| 2559 | if (f71882fg_has_in[data->type][i]) { |
| 2560 | device_remove_file(&pdev->dev, |
| 2561 | &fxxxx_in_attr[i].dev_attr); |
| 2562 | } |
| 2563 | } |
| 2564 | if (f71882fg_has_in1_alarm[data->type]) { |
| 2565 | f71882fg_remove_sysfs_files(pdev, |
| 2566 | fxxxx_in1_alarm_attr, |
| 2567 | ARRAY_SIZE(fxxxx_in1_alarm_attr)); |
Hans de Goede | fc16c56 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 2568 | } |
| 2569 | } |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2570 | |
Hans de Goede | fc16c56 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 2571 | if (start_reg & 0x02) { |
| 2572 | f71882fg_remove_sysfs_files(pdev, &fxxxx_fan_attr[0][0], |
| 2573 | ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2574 | |
Hans de Goede | 4d53811 | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 2575 | if (f71882fg_fan_has_beep[data->type]) { |
Hans de Goede | fc16c56 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 2576 | f71882fg_remove_sysfs_files(pdev, |
| 2577 | fxxxx_fan_beep_attr, nr_fans); |
Hans de Goede | 78aa4f7 | 2011-03-09 20:57:12 +0100 | [diff] [blame] | 2578 | } |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2579 | |
Hans de Goede | fc16c56 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 2580 | switch (data->type) { |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 2581 | case f71808a: |
| 2582 | f71882fg_remove_sysfs_files(pdev, |
| 2583 | &fxxxx_auto_pwm_attr[0][0], |
| 2584 | ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans); |
| 2585 | f71882fg_remove_sysfs_files(pdev, |
| 2586 | f71808a_fan3_attr, |
| 2587 | ARRAY_SIZE(f71808a_fan3_attr)); |
| 2588 | break; |
Hans de Goede | fc16c56 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 2589 | case f71862fg: |
| 2590 | f71882fg_remove_sysfs_files(pdev, |
Hans de Goede | 5584014 | 2011-09-09 12:12:33 +0200 | [diff] [blame] | 2591 | &f71862fg_auto_pwm_attr[0][0], |
| 2592 | ARRAY_SIZE(f71862fg_auto_pwm_attr[0]) * |
| 2593 | nr_fans); |
Hans de Goede | fc16c56 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 2594 | break; |
Hans de Goede | e5e713c | 2011-03-10 08:54:02 +0100 | [diff] [blame] | 2595 | case f71808e: |
Hans de Goede | c11bb99 | 2011-03-09 20:57:15 +0100 | [diff] [blame] | 2596 | case f71869: |
| 2597 | f71882fg_remove_sysfs_files(pdev, |
Hans de Goede | 5584014 | 2011-09-09 12:12:33 +0200 | [diff] [blame] | 2598 | &f71869_auto_pwm_attr[0][0], |
| 2599 | ARRAY_SIZE(f71869_auto_pwm_attr[0]) * nr_fans); |
Hans de Goede | c11bb99 | 2011-03-09 20:57:15 +0100 | [diff] [blame] | 2600 | break; |
Hans de Goede | fc16c56 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 2601 | case f8000: |
| 2602 | f71882fg_remove_sysfs_files(pdev, |
| 2603 | f8000_fan_attr, |
| 2604 | ARRAY_SIZE(f8000_fan_attr)); |
| 2605 | f71882fg_remove_sysfs_files(pdev, |
Hans de Goede | 5584014 | 2011-09-09 12:12:33 +0200 | [diff] [blame] | 2606 | &f8000_auto_pwm_attr[0][0], |
| 2607 | ARRAY_SIZE(f8000_auto_pwm_attr[0]) * nr_fans); |
Hans de Goede | fc16c56 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 2608 | break; |
Hans de Goede | 3cad402 | 2011-03-09 20:57:14 +0100 | [diff] [blame] | 2609 | default: |
Hans de Goede | fc16c56 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 2610 | f71882fg_remove_sysfs_files(pdev, |
| 2611 | &fxxxx_auto_pwm_attr[0][0], |
| 2612 | ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans); |
| 2613 | } |
| 2614 | } |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2615 | return 0; |
| 2616 | } |
| 2617 | |
Guenter Roeck | 0038389 | 2012-08-04 09:46:36 -0700 | [diff] [blame] | 2618 | static int __init f71882fg_find(int sioaddr, struct f71882fg_sio_data *sio_data) |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2619 | { |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2620 | u16 devid; |
Guenter Roeck | 0038389 | 2012-08-04 09:46:36 -0700 | [diff] [blame] | 2621 | unsigned short address; |
Giel van Schijndel | cadb865 | 2010-10-03 08:09:49 -0400 | [diff] [blame] | 2622 | int err = superio_enter(sioaddr); |
| 2623 | if (err) |
| 2624 | return err; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2625 | |
| 2626 | devid = superio_inw(sioaddr, SIO_REG_MANID); |
| 2627 | if (devid != SIO_FINTEK_ID) { |
Joe Perches | 22d3b41 | 2010-10-20 06:51:34 +0000 | [diff] [blame] | 2628 | pr_debug("Not a Fintek device\n"); |
Giel van Schijndel | cadb865 | 2010-10-03 08:09:49 -0400 | [diff] [blame] | 2629 | err = -ENODEV; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2630 | goto exit; |
| 2631 | } |
| 2632 | |
Jean Delvare | 67b671b | 2007-12-06 23:13:42 +0100 | [diff] [blame] | 2633 | devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID); |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2634 | switch (devid) { |
Hans de Goede | e5e713c | 2011-03-10 08:54:02 +0100 | [diff] [blame] | 2635 | case SIO_F71808E_ID: |
| 2636 | sio_data->type = f71808e; |
| 2637 | break; |
Hans de Goede | 629c58b | 2011-05-25 20:43:32 +0200 | [diff] [blame] | 2638 | case SIO_F71808A_ID: |
| 2639 | sio_data->type = f71808a; |
| 2640 | break; |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 2641 | case SIO_F71858_ID: |
| 2642 | sio_data->type = f71858fg; |
| 2643 | break; |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2644 | case SIO_F71862_ID: |
| 2645 | sio_data->type = f71862fg; |
| 2646 | break; |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 2647 | case SIO_F71868_ID: |
| 2648 | sio_data->type = f71868a; |
| 2649 | break; |
Hans de Goede | c11bb99 | 2011-03-09 20:57:15 +0100 | [diff] [blame] | 2650 | case SIO_F71869_ID: |
| 2651 | sio_data->type = f71869; |
| 2652 | break; |
Hans de Goede | 5da556e | 2011-07-03 13:32:53 +0200 | [diff] [blame] | 2653 | case SIO_F71869A_ID: |
| 2654 | sio_data->type = f71869a; |
| 2655 | break; |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2656 | case SIO_F71882_ID: |
| 2657 | sio_data->type = f71882fg; |
| 2658 | break; |
Hans de Goede | 7669896 | 2009-12-09 20:36:01 +0100 | [diff] [blame] | 2659 | case SIO_F71889_ID: |
| 2660 | sio_data->type = f71889fg; |
| 2661 | break; |
Hans de Goede | 3cad402 | 2011-03-09 20:57:14 +0100 | [diff] [blame] | 2662 | case SIO_F71889E_ID: |
| 2663 | sio_data->type = f71889ed; |
| 2664 | break; |
Hans de Goede | a66c108 | 2011-03-26 10:45:02 +0100 | [diff] [blame] | 2665 | case SIO_F71889A_ID: |
| 2666 | sio_data->type = f71889a; |
| 2667 | break; |
Hans de Goede | ed4f7c2 | 2009-01-07 16:37:30 +0100 | [diff] [blame] | 2668 | case SIO_F8000_ID: |
| 2669 | sio_data->type = f8000; |
| 2670 | break; |
Jean Delvare | 383586b | 2011-03-26 10:45:02 +0100 | [diff] [blame] | 2671 | case SIO_F81865_ID: |
| 2672 | sio_data->type = f81865f; |
| 2673 | break; |
Peter Hung | 2725fe2 | 2015-07-07 16:22:36 +0800 | [diff] [blame] | 2674 | case SIO_F81866_ID: |
| 2675 | sio_data->type = f81866a; |
| 2676 | break; |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2677 | default: |
Joe Perches | 22d3b41 | 2010-10-20 06:51:34 +0000 | [diff] [blame] | 2678 | pr_info("Unsupported Fintek device: %04x\n", |
| 2679 | (unsigned int)devid); |
Giel van Schijndel | cadb865 | 2010-10-03 08:09:49 -0400 | [diff] [blame] | 2680 | err = -ENODEV; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2681 | goto exit; |
| 2682 | } |
| 2683 | |
Hans de Goede | 09475d3 | 2009-06-15 18:39:52 +0200 | [diff] [blame] | 2684 | if (sio_data->type == f71858fg) |
| 2685 | superio_select(sioaddr, SIO_F71858FG_LD_HWM); |
| 2686 | else |
| 2687 | superio_select(sioaddr, SIO_F71882FG_LD_HWM); |
| 2688 | |
Mark M. Hoffman | 8afb104 | 2007-08-21 23:10:46 -0400 | [diff] [blame] | 2689 | if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) { |
Joe Perches | 22d3b41 | 2010-10-20 06:51:34 +0000 | [diff] [blame] | 2690 | pr_warn("Device not activated\n"); |
Giel van Schijndel | cadb865 | 2010-10-03 08:09:49 -0400 | [diff] [blame] | 2691 | err = -ENODEV; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2692 | goto exit; |
| 2693 | } |
| 2694 | |
Guenter Roeck | 0038389 | 2012-08-04 09:46:36 -0700 | [diff] [blame] | 2695 | address = superio_inw(sioaddr, SIO_REG_ADDR); |
| 2696 | if (address == 0) { |
Joe Perches | 22d3b41 | 2010-10-20 06:51:34 +0000 | [diff] [blame] | 2697 | pr_warn("Base address not set\n"); |
Giel van Schijndel | cadb865 | 2010-10-03 08:09:49 -0400 | [diff] [blame] | 2698 | err = -ENODEV; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2699 | goto exit; |
| 2700 | } |
Guenter Roeck | 0038389 | 2012-08-04 09:46:36 -0700 | [diff] [blame] | 2701 | address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */ |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2702 | |
Guenter Roeck | 0038389 | 2012-08-04 09:46:36 -0700 | [diff] [blame] | 2703 | err = address; |
Joe Perches | 22d3b41 | 2010-10-20 06:51:34 +0000 | [diff] [blame] | 2704 | pr_info("Found %s chip at %#x, revision %d\n", |
Guenter Roeck | 0038389 | 2012-08-04 09:46:36 -0700 | [diff] [blame] | 2705 | f71882fg_names[sio_data->type], (unsigned int)address, |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2706 | (int)superio_inb(sioaddr, SIO_REG_DEVREV)); |
| 2707 | exit: |
| 2708 | superio_exit(sioaddr); |
| 2709 | return err; |
| 2710 | } |
| 2711 | |
Guenter Roeck | 0038389 | 2012-08-04 09:46:36 -0700 | [diff] [blame] | 2712 | static int __init f71882fg_device_add(int address, |
| 2713 | const struct f71882fg_sio_data *sio_data) |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2714 | { |
| 2715 | struct resource res = { |
| 2716 | .start = address, |
| 2717 | .end = address + REGION_LENGTH - 1, |
| 2718 | .flags = IORESOURCE_IO, |
| 2719 | }; |
| 2720 | int err; |
| 2721 | |
| 2722 | f71882fg_pdev = platform_device_alloc(DRVNAME, address); |
Mark M. Hoffman | 8afb104 | 2007-08-21 23:10:46 -0400 | [diff] [blame] | 2723 | if (!f71882fg_pdev) |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2724 | return -ENOMEM; |
| 2725 | |
| 2726 | res.name = f71882fg_pdev->name; |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 2727 | err = acpi_check_resource_conflict(&res); |
| 2728 | if (err) |
Hans de Goede | 18632f8 | 2009-02-17 19:59:54 +0100 | [diff] [blame] | 2729 | goto exit_device_put; |
Jean Delvare | b9acb64 | 2009-01-07 16:37:35 +0100 | [diff] [blame] | 2730 | |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2731 | err = platform_device_add_resources(f71882fg_pdev, &res, 1); |
Mark M. Hoffman | 8afb104 | 2007-08-21 23:10:46 -0400 | [diff] [blame] | 2732 | if (err) { |
Joe Perches | 22d3b41 | 2010-10-20 06:51:34 +0000 | [diff] [blame] | 2733 | pr_err("Device resource addition failed\n"); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2734 | goto exit_device_put; |
| 2735 | } |
| 2736 | |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2737 | err = platform_device_add_data(f71882fg_pdev, sio_data, |
| 2738 | sizeof(struct f71882fg_sio_data)); |
| 2739 | if (err) { |
Joe Perches | 22d3b41 | 2010-10-20 06:51:34 +0000 | [diff] [blame] | 2740 | pr_err("Platform data allocation failed\n"); |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2741 | goto exit_device_put; |
| 2742 | } |
| 2743 | |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2744 | err = platform_device_add(f71882fg_pdev); |
Mark M. Hoffman | 8afb104 | 2007-08-21 23:10:46 -0400 | [diff] [blame] | 2745 | if (err) { |
Joe Perches | 22d3b41 | 2010-10-20 06:51:34 +0000 | [diff] [blame] | 2746 | pr_err("Device addition failed\n"); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2747 | goto exit_device_put; |
| 2748 | } |
| 2749 | |
| 2750 | return 0; |
| 2751 | |
| 2752 | exit_device_put: |
| 2753 | platform_device_put(f71882fg_pdev); |
| 2754 | |
| 2755 | return err; |
| 2756 | } |
| 2757 | |
| 2758 | static int __init f71882fg_init(void) |
| 2759 | { |
Guenter Roeck | 0038389 | 2012-08-04 09:46:36 -0700 | [diff] [blame] | 2760 | int err; |
| 2761 | int address; |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2762 | struct f71882fg_sio_data sio_data; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2763 | |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2764 | memset(&sio_data, 0, sizeof(sio_data)); |
| 2765 | |
Guenter Roeck | 0038389 | 2012-08-04 09:46:36 -0700 | [diff] [blame] | 2766 | address = f71882fg_find(0x2e, &sio_data); |
| 2767 | if (address < 0) |
| 2768 | address = f71882fg_find(0x4e, &sio_data); |
| 2769 | if (address < 0) |
| 2770 | return address; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2771 | |
Hans de Goede | c13548c | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2772 | err = platform_driver_register(&f71882fg_driver); |
| 2773 | if (err) |
Guenter Roeck | 0038389 | 2012-08-04 09:46:36 -0700 | [diff] [blame] | 2774 | return err; |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2775 | |
Hans de Goede | 498be96 | 2009-01-07 16:37:28 +0100 | [diff] [blame] | 2776 | err = f71882fg_device_add(address, &sio_data); |
Hans de Goede | c13548c | 2009-01-07 16:37:27 +0100 | [diff] [blame] | 2777 | if (err) |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2778 | goto exit_driver; |
| 2779 | |
| 2780 | return 0; |
| 2781 | |
| 2782 | exit_driver: |
| 2783 | platform_driver_unregister(&f71882fg_driver); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2784 | return err; |
| 2785 | } |
| 2786 | |
| 2787 | static void __exit f71882fg_exit(void) |
| 2788 | { |
| 2789 | platform_device_unregister(f71882fg_pdev); |
| 2790 | platform_driver_unregister(&f71882fg_driver); |
| 2791 | } |
| 2792 | |
| 2793 | MODULE_DESCRIPTION("F71882FG Hardware Monitoring Driver"); |
Hans de Goede | 7958e3b | 2011-07-03 13:32:53 +0200 | [diff] [blame] | 2794 | MODULE_AUTHOR("Hans Edgington, Hans de Goede <hdegoede@redhat.com>"); |
Hans de Goede | 45fb366 | 2007-07-13 14:34:19 +0200 | [diff] [blame] | 2795 | MODULE_LICENSE("GPL"); |
| 2796 | |
| 2797 | module_init(f71882fg_init); |
| 2798 | module_exit(f71882fg_exit); |