blob: 2b4acb86c191eec0c4a23f0541eb0c8d33079445 [file] [log] [blame]
Komal Shah7768a132006-09-29 01:59:18 -07001/*
Felipe Balbi28171422008-09-20 04:14:01 +03002 * omap_wdt.c
Komal Shah7768a132006-09-29 01:59:18 -07003 *
Felipe Balbi28171422008-09-20 04:14:01 +03004 * Watchdog driver for the TI OMAP 16xx & 24xx/34xx 32KHz (non-secure) watchdog
Komal Shah7768a132006-09-29 01:59:18 -07005 *
6 * Author: MontaVista Software, Inc.
7 * <gdavis@mvista.com> or <source@mvista.com>
8 *
9 * 2003 (c) MontaVista Software, Inc. This file is licensed under the
10 * terms of the GNU General Public License version 2. This program is
11 * licensed "as is" without any warranty of any kind, whether express
12 * or implied.
13 *
14 * History:
15 *
16 * 20030527: George G. Davis <gdavis@mvista.com>
17 * Initially based on linux-2.4.19-rmk7-pxa1/drivers/char/sa1100_wdt.c
18 * (c) Copyright 2000 Oleg Drokin <green@crimea.edu>
Alan Cox29fa0582008-10-27 15:17:56 +000019 * Based on SoftDog driver by Alan Cox <alan@lxorguk.ukuu.org.uk>
Komal Shah7768a132006-09-29 01:59:18 -070020 *
21 * Copyright (c) 2004 Texas Instruments.
22 * 1. Modified to support OMAP1610 32-KHz watchdog timer
23 * 2. Ported to 2.6 kernel
24 *
25 * Copyright (c) 2005 David Brownell
26 * Use the driver model and standard identifiers; handle bigger timeouts.
27 */
28
29#include <linux/module.h>
Komal Shah7768a132006-09-29 01:59:18 -070030#include <linux/types.h>
31#include <linux/kernel.h>
32#include <linux/fs.h>
33#include <linux/mm.h>
34#include <linux/miscdevice.h>
35#include <linux/watchdog.h>
36#include <linux/reboot.h>
Komal Shah7768a132006-09-29 01:59:18 -070037#include <linux/init.h>
38#include <linux/err.h>
39#include <linux/platform_device.h>
40#include <linux/moduleparam.h>
Jiri Slaby1977f032007-10-18 23:40:25 -070041#include <linux/bitops.h>
Wim Van Sebroeck089ab072008-07-15 11:46:11 +000042#include <linux/io.h>
Alan Cox12b9df72008-05-19 14:07:32 +010043#include <linux/uaccess.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090044#include <linux/slab.h>
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +053045#include <linux/pm_runtime.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010046#include <mach/hardware.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070047#include <plat/prcm.h>
Komal Shah7768a132006-09-29 01:59:18 -070048
49#include "omap_wdt.h"
50
Felipe Balbi28171422008-09-20 04:14:01 +030051static struct platform_device *omap_wdt_dev;
52
Komal Shah7768a132006-09-29 01:59:18 -070053static unsigned timer_margin;
54module_param(timer_margin, uint, 0);
55MODULE_PARM_DESC(timer_margin, "initial watchdog timeout (in seconds)");
56
Komal Shah7768a132006-09-29 01:59:18 -070057static unsigned int wdt_trgr_pattern = 0x1234;
Alan Cox12b9df72008-05-19 14:07:32 +010058static spinlock_t wdt_lock;
Komal Shah7768a132006-09-29 01:59:18 -070059
Felipe Balbi28171422008-09-20 04:14:01 +030060struct omap_wdt_dev {
61 void __iomem *base; /* physical */
62 struct device *dev;
63 int omap_wdt_users;
Felipe Balbi28171422008-09-20 04:14:01 +030064 struct resource *mem;
65 struct miscdevice omap_wdt_miscdev;
66};
67
68static void omap_wdt_ping(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -070069{
Felipe Balbi28171422008-09-20 04:14:01 +030070 void __iomem *base = wdev->base;
Felipe Balbib3112182008-09-20 04:14:03 +030071
Komal Shah7768a132006-09-29 01:59:18 -070072 /* wait for posted write to complete */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +030073 while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x08)
Komal Shah7768a132006-09-29 01:59:18 -070074 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +030075
Komal Shah7768a132006-09-29 01:59:18 -070076 wdt_trgr_pattern = ~wdt_trgr_pattern;
Felipe Balbi9f69e3b2008-09-20 04:14:02 +030077 __raw_writel(wdt_trgr_pattern, (base + OMAP_WATCHDOG_TGR));
Felipe Balbib3112182008-09-20 04:14:03 +030078
Komal Shah7768a132006-09-29 01:59:18 -070079 /* wait for posted write to complete */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +030080 while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x08)
Komal Shah7768a132006-09-29 01:59:18 -070081 cpu_relax();
82 /* reloaded WCRR from WLDR */
83}
84
Felipe Balbi28171422008-09-20 04:14:01 +030085static void omap_wdt_enable(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -070086{
Felipe Balbib3112182008-09-20 04:14:03 +030087 void __iomem *base = wdev->base;
88
Komal Shah7768a132006-09-29 01:59:18 -070089 /* Sequence to enable the watchdog */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +030090 __raw_writel(0xBBBB, base + OMAP_WATCHDOG_SPR);
91 while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -070092 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +030093
Felipe Balbi9f69e3b2008-09-20 04:14:02 +030094 __raw_writel(0x4444, base + OMAP_WATCHDOG_SPR);
95 while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -070096 cpu_relax();
97}
98
Felipe Balbi28171422008-09-20 04:14:01 +030099static void omap_wdt_disable(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -0700100{
Felipe Balbib3112182008-09-20 04:14:03 +0300101 void __iomem *base = wdev->base;
102
Komal Shah7768a132006-09-29 01:59:18 -0700103 /* sequence required to disable watchdog */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300104 __raw_writel(0xAAAA, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
105 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -0700106 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +0300107
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300108 __raw_writel(0x5555, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
109 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -0700110 cpu_relax();
111}
112
113static void omap_wdt_adjust_timeout(unsigned new_timeout)
114{
115 if (new_timeout < TIMER_MARGIN_MIN)
116 new_timeout = TIMER_MARGIN_DEFAULT;
117 if (new_timeout > TIMER_MARGIN_MAX)
118 new_timeout = TIMER_MARGIN_MAX;
119 timer_margin = new_timeout;
120}
121
Felipe Balbi28171422008-09-20 04:14:01 +0300122static void omap_wdt_set_timeout(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -0700123{
124 u32 pre_margin = GET_WLDR_VAL(timer_margin);
Felipe Balbib3112182008-09-20 04:14:03 +0300125 void __iomem *base = wdev->base;
Komal Shah7768a132006-09-29 01:59:18 -0700126
Paul Walmsley0503add2011-03-10 22:40:05 -0700127 pm_runtime_get_sync(wdev->dev);
128
Komal Shah7768a132006-09-29 01:59:18 -0700129 /* just count up at 32 KHz */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300130 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x04)
Komal Shah7768a132006-09-29 01:59:18 -0700131 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +0300132
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300133 __raw_writel(pre_margin, base + OMAP_WATCHDOG_LDR);
134 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x04)
Komal Shah7768a132006-09-29 01:59:18 -0700135 cpu_relax();
Paul Walmsley0503add2011-03-10 22:40:05 -0700136
137 pm_runtime_put_sync(wdev->dev);
Komal Shah7768a132006-09-29 01:59:18 -0700138}
139
140/*
141 * Allow only one task to hold it open
142 */
Komal Shah7768a132006-09-29 01:59:18 -0700143static int omap_wdt_open(struct inode *inode, struct file *file)
144{
Felipe Balbib3112182008-09-20 04:14:03 +0300145 struct omap_wdt_dev *wdev = platform_get_drvdata(omap_wdt_dev);
146 void __iomem *base = wdev->base;
147
Felipe Balbi28171422008-09-20 04:14:01 +0300148 if (test_and_set_bit(1, (unsigned long *)&(wdev->omap_wdt_users)))
Komal Shah7768a132006-09-29 01:59:18 -0700149 return -EBUSY;
150
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530151 pm_runtime_get_sync(wdev->dev);
Komal Shah7768a132006-09-29 01:59:18 -0700152
153 /* initialize prescaler */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300154 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x01)
Komal Shah7768a132006-09-29 01:59:18 -0700155 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +0300156
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300157 __raw_writel((1 << 5) | (PTV << 2), base + OMAP_WATCHDOG_CNTRL);
158 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x01)
Komal Shah7768a132006-09-29 01:59:18 -0700159 cpu_relax();
160
Felipe Balbi28171422008-09-20 04:14:01 +0300161 file->private_data = (void *) wdev;
162
163 omap_wdt_set_timeout(wdev);
Ulrik Bech Hald789cd472009-06-12 16:18:32 -0500164 omap_wdt_ping(wdev); /* trigger loading of new timeout value */
Felipe Balbi28171422008-09-20 04:14:01 +0300165 omap_wdt_enable(wdev);
Felipe Balbib3112182008-09-20 04:14:03 +0300166
Paul Walmsley0503add2011-03-10 22:40:05 -0700167 pm_runtime_put_sync(wdev->dev);
168
Wim Van Sebroeckec9505a2007-07-20 20:41:37 +0000169 return nonseekable_open(inode, file);
Komal Shah7768a132006-09-29 01:59:18 -0700170}
171
172static int omap_wdt_release(struct inode *inode, struct file *file)
173{
Felipe Balbib3112182008-09-20 04:14:03 +0300174 struct omap_wdt_dev *wdev = file->private_data;
175
Komal Shah7768a132006-09-29 01:59:18 -0700176 /*
177 * Shut off the timer unless NOWAYOUT is defined.
178 */
179#ifndef CONFIG_WATCHDOG_NOWAYOUT
Paul Walmsley0503add2011-03-10 22:40:05 -0700180 pm_runtime_get_sync(wdev->dev);
Komal Shah7768a132006-09-29 01:59:18 -0700181
Felipe Balbi28171422008-09-20 04:14:01 +0300182 omap_wdt_disable(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700183
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530184 pm_runtime_put_sync(wdev->dev);
Komal Shah7768a132006-09-29 01:59:18 -0700185#else
186 printk(KERN_CRIT "omap_wdt: Unexpected close, not stopping!\n");
187#endif
Felipe Balbi28171422008-09-20 04:14:01 +0300188 wdev->omap_wdt_users = 0;
Felipe Balbib3112182008-09-20 04:14:03 +0300189
Komal Shah7768a132006-09-29 01:59:18 -0700190 return 0;
191}
192
Alan Cox12b9df72008-05-19 14:07:32 +0100193static ssize_t omap_wdt_write(struct file *file, const char __user *data,
Komal Shah7768a132006-09-29 01:59:18 -0700194 size_t len, loff_t *ppos)
195{
Felipe Balbib3112182008-09-20 04:14:03 +0300196 struct omap_wdt_dev *wdev = file->private_data;
197
Komal Shah7768a132006-09-29 01:59:18 -0700198 /* Refresh LOAD_TIME. */
Alan Cox12b9df72008-05-19 14:07:32 +0100199 if (len) {
Paul Walmsley0503add2011-03-10 22:40:05 -0700200 pm_runtime_get_sync(wdev->dev);
Alan Cox12b9df72008-05-19 14:07:32 +0100201 spin_lock(&wdt_lock);
Felipe Balbi28171422008-09-20 04:14:01 +0300202 omap_wdt_ping(wdev);
Alan Cox12b9df72008-05-19 14:07:32 +0100203 spin_unlock(&wdt_lock);
Paul Walmsley0503add2011-03-10 22:40:05 -0700204 pm_runtime_put_sync(wdev->dev);
Alan Cox12b9df72008-05-19 14:07:32 +0100205 }
Komal Shah7768a132006-09-29 01:59:18 -0700206 return len;
207}
208
Alan Cox12b9df72008-05-19 14:07:32 +0100209static long omap_wdt_ioctl(struct file *file, unsigned int cmd,
210 unsigned long arg)
Komal Shah7768a132006-09-29 01:59:18 -0700211{
Felipe Balbi28171422008-09-20 04:14:01 +0300212 struct omap_wdt_dev *wdev;
Komal Shah7768a132006-09-29 01:59:18 -0700213 int new_margin;
Alan Cox12b9df72008-05-19 14:07:32 +0100214 static const struct watchdog_info ident = {
Komal Shah7768a132006-09-29 01:59:18 -0700215 .identity = "OMAP Watchdog",
216 .options = WDIOF_SETTIMEOUT,
217 .firmware_version = 0,
218 };
Felipe Balbib3112182008-09-20 04:14:03 +0300219
Felipe Balbi28171422008-09-20 04:14:01 +0300220 wdev = file->private_data;
Komal Shah7768a132006-09-29 01:59:18 -0700221
222 switch (cmd) {
Komal Shah7768a132006-09-29 01:59:18 -0700223 case WDIOC_GETSUPPORT:
224 return copy_to_user((struct watchdog_info __user *)arg, &ident,
225 sizeof(ident));
226 case WDIOC_GETSTATUS:
227 return put_user(0, (int __user *)arg);
228 case WDIOC_GETBOOTSTATUS:
229 if (cpu_is_omap16xx())
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300230 return put_user(__raw_readw(ARM_SYSST),
Komal Shah7768a132006-09-29 01:59:18 -0700231 (int __user *)arg);
232 if (cpu_is_omap24xx())
233 return put_user(omap_prcm_get_reset_sources(),
234 (int __user *)arg);
235 case WDIOC_KEEPALIVE:
Paul Walmsley0503add2011-03-10 22:40:05 -0700236 pm_runtime_get_sync(wdev->dev);
Alan Cox12b9df72008-05-19 14:07:32 +0100237 spin_lock(&wdt_lock);
Felipe Balbi28171422008-09-20 04:14:01 +0300238 omap_wdt_ping(wdev);
Alan Cox12b9df72008-05-19 14:07:32 +0100239 spin_unlock(&wdt_lock);
Paul Walmsley0503add2011-03-10 22:40:05 -0700240 pm_runtime_put_sync(wdev->dev);
Komal Shah7768a132006-09-29 01:59:18 -0700241 return 0;
242 case WDIOC_SETTIMEOUT:
243 if (get_user(new_margin, (int __user *)arg))
244 return -EFAULT;
245 omap_wdt_adjust_timeout(new_margin);
246
Paul Walmsley0503add2011-03-10 22:40:05 -0700247 pm_runtime_get_sync(wdev->dev);
Alan Cox12b9df72008-05-19 14:07:32 +0100248 spin_lock(&wdt_lock);
Felipe Balbi28171422008-09-20 04:14:01 +0300249 omap_wdt_disable(wdev);
250 omap_wdt_set_timeout(wdev);
251 omap_wdt_enable(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700252
Felipe Balbi28171422008-09-20 04:14:01 +0300253 omap_wdt_ping(wdev);
Alan Cox12b9df72008-05-19 14:07:32 +0100254 spin_unlock(&wdt_lock);
Paul Walmsley0503add2011-03-10 22:40:05 -0700255 pm_runtime_put_sync(wdev->dev);
Komal Shah7768a132006-09-29 01:59:18 -0700256 /* Fall */
257 case WDIOC_GETTIMEOUT:
258 return put_user(timer_margin, (int __user *)arg);
Wim Van Sebroeck0c06090c2008-07-18 11:41:17 +0000259 default:
260 return -ENOTTY;
Komal Shah7768a132006-09-29 01:59:18 -0700261 }
262}
263
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800264static const struct file_operations omap_wdt_fops = {
Komal Shah7768a132006-09-29 01:59:18 -0700265 .owner = THIS_MODULE,
266 .write = omap_wdt_write,
Alan Cox12b9df72008-05-19 14:07:32 +0100267 .unlocked_ioctl = omap_wdt_ioctl,
Komal Shah7768a132006-09-29 01:59:18 -0700268 .open = omap_wdt_open,
269 .release = omap_wdt_release,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200270 .llseek = no_llseek,
Komal Shah7768a132006-09-29 01:59:18 -0700271};
272
Uwe Kleine-König0e3912c2009-03-28 00:26:56 +0100273static int __devinit omap_wdt_probe(struct platform_device *pdev)
Komal Shah7768a132006-09-29 01:59:18 -0700274{
275 struct resource *res, *mem;
Felipe Balbi28171422008-09-20 04:14:01 +0300276 struct omap_wdt_dev *wdev;
Felipe Balbib3112182008-09-20 04:14:03 +0300277 int ret;
Komal Shah7768a132006-09-29 01:59:18 -0700278
279 /* reserve static register mappings */
280 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Felipe Balbib3112182008-09-20 04:14:03 +0300281 if (!res) {
282 ret = -ENOENT;
283 goto err_get_resource;
284 }
Komal Shah7768a132006-09-29 01:59:18 -0700285
Felipe Balbib3112182008-09-20 04:14:03 +0300286 if (omap_wdt_dev) {
287 ret = -EBUSY;
288 goto err_busy;
289 }
Felipe Balbi28171422008-09-20 04:14:01 +0300290
H Hartley Sweetenb782a562009-12-04 12:24:04 -0500291 mem = request_mem_region(res->start, resource_size(res), pdev->name);
Felipe Balbib3112182008-09-20 04:14:03 +0300292 if (!mem) {
293 ret = -EBUSY;
294 goto err_busy;
295 }
Komal Shah7768a132006-09-29 01:59:18 -0700296
Felipe Balbi28171422008-09-20 04:14:01 +0300297 wdev = kzalloc(sizeof(struct omap_wdt_dev), GFP_KERNEL);
298 if (!wdev) {
299 ret = -ENOMEM;
Felipe Balbib3112182008-09-20 04:14:03 +0300300 goto err_kzalloc;
Felipe Balbi28171422008-09-20 04:14:01 +0300301 }
Felipe Balbib3112182008-09-20 04:14:03 +0300302
Felipe Balbi28171422008-09-20 04:14:01 +0300303 wdev->omap_wdt_users = 0;
304 wdev->mem = mem;
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530305 wdev->dev = &pdev->dev;
Komal Shah7768a132006-09-29 01:59:18 -0700306
H Hartley Sweetenb782a562009-12-04 12:24:04 -0500307 wdev->base = ioremap(res->start, resource_size(res));
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300308 if (!wdev->base) {
309 ret = -ENOMEM;
Felipe Balbib3112182008-09-20 04:14:03 +0300310 goto err_ioremap;
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300311 }
312
Felipe Balbi28171422008-09-20 04:14:01 +0300313 platform_set_drvdata(pdev, wdev);
314
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530315 pm_runtime_enable(wdev->dev);
316 pm_runtime_get_sync(wdev->dev);
Ulrik Bech Hald789cd472009-06-12 16:18:32 -0500317
Felipe Balbi28171422008-09-20 04:14:01 +0300318 omap_wdt_disable(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700319 omap_wdt_adjust_timeout(timer_margin);
320
Felipe Balbi28171422008-09-20 04:14:01 +0300321 wdev->omap_wdt_miscdev.parent = &pdev->dev;
322 wdev->omap_wdt_miscdev.minor = WATCHDOG_MINOR;
323 wdev->omap_wdt_miscdev.name = "watchdog";
324 wdev->omap_wdt_miscdev.fops = &omap_wdt_fops;
325
326 ret = misc_register(&(wdev->omap_wdt_miscdev));
Komal Shah7768a132006-09-29 01:59:18 -0700327 if (ret)
Felipe Balbib3112182008-09-20 04:14:03 +0300328 goto err_misc;
Komal Shah7768a132006-09-29 01:59:18 -0700329
Felipe Balbi28171422008-09-20 04:14:01 +0300330 pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec\n",
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300331 __raw_readl(wdev->base + OMAP_WATCHDOG_REV) & 0xFF,
Felipe Balbi28171422008-09-20 04:14:01 +0300332 timer_margin);
Komal Shah7768a132006-09-29 01:59:18 -0700333
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530334 pm_runtime_put_sync(wdev->dev);
Ulrik Bech Hald789cd472009-06-12 16:18:32 -0500335
Felipe Balbi28171422008-09-20 04:14:01 +0300336 omap_wdt_dev = pdev;
337
Komal Shah7768a132006-09-29 01:59:18 -0700338 return 0;
339
Felipe Balbib3112182008-09-20 04:14:03 +0300340err_misc:
341 platform_set_drvdata(pdev, NULL);
342 iounmap(wdev->base);
343
344err_ioremap:
345 wdev->base = NULL;
Felipe Balbib3112182008-09-20 04:14:03 +0300346 kfree(wdev);
347
348err_kzalloc:
H Hartley Sweetenb782a562009-12-04 12:24:04 -0500349 release_mem_region(res->start, resource_size(res));
Felipe Balbib3112182008-09-20 04:14:03 +0300350
351err_busy:
352err_get_resource:
353
Komal Shah7768a132006-09-29 01:59:18 -0700354 return ret;
355}
356
357static void omap_wdt_shutdown(struct platform_device *pdev)
358{
Felipe Balbib3112182008-09-20 04:14:03 +0300359 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
Felipe Balbi28171422008-09-20 04:14:01 +0300360
Paul Walmsley0503add2011-03-10 22:40:05 -0700361 if (wdev->omap_wdt_users) {
362 pm_runtime_get_sync(wdev->dev);
Felipe Balbi28171422008-09-20 04:14:01 +0300363 omap_wdt_disable(wdev);
Paul Walmsley0503add2011-03-10 22:40:05 -0700364 pm_runtime_put_sync(wdev->dev);
365 }
Komal Shah7768a132006-09-29 01:59:18 -0700366}
367
Uwe Kleine-König0e3912c2009-03-28 00:26:56 +0100368static int __devexit omap_wdt_remove(struct platform_device *pdev)
Komal Shah7768a132006-09-29 01:59:18 -0700369{
Felipe Balbib3112182008-09-20 04:14:03 +0300370 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
Felipe Balbi28171422008-09-20 04:14:01 +0300371 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
372
373 if (!res)
374 return -ENOENT;
375
376 misc_deregister(&(wdev->omap_wdt_miscdev));
H Hartley Sweetenb782a562009-12-04 12:24:04 -0500377 release_mem_region(res->start, resource_size(res));
Felipe Balbi28171422008-09-20 04:14:01 +0300378 platform_set_drvdata(pdev, NULL);
Felipe Balbib3112182008-09-20 04:14:03 +0300379
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300380 iounmap(wdev->base);
381
Felipe Balbi28171422008-09-20 04:14:01 +0300382 kfree(wdev);
383 omap_wdt_dev = NULL;
Felipe Balbib3112182008-09-20 04:14:03 +0300384
Komal Shah7768a132006-09-29 01:59:18 -0700385 return 0;
386}
387
388#ifdef CONFIG_PM
389
390/* REVISIT ... not clear this is the best way to handle system suspend; and
391 * it's very inappropriate for selective device suspend (e.g. suspending this
392 * through sysfs rather than by stopping the watchdog daemon). Also, this
393 * may not play well enough with NOWAYOUT...
394 */
395
396static int omap_wdt_suspend(struct platform_device *pdev, pm_message_t state)
397{
Felipe Balbib3112182008-09-20 04:14:03 +0300398 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
399
Paul Walmsley0503add2011-03-10 22:40:05 -0700400 if (wdev->omap_wdt_users) {
401 pm_runtime_get_sync(wdev->dev);
Felipe Balbi28171422008-09-20 04:14:01 +0300402 omap_wdt_disable(wdev);
Paul Walmsley0503add2011-03-10 22:40:05 -0700403 pm_runtime_put_sync(wdev->dev);
404 }
Felipe Balbib3112182008-09-20 04:14:03 +0300405
Komal Shah7768a132006-09-29 01:59:18 -0700406 return 0;
407}
408
409static int omap_wdt_resume(struct platform_device *pdev)
410{
Felipe Balbib3112182008-09-20 04:14:03 +0300411 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
412
Felipe Balbi28171422008-09-20 04:14:01 +0300413 if (wdev->omap_wdt_users) {
Paul Walmsley0503add2011-03-10 22:40:05 -0700414 pm_runtime_get_sync(wdev->dev);
Felipe Balbi28171422008-09-20 04:14:01 +0300415 omap_wdt_enable(wdev);
416 omap_wdt_ping(wdev);
Paul Walmsley0503add2011-03-10 22:40:05 -0700417 pm_runtime_put_sync(wdev->dev);
Komal Shah7768a132006-09-29 01:59:18 -0700418 }
Felipe Balbib3112182008-09-20 04:14:03 +0300419
Komal Shah7768a132006-09-29 01:59:18 -0700420 return 0;
421}
422
423#else
424#define omap_wdt_suspend NULL
425#define omap_wdt_resume NULL
426#endif
427
428static struct platform_driver omap_wdt_driver = {
429 .probe = omap_wdt_probe,
Uwe Kleine-König0e3912c2009-03-28 00:26:56 +0100430 .remove = __devexit_p(omap_wdt_remove),
Komal Shah7768a132006-09-29 01:59:18 -0700431 .shutdown = omap_wdt_shutdown,
432 .suspend = omap_wdt_suspend,
433 .resume = omap_wdt_resume,
434 .driver = {
435 .owner = THIS_MODULE,
436 .name = "omap_wdt",
437 },
438};
439
440static int __init omap_wdt_init(void)
441{
Alan Cox12b9df72008-05-19 14:07:32 +0100442 spin_lock_init(&wdt_lock);
Komal Shah7768a132006-09-29 01:59:18 -0700443 return platform_driver_register(&omap_wdt_driver);
444}
445
446static void __exit omap_wdt_exit(void)
447{
448 platform_driver_unregister(&omap_wdt_driver);
449}
450
451module_init(omap_wdt_init);
452module_exit(omap_wdt_exit);
453
454MODULE_AUTHOR("George G. Davis");
455MODULE_LICENSE("GPL");
456MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
Kay Sieversf37d1932008-04-10 21:29:23 -0700457MODULE_ALIAS("platform:omap_wdt");