From patchwork Thu Apr 25 09:07:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: PeterYin X-Patchwork-Id: 13642994 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id ECB62C4345F for ; Thu, 25 Apr 2024 09:08:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=rutUTEEv/2+ZBwmv45HER1r4YQ3VkGRtYvDhPGmkeTc=; b=LJeMYcRkUwnHZN c1s2xO+9or0elWVI1JoxPHS3ARNLXLXRz1HvSnodualhvdouSDZPLpD+zkRZQwGNU6g5ginrA3fho ulhINhfdoVjNfBwxaA3SBvkNq7cfV870AZtzHJ4DN0amAFGlC2FzOATkfemm105vsyFZMtYd2mvPJ MO7XQfqzY6L1rL9vT7zvTr0yzwjI2I8JNffRvatzewPz0AOd36cHi/+NcJyBEgTbUI6/0nCLy7mJh o5lc+G40gve1y7XEuj54+D+hiChssdil35nHDWjRJsayb6vd0Q07/vsgsqZOTUtgW4OSRCOjL/EzN RMVPLQ+2m/dSgJ3EuJww==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzv50-00000007XhJ-3pvW; Thu, 25 Apr 2024 09:07:46 +0000 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rzv4q-00000007Xds-39b5 for linux-arm-kernel@lists.infradead.org; Thu, 25 Apr 2024 09:07:38 +0000 Received: by mail-pg1-x531.google.com with SMTP id 41be03b00d2f7-5dcc4076c13so580357a12.0 for ; Thu, 25 Apr 2024 02:07:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714036055; x=1714640855; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=+4wTUU05Xd7j3sy440urBnEwP2fHUD5P7kgF0xvHMjc=; b=hyIwy6XuP2C9ggxhXs9fEwxcjtSxYm/0CWCHz2opOzmDXTn1Yfyh+PV3JGWVZuuAM4 01IJc3VUSTxA8I/8xhDLfU1HEgitQcgTxXQubZil5TMMPW8np/R9jYDGGGsKDsjm7S9h B6UXhHkqFyLB89JT1HpZf47LulaLZBVywYvzrW5NOD2cUVcXecca5TruvO7wIbrD2D3S nldBjNFvRbQhMwtoa+byLtX4Qa6jngu3job7gL0asAVryeFPKAhFRWjkm1wkQ+WvyAn8 HaXxS+X9cKUsWdwMeUZlY9ZfjV+pP+Mn91f9DQehzoUqRg6CEswsRQ7p6JXVnDYJPigY ypYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714036055; x=1714640855; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+4wTUU05Xd7j3sy440urBnEwP2fHUD5P7kgF0xvHMjc=; b=fRIuY9rXZmuLyHd7yn+Yv4wG0yItNnruyFz2vx2kKNDJUxTGNHkBG1nbTXEIofGtn6 dFQC4l5qNo5PbFhnrKhPH8OGjl82DCnL6RsLF96Syh0SRTZ8+sgJiVQs9CtrBdsf5bAv DCwlB/U1lgAGxAvyytT9otfh5iSWZqP85AlbXiuc/vvA+J5lbuEOoLDY8Au+i/63YAaR DqBGC4z+XaV2btGuJ3tX7okKwKuEUmnwcmZFDhbbabyVXSl06IEqYyT/T9qxYykFuJJ5 mP6ka0hxlRm2mM7+6Yb+VD4XLpcU6IBDfQ8gsgPaBr3vGY4LFXwtLJA8owf4XtKEAnnj NcZg== X-Forwarded-Encrypted: i=1; AJvYcCX/I0fXzs9tu6zI+OKrymhVUFbEQ1xmAtXuXHYpLi1Gs09+ph5M4xRCxZsAJREM8ciXTHG81qDVgk6HCBrdT+R3C0ZTubgrB/8smbypSMWeKkd6UMU= X-Gm-Message-State: AOJu0Ywlyv+a6j7L3VBtqxomBqUA4HavBblyG05QQMkqpE0WjvA2vDs9 k4ZuF2luwcAgWoVdjv0nHDBmYjgbr0NyD/5FLsT4vC7qL8Gs+2Zy X-Google-Smtp-Source: AGHT+IH00G50r60em0IVFLInu1mkzKCgJhWo7ypEjI8FeXomqiULAZ2cCuQIn+gE3UsYxotvJkPddw== X-Received: by 2002:a17:90a:7306:b0:2a2:9e5d:9bf9 with SMTP id m6-20020a17090a730600b002a29e5d9bf9mr3363222pjk.8.1714036055337; Thu, 25 Apr 2024 02:07:35 -0700 (PDT) Received: from peter-bmc.dhcpserver.bu9bmc.local (2001-b400-e339-24b8-1743-5d70-cc45-1c02.emome-ip6.hinet.net. [2001:b400:e339:24b8:1743:5d70:cc45:1c02]) by smtp.gmail.com with ESMTPSA id g21-20020a17090a7d1500b002a574ab7f5esm12489938pjl.53.2024.04.25.02.07.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Apr 2024 02:07:34 -0700 (PDT) From: Peter Yin To: patrick@stwcx.xyz, Wim Van Sebroeck , Guenter Roeck , Joel Stanley , Andrew Jeffery , linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH v7 1/1] drivers: watchdog: revise watchdog bootstatus Date: Thu, 25 Apr 2024 17:07:26 +0800 Message-Id: <20240425090727.3787160-2-peteryin.openbmc@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240425090727.3787160-1-peteryin.openbmc@gmail.com> References: <20240425090727.3787160-1-peteryin.openbmc@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240425_020736_916319_ED501802 X-CRM114-Status: GOOD ( 21.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Regarding the AST2600 specification, the WDTn Timeout Status Register (WDT10) has bit 1 reserved. Bit 1 of the status register indicates on ast2500 if the boot was from the second boot source. It does not indicate that the most recent reset was triggered by the watchdog. The code should just be changed to set WDIOF_CARDRESET if bit 0 of the status register is set. However, this bit can be clear when watchdog register 0x0c bit1(Reset System after timeout) is enabled. Thereforce include SCU register to veriy WDIOF_EXTERN1 and WDIOF_CARDRESET in ast2600 SCU74 or ast2400/ast2500 SCU3C. Signed-off-by: Peter Yin --- drivers/watchdog/aspeed_wdt.c | 109 ++++++++++++++++++++++++++++++++-- 1 file changed, 103 insertions(+), 6 deletions(-) diff --git a/drivers/watchdog/aspeed_wdt.c b/drivers/watchdog/aspeed_wdt.c index b4773a6aaf8c..4c58593658bc 100644 --- a/drivers/watchdog/aspeed_wdt.c +++ b/drivers/watchdog/aspeed_wdt.c @@ -11,10 +11,12 @@ #include #include #include +#include #include #include #include #include +#include #include static bool nowayout = WATCHDOG_NOWAYOUT; @@ -82,6 +84,16 @@ MODULE_DEVICE_TABLE(of, aspeed_wdt_of_table); #define WDT_RESET_MASK1 0x1c #define WDT_RESET_MASK2 0x20 +//AST SCU Register +#define AST2400_AST2500_SYSTEM_RESET_EVENT 0x3C +#define AST2400_WATCHDOG_RESET_FLAG BIT(1) +#define AST2400_RESET_FLAG_CLEAR GENMASK(2, 0) +#define AST2500_WATCHDOG_RESET_FLAG GENMASK(4, 2) +#define AST2600_SYSTEM_RESET_EVENT 0x74 +#define POWERON_RESET_FLAG BIT(0) +#define EXTERN_RESET_FLAG BIT(1) +#define AST2600_WATCHDOG_RESET_FLAG GENMASK(31, 16) + /* * WDT_RESET_WIDTH controls the characteristics of the external pulse (if * enabled), specifically: @@ -310,6 +322,7 @@ static int aspeed_wdt_probe(struct platform_device *pdev) const struct of_device_id *ofdid; struct aspeed_wdt *wdt; struct device_node *np; + struct regmap *scu_base; const char *reset_type; u32 duration; u32 status; @@ -458,15 +471,99 @@ static int aspeed_wdt_probe(struct platform_device *pdev) writel(duration - 1, wdt->base + WDT_RESET_WIDTH); } - status = readl(wdt->base + WDT_TIMEOUT_STATUS); - if (status & WDT_TIMEOUT_STATUS_BOOT_SECONDARY) { - wdt->wdd.bootstatus = WDIOF_CARDRESET; + /* + * Power on reset is set when triggered by AC or SRSRST. + * Thereforce, we clear flag to ensure + * next boot cause is a real watchdog case. + * We use the external reset flag to determine + * if it is an external reset or card reset + */ + if (of_device_is_compatible(np, "aspeed,ast2600-wdt")) { + scu_base = syscon_regmap_lookup_by_compatible( + "aspeed,ast2600-scu"); + if (IS_ERR(scu_base)) + return PTR_ERR(scu_base); + + ret = regmap_read(scu_base, + AST2600_SYSTEM_RESET_EVENT, + &status); + if (ret) + return ret; + + if ((status & POWERON_RESET_FLAG) == 0 && + status & AST2600_WATCHDOG_RESET_FLAG) { + if(status & EXTERN_RESET_FLAG) + wdt->wdd.bootstatus = WDIOF_EXTERN1; + else + wdt->wdd.bootstatus = WDIOF_CARDRESET; + } + status = AST2600_WATCHDOG_RESET_FLAG | + POWERON_RESET_FLAG | + EXTERN_RESET_FLAG; + + ret = regmap_write(scu_base, + AST2600_SYSTEM_RESET_EVENT, + status); + } else if (of_device_is_compatible(np, "aspeed,ast2500-wdt")) { + scu_base = syscon_regmap_lookup_by_compatible( + "aspeed,ast2500-scu"); + if (IS_ERR(scu_base)) + return PTR_ERR(scu_base); + + ret = regmap_read(scu_base, + AST2400_AST2500_SYSTEM_RESET_EVENT, + &status); + if (ret) + return ret; + + if ((status & POWERON_RESET_FLAG) == 0 && + status & AST2500_WATCHDOG_RESET_FLAG) { + if(status & EXTERN_RESET_FLAG) + wdt->wdd.bootstatus = WDIOF_EXTERN1; + else + wdt->wdd.bootstatus = WDIOF_CARDRESET; + } + + status = AST2500_WATCHDOG_RESET_FLAG | + POWERON_RESET_FLAG | + EXTERN_RESET_FLAG; + + ret = regmap_write(scu_base, + AST2400_AST2500_SYSTEM_RESET_EVENT, + status); - if (of_device_is_compatible(np, "aspeed,ast2400-wdt") || - of_device_is_compatible(np, "aspeed,ast2500-wdt")) - wdt->wdd.groups = bswitch_groups; + wdt->wdd.groups = bswitch_groups; + } else { + scu_base = syscon_regmap_lookup_by_compatible( + "aspeed,ast2400-scu"); + if (IS_ERR(scu_base)) + return PTR_ERR(scu_base); + + ret = regmap_read(scu_base, + AST2400_AST2500_SYSTEM_RESET_EVENT, + &status); + if (ret) + return ret; + /* + * Ast2400 external reset can clear watdog dog rest flag, so + * only support WDIOF_CARDRESET + */ + if ((status & POWERON_RESET_FLAG) == 0 && + status & AST2400_WATCHDOG_RESET_FLAG) + wdt->wdd.bootstatus = WDIOF_CARDRESET; + + status = AST2400_RESET_FLAG_CLEAR; + + ret = regmap_write(scu_base, + AST2400_AST2500_SYSTEM_RESET_EVENT, + status); + + wdt->wdd.groups = bswitch_groups; } + if (ret) + return ret; + dev_set_drvdata(dev, wdt); return devm_watchdog_register_device(dev, &wdt->wdd);