From patchwork Sun May 21 13:09:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hauke Mehrtens X-Patchwork-Id: 9739065 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 BE40860392 for ; Sun, 21 May 2017 13:09:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF133286B7 for ; Sun, 21 May 2017 13:09:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A3476286DC; Sun, 21 May 2017 13:09:57 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8881E286D9 for ; Sun, 21 May 2017 13:09:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753609AbdEUNJu (ORCPT ); Sun, 21 May 2017 09:09:50 -0400 Received: from hauke-m.de ([5.39.93.123]:36632 "EHLO mail.hauke-m.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752612AbdEUNJq (ORCPT ); Sun, 21 May 2017 09:09:46 -0400 Received: from hauke-desktop.lan (p2003008628380100610A1109F04F7762.dip0.t-ipconnect.de [IPv6:2003:86:2838:100:610a:1109:f04f:7762]) by mail.hauke-m.de (Postfix) with ESMTPSA id 7DBD31001D6; Sun, 21 May 2017 15:09:44 +0200 (CEST) From: Hauke Mehrtens To: ralf@linux-mips.org Cc: linux-mips@linux-mips.org, linux-mtd@lists.infradead.org, linux-watchdog@vger.kernel.org, devicetree@vger.kernel.org, martin.blumenstingl@googlemail.com, john@phrozen.org, linux-spi@vger.kernel.org, hauke.mehrtens@intel.com, robh@kernel.org, Hauke Mehrtens Subject: [PATCH v2 04/15] watchdog: lantiq: access boot cause register through regmap Date: Sun, 21 May 2017 15:09:07 +0200 Message-Id: <20170521130918.27446-5-hauke@hauke-m.de> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170521130918.27446-1-hauke@hauke-m.de> References: <20170521130918.27446-1-hauke@hauke-m.de> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch avoids accessing the function ltq_reset_cause() and directly accesses the register given over the syscon interface. The syscon interface will be implemented for the xway SoCs for the falcon SoCs the ltq_reset_cause() function never worked, because a wrong offset was used. Signed-off-by: Hauke Mehrtens Acked-by: Guenter Roeck --- drivers/watchdog/lantiq_wdt.c | 48 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 4 deletions(-) diff --git a/drivers/watchdog/lantiq_wdt.c b/drivers/watchdog/lantiq_wdt.c index e0823677d8c1..d0447d8cabd0 100644 --- a/drivers/watchdog/lantiq_wdt.c +++ b/drivers/watchdog/lantiq_wdt.c @@ -4,6 +4,7 @@ * by the Free Software Foundation. * * Copyright (C) 2010 John Crispin + * Copyright (C) 2017 Hauke Mehrtens * Based on EP93xx wdt driver */ @@ -17,9 +18,14 @@ #include #include #include +#include +#include #include +#define LTQ_RST_CAUSE_WDT_XRX BIT(31) +#define LTQ_RST_CAUSE_WDT_FALCON 0x02 + /* * Section 3.4 of the datasheet * The password sequence protects the WDT control register from unintended @@ -186,6 +192,40 @@ static struct miscdevice ltq_wdt_miscdev = { .fops = <q_wdt_fops, }; +static void ltq_set_wdt_bootstatus(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + struct regmap *rcu_regmap; + u32 status_reg_offset; + u32 val; + int err; + + rcu_regmap = syscon_regmap_lookup_by_phandle(np, + "lantiq,rcu-syscon"); + if (IS_ERR_OR_NULL(rcu_regmap)) + return; + + err = of_property_read_u32_index(np, "lantiq,rcu-syscon", 1, + &status_reg_offset); + if (err) { + dev_err(&pdev->dev, "Failed to get RCU reg offset\n"); + return; + } + + err = regmap_read(rcu_regmap, status_reg_offset, &val); + if (err) + return; + + /* find out if the watchdog caused the last reboot */ + if (of_device_is_compatible(np, "lantiq,wdt-xrx100")) { + if (val & LTQ_RST_CAUSE_WDT_XRX) + ltq_wdt_bootstatus = WDIOF_CARDRESET; + } else if (of_device_is_compatible(np, "lantiq,wdt-falcon")) { + if ((val & 0x7) == LTQ_RST_CAUSE_WDT_FALCON) + ltq_wdt_bootstatus = WDIOF_CARDRESET; + } +} + static int ltq_wdt_probe(struct platform_device *pdev) { @@ -205,9 +245,7 @@ ltq_wdt_probe(struct platform_device *pdev) ltq_io_region_clk_rate = clk_get_rate(clk); clk_put(clk); - /* find out if the watchdog caused the last reboot */ - if (ltq_reset_cause() == LTQ_RST_CAUSE_WDTRST) - ltq_wdt_bootstatus = WDIOF_CARDRESET; + ltq_set_wdt_bootstatus(pdev); dev_info(&pdev->dev, "Init done\n"); return misc_register(<q_wdt_miscdev); @@ -222,7 +260,9 @@ ltq_wdt_remove(struct platform_device *pdev) } static const struct of_device_id ltq_wdt_match[] = { - { .compatible = "lantiq,wdt" }, + { .compatible = "lantiq,wdt"}, + { .compatible = "lantiq,wdt-xrx100"}, + { .compatible = "lantiq,wdt-falcon"}, {}, }; MODULE_DEVICE_TABLE(of, ltq_wdt_match);