From: Johan Dahlin <jdahlin@gmail.com>
To: Guenter Roeck <linux@roeck-us.net>
Cc: linux-hwmon@vger.kernel.org, linux-kernel@vger.kernel.org,
Alwyn Kik <alwyn@kik.pw>,
Fabio Baltieri <fabio.baltieri@gmail.com>,
Hamza Mahfooz <someguy@effective-light.com>,
Johan Dahlin <jdahlin@gmail.com>
Subject: [PATCH v2 2/7] hwmon: (nct6683) Restore automatic fan control on driver removal
Date: Wed, 11 Nov 2026 09:28:33 +0100 [thread overview]
Message-ID: <20261111082838.1418051-3-jdahlin@gmail.com> (raw)
In-Reply-To: <20261111082838.1418051-1-jdahlin@gmail.com>
A fan switched to manual mode through pwmN_enable keeps its last duty
cycle after the driver is unloaded, with nothing left to adjust it.
Return the channels the driver switched to manual mode to automatic mode
when the device is removed, using the bitmap kept for resume. Other
channels are not touched.
Signed-off-by: Johan Dahlin <jdahlin@gmail.com>
---
drivers/hwmon/nct6683.c | 34 ++++++++++++++++++++++++++++++++++
1 file changed, 34 insertions(+)
diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
index 0565ca9290eb..d43dcf90048b 100644
--- a/drivers/hwmon/nct6683.c
+++ b/drivers/hwmon/nct6683.c
@@ -1584,6 +1584,32 @@ static void nct6683_setup_sensors(struct nct6683_data *data)
}
}
+/*
+ * Hand the fans the driver switched to manual mode back to the EC, so that
+ * they do not stay at a fixed duty cycle once nobody is left to adjust it.
+ */
+static void nct6683_restore_fan_control(void *_dev)
+{
+ struct device *dev = _dev;
+ struct nct6683_data *data = dev_get_drvdata(dev);
+ unsigned long manual;
+ int ch, err;
+
+ mutex_lock(&data->update_lock);
+ manual = data->pwm_manual;
+ for_each_set_bit(ch, &manual, NCT6683_NUM_REG_FAN) {
+ err = nct6683_fan_ctrl_update(data, ch, false, -1);
+ if (err) {
+ dev_warn(dev, "Failed to restore automatic mode of pwm%d: %d\n",
+ ch + 1, err);
+ /* The EC does not respond, skip the remaining channels */
+ if (err == -ETIMEDOUT)
+ break;
+ }
+ }
+ mutex_unlock(&data->update_lock);
+}
+
static int nct6683_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
@@ -1593,6 +1619,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);
@@ -1710,6 +1737,13 @@ static int nct6683_probe(struct platform_device *pdev)
nct6683_read(data, NCT6683_REG_VERSION_LO),
build);
+ if (data->have_fan_ctrl) {
+ err = devm_add_action_or_reset(dev, nct6683_restore_fan_control,
+ dev);
+ 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
next prev parent reply other threads:[~2026-11-11 8:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-11 8:28 [PATCH v2 0/7] hwmon: (nct6683) Fan control and sensor names for ASRock NCT6686D boards Johan Dahlin
2026-11-11 8:28 ` [PATCH v2 1/7] hwmon: (nct6683) Add customer ID for ASRock B850 Steel Legend WiFi Johan Dahlin
2026-11-11 8:28 ` Johan Dahlin [this message]
2026-11-11 8:28 ` [PATCH v2 3/7] hwmon: (nct6683) Enable fan control on " Johan Dahlin
2026-11-11 8:28 ` [PATCH v2 4/7] hwmon: (nct6683) Enable fan control on ASRock BC-250 Johan Dahlin
2026-11-11 8:28 ` [PATCH v2 5/7] hwmon: (nct6683) Name the sensors of the ASRock B850 Steel Legend WiFi Johan Dahlin
2026-11-11 8:28 ` [PATCH v2 6/7] hwmon: (nct6683) Name the fan headers " Johan Dahlin
2026-11-11 8:28 ` [PATCH v2 7/7] hwmon: (nct6683) Scale the +5V and +12V inputs " 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=20261111082838.1418051-3-jdahlin@gmail.com \
--to=jdahlin@gmail.com \
--cc=alwyn@kik.pw \
--cc=fabio.baltieri@gmail.com \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=someguy@effective-light.com \
/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®