Watchdog for ZynqMP RPU#789
Conversation
- kernel level watchdog initialization - reload value in board_config.h for user - watchdog prescaler set to 512 (LPD_LSBUS_CLK) - RPU reset on timeout - syscall for reload YT: DO-836
| *(zynq_common.swdt_lpd + swdt_lpd_control) = (SWDT_CONTROL_CKEY | (0xFFF << SWDT_CONTROL_CRV_BIT)| SWDT_CONTROL_CLKSEL ); | ||
|
|
||
| #if defined(WATCHDOG) | ||
| /* set cotnrol: LPD_LSBUS_CLK scaler = 512 (gives reload value from ~20ms to 85s fro 100MHz LPD_LSBUS_CLK)*/ |
There was a problem hiding this comment.
[codespell] reported by reviewdog 🐶
fro ==> for, from
| * in the UG: "Note: If a restart signal is received the prescaler should be reset." | ||
| */ | ||
| *(zynq_common.swdt_lpd + swdt_lpd_mode) = (SWDT_MODE_ZKEY); | ||
| *(zynq_common.swdt_lpd + swdt_lpd_control) = (SWDT_CONTROL_CKEY | (0xFFF << SWDT_CONTROL_CRV_BIT)| SWDT_CONTROL_CLKSEL ); |
There was a problem hiding this comment.
[clang-format-pr] reported by reviewdog 🐶
suggested fix
| *(zynq_common.swdt_lpd + swdt_lpd_control) = (SWDT_CONTROL_CKEY | (0xFFF << SWDT_CONTROL_CRV_BIT)| SWDT_CONTROL_CLKSEL ); | |
| *(zynq_common.swdt_lpd + swdt_lpd_control) = (SWDT_CONTROL_CKEY | (0xFFF << SWDT_CONTROL_CRV_BIT) | SWDT_CONTROL_CLKSEL); |
There was a problem hiding this comment.
Code Review
This pull request introduces watchdog (SWDT) support for the ZynqMP platform, including register definitions, initialization, and platform control handlers for enabling and reloading the watchdog. However, there are critical issues in the implementation: the SWDT_CONTROL_CKEY shift value is incorrect (should be shifted by 14 instead of 12), which prevents control register writes from taking effect. Additionally, the platform control handlers for setting watchdog reload and enable do not set the return value ret to 0 on success, causing them to incorrectly return an error code to the caller.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| #define SWDT_MODE_WDEN (0x1U) | ||
| #define SWDT_MODE_RSTEN (0x1U << 1) | ||
| #define SWDT_MODE_RSTLN (0x4U << 4) /* reset len = 4 -> 32 clock cycles*/ | ||
| #define SWDT_CONTROL_CKEY (SWDT_CKEY << 12) |
There was a problem hiding this comment.
In the ZynqMP SWDT Control Register (WDG_CONTROL), the CKEY field is located at bits [25:14], while the CRV (Counter Reload Value) field is at bits [13:2] (12 bits), and CLKSEL is at bits [1:0]. Shifting SWDT_CKEY (0x248) by 12 instead of 14 will result in an incorrect key being written to the register, causing the hardware to ignore any writes to the control register. This prevents both watchdog initialization and subsequent reload value updates from taking effect.
#define SWDT_CONTROL_CKEY (SWDT_CKEY << 14)| if ((data->action == pctl_set) && (data->wdg_enable.enable == 1)) { | ||
| *(zynq_common.swdt_lpd + swdt_lpd_restart) = SWDT_RESTART_RKEY; | ||
| *(zynq_common.swdt_lpd + swdt_lpd_mode) = (SWDT_MODE_ZKEY | SWDT_MODE_RSTLN | SWDT_MODE_RSTEN | SWDT_MODE_WDEN); | ||
| } | ||
| else if ((data->action == pctl_set) && (data->wdg_enable.enable == 0)) { | ||
| *(zynq_common.swdt_lpd + swdt_lpd_restart) = SWDT_RESTART_RKEY; | ||
| *(zynq_common.swdt_lpd + swdt_lpd_mode) = (SWDT_MODE_ZKEY); | ||
| } |
There was a problem hiding this comment.
When performing a pctl_set action for pctl_wdg_enable, the return value ret is not set to 0 upon success. Since ret is initialized to -1, the function will return -1 (error) to the caller even when the enable/disable operation succeeded.
if ((data->action == pctl_set) && (data->wdg_enable.enable == 1)) {
*(zynq_common.swdt_lpd + swdt_lpd_restart) = SWDT_RESTART_RKEY;
*(zynq_common.swdt_lpd + swdt_lpd_mode) = (SWDT_MODE_ZKEY | SWDT_MODE_RSTLN | SWDT_MODE_RSTEN | SWDT_MODE_WDEN);
ret = 0;
}
else if ((data->action == pctl_set) && (data->wdg_enable.enable == 0)) {
*(zynq_common.swdt_lpd + swdt_lpd_restart) = SWDT_RESTART_RKEY;
*(zynq_common.swdt_lpd + swdt_lpd_mode) = (SWDT_MODE_ZKEY);
ret = 0;
}| break; | ||
|
|
||
| case pctl_wdg_enable: | ||
| if ((data->action == pctl_set) && (data->wdg_enable.enable == 1)) { |
| *(zynq_common.swdt_lpd + swdt_lpd_restart) = SWDT_RESTART_RKEY; | ||
| *(zynq_common.swdt_lpd + swdt_lpd_mode) = (SWDT_MODE_ZKEY | SWDT_MODE_RSTLN | SWDT_MODE_RSTEN | SWDT_MODE_WDEN); | ||
| } | ||
| else if ((data->action == pctl_set) && (data->wdg_enable.enable == 0)) { |
| } | ||
| else if (data->action == pctl_get) { | ||
| ret = 0; | ||
| data->wdg_enable.enable = (*(zynq_common.swdt_lpd + swdt_lpd_mode) & SWDT_MODE_WDEN) ? 1 : 0; |
| } | ||
| else if (data->action == pctl_get) { | ||
| ret = 0; | ||
| data->wdg_enable.enable = (*(zynq_common.swdt_lpd + swdt_lpd_mode) & SWDT_MODE_WDEN) ? 1 : 0; |
Unit Test Results10 860 tests +275 10 190 ✅ +275 53m 6s ⏱️ +58s Results for commit a6bb355. ± Comparison against base commit 57b3041. This pull request removes 3 and adds 278 tests. Note that renamed tests count towards both.♻️ This comment has been updated with latest results. |
- platformctl for reload and enable YT: DO-836
251770b to
a6bb355
Compare
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces support for the System Watchdog Timer (SWDT) on the ZynqMP platform, including initialization, reload, and enable/disable controls via hal_platformctl. However, two issues were identified: the register offsets defined in zynqmp_regs.h are incorrect due to a gap between the mode and control registers, which will lead to writing to incorrect registers, and there is a mismatch in SWDT_MODE_RSTLN where the value 4 is used instead of 3 for a 32-clock-cycle reset pulse length.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| swdt_lpd_mode = 0x00, | ||
| swdt_lpd_control, | ||
| swdt_lpd_restart, | ||
| swdt_lpd_status |
There was a problem hiding this comment.
The register offsets defined in the enum are incorrect. In the ZynqMP SWDT, there is a gap between the mode register (offset 0x00) and the control register (offset 0x08). Since these are used as indices for a volatile u32 * pointer, the enum values must represent the word offsets (index) of each register. Currently, swdt_lpd_control is implicitly assigned 1 (which corresponds to byte offset 0x04, a reserved area), and swdt_lpd_restart is assigned 2 (which corresponds to byte offset 0x08, the control register). This will cause watchdog configuration and reload operations to write to the wrong registers.
| swdt_lpd_mode = 0x00, | |
| swdt_lpd_control, | |
| swdt_lpd_restart, | |
| swdt_lpd_status | |
| swdt_lpd_mode = 0x00, | |
| swdt_lpd_control = 0x02, | |
| swdt_lpd_restart = 0x03, | |
| swdt_lpd_status = 0x04 |
| struct { | ||
| __u32 reload; | ||
| } wdg_reload; | ||
|
|
||
| struct { | ||
| __u8 enable; | ||
| } wdg_enable; |
There was a problem hiding this comment.
nitpick: I could be wrong on this, but wouldn't it be clearer to do something like this:
union {
__u32 reload;
__u8 enable;
} wdg;Then again, all the other options have corresponding structures (except for mioclock which I guess belongs to mio structure?)...
|
|
||
| case pctl_wdg_reload: | ||
| /* If watchdog is not enabled this will take no effects*/ | ||
| if ((data->action == pctl_set) && (data->wdg_reload.reload >= 0x000FFFU) && (data->wdg_reload.reload <= 0xFFFFFFU)) { |
There was a problem hiding this comment.
returning -EINVAL in case the latter 2 conditions are wrong could be more informative to the user
| case pctl_wdg_reload: | ||
| /* If watchdog is not enabled this will take no effects*/ | ||
| if ((data->action == pctl_set) && (data->wdg_reload.reload >= 0x000FFFU) && (data->wdg_reload.reload <= 0xFFFFFFU)) { | ||
| *(zynq_common.swdt_lpd + swdt_lpd_control) = (SWDT_CONTROL_CKEY | ((data->wdg_reload.reload >> 12) & 0xFFFU) << SWDT_CONTROL_CRV_BIT | SWDT_CONTROL_CLKSEL); |
There was a problem hiding this comment.
nitpick: add parenthesis over ((data->wdg_reload.reload >> 12) & 0xFFFU) << SWDT_CONTROL_CRV_BIT


Description
This PR introduces Watchdog handlers for ZynqMP RPU
hal_wdgReloadis now definedplatformctl:pctl_wdg_reloadandpctl_wdg_enable(set new reload value,enable/disable respectively) are now defined
Motivation and Context
The ZynqMP RPU targets critical application in UAV domain. By default it is configured
to run in lock-step. Watchdog support is required for this kind of application.s
Types of changes
How Has This Been Tested?
Checklist:
Special treatment