Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp768229ybg; Tue, 28 Jul 2020 19:25:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyB/jgFYvztpJ1hncbU1s5aO7Xndqs4uTe+nUnNrV+Ikgtl+D0wLirKzHEYWd0wlWKAEUWA X-Received: by 2002:a17:906:9592:: with SMTP id r18mr4246551ejx.464.1595989517483; Tue, 28 Jul 2020 19:25:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595989517; cv=none; d=google.com; s=arc-20160816; b=Sm5XjUohZovFYIgY/Y30GL8a80dRyYGiDz8b0Of2sn6rjt8cErIA0Yw1mOy3vIqPT7 6oNGhAbDfW+hRkByb5twOs1gw1rRmJdb0skiMq7Ft8SXlt/qEJxElakE9CkUmHz6GA7o crFxlw3L9NOOgJHxtqCpoV3LoHxh0N7ThpVG6LncP6nP8zG1g8T7mKOZxJ+Wq8Ia4yZp KCbqaDIgrKnqGnHd6Lv2n3y6gBWX3bOUbx3ZOE0gLESRuYJ3Kr+Krt+fpTxLxNc5BOiF 25Mv1DFmDza+Hd0w6zXCF5u71yTsMGrETbpvHUMn7krOM5Dd2NpnM6N+3gnUE4fewBr7 VIwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=YPxOmzvNWWT/dEIoiaUDQMNfPeci2UcIHIkwFYW8vIk=; b=dbMgDFJcMvhyWIvMTEH5RV6HHD7BuXh8cW7ibvPbkbzKAPr6C4zS+F313y4bSl+qVF JAlyzj8LGrDN9HYjsvrsjiyGYb5PqU/51uu6rxYGF6k8eQfrTR3HFDNySmUHKJHn8e2D 3v7lUCKvkcfdocBr5CmBwqN5rsYJtOsL8LbUEhP7RDXBWefV+ZKEcHRlfqKUlf7kI3gs N7kFMD8yqG2q3m47y85acEPY4y3KUJum5B5Qyo9jygj6tLEUjB0YNrs/doWGCuLbdIeT G2ixHpc8BW3ahzttXQAxKuiWn5pFrflijGi3PIxnDJpyKYtHIXvxSuKPhHd+SvB9Qacv y0fw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 7si208073ejq.309.2020.07.28.19.24.54; Tue, 28 Jul 2020 19:25:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731106AbgG2CYs (ORCPT + 99 others); Tue, 28 Jul 2020 22:24:48 -0400 Received: from inva021.nxp.com ([92.121.34.21]:47326 "EHLO inva021.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730901AbgG2CYr (ORCPT ); Tue, 28 Jul 2020 22:24:47 -0400 Received: from inva021.nxp.com (localhost [127.0.0.1]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id DAA71200100; Wed, 29 Jul 2020 04:24:44 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva021.eu-rdc02.nxp.com (Postfix) with ESMTP id 90D1E200D82; Wed, 29 Jul 2020 04:24:40 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id 3B70B402DF; Wed, 29 Jul 2020 04:24:35 +0200 (CEST) From: Anson Huang To: wim@linux-watchdog.org, linux@roeck-us.net, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: Linux-imx@nxp.com Subject: [PATCH V2 1/2] watchdog: imx7ulp: Strictly follow the sequence for wdog operations Date: Wed, 29 Jul 2020 10:20:26 +0800 Message-Id: <1595989227-24700-1-git-send-email-Anson.Huang@nxp.com> X-Mailer: git-send-email 2.7.4 X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org According to reference manual, the i.MX7ULP WDOG's operations should follow below sequence: 1. disable global interrupts; 2. unlock the wdog and wait unlock bit set; 3. reconfigure the wdog and wait for reconfiguration bit set; 4. enabel global interrupts. Strictly follow the recommended sequence can make it more robust. Signed-off-by: Anson Huang --- Changes since V1: - use readl_poll_timeout_atomic() instead of usleep_ranges() since IRQ is disabled. --- drivers/watchdog/imx7ulp_wdt.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/watchdog/imx7ulp_wdt.c b/drivers/watchdog/imx7ulp_wdt.c index 7993c8c..7d2b12e 100644 --- a/drivers/watchdog/imx7ulp_wdt.c +++ b/drivers/watchdog/imx7ulp_wdt.c @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -36,6 +37,7 @@ #define DEFAULT_TIMEOUT 60 #define MAX_TIMEOUT 128 #define WDOG_CLOCK_RATE 1000 +#define WDOG_WAIT_TIMEOUT 10000 static bool nowayout = WATCHDOG_NOWAYOUT; module_param(nowayout, bool, 0000); @@ -48,17 +50,31 @@ struct imx7ulp_wdt_device { struct clk *clk; }; +static inline void imx7ulp_wdt_wait(void __iomem *base, u32 mask) +{ + u32 val = readl(base + WDOG_CS); + + if (!(val & mask)) + WARN_ON(readl_poll_timeout_atomic(base + WDOG_CS, val, + val & mask, 0, + WDOG_WAIT_TIMEOUT)); +} + static void imx7ulp_wdt_enable(struct watchdog_device *wdog, bool enable) { struct imx7ulp_wdt_device *wdt = watchdog_get_drvdata(wdog); u32 val = readl(wdt->base + WDOG_CS); + local_irq_disable(); writel(UNLOCK, wdt->base + WDOG_CNT); + imx7ulp_wdt_wait(wdt->base, WDOG_CS_ULK); if (enable) writel(val | WDOG_CS_EN, wdt->base + WDOG_CS); else writel(val & ~WDOG_CS_EN, wdt->base + WDOG_CS); + imx7ulp_wdt_wait(wdt->base, WDOG_CS_RCS); + local_irq_enable(); } static bool imx7ulp_wdt_is_enabled(void __iomem *base) @@ -72,7 +88,12 @@ static int imx7ulp_wdt_ping(struct watchdog_device *wdog) { struct imx7ulp_wdt_device *wdt = watchdog_get_drvdata(wdog); + local_irq_disable(); + writel(UNLOCK, wdt->base + WDOG_CNT); + imx7ulp_wdt_wait(wdt->base, WDOG_CS_ULK); writel(REFRESH, wdt->base + WDOG_CNT); + imx7ulp_wdt_wait(wdt->base, WDOG_CS_RCS); + local_irq_enable(); return 0; } @@ -98,8 +119,12 @@ static int imx7ulp_wdt_set_timeout(struct watchdog_device *wdog, struct imx7ulp_wdt_device *wdt = watchdog_get_drvdata(wdog); u32 val = WDOG_CLOCK_RATE * timeout; + local_irq_disable(); writel(UNLOCK, wdt->base + WDOG_CNT); + imx7ulp_wdt_wait(wdt->base, WDOG_CS_ULK); writel(val, wdt->base + WDOG_TOVAL); + imx7ulp_wdt_wait(wdt->base, WDOG_CS_RCS); + local_irq_enable(); wdog->timeout = timeout; @@ -140,15 +165,19 @@ static void imx7ulp_wdt_init(void __iomem *base, unsigned int timeout) { u32 val; + local_irq_disable(); /* unlock the wdog for reconfiguration */ writel_relaxed(UNLOCK_SEQ0, base + WDOG_CNT); writel_relaxed(UNLOCK_SEQ1, base + WDOG_CNT); + imx7ulp_wdt_wait(base, WDOG_CS_ULK); /* set an initial timeout value in TOVAL */ writel(timeout, base + WDOG_TOVAL); /* enable 32bit command sequence and reconfigure */ val = WDOG_CS_CMD32EN | WDOG_CS_CLK | WDOG_CS_UPDATE; writel(val, base + WDOG_CS); + imx7ulp_wdt_wait(base, WDOG_CS_RCS); + local_irq_enable(); } static void imx7ulp_wdt_action(void *data) -- 2.7.4