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 1/5] hwmon: (nct6683) Retry pwm writes until they take effect
Date: Tue, 25 Aug 2026 11:25:42 +0200 [thread overview]
Message-ID: <20260825092546.669450-2-jdahlin@gmail.com> (raw)
In-Reply-To: <20260825092546.669450-1-jdahlin@gmail.com>
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.
Signed-off-by: Johan Dahlin <jdahlin@gmail.com>
---
drivers/hwmon/nct6683.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/drivers/hwmon/nct6683.c b/drivers/hwmon/nct6683.c
index e1c36c95affb..b524a45b1471 100644
--- a/drivers/hwmon/nct6683.c
+++ b/drivers/hwmon/nct6683.c
@@ -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);
--
2.53.0
next prev 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 ` Johan Dahlin [this message]
2026-08-25 9:25 ` [PATCH 2/5] hwmon: (nct6683) Add customer ID " Johan Dahlin
2026-08-25 9:25 ` [PATCH 3/5] hwmon: (nct6683) Add pwm[1-8]_enable Johan Dahlin
2026-08-25 9:25 ` [PATCH 4/5] hwmon: (nct6683) Restore fan control mode on driver removal Johan Dahlin
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-2-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