From patchwork Fri Aug 28 07:49:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Freddy Hsin X-Patchwork-Id: 258999 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-11.1 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, MIME_BASE64_TEXT, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, UNPARSEABLE_RELAY,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC62CC433E6 for ; Fri, 28 Aug 2020 07:50:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 81CAD20C56 for ; Fri, 28 Aug 2020 07:50:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="Pv+5ikzl" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728535AbgH1HuD (ORCPT ); Fri, 28 Aug 2020 03:50:03 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:57706 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726571AbgH1HuC (ORCPT ); Fri, 28 Aug 2020 03:50:02 -0400 X-UUID: 4121e747aece49eb94cf3bf6556b20e1-20200828 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=3WgwFhaLMdkUWyelN9/5DI31mttcEviLuRyGT0q3ZCc=; b=Pv+5ikzlk4lG+nEzdDOh6JhkrfGTWyyiM3BnFLMhYwQRJo7G3AYronxNHK8PDntyxMDurWZu21a6RlZn8qOa67bdVkLWdPkjwizTqXAxZLU04YWQE5o1POMzb+0tzHQV45xIJNYTMynxqCFJms5L/v6MkoPjAJ7dNxHXVkNESFo=; X-UUID: 4121e747aece49eb94cf3bf6556b20e1-20200828 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 1015399420; Fri, 28 Aug 2020 15:49:59 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 28 Aug 2020 15:49:56 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Fri, 28 Aug 2020 15:49:59 +0800 From: Freddy Hsin To: Wim Van Sebroeck , Guenter Roeck , Matthias Brugger , , , , CC: , , , , Freddy Hsin Subject: [PATCH v1 1/1] driver: watchdog: Add mtk_wdt_init for mediatek watchdog hw init Date: Fri, 28 Aug 2020 15:49:28 +0800 Message-ID: <1598600968-28498-2-git-send-email-freddy.hsin@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1598600968-28498-1-git-send-email-freddy.hsin@mediatek.com> References: <1598600968-28498-1-git-send-email-freddy.hsin@mediatek.com> MIME-Version: 1.0 X-MTK: N Sender: linux-watchdog-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-watchdog@vger.kernel.org 1. add a hw initialization function 2. enable/disable the watchdog depends on the original hw setting 3. set WDOD_HW_RUNNING in start function in order to start kicker after driver probe and clear the bit in stop function Change-Id: I25aa797f3b88288f26984455e499e599e27f09fa Signed-off-by: Freddy Hsin --- drivers/watchdog/mtk_wdt.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) -- 1.7.9.5 diff --git a/drivers/watchdog/mtk_wdt.c b/drivers/watchdog/mtk_wdt.c index d6a6393..59b5061 100644 --- a/drivers/watchdog/mtk_wdt.c +++ b/drivers/watchdog/mtk_wdt.c @@ -57,6 +57,9 @@ static bool nowayout = WATCHDOG_NOWAYOUT; static unsigned int timeout; +static int mtk_wdt_start(struct watchdog_device *wdt_dev); +static int mtk_wdt_stop(struct watchdog_device *wdt_dev); + struct mtk_wdt_dev { struct watchdog_device wdt_dev; void __iomem *wdt_base; @@ -148,6 +151,19 @@ static int toprgu_register_reset_controller(struct platform_device *pdev, return ret; } +static int mtk_wdt_init(struct watchdog_device *wdt_dev) +{ + struct mtk_wdt_dev *mtk_wdt = watchdog_get_drvdata(wdt_dev); + void __iomem *wdt_base; + + wdt_base = mtk_wdt->wdt_base; + + if (readl(wdt_base + WDT_MODE) & WDT_MODE_EN) + mtk_wdt_start(wdt_dev); + else + mtk_wdt_stop(wdt_dev); +} + static int mtk_wdt_restart(struct watchdog_device *wdt_dev, unsigned long action, void *data) { @@ -206,6 +222,8 @@ static int mtk_wdt_stop(struct watchdog_device *wdt_dev) reg |= WDT_MODE_KEY; iowrite32(reg, wdt_base + WDT_MODE); + clear_bit(WDOG_HW_RUNNING, &wdt_dev->status); + return 0; } @@ -225,6 +243,8 @@ static int mtk_wdt_start(struct watchdog_device *wdt_dev) reg |= (WDT_MODE_EN | WDT_MODE_KEY); iowrite32(reg, wdt_base + WDT_MODE); + set_bit(WDOG_HW_RUNNING, &wdt_dev->status); + return 0; } @@ -274,7 +294,7 @@ static int mtk_wdt_probe(struct platform_device *pdev) watchdog_set_drvdata(&mtk_wdt->wdt_dev, mtk_wdt); - mtk_wdt_stop(&mtk_wdt->wdt_dev); + mtk_wdt_init(&mtk_wdt->wdt_dev); watchdog_stop_on_reboot(&mtk_wdt->wdt_dev); err = devm_watchdog_register_device(dev, &mtk_wdt->wdt_dev);