1 /***************************************************************************
2 * Copyright (C) 2006 by Hans Edgington <hans@edgington.nl> *
3 * Copyright (C) 2007-2009 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 #include <linux/module.h>
22 #include <linux/init.h>
23 #include <linux/slab.h>
24 #include <linux/jiffies.h>
25 #include <linux/platform_device.h>
26 #include <linux/hwmon.h>
27 #include <linux/hwmon-sysfs.h>
28 #include <linux/err.h>
29 #include <linux/mutex.h>
31 #include <linux/acpi.h>
33 #define DRVNAME "f71882fg"
35 #define SIO_F71858FG_LD_HWM 0x02 /* Hardware monitor logical device */
36 #define SIO_F71882FG_LD_HWM 0x04 /* Hardware monitor logical device */
37 #define SIO_UNLOCK_KEY 0x87 /* Key to enable Super-I/O */
38 #define SIO_LOCK_KEY 0xAA /* Key to diasble Super-I/O */
40 #define SIO_REG_LDSEL 0x07 /* Logical device select */
41 #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */
42 #define SIO_REG_DEVREV 0x22 /* Device revision */
43 #define SIO_REG_MANID 0x23 /* Fintek ID (2 bytes) */
44 #define SIO_REG_ENABLE 0x30 /* Logical device enable */
45 #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
47 #define SIO_FINTEK_ID 0x1934 /* Manufacturers ID */
48 #define SIO_F71858_ID 0x0507 /* Chipset ID */
49 #define SIO_F71862_ID 0x0601 /* Chipset ID */
50 #define SIO_F71882_ID 0x0541 /* Chipset ID */
51 #define SIO_F71889_ID 0x0723 /* Chipset ID */
52 #define SIO_F8000_ID 0x0581 /* Chipset ID */
54 #define REGION_LENGTH 8
55 #define ADDR_REG_OFFSET 5
56 #define DATA_REG_OFFSET 6
58 #define F71882FG_REG_PECI 0x0A
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_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm)))
88 #define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm)))
89 #define F71882FG_REG_POINT_MAPPING(nr) (0xAF + 16 * (nr))
91 #define F71882FG_REG_START 0x01
93 #define FAN_MIN_DETECT 366 /* Lowest detectable fanspeed */
95 static unsigned short force_id;
96 module_param(force_id, ushort, 0);
97 MODULE_PARM_DESC(force_id, "Override the detected device ID");
99 enum chips { f71858fg, f71862fg, f71882fg, f71889fg, f8000 };
101 static const char *f71882fg_names[] = {
109 static struct platform_device *f71882fg_pdev;
111 /* Super-I/O Function prototypes */
112 static inline int superio_inb(int base, int reg);
113 static inline int superio_inw(int base, int reg);
114 static inline void superio_enter(int base);
115 static inline void superio_select(int base, int ld);
116 static inline void superio_exit(int base);
118 struct f71882fg_sio_data {
122 struct f71882fg_data {
125 struct device *hwmon_dev;
127 struct mutex update_lock;
128 int temp_start; /* temp numbering start (0 or 1) */
129 char valid; /* !=0 if following fields are valid */
130 unsigned long last_updated; /* In jiffies */
131 unsigned long last_limits; /* In jiffies */
133 /* Register Values */
140 u16 fan_full_speed[4];
143 /* Note: all models have only 3 temperature channels, but on some
144 they are addressed as 0-2 and on others as 1-3, so for coding
145 convenience we reserve space for 4 channels */
149 u8 temp_hyst[2]; /* 2 hysts stored per reg */
157 u8 pwm_auto_point_hyst[2];
158 u8 pwm_auto_point_mapping[4];
159 u8 pwm_auto_point_pwm[4][5];
160 s8 pwm_auto_point_temp[4][4];
164 static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
166 static ssize_t show_in_max(struct device *dev, struct device_attribute
167 *devattr, char *buf);
168 static ssize_t store_in_max(struct device *dev, struct device_attribute
169 *devattr, const char *buf, size_t count);
170 static ssize_t show_in_beep(struct device *dev, struct device_attribute
171 *devattr, char *buf);
172 static ssize_t store_in_beep(struct device *dev, struct device_attribute
173 *devattr, const char *buf, size_t count);
174 static ssize_t show_in_alarm(struct device *dev, struct device_attribute
175 *devattr, char *buf);
177 static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
179 static ssize_t show_fan_full_speed(struct device *dev,
180 struct device_attribute *devattr, char *buf);
181 static ssize_t store_fan_full_speed(struct device *dev,
182 struct device_attribute *devattr, const char *buf, size_t count);
183 static ssize_t show_fan_beep(struct device *dev, struct device_attribute
184 *devattr, char *buf);
185 static ssize_t store_fan_beep(struct device *dev, struct device_attribute
186 *devattr, const char *buf, size_t count);
187 static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
188 *devattr, char *buf);
190 static ssize_t show_temp(struct device *dev, struct device_attribute
191 *devattr, char *buf);
192 static ssize_t show_temp_max(struct device *dev, struct device_attribute
193 *devattr, char *buf);
194 static ssize_t store_temp_max(struct device *dev, struct device_attribute
195 *devattr, const char *buf, size_t count);
196 static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
197 *devattr, char *buf);
198 static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
199 *devattr, const char *buf, size_t count);
200 static ssize_t show_temp_crit(struct device *dev, struct device_attribute
201 *devattr, char *buf);
202 static ssize_t store_temp_crit(struct device *dev, struct device_attribute
203 *devattr, const char *buf, size_t count);
204 static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
205 *devattr, char *buf);
206 static ssize_t show_temp_type(struct device *dev, struct device_attribute
207 *devattr, char *buf);
208 static ssize_t show_temp_beep(struct device *dev, struct device_attribute
209 *devattr, char *buf);
210 static ssize_t store_temp_beep(struct device *dev, struct device_attribute
211 *devattr, const char *buf, size_t count);
212 static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
213 *devattr, char *buf);
214 static ssize_t show_temp_fault(struct device *dev, struct device_attribute
215 *devattr, char *buf);
216 /* PWM and Auto point control */
217 static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
219 static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr,
220 const char *buf, size_t count);
221 static ssize_t show_pwm_enable(struct device *dev,
222 struct device_attribute *devattr, char *buf);
223 static ssize_t store_pwm_enable(struct device *dev,
224 struct device_attribute *devattr, const char *buf, size_t count);
225 static ssize_t show_pwm_interpolate(struct device *dev,
226 struct device_attribute *devattr, char *buf);
227 static ssize_t store_pwm_interpolate(struct device *dev,
228 struct device_attribute *devattr, const char *buf, size_t count);
229 static ssize_t show_pwm_auto_point_channel(struct device *dev,
230 struct device_attribute *devattr, char *buf);
231 static ssize_t store_pwm_auto_point_channel(struct device *dev,
232 struct device_attribute *devattr, const char *buf, size_t count);
233 static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
234 struct device_attribute *devattr, char *buf);
235 static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
236 struct device_attribute *devattr, const char *buf, size_t count);
237 static ssize_t show_pwm_auto_point_pwm(struct device *dev,
238 struct device_attribute *devattr, char *buf);
239 static ssize_t store_pwm_auto_point_pwm(struct device *dev,
240 struct device_attribute *devattr, const char *buf, size_t count);
241 static ssize_t show_pwm_auto_point_temp(struct device *dev,
242 struct device_attribute *devattr, char *buf);
243 static ssize_t store_pwm_auto_point_temp(struct device *dev,
244 struct device_attribute *devattr, const char *buf, size_t count);
246 static ssize_t show_name(struct device *dev, struct device_attribute *devattr,
249 static int __devinit f71882fg_probe(struct platform_device * pdev);
250 static int f71882fg_remove(struct platform_device *pdev);
252 static struct platform_driver f71882fg_driver = {
254 .owner = THIS_MODULE,
257 .probe = f71882fg_probe,
258 .remove = f71882fg_remove,
261 static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
263 /* Temp and in attr for the f71858fg, the f71858fg is special as it
264 has its temperature indexes start at 0 (the others start at 1) and
265 it only has 3 voltage inputs */
266 static struct sensor_device_attribute_2 f71858fg_in_temp_attr[] = {
267 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
268 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
269 SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2),
270 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
271 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
272 store_temp_max, 0, 0),
273 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
274 store_temp_max_hyst, 0, 0),
275 SENSOR_ATTR_2(temp1_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 0),
276 SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
277 store_temp_crit, 0, 0),
278 SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
280 SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4),
281 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0),
282 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1),
283 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max,
284 store_temp_max, 0, 1),
285 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
286 store_temp_max_hyst, 0, 1),
287 SENSOR_ATTR_2(temp2_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
288 SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
289 store_temp_crit, 0, 1),
290 SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
292 SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
293 SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 1),
294 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
295 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2),
296 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
297 store_temp_max, 0, 2),
298 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
299 store_temp_max_hyst, 0, 2),
300 SENSOR_ATTR_2(temp3_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
301 SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit,
302 store_temp_crit, 0, 2),
303 SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
305 SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
306 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
309 /* Temp and in attr common to the f71862fg, f71882fg and f71889fg */
310 static struct sensor_device_attribute_2 fxxxx_in_temp_attr[] = {
311 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
312 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
313 SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2),
314 SENSOR_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 0, 3),
315 SENSOR_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 0, 4),
316 SENSOR_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 0, 5),
317 SENSOR_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 0, 6),
318 SENSOR_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 0, 7),
319 SENSOR_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 0, 8),
320 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 1),
321 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
322 store_temp_max, 0, 1),
323 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
324 store_temp_max_hyst, 0, 1),
325 /* Should really be temp1_max_alarm, but older versions did not handle
326 the max and crit alarms separately and lm_sensors v2 depends on the
327 presence of temp#_alarm files. The same goes for temp2/3 _alarm. */
328 SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
329 SENSOR_ATTR_2(temp1_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
330 store_temp_beep, 0, 1),
331 SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
332 store_temp_crit, 0, 1),
333 SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
335 SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
336 SENSOR_ATTR_2(temp1_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
337 store_temp_beep, 0, 5),
338 SENSOR_ATTR_2(temp1_type, S_IRUGO, show_temp_type, NULL, 0, 1),
339 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
340 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 2),
341 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max,
342 store_temp_max, 0, 2),
343 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
344 store_temp_max_hyst, 0, 2),
345 /* Should be temp2_max_alarm, see temp1_alarm note */
346 SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
347 SENSOR_ATTR_2(temp2_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
348 store_temp_beep, 0, 2),
349 SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
350 store_temp_crit, 0, 2),
351 SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
353 SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
354 SENSOR_ATTR_2(temp2_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
355 store_temp_beep, 0, 6),
356 SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 2),
357 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
358 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 3),
359 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
360 store_temp_max, 0, 3),
361 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
362 store_temp_max_hyst, 0, 3),
363 /* Should be temp3_max_alarm, see temp1_alarm note */
364 SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 3),
365 SENSOR_ATTR_2(temp3_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
366 store_temp_beep, 0, 3),
367 SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit,
368 store_temp_crit, 0, 3),
369 SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
371 SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 7),
372 SENSOR_ATTR_2(temp3_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
373 store_temp_beep, 0, 7),
374 SENSOR_ATTR_2(temp3_type, S_IRUGO, show_temp_type, NULL, 0, 3),
375 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 3),
378 /* For models with in1 alarm capability */
379 static struct sensor_device_attribute_2 fxxxx_in1_alarm_attr[] = {
380 SENSOR_ATTR_2(in1_max, S_IRUGO|S_IWUSR, show_in_max, store_in_max,
382 SENSOR_ATTR_2(in1_beep, S_IRUGO|S_IWUSR, show_in_beep, store_in_beep,
384 SENSOR_ATTR_2(in1_alarm, S_IRUGO, show_in_alarm, NULL, 0, 1),
387 /* Temp and in attr for the f8000
388 Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max)
389 is used as hysteresis value to clear alarms
390 Also like the f71858fg its temperature indexes start at 0
392 static struct sensor_device_attribute_2 f8000_in_temp_attr[] = {
393 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
394 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
395 SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2),
396 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
397 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_crit,
398 store_temp_crit, 0, 0),
399 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
400 store_temp_max, 0, 0),
401 SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4),
402 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0),
403 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1),
404 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_crit,
405 store_temp_crit, 0, 1),
406 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
407 store_temp_max, 0, 1),
408 SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
409 SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 1),
410 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
411 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2),
412 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_crit,
413 store_temp_crit, 0, 2),
414 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
415 store_temp_max, 0, 2),
416 SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
417 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
420 /* Fan / PWM attr common to all models */
421 static struct sensor_device_attribute_2 fxxxx_fan_attr[4][6] = { {
422 SENSOR_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0),
423 SENSOR_ATTR_2(fan1_full_speed, S_IRUGO|S_IWUSR,
425 store_fan_full_speed, 0, 0),
426 SENSOR_ATTR_2(fan1_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 0),
427 SENSOR_ATTR_2(pwm1, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 0),
428 SENSOR_ATTR_2(pwm1_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
429 store_pwm_enable, 0, 0),
430 SENSOR_ATTR_2(pwm1_interpolate, S_IRUGO|S_IWUSR,
431 show_pwm_interpolate, store_pwm_interpolate, 0, 0),
433 SENSOR_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 0, 1),
434 SENSOR_ATTR_2(fan2_full_speed, S_IRUGO|S_IWUSR,
436 store_fan_full_speed, 0, 1),
437 SENSOR_ATTR_2(fan2_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 1),
438 SENSOR_ATTR_2(pwm2, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 1),
439 SENSOR_ATTR_2(pwm2_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
440 store_pwm_enable, 0, 1),
441 SENSOR_ATTR_2(pwm2_interpolate, S_IRUGO|S_IWUSR,
442 show_pwm_interpolate, store_pwm_interpolate, 0, 1),
444 SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
445 SENSOR_ATTR_2(fan3_full_speed, S_IRUGO|S_IWUSR,
447 store_fan_full_speed, 0, 2),
448 SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
449 SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 2),
450 SENSOR_ATTR_2(pwm3_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
451 store_pwm_enable, 0, 2),
452 SENSOR_ATTR_2(pwm3_interpolate, S_IRUGO|S_IWUSR,
453 show_pwm_interpolate, store_pwm_interpolate, 0, 2),
455 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
456 SENSOR_ATTR_2(fan4_full_speed, S_IRUGO|S_IWUSR,
458 store_fan_full_speed, 0, 3),
459 SENSOR_ATTR_2(fan4_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 3),
460 SENSOR_ATTR_2(pwm4, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 3),
461 SENSOR_ATTR_2(pwm4_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
462 store_pwm_enable, 0, 3),
463 SENSOR_ATTR_2(pwm4_interpolate, S_IRUGO|S_IWUSR,
464 show_pwm_interpolate, store_pwm_interpolate, 0, 3),
467 /* Attr for models which can beep on Fan alarm */
468 static struct sensor_device_attribute_2 fxxxx_fan_beep_attr[] = {
469 SENSOR_ATTR_2(fan1_beep, S_IRUGO|S_IWUSR, show_fan_beep,
470 store_fan_beep, 0, 0),
471 SENSOR_ATTR_2(fan2_beep, S_IRUGO|S_IWUSR, show_fan_beep,
472 store_fan_beep, 0, 1),
473 SENSOR_ATTR_2(fan3_beep, S_IRUGO|S_IWUSR, show_fan_beep,
474 store_fan_beep, 0, 2),
475 SENSOR_ATTR_2(fan4_beep, S_IRUGO|S_IWUSR, show_fan_beep,
476 store_fan_beep, 0, 3),
479 /* PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
480 f71858fg / f71882fg / f71889fg */
481 static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr[] = {
482 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
483 show_pwm_auto_point_channel,
484 store_pwm_auto_point_channel, 0, 0),
485 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
486 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
488 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
489 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
491 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
492 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
494 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
495 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
497 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
498 show_pwm_auto_point_temp_hyst,
499 store_pwm_auto_point_temp_hyst,
501 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
502 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
504 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
505 show_pwm_auto_point_channel,
506 store_pwm_auto_point_channel, 0, 1),
507 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
508 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
510 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
511 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
513 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
514 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
516 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
517 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
519 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
520 show_pwm_auto_point_temp_hyst,
521 store_pwm_auto_point_temp_hyst,
523 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
524 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
526 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
527 show_pwm_auto_point_channel,
528 store_pwm_auto_point_channel, 0, 2),
529 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
530 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
532 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
533 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
535 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
536 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
538 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
539 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
541 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
542 show_pwm_auto_point_temp_hyst,
543 store_pwm_auto_point_temp_hyst,
545 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
546 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
549 /* PWM attr common to the f71858fg, f71882fg and f71889fg */
550 static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr[4][14] = { {
551 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
552 show_pwm_auto_point_channel,
553 store_pwm_auto_point_channel, 0, 0),
554 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
555 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
557 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
558 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
560 SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO|S_IWUSR,
561 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
563 SENSOR_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO|S_IWUSR,
564 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
566 SENSOR_ATTR_2(pwm1_auto_point5_pwm, S_IRUGO|S_IWUSR,
567 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
569 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
570 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
572 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
573 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
575 SENSOR_ATTR_2(pwm1_auto_point3_temp, S_IRUGO|S_IWUSR,
576 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
578 SENSOR_ATTR_2(pwm1_auto_point4_temp, S_IRUGO|S_IWUSR,
579 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
581 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
582 show_pwm_auto_point_temp_hyst,
583 store_pwm_auto_point_temp_hyst,
585 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
586 show_pwm_auto_point_temp_hyst, NULL, 1, 0),
587 SENSOR_ATTR_2(pwm1_auto_point3_temp_hyst, S_IRUGO,
588 show_pwm_auto_point_temp_hyst, NULL, 2, 0),
589 SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst, S_IRUGO,
590 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
592 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
593 show_pwm_auto_point_channel,
594 store_pwm_auto_point_channel, 0, 1),
595 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
596 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
598 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
599 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
601 SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO|S_IWUSR,
602 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
604 SENSOR_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO|S_IWUSR,
605 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
607 SENSOR_ATTR_2(pwm2_auto_point5_pwm, S_IRUGO|S_IWUSR,
608 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
610 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
611 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
613 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
614 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
616 SENSOR_ATTR_2(pwm2_auto_point3_temp, S_IRUGO|S_IWUSR,
617 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
619 SENSOR_ATTR_2(pwm2_auto_point4_temp, S_IRUGO|S_IWUSR,
620 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
622 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
623 show_pwm_auto_point_temp_hyst,
624 store_pwm_auto_point_temp_hyst,
626 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
627 show_pwm_auto_point_temp_hyst, NULL, 1, 1),
628 SENSOR_ATTR_2(pwm2_auto_point3_temp_hyst, S_IRUGO,
629 show_pwm_auto_point_temp_hyst, NULL, 2, 1),
630 SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst, S_IRUGO,
631 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
633 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
634 show_pwm_auto_point_channel,
635 store_pwm_auto_point_channel, 0, 2),
636 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
637 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
639 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
640 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
642 SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO|S_IWUSR,
643 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
645 SENSOR_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO|S_IWUSR,
646 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
648 SENSOR_ATTR_2(pwm3_auto_point5_pwm, S_IRUGO|S_IWUSR,
649 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
651 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
652 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
654 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
655 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
657 SENSOR_ATTR_2(pwm3_auto_point3_temp, S_IRUGO|S_IWUSR,
658 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
660 SENSOR_ATTR_2(pwm3_auto_point4_temp, S_IRUGO|S_IWUSR,
661 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
663 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
664 show_pwm_auto_point_temp_hyst,
665 store_pwm_auto_point_temp_hyst,
667 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
668 show_pwm_auto_point_temp_hyst, NULL, 1, 2),
669 SENSOR_ATTR_2(pwm3_auto_point3_temp_hyst, S_IRUGO,
670 show_pwm_auto_point_temp_hyst, NULL, 2, 2),
671 SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst, S_IRUGO,
672 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
674 SENSOR_ATTR_2(pwm4_auto_channels_temp, S_IRUGO|S_IWUSR,
675 show_pwm_auto_point_channel,
676 store_pwm_auto_point_channel, 0, 3),
677 SENSOR_ATTR_2(pwm4_auto_point1_pwm, S_IRUGO|S_IWUSR,
678 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
680 SENSOR_ATTR_2(pwm4_auto_point2_pwm, S_IRUGO|S_IWUSR,
681 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
683 SENSOR_ATTR_2(pwm4_auto_point3_pwm, S_IRUGO|S_IWUSR,
684 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
686 SENSOR_ATTR_2(pwm4_auto_point4_pwm, S_IRUGO|S_IWUSR,
687 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
689 SENSOR_ATTR_2(pwm4_auto_point5_pwm, S_IRUGO|S_IWUSR,
690 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
692 SENSOR_ATTR_2(pwm4_auto_point1_temp, S_IRUGO|S_IWUSR,
693 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
695 SENSOR_ATTR_2(pwm4_auto_point2_temp, S_IRUGO|S_IWUSR,
696 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
698 SENSOR_ATTR_2(pwm4_auto_point3_temp, S_IRUGO|S_IWUSR,
699 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
701 SENSOR_ATTR_2(pwm4_auto_point4_temp, S_IRUGO|S_IWUSR,
702 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
704 SENSOR_ATTR_2(pwm4_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
705 show_pwm_auto_point_temp_hyst,
706 store_pwm_auto_point_temp_hyst,
708 SENSOR_ATTR_2(pwm4_auto_point2_temp_hyst, S_IRUGO,
709 show_pwm_auto_point_temp_hyst, NULL, 1, 3),
710 SENSOR_ATTR_2(pwm4_auto_point3_temp_hyst, S_IRUGO,
711 show_pwm_auto_point_temp_hyst, NULL, 2, 3),
712 SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst, S_IRUGO,
713 show_pwm_auto_point_temp_hyst, NULL, 3, 3),
716 /* Fan attr specific to the f8000 (4th fan input can only measure speed) */
717 static struct sensor_device_attribute_2 f8000_fan_attr[] = {
718 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
721 /* PWM attr for the f8000, zones mapped to temp instead of to pwm!
722 Also the register block at offset A0 maps to TEMP1 (so our temp2, as the
723 F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0 */
724 static struct sensor_device_attribute_2 f8000_auto_pwm_attr[] = {
725 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
726 show_pwm_auto_point_channel,
727 store_pwm_auto_point_channel, 0, 0),
728 SENSOR_ATTR_2(temp1_auto_point1_pwm, S_IRUGO|S_IWUSR,
729 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
731 SENSOR_ATTR_2(temp1_auto_point2_pwm, S_IRUGO|S_IWUSR,
732 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
734 SENSOR_ATTR_2(temp1_auto_point3_pwm, S_IRUGO|S_IWUSR,
735 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
737 SENSOR_ATTR_2(temp1_auto_point4_pwm, S_IRUGO|S_IWUSR,
738 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
740 SENSOR_ATTR_2(temp1_auto_point5_pwm, S_IRUGO|S_IWUSR,
741 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
743 SENSOR_ATTR_2(temp1_auto_point1_temp, S_IRUGO|S_IWUSR,
744 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
746 SENSOR_ATTR_2(temp1_auto_point2_temp, S_IRUGO|S_IWUSR,
747 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
749 SENSOR_ATTR_2(temp1_auto_point3_temp, S_IRUGO|S_IWUSR,
750 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
752 SENSOR_ATTR_2(temp1_auto_point4_temp, S_IRUGO|S_IWUSR,
753 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
755 SENSOR_ATTR_2(temp1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
756 show_pwm_auto_point_temp_hyst,
757 store_pwm_auto_point_temp_hyst,
759 SENSOR_ATTR_2(temp1_auto_point2_temp_hyst, S_IRUGO,
760 show_pwm_auto_point_temp_hyst, NULL, 1, 2),
761 SENSOR_ATTR_2(temp1_auto_point3_temp_hyst, S_IRUGO,
762 show_pwm_auto_point_temp_hyst, NULL, 2, 2),
763 SENSOR_ATTR_2(temp1_auto_point4_temp_hyst, S_IRUGO,
764 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
766 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
767 show_pwm_auto_point_channel,
768 store_pwm_auto_point_channel, 0, 1),
769 SENSOR_ATTR_2(temp2_auto_point1_pwm, S_IRUGO|S_IWUSR,
770 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
772 SENSOR_ATTR_2(temp2_auto_point2_pwm, S_IRUGO|S_IWUSR,
773 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
775 SENSOR_ATTR_2(temp2_auto_point3_pwm, S_IRUGO|S_IWUSR,
776 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
778 SENSOR_ATTR_2(temp2_auto_point4_pwm, S_IRUGO|S_IWUSR,
779 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
781 SENSOR_ATTR_2(temp2_auto_point5_pwm, S_IRUGO|S_IWUSR,
782 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
784 SENSOR_ATTR_2(temp2_auto_point1_temp, S_IRUGO|S_IWUSR,
785 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
787 SENSOR_ATTR_2(temp2_auto_point2_temp, S_IRUGO|S_IWUSR,
788 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
790 SENSOR_ATTR_2(temp2_auto_point3_temp, S_IRUGO|S_IWUSR,
791 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
793 SENSOR_ATTR_2(temp2_auto_point4_temp, S_IRUGO|S_IWUSR,
794 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
796 SENSOR_ATTR_2(temp2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
797 show_pwm_auto_point_temp_hyst,
798 store_pwm_auto_point_temp_hyst,
800 SENSOR_ATTR_2(temp2_auto_point2_temp_hyst, S_IRUGO,
801 show_pwm_auto_point_temp_hyst, NULL, 1, 0),
802 SENSOR_ATTR_2(temp2_auto_point3_temp_hyst, S_IRUGO,
803 show_pwm_auto_point_temp_hyst, NULL, 2, 0),
804 SENSOR_ATTR_2(temp2_auto_point4_temp_hyst, S_IRUGO,
805 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
807 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
808 show_pwm_auto_point_channel,
809 store_pwm_auto_point_channel, 0, 2),
810 SENSOR_ATTR_2(temp3_auto_point1_pwm, S_IRUGO|S_IWUSR,
811 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
813 SENSOR_ATTR_2(temp3_auto_point2_pwm, S_IRUGO|S_IWUSR,
814 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
816 SENSOR_ATTR_2(temp3_auto_point3_pwm, S_IRUGO|S_IWUSR,
817 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
819 SENSOR_ATTR_2(temp3_auto_point4_pwm, S_IRUGO|S_IWUSR,
820 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
822 SENSOR_ATTR_2(temp3_auto_point5_pwm, S_IRUGO|S_IWUSR,
823 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
825 SENSOR_ATTR_2(temp3_auto_point1_temp, S_IRUGO|S_IWUSR,
826 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
828 SENSOR_ATTR_2(temp3_auto_point2_temp, S_IRUGO|S_IWUSR,
829 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
831 SENSOR_ATTR_2(temp3_auto_point3_temp, S_IRUGO|S_IWUSR,
832 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
834 SENSOR_ATTR_2(temp3_auto_point4_temp, S_IRUGO|S_IWUSR,
835 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
837 SENSOR_ATTR_2(temp3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
838 show_pwm_auto_point_temp_hyst,
839 store_pwm_auto_point_temp_hyst,
841 SENSOR_ATTR_2(temp3_auto_point2_temp_hyst, S_IRUGO,
842 show_pwm_auto_point_temp_hyst, NULL, 1, 1),
843 SENSOR_ATTR_2(temp3_auto_point3_temp_hyst, S_IRUGO,
844 show_pwm_auto_point_temp_hyst, NULL, 2, 1),
845 SENSOR_ATTR_2(temp3_auto_point4_temp_hyst, S_IRUGO,
846 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
849 /* Super I/O functions */
850 static inline int superio_inb(int base, int reg)
853 return inb(base + 1);
856 static int superio_inw(int base, int reg)
859 val = superio_inb(base, reg) << 8;
860 val |= superio_inb(base, reg + 1);
864 static inline void superio_enter(int base)
866 /* according to the datasheet the key must be send twice! */
867 outb(SIO_UNLOCK_KEY, base);
868 outb(SIO_UNLOCK_KEY, base);
871 static inline void superio_select(int base, int ld)
873 outb(SIO_REG_LDSEL, base);
877 static inline void superio_exit(int base)
879 outb(SIO_LOCK_KEY, base);
882 static inline int fan_from_reg(u16 reg)
884 return reg ? (1500000 / reg) : 0;
887 static inline u16 fan_to_reg(int fan)
889 return fan ? (1500000 / fan) : 0;
892 static u8 f71882fg_read8(struct f71882fg_data *data, u8 reg)
896 outb(reg, data->addr + ADDR_REG_OFFSET);
897 val = inb(data->addr + DATA_REG_OFFSET);
902 static u16 f71882fg_read16(struct f71882fg_data *data, u8 reg)
906 val = f71882fg_read8(data, reg) << 8;
907 val |= f71882fg_read8(data, reg + 1);
912 static void f71882fg_write8(struct f71882fg_data *data, u8 reg, u8 val)
914 outb(reg, data->addr + ADDR_REG_OFFSET);
915 outb(val, data->addr + DATA_REG_OFFSET);
918 static void f71882fg_write16(struct f71882fg_data *data, u8 reg, u16 val)
920 f71882fg_write8(data, reg, val >> 8);
921 f71882fg_write8(data, reg + 1, val & 0xff);
924 static u16 f71882fg_read_temp(struct f71882fg_data *data, int nr)
926 if (data->type == f71858fg)
927 return f71882fg_read16(data, F71882FG_REG_TEMP(nr));
929 return f71882fg_read8(data, F71882FG_REG_TEMP(nr));
932 static struct f71882fg_data *f71882fg_update_device(struct device *dev)
934 struct f71882fg_data *data = dev_get_drvdata(dev);
935 int nr, reg = 0, reg2;
936 int nr_fans = (data->type == f71882fg) ? 4 : 3;
937 int nr_ins = (data->type == f71858fg || data->type == f8000) ? 3 : 9;
939 mutex_lock(&data->update_lock);
941 /* Update once every 60 seconds */
942 if (time_after(jiffies, data->last_limits + 60 * HZ) ||
944 if (data->type == f71882fg || data->type == f71889fg) {
946 f71882fg_read8(data, F71882FG_REG_IN1_HIGH);
948 f71882fg_read8(data, F71882FG_REG_IN_BEEP);
951 /* Get High & boundary temps*/
952 for (nr = data->temp_start; nr < 3 + data->temp_start; nr++) {
953 data->temp_ovt[nr] = f71882fg_read8(data,
954 F71882FG_REG_TEMP_OVT(nr));
955 data->temp_high[nr] = f71882fg_read8(data,
956 F71882FG_REG_TEMP_HIGH(nr));
959 if (data->type != f8000) {
960 data->temp_hyst[0] = f71882fg_read8(data,
961 F71882FG_REG_TEMP_HYST(0));
962 data->temp_hyst[1] = f71882fg_read8(data,
963 F71882FG_REG_TEMP_HYST(1));
966 if (data->type == f71862fg || data->type == f71882fg ||
967 data->type == f71889fg) {
968 data->fan_beep = f71882fg_read8(data,
969 F71882FG_REG_FAN_BEEP);
970 data->temp_beep = f71882fg_read8(data,
971 F71882FG_REG_TEMP_BEEP);
972 /* Have to hardcode type, because temp1 is special */
973 reg = f71882fg_read8(data, F71882FG_REG_TEMP_TYPE);
974 data->temp_type[2] = (reg & 0x04) ? 2 : 4;
975 data->temp_type[3] = (reg & 0x08) ? 2 : 4;
977 /* Determine temp index 1 sensor type */
978 if (data->type == f71889fg) {
979 reg2 = f71882fg_read8(data, F71882FG_REG_START);
980 switch ((reg2 & 0x60) >> 5) {
981 case 0x00: /* BJT / Thermistor */
982 data->temp_type[1] = (reg & 0x02) ? 2 : 4;
984 case 0x01: /* AMDSI */
985 data->temp_type[1] = 5;
987 case 0x02: /* PECI */
988 case 0x03: /* Ibex Peak ?? Report as PECI for now */
989 data->temp_type[1] = 6;
993 reg2 = f71882fg_read8(data, F71882FG_REG_PECI);
994 if ((reg2 & 0x03) == 0x01)
995 data->temp_type[1] = 6; /* PECI */
996 else if ((reg2 & 0x03) == 0x02)
997 data->temp_type[1] = 5; /* AMDSI */
998 else if (data->type == f71862fg ||
999 data->type == f71882fg)
1000 data->temp_type[1] = (reg & 0x02) ? 2 : 4;
1001 else /* f71858fg and f8000 only support BJT */
1002 data->temp_type[1] = 2;
1005 data->pwm_enable = f71882fg_read8(data,
1006 F71882FG_REG_PWM_ENABLE);
1007 data->pwm_auto_point_hyst[0] =
1008 f71882fg_read8(data, F71882FG_REG_FAN_HYST(0));
1009 data->pwm_auto_point_hyst[1] =
1010 f71882fg_read8(data, F71882FG_REG_FAN_HYST(1));
1012 for (nr = 0; nr < nr_fans; nr++) {
1013 data->pwm_auto_point_mapping[nr] =
1014 f71882fg_read8(data,
1015 F71882FG_REG_POINT_MAPPING(nr));
1017 if (data->type != f71862fg) {
1019 for (point = 0; point < 5; point++) {
1020 data->pwm_auto_point_pwm[nr][point] =
1021 f71882fg_read8(data,
1022 F71882FG_REG_POINT_PWM
1025 for (point = 0; point < 4; point++) {
1026 data->pwm_auto_point_temp[nr][point] =
1027 f71882fg_read8(data,
1028 F71882FG_REG_POINT_TEMP
1032 data->pwm_auto_point_pwm[nr][1] =
1033 f71882fg_read8(data,
1034 F71882FG_REG_POINT_PWM
1036 data->pwm_auto_point_pwm[nr][4] =
1037 f71882fg_read8(data,
1038 F71882FG_REG_POINT_PWM
1040 data->pwm_auto_point_temp[nr][0] =
1041 f71882fg_read8(data,
1042 F71882FG_REG_POINT_TEMP
1044 data->pwm_auto_point_temp[nr][3] =
1045 f71882fg_read8(data,
1046 F71882FG_REG_POINT_TEMP
1050 data->last_limits = jiffies;
1053 /* Update every second */
1054 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
1055 data->temp_status = f71882fg_read8(data,
1056 F71882FG_REG_TEMP_STATUS);
1057 data->temp_diode_open = f71882fg_read8(data,
1058 F71882FG_REG_TEMP_DIODE_OPEN);
1059 for (nr = data->temp_start; nr < 3 + data->temp_start; nr++)
1060 data->temp[nr] = f71882fg_read_temp(data, nr);
1062 data->fan_status = f71882fg_read8(data,
1063 F71882FG_REG_FAN_STATUS);
1064 for (nr = 0; nr < nr_fans; nr++) {
1065 data->fan[nr] = f71882fg_read16(data,
1066 F71882FG_REG_FAN(nr));
1067 data->fan_target[nr] =
1068 f71882fg_read16(data, F71882FG_REG_FAN_TARGET(nr));
1069 data->fan_full_speed[nr] =
1070 f71882fg_read16(data,
1071 F71882FG_REG_FAN_FULL_SPEED(nr));
1073 f71882fg_read8(data, F71882FG_REG_PWM(nr));
1076 /* The f8000 can monitor 1 more fan, but has no pwm for it */
1077 if (data->type == f8000)
1078 data->fan[3] = f71882fg_read16(data,
1079 F71882FG_REG_FAN(3));
1080 if (data->type == f71882fg || data->type == f71889fg)
1081 data->in_status = f71882fg_read8(data,
1082 F71882FG_REG_IN_STATUS);
1083 for (nr = 0; nr < nr_ins; nr++)
1084 data->in[nr] = f71882fg_read8(data,
1085 F71882FG_REG_IN(nr));
1087 data->last_updated = jiffies;
1091 mutex_unlock(&data->update_lock);
1096 /* Sysfs Interface */
1097 static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
1100 struct f71882fg_data *data = f71882fg_update_device(dev);
1101 int nr = to_sensor_dev_attr_2(devattr)->index;
1102 int speed = fan_from_reg(data->fan[nr]);
1104 if (speed == FAN_MIN_DETECT)
1107 return sprintf(buf, "%d\n", speed);
1110 static ssize_t show_fan_full_speed(struct device *dev,
1111 struct device_attribute *devattr, char *buf)
1113 struct f71882fg_data *data = f71882fg_update_device(dev);
1114 int nr = to_sensor_dev_attr_2(devattr)->index;
1115 int speed = fan_from_reg(data->fan_full_speed[nr]);
1116 return sprintf(buf, "%d\n", speed);
1119 static ssize_t store_fan_full_speed(struct device *dev,
1120 struct device_attribute *devattr,
1121 const char *buf, size_t count)
1123 struct f71882fg_data *data = dev_get_drvdata(dev);
1124 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1127 err = strict_strtol(buf, 10, &val);
1131 val = SENSORS_LIMIT(val, 23, 1500000);
1132 val = fan_to_reg(val);
1134 mutex_lock(&data->update_lock);
1135 f71882fg_write16(data, F71882FG_REG_FAN_FULL_SPEED(nr), val);
1136 data->fan_full_speed[nr] = val;
1137 mutex_unlock(&data->update_lock);
1142 static ssize_t show_fan_beep(struct device *dev, struct device_attribute
1143 *devattr, char *buf)
1145 struct f71882fg_data *data = f71882fg_update_device(dev);
1146 int nr = to_sensor_dev_attr_2(devattr)->index;
1148 if (data->fan_beep & (1 << nr))
1149 return sprintf(buf, "1\n");
1151 return sprintf(buf, "0\n");
1154 static ssize_t store_fan_beep(struct device *dev, struct device_attribute
1155 *devattr, const char *buf, size_t count)
1157 struct f71882fg_data *data = dev_get_drvdata(dev);
1158 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1161 err = strict_strtoul(buf, 10, &val);
1165 mutex_lock(&data->update_lock);
1166 data->fan_beep = f71882fg_read8(data, F71882FG_REG_FAN_BEEP);
1168 data->fan_beep |= 1 << nr;
1170 data->fan_beep &= ~(1 << nr);
1172 f71882fg_write8(data, F71882FG_REG_FAN_BEEP, data->fan_beep);
1173 mutex_unlock(&data->update_lock);
1178 static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
1179 *devattr, char *buf)
1181 struct f71882fg_data *data = f71882fg_update_device(dev);
1182 int nr = to_sensor_dev_attr_2(devattr)->index;
1184 if (data->fan_status & (1 << nr))
1185 return sprintf(buf, "1\n");
1187 return sprintf(buf, "0\n");
1190 static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
1193 struct f71882fg_data *data = f71882fg_update_device(dev);
1194 int nr = to_sensor_dev_attr_2(devattr)->index;
1196 return sprintf(buf, "%d\n", data->in[nr] * 8);
1199 static ssize_t show_in_max(struct device *dev, struct device_attribute
1200 *devattr, char *buf)
1202 struct f71882fg_data *data = f71882fg_update_device(dev);
1204 return sprintf(buf, "%d\n", data->in1_max * 8);
1207 static ssize_t store_in_max(struct device *dev, struct device_attribute
1208 *devattr, const char *buf, size_t count)
1210 struct f71882fg_data *data = dev_get_drvdata(dev);
1214 err = strict_strtol(buf, 10, &val);
1219 val = SENSORS_LIMIT(val, 0, 255);
1221 mutex_lock(&data->update_lock);
1222 f71882fg_write8(data, F71882FG_REG_IN1_HIGH, val);
1223 data->in1_max = val;
1224 mutex_unlock(&data->update_lock);
1229 static ssize_t show_in_beep(struct device *dev, struct device_attribute
1230 *devattr, char *buf)
1232 struct f71882fg_data *data = f71882fg_update_device(dev);
1233 int nr = to_sensor_dev_attr_2(devattr)->index;
1235 if (data->in_beep & (1 << nr))
1236 return sprintf(buf, "1\n");
1238 return sprintf(buf, "0\n");
1241 static ssize_t store_in_beep(struct device *dev, struct device_attribute
1242 *devattr, const char *buf, size_t count)
1244 struct f71882fg_data *data = dev_get_drvdata(dev);
1245 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1248 err = strict_strtoul(buf, 10, &val);
1252 mutex_lock(&data->update_lock);
1253 data->in_beep = f71882fg_read8(data, F71882FG_REG_IN_BEEP);
1255 data->in_beep |= 1 << nr;
1257 data->in_beep &= ~(1 << nr);
1259 f71882fg_write8(data, F71882FG_REG_IN_BEEP, data->in_beep);
1260 mutex_unlock(&data->update_lock);
1265 static ssize_t show_in_alarm(struct device *dev, struct device_attribute
1266 *devattr, char *buf)
1268 struct f71882fg_data *data = f71882fg_update_device(dev);
1269 int nr = to_sensor_dev_attr_2(devattr)->index;
1271 if (data->in_status & (1 << nr))
1272 return sprintf(buf, "1\n");
1274 return sprintf(buf, "0\n");
1277 static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
1280 struct f71882fg_data *data = f71882fg_update_device(dev);
1281 int nr = to_sensor_dev_attr_2(devattr)->index;
1284 if (data->type == f71858fg) {
1285 /* TEMP_TABLE_SEL 1 or 3 ? */
1286 if (data->temp_config & 1) {
1287 sign = data->temp[nr] & 0x0001;
1288 temp = (data->temp[nr] >> 5) & 0x7ff;
1290 sign = data->temp[nr] & 0x8000;
1291 temp = (data->temp[nr] >> 5) & 0x3ff;
1297 temp = data->temp[nr] * 1000;
1299 return sprintf(buf, "%d\n", temp);
1302 static ssize_t show_temp_max(struct device *dev, struct device_attribute
1303 *devattr, char *buf)
1305 struct f71882fg_data *data = f71882fg_update_device(dev);
1306 int nr = to_sensor_dev_attr_2(devattr)->index;
1308 return sprintf(buf, "%d\n", data->temp_high[nr] * 1000);
1311 static ssize_t store_temp_max(struct device *dev, struct device_attribute
1312 *devattr, const char *buf, size_t count)
1314 struct f71882fg_data *data = dev_get_drvdata(dev);
1315 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1318 err = strict_strtol(buf, 10, &val);
1323 val = SENSORS_LIMIT(val, 0, 255);
1325 mutex_lock(&data->update_lock);
1326 f71882fg_write8(data, F71882FG_REG_TEMP_HIGH(nr), val);
1327 data->temp_high[nr] = val;
1328 mutex_unlock(&data->update_lock);
1333 static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
1334 *devattr, char *buf)
1336 struct f71882fg_data *data = f71882fg_update_device(dev);
1337 int nr = to_sensor_dev_attr_2(devattr)->index;
1340 mutex_lock(&data->update_lock);
1342 temp_max_hyst = data->temp_hyst[nr / 2] >> 4;
1344 temp_max_hyst = data->temp_hyst[nr / 2] & 0x0f;
1345 temp_max_hyst = (data->temp_high[nr] - temp_max_hyst) * 1000;
1346 mutex_unlock(&data->update_lock);
1348 return sprintf(buf, "%d\n", temp_max_hyst);
1351 static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
1352 *devattr, const char *buf, size_t count)
1354 struct f71882fg_data *data = dev_get_drvdata(dev);
1355 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1356 ssize_t ret = count;
1360 err = strict_strtol(buf, 10, &val);
1366 mutex_lock(&data->update_lock);
1368 /* convert abs to relative and check */
1369 data->temp_high[nr] = f71882fg_read8(data, F71882FG_REG_TEMP_HIGH(nr));
1370 val = SENSORS_LIMIT(val, data->temp_high[nr] - 15,
1371 data->temp_high[nr]);
1372 val = data->temp_high[nr] - val;
1374 /* convert value to register contents */
1375 reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST(nr / 2));
1377 reg = (reg & 0x0f) | (val << 4);
1379 reg = (reg & 0xf0) | val;
1380 f71882fg_write8(data, F71882FG_REG_TEMP_HYST(nr / 2), reg);
1381 data->temp_hyst[nr / 2] = reg;
1383 mutex_unlock(&data->update_lock);
1387 static ssize_t show_temp_crit(struct device *dev, struct device_attribute
1388 *devattr, char *buf)
1390 struct f71882fg_data *data = f71882fg_update_device(dev);
1391 int nr = to_sensor_dev_attr_2(devattr)->index;
1393 return sprintf(buf, "%d\n", data->temp_ovt[nr] * 1000);
1396 static ssize_t store_temp_crit(struct device *dev, struct device_attribute
1397 *devattr, const char *buf, size_t count)
1399 struct f71882fg_data *data = dev_get_drvdata(dev);
1400 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1403 err = strict_strtol(buf, 10, &val);
1408 val = SENSORS_LIMIT(val, 0, 255);
1410 mutex_lock(&data->update_lock);
1411 f71882fg_write8(data, F71882FG_REG_TEMP_OVT(nr), val);
1412 data->temp_ovt[nr] = val;
1413 mutex_unlock(&data->update_lock);
1418 static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
1419 *devattr, char *buf)
1421 struct f71882fg_data *data = f71882fg_update_device(dev);
1422 int nr = to_sensor_dev_attr_2(devattr)->index;
1425 mutex_lock(&data->update_lock);
1427 temp_crit_hyst = data->temp_hyst[nr / 2] >> 4;
1429 temp_crit_hyst = data->temp_hyst[nr / 2] & 0x0f;
1430 temp_crit_hyst = (data->temp_ovt[nr] - temp_crit_hyst) * 1000;
1431 mutex_unlock(&data->update_lock);
1433 return sprintf(buf, "%d\n", temp_crit_hyst);
1436 static ssize_t show_temp_type(struct device *dev, struct device_attribute
1437 *devattr, char *buf)
1439 struct f71882fg_data *data = f71882fg_update_device(dev);
1440 int nr = to_sensor_dev_attr_2(devattr)->index;
1442 return sprintf(buf, "%d\n", data->temp_type[nr]);
1445 static ssize_t show_temp_beep(struct device *dev, struct device_attribute
1446 *devattr, char *buf)
1448 struct f71882fg_data *data = f71882fg_update_device(dev);
1449 int nr = to_sensor_dev_attr_2(devattr)->index;
1451 if (data->temp_beep & (1 << nr))
1452 return sprintf(buf, "1\n");
1454 return sprintf(buf, "0\n");
1457 static ssize_t store_temp_beep(struct device *dev, struct device_attribute
1458 *devattr, const char *buf, size_t count)
1460 struct f71882fg_data *data = dev_get_drvdata(dev);
1461 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1464 err = strict_strtoul(buf, 10, &val);
1468 mutex_lock(&data->update_lock);
1469 data->temp_beep = f71882fg_read8(data, F71882FG_REG_TEMP_BEEP);
1471 data->temp_beep |= 1 << nr;
1473 data->temp_beep &= ~(1 << nr);
1475 f71882fg_write8(data, F71882FG_REG_TEMP_BEEP, data->temp_beep);
1476 mutex_unlock(&data->update_lock);
1481 static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
1482 *devattr, char *buf)
1484 struct f71882fg_data *data = f71882fg_update_device(dev);
1485 int nr = to_sensor_dev_attr_2(devattr)->index;
1487 if (data->temp_status & (1 << nr))
1488 return sprintf(buf, "1\n");
1490 return sprintf(buf, "0\n");
1493 static ssize_t show_temp_fault(struct device *dev, struct device_attribute
1494 *devattr, char *buf)
1496 struct f71882fg_data *data = f71882fg_update_device(dev);
1497 int nr = to_sensor_dev_attr_2(devattr)->index;
1499 if (data->temp_diode_open & (1 << nr))
1500 return sprintf(buf, "1\n");
1502 return sprintf(buf, "0\n");
1505 static ssize_t show_pwm(struct device *dev,
1506 struct device_attribute *devattr, char *buf)
1508 struct f71882fg_data *data = f71882fg_update_device(dev);
1509 int val, nr = to_sensor_dev_attr_2(devattr)->index;
1510 mutex_lock(&data->update_lock);
1511 if (data->pwm_enable & (1 << (2 * nr)))
1513 val = data->pwm[nr];
1516 val = 255 * fan_from_reg(data->fan_target[nr])
1517 / fan_from_reg(data->fan_full_speed[nr]);
1519 mutex_unlock(&data->update_lock);
1520 return sprintf(buf, "%d\n", val);
1523 static ssize_t store_pwm(struct device *dev,
1524 struct device_attribute *devattr, const char *buf,
1527 struct f71882fg_data *data = dev_get_drvdata(dev);
1528 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1531 err = strict_strtol(buf, 10, &val);
1535 val = SENSORS_LIMIT(val, 0, 255);
1537 mutex_lock(&data->update_lock);
1538 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
1539 if ((data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 3) != 2) ||
1540 (data->type != f8000 && !((data->pwm_enable >> 2 * nr) & 2))) {
1544 if (data->pwm_enable & (1 << (2 * nr))) {
1546 f71882fg_write8(data, F71882FG_REG_PWM(nr), val);
1547 data->pwm[nr] = val;
1550 int target, full_speed;
1551 full_speed = f71882fg_read16(data,
1552 F71882FG_REG_FAN_FULL_SPEED(nr));
1553 target = fan_to_reg(val * fan_from_reg(full_speed) / 255);
1554 f71882fg_write16(data, F71882FG_REG_FAN_TARGET(nr), target);
1555 data->fan_target[nr] = target;
1556 data->fan_full_speed[nr] = full_speed;
1559 mutex_unlock(&data->update_lock);
1564 static ssize_t show_pwm_enable(struct device *dev,
1565 struct device_attribute *devattr, char *buf)
1568 struct f71882fg_data *data = f71882fg_update_device(dev);
1569 int nr = to_sensor_dev_attr_2(devattr)->index;
1571 switch ((data->pwm_enable >> 2 * nr) & 3) {
1574 result = 2; /* Normal auto mode */
1577 result = 1; /* Manual mode */
1580 if (data->type == f8000)
1581 result = 3; /* Thermostat mode */
1583 result = 1; /* Manual mode */
1587 return sprintf(buf, "%d\n", result);
1590 static ssize_t store_pwm_enable(struct device *dev, struct device_attribute
1591 *devattr, const char *buf, size_t count)
1593 struct f71882fg_data *data = dev_get_drvdata(dev);
1594 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1597 err = strict_strtol(buf, 10, &val);
1601 /* Special case for F8000 pwm channel 3 which only does auto mode */
1602 if (data->type == f8000 && nr == 2 && val != 2)
1605 mutex_lock(&data->update_lock);
1606 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
1607 /* Special case for F8000 auto PWM mode / Thermostat mode */
1608 if (data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 1)) {
1611 data->pwm_enable &= ~(2 << (2 * nr));
1612 break; /* Normal auto mode */
1614 data->pwm_enable |= 2 << (2 * nr);
1615 break; /* Thermostat mode */
1623 /* The f71858fg does not support manual RPM mode */
1624 if (data->type == f71858fg &&
1625 ((data->pwm_enable >> (2 * nr)) & 1)) {
1629 data->pwm_enable |= 2 << (2 * nr);
1632 data->pwm_enable &= ~(2 << (2 * nr));
1633 break; /* Normal auto mode */
1639 f71882fg_write8(data, F71882FG_REG_PWM_ENABLE, data->pwm_enable);
1641 mutex_unlock(&data->update_lock);
1646 static ssize_t show_pwm_auto_point_pwm(struct device *dev,
1647 struct device_attribute *devattr,
1651 struct f71882fg_data *data = f71882fg_update_device(dev);
1652 int pwm = to_sensor_dev_attr_2(devattr)->index;
1653 int point = to_sensor_dev_attr_2(devattr)->nr;
1655 mutex_lock(&data->update_lock);
1656 if (data->pwm_enable & (1 << (2 * pwm))) {
1658 result = data->pwm_auto_point_pwm[pwm][point];
1661 result = 32 * 255 / (32 + data->pwm_auto_point_pwm[pwm][point]);
1663 mutex_unlock(&data->update_lock);
1665 return sprintf(buf, "%d\n", result);
1668 static ssize_t store_pwm_auto_point_pwm(struct device *dev,
1669 struct device_attribute *devattr,
1670 const char *buf, size_t count)
1672 struct f71882fg_data *data = dev_get_drvdata(dev);
1673 int err, pwm = to_sensor_dev_attr_2(devattr)->index;
1674 int point = to_sensor_dev_attr_2(devattr)->nr;
1677 err = strict_strtol(buf, 10, &val);
1681 val = SENSORS_LIMIT(val, 0, 255);
1683 mutex_lock(&data->update_lock);
1684 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
1685 if (data->pwm_enable & (1 << (2 * pwm))) {
1689 if (val < 29) /* Prevent negative numbers */
1692 val = (255 - val) * 32 / val;
1694 f71882fg_write8(data, F71882FG_REG_POINT_PWM(pwm, point), val);
1695 data->pwm_auto_point_pwm[pwm][point] = val;
1696 mutex_unlock(&data->update_lock);
1701 static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
1702 struct device_attribute *devattr,
1706 struct f71882fg_data *data = f71882fg_update_device(dev);
1707 int nr = to_sensor_dev_attr_2(devattr)->index;
1708 int point = to_sensor_dev_attr_2(devattr)->nr;
1710 mutex_lock(&data->update_lock);
1712 result = data->pwm_auto_point_hyst[nr / 2] >> 4;
1714 result = data->pwm_auto_point_hyst[nr / 2] & 0x0f;
1715 result = 1000 * (data->pwm_auto_point_temp[nr][point] - result);
1716 mutex_unlock(&data->update_lock);
1718 return sprintf(buf, "%d\n", result);
1721 static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
1722 struct device_attribute *devattr,
1723 const char *buf, size_t count)
1725 struct f71882fg_data *data = dev_get_drvdata(dev);
1726 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1727 int point = to_sensor_dev_attr_2(devattr)->nr;
1731 err = strict_strtol(buf, 10, &val);
1737 mutex_lock(&data->update_lock);
1738 data->pwm_auto_point_temp[nr][point] =
1739 f71882fg_read8(data, F71882FG_REG_POINT_TEMP(nr, point));
1740 val = SENSORS_LIMIT(val, data->pwm_auto_point_temp[nr][point] - 15,
1741 data->pwm_auto_point_temp[nr][point]);
1742 val = data->pwm_auto_point_temp[nr][point] - val;
1744 reg = f71882fg_read8(data, F71882FG_REG_FAN_HYST(nr / 2));
1746 reg = (reg & 0x0f) | (val << 4);
1748 reg = (reg & 0xf0) | val;
1750 f71882fg_write8(data, F71882FG_REG_FAN_HYST(nr / 2), reg);
1751 data->pwm_auto_point_hyst[nr / 2] = reg;
1752 mutex_unlock(&data->update_lock);
1757 static ssize_t show_pwm_interpolate(struct device *dev,
1758 struct device_attribute *devattr, char *buf)
1761 struct f71882fg_data *data = f71882fg_update_device(dev);
1762 int nr = to_sensor_dev_attr_2(devattr)->index;
1764 result = (data->pwm_auto_point_mapping[nr] >> 4) & 1;
1766 return sprintf(buf, "%d\n", result);
1769 static ssize_t store_pwm_interpolate(struct device *dev,
1770 struct device_attribute *devattr,
1771 const char *buf, size_t count)
1773 struct f71882fg_data *data = dev_get_drvdata(dev);
1774 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1777 err = strict_strtoul(buf, 10, &val);
1781 mutex_lock(&data->update_lock);
1782 data->pwm_auto_point_mapping[nr] =
1783 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
1785 val = data->pwm_auto_point_mapping[nr] | (1 << 4);
1787 val = data->pwm_auto_point_mapping[nr] & (~(1 << 4));
1788 f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val);
1789 data->pwm_auto_point_mapping[nr] = val;
1790 mutex_unlock(&data->update_lock);
1795 static ssize_t show_pwm_auto_point_channel(struct device *dev,
1796 struct device_attribute *devattr,
1800 struct f71882fg_data *data = f71882fg_update_device(dev);
1801 int nr = to_sensor_dev_attr_2(devattr)->index;
1803 result = 1 << ((data->pwm_auto_point_mapping[nr] & 3) -
1806 return sprintf(buf, "%d\n", result);
1809 static ssize_t store_pwm_auto_point_channel(struct device *dev,
1810 struct device_attribute *devattr,
1811 const char *buf, size_t count)
1813 struct f71882fg_data *data = dev_get_drvdata(dev);
1814 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1817 err = strict_strtol(buf, 10, &val);
1834 val += data->temp_start;
1835 mutex_lock(&data->update_lock);
1836 data->pwm_auto_point_mapping[nr] =
1837 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
1838 val = (data->pwm_auto_point_mapping[nr] & 0xfc) | val;
1839 f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val);
1840 data->pwm_auto_point_mapping[nr] = val;
1841 mutex_unlock(&data->update_lock);
1846 static ssize_t show_pwm_auto_point_temp(struct device *dev,
1847 struct device_attribute *devattr,
1851 struct f71882fg_data *data = f71882fg_update_device(dev);
1852 int pwm = to_sensor_dev_attr_2(devattr)->index;
1853 int point = to_sensor_dev_attr_2(devattr)->nr;
1855 result = data->pwm_auto_point_temp[pwm][point];
1856 return sprintf(buf, "%d\n", 1000 * result);
1859 static ssize_t store_pwm_auto_point_temp(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, pwm = to_sensor_dev_attr_2(devattr)->index;
1865 int point = to_sensor_dev_attr_2(devattr)->nr;
1868 err = strict_strtol(buf, 10, &val);
1874 if (data->type == f71889fg)
1875 val = SENSORS_LIMIT(val, -128, 127);
1877 val = SENSORS_LIMIT(val, 0, 127);
1879 mutex_lock(&data->update_lock);
1880 f71882fg_write8(data, F71882FG_REG_POINT_TEMP(pwm, point), val);
1881 data->pwm_auto_point_temp[pwm][point] = val;
1882 mutex_unlock(&data->update_lock);
1887 static ssize_t show_name(struct device *dev, struct device_attribute *devattr,
1890 struct f71882fg_data *data = dev_get_drvdata(dev);
1891 return sprintf(buf, "%s\n", f71882fg_names[data->type]);
1894 static int __devinit f71882fg_create_sysfs_files(struct platform_device *pdev,
1895 struct sensor_device_attribute_2 *attr, int count)
1899 for (i = 0; i < count; i++) {
1900 err = device_create_file(&pdev->dev, &attr[i].dev_attr);
1907 static void f71882fg_remove_sysfs_files(struct platform_device *pdev,
1908 struct sensor_device_attribute_2 *attr, int count)
1912 for (i = 0; i < count; i++)
1913 device_remove_file(&pdev->dev, &attr[i].dev_attr);
1916 static int __devinit f71882fg_probe(struct platform_device *pdev)
1918 struct f71882fg_data *data;
1919 struct f71882fg_sio_data *sio_data = pdev->dev.platform_data;
1920 int err, i, nr_fans = (sio_data->type == f71882fg) ? 4 : 3;
1923 data = kzalloc(sizeof(struct f71882fg_data), GFP_KERNEL);
1927 data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start;
1928 data->type = sio_data->type;
1930 (data->type == f71858fg || data->type == f8000) ? 0 : 1;
1931 mutex_init(&data->update_lock);
1932 platform_set_drvdata(pdev, data);
1934 start_reg = f71882fg_read8(data, F71882FG_REG_START);
1935 if (start_reg & 0x04) {
1936 dev_warn(&pdev->dev, "Hardware monitor is powered down\n");
1940 if (!(start_reg & 0x03)) {
1941 dev_warn(&pdev->dev, "Hardware monitoring not activated\n");
1946 /* Register sysfs interface files */
1947 err = device_create_file(&pdev->dev, &dev_attr_name);
1949 goto exit_unregister_sysfs;
1951 if (start_reg & 0x01) {
1952 switch (data->type) {
1955 f71882fg_read8(data, F71882FG_REG_TEMP_CONFIG);
1956 if (data->temp_config & 0x10)
1957 /* The f71858fg temperature alarms behave as
1958 the f8000 alarms in this mode */
1959 err = f71882fg_create_sysfs_files(pdev,
1961 ARRAY_SIZE(f8000_in_temp_attr));
1963 err = f71882fg_create_sysfs_files(pdev,
1964 f71858fg_in_temp_attr,
1965 ARRAY_SIZE(f71858fg_in_temp_attr));
1969 err = f71882fg_create_sysfs_files(pdev,
1970 fxxxx_in1_alarm_attr,
1971 ARRAY_SIZE(fxxxx_in1_alarm_attr));
1973 goto exit_unregister_sysfs;
1976 err = f71882fg_create_sysfs_files(pdev,
1978 ARRAY_SIZE(fxxxx_in_temp_attr));
1981 err = f71882fg_create_sysfs_files(pdev,
1983 ARRAY_SIZE(f8000_in_temp_attr));
1987 goto exit_unregister_sysfs;
1990 if (start_reg & 0x02) {
1992 f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
1994 /* Sanity check the pwm settings */
1995 switch (data->type) {
1998 for (i = 0; i < nr_fans; i++)
1999 if (((data->pwm_enable >> (i * 2)) & 3) == 3)
2003 err = (data->pwm_enable & 0x15) != 0x15;
2010 err = data->pwm_enable & 0x20;
2015 "Invalid (reserved) pwm settings: 0x%02x\n",
2016 (unsigned int)data->pwm_enable);
2018 goto exit_unregister_sysfs;
2021 err = f71882fg_create_sysfs_files(pdev, &fxxxx_fan_attr[0][0],
2022 ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans);
2024 goto exit_unregister_sysfs;
2026 if (data->type == f71862fg || data->type == f71882fg ||
2027 data->type == f71889fg) {
2028 err = f71882fg_create_sysfs_files(pdev,
2029 fxxxx_fan_beep_attr, nr_fans);
2031 goto exit_unregister_sysfs;
2034 switch (data->type) {
2036 err = f71882fg_create_sysfs_files(pdev,
2037 f71862fg_auto_pwm_attr,
2038 ARRAY_SIZE(f71862fg_auto_pwm_attr));
2041 err = f71882fg_create_sysfs_files(pdev,
2043 ARRAY_SIZE(f8000_fan_attr));
2045 goto exit_unregister_sysfs;
2046 err = f71882fg_create_sysfs_files(pdev,
2047 f8000_auto_pwm_attr,
2048 ARRAY_SIZE(f8000_auto_pwm_attr));
2051 for (i = 0; i < nr_fans; i++) {
2052 data->pwm_auto_point_mapping[i] =
2053 f71882fg_read8(data,
2054 F71882FG_REG_POINT_MAPPING(i));
2055 if (data->pwm_auto_point_mapping[i] & 0x80)
2059 dev_warn(&pdev->dev,
2060 "Auto pwm controlled by raw digital "
2061 "data, disabling pwm auto_point "
2062 "sysfs attributes\n");
2066 default: /* f71858fg / f71882fg */
2067 err = f71882fg_create_sysfs_files(pdev,
2068 &fxxxx_auto_pwm_attr[0][0],
2069 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
2072 goto exit_unregister_sysfs;
2074 for (i = 0; i < nr_fans; i++)
2075 dev_info(&pdev->dev, "Fan: %d is in %s mode\n", i + 1,
2076 (data->pwm_enable & (1 << 2 * i)) ?
2077 "duty-cycle" : "RPM");
2080 data->hwmon_dev = hwmon_device_register(&pdev->dev);
2081 if (IS_ERR(data->hwmon_dev)) {
2082 err = PTR_ERR(data->hwmon_dev);
2083 data->hwmon_dev = NULL;
2084 goto exit_unregister_sysfs;
2089 exit_unregister_sysfs:
2090 f71882fg_remove(pdev); /* Will unregister the sysfs files for us */
2091 return err; /* f71882fg_remove() also frees our data */
2097 static int f71882fg_remove(struct platform_device *pdev)
2099 struct f71882fg_data *data = platform_get_drvdata(pdev);
2100 int nr_fans = (data->type == f71882fg) ? 4 : 3;
2101 u8 start_reg = f71882fg_read8(data, F71882FG_REG_START);
2103 platform_set_drvdata(pdev, NULL);
2104 if (data->hwmon_dev)
2105 hwmon_device_unregister(data->hwmon_dev);
2107 device_remove_file(&pdev->dev, &dev_attr_name);
2109 if (start_reg & 0x01) {
2110 switch (data->type) {
2112 if (data->temp_config & 0x10)
2113 f71882fg_remove_sysfs_files(pdev,
2115 ARRAY_SIZE(f8000_in_temp_attr));
2117 f71882fg_remove_sysfs_files(pdev,
2118 f71858fg_in_temp_attr,
2119 ARRAY_SIZE(f71858fg_in_temp_attr));
2123 f71882fg_remove_sysfs_files(pdev,
2124 fxxxx_in1_alarm_attr,
2125 ARRAY_SIZE(fxxxx_in1_alarm_attr));
2128 f71882fg_remove_sysfs_files(pdev,
2130 ARRAY_SIZE(fxxxx_in_temp_attr));
2133 f71882fg_remove_sysfs_files(pdev,
2135 ARRAY_SIZE(f8000_in_temp_attr));
2140 if (start_reg & 0x02) {
2141 f71882fg_remove_sysfs_files(pdev, &fxxxx_fan_attr[0][0],
2142 ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans);
2144 if (data->type == f71862fg || data->type == f71882fg ||
2145 data->type == f71889fg)
2146 f71882fg_remove_sysfs_files(pdev,
2147 fxxxx_fan_beep_attr, nr_fans);
2149 switch (data->type) {
2151 f71882fg_remove_sysfs_files(pdev,
2152 f71862fg_auto_pwm_attr,
2153 ARRAY_SIZE(f71862fg_auto_pwm_attr));
2156 f71882fg_remove_sysfs_files(pdev,
2158 ARRAY_SIZE(f8000_fan_attr));
2159 f71882fg_remove_sysfs_files(pdev,
2160 f8000_auto_pwm_attr,
2161 ARRAY_SIZE(f8000_auto_pwm_attr));
2163 default: /* f71858fg / f71882fg / f71889fg */
2164 f71882fg_remove_sysfs_files(pdev,
2165 &fxxxx_auto_pwm_attr[0][0],
2166 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
2175 static int __init f71882fg_find(int sioaddr, unsigned short *address,
2176 struct f71882fg_sio_data *sio_data)
2181 /* Don't step on other drivers' I/O space by accident */
2182 if (!request_region(sioaddr, 2, DRVNAME)) {
2183 printk(KERN_ERR DRVNAME ": I/O address 0x%04x already in use\n",
2188 superio_enter(sioaddr);
2190 devid = superio_inw(sioaddr, SIO_REG_MANID);
2191 if (devid != SIO_FINTEK_ID) {
2192 pr_debug(DRVNAME ": Not a Fintek device\n");
2196 devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID);
2199 sio_data->type = f71858fg;
2202 sio_data->type = f71862fg;
2205 sio_data->type = f71882fg;
2208 sio_data->type = f71889fg;
2211 sio_data->type = f8000;
2214 printk(KERN_INFO DRVNAME ": Unsupported Fintek device: %04x\n",
2215 (unsigned int)devid);
2219 if (sio_data->type == f71858fg)
2220 superio_select(sioaddr, SIO_F71858FG_LD_HWM);
2222 superio_select(sioaddr, SIO_F71882FG_LD_HWM);
2224 if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) {
2225 printk(KERN_WARNING DRVNAME ": Device not activated\n");
2229 *address = superio_inw(sioaddr, SIO_REG_ADDR);
2230 if (*address == 0) {
2231 printk(KERN_WARNING DRVNAME ": Base address not set\n");
2234 *address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */
2237 printk(KERN_INFO DRVNAME ": Found %s chip at %#x, revision %d\n",
2238 f71882fg_names[sio_data->type], (unsigned int)*address,
2239 (int)superio_inb(sioaddr, SIO_REG_DEVREV));
2241 superio_exit(sioaddr);
2242 release_region(sioaddr, 2);
2246 static int __init f71882fg_device_add(unsigned short address,
2247 const struct f71882fg_sio_data *sio_data)
2249 struct resource res = {
2251 .end = address + REGION_LENGTH - 1,
2252 .flags = IORESOURCE_IO,
2256 f71882fg_pdev = platform_device_alloc(DRVNAME, address);
2260 res.name = f71882fg_pdev->name;
2261 err = acpi_check_resource_conflict(&res);
2263 goto exit_device_put;
2265 err = platform_device_add_resources(f71882fg_pdev, &res, 1);
2267 printk(KERN_ERR DRVNAME ": Device resource addition failed\n");
2268 goto exit_device_put;
2271 err = platform_device_add_data(f71882fg_pdev, sio_data,
2272 sizeof(struct f71882fg_sio_data));
2274 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n");
2275 goto exit_device_put;
2278 err = platform_device_add(f71882fg_pdev);
2280 printk(KERN_ERR DRVNAME ": Device addition failed\n");
2281 goto exit_device_put;
2287 platform_device_put(f71882fg_pdev);
2292 static int __init f71882fg_init(void)
2295 unsigned short address;
2296 struct f71882fg_sio_data sio_data;
2298 memset(&sio_data, 0, sizeof(sio_data));
2300 if (f71882fg_find(0x2e, &address, &sio_data) &&
2301 f71882fg_find(0x4e, &address, &sio_data))
2304 err = platform_driver_register(&f71882fg_driver);
2308 err = f71882fg_device_add(address, &sio_data);
2315 platform_driver_unregister(&f71882fg_driver);
2320 static void __exit f71882fg_exit(void)
2322 platform_device_unregister(f71882fg_pdev);
2323 platform_driver_unregister(&f71882fg_driver);
2326 MODULE_DESCRIPTION("F71882FG Hardware Monitoring Driver");
2327 MODULE_AUTHOR("Hans Edgington, Hans de Goede (hdegoede@redhat.com)");
2328 MODULE_LICENSE("GPL");
2330 module_init(f71882fg_init);
2331 module_exit(f71882fg_exit);