[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID:
<TYZPR06MB5203E67A63085A477165DC7DB21E2@TYZPR06MB5203.apcprd06.prod.outlook.com>
Date: Sun, 12 Jan 2025 07:43:16 +0000
From: Chin-Ting Kuo <chin-ting_kuo@...eedtech.com>
To: Guenter Roeck <linux@...ck-us.net>, "patrick@...cx.xyz"
<patrick@...cx.xyz>, "andrew@...econstruct.com.au"
<andrew@...econstruct.com.au>, "wim@...ux-watchdog.org"
<wim@...ux-watchdog.org>, "joel@....id.au" <joel@....id.au>,
"linux-watchdog@...r.kernel.org" <linux-watchdog@...r.kernel.org>,
"linux-arm-kernel@...ts.infradead.org"
<linux-arm-kernel@...ts.infradead.org>, "linux-aspeed@...ts.ozlabs.org"
<linux-aspeed@...ts.ozlabs.org>, "linux-kernel@...r.kernel.org"
<linux-kernel@...r.kernel.org>
CC: "Peter.Yin@...ntatw.com" <Peter.Yin@...ntatw.com>,
"Patrick_NC_Lin@...ynn.com" <Patrick_NC_Lin@...ynn.com>, BMC-SW
<BMC-SW@...eedtech.com>, "chnguyen@...erecomputing.com"
<chnguyen@...erecomputing.com>, Aaron Lee <aaron_lee@...eedtech.com>
Subject: RE: [PATCH v5 1/1] watchdog: aspeed: Update bootstatus handling
Hi Guenter,
Thanks for the review.
> -----Original Message-----
> From: Guenter Roeck <groeck7@...il.com> On Behalf Of Guenter Roeck
> Sent: Tuesday, January 7, 2025 11:14 AM
> Subject: Re: [PATCH v5 1/1] watchdog: aspeed: Update bootstatus handling
>
> On 12/31/24 23:01, Chin-Ting Kuo wrote:
> > The boot status in the watchdog device struct is updated during
> > controller probe stage. Application layer can get the boot status
> > through the command, cat /sys/class/watchdog/watchdogX/bootstatus.
> > The bootstatus can be,
> > WDIOF_CARDRESET => the system is reset by WDT SoC reset.
> > Others => other reset events, e.g., power on reset.
> >
> > On ASPEED platform, the boot status is recorded in the SCU registers.
> > - AST2400: Only a bit represents for any WDT reset.
> > - AST2500/AST2600: The reset triggered by different WDT controllers
> > can be distinguished by different SCU bits.
> >
> > Besides, on AST2400 and AST2500, since alternating boot event is
> > triggered by WDT SoC reset, it is classified as WDIOF_CARDRESET.
> >
> > Signed-off-by: Chin-Ting Kuo <chin-ting_kuo@...eedtech.com>
> > ---
> > drivers/watchdog/aspeed_wdt.c | 85
> ++++++++++++++++++++++++++++++++++-
> > 1 file changed, 83 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/watchdog/aspeed_wdt.c
> > b/drivers/watchdog/aspeed_wdt.c index b4773a6aaf8c..1fae70b2fa6b
> > 100644
> > --- a/drivers/watchdog/aspeed_wdt.c
> > +++ b/drivers/watchdog/aspeed_wdt.c
> > @@ -11,21 +11,30 @@
> > #include <linux/io.h>
> > #include <linux/kernel.h>
> > #include <linux/kstrtox.h>
> > +#include <linux/mfd/syscon.h>
> > #include <linux/module.h>
> > #include <linux/of.h>
> > #include <linux/of_irq.h>
> > #include <linux/platform_device.h>
> > +#include <linux/regmap.h>
> > #include <linux/watchdog.h>
> >
> > static bool nowayout = WATCHDOG_NOWAYOUT;
> > module_param(nowayout, bool, 0);
> > MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once
> started (default="
> > __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
> > +struct aspeed_wdt_scu {
> > + const char *compatible;
> > + u32 reset_status_reg;
> > + u32 wdt_reset_mask;
> > + u32 wdt_reset_mask_shift;
> > +};
> >
> > struct aspeed_wdt_config {
> > u32 ext_pulse_width_mask;
> > u32 irq_shift;
> > u32 irq_mask;
> > + struct aspeed_wdt_scu scu;
> > };
> >
> > struct aspeed_wdt {
> > @@ -39,18 +48,36 @@ static const struct aspeed_wdt_config
> ast2400_config = {
> > .ext_pulse_width_mask = 0xff,
> > .irq_shift = 0,
> > .irq_mask = 0,
> > + .scu = {
> > + .compatible = "aspeed,ast2400-scu",
> > + .reset_status_reg = 0x3c,
> > + .wdt_reset_mask = 0x1,
> > + .wdt_reset_mask_shift = 1,
> > + },
> > };
> >
> > static const struct aspeed_wdt_config ast2500_config = {
> > .ext_pulse_width_mask = 0xfffff,
> > .irq_shift = 12,
> > .irq_mask = GENMASK(31, 12),
> > + .scu = {
> > + .compatible = "aspeed,ast2500-scu",
> > + .reset_status_reg = 0x3c,
> > + .wdt_reset_mask = 0x1,
> > + .wdt_reset_mask_shift = 2,
> > + },
> > };
> >
> > static const struct aspeed_wdt_config ast2600_config = {
> > .ext_pulse_width_mask = 0xfffff,
> > .irq_shift = 0,
> > .irq_mask = GENMASK(31, 10),
> > + .scu = {
> > + .compatible = "aspeed,ast2600-scu",
> > + .reset_status_reg = 0x74,
> > + .wdt_reset_mask = 0xf,
> > + .wdt_reset_mask_shift = 16,
> > + },
> > };
> >
> > static const struct of_device_id aspeed_wdt_of_table[] = { @@ -213,6
> > +240,60 @@ static int aspeed_wdt_restart(struct watchdog_device *wdd,
> > return 0;
> > }
> >
> > +static void aspeed_wdt_update_bootstatus(struct platform_device *pdev,
> > + struct aspeed_wdt *wdt)
> > +{
> > + struct resource *res;
> > + struct aspeed_wdt_scu scu = wdt->cfg->scu;
> > + struct regmap *scu_base;
> > + u32 reset_mask_width;
> > + u32 reset_mask_shift;
> > + u32 reg_size;
> > + u32 idx = 0;
> > + u32 status;
> > + int ret;
> > +
> > + if (!of_device_is_compatible(pdev->dev.of_node, "aspeed,ast2400-wdt"))
> {
> > + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> > + if (res) {
> > + reg_size = res->end - res->start;
>
> Is this correct ? Normally one would use resource_size() which is
> res->end - res->start + 1.
>
You are correct. This will be updated in the next patch version.
> > + if (reg_size)
>
> ... and then this if() would not be needed. Either case, if res->end - res->start is
> 1, there are actually 2 registers, so the calculation seems off.
>
Thanks for the reminder. This will be updated in the next patch version.
> > + idx = ((intptr_t)wdt->base & 0x00000fff) / reg_size;
> > + }
> > + }
> > +
> > + wdt->wdd.bootstatus = WDIOS_UNKNOWN;
> > + scu_base = syscon_regmap_lookup_by_compatible(scu.compatible);
> > + if (IS_ERR(scu_base))
> > + return;
>
> This should be
> if (IS_ERR(scu_base)) {
> wdt->wdd.bootstatus = WDIOS_UNKNOWN;
> return;
> }
>
Okay, will be updated.
> to avoid having to clear it below.
>
> > +
> > + ret = regmap_read(scu_base, scu.reset_status_reg, &status);
> > + if (ret)
> > + return;
> > +
> > + reset_mask_width = hweight32(scu.wdt_reset_mask);
> > + reset_mask_shift = scu.wdt_reset_mask_shift +
> > + reset_mask_width * idx;
> > +
> > + if (status & (scu.wdt_reset_mask << reset_mask_shift))
> > + wdt->wdd.bootstatus = WDIOF_CARDRESET;
> > + else
> > + wdt->wdd.bootstatus = 0;
> > +
> > + /* clear wdt reset event flag */
> > + if (of_device_is_compatible(pdev->dev.of_node, "aspeed,ast2400-wdt") ||
> > + of_device_is_compatible(pdev->dev.of_node, "aspeed,ast2500-wdt"))
> {
> > + ret = regmap_read(scu_base, scu.reset_status_reg, &status);
> > + if (!ret) {
> > + status &= ~(scu.wdt_reset_mask << reset_mask_shift);
> > + regmap_write(scu_base, scu.reset_status_reg, status);
> > + }
> > + } else {
> > + regmap_write(scu_base, scu.reset_status_reg,
> > + scu.wdt_reset_mask << reset_mask_shift);
> > + }
> > +}
> > +
> > /* access_cs0 shows if cs0 is accessible, hence the reverted bit */
> > static ssize_t access_cs0_show(struct device *dev,
> > struct device_attribute *attr, char *buf) @@
> -458,10
> > +539,10 @@ static int aspeed_wdt_probe(struct platform_device *pdev)
> > writel(duration - 1, wdt->base + WDT_RESET_WIDTH);
> > }
> >
> > + aspeed_wdt_update_bootstatus(pdev, wdt);
> > +
> > status = readl(wdt->base + WDT_TIMEOUT_STATUS);
> > if (status & WDT_TIMEOUT_STATUS_BOOT_SECONDARY) {
> > - wdt->wdd.bootstatus = WDIOF_CARDRESET;
> > -
> > if (of_device_is_compatible(np, "aspeed,ast2400-wdt") ||
> > of_device_is_compatible(np, "aspeed,ast2500-wdt"))
> > wdt->wdd.groups = bswitch_groups;
Best Wishes,
Chin-Ting
Powered by blists - more mailing lists