drivers/uart/sifive.c: Fix divisor calculation

The divisor is calculated using the following formula:
div = (frequency / baudrate) - 1;

The current implementation however essentially calculates:
div = (frequency / baudrate);

Signed-off-by: Maximilian Brune <maximilian.brune@9elements.com>
Change-Id: I8a0898ce9016a70c0f91dc8a99fc1cf9e46d20c4
Reviewed-on: https://review.coreboot.org/c/coreboot/+/79951
Reviewed-by: ron minnich <rminnich@gmail.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Menzel <paulepanter@mailbox.org>
This commit is contained in:
Maximilian Brune 2024-01-14 20:06:10 +06:00 committed by Lean Sheng Tan
parent 2d26e9bdce
commit a2eca49d83
1 changed files with 10 additions and 3 deletions

View File

@ -47,9 +47,16 @@ static void sifive_uart_init(struct sifive_uart_registers *regs, int div)
void uart_init(unsigned int idx)
{
unsigned int div;
div = uart_baudrate_divisor(get_uart_baudrate(),
uart_platform_refclk(), uart_input_clock_divider());
/*
* according to FU540/FU740 manual:
* f_baud = f_in / (div + 1)
* <=>
* div = (f_in / f_baud) - 1
*/
unsigned int div = uart_baudrate_divisor(get_uart_baudrate(), uart_platform_refclk(),
uart_input_clock_divider());
div -= 1;
sifive_uart_init(uart_platform_baseptr(idx), div);
}