Skip to contentSkip to conversation

hwmon: (nct6683) Fan control for ASRock B850 Steel Legend WiFi

PATCH Superseded Johan Dahlin 5 participants 15 messages Aug 25 – Nov 10

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover hwmon: (nct6683) Fan control for ASRock B850 Steel Legend WiFi

Fan control does not work on an ASRock B850 Steel Legend WiFi (NCT6686D, EC firmware 1.0 build 10/29/24). The driver does not recognise the board's customer ID, so it only probes with force=1. Its pwm attributes are then read-only, and even once writable the EC ignores them until the fan is put in manual mode through register 0xa00, which the driver does not expose. Writes that do get through are sometimes silently discarded, because the settling delay in store_pwm() is too short on this firmware.

This series fixes those one at a time. Patch 1 stands on its own: a write that succeeds on the first attempt issues the same register sequence as today, so boards that work now are unaffected. The fan control changes are exposed on verified boards only.

With the whole series applied, all six fans report and pwm[1-6]_enable read 2 after probe:

fan1: 815 RPM fan2: 631 RPM fan5: 386 RPM fan6: 354 RPM

With pwm5 in manual mode:

  written   applied   fan5
  60        60        337 RPM
  100       100       443 RPM
  150       150       627 RPM
  200       200       794 RPM
  255       255       933 RPM

Writing 2 back returns the fan to the EC, as does unloading the driver. Without patch 1, two of six writes were lost and the fan kept following its previous value.

Each patch was also built individually. I have no access to Mitac, MSI or Intel hardware.

Johan Dahlin (5):
hwmon: (nct6683) Retry pwm writes until they take effect
hwmon: (nct6683) Add customer ID for ASRock B850 Steel Legend WiFi
hwmon: (nct6683) Add pwm[1-8]_enable
hwmon: (nct6683) Restore fan control mode on driver removal
hwmon: (nct6683) Enable pwm control on ASRock B850 Steel Legend WiFi

 Documentation/hwmon/nct6683.rst |   7 ++
 drivers/hwmon/nct6683.c         | 124 +++++++++++++++++++++++++++++---
 2 files changed, 122 insertions(+), 9 deletions(-)
Signature · 1 line
2.53.0
#1 lore raw

PATCH 1/5 hwmon: (nct6683) Retry pwm writes until they take effect

store_pwm() waits a fixed 1-2 ms for the EC to hand over the fan configuration registers before writing. That delay dates back to commit 91918d13eb17 ("hwmon: (nct6683) Add basic support for NCT6683 on Mitac boards") and, pwm being read-only elsewhere, has never been exercised against other firmware.

It is too short for at least one of them: on an ASRock B850 Steel Legend WiFi (NCT6686D), two of six consecutive pwm writes were silently discarded, leaving the fan on its previous setting.

Read the value back and repeat the sequence when it did not stick, waiting longer each time and reporting -EIO if it never does. Raising the delay for everyone would penalise boards that work today, while a write that succeeds first time issues the same register sequence as before.

---
 drivers/hwmon/nct6683.c | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/hwmon/nct6683.c +16 -5
index e1c36c95affb..b524a45b1471 100644
@@ -934,18 +934,29 @@ store_pwm(struct device *dev, struct device_attribute *attr, const char *buf,
 	struct nct6683_data *data = dev_get_drvdata(dev);
 	int index = sattr->index;
 	unsigned long val;
+	int tries;
 
 	if (kstrtoul(buf, 10, &val) || val > 255)
 		return -EINVAL;
 
+	/*
+	 * The EC does not always release the fan configuration registers
+	 * within the settling delay, and a write issued before it does is
+	 * silently discarded. Repeat the sequence until the value sticks.
+	 */
 	mutex_lock(&data->update_lock);
-	nct6683_write(data, NCT6683_REG_FAN_CFG_CTRL, NCT6683_FAN_CFG_REQ);
-	usleep_range(1000, 2000);
-	nct6683_write(data, NCT6683_REG_PWM_WRITE(index), val);
-	nct6683_write(data, NCT6683_REG_FAN_CFG_CTRL, NCT6683_FAN_CFG_DONE);
+	for (tries = 0; tries < 3; tries++) {
+		nct6683_write(data, NCT6683_REG_FAN_CFG_CTRL, NCT6683_FAN_CFG_REQ);
+		/* A failed attempt means the EC needed longer than we waited */
+		usleep_range(1000 * (tries + 1), 2000 * (tries + 1));
+		nct6683_write(data, NCT6683_REG_PWM_WRITE(index), val);
+		nct6683_write(data, NCT6683_REG_FAN_CFG_CTRL, NCT6683_FAN_CFG_DONE);
+		if (nct6683_read(data, NCT6683_REG_PWM_WRITE(index)) == val)
+			break;
+	}
 	mutex_unlock(&data->update_lock);
 
-	return count;
+	return tries == 3 ? -EIO : count;
 }
 
 SENSOR_TEMPLATE(pwm, "pwm%d", S_IRUGO, show_pwm, store_pwm, 0);
