1*2874c5fdSThomas Gleixner // SPDX-License-Identifier: GPL-2.0-or-later
281fbc5efSPaul Walmsley /*
381fbc5efSPaul Walmsley * OMAP2+ MPU WD_TIMER-specific code
481fbc5efSPaul Walmsley *
5b13159afSPaul Walmsley * Copyright (C) 2012 Texas Instruments, Inc.
681fbc5efSPaul Walmsley */
781fbc5efSPaul Walmsley
881fbc5efSPaul Walmsley #include <linux/kernel.h>
981fbc5efSPaul Walmsley #include <linux/io.h>
1081fbc5efSPaul Walmsley #include <linux/err.h>
1181fbc5efSPaul Walmsley
1237c67d03SPaul Walmsley #include <linux/platform_data/omap-wd-timer.h>
1381fbc5efSPaul Walmsley
1437c67d03SPaul Walmsley #include "omap_hwmod.h"
1537c67d03SPaul Walmsley #include "omap_device.h"
16a9b365bdSNishanth Menon #include "wd_timer.h"
17414e4128SKevin Hilman #include "common.h"
1837c67d03SPaul Walmsley #include "prm.h"
1937c67d03SPaul Walmsley #include "soc.h"
20a9b365bdSNishanth Menon
2181fbc5efSPaul Walmsley /*
2281fbc5efSPaul Walmsley * In order to avoid any assumptions from bootloader regarding WDT
2381fbc5efSPaul Walmsley * settings, WDT module is reset during init. This enables the watchdog
2481fbc5efSPaul Walmsley * timer. Hence it is required to disable the watchdog after the WDT reset
2581fbc5efSPaul Walmsley * during init. Otherwise the system would reboot as per the default
2681fbc5efSPaul Walmsley * watchdog timer registers settings.
2781fbc5efSPaul Walmsley */
2881fbc5efSPaul Walmsley #define OMAP_WDT_WPS 0x34
2981fbc5efSPaul Walmsley #define OMAP_WDT_SPR 0x48
3081fbc5efSPaul Walmsley
omap2_wd_timer_disable(struct omap_hwmod * oh)3181fbc5efSPaul Walmsley int omap2_wd_timer_disable(struct omap_hwmod *oh)
3281fbc5efSPaul Walmsley {
3381fbc5efSPaul Walmsley void __iomem *base;
3481fbc5efSPaul Walmsley
3581fbc5efSPaul Walmsley if (!oh) {
3681fbc5efSPaul Walmsley pr_err("%s: Could not look up wdtimer_hwmod\n", __func__);
3781fbc5efSPaul Walmsley return -EINVAL;
3881fbc5efSPaul Walmsley }
3981fbc5efSPaul Walmsley
4081fbc5efSPaul Walmsley base = omap_hwmod_get_mpu_rt_va(oh);
4181fbc5efSPaul Walmsley if (!base) {
4281fbc5efSPaul Walmsley pr_err("%s: Could not get the base address for %s\n",
4381fbc5efSPaul Walmsley oh->name, __func__);
4481fbc5efSPaul Walmsley return -EINVAL;
4581fbc5efSPaul Walmsley }
4681fbc5efSPaul Walmsley
4781fbc5efSPaul Walmsley /* sequence required to disable watchdog */
48edfaf05cSVictor Kamensky writel_relaxed(0xAAAA, base + OMAP_WDT_SPR);
49edfaf05cSVictor Kamensky while (readl_relaxed(base + OMAP_WDT_WPS) & 0x10)
5081fbc5efSPaul Walmsley cpu_relax();
5181fbc5efSPaul Walmsley
52edfaf05cSVictor Kamensky writel_relaxed(0x5555, base + OMAP_WDT_SPR);
53edfaf05cSVictor Kamensky while (readl_relaxed(base + OMAP_WDT_WPS) & 0x10)
5481fbc5efSPaul Walmsley cpu_relax();
5581fbc5efSPaul Walmsley
56ff2516fbSPaul Walmsley return 0;
5781fbc5efSPaul Walmsley }
5881fbc5efSPaul Walmsley
59414e4128SKevin Hilman /**
60414e4128SKevin Hilman * omap2_wdtimer_reset - reset and disable the WDTIMER IP block
61414e4128SKevin Hilman * @oh: struct omap_hwmod *
62414e4128SKevin Hilman *
63414e4128SKevin Hilman * After the WDTIMER IP blocks are reset on OMAP2/3, we must also take
64414e4128SKevin Hilman * care to execute the special watchdog disable sequence. This is
65414e4128SKevin Hilman * because the watchdog is re-armed upon OCP softreset. (On OMAP4,
66414e4128SKevin Hilman * this behavior was apparently changed and the watchdog is no longer
67414e4128SKevin Hilman * re-armed after an OCP soft-reset.) Returns -ETIMEDOUT if the reset
68414e4128SKevin Hilman * did not complete, or 0 upon success.
69414e4128SKevin Hilman *
70414e4128SKevin Hilman * XXX Most of this code should be moved to the omap_hwmod.c layer
71414e4128SKevin Hilman * during a normal merge window. omap_hwmod_softreset() should be
72414e4128SKevin Hilman * renamed to omap_hwmod_set_ocp_softreset(), and omap_hwmod_softreset()
73414e4128SKevin Hilman * should call the hwmod _ocp_softreset() code.
74414e4128SKevin Hilman */
omap2_wd_timer_reset(struct omap_hwmod * oh)75414e4128SKevin Hilman int omap2_wd_timer_reset(struct omap_hwmod *oh)
76414e4128SKevin Hilman {
77414e4128SKevin Hilman int c = 0;
78414e4128SKevin Hilman
79414e4128SKevin Hilman /* Write to the SOFTRESET bit */
80414e4128SKevin Hilman omap_hwmod_softreset(oh);
81414e4128SKevin Hilman
82414e4128SKevin Hilman /* Poll on RESETDONE bit */
83414e4128SKevin Hilman omap_test_timeout((omap_hwmod_read(oh,
84414e4128SKevin Hilman oh->class->sysc->syss_offs)
85414e4128SKevin Hilman & SYSS_RESETDONE_MASK),
86414e4128SKevin Hilman MAX_MODULE_SOFTRESET_WAIT, c);
87414e4128SKevin Hilman
88414e4128SKevin Hilman if (oh->class->sysc->srst_udelay)
89414e4128SKevin Hilman udelay(oh->class->sysc->srst_udelay);
90414e4128SKevin Hilman
91414e4128SKevin Hilman if (c == MAX_MODULE_SOFTRESET_WAIT)
923d0cb73eSJoe Perches pr_warn("%s: %s: softreset failed (waited %d usec)\n",
93414e4128SKevin Hilman __func__, oh->name, MAX_MODULE_SOFTRESET_WAIT);
94414e4128SKevin Hilman else
95414e4128SKevin Hilman pr_debug("%s: %s: softreset in %d usec\n", __func__,
96414e4128SKevin Hilman oh->name, c);
97414e4128SKevin Hilman
98414e4128SKevin Hilman return (c == MAX_MODULE_SOFTRESET_WAIT) ? -ETIMEDOUT :
99414e4128SKevin Hilman omap2_wd_timer_disable(oh);
100414e4128SKevin Hilman }
101