From patchwork Tue Jan 30 20:22:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fabrizio Castro X-Patchwork-Id: 10192515 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 14F20601A0 for ; Tue, 30 Jan 2018 20:27:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0418227BA5 for ; Tue, 30 Jan 2018 20:27:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E9ED927C2D; Tue, 30 Jan 2018 20:27:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8AB1327BA5 for ; Tue, 30 Jan 2018 20:27:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=Fq2JVYYiHDWT29L6qiRy3bk5MqpkfMZ3oLS09kfrlIA=; b=U/3E4MotkA3F75i+ofDRRMz7tu PjQXnmQ7NeNJ4KmyS4KjhsXX7zTcCDTziguLq23n67ScjE88Y3JVWoXwACytrucTVzWA4RLtQ1HNl yQDXEYgCDMNFJhQZKFs4EklgAUtlgSEj4cpQmOvAK26pYY7OSBN2Dt9E2mfrLlcPpzwHb1VSjDlCb G0KGizdtMP33yG2cFeqVadYeJkfiqto91eOxgb+mMwxvdpNknhuqZeF8Zt9yyCmL4URtrPq+be/+i E2UWpzMMIGfS+aGbWf6RPXaPpRuqYuzlHGTQAGPBAzTI/VVAmjPtuDcwmFVun6UBImBXmRCYtyYr+ ijNdmeJg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1egcVH-0002b2-0d; Tue, 30 Jan 2018 20:27:39 +0000 Received: from relmlor2.renesas.com ([210.160.252.172] helo=relmlie1.idc.renesas.com) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1egcS4-0006RU-9X for linux-arm-kernel@lists.infradead.org; Tue, 30 Jan 2018 20:24:50 +0000 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie1.idc.renesas.com with ESMTP; 31 Jan 2018 05:24:09 +0900 Received: from relmlii1.idc.renesas.com (relmlii1.idc.renesas.com [10.200.68.65]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id 64FC25B7F5; Wed, 31 Jan 2018 05:24:09 +0900 (JST) X-IronPort-AV: E=Sophos;i="5.46,436,1511794800"; d="scan'208";a="269795830" Received: from unknown (HELO fabrizio-dev.ree.adwin.renesas.com) ([10.226.37.88]) by relmlii1.idc.renesas.com with ESMTP; 31 Jan 2018 05:24:03 +0900 From: Fabrizio Castro To: Philipp Zabel , Rob Herring , Mark Rutland , Wim Van Sebroeck , Russell King , Catalin Marinas , Will Deacon , Michael Turquette , Stephen Boyd , Simon Horman , Magnus Damm , Geert Uytterhoeven , Wolfram Sang Subject: [RFC v3 11/25] watchdog: renesas_wdt: Add R-Car Gen2 support Date: Tue, 30 Jan 2018 20:22:44 +0000 Message-Id: <1517343778-27902-12-git-send-email-fabrizio.castro@bp.renesas.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517343778-27902-1-git-send-email-fabrizio.castro@bp.renesas.com> References: <1517343778-27902-1-git-send-email-fabrizio.castro@bp.renesas.com> X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Fabrizio Castro , devicetree@vger.kernel.org, Chris Paterson , linux-watchdog@vger.kernel.org, Biju Das , linux-renesas-soc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Ramesh Shanmugasundaram , linux-clk@vger.kernel.org, Guenter Roeck MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On R-Car Gen2 and RZ/G1 the rwdt clock needs to be always ON, therefore when suspending to RAM we need to explicitly disable the counting by clearing TME from RWTCSRA. Also, on some systems RWDT is the only piece of HW that allows the SoC to be restarted, therefore this patch implements the restart callback. Signed-off-by: Fabrizio Castro Signed-off-by: Ramesh Shanmugasundaram --- Wolfram, was the restart callback implementation missing for a reason? Is its implementation going to break any Gen3 platform? v1->v3: * unified Gen2 and Gen3 drivers. drivers/watchdog/renesas_wdt.c | 61 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 5 deletions(-) diff --git a/drivers/watchdog/renesas_wdt.c b/drivers/watchdog/renesas_wdt.c index 831ef83..eedb016 100644 --- a/drivers/watchdog/renesas_wdt.c +++ b/drivers/watchdog/renesas_wdt.c @@ -107,6 +107,24 @@ static unsigned int rwdt_get_timeleft(struct watchdog_device *wdev) return DIV_BY_CLKS_PER_SEC(priv, 65536 - val); } +static int rwdt_restart(struct watchdog_device *wdev, unsigned long action, + void *data) +{ + struct rwdt_priv *priv = watchdog_get_drvdata(wdev); + + pm_runtime_get_sync(wdev->parent); + + rwdt_write(priv, 0x00, RWTCSRB); + rwdt_write(priv, 0x00, RWTCSRA); + rwdt_write(priv, 0xffff, RWTCNT); + + while (readb_relaxed(priv->base + RWTCSRA) & RWTCSRA_WRFLG) + cpu_relax(); + + rwdt_write(priv, 0x80, RWTCSRA); + return 0; +} + static const struct watchdog_info rwdt_ident = { .options = WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING | WDIOF_SETTIMEOUT, .identity = "Renesas WDT Watchdog", @@ -118,6 +136,7 @@ static const struct watchdog_ops rwdt_ops = { .stop = rwdt_stop, .ping = rwdt_init_timeout, .get_timeleft = rwdt_get_timeleft, + .restart = rwdt_restart, }; static int rwdt_probe(struct platform_device *pdev) @@ -203,13 +222,42 @@ static int rwdt_remove(struct platform_device *pdev) return 0; } -/* - * This driver does also fit for R-Car Gen2 (r8a779[0-4]) WDT. However, for SMP - * to work there, one also needs a RESET (RST) driver which does not exist yet - * due to HW issues. This needs to be solved before adding compatibles here. - */ +#ifdef CONFIG_PM +static int rwdt_suspend(struct device *dev) +{ + struct platform_device *pdev; + struct rwdt_priv *priv; + + pdev = to_platform_device(dev); + priv = platform_get_drvdata(pdev); + if (watchdog_active(&priv->wdev)) { + rwdt_write(priv, priv->cks, RWTCSRA); + } + return 0; +} + +static int rwdt_resume(struct device *dev) +{ + struct platform_device *pdev; + struct rwdt_priv *priv; + + pdev = to_platform_device(dev); + priv = platform_get_drvdata(pdev); + if (watchdog_active(&priv->wdev)) { + rwdt_write(priv, priv->cks | RWTCSRA_TME, RWTCSRA); + } + return 0; +} + +static const struct dev_pm_ops rwdt_pm = { + .suspend = rwdt_suspend, + .resume = rwdt_resume, +}; +#endif + static const struct of_device_id rwdt_ids[] = { { .compatible = "renesas,rcar-gen3-wdt", }, + { .compatible = "renesas,rcar-gen2-wdt", }, { /* sentinel */ } }; MODULE_DEVICE_TABLE(of, rwdt_ids); @@ -218,6 +266,9 @@ static struct platform_driver rwdt_driver = { .driver = { .name = "renesas_wdt", .of_match_table = rwdt_ids, +#ifdef CONFIG_PM + .pm = &rwdt_pm, +#endif }, .probe = rwdt_probe, .remove = rwdt_remove,