2019-06-20 16:28:46 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2006-09-29 08:59:18 +00:00
|
|
|
/*
|
2008-09-20 01:14:01 +00:00
|
|
|
* omap_wdt.c
|
2006-09-29 08:59:18 +00:00
|
|
|
*
|
2008-09-20 01:14:01 +00:00
|
|
|
* Watchdog driver for the TI OMAP 16xx & 24xx/34xx 32KHz (non-secure) watchdog
|
2006-09-29 08:59:18 +00:00
|
|
|
*
|
|
|
|
* Author: MontaVista Software, Inc.
|
|
|
|
* <gdavis@mvista.com> or <source@mvista.com>
|
|
|
|
*
|
2019-06-20 16:28:46 +00:00
|
|
|
* 2003 (c) MontaVista Software, Inc.
|
2006-09-29 08:59:18 +00:00
|
|
|
*
|
|
|
|
* 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>
|
2008-10-27 15:17:56 +00:00
|
|
|
* Based on SoftDog driver by Alan Cox <alan@lxorguk.ukuu.org.uk>
|
2006-09-29 08:59:18 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-02-15 23:06:19 +00:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2006-09-29 08:59:18 +00:00
|
|
|
#include <linux/module.h>
|
2018-06-20 05:47:28 +00:00
|
|
|
#include <linux/mod_devicetable.h>
|
2006-09-29 08:59:18 +00:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/mm.h>
|
|
|
|
#include <linux/watchdog.h>
|
|
|
|
#include <linux/reboot.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/moduleparam.h>
|
2008-07-15 11:46:11 +00:00
|
|
|
#include <linux/io.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/slab.h>
|
2010-09-23 14:32:43 +00:00
|
|
|
#include <linux/pm_runtime.h>
|
2012-10-30 02:49:44 +00:00
|
|
|
#include <linux/platform_data/omap-wd-timer.h>
|
2006-09-29 08:59:18 +00:00
|
|
|
|
|
|
|
#include "omap_wdt.h"
|
|
|
|
|
2013-02-16 23:49:26 +00:00
|
|
|
static bool nowayout = WATCHDOG_NOWAYOUT;
|
|
|
|
module_param(nowayout, bool, 0);
|
|
|
|
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started "
|
|
|
|
"(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
|
|
|
|
|
2006-09-29 08:59:18 +00:00
|
|
|
static unsigned timer_margin;
|
|
|
|
module_param(timer_margin, uint, 0);
|
|
|
|
MODULE_PARM_DESC(timer_margin, "initial watchdog timeout (in seconds)");
|
|
|
|
|
2015-04-27 09:23:00 +00:00
|
|
|
#define to_omap_wdt_dev(_wdog) container_of(_wdog, struct omap_wdt_dev, wdog)
|
|
|
|
|
2015-06-25 10:21:51 +00:00
|
|
|
static bool early_enable;
|
|
|
|
module_param(early_enable, bool, 0);
|
|
|
|
MODULE_PARM_DESC(early_enable,
|
|
|
|
"Watchdog is started on module insertion (default=0)");
|
|
|
|
|
2008-09-20 01:14:01 +00:00
|
|
|
struct omap_wdt_dev {
|
2015-04-27 09:23:00 +00:00
|
|
|
struct watchdog_device wdog;
|
2008-09-20 01:14:01 +00:00
|
|
|
void __iomem *base; /* physical */
|
|
|
|
struct device *dev;
|
2012-10-10 20:23:32 +00:00
|
|
|
bool omap_wdt_users;
|
|
|
|
int wdt_trgr_pattern;
|
|
|
|
struct mutex lock; /* to avoid races with PM */
|
2008-09-20 01:14:01 +00:00
|
|
|
};
|
|
|
|
|
2012-10-10 20:23:32 +00:00
|
|
|
static void omap_wdt_reload(struct omap_wdt_dev *wdev)
|
2006-09-29 08:59:18 +00:00
|
|
|
{
|
2008-09-20 01:14:01 +00:00
|
|
|
void __iomem *base = wdev->base;
|
2008-09-20 01:14:03 +00:00
|
|
|
|
2006-09-29 08:59:18 +00:00
|
|
|
/* wait for posted write to complete */
|
2013-11-16 00:01:05 +00:00
|
|
|
while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x08)
|
2006-09-29 08:59:18 +00:00
|
|
|
cpu_relax();
|
2008-09-20 01:14:03 +00:00
|
|
|
|
2012-10-10 20:23:32 +00:00
|
|
|
wdev->wdt_trgr_pattern = ~wdev->wdt_trgr_pattern;
|
2013-11-16 00:01:05 +00:00
|
|
|
writel_relaxed(wdev->wdt_trgr_pattern, (base + OMAP_WATCHDOG_TGR));
|
2008-09-20 01:14:03 +00:00
|
|
|
|
2006-09-29 08:59:18 +00:00
|
|
|
/* wait for posted write to complete */
|
2013-11-16 00:01:05 +00:00
|
|
|
while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x08)
|
2006-09-29 08:59:18 +00:00
|
|
|
cpu_relax();
|
|
|
|
/* reloaded WCRR from WLDR */
|
|
|
|
}
|
|
|
|
|
2008-09-20 01:14:01 +00:00
|
|
|
static void omap_wdt_enable(struct omap_wdt_dev *wdev)
|
2006-09-29 08:59:18 +00:00
|
|
|
{
|
2008-09-20 01:14:03 +00:00
|
|
|
void __iomem *base = wdev->base;
|
|
|
|
|
2006-09-29 08:59:18 +00:00
|
|
|
/* Sequence to enable the watchdog */
|
2013-11-16 00:01:05 +00:00
|
|
|
writel_relaxed(0xBBBB, base + OMAP_WATCHDOG_SPR);
|
|
|
|
while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x10)
|
2006-09-29 08:59:18 +00:00
|
|
|
cpu_relax();
|
2008-09-20 01:14:03 +00:00
|
|
|
|
2013-11-16 00:01:05 +00:00
|
|
|
writel_relaxed(0x4444, base + OMAP_WATCHDOG_SPR);
|
|
|
|
while ((readl_relaxed(base + OMAP_WATCHDOG_WPS)) & 0x10)
|
2006-09-29 08:59:18 +00:00
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
|
2008-09-20 01:14:01 +00:00
|
|
|
static void omap_wdt_disable(struct omap_wdt_dev *wdev)
|
2006-09-29 08:59:18 +00:00
|
|
|
{
|
2008-09-20 01:14:03 +00:00
|
|
|
void __iomem *base = wdev->base;
|
|
|
|
|
2006-09-29 08:59:18 +00:00
|
|
|
/* sequence required to disable watchdog */
|
2013-11-16 00:01:05 +00:00
|
|
|
writel_relaxed(0xAAAA, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
|
|
|
|
while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x10)
|
2006-09-29 08:59:18 +00:00
|
|
|
cpu_relax();
|
2008-09-20 01:14:03 +00:00
|
|
|
|
2013-11-16 00:01:05 +00:00
|
|
|
writel_relaxed(0x5555, base + OMAP_WATCHDOG_SPR); /* TIMER_MODE */
|
|
|
|
while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x10)
|
2006-09-29 08:59:18 +00:00
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
|
2012-10-10 20:23:32 +00:00
|
|
|
static void omap_wdt_set_timer(struct omap_wdt_dev *wdev,
|
|
|
|
unsigned int timeout)
|
2006-09-29 08:59:18 +00:00
|
|
|
{
|
2012-10-10 20:23:32 +00:00
|
|
|
u32 pre_margin = GET_WLDR_VAL(timeout);
|
2008-09-20 01:14:03 +00:00
|
|
|
void __iomem *base = wdev->base;
|
2006-09-29 08:59:18 +00:00
|
|
|
|
|
|
|
/* just count up at 32 KHz */
|
2013-11-16 00:01:05 +00:00
|
|
|
while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x04)
|
2006-09-29 08:59:18 +00:00
|
|
|
cpu_relax();
|
2008-09-20 01:14:03 +00:00
|
|
|
|
2013-11-16 00:01:05 +00:00
|
|
|
writel_relaxed(pre_margin, base + OMAP_WATCHDOG_LDR);
|
|
|
|
while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x04)
|
2006-09-29 08:59:18 +00:00
|
|
|
cpu_relax();
|
|
|
|
}
|
|
|
|
|
2012-10-10 20:23:32 +00:00
|
|
|
static int omap_wdt_start(struct watchdog_device *wdog)
|
2006-09-29 08:59:18 +00:00
|
|
|
{
|
2015-04-27 09:23:00 +00:00
|
|
|
struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
|
2008-09-20 01:14:03 +00:00
|
|
|
void __iomem *base = wdev->base;
|
|
|
|
|
2012-10-10 20:23:32 +00:00
|
|
|
mutex_lock(&wdev->lock);
|
|
|
|
|
|
|
|
wdev->omap_wdt_users = true;
|
2006-09-29 08:59:18 +00:00
|
|
|
|
2010-09-23 14:32:43 +00:00
|
|
|
pm_runtime_get_sync(wdev->dev);
|
2006-09-29 08:59:18 +00:00
|
|
|
|
2015-04-29 18:38:46 +00:00
|
|
|
/*
|
|
|
|
* Make sure the watchdog is disabled. This is unfortunately required
|
|
|
|
* because writing to various registers with the watchdog running has no
|
|
|
|
* effect.
|
|
|
|
*/
|
|
|
|
omap_wdt_disable(wdev);
|
|
|
|
|
2006-09-29 08:59:18 +00:00
|
|
|
/* initialize prescaler */
|
2013-11-16 00:01:05 +00:00
|
|
|
while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x01)
|
2006-09-29 08:59:18 +00:00
|
|
|
cpu_relax();
|
2008-09-20 01:14:03 +00:00
|
|
|
|
2013-11-16 00:01:05 +00:00
|
|
|
writel_relaxed((1 << 5) | (PTV << 2), base + OMAP_WATCHDOG_CNTRL);
|
|
|
|
while (readl_relaxed(base + OMAP_WATCHDOG_WPS) & 0x01)
|
2006-09-29 08:59:18 +00:00
|
|
|
cpu_relax();
|
|
|
|
|
2012-10-10 20:23:32 +00:00
|
|
|
omap_wdt_set_timer(wdev, wdog->timeout);
|
|
|
|
omap_wdt_reload(wdev); /* trigger loading of new timeout value */
|
2008-09-20 01:14:01 +00:00
|
|
|
omap_wdt_enable(wdev);
|
2008-09-20 01:14:03 +00:00
|
|
|
|
2012-10-10 20:23:32 +00:00
|
|
|
mutex_unlock(&wdev->lock);
|
|
|
|
|
|
|
|
return 0;
|
2006-09-29 08:59:18 +00:00
|
|
|
}
|
|
|
|
|
2012-10-10 20:23:32 +00:00
|
|
|
static int omap_wdt_stop(struct watchdog_device *wdog)
|
2006-09-29 08:59:18 +00:00
|
|
|
{
|
2015-04-27 09:23:00 +00:00
|
|
|
struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
|
2008-09-20 01:14:03 +00:00
|
|
|
|
2012-10-10 20:23:32 +00:00
|
|
|
mutex_lock(&wdev->lock);
|
2008-09-20 01:14:01 +00:00
|
|
|
omap_wdt_disable(wdev);
|
2010-09-23 14:32:43 +00:00
|
|
|
pm_runtime_put_sync(wdev->dev);
|
2012-10-10 20:23:32 +00:00
|
|
|
wdev->omap_wdt_users = false;
|
|
|
|
mutex_unlock(&wdev->lock);
|
2006-09-29 08:59:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-10-10 20:23:32 +00:00
|
|
|
static int omap_wdt_ping(struct watchdog_device *wdog)
|
2006-09-29 08:59:18 +00:00
|
|
|
{
|
2015-04-27 09:23:00 +00:00
|
|
|
struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
|
2008-09-20 01:14:03 +00:00
|
|
|
|
2012-10-10 20:23:32 +00:00
|
|
|
mutex_lock(&wdev->lock);
|
|
|
|
omap_wdt_reload(wdev);
|
|
|
|
mutex_unlock(&wdev->lock);
|
|
|
|
|
|
|
|
return 0;
|
2006-09-29 08:59:18 +00:00
|
|
|
}
|
|
|
|
|
2012-10-10 20:23:32 +00:00
|
|
|
static int omap_wdt_set_timeout(struct watchdog_device *wdog,
|
|
|
|
unsigned int timeout)
|
2006-09-29 08:59:18 +00:00
|
|
|
{
|
2015-04-27 09:23:00 +00:00
|
|
|
struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
|
2006-09-29 08:59:18 +00:00
|
|
|
|
2012-10-10 20:23:32 +00:00
|
|
|
mutex_lock(&wdev->lock);
|
|
|
|
omap_wdt_disable(wdev);
|
|
|
|
omap_wdt_set_timer(wdev, timeout);
|
|
|
|
omap_wdt_enable(wdev);
|
|
|
|
omap_wdt_reload(wdev);
|
|
|
|
wdog->timeout = timeout;
|
|
|
|
mutex_unlock(&wdev->lock);
|
|
|
|
|
|
|
|
return 0;
|
2006-09-29 08:59:18 +00:00
|
|
|
}
|
|
|
|
|
2015-06-17 08:58:59 +00:00
|
|
|
static unsigned int omap_wdt_get_timeleft(struct watchdog_device *wdog)
|
|
|
|
{
|
2015-11-02 02:20:20 +00:00
|
|
|
struct omap_wdt_dev *wdev = to_omap_wdt_dev(wdog);
|
2015-06-17 08:58:59 +00:00
|
|
|
void __iomem *base = wdev->base;
|
|
|
|
u32 value;
|
|
|
|
|
|
|
|
value = readl_relaxed(base + OMAP_WATCHDOG_CRR);
|
|
|
|
return GET_WCCR_SECS(value);
|
|
|
|
}
|
|
|
|
|
2012-10-10 20:23:32 +00:00
|
|
|
static const struct watchdog_info omap_wdt_info = {
|
2014-10-14 19:25:19 +00:00
|
|
|
.options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE | WDIOF_KEEPALIVEPING,
|
2012-10-10 20:23:32 +00:00
|
|
|
.identity = "OMAP Watchdog",
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct watchdog_ops omap_wdt_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.start = omap_wdt_start,
|
|
|
|
.stop = omap_wdt_stop,
|
|
|
|
.ping = omap_wdt_ping,
|
|
|
|
.set_timeout = omap_wdt_set_timeout,
|
2015-06-17 08:58:59 +00:00
|
|
|
.get_timeleft = omap_wdt_get_timeleft,
|
2006-09-29 08:59:18 +00:00
|
|
|
};
|
|
|
|
|
2012-11-19 18:21:41 +00:00
|
|
|
static int omap_wdt_probe(struct platform_device *pdev)
|
2006-09-29 08:59:18 +00:00
|
|
|
{
|
2013-07-30 10:58:51 +00:00
|
|
|
struct omap_wd_timer_platform_data *pdata = dev_get_platdata(&pdev->dev);
|
2008-09-20 01:14:01 +00:00
|
|
|
struct omap_wdt_dev *wdev;
|
2008-09-20 01:14:03 +00:00
|
|
|
int ret;
|
2006-09-29 08:59:18 +00:00
|
|
|
|
2012-10-10 20:23:33 +00:00
|
|
|
wdev = devm_kzalloc(&pdev->dev, sizeof(*wdev), GFP_KERNEL);
|
|
|
|
if (!wdev)
|
|
|
|
return -ENOMEM;
|
2008-09-20 01:14:03 +00:00
|
|
|
|
2012-10-10 20:23:32 +00:00
|
|
|
wdev->omap_wdt_users = false;
|
|
|
|
wdev->dev = &pdev->dev;
|
|
|
|
wdev->wdt_trgr_pattern = 0x1234;
|
|
|
|
mutex_init(&wdev->lock);
|
2008-09-20 01:14:01 +00:00
|
|
|
|
2014-02-11 12:44:12 +00:00
|
|
|
/* reserve static register mappings */
|
watchdog: Convert to use devm_platform_ioremap_resource
Use devm_platform_ioremap_resource to reduce source code size,
improve readability, and reduce the likelyhood of bugs.
The conversion was done automatically with coccinelle using the
following semantic patch.
@r@
identifier res, pdev;
expression a;
expression index;
expression e;
@@
<+...
- res = platform_get_resource(pdev, IORESOURCE_MEM, index);
- a = devm_ioremap_resource(e, res);
+ a = devm_platform_ioremap_resource(pdev, index);
...+>
@depends on r@
identifier r.res;
@@
- struct resource *res;
... when != res
@@
identifier res, pdev;
expression index;
expression a;
@@
- struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, index);
- a = devm_ioremap_resource(&pdev->dev, res);
+ a = devm_platform_ioremap_resource(pdev, index);
Cc: Joel Stanley <joel@jms.id.au>
Cc: Nicolas Ferre <nicolas.ferre@microchip.com>
Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Baruch Siach <baruch@tkos.co.il>
Cc: Keguang Zhang <keguang.zhang@gmail.com>
Cc: Vladimir Zapolskiy <vz@mleia.com>
Cc: Kevin Hilman <khilman@baylibre.com>
Cc: Matthias Brugger <matthias.bgg@gmail.com>
Cc: Avi Fishman <avifishman70@gmail.com>
Cc: Nancy Yuen <yuenn@google.com>
Cc: Brendan Higgins <brendanhiggins@google.com>
Cc: Wan ZongShun <mcuos.com@gmail.com>
Cc: Michal Simek <michal.simek@xilinx.com>
Cc: Sylvain Lemieux <slemieux.tyco@gmail.com>
Cc: Kukjin Kim <kgene@kernel.org>
Cc: Barry Song <baohua@kernel.org>
Cc: Orson Zhai <orsonzhai@gmail.com>
Cc: Patrice Chotard <patrice.chotard@st.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Maxime Ripard <maxime.ripard@bootlin.com>
Cc: Chen-Yu Tsai <wens@csie.org>
Cc: Marc Gonzalez <marc.w.gonzalez@free.fr>
Cc: Thierry Reding <thierry.reding@gmail.com>
Cc: Shawn Guo <shawnguo@kernel.org>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Tested-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Acked-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Acked-by: Maxime Ripard <maxime.ripard@bootlin.com>
Acked-by: Michal Simek <michal.simek@xilinx.com> (cadence/xilinx wdts)
Acked-by: Thierry Reding <treding@nvidia.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Acked-by: Patrice Chotard <patrice.chotard@st.com>
Acked-by: Vladimir Zapolskiy <vz@mleia.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Signed-off-by: Wim Van Sebroeck <wim@linux-watchdog.org>
2019-04-02 19:01:53 +00:00
|
|
|
wdev->base = devm_platform_ioremap_resource(pdev, 0);
|
2014-02-11 12:44:12 +00:00
|
|
|
if (IS_ERR(wdev->base))
|
|
|
|
return PTR_ERR(wdev->base);
|
2008-09-20 01:14:02 +00:00
|
|
|
|
2015-04-27 09:23:00 +00:00
|
|
|
wdev->wdog.info = &omap_wdt_info;
|
|
|
|
wdev->wdog.ops = &omap_wdt_ops;
|
|
|
|
wdev->wdog.min_timeout = TIMER_MARGIN_MIN;
|
|
|
|
wdev->wdog.max_timeout = TIMER_MARGIN_MAX;
|
2018-02-10 20:36:21 +00:00
|
|
|
wdev->wdog.timeout = TIMER_MARGIN_DEFAULT;
|
2015-08-20 08:35:01 +00:00
|
|
|
wdev->wdog.parent = &pdev->dev;
|
2012-10-10 20:23:32 +00:00
|
|
|
|
2018-02-10 20:36:21 +00:00
|
|
|
watchdog_init_timeout(&wdev->wdog, timer_margin, &pdev->dev);
|
2012-10-10 20:23:32 +00:00
|
|
|
|
2015-04-27 09:23:00 +00:00
|
|
|
watchdog_set_nowayout(&wdev->wdog, nowayout);
|
2012-10-10 20:23:32 +00:00
|
|
|
|
2015-04-27 09:23:00 +00:00
|
|
|
platform_set_drvdata(pdev, wdev);
|
2006-09-29 08:59:18 +00:00
|
|
|
|
2010-09-23 14:32:43 +00:00
|
|
|
pm_runtime_enable(wdev->dev);
|
|
|
|
pm_runtime_get_sync(wdev->dev);
|
2009-06-12 21:18:32 +00:00
|
|
|
|
2015-04-27 09:23:01 +00:00
|
|
|
if (pdata && pdata->read_reset_sources) {
|
|
|
|
u32 rs = pdata->read_reset_sources();
|
|
|
|
if (rs & (1 << OMAP_MPU_WD_RST_SRC_ID_SHIFT))
|
|
|
|
wdev->wdog.bootstatus = WDIOF_CARDRESET;
|
|
|
|
}
|
2006-09-29 08:59:18 +00:00
|
|
|
|
2015-12-15 10:37:41 +00:00
|
|
|
if (!early_enable)
|
|
|
|
omap_wdt_disable(wdev);
|
2008-09-20 01:14:01 +00:00
|
|
|
|
2015-04-27 09:23:00 +00:00
|
|
|
ret = watchdog_register_device(&wdev->wdog);
|
2012-10-10 20:23:37 +00:00
|
|
|
if (ret) {
|
2020-05-21 08:01:41 +00:00
|
|
|
pm_runtime_put(wdev->dev);
|
2012-10-10 20:23:37 +00:00
|
|
|
pm_runtime_disable(wdev->dev);
|
|
|
|
return ret;
|
|
|
|
}
|
2006-09-29 08:59:18 +00:00
|
|
|
|
2008-09-20 01:14:01 +00:00
|
|
|
pr_info("OMAP Watchdog Timer Rev 0x%02x: initial timeout %d sec\n",
|
2013-11-16 00:01:05 +00:00
|
|
|
readl_relaxed(wdev->base + OMAP_WATCHDOG_REV) & 0xFF,
|
2015-04-27 09:23:00 +00:00
|
|
|
wdev->wdog.timeout);
|
2006-09-29 08:59:18 +00:00
|
|
|
|
2015-06-25 10:21:51 +00:00
|
|
|
if (early_enable)
|
|
|
|
omap_wdt_start(&wdev->wdog);
|
|
|
|
|
2015-12-15 10:37:40 +00:00
|
|
|
pm_runtime_put(wdev->dev);
|
|
|
|
|
2006-09-29 08:59:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void omap_wdt_shutdown(struct platform_device *pdev)
|
|
|
|
{
|
2015-04-27 09:23:00 +00:00
|
|
|
struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
|
2008-09-20 01:14:01 +00:00
|
|
|
|
2012-10-10 20:23:32 +00:00
|
|
|
mutex_lock(&wdev->lock);
|
2011-03-11 05:40:05 +00:00
|
|
|
if (wdev->omap_wdt_users) {
|
2008-09-20 01:14:01 +00:00
|
|
|
omap_wdt_disable(wdev);
|
2011-03-11 05:40:05 +00:00
|
|
|
pm_runtime_put_sync(wdev->dev);
|
|
|
|
}
|
2012-10-10 20:23:32 +00:00
|
|
|
mutex_unlock(&wdev->lock);
|
2006-09-29 08:59:18 +00:00
|
|
|
}
|
|
|
|
|
2012-11-19 18:26:24 +00:00
|
|
|
static int omap_wdt_remove(struct platform_device *pdev)
|
2006-09-29 08:59:18 +00:00
|
|
|
{
|
2015-04-27 09:23:00 +00:00
|
|
|
struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
|
2008-09-20 01:14:01 +00:00
|
|
|
|
2012-01-11 14:20:18 +00:00
|
|
|
pm_runtime_disable(wdev->dev);
|
2015-04-27 09:23:00 +00:00
|
|
|
watchdog_unregister_device(&wdev->wdog);
|
2008-09-20 01:14:03 +00:00
|
|
|
|
2006-09-29 08:59:18 +00:00
|
|
|
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)
|
|
|
|
{
|
2015-04-27 09:23:00 +00:00
|
|
|
struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
|
2008-09-20 01:14:03 +00:00
|
|
|
|
2012-10-10 20:23:32 +00:00
|
|
|
mutex_lock(&wdev->lock);
|
2011-03-11 05:40:05 +00:00
|
|
|
if (wdev->omap_wdt_users) {
|
2008-09-20 01:14:01 +00:00
|
|
|
omap_wdt_disable(wdev);
|
2011-03-11 05:40:05 +00:00
|
|
|
pm_runtime_put_sync(wdev->dev);
|
|
|
|
}
|
2012-10-10 20:23:32 +00:00
|
|
|
mutex_unlock(&wdev->lock);
|
2008-09-20 01:14:03 +00:00
|
|
|
|
2006-09-29 08:59:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int omap_wdt_resume(struct platform_device *pdev)
|
|
|
|
{
|
2015-04-27 09:23:00 +00:00
|
|
|
struct omap_wdt_dev *wdev = platform_get_drvdata(pdev);
|
2008-09-20 01:14:03 +00:00
|
|
|
|
2012-10-10 20:23:32 +00:00
|
|
|
mutex_lock(&wdev->lock);
|
2008-09-20 01:14:01 +00:00
|
|
|
if (wdev->omap_wdt_users) {
|
2011-03-11 05:40:05 +00:00
|
|
|
pm_runtime_get_sync(wdev->dev);
|
2008-09-20 01:14:01 +00:00
|
|
|
omap_wdt_enable(wdev);
|
2012-10-10 20:23:32 +00:00
|
|
|
omap_wdt_reload(wdev);
|
2006-09-29 08:59:18 +00:00
|
|
|
}
|
2012-10-10 20:23:32 +00:00
|
|
|
mutex_unlock(&wdev->lock);
|
2008-09-20 01:14:03 +00:00
|
|
|
|
2006-09-29 08:59:18 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define omap_wdt_suspend NULL
|
|
|
|
#define omap_wdt_resume NULL
|
|
|
|
#endif
|
|
|
|
|
2012-06-01 04:44:16 +00:00
|
|
|
static const struct of_device_id omap_wdt_of_match[] = {
|
|
|
|
{ .compatible = "ti,omap3-wdt", },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, omap_wdt_of_match);
|
|
|
|
|
2006-09-29 08:59:18 +00:00
|
|
|
static struct platform_driver omap_wdt_driver = {
|
|
|
|
.probe = omap_wdt_probe,
|
2012-11-19 18:21:12 +00:00
|
|
|
.remove = omap_wdt_remove,
|
2006-09-29 08:59:18 +00:00
|
|
|
.shutdown = omap_wdt_shutdown,
|
|
|
|
.suspend = omap_wdt_suspend,
|
|
|
|
.resume = omap_wdt_resume,
|
|
|
|
.driver = {
|
|
|
|
.name = "omap_wdt",
|
2012-06-01 04:44:16 +00:00
|
|
|
.of_match_table = omap_wdt_of_match,
|
2006-09-29 08:59:18 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2011-11-29 05:56:27 +00:00
|
|
|
module_platform_driver(omap_wdt_driver);
|
2006-09-29 08:59:18 +00:00
|
|
|
|
|
|
|
MODULE_AUTHOR("George G. Davis");
|
|
|
|
MODULE_LICENSE("GPL");
|
2008-04-11 04:29:23 +00:00
|
|
|
MODULE_ALIAS("platform:omap_wdt");
|