commit 885b6b8340f34778237edaad965cf63006483be5
parent 3edfbe4c9e9a02c343af87adbe9dfcba76a0afee
Author: Dimitris Papastamos <dimitris.papastamos@arm.com>
Date: Tue, 16 Oct 2018 17:25:37 +0100
[uart] Pass the CLK/BAUD rate and base address externally
Switch to uart3 as the other UARTs are being used by TF/TFTF.
Change-Id: I14eaa6116047dad2c55941f4fc6ca778c1dd8b6a
Signed-off-by: Dimitris Papastamos <dimitris.papastamos@arm.com>
Diffstat:
5 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/arch/arm64/Makefile b/arch/arm64/Makefile
@@ -1,6 +1,10 @@
PROJECTDIR = ../..
include $(PROJECTDIR)/scripts/rules.mk
+MORECFLAGS = -DUARTBASE=0x1c0c0000 \
+ -DUARTCLK=24000000 \
+ -DUARTBAUDRATE=115200 \
+
ROMOBJS = rom-crt-$(SYS).o \
rom-$(SYS).o panic.o \
arch.o \
diff --git a/arch/arm64/rom-none.c b/arch/arm64/rom-none.c
@@ -22,7 +22,6 @@ main(void *text, void *ram, size_t ramsiz)
fp = (struct trapframe *) (bp + bsssiz);
fp += NR_NESTED - 1;
wr_sp_r(fp);
- uartinit(115200);
enaabt();
isb();
@@ -30,6 +29,9 @@ main(void *text, void *ram, size_t ramsiz)
memset(fp, 0, sizeof(*fp));
bss->text = text;
+ bss->uartbase = (void *)UARTBASE;
+
+ uartinit(UARTCLK, UARTBAUDRATE);
fp->sp = bp + (ramsiz - 16);
fp->elr = rd_rvbar_el3();
diff --git a/drivers/uart.c b/drivers/uart.c
@@ -1,9 +1,6 @@
#include <uart.h>
#include <rcode.h>
-#define BASE 0x1c090000
-#define CLK 24000000
-
#define CR 0x30
#define FBRD 0x28
#define IBRD 0x24
@@ -25,12 +22,12 @@
#define FR_RXFE (1 << 4)
static void
-setbaudrate(int baudrate)
+setbaudrate(unsigned clk, unsigned baudrate)
{
- char *base = (char *)BASE;
+ char *base = bss->uartbase;
unsigned int div;
- div = (CLK * 4) / baudrate;
+ div = (clk * 4) / baudrate;
outm32(div >> 6, base + IBRD);
outm32(div & 0x3f, base + FBRD);
}
@@ -38,7 +35,7 @@ setbaudrate(int baudrate)
static void
flush(void)
{
- char *base = (char *)BASE;
+ char *base = bss->uartbase;
while ((inm32(base + CR) & CR_EN) &&
(inm32(base + FR) & FR_TXFE))
@@ -53,13 +50,13 @@ ansisetmode(void)
}
void
-uartinit(int baudrate)
+uartinit(unsigned clk, unsigned baudrate)
{
- char *base = (char *)BASE;
+ char *base = bss->uartbase;
outm32(0, base + RSR_ECR);
outm32(0, base + CR);
- setbaudrate(baudrate);
+ setbaudrate(clk, baudrate);
outm32(LCRH_WLEN_8 | LCRH_FEN, base + LCRH);
outm32(CR_EN | CR_TXE | CR_RXE, base + CR);
ansisetmode();
@@ -69,7 +66,7 @@ uartinit(int baudrate)
int
uartgetc(void)
{
- char *base = (char *)BASE;
+ char *base = bss->uartbase;
while (inm32(base + FR) & FR_RXFE)
;
@@ -79,7 +76,7 @@ uartgetc(void)
int
uartputc(int c)
{
- char *base = (char *)BASE;
+ char *base = bss->uartbase;
while (inm32(base + FR) & FR_TXFF)
;
diff --git a/include/rcode.h b/include/rcode.h
@@ -15,6 +15,7 @@ typedef struct rmucmd Rmucmd;
struct bssmap {
char in_panic;
void *text;
+ void *uartbase;
};
struct rowidx {
diff --git a/include/uart.h b/include/uart.h
@@ -1,6 +1,6 @@
#include <stddef.h>
-extern void uartinit(int baudrate);
+extern void uartinit(unsigned clkrate, unsigned baudrate);
extern int uartgetc(void);
extern int uartputc(int c);
extern void uartwrite(const char *buf, size_t siz);