blob: 9c389b16497f5ae6cda95229e00ea6c481b65464 [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>
19 * Based on SoftDog driver by Alan Cox <alan@redhat.com>
20 *
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>
41#include <linux/clk.h>
Jiri Slaby1977f032007-10-18 23:40:25 -070042#include <linux/bitops.h>
Wim Van Sebroeck089ab072008-07-15 11:46:11 +000043#include <linux/io.h>
Alan Cox12b9df72008-05-19 14:07:32 +010044#include <linux/uaccess.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010045#include <mach/hardware.h>
Russell Kinga09e64f2008-08-05 16:14:15 +010046#include <mach/prcm.h>
Komal Shah7768a132006-09-29 01:59:18 -070047
48#include "omap_wdt.h"
49
Felipe Balbi28171422008-09-20 04:14:01 +030050static struct platform_device *omap_wdt_dev;
51
Komal Shah7768a132006-09-29 01:59:18 -070052static unsigned timer_margin;
53module_param(timer_margin, uint, 0);
54MODULE_PARM_DESC(timer_margin, "initial watchdog timeout (in seconds)");
55
Komal Shah7768a132006-09-29 01:59:18 -070056static unsigned int wdt_trgr_pattern = 0x1234;
Alan Cox12b9df72008-05-19 14:07:32 +010057static spinlock_t wdt_lock;
Komal Shah7768a132006-09-29 01:59:18 -070058
Felipe Balbi28171422008-09-20 04:14:01 +030059struct omap_wdt_dev {
60 void __iomem *base; /* physical */
61 struct device *dev;
62 int omap_wdt_users;
63 struct clk *armwdt_ck;
64 struct clk *mpu_wdt_ick;
65 struct clk *mpu_wdt_fck;
66 struct resource *mem;
67 struct miscdevice omap_wdt_miscdev;
68};
69
70static void omap_wdt_ping(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -070071{
Felipe Balbi28171422008-09-20 04:14:01 +030072 void __iomem *base = wdev->base;
Komal Shah7768a132006-09-29 01:59:18 -070073 /* wait for posted write to complete */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +030074 while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x08)
Komal Shah7768a132006-09-29 01:59:18 -070075 cpu_relax();
76 wdt_trgr_pattern = ~wdt_trgr_pattern;
Felipe Balbi9f69e3b2008-09-20 04:14:02 +030077 __raw_writel(wdt_trgr_pattern, (base + OMAP_WATCHDOG_TGR));
Komal Shah7768a132006-09-29 01:59:18 -070078 /* wait for posted write to complete */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +030079 while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x08)
Komal Shah7768a132006-09-29 01:59:18 -070080 cpu_relax();
81 /* reloaded WCRR from WLDR */
82}
83
Felipe Balbi28171422008-09-20 04:14:01 +030084static void omap_wdt_enable(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -070085{
Felipe Balbi28171422008-09-20 04:14:01 +030086 void __iomem *base;
87 base = wdev->base;
Komal Shah7768a132006-09-29 01:59:18 -070088 /* Sequence to enable the watchdog */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +030089 __raw_writel(0xBBBB, base + OMAP_WATCHDOG_SPR);
90 while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -070091 cpu_relax();
Felipe Balbi9f69e3b2008-09-20 04:14:02 +030092 __raw_writel(0x4444, base + OMAP_WATCHDOG_SPR);
93 while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -070094 cpu_relax();
95}
96
Felipe Balbi28171422008-09-20 04:14:01 +030097static void omap_wdt_disable(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -070098{
Felipe Balbi28171422008-09-20 04:14:01 +030099 void __iomem *base;
100 base = wdev->base;
Komal Shah7768a132006-09-29 01:59:18 -0700101 /* sequence required to disable watchdog */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300102 __raw_writel(0xAAAA, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
103 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -0700104 cpu_relax();
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300105 __raw_writel(0x5555, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
106 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -0700107 cpu_relax();
108}
109
110static void omap_wdt_adjust_timeout(unsigned new_timeout)
111{
112 if (new_timeout < TIMER_MARGIN_MIN)
113 new_timeout = TIMER_MARGIN_DEFAULT;
114 if (new_timeout > TIMER_MARGIN_MAX)
115 new_timeout = TIMER_MARGIN_MAX;
116 timer_margin = new_timeout;
117}
118
Felipe Balbi28171422008-09-20 04:14:01 +0300119static void omap_wdt_set_timeout(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -0700120{
121 u32 pre_margin = GET_WLDR_VAL(timer_margin);
Felipe Balbi28171422008-09-20 04:14:01 +0300122 void __iomem *base;
123 base = wdev->base;
Komal Shah7768a132006-09-29 01:59:18 -0700124
125 /* just count up at 32 KHz */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300126 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x04)
Komal Shah7768a132006-09-29 01:59:18 -0700127 cpu_relax();
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300128 __raw_writel(pre_margin, base + OMAP_WATCHDOG_LDR);
129 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x04)
Komal Shah7768a132006-09-29 01:59:18 -0700130 cpu_relax();
131}
132
133/*
134 * Allow only one task to hold it open
135 */
136
137static int omap_wdt_open(struct inode *inode, struct file *file)
138{
Felipe Balbi28171422008-09-20 04:14:01 +0300139 struct omap_wdt_dev *wdev;
140 void __iomem *base;
141 wdev = platform_get_drvdata(omap_wdt_dev);
142 base = wdev->base;
143 if (test_and_set_bit(1, (unsigned long *)&(wdev->omap_wdt_users)))
Komal Shah7768a132006-09-29 01:59:18 -0700144 return -EBUSY;
145
146 if (cpu_is_omap16xx())
Felipe Balbi28171422008-09-20 04:14:01 +0300147 clk_enable(wdev->armwdt_ck); /* Enable the clock */
Komal Shah7768a132006-09-29 01:59:18 -0700148
Felipe Balbi28171422008-09-20 04:14:01 +0300149 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
150 clk_enable(wdev->mpu_wdt_ick); /* Enable the interface clock */
151 clk_enable(wdev->mpu_wdt_fck); /* Enable the functional clock */
Komal Shah7768a132006-09-29 01:59:18 -0700152 }
153
154 /* initialize prescaler */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300155 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x01)
Komal Shah7768a132006-09-29 01:59:18 -0700156 cpu_relax();
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);
164 omap_wdt_enable(wdev);
Wim Van Sebroeckec9505a2007-07-20 20:41:37 +0000165 return nonseekable_open(inode, file);
Komal Shah7768a132006-09-29 01:59:18 -0700166}
167
168static int omap_wdt_release(struct inode *inode, struct file *file)
169{
Felipe Balbi28171422008-09-20 04:14:01 +0300170 struct omap_wdt_dev *wdev;
171 wdev = file->private_data;
Komal Shah7768a132006-09-29 01:59:18 -0700172 /*
173 * Shut off the timer unless NOWAYOUT is defined.
174 */
175#ifndef CONFIG_WATCHDOG_NOWAYOUT
Komal Shah7768a132006-09-29 01:59:18 -0700176
Felipe Balbi28171422008-09-20 04:14:01 +0300177 omap_wdt_disable(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700178
Felipe Balbi28171422008-09-20 04:14:01 +0300179 if (cpu_is_omap16xx())
180 clk_disable(wdev->armwdt_ck); /* Disable the clock */
181
182 if (cpu_is_omap24xx() || cpu_is_omap34xx()) {
183 clk_disable(wdev->mpu_wdt_ick); /* Disable the clock */
184 clk_disable(wdev->mpu_wdt_fck); /* Disable the clock */
Komal Shah7768a132006-09-29 01:59:18 -0700185 }
186#else
187 printk(KERN_CRIT "omap_wdt: Unexpected close, not stopping!\n");
188#endif
Felipe Balbi28171422008-09-20 04:14:01 +0300189 wdev->omap_wdt_users = 0;
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 Balbi28171422008-09-20 04:14:01 +0300196 struct omap_wdt_dev *wdev;
197 wdev = file->private_data;
Komal Shah7768a132006-09-29 01:59:18 -0700198 /* Refresh LOAD_TIME. */
Alan Cox12b9df72008-05-19 14:07:32 +0100199 if (len) {
200 spin_lock(&wdt_lock);
Felipe Balbi28171422008-09-20 04:14:01 +0300201 omap_wdt_ping(wdev);
Alan Cox12b9df72008-05-19 14:07:32 +0100202 spin_unlock(&wdt_lock);
203 }
Komal Shah7768a132006-09-29 01:59:18 -0700204 return len;
205}
206
Alan Cox12b9df72008-05-19 14:07:32 +0100207static long omap_wdt_ioctl(struct file *file, unsigned int cmd,
208 unsigned long arg)
Komal Shah7768a132006-09-29 01:59:18 -0700209{
Felipe Balbi28171422008-09-20 04:14:01 +0300210 struct omap_wdt_dev *wdev;
Komal Shah7768a132006-09-29 01:59:18 -0700211 int new_margin;
Alan Cox12b9df72008-05-19 14:07:32 +0100212 static const struct watchdog_info ident = {
Komal Shah7768a132006-09-29 01:59:18 -0700213 .identity = "OMAP Watchdog",
214 .options = WDIOF_SETTIMEOUT,
215 .firmware_version = 0,
216 };
Felipe Balbi28171422008-09-20 04:14:01 +0300217 wdev = file->private_data;
Komal Shah7768a132006-09-29 01:59:18 -0700218
219 switch (cmd) {
Komal Shah7768a132006-09-29 01:59:18 -0700220 case WDIOC_GETSUPPORT:
221 return copy_to_user((struct watchdog_info __user *)arg, &ident,
222 sizeof(ident));
223 case WDIOC_GETSTATUS:
224 return put_user(0, (int __user *)arg);
225 case WDIOC_GETBOOTSTATUS:
226 if (cpu_is_omap16xx())
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300227 return put_user(__raw_readw(ARM_SYSST),
Komal Shah7768a132006-09-29 01:59:18 -0700228 (int __user *)arg);
229 if (cpu_is_omap24xx())
230 return put_user(omap_prcm_get_reset_sources(),
231 (int __user *)arg);
232 case WDIOC_KEEPALIVE:
Alan Cox12b9df72008-05-19 14:07:32 +0100233 spin_lock(&wdt_lock);
Felipe Balbi28171422008-09-20 04:14:01 +0300234 omap_wdt_ping(wdev);
Alan Cox12b9df72008-05-19 14:07:32 +0100235 spin_unlock(&wdt_lock);
Komal Shah7768a132006-09-29 01:59:18 -0700236 return 0;
237 case WDIOC_SETTIMEOUT:
238 if (get_user(new_margin, (int __user *)arg))
239 return -EFAULT;
240 omap_wdt_adjust_timeout(new_margin);
241
Alan Cox12b9df72008-05-19 14:07:32 +0100242 spin_lock(&wdt_lock);
Felipe Balbi28171422008-09-20 04:14:01 +0300243 omap_wdt_disable(wdev);
244 omap_wdt_set_timeout(wdev);
245 omap_wdt_enable(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700246
Felipe Balbi28171422008-09-20 04:14:01 +0300247 omap_wdt_ping(wdev);
Alan Cox12b9df72008-05-19 14:07:32 +0100248 spin_unlock(&wdt_lock);
Komal Shah7768a132006-09-29 01:59:18 -0700249 /* Fall */
250 case WDIOC_GETTIMEOUT:
251 return put_user(timer_margin, (int __user *)arg);
Wim Van Sebroeck0c060902008-07-18 11:41:17 +0000252 default:
253 return -ENOTTY;
Komal Shah7768a132006-09-29 01:59:18 -0700254 }
255}
256
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800257static const struct file_operations omap_wdt_fops = {
Komal Shah7768a132006-09-29 01:59:18 -0700258 .owner = THIS_MODULE,
259 .write = omap_wdt_write,
Alan Cox12b9df72008-05-19 14:07:32 +0100260 .unlocked_ioctl = omap_wdt_ioctl,
Komal Shah7768a132006-09-29 01:59:18 -0700261 .open = omap_wdt_open,
262 .release = omap_wdt_release,
263};
264
Komal Shah7768a132006-09-29 01:59:18 -0700265
266static int __init omap_wdt_probe(struct platform_device *pdev)
267{
268 struct resource *res, *mem;
269 int ret;
Felipe Balbi28171422008-09-20 04:14:01 +0300270 struct omap_wdt_dev *wdev;
Komal Shah7768a132006-09-29 01:59:18 -0700271
272 /* reserve static register mappings */
273 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
274 if (!res)
275 return -ENOENT;
276
Felipe Balbi28171422008-09-20 04:14:01 +0300277 if (omap_wdt_dev)
278 return -EBUSY;
279
Komal Shah7768a132006-09-29 01:59:18 -0700280 mem = request_mem_region(res->start, res->end - res->start + 1,
281 pdev->name);
282 if (mem == NULL)
283 return -EBUSY;
284
Felipe Balbi28171422008-09-20 04:14:01 +0300285 wdev = kzalloc(sizeof(struct omap_wdt_dev), GFP_KERNEL);
286 if (!wdev) {
287 ret = -ENOMEM;
288 goto fail;
289 }
290 wdev->omap_wdt_users = 0;
291 wdev->mem = mem;
Komal Shah7768a132006-09-29 01:59:18 -0700292
293 if (cpu_is_omap16xx()) {
Felipe Balbi28171422008-09-20 04:14:01 +0300294 wdev->armwdt_ck = clk_get(&pdev->dev, "armwdt_ck");
295 if (IS_ERR(wdev->armwdt_ck)) {
296 ret = PTR_ERR(wdev->armwdt_ck);
297 wdev->armwdt_ck = NULL;
Komal Shah7768a132006-09-29 01:59:18 -0700298 goto fail;
299 }
300 }
301
302 if (cpu_is_omap24xx()) {
Felipe Balbi28171422008-09-20 04:14:01 +0300303 wdev->mpu_wdt_ick = clk_get(&pdev->dev, "mpu_wdt_ick");
304 if (IS_ERR(wdev->mpu_wdt_ick)) {
305 ret = PTR_ERR(wdev->mpu_wdt_ick);
306 wdev->mpu_wdt_ick = NULL;
Komal Shah7768a132006-09-29 01:59:18 -0700307 goto fail;
308 }
Felipe Balbi28171422008-09-20 04:14:01 +0300309 wdev->mpu_wdt_fck = clk_get(&pdev->dev, "mpu_wdt_fck");
310 if (IS_ERR(wdev->mpu_wdt_fck)) {
311 ret = PTR_ERR(wdev->mpu_wdt_fck);
312 wdev->mpu_wdt_fck = NULL;
Komal Shah7768a132006-09-29 01:59:18 -0700313 goto fail;
314 }
315 }
316
Felipe Balbi28171422008-09-20 04:14:01 +0300317 if (cpu_is_omap34xx()) {
318 wdev->mpu_wdt_ick = clk_get(&pdev->dev, "wdt2_ick");
319 if (IS_ERR(wdev->mpu_wdt_ick)) {
320 ret = PTR_ERR(wdev->mpu_wdt_ick);
321 wdev->mpu_wdt_ick = NULL;
322 goto fail;
323 }
324 wdev->mpu_wdt_fck = clk_get(&pdev->dev, "wdt2_fck");
325 if (IS_ERR(wdev->mpu_wdt_fck)) {
326 ret = PTR_ERR(wdev->mpu_wdt_fck);
327 wdev->mpu_wdt_fck = NULL;
328 goto fail;
329 }
330 }
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300331 wdev->base = ioremap(res->start, res->end - res->start + 1);
332 if (!wdev->base) {
333 ret = -ENOMEM;
334 goto fail;
335 }
336
Felipe Balbi28171422008-09-20 04:14:01 +0300337 platform_set_drvdata(pdev, wdev);
338
339 omap_wdt_disable(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700340 omap_wdt_adjust_timeout(timer_margin);
341
Felipe Balbi28171422008-09-20 04:14:01 +0300342 wdev->omap_wdt_miscdev.parent = &pdev->dev;
343 wdev->omap_wdt_miscdev.minor = WATCHDOG_MINOR;
344 wdev->omap_wdt_miscdev.name = "watchdog";
345 wdev->omap_wdt_miscdev.fops = &omap_wdt_fops;
346
347 ret = misc_register(&(wdev->omap_wdt_miscdev));
Komal Shah7768a132006-09-29 01:59:18 -0700348 if (ret)
349 goto fail;
350
Felipe Balbi28171422008-09-20 04:14:01 +0300351 pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec\n",
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300352 __raw_readl(wdev->base + OMAP_WATCHDOG_REV) & 0xFF,
Felipe Balbi28171422008-09-20 04:14:01 +0300353 timer_margin);
Komal Shah7768a132006-09-29 01:59:18 -0700354
355 /* autogate OCP interface clock */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300356 __raw_writel(0x01, wdev->base + OMAP_WATCHDOG_SYS_CONFIG);
Felipe Balbi28171422008-09-20 04:14:01 +0300357
358 omap_wdt_dev = pdev;
359
Komal Shah7768a132006-09-29 01:59:18 -0700360 return 0;
361
362fail:
Felipe Balbi28171422008-09-20 04:14:01 +0300363 if (wdev) {
364 platform_set_drvdata(pdev, NULL);
365 if (wdev->armwdt_ck)
366 clk_put(wdev->armwdt_ck);
367 if (wdev->mpu_wdt_ick)
368 clk_put(wdev->mpu_wdt_ick);
369 if (wdev->mpu_wdt_fck)
370 clk_put(wdev->mpu_wdt_fck);
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300371 iounmap(wdev->base);
Felipe Balbi28171422008-09-20 04:14:01 +0300372 kfree(wdev);
373 }
374 if (mem) {
375 release_mem_region(res->start, res->end - res->start + 1);
376 }
Komal Shah7768a132006-09-29 01:59:18 -0700377 return ret;
378}
379
380static void omap_wdt_shutdown(struct platform_device *pdev)
381{
Felipe Balbi28171422008-09-20 04:14:01 +0300382 struct omap_wdt_dev *wdev;
383 wdev = platform_get_drvdata(pdev);
384
385 if (wdev->omap_wdt_users)
386 omap_wdt_disable(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700387}
388
389static int omap_wdt_remove(struct platform_device *pdev)
390{
Felipe Balbi28171422008-09-20 04:14:01 +0300391 struct omap_wdt_dev *wdev;
392 wdev = platform_get_drvdata(pdev);
393 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
394
395 if (!res)
396 return -ENOENT;
397
398 misc_deregister(&(wdev->omap_wdt_miscdev));
399 release_mem_region(res->start, res->end - res->start + 1);
400 platform_set_drvdata(pdev, NULL);
401 if (wdev->armwdt_ck) {
402 clk_put(wdev->armwdt_ck);
403 wdev->armwdt_ck = NULL;
404 }
405 if (wdev->mpu_wdt_ick) {
406 clk_put(wdev->mpu_wdt_ick);
407 wdev->mpu_wdt_ick = NULL;
408 }
409 if (wdev->mpu_wdt_fck) {
410 clk_put(wdev->mpu_wdt_fck);
411 wdev->mpu_wdt_fck = NULL;
412 }
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300413 iounmap(wdev->base);
414
Felipe Balbi28171422008-09-20 04:14:01 +0300415 kfree(wdev);
416 omap_wdt_dev = NULL;
Komal Shah7768a132006-09-29 01:59:18 -0700417 return 0;
418}
419
420#ifdef CONFIG_PM
421
422/* REVISIT ... not clear this is the best way to handle system suspend; and
423 * it's very inappropriate for selective device suspend (e.g. suspending this
424 * through sysfs rather than by stopping the watchdog daemon). Also, this
425 * may not play well enough with NOWAYOUT...
426 */
427
428static int omap_wdt_suspend(struct platform_device *pdev, pm_message_t state)
429{
Felipe Balbi28171422008-09-20 04:14:01 +0300430 struct omap_wdt_dev *wdev;
431 wdev = platform_get_drvdata(pdev);
432 if (wdev->omap_wdt_users)
433 omap_wdt_disable(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700434 return 0;
435}
436
437static int omap_wdt_resume(struct platform_device *pdev)
438{
Felipe Balbi28171422008-09-20 04:14:01 +0300439 struct omap_wdt_dev *wdev;
440 wdev = platform_get_drvdata(pdev);
441 if (wdev->omap_wdt_users) {
442 omap_wdt_enable(wdev);
443 omap_wdt_ping(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700444 }
445 return 0;
446}
447
448#else
449#define omap_wdt_suspend NULL
450#define omap_wdt_resume NULL
451#endif
452
453static struct platform_driver omap_wdt_driver = {
454 .probe = omap_wdt_probe,
455 .remove = omap_wdt_remove,
456 .shutdown = omap_wdt_shutdown,
457 .suspend = omap_wdt_suspend,
458 .resume = omap_wdt_resume,
459 .driver = {
460 .owner = THIS_MODULE,
461 .name = "omap_wdt",
462 },
463};
464
465static int __init omap_wdt_init(void)
466{
Alan Cox12b9df72008-05-19 14:07:32 +0100467 spin_lock_init(&wdt_lock);
Komal Shah7768a132006-09-29 01:59:18 -0700468 return platform_driver_register(&omap_wdt_driver);
469}
470
471static void __exit omap_wdt_exit(void)
472{
473 platform_driver_unregister(&omap_wdt_driver);
474}
475
476module_init(omap_wdt_init);
477module_exit(omap_wdt_exit);
478
479MODULE_AUTHOR("George G. Davis");
480MODULE_LICENSE("GPL");
481MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
Kay Sieversf37d1932008-04-10 21:29:23 -0700482MODULE_ALIAS("platform:omap_wdt");