hwmon/f71882fg: Remove bogus temp2_type for certain models
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / hwmon / f71882fg.c
blobb8b4bc9db03dcb1f03ade13effd1ce34c02d4cac
1 /***************************************************************************
2 * Copyright (C) 2006 by Hans Edgington <hans@edgington.nl> *
3 * Copyright (C) 2007-2011 Hans de Goede <hdegoede@redhat.com> *
4 * *
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. *
9 * *
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. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
21 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
23 #include <linux/module.h>
24 #include <linux/init.h>
25 #include <linux/slab.h>
26 #include <linux/jiffies.h>
27 #include <linux/platform_device.h>
28 #include <linux/hwmon.h>
29 #include <linux/hwmon-sysfs.h>
30 #include <linux/err.h>
31 #include <linux/mutex.h>
32 #include <linux/io.h>
33 #include <linux/acpi.h>
35 #define DRVNAME "f71882fg"
37 #define SIO_F71858FG_LD_HWM 0x02 /* Hardware monitor logical device */
38 #define SIO_F71882FG_LD_HWM 0x04 /* Hardware monitor logical device */
39 #define SIO_UNLOCK_KEY 0x87 /* Key to enable Super-I/O */
40 #define SIO_LOCK_KEY 0xAA /* Key to disable Super-I/O */
42 #define SIO_REG_LDSEL 0x07 /* Logical device select */
43 #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */
44 #define SIO_REG_DEVREV 0x22 /* Device revision */
45 #define SIO_REG_MANID 0x23 /* Fintek ID (2 bytes) */
46 #define SIO_REG_ENABLE 0x30 /* Logical device enable */
47 #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
49 #define SIO_FINTEK_ID 0x1934 /* Manufacturers ID */
50 #define SIO_F71858_ID 0x0507 /* Chipset ID */
51 #define SIO_F71862_ID 0x0601 /* Chipset ID */
52 #define SIO_F71882_ID 0x0541 /* Chipset ID */
53 #define SIO_F71889_ID 0x0723 /* Chipset ID */
54 #define SIO_F8000_ID 0x0581 /* Chipset ID */
56 #define REGION_LENGTH 8
57 #define ADDR_REG_OFFSET 5
58 #define DATA_REG_OFFSET 6
60 #define F71882FG_REG_IN_STATUS 0x12 /* f71882fg only */
61 #define F71882FG_REG_IN_BEEP 0x13 /* f71882fg only */
62 #define F71882FG_REG_IN(nr) (0x20 + (nr))
63 #define F71882FG_REG_IN1_HIGH 0x32 /* f71882fg only */
65 #define F71882FG_REG_FAN(nr) (0xA0 + (16 * (nr)))
66 #define F71882FG_REG_FAN_TARGET(nr) (0xA2 + (16 * (nr)))
67 #define F71882FG_REG_FAN_FULL_SPEED(nr) (0xA4 + (16 * (nr)))
68 #define F71882FG_REG_FAN_STATUS 0x92
69 #define F71882FG_REG_FAN_BEEP 0x93
71 #define F71882FG_REG_TEMP(nr) (0x70 + 2 * (nr))
72 #define F71882FG_REG_TEMP_OVT(nr) (0x80 + 2 * (nr))
73 #define F71882FG_REG_TEMP_HIGH(nr) (0x81 + 2 * (nr))
74 #define F71882FG_REG_TEMP_STATUS 0x62
75 #define F71882FG_REG_TEMP_BEEP 0x63
76 #define F71882FG_REG_TEMP_CONFIG 0x69
77 #define F71882FG_REG_TEMP_HYST(nr) (0x6C + (nr))
78 #define F71882FG_REG_TEMP_TYPE 0x6B
79 #define F71882FG_REG_TEMP_DIODE_OPEN 0x6F
81 #define F71882FG_REG_PWM(nr) (0xA3 + (16 * (nr)))
82 #define F71882FG_REG_PWM_TYPE 0x94
83 #define F71882FG_REG_PWM_ENABLE 0x96
85 #define F71882FG_REG_FAN_HYST(nr) (0x98 + (nr))
87 #define F71882FG_REG_FAN_FAULT_T 0x9F
88 #define F71882FG_FAN_NEG_TEMP_EN 0x20
90 #define F71882FG_REG_POINT_PWM(pwm, point) (0xAA + (point) + (16 * (pwm)))
91 #define F71882FG_REG_POINT_TEMP(pwm, point) (0xA6 + (point) + (16 * (pwm)))
92 #define F71882FG_REG_POINT_MAPPING(nr) (0xAF + 16 * (nr))
94 #define F71882FG_REG_START 0x01
96 #define F71882FG_MAX_INS 9
98 #define FAN_MIN_DETECT 366 /* Lowest detectable fanspeed */
100 static unsigned short force_id;
101 module_param(force_id, ushort, 0);
102 MODULE_PARM_DESC(force_id, "Override the detected device ID");
104 enum chips { f71858fg, f71862fg, f71882fg, f71889fg, f8000 };
106 static const char *f71882fg_names[] = {
107 "f71858fg",
108 "f71862fg",
109 "f71882fg",
110 "f71889fg",
111 "f8000",
114 static const char f71882fg_has_in[5][F71882FG_MAX_INS] = {
115 { 1, 1, 1, 0, 0, 0, 0, 0, 0 }, /* f71858fg */
116 { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* f71862fg */
117 { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* f71882fg */
118 { 1, 1, 1, 1, 1, 1, 1, 1, 1 }, /* f71889fg */
119 { 1, 1, 1, 0, 0, 0, 0, 0, 0 }, /* f8000 */
122 static const char f71882fg_has_in1_alarm[5] = {
123 0, /* f71858fg */
124 0, /* f71862fg */
125 1, /* f71882fg */
126 1, /* f71889fg */
127 0, /* f8000 */
130 static struct platform_device *f71882fg_pdev;
132 /* Super-I/O Function prototypes */
133 static inline int superio_inb(int base, int reg);
134 static inline int superio_inw(int base, int reg);
135 static inline int superio_enter(int base);
136 static inline void superio_select(int base, int ld);
137 static inline void superio_exit(int base);
139 struct f71882fg_sio_data {
140 enum chips type;
143 struct f71882fg_data {
144 unsigned short addr;
145 enum chips type;
146 struct device *hwmon_dev;
148 struct mutex update_lock;
149 int temp_start; /* temp numbering start (0 or 1) */
150 char valid; /* !=0 if following fields are valid */
151 char auto_point_temp_signed;
152 unsigned long last_updated; /* In jiffies */
153 unsigned long last_limits; /* In jiffies */
155 /* Register Values */
156 u8 in[F71882FG_MAX_INS];
157 u8 in1_max;
158 u8 in_status;
159 u8 in_beep;
160 u16 fan[4];
161 u16 fan_target[4];
162 u16 fan_full_speed[4];
163 u8 fan_status;
164 u8 fan_beep;
165 /* Note: all models have only 3 temperature channels, but on some
166 they are addressed as 0-2 and on others as 1-3, so for coding
167 convenience we reserve space for 4 channels */
168 u16 temp[4];
169 u8 temp_ovt[4];
170 u8 temp_high[4];
171 u8 temp_hyst[2]; /* 2 hysts stored per reg */
172 u8 temp_type[4];
173 u8 temp_status;
174 u8 temp_beep;
175 u8 temp_diode_open;
176 u8 temp_config;
177 u8 pwm[4];
178 u8 pwm_enable;
179 u8 pwm_auto_point_hyst[2];
180 u8 pwm_auto_point_mapping[4];
181 u8 pwm_auto_point_pwm[4][5];
182 s8 pwm_auto_point_temp[4][4];
185 /* Sysfs in */
186 static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
187 char *buf);
188 static ssize_t show_in_max(struct device *dev, struct device_attribute
189 *devattr, char *buf);
190 static ssize_t store_in_max(struct device *dev, struct device_attribute
191 *devattr, const char *buf, size_t count);
192 static ssize_t show_in_beep(struct device *dev, struct device_attribute
193 *devattr, char *buf);
194 static ssize_t store_in_beep(struct device *dev, struct device_attribute
195 *devattr, const char *buf, size_t count);
196 static ssize_t show_in_alarm(struct device *dev, struct device_attribute
197 *devattr, char *buf);
198 /* Sysfs Fan */
199 static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
200 char *buf);
201 static ssize_t show_fan_full_speed(struct device *dev,
202 struct device_attribute *devattr, char *buf);
203 static ssize_t store_fan_full_speed(struct device *dev,
204 struct device_attribute *devattr, const char *buf, size_t count);
205 static ssize_t show_fan_beep(struct device *dev, struct device_attribute
206 *devattr, char *buf);
207 static ssize_t store_fan_beep(struct device *dev, struct device_attribute
208 *devattr, const char *buf, size_t count);
209 static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
210 *devattr, char *buf);
211 /* Sysfs Temp */
212 static ssize_t show_temp(struct device *dev, struct device_attribute
213 *devattr, char *buf);
214 static ssize_t show_temp_max(struct device *dev, struct device_attribute
215 *devattr, char *buf);
216 static ssize_t store_temp_max(struct device *dev, struct device_attribute
217 *devattr, const char *buf, size_t count);
218 static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
219 *devattr, char *buf);
220 static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
221 *devattr, const char *buf, size_t count);
222 static ssize_t show_temp_crit(struct device *dev, struct device_attribute
223 *devattr, char *buf);
224 static ssize_t store_temp_crit(struct device *dev, struct device_attribute
225 *devattr, const char *buf, size_t count);
226 static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
227 *devattr, char *buf);
228 static ssize_t show_temp_type(struct device *dev, struct device_attribute
229 *devattr, char *buf);
230 static ssize_t show_temp_beep(struct device *dev, struct device_attribute
231 *devattr, char *buf);
232 static ssize_t store_temp_beep(struct device *dev, struct device_attribute
233 *devattr, const char *buf, size_t count);
234 static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
235 *devattr, char *buf);
236 static ssize_t show_temp_fault(struct device *dev, struct device_attribute
237 *devattr, char *buf);
238 /* PWM and Auto point control */
239 static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr,
240 char *buf);
241 static ssize_t store_pwm(struct device *dev, struct device_attribute *devattr,
242 const char *buf, size_t count);
243 static ssize_t show_pwm_enable(struct device *dev,
244 struct device_attribute *devattr, char *buf);
245 static ssize_t store_pwm_enable(struct device *dev,
246 struct device_attribute *devattr, const char *buf, size_t count);
247 static ssize_t show_pwm_interpolate(struct device *dev,
248 struct device_attribute *devattr, char *buf);
249 static ssize_t store_pwm_interpolate(struct device *dev,
250 struct device_attribute *devattr, const char *buf, size_t count);
251 static ssize_t show_pwm_auto_point_channel(struct device *dev,
252 struct device_attribute *devattr, char *buf);
253 static ssize_t store_pwm_auto_point_channel(struct device *dev,
254 struct device_attribute *devattr, const char *buf, size_t count);
255 static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
256 struct device_attribute *devattr, char *buf);
257 static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
258 struct device_attribute *devattr, const char *buf, size_t count);
259 static ssize_t show_pwm_auto_point_pwm(struct device *dev,
260 struct device_attribute *devattr, char *buf);
261 static ssize_t store_pwm_auto_point_pwm(struct device *dev,
262 struct device_attribute *devattr, const char *buf, size_t count);
263 static ssize_t show_pwm_auto_point_temp(struct device *dev,
264 struct device_attribute *devattr, char *buf);
265 static ssize_t store_pwm_auto_point_temp(struct device *dev,
266 struct device_attribute *devattr, const char *buf, size_t count);
267 /* Sysfs misc */
268 static ssize_t show_name(struct device *dev, struct device_attribute *devattr,
269 char *buf);
271 static int __devinit f71882fg_probe(struct platform_device * pdev);
272 static int f71882fg_remove(struct platform_device *pdev);
274 static struct platform_driver f71882fg_driver = {
275 .driver = {
276 .owner = THIS_MODULE,
277 .name = DRVNAME,
279 .probe = f71882fg_probe,
280 .remove = f71882fg_remove,
283 static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
285 /* Temp attr for the f71858fg, the f71858fg is special as it has its
286 temperature indexes start at 0 (the others start at 1) */
287 static struct sensor_device_attribute_2 f71858fg_temp_attr[] = {
288 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0),
289 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
290 store_temp_max, 0, 0),
291 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
292 store_temp_max_hyst, 0, 0),
293 SENSOR_ATTR_2(temp1_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 0),
294 SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
295 store_temp_crit, 0, 0),
296 SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
297 0, 0),
298 SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 4),
299 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 0),
300 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 1),
301 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max,
302 store_temp_max, 0, 1),
303 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
304 store_temp_max_hyst, 0, 1),
305 SENSOR_ATTR_2(temp2_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
306 SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
307 store_temp_crit, 0, 1),
308 SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
309 0, 1),
310 SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
311 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
312 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2),
313 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
314 store_temp_max, 0, 2),
315 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
316 store_temp_max_hyst, 0, 2),
317 SENSOR_ATTR_2(temp3_max_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
318 SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit,
319 store_temp_crit, 0, 2),
320 SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
321 0, 2),
322 SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
323 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
326 /* Temp attr for the standard models */
327 static struct sensor_device_attribute_2 fxxxx_temp_attr[3][11] = { {
328 SENSOR_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 1),
329 SENSOR_ATTR_2(temp1_max, S_IRUGO|S_IWUSR, show_temp_max,
330 store_temp_max, 0, 1),
331 SENSOR_ATTR_2(temp1_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
332 store_temp_max_hyst, 0, 1),
333 /* Should really be temp1_max_alarm, but older versions did not handle
334 the max and crit alarms separately and lm_sensors v2 depends on the
335 presence of temp#_alarm files. The same goes for temp2/3 _alarm. */
336 SENSOR_ATTR_2(temp1_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 1),
337 SENSOR_ATTR_2(temp1_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
338 store_temp_beep, 0, 1),
339 SENSOR_ATTR_2(temp1_crit, S_IRUGO|S_IWUSR, show_temp_crit,
340 store_temp_crit, 0, 1),
341 SENSOR_ATTR_2(temp1_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
342 0, 1),
343 SENSOR_ATTR_2(temp1_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 5),
344 SENSOR_ATTR_2(temp1_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
345 store_temp_beep, 0, 5),
346 SENSOR_ATTR_2(temp1_type, S_IRUGO, show_temp_type, NULL, 0, 1),
347 SENSOR_ATTR_2(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
348 }, {
349 SENSOR_ATTR_2(temp2_input, S_IRUGO, show_temp, NULL, 0, 2),
350 SENSOR_ATTR_2(temp2_max, S_IRUGO|S_IWUSR, show_temp_max,
351 store_temp_max, 0, 2),
352 SENSOR_ATTR_2(temp2_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
353 store_temp_max_hyst, 0, 2),
354 /* Should be temp2_max_alarm, see temp1_alarm note */
355 SENSOR_ATTR_2(temp2_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 2),
356 SENSOR_ATTR_2(temp2_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
357 store_temp_beep, 0, 2),
358 SENSOR_ATTR_2(temp2_crit, S_IRUGO|S_IWUSR, show_temp_crit,
359 store_temp_crit, 0, 2),
360 SENSOR_ATTR_2(temp2_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
361 0, 2),
362 SENSOR_ATTR_2(temp2_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
363 SENSOR_ATTR_2(temp2_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
364 store_temp_beep, 0, 6),
365 SENSOR_ATTR_2(temp2_type, S_IRUGO, show_temp_type, NULL, 0, 2),
366 SENSOR_ATTR_2(temp2_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
367 }, {
368 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 3),
369 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_max,
370 store_temp_max, 0, 3),
371 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max_hyst,
372 store_temp_max_hyst, 0, 3),
373 /* Should be temp3_max_alarm, see temp1_alarm note */
374 SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 3),
375 SENSOR_ATTR_2(temp3_max_beep, S_IRUGO|S_IWUSR, show_temp_beep,
376 store_temp_beep, 0, 3),
377 SENSOR_ATTR_2(temp3_crit, S_IRUGO|S_IWUSR, show_temp_crit,
378 store_temp_crit, 0, 3),
379 SENSOR_ATTR_2(temp3_crit_hyst, S_IRUGO, show_temp_crit_hyst, NULL,
380 0, 3),
381 SENSOR_ATTR_2(temp3_crit_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 7),
382 SENSOR_ATTR_2(temp3_crit_beep, S_IRUGO|S_IWUSR, show_temp_beep,
383 store_temp_beep, 0, 7),
384 SENSOR_ATTR_2(temp3_type, S_IRUGO, show_temp_type, NULL, 0, 3),
385 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 3),
386 } };
388 /* Temp attr for the f8000
389 Note on the f8000 temp_ovt (crit) is used as max, and temp_high (max)
390 is used as hysteresis value to clear alarms
391 Also like the f71858fg its temperature indexes start at 0
393 static struct sensor_device_attribute_2 f8000_temp_attr[] = {
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_fault, S_IRUGO, show_temp_fault, NULL, 0, 1),
408 SENSOR_ATTR_2(temp3_input, S_IRUGO, show_temp, NULL, 0, 2),
409 SENSOR_ATTR_2(temp3_max, S_IRUGO|S_IWUSR, show_temp_crit,
410 store_temp_crit, 0, 2),
411 SENSOR_ATTR_2(temp3_max_hyst, S_IRUGO|S_IWUSR, show_temp_max,
412 store_temp_max, 0, 2),
413 SENSOR_ATTR_2(temp3_alarm, S_IRUGO, show_temp_alarm, NULL, 0, 6),
414 SENSOR_ATTR_2(temp3_fault, S_IRUGO, show_temp_fault, NULL, 0, 2),
417 /* in attr for all models */
418 static struct sensor_device_attribute_2 fxxxx_in_attr[] = {
419 SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0),
420 SENSOR_ATTR_2(in1_input, S_IRUGO, show_in, NULL, 0, 1),
421 SENSOR_ATTR_2(in2_input, S_IRUGO, show_in, NULL, 0, 2),
422 SENSOR_ATTR_2(in3_input, S_IRUGO, show_in, NULL, 0, 3),
423 SENSOR_ATTR_2(in4_input, S_IRUGO, show_in, NULL, 0, 4),
424 SENSOR_ATTR_2(in5_input, S_IRUGO, show_in, NULL, 0, 5),
425 SENSOR_ATTR_2(in6_input, S_IRUGO, show_in, NULL, 0, 6),
426 SENSOR_ATTR_2(in7_input, S_IRUGO, show_in, NULL, 0, 7),
427 SENSOR_ATTR_2(in8_input, S_IRUGO, show_in, NULL, 0, 8),
430 /* For models with in1 alarm capability */
431 static struct sensor_device_attribute_2 fxxxx_in1_alarm_attr[] = {
432 SENSOR_ATTR_2(in1_max, S_IRUGO|S_IWUSR, show_in_max, store_in_max,
433 0, 1),
434 SENSOR_ATTR_2(in1_beep, S_IRUGO|S_IWUSR, show_in_beep, store_in_beep,
435 0, 1),
436 SENSOR_ATTR_2(in1_alarm, S_IRUGO, show_in_alarm, NULL, 0, 1),
439 /* Fan / PWM attr common to all models */
440 static struct sensor_device_attribute_2 fxxxx_fan_attr[4][6] = { {
441 SENSOR_ATTR_2(fan1_input, S_IRUGO, show_fan, NULL, 0, 0),
442 SENSOR_ATTR_2(fan1_full_speed, S_IRUGO|S_IWUSR,
443 show_fan_full_speed,
444 store_fan_full_speed, 0, 0),
445 SENSOR_ATTR_2(fan1_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 0),
446 SENSOR_ATTR_2(pwm1, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 0),
447 SENSOR_ATTR_2(pwm1_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
448 store_pwm_enable, 0, 0),
449 SENSOR_ATTR_2(pwm1_interpolate, S_IRUGO|S_IWUSR,
450 show_pwm_interpolate, store_pwm_interpolate, 0, 0),
451 }, {
452 SENSOR_ATTR_2(fan2_input, S_IRUGO, show_fan, NULL, 0, 1),
453 SENSOR_ATTR_2(fan2_full_speed, S_IRUGO|S_IWUSR,
454 show_fan_full_speed,
455 store_fan_full_speed, 0, 1),
456 SENSOR_ATTR_2(fan2_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 1),
457 SENSOR_ATTR_2(pwm2, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 1),
458 SENSOR_ATTR_2(pwm2_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
459 store_pwm_enable, 0, 1),
460 SENSOR_ATTR_2(pwm2_interpolate, S_IRUGO|S_IWUSR,
461 show_pwm_interpolate, store_pwm_interpolate, 0, 1),
462 }, {
463 SENSOR_ATTR_2(fan3_input, S_IRUGO, show_fan, NULL, 0, 2),
464 SENSOR_ATTR_2(fan3_full_speed, S_IRUGO|S_IWUSR,
465 show_fan_full_speed,
466 store_fan_full_speed, 0, 2),
467 SENSOR_ATTR_2(fan3_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 2),
468 SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 2),
469 SENSOR_ATTR_2(pwm3_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
470 store_pwm_enable, 0, 2),
471 SENSOR_ATTR_2(pwm3_interpolate, S_IRUGO|S_IWUSR,
472 show_pwm_interpolate, store_pwm_interpolate, 0, 2),
473 }, {
474 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
475 SENSOR_ATTR_2(fan4_full_speed, S_IRUGO|S_IWUSR,
476 show_fan_full_speed,
477 store_fan_full_speed, 0, 3),
478 SENSOR_ATTR_2(fan4_alarm, S_IRUGO, show_fan_alarm, NULL, 0, 3),
479 SENSOR_ATTR_2(pwm4, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 3),
480 SENSOR_ATTR_2(pwm4_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
481 store_pwm_enable, 0, 3),
482 SENSOR_ATTR_2(pwm4_interpolate, S_IRUGO|S_IWUSR,
483 show_pwm_interpolate, store_pwm_interpolate, 0, 3),
484 } };
486 /* Attr for models which can beep on Fan alarm */
487 static struct sensor_device_attribute_2 fxxxx_fan_beep_attr[] = {
488 SENSOR_ATTR_2(fan1_beep, S_IRUGO|S_IWUSR, show_fan_beep,
489 store_fan_beep, 0, 0),
490 SENSOR_ATTR_2(fan2_beep, S_IRUGO|S_IWUSR, show_fan_beep,
491 store_fan_beep, 0, 1),
492 SENSOR_ATTR_2(fan3_beep, S_IRUGO|S_IWUSR, show_fan_beep,
493 store_fan_beep, 0, 2),
494 SENSOR_ATTR_2(fan4_beep, S_IRUGO|S_IWUSR, show_fan_beep,
495 store_fan_beep, 0, 3),
498 /* PWM attr for the f71862fg, fewer pwms and fewer zones per pwm than the
499 f71858fg / f71882fg / f71889fg */
500 static struct sensor_device_attribute_2 f71862fg_auto_pwm_attr[] = {
501 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
502 show_pwm_auto_point_channel,
503 store_pwm_auto_point_channel, 0, 0),
504 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
505 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
506 1, 0),
507 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
508 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
509 4, 0),
510 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
511 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
512 0, 0),
513 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
514 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
515 3, 0),
516 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
517 show_pwm_auto_point_temp_hyst,
518 store_pwm_auto_point_temp_hyst,
519 0, 0),
520 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
521 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
523 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
524 show_pwm_auto_point_channel,
525 store_pwm_auto_point_channel, 0, 1),
526 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
527 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
528 1, 1),
529 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
530 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
531 4, 1),
532 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
533 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
534 0, 1),
535 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
536 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
537 3, 1),
538 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
539 show_pwm_auto_point_temp_hyst,
540 store_pwm_auto_point_temp_hyst,
541 0, 1),
542 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
543 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
545 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
546 show_pwm_auto_point_channel,
547 store_pwm_auto_point_channel, 0, 2),
548 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
549 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
550 1, 2),
551 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
552 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
553 4, 2),
554 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
555 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
556 0, 2),
557 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
558 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
559 3, 2),
560 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
561 show_pwm_auto_point_temp_hyst,
562 store_pwm_auto_point_temp_hyst,
563 0, 2),
564 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
565 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
568 /* PWM attr common to the f71858fg, f71882fg and f71889fg */
569 static struct sensor_device_attribute_2 fxxxx_auto_pwm_attr[4][14] = { {
570 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
571 show_pwm_auto_point_channel,
572 store_pwm_auto_point_channel, 0, 0),
573 SENSOR_ATTR_2(pwm1_auto_point1_pwm, S_IRUGO|S_IWUSR,
574 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
575 0, 0),
576 SENSOR_ATTR_2(pwm1_auto_point2_pwm, S_IRUGO|S_IWUSR,
577 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
578 1, 0),
579 SENSOR_ATTR_2(pwm1_auto_point3_pwm, S_IRUGO|S_IWUSR,
580 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
581 2, 0),
582 SENSOR_ATTR_2(pwm1_auto_point4_pwm, S_IRUGO|S_IWUSR,
583 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
584 3, 0),
585 SENSOR_ATTR_2(pwm1_auto_point5_pwm, S_IRUGO|S_IWUSR,
586 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
587 4, 0),
588 SENSOR_ATTR_2(pwm1_auto_point1_temp, S_IRUGO|S_IWUSR,
589 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
590 0, 0),
591 SENSOR_ATTR_2(pwm1_auto_point2_temp, S_IRUGO|S_IWUSR,
592 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
593 1, 0),
594 SENSOR_ATTR_2(pwm1_auto_point3_temp, S_IRUGO|S_IWUSR,
595 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
596 2, 0),
597 SENSOR_ATTR_2(pwm1_auto_point4_temp, S_IRUGO|S_IWUSR,
598 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
599 3, 0),
600 SENSOR_ATTR_2(pwm1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
601 show_pwm_auto_point_temp_hyst,
602 store_pwm_auto_point_temp_hyst,
603 0, 0),
604 SENSOR_ATTR_2(pwm1_auto_point2_temp_hyst, S_IRUGO,
605 show_pwm_auto_point_temp_hyst, NULL, 1, 0),
606 SENSOR_ATTR_2(pwm1_auto_point3_temp_hyst, S_IRUGO,
607 show_pwm_auto_point_temp_hyst, NULL, 2, 0),
608 SENSOR_ATTR_2(pwm1_auto_point4_temp_hyst, S_IRUGO,
609 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
610 }, {
611 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
612 show_pwm_auto_point_channel,
613 store_pwm_auto_point_channel, 0, 1),
614 SENSOR_ATTR_2(pwm2_auto_point1_pwm, S_IRUGO|S_IWUSR,
615 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
616 0, 1),
617 SENSOR_ATTR_2(pwm2_auto_point2_pwm, S_IRUGO|S_IWUSR,
618 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
619 1, 1),
620 SENSOR_ATTR_2(pwm2_auto_point3_pwm, S_IRUGO|S_IWUSR,
621 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
622 2, 1),
623 SENSOR_ATTR_2(pwm2_auto_point4_pwm, S_IRUGO|S_IWUSR,
624 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
625 3, 1),
626 SENSOR_ATTR_2(pwm2_auto_point5_pwm, S_IRUGO|S_IWUSR,
627 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
628 4, 1),
629 SENSOR_ATTR_2(pwm2_auto_point1_temp, S_IRUGO|S_IWUSR,
630 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
631 0, 1),
632 SENSOR_ATTR_2(pwm2_auto_point2_temp, S_IRUGO|S_IWUSR,
633 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
634 1, 1),
635 SENSOR_ATTR_2(pwm2_auto_point3_temp, S_IRUGO|S_IWUSR,
636 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
637 2, 1),
638 SENSOR_ATTR_2(pwm2_auto_point4_temp, S_IRUGO|S_IWUSR,
639 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
640 3, 1),
641 SENSOR_ATTR_2(pwm2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
642 show_pwm_auto_point_temp_hyst,
643 store_pwm_auto_point_temp_hyst,
644 0, 1),
645 SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
646 show_pwm_auto_point_temp_hyst, NULL, 1, 1),
647 SENSOR_ATTR_2(pwm2_auto_point3_temp_hyst, S_IRUGO,
648 show_pwm_auto_point_temp_hyst, NULL, 2, 1),
649 SENSOR_ATTR_2(pwm2_auto_point4_temp_hyst, S_IRUGO,
650 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
651 }, {
652 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
653 show_pwm_auto_point_channel,
654 store_pwm_auto_point_channel, 0, 2),
655 SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
656 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
657 0, 2),
658 SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
659 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
660 1, 2),
661 SENSOR_ATTR_2(pwm3_auto_point3_pwm, S_IRUGO|S_IWUSR,
662 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
663 2, 2),
664 SENSOR_ATTR_2(pwm3_auto_point4_pwm, S_IRUGO|S_IWUSR,
665 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
666 3, 2),
667 SENSOR_ATTR_2(pwm3_auto_point5_pwm, S_IRUGO|S_IWUSR,
668 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
669 4, 2),
670 SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
671 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
672 0, 2),
673 SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
674 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
675 1, 2),
676 SENSOR_ATTR_2(pwm3_auto_point3_temp, S_IRUGO|S_IWUSR,
677 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
678 2, 2),
679 SENSOR_ATTR_2(pwm3_auto_point4_temp, S_IRUGO|S_IWUSR,
680 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
681 3, 2),
682 SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
683 show_pwm_auto_point_temp_hyst,
684 store_pwm_auto_point_temp_hyst,
685 0, 2),
686 SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
687 show_pwm_auto_point_temp_hyst, NULL, 1, 2),
688 SENSOR_ATTR_2(pwm3_auto_point3_temp_hyst, S_IRUGO,
689 show_pwm_auto_point_temp_hyst, NULL, 2, 2),
690 SENSOR_ATTR_2(pwm3_auto_point4_temp_hyst, S_IRUGO,
691 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
692 }, {
693 SENSOR_ATTR_2(pwm4_auto_channels_temp, S_IRUGO|S_IWUSR,
694 show_pwm_auto_point_channel,
695 store_pwm_auto_point_channel, 0, 3),
696 SENSOR_ATTR_2(pwm4_auto_point1_pwm, S_IRUGO|S_IWUSR,
697 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
698 0, 3),
699 SENSOR_ATTR_2(pwm4_auto_point2_pwm, S_IRUGO|S_IWUSR,
700 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
701 1, 3),
702 SENSOR_ATTR_2(pwm4_auto_point3_pwm, S_IRUGO|S_IWUSR,
703 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
704 2, 3),
705 SENSOR_ATTR_2(pwm4_auto_point4_pwm, S_IRUGO|S_IWUSR,
706 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
707 3, 3),
708 SENSOR_ATTR_2(pwm4_auto_point5_pwm, S_IRUGO|S_IWUSR,
709 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
710 4, 3),
711 SENSOR_ATTR_2(pwm4_auto_point1_temp, S_IRUGO|S_IWUSR,
712 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
713 0, 3),
714 SENSOR_ATTR_2(pwm4_auto_point2_temp, S_IRUGO|S_IWUSR,
715 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
716 1, 3),
717 SENSOR_ATTR_2(pwm4_auto_point3_temp, S_IRUGO|S_IWUSR,
718 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
719 2, 3),
720 SENSOR_ATTR_2(pwm4_auto_point4_temp, S_IRUGO|S_IWUSR,
721 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
722 3, 3),
723 SENSOR_ATTR_2(pwm4_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
724 show_pwm_auto_point_temp_hyst,
725 store_pwm_auto_point_temp_hyst,
726 0, 3),
727 SENSOR_ATTR_2(pwm4_auto_point2_temp_hyst, S_IRUGO,
728 show_pwm_auto_point_temp_hyst, NULL, 1, 3),
729 SENSOR_ATTR_2(pwm4_auto_point3_temp_hyst, S_IRUGO,
730 show_pwm_auto_point_temp_hyst, NULL, 2, 3),
731 SENSOR_ATTR_2(pwm4_auto_point4_temp_hyst, S_IRUGO,
732 show_pwm_auto_point_temp_hyst, NULL, 3, 3),
733 } };
735 /* Fan attr specific to the f8000 (4th fan input can only measure speed) */
736 static struct sensor_device_attribute_2 f8000_fan_attr[] = {
737 SENSOR_ATTR_2(fan4_input, S_IRUGO, show_fan, NULL, 0, 3),
740 /* PWM attr for the f8000, zones mapped to temp instead of to pwm!
741 Also the register block at offset A0 maps to TEMP1 (so our temp2, as the
742 F8000 starts counting temps at 0), B0 maps the TEMP2 and C0 maps to TEMP0 */
743 static struct sensor_device_attribute_2 f8000_auto_pwm_attr[] = {
744 SENSOR_ATTR_2(pwm1_auto_channels_temp, S_IRUGO|S_IWUSR,
745 show_pwm_auto_point_channel,
746 store_pwm_auto_point_channel, 0, 0),
747 SENSOR_ATTR_2(temp1_auto_point1_pwm, S_IRUGO|S_IWUSR,
748 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
749 0, 2),
750 SENSOR_ATTR_2(temp1_auto_point2_pwm, S_IRUGO|S_IWUSR,
751 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
752 1, 2),
753 SENSOR_ATTR_2(temp1_auto_point3_pwm, S_IRUGO|S_IWUSR,
754 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
755 2, 2),
756 SENSOR_ATTR_2(temp1_auto_point4_pwm, S_IRUGO|S_IWUSR,
757 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
758 3, 2),
759 SENSOR_ATTR_2(temp1_auto_point5_pwm, S_IRUGO|S_IWUSR,
760 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
761 4, 2),
762 SENSOR_ATTR_2(temp1_auto_point1_temp, S_IRUGO|S_IWUSR,
763 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
764 0, 2),
765 SENSOR_ATTR_2(temp1_auto_point2_temp, S_IRUGO|S_IWUSR,
766 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
767 1, 2),
768 SENSOR_ATTR_2(temp1_auto_point3_temp, S_IRUGO|S_IWUSR,
769 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
770 2, 2),
771 SENSOR_ATTR_2(temp1_auto_point4_temp, S_IRUGO|S_IWUSR,
772 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
773 3, 2),
774 SENSOR_ATTR_2(temp1_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
775 show_pwm_auto_point_temp_hyst,
776 store_pwm_auto_point_temp_hyst,
777 0, 2),
778 SENSOR_ATTR_2(temp1_auto_point2_temp_hyst, S_IRUGO,
779 show_pwm_auto_point_temp_hyst, NULL, 1, 2),
780 SENSOR_ATTR_2(temp1_auto_point3_temp_hyst, S_IRUGO,
781 show_pwm_auto_point_temp_hyst, NULL, 2, 2),
782 SENSOR_ATTR_2(temp1_auto_point4_temp_hyst, S_IRUGO,
783 show_pwm_auto_point_temp_hyst, NULL, 3, 2),
785 SENSOR_ATTR_2(pwm2_auto_channels_temp, S_IRUGO|S_IWUSR,
786 show_pwm_auto_point_channel,
787 store_pwm_auto_point_channel, 0, 1),
788 SENSOR_ATTR_2(temp2_auto_point1_pwm, S_IRUGO|S_IWUSR,
789 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
790 0, 0),
791 SENSOR_ATTR_2(temp2_auto_point2_pwm, S_IRUGO|S_IWUSR,
792 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
793 1, 0),
794 SENSOR_ATTR_2(temp2_auto_point3_pwm, S_IRUGO|S_IWUSR,
795 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
796 2, 0),
797 SENSOR_ATTR_2(temp2_auto_point4_pwm, S_IRUGO|S_IWUSR,
798 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
799 3, 0),
800 SENSOR_ATTR_2(temp2_auto_point5_pwm, S_IRUGO|S_IWUSR,
801 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
802 4, 0),
803 SENSOR_ATTR_2(temp2_auto_point1_temp, S_IRUGO|S_IWUSR,
804 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
805 0, 0),
806 SENSOR_ATTR_2(temp2_auto_point2_temp, S_IRUGO|S_IWUSR,
807 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
808 1, 0),
809 SENSOR_ATTR_2(temp2_auto_point3_temp, S_IRUGO|S_IWUSR,
810 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
811 2, 0),
812 SENSOR_ATTR_2(temp2_auto_point4_temp, S_IRUGO|S_IWUSR,
813 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
814 3, 0),
815 SENSOR_ATTR_2(temp2_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
816 show_pwm_auto_point_temp_hyst,
817 store_pwm_auto_point_temp_hyst,
818 0, 0),
819 SENSOR_ATTR_2(temp2_auto_point2_temp_hyst, S_IRUGO,
820 show_pwm_auto_point_temp_hyst, NULL, 1, 0),
821 SENSOR_ATTR_2(temp2_auto_point3_temp_hyst, S_IRUGO,
822 show_pwm_auto_point_temp_hyst, NULL, 2, 0),
823 SENSOR_ATTR_2(temp2_auto_point4_temp_hyst, S_IRUGO,
824 show_pwm_auto_point_temp_hyst, NULL, 3, 0),
826 SENSOR_ATTR_2(pwm3_auto_channels_temp, S_IRUGO|S_IWUSR,
827 show_pwm_auto_point_channel,
828 store_pwm_auto_point_channel, 0, 2),
829 SENSOR_ATTR_2(temp3_auto_point1_pwm, S_IRUGO|S_IWUSR,
830 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
831 0, 1),
832 SENSOR_ATTR_2(temp3_auto_point2_pwm, S_IRUGO|S_IWUSR,
833 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
834 1, 1),
835 SENSOR_ATTR_2(temp3_auto_point3_pwm, S_IRUGO|S_IWUSR,
836 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
837 2, 1),
838 SENSOR_ATTR_2(temp3_auto_point4_pwm, S_IRUGO|S_IWUSR,
839 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
840 3, 1),
841 SENSOR_ATTR_2(temp3_auto_point5_pwm, S_IRUGO|S_IWUSR,
842 show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
843 4, 1),
844 SENSOR_ATTR_2(temp3_auto_point1_temp, S_IRUGO|S_IWUSR,
845 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
846 0, 1),
847 SENSOR_ATTR_2(temp3_auto_point2_temp, S_IRUGO|S_IWUSR,
848 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
849 1, 1),
850 SENSOR_ATTR_2(temp3_auto_point3_temp, S_IRUGO|S_IWUSR,
851 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
852 2, 1),
853 SENSOR_ATTR_2(temp3_auto_point4_temp, S_IRUGO|S_IWUSR,
854 show_pwm_auto_point_temp, store_pwm_auto_point_temp,
855 3, 1),
856 SENSOR_ATTR_2(temp3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
857 show_pwm_auto_point_temp_hyst,
858 store_pwm_auto_point_temp_hyst,
859 0, 1),
860 SENSOR_ATTR_2(temp3_auto_point2_temp_hyst, S_IRUGO,
861 show_pwm_auto_point_temp_hyst, NULL, 1, 1),
862 SENSOR_ATTR_2(temp3_auto_point3_temp_hyst, S_IRUGO,
863 show_pwm_auto_point_temp_hyst, NULL, 2, 1),
864 SENSOR_ATTR_2(temp3_auto_point4_temp_hyst, S_IRUGO,
865 show_pwm_auto_point_temp_hyst, NULL, 3, 1),
868 /* Super I/O functions */
869 static inline int superio_inb(int base, int reg)
871 outb(reg, base);
872 return inb(base + 1);
875 static int superio_inw(int base, int reg)
877 int val;
878 val = superio_inb(base, reg) << 8;
879 val |= superio_inb(base, reg + 1);
880 return val;
883 static inline int superio_enter(int base)
885 /* Don't step on other drivers' I/O space by accident */
886 if (!request_muxed_region(base, 2, DRVNAME)) {
887 pr_err("I/O address 0x%04x already in use\n", base);
888 return -EBUSY;
891 /* according to the datasheet the key must be send twice! */
892 outb(SIO_UNLOCK_KEY, base);
893 outb(SIO_UNLOCK_KEY, base);
895 return 0;
898 static inline void superio_select(int base, int ld)
900 outb(SIO_REG_LDSEL, base);
901 outb(ld, base + 1);
904 static inline void superio_exit(int base)
906 outb(SIO_LOCK_KEY, base);
907 release_region(base, 2);
910 static inline int fan_from_reg(u16 reg)
912 return reg ? (1500000 / reg) : 0;
915 static inline u16 fan_to_reg(int fan)
917 return fan ? (1500000 / fan) : 0;
920 static u8 f71882fg_read8(struct f71882fg_data *data, u8 reg)
922 u8 val;
924 outb(reg, data->addr + ADDR_REG_OFFSET);
925 val = inb(data->addr + DATA_REG_OFFSET);
927 return val;
930 static u16 f71882fg_read16(struct f71882fg_data *data, u8 reg)
932 u16 val;
934 val = f71882fg_read8(data, reg) << 8;
935 val |= f71882fg_read8(data, reg + 1);
937 return val;
940 static void f71882fg_write8(struct f71882fg_data *data, u8 reg, u8 val)
942 outb(reg, data->addr + ADDR_REG_OFFSET);
943 outb(val, data->addr + DATA_REG_OFFSET);
946 static void f71882fg_write16(struct f71882fg_data *data, u8 reg, u16 val)
948 f71882fg_write8(data, reg, val >> 8);
949 f71882fg_write8(data, reg + 1, val & 0xff);
952 static u16 f71882fg_read_temp(struct f71882fg_data *data, int nr)
954 if (data->type == f71858fg)
955 return f71882fg_read16(data, F71882FG_REG_TEMP(nr));
956 else
957 return f71882fg_read8(data, F71882FG_REG_TEMP(nr));
960 static struct f71882fg_data *f71882fg_update_device(struct device *dev)
962 struct f71882fg_data *data = dev_get_drvdata(dev);
963 int nr, reg;
964 int nr_fans = (data->type == f71882fg) ? 4 : 3;
966 mutex_lock(&data->update_lock);
968 /* Update once every 60 seconds */
969 if (time_after(jiffies, data->last_limits + 60 * HZ) ||
970 !data->valid) {
971 if (f71882fg_has_in1_alarm[data->type]) {
972 data->in1_max =
973 f71882fg_read8(data, F71882FG_REG_IN1_HIGH);
974 data->in_beep =
975 f71882fg_read8(data, F71882FG_REG_IN_BEEP);
978 /* Get High & boundary temps*/
979 for (nr = data->temp_start; nr < 3 + data->temp_start; nr++) {
980 data->temp_ovt[nr] = f71882fg_read8(data,
981 F71882FG_REG_TEMP_OVT(nr));
982 data->temp_high[nr] = f71882fg_read8(data,
983 F71882FG_REG_TEMP_HIGH(nr));
986 if (data->type != f8000) {
987 data->temp_hyst[0] = f71882fg_read8(data,
988 F71882FG_REG_TEMP_HYST(0));
989 data->temp_hyst[1] = f71882fg_read8(data,
990 F71882FG_REG_TEMP_HYST(1));
993 if (data->type == f71862fg || data->type == f71882fg ||
994 data->type == f71889fg) {
995 data->fan_beep = f71882fg_read8(data,
996 F71882FG_REG_FAN_BEEP);
997 data->temp_beep = f71882fg_read8(data,
998 F71882FG_REG_TEMP_BEEP);
999 reg = f71882fg_read8(data, F71882FG_REG_TEMP_TYPE);
1000 data->temp_type[1] = (reg & 0x02) ? 2 : 4;
1001 data->temp_type[2] = (reg & 0x04) ? 2 : 4;
1002 data->temp_type[3] = (reg & 0x08) ? 2 : 4;
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) {
1018 int point;
1019 for (point = 0; point < 5; point++) {
1020 data->pwm_auto_point_pwm[nr][point] =
1021 f71882fg_read8(data,
1022 F71882FG_REG_POINT_PWM
1023 (nr, point));
1025 for (point = 0; point < 4; point++) {
1026 data->pwm_auto_point_temp[nr][point] =
1027 f71882fg_read8(data,
1028 F71882FG_REG_POINT_TEMP
1029 (nr, point));
1031 } else {
1032 data->pwm_auto_point_pwm[nr][1] =
1033 f71882fg_read8(data,
1034 F71882FG_REG_POINT_PWM
1035 (nr, 1));
1036 data->pwm_auto_point_pwm[nr][4] =
1037 f71882fg_read8(data,
1038 F71882FG_REG_POINT_PWM
1039 (nr, 4));
1040 data->pwm_auto_point_temp[nr][0] =
1041 f71882fg_read8(data,
1042 F71882FG_REG_POINT_TEMP
1043 (nr, 0));
1044 data->pwm_auto_point_temp[nr][3] =
1045 f71882fg_read8(data,
1046 F71882FG_REG_POINT_TEMP
1047 (nr, 3));
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));
1072 data->pwm[nr] =
1073 f71882fg_read8(data, F71882FG_REG_PWM(nr));
1075 /* The f8000 can monitor 1 more fan, but has no pwm for it */
1076 if (data->type == f8000)
1077 data->fan[3] = f71882fg_read16(data,
1078 F71882FG_REG_FAN(3));
1080 if (f71882fg_has_in1_alarm[data->type])
1081 data->in_status = f71882fg_read8(data,
1082 F71882FG_REG_IN_STATUS);
1083 for (nr = 0; nr < F71882FG_MAX_INS; nr++)
1084 if (f71882fg_has_in[data->type][nr])
1085 data->in[nr] = f71882fg_read8(data,
1086 F71882FG_REG_IN(nr));
1088 data->last_updated = jiffies;
1089 data->valid = 1;
1092 mutex_unlock(&data->update_lock);
1094 return data;
1097 /* Sysfs Interface */
1098 static ssize_t show_fan(struct device *dev, struct device_attribute *devattr,
1099 char *buf)
1101 struct f71882fg_data *data = f71882fg_update_device(dev);
1102 int nr = to_sensor_dev_attr_2(devattr)->index;
1103 int speed = fan_from_reg(data->fan[nr]);
1105 if (speed == FAN_MIN_DETECT)
1106 speed = 0;
1108 return sprintf(buf, "%d\n", speed);
1111 static ssize_t show_fan_full_speed(struct device *dev,
1112 struct device_attribute *devattr, char *buf)
1114 struct f71882fg_data *data = f71882fg_update_device(dev);
1115 int nr = to_sensor_dev_attr_2(devattr)->index;
1116 int speed = fan_from_reg(data->fan_full_speed[nr]);
1117 return sprintf(buf, "%d\n", speed);
1120 static ssize_t store_fan_full_speed(struct device *dev,
1121 struct device_attribute *devattr,
1122 const char *buf, size_t count)
1124 struct f71882fg_data *data = dev_get_drvdata(dev);
1125 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1126 long val;
1128 err = strict_strtol(buf, 10, &val);
1129 if (err)
1130 return err;
1132 val = SENSORS_LIMIT(val, 23, 1500000);
1133 val = fan_to_reg(val);
1135 mutex_lock(&data->update_lock);
1136 f71882fg_write16(data, F71882FG_REG_FAN_FULL_SPEED(nr), val);
1137 data->fan_full_speed[nr] = val;
1138 mutex_unlock(&data->update_lock);
1140 return count;
1143 static ssize_t show_fan_beep(struct device *dev, struct device_attribute
1144 *devattr, char *buf)
1146 struct f71882fg_data *data = f71882fg_update_device(dev);
1147 int nr = to_sensor_dev_attr_2(devattr)->index;
1149 if (data->fan_beep & (1 << nr))
1150 return sprintf(buf, "1\n");
1151 else
1152 return sprintf(buf, "0\n");
1155 static ssize_t store_fan_beep(struct device *dev, struct device_attribute
1156 *devattr, const char *buf, size_t count)
1158 struct f71882fg_data *data = dev_get_drvdata(dev);
1159 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1160 unsigned long val;
1162 err = strict_strtoul(buf, 10, &val);
1163 if (err)
1164 return err;
1166 mutex_lock(&data->update_lock);
1167 data->fan_beep = f71882fg_read8(data, F71882FG_REG_FAN_BEEP);
1168 if (val)
1169 data->fan_beep |= 1 << nr;
1170 else
1171 data->fan_beep &= ~(1 << nr);
1173 f71882fg_write8(data, F71882FG_REG_FAN_BEEP, data->fan_beep);
1174 mutex_unlock(&data->update_lock);
1176 return count;
1179 static ssize_t show_fan_alarm(struct device *dev, struct device_attribute
1180 *devattr, char *buf)
1182 struct f71882fg_data *data = f71882fg_update_device(dev);
1183 int nr = to_sensor_dev_attr_2(devattr)->index;
1185 if (data->fan_status & (1 << nr))
1186 return sprintf(buf, "1\n");
1187 else
1188 return sprintf(buf, "0\n");
1191 static ssize_t show_in(struct device *dev, struct device_attribute *devattr,
1192 char *buf)
1194 struct f71882fg_data *data = f71882fg_update_device(dev);
1195 int nr = to_sensor_dev_attr_2(devattr)->index;
1197 return sprintf(buf, "%d\n", data->in[nr] * 8);
1200 static ssize_t show_in_max(struct device *dev, struct device_attribute
1201 *devattr, char *buf)
1203 struct f71882fg_data *data = f71882fg_update_device(dev);
1205 return sprintf(buf, "%d\n", data->in1_max * 8);
1208 static ssize_t store_in_max(struct device *dev, struct device_attribute
1209 *devattr, const char *buf, size_t count)
1211 struct f71882fg_data *data = dev_get_drvdata(dev);
1212 int err;
1213 long val;
1215 err = strict_strtol(buf, 10, &val);
1216 if (err)
1217 return err;
1219 val /= 8;
1220 val = SENSORS_LIMIT(val, 0, 255);
1222 mutex_lock(&data->update_lock);
1223 f71882fg_write8(data, F71882FG_REG_IN1_HIGH, val);
1224 data->in1_max = val;
1225 mutex_unlock(&data->update_lock);
1227 return count;
1230 static ssize_t show_in_beep(struct device *dev, struct device_attribute
1231 *devattr, char *buf)
1233 struct f71882fg_data *data = f71882fg_update_device(dev);
1234 int nr = to_sensor_dev_attr_2(devattr)->index;
1236 if (data->in_beep & (1 << nr))
1237 return sprintf(buf, "1\n");
1238 else
1239 return sprintf(buf, "0\n");
1242 static ssize_t store_in_beep(struct device *dev, struct device_attribute
1243 *devattr, const char *buf, size_t count)
1245 struct f71882fg_data *data = dev_get_drvdata(dev);
1246 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1247 unsigned long val;
1249 err = strict_strtoul(buf, 10, &val);
1250 if (err)
1251 return err;
1253 mutex_lock(&data->update_lock);
1254 data->in_beep = f71882fg_read8(data, F71882FG_REG_IN_BEEP);
1255 if (val)
1256 data->in_beep |= 1 << nr;
1257 else
1258 data->in_beep &= ~(1 << nr);
1260 f71882fg_write8(data, F71882FG_REG_IN_BEEP, data->in_beep);
1261 mutex_unlock(&data->update_lock);
1263 return count;
1266 static ssize_t show_in_alarm(struct device *dev, struct device_attribute
1267 *devattr, char *buf)
1269 struct f71882fg_data *data = f71882fg_update_device(dev);
1270 int nr = to_sensor_dev_attr_2(devattr)->index;
1272 if (data->in_status & (1 << nr))
1273 return sprintf(buf, "1\n");
1274 else
1275 return sprintf(buf, "0\n");
1278 static ssize_t show_temp(struct device *dev, struct device_attribute *devattr,
1279 char *buf)
1281 struct f71882fg_data *data = f71882fg_update_device(dev);
1282 int nr = to_sensor_dev_attr_2(devattr)->index;
1283 int sign, temp;
1285 if (data->type == f71858fg) {
1286 /* TEMP_TABLE_SEL 1 or 3 ? */
1287 if (data->temp_config & 1) {
1288 sign = data->temp[nr] & 0x0001;
1289 temp = (data->temp[nr] >> 5) & 0x7ff;
1290 } else {
1291 sign = data->temp[nr] & 0x8000;
1292 temp = (data->temp[nr] >> 5) & 0x3ff;
1294 temp *= 125;
1295 if (sign)
1296 temp -= 128000;
1297 } else
1298 temp = data->temp[nr] * 1000;
1300 return sprintf(buf, "%d\n", temp);
1303 static ssize_t show_temp_max(struct device *dev, struct device_attribute
1304 *devattr, char *buf)
1306 struct f71882fg_data *data = f71882fg_update_device(dev);
1307 int nr = to_sensor_dev_attr_2(devattr)->index;
1309 return sprintf(buf, "%d\n", data->temp_high[nr] * 1000);
1312 static ssize_t store_temp_max(struct device *dev, struct device_attribute
1313 *devattr, const char *buf, size_t count)
1315 struct f71882fg_data *data = dev_get_drvdata(dev);
1316 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1317 long val;
1319 err = strict_strtol(buf, 10, &val);
1320 if (err)
1321 return err;
1323 val /= 1000;
1324 val = SENSORS_LIMIT(val, 0, 255);
1326 mutex_lock(&data->update_lock);
1327 f71882fg_write8(data, F71882FG_REG_TEMP_HIGH(nr), val);
1328 data->temp_high[nr] = val;
1329 mutex_unlock(&data->update_lock);
1331 return count;
1334 static ssize_t show_temp_max_hyst(struct device *dev, struct device_attribute
1335 *devattr, char *buf)
1337 struct f71882fg_data *data = f71882fg_update_device(dev);
1338 int nr = to_sensor_dev_attr_2(devattr)->index;
1339 int temp_max_hyst;
1341 mutex_lock(&data->update_lock);
1342 if (nr & 1)
1343 temp_max_hyst = data->temp_hyst[nr / 2] >> 4;
1344 else
1345 temp_max_hyst = data->temp_hyst[nr / 2] & 0x0f;
1346 temp_max_hyst = (data->temp_high[nr] - temp_max_hyst) * 1000;
1347 mutex_unlock(&data->update_lock);
1349 return sprintf(buf, "%d\n", temp_max_hyst);
1352 static ssize_t store_temp_max_hyst(struct device *dev, struct device_attribute
1353 *devattr, const char *buf, size_t count)
1355 struct f71882fg_data *data = dev_get_drvdata(dev);
1356 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1357 ssize_t ret = count;
1358 u8 reg;
1359 long val;
1361 err = strict_strtol(buf, 10, &val);
1362 if (err)
1363 return err;
1365 val /= 1000;
1367 mutex_lock(&data->update_lock);
1369 /* convert abs to relative and check */
1370 data->temp_high[nr] = f71882fg_read8(data, F71882FG_REG_TEMP_HIGH(nr));
1371 val = SENSORS_LIMIT(val, data->temp_high[nr] - 15,
1372 data->temp_high[nr]);
1373 val = data->temp_high[nr] - val;
1375 /* convert value to register contents */
1376 reg = f71882fg_read8(data, F71882FG_REG_TEMP_HYST(nr / 2));
1377 if (nr & 1)
1378 reg = (reg & 0x0f) | (val << 4);
1379 else
1380 reg = (reg & 0xf0) | val;
1381 f71882fg_write8(data, F71882FG_REG_TEMP_HYST(nr / 2), reg);
1382 data->temp_hyst[nr / 2] = reg;
1384 mutex_unlock(&data->update_lock);
1385 return ret;
1388 static ssize_t show_temp_crit(struct device *dev, struct device_attribute
1389 *devattr, char *buf)
1391 struct f71882fg_data *data = f71882fg_update_device(dev);
1392 int nr = to_sensor_dev_attr_2(devattr)->index;
1394 return sprintf(buf, "%d\n", data->temp_ovt[nr] * 1000);
1397 static ssize_t store_temp_crit(struct device *dev, struct device_attribute
1398 *devattr, const char *buf, size_t count)
1400 struct f71882fg_data *data = dev_get_drvdata(dev);
1401 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1402 long val;
1404 err = strict_strtol(buf, 10, &val);
1405 if (err)
1406 return err;
1408 val /= 1000;
1409 val = SENSORS_LIMIT(val, 0, 255);
1411 mutex_lock(&data->update_lock);
1412 f71882fg_write8(data, F71882FG_REG_TEMP_OVT(nr), val);
1413 data->temp_ovt[nr] = val;
1414 mutex_unlock(&data->update_lock);
1416 return count;
1419 static ssize_t show_temp_crit_hyst(struct device *dev, struct device_attribute
1420 *devattr, char *buf)
1422 struct f71882fg_data *data = f71882fg_update_device(dev);
1423 int nr = to_sensor_dev_attr_2(devattr)->index;
1424 int temp_crit_hyst;
1426 mutex_lock(&data->update_lock);
1427 if (nr & 1)
1428 temp_crit_hyst = data->temp_hyst[nr / 2] >> 4;
1429 else
1430 temp_crit_hyst = data->temp_hyst[nr / 2] & 0x0f;
1431 temp_crit_hyst = (data->temp_ovt[nr] - temp_crit_hyst) * 1000;
1432 mutex_unlock(&data->update_lock);
1434 return sprintf(buf, "%d\n", temp_crit_hyst);
1437 static ssize_t show_temp_type(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 return sprintf(buf, "%d\n", data->temp_type[nr]);
1446 static ssize_t show_temp_beep(struct device *dev, struct device_attribute
1447 *devattr, char *buf)
1449 struct f71882fg_data *data = f71882fg_update_device(dev);
1450 int nr = to_sensor_dev_attr_2(devattr)->index;
1452 if (data->temp_beep & (1 << nr))
1453 return sprintf(buf, "1\n");
1454 else
1455 return sprintf(buf, "0\n");
1458 static ssize_t store_temp_beep(struct device *dev, struct device_attribute
1459 *devattr, const char *buf, size_t count)
1461 struct f71882fg_data *data = dev_get_drvdata(dev);
1462 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1463 unsigned long val;
1465 err = strict_strtoul(buf, 10, &val);
1466 if (err)
1467 return err;
1469 mutex_lock(&data->update_lock);
1470 data->temp_beep = f71882fg_read8(data, F71882FG_REG_TEMP_BEEP);
1471 if (val)
1472 data->temp_beep |= 1 << nr;
1473 else
1474 data->temp_beep &= ~(1 << nr);
1476 f71882fg_write8(data, F71882FG_REG_TEMP_BEEP, data->temp_beep);
1477 mutex_unlock(&data->update_lock);
1479 return count;
1482 static ssize_t show_temp_alarm(struct device *dev, struct device_attribute
1483 *devattr, char *buf)
1485 struct f71882fg_data *data = f71882fg_update_device(dev);
1486 int nr = to_sensor_dev_attr_2(devattr)->index;
1488 if (data->temp_status & (1 << nr))
1489 return sprintf(buf, "1\n");
1490 else
1491 return sprintf(buf, "0\n");
1494 static ssize_t show_temp_fault(struct device *dev, struct device_attribute
1495 *devattr, char *buf)
1497 struct f71882fg_data *data = f71882fg_update_device(dev);
1498 int nr = to_sensor_dev_attr_2(devattr)->index;
1500 if (data->temp_diode_open & (1 << nr))
1501 return sprintf(buf, "1\n");
1502 else
1503 return sprintf(buf, "0\n");
1506 static ssize_t show_pwm(struct device *dev,
1507 struct device_attribute *devattr, char *buf)
1509 struct f71882fg_data *data = f71882fg_update_device(dev);
1510 int val, nr = to_sensor_dev_attr_2(devattr)->index;
1511 mutex_lock(&data->update_lock);
1512 if (data->pwm_enable & (1 << (2 * nr)))
1513 /* PWM mode */
1514 val = data->pwm[nr];
1515 else {
1516 /* RPM mode */
1517 val = 255 * fan_from_reg(data->fan_target[nr])
1518 / fan_from_reg(data->fan_full_speed[nr]);
1520 mutex_unlock(&data->update_lock);
1521 return sprintf(buf, "%d\n", val);
1524 static ssize_t store_pwm(struct device *dev,
1525 struct device_attribute *devattr, const char *buf,
1526 size_t count)
1528 struct f71882fg_data *data = dev_get_drvdata(dev);
1529 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1530 long val;
1532 err = strict_strtol(buf, 10, &val);
1533 if (err)
1534 return err;
1536 val = SENSORS_LIMIT(val, 0, 255);
1538 mutex_lock(&data->update_lock);
1539 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
1540 if ((data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 3) != 2) ||
1541 (data->type != f8000 && !((data->pwm_enable >> 2 * nr) & 2))) {
1542 count = -EROFS;
1543 goto leave;
1545 if (data->pwm_enable & (1 << (2 * nr))) {
1546 /* PWM mode */
1547 f71882fg_write8(data, F71882FG_REG_PWM(nr), val);
1548 data->pwm[nr] = val;
1549 } else {
1550 /* RPM mode */
1551 int target, full_speed;
1552 full_speed = f71882fg_read16(data,
1553 F71882FG_REG_FAN_FULL_SPEED(nr));
1554 target = fan_to_reg(val * fan_from_reg(full_speed) / 255);
1555 f71882fg_write16(data, F71882FG_REG_FAN_TARGET(nr), target);
1556 data->fan_target[nr] = target;
1557 data->fan_full_speed[nr] = full_speed;
1559 leave:
1560 mutex_unlock(&data->update_lock);
1562 return count;
1565 static ssize_t show_pwm_enable(struct device *dev,
1566 struct device_attribute *devattr, char *buf)
1568 int result = 0;
1569 struct f71882fg_data *data = f71882fg_update_device(dev);
1570 int nr = to_sensor_dev_attr_2(devattr)->index;
1572 switch ((data->pwm_enable >> 2 * nr) & 3) {
1573 case 0:
1574 case 1:
1575 result = 2; /* Normal auto mode */
1576 break;
1577 case 2:
1578 result = 1; /* Manual mode */
1579 break;
1580 case 3:
1581 if (data->type == f8000)
1582 result = 3; /* Thermostat mode */
1583 else
1584 result = 1; /* Manual mode */
1585 break;
1588 return sprintf(buf, "%d\n", result);
1591 static ssize_t store_pwm_enable(struct device *dev, struct device_attribute
1592 *devattr, const char *buf, size_t count)
1594 struct f71882fg_data *data = dev_get_drvdata(dev);
1595 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1596 long val;
1598 err = strict_strtol(buf, 10, &val);
1599 if (err)
1600 return err;
1602 /* Special case for F8000 pwm channel 3 which only does auto mode */
1603 if (data->type == f8000 && nr == 2 && val != 2)
1604 return -EINVAL;
1606 mutex_lock(&data->update_lock);
1607 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
1608 /* Special case for F8000 auto PWM mode / Thermostat mode */
1609 if (data->type == f8000 && ((data->pwm_enable >> 2 * nr) & 1)) {
1610 switch (val) {
1611 case 2:
1612 data->pwm_enable &= ~(2 << (2 * nr));
1613 break; /* Normal auto mode */
1614 case 3:
1615 data->pwm_enable |= 2 << (2 * nr);
1616 break; /* Thermostat mode */
1617 default:
1618 count = -EINVAL;
1619 goto leave;
1621 } else {
1622 switch (val) {
1623 case 1:
1624 /* The f71858fg does not support manual RPM mode */
1625 if (data->type == f71858fg &&
1626 ((data->pwm_enable >> (2 * nr)) & 1)) {
1627 count = -EINVAL;
1628 goto leave;
1630 data->pwm_enable |= 2 << (2 * nr);
1631 break; /* Manual */
1632 case 2:
1633 data->pwm_enable &= ~(2 << (2 * nr));
1634 break; /* Normal auto mode */
1635 default:
1636 count = -EINVAL;
1637 goto leave;
1640 f71882fg_write8(data, F71882FG_REG_PWM_ENABLE, data->pwm_enable);
1641 leave:
1642 mutex_unlock(&data->update_lock);
1644 return count;
1647 static ssize_t show_pwm_auto_point_pwm(struct device *dev,
1648 struct device_attribute *devattr,
1649 char *buf)
1651 int result;
1652 struct f71882fg_data *data = f71882fg_update_device(dev);
1653 int pwm = to_sensor_dev_attr_2(devattr)->index;
1654 int point = to_sensor_dev_attr_2(devattr)->nr;
1656 mutex_lock(&data->update_lock);
1657 if (data->pwm_enable & (1 << (2 * pwm))) {
1658 /* PWM mode */
1659 result = data->pwm_auto_point_pwm[pwm][point];
1660 } else {
1661 /* RPM mode */
1662 result = 32 * 255 / (32 + data->pwm_auto_point_pwm[pwm][point]);
1664 mutex_unlock(&data->update_lock);
1666 return sprintf(buf, "%d\n", result);
1669 static ssize_t store_pwm_auto_point_pwm(struct device *dev,
1670 struct device_attribute *devattr,
1671 const char *buf, size_t count)
1673 struct f71882fg_data *data = dev_get_drvdata(dev);
1674 int err, pwm = to_sensor_dev_attr_2(devattr)->index;
1675 int point = to_sensor_dev_attr_2(devattr)->nr;
1676 long val;
1678 err = strict_strtol(buf, 10, &val);
1679 if (err)
1680 return err;
1682 val = SENSORS_LIMIT(val, 0, 255);
1684 mutex_lock(&data->update_lock);
1685 data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
1686 if (data->pwm_enable & (1 << (2 * pwm))) {
1687 /* PWM mode */
1688 } else {
1689 /* RPM mode */
1690 if (val < 29) /* Prevent negative numbers */
1691 val = 255;
1692 else
1693 val = (255 - val) * 32 / val;
1695 f71882fg_write8(data, F71882FG_REG_POINT_PWM(pwm, point), val);
1696 data->pwm_auto_point_pwm[pwm][point] = val;
1697 mutex_unlock(&data->update_lock);
1699 return count;
1702 static ssize_t show_pwm_auto_point_temp_hyst(struct device *dev,
1703 struct device_attribute *devattr,
1704 char *buf)
1706 int result = 0;
1707 struct f71882fg_data *data = f71882fg_update_device(dev);
1708 int nr = to_sensor_dev_attr_2(devattr)->index;
1709 int point = to_sensor_dev_attr_2(devattr)->nr;
1711 mutex_lock(&data->update_lock);
1712 if (nr & 1)
1713 result = data->pwm_auto_point_hyst[nr / 2] >> 4;
1714 else
1715 result = data->pwm_auto_point_hyst[nr / 2] & 0x0f;
1716 result = 1000 * (data->pwm_auto_point_temp[nr][point] - result);
1717 mutex_unlock(&data->update_lock);
1719 return sprintf(buf, "%d\n", result);
1722 static ssize_t store_pwm_auto_point_temp_hyst(struct device *dev,
1723 struct device_attribute *devattr,
1724 const char *buf, size_t count)
1726 struct f71882fg_data *data = dev_get_drvdata(dev);
1727 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1728 int point = to_sensor_dev_attr_2(devattr)->nr;
1729 u8 reg;
1730 long val;
1732 err = strict_strtol(buf, 10, &val);
1733 if (err)
1734 return err;
1736 val /= 1000;
1738 mutex_lock(&data->update_lock);
1739 data->pwm_auto_point_temp[nr][point] =
1740 f71882fg_read8(data, F71882FG_REG_POINT_TEMP(nr, point));
1741 val = SENSORS_LIMIT(val, data->pwm_auto_point_temp[nr][point] - 15,
1742 data->pwm_auto_point_temp[nr][point]);
1743 val = data->pwm_auto_point_temp[nr][point] - val;
1745 reg = f71882fg_read8(data, F71882FG_REG_FAN_HYST(nr / 2));
1746 if (nr & 1)
1747 reg = (reg & 0x0f) | (val << 4);
1748 else
1749 reg = (reg & 0xf0) | val;
1751 f71882fg_write8(data, F71882FG_REG_FAN_HYST(nr / 2), reg);
1752 data->pwm_auto_point_hyst[nr / 2] = reg;
1753 mutex_unlock(&data->update_lock);
1755 return count;
1758 static ssize_t show_pwm_interpolate(struct device *dev,
1759 struct device_attribute *devattr, char *buf)
1761 int result;
1762 struct f71882fg_data *data = f71882fg_update_device(dev);
1763 int nr = to_sensor_dev_attr_2(devattr)->index;
1765 result = (data->pwm_auto_point_mapping[nr] >> 4) & 1;
1767 return sprintf(buf, "%d\n", result);
1770 static ssize_t store_pwm_interpolate(struct device *dev,
1771 struct device_attribute *devattr,
1772 const char *buf, size_t count)
1774 struct f71882fg_data *data = dev_get_drvdata(dev);
1775 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1776 unsigned long val;
1778 err = strict_strtoul(buf, 10, &val);
1779 if (err)
1780 return err;
1782 mutex_lock(&data->update_lock);
1783 data->pwm_auto_point_mapping[nr] =
1784 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
1785 if (val)
1786 val = data->pwm_auto_point_mapping[nr] | (1 << 4);
1787 else
1788 val = data->pwm_auto_point_mapping[nr] & (~(1 << 4));
1789 f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val);
1790 data->pwm_auto_point_mapping[nr] = val;
1791 mutex_unlock(&data->update_lock);
1793 return count;
1796 static ssize_t show_pwm_auto_point_channel(struct device *dev,
1797 struct device_attribute *devattr,
1798 char *buf)
1800 int result;
1801 struct f71882fg_data *data = f71882fg_update_device(dev);
1802 int nr = to_sensor_dev_attr_2(devattr)->index;
1804 result = 1 << ((data->pwm_auto_point_mapping[nr] & 3) -
1805 data->temp_start);
1807 return sprintf(buf, "%d\n", result);
1810 static ssize_t store_pwm_auto_point_channel(struct device *dev,
1811 struct device_attribute *devattr,
1812 const char *buf, size_t count)
1814 struct f71882fg_data *data = dev_get_drvdata(dev);
1815 int err, nr = to_sensor_dev_attr_2(devattr)->index;
1816 long val;
1818 err = strict_strtol(buf, 10, &val);
1819 if (err)
1820 return err;
1822 switch (val) {
1823 case 1:
1824 val = 0;
1825 break;
1826 case 2:
1827 val = 1;
1828 break;
1829 case 4:
1830 val = 2;
1831 break;
1832 default:
1833 return -EINVAL;
1835 val += data->temp_start;
1836 mutex_lock(&data->update_lock);
1837 data->pwm_auto_point_mapping[nr] =
1838 f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
1839 val = (data->pwm_auto_point_mapping[nr] & 0xfc) | val;
1840 f71882fg_write8(data, F71882FG_REG_POINT_MAPPING(nr), val);
1841 data->pwm_auto_point_mapping[nr] = val;
1842 mutex_unlock(&data->update_lock);
1844 return count;
1847 static ssize_t show_pwm_auto_point_temp(struct device *dev,
1848 struct device_attribute *devattr,
1849 char *buf)
1851 int result;
1852 struct f71882fg_data *data = f71882fg_update_device(dev);
1853 int pwm = to_sensor_dev_attr_2(devattr)->index;
1854 int point = to_sensor_dev_attr_2(devattr)->nr;
1856 result = data->pwm_auto_point_temp[pwm][point];
1857 return sprintf(buf, "%d\n", 1000 * result);
1860 static ssize_t store_pwm_auto_point_temp(struct device *dev,
1861 struct device_attribute *devattr,
1862 const char *buf, size_t count)
1864 struct f71882fg_data *data = dev_get_drvdata(dev);
1865 int err, pwm = to_sensor_dev_attr_2(devattr)->index;
1866 int point = to_sensor_dev_attr_2(devattr)->nr;
1867 long val;
1869 err = strict_strtol(buf, 10, &val);
1870 if (err)
1871 return err;
1873 val /= 1000;
1875 if (data->auto_point_temp_signed)
1876 val = SENSORS_LIMIT(val, -128, 127);
1877 else
1878 val = SENSORS_LIMIT(val, 0, 127);
1880 mutex_lock(&data->update_lock);
1881 f71882fg_write8(data, F71882FG_REG_POINT_TEMP(pwm, point), val);
1882 data->pwm_auto_point_temp[pwm][point] = val;
1883 mutex_unlock(&data->update_lock);
1885 return count;
1888 static ssize_t show_name(struct device *dev, struct device_attribute *devattr,
1889 char *buf)
1891 struct f71882fg_data *data = dev_get_drvdata(dev);
1892 return sprintf(buf, "%s\n", f71882fg_names[data->type]);
1895 static int __devinit f71882fg_create_sysfs_files(struct platform_device *pdev,
1896 struct sensor_device_attribute_2 *attr, int count)
1898 int err, i;
1900 for (i = 0; i < count; i++) {
1901 err = device_create_file(&pdev->dev, &attr[i].dev_attr);
1902 if (err)
1903 return err;
1905 return 0;
1908 static void f71882fg_remove_sysfs_files(struct platform_device *pdev,
1909 struct sensor_device_attribute_2 *attr, int count)
1911 int i;
1913 for (i = 0; i < count; i++)
1914 device_remove_file(&pdev->dev, &attr[i].dev_attr);
1917 static int __devinit f71882fg_probe(struct platform_device *pdev)
1919 struct f71882fg_data *data;
1920 struct f71882fg_sio_data *sio_data = pdev->dev.platform_data;
1921 int err, i, nr_fans = (sio_data->type == f71882fg) ? 4 : 3;
1922 int nr_temps = 3;
1923 u8 start_reg, reg;
1925 data = kzalloc(sizeof(struct f71882fg_data), GFP_KERNEL);
1926 if (!data)
1927 return -ENOMEM;
1929 data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start;
1930 data->type = sio_data->type;
1931 data->temp_start =
1932 (data->type == f71858fg || data->type == f8000) ? 0 : 1;
1933 mutex_init(&data->update_lock);
1934 platform_set_drvdata(pdev, data);
1936 start_reg = f71882fg_read8(data, F71882FG_REG_START);
1937 if (start_reg & 0x04) {
1938 dev_warn(&pdev->dev, "Hardware monitor is powered down\n");
1939 err = -ENODEV;
1940 goto exit_free;
1942 if (!(start_reg & 0x03)) {
1943 dev_warn(&pdev->dev, "Hardware monitoring not activated\n");
1944 err = -ENODEV;
1945 goto exit_free;
1948 /* Register sysfs interface files */
1949 err = device_create_file(&pdev->dev, &dev_attr_name);
1950 if (err)
1951 goto exit_unregister_sysfs;
1953 if (start_reg & 0x01) {
1954 switch (data->type) {
1955 case f71858fg:
1956 data->temp_config =
1957 f71882fg_read8(data, F71882FG_REG_TEMP_CONFIG);
1958 if (data->temp_config & 0x10)
1959 /* The f71858fg temperature alarms behave as
1960 the f8000 alarms in this mode */
1961 err = f71882fg_create_sysfs_files(pdev,
1962 f8000_temp_attr,
1963 ARRAY_SIZE(f8000_temp_attr));
1964 else
1965 err = f71882fg_create_sysfs_files(pdev,
1966 f71858fg_temp_attr,
1967 ARRAY_SIZE(f71858fg_temp_attr));
1968 break;
1969 case f8000:
1970 err = f71882fg_create_sysfs_files(pdev,
1971 f8000_temp_attr,
1972 ARRAY_SIZE(f8000_temp_attr));
1973 break;
1974 default:
1975 err = f71882fg_create_sysfs_files(pdev,
1976 &fxxxx_temp_attr[0][0],
1977 ARRAY_SIZE(fxxxx_temp_attr[0]) * nr_temps);
1979 if (err)
1980 goto exit_unregister_sysfs;
1982 for (i = 0; i < F71882FG_MAX_INS; i++) {
1983 if (f71882fg_has_in[data->type][i]) {
1984 err = device_create_file(&pdev->dev,
1985 &fxxxx_in_attr[i].dev_attr);
1986 if (err)
1987 goto exit_unregister_sysfs;
1990 if (f71882fg_has_in1_alarm[data->type]) {
1991 err = f71882fg_create_sysfs_files(pdev,
1992 fxxxx_in1_alarm_attr,
1993 ARRAY_SIZE(fxxxx_in1_alarm_attr));
1994 if (err)
1995 goto exit_unregister_sysfs;
1999 if (start_reg & 0x02) {
2000 switch (data->type) {
2001 case f71889fg:
2002 reg = f71882fg_read8(data, F71882FG_REG_FAN_FAULT_T);
2003 if (reg & F71882FG_FAN_NEG_TEMP_EN)
2004 data->auto_point_temp_signed = 1;
2005 break;
2006 default:
2007 break;
2010 data->pwm_enable =
2011 f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
2013 /* Sanity check the pwm settings */
2014 switch (data->type) {
2015 case f71858fg:
2016 err = 0;
2017 for (i = 0; i < nr_fans; i++)
2018 if (((data->pwm_enable >> (i * 2)) & 3) == 3)
2019 err = 1;
2020 break;
2021 case f71862fg:
2022 err = (data->pwm_enable & 0x15) != 0x15;
2023 break;
2024 case f71882fg:
2025 case f71889fg:
2026 err = 0;
2027 break;
2028 case f8000:
2029 err = data->pwm_enable & 0x20;
2030 break;
2032 if (err) {
2033 dev_err(&pdev->dev,
2034 "Invalid (reserved) pwm settings: 0x%02x\n",
2035 (unsigned int)data->pwm_enable);
2036 err = -ENODEV;
2037 goto exit_unregister_sysfs;
2040 err = f71882fg_create_sysfs_files(pdev, &fxxxx_fan_attr[0][0],
2041 ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans);
2042 if (err)
2043 goto exit_unregister_sysfs;
2045 if (data->type == f71862fg || data->type == f71882fg ||
2046 data->type == f71889fg) {
2047 err = f71882fg_create_sysfs_files(pdev,
2048 fxxxx_fan_beep_attr, nr_fans);
2049 if (err)
2050 goto exit_unregister_sysfs;
2053 switch (data->type) {
2054 case f71862fg:
2055 err = f71882fg_create_sysfs_files(pdev,
2056 f71862fg_auto_pwm_attr,
2057 ARRAY_SIZE(f71862fg_auto_pwm_attr));
2058 break;
2059 case f8000:
2060 err = f71882fg_create_sysfs_files(pdev,
2061 f8000_fan_attr,
2062 ARRAY_SIZE(f8000_fan_attr));
2063 if (err)
2064 goto exit_unregister_sysfs;
2065 err = f71882fg_create_sysfs_files(pdev,
2066 f8000_auto_pwm_attr,
2067 ARRAY_SIZE(f8000_auto_pwm_attr));
2068 break;
2069 case f71889fg:
2070 for (i = 0; i < nr_fans; i++) {
2071 data->pwm_auto_point_mapping[i] =
2072 f71882fg_read8(data,
2073 F71882FG_REG_POINT_MAPPING(i));
2074 if (data->pwm_auto_point_mapping[i] & 0x80)
2075 break;
2077 if (i != nr_fans) {
2078 dev_warn(&pdev->dev,
2079 "Auto pwm controlled by raw digital "
2080 "data, disabling pwm auto_point "
2081 "sysfs attributes\n");
2082 break;
2084 /* fall through */
2085 default: /* f71858fg / f71882fg */
2086 err = f71882fg_create_sysfs_files(pdev,
2087 &fxxxx_auto_pwm_attr[0][0],
2088 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
2090 if (err)
2091 goto exit_unregister_sysfs;
2093 for (i = 0; i < nr_fans; i++)
2094 dev_info(&pdev->dev, "Fan: %d is in %s mode\n", i + 1,
2095 (data->pwm_enable & (1 << 2 * i)) ?
2096 "duty-cycle" : "RPM");
2099 data->hwmon_dev = hwmon_device_register(&pdev->dev);
2100 if (IS_ERR(data->hwmon_dev)) {
2101 err = PTR_ERR(data->hwmon_dev);
2102 data->hwmon_dev = NULL;
2103 goto exit_unregister_sysfs;
2106 return 0;
2108 exit_unregister_sysfs:
2109 f71882fg_remove(pdev); /* Will unregister the sysfs files for us */
2110 return err; /* f71882fg_remove() also frees our data */
2111 exit_free:
2112 kfree(data);
2113 return err;
2116 static int f71882fg_remove(struct platform_device *pdev)
2118 struct f71882fg_data *data = platform_get_drvdata(pdev);
2119 int i, nr_fans = (data->type == f71882fg) ? 4 : 3;
2120 int nr_temps = 3;
2121 u8 start_reg = f71882fg_read8(data, F71882FG_REG_START);
2123 if (data->hwmon_dev)
2124 hwmon_device_unregister(data->hwmon_dev);
2126 device_remove_file(&pdev->dev, &dev_attr_name);
2128 if (start_reg & 0x01) {
2129 switch (data->type) {
2130 case f71858fg:
2131 if (data->temp_config & 0x10)
2132 f71882fg_remove_sysfs_files(pdev,
2133 f8000_temp_attr,
2134 ARRAY_SIZE(f8000_temp_attr));
2135 else
2136 f71882fg_remove_sysfs_files(pdev,
2137 f71858fg_temp_attr,
2138 ARRAY_SIZE(f71858fg_temp_attr));
2139 break;
2140 case f8000:
2141 f71882fg_remove_sysfs_files(pdev,
2142 f8000_temp_attr,
2143 ARRAY_SIZE(f8000_temp_attr));
2144 break;
2145 default:
2146 f71882fg_remove_sysfs_files(pdev,
2147 &fxxxx_temp_attr[0][0],
2148 ARRAY_SIZE(fxxxx_temp_attr[0]) * nr_temps);
2150 for (i = 0; i < F71882FG_MAX_INS; i++) {
2151 if (f71882fg_has_in[data->type][i]) {
2152 device_remove_file(&pdev->dev,
2153 &fxxxx_in_attr[i].dev_attr);
2156 if (f71882fg_has_in1_alarm[data->type]) {
2157 f71882fg_remove_sysfs_files(pdev,
2158 fxxxx_in1_alarm_attr,
2159 ARRAY_SIZE(fxxxx_in1_alarm_attr));
2163 if (start_reg & 0x02) {
2164 f71882fg_remove_sysfs_files(pdev, &fxxxx_fan_attr[0][0],
2165 ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans);
2167 if (data->type == f71862fg || data->type == f71882fg ||
2168 data->type == f71889fg)
2169 f71882fg_remove_sysfs_files(pdev,
2170 fxxxx_fan_beep_attr, nr_fans);
2172 switch (data->type) {
2173 case f71862fg:
2174 f71882fg_remove_sysfs_files(pdev,
2175 f71862fg_auto_pwm_attr,
2176 ARRAY_SIZE(f71862fg_auto_pwm_attr));
2177 break;
2178 case f8000:
2179 f71882fg_remove_sysfs_files(pdev,
2180 f8000_fan_attr,
2181 ARRAY_SIZE(f8000_fan_attr));
2182 f71882fg_remove_sysfs_files(pdev,
2183 f8000_auto_pwm_attr,
2184 ARRAY_SIZE(f8000_auto_pwm_attr));
2185 break;
2186 default: /* f71858fg / f71882fg / f71889fg */
2187 f71882fg_remove_sysfs_files(pdev,
2188 &fxxxx_auto_pwm_attr[0][0],
2189 ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
2193 platform_set_drvdata(pdev, NULL);
2194 kfree(data);
2196 return 0;
2199 static int __init f71882fg_find(int sioaddr, unsigned short *address,
2200 struct f71882fg_sio_data *sio_data)
2202 u16 devid;
2203 int err = superio_enter(sioaddr);
2204 if (err)
2205 return err;
2207 devid = superio_inw(sioaddr, SIO_REG_MANID);
2208 if (devid != SIO_FINTEK_ID) {
2209 pr_debug("Not a Fintek device\n");
2210 err = -ENODEV;
2211 goto exit;
2214 devid = force_id ? force_id : superio_inw(sioaddr, SIO_REG_DEVID);
2215 switch (devid) {
2216 case SIO_F71858_ID:
2217 sio_data->type = f71858fg;
2218 break;
2219 case SIO_F71862_ID:
2220 sio_data->type = f71862fg;
2221 break;
2222 case SIO_F71882_ID:
2223 sio_data->type = f71882fg;
2224 break;
2225 case SIO_F71889_ID:
2226 sio_data->type = f71889fg;
2227 break;
2228 case SIO_F8000_ID:
2229 sio_data->type = f8000;
2230 break;
2231 default:
2232 pr_info("Unsupported Fintek device: %04x\n",
2233 (unsigned int)devid);
2234 err = -ENODEV;
2235 goto exit;
2238 if (sio_data->type == f71858fg)
2239 superio_select(sioaddr, SIO_F71858FG_LD_HWM);
2240 else
2241 superio_select(sioaddr, SIO_F71882FG_LD_HWM);
2243 if (!(superio_inb(sioaddr, SIO_REG_ENABLE) & 0x01)) {
2244 pr_warn("Device not activated\n");
2245 err = -ENODEV;
2246 goto exit;
2249 *address = superio_inw(sioaddr, SIO_REG_ADDR);
2250 if (*address == 0) {
2251 pr_warn("Base address not set\n");
2252 err = -ENODEV;
2253 goto exit;
2255 *address &= ~(REGION_LENGTH - 1); /* Ignore 3 LSB */
2257 err = 0;
2258 pr_info("Found %s chip at %#x, revision %d\n",
2259 f71882fg_names[sio_data->type], (unsigned int)*address,
2260 (int)superio_inb(sioaddr, SIO_REG_DEVREV));
2261 exit:
2262 superio_exit(sioaddr);
2263 return err;
2266 static int __init f71882fg_device_add(unsigned short address,
2267 const struct f71882fg_sio_data *sio_data)
2269 struct resource res = {
2270 .start = address,
2271 .end = address + REGION_LENGTH - 1,
2272 .flags = IORESOURCE_IO,
2274 int err;
2276 f71882fg_pdev = platform_device_alloc(DRVNAME, address);
2277 if (!f71882fg_pdev)
2278 return -ENOMEM;
2280 res.name = f71882fg_pdev->name;
2281 err = acpi_check_resource_conflict(&res);
2282 if (err)
2283 goto exit_device_put;
2285 err = platform_device_add_resources(f71882fg_pdev, &res, 1);
2286 if (err) {
2287 pr_err("Device resource addition failed\n");
2288 goto exit_device_put;
2291 err = platform_device_add_data(f71882fg_pdev, sio_data,
2292 sizeof(struct f71882fg_sio_data));
2293 if (err) {
2294 pr_err("Platform data allocation failed\n");
2295 goto exit_device_put;
2298 err = platform_device_add(f71882fg_pdev);
2299 if (err) {
2300 pr_err("Device addition failed\n");
2301 goto exit_device_put;
2304 return 0;
2306 exit_device_put:
2307 platform_device_put(f71882fg_pdev);
2309 return err;
2312 static int __init f71882fg_init(void)
2314 int err = -ENODEV;
2315 unsigned short address;
2316 struct f71882fg_sio_data sio_data;
2318 memset(&sio_data, 0, sizeof(sio_data));
2320 if (f71882fg_find(0x2e, &address, &sio_data) &&
2321 f71882fg_find(0x4e, &address, &sio_data))
2322 goto exit;
2324 err = platform_driver_register(&f71882fg_driver);
2325 if (err)
2326 goto exit;
2328 err = f71882fg_device_add(address, &sio_data);
2329 if (err)
2330 goto exit_driver;
2332 return 0;
2334 exit_driver:
2335 platform_driver_unregister(&f71882fg_driver);
2336 exit:
2337 return err;
2340 static void __exit f71882fg_exit(void)
2342 platform_device_unregister(f71882fg_pdev);
2343 platform_driver_unregister(&f71882fg_driver);
2346 MODULE_DESCRIPTION("F71882FG Hardware Monitoring Driver");
2347 MODULE_AUTHOR("Hans Edgington, Hans de Goede (hdegoede@redhat.com)");
2348 MODULE_LICENSE("GPL");
2350 module_init(f71882fg_init);
2351 module_exit(f71882fg_exit);