Skip to content

Commit

Permalink
fix fsbl and opensbi serial ports print baud --form https://community…
Browse files Browse the repository at this point in the history
  • Loading branch information
yue-xiaomin committed Dec 24, 2023
1 parent ab1c239 commit 3dad3aa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
26 changes: 26 additions & 0 deletions fsbl/plat/cv180x/bl2/bl2_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,34 @@ int dec_verify_image(const void *image, size_t size, size_t dec_skip, struct fip
}
#endif

// Start of addition
#define UART_DLL 0x04140000
#define UART_DLH 0x04140004
#define UART_LCR 0x0414000C

void set_baudrate()
{
// 14 for 115200, 13 for 128000
int baud_divisor = 14;

// set DLAB to 1 to set dll and dlh
*(volatile uint32_t*)(UART_LCR) |= (uint32_t)0x80;

// set divisor
*(volatile uint32_t*)(UART_DLL) = (uint32_t)(baud_divisor & 0xff);
*(volatile uint32_t*)(UART_DLH) = (uint32_t)((baud_divisor >> 8) & 0xff);

// set DLAB back to 0
*(volatile uint32_t*)(UART_LCR) &= (uint32_t)(~0x80);
}
// End of addition

void bl2_main(void)
{
// Start of addition
set_baudrate();
// End of addition

ATF_STATE = ATF_STATE_BL2_MAIN;
time_records->fsbl_start = read_time_ms();

Expand Down
2 changes: 1 addition & 1 deletion opensbi/lib/utils/serial/uart8250.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int uart8250_init(unsigned long base, u32 in_freq, u32 baudrate, u32 reg_shift,
uart8250_in_freq = in_freq;
uart8250_baudrate = baudrate;

bdiv = uart8250_in_freq / (16 * uart8250_baudrate);
bdiv = (uart8250_in_freq + 8 * uart8250_baudrate) / (16 * uart8250_baudrate);

/* Disable all interrupts */
set_reg(UART_IER_OFFSET, 0x00);
Expand Down

0 comments on commit 3dad3aa

Please sign in to comment.