mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Johan Dahlin <jdahlin@gmail.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
	Johan Dahlin <jdahlin@gmail.com>
Subject: [PATCH 4/5] hwmon: (nct6683) Restore fan control mode on driver removal
Date: Tue, 25 Aug 2026 11:25:45 +0200	[thread overview]
Message-ID: <20260825092546.669450-5-jdahlin@gmail.com> (raw)
In-Reply-To: <20260825092546.669450-1-jdahlin@gmail.com>

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@gmail.com>
---
 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


  parent reply	other threads:[~2026-08-25  9:25 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-25  9:25 [PATCH 0/5] hwmon: (nct6683) Fan control for ASRock B850 Steel Legend WiFi Johan Dahlin
2026-08-25  9:25 ` [PATCH 1/5] hwmon: (nct6683) Retry pwm writes until they take effect Johan Dahlin
2026-08-25  9:25 ` [PATCH 2/5] hwmon: (nct6683) Add customer ID for ASRock B850 Steel Legend WiFi Johan Dahlin
2026-08-25  9:25 ` [PATCH 3/5] hwmon: (nct6683) Add pwm[1-8]_enable Johan Dahlin
2026-08-25  9:25 ` Johan Dahlin [this message]
2026-08-25  9:25 ` [PATCH 5/5] hwmon: (nct6683) Enable pwm control on ASRock B850 Steel Legend WiFi Johan Dahlin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260825092546.669450-5-jdahlin@gmail.com \
    --to=jdahlin@gmail.com \
    --cc=linux-hwmon@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@roeck-us.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®