From 2cbcd2b7103f61a0a5b5f755aa92e3da8ec527f5 Mon Sep 17 00:00:00 2001 From: Kyösti Mälkki Date: Wed, 19 Feb 2014 08:58:12 +0200 Subject: ti/am335x: Fix baudrate calculation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit UART input clock is platform dependent. Also account for possible use of get_option() where baudrate is not compile-time constant. The hardware reference on BeagleBone is from a 48 MHz oscillator input. With pre-divisor of 16 we get same register values as in table 19-25. Change-Id: I89aee27c958f8618ce79a968ae7520a867e7e8a2 Signed-off-by: Kyösti Mälkki Reviewed-on: http://review.coreboot.org/5290 Tested-by: build bot (Jenkins) Reviewed-by: Stefan Reinauer --- src/cpu/ti/am335x/uart.c | 38 +++++++++++++++++--------------------- 1 file changed, 17 insertions(+), 21 deletions(-) (limited to 'src/cpu/ti/am335x') diff --git a/src/cpu/ti/am335x/uart.c b/src/cpu/ti/am335x/uart.c index bd2ff44044..719215ec8c 100644 --- a/src/cpu/ti/am335x/uart.c +++ b/src/cpu/ti/am335x/uart.c @@ -35,10 +35,10 @@ #define LSR_TXFIFOE (1 << 5) /* - * Initialise the serial port with the given baudrate. The settings + * Initialise the serial port with the given baudrate divisor. The settings * are always 8 data bits, no parity, 1 stop bit, no start bits. */ -static void am335x_uart_init_dev(void) +static void am335x_uart_init(uint16_t div) { struct am335x_uart *uart = (struct am335x_uart *) CONFIG_CONSOLE_SERIAL_UART_ADDRESS; @@ -107,24 +107,8 @@ static void am335x_uart_init_dev(void) write16(0xbf, &uart->lcr); /* 7. Set dll and dlh to the desired values (table 19-25) */ - if (CONFIG_CONSOLE_SERIAL_9600) { - write16(0x01, &uart->dlh); - write16(0x38, &uart->dll); - } else if (CONFIG_CONSOLE_SERIAL_19200) { - write16(0x00, &uart->dlh); - write16(0x9c, &uart->dll); - } else if (CONFIG_CONSOLE_SERIAL_38400) { - write16(0x00, &uart->dlh); - write16(0x4e, &uart->dll); - } else if (CONFIG_CONSOLE_SERIAL_57600) { - write16(0x00, &uart->dlh); - write16(0x34, &uart->dll); - } else if (CONFIG_CONSOLE_SERIAL_115200) { - write16(0x00, &uart->dlh); - write16(0x1a, &uart->dll); - } else { - /* Unrecognized baud rate? */ - } + write16((div >> 8), &uart->dlh); + write16((div & 0xff), &uart->dll); /* 8. Switch to operational mode to access ier */ write16(0x0, &uart->lcr); @@ -173,12 +157,24 @@ static void am335x_uart_tx_byte(unsigned char data) return write8(data, &uart->thr); } +unsigned int uart_platform_refclk(void) +{ + return 48000000; +} + +static void am335x_uart_init_dev(void) +{ + uint16_t div = (uint16_t) uart_baudrate_divisor( + default_baudrate(), uart_platform_refclk(), 16); + am335x_uart_init(div); +} + +#if !defined(__PRE_RAM__) uint32_t uartmem_getbaseaddr(void) { return CONFIG_CONSOLE_SERIAL_UART_ADDRESS; } -#if !defined(__PRE_RAM__) static const struct console_driver exynos5_uart_console __console = { .init = am335x_uart_init_dev, .tx_byte = am335x_uart_tx_byte, -- cgit v1.2.3