From patchwork Fri Feb 1 07:06:20 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenyou Yang X-Patchwork-Id: 2076961 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 1BB7740106 for ; Fri, 1 Feb 2013 07:10:55 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1U1Ajv-0004Vv-GY; Fri, 01 Feb 2013 07:08:47 +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 1U1Air-00042D-P7 for linux-arm-kernel@lists.infradead.org; Fri, 01 Feb 2013 07:07:49 +0000 Received: from penbh01.corp.atmel.com ([10.168.5.31]) by sjogate2.atmel.com (8.13.6/8.13.6) with ESMTP id r117251E006574; Thu, 31 Jan 2013 23:02:06 -0800 (PST) Received: from penmb01.corp.atmel.com ([10.168.5.33]) by penbh01.corp.atmel.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 1 Feb 2013 15:07:24 +0800 Received: from shaarm01.corp.atmel.com ([10.217.6.34]) by penmb01.corp.atmel.com with Microsoft SMTPSVC(6.0.3790.3959); Fri, 1 Feb 2013 15:07:22 +0800 From: Wenyou Yang To: linux-arm-kernel@lists.infradead.org Subject: [PATCH v4 2/8] watchdog/at91sam9_wdt: Remove at91wdt_private and add at91wdt_drvdata struct Date: Fri, 1 Feb 2013 15:06:20 +0800 Message-Id: <1359702386-21284-3-git-send-email-wenyou.yang@atmel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1359702386-21284-1-git-send-email-wenyou.yang@atmel.com> References: <1359702386-21284-1-git-send-email-wenyou.yang@atmel.com> X-OriginalArrivalTime: 01 Feb 2013 07:07:22.0778 (UTC) FILETIME=[C843A7A0:01CE004A] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130201_020742_127146_6F95B263 X-CRM114-Status: GOOD ( 17.62 ) 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, fabio.porcedda@gmail.com, 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 Remove the global variable at91wdt_private, add the struct at91wdt_drvdata as a substitute, and set it as the driver data of the at91wdt_wdd. Signed-off-by: Wenyou Yang Cc: wim@iguana.be Cc: linux-watchdog@vger.kernel.org Cc: linux-kernel@vger.kernel.org --- drivers/watchdog/at91sam9_wdt.c | 88 +++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 41 deletions(-) diff --git a/drivers/watchdog/at91sam9_wdt.c b/drivers/watchdog/at91sam9_wdt.c index 61129fc..66d3afb 100644 --- a/drivers/watchdog/at91sam9_wdt.c +++ b/drivers/watchdog/at91sam9_wdt.c @@ -38,11 +38,6 @@ #define DRV_NAME "AT91SAM9 Watchdog" -#define wdt_read(field) \ - __raw_readl(at91wdt_private.base + field) -#define wdt_write(field, val) \ - __raw_writel((val), at91wdt_private.base + field) - /* AT91SAM9 watchdog runs a 12bit counter @ 256Hz, * use this to convert a watchdog * value from/to milliseconds. @@ -72,23 +67,33 @@ MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started " static void at91_ping(unsigned long data); -static struct { - void __iomem *base; - 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; +struct at91wdt_drvdata { + void __iomem *phybase; + bool is_enable; /* indicate if the watchdog is eabled */ + unsigned long next_heartbeat; /* the next_heartbeat for the timer */ + struct timer_list timer; /* The timer that pings the watchdog */ +}; /* ......................................................................... */ +static inline unsigned int wdt_read(struct at91wdt_drvdata *driver_data, + unsigned int field) +{ + return readl_relaxed(driver_data->phybase + field); +} + +static inline void wdt_write(struct at91wdt_drvdata *driver_data, + unsigned int field, unsigned int val) +{ + writel_relaxed((val), driver_data->phybase + field); +} /* * Reload the watchdog timer. (ie, pat the watchdog) */ -static inline void at91_wdt_reset(void) +static inline void at91_wdt_reset(struct at91wdt_drvdata *driver_data) { - wdt_write(AT91_WDT_CR, AT91_WDT_KEY | AT91_WDT_WDRSTT); + wdt_write(driver_data, AT91_WDT_CR, AT91_WDT_KEY | AT91_WDT_WDRSTT); } /* @@ -96,10 +101,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)) { - at91_wdt_reset(); - mod_timer(&at91wdt_private.timer, jiffies + WDT_TIMEOUT); + 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(driver_data); + mod_timer(&driver_data->timer, jiffies + WDT_TIMEOUT); } else pr_crit("I will reset your machine !\n"); } @@ -109,11 +116,8 @@ static void at91_ping(unsigned long data) */ static int at91_wdt_open(struct inode *inode, struct file *file) { - if (test_and_set_bit(0, &at91wdt_private.open)) - return -EBUSY; - - at91wdt_private.next_heartbeat = jiffies + heartbeat * HZ; - mod_timer(&at91wdt_private.timer, jiffies + WDT_TIMEOUT); + driver_data->next_heartbeat = jiffies + heartbeat * HZ; + mod_timer(&driver_data->timer, jiffies + WDT_TIMEOUT); return nonseekable_open(inode, file); } @@ -123,13 +127,8 @@ static int at91_wdt_open(struct inode *inode, struct file *file) */ static int at91_wdt_close(struct inode *inode, struct file *file) { - clear_bit(0, &at91wdt_private.open); + del_timer(&driver_data->timer); - /* stop internal ping */ - if (!at91wdt_private.expect_close) - del_timer(&at91wdt_private.timer); - - at91wdt_private.expect_close = 0; return 0; } @@ -191,7 +190,7 @@ static long at91_wdt_ioctl(struct file *file, return put_user(0, p); case WDIOC_KEEPALIVE: - at91wdt_private.next_heartbeat = jiffies + heartbeat * HZ; + driver_data->next_heartbeat = jiffies + heartbeat * HZ; return 0; case WDIOC_SETTIMEOUT: @@ -199,7 +198,7 @@ static long at91_wdt_ioctl(struct file *file, return -EFAULT; heartbeat = new_value; - at91wdt_private.next_heartbeat = jiffies + heartbeat * HZ; + driver_data->next_heartbeat = jiffies + heartbeat * HZ; return put_user(new_value, p); /* return current value */ @@ -222,20 +221,16 @@ static ssize_t at91_wdt_write(struct file *file, const char *data, size_t len, if (!nowayout) { size_t i; - at91wdt_private.expect_close = 0; for (i = 0; i < len; i++) { char c; if (get_user(c, data + i)) return -EFAULT; - if (c == 'V') { - at91wdt_private.expect_close = 42; - break; } } } - at91wdt_private.next_heartbeat = jiffies + heartbeat * HZ; + driver_data->next_heartbeat = jiffies + heartbeat * HZ; return len; } @@ -265,9 +260,19 @@ static struct watchdog_device at91wdt_wdd __initdata = { 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; + } + + watchdog_set_drvdata(&at91wdt_wdd, driver_data); + if (at91wdt_miscdev.parent) return -EBUSY; at91wdt_miscdev.parent = &pdev->dev; @@ -275,8 +280,8 @@ static int __init at91wdt_probe(struct platform_device *pdev) 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->phybase = ioremap(r->start, resource_size(r)); + if (!driver_data->phybase) { dev_err(&pdev->dev, "failed to map registers, aborting.\n"); return -ENOMEM; } @@ -292,9 +297,10 @@ static int __init at91wdt_probe(struct platform_device *pdev) if (res) return res; - at91wdt_private.next_heartbeat = jiffies + at91wdt_wdd.timeout * HZ; - setup_timer(&at91wdt_private.timer, at91_ping, 0); - mod_timer(&at91wdt_private.timer, jiffies + WDT_TIMEOUT); + driver_data->next_heartbeat = jiffies + at91wdt_wdd.timeout * HZ; + setup_timer(&driver_data->timer, at91_ping, + (unsigned long)&at91wdt_wdd); + mod_timer(&driver_data->timer, jiffies + WDT_TIMEOUT); pr_info("enabled (heartbeat=%d sec, nowayout=%d)\n", at91wdt_wdd.timeout, nowayout);