2019-06-04 16:11:33 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2007-11-12 00:32:17 +08:00
|
|
|
/*
|
|
|
|
* txx9wdt: A Hardware Watchdog Driver for TXx9 SoCs
|
|
|
|
*
|
|
|
|
* Copyright (C) 2007 Atsushi Nemoto <anemo@mba.ocn.ne.jp>
|
|
|
|
*/
|
2012-02-16 07:06:19 +08:00
|
|
|
|
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
|
2007-11-12 00:32:17 +08:00
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/moduleparam.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/watchdog.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <asm/txx9tmr.h>
|
|
|
|
|
2012-03-23 18:48:22 +08:00
|
|
|
#define WD_TIMER_CCD 7 /* 1/256 */
|
|
|
|
#define WD_TIMER_CLK (clk_get_rate(txx9_imclk) / (2 << WD_TIMER_CCD))
|
|
|
|
#define WD_MAX_TIMEOUT ((0xffffffff >> (32 - TXX9_TIMER_BITS)) / WD_TIMER_CLK)
|
2007-11-12 00:32:17 +08:00
|
|
|
#define TIMER_MARGIN 60 /* Default is 60 seconds */
|
|
|
|
|
2012-03-23 18:48:22 +08:00
|
|
|
static unsigned int timeout = TIMER_MARGIN; /* in seconds */
|
|
|
|
module_param(timeout, uint, 0);
|
2007-11-12 00:32:17 +08:00
|
|
|
MODULE_PARM_DESC(timeout,
|
|
|
|
"Watchdog timeout in seconds. "
|
|
|
|
"(0<timeout<((2^" __MODULE_STRING(TXX9_TIMER_BITS) ")/(IMCLK/256)), "
|
|
|
|
"default=" __MODULE_STRING(TIMER_MARGIN) ")");
|
|
|
|
|
2012-03-05 23:51:11 +08:00
|
|
|
static bool nowayout = WATCHDOG_NOWAYOUT;
|
|
|
|
module_param(nowayout, bool, 0);
|
2007-11-12 00:32:17 +08:00
|
|
|
MODULE_PARM_DESC(nowayout,
|
|
|
|
"Watchdog cannot be stopped once started "
|
|
|
|
"(default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
|
|
|
|
|
|
|
|
static struct txx9_tmr_reg __iomem *txx9wdt_reg;
|
|
|
|
static struct clk *txx9_imclk;
|
2008-08-08 23:18:46 +08:00
|
|
|
static DEFINE_SPINLOCK(txx9_lock);
|
2007-11-12 00:32:17 +08:00
|
|
|
|
2012-03-16 11:53:53 +08:00
|
|
|
static int txx9wdt_ping(struct watchdog_device *wdt_dev)
|
2007-11-12 00:32:17 +08:00
|
|
|
{
|
2008-05-19 21:09:12 +08:00
|
|
|
spin_lock(&txx9_lock);
|
2007-11-12 00:32:17 +08:00
|
|
|
__raw_writel(TXx9_TMWTMR_TWIE | TXx9_TMWTMR_TWC, &txx9wdt_reg->wtmr);
|
2008-05-19 21:09:12 +08:00
|
|
|
spin_unlock(&txx9_lock);
|
2012-03-16 11:53:53 +08:00
|
|
|
return 0;
|
2007-11-12 00:32:17 +08:00
|
|
|
}
|
|
|
|
|
2012-03-16 11:53:53 +08:00
|
|
|
static int txx9wdt_start(struct watchdog_device *wdt_dev)
|
2007-11-12 00:32:17 +08:00
|
|
|
{
|
2008-05-19 21:09:12 +08:00
|
|
|
spin_lock(&txx9_lock);
|
2012-03-23 18:48:22 +08:00
|
|
|
__raw_writel(WD_TIMER_CLK * wdt_dev->timeout, &txx9wdt_reg->cpra);
|
2007-11-12 00:32:17 +08:00
|
|
|
__raw_writel(WD_TIMER_CCD, &txx9wdt_reg->ccdr);
|
|
|
|
__raw_writel(0, &txx9wdt_reg->tisr); /* clear pending interrupt */
|
|
|
|
__raw_writel(TXx9_TMTCR_TCE | TXx9_TMTCR_CCDE | TXx9_TMTCR_TMODE_WDOG,
|
|
|
|
&txx9wdt_reg->tcr);
|
|
|
|
__raw_writel(TXx9_TMWTMR_TWIE | TXx9_TMWTMR_TWC, &txx9wdt_reg->wtmr);
|
2008-05-19 21:09:12 +08:00
|
|
|
spin_unlock(&txx9_lock);
|
2012-03-16 11:53:53 +08:00
|
|
|
return 0;
|
2007-11-12 00:32:17 +08:00
|
|
|
}
|
|
|
|
|
2012-03-16 11:53:53 +08:00
|
|
|
static int txx9wdt_stop(struct watchdog_device *wdt_dev)
|
2007-11-12 00:32:17 +08:00
|
|
|
{
|
2008-05-19 21:09:12 +08:00
|
|
|
spin_lock(&txx9_lock);
|
2007-11-12 00:32:17 +08:00
|
|
|
__raw_writel(TXx9_TMWTMR_WDIS, &txx9wdt_reg->wtmr);
|
|
|
|
__raw_writel(__raw_readl(&txx9wdt_reg->tcr) & ~TXx9_TMTCR_TCE,
|
|
|
|
&txx9wdt_reg->tcr);
|
2008-05-19 21:09:12 +08:00
|
|
|
spin_unlock(&txx9_lock);
|
2007-11-12 00:32:17 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-16 11:53:53 +08:00
|
|
|
static int txx9wdt_set_timeout(struct watchdog_device *wdt_dev,
|
|
|
|
unsigned int new_timeout)
|
2007-11-12 00:32:17 +08:00
|
|
|
{
|
2012-03-23 18:48:22 +08:00
|
|
|
wdt_dev->timeout = new_timeout;
|
2012-03-16 11:53:53 +08:00
|
|
|
txx9wdt_stop(wdt_dev);
|
|
|
|
txx9wdt_start(wdt_dev);
|
|
|
|
return 0;
|
2007-11-12 00:32:17 +08:00
|
|
|
}
|
|
|
|
|
2012-03-16 11:53:53 +08:00
|
|
|
static const struct watchdog_info txx9wdt_info = {
|
|
|
|
.options = WDIOF_SETTIMEOUT | WDIOF_KEEPALIVEPING | WDIOF_MAGICCLOSE,
|
|
|
|
.identity = "Hardware Watchdog for TXx9",
|
|
|
|
};
|
2007-11-12 00:32:17 +08:00
|
|
|
|
2012-03-16 11:53:53 +08:00
|
|
|
static const struct watchdog_ops txx9wdt_ops = {
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.start = txx9wdt_start,
|
|
|
|
.stop = txx9wdt_stop,
|
|
|
|
.ping = txx9wdt_ping,
|
|
|
|
.set_timeout = txx9wdt_set_timeout,
|
2007-11-12 00:32:17 +08:00
|
|
|
};
|
|
|
|
|
2012-03-16 11:53:53 +08:00
|
|
|
static struct watchdog_device txx9wdt = {
|
|
|
|
.info = &txx9wdt_info,
|
|
|
|
.ops = &txx9wdt_ops,
|
2007-11-12 00:32:17 +08:00
|
|
|
};
|
|
|
|
|
2023-11-06 23:48:10 +08:00
|
|
|
static int txx9wdt_probe(struct platform_device *dev)
|
2007-11-12 00:32:17 +08:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
txx9_imclk = clk_get(NULL, "imbus_clk");
|
|
|
|
if (IS_ERR(txx9_imclk)) {
|
|
|
|
ret = PTR_ERR(txx9_imclk);
|
|
|
|
txx9_imclk = NULL;
|
|
|
|
goto exit;
|
|
|
|
}
|
2016-09-11 16:59:57 +08:00
|
|
|
ret = clk_prepare_enable(txx9_imclk);
|
2007-11-12 00:32:17 +08:00
|
|
|
if (ret) {
|
|
|
|
clk_put(txx9_imclk);
|
|
|
|
txx9_imclk = NULL;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
txx9wdt_reg = devm_platform_ioremap_resource(dev, 0);
|
2013-01-21 18:09:25 +08:00
|
|
|
if (IS_ERR(txx9wdt_reg)) {
|
|
|
|
ret = PTR_ERR(txx9wdt_reg);
|
2007-11-12 00:32:17 +08:00
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
|
2012-03-23 18:48:22 +08:00
|
|
|
if (timeout < 1 || timeout > WD_MAX_TIMEOUT)
|
|
|
|
timeout = TIMER_MARGIN;
|
|
|
|
txx9wdt.timeout = timeout;
|
2012-03-16 11:53:53 +08:00
|
|
|
txx9wdt.min_timeout = 1;
|
|
|
|
txx9wdt.max_timeout = WD_MAX_TIMEOUT;
|
2015-08-20 16:35:01 +08:00
|
|
|
txx9wdt.parent = &dev->dev;
|
2012-03-16 11:53:53 +08:00
|
|
|
watchdog_set_nowayout(&txx9wdt, nowayout);
|
|
|
|
|
|
|
|
ret = watchdog_register_device(&txx9wdt);
|
|
|
|
if (ret)
|
|
|
|
goto exit;
|
|
|
|
|
2012-02-16 07:06:19 +08:00
|
|
|
pr_info("Hardware Watchdog Timer: timeout=%d sec (max %ld) (nowayout= %d)\n",
|
|
|
|
timeout, WD_MAX_TIMEOUT, nowayout);
|
2007-11-12 00:32:17 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
exit:
|
|
|
|
if (txx9_imclk) {
|
2016-09-11 16:59:57 +08:00
|
|
|
clk_disable_unprepare(txx9_imclk);
|
2007-11-12 00:32:17 +08:00
|
|
|
clk_put(txx9_imclk);
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-11-06 23:48:13 +08:00
|
|
|
static void txx9wdt_remove(struct platform_device *dev)
|
2007-11-12 00:32:17 +08:00
|
|
|
{
|
2012-03-16 11:53:53 +08:00
|
|
|
watchdog_unregister_device(&txx9wdt);
|
2016-09-11 16:59:57 +08:00
|
|
|
clk_disable_unprepare(txx9_imclk);
|
2007-11-12 00:32:17 +08:00
|
|
|
clk_put(txx9_imclk);
|
|
|
|
}
|
|
|
|
|
2009-12-27 03:13:00 +08:00
|
|
|
static void txx9wdt_shutdown(struct platform_device *dev)
|
|
|
|
{
|
2012-03-16 11:53:53 +08:00
|
|
|
txx9wdt_stop(&txx9wdt);
|
2009-12-27 03:13:00 +08:00
|
|
|
}
|
|
|
|
|
2007-11-12 00:32:17 +08:00
|
|
|
static struct platform_driver txx9wdt_driver = {
|
2023-11-06 23:48:10 +08:00
|
|
|
.probe = txx9wdt_probe,
|
2023-11-06 23:48:13 +08:00
|
|
|
.remove_new = txx9wdt_remove,
|
2009-12-27 03:13:00 +08:00
|
|
|
.shutdown = txx9wdt_shutdown,
|
2007-11-12 00:32:17 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "txx9wdt",
|
|
|
|
},
|
|
|
|
};
|
2023-11-06 23:48:10 +08:00
|
|
|
module_platform_driver(txx9wdt_driver);
|
2007-11-12 00:32:17 +08:00
|
|
|
|
|
|
|
MODULE_DESCRIPTION("TXx9 Watchdog Driver");
|
|
|
|
MODULE_LICENSE("GPL");
|
2008-04-11 12:29:23 +08:00
|
|
|
MODULE_ALIAS("platform:txx9wdt");
|