diff options
author | Maximilian Brune <maximilian.brune@9elements.com> | 2024-01-14 20:06:10 +0600 |
---|---|---|
committer | Lean Sheng Tan <sheng.tan@9elements.com> | 2024-02-10 17:29:45 +0000 |
commit | a2eca49d837880dbdb8f07c7022fc740def4e4e4 (patch) | |
tree | 7810e742f8859d4b20c3075b9c7ba47e49d044bd | |
parent | 2d26e9bdce01a23eabf843c3d0d029fcab686e7f (diff) |
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>
-rw-r--r-- | src/drivers/uart/sifive.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/drivers/uart/sifive.c b/src/drivers/uart/sifive.c index d1b89dc745..815a0cfb05 100644 --- a/src/drivers/uart/sifive.c +++ b/src/drivers/uart/sifive.c @@ -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); } |