Blame view

drivers/watchdog/omap_wdt.c 10.5 KB
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
1
  /*
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
2
   * omap_wdt.c
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
3
   *
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
4
   * Watchdog driver for the TI OMAP 16xx & 24xx/34xx 32KHz (non-secure) watchdog
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
5
6
7
8
9
10
11
12
13
14
15
16
17
18
   *
   * Author: MontaVista Software, Inc.
   *	 <gdavis@mvista.com> or <source@mvista.com>
   *
   * 2003 (c) MontaVista Software, Inc. This file is licensed under the
   * terms of the GNU General Public License version 2. This program is
   * licensed "as is" without any warranty of any kind, whether express
   * or implied.
   *
   * History:
   *
   * 20030527: George G. Davis <gdavis@mvista.com>
   *	Initially based on linux-2.4.19-rmk7-pxa1/drivers/char/sa1100_wdt.c
   *	(c) Copyright 2000 Oleg Drokin <green@crimea.edu>
29fa0586d   Alan Cox   [PATCH] Switch al...
19
   *	Based on SoftDog driver by Alan Cox <alan@lxorguk.ukuu.org.uk>
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
20
21
22
23
24
25
26
27
28
29
   *
   * Copyright (c) 2004 Texas Instruments.
   *	1. Modified to support OMAP1610 32-KHz watchdog timer
   *	2. Ported to 2.6 kernel
   *
   * Copyright (c) 2005 David Brownell
   *	Use the driver model and standard identifiers; handle bigger timeouts.
   */
  
  #include <linux/module.h>
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
30
31
32
33
34
35
36
  #include <linux/types.h>
  #include <linux/kernel.h>
  #include <linux/fs.h>
  #include <linux/mm.h>
  #include <linux/miscdevice.h>
  #include <linux/watchdog.h>
  #include <linux/reboot.h>
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
37
38
39
40
  #include <linux/init.h>
  #include <linux/err.h>
  #include <linux/platform_device.h>
  #include <linux/moduleparam.h>
1977f0327   Jiri Slaby   remove asm/bitops...
41
  #include <linux/bitops.h>
089ab0791   Wim Van Sebroeck   [WATCHDOG] Clean-...
42
  #include <linux/io.h>
12b9df7d2   Alan Cox   [WATCHDOG 30/57] ...
43
  #include <linux/uaccess.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
44
  #include <linux/slab.h>
7ec5ad0f3   Varadarajan, Charulatha   OMAP: WDT: Use PM...
45
  #include <linux/pm_runtime.h>
a09e64fbc   Russell King   [ARM] Move includ...
46
  #include <mach/hardware.h>
ce491cf85   Tony Lindgren   omap: headers: Mo...
47
  #include <plat/prcm.h>
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
48
49
  
  #include "omap_wdt.h"
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
50
  static struct platform_device *omap_wdt_dev;
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
51
52
53
  static unsigned timer_margin;
  module_param(timer_margin, uint, 0);
  MODULE_PARM_DESC(timer_margin, "initial watchdog timeout (in seconds)");
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
54
  static unsigned int wdt_trgr_pattern = 0x1234;
1334f3293   Axel Lin   watchdog: Use DEF...
55
  static DEFINE_SPINLOCK(wdt_lock);
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
56

2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
57
58
59
60
  struct omap_wdt_dev {
  	void __iomem    *base;          /* physical */
  	struct device   *dev;
  	int             omap_wdt_users;
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
61
62
63
64
65
  	struct resource *mem;
  	struct miscdevice omap_wdt_miscdev;
  };
  
  static void omap_wdt_ping(struct omap_wdt_dev *wdev)
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
66
  {
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
67
  	void __iomem    *base = wdev->base;
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
68

7768a13c2   Komal Shah   [PATCH] OMAP: Add...
69
  	/* wait for posted write to complete */
9f69e3b0c   Felipe Balbi   [WATCHDOG] omap_w...
70
  	while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x08)
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
71
  		cpu_relax();
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
72

