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