blob: 89db92d10ade764a59eae62fa39e2cc0b16d5375 [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>
Komal Shah7768a132006-09-29 01:59:18 -070034#include <linux/mm.h>
Komal Shah7768a132006-09-29 01:59:18 -070035#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>
Wim Van Sebroeck089ab072008-07-15 11:46:11 +000041#include <linux/io.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090042#include <linux/slab.h>
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +053043#include <linux/pm_runtime.h>
Paul Walmsley129f5572012-10-29 20:49:44 -060044#include <linux/platform_data/omap-wd-timer.h>
Komal Shah7768a132006-09-29 01:59:18 -070045
46#include "omap_wdt.h"
47
48static unsigned timer_margin;
49module_param(timer_margin, uint, 0);
50MODULE_PARM_DESC(timer_margin, "initial watchdog timeout (in seconds)");
51
Felipe Balbi28171422008-09-20 04:14:01 +030052struct omap_wdt_dev {
53 void __iomem *base; /* physical */
54 struct device *dev;
Aaro Koskinen67c0f552012-10-10 23:23:32 +030055 bool omap_wdt_users;
Felipe Balbi28171422008-09-20 04:14:01 +030056 struct resource *mem;
Aaro Koskinen67c0f552012-10-10 23:23:32 +030057 int wdt_trgr_pattern;
58 struct mutex lock; /* to avoid races with PM */
Felipe Balbi28171422008-09-20 04:14:01 +030059};
60
Aaro Koskinen67c0f552012-10-10 23:23:32 +030061static void omap_wdt_reload(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -070062{
Felipe Balbi28171422008-09-20 04:14:01 +030063 void __iomem *base = wdev->base;
Felipe Balbib3112182008-09-20 04:14:03 +030064
Komal Shah7768a132006-09-29 01:59:18 -070065 /* wait for posted write to complete */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +030066 while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x08)
Komal Shah7768a132006-09-29 01:59:18 -070067 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +030068
Aaro Koskinen67c0f552012-10-10 23:23:32 +030069 wdev->wdt_trgr_pattern = ~wdev->wdt_trgr_pattern;
70 __raw_writel(wdev->wdt_trgr_pattern, (base + OMAP_WATCHDOG_TGR));
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();
75 /* reloaded WCRR from WLDR */
76}
77
Felipe Balbi28171422008-09-20 04:14:01 +030078static void omap_wdt_enable(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -070079{
Felipe Balbib3112182008-09-20 04:14:03 +030080 void __iomem *base = wdev->base;
81
Komal Shah7768a132006-09-29 01:59:18 -070082 /* Sequence to enable the watchdog */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +030083 __raw_writel(0xBBBB, base + OMAP_WATCHDOG_SPR);
84 while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -070085 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +030086
Felipe Balbi9f69e3b2008-09-20 04:14:02 +030087 __raw_writel(0x4444, base + OMAP_WATCHDOG_SPR);
88 while ((__raw_readl(base + OMAP_WATCHDOG_WPS)) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -070089 cpu_relax();
90}
91
Felipe Balbi28171422008-09-20 04:14:01 +030092static void omap_wdt_disable(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -070093{
Felipe Balbib3112182008-09-20 04:14:03 +030094 void __iomem *base = wdev->base;
95
Komal Shah7768a132006-09-29 01:59:18 -070096 /* sequence required to disable watchdog */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +030097 __raw_writel(0xAAAA, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
98 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -070099 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +0300100
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300101 __raw_writel(0x5555, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
102 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -0700103 cpu_relax();
104}
105
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300106static void omap_wdt_set_timer(struct omap_wdt_dev *wdev,
107 unsigned int timeout)
Komal Shah7768a132006-09-29 01:59:18 -0700108{
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300109 u32 pre_margin = GET_WLDR_VAL(timeout);
Felipe Balbib3112182008-09-20 04:14:03 +0300110 void __iomem *base = wdev->base;
Komal Shah7768a132006-09-29 01:59:18 -0700111
112 /* just count up at 32 KHz */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300113 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x04)
Komal Shah7768a132006-09-29 01:59:18 -0700114 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +0300115
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300116 __raw_writel(pre_margin, base + OMAP_WATCHDOG_LDR);
117 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x04)
Komal Shah7768a132006-09-29 01:59:18 -0700118 cpu_relax();
119}
120
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300121static int omap_wdt_start(struct watchdog_device *wdog)
Komal Shah7768a132006-09-29 01:59:18 -0700122{
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300123 struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog);
Felipe Balbib3112182008-09-20 04:14:03 +0300124 void __iomem *base = wdev->base;
125
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300126 mutex_lock(&wdev->lock);
127
128 wdev->omap_wdt_users = true;
Komal Shah7768a132006-09-29 01:59:18 -0700129
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530130 pm_runtime_get_sync(wdev->dev);
Komal Shah7768a132006-09-29 01:59:18 -0700131
132 /* initialize prescaler */
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300133 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x01)
Komal Shah7768a132006-09-29 01:59:18 -0700134 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +0300135
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300136 __raw_writel((1 << 5) | (PTV << 2), base + OMAP_WATCHDOG_CNTRL);
137 while (__raw_readl(base + OMAP_WATCHDOG_WPS) & 0x01)
Komal Shah7768a132006-09-29 01:59:18 -0700138 cpu_relax();
139
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300140 omap_wdt_set_timer(wdev, wdog->timeout);
141 omap_wdt_reload(wdev); /* trigger loading of new timeout value */
Felipe Balbi28171422008-09-20 04:14:01 +0300142 omap_wdt_enable(wdev);
Felipe Balbib3112182008-09-20 04:14:03 +0300143
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300144 mutex_unlock(&wdev->lock);
Felipe Balbib3112182008-09-20 04:14:03 +0300145
Komal Shah7768a132006-09-29 01:59:18 -0700146 return 0;
147}
148
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300149static int omap_wdt_stop(struct watchdog_device *wdog)
Komal Shah7768a132006-09-29 01:59:18 -0700150{
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300151 struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog);
Felipe Balbib3112182008-09-20 04:14:03 +0300152
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300153 mutex_lock(&wdev->lock);
154 omap_wdt_disable(wdev);
155 pm_runtime_put_sync(wdev->dev);
156 wdev->omap_wdt_users = false;
157 mutex_unlock(&wdev->lock);
158 return 0;
Komal Shah7768a132006-09-29 01:59:18 -0700159}
160
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300161static int omap_wdt_ping(struct watchdog_device *wdog)
Komal Shah7768a132006-09-29 01:59:18 -0700162{
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300163 struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog);
Felipe Balbib3112182008-09-20 04:14:03 +0300164
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300165 mutex_lock(&wdev->lock);
166 omap_wdt_reload(wdev);
167 mutex_unlock(&wdev->lock);
Komal Shah7768a132006-09-29 01:59:18 -0700168
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300169 return 0;
Komal Shah7768a132006-09-29 01:59:18 -0700170}
171
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300172static int omap_wdt_set_timeout(struct watchdog_device *wdog,
173 unsigned int timeout)
174{
175 struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog);
176
177 mutex_lock(&wdev->lock);
178 omap_wdt_disable(wdev);
179 omap_wdt_set_timer(wdev, timeout);
180 omap_wdt_enable(wdev);
181 omap_wdt_reload(wdev);
182 wdog->timeout = timeout;
183 mutex_unlock(&wdev->lock);
184
185 return 0;
186}
187
188static const struct watchdog_info omap_wdt_info = {
189 .options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING,
190 .identity = "OMAP Watchdog",
191};
192
193static const struct watchdog_ops omap_wdt_ops = {
194 .owner = THIS_MODULE,
195 .start = omap_wdt_start,
196 .stop = omap_wdt_stop,
197 .ping = omap_wdt_ping,
198 .set_timeout = omap_wdt_set_timeout,
Komal Shah7768a132006-09-29 01:59:18 -0700199};
200
Bill Pemberton2d991a12012-11-19 13:21:41 -0500201static int omap_wdt_probe(struct platform_device *pdev)
Komal Shah7768a132006-09-29 01:59:18 -0700202{
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300203 struct omap_wd_timer_platform_data *pdata = pdev->dev.platform_data;
204 bool nowayout = WATCHDOG_NOWAYOUT;
205 struct watchdog_device *omap_wdt;
Komal Shah7768a132006-09-29 01:59:18 -0700206 struct resource *res, *mem;
Felipe Balbi28171422008-09-20 04:14:01 +0300207 struct omap_wdt_dev *wdev;
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300208 u32 rs;
Felipe Balbib3112182008-09-20 04:14:03 +0300209 int ret;
Komal Shah7768a132006-09-29 01:59:18 -0700210
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300211 omap_wdt = kzalloc(sizeof(*omap_wdt), GFP_KERNEL);
212 if (!omap_wdt)
213 return -ENOMEM;
214
Komal Shah7768a132006-09-29 01:59:18 -0700215 /* reserve static register mappings */
216 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Felipe Balbib3112182008-09-20 04:14:03 +0300217 if (!res) {
218 ret = -ENOENT;
219 goto err_get_resource;
220 }
Komal Shah7768a132006-09-29 01:59:18 -0700221
H Hartley Sweetenb782a562009-12-04 12:24:04 -0500222 mem = request_mem_region(res->start, resource_size(res), pdev->name);
Felipe Balbib3112182008-09-20 04:14:03 +0300223 if (!mem) {
224 ret = -EBUSY;
225 goto err_busy;
226 }
Komal Shah7768a132006-09-29 01:59:18 -0700227
Felipe Balbi28171422008-09-20 04:14:01 +0300228 wdev = kzalloc(sizeof(struct omap_wdt_dev), GFP_KERNEL);
229 if (!wdev) {
230 ret = -ENOMEM;
Felipe Balbib3112182008-09-20 04:14:03 +0300231 goto err_kzalloc;
Felipe Balbi28171422008-09-20 04:14:01 +0300232 }
Felipe Balbib3112182008-09-20 04:14:03 +0300233
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300234 wdev->omap_wdt_users = false;
235 wdev->mem = mem;
236 wdev->dev = &pdev->dev;
237 wdev->wdt_trgr_pattern = 0x1234;
238 mutex_init(&wdev->lock);
Komal Shah7768a132006-09-29 01:59:18 -0700239
H Hartley Sweetenb782a562009-12-04 12:24:04 -0500240 wdev->base = ioremap(res->start, resource_size(res));
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300241 if (!wdev->base) {
242 ret = -ENOMEM;
Felipe Balbib3112182008-09-20 04:14:03 +0300243 goto err_ioremap;
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300244 }
245
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300246 omap_wdt->info = &omap_wdt_info;
247 omap_wdt->ops = &omap_wdt_ops;
248 omap_wdt->min_timeout = TIMER_MARGIN_MIN;
249 omap_wdt->max_timeout = TIMER_MARGIN_MAX;
250
251 if (timer_margin >= TIMER_MARGIN_MIN &&
252 timer_margin <= TIMER_MARGIN_MAX)
253 omap_wdt->timeout = timer_margin;
254 else
255 omap_wdt->timeout = TIMER_MARGIN_DEFAULT;
256
257 watchdog_set_drvdata(omap_wdt, wdev);
258 watchdog_set_nowayout(omap_wdt, nowayout);
259
260 platform_set_drvdata(pdev, omap_wdt);
Felipe Balbi28171422008-09-20 04:14:01 +0300261
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530262 pm_runtime_enable(wdev->dev);
263 pm_runtime_get_sync(wdev->dev);
Ulrik Bech Hald789cd472009-06-12 16:18:32 -0500264
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300265 if (pdata && pdata->read_reset_sources)
266 rs = pdata->read_reset_sources();
267 else
268 rs = 0;
269 omap_wdt->bootstatus = (rs & (1 << OMAP_MPU_WD_RST_SRC_ID_SHIFT)) ?
270 WDIOF_CARDRESET : 0;
271
Felipe Balbi28171422008-09-20 04:14:01 +0300272 omap_wdt_disable(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700273
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300274 ret = watchdog_register_device(omap_wdt);
Komal Shah7768a132006-09-29 01:59:18 -0700275 if (ret)
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300276 goto err_register;
Komal Shah7768a132006-09-29 01:59:18 -0700277
Felipe Balbi28171422008-09-20 04:14:01 +0300278 pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec\n",
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300279 __raw_readl(wdev->base + OMAP_WATCHDOG_REV) & 0xFF,
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300280 omap_wdt->timeout);
Komal Shah7768a132006-09-29 01:59:18 -0700281
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530282 pm_runtime_put_sync(wdev->dev);
Ulrik Bech Hald789cd472009-06-12 16:18:32 -0500283
Komal Shah7768a132006-09-29 01:59:18 -0700284 return 0;
285
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300286err_register:
Shubhrajyoti D12c583d2012-01-11 19:50:18 +0530287 pm_runtime_disable(wdev->dev);
Felipe Balbib3112182008-09-20 04:14:03 +0300288 platform_set_drvdata(pdev, NULL);
289 iounmap(wdev->base);
290
291err_ioremap:
292 wdev->base = NULL;
Felipe Balbib3112182008-09-20 04:14:03 +0300293 kfree(wdev);
294
295err_kzalloc:
H Hartley Sweetenb782a562009-12-04 12:24:04 -0500296 release_mem_region(res->start, resource_size(res));
Felipe Balbib3112182008-09-20 04:14:03 +0300297
298err_busy:
299err_get_resource:
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300300 kfree(omap_wdt);
Komal Shah7768a132006-09-29 01:59:18 -0700301 return ret;
302}
303
304static void omap_wdt_shutdown(struct platform_device *pdev)
305{
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300306 struct watchdog_device *wdog = platform_get_drvdata(pdev);
307 struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog);
Felipe Balbi28171422008-09-20 04:14:01 +0300308
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300309 mutex_lock(&wdev->lock);
Paul Walmsley0503add2011-03-10 22:40:05 -0700310 if (wdev->omap_wdt_users) {
Felipe Balbi28171422008-09-20 04:14:01 +0300311 omap_wdt_disable(wdev);
Paul Walmsley0503add2011-03-10 22:40:05 -0700312 pm_runtime_put_sync(wdev->dev);
313 }
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300314 mutex_unlock(&wdev->lock);
Komal Shah7768a132006-09-29 01:59:18 -0700315}
316
Bill Pemberton4b12b892012-11-19 13:26:24 -0500317static int omap_wdt_remove(struct platform_device *pdev)
Komal Shah7768a132006-09-29 01:59:18 -0700318{
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300319 struct watchdog_device *wdog = platform_get_drvdata(pdev);
320 struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog);
Felipe Balbi28171422008-09-20 04:14:01 +0300321 struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
322
Shubhrajyoti D12c583d2012-01-11 19:50:18 +0530323 pm_runtime_disable(wdev->dev);
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300324 watchdog_unregister_device(wdog);
H Hartley Sweetenb782a562009-12-04 12:24:04 -0500325 release_mem_region(res->start, resource_size(res));
Felipe Balbi28171422008-09-20 04:14:01 +0300326 platform_set_drvdata(pdev, NULL);
Felipe Balbib3112182008-09-20 04:14:03 +0300327
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300328 iounmap(wdev->base);
329
Felipe Balbi28171422008-09-20 04:14:01 +0300330 kfree(wdev);
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300331 kfree(wdog);
Felipe Balbib3112182008-09-20 04:14:03 +0300332
Komal Shah7768a132006-09-29 01:59:18 -0700333 return 0;
334}
335
336#ifdef CONFIG_PM
337
338/* REVISIT ... not clear this is the best way to handle system suspend; and
339 * it's very inappropriate for selective device suspend (e.g. suspending this
340 * through sysfs rather than by stopping the watchdog daemon). Also, this
341 * may not play well enough with NOWAYOUT...
342 */
343
344static int omap_wdt_suspend(struct platform_device *pdev, pm_message_t state)
345{
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300346 struct watchdog_device *wdog = platform_get_drvdata(pdev);
347 struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog);
Felipe Balbib3112182008-09-20 04:14:03 +0300348
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300349 mutex_lock(&wdev->lock);
Paul Walmsley0503add2011-03-10 22:40:05 -0700350 if (wdev->omap_wdt_users) {
Felipe Balbi28171422008-09-20 04:14:01 +0300351 omap_wdt_disable(wdev);
Paul Walmsley0503add2011-03-10 22:40:05 -0700352 pm_runtime_put_sync(wdev->dev);
353 }
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300354 mutex_unlock(&wdev->lock);
Felipe Balbib3112182008-09-20 04:14:03 +0300355
Komal Shah7768a132006-09-29 01:59:18 -0700356 return 0;
357}
358
359static int omap_wdt_resume(struct platform_device *pdev)
360{
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300361 struct watchdog_device *wdog = platform_get_drvdata(pdev);
362 struct omap_wdt_dev *wdev = watchdog_get_drvdata(wdog);
Felipe Balbib3112182008-09-20 04:14:03 +0300363
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300364 mutex_lock(&wdev->lock);
Felipe Balbi28171422008-09-20 04:14:01 +0300365 if (wdev->omap_wdt_users) {
Paul Walmsley0503add2011-03-10 22:40:05 -0700366 pm_runtime_get_sync(wdev->dev);
Felipe Balbi28171422008-09-20 04:14:01 +0300367 omap_wdt_enable(wdev);
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300368 omap_wdt_reload(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700369 }
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300370 mutex_unlock(&wdev->lock);
Felipe Balbib3112182008-09-20 04:14:03 +0300371
Komal Shah7768a132006-09-29 01:59:18 -0700372 return 0;
373}
374
375#else
376#define omap_wdt_suspend NULL
377#define omap_wdt_resume NULL
378#endif
379
Xiao Jiange6ca04e2012-06-01 12:44:16 +0800380static const struct of_device_id omap_wdt_of_match[] = {
381 { .compatible = "ti,omap3-wdt", },
382 {},
383};
384MODULE_DEVICE_TABLE(of, omap_wdt_of_match);
385
Komal Shah7768a132006-09-29 01:59:18 -0700386static struct platform_driver omap_wdt_driver = {
387 .probe = omap_wdt_probe,
Bill Pemberton82268712012-11-19 13:21:12 -0500388 .remove = omap_wdt_remove,
Komal Shah7768a132006-09-29 01:59:18 -0700389 .shutdown = omap_wdt_shutdown,
390 .suspend = omap_wdt_suspend,
391 .resume = omap_wdt_resume,
392 .driver = {
393 .owner = THIS_MODULE,
394 .name = "omap_wdt",
Xiao Jiange6ca04e2012-06-01 12:44:16 +0800395 .of_match_table = omap_wdt_of_match,
Komal Shah7768a132006-09-29 01:59:18 -0700396 },
397};
398
Axel Linb8ec6112011-11-29 13:56:27 +0800399module_platform_driver(omap_wdt_driver);
Komal Shah7768a132006-09-29 01:59:18 -0700400
401MODULE_AUTHOR("George G. Davis");
402MODULE_LICENSE("GPL");
Kay Sieversf37d1932008-04-10 21:29:23 -0700403MODULE_ALIAS("platform:omap_wdt");