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_F8000_ID 0x0581 /* Chipset ID */
53 #define REGION_LENGTH 8
54 #define ADDR_REG_OFFSET 5
55 #define DATA_REG_OFFSET 6
57 #define F71882FG_REG_PECI 0x0A
59 #define F71882FG_REG_IN_STATUS 0x12 /* f71882fg only */
60 #define F71882FG_REG_IN_BEEP 0x13 /* f71882fg only */
61 #define F71882FG_REG_IN(nr) (0x20 + (nr))
62 #define F71882FG_REG_IN1_HIGH 0x32 /* f71882fg only */
64 #define F71882FG_REG_FAN(nr) (0xA0 + (16 * (nr)))
65 #define F71882FG_REG_FAN_TARGET(nr) (0xA2 + (16 * (nr)))
66 #define F71882FG_REG_FAN_FULL_SPEED(nr) (0xA4 + (16 * (nr)))
67 #define F71882FG_REG_FAN_STATUS 0x92
68 #define F71882FG_REG_FAN_BEEP 0x93
70 #define F71882FG_REG_TEMP(nr) (0x70 + 2 * (nr))
71 #define F71882FG_REG_TEMP_OVT(nr) (0x80 + 2 * (nr))
72 #define F71882FG_REG_TEMP_HIGH(nr) (0x81 + 2 * (nr))
73 #define F71882FG_REG_TEMP_STATUS 0x62
74 #define F71882FG_REG_TEMP_BEEP 0x63
75 #define F71882FG_REG_TEMP_CONFIG 0x69
76 #define F71882FG_REG_TEMP_HYST(nr) (0x6C + (nr))
77 #define F71882FG_REG_TEMP_TYPE 0x6B
78 #define F71882FG_REG_TEMP_DIODE_OPEN 0x6F
80 #define F71882FG_REG_PWM(nr) (0xA3 + (16 * (nr)))
81 #define F71882FG_REG_PWM_TYPE 0x94
82 #define F71882FG_REG_PWM_ENABLE 0x96
84 #define F71882FG_REG_FAN_HYST(nr) (0x98 + (nr))
86 #define F71882FG_REG_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm)))
87 #define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm)))
88 #define F71882FG_REG_POINT_MAPPING(nr) (0xAF + 16 * (nr))
90 #define F71882FG_REG_START 0x01
92 #define FAN_MIN_DETECT 366 /* Lowest detectable fanspeed */
94 static unsigned short force_id;
95 module_param(force_id, ushort, 0);
96 MODULE_PARM_DESC(force_id, "Override the detected device ID");
98 enum chips { f71858fg, f71862fg, f71882fg, f8000 };
100 static const char *f71882fg_names[] = {
107 static struct platform_device *f71882fg_pdev;
109 /* Super-I/O Function prototypes */
110 static inline int superio_inb(int base, int reg);
111 static inline int superio_inw(int base, int reg);
112 static inline void superio_enter(int base);
113 static inline void superio_select(int base, int ld);
114 static inline void superio_exit(int base);
116 struct f71882fg_sio_data {
120 struct f71882fg_data {
123 struct device *hwmon_dev;
125 struct mutex update_lock;
126 int temp_start; /* temp numbering start (0 or 1) */
127 char valid; /* !=0 if following fields are valid */
128 unsigned long last_updated; /* In jiffies */
129 unsigned long last_limits; /* In jiffies */
131 /* Register Values */
138 u16 fan_full_speed[4];
141 /* Note: all models have only 3 temperature channels, but on some
142 they are addressed as 0-2 and on others as 1-3, so for coding
143 convenience we reserve space for 4 channels */
147 u8 temp_hyst[2]; /* 2 hysts stored per reg */
155 u8 pwm_auto_point_hyst[2];
156 u8 pwm_auto_point_mapping[4];
157 u8 pwm_auto_point_pwm[4][5];
158 u8 pwm_auto_point_temp[4][4];
162 static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
164 static ssize_t show_in_max(struct device *dev, struct device_attribute
165 *devattr, char *buf);
166 static ssize_t store_in_max(struct device *dev, struct device_attribute
167 *devattr, const char *buf, size_t count);
168 static ssize_t show_in_beep(struct device *dev, struct device_attribute
169 *devattr, char *buf);
170 static ssize_t store_in_beep(struct device *dev, struct device_attribute
171 *devattr, const char *buf, size_t count);
172 static ssize_t show_in_alarm(struct device *dev, struct device_attribute
173 *devattr, char *buf);
175 static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
177 static ssize_t show_fan_full_speed(struct device *dev,
178 struct device_attribute *devattr, char *buf);
179 static ssize_t store_fan_full_speed(struct device *dev,
180 struct device_attribute *devattr, const char *buf, size_t count);
181 static ssize_t show_fan_beep(struct device *dev, struct device_attribute
182 *devattr, char *buf);
183 static ssize_t store_fan_beep(struct device *dev, struct device_attribute
184 *devattr, const char *buf, size_t count);
185 static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
186 *devattr, char *buf);
188 static ssize_t show_temp(struct device *dev, struct device_attribute
189 *devattr, char *buf);
190 static ssize_t show_temp_max(struct device *dev, struct device_attribute
191 *devattr, char *buf);
192 static ssize_t store_temp_max(struct device *dev, struct device_attribute
193 *devattr, const char *buf, size_t count);
194 static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
195 *devattr, char *buf);
196 static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
197 *devattr, const char *buf, size_t count);
198 static ssize_t show_temp_crit(struct device *dev, struct device_attribute
199 *devattr, char *buf);
200 static ssize_t store_temp_crit(struct device *dev, struct device_attribute
201 *devattr, const char *buf, size_t count);
202 static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
203 *devattr, char *buf);
204 static ssize_t show_temp_type(struct device *dev, struct device_attribute
205 *devattr, char *buf);
206 static ssize_t show_temp_beep(struct device *dev, struct device_attribute
207 *devattr, char *buf);
208 static ssize_t store_temp_beep(struct device *dev, struct device_attribute
209 *devattr, const char *buf, size_t count);
210 static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
211 *devattr, char *buf);
212 static ssize_t show_temp_fault(struct device *dev, struct device_attribute
213 *devattr, char *buf);
214 /* PWM and Auto point control */
215 static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
217 static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr,
218 const char *buf, size_t count);
219 static ssize_t show_pwm_enable(struct device *dev,
220 struct device_attribute *devattr, char *buf);
221 static ssize_t store_pwm_enable(struct device *dev,
222 struct device_attribute *devattr, const char *buf, size_t count);
223 static ssize_t show_pwm_interpolate(struct device *dev,
224 struct device_attribute *devattr, char *buf);
225 static ssize_t store_pwm_interpolate(struct device *dev,
226 struct device_attribute *devattr, const char *buf, size_t count);
227 static ssize_t show_pwm_auto_point_channel(struct device *dev,
228 struct device_attribute *devattr, char *buf);
229 static ssize_t store_pwm_auto_point_channel(struct device *dev,
230 struct device_attribute *devattr, const char *buf, size_t count);
231 static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
232 struct device_attribute *devattr, char *buf);
233 static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
234 struct device_attribute *devattr, const char *buf, size_t count);
235 static ssize_t show_pwm_auto_point_pwm(struct device *dev,
236 struct device_attribute *devattr, char *buf);
237 static ssize_t store_pwm_auto_point_pwm(struct device *dev,
238 struct device_attribute *devattr, const char *buf, size_t count);
239 static ssize_t show_pwm_auto_point_temp(struct device *dev,
240 struct device_attribute *devattr, char *buf);
241 static ssize_t store_pwm_auto_point_temp(struct device *dev,
242 struct device_attribute *devattr, const char *buf, size_t count);
244 static ssize_t show_name(struct device *dev, struct device_attribute *devattr,
247 static int __devinit f71882fg_probe(struct platform_device * pdev);
248 static int f71882fg_remove(struct platform_device *pdev);
250 static struct platform_driver f71882fg_driver = {
252 .owner = THIS_MODULE,
255 .probe = f71882fg_probe,
256 .remove = f71882fg_remove,
259 static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
261 /* Temp and in attr for the f71858fg, the f71858fg is special as it
262 has its temperature indexes start at 0 (the others start at 1) and
263 it only has 3 voltage inputs */
264 static struct sensor_device_attribute_2 f71858fg_in_temp_attr[] = {
265 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
266 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
267 SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2),
268 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
269 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
270 store_temp_max, 0, 0),
271 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
272 store_temp_max_hyst, 0, 0),
273 SENSOR_ATTR_2(temp1_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 0),
274 SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
275 store_temp_crit, 0, 0),
276 SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
278 SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4),
279 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0),
280 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1),
281 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max,
282 store_temp_max, 0, 1),
283 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
284 store_temp_max_hyst, 0, 1),
285 SENSOR_ATTR_2(temp2_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
286 SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
287 store_temp_crit, 0, 1),
288 SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
290 SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
291 SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 1),
292 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
293 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2),
294 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
295 store_temp_max, 0, 2),
296 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
297 store_temp_max_hyst, 0, 2),
298 SENSOR_ATTR_2(temp3_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
299 SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit,
300 store_temp_crit, 0, 2),
301 SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
303 SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
304 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
307 /* Temp and in attr common to the f71862fg, f71882fg and f71889fg */
308 static struct sensor_device_attribute_2 fxxxx_in_temp_attr[] = {
309 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
310 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
311 SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2),
312 SENSOR_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 0, 3),
313 SENSOR_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 0, 4),
314 SENSOR_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 0, 5),
315 SENSOR_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 0, 6),
316 SENSOR_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 0, 7),
317 SENSOR_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 0, 8),
318 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 1),
319 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
320 store_temp_max, 0, 1),
321 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
322 store_temp_max_hyst, 0, 1),
323 /* Should really be temp1_max_alarm, but older versions did not handle
324 the max and crit alarms separately and lm_sensors v2 depends on the
325 presence of temp#_alarm files. The same goes for temp2/3 _alarm. */
326 SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
327 SENSOR_ATTR_2(temp1_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
328 store_temp_beep, 0, 1),
329 SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
330 store_temp_crit, 0, 1),
331 SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
333 SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
334 SENSOR_ATTR_2(temp1_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
335 store_temp_beep, 0, 5),
336 SENSOR_ATTR_2(temp1_type, S_IRUGO, show_temp_type, NULL, 0, 1),
337 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
338 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 2),
339 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max,
340 store_temp_max, 0, 2),
341 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
342 store_temp_max_hyst, 0, 2),
343 /* Should be temp2_max_alarm, see temp1_alarm note */
344 SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
345 SENSOR_ATTR_2(temp2_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
346 store_temp_beep, 0, 2),
347 SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
348 store_temp_crit, 0, 2),
349 SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
351 SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
352 SENSOR_ATTR_2(temp2_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
353 store_temp_beep, 0, 6),
354 SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 2),
355 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
356 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 3),
357 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
358 store_temp_max, 0, 3),
359 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
360 store_temp_max_hyst, 0, 3),
361 /* Should be temp3_max_alarm, see temp1_alarm note */
362 SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 3),
363 SENSOR_ATTR_2(temp3_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
364 store_temp_beep, 0, 3),
365 SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit,
366 store_temp_crit, 0, 3),
367 SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
369 SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 7),
370 SENSOR_ATTR_2(temp3_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
371 store_temp_beep, 0, 7),
372 SENSOR_ATTR_2(temp3_type, S_IRUGO, show_temp_type, NULL, 0, 3),
373 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 3),
376 /* For models with in1 alarm capability */
377 static struct sensor_device_attribute_2 fxxxx_in1_alarm_attr[] = {
378 SENSOR_ATTR_2(in1_max, S_IRUGO|S_IWUSR, show_in_max, store_in_max,
380 SENSOR_ATTR_2(in1_beep, S_IRUGO|S_IWUSR, show_in_beep, store_in_beep,
382 SENSOR_ATTR_2(in1_alarm, S_IRUGO, show_in_alarm, NULL, 0, 1),
385 /* Temp and in attr for the f8000
386 Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max)
387 is used as hysteresis value to clear alarms
388 Also like the f71858fg its temperature indexes start at 0
390 static struct sensor_device_attribute_2 f8000_in_temp_attr[] = {
391 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
392 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
393 SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2),
394 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
395 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_crit,
396 store_temp_crit, 0, 0),
397 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
398 store_temp_max, 0, 0),
399 SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4),
400 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0),
401 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1),
402 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_crit,
403 store_temp_crit, 0, 1),
404 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
405 store_temp_max, 0, 1),
406 SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
407 SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 1),
408 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
409 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2),
410 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_crit,
411 store_temp_crit, 0, 2),
412 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
413 store_temp_max, 0, 2),
414 SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
415 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
418 /* Fan / PWM attr common to all models */
419 static struct sensor_device_attribute_2 fxxxx_fan_attr[4][6] = { {
420 SENSOR_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0),
421 SENSOR_ATTR_2(fan1_full_speed, S_IRUGO|S_IWUSR,
423 store_fan_full_speed, 0, 0),
424 SENSOR_ATTR_2(fan1_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 0),
425 SENSOR_ATTR_2(pwm1, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 0),
426 SENSOR_ATTR_2(pwm1_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
427 store_pwm_enable, 0, 0),
428 SENSOR_ATTR_2(pwm1_interpolate, S_IRUGO|S_IWUSR,
429 show_pwm_interpolate, store_pwm_interpolate, 0, 0),
431 SENSOR_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 0, 1),
432 SENSOR_ATTR_2(fan2_full_speed, S_IRUGO|S_IWUSR,
434 store_fan_full_speed, 0, 1),
435 SENSOR_ATTR_2(fan2_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 1),
436 SENSOR_ATTR_2(pwm2, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 1),
437 SENSOR_ATTR_2(pwm2_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
438 store_pwm_enable, 0, 1),
439 SENSOR_ATTR_2(pwm2_interpolate, S_IRUGO|S_IWUSR,
440 show_pwm_interpolate, store_pwm_interpolate, 0, 1),
442 SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
443 SENSOR_ATTR_2(fan3_full_speed, S_IRUGO|S_IWUSR,
445 store_fan_full_speed, 0, 2),
446 SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
447 SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 2),
448 SENSOR_ATTR_2(pwm3_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
449 store_pwm_enable, 0, 2),
450 SENSOR_ATTR_2(pwm3_interpolate, S_IRUGO|S_IWUSR,
451 show_pwm_interpolate, store_pwm_interpolate, 0, 2),
453 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
454 SENSOR_ATTR_2(fan4_full_speed, S_IRUGO|S_IWUSR,
456 store_fan_full_speed, 0, 3),
457 SENSOR_ATTR_2(fan4_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 3),
458 SENSOR_ATTR_2(pwm4, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 3),
459 SENSOR_ATTR_2(pwm4_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
460 store_pwm_enable, 0, 3),
461 SENSOR_ATTR_2(pwm4_interpolate, S_IRUGO|S_IWUSR,
462 show_pwm_interpolate, store_pwm_interpolate, 0, 3),
465 /* Attr for models which can beep on Fan alarm */
466 static struct sensor_device_attribute_2 fxxxx_fan_beep_attr[] = {
467 SENSOR_ATTR_2(fan1_beep, S_IRUGO|S_IWUSR, show_fan_beep,
468 store_fan_beep, 0, 0),
469 SENSOR_ATTR_2(fan2_beep, S_IRUGO|S_IWUSR, show_fan_beep,
470 store_fan_beep, 0, 1),
471 SENSOR_ATTR_2(fan3_beep, S_IRUGO|S_IWUSR, show_fan_beep,
472 store_fan_beep, 0, 2),
473 SENSOR_ATTR_2(fan4_beep, S_IRUGO|S_IWUSR, show_fan_beep,
474 store_fan_beep, 0, 3),
477 /* PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
478 f71858fg / f71882fg / f71889fg */
479 static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr[] = {
480 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
481 show_pwm_auto_point_channel,
482 store_pwm_auto_point_channel, 0, 0),
483 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
484 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
486 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
487 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
489 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
490 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
492 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
493 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
495 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
496 show_pwm_auto_point_temp_hyst,
497 store_pwm_auto_point_temp_hyst,
499 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
500 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
502 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
503 show_pwm_auto_point_channel,
504 store_pwm_auto_point_channel, 0, 1),
505 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
506 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
508 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
509 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
511 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
512 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
514 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
515 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
517 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
518 show_pwm_auto_point_temp_hyst,
519 store_pwm_auto_point_temp_hyst,
521 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
522 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
524 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
525 show_pwm_auto_point_channel,
526 store_pwm_auto_point_channel, 0, 2),
527 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
528 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
530 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
531 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
533 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
534 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
536 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
537 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
539 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
540 show_pwm_auto_point_temp_hyst,
541 store_pwm_auto_point_temp_hyst,
543 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
544 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
547 /* PWM attr common to the f71858fg, f71882fg and f71889fg */
548 static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr[4][14] = { {
549 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
550 show_pwm_auto_point_channel,
551 store_pwm_auto_point_channel, 0, 0),
552 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
553 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
555 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
556 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
558 SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO|S_IWUSR,
559 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
561 SENSOR_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO|S_IWUSR,
562 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
564 SENSOR_ATTR_2(pwm1_auto_point5_pwm, S_IRUGO|S_IWUSR,
565 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
567 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
568 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
570 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
571 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
573 SENSOR_ATTR_2(pwm1_auto_point3_temp, S_IRUGO|S_IWUSR,
574 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
576 SENSOR_ATTR_2(pwm1_auto_point4_temp, S_IRUGO|S_IWUSR,
577 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
579 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
580 show_pwm_auto_point_temp_hyst,
581 store_pwm_auto_point_temp_hyst,
583 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
584 show_pwm_auto_point_temp_hyst, NULL, 1, 0),
585 SENSOR_ATTR_2(pwm1_auto_point3_temp_hyst, S_IRUGO,
586 show_pwm_auto_point_temp_hyst, NULL, 2, 0),
587 SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst, S_IRUGO,
588 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
590 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
591 show_pwm_auto_point_channel,
592 store_pwm_auto_point_channel, 0, 1),
593 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
594 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
596 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
597 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
599 SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO|S_IWUSR,
600 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
602 SENSOR_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO|S_IWUSR,
603 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
605 SENSOR_ATTR_2(pwm2_auto_point5_pwm, S_IRUGO|S_IWUSR,
606 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
608 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
609 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
611 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
612 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
614 SENSOR_ATTR_2(pwm2_auto_point3_temp, S_IRUGO|S_IWUSR,
615 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
617 SENSOR_ATTR_2(pwm2_auto_point4_temp, S_IRUGO|S_IWUSR,
618 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
620 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
621 show_pwm_auto_point_temp_hyst,
622 store_pwm_auto_point_temp_hyst,
624 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
625 show_pwm_auto_point_temp_hyst, NULL, 1, 1),
626 SENSOR_ATTR_2(pwm2_auto_point3_temp_hyst, S_IRUGO,
627 show_pwm_auto_point_temp_hyst, NULL, 2, 1),
628 SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst, S_IRUGO,
629 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
631 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
632 show_pwm_auto_point_channel,
633 store_pwm_auto_point_channel, 0, 2),
634 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
635 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
637 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
638 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
640 SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO|S_IWUSR,
641 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
643 SENSOR_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO|S_IWUSR,
644 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
646 SENSOR_ATTR_2(pwm3_auto_point5_pwm, S_IRUGO|S_IWUSR,
647 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
649 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
650 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
652 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
653 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
655 SENSOR_ATTR_2(pwm3_auto_point3_temp, S_IRUGO|S_IWUSR,
656 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
658 SENSOR_ATTR_2(pwm3_auto_point4_temp, S_IRUGO|S_IWUSR,
659 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
661 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
662 show_pwm_auto_point_temp_hyst,
663 store_pwm_auto_point_temp_hyst,
665 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
666 show_pwm_auto_point_temp_hyst, NULL, 1, 2),
667 SENSOR_ATTR_2(pwm3_auto_point3_temp_hyst, S_IRUGO,
668 show_pwm_auto_point_temp_hyst, NULL, 2, 2),
669 SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst, S_IRUGO,
670 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
672 SENSOR_ATTR_2(pwm4_auto_channels_temp, S_IRUGO|S_IWUSR,
673 show_pwm_auto_point_channel,
674 store_pwm_auto_point_channel, 0, 3),
675 SENSOR_ATTR_2(pwm4_auto_point1_pwm, S_IRUGO|S_IWUSR,
676 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
678 SENSOR_ATTR_2(pwm4_auto_point2_pwm, S_IRUGO|S_IWUSR,
679 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
681 SENSOR_ATTR_2(pwm4_auto_point3_pwm, S_IRUGO|S_IWUSR,
682 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
684 SENSOR_ATTR_2(pwm4_auto_point4_pwm, S_IRUGO|S_IWUSR,
685 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
687 SENSOR_ATTR_2(pwm4_auto_point5_pwm, S_IRUGO|S_IWUSR,
688 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
690 SENSOR_ATTR_2(pwm4_auto_point1_temp, S_IRUGO|S_IWUSR,
691 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
693 SENSOR_ATTR_2(pwm4_auto_point2_temp, S_IRUGO|S_IWUSR,
694 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
696 SENSOR_ATTR_2(pwm4_auto_point3_temp, S_IRUGO|S_IWUSR,
697 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
699 SENSOR_ATTR_2(pwm4_auto_point4_temp, S_IRUGO|S_IWUSR,
700 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
702 SENSOR_ATTR_2(pwm4_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
703 show_pwm_auto_point_temp_hyst,
704 store_pwm_auto_point_temp_hyst,
706 SENSOR_ATTR_2(pwm4_auto_point2_temp_hyst, S_IRUGO,
707 show_pwm_auto_point_temp_hyst, NULL, 1, 3),
708 SENSOR_ATTR_2(pwm4_auto_point3_temp_hyst, S_IRUGO,
709 show_pwm_auto_point_temp_hyst, NULL, 2, 3),
710 SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst, S_IRUGO,
711 show_pwm_auto_point_temp_hyst, NULL, 3, 3),
714 /* Fan attr specific to the f8000 (4th fan input can only measure speed) */
715 static struct sensor_device_attribute_2 f8000_fan_attr[] = {
716 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
719 /* PWM attr for the f8000, zones mapped to temp instead of to pwm!
720 Also the register block at offset A0 maps to TEMP1 (so our temp2, as the
721 F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0 */
722 static struct sensor_device_attribute_2 f8000_auto_pwm_attr[] = {
723 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
724 show_pwm_auto_point_channel,
725 store_pwm_auto_point_channel, 0, 0),
726 SENSOR_ATTR_2(temp1_auto_point1_pwm, S_IRUGO|S_IWUSR,
727 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
729 SENSOR_ATTR_2(temp1_auto_point2_pwm, S_IRUGO|S_IWUSR,
730 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
732 SENSOR_ATTR_2(temp1_auto_point3_pwm, S_IRUGO|S_IWUSR,
733 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
735 SENSOR_ATTR_2(temp1_auto_point4_pwm, S_IRUGO|S_IWUSR,
736 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
738 SENSOR_ATTR_2(temp1_auto_point5_pwm, S_IRUGO|S_IWUSR,
739 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
741 SENSOR_ATTR_2(temp1_auto_point1_temp, S_IRUGO|S_IWUSR,
742 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
744 SENSOR_ATTR_2(temp1_auto_point2_temp, S_IRUGO|S_IWUSR,
745 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
747 SENSOR_ATTR_2(temp1_auto_point3_temp, S_IRUGO|S_IWUSR,
748 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
750 SENSOR_ATTR_2(temp1_auto_point4_temp, S_IRUGO|S_IWUSR,
751 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
753 SENSOR_ATTR_2(temp1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
754 show_pwm_auto_point_temp_hyst,
755 store_pwm_auto_point_temp_hyst,
757 SENSOR_ATTR_2(temp1_auto_point2_temp_hyst, S_IRUGO,
758 show_pwm_auto_point_temp_hyst, NULL, 1, 2),
759 SENSOR_ATTR_2(temp1_auto_point3_temp_hyst, S_IRUGO,
760 show_pwm_auto_point_temp_hyst, NULL, 2, 2),
761 SENSOR_ATTR_2(temp1_auto_point4_temp_hyst, S_IRUGO,
762 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
764 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
765 show_pwm_auto_point_channel,
766 store_pwm_auto_point_channel, 0, 1),
767 SENSOR_ATTR_2(temp2_auto_point1_pwm, S_IRUGO|S_IWUSR,
768 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
770 SENSOR_ATTR_2(temp2_auto_point2_pwm, S_IRUGO|S_IWUSR,
771 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
773 SENSOR_ATTR_2(temp2_auto_point3_pwm, S_IRUGO|S_IWUSR,
774 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
776 SENSOR_ATTR_2(temp2_auto_point4_pwm, S_IRUGO|S_IWUSR,
777 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
779 SENSOR_ATTR_2(temp2_auto_point5_pwm, S_IRUGO|S_IWUSR,
780 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
782 SENSOR_ATTR_2(temp2_auto_point1_temp, S_IRUGO|S_IWUSR,
783 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
785 SENSOR_ATTR_2(temp2_auto_point2_temp, S_IRUGO|S_IWUSR,
786 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
788 SENSOR_ATTR_2(temp2_auto_point3_temp, S_IRUGO|S_IWUSR,
789 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
791 SENSOR_ATTR_2(temp2_auto_point4_temp, S_IRUGO|S_IWUSR,
792 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
794 SENSOR_ATTR_2(temp2_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(temp2_auto_point2_temp_hyst, S_IRUGO,
799 show_pwm_auto_point_temp_hyst, NULL, 1, 0),
800 SENSOR_ATTR_2(temp2_auto_point3_temp_hyst, S_IRUGO,
801 show_pwm_auto_point_temp_hyst, NULL, 2, 0),
802 SENSOR_ATTR_2(temp2_auto_point4_temp_hyst, S_IRUGO,
803 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
805 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
806 show_pwm_auto_point_channel,
807 store_pwm_auto_point_channel, 0, 2),
808 SENSOR_ATTR_2(temp3_auto_point1_pwm, S_IRUGO|S_IWUSR,
809 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
811 SENSOR_ATTR_2(temp3_auto_point2_pwm, S_IRUGO|S_IWUSR,
812 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
814 SENSOR_ATTR_2(temp3_auto_point3_pwm, S_IRUGO|S_IWUSR,
815 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
817 SENSOR_ATTR_2(temp3_auto_point4_pwm, S_IRUGO|S_IWUSR,
818 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
820 SENSOR_ATTR_2(temp3_auto_point5_pwm, S_IRUGO|S_IWUSR,
821 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
823 SENSOR_ATTR_2(temp3_auto_point1_temp, S_IRUGO|S_IWUSR,
824 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
826 SENSOR_ATTR_2(temp3_auto_point2_temp, S_IRUGO|S_IWUSR,
827 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
829 SENSOR_ATTR_2(temp3_auto_point3_temp, S_IRUGO|S_IWUSR,
830 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
832 SENSOR_ATTR_2(temp3_auto_point4_temp, S_IRUGO|S_IWUSR,
833 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
835 SENSOR_ATTR_2(temp3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
836 show_pwm_auto_point_temp_hyst,
837 store_pwm_auto_point_temp_hyst,
839 SENSOR_ATTR_2(temp3_auto_point2_temp_hyst, S_IRUGO,
840 show_pwm_auto_point_temp_hyst, NULL, 1, 1),
841 SENSOR_ATTR_2(temp3_auto_point3_temp_hyst, S_IRUGO,
842 show_pwm_auto_point_temp_hyst, NULL, 2, 1),
843 SENSOR_ATTR_2(temp3_auto_point4_temp_hyst, S_IRUGO,
844 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
847 /* Super I/O functions */
848 static inline int superio_inb(int base, int reg)
851 return inb(base + 1);
854 static int superio_inw(int base, int reg)
858 val = inb(base + 1) << 8;
860 val |= inb(base + 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 outb(reg++, data->addr + ADDR_REG_OFFSET);
907 val = inb(data->addr + DATA_REG_OFFSET) << 8;
908 outb(reg, data->addr + ADDR_REG_OFFSET);
909 val |= inb(data->addr + DATA_REG_OFFSET);
914 static void f71882fg_write8(struct f71882fg_data *data, u8 reg, u8 val)
916 outb(reg, data->addr + ADDR_REG_OFFSET);
917 outb(val, data->addr + DATA_REG_OFFSET);
920 static void f71882fg_write16(struct f71882fg_data *data, u8 reg, u16 val)
922 outb(reg++, data->addr + ADDR_REG_OFFSET);
923 outb(val >> 8, data->addr + DATA_REG_OFFSET);
924 outb(reg, data->addr + ADDR_REG_OFFSET);
925 outb(val & 255, data->addr + DATA_REG_OFFSET);
928 static u16 f71882fg_read_temp(struct f71882fg_data *data, int nr)
930 if (data->type == f71858fg)
931 return f71882fg_read16(data, F71882FG_REG_TEMP(nr));
933 return f71882fg_read8(data, F71882FG_REG_TEMP(nr));
936 static struct f71882fg_data *f71882fg_update_device(struct device *dev)
938 struct f71882fg_data *data = dev_get_drvdata(dev);
939 int nr, reg = 0, reg2;
940 int nr_fans = (data->type == f71882fg) ? 4 : 3;
941 int nr_ins = (data->type == f71858fg || data->type == f8000) ? 3 : 9;
943 mutex_lock(&data->update_lock);
945 /* Update once every 60 seconds */
946 if ( time_after(jiffies, data->last_limits + 60 * HZ ) ||
948 if (data->type == f71882fg) {
950 f71882fg_read8(data, F71882FG_REG_IN1_HIGH);
952 f71882fg_read8(data, F71882FG_REG_IN_BEEP);
955 /* Get High & boundary temps*/
956 for (nr = data->temp_start; nr < 3 + data->temp_start; nr++) {
957 data->temp_ovt[nr] = f71882fg_read8(data,
958 F71882FG_REG_TEMP_OVT(nr));
959 data->temp_high[nr] = f71882fg_read8(data,
960 F71882FG_REG_TEMP_HIGH(nr));
963 if (data->type != f8000) {
964 data->temp_hyst[0] = f71882fg_read8(data,
965 F71882FG_REG_TEMP_HYST(0));
966 data->temp_hyst[1] = f71882fg_read8(data,
967 F71882FG_REG_TEMP_HYST(1));
970 if (data->type == f71862fg || data->type == f71882fg) {
971 data->fan_beep = f71882fg_read8(data,
972 F71882FG_REG_FAN_BEEP);
973 data->temp_beep = f71882fg_read8(data,
974 F71882FG_REG_TEMP_BEEP);
975 /* Have to hardcode type, because temp1 is special */
976 reg = f71882fg_read8(data, F71882FG_REG_TEMP_TYPE);
977 data->temp_type[2] = (reg & 0x04) ? 2 : 4;
978 data->temp_type[3] = (reg & 0x08) ? 2 : 4;
980 reg2 = f71882fg_read8(data, F71882FG_REG_PECI);
981 if ((reg2 & 0x03) == 0x01)
982 data->temp_type[1] = 6 /* PECI */;
983 else if ((reg2 & 0x03) == 0x02)
984 data->temp_type[1] = 5 /* AMDSI */;
985 else if (data->type == f71862fg || data->type == f71882fg)
986 data->temp_type[1] = (reg & 0x02) ? 2 : 4;
988 data->temp_type[1] = 2; /* Only supports BJT */
990 data->pwm_enable = f71882fg_read8(data,
991 F71882FG_REG_PWM_ENABLE);
992 data->pwm_auto_point_hyst[0] =
993 f71882fg_read8(data, F71882FG_REG_FAN_HYST(0));
994 data->pwm_auto_point_hyst[1] =
995 f71882fg_read8(data, F71882FG_REG_FAN_HYST(1));
997 for (nr = 0; nr < nr_fans; nr++) {
998 data->pwm_auto_point_mapping[nr] =
1000 F71882FG_REG_POINT_MAPPING(nr));
1002 if (data->type != f71862fg) {
1004 for (point = 0; point < 5; point++) {
1005 data->pwm_auto_point_pwm[nr][point] =
1006 f71882fg_read8(data,
1007 F71882FG_REG_POINT_PWM
1010 for (point = 0; point < 4; point++) {
1011 data->pwm_auto_point_temp[nr][point] =
1012 f71882fg_read8(data,
1013 F71882FG_REG_POINT_TEMP
1017 data->pwm_auto_point_pwm[nr][1] =
1018 f71882fg_read8(data,
1019 F71882FG_REG_POINT_PWM
1021 data->pwm_auto_point_pwm[nr][4] =
1022 f71882fg_read8(data,
1023 F71882FG_REG_POINT_PWM
1025 data->pwm_auto_point_temp[nr][0] =
1026 f71882fg_read8(data,
1027 F71882FG_REG_POINT_TEMP
1029 data->pwm_auto_point_temp[nr][3] =
1030 f71882fg_read8(data,
1031 F71882FG_REG_POINT_TEMP
1035 data->last_limits = jiffies;
1038 /* Update every second */
1039 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
1040 data->temp_status = f71882fg_read8(data,
1041 F71882FG_REG_TEMP_STATUS);
1042 data->temp_diode_open = f71882fg_read8(data,
1043 F71882FG_REG_TEMP_DIODE_OPEN);
1044 for (nr = data->temp_start; nr < 3 + data->temp_start; nr++)
1045 data->temp[nr] = f71882fg_read_temp(data, nr);
1047 data->fan_status = f71882fg_read8(data,
1048 F71882FG_REG_FAN_STATUS);
1049 for (nr = 0; nr < nr_fans; nr++) {
1050 data->fan[nr] = f71882fg_read16(data,
1051 F71882FG_REG_FAN(nr));
1052 data->fan_target[nr] =
1053 f71882fg_read16(data, F71882FG_REG_FAN_TARGET(nr));
1054 data->fan_full_speed[nr] =
1055 f71882fg_read16(data,
1056 F71882FG_REG_FAN_FULL_SPEED(nr));
1058 f71882fg_read8(data, F71882FG_REG_PWM(nr));
1061 /* The f8000 can monitor 1 more fan, but has no pwm for it */
1062 if (data->type == f8000)
1063 data->fan[3] = f71882fg_read16(data,
1064 F71882FG_REG_FAN(3));
1065 if (data->type == f71882fg)
1066 data->in_status = f71882fg_read8(data,
1067 F71882FG_REG_IN_STATUS);
1068 for (nr = 0; nr < nr_ins; nr++)
1069 data->in[nr] = f71882fg_read8(data,
1070 F71882FG_REG_IN(nr));
1072 data->last_updated = jiffies;
1076 mutex_unlock(&data->update_lock);
1081 /* Sysfs Interface */
1082 static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
1085 struct f71882fg_data *data = f71882fg_update_device(dev);
1086 int nr = to_sensor_dev_attr_2(devattr)->index;
1087 int speed = fan_from_reg(data->fan[nr]);
1089 if (speed == FAN_MIN_DETECT)
1092 return sprintf(buf, "%d\n", speed);
1095 static ssize_t show_fan_full_speed(struct device *dev,
1096 struct device_attribute *devattr, char *buf)
1098 struct f71882fg_data *data = f71882fg_update_device(dev);
1099 int nr = to_sensor_dev_attr_2(devattr)->index;
1100 int speed = fan_from_reg(data->fan_full_speed[nr]);
1101 return sprintf(buf, "%d\n", speed);
1104 static ssize_t store_fan_full_speed(struct device *dev,
1105 struct device_attribute *devattr,
1106 const char *buf, size_t count)
1108 struct f71882fg_data *data = dev_get_drvdata(dev);
1109 int nr = to_sensor_dev_attr_2(devattr)->index;
1110 long val = simple_strtol(buf, NULL, 10);
1112 val = SENSORS_LIMIT(val, 23, 1500000);
1113 val = fan_to_reg(val);
1115 mutex_lock(&data->update_lock);
1116 f71882fg_write16(data, F71882FG_REG_FAN_FULL_SPEED(nr), val);
1117 data->fan_full_speed[nr] = val;
1118 mutex_unlock(&data->update_lock);
1123 static ssize_t show_fan_beep(struct device *dev, struct device_attribute
1124 *devattr, char *buf)
1126 struct f71882fg_data *data = f71882fg_update_device(dev);
1127 int nr = to_sensor_dev_attr_2(devattr)->index;
1129 if (data->fan_beep & (1 << nr))
1130 return sprintf(buf, "1\n");
1132 return sprintf(buf, "0\n");
1135 static ssize_t store_fan_beep(struct device *dev, struct device_attribute
1136 *devattr, const char *buf, size_t count)
1138 struct f71882fg_data *data = dev_get_drvdata(dev);
1139 int nr = to_sensor_dev_attr_2(devattr)->index;
1140 unsigned long val = simple_strtoul(buf, NULL, 10);
1142 mutex_lock(&data->update_lock);
1143 data->fan_beep = f71882fg_read8(data, F71882FG_REG_FAN_BEEP);
1145 data->fan_beep |= 1 << nr;
1147 data->fan_beep &= ~(1 << nr);
1149 f71882fg_write8(data, F71882FG_REG_FAN_BEEP, data->fan_beep);
1150 mutex_unlock(&data->update_lock);
1155 static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
1156 *devattr, char *buf)
1158 struct f71882fg_data *data = f71882fg_update_device(dev);
1159 int nr = to_sensor_dev_attr_2(devattr)->index;
1161 if (data->fan_status & (1 << nr))
1162 return sprintf(buf, "1\n");
1164 return sprintf(buf, "0\n");
1167 static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
1170 struct f71882fg_data *data = f71882fg_update_device(dev);
1171 int nr = to_sensor_dev_attr_2(devattr)->index;
1173 return sprintf(buf, "%d\n", data->in[nr] * 8);
1176 static ssize_t show_in_max(struct device *dev, struct device_attribute
1177 *devattr, char *buf)
1179 struct f71882fg_data *data = f71882fg_update_device(dev);
1181 return sprintf(buf, "%d\n", data->in1_max * 8);
1184 static ssize_t store_in_max(struct device *dev, struct device_attribute
1185 *devattr, const char *buf, size_t count)
1187 struct f71882fg_data *data = dev_get_drvdata(dev);
1188 long val = simple_strtol(buf, NULL, 10) / 8;
1189 val = SENSORS_LIMIT(val, 0, 255);
1191 mutex_lock(&data->update_lock);
1192 f71882fg_write8(data, F71882FG_REG_IN1_HIGH, val);
1193 data->in1_max = val;
1194 mutex_unlock(&data->update_lock);
1199 static ssize_t show_in_beep(struct device *dev, struct device_attribute
1200 *devattr, char *buf)
1202 struct f71882fg_data *data = f71882fg_update_device(dev);
1203 int nr = to_sensor_dev_attr_2(devattr)->index;
1205 if (data->in_beep & (1 << nr))
1206 return sprintf(buf, "1\n");
1208 return sprintf(buf, "0\n");
1211 static ssize_t store_in_beep(struct device *dev, struct device_attribute
1212 *devattr, const char *buf, size_t count)
1214 struct f71882fg_data *data = dev_get_drvdata(dev);
1215 int nr = to_sensor_dev_attr_2(devattr)->index;
1216 unsigned long val = simple_strtoul(buf, NULL, 10);
1218 mutex_lock(&data->update_lock);
1219 data->in_beep = f71882fg_read8(data, F71882FG_REG_IN_BEEP);
1221 data->in_beep |= 1 << nr;
1223 data->in_beep &= ~(1 << nr);
1225 f71882fg_write8(data, F71882FG_REG_IN_BEEP, data->in_beep);
1226 mutex_unlock(&data->update_lock);
1231 static ssize_t show_in_alarm(struct device *dev, struct device_attribute
1232 *devattr, char *buf)
1234 struct f71882fg_data *data = f71882fg_update_device(dev);
1235 int nr = to_sensor_dev_attr_2(devattr)->index;
1237 if (data->in_status & (1 << nr))
1238 return sprintf(buf, "1\n");
1240 return sprintf(buf, "0\n");
1243 static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
1246 struct f71882fg_data *data = f71882fg_update_device(dev);
1247 int nr = to_sensor_dev_attr_2(devattr)->index;
1250 if (data->type == f71858fg) {
1251 /* TEMP_TABLE_SEL 1 or 3 ? */
1252 if (data->temp_config & 1) {
1253 sign = data->temp[nr] & 0x0001;
1254 temp = (data->temp[nr] >> 5) & 0x7ff;
1256 sign = data->temp[nr] & 0x8000;
1257 temp = (data->temp[nr] >> 5) & 0x3ff;
1263 temp = data->temp[nr] * 1000;
1265 return sprintf(buf, "%d\n", temp);
1268 static ssize_t show_temp_max(struct device *dev, struct device_attribute
1269 *devattr, char *buf)
1271 struct f71882fg_data *data = f71882fg_update_device(dev);
1272 int nr = to_sensor_dev_attr_2(devattr)->index;
1274 return sprintf(buf, "%d\n", data->temp_high[nr] * 1000);
1277 static ssize_t store_temp_max(struct device *dev, struct device_attribute
1278 *devattr, const char *buf, size_t count)
1280 struct f71882fg_data *data = dev_get_drvdata(dev);
1281 int nr = to_sensor_dev_attr_2(devattr)->index;
1282 long val = simple_strtol(buf, NULL, 10) / 1000;
1283 val = SENSORS_LIMIT(val, 0, 255);
1285 mutex_lock(&data->update_lock);
1286 f71882fg_write8(data, F71882FG_REG_TEMP_HIGH(nr), val);
1287 data->temp_high[nr] = val;
1288 mutex_unlock(&data->update_lock);
1293 static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
1294 *devattr, char *buf)
1296 struct f71882fg_data *data = f71882fg_update_device(dev);
1297 int nr = to_sensor_dev_attr_2(devattr)->index;
1300 mutex_lock(&data->update_lock);
1302 temp_max_hyst = data->temp_hyst[nr / 2] >> 4;
1304 temp_max_hyst = data->temp_hyst[nr / 2] & 0x0f;
1305 temp_max_hyst = (data->temp_high[nr] - temp_max_hyst) * 1000;
1306 mutex_unlock(&data->update_lock);
1308 return sprintf(buf, "%d\n", temp_max_hyst);
1311 static ssize_t store_temp_max_hyst(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 nr = to_sensor_dev_attr_2(devattr)->index;
1316 long val = simple_strtol(buf, NULL, 10) / 1000;
1317 ssize_t ret = count;
1320 mutex_lock(&data->update_lock);
1322 /* convert abs to relative and check */
1323 data->temp_high[nr] = f71882fg_read8(data, F71882FG_REG_TEMP_HIGH(nr));
1324 val = SENSORS_LIMIT(val, data->temp_high[nr] - 15,
1325 data->temp_high[nr]);
1326 val = data->temp_high[nr] - val;
1328 /* convert value to register contents */
1329 reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST(nr / 2));
1331 reg = (reg & 0x0f) | (val << 4);
1333 reg = (reg & 0xf0) | val;
1334 f71882fg_write8(data, F71882FG_REG_TEMP_HYST(nr / 2), reg);
1335 data->temp_hyst[nr / 2] = reg;
1337 mutex_unlock(&data->update_lock);
1341 static ssize_t show_temp_crit(struct device *dev, struct device_attribute
1342 *devattr, char *buf)
1344 struct f71882fg_data *data = f71882fg_update_device(dev);
1345 int nr = to_sensor_dev_attr_2(devattr)->index;
1347 return sprintf(buf, "%d\n", data->temp_ovt[nr] * 1000);
1350 static ssize_t store_temp_crit(struct device *dev, struct device_attribute
1351 *devattr, const char *buf, size_t count)
1353 struct f71882fg_data *data = dev_get_drvdata(dev);
1354 int nr = to_sensor_dev_attr_2(devattr)->index;
1355 long val = simple_strtol(buf, NULL, 10) / 1000;
1356 val = SENSORS_LIMIT(val, 0, 255);
1358 mutex_lock(&data->update_lock);
1359 f71882fg_write8(data, F71882FG_REG_TEMP_OVT(nr), val);
1360 data->temp_ovt[nr] = val;
1361 mutex_unlock(&data->update_lock);
1366 static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
1367 *devattr, char *buf)
1369 struct f71882fg_data *data = f71882fg_update_device(dev);
1370 int nr = to_sensor_dev_attr_2(devattr)->index;
1373 mutex_lock(&data->update_lock);
1375 temp_crit_hyst = data->temp_hyst[nr / 2] >> 4;
1377 temp_crit_hyst = data->temp_hyst[nr / 2] & 0x0f;
1378 temp_crit_hyst = (data->temp_ovt[nr] - temp_crit_hyst) * 1000;
1379 mutex_unlock(&data->update_lock);
1381 return sprintf(buf, "%d\n", temp_crit_hyst);
1384 static ssize_t show_temp_type(struct device *dev, struct device_attribute
1385 *devattr, char *buf)
1387 struct f71882fg_data *data = f71882fg_update_device(dev);
1388 int nr = to_sensor_dev_attr_2(devattr)->index;
1390 return sprintf(buf, "%d\n", data->temp_type[nr]);
1393 static ssize_t show_temp_beep(struct device *dev, struct device_attribute
1394 *devattr, char *buf)
1396 struct f71882fg_data *data = f71882fg_update_device(dev);
1397 int nr = to_sensor_dev_attr_2(devattr)->index;
1399 if (data->temp_beep & (1 << nr))
1400 return sprintf(buf, "1\n");
1402 return sprintf(buf, "0\n");
1405 static ssize_t store_temp_beep(struct device *dev, struct device_attribute
1406 *devattr, const char *buf, size_t count)
1408 struct f71882fg_data *data = dev_get_drvdata(dev);
1409 int nr = to_sensor_dev_attr_2(devattr)->index;
1410 unsigned long val = simple_strtoul(buf, NULL, 10);
1412 mutex_lock(&data->update_lock);
1413 data->temp_beep = f71882fg_read8(data, F71882FG_REG_TEMP_BEEP);
1415 data->temp_beep |= 1 << nr;
1417 data->temp_beep &= ~(1 << nr);
1419 f71882fg_write8(data, F71882FG_REG_TEMP_BEEP, data->temp_beep);
1420 mutex_unlock(&data->update_lock);
1425 static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
1426 *devattr, char *buf)
1428 struct f71882fg_data *data = f71882fg_update_device(dev);
1429 int nr = to_sensor_dev_attr_2(devattr)->index;
1431 if (data->temp_status & (1 << nr))
1432 return sprintf(buf, "1\n");
1434 return sprintf(buf, "0\n");
1437 static ssize_t show_temp_fault(struct device *dev, struct device_attribute
1438 *devattr, char *buf)
1440 struct f71882fg_data *data = f71882fg_update_device(dev);
1441 int nr = to_sensor_dev_attr_2(devattr)->index;
1443 if (data->temp_diode_open & (1 << nr))
1444 return sprintf(buf, "1\n");
1446 return sprintf(buf, "0\n");
1449 static ssize_t show_pwm(struct device *dev,
1450 struct device_attribute *devattr, char *buf)
1452 struct f71882fg_data *data = f71882fg_update_device(dev);
1453 int val, nr = to_sensor_dev_attr_2(devattr)->index;
1454 mutex_lock(&data->update_lock);
1455 if (data->pwm_enable & (1 << (2 * nr)))
1457 val = data->pwm[nr];
1460 val = 255 * fan_from_reg(data->fan_target[nr])
1461 / fan_from_reg(data->fan_full_speed[nr]);
1463 mutex_unlock(&data->update_lock);
1464 return sprintf(buf, "%d\n", val);
1467 static ssize_t store_pwm(struct device *dev,
1468 struct device_attribute *devattr, const char *buf,
1471 struct f71882fg_data *data = dev_get_drvdata(dev);
1472 int nr = to_sensor_dev_attr_2(devattr)->index;
1473 long val = simple_strtol(buf, NULL, 10);
1474 val = SENSORS_LIMIT(val, 0, 255);
1476 mutex_lock(&data->update_lock);
1477 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
1478 if ((data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 3) != 2) ||
1479 (data->type != f8000 && !((data->pwm_enable >> 2 * nr) & 2))) {
1483 if (data->pwm_enable & (1 << (2 * nr))) {
1485 f71882fg_write8(data, F71882FG_REG_PWM(nr), val);
1486 data->pwm[nr] = val;
1489 int target, full_speed;
1490 full_speed = f71882fg_read16(data,
1491 F71882FG_REG_FAN_FULL_SPEED(nr));
1492 target = fan_to_reg(val * fan_from_reg(full_speed) / 255);
1493 f71882fg_write16(data, F71882FG_REG_FAN_TARGET(nr), target);
1494 data->fan_target[nr] = target;
1495 data->fan_full_speed[nr] = full_speed;
1498 mutex_unlock(&data->update_lock);
1503 static ssize_t show_pwm_enable(struct device *dev,
1504 struct device_attribute *devattr, char *buf)
1507 struct f71882fg_data *data = f71882fg_update_device(dev);
1508 int nr = to_sensor_dev_attr_2(devattr)->index;
1510 switch ((data->pwm_enable >> 2 * nr) & 3) {
1513 result = 2; /* Normal auto mode */
1516 result = 1; /* Manual mode */
1519 if (data->type == f8000)
1520 result = 3; /* Thermostat mode */
1522 result = 1; /* Manual mode */
1526 return sprintf(buf, "%d\n", result);
1529 static ssize_t store_pwm_enable(struct device *dev, struct device_attribute
1530 *devattr, const char *buf, size_t count)
1532 struct f71882fg_data *data = dev_get_drvdata(dev);
1533 int nr = to_sensor_dev_attr_2(devattr)->index;
1534 long val = simple_strtol(buf, NULL, 10);
1536 /* Special case for F8000 pwm channel 3 which only does auto mode */
1537 if (data->type == f8000 && nr == 2 && val != 2)
1540 mutex_lock(&data->update_lock);
1541 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
1542 /* Special case for F8000 auto PWM mode / Thermostat mode */
1543 if (data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 1)) {
1546 data->pwm_enable &= ~(2 << (2 * nr));
1547 break; /* Normal auto mode */
1549 data->pwm_enable |= 2 << (2 * nr);
1550 break; /* Thermostat mode */
1558 /* The f71858fg does not support manual RPM mode */
1559 if (data->type == f71858fg &&
1560 ((data->pwm_enable >> (2 * nr)) & 1)) {
1564 data->pwm_enable |= 2 << (2 * nr);
1567 data->pwm_enable &= ~(2 << (2 * nr));
1568 break; /* Normal auto mode */
1574 f71882fg_write8(data, F71882FG_REG_PWM_ENABLE, data->pwm_enable);
1576 mutex_unlock(&data->update_lock);
1581 static ssize_t show_pwm_auto_point_pwm(struct device *dev,
1582 struct device_attribute *devattr,
1586 struct f71882fg_data *data = f71882fg_update_device(dev);
1587 int pwm = to_sensor_dev_attr_2(devattr)->index;
1588 int point = to_sensor_dev_attr_2(devattr)->nr;
1590 mutex_lock(&data->update_lock);
1591 if (data->pwm_enable & (1 << (2 * pwm))) {
1593 result = data->pwm_auto_point_pwm[pwm][point];
1596 result = 32 * 255 / (32 + data->pwm_auto_point_pwm[pwm][point]);
1598 mutex_unlock(&data->update_lock);
1600 return sprintf(buf, "%d\n", result);
1603 static ssize_t store_pwm_auto_point_pwm(struct device *dev,
1604 struct device_attribute *devattr,
1605 const char *buf, size_t count)
1607 struct f71882fg_data *data = dev_get_drvdata(dev);
1608 int pwm = to_sensor_dev_attr_2(devattr)->index;
1609 int point = to_sensor_dev_attr_2(devattr)->nr;
1610 long val = simple_strtol(buf, NULL, 10);
1611 val = SENSORS_LIMIT(val, 0, 255);
1613 mutex_lock(&data->update_lock);
1614 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
1615 if (data->pwm_enable & (1 << (2 * pwm))) {
1619 if (val < 29) /* Prevent negative numbers */
1622 val = (255 - val) * 32 / val;
1624 f71882fg_write8(data, F71882FG_REG_POINT_PWM(pwm, point), val);
1625 data->pwm_auto_point_pwm[pwm][point] = val;
1626 mutex_unlock(&data->update_lock);
1631 static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
1632 struct device_attribute *devattr,
1636 struct f71882fg_data *data = f71882fg_update_device(dev);
1637 int nr = to_sensor_dev_attr_2(devattr)->index;
1638 int point = to_sensor_dev_attr_2(devattr)->nr;
1640 mutex_lock(&data->update_lock);
1642 result = data->pwm_auto_point_hyst[nr / 2] >> 4;
1644 result = data->pwm_auto_point_hyst[nr / 2] & 0x0f;
1645 result = 1000 * (data->pwm_auto_point_temp[nr][point] - result);
1646 mutex_unlock(&data->update_lock);
1648 return sprintf(buf, "%d\n", result);
1651 static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
1652 struct device_attribute *devattr,
1653 const char *buf, size_t count)
1655 struct f71882fg_data *data = dev_get_drvdata(dev);
1656 int nr = to_sensor_dev_attr_2(devattr)->index;
1657 int point = to_sensor_dev_attr_2(devattr)->nr;
1658 long val = simple_strtol(buf, NULL, 10) / 1000;
1661 mutex_lock(&data->update_lock);
1662 data->pwm_auto_point_temp[nr][point] =
1663 f71882fg_read8(data, F71882FG_REG_POINT_TEMP(nr, point));
1664 val = SENSORS_LIMIT(val, data->pwm_auto_point_temp[nr][point] - 15,
1665 data->pwm_auto_point_temp[nr][point]);
1666 val = data->pwm_auto_point_temp[nr][point] - val;
1668 reg = f71882fg_read8(data, F71882FG_REG_FAN_HYST(nr / 2));
1670 reg = (reg & 0x0f) | (val << 4);
1672 reg = (reg & 0xf0) | val;
1674 f71882fg_write8(data, F71882FG_REG_FAN_HYST(nr / 2), reg);
1675 data->pwm_auto_point_hyst[nr / 2] = reg;
1676 mutex_unlock(&data->update_lock);
1681 static ssize_t show_pwm_interpolate(struct device *dev,
1682 struct device_attribute *devattr, char *buf)
1685 struct f71882fg_data *data = f71882fg_update_device(dev);
1686 int nr = to_sensor_dev_attr_2(devattr)->index;
1688 result = (data->pwm_auto_point_mapping[nr] >> 4) & 1;
1690 return sprintf(buf, "%d\n", result);
1693 static ssize_t store_pwm_interpolate(struct device *dev,
1694 struct device_attribute *devattr,
1695 const char *buf, size_t count)
1697 struct f71882fg_data *data = dev_get_drvdata(dev);
1698 int nr = to_sensor_dev_attr_2(devattr)->index;
1699 unsigned long val = simple_strtoul(buf, NULL, 10);
1701 mutex_lock(&data->update_lock);
1702 data->pwm_auto_point_mapping[nr] =
1703 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
1705 val = data->pwm_auto_point_mapping[nr] | (1 << 4);
1707 val = data->pwm_auto_point_mapping[nr] & (~(1 << 4));
1708 f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val);
1709 data->pwm_auto_point_mapping[nr] = val;
1710 mutex_unlock(&data->update_lock);
1715 static ssize_t show_pwm_auto_point_channel(struct device *dev,
1716 struct device_attribute *devattr,
1720 struct f71882fg_data *data = f71882fg_update_device(dev);
1721 int nr = to_sensor_dev_attr_2(devattr)->index;
1723 result = 1 << ((data->pwm_auto_point_mapping[nr] & 3) -
1726 return sprintf(buf, "%d\n", result);
1729 static ssize_t store_pwm_auto_point_channel(struct device *dev,
1730 struct device_attribute *devattr,
1731 const char *buf, size_t count)
1733 struct f71882fg_data *data = dev_get_drvdata(dev);
1734 int nr = to_sensor_dev_attr_2(devattr)->index;
1735 long val = simple_strtol(buf, NULL, 10);
1750 val += data->temp_start;
1751 mutex_lock(&data->update_lock);
1752 data->pwm_auto_point_mapping[nr] =
1753 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
1754 val = (data->pwm_auto_point_mapping[nr] & 0xfc) | val;
1755 f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val);
1756 data->pwm_auto_point_mapping[nr] = val;
1757 mutex_unlock(&data->update_lock);
1762 static ssize_t show_pwm_auto_point_temp(struct device *dev,
1763 struct device_attribute *devattr,
1767 struct f71882fg_data *data = f71882fg_update_device(dev);
1768 int pwm = to_sensor_dev_attr_2(devattr)->index;
1769 int point = to_sensor_dev_attr_2(devattr)->nr;
1771 result = data->pwm_auto_point_temp[pwm][point];
1772 return sprintf(buf, "%d\n", 1000 * result);
1775 static ssize_t store_pwm_auto_point_temp(struct device *dev,
1776 struct device_attribute *devattr,
1777 const char *buf, size_t count)
1779 struct f71882fg_data *data = dev_get_drvdata(dev);
1780 int pwm = to_sensor_dev_attr_2(devattr)->index;
1781 int point = to_sensor_dev_attr_2(devattr)->nr;
1782 long val = simple_strtol(buf, NULL, 10) / 1000;
1783 val = SENSORS_LIMIT(val, 0, 255);
1785 mutex_lock(&data->update_lock);
1786 f71882fg_write8(data, F71882FG_REG_POINT_TEMP(pwm, point), val);
1787 data->pwm_auto_point_temp[pwm][point] = val;
1788 mutex_unlock(&data->update_lock);
1793 static ssize_t show_name(struct device *dev, struct device_attribute *devattr,
1796 struct f71882fg_data *data = dev_get_drvdata(dev);
1797 return sprintf(buf, "%s\n", f71882fg_names[data->type]);
1800 static int __devinit f71882fg_create_sysfs_files(struct platform_device *pdev,
1801 struct sensor_device_attribute_2 *attr, int count)
1805 for (i = 0; i < count; i++) {
1806 err = device_create_file(&pdev->dev, &attr[i].dev_attr);
1813 static int __devinit f71882fg_probe(struct platform_device *pdev)
1815 struct f71882fg_data *data;
1816 struct f71882fg_sio_data *sio_data = pdev->dev.platform_data;
1817 int err, i, nr_fans = (sio_data->type == f71882fg) ? 4 : 3;
1820 data = kzalloc(sizeof(struct f71882fg_data), GFP_KERNEL);
1824 data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start;
1825 data->type = sio_data->type;
1827 (data->type == f71858fg || data->type == f8000) ? 0 : 1;
1828 mutex_init(&data->update_lock);
1829 platform_set_drvdata(pdev, data);
1831 start_reg = f71882fg_read8(data, F71882FG_REG_START);
1832 if (start_reg & 0x04) {
1833 dev_warn(&pdev->dev, "Hardware monitor is powered down\n");
1837 if (!(start_reg & 0x03)) {
1838 dev_warn(&pdev->dev, "Hardware monitoring not activated\n");
1843 /* Register sysfs interface files */
1844 err = device_create_file(&pdev->dev, &dev_attr_name);
1846 goto exit_unregister_sysfs;
1848 if (start_reg & 0x01) {
1849 switch (data->type) {
1852 f71882fg_read8(data, F71882FG_REG_TEMP_CONFIG);
1853 if (data->temp_config & 0x10)
1854 /* The f71858fg temperature alarms behave as
1855 the f8000 alarms in this mode */
1856 err = f71882fg_create_sysfs_files(pdev,
1858 ARRAY_SIZE(f8000_in_temp_attr));
1860 err = f71882fg_create_sysfs_files(pdev,
1861 f71858fg_in_temp_attr,
1862 ARRAY_SIZE(f71858fg_in_temp_attr));
1865 err = f71882fg_create_sysfs_files(pdev,
1866 fxxxx_in1_alarm_attr,
1867 ARRAY_SIZE(fxxxx_in1_alarm_attr));
1869 goto exit_unregister_sysfs;
1872 err = f71882fg_create_sysfs_files(pdev,
1874 ARRAY_SIZE(fxxxx_in_temp_attr));
1877 err = f71882fg_create_sysfs_files(pdev,
1879 ARRAY_SIZE(f8000_in_temp_attr));
1883 goto exit_unregister_sysfs;
1886 if (start_reg & 0x02) {
1888 f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
1890 /* Sanity check the pwm settings */
1891 switch (data->type) {
1894 for (i = 0; i < nr_fans; i++)
1895 if (((data->pwm_enable >> (i * 2)) & 3) == 3)
1899 err = (data->pwm_enable & 0x15) != 0x15;
1905 err = data->pwm_enable & 0x20;
1910 "Invalid (reserved) pwm settings: 0x%02x\n",
1911 (unsigned int)data->pwm_enable);
1913 goto exit_unregister_sysfs;
1916 err = f71882fg_create_sysfs_files(pdev, &fxxxx_fan_attr[0][0],
1917 ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans);
1919 goto exit_unregister_sysfs;
1921 if (data->type == f71862fg || data->type == f71882fg) {
1922 err = f71882fg_create_sysfs_files(pdev,
1923 fxxxx_fan_beep_attr, nr_fans);
1925 goto exit_unregister_sysfs;
1928 switch (data->type) {
1930 err = f71882fg_create_sysfs_files(pdev,
1931 f71862fg_auto_pwm_attr,
1932 ARRAY_SIZE(f71862fg_auto_pwm_attr));
1935 err = f71882fg_create_sysfs_files(pdev,
1937 ARRAY_SIZE(f8000_fan_attr));
1939 goto exit_unregister_sysfs;
1940 err = f71882fg_create_sysfs_files(pdev,
1941 f8000_auto_pwm_attr,
1942 ARRAY_SIZE(f8000_auto_pwm_attr));
1944 default: /* f71858fg / f71882fg */
1945 err = f71882fg_create_sysfs_files(pdev,
1946 &fxxxx_auto_pwm_attr[0][0],
1947 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
1950 goto exit_unregister_sysfs;
1952 for (i = 0; i < nr_fans; i++)
1953 dev_info(&pdev->dev, "Fan: %d is in %s mode\n", i + 1,
1954 (data->pwm_enable & (1 << 2 * i)) ?
1955 "duty-cycle" : "RPM");
1958 data->hwmon_dev = hwmon_device_register(&pdev->dev);
1959 if (IS_ERR(data->hwmon_dev)) {
1960 err = PTR_ERR(data->hwmon_dev);
1961 data->hwmon_dev = NULL;
1962 goto exit_unregister_sysfs;
1967 exit_unregister_sysfs:
1968 f71882fg_remove(pdev); /* Will unregister the sysfs files for us */
1969 return err; /* f71882fg_remove() also frees our data */
1975 static int f71882fg_remove(struct platform_device *pdev)
1978 struct f71882fg_data *data = platform_get_drvdata(pdev);
1980 platform_set_drvdata(pdev, NULL);
1981 if (data->hwmon_dev)
1982 hwmon_device_unregister(data->hwmon_dev);
1984 /* Note we are not looping over all attr arrays we have as the ones
1985 below are supersets of the ones skipped. */
1986 device_remove_file(&pdev->dev, &dev_attr_name);
1988 for (i = 0; i < ARRAY_SIZE(fxxxx_in_temp_attr); i++)
1989 device_remove_file(&pdev->dev,
1990 &fxxxx_in_temp_attr[i].dev_attr);
1992 for (i = 0; i < ARRAY_SIZE(fxxxx_in1_alarm_attr); i++)
1993 device_remove_file(&pdev->dev,
1994 &fxxxx_in1_alarm_attr[i].dev_attr);
1996 for (i = 0; i < ARRAY_SIZE(fxxxx_fan_attr); i++)
1997 for (j = 0; j < ARRAY_SIZE(fxxxx_fan_attr[0]); j++)
1998 device_remove_file(&pdev->dev,
1999 &fxxxx_fan_attr[i][j].dev_attr);
2001 for (i = 0; i < ARRAY_SIZE(fxxxx_fan_beep_attr); i++)
2002 device_remove_file(&pdev->dev,
2003 &fxxxx_fan_beep_attr[i].dev_attr);
2005 for (i = 0; i < ARRAY_SIZE(fxxxx_auto_pwm_attr); i++)
2006 for (j = 0; j < ARRAY_SIZE(fxxxx_auto_pwm_attr[0]); j++)
2007 device_remove_file(&pdev->dev,
2008 &fxxxx_auto_pwm_attr[i][j].dev_attr);
2010 for (i = 0; i < ARRAY_SIZE(f8000_auto_pwm_attr); i++)
2011 device_remove_file(&pdev->dev,
2012 &f8000_auto_pwm_attr[i].dev_attr);
2019 static int __init f71882fg_find(int sioaddr, unsigned short *address,
2020 struct f71882fg_sio_data *sio_data)
2025 superio_enter(sioaddr);
2027 devid = superio_inw(sioaddr, SIO_REG_MANID);
2028 if (devid != SIO_FINTEK_ID) {
2029 pr_debug(DRVNAME ": Not a Fintek device\n");
2033 devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID);
2036 sio_data->type = f71858fg;
2039 sio_data->type = f71862fg;
2042 sio_data->type = f71882fg;
2045 sio_data->type = f8000;
2048 printk(KERN_INFO DRVNAME ": Unsupported Fintek device\n");
2052 if (sio_data->type == f71858fg)
2053 superio_select(sioaddr, SIO_F71858FG_LD_HWM);
2055 superio_select(sioaddr, SIO_F71882FG_LD_HWM);
2057 if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) {
2058 printk(KERN_WARNING DRVNAME ": Device not activated\n");
2062 *address = superio_inw(sioaddr, SIO_REG_ADDR);
2065 printk(KERN_WARNING DRVNAME ": Base address not set\n");
2068 *address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */
2071 printk(KERN_INFO DRVNAME ": Found %s chip at %#x, revision %d\n",
2072 f71882fg_names[sio_data->type], (unsigned int)*address,
2073 (int)superio_inb(sioaddr, SIO_REG_DEVREV));
2075 superio_exit(sioaddr);
2079 static int __init f71882fg_device_add(unsigned short address,
2080 const struct f71882fg_sio_data *sio_data)
2082 struct resource res = {
2084 .end = address + REGION_LENGTH - 1,
2085 .flags = IORESOURCE_IO,
2089 f71882fg_pdev = platform_device_alloc(DRVNAME, address);
2093 res.name = f71882fg_pdev->name;
2094 err = acpi_check_resource_conflict(&res);
2096 goto exit_device_put;
2098 err = platform_device_add_resources(f71882fg_pdev, &res, 1);
2100 printk(KERN_ERR DRVNAME ": Device resource addition failed\n");
2101 goto exit_device_put;
2104 err = platform_device_add_data(f71882fg_pdev, sio_data,
2105 sizeof(struct f71882fg_sio_data));
2107 printk(KERN_ERR DRVNAME ": Platform data allocation failed\n");
2108 goto exit_device_put;
2111 err = platform_device_add(f71882fg_pdev);
2113 printk(KERN_ERR DRVNAME ": Device addition failed\n");
2114 goto exit_device_put;
2120 platform_device_put(f71882fg_pdev);
2125 static int __init f71882fg_init(void)
2128 unsigned short address;
2129 struct f71882fg_sio_data sio_data;
2131 memset(&sio_data, 0, sizeof(sio_data));
2133 if (f71882fg_find(0x2e, &address, &sio_data) &&
2134 f71882fg_find(0x4e, &address, &sio_data))
2137 err = platform_driver_register(&f71882fg_driver);
2141 err = f71882fg_device_add(address, &sio_data);
2148 platform_driver_unregister(&f71882fg_driver);
2153 static void __exit f71882fg_exit(void)
2155 platform_device_unregister(f71882fg_pdev);
2156 platform_driver_unregister(&f71882fg_driver);
2159 MODULE_DESCRIPTION("F71882FG Hardware Monitoring Driver");
2160 MODULE_AUTHOR("Hans Edgington, Hans de Goede (hdegoede@redhat.com)");
2161 MODULE_LICENSE("GPL");
2163 module_init(f71882fg_init);
2164 module_exit(f71882fg_exit);