Skip to content

Commit d0cf9d8

Browse files
committed
ARM: brcmstb: Add earlyprintk support using run-time checks
The SUN_TOP_CTRL_FAMILY_ID register is at a fixed absolute address for all of our supported chips, so utilize its value to determine what the UARTA base address should be based on the value we read. Since the code is called both during decompressor when the MMU is off, and after the MMU has been turned on in the kernel, and we want to do the lookup only once, we use the same technique as tegra.S and have a shared storage location between the decompressor and the kernel. Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
1 parent 29b4817 commit d0cf9d8

3 files changed

Lines changed: 168 additions & 7 deletions

File tree

‎arch/arm/Kconfig.debug‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,11 @@ choice
186186
config DEBUG_BRCMSTB_UART
187187
bool "Use BRCMSTB UART for low-level debug"
188188
depends on ARCH_BRCMSTB
189-
select DEBUG_UART_8250
190189
help
191190
Say Y here if you want the debug print routines to direct
192-
their output to the first serial port on these devices.
191+
their output to the first serial port on these devices. The
192+
UART physical and virtual address is automatically provided
193+
based on the chip identification register value.
193194

194195
If you have a Broadcom STB chip and would like early print
195196
messages to appear over the UART, select this option.
@@ -1430,6 +1431,7 @@ config DEBUG_LL_INCLUDE
14301431
default "debug/zynq.S" if DEBUG_ZYNQ_UART0 || DEBUG_ZYNQ_UART1
14311432
default "debug/bcm63xx.S" if DEBUG_BCM63XX_UART
14321433
default "debug/digicolor.S" if DEBUG_DIGICOLOR_UA0
1434+
default "debug/brcmstb.S" if DEBUG_BRCMSTB_UART
14331435
default "mach/debug-macro.S"
14341436

14351437
# Compatibility options for PL01x
@@ -1520,7 +1522,6 @@ config DEBUG_UART_PHYS
15201522
default 0xe6e60000 if DEBUG_RCAR_GEN2_SCIF0
15211523
default 0xe8008000 if DEBUG_R7S72100_SCIF2
15221524
default 0xf0000be0 if ARCH_EBSA110
1523-
default 0xf040ab00 if DEBUG_BRCMSTB_UART
15241525
default 0xf1012000 if DEBUG_MVEBU_UART0_ALTERNATE
15251526
default 0xf1012100 if DEBUG_MVEBU_UART1_ALTERNATE
15261527
default 0xf7fc9000 if DEBUG_BERLIN_UART
@@ -1604,7 +1605,6 @@ config DEBUG_UART_VIRT
16041605
default 0xfb009000 if DEBUG_REALVIEW_STD_PORT
16051606
default 0xfb00c000 if DEBUG_AT91_SAMA5D4_USART3
16061607
default 0xfb10c000 if DEBUG_REALVIEW_PB1176_PORT
1607-
default 0xfc40ab00 if DEBUG_BRCMSTB_UART
16081608
default 0xfc705000 if DEBUG_ZTE_ZX
16091609
default 0xfcfe8600 if DEBUG_BCM63XX_UART
16101610
default 0xfd000000 if DEBUG_SPEAR3XX || DEBUG_SPEAR13XX
@@ -1677,8 +1677,7 @@ config DEBUG_UART_8250_WORD
16771677
DEBUG_ALPINE_UART0 || \
16781678
DEBUG_DAVINCI_DMx_UART0 || DEBUG_DAVINCI_DA8XX_UART1 || \
16791679
DEBUG_DAVINCI_DA8XX_UART2 || \
1680-
DEBUG_BCM_KONA_UART || DEBUG_RK32_UART2 || \
1681-
DEBUG_BRCMSTB_UART
1680+
DEBUG_BCM_KONA_UART || DEBUG_RK32_UART2
16821681

