1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /***************************************************************************
3 * Copyright (C) 2006 by Hans Edgington <hans@edgington.nl> *
4 * Copyright (C) 2007-2011 Hans de Goede <hdegoede@redhat.com> *
6 ***************************************************************************/
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #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>
20 #include <linux/acpi.h>
22 #define DRVNAME "f71882fg"
24 #define SIO_F71858FG_LD_HWM 0x02 /* Hardware monitor logical device */
25 #define SIO_F71882FG_LD_HWM 0x04 /* Hardware monitor logical device */
26 #define SIO_UNLOCK_KEY 0x87 /* Key to enable Super-I/O */
27 #define SIO_LOCK_KEY 0xAA /* Key to disable Super-I/O */
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) */
36 #define SIO_FINTEK_ID 0x1934 /* Manufacturers ID */
37 #define SIO_F71808E_ID 0x0901 /* Chipset ID */
38 #define SIO_F71808A_ID 0x1001 /* Chipset ID */
39 #define SIO_F71858_ID 0x0507 /* Chipset ID */
40 #define SIO_F71862_ID 0x0601 /* Chipset ID */
41 #define SIO_F71868_ID 0x1106 /* Chipset ID */
42 #define SIO_F71869_ID 0x0814 /* Chipset ID */
43 #define SIO_F71869A_ID 0x1007 /* Chipset ID */
44 #define SIO_F71882_ID 0x0541 /* Chipset ID */
45 #define SIO_F71889_ID 0x0723 /* Chipset ID */
46 #define SIO_F71889E_ID 0x0909 /* Chipset ID */
47 #define SIO_F71889A_ID 0x1005 /* Chipset ID */
48 #define SIO_F8000_ID 0x0581 /* Chipset ID */
49 #define SIO_F81768D_ID 0x1210 /* Chipset ID */
50 #define SIO_F81865_ID 0x0704 /* Chipset ID */
51 #define SIO_F81866_ID 0x1010 /* Chipset ID */
52 #define SIO_F81966_ID 0x1502 /* Chipset ID */
54 #define REGION_LENGTH 8
55 #define ADDR_REG_OFFSET 5
56 #define DATA_REG_OFFSET 6
58 #define F71882FG_REG_IN_STATUS 0x12 /* f7188x only */
59 #define F71882FG_REG_IN_BEEP 0x13 /* f7188x only */
60 #define F71882FG_REG_IN(nr) (0x20 + (nr))
61 #define F71882FG_REG_IN1_HIGH 0x32 /* f7188x only */
63 #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 */
67 #define F71882FG_REG_FAN(nr) (0xA0 + (16 * (nr)))
68 #define F71882FG_REG_FAN_TARGET(nr) (0xA2 + (16 * (nr)))
69 #define F71882FG_REG_FAN_FULL_SPEED(nr) (0xA4 + (16 * (nr)))
70 #define F71882FG_REG_FAN_STATUS 0x92
71 #define F71882FG_REG_FAN_BEEP 0x93
73 #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))
76 #define F71882FG_REG_TEMP_STATUS 0x62
77 #define F71882FG_REG_TEMP_BEEP 0x63
78 #define F71882FG_REG_TEMP_CONFIG 0x69
79 #define F71882FG_REG_TEMP_HYST(nr) (0x6C + (nr))
80 #define F71882FG_REG_TEMP_TYPE 0x6B
81 #define F71882FG_REG_TEMP_DIODE_OPEN 0x6F
83 #define F71882FG_REG_PWM(nr) (0xA3 + (16 * (nr)))
84 #define F71882FG_REG_PWM_TYPE 0x94
85 #define F71882FG_REG_PWM_ENABLE 0x96
87 #define F71882FG_REG_FAN_HYST(nr) (0x98 + (nr))
89 #define F71882FG_REG_FAN_FAULT_T 0x9F
90 #define F71882FG_FAN_NEG_TEMP_EN 0x20
91 #define F71882FG_FAN_PROG_SEL 0x80
93 #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))
97 #define F71882FG_REG_START 0x01
99 #define F71882FG_MAX_INS 11
101 #define FAN_MIN_DETECT 366 /* Lowest detectable fanspeed */
103 static unsigned short force_id;
104 module_param(force_id, ushort, 0);
105 MODULE_PARM_DESC(force_id, "Override the detected device ID");
107 enum chips { f71808e, f71808a, f71858fg, f71862fg, f71868a, f71869, f71869a,
108 f71882fg, f71889fg, f71889ed, f71889a, f8000, f81768d, f81865f,
111 static const char *const f71882fg_names[] = {
117 "f71869", /* Both f71869f and f71869e, reg. compatible and same id */
120 "f71889fg", /* f81801u too, same id */
129 static const char f71882fg_has_in[][F71882FG_MAX_INS] = {
130 [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 },
147 static const char f71882fg_has_in1_alarm[] = {
165 static const char f71882fg_fan_has_beep[] = {
183 static const char f71882fg_nr_fans[] = {
185 [f71808a] = 2, /* +1 fan which is monitor + simple pwm only */
195 [f8000] = 3, /* +1 fan which is monitor only */
201 static const char f71882fg_temp_has_beep[] = {
219 static const char f71882fg_nr_temps[] = {
237 static struct platform_device *f71882fg_pdev;
239 /* Super-I/O Function prototypes */
240 static inline int superio_inb(int base, int reg);
241 static inline int superio_inw(int base, int reg);
242 static inline int superio_enter(int base);
243 static inline void superio_select(int base, int ld);
244 static inline void superio_exit(int base);
246 struct f71882fg_sio_data {
250 struct f71882fg_data {
253 struct device *hwmon_dev;
255 struct mutex update_lock;
256 int temp_start; /* temp numbering start (0 or 1) */
257 bool valid; /* true if following fields are valid */
258 char auto_point_temp_signed;
259 unsigned long last_updated; /* In jiffies */
260 unsigned long last_limits; /* In jiffies */
262 /* Register Values */
263 u8 in[F71882FG_MAX_INS];
269 u16 fan_full_speed[4];
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
280 u8 temp_hyst[2]; /* 2 hysts stored per reg */
288 u8 pwm_auto_point_hyst[2];
289 u8 pwm_auto_point_mapping[4];
290 u8 pwm_auto_point_pwm[4][5];
291 s8 pwm_auto_point_temp[4][4];
295 static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
297 static ssize_t show_in_max(struct device *dev, struct device_attribute
298 *devattr, char *buf);
299 static ssize_t store_in_max(struct device *dev, struct device_attribute
300 *devattr, const char *buf, size_t count);
301 static ssize_t show_in_beep(struct device *dev, struct device_attribute
302 *devattr, char *buf);
303 static ssize_t store_in_beep(struct device *dev, struct device_attribute
304 *devattr, const char *buf, size_t count);
305 static ssize_t show_in_alarm(struct device *dev, struct device_attribute
306 *devattr, char *buf);
308 static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
310 static ssize_t show_fan_full_speed(struct device *dev,
311 struct device_attribute *devattr, char *buf);
312 static ssize_t store_fan_full_speed(struct device *dev,
313 struct device_attribute *devattr, const char *buf, size_t count);
314 static ssize_t show_fan_beep(struct device *dev, struct device_attribute
315 *devattr, char *buf);
316 static ssize_t store_fan_beep(struct device *dev, struct device_attribute
317 *devattr, const char *buf, size_t count);
318 static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
319 *devattr, char *buf);
321 static ssize_t show_temp(struct device *dev, struct device_attribute
322 *devattr, char *buf);
323 static ssize_t show_temp_max(struct device *dev, struct device_attribute
324 *devattr, char *buf);
325 static ssize_t store_temp_max(struct device *dev, struct device_attribute
326 *devattr, const char *buf, size_t count);
327 static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
328 *devattr, char *buf);
329 static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
330 *devattr, const char *buf, size_t count);
331 static ssize_t show_temp_crit(struct device *dev, struct device_attribute
332 *devattr, char *buf);
333 static ssize_t store_temp_crit(struct device *dev, struct device_attribute
334 *devattr, const char *buf, size_t count);
335 static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
336 *devattr, char *buf);
337 static ssize_t show_temp_type(struct device *dev, struct device_attribute
338 *devattr, char *buf);
339 static ssize_t show_temp_beep(struct device *dev, struct device_attribute
340 *devattr, char *buf);
341 static ssize_t store_temp_beep(struct device *dev, struct device_attribute
342 *devattr, const char *buf, size_t count);
343 static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
344 *devattr, char *buf);
345 static ssize_t show_temp_fault(struct device *dev, struct device_attribute
346 *devattr, char *buf);
347 /* PWM and Auto point control */
348 static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
350 static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr,
351 const char *buf, size_t count);
352 static ssize_t show_simple_pwm(struct device *dev,
353 struct device_attribute *devattr, char *buf);
354 static ssize_t store_simple_pwm(struct device *dev,
355 struct device_attribute *devattr, const char *buf, size_t count);
356 static ssize_t show_pwm_enable(struct device *dev,
357 struct device_attribute *devattr, char *buf);
358 static ssize_t store_pwm_enable(struct device *dev,
359 struct device_attribute *devattr, const char *buf, size_t count);
360 static ssize_t show_pwm_interpolate(struct device *dev,
361 struct device_attribute *devattr, char *buf);
362 static ssize_t store_pwm_interpolate(struct device *dev,
363 struct device_attribute *devattr, const char *buf, size_t count);
364 static ssize_t show_pwm_auto_point_channel(struct device *dev,
365 struct device_attribute *devattr, char *buf);
366 static ssize_t store_pwm_auto_point_channel(struct device *dev,
367 struct device_attribute *devattr, const char *buf, size_t count);
368 static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
369 struct device_attribute *devattr, char *buf);
370 static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
371 struct device_attribute *devattr, const char *buf, size_t count);
372 static ssize_t show_pwm_auto_point_pwm(struct device *dev,
373 struct device_attribute *devattr, char *buf);
374 static ssize_t store_pwm_auto_point_pwm(struct device *dev,
375 struct device_attribute *devattr, const char *buf, size_t count);
376 static ssize_t show_pwm_auto_point_temp(struct device *dev,
377 struct device_attribute *devattr, char *buf);
378 static ssize_t store_pwm_auto_point_temp(struct device *dev,
379 struct device_attribute *devattr, const char *buf, size_t count);
381 static ssize_t name_show(struct device *dev, struct device_attribute *devattr,
384 static int f71882fg_probe(struct platform_device *pdev);
385 static int f71882fg_remove(struct platform_device *pdev);
387 static struct platform_driver f71882fg_driver = {
391 .probe = f71882fg_probe,
392 .remove = f71882fg_remove,
395 static DEVICE_ATTR_RO(name);
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)
401 static struct sensor_device_attribute_2 f71858fg_temp_attr[] = {
402 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,
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,
424 SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
425 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,
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),
440 /* Temp attr for the standard models */
441 static struct sensor_device_attribute_2 fxxxx_temp_attr[3][9] = { {
442 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 1),
443 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
444 store_temp_max, 0, 1),
445 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
446 store_temp_max_hyst, 0, 1),
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.
452 SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
453 SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
454 store_temp_crit, 0, 1),
455 SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
457 SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
458 SENSOR_ATTR_2(temp1_type, S_IRUGO, show_temp_type, NULL, 0, 1),
459 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
461 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,
463 store_temp_max, 0, 2),
464 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
465 store_temp_max_hyst, 0, 2),
466 /* Should be temp2_max_alarm, see temp1_alarm note */
467 SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
468 SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
469 store_temp_crit, 0, 2),
470 SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
472 SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
473 SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 2),
474 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
476 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),
481 /* Should be temp3_max_alarm, see temp1_alarm note */
482 SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 3),
483 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,
487 SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 7),
488 SENSOR_ATTR_2(temp3_type, S_IRUGO, show_temp_type, NULL, 0, 3),
489 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 3),
492 /* Temp attr for models which can beep on temp alarm */
493 static 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),
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),
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),
510 static 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),
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),
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),
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
533 static struct sensor_device_attribute_2 f8000_temp_attr[] = {
534 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),
540 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0),
541 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),
547 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
548 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),
554 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
557 /* in attr for all models */
558 static 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),
568 SENSOR_ATTR_2(in9_input, S_IRUGO, show_in, NULL, 0, 9),
569 SENSOR_ATTR_2(in10_input, S_IRUGO, show_in, NULL, 0, 10),
572 /* For models with in1 alarm capability */
573 static 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,
576 SENSOR_ATTR_2(in1_beep, S_IRUGO|S_IWUSR, show_in_beep, store_in_beep,
578 SENSOR_ATTR_2(in1_alarm, S_IRUGO, show_in_alarm, NULL, 0, 1),
581 /* Fan / PWM attr common to all models */
582 static struct sensor_device_attribute_2 fxxxx_fan_attr[4][6] = { {
583 SENSOR_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0),
584 SENSOR_ATTR_2(fan1_full_speed, S_IRUGO|S_IWUSR,
586 store_fan_full_speed, 0, 0),
587 SENSOR_ATTR_2(fan1_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 0),
588 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),
594 SENSOR_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 0, 1),
595 SENSOR_ATTR_2(fan2_full_speed, S_IRUGO|S_IWUSR,
597 store_fan_full_speed, 0, 1),
598 SENSOR_ATTR_2(fan2_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 1),
599 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),
605 SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
606 SENSOR_ATTR_2(fan3_full_speed, S_IRUGO|S_IWUSR,
608 store_fan_full_speed, 0, 2),
609 SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
610 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),
613 SENSOR_ATTR_2(pwm3_interpolate, S_IRUGO|S_IWUSR,
614 show_pwm_interpolate, store_pwm_interpolate, 0, 2),
616 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
617 SENSOR_ATTR_2(fan4_full_speed, S_IRUGO|S_IWUSR,
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),
628 /* Attr for the third fan of the f71808a, which only has manual pwm */
629 static 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),
636 /* Attr for models which can beep on Fan alarm */
637 static struct sensor_device_attribute_2 fxxxx_fan_beep_attr[] = {
638 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),
644 SENSOR_ATTR_2(fan4_beep, S_IRUGO|S_IWUSR, show_fan_beep,
645 store_fan_beep, 0, 3),
649 * PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
652 static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr[3][7] = { {
653 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),
656 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
657 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
659 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
660 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
662 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
663 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
665 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
666 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
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,
672 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
673 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
675 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),
678 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
679 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
681 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
682 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
684 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
685 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
687 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
688 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
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,
694 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
695 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
697 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),
700 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
701 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
703 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
704 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
706 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
707 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
709 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
710 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
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,
716 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
717 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
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
725 static struct sensor_device_attribute_2 f71869_auto_pwm_attr[3][8] = { {
726 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,
732 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
733 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
735 SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO|S_IWUSR,
736 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
738 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
739 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
741 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
742 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
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,
748 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
749 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
751 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,
757 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
758 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
760 SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO|S_IWUSR,
761 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
763 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
764 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
766 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
767 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
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,
773 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
774 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
776 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,
782 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
783 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
785 SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO|S_IWUSR,
786 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
788 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
789 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
791 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
792 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
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,
798 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
799 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
802 /* PWM attr for the standard models */
803 static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr[4][14] = { {
804 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),
807 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
808 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
810 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
811 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
813 SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO|S_IWUSR,
814 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
816 SENSOR_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO|S_IWUSR,
817 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
819 SENSOR_ATTR_2(pwm1_auto_point5_pwm, S_IRUGO|S_IWUSR,
820 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
822 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
823 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
825 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
826 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
828 SENSOR_ATTR_2(pwm1_auto_point3_temp, S_IRUGO|S_IWUSR,
829 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
831 SENSOR_ATTR_2(pwm1_auto_point4_temp, S_IRUGO|S_IWUSR,
832 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
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,
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),
845 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),
848 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
849 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
851 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
852 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
854 SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO|S_IWUSR,
855 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
857 SENSOR_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO|S_IWUSR,
858 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
860 SENSOR_ATTR_2(pwm2_auto_point5_pwm, S_IRUGO|S_IWUSR,
861 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
863 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
864 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
866 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
867 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
869 SENSOR_ATTR_2(pwm2_auto_point3_temp, S_IRUGO|S_IWUSR,
870 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
872 SENSOR_ATTR_2(pwm2_auto_point4_temp, S_IRUGO|S_IWUSR,
873 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
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,
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),
886 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),
889 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
890 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
892 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
893 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
895 SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO|S_IWUSR,
896 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
898 SENSOR_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO|S_IWUSR,
899 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
901 SENSOR_ATTR_2(pwm3_auto_point5_pwm, S_IRUGO|S_IWUSR,
902 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
904 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
905 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
907 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
908 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
910 SENSOR_ATTR_2(pwm3_auto_point3_temp, S_IRUGO|S_IWUSR,
911 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
913 SENSOR_ATTR_2(pwm3_auto_point4_temp, S_IRUGO|S_IWUSR,
914 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
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,
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),
927 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,
933 SENSOR_ATTR_2(pwm4_auto_point2_pwm, S_IRUGO|S_IWUSR,
934 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
936 SENSOR_ATTR_2(pwm4_auto_point3_pwm, S_IRUGO|S_IWUSR,
937 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
939 SENSOR_ATTR_2(pwm4_auto_point4_pwm, S_IRUGO|S_IWUSR,
940 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
942 SENSOR_ATTR_2(pwm4_auto_point5_pwm, S_IRUGO|S_IWUSR,
943 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
945 SENSOR_ATTR_2(pwm4_auto_point1_temp, S_IRUGO|S_IWUSR,
946 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
948 SENSOR_ATTR_2(pwm4_auto_point2_temp, S_IRUGO|S_IWUSR,
949 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
951 SENSOR_ATTR_2(pwm4_auto_point3_temp, S_IRUGO|S_IWUSR,
952 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
954 SENSOR_ATTR_2(pwm4_auto_point4_temp, S_IRUGO|S_IWUSR,
955 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
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,
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),
969 /* Fan attr specific to the f8000 (4th fan input can only measure speed) */
970 static struct sensor_device_attribute_2 f8000_fan_attr[] = {
971 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
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
979 static struct sensor_device_attribute_2 f8000_auto_pwm_attr[3][14] = { {
980 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),
983 SENSOR_ATTR_2(temp1_auto_point1_pwm, S_IRUGO|S_IWUSR,
984 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
986 SENSOR_ATTR_2(temp1_auto_point2_pwm, S_IRUGO|S_IWUSR,
987 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
989 SENSOR_ATTR_2(temp1_auto_point3_pwm, S_IRUGO|S_IWUSR,
990 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
992 SENSOR_ATTR_2(temp1_auto_point4_pwm, S_IRUGO|S_IWUSR,
993 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
995 SENSOR_ATTR_2(temp1_auto_point5_pwm, S_IRUGO|S_IWUSR,
996 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
998 SENSOR_ATTR_2(temp1_auto_point1_temp, S_IRUGO|S_IWUSR,
999 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1001 SENSOR_ATTR_2(temp1_auto_point2_temp, S_IRUGO|S_IWUSR,
1002 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1004 SENSOR_ATTR_2(temp1_auto_point3_temp, S_IRUGO|S_IWUSR,
1005 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1007 SENSOR_ATTR_2(temp1_auto_point4_temp, S_IRUGO|S_IWUSR,
1008 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
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,
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),
1021 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),
1024 SENSOR_ATTR_2(temp2_auto_point1_pwm, S_IRUGO|S_IWUSR,
1025 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1027 SENSOR_ATTR_2(temp2_auto_point2_pwm, S_IRUGO|S_IWUSR,
1028 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1030 SENSOR_ATTR_2(temp2_auto_point3_pwm, S_IRUGO|S_IWUSR,
1031 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1033 SENSOR_ATTR_2(temp2_auto_point4_pwm, S_IRUGO|S_IWUSR,
1034 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1036 SENSOR_ATTR_2(temp2_auto_point5_pwm, S_IRUGO|S_IWUSR,
1037 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1039 SENSOR_ATTR_2(temp2_auto_point1_temp, S_IRUGO|S_IWUSR,
1040 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1042 SENSOR_ATTR_2(temp2_auto_point2_temp, S_IRUGO|S_IWUSR,
1043 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1045 SENSOR_ATTR_2(temp2_auto_point3_temp, S_IRUGO|S_IWUSR,
1046 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1048 SENSOR_ATTR_2(temp2_auto_point4_temp, S_IRUGO|S_IWUSR,
1049 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
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,
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),
1062 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),
1065 SENSOR_ATTR_2(temp3_auto_point1_pwm, S_IRUGO|S_IWUSR,
1066 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1068 SENSOR_ATTR_2(temp3_auto_point2_pwm, S_IRUGO|S_IWUSR,
1069 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1071 SENSOR_ATTR_2(temp3_auto_point3_pwm, S_IRUGO|S_IWUSR,
1072 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1074 SENSOR_ATTR_2(temp3_auto_point4_pwm, S_IRUGO|S_IWUSR,
1075 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1077 SENSOR_ATTR_2(temp3_auto_point5_pwm, S_IRUGO|S_IWUSR,
1078 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
1080 SENSOR_ATTR_2(temp3_auto_point1_temp, S_IRUGO|S_IWUSR,
1081 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1083 SENSOR_ATTR_2(temp3_auto_point2_temp, S_IRUGO|S_IWUSR,
1084 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1086 SENSOR_ATTR_2(temp3_auto_point3_temp, S_IRUGO|S_IWUSR,
1087 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
1089 SENSOR_ATTR_2(temp3_auto_point4_temp, S_IRUGO|S_IWUSR,
1090 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
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,
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),
1104 /* Super I/O functions */
1105 static inline int superio_inb(int base, int reg)
1108 return inb(base + 1);
1111 static int superio_inw(int base, int reg)
1114 val = superio_inb(base, reg) << 8;
1115 val |= superio_inb(base, reg + 1);
1119 static inline int superio_enter(int base)
1121 /* Don't step on other drivers' I/O space by accident */
1122 if (!request_muxed_region(base, 2, DRVNAME)) {
1123 pr_err("I/O address 0x%04x already in use\n", base);
1127 /* according to the datasheet the key must be send twice! */
1128 outb(SIO_UNLOCK_KEY, base);
1129 outb(SIO_UNLOCK_KEY, base);
1134 static inline void superio_select(int base, int ld)
1136 outb(SIO_REG_LDSEL, base);
1140 static inline void superio_exit(int base)
1142 outb(SIO_LOCK_KEY, base);
1143 release_region(base, 2);
1146 static inline int fan_from_reg(u16 reg)
1148 return reg ? (1500000 / reg) : 0;
1151 static inline u16 fan_to_reg(int fan)
1153 return fan ? (1500000 / fan) : 0;
1156 static u8 f71882fg_read8(struct f71882fg_data *data, u8 reg)
1160 outb(reg, data->addr + ADDR_REG_OFFSET);
1161 val = inb(data->addr + DATA_REG_OFFSET);
1166 static u16 f71882fg_read16(struct f71882fg_data *data, u8 reg)
1170 val = f71882fg_read8(data, reg) << 8;
1171 val |= f71882fg_read8(data, reg + 1);
1176 static void f71882fg_write8(struct f71882fg_data *data, u8 reg, u8 val)
1178 outb(reg, data->addr + ADDR_REG_OFFSET);
1179 outb(val, data->addr + DATA_REG_OFFSET);
1182 static void f71882fg_write16(struct f71882fg_data *data, u8 reg, u16 val)
1184 f71882fg_write8(data, reg, val >> 8);
1185 f71882fg_write8(data, reg + 1, val & 0xff);
1188 static u16 f71882fg_read_temp(struct f71882fg_data *data, int nr)
1190 if (data->type == f71858fg)
1191 return f71882fg_read16(data, F71882FG_REG_TEMP(nr));
1193 return f71882fg_read8(data, F71882FG_REG_TEMP(nr));
1196 static struct f71882fg_data *f71882fg_update_device(struct device *dev)
1198 struct f71882fg_data *data = dev_get_drvdata(dev);
1199 int nr_fans = f71882fg_nr_fans[data->type];
1200 int nr_temps = f71882fg_nr_temps[data->type];
1203 mutex_lock(&data->update_lock);
1205 /* Update once every 60 seconds */
1206 if (time_after(jiffies, data->last_limits + 60 * HZ) ||
1208 if (f71882fg_has_in1_alarm[data->type]) {
1209 if (data->type == f81866a) {
1211 f71882fg_read8(data,
1212 F81866_REG_IN1_HIGH);
1214 f71882fg_read8(data,
1215 F81866_REG_IN_BEEP);
1218 f71882fg_read8(data,
1219 F71882FG_REG_IN1_HIGH);
1221 f71882fg_read8(data,
1222 F71882FG_REG_IN_BEEP);
1226 /* Get High & boundary temps*/
1227 for (nr = data->temp_start; nr < nr_temps + data->temp_start;
1229 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));
1235 if (data->type != f8000) {
1236 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));
1241 /* All but the f71858fg / f8000 have this register */
1242 if ((data->type != f71858fg) && (data->type != f8000)) {
1243 reg = f71882fg_read8(data, F71882FG_REG_TEMP_TYPE);
1244 data->temp_type[1] = (reg & 0x02) ? 2 : 4;
1245 data->temp_type[2] = (reg & 0x04) ? 2 : 4;
1246 data->temp_type[3] = (reg & 0x08) ? 2 : 4;
1249 if (f71882fg_fan_has_beep[data->type])
1250 data->fan_beep = f71882fg_read8(data,
1251 F71882FG_REG_FAN_BEEP);
1253 if (f71882fg_temp_has_beep[data->type])
1254 data->temp_beep = f71882fg_read8(data,
1255 F71882FG_REG_TEMP_BEEP);
1257 data->pwm_enable = f71882fg_read8(data,
1258 F71882FG_REG_PWM_ENABLE);
1259 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));
1264 for (nr = 0; nr < nr_fans; nr++) {
1265 data->pwm_auto_point_mapping[nr] =
1266 f71882fg_read8(data,
1267 F71882FG_REG_POINT_MAPPING(nr));
1269 switch (data->type) {
1271 for (point = 0; point < 5; point++) {
1272 data->pwm_auto_point_pwm[nr][point] =
1273 f71882fg_read8(data,
1274 F71882FG_REG_POINT_PWM
1277 for (point = 0; point < 4; point++) {
1278 data->pwm_auto_point_temp[nr][point] =
1279 f71882fg_read8(data,
1280 F71882FG_REG_POINT_TEMP
1286 data->pwm_auto_point_pwm[nr][0] =
1287 f71882fg_read8(data,
1288 F71882FG_REG_POINT_PWM(nr, 0));
1291 data->pwm_auto_point_pwm[nr][1] =
1292 f71882fg_read8(data,
1293 F71882FG_REG_POINT_PWM
1295 data->pwm_auto_point_pwm[nr][4] =
1296 f71882fg_read8(data,
1297 F71882FG_REG_POINT_PWM
1299 data->pwm_auto_point_temp[nr][0] =
1300 f71882fg_read8(data,
1301 F71882FG_REG_POINT_TEMP
1303 data->pwm_auto_point_temp[nr][3] =
1304 f71882fg_read8(data,
1305 F71882FG_REG_POINT_TEMP
1310 data->last_limits = jiffies;
1313 /* Update every second */
1314 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
1315 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);
1319 for (nr = data->temp_start; nr < nr_temps + data->temp_start;
1321 data->temp[nr] = f71882fg_read_temp(data, nr);
1323 data->fan_status = f71882fg_read8(data,
1324 F71882FG_REG_FAN_STATUS);
1325 for (nr = 0; nr < nr_fans; nr++) {
1326 data->fan[nr] = f71882fg_read16(data,
1327 F71882FG_REG_FAN(nr));
1328 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));
1334 f71882fg_read8(data, F71882FG_REG_PWM(nr));
1336 /* 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));
1343 if (data->type == f8000)
1344 data->fan[3] = f71882fg_read16(data,
1345 F71882FG_REG_FAN(3));
1347 if (f71882fg_has_in1_alarm[data->type]) {
1348 if (data->type == f81866a)
1349 data->in_status = f71882fg_read8(data,
1350 F81866_REG_IN_STATUS);
1353 data->in_status = f71882fg_read8(data,
1354 F71882FG_REG_IN_STATUS);
1357 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));
1362 data->last_updated = jiffies;
1366 mutex_unlock(&data->update_lock);
1371 /* Sysfs Interface */
1372 static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
1375 struct f71882fg_data *data = f71882fg_update_device(dev);
1376 int nr = to_sensor_dev_attr_2(devattr)->index;
1377 int speed = fan_from_reg(data->fan[nr]);
1379 if (speed == FAN_MIN_DETECT)
1382 return sprintf(buf, "%d\n", speed);
1385 static ssize_t show_fan_full_speed(struct device *dev,
1386 struct device_attribute *devattr, char *buf)
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);
1394 static ssize_t store_fan_full_speed(struct device *dev,
1395 struct device_attribute *devattr,
1396 const char *buf, size_t count)
1398 struct f71882fg_data *data = dev_get_drvdata(dev);
1399 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1402 err = kstrtol(buf, 10, &val);
1406 val = clamp_val(val, 23, 1500000);
1407 val = fan_to_reg(val);
1409 mutex_lock(&data->update_lock);
1410 f71882fg_write16(data, F71882FG_REG_FAN_FULL_SPEED(nr), val);
1411 data->fan_full_speed[nr] = val;
1412 mutex_unlock(&data->update_lock);
1417 static ssize_t show_fan_beep(struct device *dev, struct device_attribute
1418 *devattr, char *buf)
1420 struct f71882fg_data *data = f71882fg_update_device(dev);
1421 int nr = to_sensor_dev_attr_2(devattr)->index;
1423 if (data->fan_beep & (1 << nr))
1424 return sprintf(buf, "1\n");
1426 return sprintf(buf, "0\n");
1429 static ssize_t store_fan_beep(struct device *dev, struct device_attribute
1430 *devattr, const char *buf, size_t count)
1432 struct f71882fg_data *data = dev_get_drvdata(dev);
1433 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1436 err = kstrtoul(buf, 10, &val);
1440 mutex_lock(&data->update_lock);
1441 data->fan_beep = f71882fg_read8(data, F71882FG_REG_FAN_BEEP);
1443 data->fan_beep |= 1 << nr;
1445 data->fan_beep &= ~(1 << nr);
1447 f71882fg_write8(data, F71882FG_REG_FAN_BEEP, data->fan_beep);
1448 mutex_unlock(&data->update_lock);
1453 static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
1454 *devattr, char *buf)
1456 struct f71882fg_data *data = f71882fg_update_device(dev);
1457 int nr = to_sensor_dev_attr_2(devattr)->index;
1459 if (data->fan_status & (1 << nr))
1460 return sprintf(buf, "1\n");
1462 return sprintf(buf, "0\n");
1465 static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
1468 struct f71882fg_data *data = f71882fg_update_device(dev);
1469 int nr = to_sensor_dev_attr_2(devattr)->index;
1471 return sprintf(buf, "%d\n", data->in[nr] * 8);
1474 static ssize_t show_in_max(struct device *dev, struct device_attribute
1475 *devattr, char *buf)
1477 struct f71882fg_data *data = f71882fg_update_device(dev);
1479 return sprintf(buf, "%d\n", data->in1_max * 8);
1482 static ssize_t store_in_max(struct device *dev, struct device_attribute
1483 *devattr, const char *buf, size_t count)
1485 struct f71882fg_data *data = dev_get_drvdata(dev);
1489 err = kstrtol(buf, 10, &val);
1494 val = clamp_val(val, 0, 255);
1496 mutex_lock(&data->update_lock);
1497 if (data->type == f81866a)
1498 f71882fg_write8(data, F81866_REG_IN1_HIGH, val);
1500 f71882fg_write8(data, F71882FG_REG_IN1_HIGH, val);
1501 data->in1_max = val;
1502 mutex_unlock(&data->update_lock);
1507 static ssize_t show_in_beep(struct device *dev, struct device_attribute
1508 *devattr, char *buf)
1510 struct f71882fg_data *data = f71882fg_update_device(dev);
1511 int nr = to_sensor_dev_attr_2(devattr)->index;
1513 if (data->in_beep & (1 << nr))
1514 return sprintf(buf, "1\n");
1516 return sprintf(buf, "0\n");
1519 static ssize_t store_in_beep(struct device *dev, struct device_attribute
1520 *devattr, const char *buf, size_t count)
1522 struct f71882fg_data *data = dev_get_drvdata(dev);
1523 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1526 err = kstrtoul(buf, 10, &val);
1530 mutex_lock(&data->update_lock);
1531 if (data->type == f81866a)
1532 data->in_beep = f71882fg_read8(data, F81866_REG_IN_BEEP);
1534 data->in_beep = f71882fg_read8(data, F71882FG_REG_IN_BEEP);
1537 data->in_beep |= 1 << nr;
1539 data->in_beep &= ~(1 << nr);
1541 if (data->type == f81866a)
1542 f71882fg_write8(data, F81866_REG_IN_BEEP, data->in_beep);
1544 f71882fg_write8(data, F71882FG_REG_IN_BEEP, data->in_beep);
1545 mutex_unlock(&data->update_lock);
1550 static ssize_t show_in_alarm(struct device *dev, struct device_attribute
1551 *devattr, char *buf)
1553 struct f71882fg_data *data = f71882fg_update_device(dev);
1554 int nr = to_sensor_dev_attr_2(devattr)->index;
1556 if (data->in_status & (1 << nr))
1557 return sprintf(buf, "1\n");
1559 return sprintf(buf, "0\n");
1562 static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
1565 struct f71882fg_data *data = f71882fg_update_device(dev);
1566 int nr = to_sensor_dev_attr_2(devattr)->index;
1569 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;
1575 sign = data->temp[nr] & 0x8000;
1576 temp = (data->temp[nr] >> 5) & 0x3ff;
1582 temp = ((s8)data->temp[nr]) * 1000;
1585 return sprintf(buf, "%d\n", temp);
1588 static ssize_t show_temp_max(struct device *dev, struct device_attribute
1589 *devattr, char *buf)
1591 struct f71882fg_data *data = f71882fg_update_device(dev);
1592 int nr = to_sensor_dev_attr_2(devattr)->index;
1594 return sprintf(buf, "%d\n", data->temp_high[nr] * 1000);
1597 static ssize_t store_temp_max(struct device *dev, struct device_attribute
1598 *devattr, const char *buf, size_t count)
1600 struct f71882fg_data *data = dev_get_drvdata(dev);
1601 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1604 err = kstrtol(buf, 10, &val);
1609 val = clamp_val(val, 0, 255);
1611 mutex_lock(&data->update_lock);
1612 f71882fg_write8(data, F71882FG_REG_TEMP_HIGH(nr), val);
1613 data->temp_high[nr] = val;
1614 mutex_unlock(&data->update_lock);
1619 static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
1620 *devattr, char *buf)
1622 struct f71882fg_data *data = f71882fg_update_device(dev);
1623 int nr = to_sensor_dev_attr_2(devattr)->index;
1626 mutex_lock(&data->update_lock);
1628 temp_max_hyst = data->temp_hyst[nr / 2] >> 4;
1630 temp_max_hyst = data->temp_hyst[nr / 2] & 0x0f;
1631 temp_max_hyst = (data->temp_high[nr] - temp_max_hyst) * 1000;
1632 mutex_unlock(&data->update_lock);
1634 return sprintf(buf, "%d\n", temp_max_hyst);
1637 static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
1638 *devattr, const char *buf, size_t count)
1640 struct f71882fg_data *data = dev_get_drvdata(dev);
1641 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1642 ssize_t ret = count;
1646 err = kstrtol(buf, 10, &val);
1652 mutex_lock(&data->update_lock);
1654 /* convert abs to relative and check */
1655 data->temp_high[nr] = f71882fg_read8(data, F71882FG_REG_TEMP_HIGH(nr));
1656 val = clamp_val(val, data->temp_high[nr] - 15, data->temp_high[nr]);
1657 val = data->temp_high[nr] - val;
1659 /* convert value to register contents */
1660 reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST(nr / 2));
1662 reg = (reg & 0x0f) | (val << 4);
1664 reg = (reg & 0xf0) | val;
1665 f71882fg_write8(data, F71882FG_REG_TEMP_HYST(nr / 2), reg);
1666 data->temp_hyst[nr / 2] = reg;
1668 mutex_unlock(&data->update_lock);
1672 static ssize_t show_temp_crit(struct device *dev, struct device_attribute
1673 *devattr, char *buf)
1675 struct f71882fg_data *data = f71882fg_update_device(dev);
1676 int nr = to_sensor_dev_attr_2(devattr)->index;
1678 return sprintf(buf, "%d\n", data->temp_ovt[nr] * 1000);
1681 static ssize_t store_temp_crit(struct device *dev, struct device_attribute
1682 *devattr, const char *buf, size_t count)
1684 struct f71882fg_data *data = dev_get_drvdata(dev);
1685 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1688 err = kstrtol(buf, 10, &val);
1693 val = clamp_val(val, 0, 255);
1695 mutex_lock(&data->update_lock);
1696 f71882fg_write8(data, F71882FG_REG_TEMP_OVT(nr), val);
1697 data->temp_ovt[nr] = val;
1698 mutex_unlock(&data->update_lock);
1703 static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
1704 *devattr, char *buf)
1706 struct f71882fg_data *data = f71882fg_update_device(dev);
1707 int nr = to_sensor_dev_attr_2(devattr)->index;
1710 mutex_lock(&data->update_lock);
1712 temp_crit_hyst = data->temp_hyst[nr / 2] >> 4;
1714 temp_crit_hyst = data->temp_hyst[nr / 2] & 0x0f;
1715 temp_crit_hyst = (data->temp_ovt[nr] - temp_crit_hyst) * 1000;
1716 mutex_unlock(&data->update_lock);
1718 return sprintf(buf, "%d\n", temp_crit_hyst);
1721 static ssize_t show_temp_type(struct device *dev, struct device_attribute
1722 *devattr, char *buf)
1724 struct f71882fg_data *data = f71882fg_update_device(dev);
1725 int nr = to_sensor_dev_attr_2(devattr)->index;
1727 return sprintf(buf, "%d\n", data->temp_type[nr]);
1730 static ssize_t show_temp_beep(struct device *dev, struct device_attribute
1731 *devattr, char *buf)
1733 struct f71882fg_data *data = f71882fg_update_device(dev);
1734 int nr = to_sensor_dev_attr_2(devattr)->index;
1736 if (data->temp_beep & (1 << nr))
1737 return sprintf(buf, "1\n");
1739 return sprintf(buf, "0\n");
1742 static ssize_t store_temp_beep(struct device *dev, struct device_attribute
1743 *devattr, const char *buf, size_t count)
1745 struct f71882fg_data *data = dev_get_drvdata(dev);
1746 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1749 err = kstrtoul(buf, 10, &val);
1753 mutex_lock(&data->update_lock);
1754 data->temp_beep = f71882fg_read8(data, F71882FG_REG_TEMP_BEEP);
1756 data->temp_beep |= 1 << nr;
1758 data->temp_beep &= ~(1 << nr);
1760 f71882fg_write8(data, F71882FG_REG_TEMP_BEEP, data->temp_beep);
1761 mutex_unlock(&data->update_lock);
1766 static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
1767 *devattr, char *buf)
1769 struct f71882fg_data *data = f71882fg_update_device(dev);
1770 int nr = to_sensor_dev_attr_2(devattr)->index;
1772 if (data->temp_status & (1 << nr))
1773 return sprintf(buf, "1\n");
1775 return sprintf(buf, "0\n");
1778 static ssize_t show_temp_fault(struct device *dev, struct device_attribute
1779 *devattr, char *buf)
1781 struct f71882fg_data *data = f71882fg_update_device(dev);
1782 int nr = to_sensor_dev_attr_2(devattr)->index;
1784 if (data->temp_diode_open & (1 << nr))
1785 return sprintf(buf, "1\n");
1787 return sprintf(buf, "0\n");
1790 static ssize_t show_pwm(struct device *dev,
1791 struct device_attribute *devattr, char *buf)
1793 struct f71882fg_data *data = f71882fg_update_device(dev);
1794 int val, nr = to_sensor_dev_attr_2(devattr)->index;
1795 mutex_lock(&data->update_lock);
1796 if (data->pwm_enable & (1 << (2 * nr)))
1798 val = data->pwm[nr];
1801 val = 255 * fan_from_reg(data->fan_target[nr])
1802 / fan_from_reg(data->fan_full_speed[nr]);
1804 mutex_unlock(&data->update_lock);
1805 return sprintf(buf, "%d\n", val);
1808 static ssize_t store_pwm(struct device *dev,
1809 struct device_attribute *devattr, const char *buf,
1812 struct f71882fg_data *data = dev_get_drvdata(dev);
1813 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1816 err = kstrtol(buf, 10, &val);
1820 val = clamp_val(val, 0, 255);
1822 mutex_lock(&data->update_lock);
1823 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
1824 if ((data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 3) != 2) ||
1825 (data->type != f8000 && !((data->pwm_enable >> 2 * nr) & 2))) {
1829 if (data->pwm_enable & (1 << (2 * nr))) {
1831 f71882fg_write8(data, F71882FG_REG_PWM(nr), val);
1832 data->pwm[nr] = val;
1835 int target, full_speed;
1836 full_speed = f71882fg_read16(data,
1837 F71882FG_REG_FAN_FULL_SPEED(nr));
1838 target = fan_to_reg(val * fan_from_reg(full_speed) / 255);
1839 f71882fg_write16(data, F71882FG_REG_FAN_TARGET(nr), target);
1840 data->fan_target[nr] = target;
1841 data->fan_full_speed[nr] = full_speed;
1844 mutex_unlock(&data->update_lock);
1849 static ssize_t show_simple_pwm(struct device *dev,
1850 struct device_attribute *devattr, char *buf)
1852 struct f71882fg_data *data = f71882fg_update_device(dev);
1853 int val, nr = to_sensor_dev_attr_2(devattr)->index;
1855 val = data->pwm[nr];
1856 return sprintf(buf, "%d\n", val);
1859 static ssize_t store_simple_pwm(struct device *dev,
1860 struct device_attribute *devattr,
1861 const char *buf, size_t count)
1863 struct f71882fg_data *data = dev_get_drvdata(dev);
1864 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1867 err = kstrtol(buf, 10, &val);
1871 val = clamp_val(val, 0, 255);
1873 mutex_lock(&data->update_lock);
1874 f71882fg_write8(data, F71882FG_REG_PWM(nr), val);
1875 data->pwm[nr] = val;
1876 mutex_unlock(&data->update_lock);
1881 static ssize_t show_pwm_enable(struct device *dev,
1882 struct device_attribute *devattr, char *buf)
1885 struct f71882fg_data *data = f71882fg_update_device(dev);
1886 int nr = to_sensor_dev_attr_2(devattr)->index;
1888 switch ((data->pwm_enable >> 2 * nr) & 3) {
1891 result = 2; /* Normal auto mode */
1894 result = 1; /* Manual mode */
1897 if (data->type == f8000)
1898 result = 3; /* Thermostat mode */
1900 result = 1; /* Manual mode */
1904 return sprintf(buf, "%d\n", result);
1907 static ssize_t store_pwm_enable(struct device *dev, struct device_attribute
1908 *devattr, const char *buf, size_t count)
1910 struct f71882fg_data *data = dev_get_drvdata(dev);
1911 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1914 err = kstrtol(buf, 10, &val);
1918 /* Special case for F8000 pwm channel 3 which only does auto mode */
1919 if (data->type == f8000 && nr == 2 && val != 2)
1922 mutex_lock(&data->update_lock);
1923 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
1924 /* Special case for F8000 auto PWM mode / Thermostat mode */
1925 if (data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 1)) {
1928 data->pwm_enable &= ~(2 << (2 * nr));
1929 break; /* Normal auto mode */
1931 data->pwm_enable |= 2 << (2 * nr);
1932 break; /* Thermostat mode */
1940 /* The f71858fg does not support manual RPM mode */
1941 if (data->type == f71858fg &&
1942 ((data->pwm_enable >> (2 * nr)) & 1)) {
1946 data->pwm_enable |= 2 << (2 * nr);
1949 data->pwm_enable &= ~(2 << (2 * nr));
1950 break; /* Normal auto mode */
1956 f71882fg_write8(data, F71882FG_REG_PWM_ENABLE, data->pwm_enable);
1958 mutex_unlock(&data->update_lock);
1963 static ssize_t show_pwm_auto_point_pwm(struct device *dev,
1964 struct device_attribute *devattr,
1968 struct f71882fg_data *data = f71882fg_update_device(dev);
1969 int pwm = to_sensor_dev_attr_2(devattr)->index;
1970 int point = to_sensor_dev_attr_2(devattr)->nr;
1972 mutex_lock(&data->update_lock);
1973 if (data->pwm_enable & (1 << (2 * pwm))) {
1975 result = data->pwm_auto_point_pwm[pwm][point];
1978 result = 32 * 255 / (32 + data->pwm_auto_point_pwm[pwm][point]);
1980 mutex_unlock(&data->update_lock);
1982 return sprintf(buf, "%d\n", result);
1985 static ssize_t store_pwm_auto_point_pwm(struct device *dev,
1986 struct device_attribute *devattr,
1987 const char *buf, size_t count)
1989 struct f71882fg_data *data = dev_get_drvdata(dev);
1990 int err, pwm = to_sensor_dev_attr_2(devattr)->index;
1991 int point = to_sensor_dev_attr_2(devattr)->nr;
1994 err = kstrtol(buf, 10, &val);
1998 val = clamp_val(val, 0, 255);
2000 mutex_lock(&data->update_lock);
2001 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
2002 if (data->pwm_enable & (1 << (2 * pwm))) {
2006 if (val < 29) /* Prevent negative numbers */
2009 val = (255 - val) * 32 / val;
2011 f71882fg_write8(data, F71882FG_REG_POINT_PWM(pwm, point), val);
2012 data->pwm_auto_point_pwm[pwm][point] = val;
2013 mutex_unlock(&data->update_lock);
2018 static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
2019 struct device_attribute *devattr,
2023 struct f71882fg_data *data = f71882fg_update_device(dev);
2024 int nr = to_sensor_dev_attr_2(devattr)->index;
2025 int point = to_sensor_dev_attr_2(devattr)->nr;
2027 mutex_lock(&data->update_lock);
2029 result = data->pwm_auto_point_hyst[nr / 2] >> 4;
2031 result = data->pwm_auto_point_hyst[nr / 2] & 0x0f;
2032 result = 1000 * (data->pwm_auto_point_temp[nr][point] - result);
2033 mutex_unlock(&data->update_lock);
2035 return sprintf(buf, "%d\n", result);
2038 static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
2039 struct device_attribute *devattr,
2040 const char *buf, size_t count)
2042 struct f71882fg_data *data = dev_get_drvdata(dev);
2043 int err, nr = to_sensor_dev_attr_2(devattr)->index;
2044 int point = to_sensor_dev_attr_2(devattr)->nr;
2048 err = kstrtol(buf, 10, &val);
2054 mutex_lock(&data->update_lock);
2055 data->pwm_auto_point_temp[nr][point] =
2056 f71882fg_read8(data, F71882FG_REG_POINT_TEMP(nr, point));
2057 val = clamp_val(val, data->pwm_auto_point_temp[nr][point] - 15,
2058 data->pwm_auto_point_temp[nr][point]);
2059 val = data->pwm_auto_point_temp[nr][point] - val;
2061 reg = f71882fg_read8(data, F71882FG_REG_FAN_HYST(nr / 2));
2063 reg = (reg & 0x0f) | (val << 4);
2065 reg = (reg & 0xf0) | val;
2067 f71882fg_write8(data, F71882FG_REG_FAN_HYST(nr / 2), reg);
2068 data->pwm_auto_point_hyst[nr / 2] = reg;
2069 mutex_unlock(&data->update_lock);
2074 static ssize_t show_pwm_interpolate(struct device *dev,
2075 struct device_attribute *devattr, char *buf)
2078 struct f71882fg_data *data = f71882fg_update_device(dev);
2079 int nr = to_sensor_dev_attr_2(devattr)->index;
2081 result = (data->pwm_auto_point_mapping[nr] >> 4) & 1;
2083 return sprintf(buf, "%d\n", result);
2086 static ssize_t store_pwm_interpolate(struct device *dev,
2087 struct device_attribute *devattr,
2088 const char *buf, size_t count)
2090 struct f71882fg_data *data = dev_get_drvdata(dev);
2091 int err, nr = to_sensor_dev_attr_2(devattr)->index;
2094 err = kstrtoul(buf, 10, &val);
2098 mutex_lock(&data->update_lock);
2099 data->pwm_auto_point_mapping[nr] =
2100 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
2102 val = data->pwm_auto_point_mapping[nr] | (1 << 4);
2104 val = data->pwm_auto_point_mapping[nr] & (~(1 << 4));
2105 f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val);
2106 data->pwm_auto_point_mapping[nr] = val;
2107 mutex_unlock(&data->update_lock);
2112 static ssize_t show_pwm_auto_point_channel(struct device *dev,
2113 struct device_attribute *devattr,
2117 struct f71882fg_data *data = f71882fg_update_device(dev);
2118 int nr = to_sensor_dev_attr_2(devattr)->index;
2120 result = 1 << ((data->pwm_auto_point_mapping[nr] & 3) -
2123 return sprintf(buf, "%d\n", result);
2126 static ssize_t store_pwm_auto_point_channel(struct device *dev,
2127 struct device_attribute *devattr,
2128 const char *buf, size_t count)
2130 struct f71882fg_data *data = dev_get_drvdata(dev);
2131 int err, nr = to_sensor_dev_attr_2(devattr)->index;
2134 err = kstrtol(buf, 10, &val);
2151 val += data->temp_start;
2152 mutex_lock(&data->update_lock);
2153 data->pwm_auto_point_mapping[nr] =
2154 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
2155 val = (data->pwm_auto_point_mapping[nr] & 0xfc) | val;
2156 f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val);
2157 data->pwm_auto_point_mapping[nr] = val;
2158 mutex_unlock(&data->update_lock);
2163 static ssize_t show_pwm_auto_point_temp(struct device *dev,
2164 struct device_attribute *devattr,
2168 struct f71882fg_data *data = f71882fg_update_device(dev);
2169 int pwm = to_sensor_dev_attr_2(devattr)->index;
2170 int point = to_sensor_dev_attr_2(devattr)->nr;
2172 result = data->pwm_auto_point_temp[pwm][point];
2173 return sprintf(buf, "%d\n", 1000 * result);
2176 static ssize_t store_pwm_auto_point_temp(struct device *dev,
2177 struct device_attribute *devattr,
2178 const char *buf, size_t count)
2180 struct f71882fg_data *data = dev_get_drvdata(dev);
2181 int err, pwm = to_sensor_dev_attr_2(devattr)->index;
2182 int point = to_sensor_dev_attr_2(devattr)->nr;
2185 err = kstrtol(buf, 10, &val);
2191 if (data->auto_point_temp_signed)
2192 val = clamp_val(val, -128, 127);
2194 val = clamp_val(val, 0, 127);
2196 mutex_lock(&data->update_lock);
2197 f71882fg_write8(data, F71882FG_REG_POINT_TEMP(pwm, point), val);
2198 data->pwm_auto_point_temp[pwm][point] = val;
2199 mutex_unlock(&data->update_lock);
2204 static ssize_t name_show(struct device *dev, struct device_attribute *devattr,
2207 struct f71882fg_data *data = dev_get_drvdata(dev);
2208 return sprintf(buf, "%s\n", f71882fg_names[data->type]);
2211 static int f71882fg_create_sysfs_files(struct platform_device *pdev,
2212 struct sensor_device_attribute_2 *attr, int count)
2216 for (i = 0; i < count; i++) {
2217 err = device_create_file(&pdev->dev, &attr[i].dev_attr);
2224 static void f71882fg_remove_sysfs_files(struct platform_device *pdev,
2225 struct sensor_device_attribute_2 *attr, int count)
2229 for (i = 0; i < count; i++)
2230 device_remove_file(&pdev->dev, &attr[i].dev_attr);
2233 static int f71882fg_create_fan_sysfs_files(
2234 struct platform_device *pdev, int idx)
2236 struct f71882fg_data *data = platform_get_drvdata(pdev);
2239 /* Sanity check the pwm setting */
2241 switch (data->type) {
2243 if (((data->pwm_enable >> (idx * 2)) & 3) == 3)
2247 if (((data->pwm_enable >> (idx * 2)) & 1) != 1)
2252 err = data->pwm_enable & 0x20;
2259 "Invalid (reserved) pwm settings: 0x%02x, "
2260 "skipping fan %d\n",
2261 (data->pwm_enable >> (idx * 2)) & 3, idx + 1);
2262 return 0; /* This is a non fatal condition */
2265 err = f71882fg_create_sysfs_files(pdev, &fxxxx_fan_attr[idx][0],
2266 ARRAY_SIZE(fxxxx_fan_attr[0]));
2270 if (f71882fg_fan_has_beep[data->type]) {
2271 err = f71882fg_create_sysfs_files(pdev,
2272 &fxxxx_fan_beep_attr[idx],
2278 dev_info(&pdev->dev, "Fan: %d is in %s mode\n", idx + 1,
2279 (data->pwm_enable & (1 << (2 * idx))) ? "duty-cycle" : "RPM");
2281 /* Check for unsupported auto pwm settings */
2282 switch (data->type) {
2290 data->pwm_auto_point_mapping[idx] =
2291 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(idx));
2292 if ((data->pwm_auto_point_mapping[idx] & 0x80) ||
2293 (data->pwm_auto_point_mapping[idx] & 3) == 0) {
2294 dev_warn(&pdev->dev,
2295 "Auto pwm controlled by raw digital "
2296 "data, disabling pwm auto_point "
2297 "sysfs attributes for fan %d\n", idx + 1);
2298 return 0; /* This is a non fatal condition */
2305 switch (data->type) {
2307 err = f71882fg_create_sysfs_files(pdev,
2308 &f71862fg_auto_pwm_attr[idx][0],
2309 ARRAY_SIZE(f71862fg_auto_pwm_attr[0]));
2313 err = f71882fg_create_sysfs_files(pdev,
2314 &f71869_auto_pwm_attr[idx][0],
2315 ARRAY_SIZE(f71869_auto_pwm_attr[0]));
2318 err = f71882fg_create_sysfs_files(pdev,
2319 &f8000_auto_pwm_attr[idx][0],
2320 ARRAY_SIZE(f8000_auto_pwm_attr[0]));
2323 err = f71882fg_create_sysfs_files(pdev,
2324 &fxxxx_auto_pwm_attr[idx][0],
2325 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]));
2331 static int f71882fg_probe(struct platform_device *pdev)
2333 struct f71882fg_data *data;
2334 struct f71882fg_sio_data *sio_data = dev_get_platdata(&pdev->dev);
2335 int nr_fans = f71882fg_nr_fans[sio_data->type];
2336 int nr_temps = f71882fg_nr_temps[sio_data->type];
2341 data = devm_kzalloc(&pdev->dev, sizeof(struct f71882fg_data),
2346 data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start;
2347 data->type = sio_data->type;
2349 (data->type == f71858fg || data->type == f8000 ||
2350 data->type == f81866a) ? 0 : 1;
2351 mutex_init(&data->update_lock);
2352 platform_set_drvdata(pdev, data);
2354 start_reg = f71882fg_read8(data, F71882FG_REG_START);
2355 if (start_reg & 0x04) {
2356 dev_warn(&pdev->dev, "Hardware monitor is powered down\n");
2359 if (!(start_reg & 0x03)) {
2360 dev_warn(&pdev->dev, "Hardware monitoring not activated\n");
2364 /* Register sysfs interface files */
2365 err = device_create_file(&pdev->dev, &dev_attr_name);
2367 goto exit_unregister_sysfs;
2369 if (start_reg & 0x01) {
2370 switch (data->type) {
2373 f71882fg_read8(data, F71882FG_REG_TEMP_CONFIG);
2374 if (data->temp_config & 0x10)
2376 * The f71858fg temperature alarms behave as
2377 * the f8000 alarms in this mode
2379 err = f71882fg_create_sysfs_files(pdev,
2381 ARRAY_SIZE(f8000_temp_attr));
2383 err = f71882fg_create_sysfs_files(pdev,
2385 ARRAY_SIZE(f71858fg_temp_attr));
2388 err = f71882fg_create_sysfs_files(pdev,
2390 ARRAY_SIZE(f8000_temp_attr));
2393 err = f71882fg_create_sysfs_files(pdev,
2395 ARRAY_SIZE(f71858fg_temp_attr));
2398 err = f71882fg_create_sysfs_files(pdev,
2399 &fxxxx_temp_attr[0][0],
2400 ARRAY_SIZE(fxxxx_temp_attr[0]) * nr_temps);
2403 goto exit_unregister_sysfs;
2405 if (f71882fg_temp_has_beep[data->type]) {
2406 if (data->type == f81866a) {
2407 size = ARRAY_SIZE(f81866_temp_beep_attr[0]);
2408 err = f71882fg_create_sysfs_files(pdev,
2409 &f81866_temp_beep_attr[0][0],
2413 size = ARRAY_SIZE(fxxxx_temp_beep_attr[0]);
2414 err = f71882fg_create_sysfs_files(pdev,
2415 &fxxxx_temp_beep_attr[0][0],
2419 goto exit_unregister_sysfs;
2422 for (i = 0; i < F71882FG_MAX_INS; i++) {
2423 if (f71882fg_has_in[data->type][i]) {
2424 err = device_create_file(&pdev->dev,
2425 &fxxxx_in_attr[i].dev_attr);
2427 goto exit_unregister_sysfs;
2430 if (f71882fg_has_in1_alarm[data->type]) {
2431 err = f71882fg_create_sysfs_files(pdev,
2432 fxxxx_in1_alarm_attr,
2433 ARRAY_SIZE(fxxxx_in1_alarm_attr));
2435 goto exit_unregister_sysfs;
2439 if (start_reg & 0x02) {
2440 switch (data->type) {
2445 /* These always have signed auto point temps */
2446 data->auto_point_temp_signed = 1;
2447 fallthrough; /* to select correct fan/pwm reg bank! */
2451 reg = f71882fg_read8(data, F71882FG_REG_FAN_FAULT_T);
2452 if (reg & F71882FG_FAN_NEG_TEMP_EN)
2453 data->auto_point_temp_signed = 1;
2454 /* Ensure banked pwm registers point to right bank */
2455 reg &= ~F71882FG_FAN_PROG_SEL;
2456 f71882fg_write8(data, F71882FG_REG_FAN_FAULT_T, reg);
2463 f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
2465 for (i = 0; i < nr_fans; i++) {
2466 err = f71882fg_create_fan_sysfs_files(pdev, i);
2468 goto exit_unregister_sysfs;
2471 /* Some types have 1 extra fan with limited functionality */
2472 switch (data->type) {
2474 err = f71882fg_create_sysfs_files(pdev,
2476 ARRAY_SIZE(f71808a_fan3_attr));
2479 err = f71882fg_create_sysfs_files(pdev,
2481 ARRAY_SIZE(f8000_fan_attr));
2487 goto exit_unregister_sysfs;
2490 data->hwmon_dev = hwmon_device_register(&pdev->dev);
2491 if (IS_ERR(data->hwmon_dev)) {
2492 err = PTR_ERR(data->hwmon_dev);
2493 data->hwmon_dev = NULL;
2494 goto exit_unregister_sysfs;
2499 exit_unregister_sysfs:
2500 f71882fg_remove(pdev); /* Will unregister the sysfs files for us */
2501 return err; /* f71882fg_remove() also frees our data */
2504 static int f71882fg_remove(struct platform_device *pdev)
2506 struct f71882fg_data *data = platform_get_drvdata(pdev);
2507 int nr_fans = f71882fg_nr_fans[data->type];
2508 int nr_temps = f71882fg_nr_temps[data->type];
2510 u8 start_reg = f71882fg_read8(data, F71882FG_REG_START);
2512 if (data->hwmon_dev)
2513 hwmon_device_unregister(data->hwmon_dev);
2515 device_remove_file(&pdev->dev, &dev_attr_name);
2517 if (start_reg & 0x01) {
2518 switch (data->type) {
2520 if (data->temp_config & 0x10)
2521 f71882fg_remove_sysfs_files(pdev,
2523 ARRAY_SIZE(f8000_temp_attr));
2525 f71882fg_remove_sysfs_files(pdev,
2527 ARRAY_SIZE(f71858fg_temp_attr));
2530 f71882fg_remove_sysfs_files(pdev,
2532 ARRAY_SIZE(f8000_temp_attr));
2535 f71882fg_remove_sysfs_files(pdev,
2537 ARRAY_SIZE(f71858fg_temp_attr));
2540 f71882fg_remove_sysfs_files(pdev,
2541 &fxxxx_temp_attr[0][0],
2542 ARRAY_SIZE(fxxxx_temp_attr[0]) * nr_temps);
2544 if (f71882fg_temp_has_beep[data->type]) {
2545 if (data->type == f81866a)
2546 f71882fg_remove_sysfs_files(pdev,
2547 &f81866_temp_beep_attr[0][0],
2548 ARRAY_SIZE(f81866_temp_beep_attr[0])
2551 f71882fg_remove_sysfs_files(pdev,
2552 &fxxxx_temp_beep_attr[0][0],
2553 ARRAY_SIZE(fxxxx_temp_beep_attr[0])
2557 for (i = 0; i < F71882FG_MAX_INS; i++) {
2558 if (f71882fg_has_in[data->type][i]) {
2559 device_remove_file(&pdev->dev,
2560 &fxxxx_in_attr[i].dev_attr);
2563 if (f71882fg_has_in1_alarm[data->type]) {
2564 f71882fg_remove_sysfs_files(pdev,
2565 fxxxx_in1_alarm_attr,
2566 ARRAY_SIZE(fxxxx_in1_alarm_attr));
2570 if (start_reg & 0x02) {
2571 f71882fg_remove_sysfs_files(pdev, &fxxxx_fan_attr[0][0],
2572 ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans);
2574 if (f71882fg_fan_has_beep[data->type]) {
2575 f71882fg_remove_sysfs_files(pdev,
2576 fxxxx_fan_beep_attr, nr_fans);
2579 switch (data->type) {
2581 f71882fg_remove_sysfs_files(pdev,
2582 &fxxxx_auto_pwm_attr[0][0],
2583 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
2584 f71882fg_remove_sysfs_files(pdev,
2586 ARRAY_SIZE(f71808a_fan3_attr));
2589 f71882fg_remove_sysfs_files(pdev,
2590 &f71862fg_auto_pwm_attr[0][0],
2591 ARRAY_SIZE(f71862fg_auto_pwm_attr[0]) *
2596 f71882fg_remove_sysfs_files(pdev,
2597 &f71869_auto_pwm_attr[0][0],
2598 ARRAY_SIZE(f71869_auto_pwm_attr[0]) * nr_fans);
2601 f71882fg_remove_sysfs_files(pdev,
2603 ARRAY_SIZE(f8000_fan_attr));
2604 f71882fg_remove_sysfs_files(pdev,
2605 &f8000_auto_pwm_attr[0][0],
2606 ARRAY_SIZE(f8000_auto_pwm_attr[0]) * nr_fans);
2609 f71882fg_remove_sysfs_files(pdev,
2610 &fxxxx_auto_pwm_attr[0][0],
2611 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
2617 static int __init f71882fg_find(int sioaddr, struct f71882fg_sio_data *sio_data)
2620 unsigned short address;
2621 int err = superio_enter(sioaddr);
2625 devid = superio_inw(sioaddr, SIO_REG_MANID);
2626 if (devid != SIO_FINTEK_ID) {
2627 pr_debug("Not a Fintek device\n");
2632 devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID);
2634 case SIO_F71808E_ID:
2635 sio_data->type = f71808e;
2637 case SIO_F71808A_ID:
2638 sio_data->type = f71808a;
2641 sio_data->type = f71858fg;
2644 sio_data->type = f71862fg;
2647 sio_data->type = f71868a;
2650 sio_data->type = f71869;
2652 case SIO_F71869A_ID:
2653 sio_data->type = f71869a;
2656 sio_data->type = f71882fg;
2659 sio_data->type = f71889fg;
2661 case SIO_F71889E_ID:
2662 sio_data->type = f71889ed;
2664 case SIO_F71889A_ID:
2665 sio_data->type = f71889a;
2668 sio_data->type = f8000;
2670 case SIO_F81768D_ID:
2671 sio_data->type = f81768d;
2674 sio_data->type = f81865f;
2678 sio_data->type = f81866a;
2681 pr_info("Unsupported Fintek device: %04x\n",
2682 (unsigned int)devid);
2687 if (sio_data->type == f71858fg)
2688 superio_select(sioaddr, SIO_F71858FG_LD_HWM);
2690 superio_select(sioaddr, SIO_F71882FG_LD_HWM);
2692 if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) {
2693 pr_warn("Device not activated\n");
2698 address = superio_inw(sioaddr, SIO_REG_ADDR);
2700 pr_warn("Base address not set\n");
2704 address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */
2707 pr_info("Found %s chip at %#x, revision %d\n",
2708 f71882fg_names[sio_data->type], (unsigned int)address,
2709 (int)superio_inb(sioaddr, SIO_REG_DEVREV));
2711 superio_exit(sioaddr);
2715 static int __init f71882fg_device_add(int address,
2716 const struct f71882fg_sio_data *sio_data)
2718 struct resource res = {
2720 .end = address + REGION_LENGTH - 1,
2721 .flags = IORESOURCE_IO,
2725 f71882fg_pdev = platform_device_alloc(DRVNAME, address);
2729 res.name = f71882fg_pdev->name;
2730 err = acpi_check_resource_conflict(&res);
2732 goto exit_device_put;
2734 err = platform_device_add_resources(f71882fg_pdev, &res, 1);
2736 pr_err("Device resource addition failed\n");
2737 goto exit_device_put;
2740 err = platform_device_add_data(f71882fg_pdev, sio_data,
2741 sizeof(struct f71882fg_sio_data));
2743 pr_err("Platform data allocation failed\n");
2744 goto exit_device_put;
2747 err = platform_device_add(f71882fg_pdev);
2749 pr_err("Device addition failed\n");
2750 goto exit_device_put;
2756 platform_device_put(f71882fg_pdev);
2761 static int __init f71882fg_init(void)
2765 struct f71882fg_sio_data sio_data;
2767 memset(&sio_data, 0, sizeof(sio_data));
2769 address = f71882fg_find(0x2e, &sio_data);
2771 address = f71882fg_find(0x4e, &sio_data);
2775 err = platform_driver_register(&f71882fg_driver);
2779 err = f71882fg_device_add(address, &sio_data);
2786 platform_driver_unregister(&f71882fg_driver);
2790 static void __exit f71882fg_exit(void)
2792 platform_device_unregister(f71882fg_pdev);
2793 platform_driver_unregister(&f71882fg_driver);
2796 MODULE_DESCRIPTION("F71882FG Hardware Monitoring Driver");
2797 MODULE_AUTHOR("Hans Edgington, Hans de Goede <hdegoede@redhat.com>");
2798 MODULE_LICENSE("GPL");
2800 module_init(f71882fg_init);
2801 module_exit(f71882fg_exit);