From patchwork Tue Apr 30 14:31:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: PeterYin X-Patchwork-Id: 13649436 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 E703EC25B4F for ; Tue, 30 Apr 2024 14:33:56 +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=mp5iESzMm4CRBZJGcJwLoIA3Et6FfuRomQFUYNOsBEs=; b=YoCIlREZvdzlCQ Kcmi4826M1OCziJJDRZKqmHtrvTHlMM1MzPCrZ3UygcSiXGD3VPNgh8Rm2bqV0XDoSNOo+7+0CHIy cxrlnmjAAQjXH9qUqXa3MSBeEE6L4bAgy9HdNcloI0YqVj6G4YN7tt2V7ZMxxtGBFHm4/AfhiZQcy zzOt1eYSslJpOGQgZ4rQgaxm7BX4SEXlr4VZ7WTxO9a95X1rDZSri3/+rqiBsTxDA1nbfoQZpPrhS YcuYf1Vaw+CbTl6cifz5daepBR6bVNjIyej8FzpC8bSVHDqrVe5N3pjn5ZjYEN9vce/WBGosbbRs/ hDRQhkjJyrMWVdJeMYFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1oYE-00000006r5I-2Mla; Tue, 30 Apr 2024 14:33:46 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1s1oXx-00000006qvB-1x45 for linux-arm-kernel@lists.infradead.org; Tue, 30 Apr 2024 14:33:30 +0000 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-1e65a1370b7so53627505ad.3 for ; Tue, 30 Apr 2024 07:33:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714487601; x=1715092401; 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=n9+uw12LzVsx3wU8adlXBHs43wHbzfmBsLnbaFarO2I=; b=VSXcBUDc5aQi3nZoDdQCT0pLl9TCBWW1He6Pdhoyt0yqStrt7+w8bDL3BFp4Qj+wTZ 2oiKwvh+oaILnfY76mJCHxymoMTUhp310RxrosrkXx7UZOrt9mz3hddoerdk7j2yLGex SdJQ7xZ/0/Hu7g2no2BWCyqvmZ92OiyfCKzdflCBXznl9d5xo6TJf3gsdLA7sKU0/8s4 knIxvjaYs9iH5p3PPTC3LJOkeZlZTBSIcRQ+ZPq76Jm6g/nWMVVuj8l2xQjOQ1vUtvyX FJWYxpzENUAd/sKLbQ/L+QBmYo4w3L5GWHfIvidY028EOS+51h5e2tpn/AQDANhazAM/ 1/qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714487601; x=1715092401; 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=n9+uw12LzVsx3wU8adlXBHs43wHbzfmBsLnbaFarO2I=; b=cXY0QMEHx/e/tvH8FTEjnTolNuu37eolb8b/i4gWYfTw1zR0e60aPw+5z8H1UtCV+D EDQ6+vPGJUYoAczzu5Zou6S8rtWM1DsJGeXcNIg4cXonY4T6GL/s+NaGJ0hm5Ey4QKaD DJA6zA2br1Rxf9EP5OtrmcutZ6mGua1tmc9FQvso6rW7bOBstShSRQayGKON82Icp7EL yw59SDMv8OfyGbg1LVCiodEfSmac7t9cenWQObxKZbZfD3uNucDo0yPSPrPbP1oMxm18 ecmTqHs3lQV4YsFHHMi5Bunbe3R2cgTtGY8tneYc8WwiRTi8IrsfgwdOO6OJNnVzoKmt xtog== X-Forwarded-Encrypted: i=1; AJvYcCW5fYQdzOab2LNKTmdhZQPUMe79xJ1OS+JvKvwBA8GJoiYsUsQRJpahWhLQHO/F/TGR3MYJpJFnEzsAAm2yDH74SDNtBh4D5z5hNBAHchNUEGUejoQ= X-Gm-Message-State: AOJu0YymReatdh83n45UG4w1G0PwDs89xTlXyhFTL4mhf+5rbpVwKEiG vajfZKR3h4k6A8yWA7nUqVJ+K5xicEdbXpgNmldGzTe9KJc3GZId X-Google-Smtp-Source: AGHT+IH4UdZbzfvSJo3QJfZt+JphuB4AEFpA9cZMcuqalJRWHwyT3Ed+65xfdEtezZjfDmHJFi8NrA== X-Received: by 2002:a17:902:e806:b0:1e2:81c1:b35e with SMTP id u6-20020a170902e80600b001e281c1b35emr17906114plg.54.1714487600758; Tue, 30 Apr 2024 07:33:20 -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 m1-20020a170902db0100b001e47972a2casm1682431plx.96.2024.04.30.07.33.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Apr 2024 07:33:20 -0700 (PDT) From: Peter Yin To: patrick@stwcx.xyz, Wim Van Sebroeck , Guenter Roeck , Joel Stanley , Andrew Jeffery , Eddie James , linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: [PATCH v9 1/1] watchdog: aspeed: Revise handling of bootstatus Date: Tue, 30 Apr 2024 22:31:14 +0800 Message-Id: <20240430143114.1323686-2-peteryin.openbmc@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240430143114.1323686-1-peteryin.openbmc@gmail.com> References: <20240430143114.1323686-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-20240430_073329_533914_F2CEFED3 X-CRM114-Status: GOOD ( 22.44 ) 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. Fixes: 49d4d277ca54 ("aspeed: watchdog: Set bootstatus during probe") Signed-off-by: Peter Yin --- drivers/watchdog/aspeed_wdt.c | 90 +++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 8 deletions(-) diff --git a/drivers/watchdog/aspeed_wdt.c b/drivers/watchdog/aspeed_wdt.c index b4773a6aaf8c..556493763793 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,38 @@ module_param(nowayout, bool, 0); MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); +/* AST SCU Register for System Reset Event Log Register Set + * ast2600 is scu074 ast2400/2500 is scu03c + */ +#define AST_SCU_SYS_RESET_POWERON_MASK BIT(0) +#define AST_SCU_SYS_RESET_EXTERN_FLAG BIT(1) + +#define AST2400_SYSTEM_RESET_STATUS 0x3C +#define AST2400_WATCHDOG_RESET_MASK BIT(1) +#define AST2400_RESET_FLAG_CLEAR GENMASK(2, 0) + +#define AST2500_WATCHDOG_RESET_MASK GENMASK(4, 2) +#define AST2500_RESET_FLAG_CLEAR (AST2500_WATCHDOG_RESET_MASK | \ + AST_SCU_SYS_RESET_POWERON_MASK | \ + AST_SCU_SYS_RESET_EXTERN_FLAG) + +#define AST2600_SYSTEM_RESET_STATUS 0x74 +#define AST2600_WATCHDOG_RESET_MASK GENMASK(31, 16) +#define AST2600_RESET_FLAG_CLEAR (AST2600_WATCHDOG_RESET_MASK | \ + AST_SCU_SYS_RESET_POWERON_MASK | \ + AST_SCU_SYS_RESET_EXTERN_FLAG) + struct aspeed_wdt_config { u32 ext_pulse_width_mask; u32 irq_shift; u32 irq_mask; + struct { + const char *compatible; + u32 reset_status_reg; + u32 watchdog_reset_mask; + u32 extern_reset_mask; + u32 reset_flag_clear; + } scu; }; struct aspeed_wdt { @@ -39,18 +69,39 @@ 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 = AST2400_SYSTEM_RESET_STATUS, + .watchdog_reset_mask = AST2400_WATCHDOG_RESET_MASK, + .extern_reset_mask = 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), + .scu = { + .compatible = "aspeed,ast2500-scu", + .reset_status_reg = AST2400_SYSTEM_RESET_STATUS, + .watchdog_reset_mask = AST2500_WATCHDOG_RESET_MASK, + .extern_reset_mask = AST_SCU_SYS_RESET_EXTERN_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), + .scu = { + .compatible = "aspeed,ast2600-scu", + .reset_status_reg = AST2600_SYSTEM_RESET_STATUS, + .watchdog_reset_mask = AST2600_WATCHDOG_RESET_MASK, + .extern_reset_mask = AST_SCU_SYS_RESET_EXTERN_FLAG, + .reset_flag_clear = AST2600_RESET_FLAG_CLEAR, + } }; static const struct of_device_id aspeed_wdt_of_table[] = { @@ -310,6 +361,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; const char *reset_type; u32 duration; u32 status; @@ -458,14 +510,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 = syscon_regmap_lookup_by_compatible(wdt->cfg->scu.compatible); + if (IS_ERR(scu)) + return PTR_ERR(scu); + + ret = regmap_read(scu, wdt->cfg->scu.reset_status_reg, &status); + if (ret) + return ret; + + if (!(status & AST_SCU_SYS_RESET_POWERON_MASK) && + status & wdt->cfg->scu.watchdog_reset_mask) + wdt->wdd.bootstatus = (status & wdt->cfg->scu.extern_reset_mask) + ? WDIOF_EXTERN1 : WDIOF_CARDRESET; + + status = wdt->cfg->scu.reset_flag_clear; + ret = regmap_write(scu, wdt->cfg->scu.reset_status_reg, 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);