From patchwork Sat Jan 5 02:38:42 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wenyou Yang X-Patchwork-Id: 1935661 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id CCE92E016D for ; Sat, 5 Jan 2013 02:49:18 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1TrJlS-0001Hv-Q0; Sat, 05 Jan 2013 02:45:38 +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 1TrJkg-0001A1-F5 for linux-arm-kernel@lists.infradead.org; Sat, 05 Jan 2013 02:44:52 +0000 Received: from penbh01.corp.atmel.com ([10.168.5.31]) by sjogate2.atmel.com (8.13.6/8.13.6) with ESMTP id r052dH5B015608; Fri, 4 Jan 2013 18:39: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); Sat, 5 Jan 2013 10:44:29 +0800 Received: from shaarm01.corp.atmel.com ([10.217.6.34]) by penmb01.corp.atmel.com with Microsoft SMTPSVC(6.0.3790.3959); Sat, 5 Jan 2013 10:44:28 +0800 From: Wenyou Yang To: linux-arm-kernel@lists.infradead.org Subject: [v3 PATCH 2/9] watchdog/at91sam9_wdt: Remove at91wdt_private and add at91wdt_drvdata struct Date: Sat, 5 Jan 2013 10:38:42 +0800 Message-Id: <1357353529-20901-3-git-send-email-wenyou.yang@atmel.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1357353529-20901-1-git-send-email-wenyou.yang@atmel.com> References: <1357353529-20901-1-git-send-email-wenyou.yang@atmel.com> X-OriginalArrivalTime: 05 Jan 2013 02:44:29.0019 (UTC) FILETIME=[9537CAB0:01CDEAEE] X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130104_214450_738501_A8D025C6 X-CRM114-Status: GOOD ( 17.55 ) 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 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 d864dc4..f10a897 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);