coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
uart.c
Go to the documentation of this file.
1
/* SPDX-License-Identifier: GPL-2.0-only */
2
3
#include <
device/mmio.h
>
4
#include <
boot/coreboot_tables.h
>
5
#include <
console/uart.h
>
6
#include <
drivers/uart/uart8250reg.h
>
7
8
struct
tegra124_uart
{
9
union
{
10
uint32_t
thr
;
// Transmit holding register.
11
uint32_t
rbr
;
// Receive buffer register.
12
uint32_t
dll
;
// Divisor latch lsb.
13
};
14
union
{
15
uint32_t
ier
;
// Interrupt enable register.
16
uint32_t
dlm
;
// Divisor latch msb.
17
};
18
union
{
19
uint32_t
iir
;
// Interrupt identification register.
20
uint32_t
fcr
;
// FIFO control register.
21
};
22
uint32_t
lcr
;
// Line control register.
23
uint32_t
mcr
;
// Modem control register.
24
uint32_t
lsr
;
// Line status register.
25
uint32_t
msr
;
// Modem status register.
26
}
__packed
;
27
28
static
void
tegra124_uart_tx_flush
(
struct
tegra124_uart
*
uart_ptr
);
29
static
int
tegra124_uart_tst_byte
(
struct
tegra124_uart
*
uart_ptr
);
30
31
static
void
tegra124_uart_init
(
struct
tegra124_uart
*
uart_ptr
)
32
{
33
// Use a hardcoded divisor for now.
34
const
unsigned
int
divisor = 221;
35
const
uint8_t
line_config =
UART8250_LCR_WLS_8
;
// 8n1
36
37
tegra124_uart_tx_flush
(
uart_ptr
);
38
39
// Disable interrupts.
40
write8
(&
uart_ptr
->
ier
, 0);
41
// Force DTR and RTS to high.
42
write8
(&
uart_ptr
->
mcr
,
UART8250_MCR_DTR
|
UART8250_MCR_RTS
);
43
// Set line configuration, access divisor latches.
44
write8
(&
uart_ptr
->
lcr
,
UART8250_LCR_DLAB
| line_config);
45
// Set the divisor.
46
write8
(&
uart_ptr
->
dll
, divisor & 0xff);
47
write8
(&
uart_ptr
->
dlm
, (divisor >> 8) & 0xff);
48
// Hide the divisor latches.
49
write8
(&
uart_ptr
->
lcr
, line_config);
50
// Enable FIFOs, and clear receive and transmit.
51
write8
(&
uart_ptr
->
fcr
,
UART8250_FCR_FIFO_EN
|
52
UART8250_FCR_CLEAR_RCVR
|
UART8250_FCR_CLEAR_XMIT
);
53
}
54
55
static
unsigned
char
tegra124_uart_rx_byte
(
struct
tegra124_uart
*
uart_ptr
)
56
{
57
if
(!
tegra124_uart_tst_byte
(
uart_ptr
))
58
return
0;
59
return
read8
(&
uart_ptr
->
rbr
);
60
}
61
62
static
void
tegra124_uart_tx_byte
(
struct
tegra124_uart
*
uart_ptr
,
unsigned
char
data)
63
{
64
while
(!(
read8
(&
uart_ptr
->
lsr
) &
UART8250_LSR_THRE
));
65
write8
(&
uart_ptr
->
thr
, data);
66
}
67
68
static
void
tegra124_uart_tx_flush
(
struct
tegra124_uart
*
uart_ptr
)
69
{
70
while
(!(
read8
(&
uart_ptr
->
lsr
) &
UART8250_LSR_TEMT
));
71
}
72
73
static
int
tegra124_uart_tst_byte
(
struct
tegra124_uart
*
uart_ptr
)
74
{
75
return
(
read8
(&
uart_ptr
->
lsr
) &
UART8250_LSR_DR
) ==
UART8250_LSR_DR
;
76
}
77
78
uintptr_t
uart_platform_base
(
unsigned
int
idx)
79
{
80
//Default to UART A
81
unsigned
int
base
= 0x70006000;
82
//UARTs A - E are mapped as index 0 - 4
83
if
((idx < 5)) {
84
if
(idx != 1) {
//not UART B
85
base
+= idx * 0x100;
86
}
else
{
87
base
+= 0x40;
88
}
89
}
90
return
base
;
91
}
92
93
void
uart_init
(
unsigned
int
idx)
94
{
95
struct
tegra124_uart
*
uart_ptr
=
uart_platform_baseptr
(idx);
96
tegra124_uart_init
(
uart_ptr
);
97
}
98
99
unsigned
char
uart_rx_byte
(
unsigned
int
idx)
100
{
101
struct
tegra124_uart
*
uart_ptr
=
uart_platform_baseptr
(idx);
102
return
tegra124_uart_rx_byte
(
uart_ptr
);
103
}
104
105
void
uart_tx_byte
(
unsigned
int
idx,
unsigned
char
data)
106
{
107
struct
tegra124_uart
*
uart_ptr
=
uart_platform_baseptr
(idx);
108
tegra124_uart_tx_byte
(
uart_ptr
, data);
109
}
110
111
void
uart_tx_flush
(
unsigned
int
idx)
112
{
113
struct
tegra124_uart
*
uart_ptr
=
uart_platform_baseptr
(idx);
114
tegra124_uart_tx_flush
(
uart_ptr
);
115
}
116
117
void
uart_fill_lb
(
void
*data)
118
{
119
struct
lb_serial
serial
;
120
serial
.type =
LB_SERIAL_TYPE_MEMORY_MAPPED
;
121
serial
.baseaddr =
uart_platform_base
(CONFIG_UART_FOR_CONSOLE);
122
serial
.baud =
get_uart_baudrate
();
123
serial
.regwidth = 4;
124
serial
.input_hertz =
uart_platform_refclk
();
125
serial
.uart_pci_addr = CONFIG_UART_PCI_ADDR;
126
lb_add_serial
(&
serial
, data);
127
128
lb_add_console
(
LB_TAG_CONSOLE_SERIAL8250MEM
, data);
129
}
write8
static void write8(void *addr, uint8_t val)
Definition:
mmio.h:30
read8
static uint8_t read8(const void *addr)
Definition:
mmio.h:12
get_uart_baudrate
unsigned int get_uart_baudrate(void)
Definition:
bmcinfo.c:167
LB_TAG_CONSOLE_SERIAL8250MEM
#define LB_TAG_CONSOLE_SERIAL8250MEM
Definition:
coreboot_tables.h:213
LB_SERIAL_TYPE_MEMORY_MAPPED
#define LB_SERIAL_TYPE_MEMORY_MAPPED
Definition:
coreboot_tables.h:179
coreboot_tables.h
lb_add_console
void lb_add_console(uint16_t consoletype, void *data)
Definition:
coreboot_table.c:110
lb_add_serial
void lb_add_serial(struct lb_serial *serial, void *data)
Definition:
coreboot_table.c:94
uart.h
uart_platform_baseptr
static void * uart_platform_baseptr(unsigned int idx)
Definition:
uart.h:57
mmio.h
serial
unsigned int serial
Definition:
edid.c:52
uart_init
void uart_init(unsigned int idx)
Definition:
uart.c:13
uart_tx_flush
void uart_tx_flush(unsigned int idx)
Definition:
uart.c:27
uart_platform_base
uintptr_t uart_platform_base(unsigned int idx)
Definition:
uart.c:8
uart_rx_byte
unsigned char uart_rx_byte(unsigned int idx)
Definition:
uart.c:17
uart_fill_lb
void uart_fill_lb(void *data)
Definition:
uart.c:31
uart_tx_byte
void uart_tx_byte(unsigned int idx, unsigned char data)
Definition:
uart.c:22
base
uintptr_t base
Definition:
uart.c:17
uart_platform_refclk
unsigned int uart_platform_refclk(void)
Definition:
uart.c:85
__packed
struct mtk_uart __packed
uart_ptr
static struct mtk_uart *const uart_ptr
Definition:
uart.c:67
tegra124_uart_init
static void tegra124_uart_init(struct tegra124_uart *uart_ptr)
Definition:
uart.c:31
tegra124_uart_tx_flush
static void tegra124_uart_tx_flush(struct tegra124_uart *uart_ptr)
Definition:
uart.c:68
tegra124_uart_tst_byte
static int tegra124_uart_tst_byte(struct tegra124_uart *uart_ptr)
Definition:
uart.c:73
tegra124_uart_tx_byte
static void tegra124_uart_tx_byte(struct tegra124_uart *uart_ptr, unsigned char data)
Definition:
uart.c:62
tegra124_uart_rx_byte
static unsigned char tegra124_uart_rx_byte(struct tegra124_uart *uart_ptr)
Definition:
uart.c:55
uint32_t
unsigned int uint32_t
Definition:
stdint.h:14
uintptr_t
unsigned long uintptr_t
Definition:
stdint.h:21
uint8_t
unsigned char uint8_t
Definition:
stdint.h:8
lb_serial
Definition:
coreboot_tables.h:175
mtk_uart::mcr
uint32_t mcr
Definition:
uart.c:29
mtk_uart::thr
uint32_t thr
Definition:
uart.c:14
mtk_uart::ier
uint32_t ier
Definition:
uart.c:19
mtk_uart::dlm
uint32_t dlm
Definition:
uart.c:20
mtk_uart::lsr
uint32_t lsr
Definition:
uart.c:33
mtk_uart::rbr
uint32_t rbr
Definition:
uart.c:15
mtk_uart::dll
uint32_t dll
Definition:
uart.c:16
mtk_uart::lcr
uint32_t lcr
Definition:
uart.c:27
mtk_uart::fcr
uint32_t fcr
Definition:
uart.c:24
tegra124_uart
Definition:
uart.c:8
tegra124_uart::fcr
uint32_t fcr
Definition:
uart.c:20
tegra124_uart::dlm
uint32_t dlm
Definition:
uart.c:16
tegra124_uart::thr
uint32_t thr
Definition:
uart.c:10
tegra124_uart::mcr
uint32_t mcr
Definition:
uart.c:23
tegra124_uart::dll
uint32_t dll
Definition:
uart.c:12
tegra124_uart::rbr
uint32_t rbr
Definition:
uart.c:11
tegra124_uart::lsr
uint32_t lsr
Definition:
uart.c:24
tegra124_uart::lcr
uint32_t lcr
Definition:
uart.c:22
tegra124_uart::iir
uint32_t iir
Definition:
uart.c:19
tegra124_uart::ier
uint32_t ier
Definition:
uart.c:15
tegra124_uart::msr
uint32_t msr
Definition:
uart.c:25
uart8250reg.h
UART8250_LCR_WLS_8
#define UART8250_LCR_WLS_8
Definition:
uart8250reg.h:44
UART8250_LCR_DLAB
#define UART8250_LCR_DLAB
Definition:
uart8250reg.h:50
UART8250_LSR_DR
#define UART8250_LSR_DR
Definition:
uart8250reg.h:67
UART8250_FCR_CLEAR_RCVR
#define UART8250_FCR_CLEAR_RCVR
Definition:
uart8250reg.h:30
UART8250_FCR_CLEAR_XMIT
#define UART8250_FCR_CLEAR_XMIT
Definition:
uart8250reg.h:31
UART8250_LSR_TEMT
#define UART8250_LSR_TEMT
Definition:
uart8250reg.h:73
UART8250_MCR_DTR
#define UART8250_MCR_DTR
Definition:
uart8250reg.h:53
UART8250_FCR_FIFO_EN
#define UART8250_FCR_FIFO_EN
Definition:
uart8250reg.h:29
UART8250_MCR_RTS
#define UART8250_MCR_RTS
Definition:
uart8250reg.h:54
UART8250_LSR_THRE
#define UART8250_LSR_THRE
Definition:
uart8250reg.h:72
src
soc
nvidia
tegra124
uart.c
Generated by
1.9.1