18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * arch/arm/mach-ep93xx/include/mach/uncompress.h
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2006 Lennert Buytenhek <buytenh@wantstofly.org>
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <mach/ep93xx-regs.h>
98c2ecf20Sopenharmony_ci#include <asm/mach-types.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_cistatic unsigned char __raw_readb(unsigned int ptr)
128c2ecf20Sopenharmony_ci{
138c2ecf20Sopenharmony_ci	return *((volatile unsigned char *)ptr);
148c2ecf20Sopenharmony_ci}
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_cistatic unsigned int __raw_readl(unsigned int ptr)
178c2ecf20Sopenharmony_ci{
188c2ecf20Sopenharmony_ci	return *((volatile unsigned int *)ptr);
198c2ecf20Sopenharmony_ci}
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistatic void __raw_writeb(unsigned char value, unsigned int ptr)
228c2ecf20Sopenharmony_ci{
238c2ecf20Sopenharmony_ci	*((volatile unsigned char *)ptr) = value;
248c2ecf20Sopenharmony_ci}
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistatic void __raw_writel(unsigned int value, unsigned int ptr)
278c2ecf20Sopenharmony_ci{
288c2ecf20Sopenharmony_ci	*((volatile unsigned int *)ptr) = value;
298c2ecf20Sopenharmony_ci}
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci#define PHYS_UART_DATA		(CONFIG_DEBUG_UART_PHYS + 0x00)
328c2ecf20Sopenharmony_ci#define PHYS_UART_FLAG		(CONFIG_DEBUG_UART_PHYS + 0x18)
338c2ecf20Sopenharmony_ci#define UART_FLAG_TXFF		0x20
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistatic inline void putc(int c)
368c2ecf20Sopenharmony_ci{
378c2ecf20Sopenharmony_ci	int i;
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci	for (i = 0; i < 10000; i++) {
408c2ecf20Sopenharmony_ci		/* Transmit fifo not full? */
418c2ecf20Sopenharmony_ci		if (!(__raw_readb(PHYS_UART_FLAG) & UART_FLAG_TXFF))
428c2ecf20Sopenharmony_ci			break;
438c2ecf20Sopenharmony_ci	}
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	__raw_writeb(c, PHYS_UART_DATA);
468c2ecf20Sopenharmony_ci}
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_cistatic inline void flush(void)
498c2ecf20Sopenharmony_ci{
508c2ecf20Sopenharmony_ci}
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci/*
548c2ecf20Sopenharmony_ci * Some bootloaders don't turn off DMA from the ethernet MAC before
558c2ecf20Sopenharmony_ci * jumping to linux, which means that we might end up with bits of RX
568c2ecf20Sopenharmony_ci * status and packet data scribbled over the uncompressed kernel image.
578c2ecf20Sopenharmony_ci * Work around this by resetting the ethernet MAC before we uncompress.
588c2ecf20Sopenharmony_ci */
598c2ecf20Sopenharmony_ci#define PHYS_ETH_SELF_CTL		0x80010020
608c2ecf20Sopenharmony_ci#define ETH_SELF_CTL_RESET		0x00000001
618c2ecf20Sopenharmony_ci
628c2ecf20Sopenharmony_cistatic void ethernet_reset(void)
638c2ecf20Sopenharmony_ci{
648c2ecf20Sopenharmony_ci	unsigned int v;
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ci	/* Reset the ethernet MAC.  */
678c2ecf20Sopenharmony_ci	v = __raw_readl(PHYS_ETH_SELF_CTL);
688c2ecf20Sopenharmony_ci	__raw_writel(v | ETH_SELF_CTL_RESET, PHYS_ETH_SELF_CTL);
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci	/* Wait for reset to finish.  */
718c2ecf20Sopenharmony_ci	while (__raw_readl(PHYS_ETH_SELF_CTL) & ETH_SELF_CTL_RESET)
728c2ecf20Sopenharmony_ci		;
738c2ecf20Sopenharmony_ci}
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci#define TS72XX_WDT_CONTROL_PHYS_BASE	0x23800000
768c2ecf20Sopenharmony_ci#define TS72XX_WDT_FEED_PHYS_BASE	0x23c00000
778c2ecf20Sopenharmony_ci#define TS72XX_WDT_FEED_VAL		0x05
788c2ecf20Sopenharmony_ci
798c2ecf20Sopenharmony_cistatic void __maybe_unused ts72xx_watchdog_disable(void)
808c2ecf20Sopenharmony_ci{
818c2ecf20Sopenharmony_ci	__raw_writeb(TS72XX_WDT_FEED_VAL, TS72XX_WDT_FEED_PHYS_BASE);
828c2ecf20Sopenharmony_ci	__raw_writeb(0, TS72XX_WDT_CONTROL_PHYS_BASE);
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistatic void arch_decomp_setup(void)
868c2ecf20Sopenharmony_ci{
878c2ecf20Sopenharmony_ci	if (machine_is_ts72xx())
888c2ecf20Sopenharmony_ci		ts72xx_watchdog_disable();
898c2ecf20Sopenharmony_ci	ethernet_reset();
908c2ecf20Sopenharmony_ci}
91