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