7768a13c2   Komal Shah   [PATCH] OMAP: Add...
73
  	wdt_trgr_pattern = ~wdt_trgr_pattern;
9f69e3b0c   Felipe Balbi   [WATCHDOG] omap_w...
74
  	__raw_writel(wdt_trgr_pattern, (base + OMAP_WATCHDOG_TGR));
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
75

7768a13c2   Komal Shah   [PATCH] OMAP: Add...
76
  	/* wait for posted write to complete */
9f69e3b0c   Felipe Balbi   [WATCHDOG] omap_w...
77
  	while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x08)
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
78
79
80
  		cpu_relax();
  	/* reloaded WCRR from WLDR */
  }
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
81
  static void omap_wdt_enable(struct omap_wdt_dev *wdev)
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
82
  {
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
83
  	void __iomem *base = wdev->base;
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
84
  	/* Sequence to enable the watchdog */
9f69e3b0c   Felipe Balbi   [WATCHDOG] omap_w...
85
86
  	__raw_writel(0xBBBB, base + OMAP_WATCHDOG_SPR);
  	while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x10)
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
87
  		cpu_relax();
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
88

9f69e3b0c   Felipe Balbi   [WATCHDOG] omap_w...
89
90
  	__raw_writel(0x4444, base + OMAP_WATCHDOG_SPR);
  	while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x10)
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
91
92
  		cpu_relax();
  }
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
93
  static void omap_wdt_disable(struct omap_wdt_dev *wdev)
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
94
  {
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
95
  	void __iomem *base = wdev->base;
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
96
  	/* sequence required to disable watchdog */
9f69e3b0c   Felipe Balbi   [WATCHDOG] omap_w...
97
98
  	__raw_writel(0xAAAA, base + OMAP_WATCHDOG_SPR);	/* TIMER_MODE */
  	while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x10)
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
99
  		cpu_relax();
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
100

9f69e3b0c   Felipe Balbi   [WATCHDOG] omap_w...
101
102
  	__raw_writel(0x5555, base + OMAP_WATCHDOG_SPR);	/* TIMER_MODE */
  	while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x10)
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
103
104
105
106
107
108
109
110
111
112
113
  		cpu_relax();
  }
  
  static void omap_wdt_adjust_timeout(unsigned new_timeout)
  {
  	if (new_timeout < TIMER_MARGIN_MIN)
  		new_timeout = TIMER_MARGIN_DEFAULT;
  	if (new_timeout > TIMER_MARGIN_MAX)
  		new_timeout = TIMER_MARGIN_MAX;
  	timer_margin = new_timeout;
  }
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
114
  static void omap_wdt_set_timeout(struct omap_wdt_dev *wdev)
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
115
116
  {
  	u32 pre_margin = GET_WLDR_VAL(timer_margin);
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
117
  	void __iomem *base = wdev->base;
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
118

0503add9d   Paul Walmsley   Watchdog: omap_wd...
119
  	pm_runtime_get_sync(wdev->dev);
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
120
  	/* just count up at 32 KHz */
9f69e3b0c   Felipe Balbi   [WATCHDOG] omap_w...
121
  	while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x04)
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
122
  		cpu_relax();
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
123

9f69e3b0c   Felipe Balbi   [WATCHDOG] omap_w...
124
125
  	__raw_writel(pre_margin, base + OMAP_WATCHDOG_LDR);
  	while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x04)
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
126
  		cpu_relax();
0503add9d   Paul Walmsley   Watchdog: omap_wd...
127
128
  
  	pm_runtime_put_sync(wdev->dev);
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
129
130
131
132
133
  }
  
  /*
   *	Allow only one task to hold it open
   */
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
134
135
  static int omap_wdt_open(struct inode *inode, struct file *file)
  {
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
136
137
  	struct omap_wdt_dev *wdev = platform_get_drvdata(omap_wdt_dev);
  	void __iomem *base = wdev->base;
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
138
  	if (test_and_set_bit(1, (unsigned long *)&(wdev->omap_wdt_users)))
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
139
  		return -EBUSY;
7ec5ad0f3   Varadarajan, Charulatha   OMAP: WDT: Use PM...
140
  	pm_runtime_get_sync(wdev->dev);
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
141
142
  
  	/* initialize prescaler */
9f69e3b0c   Felipe Balbi   [WATCHDOG] omap_w...
143
  	while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x01)
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
144
  		cpu_relax();
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
145

