drivers/hwmon/pmbus/adm1266.c | 155 ++++++++++++++++++++++++++++++++++++------ 1 file changed, 134 insertions(+), 21 deletions(-)
This is what remains of the v3 series after Guenter applied patches
1/5 (firmware_revision) and 5/5 (GPIO line label) to hwmon-next, and
asked for patch 4/5 (rtc_class) to be dropped.
Patch 1 adds a write-only clear_blackbox debugfs file. Devices
configured for single-recording mode (BLACKBOX_CONFIG[0] = 0) need
an explicit clear once the 32-record buffer fills; the documented
sub-command ({0xFE, 0x00} block-write to 0xDE) wasn't reachable
from userspace. The write takes pmbus_lock so it serialises against
the multi-record nvmem blackbox-read iteration (which now also runs
under pmbus_lock after the parallel "hwmon: (pmbus/adm1266) GPIO,
NVMEM, and debugfs accessor fixes" series).
Patch 2 exposes the non-volatile POWERUP_COUNTER (0xE4) via debugfs.
The same value is embedded in every blackbox record, so the live
value lets userspace match a captured record back to the boot it
came from when correlating logs. The block-read is taken under
pmbus_lock to serialise against any pmbus_core PAGE+register
sequence on the device.
Patch 3 adds an RW rtc debugfs file backing the chip's SET_RTC
(0xDF) register. The driver seeds SET_RTC once at probe with
ktime_get_real_seconds(); over a long uptime the chip's counter
drifts away from host wall-clock and the timestamp embedded in
each blackbox record stops being meaningful in wall-clock terms.
Read returns the chip's current seconds counter (useful for
observing drift). Write makes the kernel re-read
ktime_get_real_seconds() itself and push it to SET_RTC -- the
write payload is ignored, so userspace cannot push a wrong value.
A userspace agent (chrony hook, systemd-timesyncd dispatch script)
can write to this file periodically to keep the chip aligned.
Patch 3 also drops the now-redundant adm1266_set_rtc() probe-time
helper, since the new adm1266_rtc_set() callback does the same
byte-packing and write; probe simply calls
adm1266_rtc_set(client, 0) after pmbus_do_probe().
This series builds on the "GPIO, NVMEM, and debugfs accessor
fixes" series now in hwmon-next, which gives it two invariants the
new debugfs files rely on:
- adm1266_nvmem_read() runs under pmbus_lock, which is what makes
"both clear-blackbox-write and nvmem blackbox read serialise"
work for patch 1.
- adm1266_config_nvmem() / adm1266_config_gpio() are called after
pmbus_do_probe(), so any debugfs / nvmem callback that grabs
pmbus_lock has a live mutex to take.
Signed-off-by: Abdurrahman Hussain <abdurrahman@nexthop.ai>
---
Changes in v5:
- Rebase onto hwmon-next, which now has the "GPIO, NVMEM, and
debugfs accessor fixes" series applied. As a result, the
pre-existing-bug parts of v4 (the pmbus_lock lift in
adm1266_nvmem_read() and the adm1266_config_nvmem() probe-order
move that were folded into patch 1, plus former patch 3
"serialize sequencer_state debugfs read with pmbus_lock") are
now in the tree via that series with Fixes: tags and Cc: stable,
so they come out of this feature series.
- Patch 1 (clear_blackbox) shrinks accordingly to just the new
debugfs entry and its own pmbus_lock-guarded write handler.
- Drop former patch 3 (state_read lock) for the same reason -- it
is gpio-fixes patch 8 now.
- New patch 3: add an RW rtc debugfs entry exposing the
chip's SET_RTC (0xDF) register. Read returns the chip's
current seconds counter so userspace can observe drift; write
makes the kernel re-read ktime_get_real_seconds() and push it
to SET_RTC (the write payload is ignored). Implements the
combined RW shape Guenter suggested when I asked about
re-exposing SET_RTC after the v3 rtc_class approach was
rejected. Patch 3 also drops the now-redundant
adm1266_set_rtc() probe-time helper -- the new
adm1266_rtc_set() callback does the same work, so probe calls
it directly (with an ignored @val argument) after
pmbus_do_probe().
- Add Assisted-by: trailers to all three patches per
Documentation/process/coding-assistants.rst (Claude Code during
development, sashiko's Gemini-backed reviewer during v2/v3
review cycles).
- Cover body reworked to describe the (now satisfied) gpio-fixes
dependency as a "builds on" rather than "depends on" relation.
- Link to v4: https://patch.msgid.link/20260516-adm1266-v4-0-1f8df4797258@nexthop.ai
Changes in v4:
- Drop former patches 1 (firmware_revision) and 5 (GPIO line label):
applied to hwmon-next by Guenter.
- Drop former patch 4 (rtc_class) per Guenter's review: turning the
chip into a pseudo rtc_class device and making the driver depend
on the RTC subsystem was rejected. The underlying CLOCK_MONOTONIC
-vs- wall-clock bug in the original probe-time seed is fixed
independently in the "hwmon: (pmbus/adm1266) buffer-bound and
timestamp fixes" series sent in parallel, so the seed-at-probe
behaviour becomes correct without this driver needing to depend
on RTC_CLASS.
- Patch 1 (clear_blackbox, was 2/5): take pmbus_lock at the outer
adm1266_nvmem_read() callback rather than inside
adm1266_nvmem_read_blackbox() so it covers the memset of
data->dev_mem, the refill, and the memcpy to userspace as a
single critical section. The nvmem core does not serialize
concurrent reg_read invocations, so the v3 placement still let
the memset race with another reader's memcpy to userspace
(Sashiko review of v3).
- Patch 2 (powerup_counter, was 3/5): take pmbus_lock around the
block-read so the access serialises with any pmbus_core sequence
that sets PAGE on the device (Sashiko review of v3).
- New patch 3: take pmbus_lock in adm1266_state_read() (the
sequencer_state debugfs handler). Same defensive-locking
argument as patches 1 and 2; surfaced while folding similar
fixes into the parallel "hwmon: (pmbus/adm1266) GPIO accessor
fixes" series.
- Link to v3: https://patch.msgid.link/20260512-adm1266-v3-0-a81a479b0bb0@nexthop.ai
Changes in v3:
- Patch 2: take guard(pmbus_lock)(client) in
adm1266_clear_blackbox_write() and adm1266_nvmem_read_blackbox()
to serialise the clear against the multi-record nvmem read loop
(both share command 0xDE). Also move adm1266_config_nvmem() to
after pmbus_do_probe() so the blackbox nvmem entry isn't exposed
to userspace before the PMBus mutex is initialised (Sashiko
review).
- Patch 4: take guard(pmbus_lock)(client) in the RTC
read_time/set_time callbacks to serialise against the PMBus
core's PAGE+register sequences. Move adm1266_register_rtc() to
after pmbus_do_probe() for the same reason as the config_nvmem
move; /dev/rtcN being opened by userspace (systemd-timesyncd,
udev) before probe completed would otherwise hit an
uninitialised mutex (observed on hardware, also flagged by
Sashiko).
- Link to v2: https://patch.msgid.link/20260510-adm1266-v2-0-3a22b903c2f1@nexthop.ai
Changes in v2:
- Drop the v1 "use wall-clock seconds for SET_RTC" and "write
fractional-seconds field of SET_RTC" patches. v1 patch 6 already
added an rtc_class device, so userspace now owns the time-set
policy and the probe-time seed is no longer needed - removing it
also fixes the cross-reboot blackbox-correlation regression the
seed introduced.
- In the rtc_class patch, write the SET_RTC fractional-seconds
bytes as zero rather than computing them from a timespec64. The
rtc_class API is second-precision, so the divide that v1 patch 2
was adding never produced a non-zero result anyway. This also
drops the 64-bit divide that would have failed to link on 32-bit
builds (Sashiko review).
- Use %d (decimal) for the I2C adapter number in GPIO line labels,
matching the i2c-N convention used elsewhere in Linux. v1 used
%x, which rendered bus numbers >= 10 in hexadecimal (Sashiko
review).
- Link to v1: https://patch.msgid.link/20260508-adm1266-v1-0-ec08bf29e0ce@nexthop.ai
To: Guenter Roeck <linux@roeck-us.net>
To: Alexandru Tachici <alexandru.tachici@analog.com>
Cc: linux-hwmon@vger.kernel.org
Cc: linux-kernel@vger.kernel.org
---
Abdurrahman Hussain (3):
hwmon: (pmbus/adm1266) add clear_blackbox debugfs entry
hwmon: (pmbus/adm1266) add powerup_counter debugfs entry
hwmon: (pmbus/adm1266) add rtc debugfs entry
drivers/hwmon/pmbus/adm1266.c | 155 ++++++++++++++++++++++++++++++++++++------
1 file changed, 134 insertions(+), 21 deletions(-)
---
base-commit: 7e63dac55e2de42a7947613c01e3d3c0fb9c15fc
change-id: 20260507-adm1266-cf3af42dc3d2
Best regards,
--
Abdurrahman Hussain <abdurrahman@nexthop.ai>
© 2016 - 2026 Red Hat, Inc.