Signature · 1 line
2.53.0
#3 lore raw

PATCH 2/5 hwmon: (nct6683) Add customer ID for ASRock B850 Steel Legend WiFi

In reply to Johan Dahlin

The ASRock B850 Steel Legend WiFi uses an NCT6686D chip reporting customer ID 0x164a. Without this ID the driver refuses to probe unless the force module parameter is set, leaving the board without hardware monitoring.

Add NCT6683_CUSTOMER_ID_ASROCK8 and handle it in the probe function.

---
 Documentation/hwmon/nct6683.rst | 1 +
 drivers/hwmon/nct6683.c         | 3 +++
 2 files changed, 4 insertions(+)
Documentation/hwmon/nct6683.rst +1 -0
index 45eec9dd349a..908c0b10c642 100644
@@ -66,6 +66,7 @@ ASRock X570			NCT6683D EC firmware version 1.0 build 06/28/19
 ASRock X670E			NCT6686D EC firmware version 1.0 build 05/19/22
 ASRock B650 Steel Legend WiFi	NCT6686D EC firmware version 1.0 build 11/09/23
 ASRock Z590 Taichi		NCT6686D EC firmware version 1.0 build 01/25/21
+ASRock B850 Steel Legend WiFi	NCT6686D EC firmware version 1.0 build 10/29/24
 MSI B550			NCT6687D EC firmware version 1.0 build 05/07/20
 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 +3 -0
index b524a45b1471..b43e915f9d0f 100644
@@ -184,6 +184,7 @@ superio_exit(int ioreg)
 #define NCT6683_CUSTOMER_ID_ASROCK5	0x1621
 #define NCT6683_CUSTOMER_ID_ASROCK6	0x1633
 #define NCT6683_CUSTOMER_ID_ASROCK7	0x163d
+#define NCT6683_CUSTOMER_ID_ASROCK8	0x164a
 
 #define NCT6683_REG_BUILD_YEAR		0x604
 #define NCT6683_REG_BUILD_MONTH		0x605
@@ -1262,6 +1263,8 @@ static int nct6683_probe(struct platform_device *pdev)
 		break;
 	case NCT6683_CUSTOMER_ID_ASROCK7:
 		break;
+	case NCT6683_CUSTOMER_ID_ASROCK8:
+		break;
 	default:
 		if (!force)
 			return -ENODEV;
Signature · 1 line
2.53.0
#5 lore raw

PATCH 3/5 hwmon: (nct6683) Add pwm[1-8]_enable

In reply to Johan Dahlin

NCT668x keeps a per-fan manual-control bitmap in register 0xa00. While a fan's bit is clear the EC runs its own control loop and ignores the pwm registers, so a pwm write succeeds and then has no effect on the fan.

Expose the bitmap as pwm[1-8]_enable following the hwmon ABI, with 1 for manual control and 2 for the EC's automatic control. The attribute group now has two attributes per channel, so is_visible derives the channel from the attribute index.

Intel boards run a firmware variant that Nuvoton confirms uses different register addresses, so 0xa00 cannot be assumed to mean the same thing there. Only expose the attribute where fan control has been verified.

The register was derived from the out-of-tree nct6687d driver, which documents it from LibreHardwareMonitor's reverse engineering.

---
 Documentation/hwmon/nct6683.rst |  6 +++
 drivers/hwmon/nct6683.c         | 77 +++++++++++++++++++++++++++++++--
 2 files changed, 79 insertions(+), 4 deletions(-)
