1 /***************************************************************************
2 * Copyright (C) 2006 by Hans Edgington <hans@edgington.nl> *
3 * Copyright (C) 2007-2011 Hans de Goede <hdegoede@redhat.com> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/slab.h>
26 #include <linux/jiffies.h>
27 #include <linux/platform_device.h>
28 #include <linux/hwmon.h>
29 #include <linux/hwmon-sysfs.h>
30 #include <linux/err.h>
31 #include <linux/mutex.h>
33 #include <linux/acpi.h>
35 #define DRVNAME "f71882fg"
37 #define SIO_F71858FG_LD_HWM 0x02 /* Hardware monitor logical device */
38 #define SIO_F71882FG_LD_HWM 0x04 /* Hardware monitor logical device */
39 #define SIO_UNLOCK_KEY 0x87 /* Key to enable Super-I/O */
40 #define SIO_LOCK_KEY 0xAA /* Key to disable Super-I/O */
42 #define SIO_REG_LDSEL 0x07 /* Logical device select */
43 #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */
44 #define SIO_REG_DEVREV 0x22 /* Device revision */
45 #define SIO_REG_MANID 0x23 /* Fintek ID (2 bytes) */
46 #define SIO_REG_ENABLE 0x30 /* Logical device enable */
47 #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
49 #define SIO_FINTEK_ID 0x1934 /* Manufacturers ID */
50 #define SIO_F71858_ID 0x0507 /* Chipset ID */
51 #define SIO_F71862_ID 0x0601 /* Chipset ID */
52 #define SIO_F71882_ID 0x0541 /* Chipset ID */
53 #define SIO_F71889_ID 0x0723 /* Chipset ID */
54 #define SIO_F8000_ID 0x0581 /* Chipset ID */
56 #define REGION_LENGTH 8
57 #define ADDR_REG_OFFSET 5
58 #define DATA_REG_OFFSET 6
60 #define F71882FG_REG_IN_STATUS 0x12 /* f71882fg only */
61 #define F71882FG_REG_IN_BEEP 0x13 /* f71882fg only */
62 #define F71882FG_REG_IN(nr) (0x20 + (nr))
63 #define F71882FG_REG_IN1_HIGH 0x32 /* f71882fg only */
65 #define F71882FG_REG_FAN(nr) (0xA0 + (16 * (nr)))
66 #define F71882FG_REG_FAN_TARGET(nr) (0xA2 + (16 * (nr)))
67 #define F71882FG_REG_FAN_FULL_SPEED(nr) (0xA4 + (16 * (nr)))
68 #define F71882FG_REG_FAN_STATUS 0x92
69 #define F71882FG_REG_FAN_BEEP 0x93
71 #define F71882FG_REG_TEMP(nr) (0x70 + 2 * (nr))
72 #define F71882FG_REG_TEMP_OVT(nr) (0x80 + 2 * (nr))
73 #define F71882FG_REG_TEMP_HIGH(nr) (0x81 + 2 * (nr))
74 #define F71882FG_REG_TEMP_STATUS 0x62
75 #define F71882FG_REG_TEMP_BEEP 0x63
76 #define F71882FG_REG_TEMP_CONFIG 0x69
77 #define F71882FG_REG_TEMP_HYST(nr) (0x6C + (nr))
78 #define F71882FG_REG_TEMP_TYPE 0x6B
79 #define F71882FG_REG_TEMP_DIODE_OPEN 0x6F
81 #define F71882FG_REG_PWM(nr) (0xA3 + (16 * (nr)))
82 #define F71882FG_REG_PWM_TYPE 0x94
83 #define F71882FG_REG_PWM_ENABLE 0x96
85 #define F71882FG_REG_FAN_HYST(nr) (0x98 + (nr))
87 #define F71882FG_REG_FAN_FAULT_T 0x9F
88 #define F71882FG_FAN_NEG_TEMP_EN 0x20
90 #define F71882FG_REG_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm)))
91 #define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm)))
92 #define F71882FG_REG_POINT_MAPPING(nr) (0xAF + 16 * (nr))
94 #define F71882FG_REG_START 0x01
96 #define FAN_MIN_DETECT 366 /* Lowest detectable fanspeed */
98 static unsigned short force_id;
99 module_param(force_id, ushort, 0);
100 MODULE_PARM_DESC(force_id, "Override the detected device ID");
102 enum chips { f71858fg, f71862fg, f71882fg, f71889fg, f8000 };
104 static const char *f71882fg_names[] = {
112 static struct platform_device *f71882fg_pdev;
114 /* Super-I/O Function prototypes */
115 static inline int superio_inb(int base, int reg);
116 static inline int superio_inw(int base, int reg);
117 static inline int superio_enter(int base);
118 static inline void superio_select(int base, int ld);
119 static inline void superio_exit(int base);
121 struct f71882fg_sio_data {
125 struct f71882fg_data {
128 struct device *hwmon_dev;
130 struct mutex update_lock;
131 int temp_start; /* temp numbering start (0 or 1) */
132 char valid; /* !=0 if following fields are valid */
133 char auto_point_temp_signed;
134 unsigned long last_updated; /* In jiffies */
135 unsigned long last_limits; /* In jiffies */
137 /* Register Values */
144 u16 fan_full_speed[4];
147 /* Note: all models have only 3 temperature channels, but on some
148 they are addressed as 0-2 and on others as 1-3, so for coding
149 convenience we reserve space for 4 channels */
153 u8 temp_hyst[2]; /* 2 hysts stored per reg */
161 u8 pwm_auto_point_hyst[2];
162 u8 pwm_auto_point_mapping[4];
163 u8 pwm_auto_point_pwm[4][5];
164 s8 pwm_auto_point_temp[4][4];
168 static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
170 static ssize_t show_in_max(struct device *dev, struct device_attribute
171 *devattr, char *buf);
172 static ssize_t store_in_max(struct device *dev, struct device_attribute
173 *devattr, const char *buf, size_t count);
174 static ssize_t show_in_beep(struct device *dev, struct device_attribute
175 *devattr, char *buf);
176 static ssize_t store_in_beep(struct device *dev, struct device_attribute
177 *devattr, const char *buf, size_t count);
178 static ssize_t show_in_alarm(struct device *dev, struct device_attribute
179 *devattr, char *buf);
181 static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
183 static ssize_t show_fan_full_speed(struct device *dev,
184 struct device_attribute *devattr, char *buf);
185 static ssize_t store_fan_full_speed(struct device *dev,
186 struct device_attribute *devattr, const char *buf, size_t count);
187 static ssize_t show_fan_beep(struct device *dev, struct device_attribute
188 *devattr, char *buf);
189 static ssize_t store_fan_beep(struct device *dev, struct device_attribute
190 *devattr, const char *buf, size_t count);
191 static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
192 *devattr, char *buf);
194 static ssize_t show_temp(struct device *dev, struct device_attribute
195 *devattr, char *buf);
196 static ssize_t show_temp_max(struct device *dev, struct device_attribute
197 *devattr, char *buf);
198 static ssize_t store_temp_max(struct device *dev, struct device_attribute
199 *devattr, const char *buf, size_t count);
200 static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
201 *devattr, char *buf);
202 static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
203 *devattr, const char *buf, size_t count);
204 static ssize_t show_temp_crit(struct device *dev, struct device_attribute
205 *devattr, char *buf);
206 static ssize_t store_temp_crit(struct device *dev, struct device_attribute
207 *devattr, const char *buf, size_t count);
208 static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
209 *devattr, char *buf);
210 static ssize_t show_temp_type(struct device *dev, struct device_attribute
211 *devattr, char *buf);
212 static ssize_t show_temp_beep(struct device *dev, struct device_attribute
213 *devattr, char *buf);
214 static ssize_t store_temp_beep(struct device *dev, struct device_attribute
215 *devattr, const char *buf, size_t count);
216 static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
217 *devattr, char *buf);
218 static ssize_t show_temp_fault(struct device *dev, struct device_attribute
219 *devattr, char *buf);
220 /* PWM and Auto point control */
221 static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
223 static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr,
224 const char *buf, size_t count);
225 static ssize_t show_pwm_enable(struct device *dev,
226 struct device_attribute *devattr, char *buf);
227 static ssize_t store_pwm_enable(struct device *dev,
228 struct device_attribute *devattr, const char *buf, size_t count);
229 static ssize_t show_pwm_interpolate(struct device *dev,
230 struct device_attribute *devattr, char *buf);
231 static ssize_t store_pwm_interpolate(struct device *dev,
232 struct device_attribute *devattr, const char *buf, size_t count);
233 static ssize_t show_pwm_auto_point_channel(struct device *dev,
234 struct device_attribute *devattr, char *buf);
235 static ssize_t store_pwm_auto_point_channel(struct device *dev,
236 struct device_attribute *devattr, const char *buf, size_t count);
237 static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
238 struct device_attribute *devattr, char *buf);
239 static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
240 struct device_attribute *devattr, const char *buf, size_t count);
241 static ssize_t show_pwm_auto_point_pwm(struct device *dev,
242 struct device_attribute *devattr, char *buf);
243 static ssize_t store_pwm_auto_point_pwm(struct device *dev,
244 struct device_attribute *devattr, const char *buf, size_t count);
245 static ssize_t show_pwm_auto_point_temp(struct device *dev,
246 struct device_attribute *devattr, char *buf);
247 static ssize_t store_pwm_auto_point_temp(struct device *dev,
248 struct device_attribute *devattr, const char *buf, size_t count);
250 static ssize_t show_name(struct device *dev, struct device_attribute *devattr,
253 static int __devinit f71882fg_probe(struct platform_device * pdev);
254 static int f71882fg_remove(struct platform_device *pdev);
256 static struct platform_driver f71882fg_driver = {
258 .owner = THIS_MODULE,
261 .probe = f71882fg_probe,
262 .remove = f71882fg_remove,
265 static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
267 /* Temp and in attr for the f71858fg, the f71858fg is special as it
268 has its temperature indexes start at 0 (the others start at 1) and
269 it only has 3 voltage inputs */
270 static struct sensor_device_attribute_2 f71858fg_in_temp_attr[] = {
271 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
272 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
273 SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2),
274 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
275 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
276 store_temp_max, 0, 0),
277 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
278 store_temp_max_hyst, 0, 0),
279 SENSOR_ATTR_2(temp1_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 0),
280 SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
281 store_temp_crit, 0, 0),
282 SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
284 SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4),
285 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0),
286 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1),
287 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max,
288 store_temp_max, 0, 1),
289 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
290 store_temp_max_hyst, 0, 1),
291 SENSOR_ATTR_2(temp2_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
292 SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
293 store_temp_crit, 0, 1),
294 SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
296 SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
297 SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 1),
298 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
299 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2),
300 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
301 store_temp_max, 0, 2),
302 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
303 store_temp_max_hyst, 0, 2),
304 SENSOR_ATTR_2(temp3_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
305 SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit,
306 store_temp_crit, 0, 2),
307 SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
309 SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
310 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
313 /* Temp and in attr common to the f71862fg, f71882fg and f71889fg */
314 static struct sensor_device_attribute_2 fxxxx_in_temp_attr[] = {
315 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
316 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
317 SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2),
318 SENSOR_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 0, 3),
319 SENSOR_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 0, 4),
320 SENSOR_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 0, 5),
321 SENSOR_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 0, 6),
322 SENSOR_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 0, 7),
323 SENSOR_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 0, 8),
324 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 1),
325 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
326 store_temp_max, 0, 1),
327 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
328 store_temp_max_hyst, 0, 1),
329 /* Should really be temp1_max_alarm, but older versions did not handle
330 the max and crit alarms separately and lm_sensors v2 depends on the
331 presence of temp#_alarm files. The same goes for temp2/3 _alarm. */
332 SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
333 SENSOR_ATTR_2(temp1_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
334 store_temp_beep, 0, 1),
335 SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
336 store_temp_crit, 0, 1),
337 SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
339 SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
340 SENSOR_ATTR_2(temp1_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
341 store_temp_beep, 0, 5),
342 SENSOR_ATTR_2(temp1_type, S_IRUGO, show_temp_type, NULL, 0, 1),
343 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
344 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 2),
345 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max,
346 store_temp_max, 0, 2),
347 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
348 store_temp_max_hyst, 0, 2),
349 /* Should be temp2_max_alarm, see temp1_alarm note */
350 SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
351 SENSOR_ATTR_2(temp2_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
352 store_temp_beep, 0, 2),
353 SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
354 store_temp_crit, 0, 2),
355 SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
357 SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
358 SENSOR_ATTR_2(temp2_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
359 store_temp_beep, 0, 6),
360 SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 2),
361 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
362 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 3),
363 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
364 store_temp_max, 0, 3),
365 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
366 store_temp_max_hyst, 0, 3),
367 /* Should be temp3_max_alarm, see temp1_alarm note */
368 SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 3),
369 SENSOR_ATTR_2(temp3_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
370 store_temp_beep, 0, 3),
371 SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit,
372 store_temp_crit, 0, 3),
373 SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
375 SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 7),
376 SENSOR_ATTR_2(temp3_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
377 store_temp_beep, 0, 7),
378 SENSOR_ATTR_2(temp3_type, S_IRUGO, show_temp_type, NULL, 0, 3),
379 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 3),
382 /* For models with in1 alarm capability */
383 static struct sensor_device_attribute_2 fxxxx_in1_alarm_attr[] = {
384 SENSOR_ATTR_2(in1_max, S_IRUGO|S_IWUSR, show_in_max, store_in_max,
386 SENSOR_ATTR_2(in1_beep, S_IRUGO|S_IWUSR, show_in_beep, store_in_beep,
388 SENSOR_ATTR_2(in1_alarm, S_IRUGO, show_in_alarm, NULL, 0, 1),
391 /* Temp and in attr for the f8000
392 Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max)
393 is used as hysteresis value to clear alarms
394 Also like the f71858fg its temperature indexes start at 0
396 static struct sensor_device_attribute_2 f8000_in_temp_attr[] = {
397 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
398 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
399 SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2),
400 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
401 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_crit,
402 store_temp_crit, 0, 0),
403 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
404 store_temp_max, 0, 0),
405 SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4),
406 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0),
407 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1),
408 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_crit,
409 store_temp_crit, 0, 1),
410 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
411 store_temp_max, 0, 1),
412 SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
413 SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 1),
414 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
415 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2),
416 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_crit,
417 store_temp_crit, 0, 2),
418 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
419 store_temp_max, 0, 2),
420 SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
421 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
424 /* Fan / PWM attr common to all models */
425 static struct sensor_device_attribute_2 fxxxx_fan_attr[4][6] = { {
426 SENSOR_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0),
427 SENSOR_ATTR_2(fan1_full_speed, S_IRUGO|S_IWUSR,
429 store_fan_full_speed, 0, 0),
430 SENSOR_ATTR_2(fan1_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 0),
431 SENSOR_ATTR_2(pwm1, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 0),
432 SENSOR_ATTR_2(pwm1_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
433 store_pwm_enable, 0, 0),
434 SENSOR_ATTR_2(pwm1_interpolate, S_IRUGO|S_IWUSR,
435 show_pwm_interpolate, store_pwm_interpolate, 0, 0),
437 SENSOR_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 0, 1),
438 SENSOR_ATTR_2(fan2_full_speed, S_IRUGO|S_IWUSR,
440 store_fan_full_speed, 0, 1),
441 SENSOR_ATTR_2(fan2_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 1),
442 SENSOR_ATTR_2(pwm2, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 1),
443 SENSOR_ATTR_2(pwm2_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
444 store_pwm_enable, 0, 1),
445 SENSOR_ATTR_2(pwm2_interpolate, S_IRUGO|S_IWUSR,
446 show_pwm_interpolate, store_pwm_interpolate, 0, 1),
448 SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
449 SENSOR_ATTR_2(fan3_full_speed, S_IRUGO|S_IWUSR,
451 store_fan_full_speed, 0, 2),
452 SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
453 SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 2),
454 SENSOR_ATTR_2(pwm3_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
455 store_pwm_enable, 0, 2),
456 SENSOR_ATTR_2(pwm3_interpolate, S_IRUGO|S_IWUSR,
457 show_pwm_interpolate, store_pwm_interpolate, 0, 2),
459 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
460 SENSOR_ATTR_2(fan4_full_speed, S_IRUGO|S_IWUSR,
462 store_fan_full_speed, 0, 3),
463 SENSOR_ATTR_2(fan4_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 3),
464 SENSOR_ATTR_2(pwm4, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 3),
465 SENSOR_ATTR_2(pwm4_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
466 store_pwm_enable, 0, 3),
467 SENSOR_ATTR_2(pwm4_interpolate, S_IRUGO|S_IWUSR,
468 show_pwm_interpolate, store_pwm_interpolate, 0, 3),
471 /* Attr for models which can beep on Fan alarm */
472 static struct sensor_device_attribute_2 fxxxx_fan_beep_attr[] = {
473 SENSOR_ATTR_2(fan1_beep, S_IRUGO|S_IWUSR, show_fan_beep,
474 store_fan_beep, 0, 0),
475 SENSOR_ATTR_2(fan2_beep, S_IRUGO|S_IWUSR, show_fan_beep,
476 store_fan_beep, 0, 1),
477 SENSOR_ATTR_2(fan3_beep, S_IRUGO|S_IWUSR, show_fan_beep,
478 store_fan_beep, 0, 2),
479 SENSOR_ATTR_2(fan4_beep, S_IRUGO|S_IWUSR, show_fan_beep,
480 store_fan_beep, 0, 3),
483 /* PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
484 f71858fg / f71882fg / f71889fg */
485 static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr[] = {
486 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
487 show_pwm_auto_point_channel,
488 store_pwm_auto_point_channel, 0, 0),
489 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
490 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
492 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
493 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
495 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
496 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
498 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
499 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
501 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
502 show_pwm_auto_point_temp_hyst,
503 store_pwm_auto_point_temp_hyst,
505 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
506 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
508 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
509 show_pwm_auto_point_channel,
510 store_pwm_auto_point_channel, 0, 1),
511 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
512 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
514 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
515 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
517 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
518 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
520 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
521 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
523 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
524 show_pwm_auto_point_temp_hyst,
525 store_pwm_auto_point_temp_hyst,
527 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
528 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
530 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
531 show_pwm_auto_point_channel,
532 store_pwm_auto_point_channel, 0, 2),
533 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
534 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
536 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
537 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
539 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
540 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
542 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
543 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
545 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
546 show_pwm_auto_point_temp_hyst,
547 store_pwm_auto_point_temp_hyst,
549 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
550 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
553 /* PWM attr common to the f71858fg, f71882fg and f71889fg */
554 static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr[4][14] = { {
555 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
556 show_pwm_auto_point_channel,
557 store_pwm_auto_point_channel, 0, 0),
558 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
559 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
561 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
562 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
564 SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO|S_IWUSR,
565 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
567 SENSOR_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO|S_IWUSR,
568 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
570 SENSOR_ATTR_2(pwm1_auto_point5_pwm, S_IRUGO|S_IWUSR,
571 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
573 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
574 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
576 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
577 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
579 SENSOR_ATTR_2(pwm1_auto_point3_temp, S_IRUGO|S_IWUSR,
580 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
582 SENSOR_ATTR_2(pwm1_auto_point4_temp, S_IRUGO|S_IWUSR,
583 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
585 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
586 show_pwm_auto_point_temp_hyst,
587 store_pwm_auto_point_temp_hyst,
589 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
590 show_pwm_auto_point_temp_hyst, NULL, 1, 0),
591 SENSOR_ATTR_2(pwm1_auto_point3_temp_hyst, S_IRUGO,
592 show_pwm_auto_point_temp_hyst, NULL, 2, 0),
593 SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst, S_IRUGO,
594 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
596 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
597 show_pwm_auto_point_channel,
598 store_pwm_auto_point_channel, 0, 1),
599 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
600 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
602 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
603 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
605 SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO|S_IWUSR,
606 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
608 SENSOR_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO|S_IWUSR,
609 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
611 SENSOR_ATTR_2(pwm2_auto_point5_pwm, S_IRUGO|S_IWUSR,
612 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
614 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
615 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
617 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
618 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
620 SENSOR_ATTR_2(pwm2_auto_point3_temp, S_IRUGO|S_IWUSR,
621 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
623 SENSOR_ATTR_2(pwm2_auto_point4_temp, S_IRUGO|S_IWUSR,
624 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
626 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
627 show_pwm_auto_point_temp_hyst,
628 store_pwm_auto_point_temp_hyst,
630 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
631 show_pwm_auto_point_temp_hyst, NULL, 1, 1),
632 SENSOR_ATTR_2(pwm2_auto_point3_temp_hyst, S_IRUGO,
633 show_pwm_auto_point_temp_hyst, NULL, 2, 1),
634 SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst, S_IRUGO,
635 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
637 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
638 show_pwm_auto_point_channel,
639 store_pwm_auto_point_channel, 0, 2),
640 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
641 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
643 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
644 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
646 SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO|S_IWUSR,
647 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
649 SENSOR_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO|S_IWUSR,
650 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
652 SENSOR_ATTR_2(pwm3_auto_point5_pwm, S_IRUGO|S_IWUSR,
653 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
655 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
656 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
658 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
659 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
661 SENSOR_ATTR_2(pwm3_auto_point3_temp, S_IRUGO|S_IWUSR,
662 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
664 SENSOR_ATTR_2(pwm3_auto_point4_temp, S_IRUGO|S_IWUSR,
665 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
667 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
668 show_pwm_auto_point_temp_hyst,
669 store_pwm_auto_point_temp_hyst,
671 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
672 show_pwm_auto_point_temp_hyst, NULL, 1, 2),
673 SENSOR_ATTR_2(pwm3_auto_point3_temp_hyst, S_IRUGO,
674 show_pwm_auto_point_temp_hyst, NULL, 2, 2),
675 SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst, S_IRUGO,
676 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
678 SENSOR_ATTR_2(pwm4_auto_channels_temp, S_IRUGO|S_IWUSR,
679 show_pwm_auto_point_channel,
680 store_pwm_auto_point_channel, 0, 3),
681 SENSOR_ATTR_2(pwm4_auto_point1_pwm, S_IRUGO|S_IWUSR,
682 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
684 SENSOR_ATTR_2(pwm4_auto_point2_pwm, S_IRUGO|S_IWUSR,
685 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
687 SENSOR_ATTR_2(pwm4_auto_point3_pwm, S_IRUGO|S_IWUSR,
688 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
690 SENSOR_ATTR_2(pwm4_auto_point4_pwm, S_IRUGO|S_IWUSR,
691 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
693 SENSOR_ATTR_2(pwm4_auto_point5_pwm, S_IRUGO|S_IWUSR,
694 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
696 SENSOR_ATTR_2(pwm4_auto_point1_temp, S_IRUGO|S_IWUSR,
697 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
699 SENSOR_ATTR_2(pwm4_auto_point2_temp, S_IRUGO|S_IWUSR,
700 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
702 SENSOR_ATTR_2(pwm4_auto_point3_temp, S_IRUGO|S_IWUSR,
703 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
705 SENSOR_ATTR_2(pwm4_auto_point4_temp, S_IRUGO|S_IWUSR,
706 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
708 SENSOR_ATTR_2(pwm4_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
709 show_pwm_auto_point_temp_hyst,
710 store_pwm_auto_point_temp_hyst,
712 SENSOR_ATTR_2(pwm4_auto_point2_temp_hyst, S_IRUGO,
713 show_pwm_auto_point_temp_hyst, NULL, 1, 3),
714 SENSOR_ATTR_2(pwm4_auto_point3_temp_hyst, S_IRUGO,
715 show_pwm_auto_point_temp_hyst, NULL, 2, 3),
716 SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst, S_IRUGO,
717 show_pwm_auto_point_temp_hyst, NULL, 3, 3),
720 /* Fan attr specific to the f8000 (4th fan input can only measure speed) */
721 static struct sensor_device_attribute_2 f8000_fan_attr[] = {
722 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
725 /* PWM attr for the f8000, zones mapped to temp instead of to pwm!
726 Also the register block at offset A0 maps to TEMP1 (so our temp2, as the
727 F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0 */
728 static struct sensor_device_attribute_2 f8000_auto_pwm_attr[] = {
729 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
730 show_pwm_auto_point_channel,
731 store_pwm_auto_point_channel, 0, 0),
732 SENSOR_ATTR_2(temp1_auto_point1_pwm, S_IRUGO|S_IWUSR,
733 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
735 SENSOR_ATTR_2(temp1_auto_point2_pwm, S_IRUGO|S_IWUSR,
736 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
738 SENSOR_ATTR_2(temp1_auto_point3_pwm, S_IRUGO|S_IWUSR,
739 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
741 SENSOR_ATTR_2(temp1_auto_point4_pwm, S_IRUGO|S_IWUSR,
742 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
744 SENSOR_ATTR_2(temp1_auto_point5_pwm, S_IRUGO|S_IWUSR,
745 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
747 SENSOR_ATTR_2(temp1_auto_point1_temp, S_IRUGO|S_IWUSR,
748 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
750 SENSOR_ATTR_2(temp1_auto_point2_temp, S_IRUGO|S_IWUSR,
751 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
753 SENSOR_ATTR_2(temp1_auto_point3_temp, S_IRUGO|S_IWUSR,
754 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
756 SENSOR_ATTR_2(temp1_auto_point4_temp, S_IRUGO|S_IWUSR,
757 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
759 SENSOR_ATTR_2(temp1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
760 show_pwm_auto_point_temp_hyst,
761 store_pwm_auto_point_temp_hyst,
763 SENSOR_ATTR_2(temp1_auto_point2_temp_hyst, S_IRUGO,
764 show_pwm_auto_point_temp_hyst, NULL, 1, 2),
765 SENSOR_ATTR_2(temp1_auto_point3_temp_hyst, S_IRUGO,
766 show_pwm_auto_point_temp_hyst, NULL, 2, 2),
767 SENSOR_ATTR_2(temp1_auto_point4_temp_hyst, S_IRUGO,
768 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
770 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
771 show_pwm_auto_point_channel,
772 store_pwm_auto_point_channel, 0, 1),
773 SENSOR_ATTR_2(temp2_auto_point1_pwm, S_IRUGO|S_IWUSR,
774 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
776 SENSOR_ATTR_2(temp2_auto_point2_pwm, S_IRUGO|S_IWUSR,
777 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
779 SENSOR_ATTR_2(temp2_auto_point3_pwm, S_IRUGO|S_IWUSR,
780 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
782 SENSOR_ATTR_2(temp2_auto_point4_pwm, S_IRUGO|S_IWUSR,
783 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
785 SENSOR_ATTR_2(temp2_auto_point5_pwm, S_IRUGO|S_IWUSR,
786 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
788 SENSOR_ATTR_2(temp2_auto_point1_temp, S_IRUGO|S_IWUSR,
789 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
791 SENSOR_ATTR_2(temp2_auto_point2_temp, S_IRUGO|S_IWUSR,
792 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
794 SENSOR_ATTR_2(temp2_auto_point3_temp, S_IRUGO|S_IWUSR,
795 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
797 SENSOR_ATTR_2(temp2_auto_point4_temp, S_IRUGO|S_IWUSR,
798 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
800 SENSOR_ATTR_2(temp2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
801 show_pwm_auto_point_temp_hyst,
802 store_pwm_auto_point_temp_hyst,
804 SENSOR_ATTR_2(temp2_auto_point2_temp_hyst, S_IRUGO,
805 show_pwm_auto_point_temp_hyst, NULL, 1, 0),
806 SENSOR_ATTR_2(temp2_auto_point3_temp_hyst, S_IRUGO,
807 show_pwm_auto_point_temp_hyst, NULL, 2, 0),
808 SENSOR_ATTR_2(temp2_auto_point4_temp_hyst, S_IRUGO,
809 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
811 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
812 show_pwm_auto_point_channel,
813 store_pwm_auto_point_channel, 0, 2),
814 SENSOR_ATTR_2(temp3_auto_point1_pwm, S_IRUGO|S_IWUSR,
815 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
817 SENSOR_ATTR_2(temp3_auto_point2_pwm, S_IRUGO|S_IWUSR,
818 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
820 SENSOR_ATTR_2(temp3_auto_point3_pwm, S_IRUGO|S_IWUSR,
821 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
823 SENSOR_ATTR_2(temp3_auto_point4_pwm, S_IRUGO|S_IWUSR,
824 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
826 SENSOR_ATTR_2(temp3_auto_point5_pwm, S_IRUGO|S_IWUSR,
827 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
829 SENSOR_ATTR_2(temp3_auto_point1_temp, S_IRUGO|S_IWUSR,
830 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
832 SENSOR_ATTR_2(temp3_auto_point2_temp, S_IRUGO|S_IWUSR,
833 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
835 SENSOR_ATTR_2(temp3_auto_point3_temp, S_IRUGO|S_IWUSR,
836 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
838 SENSOR_ATTR_2(temp3_auto_point4_temp, S_IRUGO|S_IWUSR,
839 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
841 SENSOR_ATTR_2(temp3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
842 show_pwm_auto_point_temp_hyst,
843 store_pwm_auto_point_temp_hyst,
845 SENSOR_ATTR_2(temp3_auto_point2_temp_hyst, S_IRUGO,
846 show_pwm_auto_point_temp_hyst, NULL, 1, 1),
847 SENSOR_ATTR_2(temp3_auto_point3_temp_hyst, S_IRUGO,
848 show_pwm_auto_point_temp_hyst, NULL, 2, 1),
849 SENSOR_ATTR_2(temp3_auto_point4_temp_hyst, S_IRUGO,
850 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
853 /* Super I/O functions */
854 static inline int superio_inb(int base, int reg)
857 return inb(base + 1);
860 static int superio_inw(int base, int reg)
863 val = superio_inb(base, reg) << 8;
864 val |= superio_inb(base, reg + 1);
868 static inline int superio_enter(int base)
870 /* Don't step on other drivers' I/O space by accident */
871 if (!request_muxed_region(base, 2, DRVNAME)) {
872 pr_err("I/O address 0x%04x already in use\n", base);
876 /* according to the datasheet the key must be send twice! */
877 outb(SIO_UNLOCK_KEY, base);
878 outb(SIO_UNLOCK_KEY, base);
883 static inline void superio_select(int base, int ld)
885 outb(SIO_REG_LDSEL, base);
889 static inline void superio_exit(int base)
891 outb(SIO_LOCK_KEY, base);
892 release_region(base, 2);
895 static inline int fan_from_reg(u16 reg)
897 return reg ? (1500000 / reg) : 0;
900 static inline u16 fan_to_reg(int fan)
902 return fan ? (1500000 / fan) : 0;
905 static u8 f71882fg_read8(struct f71882fg_data *data, u8 reg)
909 outb(reg, data->addr + ADDR_REG_OFFSET);
910 val = inb(data->addr + DATA_REG_OFFSET);
915 static u16 f71882fg_read16(struct f71882fg_data *data, u8 reg)
919 val = f71882fg_read8(data, reg) << 8;
920 val |= f71882fg_read8(data, reg + 1);
925 static void f71882fg_write8(struct f71882fg_data *data, u8 reg, u8 val)
927 outb(reg, data->addr + ADDR_REG_OFFSET);
928 outb(val, data->addr + DATA_REG_OFFSET);
931 static void f71882fg_write16(struct f71882fg_data *data, u8 reg, u16 val)
933 f71882fg_write8(data, reg, val >> 8);
934 f71882fg_write8(data, reg + 1, val & 0xff);
937 static u16 f71882fg_read_temp(struct f71882fg_data *data, int nr)
939 if (data->type == f71858fg)
940 return f71882fg_read16(data, F71882FG_REG_TEMP(nr));
942 return f71882fg_read8(data, F71882FG_REG_TEMP(nr));
945 static struct f71882fg_data *f71882fg_update_device(struct device *dev)
947 struct f71882fg_data *data = dev_get_drvdata(dev);
949 int nr_fans = (data->type == f71882fg) ? 4 : 3;
950 int nr_ins = (data->type == f71858fg || data->type == f8000) ? 3 : 9;
952 mutex_lock(&data->update_lock);
954 /* Update once every 60 seconds */
955 if (time_after(jiffies, data->last_limits + 60 * HZ) ||
957 if (data->type == f71882fg || data->type == f71889fg) {
959 f71882fg_read8(data, F71882FG_REG_IN1_HIGH);
961 f71882fg_read8(data, F71882FG_REG_IN_BEEP);
964 /* Get High & boundary temps*/
965 for (nr = data->temp_start; nr < 3 + data->temp_start; nr++) {
966 data->temp_ovt[nr] = f71882fg_read8(data,
967 F71882FG_REG_TEMP_OVT(nr));
968 data->temp_high[nr] = f71882fg_read8(data,
969 F71882FG_REG_TEMP_HIGH(nr));
972 if (data->type != f8000) {
973 data->temp_hyst[0] = f71882fg_read8(data,
974 F71882FG_REG_TEMP_HYST(0));
975 data->temp_hyst[1] = f71882fg_read8(data,
976 F71882FG_REG_TEMP_HYST(1));
979 if (data->type == f71862fg || data->type == f71882fg ||
980 data->type == f71889fg) {
981 data->fan_beep = f71882fg_read8(data,
982 F71882FG_REG_FAN_BEEP);
983 data->temp_beep = f71882fg_read8(data,
984 F71882FG_REG_TEMP_BEEP);
985 reg = f71882fg_read8(data, F71882FG_REG_TEMP_TYPE);
986 data->temp_type[1] = (reg & 0x02) ? 2 : 4;
987 data->temp_type[2] = (reg & 0x04) ? 2 : 4;
988 data->temp_type[3] = (reg & 0x08) ? 2 : 4;
991 data->pwm_enable = f71882fg_read8(data,
992 F71882FG_REG_PWM_ENABLE);
993 data->pwm_auto_point_hyst[0] =
994 f71882fg_read8(data, F71882FG_REG_FAN_HYST(0));
995 data->pwm_auto_point_hyst[1] =
996 f71882fg_read8(data, F71882FG_REG_FAN_HYST(1));
998 for (nr = 0; nr < nr_fans; nr++) {
999 data->pwm_auto_point_mapping[nr] =
1000 f71882fg_read8(data,
1001 F71882FG_REG_POINT_MAPPING(nr));
1003 if (data->type != f71862fg) {
1005 for (point = 0; point < 5; point++) {
1006 data->pwm_auto_point_pwm[nr][point] =
1007 f71882fg_read8(data,
1008 F71882FG_REG_POINT_PWM
1011 for (point = 0; point < 4; point++) {
1012 data->pwm_auto_point_temp[nr][point] =
1013 f71882fg_read8(data,
1014 F71882FG_REG_POINT_TEMP
1018 data->pwm_auto_point_pwm[nr][1] =
1019 f71882fg_read8(data,
1020 F71882FG_REG_POINT_PWM
1022 data->pwm_auto_point_pwm[nr][4] =
1023 f71882fg_read8(data,
1024 F71882FG_REG_POINT_PWM
1026 data->pwm_auto_point_temp[nr][0] =
1027 f71882fg_read8(data,
1028 F71882FG_REG_POINT_TEMP
1030 data->pwm_auto_point_temp[nr][3] =
1031 f71882fg_read8(data,
1032 F71882FG_REG_POINT_TEMP
1036 data->last_limits = jiffies;
1039 /* Update every second */
1040 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
1041 data->temp_status = f71882fg_read8(data,
1042 F71882FG_REG_TEMP_STATUS);
1043 data->temp_diode_open = f71882fg_read8(data,
1044 F71882FG_REG_TEMP_DIODE_OPEN);
1045 for (nr = data->temp_start; nr < 3 + data->temp_start; nr++)
1046 data->temp[nr] = f71882fg_read_temp(data, nr);
1048 data->fan_status = f71882fg_read8(data,
1049 F71882FG_REG_FAN_STATUS);
1050 for (nr = 0; nr < nr_fans; nr++) {
1051 data->fan[nr] = f71882fg_read16(data,
1052 F71882FG_REG_FAN(nr));
1053 data->fan_target[nr] =
1054 f71882fg_read16(data, F71882FG_REG_FAN_TARGET(nr));
1055 data->fan_full_speed[nr] =
1056 f71882fg_read16(data,
1057 F71882FG_REG_FAN_FULL_SPEED(nr));
1059 f71882fg_read8(data, F71882FG_REG_PWM(nr));
1062 /* The f8000 can monitor 1 more fan, but has no pwm for it */
1063 if (data->type == f8000)
1064 data->fan[3] = f71882fg_read16(data,
1065 F71882FG_REG_FAN(3));
1066 if (data->type == f71882fg || data->type == f71889fg)
1067 data->in_status = f71882fg_read8(data,
1068 F71882FG_REG_IN_STATUS);
1069 for (nr = 0; nr < nr_ins; nr++)
1070 data->in[nr] = f71882fg_read8(data,
1071 F71882FG_REG_IN(nr));
1073 data->last_updated = jiffies;
1077 mutex_unlock(&data->update_lock);
1082 /* Sysfs Interface */
1083 static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
1086 struct f71882fg_data *data = f71882fg_update_device(dev);
1087 int nr = to_sensor_dev_attr_2(devattr)->index;
1088 int speed = fan_from_reg(data->fan[nr]);
1090 if (speed == FAN_MIN_DETECT)
1093 return sprintf(buf, "%d\n", speed);
1096 static ssize_t show_fan_full_speed(struct device *dev,
1097 struct device_attribute *devattr, char *buf)
1099 struct f71882fg_data *data = f71882fg_update_device(dev);
1100 int nr = to_sensor_dev_attr_2(devattr)->index;
1101 int speed = fan_from_reg(data->fan_full_speed[nr]);
1102 return sprintf(buf, "%d\n", speed);
1105 static ssize_t store_fan_full_speed(struct device *dev,
1106 struct device_attribute *devattr,
1107 const char *buf, size_t count)
1109 struct f71882fg_data *data = dev_get_drvdata(dev);
1110 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1113 err = strict_strtol(buf, 10, &val);
1117 val = SENSORS_LIMIT(val, 23, 1500000);
1118 val = fan_to_reg(val);
1120 mutex_lock(&data->update_lock);
1121 f71882fg_write16(data, F71882FG_REG_FAN_FULL_SPEED(nr), val);
1122 data->fan_full_speed[nr] = val;
1123 mutex_unlock(&data->update_lock);
1128 static ssize_t show_fan_beep(struct device *dev, struct device_attribute
1129 *devattr, char *buf)
1131 struct f71882fg_data *data = f71882fg_update_device(dev);
1132 int nr = to_sensor_dev_attr_2(devattr)->index;
1134 if (data->fan_beep & (1 << nr))
1135 return sprintf(buf, "1\n");
1137 return sprintf(buf, "0\n");
1140 static ssize_t store_fan_beep(struct device *dev, struct device_attribute
1141 *devattr, const char *buf, size_t count)
1143 struct f71882fg_data *data = dev_get_drvdata(dev);
1144 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1147 err = strict_strtoul(buf, 10, &val);
1151 mutex_lock(&data->update_lock);
1152 data->fan_beep = f71882fg_read8(data, F71882FG_REG_FAN_BEEP);
1154 data->fan_beep |= 1 << nr;
1156 data->fan_beep &= ~(1 << nr);
1158 f71882fg_write8(data, F71882FG_REG_FAN_BEEP, data->fan_beep);
1159 mutex_unlock(&data->update_lock);
1164 static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
1165 *devattr, char *buf)
1167 struct f71882fg_data *data = f71882fg_update_device(dev);
1168 int nr = to_sensor_dev_attr_2(devattr)->index;
1170 if (data->fan_status & (1 << nr))
1171 return sprintf(buf, "1\n");
1173 return sprintf(buf, "0\n");
1176 static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
1179 struct f71882fg_data *data = f71882fg_update_device(dev);
1180 int nr = to_sensor_dev_attr_2(devattr)->index;
1182 return sprintf(buf, "%d\n", data->in[nr] * 8);
1185 static ssize_t show_in_max(struct device *dev, struct device_attribute
1186 *devattr, char *buf)
1188 struct f71882fg_data *data = f71882fg_update_device(dev);
1190 return sprintf(buf, "%d\n", data->in1_max * 8);
1193 static ssize_t store_in_max(struct device *dev, struct device_attribute
1194 *devattr, const char *buf, size_t count)
1196 struct f71882fg_data *data = dev_get_drvdata(dev);
1200 err = strict_strtol(buf, 10, &val);
1205 val = SENSORS_LIMIT(val, 0, 255);
1207 mutex_lock(&data->update_lock);
1208 f71882fg_write8(data, F71882FG_REG_IN1_HIGH, val);
1209 data->in1_max = val;
1210 mutex_unlock(&data->update_lock);
1215 static ssize_t show_in_beep(struct device *dev, struct device_attribute
1216 *devattr, char *buf)
1218 struct f71882fg_data *data = f71882fg_update_device(dev);
1219 int nr = to_sensor_dev_attr_2(devattr)->index;
1221 if (data->in_beep & (1 << nr))
1222 return sprintf(buf, "1\n");
1224 return sprintf(buf, "0\n");
1227 static ssize_t store_in_beep(struct device *dev, struct device_attribute
1228 *devattr, const char *buf, size_t count)
1230 struct f71882fg_data *data = dev_get_drvdata(dev);
1231 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1234 err = strict_strtoul(buf, 10, &val);
1238 mutex_lock(&data->update_lock);
1239 data->in_beep = f71882fg_read8(data, F71882FG_REG_IN_BEEP);
1241 data->in_beep |= 1 << nr;
1243 data->in_beep &= ~(1 << nr);
1245 f71882fg_write8(data, F71882FG_REG_IN_BEEP, data->in_beep);
1246 mutex_unlock(&data->update_lock);
1251 static ssize_t show_in_alarm(struct device *dev, struct device_attribute
1252 *devattr, char *buf)
1254 struct f71882fg_data *data = f71882fg_update_device(dev);
1255 int nr = to_sensor_dev_attr_2(devattr)->index;
1257 if (data->in_status & (1 << nr))
1258 return sprintf(buf, "1\n");
1260 return sprintf(buf, "0\n");
1263 static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
1266 struct f71882fg_data *data = f71882fg_update_device(dev);
1267 int nr = to_sensor_dev_attr_2(devattr)->index;
1270 if (data->type == f71858fg) {
1271 /* TEMP_TABLE_SEL 1 or 3 ? */
1272 if (data->temp_config & 1) {
1273 sign = data->temp[nr] & 0x0001;
1274 temp = (data->temp[nr] >> 5) & 0x7ff;
1276 sign = data->temp[nr] & 0x8000;
1277 temp = (data->temp[nr] >> 5) & 0x3ff;
1283 temp = data->temp[nr] * 1000;
1285 return sprintf(buf, "%d\n", temp);
1288 static ssize_t show_temp_max(struct device *dev, struct device_attribute
1289 *devattr, char *buf)
1291 struct f71882fg_data *data = f71882fg_update_device(dev);
1292 int nr = to_sensor_dev_attr_2(devattr)->index;
1294 return sprintf(buf, "%d\n", data->temp_high[nr] * 1000);
1297 static ssize_t store_temp_max(struct device *dev, struct device_attribute
1298 *devattr, const char *buf, size_t count)
1300 struct f71882fg_data *data = dev_get_drvdata(dev);
1301 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1304 err = strict_strtol(buf, 10, &val);
1309 val = SENSORS_LIMIT(val, 0, 255);
1311 mutex_lock(&data->update_lock);
1312 f71882fg_write8(data, F71882FG_REG_TEMP_HIGH(nr), val);
1313 data->temp_high[nr] = val;
1314 mutex_unlock(&data->update_lock);
1319 static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
1320 *devattr, char *buf)
1322 struct f71882fg_data *data = f71882fg_update_device(dev);
1323 int nr = to_sensor_dev_attr_2(devattr)->index;
1326 mutex_lock(&data->update_lock);
1328 temp_max_hyst = data->temp_hyst[nr / 2] >> 4;
1330 temp_max_hyst = data->temp_hyst[nr / 2] & 0x0f;
1331 temp_max_hyst = (data->temp_high[nr] - temp_max_hyst) * 1000;
1332 mutex_unlock(&data->update_lock);
1334 return sprintf(buf, "%d\n", temp_max_hyst);
1337 static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
1338 *devattr, const char *buf, size_t count)
1340 struct f71882fg_data *data = dev_get_drvdata(dev);
1341 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1342 ssize_t ret = count;
1346 err = strict_strtol(buf, 10, &val);
1352 mutex_lock(&data->update_lock);
1354 /* convert abs to relative and check */
1355 data->temp_high[nr] = f71882fg_read8(data, F71882FG_REG_TEMP_HIGH(nr));
1356 val = SENSORS_LIMIT(val, data->temp_high[nr] - 15,
1357 data->temp_high[nr]);
1358 val = data->temp_high[nr] - val;
1360 /* convert value to register contents */
1361 reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST(nr / 2));
1363 reg = (reg & 0x0f) | (val << 4);
1365 reg = (reg & 0xf0) | val;
1366 f71882fg_write8(data, F71882FG_REG_TEMP_HYST(nr / 2), reg);
1367 data->temp_hyst[nr / 2] = reg;
1369 mutex_unlock(&data->update_lock);
1373 static ssize_t show_temp_crit(struct device *dev, struct device_attribute
1374 *devattr, char *buf)
1376 struct f71882fg_data *data = f71882fg_update_device(dev);
1377 int nr = to_sensor_dev_attr_2(devattr)->index;
1379 return sprintf(buf, "%d\n", data->temp_ovt[nr] * 1000);
1382 static ssize_t store_temp_crit(struct device *dev, struct device_attribute
1383 *devattr, const char *buf, size_t count)
1385 struct f71882fg_data *data = dev_get_drvdata(dev);
1386 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1389 err = strict_strtol(buf, 10, &val);
1394 val = SENSORS_LIMIT(val, 0, 255);
1396 mutex_lock(&data->update_lock);
1397 f71882fg_write8(data, F71882FG_REG_TEMP_OVT(nr), val);
1398 data->temp_ovt[nr] = val;
1399 mutex_unlock(&data->update_lock);
1404 static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
1405 *devattr, char *buf)
1407 struct f71882fg_data *data = f71882fg_update_device(dev);
1408 int nr = to_sensor_dev_attr_2(devattr)->index;
1411 mutex_lock(&data->update_lock);
1413 temp_crit_hyst = data->temp_hyst[nr / 2] >> 4;
1415 temp_crit_hyst = data->temp_hyst[nr / 2] & 0x0f;
1416 temp_crit_hyst = (data->temp_ovt[nr] - temp_crit_hyst) * 1000;
1417 mutex_unlock(&data->update_lock);
1419 return sprintf(buf, "%d\n", temp_crit_hyst);
1422 static ssize_t show_temp_type(struct device *dev, struct device_attribute
1423 *devattr, char *buf)
1425 struct f71882fg_data *data = f71882fg_update_device(dev);
1426 int nr = to_sensor_dev_attr_2(devattr)->index;
1428 return sprintf(buf, "%d\n", data->temp_type[nr]);
1431 static ssize_t show_temp_beep(struct device *dev, struct device_attribute
1432 *devattr, char *buf)
1434 struct f71882fg_data *data = f71882fg_update_device(dev);
1435 int nr = to_sensor_dev_attr_2(devattr)->index;
1437 if (data->temp_beep & (1 << nr))
1438 return sprintf(buf, "1\n");
1440 return sprintf(buf, "0\n");
1443 static ssize_t store_temp_beep(struct device *dev, struct device_attribute
1444 *devattr, const char *buf, size_t count)
1446 struct f71882fg_data *data = dev_get_drvdata(dev);
1447 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1450 err = strict_strtoul(buf, 10, &val);
1454 mutex_lock(&data->update_lock);
1455 data->temp_beep = f71882fg_read8(data, F71882FG_REG_TEMP_BEEP);
1457 data->temp_beep |= 1 << nr;
1459 data->temp_beep &= ~(1 << nr);
1461 f71882fg_write8(data, F71882FG_REG_TEMP_BEEP, data->temp_beep);
1462 mutex_unlock(&data->update_lock);
1467 static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
1468 *devattr, char *buf)
1470 struct f71882fg_data *data = f71882fg_update_device(dev);
1471 int nr = to_sensor_dev_attr_2(devattr)->index;
1473 if (data->temp_status & (1 << nr))
1474 return sprintf(buf, "1\n");
1476 return sprintf(buf, "0\n");
1479 static ssize_t show_temp_fault(struct device *dev, struct device_attribute
1480 *devattr, char *buf)
1482 struct f71882fg_data *data = f71882fg_update_device(dev);
1483 int nr = to_sensor_dev_attr_2(devattr)->index;
1485 if (data->temp_diode_open & (1 << nr))
1486 return sprintf(buf, "1\n");
1488 return sprintf(buf, "0\n");
1491 static ssize_t show_pwm(struct device *dev,
1492 struct device_attribute *devattr, char *buf)
1494 struct f71882fg_data *data = f71882fg_update_device(dev);
1495 int val, nr = to_sensor_dev_attr_2(devattr)->index;
1496 mutex_lock(&data->update_lock);
1497 if (data->pwm_enable & (1 << (2 * nr)))
1499 val = data->pwm[nr];
1502 val = 255 * fan_from_reg(data->fan_target[nr])
1503 / fan_from_reg(data->fan_full_speed[nr]);
1505 mutex_unlock(&data->update_lock);
1506 return sprintf(buf, "%d\n", val);
1509 static ssize_t store_pwm(struct device *dev,
1510 struct device_attribute *devattr, const char *buf,
1513 struct f71882fg_data *data = dev_get_drvdata(dev);
1514 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1517 err = strict_strtol(buf, 10, &val);
1521 val = SENSORS_LIMIT(val, 0, 255);
1523 mutex_lock(&data->update_lock);
1524 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
1525 if ((data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 3) != 2) ||
1526 (data->type != f8000 && !((data->pwm_enable >> 2 * nr) & 2))) {
1530 if (data->pwm_enable & (1 << (2 * nr))) {
1532 f71882fg_write8(data, F71882FG_REG_PWM(nr), val);
1533 data->pwm[nr] = val;
1536 int target, full_speed;
1537 full_speed = f71882fg_read16(data,
1538 F71882FG_REG_FAN_FULL_SPEED(nr));
1539 target = fan_to_reg(val * fan_from_reg(full_speed) / 255);
1540 f71882fg_write16(data, F71882FG_REG_FAN_TARGET(nr), target);
1541 data->fan_target[nr] = target;
1542 data->fan_full_speed[nr] = full_speed;
1545 mutex_unlock(&data->update_lock);
1550 static ssize_t show_pwm_enable(struct device *dev,
1551 struct device_attribute *devattr, char *buf)
1554 struct f71882fg_data *data = f71882fg_update_device(dev);
1555 int nr = to_sensor_dev_attr_2(devattr)->index;
1557 switch ((data->pwm_enable >> 2 * nr) & 3) {
1560 result = 2; /* Normal auto mode */
1563 result = 1; /* Manual mode */
1566 if (data->type == f8000)
1567 result = 3; /* Thermostat mode */
1569 result = 1; /* Manual mode */
1573 return sprintf(buf, "%d\n", result);
1576 static ssize_t store_pwm_enable(struct device *dev, struct device_attribute
1577 *devattr, const char *buf, size_t count)
1579 struct f71882fg_data *data = dev_get_drvdata(dev);
1580 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1583 err = strict_strtol(buf, 10, &val);
1587 /* Special case for F8000 pwm channel 3 which only does auto mode */
1588 if (data->type == f8000 && nr == 2 && val != 2)
1591 mutex_lock(&data->update_lock);
1592 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
1593 /* Special case for F8000 auto PWM mode / Thermostat mode */
1594 if (data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 1)) {
1597 data->pwm_enable &= ~(2 << (2 * nr));
1598 break; /* Normal auto mode */
1600 data->pwm_enable |= 2 << (2 * nr);
1601 break; /* Thermostat mode */
1609 /* The f71858fg does not support manual RPM mode */
1610 if (data->type == f71858fg &&
1611 ((data->pwm_enable >> (2 * nr)) & 1)) {
1615 data->pwm_enable |= 2 << (2 * nr);
1618 data->pwm_enable &= ~(2 << (2 * nr));
1619 break; /* Normal auto mode */
1625 f71882fg_write8(data, F71882FG_REG_PWM_ENABLE, data->pwm_enable);
1627 mutex_unlock(&data->update_lock);
1632 static ssize_t show_pwm_auto_point_pwm(struct device *dev,
1633 struct device_attribute *devattr,
1637 struct f71882fg_data *data = f71882fg_update_device(dev);
1638 int pwm = to_sensor_dev_attr_2(devattr)->index;
1639 int point = to_sensor_dev_attr_2(devattr)->nr;
1641 mutex_lock(&data->update_lock);
1642 if (data->pwm_enable & (1 << (2 * pwm))) {
1644 result = data->pwm_auto_point_pwm[pwm][point];
1647 result = 32 * 255 / (32 + data->pwm_auto_point_pwm[pwm][point]);
1649 mutex_unlock(&data->update_lock);
1651 return sprintf(buf, "%d\n", result);
1654 static ssize_t store_pwm_auto_point_pwm(struct device *dev,
1655 struct device_attribute *devattr,
1656 const char *buf, size_t count)
1658 struct f71882fg_data *data = dev_get_drvdata(dev);
1659 int err, pwm = to_sensor_dev_attr_2(devattr)->index;
1660 int point = to_sensor_dev_attr_2(devattr)->nr;
1663 err = strict_strtol(buf, 10, &val);
1667 val = SENSORS_LIMIT(val, 0, 255);
1669 mutex_lock(&data->update_lock);
1670 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
1671 if (data->pwm_enable & (1 << (2 * pwm))) {
1675 if (val < 29) /* Prevent negative numbers */
1678 val = (255 - val) * 32 / val;
1680 f71882fg_write8(data, F71882FG_REG_POINT_PWM(pwm, point), val);
1681 data->pwm_auto_point_pwm[pwm][point] = val;
1682 mutex_unlock(&data->update_lock);
1687 static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
1688 struct device_attribute *devattr,
1692 struct f71882fg_data *data = f71882fg_update_device(dev);
1693 int nr = to_sensor_dev_attr_2(devattr)->index;
1694 int point = to_sensor_dev_attr_2(devattr)->nr;
1696 mutex_lock(&data->update_lock);
1698 result = data->pwm_auto_point_hyst[nr / 2] >> 4;
1700 result = data->pwm_auto_point_hyst[nr / 2] & 0x0f;
1701 result = 1000 * (data->pwm_auto_point_temp[nr][point] - result);
1702 mutex_unlock(&data->update_lock);
1704 return sprintf(buf, "%d\n", result);
1707 static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
1708 struct device_attribute *devattr,
1709 const char *buf, size_t count)
1711 struct f71882fg_data *data = dev_get_drvdata(dev);
1712 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1713 int point = to_sensor_dev_attr_2(devattr)->nr;
1717 err = strict_strtol(buf, 10, &val);
1723 mutex_lock(&data->update_lock);
1724 data->pwm_auto_point_temp[nr][point] =
1725 f71882fg_read8(data, F71882FG_REG_POINT_TEMP(nr, point));
1726 val = SENSORS_LIMIT(val, data->pwm_auto_point_temp[nr][point] - 15,
1727 data->pwm_auto_point_temp[nr][point]);
1728 val = data->pwm_auto_point_temp[nr][point] - val;
1730 reg = f71882fg_read8(data, F71882FG_REG_FAN_HYST(nr / 2));
1732 reg = (reg & 0x0f) | (val << 4);
1734 reg = (reg & 0xf0) | val;
1736 f71882fg_write8(data, F71882FG_REG_FAN_HYST(nr / 2), reg);
1737 data->pwm_auto_point_hyst[nr / 2] = reg;
1738 mutex_unlock(&data->update_lock);
1743 static ssize_t show_pwm_interpolate(struct device *dev,
1744 struct device_attribute *devattr, char *buf)
1747 struct f71882fg_data *data = f71882fg_update_device(dev);
1748 int nr = to_sensor_dev_attr_2(devattr)->index;
1750 result = (data->pwm_auto_point_mapping[nr] >> 4) & 1;
1752 return sprintf(buf, "%d\n", result);
1755 static ssize_t store_pwm_interpolate(struct device *dev,
1756 struct device_attribute *devattr,
1757 const char *buf, size_t count)
1759 struct f71882fg_data *data = dev_get_drvdata(dev);
1760 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1763 err = strict_strtoul(buf, 10, &val);
1767 mutex_lock(&data->update_lock);
1768 data->pwm_auto_point_mapping[nr] =
1769 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
1771 val = data->pwm_auto_point_mapping[nr] | (1 << 4);
1773 val = data->pwm_auto_point_mapping[nr] & (~(1 << 4));
1774 f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val);
1775 data->pwm_auto_point_mapping[nr] = val;
1776 mutex_unlock(&data->update_lock);
1781 static ssize_t show_pwm_auto_point_channel(struct device *dev,
1782 struct device_attribute *devattr,
1786 struct f71882fg_data *data = f71882fg_update_device(dev);
1787 int nr = to_sensor_dev_attr_2(devattr)->index;
1789 result = 1 << ((data->pwm_auto_point_mapping[nr] & 3) -
1792 return sprintf(buf, "%d\n", result);
1795 static ssize_t store_pwm_auto_point_channel(struct device *dev,
1796 struct device_attribute *devattr,
1797 const char *buf, size_t count)
1799 struct f71882fg_data *data = dev_get_drvdata(dev);
1800 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1803 err = strict_strtol(buf, 10, &val);
1820 val += data->temp_start;
1821 mutex_lock(&data->update_lock);
1822 data->pwm_auto_point_mapping[nr] =
1823 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
1824 val = (data->pwm_auto_point_mapping[nr] & 0xfc) | val;
1825 f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val);
1826 data->pwm_auto_point_mapping[nr] = val;
1827 mutex_unlock(&data->update_lock);
1832 static ssize_t show_pwm_auto_point_temp(struct device *dev,
1833 struct device_attribute *devattr,
1837 struct f71882fg_data *data = f71882fg_update_device(dev);
1838 int pwm = to_sensor_dev_attr_2(devattr)->index;
1839 int point = to_sensor_dev_attr_2(devattr)->nr;
1841 result = data->pwm_auto_point_temp[pwm][point];
1842 return sprintf(buf, "%d\n", 1000 * result);
1845 static ssize_t store_pwm_auto_point_temp(struct device *dev,
1846 struct device_attribute *devattr,
1847 const char *buf, size_t count)
1849 struct f71882fg_data *data = dev_get_drvdata(dev);
1850 int err, pwm = to_sensor_dev_attr_2(devattr)->index;
1851 int point = to_sensor_dev_attr_2(devattr)->nr;
1854 err = strict_strtol(buf, 10, &val);
1860 if (data->auto_point_temp_signed)
1861 val = SENSORS_LIMIT(val, -128, 127);
1863 val = SENSORS_LIMIT(val, 0, 127);
1865 mutex_lock(&data->update_lock);
1866 f71882fg_write8(data, F71882FG_REG_POINT_TEMP(pwm, point), val);
1867 data->pwm_auto_point_temp[pwm][point] = val;
1868 mutex_unlock(&data->update_lock);
1873 static ssize_t show_name(struct device *dev, struct device_attribute *devattr,
1876 struct f71882fg_data *data = dev_get_drvdata(dev);
1877 return sprintf(buf, "%s\n", f71882fg_names[data->type]);
1880 static int __devinit f71882fg_create_sysfs_files(struct platform_device *pdev,
1881 struct sensor_device_attribute_2 *attr, int count)
1885 for (i = 0; i < count; i++) {
1886 err = device_create_file(&pdev->dev, &attr[i].dev_attr);
1893 static void f71882fg_remove_sysfs_files(struct platform_device *pdev,
1894 struct sensor_device_attribute_2 *attr, int count)
1898 for (i = 0; i < count; i++)
1899 device_remove_file(&pdev->dev, &attr[i].dev_attr);
1902 static int __devinit f71882fg_probe(struct platform_device *pdev)
1904 struct f71882fg_data *data;
1905 struct f71882fg_sio_data *sio_data = pdev->dev.platform_data;
1906 int err, i, nr_fans = (sio_data->type == f71882fg) ? 4 : 3;
1909 data = kzalloc(sizeof(struct f71882fg_data), GFP_KERNEL);
1913 data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start;
1914 data->type = sio_data->type;
1916 (data->type == f71858fg || data->type == f8000) ? 0 : 1;
1917 mutex_init(&data->update_lock);
1918 platform_set_drvdata(pdev, data);
1920 start_reg = f71882fg_read8(data, F71882FG_REG_START);
1921 if (start_reg & 0x04) {
1922 dev_warn(&pdev->dev, "Hardware monitor is powered down\n");
1926 if (!(start_reg & 0x03)) {
1927 dev_warn(&pdev->dev, "Hardware monitoring not activated\n");
1932 /* Register sysfs interface files */
1933 err = device_create_file(&pdev->dev, &dev_attr_name);
1935 goto exit_unregister_sysfs;
1937 if (start_reg & 0x01) {
1938 switch (data->type) {
1941 f71882fg_read8(data, F71882FG_REG_TEMP_CONFIG);
1942 if (data->temp_config & 0x10)
1943 /* The f71858fg temperature alarms behave as
1944 the f8000 alarms in this mode */
1945 err = f71882fg_create_sysfs_files(pdev,
1947 ARRAY_SIZE(f8000_in_temp_attr));
1949 err = f71882fg_create_sysfs_files(pdev,
1950 f71858fg_in_temp_attr,
1951 ARRAY_SIZE(f71858fg_in_temp_attr));
1955 err = f71882fg_create_sysfs_files(pdev,
1956 fxxxx_in1_alarm_attr,
1957 ARRAY_SIZE(fxxxx_in1_alarm_attr));
1959 goto exit_unregister_sysfs;
1962 err = f71882fg_create_sysfs_files(pdev,
1964 ARRAY_SIZE(fxxxx_in_temp_attr));
1967 err = f71882fg_create_sysfs_files(pdev,
1969 ARRAY_SIZE(f8000_in_temp_attr));
1973 goto exit_unregister_sysfs;
1976 if (start_reg & 0x02) {
1977 switch (data->type) {
1979 reg = f71882fg_read8(data, F71882FG_REG_FAN_FAULT_T);
1980 if (reg & F71882FG_FAN_NEG_TEMP_EN)
1981 data->auto_point_temp_signed = 1;
1988 f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
1990 /* Sanity check the pwm settings */
1991 switch (data->type) {
1994 for (i = 0; i < nr_fans; i++)
1995 if (((data->pwm_enable >> (i * 2)) & 3) == 3)
1999 err = (data->pwm_enable & 0x15) != 0x15;
2006 err = data->pwm_enable & 0x20;
2011 "Invalid (reserved) pwm settings: 0x%02x\n",
2012 (unsigned int)data->pwm_enable);
2014 goto exit_unregister_sysfs;
2017 err = f71882fg_create_sysfs_files(pdev, &fxxxx_fan_attr[0][0],
2018 ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans);
2020 goto exit_unregister_sysfs;
2022 if (data->type == f71862fg || data->type == f71882fg ||
2023 data->type == f71889fg) {
2024 err = f71882fg_create_sysfs_files(pdev,
2025 fxxxx_fan_beep_attr, nr_fans);
2027 goto exit_unregister_sysfs;
2030 switch (data->type) {
2032 err = f71882fg_create_sysfs_files(pdev,
2033 f71862fg_auto_pwm_attr,
2034 ARRAY_SIZE(f71862fg_auto_pwm_attr));
2037 err = f71882fg_create_sysfs_files(pdev,
2039 ARRAY_SIZE(f8000_fan_attr));
2041 goto exit_unregister_sysfs;
2042 err = f71882fg_create_sysfs_files(pdev,
2043 f8000_auto_pwm_attr,
2044 ARRAY_SIZE(f8000_auto_pwm_attr));
2047 for (i = 0; i < nr_fans; i++) {
2048 data->pwm_auto_point_mapping[i] =
2049 f71882fg_read8(data,
2050 F71882FG_REG_POINT_MAPPING(i));
2051 if (data->pwm_auto_point_mapping[i] & 0x80)
2055 dev_warn(&pdev->dev,
2056 "Auto pwm controlled by raw digital "
2057 "data, disabling pwm auto_point "
2058 "sysfs attributes\n");
2062 default: /* f71858fg / f71882fg */
2063 err = f71882fg_create_sysfs_files(pdev,
2064 &fxxxx_auto_pwm_attr[0][0],
2065 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
2068 goto exit_unregister_sysfs;
2070 for (i = 0; i < nr_fans; i++)
2071 dev_info(&pdev->dev, "Fan: %d is in %s mode\n", i + 1,
2072 (data->pwm_enable & (1 << 2 * i)) ?
2073 "duty-cycle" : "RPM");
2076 data->hwmon_dev = hwmon_device_register(&pdev->dev);
2077 if (IS_ERR(data->hwmon_dev)) {
2078 err = PTR_ERR(data->hwmon_dev);
2079 data->hwmon_dev = NULL;
2080 goto exit_unregister_sysfs;
2085 exit_unregister_sysfs:
2086 f71882fg_remove(pdev); /* Will unregister the sysfs files for us */
2087 return err; /* f71882fg_remove() also frees our data */
2093 static int f71882fg_remove(struct platform_device *pdev)
2095 struct f71882fg_data *data = platform_get_drvdata(pdev);
2096 int nr_fans = (data->type == f71882fg) ? 4 : 3;
2097 u8 start_reg = f71882fg_read8(data, F71882FG_REG_START);
2099 if (data->hwmon_dev)
2100 hwmon_device_unregister(data->hwmon_dev);
2102 device_remove_file(&pdev->dev, &dev_attr_name);
2104 if (start_reg & 0x01) {
2105 switch (data->type) {
2107 if (data->temp_config & 0x10)
2108 f71882fg_remove_sysfs_files(pdev,
2110 ARRAY_SIZE(f8000_in_temp_attr));
2112 f71882fg_remove_sysfs_files(pdev,
2113 f71858fg_in_temp_attr,
2114 ARRAY_SIZE(f71858fg_in_temp_attr));
2118 f71882fg_remove_sysfs_files(pdev,
2119 fxxxx_in1_alarm_attr,
2120 ARRAY_SIZE(fxxxx_in1_alarm_attr));
2123 f71882fg_remove_sysfs_files(pdev,
2125 ARRAY_SIZE(fxxxx_in_temp_attr));
2128 f71882fg_remove_sysfs_files(pdev,
2130 ARRAY_SIZE(f8000_in_temp_attr));
2135 if (start_reg & 0x02) {
2136 f71882fg_remove_sysfs_files(pdev, &fxxxx_fan_attr[0][0],
2137 ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans);
2139 if (data->type == f71862fg || data->type == f71882fg ||
2140 data->type == f71889fg)
2141 f71882fg_remove_sysfs_files(pdev,
2142 fxxxx_fan_beep_attr, nr_fans);
2144 switch (data->type) {
2146 f71882fg_remove_sysfs_files(pdev,
2147 f71862fg_auto_pwm_attr,
2148 ARRAY_SIZE(f71862fg_auto_pwm_attr));
2151 f71882fg_remove_sysfs_files(pdev,
2153 ARRAY_SIZE(f8000_fan_attr));
2154 f71882fg_remove_sysfs_files(pdev,
2155 f8000_auto_pwm_attr,
2156 ARRAY_SIZE(f8000_auto_pwm_attr));
2158 default: /* f71858fg / f71882fg / f71889fg */
2159 f71882fg_remove_sysfs_files(pdev,
2160 &fxxxx_auto_pwm_attr[0][0],
2161 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
2165 platform_set_drvdata(pdev, NULL);
2171 static int __init f71882fg_find(int sioaddr, unsigned short *address,
2172 struct f71882fg_sio_data *sio_data)
2175 int err = superio_enter(sioaddr);
2179 devid = superio_inw(sioaddr, SIO_REG_MANID);
2180 if (devid != SIO_FINTEK_ID) {
2181 pr_debug("Not a Fintek device\n");
2186 devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID);
2189 sio_data->type = f71858fg;
2192 sio_data->type = f71862fg;
2195 sio_data->type = f71882fg;
2198 sio_data->type = f71889fg;
2201 sio_data->type = f8000;
2204 pr_info("Unsupported Fintek device: %04x\n",
2205 (unsigned int)devid);
2210 if (sio_data->type == f71858fg)
2211 superio_select(sioaddr, SIO_F71858FG_LD_HWM);
2213 superio_select(sioaddr, SIO_F71882FG_LD_HWM);
2215 if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) {
2216 pr_warn("Device not activated\n");
2221 *address = superio_inw(sioaddr, SIO_REG_ADDR);
2222 if (*address == 0) {
2223 pr_warn("Base address not set\n");
2227 *address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */
2230 pr_info("Found %s chip at %#x, revision %d\n",
2231 f71882fg_names[sio_data->type], (unsigned int)*address,
2232 (int)superio_inb(sioaddr, SIO_REG_DEVREV));
2234 superio_exit(sioaddr);
2238 static int __init f71882fg_device_add(unsigned short address,
2239 const struct f71882fg_sio_data *sio_data)
2241 struct resource res = {
2243 .end = address + REGION_LENGTH - 1,
2244 .flags = IORESOURCE_IO,
2248 f71882fg_pdev = platform_device_alloc(DRVNAME, address);
2252 res.name = f71882fg_pdev->name;
2253 err = acpi_check_resource_conflict(&res);
2255 goto exit_device_put;
2257 err = platform_device_add_resources(f71882fg_pdev, &res, 1);
2259 pr_err("Device resource addition failed\n");
2260 goto exit_device_put;
2263 err = platform_device_add_data(f71882fg_pdev, sio_data,
2264 sizeof(struct f71882fg_sio_data));
2266 pr_err("Platform data allocation failed\n");
2267 goto exit_device_put;
2270 err = platform_device_add(f71882fg_pdev);
2272 pr_err("Device addition failed\n");
2273 goto exit_device_put;
2279 platform_device_put(f71882fg_pdev);
2284 static int __init f71882fg_init(void)
2287 unsigned short address;
2288 struct f71882fg_sio_data sio_data;
2290 memset(&sio_data, 0, sizeof(sio_data));
2292 if (f71882fg_find(0x2e, &address, &sio_data) &&
2293 f71882fg_find(0x4e, &address, &sio_data))
2296 err = platform_driver_register(&f71882fg_driver);
2300 err = f71882fg_device_add(address, &sio_data);
2307 platform_driver_unregister(&f71882fg_driver);
2312 static void __exit f71882fg_exit(void)
2314 platform_device_unregister(f71882fg_pdev);
2315 platform_driver_unregister(&f71882fg_driver);
2318 MODULE_DESCRIPTION("F71882FG Hardware Monitoring Driver");
2319 MODULE_AUTHOR("Hans Edgington, Hans de Goede (hdegoede@redhat.com)");
2320 MODULE_LICENSE("GPL");
2322 module_init(f71882fg_init);
2323 module_exit(f71882fg_exit);