Skip to contentSkip to conversation

hwmon: (nct6683) Add fan control support for MSI boards with NCT6687D-R

PATCH Applied Hamza Mahfooz 4 participants 10 messages Oct 4 – Nov 6

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover hwmon: (nct6683) Add fan control support for MSI boards with NCT6687D-R

Recent MSI boards (customer ID 0x20d) use an NCT6687D-R, whose fan control registers differ from the ones used on Mitac boards, the only boards for which the driver supports fan control so far. In addition, the system fans of these boards are connected to channels 10-15, whose duty cycle the driver does not report.

This series adds fan control support for these boards, based on the register map reverse engineered by the LibreHardwareMonitor project [1], which uses it on MSI 800-series boards.

Patch 1 reports the duty cycle of the system fans, and patch 2 adds fan control support for the CPU, pump and system fan headers.

Tested on an MSI PRO B850-P WIFI (MS-7E56, BIOS 2.A93, NCT6687D EC firmware version 0.0 build 04/18/25), on top of kernel v7.3-rc5. Fan control is available on pwm1, pwm2 and pwm13 to pwm16 on this board.

[1] https://github.com/LibreHardwareMonitor/LibreHardwareMonitor/pull/2294

Hamza Mahfooz (2):
hwmon: (nct6683) Report the duty cycle of NCT6687D-R system fans
hwmon: (nct6683) Add fan control support for MSI boards with

    NCT6687D-R
 Documentation/hwmon/nct6683.rst |  17 +++
 drivers/hwmon/nct6683.c         | 233 +++++++++++++++++++++++++++++++-
 2 files changed, 244 insertions(+), 6 deletions(-)
Signature · 1 line
2.56.0
#1 lore raw

PATCH 1/2 hwmon: (nct6683) Report the duty cycle of NCT6687D-R system fans

Recent MSI boards (customer ID 0x20d) use an NCT6687D-R. Its system fans are connected to channels 10-15, which have no fan output configuration register, so their duty cycle is not reported.

According to a reverse engineered register map, the duty cycle of these channels is reported in register (0xe00 + channel - 10). Report it for the system fans that are present, so that pwmN matches fanN. To do so, support up to 16 pwm channels, indexed by fan channel.

---
 drivers/hwmon/nct6683.c | 26 ++++++++++++++++++++++----
 1 file changed, 22 insertions(+), 4 deletions(-)
drivers/hwmon/nct6683.c +22 -4
index e1c36c95a..a43e23c65 100644
@@ -22,6 +22,7 @@
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include <linux/acpi.h>
+#include <linux/bits.h>
 #include <linux/delay.h>
 #include <linux/err.h>
 #include <linux/init.h>
@@ -169,6 +170,8 @@ superio_exit(int ioreg)
 #define NCT6683_FAN_CFG_REQ		0x80
 #define NCT6683_FAN_CFG_DONE		0x40
 
+#define NCT6687DR_REG_PWM_SYS(x)	(0xe00 + (x) - 10)	/* channels 10-15 */
+
 #define NCT6683_REG_CUSTOMER_ID		0x602
 #define NCT6683_CUSTOMER_ID_INTEL	0x805
 #define NCT6683_CUSTOMER_ID_MITAC	0xa0e
@@ -341,8 +344,8 @@ struct nct6683_data {
 	u8 fanout_cfg[NCT6683_NUM_REG_FAN];
 	u16 have_fan;			/* some fan inputs can be disabled */
 
-	u8 have_pwm;
-	u8 pwm[NCT6683_NUM_REG_PWM];
+	u16 have_pwm;
+	u8 pwm[NCT6683_NUM_REG_FAN];	/* indexed by fan channel */
 
 #ifdef CONFIG_PM
 	/* Remember extra register values over suspend/resume */
@@ -588,15 +591,21 @@ static int get_temp_reg(struct nct6683_data *data, int nr, int index)
 	return reg;
 }
 
