blob: e4ff21f8270c66eeb0e48239d90055616dec8a30 [file] [log] [blame]
Hans de Goede45fb3662007-07-13 14:34:19 +02001/***************************************************************************
2 * Copyright (C) 2006 by Hans Edgington <hans@edgington.nl> *
Hans de Goede44c4dc52011-03-09 20:57:07 +01003 * Copyright (C) 2007-2011 Hans de Goede <hdegoede@redhat.com> *
Hans de Goede45fb3662007-07-13 14:34:19 +02004 * *
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 Perches22d3b412010-10-20 06:51:34 +000021#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
22
Hans de Goede45fb3662007-07-13 14:34:19 +020023#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 Doesburg77a4a3e2009-01-07 16:37:27 +010032#include <linux/io.h>
Jean Delvareb9acb642009-01-07 16:37:35 +010033#include <linux/acpi.h>
Hans de Goede45fb3662007-07-13 14:34:19 +020034
35#define DRVNAME "f71882fg"
36
Hans de Goede09475d32009-06-15 18:39:52 +020037#define SIO_F71858FG_LD_HWM 0x02 /* Hardware monitor logical device */
Mark van Doesburg77a4a3e2009-01-07 16:37:27 +010038#define SIO_F71882FG_LD_HWM 0x04 /* Hardware monitor logical device */
Hans de Goede45fb3662007-07-13 14:34:19 +020039#define SIO_UNLOCK_KEY 0x87 /* Key to enable Super-I/O */
Hans de Goede14a40192011-03-13 13:50:32 +010040#define SIO_LOCK_KEY 0xAA /* Key to disable Super-I/O */
Hans de Goede45fb3662007-07-13 14:34:19 +020041
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 Goedee5e713c2011-03-10 08:54:02 +010050#define SIO_F71808E_ID 0x0901 /* Chipset ID */
Hans de Goede629c58b2011-05-25 20:43:32 +020051#define SIO_F71808A_ID 0x1001 /* Chipset ID */
Hans de Goede09475d32009-06-15 18:39:52 +020052#define SIO_F71858_ID 0x0507 /* Chipset ID */
Hans de Goede498be962009-01-07 16:37:28 +010053#define SIO_F71862_ID 0x0601 /* Chipset ID */
Peter Hung2725fe22015-07-07 16:22:36 +080054#define SIO_F71868_ID 0x1106 /* Chipset ID */
Hans de Goedec11bb992011-03-09 20:57:15 +010055#define SIO_F71869_ID 0x0814 /* Chipset ID */
Hans de Goede5da556e2011-07-03 13:32:53 +020056#define SIO_F71869A_ID 0x1007 /* Chipset ID */
Hans de Goede45fb3662007-07-13 14:34:19 +020057#define SIO_F71882_ID 0x0541 /* Chipset ID */
Hans de Goede76698962009-12-09 20:36:01 +010058#define SIO_F71889_ID 0x0723 /* Chipset ID */
Hans de Goede3cad4022011-03-09 20:57:14 +010059#define SIO_F71889E_ID 0x0909 /* Chipset ID */
Hans de Goedea66c1082011-03-26 10:45:02 +010060#define SIO_F71889A_ID 0x1005 /* Chipset ID */
Hans de Goedeed4f7c22009-01-07 16:37:30 +010061#define SIO_F8000_ID 0x0581 /* Chipset ID */
Jean Delvare383586b2011-03-26 10:45:02 +010062#define SIO_F81865_ID 0x0704 /* Chipset ID */
Peter Hung2725fe22015-07-07 16:22:36 +080063#define SIO_F81866_ID 0x1010 /* Chipset ID */
Hans de Goede45fb3662007-07-13 14:34:19 +020064
65#define REGION_LENGTH 8
66#define ADDR_REG_OFFSET 5
67#define DATA_REG_OFFSET 6
68
Hans de Goede3cad4022011-03-09 20:57:14 +010069#define F71882FG_REG_IN_STATUS 0x12 /* f7188x only */
70#define F71882FG_REG_IN_BEEP 0x13 /* f7188x only */
Hans de Goede45fb3662007-07-13 14:34:19 +020071#define F71882FG_REG_IN(nr) (0x20 + (nr))
Hans de Goede3cad4022011-03-09 20:57:14 +010072#define F71882FG_REG_IN1_HIGH 0x32 /* f7188x only */
Hans de Goede45fb3662007-07-13 14:34:19 +020073
Peter Hung3e40b862015-07-07 16:22:38 +080074#define F81866_REG_IN_STATUS 0x16 /* F81866 only */
75#define F81866_REG_IN_BEEP 0x17 /* F81866 only */
76#define F81866_REG_IN1_HIGH 0x3a /* F81866 only */
77
Hans de Goede45fb3662007-07-13 14:34:19 +020078#define F71882FG_REG_FAN(nr) (0xA0 + (16 * (nr)))
Mark van Doesburg9ab796e2009-01-07 16:37:27 +010079#define F71882FG_REG_FAN_TARGET(nr) (0xA2 + (16 * (nr)))
80#define F71882FG_REG_FAN_FULL_SPEED(nr) (0xA4 + (16 * (nr)))
Hans de Goede45fb3662007-07-13 14:34:19 +020081#define F71882FG_REG_FAN_STATUS 0x92
82#define F71882FG_REG_FAN_BEEP 0x93
83
Hans de Goede7567a042009-01-07 16:37:28 +010084#define F71882FG_REG_TEMP(nr) (0x70 + 2 * (nr))
85#define F71882FG_REG_TEMP_OVT(nr) (0x80 + 2 * (nr))
86#define F71882FG_REG_TEMP_HIGH(nr) (0x81 + 2 * (nr))
Hans de Goede45fb3662007-07-13 14:34:19 +020087#define F71882FG_REG_TEMP_STATUS 0x62
88#define F71882FG_REG_TEMP_BEEP 0x63
Hans de Goede09475d32009-06-15 18:39:52 +020089#define F71882FG_REG_TEMP_CONFIG 0x69
Hans de Goedebc274902009-01-07 16:37:29 +010090#define F71882FG_REG_TEMP_HYST(nr) (0x6C + (nr))
Hans de Goede45fb3662007-07-13 14:34:19 +020091#define F71882FG_REG_TEMP_TYPE 0x6B
92#define F71882FG_REG_TEMP_DIODE_OPEN 0x6F
93
Mark van Doesburg9ab796e2009-01-07 16:37:27 +010094#define F71882FG_REG_PWM(nr) (0xA3 + (16 * (nr)))
95#define F71882FG_REG_PWM_TYPE 0x94
96#define F71882FG_REG_PWM_ENABLE 0x96
97
Hans de Goedebc274902009-01-07 16:37:29 +010098#define F71882FG_REG_FAN_HYST(nr) (0x98 + (nr))
Mark van Doesburg9ab796e2009-01-07 16:37:27 +010099
Hans de Goede98f7ba12011-03-09 20:57:09 +0100100#define F71882FG_REG_FAN_FAULT_T 0x9F
101#define F71882FG_FAN_NEG_TEMP_EN 0x20
Hans de Goede3cad4022011-03-09 20:57:14 +0100102#define F71882FG_FAN_PROG_SEL 0x80
Hans de Goede98f7ba12011-03-09 20:57:09 +0100103
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100104#define F71882FG_REG_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm)))
105#define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm)))
106#define F71882FG_REG_POINT_MAPPING(nr) (0xAF + 16 * (nr))
107
Hans de Goede45fb3662007-07-13 14:34:19 +0200108#define F71882FG_REG_START 0x01
109
Peter Hung2725fe22015-07-07 16:22:36 +0800110#define F71882FG_MAX_INS 10
Hans de Goede0bae6402011-03-09 20:57:10 +0100111
Hans de Goede45fb3662007-07-13 14:34:19 +0200112#define FAN_MIN_DETECT 366 /* Lowest detectable fanspeed */
113
Jean Delvare67b671b2007-12-06 23:13:42 +0100114static unsigned short force_id;
115module_param(force_id, ushort, 0);
116MODULE_PARM_DESC(force_id, "Override the detected device ID");
117
Peter Hung2725fe22015-07-07 16:22:36 +0800118enum chips { f71808e, f71808a, f71858fg, f71862fg, f71868a, f71869, f71869a,
119 f71882fg, f71889fg, f71889ed, f71889a, f8000, f81865f, f81866a};
Hans de Goede498be962009-01-07 16:37:28 +0100120
Frans Meulenbroeks1dc37082012-01-08 19:34:10 +0100121static const char *const f71882fg_names[] = {
Hans de Goedee5e713c2011-03-10 08:54:02 +0100122 "f71808e",
Hans de Goede629c58b2011-05-25 20:43:32 +0200123 "f71808a",
Hans de Goede09475d32009-06-15 18:39:52 +0200124 "f71858fg",
Hans de Goede498be962009-01-07 16:37:28 +0100125 "f71862fg",
Peter Hung2725fe22015-07-07 16:22:36 +0800126 "f71868a",
Hans de Goedec11bb992011-03-09 20:57:15 +0100127 "f71869", /* Both f71869f and f71869e, reg. compatible and same id */
Hans de Goede5da556e2011-07-03 13:32:53 +0200128 "f71869a",
Hans de Goede498be962009-01-07 16:37:28 +0100129 "f71882fg",
Jean Delvare5d7f77b2011-03-26 10:45:02 +0100130 "f71889fg", /* f81801u too, same id */
Hans de Goede3cad4022011-03-09 20:57:14 +0100131 "f71889ed",
Hans de Goedea66c1082011-03-26 10:45:02 +0100132 "f71889a",
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100133 "f8000",
Jean Delvare383586b2011-03-26 10:45:02 +0100134 "f81865f",
Peter Hung2725fe22015-07-07 16:22:36 +0800135 "f81866a",
Hans de Goede498be962009-01-07 16:37:28 +0100136};
137
Jean Delvare2740c602011-03-26 10:45:01 +0100138static const char f71882fg_has_in[][F71882FG_MAX_INS] = {
Peter Hung2725fe22015-07-07 16:22:36 +0800139 [f71808e] = { 1, 1, 1, 1, 1, 1, 0, 1, 1, 0 },
140 [f71808a] = { 1, 1, 1, 1, 0, 0, 0, 1, 1, 0 },
141 [f71858fg] = { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
142 [f71862fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
143 [f71868a] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
144 [f71869] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
145 [f71869a] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
146 [f71882fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
147 [f71889fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
148 [f71889ed] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
149 [f71889a] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
150 [f8000] = { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 },
151 [f81865f] = { 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 },
152 [f81866a] = { 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
Hans de Goede0bae6402011-03-09 20:57:10 +0100153};
154
Jean Delvare2740c602011-03-26 10:45:01 +0100155static const char f71882fg_has_in1_alarm[] = {
156 [f71808e] = 0,
Hans de Goede629c58b2011-05-25 20:43:32 +0200157 [f71808a] = 0,
Jean Delvare2740c602011-03-26 10:45:01 +0100158 [f71858fg] = 0,
159 [f71862fg] = 0,
Peter Hung2725fe22015-07-07 16:22:36 +0800160 [f71868a] = 0,
Jean Delvare2740c602011-03-26 10:45:01 +0100161 [f71869] = 0,
Hans de Goede5da556e2011-07-03 13:32:53 +0200162 [f71869a] = 0,
Jean Delvare2740c602011-03-26 10:45:01 +0100163 [f71882fg] = 1,
164 [f71889fg] = 1,
165 [f71889ed] = 1,
Hans de Goedea66c1082011-03-26 10:45:02 +0100166 [f71889a] = 1,
Jean Delvare2740c602011-03-26 10:45:01 +0100167 [f8000] = 0,
Jean Delvare383586b2011-03-26 10:45:02 +0100168 [f81865f] = 1,
Peter Hung2725fe22015-07-07 16:22:36 +0800169 [f81866a] = 1,
Hans de Goede0bae6402011-03-09 20:57:10 +0100170};
171
Hans de Goede4d538112011-05-25 20:43:32 +0200172static const char f71882fg_fan_has_beep[] = {
Jean Delvare2740c602011-03-26 10:45:01 +0100173 [f71808e] = 0,
Hans de Goede629c58b2011-05-25 20:43:32 +0200174 [f71808a] = 0,
Jean Delvare2740c602011-03-26 10:45:01 +0100175 [f71858fg] = 0,
176 [f71862fg] = 1,
Peter Hung2725fe22015-07-07 16:22:36 +0800177 [f71868a] = 1,
Jean Delvare2740c602011-03-26 10:45:01 +0100178 [f71869] = 1,
Hans de Goede5da556e2011-07-03 13:32:53 +0200179 [f71869a] = 1,
Jean Delvare2740c602011-03-26 10:45:01 +0100180 [f71882fg] = 1,
181 [f71889fg] = 1,
182 [f71889ed] = 1,
Hans de Goedea66c1082011-03-26 10:45:02 +0100183 [f71889a] = 1,
Jean Delvare2740c602011-03-26 10:45:01 +0100184 [f8000] = 0,
Jean Delvare383586b2011-03-26 10:45:02 +0100185 [f81865f] = 1,
Peter Hung2725fe22015-07-07 16:22:36 +0800186 [f81866a] = 1,
Hans de Goede78aa4f72011-03-09 20:57:12 +0100187};
188
Jean Delvaref27def02011-03-26 10:45:01 +0100189static const char f71882fg_nr_fans[] = {
190 [f71808e] = 3,
Hans de Goede629c58b2011-05-25 20:43:32 +0200191 [f71808a] = 2, /* +1 fan which is monitor + simple pwm only */
Jean Delvaref27def02011-03-26 10:45:01 +0100192 [f71858fg] = 3,
193 [f71862fg] = 3,
Peter Hung2725fe22015-07-07 16:22:36 +0800194 [f71868a] = 3,
Jean Delvaref27def02011-03-26 10:45:01 +0100195 [f71869] = 3,
Hans de Goede5da556e2011-07-03 13:32:53 +0200196 [f71869a] = 3,
Jean Delvaref27def02011-03-26 10:45:01 +0100197 [f71882fg] = 4,
198 [f71889fg] = 3,
199 [f71889ed] = 3,
Hans de Goedea66c1082011-03-26 10:45:02 +0100200 [f71889a] = 3,
Hans de Goede629c58b2011-05-25 20:43:32 +0200201 [f8000] = 3, /* +1 fan which is monitor only */
Jean Delvare383586b2011-03-26 10:45:02 +0100202 [f81865f] = 2,
Peter Hung2725fe22015-07-07 16:22:36 +0800203 [f81866a] = 3,
Jean Delvaref27def02011-03-26 10:45:01 +0100204};
205
Hans de Goede4d538112011-05-25 20:43:32 +0200206static const char f71882fg_temp_has_beep[] = {
207 [f71808e] = 0,
Hans de Goede629c58b2011-05-25 20:43:32 +0200208 [f71808a] = 1,
Hans de Goede4d538112011-05-25 20:43:32 +0200209 [f71858fg] = 0,
210 [f71862fg] = 1,
Peter Hung2725fe22015-07-07 16:22:36 +0800211 [f71868a] = 1,
Hans de Goede4d538112011-05-25 20:43:32 +0200212 [f71869] = 1,
Hans de Goede5da556e2011-07-03 13:32:53 +0200213 [f71869a] = 1,
Hans de Goede4d538112011-05-25 20:43:32 +0200214 [f71882fg] = 1,
215 [f71889fg] = 1,
216 [f71889ed] = 1,
217 [f71889a] = 1,
218 [f8000] = 0,
219 [f81865f] = 1,
Peter Hung2725fe22015-07-07 16:22:36 +0800220 [f81866a] = 1,
Hans de Goede4d538112011-05-25 20:43:32 +0200221};
222
Jean Delvaref27def02011-03-26 10:45:01 +0100223static const char f71882fg_nr_temps[] = {
224 [f71808e] = 2,
Hans de Goede629c58b2011-05-25 20:43:32 +0200225 [f71808a] = 2,
Jean Delvaref27def02011-03-26 10:45:01 +0100226 [f71858fg] = 3,
227 [f71862fg] = 3,
Peter Hung2725fe22015-07-07 16:22:36 +0800228 [f71868a] = 3,
Jean Delvaref27def02011-03-26 10:45:01 +0100229 [f71869] = 3,
Hans de Goede5da556e2011-07-03 13:32:53 +0200230 [f71869a] = 3,
Jean Delvaref27def02011-03-26 10:45:01 +0100231 [f71882fg] = 3,
232 [f71889fg] = 3,
233 [f71889ed] = 3,
Hans de Goedea66c1082011-03-26 10:45:02 +0100234 [f71889a] = 3,
Jean Delvaref27def02011-03-26 10:45:01 +0100235 [f8000] = 3,
Jean Delvare383586b2011-03-26 10:45:02 +0100236 [f81865f] = 2,
Peter Hung2725fe22015-07-07 16:22:36 +0800237 [f81866a] = 3,
Jean Delvaref27def02011-03-26 10:45:01 +0100238};
239
Mark van Doesburg77a4a3e2009-01-07 16:37:27 +0100240static struct platform_device *f71882fg_pdev;
Hans de Goede45fb3662007-07-13 14:34:19 +0200241
242/* Super-I/O Function prototypes */
243static inline int superio_inb(int base, int reg);
244static inline int superio_inw(int base, int reg);
Giel van Schijndelcadb8652010-10-03 08:09:49 -0400245static inline int superio_enter(int base);
Hans de Goede45fb3662007-07-13 14:34:19 +0200246static inline void superio_select(int base, int ld);
247static inline void superio_exit(int base);
248
Hans de Goede498be962009-01-07 16:37:28 +0100249struct f71882fg_sio_data {
250 enum chips type;
251};
252
Hans de Goede45fb3662007-07-13 14:34:19 +0200253struct f71882fg_data {
254 unsigned short addr;
Hans de Goede498be962009-01-07 16:37:28 +0100255 enum chips type;
Tony Jones1beeffe2007-08-20 13:46:20 -0700256 struct device *hwmon_dev;
Hans de Goede45fb3662007-07-13 14:34:19 +0200257
258 struct mutex update_lock;
Hans de Goede09475d32009-06-15 18:39:52 +0200259 int temp_start; /* temp numbering start (0 or 1) */
Hans de Goede45fb3662007-07-13 14:34:19 +0200260 char valid; /* !=0 if following fields are valid */
Hans de Goede98f7ba12011-03-09 20:57:09 +0100261 char auto_point_temp_signed;
Hans de Goede45fb3662007-07-13 14:34:19 +0200262 unsigned long last_updated; /* In jiffies */
263 unsigned long last_limits; /* In jiffies */
264
265 /* Register Values */
Hans de Goede0bae6402011-03-09 20:57:10 +0100266 u8 in[F71882FG_MAX_INS];
Hans de Goede45fb3662007-07-13 14:34:19 +0200267 u8 in1_max;
268 u8 in_status;
269 u8 in_beep;
270 u16 fan[4];
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100271 u16 fan_target[4];
272 u16 fan_full_speed[4];
Hans de Goede45fb3662007-07-13 14:34:19 +0200273 u8 fan_status;
274 u8 fan_beep;
Guenter Roeck20eaf722012-01-19 11:02:17 -0800275 /*
276 * Note: all models have max 3 temperature channels, but on some
277 * they are addressed as 0-2 and on others as 1-3, so for coding
278 * convenience we reserve space for 4 channels
279 */
Hans de Goede09475d32009-06-15 18:39:52 +0200280 u16 temp[4];
Hans de Goede7567a042009-01-07 16:37:28 +0100281 u8 temp_ovt[4];
282 u8 temp_high[4];
Hans de Goedebc274902009-01-07 16:37:29 +0100283 u8 temp_hyst[2]; /* 2 hysts stored per reg */
Hans de Goede7567a042009-01-07 16:37:28 +0100284 u8 temp_type[4];
Hans de Goede45fb3662007-07-13 14:34:19 +0200285 u8 temp_status;
286 u8 temp_beep;
287 u8 temp_diode_open;
Hans de Goede09475d32009-06-15 18:39:52 +0200288 u8 temp_config;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100289 u8 pwm[4];
290 u8 pwm_enable;
291 u8 pwm_auto_point_hyst[2];
292 u8 pwm_auto_point_mapping[4];
293 u8 pwm_auto_point_pwm[4][5];
Hans de Goede76698962009-12-09 20:36:01 +0100294 s8 pwm_auto_point_temp[4][4];
Hans de Goede45fb3662007-07-13 14:34:19 +0200295};
296
Mark van Doesburg77a4a3e2009-01-07 16:37:27 +0100297/* Sysfs in */
Hans de Goede45fb3662007-07-13 14:34:19 +0200298static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
299 char *buf);
300static ssize_t show_in_max(struct device *dev, struct device_attribute
301 *devattr, char *buf);
302static ssize_t store_in_max(struct device *dev, struct device_attribute
303 *devattr, const char *buf, size_t count);
304static ssize_t show_in_beep(struct device *dev, struct device_attribute
305 *devattr, char *buf);
306static ssize_t store_in_beep(struct device *dev, struct device_attribute
307 *devattr, const char *buf, size_t count);
308static ssize_t show_in_alarm(struct device *dev, struct device_attribute
309 *devattr, char *buf);
310/* Sysfs Fan */
311static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
312 char *buf);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100313static ssize_t show_fan_full_speed(struct device *dev,
314 struct device_attribute *devattr, char *buf);
315static ssize_t store_fan_full_speed(struct device *dev,
316 struct device_attribute *devattr, const char *buf, size_t count);
Hans de Goede45fb3662007-07-13 14:34:19 +0200317static ssize_t show_fan_beep(struct device *dev, struct device_attribute
318 *devattr, char *buf);
319static ssize_t store_fan_beep(struct device *dev, struct device_attribute
320 *devattr, const char *buf, size_t count);
321static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
322 *devattr, char *buf);
323/* Sysfs Temp */
324static ssize_t show_temp(struct device *dev, struct device_attribute
325 *devattr, char *buf);
326static ssize_t show_temp_max(struct device *dev, struct device_attribute
327 *devattr, char *buf);
328static ssize_t store_temp_max(struct device *dev, struct device_attribute
329 *devattr, const char *buf, size_t count);
330static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
331 *devattr, char *buf);
332static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
333 *devattr, const char *buf, size_t count);
334static ssize_t show_temp_crit(struct device *dev, struct device_attribute
335 *devattr, char *buf);
336static ssize_t store_temp_crit(struct device *dev, struct device_attribute
337 *devattr, const char *buf, size_t count);
338static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
339 *devattr, char *buf);
340static ssize_t show_temp_type(struct device *dev, struct device_attribute
341 *devattr, char *buf);
342static ssize_t show_temp_beep(struct device *dev, struct device_attribute
343 *devattr, char *buf);
344static ssize_t store_temp_beep(struct device *dev, struct device_attribute
345 *devattr, const char *buf, size_t count);
346static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
347 *devattr, char *buf);
348static ssize_t show_temp_fault(struct device *dev, struct device_attribute
349 *devattr, char *buf);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100350/* PWM and Auto point control */
351static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
352 char *buf);
353static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr,
354 const char *buf, size_t count);
Hans de Goede629c58b2011-05-25 20:43:32 +0200355static ssize_t show_simple_pwm(struct device *dev,
356 struct device_attribute *devattr, char *buf);
357static ssize_t store_simple_pwm(struct device *dev,
358 struct device_attribute *devattr, const char *buf, size_t count);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100359static ssize_t show_pwm_enable(struct device *dev,
360 struct device_attribute *devattr, char *buf);
361static ssize_t store_pwm_enable(struct device *dev,
362 struct device_attribute *devattr, const char *buf, size_t count);
363static ssize_t show_pwm_interpolate(struct device *dev,
364 struct device_attribute *devattr, char *buf);
365static ssize_t store_pwm_interpolate(struct device *dev,
366 struct device_attribute *devattr, const char *buf, size_t count);
367static ssize_t show_pwm_auto_point_channel(struct device *dev,
368 struct device_attribute *devattr, char *buf);
369static ssize_t store_pwm_auto_point_channel(struct device *dev,
370 struct device_attribute *devattr, const char *buf, size_t count);
371static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
372 struct device_attribute *devattr, char *buf);
373static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
374 struct device_attribute *devattr, const char *buf, size_t count);
375static ssize_t show_pwm_auto_point_pwm(struct device *dev,
376 struct device_attribute *devattr, char *buf);
377static ssize_t store_pwm_auto_point_pwm(struct device *dev,
378 struct device_attribute *devattr, const char *buf, size_t count);
379static ssize_t show_pwm_auto_point_temp(struct device *dev,
380 struct device_attribute *devattr, char *buf);
381static ssize_t store_pwm_auto_point_temp(struct device *dev,
382 struct device_attribute *devattr, const char *buf, size_t count);
Hans de Goede45fb3662007-07-13 14:34:19 +0200383/* Sysfs misc */
384static ssize_t show_name(struct device *dev, struct device_attribute *devattr,
385 char *buf);
386
Bill Pemberton6c931ae2012-11-19 13:22:35 -0500387static int f71882fg_probe(struct platform_device *pdev);
Hans de Goedec13548c2009-01-07 16:37:27 +0100388static int f71882fg_remove(struct platform_device *pdev);
Hans de Goede45fb3662007-07-13 14:34:19 +0200389
390static struct platform_driver f71882fg_driver = {
391 .driver = {
Hans de Goede45fb3662007-07-13 14:34:19 +0200392 .name = DRVNAME,
393 },
394 .probe = f71882fg_probe,
Jean Delvarecd659fd2009-06-15 18:39:45 +0200395 .remove = f71882fg_remove,
Hans de Goede45fb3662007-07-13 14:34:19 +0200396};
397
Hans de Goedec13548c2009-01-07 16:37:27 +0100398static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
Hans de Goede45fb3662007-07-13 14:34:19 +0200399
Guenter Roeck20eaf722012-01-19 11:02:17 -0800400/*
401 * Temp attr for the f71858fg, the f71858fg is special as it has its
402 * temperature indexes start at 0 (the others start at 1)
403 */
Hans de Goede0bae6402011-03-09 20:57:10 +0100404static struct sensor_device_attribute_2 f71858fg_temp_attr[] = {
Hans de Goede09475d32009-06-15 18:39:52 +0200405 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
406 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
407 store_temp_max, 0, 0),
408 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
409 store_temp_max_hyst, 0, 0),
410 SENSOR_ATTR_2(temp1_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 0),
411 SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
412 store_temp_crit, 0, 0),
413 SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
414 0, 0),
415 SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4),
416 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0),
417 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1),
418 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max,
419 store_temp_max, 0, 1),
420 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
421 store_temp_max_hyst, 0, 1),
422 SENSOR_ATTR_2(temp2_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
423 SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
424 store_temp_crit, 0, 1),
425 SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
426 0, 1),
427 SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
Hans de Goede09475d32009-06-15 18:39:52 +0200428 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
429 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2),
430 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
431 store_temp_max, 0, 2),
432 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
433 store_temp_max_hyst, 0, 2),
434 SENSOR_ATTR_2(temp3_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
435 SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit,
436 store_temp_crit, 0, 2),
437 SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
438 0, 2),
439 SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
440 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
441};
442
Hans de Goede0bae6402011-03-09 20:57:10 +0100443/* Temp attr for the standard models */
Hans de Goede78aa4f72011-03-09 20:57:12 +0100444static struct sensor_device_attribute_2 fxxxx_temp_attr[3][9] = { {
Hans de Goede7567a042009-01-07 16:37:28 +0100445 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 1),
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100446 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100447 store_temp_max, 0, 1),
Hans de Goede7567a042009-01-07 16:37:28 +0100448 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100449 store_temp_max_hyst, 0, 1),
Guenter Roeck20eaf722012-01-19 11:02:17 -0800450 /*
451 * Should really be temp1_max_alarm, but older versions did not handle
452 * the max and crit alarms separately and lm_sensors v2 depends on the
453 * presence of temp#_alarm files. The same goes for temp2/3 _alarm.
454 */
Hans de Goede754a5907b2009-01-07 16:37:29 +0100455 SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
Hans de Goede7567a042009-01-07 16:37:28 +0100456 SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100457 store_temp_crit, 0, 1),
Hans de Goede7567a042009-01-07 16:37:28 +0100458 SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100459 0, 1),
Hans de Goede754a5907b2009-01-07 16:37:29 +0100460 SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
Hans de Goede7567a042009-01-07 16:37:28 +0100461 SENSOR_ATTR_2(temp1_type, S_IRUGO, show_temp_type, NULL, 0, 1),
Hans de Goede7567a042009-01-07 16:37:28 +0100462 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
Hans de Goede60d2b372011-03-09 20:57:11 +0100463}, {
Hans de Goede7567a042009-01-07 16:37:28 +0100464 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 2),
465 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100466 store_temp_max, 0, 2),
Hans de Goede7567a042009-01-07 16:37:28 +0100467 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100468 store_temp_max_hyst, 0, 2),
Hans de Goede754a5907b2009-01-07 16:37:29 +0100469 /* Should be temp2_max_alarm, see temp1_alarm note */
470 SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
Hans de Goede7567a042009-01-07 16:37:28 +0100471 SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100472 store_temp_crit, 0, 2),
Hans de Goede7567a042009-01-07 16:37:28 +0100473 SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100474 0, 2),
Hans de Goede754a5907b2009-01-07 16:37:29 +0100475 SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
Hans de Goede7567a042009-01-07 16:37:28 +0100476 SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 2),
Hans de Goede7567a042009-01-07 16:37:28 +0100477 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
Hans de Goede60d2b372011-03-09 20:57:11 +0100478}, {
Hans de Goede7567a042009-01-07 16:37:28 +0100479 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 3),
480 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
481 store_temp_max, 0, 3),
482 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
483 store_temp_max_hyst, 0, 3),
Hans de Goede754a5907b2009-01-07 16:37:29 +0100484 /* Should be temp3_max_alarm, see temp1_alarm note */
485 SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 3),
Hans de Goede7567a042009-01-07 16:37:28 +0100486 SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit,
487 store_temp_crit, 0, 3),
488 SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
489 0, 3),
Hans de Goede754a5907b2009-01-07 16:37:29 +0100490 SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 7),
Hans de Goede7567a042009-01-07 16:37:28 +0100491 SENSOR_ATTR_2(temp3_type, S_IRUGO, show_temp_type, NULL, 0, 3),
Hans de Goede7567a042009-01-07 16:37:28 +0100492 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 3),
Hans de Goede60d2b372011-03-09 20:57:11 +0100493} };
Hans de Goede45fb3662007-07-13 14:34:19 +0200494
Hans de Goede78aa4f72011-03-09 20:57:12 +0100495/* Temp attr for models which can beep on temp alarm */
496static struct sensor_device_attribute_2 fxxxx_temp_beep_attr[3][2] = { {
497 SENSOR_ATTR_2(temp1_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
498 store_temp_beep, 0, 1),
499 SENSOR_ATTR_2(temp1_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
500 store_temp_beep, 0, 5),
501}, {
502 SENSOR_ATTR_2(temp2_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
503 store_temp_beep, 0, 2),
504 SENSOR_ATTR_2(temp2_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
505 store_temp_beep, 0, 6),
506}, {
507 SENSOR_ATTR_2(temp3_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
508 store_temp_beep, 0, 3),
509 SENSOR_ATTR_2(temp3_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
510 store_temp_beep, 0, 7),
511} };
512
Peter Hungdcd956f2015-07-07 16:22:37 +0800513static struct sensor_device_attribute_2 f81866_temp_beep_attr[3][2] = { {
514 SENSOR_ATTR_2(temp1_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
515 store_temp_beep, 0, 0),
516 SENSOR_ATTR_2(temp1_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
517 store_temp_beep, 0, 4),
518}, {
519 SENSOR_ATTR_2(temp2_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
520 store_temp_beep, 0, 1),
521 SENSOR_ATTR_2(temp2_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
522 store_temp_beep, 0, 5),
523}, {
524 SENSOR_ATTR_2(temp3_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
525 store_temp_beep, 0, 2),
526 SENSOR_ATTR_2(temp3_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
527 store_temp_beep, 0, 6),
528} };
529
Guenter Roeck20eaf722012-01-19 11:02:17 -0800530/*
531 * Temp attr for the f8000
532 * Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max)
533 * is used as hysteresis value to clear alarms
534 * Also like the f71858fg its temperature indexes start at 0
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100535 */
Hans de Goede0bae6402011-03-09 20:57:10 +0100536static struct sensor_device_attribute_2 f8000_temp_attr[] = {
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100537 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
538 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_crit,
539 store_temp_crit, 0, 0),
540 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
541 store_temp_max, 0, 0),
542 SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4),
Hans de Goedeb6858bc2009-06-15 18:39:51 +0200543 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0),
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100544 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1),
545 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_crit,
546 store_temp_crit, 0, 1),
547 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
548 store_temp_max, 0, 1),
549 SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
Hans de Goedeb6858bc2009-06-15 18:39:51 +0200550 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100551 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2),
552 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_crit,
553 store_temp_crit, 0, 2),
554 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
555 store_temp_max, 0, 2),
556 SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
Hans de Goedeb6858bc2009-06-15 18:39:51 +0200557 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100558};
559
Hans de Goede0bae6402011-03-09 20:57:10 +0100560/* in attr for all models */
561static struct sensor_device_attribute_2 fxxxx_in_attr[] = {
562 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
563 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
564 SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2),
565 SENSOR_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 0, 3),
566 SENSOR_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 0, 4),
567 SENSOR_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 0, 5),
568 SENSOR_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 0, 6),
569 SENSOR_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 0, 7),
570 SENSOR_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 0, 8),
Peter Hung2725fe22015-07-07 16:22:36 +0800571 SENSOR_ATTR_2(in9_input, S_IRUGO, show_in, NULL, 0, 9),
Hans de Goede0bae6402011-03-09 20:57:10 +0100572};
573
574/* For models with in1 alarm capability */
575static struct sensor_device_attribute_2 fxxxx_in1_alarm_attr[] = {
576 SENSOR_ATTR_2(in1_max, S_IRUGO|S_IWUSR, show_in_max, store_in_max,
577 0, 1),
578 SENSOR_ATTR_2(in1_beep, S_IRUGO|S_IWUSR, show_in_beep, store_in_beep,
579 0, 1),
580 SENSOR_ATTR_2(in1_alarm, S_IRUGO, show_in_alarm, NULL, 0, 1),
581};
582
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100583/* Fan / PWM attr common to all models */
Hans de Goedeb69b0392009-12-09 20:36:00 +0100584static struct sensor_device_attribute_2 fxxxx_fan_attr[4][6] = { {
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100585 SENSOR_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0),
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100586 SENSOR_ATTR_2(fan1_full_speed, S_IRUGO|S_IWUSR,
587 show_fan_full_speed,
588 store_fan_full_speed, 0, 0),
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100589 SENSOR_ATTR_2(fan1_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 0),
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100590 SENSOR_ATTR_2(pwm1, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 0),
591 SENSOR_ATTR_2(pwm1_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
592 store_pwm_enable, 0, 0),
593 SENSOR_ATTR_2(pwm1_interpolate, S_IRUGO|S_IWUSR,
594 show_pwm_interpolate, store_pwm_interpolate, 0, 0),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100595}, {
596 SENSOR_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 0, 1),
597 SENSOR_ATTR_2(fan2_full_speed, S_IRUGO|S_IWUSR,
598 show_fan_full_speed,
599 store_fan_full_speed, 0, 1),
600 SENSOR_ATTR_2(fan2_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 1),
Hans de Goede498be962009-01-07 16:37:28 +0100601 SENSOR_ATTR_2(pwm2, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 1),
602 SENSOR_ATTR_2(pwm2_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
603 store_pwm_enable, 0, 1),
604 SENSOR_ATTR_2(pwm2_interpolate, S_IRUGO|S_IWUSR,
605 show_pwm_interpolate, store_pwm_interpolate, 0, 1),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100606}, {
607 SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
608 SENSOR_ATTR_2(fan3_full_speed, S_IRUGO|S_IWUSR,
609 show_fan_full_speed,
610 store_fan_full_speed, 0, 2),
611 SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
Hans de Goede3fc78382009-06-15 18:39:50 +0200612 SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 2),
613 SENSOR_ATTR_2(pwm3_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
614 store_pwm_enable, 0, 2),
Hans de Goede498be962009-01-07 16:37:28 +0100615 SENSOR_ATTR_2(pwm3_interpolate, S_IRUGO|S_IWUSR,
616 show_pwm_interpolate, store_pwm_interpolate, 0, 2),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100617}, {
618 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
619 SENSOR_ATTR_2(fan4_full_speed, S_IRUGO|S_IWUSR,
620 show_fan_full_speed,
621 store_fan_full_speed, 0, 3),
622 SENSOR_ATTR_2(fan4_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 3),
623 SENSOR_ATTR_2(pwm4, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 3),
624 SENSOR_ATTR_2(pwm4_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
625 store_pwm_enable, 0, 3),
626 SENSOR_ATTR_2(pwm4_interpolate, S_IRUGO|S_IWUSR,
627 show_pwm_interpolate, store_pwm_interpolate, 0, 3),
628} };
Hans de Goede498be962009-01-07 16:37:28 +0100629
Hans de Goede629c58b2011-05-25 20:43:32 +0200630/* Attr for the third fan of the f71808a, which only has manual pwm */
631static struct sensor_device_attribute_2 f71808a_fan3_attr[] = {
632 SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
633 SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
634 SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR,
635 show_simple_pwm, store_simple_pwm, 0, 2),
636};
637
Hans de Goede66344aa2009-12-09 20:35:59 +0100638/* Attr for models which can beep on Fan alarm */
639static struct sensor_device_attribute_2 fxxxx_fan_beep_attr[] = {
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100640 SENSOR_ATTR_2(fan1_beep, S_IRUGO|S_IWUSR, show_fan_beep,
641 store_fan_beep, 0, 0),
642 SENSOR_ATTR_2(fan2_beep, S_IRUGO|S_IWUSR, show_fan_beep,
643 store_fan_beep, 0, 1),
644 SENSOR_ATTR_2(fan3_beep, S_IRUGO|S_IWUSR, show_fan_beep,
645 store_fan_beep, 0, 2),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100646 SENSOR_ATTR_2(fan4_beep, S_IRUGO|S_IWUSR, show_fan_beep,
647 store_fan_beep, 0, 3),
Hans de Goede66344aa2009-12-09 20:35:59 +0100648};
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100649
Guenter Roeck20eaf722012-01-19 11:02:17 -0800650/*
651 * PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
652 * standard models
653 */
Hans de Goede55840142011-09-09 12:12:33 +0200654static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr[3][7] = { {
Hans de Goede66344aa2009-12-09 20:35:59 +0100655 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
656 show_pwm_auto_point_channel,
657 store_pwm_auto_point_channel, 0, 0),
Hans de Goede498be962009-01-07 16:37:28 +0100658 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
659 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
660 1, 0),
661 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
662 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
663 4, 0),
664 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
665 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
666 0, 0),
667 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
668 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
669 3, 0),
670 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
671 show_pwm_auto_point_temp_hyst,
672 store_pwm_auto_point_temp_hyst,
673 0, 0),
674 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
675 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
Hans de Goede55840142011-09-09 12:12:33 +0200676}, {
Hans de Goede66344aa2009-12-09 20:35:59 +0100677 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
678 show_pwm_auto_point_channel,
679 store_pwm_auto_point_channel, 0, 1),
Hans de Goede498be962009-01-07 16:37:28 +0100680 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
681 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
682 1, 1),
683 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
684 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
685 4, 1),
686 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
687 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
688 0, 1),
689 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
690 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
691 3, 1),
692 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
693 show_pwm_auto_point_temp_hyst,
694 store_pwm_auto_point_temp_hyst,
695 0, 1),
696 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
697 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
Hans de Goede55840142011-09-09 12:12:33 +0200698}, {
Hans de Goede66344aa2009-12-09 20:35:59 +0100699 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
700 show_pwm_auto_point_channel,
701 store_pwm_auto_point_channel, 0, 2),
Hans de Goede49010622009-01-07 16:37:30 +0100702 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
703 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
704 1, 2),
705 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
706 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
707 4, 2),
708 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
709 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
710 0, 2),
711 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
712 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
713 3, 2),
714 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
715 show_pwm_auto_point_temp_hyst,
716 store_pwm_auto_point_temp_hyst,
717 0, 2),
718 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
719 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
Hans de Goede55840142011-09-09 12:12:33 +0200720} };
Hans de Goede498be962009-01-07 16:37:28 +0100721
Guenter Roeck20eaf722012-01-19 11:02:17 -0800722/*
723 * PWM attr for the f71808e/f71869, almost identical to the f71862fg, but the
724 * pwm setting when the temperature is above the pwmX_auto_point1_temp can be
725 * programmed instead of being hardcoded to 0xff
726 */
Hans de Goede55840142011-09-09 12:12:33 +0200727static struct sensor_device_attribute_2 f71869_auto_pwm_attr[3][8] = { {
Hans de Goedec11bb992011-03-09 20:57:15 +0100728 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
729 show_pwm_auto_point_channel,
730 store_pwm_auto_point_channel, 0, 0),
731 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
732 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
733 0, 0),
734 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
735 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
736 1, 0),
737 SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO|S_IWUSR,
738 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
739 4, 0),
740 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
741 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
742 0, 0),
743 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
744 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
745 3, 0),
746 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
747 show_pwm_auto_point_temp_hyst,
748 store_pwm_auto_point_temp_hyst,
749 0, 0),
750 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
751 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
Hans de Goede55840142011-09-09 12:12:33 +0200752}, {
Hans de Goedec11bb992011-03-09 20:57:15 +0100753 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
754 show_pwm_auto_point_channel,
755 store_pwm_auto_point_channel, 0, 1),
756 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
757 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
758 0, 1),
759 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
760 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
761 1, 1),
762 SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO|S_IWUSR,
763 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
764 4, 1),
765 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
766 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
767 0, 1),
768 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
769 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
770 3, 1),
771 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
772 show_pwm_auto_point_temp_hyst,
773 store_pwm_auto_point_temp_hyst,
774 0, 1),
775 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
776 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
Hans de Goede55840142011-09-09 12:12:33 +0200777}, {
Hans de Goedec11bb992011-03-09 20:57:15 +0100778 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
779 show_pwm_auto_point_channel,
780 store_pwm_auto_point_channel, 0, 2),
781 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
782 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
783 0, 2),
784 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
785 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
786 1, 2),
787 SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO|S_IWUSR,
788 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
789 4, 2),
790 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
791 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
792 0, 2),
793 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
794 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
795 3, 2),
796 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
797 show_pwm_auto_point_temp_hyst,
798 store_pwm_auto_point_temp_hyst,
799 0, 2),
800 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
801 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
Hans de Goede55840142011-09-09 12:12:33 +0200802} };
Hans de Goedec11bb992011-03-09 20:57:15 +0100803
Hans de Goede3cad4022011-03-09 20:57:14 +0100804/* PWM attr for the standard models */
Hans de Goedeb69b0392009-12-09 20:36:00 +0100805static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr[4][14] = { {
Hans de Goede66344aa2009-12-09 20:35:59 +0100806 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
807 show_pwm_auto_point_channel,
808 store_pwm_auto_point_channel, 0, 0),
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100809 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
810 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
811 0, 0),
812 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
813 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
814 1, 0),
815 SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO|S_IWUSR,
816 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
817 2, 0),
818 SENSOR_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO|S_IWUSR,
819 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
820 3, 0),
821 SENSOR_ATTR_2(pwm1_auto_point5_pwm, S_IRUGO|S_IWUSR,
822 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
823 4, 0),
824 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
825 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
826 0, 0),
827 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
828 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
829 1, 0),
830 SENSOR_ATTR_2(pwm1_auto_point3_temp, S_IRUGO|S_IWUSR,
831 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
832 2, 0),
833 SENSOR_ATTR_2(pwm1_auto_point4_temp, S_IRUGO|S_IWUSR,
834 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
835 3, 0),
836 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
837 show_pwm_auto_point_temp_hyst,
838 store_pwm_auto_point_temp_hyst,
839 0, 0),
840 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
841 show_pwm_auto_point_temp_hyst, NULL, 1, 0),
842 SENSOR_ATTR_2(pwm1_auto_point3_temp_hyst, S_IRUGO,
843 show_pwm_auto_point_temp_hyst, NULL, 2, 0),
844 SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst, S_IRUGO,
845 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100846}, {
Hans de Goede66344aa2009-12-09 20:35:59 +0100847 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
848 show_pwm_auto_point_channel,
849 store_pwm_auto_point_channel, 0, 1),
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100850 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
851 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
852 0, 1),
853 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
854 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
855 1, 1),
856 SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO|S_IWUSR,
857 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
858 2, 1),
859 SENSOR_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO|S_IWUSR,
860 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
861 3, 1),
862 SENSOR_ATTR_2(pwm2_auto_point5_pwm, S_IRUGO|S_IWUSR,
863 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
864 4, 1),
865 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
866 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
867 0, 1),
868 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
869 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
870 1, 1),
871 SENSOR_ATTR_2(pwm2_auto_point3_temp, S_IRUGO|S_IWUSR,
872 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
873 2, 1),
874 SENSOR_ATTR_2(pwm2_auto_point4_temp, S_IRUGO|S_IWUSR,
875 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
876 3, 1),
877 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
878 show_pwm_auto_point_temp_hyst,
879 store_pwm_auto_point_temp_hyst,
880 0, 1),
881 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
882 show_pwm_auto_point_temp_hyst, NULL, 1, 1),
883 SENSOR_ATTR_2(pwm2_auto_point3_temp_hyst, S_IRUGO,
884 show_pwm_auto_point_temp_hyst, NULL, 2, 1),
885 SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst, S_IRUGO,
886 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100887}, {
Hans de Goede66344aa2009-12-09 20:35:59 +0100888 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
889 show_pwm_auto_point_channel,
890 store_pwm_auto_point_channel, 0, 2),
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100891 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
892 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
893 0, 2),
894 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
895 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
896 1, 2),
897 SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO|S_IWUSR,
898 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
899 2, 2),
900 SENSOR_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO|S_IWUSR,
901 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
902 3, 2),
903 SENSOR_ATTR_2(pwm3_auto_point5_pwm, S_IRUGO|S_IWUSR,
904 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
905 4, 2),
906 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
907 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
908 0, 2),
909 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
910 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
911 1, 2),
912 SENSOR_ATTR_2(pwm3_auto_point3_temp, S_IRUGO|S_IWUSR,
913 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
914 2, 2),
915 SENSOR_ATTR_2(pwm3_auto_point4_temp, S_IRUGO|S_IWUSR,
916 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
917 3, 2),
918 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
919 show_pwm_auto_point_temp_hyst,
920 store_pwm_auto_point_temp_hyst,
921 0, 2),
922 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
923 show_pwm_auto_point_temp_hyst, NULL, 1, 2),
924 SENSOR_ATTR_2(pwm3_auto_point3_temp_hyst, S_IRUGO,
925 show_pwm_auto_point_temp_hyst, NULL, 2, 2),
926 SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst, S_IRUGO,
927 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100928}, {
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100929 SENSOR_ATTR_2(pwm4_auto_channels_temp, S_IRUGO|S_IWUSR,
930 show_pwm_auto_point_channel,
931 store_pwm_auto_point_channel, 0, 3),
932 SENSOR_ATTR_2(pwm4_auto_point1_pwm, S_IRUGO|S_IWUSR,
933 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
934 0, 3),
935 SENSOR_ATTR_2(pwm4_auto_point2_pwm, S_IRUGO|S_IWUSR,
936 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
937 1, 3),
938 SENSOR_ATTR_2(pwm4_auto_point3_pwm, S_IRUGO|S_IWUSR,
939 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
940 2, 3),
941 SENSOR_ATTR_2(pwm4_auto_point4_pwm, S_IRUGO|S_IWUSR,
942 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
943 3, 3),
944 SENSOR_ATTR_2(pwm4_auto_point5_pwm, S_IRUGO|S_IWUSR,
945 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
946 4, 3),
947 SENSOR_ATTR_2(pwm4_auto_point1_temp, S_IRUGO|S_IWUSR,
948 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
949 0, 3),
950 SENSOR_ATTR_2(pwm4_auto_point2_temp, S_IRUGO|S_IWUSR,
951 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
952 1, 3),
953 SENSOR_ATTR_2(pwm4_auto_point3_temp, S_IRUGO|S_IWUSR,
954 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
955 2, 3),
956 SENSOR_ATTR_2(pwm4_auto_point4_temp, S_IRUGO|S_IWUSR,
957 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
958 3, 3),
959 SENSOR_ATTR_2(pwm4_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
960 show_pwm_auto_point_temp_hyst,
961 store_pwm_auto_point_temp_hyst,
962 0, 3),
963 SENSOR_ATTR_2(pwm4_auto_point2_temp_hyst, S_IRUGO,
964 show_pwm_auto_point_temp_hyst, NULL, 1, 3),
965 SENSOR_ATTR_2(pwm4_auto_point3_temp_hyst, S_IRUGO,
966 show_pwm_auto_point_temp_hyst, NULL, 2, 3),
967 SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst, S_IRUGO,
968 show_pwm_auto_point_temp_hyst, NULL, 3, 3),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100969} };
Hans de Goede45fb3662007-07-13 14:34:19 +0200970
Hans de Goede66344aa2009-12-09 20:35:59 +0100971/* Fan attr specific to the f8000 (4th fan input can only measure speed) */
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100972static struct sensor_device_attribute_2 f8000_fan_attr[] = {
973 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
Hans de Goede66344aa2009-12-09 20:35:59 +0100974};
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100975
Guenter Roeck20eaf722012-01-19 11:02:17 -0800976/*
977 * PWM attr for the f8000, zones mapped to temp instead of to pwm!
978 * Also the register block at offset A0 maps to TEMP1 (so our temp2, as the
979 * F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0
980 */
Hans de Goede55840142011-09-09 12:12:33 +0200981static struct sensor_device_attribute_2 f8000_auto_pwm_attr[3][14] = { {
Hans de Goede66344aa2009-12-09 20:35:59 +0100982 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
983 show_pwm_auto_point_channel,
984 store_pwm_auto_point_channel, 0, 0),
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100985 SENSOR_ATTR_2(temp1_auto_point1_pwm, S_IRUGO|S_IWUSR,
986 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
987 0, 2),
988 SENSOR_ATTR_2(temp1_auto_point2_pwm, S_IRUGO|S_IWUSR,
989 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
990 1, 2),
991 SENSOR_ATTR_2(temp1_auto_point3_pwm, S_IRUGO|S_IWUSR,
992 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
993 2, 2),
994 SENSOR_ATTR_2(temp1_auto_point4_pwm, S_IRUGO|S_IWUSR,
995 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
996 3, 2),
997 SENSOR_ATTR_2(temp1_auto_point5_pwm, S_IRUGO|S_IWUSR,
998 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
999 4, 2),
1000 SENSOR_ATTR_2(temp1_auto_point1_temp, S_IRUGO|S_IWUSR,
1001 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1002 0, 2),
1003 SENSOR_ATTR_2(temp1_auto_point2_temp, S_IRUGO|S_IWUSR,
1004 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1005 1, 2),
1006 SENSOR_ATTR_2(temp1_auto_point3_temp, S_IRUGO|S_IWUSR,
1007 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1008 2, 2),
1009 SENSOR_ATTR_2(temp1_auto_point4_temp, S_IRUGO|S_IWUSR,
1010 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1011 3, 2),
1012 SENSOR_ATTR_2(temp1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
1013 show_pwm_auto_point_temp_hyst,
1014 store_pwm_auto_point_temp_hyst,
1015 0, 2),
1016 SENSOR_ATTR_2(temp1_auto_point2_temp_hyst, S_IRUGO,
1017 show_pwm_auto_point_temp_hyst, NULL, 1, 2),
1018 SENSOR_ATTR_2(temp1_auto_point3_temp_hyst, S_IRUGO,
1019 show_pwm_auto_point_temp_hyst, NULL, 2, 2),
1020 SENSOR_ATTR_2(temp1_auto_point4_temp_hyst, S_IRUGO,
1021 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
Hans de Goede55840142011-09-09 12:12:33 +02001022}, {
Hans de Goede66344aa2009-12-09 20:35:59 +01001023 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
1024 show_pwm_auto_point_channel,
1025 store_pwm_auto_point_channel, 0, 1),
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001026 SENSOR_ATTR_2(temp2_auto_point1_pwm, S_IRUGO|S_IWUSR,
1027 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1028 0, 0),
1029 SENSOR_ATTR_2(temp2_auto_point2_pwm, S_IRUGO|S_IWUSR,
1030 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1031 1, 0),
1032 SENSOR_ATTR_2(temp2_auto_point3_pwm, S_IRUGO|S_IWUSR,
1033 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1034 2, 0),
1035 SENSOR_ATTR_2(temp2_auto_point4_pwm, S_IRUGO|S_IWUSR,
1036 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1037 3, 0),
1038 SENSOR_ATTR_2(temp2_auto_point5_pwm, S_IRUGO|S_IWUSR,
1039 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1040 4, 0),
1041 SENSOR_ATTR_2(temp2_auto_point1_temp, S_IRUGO|S_IWUSR,
1042 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1043 0, 0),
1044 SENSOR_ATTR_2(temp2_auto_point2_temp, S_IRUGO|S_IWUSR,
1045 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1046 1, 0),
1047 SENSOR_ATTR_2(temp2_auto_point3_temp, S_IRUGO|S_IWUSR,
1048 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1049 2, 0),
1050 SENSOR_ATTR_2(temp2_auto_point4_temp, S_IRUGO|S_IWUSR,
1051 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1052 3, 0),
1053 SENSOR_ATTR_2(temp2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
1054 show_pwm_auto_point_temp_hyst,
1055 store_pwm_auto_point_temp_hyst,
1056 0, 0),
1057 SENSOR_ATTR_2(temp2_auto_point2_temp_hyst, S_IRUGO,
1058 show_pwm_auto_point_temp_hyst, NULL, 1, 0),
1059 SENSOR_ATTR_2(temp2_auto_point3_temp_hyst, S_IRUGO,
1060 show_pwm_auto_point_temp_hyst, NULL, 2, 0),
1061 SENSOR_ATTR_2(temp2_auto_point4_temp_hyst, S_IRUGO,
1062 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
Hans de Goede55840142011-09-09 12:12:33 +02001063}, {
Hans de Goede66344aa2009-12-09 20:35:59 +01001064 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
1065 show_pwm_auto_point_channel,
1066 store_pwm_auto_point_channel, 0, 2),
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001067 SENSOR_ATTR_2(temp3_auto_point1_pwm, S_IRUGO|S_IWUSR,
1068 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1069 0, 1),
1070 SENSOR_ATTR_2(temp3_auto_point2_pwm, S_IRUGO|S_IWUSR,
1071 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1072 1, 1),
1073 SENSOR_ATTR_2(temp3_auto_point3_pwm, S_IRUGO|S_IWUSR,
1074 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1075 2, 1),
1076 SENSOR_ATTR_2(temp3_auto_point4_pwm, S_IRUGO|S_IWUSR,
1077 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1078 3, 1),
1079 SENSOR_ATTR_2(temp3_auto_point5_pwm, S_IRUGO|S_IWUSR,
1080 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1081 4, 1),
1082 SENSOR_ATTR_2(temp3_auto_point1_temp, S_IRUGO|S_IWUSR,
1083 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1084 0, 1),
1085 SENSOR_ATTR_2(temp3_auto_point2_temp, S_IRUGO|S_IWUSR,
1086 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1087 1, 1),
1088 SENSOR_ATTR_2(temp3_auto_point3_temp, S_IRUGO|S_IWUSR,
1089 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1090 2, 1),
1091 SENSOR_ATTR_2(temp3_auto_point4_temp, S_IRUGO|S_IWUSR,
1092 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1093 3, 1),
1094 SENSOR_ATTR_2(temp3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
1095 show_pwm_auto_point_temp_hyst,
1096 store_pwm_auto_point_temp_hyst,
1097 0, 1),
1098 SENSOR_ATTR_2(temp3_auto_point2_temp_hyst, S_IRUGO,
1099 show_pwm_auto_point_temp_hyst, NULL, 1, 1),
1100 SENSOR_ATTR_2(temp3_auto_point3_temp_hyst, S_IRUGO,
1101 show_pwm_auto_point_temp_hyst, NULL, 2, 1),
1102 SENSOR_ATTR_2(temp3_auto_point4_temp_hyst, S_IRUGO,
1103 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
Hans de Goede55840142011-09-09 12:12:33 +02001104} };
Hans de Goede45fb3662007-07-13 14:34:19 +02001105
1106/* Super I/O functions */
1107static inline int superio_inb(int base, int reg)
1108{
1109 outb(reg, base);
1110 return inb(base + 1);
1111}
1112
1113static int superio_inw(int base, int reg)
1114{
1115 int val;
Giel van Schijndelbd328ac2010-05-27 19:58:42 +02001116 val = superio_inb(base, reg) << 8;
1117 val |= superio_inb(base, reg + 1);
Hans de Goede45fb3662007-07-13 14:34:19 +02001118 return val;
1119}
1120
Giel van Schijndelcadb8652010-10-03 08:09:49 -04001121static inline int superio_enter(int base)
Hans de Goede45fb3662007-07-13 14:34:19 +02001122{
Giel van Schijndelcadb8652010-10-03 08:09:49 -04001123 /* Don't step on other drivers' I/O space by accident */
1124 if (!request_muxed_region(base, 2, DRVNAME)) {
Joe Perches22d3b412010-10-20 06:51:34 +00001125 pr_err("I/O address 0x%04x already in use\n", base);
Giel van Schijndelcadb8652010-10-03 08:09:49 -04001126 return -EBUSY;
1127 }
1128
Hans de Goede45fb3662007-07-13 14:34:19 +02001129 /* according to the datasheet the key must be send twice! */
Giel van Schijndel162bb592010-05-27 19:58:40 +02001130 outb(SIO_UNLOCK_KEY, base);
1131 outb(SIO_UNLOCK_KEY, base);
Giel van Schijndelcadb8652010-10-03 08:09:49 -04001132
1133 return 0;
Hans de Goede45fb3662007-07-13 14:34:19 +02001134}
1135
Giel van Schijndel162bb592010-05-27 19:58:40 +02001136static inline void superio_select(int base, int ld)
Hans de Goede45fb3662007-07-13 14:34:19 +02001137{
1138 outb(SIO_REG_LDSEL, base);
1139 outb(ld, base + 1);
1140}
1141
1142static inline void superio_exit(int base)
1143{
1144 outb(SIO_LOCK_KEY, base);
Giel van Schijndelcadb8652010-10-03 08:09:49 -04001145 release_region(base, 2);
Hans de Goede45fb3662007-07-13 14:34:19 +02001146}
1147
Hans de Goede2f650632009-01-07 16:37:31 +01001148static inline int fan_from_reg(u16 reg)
Hans de Goede45fb3662007-07-13 14:34:19 +02001149{
1150 return reg ? (1500000 / reg) : 0;
1151}
1152
Hans de Goede2f650632009-01-07 16:37:31 +01001153static inline u16 fan_to_reg(int fan)
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001154{
1155 return fan ? (1500000 / fan) : 0;
1156}
1157
Hans de Goede45fb3662007-07-13 14:34:19 +02001158static u8 f71882fg_read8(struct f71882fg_data *data, u8 reg)
1159{
1160 u8 val;
1161
1162 outb(reg, data->addr + ADDR_REG_OFFSET);
1163 val = inb(data->addr + DATA_REG_OFFSET);
1164
1165 return val;
1166}
1167
1168static u16 f71882fg_read16(struct f71882fg_data *data, u8 reg)
1169{
1170 u16 val;
1171
Giel van Schijndelbd328ac2010-05-27 19:58:42 +02001172 val = f71882fg_read8(data, reg) << 8;
1173 val |= f71882fg_read8(data, reg + 1);
Hans de Goede45fb3662007-07-13 14:34:19 +02001174
1175 return val;
1176}
1177
1178static void f71882fg_write8(struct f71882fg_data *data, u8 reg, u8 val)
1179{
1180 outb(reg, data->addr + ADDR_REG_OFFSET);
1181 outb(val, data->addr + DATA_REG_OFFSET);
1182}
1183
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001184static void f71882fg_write16(struct f71882fg_data *data, u8 reg, u16 val)
1185{
Giel van Schijndelbd328ac2010-05-27 19:58:42 +02001186 f71882fg_write8(data, reg, val >> 8);
1187 f71882fg_write8(data, reg + 1, val & 0xff);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001188}
1189
Hans de Goede09475d32009-06-15 18:39:52 +02001190static u16 f71882fg_read_temp(struct f71882fg_data *data, int nr)
1191{
1192 if (data->type == f71858fg)
1193 return f71882fg_read16(data, F71882FG_REG_TEMP(nr));
1194 else
1195 return f71882fg_read8(data, F71882FG_REG_TEMP(nr));
1196}
1197
Mark van Doesburg77a4a3e2009-01-07 16:37:27 +01001198static struct f71882fg_data *f71882fg_update_device(struct device *dev)
Hans de Goede45fb3662007-07-13 14:34:19 +02001199{
1200 struct f71882fg_data *data = dev_get_drvdata(dev);
Jean Delvaref27def02011-03-26 10:45:01 +01001201 int nr_fans = f71882fg_nr_fans[data->type];
1202 int nr_temps = f71882fg_nr_temps[data->type];
Hans de Goedee5e713c2011-03-10 08:54:02 +01001203 int nr, reg, point;
Hans de Goede45fb3662007-07-13 14:34:19 +02001204
1205 mutex_lock(&data->update_lock);
1206
1207 /* Update once every 60 seconds */
Giel van Schijndel162bb592010-05-27 19:58:40 +02001208 if (time_after(jiffies, data->last_limits + 60 * HZ) ||
Hans de Goede45fb3662007-07-13 14:34:19 +02001209 !data->valid) {
Hans de Goede0bae6402011-03-09 20:57:10 +01001210 if (f71882fg_has_in1_alarm[data->type]) {
Peter Hung3e40b862015-07-07 16:22:38 +08001211 if (data->type == f81866a) {
1212 data->in1_max =
1213 f71882fg_read8(data,
1214 F81866_REG_IN1_HIGH);
1215 data->in_beep =
1216 f71882fg_read8(data,
1217 F81866_REG_IN_BEEP);
1218 } else {
1219 data->in1_max =
1220 f71882fg_read8(data,
1221 F71882FG_REG_IN1_HIGH);
1222 data->in_beep =
1223 f71882fg_read8(data,
1224 F71882FG_REG_IN_BEEP);
1225 }
Hans de Goede498be962009-01-07 16:37:28 +01001226 }
Hans de Goede45fb3662007-07-13 14:34:19 +02001227
1228 /* Get High & boundary temps*/
Hans de Goedee5e713c2011-03-10 08:54:02 +01001229 for (nr = data->temp_start; nr < nr_temps + data->temp_start;
1230 nr++) {
Hans de Goede45fb3662007-07-13 14:34:19 +02001231 data->temp_ovt[nr] = f71882fg_read8(data,
1232 F71882FG_REG_TEMP_OVT(nr));
1233 data->temp_high[nr] = f71882fg_read8(data,
1234 F71882FG_REG_TEMP_HIGH(nr));
1235 }
1236
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001237 if (data->type != f8000) {
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001238 data->temp_hyst[0] = f71882fg_read8(data,
1239 F71882FG_REG_TEMP_HYST(0));
1240 data->temp_hyst[1] = f71882fg_read8(data,
1241 F71882FG_REG_TEMP_HYST(1));
Hans de Goede09475d32009-06-15 18:39:52 +02001242 }
Hans de Goede78aa4f72011-03-09 20:57:12 +01001243 /* All but the f71858fg / f8000 have this register */
1244 if ((data->type != f71858fg) && (data->type != f8000)) {
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001245 reg = f71882fg_read8(data, F71882FG_REG_TEMP_TYPE);
Hans de Goede44c4dc52011-03-09 20:57:07 +01001246 data->temp_type[1] = (reg & 0x02) ? 2 : 4;
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001247 data->temp_type[2] = (reg & 0x04) ? 2 : 4;
1248 data->temp_type[3] = (reg & 0x08) ? 2 : 4;
1249 }
Hans de Goede45fb3662007-07-13 14:34:19 +02001250
Hans de Goede4d538112011-05-25 20:43:32 +02001251 if (f71882fg_fan_has_beep[data->type])
Hans de Goede78aa4f72011-03-09 20:57:12 +01001252 data->fan_beep = f71882fg_read8(data,
1253 F71882FG_REG_FAN_BEEP);
Hans de Goede4d538112011-05-25 20:43:32 +02001254
1255 if (f71882fg_temp_has_beep[data->type])
Hans de Goede78aa4f72011-03-09 20:57:12 +01001256 data->temp_beep = f71882fg_read8(data,
1257 F71882FG_REG_TEMP_BEEP);
Hans de Goede78aa4f72011-03-09 20:57:12 +01001258
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001259 data->pwm_enable = f71882fg_read8(data,
1260 F71882FG_REG_PWM_ENABLE);
Hans de Goedebc274902009-01-07 16:37:29 +01001261 data->pwm_auto_point_hyst[0] =
1262 f71882fg_read8(data, F71882FG_REG_FAN_HYST(0));
1263 data->pwm_auto_point_hyst[1] =
1264 f71882fg_read8(data, F71882FG_REG_FAN_HYST(1));
1265
Hans de Goede498be962009-01-07 16:37:28 +01001266 for (nr = 0; nr < nr_fans; nr++) {
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001267 data->pwm_auto_point_mapping[nr] =
1268 f71882fg_read8(data,
1269 F71882FG_REG_POINT_MAPPING(nr));
1270
Hans de Goedee5e713c2011-03-10 08:54:02 +01001271 switch (data->type) {
1272 default:
Hans de Goede498be962009-01-07 16:37:28 +01001273 for (point = 0; point < 5; point++) {
1274 data->pwm_auto_point_pwm[nr][point] =
1275 f71882fg_read8(data,
1276 F71882FG_REG_POINT_PWM
1277 (nr, point));
1278 }
1279 for (point = 0; point < 4; point++) {
1280 data->pwm_auto_point_temp[nr][point] =
1281 f71882fg_read8(data,
1282 F71882FG_REG_POINT_TEMP
1283 (nr, point));
1284 }
Hans de Goedee5e713c2011-03-10 08:54:02 +01001285 break;
1286 case f71808e:
1287 case f71869:
1288 data->pwm_auto_point_pwm[nr][0] =
1289 f71882fg_read8(data,
1290 F71882FG_REG_POINT_PWM(nr, 0));
1291 /* Fall through */
1292 case f71862fg:
Hans de Goede498be962009-01-07 16:37:28 +01001293 data->pwm_auto_point_pwm[nr][1] =
1294 f71882fg_read8(data,
1295 F71882FG_REG_POINT_PWM
1296 (nr, 1));
1297 data->pwm_auto_point_pwm[nr][4] =
1298 f71882fg_read8(data,
1299 F71882FG_REG_POINT_PWM
1300 (nr, 4));
1301 data->pwm_auto_point_temp[nr][0] =
1302 f71882fg_read8(data,
1303 F71882FG_REG_POINT_TEMP
1304 (nr, 0));
1305 data->pwm_auto_point_temp[nr][3] =
1306 f71882fg_read8(data,
1307 F71882FG_REG_POINT_TEMP
1308 (nr, 3));
Hans de Goedee5e713c2011-03-10 08:54:02 +01001309 break;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001310 }
1311 }
Hans de Goede45fb3662007-07-13 14:34:19 +02001312 data->last_limits = jiffies;
1313 }
1314
1315 /* Update every second */
Mark M. Hoffman8afb1042007-08-21 23:10:46 -04001316 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
Hans de Goede45fb3662007-07-13 14:34:19 +02001317 data->temp_status = f71882fg_read8(data,
1318 F71882FG_REG_TEMP_STATUS);
1319 data->temp_diode_open = f71882fg_read8(data,
1320 F71882FG_REG_TEMP_DIODE_OPEN);
Hans de Goedee5e713c2011-03-10 08:54:02 +01001321 for (nr = data->temp_start; nr < nr_temps + data->temp_start;
1322 nr++)
Hans de Goede09475d32009-06-15 18:39:52 +02001323 data->temp[nr] = f71882fg_read_temp(data, nr);
Hans de Goede45fb3662007-07-13 14:34:19 +02001324
1325 data->fan_status = f71882fg_read8(data,
1326 F71882FG_REG_FAN_STATUS);
Hans de Goede498be962009-01-07 16:37:28 +01001327 for (nr = 0; nr < nr_fans; nr++) {
Hans de Goede45fb3662007-07-13 14:34:19 +02001328 data->fan[nr] = f71882fg_read16(data,
1329 F71882FG_REG_FAN(nr));
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001330 data->fan_target[nr] =
1331 f71882fg_read16(data, F71882FG_REG_FAN_TARGET(nr));
1332 data->fan_full_speed[nr] =
1333 f71882fg_read16(data,
1334 F71882FG_REG_FAN_FULL_SPEED(nr));
1335 data->pwm[nr] =
1336 f71882fg_read8(data, F71882FG_REG_PWM(nr));
1337 }
Hans de Goede629c58b2011-05-25 20:43:32 +02001338 /* Some models have 1 more fan with limited capabilities */
1339 if (data->type == f71808a) {
1340 data->fan[2] = f71882fg_read16(data,
1341 F71882FG_REG_FAN(2));
1342 data->pwm[2] = f71882fg_read8(data,
1343 F71882FG_REG_PWM(2));
1344 }
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001345 if (data->type == f8000)
1346 data->fan[3] = f71882fg_read16(data,
1347 F71882FG_REG_FAN(3));
Hans de Goede0bae6402011-03-09 20:57:10 +01001348
Peter Hung3e40b862015-07-07 16:22:38 +08001349 if (f71882fg_has_in1_alarm[data->type]) {
1350 if (data->type == f81866a)
1351 data->in_status = f71882fg_read8(data,
1352 F81866_REG_IN_STATUS);
1353
1354 else
1355 data->in_status = f71882fg_read8(data,
Hans de Goede45fb3662007-07-13 14:34:19 +02001356 F71882FG_REG_IN_STATUS);
Peter Hung3e40b862015-07-07 16:22:38 +08001357 }
1358
Hans de Goede0bae6402011-03-09 20:57:10 +01001359 for (nr = 0; nr < F71882FG_MAX_INS; nr++)
1360 if (f71882fg_has_in[data->type][nr])
1361 data->in[nr] = f71882fg_read8(data,
1362 F71882FG_REG_IN(nr));
Hans de Goede45fb3662007-07-13 14:34:19 +02001363
1364 data->last_updated = jiffies;
1365 data->valid = 1;
1366 }
1367
1368 mutex_unlock(&data->update_lock);
1369
1370 return data;
1371}
1372
1373/* Sysfs Interface */
1374static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
1375 char *buf)
1376{
1377 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001378 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001379 int speed = fan_from_reg(data->fan[nr]);
1380
1381 if (speed == FAN_MIN_DETECT)
1382 speed = 0;
1383
1384 return sprintf(buf, "%d\n", speed);
1385}
1386
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001387static ssize_t show_fan_full_speed(struct device *dev,
1388 struct device_attribute *devattr, char *buf)
1389{
1390 struct f71882fg_data *data = f71882fg_update_device(dev);
1391 int nr = to_sensor_dev_attr_2(devattr)->index;
1392 int speed = fan_from_reg(data->fan_full_speed[nr]);
1393 return sprintf(buf, "%d\n", speed);
1394}
1395
1396static ssize_t store_fan_full_speed(struct device *dev,
1397 struct device_attribute *devattr,
1398 const char *buf, size_t count)
1399{
1400 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001401 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1402 long val;
1403
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001404 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001405 if (err)
1406 return err;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001407
Guenter Roeck2a844c12013-01-09 08:09:34 -08001408 val = clamp_val(val, 23, 1500000);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001409 val = fan_to_reg(val);
1410
1411 mutex_lock(&data->update_lock);
Hans de Goede4c82c382009-01-07 16:37:30 +01001412 f71882fg_write16(data, F71882FG_REG_FAN_FULL_SPEED(nr), val);
1413 data->fan_full_speed[nr] = val;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001414 mutex_unlock(&data->update_lock);
1415
1416 return count;
1417}
1418
Hans de Goede45fb3662007-07-13 14:34:19 +02001419static ssize_t show_fan_beep(struct device *dev, struct device_attribute
1420 *devattr, char *buf)
1421{
1422 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001423 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001424
1425 if (data->fan_beep & (1 << nr))
1426 return sprintf(buf, "1\n");
1427 else
1428 return sprintf(buf, "0\n");
1429}
1430
1431static ssize_t store_fan_beep(struct device *dev, struct device_attribute
1432 *devattr, const char *buf, size_t count)
1433{
1434 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001435 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1436 unsigned long val;
1437
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001438 err = kstrtoul(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001439 if (err)
1440 return err;
Hans de Goede45fb3662007-07-13 14:34:19 +02001441
1442 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01001443 data->fan_beep = f71882fg_read8(data, F71882FG_REG_FAN_BEEP);
Hans de Goede45fb3662007-07-13 14:34:19 +02001444 if (val)
1445 data->fan_beep |= 1 << nr;
1446 else
1447 data->fan_beep &= ~(1 << nr);
1448
1449 f71882fg_write8(data, F71882FG_REG_FAN_BEEP, data->fan_beep);
1450 mutex_unlock(&data->update_lock);
1451
1452 return count;
1453}
1454
1455static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
1456 *devattr, char *buf)
1457{
1458 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001459 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001460
1461 if (data->fan_status & (1 << nr))
1462 return sprintf(buf, "1\n");
1463 else
1464 return sprintf(buf, "0\n");
1465}
1466
1467static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
1468 char *buf)
1469{
1470 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001471 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001472
1473 return sprintf(buf, "%d\n", data->in[nr] * 8);
1474}
1475
1476static ssize_t show_in_max(struct device *dev, struct device_attribute
1477 *devattr, char *buf)
1478{
1479 struct f71882fg_data *data = f71882fg_update_device(dev);
1480
1481 return sprintf(buf, "%d\n", data->in1_max * 8);
1482}
1483
1484static ssize_t store_in_max(struct device *dev, struct device_attribute
1485 *devattr, const char *buf, size_t count)
1486{
1487 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001488 int err;
1489 long val;
1490
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001491 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001492 if (err)
1493 return err;
1494
1495 val /= 8;
Guenter Roeck2a844c12013-01-09 08:09:34 -08001496 val = clamp_val(val, 0, 255);
Hans de Goede45fb3662007-07-13 14:34:19 +02001497
1498 mutex_lock(&data->update_lock);
Peter Hung3e40b862015-07-07 16:22:38 +08001499 if (data->type == f81866a)
1500 f71882fg_write8(data, F81866_REG_IN1_HIGH, val);
1501 else
1502 f71882fg_write8(data, F71882FG_REG_IN1_HIGH, val);
Hans de Goede45fb3662007-07-13 14:34:19 +02001503 data->in1_max = val;
1504 mutex_unlock(&data->update_lock);
1505
1506 return count;
1507}
1508
1509static ssize_t show_in_beep(struct device *dev, struct device_attribute
1510 *devattr, char *buf)
1511{
1512 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001513 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001514
1515 if (data->in_beep & (1 << nr))
1516 return sprintf(buf, "1\n");
1517 else
1518 return sprintf(buf, "0\n");
1519}
1520
1521static ssize_t store_in_beep(struct device *dev, struct device_attribute
1522 *devattr, const char *buf, size_t count)
1523{
1524 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001525 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1526 unsigned long val;
1527
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001528 err = kstrtoul(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001529 if (err)
1530 return err;
Hans de Goede45fb3662007-07-13 14:34:19 +02001531
1532 mutex_lock(&data->update_lock);
Peter Hung3e40b862015-07-07 16:22:38 +08001533 if (data->type == f81866a)
1534 data->in_beep = f71882fg_read8(data, F81866_REG_IN_BEEP);
1535 else
1536 data->in_beep = f71882fg_read8(data, F71882FG_REG_IN_BEEP);
1537
Hans de Goede45fb3662007-07-13 14:34:19 +02001538 if (val)
1539 data->in_beep |= 1 << nr;
1540 else
1541 data->in_beep &= ~(1 << nr);
1542
Peter Hung3e40b862015-07-07 16:22:38 +08001543 if (data->type == f81866a)
1544 f71882fg_write8(data, F81866_REG_IN_BEEP, data->in_beep);
1545 else
1546 f71882fg_write8(data, F71882FG_REG_IN_BEEP, data->in_beep);
Hans de Goede45fb3662007-07-13 14:34:19 +02001547 mutex_unlock(&data->update_lock);
1548
1549 return count;
1550}
1551
1552static ssize_t show_in_alarm(struct device *dev, struct device_attribute
1553 *devattr, char *buf)
1554{
1555 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001556 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001557
1558 if (data->in_status & (1 << nr))
1559 return sprintf(buf, "1\n");
1560 else
1561 return sprintf(buf, "0\n");
1562}
1563
1564static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
1565 char *buf)
1566{
1567 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001568 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede09475d32009-06-15 18:39:52 +02001569 int sign, temp;
Hans de Goede45fb3662007-07-13 14:34:19 +02001570
Hans de Goede09475d32009-06-15 18:39:52 +02001571 if (data->type == f71858fg) {
1572 /* TEMP_TABLE_SEL 1 or 3 ? */
1573 if (data->temp_config & 1) {
1574 sign = data->temp[nr] & 0x0001;
1575 temp = (data->temp[nr] >> 5) & 0x7ff;
1576 } else {
1577 sign = data->temp[nr] & 0x8000;
1578 temp = (data->temp[nr] >> 5) & 0x3ff;
1579 }
1580 temp *= 125;
1581 if (sign)
1582 temp -= 128000;
1583 } else
1584 temp = data->temp[nr] * 1000;
1585
1586 return sprintf(buf, "%d\n", temp);
Hans de Goede45fb3662007-07-13 14:34:19 +02001587}
1588
1589static ssize_t show_temp_max(struct device *dev, struct device_attribute
1590 *devattr, char *buf)
1591{
1592 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001593 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001594
1595 return sprintf(buf, "%d\n", data->temp_high[nr] * 1000);
1596}
1597
1598static ssize_t store_temp_max(struct device *dev, struct device_attribute
1599 *devattr, const char *buf, size_t count)
1600{
1601 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001602 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1603 long val;
1604
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001605 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001606 if (err)
1607 return err;
1608
1609 val /= 1000;
Guenter Roeck2a844c12013-01-09 08:09:34 -08001610 val = clamp_val(val, 0, 255);
Hans de Goede45fb3662007-07-13 14:34:19 +02001611
1612 mutex_lock(&data->update_lock);
1613 f71882fg_write8(data, F71882FG_REG_TEMP_HIGH(nr), val);
1614 data->temp_high[nr] = val;
1615 mutex_unlock(&data->update_lock);
1616
1617 return count;
1618}
1619
1620static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
1621 *devattr, char *buf)
1622{
1623 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001624 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goedece0bfa52009-01-07 16:37:28 +01001625 int temp_max_hyst;
Hans de Goede45fb3662007-07-13 14:34:19 +02001626
Hans de Goedece0bfa52009-01-07 16:37:28 +01001627 mutex_lock(&data->update_lock);
Hans de Goedebc274902009-01-07 16:37:29 +01001628 if (nr & 1)
1629 temp_max_hyst = data->temp_hyst[nr / 2] >> 4;
1630 else
1631 temp_max_hyst = data->temp_hyst[nr / 2] & 0x0f;
1632 temp_max_hyst = (data->temp_high[nr] - temp_max_hyst) * 1000;
Hans de Goedece0bfa52009-01-07 16:37:28 +01001633 mutex_unlock(&data->update_lock);
1634
1635 return sprintf(buf, "%d\n", temp_max_hyst);
Hans de Goede45fb3662007-07-13 14:34:19 +02001636}
1637
1638static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
1639 *devattr, const char *buf, size_t count)
1640{
1641 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001642 int err, nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001643 ssize_t ret = count;
Hans de Goedece0bfa52009-01-07 16:37:28 +01001644 u8 reg;
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001645 long val;
1646
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001647 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001648 if (err)
1649 return err;
1650
1651 val /= 1000;
Hans de Goede45fb3662007-07-13 14:34:19 +02001652
1653 mutex_lock(&data->update_lock);
1654
1655 /* convert abs to relative and check */
Hans de Goedece0bfa52009-01-07 16:37:28 +01001656 data->temp_high[nr] = f71882fg_read8(data, F71882FG_REG_TEMP_HIGH(nr));
Guenter Roeck2a844c12013-01-09 08:09:34 -08001657 val = clamp_val(val, data->temp_high[nr] - 15, data->temp_high[nr]);
Hans de Goede45fb3662007-07-13 14:34:19 +02001658 val = data->temp_high[nr] - val;
Hans de Goede45fb3662007-07-13 14:34:19 +02001659
1660 /* convert value to register contents */
Hans de Goedebc274902009-01-07 16:37:29 +01001661 reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST(nr / 2));
1662 if (nr & 1)
1663 reg = (reg & 0x0f) | (val << 4);
1664 else
1665 reg = (reg & 0xf0) | val;
1666 f71882fg_write8(data, F71882FG_REG_TEMP_HYST(nr / 2), reg);
1667 data->temp_hyst[nr / 2] = reg;
Hans de Goede45fb3662007-07-13 14:34:19 +02001668
Hans de Goede45fb3662007-07-13 14:34:19 +02001669 mutex_unlock(&data->update_lock);
1670 return ret;
1671}
1672
1673static ssize_t show_temp_crit(struct device *dev, struct device_attribute
1674 *devattr, char *buf)
1675{
1676 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001677 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001678
1679 return sprintf(buf, "%d\n", data->temp_ovt[nr] * 1000);
1680}
1681
1682static ssize_t store_temp_crit(struct device *dev, struct device_attribute
1683 *devattr, const char *buf, size_t count)
1684{
1685 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001686 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1687 long val;
1688
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001689 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001690 if (err)
1691 return err;
1692
1693 val /= 1000;
Guenter Roeck2a844c12013-01-09 08:09:34 -08001694 val = clamp_val(val, 0, 255);
Hans de Goede45fb3662007-07-13 14:34:19 +02001695
1696 mutex_lock(&data->update_lock);
1697 f71882fg_write8(data, F71882FG_REG_TEMP_OVT(nr), val);
1698 data->temp_ovt[nr] = val;
1699 mutex_unlock(&data->update_lock);
1700
1701 return count;
1702}
1703
1704static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
1705 *devattr, char *buf)
1706{
1707 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001708 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goedece0bfa52009-01-07 16:37:28 +01001709 int temp_crit_hyst;
Hans de Goede45fb3662007-07-13 14:34:19 +02001710
Hans de Goedece0bfa52009-01-07 16:37:28 +01001711 mutex_lock(&data->update_lock);
Hans de Goedebc274902009-01-07 16:37:29 +01001712 if (nr & 1)
1713 temp_crit_hyst = data->temp_hyst[nr / 2] >> 4;
1714 else
1715 temp_crit_hyst = data->temp_hyst[nr / 2] & 0x0f;
1716 temp_crit_hyst = (data->temp_ovt[nr] - temp_crit_hyst) * 1000;
Hans de Goedece0bfa52009-01-07 16:37:28 +01001717 mutex_unlock(&data->update_lock);
1718
1719 return sprintf(buf, "%d\n", temp_crit_hyst);
Hans de Goede45fb3662007-07-13 14:34:19 +02001720}
1721
1722static ssize_t show_temp_type(struct device *dev, struct device_attribute
1723 *devattr, char *buf)
1724{
1725 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001726 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001727
1728 return sprintf(buf, "%d\n", data->temp_type[nr]);
1729}
1730
1731static ssize_t show_temp_beep(struct device *dev, struct device_attribute
1732 *devattr, char *buf)
1733{
1734 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001735 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001736
Hans de Goede7567a042009-01-07 16:37:28 +01001737 if (data->temp_beep & (1 << nr))
Hans de Goede45fb3662007-07-13 14:34:19 +02001738 return sprintf(buf, "1\n");
1739 else
1740 return sprintf(buf, "0\n");
1741}
1742
1743static ssize_t store_temp_beep(struct device *dev, struct device_attribute
1744 *devattr, const char *buf, size_t count)
1745{
1746 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001747 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1748 unsigned long val;
1749
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001750 err = kstrtoul(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001751 if (err)
1752 return err;
Hans de Goede45fb3662007-07-13 14:34:19 +02001753
1754 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01001755 data->temp_beep = f71882fg_read8(data, F71882FG_REG_TEMP_BEEP);
Hans de Goede45fb3662007-07-13 14:34:19 +02001756 if (val)
Hans de Goede7567a042009-01-07 16:37:28 +01001757 data->temp_beep |= 1 << nr;
Hans de Goede45fb3662007-07-13 14:34:19 +02001758 else
Hans de Goede7567a042009-01-07 16:37:28 +01001759 data->temp_beep &= ~(1 << nr);
Hans de Goede45fb3662007-07-13 14:34:19 +02001760
1761 f71882fg_write8(data, F71882FG_REG_TEMP_BEEP, data->temp_beep);
1762 mutex_unlock(&data->update_lock);
1763
1764 return count;
1765}
1766
1767static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
1768 *devattr, char *buf)
1769{
1770 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001771 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001772
Hans de Goede7567a042009-01-07 16:37:28 +01001773 if (data->temp_status & (1 << nr))
Hans de Goede45fb3662007-07-13 14:34:19 +02001774 return sprintf(buf, "1\n");
1775 else
1776 return sprintf(buf, "0\n");
1777}
1778
1779static ssize_t show_temp_fault(struct device *dev, struct device_attribute
1780 *devattr, char *buf)
1781{
1782 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001783 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001784
Hans de Goede7567a042009-01-07 16:37:28 +01001785 if (data->temp_diode_open & (1 << nr))
Hans de Goede45fb3662007-07-13 14:34:19 +02001786 return sprintf(buf, "1\n");
1787 else
1788 return sprintf(buf, "0\n");
1789}
1790
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001791static ssize_t show_pwm(struct device *dev,
1792 struct device_attribute *devattr, char *buf)
1793{
1794 struct f71882fg_data *data = f71882fg_update_device(dev);
1795 int val, nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goedece0bfa52009-01-07 16:37:28 +01001796 mutex_lock(&data->update_lock);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001797 if (data->pwm_enable & (1 << (2 * nr)))
1798 /* PWM mode */
1799 val = data->pwm[nr];
1800 else {
1801 /* RPM mode */
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001802 val = 255 * fan_from_reg(data->fan_target[nr])
1803 / fan_from_reg(data->fan_full_speed[nr]);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001804 }
Hans de Goedece0bfa52009-01-07 16:37:28 +01001805 mutex_unlock(&data->update_lock);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001806 return sprintf(buf, "%d\n", val);
1807}
1808
1809static ssize_t store_pwm(struct device *dev,
1810 struct device_attribute *devattr, const char *buf,
1811 size_t count)
1812{
Hans de Goedece0bfa52009-01-07 16:37:28 +01001813 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001814 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1815 long val;
1816
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001817 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001818 if (err)
1819 return err;
1820
Guenter Roeck2a844c12013-01-09 08:09:34 -08001821 val = clamp_val(val, 0, 255);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001822
1823 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01001824 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001825 if ((data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 3) != 2) ||
1826 (data->type != f8000 && !((data->pwm_enable >> 2 * nr) & 2))) {
1827 count = -EROFS;
1828 goto leave;
1829 }
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001830 if (data->pwm_enable & (1 << (2 * nr))) {
1831 /* PWM mode */
1832 f71882fg_write8(data, F71882FG_REG_PWM(nr), val);
1833 data->pwm[nr] = val;
1834 } else {
1835 /* RPM mode */
Hans de Goedece0bfa52009-01-07 16:37:28 +01001836 int target, full_speed;
1837 full_speed = f71882fg_read16(data,
1838 F71882FG_REG_FAN_FULL_SPEED(nr));
1839 target = fan_to_reg(val * fan_from_reg(full_speed) / 255);
1840 f71882fg_write16(data, F71882FG_REG_FAN_TARGET(nr), target);
1841 data->fan_target[nr] = target;
1842 data->fan_full_speed[nr] = full_speed;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001843 }
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001844leave:
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001845 mutex_unlock(&data->update_lock);
1846
1847 return count;
1848}
1849
Hans de Goede629c58b2011-05-25 20:43:32 +02001850static ssize_t show_simple_pwm(struct device *dev,
1851 struct device_attribute *devattr, char *buf)
1852{
1853 struct f71882fg_data *data = f71882fg_update_device(dev);
1854 int val, nr = to_sensor_dev_attr_2(devattr)->index;
1855
1856 val = data->pwm[nr];
1857 return sprintf(buf, "%d\n", val);
1858}
1859
1860static ssize_t store_simple_pwm(struct device *dev,
1861 struct device_attribute *devattr,
1862 const char *buf, size_t count)
1863{
1864 struct f71882fg_data *data = dev_get_drvdata(dev);
1865 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1866 long val;
1867
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001868 err = kstrtol(buf, 10, &val);
Hans de Goede629c58b2011-05-25 20:43:32 +02001869 if (err)
1870 return err;
1871
Guenter Roeck2a844c12013-01-09 08:09:34 -08001872 val = clamp_val(val, 0, 255);
Hans de Goede629c58b2011-05-25 20:43:32 +02001873
1874 mutex_lock(&data->update_lock);
1875 f71882fg_write8(data, F71882FG_REG_PWM(nr), val);
1876 data->pwm[nr] = val;
1877 mutex_unlock(&data->update_lock);
1878
1879 return count;
1880}
1881
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001882static ssize_t show_pwm_enable(struct device *dev,
1883 struct device_attribute *devattr, char *buf)
1884{
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001885 int result = 0;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001886 struct f71882fg_data *data = f71882fg_update_device(dev);
1887 int nr = to_sensor_dev_attr_2(devattr)->index;
1888
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001889 switch ((data->pwm_enable >> 2 * nr) & 3) {
1890 case 0:
1891 case 1:
1892 result = 2; /* Normal auto mode */
1893 break;
1894 case 2:
1895 result = 1; /* Manual mode */
1896 break;
1897 case 3:
1898 if (data->type == f8000)
1899 result = 3; /* Thermostat mode */
1900 else
1901 result = 1; /* Manual mode */
1902 break;
1903 }
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001904
1905 return sprintf(buf, "%d\n", result);
1906}
1907
1908static ssize_t store_pwm_enable(struct device *dev, struct device_attribute
1909 *devattr, const char *buf, size_t count)
1910{
1911 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001912 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1913 long val;
1914
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001915 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001916 if (err)
1917 return err;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001918
Hans de Goede3fc78382009-06-15 18:39:50 +02001919 /* Special case for F8000 pwm channel 3 which only does auto mode */
1920 if (data->type == f8000 && nr == 2 && val != 2)
1921 return -EINVAL;
1922
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001923 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01001924 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001925 /* Special case for F8000 auto PWM mode / Thermostat mode */
1926 if (data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 1)) {
1927 switch (val) {
1928 case 2:
1929 data->pwm_enable &= ~(2 << (2 * nr));
1930 break; /* Normal auto mode */
1931 case 3:
1932 data->pwm_enable |= 2 << (2 * nr);
1933 break; /* Thermostat mode */
1934 default:
1935 count = -EINVAL;
1936 goto leave;
1937 }
1938 } else {
1939 switch (val) {
1940 case 1:
Hans de Goede09475d32009-06-15 18:39:52 +02001941 /* The f71858fg does not support manual RPM mode */
1942 if (data->type == f71858fg &&
1943 ((data->pwm_enable >> (2 * nr)) & 1)) {
1944 count = -EINVAL;
1945 goto leave;
1946 }
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001947 data->pwm_enable |= 2 << (2 * nr);
1948 break; /* Manual */
1949 case 2:
1950 data->pwm_enable &= ~(2 << (2 * nr));
1951 break; /* Normal auto mode */
1952 default:
1953 count = -EINVAL;
1954 goto leave;
1955 }
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001956 }
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001957 f71882fg_write8(data, F71882FG_REG_PWM_ENABLE, data->pwm_enable);
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001958leave:
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001959 mutex_unlock(&data->update_lock);
1960
1961 return count;
1962}
1963
1964static ssize_t show_pwm_auto_point_pwm(struct device *dev,
1965 struct device_attribute *devattr,
1966 char *buf)
1967{
1968 int result;
1969 struct f71882fg_data *data = f71882fg_update_device(dev);
1970 int pwm = to_sensor_dev_attr_2(devattr)->index;
1971 int point = to_sensor_dev_attr_2(devattr)->nr;
1972
Hans de Goedece0bfa52009-01-07 16:37:28 +01001973 mutex_lock(&data->update_lock);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001974 if (data->pwm_enable & (1 << (2 * pwm))) {
1975 /* PWM mode */
1976 result = data->pwm_auto_point_pwm[pwm][point];
1977 } else {
1978 /* RPM mode */
1979 result = 32 * 255 / (32 + data->pwm_auto_point_pwm[pwm][point]);
1980 }
Hans de Goedece0bfa52009-01-07 16:37:28 +01001981 mutex_unlock(&data->update_lock);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001982
1983 return sprintf(buf, "%d\n", result);
1984}
1985
1986static ssize_t store_pwm_auto_point_pwm(struct device *dev,
1987 struct device_attribute *devattr,
1988 const char *buf, size_t count)
1989{
Hans de Goedece0bfa52009-01-07 16:37:28 +01001990 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001991 int err, pwm = to_sensor_dev_attr_2(devattr)->index;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001992 int point = to_sensor_dev_attr_2(devattr)->nr;
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001993 long val;
1994
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001995 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001996 if (err)
1997 return err;
1998
Guenter Roeck2a844c12013-01-09 08:09:34 -08001999 val = clamp_val(val, 0, 255);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002000
2001 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01002002 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002003 if (data->pwm_enable & (1 << (2 * pwm))) {
2004 /* PWM mode */
2005 } else {
2006 /* RPM mode */
2007 if (val < 29) /* Prevent negative numbers */
2008 val = 255;
2009 else
2010 val = (255 - val) * 32 / val;
2011 }
2012 f71882fg_write8(data, F71882FG_REG_POINT_PWM(pwm, point), val);
2013 data->pwm_auto_point_pwm[pwm][point] = val;
2014 mutex_unlock(&data->update_lock);
2015
2016 return count;
2017}
2018
2019static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
2020 struct device_attribute *devattr,
2021 char *buf)
2022{
2023 int result = 0;
2024 struct f71882fg_data *data = f71882fg_update_device(dev);
2025 int nr = to_sensor_dev_attr_2(devattr)->index;
2026 int point = to_sensor_dev_attr_2(devattr)->nr;
2027
2028 mutex_lock(&data->update_lock);
Hans de Goedebc274902009-01-07 16:37:29 +01002029 if (nr & 1)
2030 result = data->pwm_auto_point_hyst[nr / 2] >> 4;
2031 else
2032 result = data->pwm_auto_point_hyst[nr / 2] & 0x0f;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002033 result = 1000 * (data->pwm_auto_point_temp[nr][point] - result);
2034 mutex_unlock(&data->update_lock);
2035
2036 return sprintf(buf, "%d\n", result);
2037}
2038
2039static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
2040 struct device_attribute *devattr,
2041 const char *buf, size_t count)
2042{
Hans de Goedece0bfa52009-01-07 16:37:28 +01002043 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002044 int err, nr = to_sensor_dev_attr_2(devattr)->index;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002045 int point = to_sensor_dev_attr_2(devattr)->nr;
Hans de Goedebc274902009-01-07 16:37:29 +01002046 u8 reg;
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002047 long val;
2048
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01002049 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002050 if (err)
2051 return err;
2052
2053 val /= 1000;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002054
2055 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01002056 data->pwm_auto_point_temp[nr][point] =
2057 f71882fg_read8(data, F71882FG_REG_POINT_TEMP(nr, point));
Guenter Roeck2a844c12013-01-09 08:09:34 -08002058 val = clamp_val(val, data->pwm_auto_point_temp[nr][point] - 15,
2059 data->pwm_auto_point_temp[nr][point]);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002060 val = data->pwm_auto_point_temp[nr][point] - val;
2061
Hans de Goedebc274902009-01-07 16:37:29 +01002062 reg = f71882fg_read8(data, F71882FG_REG_FAN_HYST(nr / 2));
2063 if (nr & 1)
2064 reg = (reg & 0x0f) | (val << 4);
2065 else
2066 reg = (reg & 0xf0) | val;
2067
2068 f71882fg_write8(data, F71882FG_REG_FAN_HYST(nr / 2), reg);
2069 data->pwm_auto_point_hyst[nr / 2] = reg;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002070 mutex_unlock(&data->update_lock);
2071
2072 return count;
2073}
2074
2075static ssize_t show_pwm_interpolate(struct device *dev,
2076 struct device_attribute *devattr, char *buf)
2077{
2078 int result;
2079 struct f71882fg_data *data = f71882fg_update_device(dev);
2080 int nr = to_sensor_dev_attr_2(devattr)->index;
2081
2082 result = (data->pwm_auto_point_mapping[nr] >> 4) & 1;
2083
2084 return sprintf(buf, "%d\n", result);
2085}
2086
2087static ssize_t store_pwm_interpolate(struct device *dev,
2088 struct device_attribute *devattr,
2089 const char *buf, size_t count)
2090{
Hans de Goedece0bfa52009-01-07 16:37:28 +01002091 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002092 int err, nr = to_sensor_dev_attr_2(devattr)->index;
2093 unsigned long val;
2094
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01002095 err = kstrtoul(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002096 if (err)
2097 return err;
Hans de Goedece0bfa52009-01-07 16:37:28 +01002098
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002099 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01002100 data->pwm_auto_point_mapping[nr] =
2101 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002102 if (val)
2103 val = data->pwm_auto_point_mapping[nr] | (1 << 4);
2104 else
2105 val = data->pwm_auto_point_mapping[nr] & (~(1 << 4));
2106 f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val);
2107 data->pwm_auto_point_mapping[nr] = val;
2108 mutex_unlock(&data->update_lock);
2109
2110 return count;
2111}
2112
2113static ssize_t show_pwm_auto_point_channel(struct device *dev,
2114 struct device_attribute *devattr,
2115 char *buf)
2116{
2117 int result;
2118 struct f71882fg_data *data = f71882fg_update_device(dev);
2119 int nr = to_sensor_dev_attr_2(devattr)->index;
2120
Hans de Goede09475d32009-06-15 18:39:52 +02002121 result = 1 << ((data->pwm_auto_point_mapping[nr] & 3) -
2122 data->temp_start);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002123
2124 return sprintf(buf, "%d\n", result);
2125}
2126
2127static ssize_t store_pwm_auto_point_channel(struct device *dev,
2128 struct device_attribute *devattr,
2129 const char *buf, size_t count)
2130{
Hans de Goedece0bfa52009-01-07 16:37:28 +01002131 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002132 int err, nr = to_sensor_dev_attr_2(devattr)->index;
2133 long val;
2134
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01002135 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002136 if (err)
2137 return err;
Hans de Goede30453012009-01-07 16:37:30 +01002138
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002139 switch (val) {
2140 case 1:
Hans de Goede30453012009-01-07 16:37:30 +01002141 val = 0;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002142 break;
2143 case 2:
Hans de Goede30453012009-01-07 16:37:30 +01002144 val = 1;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002145 break;
2146 case 4:
Hans de Goede30453012009-01-07 16:37:30 +01002147 val = 2;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002148 break;
2149 default:
2150 return -EINVAL;
2151 }
Hans de Goede09475d32009-06-15 18:39:52 +02002152 val += data->temp_start;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002153 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01002154 data->pwm_auto_point_mapping[nr] =
2155 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002156 val = (data->pwm_auto_point_mapping[nr] & 0xfc) | val;
2157 f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val);
2158 data->pwm_auto_point_mapping[nr] = val;
2159 mutex_unlock(&data->update_lock);
2160
2161 return count;
2162}
2163
2164static ssize_t show_pwm_auto_point_temp(struct device *dev,
2165 struct device_attribute *devattr,
2166 char *buf)
2167{
2168 int result;
2169 struct f71882fg_data *data = f71882fg_update_device(dev);
2170 int pwm = to_sensor_dev_attr_2(devattr)->index;
2171 int point = to_sensor_dev_attr_2(devattr)->nr;
2172
2173 result = data->pwm_auto_point_temp[pwm][point];
2174 return sprintf(buf, "%d\n", 1000 * result);
2175}
2176
2177static ssize_t store_pwm_auto_point_temp(struct device *dev,
2178 struct device_attribute *devattr,
2179 const char *buf, size_t count)
2180{
Hans de Goedece0bfa52009-01-07 16:37:28 +01002181 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002182 int err, pwm = to_sensor_dev_attr_2(devattr)->index;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002183 int point = to_sensor_dev_attr_2(devattr)->nr;
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002184 long val;
2185
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01002186 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002187 if (err)
2188 return err;
2189
2190 val /= 1000;
Hans de Goede76698962009-12-09 20:36:01 +01002191
Hans de Goede98f7ba12011-03-09 20:57:09 +01002192 if (data->auto_point_temp_signed)
Guenter Roeck2a844c12013-01-09 08:09:34 -08002193 val = clamp_val(val, -128, 127);
Hans de Goede76698962009-12-09 20:36:01 +01002194 else
Guenter Roeck2a844c12013-01-09 08:09:34 -08002195 val = clamp_val(val, 0, 127);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002196
2197 mutex_lock(&data->update_lock);
2198 f71882fg_write8(data, F71882FG_REG_POINT_TEMP(pwm, point), val);
2199 data->pwm_auto_point_temp[pwm][point] = val;
2200 mutex_unlock(&data->update_lock);
2201
2202 return count;
2203}
2204
Hans de Goede45fb3662007-07-13 14:34:19 +02002205static ssize_t show_name(struct device *dev, struct device_attribute *devattr,
2206 char *buf)
2207{
Hans de Goede498be962009-01-07 16:37:28 +01002208 struct f71882fg_data *data = dev_get_drvdata(dev);
2209 return sprintf(buf, "%s\n", f71882fg_names[data->type]);
Hans de Goede45fb3662007-07-13 14:34:19 +02002210}
2211
Bill Pemberton6c931ae2012-11-19 13:22:35 -05002212static int f71882fg_create_sysfs_files(struct platform_device *pdev,
Hans de Goedec13548c2009-01-07 16:37:27 +01002213 struct sensor_device_attribute_2 *attr, int count)
2214{
2215 int err, i;
Hans de Goede45fb3662007-07-13 14:34:19 +02002216
Hans de Goedec13548c2009-01-07 16:37:27 +01002217 for (i = 0; i < count; i++) {
2218 err = device_create_file(&pdev->dev, &attr[i].dev_attr);
2219 if (err)
2220 return err;
2221 }
2222 return 0;
2223}
2224
Hans de Goedefc16c562009-12-09 20:36:01 +01002225static void f71882fg_remove_sysfs_files(struct platform_device *pdev,
2226 struct sensor_device_attribute_2 *attr, int count)
2227{
2228 int i;
2229
2230 for (i = 0; i < count; i++)
2231 device_remove_file(&pdev->dev, &attr[i].dev_attr);
2232}
2233
Bill Pemberton6c931ae2012-11-19 13:22:35 -05002234static int f71882fg_create_fan_sysfs_files(
Hans de Goede65434392011-09-09 12:12:35 +02002235 struct platform_device *pdev, int idx)
Hans de Goede9af07942011-09-09 12:12:34 +02002236{
2237 struct f71882fg_data *data = platform_get_drvdata(pdev);
2238 int err;
2239
Hans de Goede65434392011-09-09 12:12:35 +02002240 /* Sanity check the pwm setting */
2241 err = 0;
2242 switch (data->type) {
2243 case f71858fg:
2244 if (((data->pwm_enable >> (idx * 2)) & 3) == 3)
2245 err = 1;
2246 break;
2247 case f71862fg:
2248 if (((data->pwm_enable >> (idx * 2)) & 1) != 1)
2249 err = 1;
2250 break;
2251 case f8000:
2252 if (idx == 2)
2253 err = data->pwm_enable & 0x20;
2254 break;
2255 default:
2256 break;
2257 }
2258 if (err) {
2259 dev_err(&pdev->dev,
2260 "Invalid (reserved) pwm settings: 0x%02x, "
2261 "skipping fan %d\n",
2262 (data->pwm_enable >> (idx * 2)) & 3, idx + 1);
2263 return 0; /* This is a non fatal condition */
2264 }
2265
Hans de Goede9af07942011-09-09 12:12:34 +02002266 err = f71882fg_create_sysfs_files(pdev, &fxxxx_fan_attr[idx][0],
2267 ARRAY_SIZE(fxxxx_fan_attr[0]));
2268 if (err)
2269 return err;
2270
2271 if (f71882fg_fan_has_beep[data->type]) {
2272 err = f71882fg_create_sysfs_files(pdev,
2273 &fxxxx_fan_beep_attr[idx],
2274 1);
2275 if (err)
2276 return err;
2277 }
2278
Hans de Goede65434392011-09-09 12:12:35 +02002279 dev_info(&pdev->dev, "Fan: %d is in %s mode\n", idx + 1,
2280 (data->pwm_enable & (1 << (2 * idx))) ? "duty-cycle" : "RPM");
2281
2282 /* Check for unsupported auto pwm settings */
2283 switch (data->type) {
2284 case f71808e:
2285 case f71808a:
2286 case f71869:
2287 case f71869a:
2288 case f71889fg:
2289 case f71889ed:
2290 case f71889a:
2291 data->pwm_auto_point_mapping[idx] =
2292 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(idx));
2293 if ((data->pwm_auto_point_mapping[idx] & 0x80) ||
2294 (data->pwm_auto_point_mapping[idx] & 3) == 0) {
2295 dev_warn(&pdev->dev,
2296 "Auto pwm controlled by raw digital "
2297 "data, disabling pwm auto_point "
2298 "sysfs attributes for fan %d\n", idx + 1);
2299 return 0; /* This is a non fatal condition */
2300 }
2301 break;
2302 default:
2303 break;
2304 }
Hans de Goede9af07942011-09-09 12:12:34 +02002305
2306 switch (data->type) {
2307 case f71862fg:
2308 err = f71882fg_create_sysfs_files(pdev,
2309 &f71862fg_auto_pwm_attr[idx][0],
2310 ARRAY_SIZE(f71862fg_auto_pwm_attr[0]));
2311 break;
2312 case f71808e:
2313 case f71869:
2314 err = f71882fg_create_sysfs_files(pdev,
2315 &f71869_auto_pwm_attr[idx][0],
2316 ARRAY_SIZE(f71869_auto_pwm_attr[0]));
2317 break;
2318 case f8000:
2319 err = f71882fg_create_sysfs_files(pdev,
2320 &f8000_auto_pwm_attr[idx][0],
2321 ARRAY_SIZE(f8000_auto_pwm_attr[0]));
2322 break;
2323 default:
2324 err = f71882fg_create_sysfs_files(pdev,
2325 &fxxxx_auto_pwm_attr[idx][0],
2326 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]));
2327 }
2328
2329 return err;
2330}
2331
Bill Pemberton6c931ae2012-11-19 13:22:35 -05002332static int f71882fg_probe(struct platform_device *pdev)
Hans de Goede45fb3662007-07-13 14:34:19 +02002333{
2334 struct f71882fg_data *data;
Jingoo Hana8b3a3a2013-07-30 17:13:06 +09002335 struct f71882fg_sio_data *sio_data = dev_get_platdata(&pdev->dev);
Jean Delvaref27def02011-03-26 10:45:01 +01002336 int nr_fans = f71882fg_nr_fans[sio_data->type];
2337 int nr_temps = f71882fg_nr_temps[sio_data->type];
2338 int err, i;
Peter Hungdcd956f2015-07-07 16:22:37 +08002339 int size;
Hans de Goede98f7ba12011-03-09 20:57:09 +01002340 u8 start_reg, reg;
Hans de Goede45fb3662007-07-13 14:34:19 +02002341
Guenter Roeck33cd66e2012-06-02 09:58:05 -07002342 data = devm_kzalloc(&pdev->dev, sizeof(struct f71882fg_data),
2343 GFP_KERNEL);
Hans de Goedec13548c2009-01-07 16:37:27 +01002344 if (!data)
Hans de Goede45fb3662007-07-13 14:34:19 +02002345 return -ENOMEM;
2346
2347 data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start;
Hans de Goede498be962009-01-07 16:37:28 +01002348 data->type = sio_data->type;
Hans de Goede09475d32009-06-15 18:39:52 +02002349 data->temp_start =
Peter Hungdcd956f2015-07-07 16:22:37 +08002350 (data->type == f71858fg || data->type == f8000 ||
2351 data->type == f81866a) ? 0 : 1;
Hans de Goede45fb3662007-07-13 14:34:19 +02002352 mutex_init(&data->update_lock);
2353 platform_set_drvdata(pdev, data);
2354
Hans de Goede3cc74752009-01-07 16:37:28 +01002355 start_reg = f71882fg_read8(data, F71882FG_REG_START);
Hans de Goede12d66e82009-01-07 16:37:29 +01002356 if (start_reg & 0x04) {
2357 dev_warn(&pdev->dev, "Hardware monitor is powered down\n");
Guenter Roeck33cd66e2012-06-02 09:58:05 -07002358 return -ENODEV;
Hans de Goede12d66e82009-01-07 16:37:29 +01002359 }
Hans de Goede3cc74752009-01-07 16:37:28 +01002360 if (!(start_reg & 0x03)) {
2361 dev_warn(&pdev->dev, "Hardware monitoring not activated\n");
Guenter Roeck33cd66e2012-06-02 09:58:05 -07002362 return -ENODEV;
Hans de Goede3cc74752009-01-07 16:37:28 +01002363 }
2364
Hans de Goede45fb3662007-07-13 14:34:19 +02002365 /* Register sysfs interface files */
Hans de Goedec13548c2009-01-07 16:37:27 +01002366 err = device_create_file(&pdev->dev, &dev_attr_name);
2367 if (err)
2368 goto exit_unregister_sysfs;
2369
Hans de Goedec13548c2009-01-07 16:37:27 +01002370 if (start_reg & 0x01) {
Hans de Goedeed4f7c22009-01-07 16:37:30 +01002371 switch (data->type) {
Hans de Goede09475d32009-06-15 18:39:52 +02002372 case f71858fg:
2373 data->temp_config =
2374 f71882fg_read8(data, F71882FG_REG_TEMP_CONFIG);
2375 if (data->temp_config & 0x10)
Guenter Roeck20eaf722012-01-19 11:02:17 -08002376 /*
2377 * The f71858fg temperature alarms behave as
2378 * the f8000 alarms in this mode
2379 */
Hans de Goede09475d32009-06-15 18:39:52 +02002380 err = f71882fg_create_sysfs_files(pdev,
Hans de Goede0bae6402011-03-09 20:57:10 +01002381 f8000_temp_attr,
2382 ARRAY_SIZE(f8000_temp_attr));
Hans de Goede09475d32009-06-15 18:39:52 +02002383 else
2384 err = f71882fg_create_sysfs_files(pdev,
Hans de Goede0bae6402011-03-09 20:57:10 +01002385 f71858fg_temp_attr,
2386 ARRAY_SIZE(f71858fg_temp_attr));
Hans de Goede09475d32009-06-15 18:39:52 +02002387 break;
Hans de Goede0bae6402011-03-09 20:57:10 +01002388 case f8000:
2389 err = f71882fg_create_sysfs_files(pdev,
2390 f8000_temp_attr,
2391 ARRAY_SIZE(f8000_temp_attr));
2392 break;
Peter Hungdcd956f2015-07-07 16:22:37 +08002393 case f81866a:
2394 err = f71882fg_create_sysfs_files(pdev,
2395 f71858fg_temp_attr,
2396 ARRAY_SIZE(f71858fg_temp_attr));
2397 break;
Hans de Goede0bae6402011-03-09 20:57:10 +01002398 default:
2399 err = f71882fg_create_sysfs_files(pdev,
Hans de Goede60d2b372011-03-09 20:57:11 +01002400 &fxxxx_temp_attr[0][0],
2401 ARRAY_SIZE(fxxxx_temp_attr[0]) * nr_temps);
Hans de Goede0bae6402011-03-09 20:57:10 +01002402 }
2403 if (err)
2404 goto exit_unregister_sysfs;
2405
Hans de Goede4d538112011-05-25 20:43:32 +02002406 if (f71882fg_temp_has_beep[data->type]) {
Peter Hungdcd956f2015-07-07 16:22:37 +08002407 if (data->type == f81866a) {
2408 size = ARRAY_SIZE(f81866_temp_beep_attr[0]);
2409 err = f71882fg_create_sysfs_files(pdev,
2410 &f81866_temp_beep_attr[0][0],
2411 size * nr_temps);
2412
2413 } else {
2414 size = ARRAY_SIZE(fxxxx_temp_beep_attr[0]);
2415 err = f71882fg_create_sysfs_files(pdev,
2416 &fxxxx_temp_beep_attr[0][0],
2417 size * nr_temps);
2418 }
Hans de Goede78aa4f72011-03-09 20:57:12 +01002419 if (err)
2420 goto exit_unregister_sysfs;
2421 }
2422
Hans de Goede0bae6402011-03-09 20:57:10 +01002423 for (i = 0; i < F71882FG_MAX_INS; i++) {
2424 if (f71882fg_has_in[data->type][i]) {
2425 err = device_create_file(&pdev->dev,
2426 &fxxxx_in_attr[i].dev_attr);
2427 if (err)
2428 goto exit_unregister_sysfs;
2429 }
2430 }
2431 if (f71882fg_has_in1_alarm[data->type]) {
Hans de Goede498be962009-01-07 16:37:28 +01002432 err = f71882fg_create_sysfs_files(pdev,
Hans de Goede66344aa2009-12-09 20:35:59 +01002433 fxxxx_in1_alarm_attr,
2434 ARRAY_SIZE(fxxxx_in1_alarm_attr));
Hans de Goede498be962009-01-07 16:37:28 +01002435 if (err)
2436 goto exit_unregister_sysfs;
2437 }
Hans de Goede45fb3662007-07-13 14:34:19 +02002438 }
2439
Hans de Goede45fb3662007-07-13 14:34:19 +02002440 if (start_reg & 0x02) {
Hans de Goede98f7ba12011-03-09 20:57:09 +01002441 switch (data->type) {
Hans de Goedee5e713c2011-03-10 08:54:02 +01002442 case f71808e:
Hans de Goede629c58b2011-05-25 20:43:32 +02002443 case f71808a:
Hans de Goedec11bb992011-03-09 20:57:15 +01002444 case f71869:
Hans de Goede5da556e2011-07-03 13:32:53 +02002445 case f71869a:
Hans de Goedee5e713c2011-03-10 08:54:02 +01002446 /* These always have signed auto point temps */
Hans de Goedec11bb992011-03-09 20:57:15 +01002447 data->auto_point_temp_signed = 1;
2448 /* Fall through to select correct fan/pwm reg bank! */
Hans de Goede98f7ba12011-03-09 20:57:09 +01002449 case f71889fg:
Hans de Goede3cad4022011-03-09 20:57:14 +01002450 case f71889ed:
Hans de Goedea66c1082011-03-26 10:45:02 +01002451 case f71889a:
Hans de Goede98f7ba12011-03-09 20:57:09 +01002452 reg = f71882fg_read8(data, F71882FG_REG_FAN_FAULT_T);
2453 if (reg & F71882FG_FAN_NEG_TEMP_EN)
2454 data->auto_point_temp_signed = 1;
Hans de Goede3cad4022011-03-09 20:57:14 +01002455 /* Ensure banked pwm registers point to right bank */
2456 reg &= ~F71882FG_FAN_PROG_SEL;
2457 f71882fg_write8(data, F71882FG_REG_FAN_FAULT_T, reg);
Hans de Goede98f7ba12011-03-09 20:57:09 +01002458 break;
2459 default:
2460 break;
2461 }
2462
Hans de Goede996cadb2009-06-15 18:39:51 +02002463 data->pwm_enable =
2464 f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
2465
Hans de Goede9af07942011-09-09 12:12:34 +02002466 for (i = 0; i < nr_fans; i++) {
Hans de Goede65434392011-09-09 12:12:35 +02002467 err = f71882fg_create_fan_sysfs_files(pdev, i);
Hans de Goede9af07942011-09-09 12:12:34 +02002468 if (err)
2469 goto exit_unregister_sysfs;
Hans de Goede9af07942011-09-09 12:12:34 +02002470 }
2471
2472 /* Some types have 1 extra fan with limited functionality */
Hans de Goedee48a7f12011-03-09 20:57:13 +01002473 switch (data->type) {
Hans de Goede629c58b2011-05-25 20:43:32 +02002474 case f71808a:
2475 err = f71882fg_create_sysfs_files(pdev,
Hans de Goede629c58b2011-05-25 20:43:32 +02002476 f71808a_fan3_attr,
2477 ARRAY_SIZE(f71808a_fan3_attr));
2478 break;
Hans de Goedeed4f7c22009-01-07 16:37:30 +01002479 case f8000:
2480 err = f71882fg_create_sysfs_files(pdev,
2481 f8000_fan_attr,
2482 ARRAY_SIZE(f8000_fan_attr));
2483 break;
Hans de Goedee48a7f12011-03-09 20:57:13 +01002484 default:
Hans de Goede9af07942011-09-09 12:12:34 +02002485 break;
Hans de Goede498be962009-01-07 16:37:28 +01002486 }
Hans de Goedec13548c2009-01-07 16:37:27 +01002487 if (err)
2488 goto exit_unregister_sysfs;
Hans de Goede45fb3662007-07-13 14:34:19 +02002489 }
2490
Tony Jones1beeffe2007-08-20 13:46:20 -07002491 data->hwmon_dev = hwmon_device_register(&pdev->dev);
2492 if (IS_ERR(data->hwmon_dev)) {
2493 err = PTR_ERR(data->hwmon_dev);
Hans de Goedec13548c2009-01-07 16:37:27 +01002494 data->hwmon_dev = NULL;
Hans de Goede45fb3662007-07-13 14:34:19 +02002495 goto exit_unregister_sysfs;
2496 }
2497
2498 return 0;
2499
2500exit_unregister_sysfs:
Hans de Goedec13548c2009-01-07 16:37:27 +01002501 f71882fg_remove(pdev); /* Will unregister the sysfs files for us */
Hans de Goede3cc74752009-01-07 16:37:28 +01002502 return err; /* f71882fg_remove() also frees our data */
Hans de Goede45fb3662007-07-13 14:34:19 +02002503}
2504
Hans de Goedec13548c2009-01-07 16:37:27 +01002505static int f71882fg_remove(struct platform_device *pdev)
Hans de Goede45fb3662007-07-13 14:34:19 +02002506{
Hans de Goede45fb3662007-07-13 14:34:19 +02002507 struct f71882fg_data *data = platform_get_drvdata(pdev);
Jean Delvaref27def02011-03-26 10:45:01 +01002508 int nr_fans = f71882fg_nr_fans[data->type];
2509 int nr_temps = f71882fg_nr_temps[data->type];
2510 int i;
Hans de Goedefc16c562009-12-09 20:36:01 +01002511 u8 start_reg = f71882fg_read8(data, F71882FG_REG_START);
Hans de Goede45fb3662007-07-13 14:34:19 +02002512
Hans de Goedec13548c2009-01-07 16:37:27 +01002513 if (data->hwmon_dev)
2514 hwmon_device_unregister(data->hwmon_dev);
Hans de Goede45fb3662007-07-13 14:34:19 +02002515
Hans de Goedec13548c2009-01-07 16:37:27 +01002516 device_remove_file(&pdev->dev, &dev_attr_name);
Hans de Goede45fb3662007-07-13 14:34:19 +02002517
Hans de Goedefc16c562009-12-09 20:36:01 +01002518 if (start_reg & 0x01) {
2519 switch (data->type) {
2520 case f71858fg:
2521 if (data->temp_config & 0x10)
2522 f71882fg_remove_sysfs_files(pdev,
Hans de Goede0bae6402011-03-09 20:57:10 +01002523 f8000_temp_attr,
2524 ARRAY_SIZE(f8000_temp_attr));
Hans de Goedefc16c562009-12-09 20:36:01 +01002525 else
2526 f71882fg_remove_sysfs_files(pdev,
Hans de Goede0bae6402011-03-09 20:57:10 +01002527 f71858fg_temp_attr,
2528 ARRAY_SIZE(f71858fg_temp_attr));
Hans de Goedefc16c562009-12-09 20:36:01 +01002529 break;
2530 case f8000:
2531 f71882fg_remove_sysfs_files(pdev,
Hans de Goede0bae6402011-03-09 20:57:10 +01002532 f8000_temp_attr,
2533 ARRAY_SIZE(f8000_temp_attr));
Hans de Goedefc16c562009-12-09 20:36:01 +01002534 break;
Peter Hungdcd956f2015-07-07 16:22:37 +08002535 case f81866a:
2536 f71882fg_remove_sysfs_files(pdev,
2537 f71858fg_temp_attr,
2538 ARRAY_SIZE(f71858fg_temp_attr));
2539 break;
Hans de Goede0bae6402011-03-09 20:57:10 +01002540 default:
2541 f71882fg_remove_sysfs_files(pdev,
Hans de Goede60d2b372011-03-09 20:57:11 +01002542 &fxxxx_temp_attr[0][0],
2543 ARRAY_SIZE(fxxxx_temp_attr[0]) * nr_temps);
Hans de Goede0bae6402011-03-09 20:57:10 +01002544 }
Hans de Goede4d538112011-05-25 20:43:32 +02002545 if (f71882fg_temp_has_beep[data->type]) {
Peter Hungdcd956f2015-07-07 16:22:37 +08002546 if (data->type == f81866a)
2547 f71882fg_remove_sysfs_files(pdev,
2548 &f81866_temp_beep_attr[0][0],
2549 ARRAY_SIZE(f81866_temp_beep_attr[0])
2550 * nr_temps);
2551 else
2552 f71882fg_remove_sysfs_files(pdev,
2553 &fxxxx_temp_beep_attr[0][0],
2554 ARRAY_SIZE(fxxxx_temp_beep_attr[0])
2555 * nr_temps);
Hans de Goede78aa4f72011-03-09 20:57:12 +01002556 }
2557
Hans de Goede0bae6402011-03-09 20:57:10 +01002558 for (i = 0; i < F71882FG_MAX_INS; i++) {
2559 if (f71882fg_has_in[data->type][i]) {
2560 device_remove_file(&pdev->dev,
2561 &fxxxx_in_attr[i].dev_attr);
2562 }
2563 }
2564 if (f71882fg_has_in1_alarm[data->type]) {
2565 f71882fg_remove_sysfs_files(pdev,
2566 fxxxx_in1_alarm_attr,
2567 ARRAY_SIZE(fxxxx_in1_alarm_attr));
Hans de Goedefc16c562009-12-09 20:36:01 +01002568 }
2569 }
Hans de Goede498be962009-01-07 16:37:28 +01002570
Hans de Goedefc16c562009-12-09 20:36:01 +01002571 if (start_reg & 0x02) {
2572 f71882fg_remove_sysfs_files(pdev, &fxxxx_fan_attr[0][0],
2573 ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans);
Hans de Goede45fb3662007-07-13 14:34:19 +02002574
Hans de Goede4d538112011-05-25 20:43:32 +02002575 if (f71882fg_fan_has_beep[data->type]) {
Hans de Goedefc16c562009-12-09 20:36:01 +01002576 f71882fg_remove_sysfs_files(pdev,
2577 fxxxx_fan_beep_attr, nr_fans);
Hans de Goede78aa4f72011-03-09 20:57:12 +01002578 }
Hans de Goede498be962009-01-07 16:37:28 +01002579
Hans de Goedefc16c562009-12-09 20:36:01 +01002580 switch (data->type) {
Hans de Goede629c58b2011-05-25 20:43:32 +02002581 case f71808a:
2582 f71882fg_remove_sysfs_files(pdev,
2583 &fxxxx_auto_pwm_attr[0][0],
2584 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
2585 f71882fg_remove_sysfs_files(pdev,
2586 f71808a_fan3_attr,
2587 ARRAY_SIZE(f71808a_fan3_attr));
2588 break;
Hans de Goedefc16c562009-12-09 20:36:01 +01002589 case f71862fg:
2590 f71882fg_remove_sysfs_files(pdev,
Hans de Goede55840142011-09-09 12:12:33 +02002591 &f71862fg_auto_pwm_attr[0][0],
2592 ARRAY_SIZE(f71862fg_auto_pwm_attr[0]) *
2593 nr_fans);
Hans de Goedefc16c562009-12-09 20:36:01 +01002594 break;
Hans de Goedee5e713c2011-03-10 08:54:02 +01002595 case f71808e:
Hans de Goedec11bb992011-03-09 20:57:15 +01002596 case f71869:
2597 f71882fg_remove_sysfs_files(pdev,
Hans de Goede55840142011-09-09 12:12:33 +02002598 &f71869_auto_pwm_attr[0][0],
2599 ARRAY_SIZE(f71869_auto_pwm_attr[0]) * nr_fans);
Hans de Goedec11bb992011-03-09 20:57:15 +01002600 break;
Hans de Goedefc16c562009-12-09 20:36:01 +01002601 case f8000:
2602 f71882fg_remove_sysfs_files(pdev,
2603 f8000_fan_attr,
2604 ARRAY_SIZE(f8000_fan_attr));
2605 f71882fg_remove_sysfs_files(pdev,
Hans de Goede55840142011-09-09 12:12:33 +02002606 &f8000_auto_pwm_attr[0][0],
2607 ARRAY_SIZE(f8000_auto_pwm_attr[0]) * nr_fans);
Hans de Goedefc16c562009-12-09 20:36:01 +01002608 break;
Hans de Goede3cad4022011-03-09 20:57:14 +01002609 default:
Hans de Goedefc16c562009-12-09 20:36:01 +01002610 f71882fg_remove_sysfs_files(pdev,
2611 &fxxxx_auto_pwm_attr[0][0],
2612 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
2613 }
2614 }
Hans de Goede45fb3662007-07-13 14:34:19 +02002615 return 0;
2616}
2617
Guenter Roeck00383892012-08-04 09:46:36 -07002618static int __init f71882fg_find(int sioaddr, struct f71882fg_sio_data *sio_data)
Hans de Goede45fb3662007-07-13 14:34:19 +02002619{
Hans de Goede45fb3662007-07-13 14:34:19 +02002620 u16 devid;
Guenter Roeck00383892012-08-04 09:46:36 -07002621 unsigned short address;
Giel van Schijndelcadb8652010-10-03 08:09:49 -04002622 int err = superio_enter(sioaddr);
2623 if (err)
2624 return err;
Hans de Goede45fb3662007-07-13 14:34:19 +02002625
2626 devid = superio_inw(sioaddr, SIO_REG_MANID);
2627 if (devid != SIO_FINTEK_ID) {
Joe Perches22d3b412010-10-20 06:51:34 +00002628 pr_debug("Not a Fintek device\n");
Giel van Schijndelcadb8652010-10-03 08:09:49 -04002629 err = -ENODEV;
Hans de Goede45fb3662007-07-13 14:34:19 +02002630 goto exit;
2631 }
2632
Jean Delvare67b671b2007-12-06 23:13:42 +01002633 devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID);
Hans de Goede498be962009-01-07 16:37:28 +01002634 switch (devid) {
Hans de Goedee5e713c2011-03-10 08:54:02 +01002635 case SIO_F71808E_ID:
2636 sio_data->type = f71808e;
2637 break;
Hans de Goede629c58b2011-05-25 20:43:32 +02002638 case SIO_F71808A_ID:
2639 sio_data->type = f71808a;
2640 break;
Hans de Goede09475d32009-06-15 18:39:52 +02002641 case SIO_F71858_ID:
2642 sio_data->type = f71858fg;
2643 break;
Hans de Goede498be962009-01-07 16:37:28 +01002644 case SIO_F71862_ID:
2645 sio_data->type = f71862fg;
2646 break;
Peter Hung2725fe22015-07-07 16:22:36 +08002647 case SIO_F71868_ID:
2648 sio_data->type = f71868a;
2649 break;
Hans de Goedec11bb992011-03-09 20:57:15 +01002650 case SIO_F71869_ID:
2651 sio_data->type = f71869;
2652 break;
Hans de Goede5da556e2011-07-03 13:32:53 +02002653 case SIO_F71869A_ID:
2654 sio_data->type = f71869a;
2655 break;
Hans de Goede498be962009-01-07 16:37:28 +01002656 case SIO_F71882_ID:
2657 sio_data->type = f71882fg;
2658 break;
Hans de Goede76698962009-12-09 20:36:01 +01002659 case SIO_F71889_ID:
2660 sio_data->type = f71889fg;
2661 break;
Hans de Goede3cad4022011-03-09 20:57:14 +01002662 case SIO_F71889E_ID:
2663 sio_data->type = f71889ed;
2664 break;
Hans de Goedea66c1082011-03-26 10:45:02 +01002665 case SIO_F71889A_ID:
2666 sio_data->type = f71889a;
2667 break;
Hans de Goedeed4f7c22009-01-07 16:37:30 +01002668 case SIO_F8000_ID:
2669 sio_data->type = f8000;
2670 break;
Jean Delvare383586b2011-03-26 10:45:02 +01002671 case SIO_F81865_ID:
2672 sio_data->type = f81865f;
2673 break;
Peter Hung2725fe22015-07-07 16:22:36 +08002674 case SIO_F81866_ID:
2675 sio_data->type = f81866a;
2676 break;
Hans de Goede498be962009-01-07 16:37:28 +01002677 default:
Joe Perches22d3b412010-10-20 06:51:34 +00002678 pr_info("Unsupported Fintek device: %04x\n",
2679 (unsigned int)devid);
Giel van Schijndelcadb8652010-10-03 08:09:49 -04002680 err = -ENODEV;
Hans de Goede45fb3662007-07-13 14:34:19 +02002681 goto exit;
2682 }
2683
Hans de Goede09475d32009-06-15 18:39:52 +02002684 if (sio_data->type == f71858fg)
2685 superio_select(sioaddr, SIO_F71858FG_LD_HWM);
2686 else
2687 superio_select(sioaddr, SIO_F71882FG_LD_HWM);
2688
Mark M. Hoffman8afb1042007-08-21 23:10:46 -04002689 if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) {
Joe Perches22d3b412010-10-20 06:51:34 +00002690 pr_warn("Device not activated\n");
Giel van Schijndelcadb8652010-10-03 08:09:49 -04002691 err = -ENODEV;
Hans de Goede45fb3662007-07-13 14:34:19 +02002692 goto exit;
2693 }
2694
Guenter Roeck00383892012-08-04 09:46:36 -07002695 address = superio_inw(sioaddr, SIO_REG_ADDR);
2696 if (address == 0) {
Joe Perches22d3b412010-10-20 06:51:34 +00002697 pr_warn("Base address not set\n");
Giel van Schijndelcadb8652010-10-03 08:09:49 -04002698 err = -ENODEV;
Hans de Goede45fb3662007-07-13 14:34:19 +02002699 goto exit;
2700 }
Guenter Roeck00383892012-08-04 09:46:36 -07002701 address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */
Hans de Goede45fb3662007-07-13 14:34:19 +02002702
Guenter Roeck00383892012-08-04 09:46:36 -07002703 err = address;
Joe Perches22d3b412010-10-20 06:51:34 +00002704 pr_info("Found %s chip at %#x, revision %d\n",
Guenter Roeck00383892012-08-04 09:46:36 -07002705 f71882fg_names[sio_data->type], (unsigned int)address,
Hans de Goede45fb3662007-07-13 14:34:19 +02002706 (int)superio_inb(sioaddr, SIO_REG_DEVREV));
2707exit:
2708 superio_exit(sioaddr);
2709 return err;
2710}
2711
Guenter Roeck00383892012-08-04 09:46:36 -07002712static int __init f71882fg_device_add(int address,
2713 const struct f71882fg_sio_data *sio_data)
Hans de Goede45fb3662007-07-13 14:34:19 +02002714{
2715 struct resource res = {
2716 .start = address,
2717 .end = address + REGION_LENGTH - 1,
2718 .flags = IORESOURCE_IO,
2719 };
2720 int err;
2721
2722 f71882fg_pdev = platform_device_alloc(DRVNAME, address);
Mark M. Hoffman8afb1042007-08-21 23:10:46 -04002723 if (!f71882fg_pdev)
Hans de Goede45fb3662007-07-13 14:34:19 +02002724 return -ENOMEM;
2725
2726 res.name = f71882fg_pdev->name;
Jean Delvareb9acb642009-01-07 16:37:35 +01002727 err = acpi_check_resource_conflict(&res);
2728 if (err)
Hans de Goede18632f82009-02-17 19:59:54 +01002729 goto exit_device_put;
Jean Delvareb9acb642009-01-07 16:37:35 +01002730
Hans de Goede45fb3662007-07-13 14:34:19 +02002731 err = platform_device_add_resources(f71882fg_pdev, &res, 1);
Mark M. Hoffman8afb1042007-08-21 23:10:46 -04002732 if (err) {
Joe Perches22d3b412010-10-20 06:51:34 +00002733 pr_err("Device resource addition failed\n");
Hans de Goede45fb3662007-07-13 14:34:19 +02002734 goto exit_device_put;
2735 }
2736
Hans de Goede498be962009-01-07 16:37:28 +01002737 err = platform_device_add_data(f71882fg_pdev, sio_data,
2738 sizeof(struct f71882fg_sio_data));
2739 if (err) {
Joe Perches22d3b412010-10-20 06:51:34 +00002740 pr_err("Platform data allocation failed\n");
Hans de Goede498be962009-01-07 16:37:28 +01002741 goto exit_device_put;
2742 }
2743
Hans de Goede45fb3662007-07-13 14:34:19 +02002744 err = platform_device_add(f71882fg_pdev);
Mark M. Hoffman8afb1042007-08-21 23:10:46 -04002745 if (err) {
Joe Perches22d3b412010-10-20 06:51:34 +00002746 pr_err("Device addition failed\n");
Hans de Goede45fb3662007-07-13 14:34:19 +02002747 goto exit_device_put;
2748 }
2749
2750 return 0;
2751
2752exit_device_put:
2753 platform_device_put(f71882fg_pdev);
2754
2755 return err;
2756}
2757
2758static int __init f71882fg_init(void)
2759{
Guenter Roeck00383892012-08-04 09:46:36 -07002760 int err;
2761 int address;
Hans de Goede498be962009-01-07 16:37:28 +01002762 struct f71882fg_sio_data sio_data;
Hans de Goede45fb3662007-07-13 14:34:19 +02002763
Hans de Goede498be962009-01-07 16:37:28 +01002764 memset(&sio_data, 0, sizeof(sio_data));
2765
Guenter Roeck00383892012-08-04 09:46:36 -07002766 address = f71882fg_find(0x2e, &sio_data);
2767 if (address < 0)
2768 address = f71882fg_find(0x4e, &sio_data);
2769 if (address < 0)
2770 return address;
Hans de Goede45fb3662007-07-13 14:34:19 +02002771
Hans de Goedec13548c2009-01-07 16:37:27 +01002772 err = platform_driver_register(&f71882fg_driver);
2773 if (err)
Guenter Roeck00383892012-08-04 09:46:36 -07002774 return err;
Hans de Goede45fb3662007-07-13 14:34:19 +02002775
Hans de Goede498be962009-01-07 16:37:28 +01002776 err = f71882fg_device_add(address, &sio_data);
Hans de Goedec13548c2009-01-07 16:37:27 +01002777 if (err)
Hans de Goede45fb3662007-07-13 14:34:19 +02002778 goto exit_driver;
2779
2780 return 0;
2781
2782exit_driver:
2783 platform_driver_unregister(&f71882fg_driver);
Hans de Goede45fb3662007-07-13 14:34:19 +02002784 return err;
2785}
2786
2787static void __exit f71882fg_exit(void)
2788{
2789 platform_device_unregister(f71882fg_pdev);
2790 platform_driver_unregister(&f71882fg_driver);
2791}
2792
2793MODULE_DESCRIPTION("F71882FG Hardware Monitoring Driver");
Hans de Goede7958e3b2011-07-03 13:32:53 +02002794MODULE_AUTHOR("Hans Edgington, Hans de Goede <hdegoede@redhat.com>");
Hans de Goede45fb3662007-07-13 14:34:19 +02002795MODULE_LICENSE("GPL");
2796
2797module_init(f71882fg_init);
2798module_exit(f71882fg_exit);