blob: 938a8b9ec70dd337b0ea5b7b8c900b51c4dba907 [file] [log] [blame]
Thomas Gleixner1a59d1b82019-05-27 08:55:05 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Hans de Goede45fb3662007-07-13 14:34:19 +02002/***************************************************************************
3 * Copyright (C) 2006 by Hans Edgington <hans@edgington.nl> *
Hans de Goede44c4dc52011-03-09 20:57:07 +01004 * Copyright (C) 2007-2011 Hans de Goede <hdegoede@redhat.com> *
Hans de Goede45fb3662007-07-13 14:34:19 +02005 * *
Hans de Goede45fb3662007-07-13 14:34:19 +02006 ***************************************************************************/
7
Joe Perches22d3b412010-10-20 06:51:34 +00008#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
9
Hans de Goede45fb3662007-07-13 14:34:19 +020010#include <linux/module.h>
11#include <linux/init.h>
12#include <linux/slab.h>
13#include <linux/jiffies.h>
14#include <linux/platform_device.h>
15#include <linux/hwmon.h>
16#include <linux/hwmon-sysfs.h>
17#include <linux/err.h>
18#include <linux/mutex.h>
Mark van Doesburg77a4a3e2009-01-07 16:37:27 +010019#include <linux/io.h>
Jean Delvareb9acb642009-01-07 16:37:35 +010020#include <linux/acpi.h>
Hans de Goede45fb3662007-07-13 14:34:19 +020021
22#define DRVNAME "f71882fg"
23
Hans de Goede09475d32009-06-15 18:39:52 +020024#define SIO_F71858FG_LD_HWM 0x02 /* Hardware monitor logical device */
Mark van Doesburg77a4a3e2009-01-07 16:37:27 +010025#define SIO_F71882FG_LD_HWM 0x04 /* Hardware monitor logical device */
Hans de Goede45fb3662007-07-13 14:34:19 +020026#define SIO_UNLOCK_KEY 0x87 /* Key to enable Super-I/O */
Hans de Goede14a40192011-03-13 13:50:32 +010027#define SIO_LOCK_KEY 0xAA /* Key to disable Super-I/O */
Hans de Goede45fb3662007-07-13 14:34:19 +020028
29#define SIO_REG_LDSEL 0x07 /* Logical device select */
30#define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */
31#define SIO_REG_DEVREV 0x22 /* Device revision */
32#define SIO_REG_MANID 0x23 /* Fintek ID (2 bytes) */
33#define SIO_REG_ENABLE 0x30 /* Logical device enable */
34#define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
35
36#define SIO_FINTEK_ID 0x1934 /* Manufacturers ID */
Hans de Goedee5e713c2011-03-10 08:54:02 +010037#define SIO_F71808E_ID 0x0901 /* Chipset ID */
Hans de Goede629c58b2011-05-25 20:43:32 +020038#define SIO_F71808A_ID 0x1001 /* Chipset ID */
Hans de Goede09475d32009-06-15 18:39:52 +020039#define SIO_F71858_ID 0x0507 /* Chipset ID */
Hans de Goede498be962009-01-07 16:37:28 +010040#define SIO_F71862_ID 0x0601 /* Chipset ID */
Peter Hung2725fe22015-07-07 16:22:36 +080041#define SIO_F71868_ID 0x1106 /* Chipset ID */
Hans de Goedec11bb992011-03-09 20:57:15 +010042#define SIO_F71869_ID 0x0814 /* Chipset ID */
Hans de Goede5da556e2011-07-03 13:32:53 +020043#define SIO_F71869A_ID 0x1007 /* Chipset ID */
Hans de Goede45fb3662007-07-13 14:34:19 +020044#define SIO_F71882_ID 0x0541 /* Chipset ID */
Hans de Goede76698962009-12-09 20:36:01 +010045#define SIO_F71889_ID 0x0723 /* Chipset ID */
Hans de Goede3cad4022011-03-09 20:57:14 +010046#define SIO_F71889E_ID 0x0909 /* Chipset ID */
Hans de Goedea66c1082011-03-26 10:45:02 +010047#define SIO_F71889A_ID 0x1005 /* Chipset ID */
Hans de Goedeed4f7c22009-01-07 16:37:30 +010048#define SIO_F8000_ID 0x0581 /* Chipset ID */
George Josephd8363bb2015-07-07 19:16:53 -060049#define SIO_F81768D_ID 0x1210 /* Chipset ID */
Jean Delvare383586b2011-03-26 10:45:02 +010050#define SIO_F81865_ID 0x0704 /* Chipset ID */
Peter Hung2725fe22015-07-07 16:22:36 +080051#define SIO_F81866_ID 0x1010 /* Chipset ID */
Menghui Wudf293072021-11-17 10:43:20 +080052#define SIO_F81966_ID 0x1502 /* Chipset ID */
Hans de Goede45fb3662007-07-13 14:34:19 +020053
54#define REGION_LENGTH 8
55#define ADDR_REG_OFFSET 5
56#define DATA_REG_OFFSET 6
57
Hans de Goede3cad4022011-03-09 20:57:14 +010058#define F71882FG_REG_IN_STATUS 0x12 /* f7188x only */
59#define F71882FG_REG_IN_BEEP 0x13 /* f7188x only */
Hans de Goede45fb3662007-07-13 14:34:19 +020060#define F71882FG_REG_IN(nr) (0x20 + (nr))
Hans de Goede3cad4022011-03-09 20:57:14 +010061#define F71882FG_REG_IN1_HIGH 0x32 /* f7188x only */
Hans de Goede45fb3662007-07-13 14:34:19 +020062
Peter Hung3e40b862015-07-07 16:22:38 +080063#define F81866_REG_IN_STATUS 0x16 /* F81866 only */
64#define F81866_REG_IN_BEEP 0x17 /* F81866 only */
65#define F81866_REG_IN1_HIGH 0x3a /* F81866 only */
66
Hans de Goede45fb3662007-07-13 14:34:19 +020067#define F71882FG_REG_FAN(nr) (0xA0 + (16 * (nr)))
Mark van Doesburg9ab796e2009-01-07 16:37:27 +010068#define F71882FG_REG_FAN_TARGET(nr) (0xA2 + (16 * (nr)))
69#define F71882FG_REG_FAN_FULL_SPEED(nr) (0xA4 + (16 * (nr)))
Hans de Goede45fb3662007-07-13 14:34:19 +020070#define F71882FG_REG_FAN_STATUS 0x92
71#define F71882FG_REG_FAN_BEEP 0x93
72
Hans de Goede7567a042009-01-07 16:37:28 +010073#define F71882FG_REG_TEMP(nr) (0x70 + 2 * (nr))
74#define F71882FG_REG_TEMP_OVT(nr) (0x80 + 2 * (nr))
75#define F71882FG_REG_TEMP_HIGH(nr) (0x81 + 2 * (nr))
Hans de Goede45fb3662007-07-13 14:34:19 +020076#define F71882FG_REG_TEMP_STATUS 0x62
77#define F71882FG_REG_TEMP_BEEP 0x63
Hans de Goede09475d32009-06-15 18:39:52 +020078#define F71882FG_REG_TEMP_CONFIG 0x69
Hans de Goedebc274902009-01-07 16:37:29 +010079#define F71882FG_REG_TEMP_HYST(nr) (0x6C + (nr))
Hans de Goede45fb3662007-07-13 14:34:19 +020080#define F71882FG_REG_TEMP_TYPE 0x6B
81#define F71882FG_REG_TEMP_DIODE_OPEN 0x6F
82
Mark van Doesburg9ab796e2009-01-07 16:37:27 +010083#define F71882FG_REG_PWM(nr) (0xA3 + (16 * (nr)))
84#define F71882FG_REG_PWM_TYPE 0x94
85#define F71882FG_REG_PWM_ENABLE 0x96
86
Hans de Goedebc274902009-01-07 16:37:29 +010087#define F71882FG_REG_FAN_HYST(nr) (0x98 + (nr))
Mark van Doesburg9ab796e2009-01-07 16:37:27 +010088
Hans de Goede98f7ba12011-03-09 20:57:09 +010089#define F71882FG_REG_FAN_FAULT_T 0x9F
90#define F71882FG_FAN_NEG_TEMP_EN 0x20
Hans de Goede3cad4022011-03-09 20:57:14 +010091#define F71882FG_FAN_PROG_SEL 0x80
Hans de Goede98f7ba12011-03-09 20:57:09 +010092
Mark van Doesburg9ab796e2009-01-07 16:37:27 +010093#define F71882FG_REG_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm)))
94#define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm)))
95#define F71882FG_REG_POINT_MAPPING(nr) (0xAF + 16 * (nr))
96
Hans de Goede45fb3662007-07-13 14:34:19 +020097#define F71882FG_REG_START 0x01
98
George Josephd8363bb2015-07-07 19:16:53 -060099#define F71882FG_MAX_INS 11
Hans de Goede0bae6402011-03-09 20:57:10 +0100100
Hans de Goede45fb3662007-07-13 14:34:19 +0200101#define FAN_MIN_DETECT 366 /* Lowest detectable fanspeed */
102
Jean Delvare67b671b2007-12-06 23:13:42 +0100103static unsigned short force_id;
104module_param(force_id, ushort, 0);
105MODULE_PARM_DESC(force_id, "Override the detected device ID");
106
Peter Hung2725fe22015-07-07 16:22:36 +0800107enum chips { f71808e, f71808a, f71858fg, f71862fg, f71868a, f71869, f71869a,
George Josephd8363bb2015-07-07 19:16:53 -0600108 f71882fg, f71889fg, f71889ed, f71889a, f8000, f81768d, f81865f,
109 f81866a};
Hans de Goede498be962009-01-07 16:37:28 +0100110
Frans Meulenbroeks1dc37082012-01-08 19:34:10 +0100111static const char *const f71882fg_names[] = {
Hans de Goedee5e713c2011-03-10 08:54:02 +0100112 "f71808e",
Hans de Goede629c58b2011-05-25 20:43:32 +0200113 "f71808a",
Hans de Goede09475d32009-06-15 18:39:52 +0200114 "f71858fg",
Hans de Goede498be962009-01-07 16:37:28 +0100115 "f71862fg",
Peter Hung2725fe22015-07-07 16:22:36 +0800116 "f71868a",
Hans de Goedec11bb992011-03-09 20:57:15 +0100117 "f71869", /* Both f71869f and f71869e, reg. compatible and same id */
Hans de Goede5da556e2011-07-03 13:32:53 +0200118 "f71869a",
Hans de Goede498be962009-01-07 16:37:28 +0100119 "f71882fg",
Jean Delvare5d7f77b2011-03-26 10:45:02 +0100120 "f71889fg", /* f81801u too, same id */
Hans de Goede3cad4022011-03-09 20:57:14 +0100121 "f71889ed",
Hans de Goedea66c1082011-03-26 10:45:02 +0100122 "f71889a",
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100123 "f8000",
George Josephd8363bb2015-07-07 19:16:53 -0600124 "f81768d",
Jean Delvare383586b2011-03-26 10:45:02 +0100125 "f81865f",
Peter Hung2725fe22015-07-07 16:22:36 +0800126 "f81866a",
Hans de Goede498be962009-01-07 16:37:28 +0100127};
128
Jean Delvare2740c602011-03-26 10:45:01 +0100129static const char f71882fg_has_in[][F71882FG_MAX_INS] = {
George Josephd8363bb2015-07-07 19:16:53 -0600130 [f71808e] = { 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0 },
131 [f71808a] = { 1, 1, 1, 1, 0, 0, 0, 1, 1, 0, 0 },
132 [f71858fg] = { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
133 [f71862fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
134 [f71868a] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0 },
135 [f71869] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
136 [f71869a] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
137 [f71882fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
138 [f71889fg] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
139 [f71889ed] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
140 [f71889a] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 },
141 [f8000] = { 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0 },
142 [f81768d] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 },
143 [f81865f] = { 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0 },
144 [f81866a] = { 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0 },
Hans de Goede0bae6402011-03-09 20:57:10 +0100145};
146
Jean Delvare2740c602011-03-26 10:45:01 +0100147static const char f71882fg_has_in1_alarm[] = {
148 [f71808e] = 0,
Hans de Goede629c58b2011-05-25 20:43:32 +0200149 [f71808a] = 0,
Jean Delvare2740c602011-03-26 10:45:01 +0100150 [f71858fg] = 0,
151 [f71862fg] = 0,
Peter Hung2725fe22015-07-07 16:22:36 +0800152 [f71868a] = 0,
Jean Delvare2740c602011-03-26 10:45:01 +0100153 [f71869] = 0,
Hans de Goede5da556e2011-07-03 13:32:53 +0200154 [f71869a] = 0,
Jean Delvare2740c602011-03-26 10:45:01 +0100155 [f71882fg] = 1,
156 [f71889fg] = 1,
157 [f71889ed] = 1,
Hans de Goedea66c1082011-03-26 10:45:02 +0100158 [f71889a] = 1,
Jean Delvare2740c602011-03-26 10:45:01 +0100159 [f8000] = 0,
George Josephd8363bb2015-07-07 19:16:53 -0600160 [f81768d] = 1,
Jean Delvare383586b2011-03-26 10:45:02 +0100161 [f81865f] = 1,
Peter Hung2725fe22015-07-07 16:22:36 +0800162 [f81866a] = 1,
Hans de Goede0bae6402011-03-09 20:57:10 +0100163};
164
Hans de Goede4d538112011-05-25 20:43:32 +0200165static const char f71882fg_fan_has_beep[] = {
Jean Delvare2740c602011-03-26 10:45:01 +0100166 [f71808e] = 0,
Hans de Goede629c58b2011-05-25 20:43:32 +0200167 [f71808a] = 0,
Jean Delvare2740c602011-03-26 10:45:01 +0100168 [f71858fg] = 0,
169 [f71862fg] = 1,
Peter Hung2725fe22015-07-07 16:22:36 +0800170 [f71868a] = 1,
Jean Delvare2740c602011-03-26 10:45:01 +0100171 [f71869] = 1,
Hans de Goede5da556e2011-07-03 13:32:53 +0200172 [f71869a] = 1,
Jean Delvare2740c602011-03-26 10:45:01 +0100173 [f71882fg] = 1,
174 [f71889fg] = 1,
175 [f71889ed] = 1,
Hans de Goedea66c1082011-03-26 10:45:02 +0100176 [f71889a] = 1,
Jean Delvare2740c602011-03-26 10:45:01 +0100177 [f8000] = 0,
George Josephd8363bb2015-07-07 19:16:53 -0600178 [f81768d] = 1,
Jean Delvare383586b2011-03-26 10:45:02 +0100179 [f81865f] = 1,
Peter Hung2725fe22015-07-07 16:22:36 +0800180 [f81866a] = 1,
Hans de Goede78aa4f72011-03-09 20:57:12 +0100181};
182
Jean Delvaref27def02011-03-26 10:45:01 +0100183static const char f71882fg_nr_fans[] = {
184 [f71808e] = 3,
Hans de Goede629c58b2011-05-25 20:43:32 +0200185 [f71808a] = 2, /* +1 fan which is monitor + simple pwm only */
Jean Delvaref27def02011-03-26 10:45:01 +0100186 [f71858fg] = 3,
187 [f71862fg] = 3,
Peter Hung2725fe22015-07-07 16:22:36 +0800188 [f71868a] = 3,
Jean Delvaref27def02011-03-26 10:45:01 +0100189 [f71869] = 3,
Hans de Goede5da556e2011-07-03 13:32:53 +0200190 [f71869a] = 3,
Jean Delvaref27def02011-03-26 10:45:01 +0100191 [f71882fg] = 4,
192 [f71889fg] = 3,
193 [f71889ed] = 3,
Hans de Goedea66c1082011-03-26 10:45:02 +0100194 [f71889a] = 3,
Hans de Goede629c58b2011-05-25 20:43:32 +0200195 [f8000] = 3, /* +1 fan which is monitor only */
George Josephd8363bb2015-07-07 19:16:53 -0600196 [f81768d] = 3,
Jean Delvare383586b2011-03-26 10:45:02 +0100197 [f81865f] = 2,
Peter Hung2725fe22015-07-07 16:22:36 +0800198 [f81866a] = 3,
Jean Delvaref27def02011-03-26 10:45:01 +0100199};
200
Hans de Goede4d538112011-05-25 20:43:32 +0200201static const char f71882fg_temp_has_beep[] = {
202 [f71808e] = 0,
Hans de Goede629c58b2011-05-25 20:43:32 +0200203 [f71808a] = 1,
Hans de Goede4d538112011-05-25 20:43:32 +0200204 [f71858fg] = 0,
205 [f71862fg] = 1,
Peter Hung2725fe22015-07-07 16:22:36 +0800206 [f71868a] = 1,
Hans de Goede4d538112011-05-25 20:43:32 +0200207 [f71869] = 1,
Hans de Goede5da556e2011-07-03 13:32:53 +0200208 [f71869a] = 1,
Hans de Goede4d538112011-05-25 20:43:32 +0200209 [f71882fg] = 1,
210 [f71889fg] = 1,
211 [f71889ed] = 1,
212 [f71889a] = 1,
213 [f8000] = 0,
George Josephd8363bb2015-07-07 19:16:53 -0600214 [f81768d] = 1,
Hans de Goede4d538112011-05-25 20:43:32 +0200215 [f81865f] = 1,
Peter Hung2725fe22015-07-07 16:22:36 +0800216 [f81866a] = 1,
Hans de Goede4d538112011-05-25 20:43:32 +0200217};
218
Jean Delvaref27def02011-03-26 10:45:01 +0100219static const char f71882fg_nr_temps[] = {
220 [f71808e] = 2,
Hans de Goede629c58b2011-05-25 20:43:32 +0200221 [f71808a] = 2,
Jean Delvaref27def02011-03-26 10:45:01 +0100222 [f71858fg] = 3,
223 [f71862fg] = 3,
Peter Hung2725fe22015-07-07 16:22:36 +0800224 [f71868a] = 3,
Jean Delvaref27def02011-03-26 10:45:01 +0100225 [f71869] = 3,
Hans de Goede5da556e2011-07-03 13:32:53 +0200226 [f71869a] = 3,
Jean Delvaref27def02011-03-26 10:45:01 +0100227 [f71882fg] = 3,
228 [f71889fg] = 3,
229 [f71889ed] = 3,
Hans de Goedea66c1082011-03-26 10:45:02 +0100230 [f71889a] = 3,
Jean Delvaref27def02011-03-26 10:45:01 +0100231 [f8000] = 3,
George Josephd8363bb2015-07-07 19:16:53 -0600232 [f81768d] = 3,
Jean Delvare383586b2011-03-26 10:45:02 +0100233 [f81865f] = 2,
Peter Hung2725fe22015-07-07 16:22:36 +0800234 [f81866a] = 3,
Jean Delvaref27def02011-03-26 10:45:01 +0100235};
236
Mark van Doesburg77a4a3e2009-01-07 16:37:27 +0100237static struct platform_device *f71882fg_pdev;
Hans de Goede45fb3662007-07-13 14:34:19 +0200238
239/* Super-I/O Function prototypes */
240static inline int superio_inb(int base, int reg);
241static inline int superio_inw(int base, int reg);
Giel van Schijndelcadb8652010-10-03 08:09:49 -0400242static inline int superio_enter(int base);
Hans de Goede45fb3662007-07-13 14:34:19 +0200243static inline void superio_select(int base, int ld);
244static inline void superio_exit(int base);
245
Hans de Goede498be962009-01-07 16:37:28 +0100246struct f71882fg_sio_data {
247 enum chips type;
248};
249
Hans de Goede45fb3662007-07-13 14:34:19 +0200250struct f71882fg_data {
251 unsigned short addr;
Hans de Goede498be962009-01-07 16:37:28 +0100252 enum chips type;
Tony Jones1beeffe2007-08-20 13:46:20 -0700253 struct device *hwmon_dev;
Hans de Goede45fb3662007-07-13 14:34:19 +0200254
255 struct mutex update_lock;
Hans de Goede09475d32009-06-15 18:39:52 +0200256 int temp_start; /* temp numbering start (0 or 1) */
Paul Fertser952a11c2021-09-24 22:52:02 +0300257 bool valid; /* true if following fields are valid */
Hans de Goede98f7ba12011-03-09 20:57:09 +0100258 char auto_point_temp_signed;
Hans de Goede45fb3662007-07-13 14:34:19 +0200259 unsigned long last_updated; /* In jiffies */
260 unsigned long last_limits; /* In jiffies */
261
262 /* Register Values */
Hans de Goede0bae6402011-03-09 20:57:10 +0100263 u8 in[F71882FG_MAX_INS];
Hans de Goede45fb3662007-07-13 14:34:19 +0200264 u8 in1_max;
265 u8 in_status;
266 u8 in_beep;
267 u16 fan[4];
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100268 u16 fan_target[4];
269 u16 fan_full_speed[4];
Hans de Goede45fb3662007-07-13 14:34:19 +0200270 u8 fan_status;
271 u8 fan_beep;
Guenter Roeck20eaf722012-01-19 11:02:17 -0800272 /*
273 * Note: all models have max 3 temperature channels, but on some
274 * they are addressed as 0-2 and on others as 1-3, so for coding
275 * convenience we reserve space for 4 channels
276 */
Hans de Goede09475d32009-06-15 18:39:52 +0200277 u16 temp[4];
Hans de Goede7567a042009-01-07 16:37:28 +0100278 u8 temp_ovt[4];
279 u8 temp_high[4];
Hans de Goedebc274902009-01-07 16:37:29 +0100280 u8 temp_hyst[2]; /* 2 hysts stored per reg */
Hans de Goede7567a042009-01-07 16:37:28 +0100281 u8 temp_type[4];
Hans de Goede45fb3662007-07-13 14:34:19 +0200282 u8 temp_status;
283 u8 temp_beep;
284 u8 temp_diode_open;
Hans de Goede09475d32009-06-15 18:39:52 +0200285 u8 temp_config;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100286 u8 pwm[4];
287 u8 pwm_enable;
288 u8 pwm_auto_point_hyst[2];
289 u8 pwm_auto_point_mapping[4];
290 u8 pwm_auto_point_pwm[4][5];
Hans de Goede76698962009-12-09 20:36:01 +0100291 s8 pwm_auto_point_temp[4][4];
Hans de Goede45fb3662007-07-13 14:34:19 +0200292};
293
Mark van Doesburg77a4a3e2009-01-07 16:37:27 +0100294/* Sysfs in */
Hans de Goede45fb3662007-07-13 14:34:19 +0200295static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
296 char *buf);
297static ssize_t show_in_max(struct device *dev, struct device_attribute
298 *devattr, char *buf);
299static ssize_t store_in_max(struct device *dev, struct device_attribute
300 *devattr, const char *buf, size_t count);
301static ssize_t show_in_beep(struct device *dev, struct device_attribute
302 *devattr, char *buf);
303static ssize_t store_in_beep(struct device *dev, struct device_attribute
304 *devattr, const char *buf, size_t count);
305static ssize_t show_in_alarm(struct device *dev, struct device_attribute
306 *devattr, char *buf);
307/* Sysfs Fan */
308static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
309 char *buf);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100310static ssize_t show_fan_full_speed(struct device *dev,
311 struct device_attribute *devattr, char *buf);
312static ssize_t store_fan_full_speed(struct device *dev,
313 struct device_attribute *devattr, const char *buf, size_t count);
Hans de Goede45fb3662007-07-13 14:34:19 +0200314static ssize_t show_fan_beep(struct device *dev, struct device_attribute
315 *devattr, char *buf);
316static ssize_t store_fan_beep(struct device *dev, struct device_attribute
317 *devattr, const char *buf, size_t count);
318static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
319 *devattr, char *buf);
320/* Sysfs Temp */
321static ssize_t show_temp(struct device *dev, struct device_attribute
322 *devattr, char *buf);
323static ssize_t show_temp_max(struct device *dev, struct device_attribute
324 *devattr, char *buf);
325static ssize_t store_temp_max(struct device *dev, struct device_attribute
326 *devattr, const char *buf, size_t count);
327static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
328 *devattr, char *buf);
329static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
330 *devattr, const char *buf, size_t count);
331static ssize_t show_temp_crit(struct device *dev, struct device_attribute
332 *devattr, char *buf);
333static ssize_t store_temp_crit(struct device *dev, struct device_attribute
334 *devattr, const char *buf, size_t count);
335static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
336 *devattr, char *buf);
337static ssize_t show_temp_type(struct device *dev, struct device_attribute
338 *devattr, char *buf);
339static ssize_t show_temp_beep(struct device *dev, struct device_attribute
340 *devattr, char *buf);
341static ssize_t store_temp_beep(struct device *dev, struct device_attribute
342 *devattr, const char *buf, size_t count);
343static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
344 *devattr, char *buf);
345static ssize_t show_temp_fault(struct device *dev, struct device_attribute
346 *devattr, char *buf);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100347/* PWM and Auto point control */
348static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
349 char *buf);
350static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr,
351 const char *buf, size_t count);
Hans de Goede629c58b2011-05-25 20:43:32 +0200352static ssize_t show_simple_pwm(struct device *dev,
353 struct device_attribute *devattr, char *buf);
354static ssize_t store_simple_pwm(struct device *dev,
355 struct device_attribute *devattr, const char *buf, size_t count);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100356static ssize_t show_pwm_enable(struct device *dev,
357 struct device_attribute *devattr, char *buf);
358static ssize_t store_pwm_enable(struct device *dev,
359 struct device_attribute *devattr, const char *buf, size_t count);
360static ssize_t show_pwm_interpolate(struct device *dev,
361 struct device_attribute *devattr, char *buf);
362static ssize_t store_pwm_interpolate(struct device *dev,
363 struct device_attribute *devattr, const char *buf, size_t count);
364static ssize_t show_pwm_auto_point_channel(struct device *dev,
365 struct device_attribute *devattr, char *buf);
366static ssize_t store_pwm_auto_point_channel(struct device *dev,
367 struct device_attribute *devattr, const char *buf, size_t count);
368static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
369 struct device_attribute *devattr, char *buf);
370static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
371 struct device_attribute *devattr, const char *buf, size_t count);
372static ssize_t show_pwm_auto_point_pwm(struct device *dev,
373 struct device_attribute *devattr, char *buf);
374static ssize_t store_pwm_auto_point_pwm(struct device *dev,
375 struct device_attribute *devattr, const char *buf, size_t count);
376static ssize_t show_pwm_auto_point_temp(struct device *dev,
377 struct device_attribute *devattr, char *buf);
378static ssize_t store_pwm_auto_point_temp(struct device *dev,
379 struct device_attribute *devattr, const char *buf, size_t count);
Hans de Goede45fb3662007-07-13 14:34:19 +0200380/* Sysfs misc */
Julia Lawallf2620e72016-12-22 13:04:39 +0100381static ssize_t name_show(struct device *dev, struct device_attribute *devattr,
Hans de Goede45fb3662007-07-13 14:34:19 +0200382 char *buf);
383
Bill Pemberton6c931ae2012-11-19 13:22:35 -0500384static int f71882fg_probe(struct platform_device *pdev);
Hans de Goedec13548c2009-01-07 16:37:27 +0100385static int f71882fg_remove(struct platform_device *pdev);
Hans de Goede45fb3662007-07-13 14:34:19 +0200386
387static struct platform_driver f71882fg_driver = {
388 .driver = {
Hans de Goede45fb3662007-07-13 14:34:19 +0200389 .name = DRVNAME,
390 },
391 .probe = f71882fg_probe,
Jean Delvarecd659fd2009-06-15 18:39:45 +0200392 .remove = f71882fg_remove,
Hans de Goede45fb3662007-07-13 14:34:19 +0200393};
394
Julia Lawallf2620e72016-12-22 13:04:39 +0100395static DEVICE_ATTR_RO(name);
Hans de Goede45fb3662007-07-13 14:34:19 +0200396
Guenter Roeck20eaf722012-01-19 11:02:17 -0800397/*
398 * Temp attr for the f71858fg, the f71858fg is special as it has its
399 * temperature indexes start at 0 (the others start at 1)
400 */
Hans de Goede0bae6402011-03-09 20:57:10 +0100401static struct sensor_device_attribute_2 f71858fg_temp_attr[] = {
Hans de Goede09475d32009-06-15 18:39:52 +0200402 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
403 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
404 store_temp_max, 0, 0),
405 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
406 store_temp_max_hyst, 0, 0),
407 SENSOR_ATTR_2(temp1_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 0),
408 SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
409 store_temp_crit, 0, 0),
410 SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
411 0, 0),
412 SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4),
413 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0),
414 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1),
415 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max,
416 store_temp_max, 0, 1),
417 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
418 store_temp_max_hyst, 0, 1),
419 SENSOR_ATTR_2(temp2_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
420 SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
421 store_temp_crit, 0, 1),
422 SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
423 0, 1),
424 SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
Hans de Goede09475d32009-06-15 18:39:52 +0200425 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
426 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2),
427 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
428 store_temp_max, 0, 2),
429 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
430 store_temp_max_hyst, 0, 2),
431 SENSOR_ATTR_2(temp3_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
432 SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit,
433 store_temp_crit, 0, 2),
434 SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
435 0, 2),
436 SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
437 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
438};
439
Hans de Goede0bae6402011-03-09 20:57:10 +0100440/* Temp attr for the standard models */
Hans de Goede78aa4f72011-03-09 20:57:12 +0100441static struct sensor_device_attribute_2 fxxxx_temp_attr[3][9] = { {
Hans de Goede7567a042009-01-07 16:37:28 +0100442 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 1),
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100443 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100444 store_temp_max, 0, 1),
Hans de Goede7567a042009-01-07 16:37:28 +0100445 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100446 store_temp_max_hyst, 0, 1),
Guenter Roeck20eaf722012-01-19 11:02:17 -0800447 /*
448 * Should really be temp1_max_alarm, but older versions did not handle
449 * the max and crit alarms separately and lm_sensors v2 depends on the
450 * presence of temp#_alarm files. The same goes for temp2/3 _alarm.
451 */
Hans de Goede754a5907b2009-01-07 16:37:29 +0100452 SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
Hans de Goede7567a042009-01-07 16:37:28 +0100453 SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100454 store_temp_crit, 0, 1),
Hans de Goede7567a042009-01-07 16:37:28 +0100455 SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100456 0, 1),
Hans de Goede754a5907b2009-01-07 16:37:29 +0100457 SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
Hans de Goede7567a042009-01-07 16:37:28 +0100458 SENSOR_ATTR_2(temp1_type, S_IRUGO, show_temp_type, NULL, 0, 1),
Hans de Goede7567a042009-01-07 16:37:28 +0100459 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
Hans de Goede60d2b372011-03-09 20:57:11 +0100460}, {
Hans de Goede7567a042009-01-07 16:37:28 +0100461 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 2),
462 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100463 store_temp_max, 0, 2),
Hans de Goede7567a042009-01-07 16:37:28 +0100464 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100465 store_temp_max_hyst, 0, 2),
Hans de Goede754a5907b2009-01-07 16:37:29 +0100466 /* Should be temp2_max_alarm, see temp1_alarm note */
467 SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
Hans de Goede7567a042009-01-07 16:37:28 +0100468 SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100469 store_temp_crit, 0, 2),
Hans de Goede7567a042009-01-07 16:37:28 +0100470 SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100471 0, 2),
Hans de Goede754a5907b2009-01-07 16:37:29 +0100472 SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
Hans de Goede7567a042009-01-07 16:37:28 +0100473 SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 2),
Hans de Goede7567a042009-01-07 16:37:28 +0100474 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
Hans de Goede60d2b372011-03-09 20:57:11 +0100475}, {
Hans de Goede7567a042009-01-07 16:37:28 +0100476 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 3),
477 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
478 store_temp_max, 0, 3),
479 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
480 store_temp_max_hyst, 0, 3),
Hans de Goede754a5907b2009-01-07 16:37:29 +0100481 /* Should be temp3_max_alarm, see temp1_alarm note */
482 SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 3),
Hans de Goede7567a042009-01-07 16:37:28 +0100483 SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit,
484 store_temp_crit, 0, 3),
485 SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
486 0, 3),
Hans de Goede754a5907b2009-01-07 16:37:29 +0100487 SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 7),
Hans de Goede7567a042009-01-07 16:37:28 +0100488 SENSOR_ATTR_2(temp3_type, S_IRUGO, show_temp_type, NULL, 0, 3),
Hans de Goede7567a042009-01-07 16:37:28 +0100489 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 3),
Hans de Goede60d2b372011-03-09 20:57:11 +0100490} };
Hans de Goede45fb3662007-07-13 14:34:19 +0200491
Hans de Goede78aa4f72011-03-09 20:57:12 +0100492/* Temp attr for models which can beep on temp alarm */
493static struct sensor_device_attribute_2 fxxxx_temp_beep_attr[3][2] = { {
494 SENSOR_ATTR_2(temp1_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
495 store_temp_beep, 0, 1),
496 SENSOR_ATTR_2(temp1_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
497 store_temp_beep, 0, 5),
498}, {
499 SENSOR_ATTR_2(temp2_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
500 store_temp_beep, 0, 2),
501 SENSOR_ATTR_2(temp2_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
502 store_temp_beep, 0, 6),
503}, {
504 SENSOR_ATTR_2(temp3_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
505 store_temp_beep, 0, 3),
506 SENSOR_ATTR_2(temp3_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
507 store_temp_beep, 0, 7),
508} };
509
Peter Hungdcd956f2015-07-07 16:22:37 +0800510static struct sensor_device_attribute_2 f81866_temp_beep_attr[3][2] = { {
511 SENSOR_ATTR_2(temp1_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
512 store_temp_beep, 0, 0),
513 SENSOR_ATTR_2(temp1_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
514 store_temp_beep, 0, 4),
515}, {
516 SENSOR_ATTR_2(temp2_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
517 store_temp_beep, 0, 1),
518 SENSOR_ATTR_2(temp2_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
519 store_temp_beep, 0, 5),
520}, {
521 SENSOR_ATTR_2(temp3_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
522 store_temp_beep, 0, 2),
523 SENSOR_ATTR_2(temp3_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
524 store_temp_beep, 0, 6),
525} };
526
Guenter Roeck20eaf722012-01-19 11:02:17 -0800527/*
528 * Temp attr for the f8000
529 * Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max)
530 * is used as hysteresis value to clear alarms
531 * Also like the f71858fg its temperature indexes start at 0
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100532 */
Hans de Goede0bae6402011-03-09 20:57:10 +0100533static struct sensor_device_attribute_2 f8000_temp_attr[] = {
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100534 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
535 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_crit,
536 store_temp_crit, 0, 0),
537 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
538 store_temp_max, 0, 0),
539 SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4),
Hans de Goedeb6858bc2009-06-15 18:39:51 +0200540 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0),
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100541 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1),
542 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_crit,
543 store_temp_crit, 0, 1),
544 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
545 store_temp_max, 0, 1),
546 SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
Hans de Goedeb6858bc2009-06-15 18:39:51 +0200547 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100548 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2),
549 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_crit,
550 store_temp_crit, 0, 2),
551 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
552 store_temp_max, 0, 2),
553 SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
Hans de Goedeb6858bc2009-06-15 18:39:51 +0200554 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100555};
556
Hans de Goede0bae6402011-03-09 20:57:10 +0100557/* in attr for all models */
558static struct sensor_device_attribute_2 fxxxx_in_attr[] = {
559 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
560 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
561 SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2),
562 SENSOR_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 0, 3),
563 SENSOR_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 0, 4),
564 SENSOR_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 0, 5),
565 SENSOR_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 0, 6),
566 SENSOR_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 0, 7),
567 SENSOR_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 0, 8),
Peter Hung2725fe22015-07-07 16:22:36 +0800568 SENSOR_ATTR_2(in9_input, S_IRUGO, show_in, NULL, 0, 9),
George Josephd8363bb2015-07-07 19:16:53 -0600569 SENSOR_ATTR_2(in10_input, S_IRUGO, show_in, NULL, 0, 10),
Hans de Goede0bae6402011-03-09 20:57:10 +0100570};
571
572/* For models with in1 alarm capability */
573static struct sensor_device_attribute_2 fxxxx_in1_alarm_attr[] = {
574 SENSOR_ATTR_2(in1_max, S_IRUGO|S_IWUSR, show_in_max, store_in_max,
575 0, 1),
576 SENSOR_ATTR_2(in1_beep, S_IRUGO|S_IWUSR, show_in_beep, store_in_beep,
577 0, 1),
578 SENSOR_ATTR_2(in1_alarm, S_IRUGO, show_in_alarm, NULL, 0, 1),
579};
580
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100581/* Fan / PWM attr common to all models */
Hans de Goedeb69b0392009-12-09 20:36:00 +0100582static struct sensor_device_attribute_2 fxxxx_fan_attr[4][6] = { {
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100583 SENSOR_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0),
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100584 SENSOR_ATTR_2(fan1_full_speed, S_IRUGO|S_IWUSR,
585 show_fan_full_speed,
586 store_fan_full_speed, 0, 0),
Mark van Doesburgbc37ae72009-01-07 16:37:27 +0100587 SENSOR_ATTR_2(fan1_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 0),
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100588 SENSOR_ATTR_2(pwm1, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 0),
589 SENSOR_ATTR_2(pwm1_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
590 store_pwm_enable, 0, 0),
591 SENSOR_ATTR_2(pwm1_interpolate, S_IRUGO|S_IWUSR,
592 show_pwm_interpolate, store_pwm_interpolate, 0, 0),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100593}, {
594 SENSOR_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 0, 1),
595 SENSOR_ATTR_2(fan2_full_speed, S_IRUGO|S_IWUSR,
596 show_fan_full_speed,
597 store_fan_full_speed, 0, 1),
598 SENSOR_ATTR_2(fan2_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 1),
Hans de Goede498be962009-01-07 16:37:28 +0100599 SENSOR_ATTR_2(pwm2, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 1),
600 SENSOR_ATTR_2(pwm2_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
601 store_pwm_enable, 0, 1),
602 SENSOR_ATTR_2(pwm2_interpolate, S_IRUGO|S_IWUSR,
603 show_pwm_interpolate, store_pwm_interpolate, 0, 1),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100604}, {
605 SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
606 SENSOR_ATTR_2(fan3_full_speed, S_IRUGO|S_IWUSR,
607 show_fan_full_speed,
608 store_fan_full_speed, 0, 2),
609 SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
Hans de Goede3fc78382009-06-15 18:39:50 +0200610 SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 2),
611 SENSOR_ATTR_2(pwm3_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
612 store_pwm_enable, 0, 2),
Hans de Goede498be962009-01-07 16:37:28 +0100613 SENSOR_ATTR_2(pwm3_interpolate, S_IRUGO|S_IWUSR,
614 show_pwm_interpolate, store_pwm_interpolate, 0, 2),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100615}, {
616 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
617 SENSOR_ATTR_2(fan4_full_speed, S_IRUGO|S_IWUSR,
618 show_fan_full_speed,
619 store_fan_full_speed, 0, 3),
620 SENSOR_ATTR_2(fan4_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 3),
621 SENSOR_ATTR_2(pwm4, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 3),
622 SENSOR_ATTR_2(pwm4_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
623 store_pwm_enable, 0, 3),
624 SENSOR_ATTR_2(pwm4_interpolate, S_IRUGO|S_IWUSR,
625 show_pwm_interpolate, store_pwm_interpolate, 0, 3),
626} };
Hans de Goede498be962009-01-07 16:37:28 +0100627
Hans de Goede629c58b2011-05-25 20:43:32 +0200628/* Attr for the third fan of the f71808a, which only has manual pwm */
629static struct sensor_device_attribute_2 f71808a_fan3_attr[] = {
630 SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
631 SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
632 SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR,
633 show_simple_pwm, store_simple_pwm, 0, 2),
634};
635
Hans de Goede66344aa2009-12-09 20:35:59 +0100636/* Attr for models which can beep on Fan alarm */
637static struct sensor_device_attribute_2 fxxxx_fan_beep_attr[] = {
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100638 SENSOR_ATTR_2(fan1_beep, S_IRUGO|S_IWUSR, show_fan_beep,
639 store_fan_beep, 0, 0),
640 SENSOR_ATTR_2(fan2_beep, S_IRUGO|S_IWUSR, show_fan_beep,
641 store_fan_beep, 0, 1),
642 SENSOR_ATTR_2(fan3_beep, S_IRUGO|S_IWUSR, show_fan_beep,
643 store_fan_beep, 0, 2),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100644 SENSOR_ATTR_2(fan4_beep, S_IRUGO|S_IWUSR, show_fan_beep,
645 store_fan_beep, 0, 3),
Hans de Goede66344aa2009-12-09 20:35:59 +0100646};
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100647
Guenter Roeck20eaf722012-01-19 11:02:17 -0800648/*
649 * PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
650 * standard models
651 */
Hans de Goede55840142011-09-09 12:12:33 +0200652static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr[3][7] = { {
Hans de Goede66344aa2009-12-09 20:35:59 +0100653 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
654 show_pwm_auto_point_channel,
655 store_pwm_auto_point_channel, 0, 0),
Hans de Goede498be962009-01-07 16:37:28 +0100656 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
657 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
658 1, 0),
659 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
660 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
661 4, 0),
662 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
663 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
664 0, 0),
665 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
666 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
667 3, 0),
668 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
669 show_pwm_auto_point_temp_hyst,
670 store_pwm_auto_point_temp_hyst,
671 0, 0),
672 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
673 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
Hans de Goede55840142011-09-09 12:12:33 +0200674}, {
Hans de Goede66344aa2009-12-09 20:35:59 +0100675 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
676 show_pwm_auto_point_channel,
677 store_pwm_auto_point_channel, 0, 1),
Hans de Goede498be962009-01-07 16:37:28 +0100678 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
679 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
680 1, 1),
681 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
682 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
683 4, 1),
684 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
685 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
686 0, 1),
687 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
688 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
689 3, 1),
690 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
691 show_pwm_auto_point_temp_hyst,
692 store_pwm_auto_point_temp_hyst,
693 0, 1),
694 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
695 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
Hans de Goede55840142011-09-09 12:12:33 +0200696}, {
Hans de Goede66344aa2009-12-09 20:35:59 +0100697 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
698 show_pwm_auto_point_channel,
699 store_pwm_auto_point_channel, 0, 2),
Hans de Goede49010622009-01-07 16:37:30 +0100700 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
701 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
702 1, 2),
703 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
704 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
705 4, 2),
706 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
707 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
708 0, 2),
709 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
710 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
711 3, 2),
712 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
713 show_pwm_auto_point_temp_hyst,
714 store_pwm_auto_point_temp_hyst,
715 0, 2),
716 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
717 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
Hans de Goede55840142011-09-09 12:12:33 +0200718} };
Hans de Goede498be962009-01-07 16:37:28 +0100719
Guenter Roeck20eaf722012-01-19 11:02:17 -0800720/*
721 * PWM attr for the f71808e/f71869, almost identical to the f71862fg, but the
722 * pwm setting when the temperature is above the pwmX_auto_point1_temp can be
723 * programmed instead of being hardcoded to 0xff
724 */
Hans de Goede55840142011-09-09 12:12:33 +0200725static struct sensor_device_attribute_2 f71869_auto_pwm_attr[3][8] = { {
Hans de Goedec11bb992011-03-09 20:57:15 +0100726 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
727 show_pwm_auto_point_channel,
728 store_pwm_auto_point_channel, 0, 0),
729 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
730 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
731 0, 0),
732 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
733 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
734 1, 0),
735 SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO|S_IWUSR,
736 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
737 4, 0),
738 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
739 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
740 0, 0),
741 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
742 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
743 3, 0),
744 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
745 show_pwm_auto_point_temp_hyst,
746 store_pwm_auto_point_temp_hyst,
747 0, 0),
748 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
749 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
Hans de Goede55840142011-09-09 12:12:33 +0200750}, {
Hans de Goedec11bb992011-03-09 20:57:15 +0100751 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
752 show_pwm_auto_point_channel,
753 store_pwm_auto_point_channel, 0, 1),
754 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
755 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
756 0, 1),
757 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
758 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
759 1, 1),
760 SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO|S_IWUSR,
761 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
762 4, 1),
763 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
764 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
765 0, 1),
766 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
767 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
768 3, 1),
769 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
770 show_pwm_auto_point_temp_hyst,
771 store_pwm_auto_point_temp_hyst,
772 0, 1),
773 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
774 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
Hans de Goede55840142011-09-09 12:12:33 +0200775}, {
Hans de Goedec11bb992011-03-09 20:57:15 +0100776 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
777 show_pwm_auto_point_channel,
778 store_pwm_auto_point_channel, 0, 2),
779 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
780 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
781 0, 2),
782 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
783 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
784 1, 2),
785 SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO|S_IWUSR,
786 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
787 4, 2),
788 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
789 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
790 0, 2),
791 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
792 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
793 3, 2),
794 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
795 show_pwm_auto_point_temp_hyst,
796 store_pwm_auto_point_temp_hyst,
797 0, 2),
798 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
799 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
Hans de Goede55840142011-09-09 12:12:33 +0200800} };
Hans de Goedec11bb992011-03-09 20:57:15 +0100801
Hans de Goede3cad4022011-03-09 20:57:14 +0100802/* PWM attr for the standard models */
Hans de Goedeb69b0392009-12-09 20:36:00 +0100803static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr[4][14] = { {
Hans de Goede66344aa2009-12-09 20:35:59 +0100804 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
805 show_pwm_auto_point_channel,
806 store_pwm_auto_point_channel, 0, 0),
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100807 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
808 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
809 0, 0),
810 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
811 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
812 1, 0),
813 SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO|S_IWUSR,
814 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
815 2, 0),
816 SENSOR_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO|S_IWUSR,
817 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
818 3, 0),
819 SENSOR_ATTR_2(pwm1_auto_point5_pwm, S_IRUGO|S_IWUSR,
820 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
821 4, 0),
822 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
823 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
824 0, 0),
825 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
826 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
827 1, 0),
828 SENSOR_ATTR_2(pwm1_auto_point3_temp, S_IRUGO|S_IWUSR,
829 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
830 2, 0),
831 SENSOR_ATTR_2(pwm1_auto_point4_temp, S_IRUGO|S_IWUSR,
832 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
833 3, 0),
834 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
835 show_pwm_auto_point_temp_hyst,
836 store_pwm_auto_point_temp_hyst,
837 0, 0),
838 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
839 show_pwm_auto_point_temp_hyst, NULL, 1, 0),
840 SENSOR_ATTR_2(pwm1_auto_point3_temp_hyst, S_IRUGO,
841 show_pwm_auto_point_temp_hyst, NULL, 2, 0),
842 SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst, S_IRUGO,
843 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100844}, {
Hans de Goede66344aa2009-12-09 20:35:59 +0100845 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
846 show_pwm_auto_point_channel,
847 store_pwm_auto_point_channel, 0, 1),
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100848 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
849 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
850 0, 1),
851 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
852 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
853 1, 1),
854 SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO|S_IWUSR,
855 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
856 2, 1),
857 SENSOR_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO|S_IWUSR,
858 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
859 3, 1),
860 SENSOR_ATTR_2(pwm2_auto_point5_pwm, S_IRUGO|S_IWUSR,
861 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
862 4, 1),
863 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
864 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
865 0, 1),
866 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
867 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
868 1, 1),
869 SENSOR_ATTR_2(pwm2_auto_point3_temp, S_IRUGO|S_IWUSR,
870 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
871 2, 1),
872 SENSOR_ATTR_2(pwm2_auto_point4_temp, S_IRUGO|S_IWUSR,
873 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
874 3, 1),
875 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
876 show_pwm_auto_point_temp_hyst,
877 store_pwm_auto_point_temp_hyst,
878 0, 1),
879 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
880 show_pwm_auto_point_temp_hyst, NULL, 1, 1),
881 SENSOR_ATTR_2(pwm2_auto_point3_temp_hyst, S_IRUGO,
882 show_pwm_auto_point_temp_hyst, NULL, 2, 1),
883 SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst, S_IRUGO,
884 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100885}, {
Hans de Goede66344aa2009-12-09 20:35:59 +0100886 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
887 show_pwm_auto_point_channel,
888 store_pwm_auto_point_channel, 0, 2),
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100889 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
890 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
891 0, 2),
892 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
893 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
894 1, 2),
895 SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO|S_IWUSR,
896 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
897 2, 2),
898 SENSOR_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO|S_IWUSR,
899 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
900 3, 2),
901 SENSOR_ATTR_2(pwm3_auto_point5_pwm, S_IRUGO|S_IWUSR,
902 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
903 4, 2),
904 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
905 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
906 0, 2),
907 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
908 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
909 1, 2),
910 SENSOR_ATTR_2(pwm3_auto_point3_temp, S_IRUGO|S_IWUSR,
911 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
912 2, 2),
913 SENSOR_ATTR_2(pwm3_auto_point4_temp, S_IRUGO|S_IWUSR,
914 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
915 3, 2),
916 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
917 show_pwm_auto_point_temp_hyst,
918 store_pwm_auto_point_temp_hyst,
919 0, 2),
920 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
921 show_pwm_auto_point_temp_hyst, NULL, 1, 2),
922 SENSOR_ATTR_2(pwm3_auto_point3_temp_hyst, S_IRUGO,
923 show_pwm_auto_point_temp_hyst, NULL, 2, 2),
924 SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst, S_IRUGO,
925 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100926}, {
Mark van Doesburg9ab796e2009-01-07 16:37:27 +0100927 SENSOR_ATTR_2(pwm4_auto_channels_temp, S_IRUGO|S_IWUSR,
928 show_pwm_auto_point_channel,
929 store_pwm_auto_point_channel, 0, 3),
930 SENSOR_ATTR_2(pwm4_auto_point1_pwm, S_IRUGO|S_IWUSR,
931 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
932 0, 3),
933 SENSOR_ATTR_2(pwm4_auto_point2_pwm, S_IRUGO|S_IWUSR,
934 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
935 1, 3),
936 SENSOR_ATTR_2(pwm4_auto_point3_pwm, S_IRUGO|S_IWUSR,
937 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
938 2, 3),
939 SENSOR_ATTR_2(pwm4_auto_point4_pwm, S_IRUGO|S_IWUSR,
940 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
941 3, 3),
942 SENSOR_ATTR_2(pwm4_auto_point5_pwm, S_IRUGO|S_IWUSR,
943 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
944 4, 3),
945 SENSOR_ATTR_2(pwm4_auto_point1_temp, S_IRUGO|S_IWUSR,
946 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
947 0, 3),
948 SENSOR_ATTR_2(pwm4_auto_point2_temp, S_IRUGO|S_IWUSR,
949 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
950 1, 3),
951 SENSOR_ATTR_2(pwm4_auto_point3_temp, S_IRUGO|S_IWUSR,
952 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
953 2, 3),
954 SENSOR_ATTR_2(pwm4_auto_point4_temp, S_IRUGO|S_IWUSR,
955 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
956 3, 3),
957 SENSOR_ATTR_2(pwm4_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
958 show_pwm_auto_point_temp_hyst,
959 store_pwm_auto_point_temp_hyst,
960 0, 3),
961 SENSOR_ATTR_2(pwm4_auto_point2_temp_hyst, S_IRUGO,
962 show_pwm_auto_point_temp_hyst, NULL, 1, 3),
963 SENSOR_ATTR_2(pwm4_auto_point3_temp_hyst, S_IRUGO,
964 show_pwm_auto_point_temp_hyst, NULL, 2, 3),
965 SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst, S_IRUGO,
966 show_pwm_auto_point_temp_hyst, NULL, 3, 3),
Hans de Goedeb69b0392009-12-09 20:36:00 +0100967} };
Hans de Goede45fb3662007-07-13 14:34:19 +0200968
Hans de Goede66344aa2009-12-09 20:35:59 +0100969/* Fan attr specific to the f8000 (4th fan input can only measure speed) */
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100970static struct sensor_device_attribute_2 f8000_fan_attr[] = {
971 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
Hans de Goede66344aa2009-12-09 20:35:59 +0100972};
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100973
Guenter Roeck20eaf722012-01-19 11:02:17 -0800974/*
975 * PWM attr for the f8000, zones mapped to temp instead of to pwm!
976 * Also the register block at offset A0 maps to TEMP1 (so our temp2, as the
977 * F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0
978 */
Hans de Goede55840142011-09-09 12:12:33 +0200979static struct sensor_device_attribute_2 f8000_auto_pwm_attr[3][14] = { {
Hans de Goede66344aa2009-12-09 20:35:59 +0100980 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
981 show_pwm_auto_point_channel,
982 store_pwm_auto_point_channel, 0, 0),
Hans de Goedeed4f7c22009-01-07 16:37:30 +0100983 SENSOR_ATTR_2(temp1_auto_point1_pwm, S_IRUGO|S_IWUSR,
984 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
985 0, 2),
986 SENSOR_ATTR_2(temp1_auto_point2_pwm, S_IRUGO|S_IWUSR,
987 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
988 1, 2),
989 SENSOR_ATTR_2(temp1_auto_point3_pwm, S_IRUGO|S_IWUSR,
990 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
991 2, 2),
992 SENSOR_ATTR_2(temp1_auto_point4_pwm, S_IRUGO|S_IWUSR,
993 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
994 3, 2),
995 SENSOR_ATTR_2(temp1_auto_point5_pwm, S_IRUGO|S_IWUSR,
996 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
997 4, 2),
998 SENSOR_ATTR_2(temp1_auto_point1_temp, S_IRUGO|S_IWUSR,
999 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1000 0, 2),
1001 SENSOR_ATTR_2(temp1_auto_point2_temp, S_IRUGO|S_IWUSR,
1002 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1003 1, 2),
1004 SENSOR_ATTR_2(temp1_auto_point3_temp, S_IRUGO|S_IWUSR,
1005 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1006 2, 2),
1007 SENSOR_ATTR_2(temp1_auto_point4_temp, S_IRUGO|S_IWUSR,
1008 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1009 3, 2),
1010 SENSOR_ATTR_2(temp1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
1011 show_pwm_auto_point_temp_hyst,
1012 store_pwm_auto_point_temp_hyst,
1013 0, 2),
1014 SENSOR_ATTR_2(temp1_auto_point2_temp_hyst, S_IRUGO,
1015 show_pwm_auto_point_temp_hyst, NULL, 1, 2),
1016 SENSOR_ATTR_2(temp1_auto_point3_temp_hyst, S_IRUGO,
1017 show_pwm_auto_point_temp_hyst, NULL, 2, 2),
1018 SENSOR_ATTR_2(temp1_auto_point4_temp_hyst, S_IRUGO,
1019 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
Hans de Goede55840142011-09-09 12:12:33 +02001020}, {
Hans de Goede66344aa2009-12-09 20:35:59 +01001021 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
1022 show_pwm_auto_point_channel,
1023 store_pwm_auto_point_channel, 0, 1),
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001024 SENSOR_ATTR_2(temp2_auto_point1_pwm, S_IRUGO|S_IWUSR,
1025 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1026 0, 0),
1027 SENSOR_ATTR_2(temp2_auto_point2_pwm, S_IRUGO|S_IWUSR,
1028 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1029 1, 0),
1030 SENSOR_ATTR_2(temp2_auto_point3_pwm, S_IRUGO|S_IWUSR,
1031 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1032 2, 0),
1033 SENSOR_ATTR_2(temp2_auto_point4_pwm, S_IRUGO|S_IWUSR,
1034 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1035 3, 0),
1036 SENSOR_ATTR_2(temp2_auto_point5_pwm, S_IRUGO|S_IWUSR,
1037 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1038 4, 0),
1039 SENSOR_ATTR_2(temp2_auto_point1_temp, S_IRUGO|S_IWUSR,
1040 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1041 0, 0),
1042 SENSOR_ATTR_2(temp2_auto_point2_temp, S_IRUGO|S_IWUSR,
1043 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1044 1, 0),
1045 SENSOR_ATTR_2(temp2_auto_point3_temp, S_IRUGO|S_IWUSR,
1046 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1047 2, 0),
1048 SENSOR_ATTR_2(temp2_auto_point4_temp, S_IRUGO|S_IWUSR,
1049 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1050 3, 0),
1051 SENSOR_ATTR_2(temp2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
1052 show_pwm_auto_point_temp_hyst,
1053 store_pwm_auto_point_temp_hyst,
1054 0, 0),
1055 SENSOR_ATTR_2(temp2_auto_point2_temp_hyst, S_IRUGO,
1056 show_pwm_auto_point_temp_hyst, NULL, 1, 0),
1057 SENSOR_ATTR_2(temp2_auto_point3_temp_hyst, S_IRUGO,
1058 show_pwm_auto_point_temp_hyst, NULL, 2, 0),
1059 SENSOR_ATTR_2(temp2_auto_point4_temp_hyst, S_IRUGO,
1060 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
Hans de Goede55840142011-09-09 12:12:33 +02001061}, {
Hans de Goede66344aa2009-12-09 20:35:59 +01001062 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
1063 show_pwm_auto_point_channel,
1064 store_pwm_auto_point_channel, 0, 2),
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001065 SENSOR_ATTR_2(temp3_auto_point1_pwm, S_IRUGO|S_IWUSR,
1066 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1067 0, 1),
1068 SENSOR_ATTR_2(temp3_auto_point2_pwm, S_IRUGO|S_IWUSR,
1069 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1070 1, 1),
1071 SENSOR_ATTR_2(temp3_auto_point3_pwm, S_IRUGO|S_IWUSR,
1072 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1073 2, 1),
1074 SENSOR_ATTR_2(temp3_auto_point4_pwm, S_IRUGO|S_IWUSR,
1075 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1076 3, 1),
1077 SENSOR_ATTR_2(temp3_auto_point5_pwm, S_IRUGO|S_IWUSR,
1078 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1079 4, 1),
1080 SENSOR_ATTR_2(temp3_auto_point1_temp, S_IRUGO|S_IWUSR,
1081 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1082 0, 1),
1083 SENSOR_ATTR_2(temp3_auto_point2_temp, S_IRUGO|S_IWUSR,
1084 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1085 1, 1),
1086 SENSOR_ATTR_2(temp3_auto_point3_temp, S_IRUGO|S_IWUSR,
1087 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1088 2, 1),
1089 SENSOR_ATTR_2(temp3_auto_point4_temp, S_IRUGO|S_IWUSR,
1090 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1091 3, 1),
1092 SENSOR_ATTR_2(temp3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
1093 show_pwm_auto_point_temp_hyst,
1094 store_pwm_auto_point_temp_hyst,
1095 0, 1),
1096 SENSOR_ATTR_2(temp3_auto_point2_temp_hyst, S_IRUGO,
1097 show_pwm_auto_point_temp_hyst, NULL, 1, 1),
1098 SENSOR_ATTR_2(temp3_auto_point3_temp_hyst, S_IRUGO,
1099 show_pwm_auto_point_temp_hyst, NULL, 2, 1),
1100 SENSOR_ATTR_2(temp3_auto_point4_temp_hyst, S_IRUGO,
1101 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
Hans de Goede55840142011-09-09 12:12:33 +02001102} };
Hans de Goede45fb3662007-07-13 14:34:19 +02001103
1104/* Super I/O functions */
1105static inline int superio_inb(int base, int reg)
1106{
1107 outb(reg, base);
1108 return inb(base + 1);
1109}
1110
1111static int superio_inw(int base, int reg)
1112{
1113 int val;
Giel van Schijndelbd328ac2010-05-27 19:58:42 +02001114 val = superio_inb(base, reg) << 8;
1115 val |= superio_inb(base, reg + 1);
Hans de Goede45fb3662007-07-13 14:34:19 +02001116 return val;
1117}
1118
Giel van Schijndelcadb8652010-10-03 08:09:49 -04001119static inline int superio_enter(int base)
Hans de Goede45fb3662007-07-13 14:34:19 +02001120{
Giel van Schijndelcadb8652010-10-03 08:09:49 -04001121 /* Don't step on other drivers' I/O space by accident */
1122 if (!request_muxed_region(base, 2, DRVNAME)) {
Joe Perches22d3b412010-10-20 06:51:34 +00001123 pr_err("I/O address 0x%04x already in use\n", base);
Giel van Schijndelcadb8652010-10-03 08:09:49 -04001124 return -EBUSY;
1125 }
1126
Hans de Goede45fb3662007-07-13 14:34:19 +02001127 /* according to the datasheet the key must be send twice! */
Giel van Schijndel162bb592010-05-27 19:58:40 +02001128 outb(SIO_UNLOCK_KEY, base);
1129 outb(SIO_UNLOCK_KEY, base);
Giel van Schijndelcadb8652010-10-03 08:09:49 -04001130
1131 return 0;
Hans de Goede45fb3662007-07-13 14:34:19 +02001132}
1133
Giel van Schijndel162bb592010-05-27 19:58:40 +02001134static inline void superio_select(int base, int ld)
Hans de Goede45fb3662007-07-13 14:34:19 +02001135{
1136 outb(SIO_REG_LDSEL, base);
1137 outb(ld, base + 1);
1138}
1139
1140static inline void superio_exit(int base)
1141{
1142 outb(SIO_LOCK_KEY, base);
Giel van Schijndelcadb8652010-10-03 08:09:49 -04001143 release_region(base, 2);
Hans de Goede45fb3662007-07-13 14:34:19 +02001144}
1145
Hans de Goede2f650632009-01-07 16:37:31 +01001146static inline int fan_from_reg(u16 reg)
Hans de Goede45fb3662007-07-13 14:34:19 +02001147{
1148 return reg ? (1500000 / reg) : 0;
1149}
1150
Hans de Goede2f650632009-01-07 16:37:31 +01001151static inline u16 fan_to_reg(int fan)
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001152{
1153 return fan ? (1500000 / fan) : 0;
1154}
1155
Hans de Goede45fb3662007-07-13 14:34:19 +02001156static u8 f71882fg_read8(struct f71882fg_data *data, u8 reg)
1157{
1158 u8 val;
1159
1160 outb(reg, data->addr + ADDR_REG_OFFSET);
1161 val = inb(data->addr + DATA_REG_OFFSET);
1162
1163 return val;
1164}
1165
1166static u16 f71882fg_read16(struct f71882fg_data *data, u8 reg)
1167{
1168 u16 val;
1169
Giel van Schijndelbd328ac2010-05-27 19:58:42 +02001170 val = f71882fg_read8(data, reg) << 8;
1171 val |= f71882fg_read8(data, reg + 1);
Hans de Goede45fb3662007-07-13 14:34:19 +02001172
1173 return val;
1174}
1175
1176static void f71882fg_write8(struct f71882fg_data *data, u8 reg, u8 val)
1177{
1178 outb(reg, data->addr + ADDR_REG_OFFSET);
1179 outb(val, data->addr + DATA_REG_OFFSET);
1180}
1181
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001182static void f71882fg_write16(struct f71882fg_data *data, u8 reg, u16 val)
1183{
Giel van Schijndelbd328ac2010-05-27 19:58:42 +02001184 f71882fg_write8(data, reg, val >> 8);
1185 f71882fg_write8(data, reg + 1, val & 0xff);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001186}
1187
Hans de Goede09475d32009-06-15 18:39:52 +02001188static u16 f71882fg_read_temp(struct f71882fg_data *data, int nr)
1189{
1190 if (data->type == f71858fg)
1191 return f71882fg_read16(data, F71882FG_REG_TEMP(nr));
1192 else
1193 return f71882fg_read8(data, F71882FG_REG_TEMP(nr));
1194}
1195
Mark van Doesburg77a4a3e2009-01-07 16:37:27 +01001196static struct f71882fg_data *f71882fg_update_device(struct device *dev)
Hans de Goede45fb3662007-07-13 14:34:19 +02001197{
1198 struct f71882fg_data *data = dev_get_drvdata(dev);
Jean Delvaref27def02011-03-26 10:45:01 +01001199 int nr_fans = f71882fg_nr_fans[data->type];
1200 int nr_temps = f71882fg_nr_temps[data->type];
Hans de Goedee5e713c2011-03-10 08:54:02 +01001201 int nr, reg, point;
Hans de Goede45fb3662007-07-13 14:34:19 +02001202
1203 mutex_lock(&data->update_lock);
1204
1205 /* Update once every 60 seconds */
Giel van Schijndel162bb592010-05-27 19:58:40 +02001206 if (time_after(jiffies, data->last_limits + 60 * HZ) ||
Hans de Goede45fb3662007-07-13 14:34:19 +02001207 !data->valid) {
Hans de Goede0bae6402011-03-09 20:57:10 +01001208 if (f71882fg_has_in1_alarm[data->type]) {
Peter Hung3e40b862015-07-07 16:22:38 +08001209 if (data->type == f81866a) {
1210 data->in1_max =
1211 f71882fg_read8(data,
1212 F81866_REG_IN1_HIGH);
1213 data->in_beep =
1214 f71882fg_read8(data,
1215 F81866_REG_IN_BEEP);
1216 } else {
1217 data->in1_max =
1218 f71882fg_read8(data,
1219 F71882FG_REG_IN1_HIGH);
1220 data->in_beep =
1221 f71882fg_read8(data,
1222 F71882FG_REG_IN_BEEP);
1223 }
Hans de Goede498be962009-01-07 16:37:28 +01001224 }
Hans de Goede45fb3662007-07-13 14:34:19 +02001225
1226 /* Get High & boundary temps*/
Hans de Goedee5e713c2011-03-10 08:54:02 +01001227 for (nr = data->temp_start; nr < nr_temps + data->temp_start;
1228 nr++) {
Hans de Goede45fb3662007-07-13 14:34:19 +02001229 data->temp_ovt[nr] = f71882fg_read8(data,
1230 F71882FG_REG_TEMP_OVT(nr));
1231 data->temp_high[nr] = f71882fg_read8(data,
1232 F71882FG_REG_TEMP_HIGH(nr));
1233 }
1234
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001235 if (data->type != f8000) {
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001236 data->temp_hyst[0] = f71882fg_read8(data,
1237 F71882FG_REG_TEMP_HYST(0));
1238 data->temp_hyst[1] = f71882fg_read8(data,
1239 F71882FG_REG_TEMP_HYST(1));
Hans de Goede09475d32009-06-15 18:39:52 +02001240 }
Hans de Goede78aa4f72011-03-09 20:57:12 +01001241 /* All but the f71858fg / f8000 have this register */
1242 if ((data->type != f71858fg) && (data->type != f8000)) {
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001243 reg = f71882fg_read8(data, F71882FG_REG_TEMP_TYPE);
Hans de Goede44c4dc52011-03-09 20:57:07 +01001244 data->temp_type[1] = (reg & 0x02) ? 2 : 4;
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001245 data->temp_type[2] = (reg & 0x04) ? 2 : 4;
1246 data->temp_type[3] = (reg & 0x08) ? 2 : 4;
1247 }
Hans de Goede45fb3662007-07-13 14:34:19 +02001248
Hans de Goede4d538112011-05-25 20:43:32 +02001249 if (f71882fg_fan_has_beep[data->type])
Hans de Goede78aa4f72011-03-09 20:57:12 +01001250 data->fan_beep = f71882fg_read8(data,
1251 F71882FG_REG_FAN_BEEP);
Hans de Goede4d538112011-05-25 20:43:32 +02001252
1253 if (f71882fg_temp_has_beep[data->type])
Hans de Goede78aa4f72011-03-09 20:57:12 +01001254 data->temp_beep = f71882fg_read8(data,
1255 F71882FG_REG_TEMP_BEEP);
Hans de Goede78aa4f72011-03-09 20:57:12 +01001256
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001257 data->pwm_enable = f71882fg_read8(data,
1258 F71882FG_REG_PWM_ENABLE);
Hans de Goedebc274902009-01-07 16:37:29 +01001259 data->pwm_auto_point_hyst[0] =
1260 f71882fg_read8(data, F71882FG_REG_FAN_HYST(0));
1261 data->pwm_auto_point_hyst[1] =
1262 f71882fg_read8(data, F71882FG_REG_FAN_HYST(1));
1263
Hans de Goede498be962009-01-07 16:37:28 +01001264 for (nr = 0; nr < nr_fans; nr++) {
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001265 data->pwm_auto_point_mapping[nr] =
1266 f71882fg_read8(data,
1267 F71882FG_REG_POINT_MAPPING(nr));
1268
Hans de Goedee5e713c2011-03-10 08:54:02 +01001269 switch (data->type) {
1270 default:
Hans de Goede498be962009-01-07 16:37:28 +01001271 for (point = 0; point < 5; point++) {
1272 data->pwm_auto_point_pwm[nr][point] =
1273 f71882fg_read8(data,
1274 F71882FG_REG_POINT_PWM
1275 (nr, point));
1276 }
1277 for (point = 0; point < 4; point++) {
1278 data->pwm_auto_point_temp[nr][point] =
1279 f71882fg_read8(data,
1280 F71882FG_REG_POINT_TEMP
1281 (nr, point));
1282 }
Hans de Goedee5e713c2011-03-10 08:54:02 +01001283 break;
1284 case f71808e:
1285 case f71869:
1286 data->pwm_auto_point_pwm[nr][0] =
1287 f71882fg_read8(data,
1288 F71882FG_REG_POINT_PWM(nr, 0));
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05001289 fallthrough;
Hans de Goedee5e713c2011-03-10 08:54:02 +01001290 case f71862fg:
Hans de Goede498be962009-01-07 16:37:28 +01001291 data->pwm_auto_point_pwm[nr][1] =
1292 f71882fg_read8(data,
1293 F71882FG_REG_POINT_PWM
1294 (nr, 1));
1295 data->pwm_auto_point_pwm[nr][4] =
1296 f71882fg_read8(data,
1297 F71882FG_REG_POINT_PWM
1298 (nr, 4));
1299 data->pwm_auto_point_temp[nr][0] =
1300 f71882fg_read8(data,
1301 F71882FG_REG_POINT_TEMP
1302 (nr, 0));
1303 data->pwm_auto_point_temp[nr][3] =
1304 f71882fg_read8(data,
1305 F71882FG_REG_POINT_TEMP
1306 (nr, 3));
Hans de Goedee5e713c2011-03-10 08:54:02 +01001307 break;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001308 }
1309 }
Hans de Goede45fb3662007-07-13 14:34:19 +02001310 data->last_limits = jiffies;
1311 }
1312
1313 /* Update every second */
Mark M. Hoffman8afb1042007-08-21 23:10:46 -04001314 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
Hans de Goede45fb3662007-07-13 14:34:19 +02001315 data->temp_status = f71882fg_read8(data,
1316 F71882FG_REG_TEMP_STATUS);
1317 data->temp_diode_open = f71882fg_read8(data,
1318 F71882FG_REG_TEMP_DIODE_OPEN);
Hans de Goedee5e713c2011-03-10 08:54:02 +01001319 for (nr = data->temp_start; nr < nr_temps + data->temp_start;
1320 nr++)
Hans de Goede09475d32009-06-15 18:39:52 +02001321 data->temp[nr] = f71882fg_read_temp(data, nr);
Hans de Goede45fb3662007-07-13 14:34:19 +02001322
1323 data->fan_status = f71882fg_read8(data,
1324 F71882FG_REG_FAN_STATUS);
Hans de Goede498be962009-01-07 16:37:28 +01001325 for (nr = 0; nr < nr_fans; nr++) {
Hans de Goede45fb3662007-07-13 14:34:19 +02001326 data->fan[nr] = f71882fg_read16(data,
1327 F71882FG_REG_FAN(nr));
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001328 data->fan_target[nr] =
1329 f71882fg_read16(data, F71882FG_REG_FAN_TARGET(nr));
1330 data->fan_full_speed[nr] =
1331 f71882fg_read16(data,
1332 F71882FG_REG_FAN_FULL_SPEED(nr));
1333 data->pwm[nr] =
1334 f71882fg_read8(data, F71882FG_REG_PWM(nr));
1335 }
Hans de Goede629c58b2011-05-25 20:43:32 +02001336 /* Some models have 1 more fan with limited capabilities */
1337 if (data->type == f71808a) {
1338 data->fan[2] = f71882fg_read16(data,
1339 F71882FG_REG_FAN(2));
1340 data->pwm[2] = f71882fg_read8(data,
1341 F71882FG_REG_PWM(2));
1342 }
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001343 if (data->type == f8000)
1344 data->fan[3] = f71882fg_read16(data,
1345 F71882FG_REG_FAN(3));
Hans de Goede0bae6402011-03-09 20:57:10 +01001346
Peter Hung3e40b862015-07-07 16:22:38 +08001347 if (f71882fg_has_in1_alarm[data->type]) {
1348 if (data->type == f81866a)
1349 data->in_status = f71882fg_read8(data,
1350 F81866_REG_IN_STATUS);
1351
1352 else
1353 data->in_status = f71882fg_read8(data,
Hans de Goede45fb3662007-07-13 14:34:19 +02001354 F71882FG_REG_IN_STATUS);
Peter Hung3e40b862015-07-07 16:22:38 +08001355 }
1356
Hans de Goede0bae6402011-03-09 20:57:10 +01001357 for (nr = 0; nr < F71882FG_MAX_INS; nr++)
1358 if (f71882fg_has_in[data->type][nr])
1359 data->in[nr] = f71882fg_read8(data,
1360 F71882FG_REG_IN(nr));
Hans de Goede45fb3662007-07-13 14:34:19 +02001361
1362 data->last_updated = jiffies;
Paul Fertser952a11c2021-09-24 22:52:02 +03001363 data->valid = true;
Hans de Goede45fb3662007-07-13 14:34:19 +02001364 }
1365
1366 mutex_unlock(&data->update_lock);
1367
1368 return data;
1369}
1370
1371/* Sysfs Interface */
1372static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
1373 char *buf)
1374{
1375 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001376 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001377 int speed = fan_from_reg(data->fan[nr]);
1378
1379 if (speed == FAN_MIN_DETECT)
1380 speed = 0;
1381
1382 return sprintf(buf, "%d\n", speed);
1383}
1384
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001385static ssize_t show_fan_full_speed(struct device *dev,
1386 struct device_attribute *devattr, char *buf)
1387{
1388 struct f71882fg_data *data = f71882fg_update_device(dev);
1389 int nr = to_sensor_dev_attr_2(devattr)->index;
1390 int speed = fan_from_reg(data->fan_full_speed[nr]);
1391 return sprintf(buf, "%d\n", speed);
1392}
1393
1394static ssize_t store_fan_full_speed(struct device *dev,
1395 struct device_attribute *devattr,
1396 const char *buf, size_t count)
1397{
1398 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001399 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1400 long val;
1401
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001402 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001403 if (err)
1404 return err;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001405
Guenter Roeck2a844c12013-01-09 08:09:34 -08001406 val = clamp_val(val, 23, 1500000);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001407 val = fan_to_reg(val);
1408
1409 mutex_lock(&data->update_lock);
Hans de Goede4c82c382009-01-07 16:37:30 +01001410 f71882fg_write16(data, F71882FG_REG_FAN_FULL_SPEED(nr), val);
1411 data->fan_full_speed[nr] = val;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001412 mutex_unlock(&data->update_lock);
1413
1414 return count;
1415}
1416
Hans de Goede45fb3662007-07-13 14:34:19 +02001417static ssize_t show_fan_beep(struct device *dev, struct device_attribute
1418 *devattr, char *buf)
1419{
1420 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001421 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001422
1423 if (data->fan_beep & (1 << nr))
1424 return sprintf(buf, "1\n");
1425 else
1426 return sprintf(buf, "0\n");
1427}
1428
1429static ssize_t store_fan_beep(struct device *dev, struct device_attribute
1430 *devattr, const char *buf, size_t count)
1431{
1432 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001433 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1434 unsigned long val;
1435
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001436 err = kstrtoul(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001437 if (err)
1438 return err;
Hans de Goede45fb3662007-07-13 14:34:19 +02001439
1440 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01001441 data->fan_beep = f71882fg_read8(data, F71882FG_REG_FAN_BEEP);
Hans de Goede45fb3662007-07-13 14:34:19 +02001442 if (val)
1443 data->fan_beep |= 1 << nr;
1444 else
1445 data->fan_beep &= ~(1 << nr);
1446
1447 f71882fg_write8(data, F71882FG_REG_FAN_BEEP, data->fan_beep);
1448 mutex_unlock(&data->update_lock);
1449
1450 return count;
1451}
1452
1453static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
1454 *devattr, char *buf)
1455{
1456 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001457 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001458
1459 if (data->fan_status & (1 << nr))
1460 return sprintf(buf, "1\n");
1461 else
1462 return sprintf(buf, "0\n");
1463}
1464
1465static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
1466 char *buf)
1467{
1468 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001469 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001470
1471 return sprintf(buf, "%d\n", data->in[nr] * 8);
1472}
1473
1474static ssize_t show_in_max(struct device *dev, struct device_attribute
1475 *devattr, char *buf)
1476{
1477 struct f71882fg_data *data = f71882fg_update_device(dev);
1478
1479 return sprintf(buf, "%d\n", data->in1_max * 8);
1480}
1481
1482static ssize_t store_in_max(struct device *dev, struct device_attribute
1483 *devattr, const char *buf, size_t count)
1484{
1485 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001486 int err;
1487 long val;
1488
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001489 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001490 if (err)
1491 return err;
1492
1493 val /= 8;
Guenter Roeck2a844c12013-01-09 08:09:34 -08001494 val = clamp_val(val, 0, 255);
Hans de Goede45fb3662007-07-13 14:34:19 +02001495
1496 mutex_lock(&data->update_lock);
Peter Hung3e40b862015-07-07 16:22:38 +08001497 if (data->type == f81866a)
1498 f71882fg_write8(data, F81866_REG_IN1_HIGH, val);
1499 else
1500 f71882fg_write8(data, F71882FG_REG_IN1_HIGH, val);
Hans de Goede45fb3662007-07-13 14:34:19 +02001501 data->in1_max = val;
1502 mutex_unlock(&data->update_lock);
1503
1504 return count;
1505}
1506
1507static ssize_t show_in_beep(struct device *dev, struct device_attribute
1508 *devattr, char *buf)
1509{
1510 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001511 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001512
1513 if (data->in_beep & (1 << nr))
1514 return sprintf(buf, "1\n");
1515 else
1516 return sprintf(buf, "0\n");
1517}
1518
1519static ssize_t store_in_beep(struct device *dev, struct device_attribute
1520 *devattr, const char *buf, size_t count)
1521{
1522 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001523 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1524 unsigned long val;
1525
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001526 err = kstrtoul(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001527 if (err)
1528 return err;
Hans de Goede45fb3662007-07-13 14:34:19 +02001529
1530 mutex_lock(&data->update_lock);
Peter Hung3e40b862015-07-07 16:22:38 +08001531 if (data->type == f81866a)
1532 data->in_beep = f71882fg_read8(data, F81866_REG_IN_BEEP);
1533 else
1534 data->in_beep = f71882fg_read8(data, F71882FG_REG_IN_BEEP);
1535
Hans de Goede45fb3662007-07-13 14:34:19 +02001536 if (val)
1537 data->in_beep |= 1 << nr;
1538 else
1539 data->in_beep &= ~(1 << nr);
1540
Peter Hung3e40b862015-07-07 16:22:38 +08001541 if (data->type == f81866a)
1542 f71882fg_write8(data, F81866_REG_IN_BEEP, data->in_beep);
1543 else
1544 f71882fg_write8(data, F71882FG_REG_IN_BEEP, data->in_beep);
Hans de Goede45fb3662007-07-13 14:34:19 +02001545 mutex_unlock(&data->update_lock);
1546
1547 return count;
1548}
1549
1550static ssize_t show_in_alarm(struct device *dev, struct device_attribute
1551 *devattr, char *buf)
1552{
1553 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001554 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001555
1556 if (data->in_status & (1 << nr))
1557 return sprintf(buf, "1\n");
1558 else
1559 return sprintf(buf, "0\n");
1560}
1561
1562static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
1563 char *buf)
1564{
1565 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001566 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede09475d32009-06-15 18:39:52 +02001567 int sign, temp;
Hans de Goede45fb3662007-07-13 14:34:19 +02001568
Hans de Goede09475d32009-06-15 18:39:52 +02001569 if (data->type == f71858fg) {
1570 /* TEMP_TABLE_SEL 1 or 3 ? */
1571 if (data->temp_config & 1) {
1572 sign = data->temp[nr] & 0x0001;
1573 temp = (data->temp[nr] >> 5) & 0x7ff;
1574 } else {
1575 sign = data->temp[nr] & 0x8000;
1576 temp = (data->temp[nr] >> 5) & 0x3ff;
1577 }
1578 temp *= 125;
1579 if (sign)
1580 temp -= 128000;
1581 } else
1582 temp = data->temp[nr] * 1000;
1583
1584 return sprintf(buf, "%d\n", temp);
Hans de Goede45fb3662007-07-13 14:34:19 +02001585}
1586
1587static ssize_t show_temp_max(struct device *dev, struct device_attribute
1588 *devattr, char *buf)
1589{
1590 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001591 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001592
1593 return sprintf(buf, "%d\n", data->temp_high[nr] * 1000);
1594}
1595
1596static ssize_t store_temp_max(struct device *dev, struct device_attribute
1597 *devattr, const char *buf, size_t count)
1598{
1599 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001600 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1601 long val;
1602
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001603 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001604 if (err)
1605 return err;
1606
1607 val /= 1000;
Guenter Roeck2a844c12013-01-09 08:09:34 -08001608 val = clamp_val(val, 0, 255);
Hans de Goede45fb3662007-07-13 14:34:19 +02001609
1610 mutex_lock(&data->update_lock);
1611 f71882fg_write8(data, F71882FG_REG_TEMP_HIGH(nr), val);
1612 data->temp_high[nr] = val;
1613 mutex_unlock(&data->update_lock);
1614
1615 return count;
1616}
1617
1618static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
1619 *devattr, char *buf)
1620{
1621 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001622 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goedece0bfa52009-01-07 16:37:28 +01001623 int temp_max_hyst;
Hans de Goede45fb3662007-07-13 14:34:19 +02001624
Hans de Goedece0bfa52009-01-07 16:37:28 +01001625 mutex_lock(&data->update_lock);
Hans de Goedebc274902009-01-07 16:37:29 +01001626 if (nr & 1)
1627 temp_max_hyst = data->temp_hyst[nr / 2] >> 4;
1628 else
1629 temp_max_hyst = data->temp_hyst[nr / 2] & 0x0f;
1630 temp_max_hyst = (data->temp_high[nr] - temp_max_hyst) * 1000;
Hans de Goedece0bfa52009-01-07 16:37:28 +01001631 mutex_unlock(&data->update_lock);
1632
1633 return sprintf(buf, "%d\n", temp_max_hyst);
Hans de Goede45fb3662007-07-13 14:34:19 +02001634}
1635
1636static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
1637 *devattr, const char *buf, size_t count)
1638{
1639 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001640 int err, nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001641 ssize_t ret = count;
Hans de Goedece0bfa52009-01-07 16:37:28 +01001642 u8 reg;
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001643 long val;
1644
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001645 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001646 if (err)
1647 return err;
1648
1649 val /= 1000;
Hans de Goede45fb3662007-07-13 14:34:19 +02001650
1651 mutex_lock(&data->update_lock);
1652
1653 /* convert abs to relative and check */
Hans de Goedece0bfa52009-01-07 16:37:28 +01001654 data->temp_high[nr] = f71882fg_read8(data, F71882FG_REG_TEMP_HIGH(nr));
Guenter Roeck2a844c12013-01-09 08:09:34 -08001655 val = clamp_val(val, data->temp_high[nr] - 15, data->temp_high[nr]);
Hans de Goede45fb3662007-07-13 14:34:19 +02001656 val = data->temp_high[nr] - val;
Hans de Goede45fb3662007-07-13 14:34:19 +02001657
1658 /* convert value to register contents */
Hans de Goedebc274902009-01-07 16:37:29 +01001659 reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST(nr / 2));
1660 if (nr & 1)
1661 reg = (reg & 0x0f) | (val << 4);
1662 else
1663 reg = (reg & 0xf0) | val;
1664 f71882fg_write8(data, F71882FG_REG_TEMP_HYST(nr / 2), reg);
1665 data->temp_hyst[nr / 2] = reg;
Hans de Goede45fb3662007-07-13 14:34:19 +02001666
Hans de Goede45fb3662007-07-13 14:34:19 +02001667 mutex_unlock(&data->update_lock);
1668 return ret;
1669}
1670
1671static ssize_t show_temp_crit(struct device *dev, struct device_attribute
1672 *devattr, char *buf)
1673{
1674 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001675 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001676
1677 return sprintf(buf, "%d\n", data->temp_ovt[nr] * 1000);
1678}
1679
1680static ssize_t store_temp_crit(struct device *dev, struct device_attribute
1681 *devattr, const char *buf, size_t count)
1682{
1683 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001684 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1685 long val;
1686
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001687 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001688 if (err)
1689 return err;
1690
1691 val /= 1000;
Guenter Roeck2a844c12013-01-09 08:09:34 -08001692 val = clamp_val(val, 0, 255);
Hans de Goede45fb3662007-07-13 14:34:19 +02001693
1694 mutex_lock(&data->update_lock);
1695 f71882fg_write8(data, F71882FG_REG_TEMP_OVT(nr), val);
1696 data->temp_ovt[nr] = val;
1697 mutex_unlock(&data->update_lock);
1698
1699 return count;
1700}
1701
1702static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
1703 *devattr, char *buf)
1704{
1705 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001706 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goedece0bfa52009-01-07 16:37:28 +01001707 int temp_crit_hyst;
Hans de Goede45fb3662007-07-13 14:34:19 +02001708
Hans de Goedece0bfa52009-01-07 16:37:28 +01001709 mutex_lock(&data->update_lock);
Hans de Goedebc274902009-01-07 16:37:29 +01001710 if (nr & 1)
1711 temp_crit_hyst = data->temp_hyst[nr / 2] >> 4;
1712 else
1713 temp_crit_hyst = data->temp_hyst[nr / 2] & 0x0f;
1714 temp_crit_hyst = (data->temp_ovt[nr] - temp_crit_hyst) * 1000;
Hans de Goedece0bfa52009-01-07 16:37:28 +01001715 mutex_unlock(&data->update_lock);
1716
1717 return sprintf(buf, "%d\n", temp_crit_hyst);
Hans de Goede45fb3662007-07-13 14:34:19 +02001718}
1719
1720static ssize_t show_temp_type(struct device *dev, struct device_attribute
1721 *devattr, char *buf)
1722{
1723 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001724 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001725
1726 return sprintf(buf, "%d\n", data->temp_type[nr]);
1727}
1728
1729static ssize_t show_temp_beep(struct device *dev, struct device_attribute
1730 *devattr, char *buf)
1731{
1732 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001733 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001734
Hans de Goede7567a042009-01-07 16:37:28 +01001735 if (data->temp_beep & (1 << nr))
Hans de Goede45fb3662007-07-13 14:34:19 +02001736 return sprintf(buf, "1\n");
1737 else
1738 return sprintf(buf, "0\n");
1739}
1740
1741static ssize_t store_temp_beep(struct device *dev, struct device_attribute
1742 *devattr, const char *buf, size_t count)
1743{
1744 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001745 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1746 unsigned long val;
1747
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001748 err = kstrtoul(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001749 if (err)
1750 return err;
Hans de Goede45fb3662007-07-13 14:34:19 +02001751
1752 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01001753 data->temp_beep = f71882fg_read8(data, F71882FG_REG_TEMP_BEEP);
Hans de Goede45fb3662007-07-13 14:34:19 +02001754 if (val)
Hans de Goede7567a042009-01-07 16:37:28 +01001755 data->temp_beep |= 1 << nr;
Hans de Goede45fb3662007-07-13 14:34:19 +02001756 else
Hans de Goede7567a042009-01-07 16:37:28 +01001757 data->temp_beep &= ~(1 << nr);
Hans de Goede45fb3662007-07-13 14:34:19 +02001758
1759 f71882fg_write8(data, F71882FG_REG_TEMP_BEEP, data->temp_beep);
1760 mutex_unlock(&data->update_lock);
1761
1762 return count;
1763}
1764
1765static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
1766 *devattr, char *buf)
1767{
1768 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001769 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001770
Hans de Goede7567a042009-01-07 16:37:28 +01001771 if (data->temp_status & (1 << nr))
Hans de Goede45fb3662007-07-13 14:34:19 +02001772 return sprintf(buf, "1\n");
1773 else
1774 return sprintf(buf, "0\n");
1775}
1776
1777static ssize_t show_temp_fault(struct device *dev, struct device_attribute
1778 *devattr, char *buf)
1779{
1780 struct f71882fg_data *data = f71882fg_update_device(dev);
Mark van Doesburgbc37ae72009-01-07 16:37:27 +01001781 int nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goede45fb3662007-07-13 14:34:19 +02001782
Hans de Goede7567a042009-01-07 16:37:28 +01001783 if (data->temp_diode_open & (1 << nr))
Hans de Goede45fb3662007-07-13 14:34:19 +02001784 return sprintf(buf, "1\n");
1785 else
1786 return sprintf(buf, "0\n");
1787}
1788
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001789static ssize_t show_pwm(struct device *dev,
1790 struct device_attribute *devattr, char *buf)
1791{
1792 struct f71882fg_data *data = f71882fg_update_device(dev);
1793 int val, nr = to_sensor_dev_attr_2(devattr)->index;
Hans de Goedece0bfa52009-01-07 16:37:28 +01001794 mutex_lock(&data->update_lock);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001795 if (data->pwm_enable & (1 << (2 * nr)))
1796 /* PWM mode */
1797 val = data->pwm[nr];
1798 else {
1799 /* RPM mode */
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001800 val = 255 * fan_from_reg(data->fan_target[nr])
1801 / fan_from_reg(data->fan_full_speed[nr]);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001802 }
Hans de Goedece0bfa52009-01-07 16:37:28 +01001803 mutex_unlock(&data->update_lock);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001804 return sprintf(buf, "%d\n", val);
1805}
1806
1807static ssize_t store_pwm(struct device *dev,
1808 struct device_attribute *devattr, const char *buf,
1809 size_t count)
1810{
Hans de Goedece0bfa52009-01-07 16:37:28 +01001811 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001812 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1813 long val;
1814
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001815 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001816 if (err)
1817 return err;
1818
Guenter Roeck2a844c12013-01-09 08:09:34 -08001819 val = clamp_val(val, 0, 255);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001820
1821 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01001822 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001823 if ((data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 3) != 2) ||
1824 (data->type != f8000 && !((data->pwm_enable >> 2 * nr) & 2))) {
1825 count = -EROFS;
1826 goto leave;
1827 }
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001828 if (data->pwm_enable & (1 << (2 * nr))) {
1829 /* PWM mode */
1830 f71882fg_write8(data, F71882FG_REG_PWM(nr), val);
1831 data->pwm[nr] = val;
1832 } else {
1833 /* RPM mode */
Hans de Goedece0bfa52009-01-07 16:37:28 +01001834 int target, full_speed;
1835 full_speed = f71882fg_read16(data,
1836 F71882FG_REG_FAN_FULL_SPEED(nr));
1837 target = fan_to_reg(val * fan_from_reg(full_speed) / 255);
1838 f71882fg_write16(data, F71882FG_REG_FAN_TARGET(nr), target);
1839 data->fan_target[nr] = target;
1840 data->fan_full_speed[nr] = full_speed;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001841 }
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001842leave:
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001843 mutex_unlock(&data->update_lock);
1844
1845 return count;
1846}
1847
Hans de Goede629c58b2011-05-25 20:43:32 +02001848static ssize_t show_simple_pwm(struct device *dev,
1849 struct device_attribute *devattr, char *buf)
1850{
1851 struct f71882fg_data *data = f71882fg_update_device(dev);
1852 int val, nr = to_sensor_dev_attr_2(devattr)->index;
1853
1854 val = data->pwm[nr];
1855 return sprintf(buf, "%d\n", val);
1856}
1857
1858static ssize_t store_simple_pwm(struct device *dev,
1859 struct device_attribute *devattr,
1860 const char *buf, size_t count)
1861{
1862 struct f71882fg_data *data = dev_get_drvdata(dev);
1863 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1864 long val;
1865
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001866 err = kstrtol(buf, 10, &val);
Hans de Goede629c58b2011-05-25 20:43:32 +02001867 if (err)
1868 return err;
1869
Guenter Roeck2a844c12013-01-09 08:09:34 -08001870 val = clamp_val(val, 0, 255);
Hans de Goede629c58b2011-05-25 20:43:32 +02001871
1872 mutex_lock(&data->update_lock);
1873 f71882fg_write8(data, F71882FG_REG_PWM(nr), val);
1874 data->pwm[nr] = val;
1875 mutex_unlock(&data->update_lock);
1876
1877 return count;
1878}
1879
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001880static ssize_t show_pwm_enable(struct device *dev,
1881 struct device_attribute *devattr, char *buf)
1882{
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001883 int result = 0;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001884 struct f71882fg_data *data = f71882fg_update_device(dev);
1885 int nr = to_sensor_dev_attr_2(devattr)->index;
1886
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001887 switch ((data->pwm_enable >> 2 * nr) & 3) {
1888 case 0:
1889 case 1:
1890 result = 2; /* Normal auto mode */
1891 break;
1892 case 2:
1893 result = 1; /* Manual mode */
1894 break;
1895 case 3:
1896 if (data->type == f8000)
1897 result = 3; /* Thermostat mode */
1898 else
1899 result = 1; /* Manual mode */
1900 break;
1901 }
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001902
1903 return sprintf(buf, "%d\n", result);
1904}
1905
1906static ssize_t store_pwm_enable(struct device *dev, struct device_attribute
1907 *devattr, const char *buf, size_t count)
1908{
1909 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001910 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1911 long val;
1912
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001913 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001914 if (err)
1915 return err;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001916
Hans de Goede3fc78382009-06-15 18:39:50 +02001917 /* Special case for F8000 pwm channel 3 which only does auto mode */
1918 if (data->type == f8000 && nr == 2 && val != 2)
1919 return -EINVAL;
1920
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001921 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01001922 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001923 /* Special case for F8000 auto PWM mode / Thermostat mode */
1924 if (data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 1)) {
1925 switch (val) {
1926 case 2:
1927 data->pwm_enable &= ~(2 << (2 * nr));
1928 break; /* Normal auto mode */
1929 case 3:
1930 data->pwm_enable |= 2 << (2 * nr);
1931 break; /* Thermostat mode */
1932 default:
1933 count = -EINVAL;
1934 goto leave;
1935 }
1936 } else {
1937 switch (val) {
1938 case 1:
Hans de Goede09475d32009-06-15 18:39:52 +02001939 /* The f71858fg does not support manual RPM mode */
1940 if (data->type == f71858fg &&
1941 ((data->pwm_enable >> (2 * nr)) & 1)) {
1942 count = -EINVAL;
1943 goto leave;
1944 }
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001945 data->pwm_enable |= 2 << (2 * nr);
1946 break; /* Manual */
1947 case 2:
1948 data->pwm_enable &= ~(2 << (2 * nr));
1949 break; /* Normal auto mode */
1950 default:
1951 count = -EINVAL;
1952 goto leave;
1953 }
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001954 }
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001955 f71882fg_write8(data, F71882FG_REG_PWM_ENABLE, data->pwm_enable);
Hans de Goedeed4f7c22009-01-07 16:37:30 +01001956leave:
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001957 mutex_unlock(&data->update_lock);
1958
1959 return count;
1960}
1961
1962static ssize_t show_pwm_auto_point_pwm(struct device *dev,
1963 struct device_attribute *devattr,
1964 char *buf)
1965{
1966 int result;
1967 struct f71882fg_data *data = f71882fg_update_device(dev);
1968 int pwm = to_sensor_dev_attr_2(devattr)->index;
1969 int point = to_sensor_dev_attr_2(devattr)->nr;
1970
Hans de Goedece0bfa52009-01-07 16:37:28 +01001971 mutex_lock(&data->update_lock);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001972 if (data->pwm_enable & (1 << (2 * pwm))) {
1973 /* PWM mode */
1974 result = data->pwm_auto_point_pwm[pwm][point];
1975 } else {
1976 /* RPM mode */
1977 result = 32 * 255 / (32 + data->pwm_auto_point_pwm[pwm][point]);
1978 }
Hans de Goedece0bfa52009-01-07 16:37:28 +01001979 mutex_unlock(&data->update_lock);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001980
1981 return sprintf(buf, "%d\n", result);
1982}
1983
1984static ssize_t store_pwm_auto_point_pwm(struct device *dev,
1985 struct device_attribute *devattr,
1986 const char *buf, size_t count)
1987{
Hans de Goedece0bfa52009-01-07 16:37:28 +01001988 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001989 int err, pwm = to_sensor_dev_attr_2(devattr)->index;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001990 int point = to_sensor_dev_attr_2(devattr)->nr;
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001991 long val;
1992
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01001993 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02001994 if (err)
1995 return err;
1996
Guenter Roeck2a844c12013-01-09 08:09:34 -08001997 val = clamp_val(val, 0, 255);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01001998
1999 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01002000 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002001 if (data->pwm_enable & (1 << (2 * pwm))) {
2002 /* PWM mode */
2003 } else {
2004 /* RPM mode */
2005 if (val < 29) /* Prevent negative numbers */
2006 val = 255;
2007 else
2008 val = (255 - val) * 32 / val;
2009 }
2010 f71882fg_write8(data, F71882FG_REG_POINT_PWM(pwm, point), val);
2011 data->pwm_auto_point_pwm[pwm][point] = val;
2012 mutex_unlock(&data->update_lock);
2013
2014 return count;
2015}
2016
2017static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
2018 struct device_attribute *devattr,
2019 char *buf)
2020{
2021 int result = 0;
2022 struct f71882fg_data *data = f71882fg_update_device(dev);
2023 int nr = to_sensor_dev_attr_2(devattr)->index;
2024 int point = to_sensor_dev_attr_2(devattr)->nr;
2025
2026 mutex_lock(&data->update_lock);
Hans de Goedebc274902009-01-07 16:37:29 +01002027 if (nr & 1)
2028 result = data->pwm_auto_point_hyst[nr / 2] >> 4;
2029 else
2030 result = data->pwm_auto_point_hyst[nr / 2] & 0x0f;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002031 result = 1000 * (data->pwm_auto_point_temp[nr][point] - result);
2032 mutex_unlock(&data->update_lock);
2033
2034 return sprintf(buf, "%d\n", result);
2035}
2036
2037static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
2038 struct device_attribute *devattr,
2039 const char *buf, size_t count)
2040{
Hans de Goedece0bfa52009-01-07 16:37:28 +01002041 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002042 int err, nr = to_sensor_dev_attr_2(devattr)->index;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002043 int point = to_sensor_dev_attr_2(devattr)->nr;
Hans de Goedebc274902009-01-07 16:37:29 +01002044 u8 reg;
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002045 long val;
2046
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01002047 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002048 if (err)
2049 return err;
2050
2051 val /= 1000;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002052
2053 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01002054 data->pwm_auto_point_temp[nr][point] =
2055 f71882fg_read8(data, F71882FG_REG_POINT_TEMP(nr, point));
Guenter Roeck2a844c12013-01-09 08:09:34 -08002056 val = clamp_val(val, data->pwm_auto_point_temp[nr][point] - 15,
2057 data->pwm_auto_point_temp[nr][point]);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002058 val = data->pwm_auto_point_temp[nr][point] - val;
2059
Hans de Goedebc274902009-01-07 16:37:29 +01002060 reg = f71882fg_read8(data, F71882FG_REG_FAN_HYST(nr / 2));
2061 if (nr & 1)
2062 reg = (reg & 0x0f) | (val << 4);
2063 else
2064 reg = (reg & 0xf0) | val;
2065
2066 f71882fg_write8(data, F71882FG_REG_FAN_HYST(nr / 2), reg);
2067 data->pwm_auto_point_hyst[nr / 2] = reg;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002068 mutex_unlock(&data->update_lock);
2069
2070 return count;
2071}
2072
2073static ssize_t show_pwm_interpolate(struct device *dev,
2074 struct device_attribute *devattr, char *buf)
2075{
2076 int result;
2077 struct f71882fg_data *data = f71882fg_update_device(dev);
2078 int nr = to_sensor_dev_attr_2(devattr)->index;
2079
2080 result = (data->pwm_auto_point_mapping[nr] >> 4) & 1;
2081
2082 return sprintf(buf, "%d\n", result);
2083}
2084
2085static ssize_t store_pwm_interpolate(struct device *dev,
2086 struct device_attribute *devattr,
2087 const char *buf, size_t count)
2088{
Hans de Goedece0bfa52009-01-07 16:37:28 +01002089 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002090 int err, nr = to_sensor_dev_attr_2(devattr)->index;
2091 unsigned long val;
2092
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01002093 err = kstrtoul(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002094 if (err)
2095 return err;
Hans de Goedece0bfa52009-01-07 16:37:28 +01002096
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002097 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01002098 data->pwm_auto_point_mapping[nr] =
2099 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002100 if (val)
2101 val = data->pwm_auto_point_mapping[nr] | (1 << 4);
2102 else
2103 val = data->pwm_auto_point_mapping[nr] & (~(1 << 4));
2104 f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val);
2105 data->pwm_auto_point_mapping[nr] = val;
2106 mutex_unlock(&data->update_lock);
2107
2108 return count;
2109}
2110
2111static ssize_t show_pwm_auto_point_channel(struct device *dev,
2112 struct device_attribute *devattr,
2113 char *buf)
2114{
2115 int result;
2116 struct f71882fg_data *data = f71882fg_update_device(dev);
2117 int nr = to_sensor_dev_attr_2(devattr)->index;
2118
Hans de Goede09475d32009-06-15 18:39:52 +02002119 result = 1 << ((data->pwm_auto_point_mapping[nr] & 3) -
2120 data->temp_start);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002121
2122 return sprintf(buf, "%d\n", result);
2123}
2124
2125static ssize_t store_pwm_auto_point_channel(struct device *dev,
2126 struct device_attribute *devattr,
2127 const char *buf, size_t count)
2128{
Hans de Goedece0bfa52009-01-07 16:37:28 +01002129 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002130 int err, nr = to_sensor_dev_attr_2(devattr)->index;
2131 long val;
2132
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01002133 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002134 if (err)
2135 return err;
Hans de Goede30453012009-01-07 16:37:30 +01002136
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002137 switch (val) {
2138 case 1:
Hans de Goede30453012009-01-07 16:37:30 +01002139 val = 0;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002140 break;
2141 case 2:
Hans de Goede30453012009-01-07 16:37:30 +01002142 val = 1;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002143 break;
2144 case 4:
Hans de Goede30453012009-01-07 16:37:30 +01002145 val = 2;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002146 break;
2147 default:
2148 return -EINVAL;
2149 }
Hans de Goede09475d32009-06-15 18:39:52 +02002150 val += data->temp_start;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002151 mutex_lock(&data->update_lock);
Hans de Goedece0bfa52009-01-07 16:37:28 +01002152 data->pwm_auto_point_mapping[nr] =
2153 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002154 val = (data->pwm_auto_point_mapping[nr] & 0xfc) | val;
2155 f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val);
2156 data->pwm_auto_point_mapping[nr] = val;
2157 mutex_unlock(&data->update_lock);
2158
2159 return count;
2160}
2161
2162static ssize_t show_pwm_auto_point_temp(struct device *dev,
2163 struct device_attribute *devattr,
2164 char *buf)
2165{
2166 int result;
2167 struct f71882fg_data *data = f71882fg_update_device(dev);
2168 int pwm = to_sensor_dev_attr_2(devattr)->index;
2169 int point = to_sensor_dev_attr_2(devattr)->nr;
2170
2171 result = data->pwm_auto_point_temp[pwm][point];
2172 return sprintf(buf, "%d\n", 1000 * result);
2173}
2174
2175static ssize_t store_pwm_auto_point_temp(struct device *dev,
2176 struct device_attribute *devattr,
2177 const char *buf, size_t count)
2178{
Hans de Goedece0bfa52009-01-07 16:37:28 +01002179 struct f71882fg_data *data = dev_get_drvdata(dev);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002180 int err, pwm = to_sensor_dev_attr_2(devattr)->index;
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002181 int point = to_sensor_dev_attr_2(devattr)->nr;
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002182 long val;
2183
Frans Meulenbroeks179c4fd2012-01-04 20:58:52 +01002184 err = kstrtol(buf, 10, &val);
Giel van Schijndele8a4eac2010-05-27 19:58:41 +02002185 if (err)
2186 return err;
2187
2188 val /= 1000;
Hans de Goede76698962009-12-09 20:36:01 +01002189
Hans de Goede98f7ba12011-03-09 20:57:09 +01002190 if (data->auto_point_temp_signed)
Guenter Roeck2a844c12013-01-09 08:09:34 -08002191 val = clamp_val(val, -128, 127);
Hans de Goede76698962009-12-09 20:36:01 +01002192 else
Guenter Roeck2a844c12013-01-09 08:09:34 -08002193 val = clamp_val(val, 0, 127);
Mark van Doesburg9ab796e2009-01-07 16:37:27 +01002194
2195 mutex_lock(&data->update_lock);
2196 f71882fg_write8(data, F71882FG_REG_POINT_TEMP(pwm, point), val);
2197 data->pwm_auto_point_temp[pwm][point] = val;
2198 mutex_unlock(&data->update_lock);
2199
2200 return count;
2201}
2202
Julia Lawallf2620e72016-12-22 13:04:39 +01002203static ssize_t name_show(struct device *dev, struct device_attribute *devattr,
Hans de Goede45fb3662007-07-13 14:34:19 +02002204 char *buf)
2205{
Hans de Goede498be962009-01-07 16:37:28 +01002206 struct f71882fg_data *data = dev_get_drvdata(dev);
2207 return sprintf(buf, "%s\n", f71882fg_names[data->type]);
Hans de Goede45fb3662007-07-13 14:34:19 +02002208}
2209
Bill Pemberton6c931ae2012-11-19 13:22:35 -05002210static int f71882fg_create_sysfs_files(struct platform_device *pdev,
Hans de Goedec13548c2009-01-07 16:37:27 +01002211 struct sensor_device_attribute_2 *attr, int count)
2212{
2213 int err, i;
Hans de Goede45fb3662007-07-13 14:34:19 +02002214
Hans de Goedec13548c2009-01-07 16:37:27 +01002215 for (i = 0; i < count; i++) {
2216 err = device_create_file(&pdev->dev, &attr[i].dev_attr);
2217 if (err)
2218 return err;
2219 }
2220 return 0;
2221}
2222
Hans de Goedefc16c562009-12-09 20:36:01 +01002223static void f71882fg_remove_sysfs_files(struct platform_device *pdev,
2224 struct sensor_device_attribute_2 *attr, int count)
2225{
2226 int i;
2227
2228 for (i = 0; i < count; i++)
2229 device_remove_file(&pdev->dev, &attr[i].dev_attr);
2230}
2231
Bill Pemberton6c931ae2012-11-19 13:22:35 -05002232static int f71882fg_create_fan_sysfs_files(
Hans de Goede65434392011-09-09 12:12:35 +02002233 struct platform_device *pdev, int idx)
Hans de Goede9af07942011-09-09 12:12:34 +02002234{
2235 struct f71882fg_data *data = platform_get_drvdata(pdev);
2236 int err;
2237
Hans de Goede65434392011-09-09 12:12:35 +02002238 /* Sanity check the pwm setting */
2239 err = 0;
2240 switch (data->type) {
2241 case f71858fg:
2242 if (((data->pwm_enable >> (idx * 2)) & 3) == 3)
2243 err = 1;
2244 break;
2245 case f71862fg:
2246 if (((data->pwm_enable >> (idx * 2)) & 1) != 1)
2247 err = 1;
2248 break;
2249 case f8000:
2250 if (idx == 2)
2251 err = data->pwm_enable & 0x20;
2252 break;
2253 default:
2254 break;
2255 }
2256 if (err) {
2257 dev_err(&pdev->dev,
2258 "Invalid (reserved) pwm settings: 0x%02x, "
2259 "skipping fan %d\n",
2260 (data->pwm_enable >> (idx * 2)) & 3, idx + 1);
2261 return 0; /* This is a non fatal condition */
2262 }
2263
Hans de Goede9af07942011-09-09 12:12:34 +02002264 err = f71882fg_create_sysfs_files(pdev, &fxxxx_fan_attr[idx][0],
2265 ARRAY_SIZE(fxxxx_fan_attr[0]));
2266 if (err)
2267 return err;
2268
2269 if (f71882fg_fan_has_beep[data->type]) {
2270 err = f71882fg_create_sysfs_files(pdev,
2271 &fxxxx_fan_beep_attr[idx],
2272 1);
2273 if (err)
2274 return err;
2275 }
2276
Hans de Goede65434392011-09-09 12:12:35 +02002277 dev_info(&pdev->dev, "Fan: %d is in %s mode\n", idx + 1,
2278 (data->pwm_enable & (1 << (2 * idx))) ? "duty-cycle" : "RPM");
2279
2280 /* Check for unsupported auto pwm settings */
2281 switch (data->type) {
2282 case f71808e:
2283 case f71808a:
2284 case f71869:
2285 case f71869a:
2286 case f71889fg:
2287 case f71889ed:
2288 case f71889a:
2289 data->pwm_auto_point_mapping[idx] =
2290 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(idx));
2291 if ((data->pwm_auto_point_mapping[idx] & 0x80) ||
2292 (data->pwm_auto_point_mapping[idx] & 3) == 0) {
2293 dev_warn(&pdev->dev,
2294 "Auto pwm controlled by raw digital "
2295 "data, disabling pwm auto_point "
2296 "sysfs attributes for fan %d\n", idx + 1);
2297 return 0; /* This is a non fatal condition */
2298 }
2299 break;
2300 default:
2301 break;
2302 }
Hans de Goede9af07942011-09-09 12:12:34 +02002303
2304 switch (data->type) {
2305 case f71862fg:
2306 err = f71882fg_create_sysfs_files(pdev,
2307 &f71862fg_auto_pwm_attr[idx][0],
2308 ARRAY_SIZE(f71862fg_auto_pwm_attr[0]));
2309 break;
2310 case f71808e:
2311 case f71869:
2312 err = f71882fg_create_sysfs_files(pdev,
2313 &f71869_auto_pwm_attr[idx][0],
2314 ARRAY_SIZE(f71869_auto_pwm_attr[0]));
2315 break;
2316 case f8000:
2317 err = f71882fg_create_sysfs_files(pdev,
2318 &f8000_auto_pwm_attr[idx][0],
2319 ARRAY_SIZE(f8000_auto_pwm_attr[0]));
2320 break;
2321 default:
2322 err = f71882fg_create_sysfs_files(pdev,
2323 &fxxxx_auto_pwm_attr[idx][0],
2324 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]));
2325 }
2326
2327 return err;
2328}
2329
Bill Pemberton6c931ae2012-11-19 13:22:35 -05002330static int f71882fg_probe(struct platform_device *pdev)
Hans de Goede45fb3662007-07-13 14:34:19 +02002331{
2332 struct f71882fg_data *data;
Jingoo Hana8b3a3a2013-07-30 17:13:06 +09002333 struct f71882fg_sio_data *sio_data = dev_get_platdata(&pdev->dev);
Jean Delvaref27def02011-03-26 10:45:01 +01002334 int nr_fans = f71882fg_nr_fans[sio_data->type];
2335 int nr_temps = f71882fg_nr_temps[sio_data->type];
2336 int err, i;
Peter Hungdcd956f2015-07-07 16:22:37 +08002337 int size;
Hans de Goede98f7ba12011-03-09 20:57:09 +01002338 u8 start_reg, reg;
Hans de Goede45fb3662007-07-13 14:34:19 +02002339
Guenter Roeck33cd66e2012-06-02 09:58:05 -07002340 data = devm_kzalloc(&pdev->dev, sizeof(struct f71882fg_data),
2341 GFP_KERNEL);
Hans de Goedec13548c2009-01-07 16:37:27 +01002342 if (!data)
Hans de Goede45fb3662007-07-13 14:34:19 +02002343 return -ENOMEM;
2344
2345 data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start;
Hans de Goede498be962009-01-07 16:37:28 +01002346 data->type = sio_data->type;
Hans de Goede09475d32009-06-15 18:39:52 +02002347 data->temp_start =
Peter Hungdcd956f2015-07-07 16:22:37 +08002348 (data->type == f71858fg || data->type == f8000 ||
2349 data->type == f81866a) ? 0 : 1;
Hans de Goede45fb3662007-07-13 14:34:19 +02002350 mutex_init(&data->update_lock);
2351 platform_set_drvdata(pdev, data);
2352
Hans de Goede3cc74752009-01-07 16:37:28 +01002353 start_reg = f71882fg_read8(data, F71882FG_REG_START);
Hans de Goede12d66e82009-01-07 16:37:29 +01002354 if (start_reg & 0x04) {
2355 dev_warn(&pdev->dev, "Hardware monitor is powered down\n");
Guenter Roeck33cd66e2012-06-02 09:58:05 -07002356 return -ENODEV;
Hans de Goede12d66e82009-01-07 16:37:29 +01002357 }
Hans de Goede3cc74752009-01-07 16:37:28 +01002358 if (!(start_reg & 0x03)) {
2359 dev_warn(&pdev->dev, "Hardware monitoring not activated\n");
Guenter Roeck33cd66e2012-06-02 09:58:05 -07002360 return -ENODEV;
Hans de Goede3cc74752009-01-07 16:37:28 +01002361 }
2362
Hans de Goede45fb3662007-07-13 14:34:19 +02002363 /* Register sysfs interface files */
Hans de Goedec13548c2009-01-07 16:37:27 +01002364 err = device_create_file(&pdev->dev, &dev_attr_name);
2365 if (err)
2366 goto exit_unregister_sysfs;
2367
Hans de Goedec13548c2009-01-07 16:37:27 +01002368 if (start_reg & 0x01) {
Hans de Goedeed4f7c22009-01-07 16:37:30 +01002369 switch (data->type) {
Hans de Goede09475d32009-06-15 18:39:52 +02002370 case f71858fg:
2371 data->temp_config =
2372 f71882fg_read8(data, F71882FG_REG_TEMP_CONFIG);
2373 if (data->temp_config & 0x10)
Guenter Roeck20eaf722012-01-19 11:02:17 -08002374 /*
2375 * The f71858fg temperature alarms behave as
2376 * the f8000 alarms in this mode
2377 */
Hans de Goede09475d32009-06-15 18:39:52 +02002378 err = f71882fg_create_sysfs_files(pdev,
Hans de Goede0bae6402011-03-09 20:57:10 +01002379 f8000_temp_attr,
2380 ARRAY_SIZE(f8000_temp_attr));
Hans de Goede09475d32009-06-15 18:39:52 +02002381 else
2382 err = f71882fg_create_sysfs_files(pdev,
Hans de Goede0bae6402011-03-09 20:57:10 +01002383 f71858fg_temp_attr,
2384 ARRAY_SIZE(f71858fg_temp_attr));
Hans de Goede09475d32009-06-15 18:39:52 +02002385 break;
Hans de Goede0bae6402011-03-09 20:57:10 +01002386 case f8000:
2387 err = f71882fg_create_sysfs_files(pdev,
2388 f8000_temp_attr,
2389 ARRAY_SIZE(f8000_temp_attr));
2390 break;
Peter Hungdcd956f2015-07-07 16:22:37 +08002391 case f81866a:
2392 err = f71882fg_create_sysfs_files(pdev,
2393 f71858fg_temp_attr,
2394 ARRAY_SIZE(f71858fg_temp_attr));
2395 break;
Hans de Goede0bae6402011-03-09 20:57:10 +01002396 default:
2397 err = f71882fg_create_sysfs_files(pdev,
Hans de Goede60d2b372011-03-09 20:57:11 +01002398 &fxxxx_temp_attr[0][0],
2399 ARRAY_SIZE(fxxxx_temp_attr[0]) * nr_temps);
Hans de Goede0bae6402011-03-09 20:57:10 +01002400 }
2401 if (err)
2402 goto exit_unregister_sysfs;
2403
Hans de Goede4d538112011-05-25 20:43:32 +02002404 if (f71882fg_temp_has_beep[data->type]) {
Peter Hungdcd956f2015-07-07 16:22:37 +08002405 if (data->type == f81866a) {
2406 size = ARRAY_SIZE(f81866_temp_beep_attr[0]);
2407 err = f71882fg_create_sysfs_files(pdev,
2408 &f81866_temp_beep_attr[0][0],
2409 size * nr_temps);
2410
2411 } else {
2412 size = ARRAY_SIZE(fxxxx_temp_beep_attr[0]);
2413 err = f71882fg_create_sysfs_files(pdev,
2414 &fxxxx_temp_beep_attr[0][0],
2415 size * nr_temps);
2416 }
Hans de Goede78aa4f72011-03-09 20:57:12 +01002417 if (err)
2418 goto exit_unregister_sysfs;
2419 }
2420
Hans de Goede0bae6402011-03-09 20:57:10 +01002421 for (i = 0; i < F71882FG_MAX_INS; i++) {
2422 if (f71882fg_has_in[data->type][i]) {
2423 err = device_create_file(&pdev->dev,
2424 &fxxxx_in_attr[i].dev_attr);
2425 if (err)
2426 goto exit_unregister_sysfs;
2427 }
2428 }
2429 if (f71882fg_has_in1_alarm[data->type]) {
Hans de Goede498be962009-01-07 16:37:28 +01002430 err = f71882fg_create_sysfs_files(pdev,
Hans de Goede66344aa2009-12-09 20:35:59 +01002431 fxxxx_in1_alarm_attr,
2432 ARRAY_SIZE(fxxxx_in1_alarm_attr));
Hans de Goede498be962009-01-07 16:37:28 +01002433 if (err)
2434 goto exit_unregister_sysfs;
2435 }
Hans de Goede45fb3662007-07-13 14:34:19 +02002436 }
2437
Hans de Goede45fb3662007-07-13 14:34:19 +02002438 if (start_reg & 0x02) {
Hans de Goede98f7ba12011-03-09 20:57:09 +01002439 switch (data->type) {
Hans de Goedee5e713c2011-03-10 08:54:02 +01002440 case f71808e:
Hans de Goede629c58b2011-05-25 20:43:32 +02002441 case f71808a:
Hans de Goedec11bb992011-03-09 20:57:15 +01002442 case f71869:
Hans de Goede5da556e2011-07-03 13:32:53 +02002443 case f71869a:
Hans de Goedee5e713c2011-03-10 08:54:02 +01002444 /* These always have signed auto point temps */
Hans de Goedec11bb992011-03-09 20:57:15 +01002445 data->auto_point_temp_signed = 1;
Gustavo A. R. Silvadf561f662020-08-23 17:36:59 -05002446 fallthrough; /* to select correct fan/pwm reg bank! */
Hans de Goede98f7ba12011-03-09 20:57:09 +01002447 case f71889fg:
Hans de Goede3cad4022011-03-09 20:57:14 +01002448 case f71889ed:
Hans de Goedea66c1082011-03-26 10:45:02 +01002449 case f71889a:
Hans de Goede98f7ba12011-03-09 20:57:09 +01002450 reg = f71882fg_read8(data, F71882FG_REG_FAN_FAULT_T);
2451 if (reg & F71882FG_FAN_NEG_TEMP_EN)
2452 data->auto_point_temp_signed = 1;
Hans de Goede3cad4022011-03-09 20:57:14 +01002453 /* Ensure banked pwm registers point to right bank */
2454 reg &= ~F71882FG_FAN_PROG_SEL;
2455 f71882fg_write8(data, F71882FG_REG_FAN_FAULT_T, reg);
Hans de Goede98f7ba12011-03-09 20:57:09 +01002456 break;
2457 default:
2458 break;
2459 }
2460
Hans de Goede996cadb2009-06-15 18:39:51 +02002461 data->pwm_enable =
2462 f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
2463
Hans de Goede9af07942011-09-09 12:12:34 +02002464 for (i = 0; i < nr_fans; i++) {
Hans de Goede65434392011-09-09 12:12:35 +02002465 err = f71882fg_create_fan_sysfs_files(pdev, i);
Hans de Goede9af07942011-09-09 12:12:34 +02002466 if (err)
2467 goto exit_unregister_sysfs;
Hans de Goede9af07942011-09-09 12:12:34 +02002468 }
2469
2470 /* Some types have 1 extra fan with limited functionality */
Hans de Goedee48a7f12011-03-09 20:57:13 +01002471 switch (data->type) {
Hans de Goede629c58b2011-05-25 20:43:32 +02002472 case f71808a:
2473 err = f71882fg_create_sysfs_files(pdev,
Hans de Goede629c58b2011-05-25 20:43:32 +02002474 f71808a_fan3_attr,
2475 ARRAY_SIZE(f71808a_fan3_attr));
2476 break;
Hans de Goedeed4f7c22009-01-07 16:37:30 +01002477 case f8000:
2478 err = f71882fg_create_sysfs_files(pdev,
2479 f8000_fan_attr,
2480 ARRAY_SIZE(f8000_fan_attr));
2481 break;
Hans de Goedee48a7f12011-03-09 20:57:13 +01002482 default:
Hans de Goede9af07942011-09-09 12:12:34 +02002483 break;
Hans de Goede498be962009-01-07 16:37:28 +01002484 }
Hans de Goedec13548c2009-01-07 16:37:27 +01002485 if (err)
2486 goto exit_unregister_sysfs;
Hans de Goede45fb3662007-07-13 14:34:19 +02002487 }
2488
Tony Jones1beeffe2007-08-20 13:46:20 -07002489 data->hwmon_dev = hwmon_device_register(&pdev->dev);
2490 if (IS_ERR(data->hwmon_dev)) {
2491 err = PTR_ERR(data->hwmon_dev);
Hans de Goedec13548c2009-01-07 16:37:27 +01002492 data->hwmon_dev = NULL;
Hans de Goede45fb3662007-07-13 14:34:19 +02002493 goto exit_unregister_sysfs;
2494 }
2495
2496 return 0;
2497
2498exit_unregister_sysfs:
Hans de Goedec13548c2009-01-07 16:37:27 +01002499 f71882fg_remove(pdev); /* Will unregister the sysfs files for us */
Hans de Goede3cc74752009-01-07 16:37:28 +01002500 return err; /* f71882fg_remove() also frees our data */
Hans de Goede45fb3662007-07-13 14:34:19 +02002501}
2502
Hans de Goedec13548c2009-01-07 16:37:27 +01002503static int f71882fg_remove(struct platform_device *pdev)
Hans de Goede45fb3662007-07-13 14:34:19 +02002504{
Hans de Goede45fb3662007-07-13 14:34:19 +02002505 struct f71882fg_data *data = platform_get_drvdata(pdev);
Jean Delvaref27def02011-03-26 10:45:01 +01002506 int nr_fans = f71882fg_nr_fans[data->type];
2507 int nr_temps = f71882fg_nr_temps[data->type];
2508 int i;
Hans de Goedefc16c562009-12-09 20:36:01 +01002509 u8 start_reg = f71882fg_read8(data, F71882FG_REG_START);
Hans de Goede45fb3662007-07-13 14:34:19 +02002510
Hans de Goedec13548c2009-01-07 16:37:27 +01002511 if (data->hwmon_dev)
2512 hwmon_device_unregister(data->hwmon_dev);
Hans de Goede45fb3662007-07-13 14:34:19 +02002513
Hans de Goedec13548c2009-01-07 16:37:27 +01002514 device_remove_file(&pdev->dev, &dev_attr_name);
Hans de Goede45fb3662007-07-13 14:34:19 +02002515
Hans de Goedefc16c562009-12-09 20:36:01 +01002516 if (start_reg & 0x01) {
2517 switch (data->type) {
2518 case f71858fg:
2519 if (data->temp_config & 0x10)
2520 f71882fg_remove_sysfs_files(pdev,
Hans de Goede0bae6402011-03-09 20:57:10 +01002521 f8000_temp_attr,
2522 ARRAY_SIZE(f8000_temp_attr));
Hans de Goedefc16c562009-12-09 20:36:01 +01002523 else
2524 f71882fg_remove_sysfs_files(pdev,
Hans de Goede0bae6402011-03-09 20:57:10 +01002525 f71858fg_temp_attr,
2526 ARRAY_SIZE(f71858fg_temp_attr));
Hans de Goedefc16c562009-12-09 20:36:01 +01002527 break;
2528 case f8000:
2529 f71882fg_remove_sysfs_files(pdev,
Hans de Goede0bae6402011-03-09 20:57:10 +01002530 f8000_temp_attr,
2531 ARRAY_SIZE(f8000_temp_attr));
Hans de Goedefc16c562009-12-09 20:36:01 +01002532 break;
Peter Hungdcd956f2015-07-07 16:22:37 +08002533 case f81866a:
2534 f71882fg_remove_sysfs_files(pdev,
2535 f71858fg_temp_attr,
2536 ARRAY_SIZE(f71858fg_temp_attr));
2537 break;
Hans de Goede0bae6402011-03-09 20:57:10 +01002538 default:
2539 f71882fg_remove_sysfs_files(pdev,
Hans de Goede60d2b372011-03-09 20:57:11 +01002540 &fxxxx_temp_attr[0][0],
2541 ARRAY_SIZE(fxxxx_temp_attr[0]) * nr_temps);
Hans de Goede0bae6402011-03-09 20:57:10 +01002542 }
Hans de Goede4d538112011-05-25 20:43:32 +02002543 if (f71882fg_temp_has_beep[data->type]) {
Peter Hungdcd956f2015-07-07 16:22:37 +08002544 if (data->type == f81866a)
2545 f71882fg_remove_sysfs_files(pdev,
2546 &f81866_temp_beep_attr[0][0],
2547 ARRAY_SIZE(f81866_temp_beep_attr[0])
2548 * nr_temps);
2549 else
2550 f71882fg_remove_sysfs_files(pdev,
2551 &fxxxx_temp_beep_attr[0][0],
2552 ARRAY_SIZE(fxxxx_temp_beep_attr[0])
2553 * nr_temps);
Hans de Goede78aa4f72011-03-09 20:57:12 +01002554 }
2555
Hans de Goede0bae6402011-03-09 20:57:10 +01002556 for (i = 0; i < F71882FG_MAX_INS; i++) {
2557 if (f71882fg_has_in[data->type][i]) {
2558 device_remove_file(&pdev->dev,
2559 &fxxxx_in_attr[i].dev_attr);
2560 }
2561 }
2562 if (f71882fg_has_in1_alarm[data->type]) {
2563 f71882fg_remove_sysfs_files(pdev,
2564 fxxxx_in1_alarm_attr,
2565 ARRAY_SIZE(fxxxx_in1_alarm_attr));
Hans de Goedefc16c562009-12-09 20:36:01 +01002566 }
2567 }
Hans de Goede498be962009-01-07 16:37:28 +01002568
Hans de Goedefc16c562009-12-09 20:36:01 +01002569 if (start_reg & 0x02) {
2570 f71882fg_remove_sysfs_files(pdev, &fxxxx_fan_attr[0][0],
2571 ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans);
Hans de Goede45fb3662007-07-13 14:34:19 +02002572
Hans de Goede4d538112011-05-25 20:43:32 +02002573 if (f71882fg_fan_has_beep[data->type]) {
Hans de Goedefc16c562009-12-09 20:36:01 +01002574 f71882fg_remove_sysfs_files(pdev,
2575 fxxxx_fan_beep_attr, nr_fans);
Hans de Goede78aa4f72011-03-09 20:57:12 +01002576 }
Hans de Goede498be962009-01-07 16:37:28 +01002577
Hans de Goedefc16c562009-12-09 20:36:01 +01002578 switch (data->type) {
Hans de Goede629c58b2011-05-25 20:43:32 +02002579 case f71808a:
2580 f71882fg_remove_sysfs_files(pdev,
2581 &fxxxx_auto_pwm_attr[0][0],
2582 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
2583 f71882fg_remove_sysfs_files(pdev,
2584 f71808a_fan3_attr,
2585 ARRAY_SIZE(f71808a_fan3_attr));
2586 break;
Hans de Goedefc16c562009-12-09 20:36:01 +01002587 case f71862fg:
2588 f71882fg_remove_sysfs_files(pdev,
Hans de Goede55840142011-09-09 12:12:33 +02002589 &f71862fg_auto_pwm_attr[0][0],
2590 ARRAY_SIZE(f71862fg_auto_pwm_attr[0]) *
2591 nr_fans);
Hans de Goedefc16c562009-12-09 20:36:01 +01002592 break;
Hans de Goedee5e713c2011-03-10 08:54:02 +01002593 case f71808e:
Hans de Goedec11bb992011-03-09 20:57:15 +01002594 case f71869:
2595 f71882fg_remove_sysfs_files(pdev,
Hans de Goede55840142011-09-09 12:12:33 +02002596 &f71869_auto_pwm_attr[0][0],
2597 ARRAY_SIZE(f71869_auto_pwm_attr[0]) * nr_fans);
Hans de Goedec11bb992011-03-09 20:57:15 +01002598 break;
Hans de Goedefc16c562009-12-09 20:36:01 +01002599 case f8000:
2600 f71882fg_remove_sysfs_files(pdev,
2601 f8000_fan_attr,
2602 ARRAY_SIZE(f8000_fan_attr));
2603 f71882fg_remove_sysfs_files(pdev,
Hans de Goede55840142011-09-09 12:12:33 +02002604 &f8000_auto_pwm_attr[0][0],
2605 ARRAY_SIZE(f8000_auto_pwm_attr[0]) * nr_fans);
Hans de Goedefc16c562009-12-09 20:36:01 +01002606 break;
Hans de Goede3cad4022011-03-09 20:57:14 +01002607 default:
Hans de Goedefc16c562009-12-09 20:36:01 +01002608 f71882fg_remove_sysfs_files(pdev,
2609 &fxxxx_auto_pwm_attr[0][0],
2610 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
2611 }
2612 }
Hans de Goede45fb3662007-07-13 14:34:19 +02002613 return 0;
2614}
2615
Guenter Roeck00383892012-08-04 09:46:36 -07002616static int __init f71882fg_find(int sioaddr, struct f71882fg_sio_data *sio_data)
Hans de Goede45fb3662007-07-13 14:34:19 +02002617{
Hans de Goede45fb3662007-07-13 14:34:19 +02002618 u16 devid;
Guenter Roeck00383892012-08-04 09:46:36 -07002619 unsigned short address;
Giel van Schijndelcadb8652010-10-03 08:09:49 -04002620 int err = superio_enter(sioaddr);
2621 if (err)
2622 return err;
Hans de Goede45fb3662007-07-13 14:34:19 +02002623
2624 devid = superio_inw(sioaddr, SIO_REG_MANID);
2625 if (devid != SIO_FINTEK_ID) {
Joe Perches22d3b412010-10-20 06:51:34 +00002626 pr_debug("Not a Fintek device\n");
Giel van Schijndelcadb8652010-10-03 08:09:49 -04002627 err = -ENODEV;
Hans de Goede45fb3662007-07-13 14:34:19 +02002628 goto exit;
2629 }
2630
Jean Delvare67b671b2007-12-06 23:13:42 +01002631 devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID);
Hans de Goede498be962009-01-07 16:37:28 +01002632 switch (devid) {
Hans de Goedee5e713c2011-03-10 08:54:02 +01002633 case SIO_F71808E_ID:
2634 sio_data->type = f71808e;
2635 break;
Hans de Goede629c58b2011-05-25 20:43:32 +02002636 case SIO_F71808A_ID:
2637 sio_data->type = f71808a;
2638 break;
Hans de Goede09475d32009-06-15 18:39:52 +02002639 case SIO_F71858_ID:
2640 sio_data->type = f71858fg;
2641 break;
Hans de Goede498be962009-01-07 16:37:28 +01002642 case SIO_F71862_ID:
2643 sio_data->type = f71862fg;
2644 break;
Peter Hung2725fe22015-07-07 16:22:36 +08002645 case SIO_F71868_ID:
2646 sio_data->type = f71868a;
2647 break;
Hans de Goedec11bb992011-03-09 20:57:15 +01002648 case SIO_F71869_ID:
2649 sio_data->type = f71869;
2650 break;
Hans de Goede5da556e2011-07-03 13:32:53 +02002651 case SIO_F71869A_ID:
2652 sio_data->type = f71869a;
2653 break;
Hans de Goede498be962009-01-07 16:37:28 +01002654 case SIO_F71882_ID:
2655 sio_data->type = f71882fg;
2656 break;
Hans de Goede76698962009-12-09 20:36:01 +01002657 case SIO_F71889_ID:
2658 sio_data->type = f71889fg;
2659 break;
Hans de Goede3cad4022011-03-09 20:57:14 +01002660 case SIO_F71889E_ID:
2661 sio_data->type = f71889ed;
2662 break;
Hans de Goedea66c1082011-03-26 10:45:02 +01002663 case SIO_F71889A_ID:
2664 sio_data->type = f71889a;
2665 break;
Hans de Goedeed4f7c22009-01-07 16:37:30 +01002666 case SIO_F8000_ID:
2667 sio_data->type = f8000;
2668 break;
George Josephd8363bb2015-07-07 19:16:53 -06002669 case SIO_F81768D_ID:
2670 sio_data->type = f81768d;
2671 break;
Jean Delvare383586b2011-03-26 10:45:02 +01002672 case SIO_F81865_ID:
2673 sio_data->type = f81865f;
2674 break;
Peter Hung2725fe22015-07-07 16:22:36 +08002675 case SIO_F81866_ID:
Menghui Wudf293072021-11-17 10:43:20 +08002676 case SIO_F81966_ID:
Peter Hung2725fe22015-07-07 16:22:36 +08002677 sio_data->type = f81866a;
2678 break;
Hans de Goede498be962009-01-07 16:37:28 +01002679 default:
Joe Perches22d3b412010-10-20 06:51:34 +00002680 pr_info("Unsupported Fintek device: %04x\n",
2681 (unsigned int)devid);
Giel van Schijndelcadb8652010-10-03 08:09:49 -04002682 err = -ENODEV;
Hans de Goede45fb3662007-07-13 14:34:19 +02002683 goto exit;
2684 }
2685
Hans de Goede09475d32009-06-15 18:39:52 +02002686 if (sio_data->type == f71858fg)
2687 superio_select(sioaddr, SIO_F71858FG_LD_HWM);
2688 else
2689 superio_select(sioaddr, SIO_F71882FG_LD_HWM);
2690
Mark M. Hoffman8afb1042007-08-21 23:10:46 -04002691 if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) {
Joe Perches22d3b412010-10-20 06:51:34 +00002692 pr_warn("Device not activated\n");
Giel van Schijndelcadb8652010-10-03 08:09:49 -04002693 err = -ENODEV;
Hans de Goede45fb3662007-07-13 14:34:19 +02002694 goto exit;
2695 }
2696
Guenter Roeck00383892012-08-04 09:46:36 -07002697 address = superio_inw(sioaddr, SIO_REG_ADDR);
2698 if (address == 0) {
Joe Perches22d3b412010-10-20 06:51:34 +00002699 pr_warn("Base address not set\n");
Giel van Schijndelcadb8652010-10-03 08:09:49 -04002700 err = -ENODEV;
Hans de Goede45fb3662007-07-13 14:34:19 +02002701 goto exit;
2702 }
Guenter Roeck00383892012-08-04 09:46:36 -07002703 address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */
Hans de Goede45fb3662007-07-13 14:34:19 +02002704
Guenter Roeck00383892012-08-04 09:46:36 -07002705 err = address;
Joe Perches22d3b412010-10-20 06:51:34 +00002706 pr_info("Found %s chip at %#x, revision %d\n",
Guenter Roeck00383892012-08-04 09:46:36 -07002707 f71882fg_names[sio_data->type], (unsigned int)address,
Hans de Goede45fb3662007-07-13 14:34:19 +02002708 (int)superio_inb(sioaddr, SIO_REG_DEVREV));
2709exit:
2710 superio_exit(sioaddr);
2711 return err;
2712}
2713
Guenter Roeck00383892012-08-04 09:46:36 -07002714static int __init f71882fg_device_add(int address,
2715 const struct f71882fg_sio_data *sio_data)
Hans de Goede45fb3662007-07-13 14:34:19 +02002716{
2717 struct resource res = {
2718 .start = address,
2719 .end = address + REGION_LENGTH - 1,
2720 .flags = IORESOURCE_IO,
2721 };
2722 int err;
2723
2724 f71882fg_pdev = platform_device_alloc(DRVNAME, address);
Mark M. Hoffman8afb1042007-08-21 23:10:46 -04002725 if (!f71882fg_pdev)
Hans de Goede45fb3662007-07-13 14:34:19 +02002726 return -ENOMEM;
2727
2728 res.name = f71882fg_pdev->name;
Jean Delvareb9acb642009-01-07 16:37:35 +01002729 err = acpi_check_resource_conflict(&res);
2730 if (err)
Hans de Goede18632f82009-02-17 19:59:54 +01002731 goto exit_device_put;
Jean Delvareb9acb642009-01-07 16:37:35 +01002732
Hans de Goede45fb3662007-07-13 14:34:19 +02002733 err = platform_device_add_resources(f71882fg_pdev, &res, 1);
Mark M. Hoffman8afb1042007-08-21 23:10:46 -04002734 if (err) {
Joe Perches22d3b412010-10-20 06:51:34 +00002735 pr_err("Device resource addition failed\n");
Hans de Goede45fb3662007-07-13 14:34:19 +02002736 goto exit_device_put;
2737 }
2738
Hans de Goede498be962009-01-07 16:37:28 +01002739 err = platform_device_add_data(f71882fg_pdev, sio_data,
2740 sizeof(struct f71882fg_sio_data));
2741 if (err) {
Joe Perches22d3b412010-10-20 06:51:34 +00002742 pr_err("Platform data allocation failed\n");
Hans de Goede498be962009-01-07 16:37:28 +01002743 goto exit_device_put;
2744 }
2745
Hans de Goede45fb3662007-07-13 14:34:19 +02002746 err = platform_device_add(f71882fg_pdev);
Mark M. Hoffman8afb1042007-08-21 23:10:46 -04002747 if (err) {
Joe Perches22d3b412010-10-20 06:51:34 +00002748 pr_err("Device addition failed\n");
Hans de Goede45fb3662007-07-13 14:34:19 +02002749 goto exit_device_put;
2750 }
2751
2752 return 0;
2753
2754exit_device_put:
2755 platform_device_put(f71882fg_pdev);
2756
2757 return err;
2758}
2759
2760static int __init f71882fg_init(void)
2761{
Guenter Roeck00383892012-08-04 09:46:36 -07002762 int err;
2763 int address;
Hans de Goede498be962009-01-07 16:37:28 +01002764 struct f71882fg_sio_data sio_data;
Hans de Goede45fb3662007-07-13 14:34:19 +02002765
Hans de Goede498be962009-01-07 16:37:28 +01002766 memset(&sio_data, 0, sizeof(sio_data));
2767
Guenter Roeck00383892012-08-04 09:46:36 -07002768 address = f71882fg_find(0x2e, &sio_data);
2769 if (address < 0)
2770 address = f71882fg_find(0x4e, &sio_data);
2771 if (address < 0)
2772 return address;
Hans de Goede45fb3662007-07-13 14:34:19 +02002773
Hans de Goedec13548c2009-01-07 16:37:27 +01002774 err = platform_driver_register(&f71882fg_driver);
2775 if (err)
Guenter Roeck00383892012-08-04 09:46:36 -07002776 return err;
Hans de Goede45fb3662007-07-13 14:34:19 +02002777
Hans de Goede498be962009-01-07 16:37:28 +01002778 err = f71882fg_device_add(address, &sio_data);
Hans de Goedec13548c2009-01-07 16:37:27 +01002779 if (err)
Hans de Goede45fb3662007-07-13 14:34:19 +02002780 goto exit_driver;
2781
2782 return 0;
2783
2784exit_driver:
2785 platform_driver_unregister(&f71882fg_driver);
Hans de Goede45fb3662007-07-13 14:34:19 +02002786 return err;
2787}
2788
2789static void __exit f71882fg_exit(void)
2790{
2791 platform_device_unregister(f71882fg_pdev);
2792 platform_driver_unregister(&f71882fg_driver);
2793}
2794
2795MODULE_DESCRIPTION("F71882FG Hardware Monitoring Driver");
Hans de Goede7958e3b2011-07-03 13:32:53 +02002796MODULE_AUTHOR("Hans Edgington, Hans de Goede <hdegoede@redhat.com>");
Hans de Goede45fb3662007-07-13 14:34:19 +02002797MODULE_LICENSE("GPL");
2798
2799module_init(f71882fg_init);
2800module_exit(f71882fg_exit);