<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 11 Jan 2021 at 02:55, Joel Stanley <<a href="mailto:joel@jms.id.au">joel@jms.id.au</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Tue, 5 Jan 2021 at 13:45, Tomer Maimon <<a href="mailto:tmaimon77@gmail.com" target="_blank">tmaimon77@gmail.com</a>> wrote:<br>
><br>
> Add Device tree restart priority and<br>
> three reset types support.<br>
><br>
> Signed-off-by: Tomer Maimon <<a href="mailto:tmaimon77@gmail.com" target="_blank">tmaimon77@gmail.com</a>><br>
<br>
Can you remind me the history of this change. Was a similar patch<br>
rejected by mainline?<br></blockquote><div><a href="https://www.spinics.net/lists/kernel/msg3425926.html">https://www.spinics.net/lists/kernel/msg3425926.html</a> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> ---<br>
> drivers/watchdog/npcm_wdt.c | 121 +++++++++++++++++++++++++++++++++++-<br>
> 1 file changed, 119 insertions(+), 2 deletions(-)<br>
><br>
> diff --git a/drivers/watchdog/npcm_wdt.c b/drivers/watchdog/npcm_wdt.c<br>
> index 765577f11c8d..bbf27da34834 100644<br>
> --- a/drivers/watchdog/npcm_wdt.c<br>
> +++ b/drivers/watchdog/npcm_wdt.c<br>
> @@ -11,7 +11,24 @@<br>
> #include <linux/platform_device.h><br>
> #include <linux/slab.h><br>
> #include <linux/watchdog.h><br>
> -<br>
> +#include <linux/regmap.h><br>
> +#include <linux/mfd/syscon.h><br>
> +<br>
> +/* NPCM7xx GCR module */<br>
> +#define NPCM7XX_RESSR_OFFSET 0x6C<br>
> +#define NPCM7XX_INTCR2_OFFSET 0x60<br>
> +<br>
> +#define NPCM7XX_PORST BIT(31)<br>
> +#define NPCM7XX_CORST BIT(30)<br>
> +#define NPCM7XX_WD0RST BIT(29)<br>
> +#define NPCM7XX_WD1RST BIT(24)<br>
> +#define NPCM7XX_WD2RST BIT(23)<br>
> +#define NPCM7XX_SWR1RST BIT(28)<br>
> +#define NPCM7XX_SWR2RST BIT(27)<br>
> +#define NPCM7XX_SWR3RST BIT(26)<br>
> +#define NPCM7XX_SWR4RST BIT(25)<br>
> +<br>
> + /* WD register */<br>
> #define NPCM_WTCR 0x1C<br>
><br>
> #define NPCM_WTCLK (BIT(10) | BIT(11)) /* Clock divider */<br>
> @@ -43,6 +60,10 @@<br>
> struct npcm_wdt {<br>
> struct watchdog_device wdd;<br>
> void __iomem *reg;<br>
> + u32 card_reset;<br>
> + u32 ext1_reset;<br>
> + u32 ext2_reset;<br>
> +<br>
> };<br>
><br>
> static inline struct npcm_wdt *to_npcm_wdt(struct watchdog_device *wdd)<br>
> @@ -176,14 +197,70 @@ static const struct watchdog_ops npcm_wdt_ops = {<br>
> .restart = npcm_wdt_restart,<br>
> };<br>
><br>
> +static void npcm_get_reset_status(struct npcm_wdt *wdt, struct device *dev)<br>
> +{<br>
> + struct regmap *gcr_regmap;<br>
> + u32 rstval;<br>
> +<br>
> + if (of_device_is_compatible(dev->of_node, "nuvoton,npcm750-wdt")) {<br>
> + gcr_regmap = syscon_regmap_lookup_by_compatible("nuvoton,npcm750-gcr");<br>
<br>
This will have the same issues as the ADC with supporting multiple<br>
families of chip with the same code. I suggest you adjust it to use<br>
the phandle approach.<br><br></blockquote><div>Do you mean by having a gcr phandle property in the wdt npcm device tree node?</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
> + if (IS_ERR(gcr_regmap)) {<br>
> + dev_warn(dev, "Failed to find nuvoton,npcm750-gcr WD reset status not supported\n");<br>
> + }<br>
> +<br>
> + regmap_read(gcr_regmap, NPCM7XX_RESSR_OFFSET, &rstval);<br>
> + if (!rstval) {<br>
> + regmap_read(gcr_regmap, NPCM7XX_INTCR2_OFFSET, &rstval);<br>
> + rstval = ~rstval;<br>
> + }<br>
> +<br>
> + if(rstval & wdt->card_reset)<br>
> + wdt->wdd.bootstatus |= WDIOF_CARDRESET;<br>
> + if(rstval & wdt->ext1_reset)<br>
> + wdt->wdd.bootstatus |= WDIOF_EXTERN1;<br>
> + if(rstval & wdt->ext2_reset)<br>
> + wdt->wdd.bootstatus |= WDIOF_EXTERN2;<br>
> + }<br>
> +<br>
> +}<br>
> +<br>
> +static u32 npcm_wdt_reset_type(const char *reset_type)<br>
> +{<br>
> + if (!strcmp(reset_type, "porst"))<br>
> + return NPCM7XX_PORST;<br>
> + else if (!strcmp(reset_type, "corst"))<br>
> + return NPCM7XX_CORST;<br>
> + else if (!strcmp(reset_type, "wd0"))<br>
> + return NPCM7XX_WD0RST;<br>
> + else if (!strcmp(reset_type, "wd1"))<br>
> + return NPCM7XX_WD1RST;<br>
> + else if (!strcmp(reset_type, "wd2"))<br>
> + return NPCM7XX_WD2RST;<br>
> + else if (!strcmp(reset_type, "sw1"))<br>
> + return NPCM7XX_SWR1RST;<br>
> + else if (!strcmp(reset_type, "sw2"))<br>
> + return NPCM7XX_SWR2RST;<br>
> + else if (!strcmp(reset_type, "sw3"))<br>
> + return NPCM7XX_SWR3RST;<br>
> + else if (!strcmp(reset_type, "sw4"))<br>
> + return NPCM7XX_SWR4RST;<br>
> +<br>
> + return 0;<br>
> +}<br>
> +<br>
> static int npcm_wdt_probe(struct platform_device *pdev)<br>
> {<br>
> struct device *dev = &pdev->dev;<br>
> + const char *card_reset_type;<br>
> + const char *ext1_reset_type;<br>
> + const char *ext2_reset_type;<br>
> struct npcm_wdt *wdt;<br>
> + struct resource *res;<br>
> + u32 priority;<br>
> int irq;<br>
> int ret;<br>
><br>
> - wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);<br>
> + wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL);<br>
> if (!wdt)<br>
> return -ENOMEM;<br>
><br>
> @@ -195,6 +272,45 @@ static int npcm_wdt_probe(struct platform_device *pdev)<br>
> if (irq < 0)<br>
> return irq;<br>
><br>
> + if (of_property_read_u32(pdev->dev.of_node, "nuvoton,restart-priority",<br>
> + &priority))<br>
> + watchdog_set_restart_priority(&wdt->wdd, 128);<br>
> + else<br>
> + watchdog_set_restart_priority(&wdt->wdd, priority);<br>
> +<br>
> + ret = of_property_read_string(pdev->dev.of_node,<br>
> + "nuvoton,card-reset-type",<br>
> + &card_reset_type);<br>
> + if (ret)<br>
> + wdt->card_reset = NPCM7XX_PORST;<br>
> + else {<br>
> + wdt->card_reset = npcm_wdt_reset_type(card_reset_type);<br>
> + if (!wdt->card_reset)<br>
> + wdt->card_reset = NPCM7XX_PORST;<br>
> + }<br>
> +<br>
> + ret = of_property_read_string(pdev->dev.of_node,<br>
> + "nuvoton,ext1-reset-type",<br>
> + &ext1_reset_type);<br>
> + if (ret)<br>
> + wdt->ext1_reset = NPCM7XX_WD0RST;<br>
> + else {<br>
> + wdt->ext1_reset = npcm_wdt_reset_type(ext1_reset_type);<br>
> + if (!wdt->ext1_reset)<br>
> + wdt->ext1_reset = NPCM7XX_WD0RST;<br>
> + }<br>
> +<br>
> + ret = of_property_read_string(pdev->dev.of_node,<br>
> + "nuvoton,ext2-reset-type",<br>
> + &ext2_reset_type);<br>
> + if (ret)<br>
> + wdt->ext2_reset = NPCM7XX_SWR1RST;<br>
> + else {<br>
> + wdt->ext2_reset = npcm_wdt_reset_type(ext2_reset_type);<br>
> + if (!wdt->ext2_reset)<br>
> + wdt->ext2_reset = NPCM7XX_SWR1RST;<br>
> + }<br>
> +<br>
> wdt-><a href="http://wdd.info" rel="noreferrer" target="_blank">wdd.info</a> = &npcm_wdt_info;<br>
> wdt->wdd.ops = &npcm_wdt_ops;<br>
> wdt->wdd.min_timeout = 1;<br>
> @@ -213,6 +329,7 @@ static int npcm_wdt_probe(struct platform_device *pdev)<br>
> set_bit(WDOG_HW_RUNNING, &wdt->wdd.status);<br>
> }<br>
><br>
> + npcm_get_reset_status(wdt, dev);<br>
> ret = devm_request_irq(dev, irq, npcm_wdt_interrupt, 0, "watchdog",<br>
> wdt);<br>
> if (ret)<br>
> --<br>
> 2.22.0<br>
><br>
</blockquote></div></div>