/* SPDX-License-Identifier: GPL-2.0-only */1/*2* Copyright (C) 2010,2011 Google, Inc.3* Copyright (C) 2011-2012 NVIDIA CORPORATION. All Rights Reserved.4*5* Author:6* Colin Cross <[email protected]>7* Erik Gilling <[email protected]>8* Doug Anderson <[email protected]>9* Stephen Warren <[email protected]>10*11* Portions based on mach-omap2's debug-macro.S12* Copyright (C) 1994-1999 Russell King13*/1415#include <linux/serial_reg.h>1617#define UART_SHIFT 21819/* Physical addresses */20#define TEGRA_CLK_RESET_BASE 0x6000600021#define TEGRA_APB_MISC_BASE 0x7000000022#define TEGRA_UARTA_BASE 0x7000600023#define TEGRA_UARTB_BASE 0x7000604024#define TEGRA_UARTC_BASE 0x7000620025#define TEGRA_UARTD_BASE 0x7000630026#define TEGRA_UARTE_BASE 0x7000640027#define TEGRA_PMC_BASE 0x7000e4002829#define TEGRA_CLK_RST_DEVICES_L (TEGRA_CLK_RESET_BASE + 0x04)30#define TEGRA_CLK_RST_DEVICES_H (TEGRA_CLK_RESET_BASE + 0x08)31#define TEGRA_CLK_RST_DEVICES_U (TEGRA_CLK_RESET_BASE + 0x0c)32#define TEGRA_CLK_OUT_ENB_L (TEGRA_CLK_RESET_BASE + 0x10)33#define TEGRA_CLK_OUT_ENB_H (TEGRA_CLK_RESET_BASE + 0x14)34#define TEGRA_CLK_OUT_ENB_U (TEGRA_CLK_RESET_BASE + 0x18)35#define TEGRA_PMC_SCRATCH20 (TEGRA_PMC_BASE + 0xa0)36#define TEGRA_APB_MISC_GP_HIDREV (TEGRA_APB_MISC_BASE + 0x804)3738/*39* Must be section-aligned since a section mapping is used early on.40* Must not overlap with regions in mach-tegra/io.c:tegra_io_desc[].41*/42#define UART_VIRTUAL_BASE 0xfe8000004344#define checkuart(rp, rv, lhu, bit, uart) \45/* Load address of CLK_RST register */ \46ldr rp, =TEGRA_CLK_RST_DEVICES_##lhu ; \47/* Load value from CLK_RST register */ \48ldr rp, [rp, #0] ; \49/* Test UART's reset bit */ \50tst rp, #(1 << bit) ; \51/* If set, can't use UART; jump to save no UART */ \52bne 90f ; \53/* Load address of CLK_OUT_ENB register */ \54ldr rp, =TEGRA_CLK_OUT_ENB_##lhu ; \55/* Load value from CLK_OUT_ENB register */ \56ldr rp, [rp, #0] ; \57/* Test UART's clock enable bit */ \58tst rp, #(1 << bit) ; \59/* If clear, can't use UART; jump to save no UART */ \60beq 90f ; \61/* Passed all tests, load address of UART registers */ \62ldr rp, =TEGRA_UART##uart##_BASE ; \63/* Jump to save UART address */ \64b 91f6566.macro addruart, rp, rv, tmp67adr \rp, 99f @ actual addr of 99f68ldr \rv, [\rp] @ linked addr is stored there69sub \rv, \rv, \rp @ offset between the two70ldr \rp, [\rp, #4] @ linked tegra_uart_config71sub \tmp, \rp, \rv @ actual tegra_uart_config72ldr \rp, [\tmp] @ Load tegra_uart_config73cmp \rp, #1 @ needs initialization?74bne 100f @ no; go load the addresses75mov \rv, #0 @ yes; record init is done76str \rv, [\tmp]7778#ifdef CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA79/* Check ODMDATA */8010: ldr \rp, =TEGRA_PMC_SCRATCH2081ldr \rp, [\rp, #0] @ Load PMC_SCRATCH2082lsr \rv, \rp, #18 @ 19:18 are console type83and \rv, \rv, #384cmp \rv, #2 @ 2 and 3 mean DCC, UART85beq 11f @ some boards swap the meaning86cmp \rv, #3 @ so accept either87bne 90f8811: lsr \rv, \rp, #15 @ 17:15 are UART ID89and \rv, #790cmp \rv, #0 @ UART 0?91beq 20f92cmp \rv, #1 @ UART 1?93beq 21f94cmp \rv, #2 @ UART 2?95beq 22f96cmp \rv, #3 @ UART 3?97beq 23f98cmp \rv, #4 @ UART 4?99beq 24f100b 90f @ invalid101#endif102103#if defined(CONFIG_TEGRA_DEBUG_UARTA) || \104defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)105/* Check UART A validity */10620: checkuart(\rp, \rv, L, 6, A)107#endif108109#if defined(CONFIG_TEGRA_DEBUG_UARTB) || \110defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)111/* Check UART B validity */11221: checkuart(\rp, \rv, L, 7, B)113#endif114115#if defined(CONFIG_TEGRA_DEBUG_UARTC) || \116defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)117/* Check UART C validity */11822: checkuart(\rp, \rv, H, 23, C)119#endif120121#if defined(CONFIG_TEGRA_DEBUG_UARTD) || \122defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)123/* Check UART D validity */12423: checkuart(\rp, \rv, U, 1, D)125#endif126127#if defined(CONFIG_TEGRA_DEBUG_UARTE) || \128defined(CONFIG_TEGRA_DEBUG_UART_AUTO_ODMDATA)129/* Check UART E validity */13024:131checkuart(\rp, \rv, U, 2, E)132#endif133134/* No valid UART found */13590: mov \rp, #0136/* fall through */137138/* Record whichever UART we chose */13991: str \rp, [\tmp, #4] @ Store in tegra_uart_phys140cmp \rp, #0 @ Valid UART address?141bne 92f @ Yes, go process it142str \rp, [\tmp, #8] @ Store 0 in tegra_uart_virt143b 100f @ Done14492: and \rv, \rp, #0xffffff @ offset within 1MB section145add \rv, \rv, #UART_VIRTUAL_BASE146str \rv, [\tmp, #8] @ Store in tegra_uart_virt147b 100f148149.align15099: .word .151#if defined(ZIMAGE)152.word . + 4153/*154* Storage for the state maintained by the macro.155*156* In the kernel proper, this data is located in arch/arm/mach-tegra/tegra.c.157* That's because this header is included from multiple files, and we only158* want a single copy of the data. In particular, the UART probing code above159* assumes it's running using physical addresses. This is true when this file160* is included from head.o, but not when included from debug.o. So we need161* to share the probe results between the two copies, rather than having162* to re-run the probing again later.163*164* In the decompressor, we put the storage right here, since common.c165* isn't included in the decompressor build. This storage data gets put in166* .text even though it's really data, since .data is discarded from the167* decompressor. Luckily, .text is writeable in the decompressor, unless168* CONFIG_ZBOOT_ROM. That dependency is handled in arch/arm/Kconfig.debug.169*/170/* Debug UART initialization required */171.word 1172/* Debug UART physical address */173.word 0174/* Debug UART virtual address */175.word 0176#else177.word tegra_uart_config178#endif179.ltorg180181/* Load previously selected UART address */182100: ldr \rp, [\tmp, #4] @ Load tegra_uart_phys183ldr \rv, [\tmp, #8] @ Load tegra_uart_virt184.endm185186/*187* Code below is swiped from <asm/hardware/debug-8250.S>, but add an extra188* check to make sure that the UART address is actually valid.189*/190191.macro senduart, rd, rx192cmp \rx, #0193strbne \rd, [\rx, #UART_TX << UART_SHIFT]1941001:195.endm196197.macro busyuart, rd, rx198cmp \rx, #0199beq 1002f2001001: ldrb \rd, [\rx, #UART_LSR << UART_SHIFT]201and \rd, \rd, #UART_LSR_THRE202teq \rd, #UART_LSR_THRE203bne 1001b2041002:205.endm206207.macro waituartcts, rd, rx208cmp \rx, #0209beq 1002f2101001: ldrb \rd, [\rx, #UART_MSR << UART_SHIFT]211tst \rd, #UART_MSR_CTS212beq 1001b2131002:214.endm215216.macro waituarttxrdy,rd,rx217.endm218219220