9f69e3b0c   Felipe Balbi   [WATCHDOG] omap_w...
146
147
  	__raw_writel((1 << 5) | (PTV << 2), base + OMAP_WATCHDOG_CNTRL);
  	while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x01)
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
148
  		cpu_relax();
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
149
150
151
  	file->private_data = (void *) wdev;
  
  	omap_wdt_set_timeout(wdev);
789cd4702   Ulrik Bech Hald   [WATCHDOG] OMAP f...
152
  	omap_wdt_ping(wdev); /* trigger loading of new timeout value */
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
153
  	omap_wdt_enable(wdev);
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
154

0503add9d   Paul Walmsley   Watchdog: omap_wd...
155
  	pm_runtime_put_sync(wdev->dev);
ec9505a7e   Wim Van Sebroeck   [WATCHDOG] VFS cl...
156
  	return nonseekable_open(inode, file);
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
157
158
159
160
  }
  
  static int omap_wdt_release(struct inode *inode, struct file *file)
  {
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
161
  	struct omap_wdt_dev *wdev = file->private_data;
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
162
163
164
165
  	/*
  	 *      Shut off the timer unless NOWAYOUT is defined.
  	 */
  #ifndef CONFIG_WATCHDOG_NOWAYOUT
0503add9d   Paul Walmsley   Watchdog: omap_wd...
166
  	pm_runtime_get_sync(wdev->dev);
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
167

2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
168
  	omap_wdt_disable(wdev);
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
169

7ec5ad0f3   Varadarajan, Charulatha   OMAP: WDT: Use PM...
170
  	pm_runtime_put_sync(wdev->dev);
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
171
172
173
174
  #else
  	printk(KERN_CRIT "omap_wdt: Unexpected close, not stopping!
  ");
  #endif
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
175
  	wdev->omap_wdt_users = 0;
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
176

7768a13c2   Komal Shah   [PATCH] OMAP: Add...
177
178
  	return 0;
  }
12b9df7d2   Alan Cox   [WATCHDOG 30/57] ...
179
  static ssize_t omap_wdt_write(struct file *file, const char __user *data,
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
180
181
  		size_t len, loff_t *ppos)
  {
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
182
  	struct omap_wdt_dev *wdev = file->private_data;
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
183
  	/* Refresh LOAD_TIME. */
12b9df7d2   Alan Cox   [WATCHDOG 30/57] ...
184
  	if (len) {
0503add9d   Paul Walmsley   Watchdog: omap_wd...
185
  		pm_runtime_get_sync(wdev->dev);
12b9df7d2   Alan Cox   [WATCHDOG 30/57] ...
186
  		spin_lock(&wdt_lock);
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
187
  		omap_wdt_ping(wdev);
12b9df7d2   Alan Cox   [WATCHDOG 30/57] ...
188
  		spin_unlock(&wdt_lock);
0503add9d   Paul Walmsley   Watchdog: omap_wd...
189
  		pm_runtime_put_sync(wdev->dev);
12b9df7d2   Alan Cox   [WATCHDOG 30/57] ...
190
  	}
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
191
192
  	return len;
  }
12b9df7d2   Alan Cox   [WATCHDOG 30/57] ...
193
194
  static long omap_wdt_ioctl(struct file *file, unsigned int cmd,
  						unsigned long arg)
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
195
  {
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
196
  	struct omap_wdt_dev *wdev;
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
197
  	int new_margin;
12b9df7d2   Alan Cox   [WATCHDOG 30/57] ...
198
  	static const struct watchdog_info ident = {
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
199
200
201
202
  		.identity = "OMAP Watchdog",
  		.options = WDIOF_SETTIMEOUT,
  		.firmware_version = 0,
  	};
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
203

2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
204
  	wdev = file->private_data;
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
205
206
  
  	switch (cmd) {
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
207
208
209
210
211
212
213
  	case WDIOC_GETSUPPORT:
  		return copy_to_user((struct watchdog_info __user *)arg, &ident,
  				sizeof(ident));
  	case WDIOC_GETSTATUS:
  		return put_user(0, (int __user *)arg);
  	case WDIOC_GETBOOTSTATUS:
  		if (cpu_is_omap16xx())
9f69e3b0c   Felipe Balbi   [WATCHDOG] omap_w...
214
  			return put_user(__raw_readw(ARM_SYSST),
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
215
216
217
218
  					(int __user *)arg);
  		if (cpu_is_omap24xx())
  			return put_user(omap_prcm_get_reset_sources(),
  					(int __user *)arg);
e2bf7c4c2   Shubhrajyoti D   watchdog: omap_wd...
219
  		return put_user(0, (int __user *)arg);
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
220
  	case WDIOC_KEEPALIVE:
0503add9d   Paul Walmsley   Watchdog: omap_wd...
221
  		pm_runtime_get_sync(wdev->dev);
12b9df7d2   Alan Cox   [WATCHDOG 30/57] ...
222
  		spin_lock(&wdt_lock);
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
223
  		omap_wdt_ping(wdev);
12b9df7d2   Alan Cox   [WATCHDOG 30/57] ...
224
  		spin_unlock(&wdt_lock);
0503add9d   Paul Walmsley   Watchdog: omap_wd...
225
  		pm_runtime_put_sync(wdev->dev);
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
226
227
228
229
230
  		return 0;
  	case WDIOC_SETTIMEOUT:
  		if (get_user(new_margin, (int __user *)arg))
  			return -EFAULT;
  		omap_wdt_adjust_timeout(new_margin);
0503add9d   Paul Walmsley   Watchdog: omap_wd...
231
  		pm_runtime_get_sync(wdev->dev);
12b9df7d2   Alan Cox   [WATCHDOG 30/57] ...
232
  		spin_lock(&wdt_lock);
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
233
234
235
  		omap_wdt_disable(wdev);
  		omap_wdt_set_timeout(wdev);
  		omap_wdt_enable(wdev);
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
236

2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
237
  		omap_wdt_ping(wdev);
12b9df7d2   Alan Cox   [WATCHDOG 30/57] ...
238
  		spin_unlock(&wdt_lock);
0503add9d   Paul Walmsley   Watchdog: omap_wd...
239
  		pm_runtime_put_sync(wdev->dev);
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
240
241
242
  		/* Fall */
  	case WDIOC_GETTIMEOUT:
  		return put_user(timer_margin, (int __user *)arg);
0c06090c9   Wim Van Sebroeck   [WATCHDOG] Coding...
243
244
  	default:
  		return -ENOTTY;
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
245
246
  	}
  }
2b8693c06   Arjan van de Ven   [PATCH] mark stru...
247
  static const struct file_operations omap_wdt_fops = {
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
248
249
  	.owner = THIS_MODULE,
  	.write = omap_wdt_write,
12b9df7d2   Alan Cox   [WATCHDOG 30/57] ...
250
  	.unlocked_ioctl = omap_wdt_ioctl,
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
251
252
  	.open = omap_wdt_open,
  	.release = omap_wdt_release,
6038f373a   Arnd Bergmann   llseek: automatic...
253
  	.llseek = no_llseek,
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
254
  };
0e3912c75   Uwe Kleine-König   [WATCHDOG] omap_w...
255
  static int __devinit omap_wdt_probe(struct platform_device *pdev)
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
256
257
  {
  	struct resource *res, *mem;
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
258
  	struct omap_wdt_dev *wdev;
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
259
  	int ret;
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
260
261
262
  
  	/* reserve static register mappings */
  	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
263
264
265
266
  	if (!res) {
  		ret = -ENOENT;
  		goto err_get_resource;
  	}
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
267

b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
268
269
270
271
  	if (omap_wdt_dev) {
  		ret = -EBUSY;
  		goto err_busy;
  	}
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
272

b782a5637   H Hartley Sweeten   [WATCHDOG] use re...
273
  	mem = request_mem_region(res->start, resource_size(res), pdev->name);
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
274
275
276
277
  	if (!mem) {
  		ret = -EBUSY;
  		goto err_busy;
  	}
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
278

2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
279
280
281
  	wdev = kzalloc(sizeof(struct omap_wdt_dev), GFP_KERNEL);
  	if (!wdev) {
  		ret = -ENOMEM;
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
282
  		goto err_kzalloc;
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
283
  	}
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
284

2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
285
286
  	wdev->omap_wdt_users = 0;
  	wdev->mem = mem;
7ec5ad0f3   Varadarajan, Charulatha   OMAP: WDT: Use PM...
287
  	wdev->dev = &pdev->dev;
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
288

b782a5637   H Hartley Sweeten   [WATCHDOG] use re...
289
  	wdev->base = ioremap(res->start, resource_size(res));
9f69e3b0c   Felipe Balbi   [WATCHDOG] omap_w...
290
291
  	if (!wdev->base) {
  		ret = -ENOMEM;
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
292
  		goto err_ioremap;
9f69e3b0c   Felipe Balbi   [WATCHDOG] omap_w...
293
  	}
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
294
  	platform_set_drvdata(pdev, wdev);
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
295

7ec5ad0f3   Varadarajan, Charulatha   OMAP: WDT: Use PM...
296
297
  	pm_runtime_enable(wdev->dev);
  	pm_runtime_get_sync(wdev->dev);
789cd4702   Ulrik Bech Hald   [WATCHDOG] OMAP f...
298

2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
299
  	omap_wdt_disable(wdev);
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
300
  	omap_wdt_adjust_timeout(timer_margin);
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
301
302
303
304
305
306
  	wdev->omap_wdt_miscdev.parent = &pdev->dev;
  	wdev->omap_wdt_miscdev.minor = WATCHDOG_MINOR;
  	wdev->omap_wdt_miscdev.name = "watchdog";
  	wdev->omap_wdt_miscdev.fops = &omap_wdt_fops;
  
  	ret = misc_register(&(wdev->omap_wdt_miscdev));
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
307
  	if (ret)
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
308
  		goto err_misc;
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
309

2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
310
311
  	pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec
  ",
9f69e3b0c   Felipe Balbi   [WATCHDOG] omap_w...
312
  		__raw_readl(wdev->base + OMAP_WATCHDOG_REV) & 0xFF,
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
313
  		timer_margin);
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
314

7ec5ad0f3   Varadarajan, Charulatha   OMAP: WDT: Use PM...
315
  	pm_runtime_put_sync(wdev->dev);
789cd4702   Ulrik Bech Hald   [WATCHDOG] OMAP f...
316

2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
317
  	omap_wdt_dev = pdev;
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
318
  	return 0;
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
319
320
321
322
323
324
  err_misc:
  	platform_set_drvdata(pdev, NULL);
  	iounmap(wdev->base);
  
  err_ioremap:
  	wdev->base = NULL;
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
325
326
327
  	kfree(wdev);
  
  err_kzalloc:
b782a5637   H Hartley Sweeten   [WATCHDOG] use re...
328
  	release_mem_region(res->start, resource_size(res));
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
329
330
331
  
  err_busy:
  err_get_resource:
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
332
333
334
335
336
  	return ret;
  }
  
  static void omap_wdt_shutdown(struct platform_device *pdev)
  {
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
337
  	struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
338

0503add9d   Paul Walmsley   Watchdog: omap_wd...
339
340
  	if (wdev->omap_wdt_users) {
  		pm_runtime_get_sync(wdev->dev);
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
341
  		omap_wdt_disable(wdev);
0503add9d   Paul Walmsley   Watchdog: omap_wd...
342
343
  		pm_runtime_put_sync(wdev->dev);
  	}
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
344
  }
