blob: 6f17c935a6cf86b1fcb47856532a8d6374bd0d82 [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/err.h>
38#include <linux/platform_device.h>
39#include <linux/moduleparam.h>
Wim Van Sebroeck089ab072008-07-15 11:46:11 +000040#include <linux/io.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +053042#include <linux/pm_runtime.h>
Paul Walmsley129f5572012-10-29 20:49:44 -060043#include <linux/platform_data/omap-wd-timer.h>
Komal Shah7768a132006-09-29 01:59:18 -070044
45#include "omap_wdt.h"
46
Pali Rohár2dd7b242013-02-17 00:49:26 +010047static bool nowayout = WATCHDOG_NOWAYOUT;
48module_param(nowayout, bool, 0);
49MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
50 "(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
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
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +020056#define to_omap_wdt_dev(_wdog) container_of(_wdog, struct omap_wdt_dev, wdog)
57
Lars Poeschelb2102eb2015-06-25 12:21:51 +020058static bool early_enable;
59module_param(early_enable, bool, 0);
60MODULE_PARM_DESC(early_enable,
61 "Watchdog is started on module insertion (default=0)");
62
Felipe Balbi28171422008-09-20 04:14:01 +030063struct omap_wdt_dev {
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +020064 struct watchdog_device wdog;
Felipe Balbi28171422008-09-20 04:14:01 +030065 void __iomem *base; /* physical */
66 struct device *dev;
Aaro Koskinen67c0f552012-10-10 23:23:32 +030067 bool omap_wdt_users;
Aaro Koskinen67c0f552012-10-10 23:23:32 +030068 int wdt_trgr_pattern;
69 struct mutex lock; /* to avoid races with PM */
Felipe Balbi28171422008-09-20 04:14:01 +030070};
71
Aaro Koskinen67c0f552012-10-10 23:23:32 +030072static void omap_wdt_reload(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -070073{
Felipe Balbi28171422008-09-20 04:14:01 +030074 void __iomem *base = wdev->base;
Felipe Balbib3112182008-09-20 04:14:03 +030075
Komal Shah7768a132006-09-29 01:59:18 -070076 /* wait for posted write to complete */
Victor Kamensky4a7e94a2013-11-16 02:01:05 +020077 while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x08)
Komal Shah7768a132006-09-29 01:59:18 -070078 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +030079
Aaro Koskinen67c0f552012-10-10 23:23:32 +030080 wdev->wdt_trgr_pattern = ~wdev->wdt_trgr_pattern;
Victor Kamensky4a7e94a2013-11-16 02:01:05 +020081 writel_relaxed(wdev->wdt_trgr_pattern, (base + OMAP_WATCHDOG_TGR));
Felipe Balbib3112182008-09-20 04:14:03 +030082
Komal Shah7768a132006-09-29 01:59:18 -070083 /* wait for posted write to complete */
Victor Kamensky4a7e94a2013-11-16 02:01:05 +020084 while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x08)
Komal Shah7768a132006-09-29 01:59:18 -070085 cpu_relax();
86 /* reloaded WCRR from WLDR */
87}
88
Felipe Balbi28171422008-09-20 04:14:01 +030089static void omap_wdt_enable(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -070090{
Felipe Balbib3112182008-09-20 04:14:03 +030091 void __iomem *base = wdev->base;
92
Komal Shah7768a132006-09-29 01:59:18 -070093 /* Sequence to enable the watchdog */
Victor Kamensky4a7e94a2013-11-16 02:01:05 +020094 writel_relaxed(0xBBBB, base + OMAP_WATCHDOG_SPR);
95 while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -070096 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +030097
Victor Kamensky4a7e94a2013-11-16 02:01:05 +020098 writel_relaxed(0x4444, base + OMAP_WATCHDOG_SPR);
99 while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -0700100 cpu_relax();
101}
102
Felipe Balbi28171422008-09-20 04:14:01 +0300103static void omap_wdt_disable(struct omap_wdt_dev *wdev)
Komal Shah7768a132006-09-29 01:59:18 -0700104{
Felipe Balbib3112182008-09-20 04:14:03 +0300105 void __iomem *base = wdev->base;
106
Komal Shah7768a132006-09-29 01:59:18 -0700107 /* sequence required to disable watchdog */
Victor Kamensky4a7e94a2013-11-16 02:01:05 +0200108 writel_relaxed(0xAAAA, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
109 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -0700110 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +0300111
Victor Kamensky4a7e94a2013-11-16 02:01:05 +0200112 writel_relaxed(0x5555, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
113 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x10)
Komal Shah7768a132006-09-29 01:59:18 -0700114 cpu_relax();
115}
116
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300117static void omap_wdt_set_timer(struct omap_wdt_dev *wdev,
118 unsigned int timeout)
Komal Shah7768a132006-09-29 01:59:18 -0700119{
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300120 u32 pre_margin = GET_WLDR_VAL(timeout);
Felipe Balbib3112182008-09-20 04:14:03 +0300121 void __iomem *base = wdev->base;
Komal Shah7768a132006-09-29 01:59:18 -0700122
123 /* just count up at 32 KHz */
Victor Kamensky4a7e94a2013-11-16 02:01:05 +0200124 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x04)
Komal Shah7768a132006-09-29 01:59:18 -0700125 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +0300126
Victor Kamensky4a7e94a2013-11-16 02:01:05 +0200127 writel_relaxed(pre_margin, base + OMAP_WATCHDOG_LDR);
128 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x04)
Komal Shah7768a132006-09-29 01:59:18 -0700129 cpu_relax();
130}
131
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300132static int omap_wdt_start(struct watchdog_device *wdog)
Komal Shah7768a132006-09-29 01:59:18 -0700133{
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200134 struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
Felipe Balbib3112182008-09-20 04:14:03 +0300135 void __iomem *base = wdev->base;
136
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300137 mutex_lock(&wdev->lock);
138
139 wdev->omap_wdt_users = true;
Komal Shah7768a132006-09-29 01:59:18 -0700140
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530141 pm_runtime_get_sync(wdev->dev);
Komal Shah7768a132006-09-29 01:59:18 -0700142
Uwe Kleine-König530c11d2015-04-29 20:38:46 +0200143 /*
144 * Make sure the watchdog is disabled. This is unfortunately required
145 * because writing to various registers with the watchdog running has no
146 * effect.
147 */
148 omap_wdt_disable(wdev);
149
Komal Shah7768a132006-09-29 01:59:18 -0700150 /* initialize prescaler */
Victor Kamensky4a7e94a2013-11-16 02:01:05 +0200151 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x01)
Komal Shah7768a132006-09-29 01:59:18 -0700152 cpu_relax();
Felipe Balbib3112182008-09-20 04:14:03 +0300153
Victor Kamensky4a7e94a2013-11-16 02:01:05 +0200154 writel_relaxed((1 << 5) | (PTV << 2), base + OMAP_WATCHDOG_CNTRL);
155 while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x01)
Komal Shah7768a132006-09-29 01:59:18 -0700156 cpu_relax();
157
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300158 omap_wdt_set_timer(wdev, wdog->timeout);
159 omap_wdt_reload(wdev); /* trigger loading of new timeout value */
Felipe Balbi28171422008-09-20 04:14:01 +0300160 omap_wdt_enable(wdev);
Felipe Balbib3112182008-09-20 04:14:03 +0300161
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300162 mutex_unlock(&wdev->lock);
Felipe Balbib3112182008-09-20 04:14:03 +0300163
Komal Shah7768a132006-09-29 01:59:18 -0700164 return 0;
165}
166
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300167static int omap_wdt_stop(struct watchdog_device *wdog)
Komal Shah7768a132006-09-29 01:59:18 -0700168{
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200169 struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
Felipe Balbib3112182008-09-20 04:14:03 +0300170
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300171 mutex_lock(&wdev->lock);
172 omap_wdt_disable(wdev);
173 pm_runtime_put_sync(wdev->dev);
174 wdev->omap_wdt_users = false;
175 mutex_unlock(&wdev->lock);
176 return 0;
Komal Shah7768a132006-09-29 01:59:18 -0700177}
178
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300179static int omap_wdt_ping(struct watchdog_device *wdog)
Komal Shah7768a132006-09-29 01:59:18 -0700180{
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200181 struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
Felipe Balbib3112182008-09-20 04:14:03 +0300182
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300183 mutex_lock(&wdev->lock);
184 omap_wdt_reload(wdev);
185 mutex_unlock(&wdev->lock);
Komal Shah7768a132006-09-29 01:59:18 -0700186
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300187 return 0;
Komal Shah7768a132006-09-29 01:59:18 -0700188}
189
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300190static int omap_wdt_set_timeout(struct watchdog_device *wdog,
191 unsigned int timeout)
192{
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200193 struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300194
195 mutex_lock(&wdev->lock);
196 omap_wdt_disable(wdev);
197 omap_wdt_set_timer(wdev, timeout);
198 omap_wdt_enable(wdev);
199 omap_wdt_reload(wdev);
200 wdog->timeout = timeout;
201 mutex_unlock(&wdev->lock);
202
203 return 0;
204}
205
Lars Poeschel452fafe2015-06-17 10:58:59 +0200206static unsigned int omap_wdt_get_timeleft(struct watchdog_device *wdog)
207{
Peter Robinsonde55acd2015-11-02 02:20:20 +0000208 struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
Lars Poeschel452fafe2015-06-17 10:58:59 +0200209 void __iomem *base = wdev->base;
210 u32 value;
211
212 value = readl_relaxed(base + OMAP_WATCHDOG_CRR);
213 return GET_WCCR_SECS(value);
214}
215
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300216static const struct watchdog_info omap_wdt_info = {
Tony Lindgrenfb1cbea2014-10-14 12:25:19 -0700217 .options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING,
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300218 .identity = "OMAP Watchdog",
219};
220
221static const struct watchdog_ops omap_wdt_ops = {
222 .owner = THIS_MODULE,
223 .start = omap_wdt_start,
224 .stop = omap_wdt_stop,
225 .ping = omap_wdt_ping,
226 .set_timeout = omap_wdt_set_timeout,
Lars Poeschel452fafe2015-06-17 10:58:59 +0200227 .get_timeleft = omap_wdt_get_timeleft,
Komal Shah7768a132006-09-29 01:59:18 -0700228};
229
Bill Pemberton2d991a12012-11-19 13:21:41 -0500230static int omap_wdt_probe(struct platform_device *pdev)
Komal Shah7768a132006-09-29 01:59:18 -0700231{
Jingoo Hanbc8fdfb2013-07-30 19:58:51 +0900232 struct omap_wd_timer_platform_data *pdata = dev_get_platdata(&pdev->dev);
Jingoo Han6e272062014-02-11 21:44:12 +0900233 struct resource *res;
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 */
247 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
248 wdev->base = devm_ioremap_resource(&pdev->dev, res);
249 if (IS_ERR(wdev->base))
250 return PTR_ERR(wdev->base);
Felipe Balbi9f69e3b2008-09-20 04:14:02 +0300251
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200252 wdev->wdog.info = &omap_wdt_info;
253 wdev->wdog.ops = &omap_wdt_ops;
254 wdev->wdog.min_timeout = TIMER_MARGIN_MIN;
255 wdev->wdog.max_timeout = TIMER_MARGIN_MAX;
Pratyush Anand65518812015-08-20 14:05:01 +0530256 wdev->wdog.parent = &pdev->dev;
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300257
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200258 if (watchdog_init_timeout(&wdev->wdog, timer_margin, &pdev->dev) < 0)
259 wdev->wdog.timeout = TIMER_MARGIN_DEFAULT;
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300260
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200261 watchdog_set_nowayout(&wdev->wdog, nowayout);
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300262
Uwe Kleine-Königd2f78262015-04-27 11:23:00 +0200263 platform_set_drvdata(pdev, wdev);
Felipe Balbi28171422008-09-20 04:14:01 +0300264
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530265 pm_runtime_enable(wdev->dev);
266 pm_runtime_get_sync(wdev->dev);
Ulrik Bech Hald789cd472009-06-12 16:18:32 -0500267
Uwe Kleine-König0b3330f2015-04-27 11:23:01 +0200268 if (pdata && pdata->read_reset_sources) {
269 u32 rs = pdata->read_reset_sources();
270 if (rs & (1 << OMAP_MPU_WD_RST_SRC_ID_SHIFT))
271 wdev->wdog.bootstatus = WDIOF_CARDRESET;
272 }
Aaro Koskinen67c0f552012-10-10 23:23:32 +0300273
Felipe Balbi28171422008-09-20 04:14:01 +0300274 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
Varadarajan, Charulatha7ec5ad02010-09-23 20:02:43 +0530286 pm_runtime_put_sync(wdev->dev);
Ulrik Bech Hald789cd472009-06-12 16:18:32 -0500287
Lars Poeschelb2102eb2015-06-25 12:21:51 +0200288 if (early_enable)
289 omap_wdt_start(&wdev->wdog);
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");