Documentation/hwmon/nct6683.rst +6 -0
index 908c0b10c642..ff5edb34c5c5 100644
@@ -49,6 +49,12 @@ 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 is likewise restricted. The EC runs its own control loop unless
+a fan is switched to manual mode by writing 1 to its pwm[1-8]_enable
+attribute, and pwm values are only writable on boards where this has been
+verified to work. On all other boards the pwm attributes are read-only and
+the fan curve must be configured from the BIOS.
+
 Tested Boards and Firmware Versions
 -----------------------------------
 
drivers/hwmon/nct6683.c +73 -4

104 lines not on this page · raw message

Signature · 1 line
2.53.0
#8 lore raw

PATCH 4/5 hwmon: (nct6683) Restore fan control mode on driver removal

In reply to Johan Dahlin

A fan switched to manual mode stays there when the driver is unloaded, leaving it pinned at whatever pwm value was last written with nothing left to update it.

Record the fan control mode register during probe and put it back with a devres action, so the EC resumes control of the fans the driver took over while anything the firmware had already set is left alone. The action is registered before the hwmon device, so it runs after the attributes are gone and cannot race with a pwm write, and it is a no-op if probe fails before the driver touches the register.

Boards where the driver does not manage the register do not register it.

---
 drivers/hwmon/nct6683.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
drivers/hwmon/nct6683.c +22 -0
index 0324ace707a5..6825e6c3af34 100644
@@ -344,6 +344,7 @@ struct nct6683_data {
 	u16 have_fan;			/* some fan inputs can be disabled */
 
 	u8 have_pwm;
+	u8 initial_fan_ctrl_mode;
 	u8 pwm[NCT6683_NUM_REG_PWM];
 
 #ifdef CONFIG_PM
@@ -1275,6 +1276,17 @@ static void nct6683_setup_sensors(struct nct6683_data *data)
 	}
 }
 
+/* Put the fan control mode register back the way probe found it. */
+static void nct6683_restore_fan_control(void *_data)
+{
+	struct nct6683_data *data = _data;
+
+	mutex_lock(&data->update_lock);
+	nct6683_write(data, NCT6683_REG_FAN_CTRL_MODE,
+		      data->initial_fan_ctrl_mode);
+	mutex_unlock(&data->update_lock);
+}
+
 static int nct6683_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -1284,6 +1296,7 @@ static int nct6683_probe(struct platform_device *pdev)
 	struct device *hwmon_dev;
 	struct resource *res;
 	int groups = 0;
+	int err;
 	char build[16];
 
 	res = platform_get_resource(pdev, IORESOURCE_IO, 0);
@@ -1401,6 +1414,15 @@ static int nct6683_probe(struct platform_device *pdev)
 		 nct6683_read(data, NCT6683_REG_VERSION_LO),
 		 build);
 
+	if (nct6683_has_fan_control(data)) {
+		data->initial_fan_ctrl_mode =
+			nct6683_read(data, NCT6683_REG_FAN_CTRL_MODE);
+		err = devm_add_action_or_reset(dev, nct6683_restore_fan_control,
+					       data);
+		if (err)
+			return err;
+	}
+
 	hwmon_dev = devm_hwmon_device_register_with_groups(dev,
 			nct6683_device_names[data->kind], data, data->groups);
 	return PTR_ERR_OR_ZERO(hwmon_dev);
Signature · 1 line
2.53.0
#10 lore raw

PATCH 5/5 hwmon: (nct6683) Enable pwm control on ASRock B850 Steel Legend WiFi

In reply to Johan Dahlin

Fan control has been measured on this board: with a fan in manual mode the applied pwm value tracks what is written, and the fan responds proportionally from 337 RPM at pwm 60 to 933 RPM at pwm 255.

Allow pwm writes on this board.

---
 drivers/hwmon/nct6683.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/nct6683.c +2 -1
