2018-03-16 15:14:11 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-03-31 06:14:59 +00:00
|
|
|
/*
|
|
|
|
* Watchdog driver for Conexant Digicolor
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Paradox Innovation Ltd.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/watchdog.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/of_address.h>
|
|
|
|
|
|
|
|
#define TIMER_A_CONTROL 0
|
|
|
|
#define TIMER_A_COUNT 4
|
|
|
|
|
|
|
|
#define TIMER_A_ENABLE_COUNT BIT(0)
|
|
|
|
#define TIMER_A_ENABLE_WATCHDOG BIT(1)
|
|
|
|
|
|
|
|
struct dc_wdt {
|
|
|
|
void __iomem *base;
|
|
|
|
struct clk *clk;
|
|
|
|
spinlock_t lock;
|
|
|
|
};
|
|
|
|
|
|
|
|
static unsigned timeout;
|
|
|
|
module_param(timeout, uint, 0);
|
|
|
|
MODULE_PARM_DESC(timeout, "Watchdog timeout in seconds");
|
|
|
|
|
|
|
|
static void dc_wdt_set(struct dc_wdt *wdt, u32 ticks)
|
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&wdt->lock, flags);
|
|
|
|
|
|
|
|
writel_relaxed(0, wdt->base + TIMER_A_CONTROL);
|
|
|
|
writel_relaxed(ticks, wdt->base + TIMER_A_COUNT);
|
|
|
|
writel_relaxed(TIMER_A_ENABLE_COUNT | TIMER_A_ENABLE_WATCHDOG,
|
|
|
|
wdt->base + TIMER_A_CONTROL);
|
|
|
|
|
|
|
|
spin_unlock_irqrestore(&wdt->lock, flags);
|
|
|
|
}
|
|
|
|
|
2016-02-27 01:32:49 +00:00
|
|
|
static int dc_wdt_restart(struct watchdog_device *wdog, unsigned long action,
|
|
|
|
void *data)
|
2015-03-31 06:14:59 +00:00
|
|
|
{
|
2015-11-16 17:28:02 +00:00
|
|
|
struct dc_wdt *wdt = watchdog_get_drvdata(wdog);
|
2015-03-31 06:14:59 +00:00
|
|
|
|
|
|
|
dc_wdt_set(wdt, 1);
|
|
|
|
/* wait for reset to assert... */
|
|
|
|
mdelay(500);
|
|
|
|
|
2015-11-16 17:28:02 +00:00
|
|
|
return 0;
|
2015-03-31 06:14:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int dc_wdt_start(struct watchdog_device *wdog)
|
|
|
|
{
|
|
|
|
struct dc_wdt *wdt = watchdog_get_drvdata(wdog);
|
|
|
|
|
|
|
|
dc_wdt_set(wdt, wdog->timeout * clk_get_rate(wdt->clk));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dc_wdt_stop(struct watchdog_device *wdog)
|
|
|
|
{
|
|
|
|
struct dc_wdt *wdt = watchdog_get_drvdata(wdog);
|
|
|
|
|
|
|
|
writel_relaxed(0, wdt->base + TIMER_A_CONTROL);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int dc_wdt_set_timeout(struct watchdog_device *wdog, unsigned int t)
|
|
|
|
{
|
|
|
|
struct dc_wdt *wdt = watchdog_get_drvdata(wdog);
|
|
|
|
|
|
|
|
dc_wdt_set(wdt, t * clk_get_rate(wdt->clk));
|
|
|
|
wdog->timeout = t;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int dc_wdt_get_timeleft(struct watchdog_device *wdog)
|
|
|
|
{
|
|
|
|
struct dc_wdt *wdt = watchdog_get_drvdata(wdog);
|
|
|
|
uint32_t count = readl_relaxed(wdt->base + TIMER_A_COUNT);
|
|
|
|
|
|
|
|
return count / clk_get_rate(wdt->clk);
|
|
|
|
}
|
|
|
|
|
2017-01-28 07:41:17 +00:00
|
|
|
static const struct watchdog_ops dc_wdt_ops = {
|
2015-03-31 06:14:59 +00:00
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.start = dc_wdt_start,
|
|
|
|
.stop = dc_wdt_stop,
|
|
|
|
.set_timeout = dc_wdt_set_timeout,
|
|
|
|
.get_timeleft = dc_wdt_get_timeleft,
|
2015-11-16 17:28:02 +00:00
|
|
|
.restart = dc_wdt_restart,
|
2015-03-31 06:14:59 +00:00
|
|
|
};
|
|
|
|
|
2016-12-26 17:05:11 +00:00
|
|
|
static const struct watchdog_info dc_wdt_info = {
|
2015-03-31 06:14:59 +00:00
|
|
|
.options = WDIOF_SETTIMEOUT | WDIOF_MAGICCLOSE
|
|
|
|
| WDIOF_KEEPALIVEPING,
|
|
|
|
.identity = "Conexant Digicolor Watchdog",
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct watchdog_device dc_wdt_wdd = {
|
|
|
|
.info = &dc_wdt_info,
|
|
|
|
.ops = &dc_wdt_ops,
|
|
|
|
.min_timeout = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int dc_wdt_probe(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct dc_wdt *wdt;
|
|
|
|
|
|
|
|
wdt = devm_kzalloc(dev, sizeof(struct dc_wdt), GFP_KERNEL);
|
|
|
|
if (!wdt)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
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
|
|
|
wdt->base = devm_platform_ioremap_resource(pdev, 0);
|
2017-01-10 23:21:48 +00:00
|
|
|
if (IS_ERR(wdt->base))
|
|
|
|
return PTR_ERR(wdt->base);
|
2015-03-31 06:14:59 +00:00
|
|
|
|
2017-01-10 23:21:48 +00:00
|
|
|
wdt->clk = devm_clk_get(dev, NULL);
|
|
|
|
if (IS_ERR(wdt->clk))
|
|
|
|
return PTR_ERR(wdt->clk);
|
2015-03-31 06:14:59 +00:00
|
|
|
dc_wdt_wdd.max_timeout = U32_MAX / clk_get_rate(wdt->clk);
|
|
|
|
dc_wdt_wdd.timeout = dc_wdt_wdd.max_timeout;
|
2017-01-10 23:21:48 +00:00
|
|
|
dc_wdt_wdd.parent = dev;
|
2015-03-31 06:14:59 +00:00
|
|
|
|
|
|
|
spin_lock_init(&wdt->lock);
|
|
|
|
|
|
|
|
watchdog_set_drvdata(&dc_wdt_wdd, wdt);
|
2015-11-16 17:28:02 +00:00
|
|
|
watchdog_set_restart_priority(&dc_wdt_wdd, 128);
|
2015-03-31 06:14:59 +00:00
|
|
|
watchdog_init_timeout(&dc_wdt_wdd, timeout, dev);
|
2017-01-10 23:21:48 +00:00
|
|
|
watchdog_stop_on_reboot(&dc_wdt_wdd);
|
2019-05-18 21:27:26 +00:00
|
|
|
return devm_watchdog_register_device(dev, &dc_wdt_wdd);
|
2015-03-31 06:14:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id dc_wdt_of_match[] = {
|
|
|
|
{ .compatible = "cnxt,cx92755-wdt", },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, dc_wdt_of_match);
|
|
|
|
|
|
|
|
static struct platform_driver dc_wdt_driver = {
|
|
|
|
.probe = dc_wdt_probe,
|
|
|
|
.driver = {
|
|
|
|
.name = "digicolor-wdt",
|
|
|
|
.of_match_table = dc_wdt_of_match,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
module_platform_driver(dc_wdt_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("Baruch Siach <baruch@tkos.co.il>");
|
|
|
|
MODULE_DESCRIPTION("Driver for Conexant Digicolor watchdog timer");
|
|
|
|
MODULE_LICENSE("GPL");
|