From patchwork Thu Feb 16 19:30:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexandre Belloni X-Patchwork-Id: 9578223 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 7BC86600C5 for ; Thu, 16 Feb 2017 19:32:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6EC3C28665 for ; Thu, 16 Feb 2017 19:32:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61E2128669; Thu, 16 Feb 2017 19:32:13 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID 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 BA67A28665 for ; Thu, 16 Feb 2017 19:32:12 +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: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:In-Reply-To: References:List-Owner; bh=PmHb6GUXD8u0YO59lpcrk8qp12Y0Fe8Eb4sClLMZjr0=; b=bl4 OGKURHMzPYzgezLilZZfOMu/da99feEb2GE5nAXyQfPMdeaPyJSgnw4VEyJm9YfjGVbrzRh+6Td+0 LC8tTQ2oeFVpV4b1UX6PDyNovwE9QYmoX7vwbpeeUt/ZIafxwbU2FZRxGYDJyxRQYpaojQODUL+QI QLyLZJzW4AQLxcdQS+4No/UNwAmk8DwZmXKfpSrB7dQsOiaJwXsgWIrigCnrFpahk/Dguq2Ps2b9x 74tmkD3bwEGvaAXT6lK+gktSfW3i0S+c3sZETglOV1VtkmwN9DCQ4e3XshbH4HZXRflwRrPV4KBCw FeGFpy29NwMPVll2tca4P3m+ot0drZg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ceRmf-0003Es-N8; Thu, 16 Feb 2017 19:32:05 +0000 Received: from mail.free-electrons.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ceRlv-0002eL-Bd for linux-arm-kernel@lists.infradead.org; Thu, 16 Feb 2017 19:31:23 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id C0E9D20BA1; Thu, 16 Feb 2017 20:30:56 +0100 (CET) Received: from localhost (unknown [88.191.26.124]) by mail.free-electrons.com (Postfix) with ESMTPSA id 98BAB20B7A; Thu, 16 Feb 2017 20:30:56 +0100 (CET) From: Alexandre Belloni To: Guenter Roeck Subject: [PATCH v2 1/3] watchdog: sama5d4: Cleanup init Date: Thu, 16 Feb 2017 20:30:51 +0100 Message-Id: <20170216193053.5546-1-alexandre.belloni@free-electrons.com> X-Mailer: git-send-email 2.11.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170216_113119_779284_3427B56A X-CRM114-Status: GOOD ( 15.31 ) 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: linux-watchdog@vger.kernel.org, Nicolas Ferre , linux-kernel@vger.kernel.org, Wim Van Sebroeck , Alexandre Belloni , linux-arm-kernel@lists.infradead.org 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 .config is used to cache a part of WDT_MR at probe time and is not used afterwards. Also functions are used while they always return 0. Simplify the flow by having everything in .probe(). Signed-off-by: Alexandre Belloni --- Changes in v2: - completely get rid of .config instead of caching it - merge init functions in probe() drivers/watchdog/sama5d4_wdt.c | 92 ++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 58 deletions(-) diff --git a/drivers/watchdog/sama5d4_wdt.c b/drivers/watchdog/sama5d4_wdt.c index a49634cdc1cc..2c6f5a70ae67 100644 --- a/drivers/watchdog/sama5d4_wdt.c +++ b/drivers/watchdog/sama5d4_wdt.c @@ -28,7 +28,6 @@ struct sama5d4_wdt { struct watchdog_device wdd; void __iomem *reg_base; - u32 config; }; static int wdt_timeout = WDT_DEFAULT_TIMEOUT; @@ -128,57 +127,15 @@ static irqreturn_t sama5d4_wdt_irq_handler(int irq, void *dev_id) return IRQ_HANDLED; } -static int of_sama5d4_wdt_init(struct device_node *np, struct sama5d4_wdt *wdt) -{ - const char *tmp; - - wdt->config = AT91_WDT_WDDIS; - - if (!of_property_read_string(np, "atmel,watchdog-type", &tmp) && - !strcmp(tmp, "software")) - wdt->config |= AT91_WDT_WDFIEN; - else - wdt->config |= AT91_WDT_WDRSTEN; - - if (of_property_read_bool(np, "atmel,idle-halt")) - wdt->config |= AT91_WDT_WDIDLEHLT; - - if (of_property_read_bool(np, "atmel,dbg-halt")) - wdt->config |= AT91_WDT_WDDBGHLT; - - return 0; -} - -static int sama5d4_wdt_init(struct sama5d4_wdt *wdt) -{ - struct watchdog_device *wdd = &wdt->wdd; - u32 value = WDT_SEC2TICKS(wdd->timeout); - u32 reg; - - /* - * Because the fields WDV and WDD must not be modified when the WDDIS - * bit is set, so clear the WDDIS bit before writing the WDT_MR. - */ - reg = wdt_read(wdt, AT91_WDT_MR); - reg &= ~AT91_WDT_WDDIS; - wdt_write(wdt, AT91_WDT_MR, reg); - - reg = wdt->config; - reg |= AT91_WDT_SET_WDD(value); - reg |= AT91_WDT_SET_WDV(value); - - wdt_write(wdt, AT91_WDT_MR, reg); - - return 0; -} - static int sama5d4_wdt_probe(struct platform_device *pdev) { struct watchdog_device *wdd; struct sama5d4_wdt *wdt; struct resource *res; void __iomem *regs; - u32 irq = 0; + struct device_node *np = pdev->dev.of_node; + const char *tmp; + u32 mr, reg, irq = 0; int ret; wdt = devm_kzalloc(&pdev->dev, sizeof(*wdt), GFP_KERNEL); @@ -201,17 +158,26 @@ static int sama5d4_wdt_probe(struct platform_device *pdev) wdt->reg_base = regs; - if (pdev->dev.of_node) { - irq = irq_of_parse_and_map(pdev->dev.of_node, 0); - if (!irq) - dev_warn(&pdev->dev, "failed to get IRQ from DT\n"); + irq = irq_of_parse_and_map(np, 0); + if (!irq) + dev_warn(&pdev->dev, "failed to get IRQ from DT\n"); - ret = of_sama5d4_wdt_init(pdev->dev.of_node, wdt); - if (ret) - return ret; - } - if ((wdt->config & AT91_WDT_WDFIEN) && irq) { + mr = AT91_WDT_WDDIS; + + if (!of_property_read_string(np, "atmel,watchdog-type", &tmp) && + !strcmp(tmp, "software")) + mr |= AT91_WDT_WDFIEN; + else + mr |= AT91_WDT_WDRSTEN; + + if (of_property_read_bool(np, "atmel,idle-halt")) + mr |= AT91_WDT_WDIDLEHLT; + + if (of_property_read_bool(np, "atmel,dbg-halt")) + mr |= AT91_WDT_WDDBGHLT; + + if ((mr & AT91_WDT_WDFIEN) && irq) { ret = devm_request_irq(&pdev->dev, irq, sama5d4_wdt_irq_handler, IRQF_SHARED | IRQF_IRQPOLL | IRQF_NO_SUSPEND, pdev->name, pdev); @@ -228,9 +194,19 @@ static int sama5d4_wdt_probe(struct platform_device *pdev) return ret; } - ret = sama5d4_wdt_init(wdt); - if (ret) - return ret; + /* + * WDV and WDD must not be modified when the WDDIS bit is set, so clear + * the WDDIS bit before writing the WDT_MR. + */ + reg = wdt_read(wdt, AT91_WDT_MR); + reg &= ~AT91_WDT_WDDIS; + wdt_write(wdt, AT91_WDT_MR, reg); + + reg = mr; + reg |= AT91_WDT_SET_WDD(WDT_SEC2TICKS(wdd->timeout)); + reg |= AT91_WDT_SET_WDV(WDT_SEC2TICKS(wdd->timeout)); + + wdt_write(wdt, AT91_WDT_MR, reg); watchdog_set_nowayout(wdd, nowayout);