blob: 2e5c6f46e4422b818ec8d91a33af971213a23074 [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 */
Hans de Goedec11bb992011-03-09 20:57:15 +010054#define SIO_F71869_ID 0x0814 /* Chipset ID */
Hans de Goede5da556e2011-07-03 13:32:53 +020055#define SIO_F71869A_ID 0x1007 /* Chipset ID */
Hans de Goede45fb3662007-07-13 14:34:19 +020056#define SIO_F71882_ID 0x0541 /* Chipset ID */
Hans de Goede76698962009-12-09 20:36:01 +010057#define SIO_F71889_ID 0x0723 /* Chipset ID */
Hans de Goede3cad4022011-03-09 20:57:14 +010058#define SIO_F71889E_ID 0x0909 /* Chipset ID */
Hans de Goedea66c1082011-03-26 10:45:02 +010059#define SIO_F71889A_ID 0x1005 /* Chipset ID */
Hans de Goedeed4f7c22009-01-07 16:37:30 +010060#define SIO_F8000_ID 0x0581 /* Chipset ID */
Jean Delvare383586b2011-03-26 10:45:02 +010061#define SIO_F81865_ID 0x0704 /* Chipset ID */
Hans de Goede45fb3662007-07-13 14:34:19 +020062
63#define REGION_LENGTH 8
64#define ADDR_REG_OFFSET 5
65#define DATA_REG_OFFSET 6
66
Hans de Goede3cad4022011-03-09 20:57:14 +010067#define F71882FG_REG_IN_STATUS 0x12 /* f7188x only */
68#define F71882FG_REG_IN_BEEP 0x13 /* f7188x only */
Hans de Goede45fb3662007-07-13 14:34:19 +020069#define F71882FG_REG_IN(nr) (0x20 + (nr))
Hans de Goede3cad4022011-03-09 20:57:14 +010070#define F71882FG_REG_IN1_HIGH 0x32 /* f7188x only */
Hans de Goede45fb3662007-07-13 14:34:19 +020071
72#define F71882FG_REG_FAN(nr) (0xA0 + (16 * (nr)))
Mark van Doesburg9ab796e2009-01-07 16:37:27 +010073#define F71882FG_REG_FAN_TARGET(nr) (0xA2 + (16 * (nr)))
74#define F71882FG_REG_FAN_FULL_SPEED(nr) (0xA4 + (16 * (nr)))
Hans de Goede45fb3662007-07-13 14:34:19 +020075#define F71882FG_REG_FAN_STATUS 0x92
76#define F71882FG_REG_FAN_BEEP 0x93
77
Hans de Goede7567a042009-01-07 16:37:28 +010078#define F71882FG_REG_TEMP(nr) (0x70 + 2 * (nr))
79#define F71882FG_REG_TEMP_OVT(nr) (0x80 + 2 * (nr))
80#define F71882FG_REG_TEMP_HIGH(nr) (0x81 + 2 * (nr))
Hans de Goede45fb3662007-07-13 14:34:19 +020081#define F71882FG_REG_TEMP_STATUS 0x62
82#define F71882FG_REG_TEMP_BEEP 0x63
Hans de Goede09475d32009-06-15 18:39:52 +020083#define F71882FG_REG_TEMP_CONFIG 0x69
Hans de Goedebc274902009-01-07 16:37:29 +010084#define F71882FG_REG_TEMP_HYST(nr) (0x6C + (nr))
Hans de Goede45fb3662007-07-13 14:34:19 +020085#define F71882FG_REG_TEMP_TYPE 0x6B
86#define F71882FG_REG_TEMP_DIODE_OPEN 0x6F
87
Mark van Doesburg9ab796e2009-01-07 16:37:27 +010088#define F71882FG_REG_PWM(nr) (0xA3 + (16 * (nr)))
89#define F71882FG_REG_PWM_TYPE 0x94
90#define F71882FG_REG_PWM_ENABLE 0x96
91
Hans de Goedebc274902009-01-07 16:37:29 +010092#define F71882FG_REG_FAN_HYST(nr) (0x98 + (nr))
Mark van Doesburg9ab796e2009-01-07 16:37:27 +010093
Hans de Goede98f7ba12011-03-09 20:57:09 +010094#define F71882FG_REG_FAN_FAULT_T 0x9F
95#define F71882FG_FAN_NEG_TEMP_EN 0x20
Hans de Goede3cad4022011-03-09 20:57:14 +010096#define F71882FG_FAN_PROG_SEL 0x80
Hans de Goede98f7ba12011-03-09 20:57:09 +010097
Mark van Doesburg9ab796e2009-01-07 16:37:27 +010098#define F71882FG_REG_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm)))
99#define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm)))
100#define F71882FG_REG_POINT_MAPPING(nr) (0xAF + 16 * (nr))
101
Hans de Goede45fb3662007-07-13 14:34:19 +0200102#define F71882FG_REG_START 0x01
103
Hans de Goede0bae6402011-03-09 20:57:10 +0100104#define F71882FG_MAX_INS 9
105
Hans de Goede45fb3662007-07-13 14:34:19 +0200106#define FAN_MIN_DETECT 366 /* Lowest detectable fanspeed */
107
Jean Delvare67b671b2007-12-06 23:13:42 +0100108static unsigned short force_id;
109module_param(force_id, ushort, 0);
110MODULE_PARM_DESC(force_id, "Override the detected device ID");
111
Hans de Goede5da556e2011-07-03 13:32:53 +0200112enum chips { f71808e, f71808a, f71858fg, f71862fg, f71869, f71869a, f71882fg,
113 f71889fg, f71889ed, f71889a, f8000, f81865f };
Hans de Goede498be962009-01-07 16:37:28 +0100114
Frans Meulenbroeks1dc37082012-01-08 19:34:10 +0100115static const char *const f71882fg_names[] = {
Hans de Goedee5e713c2011-03-10 08:54:02 +0100116 "f71808e",
Hans de Goede629c58b2011-05-25 20:43:32 +0200117 "f71808a",
Hans de Goede09475d32009-06-15 18:39:52 +0200118 "f71858fg",
Hans de Goede498be962009-01-07 16:37:28 +0100119 "f71862fg",
Hans de Goedec11bb992011-03-09 20:57:15 +0100120 "f71869", /* Both f71869f and f71869e, reg. compatible and same id */
Hans de Goede5da556e2011-07-03 13:32:53 +0200121 "f71869a",
Hans de Goede498be962009-01-07 16:37:28 +0100122 "f71882fg",
Jean Delvare5d7f77b2011-03-26 10:45:02 +0100123 "f71889fg", /* f81801u too, same id */
Hans de Goede3cad4022011-03-09 20:57:14 +0100124 "f71889ed",
Hans de Goedea66c1082011-03-26 10:45:02 +0100125 "f71889a",
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100126 "f8000",
Jean Delvare383586b2011-03-26 10:45:02 +0100127 "f81865f",
Hans de Goede498be962009-01-07 16:37:28 +0100128};
129
Jean Delvare2740c602011-03-26 10:45:01 +0100130static const char f71882fg_has_in[][F71882FG_MAX_INS] = {
131 [f71808e] = { 1, 1, 1, 1, 1, 1, 0, 1, 1 },
Hans de Goede629c58b2011-05-25 20:43:32 +0200132 [f71808a] = { 1, 1, 1, 1, 0, 0, 0, 1, 1 },
Jean Delvare2740c602011-03-26 10:45:01 +0100133 [f71858fg] = { 1, 1, 1, 0, 0, 0, 0, 0, 0 },
134 [f71862fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
135 [f71869] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
Hans de Goede5da556e2011-07-03 13:32:53 +0200136 [f71869a] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
Jean Delvare2740c602011-03-26 10:45:01 +0100137 [f71882fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
138 [f71889fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
139 [f71889ed] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
Hans de Goedea66c1082011-03-26 10:45:02 +0100140 [f71889a] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 },
Jean Delvare2740c602011-03-26 10:45:01 +0100141 [f8000] = { 1, 1, 1, 0, 0, 0, 0, 0, 0 },
Jean Delvare383586b2011-03-26 10:45:02 +0100142 [f81865f] = { 1, 1, 1, 1, 1, 1, 1, 0, 0 },
Hans de Goede0bae6402011-03-09 20:57:10 +0100143};
144
Jean Delvare2740c602011-03-26 10:45:01 +0100145static const char f71882fg_has_in1_alarm[] = {
146 [f71808e] = 0,
Hans de Goede629c58b2011-05-25 20:43:32 +0200147 [f71808a] = 0,
Jean Delvare2740c602011-03-26 10:45:01 +0100148 [f71858fg] = 0,
149 [f71862fg] = 0,
150 [f71869] = 0,
Hans de Goede5da556e2011-07-03 13:32:53 +0200151 [f71869a] = 0,
Jean Delvare2740c602011-03-26 10:45:01 +0100152 [f71882fg] = 1,
153 [f71889fg] = 1,
154 [f71889ed] = 1,
Hans de Goedea66c1082011-03-26 10:45:02 +0100155 [f71889a] = 1,
Jean Delvare2740c602011-03-26 10:45:01 +0100156 [f8000] = 0,
Jean Delvare383586b2011-03-26 10:45:02 +0100157 [f81865f] = 1,
Hans de Goede0bae6402011-03-09 20:57:10 +0100158};
159
Hans de Goede4d538112011-05-25 20:43:32 +0200160static const char f71882fg_fan_has_beep[] = {
Jean Delvare2740c602011-03-26 10:45:01 +0100161 [f71808e] = 0,
Hans de Goede629c58b2011-05-25 20:43:32 +0200162 [f71808a] = 0,
Jean Delvare2740c602011-03-26 10:45:01 +0100163 [f71858fg] = 0,
164 [f71862fg] = 1,
165 [f71869] = 1,
Hans de Goede5da556e2011-07-03 13:32:53 +0200166 [f71869a] = 1,
Jean Delvare2740c602011-03-26 10:45:01 +0100167 [f71882fg] = 1,
168 [f71889fg] = 1,
169 [f71889ed] = 1,
Hans de Goedea66c1082011-03-26 10:45:02 +0100170 [f71889a] = 1,
Jean Delvare2740c602011-03-26 10:45:01 +0100171 [f8000] = 0,
Jean Delvare383586b2011-03-26 10:45:02 +0100172 [f81865f] = 1,
Hans de Goede78aa4f72011-03-09 20:57:12 +0100173};
174
Jean Delvaref27def02011-03-26 10:45:01 +0100175static const char f71882fg_nr_fans[] = {
176 [f71808e] = 3,
Hans de Goede629c58b2011-05-25 20:43:32 +0200177 [f71808a] = 2, /* +1 fan which is monitor + simple pwm only */
Jean Delvaref27def02011-03-26 10:45:01 +0100178 [f71858fg] = 3,
179 [f71862fg] = 3,
180 [f71869] = 3,
Hans de Goede5da556e2011-07-03 13:32:53 +0200181 [f71869a] = 3,
Jean Delvaref27def02011-03-26 10:45:01 +0100182 [f71882fg] = 4,
183 [f71889fg] = 3,
184 [f71889ed] = 3,
Hans de Goedea66c1082011-03-26 10:45:02 +0100185 [f71889a] = 3,
Hans de Goede629c58b2011-05-25 20:43:32 +0200186 [f8000] = 3, /* +1 fan which is monitor only */
Jean Delvare383586b2011-03-26 10:45:02 +0100187 [f81865f] = 2,
Jean Delvaref27def02011-03-26 10:45:01 +0100188};
189
Hans de Goede4d538112011-05-25 20:43:32 +0200190static const char f71882fg_temp_has_beep[] = {
191 [f71808e] = 0,
Hans de Goede629c58b2011-05-25 20:43:32 +0200192 [f71808a] = 1,
Hans de Goede4d538112011-05-25 20:43:32 +0200193 [f71858fg] = 0,
194 [f71862fg] = 1,
195 [f71869] = 1,
Hans de Goede5da556e2011-07-03 13:32:53 +0200196 [f71869a] = 1,
Hans de Goede4d538112011-05-25 20:43:32 +0200197 [f71882fg] = 1,
198 [f71889fg] = 1,
199 [f71889ed] = 1,
200 [f71889a] = 1,
201 [f8000] = 0,
202 [f81865f] = 1,
203};
204
Jean Delvaref27def02011-03-26 10:45:01 +0100205static const char f71882fg_nr_temps[] = {
206 [f71808e] = 2,
Hans de Goede629c58b2011-05-25 20:43:32 +0200207 [f71808a] = 2,
Jean Delvaref27def02011-03-26 10:45:01 +0100208 [f71858fg] = 3,
209 [f71862fg] = 3,
210 [f71869] = 3,
Hans de Goede5da556e2011-07-03 13:32:53 +0200211 [f71869a] = 3,
Jean Delvaref27def02011-03-26 10:45:01 +0100212 [f71882fg] = 3,
213 [f71889fg] = 3,
214 [f71889ed] = 3,
Hans de Goedea66c1082011-03-26 10:45:02 +0100215 [f71889a] = 3,
Jean Delvaref27def02011-03-26 10:45:01 +0100216 [f8000] = 3,
Jean Delvare383586b2011-03-26 10:45:02 +0100217 [f81865f] = 2,
Jean Delvaref27def02011-03-26 10:45:01 +0100218};
219
Mark van Doesburg77a4a3e2009-01-07 16:37:27 +0100220static struct platform_device *f71882fg_pdev;
Hans de Goede45fb3662007-07-13 14:34:19 +0200221
222/* Super-I/O Function prototypes */
223static inline int superio_inb(int base, int reg);
224static inline int superio_inw(int base, int reg);
Giel van Schijndelcadb8652010-10-03 08:09:49 -0400225static inline int superio_enter(int base);
Hans de Goede45fb3662007-07-13 14:34:19 +0200226static inline void superio_select(int base, int ld);
227static inline void superio_exit(int base);
228
Hans de Goede498be962009-01-07 16:37:28 +0100229struct f71882fg_sio_data {
230 enum chips type;
231};
232
Hans de Goede45fb3662007-07-13 14:34:19 +0200233struct f71882fg_data {
234 unsigned short addr;
Hans de Goede498be962009-01-07 16:37:28 +0100235 enum chips type;
Tony Jones1beeffe2007-08-20 13:46:20 -0700236 struct device *hwmon_dev;
Hans de Goede45fb3662007-07-13 14:34:19 +0200237
238 struct mutex update_lock;
Hans de Goede09475d32009-06-15 18:39:52 +0200239 int temp_start; /* temp numbering start (0 or 1) */
Hans de Goede45fb3662007-07-13 14:34:19 +0200240 char valid; /* !=0 if following fields are valid */
Hans de Goede98f7ba12011-03-09 20:57:09 +0100241 char auto_point_temp_signed;
Hans de Goede45fb3662007-07-13 14:34:19 +0200242 unsigned long last_updated; /* In jiffies */
243 unsigned long last_limits; /* In jiffies */
244
245 /* Register Values */
Hans de Goede0bae6402011-03-09 20:57:10 +0100246 u8 in[F71882FG_MAX_INS];
Hans de Goede45fb3662007-07-13 14:34:19 +0200247 u8 in1_max;
248 u8 in_status;
249 u8 in_beep;
250 u16 fan[4];
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100251 u16 fan_target[4];
252 u16 fan_full_speed[4];
Hans de Goede45fb3662007-07-13 14:34:19 +0200253 u8 fan_status;
254 u8 fan_beep;
Guenter Roeck20eaf722012-01-19 11:02:17 -0800255 /*
256 * Note: all models have max 3 temperature channels, but on some
257 * they are addressed as 0-2 and on others as 1-3, so for coding
258 * convenience we reserve space for 4 channels
259 */
Hans de Goede09475d32009-06-15 18:39:52 +0200260 u16 temp[4];
Hans de Goede7567a042009-01-07 16:37:28 +0100261 u8 temp_ovt[4];
262 u8 temp_high[4];
Hans de Goedebc274902009-01-07 16:37:29 +0100263 u8 temp_hyst[2]; /* 2 hysts stored per reg */
Hans de Goede7567a042009-01-07 16:37:28 +0100264 u8 temp_type[4];
Hans de Goede45fb3662007-07-13 14:34:19 +0200265 u8 temp_status;
266 u8 temp_beep;
267 u8 temp_diode_open;
Hans de Goede09475d32009-06-15 18:39:52 +0200268 u8 temp_config;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100269 u8 pwm[4];
270 u8 pwm_enable;
271 u8 pwm_auto_point_hyst[2];
272 u8 pwm_auto_point_mapping[4];
273 u8 pwm_auto_point_pwm[4][5];
Hans de Goede76698962009-12-09 20:36:01 +0100274 s8 pwm_auto_point_temp[4][4];
Hans de Goede45fb3662007-07-13 14:34:19 +0200275};
276
Mark van Doesburg77a4a3e2009-01-07 16:37:27 +0100277/* Sysfs in */
Hans de Goede45fb3662007-07-13 14:34:19 +0200278static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
279 char *buf);
280static ssize_t show_in_max(struct device *dev, struct device_attribute
281 *devattr, char *buf);
282static ssize_t store_in_max(struct device *dev, struct device_attribute
283 *devattr, const char *buf, size_t count);
284static ssize_t show_in_beep(struct device *dev, struct device_attribute
285 *devattr, char *buf);
286static ssize_t store_in_beep(struct device *dev, struct device_attribute
287 *devattr, const char *buf, size_t count);
288static ssize_t show_in_alarm(struct device *dev, struct device_attribute
289 *devattr, char *buf);
290/* Sysfs Fan */
291static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
292 char *buf);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100293static ssize_t show_fan_full_speed(struct device *dev,
294 struct device_attribute *devattr, char *buf);
295static ssize_t store_fan_full_speed(struct device *dev,
296 struct device_attribute *devattr, const char *buf, size_t count);
Hans de Goede45fb3662007-07-13 14:34:19 +0200297static ssize_t show_fan_beep(struct device *dev, struct device_attribute
298 *devattr, char *buf);
299static ssize_t store_fan_beep(struct device *dev, struct device_attribute
300 *devattr, const char *buf, size_t count);
301static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
302 *devattr, char *buf);
303/* Sysfs Temp */
304static ssize_t show_temp(struct device *dev, struct device_attribute
305 *devattr, char *buf);
306static ssize_t show_temp_max(struct device *dev, struct device_attribute
307 *devattr, char *buf);
308static ssize_t store_temp_max(struct device *dev, struct device_attribute
309 *devattr, const char *buf, size_t count);
310static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
311 *devattr, char *buf);
312static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
313 *devattr, const char *buf, size_t count);
314static ssize_t show_temp_crit(struct device *dev, struct device_attribute
315 *devattr, char *buf);
316static ssize_t store_temp_crit(struct device *dev, struct device_attribute
317 *devattr, const char *buf, size_t count);
318static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
319 *devattr, char *buf);
320static ssize_t show_temp_type(struct device *dev, struct device_attribute
321 *devattr, char *buf);
322static ssize_t show_temp_beep(struct device *dev, struct device_attribute
323 *devattr, char *buf);
324static ssize_t store_temp_beep(struct device *dev, struct device_attribute
325 *devattr, const char *buf, size_t count);
326static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
327 *devattr, char *buf);
328static ssize_t show_temp_fault(struct device *dev, struct device_attribute
329 *devattr, char *buf);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100330/* PWM and Auto point control */
331static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
332 char *buf);
333static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr,
334 const char *buf, size_t count);
Hans de Goede629c58b2011-05-25 20:43:32 +0200335static ssize_t show_simple_pwm(struct device *dev,
336 struct device_attribute *devattr, char *buf);
337static ssize_t store_simple_pwm(struct device *dev,
338 struct device_attribute *devattr, const char *buf, size_t count);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100339static ssize_t show_pwm_enable(struct device *dev,
340 struct device_attribute *devattr, char *buf);
341static ssize_t store_pwm_enable(struct device *dev,
342 struct device_attribute *devattr, const char *buf, size_t count);
343static ssize_t show_pwm_interpolate(struct device *dev,
344 struct device_attribute *devattr, char *buf);
345static ssize_t store_pwm_interpolate(struct device *dev,
346 struct device_attribute *devattr, const char *buf, size_t count);
347static ssize_t show_pwm_auto_point_channel(struct device *dev,
348 struct device_attribute *devattr, char *buf);
349static ssize_t store_pwm_auto_point_channel(struct device *dev,
350 struct device_attribute *devattr, const char *buf, size_t count);
351static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
352 struct device_attribute *devattr, char *buf);
353static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
354 struct device_attribute *devattr, const char *buf, size_t count);
355static ssize_t show_pwm_auto_point_pwm(struct device *dev,
356 struct device_attribute *devattr, char *buf);
357static ssize_t store_pwm_auto_point_pwm(struct device *dev,
358 struct device_attribute *devattr, const char *buf, size_t count);
359static ssize_t show_pwm_auto_point_temp(struct device *dev,
360 struct device_attribute *devattr, char *buf);
361static ssize_t store_pwm_auto_point_temp(struct device *dev,
362 struct device_attribute *devattr, const char *buf, size_t count);
Hans de Goede45fb3662007-07-13 14:34:19 +0200363/* Sysfs misc */
364static ssize_t show_name(struct device *dev, struct device_attribute *devattr,
365 char *buf);
366
Bill Pemberton6c931ae2012-11-19 13:22:35 -0500367static int f71882fg_probe(struct platform_device *pdev);
Hans de Goedec13548c2009-01-07 16:37:27 +0100368static int f71882fg_remove(struct platform_device *pdev);
Hans de Goede45fb3662007-07-13 14:34:19 +0200369
370static struct platform_driver f71882fg_driver = {
371 .driver = {
Hans de Goede45fb3662007-07-13 14:34:19 +0200372 .name = DRVNAME,
373 },
374 .probe = f71882fg_probe,
Jean Delvarecd659fd2009-06-15 18:39:45 +0200375 .remove = f71882fg_remove,
Hans de Goede45fb3662007-07-13 14:34:19 +0200376};
377
Hans de Goedec13548c2009-01-07 16:37:27 +0100378static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
Hans de Goede45fb3662007-07-13 14:34:19 +0200379
Guenter Roeck20eaf722012-01-19 11:02:17 -0800380/*
381 * Temp attr for the f71858fg, the f71858fg is special as it has its
382 * temperature indexes start at 0 (the others start at 1)
383 */
Hans de Goede0bae6402011-03-09 20:57:10 +0100384static struct sensor_device_attribute_2 f71858fg_temp_attr[] = {
Hans de Goede09475d32009-06-15 18:39:52 +0200385 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
386 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
387 store_temp_max, 0, 0),
388 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
389 store_temp_max_hyst, 0, 0),
390 SENSOR_ATTR_2(temp1_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 0),
391 SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
392 store_temp_crit, 0, 0),
393 SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
394 0, 0),
395 SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4),
396 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0),
397 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1),
398 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max,
399 store_temp_max, 0, 1),
400 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
401 store_temp_max_hyst, 0, 1),
402 SENSOR_ATTR_2(temp2_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
403 SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
404 store_temp_crit, 0, 1),
405 SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
406 0, 1),
407 SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
Hans de Goede09475d32009-06-15 18:39:52 +0200408 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
409 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2),
410 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
411 store_temp_max, 0, 2),
412 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
413 store_temp_max_hyst, 0, 2),
414 SENSOR_ATTR_2(temp3_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
415 SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit,
416 store_temp_crit, 0, 2),
417 SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
418 0, 2),
419 SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
420 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
421};
422
Hans de Goede0bae6402011-03-09 20:57:10 +0100423/* Temp attr for the standard models */
Hans de Goede78aa4f72011-03-09 20:57:12 +0100424static struct sensor_device_attribute_2 fxxxx_temp_attr[3][9] = { {
Hans de Goede7567a042009-01-07 16:37:28 +0100425 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 1),
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100426 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100427 store_temp_max, 0, 1),
Hans de Goede7567a042009-01-07 16:37:28 +0100428 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100429 store_temp_max_hyst, 0, 1),
Guenter Roeck20eaf722012-01-19 11:02:17 -0800430 /*
431 * Should really be temp1_max_alarm, but older versions did not handle
432 * the max and crit alarms separately and lm_sensors v2 depends on the
433 * presence of temp#_alarm files. The same goes for temp2/3 _alarm.
434 */
Hans de Goede754a5907b2009-01-07 16:37:29 +0100435 SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
Hans de Goede7567a042009-01-07 16:37:28 +0100436 SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100437 store_temp_crit, 0, 1),
Hans de Goede7567a042009-01-07 16:37:28 +0100438 SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100439 0, 1),
Hans de Goede754a5907b2009-01-07 16:37:29 +0100440 SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
Hans de Goede7567a042009-01-07 16:37:28 +0100441 SENSOR_ATTR_2(temp1_type, S_IRUGO, show_temp_type, NULL, 0, 1),
Hans de Goede7567a042009-01-07 16:37:28 +0100442 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
Hans de Goede60d2b372011-03-09 20:57:11 +0100443}, {
Hans de Goede7567a042009-01-07 16:37:28 +0100444 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 2),
445 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100446 store_temp_max, 0, 2),
Hans de Goede7567a042009-01-07 16:37:28 +0100447 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100448 store_temp_max_hyst, 0, 2),
Hans de Goede754a5907b2009-01-07 16:37:29 +0100449 /* Should be temp2_max_alarm, see temp1_alarm note */
450 SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
Hans de Goede7567a042009-01-07 16:37:28 +0100451 SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100452 store_temp_crit, 0, 2),
Hans de Goede7567a042009-01-07 16:37:28 +0100453 SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100454 0, 2),
Hans de Goede754a5907b2009-01-07 16:37:29 +0100455 SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
Hans de Goede7567a042009-01-07 16:37:28 +0100456 SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 2),
Hans de Goede7567a042009-01-07 16:37:28 +0100457 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
Hans de Goede60d2b372011-03-09 20:57:11 +0100458}, {
Hans de Goede7567a042009-01-07 16:37:28 +0100459 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 3),
460 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
461 store_temp_max, 0, 3),
462 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
463 store_temp_max_hyst, 0, 3),
Hans de Goede754a5907b2009-01-07 16:37:29 +0100464 /* Should be temp3_max_alarm, see temp1_alarm note */
465 SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 3),
Hans de Goede7567a042009-01-07 16:37:28 +0100466 SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit,
467 store_temp_crit, 0, 3),
468 SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
469 0, 3),
Hans de Goede754a5907b2009-01-07 16:37:29 +0100470 SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 7),
Hans de Goede7567a042009-01-07 16:37:28 +0100471 SENSOR_ATTR_2(temp3_type, S_IRUGO, show_temp_type, NULL, 0, 3),
Hans de Goede7567a042009-01-07 16:37:28 +0100472 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 3),
Hans de Goede60d2b372011-03-09 20:57:11 +0100473} };
Hans de Goede45fb3662007-07-13 14:34:19 +0200474
Hans de Goede78aa4f72011-03-09 20:57:12 +0100475/* Temp attr for models which can beep on temp alarm */
476static struct sensor_device_attribute_2 fxxxx_temp_beep_attr[3][2] = { {
477 SENSOR_ATTR_2(temp1_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
478 store_temp_beep, 0, 1),
479 SENSOR_ATTR_2(temp1_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
480 store_temp_beep, 0, 5),
481}, {
482 SENSOR_ATTR_2(temp2_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
483 store_temp_beep, 0, 2),
484 SENSOR_ATTR_2(temp2_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
485 store_temp_beep, 0, 6),
486}, {
487 SENSOR_ATTR_2(temp3_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
488 store_temp_beep, 0, 3),
489 SENSOR_ATTR_2(temp3_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
490 store_temp_beep, 0, 7),
491} };
492
Guenter Roeck20eaf722012-01-19 11:02:17 -0800493/*
494 * Temp attr for the f8000
495 * Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max)
496 * is used as hysteresis value to clear alarms
497 * Also like the f71858fg its temperature indexes start at 0
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100498 */
Hans de Goede0bae6402011-03-09 20:57:10 +0100499static struct sensor_device_attribute_2 f8000_temp_attr[] = {
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100500 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
501 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_crit,
502 store_temp_crit, 0, 0),
503 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
504 store_temp_max, 0, 0),
505 SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4),
Hans de Goedeb6858bc2009-06-15 18:39:51 +0200506 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0),
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100507 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1),
508 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_crit,
509 store_temp_crit, 0, 1),
510 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
511 store_temp_max, 0, 1),
512 SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
Hans de Goedeb6858bc2009-06-15 18:39:51 +0200513 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100514 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2),
515 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_crit,
516 store_temp_crit, 0, 2),
517 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
518 store_temp_max, 0, 2),
519 SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
Hans de Goedeb6858bc2009-06-15 18:39:51 +0200520 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100521};
522
Hans de Goede0bae6402011-03-09 20:57:10 +0100523/* in attr for all models */
524static struct sensor_device_attribute_2 fxxxx_in_attr[] = {
525 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
526 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
527 SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2),
528 SENSOR_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 0, 3),
529 SENSOR_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 0, 4),
530 SENSOR_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 0, 5),
531 SENSOR_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 0, 6),
532 SENSOR_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 0, 7),
533 SENSOR_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 0, 8),
534};
535
536/* For models with in1 alarm capability */
537static struct sensor_device_attribute_2 fxxxx_in1_alarm_attr[] = {
538 SENSOR_ATTR_2(in1_max, S_IRUGO|S_IWUSR, show_in_max, store_in_max,
539 0, 1),
540 SENSOR_ATTR_2(in1_beep, S_IRUGO|S_IWUSR, show_in_beep, store_in_beep,
541 0, 1),
542 SENSOR_ATTR_2(in1_alarm, S_IRUGO, show_in_alarm, NULL, 0, 1),
543};
544
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100545/* Fan / PWM attr common to all models */
Hans de Goedeb69b0392009-12-09 20:36:00 +0100546static struct sensor_device_attribute_2 fxxxx_fan_attr[4][6] = { {
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100547 SENSOR_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0),
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100548 SENSOR_ATTR_2(fan1_full_speed, S_IRUGO|S_IWUSR,
549 show_fan_full_speed,
550 store_fan_full_speed, 0, 0),
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100551 SENSOR_ATTR_2(fan1_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 0),
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100552 SENSOR_ATTR_2(pwm1, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 0),
553 SENSOR_ATTR_2(pwm1_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
554 store_pwm_enable, 0, 0),
555 SENSOR_ATTR_2(pwm1_interpolate, S_IRUGO|S_IWUSR,
556 show_pwm_interpolate, store_pwm_interpolate, 0, 0),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100557}, {
558 SENSOR_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 0, 1),
559 SENSOR_ATTR_2(fan2_full_speed, S_IRUGO|S_IWUSR,
560 show_fan_full_speed,
561 store_fan_full_speed, 0, 1),
562 SENSOR_ATTR_2(fan2_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 1),
Hans de Goede498be962009-01-07 16:37:28 +0100563 SENSOR_ATTR_2(pwm2, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 1),
564 SENSOR_ATTR_2(pwm2_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
565 store_pwm_enable, 0, 1),
566 SENSOR_ATTR_2(pwm2_interpolate, S_IRUGO|S_IWUSR,
567 show_pwm_interpolate, store_pwm_interpolate, 0, 1),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100568}, {
569 SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
570 SENSOR_ATTR_2(fan3_full_speed, S_IRUGO|S_IWUSR,
571 show_fan_full_speed,
572 store_fan_full_speed, 0, 2),
573 SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
Hans de Goede3fc78382009-06-15 18:39:50 +0200574 SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 2),
575 SENSOR_ATTR_2(pwm3_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
576 store_pwm_enable, 0, 2),
Hans de Goede498be962009-01-07 16:37:28 +0100577 SENSOR_ATTR_2(pwm3_interpolate, S_IRUGO|S_IWUSR,
578 show_pwm_interpolate, store_pwm_interpolate, 0, 2),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100579}, {
580 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
581 SENSOR_ATTR_2(fan4_full_speed, S_IRUGO|S_IWUSR,
582 show_fan_full_speed,
583 store_fan_full_speed, 0, 3),
584 SENSOR_ATTR_2(fan4_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 3),
585 SENSOR_ATTR_2(pwm4, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 3),
586 SENSOR_ATTR_2(pwm4_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
587 store_pwm_enable, 0, 3),
588 SENSOR_ATTR_2(pwm4_interpolate, S_IRUGO|S_IWUSR,
589 show_pwm_interpolate, store_pwm_interpolate, 0, 3),
590} };
Hans de Goede498be962009-01-07 16:37:28 +0100591
Hans de Goede629c58b2011-05-25 20:43:32 +0200592/* Attr for the third fan of the f71808a, which only has manual pwm */
593static struct sensor_device_attribute_2 f71808a_fan3_attr[] = {
594 SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
595 SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
596 SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR,
597 show_simple_pwm, store_simple_pwm, 0, 2),
598};
599
Hans de Goede66344aa2009-12-09 20:35:59 +0100600/* Attr for models which can beep on Fan alarm */
601static struct sensor_device_attribute_2 fxxxx_fan_beep_attr[] = {
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100602 SENSOR_ATTR_2(fan1_beep, S_IRUGO|S_IWUSR, show_fan_beep,
603 store_fan_beep, 0, 0),
604 SENSOR_ATTR_2(fan2_beep, S_IRUGO|S_IWUSR, show_fan_beep,
605 store_fan_beep, 0, 1),
606 SENSOR_ATTR_2(fan3_beep, S_IRUGO|S_IWUSR, show_fan_beep,
607 store_fan_beep, 0, 2),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100608 SENSOR_ATTR_2(fan4_beep, S_IRUGO|S_IWUSR, show_fan_beep,
609 store_fan_beep, 0, 3),
Hans de Goede66344aa2009-12-09 20:35:59 +0100610};
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100611
Guenter Roeck20eaf722012-01-19 11:02:17 -0800612/*
613 * PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
614 * standard models
615 */
Hans de Goede55840142011-09-09 12:12:33 +0200616static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr[3][7] = { {
Hans de Goede66344aa2009-12-09 20:35:59 +0100617 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
618 show_pwm_auto_point_channel,
619 store_pwm_auto_point_channel, 0, 0),
Hans de Goede498be962009-01-07 16:37:28 +0100620 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
621 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
622 1, 0),
623 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
624 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
625 4, 0),
626 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
627 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
628 0, 0),
629 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
630 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
631 3, 0),
632 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
633 show_pwm_auto_point_temp_hyst,
634 store_pwm_auto_point_temp_hyst,
635 0, 0),
636 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
637 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
Hans de Goede55840142011-09-09 12:12:33 +0200638}, {
Hans de Goede66344aa2009-12-09 20:35:59 +0100639 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
640 show_pwm_auto_point_channel,
641 store_pwm_auto_point_channel, 0, 1),
Hans de Goede498be962009-01-07 16:37:28 +0100642 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
643 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
644 1, 1),
645 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
646 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
647 4, 1),
648 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
649 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
650 0, 1),
651 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
652 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
653 3, 1),
654 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
655 show_pwm_auto_point_temp_hyst,
656 store_pwm_auto_point_temp_hyst,
657 0, 1),
658 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
659 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
Hans de Goede55840142011-09-09 12:12:33 +0200660}, {
Hans de Goede66344aa2009-12-09 20:35:59 +0100661 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
662 show_pwm_auto_point_channel,
663 store_pwm_auto_point_channel, 0, 2),
Hans de Goede49010622009-01-07 16:37:30 +0100664 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
665 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
666 1, 2),
667 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
668 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
669 4, 2),
670 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
671 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
672 0, 2),
673 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
674 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
675 3, 2),
676 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
677 show_pwm_auto_point_temp_hyst,
678 store_pwm_auto_point_temp_hyst,
679 0, 2),
680 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
681 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
Hans de Goede55840142011-09-09 12:12:33 +0200682} };
Hans de Goede498be962009-01-07 16:37:28 +0100683
Guenter Roeck20eaf722012-01-19 11:02:17 -0800684/*
685 * PWM attr for the f71808e/f71869, almost identical to the f71862fg, but the
686 * pwm setting when the temperature is above the pwmX_auto_point1_temp can be
687 * programmed instead of being hardcoded to 0xff
688 */
Hans de Goede55840142011-09-09 12:12:33 +0200689static struct sensor_device_attribute_2 f71869_auto_pwm_attr[3][8] = { {
Hans de Goedec11bb992011-03-09 20:57:15 +0100690 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
691 show_pwm_auto_point_channel,
692 store_pwm_auto_point_channel, 0, 0),
693 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
694 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
695 0, 0),
696 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
697 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
698 1, 0),
699 SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO|S_IWUSR,
700 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
701 4, 0),
702 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
703 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
704 0, 0),
705 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
706 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
707 3, 0),
708 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
709 show_pwm_auto_point_temp_hyst,
710 store_pwm_auto_point_temp_hyst,
711 0, 0),
712 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
713 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
Hans de Goede55840142011-09-09 12:12:33 +0200714}, {
Hans de Goedec11bb992011-03-09 20:57:15 +0100715 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
716 show_pwm_auto_point_channel,
717 store_pwm_auto_point_channel, 0, 1),
718 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
719 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
720 0, 1),
721 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
722 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
723 1, 1),
724 SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO|S_IWUSR,
725 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
726 4, 1),
727 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
728 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
729 0, 1),
730 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
731 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
732 3, 1),
733 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
734 show_pwm_auto_point_temp_hyst,
735 store_pwm_auto_point_temp_hyst,
736 0, 1),
737 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
738 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
Hans de Goede55840142011-09-09 12:12:33 +0200739}, {
Hans de Goedec11bb992011-03-09 20:57:15 +0100740 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
741 show_pwm_auto_point_channel,
742 store_pwm_auto_point_channel, 0, 2),
743 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
744 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
745 0, 2),
746 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
747 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
748 1, 2),
749 SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO|S_IWUSR,
750 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
751 4, 2),
752 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
753 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
754 0, 2),
755 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
756 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
757 3, 2),
758 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
759 show_pwm_auto_point_temp_hyst,
760 store_pwm_auto_point_temp_hyst,
761 0, 2),
762 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
763 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
Hans de Goede55840142011-09-09 12:12:33 +0200764} };
Hans de Goedec11bb992011-03-09 20:57:15 +0100765
Hans de Goede3cad4022011-03-09 20:57:14 +0100766/* PWM attr for the standard models */
Hans de Goedeb69b0392009-12-09 20:36:00 +0100767static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr[4][14] = { {
Hans de Goede66344aa2009-12-09 20:35:59 +0100768 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
769 show_pwm_auto_point_channel,
770 store_pwm_auto_point_channel, 0, 0),
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100771 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
772 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
773 0, 0),
774 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
775 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
776 1, 0),
777 SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO|S_IWUSR,
778 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
779 2, 0),
780 SENSOR_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO|S_IWUSR,
781 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
782 3, 0),
783 SENSOR_ATTR_2(pwm1_auto_point5_pwm, S_IRUGO|S_IWUSR,
784 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
785 4, 0),
786 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
787 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
788 0, 0),
789 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
790 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
791 1, 0),
792 SENSOR_ATTR_2(pwm1_auto_point3_temp, S_IRUGO|S_IWUSR,
793 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
794 2, 0),
795 SENSOR_ATTR_2(pwm1_auto_point4_temp, S_IRUGO|S_IWUSR,
796 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
797 3, 0),
798 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
799 show_pwm_auto_point_temp_hyst,
800 store_pwm_auto_point_temp_hyst,
801 0, 0),
802 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
803 show_pwm_auto_point_temp_hyst, NULL, 1, 0),
804 SENSOR_ATTR_2(pwm1_auto_point3_temp_hyst, S_IRUGO,
805 show_pwm_auto_point_temp_hyst, NULL, 2, 0),
806 SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst, S_IRUGO,
807 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100808}, {
Hans de Goede66344aa2009-12-09 20:35:59 +0100809 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
810 show_pwm_auto_point_channel,
811 store_pwm_auto_point_channel, 0, 1),
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100812 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
813 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
814 0, 1),
815 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
816 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
817 1, 1),
818 SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO|S_IWUSR,
819 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
820 2, 1),
821 SENSOR_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO|S_IWUSR,
822 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
823 3, 1),
824 SENSOR_ATTR_2(pwm2_auto_point5_pwm, S_IRUGO|S_IWUSR,
825 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
826 4, 1),
827 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
828 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
829 0, 1),
830 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
831 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
832 1, 1),
833 SENSOR_ATTR_2(pwm2_auto_point3_temp, S_IRUGO|S_IWUSR,
834 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
835 2, 1),
836 SENSOR_ATTR_2(pwm2_auto_point4_temp, S_IRUGO|S_IWUSR,
837 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
838 3, 1),
839 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
840 show_pwm_auto_point_temp_hyst,
841 store_pwm_auto_point_temp_hyst,
842 0, 1),
843 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
844 show_pwm_auto_point_temp_hyst, NULL, 1, 1),
845 SENSOR_ATTR_2(pwm2_auto_point3_temp_hyst, S_IRUGO,
846 show_pwm_auto_point_temp_hyst, NULL, 2, 1),
847 SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst, S_IRUGO,
848 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100849}, {
Hans de Goede66344aa2009-12-09 20:35:59 +0100850 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
851 show_pwm_auto_point_channel,
852 store_pwm_auto_point_channel, 0, 2),
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100853 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
854 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
855 0, 2),
856 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
857 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
858 1, 2),
859 SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO|S_IWUSR,
860 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
861 2, 2),
862 SENSOR_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO|S_IWUSR,
863 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
864 3, 2),
865 SENSOR_ATTR_2(pwm3_auto_point5_pwm, S_IRUGO|S_IWUSR,
866 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
867 4, 2),
868 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
869 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
870 0, 2),
871 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
872 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
873 1, 2),
874 SENSOR_ATTR_2(pwm3_auto_point3_temp, S_IRUGO|S_IWUSR,
875 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
876 2, 2),
877 SENSOR_ATTR_2(pwm3_auto_point4_temp, S_IRUGO|S_IWUSR,
878 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
879 3, 2),
880 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
881 show_pwm_auto_point_temp_hyst,
882 store_pwm_auto_point_temp_hyst,
883 0, 2),
884 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
885 show_pwm_auto_point_temp_hyst, NULL, 1, 2),
886 SENSOR_ATTR_2(pwm3_auto_point3_temp_hyst, S_IRUGO,
887 show_pwm_auto_point_temp_hyst, NULL, 2, 2),
888 SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst, S_IRUGO,
889 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100890}, {
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100891 SENSOR_ATTR_2(pwm4_auto_channels_temp, S_IRUGO|S_IWUSR,
892 show_pwm_auto_point_channel,
893 store_pwm_auto_point_channel, 0, 3),
894 SENSOR_ATTR_2(pwm4_auto_point1_pwm, S_IRUGO|S_IWUSR,
895 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
896 0, 3),
897 SENSOR_ATTR_2(pwm4_auto_point2_pwm, S_IRUGO|S_IWUSR,
898 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
899 1, 3),
900 SENSOR_ATTR_2(pwm4_auto_point3_pwm, S_IRUGO|S_IWUSR,
901 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
902 2, 3),
903 SENSOR_ATTR_2(pwm4_auto_point4_pwm, S_IRUGO|S_IWUSR,
904 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
905 3, 3),
906 SENSOR_ATTR_2(pwm4_auto_point5_pwm, S_IRUGO|S_IWUSR,
907 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
908 4, 3),
909 SENSOR_ATTR_2(pwm4_auto_point1_temp, S_IRUGO|S_IWUSR,
910 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
911 0, 3),
912 SENSOR_ATTR_2(pwm4_auto_point2_temp, S_IRUGO|S_IWUSR,
913 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
914 1, 3),
915 SENSOR_ATTR_2(pwm4_auto_point3_temp, S_IRUGO|S_IWUSR,
916 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
917 2, 3),
918 SENSOR_ATTR_2(pwm4_auto_point4_temp, S_IRUGO|S_IWUSR,
919 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
920 3, 3),
921 SENSOR_ATTR_2(pwm4_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
922 show_pwm_auto_point_temp_hyst,
923 store_pwm_auto_point_temp_hyst,
924 0, 3),
925 SENSOR_ATTR_2(pwm4_auto_point2_temp_hyst, S_IRUGO,
926 show_pwm_auto_point_temp_hyst, NULL, 1, 3),
927 SENSOR_ATTR_2(pwm4_auto_point3_temp_hyst, S_IRUGO,
928 show_pwm_auto_point_temp_hyst, NULL, 2, 3),
929 SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst, S_IRUGO,
930 show_pwm_auto_point_temp_hyst, NULL, 3, 3),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100931} };
Hans de Goede45fb3662007-07-13 14:34:19 +0200932
Hans de Goede66344aa2009-12-09 20:35:59 +0100933/* Fan attr specific to the f8000 (4th fan input can only measure speed) */
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100934static struct sensor_device_attribute_2 f8000_fan_attr[] = {
935 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
Hans de Goede66344aa2009-12-09 20:35:59 +0100936};
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100937
Guenter Roeck20eaf722012-01-19 11:02:17 -0800938/*
939 * PWM attr for the f8000, zones mapped to temp instead of to pwm!
940 * Also the register block at offset A0 maps to TEMP1 (so our temp2, as the
941 * F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0
942 */
Hans de Goede55840142011-09-09 12:12:33 +0200943static struct sensor_device_attribute_2 f8000_auto_pwm_attr[3][14] = { {
Hans de Goede66344aa2009-12-09 20:35:59 +0100944 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
945 show_pwm_auto_point_channel,
946 store_pwm_auto_point_channel, 0, 0),
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100947 SENSOR_ATTR_2(temp1_auto_point1_pwm, S_IRUGO|S_IWUSR,
948 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
949 0, 2),
950 SENSOR_ATTR_2(temp1_auto_point2_pwm, S_IRUGO|S_IWUSR,
951 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
952 1, 2),
953 SENSOR_ATTR_2(temp1_auto_point3_pwm, S_IRUGO|S_IWUSR,
954 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
955 2, 2),
956 SENSOR_ATTR_2(temp1_auto_point4_pwm, S_IRUGO|S_IWUSR,
957 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
958 3, 2),
959 SENSOR_ATTR_2(temp1_auto_point5_pwm, S_IRUGO|S_IWUSR,
960 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
961 4, 2),
962 SENSOR_ATTR_2(temp1_auto_point1_temp, S_IRUGO|S_IWUSR,
963 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
964 0, 2),
965 SENSOR_ATTR_2(temp1_auto_point2_temp, S_IRUGO|S_IWUSR,
966 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
967 1, 2),
968 SENSOR_ATTR_2(temp1_auto_point3_temp, S_IRUGO|S_IWUSR,
969 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
970 2, 2),
971 SENSOR_ATTR_2(temp1_auto_point4_temp, S_IRUGO|S_IWUSR,
972 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
973 3, 2),
974 SENSOR_ATTR_2(temp1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
975 show_pwm_auto_point_temp_hyst,
976 store_pwm_auto_point_temp_hyst,
977 0, 2),
978 SENSOR_ATTR_2(temp1_auto_point2_temp_hyst, S_IRUGO,
979 show_pwm_auto_point_temp_hyst, NULL, 1, 2),
980 SENSOR_ATTR_2(temp1_auto_point3_temp_hyst, S_IRUGO,
981 show_pwm_auto_point_temp_hyst, NULL, 2, 2),
982 SENSOR_ATTR_2(temp1_auto_point4_temp_hyst, S_IRUGO,
983 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
Hans de Goede55840142011-09-09 12:12:33 +0200984}, {
Hans de Goede66344aa2009-12-09 20:35:59 +0100985 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
986 show_pwm_auto_point_channel,
987 store_pwm_auto_point_channel, 0, 1),
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100988 SENSOR_ATTR_2(temp2_auto_point1_pwm, S_IRUGO|S_IWUSR,
989 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
990 0, 0),
991 SENSOR_ATTR_2(temp2_auto_point2_pwm, S_IRUGO|S_IWUSR,
992 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
993 1, 0),
994 SENSOR_ATTR_2(temp2_auto_point3_pwm, S_IRUGO|S_IWUSR,
995 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
996 2, 0),
997 SENSOR_ATTR_2(temp2_auto_point4_pwm, S_IRUGO|S_IWUSR,
998 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
999 3, 0),
1000 SENSOR_ATTR_2(temp2_auto_point5_pwm, S_IRUGO|S_IWUSR,
1001 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1002 4, 0),
1003 SENSOR_ATTR_2(temp2_auto_point1_temp, S_IRUGO|S_IWUSR,
1004 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1005 0, 0),
1006 SENSOR_ATTR_2(temp2_auto_point2_temp, S_IRUGO|S_IWUSR,
1007 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1008 1, 0),
1009 SENSOR_ATTR_2(temp2_auto_point3_temp, S_IRUGO|S_IWUSR,
1010 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1011 2, 0),
1012 SENSOR_ATTR_2(temp2_auto_point4_temp, S_IRUGO|S_IWUSR,
1013 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1014 3, 0),
1015 SENSOR_ATTR_2(temp2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
1016 show_pwm_auto_point_temp_hyst,
1017 store_pwm_auto_point_temp_hyst,
1018 0, 0),
1019 SENSOR_ATTR_2(temp2_auto_point2_temp_hyst, S_IRUGO,
1020 show_pwm_auto_point_temp_hyst, NULL, 1, 0),
1021 SENSOR_ATTR_2(temp2_auto_point3_temp_hyst, S_IRUGO,
1022 show_pwm_auto_point_temp_hyst, NULL, 2, 0),
1023 SENSOR_ATTR_2(temp2_auto_point4_temp_hyst, S_IRUGO,
1024 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
Hans de Goede55840142011-09-09 12:12:33 +02001025}, {
Hans de Goede66344aa2009-12-09 20:35:59 +01001026 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
1027 show_pwm_auto_point_channel,
1028 store_pwm_auto_point_channel, 0, 2),
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001029 SENSOR_ATTR_2(temp3_auto_point1_pwm, S_IRUGO|S_IWUSR,
1030 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1031 0, 1),
1032 SENSOR_ATTR_2(temp3_auto_point2_pwm, S_IRUGO|S_IWUSR,
1033 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1034 1, 1),
1035 SENSOR_ATTR_2(temp3_auto_point3_pwm, S_IRUGO|S_IWUSR,
1036 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1037 2, 1),
1038 SENSOR_ATTR_2(temp3_auto_point4_pwm, S_IRUGO|S_IWUSR,
1039 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1040 3, 1),
1041 SENSOR_ATTR_2(temp3_auto_point5_pwm, S_IRUGO|S_IWUSR,
1042 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1043 4, 1),
1044 SENSOR_ATTR_2(temp3_auto_point1_temp, S_IRUGO|S_IWUSR,
1045 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1046 0, 1),
1047 SENSOR_ATTR_2(temp3_auto_point2_temp, S_IRUGO|S_IWUSR,
1048 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1049 1, 1),
1050 SENSOR_ATTR_2(temp3_auto_point3_temp, S_IRUGO|S_IWUSR,
1051 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1052 2, 1),
1053 SENSOR_ATTR_2(temp3_auto_point4_temp, S_IRUGO|S_IWUSR,
1054 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1055 3, 1),
1056 SENSOR_ATTR_2(temp3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
1057 show_pwm_auto_point_temp_hyst,
1058 store_pwm_auto_point_temp_hyst,
1059 0, 1),
1060 SENSOR_ATTR_2(temp3_auto_point2_temp_hyst, S_IRUGO,
1061 show_pwm_auto_point_temp_hyst, NULL, 1, 1),
1062 SENSOR_ATTR_2(temp3_auto_point3_temp_hyst, S_IRUGO,
1063 show_pwm_auto_point_temp_hyst, NULL, 2, 1),
1064 SENSOR_ATTR_2(temp3_auto_point4_temp_hyst, S_IRUGO,
1065 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
Hans de Goede55840142011-09-09 12:12:33 +02001066} };
Hans de Goede45fb3662007-07-13 14:34:19 +02001067
1068/* Super I/O functions */
1069static inline int superio_inb(int base, int reg)
1070{
1071 outb(reg, base);
1072 return inb(base + 1);
1073}
1074
1075static int superio_inw(int base, int reg)
1076{
1077 int val;
Giel van Schijndelbd328ac2010-05-27 19:58:42 +02001078 val = superio_inb(base, reg) << 8;
1079 val |= superio_inb(base, reg + 1);
Hans de Goede45fb3662007-07-13 14:34:19 +02001080 return val;
1081}
1082
Giel van Schijndelcadb8652010-10-03 08:09:49 -04001083static inline int superio_enter(int base)
Hans de Goede45fb3662007-07-13 14:34:19 +02001084{
Giel van Schijndelcadb8652010-10-03 08:09:49 -04001085 /* Don't step on other drivers' I/O space by accident */
1086 if (!request_muxed_region(base, 2, DRVNAME)) {
Joe Perches22d3b412010-10-20 06:51:34 +00001087 pr_err("I/O address 0x%04x already in use\n", base);
Giel van Schijndelcadb8652010-10-03 08:09:49 -04001088 return -EBUSY;
1089 }
1090
Hans de Goede45fb3662007-07-13 14:34:19 +02001091 /* according to the datasheet the key must be send twice! */
Giel van Schijndel162bb592010-05-27 19:58:40 +02001092 outb(SIO_UNLOCK_KEY, base);
1093 outb(SIO_UNLOCK_KEY, base);
Giel van Schijndelcadb8652010-10-03 08:09:49 -04001094
1095 return 0;
Hans de Goede45fb3662007-07-13 14:34:19 +02001096}
1097
Giel van Schijndel162bb592010-05-27 19:58:40 +02001098static inline void superio_select(int base, int ld)
Hans de Goede45fb3662007-07-13 14:34:19 +02001099{
1100 outb(SIO_REG_LDSEL, base);
1101 outb(ld, base + 1);
1102}
1103
1104static inline void superio_exit(int base)
1105{
1106 outb(SIO_LOCK_KEY, base);
Giel van Schijndelcadb8652010-10-03 08:09:49 -04001107 release_region(base, 2);
Hans de Goede45fb3662007-07-13 14:34:19 +02001108}
1109
Hans de Goede2f650632009-01-07 16:37:31 +01001110static inline int fan_from_reg(u16 reg)
Hans de Goede45fb3662007-07-13 14:34:19 +02001111{
1112 return reg ? (1500000 / reg) : 0;
1113}
1114
Hans de Goede2f650632009-01-07 16:37:31 +01001115static inline u16 fan_to_reg(int fan)
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001116{
1117 return fan ? (1500000 / fan) : 0;
1118}
1119
Hans de Goede45fb3662007-07-13 14:34:19 +02001120static u8 f71882fg_read8(struct f71882fg_data *data, u8 reg)
1121{
1122 u8 val;
1123
1124 outb(reg, data->addr + ADDR_REG_OFFSET);
1125 val = inb(data->addr + DATA_REG_OFFSET);
1126
1127 return val;
1128}
1129
1130static u16 f71882fg_read16(struct f71882fg_data *data, u8 reg)
1131{
1132 u16 val;
1133
Giel van Schijndelbd328ac2010-05-27 19:58:42 +02001134 val = f71882fg_read8(data, reg) << 8;
1135 val |= f71882fg_read8(data, reg + 1);
Hans de Goede45fb3662007-07-13 14:34:19 +02001136
1137 return val;
1138}
1139
1140static void f71882fg_write8(struct f71882fg_data *data, u8 reg, u8 val)
1141{
1142 outb(reg, data->addr + ADDR_REG_OFFSET);
1143 outb(val, data->addr + DATA_REG_OFFSET);
1144}
1145
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001146static void f71882fg_write16(struct f71882fg_data *data, u8 reg, u16 val)
1147{
Giel van Schijndelbd328ac2010-05-27 19:58:42 +02001148 f71882fg_write8(data, reg, val >> 8);
1149 f71882fg_write8(data, reg + 1, val & 0xff);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001150}
1151
Hans de Goede09475d32009-06-15 18:39:52 +02001152static u16 f71882fg_read_temp(struct f71882fg_data *data, int nr)
1153{
1154 if (data->type == f71858fg)
1155 return f71882fg_read16(data, F71882FG_REG_TEMP(nr));
1156 else
1157 return f71882fg_read8(data, F71882FG_REG_TEMP(nr));
1158}
1159
Mark van Doesburg77a4a3e2009-01-07 16:37:27 +01001160static struct f71882fg_data *f71882fg_update_device(struct device *dev)
Hans de Goede45fb3662007-07-13 14:34:19 +02001161{
1162 struct f71882fg_data *data = dev_get_drvdata(dev);
Jean Delvaref27def02011-03-26 10:45:01 +01001163 int nr_fans = f71882fg_nr_fans[data->type];
1164 int nr_temps = f71882fg_nr_temps[data->type];
Hans de Goedee5e713c2011-03-10 08:54:02 +01001165 int nr, reg, point;
Hans de Goede45fb3662007-07-13 14:34:19 +02001166
1167 mutex_lock(&data->update_lock);
1168
1169 /* Update once every 60 seconds */
Giel van Schijndel162bb592010-05-27 19:58:40 +02001170 if (time_after(jiffies, data->last_limits + 60 * HZ) ||
Hans de Goede45fb3662007-07-13 14:34:19 +02001171 !data->valid) {
Hans de Goede0bae6402011-03-09 20:57:10 +01001172 if (f71882fg_has_in1_alarm[data->type]) {
Hans de Goede498be962009-01-07 16:37:28 +01001173 data->in1_max =
1174 f71882fg_read8(data, F71882FG_REG_IN1_HIGH);
1175 data->in_beep =
1176 f71882fg_read8(data, F71882FG_REG_IN_BEEP);
1177 }
Hans de Goede45fb3662007-07-13 14:34:19 +02001178
1179 /* Get High & boundary temps*/
Hans de Goedee5e713c2011-03-10 08:54:02 +01001180 for (nr = data->temp_start; nr < nr_temps + data->temp_start;
1181 nr++) {
Hans de Goede45fb3662007-07-13 14:34:19 +02001182 data->temp_ovt[nr] = f71882fg_read8(data,
1183 F71882FG_REG_TEMP_OVT(nr));
1184 data->temp_high[nr] = f71882fg_read8(data,
1185 F71882FG_REG_TEMP_HIGH(nr));
1186 }
1187
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001188 if (data->type != f8000) {
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001189 data->temp_hyst[0] = f71882fg_read8(data,
1190 F71882FG_REG_TEMP_HYST(0));
1191 data->temp_hyst[1] = f71882fg_read8(data,
1192 F71882FG_REG_TEMP_HYST(1));
Hans de Goede09475d32009-06-15 18:39:52 +02001193 }
Hans de Goede78aa4f72011-03-09 20:57:12 +01001194 /* All but the f71858fg / f8000 have this register */
1195 if ((data->type != f71858fg) && (data->type != f8000)) {
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001196 reg = f71882fg_read8(data, F71882FG_REG_TEMP_TYPE);
Hans de Goede44c4dc52011-03-09 20:57:07 +01001197 data->temp_type[1] = (reg & 0x02) ? 2 : 4;
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001198 data->temp_type[2] = (reg & 0x04) ? 2 : 4;
1199 data->temp_type[3] = (reg & 0x08) ? 2 : 4;
1200 }
Hans de Goede45fb3662007-07-13 14:34:19 +02001201
Hans de Goede4d538112011-05-25 20:43:32 +02001202 if (f71882fg_fan_has_beep[data->type])
Hans de Goede78aa4f72011-03-09 20:57:12 +01001203 data->fan_beep = f71882fg_read8(data,
1204 F71882FG_REG_FAN_BEEP);
Hans de Goede4d538112011-05-25 20:43:32 +02001205
1206 if (f71882fg_temp_has_beep[data->type])
Hans de Goede78aa4f72011-03-09 20:57:12 +01001207 data->temp_beep = f71882fg_read8(data,
1208 F71882FG_REG_TEMP_BEEP);
Hans de Goede78aa4f72011-03-09 20:57:12 +01001209
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001210 data->pwm_enable = f71882fg_read8(data,
1211 F71882FG_REG_PWM_ENABLE);
Hans de Goedebc274902009-01-07 16:37:29 +01001212 data->pwm_auto_point_hyst[0] =
1213 f71882fg_read8(data, F71882FG_REG_FAN_HYST(0));
1214 data->pwm_auto_point_hyst[1] =
1215 f71882fg_read8(data, F71882FG_REG_FAN_HYST(1));
1216
Hans de Goede498be962009-01-07 16:37:28 +01001217 for (nr = 0; nr < nr_fans; nr++) {
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001218 data->pwm_auto_point_mapping[nr] =
1219 f71882fg_read8(data,
1220 F71882FG_REG_POINT_MAPPING(nr));
1221
Hans de Goedee5e713c2011-03-10 08:54:02 +01001222 switch (data->type) {
1223 default:
Hans de Goede498be962009-01-07 16:37:28 +01001224 for (point = 0; point < 5; point++) {
1225 data->pwm_auto_point_pwm[nr][point] =
1226 f71882fg_read8(data,
1227 F71882FG_REG_POINT_PWM
1228 (nr, point));
1229 }
1230 for (point = 0; point < 4; point++) {
1231 data->pwm_auto_point_temp[nr][point] =
1232 f71882fg_read8(data,
1233 F71882FG_REG_POINT_TEMP
1234 (nr, point));
1235 }
Hans de Goedee5e713c2011-03-10 08:54:02 +01001236 break;
1237 case f71808e:
1238 case f71869:
1239 data->pwm_auto_point_pwm[nr][0] =
1240 f71882fg_read8(data,
1241 F71882FG_REG_POINT_PWM(nr, 0));
1242 /* Fall through */
1243 case f71862fg:
Hans de Goede498be962009-01-07 16:37:28 +01001244 data->pwm_auto_point_pwm[nr][1] =
1245 f71882fg_read8(data,
1246 F71882FG_REG_POINT_PWM
1247 (nr, 1));
1248 data->pwm_auto_point_pwm[nr][4] =
1249 f71882fg_read8(data,
1250 F71882FG_REG_POINT_PWM
1251 (nr, 4));
1252 data->pwm_auto_point_temp[nr][0] =
1253 f71882fg_read8(data,
1254 F71882FG_REG_POINT_TEMP
1255 (nr, 0));
1256 data->pwm_auto_point_temp[nr][3] =
1257 f71882fg_read8(data,
1258 F71882FG_REG_POINT_TEMP
1259 (nr, 3));
Hans de Goedee5e713c2011-03-10 08:54:02 +01001260 break;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001261 }
1262 }
Hans de Goede45fb3662007-07-13 14:34:19 +02001263 data->last_limits = jiffies;
1264 }
1265
1266 /* Update every second */
Mark M. Hoffman8afb1042007-08-21 23:10:46 -04001267 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
Hans de Goede45fb3662007-07-13 14:34:19 +02001268 data->temp_status = f71882fg_read8(data,
1269 F71882FG_REG_TEMP_STATUS);
1270 data->temp_diode_open = f71882fg_read8(data,
1271 F71882FG_REG_TEMP_DIODE_OPEN);
Hans de Goedee5e713c2011-03-10 08:54:02 +01001272 for (nr = data->temp_start; nr < nr_temps + data->temp_start;
1273 nr++)
Hans de Goede09475d32009-06-15 18:39:52 +02001274 data->temp[nr] = f71882fg_read_temp(data, nr);
Hans de Goede45fb3662007-07-13 14:34:19 +02001275
1276 data->fan_status = f71882fg_read8(data,
1277 F71882FG_REG_FAN_STATUS);
Hans de Goede498be962009-01-07 16:37:28 +01001278 for (nr = 0; nr < nr_fans; nr++) {
Hans de Goede45fb3662007-07-13 14:34:19 +02001279 data->fan[nr] = f71882fg_read16(data,
1280 F71882FG_REG_FAN(nr));
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001281 data->fan_target[nr] =
1282 f71882fg_read16(data, F71882FG_REG_FAN_TARGET(nr));
1283 data->fan_full_speed[nr] =
1284 f71882fg_read16(data,
1285 F71882FG_REG_FAN_FULL_SPEED(nr));
1286 data->pwm[nr] =
1287 f71882fg_read8(data, F71882FG_REG_PWM(nr));
1288 }
Hans de Goede629c58b2011-05-25 20:43:32 +02001289 /* Some models have 1 more fan with limited capabilities */
1290 if (data->type == f71808a) {
1291 data->fan[2] = f71882fg_read16(data,
1292 F71882FG_REG_FAN(2));
1293 data->pwm[2] = f71882fg_read8(data,
1294 F71882FG_REG_PWM(2));
1295 }
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001296 if (data->type == f8000)
1297 data->fan[3] = f71882fg_read16(data,
1298 F71882FG_REG_FAN(3));
Hans de Goede0bae6402011-03-09 20:57:10 +01001299
1300 if (f71882fg_has_in1_alarm[data->type])
Hans de Goede498be962009-01-07 16:37:28 +01001301 data->in_status = f71882fg_read8(data,
Hans de Goede45fb3662007-07-13 14:34:19 +02001302 F71882FG_REG_IN_STATUS);
Hans de Goede0bae6402011-03-09 20:57:10 +01001303 for (nr = 0; nr < F71882FG_MAX_INS; nr++)
1304 if (f71882fg_has_in[data->type][nr])
1305 data->in[nr] = f71882fg_read8(data,
1306 F71882FG_REG_IN(nr));
Hans de Goede45fb3662007-07-13 14:34:19 +02001307
1308 data->last_updated = jiffies;
1309 data->valid = 1;
1310 }
1311
1312 mutex_unlock(&data->update_lock);
1313
1314 return data;
1315}
1316
1317/* Sysfs Interface */
1318static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
1319 char *buf)
1320{
1321 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001322 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001323 int speed = fan_from_reg(data->fan[nr]);
1324
1325 if (speed == FAN_MIN_DETECT)
1326 speed = 0;
1327
1328 return sprintf(buf, "%d\n", speed);
1329}
1330
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001331static ssize_t show_fan_full_speed(struct device *dev,
1332 struct device_attribute *devattr, char *buf)
1333{
1334 struct f71882fg_data *data = f71882fg_update_device(dev);
1335 int nr = to_sensor_dev_attr_2(devattr)->index;
1336 int speed = fan_from_reg(data->fan_full_speed[nr]);
1337 return sprintf(buf, "%d\n", speed);
1338}
1339
1340static ssize_t store_fan_full_speed(struct device *dev,
1341 struct device_attribute *devattr,
1342 const char *buf, size_t count)
1343{
1344 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001345 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1346 long val;
1347
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001348 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001349 if (err)
1350 return err;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001351
Guenter Roeck2a844c12013-01-09 08:09:34 -08001352 val = clamp_val(val, 23, 1500000);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001353 val = fan_to_reg(val);
1354
1355 mutex_lock(&data->update_lock);
Hans de Goede4c82c382009-01-07 16:37:30 +01001356 f71882fg_write16(data, F71882FG_REG_FAN_FULL_SPEED(nr), val);
1357 data->fan_full_speed[nr] = val;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001358 mutex_unlock(&data->update_lock);
1359
1360 return count;
1361}
1362
Hans de Goede45fb3662007-07-13 14:34:19 +02001363static ssize_t show_fan_beep(struct device *dev, struct device_attribute
1364 *devattr, char *buf)
1365{
1366 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001367 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001368
1369 if (data->fan_beep & (1 << nr))
1370 return sprintf(buf, "1\n");
1371 else
1372 return sprintf(buf, "0\n");
1373}
1374
1375static ssize_t store_fan_beep(struct device *dev, struct device_attribute
1376 *devattr, const char *buf, size_t count)
1377{
1378 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001379 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1380 unsigned long val;
1381
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001382 err = kstrtoul(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001383 if (err)
1384 return err;
Hans de Goede45fb3662007-07-13 14:34:19 +02001385
1386 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01001387 data->fan_beep = f71882fg_read8(data, F71882FG_REG_FAN_BEEP);
Hans de Goede45fb3662007-07-13 14:34:19 +02001388 if (val)
1389 data->fan_beep |= 1 << nr;
1390 else
1391 data->fan_beep &= ~(1 << nr);
1392
1393 f71882fg_write8(data, F71882FG_REG_FAN_BEEP, data->fan_beep);
1394 mutex_unlock(&data->update_lock);
1395
1396 return count;
1397}
1398
1399static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
1400 *devattr, char *buf)
1401{
1402 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001403 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001404
1405 if (data->fan_status & (1 << nr))
1406 return sprintf(buf, "1\n");
1407 else
1408 return sprintf(buf, "0\n");
1409}
1410
1411static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
1412 char *buf)
1413{
1414 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001415 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001416
1417 return sprintf(buf, "%d\n", data->in[nr] * 8);
1418}
1419
1420static ssize_t show_in_max(struct device *dev, struct device_attribute
1421 *devattr, char *buf)
1422{
1423 struct f71882fg_data *data = f71882fg_update_device(dev);
1424
1425 return sprintf(buf, "%d\n", data->in1_max * 8);
1426}
1427
1428static ssize_t store_in_max(struct device *dev, struct device_attribute
1429 *devattr, const char *buf, size_t count)
1430{
1431 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001432 int err;
1433 long val;
1434
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001435 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001436 if (err)
1437 return err;
1438
1439 val /= 8;
Guenter Roeck2a844c12013-01-09 08:09:34 -08001440 val = clamp_val(val, 0, 255);
Hans de Goede45fb3662007-07-13 14:34:19 +02001441
1442 mutex_lock(&data->update_lock);
1443 f71882fg_write8(data, F71882FG_REG_IN1_HIGH, val);
1444 data->in1_max = val;
1445 mutex_unlock(&data->update_lock);
1446
1447 return count;
1448}
1449
1450static ssize_t show_in_beep(struct device *dev, struct device_attribute
1451 *devattr, char *buf)
1452{
1453 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001454 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001455
1456 if (data->in_beep & (1 << nr))
1457 return sprintf(buf, "1\n");
1458 else
1459 return sprintf(buf, "0\n");
1460}
1461
1462static ssize_t store_in_beep(struct device *dev, struct device_attribute
1463 *devattr, const char *buf, size_t count)
1464{
1465 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001466 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1467 unsigned long val;
1468
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001469 err = kstrtoul(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001470 if (err)
1471 return err;
Hans de Goede45fb3662007-07-13 14:34:19 +02001472
1473 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01001474 data->in_beep = f71882fg_read8(data, F71882FG_REG_IN_BEEP);
Hans de Goede45fb3662007-07-13 14:34:19 +02001475 if (val)
1476 data->in_beep |= 1 << nr;
1477 else
1478 data->in_beep &= ~(1 << nr);
1479
1480 f71882fg_write8(data, F71882FG_REG_IN_BEEP, data->in_beep);
1481 mutex_unlock(&data->update_lock);
1482
1483 return count;
1484}
1485
1486static ssize_t show_in_alarm(struct device *dev, struct device_attribute
1487 *devattr, char *buf)
1488{
1489 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001490 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001491
1492 if (data->in_status & (1 << nr))
1493 return sprintf(buf, "1\n");
1494 else
1495 return sprintf(buf, "0\n");
1496}
1497
1498static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
1499 char *buf)
1500{
1501 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001502 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede09475d32009-06-15 18:39:52 +02001503 int sign, temp;
Hans de Goede45fb3662007-07-13 14:34:19 +02001504
Hans de Goede09475d32009-06-15 18:39:52 +02001505 if (data->type == f71858fg) {
1506 /* TEMP_TABLE_SEL 1 or 3 ? */
1507 if (data->temp_config & 1) {
1508 sign = data->temp[nr] & 0x0001;
1509 temp = (data->temp[nr] >> 5) & 0x7ff;
1510 } else {
1511 sign = data->temp[nr] & 0x8000;
1512 temp = (data->temp[nr] >> 5) & 0x3ff;
1513 }
1514 temp *= 125;
1515 if (sign)
1516 temp -= 128000;
1517 } else
1518 temp = data->temp[nr] * 1000;
1519
1520 return sprintf(buf, "%d\n", temp);
Hans de Goede45fb3662007-07-13 14:34:19 +02001521}
1522
1523static ssize_t show_temp_max(struct device *dev, struct device_attribute
1524 *devattr, char *buf)
1525{
1526 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001527 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001528
1529 return sprintf(buf, "%d\n", data->temp_high[nr] * 1000);
1530}
1531
1532static ssize_t store_temp_max(struct device *dev, struct device_attribute
1533 *devattr, const char *buf, size_t count)
1534{
1535 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001536 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1537 long val;
1538
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001539 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001540 if (err)
1541 return err;
1542
1543 val /= 1000;
Guenter Roeck2a844c12013-01-09 08:09:34 -08001544 val = clamp_val(val, 0, 255);
Hans de Goede45fb3662007-07-13 14:34:19 +02001545
1546 mutex_lock(&data->update_lock);
1547 f71882fg_write8(data, F71882FG_REG_TEMP_HIGH(nr), val);
1548 data->temp_high[nr] = val;
1549 mutex_unlock(&data->update_lock);
1550
1551 return count;
1552}
1553
1554static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
1555 *devattr, char *buf)
1556{
1557 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001558 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goedece0bfa52009-01-07 16:37:28 +01001559 int temp_max_hyst;
Hans de Goede45fb3662007-07-13 14:34:19 +02001560
Hans de Goedece0bfa52009-01-07 16:37:28 +01001561 mutex_lock(&data->update_lock);
Hans de Goedebc274902009-01-07 16:37:29 +01001562 if (nr & 1)
1563 temp_max_hyst = data->temp_hyst[nr / 2] >> 4;
1564 else
1565 temp_max_hyst = data->temp_hyst[nr / 2] & 0x0f;
1566 temp_max_hyst = (data->temp_high[nr] - temp_max_hyst) * 1000;
Hans de Goedece0bfa52009-01-07 16:37:28 +01001567 mutex_unlock(&data->update_lock);
1568
1569 return sprintf(buf, "%d\n", temp_max_hyst);
Hans de Goede45fb3662007-07-13 14:34:19 +02001570}
1571
1572static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
1573 *devattr, const char *buf, size_t count)
1574{
1575 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001576 int err, nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001577 ssize_t ret = count;
Hans de Goedece0bfa52009-01-07 16:37:28 +01001578 u8 reg;
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001579 long val;
1580
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001581 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001582 if (err)
1583 return err;
1584
1585 val /= 1000;
Hans de Goede45fb3662007-07-13 14:34:19 +02001586
1587 mutex_lock(&data->update_lock);
1588
1589 /* convert abs to relative and check */
Hans de Goedece0bfa52009-01-07 16:37:28 +01001590 data->temp_high[nr] = f71882fg_read8(data, F71882FG_REG_TEMP_HIGH(nr));
Guenter Roeck2a844c12013-01-09 08:09:34 -08001591 val = clamp_val(val, data->temp_high[nr] - 15, data->temp_high[nr]);
Hans de Goede45fb3662007-07-13 14:34:19 +02001592 val = data->temp_high[nr] - val;
Hans de Goede45fb3662007-07-13 14:34:19 +02001593
1594 /* convert value to register contents */
Hans de Goedebc274902009-01-07 16:37:29 +01001595 reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST(nr / 2));
1596 if (nr & 1)
1597 reg = (reg & 0x0f) | (val << 4);
1598 else
1599 reg = (reg & 0xf0) | val;
1600 f71882fg_write8(data, F71882FG_REG_TEMP_HYST(nr / 2), reg);
1601 data->temp_hyst[nr / 2] = reg;
Hans de Goede45fb3662007-07-13 14:34:19 +02001602
Hans de Goede45fb3662007-07-13 14:34:19 +02001603 mutex_unlock(&data->update_lock);
1604 return ret;
1605}
1606
1607static ssize_t show_temp_crit(struct device *dev, struct device_attribute
1608 *devattr, char *buf)
1609{
1610 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001611 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001612
1613 return sprintf(buf, "%d\n", data->temp_ovt[nr] * 1000);
1614}
1615
1616static ssize_t store_temp_crit(struct device *dev, struct device_attribute
1617 *devattr, const char *buf, size_t count)
1618{
1619 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001620 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1621 long val;
1622
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001623 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001624 if (err)
1625 return err;
1626
1627 val /= 1000;
Guenter Roeck2a844c12013-01-09 08:09:34 -08001628 val = clamp_val(val, 0, 255);
Hans de Goede45fb3662007-07-13 14:34:19 +02001629
1630 mutex_lock(&data->update_lock);
1631 f71882fg_write8(data, F71882FG_REG_TEMP_OVT(nr), val);
1632 data->temp_ovt[nr] = val;
1633 mutex_unlock(&data->update_lock);
1634
1635 return count;
1636}
1637
1638static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
1639 *devattr, char *buf)
1640{
1641 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001642 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goedece0bfa52009-01-07 16:37:28 +01001643 int temp_crit_hyst;
Hans de Goede45fb3662007-07-13 14:34:19 +02001644
Hans de Goedece0bfa52009-01-07 16:37:28 +01001645 mutex_lock(&data->update_lock);
Hans de Goedebc274902009-01-07 16:37:29 +01001646 if (nr & 1)
1647 temp_crit_hyst = data->temp_hyst[nr / 2] >> 4;
1648 else
1649 temp_crit_hyst = data->temp_hyst[nr / 2] & 0x0f;
1650 temp_crit_hyst = (data->temp_ovt[nr] - temp_crit_hyst) * 1000;
Hans de Goedece0bfa52009-01-07 16:37:28 +01001651 mutex_unlock(&data->update_lock);
1652
1653 return sprintf(buf, "%d\n", temp_crit_hyst);
Hans de Goede45fb3662007-07-13 14:34:19 +02001654}
1655
1656static ssize_t show_temp_type(struct device *dev, struct device_attribute
1657 *devattr, char *buf)
1658{
1659 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001660 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001661
1662 return sprintf(buf, "%d\n", data->temp_type[nr]);
1663}
1664
1665static ssize_t show_temp_beep(struct device *dev, struct device_attribute
1666 *devattr, char *buf)
1667{
1668 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001669 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001670
Hans de Goede7567a042009-01-07 16:37:28 +01001671 if (data->temp_beep & (1 << nr))
Hans de Goede45fb3662007-07-13 14:34:19 +02001672 return sprintf(buf, "1\n");
1673 else
1674 return sprintf(buf, "0\n");
1675}
1676
1677static ssize_t store_temp_beep(struct device *dev, struct device_attribute
1678 *devattr, const char *buf, size_t count)
1679{
1680 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001681 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1682 unsigned long val;
1683
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001684 err = kstrtoul(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001685 if (err)
1686 return err;
Hans de Goede45fb3662007-07-13 14:34:19 +02001687
1688 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01001689 data->temp_beep = f71882fg_read8(data, F71882FG_REG_TEMP_BEEP);
Hans de Goede45fb3662007-07-13 14:34:19 +02001690 if (val)
Hans de Goede7567a042009-01-07 16:37:28 +01001691 data->temp_beep |= 1 << nr;
Hans de Goede45fb3662007-07-13 14:34:19 +02001692 else
Hans de Goede7567a042009-01-07 16:37:28 +01001693 data->temp_beep &= ~(1 << nr);
Hans de Goede45fb3662007-07-13 14:34:19 +02001694
1695 f71882fg_write8(data, F71882FG_REG_TEMP_BEEP, data->temp_beep);
1696 mutex_unlock(&data->update_lock);
1697
1698 return count;
1699}
1700
1701static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
1702 *devattr, char *buf)
1703{
1704 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001705 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001706
Hans de Goede7567a042009-01-07 16:37:28 +01001707 if (data->temp_status & (1 << nr))
Hans de Goede45fb3662007-07-13 14:34:19 +02001708 return sprintf(buf, "1\n");
1709 else
1710 return sprintf(buf, "0\n");
1711}
1712
1713static ssize_t show_temp_fault(struct device *dev, struct device_attribute
1714 *devattr, char *buf)
1715{
1716 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001717 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001718
Hans de Goede7567a042009-01-07 16:37:28 +01001719 if (data->temp_diode_open & (1 << nr))
Hans de Goede45fb3662007-07-13 14:34:19 +02001720 return sprintf(buf, "1\n");
1721 else
1722 return sprintf(buf, "0\n");
1723}
1724
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001725static ssize_t show_pwm(struct device *dev,
1726 struct device_attribute *devattr, char *buf)
1727{
1728 struct f71882fg_data *data = f71882fg_update_device(dev);
1729 int val, nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goedece0bfa52009-01-07 16:37:28 +01001730 mutex_lock(&data->update_lock);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001731 if (data->pwm_enable & (1 << (2 * nr)))
1732 /* PWM mode */
1733 val = data->pwm[nr];
1734 else {
1735 /* RPM mode */
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001736 val = 255 * fan_from_reg(data->fan_target[nr])
1737 / fan_from_reg(data->fan_full_speed[nr]);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001738 }
Hans de Goedece0bfa52009-01-07 16:37:28 +01001739 mutex_unlock(&data->update_lock);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001740 return sprintf(buf, "%d\n", val);
1741}
1742
1743static ssize_t store_pwm(struct device *dev,
1744 struct device_attribute *devattr, const char *buf,
1745 size_t count)
1746{
Hans de Goedece0bfa52009-01-07 16:37:28 +01001747 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001748 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1749 long val;
1750
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001751 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001752 if (err)
1753 return err;
1754
Guenter Roeck2a844c12013-01-09 08:09:34 -08001755 val = clamp_val(val, 0, 255);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001756
1757 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01001758 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001759 if ((data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 3) != 2) ||
1760 (data->type != f8000 && !((data->pwm_enable >> 2 * nr) & 2))) {
1761 count = -EROFS;
1762 goto leave;
1763 }
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001764 if (data->pwm_enable & (1 << (2 * nr))) {
1765 /* PWM mode */
1766 f71882fg_write8(data, F71882FG_REG_PWM(nr), val);
1767 data->pwm[nr] = val;
1768 } else {
1769 /* RPM mode */
Hans de Goedece0bfa52009-01-07 16:37:28 +01001770 int target, full_speed;
1771 full_speed = f71882fg_read16(data,
1772 F71882FG_REG_FAN_FULL_SPEED(nr));
1773 target = fan_to_reg(val * fan_from_reg(full_speed) / 255);
1774 f71882fg_write16(data, F71882FG_REG_FAN_TARGET(nr), target);
1775 data->fan_target[nr] = target;
1776 data->fan_full_speed[nr] = full_speed;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001777 }
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001778leave:
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001779 mutex_unlock(&data->update_lock);
1780
1781 return count;
1782}
1783
Hans de Goede629c58b2011-05-25 20:43:32 +02001784static ssize_t show_simple_pwm(struct device *dev,
1785 struct device_attribute *devattr, char *buf)
1786{
1787 struct f71882fg_data *data = f71882fg_update_device(dev);
1788 int val, nr = to_sensor_dev_attr_2(devattr)->index;
1789
1790 val = data->pwm[nr];
1791 return sprintf(buf, "%d\n", val);
1792}
1793
1794static ssize_t store_simple_pwm(struct device *dev,
1795 struct device_attribute *devattr,
1796 const char *buf, size_t count)
1797{
1798 struct f71882fg_data *data = dev_get_drvdata(dev);
1799 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1800 long val;
1801
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001802 err = kstrtol(buf, 10, &val);
Hans de Goede629c58b2011-05-25 20:43:32 +02001803 if (err)
1804 return err;
1805
Guenter Roeck2a844c12013-01-09 08:09:34 -08001806 val = clamp_val(val, 0, 255);
Hans de Goede629c58b2011-05-25 20:43:32 +02001807
1808 mutex_lock(&data->update_lock);
1809 f71882fg_write8(data, F71882FG_REG_PWM(nr), val);
1810 data->pwm[nr] = val;
1811 mutex_unlock(&data->update_lock);
1812
1813 return count;
1814}
1815
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001816static ssize_t show_pwm_enable(struct device *dev,
1817 struct device_attribute *devattr, char *buf)
1818{
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001819 int result = 0;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001820 struct f71882fg_data *data = f71882fg_update_device(dev);
1821 int nr = to_sensor_dev_attr_2(devattr)->index;
1822
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001823 switch ((data->pwm_enable >> 2 * nr) & 3) {
1824 case 0:
1825 case 1:
1826 result = 2; /* Normal auto mode */
1827 break;
1828 case 2:
1829 result = 1; /* Manual mode */
1830 break;
1831 case 3:
1832 if (data->type == f8000)
1833 result = 3; /* Thermostat mode */
1834 else
1835 result = 1; /* Manual mode */
1836 break;
1837 }
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001838
1839 return sprintf(buf, "%d\n", result);
1840}
1841
1842static ssize_t store_pwm_enable(struct device *dev, struct device_attribute
1843 *devattr, const char *buf, size_t count)
1844{
1845 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001846 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1847 long val;
1848
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001849 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001850 if (err)
1851 return err;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001852
Hans de Goede3fc78382009-06-15 18:39:50 +02001853 /* Special case for F8000 pwm channel 3 which only does auto mode */
1854 if (data->type == f8000 && nr == 2 && val != 2)
1855 return -EINVAL;
1856
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001857 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01001858 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001859 /* Special case for F8000 auto PWM mode / Thermostat mode */
1860 if (data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 1)) {
1861 switch (val) {
1862 case 2:
1863 data->pwm_enable &= ~(2 << (2 * nr));
1864 break; /* Normal auto mode */
1865 case 3:
1866 data->pwm_enable |= 2 << (2 * nr);
1867 break; /* Thermostat mode */
1868 default:
1869 count = -EINVAL;
1870 goto leave;
1871 }
1872 } else {
1873 switch (val) {
1874 case 1:
Hans de Goede09475d32009-06-15 18:39:52 +02001875 /* The f71858fg does not support manual RPM mode */
1876 if (data->type == f71858fg &&
1877 ((data->pwm_enable >> (2 * nr)) & 1)) {
1878 count = -EINVAL;
1879 goto leave;
1880 }
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001881 data->pwm_enable |= 2 << (2 * nr);
1882 break; /* Manual */
1883 case 2:
1884 data->pwm_enable &= ~(2 << (2 * nr));
1885 break; /* Normal auto mode */
1886 default:
1887 count = -EINVAL;
1888 goto leave;
1889 }
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001890 }
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001891 f71882fg_write8(data, F71882FG_REG_PWM_ENABLE, data->pwm_enable);
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001892leave:
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001893 mutex_unlock(&data->update_lock);
1894
1895 return count;
1896}
1897
1898static ssize_t show_pwm_auto_point_pwm(struct device *dev,
1899 struct device_attribute *devattr,
1900 char *buf)
1901{
1902 int result;
1903 struct f71882fg_data *data = f71882fg_update_device(dev);
1904 int pwm = to_sensor_dev_attr_2(devattr)->index;
1905 int point = to_sensor_dev_attr_2(devattr)->nr;
1906
Hans de Goedece0bfa52009-01-07 16:37:28 +01001907 mutex_lock(&data->update_lock);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001908 if (data->pwm_enable & (1 << (2 * pwm))) {
1909 /* PWM mode */
1910 result = data->pwm_auto_point_pwm[pwm][point];
1911 } else {
1912 /* RPM mode */
1913 result = 32 * 255 / (32 + data->pwm_auto_point_pwm[pwm][point]);
1914 }
Hans de Goedece0bfa52009-01-07 16:37:28 +01001915 mutex_unlock(&data->update_lock);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001916
1917 return sprintf(buf, "%d\n", result);
1918}
1919
1920static ssize_t store_pwm_auto_point_pwm(struct device *dev,
1921 struct device_attribute *devattr,
1922 const char *buf, size_t count)
1923{
Hans de Goedece0bfa52009-01-07 16:37:28 +01001924 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001925 int err, pwm = to_sensor_dev_attr_2(devattr)->index;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001926 int point = to_sensor_dev_attr_2(devattr)->nr;
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001927 long val;
1928
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001929 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001930 if (err)
1931 return err;
1932
Guenter Roeck2a844c12013-01-09 08:09:34 -08001933 val = clamp_val(val, 0, 255);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001934
1935 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01001936 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001937 if (data->pwm_enable & (1 << (2 * pwm))) {
1938 /* PWM mode */
1939 } else {
1940 /* RPM mode */
1941 if (val < 29) /* Prevent negative numbers */
1942 val = 255;
1943 else
1944 val = (255 - val) * 32 / val;
1945 }
1946 f71882fg_write8(data, F71882FG_REG_POINT_PWM(pwm, point), val);
1947 data->pwm_auto_point_pwm[pwm][point] = val;
1948 mutex_unlock(&data->update_lock);
1949
1950 return count;
1951}
1952
1953static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
1954 struct device_attribute *devattr,
1955 char *buf)
1956{
1957 int result = 0;
1958 struct f71882fg_data *data = f71882fg_update_device(dev);
1959 int nr = to_sensor_dev_attr_2(devattr)->index;
1960 int point = to_sensor_dev_attr_2(devattr)->nr;
1961
1962 mutex_lock(&data->update_lock);
Hans de Goedebc274902009-01-07 16:37:29 +01001963 if (nr & 1)
1964 result = data->pwm_auto_point_hyst[nr / 2] >> 4;
1965 else
1966 result = data->pwm_auto_point_hyst[nr / 2] & 0x0f;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001967 result = 1000 * (data->pwm_auto_point_temp[nr][point] - result);
1968 mutex_unlock(&data->update_lock);
1969
1970 return sprintf(buf, "%d\n", result);
1971}
1972
1973static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
1974 struct device_attribute *devattr,
1975 const char *buf, size_t count)
1976{
Hans de Goedece0bfa52009-01-07 16:37:28 +01001977 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001978 int err, nr = to_sensor_dev_attr_2(devattr)->index;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001979 int point = to_sensor_dev_attr_2(devattr)->nr;
Hans de Goedebc274902009-01-07 16:37:29 +01001980 u8 reg;
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001981 long val;
1982
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001983 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001984 if (err)
1985 return err;
1986
1987 val /= 1000;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001988
1989 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01001990 data->pwm_auto_point_temp[nr][point] =
1991 f71882fg_read8(data, F71882FG_REG_POINT_TEMP(nr, point));
Guenter Roeck2a844c12013-01-09 08:09:34 -08001992 val = clamp_val(val, data->pwm_auto_point_temp[nr][point] - 15,
1993 data->pwm_auto_point_temp[nr][point]);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001994 val = data->pwm_auto_point_temp[nr][point] - val;
1995
Hans de Goedebc274902009-01-07 16:37:29 +01001996 reg = f71882fg_read8(data, F71882FG_REG_FAN_HYST(nr / 2));
1997 if (nr & 1)
1998 reg = (reg & 0x0f) | (val << 4);
1999 else
2000 reg = (reg & 0xf0) | val;
2001
2002 f71882fg_write8(data, F71882FG_REG_FAN_HYST(nr / 2), reg);
2003 data->pwm_auto_point_hyst[nr / 2] = reg;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002004 mutex_unlock(&data->update_lock);
2005
2006 return count;
2007}
2008
2009static ssize_t show_pwm_interpolate(struct device *dev,
2010 struct device_attribute *devattr, char *buf)
2011{
2012 int result;
2013 struct f71882fg_data *data = f71882fg_update_device(dev);
2014 int nr = to_sensor_dev_attr_2(devattr)->index;
2015
2016 result = (data->pwm_auto_point_mapping[nr] >> 4) & 1;
2017
2018 return sprintf(buf, "%d\n", result);
2019}
2020
2021static ssize_t store_pwm_interpolate(struct device *dev,
2022 struct device_attribute *devattr,
2023 const char *buf, size_t count)
2024{
Hans de Goedece0bfa52009-01-07 16:37:28 +01002025 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002026 int err, nr = to_sensor_dev_attr_2(devattr)->index;
2027 unsigned long val;
2028
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01002029 err = kstrtoul(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002030 if (err)
2031 return err;
Hans de Goedece0bfa52009-01-07 16:37:28 +01002032
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002033 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01002034 data->pwm_auto_point_mapping[nr] =
2035 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002036 if (val)
2037 val = data->pwm_auto_point_mapping[nr] | (1 << 4);
2038 else
2039 val = data->pwm_auto_point_mapping[nr] & (~(1 << 4));
2040 f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val);
2041 data->pwm_auto_point_mapping[nr] = val;
2042 mutex_unlock(&data->update_lock);
2043
2044 return count;
2045}
2046
2047static ssize_t show_pwm_auto_point_channel(struct device *dev,
2048 struct device_attribute *devattr,
2049 char *buf)
2050{
2051 int result;
2052 struct f71882fg_data *data = f71882fg_update_device(dev);
2053 int nr = to_sensor_dev_attr_2(devattr)->index;
2054
Hans de Goede09475d32009-06-15 18:39:52 +02002055 result = 1 << ((data->pwm_auto_point_mapping[nr] & 3) -
2056 data->temp_start);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002057
2058 return sprintf(buf, "%d\n", result);
2059}
2060
2061static ssize_t store_pwm_auto_point_channel(struct device *dev,
2062 struct device_attribute *devattr,
2063 const char *buf, size_t count)
2064{
Hans de Goedece0bfa52009-01-07 16:37:28 +01002065 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002066 int err, nr = to_sensor_dev_attr_2(devattr)->index;
2067 long val;
2068
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01002069 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002070 if (err)
2071 return err;
Hans de Goede30453012009-01-07 16:37:30 +01002072
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002073 switch (val) {
2074 case 1:
Hans de Goede30453012009-01-07 16:37:30 +01002075 val = 0;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002076 break;
2077 case 2:
Hans de Goede30453012009-01-07 16:37:30 +01002078 val = 1;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002079 break;
2080 case 4:
Hans de Goede30453012009-01-07 16:37:30 +01002081 val = 2;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002082 break;
2083 default:
2084 return -EINVAL;
2085 }
Hans de Goede09475d32009-06-15 18:39:52 +02002086 val += data->temp_start;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002087 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01002088 data->pwm_auto_point_mapping[nr] =
2089 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002090 val = (data->pwm_auto_point_mapping[nr] & 0xfc) | val;
2091 f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val);
2092 data->pwm_auto_point_mapping[nr] = val;
2093 mutex_unlock(&data->update_lock);
2094
2095 return count;
2096}
2097
2098static ssize_t show_pwm_auto_point_temp(struct device *dev,
2099 struct device_attribute *devattr,
2100 char *buf)
2101{
2102 int result;
2103 struct f71882fg_data *data = f71882fg_update_device(dev);
2104 int pwm = to_sensor_dev_attr_2(devattr)->index;
2105 int point = to_sensor_dev_attr_2(devattr)->nr;
2106
2107 result = data->pwm_auto_point_temp[pwm][point];
2108 return sprintf(buf, "%d\n", 1000 * result);
2109}
2110
2111static ssize_t store_pwm_auto_point_temp(struct device *dev,
2112 struct device_attribute *devattr,
2113 const char *buf, size_t count)
2114{
Hans de Goedece0bfa52009-01-07 16:37:28 +01002115 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002116 int err, pwm = to_sensor_dev_attr_2(devattr)->index;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002117 int point = to_sensor_dev_attr_2(devattr)->nr;
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002118 long val;
2119
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01002120 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002121 if (err)
2122 return err;
2123
2124 val /= 1000;
Hans de Goede76698962009-12-09 20:36:01 +01002125
Hans de Goede98f7ba12011-03-09 20:57:09 +01002126 if (data->auto_point_temp_signed)
Guenter Roeck2a844c12013-01-09 08:09:34 -08002127 val = clamp_val(val, -128, 127);
Hans de Goede76698962009-12-09 20:36:01 +01002128 else
Guenter Roeck2a844c12013-01-09 08:09:34 -08002129 val = clamp_val(val, 0, 127);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002130
2131 mutex_lock(&data->update_lock);
2132 f71882fg_write8(data, F71882FG_REG_POINT_TEMP(pwm, point), val);
2133 data->pwm_auto_point_temp[pwm][point] = val;
2134 mutex_unlock(&data->update_lock);
2135
2136 return count;
2137}
2138
Hans de Goede45fb3662007-07-13 14:34:19 +02002139static ssize_t show_name(struct device *dev, struct device_attribute *devattr,
2140 char *buf)
2141{
Hans de Goede498be962009-01-07 16:37:28 +01002142 struct f71882fg_data *data = dev_get_drvdata(dev);
2143 return sprintf(buf, "%s\n", f71882fg_names[data->type]);
Hans de Goede45fb3662007-07-13 14:34:19 +02002144}
2145
Bill Pemberton6c931ae2012-11-19 13:22:35 -05002146static int f71882fg_create_sysfs_files(struct platform_device *pdev,
Hans de Goedec13548c2009-01-07 16:37:27 +01002147 struct sensor_device_attribute_2 *attr, int count)
2148{
2149 int err, i;
Hans de Goede45fb3662007-07-13 14:34:19 +02002150
Hans de Goedec13548c2009-01-07 16:37:27 +01002151 for (i = 0; i < count; i++) {
2152 err = device_create_file(&pdev->dev, &attr[i].dev_attr);
2153 if (err)
2154 return err;
2155 }
2156 return 0;
2157}
2158
Hans de Goedefc16c562009-12-09 20:36:01 +01002159static void f71882fg_remove_sysfs_files(struct platform_device *pdev,
2160 struct sensor_device_attribute_2 *attr, int count)
2161{
2162 int i;
2163
2164 for (i = 0; i < count; i++)
2165 device_remove_file(&pdev->dev, &attr[i].dev_attr);
2166}
2167
Bill Pemberton6c931ae2012-11-19 13:22:35 -05002168static int f71882fg_create_fan_sysfs_files(
Hans de Goede65434392011-09-09 12:12:35 +02002169 struct platform_device *pdev, int idx)
Hans de Goede9af07942011-09-09 12:12:34 +02002170{
2171 struct f71882fg_data *data = platform_get_drvdata(pdev);
2172 int err;
2173
Hans de Goede65434392011-09-09 12:12:35 +02002174 /* Sanity check the pwm setting */
2175 err = 0;
2176 switch (data->type) {
2177 case f71858fg:
2178 if (((data->pwm_enable >> (idx * 2)) & 3) == 3)
2179 err = 1;
2180 break;
2181 case f71862fg:
2182 if (((data->pwm_enable >> (idx * 2)) & 1) != 1)
2183 err = 1;
2184 break;
2185 case f8000:
2186 if (idx == 2)
2187 err = data->pwm_enable & 0x20;
2188 break;
2189 default:
2190 break;
2191 }
2192 if (err) {
2193 dev_err(&pdev->dev,
2194 "Invalid (reserved) pwm settings: 0x%02x, "
2195 "skipping fan %d\n",
2196 (data->pwm_enable >> (idx * 2)) & 3, idx + 1);
2197 return 0; /* This is a non fatal condition */
2198 }
2199
Hans de Goede9af07942011-09-09 12:12:34 +02002200 err = f71882fg_create_sysfs_files(pdev, &fxxxx_fan_attr[idx][0],
2201 ARRAY_SIZE(fxxxx_fan_attr[0]));
2202 if (err)
2203 return err;
2204
2205 if (f71882fg_fan_has_beep[data->type]) {
2206 err = f71882fg_create_sysfs_files(pdev,
2207 &fxxxx_fan_beep_attr[idx],
2208 1);
2209 if (err)
2210 return err;
2211 }
2212
Hans de Goede65434392011-09-09 12:12:35 +02002213 dev_info(&pdev->dev, "Fan: %d is in %s mode\n", idx + 1,
2214 (data->pwm_enable & (1 << (2 * idx))) ? "duty-cycle" : "RPM");
2215
2216 /* Check for unsupported auto pwm settings */
2217 switch (data->type) {
2218 case f71808e:
2219 case f71808a:
2220 case f71869:
2221 case f71869a:
2222 case f71889fg:
2223 case f71889ed:
2224 case f71889a:
2225 data->pwm_auto_point_mapping[idx] =
2226 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(idx));
2227 if ((data->pwm_auto_point_mapping[idx] & 0x80) ||
2228 (data->pwm_auto_point_mapping[idx] & 3) == 0) {
2229 dev_warn(&pdev->dev,
2230 "Auto pwm controlled by raw digital "
2231 "data, disabling pwm auto_point "
2232 "sysfs attributes for fan %d\n", idx + 1);
2233 return 0; /* This is a non fatal condition */
2234 }
2235 break;
2236 default:
2237 break;
2238 }
Hans de Goede9af07942011-09-09 12:12:34 +02002239
2240 switch (data->type) {
2241 case f71862fg:
2242 err = f71882fg_create_sysfs_files(pdev,
2243 &f71862fg_auto_pwm_attr[idx][0],
2244 ARRAY_SIZE(f71862fg_auto_pwm_attr[0]));
2245 break;
2246 case f71808e:
2247 case f71869:
2248 err = f71882fg_create_sysfs_files(pdev,
2249 &f71869_auto_pwm_attr[idx][0],
2250 ARRAY_SIZE(f71869_auto_pwm_attr[0]));
2251 break;
2252 case f8000:
2253 err = f71882fg_create_sysfs_files(pdev,
2254 &f8000_auto_pwm_attr[idx][0],
2255 ARRAY_SIZE(f8000_auto_pwm_attr[0]));
2256 break;
2257 default:
2258 err = f71882fg_create_sysfs_files(pdev,
2259 &fxxxx_auto_pwm_attr[idx][0],
2260 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]));
2261 }
2262
2263 return err;
2264}
2265
Bill Pemberton6c931ae2012-11-19 13:22:35 -05002266static int f71882fg_probe(struct platform_device *pdev)
Hans de Goede45fb3662007-07-13 14:34:19 +02002267{
2268 struct f71882fg_data *data;
Jingoo Hana8b3a3a2013-07-30 17:13:06 +09002269 struct f71882fg_sio_data *sio_data = dev_get_platdata(&pdev->dev);
Jean Delvaref27def02011-03-26 10:45:01 +01002270 int nr_fans = f71882fg_nr_fans[sio_data->type];
2271 int nr_temps = f71882fg_nr_temps[sio_data->type];
2272 int err, i;
Hans de Goede98f7ba12011-03-09 20:57:09 +01002273 u8 start_reg, reg;
Hans de Goede45fb3662007-07-13 14:34:19 +02002274
Guenter Roeck33cd66e2012-06-02 09:58:05 -07002275 data = devm_kzalloc(&pdev->dev, sizeof(struct f71882fg_data),
2276 GFP_KERNEL);
Hans de Goedec13548c2009-01-07 16:37:27 +01002277 if (!data)
Hans de Goede45fb3662007-07-13 14:34:19 +02002278 return -ENOMEM;
2279
2280 data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start;
Hans de Goede498be962009-01-07 16:37:28 +01002281 data->type = sio_data->type;
Hans de Goede09475d32009-06-15 18:39:52 +02002282 data->temp_start =
2283 (data->type == f71858fg || data->type == f8000) ? 0 : 1;
Hans de Goede45fb3662007-07-13 14:34:19 +02002284 mutex_init(&data->update_lock);
2285 platform_set_drvdata(pdev, data);
2286
Hans de Goede3cc74752009-01-07 16:37:28 +01002287 start_reg = f71882fg_read8(data, F71882FG_REG_START);
Hans de Goede12d66e82009-01-07 16:37:29 +01002288 if (start_reg & 0x04) {
2289 dev_warn(&pdev->dev, "Hardware monitor is powered down\n");
Guenter Roeck33cd66e2012-06-02 09:58:05 -07002290 return -ENODEV;
Hans de Goede12d66e82009-01-07 16:37:29 +01002291 }
Hans de Goede3cc74752009-01-07 16:37:28 +01002292 if (!(start_reg & 0x03)) {
2293 dev_warn(&pdev->dev, "Hardware monitoring not activated\n");
Guenter Roeck33cd66e2012-06-02 09:58:05 -07002294 return -ENODEV;
Hans de Goede3cc74752009-01-07 16:37:28 +01002295 }
2296
Hans de Goede45fb3662007-07-13 14:34:19 +02002297 /* Register sysfs interface files */
Hans de Goedec13548c2009-01-07 16:37:27 +01002298 err = device_create_file(&pdev->dev, &dev_attr_name);
2299 if (err)
2300 goto exit_unregister_sysfs;
2301
Hans de Goedec13548c2009-01-07 16:37:27 +01002302 if (start_reg & 0x01) {
Hans de Goedeed4f7c22009-01-07 16:37:30 +01002303 switch (data->type) {
Hans de Goede09475d32009-06-15 18:39:52 +02002304 case f71858fg:
2305 data->temp_config =
2306 f71882fg_read8(data, F71882FG_REG_TEMP_CONFIG);
2307 if (data->temp_config & 0x10)
Guenter Roeck20eaf722012-01-19 11:02:17 -08002308 /*
2309 * The f71858fg temperature alarms behave as
2310 * the f8000 alarms in this mode
2311 */
Hans de Goede09475d32009-06-15 18:39:52 +02002312 err = f71882fg_create_sysfs_files(pdev,
Hans de Goede0bae6402011-03-09 20:57:10 +01002313 f8000_temp_attr,
2314 ARRAY_SIZE(f8000_temp_attr));
Hans de Goede09475d32009-06-15 18:39:52 +02002315 else
2316 err = f71882fg_create_sysfs_files(pdev,
Hans de Goede0bae6402011-03-09 20:57:10 +01002317 f71858fg_temp_attr,
2318 ARRAY_SIZE(f71858fg_temp_attr));
Hans de Goede09475d32009-06-15 18:39:52 +02002319 break;
Hans de Goede0bae6402011-03-09 20:57:10 +01002320 case f8000:
2321 err = f71882fg_create_sysfs_files(pdev,
2322 f8000_temp_attr,
2323 ARRAY_SIZE(f8000_temp_attr));
2324 break;
2325 default:
2326 err = f71882fg_create_sysfs_files(pdev,
Hans de Goede60d2b372011-03-09 20:57:11 +01002327 &fxxxx_temp_attr[0][0],
2328 ARRAY_SIZE(fxxxx_temp_attr[0]) * nr_temps);
Hans de Goede0bae6402011-03-09 20:57:10 +01002329 }
2330 if (err)
2331 goto exit_unregister_sysfs;
2332
Hans de Goede4d538112011-05-25 20:43:32 +02002333 if (f71882fg_temp_has_beep[data->type]) {
Hans de Goede78aa4f72011-03-09 20:57:12 +01002334 err = f71882fg_create_sysfs_files(pdev,
2335 &fxxxx_temp_beep_attr[0][0],
2336 ARRAY_SIZE(fxxxx_temp_beep_attr[0])
2337 * nr_temps);
2338 if (err)
2339 goto exit_unregister_sysfs;
2340 }
2341
Hans de Goede0bae6402011-03-09 20:57:10 +01002342 for (i = 0; i < F71882FG_MAX_INS; i++) {
2343 if (f71882fg_has_in[data->type][i]) {
2344 err = device_create_file(&pdev->dev,
2345 &fxxxx_in_attr[i].dev_attr);
2346 if (err)
2347 goto exit_unregister_sysfs;
2348 }
2349 }
2350 if (f71882fg_has_in1_alarm[data->type]) {
Hans de Goede498be962009-01-07 16:37:28 +01002351 err = f71882fg_create_sysfs_files(pdev,
Hans de Goede66344aa2009-12-09 20:35:59 +01002352 fxxxx_in1_alarm_attr,
2353 ARRAY_SIZE(fxxxx_in1_alarm_attr));
Hans de Goede498be962009-01-07 16:37:28 +01002354 if (err)
2355 goto exit_unregister_sysfs;
2356 }
Hans de Goede45fb3662007-07-13 14:34:19 +02002357 }
2358
Hans de Goede45fb3662007-07-13 14:34:19 +02002359 if (start_reg & 0x02) {
Hans de Goede98f7ba12011-03-09 20:57:09 +01002360 switch (data->type) {
Hans de Goedee5e713c2011-03-10 08:54:02 +01002361 case f71808e:
Hans de Goede629c58b2011-05-25 20:43:32 +02002362 case f71808a:
Hans de Goedec11bb992011-03-09 20:57:15 +01002363 case f71869:
Hans de Goede5da556e2011-07-03 13:32:53 +02002364 case f71869a:
Hans de Goedee5e713c2011-03-10 08:54:02 +01002365 /* These always have signed auto point temps */
Hans de Goedec11bb992011-03-09 20:57:15 +01002366 data->auto_point_temp_signed = 1;
2367 /* Fall through to select correct fan/pwm reg bank! */
Hans de Goede98f7ba12011-03-09 20:57:09 +01002368 case f71889fg:
Hans de Goede3cad4022011-03-09 20:57:14 +01002369 case f71889ed:
Hans de Goedea66c1082011-03-26 10:45:02 +01002370 case f71889a:
Hans de Goede98f7ba12011-03-09 20:57:09 +01002371 reg = f71882fg_read8(data, F71882FG_REG_FAN_FAULT_T);
2372 if (reg & F71882FG_FAN_NEG_TEMP_EN)
2373 data->auto_point_temp_signed = 1;
Hans de Goede3cad4022011-03-09 20:57:14 +01002374 /* Ensure banked pwm registers point to right bank */
2375 reg &= ~F71882FG_FAN_PROG_SEL;
2376 f71882fg_write8(data, F71882FG_REG_FAN_FAULT_T, reg);
Hans de Goede98f7ba12011-03-09 20:57:09 +01002377 break;
2378 default:
2379 break;
2380 }
2381
Hans de Goede996cadb2009-06-15 18:39:51 +02002382 data->pwm_enable =
2383 f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
2384
Hans de Goede9af07942011-09-09 12:12:34 +02002385 for (i = 0; i < nr_fans; i++) {
Hans de Goede65434392011-09-09 12:12:35 +02002386 err = f71882fg_create_fan_sysfs_files(pdev, i);
Hans de Goede9af07942011-09-09 12:12:34 +02002387 if (err)
2388 goto exit_unregister_sysfs;
Hans de Goede9af07942011-09-09 12:12:34 +02002389 }
2390
2391 /* Some types have 1 extra fan with limited functionality */
Hans de Goedee48a7f12011-03-09 20:57:13 +01002392 switch (data->type) {
Hans de Goede629c58b2011-05-25 20:43:32 +02002393 case f71808a:
2394 err = f71882fg_create_sysfs_files(pdev,
Hans de Goede629c58b2011-05-25 20:43:32 +02002395 f71808a_fan3_attr,
2396 ARRAY_SIZE(f71808a_fan3_attr));
2397 break;
Hans de Goedeed4f7c22009-01-07 16:37:30 +01002398 case f8000:
2399 err = f71882fg_create_sysfs_files(pdev,
2400 f8000_fan_attr,
2401 ARRAY_SIZE(f8000_fan_attr));
2402 break;
Hans de Goedee48a7f12011-03-09 20:57:13 +01002403 default:
Hans de Goede9af07942011-09-09 12:12:34 +02002404 break;
Hans de Goede498be962009-01-07 16:37:28 +01002405 }
Hans de Goedec13548c2009-01-07 16:37:27 +01002406 if (err)
2407 goto exit_unregister_sysfs;
Hans de Goede45fb3662007-07-13 14:34:19 +02002408 }
2409
Tony Jones1beeffe2007-08-20 13:46:20 -07002410 data->hwmon_dev = hwmon_device_register(&pdev->dev);
2411 if (IS_ERR(data->hwmon_dev)) {
2412 err = PTR_ERR(data->hwmon_dev);
Hans de Goedec13548c2009-01-07 16:37:27 +01002413 data->hwmon_dev = NULL;
Hans de Goede45fb3662007-07-13 14:34:19 +02002414 goto exit_unregister_sysfs;
2415 }
2416
2417 return 0;
2418
2419exit_unregister_sysfs:
Hans de Goedec13548c2009-01-07 16:37:27 +01002420 f71882fg_remove(pdev); /* Will unregister the sysfs files for us */
Hans de Goede3cc74752009-01-07 16:37:28 +01002421 return err; /* f71882fg_remove() also frees our data */
Hans de Goede45fb3662007-07-13 14:34:19 +02002422}
2423
Hans de Goedec13548c2009-01-07 16:37:27 +01002424static int f71882fg_remove(struct platform_device *pdev)
Hans de Goede45fb3662007-07-13 14:34:19 +02002425{
Hans de Goede45fb3662007-07-13 14:34:19 +02002426 struct f71882fg_data *data = platform_get_drvdata(pdev);
Jean Delvaref27def02011-03-26 10:45:01 +01002427 int nr_fans = f71882fg_nr_fans[data->type];
2428 int nr_temps = f71882fg_nr_temps[data->type];
2429 int i;
Hans de Goedefc16c562009-12-09 20:36:01 +01002430 u8 start_reg = f71882fg_read8(data, F71882FG_REG_START);
Hans de Goede45fb3662007-07-13 14:34:19 +02002431
Hans de Goedec13548c2009-01-07 16:37:27 +01002432 if (data->hwmon_dev)
2433 hwmon_device_unregister(data->hwmon_dev);
Hans de Goede45fb3662007-07-13 14:34:19 +02002434
Hans de Goedec13548c2009-01-07 16:37:27 +01002435 device_remove_file(&pdev->dev, &dev_attr_name);
Hans de Goede45fb3662007-07-13 14:34:19 +02002436
Hans de Goedefc16c562009-12-09 20:36:01 +01002437 if (start_reg & 0x01) {
2438 switch (data->type) {
2439 case f71858fg:
2440 if (data->temp_config & 0x10)
2441 f71882fg_remove_sysfs_files(pdev,
Hans de Goede0bae6402011-03-09 20:57:10 +01002442 f8000_temp_attr,
2443 ARRAY_SIZE(f8000_temp_attr));
Hans de Goedefc16c562009-12-09 20:36:01 +01002444 else
2445 f71882fg_remove_sysfs_files(pdev,
Hans de Goede0bae6402011-03-09 20:57:10 +01002446 f71858fg_temp_attr,
2447 ARRAY_SIZE(f71858fg_temp_attr));
Hans de Goedefc16c562009-12-09 20:36:01 +01002448 break;
2449 case f8000:
2450 f71882fg_remove_sysfs_files(pdev,
Hans de Goede0bae6402011-03-09 20:57:10 +01002451 f8000_temp_attr,
2452 ARRAY_SIZE(f8000_temp_attr));
Hans de Goedefc16c562009-12-09 20:36:01 +01002453 break;
Hans de Goede0bae6402011-03-09 20:57:10 +01002454 default:
2455 f71882fg_remove_sysfs_files(pdev,
Hans de Goede60d2b372011-03-09 20:57:11 +01002456 &fxxxx_temp_attr[0][0],
2457 ARRAY_SIZE(fxxxx_temp_attr[0]) * nr_temps);
Hans de Goede0bae6402011-03-09 20:57:10 +01002458 }
Hans de Goede4d538112011-05-25 20:43:32 +02002459 if (f71882fg_temp_has_beep[data->type]) {
Hans de Goede78aa4f72011-03-09 20:57:12 +01002460 f71882fg_remove_sysfs_files(pdev,
2461 &fxxxx_temp_beep_attr[0][0],
2462 ARRAY_SIZE(fxxxx_temp_beep_attr[0]) * nr_temps);
2463 }
2464
Hans de Goede0bae6402011-03-09 20:57:10 +01002465 for (i = 0; i < F71882FG_MAX_INS; i++) {
2466 if (f71882fg_has_in[data->type][i]) {
2467 device_remove_file(&pdev->dev,
2468 &fxxxx_in_attr[i].dev_attr);
2469 }
2470 }
2471 if (f71882fg_has_in1_alarm[data->type]) {
2472 f71882fg_remove_sysfs_files(pdev,
2473 fxxxx_in1_alarm_attr,
2474 ARRAY_SIZE(fxxxx_in1_alarm_attr));
Hans de Goedefc16c562009-12-09 20:36:01 +01002475 }
2476 }
Hans de Goede498be962009-01-07 16:37:28 +01002477
Hans de Goedefc16c562009-12-09 20:36:01 +01002478 if (start_reg & 0x02) {
2479 f71882fg_remove_sysfs_files(pdev, &fxxxx_fan_attr[0][0],
2480 ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans);
Hans de Goede45fb3662007-07-13 14:34:19 +02002481
Hans de Goede4d538112011-05-25 20:43:32 +02002482 if (f71882fg_fan_has_beep[data->type]) {
Hans de Goedefc16c562009-12-09 20:36:01 +01002483 f71882fg_remove_sysfs_files(pdev,
2484 fxxxx_fan_beep_attr, nr_fans);
Hans de Goede78aa4f72011-03-09 20:57:12 +01002485 }
Hans de Goede498be962009-01-07 16:37:28 +01002486
Hans de Goedefc16c562009-12-09 20:36:01 +01002487 switch (data->type) {
Hans de Goede629c58b2011-05-25 20:43:32 +02002488 case f71808a:
2489 f71882fg_remove_sysfs_files(pdev,
2490 &fxxxx_auto_pwm_attr[0][0],
2491 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
2492 f71882fg_remove_sysfs_files(pdev,
2493 f71808a_fan3_attr,
2494 ARRAY_SIZE(f71808a_fan3_attr));
2495 break;
Hans de Goedefc16c562009-12-09 20:36:01 +01002496 case f71862fg:
2497 f71882fg_remove_sysfs_files(pdev,
Hans de Goede55840142011-09-09 12:12:33 +02002498 &f71862fg_auto_pwm_attr[0][0],
2499 ARRAY_SIZE(f71862fg_auto_pwm_attr[0]) *
2500 nr_fans);
Hans de Goedefc16c562009-12-09 20:36:01 +01002501 break;
Hans de Goedee5e713c2011-03-10 08:54:02 +01002502 case f71808e:
Hans de Goedec11bb992011-03-09 20:57:15 +01002503 case f71869:
2504 f71882fg_remove_sysfs_files(pdev,
Hans de Goede55840142011-09-09 12:12:33 +02002505 &f71869_auto_pwm_attr[0][0],
2506 ARRAY_SIZE(f71869_auto_pwm_attr[0]) * nr_fans);
Hans de Goedec11bb992011-03-09 20:57:15 +01002507 break;
Hans de Goedefc16c562009-12-09 20:36:01 +01002508 case f8000:
2509 f71882fg_remove_sysfs_files(pdev,
2510 f8000_fan_attr,
2511 ARRAY_SIZE(f8000_fan_attr));
2512 f71882fg_remove_sysfs_files(pdev,
Hans de Goede55840142011-09-09 12:12:33 +02002513 &f8000_auto_pwm_attr[0][0],
2514 ARRAY_SIZE(f8000_auto_pwm_attr[0]) * nr_fans);
Hans de Goedefc16c562009-12-09 20:36:01 +01002515 break;
Hans de Goede3cad4022011-03-09 20:57:14 +01002516 default:
Hans de Goedefc16c562009-12-09 20:36:01 +01002517 f71882fg_remove_sysfs_files(pdev,
2518 &fxxxx_auto_pwm_attr[0][0],
2519 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
2520 }
2521 }
Hans de Goede45fb3662007-07-13 14:34:19 +02002522 return 0;
2523}
2524
Guenter Roeck00383892012-08-04 09:46:36 -07002525static int __init f71882fg_find(int sioaddr, struct f71882fg_sio_data *sio_data)
Hans de Goede45fb3662007-07-13 14:34:19 +02002526{
Hans de Goede45fb3662007-07-13 14:34:19 +02002527 u16 devid;
Guenter Roeck00383892012-08-04 09:46:36 -07002528 unsigned short address;
Giel van Schijndelcadb8652010-10-03 08:09:49 -04002529 int err = superio_enter(sioaddr);
2530 if (err)
2531 return err;
Hans de Goede45fb3662007-07-13 14:34:19 +02002532
2533 devid = superio_inw(sioaddr, SIO_REG_MANID);
2534 if (devid != SIO_FINTEK_ID) {
Joe Perches22d3b412010-10-20 06:51:34 +00002535 pr_debug("Not a Fintek device\n");
Giel van Schijndelcadb8652010-10-03 08:09:49 -04002536 err = -ENODEV;
Hans de Goede45fb3662007-07-13 14:34:19 +02002537 goto exit;
2538 }
2539
Jean Delvare67b671b2007-12-06 23:13:42 +01002540 devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID);
Hans de Goede498be962009-01-07 16:37:28 +01002541 switch (devid) {
Hans de Goedee5e713c2011-03-10 08:54:02 +01002542 case SIO_F71808E_ID:
2543 sio_data->type = f71808e;
2544 break;
Hans de Goede629c58b2011-05-25 20:43:32 +02002545 case SIO_F71808A_ID:
2546 sio_data->type = f71808a;
2547 break;
Hans de Goede09475d32009-06-15 18:39:52 +02002548 case SIO_F71858_ID:
2549 sio_data->type = f71858fg;
2550 break;
Hans de Goede498be962009-01-07 16:37:28 +01002551 case SIO_F71862_ID:
2552 sio_data->type = f71862fg;
2553 break;
Hans de Goedec11bb992011-03-09 20:57:15 +01002554 case SIO_F71869_ID:
2555 sio_data->type = f71869;
2556 break;
Hans de Goede5da556e2011-07-03 13:32:53 +02002557 case SIO_F71869A_ID:
2558 sio_data->type = f71869a;
2559 break;
Hans de Goede498be962009-01-07 16:37:28 +01002560 case SIO_F71882_ID:
2561 sio_data->type = f71882fg;
2562 break;
Hans de Goede76698962009-12-09 20:36:01 +01002563 case SIO_F71889_ID:
2564 sio_data->type = f71889fg;
2565 break;
Hans de Goede3cad4022011-03-09 20:57:14 +01002566 case SIO_F71889E_ID:
2567 sio_data->type = f71889ed;
2568 break;
Hans de Goedea66c1082011-03-26 10:45:02 +01002569 case SIO_F71889A_ID:
2570 sio_data->type = f71889a;
2571 break;
Hans de Goedeed4f7c22009-01-07 16:37:30 +01002572 case SIO_F8000_ID:
2573 sio_data->type = f8000;
2574 break;
Jean Delvare383586b2011-03-26 10:45:02 +01002575 case SIO_F81865_ID:
2576 sio_data->type = f81865f;
2577 break;
Hans de Goede498be962009-01-07 16:37:28 +01002578 default:
Joe Perches22d3b412010-10-20 06:51:34 +00002579 pr_info("Unsupported Fintek device: %04x\n",
2580 (unsigned int)devid);
Giel van Schijndelcadb8652010-10-03 08:09:49 -04002581 err = -ENODEV;
Hans de Goede45fb3662007-07-13 14:34:19 +02002582 goto exit;
2583 }
2584
Hans de Goede09475d32009-06-15 18:39:52 +02002585 if (sio_data->type == f71858fg)
2586 superio_select(sioaddr, SIO_F71858FG_LD_HWM);
2587 else
2588 superio_select(sioaddr, SIO_F71882FG_LD_HWM);
2589
Mark M. Hoffman8afb1042007-08-21 23:10:46 -04002590 if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) {
Joe Perches22d3b412010-10-20 06:51:34 +00002591 pr_warn("Device not activated\n");
Giel van Schijndelcadb8652010-10-03 08:09:49 -04002592 err = -ENODEV;
Hans de Goede45fb3662007-07-13 14:34:19 +02002593 goto exit;
2594 }
2595
Guenter Roeck00383892012-08-04 09:46:36 -07002596 address = superio_inw(sioaddr, SIO_REG_ADDR);
2597 if (address == 0) {
Joe Perches22d3b412010-10-20 06:51:34 +00002598 pr_warn("Base address not set\n");
Giel van Schijndelcadb8652010-10-03 08:09:49 -04002599 err = -ENODEV;
Hans de Goede45fb3662007-07-13 14:34:19 +02002600 goto exit;
2601 }
Guenter Roeck00383892012-08-04 09:46:36 -07002602 address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */
Hans de Goede45fb3662007-07-13 14:34:19 +02002603
Guenter Roeck00383892012-08-04 09:46:36 -07002604 err = address;
Joe Perches22d3b412010-10-20 06:51:34 +00002605 pr_info("Found %s chip at %#x, revision %d\n",
Guenter Roeck00383892012-08-04 09:46:36 -07002606 f71882fg_names[sio_data->type], (unsigned int)address,
Hans de Goede45fb3662007-07-13 14:34:19 +02002607 (int)superio_inb(sioaddr, SIO_REG_DEVREV));
2608exit:
2609 superio_exit(sioaddr);
2610 return err;
2611}
2612
Guenter Roeck00383892012-08-04 09:46:36 -07002613static int __init f71882fg_device_add(int address,
2614 const struct f71882fg_sio_data *sio_data)
Hans de Goede45fb3662007-07-13 14:34:19 +02002615{
2616 struct resource res = {
2617 .start = address,
2618 .end = address + REGION_LENGTH - 1,
2619 .flags = IORESOURCE_IO,
2620 };
2621 int err;
2622
2623 f71882fg_pdev = platform_device_alloc(DRVNAME, address);
Mark M. Hoffman8afb1042007-08-21 23:10:46 -04002624 if (!f71882fg_pdev)
Hans de Goede45fb3662007-07-13 14:34:19 +02002625 return -ENOMEM;
2626
2627 res.name = f71882fg_pdev->name;
Jean Delvareb9acb642009-01-07 16:37:35 +01002628 err = acpi_check_resource_conflict(&res);
2629 if (err)
Hans de Goede18632f82009-02-17 19:59:54 +01002630 goto exit_device_put;
Jean Delvareb9acb642009-01-07 16:37:35 +01002631
Hans de Goede45fb3662007-07-13 14:34:19 +02002632 err = platform_device_add_resources(f71882fg_pdev, &res, 1);
Mark M. Hoffman8afb1042007-08-21 23:10:46 -04002633 if (err) {
Joe Perches22d3b412010-10-20 06:51:34 +00002634 pr_err("Device resource addition failed\n");
Hans de Goede45fb3662007-07-13 14:34:19 +02002635 goto exit_device_put;
2636 }
2637
Hans de Goede498be962009-01-07 16:37:28 +01002638 err = platform_device_add_data(f71882fg_pdev, sio_data,
2639 sizeof(struct f71882fg_sio_data));
2640 if (err) {
Joe Perches22d3b412010-10-20 06:51:34 +00002641 pr_err("Platform data allocation failed\n");
Hans de Goede498be962009-01-07 16:37:28 +01002642 goto exit_device_put;
2643 }
2644
Hans de Goede45fb3662007-07-13 14:34:19 +02002645 err = platform_device_add(f71882fg_pdev);
Mark M. Hoffman8afb1042007-08-21 23:10:46 -04002646 if (err) {
Joe Perches22d3b412010-10-20 06:51:34 +00002647 pr_err("Device addition failed\n");
Hans de Goede45fb3662007-07-13 14:34:19 +02002648 goto exit_device_put;
2649 }
2650
2651 return 0;
2652
2653exit_device_put:
2654 platform_device_put(f71882fg_pdev);
2655
2656 return err;
2657}
2658
2659static int __init f71882fg_init(void)
2660{
Guenter Roeck00383892012-08-04 09:46:36 -07002661 int err;
2662 int address;
Hans de Goede498be962009-01-07 16:37:28 +01002663 struct f71882fg_sio_data sio_data;
Hans de Goede45fb3662007-07-13 14:34:19 +02002664
Hans de Goede498be962009-01-07 16:37:28 +01002665 memset(&sio_data, 0, sizeof(sio_data));
2666
Guenter Roeck00383892012-08-04 09:46:36 -07002667 address = f71882fg_find(0x2e, &sio_data);
2668 if (address < 0)
2669 address = f71882fg_find(0x4e, &sio_data);
2670 if (address < 0)
2671 return address;
Hans de Goede45fb3662007-07-13 14:34:19 +02002672
Hans de Goedec13548c2009-01-07 16:37:27 +01002673 err = platform_driver_register(&f71882fg_driver);
2674 if (err)
Guenter Roeck00383892012-08-04 09:46:36 -07002675 return err;
Hans de Goede45fb3662007-07-13 14:34:19 +02002676
Hans de Goede498be962009-01-07 16:37:28 +01002677 err = f71882fg_device_add(address, &sio_data);
Hans de Goedec13548c2009-01-07 16:37:27 +01002678 if (err)
Hans de Goede45fb3662007-07-13 14:34:19 +02002679 goto exit_driver;
2680
2681 return 0;
2682
2683exit_driver:
2684 platform_driver_unregister(&f71882fg_driver);
Hans de Goede45fb3662007-07-13 14:34:19 +02002685 return err;
2686}
2687
2688static void __exit f71882fg_exit(void)
2689{
2690 platform_device_unregister(f71882fg_pdev);
2691 platform_driver_unregister(&f71882fg_driver);
2692}
2693
2694MODULE_DESCRIPTION("F71882FG Hardware Monitoring Driver");
Hans de Goede7958e3b2011-07-03 13:32:53 +02002695MODULE_AUTHOR("Hans Edgington, Hans de Goede <hdegoede@redhat.com>");
Hans de Goede45fb3662007-07-13 14:34:19 +02002696MODULE_LICENSE("GPL");
2697
2698module_init(f71882fg_init);
2699module_exit(f71882fg_exit);