From patchwork Wed Nov 14 07:16:00 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenyou Yang X-Patchwork-Id: 1739341 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork1.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork1.kernel.org (Postfix) with ESMTP id BA73E3FC64 for ; Wed, 14 Nov 2012 07:23:43 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TYXGP-0002FI-By; Wed, 14 Nov 2012 07:19:57 +0000 Received: from newsmtp5.atmel.com ([204.2.163.5] helo=sjogate2.atmel.com) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TYXG0-0002CA-GV for linux-arm-kernel@lists.infradead.org; Wed, 14 Nov 2012 07:19:33 +0000 Received: from penbh01.corp.atmel.com ([10.168.5.31]) by sjogate2.atmel.com (8.13.6/8.13.6) with ESMTP id qAE7E6GB008421; Tue, 13 Nov 2012 23:14:18 -0800 (PST) Received: from penmb01.corp.atmel.com ([10.168.5.33]) by penbh01.corp.atmel.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 14 Nov 2012 15:19:20 +0800 Received: from shaarm01.corp.atmel.com ([10.217.6.34]) by penmb01.corp.atmel.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 14 Nov 2012 15:19:20 +0800 From: Wenyou Yang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 02/11] watchdog/at91sam9_wdt: change the at91wdt_private struct to the at91wdt_drvdata struct Date: Wed, 14 Nov 2012 15:16:00 +0800 Message-Id: <1352877369-19740-3-git-send-email-wenyou.yang@atmel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1352877369-19740-1-git-send-email-wenyou.yang@atmel.com> References: <1352877369-19740-1-git-send-email-wenyou.yang@atmel.com> X-OriginalArrivalTime: 14 Nov 2012 07:19:20.0556 (UTC) FILETIME=[5D75A2C0:01CDC238] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121114_021932_945326_2EF5F6F4 X-CRM114-Status: GOOD ( 14.17 ) X-Spam-Score: -2.6 (--) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-2.6 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: linux-watchdog@vger.kernel.org, JM.Lin@atmel.com, nicolas.ferre@atmel.com, linux-kernel@vger.kernel.org, wenyou.yang@atmel.com, wim@iguana.be, plagnioj@jcrosoft.com X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Set the at91wdt_drvdata struct as the driver data of struct watchdog_device. Signed-off-by: Wenyou Yang --- drivers/watchdog/at91sam9_wdt.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/drivers/watchdog/at91sam9_wdt.c b/drivers/watchdog/at91sam9_wdt.c index 549c256..31c914a 100644 --- a/drivers/watchdog/at91sam9_wdt.c +++ b/drivers/watchdog/at91sam9_wdt.c @@ -66,13 +66,12 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started " static void at91_ping(unsigned long data); -static struct { +struct at91wdt_drvdata { void __iomem *base; + bool enabled; /* indicate if the watchdog is eabled */ unsigned long next_heartbeat; /* the next_heartbeat for the timer */ - unsigned long open; - char expect_close; struct timer_list timer; /* The timer that pings the watchdog */ -} at91wdt_private; +}; /* ......................................................................... */ @@ -90,10 +89,12 @@ static inline void at91_wdt_reset(void) */ static void at91_ping(unsigned long data) { - if (time_before(jiffies, at91wdt_private.next_heartbeat) || - (!nowayout && !at91wdt_private.open)) { + struct watchdog_device *wddev = (struct watchdog_device *)data; + struct at91wdt_drvdata *driver_data = watchdog_get_drvdata(wddev); + + if (time_before(jiffies, driver_data->next_heartbeat)) at91_wdt_reset(); - mod_timer(&at91wdt_private.timer, jiffies + WDT_TIMEOUT); + mod_timer(&driver_data->timer, jiffies + WDT_TIMEOUT); } else pr_crit("I will reset your machine !\n"); } @@ -138,26 +139,36 @@ static const struct watchdog_info at91_wdt_info = { static int __init at91wdt_probe(struct platform_device *pdev) { + struct at91wdt_drvdata *driver_data; struct resource *r; int res; + driver_data = devm_kzalloc(&pdev->dev, + sizeof(*driver_data), GFP_KERNEL); + if (!driver_data) { + dev_err(&pdev->dev, "Unable to alloacate watchdog device\n"); + return -ENOMEM; + } + r = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!r) return -ENODEV; - at91wdt_private.base = ioremap(r->start, resource_size(r)); - if (!at91wdt_private.base) { + driver_data->base = ioremap(r->start, resource_size(r)); + if (!driver_data->base) { dev_err(&pdev->dev, "failed to map registers, aborting.\n"); return -ENOMEM; } + watchdog_set_drvdata(&at91_wddev, driver_data); + /* Set watchdog */ res = at91_wdt_settimeout(ms_to_ticks(WDT_HW_TIMEOUT * 1000)); if (res) return res; - at91wdt_private.next_heartbeat = jiffies + heartbeat * HZ; - setup_timer(&at91wdt_private.timer, at91_ping, 0); - mod_timer(&at91wdt_private.timer, jiffies + WDT_TIMEOUT); + driver_data->next_heartbeat = jiffies + heartbeat * HZ; + setup_timer(&driver_data->timer, at91_ping, 0); + mod_timer(&driver_data->timer, jiffies + WDT_TIMEOUT); pr_info("enabled (heartbeat=%d sec, nowayout=%d)\n", heartbeat, nowayout);