/* SPDX-License-Identifier: GPL-2.0-only */1/* Copyright (C) 2016 Broadcom */2#include <linux/serial_reg.h>3#include <asm/cputype.h>45/* Physical register offset and virtual register offset */6#define REG_PHYS_BASE 0xf00000007#define REG_PHYS_BASE_V7 0x080000008#define REG_VIRT_BASE 0xfc0000009#define REG_PHYS_ADDR(x) ((x) + REG_PHYS_BASE)10#define REG_PHYS_ADDR_V7(x) ((x) + REG_PHYS_BASE_V7)1112/* Product id can be read from here */13#define SUN_TOP_CTRL_BASE REG_PHYS_ADDR(0x404000)14#define SUN_TOP_CTRL_BASE_V7 REG_PHYS_ADDR_V7(0x404000)1516#define UARTA_3390 REG_PHYS_ADDR(0x40a900)17#define UARTA_72116 UARTA_725518#define UARTA_7250 REG_PHYS_ADDR(0x40b400)19#define UARTA_7255 REG_PHYS_ADDR(0x40c000)20#define UARTA_7260 UARTA_725521#define UARTA_7268 UARTA_725522#define UARTA_7271 UARTA_726823#define UARTA_7278 REG_PHYS_ADDR_V7(0x40c000)24#define UARTA_7216 UARTA_727825#define UARTA_72164 UARTA_727826#define UARTA_72165 UARTA_727827#define UARTA_7364 REG_PHYS_ADDR(0x40b000)28#define UARTA_7366 UARTA_736429#define UARTA_74165 UARTA_727830#define UARTA_74371 REG_PHYS_ADDR(0x406b00)31#define UARTA_7439 REG_PHYS_ADDR(0x40a900)32#define UARTA_7445 REG_PHYS_ADDR(0x40ab00)3334#define UART_SHIFT 23536#define checkuart(rp, rv, family_id, family) \37/* Load family id */ \38ldr rp, =family_id ; \39/* Compare SUN_TOP_CTRL value against it */ \40cmp rp, rv ; \41/* Passed test, load address */ \42ldreq rp, =UARTA_##family ; \43/* Jump to save UART address */ \44beq 91f4546.macro addruart, rp, rv, tmp47adr \rp, 99f @ actual addr of 99f48ldr \rv, [\rp] @ linked addr is stored there49sub \rv, \rv, \rp @ offset between the two50ldr \rp, [\rp, #4] @ linked brcmstb_uart_config51sub \tmp, \rp, \rv @ actual brcmstb_uart_config52ldr \rp, [\tmp] @ Load brcmstb_uart_config53cmp \rp, #1 @ needs initialization?54bne 100f @ no; go load the addresses55mov \rv, #0 @ yes; record init is done56str \rv, [\tmp]5758/* Check for V7 memory map if B53 */59mrc p15, 0, \rv, c0, c0, 0 @ get Main ID register60ldr \rp, =ARM_CPU_PART_MASK61and \rv, \rv, \rp62ldr \rp, =ARM_CPU_PART_BRAHMA_B53 @ check for B53 CPU63cmp \rv, \rp64bne 10f6566/* if PERIPHBASE doesn't overlap REG_PHYS_BASE use V7 map */67mrc p15, 1, \rv, c15, c3, 0 @ get PERIPHBASE from CBAR68ands \rv, \rv, #REG_PHYS_BASE69ldreq \rp, =SUN_TOP_CTRL_BASE_V77071/* Check SUN_TOP_CTRL base */7210: ldrne \rp, =SUN_TOP_CTRL_BASE @ load SUN_TOP_CTRL PA73ldr \rv, [\rp, #0] @ get register contents74ARM_BE8( rev \rv, \rv )75and \rv, \rv, #0xffffff00 @ strip revision bits [7:0]7677/* Chip specific detection starts here */7820: checkuart(\rp, \rv, 0x33900000, 3390)7921: checkuart(\rp, \rv, 0x07211600, 72116)8022: checkuart(\rp, \rv, 0x72160000, 7216)8123: checkuart(\rp, \rv, 0x07216400, 72164)8224: checkuart(\rp, \rv, 0x07216500, 72165)8325: checkuart(\rp, \rv, 0x72500000, 7250)8426: checkuart(\rp, \rv, 0x72550000, 7255)8527: checkuart(\rp, \rv, 0x72600000, 7260)8628: checkuart(\rp, \rv, 0x72680000, 7268)8729: checkuart(\rp, \rv, 0x72710000, 7271)8830: checkuart(\rp, \rv, 0x72780000, 7278)8931: checkuart(\rp, \rv, 0x73640000, 7364)9032: checkuart(\rp, \rv, 0x73660000, 7366)9133: checkuart(\rp, \rv, 0x07416500, 74165)9234: checkuart(\rp, \rv, 0x07437100, 74371)9335: checkuart(\rp, \rv, 0x74390000, 7439)9436: checkuart(\rp, \rv, 0x74450000, 7445)9596/* No valid UART found */9790: mov \rp, #098/* fall through */99100/* Record whichever UART we chose */10191: str \rp, [\tmp, #4] @ Store in brcmstb_uart_phys102cmp \rp, #0 @ Valid UART address?103bne 92f @ Yes, go process it104str \rp, [\tmp, #8] @ Store 0 in brcmstb_uart_virt105b 100f @ Done10692: and \rv, \rp, #0xffffff @ offset within 16MB section107add \rv, \rv, #REG_VIRT_BASE108str \rv, [\tmp, #8] @ Store in brcmstb_uart_virt109b 100f110111.align11299: .word .113.word brcmstb_uart_config114.ltorg115116/* Load previously selected UART address */117100: ldr \rp, [\tmp, #4] @ Load brcmstb_uart_phys118ldr \rv, [\tmp, #8] @ Load brcmstb_uart_virt119.endm120121.macro store, rd, rx:vararg122ARM_BE8( rev \rd, \rd )123str \rd, \rx124.endm125126.macro load, rd, rx:vararg127ldr \rd, \rx128ARM_BE8( rev \rd, \rd )129.endm130131.macro senduart,rd,rx132store \rd, [\rx, #UART_TX << UART_SHIFT]133.endm134135.macro busyuart,rd,rx1361002: load \rd, [\rx, #UART_LSR << UART_SHIFT]137and \rd, \rd, #UART_LSR_TEMT | UART_LSR_THRE138teq \rd, #UART_LSR_TEMT | UART_LSR_THRE139bne 1002b140.endm141142.macro waituarttxrdy,rd,rx143.endm144145.macro waituartcts,rd,rx146.endm147148/*149* Storage for the state maintained by the macros above.150*151* In the kernel proper, this data is located in arch/arm/mach-bcm/brcmstb.c.152* That's because this header is included from multiple files, and we only153* want a single copy of the data. In particular, the UART probing code above154* assumes it's running using physical addresses. This is true when this file155* is included from head.o, but not when included from debug.o. So we need156* to share the probe results between the two copies, rather than having157* to re-run the probing again later.158*159* In the decompressor, we put the symbol/storage right here, since common.c160* isn't included in the decompressor build. This symbol gets put in .text161* even though it's really data, since .data is discarded from the162* decompressor. Luckily, .text is writeable in the decompressor, unless163* CONFIG_ZBOOT_ROM. That dependency is handled in arch/arm/Kconfig.debug.164*/165#if defined(ZIMAGE)166brcmstb_uart_config:167/* Debug UART initialization required */168.word 1169/* Debug UART physical address */170.word 0171/* Debug UART virtual address */172.word 0173#endif174175176