watchdog: npcm: add last bootstatus support
Tomer Maimon
maintainerv2 cover watchdog: npcm: add last bootstatus support
This patch set adds last reset bootstatus support in watchdog the Nuvoton NPCM Baseboard Management Controller (BMC).
The NPCM watchdog driver tested on NPCM750 evaluation board.
Addressed comments from:.
- Guenter Roeck: https://www.spinics.net/lists/kernel/msg3425926.html
- Guenter Roeck: https://lkml.org/lkml/2020/3/1/144
Changes since version 1:
- Remove restart priority support.
- Modify commit message.
- Modify define in alphabetic order.
- Add reset bootstatus remarks.
- Remove and modify whitespace.
Tomer Maimon (3):
dt-binding: watchdog: add bootstatus reset type documentation
watchdog: npcm: sets card ext1 and ext2 bootstatus during probe
watchdog: npcm: remove whitespaces
.../bindings/watchdog/nuvoton,npcm-wdt.txt | 30 ++++ drivers/watchdog/npcm_wdt.c | 131 ++++++++++++++++-- 2 files changed, 151 insertions(+), 10 deletions(-)
Signature · 1 line
2.22.0
Tomer Maimon
maintainerPATCH v2 1/3 dt-binding: watchdog: add bootstatus reset type documentation
Add device tree three bootstatus reset types documentation.
--- .../bindings/watchdog/nuvoton,npcm-wdt.txt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+)
Documentation/devicetree/bindings/watchdog/nuvoton,npcm-wdt.txt +30 -0
@@ -17,6 +17,33 @@ Required clocking property, have to be one of: Optional properties: - timeout-sec : Contains the watchdog timeout in seconds +- nuvoton,card-reset-type : "porst|corst|wd0|wd1|wd2|sw1|sw2|sw3|sw4" + Contains the card reset type for checking and indicating + the last card reset status (WDIOF_CARDRESET) + + If 'nuvoton,card-reset-type' is not specified the default is porst + + Reset types: + - porst: Power reset + - corst: Core reset + - wdX : Watchdog reset X (X represante 0-2) + - swX : Software reset X (X represante 1-4) + +- nuvoton,ext1-reset-type : "porst|corst|wd0|wd1|wd2|sw1|sw2|sw3|sw4" + Contains the external 2 reset type for checking and indicating + the last external 2 reset status (WDIOF_EXTERN1) + + If 'nuvoton,card-reset-type' is not specified the default is wd0. + + Reset types are the same as in nuvoton,card-reset-type property. + +- nuvoton,ext2-reset-type : "porst|corst|wd0|wd1|wd2|sw1|sw2|sw3|sw4" + Contains the external 2 reset type for checking and indicating + the last external 2 reset status (WDIOF_EXTERN2) + + If 'nuvoton,card-reset-type' is not specified the default is sw1. + + Reset types are the same as in nuvoton,card-reset-type property. Example:
@@ -25,4 +52,7 @@ timer@f000801c { interrupts = <GIC_SPI 47 IRQ_TYPE_LEVEL_HIGH>; reg = <0xf000801c 0x4>; clocks = <&clk NPCM7XX_CLK_TIMER>; + nuvoton,card-reset-type = "porst"; + nuvoton,ext1-reset-type = "wd1"; + nuvoton,ext2-reset-type = "sw2"; };
Signature · 1 line
2.22.0
Guenter Roeck
maintainerRe: [PATCH v2 1/3] dt-binding: watchdog: add bootstatus reset type documentation
Quoted 46 lines · Tomer Maimon
Add device tree three bootstatus reset types documentation.
Signed-off-by Tomer Maimon <[email protected]>--- .../bindings/watchdog/nuvoton,npcm-wdt.txt | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+)Documentation/devicetree/bindings/watchdog/nuvoton,npcm-wdt.txt +27
-0@@ -17,6 +17,33 @@ Required clocking property, have to be one of: Optional properties: - timeout-sec : Contains the watchdog timeout in seconds +- nuvoton,card-reset-type : "porst|corst|wd0|wd1|wd2|sw1|sw2|sw3|sw4" + Contains the card reset type for checking and indicating + the last card reset status (WDIOF_CARDRESET) + + If 'nuvoton,card-reset-type' is not specified the default is porst + + Reset types: + - porst: Power reset + - corst: Core reset + - wdX : Watchdog reset X (X represante 0-2) + - swX : Software reset X (X represante 1-4) + +- nuvoton,ext1-reset-type : "porst|corst|wd0|wd1|wd2|sw1|sw2|sw3|sw4" + Contains the external 2 reset type for checking and indicating + the last external 2 reset status (WDIOF_EXTERN1) + + If 'nuvoton,card-reset-type' is not specified the default is wd0. + + Reset types are the same as in nuvoton,card-reset-type property. + +- nuvoton,ext2-reset-type : "porst|corst|wd0|wd1|wd2|sw1|sw2|sw3|sw4" + Contains the external 2 reset type for checking and indicating + the last external 2 reset status (WDIOF_EXTERN2) + + If 'nuvoton,card-reset-type' is not specified the default is sw1. + + Reset types are the same as in nuvoton,card-reset-type property. Example:
Documentation/devicetree/bindings/watchdog/nuvoton,npcm-wdt.txt timer@f000801c { · line 57
Quoted 6 lines
Documentation/devicetree/bindings/watchdog/nuvoton,npcm-wdt.txt +3
-0@@ -25,4 +52,7 @@ timer@f000801c { interrupts = <GIC_SPI 47 IRQ_TYPE_LEVEL_HIGH>; reg = <0xf000801c 0x4>; clocks = <&clk NPCM7XX_CLK_TIMER>; + nuvoton,card-reset-type = "porst"; + nuvoton,ext1-reset-type = "wd1"; + nuvoton,ext2-reset-type = "sw2";
This set of properties maps chip reset types to reset types defined by the Linux watchdog subsystem (ie WDIOF_CARDRESET, WDIOF_EXTERN1, and WDIOF_EXTERN2). It is neither a hardware description nor a system configuration.
It is up to Rob to decide, but I personally don't think it is appropriate.
Guenter
Tomer Maimon
maintainerPATCH v2 2/3 watchdog: npcm: sets card ext1 and ext2 bootstatus during probe
In reply to Tomer MaimonThe NPCM750 have the following nine resets:
- Power on reset.
- Core reset
- Watchdog0-2 resets.
- Software1-4 resets
During probe NPCM watchdog sets WDIOF_CARDRESET, WDIOF_EXTERN1 and WDIOF_EXTERN2 bootstatus flags.
Each bootstatus flag can represent one of the NPCM750 resets.
Bootstatus flag configure by the DT properties.
--- drivers/watchdog/npcm_wdt.c | 112 ++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+)
drivers/watchdog/npcm_wdt.c +112 -0
@@ -6,12 +6,29 @@#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> +/* NPCM7xx GCR module */ +#define NPCM7XX_RESSR_OFFSET 0x6C +#define NPCM7XX_INTCR2_OFFSET 0x60 + +#define NPCM7XX_PORST BIT(31) +#define NPCM7XX_CORST BIT(30) +#define NPCM7XX_WD0RST BIT(29) +#define NPCM7XX_WD1RST BIT(24) +#define NPCM7XX_WD2RST BIT(23) +#define NPCM7XX_SWR1RST BIT(28) +#define NPCM7XX_SWR2RST BIT(27) +#define NPCM7XX_SWR3RST BIT(26) +#define NPCM7XX_SWR4RST BIT(25) + +/* WD register */ #define NPCM_WTCR 0x1C#define NPCM_WTCLK (BIT(10) | BIT(11))/* Clock divider */
@@ -43,6 +60,9 @@struct npcm_wdt {struct watchdog_device wdd;void __iomem *reg; +u32 card_reset; +u32 ext1_reset; +u32 ext2_reset; };static inline struct npcm_wdt *to_npcm_wdt (struct watchdog_device *wdd)
@@ -177,9 +197,66 @@ static const struct watchdog_ops npcm_wdt_ops = { .restart = npcm_wdt_restart, }; +static void npcm_get_reset_status (struct npcm_wdt *wdt,struct device *dev) +{ +struct regmap *gcr_regmap; +u32 rstval; + +if (of_device_is_compatible (dev->of_node,"nuvoton,npcm750-wdt" )) { + gcr_regmap =syscon_regmap_lookup_by_compatible ("nuvoton,npcm750-gcr" ); +if (IS_ERR (gcr_regmap)) +dev_warn (dev,"Failed to find nuvoton,npcm750-gcr WD reset status not supported\n" ); + +/* Reading last reset status bit */ +regmap_read (gcr_regmap,NPCM7XX_RESSR_OFFSET , &rstval); +/* In case of NPCM750 power on, the reset status copied to +* NPCM7XX_INTCR2_OFFSET register and then NPCM7XX_RESSR_OFFSET +* register is cleaned. +*/ +if (!rstval) { +regmap_read (gcr_regmap,NPCM7XX_INTCR2_OFFSET , &rstval); + rstval = ~rstval; + } + +if (rstval & wdt->card_reset) + wdt->wdd.bootstatus |=WDIOF_CARDRESET ; +if (rstval & wdt->ext1_reset) + wdt->wdd.bootstatus |=WDIOF_EXTERN1 ; +if (rstval & wdt->ext2_reset) + wdt->wdd.bootstatus |=WDIOF_EXTERN2 ; + } +} + +static u32 npcm_wdt_reset_type (const char *reset_type) +{ +if (!strcmp (reset_type,"porst" )) +return NPCM7XX_PORST ; +else if (!strcmp (reset_type,"corst" )) +return NPCM7XX_CORST ; +else if (!strcmp (reset_type,"wd0" )) +return NPCM7XX_WD0RST ; +else if (!strcmp (reset_type,"wd1" )) +return NPCM7XX_WD1RST ; +else if (!strcmp (reset_type,"wd2" )) +return NPCM7XX_WD2RST ; +else if (!strcmp (reset_type,"sw1" )) +return NPCM7XX_SWR1RST ; +else if (!strcmp (reset_type,"sw2" )) +return NPCM7XX_SWR2RST ; +else if (!strcmp (reset_type,"sw3" )) +return NPCM7XX_SWR3RST ; +else if (!strcmp (reset_type,"sw4" )) +return NPCM7XX_SWR4RST ; + +return 0 ; +} +static int npcm_wdt_probe (struct platform_device *pdev) {struct device *dev = &pdev->dev; +const char *card_reset_type; +const char *ext1_reset_type; +const char *ext2_reset_type;struct npcm_wdt *wdt;int irq;int ret;
@@ -196,6 +273,39 @@ static int npcm_wdt_probe(struct platform_device *pdev)if (irq <0 )return irq; + ret =of_property_read_string (pdev->dev.of_node, +"nuvoton,card-reset-type" , + &card_reset_type); +if (ret) { + wdt->card_reset =NPCM7XX_PORST ; + }else { + wdt->card_reset =npcm_wdt_reset_type (card_reset_type); +if (!wdt->card_reset) + wdt->card_reset =NPCM7XX_PORST ; + } + + ret =of_property_read_string (pdev->dev.of_node, +"nuvoton,ext1-reset-type" , + &ext1_reset_type); +if (ret) { + wdt->ext1_reset =NPCM7XX_WD0RST ; + }else { + wdt->ext1_reset =npcm_wdt_reset_type (ext1_reset_type); +if (!wdt->ext1_reset) + wdt->ext1_reset =NPCM7XX_WD0RST ; + } + + ret =of_property_read_string (pdev->dev.of_node, +"nuvoton,ext2-reset-type" , + &ext2_reset_type); +if (ret) { + wdt->ext2_reset =NPCM7XX_SWR1RST ; + }else { + wdt->ext2_reset =npcm_wdt_reset_type (ext2_reset_type); +if (!wdt->ext2_reset) + wdt->ext2_reset =NPCM7XX_SWR1RST ; + } + wdt->wdd.info = &npcm_wdt_info; wdt->wdd.ops = &npcm_wdt_ops; wdt->wdd.min_timeout =1 ;
@@ -214,6 +324,8 @@ static int npcm_wdt_probe(struct platform_device *pdev)set_bit (WDOG_HW_RUNNING , &wdt->wdd.status); } +npcm_get_reset_status (wdt, dev); + ret =devm_request_irq (dev, irq, npcm_wdt_interrupt,0 ,"watchdog" , wdt);if (ret)
Signature · 1 line
2.22.0
Tomer Maimon
maintainerPATCH v2 3/3 watchdog: npcm: remove whitespaces
In reply to Tomer Maimon--- drivers/watchdog/npcm_wdt.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/watchdog/npcm_wdt.c +9 -10
@@ -123,30 +123,29 @@ static int npcm_wdt_stop(struct watchdog_device *wdd)return 0 ; } -static int npcm_wdt_set_timeout (struct watchdog_device *wdd,unsigned int timeout) {if (timeout <2 ) wdd->timeout =1 ;else if (timeout <3 ) - wdd->timeout =2 ; + wdd->timeout =2 ;else if (timeout <6 ) - wdd->timeout =5 ; + wdd->timeout =5 ;else if (timeout <11 ) - wdd->timeout =10 ; + wdd->timeout =10 ;else if (timeout <22 ) - wdd->timeout =21 ; + wdd->timeout =21 ;else if (timeout <44 ) - wdd->timeout =43 ; + wdd->timeout =43 ;else if (timeout <87 ) - wdd->timeout =86 ; + wdd->timeout =86 ;else if (timeout <173 ) - wdd->timeout =172 ; + wdd->timeout =172 ;else if (timeout <688 ) - wdd->timeout =687 ; + wdd->timeout =687 ;else - wdd->timeout =2750 ; + wdd->timeout =2750 ;if (watchdog_active (wdd))npcm_wdt_start (wdd);
Signature · 1 line
2.22.0
Guenter Roeck
maintainerRe: [PATCH v2 3/3] watchdog: npcm: remove whitespaces
Quoted 1 line · Tomer Maimon
Signed-off-by Tomer Maimon <[email protected]>
Turns out this problem does not actually exist in the upstream driver (as of v5.6-rc4). You might want to align your code with the upstream kernel.
Guenter
Quoted 48 lines
--- drivers/watchdog/npcm_wdt.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)drivers/watchdog/npcm_wdt.c +9
-10@@ -123,30 +123,29 @@ static int npcm_wdt_stop(struct watchdog_device *wdd)return 0 ; } -static int npcm_wdt_set_timeout (struct watchdog_device *wdd,unsigned int timeout) {if (timeout <2 ) wdd->timeout =1 ;else if (timeout <3 ) - wdd->timeout =2 ; + wdd->timeout =2 ;else if (timeout <6 ) - wdd->timeout =5 ; + wdd->timeout =5 ;else if (timeout <11 ) - wdd->timeout =10 ; + wdd->timeout =10 ;else if (timeout <22 ) - wdd->timeout =21 ; + wdd->timeout =21 ;else if (timeout <44 ) - wdd->timeout =43 ; + wdd->timeout =43 ;else if (timeout <87 ) - wdd->timeout =86 ; + wdd->timeout =86 ;else if (timeout <173 ) - wdd->timeout =172 ; + wdd->timeout =172 ;else if (timeout <688 ) - wdd->timeout =687 ; + wdd->timeout =687 ;else - wdd->timeout =2750 ; + wdd->timeout =2750 ;if (watchdog_active (wdd))npcm_wdt_start (wdd);
Tomer Maimon
maintainerRe: [PATCH v2 3/3] watchdog: npcm: remove whitespaces
Hi Guenter,
I still see the whitespaces warning in v5.6-rc4
https://github.com/torvalds/linux/blob/master/drivers/watchdog/npcm_wdt.c#L106
bash-4.2$ ./scripts/checkpatch.pl --strict --filedrivers/watchdog/npcm_wdt.c
CHECK: Please don't use multiple blank lines
#106: FILE: drivers/watchdog/npcm_wdt.c:106:
+
+
WARNING: suspect code indent for conditional statements (8, 14) #112: FILE: drivers/watchdog/npcm_wdt.c:112:
+ else if (timeout < 3)
+ wdd->timeout = 2;
WARNING: suspect code indent for conditional statements (8, 14) #114: FILE: drivers/watchdog/npcm_wdt.c:114:
+ else if (timeout < 6)
+ wdd->timeout = 5;
WARNING: suspect code indent for conditional statements (8, 14) #116: FILE: drivers/watchdog/npcm_wdt.c:116:
+ else if (timeout < 11)
+ wdd->timeout = 10;
WARNING: suspect code indent for conditional statements (8, 14) #118: FILE: drivers/watchdog/npcm_wdt.c:118:
+ else if (timeout < 22)
+ wdd->timeout = 21;
WARNING: suspect code indent for conditional statements (8, 14) #120: FILE: drivers/watchdog/npcm_wdt.c:120:
+ else if (timeout < 44)
+ wdd->timeout = 43;
WARNING: suspect code indent for conditional statements (8, 14) #122: FILE: drivers/watchdog/npcm_wdt.c:122:
+ else if (timeout < 87)
+ wdd->timeout = 86;
WARNING: suspect code indent for conditional statements (8, 14) #124: FILE: drivers/watchdog/npcm_wdt.c:124:
+ else if (timeout < 173)
+ wdd->timeout = 172;
WARNING: suspect code indent for conditional statements (8, 14) #126: FILE: drivers/watchdog/npcm_wdt.c:126:
+ else if (timeout < 688)
+ wdd->timeout = 687;
WARNING: suspect code indent for conditional statements (8, 14) #128: FILE: drivers/watchdog/npcm_wdt.c:128:
+ else
+ wdd->timeout = 2750;
Thanks,
Tomer
Quoted 59 lines · Guenter Roeck
Quoted 1 line · Tomer Maimon
Signed-off-by Tomer Maimon <[email protected]>Turns out this problem does not actually exist in the upstream driver (as of v5.6-rc4). You might want to align your code with the upstream kernel.
Guenter
drivers/watchdog/npcm_wdt.c static int npcm_wdt_stop(struct watchdog_device
Quoted 9 lines
--- drivers/watchdog/npcm_wdt.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)drivers/watchdog/npcm_wdt.c +0
-0@@ -123,30 +123,29 @@ static int npcm_wdt_stop(struct watchdog_device*wdd)
Quoted 39 lines
drivers/watchdog/npcm_wdt.c +9
-10return 0 ; } -static int npcm_wdt_set_timeout (struct watchdog_device *wdd,unsigned int timeout) {if (timeout <2 ) wdd->timeout =1 ;else if (timeout <3 ) - wdd->timeout =2 ; + wdd->timeout =2 ;else if (timeout <6 ) - wdd->timeout =5 ; + wdd->timeout =5 ;else if (timeout <11 ) - wdd->timeout =10 ; + wdd->timeout =10 ;else if (timeout <22 ) - wdd->timeout =21 ; + wdd->timeout =21 ;else if (timeout <44 ) - wdd->timeout =43 ; + wdd->timeout =43 ;else if (timeout <87 ) - wdd->timeout =86 ; + wdd->timeout =86 ;else if (timeout <173 ) - wdd->timeout =172 ; + wdd->timeout =172 ;else if (timeout <688 ) - wdd->timeout =687 ; + wdd->timeout =687 ;else - wdd->timeout =2750 ; + wdd->timeout =2750 ;if (watchdog_active (wdd))npcm_wdt_start (wdd);
Re: [PATCH v2 3/3] watchdog: npcm: remove whitespaces
Quoted 6 lines · Tomer Maimon
Hi Guenter,
I still see the whitespaces warning in v5.6-rc4
https://github.com/torvalds/linux/blob/master/drivers/watchdog/npcm_wdt.c#L106
You are corerct, sorry. No idea what I looked at yesterday.
Quoted 118 lines
bash-4.2$
./scripts/checkpatch.pl--strict --filedrivers/watchdog/npcm_wdt.c
CHECK: Please don't use multiple blank lines
#106: FILE:drivers/watchdog/npcm_wdt.c:106:(quoted diff) +2
-0+ +WARNING: suspect code indent for conditional statements (8, 14) #112: FILE:
drivers/watchdog/npcm_wdt.c:112:
+ else if (timeout < 3)
+wdd->timeout= 2;WARNING: suspect code indent for conditional statements (8, 14) #114: FILE:
drivers/watchdog/npcm_wdt.c:114:
+ else if (timeout < 6)
+wdd->timeout= 5;WARNING: suspect code indent for conditional statements (8, 14) #116: FILE:
drivers/watchdog/npcm_wdt.c:116:
+ else if (timeout < 11)
+wdd->timeout= 10;WARNING: suspect code indent for conditional statements (8, 14) #118: FILE:
drivers/watchdog/npcm_wdt.c:118:
+ else if (timeout < 22)
+wdd->timeout= 21;WARNING: suspect code indent for conditional statements (8, 14) #120: FILE:
drivers/watchdog/npcm_wdt.c:120:
+ else if (timeout < 44)
+wdd->timeout= 43;WARNING: suspect code indent for conditional statements (8, 14) #122: FILE:
drivers/watchdog/npcm_wdt.c:122:
+ else if (timeout < 87)
+wdd->timeout= 86;WARNING: suspect code indent for conditional statements (8, 14) #124: FILE:
drivers/watchdog/npcm_wdt.c:124:
+ else if (timeout < 173)
+wdd->timeout= 172;WARNING: suspect code indent for conditional statements (8, 14) #126: FILE:
drivers/watchdog/npcm_wdt.c:126:
+ else if (timeout < 688)
+wdd->timeout= 687;WARNING: suspect code indent for conditional statements (8, 14) #128: FILE:
drivers/watchdog/npcm_wdt.c:128:
+ else
+wdd->timeout= 2750;Thanks,
Tomer
Quoted 59 lines · Guenter Roeck
Quoted 1 line · Tomer Maimon
Signed-off-by Tomer Maimon <[email protected]>Turns out this problem does not actually exist in the upstream driver (as of v5.6-rc4). You might want to align your code with the upstream kernel.
Guenter
drivers/watchdog/npcm_wdt.c static int npcm_wdt_stop(struct watchdog_device
Quoted 9 lines
--- drivers/watchdog/npcm_wdt.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)drivers/watchdog/npcm_wdt.c +0
-0@@ -123,30 +123,29 @@ static int npcm_wdt_stop(struct watchdog_device*wdd)
Quoted 39 lines
drivers/watchdog/npcm_wdt.c +9
-10return 0 ; } -static int npcm_wdt_set_timeout (struct watchdog_device *wdd,unsigned int timeout) {if (timeout <2 ) wdd->timeout =1 ;else if (timeout <3 ) - wdd->timeout =2 ; + wdd->timeout =2 ;else if (timeout <6 ) - wdd->timeout =5 ; + wdd->timeout =5 ;else if (timeout <11 ) - wdd->timeout =10 ; + wdd->timeout =10 ;else if (timeout <22 ) - wdd->timeout =21 ; + wdd->timeout =21 ;else if (timeout <44 ) - wdd->timeout =43 ; + wdd->timeout =43 ;else if (timeout <87 ) - wdd->timeout =86 ; + wdd->timeout =86 ;else if (timeout <173 ) - wdd->timeout =172 ; + wdd->timeout =172 ;else if (timeout <688 ) - wdd->timeout =687 ; + wdd->timeout =687 ;else - wdd->timeout =2750 ; + wdd->timeout =2750 ;if (watchdog_active (wdd))npcm_wdt_start (wdd);