index 6825e6c3af34..df28055b1a1c 100644
@@ -972,7 +972,8 @@ SENSOR_TEMPLATE(pwm, "pwm%d", S_IRUGO, show_pwm, store_pwm, 0);
  */
 static bool nct6683_has_fan_control(struct nct6683_data *data)
 {
-	return data->customer_id == NCT6683_CUSTOMER_ID_MITAC;
+	return data->customer_id == NCT6683_CUSTOMER_ID_MITAC ||
+	       data->customer_id == NCT6683_CUSTOMER_ID_ASROCK8;
 }
 
 /*
Signature · 1 line
2.53.0
#4 lore raw

Re: [PATCH 2/5] hwmon: (nct6683) Add customer ID for ASRock B850 Steel Legend WiFi

In reply to Johan Dahlin
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 7 lines

The ASRock B850 Steel Legend WiFi uses an NCT6686D chip reporting customer ID 0x164a. Without this ID the driver refuses to probe unless the force module parameter is set, leaving the board without hardware monitoring.

Add NCT6683_CUSTOMER_ID_ASROCK8 and handle it in the probe function.

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
#9 lore raw

Re: [PATCH 4/5] hwmon: (nct6683) Restore fan control mode on driver removal

In reply to Johan Dahlin
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 11 lines

A fan switched to manual mode stays there when the driver is unloaded, leaving it pinned at whatever pwm value was last written with nothing left to update it.

Record the fan control mode register during probe and put it back with a devres action, so the EC resumes control of the fans the driver took over while anything the firmware had already set is left alone. The action is registered before the hwmon device, so it runs after the attributes are gone and cannot race with a pwm write, and it is a no-op if probe fails before the driver touches the register.

Quoted 3 lines

Boards where the driver does not manage the register do not register it.

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=4
#2 lore raw

Re: [PATCH 1/5] hwmon: (nct6683) Retry pwm writes until they take effect

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

store_pwm() waits a fixed 1-2 ms for the EC to hand over the fan configuration registers before writing. That delay dates back to commit 91918d13eb17 ("hwmon: (nct6683) Add basic support for NCT6683 on Mitac boards") and, pwm being read-only elsewhere, has never been exercised against other firmware.

It is too short for at least one of them: on an ASRock B850 Steel Legend WiFi (NCT6686D), two of six consecutive pwm writes were silently discarded, leaving the fan on its previous setting.

Quoted 6 lines

Read the value back and repeat the sequence when it did not stick, waiting longer each time and reporting -EIO if it never does. Raising the delay for everyone would penalise boards that work today, while a write that succeeds first time issues the same register sequence as before.

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
#11 lore raw

Re: [PATCH 5/5] hwmon: (nct6683) Enable pwm control on ASRock B850 Steel Legend WiFi

In reply to Johan Dahlin
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:

Pre-existing issues:
- [High] The sysfs show/store callbacks for 'pwm' and 'pwm_enable' attributes incorrectly cast the incoming attribute pointer to struct sensor_device_attribute_2, causing broken behavior on Big Endian systems. --

--- Patch [5]: [PATCH 5/5] hwmon: (nct6683) Enable pwm control on ASRock B850 Steel Legend WiFi --- commit 098ac72f5515df05870f944950a3f04a964252c2
Author: Johan Dahlin <[email protected]>

hwmon: (nct6683) Enable pwm control on ASRock B850 Steel Legend WiFi

Fan control has been measured on this board: with a fan in manual mode the applied pwm value tracks what is written, and the fan responds proportionally from 337 RPM at pwm 60 to 933 RPM at pwm 255.

Allow pwm writes on this board.

drivers/hwmon/nct6683.c SENSOR_TEMPLATE(pwm, "pwm%d", S_IRUGO, show_pwm, store_pwm, 0);

Quoted 5 lines
drivers/hwmon/nct6683.c +0 -0
index 6825e6c3af34f..df28055b1a1c4 100644
@@ -972,7 +972,8 @@ SENSOR_TEMPLATE(pwm, "pwm%d", S_IRUGO, show_pwm, store_pwm, 0);

[Severity: High]
This is a pre-existing issue, but since this patch enables PWM writes for a new board, is there a type punning bug in the PWM sysfs callbacks?

SENSOR_TEMPLATE defines these attributes as struct sensor_device_attribute, which has an 'int index' field (4 bytes). However, the callbacks like show_pwm() and store_pwm() cast this attribute to
struct sensor_device_attribute_2:

drivers/hwmon/nct6683.c:show_pwm() {
    struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);
    int index = sattr->index;
    ...
}

struct sensor_device_attribute_2 uses a 'u8 index' (1 byte). On Big Endian systems, reading the 1-byte u8 from a 4-byte int will yield 0 instead of the true index, so all PWM attribute accesses will incorrectly target channel 0.

Does this need to be fixed to use to_sensor_dev_attr(attr) instead?

Quoted 9 lines
drivers/hwmon/nct6683.c +2 -1
  */
 static bool nct6683_has_fan_control(struct nct6683_data *data)
 {
-	return data->customer_id == NCT6683_CUSTOMER_ID_MITAC;
+	return data->customer_id == NCT6683_CUSTOMER_ID_MITAC ||
+	       data->customer_id == NCT6683_CUSTOMER_ID_ASROCK8;
 }
 
 /*
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=5
#6 lore raw

Re: [PATCH 3/5] hwmon: (nct6683) Add pwm[1-8]_enable

In reply to Johan Dahlin
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [Medium] The sysfs callbacks `show_pwm_enable()` and `store_pwm_enable()` incorrectly cast their…

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The sysfs callbacks show_pwm_enable() and store_pwm_enable() incorrectly cast their attribute argument to struct sensor_device_attribute_2 *, leading to type confusion with struct sensor_device_attribute and causing failures on Big-Endian architectures. --

--- Patch [3]: [PATCH 3/5] hwmon: (nct6683) Add pwm[1-8]_enable --- commit ae1360636538f417a87b23c1e1c204ef9329c018
Author: Johan Dahlin <[email protected]>

hwmon: (nct6683) Add pwm[1-8]_enable

This commit exposes the manual-control bitmap as pwm[1-8]_enable for fan control on supported boards, falling back to read-only hardware control on unsupported variants.

Quoted 4 lines
drivers/hwmon/nct6683.c +0 -0
index b43e915f9d0fb..0324ace707a53 100644

[ ... ]

Quoted 1 line
drivers/hwmon/nct6683.c +0 -0
@@ -962,25 +963,93 @@ store_pwm(struct device *dev, struct device_attribute *attr, const char *buf,

[ ... ]

drivers/hwmon/nct6683.c store_pwm(struct device *dev, struct device_attribute *attr, const char *buf, · line 985

Quoted 4 lines
drivers/hwmon/nct6683.c +4 -0
+static ssize_t
+show_pwm_enable(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);

[Severity: Medium]
Does this cast cause type confusion with struct sensor_device_attribute?

The template initializes the attribute as a struct sensor_device_attribute, which uses an int for the index field, but it is cast here to a struct sensor_device_attribute_2, which uses a u8 for the index.

On Big-Endian architectures, reading a u8 from an int field aliases the MSB. Would this result in an index of 0, effectively mapping all manual fan control operations to channel 0 and breaking functionality for fans 1-7?

Quoted 5 lines
drivers/hwmon/nct6683.c +5 -0
+	struct nct6683_data *data = dev_get_drvdata(dev);
+	u8 mode;
+
+	mutex_lock(&data->update_lock);
+	mode = nct6683_read(data, NCT6683_REG_FAN_CTRL_MODE);

drivers/hwmon/nct6683.c store_pwm(struct device *dev, struct device_attribute *attr, const char *buf, · line 1000

Quoted 10 lines
drivers/hwmon/nct6683.c +10 -0
+	mutex_unlock(&data->update_lock);
+
+	return sysfs_emit(buf, "%d\n", (mode & BIT(sattr->index)) ? 1 : 2);
+}
+
+static ssize_t
+store_pwm_enable(struct device *dev, struct device_attribute *attr,
+		 const char *buf, size_t count)
+{
+	struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);

[Severity: Medium]
Is there a similar type confusion issue on the store path?

Casting to struct sensor_device_attribute_2 and reading the u8 index might similarly fail on Big-Endian systems during store operations, causing writes to unintended channels.

Quoted 2 lines
drivers/hwmon/nct6683.c +2 -0
+	struct nct6683_data *data = dev_get_drvdata(dev);
+	u8 bit = BIT(sattr->index);

[ ... ]

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

Re: [PATCH 3/5] hwmon: (nct6683) Add pwm[1-8]_enable

Quoted 2 lines · On 8/25/26 02:44, [email protected] wrote:

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] The sysfs callbacks show_pwm_enable() and store_pwm_enable() incorrectly cast their attribute argument to struct sensor_device_attribute_2 *, leading to type confusion with struct sensor_device_attribute and causing failures on Big-Endian architectures.

Yes. Please fix.

Thanks,
Guenter

Quoted 65 lines

--

--- Patch [3]: [PATCH 3/5] hwmon: (nct6683) Add pwm[1-8]_enable --- commit ae1360636538f417a87b23c1e1c204ef9329c018
Author: Johan Dahlin <[email protected]>

hwmon: (nct6683) Add pwm[1-8]_enable

This commit exposes the manual-control bitmap as pwm[1-8]_enable for fan control on supported boards, falling back to read-only hardware control on unsupported variants.

Quoted 4 lines
drivers/hwmon/nct6683.c +0 -0
index b43e915f9d0fb..0324ace707a53 100644

[ ... ]

Quoted 1 line
drivers/hwmon/nct6683.c +0 -0
@@ -962,25 +963,93 @@ store_pwm(struct device *dev, struct device_attribute *attr, const char *buf,

[ ... ]

drivers/hwmon/nct6683.c store_pwm(struct device *dev, struct device_attribute *attr, const char *buf, · line 985

Quoted 4 lines
drivers/hwmon/nct6683.c +4 -0
+static ssize_t
+show_pwm_enable(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);

[Severity: Medium]
Does this cast cause type confusion with struct sensor_device_attribute?

The template initializes the attribute as a struct sensor_device_attribute, which uses an int for the index field, but it is cast here to a struct sensor_device_attribute_2, which uses a u8 for the index.

On Big-Endian architectures, reading a u8 from an int field aliases the MSB. Would this result in an index of 0, effectively mapping all manual fan control operations to channel 0 and breaking functionality for fans 1-7?

Quoted 5 lines
drivers/hwmon/nct6683.c +5 -0
+	struct nct6683_data *data = dev_get_drvdata(dev);
+	u8 mode;
+
+	mutex_lock(&data->update_lock);
+	mode = nct6683_read(data, NCT6683_REG_FAN_CTRL_MODE);

drivers/hwmon/nct6683.c store_pwm(struct device *dev, struct device_attribute *attr, const char *buf, · line 1000

Quoted 10 lines
drivers/hwmon/nct6683.c +10 -0
+	mutex_unlock(&data->update_lock);
+
+	return sysfs_emit(buf, "%d\n", (mode & BIT(sattr->index)) ? 1 : 2);
+}
+
+static ssize_t
+store_pwm_enable(struct device *dev, struct device_attribute *attr,
+		 const char *buf, size_t count)
+{
+	struct sensor_device_attribute_2 *sattr = to_sensor_dev_attr_2(attr);

[Severity: Medium]
Is there a similar type confusion issue on the store path?

Casting to struct sensor_device_attribute_2 and reading the u8 index might similarly fail on Big-Endian systems during store operations, causing writes to unintended channels.

Quoted 2 lines
drivers/hwmon/nct6683.c +2 -0
+	struct nct6683_data *data = dev_get_drvdata(dev);
+	u8 bit = BIT(sattr->index);

[ ... ]

Tested-by on v1 5/5
#12 lore raw

Re: [PATCH 5/5] hwmon: (nct6683) Enable pwm control on ASRock B850 Steel Legend WiFi

In reply to Johan Dahlin

Hi,

Quoted 16 lines · Johan Dahlin

Fan control has been measured on this board: with a fan in manual mode the applied pwm value tracks what is written, and the fan responds proportionally from 337 RPM at pwm 60 to 933 RPM at pwm 255.

Allow pwm writes on this board.

---
 drivers/hwmon/nct6683.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/nct6683.c +0 -0
index 6825e6c3af34..df28055b1a1c 100644

drivers/hwmon/nct6683.c SENSOR_TEMPLATE(pwm, "pwm%d", S_IRUGO, show_pwm, store_pwm, 0); · line 979

Quoted 9 lines
drivers/hwmon/nct6683.c +2 -1
@@ -972,7 +972,8 @@ SENSOR_TEMPLATE(pwm, "pwm%d", S_IRUGO, show_pwm, store_pwm, 0);
  */
 static bool nct6683_has_fan_control(struct nct6683_data *data)
 {
-	return data->customer_id == NCT6683_CUSTOMER_ID_MITAC;
+	return data->customer_id == NCT6683_CUSTOMER_ID_MITAC ||
+	       data->customer_id == NCT6683_CUSTOMER_ID_ASROCK8;
 }
 
 /*

Thanks for the patches, I tried this on an ASRock BC-250, also NCT6686D, and it works fine there as well. The board id is NCT6683_CUSTOMER_ID_AMD and all it needed was:

-              data->customer_id == NCT6683_CUSTOMER_ID_ASROCK8;
+              data->customer_id == NCT6683_CUSTOMER_ID_ASROCK8 ||
+              data->customer_id == NCT6683_CUSTOMER_ID_AMD;

Maybe you can add that as well once you send the v2 of this? (and a

send a followup myself once this gets merged, whatever you prefer.

Either way I feel like this list is going to grow, maybe a

switch (data->customer_id) {
...

would work out better long term here.

Thanks,
Fabio

maintainer
#13 lore raw

Re: [PATCH 5/5] hwmon: (nct6683) Enable pwm control on ASRock B850 Steel Legend WiFi

Quoted 39 lines · Fabio Baltieri

Hi,

Quoted 16 lines · Johan Dahlin

Fan control has been measured on this board: with a fan in manual mode the applied pwm value tracks what is written, and the fan responds proportionally from 337 RPM at pwm 60 to 933 RPM at pwm 255.

Allow pwm writes on this board.

---
  drivers/hwmon/nct6683.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
drivers/hwmon/nct6683.c +0 -0
index 6825e6c3af34..df28055b1a1c 100644

drivers/hwmon/nct6683.c SENSOR_TEMPLATE(pwm, "pwm%d", S_IRUGO, show_pwm, store_pwm, 0); · line 979

Quoted 9 lines
drivers/hwmon/nct6683.c +2 -1
@@ -972,7 +972,8 @@ SENSOR_TEMPLATE(pwm, "pwm%d", S_IRUGO, show_pwm, store_pwm, 0);
   */
  static bool nct6683_has_fan_control(struct nct6683_data *data)
  {
-	return data->customer_id == NCT6683_CUSTOMER_ID_MITAC;
+	return data->customer_id == NCT6683_CUSTOMER_ID_MITAC ||
+	       data->customer_id == NCT6683_CUSTOMER_ID_ASROCK8;
  }
 
  /*

Thanks for the patches, I tried this on an ASRock BC-250, also NCT6686D, and it works fine there as well. The board id is NCT6683_CUSTOMER_ID_AMD and all it needed was:

(quoted diff) +2 -1
-              data->customer_id == NCT6683_CUSTOMER_ID_ASROCK8;
+              data->customer_id == NCT6683_CUSTOMER_ID_ASROCK8 ||
+              data->customer_id == NCT6683_CUSTOMER_ID_AMD;

Maybe you can add that as well once you send the v2 of this? (and a

Quoted 9 lines

send a followup myself once this gets merged, whatever you prefer.

Either way I feel like this list is going to grow, maybe a

switch (data->customer_id) {
...

would work out better long term here.

Or maybe add a boolean have_fan_control or similar to struct nct6683_data, populate it in the probe function, and just use it.

Thanks,
Guenter

Tested-by on the v1 series
#14 lore raw
In reply to Johan Dahlin

Hi Johan!

I have the same board in my system so I wanted to help out:
ASRock B850 Steel Legend WiFi, BIOS 4.10 (02/10/2026), NCT6686D EC firmware 1.0 build 10/29/24.

Tested the whole series twice: on 05441d697f7f (7.4-rc1 + 132), and on 7.4-rc2, both without issues.

Patch 2/5 needed git am -3 because the docs changed in 04f4079ee61a ("hwmon: (nct6683) Add more MSI boards to list of tested boards"). The driver probes without force, and pwmN_enable reads 2 after probe.

Manual control works on CPU_FAN1/2, AIO_PUMP and CHA_FAN1/3 with fanN tracking pwmN.
CHA_FAN2 is untested (fan cable too short) but by elimination it should be fan5/pwm5.

Also tested patch 4/5; a fan in manual mode at pwm 255 went back to EC control on rmmod. pwm6_enable read 2 after reload.

I didn't test suspend/resume, or the retry path in 1/5 (I never caught a lost write).

Is a v2 planned with the requested changes? Happy to test it!

PS: this is my first time on the kernel mailing list, pointers welcome.

For the whole series: