2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2013-08-19 14:38:59 +00:00
|
|
|
/*
|
|
|
|
* omap_wdt.c
|
|
|
|
*
|
|
|
|
* (C) Copyright 2013
|
|
|
|
* Heiko Schocher, DENX Software Engineering, hs@denx.de.
|
|
|
|
*
|
|
|
|
* Based on:
|
|
|
|
*
|
|
|
|
* Watchdog driver for the TI OMAP 16xx & 24xx/34xx 32KHz (non-secure) watchdog
|
|
|
|
*
|
|
|
|
* commit 2d991a164a61858012651e13c59521975504e260
|
|
|
|
* Author: Bill Pemberton <wfp5p@virginia.edu>
|
|
|
|
* Date: Mon Nov 19 13:21:41 2012 -0500
|
|
|
|
*
|
|
|
|
* watchdog: remove use of __devinit
|
|
|
|
*
|
|
|
|
* CONFIG_HOTPLUG is going away as an option so __devinit is no longer
|
|
|
|
* needed.
|
|
|
|
*
|
|
|
|
* Author: MontaVista Software, Inc.
|
|
|
|
* <gdavis@mvista.com> or <source@mvista.com>
|
|
|
|
*
|
|
|
|
* History:
|
|
|
|
*
|
|
|
|
* 20030527: George G. Davis <gdavis@mvista.com>
|
|
|
|
* Initially based on linux-2.4.19-rmk7-pxa1/drivers/char/sa1100_wdt.c
|
|
|
|
* (c) Copyright 2000 Oleg Drokin <green@crimea.edu>
|
|
|
|
* Based on SoftDog driver by Alan Cox <alan@lxorguk.ukuu.org.uk>
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004 Texas Instruments.
|
|
|
|
* 1. Modified to support OMAP1610 32-KHz watchdog timer
|
|
|
|
* 2. Ported to 2.6 kernel
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005 David Brownell
|
|
|
|
* Use the driver model and standard identifiers; handle bigger timeouts.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2013-08-19 14:38:59 +00:00
|
|
|
#include <watchdog.h>
|
|
|
|
#include <asm/arch/hardware.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/processor.h>
|
|
|
|
#include <asm/arch/cpu.h>
|
2019-07-31 16:24:06 +00:00
|
|
|
#include <wdt.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <errno.h>
|
2013-08-19 14:38:59 +00:00
|
|
|
|
|
|
|
/* Hardware timeout in seconds */
|
|
|
|
#define WDT_HW_TIMEOUT 60
|
|
|
|
|
2019-07-31 16:24:06 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(WDT)
|
2013-08-19 14:38:59 +00:00
|
|
|
static unsigned int wdt_trgr_pattern = 0x1234;
|
|
|
|
|
|
|
|
void hw_watchdog_reset(void)
|
|
|
|
{
|
|
|
|
struct wd_timer *wdt = (struct wd_timer *)WDT_BASE;
|
|
|
|
|
2018-03-01 01:15:48 +00:00
|
|
|
/*
|
|
|
|
* Somebody just triggered watchdog reset and write to WTGR register
|
|
|
|
* is in progress. It is resetting right now, no need to trigger it
|
|
|
|
* again
|
|
|
|
*/
|
|
|
|
if ((readl(&wdt->wdtwwps)) & WDT_WWPS_PEND_WTGR)
|
|
|
|
return;
|
2013-08-19 14:38:59 +00:00
|
|
|
|
|
|
|
wdt_trgr_pattern = ~wdt_trgr_pattern;
|
|
|
|
writel(wdt_trgr_pattern, &wdt->wdtwtgr);
|
|
|
|
|
2018-03-01 01:15:48 +00:00
|
|
|
/*
|
|
|
|
* Don't wait for posted write to complete, i.e. don't check
|
|
|
|
* WDT_WWPS_PEND_WTGR bit in WWPS register. There is no writes to
|
|
|
|
* WTGR register outside of this func, and if entering it
|
|
|
|
* we see WDT_WWPS_PEND_WTGR bit set, it means watchdog reset
|
|
|
|
* was just triggered. This prevents us from wasting time in busy
|
|
|
|
* polling of WDT_WWPS_PEND_WTGR bit.
|
|
|
|
*/
|
2013-08-19 14:38:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int omap_wdt_set_timeout(unsigned int timeout)
|
|
|
|
{
|
|
|
|
struct wd_timer *wdt = (struct wd_timer *)WDT_BASE;
|
|
|
|
u32 pre_margin = GET_WLDR_VAL(timeout);
|
|
|
|
|
|
|
|
/* just count up at 32 KHz */
|
|
|
|
while (readl(&wdt->wdtwwps) & WDT_WWPS_PEND_WLDR)
|
|
|
|
;
|
|
|
|
|
|
|
|
writel(pre_margin, &wdt->wdtwldr);
|
|
|
|
while (readl(&wdt->wdtwwps) & WDT_WWPS_PEND_WLDR)
|
|
|
|
;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-19 22:24:38 +00:00
|
|
|
void hw_watchdog_disable(void)
|
|
|
|
{
|
|
|
|
struct wd_timer *wdt = (struct wd_timer *)WDT_BASE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Disable watchdog
|
|
|
|
*/
|
|
|
|
writel(0xAAAA, &wdt->wdtwspr);
|
|
|
|
while (readl(&wdt->wdtwwps) != 0x0)
|
|
|
|
;
|
|
|
|
writel(0x5555, &wdt->wdtwspr);
|
|
|
|
while (readl(&wdt->wdtwwps) != 0x0)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2013-08-19 14:38:59 +00:00
|
|
|
void hw_watchdog_init(void)
|
|
|
|
{
|
|
|
|
struct wd_timer *wdt = (struct wd_timer *)WDT_BASE;
|
|
|
|
|
2017-02-19 22:24:38 +00:00
|
|
|
/*
|
|
|
|
* Make sure the watchdog is disabled. This is unfortunately required
|
|
|
|
* because writing to various registers with the watchdog running has no
|
|
|
|
* effect.
|
|
|
|
*/
|
|
|
|
hw_watchdog_disable();
|
|
|
|
|
2013-08-19 14:38:59 +00:00
|
|
|
/* initialize prescaler */
|
|
|
|
while (readl(&wdt->wdtwwps) & WDT_WWPS_PEND_WCLR)
|
|
|
|
;
|
|
|
|
|
|
|
|
writel(WDT_WCLR_PRE | (PTV << WDT_WCLR_PTV_OFF), &wdt->wdtwclr);
|
|
|
|
while (readl(&wdt->wdtwwps) & WDT_WWPS_PEND_WCLR)
|
|
|
|
;
|
|
|
|
|
|
|
|
omap_wdt_set_timeout(WDT_HW_TIMEOUT);
|
|
|
|
|
|
|
|
/* Sequence to enable the watchdog */
|
|
|
|
writel(0xBBBB, &wdt->wdtwspr);
|
|
|
|
while ((readl(&wdt->wdtwwps)) & WDT_WWPS_PEND_WSPR)
|
|
|
|
;
|
|
|
|
|
|
|
|
writel(0x4444, &wdt->wdtwspr);
|
|
|
|
while ((readl(&wdt->wdtwwps)) & WDT_WWPS_PEND_WSPR)
|
|
|
|
;
|
|
|
|
}
|
2019-07-31 16:24:07 +00:00
|
|
|
|
|
|
|
void watchdog_reset(void)
|
|
|
|
{
|
|
|
|
hw_watchdog_reset();
|
|
|
|
}
|
|
|
|
|
2019-07-31 16:24:06 +00:00
|
|
|
#else
|
2019-07-31 16:24:07 +00:00
|
|
|
|
2019-07-31 16:24:06 +00:00
|
|
|
static int omap3_wdt_reset(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct omap3_wdt_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2020-01-24 04:44:25 +00:00
|
|
|
/*
|
|
|
|
* Somebody just triggered watchdog reset and write to WTGR register
|
|
|
|
* is in progress. It is resetting right now, no need to trigger it
|
|
|
|
* again
|
|
|
|
*/
|
2019-07-31 16:24:06 +00:00
|
|
|
if ((readl(&priv->regs->wdtwwps)) & WDT_WWPS_PEND_WTGR)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
priv->wdt_trgr_pattern = ~(priv->wdt_trgr_pattern);
|
|
|
|
writel(priv->wdt_trgr_pattern, &priv->regs->wdtwtgr);
|
2020-01-24 04:44:25 +00:00
|
|
|
/*
|
|
|
|
* Don't wait for posted write to complete, i.e. don't check
|
|
|
|
* WDT_WWPS_PEND_WTGR bit in WWPS register. There is no writes to
|
|
|
|
* WTGR register outside of this func, and if entering it
|
|
|
|
* we see WDT_WWPS_PEND_WTGR bit set, it means watchdog reset
|
|
|
|
* was just triggered. This prevents us from wasting time in busy
|
|
|
|
* polling of WDT_WWPS_PEND_WTGR bit.
|
|
|
|
*/
|
2019-07-31 16:24:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int omap3_wdt_stop(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct omap3_wdt_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2020-01-24 04:44:25 +00:00
|
|
|
/* disable watchdog */
|
2019-07-31 16:24:06 +00:00
|
|
|
writel(0xAAAA, &priv->regs->wdtwspr);
|
|
|
|
while (readl(&priv->regs->wdtwwps) != 0x0)
|
|
|
|
;
|
|
|
|
writel(0x5555, &priv->regs->wdtwspr);
|
|
|
|
while (readl(&priv->regs->wdtwwps) != 0x0)
|
|
|
|
;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int omap3_wdt_start(struct udevice *dev, u64 timeout_ms, ulong flags)
|
|
|
|
{
|
|
|
|
struct omap3_wdt_priv *priv = dev_get_priv(dev);
|
2020-01-24 04:44:23 +00:00
|
|
|
u32 pre_margin = GET_WLDR_VAL(timeout_ms / 1000);
|
2020-01-24 04:44:25 +00:00
|
|
|
/*
|
|
|
|
* Make sure the watchdog is disabled. This is unfortunately required
|
|
|
|
* because writing to various registers with the watchdog running has
|
|
|
|
* no effect.
|
|
|
|
*/
|
2019-07-31 16:24:06 +00:00
|
|
|
omap3_wdt_stop(dev);
|
|
|
|
|
2020-01-24 04:44:25 +00:00
|
|
|
/* initialize prescaler */
|
2019-07-31 16:24:06 +00:00
|
|
|
while (readl(&priv->regs->wdtwwps) & WDT_WWPS_PEND_WCLR)
|
|
|
|
;
|
|
|
|
|
|
|
|
writel(WDT_WCLR_PRE | (PTV << WDT_WCLR_PTV_OFF), &priv->regs->wdtwclr);
|
|
|
|
while (readl(&priv->regs->wdtwwps) & WDT_WWPS_PEND_WCLR)
|
|
|
|
;
|
2020-01-24 04:44:25 +00:00
|
|
|
/* just count up at 32 KHz */
|
2019-07-31 16:24:06 +00:00
|
|
|
while (readl(&priv->regs->wdtwwps) & WDT_WWPS_PEND_WLDR)
|
|
|
|
;
|
|
|
|
|
|
|
|
writel(pre_margin, &priv->regs->wdtwldr);
|
|
|
|
while (readl(&priv->regs->wdtwwps) & WDT_WWPS_PEND_WLDR)
|
|
|
|
;
|
2020-01-24 04:44:25 +00:00
|
|
|
/* Sequence to enable the watchdog */
|
2019-07-31 16:24:06 +00:00
|
|
|
writel(0xBBBB, &priv->regs->wdtwspr);
|
|
|
|
while ((readl(&priv->regs->wdtwwps)) & WDT_WWPS_PEND_WSPR)
|
|
|
|
;
|
|
|
|
|
|
|
|
writel(0x4444, &priv->regs->wdtwspr);
|
|
|
|
while ((readl(&priv->regs->wdtwwps)) & WDT_WWPS_PEND_WSPR)
|
|
|
|
;
|
|
|
|
|
2020-01-24 04:44:24 +00:00
|
|
|
/* Trigger the watchdog to actually reload the counter. */
|
|
|
|
while ((readl(&priv->regs->wdtwwps)) & WDT_WWPS_PEND_WTGR)
|
|
|
|
;
|
|
|
|
|
|
|
|
priv->wdt_trgr_pattern = ~(priv->wdt_trgr_pattern);
|
|
|
|
writel(priv->wdt_trgr_pattern, &priv->regs->wdtwtgr);
|
|
|
|
|
|
|
|
while ((readl(&priv->regs->wdtwwps)) & WDT_WWPS_PEND_WTGR)
|
|
|
|
;
|
|
|
|
|
2019-07-31 16:24:06 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int omap3_wdt_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct omap3_wdt_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2020-07-24 12:42:06 +00:00
|
|
|
priv->regs = (struct wd_timer *)devfdt_get_addr(dev);
|
2019-07-31 16:24:06 +00:00
|
|
|
if (!priv->regs)
|
|
|
|
return -EINVAL;
|
|
|
|
|
2019-09-16 08:09:17 +00:00
|
|
|
priv->wdt_trgr_pattern = 0x1234;
|
2019-07-31 16:24:06 +00:00
|
|
|
debug("%s: Probing wdt%u\n", __func__, dev->seq);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wdt_ops omap3_wdt_ops = {
|
|
|
|
.start = omap3_wdt_start,
|
|
|
|
.stop = omap3_wdt_stop,
|
|
|
|
.reset = omap3_wdt_reset,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id omap3_wdt_ids[] = {
|
|
|
|
{ .compatible = "ti,omap3-wdt" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(omap3_wdt) = {
|
|
|
|
.name = "omap3_wdt",
|
|
|
|
.id = UCLASS_WDT,
|
|
|
|
.of_match = omap3_wdt_ids,
|
|
|
|
.ops = &omap3_wdt_ops,
|
|
|
|
.probe = omap3_wdt_probe,
|
|
|
|
.priv_auto_alloc_size = sizeof(struct omap3_wdt_priv),
|
|
|
|
};
|
|
|
|
#endif /* !CONFIG_IS_ENABLED(WDT) */
|