watchdog: npcm: Add reset status detection support
Subsystems (4)
Tomer Maimon
maintainerv2 cover watchdog: npcm: Add reset status detection support
This series documents and implements reset indication reporting for the NPCM watchdog driver on NPCM7xx and NPCM8xx systems, and documents the optional GCR syscon property used by that support.
Patch 1 updates the watchdog binding to allow the optional ``nuvoton,sysgcr`` property used for reset-cause reporting. Patch 2 adds watchdog documentation that describes the bootstatus mapping.
Patch 3 reads the SoC reset indication bits and maps them into the existing watchdog bootstatus flags for NPCM750 and NPCM845, while leaving WPCM450 unchanged.
Addressed comments from:
- Krzysztof Kozlowski: https://patchwork.ozlabs.org/project/openbmc/patch/[email protected]/
- Guenter Roeck: https://patchwork.ozlabs.org/project/openbmc/patch/[email protected]/
Changes since version 1:
- Modify reset detection handle in the watchodg.
- reword patch 1 to use the GCR syscon-property wording from the applied NPCM reset binding update and drop the optional property from the binding example.
- reword the patch subjects and commit message bodies to match current kernel dt-bindings, docs, and watchdog style.
Tomer Maimon (3):
dt-bindings: watchdog: npcm: add GCR syscon property
docs: watchdog: npcm: Add reset status description
watchdog: npcm: add bootstatus support
.../watchdog/nuvoton,npcm750-wdt.yaml | 6 + Documentation/watchdog/index.rst | 1 + Documentation/watchdog/npcm_wdt.rst | 70 +++++++ drivers/watchdog/npcm_wdt.c | 197 +++++++++++++++++- 4 files changed, 272 insertions(+), 2 deletions(-) create mode 100644 Documentation/watchdog/npcm_wdt.rst
Signature · 1 line
2.34.1
Tomer Maimon
maintainerPATCH v2 1/3 dt-bindings: watchdog: npcm: add GCR syscon property
Describe syscon property that handles general control registers (GCR) in Nuvoton BMC NPCM watchdog driver.
--- .../devicetree/bindings/watchdog/nuvoton,npcm750-wdt.yaml | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/watchdog/nuvoton,npcm750-wdt.yaml +6 -0
@@ -40,6 +40,12 @@ properties: clock-frequency: description: Frequency in Hz of the clock that drives the NPCM timer. + nuvoton,sysgcr: + $ref: /schemas/types.yaml#/definitions/phandle + description: + a phandle to access GCR registers on NPCM750 and NPCM845 watchdog + instances. + required: - compatible - reg
Signature · 1 line
2.34.1
Re: [PATCH v2 1/3] dt-bindings: watchdog: npcm: add GCR syscon property
Quoted 2 lines · Tomer Maimon
Describe syscon property that handles general control registers (GCR) in Nuvoton BMC NPCM watchdog driver.
Why? Well, you try to answer by saying something about driver, but we do not add bindings for drivers. Instead hardware should be the reason.
Anyway, why is this needed now?
Quoted 11 lines
Signed-off-by Tomer Maimon <[email protected]>--- .../devicetree/bindings/watchdog/nuvoton,npcm750-wdt.yaml | 6 ++++++ 1 file changed, 6 insertions(+)Documentation/devicetree/bindings/watchdog/nuvoton,npcm750-wdt.yaml +0
-0
Documentation/devicetree/bindings/watchdog/nuvoton,npcm750-wdt.yaml properties: · line 47
Quoted 8 lines
Documentation/devicetree/bindings/watchdog/nuvoton,npcm750-wdt.yaml +5
-0@@ -40,6 +40,12 @@ properties: clock-frequency: description: Frequency in Hz of the clock that drives the NPCM timer. + nuvoton,sysgcr: + $ref: /schemas/types.yaml#/definitions/phandle + description: + a phandle to access GCR registers on NPCM750 and NPCM845 watchdog + instances.
Here you write also for what purpose.
Best regards,
Krzysztof
Tomer Maimon
maintainerRe: [PATCH v2 1/3] dt-bindings: watchdog: npcm: add GCR syscon property
Hi Krzysztof,
Quoted 9 lines · Krzysztof Kozlowski
Quoted 2 lines · Tomer Maimon
Describe syscon property that handles general control registers (GCR) in Nuvoton BMC NPCM watchdog driver.
Why? Well, you try to answer by saying something about driver, but we do not add bindings for drivers. Instead hardware should be the reason.
Anyway, why is this needed now?
It is needed for accessing the reset indication registers. I would mention it in the commit message.
Quoted 24 lines
Quoted 12 lines
Signed-off-by Tomer Maimon <[email protected]>--- .../devicetree/bindings/watchdog/nuvoton,npcm750-wdt.yaml | 6 ++++++ 1 file changed, 6 insertions(+)Documentation/devicetree/bindings/watchdog/nuvoton,npcm750-wdt.yaml +0
-0Documentation/devicetree/bindings/watchdog/nuvoton,npcm750-wdt.yaml properties: · line 47
Quoted 8 lines
Documentation/devicetree/bindings/watchdog/nuvoton,npcm750-wdt.yaml +5
-0@@ -40,6 +40,12 @@ properties: clock-frequency: description: Frequency in Hz of the clock that drives the NPCM timer. + nuvoton,sysgcr: + $ref: /schemas/types.yaml#/definitions/phandle + description: + a phandle to access GCR registers on NPCM750 and NPCM845 watchdog + instances.Here you write also for what purpose.
Quoted 3 lines
Best regards,
Krzysztof
Thanks,
Tomer
Tomer Maimon
maintainerPATCH v2 2/3 docs: watchdog: npcm: Add reset status description
In reply to Tomer MaimonAdd documentation describing how the NPCM watchdog driver reports reset causes through bootstatus on NPCM750 and NPCM845 systems.
Document the reset flag mapping, the watchdog instance mapping for WDIOF_CARDRESET, and the NPCM750/NPCM845 latch handling. Also mention sysfs bootstatus reporting when watchdog sysfs support is enabled.
--- Documentation/watchdog/index.rst | 1 + Documentation/watchdog/npcm_wdt.rst | 70 +++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 Documentation/watchdog/npcm_wdt.rst
Documentation/watchdog/index.rst +1 -0
@@ -9,6 +9,7 @@ Watchdog Support hpwdt mlx-wdt + npcm_wdt pcwd-watchdog watchdog-api watchdog-kernel-api
Documentation/watchdog/npcm_wdt.rst new file +70 -0
70 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v2 2/3] docs: watchdog: npcm: Add reset status description
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider: - [High] UAPI Semantic Violation: Overloading generic watchdog bootstatus flags with unrelated…
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [High] UAPI Semantic Violation: Overloading generic watchdog bootstatus flags with unrelated platform-specific reset causes. --
commit 622b044102abac9e6e33a21b4739ad90ba16eec5
Author: Tomer Maimon <[email protected]>
docs: watchdog: npcm: Add reset status description
This commit adds documentation describing how the NPCM watchdog driver reports reset causes through bootstatus on NPCM750 and NPCM845 systems. It documents the fixed reset flag mapping, watchdog instance mapping, and sysfs reporting behavior.
Quoted 5 lines
Documentation/watchdog/npcm_wdt.rst new file +0
-0
[ ... ]
Quoted 5 lines
+.. list-table:: Reset-cause mapping
Documentation/watchdog/npcm_wdt.rst new file +4
-0+ :header-rows: 1 + + * - Platform + - Reset indication
Documentation/watchdog/npcm_wdt.rst line 32
Quoted 10 lines
Documentation/watchdog/npcm_wdt.rst new file +10
-0+ - Bootstatus flag + - Reported meaning + * - NPCM750 and NPCM845 + - ``PORST`` + - ``WDIOF_OVERHEAT`` + - power-on reset + * - NPCM750 and NPCM845 + - ``CORST`` + - ``WDIOF_FANFAULT`` + - core reset
[Severity: High]
Is it intentional to overload standard watchdog UAPI flags with unrelated platform-specific reset causes?
Mapping "power-on reset" (NPCM_PORST) to WDIOF_OVERHEAT ("Reset due to CPU overheat") and "core reset" (NPCM_CORST) to WDIOF_FANFAULT ("Fan failed") will cause generic userspace applications, system managers, and monitoring tools to misinterpret the values. This could lead to false reports of CPU overheating or fan failures during normal cold boots.
Should these hardware-specific reset reasons be exposed via a dedicated reset-reason framework or custom sysfs attributes instead of redefining standardized generic UAPI flags?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Tomer Maimon
maintainerPATCH v2 3/3 watchdog: npcm: add bootstatus support
In reply to Tomer MaimonThe NPCM750 uses RESSR and the NPCM845 uses INTCR2 to latch reset indications. Read those bits during probe and map them into watchdog bootstatus flags.
For NPCM845, cache the sampled INTCR2 state in SCRPAD10 after the reset status bits are cleared so later probes can report the same boot-time state. Also report WDIOF_CARDRESET for the watchdog instance whose reset bit is latched, while leaving WPCM450 behavior unchanged.
--- drivers/watchdog/npcm_wdt.c | 197 +++++++++++++++++++++++++++++++++++- 1 file changed, 195 insertions(+), 2 deletions(-)
drivers/watchdog/npcm_wdt.c +195 -2
@@ -7,14 +7,51 @@#include <linux/delay.h> #include <linux/interrupt.h> #include <linux/kernel.h> +#include <linux/mfd/syscon.h> #include <linux/module.h> #include <linux/of_irq.h> #include <linux/platform_device.h> +#include <linux/regmap.h> #include <linux/slab.h> #include <linux/watchdog.h> #define NPCM_WTCR 0x1C +/* NPCM GCR module */ +#define NPCM_RESSR_OFFSET 0x6C +#define NPCM_INTCR2_OFFSET 0x60 +#define NPCM8XX_SCRPAD10_OFFSET 0xE28 + +#define NPCM_PORST BIT(31) +#define NPCM_CORST BIT(30) +#define NPCM_WD0RST BIT(29) +#define NPCM_SWR1RST BIT(28) +#define NPCM_SWR2RST BIT(27) +#define NPCM_SWR3RST BIT(26) +#define NPCM_SWR4RST BIT(25) +#define NPCM_WD1RST BIT(24) +#define NPCM_WD2RST BIT(23) +#define NPCM8XX_RST (GENMASK(31, 23) | GENMASK(15, 12)) +#define NPCM8XX_TIP_RESET BIT(25)/* Replaces SWRST4 on NPCM8xx */ + +/* Per-instance mapping of MMIO base address to its RESSR/INTCR2 reset bit. */ +struct npcm_wdt_rst_map { +phys_addr_t base; +u32 rst_bit; +}; + +struct npcm_wdt_status_map { +u32 rst_bit; +u32 wdiof_flag; +}; + +struct npcm_wdt_data { +const struct npcm_wdt_rst_map *rst_map; +unsigned int rst_map_size; +const struct npcm_wdt_status_map *status_map; +unsigned int status_map_size; +}; +#define NPCM_WTCLK (BIT(10) | BIT(11))/* Clock divider */ #define NPCM_WTE BIT(7)/* Enable */ #define NPCM_WTIE BIT(6)/* Enable irq */
@@ -47,6 +84,50 @@ struct npcm_wdt {struct clk *clk; }; +static const struct npcm_wdt_rst_map npcm750_rst_map[] = { + {0xf000801c ,NPCM_WD0RST }, + {0xf000901c ,NPCM_WD1RST }, + {0xf000a01c ,NPCM_WD2RST }, +}; + +static const struct npcm_wdt_status_map npcm750_status_map[] = { + {NPCM_PORST ,WDIOF_OVERHEAT }, + {NPCM_CORST ,WDIOF_FANFAULT }, + {NPCM_SWR1RST ,WDIOF_EXTERN1 }, + {NPCM_SWR2RST ,WDIOF_EXTERN2 }, + {NPCM_SWR3RST ,WDIOF_POWERUNDER }, + {NPCM_SWR4RST ,WDIOF_POWEROVER }, +}; + +static const struct npcm_wdt_data npcm750_data = { + .rst_map = npcm750_rst_map, + .rst_map_size =ARRAY_SIZE (npcm750_rst_map), + .status_map = npcm750_status_map, + .status_map_size =ARRAY_SIZE (npcm750_status_map), +}; + +static const struct npcm_wdt_rst_map npcm845_rst_map[] = { + {0xf000801c ,NPCM_WD0RST }, + {0xf000901c ,NPCM_WD1RST }, + {0xf000a01c ,NPCM_WD2RST }, +}; + +static const struct npcm_wdt_status_map npcm845_status_map[] = { + {NPCM_PORST ,WDIOF_OVERHEAT }, + {NPCM_CORST ,WDIOF_FANFAULT }, + {NPCM_SWR1RST ,WDIOF_EXTERN1 }, + {NPCM_SWR2RST ,WDIOF_EXTERN2 }, + {NPCM_SWR3RST ,WDIOF_POWERUNDER }, + {NPCM8XX_TIP_RESET ,WDIOF_POWEROVER }, +}; + +static const struct npcm_wdt_data npcm845_data = { + .rst_map = npcm845_rst_map, + .rst_map_size =ARRAY_SIZE (npcm845_rst_map), + .status_map = npcm845_status_map, + .status_map_size =ARRAY_SIZE (npcm845_status_map), +}; +static inline struct npcm_wdt *to_npcm_wdt (struct watchdog_device *wdd) { return container_of(wdd, struct npcm_wdt, wdd);
@@ -169,6 +250,92 @@ static bool npcm_is_running(struct watchdog_device *wdd)return readl (wdt->reg) &NPCM_WTE ; } +static void npcm_get_reset_status (struct npcm_wdt *wdt,struct device *dev, +const struct npcm_wdt_data *data, +resource_size_t start) +{ +struct regmap *gcr_regmap; +u32 rstval =0 ; +unsigned int i; +int ret; + +if (!data) +return ; + + gcr_regmap =syscon_regmap_lookup_by_phandle (dev->of_node, +"nuvoton,sysgcr" ); +if (IS_ERR (gcr_regmap)) { +dev_warn (dev, +"Failed to find nuvoton,sysgcr, WD reset status not supported\n" ); +return ; + } + +if (of_device_is_compatible (dev->of_node,"nuvoton,npcm845-wdt" )) { + ret =regmap_read (gcr_regmap,NPCM_INTCR2_OFFSET , &rstval); +if (ret) { +dev_warn (dev,"Failed to read INTCR2 reset status: %d\n" , + ret); +return ; + } + +if (rstval &NPCM8XX_RST ) { + ret =regmap_write (gcr_regmap,NPCM_INTCR2_OFFSET , + rstval & ~NPCM8XX_RST ); +if (ret) { +dev_warn (dev, +"Failed to clear INTCR2 reset status: %d\n" , + ret); +return ; + } + + ret =regmap_write (gcr_regmap,NPCM8XX_SCRPAD10_OFFSET , + rstval); +if (ret) { +dev_warn (dev, +"Failed to cache reset status in SCRPAD10: %d\n" , + ret); +return ; + } + }else { + ret =regmap_read (gcr_regmap,NPCM8XX_SCRPAD10_OFFSET , + &rstval); +if (ret) { +dev_warn (dev, +"Failed to read cached reset status from SCRPAD10: %d\n" , + ret); +return ; + } + } + }else if (of_device_is_compatible (dev->of_node,"nuvoton,npcm750-wdt" )) { + ret =regmap_read (gcr_regmap,NPCM_RESSR_OFFSET , &rstval); +if (ret) { +dev_warn (dev,"Failed to read RESSR reset status: %d\n" , + ret); +return ; + } + + ret =regmap_write (gcr_regmap,NPCM_RESSR_OFFSET , rstval); +if (ret) { +dev_warn (dev,"Failed to clear RESSR reset status: %d\n" , + ret); +return ; + } + } + +for (i =0 ; i < data->status_map_size; i++) { +if (rstval & data->status_map[i].rst_bit) + wdt->wdd.bootstatus |= data->status_map[i].wdiof_flag; + } + +for (i =0 ; i < data->rst_map_size; i++) { +if (data->rst_map[i].base == start && + rstval & data->rst_map[i].rst_bit) { + wdt->wdd.bootstatus |=WDIOF_CARDRESET ; +break ; + } + } +} +static const struct watchdog_info npcm_wdt_info = { .identity =KBUILD_MODNAME , .options =WDIOF_SETTIMEOUT
@@ -176,6 +343,20 @@ static const struct watchdog_info npcm_wdt_info = { | WDIOF_MAGICCLOSE, }; +static const struct watchdog_info npcm_wdt_rst_info = { + .identity =KBUILD_MODNAME , + .options =WDIOF_SETTIMEOUT + |WDIOF_KEEPALIVEPING + |WDIOF_MAGICCLOSE + |WDIOF_CARDRESET + |WDIOF_OVERHEAT + |WDIOF_FANFAULT + |WDIOF_EXTERN1 + |WDIOF_EXTERN2 + |WDIOF_POWERUNDER + |WDIOF_POWEROVER , +}; +static const struct watchdog_ops npcm_wdt_ops = { .owner =THIS_MODULE , .start = npcm_wdt_start,
@@ -188,7 +369,10 @@ static const struct watchdog_ops npcm_wdt_ops = {static int npcm_wdt_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; +const struct npcm_wdt_data *data =device_get_match_data (dev); +struct resource *res;struct npcm_wdt *wdt; +resource_size_t start;int irq;int ret;
@@ -196,10 +380,16 @@ static int npcm_wdt_probe(struct platform_device *pdev)if (!wdt)return -ENOMEM ; + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); +if (!res) +return -EINVAL ; + wdt->reg =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (wdt->reg))return PTR_ERR (wdt->reg); + start = res->start; + wdt->clk =devm_clk_get_optional (&pdev->dev,NULL );if (IS_ERR (wdt->clk))return PTR_ERR (wdt->clk);
@@ -208,7 +398,7 @@ static int npcm_wdt_probe(struct platform_device *pdev)if (irq <0 )return irq; - wdt->wdd.info = &npcm_wdt_info; + wdt->wdd.info = data ? &npcm_wdt_rst_info : &npcm_wdt_info; wdt->wdd.ops = &npcm_wdt_ops; wdt->wdd.min_timeout =1 ; wdt->wdd.max_timeout =2750 ;
@@ -220,6 +410,8 @@ static int npcm_wdt_probe(struct platform_device *pdev)/* Ensure timeout is able to be represented by the hardware */ npcm_wdt_set_timeout (&wdt->wdd, wdt->wdd.timeout); +npcm_get_reset_status (wdt, dev, data, start); +if (npcm_is_running (&wdt->wdd)) {/* Restart with the default or device-tree specified timeout */ npcm_wdt_start (&wdt->wdd);
@@ -243,7 +435,8 @@ static int npcm_wdt_probe(struct platform_device *pdev)#ifdef CONFIG_OF static const struct of_device_id npcm_wdt_match[] = { {.compatible ="nuvoton,wpcm450-wdt" }, - {.compatible ="nuvoton,npcm750-wdt" }, + {.compatible ="nuvoton,npcm750-wdt" , .data = &npcm750_data}, + {.compatible ="nuvoton,npcm845-wdt" , .data = &npcm845_data}, {}, };MODULE_DEVICE_TABLE (of, npcm_wdt_match);
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v2 3/3] watchdog: npcm: add bootstatus support
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider: - [High] The first watchdog instance on NPCM750 clears the global RESSR register without caching it…
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The first watchdog instance on NPCM750 clears the global RESSR register without caching it, causing subsequent watchdog instances to permanently lose their reset status.
- [High] Non-atomic read-modify-write of the shared INTCR2 register clobbers concurrent modifications and incorrectly handles W1C semantics.
--
commit dafe1267618ef0158376caf5f3acee9d7fe7b1b7
Author: Tomer Maimon <[email protected]>
watchdog: npcm: add bootstatus support
The NPCM750 uses RESSR and the NPCM845 uses INTCR2 to latch reset indications. Read those bits during probe and map them into watchdog bootstatus flags.
Quoted 4 lines
drivers/watchdog/npcm_wdt.c +0
-0
[ ... ]
Quoted 8 lines
drivers/watchdog/npcm_wdt.c +4
-0@@ -169,6 +250,92 @@ static bool npcm_is_running(struct watchdog_device *wdd)return readl (wdt->reg) &NPCM_WTE ; } +static void npcm_get_reset_status (struct npcm_wdt *wdt,struct device *dev, +const struct npcm_wdt_data *data, +resource_size_t start) +{
[ ... ]
drivers/watchdog/npcm_wdt.c static bool npcm_is_running(struct watchdog_device *wdd) · line 283
Quoted 11 lines
drivers/watchdog/npcm_wdt.c +11
-0+if (of_device_is_compatible (dev->of_node,"nuvoton,npcm845-wdt" )) { + ret =regmap_read (gcr_regmap,NPCM_INTCR2_OFFSET , &rstval); +if (ret) { +dev_warn (dev,"Failed to read INTCR2 reset status: %d\n" , + ret); +return ; + } + +if (rstval &NPCM8XX_RST ) { + ret =regmap_write (gcr_regmap,NPCM_INTCR2_OFFSET , + rstval & ~NPCM8XX_RST );
[Severity: High]
Does this non-atomic read-modify-write risk clobbering concurrent modifications to the shared INTCR2 register?
Since INTCR2 is a shared global control register accessed by multiple drivers, using regmap_read() followed by regmap_write() drops the regmap lock between operations. Any concurrent modifications to INTCR2 by other drivers could be overwritten.
Also, if INTCR2 contains Write-1-to-Clear (W1C) status bits, writing rstval & ~NPCM8XX_RST might incorrectly write 1s to all other active bits (clearing them) and 0s to the watchdog bits.
Could regmap_update_bits() or a W1C-safe write be used here instead?
Quoted 6 lines
drivers/watchdog/npcm_wdt.c +6
-0+if (ret) { +dev_warn (dev, +"Failed to clear INTCR2 reset status: %d\n" , + ret); +return ; + }
[ ... ]
drivers/watchdog/npcm_wdt.c static bool npcm_is_running(struct watchdog_device *wdd) · line 317
Quoted 10 lines
drivers/watchdog/npcm_wdt.c +10
-0+ } + }else if (of_device_is_compatible (dev->of_node,"nuvoton,npcm750-wdt" )) { + ret =regmap_read (gcr_regmap,NPCM_RESSR_OFFSET , &rstval); +if (ret) { +dev_warn (dev,"Failed to read RESSR reset status: %d\n" , + ret); +return ; + } + + ret =regmap_write (gcr_regmap,NPCM_RESSR_OFFSET , rstval);
[Severity: High]
Will the first watchdog instance on NPCM750 clear the global RESSR register without caching it, causing subsequent instances to lose their reset status?
The NPCM750 SoC has three watchdog instances that share the global RESSR register. When the first watchdog probes, it reads RESSR and immediately clears it by writing the value back. Because the value is not cached (unlike the SCRPAD10 mechanism used for NPCM845), when the remaining watchdogs probe, they will read 0 from RESSR and permanently lose their boot status indications.
Quoted 6 lines
drivers/watchdog/npcm_wdt.c +6
-0+if (ret) { +dev_warn (dev,"Failed to clear RESSR reset status: %d\n" , + ret); +return ; + } + }
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Tomer Maimon
maintainerRe: [PATCH v2 3/3] watchdog: npcm: add bootstatus support
Hi,
Thanks for the comments.
Quoted 41 lines · On Mon, 22 Jun 2026 at 11:42, <[email protected]> wrote:
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] The first watchdog instance on NPCM750 clears the global RESSR register without caching it, causing subsequent watchdog instances to permanently lose their reset status.
- [High] Non-atomic read-modify-write of the shared INTCR2 register clobbers concurrent modifications and incorrectly handles W1C semantics.
--commit
dafe1267618ef0158376caf5f3acee9d7fe7b1b7
Author: Tomer Maimon <[email protected]>watchdog: npcm: add bootstatus support
The NPCM750 uses RESSR and the NPCM845 uses INTCR2 to latch reset indications. Read those bits during probe and map them into watchdog bootstatus flags.
Quoted 4 lines
drivers/watchdog/npcm_wdt.c +0
-0[ ... ]
Quoted 8 lines
drivers/watchdog/npcm_wdt.c +4
-0@@ -169,6 +250,92 @@ static bool npcm_is_running(struct watchdog_device *wdd)return readl (wdt->reg) &NPCM_WTE ; } +static void npcm_get_reset_status (struct npcm_wdt *wdt,struct device *dev, +const struct npcm_wdt_data *data, +resource_size_t start) +{[ ... ]
drivers/watchdog/npcm_wdt.c static bool npcm_is_running(struct watchdog_device *wdd) · line 283
Quoted 11 lines
drivers/watchdog/npcm_wdt.c +11
-0+if (of_device_is_compatible (dev->of_node,"nuvoton,npcm845-wdt" )) { + ret =regmap_read (gcr_regmap,NPCM_INTCR2_OFFSET , &rstval); +if (ret) { +dev_warn (dev,"Failed to read INTCR2 reset status: %d\n" , + ret); +return ; + } + +if (rstval &NPCM8XX_RST ) { + ret =regmap_write (gcr_regmap,NPCM_INTCR2_OFFSET , + rstval & ~NPCM8XX_RST );
Quoted 3 lines
[Severity: High]
Does this non-atomic read-modify-write risk clobbering concurrent modifications to the shared INTCR2 register?
No, the INTCR2 is accessed only by the WD driver, and reads occur only during the WD probe.
Quoted 9 lines
Since INTCR2 is a shared global control register accessed by multiple drivers, using
regmap_read()followed byregmap_write()drops the regmap lock between operations. Any concurrent modifications to INTCR2 by other drivers could be overwritten.Also, if INTCR2 contains Write-1-to-Clear (W1C) status bits, writing
rstval & ~NPCM8XX_RSTmight incorrectly write 1s to all other active bits (clearing them) and 0s to the watchdog bits.
the INTCR2 is not contains Write-1-to-Clear (W1C) status bits.
Quoted 2 lines
Could
regmap_update_bits()or a W1C-safe write be used here instead?
It is not needed here.
Quoted 23 lines
Quoted 7 lines
drivers/watchdog/npcm_wdt.c +6
-0+if (ret) { +dev_warn (dev, +"Failed to clear INTCR2 reset status: %d\n" , + ret); +return ; + }[ ... ]
drivers/watchdog/npcm_wdt.c static bool npcm_is_running(struct watchdog_device *wdd) · line 317
Quoted 10 lines
drivers/watchdog/npcm_wdt.c +10
-0+ } + }else if (of_device_is_compatible (dev->of_node,"nuvoton,npcm750-wdt" )) { + ret =regmap_read (gcr_regmap,NPCM_RESSR_OFFSET , &rstval); +if (ret) { +dev_warn (dev,"Failed to read RESSR reset status: %d\n" , + ret); +return ; + } + + ret =regmap_write (gcr_regmap,NPCM_RESSR_OFFSET , rstval);[Severity: High]
Will the first watchdog instance on NPCM750 clear the global RESSR register without caching it, causing subsequent instances to lose their reset status?
Quoted 6 lines
The NPCM750 SoC has three watchdog instances that share the global RESSR register. When the first watchdog probes, it reads RESSR and immediately clears it by writing the value back. Because the value is not cached (unlike the SCRPAD10 mechanism used for NPCM845), when the remaining watchdogs probe, they will read 0 from RESSR and permanently lose their boot status indications.
Will be change in V3
Quoted 10 lines
drivers/watchdog/npcm_wdt.c static bool npcm_is_running(struct watchdog_device *wdd) · line 323
Quoted 7 lines
drivers/watchdog/npcm_wdt.c +6
-0+if (ret) { +dev_warn (dev,"Failed to clear RESSR reset status: %d\n" , + ret); +return ; + } + }--
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Thanks,
Tomer