1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <device/mmio.h>
4 #include <boot/coreboot_tables.h>
5 #include <console/uart.h>
6 #include <drivers/uart/pl011.h>
8 void uart_init(unsigned int idx
)
10 struct pl011_uart
*regs
= uart_platform_baseptr(idx
);
17 tmp
= read32(®s
->cr
);
18 tmp
&= ~PL011_UARTCR_UARTEN
;
19 write32(®s
->cr
, tmp
);
23 * As per: PL011 Technical reference manual:
24 * BAUDDIV = (Fuartclk / (16 * baud_rate))
25 * Considering 6 bits(64) for UARTFBRD
26 * BAUDDIV = (Fuartclk * 4 / baud_rate)
28 tmp
= uart_platform_refclk() * 4 / get_uart_baudrate();
30 write32(®s
->ibrd
, tmp
>> 6);
31 write32(®s
->fbrd
, tmp
& 0x3f);
33 /* Program LINE Control 8n1, FIFO enable */
34 tmp
= read32(®s
->lcr_h
);
35 tmp
|= PL011_LINE_CONTROL
;
36 write32(®s
->lcr_h
, tmp
);
39 tmp
= read32(®s
->cr
);
40 tmp
|= PL011_UARTCR_UARTEN
| PL011_UARTCR_RXE
| PL011_UARTCR_TXE
;
41 write32(®s
->cr
, tmp
);
44 void uart_tx_byte(unsigned int idx
, unsigned char data
)
46 struct pl011_uart
*regs
= uart_platform_baseptr(idx
);
48 write8(®s
->dr
, data
);
52 void uart_tx_flush(unsigned int idx
)
54 struct pl011_uart
*regs
= uart_platform_baseptr(idx
);
56 /* FIXME: add a timeout */
57 while (!(read32(®s
->fr
) & PL011_UARTFR_TXFE
))
61 unsigned char uart_rx_byte(unsigned int idx
)
63 struct pl011_uart
*regs
= uart_platform_baseptr(idx
);
65 while (read32(®s
->fr
) & PL011_UARTFR_RXFE
)
67 return read8(®s
->dr
);
70 enum cb_err
fill_lb_serial(struct lb_serial
*serial
)
72 serial
->type
= LB_SERIAL_TYPE_MEMORY_MAPPED
;
73 serial
->baseaddr
= uart_platform_base(CONFIG_UART_FOR_CONSOLE
);
74 serial
->baud
= get_uart_baudrate();
76 serial
->input_hertz
= uart_platform_refclk();