16831682
config DEBUG_UART_8250_PALMCHIP
16841683
bool "8250 UART is Palmchip BK-310x"
@@ -1697,7 +1696,8 @@ config DEBUG_UNCOMPRESS
16971696
bool
16981697
depends on ARCH_MULTIPLATFORM || PLAT_SAMSUNG || ARM_SINGLE_ARMV7M
16991698
default y if DEBUG_LL && !DEBUG_OMAP2PLUS_UART && \
1700-
(!DEBUG_TEGRA_UART || !ZBOOT_ROM)
1699+
(!DEBUG_TEGRA_UART || !ZBOOT_ROM) && \
1700+
!DEBUG_BRCMSTB_UART
17011701
help
17021702
This option influences the normal decompressor output for
17031703
multiplatform kernels. Normally, multiplatform kernels disable

‎arch/arm/include/debug/brcmstb.S‎

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*
2+
* Copyright (C) 2016 Broadcom
3+
*
4+
* This program is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU General Public License as
6+
* published by the Free Software Foundation version 2.
7+
*
8+
* This program is distributed "as is" WITHOUT ANY WARRANTY of any
9+
* kind, whether express or implied; without even the implied warranty
10+
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU General Public License for more details.
12+
*/
13+
#include <linux/serial_reg.h>
14+
15+
/* Physical register offset and virtual register offset */
16+
#define REG_PHYS_BASE 0xf0000000
17+
#define REG_VIRT_BASE 0xfc000000
18+
#define REG_PHYS_ADDR(x) ((x) + REG_PHYS_BASE)
19+
20+
/* Product id can be read from here */
21+
#define SUN_TOP_CTRL_BASE REG_PHYS_ADDR(0x404000)
22+
23+
#define UARTA_3390 REG_PHYS_ADDR(0x40a900)
24+
#define UARTA_7250 REG_PHYS_ADDR(0x40b400)
25+
#define UARTA_7268 REG_PHYS_ADDR(0x40c000)
26+
#define UARTA_7271 UARTA_7268
27+
#define UARTA_7364 REG_PHYS_ADDR(0x40b000)
28+
#define UARTA_7366 UARTA_7364
29+
#define UARTA_74371 REG_PHYS_ADDR(0x406b00)
30+
#define UARTA_7439 REG_PHYS_ADDR(0x40a900)
31+
#define UARTA_7445 REG_PHYS_ADDR(0x40ab00)
32+
33+
#define UART_SHIFT 2
34+
35+
#define checkuart(rp, rv, family_id, family) \
36+
/* Load family id */ \
37+
ldr rp, =family_id ; \
38+
/* Compare SUN_TOP_CTRL value against it */ \
39+
cmp rp, rv ; \
40+
/* Passed test, load address */ \
41+
ldreq rp, =UARTA_##family ; \
42+
/* Jump to save UART address */ \
43+
beq 91f
44+
45+
.macro addruart, rp, rv, tmp
46+
adr \rp, 99f @ actual addr of 99f
47+
ldr \rv, [\rp] @ linked addr is stored there
48+
sub \rv, \rv, \rp @ offset between the two
49+
ldr \rp, [\rp, #4] @ linked brcmstb_uart_config
50+
sub \tmp, \rp, \rv @ actual brcmstb_uart_config
51+
ldr \rp, [\tmp] @ Load brcmstb_uart_config
52+
cmp \rp, #1 @ needs initialization?
53+
bne 100f @ no; go load the addresses
54+
mov \rv, #0 @ yes; record init is done
55+
str \rv, [\tmp]
56+
57+
/* Check SUN_TOP_CTRL base */
58+
ldr \rp, =SUN_TOP_CTRL_BASE @ load SUN_TOP_CTRL PA
59+
ldr \rv, [\rp, #0] @ get register contents
60+
and \rv, \rv, #0xffffff00 @ strip revision bits [7:0]
61+
62+
/* Chip specific detection starts here */
63+
20: checkuart(\rp, \rv, 0x33900000, 3390)
64+
21: checkuart(\rp, \rv, 0x72500000, 7250)
65+
22: checkuart(\rp, \rv, 0x72680000, 7268)
66+
23: checkuart(\rp, \rv, 0x72710000, 7271)
67+
24: checkuart(\rp, \rv, 0x73640000, 7364)
68+
25: checkuart(\rp, \rv, 0x73660000, 7366)
69+
26: checkuart(\rp, \rv, 0x07437100, 74371)
70+
27: checkuart(\rp, \rv, 0x74390000, 7439)
71+
28: checkuart(\rp, \rv, 0x74450000, 7445)
72+
73+
/* No valid UART found */
74+
90: mov \rp, #0
75+
/* fall through */
76+
77+
/* Record whichever UART we chose */
78+
91: str \rp, [\tmp, #4] @ Store in brcmstb_uart_phys
79+
cmp \rp, #0 @ Valid UART address?
80+
bne 92f @ Yes, go process it
81+
str \rp, [\tmp, #8] @ Store 0 in brcmstb_uart_virt
82+
b 100f @ Done
83+
92: and \rv, \rp, #0xffffff @ offset within 16MB section
84+
add \rv, \rv, #REG_VIRT_BASE
85+
str \rv, [\tmp, #8] @ Store in brcmstb_uart_virt
86+
b 100f
87+
88+
.align
89+
99: .word .
90+
.word brcmstb_uart_config
91+
.ltorg
92+
93+
/* Load previously selected UART address */
94+
100: ldr \rp, [\tmp, #4] @ Load brcmstb_uart_phys
95+
ldr \rv, [\tmp, #8] @ Load brcmstb_uart_virt
96+
.endm
97+
98+
.macro store, rd, rx:vararg
99+
str \rd, \rx
100+
.endm
101+
102+
.macro load, rd, rx:vararg
103+
ldr \rd, \rx
104+
.endm
105+
106+
.macro senduart,rd,rx
107+
store \rd, [\rx, #UART_TX << UART_SHIFT]
108+
.endm
109+
110+
.macro busyuart,rd,rx
111+
1002: load \rd, [\rx, #UART_LSR << UART_SHIFT]
112+
and \rd, \rd, #UART_LSR_TEMT | UART_LSR_THRE
113+
teq \rd, #UART_LSR_TEMT | UART_LSR_THRE
114+
bne 1002b
115+
.endm
116+
117+
.macro waituart,rd,rx
118+
.endm
119+
120+
/*
121+
* Storage for the state maintained by the macros above.
122+
*
123+
* In the kernel proper, this data is located in arch/arm/mach-bcm/brcmstb.c.
124+
* That's because this header is included from multiple files, and we only
125+
* want a single copy of the data. In particular, the UART probing code above
126+
* assumes it's running using physical addresses. This is true when this file
127+
* is included from head.o, but not when included from debug.o. So we need
128+
* to share the probe results between the two copies, rather than having
129+
* to re-run the probing again later.
130+
*
131+
* In the decompressor, we put the symbol/storage right here, since common.c
132+
* isn't included in the decompressor build. This symbol gets put in .text
133+
* even though it's really data, since .data is discarded from the
134+
* decompressor. Luckily, .text is writeable in the decompressor, unless
135+
* CONFIG_ZBOOT_ROM. That dependency is handled in arch/arm/Kconfig.debug.
136+
*/
137+
#if defined(ZIMAGE)
138+
brcmstb_uart_config:
139+
/* Debug UART initialization required */
140+
.word 1
141+
/* Debug UART physical address */
142+
.word 0
143+
/* Debug UART virtual address */
144+
.word 0
145+
#endif

‎arch/arm/mach-bcm/brcmstb.c‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@
1919
#include <asm/mach-types.h>
2020
#include <asm/mach/arch.h>
2121

22+
/*
23+
* Storage for debug-macro.S's state.
24+
*
25+
* This must be in .data not .bss so that it gets initialized each time the
26+
* kernel is loaded. The data is declared here rather than debug-macro.S so
27+
* that multiple inclusions of debug-macro.S point at the same data.
28+
*/
29+
u32 brcmstb_uart_config[3] = {
30+
/* Debug UART initialization required */
31+
1,
32+
/* Debug UART physical address */
33+
0,
34+
/* Debug UART virtual address */
35+
0,
36+
};
37+
2238
static void __init brcmstb_init_irq(void)
2339
{
2440
irqchip_init();

0 commit comments

Comments
 (0)