Skip to content

drivers: wdt: npcx: add wdt driver support for npck3 #92379

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2025

Conversation

alvsun
Copy link
Contributor

@alvsun alvsun commented Jun 30, 2025

Enables the extended Watchdog Timer driver for npck3.

Comment on lines 26 to 27
bool "Extended NPCX watchdog driver support"
default y if DT_HAS_NUVOTON_NPCX_WATCHDOG_NPCKN_V1_ENABLED
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has the potential of creating an inconsistent situation if you'll ever have a chip with multiple watchdog timers, where the change in one of the compatibles result in a change in code for all the instances. Plus there's lot of boilerplate, would it make sense to use CONFIG_SOC_SERIES_NPCK3 instead?

Comment on lines 379 to 381
compatible = "nuvoton,npcx-watchdog", "nuvoton,npcx-watchdog-npckn-v1";
reg = <0x400d8000 0x2000>;
t0-out = <&wui_t0out>;
Copy link
Contributor

@bjarki-andreasen bjarki-andreasen Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are two ways to do this in zephyr

a. Add a separate compatible, like "nuvoton,npcx-watchdog-npckn-v1", and use that as the primary and only compatible for the hardware. We don't have loadable drivers to choose from at runtime in order of specificity, the one driver included is the one you get, so only the one, specific compatible you will build a driver for, should be present.

b. add the extended feature as a flag, which seems like the way easiest solution here. add a boolean like is-extended; or supports-extended; or something to the binding for "nuvoton,npcx-watchdog", store the boolean in driver config, and check for it in the driver, no new Kconfig required :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I second this, property seems the easier to maintain, but see my comment above, if this matches with some specific soc families it may be even simpler to use one of those options, ST does it all over the place (and to be perfectly honest the result is not pretty, but it works for them)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @fabiobaltieri @bjarki-andreasen
Thanks for the useful feedback.

We use a compatible-based approach to handle scenarios like the following:
For example, if a future NPCK5 series is designed to be compatible with NPCK3,
we can simply reuse the same compatible string in the DTS node to extend driver support, without modifying the existing driver logic.

This approach avoids adding additional conditional checks in Kconfig,
such as repeatedly updating WDT_NPCX_EX with new SoC series macros (e.g., CONFIG_SOC_SERIES_NPCK3 || CONFIG_SOC_SERIES_NPCK5),
which can become harder to maintain as more SoC series are introduced and may sometimes be unintentionally missed.

By leveraging the compatible mechanism, hardware inheritance and driver extension can be centralized in the device tree, keeping the driver code cleaner and reducing boilerplate.

As the number of supported variants grows, this design provides a more sustainable and scalable path for future maintenance and expansion.

Regarding the inconsistent situation that @fabiobaltieri mentioned,
We assume that the compatible string should be assigned to the same value for all instances of the same hardware module in a SoC. And they shouldn't be changed lightly.

If you have better suggestions or further concerns, please feel free to let me know.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the suggestion is to add a boolean property instead of a new compatible, should be a way less intrusive change, especially if you have more variations in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the boolean property, we have a couple of concerns and would appreciate your thoughts:

  1. Code Size Impact:
    Since runtime boolean properties rely on runtime checks, the related code paths will always be included in the final binary.
    If we use compile-time #ifdefs (based on SoC configs), we can completely exclude unused code paths, which is critical for our resource-constrained platforms.
    Do you have any recommended practices to minimize code size increase when using runtime boolean properties?

  2. Future Compatibility:
    If a future SoC (e.g., NPCK6) inherits features from both NPCK3 and NPCK5 while introducing additional unique functionalities, we would need to introduce more boolean flags to represent these new combinations, which may lead to increased complexity and harder maintenance.
    For example:
    supports-extended; for NPCK3 & NPCK5
    supports-extended-k6; for NPCK6
    Would you still recommend using the boolean flag approach for managing such evolving scenarios?

Note:
Since we have just started submitting the K3 PR, we plan to gradually submit other modules with minor changes (e.g., #89480, #90982) and gradually adopt this mechanism.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We also saw the similar usage in lpuart1 node of stm32 that assigns two compatible strings compatible = "st,stm32-lpuart", "st,stm32-uart"; in the compatible property and use the string st_stm32_lpuart to guard its specific codes in the driver.

Copy link
Contributor

@bjarki-andreasen bjarki-andreasen Jul 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. we have DT_ANY_INST_HAS_PROP_STATUS_OKAY() to check if any device has the flag enabled and has status okay, so you can compile out the boolean if not needed :)
  2. using separate, unique compats would be the way to go if its not the same hardware block with slight differences in features, but different hardware blocks. But its up to you which route you think matches best

@alvsun alvsun marked this pull request as draft July 8, 2025 05:51
@alvsun alvsun force-pushed the npcx_k3_wdt branch 2 times, most recently from c9c0677 to c302bf5 Compare July 8, 2025 06:24
@alvsun alvsun marked this pull request as ready for review July 8, 2025 09:27
@@ -379,6 +379,7 @@
compatible = "nuvoton,npcx-watchdog";
reg = <0x400d8000 0x2000>;
t0-out = <&wui_t0out>;
support-npckn-v1; /* Enable NPCKn driver */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: wouldn't bother with the comment, the property name is descriptive enough

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Enables the extended Watchdog Timer driver for npck3.

Signed-off-by: Alvis Sun <[email protected]>
Signed-off-by: Mulin Chao <[email protected]>
Copy link

sonarqubecloud bot commented Jul 9, 2025

@dkalowsk dkalowsk added this to the v4.3.0 milestone Jul 11, 2025
@nashif nashif merged commit 5b1d16d into zephyrproject-rtos:main Jul 19, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Watchdog Watchdog platform: Nuvoton NPCM platform: Nuvoton NPCX Nuvoton NPCX platform: Nuvoton Numicro Numaker Nuvoton Technology Corporation, Numicro Numaker
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants