162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * OMAP1 reset support
462306a36Sopenharmony_ci */
562306a36Sopenharmony_ci#include <linux/kernel.h>
662306a36Sopenharmony_ci#include <linux/io.h>
762306a36Sopenharmony_ci#include <linux/reboot.h>
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci#include "hardware.h"
1062306a36Sopenharmony_ci#include "iomap.h"
1162306a36Sopenharmony_ci#include "common.h"
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci/* ARM_SYSST bit shifts related to SoC reset sources */
1462306a36Sopenharmony_ci#define ARM_SYSST_POR_SHIFT				5
1562306a36Sopenharmony_ci#define ARM_SYSST_EXT_RST_SHIFT				4
1662306a36Sopenharmony_ci#define ARM_SYSST_ARM_WDRST_SHIFT			2
1762306a36Sopenharmony_ci#define ARM_SYSST_GLOB_SWRST_SHIFT			1
1862306a36Sopenharmony_ci
1962306a36Sopenharmony_ci/* Standardized reset source bits (across all OMAP SoCs) */
2062306a36Sopenharmony_ci#define OMAP_GLOBAL_COLD_RST_SRC_ID_SHIFT		0
2162306a36Sopenharmony_ci#define OMAP_GLOBAL_WARM_RST_SRC_ID_SHIFT		1
2262306a36Sopenharmony_ci#define OMAP_MPU_WD_RST_SRC_ID_SHIFT			3
2362306a36Sopenharmony_ci#define OMAP_EXTWARM_RST_SRC_ID_SHIFT			5
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_civoid omap1_restart(enum reboot_mode mode, const char *cmd)
2762306a36Sopenharmony_ci{
2862306a36Sopenharmony_ci	/*
2962306a36Sopenharmony_ci	 * Workaround for 5912/1611b bug mentioned in sprz209d.pdf p. 28
3062306a36Sopenharmony_ci	 * "Global Software Reset Affects Traffic Controller Frequency".
3162306a36Sopenharmony_ci	 */
3262306a36Sopenharmony_ci	if (cpu_is_omap5912()) {
3362306a36Sopenharmony_ci		omap_writew(omap_readw(DPLL_CTL) & ~(1 << 4), DPLL_CTL);
3462306a36Sopenharmony_ci		omap_writew(0x8, ARM_RSTCT1);
3562306a36Sopenharmony_ci	}
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci	omap_writew(1, ARM_RSTCT1);
3862306a36Sopenharmony_ci}
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci/**
4162306a36Sopenharmony_ci * omap1_get_reset_sources - return the source of the SoC's last reset
4262306a36Sopenharmony_ci *
4362306a36Sopenharmony_ci * Returns bits that represent the last reset source for the SoC.  The
4462306a36Sopenharmony_ci * format is standardized across OMAPs for use by the OMAP watchdog.
4562306a36Sopenharmony_ci */
4662306a36Sopenharmony_ciu32 omap1_get_reset_sources(void)
4762306a36Sopenharmony_ci{
4862306a36Sopenharmony_ci	u32 ret = 0;
4962306a36Sopenharmony_ci	u16 rs;
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ci	rs = __raw_readw(OMAP1_IO_ADDRESS(ARM_SYSST));
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci	if (rs & (1 << ARM_SYSST_POR_SHIFT))
5462306a36Sopenharmony_ci		ret |= 1 << OMAP_GLOBAL_COLD_RST_SRC_ID_SHIFT;
5562306a36Sopenharmony_ci	if (rs & (1 << ARM_SYSST_EXT_RST_SHIFT))
5662306a36Sopenharmony_ci		ret |= 1 << OMAP_EXTWARM_RST_SRC_ID_SHIFT;
5762306a36Sopenharmony_ci	if (rs & (1 << ARM_SYSST_ARM_WDRST_SHIFT))
5862306a36Sopenharmony_ci		ret |= 1 << OMAP_MPU_WD_RST_SRC_ID_SHIFT;
5962306a36Sopenharmony_ci	if (rs & (1 << ARM_SYSST_GLOB_SWRST_SHIFT))
6062306a36Sopenharmony_ci		ret |= 1 << OMAP_GLOBAL_WARM_RST_SRC_ID_SHIFT;
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci	return ret;
6362306a36Sopenharmony_ci}
64