From patchwork Sun Apr 28 14:29:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: PeterYin X-Patchwork-Id: 13646061 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 4A569C10F1A for ; Sun, 28 Apr 2024 14:32:09 +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=5YdWL4UgjOqIAq8ELkiOsguPZBYNrBiMPFxZ5Z5V14A=; b=h/viYPdd+58CHd zLDGPNMEEbApKdSk6Pz11CFK4raQInHEsuEXe+dMHQIzPID+1/nqvvRVnbTxq7KTtvNuQuNe9pBHX QkmHyQw/yWPsqE2j37LRAEJ6aJuY2Wk8P6c2uGr8Pu2kwmIjd7rcIw2FMxVJ1LsDR8T10duoBqO15 adXaIQOq82w/rfyYyLGfhAVfc4zGE5EwU7CyiAVpfEpc4KvTFlDYxVcT19ZqwR3l37Sg8VgbsTCFV Cmp8yZ2pO0AVQpM0pJj9q6tJCycAN5apscNSBMq85kZr/KKh/SQucDqpMPMfBYEJFRVxKIFGd09ad DMEsefTZoJJXp4lxkayg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s15ZI-000000007ht-3Nln; Sun, 28 Apr 2024 14:31:52 +0000 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s15ZE-000000007fm-3cOt for linux-arm-kernel@lists.infradead.org; Sun, 28 Apr 2024 14:31:50 +0000 Received: by mail-pl1-x631.google.com with SMTP id d9443c01a7336-1e2bbc2048eso31982305ad.3 for ; Sun, 28 Apr 2024 07:31:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714314703; x=1714919503; 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=yXqf8F3SecFIk6T1Akuz7f4j9GlOgRtt8O4mjizvpu4=; b=e3nwrL/T0MVlsFo56k/59XdgOVXKg1+6CkxxW/Jh4RyloL+ET386Yv+8yMtLXWu9iu MjfDYz3whKmWgafW3m+yUSjihTgrLx2pxrEEM2JstzaQmdZQ47KwLwXLeHMVZ5SW15JD yR2wv56LbJcF8z4se6H/9vGGUBkrjOcLZtY3Up5kNs/2xguLUbiDQycSlUb4qoOKy1CT w7BZsDB/C7IXS4BlZtQSCHUlzNRzP4gOmYYGoRJnaJyd8E/KJyH324aqLmSzWQRjT1/s 80Sl6wA5CB7ecH0BHJ4rIsoUJblfXQyhwHJ8NJAIbDiFbL3yegEP4mdp6zteV1aA8U/V 5E5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714314703; x=1714919503; 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=yXqf8F3SecFIk6T1Akuz7f4j9GlOgRtt8O4mjizvpu4=; b=N95JhW/al3+e2esAaP0aNFZJbubKBRwyb53iUd+pgEI0Mm5GD1oE7+i+Ze7T0aX16E b7WSSWJe+VPcrJAP6GcTo/crNZSCn5sCXqh+3oXSHVzVF2Tw7Q51jbzOZTYIfpvbPSRa S+28bWJ4Ri0WFZnBcjxl4o6v+wY4KihPUL4xxecpjpJEOUGT2BgnUHu1bnGSSEzswdZ/ NSXwdT4vzMtMXr23fySwK8W1mUO3ZzvZmDAiH4+GacJ+gwYssjIZDIYyaAZp1x03Msxb vsT8XXDqv14agsqPT9AN7koWE7fqlrbLkq6NBaURASHdOvMMua3b0DA4/C4YDM6z7KJp /xGA== X-Forwarded-Encrypted: i=1; AJvYcCXnCbTxzkJV3Pau5Cp+kUHaBzucXD/EB+W57p6K9YkH5cO+W1AiZrF9DVNtqKPJyCI1Zo7tppBeNJr9L18C+m0NyMT7sGPwhJUlEd4+TG7nxRi30FU= X-Gm-Message-State: AOJu0Yy5+f+vNgOeP0qINFttYUkWwh4cIrNHaymLjdmmzmVxecJ0is3x g3c5zykQrW/ECikCzdzr+4Ei/EJcLb90MxugnMQX5WFjPHshiqIx X-Google-Smtp-Source: AGHT+IG6q6wHxQ91YJnCTGvVZFyYo0xYdTvqDFb5dXnQuTlsuMiga8xv5uzQdfDtcGTXR7Y0kjbYHg== X-Received: by 2002:a17:902:fc4d:b0:1eb:2988:549d with SMTP id me13-20020a170902fc4d00b001eb2988549dmr8241260plb.40.1714314703323; Sun, 28 Apr 2024 07:31:43 -0700 (PDT) Received: from peter-bmc.dhcpserver.bu9bmc.local (1-34-21-66.hinet-ip.hinet.net. [1.34.21.66]) by smtp.gmail.com with ESMTPSA id h6-20020a636c06000000b00612dc2ec375sm1034834pgc.16.2024.04.28.07.31.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Apr 2024 07:31:42 -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 v8 1/1] drivers: watchdog: revise watchdog bootstatus Date: Sun, 28 Apr 2024 22:29:36 +0800 Message-Id: <20240428142937.785925-2-peteryin.openbmc@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240428142937.785925-1-peteryin.openbmc@gmail.com> References: <20240428142937.785925-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-20240428_073148_933821_977D850F X-CRM114-Status: GOOD ( 21.71 ) 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 Signed-off-by: Peter Yin --- drivers/watchdog/aspeed_wdt.c | 78 +++++++++++++++++++++++++++++++---- 1 file changed, 70 insertions(+), 8 deletions(-) diff --git a/drivers/watchdog/aspeed_wdt.c b/drivers/watchdog/aspeed_wdt.c index b4773a6aaf8c..4393625c2e96 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; @@ -22,10 +24,32 @@ module_param(nowayout, bool, 0); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); +//AST SCU Register +#define POWERON_RESET_FLAG BIT(0) +#define EXTERN_RESET_FLAG BIT(1) + +#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 AST2500_RESET_FLAG_CLEAR (AST2500_WATCHDOG_RESET_FLAG | \ + POWERON_RESET_FLAG | EXTERN_RESET_FLAG) + +#define AST2600_SYSTEM_RESET_EVENT 0x74 +#define AST2600_WATCHDOG_RESET_FLAG GENMASK(31, 16) +#define AST2600_RESET_FLAG_CLEAR (AST2600_WATCHDOG_RESET_FLAG | \ + POWERON_RESET_FLAG | EXTERN_RESET_FLAG) + struct aspeed_wdt_config { u32 ext_pulse_width_mask; u32 irq_shift; u32 irq_mask; + const char *compatible; + u32 reset_event; + u32 watchdog_reset_flag; + u32 extern_reset_flag; + u32 reset_flag_clear; }; struct aspeed_wdt { @@ -39,18 +63,33 @@ static const struct aspeed_wdt_config ast2400_config = { .ext_pulse_width_mask = 0xff, .irq_shift = 0, .irq_mask = 0, + .compatible = "aspeed,ast2400-scu", + .reset_event = AST2400_AST2500_SYSTEM_RESET_EVENT, + .watchdog_reset_flag = AST2400_WATCHDOG_RESET_FLAG, + .extern_reset_flag = 0, + .reset_flag_clear = AST2400_RESET_FLAG_CLEAR, }; static const struct aspeed_wdt_config ast2500_config = { .ext_pulse_width_mask = 0xfffff, .irq_shift = 12, .irq_mask = GENMASK(31, 12), + .compatible = "aspeed,ast2500-scu", + .reset_event = AST2400_AST2500_SYSTEM_RESET_EVENT, + .watchdog_reset_flag = AST2500_WATCHDOG_RESET_FLAG, + .extern_reset_flag = EXTERN_RESET_FLAG, + .reset_flag_clear = AST2500_RESET_FLAG_CLEAR, }; static const struct aspeed_wdt_config ast2600_config = { .ext_pulse_width_mask = 0xfffff, .irq_shift = 0, .irq_mask = GENMASK(31, 10), + .compatible = "aspeed,ast2600-scu", + .reset_event = AST2600_SYSTEM_RESET_EVENT, + .watchdog_reset_flag = AST2600_WATCHDOG_RESET_FLAG, + .extern_reset_flag = EXTERN_RESET_FLAG, + .reset_flag_clear = AST2600_RESET_FLAG_CLEAR, }; static const struct of_device_id aspeed_wdt_of_table[] = { @@ -310,6 +349,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,14 +498,36 @@ 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; - - if (of_device_is_compatible(np, "aspeed,ast2400-wdt") || - of_device_is_compatible(np, "aspeed,ast2500-wdt")) - wdt->wdd.groups = bswitch_groups; - } + /* + * 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. + * However, The ast2400 watchdog flag is cleared by an external reset, + * so it only supports WDIOF_CARDRESET. + */ + scu_base = syscon_regmap_lookup_by_compatible(wdt->cfg->compatible); + if (IS_ERR(scu_base)) + return PTR_ERR(scu_base); + + ret = regmap_read(scu_base, wdt->cfg->reset_event, &status); + if (ret) + return ret; + + if (!(status & POWERON_RESET_FLAG) && + status & wdt->cfg->watchdog_reset_flag) + wdt->wdd.bootstatus = (status & wdt->cfg->extern_reset_flag) ? + WDIOF_EXTERN1 : WDIOF_CARDRESET; + + status = wdt->cfg->reset_flag_clear; + ret = regmap_write(scu_base, wdt->cfg->reset_event, status); + if (ret) + return ret; + + if (of_device_is_compatible(np, "aspeed,ast2400-wdt") || + of_device_is_compatible(np, "aspeed,ast2500-wdt")) + wdt->wdd.groups = bswitch_groups; dev_set_drvdata(dev, wdt);