2012-10-22 15:19:01 +00:00
|
|
|
/*
|
|
|
|
* watchdog.c - driver for i.mx on-chip watchdog
|
|
|
|
*
|
|
|
|
* Licensed under the GPL-2 or later.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-12-28 17:45:01 +00:00
|
|
|
#include <cpu_func.h>
|
2019-06-09 01:46:22 +00:00
|
|
|
#include <dm.h>
|
2019-12-28 17:45:07 +00:00
|
|
|
#include <hang.h>
|
2012-10-22 15:19:01 +00:00
|
|
|
#include <asm/io.h>
|
2019-06-09 01:46:22 +00:00
|
|
|
#include <wdt.h>
|
2012-10-22 15:19:01 +00:00
|
|
|
#include <watchdog.h>
|
|
|
|
#include <asm/arch/imx-regs.h>
|
2018-10-18 10:27:45 +00:00
|
|
|
#ifdef CONFIG_FSL_LSCH2
|
|
|
|
#include <asm/arch/immap_lsch2.h>
|
|
|
|
#endif
|
2015-10-03 17:20:59 +00:00
|
|
|
#include <fsl_wdog.h>
|
2012-10-22 15:19:01 +00:00
|
|
|
|
2019-08-06 17:05:30 +00:00
|
|
|
static void imx_watchdog_expire_now(struct watchdog_regs *wdog, bool ext_reset)
|
2019-06-09 01:46:22 +00:00
|
|
|
{
|
2019-08-06 17:05:30 +00:00
|
|
|
u16 wcr = WCR_WDE;
|
|
|
|
|
|
|
|
if (ext_reset)
|
|
|
|
wcr |= WCR_SRS; /* do not assert internal reset */
|
|
|
|
else
|
|
|
|
wcr |= WCR_WDA; /* do not assert external reset */
|
|
|
|
|
|
|
|
/* Write 3 times to ensure it works, due to IMX6Q errata ERR004346 */
|
|
|
|
writew(wcr, &wdog->wcr);
|
|
|
|
writew(wcr, &wdog->wcr);
|
|
|
|
writew(wcr, &wdog->wcr);
|
2019-06-09 01:46:22 +00:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
/*
|
2019-08-06 17:05:30 +00:00
|
|
|
* spin before reset
|
2019-06-09 01:46:22 +00:00
|
|
|
*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if !defined(CONFIG_IMX_WATCHDOG) || \
|
|
|
|
(defined(CONFIG_IMX_WATCHDOG) && !CONFIG_IS_ENABLED(WDT))
|
|
|
|
void __attribute__((weak)) reset_cpu(ulong addr)
|
2012-10-22 15:19:01 +00:00
|
|
|
{
|
|
|
|
struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
|
|
|
|
|
2019-08-06 17:05:30 +00:00
|
|
|
imx_watchdog_expire_now(wdog, true);
|
2019-06-09 01:46:22 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(CONFIG_IMX_WATCHDOG)
|
|
|
|
static void imx_watchdog_reset(struct watchdog_regs *wdog)
|
|
|
|
{
|
|
|
|
#ifndef CONFIG_WATCHDOG_RESET_DISABLE
|
2012-10-22 15:19:01 +00:00
|
|
|
writew(0x5555, &wdog->wsr);
|
|
|
|
writew(0xaaaa, &wdog->wsr);
|
2018-10-18 10:27:46 +00:00
|
|
|
#endif /* CONFIG_WATCHDOG_RESET_DISABLE*/
|
2012-10-22 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2019-08-06 17:05:29 +00:00
|
|
|
static void imx_watchdog_init(struct watchdog_regs *wdog, bool ext_reset)
|
2012-10-22 15:19:01 +00:00
|
|
|
{
|
|
|
|
u16 timeout;
|
2019-08-06 17:05:29 +00:00
|
|
|
u16 wcr;
|
2012-10-22 15:19:01 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The timer watchdog can be set between
|
|
|
|
* 0.5 and 128 Seconds. If not defined
|
|
|
|
* in configuration file, sets 128 Seconds
|
|
|
|
*/
|
|
|
|
#ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
|
|
|
|
#define CONFIG_WATCHDOG_TIMEOUT_MSECS 128000
|
|
|
|
#endif
|
|
|
|
timeout = (CONFIG_WATCHDOG_TIMEOUT_MSECS / 500) - 1;
|
2018-10-18 10:27:45 +00:00
|
|
|
#ifdef CONFIG_FSL_LSCH2
|
2019-08-06 17:05:29 +00:00
|
|
|
wcr = (WCR_WDA | WCR_SRS | WCR_WDE) << 8 | timeout;
|
2018-10-18 10:27:45 +00:00
|
|
|
#else
|
2019-08-06 17:05:29 +00:00
|
|
|
wcr = WCR_WDZST | WCR_WDBG | WCR_WDE | WCR_SRS |
|
|
|
|
WCR_WDA | SET_WCR_WT(timeout);
|
|
|
|
if (ext_reset)
|
|
|
|
wcr |= WCR_WDT;
|
2018-10-18 10:27:45 +00:00
|
|
|
#endif /* CONFIG_FSL_LSCH2*/
|
2019-08-06 17:05:29 +00:00
|
|
|
writew(wcr, &wdog->wcr);
|
2019-06-09 01:46:22 +00:00
|
|
|
imx_watchdog_reset(wdog);
|
2012-10-22 15:19:01 +00:00
|
|
|
}
|
|
|
|
|
2019-06-09 01:46:22 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(WDT)
|
|
|
|
void hw_watchdog_reset(void)
|
2012-10-22 15:19:01 +00:00
|
|
|
{
|
|
|
|
struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
|
|
|
|
|
2019-06-09 01:46:22 +00:00
|
|
|
imx_watchdog_reset(wdog);
|
|
|
|
}
|
2015-09-14 05:34:44 +00:00
|
|
|
|
2019-06-09 01:46:22 +00:00
|
|
|
void hw_watchdog_init(void)
|
|
|
|
{
|
|
|
|
struct watchdog_regs *wdog = (struct watchdog_regs *)WDOG1_BASE_ADDR;
|
|
|
|
|
2019-08-06 17:05:29 +00:00
|
|
|
imx_watchdog_init(wdog, true);
|
2019-06-09 01:46:22 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
struct imx_wdt_priv {
|
|
|
|
void __iomem *base;
|
2019-08-06 17:05:29 +00:00
|
|
|
bool ext_reset;
|
2019-06-09 01:46:22 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int imx_wdt_reset(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct imx_wdt_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
imx_watchdog_reset(priv->base);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx_wdt_expire_now(struct udevice *dev, ulong flags)
|
|
|
|
{
|
|
|
|
struct imx_wdt_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2019-08-06 17:05:30 +00:00
|
|
|
imx_watchdog_expire_now(priv->base, priv->ext_reset);
|
2019-06-09 01:46:22 +00:00
|
|
|
hang();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx_wdt_start(struct udevice *dev, u64 timeout, ulong flags)
|
|
|
|
{
|
|
|
|
struct imx_wdt_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2019-08-06 17:05:29 +00:00
|
|
|
imx_watchdog_init(priv->base, priv->ext_reset);
|
2019-06-09 01:46:22 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int imx_wdt_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct imx_wdt_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
priv->base = dev_read_addr_ptr(dev);
|
|
|
|
if (!priv->base)
|
|
|
|
return -ENOENT;
|
|
|
|
|
2019-08-06 17:05:29 +00:00
|
|
|
priv->ext_reset = dev_read_bool(dev, "fsl,ext-reset-output");
|
|
|
|
|
2019-06-09 01:46:22 +00:00
|
|
|
return 0;
|
2012-10-22 15:19:01 +00:00
|
|
|
}
|
2019-06-09 01:46:22 +00:00
|
|
|
|
|
|
|
static const struct wdt_ops imx_wdt_ops = {
|
|
|
|
.start = imx_wdt_start,
|
|
|
|
.reset = imx_wdt_reset,
|
|
|
|
.expire_now = imx_wdt_expire_now,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id imx_wdt_ids[] = {
|
|
|
|
{ .compatible = "fsl,imx21-wdt" },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(imx_wdt) = {
|
|
|
|
.name = "imx_wdt",
|
|
|
|
.id = UCLASS_WDT,
|
|
|
|
.of_match = imx_wdt_ids,
|
|
|
|
.probe = imx_wdt_probe,
|
|
|
|
.ops = &imx_wdt_ops,
|
|
|
|
.priv_auto_alloc_size = sizeof(struct imx_wdt_priv),
|
|
|
|
.flags = DM_FLAG_PRE_RELOC,
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
#endif
|