2019-05-19 21:51:34 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2013-10-02 08:13:49 +08:00
|
|
|
/*
|
|
|
|
* Watchdog driver for CSR SiRFprimaII and SiRFatlasVI
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013 Cambridge Silicon Radio Limited, a CSR plc group company.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/watchdog.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/uaccess.h>
|
|
|
|
|
2013-11-12 04:33:44 +08:00
|
|
|
#define CLOCK_FREQ 1000000
|
|
|
|
|
2013-10-02 08:13:49 +08:00
|
|
|
#define SIRFSOC_TIMER_COUNTER_LO 0x0000
|
|
|
|
#define SIRFSOC_TIMER_MATCH_0 0x0008
|
|
|
|
#define SIRFSOC_TIMER_INT_EN 0x0024
|
|
|
|
#define SIRFSOC_TIMER_WATCHDOG_EN 0x0028
|
|
|
|
#define SIRFSOC_TIMER_LATCH 0x0030
|
|
|
|
#define SIRFSOC_TIMER_LATCHED_LO 0x0034
|
|
|
|
|
|
|
|
#define SIRFSOC_TIMER_WDT_INDEX 5
|
|
|
|
|
|
|
|
#define SIRFSOC_WDT_MIN_TIMEOUT 30 /* 30 secs */
|
|
|
|
#define SIRFSOC_WDT_MAX_TIMEOUT (10 * 60) /* 10 mins */
|
|
|
|
#define SIRFSOC_WDT_DEFAULT_TIMEOUT 30 /* 30 secs */
|
|
|
|
|
2018-02-12 04:08:43 +08:00
|
|
|
static unsigned int timeout;
|
2013-10-02 08:13:49 +08:00
|
|
|
static bool nowayout = WATCHDOG_NOWAYOUT;
|
|
|
|
|
|
|
|
module_param(timeout, uint, 0);
|
|
|
|
module_param(nowayout, bool, 0);
|
|
|
|
|
|
|
|
MODULE_PARM_DESC(timeout, "Default watchdog timeout (in seconds)");
|
|
|
|
MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default="
|
|
|
|
__MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
|
|
|
|
|
2016-06-07 19:53:07 +08:00
|
|
|
static void __iomem *sirfsoc_wdt_base(struct watchdog_device *wdd)
|
|
|
|
{
|
|
|
|
return (void __iomem __force *)watchdog_get_drvdata(wdd);
|
|
|
|
}
|
|
|
|
|
2013-10-02 08:13:49 +08:00
|
|
|
static unsigned int sirfsoc_wdt_gettimeleft(struct watchdog_device *wdd)
|
|
|
|
{
|
|
|
|
u32 counter, match;
|
|
|
|
void __iomem *wdt_base;
|
|
|
|
int time_left;
|
|
|
|
|
2016-06-07 19:53:07 +08:00
|
|
|
wdt_base = sirfsoc_wdt_base(wdd);
|
2013-10-02 08:13:49 +08:00
|
|
|
counter = readl(wdt_base + SIRFSOC_TIMER_COUNTER_LO);
|
|
|
|
match = readl(wdt_base +
|
|
|
|
SIRFSOC_TIMER_MATCH_0 + (SIRFSOC_TIMER_WDT_INDEX << 2));
|
|
|
|
|
|
|
|
time_left = match - counter;
|
|
|
|
|
2013-11-12 04:33:44 +08:00
|
|
|
return time_left / CLOCK_FREQ;
|
2013-10-02 08:13:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sirfsoc_wdt_updatetimeout(struct watchdog_device *wdd)
|
|
|
|
{
|
|
|
|
u32 counter, timeout_ticks;
|
|
|
|
void __iomem *wdt_base;
|
|
|
|
|
2013-11-12 04:33:44 +08:00
|
|
|
timeout_ticks = wdd->timeout * CLOCK_FREQ;
|
2016-06-07 19:53:07 +08:00
|
|
|
wdt_base = sirfsoc_wdt_base(wdd);
|
2013-10-02 08:13:49 +08:00
|
|
|
|
|
|
|
/* Enable the latch before reading the LATCH_LO register */
|
|
|
|
writel(1, wdt_base + SIRFSOC_TIMER_LATCH);
|
|
|
|
|
|
|
|
/* Set the TO value */
|
|
|
|
counter = readl(wdt_base + SIRFSOC_TIMER_LATCHED_LO);
|
|
|
|
|
|
|
|
counter += timeout_ticks;
|
|
|
|
|
|
|
|
writel(counter, wdt_base +
|
|
|
|
SIRFSOC_TIMER_MATCH_0 + (SIRFSOC_TIMER_WDT_INDEX << 2));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sirfsoc_wdt_enable(struct watchdog_device *wdd)
|
|
|
|
{
|
2016-06-07 19:53:07 +08:00
|
|
|
void __iomem *wdt_base = sirfsoc_wdt_base(wdd);
|
2013-10-02 08:13:49 +08:00
|
|
|
sirfsoc_wdt_updatetimeout(wdd);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: If interrupt is not enabled
|
|
|
|
* then WD-Reset doesn't get generated at all.
|
|
|
|
*/
|
|
|
|
writel(readl(wdt_base + SIRFSOC_TIMER_INT_EN)
|
|
|
|
| (1 << SIRFSOC_TIMER_WDT_INDEX),
|
|
|
|
wdt_base + SIRFSOC_TIMER_INT_EN);
|
|
|
|
writel(1, wdt_base + SIRFSOC_TIMER_WATCHDOG_EN);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sirfsoc_wdt_disable(struct watchdog_device *wdd)
|
|
|
|
{
|
2016-06-07 19:53:07 +08:00
|
|
|
void __iomem *wdt_base = sirfsoc_wdt_base(wdd);
|
2013-10-02 08:13:49 +08:00
|
|
|
|
|
|
|
writel(0, wdt_base + SIRFSOC_TIMER_WATCHDOG_EN);
|
|
|
|
writel(readl(wdt_base + SIRFSOC_TIMER_INT_EN)
|
|
|
|
& (~(1 << SIRFSOC_TIMER_WDT_INDEX)),
|
|
|
|
wdt_base + SIRFSOC_TIMER_INT_EN);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sirfsoc_wdt_settimeout(struct watchdog_device *wdd, unsigned int to)
|
|
|
|
{
|
|
|
|
wdd->timeout = to;
|
|
|
|
sirfsoc_wdt_updatetimeout(wdd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define OPTIONS (WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE)
|
|
|
|
|
|
|
|
static const struct watchdog_info sirfsoc_wdt_ident = {
|
|
|
|
.options = OPTIONS,
|
|
|
|
.firmware_version = 0,
|
|
|
|
.identity = "SiRFSOC Watchdog",
|
|
|
|
};
|
|
|
|
|
2017-01-28 15:41:17 +08:00
|
|
|
static const struct watchdog_ops sirfsoc_wdt_ops = {
|
2013-10-02 08:13:49 +08:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.start = sirfsoc_wdt_enable,
|
|
|
|
.stop = sirfsoc_wdt_disable,
|
|
|
|
.get_timeleft = sirfsoc_wdt_gettimeleft,
|
|
|
|
.ping = sirfsoc_wdt_updatetimeout,
|
|
|
|
.set_timeout = sirfsoc_wdt_settimeout,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct watchdog_device sirfsoc_wdd = {
|
|
|
|
.info = &sirfsoc_wdt_ident,
|
|
|
|
.ops = &sirfsoc_wdt_ops,
|
|
|
|
.timeout = SIRFSOC_WDT_DEFAULT_TIMEOUT,
|
|
|
|
.min_timeout = SIRFSOC_WDT_MIN_TIMEOUT,
|
|
|
|
.max_timeout = SIRFSOC_WDT_MAX_TIMEOUT,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int sirfsoc_wdt_probe(struct platform_device *pdev)
|
|
|
|
{
|
2019-04-10 01:23:55 +08:00
|
|
|
struct device *dev = &pdev->dev;
|
2013-10-02 08:13:49 +08:00
|
|
|
int ret;
|
|
|
|
void __iomem *base;
|
|
|
|
|
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
|
|
|
base = devm_platform_ioremap_resource(pdev, 0);
|
2013-10-02 08:13:49 +08:00
|
|
|
if (IS_ERR(base))
|
|
|
|
return PTR_ERR(base);
|
|
|
|
|
2016-06-07 19:53:07 +08:00
|
|
|
watchdog_set_drvdata(&sirfsoc_wdd, (__force void *)base);
|
2013-10-02 08:13:49 +08:00
|
|
|
|
2019-04-10 01:23:55 +08:00
|
|
|
watchdog_init_timeout(&sirfsoc_wdd, timeout, dev);
|
2013-10-02 08:13:49 +08:00
|
|
|
watchdog_set_nowayout(&sirfsoc_wdd, nowayout);
|
2019-04-10 01:23:55 +08:00
|
|
|
sirfsoc_wdd.parent = dev;
|
2013-10-02 08:13:49 +08:00
|
|
|
|
2019-04-10 01:23:55 +08:00
|
|
|
watchdog_stop_on_reboot(&sirfsoc_wdd);
|
|
|
|
watchdog_stop_on_unregister(&sirfsoc_wdd);
|
|
|
|
ret = devm_watchdog_register_device(dev, &sirfsoc_wdd);
|
2013-10-02 08:13:49 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, &sirfsoc_wdd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int sirfsoc_wdt_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sirfsoc_wdt_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct watchdog_device *wdd = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: Since timer controller registers settings are saved
|
|
|
|
* and restored back by the timer-prima2.c, so we need not
|
|
|
|
* update WD settings except refreshing timeout.
|
|
|
|
*/
|
|
|
|
sirfsoc_wdt_updatetimeout(wdd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static SIMPLE_DEV_PM_OPS(sirfsoc_wdt_pm_ops,
|
|
|
|
sirfsoc_wdt_suspend, sirfsoc_wdt_resume);
|
|
|
|
|
|
|
|
static const struct of_device_id sirfsoc_wdt_of_match[] = {
|
|
|
|
{ .compatible = "sirf,prima2-tick"},
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, sirfsoc_wdt_of_match);
|
|
|
|
|
|
|
|
static struct platform_driver sirfsoc_wdt_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "sirfsoc-wdt",
|
|
|
|
.pm = &sirfsoc_wdt_pm_ops,
|
2013-12-21 16:31:13 +08:00
|
|
|
.of_match_table = sirfsoc_wdt_of_match,
|
2013-10-02 08:13:49 +08:00
|
|
|
},
|
|
|
|
.probe = sirfsoc_wdt_probe,
|
|
|
|
};
|
|
|
|
module_platform_driver(sirfsoc_wdt_driver);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("SiRF SoC watchdog driver");
|
|
|
|
MODULE_AUTHOR("Xianglong Du <Xianglong.Du@csr.com>");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_ALIAS("platform:sirfsoc-wdt");
|