2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-02-22 08:21:48 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2016 Freescale Semiconductor, Inc.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-12-28 17:45:01 +00:00
|
|
|
#include <cpu_func.h>
|
2017-02-22 08:21:48 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch/imx-regs.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* MX7ULP WDOG Register Map
|
|
|
|
*/
|
|
|
|
struct wdog_regs {
|
2021-06-29 02:32:35 +00:00
|
|
|
u32 cs;
|
2017-02-22 08:21:48 +00:00
|
|
|
u32 cnt;
|
|
|
|
u32 toval;
|
|
|
|
u32 win;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef CONFIG_WATCHDOG_TIMEOUT_MSECS
|
|
|
|
#define CONFIG_WATCHDOG_TIMEOUT_MSECS 0x1500
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define REFRESH_WORD0 0xA602 /* 1st refresh word */
|
|
|
|
#define REFRESH_WORD1 0xB480 /* 2nd refresh word */
|
|
|
|
|
|
|
|
#define UNLOCK_WORD0 0xC520 /* 1st unlock word */
|
|
|
|
#define UNLOCK_WORD1 0xD928 /* 2nd unlock word */
|
|
|
|
|
2021-06-29 02:32:35 +00:00
|
|
|
#define WDGCS_WDGE BIT(7)
|
|
|
|
#define WDGCS_WDGUPDATE BIT(5)
|
2017-02-22 08:21:48 +00:00
|
|
|
|
2021-06-29 02:32:35 +00:00
|
|
|
#define WDGCS_RCS BIT(10)
|
|
|
|
#define WDGCS_ULK BIT(11)
|
|
|
|
#define WDGCS_FLG BIT(14)
|
2017-02-22 08:21:48 +00:00
|
|
|
|
|
|
|
#define WDG_BUS_CLK (0x0)
|
|
|
|
#define WDG_LPO_CLK (0x1)
|
|
|
|
#define WDG_32KHZ_CLK (0x2)
|
|
|
|
#define WDG_EXT_CLK (0x3)
|
|
|
|
|
|
|
|
void hw_watchdog_set_timeout(u16 val)
|
|
|
|
{
|
|
|
|
/* setting timeout value */
|
|
|
|
struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
|
|
|
|
|
|
|
|
writel(val, &wdog->toval);
|
|
|
|
}
|
|
|
|
|
|
|
|
void hw_watchdog_reset(void)
|
|
|
|
{
|
|
|
|
struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
|
|
|
|
|
2021-06-29 02:32:34 +00:00
|
|
|
dmb();
|
|
|
|
__raw_writel(REFRESH_WORD0, &wdog->cnt);
|
|
|
|
__raw_writel(REFRESH_WORD1, &wdog->cnt);
|
|
|
|
dmb();
|
2017-02-22 08:21:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void hw_watchdog_init(void)
|
|
|
|
{
|
|
|
|
struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
|
|
|
|
|
2021-06-29 02:32:34 +00:00
|
|
|
dmb();
|
|
|
|
__raw_writel(UNLOCK_WORD0, &wdog->cnt);
|
|
|
|
__raw_writel(UNLOCK_WORD1, &wdog->cnt);
|
|
|
|
dmb();
|
2017-02-22 08:21:48 +00:00
|
|
|
|
2021-06-29 02:32:35 +00:00
|
|
|
/* Wait WDOG Unlock */
|
|
|
|
while (!(readl(&wdog->cs) & WDGCS_ULK))
|
|
|
|
;
|
2017-02-22 08:21:48 +00:00
|
|
|
|
|
|
|
hw_watchdog_set_timeout(CONFIG_WATCHDOG_TIMEOUT_MSECS);
|
|
|
|
writel(0, &wdog->win);
|
|
|
|
|
2021-06-29 02:32:35 +00:00
|
|
|
/* setting 1-kHz clock source, enable counter running, and clear interrupt */
|
|
|
|
writel((WDGCS_WDGE | WDGCS_WDGUPDATE |(WDG_LPO_CLK << 8) | WDGCS_FLG), &wdog->cs);
|
|
|
|
|
|
|
|
/* Wait WDOG reconfiguration */
|
|
|
|
while (!(readl(&wdog->cs) & WDGCS_RCS))
|
|
|
|
;
|
2017-02-22 08:21:48 +00:00
|
|
|
|
|
|
|
hw_watchdog_reset();
|
|
|
|
}
|
|
|
|
|
2020-12-15 15:47:52 +00:00
|
|
|
void reset_cpu(void)
|
2017-02-22 08:21:48 +00:00
|
|
|
{
|
|
|
|
struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
|
|
|
|
|
2021-06-29 02:32:34 +00:00
|
|
|
dmb();
|
|
|
|
__raw_writel(UNLOCK_WORD0, &wdog->cnt);
|
|
|
|
__raw_writel(UNLOCK_WORD1, &wdog->cnt);
|
|
|
|
dmb();
|
2017-02-22 08:21:48 +00:00
|
|
|
|
2021-06-29 02:32:35 +00:00
|
|
|
/* Wait WDOG Unlock */
|
|
|
|
while (!(readl(&wdog->cs) & WDGCS_ULK))
|
|
|
|
;
|
|
|
|
|
2017-02-22 08:21:48 +00:00
|
|
|
hw_watchdog_set_timeout(5); /* 5ms timeout */
|
|
|
|
writel(0, &wdog->win);
|
|
|
|
|
2021-06-29 02:32:35 +00:00
|
|
|
/* enable counter running */
|
|
|
|
writel((WDGCS_WDGE | (WDG_LPO_CLK << 8)), &wdog->cs);
|
|
|
|
|
|
|
|
/* Wait WDOG reconfiguration */
|
|
|
|
while (!(readl(&wdog->cs) & WDGCS_RCS))
|
|
|
|
;
|
2017-02-22 08:21:48 +00:00
|
|
|
|
|
|
|
hw_watchdog_reset();
|
|
|
|
|
|
|
|
while (1);
|
|
|
|
}
|