blob: 3dd4971160ef3efb6e3c485ef94af38641f16bdf [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
127 /* just count up at 32 KHz */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300128 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x04)
Komal Shah7768a132006-09-29 01:59:18 -0700129 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +0300130
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300131 __raw_writel(pre_margin, base + OMAP_WATCHDOG_LDR);
132 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x04)
Komal Shah7768a132006-09-29 01:59:18 -0700133 cpu_relax();
134}
135
136/*
137 * Allow only one task to hold it open
138 */
Komal Shah7768a132006-09-29 01:59:18 -0700139static int omap_wdt_open(struct inode *inode, struct file *file)
140{
Felipe Balbib3112182008-09-20 04:14:03 +0300141 struct omap_wdt_dev *wdev = platform_get_drvdata(omap_wdt_dev);
142 void __iomem *base = wdev->base;
143
Felipe Balbi28171422008-09-20 04:14:01 +0300144 if (test_and_set_bit(1, (unsigned long *)&(wdev->omap_wdt_users)))
Komal Shah7768a132006-09-29 01:59:18 -0700145 return -EBUSY;
146
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530147 pm_runtime_get_sync(wdev->dev);
Komal Shah7768a132006-09-29 01:59:18 -0700148
149 /* initialize prescaler */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300150 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x01)
Komal Shah7768a132006-09-29 01:59:18 -0700151 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +0300152
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300153 __raw_writel((1 << 5) | (PTV << 2), base + OMAP_WATCHDOG_CNTRL);
154 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x01)
Komal Shah7768a132006-09-29 01:59:18 -0700155 cpu_relax();
156
Felipe Balbi28171422008-09-20 04:14:01 +0300157 file->private_data = (void *) wdev;
158
159 omap_wdt_set_timeout(wdev);
Ulrik Bech Hald789cd472009-06-12 16:18:32 -0500160 omap_wdt_ping(wdev); /* trigger loading of new timeout value */
Felipe Balbi28171422008-09-20 04:14:01 +0300161 omap_wdt_enable(wdev);
Felipe Balbib3112182008-09-20 04:14:03 +0300162
Wim Van Sebroeckec9505a2007-07-20 20:41:37 +0000163 return nonseekable_open(inode, file);
Komal Shah7768a132006-09-29 01:59:18 -0700164}
165
166static int omap_wdt_release(struct inode *inode, struct file *file)
167{
Felipe Balbib3112182008-09-20 04:14:03 +0300168 struct omap_wdt_dev *wdev = file->private_data;
169
Komal Shah7768a132006-09-29 01:59:18 -0700170 /*
171 * Shut off the timer unless NOWAYOUT is defined.
172 */
173#ifndef CONFIG_WATCHDOG_NOWAYOUT
Komal Shah7768a132006-09-29 01:59:18 -0700174
Felipe Balbi28171422008-09-20 04:14:01 +0300175 omap_wdt_disable(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700176
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530177 pm_runtime_put_sync(wdev->dev);
Komal Shah7768a132006-09-29 01:59:18 -0700178#else
179 printk(KERN_CRIT "omap_wdt: Unexpected close, not stopping!\n");
180#endif
Felipe Balbi28171422008-09-20 04:14:01 +0300181 wdev->omap_wdt_users = 0;
Felipe Balbib3112182008-09-20 04:14:03 +0300182
Komal Shah7768a132006-09-29 01:59:18 -0700183 return 0;
184}
185
Alan Cox12b9df72008-05-19 14:07:32 +0100186static ssize_t omap_wdt_write(struct file *file, const char __user *data,
Komal Shah7768a132006-09-29 01:59:18 -0700187 size_t len, loff_t *ppos)
188{
Felipe Balbib3112182008-09-20 04:14:03 +0300189 struct omap_wdt_dev *wdev = file->private_data;
190
Komal Shah7768a132006-09-29 01:59:18 -0700191 /* Refresh LOAD_TIME. */
Alan Cox12b9df72008-05-19 14:07:32 +0100192 if (len) {
193 spin_lock(&wdt_lock);
Felipe Balbi28171422008-09-20 04:14:01 +0300194 omap_wdt_ping(wdev);
Alan Cox12b9df72008-05-19 14:07:32 +0100195 spin_unlock(&wdt_lock);
196 }
Komal Shah7768a132006-09-29 01:59:18 -0700197 return len;
198}
199
Alan Cox12b9df72008-05-19 14:07:32 +0100200static long omap_wdt_ioctl(struct file *file, unsigned int cmd,
201 unsigned long arg)
Komal Shah7768a132006-09-29 01:59:18 -0700202{
Felipe Balbi28171422008-09-20 04:14:01 +0300203 struct omap_wdt_dev *wdev;
Komal Shah7768a132006-09-29 01:59:18 -0700204 int new_margin;
Alan Cox12b9df72008-05-19 14:07:32 +0100205 static const struct watchdog_info ident = {
Komal Shah7768a132006-09-29 01:59:18 -0700206 .identity = "OMAP Watchdog",
207 .options = WDIOF_SETTIMEOUT,
208 .firmware_version = 0,
209 };
Felipe Balbib3112182008-09-20 04:14:03 +0300210
Felipe Balbi28171422008-09-20 04:14:01 +0300211 wdev = file->private_data;
Komal Shah7768a132006-09-29 01:59:18 -0700212
213 switch (cmd) {
Komal Shah7768a132006-09-29 01:59:18 -0700214 case WDIOC_GETSUPPORT:
215 return copy_to_user((struct watchdog_info __user *)arg, &ident,
216 sizeof(ident));
217 case WDIOC_GETSTATUS:
218 return put_user(0, (int __user *)arg);
219 case WDIOC_GETBOOTSTATUS:
220 if (cpu_is_omap16xx())
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300221 return put_user(__raw_readw(ARM_SYSST),
Komal Shah7768a132006-09-29 01:59:18 -0700222 (int __user *)arg);
223 if (cpu_is_omap24xx())
224 return put_user(omap_prcm_get_reset_sources(),
225 (int __user *)arg);
226 case WDIOC_KEEPALIVE:
Alan Cox12b9df72008-05-19 14:07:32 +0100227 spin_lock(&wdt_lock);
Felipe Balbi28171422008-09-20 04:14:01 +0300228 omap_wdt_ping(wdev);
Alan Cox12b9df72008-05-19 14:07:32 +0100229 spin_unlock(&wdt_lock);
Komal Shah7768a132006-09-29 01:59:18 -0700230 return 0;
231 case WDIOC_SETTIMEOUT:
232 if (get_user(new_margin, (int __user *)arg))
233 return -EFAULT;
234 omap_wdt_adjust_timeout(new_margin);
235
Alan Cox12b9df72008-05-19 14:07:32 +0100236 spin_lock(&wdt_lock);
Felipe Balbi28171422008-09-20 04:14:01 +0300237 omap_wdt_disable(wdev);
238 omap_wdt_set_timeout(wdev);
239 omap_wdt_enable(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700240
Felipe Balbi28171422008-09-20 04:14:01 +0300241 omap_wdt_ping(wdev);
Alan Cox12b9df72008-05-19 14:07:32 +0100242 spin_unlock(&wdt_lock);
Komal Shah7768a132006-09-29 01:59:18 -0700243 /* Fall */
244 case WDIOC_GETTIMEOUT:
245 return put_user(timer_margin, (int __user *)arg);
Wim Van Sebroeck0c06090c2008-07-18 11:41:17 +0000246 default:
247 return -ENOTTY;
Komal Shah7768a132006-09-29 01:59:18 -0700248 }
249}
250
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800251static const struct file_operations omap_wdt_fops = {
Komal Shah7768a132006-09-29 01:59:18 -0700252 .owner = THIS_MODULE,
253 .write = omap_wdt_write,
Alan Cox12b9df72008-05-19 14:07:32 +0100254 .unlocked_ioctl = omap_wdt_ioctl,
Komal Shah7768a132006-09-29 01:59:18 -0700255 .open = omap_wdt_open,
256 .release = omap_wdt_release,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200257 .llseek = no_llseek,
Komal Shah7768a132006-09-29 01:59:18 -0700258};
259
Uwe Kleine-König0e3912c2009-03-28 00:26:56 +0100260static int __devinit omap_wdt_probe(struct platform_device *pdev)
Komal Shah7768a132006-09-29 01:59:18 -0700261{
262 struct resource *res, *mem;
Felipe Balbi28171422008-09-20 04:14:01 +0300263 struct omap_wdt_dev *wdev;
Felipe Balbib3112182008-09-20 04:14:03 +0300264 int ret;
Komal Shah7768a132006-09-29 01:59:18 -0700265
266 /* reserve static register mappings */
267 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Felipe Balbib3112182008-09-20 04:14:03 +0300268 if (!res) {
269 ret = -ENOENT;
270 goto err_get_resource;
271 }
Komal Shah7768a132006-09-29 01:59:18 -0700272
Felipe Balbib3112182008-09-20 04:14:03 +0300273 if (omap_wdt_dev) {
274 ret = -EBUSY;
275 goto err_busy;
276 }
Felipe Balbi28171422008-09-20 04:14:01 +0300277
H Hartley Sweetenb782a562009-12-04 12:24:04 -0500278 mem = request_mem_region(res->start, resource_size(res), pdev->name);
Felipe Balbib3112182008-09-20 04:14:03 +0300279 if (!mem) {
280 ret = -EBUSY;
281 goto err_busy;
282 }
Komal Shah7768a132006-09-29 01:59:18 -0700283
Felipe Balbi28171422008-09-20 04:14:01 +0300284 wdev = kzalloc(sizeof(struct omap_wdt_dev), GFP_KERNEL);
285 if (!wdev) {
286 ret = -ENOMEM;
Felipe Balbib3112182008-09-20 04:14:03 +0300287 goto err_kzalloc;
Felipe Balbi28171422008-09-20 04:14:01 +0300288 }
Felipe Balbib3112182008-09-20 04:14:03 +0300289
Felipe Balbi28171422008-09-20 04:14:01 +0300290 wdev->omap_wdt_users = 0;
291 wdev->mem = mem;
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530292 wdev->dev = &pdev->dev;
Komal Shah7768a132006-09-29 01:59:18 -0700293
H Hartley Sweetenb782a562009-12-04 12:24:04 -0500294 wdev->base = ioremap(res->start, resource_size(res));
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300295 if (!wdev->base) {
296 ret = -ENOMEM;
Felipe Balbib3112182008-09-20 04:14:03 +0300297 goto err_ioremap;
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300298 }
299
Felipe Balbi28171422008-09-20 04:14:01 +0300300 platform_set_drvdata(pdev, wdev);
301
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530302 pm_runtime_enable(wdev->dev);
303 pm_runtime_get_sync(wdev->dev);
Ulrik Bech Hald789cd472009-06-12 16:18:32 -0500304
Felipe Balbi28171422008-09-20 04:14:01 +0300305 omap_wdt_disable(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700306 omap_wdt_adjust_timeout(timer_margin);
307
Felipe Balbi28171422008-09-20 04:14:01 +0300308 wdev->omap_wdt_miscdev.parent = &pdev->dev;
309 wdev->omap_wdt_miscdev.minor = WATCHDOG_MINOR;
310 wdev->omap_wdt_miscdev.name = "watchdog";
311 wdev->omap_wdt_miscdev.fops = &omap_wdt_fops;
312
313 ret = misc_register(&(wdev->omap_wdt_miscdev));
Komal Shah7768a132006-09-29 01:59:18 -0700314 if (ret)
Felipe Balbib3112182008-09-20 04:14:03 +0300315 goto err_misc;
Komal Shah7768a132006-09-29 01:59:18 -0700316
Felipe Balbi28171422008-09-20 04:14:01 +0300317 pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec\n",
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300318 __raw_readl(wdev->base + OMAP_WATCHDOG_REV) & 0xFF,
Felipe Balbi28171422008-09-20 04:14:01 +0300319 timer_margin);
Komal Shah7768a132006-09-29 01:59:18 -0700320
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530321 pm_runtime_put_sync(wdev->dev);
Ulrik Bech Hald789cd472009-06-12 16:18:32 -0500322
Felipe Balbi28171422008-09-20 04:14:01 +0300323 omap_wdt_dev = pdev;
324
Komal Shah7768a132006-09-29 01:59:18 -0700325 return 0;
326
Felipe Balbib3112182008-09-20 04:14:03 +0300327err_misc:
328 platform_set_drvdata(pdev, NULL);
329 iounmap(wdev->base);
330
331err_ioremap:
332 wdev->base = NULL;
Felipe Balbib3112182008-09-20 04:14:03 +0300333 kfree(wdev);
334
335err_kzalloc:
H Hartley Sweetenb782a562009-12-04 12:24:04 -0500336 release_mem_region(res->start, resource_size(res));
Felipe Balbib3112182008-09-20 04:14:03 +0300337
338err_busy:
339err_get_resource:
340
Komal Shah7768a132006-09-29 01:59:18 -0700341 return ret;
342}
343
344static void omap_wdt_shutdown(struct platform_device *pdev)
345{
Felipe Balbib3112182008-09-20 04:14:03 +0300346 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
Felipe Balbi28171422008-09-20 04:14:01 +0300347
348 if (wdev->omap_wdt_users)
349 omap_wdt_disable(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700350}
351
Uwe Kleine-König0e3912c2009-03-28 00:26:56 +0100352static int __devexit omap_wdt_remove(struct platform_device *pdev)
Komal Shah7768a132006-09-29 01:59:18 -0700353{
Felipe Balbib3112182008-09-20 04:14:03 +0300354 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
Felipe Balbi28171422008-09-20 04:14:01 +0300355 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
356
357 if (!res)
358 return -ENOENT;
359
360 misc_deregister(&(wdev->omap_wdt_miscdev));
H Hartley Sweetenb782a562009-12-04 12:24:04 -0500361 release_mem_region(res->start, resource_size(res));
Felipe Balbi28171422008-09-20 04:14:01 +0300362 platform_set_drvdata(pdev, NULL);
Felipe Balbib3112182008-09-20 04:14:03 +0300363
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300364 iounmap(wdev->base);
365
Felipe Balbi28171422008-09-20 04:14:01 +0300366 kfree(wdev);
367 omap_wdt_dev = NULL;
Felipe Balbib3112182008-09-20 04:14:03 +0300368
Komal Shah7768a132006-09-29 01:59:18 -0700369 return 0;
370}
371
372#ifdef CONFIG_PM
373
374/* REVISIT ... not clear this is the best way to handle system suspend; and
375 * it's very inappropriate for selective device suspend (e.g. suspending this
376 * through sysfs rather than by stopping the watchdog daemon). Also, this
377 * may not play well enough with NOWAYOUT...
378 */
379
380static int omap_wdt_suspend(struct platform_device *pdev, pm_message_t state)
381{
Felipe Balbib3112182008-09-20 04:14:03 +0300382 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
383
Felipe Balbi28171422008-09-20 04:14:01 +0300384 if (wdev->omap_wdt_users)
385 omap_wdt_disable(wdev);
Felipe Balbib3112182008-09-20 04:14:03 +0300386
Komal Shah7768a132006-09-29 01:59:18 -0700387 return 0;
388}
389
390static int omap_wdt_resume(struct platform_device *pdev)
391{
Felipe Balbib3112182008-09-20 04:14:03 +0300392 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
393
Felipe Balbi28171422008-09-20 04:14:01 +0300394 if (wdev->omap_wdt_users) {
395 omap_wdt_enable(wdev);
396 omap_wdt_ping(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700397 }
Felipe Balbib3112182008-09-20 04:14:03 +0300398
Komal Shah7768a132006-09-29 01:59:18 -0700399 return 0;
400}
401
402#else
403#define omap_wdt_suspend NULL
404#define omap_wdt_resume NULL
405#endif
406
407static struct platform_driver omap_wdt_driver = {
408 .probe = omap_wdt_probe,
Uwe Kleine-König0e3912c2009-03-28 00:26:56 +0100409 .remove = __devexit_p(omap_wdt_remove),
Komal Shah7768a132006-09-29 01:59:18 -0700410 .shutdown = omap_wdt_shutdown,
411 .suspend = omap_wdt_suspend,
412 .resume = omap_wdt_resume,
413 .driver = {
414 .owner = THIS_MODULE,
415 .name = "omap_wdt",
416 },
417};
418
419static int __init omap_wdt_init(void)
420{
Alan Cox12b9df72008-05-19 14:07:32 +0100421 spin_lock_init(&wdt_lock);
Komal Shah7768a132006-09-29 01:59:18 -0700422 return platform_driver_register(&omap_wdt_driver);
423}
424
425static void __exit omap_wdt_exit(void)
426{
427 platform_driver_unregister(&omap_wdt_driver);
428}
429
430module_init(omap_wdt_init);
431module_exit(omap_wdt_exit);
432
433MODULE_AUTHOR("George G. Davis");
434MODULE_LICENSE("GPL");
435MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
Kay Sieversf37d1932008-04-10 21:29:23 -0700436MODULE_ALIAS("platform:omap_wdt");