Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp71275ybg; Mon, 27 Jul 2020 23:47:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwDYiZftIpxjInz/S89uHVn/6/Z9O0V+MPq8MjbE1aP1hNGYSOnUFTVdlUKUdpSxy0z+DZ8 X-Received: by 2002:a17:906:fc10:: with SMTP id ov16mr13081588ejb.171.1595918874946; Mon, 27 Jul 2020 23:47:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595918874; cv=none; d=google.com; s=arc-20160816; b=LMlNPtTSN2krpPSp0tcuXoep/iV37mZJUxVyNwez/keKBpWqZ9q73nGUMVGDQd4U+S N527EEKqvzth4t8kcg0OPQmWmA6vABgx1b4UAIyG2H3C6jE9djdttwans3X6gxapRfb4 Mb8ZKeMQbl1tuoBwbVBH7cSsSgVQoAi0U5lemfKzJqWE0VAp2831nJtdqsKC3hXCDvC1 gSfvPtQvou8mQ6OPVQT6Gj9KwRSsQPAAIVVy2k90D2BMcH+lYmHfRXXX0FSfNyZoT454 5Is0QQgj9YbOz1Mo5cKm9z0NnfRpD5r1PdGbfm5dyldgw4reIY7CA7/thweTtgjO+TdS 2adQ== 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=yAFQIVTn1iGxh7ewqwXogBKzyMF8gW51VgzEmgk7B+M=; b=C0nKM7NT+pBMJZ4KcwhJXWvlxTg6tI0KrSDKxv2Ydoi6PzFnl/WI1MhbDAnXbmJlMV LfeA8foAEuRzo3pZidphDnUYf1aQIDUYqEAOamg+Q6PeTMNyMvVQR/3GWFE1F7vNcvdK yq2CfUiAcYJfZ29JYmyPjuCxKo+0Eru5+4wqgChaqaVr6I44U03pb/K+SC4uwAfwTd9k xrncJ7WUqbQGq4WFUNIz9f3bJXRBJx6wdl3LvcDH4sjRBxkBK2ZW3Nj0ke3m25RQTuvM +sGDrpSqCS69qUU2SbksTIi+Y2J208R7aopgAXceBktHxCCk7CZ+fbWLx2Fv69uJoaYy ci2w== 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 d4si6883804edv.535.2020.07.27.23.47.33; Mon, 27 Jul 2020 23:47:54 -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 S1727783AbgG1GrG (ORCPT + 99 others); Tue, 28 Jul 2020 02:47:06 -0400 Received: from inva020.nxp.com ([92.121.34.13]:43154 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726871AbgG1GrF (ORCPT ); Tue, 28 Jul 2020 02:47:05 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 4C4411A0D52; Tue, 28 Jul 2020 08:47:03 +0200 (CEST) Received: from invc005.ap-rdc01.nxp.com (invc005.ap-rdc01.nxp.com [165.114.16.14]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id 33B4F1A0045; Tue, 28 Jul 2020 08:46:59 +0200 (CEST) Received: from localhost.localdomain (shlinux2.ap.freescale.net [10.192.224.44]) by invc005.ap-rdc01.nxp.com (Postfix) with ESMTP id C21AB402F3; Tue, 28 Jul 2020 08:46:53 +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 1/2] watchdog: imx7ulp: Strictly follow the sequence for wdog operations Date: Tue, 28 Jul 2020 14:42:46 +0800 Message-Id: <1595918567-2017-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 --- 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..b414ecf 100644 --- a/drivers/watchdog/imx7ulp_wdt.c +++ b/drivers/watchdog/imx7ulp_wdt.c @@ -4,6 +4,7 @@ */ #include +#include #include #include #include @@ -48,17 +49,32 @@ struct imx7ulp_wdt_device { struct clk *clk; }; +static inline void imx7ulp_wdt_wait(void __iomem *base, u32 mask) +{ + int retries = 100; + + do { + if (readl_relaxed(base + WDOG_CS) & mask) + return; + usleep_range(200, 1000); + } while (retries--); +} + 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