blob: d49688d93f6ae156ab3db095f85bdd0261603813 [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>
Randy Dunlapac316722018-06-19 22:47:28 -070032#include <linux/mod_devicetable.h>
Komal Shah7768a132006-09-29 01:59:18 -070033#include <linux/types.h>
34#include <linux/kernel.h>
Komal Shah7768a132006-09-29 01:59:18 -070035#include <linux/mm.h>
Komal Shah7768a132006-09-29 01:59:18 -070036#include <linux/watchdog.h>
37#include <linux/reboot.h>
Komal Shah7768a132006-09-29 01:59:18 -070038#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
Pali Rohár2dd7b242013-02-17 00:49:26 +010048static bool nowayout = WATCHDOG_NOWAYOUT;
49module_param(nowayout, bool, 0);
50MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
51 "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
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
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +020057#define to_omap_wdt_dev(_wdog) container_of(_wdog, struct omap_wdt_dev, wdog)
58
Lars Poeschelb2102eb2015-06-25 12:21:51 +020059static bool early_enable;
60module_param(early_enable, bool, 0);
61MODULE_PARM_DESC(early_enable,
62 "Watchdog is started on module insertion (default=0)");
63
Felipe Balbi28171422008-09-20 04:14:01 +030064struct omap_wdt_dev {
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +020065 struct watchdog_device wdog;
Felipe Balbi28171422008-09-20 04:14:01 +030066 void __iomem *base; /* physical */
67 struct device *dev;
Aaro Koskinen67c0f552012-10-10 23:23:32 +030068 bool omap_wdt_users;
Aaro Koskinen67c0f552012-10-10 23:23:32 +030069 int wdt_trgr_pattern;
70 struct mutex lock; /* to avoid races with PM */
Felipe Balbi28171422008-09-20 04:14:01 +030071};
72
Aaro Koskinen67c0f552012-10-10 23:23:32 +030073static void omap_wdt_reload(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -070074{
Felipe Balbi28171422008-09-20 04:14:01 +030075 void __iomem *base = wdev->base;
Felipe Balbib3112182008-09-20 04:14:03 +030076
Komal Shah7768a132006-09-29 01:59:18 -070077 /* wait for posted write to complete */
Victor Kamensky4a7e94a2013-11-16 02:01:05 +020078 while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x08)
Komal Shah7768a132006-09-29 01:59:18 -070079 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +030080
Aaro Koskinen67c0f552012-10-10 23:23:32 +030081 wdev->wdt_trgr_pattern = ~wdev->wdt_trgr_pattern;
Victor Kamensky4a7e94a2013-11-16 02:01:05 +020082 writel_relaxed(wdev->wdt_trgr_pattern, (base + OMAP_WATCHDOG_TGR));
Felipe Balbib3112182008-09-20 04:14:03 +030083
Komal Shah7768a132006-09-29 01:59:18 -070084 /* wait for posted write to complete */
Victor Kamensky4a7e94a2013-11-16 02:01:05 +020085 while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x08)
Komal Shah7768a132006-09-29 01:59:18 -070086 cpu_relax();
87 /* reloaded WCRR from WLDR */
88}
89
Felipe Balbi28171422008-09-20 04:14:01 +030090static void omap_wdt_enable(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -070091{
Felipe Balbib3112182008-09-20 04:14:03 +030092 void __iomem *base = wdev->base;
93
Komal Shah7768a132006-09-29 01:59:18 -070094 /* Sequence to enable the watchdog */
Victor Kamensky4a7e94a2013-11-16 02:01:05 +020095 writel_relaxed(0xBBBB, base + OMAP_WATCHDOG_SPR);
96 while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -070097 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +030098
Victor Kamensky4a7e94a2013-11-16 02:01:05 +020099 writel_relaxed(0x4444, base + OMAP_WATCHDOG_SPR);
100 while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -0700101 cpu_relax();
102}
103
Felipe Balbi28171422008-09-20 04:14:01 +0300104static void omap_wdt_disable(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -0700105{
Felipe Balbib3112182008-09-20 04:14:03 +0300106 void __iomem *base = wdev->base;
107
Komal Shah7768a132006-09-29 01:59:18 -0700108 /* sequence required to disable watchdog */
Victor Kamensky4a7e94a2013-11-16 02:01:05 +0200109 writel_relaxed(0xAAAA, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
110 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -0700111 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +0300112
Victor Kamensky4a7e94a2013-11-16 02:01:05 +0200113 writel_relaxed(0x5555, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
114 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -0700115 cpu_relax();
116}
117
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300118static void omap_wdt_set_timer(struct omap_wdt_dev *wdev,
119 unsigned int timeout)
Komal Shah7768a132006-09-29 01:59:18 -0700120{
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300121 u32 pre_margin = GET_WLDR_VAL(timeout);
Felipe Balbib3112182008-09-20 04:14:03 +0300122 void __iomem *base = wdev->base;
Komal Shah7768a132006-09-29 01:59:18 -0700123
124 /* just count up at 32 KHz */
Victor Kamensky4a7e94a2013-11-16 02:01:05 +0200125 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x04)
Komal Shah7768a132006-09-29 01:59:18 -0700126 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +0300127
Victor Kamensky4a7e94a2013-11-16 02:01:05 +0200128 writel_relaxed(pre_margin, base + OMAP_WATCHDOG_LDR);
129 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x04)
Komal Shah7768a132006-09-29 01:59:18 -0700130 cpu_relax();
131}
132
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300133static int omap_wdt_start(struct watchdog_device *wdog)
Komal Shah7768a132006-09-29 01:59:18 -0700134{
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200135 struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
Felipe Balbib3112182008-09-20 04:14:03 +0300136 void __iomem *base = wdev->base;
137
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300138 mutex_lock(&wdev->lock);
139
140 wdev->omap_wdt_users = true;
Komal Shah7768a132006-09-29 01:59:18 -0700141
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530142 pm_runtime_get_sync(wdev->dev);
Komal Shah7768a132006-09-29 01:59:18 -0700143
Uwe Kleine-König530c11d2015-04-29 20:38:46 +0200144 /*
145 * Make sure the watchdog is disabled. This is unfortunately required
146 * because writing to various registers with the watchdog running has no
147 * effect.
148 */
149 omap_wdt_disable(wdev);
150
Komal Shah7768a132006-09-29 01:59:18 -0700151 /* initialize prescaler */
Victor Kamensky4a7e94a2013-11-16 02:01:05 +0200152 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x01)
Komal Shah7768a132006-09-29 01:59:18 -0700153 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +0300154
Victor Kamensky4a7e94a2013-11-16 02:01:05 +0200155 writel_relaxed((1 << 5) | (PTV << 2), base + OMAP_WATCHDOG_CNTRL);
156 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x01)
Komal Shah7768a132006-09-29 01:59:18 -0700157 cpu_relax();
158
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300159 omap_wdt_set_timer(wdev, wdog->timeout);
160 omap_wdt_reload(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
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300163 mutex_unlock(&wdev->lock);
Felipe Balbib3112182008-09-20 04:14:03 +0300164
Komal Shah7768a132006-09-29 01:59:18 -0700165 return 0;
166}
167
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300168static int omap_wdt_stop(struct watchdog_device *wdog)
Komal Shah7768a132006-09-29 01:59:18 -0700169{
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200170 struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
Felipe Balbib3112182008-09-20 04:14:03 +0300171
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300172 mutex_lock(&wdev->lock);
173 omap_wdt_disable(wdev);
174 pm_runtime_put_sync(wdev->dev);
175 wdev->omap_wdt_users = false;
176 mutex_unlock(&wdev->lock);
177 return 0;
Komal Shah7768a132006-09-29 01:59:18 -0700178}
179
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300180static int omap_wdt_ping(struct watchdog_device *wdog)
Komal Shah7768a132006-09-29 01:59:18 -0700181{
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200182 struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
Felipe Balbib3112182008-09-20 04:14:03 +0300183
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300184 mutex_lock(&wdev->lock);
185 omap_wdt_reload(wdev);
186 mutex_unlock(&wdev->lock);
Komal Shah7768a132006-09-29 01:59:18 -0700187
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300188 return 0;
Komal Shah7768a132006-09-29 01:59:18 -0700189}
190
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300191static int omap_wdt_set_timeout(struct watchdog_device *wdog,
192 unsigned int timeout)
193{
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200194 struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300195
196 mutex_lock(&wdev->lock);
197 omap_wdt_disable(wdev);
198 omap_wdt_set_timer(wdev, timeout);
199 omap_wdt_enable(wdev);
200 omap_wdt_reload(wdev);
201 wdog->timeout = timeout;
202 mutex_unlock(&wdev->lock);
203
204 return 0;
205}
206
Lars Poeschel452fafe2015-06-17 10:58:59 +0200207static unsigned int omap_wdt_get_timeleft(struct watchdog_device *wdog)
208{
Peter Robinsonde55acd2015-11-02 02:20:20 +0000209 struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
Lars Poeschel452fafe2015-06-17 10:58:59 +0200210 void __iomem *base = wdev->base;
211 u32 value;
212
213 value = readl_relaxed(base + OMAP_WATCHDOG_CRR);
214 return GET_WCCR_SECS(value);
215}
216
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300217static const struct watchdog_info omap_wdt_info = {
Tony Lindgrenfb1cbea2014-10-14 12:25:19 -0700218 .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING,
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300219 .identity = "OMAP Watchdog",
220};
221
222static const struct watchdog_ops omap_wdt_ops = {
223 .owner = THIS_MODULE,
224 .start = omap_wdt_start,
225 .stop = omap_wdt_stop,
226 .ping = omap_wdt_ping,
227 .set_timeout = omap_wdt_set_timeout,
Lars Poeschel452fafe2015-06-17 10:58:59 +0200228 .get_timeleft = omap_wdt_get_timeleft,
Komal Shah7768a132006-09-29 01:59:18 -0700229};
230
Bill Pemberton2d991a12012-11-19 13:21:41 -0500231static int omap_wdt_probe(struct platform_device *pdev)
Komal Shah7768a132006-09-29 01:59:18 -0700232{
Jingoo Hanbc8fdfb2013-07-30 19:58:51 +0900233 struct omap_wd_timer_platform_data *pdata = dev_get_platdata(&pdev->dev);
Felipe Balbi28171422008-09-20 04:14:01 +0300234 struct omap_wdt_dev *wdev;
Felipe Balbib3112182008-09-20 04:14:03 +0300235 int ret;
Komal Shah7768a132006-09-29 01:59:18 -0700236
Aaro Koskinen4f4753d2012-10-10 23:23:33 +0300237 wdev = devm_kzalloc(&pdev->dev, sizeof(*wdev), GFP_KERNEL);
238 if (!wdev)
239 return -ENOMEM;
Felipe Balbib3112182008-09-20 04:14:03 +0300240
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300241 wdev->omap_wdt_users = false;
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300242 wdev->dev = &pdev->dev;
243 wdev->wdt_trgr_pattern = 0x1234;
244 mutex_init(&wdev->lock);
Komal Shah7768a132006-09-29 01:59:18 -0700245
Jingoo Han6e272062014-02-11 21:44:12 +0900246 /* reserve static register mappings */
Guenter Roeck0f0a6a22019-04-02 12:01:53 -0700247 wdev->base = devm_platform_ioremap_resource(pdev, 0);
Jingoo Han6e272062014-02-11 21:44:12 +0900248 if (IS_ERR(wdev->base))
249 return PTR_ERR(wdev->base);
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300250
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200251 wdev->wdog.info = &omap_wdt_info;
252 wdev->wdog.ops = &omap_wdt_ops;
253 wdev->wdog.min_timeout = TIMER_MARGIN_MIN;
254 wdev->wdog.max_timeout = TIMER_MARGIN_MAX;
Marcus Folkesson12537302018-02-10 21:36:21 +0100255 wdev->wdog.timeout = TIMER_MARGIN_DEFAULT;
Pratyush Anand65518812015-08-20 14:05:01 +0530256 wdev->wdog.parent = &pdev->dev;
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300257
Marcus Folkesson12537302018-02-10 21:36:21 +0100258 watchdog_init_timeout(&wdev->wdog, timer_margin, &pdev->dev);
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300259
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200260 watchdog_set_nowayout(&wdev->wdog, nowayout);
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300261
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200262 platform_set_drvdata(pdev, wdev);
Felipe Balbi28171422008-09-20 04:14:01 +0300263
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530264 pm_runtime_enable(wdev->dev);
265 pm_runtime_get_sync(wdev->dev);
Ulrik Bech Hald789cd472009-06-12 16:18:32 -0500266
Uwe Kleine-König0b3330f2015-04-27 11:23:01 +0200267 if (pdata && pdata->read_reset_sources) {
268 u32 rs = pdata->read_reset_sources();
269 if (rs & (1 << OMAP_MPU_WD_RST_SRC_ID_SHIFT))
270 wdev->wdog.bootstatus = WDIOF_CARDRESET;
271 }
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300272
Uwe Kleine-König8605fec2015-12-15 11:37:41 +0100273 if (!early_enable)
274 omap_wdt_disable(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700275
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200276 ret = watchdog_register_device(&wdev->wdog);
Aaro Koskinen1ba85382012-10-10 23:23:37 +0300277 if (ret) {
278 pm_runtime_disable(wdev->dev);
279 return ret;
280 }
Komal Shah7768a132006-09-29 01:59:18 -0700281
Felipe Balbi28171422008-09-20 04:14:01 +0300282 pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec\n",
Victor Kamensky4a7e94a2013-11-16 02:01:05 +0200283 readl_relaxed(wdev->base + OMAP_WATCHDOG_REV) & 0xFF,
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200284 wdev->wdog.timeout);
Komal Shah7768a132006-09-29 01:59:18 -0700285
Lars Poeschelb2102eb2015-06-25 12:21:51 +0200286 if (early_enable)
287 omap_wdt_start(&wdev->wdog);
288
Uwe Kleine-Königa6392492015-12-15 11:37:40 +0100289 pm_runtime_put(wdev->dev);
290
Komal Shah7768a132006-09-29 01:59:18 -0700291 return 0;
Komal Shah7768a132006-09-29 01:59:18 -0700292}
293
294static void omap_wdt_shutdown(struct platform_device *pdev)
295{
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200296 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
Felipe Balbi28171422008-09-20 04:14:01 +0300297
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300298 mutex_lock(&wdev->lock);
Paul Walmsley0503add2011-03-10 22:40:05 -0700299 if (wdev->omap_wdt_users) {
Felipe Balbi28171422008-09-20 04:14:01 +0300300 omap_wdt_disable(wdev);
Paul Walmsley0503add2011-03-10 22:40:05 -0700301 pm_runtime_put_sync(wdev->dev);
302 }
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300303 mutex_unlock(&wdev->lock);
Komal Shah7768a132006-09-29 01:59:18 -0700304}
305
Bill Pemberton4b12b892012-11-19 13:26:24 -0500306static int omap_wdt_remove(struct platform_device *pdev)
Komal Shah7768a132006-09-29 01:59:18 -0700307{
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200308 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
Felipe Balbi28171422008-09-20 04:14:01 +0300309
Shubhrajyoti D12c583d2012-01-11 19:50:18 +0530310 pm_runtime_disable(wdev->dev);
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200311 watchdog_unregister_device(&wdev->wdog);
Felipe Balbib3112182008-09-20 04:14:03 +0300312
Komal Shah7768a132006-09-29 01:59:18 -0700313 return 0;
314}
315
316#ifdef CONFIG_PM
317
318/* REVISIT ... not clear this is the best way to handle system suspend; and
319 * it's very inappropriate for selective device suspend (e.g. suspending this
320 * through sysfs rather than by stopping the watchdog daemon). Also, this
321 * may not play well enough with NOWAYOUT...
322 */
323
324static int omap_wdt_suspend(struct platform_device *pdev, pm_message_t state)
325{
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200326 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
Felipe Balbib3112182008-09-20 04:14:03 +0300327
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300328 mutex_lock(&wdev->lock);
Paul Walmsley0503add2011-03-10 22:40:05 -0700329 if (wdev->omap_wdt_users) {
Felipe Balbi28171422008-09-20 04:14:01 +0300330 omap_wdt_disable(wdev);
Paul Walmsley0503add2011-03-10 22:40:05 -0700331 pm_runtime_put_sync(wdev->dev);
332 }
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300333 mutex_unlock(&wdev->lock);
Felipe Balbib3112182008-09-20 04:14:03 +0300334
Komal Shah7768a132006-09-29 01:59:18 -0700335 return 0;
336}
337
338static int omap_wdt_resume(struct platform_device *pdev)
339{
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200340 struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
Felipe Balbib3112182008-09-20 04:14:03 +0300341
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300342 mutex_lock(&wdev->lock);
Felipe Balbi28171422008-09-20 04:14:01 +0300343 if (wdev->omap_wdt_users) {
Paul Walmsley0503add2011-03-10 22:40:05 -0700344 pm_runtime_get_sync(wdev->dev);
Felipe Balbi28171422008-09-20 04:14:01 +0300345 omap_wdt_enable(wdev);
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300346 omap_wdt_reload(wdev);
Komal Shah7768a132006-09-29 01:59:18 -0700347 }
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300348 mutex_unlock(&wdev->lock);
Felipe Balbib3112182008-09-20 04:14:03 +0300349
Komal Shah7768a132006-09-29 01:59:18 -0700350 return 0;
351}
352
353#else
354#define omap_wdt_suspend NULL
355#define omap_wdt_resume NULL
356#endif
357
Xiao Jiange6ca04e2012-06-01 12:44:16 +0800358static const struct of_device_id omap_wdt_of_match[] = {
359 { .compatible = "ti,omap3-wdt", },
360 {},
361};
362MODULE_DEVICE_TABLE(of, omap_wdt_of_match);
363
Komal Shah7768a132006-09-29 01:59:18 -0700364static struct platform_driver omap_wdt_driver = {
365 .probe = omap_wdt_probe,
Bill Pemberton82268712012-11-19 13:21:12 -0500366 .remove = omap_wdt_remove,
Komal Shah7768a132006-09-29 01:59:18 -0700367 .shutdown = omap_wdt_shutdown,
368 .suspend = omap_wdt_suspend,
369 .resume = omap_wdt_resume,
370 .driver = {
Komal Shah7768a132006-09-29 01:59:18 -0700371 .name = "omap_wdt",
Xiao Jiange6ca04e2012-06-01 12:44:16 +0800372 .of_match_table = omap_wdt_of_match,
Komal Shah7768a132006-09-29 01:59:18 -0700373 },
374};
375
Axel Linb8ec6112011-11-29 13:56:27 +0800376module_platform_driver(omap_wdt_driver);
Komal Shah7768a132006-09-29 01:59:18 -0700377
378MODULE_AUTHOR("George G. Davis");
379MODULE_LICENSE("GPL");
Kay Sieversf37d1932008-04-10 21:29:23 -0700380MODULE_ALIAS("platform:omap_wdt");