2010-02-05 04:08:56 +08:00
|
|
|
/*
|
|
|
|
* drivers/char/watchdog/max63xx_wdt.c
|
|
|
|
*
|
|
|
|
* Driver for max63{69,70,71,72,73,74} watchdog timers
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Marc Zyngier <maz@misterjones.org>
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This driver assumes the watchdog pins are memory mapped (as it is
|
|
|
|
* the case for the Arcom Zeus). Should it be connected over GPIOs or
|
|
|
|
* another interface, some abstraction will have to be introduced.
|
|
|
|
*/
|
|
|
|
|
2013-01-21 18:09:25 +08:00
|
|
|
#include <linux/err.h>
|
2010-02-05 04:08:56 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
2018-06-20 13:47:28 +08:00
|
|
|
#include <linux/mod_devicetable.h>
|
2010-02-05 04:08:56 +08:00
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/watchdog.h>
|
|
|
|
#include <linux/bitops.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/spinlock.h>
|
|
|
|
#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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2010-02-05 04:08:56 +08:00
|
|
|
|
|
|
|
#define DEFAULT_HEARTBEAT 60
|
|
|
|
#define MAX_HEARTBEAT 60
|
|
|
|
|
2012-02-08 14:24:10 +08:00
|
|
|
static unsigned int heartbeat = DEFAULT_HEARTBEAT;
|
2012-03-05 23:51:11 +08:00
|
|
|
static bool nowayout = WATCHDOG_NOWAYOUT;
|
2010-02-05 04:08:56 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Memory mapping: a single byte, 3 first lower bits to select bit 3
|
|
|
|
* to ping the watchdog.
|
|
|
|
*/
|
|
|
|
#define MAX6369_WDSET (7 << 0)
|
2011-02-24 04:04:38 +08:00
|
|
|
#define MAX6369_WDI (1 << 3)
|
2010-02-05 04:08:56 +08:00
|
|
|
|
2015-06-18 06:58:58 +08:00
|
|
|
#define MAX6369_WDSET_DISABLED 3
|
2010-02-05 04:08:56 +08:00
|
|
|
|
|
|
|
static int nodelay;
|
2015-06-18 06:58:58 +08:00
|
|
|
|
|
|
|
struct max63xx_wdt {
|
|
|
|
struct watchdog_device wdd;
|
|
|
|
const struct max63xx_timeout *timeout;
|
|
|
|
|
|
|
|
/* memory mapping */
|
|
|
|
void __iomem *base;
|
|
|
|
spinlock_t lock;
|
|
|
|
|
|
|
|
/* WDI and WSET bits write access routines */
|
|
|
|
void (*ping)(struct max63xx_wdt *wdt);
|
|
|
|
void (*set)(struct max63xx_wdt *wdt, u8 set);
|
|
|
|
};
|
2010-02-05 04:08:56 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The timeout values used are actually the absolute minimum the chip
|
|
|
|
* offers. Typical values on my board are slightly over twice as long
|
|
|
|
* (10s setting ends up with a 25s timeout), and can be up to 3 times
|
|
|
|
* the nominal setting (according to the datasheet). So please take
|
|
|
|
* these values with a grain of salt. Same goes for the initial delay
|
|
|
|
* "feature". Only max6373/74 have a few settings without this initial
|
|
|
|
* delay (selected with the "nodelay" parameter).
|
|
|
|
*
|
|
|
|
* I also decided to remove from the tables any timeout smaller than a
|
|
|
|
* second, as it looked completly overkill...
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Timeouts in second */
|
|
|
|
struct max63xx_timeout {
|
2015-06-18 06:58:58 +08:00
|
|
|
const u8 wdset;
|
|
|
|
const u8 tdelay;
|
|
|
|
const u8 twd;
|
2010-02-05 04:08:56 +08:00
|
|
|
};
|
|
|
|
|
2015-06-18 06:58:58 +08:00
|
|
|
static const struct max63xx_timeout max6369_table[] = {
|
2010-02-05 04:08:56 +08:00
|
|
|
{ 5, 1, 1 },
|
|
|
|
{ 6, 10, 10 },
|
|
|
|
{ 7, 60, 60 },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
2015-06-18 06:58:58 +08:00
|
|
|
static const struct max63xx_timeout max6371_table[] = {
|
2010-02-05 04:08:56 +08:00
|
|
|
{ 6, 60, 3 },
|
|
|
|
{ 7, 60, 60 },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
2015-06-18 06:58:58 +08:00
|
|
|
static const struct max63xx_timeout max6373_table[] = {
|
2010-02-05 04:08:56 +08:00
|
|
|
{ 2, 60, 1 },
|
|
|
|
{ 5, 0, 1 },
|
|
|
|
{ 1, 3, 3 },
|
|
|
|
{ 7, 60, 10 },
|
|
|
|
{ 6, 0, 10 },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct max63xx_timeout *
|
|
|
|
max63xx_select_timeout(struct max63xx_timeout *table, int value)
|
|
|
|
{
|
|
|
|
while (table->twd) {
|
|
|
|
if (value <= table->twd) {
|
|
|
|
if (nodelay && table->tdelay == 0)
|
|
|
|
return table;
|
|
|
|
|
|
|
|
if (!nodelay)
|
|
|
|
return table;
|
|
|
|
}
|
|
|
|
|
|
|
|
table++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-02-08 14:24:10 +08:00
|
|
|
static int max63xx_wdt_ping(struct watchdog_device *wdd)
|
2010-02-05 04:08:56 +08:00
|
|
|
{
|
2015-06-18 06:58:58 +08:00
|
|
|
struct max63xx_wdt *wdt = watchdog_get_drvdata(wdd);
|
2010-02-05 04:08:56 +08:00
|
|
|
|
2015-06-18 06:58:58 +08:00
|
|
|
wdt->ping(wdt);
|
2012-02-08 14:24:10 +08:00
|
|
|
return 0;
|
2010-02-05 04:08:56 +08:00
|
|
|
}
|
|
|
|
|
2012-02-08 14:24:10 +08:00
|
|
|
static int max63xx_wdt_start(struct watchdog_device *wdd)
|
2010-02-05 04:08:56 +08:00
|
|
|
{
|
2015-06-18 06:58:58 +08:00
|
|
|
struct max63xx_wdt *wdt = watchdog_get_drvdata(wdd);
|
2010-02-05 04:08:56 +08:00
|
|
|
|
2015-06-18 06:58:58 +08:00
|
|
|
wdt->set(wdt, wdt->timeout->wdset);
|
2010-02-05 04:08:56 +08:00
|
|
|
|
|
|
|
/* check for a edge triggered startup */
|
2015-06-18 06:58:58 +08:00
|
|
|
if (wdt->timeout->tdelay == 0)
|
|
|
|
wdt->ping(wdt);
|
2012-02-08 14:24:10 +08:00
|
|
|
return 0;
|
2010-02-05 04:08:56 +08:00
|
|
|
}
|
|
|
|
|
2012-02-08 14:24:10 +08:00
|
|
|
static int max63xx_wdt_stop(struct watchdog_device *wdd)
|
2010-02-05 04:08:56 +08:00
|
|
|
{
|
2015-06-18 06:58:58 +08:00
|
|
|
struct max63xx_wdt *wdt = watchdog_get_drvdata(wdd);
|
2010-04-10 00:43:33 +08:00
|
|
|
|
2015-06-18 06:58:58 +08:00
|
|
|
wdt->set(wdt, MAX6369_WDSET_DISABLED);
|
2012-02-08 14:24:10 +08:00
|
|
|
return 0;
|
2010-02-05 04:08:56 +08:00
|
|
|
}
|
|
|
|
|
2012-02-08 14:24:10 +08:00
|
|
|
static const struct watchdog_ops max63xx_wdt_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.start = max63xx_wdt_start,
|
|
|
|
.stop = max63xx_wdt_stop,
|
|
|
|
.ping = max63xx_wdt_ping,
|
2010-02-05 04:08:56 +08:00
|
|
|
};
|
|
|
|
|
2015-06-18 06:58:58 +08:00
|
|
|
static const struct watchdog_info max63xx_wdt_info = {
|
|
|
|
.options = WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
|
|
|
|
.identity = "max63xx Watchdog",
|
2010-02-05 04:08:56 +08:00
|
|
|
};
|
|
|
|
|
2015-06-18 06:58:58 +08:00
|
|
|
static void max63xx_mmap_ping(struct max63xx_wdt *wdt)
|
|
|
|
{
|
|
|
|
u8 val;
|
|
|
|
|
|
|
|
spin_lock(&wdt->lock);
|
|
|
|
|
|
|
|
val = __raw_readb(wdt->base);
|
|
|
|
|
|
|
|
__raw_writeb(val | MAX6369_WDI, wdt->base);
|
|
|
|
__raw_writeb(val & ~MAX6369_WDI, wdt->base);
|
|
|
|
|
|
|
|
spin_unlock(&wdt->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void max63xx_mmap_set(struct max63xx_wdt *wdt, u8 set)
|
|
|
|
{
|
|
|
|
u8 val;
|
|
|
|
|
|
|
|
spin_lock(&wdt->lock);
|
|
|
|
|
|
|
|
val = __raw_readb(wdt->base);
|
|
|
|
val &= ~MAX6369_WDSET;
|
|
|
|
val |= set & MAX6369_WDSET;
|
|
|
|
__raw_writeb(val, wdt->base);
|
|
|
|
|
|
|
|
spin_unlock(&wdt->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int max63xx_mmap_init(struct platform_device *p, struct max63xx_wdt *wdt)
|
|
|
|
{
|
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-03 03:01:53 +08:00
|
|
|
wdt->base = devm_platform_ioremap_resource(p, 0);
|
2015-06-18 06:58:58 +08:00
|
|
|
if (IS_ERR(wdt->base))
|
|
|
|
return PTR_ERR(wdt->base);
|
|
|
|
|
|
|
|
spin_lock_init(&wdt->lock);
|
|
|
|
|
|
|
|
wdt->ping = max63xx_mmap_ping;
|
|
|
|
wdt->set = max63xx_mmap_set;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-20 02:21:41 +08:00
|
|
|
static int max63xx_wdt_probe(struct platform_device *pdev)
|
2010-02-05 04:08:56 +08:00
|
|
|
{
|
2019-04-09 03:38:46 +08:00
|
|
|
struct device *dev = &pdev->dev;
|
2015-06-18 06:58:58 +08:00
|
|
|
struct max63xx_wdt *wdt;
|
2010-02-05 04:08:56 +08:00
|
|
|
struct max63xx_timeout *table;
|
2015-06-18 06:58:58 +08:00
|
|
|
int err;
|
|
|
|
|
2019-04-09 03:38:46 +08:00
|
|
|
wdt = devm_kzalloc(dev, sizeof(*wdt), GFP_KERNEL);
|
2015-06-18 06:58:58 +08:00
|
|
|
if (!wdt)
|
|
|
|
return -ENOMEM;
|
2010-02-05 04:08:56 +08:00
|
|
|
|
|
|
|
table = (struct max63xx_timeout *)pdev->id_entry->driver_data;
|
|
|
|
|
|
|
|
if (heartbeat < 1 || heartbeat > MAX_HEARTBEAT)
|
|
|
|
heartbeat = DEFAULT_HEARTBEAT;
|
|
|
|
|
2015-06-18 06:58:58 +08:00
|
|
|
wdt->timeout = max63xx_select_timeout(table, heartbeat);
|
|
|
|
if (!wdt->timeout) {
|
2019-04-09 03:38:46 +08:00
|
|
|
dev_err(dev, "unable to satisfy %ds heartbeat request\n",
|
2015-06-18 06:58:58 +08:00
|
|
|
heartbeat);
|
2010-02-05 04:08:56 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-06-18 06:58:58 +08:00
|
|
|
err = max63xx_mmap_init(pdev, wdt);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, &wdt->wdd);
|
|
|
|
watchdog_set_drvdata(&wdt->wdd, wdt);
|
2010-02-05 04:08:56 +08:00
|
|
|
|
2019-04-09 03:38:46 +08:00
|
|
|
wdt->wdd.parent = dev;
|
2015-06-18 06:58:58 +08:00
|
|
|
wdt->wdd.timeout = wdt->timeout->twd;
|
|
|
|
wdt->wdd.info = &max63xx_wdt_info;
|
|
|
|
wdt->wdd.ops = &max63xx_wdt_ops;
|
2010-02-05 04:08:56 +08:00
|
|
|
|
2015-06-18 06:58:58 +08:00
|
|
|
watchdog_set_nowayout(&wdt->wdd, nowayout);
|
2010-02-05 04:08:56 +08:00
|
|
|
|
2019-04-09 03:38:46 +08:00
|
|
|
err = devm_watchdog_register_device(dev, &wdt->wdd);
|
2015-06-18 06:58:58 +08:00
|
|
|
if (err)
|
|
|
|
return err;
|
2010-02-05 04:08:56 +08:00
|
|
|
|
2019-04-09 03:38:46 +08:00
|
|
|
dev_info(dev, "using %ds heartbeat with %ds initial delay\n",
|
2015-06-18 06:58:58 +08:00
|
|
|
wdt->timeout->twd, wdt->timeout->tdelay);
|
|
|
|
return 0;
|
2010-02-05 04:08:56 +08:00
|
|
|
}
|
|
|
|
|
2015-05-01 23:36:52 +08:00
|
|
|
static const struct platform_device_id max63xx_id_table[] = {
|
2010-02-05 04:08:56 +08:00
|
|
|
{ "max6369_wdt", (kernel_ulong_t)max6369_table, },
|
|
|
|
{ "max6370_wdt", (kernel_ulong_t)max6369_table, },
|
|
|
|
{ "max6371_wdt", (kernel_ulong_t)max6371_table, },
|
|
|
|
{ "max6372_wdt", (kernel_ulong_t)max6371_table, },
|
|
|
|
{ "max6373_wdt", (kernel_ulong_t)max6373_table, },
|
|
|
|
{ "max6374_wdt", (kernel_ulong_t)max6373_table, },
|
|
|
|
{ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(platform, max63xx_id_table);
|
|
|
|
|
|
|
|
static struct platform_driver max63xx_wdt_driver = {
|
|
|
|
.probe = max63xx_wdt_probe,
|
|
|
|
.id_table = max63xx_id_table,
|
|
|
|
.driver = {
|
|
|
|
.name = "max63xx_wdt",
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2011-11-29 13:56:27 +08:00
|
|
|
module_platform_driver(max63xx_wdt_driver);
|
2010-02-05 04:08:56 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Marc Zyngier <maz@misterjones.org>");
|
|
|
|
MODULE_DESCRIPTION("max63xx Watchdog Driver");
|
|
|
|
|
|
|
|
module_param(heartbeat, int, 0);
|
|
|
|
MODULE_PARM_DESC(heartbeat,
|
|
|
|
"Watchdog heartbeat period in seconds from 1 to "
|
|
|
|
__MODULE_STRING(MAX_HEARTBEAT) ", default "
|
|
|
|
__MODULE_STRING(DEFAULT_HEARTBEAT));
|
|
|
|
|
2012-03-05 23:51:11 +08:00
|
|
|
module_param(nowayout, bool, 0);
|
2010-02-05 04:08:56 +08:00
|
|
|
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
|
|
|
|
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
|
|
|
|
|
|
|
|
module_param(nodelay, int, 0);
|
|
|
|
MODULE_PARM_DESC(nodelay,
|
|
|
|
"Force selection of a timeout setting without initial delay "
|
|
|
|
"(max6373/74 only, default=0)");
|
|
|
|
|
2016-01-16 01:35:34 +08:00
|
|
|
MODULE_LICENSE("GPL v2");
|