blob: 3e3ebbc83fafe8ba194470c0da8d9fe862897684 [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
Joe Perches27c766a2012-02-15 15:06:19 -080029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Komal Shah7768a132006-09-29 01:59:18 -070031#include <linux/module.h>
Komal Shah7768a132006-09-29 01:59:18 -070032#include <linux/types.h>
33#include <linux/kernel.h>
34#include <linux/fs.h>
35#include <linux/mm.h>
36#include <linux/miscdevice.h>
37#include <linux/watchdog.h>
38#include <linux/reboot.h>
Komal Shah7768a132006-09-29 01:59:18 -070039#include <linux/init.h>
40#include <linux/err.h>
41#include <linux/platform_device.h>
42#include <linux/moduleparam.h>
Jiri Slaby1977f032007-10-18 23:40:25 -070043#include <linux/bitops.h>
Wim Van Sebroeck089ab072008-07-15 11:46:11 +000044#include <linux/io.h>
Alan Cox12b9df72008-05-19 14:07:32 +010045#include <linux/uaccess.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090046#include <linux/slab.h>
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +053047#include <linux/pm_runtime.h>
Paul Walmsley129f5572012-10-29 20:49:44 -060048#include <linux/platform_data/omap-wd-timer.h>
Komal Shah7768a132006-09-29 01:59:18 -070049
50#include "omap_wdt.h"
51
Felipe Balbi28171422008-09-20 04:14:01 +030052static struct platform_device *omap_wdt_dev;
53
Komal Shah7768a132006-09-29 01:59:18 -070054static unsigned timer_margin;
55module_param(timer_margin, uint, 0);
56MODULE_PARM_DESC(timer_margin, "initial watchdog timeout (in seconds)");
57
Komal Shah7768a132006-09-29 01:59:18 -070058static unsigned int wdt_trgr_pattern = 0x1234;
Axel Lin1334f322011-11-29 13:54:01 +080059static DEFINE_SPINLOCK(wdt_lock);
Komal Shah7768a132006-09-29 01:59:18 -070060
Felipe Balbi28171422008-09-20 04:14:01 +030061struct omap_wdt_dev {
62 void __iomem *base; /* physical */
63 struct device *dev;
64 int omap_wdt_users;
Felipe Balbi28171422008-09-20 04:14:01 +030065 struct resource *mem;
66 struct miscdevice omap_wdt_miscdev;
67};
68
69static void omap_wdt_ping(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -070070{
Felipe Balbi28171422008-09-20 04:14:01 +030071 void __iomem *base = wdev->base;
Felipe Balbib3112182008-09-20 04:14:03 +030072
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();
Felipe Balbib3112182008-09-20 04:14:03 +030076
Komal Shah7768a132006-09-29 01:59:18 -070077 wdt_trgr_pattern = ~wdt_trgr_pattern;
Felipe Balbi9f69e3b2008-09-20 04:14:02 +030078 __raw_writel(wdt_trgr_pattern, (base + OMAP_WATCHDOG_TGR));
Felipe Balbib3112182008-09-20 04:14:03 +030079
Komal Shah7768a132006-09-29 01:59:18 -070080 /* wait for posted write to complete */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +030081 while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x08)
Komal Shah7768a132006-09-29 01:59:18 -070082 cpu_relax();
83 /* reloaded WCRR from WLDR */
84}
85
Felipe Balbi28171422008-09-20 04:14:01 +030086static void omap_wdt_enable(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -070087{
Felipe Balbib3112182008-09-20 04:14:03 +030088 void __iomem *base = wdev->base;
89
Komal Shah7768a132006-09-29 01:59:18 -070090 /* Sequence to enable the watchdog */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +030091 __raw_writel(0xBBBB, base + OMAP_WATCHDOG_SPR);
92 while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -070093 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +030094
Felipe Balbi9f69e3b2008-09-20 04:14:02 +030095 __raw_writel(0x4444, base + OMAP_WATCHDOG_SPR);
96 while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -070097 cpu_relax();
98}
99
Felipe Balbi28171422008-09-20 04:14:01 +0300100static void omap_wdt_disable(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -0700101{
Felipe Balbib3112182008-09-20 04:14:03 +0300102 void __iomem *base = wdev->base;
103
Komal Shah7768a132006-09-29 01:59:18 -0700104 /* sequence required to disable watchdog */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300105 __raw_writel(0xAAAA, 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();
Felipe Balbib3112182008-09-20 04:14:03 +0300108
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300109 __raw_writel(0x5555, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
110 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -0700111 cpu_relax();
112}
113
114static void omap_wdt_adjust_timeout(unsigned new_timeout)
115{
116 if (new_timeout < TIMER_MARGIN_MIN)
117 new_timeout = TIMER_MARGIN_DEFAULT;
118 if (new_timeout > TIMER_MARGIN_MAX)
119 new_timeout = TIMER_MARGIN_MAX;
120 timer_margin = new_timeout;
121}
122
Felipe Balbi28171422008-09-20 04:14:01 +0300123static void omap_wdt_set_timeout(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -0700124{
125 u32 pre_margin = GET_WLDR_VAL(timer_margin);
Felipe Balbib3112182008-09-20 04:14:03 +0300126 void __iomem *base = wdev->base;
Komal Shah7768a132006-09-29 01:59:18 -0700127
128 /* just count up at 32 KHz */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300129 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x04)
Komal Shah7768a132006-09-29 01:59:18 -0700130 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +0300131
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300132 __raw_writel(pre_margin, base + OMAP_WATCHDOG_LDR);
133 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x04)
Komal Shah7768a132006-09-29 01:59:18 -0700134 cpu_relax();
135}
136
137/*
138 * Allow only one task to hold it open
139 */
Komal Shah7768a132006-09-29 01:59:18 -0700140static int omap_wdt_open(struct inode *inode, struct file *file)
141{
Felipe Balbib3112182008-09-20 04:14:03 +0300142 struct omap_wdt_dev *wdev = platform_get_drvdata(omap_wdt_dev);
143 void __iomem *base = wdev->base;
144
Felipe Balbi28171422008-09-20 04:14:01 +0300145 if (test_and_set_bit(1, (unsigned long *)&(wdev->omap_wdt_users)))
Komal Shah7768a132006-09-29 01:59:18 -0700146 return -EBUSY;
147
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530148 pm_runtime_get_sync(wdev->dev);
Komal Shah7768a132006-09-29 01:59:18 -0700149
150 /* initialize prescaler */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300151 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x01)
Komal Shah7768a132006-09-29 01:59:18 -0700152 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +0300153
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300154 __raw_writel((1 << 5) | (PTV << 2), base + OMAP_WATCHDOG_CNTRL);
155 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x01)
Komal Shah7768a132006-09-29 01:59:18 -0700156 cpu_relax();
157
Felipe Balbi28171422008-09-20 04:14:01 +0300158 file->private_data = (void *) wdev;
159
160 omap_wdt_set_timeout(wdev);
Ulrik Bech Hald789cd472009-06-12 16:18:32 -0500161 omap_wdt_ping(wdev); /* trigger loading of new timeout value */
Felipe Balbi28171422008-09-20 04:14:01 +0300162 omap_wdt_enable(wdev);
Felipe Balbib3112182008-09-20 04:14:03 +0300163
Wim Van Sebroeckec9505a2007-07-20 20:41:37 +0000164 return nonseekable_open(inode, file);
Komal Shah7768a132006-09-29 01:59:18 -0700165}
166
167static int omap_wdt_release(struct inode *inode, struct file *file)
168{
Felipe Balbib3112182008-09-20 04:14:03 +0300169 struct omap_wdt_dev *wdev = file->private_data;
170
Komal Shah7768a132006-09-29 01:59:18 -0700171 /*
172 * Shut off the timer unless NOWAYOUT is defined.
173 */
174#ifndef CONFIG_WATCHDOG_NOWAYOUT
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
Joe Perches27c766a2012-02-15 15:06:19 -0800179 pr_crit("Unexpected close, not stopping!\n");
Komal Shah7768a132006-09-29 01:59:18 -0700180#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{
Paul Walmsley129f5572012-10-29 20:49:44 -0600203 struct omap_wd_timer_platform_data *pdata;
Felipe Balbi28171422008-09-20 04:14:01 +0300204 struct omap_wdt_dev *wdev;
Paul Walmsley129f5572012-10-29 20:49:44 -0600205 u32 rs;
206 int new_margin, bs;
Alan Cox12b9df72008-05-19 14:07:32 +0100207 static const struct watchdog_info ident = {
Komal Shah7768a132006-09-29 01:59:18 -0700208 .identity = "OMAP Watchdog",
209 .options = WDIOF_SETTIMEOUT,
210 .firmware_version = 0,
211 };
Felipe Balbib3112182008-09-20 04:14:03 +0300212
Felipe Balbi28171422008-09-20 04:14:01 +0300213 wdev = file->private_data;
Paul Walmsley129f5572012-10-29 20:49:44 -0600214 pdata = wdev->dev->platform_data;
Komal Shah7768a132006-09-29 01:59:18 -0700215
216 switch (cmd) {
Komal Shah7768a132006-09-29 01:59:18 -0700217 case WDIOC_GETSUPPORT:
218 return copy_to_user((struct watchdog_info __user *)arg, &ident,
219 sizeof(ident));
220 case WDIOC_GETSTATUS:
221 return put_user(0, (int __user *)arg);
222 case WDIOC_GETBOOTSTATUS:
Paul Walmsley129f5572012-10-29 20:49:44 -0600223 if (!pdata || !pdata->read_reset_sources)
224 return put_user(0, (int __user *)arg);
225 rs = pdata->read_reset_sources();
226 bs = (rs & (1 << OMAP_MPU_WD_RST_SRC_ID_SHIFT)) ?
227 WDIOF_CARDRESET : 0;
228 return put_user(bs, (int __user *)arg);
Komal Shah7768a132006-09-29 01:59:18 -0700229 case WDIOC_KEEPALIVE:
Alan Cox12b9df72008-05-19 14:07:32 +0100230 spin_lock(&wdt_lock);
Felipe Balbi28171422008-09-20 04:14:01 +0300231 omap_wdt_ping(wdev);
Alan Cox12b9df72008-05-19 14:07:32 +0100232 spin_unlock(&wdt_lock);
Komal Shah7768a132006-09-29 01:59:18 -0700233 return 0;
234 case WDIOC_SETTIMEOUT:
235 if (get_user(new_margin, (int __user *)arg))
236 return -EFAULT;
237 omap_wdt_adjust_timeout(new_margin);
238
Alan Cox12b9df72008-05-19 14:07:32 +0100239 spin_lock(&wdt_lock);
Felipe Balbi28171422008-09-20 04:14:01 +0300240 omap_wdt_disable(wdev);
241 omap_wdt_set_timeout(wdev);
242 omap_wdt_enable(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700243
Felipe Balbi28171422008-09-20 04:14:01 +0300244 omap_wdt_ping(wdev);
Alan Cox12b9df72008-05-19 14:07:32 +0100245 spin_unlock(&wdt_lock);
Komal Shah7768a132006-09-29 01:59:18 -0700246 /* Fall */
247 case WDIOC_GETTIMEOUT:
248 return put_user(timer_margin, (int __user *)arg);
Wim Van Sebroeck0c060902008-07-18 11:41:17 +0000249 default:
250 return -ENOTTY;
Komal Shah7768a132006-09-29 01:59:18 -0700251 }
252}
253
Arjan van de Ven2b8693c2007-02-12 00:55:32 -0800254static const struct file_operations omap_wdt_fops = {
Komal Shah7768a132006-09-29 01:59:18 -0700255 .owner = THIS_MODULE,
256 .write = omap_wdt_write,
Alan Cox12b9df72008-05-19 14:07:32 +0100257 .unlocked_ioctl = omap_wdt_ioctl,
Komal Shah7768a132006-09-29 01:59:18 -0700258 .open = omap_wdt_open,
259 .release = omap_wdt_release,
Arnd Bergmann6038f372010-08-15 18:52:59 +0200260 .llseek = no_llseek,
Komal Shah7768a132006-09-29 01:59:18 -0700261};
262
Bill Pemberton2d991a12012-11-19 13:21:41 -0500263static int omap_wdt_probe(struct platform_device *pdev)
Komal Shah7768a132006-09-29 01:59:18 -0700264{
265 struct resource *res, *mem;
Felipe Balbi28171422008-09-20 04:14:01 +0300266 struct omap_wdt_dev *wdev;
Felipe Balbib3112182008-09-20 04:14:03 +0300267 int ret;
Komal Shah7768a132006-09-29 01:59:18 -0700268
269 /* reserve static register mappings */
270 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Felipe Balbib3112182008-09-20 04:14:03 +0300271 if (!res) {
272 ret = -ENOENT;
273 goto err_get_resource;
274 }
Komal Shah7768a132006-09-29 01:59:18 -0700275
Felipe Balbib3112182008-09-20 04:14:03 +0300276 if (omap_wdt_dev) {
277 ret = -EBUSY;
278 goto err_busy;
279 }
Felipe Balbi28171422008-09-20 04:14:01 +0300280
H Hartley Sweetenb782a562009-12-04 12:24:04 -0500281 mem = request_mem_region(res->start, resource_size(res), pdev->name);
Felipe Balbib3112182008-09-20 04:14:03 +0300282 if (!mem) {
283 ret = -EBUSY;
284 goto err_busy;
285 }
Komal Shah7768a132006-09-29 01:59:18 -0700286
Felipe Balbi28171422008-09-20 04:14:01 +0300287 wdev = kzalloc(sizeof(struct omap_wdt_dev), GFP_KERNEL);
288 if (!wdev) {
289 ret = -ENOMEM;
Felipe Balbib3112182008-09-20 04:14:03 +0300290 goto err_kzalloc;
Felipe Balbi28171422008-09-20 04:14:01 +0300291 }
Felipe Balbib3112182008-09-20 04:14:03 +0300292
Felipe Balbi28171422008-09-20 04:14:01 +0300293 wdev->omap_wdt_users = 0;
294 wdev->mem = mem;
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530295 wdev->dev = &pdev->dev;
Komal Shah7768a132006-09-29 01:59:18 -0700296
H Hartley Sweetenb782a562009-12-04 12:24:04 -0500297 wdev->base = ioremap(res->start, resource_size(res));
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300298 if (!wdev->base) {
299 ret = -ENOMEM;
Felipe Balbib3112182008-09-20 04:14:03 +0300300 goto err_ioremap;
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300301 }
302
Felipe Balbi28171422008-09-20 04:14:01 +0300303 platform_set_drvdata(pdev, wdev);
304
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530305 pm_runtime_enable(wdev->dev);
306 pm_runtime_get_sync(wdev->dev);
Ulrik Bech Hald789cd472009-06-12 16:18:32 -0500307
Felipe Balbi28171422008-09-20 04:14:01 +0300308 omap_wdt_disable(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700309 omap_wdt_adjust_timeout(timer_margin);
310
Felipe Balbi28171422008-09-20 04:14:01 +0300311 wdev->omap_wdt_miscdev.parent = &pdev->dev;
312 wdev->omap_wdt_miscdev.minor = WATCHDOG_MINOR;
313 wdev->omap_wdt_miscdev.name = "watchdog";
314 wdev->omap_wdt_miscdev.fops = &omap_wdt_fops;
315
316 ret = misc_register(&(wdev->omap_wdt_miscdev));
Komal Shah7768a132006-09-29 01:59:18 -0700317 if (ret)
Felipe Balbib3112182008-09-20 04:14:03 +0300318 goto err_misc;
Komal Shah7768a132006-09-29 01:59:18 -0700319
Felipe Balbi28171422008-09-20 04:14:01 +0300320 pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec\n",
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300321 __raw_readl(wdev->base + OMAP_WATCHDOG_REV) & 0xFF,
Felipe Balbi28171422008-09-20 04:14:01 +0300322 timer_margin);
Komal Shah7768a132006-09-29 01:59:18 -0700323
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530324 pm_runtime_put_sync(wdev->dev);
Ulrik Bech Hald789cd472009-06-12 16:18:32 -0500325
Felipe Balbi28171422008-09-20 04:14:01 +0300326 omap_wdt_dev = pdev;
327
Komal Shah7768a132006-09-29 01:59:18 -0700328 return 0;
329
Felipe Balbib3112182008-09-20 04:14:03 +0300330err_misc:
Shubhrajyoti D12c583d2012-01-11 19:50:18 +0530331 pm_runtime_disable(wdev->dev);
Felipe Balbib3112182008-09-20 04:14:03 +0300332 platform_set_drvdata(pdev, NULL);
333 iounmap(wdev->base);
334
335err_ioremap:
336 wdev->base = NULL;
Felipe Balbib3112182008-09-20 04:14:03 +0300337 kfree(wdev);
338
339err_kzalloc:
H Hartley Sweetenb782a562009-12-04 12:24:04 -0500340 release_mem_region(res->start, resource_size(res));
Felipe Balbib3112182008-09-20 04:14:03 +0300341
342err_busy:
343err_get_resource:
344
Komal Shah7768a132006-09-29 01:59:18 -0700345 return ret;
346}
347
348static void omap_wdt_shutdown(struct platform_device *pdev)
349{
Felipe Balbib3112182008-09-20 04:14:03 +0300350 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
Felipe Balbi28171422008-09-20 04:14:01 +0300351
Paul Walmsley0503add2011-03-10 22:40:05 -0700352 if (wdev->omap_wdt_users) {
Felipe Balbi28171422008-09-20 04:14:01 +0300353 omap_wdt_disable(wdev);
Paul Walmsley0503add2011-03-10 22:40:05 -0700354 pm_runtime_put_sync(wdev->dev);
355 }
Komal Shah7768a132006-09-29 01:59:18 -0700356}
357
Bill Pemberton4b12b892012-11-19 13:26:24 -0500358static int omap_wdt_remove(struct platform_device *pdev)
Komal Shah7768a132006-09-29 01:59:18 -0700359{
Felipe Balbib3112182008-09-20 04:14:03 +0300360 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
Felipe Balbi28171422008-09-20 04:14:01 +0300361 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
362
Shubhrajyoti D12c583d2012-01-11 19:50:18 +0530363 pm_runtime_disable(wdev->dev);
Felipe Balbi28171422008-09-20 04:14:01 +0300364 if (!res)
365 return -ENOENT;
366
367 misc_deregister(&(wdev->omap_wdt_miscdev));
H Hartley Sweetenb782a562009-12-04 12:24:04 -0500368 release_mem_region(res->start, resource_size(res));
Felipe Balbi28171422008-09-20 04:14:01 +0300369 platform_set_drvdata(pdev, NULL);
Felipe Balbib3112182008-09-20 04:14:03 +0300370
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300371 iounmap(wdev->base);
372
Felipe Balbi28171422008-09-20 04:14:01 +0300373 kfree(wdev);
374 omap_wdt_dev = NULL;
Felipe Balbib3112182008-09-20 04:14:03 +0300375
Komal Shah7768a132006-09-29 01:59:18 -0700376 return 0;
377}
378
379#ifdef CONFIG_PM
380
381/* REVISIT ... not clear this is the best way to handle system suspend; and
382 * it's very inappropriate for selective device suspend (e.g. suspending this
383 * through sysfs rather than by stopping the watchdog daemon). Also, this
384 * may not play well enough with NOWAYOUT...
385 */
386
387static int omap_wdt_suspend(struct platform_device *pdev, pm_message_t state)
388{
Felipe Balbib3112182008-09-20 04:14:03 +0300389 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
390
Paul Walmsley0503add2011-03-10 22:40:05 -0700391 if (wdev->omap_wdt_users) {
Felipe Balbi28171422008-09-20 04:14:01 +0300392 omap_wdt_disable(wdev);
Paul Walmsley0503add2011-03-10 22:40:05 -0700393 pm_runtime_put_sync(wdev->dev);
394 }
Felipe Balbib3112182008-09-20 04:14:03 +0300395
Komal Shah7768a132006-09-29 01:59:18 -0700396 return 0;
397}
398
399static int omap_wdt_resume(struct platform_device *pdev)
400{
Felipe Balbib3112182008-09-20 04:14:03 +0300401 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
402
Felipe Balbi28171422008-09-20 04:14:01 +0300403 if (wdev->omap_wdt_users) {
Paul Walmsley0503add2011-03-10 22:40:05 -0700404 pm_runtime_get_sync(wdev->dev);
Felipe Balbi28171422008-09-20 04:14:01 +0300405 omap_wdt_enable(wdev);
406 omap_wdt_ping(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700407 }
Felipe Balbib3112182008-09-20 04:14:03 +0300408
Komal Shah7768a132006-09-29 01:59:18 -0700409 return 0;
410}
411
412#else
413#define omap_wdt_suspend NULL
414#define omap_wdt_resume NULL
415#endif
416
Xiao Jiange6ca04e2012-06-01 12:44:16 +0800417static const struct of_device_id omap_wdt_of_match[] = {
418 { .compatible = "ti,omap3-wdt", },
419 {},
420};
421MODULE_DEVICE_TABLE(of, omap_wdt_of_match);
422
Komal Shah7768a132006-09-29 01:59:18 -0700423static struct platform_driver omap_wdt_driver = {
424 .probe = omap_wdt_probe,
Bill Pemberton82268712012-11-19 13:21:12 -0500425 .remove = omap_wdt_remove,
Komal Shah7768a132006-09-29 01:59:18 -0700426 .shutdown = omap_wdt_shutdown,
427 .suspend = omap_wdt_suspend,
428 .resume = omap_wdt_resume,
429 .driver = {
430 .owner = THIS_MODULE,
431 .name = "omap_wdt",
Xiao Jiange6ca04e2012-06-01 12:44:16 +0800432 .of_match_table = omap_wdt_of_match,
Komal Shah7768a132006-09-29 01:59:18 -0700433 },
434};
435
Axel Linb8ec6112011-11-29 13:56:27 +0800436module_platform_driver(omap_wdt_driver);
Komal Shah7768a132006-09-29 01:59:18 -0700437
438MODULE_AUTHOR("George G. Davis");
439MODULE_LICENSE("GPL");
440MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
Kay Sieversf37d1932008-04-10 21:29:23 -0700441MODULE_ALIAS("platform:omap_wdt");