0e3912c75   Uwe Kleine-König   [WATCHDOG] omap_w...
345
  static int __devexit omap_wdt_remove(struct platform_device *pdev)
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
346
  {
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
347
  	struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
348
349
350
351
352
353
  	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  
  	if (!res)
  		return -ENOENT;
  
  	misc_deregister(&(wdev->omap_wdt_miscdev));
b782a5637   H Hartley Sweeten   [WATCHDOG] use re...
354
  	release_mem_region(res->start, resource_size(res));
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
355
  	platform_set_drvdata(pdev, NULL);
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
356

9f69e3b0c   Felipe Balbi   [WATCHDOG] omap_w...
357
  	iounmap(wdev->base);
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
358
359
  	kfree(wdev);
  	omap_wdt_dev = NULL;
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
360

7768a13c2   Komal Shah   [PATCH] OMAP: Add...
361
362
363
364
365
366
367
368
369
370
371
372
373
  	return 0;
  }
  
  #ifdef	CONFIG_PM
  
  /* REVISIT ... not clear this is the best way to handle system suspend; and
   * it's very inappropriate for selective device suspend (e.g. suspending this
   * through sysfs rather than by stopping the watchdog daemon).  Also, this
   * may not play well enough with NOWAYOUT...
   */
  
  static int omap_wdt_suspend(struct platform_device *pdev, pm_message_t state)
  {
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
374
  	struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
0503add9d   Paul Walmsley   Watchdog: omap_wd...
375
376
  	if (wdev->omap_wdt_users) {
  		pm_runtime_get_sync(wdev->dev);
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
377
  		omap_wdt_disable(wdev);
0503add9d   Paul Walmsley   Watchdog: omap_wd...
378
379
  		pm_runtime_put_sync(wdev->dev);
  	}
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
380

7768a13c2   Komal Shah   [PATCH] OMAP: Add...
381
382
383
384
385
  	return 0;
  }
  
  static int omap_wdt_resume(struct platform_device *pdev)
  {
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
386
  	struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
387
  	if (wdev->omap_wdt_users) {
0503add9d   Paul Walmsley   Watchdog: omap_wd...
388
  		pm_runtime_get_sync(wdev->dev);
2817142f3   Felipe Balbi   [WATCHDOG] omap_w...
389
390
  		omap_wdt_enable(wdev);
  		omap_wdt_ping(wdev);
0503add9d   Paul Walmsley   Watchdog: omap_wd...
391
  		pm_runtime_put_sync(wdev->dev);
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
392
  	}
b3112180f   Felipe Balbi   [WATCHDOG] omap_w...
393

7768a13c2   Komal Shah   [PATCH] OMAP: Add...
394
395
396
397
398
399
400
401
402
403
  	return 0;
  }
  
  #else
  #define	omap_wdt_suspend	NULL
  #define	omap_wdt_resume		NULL
  #endif
  
  static struct platform_driver omap_wdt_driver = {
  	.probe		= omap_wdt_probe,
0e3912c75   Uwe Kleine-König   [WATCHDOG] omap_w...
404
  	.remove		= __devexit_p(omap_wdt_remove),
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
405
406
407
408
409
410
411
412
  	.shutdown	= omap_wdt_shutdown,
  	.suspend	= omap_wdt_suspend,
  	.resume		= omap_wdt_resume,
  	.driver		= {
  		.owner	= THIS_MODULE,
  		.name	= "omap_wdt",
  	},
  };
b8ec61189   Axel Lin   watchdog: convert...
413
  module_platform_driver(omap_wdt_driver);
7768a13c2   Komal Shah   [PATCH] OMAP: Add...
414
415
416
417
  
  MODULE_AUTHOR("George G. Davis");
  MODULE_LICENSE("GPL");
  MODULE_ALIAS_MISCDEV(WATCHDOG_MINOR);
f37d193c7   Kay Sievers   watchdog: fix pla...
418
  MODULE_ALIAS("platform:omap_wdt");