Message ID | 20241213174419.908525-1-prabhakar.mahadev-lad.rj@bp.renesas.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | [RFC] watchdog: rzv2h_wdt: Add support to retrieve the bootstatus information | expand |
On 12/13/24 09:44, Prabhakar wrote: > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > On the RZ/V2H(P) SoC we can determine if the current boot is due to > `Power-on-Reset` or due to the `Watchdog`. The information used to > determine this is present on the CPG block. > > The CPG_ERROR_RSTm(m = 2 -8 ) registers are set in response to an error > interrupt causing an reset. CPG_ERROR_RST2[ERROR_RST1] is set if there > was an underflow/overflow on WDT1 causing an error interrupt. > > To fetch this information from CPG block `syscon` is used and bootstatus > field in the watchdog device is updated based on the > CPG_ERROR_RST2[ERROR_RST1] bit. Upon consumig CPG_ERROR_RST2[ERROR_RST1] > bit we are also clearing it. > > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > --- > @Geert, I intend to drop WDT0/2/3 nodes (and related clocks) as HW manual > says WDT1 is for CA55 (I'll first confirm this internally) > > Hi Geert/Rob, > > I havent included a binding changes as part of the RFC as I wanted to get > some initial feedback on the implementation. Currently CPG block doesnt > have the "syscon" this patch has been tested with below diff to SoC DTSI > > Cheers, > Prabhakar > > Changes to SoC DTSI: > @@ -243,7 +243,7 @@ pinctrl: pinctrl@10410000 { > }; > > cpg: clock-controller@10420000 { > - compatible = "renesas,r9a09g057-cpg"; > + compatible = "renesas,r9a09g057-cpg", "syscon"; > reg = <0 0x10420000 0 0x10000>; > clocks = <&audio_extal_clk>, <&rtxin_clk>, <&qextal_clk>; > clock-names = "audio_extal", "rtxin", "qextal"; > @@ -455,6 +456,7 @@ wdt1: watchdog@14400000 { > clock-names = "pclk", "oscclk"; > resets = <&cpg 0x76>; > power-domains = <&cpg>; > + syscon = <&cpg>; > status = "disabled"; > }; > > --- > drivers/watchdog/rzv2h_wdt.c | 27 ++++++++++++++++++++++++++- > 1 file changed, 26 insertions(+), 1 deletion(-) > > diff --git a/drivers/watchdog/rzv2h_wdt.c b/drivers/watchdog/rzv2h_wdt.c > index 8defd0241213..8e0901bb7d2b 100644 > --- a/drivers/watchdog/rzv2h_wdt.c > +++ b/drivers/watchdog/rzv2h_wdt.c > @@ -4,14 +4,17 @@ > * > * Copyright (C) 2024 Renesas Electronics Corporation. > */ > +#include <linux/bitfield.h> > #include <linux/clk.h> > #include <linux/delay.h> > #include <linux/io.h> > #include <linux/kernel.h> > +#include <linux/mfd/syscon.h> > #include <linux/module.h> > #include <linux/of.h> > #include <linux/platform_device.h> > #include <linux/pm_runtime.h> > +#include <linux/regmap.h> > #include <linux/reset.h> > #include <linux/units.h> > #include <linux/watchdog.h> > @@ -40,6 +43,10 @@ > > #define WDT_DEFAULT_TIMEOUT 60U > > +#define CPG_ERROR_RST2 0xb40 > +#define CPG_ERROR_RST2_ERR_RST1 BIT(1) > +#define CPG_ERROR_RST2_ERR_RST1_WEN (BIT(1) << 16) I could understand BIT(17) or BIT(1 + 16) or #define CPG_ERROR_RST2_ERR_RST1_BIT 1 #define CPG_ERROR_RST2_ERR_RST1 BIT(CPG_ERROR_RST2_ERR_RST1_BIT) #define CPG_ERROR_RST2_ERR_RST1_WEN BIT(CPG_ERROR_RST2_ERR_RST1_BIT + 16) but "BIT(1) << 16" really does not add value. > + > static bool nowayout = WATCHDOG_NOWAYOUT; > module_param(nowayout, bool, 0); > MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" > @@ -135,7 +142,7 @@ static int rzv2h_wdt_stop(struct watchdog_device *wdev) > } > > static const struct watchdog_info rzv2h_wdt_ident = { > - .options = WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT, > + .options = WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_CARDRESET, > .identity = "Renesas RZ/V2H WDT Watchdog", > }; > > @@ -207,12 +214,29 @@ static int rzv2h_wdt_probe(struct platform_device *pdev) > { > struct device *dev = &pdev->dev; > struct rzv2h_wdt_priv *priv; > + struct regmap *regmap; > + unsigned int buf; That is a bad variable name since it suggests a buffer, not some register content. > int ret; > > priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); > if (!priv) > return -ENOMEM; > > + regmap = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon"); > + if (IS_ERR(regmap)) > + return PTR_ERR(regmap); > + That is a change in behavior. Up to now the syscon phandle did not have to exist for the driver to work. Is it guaranteed to not result in regressions on systems where it doesn't ? Also, is this documented ? I don't seem to be able to find it. > + ret = regmap_read(regmap, CPG_ERROR_RST2, &buf); > + if (ret) > + return -EINVAL; Pass error codes back to caller. This is most definitely not an "Invalid argument". " > + > + if (buf & CPG_ERROR_RST2_ERR_RST1) { > + ret = regmap_write(regmap, CPG_ERROR_RST2, > + CPG_ERROR_RST2_ERR_RST1_WEN | CPG_ERROR_RST2_ERR_RST1); > + if (ret) > + return -EINVAL; Same as above. > + } > + > priv->base = devm_platform_ioremap_resource(pdev, 0); > if (IS_ERR(priv->base)) > return PTR_ERR(priv->base); > @@ -243,6 +267,7 @@ static int rzv2h_wdt_probe(struct platform_device *pdev) > priv->wdev.info = &rzv2h_wdt_ident; > priv->wdev.ops = &rzv2h_wdt_ops; > priv->wdev.parent = dev; > + priv->wdev.bootstatus = buf & CPG_ERROR_RST2_ERR_RST1 ? WDIOF_CARDRESET : 0; > watchdog_set_drvdata(&priv->wdev, priv); > watchdog_set_nowayout(&priv->wdev, nowayout); > watchdog_stop_on_unregister(&priv->wdev);
Hi Guenter, Thank you for the review. On Fri, Dec 13, 2024 at 6:03 PM Guenter Roeck <linux@roeck-us.net> wrote: > > On 12/13/24 09:44, Prabhakar wrote: > > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > > > On the RZ/V2H(P) SoC we can determine if the current boot is due to > > `Power-on-Reset` or due to the `Watchdog`. The information used to > > determine this is present on the CPG block. > > > > The CPG_ERROR_RSTm(m = 2 -8 ) registers are set in response to an error > > interrupt causing an reset. CPG_ERROR_RST2[ERROR_RST1] is set if there > > was an underflow/overflow on WDT1 causing an error interrupt. > > > > To fetch this information from CPG block `syscon` is used and bootstatus > > field in the watchdog device is updated based on the > > CPG_ERROR_RST2[ERROR_RST1] bit. Upon consumig CPG_ERROR_RST2[ERROR_RST1] > > bit we are also clearing it. > > > > Signed-off-by: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > --- > > @Geert, I intend to drop WDT0/2/3 nodes (and related clocks) as HW manual > > says WDT1 is for CA55 (I'll first confirm this internally) > > > > Hi Geert/Rob, > > > > I havent included a binding changes as part of the RFC as I wanted to get > > some initial feedback on the implementation. Currently CPG block doesnt > > have the "syscon" this patch has been tested with below diff to SoC DTSI > > > > Cheers, > > Prabhakar > > > > Changes to SoC DTSI: > > @@ -243,7 +243,7 @@ pinctrl: pinctrl@10410000 { > > }; > > > > cpg: clock-controller@10420000 { > > - compatible = "renesas,r9a09g057-cpg"; > > + compatible = "renesas,r9a09g057-cpg", "syscon"; > > reg = <0 0x10420000 0 0x10000>; > > clocks = <&audio_extal_clk>, <&rtxin_clk>, <&qextal_clk>; > > clock-names = "audio_extal", "rtxin", "qextal"; > > @@ -455,6 +456,7 @@ wdt1: watchdog@14400000 { > > clock-names = "pclk", "oscclk"; > > resets = <&cpg 0x76>; > > power-domains = <&cpg>; > > + syscon = <&cpg>; > > status = "disabled"; > > }; > > > > --- > > drivers/watchdog/rzv2h_wdt.c | 27 ++++++++++++++++++++++++++- > > 1 file changed, 26 insertions(+), 1 deletion(-) > > > > diff --git a/drivers/watchdog/rzv2h_wdt.c b/drivers/watchdog/rzv2h_wdt.c > > index 8defd0241213..8e0901bb7d2b 100644 > > --- a/drivers/watchdog/rzv2h_wdt.c > > +++ b/drivers/watchdog/rzv2h_wdt.c > > @@ -4,14 +4,17 @@ > > * > > * Copyright (C) 2024 Renesas Electronics Corporation. > > */ > > +#include <linux/bitfield.h> > > #include <linux/clk.h> > > #include <linux/delay.h> > > #include <linux/io.h> > > #include <linux/kernel.h> > > +#include <linux/mfd/syscon.h> > > #include <linux/module.h> > > #include <linux/of.h> > > #include <linux/platform_device.h> > > #include <linux/pm_runtime.h> > > +#include <linux/regmap.h> > > #include <linux/reset.h> > > #include <linux/units.h> > > #include <linux/watchdog.h> > > @@ -40,6 +43,10 @@ > > > > #define WDT_DEFAULT_TIMEOUT 60U > > > > +#define CPG_ERROR_RST2 0xb40 > > +#define CPG_ERROR_RST2_ERR_RST1 BIT(1) > > +#define CPG_ERROR_RST2_ERR_RST1_WEN (BIT(1) << 16) > > I could understand BIT(17) or BIT(1 + 16) or > > #define CPG_ERROR_RST2_ERR_RST1_BIT 1 > #define CPG_ERROR_RST2_ERR_RST1 BIT(CPG_ERROR_RST2_ERR_RST1_BIT) > #define CPG_ERROR_RST2_ERR_RST1_WEN BIT(CPG_ERROR_RST2_ERR_RST1_BIT + 16) > > but "BIT(1) << 16" really does not add value. > OK, I will switch to the above mentioned macros. > > + > > static bool nowayout = WATCHDOG_NOWAYOUT; > > module_param(nowayout, bool, 0); > > MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" > > @@ -135,7 +142,7 @@ static int rzv2h_wdt_stop(struct watchdog_device *wdev) > > } > > > > static const struct watchdog_info rzv2h_wdt_ident = { > > - .options = WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT, > > + .options = WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_CARDRESET, > > .identity = "Renesas RZ/V2H WDT Watchdog", > > }; > > > > @@ -207,12 +214,29 @@ static int rzv2h_wdt_probe(struct platform_device *pdev) > > { > > struct device *dev = &pdev->dev; > > struct rzv2h_wdt_priv *priv; > > + struct regmap *regmap; > > + unsigned int buf; > > That is a bad variable name since it suggests a buffer, not some > register content. > Agreed I will rename it to reg. > > int ret; > > > > priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); > > if (!priv) > > return -ENOMEM; > > > > + regmap = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon"); > > + if (IS_ERR(regmap)) > > + return PTR_ERR(regmap); > > + > > That is a change in behavior. Up to now the syscon phandle did not have to exist > for the driver to work. Is it guaranteed to not result in regressions on systems > where it doesn't ? Also, is this documented ? I don't seem to be able to find it. > Agreed. I will add a fallback mechanism to handle cases where the syscon property is not present in the WDT node. This will ensure no regressions occur, and the bootstatus will simply be set to 0 in such scenarios. As mentioned in the patch comments, I have not yet submitted the DT binding changes because I wanted feedback on the syscon approach. The new RZ SoCs have registers scattered across various locations, and I was exploring if there might be a better way to handle this. > > + ret = regmap_read(regmap, CPG_ERROR_RST2, &buf); > > + if (ret) > > + return -EINVAL; > > Pass error codes back to caller. This is most definitely not an > "Invalid argument". > OK. > " > > + > > + if (buf & CPG_ERROR_RST2_ERR_RST1) { > > + ret = regmap_write(regmap, CPG_ERROR_RST2, > > + CPG_ERROR_RST2_ERR_RST1_WEN | CPG_ERROR_RST2_ERR_RST1); > > + if (ret) > > + return -EINVAL; > > Same as above. > OK. Cheers, Prabhakar
Hi Lad, Prabhakar, > -----Original Message----- > From: Lad, Prabhakar <prabhakar.csengg@gmail.com> > Sent: 13 December 2024 19:08 > Subject: Re: [RFC PATCH] watchdog: rzv2h_wdt: Add support to retrieve the bootstatus information > > Hi Guenter, > > Thank you for the review. > > On Fri, Dec 13, 2024 at 6:03 PM Guenter Roeck <linux@roeck-us.net> wrote: > > > > On 12/13/24 09:44, Prabhakar wrote: > > > From: Lad Prabhakar <prabhakar.mahadev-lad.rj@bp.renesas.com> > > > > > > On the RZ/V2H(P) SoC we can determine if the current boot is due to > > > `Power-on-Reset` or due to the `Watchdog`. The information used to > > > determine this is present on the CPG block. > > > > > > The CPG_ERROR_RSTm(m = 2 -8 ) registers are set in response to an > > > error interrupt causing an reset. CPG_ERROR_RST2[ERROR_RST1] is set > > > if there was an underflow/overflow on WDT1 causing an error interrupt. > > > > > > To fetch this information from CPG block `syscon` is used and > > > bootstatus field in the watchdog device is updated based on the > > > CPG_ERROR_RST2[ERROR_RST1] bit. Upon consumig > > > CPG_ERROR_RST2[ERROR_RST1] bit we are also clearing it. > > > > > > Signed-off-by: Lad Prabhakar > > > <prabhakar.mahadev-lad.rj@bp.renesas.com> > > > --- > > > @Geert, I intend to drop WDT0/2/3 nodes (and related clocks) as HW > > > manual says WDT1 is for CA55 (I'll first confirm this internally) > > > > > > Hi Geert/Rob, > > > > > > I havent included a binding changes as part of the RFC as I wanted > > > to get some initial feedback on the implementation. Currently CPG > > > block doesnt have the "syscon" this patch has been tested with below > > > diff to SoC DTSI > > > > > > Cheers, > > > Prabhakar > > > > > > Changes to SoC DTSI: > > > @@ -243,7 +243,7 @@ pinctrl: pinctrl@10410000 { > > > }; > > > > > > cpg: clock-controller@10420000 { > > > - compatible = "renesas,r9a09g057-cpg"; > > > + compatible = "renesas,r9a09g057-cpg", > > > + "syscon"; > > > reg = <0 0x10420000 0 0x10000>; > > > clocks = <&audio_extal_clk>, <&rtxin_clk>, <&qextal_clk>; > > > clock-names = "audio_extal", "rtxin", > > > "qextal"; @@ -455,6 +456,7 @@ wdt1: watchdog@14400000 { > > > clock-names = "pclk", "oscclk"; > > > resets = <&cpg 0x76>; > > > power-domains = <&cpg>; > > > + syscon = <&cpg>; > > > status = "disabled"; > > > }; > > > > > > --- > > > drivers/watchdog/rzv2h_wdt.c | 27 ++++++++++++++++++++++++++- > > > 1 file changed, 26 insertions(+), 1 deletion(-) > > > > > > diff --git a/drivers/watchdog/rzv2h_wdt.c > > > b/drivers/watchdog/rzv2h_wdt.c index 8defd0241213..8e0901bb7d2b > > > 100644 > > > --- a/drivers/watchdog/rzv2h_wdt.c > > > +++ b/drivers/watchdog/rzv2h_wdt.c > > > @@ -4,14 +4,17 @@ > > > * > > > * Copyright (C) 2024 Renesas Electronics Corporation. > > > */ > > > +#include <linux/bitfield.h> > > > #include <linux/clk.h> > > > #include <linux/delay.h> > > > #include <linux/io.h> > > > #include <linux/kernel.h> > > > +#include <linux/mfd/syscon.h> > > > #include <linux/module.h> > > > #include <linux/of.h> > > > #include <linux/platform_device.h> > > > #include <linux/pm_runtime.h> > > > +#include <linux/regmap.h> > > > #include <linux/reset.h> > > > #include <linux/units.h> > > > #include <linux/watchdog.h> > > > @@ -40,6 +43,10 @@ > > > > > > #define WDT_DEFAULT_TIMEOUT 60U > > > > > > +#define CPG_ERROR_RST2 0xb40 > > > +#define CPG_ERROR_RST2_ERR_RST1 BIT(1) > > > +#define CPG_ERROR_RST2_ERR_RST1_WEN (BIT(1) << 16) > > > > I could understand BIT(17) or BIT(1 + 16) or > > > > #define CPG_ERROR_RST2_ERR_RST1_BIT 1 > > #define CPG_ERROR_RST2_ERR_RST1 BIT(CPG_ERROR_RST2_ERR_RST1_BIT) > > #define CPG_ERROR_RST2_ERR_RST1_WEN BIT(CPG_ERROR_RST2_ERR_RST1_BIT + 16) > > > > but "BIT(1) << 16" really does not add value. > > > OK, I will switch to the above mentioned macros. > > > > + > > > static bool nowayout = WATCHDOG_NOWAYOUT; > > > module_param(nowayout, bool, 0); > > > MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" > > > @@ -135,7 +142,7 @@ static int rzv2h_wdt_stop(struct watchdog_device *wdev) > > > } > > > > > > static const struct watchdog_info rzv2h_wdt_ident = { > > > - .options = WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT, > > > + .options = WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING | > > > + WDIOF_SETTIMEOUT | WDIOF_CARDRESET, > > > .identity = "Renesas RZ/V2H WDT Watchdog", > > > }; > > > > > > @@ -207,12 +214,29 @@ static int rzv2h_wdt_probe(struct platform_device *pdev) > > > { > > > struct device *dev = &pdev->dev; > > > struct rzv2h_wdt_priv *priv; > > > + struct regmap *regmap; > > > + unsigned int buf; > > > > That is a bad variable name since it suggests a buffer, not some > > register content. > > > Agreed I will rename it to reg. > > > > int ret; > > > > > > priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); > > > if (!priv) > > > return -ENOMEM; > > > > > > + regmap = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon"); > > > + if (IS_ERR(regmap)) > > > + return PTR_ERR(regmap); > > > + > > > > That is a change in behavior. Up to now the syscon phandle did not > > have to exist for the driver to work. Is it guaranteed to not result > > in regressions on systems where it doesn't ? Also, is this documented ? I don't seem to be able to > find it. > > > Agreed. I will add a fallback mechanism to handle cases where the syscon property is not present in > the WDT node. This will ensure no regressions occur, and the bootstatus will simply be set to 0 in > such scenarios. As mentioned in the patch comments, I have not yet submitted the DT binding changes > because I wanted feedback on the syscon approach. The new RZ SoCs have registers scattered across > various locations, and I was exploring if there might be a better way to handle this. See, syscon compatible not needed with [1] [1] https://lore.kernel.org/all/20241211-syscon-fixes-v1-3-b5ac8c219e96@kernel.org/ Cheers, Biju
Hi Biju, On Sat, Dec 14, 2024 at 11:32 AM Biju Das <biju.das.jz@bp.renesas.com> wrote: > > Hi Lad, Prabhakar, > <snip> > > > That is a change in behavior. Up to now the syscon phandle did not > > > have to exist for the driver to work. Is it guaranteed to not result > > > in regressions on systems where it doesn't ? Also, is this documented ? I don't seem to be able to > > find it. > > > > > Agreed. I will add a fallback mechanism to handle cases where the syscon property is not present in > > the WDT node. This will ensure no regressions occur, and the bootstatus will simply be set to 0 in > > such scenarios. As mentioned in the patch comments, I have not yet submitted the DT binding changes > > because I wanted feedback on the syscon approach. The new RZ SoCs have registers scattered across > > various locations, and I was exploring if there might be a better way to handle this. > > See, syscon compatible not needed with [1] > > [1] > https://lore.kernel.org/all/20241211-syscon-fixes-v1-3-b5ac8c219e96@kernel.org/ > As per my understanding, `syscon` compatible is required in this case because the CPG driver does not register a regmap. With the patch [1] (linked above), this applies to drivers that register a syscon regmap, where the corresponding DT node does not necessarily need a `syscon` compatible. Cheers, Prabhakar
Hi Prabhakar, > -----Original Message----- > From: Lad, Prabhakar <prabhakar.csengg@gmail.com> > Sent: 14 December 2024 21:36 > Subject: Re: [RFC PATCH] watchdog: rzv2h_wdt: Add support to retrieve the bootstatus information > > Hi Biju, > > On Sat, Dec 14, 2024 at 11:32 AM Biju Das <biju.das.jz@bp.renesas.com> wrote: > > > > Hi Lad, Prabhakar, > > > <snip> > > > > That is a change in behavior. Up to now the syscon phandle did not > > > > have to exist for the driver to work. Is it guaranteed to not > > > > result in regressions on systems where it doesn't ? Also, is this > > > > documented ? I don't seem to be able to > > > find it. > > > > > > > Agreed. I will add a fallback mechanism to handle cases where the > > > syscon property is not present in the WDT node. This will ensure no > > > regressions occur, and the bootstatus will simply be set to 0 in > > > such scenarios. As mentioned in the patch comments, I have not yet > > > submitted the DT binding changes because I wanted feedback on the syscon approach. The new RZ SoCs > have registers scattered across various locations, and I was exploring if there might be a better way > to handle this. > > > > See, syscon compatible not needed with [1] > > > > [1] > > https://lore.kernel.org/all/20241211-syscon-fixes-v1-3-b5ac8c219e96@ke > > rnel.org/ > > > As per my understanding, `syscon` compatible is required in this case because the CPG driver does not > register a regmap. With the patch [1] (linked above), this applies to drivers that register a syscon > regmap, where the corresponding DT node does not necessarily need a `syscon` compatible. I guess you can use "syscon_node_to_regmap" for that as of_syscon_register_regmap() is for externally created regmaps?? syscon_regmap_lookup_by_phandle() in turn call syscon_node_to_regmap() Cheers, Biju
Hi Biju, On Sun, Dec 15, 2024 at 9:15 AM Biju Das <biju.das.jz@bp.renesas.com> wrote: > > Hi Prabhakar, > > > -----Original Message----- > > From: Lad, Prabhakar <prabhakar.csengg@gmail.com> > > Sent: 14 December 2024 21:36 > > Subject: Re: [RFC PATCH] watchdog: rzv2h_wdt: Add support to retrieve the bootstatus information > > > > Hi Biju, > > > > On Sat, Dec 14, 2024 at 11:32 AM Biju Das <biju.das.jz@bp.renesas.com> wrote: > > > > > > Hi Lad, Prabhakar, > > > > > <snip> > > > > > That is a change in behavior. Up to now the syscon phandle did not > > > > > have to exist for the driver to work. Is it guaranteed to not > > > > > result in regressions on systems where it doesn't ? Also, is this > > > > > documented ? I don't seem to be able to > > > > find it. > > > > > > > > > Agreed. I will add a fallback mechanism to handle cases where the > > > > syscon property is not present in the WDT node. This will ensure no > > > > regressions occur, and the bootstatus will simply be set to 0 in > > > > such scenarios. As mentioned in the patch comments, I have not yet > > > > submitted the DT binding changes because I wanted feedback on the syscon approach. The new RZ SoCs > > have registers scattered across various locations, and I was exploring if there might be a better way > > to handle this. > > > > > > See, syscon compatible not needed with [1] > > > > > > [1] > > > https://lore.kernel.org/all/20241211-syscon-fixes-v1-3-b5ac8c219e96@ke > > > rnel.org/ > > > > > As per my understanding, `syscon` compatible is required in this case because the CPG driver does not > > register a regmap. With the patch [1] (linked above), this applies to drivers that register a syscon > > regmap, where the corresponding DT node does not necessarily need a `syscon` compatible. > > I guess you can use "syscon_node_to_regmap" for that as of_syscon_register_regmap() is for externally > created regmaps?? > No, it doesn't work either; the CPG node block needs to have `syscon` compatible when you are using syscon_node_to_regmap/syscon_regmap_lookup_by_phandle. See patch [0] in `device_node_get_regmap()` the `of_syscon_register()` is only called when it has a `syscon` compatible or else `-EINVAL` is returned. [0] https://lore.kernel.org/all/20241211-syscon-fixes-v1-3-b5ac8c219e96@kernel.org/ Cheers, Prabhakar
Hi Prabhakar, > -----Original Message----- > From: Lad, Prabhakar <prabhakar.csengg@gmail.com> > Sent: 16 December 2024 13:14 > Subject: Re: [RFC PATCH] watchdog: rzv2h_wdt: Add support to retrieve the bootstatus information > > Hi Biju, > > On Sun, Dec 15, 2024 at 9:15 AM Biju Das <biju.das.jz@bp.renesas.com> wrote: > > > > Hi Prabhakar, > > > > > -----Original Message----- > > > From: Lad, Prabhakar <prabhakar.csengg@gmail.com> > > > Sent: 14 December 2024 21:36 > > > Subject: Re: [RFC PATCH] watchdog: rzv2h_wdt: Add support to > > > retrieve the bootstatus information > > > > > > Hi Biju, > > > > > > On Sat, Dec 14, 2024 at 11:32 AM Biju Das <biju.das.jz@bp.renesas.com> wrote: > > > > > > > > Hi Lad, Prabhakar, > > > > > > > <snip> > > > > > > That is a change in behavior. Up to now the syscon phandle did > > > > > > not have to exist for the driver to work. Is it guaranteed to > > > > > > not result in regressions on systems where it doesn't ? Also, > > > > > > is this documented ? I don't seem to be able to > > > > > find it. > > > > > > > > > > > Agreed. I will add a fallback mechanism to handle cases where > > > > > the syscon property is not present in the WDT node. This will > > > > > ensure no regressions occur, and the bootstatus will simply be > > > > > set to 0 in such scenarios. As mentioned in the patch comments, > > > > > I have not yet submitted the DT binding changes because I wanted > > > > > feedback on the syscon approach. The new RZ SoCs > > > have registers scattered across various locations, and I was > > > exploring if there might be a better way to handle this. > > > > > > > > See, syscon compatible not needed with [1] > > > > > > > > [1] > > > > https://lore.kernel.org/all/20241211-syscon-fixes-v1-3-b5ac8c219e9 > > > > 6@ke > > > > rnel.org/ > > > > > > > As per my understanding, `syscon` compatible is required in this > > > case because the CPG driver does not register a regmap. With the > > > patch [1] (linked above), this applies to drivers that register a syscon regmap, where the > corresponding DT node does not necessarily need a `syscon` compatible. > > > > I guess you can use "syscon_node_to_regmap" for that as > > of_syscon_register_regmap() is for externally created regmaps?? > > > No, it doesn't work either; the CPG node block needs to have `syscon` compatible when you are using > syscon_node_to_regmap/syscon_regmap_lookup_by_phandle. See patch [0] in `device_node_get_regmap()` the > `of_syscon_register()` is only called when it has a `syscon` compatible or else `-EINVAL` is returned. > > [0] https://lore.kernel.org/all/20241211-syscon-fixes-v1-3-b5ac8c219e96@kernel.org/ Not sure the patch series, intention is to support only external regmap for those who does not have "syscon" compatible?? I thought the intention was, without "syscon" compatible, still it creates internal regmap, based on reg property of the system controller device node. Cheers, Biju
diff --git a/drivers/watchdog/rzv2h_wdt.c b/drivers/watchdog/rzv2h_wdt.c index 8defd0241213..8e0901bb7d2b 100644 --- a/drivers/watchdog/rzv2h_wdt.c +++ b/drivers/watchdog/rzv2h_wdt.c @@ -4,14 +4,17 @@ * * Copyright (C) 2024 Renesas Electronics Corporation. */ +#include <linux/bitfield.h> #include <linux/clk.h> #include <linux/delay.h> #include <linux/io.h> #include <linux/kernel.h> +#include <linux/mfd/syscon.h> #include <linux/module.h> #include <linux/of.h> #include <linux/platform_device.h> #include <linux/pm_runtime.h> +#include <linux/regmap.h> #include <linux/reset.h> #include <linux/units.h> #include <linux/watchdog.h> @@ -40,6 +43,10 @@ #define WDT_DEFAULT_TIMEOUT 60U +#define CPG_ERROR_RST2 0xb40 +#define CPG_ERROR_RST2_ERR_RST1 BIT(1) +#define CPG_ERROR_RST2_ERR_RST1_WEN (BIT(1) << 16) + static bool nowayout = WATCHDOG_NOWAYOUT; module_param(nowayout, bool, 0); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" @@ -135,7 +142,7 @@ static int rzv2h_wdt_stop(struct watchdog_device *wdev) } static const struct watchdog_info rzv2h_wdt_ident = { - .options = WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT, + .options = WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT | WDIOF_CARDRESET, .identity = "Renesas RZ/V2H WDT Watchdog", }; @@ -207,12 +214,29 @@ static int rzv2h_wdt_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct rzv2h_wdt_priv *priv; + struct regmap *regmap; + unsigned int buf; int ret; priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); if (!priv) return -ENOMEM; + regmap = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon"); + if (IS_ERR(regmap)) + return PTR_ERR(regmap); + + ret = regmap_read(regmap, CPG_ERROR_RST2, &buf); + if (ret) + return -EINVAL; + + if (buf & CPG_ERROR_RST2_ERR_RST1) { + ret = regmap_write(regmap, CPG_ERROR_RST2, + CPG_ERROR_RST2_ERR_RST1_WEN | CPG_ERROR_RST2_ERR_RST1); + if (ret) + return -EINVAL; + } + priv->base = devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(priv->base)) return PTR_ERR(priv->base); @@ -243,6 +267,7 @@ static int rzv2h_wdt_probe(struct platform_device *pdev) priv->wdev.info = &rzv2h_wdt_ident; priv->wdev.ops = &rzv2h_wdt_ops; priv->wdev.parent = dev; + priv->wdev.bootstatus = buf & CPG_ERROR_RST2_ERR_RST1 ? WDIOF_CARDRESET : 0; watchdog_set_drvdata(&priv->wdev, priv); watchdog_set_nowayout(&priv->wdev, nowayout); watchdog_stop_on_unregister(&priv->wdev);