[PATCH 4/5] hwmon: (nct6683) Restore fan control mode on driver removal
From: Johan Dahlin
Date: Tue Aug 25 2026 - 05:27:32 EST
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.
Signed-off-by: Johan Dahlin <jdahlin@xxxxxxxxx>
---
drivers/hwmon/nct6683.c | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
index 0324ace707a5..6825e6c3af34 100644
--- a/drivers/hwmon/nct6683.c
+++ b/drivers/hwmon/nct6683.c
@@ -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);
--
2.53.0