This series provides a fix for the wdt_start() function, which can
print incorrect timeout values in cases where the function is
called with a timeout value greater than the hardware-supported
maximum. The current implementation prints the requested value, so,
for example, the console may show that the watchdog timeout is set to
60 seconds when it is in practice clamped to 10 seconds by the device.

The series introduces the max_timeout_ms value into the per-device
uclass-plat data. By default, this value is initialized to 0, and
drivers should write the hardware-limited max_timeout_ms value into
the plat-data typically during probing.

The hardware still performs the actual clamping; max_timeout_ms only
lets the uclass report the effective value in the start-path print.
The default value 0 is considered "limitless", i.e. on drivers that
do not set the value, the prints are unaffected by this series.

The series implements this support in sbsa_gwdt, octeontx_wdt and
sandbox_wdt drivers.

This fix improves the overall correctness of the console output and
can be helpful in debugging cases, since the console prints reflect the
real timeout on the device when the driver supports the feature.
If it is unsupported on the device, the print remains as it was before.

Patch summary:
- Patch 1: Add per_device_plat_auto to the wdt uclass and a max_timeout_ms
field in a new wdt_uc_plat struct. wdt_start() uses it to report the effective
(clamped) timeout when the originally requested value is greater than the 
reported
maximum value.
- Patch 2: Set max_timeout_ms in sbsa_gwdt_probe()
- Patch 3: Set max_timeout_ms in octeontx_wdt_probe()
- Patch 4: Set max_timeout_ms in sandbox_wdt_probe() and
add clamp to sandbox_wdt_start() so the path is testable.
- Patch 5: Add a DM test for clamped and unclamped cases.

Signed-off-by: Juuso Rinta <[email protected]>
---
Changes in v2:
- Reworked approach. Dropped the get_timeout operation and switched to
per-device uclass-plat data (max_timeout_ms) for reporting effective
timeout in wdt_start().
- Added struct wdt_uc_plat and .per_device_plat_auto in the WDT uclass.
max_timeout_ms = 0 is treated as no driver-reported limit.
- Dropped the wdt gettimeout subcommand changes from v1.
- Updated sbsa_gwdt, octeontx_wdt and sandbox_wdt drivers to set 
max_timeout_ms in probe.
- Extended sandbox_wdt for testability by adding an emulated max timeout
and clamp path.
- Reworked DM tests to cover unclamped and clamped startup print paths, as
well as max_timeout_ms set/not-set behavior
- Minor cleanup in wdt_start() string handling
- Link to v1: 
https://patch.msgid.link/[email protected]

To: [email protected]
Cc: Stefan Roese <[email protected]>
Cc: Tom Rini <[email protected]>
Cc: Patrice Chotard <[email protected]>
Cc: Peng Fan <[email protected]>
Cc: Yao Zi <[email protected]>
Cc: Juuso Rinta <[email protected]>
Cc: Antonio Borneo <[email protected]>
Cc: Aaro Koskinen <[email protected]>
Cc: Simon Glass <[email protected]>

---
Juuso Rinta (5):
      watchdog: wdt-uclass: report effective timeout in start print
      watchdog: sbsa_gwdt: set max_timeout_ms in probe
      watchdog: octeontx_wdt: set max_timeout_ms in probe
      watchdog: sandbox_wdt: set max_timeout_ms in probe
      test: wdt: add a test for max_timeout_ms

 arch/sandbox/include/asm/state.h |  2 ++
 drivers/watchdog/octeontx_wdt.c  | 17 ++++++++++++++
 drivers/watchdog/sandbox_wdt.c   | 15 ++++++++++++
 drivers/watchdog/sbsa_gwdt.c     | 12 ++++++++++
 drivers/watchdog/wdt-uclass.c    | 34 ++++++++++++++++++++++++----
 include/wdt.h                    | 11 +++++++++
 test/dm/wdt.c                    | 49 ++++++++++++++++++++++++++++++++++++++--
 7 files changed, 133 insertions(+), 7 deletions(-)
---
base-commit: 1b8283bd3220e898d338fb98929f0b06ed63da84
change-id: 20260427-rinta-watchdog-gettime-6ae2e0a76983

Best regards,
--  
Juuso Rinta <[email protected]>

Reply via email to