From patchwork Tue Jun 18 15:20:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 2744421 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id B32959F3A0 for ; Tue, 18 Jun 2013 17:21:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 114E72050A for ; Tue, 18 Jun 2013 17:21:14 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B6DD820509 for ; Tue, 18 Jun 2013 17:21:12 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uoxmo-00044X-QS; Tue, 18 Jun 2013 15:25:43 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uoxkp-0003O4-7z; Tue, 18 Jun 2013 15:23:31 +0000 Received: from mail-pb0-x229.google.com ([2607:f8b0:400e:c01::229]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uoxjv-0003HH-0D for linux-arm-kernel@lists.infradead.org; Tue, 18 Jun 2013 15:22:36 +0000 Received: by mail-pb0-f41.google.com with SMTP id rp16so4021172pbb.14 for ; Tue, 18 Jun 2013 08:22:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :in-reply-to:references:x-gm-message-state; bh=9CvTScEdo5OthKeTdboAKYIs00MdCbIhAgXPz2FDwWQ=; b=b8RNhxece7kLPNkf4zEZmcsiZU/6aKnRlYTnCbwml1/8XxkvtV+ckYHyUuKSFeIVQe 8Nzn8enqTOoGkFqURZ49ve0o8qyF2SSrBryI65wVB+70fgtLI1s+y4N7DI9V1ohPVHMy iu/DiAarP+DGtvYDU8ledI06DqAWApAKgBASrkBN8/+3hAKhskU6QG7RkF4gjWL3sCX5 Lmcxo7VtLZIujUAQWrzF64Wthhx3YXSfOKkc1Kf0l7UYXR8ytzOBbbezp6IH9IKnKGK8 e52QJH/JaDchmD9dIjD4ha9CAoSIKCLzF2gYMXGnwlpQULP9vj+4uhmLsqIsTiNLpTaJ iAfw== X-Received: by 10.68.101.226 with SMTP id fj2mr17714827pbb.6.1371568933948; Tue, 18 Jun 2013 08:22:13 -0700 (PDT) Received: from localhost ([122.167.240.191]) by mx.google.com with ESMTPSA id o10sm18682264pbq.39.2013.06.18.08.22.10 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Tue, 18 Jun 2013 08:22:13 -0700 (PDT) From: Viresh Kumar To: wim@iguana.be Subject: [PATCH V3 11/14] watchdog/mpcore_wdt: Add clock framework support Date: Tue, 18 Jun 2013 20:50:35 +0530 Message-Id: <7578634884ebfe416de3a179f8dd0827ab267882.1371535243.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 1.7.12.rc2.18.g61b472e In-Reply-To: References: In-Reply-To: References: X-Gm-Message-State: ALoCoQnFaXM0yIAjHZZ0JHppmOijeukEGmIo2NI81dOwMmgFbkjvODNeONfSiIATx5Qgx78O6fzI X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130618_112235_210264_7EECE4DC X-CRM114-Status: GOOD ( 15.55 ) X-Spam-Score: -1.9 (-) Cc: marc.zyngier@arm.com, Viresh Kumar , linux-watchdog@vger.kernel.org, linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds in clk framework support for wdt driver. If clk_get fails for some platform, then we continue without clk_* API's. Signed-off-by: Viresh Kumar --- drivers/watchdog/mpcore_wdt.c | 47 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 39 insertions(+), 8 deletions(-) diff --git a/drivers/watchdog/mpcore_wdt.c b/drivers/watchdog/mpcore_wdt.c index 43f749d..1a1a1fd 100644 --- a/drivers/watchdog/mpcore_wdt.c +++ b/drivers/watchdog/mpcore_wdt.c @@ -20,6 +20,8 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include +#include #include #include #include @@ -39,6 +41,7 @@ struct mpcore_wdt { struct device *dev; void __iomem *base; spinlock_t lock; + struct clk *clk; int irq; unsigned int perturb; }; @@ -109,15 +112,23 @@ static int mpcore_wdt_ping(struct watchdog_device *wdd) return 0; } -static int mpcore_wdt_stop(struct watchdog_device *wdd) +static void __mpcore_wdt_stop(struct mpcore_wdt *wdt) { - struct mpcore_wdt *wdt = watchdog_get_drvdata(wdd); - spin_lock(&wdt->lock); writel_relaxed(0x12345678, wdt->base + TWD_WDOG_DISABLE); writel_relaxed(0x87654321, wdt->base + TWD_WDOG_DISABLE); writel_relaxed(0x0, wdt->base + TWD_WDOG_CONTROL); spin_unlock(&wdt->lock); +} + +static int mpcore_wdt_stop(struct watchdog_device *wdd) +{ + struct mpcore_wdt *wdt = watchdog_get_drvdata(wdd); + + __mpcore_wdt_stop(wdt); + + if (!IS_ERR(wdt->clk)) + clk_disable_unprepare(wdt->clk); return 0; } @@ -125,9 +136,18 @@ static int mpcore_wdt_stop(struct watchdog_device *wdd) static int mpcore_wdt_start(struct watchdog_device *wdd) { struct mpcore_wdt *wdt = watchdog_get_drvdata(wdd); + int ret; dev_info(wdt->dev, "enabling watchdog\n"); + if (!IS_ERR(wdt->clk)) { + ret = clk_prepare_enable(wdt->clk); + if (ret) { + dev_err(wdt->dev, "clock prepare-enabled failed"); + return ret; + } + } + /* This loads the count register but does NOT start the count yet */ mpcore_wdt_ping(wdd); @@ -173,7 +193,7 @@ static void mpcore_wdt_shutdown(struct platform_device *pdev) struct mpcore_wdt *wdt = platform_get_drvdata(pdev); if (system_state == SYSTEM_RESTART || system_state == SYSTEM_HALT) - mpcore_wdt_stop(&wdt->wdd); + __mpcore_wdt_stop(wdt); } static int mpcore_wdt_probe(struct platform_device *pdev) @@ -217,6 +237,17 @@ static int mpcore_wdt_probe(struct platform_device *pdev) platform_set_drvdata(pdev, wdt); watchdog_set_drvdata(&wdt->wdd, wdt); + wdt->clk = devm_clk_get(&pdev->dev, NULL); + if (IS_ERR(wdt->clk)) { + dev_warn(&pdev->dev, "Clock not found\n"); + } else { + ret = clk_prepare_enable(wdt->clk); + if (ret) { + dev_err(wdt->dev, "clock prepare-enable failed"); + goto err_set_drvdata; + } + } + wdt->wdd.bootstatus = (readl_relaxed(wdt->base + TWD_WDOG_RESETSTAT) & TWD_WDOG_RESETSTAT_MASK) ? WDIOF_CARDRESET : 0; @@ -226,7 +257,7 @@ static int mpcore_wdt_probe(struct platform_device *pdev) if (ret) { dev_err(wdt->dev, "watchdog_register_device() failed: %d\n", ret); - goto err_register; + goto err_set_drvdata; } /* @@ -246,7 +277,7 @@ static int mpcore_wdt_probe(struct platform_device *pdev) return 0; -err_register: +err_set_drvdata: watchdog_set_drvdata(&wdt->wdd, NULL); return ret; @@ -267,7 +298,7 @@ static int mpcore_wdt_suspend(struct device *dev) struct mpcore_wdt *wdt = dev_get_drvdata(dev); if (watchdog_active(&wdt->wdd)) - mpcore_wdt_stop(&wdt->wdd); /* Turn the WDT off */ + return mpcore_wdt_stop(&wdt->wdd); /* Turn the WDT off */ return 0; } @@ -277,7 +308,7 @@ static int mpcore_wdt_resume(struct device *dev) struct mpcore_wdt *wdt = dev_get_drvdata(dev); if (watchdog_active(&wdt->wdd)) - mpcore_wdt_start(&wdt->wdd); + return mpcore_wdt_start(&wdt->wdd); return 0; }