+/* Channels 8-15 are only used on NCT6687D-R */
+static u16 nct6683_pwm_reg(int ch)
+{
+	return ch < 8 ? NCT6683_REG_PWM(ch) : NCT6687DR_REG_PWM_SYS(ch);
+}
+
 static void nct6683_update_pwm(struct device *dev)
 {
 	struct nct6683_data *data = dev_get_drvdata(dev);
 	int i;
 
-	for (i = 0; i < NCT6683_NUM_REG_PWM; i++) {
+	for (i = 0; i < ARRAY_SIZE(data->pwm); i++) {
 		if (!(data->have_pwm & (1 << i)))
 			continue;
-		data->pwm[i] = nct6683_read(data, NCT6683_REG_PWM(i));
+		data->pwm[i] = nct6683_read(data, nct6683_pwm_reg(i));
 	}
 }
 
@@ -1149,6 +1158,15 @@ nct6683_setup_fans(struct nct6683_data *data)
 			data->have_pwm |= 1 << i;
 		data->fanout_cfg[i] = reg;
 	}
+
+	if (data->kind == nct6687 &&
+	    data->customer_id == NCT6683_CUSTOMER_ID_MSI4) {
+		/*
+		 * The system fan channels (10-15) have no fan output
+		 * configuration register, so check their fan input instead.
+		 */
+		data->have_pwm |= data->have_fan & GENMASK(15, 10);
+	}
 }
 
 /*
Signature · 1 line
2.56.0
#4 lore raw

PATCH 2/2 hwmon: (nct6683) Add fan control support for MSI boards with NCT6687D-R

In reply to Hamza Mahfooz

The fan control registers of the NCT6687D-R used on recent MSI boards (customer ID 0x20d) differ from the ones used on Mitac boards, and changes must be made in a configuration phase of its fan engine.

Add fan control support for these boards, based on a reverse engineered register map:

- Manual mode is selected with bit (channel % 8) of register 0xa00 (channels 0-7) or 0x80f (channels 8-15). In manual mode, the duty cycle is set with register (0xa28 + channel) (channels 0-7) or (0x260 + channel - 10) (channels 10-15). Otherwise, the fan curve configured by the BIOS is used.
- A configuration phase is requested by setting bit 7 of register 0xa01, and is entered once register 0xcf8 reports that the fan registers are unlocked. It is completed by setting bit 6 of register 0xa01, after which the EC checks the new configuration, locks the registers again and reports whether the configuration was accepted.

Fan control is supported for the CPU (channel 0), pump (channel 1) and system fan (channels 10-15) headers. Add pwmN_enable attributes for them, with 1 selecting manual and 2 automatic mode, and make pwmN writable in manual mode. The behaviour of the driver does not change unless pwmN or pwmN_enable is written.

---
 Documentation/hwmon/nct6683.rst |  17 +++
 drivers/hwmon/nct6683.c         | 209 +++++++++++++++++++++++++++++++-
 2 files changed, 223 insertions(+), 3 deletions(-)
Documentation/hwmon/nct6683.rst +17 -0
index c47b0709c..ffc80fad3 100644
@@ -49,6 +49,22 @@ The driver has only been tested with the Intel firmware, and by default
 only instantiates on Intel boards. To enable it on non-Intel boards,
 set the 'force' module parameter to 1.
 
+Fan Control
+-----------
+
+Fan control is supported on MSI boards with an NCT6687D-R (customer ID
+0x20d). pwm1 and pwm2 control the CPU and pump fan headers, and pwm11 to
+pwm16 control the system fan headers that are present. pwmN controls the
+fan reported by fanN_input.
+
+pwmN_enable selects the fan control mode:
+
+  * 1: manual mode, the duty cycle is set with pwmN
+  * 2: automatic mode, using the fan curve configured in the BIOS
+
+pwmN can only be written in manual mode. Switching to manual mode keeps the
+current duty cycle.
+
 Tested Boards and Firmware Versions
 -----------------------------------
 
@@ -71,6 +87,7 @@ MSI B550M			NCT6687D EC firmware version 1.0 build 05/07/20
 MSI B650			NCT6687D EC firmware version 0.0 build 09/27/22
 MSI B650M			NCT6687D EC firmware version 0.0 build 09/27/22
 MSI B850M			NCT6687D EC firmware version 0.0 build 03/10/25
+MSI B850-P			NCT6687D EC firmware version 0.0 build 04/18/25
 MSI X670-P			NCT6687D EC firmware version 0.0 build 09/27/22
 MSI X870E			NCT6687D EC firmware version 0.0 build 11/13/24
 ===============================	===============================================
drivers/hwmon/nct6683.c +206 -3

275 lines not on this page · raw message

Signature · 1 line
2.56.0
#5 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 18 lines

The fan control registers of the NCT6687D-R used on recent MSI boards (customer ID 0x20d) differ from the ones used on Mitac boards, and changes must be made in a configuration phase of its fan engine.

Add fan control support for these boards, based on a reverse engineered register map:

- Manual mode is selected with bit (channel % 8) of register 0xa00 (channels 0-7) or 0x80f (channels 8-15). In manual mode, the duty cycle is set with register (0xa28 + channel) (channels 0-7) or (0x260 + channel - 10) (channels 10-15). Otherwise, the fan curve configured by the BIOS is used.
- A configuration phase is requested by setting bit 7 of register 0xa01, and is entered once register 0xcf8 reports that the fan registers are unlocked. It is completed by setting bit 6 of register 0xa01, after which the EC checks the new configuration, locks the registers again and reports whether the configuration was accepted.

Quoted 7 lines

Fan control is supported for the CPU (channel 0), pump (channel 1) and system fan (channels 10-15) headers. Add pwmN_enable attributes for them, with 1 selecting manual and 2 automatic mode, and make pwmN writable in manual mode. The behaviour of the driver does not change unless pwmN or pwmN_enable is written.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
#2 lore raw

Re: [PATCH 1/2] hwmon: (nct6683) Report the duty cycle of NCT6687D-R system fans

In reply to Hamza Mahfooz
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines

Recent MSI boards (customer ID 0x20d) use an NCT6687D-R. Its system fans are connected to channels 10-15, which have no fan output configuration register, so their duty cycle is not reported.

According to a reverse engineered register map, the duty cycle of these channels is reported in register (0xe00 + channel - 10). Report it for the system fans that are present, so that pwmN matches fanN. To do so, support up to 16 pwm channels, indexed by fan channel.

Sashiko has reviewed this patch and found no issues. It looks great!

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#7 lore raw
In reply to Hamza Mahfooz
Quoted 19 lines · Hamza Mahfooz

Recent MSI boards (customer ID 0x20d) use an NCT6687D-R, whose fan control registers differ from the ones used on Mitac boards, the only boards for which the driver supports fan control so far. In addition, the system fans of these boards are connected to channels 10-15, whose duty cycle the driver does not report.

This series adds fan control support for these boards, based on the register map reverse engineered by the LibreHardwareMonitor project [1], which uses it on MSI 800-series boards.

Patch 1 reports the duty cycle of the system fans, and patch 2 adds fan control support for the CPU, pump and system fan headers.

Tested on an MSI PRO B850-P WIFI (MS-7E56, BIOS 2.A93, NCT6687D EC firmware version 0.0 build 04/18/25), on top of kernel v7.3-rc5. Fan control is available on pwm1, pwm2 and pwm13 to pwm16 on this board.

[1] https://github.com/LibreHardwareMonitor/LibreHardwareMonitor/pull/2294

Quoted 12 lines

Hamza Mahfooz (2):
hwmon: (nct6683) Report the duty cycle of NCT6687D-R system fans
hwmon: (nct6683) Add fan control support for MSI boards with

    NCT6687D-R
 Documentation/hwmon/nct6683.rst |  17 +++
 drivers/hwmon/nct6683.c         | 233 +++++++++++++++++++++++++++++++-
 2 files changed, 244 insertions(+), 6 deletions(-)
Signature · 1 line
2.56.0

Ping?

maintainer Applied
#3 lore raw

Re: [PATCH 1/2] hwmon: (nct6683) Report the duty cycle of NCT6687D-R system fans

In reply to Hamza Mahfooz
Quoted 10 lines · Hamza Mahfooz

Recent MSI boards (customer ID 0x20d) use an NCT6687D-R. Its system fans are connected to channels 10-15, which have no fan output configuration register, so their duty cycle is not reported.

According to a reverse engineered register map, the duty cycle of these channels is reported in register (0xe00 + channel - 10). Report it for the system fans that are present, so that pwmN matches fanN. To do so, support up to 16 pwm channels, indexed by fan channel.

Applied.

Thanks,
Guenter

maintainer Applied
#6 lore raw
In reply to Hamza Mahfooz
Quoted 18 lines · Hamza Mahfooz

The fan control registers of the NCT6687D-R used on recent MSI boards (customer ID 0x20d) differ from the ones used on Mitac boards, and changes must be made in a configuration phase of its fan engine.

Add fan control support for these boards, based on a reverse engineered register map:

- Manual mode is selected with bit (channel % 8) of register 0xa00 (channels 0-7) or 0x80f (channels 8-15). In manual mode, the duty cycle is set with register (0xa28 + channel) (channels 0-7) or (0x260 + channel - 10) (channels 10-15). Otherwise, the fan curve configured by the BIOS is used.
- A configuration phase is requested by setting bit 7 of register 0xa01, and is entered once register 0xcf8 reports that the fan registers are unlocked. It is completed by setting bit 6 of register 0xa01, after which the EC checks the new configuration, locks the registers again and reports whether the configuration was accepted.

Quoted 7 lines

Fan control is supported for the CPU (channel 0), pump (channel 1) and system fan (channels 10-15) headers. Add pwmN_enable attributes for them, with 1 selecting manual and 2 automatic mode, and make pwmN writable in manual mode. The behaviour of the driver does not change unless pwmN or pwmN_enable is written.

Applied.

Thanks,
Guenter

maintainer
#8 lore raw
In reply to Hamza Mahfooz
Quoted 29 lines · Hamza Mahfooz
Quoted 28 lines · Hamza Mahfooz

Recent MSI boards (customer ID 0x20d) use an NCT6687D-R, whose fan control registers differ from the ones used on Mitac boards, the only boards for which the driver supports fan control so far. In addition, the system fans of these boards are connected to channels 10-15, whose duty cycle the driver does not report.

This series adds fan control support for these boards, based on the register map reverse engineered by the LibreHardwareMonitor project [1], which uses it on MSI 800-series boards.

Patch 1 reports the duty cycle of the system fans, and patch 2 adds fan control support for the CPU, pump and system fan headers.

Tested on an MSI PRO B850-P WIFI (MS-7E56, BIOS 2.A93, NCT6687D EC firmware version 0.0 build 04/18/25), on top of kernel v7.3-rc5. Fan control is available on pwm1, pwm2 and pwm13 to pwm16 on this board.

[1] https://github.com/LibreHardwareMonitor/LibreHardwareMonitor/pull/2294

Hamza Mahfooz (2):
hwmon: (nct6683) Report the duty cycle of NCT6687D-R system fans
hwmon: (nct6683) Add fan control support for MSI boards with

     NCT6687D-R
  Documentation/hwmon/nct6683.rst |  17 +++
  drivers/hwmon/nct6683.c         | 233 +++++++++++++++++++++++++++++++-
  2 files changed, 244 insertions(+), 6 deletions(-)
Quoted 5 lines
Quoted 3 lines
Signature · 1 line
2.56.0

Ping?

Sorry, I was out of commission for a while, and I am still digging through patches. Now applied.

Guenter

Tested-by on the v1 series
#9 lore raw
In reply to Hamza Mahfooz
Quoted 2 lines · Hamza Mahfooz

Patch 1 reports the duty cycle of the system fans, and patch 2 adds fan control support for the CPU, pump and system fan headers.

Tested on an MSI MAG B850M MORTAR WIFI (MS-7E61, BIOS 1.A68, NCT6687D EC firmware version 0.0 build 03/10/25), with nct6683.c from hwmon-next built out of tree against kernel 7.2.15.

pwm1, pwm2 and pwm13 to pwm16 are writable and have pwmN_enable, all set to 2 after loading the driver. Writes were tested on pwm16 (SYS Fan 1):

pwm16_enable pwm16 fan16_input

  2                98     926 RPM  (initial, BIOS curve)
  1               255    2083 RPM  (after 8 s)
  1                80     767 RPM  (after 10 s)
  2                 -     911 RPM  (10 s after switching back)

Setting pwm16_enable back to 2 restores the BIOS fan curve. pwm4 (EZ Conn header JAF_1) remains read-only.