From patchwork Wed Nov 6 11:31:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ivan Khoronzhuk X-Patchwork-Id: 3146761 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 532F5BEEB2 for ; Wed, 6 Nov 2013 11:42:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 036C120453 for ; Wed, 6 Nov 2013 11:42:12 +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 9503120381 for ; Wed, 6 Nov 2013 11:42:10 +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 1Ve1Us-0001eu-Ii; Wed, 06 Nov 2013 11:42:06 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ve1Uq-0004q5-0c; Wed, 06 Nov 2013 11:42:04 +0000 Received: from comal.ext.ti.com ([198.47.26.152]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Ve1Um-0004pZ-KC for linux-arm-kernel@lists.infradead.org; Wed, 06 Nov 2013 11:42:01 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id rA6BVNEu020498; Wed, 6 Nov 2013 05:31:23 -0600 Received: from DNCE70.ent.ti.com (dnce70.ent.ti.com [137.167.131.19]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id rA6BVMkR026368; Wed, 6 Nov 2013 05:31:23 -0600 Received: from [10.167.145.122] (10.167.145.122) by DNCE70.ent.ti.com (137.167.131.19) with Microsoft SMTP Server id 14.2.342.3; Wed, 6 Nov 2013 12:31:22 +0100 Message-ID: <527A2888.5030604@ti.com> Date: Wed, 6 Nov 2013 13:31:20 +0200 From: "ivan.khoronzhuk" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.1.0 MIME-Version: 1.0 To: Santosh Shilimkar , , , , Subject: Fwd: [PATCH 2/8] watchdog: davinci: use davinci_wdt_device structure to hold device data References: <1383680783-12114-3-git-send-email-ivan.khoronzhuk@ti.com> In-Reply-To: <1383680783-12114-3-git-send-email-ivan.khoronzhuk@ti.com> X-Forwarded-Message-Id: <1383680783-12114-3-git-send-email-ivan.khoronzhuk@ti.com> X-Originating-IP: [10.167.145.122] X-EXCLAIMER-MD-CONFIG: f9c360f5-3d1e-4c3c-8703-f45bf52eff6b X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20131106_064200_743829_02524917 X-CRM114-Status: GOOD ( 15.24 ) X-Spam-Score: -6.9 (------) Cc: mark.rutland@arm.com, pawel.moll@arm.com, swarren@wwwdotorg.org, ijc+devicetree@hellion.org.uk, galak@kernel.crashing.org, rob.herring@calxeda.com, linux-kernel@vger.kernel.org, grant.likely@linaro.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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 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 Some SoCs, like Keystone 2, can support more than one WDT and each watchdog device has to use it's own base address, clock source, wdd device, so add new davinci_wdt_device structure to hold device data. Signed-off-by: Ivan Khoronzhuk Acked-by: Santosh Shilimkar Reviewed-by: Guenter roeck --- drivers/watchdog/davinci_wdt.c | 74 ++++++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 26 deletions(-) diff --git a/drivers/watchdog/davinci_wdt.c b/drivers/watchdog/davinci_wdt.c index a6eef71..1fc2093 100644 --- a/drivers/watchdog/davinci_wdt.c +++ b/drivers/watchdog/davinci_wdt.c @@ -56,9 +56,18 @@ #define WDKEY_SEQ1 (0xda7e << 16) static int heartbeat = MAX_HEARTBEAT + 1; -static void __iomem *wdt_base; -struct clk *wdt_clk; -static struct watchdog_device wdt_wdd; + +/* + * struct to hold data for each WDT device + * @base - base io address of WD device + * @clk - source clock of WDT + * @wdd - hold watchdog device as is in WDT core + */ +struct davinci_wdt_device { + void __iomem *base; + struct clk *clk; + struct watchdog_device wdd; +}; /* davinci_wdt_start - enable watchdog */ static int davinci_wdt_start(struct watchdog_device *wdd) @@ -66,42 +75,45 @@ static int davinci_wdt_start(struct watchdog_device *wdd) u32 tgcr; u32 timer_margin; unsigned long wdt_freq; + struct davinci_wdt_device *davinci_wdt = watchdog_get_drvdata(wdd); - wdt_freq = clk_get_rate(wdt_clk); + wdt_freq = clk_get_rate(davinci_wdt->clk); /* disable, internal clock source */ - iowrite32(0, wdt_base + TCR); + iowrite32(0, davinci_wdt->base + TCR); /* reset timer, set mode to 64-bit watchdog, and unreset */ - iowrite32(0, wdt_base + TGCR); + iowrite32(0, davinci_wdt->base + TGCR); tgcr = TIMMODE_64BIT_WDOG | TIM12RS_UNRESET | TIM34RS_UNRESET; - iowrite32(tgcr, wdt_base + TGCR); + iowrite32(tgcr, davinci_wdt->base + TGCR); /* clear counter regs */ - iowrite32(0, wdt_base + TIM12); - iowrite32(0, wdt_base + TIM34); + iowrite32(0, davinci_wdt->base + TIM12); + iowrite32(0, davinci_wdt->base + TIM34); /* set timeout period */ timer_margin = (((u64)wdd->timeout * wdt_freq) & 0xffffffff); - iowrite32(timer_margin, wdt_base + PRD12); + iowrite32(timer_margin, davinci_wdt->base + PRD12); timer_margin = (((u64)wdd->timeout * wdt_freq) >> 32); - iowrite32(timer_margin, wdt_base + PRD34); + iowrite32(timer_margin, davinci_wdt->base + PRD34); /* enable run continuously */ - iowrite32(ENAMODE12_PERIODIC, wdt_base + TCR); + iowrite32(ENAMODE12_PERIODIC, davinci_wdt->base + TCR); /* Once the WDT is in pre-active state write to * TIM12, TIM34, PRD12, PRD34, TCR, TGCR, WDTCR are * write protected (except for the WDKEY field) */ /* put watchdog in pre-active state */ - iowrite32(WDKEY_SEQ0 | WDEN, wdt_base + WDTCR); + iowrite32(WDKEY_SEQ0 | WDEN, davinci_wdt->base + WDTCR); /* put watchdog in active state */ - iowrite32(WDKEY_SEQ1 | WDEN, wdt_base + WDTCR); + iowrite32(WDKEY_SEQ1 | WDEN, davinci_wdt->base + WDTCR); return 0; } static int davinci_wdt_ping(struct watchdog_device *wdd) { + struct davinci_wdt_device *davinci_wdt = watchdog_get_drvdata(wdd); + /* put watchdog in service state */ - iowrite32(WDKEY_SEQ0, wdt_base + WDTCR); + iowrite32(WDKEY_SEQ0, davinci_wdt->base + WDTCR); /* put watchdog in active state */ - iowrite32(WDKEY_SEQ1, wdt_base + WDTCR); + iowrite32(WDKEY_SEQ1, davinci_wdt->base + WDTCR); return 0; } @@ -123,14 +135,21 @@ static int davinci_wdt_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct resource *wdt_mem; struct watchdog_device *wdd; + struct davinci_wdt_device *davinci_wdt; + + davinci_wdt = devm_kzalloc(dev, sizeof(*davinci_wdt), GFP_KERNEL); + if (!davinci_wdt) + return -ENOMEM; - wdt_clk = devm_clk_get(dev, NULL); - if (WARN_ON(IS_ERR(wdt_clk))) - return PTR_ERR(wdt_clk); + davinci_wdt->clk = devm_clk_get(dev, NULL); + if (WARN_ON(IS_ERR(davinci_wdt->clk))) + return PTR_ERR(davinci_wdt->clk); - clk_prepare_enable(wdt_clk); + clk_prepare_enable(davinci_wdt->clk); - wdd = &wdt_wdd; + platform_set_drvdata(pdev, davinci_wdt); + + wdd = &davinci_wdt->wdd; wdd->info = &davinci_wdt_info; wdd->ops = &davinci_wdt_ops; wdd->min_timeout = 1; @@ -142,12 +161,13 @@ static int davinci_wdt_probe(struct platform_device *pdev) dev_info(dev, "heartbeat %d sec\n", wdd->timeout); + watchdog_set_drvdata(wdd, davinci_wdt); watchdog_set_nowayout(wdd, WATCHDOG_NOWAYOUT); wdt_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); - wdt_base = devm_ioremap_resource(dev, wdt_mem); - if (IS_ERR(wdt_base)) - return PTR_ERR(wdt_base); + davinci_wdt->base = devm_ioremap_resource(dev, wdt_mem); + if (IS_ERR(davinci_wdt->base)) + return PTR_ERR(davinci_wdt->base); ret = watchdog_register_device(wdd); if (ret < 0) @@ -158,8 +178,10 @@ static int davinci_wdt_probe(struct platform_device *pdev) static int davinci_wdt_remove(struct platform_device *pdev) { - watchdog_unregister_device(&wdt_wdd); - clk_disable_unprepare(wdt_clk); + struct davinci_wdt_device *davinci_wdt = platform_get_drvdata(pdev); + + watchdog_unregister_device(&davinci_wdt->wdd); + clk_disable_unprepare(davinci_wdt->clk); return 0; }