2 * nct6775 - Driver for the hardware monitoring functionality of
3 * Nuvoton NCT677x Super-I/O chips
5 * Copyright (C) 2012 Guenter Roeck <linux@roeck-us.net>
7 * Derived from w83627ehf driver
8 * Copyright (C) 2005-2012 Jean Delvare <jdelvare@suse.de>
9 * Copyright (C) 2006 Yuan Mu (Winbond),
10 * Rudolf Marek <r.marek@assembler.cz>
11 * David Hubbard <david.c.hubbard@gmail.com>
12 * Daniel J Blueman <daniel.blueman@gmail.com>
13 * Copyright (C) 2010 Sheng-Yuan Huang (Nuvoton) (PS00)
15 * Shamelessly ripped from the w83627hf driver
16 * Copyright (C) 2003 Mark Studebaker
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
33 * Supports the following chips:
35 * Chip #vin #fan #pwm #temp chip IDs man ID
36 * nct6106d 9 3 3 6+3 0xc450 0xc1 0x5ca3
37 * nct6775f 9 4 3 6+3 0xb470 0xc1 0x5ca3
38 * nct6776f 9 5 3 6+3 0xc330 0xc1 0x5ca3
39 * nct6779d 15 5 5 2+6 0xc560 0xc1 0x5ca3
40 * nct6791d 15 6 6 2+6 0xc800 0xc1 0x5ca3
41 * nct6792d 15 6 6 2+6 0xc910 0xc1 0x5ca3
43 * #temp lists the number of monitored temperature sources (first value) plus
44 * the number of directly connectable temperature sensors (second value).
47 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
49 #include <linux/module.h>
50 #include <linux/init.h>
51 #include <linux/slab.h>
52 #include <linux/jiffies.h>
53 #include <linux/platform_device.h>
54 #include <linux/hwmon.h>
55 #include <linux/hwmon-sysfs.h>
56 #include <linux/hwmon-vid.h>
57 #include <linux/err.h>
58 #include <linux/mutex.h>
59 #include <linux/acpi.h>
65 enum kinds
{ nct6106
, nct6775
, nct6776
, nct6779
, nct6791
, nct6792
};
67 /* used to set data->name = nct6775_device_names[data->sio_kind] */
68 static const char * const nct6775_device_names
[] = {
77 static unsigned short force_id
;
78 module_param(force_id
, ushort
, 0);
79 MODULE_PARM_DESC(force_id
, "Override the detected device ID");
81 static unsigned short fan_debounce
;
82 module_param(fan_debounce
, ushort
, 0);
83 MODULE_PARM_DESC(fan_debounce
, "Enable debouncing for fan RPM signal");
85 #define DRVNAME "nct6775"
88 * Super-I/O constants and functions
91 #define NCT6775_LD_ACPI 0x0a
92 #define NCT6775_LD_HWM 0x0b
93 #define NCT6775_LD_VID 0x0d
95 #define SIO_REG_LDSEL 0x07 /* Logical device select */
96 #define SIO_REG_DEVID 0x20 /* Device ID (2 bytes) */
97 #define SIO_REG_ENABLE 0x30 /* Logical device enable */
98 #define SIO_REG_ADDR 0x60 /* Logical device address (2 bytes) */
100 #define SIO_NCT6106_ID 0xc450
101 #define SIO_NCT6775_ID 0xb470
102 #define SIO_NCT6776_ID 0xc330
103 #define SIO_NCT6779_ID 0xc560
104 #define SIO_NCT6791_ID 0xc800
105 #define SIO_NCT6792_ID 0xc910
106 #define SIO_ID_MASK 0xFFF0
108 enum pwm_enable
{ off
, manual
, thermal_cruise
, speed_cruise
, sf3
, sf4
};
111 superio_outb(int ioreg
, int reg
, int val
)
114 outb(val
, ioreg
+ 1);
118 superio_inb(int ioreg
, int reg
)
121 return inb(ioreg
+ 1);
125 superio_select(int ioreg
, int ld
)
127 outb(SIO_REG_LDSEL
, ioreg
);
132 superio_enter(int ioreg
)
135 * Try to reserve <ioreg> and <ioreg + 1> for exclusive access.
137 if (!request_muxed_region(ioreg
, 2, DRVNAME
))
147 superio_exit(int ioreg
)
151 outb(0x02, ioreg
+ 1);
152 release_region(ioreg
, 2);
159 #define IOREGION_ALIGNMENT (~7)
160 #define IOREGION_OFFSET 5
161 #define IOREGION_LENGTH 2
162 #define ADDR_REG_OFFSET 0
163 #define DATA_REG_OFFSET 1
165 #define NCT6775_REG_BANK 0x4E
166 #define NCT6775_REG_CONFIG 0x40
169 * Not currently used:
170 * REG_MAN_ID has the value 0x5ca3 for all supported chips.
171 * REG_CHIP_ID == 0x88/0xa1/0xc1 depending on chip model.
172 * REG_MAN_ID is at port 0x4f
173 * REG_CHIP_ID is at port 0x58
176 #define NUM_TEMP 10 /* Max number of temp attribute sets w/ limits*/
177 #define NUM_TEMP_FIXED 6 /* Max number of fixed temp attribute sets */
179 #define NUM_REG_ALARM 7 /* Max number of alarm registers */
180 #define NUM_REG_BEEP 5 /* Max number of beep registers */
184 /* Common and NCT6775 specific data */
186 /* Voltage min/max registers for nr=7..14 are in bank 5 */
188 static const u16 NCT6775_REG_IN_MAX
[] = {
189 0x2b, 0x2d, 0x2f, 0x31, 0x33, 0x35, 0x37, 0x554, 0x556, 0x558, 0x55a,
190 0x55c, 0x55e, 0x560, 0x562 };
191 static const u16 NCT6775_REG_IN_MIN
[] = {
192 0x2c, 0x2e, 0x30, 0x32, 0x34, 0x36, 0x38, 0x555, 0x557, 0x559, 0x55b,
193 0x55d, 0x55f, 0x561, 0x563 };
194 static const u16 NCT6775_REG_IN
[] = {
195 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x550, 0x551, 0x552
198 #define NCT6775_REG_VBAT 0x5D
199 #define NCT6775_REG_DIODE 0x5E
200 #define NCT6775_DIODE_MASK 0x02
202 #define NCT6775_REG_FANDIV1 0x506
203 #define NCT6775_REG_FANDIV2 0x507
205 #define NCT6775_REG_CR_FAN_DEBOUNCE 0xf0
207 static const u16 NCT6775_REG_ALARM
[NUM_REG_ALARM
] = { 0x459, 0x45A, 0x45B };
209 /* 0..15 voltages, 16..23 fans, 24..29 temperatures, 30..31 intrusion */
211 static const s8 NCT6775_ALARM_BITS
[] = {
212 0, 1, 2, 3, 8, 21, 20, 16, /* in0.. in7 */
213 17, -1, -1, -1, -1, -1, -1, /* in8..in14 */
215 6, 7, 11, -1, -1, /* fan1..fan5 */
216 -1, -1, -1, /* unused */
217 4, 5, 13, -1, -1, -1, /* temp1..temp6 */
218 12, -1 }; /* intrusion0, intrusion1 */
220 #define FAN_ALARM_BASE 16
221 #define TEMP_ALARM_BASE 24
222 #define INTRUSION_ALARM_BASE 30
224 static const u16 NCT6775_REG_BEEP
[NUM_REG_BEEP
] = { 0x56, 0x57, 0x453, 0x4e };
227 * 0..14 voltages, 15 global beep enable, 16..23 fans, 24..29 temperatures,
230 static const s8 NCT6775_BEEP_BITS
[] = {
231 0, 1, 2, 3, 8, 9, 10, 16, /* in0.. in7 */
232 17, -1, -1, -1, -1, -1, -1, /* in8..in14 */
233 21, /* global beep enable */
234 6, 7, 11, 28, -1, /* fan1..fan5 */
235 -1, -1, -1, /* unused */
236 4, 5, 13, -1, -1, -1, /* temp1..temp6 */
237 12, -1 }; /* intrusion0, intrusion1 */
239 #define BEEP_ENABLE_BASE 15
241 static const u8 NCT6775_REG_CR_CASEOPEN_CLR
[] = { 0xe6, 0xee };
242 static const u8 NCT6775_CR_CASEOPEN_CLR_MASK
[] = { 0x20, 0x01 };
244 /* DC or PWM output fan configuration */
245 static const u8 NCT6775_REG_PWM_MODE
[] = { 0x04, 0x04, 0x12 };
246 static const u8 NCT6775_PWM_MODE_MASK
[] = { 0x01, 0x02, 0x01 };
248 /* Advanced Fan control, some values are common for all fans */
250 static const u16 NCT6775_REG_TARGET
[] = {
251 0x101, 0x201, 0x301, 0x801, 0x901, 0xa01 };
252 static const u16 NCT6775_REG_FAN_MODE
[] = {
253 0x102, 0x202, 0x302, 0x802, 0x902, 0xa02 };
254 static const u16 NCT6775_REG_FAN_STEP_DOWN_TIME
[] = {
255 0x103, 0x203, 0x303, 0x803, 0x903, 0xa03 };
256 static const u16 NCT6775_REG_FAN_STEP_UP_TIME
[] = {
257 0x104, 0x204, 0x304, 0x804, 0x904, 0xa04 };
258 static const u16 NCT6775_REG_FAN_STOP_OUTPUT
[] = {
259 0x105, 0x205, 0x305, 0x805, 0x905, 0xa05 };
260 static const u16 NCT6775_REG_FAN_START_OUTPUT
[] = {
261 0x106, 0x206, 0x306, 0x806, 0x906, 0xa06 };
262 static const u16 NCT6775_REG_FAN_MAX_OUTPUT
[] = { 0x10a, 0x20a, 0x30a };
263 static const u16 NCT6775_REG_FAN_STEP_OUTPUT
[] = { 0x10b, 0x20b, 0x30b };
265 static const u16 NCT6775_REG_FAN_STOP_TIME
[] = {
266 0x107, 0x207, 0x307, 0x807, 0x907, 0xa07 };
267 static const u16 NCT6775_REG_PWM
[] = {
268 0x109, 0x209, 0x309, 0x809, 0x909, 0xa09 };
269 static const u16 NCT6775_REG_PWM_READ
[] = {
270 0x01, 0x03, 0x11, 0x13, 0x15, 0xa09 };
272 static const u16 NCT6775_REG_FAN
[] = { 0x630, 0x632, 0x634, 0x636, 0x638 };
273 static const u16 NCT6775_REG_FAN_MIN
[] = { 0x3b, 0x3c, 0x3d };
274 static const u16 NCT6775_REG_FAN_PULSES
[] = { 0x641, 0x642, 0x643, 0x644, 0 };
275 static const u16 NCT6775_FAN_PULSE_SHIFT
[] = { 0, 0, 0, 0, 0, 0 };
277 static const u16 NCT6775_REG_TEMP
[] = {
278 0x27, 0x150, 0x250, 0x62b, 0x62c, 0x62d };
280 static const u16 NCT6775_REG_TEMP_MON
[] = { 0x73, 0x75, 0x77 };
282 static const u16 NCT6775_REG_TEMP_CONFIG
[ARRAY_SIZE(NCT6775_REG_TEMP
)] = {
283 0, 0x152, 0x252, 0x628, 0x629, 0x62A };
284 static const u16 NCT6775_REG_TEMP_HYST
[ARRAY_SIZE(NCT6775_REG_TEMP
)] = {
285 0x3a, 0x153, 0x253, 0x673, 0x678, 0x67D };
286 static const u16 NCT6775_REG_TEMP_OVER
[ARRAY_SIZE(NCT6775_REG_TEMP
)] = {
287 0x39, 0x155, 0x255, 0x672, 0x677, 0x67C };
289 static const u16 NCT6775_REG_TEMP_SOURCE
[ARRAY_SIZE(NCT6775_REG_TEMP
)] = {
290 0x621, 0x622, 0x623, 0x624, 0x625, 0x626 };
292 static const u16 NCT6775_REG_TEMP_SEL
[] = {
293 0x100, 0x200, 0x300, 0x800, 0x900, 0xa00 };
295 static const u16 NCT6775_REG_WEIGHT_TEMP_SEL
[] = {
296 0x139, 0x239, 0x339, 0x839, 0x939, 0xa39 };
297 static const u16 NCT6775_REG_WEIGHT_TEMP_STEP
[] = {
298 0x13a, 0x23a, 0x33a, 0x83a, 0x93a, 0xa3a };
299 static const u16 NCT6775_REG_WEIGHT_TEMP_STEP_TOL
[] = {
300 0x13b, 0x23b, 0x33b, 0x83b, 0x93b, 0xa3b };
301 static const u16 NCT6775_REG_WEIGHT_DUTY_STEP
[] = {
302 0x13c, 0x23c, 0x33c, 0x83c, 0x93c, 0xa3c };
303 static const u16 NCT6775_REG_WEIGHT_TEMP_BASE
[] = {
304 0x13d, 0x23d, 0x33d, 0x83d, 0x93d, 0xa3d };
306 static const u16 NCT6775_REG_TEMP_OFFSET
[] = { 0x454, 0x455, 0x456 };
308 static const u16 NCT6775_REG_AUTO_TEMP
[] = {
309 0x121, 0x221, 0x321, 0x821, 0x921, 0xa21 };
310 static const u16 NCT6775_REG_AUTO_PWM
[] = {
311 0x127, 0x227, 0x327, 0x827, 0x927, 0xa27 };
313 #define NCT6775_AUTO_TEMP(data, nr, p) ((data)->REG_AUTO_TEMP[nr] + (p))
314 #define NCT6775_AUTO_PWM(data, nr, p) ((data)->REG_AUTO_PWM[nr] + (p))
316 static const u16 NCT6775_REG_CRITICAL_ENAB
[] = { 0x134, 0x234, 0x334 };
318 static const u16 NCT6775_REG_CRITICAL_TEMP
[] = {
319 0x135, 0x235, 0x335, 0x835, 0x935, 0xa35 };
320 static const u16 NCT6775_REG_CRITICAL_TEMP_TOLERANCE
[] = {
321 0x138, 0x238, 0x338, 0x838, 0x938, 0xa38 };
323 static const char *const nct6775_temp_label
[] = {
337 "PCH_CHIP_CPU_MAX_TEMP",
347 static const u16 NCT6775_REG_TEMP_ALTERNATE
[ARRAY_SIZE(nct6775_temp_label
) - 1]
348 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x661, 0x662, 0x664 };
350 static const u16 NCT6775_REG_TEMP_CRIT
[ARRAY_SIZE(nct6775_temp_label
) - 1]
351 = { 0, 0, 0, 0, 0xa00, 0xa01, 0xa02, 0xa03, 0xa04, 0xa05, 0xa06,
354 /* NCT6776 specific data */
356 static const s8 NCT6776_ALARM_BITS
[] = {
357 0, 1, 2, 3, 8, 21, 20, 16, /* in0.. in7 */
358 17, -1, -1, -1, -1, -1, -1, /* in8..in14 */
360 6, 7, 11, 10, 23, /* fan1..fan5 */
361 -1, -1, -1, /* unused */
362 4, 5, 13, -1, -1, -1, /* temp1..temp6 */
363 12, 9 }; /* intrusion0, intrusion1 */
365 static const u16 NCT6776_REG_BEEP
[NUM_REG_BEEP
] = { 0xb2, 0xb3, 0xb4, 0xb5 };
367 static const s8 NCT6776_BEEP_BITS
[] = {
368 0, 1, 2, 3, 4, 5, 6, 7, /* in0.. in7 */
369 8, -1, -1, -1, -1, -1, -1, /* in8..in14 */
370 24, /* global beep enable */
371 25, 26, 27, 28, 29, /* fan1..fan5 */
372 -1, -1, -1, /* unused */
373 16, 17, 18, 19, 20, 21, /* temp1..temp6 */
374 30, 31 }; /* intrusion0, intrusion1 */
376 static const u16 NCT6776_REG_TOLERANCE_H
[] = {
377 0x10c, 0x20c, 0x30c, 0x80c, 0x90c, 0xa0c };
379 static const u8 NCT6776_REG_PWM_MODE
[] = { 0x04, 0, 0, 0, 0, 0 };
380 static const u8 NCT6776_PWM_MODE_MASK
[] = { 0x01, 0, 0, 0, 0, 0 };
382 static const u16 NCT6776_REG_FAN_MIN
[] = { 0x63a, 0x63c, 0x63e, 0x640, 0x642 };
383 static const u16 NCT6776_REG_FAN_PULSES
[] = { 0x644, 0x645, 0x646, 0, 0 };
385 static const u16 NCT6776_REG_WEIGHT_DUTY_BASE
[] = {
386 0x13e, 0x23e, 0x33e, 0x83e, 0x93e, 0xa3e };
388 static const u16 NCT6776_REG_TEMP_CONFIG
[ARRAY_SIZE(NCT6775_REG_TEMP
)] = {
389 0x18, 0x152, 0x252, 0x628, 0x629, 0x62A };
391 static const char *const nct6776_temp_label
[] = {
406 "PCH_CHIP_CPU_MAX_TEMP",
417 static const u16 NCT6776_REG_TEMP_ALTERNATE
[ARRAY_SIZE(nct6776_temp_label
) - 1]
418 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x401, 0x402, 0x404 };
420 static const u16 NCT6776_REG_TEMP_CRIT
[ARRAY_SIZE(nct6776_temp_label
) - 1]
421 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x709, 0x70a };
423 /* NCT6779 specific data */
425 static const u16 NCT6779_REG_IN
[] = {
426 0x480, 0x481, 0x482, 0x483, 0x484, 0x485, 0x486, 0x487,
427 0x488, 0x489, 0x48a, 0x48b, 0x48c, 0x48d, 0x48e };
429 static const u16 NCT6779_REG_ALARM
[NUM_REG_ALARM
] = {
430 0x459, 0x45A, 0x45B, 0x568 };
432 static const s8 NCT6779_ALARM_BITS
[] = {
433 0, 1, 2, 3, 8, 21, 20, 16, /* in0.. in7 */
434 17, 24, 25, 26, 27, 28, 29, /* in8..in14 */
436 6, 7, 11, 10, 23, /* fan1..fan5 */
437 -1, -1, -1, /* unused */
438 4, 5, 13, -1, -1, -1, /* temp1..temp6 */
439 12, 9 }; /* intrusion0, intrusion1 */
441 static const s8 NCT6779_BEEP_BITS
[] = {
442 0, 1, 2, 3, 4, 5, 6, 7, /* in0.. in7 */
443 8, 9, 10, 11, 12, 13, 14, /* in8..in14 */
444 24, /* global beep enable */
445 25, 26, 27, 28, 29, /* fan1..fan5 */
446 -1, -1, -1, /* unused */
447 16, 17, -1, -1, -1, -1, /* temp1..temp6 */
448 30, 31 }; /* intrusion0, intrusion1 */
450 static const u16 NCT6779_REG_FAN
[] = {
451 0x4b0, 0x4b2, 0x4b4, 0x4b6, 0x4b8, 0x4ba };
452 static const u16 NCT6779_REG_FAN_PULSES
[] = {
453 0x644, 0x645, 0x646, 0x647, 0x648, 0x649 };
455 static const u16 NCT6779_REG_CRITICAL_PWM_ENABLE
[] = {
456 0x136, 0x236, 0x336, 0x836, 0x936, 0xa36 };
457 #define NCT6779_CRITICAL_PWM_ENABLE_MASK 0x01
458 static const u16 NCT6779_REG_CRITICAL_PWM
[] = {
459 0x137, 0x237, 0x337, 0x837, 0x937, 0xa37 };
461 static const u16 NCT6779_REG_TEMP
[] = { 0x27, 0x150 };
462 static const u16 NCT6779_REG_TEMP_MON
[] = { 0x73, 0x75, 0x77, 0x79, 0x7b };
463 static const u16 NCT6779_REG_TEMP_CONFIG
[ARRAY_SIZE(NCT6779_REG_TEMP
)] = {
465 static const u16 NCT6779_REG_TEMP_HYST
[ARRAY_SIZE(NCT6779_REG_TEMP
)] = {
467 static const u16 NCT6779_REG_TEMP_OVER
[ARRAY_SIZE(NCT6779_REG_TEMP
)] = {
470 static const u16 NCT6779_REG_TEMP_OFFSET
[] = {
471 0x454, 0x455, 0x456, 0x44a, 0x44b, 0x44c };
473 static const char *const nct6779_temp_label
[] = {
492 "PCH_CHIP_CPU_MAX_TEMP",
503 static const u16 NCT6779_REG_TEMP_ALTERNATE
[ARRAY_SIZE(nct6779_temp_label
) - 1]
504 = { 0x490, 0x491, 0x492, 0x493, 0x494, 0x495, 0, 0,
505 0, 0, 0, 0, 0, 0, 0, 0,
506 0, 0x400, 0x401, 0x402, 0x404, 0x405, 0x406, 0x407,
509 static const u16 NCT6779_REG_TEMP_CRIT
[ARRAY_SIZE(nct6779_temp_label
) - 1]
510 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x709, 0x70a };
512 /* NCT6791 specific data */
514 #define NCT6791_REG_HM_IO_SPACE_LOCK_ENABLE 0x28
516 static const u16 NCT6791_REG_WEIGHT_TEMP_SEL
[6] = { 0, 0x239 };
517 static const u16 NCT6791_REG_WEIGHT_TEMP_STEP
[6] = { 0, 0x23a };
518 static const u16 NCT6791_REG_WEIGHT_TEMP_STEP_TOL
[6] = { 0, 0x23b };
519 static const u16 NCT6791_REG_WEIGHT_DUTY_STEP
[6] = { 0, 0x23c };
520 static const u16 NCT6791_REG_WEIGHT_TEMP_BASE
[6] = { 0, 0x23d };
521 static const u16 NCT6791_REG_WEIGHT_DUTY_BASE
[6] = { 0, 0x23e };
523 static const u16 NCT6791_REG_ALARM
[NUM_REG_ALARM
] = {
524 0x459, 0x45A, 0x45B, 0x568, 0x45D };
526 static const s8 NCT6791_ALARM_BITS
[] = {
527 0, 1, 2, 3, 8, 21, 20, 16, /* in0.. in7 */
528 17, 24, 25, 26, 27, 28, 29, /* in8..in14 */
530 6, 7, 11, 10, 23, 33, /* fan1..fan6 */
532 4, 5, 13, -1, -1, -1, /* temp1..temp6 */
533 12, 9 }; /* intrusion0, intrusion1 */
535 /* NCT6792 specific data */
537 static const u16 NCT6792_REG_TEMP_MON
[] = {
538 0x73, 0x75, 0x77, 0x79, 0x7b, 0x7d };
539 static const u16 NCT6792_REG_BEEP
[NUM_REG_BEEP
] = {
540 0xb2, 0xb3, 0xb4, 0xb5, 0xbf };
542 /* NCT6102D/NCT6106D specific data */
544 #define NCT6106_REG_VBAT 0x318
545 #define NCT6106_REG_DIODE 0x319
546 #define NCT6106_DIODE_MASK 0x01
548 static const u16 NCT6106_REG_IN_MAX
[] = {
549 0x90, 0x92, 0x94, 0x96, 0x98, 0x9a, 0x9e, 0xa0, 0xa2 };
550 static const u16 NCT6106_REG_IN_MIN
[] = {
551 0x91, 0x93, 0x95, 0x97, 0x99, 0x9b, 0x9f, 0xa1, 0xa3 };
552 static const u16 NCT6106_REG_IN
[] = {
553 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x07, 0x08, 0x09 };
555 static const u16 NCT6106_REG_TEMP
[] = { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15 };
556 static const u16 NCT6106_REG_TEMP_MON
[] = { 0x18, 0x19, 0x1a };
557 static const u16 NCT6106_REG_TEMP_HYST
[] = {
558 0xc3, 0xc7, 0xcb, 0xcf, 0xd3, 0xd7 };
559 static const u16 NCT6106_REG_TEMP_OVER
[] = {
560 0xc2, 0xc6, 0xca, 0xce, 0xd2, 0xd6 };
561 static const u16 NCT6106_REG_TEMP_CRIT_L
[] = {
562 0xc0, 0xc4, 0xc8, 0xcc, 0xd0, 0xd4 };
563 static const u16 NCT6106_REG_TEMP_CRIT_H
[] = {
564 0xc1, 0xc5, 0xc9, 0xcf, 0xd1, 0xd5 };
565 static const u16 NCT6106_REG_TEMP_OFFSET
[] = { 0x311, 0x312, 0x313 };
566 static const u16 NCT6106_REG_TEMP_CONFIG
[] = {
567 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc };
569 static const u16 NCT6106_REG_FAN
[] = { 0x20, 0x22, 0x24 };
570 static const u16 NCT6106_REG_FAN_MIN
[] = { 0xe0, 0xe2, 0xe4 };
571 static const u16 NCT6106_REG_FAN_PULSES
[] = { 0xf6, 0xf6, 0xf6, 0, 0 };
572 static const u16 NCT6106_FAN_PULSE_SHIFT
[] = { 0, 2, 4, 0, 0 };
574 static const u8 NCT6106_REG_PWM_MODE
[] = { 0xf3, 0xf3, 0xf3 };
575 static const u8 NCT6106_PWM_MODE_MASK
[] = { 0x01, 0x02, 0x04 };
576 static const u16 NCT6106_REG_PWM
[] = { 0x119, 0x129, 0x139 };
577 static const u16 NCT6106_REG_PWM_READ
[] = { 0x4a, 0x4b, 0x4c };
578 static const u16 NCT6106_REG_FAN_MODE
[] = { 0x113, 0x123, 0x133 };
579 static const u16 NCT6106_REG_TEMP_SEL
[] = { 0x110, 0x120, 0x130 };
580 static const u16 NCT6106_REG_TEMP_SOURCE
[] = {
581 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5 };
583 static const u16 NCT6106_REG_CRITICAL_TEMP
[] = { 0x11a, 0x12a, 0x13a };
584 static const u16 NCT6106_REG_CRITICAL_TEMP_TOLERANCE
[] = {
585 0x11b, 0x12b, 0x13b };
587 static const u16 NCT6106_REG_CRITICAL_PWM_ENABLE
[] = { 0x11c, 0x12c, 0x13c };
588 #define NCT6106_CRITICAL_PWM_ENABLE_MASK 0x10
589 static const u16 NCT6106_REG_CRITICAL_PWM
[] = { 0x11d, 0x12d, 0x13d };
591 static const u16 NCT6106_REG_FAN_STEP_UP_TIME
[] = { 0x114, 0x124, 0x134 };
592 static const u16 NCT6106_REG_FAN_STEP_DOWN_TIME
[] = { 0x115, 0x125, 0x135 };
593 static const u16 NCT6106_REG_FAN_STOP_OUTPUT
[] = { 0x116, 0x126, 0x136 };
594 static const u16 NCT6106_REG_FAN_START_OUTPUT
[] = { 0x117, 0x127, 0x137 };
595 static const u16 NCT6106_REG_FAN_STOP_TIME
[] = { 0x118, 0x128, 0x138 };
596 static const u16 NCT6106_REG_TOLERANCE_H
[] = { 0x112, 0x122, 0x132 };
598 static const u16 NCT6106_REG_TARGET
[] = { 0x111, 0x121, 0x131 };
600 static const u16 NCT6106_REG_WEIGHT_TEMP_SEL
[] = { 0x168, 0x178, 0x188 };
601 static const u16 NCT6106_REG_WEIGHT_TEMP_STEP
[] = { 0x169, 0x179, 0x189 };
602 static const u16 NCT6106_REG_WEIGHT_TEMP_STEP_TOL
[] = { 0x16a, 0x17a, 0x18a };
603 static const u16 NCT6106_REG_WEIGHT_DUTY_STEP
[] = { 0x16b, 0x17b, 0x17c };
604 static const u16 NCT6106_REG_WEIGHT_TEMP_BASE
[] = { 0x16c, 0x17c, 0x18c };
605 static const u16 NCT6106_REG_WEIGHT_DUTY_BASE
[] = { 0x16d, 0x17d, 0x18d };
607 static const u16 NCT6106_REG_AUTO_TEMP
[] = { 0x160, 0x170, 0x180 };
608 static const u16 NCT6106_REG_AUTO_PWM
[] = { 0x164, 0x174, 0x184 };
610 static const u16 NCT6106_REG_ALARM
[NUM_REG_ALARM
] = {
611 0x77, 0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d };
613 static const s8 NCT6106_ALARM_BITS
[] = {
614 0, 1, 2, 3, 4, 5, 7, 8, /* in0.. in7 */
615 9, -1, -1, -1, -1, -1, -1, /* in8..in14 */
617 32, 33, 34, -1, -1, /* fan1..fan5 */
618 -1, -1, -1, /* unused */
619 16, 17, 18, 19, 20, 21, /* temp1..temp6 */
620 48, -1 /* intrusion0, intrusion1 */
623 static const u16 NCT6106_REG_BEEP
[NUM_REG_BEEP
] = {
624 0x3c0, 0x3c1, 0x3c2, 0x3c3, 0x3c4 };
626 static const s8 NCT6106_BEEP_BITS
[] = {
627 0, 1, 2, 3, 4, 5, 7, 8, /* in0.. in7 */
628 9, 10, 11, 12, -1, -1, -1, /* in8..in14 */
629 32, /* global beep enable */
630 24, 25, 26, 27, 28, /* fan1..fan5 */
631 -1, -1, -1, /* unused */
632 16, 17, 18, 19, 20, 21, /* temp1..temp6 */
633 34, -1 /* intrusion0, intrusion1 */
636 static const u16 NCT6106_REG_TEMP_ALTERNATE
[ARRAY_SIZE(nct6776_temp_label
) - 1]
637 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x51, 0x52, 0x54 };
639 static const u16 NCT6106_REG_TEMP_CRIT
[ARRAY_SIZE(nct6776_temp_label
) - 1]
640 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x204, 0x205 };
642 static enum pwm_enable
reg_to_pwm_enable(int pwm
, int mode
)
644 if (mode
== 0 && pwm
== 255)
649 static int pwm_enable_to_reg(enum pwm_enable mode
)
660 /* 1 is DC mode, output in ms */
661 static unsigned int step_time_from_reg(u8 reg
, u8 mode
)
663 return mode
? 400 * reg
: 100 * reg
;
666 static u8
step_time_to_reg(unsigned int msec
, u8 mode
)
668 return clamp_val((mode
? (msec
+ 200) / 400 :
669 (msec
+ 50) / 100), 1, 255);
672 static unsigned int fan_from_reg8(u16 reg
, unsigned int divreg
)
674 if (reg
== 0 || reg
== 255)
676 return 1350000U / (reg
<< divreg
);
679 static unsigned int fan_from_reg13(u16 reg
, unsigned int divreg
)
681 if ((reg
& 0xff1f) == 0xff1f)
684 reg
= (reg
& 0x1f) | ((reg
& 0xff00) >> 3);
689 return 1350000U / reg
;
692 static unsigned int fan_from_reg16(u16 reg
, unsigned int divreg
)
694 if (reg
== 0 || reg
== 0xffff)
698 * Even though the registers are 16 bit wide, the fan divisor
701 return 1350000U / (reg
<< divreg
);
704 static u16
fan_to_reg(u32 fan
, unsigned int divreg
)
709 return (1350000U / fan
) >> divreg
;
712 static inline unsigned int
719 * Some of the voltage inputs have internal scaling, the tables below
720 * contain 8 (the ADC LSB in mV) * scaling factor * 100
722 static const u16 scale_in
[15] = {
723 800, 800, 1600, 1600, 800, 800, 800, 1600, 1600, 800, 800, 800, 800,
727 static inline long in_from_reg(u8 reg
, u8 nr
)
729 return DIV_ROUND_CLOSEST(reg
* scale_in
[nr
], 100);
732 static inline u8
in_to_reg(u32 val
, u8 nr
)
734 return clamp_val(DIV_ROUND_CLOSEST(val
* 100, scale_in
[nr
]), 0, 255);
738 * Data structures and manipulation thereof
741 struct nct6775_data
{
742 int addr
; /* IO base of hw monitor block */
743 int sioreg
; /* SIO register address */
747 const struct attribute_group
*groups
[6];
749 u16 reg_temp
[5][NUM_TEMP
]; /* 0=temp, 1=temp_over, 2=temp_hyst,
750 * 3=temp_crit, 4=temp_lcrit
752 u8 temp_src
[NUM_TEMP
];
753 u16 reg_temp_config
[NUM_TEMP
];
754 const char * const *temp_label
;
762 const s8
*ALARM_BITS
;
766 const u16
*REG_IN_MINMAX
[2];
768 const u16
*REG_TARGET
;
770 const u16
*REG_FAN_MODE
;
771 const u16
*REG_FAN_MIN
;
772 const u16
*REG_FAN_PULSES
;
773 const u16
*FAN_PULSE_SHIFT
;
774 const u16
*REG_FAN_TIME
[3];
776 const u16
*REG_TOLERANCE_H
;
778 const u8
*REG_PWM_MODE
;
779 const u8
*PWM_MODE_MASK
;
781 const u16
*REG_PWM
[7]; /* [0]=pwm, [1]=pwm_start, [2]=pwm_floor,
782 * [3]=pwm_max, [4]=pwm_step,
783 * [5]=weight_duty_step, [6]=weight_duty_base
785 const u16
*REG_PWM_READ
;
787 const u16
*REG_CRITICAL_PWM_ENABLE
;
788 u8 CRITICAL_PWM_ENABLE_MASK
;
789 const u16
*REG_CRITICAL_PWM
;
791 const u16
*REG_AUTO_TEMP
;
792 const u16
*REG_AUTO_PWM
;
794 const u16
*REG_CRITICAL_TEMP
;
795 const u16
*REG_CRITICAL_TEMP_TOLERANCE
;
797 const u16
*REG_TEMP_SOURCE
; /* temp register sources */
798 const u16
*REG_TEMP_SEL
;
799 const u16
*REG_WEIGHT_TEMP_SEL
;
800 const u16
*REG_WEIGHT_TEMP
[3]; /* 0=base, 1=tolerance, 2=step */
802 const u16
*REG_TEMP_OFFSET
;
804 const u16
*REG_ALARM
;
807 unsigned int (*fan_from_reg
)(u16 reg
, unsigned int divreg
);
808 unsigned int (*fan_from_reg_min
)(u16 reg
, unsigned int divreg
);
810 struct mutex update_lock
;
811 bool valid
; /* true if following fields are valid */
812 unsigned long last_updated
; /* In jiffies */
814 /* Register values */
815 u8 bank
; /* current register bank */
816 u8 in_num
; /* number of in inputs we have */
817 u8 in
[15][3]; /* [0]=in, [1]=in_max, [2]=in_min */
818 unsigned int rpm
[NUM_FAN
];
819 u16 fan_min
[NUM_FAN
];
820 u8 fan_pulses
[NUM_FAN
];
823 u8 has_fan
; /* some fan inputs can be disabled */
824 u8 has_fan_min
; /* some fans don't have min register */
827 u8 num_temp_alarms
; /* 2, 3, or 6 */
828 u8 num_temp_beeps
; /* 2, 3, or 6 */
829 u8 temp_fixed_num
; /* 3 or 6 */
830 u8 temp_type
[NUM_TEMP_FIXED
];
831 s8 temp_offset
[NUM_TEMP_FIXED
];
832 s16 temp
[5][NUM_TEMP
]; /* 0=temp, 1=temp_over, 2=temp_hyst,
833 * 3=temp_crit, 4=temp_lcrit */
837 u8 pwm_num
; /* number of pwm */
838 u8 pwm_mode
[NUM_FAN
]; /* 1->DC variable voltage,
839 * 0->PWM variable duty cycle
841 enum pwm_enable pwm_enable
[NUM_FAN
];
844 * 2->thermal cruise mode (also called SmartFan I)
845 * 3->fan speed cruise mode
847 * 5->enhanced variable thermal cruise (SmartFan IV)
849 u8 pwm
[7][NUM_FAN
]; /* [0]=pwm, [1]=pwm_start, [2]=pwm_floor,
850 * [3]=pwm_max, [4]=pwm_step,
851 * [5]=weight_duty_step, [6]=weight_duty_base
854 u8 target_temp
[NUM_FAN
];
856 u32 target_speed
[NUM_FAN
];
857 u32 target_speed_tolerance
[NUM_FAN
];
858 u8 speed_tolerance_limit
;
860 u8 temp_tolerance
[2][NUM_FAN
];
863 u8 fan_time
[3][NUM_FAN
]; /* 0 = stop_time, 1 = step_up, 2 = step_down */
865 /* Automatic fan speed control registers */
867 u8 auto_pwm
[NUM_FAN
][7];
868 u8 auto_temp
[NUM_FAN
][7];
869 u8 pwm_temp_sel
[NUM_FAN
];
870 u8 pwm_weight_temp_sel
[NUM_FAN
];
871 u8 weight_temp
[3][NUM_FAN
]; /* 0->temp_step, 1->temp_step_tol,
884 /* Remember extra register values over suspend/resume */
890 struct nct6775_sio_data
{
895 struct sensor_device_template
{
896 struct device_attribute dev_attr
;
904 bool s2
; /* true if both index and nr are used */
907 struct sensor_device_attr_u
{
909 struct sensor_device_attribute a1
;
910 struct sensor_device_attribute_2 a2
;
915 #define __TEMPLATE_ATTR(_template, _mode, _show, _store) { \
916 .attr = {.name = _template, .mode = _mode }, \
921 #define SENSOR_DEVICE_TEMPLATE(_template, _mode, _show, _store, _index) \
922 { .dev_attr = __TEMPLATE_ATTR(_template, _mode, _show, _store), \
926 #define SENSOR_DEVICE_TEMPLATE_2(_template, _mode, _show, _store, \
928 { .dev_attr = __TEMPLATE_ATTR(_template, _mode, _show, _store), \
929 .u.s.index = _index, \
933 #define SENSOR_TEMPLATE(_name, _template, _mode, _show, _store, _index) \
934 static struct sensor_device_template sensor_dev_template_##_name \
935 = SENSOR_DEVICE_TEMPLATE(_template, _mode, _show, _store, \
938 #define SENSOR_TEMPLATE_2(_name, _template, _mode, _show, _store, \
940 static struct sensor_device_template sensor_dev_template_##_name \
941 = SENSOR_DEVICE_TEMPLATE_2(_template, _mode, _show, _store, \
944 struct sensor_template_group
{
945 struct sensor_device_template
**templates
;
946 umode_t (*is_visible
)(struct kobject
*, struct attribute
*, int);
950 static struct attribute_group
*
951 nct6775_create_attr_group(struct device
*dev
, struct sensor_template_group
*tg
,
954 struct attribute_group
*group
;
955 struct sensor_device_attr_u
*su
;
956 struct sensor_device_attribute
*a
;
957 struct sensor_device_attribute_2
*a2
;
958 struct attribute
**attrs
;
959 struct sensor_device_template
**t
;
963 return ERR_PTR(-EINVAL
);
966 for (count
= 0; *t
; t
++, count
++)
970 return ERR_PTR(-EINVAL
);
972 group
= devm_kzalloc(dev
, sizeof(*group
), GFP_KERNEL
);
974 return ERR_PTR(-ENOMEM
);
976 attrs
= devm_kzalloc(dev
, sizeof(*attrs
) * (repeat
* count
+ 1),
979 return ERR_PTR(-ENOMEM
);
981 su
= devm_kzalloc(dev
, sizeof(*su
) * repeat
* count
,
984 return ERR_PTR(-ENOMEM
);
986 group
->attrs
= attrs
;
987 group
->is_visible
= tg
->is_visible
;
989 for (i
= 0; i
< repeat
; i
++) {
992 snprintf(su
->name
, sizeof(su
->name
),
993 (*t
)->dev_attr
.attr
.name
, tg
->base
+ i
);
996 a2
->dev_attr
.attr
.name
= su
->name
;
997 a2
->nr
= (*t
)->u
.s
.nr
+ i
;
998 a2
->index
= (*t
)->u
.s
.index
;
999 a2
->dev_attr
.attr
.mode
=
1000 (*t
)->dev_attr
.attr
.mode
;
1001 a2
->dev_attr
.show
= (*t
)->dev_attr
.show
;
1002 a2
->dev_attr
.store
= (*t
)->dev_attr
.store
;
1003 *attrs
= &a2
->dev_attr
.attr
;
1006 a
->dev_attr
.attr
.name
= su
->name
;
1007 a
->index
= (*t
)->u
.index
+ i
;
1008 a
->dev_attr
.attr
.mode
=
1009 (*t
)->dev_attr
.attr
.mode
;
1010 a
->dev_attr
.show
= (*t
)->dev_attr
.show
;
1011 a
->dev_attr
.store
= (*t
)->dev_attr
.store
;
1012 *attrs
= &a
->dev_attr
.attr
;
1023 static bool is_word_sized(struct nct6775_data
*data
, u16 reg
)
1025 switch (data
->kind
) {
1027 return reg
== 0x20 || reg
== 0x22 || reg
== 0x24 ||
1028 reg
== 0xe0 || reg
== 0xe2 || reg
== 0xe4 ||
1029 reg
== 0x111 || reg
== 0x121 || reg
== 0x131;
1031 return (((reg
& 0xff00) == 0x100 ||
1032 (reg
& 0xff00) == 0x200) &&
1033 ((reg
& 0x00ff) == 0x50 ||
1034 (reg
& 0x00ff) == 0x53 ||
1035 (reg
& 0x00ff) == 0x55)) ||
1036 (reg
& 0xfff0) == 0x630 ||
1037 reg
== 0x640 || reg
== 0x642 ||
1039 ((reg
& 0xfff0) == 0x650 && (reg
& 0x000f) >= 0x06) ||
1040 reg
== 0x73 || reg
== 0x75 || reg
== 0x77;
1042 return (((reg
& 0xff00) == 0x100 ||
1043 (reg
& 0xff00) == 0x200) &&
1044 ((reg
& 0x00ff) == 0x50 ||
1045 (reg
& 0x00ff) == 0x53 ||
1046 (reg
& 0x00ff) == 0x55)) ||
1047 (reg
& 0xfff0) == 0x630 ||
1049 reg
== 0x640 || reg
== 0x642 ||
1050 ((reg
& 0xfff0) == 0x650 && (reg
& 0x000f) >= 0x06) ||
1051 reg
== 0x73 || reg
== 0x75 || reg
== 0x77;
1055 return reg
== 0x150 || reg
== 0x153 || reg
== 0x155 ||
1056 ((reg
& 0xfff0) == 0x4b0 && (reg
& 0x000f) < 0x0b) ||
1058 reg
== 0x63a || reg
== 0x63c || reg
== 0x63e ||
1059 reg
== 0x640 || reg
== 0x642 ||
1060 reg
== 0x73 || reg
== 0x75 || reg
== 0x77 || reg
== 0x79 ||
1061 reg
== 0x7b || reg
== 0x7d;
1067 * On older chips, only registers 0x50-0x5f are banked.
1068 * On more recent chips, all registers are banked.
1069 * Assume that is the case and set the bank number for each access.
1070 * Cache the bank number so it only needs to be set if it changes.
1072 static inline void nct6775_set_bank(struct nct6775_data
*data
, u16 reg
)
1076 if (data
->bank
!= bank
) {
1077 outb_p(NCT6775_REG_BANK
, data
->addr
+ ADDR_REG_OFFSET
);
1078 outb_p(bank
, data
->addr
+ DATA_REG_OFFSET
);
1083 static u16
nct6775_read_value(struct nct6775_data
*data
, u16 reg
)
1085 int res
, word_sized
= is_word_sized(data
, reg
);
1087 nct6775_set_bank(data
, reg
);
1088 outb_p(reg
& 0xff, data
->addr
+ ADDR_REG_OFFSET
);
1089 res
= inb_p(data
->addr
+ DATA_REG_OFFSET
);
1091 outb_p((reg
& 0xff) + 1,
1092 data
->addr
+ ADDR_REG_OFFSET
);
1093 res
= (res
<< 8) + inb_p(data
->addr
+ DATA_REG_OFFSET
);
1098 static int nct6775_write_value(struct nct6775_data
*data
, u16 reg
, u16 value
)
1100 int word_sized
= is_word_sized(data
, reg
);
1102 nct6775_set_bank(data
, reg
);
1103 outb_p(reg
& 0xff, data
->addr
+ ADDR_REG_OFFSET
);
1105 outb_p(value
>> 8, data
->addr
+ DATA_REG_OFFSET
);
1106 outb_p((reg
& 0xff) + 1,
1107 data
->addr
+ ADDR_REG_OFFSET
);
1109 outb_p(value
& 0xff, data
->addr
+ DATA_REG_OFFSET
);
1113 /* We left-align 8-bit temperature values to make the code simpler */
1114 static u16
nct6775_read_temp(struct nct6775_data
*data
, u16 reg
)
1118 res
= nct6775_read_value(data
, reg
);
1119 if (!is_word_sized(data
, reg
))
1125 static int nct6775_write_temp(struct nct6775_data
*data
, u16 reg
, u16 value
)
1127 if (!is_word_sized(data
, reg
))
1129 return nct6775_write_value(data
, reg
, value
);
1132 /* This function assumes that the caller holds data->update_lock */
1133 static void nct6775_write_fan_div(struct nct6775_data
*data
, int nr
)
1139 reg
= (nct6775_read_value(data
, NCT6775_REG_FANDIV1
) & 0x70)
1140 | (data
->fan_div
[0] & 0x7);
1141 nct6775_write_value(data
, NCT6775_REG_FANDIV1
, reg
);
1144 reg
= (nct6775_read_value(data
, NCT6775_REG_FANDIV1
) & 0x7)
1145 | ((data
->fan_div
[1] << 4) & 0x70);
1146 nct6775_write_value(data
, NCT6775_REG_FANDIV1
, reg
);
1149 reg
= (nct6775_read_value(data
, NCT6775_REG_FANDIV2
) & 0x70)
1150 | (data
->fan_div
[2] & 0x7);
1151 nct6775_write_value(data
, NCT6775_REG_FANDIV2
, reg
);
1154 reg
= (nct6775_read_value(data
, NCT6775_REG_FANDIV2
) & 0x7)
1155 | ((data
->fan_div
[3] << 4) & 0x70);
1156 nct6775_write_value(data
, NCT6775_REG_FANDIV2
, reg
);
1161 static void nct6775_write_fan_div_common(struct nct6775_data
*data
, int nr
)
1163 if (data
->kind
== nct6775
)
1164 nct6775_write_fan_div(data
, nr
);
1167 static void nct6775_update_fan_div(struct nct6775_data
*data
)
1171 i
= nct6775_read_value(data
, NCT6775_REG_FANDIV1
);
1172 data
->fan_div
[0] = i
& 0x7;
1173 data
->fan_div
[1] = (i
& 0x70) >> 4;
1174 i
= nct6775_read_value(data
, NCT6775_REG_FANDIV2
);
1175 data
->fan_div
[2] = i
& 0x7;
1176 if (data
->has_fan
& (1 << 3))
1177 data
->fan_div
[3] = (i
& 0x70) >> 4;
1180 static void nct6775_update_fan_div_common(struct nct6775_data
*data
)
1182 if (data
->kind
== nct6775
)
1183 nct6775_update_fan_div(data
);
1186 static void nct6775_init_fan_div(struct nct6775_data
*data
)
1190 nct6775_update_fan_div_common(data
);
1192 * For all fans, start with highest divider value if the divider
1193 * register is not initialized. This ensures that we get a
1194 * reading from the fan count register, even if it is not optimal.
1195 * We'll compute a better divider later on.
1197 for (i
= 0; i
< ARRAY_SIZE(data
->fan_div
); i
++) {
1198 if (!(data
->has_fan
& (1 << i
)))
1200 if (data
->fan_div
[i
] == 0) {
1201 data
->fan_div
[i
] = 7;
1202 nct6775_write_fan_div_common(data
, i
);
1207 static void nct6775_init_fan_common(struct device
*dev
,
1208 struct nct6775_data
*data
)
1213 if (data
->has_fan_div
)
1214 nct6775_init_fan_div(data
);
1217 * If fan_min is not set (0), set it to 0xff to disable it. This
1218 * prevents the unnecessary warning when fanX_min is reported as 0.
1220 for (i
= 0; i
< ARRAY_SIZE(data
->fan_min
); i
++) {
1221 if (data
->has_fan_min
& (1 << i
)) {
1222 reg
= nct6775_read_value(data
, data
->REG_FAN_MIN
[i
]);
1224 nct6775_write_value(data
, data
->REG_FAN_MIN
[i
],
1225 data
->has_fan_div
? 0xff
1231 static void nct6775_select_fan_div(struct device
*dev
,
1232 struct nct6775_data
*data
, int nr
, u16 reg
)
1234 u8 fan_div
= data
->fan_div
[nr
];
1237 if (!data
->has_fan_div
)
1241 * If we failed to measure the fan speed, or the reported value is not
1242 * in the optimal range, and the clock divider can be modified,
1243 * let's try that for next time.
1245 if (reg
== 0x00 && fan_div
< 0x07)
1247 else if (reg
!= 0x00 && reg
< 0x30 && fan_div
> 0)
1250 if (fan_div
!= data
->fan_div
[nr
]) {
1251 dev_dbg(dev
, "Modifying fan%d clock divider from %u to %u\n",
1252 nr
+ 1, div_from_reg(data
->fan_div
[nr
]),
1253 div_from_reg(fan_div
));
1255 /* Preserve min limit if possible */
1256 if (data
->has_fan_min
& (1 << nr
)) {
1257 fan_min
= data
->fan_min
[nr
];
1258 if (fan_div
> data
->fan_div
[nr
]) {
1259 if (fan_min
!= 255 && fan_min
> 1)
1262 if (fan_min
!= 255) {
1268 if (fan_min
!= data
->fan_min
[nr
]) {
1269 data
->fan_min
[nr
] = fan_min
;
1270 nct6775_write_value(data
, data
->REG_FAN_MIN
[nr
],
1274 data
->fan_div
[nr
] = fan_div
;
1275 nct6775_write_fan_div_common(data
, nr
);
1279 static void nct6775_update_pwm(struct device
*dev
)
1281 struct nct6775_data
*data
= dev_get_drvdata(dev
);
1283 int fanmodecfg
, reg
;
1286 for (i
= 0; i
< data
->pwm_num
; i
++) {
1287 if (!(data
->has_pwm
& (1 << i
)))
1290 duty_is_dc
= data
->REG_PWM_MODE
[i
] &&
1291 (nct6775_read_value(data
, data
->REG_PWM_MODE
[i
])
1292 & data
->PWM_MODE_MASK
[i
]);
1293 data
->pwm_mode
[i
] = duty_is_dc
;
1295 fanmodecfg
= nct6775_read_value(data
, data
->REG_FAN_MODE
[i
]);
1296 for (j
= 0; j
< ARRAY_SIZE(data
->REG_PWM
); j
++) {
1297 if (data
->REG_PWM
[j
] && data
->REG_PWM
[j
][i
]) {
1299 = nct6775_read_value(data
,
1300 data
->REG_PWM
[j
][i
]);
1304 data
->pwm_enable
[i
] = reg_to_pwm_enable(data
->pwm
[0][i
],
1305 (fanmodecfg
>> 4) & 7);
1307 if (!data
->temp_tolerance
[0][i
] ||
1308 data
->pwm_enable
[i
] != speed_cruise
)
1309 data
->temp_tolerance
[0][i
] = fanmodecfg
& 0x0f;
1310 if (!data
->target_speed_tolerance
[i
] ||
1311 data
->pwm_enable
[i
] == speed_cruise
) {
1312 u8 t
= fanmodecfg
& 0x0f;
1314 if (data
->REG_TOLERANCE_H
) {
1315 t
|= (nct6775_read_value(data
,
1316 data
->REG_TOLERANCE_H
[i
]) & 0x70) >> 1;
1318 data
->target_speed_tolerance
[i
] = t
;
1321 data
->temp_tolerance
[1][i
] =
1322 nct6775_read_value(data
,
1323 data
->REG_CRITICAL_TEMP_TOLERANCE
[i
]);
1325 reg
= nct6775_read_value(data
, data
->REG_TEMP_SEL
[i
]);
1326 data
->pwm_temp_sel
[i
] = reg
& 0x1f;
1327 /* If fan can stop, report floor as 0 */
1329 data
->pwm
[2][i
] = 0;
1331 if (!data
->REG_WEIGHT_TEMP_SEL
[i
])
1334 reg
= nct6775_read_value(data
, data
->REG_WEIGHT_TEMP_SEL
[i
]);
1335 data
->pwm_weight_temp_sel
[i
] = reg
& 0x1f;
1336 /* If weight is disabled, report weight source as 0 */
1337 if (j
== 1 && !(reg
& 0x80))
1338 data
->pwm_weight_temp_sel
[i
] = 0;
1340 /* Weight temp data */
1341 for (j
= 0; j
< ARRAY_SIZE(data
->weight_temp
); j
++) {
1342 data
->weight_temp
[j
][i
]
1343 = nct6775_read_value(data
,
1344 data
->REG_WEIGHT_TEMP
[j
][i
]);
1349 static void nct6775_update_pwm_limits(struct device
*dev
)
1351 struct nct6775_data
*data
= dev_get_drvdata(dev
);
1356 for (i
= 0; i
< data
->pwm_num
; i
++) {
1357 if (!(data
->has_pwm
& (1 << i
)))
1360 for (j
= 0; j
< ARRAY_SIZE(data
->fan_time
); j
++) {
1361 data
->fan_time
[j
][i
] =
1362 nct6775_read_value(data
, data
->REG_FAN_TIME
[j
][i
]);
1365 reg_t
= nct6775_read_value(data
, data
->REG_TARGET
[i
]);
1366 /* Update only in matching mode or if never updated */
1367 if (!data
->target_temp
[i
] ||
1368 data
->pwm_enable
[i
] == thermal_cruise
)
1369 data
->target_temp
[i
] = reg_t
& data
->target_temp_mask
;
1370 if (!data
->target_speed
[i
] ||
1371 data
->pwm_enable
[i
] == speed_cruise
) {
1372 if (data
->REG_TOLERANCE_H
) {
1373 reg_t
|= (nct6775_read_value(data
,
1374 data
->REG_TOLERANCE_H
[i
]) & 0x0f) << 8;
1376 data
->target_speed
[i
] = reg_t
;
1379 for (j
= 0; j
< data
->auto_pwm_num
; j
++) {
1380 data
->auto_pwm
[i
][j
] =
1381 nct6775_read_value(data
,
1382 NCT6775_AUTO_PWM(data
, i
, j
));
1383 data
->auto_temp
[i
][j
] =
1384 nct6775_read_value(data
,
1385 NCT6775_AUTO_TEMP(data
, i
, j
));
1388 /* critical auto_pwm temperature data */
1389 data
->auto_temp
[i
][data
->auto_pwm_num
] =
1390 nct6775_read_value(data
, data
->REG_CRITICAL_TEMP
[i
]);
1392 switch (data
->kind
) {
1394 reg
= nct6775_read_value(data
,
1395 NCT6775_REG_CRITICAL_ENAB
[i
]);
1396 data
->auto_pwm
[i
][data
->auto_pwm_num
] =
1397 (reg
& 0x02) ? 0xff : 0x00;
1400 data
->auto_pwm
[i
][data
->auto_pwm_num
] = 0xff;
1406 reg
= nct6775_read_value(data
,
1407 data
->REG_CRITICAL_PWM_ENABLE
[i
]);
1408 if (reg
& data
->CRITICAL_PWM_ENABLE_MASK
)
1409 reg
= nct6775_read_value(data
,
1410 data
->REG_CRITICAL_PWM
[i
]);
1413 data
->auto_pwm
[i
][data
->auto_pwm_num
] = reg
;
1419 static struct nct6775_data
*nct6775_update_device(struct device
*dev
)
1421 struct nct6775_data
*data
= dev_get_drvdata(dev
);
1424 mutex_lock(&data
->update_lock
);
1426 if (time_after(jiffies
, data
->last_updated
+ HZ
+ HZ
/ 2)
1428 /* Fan clock dividers */
1429 nct6775_update_fan_div_common(data
);
1431 /* Measured voltages and limits */
1432 for (i
= 0; i
< data
->in_num
; i
++) {
1433 if (!(data
->have_in
& (1 << i
)))
1436 data
->in
[i
][0] = nct6775_read_value(data
,
1438 data
->in
[i
][1] = nct6775_read_value(data
,
1439 data
->REG_IN_MINMAX
[0][i
]);
1440 data
->in
[i
][2] = nct6775_read_value(data
,
1441 data
->REG_IN_MINMAX
[1][i
]);
1444 /* Measured fan speeds and limits */
1445 for (i
= 0; i
< ARRAY_SIZE(data
->rpm
); i
++) {
1448 if (!(data
->has_fan
& (1 << i
)))
1451 reg
= nct6775_read_value(data
, data
->REG_FAN
[i
]);
1452 data
->rpm
[i
] = data
->fan_from_reg(reg
,
1455 if (data
->has_fan_min
& (1 << i
))
1456 data
->fan_min
[i
] = nct6775_read_value(data
,
1457 data
->REG_FAN_MIN
[i
]);
1458 data
->fan_pulses
[i
] =
1459 (nct6775_read_value(data
, data
->REG_FAN_PULSES
[i
])
1460 >> data
->FAN_PULSE_SHIFT
[i
]) & 0x03;
1462 nct6775_select_fan_div(dev
, data
, i
, reg
);
1465 nct6775_update_pwm(dev
);
1466 nct6775_update_pwm_limits(dev
);
1468 /* Measured temperatures and limits */
1469 for (i
= 0; i
< NUM_TEMP
; i
++) {
1470 if (!(data
->have_temp
& (1 << i
)))
1472 for (j
= 0; j
< ARRAY_SIZE(data
->reg_temp
); j
++) {
1473 if (data
->reg_temp
[j
][i
])
1475 = nct6775_read_temp(data
,
1476 data
->reg_temp
[j
][i
]);
1478 if (i
>= NUM_TEMP_FIXED
||
1479 !(data
->have_temp_fixed
& (1 << i
)))
1481 data
->temp_offset
[i
]
1482 = nct6775_read_value(data
, data
->REG_TEMP_OFFSET
[i
]);
1486 for (i
= 0; i
< NUM_REG_ALARM
; i
++) {
1489 if (!data
->REG_ALARM
[i
])
1491 alarm
= nct6775_read_value(data
, data
->REG_ALARM
[i
]);
1492 data
->alarms
|= ((u64
)alarm
) << (i
<< 3);
1496 for (i
= 0; i
< NUM_REG_BEEP
; i
++) {
1499 if (!data
->REG_BEEP
[i
])
1501 beep
= nct6775_read_value(data
, data
->REG_BEEP
[i
]);
1502 data
->beeps
|= ((u64
)beep
) << (i
<< 3);
1505 data
->last_updated
= jiffies
;
1509 mutex_unlock(&data
->update_lock
);
1514 * Sysfs callback functions
1517 show_in_reg(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1519 struct nct6775_data
*data
= nct6775_update_device(dev
);
1520 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
1521 int index
= sattr
->index
;
1524 return sprintf(buf
, "%ld\n", in_from_reg(data
->in
[nr
][index
], nr
));
1528 store_in_reg(struct device
*dev
, struct device_attribute
*attr
, const char *buf
,
1531 struct nct6775_data
*data
= dev_get_drvdata(dev
);
1532 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
1533 int index
= sattr
->index
;
1538 err
= kstrtoul(buf
, 10, &val
);
1541 mutex_lock(&data
->update_lock
);
1542 data
->in
[nr
][index
] = in_to_reg(val
, nr
);
1543 nct6775_write_value(data
, data
->REG_IN_MINMAX
[index
- 1][nr
],
1544 data
->in
[nr
][index
]);
1545 mutex_unlock(&data
->update_lock
);
1550 show_alarm(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1552 struct nct6775_data
*data
= nct6775_update_device(dev
);
1553 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
1554 int nr
= data
->ALARM_BITS
[sattr
->index
];
1556 return sprintf(buf
, "%u\n",
1557 (unsigned int)((data
->alarms
>> nr
) & 0x01));
1560 static int find_temp_source(struct nct6775_data
*data
, int index
, int count
)
1562 int source
= data
->temp_src
[index
];
1565 for (nr
= 0; nr
< count
; nr
++) {
1568 src
= nct6775_read_value(data
,
1569 data
->REG_TEMP_SOURCE
[nr
]) & 0x1f;
1577 show_temp_alarm(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1579 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
1580 struct nct6775_data
*data
= nct6775_update_device(dev
);
1581 unsigned int alarm
= 0;
1585 * For temperatures, there is no fixed mapping from registers to alarm
1586 * bits. Alarm bits are determined by the temperature source mapping.
1588 nr
= find_temp_source(data
, sattr
->index
, data
->num_temp_alarms
);
1590 int bit
= data
->ALARM_BITS
[nr
+ TEMP_ALARM_BASE
];
1592 alarm
= (data
->alarms
>> bit
) & 0x01;
1594 return sprintf(buf
, "%u\n", alarm
);
1598 show_beep(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1600 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
1601 struct nct6775_data
*data
= nct6775_update_device(dev
);
1602 int nr
= data
->BEEP_BITS
[sattr
->index
];
1604 return sprintf(buf
, "%u\n",
1605 (unsigned int)((data
->beeps
>> nr
) & 0x01));
1609 store_beep(struct device
*dev
, struct device_attribute
*attr
, const char *buf
,
1612 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
1613 struct nct6775_data
*data
= dev_get_drvdata(dev
);
1614 int nr
= data
->BEEP_BITS
[sattr
->index
];
1615 int regindex
= nr
>> 3;
1619 err
= kstrtoul(buf
, 10, &val
);
1625 mutex_lock(&data
->update_lock
);
1627 data
->beeps
|= (1ULL << nr
);
1629 data
->beeps
&= ~(1ULL << nr
);
1630 nct6775_write_value(data
, data
->REG_BEEP
[regindex
],
1631 (data
->beeps
>> (regindex
<< 3)) & 0xff);
1632 mutex_unlock(&data
->update_lock
);
1637 show_temp_beep(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1639 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
1640 struct nct6775_data
*data
= nct6775_update_device(dev
);
1641 unsigned int beep
= 0;
1645 * For temperatures, there is no fixed mapping from registers to beep
1646 * enable bits. Beep enable bits are determined by the temperature
1649 nr
= find_temp_source(data
, sattr
->index
, data
->num_temp_beeps
);
1651 int bit
= data
->BEEP_BITS
[nr
+ TEMP_ALARM_BASE
];
1653 beep
= (data
->beeps
>> bit
) & 0x01;
1655 return sprintf(buf
, "%u\n", beep
);
1659 store_temp_beep(struct device
*dev
, struct device_attribute
*attr
,
1660 const char *buf
, size_t count
)
1662 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
1663 struct nct6775_data
*data
= dev_get_drvdata(dev
);
1664 int nr
, bit
, regindex
;
1668 err
= kstrtoul(buf
, 10, &val
);
1674 nr
= find_temp_source(data
, sattr
->index
, data
->num_temp_beeps
);
1678 bit
= data
->BEEP_BITS
[nr
+ TEMP_ALARM_BASE
];
1679 regindex
= bit
>> 3;
1681 mutex_lock(&data
->update_lock
);
1683 data
->beeps
|= (1ULL << bit
);
1685 data
->beeps
&= ~(1ULL << bit
);
1686 nct6775_write_value(data
, data
->REG_BEEP
[regindex
],
1687 (data
->beeps
>> (regindex
<< 3)) & 0xff);
1688 mutex_unlock(&data
->update_lock
);
1693 static umode_t
nct6775_in_is_visible(struct kobject
*kobj
,
1694 struct attribute
*attr
, int index
)
1696 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
1697 struct nct6775_data
*data
= dev_get_drvdata(dev
);
1698 int in
= index
/ 5; /* voltage index */
1700 if (!(data
->have_in
& (1 << in
)))
1706 SENSOR_TEMPLATE_2(in_input
, "in%d_input", S_IRUGO
, show_in_reg
, NULL
, 0, 0);
1707 SENSOR_TEMPLATE(in_alarm
, "in%d_alarm", S_IRUGO
, show_alarm
, NULL
, 0);
1708 SENSOR_TEMPLATE(in_beep
, "in%d_beep", S_IWUSR
| S_IRUGO
, show_beep
, store_beep
,
1710 SENSOR_TEMPLATE_2(in_min
, "in%d_min", S_IWUSR
| S_IRUGO
, show_in_reg
,
1711 store_in_reg
, 0, 1);
1712 SENSOR_TEMPLATE_2(in_max
, "in%d_max", S_IWUSR
| S_IRUGO
, show_in_reg
,
1713 store_in_reg
, 0, 2);
1716 * nct6775_in_is_visible uses the index into the following array
1717 * to determine if attributes should be created or not.
1718 * Any change in order or content must be matched.
1720 static struct sensor_device_template
*nct6775_attributes_in_template
[] = {
1721 &sensor_dev_template_in_input
,
1722 &sensor_dev_template_in_alarm
,
1723 &sensor_dev_template_in_beep
,
1724 &sensor_dev_template_in_min
,
1725 &sensor_dev_template_in_max
,
1729 static struct sensor_template_group nct6775_in_template_group
= {
1730 .templates
= nct6775_attributes_in_template
,
1731 .is_visible
= nct6775_in_is_visible
,
1735 show_fan(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1737 struct nct6775_data
*data
= nct6775_update_device(dev
);
1738 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
1739 int nr
= sattr
->index
;
1741 return sprintf(buf
, "%d\n", data
->rpm
[nr
]);
1745 show_fan_min(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1747 struct nct6775_data
*data
= nct6775_update_device(dev
);
1748 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
1749 int nr
= sattr
->index
;
1751 return sprintf(buf
, "%d\n",
1752 data
->fan_from_reg_min(data
->fan_min
[nr
],
1753 data
->fan_div
[nr
]));
1757 show_fan_div(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1759 struct nct6775_data
*data
= nct6775_update_device(dev
);
1760 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
1761 int nr
= sattr
->index
;
1763 return sprintf(buf
, "%u\n", div_from_reg(data
->fan_div
[nr
]));
1767 store_fan_min(struct device
*dev
, struct device_attribute
*attr
,
1768 const char *buf
, size_t count
)
1770 struct nct6775_data
*data
= dev_get_drvdata(dev
);
1771 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
1772 int nr
= sattr
->index
;
1778 err
= kstrtoul(buf
, 10, &val
);
1782 mutex_lock(&data
->update_lock
);
1783 if (!data
->has_fan_div
) {
1784 /* NCT6776F or NCT6779D; we know this is a 13 bit register */
1790 val
= 1350000U / val
;
1791 val
= (val
& 0x1f) | ((val
<< 3) & 0xff00);
1793 data
->fan_min
[nr
] = val
;
1794 goto write_min
; /* Leave fan divider alone */
1797 /* No min limit, alarm disabled */
1798 data
->fan_min
[nr
] = 255;
1799 new_div
= data
->fan_div
[nr
]; /* No change */
1800 dev_info(dev
, "fan%u low limit and alarm disabled\n", nr
+ 1);
1803 reg
= 1350000U / val
;
1804 if (reg
>= 128 * 255) {
1806 * Speed below this value cannot possibly be represented,
1807 * even with the highest divider (128)
1809 data
->fan_min
[nr
] = 254;
1810 new_div
= 7; /* 128 == (1 << 7) */
1812 "fan%u low limit %lu below minimum %u, set to minimum\n",
1813 nr
+ 1, val
, data
->fan_from_reg_min(254, 7));
1816 * Speed above this value cannot possibly be represented,
1817 * even with the lowest divider (1)
1819 data
->fan_min
[nr
] = 1;
1820 new_div
= 0; /* 1 == (1 << 0) */
1822 "fan%u low limit %lu above maximum %u, set to maximum\n",
1823 nr
+ 1, val
, data
->fan_from_reg_min(1, 0));
1826 * Automatically pick the best divider, i.e. the one such
1827 * that the min limit will correspond to a register value
1828 * in the 96..192 range
1831 while (reg
> 192 && new_div
< 7) {
1835 data
->fan_min
[nr
] = reg
;
1840 * Write both the fan clock divider (if it changed) and the new
1841 * fan min (unconditionally)
1843 if (new_div
!= data
->fan_div
[nr
]) {
1844 dev_dbg(dev
, "fan%u clock divider changed from %u to %u\n",
1845 nr
+ 1, div_from_reg(data
->fan_div
[nr
]),
1846 div_from_reg(new_div
));
1847 data
->fan_div
[nr
] = new_div
;
1848 nct6775_write_fan_div_common(data
, nr
);
1849 /* Give the chip time to sample a new speed value */
1850 data
->last_updated
= jiffies
;
1854 nct6775_write_value(data
, data
->REG_FAN_MIN
[nr
], data
->fan_min
[nr
]);
1855 mutex_unlock(&data
->update_lock
);
1861 show_fan_pulses(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1863 struct nct6775_data
*data
= nct6775_update_device(dev
);
1864 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
1865 int p
= data
->fan_pulses
[sattr
->index
];
1867 return sprintf(buf
, "%d\n", p
? : 4);
1871 store_fan_pulses(struct device
*dev
, struct device_attribute
*attr
,
1872 const char *buf
, size_t count
)
1874 struct nct6775_data
*data
= dev_get_drvdata(dev
);
1875 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
1876 int nr
= sattr
->index
;
1881 err
= kstrtoul(buf
, 10, &val
);
1888 mutex_lock(&data
->update_lock
);
1889 data
->fan_pulses
[nr
] = val
& 3;
1890 reg
= nct6775_read_value(data
, data
->REG_FAN_PULSES
[nr
]);
1891 reg
&= ~(0x03 << data
->FAN_PULSE_SHIFT
[nr
]);
1892 reg
|= (val
& 3) << data
->FAN_PULSE_SHIFT
[nr
];
1893 nct6775_write_value(data
, data
->REG_FAN_PULSES
[nr
], reg
);
1894 mutex_unlock(&data
->update_lock
);
1899 static umode_t
nct6775_fan_is_visible(struct kobject
*kobj
,
1900 struct attribute
*attr
, int index
)
1902 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
1903 struct nct6775_data
*data
= dev_get_drvdata(dev
);
1904 int fan
= index
/ 6; /* fan index */
1905 int nr
= index
% 6; /* attribute index */
1907 if (!(data
->has_fan
& (1 << fan
)))
1910 if (nr
== 1 && data
->ALARM_BITS
[FAN_ALARM_BASE
+ fan
] == -1)
1912 if (nr
== 2 && data
->BEEP_BITS
[FAN_ALARM_BASE
+ fan
] == -1)
1914 if (nr
== 4 && !(data
->has_fan_min
& (1 << fan
)))
1916 if (nr
== 5 && data
->kind
!= nct6775
)
1922 SENSOR_TEMPLATE(fan_input
, "fan%d_input", S_IRUGO
, show_fan
, NULL
, 0);
1923 SENSOR_TEMPLATE(fan_alarm
, "fan%d_alarm", S_IRUGO
, show_alarm
, NULL
,
1925 SENSOR_TEMPLATE(fan_beep
, "fan%d_beep", S_IWUSR
| S_IRUGO
, show_beep
,
1926 store_beep
, FAN_ALARM_BASE
);
1927 SENSOR_TEMPLATE(fan_pulses
, "fan%d_pulses", S_IWUSR
| S_IRUGO
, show_fan_pulses
,
1928 store_fan_pulses
, 0);
1929 SENSOR_TEMPLATE(fan_min
, "fan%d_min", S_IWUSR
| S_IRUGO
, show_fan_min
,
1931 SENSOR_TEMPLATE(fan_div
, "fan%d_div", S_IRUGO
, show_fan_div
, NULL
, 0);
1934 * nct6775_fan_is_visible uses the index into the following array
1935 * to determine if attributes should be created or not.
1936 * Any change in order or content must be matched.
1938 static struct sensor_device_template
*nct6775_attributes_fan_template
[] = {
1939 &sensor_dev_template_fan_input
,
1940 &sensor_dev_template_fan_alarm
, /* 1 */
1941 &sensor_dev_template_fan_beep
, /* 2 */
1942 &sensor_dev_template_fan_pulses
,
1943 &sensor_dev_template_fan_min
, /* 4 */
1944 &sensor_dev_template_fan_div
, /* 5 */
1948 static struct sensor_template_group nct6775_fan_template_group
= {
1949 .templates
= nct6775_attributes_fan_template
,
1950 .is_visible
= nct6775_fan_is_visible
,
1955 show_temp_label(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1957 struct nct6775_data
*data
= nct6775_update_device(dev
);
1958 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
1959 int nr
= sattr
->index
;
1961 return sprintf(buf
, "%s\n", data
->temp_label
[data
->temp_src
[nr
]]);
1965 show_temp(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1967 struct nct6775_data
*data
= nct6775_update_device(dev
);
1968 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
1970 int index
= sattr
->index
;
1972 return sprintf(buf
, "%d\n", LM75_TEMP_FROM_REG(data
->temp
[index
][nr
]));
1976 store_temp(struct device
*dev
, struct device_attribute
*attr
, const char *buf
,
1979 struct nct6775_data
*data
= dev_get_drvdata(dev
);
1980 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
1982 int index
= sattr
->index
;
1986 err
= kstrtol(buf
, 10, &val
);
1990 mutex_lock(&data
->update_lock
);
1991 data
->temp
[index
][nr
] = LM75_TEMP_TO_REG(val
);
1992 nct6775_write_temp(data
, data
->reg_temp
[index
][nr
],
1993 data
->temp
[index
][nr
]);
1994 mutex_unlock(&data
->update_lock
);
1999 show_temp_offset(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2001 struct nct6775_data
*data
= nct6775_update_device(dev
);
2002 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
2004 return sprintf(buf
, "%d\n", data
->temp_offset
[sattr
->index
] * 1000);
2008 store_temp_offset(struct device
*dev
, struct device_attribute
*attr
,
2009 const char *buf
, size_t count
)
2011 struct nct6775_data
*data
= dev_get_drvdata(dev
);
2012 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
2013 int nr
= sattr
->index
;
2017 err
= kstrtol(buf
, 10, &val
);
2021 val
= clamp_val(DIV_ROUND_CLOSEST(val
, 1000), -128, 127);
2023 mutex_lock(&data
->update_lock
);
2024 data
->temp_offset
[nr
] = val
;
2025 nct6775_write_value(data
, data
->REG_TEMP_OFFSET
[nr
], val
);
2026 mutex_unlock(&data
->update_lock
);
2032 show_temp_type(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2034 struct nct6775_data
*data
= nct6775_update_device(dev
);
2035 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
2036 int nr
= sattr
->index
;
2038 return sprintf(buf
, "%d\n", (int)data
->temp_type
[nr
]);
2042 store_temp_type(struct device
*dev
, struct device_attribute
*attr
,
2043 const char *buf
, size_t count
)
2045 struct nct6775_data
*data
= nct6775_update_device(dev
);
2046 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
2047 int nr
= sattr
->index
;
2050 u8 vbat
, diode
, vbit
, dbit
;
2052 err
= kstrtoul(buf
, 10, &val
);
2056 if (val
!= 1 && val
!= 3 && val
!= 4)
2059 mutex_lock(&data
->update_lock
);
2061 data
->temp_type
[nr
] = val
;
2063 dbit
= data
->DIODE_MASK
<< nr
;
2064 vbat
= nct6775_read_value(data
, data
->REG_VBAT
) & ~vbit
;
2065 diode
= nct6775_read_value(data
, data
->REG_DIODE
) & ~dbit
;
2067 case 1: /* CPU diode (diode, current mode) */
2071 case 3: /* diode, voltage mode */
2074 case 4: /* thermistor */
2077 nct6775_write_value(data
, data
->REG_VBAT
, vbat
);
2078 nct6775_write_value(data
, data
->REG_DIODE
, diode
);
2080 mutex_unlock(&data
->update_lock
);
2084 static umode_t
nct6775_temp_is_visible(struct kobject
*kobj
,
2085 struct attribute
*attr
, int index
)
2087 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2088 struct nct6775_data
*data
= dev_get_drvdata(dev
);
2089 int temp
= index
/ 10; /* temp index */
2090 int nr
= index
% 10; /* attribute index */
2092 if (!(data
->have_temp
& (1 << temp
)))
2095 if (nr
== 2 && find_temp_source(data
, temp
, data
->num_temp_alarms
) < 0)
2096 return 0; /* alarm */
2098 if (nr
== 3 && find_temp_source(data
, temp
, data
->num_temp_beeps
) < 0)
2099 return 0; /* beep */
2101 if (nr
== 4 && !data
->reg_temp
[1][temp
]) /* max */
2104 if (nr
== 5 && !data
->reg_temp
[2][temp
]) /* max_hyst */
2107 if (nr
== 6 && !data
->reg_temp
[3][temp
]) /* crit */
2110 if (nr
== 7 && !data
->reg_temp
[4][temp
]) /* lcrit */
2113 /* offset and type only apply to fixed sensors */
2114 if (nr
> 7 && !(data
->have_temp_fixed
& (1 << temp
)))
2120 SENSOR_TEMPLATE_2(temp_input
, "temp%d_input", S_IRUGO
, show_temp
, NULL
, 0, 0);
2121 SENSOR_TEMPLATE(temp_label
, "temp%d_label", S_IRUGO
, show_temp_label
, NULL
, 0);
2122 SENSOR_TEMPLATE_2(temp_max
, "temp%d_max", S_IRUGO
| S_IWUSR
, show_temp
,
2124 SENSOR_TEMPLATE_2(temp_max_hyst
, "temp%d_max_hyst", S_IRUGO
| S_IWUSR
,
2125 show_temp
, store_temp
, 0, 2);
2126 SENSOR_TEMPLATE_2(temp_crit
, "temp%d_crit", S_IRUGO
| S_IWUSR
, show_temp
,
2128 SENSOR_TEMPLATE_2(temp_lcrit
, "temp%d_lcrit", S_IRUGO
| S_IWUSR
, show_temp
,
2130 SENSOR_TEMPLATE(temp_offset
, "temp%d_offset", S_IRUGO
| S_IWUSR
,
2131 show_temp_offset
, store_temp_offset
, 0);
2132 SENSOR_TEMPLATE(temp_type
, "temp%d_type", S_IRUGO
| S_IWUSR
, show_temp_type
,
2133 store_temp_type
, 0);
2134 SENSOR_TEMPLATE(temp_alarm
, "temp%d_alarm", S_IRUGO
, show_temp_alarm
, NULL
, 0);
2135 SENSOR_TEMPLATE(temp_beep
, "temp%d_beep", S_IRUGO
| S_IWUSR
, show_temp_beep
,
2136 store_temp_beep
, 0);
2139 * nct6775_temp_is_visible uses the index into the following array
2140 * to determine if attributes should be created or not.
2141 * Any change in order or content must be matched.
2143 static struct sensor_device_template
*nct6775_attributes_temp_template
[] = {
2144 &sensor_dev_template_temp_input
,
2145 &sensor_dev_template_temp_label
,
2146 &sensor_dev_template_temp_alarm
, /* 2 */
2147 &sensor_dev_template_temp_beep
, /* 3 */
2148 &sensor_dev_template_temp_max
, /* 4 */
2149 &sensor_dev_template_temp_max_hyst
, /* 5 */
2150 &sensor_dev_template_temp_crit
, /* 6 */
2151 &sensor_dev_template_temp_lcrit
, /* 7 */
2152 &sensor_dev_template_temp_offset
, /* 8 */
2153 &sensor_dev_template_temp_type
, /* 9 */
2157 static struct sensor_template_group nct6775_temp_template_group
= {
2158 .templates
= nct6775_attributes_temp_template
,
2159 .is_visible
= nct6775_temp_is_visible
,
2164 show_pwm_mode(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2166 struct nct6775_data
*data
= nct6775_update_device(dev
);
2167 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
2169 return sprintf(buf
, "%d\n", !data
->pwm_mode
[sattr
->index
]);
2173 store_pwm_mode(struct device
*dev
, struct device_attribute
*attr
,
2174 const char *buf
, size_t count
)
2176 struct nct6775_data
*data
= dev_get_drvdata(dev
);
2177 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
2178 int nr
= sattr
->index
;
2183 err
= kstrtoul(buf
, 10, &val
);
2190 /* Setting DC mode is not supported for all chips/channels */
2191 if (data
->REG_PWM_MODE
[nr
] == 0) {
2197 mutex_lock(&data
->update_lock
);
2198 data
->pwm_mode
[nr
] = val
;
2199 reg
= nct6775_read_value(data
, data
->REG_PWM_MODE
[nr
]);
2200 reg
&= ~data
->PWM_MODE_MASK
[nr
];
2202 reg
|= data
->PWM_MODE_MASK
[nr
];
2203 nct6775_write_value(data
, data
->REG_PWM_MODE
[nr
], reg
);
2204 mutex_unlock(&data
->update_lock
);
2209 show_pwm(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2211 struct nct6775_data
*data
= nct6775_update_device(dev
);
2212 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
2214 int index
= sattr
->index
;
2218 * For automatic fan control modes, show current pwm readings.
2219 * Otherwise, show the configured value.
2221 if (index
== 0 && data
->pwm_enable
[nr
] > manual
)
2222 pwm
= nct6775_read_value(data
, data
->REG_PWM_READ
[nr
]);
2224 pwm
= data
->pwm
[index
][nr
];
2226 return sprintf(buf
, "%d\n", pwm
);
2230 store_pwm(struct device
*dev
, struct device_attribute
*attr
, const char *buf
,
2233 struct nct6775_data
*data
= dev_get_drvdata(dev
);
2234 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
2236 int index
= sattr
->index
;
2238 int minval
[7] = { 0, 1, 1, data
->pwm
[2][nr
], 0, 0, 0 };
2240 = { 255, 255, data
->pwm
[3][nr
] ? : 255, 255, 255, 255, 255 };
2244 err
= kstrtoul(buf
, 10, &val
);
2247 val
= clamp_val(val
, minval
[index
], maxval
[index
]);
2249 mutex_lock(&data
->update_lock
);
2250 data
->pwm
[index
][nr
] = val
;
2251 nct6775_write_value(data
, data
->REG_PWM
[index
][nr
], val
);
2252 if (index
== 2) { /* floor: disable if val == 0 */
2253 reg
= nct6775_read_value(data
, data
->REG_TEMP_SEL
[nr
]);
2257 nct6775_write_value(data
, data
->REG_TEMP_SEL
[nr
], reg
);
2259 mutex_unlock(&data
->update_lock
);
2263 /* Returns 0 if OK, -EINVAL otherwise */
2264 static int check_trip_points(struct nct6775_data
*data
, int nr
)
2268 for (i
= 0; i
< data
->auto_pwm_num
- 1; i
++) {
2269 if (data
->auto_temp
[nr
][i
] > data
->auto_temp
[nr
][i
+ 1])
2272 for (i
= 0; i
< data
->auto_pwm_num
- 1; i
++) {
2273 if (data
->auto_pwm
[nr
][i
] > data
->auto_pwm
[nr
][i
+ 1])
2276 /* validate critical temperature and pwm if enabled (pwm > 0) */
2277 if (data
->auto_pwm
[nr
][data
->auto_pwm_num
]) {
2278 if (data
->auto_temp
[nr
][data
->auto_pwm_num
- 1] >
2279 data
->auto_temp
[nr
][data
->auto_pwm_num
] ||
2280 data
->auto_pwm
[nr
][data
->auto_pwm_num
- 1] >
2281 data
->auto_pwm
[nr
][data
->auto_pwm_num
])
2287 static void pwm_update_registers(struct nct6775_data
*data
, int nr
)
2291 switch (data
->pwm_enable
[nr
]) {
2296 reg
= nct6775_read_value(data
, data
->REG_FAN_MODE
[nr
]);
2297 reg
= (reg
& ~data
->tolerance_mask
) |
2298 (data
->target_speed_tolerance
[nr
] & data
->tolerance_mask
);
2299 nct6775_write_value(data
, data
->REG_FAN_MODE
[nr
], reg
);
2300 nct6775_write_value(data
, data
->REG_TARGET
[nr
],
2301 data
->target_speed
[nr
] & 0xff);
2302 if (data
->REG_TOLERANCE_H
) {
2303 reg
= (data
->target_speed
[nr
] >> 8) & 0x0f;
2304 reg
|= (data
->target_speed_tolerance
[nr
] & 0x38) << 1;
2305 nct6775_write_value(data
,
2306 data
->REG_TOLERANCE_H
[nr
],
2310 case thermal_cruise
:
2311 nct6775_write_value(data
, data
->REG_TARGET
[nr
],
2312 data
->target_temp
[nr
]);
2315 reg
= nct6775_read_value(data
, data
->REG_FAN_MODE
[nr
]);
2316 reg
= (reg
& ~data
->tolerance_mask
) |
2317 data
->temp_tolerance
[0][nr
];
2318 nct6775_write_value(data
, data
->REG_FAN_MODE
[nr
], reg
);
2324 show_pwm_enable(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2326 struct nct6775_data
*data
= nct6775_update_device(dev
);
2327 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
2329 return sprintf(buf
, "%d\n", data
->pwm_enable
[sattr
->index
]);
2333 store_pwm_enable(struct device
*dev
, struct device_attribute
*attr
,
2334 const char *buf
, size_t count
)
2336 struct nct6775_data
*data
= dev_get_drvdata(dev
);
2337 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
2338 int nr
= sattr
->index
;
2343 err
= kstrtoul(buf
, 10, &val
);
2350 if (val
== sf3
&& data
->kind
!= nct6775
)
2353 if (val
== sf4
&& check_trip_points(data
, nr
)) {
2354 dev_err(dev
, "Inconsistent trip points, not switching to SmartFan IV mode\n");
2355 dev_err(dev
, "Adjust trip points and try again\n");
2359 mutex_lock(&data
->update_lock
);
2360 data
->pwm_enable
[nr
] = val
;
2363 * turn off pwm control: select manual mode, set pwm to maximum
2365 data
->pwm
[0][nr
] = 255;
2366 nct6775_write_value(data
, data
->REG_PWM
[0][nr
], 255);
2368 pwm_update_registers(data
, nr
);
2369 reg
= nct6775_read_value(data
, data
->REG_FAN_MODE
[nr
]);
2371 reg
|= pwm_enable_to_reg(val
) << 4;
2372 nct6775_write_value(data
, data
->REG_FAN_MODE
[nr
], reg
);
2373 mutex_unlock(&data
->update_lock
);
2378 show_pwm_temp_sel_common(struct nct6775_data
*data
, char *buf
, int src
)
2382 for (i
= 0; i
< NUM_TEMP
; i
++) {
2383 if (!(data
->have_temp
& (1 << i
)))
2385 if (src
== data
->temp_src
[i
]) {
2391 return sprintf(buf
, "%d\n", sel
);
2395 show_pwm_temp_sel(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2397 struct nct6775_data
*data
= nct6775_update_device(dev
);
2398 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
2399 int index
= sattr
->index
;
2401 return show_pwm_temp_sel_common(data
, buf
, data
->pwm_temp_sel
[index
]);
2405 store_pwm_temp_sel(struct device
*dev
, struct device_attribute
*attr
,
2406 const char *buf
, size_t count
)
2408 struct nct6775_data
*data
= nct6775_update_device(dev
);
2409 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
2410 int nr
= sattr
->index
;
2414 err
= kstrtoul(buf
, 10, &val
);
2417 if (val
== 0 || val
> NUM_TEMP
)
2419 if (!(data
->have_temp
& (1 << (val
- 1))) || !data
->temp_src
[val
- 1])
2422 mutex_lock(&data
->update_lock
);
2423 src
= data
->temp_src
[val
- 1];
2424 data
->pwm_temp_sel
[nr
] = src
;
2425 reg
= nct6775_read_value(data
, data
->REG_TEMP_SEL
[nr
]);
2428 nct6775_write_value(data
, data
->REG_TEMP_SEL
[nr
], reg
);
2429 mutex_unlock(&data
->update_lock
);
2435 show_pwm_weight_temp_sel(struct device
*dev
, struct device_attribute
*attr
,
2438 struct nct6775_data
*data
= nct6775_update_device(dev
);
2439 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
2440 int index
= sattr
->index
;
2442 return show_pwm_temp_sel_common(data
, buf
,
2443 data
->pwm_weight_temp_sel
[index
]);
2447 store_pwm_weight_temp_sel(struct device
*dev
, struct device_attribute
*attr
,
2448 const char *buf
, size_t count
)
2450 struct nct6775_data
*data
= nct6775_update_device(dev
);
2451 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
2452 int nr
= sattr
->index
;
2456 err
= kstrtoul(buf
, 10, &val
);
2461 if (val
&& (!(data
->have_temp
& (1 << (val
- 1))) ||
2462 !data
->temp_src
[val
- 1]))
2465 mutex_lock(&data
->update_lock
);
2467 src
= data
->temp_src
[val
- 1];
2468 data
->pwm_weight_temp_sel
[nr
] = src
;
2469 reg
= nct6775_read_value(data
, data
->REG_WEIGHT_TEMP_SEL
[nr
]);
2471 reg
|= (src
| 0x80);
2472 nct6775_write_value(data
, data
->REG_WEIGHT_TEMP_SEL
[nr
], reg
);
2474 data
->pwm_weight_temp_sel
[nr
] = 0;
2475 reg
= nct6775_read_value(data
, data
->REG_WEIGHT_TEMP_SEL
[nr
]);
2477 nct6775_write_value(data
, data
->REG_WEIGHT_TEMP_SEL
[nr
], reg
);
2479 mutex_unlock(&data
->update_lock
);
2485 show_target_temp(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2487 struct nct6775_data
*data
= nct6775_update_device(dev
);
2488 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
2490 return sprintf(buf
, "%d\n", data
->target_temp
[sattr
->index
] * 1000);
2494 store_target_temp(struct device
*dev
, struct device_attribute
*attr
,
2495 const char *buf
, size_t count
)
2497 struct nct6775_data
*data
= dev_get_drvdata(dev
);
2498 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
2499 int nr
= sattr
->index
;
2503 err
= kstrtoul(buf
, 10, &val
);
2507 val
= clamp_val(DIV_ROUND_CLOSEST(val
, 1000), 0,
2508 data
->target_temp_mask
);
2510 mutex_lock(&data
->update_lock
);
2511 data
->target_temp
[nr
] = val
;
2512 pwm_update_registers(data
, nr
);
2513 mutex_unlock(&data
->update_lock
);
2518 show_target_speed(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2520 struct nct6775_data
*data
= nct6775_update_device(dev
);
2521 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
2522 int nr
= sattr
->index
;
2524 return sprintf(buf
, "%d\n",
2525 fan_from_reg16(data
->target_speed
[nr
],
2526 data
->fan_div
[nr
]));
2530 store_target_speed(struct device
*dev
, struct device_attribute
*attr
,
2531 const char *buf
, size_t count
)
2533 struct nct6775_data
*data
= dev_get_drvdata(dev
);
2534 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
2535 int nr
= sattr
->index
;
2540 err
= kstrtoul(buf
, 10, &val
);
2544 val
= clamp_val(val
, 0, 1350000U);
2545 speed
= fan_to_reg(val
, data
->fan_div
[nr
]);
2547 mutex_lock(&data
->update_lock
);
2548 data
->target_speed
[nr
] = speed
;
2549 pwm_update_registers(data
, nr
);
2550 mutex_unlock(&data
->update_lock
);
2555 show_temp_tolerance(struct device
*dev
, struct device_attribute
*attr
,
2558 struct nct6775_data
*data
= nct6775_update_device(dev
);
2559 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
2561 int index
= sattr
->index
;
2563 return sprintf(buf
, "%d\n", data
->temp_tolerance
[index
][nr
] * 1000);
2567 store_temp_tolerance(struct device
*dev
, struct device_attribute
*attr
,
2568 const char *buf
, size_t count
)
2570 struct nct6775_data
*data
= dev_get_drvdata(dev
);
2571 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
2573 int index
= sattr
->index
;
2577 err
= kstrtoul(buf
, 10, &val
);
2581 /* Limit tolerance as needed */
2582 val
= clamp_val(DIV_ROUND_CLOSEST(val
, 1000), 0, data
->tolerance_mask
);
2584 mutex_lock(&data
->update_lock
);
2585 data
->temp_tolerance
[index
][nr
] = val
;
2587 pwm_update_registers(data
, nr
);
2589 nct6775_write_value(data
,
2590 data
->REG_CRITICAL_TEMP_TOLERANCE
[nr
],
2592 mutex_unlock(&data
->update_lock
);
2597 * Fan speed tolerance is a tricky beast, since the associated register is
2598 * a tick counter, but the value is reported and configured as rpm.
2599 * Compute resulting low and high rpm values and report the difference.
2602 show_speed_tolerance(struct device
*dev
, struct device_attribute
*attr
,
2605 struct nct6775_data
*data
= nct6775_update_device(dev
);
2606 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
2607 int nr
= sattr
->index
;
2608 int low
= data
->target_speed
[nr
] - data
->target_speed_tolerance
[nr
];
2609 int high
= data
->target_speed
[nr
] + data
->target_speed_tolerance
[nr
];
2619 tolerance
= (fan_from_reg16(low
, data
->fan_div
[nr
])
2620 - fan_from_reg16(high
, data
->fan_div
[nr
])) / 2;
2622 return sprintf(buf
, "%d\n", tolerance
);
2626 store_speed_tolerance(struct device
*dev
, struct device_attribute
*attr
,
2627 const char *buf
, size_t count
)
2629 struct nct6775_data
*data
= dev_get_drvdata(dev
);
2630 struct sensor_device_attribute
*sattr
= to_sensor_dev_attr(attr
);
2631 int nr
= sattr
->index
;
2636 err
= kstrtoul(buf
, 10, &val
);
2640 high
= fan_from_reg16(data
->target_speed
[nr
],
2641 data
->fan_div
[nr
]) + val
;
2642 low
= fan_from_reg16(data
->target_speed
[nr
],
2643 data
->fan_div
[nr
]) - val
;
2649 val
= (fan_to_reg(low
, data
->fan_div
[nr
]) -
2650 fan_to_reg(high
, data
->fan_div
[nr
])) / 2;
2652 /* Limit tolerance as needed */
2653 val
= clamp_val(val
, 0, data
->speed_tolerance_limit
);
2655 mutex_lock(&data
->update_lock
);
2656 data
->target_speed_tolerance
[nr
] = val
;
2657 pwm_update_registers(data
, nr
);
2658 mutex_unlock(&data
->update_lock
);
2662 SENSOR_TEMPLATE_2(pwm
, "pwm%d", S_IWUSR
| S_IRUGO
, show_pwm
, store_pwm
, 0, 0);
2663 SENSOR_TEMPLATE(pwm_mode
, "pwm%d_mode", S_IWUSR
| S_IRUGO
, show_pwm_mode
,
2665 SENSOR_TEMPLATE(pwm_enable
, "pwm%d_enable", S_IWUSR
| S_IRUGO
, show_pwm_enable
,
2666 store_pwm_enable
, 0);
2667 SENSOR_TEMPLATE(pwm_temp_sel
, "pwm%d_temp_sel", S_IWUSR
| S_IRUGO
,
2668 show_pwm_temp_sel
, store_pwm_temp_sel
, 0);
2669 SENSOR_TEMPLATE(pwm_target_temp
, "pwm%d_target_temp", S_IWUSR
| S_IRUGO
,
2670 show_target_temp
, store_target_temp
, 0);
2671 SENSOR_TEMPLATE(fan_target
, "fan%d_target", S_IWUSR
| S_IRUGO
,
2672 show_target_speed
, store_target_speed
, 0);
2673 SENSOR_TEMPLATE(fan_tolerance
, "fan%d_tolerance", S_IWUSR
| S_IRUGO
,
2674 show_speed_tolerance
, store_speed_tolerance
, 0);
2676 /* Smart Fan registers */
2679 show_weight_temp(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2681 struct nct6775_data
*data
= nct6775_update_device(dev
);
2682 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
2684 int index
= sattr
->index
;
2686 return sprintf(buf
, "%d\n", data
->weight_temp
[index
][nr
] * 1000);
2690 store_weight_temp(struct device
*dev
, struct device_attribute
*attr
,
2691 const char *buf
, size_t count
)
2693 struct nct6775_data
*data
= dev_get_drvdata(dev
);
2694 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
2696 int index
= sattr
->index
;
2700 err
= kstrtoul(buf
, 10, &val
);
2704 val
= clamp_val(DIV_ROUND_CLOSEST(val
, 1000), 0, 255);
2706 mutex_lock(&data
->update_lock
);
2707 data
->weight_temp
[index
][nr
] = val
;
2708 nct6775_write_value(data
, data
->REG_WEIGHT_TEMP
[index
][nr
], val
);
2709 mutex_unlock(&data
->update_lock
);
2713 SENSOR_TEMPLATE(pwm_weight_temp_sel
, "pwm%d_weight_temp_sel", S_IWUSR
| S_IRUGO
,
2714 show_pwm_weight_temp_sel
, store_pwm_weight_temp_sel
, 0);
2715 SENSOR_TEMPLATE_2(pwm_weight_temp_step
, "pwm%d_weight_temp_step",
2716 S_IWUSR
| S_IRUGO
, show_weight_temp
, store_weight_temp
, 0, 0);
2717 SENSOR_TEMPLATE_2(pwm_weight_temp_step_tol
, "pwm%d_weight_temp_step_tol",
2718 S_IWUSR
| S_IRUGO
, show_weight_temp
, store_weight_temp
, 0, 1);
2719 SENSOR_TEMPLATE_2(pwm_weight_temp_step_base
, "pwm%d_weight_temp_step_base",
2720 S_IWUSR
| S_IRUGO
, show_weight_temp
, store_weight_temp
, 0, 2);
2721 SENSOR_TEMPLATE_2(pwm_weight_duty_step
, "pwm%d_weight_duty_step",
2722 S_IWUSR
| S_IRUGO
, show_pwm
, store_pwm
, 0, 5);
2723 SENSOR_TEMPLATE_2(pwm_weight_duty_base
, "pwm%d_weight_duty_base",
2724 S_IWUSR
| S_IRUGO
, show_pwm
, store_pwm
, 0, 6);
2727 show_fan_time(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2729 struct nct6775_data
*data
= nct6775_update_device(dev
);
2730 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
2732 int index
= sattr
->index
;
2734 return sprintf(buf
, "%d\n",
2735 step_time_from_reg(data
->fan_time
[index
][nr
],
2736 data
->pwm_mode
[nr
]));
2740 store_fan_time(struct device
*dev
, struct device_attribute
*attr
,
2741 const char *buf
, size_t count
)
2743 struct nct6775_data
*data
= dev_get_drvdata(dev
);
2744 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
2746 int index
= sattr
->index
;
2750 err
= kstrtoul(buf
, 10, &val
);
2754 val
= step_time_to_reg(val
, data
->pwm_mode
[nr
]);
2755 mutex_lock(&data
->update_lock
);
2756 data
->fan_time
[index
][nr
] = val
;
2757 nct6775_write_value(data
, data
->REG_FAN_TIME
[index
][nr
], val
);
2758 mutex_unlock(&data
->update_lock
);
2763 show_auto_pwm(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2765 struct nct6775_data
*data
= nct6775_update_device(dev
);
2766 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
2768 return sprintf(buf
, "%d\n", data
->auto_pwm
[sattr
->nr
][sattr
->index
]);
2772 store_auto_pwm(struct device
*dev
, struct device_attribute
*attr
,
2773 const char *buf
, size_t count
)
2775 struct nct6775_data
*data
= dev_get_drvdata(dev
);
2776 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
2778 int point
= sattr
->index
;
2783 err
= kstrtoul(buf
, 10, &val
);
2789 if (point
== data
->auto_pwm_num
) {
2790 if (data
->kind
!= nct6775
&& !val
)
2792 if (data
->kind
!= nct6779
&& val
)
2796 mutex_lock(&data
->update_lock
);
2797 data
->auto_pwm
[nr
][point
] = val
;
2798 if (point
< data
->auto_pwm_num
) {
2799 nct6775_write_value(data
,
2800 NCT6775_AUTO_PWM(data
, nr
, point
),
2801 data
->auto_pwm
[nr
][point
]);
2803 switch (data
->kind
) {
2805 /* disable if needed (pwm == 0) */
2806 reg
= nct6775_read_value(data
,
2807 NCT6775_REG_CRITICAL_ENAB
[nr
]);
2812 nct6775_write_value(data
, NCT6775_REG_CRITICAL_ENAB
[nr
],
2816 break; /* always enabled, nothing to do */
2821 nct6775_write_value(data
, data
->REG_CRITICAL_PWM
[nr
],
2823 reg
= nct6775_read_value(data
,
2824 data
->REG_CRITICAL_PWM_ENABLE
[nr
]);
2826 reg
&= ~data
->CRITICAL_PWM_ENABLE_MASK
;
2828 reg
|= data
->CRITICAL_PWM_ENABLE_MASK
;
2829 nct6775_write_value(data
,
2830 data
->REG_CRITICAL_PWM_ENABLE
[nr
],
2835 mutex_unlock(&data
->update_lock
);
2840 show_auto_temp(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
2842 struct nct6775_data
*data
= nct6775_update_device(dev
);
2843 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
2845 int point
= sattr
->index
;
2848 * We don't know for sure if the temperature is signed or unsigned.
2849 * Assume it is unsigned.
2851 return sprintf(buf
, "%d\n", data
->auto_temp
[nr
][point
] * 1000);
2855 store_auto_temp(struct device
*dev
, struct device_attribute
*attr
,
2856 const char *buf
, size_t count
)
2858 struct nct6775_data
*data
= dev_get_drvdata(dev
);
2859 struct sensor_device_attribute_2
*sattr
= to_sensor_dev_attr_2(attr
);
2861 int point
= sattr
->index
;
2865 err
= kstrtoul(buf
, 10, &val
);
2871 mutex_lock(&data
->update_lock
);
2872 data
->auto_temp
[nr
][point
] = DIV_ROUND_CLOSEST(val
, 1000);
2873 if (point
< data
->auto_pwm_num
) {
2874 nct6775_write_value(data
,
2875 NCT6775_AUTO_TEMP(data
, nr
, point
),
2876 data
->auto_temp
[nr
][point
]);
2878 nct6775_write_value(data
, data
->REG_CRITICAL_TEMP
[nr
],
2879 data
->auto_temp
[nr
][point
]);
2881 mutex_unlock(&data
->update_lock
);
2885 static umode_t
nct6775_pwm_is_visible(struct kobject
*kobj
,
2886 struct attribute
*attr
, int index
)
2888 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
2889 struct nct6775_data
*data
= dev_get_drvdata(dev
);
2890 int pwm
= index
/ 36; /* pwm index */
2891 int nr
= index
% 36; /* attribute index */
2893 if (!(data
->has_pwm
& (1 << pwm
)))
2896 if ((nr
>= 14 && nr
<= 18) || nr
== 21) /* weight */
2897 if (!data
->REG_WEIGHT_TEMP_SEL
[pwm
])
2899 if (nr
== 19 && data
->REG_PWM
[3] == NULL
) /* pwm_max */
2901 if (nr
== 20 && data
->REG_PWM
[4] == NULL
) /* pwm_step */
2903 if (nr
== 21 && data
->REG_PWM
[6] == NULL
) /* weight_duty_base */
2906 if (nr
>= 22 && nr
<= 35) { /* auto point */
2907 int api
= (nr
- 22) / 2; /* auto point index */
2909 if (api
> data
->auto_pwm_num
)
2915 SENSOR_TEMPLATE_2(pwm_stop_time
, "pwm%d_stop_time", S_IWUSR
| S_IRUGO
,
2916 show_fan_time
, store_fan_time
, 0, 0);
2917 SENSOR_TEMPLATE_2(pwm_step_up_time
, "pwm%d_step_up_time", S_IWUSR
| S_IRUGO
,
2918 show_fan_time
, store_fan_time
, 0, 1);
2919 SENSOR_TEMPLATE_2(pwm_step_down_time
, "pwm%d_step_down_time", S_IWUSR
| S_IRUGO
,
2920 show_fan_time
, store_fan_time
, 0, 2);
2921 SENSOR_TEMPLATE_2(pwm_start
, "pwm%d_start", S_IWUSR
| S_IRUGO
, show_pwm
,
2923 SENSOR_TEMPLATE_2(pwm_floor
, "pwm%d_floor", S_IWUSR
| S_IRUGO
, show_pwm
,
2925 SENSOR_TEMPLATE_2(pwm_temp_tolerance
, "pwm%d_temp_tolerance", S_IWUSR
| S_IRUGO
,
2926 show_temp_tolerance
, store_temp_tolerance
, 0, 0);
2927 SENSOR_TEMPLATE_2(pwm_crit_temp_tolerance
, "pwm%d_crit_temp_tolerance",
2928 S_IWUSR
| S_IRUGO
, show_temp_tolerance
, store_temp_tolerance
,
2931 SENSOR_TEMPLATE_2(pwm_max
, "pwm%d_max", S_IWUSR
| S_IRUGO
, show_pwm
, store_pwm
,
2934 SENSOR_TEMPLATE_2(pwm_step
, "pwm%d_step", S_IWUSR
| S_IRUGO
, show_pwm
,
2937 SENSOR_TEMPLATE_2(pwm_auto_point1_pwm
, "pwm%d_auto_point1_pwm",
2938 S_IWUSR
| S_IRUGO
, show_auto_pwm
, store_auto_pwm
, 0, 0);
2939 SENSOR_TEMPLATE_2(pwm_auto_point1_temp
, "pwm%d_auto_point1_temp",
2940 S_IWUSR
| S_IRUGO
, show_auto_temp
, store_auto_temp
, 0, 0);
2942 SENSOR_TEMPLATE_2(pwm_auto_point2_pwm
, "pwm%d_auto_point2_pwm",
2943 S_IWUSR
| S_IRUGO
, show_auto_pwm
, store_auto_pwm
, 0, 1);
2944 SENSOR_TEMPLATE_2(pwm_auto_point2_temp
, "pwm%d_auto_point2_temp",
2945 S_IWUSR
| S_IRUGO
, show_auto_temp
, store_auto_temp
, 0, 1);
2947 SENSOR_TEMPLATE_2(pwm_auto_point3_pwm
, "pwm%d_auto_point3_pwm",
2948 S_IWUSR
| S_IRUGO
, show_auto_pwm
, store_auto_pwm
, 0, 2);
2949 SENSOR_TEMPLATE_2(pwm_auto_point3_temp
, "pwm%d_auto_point3_temp",
2950 S_IWUSR
| S_IRUGO
, show_auto_temp
, store_auto_temp
, 0, 2);
2952 SENSOR_TEMPLATE_2(pwm_auto_point4_pwm
, "pwm%d_auto_point4_pwm",
2953 S_IWUSR
| S_IRUGO
, show_auto_pwm
, store_auto_pwm
, 0, 3);
2954 SENSOR_TEMPLATE_2(pwm_auto_point4_temp
, "pwm%d_auto_point4_temp",
2955 S_IWUSR
| S_IRUGO
, show_auto_temp
, store_auto_temp
, 0, 3);
2957 SENSOR_TEMPLATE_2(pwm_auto_point5_pwm
, "pwm%d_auto_point5_pwm",
2958 S_IWUSR
| S_IRUGO
, show_auto_pwm
, store_auto_pwm
, 0, 4);
2959 SENSOR_TEMPLATE_2(pwm_auto_point5_temp
, "pwm%d_auto_point5_temp",
2960 S_IWUSR
| S_IRUGO
, show_auto_temp
, store_auto_temp
, 0, 4);
2962 SENSOR_TEMPLATE_2(pwm_auto_point6_pwm
, "pwm%d_auto_point6_pwm",
2963 S_IWUSR
| S_IRUGO
, show_auto_pwm
, store_auto_pwm
, 0, 5);
2964 SENSOR_TEMPLATE_2(pwm_auto_point6_temp
, "pwm%d_auto_point6_temp",
2965 S_IWUSR
| S_IRUGO
, show_auto_temp
, store_auto_temp
, 0, 5);
2967 SENSOR_TEMPLATE_2(pwm_auto_point7_pwm
, "pwm%d_auto_point7_pwm",
2968 S_IWUSR
| S_IRUGO
, show_auto_pwm
, store_auto_pwm
, 0, 6);
2969 SENSOR_TEMPLATE_2(pwm_auto_point7_temp
, "pwm%d_auto_point7_temp",
2970 S_IWUSR
| S_IRUGO
, show_auto_temp
, store_auto_temp
, 0, 6);
2973 * nct6775_pwm_is_visible uses the index into the following array
2974 * to determine if attributes should be created or not.
2975 * Any change in order or content must be matched.
2977 static struct sensor_device_template
*nct6775_attributes_pwm_template
[] = {
2978 &sensor_dev_template_pwm
,
2979 &sensor_dev_template_pwm_mode
,
2980 &sensor_dev_template_pwm_enable
,
2981 &sensor_dev_template_pwm_temp_sel
,
2982 &sensor_dev_template_pwm_temp_tolerance
,
2983 &sensor_dev_template_pwm_crit_temp_tolerance
,
2984 &sensor_dev_template_pwm_target_temp
,
2985 &sensor_dev_template_fan_target
,
2986 &sensor_dev_template_fan_tolerance
,
2987 &sensor_dev_template_pwm_stop_time
,
2988 &sensor_dev_template_pwm_step_up_time
,
2989 &sensor_dev_template_pwm_step_down_time
,
2990 &sensor_dev_template_pwm_start
,
2991 &sensor_dev_template_pwm_floor
,
2992 &sensor_dev_template_pwm_weight_temp_sel
, /* 14 */
2993 &sensor_dev_template_pwm_weight_temp_step
,
2994 &sensor_dev_template_pwm_weight_temp_step_tol
,
2995 &sensor_dev_template_pwm_weight_temp_step_base
,
2996 &sensor_dev_template_pwm_weight_duty_step
, /* 18 */
2997 &sensor_dev_template_pwm_max
, /* 19 */
2998 &sensor_dev_template_pwm_step
, /* 20 */
2999 &sensor_dev_template_pwm_weight_duty_base
, /* 21 */
3000 &sensor_dev_template_pwm_auto_point1_pwm
, /* 22 */
3001 &sensor_dev_template_pwm_auto_point1_temp
,
3002 &sensor_dev_template_pwm_auto_point2_pwm
,
3003 &sensor_dev_template_pwm_auto_point2_temp
,
3004 &sensor_dev_template_pwm_auto_point3_pwm
,
3005 &sensor_dev_template_pwm_auto_point3_temp
,
3006 &sensor_dev_template_pwm_auto_point4_pwm
,
3007 &sensor_dev_template_pwm_auto_point4_temp
,
3008 &sensor_dev_template_pwm_auto_point5_pwm
,
3009 &sensor_dev_template_pwm_auto_point5_temp
,
3010 &sensor_dev_template_pwm_auto_point6_pwm
,
3011 &sensor_dev_template_pwm_auto_point6_temp
,
3012 &sensor_dev_template_pwm_auto_point7_pwm
,
3013 &sensor_dev_template_pwm_auto_point7_temp
, /* 35 */
3018 static struct sensor_template_group nct6775_pwm_template_group
= {
3019 .templates
= nct6775_attributes_pwm_template
,
3020 .is_visible
= nct6775_pwm_is_visible
,
3025 show_vid(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
3027 struct nct6775_data
*data
= dev_get_drvdata(dev
);
3029 return sprintf(buf
, "%d\n", vid_from_reg(data
->vid
, data
->vrm
));
3032 static DEVICE_ATTR(cpu0_vid
, S_IRUGO
, show_vid
, NULL
);
3034 /* Case open detection */
3037 clear_caseopen(struct device
*dev
, struct device_attribute
*attr
,
3038 const char *buf
, size_t count
)
3040 struct nct6775_data
*data
= dev_get_drvdata(dev
);
3041 int nr
= to_sensor_dev_attr(attr
)->index
- INTRUSION_ALARM_BASE
;
3046 if (kstrtoul(buf
, 10, &val
) || val
!= 0)
3049 mutex_lock(&data
->update_lock
);
3052 * Use CR registers to clear caseopen status.
3053 * The CR registers are the same for all chips, and not all chips
3054 * support clearing the caseopen status through "regular" registers.
3056 ret
= superio_enter(data
->sioreg
);
3062 superio_select(data
->sioreg
, NCT6775_LD_ACPI
);
3063 reg
= superio_inb(data
->sioreg
, NCT6775_REG_CR_CASEOPEN_CLR
[nr
]);
3064 reg
|= NCT6775_CR_CASEOPEN_CLR_MASK
[nr
];
3065 superio_outb(data
->sioreg
, NCT6775_REG_CR_CASEOPEN_CLR
[nr
], reg
);
3066 reg
&= ~NCT6775_CR_CASEOPEN_CLR_MASK
[nr
];
3067 superio_outb(data
->sioreg
, NCT6775_REG_CR_CASEOPEN_CLR
[nr
], reg
);
3068 superio_exit(data
->sioreg
);
3070 data
->valid
= false; /* Force cache refresh */
3072 mutex_unlock(&data
->update_lock
);
3076 static SENSOR_DEVICE_ATTR(intrusion0_alarm
, S_IWUSR
| S_IRUGO
, show_alarm
,
3077 clear_caseopen
, INTRUSION_ALARM_BASE
);
3078 static SENSOR_DEVICE_ATTR(intrusion1_alarm
, S_IWUSR
| S_IRUGO
, show_alarm
,
3079 clear_caseopen
, INTRUSION_ALARM_BASE
+ 1);
3080 static SENSOR_DEVICE_ATTR(intrusion0_beep
, S_IWUSR
| S_IRUGO
, show_beep
,
3081 store_beep
, INTRUSION_ALARM_BASE
);
3082 static SENSOR_DEVICE_ATTR(intrusion1_beep
, S_IWUSR
| S_IRUGO
, show_beep
,
3083 store_beep
, INTRUSION_ALARM_BASE
+ 1);
3084 static SENSOR_DEVICE_ATTR(beep_enable
, S_IWUSR
| S_IRUGO
, show_beep
,
3085 store_beep
, BEEP_ENABLE_BASE
);
3087 static umode_t
nct6775_other_is_visible(struct kobject
*kobj
,
3088 struct attribute
*attr
, int index
)
3090 struct device
*dev
= container_of(kobj
, struct device
, kobj
);
3091 struct nct6775_data
*data
= dev_get_drvdata(dev
);
3093 if (index
== 0 && !data
->have_vid
)
3096 if (index
== 1 || index
== 2) {
3097 if (data
->ALARM_BITS
[INTRUSION_ALARM_BASE
+ index
- 1] < 0)
3101 if (index
== 3 || index
== 4) {
3102 if (data
->BEEP_BITS
[INTRUSION_ALARM_BASE
+ index
- 3] < 0)
3110 * nct6775_other_is_visible uses the index into the following array
3111 * to determine if attributes should be created or not.
3112 * Any change in order or content must be matched.
3114 static struct attribute
*nct6775_attributes_other
[] = {
3115 &dev_attr_cpu0_vid
.attr
, /* 0 */
3116 &sensor_dev_attr_intrusion0_alarm
.dev_attr
.attr
, /* 1 */
3117 &sensor_dev_attr_intrusion1_alarm
.dev_attr
.attr
, /* 2 */
3118 &sensor_dev_attr_intrusion0_beep
.dev_attr
.attr
, /* 3 */
3119 &sensor_dev_attr_intrusion1_beep
.dev_attr
.attr
, /* 4 */
3120 &sensor_dev_attr_beep_enable
.dev_attr
.attr
, /* 5 */
3125 static const struct attribute_group nct6775_group_other
= {
3126 .attrs
= nct6775_attributes_other
,
3127 .is_visible
= nct6775_other_is_visible
,
3130 static inline void nct6775_init_device(struct nct6775_data
*data
)
3135 /* Start monitoring if needed */
3136 if (data
->REG_CONFIG
) {
3137 tmp
= nct6775_read_value(data
, data
->REG_CONFIG
);
3139 nct6775_write_value(data
, data
->REG_CONFIG
, tmp
| 0x01);
3142 /* Enable temperature sensors if needed */
3143 for (i
= 0; i
< NUM_TEMP
; i
++) {
3144 if (!(data
->have_temp
& (1 << i
)))
3146 if (!data
->reg_temp_config
[i
])
3148 tmp
= nct6775_read_value(data
, data
->reg_temp_config
[i
]);
3150 nct6775_write_value(data
, data
->reg_temp_config
[i
],
3154 /* Enable VBAT monitoring if needed */
3155 tmp
= nct6775_read_value(data
, data
->REG_VBAT
);
3157 nct6775_write_value(data
, data
->REG_VBAT
, tmp
| 0x01);
3159 diode
= nct6775_read_value(data
, data
->REG_DIODE
);
3161 for (i
= 0; i
< data
->temp_fixed_num
; i
++) {
3162 if (!(data
->have_temp_fixed
& (1 << i
)))
3164 if ((tmp
& (data
->DIODE_MASK
<< i
))) /* diode */
3166 = 3 - ((diode
>> i
) & data
->DIODE_MASK
);
3167 else /* thermistor */
3168 data
->temp_type
[i
] = 4;
3173 nct6775_check_fan_inputs(struct nct6775_data
*data
)
3175 bool fan3pin
, fan4pin
, fan4min
, fan5pin
, fan6pin
;
3176 bool pwm3pin
, pwm4pin
, pwm5pin
, pwm6pin
;
3177 int sioreg
= data
->sioreg
;
3180 /* fan4 and fan5 share some pins with the GPIO and serial flash */
3181 if (data
->kind
== nct6775
) {
3182 regval
= superio_inb(sioreg
, 0x2c);
3184 fan3pin
= regval
& (1 << 6);
3185 pwm3pin
= regval
& (1 << 7);
3187 /* On NCT6775, fan4 shares pins with the fdc interface */
3188 fan4pin
= !(superio_inb(sioreg
, 0x2A) & 0x80);
3195 } else if (data
->kind
== nct6776
) {
3196 bool gpok
= superio_inb(sioreg
, 0x27) & 0x80;
3198 superio_select(sioreg
, NCT6775_LD_HWM
);
3199 regval
= superio_inb(sioreg
, SIO_REG_ENABLE
);
3204 fan3pin
= !(superio_inb(sioreg
, 0x24) & 0x40);
3209 fan4pin
= superio_inb(sioreg
, 0x1C) & 0x01;
3214 fan5pin
= superio_inb(sioreg
, 0x1C) & 0x02;
3222 } else if (data
->kind
== nct6106
) {
3223 regval
= superio_inb(sioreg
, 0x24);
3224 fan3pin
= !(regval
& 0x80);
3225 pwm3pin
= regval
& 0x08;
3234 } else { /* NCT6779D, NCT6791D, or NCT6792D */
3235 regval
= superio_inb(sioreg
, 0x1c);
3237 fan3pin
= !(regval
& (1 << 5));
3238 fan4pin
= !(regval
& (1 << 6));
3239 fan5pin
= !(regval
& (1 << 7));
3241 pwm3pin
= !(regval
& (1 << 0));
3242 pwm4pin
= !(regval
& (1 << 1));
3243 pwm5pin
= !(regval
& (1 << 2));
3247 if (data
->kind
== nct6791
|| data
->kind
== nct6792
) {
3248 regval
= superio_inb(sioreg
, 0x2d);
3249 fan6pin
= (regval
& (1 << 1));
3250 pwm6pin
= (regval
& (1 << 0));
3251 } else { /* NCT6779D */
3257 /* fan 1 and 2 (0x03) are always present */
3258 data
->has_fan
= 0x03 | (fan3pin
<< 2) | (fan4pin
<< 3) |
3259 (fan5pin
<< 4) | (fan6pin
<< 5);
3260 data
->has_fan_min
= 0x03 | (fan3pin
<< 2) | (fan4min
<< 3) |
3262 data
->has_pwm
= 0x03 | (pwm3pin
<< 2) | (pwm4pin
<< 3) |
3263 (pwm5pin
<< 4) | (pwm6pin
<< 5);
3266 static void add_temp_sensors(struct nct6775_data
*data
, const u16
*regp
,
3267 int *available
, int *mask
)
3272 for (i
= 0; i
< data
->pwm_num
&& *available
; i
++) {
3277 src
= nct6775_read_value(data
, regp
[i
]);
3279 if (!src
|| (*mask
& (1 << src
)))
3281 if (src
>= data
->temp_label_num
||
3282 !strlen(data
->temp_label
[src
]))
3285 index
= __ffs(*available
);
3286 nct6775_write_value(data
, data
->REG_TEMP_SOURCE
[index
], src
);
3287 *available
&= ~(1 << index
);
3292 static int nct6775_probe(struct platform_device
*pdev
)
3294 struct device
*dev
= &pdev
->dev
;
3295 struct nct6775_sio_data
*sio_data
= dev_get_platdata(dev
);
3296 struct nct6775_data
*data
;
3297 struct resource
*res
;
3299 int src
, mask
, available
;
3300 const u16
*reg_temp
, *reg_temp_over
, *reg_temp_hyst
, *reg_temp_config
;
3301 const u16
*reg_temp_mon
, *reg_temp_alternate
, *reg_temp_crit
;
3302 const u16
*reg_temp_crit_l
= NULL
, *reg_temp_crit_h
= NULL
;
3303 int num_reg_temp
, num_reg_temp_mon
;
3305 struct attribute_group
*group
;
3306 struct device
*hwmon_dev
;
3307 int num_attr_groups
= 0;
3309 res
= platform_get_resource(pdev
, IORESOURCE_IO
, 0);
3310 if (!devm_request_region(&pdev
->dev
, res
->start
, IOREGION_LENGTH
,
3314 data
= devm_kzalloc(&pdev
->dev
, sizeof(struct nct6775_data
),
3319 data
->kind
= sio_data
->kind
;
3320 data
->sioreg
= sio_data
->sioreg
;
3321 data
->addr
= res
->start
;
3322 mutex_init(&data
->update_lock
);
3323 data
->name
= nct6775_device_names
[data
->kind
];
3324 data
->bank
= 0xff; /* Force initial bank selection */
3325 platform_set_drvdata(pdev
, data
);
3327 switch (data
->kind
) {
3331 data
->auto_pwm_num
= 4;
3332 data
->temp_fixed_num
= 3;
3333 data
->num_temp_alarms
= 6;
3334 data
->num_temp_beeps
= 6;
3336 data
->fan_from_reg
= fan_from_reg13
;
3337 data
->fan_from_reg_min
= fan_from_reg13
;
3339 data
->temp_label
= nct6776_temp_label
;
3340 data
->temp_label_num
= ARRAY_SIZE(nct6776_temp_label
);
3342 data
->REG_VBAT
= NCT6106_REG_VBAT
;
3343 data
->REG_DIODE
= NCT6106_REG_DIODE
;
3344 data
->DIODE_MASK
= NCT6106_DIODE_MASK
;
3345 data
->REG_VIN
= NCT6106_REG_IN
;
3346 data
->REG_IN_MINMAX
[0] = NCT6106_REG_IN_MIN
;
3347 data
->REG_IN_MINMAX
[1] = NCT6106_REG_IN_MAX
;
3348 data
->REG_TARGET
= NCT6106_REG_TARGET
;
3349 data
->REG_FAN
= NCT6106_REG_FAN
;
3350 data
->REG_FAN_MODE
= NCT6106_REG_FAN_MODE
;
3351 data
->REG_FAN_MIN
= NCT6106_REG_FAN_MIN
;
3352 data
->REG_FAN_PULSES
= NCT6106_REG_FAN_PULSES
;
3353 data
->FAN_PULSE_SHIFT
= NCT6106_FAN_PULSE_SHIFT
;
3354 data
->REG_FAN_TIME
[0] = NCT6106_REG_FAN_STOP_TIME
;
3355 data
->REG_FAN_TIME
[1] = NCT6106_REG_FAN_STEP_UP_TIME
;
3356 data
->REG_FAN_TIME
[2] = NCT6106_REG_FAN_STEP_DOWN_TIME
;
3357 data
->REG_PWM
[0] = NCT6106_REG_PWM
;
3358 data
->REG_PWM
[1] = NCT6106_REG_FAN_START_OUTPUT
;
3359 data
->REG_PWM
[2] = NCT6106_REG_FAN_STOP_OUTPUT
;
3360 data
->REG_PWM
[5] = NCT6106_REG_WEIGHT_DUTY_STEP
;
3361 data
->REG_PWM
[6] = NCT6106_REG_WEIGHT_DUTY_BASE
;
3362 data
->REG_PWM_READ
= NCT6106_REG_PWM_READ
;
3363 data
->REG_PWM_MODE
= NCT6106_REG_PWM_MODE
;
3364 data
->PWM_MODE_MASK
= NCT6106_PWM_MODE_MASK
;
3365 data
->REG_AUTO_TEMP
= NCT6106_REG_AUTO_TEMP
;
3366 data
->REG_AUTO_PWM
= NCT6106_REG_AUTO_PWM
;
3367 data
->REG_CRITICAL_TEMP
= NCT6106_REG_CRITICAL_TEMP
;
3368 data
->REG_CRITICAL_TEMP_TOLERANCE
3369 = NCT6106_REG_CRITICAL_TEMP_TOLERANCE
;
3370 data
->REG_CRITICAL_PWM_ENABLE
= NCT6106_REG_CRITICAL_PWM_ENABLE
;
3371 data
->CRITICAL_PWM_ENABLE_MASK
3372 = NCT6106_CRITICAL_PWM_ENABLE_MASK
;
3373 data
->REG_CRITICAL_PWM
= NCT6106_REG_CRITICAL_PWM
;
3374 data
->REG_TEMP_OFFSET
= NCT6106_REG_TEMP_OFFSET
;
3375 data
->REG_TEMP_SOURCE
= NCT6106_REG_TEMP_SOURCE
;
3376 data
->REG_TEMP_SEL
= NCT6106_REG_TEMP_SEL
;
3377 data
->REG_WEIGHT_TEMP_SEL
= NCT6106_REG_WEIGHT_TEMP_SEL
;
3378 data
->REG_WEIGHT_TEMP
[0] = NCT6106_REG_WEIGHT_TEMP_STEP
;
3379 data
->REG_WEIGHT_TEMP
[1] = NCT6106_REG_WEIGHT_TEMP_STEP_TOL
;
3380 data
->REG_WEIGHT_TEMP
[2] = NCT6106_REG_WEIGHT_TEMP_BASE
;
3381 data
->REG_ALARM
= NCT6106_REG_ALARM
;
3382 data
->ALARM_BITS
= NCT6106_ALARM_BITS
;
3383 data
->REG_BEEP
= NCT6106_REG_BEEP
;
3384 data
->BEEP_BITS
= NCT6106_BEEP_BITS
;
3386 reg_temp
= NCT6106_REG_TEMP
;
3387 reg_temp_mon
= NCT6106_REG_TEMP_MON
;
3388 num_reg_temp
= ARRAY_SIZE(NCT6106_REG_TEMP
);
3389 num_reg_temp_mon
= ARRAY_SIZE(NCT6106_REG_TEMP_MON
);
3390 reg_temp_over
= NCT6106_REG_TEMP_OVER
;
3391 reg_temp_hyst
= NCT6106_REG_TEMP_HYST
;
3392 reg_temp_config
= NCT6106_REG_TEMP_CONFIG
;
3393 reg_temp_alternate
= NCT6106_REG_TEMP_ALTERNATE
;
3394 reg_temp_crit
= NCT6106_REG_TEMP_CRIT
;
3395 reg_temp_crit_l
= NCT6106_REG_TEMP_CRIT_L
;
3396 reg_temp_crit_h
= NCT6106_REG_TEMP_CRIT_H
;
3402 data
->auto_pwm_num
= 6;
3403 data
->has_fan_div
= true;
3404 data
->temp_fixed_num
= 3;
3405 data
->num_temp_alarms
= 3;
3406 data
->num_temp_beeps
= 3;
3408 data
->ALARM_BITS
= NCT6775_ALARM_BITS
;
3409 data
->BEEP_BITS
= NCT6775_BEEP_BITS
;
3411 data
->fan_from_reg
= fan_from_reg16
;
3412 data
->fan_from_reg_min
= fan_from_reg8
;
3413 data
->target_temp_mask
= 0x7f;
3414 data
->tolerance_mask
= 0x0f;
3415 data
->speed_tolerance_limit
= 15;
3417 data
->temp_label
= nct6775_temp_label
;
3418 data
->temp_label_num
= ARRAY_SIZE(nct6775_temp_label
);
3420 data
->REG_CONFIG
= NCT6775_REG_CONFIG
;
3421 data
->REG_VBAT
= NCT6775_REG_VBAT
;
3422 data
->REG_DIODE
= NCT6775_REG_DIODE
;
3423 data
->DIODE_MASK
= NCT6775_DIODE_MASK
;
3424 data
->REG_VIN
= NCT6775_REG_IN
;
3425 data
->REG_IN_MINMAX
[0] = NCT6775_REG_IN_MIN
;
3426 data
->REG_IN_MINMAX
[1] = NCT6775_REG_IN_MAX
;
3427 data
->REG_TARGET
= NCT6775_REG_TARGET
;
3428 data
->REG_FAN
= NCT6775_REG_FAN
;
3429 data
->REG_FAN_MODE
= NCT6775_REG_FAN_MODE
;
3430 data
->REG_FAN_MIN
= NCT6775_REG_FAN_MIN
;
3431 data
->REG_FAN_PULSES
= NCT6775_REG_FAN_PULSES
;
3432 data
->FAN_PULSE_SHIFT
= NCT6775_FAN_PULSE_SHIFT
;
3433 data
->REG_FAN_TIME
[0] = NCT6775_REG_FAN_STOP_TIME
;
3434 data
->REG_FAN_TIME
[1] = NCT6775_REG_FAN_STEP_UP_TIME
;
3435 data
->REG_FAN_TIME
[2] = NCT6775_REG_FAN_STEP_DOWN_TIME
;
3436 data
->REG_PWM
[0] = NCT6775_REG_PWM
;
3437 data
->REG_PWM
[1] = NCT6775_REG_FAN_START_OUTPUT
;
3438 data
->REG_PWM
[2] = NCT6775_REG_FAN_STOP_OUTPUT
;
3439 data
->REG_PWM
[3] = NCT6775_REG_FAN_MAX_OUTPUT
;
3440 data
->REG_PWM
[4] = NCT6775_REG_FAN_STEP_OUTPUT
;
3441 data
->REG_PWM
[5] = NCT6775_REG_WEIGHT_DUTY_STEP
;
3442 data
->REG_PWM_READ
= NCT6775_REG_PWM_READ
;
3443 data
->REG_PWM_MODE
= NCT6775_REG_PWM_MODE
;
3444 data
->PWM_MODE_MASK
= NCT6775_PWM_MODE_MASK
;
3445 data
->REG_AUTO_TEMP
= NCT6775_REG_AUTO_TEMP
;
3446 data
->REG_AUTO_PWM
= NCT6775_REG_AUTO_PWM
;
3447 data
->REG_CRITICAL_TEMP
= NCT6775_REG_CRITICAL_TEMP
;
3448 data
->REG_CRITICAL_TEMP_TOLERANCE
3449 = NCT6775_REG_CRITICAL_TEMP_TOLERANCE
;
3450 data
->REG_TEMP_OFFSET
= NCT6775_REG_TEMP_OFFSET
;
3451 data
->REG_TEMP_SOURCE
= NCT6775_REG_TEMP_SOURCE
;
3452 data
->REG_TEMP_SEL
= NCT6775_REG_TEMP_SEL
;
3453 data
->REG_WEIGHT_TEMP_SEL
= NCT6775_REG_WEIGHT_TEMP_SEL
;
3454 data
->REG_WEIGHT_TEMP
[0] = NCT6775_REG_WEIGHT_TEMP_STEP
;
3455 data
->REG_WEIGHT_TEMP
[1] = NCT6775_REG_WEIGHT_TEMP_STEP_TOL
;
3456 data
->REG_WEIGHT_TEMP
[2] = NCT6775_REG_WEIGHT_TEMP_BASE
;
3457 data
->REG_ALARM
= NCT6775_REG_ALARM
;
3458 data
->REG_BEEP
= NCT6775_REG_BEEP
;
3460 reg_temp
= NCT6775_REG_TEMP
;
3461 reg_temp_mon
= NCT6775_REG_TEMP_MON
;
3462 num_reg_temp
= ARRAY_SIZE(NCT6775_REG_TEMP
);
3463 num_reg_temp_mon
= ARRAY_SIZE(NCT6775_REG_TEMP_MON
);
3464 reg_temp_over
= NCT6775_REG_TEMP_OVER
;
3465 reg_temp_hyst
= NCT6775_REG_TEMP_HYST
;
3466 reg_temp_config
= NCT6775_REG_TEMP_CONFIG
;
3467 reg_temp_alternate
= NCT6775_REG_TEMP_ALTERNATE
;
3468 reg_temp_crit
= NCT6775_REG_TEMP_CRIT
;
3474 data
->auto_pwm_num
= 4;
3475 data
->has_fan_div
= false;
3476 data
->temp_fixed_num
= 3;
3477 data
->num_temp_alarms
= 3;
3478 data
->num_temp_beeps
= 6;
3480 data
->ALARM_BITS
= NCT6776_ALARM_BITS
;
3481 data
->BEEP_BITS
= NCT6776_BEEP_BITS
;
3483 data
->fan_from_reg
= fan_from_reg13
;
3484 data
->fan_from_reg_min
= fan_from_reg13
;
3485 data
->target_temp_mask
= 0xff;
3486 data
->tolerance_mask
= 0x07;
3487 data
->speed_tolerance_limit
= 63;
3489 data
->temp_label
= nct6776_temp_label
;
3490 data
->temp_label_num
= ARRAY_SIZE(nct6776_temp_label
);
3492 data
->REG_CONFIG
= NCT6775_REG_CONFIG
;
3493 data
->REG_VBAT
= NCT6775_REG_VBAT
;
3494 data
->REG_DIODE
= NCT6775_REG_DIODE
;
3495 data
->DIODE_MASK
= NCT6775_DIODE_MASK
;
3496 data
->REG_VIN
= NCT6775_REG_IN
;
3497 data
->REG_IN_MINMAX
[0] = NCT6775_REG_IN_MIN
;
3498 data
->REG_IN_MINMAX
[1] = NCT6775_REG_IN_MAX
;
3499 data
->REG_TARGET
= NCT6775_REG_TARGET
;
3500 data
->REG_FAN
= NCT6775_REG_FAN
;
3501 data
->REG_FAN_MODE
= NCT6775_REG_FAN_MODE
;
3502 data
->REG_FAN_MIN
= NCT6776_REG_FAN_MIN
;
3503 data
->REG_FAN_PULSES
= NCT6776_REG_FAN_PULSES
;
3504 data
->FAN_PULSE_SHIFT
= NCT6775_FAN_PULSE_SHIFT
;
3505 data
->REG_FAN_TIME
[0] = NCT6775_REG_FAN_STOP_TIME
;
3506 data
->REG_FAN_TIME
[1] = NCT6775_REG_FAN_STEP_UP_TIME
;
3507 data
->REG_FAN_TIME
[2] = NCT6775_REG_FAN_STEP_DOWN_TIME
;
3508 data
->REG_TOLERANCE_H
= NCT6776_REG_TOLERANCE_H
;
3509 data
->REG_PWM
[0] = NCT6775_REG_PWM
;
3510 data
->REG_PWM
[1] = NCT6775_REG_FAN_START_OUTPUT
;
3511 data
->REG_PWM
[2] = NCT6775_REG_FAN_STOP_OUTPUT
;
3512 data
->REG_PWM
[5] = NCT6775_REG_WEIGHT_DUTY_STEP
;
3513 data
->REG_PWM
[6] = NCT6776_REG_WEIGHT_DUTY_BASE
;
3514 data
->REG_PWM_READ
= NCT6775_REG_PWM_READ
;
3515 data
->REG_PWM_MODE
= NCT6776_REG_PWM_MODE
;
3516 data
->PWM_MODE_MASK
= NCT6776_PWM_MODE_MASK
;
3517 data
->REG_AUTO_TEMP
= NCT6775_REG_AUTO_TEMP
;
3518 data
->REG_AUTO_PWM
= NCT6775_REG_AUTO_PWM
;
3519 data
->REG_CRITICAL_TEMP
= NCT6775_REG_CRITICAL_TEMP
;
3520 data
->REG_CRITICAL_TEMP_TOLERANCE
3521 = NCT6775_REG_CRITICAL_TEMP_TOLERANCE
;
3522 data
->REG_TEMP_OFFSET
= NCT6775_REG_TEMP_OFFSET
;
3523 data
->REG_TEMP_SOURCE
= NCT6775_REG_TEMP_SOURCE
;
3524 data
->REG_TEMP_SEL
= NCT6775_REG_TEMP_SEL
;
3525 data
->REG_WEIGHT_TEMP_SEL
= NCT6775_REG_WEIGHT_TEMP_SEL
;
3526 data
->REG_WEIGHT_TEMP
[0] = NCT6775_REG_WEIGHT_TEMP_STEP
;
3527 data
->REG_WEIGHT_TEMP
[1] = NCT6775_REG_WEIGHT_TEMP_STEP_TOL
;
3528 data
->REG_WEIGHT_TEMP
[2] = NCT6775_REG_WEIGHT_TEMP_BASE
;
3529 data
->REG_ALARM
= NCT6775_REG_ALARM
;
3530 data
->REG_BEEP
= NCT6776_REG_BEEP
;
3532 reg_temp
= NCT6775_REG_TEMP
;
3533 reg_temp_mon
= NCT6775_REG_TEMP_MON
;
3534 num_reg_temp
= ARRAY_SIZE(NCT6775_REG_TEMP
);
3535 num_reg_temp_mon
= ARRAY_SIZE(NCT6775_REG_TEMP_MON
);
3536 reg_temp_over
= NCT6775_REG_TEMP_OVER
;
3537 reg_temp_hyst
= NCT6775_REG_TEMP_HYST
;
3538 reg_temp_config
= NCT6776_REG_TEMP_CONFIG
;
3539 reg_temp_alternate
= NCT6776_REG_TEMP_ALTERNATE
;
3540 reg_temp_crit
= NCT6776_REG_TEMP_CRIT
;
3546 data
->auto_pwm_num
= 4;
3547 data
->has_fan_div
= false;
3548 data
->temp_fixed_num
= 6;
3549 data
->num_temp_alarms
= 2;
3550 data
->num_temp_beeps
= 2;
3552 data
->ALARM_BITS
= NCT6779_ALARM_BITS
;
3553 data
->BEEP_BITS
= NCT6779_BEEP_BITS
;
3555 data
->fan_from_reg
= fan_from_reg13
;
3556 data
->fan_from_reg_min
= fan_from_reg13
;
3557 data
->target_temp_mask
= 0xff;
3558 data
->tolerance_mask
= 0x07;
3559 data
->speed_tolerance_limit
= 63;
3561 data
->temp_label
= nct6779_temp_label
;
3562 data
->temp_label_num
= ARRAY_SIZE(nct6779_temp_label
);
3564 data
->REG_CONFIG
= NCT6775_REG_CONFIG
;
3565 data
->REG_VBAT
= NCT6775_REG_VBAT
;
3566 data
->REG_DIODE
= NCT6775_REG_DIODE
;
3567 data
->DIODE_MASK
= NCT6775_DIODE_MASK
;
3568 data
->REG_VIN
= NCT6779_REG_IN
;
3569 data
->REG_IN_MINMAX
[0] = NCT6775_REG_IN_MIN
;
3570 data
->REG_IN_MINMAX
[1] = NCT6775_REG_IN_MAX
;
3571 data
->REG_TARGET
= NCT6775_REG_TARGET
;
3572 data
->REG_FAN
= NCT6779_REG_FAN
;
3573 data
->REG_FAN_MODE
= NCT6775_REG_FAN_MODE
;
3574 data
->REG_FAN_MIN
= NCT6776_REG_FAN_MIN
;
3575 data
->REG_FAN_PULSES
= NCT6779_REG_FAN_PULSES
;
3576 data
->FAN_PULSE_SHIFT
= NCT6775_FAN_PULSE_SHIFT
;
3577 data
->REG_FAN_TIME
[0] = NCT6775_REG_FAN_STOP_TIME
;
3578 data
->REG_FAN_TIME
[1] = NCT6775_REG_FAN_STEP_UP_TIME
;
3579 data
->REG_FAN_TIME
[2] = NCT6775_REG_FAN_STEP_DOWN_TIME
;
3580 data
->REG_TOLERANCE_H
= NCT6776_REG_TOLERANCE_H
;
3581 data
->REG_PWM
[0] = NCT6775_REG_PWM
;
3582 data
->REG_PWM
[1] = NCT6775_REG_FAN_START_OUTPUT
;
3583 data
->REG_PWM
[2] = NCT6775_REG_FAN_STOP_OUTPUT
;
3584 data
->REG_PWM
[5] = NCT6775_REG_WEIGHT_DUTY_STEP
;
3585 data
->REG_PWM
[6] = NCT6776_REG_WEIGHT_DUTY_BASE
;
3586 data
->REG_PWM_READ
= NCT6775_REG_PWM_READ
;
3587 data
->REG_PWM_MODE
= NCT6776_REG_PWM_MODE
;
3588 data
->PWM_MODE_MASK
= NCT6776_PWM_MODE_MASK
;
3589 data
->REG_AUTO_TEMP
= NCT6775_REG_AUTO_TEMP
;
3590 data
->REG_AUTO_PWM
= NCT6775_REG_AUTO_PWM
;
3591 data
->REG_CRITICAL_TEMP
= NCT6775_REG_CRITICAL_TEMP
;
3592 data
->REG_CRITICAL_TEMP_TOLERANCE
3593 = NCT6775_REG_CRITICAL_TEMP_TOLERANCE
;
3594 data
->REG_CRITICAL_PWM_ENABLE
= NCT6779_REG_CRITICAL_PWM_ENABLE
;
3595 data
->CRITICAL_PWM_ENABLE_MASK
3596 = NCT6779_CRITICAL_PWM_ENABLE_MASK
;
3597 data
->REG_CRITICAL_PWM
= NCT6779_REG_CRITICAL_PWM
;
3598 data
->REG_TEMP_OFFSET
= NCT6779_REG_TEMP_OFFSET
;
3599 data
->REG_TEMP_SOURCE
= NCT6775_REG_TEMP_SOURCE
;
3600 data
->REG_TEMP_SEL
= NCT6775_REG_TEMP_SEL
;
3601 data
->REG_WEIGHT_TEMP_SEL
= NCT6775_REG_WEIGHT_TEMP_SEL
;
3602 data
->REG_WEIGHT_TEMP
[0] = NCT6775_REG_WEIGHT_TEMP_STEP
;
3603 data
->REG_WEIGHT_TEMP
[1] = NCT6775_REG_WEIGHT_TEMP_STEP_TOL
;
3604 data
->REG_WEIGHT_TEMP
[2] = NCT6775_REG_WEIGHT_TEMP_BASE
;
3605 data
->REG_ALARM
= NCT6779_REG_ALARM
;
3606 data
->REG_BEEP
= NCT6776_REG_BEEP
;
3608 reg_temp
= NCT6779_REG_TEMP
;
3609 reg_temp_mon
= NCT6779_REG_TEMP_MON
;
3610 num_reg_temp
= ARRAY_SIZE(NCT6779_REG_TEMP
);
3611 num_reg_temp_mon
= ARRAY_SIZE(NCT6779_REG_TEMP_MON
);
3612 reg_temp_over
= NCT6779_REG_TEMP_OVER
;
3613 reg_temp_hyst
= NCT6779_REG_TEMP_HYST
;
3614 reg_temp_config
= NCT6779_REG_TEMP_CONFIG
;
3615 reg_temp_alternate
= NCT6779_REG_TEMP_ALTERNATE
;
3616 reg_temp_crit
= NCT6779_REG_TEMP_CRIT
;
3623 data
->auto_pwm_num
= 4;
3624 data
->has_fan_div
= false;
3625 data
->temp_fixed_num
= 6;
3626 data
->num_temp_alarms
= 2;
3627 data
->num_temp_beeps
= 2;
3629 data
->ALARM_BITS
= NCT6791_ALARM_BITS
;
3630 data
->BEEP_BITS
= NCT6779_BEEP_BITS
;
3632 data
->fan_from_reg
= fan_from_reg13
;
3633 data
->fan_from_reg_min
= fan_from_reg13
;
3634 data
->target_temp_mask
= 0xff;
3635 data
->tolerance_mask
= 0x07;
3636 data
->speed_tolerance_limit
= 63;
3638 data
->temp_label
= nct6779_temp_label
;
3639 data
->temp_label_num
= ARRAY_SIZE(nct6779_temp_label
);
3641 data
->REG_CONFIG
= NCT6775_REG_CONFIG
;
3642 data
->REG_VBAT
= NCT6775_REG_VBAT
;
3643 data
->REG_DIODE
= NCT6775_REG_DIODE
;
3644 data
->DIODE_MASK
= NCT6775_DIODE_MASK
;
3645 data
->REG_VIN
= NCT6779_REG_IN
;
3646 data
->REG_IN_MINMAX
[0] = NCT6775_REG_IN_MIN
;
3647 data
->REG_IN_MINMAX
[1] = NCT6775_REG_IN_MAX
;
3648 data
->REG_TARGET
= NCT6775_REG_TARGET
;
3649 data
->REG_FAN
= NCT6779_REG_FAN
;
3650 data
->REG_FAN_MODE
= NCT6775_REG_FAN_MODE
;
3651 data
->REG_FAN_MIN
= NCT6776_REG_FAN_MIN
;
3652 data
->REG_FAN_PULSES
= NCT6779_REG_FAN_PULSES
;
3653 data
->FAN_PULSE_SHIFT
= NCT6775_FAN_PULSE_SHIFT
;
3654 data
->REG_FAN_TIME
[0] = NCT6775_REG_FAN_STOP_TIME
;
3655 data
->REG_FAN_TIME
[1] = NCT6775_REG_FAN_STEP_UP_TIME
;
3656 data
->REG_FAN_TIME
[2] = NCT6775_REG_FAN_STEP_DOWN_TIME
;
3657 data
->REG_TOLERANCE_H
= NCT6776_REG_TOLERANCE_H
;
3658 data
->REG_PWM
[0] = NCT6775_REG_PWM
;
3659 data
->REG_PWM
[1] = NCT6775_REG_FAN_START_OUTPUT
;
3660 data
->REG_PWM
[2] = NCT6775_REG_FAN_STOP_OUTPUT
;
3661 data
->REG_PWM
[5] = NCT6791_REG_WEIGHT_DUTY_STEP
;
3662 data
->REG_PWM
[6] = NCT6791_REG_WEIGHT_DUTY_BASE
;
3663 data
->REG_PWM_READ
= NCT6775_REG_PWM_READ
;
3664 data
->REG_PWM_MODE
= NCT6776_REG_PWM_MODE
;
3665 data
->PWM_MODE_MASK
= NCT6776_PWM_MODE_MASK
;
3666 data
->REG_AUTO_TEMP
= NCT6775_REG_AUTO_TEMP
;
3667 data
->REG_AUTO_PWM
= NCT6775_REG_AUTO_PWM
;
3668 data
->REG_CRITICAL_TEMP
= NCT6775_REG_CRITICAL_TEMP
;
3669 data
->REG_CRITICAL_TEMP_TOLERANCE
3670 = NCT6775_REG_CRITICAL_TEMP_TOLERANCE
;
3671 data
->REG_CRITICAL_PWM_ENABLE
= NCT6779_REG_CRITICAL_PWM_ENABLE
;
3672 data
->CRITICAL_PWM_ENABLE_MASK
3673 = NCT6779_CRITICAL_PWM_ENABLE_MASK
;
3674 data
->REG_CRITICAL_PWM
= NCT6779_REG_CRITICAL_PWM
;
3675 data
->REG_TEMP_OFFSET
= NCT6779_REG_TEMP_OFFSET
;
3676 data
->REG_TEMP_SOURCE
= NCT6775_REG_TEMP_SOURCE
;
3677 data
->REG_TEMP_SEL
= NCT6775_REG_TEMP_SEL
;
3678 data
->REG_WEIGHT_TEMP_SEL
= NCT6791_REG_WEIGHT_TEMP_SEL
;
3679 data
->REG_WEIGHT_TEMP
[0] = NCT6791_REG_WEIGHT_TEMP_STEP
;
3680 data
->REG_WEIGHT_TEMP
[1] = NCT6791_REG_WEIGHT_TEMP_STEP_TOL
;
3681 data
->REG_WEIGHT_TEMP
[2] = NCT6791_REG_WEIGHT_TEMP_BASE
;
3682 data
->REG_ALARM
= NCT6791_REG_ALARM
;
3683 if (data
->kind
== nct6791
)
3684 data
->REG_BEEP
= NCT6776_REG_BEEP
;
3686 data
->REG_BEEP
= NCT6792_REG_BEEP
;
3688 reg_temp
= NCT6779_REG_TEMP
;
3689 num_reg_temp
= ARRAY_SIZE(NCT6779_REG_TEMP
);
3690 if (data
->kind
== nct6791
) {
3691 reg_temp_mon
= NCT6779_REG_TEMP_MON
;
3692 num_reg_temp_mon
= ARRAY_SIZE(NCT6779_REG_TEMP_MON
);
3694 reg_temp_mon
= NCT6792_REG_TEMP_MON
;
3695 num_reg_temp_mon
= ARRAY_SIZE(NCT6792_REG_TEMP_MON
);
3697 reg_temp_over
= NCT6779_REG_TEMP_OVER
;
3698 reg_temp_hyst
= NCT6779_REG_TEMP_HYST
;
3699 reg_temp_config
= NCT6779_REG_TEMP_CONFIG
;
3700 reg_temp_alternate
= NCT6779_REG_TEMP_ALTERNATE
;
3701 reg_temp_crit
= NCT6779_REG_TEMP_CRIT
;
3707 data
->have_in
= (1 << data
->in_num
) - 1;
3708 data
->have_temp
= 0;
3711 * On some boards, not all available temperature sources are monitored,
3712 * even though some of the monitoring registers are unused.
3713 * Get list of unused monitoring registers, then detect if any fan
3714 * controls are configured to use unmonitored temperature sources.
3715 * If so, assign the unmonitored temperature sources to available
3716 * monitoring registers.
3720 for (i
= 0; i
< num_reg_temp
; i
++) {
3721 if (reg_temp
[i
] == 0)
3724 src
= nct6775_read_value(data
, data
->REG_TEMP_SOURCE
[i
]) & 0x1f;
3725 if (!src
|| (mask
& (1 << src
)))
3726 available
|= 1 << i
;
3732 * Now find unmonitored temperature registers and enable monitoring
3733 * if additional monitoring registers are available.
3735 add_temp_sensors(data
, data
->REG_TEMP_SEL
, &available
, &mask
);
3736 add_temp_sensors(data
, data
->REG_WEIGHT_TEMP_SEL
, &available
, &mask
);
3739 s
= NUM_TEMP_FIXED
; /* First dynamic temperature attribute */
3740 for (i
= 0; i
< num_reg_temp
; i
++) {
3741 if (reg_temp
[i
] == 0)
3744 src
= nct6775_read_value(data
, data
->REG_TEMP_SOURCE
[i
]) & 0x1f;
3745 if (!src
|| (mask
& (1 << src
)))
3748 if (src
>= data
->temp_label_num
||
3749 !strlen(data
->temp_label
[src
])) {
3751 "Invalid temperature source %d at index %d, source register 0x%x, temp register 0x%x\n",
3752 src
, i
, data
->REG_TEMP_SOURCE
[i
], reg_temp
[i
]);
3758 /* Use fixed index for SYSTIN(1), CPUTIN(2), AUXTIN(3) */
3759 if (src
<= data
->temp_fixed_num
) {
3760 data
->have_temp
|= 1 << (src
- 1);
3761 data
->have_temp_fixed
|= 1 << (src
- 1);
3762 data
->reg_temp
[0][src
- 1] = reg_temp
[i
];
3763 data
->reg_temp
[1][src
- 1] = reg_temp_over
[i
];
3764 data
->reg_temp
[2][src
- 1] = reg_temp_hyst
[i
];
3765 if (reg_temp_crit_h
&& reg_temp_crit_h
[i
])
3766 data
->reg_temp
[3][src
- 1] = reg_temp_crit_h
[i
];
3767 else if (reg_temp_crit
[src
- 1])
3768 data
->reg_temp
[3][src
- 1]
3769 = reg_temp_crit
[src
- 1];
3770 if (reg_temp_crit_l
&& reg_temp_crit_l
[i
])
3771 data
->reg_temp
[4][src
- 1] = reg_temp_crit_l
[i
];
3772 data
->reg_temp_config
[src
- 1] = reg_temp_config
[i
];
3773 data
->temp_src
[src
- 1] = src
;
3780 /* Use dynamic index for other sources */
3781 data
->have_temp
|= 1 << s
;
3782 data
->reg_temp
[0][s
] = reg_temp
[i
];
3783 data
->reg_temp
[1][s
] = reg_temp_over
[i
];
3784 data
->reg_temp
[2][s
] = reg_temp_hyst
[i
];
3785 data
->reg_temp_config
[s
] = reg_temp_config
[i
];
3786 if (reg_temp_crit_h
&& reg_temp_crit_h
[i
])
3787 data
->reg_temp
[3][s
] = reg_temp_crit_h
[i
];
3788 else if (reg_temp_crit
[src
- 1])
3789 data
->reg_temp
[3][s
] = reg_temp_crit
[src
- 1];
3790 if (reg_temp_crit_l
&& reg_temp_crit_l
[i
])
3791 data
->reg_temp
[4][s
] = reg_temp_crit_l
[i
];
3793 data
->temp_src
[s
] = src
;
3798 * Repeat with temperatures used for fan control.
3799 * This set of registers does not support limits.
3801 for (i
= 0; i
< num_reg_temp_mon
; i
++) {
3802 if (reg_temp_mon
[i
] == 0)
3805 src
= nct6775_read_value(data
, data
->REG_TEMP_SEL
[i
]) & 0x1f;
3806 if (!src
|| (mask
& (1 << src
)))
3809 if (src
>= data
->temp_label_num
||
3810 !strlen(data
->temp_label
[src
])) {
3812 "Invalid temperature source %d at index %d, source register 0x%x, temp register 0x%x\n",
3813 src
, i
, data
->REG_TEMP_SEL
[i
],
3820 /* Use fixed index for SYSTIN(1), CPUTIN(2), AUXTIN(3) */
3821 if (src
<= data
->temp_fixed_num
) {
3822 if (data
->have_temp
& (1 << (src
- 1)))
3824 data
->have_temp
|= 1 << (src
- 1);
3825 data
->have_temp_fixed
|= 1 << (src
- 1);
3826 data
->reg_temp
[0][src
- 1] = reg_temp_mon
[i
];
3827 data
->temp_src
[src
- 1] = src
;
3834 /* Use dynamic index for other sources */
3835 data
->have_temp
|= 1 << s
;
3836 data
->reg_temp
[0][s
] = reg_temp_mon
[i
];
3837 data
->temp_src
[s
] = src
;
3841 #ifdef USE_ALTERNATE
3843 * Go through the list of alternate temp registers and enable
3845 * The temperature is already monitored if the respective bit in <mask>
3848 for (i
= 0; i
< data
->temp_label_num
- 1; i
++) {
3849 if (!reg_temp_alternate
[i
])
3851 if (mask
& (1 << (i
+ 1)))
3853 if (i
< data
->temp_fixed_num
) {
3854 if (data
->have_temp
& (1 << i
))
3856 data
->have_temp
|= 1 << i
;
3857 data
->have_temp_fixed
|= 1 << i
;
3858 data
->reg_temp
[0][i
] = reg_temp_alternate
[i
];
3859 if (i
< num_reg_temp
) {
3860 data
->reg_temp
[1][i
] = reg_temp_over
[i
];
3861 data
->reg_temp
[2][i
] = reg_temp_hyst
[i
];
3863 data
->temp_src
[i
] = i
+ 1;
3867 if (s
>= NUM_TEMP
) /* Abort if no more space */
3870 data
->have_temp
|= 1 << s
;
3871 data
->reg_temp
[0][s
] = reg_temp_alternate
[i
];
3872 data
->temp_src
[s
] = i
+ 1;
3875 #endif /* USE_ALTERNATE */
3877 /* Initialize the chip */
3878 nct6775_init_device(data
);
3880 err
= superio_enter(sio_data
->sioreg
);
3884 cr2a
= superio_inb(sio_data
->sioreg
, 0x2a);
3885 switch (data
->kind
) {
3887 data
->have_vid
= (cr2a
& 0x40);
3890 data
->have_vid
= (cr2a
& 0x60) == 0x40;
3901 * We can get the VID input values directly at logical device D 0xe3.
3903 if (data
->have_vid
) {
3904 superio_select(sio_data
->sioreg
, NCT6775_LD_VID
);
3905 data
->vid
= superio_inb(sio_data
->sioreg
, 0xe3);
3906 data
->vrm
= vid_which_vrm();
3912 superio_select(sio_data
->sioreg
, NCT6775_LD_HWM
);
3913 tmp
= superio_inb(sio_data
->sioreg
,
3914 NCT6775_REG_CR_FAN_DEBOUNCE
);
3915 switch (data
->kind
) {
3931 superio_outb(sio_data
->sioreg
, NCT6775_REG_CR_FAN_DEBOUNCE
,
3933 dev_info(&pdev
->dev
, "Enabled fan debounce for chip %s\n",
3937 nct6775_check_fan_inputs(data
);
3939 superio_exit(sio_data
->sioreg
);
3941 /* Read fan clock dividers immediately */
3942 nct6775_init_fan_common(dev
, data
);
3944 /* Register sysfs hooks */
3945 group
= nct6775_create_attr_group(dev
, &nct6775_pwm_template_group
,
3948 return PTR_ERR(group
);
3950 data
->groups
[num_attr_groups
++] = group
;
3952 group
= nct6775_create_attr_group(dev
, &nct6775_in_template_group
,
3953 fls(data
->have_in
));
3955 return PTR_ERR(group
);
3957 data
->groups
[num_attr_groups
++] = group
;
3959 group
= nct6775_create_attr_group(dev
, &nct6775_fan_template_group
,
3960 fls(data
->has_fan
));
3962 return PTR_ERR(group
);
3964 data
->groups
[num_attr_groups
++] = group
;
3966 group
= nct6775_create_attr_group(dev
, &nct6775_temp_template_group
,
3967 fls(data
->have_temp
));
3969 return PTR_ERR(group
);
3971 data
->groups
[num_attr_groups
++] = group
;
3972 data
->groups
[num_attr_groups
++] = &nct6775_group_other
;
3974 hwmon_dev
= devm_hwmon_device_register_with_groups(dev
, data
->name
,
3975 data
, data
->groups
);
3976 return PTR_ERR_OR_ZERO(hwmon_dev
);
3979 static void nct6791_enable_io_mapping(int sioaddr
)
3983 val
= superio_inb(sioaddr
, NCT6791_REG_HM_IO_SPACE_LOCK_ENABLE
);
3985 pr_info("Enabling hardware monitor logical device mappings.\n");
3986 superio_outb(sioaddr
, NCT6791_REG_HM_IO_SPACE_LOCK_ENABLE
,
3991 static int __maybe_unused
nct6775_suspend(struct device
*dev
)
3993 struct nct6775_data
*data
= nct6775_update_device(dev
);
3995 mutex_lock(&data
->update_lock
);
3996 data
->vbat
= nct6775_read_value(data
, data
->REG_VBAT
);
3997 if (data
->kind
== nct6775
) {
3998 data
->fandiv1
= nct6775_read_value(data
, NCT6775_REG_FANDIV1
);
3999 data
->fandiv2
= nct6775_read_value(data
, NCT6775_REG_FANDIV2
);
4001 mutex_unlock(&data
->update_lock
);
4006 static int __maybe_unused
nct6775_resume(struct device
*dev
)
4008 struct nct6775_data
*data
= dev_get_drvdata(dev
);
4011 mutex_lock(&data
->update_lock
);
4012 data
->bank
= 0xff; /* Force initial bank selection */
4014 if (data
->kind
== nct6791
|| data
->kind
== nct6792
) {
4015 err
= superio_enter(data
->sioreg
);
4019 nct6791_enable_io_mapping(data
->sioreg
);
4020 superio_exit(data
->sioreg
);
4023 /* Restore limits */
4024 for (i
= 0; i
< data
->in_num
; i
++) {
4025 if (!(data
->have_in
& (1 << i
)))
4028 nct6775_write_value(data
, data
->REG_IN_MINMAX
[0][i
],
4030 nct6775_write_value(data
, data
->REG_IN_MINMAX
[1][i
],
4034 for (i
= 0; i
< ARRAY_SIZE(data
->fan_min
); i
++) {
4035 if (!(data
->has_fan_min
& (1 << i
)))
4038 nct6775_write_value(data
, data
->REG_FAN_MIN
[i
],
4042 for (i
= 0; i
< NUM_TEMP
; i
++) {
4043 if (!(data
->have_temp
& (1 << i
)))
4046 for (j
= 1; j
< ARRAY_SIZE(data
->reg_temp
); j
++)
4047 if (data
->reg_temp
[j
][i
])
4048 nct6775_write_temp(data
, data
->reg_temp
[j
][i
],
4052 /* Restore other settings */
4053 nct6775_write_value(data
, data
->REG_VBAT
, data
->vbat
);
4054 if (data
->kind
== nct6775
) {
4055 nct6775_write_value(data
, NCT6775_REG_FANDIV1
, data
->fandiv1
);
4056 nct6775_write_value(data
, NCT6775_REG_FANDIV2
, data
->fandiv2
);
4060 /* Force re-reading all values */
4061 data
->valid
= false;
4062 mutex_unlock(&data
->update_lock
);
4067 static SIMPLE_DEV_PM_OPS(nct6775_dev_pm_ops
, nct6775_suspend
, nct6775_resume
);
4069 static struct platform_driver nct6775_driver
= {
4072 .pm
= &nct6775_dev_pm_ops
,
4074 .probe
= nct6775_probe
,
4077 static const char * const nct6775_sio_names
[] __initconst
= {
4086 /* nct6775_find() looks for a '627 in the Super-I/O config space */
4087 static int __init
nct6775_find(int sioaddr
, struct nct6775_sio_data
*sio_data
)
4093 err
= superio_enter(sioaddr
);
4100 val
= (superio_inb(sioaddr
, SIO_REG_DEVID
) << 8)
4101 | superio_inb(sioaddr
, SIO_REG_DEVID
+ 1);
4102 switch (val
& SIO_ID_MASK
) {
4103 case SIO_NCT6106_ID
:
4104 sio_data
->kind
= nct6106
;
4106 case SIO_NCT6775_ID
:
4107 sio_data
->kind
= nct6775
;
4109 case SIO_NCT6776_ID
:
4110 sio_data
->kind
= nct6776
;
4112 case SIO_NCT6779_ID
:
4113 sio_data
->kind
= nct6779
;
4115 case SIO_NCT6791_ID
:
4116 sio_data
->kind
= nct6791
;
4118 case SIO_NCT6792_ID
:
4119 sio_data
->kind
= nct6792
;
4123 pr_debug("unsupported chip ID: 0x%04x\n", val
);
4124 superio_exit(sioaddr
);
4128 /* We have a known chip, find the HWM I/O address */
4129 superio_select(sioaddr
, NCT6775_LD_HWM
);
4130 val
= (superio_inb(sioaddr
, SIO_REG_ADDR
) << 8)
4131 | superio_inb(sioaddr
, SIO_REG_ADDR
+ 1);
4132 addr
= val
& IOREGION_ALIGNMENT
;
4134 pr_err("Refusing to enable a Super-I/O device with a base I/O port 0\n");
4135 superio_exit(sioaddr
);
4139 /* Activate logical device if needed */
4140 val
= superio_inb(sioaddr
, SIO_REG_ENABLE
);
4141 if (!(val
& 0x01)) {
4142 pr_warn("Forcibly enabling Super-I/O. Sensor is probably unusable.\n");
4143 superio_outb(sioaddr
, SIO_REG_ENABLE
, val
| 0x01);
4146 if (sio_data
->kind
== nct6791
|| sio_data
->kind
== nct6792
)
4147 nct6791_enable_io_mapping(sioaddr
);
4149 superio_exit(sioaddr
);
4150 pr_info("Found %s or compatible chip at %#x:%#x\n",
4151 nct6775_sio_names
[sio_data
->kind
], sioaddr
, addr
);
4152 sio_data
->sioreg
= sioaddr
;
4158 * when Super-I/O functions move to a separate file, the Super-I/O
4159 * bus will manage the lifetime of the device and this module will only keep
4160 * track of the nct6775 driver. But since we use platform_device_alloc(), we
4161 * must keep track of the device
4163 static struct platform_device
*pdev
[2];
4165 static int __init
sensors_nct6775_init(void)
4170 struct resource res
;
4171 struct nct6775_sio_data sio_data
;
4172 int sioaddr
[2] = { 0x2e, 0x4e };
4174 err
= platform_driver_register(&nct6775_driver
);
4179 * initialize sio_data->kind and sio_data->sioreg.
4181 * when Super-I/O functions move to a separate file, the Super-I/O
4182 * driver will probe 0x2e and 0x4e and auto-detect the presence of a
4183 * nct6775 hardware monitor, and call probe()
4185 for (i
= 0; i
< ARRAY_SIZE(pdev
); i
++) {
4186 address
= nct6775_find(sioaddr
[i
], &sio_data
);
4192 pdev
[i
] = platform_device_alloc(DRVNAME
, address
);
4195 goto exit_device_unregister
;
4198 err
= platform_device_add_data(pdev
[i
], &sio_data
,
4199 sizeof(struct nct6775_sio_data
));
4201 goto exit_device_put
;
4203 memset(&res
, 0, sizeof(res
));
4205 res
.start
= address
+ IOREGION_OFFSET
;
4206 res
.end
= address
+ IOREGION_OFFSET
+ IOREGION_LENGTH
- 1;
4207 res
.flags
= IORESOURCE_IO
;
4209 err
= acpi_check_resource_conflict(&res
);
4211 platform_device_put(pdev
[i
]);
4216 err
= platform_device_add_resources(pdev
[i
], &res
, 1);
4218 goto exit_device_put
;
4220 /* platform_device_add calls probe() */
4221 err
= platform_device_add(pdev
[i
]);
4223 goto exit_device_put
;
4227 goto exit_unregister
;
4233 platform_device_put(pdev
[i
]);
4234 exit_device_unregister
:
4237 platform_device_unregister(pdev
[i
]);
4240 platform_driver_unregister(&nct6775_driver
);
4244 static void __exit
sensors_nct6775_exit(void)
4248 for (i
= 0; i
< ARRAY_SIZE(pdev
); i
++) {
4250 platform_device_unregister(pdev
[i
]);
4252 platform_driver_unregister(&nct6775_driver
);
4255 MODULE_AUTHOR("Guenter Roeck <linux@roeck-us.net>");
4256 MODULE_DESCRIPTION("NCT6106D/NCT6775F/NCT6776F/NCT6779D/NCT6791D/NCT6792D driver");
4257 MODULE_LICENSE("GPL");
4259 module_init(sensors_nct6775_init
);
4260 module_exit(sensors_nct6775_exit
);