Kyösti Mälkki (kyosti.malkki(a)gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/5236
-gerrit
commit 933ebdab4f53d4599943d357f08b0d6ffc7da8c5
Author: Kyösti Mälkki <kyosti.malkki(a)gmail.com>
Date: Thu Jan 30 15:45:16 2014 +0200
uart8250: Move under drivers/uart
Change-Id: Ic65ffaaa092330ed68d891e4a09a8b86cdc04a3a
Signed-off-by: Kyösti Mälkki <kyosti.malkki(a)gmail.com>
---
src/arch/x86/lib/romcc_console.c | 2 +-
src/cpu/allwinner/a10/uart.c | 2 +-
src/drivers/uart/Makefile.inc | 12 ++++
src/drivers/uart/uart8250io.c | 127 +++++++++++++++++++++++++++++++++++++
src/drivers/uart/uart8250mem.c | 134 +++++++++++++++++++++++++++++++++++++++
src/drivers/uart/uart8250reg.h | 108 +++++++++++++++++++++++++++++++
src/include/uart8250.h | 108 -------------------------------
src/lib/Makefile.inc | 6 --
src/lib/uart8250.c | 127 -------------------------------------
src/lib/uart8250mem.c | 134 ---------------------------------------
10 files changed, 383 insertions(+), 377 deletions(-)
diff --git a/src/arch/x86/lib/romcc_console.c b/src/arch/x86/lib/romcc_console.c
index 1ed498a..66c81db 100644
--- a/src/arch/x86/lib/romcc_console.c
+++ b/src/arch/x86/lib/romcc_console.c
@@ -32,7 +32,7 @@
#if CONFIG_CONSOLE_SERIAL8250
#include "drivers/uart/util.c"
-#include "lib/uart8250.c"
+#include "drivers/uart/uart8250io.c"
#endif
#if CONFIG_CONSOLE_NE2K
#include "drivers/net/ne2k.c"
diff --git a/src/cpu/allwinner/a10/uart.c b/src/cpu/allwinner/a10/uart.c
index 97ac302..7dad1ca 100644
--- a/src/cpu/allwinner/a10/uart.c
+++ b/src/cpu/allwinner/a10/uart.c
@@ -7,7 +7,7 @@
#include "uart.h"
#include <arch/io.h>
-#include <uart8250.h>
+#include <drivers/uart/uart8250reg.h>
/**
* \brief Configure line control settings for UART
diff --git a/src/drivers/uart/Makefile.inc b/src/drivers/uart/Makefile.inc
index 52a7024..3a9ca3d 100644
--- a/src/drivers/uart/Makefile.inc
+++ b/src/drivers/uart/Makefile.inc
@@ -5,6 +5,18 @@ bootblock-y += util.c
smm-y += util.c
endif
+ifeq ($(CONFIG_CONSOLE_SERIAL8250),y)
+romstage-y += uart8250io.c
+ramstage-y += uart8250io.c
+smm-y += uart8250io.c
+endif
+
+ifeq ($(CONFIG_CONSOLE_SERIAL8250MEM),y)
+romstage-y += uart8250mem.c
+ramstage-y += uart8250mem.c
+smm-y += uart8250mem.c
+endif
+
ifeq ($(CONFIG_CONSOLE_SERIAL_UART),y)
ifeq ($(CONFIG_DRIVERS_UART_PL011),y)
diff --git a/src/drivers/uart/uart8250io.c b/src/drivers/uart/uart8250io.c
new file mode 100644
index 0000000..6c08ce2
--- /dev/null
+++ b/src/drivers/uart/uart8250io.c
@@ -0,0 +1,127 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2003 Eric Biederman
+ * Copyright (C) 2006-2010 coresystems GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <arch/io.h>
+#include <console/uart.h>
+#include <trace.h>
+#include "uart8250reg.h"
+
+/* Should support 8250, 16450, 16550, 16550A type UARTs */
+
+/* No reports of super-IOs that would use different clock for
+ * baudrate reference. */
+#define BAUDRATE_REFCLK 115200
+
+/* Expected character delay at 1200bps is 9ms for a working UART
+ * and no flow-control. Assume UART as stuck if shift register
+ * or FIFO takes more than 50ms per character to appear empty.
+ *
+ * Estimated that inb() from UART takes 1 microsecond.
+ */
+#define SINGLE_CHAR_TIMEOUT (50 * 1000)
+#define FIFO_TIMEOUT (16 * SINGLE_CHAR_TIMEOUT)
+
+static int uart8250_can_tx_byte(unsigned base_port)
+{
+ return inb(base_port + UART_LSR) & UART_LSR_THRE;
+}
+
+static void uart8250_tx_byte(unsigned base_port, unsigned char data)
+{
+ unsigned long int i = SINGLE_CHAR_TIMEOUT;
+ while (i-- && !uart8250_can_tx_byte(base_port));
+ outb(data, base_port + UART_TBR);
+}
+
+static void uart8250_tx_flush(unsigned base_port)
+{
+ unsigned long int i = FIFO_TIMEOUT;
+ while (i-- && !(inb(base_port + UART_LSR) & UART_LSR_TEMT));
+}
+
+static int uart8250_can_rx_byte(unsigned base_port)
+{
+ return inb(base_port + UART_LSR) & UART_LSR_DR;
+}
+
+static unsigned char uart8250_rx_byte(unsigned base_port)
+{
+ unsigned long int i = SINGLE_CHAR_TIMEOUT;
+ while (i-- && !uart8250_can_rx_byte(base_port));
+
+ if (i)
+ return inb(base_port + UART_RBR);
+ else
+ return 0x0;
+}
+
+static void uart8250_init(unsigned base_port, unsigned divisor)
+{
+ DISABLE_TRACE;
+ /* Disable interrupts */
+ outb(0x0, base_port + UART_IER);
+ /* Enable FIFOs */
+ outb(UART_FCR_FIFO_EN, base_port + UART_FCR);
+
+ /* assert DTR and RTS so the other end is happy */
+ outb(UART_MCR_DTR | UART_MCR_RTS, base_port + UART_MCR);
+
+ /* DLAB on */
+ outb(UART_LCR_DLAB | CONFIG_TTYS0_LCS, base_port + UART_LCR);
+
+ /* Set Baud Rate Divisor. 12 ==> 9600 Baud */
+ outb(divisor & 0xFF, base_port + UART_DLL);
+ outb((divisor >> 8) & 0xFF, base_port + UART_DLM);
+
+ /* Set to 3 for 8N1 */
+ outb(CONFIG_TTYS0_LCS, base_port + UART_LCR);
+ ENABLE_TRACE;
+}
+
+/* FIXME: Needs uart index from Kconfig.
+ * Already use array as a work-around for ROMCC.
+ */
+static const unsigned bases[1] = { CONFIG_TTYS0_BASE };
+
+void uart_init(void)
+{
+ unsigned int div = uart_baudrate_divisor(BAUDRATE_REFCLK);
+ uart8250_init(bases[0], div);
+}
+
+void uart_tx_byte(unsigned char data)
+{
+ uart8250_tx_byte(bases[0], data);
+}
+
+unsigned char uart_rx_byte(void)
+{
+ return uart8250_rx_byte(bases[0]);
+}
+
+int uart_can_rx_byte(void)
+{
+ return uart8250_can_rx_byte(bases[0]);
+}
+
+void uart_tx_flush(void)
+{
+ uart8250_tx_flush(bases[0]);
+}
diff --git a/src/drivers/uart/uart8250mem.c b/src/drivers/uart/uart8250mem.c
new file mode 100644
index 0000000..dded007
--- /dev/null
+++ b/src/drivers/uart/uart8250mem.c
@@ -0,0 +1,134 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2003 Eric Biederman
+ * Copyright (C) 2006-2010 coresystems GmbH
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <arch/io.h>
+#include <console/uart.h>
+#include <device/device.h>
+#include <delay.h>
+#include "uart8250reg.h"
+
+/* Should support 8250, 16450, 16550, 16550A type UARTs */
+
+/* Expected character delay at 1200bps is 9ms for a working UART
+ * and no flow-control. Assume UART as stuck if shift register
+ * or FIFO takes more than 50ms per character to appear empty.
+ */
+#define SINGLE_CHAR_TIMEOUT (50 * 1000)
+#define FIFO_TIMEOUT (16 * SINGLE_CHAR_TIMEOUT)
+
+static int uart8250_mem_can_tx_byte(unsigned base_port)
+{
+ return read8(base_port + UART_LSR) & UART_LSR_THRE;
+}
+
+static void uart8250_mem_tx_byte(unsigned base_port, unsigned char data)
+{
+ unsigned long int i = SINGLE_CHAR_TIMEOUT;
+ while(i-- && !uart8250_mem_can_tx_byte(base_port))
+ udelay(1);
+ write8(base_port + UART_TBR, data);
+}
+
+static void uart8250_mem_tx_flush(unsigned base_port)
+{
+ unsigned long int i = FIFO_TIMEOUT;
+ while(i-- && !(read8(base_port + UART_LSR) & UART_LSR_TEMT))
+ udelay(1);
+}
+
+static int uart8250_mem_can_rx_byte(unsigned base_port)
+{
+ return read8(base_port + UART_LSR) & UART_LSR_DR;
+}
+
+static unsigned char uart8250_mem_rx_byte(unsigned base_port)
+{
+ unsigned long int i = SINGLE_CHAR_TIMEOUT;
+ while(i-- && !uart8250_mem_can_rx_byte(base_port))
+ udelay(1);
+ if (i)
+ return read8(base_port + UART_RBR);
+ else
+ return 0x0;
+}
+
+static void uart8250_mem_init(unsigned base_port, unsigned divisor)
+{
+ /* Disable interrupts */
+ write8(base_port + UART_IER, 0x0);
+ /* Enable FIFOs */
+ write8(base_port + UART_FCR, UART_FCR_FIFO_EN);
+
+ /* Assert DTR and RTS so the other end is happy */
+ write8(base_port + UART_MCR, UART_MCR_DTR | UART_MCR_RTS);
+
+ /* DLAB on */
+ write8(base_port + UART_LCR, UART_LCR_DLAB | CONFIG_TTYS0_LCS);
+
+ /* Set Baud Rate Divisor. 12 ==> 9600 Baud */
+ write8(base_port + UART_DLL, divisor & 0xFF);
+ write8(base_port + UART_DLM, (divisor >> 8) & 0xFF);
+
+ /* Set to 3 for 8N1 */
+ write8(base_port + UART_LCR, CONFIG_TTYS0_LCS);
+}
+
+void uart_init(void)
+{
+ u32 base = uart_platform_base(0);
+ if (!base)
+ return;
+
+ unsigned int refclk = uart_platform_refclk();
+ unsigned int div = uart_baudrate_divisor(refclk);
+ uart8250_mem_init(base, div);
+}
+
+void uart_tx_byte(unsigned char data)
+{
+ u32 base = uart_platform_base(0);
+ if (!base)
+ return;
+ uart8250_mem_tx_byte(base, data);
+}
+
+unsigned char uart_rx_byte(void)
+{
+ u32 base = uart_platform_base(0);
+ if (!base)
+ return 0xff;
+ return uart8250_mem_rx_byte(base);
+}
+
+int uart_can_rx_byte(void)
+{
+ u32 base = uart_platform_base(0);
+ if (!base)
+ return 0;
+ return uart8250_mem_can_rx_byte(base);
+}
+
+void uart_tx_flush(void)
+{
+ u32 base = uart_platform_base(0);
+ if (!base)
+ return;
+ uart8250_mem_tx_flush(base);
+}
diff --git a/src/drivers/uart/uart8250reg.h b/src/drivers/uart/uart8250reg.h
new file mode 100644
index 0000000..cdfbb1b
--- /dev/null
+++ b/src/drivers/uart/uart8250reg.h
@@ -0,0 +1,108 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2003 Eric Biederman
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef UART8250REG_H
+#define UART8250REG_H
+
+/* Data */
+#define UART_RBR 0x00
+#define UART_TBR 0x00
+
+/* Control */
+#define UART_IER 0x01
+#define UART_IER_MSI 0x08 /* Enable Modem status interrupt */
+#define UART_IER_RLSI 0x04 /* Enable receiver line status interrupt */
+#define UART_IER_THRI 0x02 /* Enable Transmitter holding register int. */
+#define UART_IER_RDI 0x01 /* Enable receiver data interrupt */
+
+#define UART_IIR 0x02
+#define UART_IIR_NO_INT 0x01 /* No interrupts pending */
+#define UART_IIR_ID 0x06 /* Mask for the interrupt ID */
+
+#define UART_IIR_MSI 0x00 /* Modem status interrupt */
+#define UART_IIR_THRI 0x02 /* Transmitter holding register empty */
+#define UART_IIR_RDI 0x04 /* Receiver data interrupt */
+#define UART_IIR_RLSI 0x06 /* Receiver line status interrupt */
+
+#define UART_FCR 0x02
+#define UART_FCR_FIFO_EN 0x01 /* Fifo enable */
+#define UART_FCR_CLEAR_RCVR 0x02 /* Clear the RCVR FIFO */
+#define UART_FCR_CLEAR_XMIT 0x04 /* Clear the XMIT FIFO */
+#define UART_FCR_DMA_SELECT 0x08 /* For DMA applications */
+#define UART_FCR_TRIGGER_MASK 0xC0 /* Mask for the FIFO trigger range */
+#define UART_FCR_TRIGGER_1 0x00 /* Mask for trigger set at 1 */
+#define UART_FCR_TRIGGER_4 0x40 /* Mask for trigger set at 4 */
+#define UART_FCR_TRIGGER_8 0x80 /* Mask for trigger set at 8 */
+#define UART_FCR_TRIGGER_14 0xC0 /* Mask for trigger set at 14 */
+
+#define UART_FCR_RXSR 0x02 /* Receiver soft reset */
+#define UART_FCR_TXSR 0x04 /* Transmitter soft reset */
+
+#define UART_LCR 0x03
+#define UART_LCR_WLS_MSK 0x03 /* character length select mask */
+#define UART_LCR_WLS_5 0x00 /* 5 bit character length */
+#define UART_LCR_WLS_6 0x01 /* 6 bit character length */
+#define UART_LCR_WLS_7 0x02 /* 7 bit character length */
+#define UART_LCR_WLS_8 0x03 /* 8 bit character length */
+#define UART_LCR_STB 0x04 /* Number of stop Bits, off = 1, on = 1.5 or 2) */
+#define UART_LCR_PEN 0x08 /* Parity enable */
+#define UART_LCR_EPS 0x10 /* Even Parity Select */
+#define UART_LCR_STKP 0x20 /* Stick Parity */
+#define UART_LCR_SBRK 0x40 /* Set Break */
+#define UART_LCR_BKSE 0x80 /* Bank select enable */
+#define UART_LCR_DLAB 0x80 /* Divisor latch access bit */
+
+#define UART_MCR 0x04
+#define UART_MCR_DTR 0x01 /* DTR */
+#define UART_MCR_RTS 0x02 /* RTS */
+#define UART_MCR_OUT1 0x04 /* Out 1 */
+#define UART_MCR_OUT2 0x08 /* Out 2 */
+#define UART_MCR_LOOP 0x10 /* Enable loopback test mode */
+
+#define UART_MCR_DMA_EN 0x04
+#define UART_MCR_TX_DFR 0x08
+
+#define UART_DLL 0x00
+#define UART_DLM 0x01
+
+/* Status */
+#define UART_LSR 0x05
+#define UART_LSR_DR 0x01 /* Data ready */
+#define UART_LSR_OE 0x02 /* Overrun */
+#define UART_LSR_PE 0x04 /* Parity error */
+#define UART_LSR_FE 0x08 /* Framing error */
+#define UART_LSR_BI 0x10 /* Break */
+#define UART_LSR_THRE 0x20 /* Xmit holding register empty */
+#define UART_LSR_TEMT 0x40 /* Xmitter empty */
+#define UART_LSR_ERR 0x80 /* Error */
+
+#define UART_MSR 0x06
+#define UART_MSR_DCD 0x80 /* Data Carrier Detect */
+#define UART_MSR_RI 0x40 /* Ring Indicator */
+#define UART_MSR_DSR 0x20 /* Data Set Ready */
+#define UART_MSR_CTS 0x10 /* Clear to Send */
+#define UART_MSR_DDCD 0x08 /* Delta DCD */
+#define UART_MSR_TERI 0x04 /* Trailing edge ring indicator */
+#define UART_MSR_DDSR 0x02 /* Delta DSR */
+#define UART_MSR_DCTS 0x01 /* Delta CTS */
+
+#define UART_SCR 0x07
+#define UART_SPR 0x07
+
+#endif /* UART8250REG_H */
diff --git a/src/include/uart8250.h b/src/include/uart8250.h
deleted file mode 100644
index c63153c..0000000
--- a/src/include/uart8250.h
+++ /dev/null
@@ -1,108 +0,0 @@
-/*
- * This file is part of the coreboot project.
- *
- * Copyright (C) 2003 Eric Biederman
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#ifndef UART8250_H
-#define UART8250_H
-
-/* Data */
-#define UART_RBR 0x00
-#define UART_TBR 0x00
-
-/* Control */
-#define UART_IER 0x01
-#define UART_IER_MSI 0x08 /* Enable Modem status interrupt */
-#define UART_IER_RLSI 0x04 /* Enable receiver line status interrupt */
-#define UART_IER_THRI 0x02 /* Enable Transmitter holding register int. */
-#define UART_IER_RDI 0x01 /* Enable receiver data interrupt */
-
-#define UART_IIR 0x02
-#define UART_IIR_NO_INT 0x01 /* No interrupts pending */
-#define UART_IIR_ID 0x06 /* Mask for the interrupt ID */
-
-#define UART_IIR_MSI 0x00 /* Modem status interrupt */
-#define UART_IIR_THRI 0x02 /* Transmitter holding register empty */
-#define UART_IIR_RDI 0x04 /* Receiver data interrupt */
-#define UART_IIR_RLSI 0x06 /* Receiver line status interrupt */
-
-#define UART_FCR 0x02
-#define UART_FCR_FIFO_EN 0x01 /* Fifo enable */
-#define UART_FCR_CLEAR_RCVR 0x02 /* Clear the RCVR FIFO */
-#define UART_FCR_CLEAR_XMIT 0x04 /* Clear the XMIT FIFO */
-#define UART_FCR_DMA_SELECT 0x08 /* For DMA applications */
-#define UART_FCR_TRIGGER_MASK 0xC0 /* Mask for the FIFO trigger range */
-#define UART_FCR_TRIGGER_1 0x00 /* Mask for trigger set at 1 */
-#define UART_FCR_TRIGGER_4 0x40 /* Mask for trigger set at 4 */
-#define UART_FCR_TRIGGER_8 0x80 /* Mask for trigger set at 8 */
-#define UART_FCR_TRIGGER_14 0xC0 /* Mask for trigger set at 14 */
-
-#define UART_FCR_RXSR 0x02 /* Receiver soft reset */
-#define UART_FCR_TXSR 0x04 /* Transmitter soft reset */
-
-#define UART_LCR 0x03
-#define UART_LCR_WLS_MSK 0x03 /* character length select mask */
-#define UART_LCR_WLS_5 0x00 /* 5 bit character length */
-#define UART_LCR_WLS_6 0x01 /* 6 bit character length */
-#define UART_LCR_WLS_7 0x02 /* 7 bit character length */
-#define UART_LCR_WLS_8 0x03 /* 8 bit character length */
-#define UART_LCR_STB 0x04 /* Number of stop Bits, off = 1, on = 1.5 or 2) */
-#define UART_LCR_PEN 0x08 /* Parity enable */
-#define UART_LCR_EPS 0x10 /* Even Parity Select */
-#define UART_LCR_STKP 0x20 /* Stick Parity */
-#define UART_LCR_SBRK 0x40 /* Set Break */
-#define UART_LCR_BKSE 0x80 /* Bank select enable */
-#define UART_LCR_DLAB 0x80 /* Divisor latch access bit */
-
-#define UART_MCR 0x04
-#define UART_MCR_DTR 0x01 /* DTR */
-#define UART_MCR_RTS 0x02 /* RTS */
-#define UART_MCR_OUT1 0x04 /* Out 1 */
-#define UART_MCR_OUT2 0x08 /* Out 2 */
-#define UART_MCR_LOOP 0x10 /* Enable loopback test mode */
-
-#define UART_MCR_DMA_EN 0x04
-#define UART_MCR_TX_DFR 0x08
-
-#define UART_DLL 0x00
-#define UART_DLM 0x01
-
-/* Status */
-#define UART_LSR 0x05
-#define UART_LSR_DR 0x01 /* Data ready */
-#define UART_LSR_OE 0x02 /* Overrun */
-#define UART_LSR_PE 0x04 /* Parity error */
-#define UART_LSR_FE 0x08 /* Framing error */
-#define UART_LSR_BI 0x10 /* Break */
-#define UART_LSR_THRE 0x20 /* Xmit holding register empty */
-#define UART_LSR_TEMT 0x40 /* Xmitter empty */
-#define UART_LSR_ERR 0x80 /* Error */
-
-#define UART_MSR 0x06
-#define UART_MSR_DCD 0x80 /* Data Carrier Detect */
-#define UART_MSR_RI 0x40 /* Ring Indicator */
-#define UART_MSR_DSR 0x20 /* Data Set Ready */
-#define UART_MSR_CTS 0x10 /* Clear to Send */
-#define UART_MSR_DDCD 0x08 /* Delta DCD */
-#define UART_MSR_TERI 0x04 /* Trailing edge ring indicator */
-#define UART_MSR_DDSR 0x02 /* Delta DSR */
-#define UART_MSR_DCTS 0x01 /* Delta CTS */
-
-#define UART_SCR 0x07
-#define UART_SPR 0x07
-
-#endif /* UART8250_H */
diff --git a/src/lib/Makefile.inc b/src/lib/Makefile.inc
index 5c37329..6641318 100644
--- a/src/lib/Makefile.inc
+++ b/src/lib/Makefile.inc
@@ -46,8 +46,6 @@ romstage-y += cbfs.c
romstage-$(CONFIG_COMPRESS_RAMSTAGE) += lzma.c
#romstage-y += lzmadecode.c
romstage-$(CONFIG_CACHE_AS_RAM) += ramtest.c
-romstage-$(CONFIG_CONSOLE_SERIAL8250) += uart8250.c
-romstage-$(CONFIG_CONSOLE_SERIAL8250MEM) += uart8250mem.c
ifeq ($(CONFIG_EARLY_CBMEM_INIT),y)
romstage-$(CONFIG_COLLECT_TIMESTAMPS) += timestamp.c
@@ -87,8 +85,6 @@ ramstage-y += stack.c
ramstage-$(CONFIG_ARCH_X86) += gcc.c
ramstage-y += clog2.c
romstage-y += clog2.c
-ramstage-$(CONFIG_CONSOLE_SERIAL8250) += uart8250.c
-ramstage-$(CONFIG_CONSOLE_SERIAL8250MEM) += uart8250mem.c
ramstage-$(CONFIG_CONSOLE_CBMEM) += cbmem_console.c
ramstage-$(CONFIG_BOOTSPLASH) += jpeg.c
ramstage-$(CONFIG_TRACE) += trace.c
@@ -125,8 +121,6 @@ ifneq ($(CONFIG_HAVE_ARCH_MEMMOVE),y)
smm-y += memmove.c
endif
smm-y += cbfs.c memcmp.c
-smm-$(CONFIG_CONSOLE_SERIAL8250) += uart8250.c
-smm-$(CONFIG_CONSOLE_SERIAL8250MEM) += uart8250mem.c
smm-y += gcc.c
$(obj)/lib/version.ramstage.o : $(obj)/build.h
diff --git a/src/lib/uart8250.c b/src/lib/uart8250.c
deleted file mode 100644
index d5e845c..0000000
--- a/src/lib/uart8250.c
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * This file is part of the coreboot project.
- *
- * Copyright (C) 2003 Eric Biederman
- * Copyright (C) 2006-2010 coresystems GmbH
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <arch/io.h>
-#include <console/uart.h>
-#include <uart8250.h>
-#include <trace.h>
-
-/* Should support 8250, 16450, 16550, 16550A type UARTs */
-
-/* No reports of super-IOs that would use different clock for
- * baudrate reference. */
-#define BAUDRATE_REFCLK 115200
-
-/* Expected character delay at 1200bps is 9ms for a working UART
- * and no flow-control. Assume UART as stuck if shift register
- * or FIFO takes more than 50ms per character to appear empty.
- *
- * Estimated that inb() from UART takes 1 microsecond.
- */
-#define SINGLE_CHAR_TIMEOUT (50 * 1000)
-#define FIFO_TIMEOUT (16 * SINGLE_CHAR_TIMEOUT)
-
-static int uart8250_can_tx_byte(unsigned base_port)
-{
- return inb(base_port + UART_LSR) & UART_LSR_THRE;
-}
-
-static void uart8250_tx_byte(unsigned base_port, unsigned char data)
-{
- unsigned long int i = SINGLE_CHAR_TIMEOUT;
- while (i-- && !uart8250_can_tx_byte(base_port));
- outb(data, base_port + UART_TBR);
-}
-
-static void uart8250_tx_flush(unsigned base_port)
-{
- unsigned long int i = FIFO_TIMEOUT;
- while (i-- && !(inb(base_port + UART_LSR) & UART_LSR_TEMT));
-}
-
-static int uart8250_can_rx_byte(unsigned base_port)
-{
- return inb(base_port + UART_LSR) & UART_LSR_DR;
-}
-
-static unsigned char uart8250_rx_byte(unsigned base_port)
-{
- unsigned long int i = SINGLE_CHAR_TIMEOUT;
- while (i-- && !uart8250_can_rx_byte(base_port));
-
- if (i)
- return inb(base_port + UART_RBR);
- else
- return 0x0;
-}
-
-static void uart8250_init(unsigned base_port, unsigned divisor)
-{
- DISABLE_TRACE;
- /* Disable interrupts */
- outb(0x0, base_port + UART_IER);
- /* Enable FIFOs */
- outb(UART_FCR_FIFO_EN, base_port + UART_FCR);
-
- /* assert DTR and RTS so the other end is happy */
- outb(UART_MCR_DTR | UART_MCR_RTS, base_port + UART_MCR);
-
- /* DLAB on */
- outb(UART_LCR_DLAB | CONFIG_TTYS0_LCS, base_port + UART_LCR);
-
- /* Set Baud Rate Divisor. 12 ==> 9600 Baud */
- outb(divisor & 0xFF, base_port + UART_DLL);
- outb((divisor >> 8) & 0xFF, base_port + UART_DLM);
-
- /* Set to 3 for 8N1 */
- outb(CONFIG_TTYS0_LCS, base_port + UART_LCR);
- ENABLE_TRACE;
-}
-
-/* FIXME: Needs uart index from Kconfig.
- * Already use array as a work-around for ROMCC.
- */
-static const unsigned bases[1] = { CONFIG_TTYS0_BASE };
-
-void uart_init(void)
-{
- unsigned int div = uart_baudrate_divisor(BAUDRATE_REFCLK);
- uart8250_init(bases[0], div);
-}
-
-void uart_tx_byte(unsigned char data)
-{
- uart8250_tx_byte(bases[0], data);
-}
-
-unsigned char uart_rx_byte(void)
-{
- return uart8250_rx_byte(bases[0]);
-}
-
-int uart_can_rx_byte(void)
-{
- return uart8250_can_rx_byte(bases[0]);
-}
-
-void uart_tx_flush(void)
-{
- uart8250_tx_flush(bases[0]);
-}
diff --git a/src/lib/uart8250mem.c b/src/lib/uart8250mem.c
deleted file mode 100644
index fb471fb..0000000
--- a/src/lib/uart8250mem.c
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * This file is part of the coreboot project.
- *
- * Copyright (C) 2003 Eric Biederman
- * Copyright (C) 2006-2010 coresystems GmbH
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; version 2 of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <arch/io.h>
-#include <console/uart.h>
-#include <uart8250.h>
-#include <device/device.h>
-#include <delay.h>
-
-/* Should support 8250, 16450, 16550, 16550A type UARTs */
-
-/* Expected character delay at 1200bps is 9ms for a working UART
- * and no flow-control. Assume UART as stuck if shift register
- * or FIFO takes more than 50ms per character to appear empty.
- */
-#define SINGLE_CHAR_TIMEOUT (50 * 1000)
-#define FIFO_TIMEOUT (16 * SINGLE_CHAR_TIMEOUT)
-
-static int uart8250_mem_can_tx_byte(unsigned base_port)
-{
- return read8(base_port + UART_LSR) & UART_LSR_THRE;
-}
-
-static void uart8250_mem_tx_byte(unsigned base_port, unsigned char data)
-{
- unsigned long int i = SINGLE_CHAR_TIMEOUT;
- while(i-- && !uart8250_mem_can_tx_byte(base_port))
- udelay(1);
- write8(base_port + UART_TBR, data);
-}
-
-static void uart8250_mem_tx_flush(unsigned base_port)
-{
- unsigned long int i = FIFO_TIMEOUT;
- while(i-- && !(read8(base_port + UART_LSR) & UART_LSR_TEMT))
- udelay(1);
-}
-
-static int uart8250_mem_can_rx_byte(unsigned base_port)
-{
- return read8(base_port + UART_LSR) & UART_LSR_DR;
-}
-
-static unsigned char uart8250_mem_rx_byte(unsigned base_port)
-{
- unsigned long int i = SINGLE_CHAR_TIMEOUT;
- while(i-- && !uart8250_mem_can_rx_byte(base_port))
- udelay(1);
- if (i)
- return read8(base_port + UART_RBR);
- else
- return 0x0;
-}
-
-static void uart8250_mem_init(unsigned base_port, unsigned divisor)
-{
- /* Disable interrupts */
- write8(base_port + UART_IER, 0x0);
- /* Enable FIFOs */
- write8(base_port + UART_FCR, UART_FCR_FIFO_EN);
-
- /* Assert DTR and RTS so the other end is happy */
- write8(base_port + UART_MCR, UART_MCR_DTR | UART_MCR_RTS);
-
- /* DLAB on */
- write8(base_port + UART_LCR, UART_LCR_DLAB | CONFIG_TTYS0_LCS);
-
- /* Set Baud Rate Divisor. 12 ==> 9600 Baud */
- write8(base_port + UART_DLL, divisor & 0xFF);
- write8(base_port + UART_DLM, (divisor >> 8) & 0xFF);
-
- /* Set to 3 for 8N1 */
- write8(base_port + UART_LCR, CONFIG_TTYS0_LCS);
-}
-
-void uart_init(void)
-{
- u32 base = uart_platform_base(0);
- if (!base)
- return;
-
- unsigned int refclk = uart_platform_refclk();
- unsigned int div = uart_baudrate_divisor(refclk);
- uart8250_mem_init(base, div);
-}
-
-void uart_tx_byte(unsigned char data)
-{
- u32 base = uart_platform_base(0);
- if (!base)
- return;
- uart8250_mem_tx_byte(base, data);
-}
-
-unsigned char uart_rx_byte(void)
-{
- u32 base = uart_platform_base(0);
- if (!base)
- return 0xff;
- return uart8250_mem_rx_byte(base);
-}
-
-int uart_can_rx_byte(void)
-{
- u32 base = uart_platform_base(0);
- if (!base)
- return 0;
- return uart8250_mem_can_rx_byte(base);
-}
-
-void uart_tx_flush(void)
-{
- u32 base = uart_platform_base(0);
- if (!base)
- return;
- uart8250_mem_tx_flush(base);
-}
Kyösti Mälkki (kyosti.malkki(a)gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/4585
-gerrit
commit 3e5ad71a7e612fd80fbb0cb0b4c2681d73e7ed9e
Author: Kyösti Mälkki <kyosti.malkki(a)gmail.com>
Date: Mon Feb 17 11:36:29 2014 +0200
uart: Do not guard entire include file by config options
Do not guard the file by CONFIG_CONSOLE_SERIAL8250 or
CONFIG_CONSOLE_SERIAL8250MEM or CONFIG_CONSOLE_SERIAL.
Don't do indirect includes for <uart8250.h>.
The config-specific options are already properly guarded, and there
is no need to guard the register and bit definitions.
Change-Id: I7528b18cdc62bc5c22486f037e14002838a2176e
Signed-off-by: Alexandru Gagniuc <mr.nuke.me(a)gmail.com>
Signed-off-by: Kyösti Mälkki <kyosti.malkki(a)gmail.com>
---
src/cpu/allwinner/a10/uart.c | 5 -----
src/include/uart.h | 14 --------------
src/include/uart8250.h | 5 -----
3 files changed, 24 deletions(-)
diff --git a/src/cpu/allwinner/a10/uart.c b/src/cpu/allwinner/a10/uart.c
index dc98bff..97ac302 100644
--- a/src/cpu/allwinner/a10/uart.c
+++ b/src/cpu/allwinner/a10/uart.c
@@ -7,11 +7,6 @@
#include "uart.h"
#include <arch/io.h>
-
-/* Give me my 8250 UART definitions!!!! */
-/* TODO: Clean this up when uart8250mem works on ARM */
-#undef CONFIG_CONSOLE_SERIAL8250MEM
-#define CONFIG_CONSOLE_SERIAL8250MEM 1
#include <uart8250.h>
/**
diff --git a/src/include/uart.h b/src/include/uart.h
index e24699b..98d77e7 100644
--- a/src/include/uart.h
+++ b/src/include/uart.h
@@ -17,12 +17,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-/* madness. Uarts are a mess. If you include this file, it
- * includes ALL uart implementations which may be needed.
- * No need to include them separately, and include this file FIRST.
- * At least one (but at most one) of the files needs to define
- * uart_init().
- */
#ifndef UART_H
#define UART_H
@@ -36,19 +30,11 @@ unsigned int uart_platform_refclk(void);
unsigned int uart_baudrate_divisor(unsigned int refclk);
-#if CONFIG_CONSOLE_SERIAL8250 || CONFIG_CONSOLE_SERIAL8250MEM
-#include <uart8250.h>
-#endif
-
-#if CONFIG_CONSOLE_SERIAL_UART
unsigned char uart_rx_byte(void);
void uart_tx_byte(unsigned char data);
void uart_tx_flush(void);
void uart_init(void);
-#endif
-#if CONFIG_HAVE_UART_MEMORY_MAPPED
uint32_t uartmem_getbaseaddr(void);
-#endif
#endif /* UART_H */
diff --git a/src/include/uart8250.h b/src/include/uart8250.h
index 0c5ee77..112cd44 100644
--- a/src/include/uart8250.h
+++ b/src/include/uart8250.h
@@ -20,8 +20,6 @@
#ifndef UART8250_H
#define UART8250_H
-#if CONFIG_CONSOLE_SERIAL8250 || CONFIG_CONSOLE_SERIAL8250MEM
-
/* Data */
#define UART_RBR 0x00
#define UART_TBR 0x00
@@ -116,7 +114,6 @@ void uart8250_tx_flush(unsigned base_port);
* have three different sets of uart code, so it's an improvement.
*/
void uart8250_init(unsigned base_port, unsigned divisor);
-void uart_init(void);
#endif
#if CONFIG_CONSOLE_SERIAL8250MEM
void uartmem_init(void);
@@ -137,6 +134,4 @@ void oxford_init(void);
#endif
#endif
-#endif /* CONFIG_CONSOLE_SERIAL8250 || CONFIG_CONSOLE_SERIAL8250MEM */
-
#endif /* UART8250_H */
Kyösti Mälkki (kyosti.malkki(a)gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/4585
-gerrit
commit 5eeeafddb9ae5f9a338e0ae32f702fe430778c43
Author: Kyösti Mälkki <kyosti.malkki(a)gmail.com>
Date: Mon Feb 17 11:36:29 2014 +0200
uart: Do not guard entire include file by config options
Do not guard the file by CONFIG_CONSOLE_SERIAL8250 or
CONFIG_CONSOLE_SERIAL8250MEM or CONFIG_CONSOLE_SERIAL.
Don't do indirect includes for <uart8250.h>.
The config-specific options are already properly guarded, and there
is no need to guard the register and bit definitions.
Change-Id: I7528b18cdc62bc5c22486f037e14002838a2176e
Signed-off-by: Alexandru Gagniuc <mr.nuke.me(a)gmail.com>
Signed-off-by: Kyösti Mälkki <kyosti.malkki(a)gmail.com>
---
src/cpu/allwinner/a10/uart.c | 5 -----
src/include/uart.h | 14 --------------
src/include/uart8250.h | 5 -----
3 files changed, 24 deletions(-)
diff --git a/src/cpu/allwinner/a10/uart.c b/src/cpu/allwinner/a10/uart.c
index dc98bff..97ac302 100644
--- a/src/cpu/allwinner/a10/uart.c
+++ b/src/cpu/allwinner/a10/uart.c
@@ -7,11 +7,6 @@
#include "uart.h"
#include <arch/io.h>
-
-/* Give me my 8250 UART definitions!!!! */
-/* TODO: Clean this up when uart8250mem works on ARM */
-#undef CONFIG_CONSOLE_SERIAL8250MEM
-#define CONFIG_CONSOLE_SERIAL8250MEM 1
#include <uart8250.h>
/**
diff --git a/src/include/uart.h b/src/include/uart.h
index e24699b..98d77e7 100644
--- a/src/include/uart.h
+++ b/src/include/uart.h
@@ -17,12 +17,6 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-/* madness. Uarts are a mess. If you include this file, it
- * includes ALL uart implementations which may be needed.
- * No need to include them separately, and include this file FIRST.
- * At least one (but at most one) of the files needs to define
- * uart_init().
- */
#ifndef UART_H
#define UART_H
@@ -36,19 +30,11 @@ unsigned int uart_platform_refclk(void);
unsigned int uart_baudrate_divisor(unsigned int refclk);
-#if CONFIG_CONSOLE_SERIAL8250 || CONFIG_CONSOLE_SERIAL8250MEM
-#include <uart8250.h>
-#endif
-
-#if CONFIG_CONSOLE_SERIAL_UART
unsigned char uart_rx_byte(void);
void uart_tx_byte(unsigned char data);
void uart_tx_flush(void);
void uart_init(void);
-#endif
-#if CONFIG_HAVE_UART_MEMORY_MAPPED
uint32_t uartmem_getbaseaddr(void);
-#endif
#endif /* UART_H */
diff --git a/src/include/uart8250.h b/src/include/uart8250.h
index 0c5ee77..112cd44 100644
--- a/src/include/uart8250.h
+++ b/src/include/uart8250.h
@@ -20,8 +20,6 @@
#ifndef UART8250_H
#define UART8250_H
-#if CONFIG_CONSOLE_SERIAL8250 || CONFIG_CONSOLE_SERIAL8250MEM
-
/* Data */
#define UART_RBR 0x00
#define UART_TBR 0x00
@@ -116,7 +114,6 @@ void uart8250_tx_flush(unsigned base_port);
* have three different sets of uart code, so it's an improvement.
*/
void uart8250_init(unsigned base_port, unsigned divisor);
-void uart_init(void);
#endif
#if CONFIG_CONSOLE_SERIAL8250MEM
void uartmem_init(void);
@@ -137,6 +134,4 @@ void oxford_init(void);
#endif
#endif
-#endif /* CONFIG_CONSOLE_SERIAL8250 || CONFIG_CONSOLE_SERIAL8250MEM */
-
#endif /* UART8250_H */
Kyösti Mälkki (kyosti.malkki(a)gmail.com) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/5229
-gerrit
commit 2fa65a66877cd14df5f8d7bea59b434c60cebdda
Author: Kyösti Mälkki <kyosti.malkki(a)gmail.com>
Date: Mon Feb 17 19:37:52 2014 +0200
uart: Unify baudrate divisor calculation
Divisor is a function of requested baudrate and platform-specific
clock used for UART reference. Combine this with the capability to
read baudrate from option_table.
When building without option_table or when there is no entry for
baud_rate, CONFIG_TTYS0_BAUD is used.
FIXME: Field for baudrate in lb_tables is still incorrect.
Change-Id: I68539738469af780fadd3392263dd9b3d5964d2d
Signed-off-by: Kyösti Mälkki <kyosti.malkki(a)gmail.com>
---
src/arch/x86/lib/romcc_console.c | 1 +
src/drivers/oxford/oxpcie/oxpcie_early.c | 10 +++++-
src/drivers/uart/Makefile.inc | 6 ++++
src/drivers/uart/util.c | 54 ++++++++++++++++++++++++++++++++
src/include/uart.h | 10 ++++++
src/include/uart8250.h | 4 ---
src/lib/uart8250.c | 32 ++++---------------
src/lib/uart8250mem.c | 26 ++-------------
8 files changed, 89 insertions(+), 54 deletions(-)
diff --git a/src/arch/x86/lib/romcc_console.c b/src/arch/x86/lib/romcc_console.c
index db84f9e..c5e6882 100644
--- a/src/arch/x86/lib/romcc_console.c
+++ b/src/arch/x86/lib/romcc_console.c
@@ -32,6 +32,7 @@
#endif
#if CONFIG_CONSOLE_SERIAL8250
+#include "drivers/uart/util.c"
#include "lib/uart8250.c"
#endif
#if CONFIG_CONSOLE_NE2K
diff --git a/src/drivers/oxford/oxpcie/oxpcie_early.c b/src/drivers/oxford/oxpcie/oxpcie_early.c
index d04e9d4..edb97d5 100644
--- a/src/drivers/oxford/oxpcie/oxpcie_early.c
+++ b/src/drivers/oxford/oxpcie/oxpcie_early.c
@@ -21,6 +21,7 @@
#include <arch/io.h>
#include <arch/early_variables.h>
#include <delay.h>
+#include <uart.h>
#include <uart8250.h>
#include <device/pci_def.h>
@@ -116,7 +117,14 @@ void oxford_init(void)
/* Now the UART initialization */
u32 uart0_base = CONFIG_OXFORD_OXPCIE_BASE_ADDRESS + 0x1000;
- uart8250_mem_init(uart0_base, (4000000 / CONFIG_TTYS0_BAUD));
+ unsigned int refclk = uart_platform_refclk();
+ unsigned int div = uart_baudrate_divisor(refclk);
+ uart8250_mem_init(uart0_base, div);
}
#endif
+
+unsigned int uart_platform_refclk(void)
+{
+ return 4000000;
+}
diff --git a/src/drivers/uart/Makefile.inc b/src/drivers/uart/Makefile.inc
new file mode 100644
index 0000000..c797d4b
--- /dev/null
+++ b/src/drivers/uart/Makefile.inc
@@ -0,0 +1,6 @@
+ifeq ($(CONFIG_CONSOLE_SERIAL),y)
+romstage-y += util.c
+ramstage-y += util.c
+bootblock-y += util.c
+smm-y += util.c
+endif
diff --git a/src/drivers/uart/util.c b/src/drivers/uart/util.c
new file mode 100644
index 0000000..5e9b5e6
--- /dev/null
+++ b/src/drivers/uart/util.c
@@ -0,0 +1,54 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <console/console.h>
+#include <uart.h>
+#if CONFIG_USE_OPTION_TABLE
+#include <pc80/mc146818rtc.h>
+#include "option_table.h"
+#endif
+
+#if CONFIG_CONSOLE_SERIAL
+/* Treat the default base frequency 115200 as a special case
+ * to avoid runtime division. Might help ROMCC builds.
+ */
+unsigned int uart_baudrate_divisor(unsigned int basefreq)
+{
+ unsigned div = (basefreq / CONFIG_TTYS0_BAUD);
+
+#if !defined(__SMM__) && CONFIG_USE_OPTION_TABLE
+ static const unsigned char divisor[8] = { 1, 2, 3, 6, 12, 24, 48, 96 };
+ static const unsigned baud[8] =
+ { 115200, 57600, 38400, 19200, 9600, 4800, 2400, 1200 };
+ unsigned b_index = 0;
+#if defined(__PRE_RAM__)
+ b_index = read_option(baud_rate, 0xff);
+#else
+ if (get_option(&b_index, "baud_rate") != CB_SUCCESS)
+ b_index = 0xff;
+#endif
+ if (b_index < 8) {
+ if (basefreq == 115200)
+ div = divisor[b_index];
+ else
+ div = (basefreq / baud[b_index]);
+ }
+#endif
+ return div;
+}
+
+#endif
diff --git a/src/include/uart.h b/src/include/uart.h
index 9601bfa..e24699b 100644
--- a/src/include/uart.h
+++ b/src/include/uart.h
@@ -26,6 +26,16 @@
#ifndef UART_H
#define UART_H
+/* Return the clock frequency UART uses as reference clock for
+ * baudrate generator. */
+unsigned int uart_platform_refclk(void);
+
+/* Return the divisor that configures UART for baudrate detemined
+ * from option_table, or when that is not used, CONFIG_TTYS0_BAUD.
+ */
+unsigned int uart_baudrate_divisor(unsigned int refclk);
+
+
#if CONFIG_CONSOLE_SERIAL8250 || CONFIG_CONSOLE_SERIAL8250MEM
#include <uart8250.h>
#endif
diff --git a/src/include/uart8250.h b/src/include/uart8250.h
index bec3637..0c5ee77 100644
--- a/src/include/uart8250.h
+++ b/src/include/uart8250.h
@@ -107,10 +107,6 @@
#define UART_SCR 0x07
#define UART_SPR 0x07
-#if ((115200 % CONFIG_TTYS0_BAUD) != 0)
-#error Bad ttyS0 baud rate
-#endif
-
#if CONFIG_CONSOLE_SERIAL8250
unsigned char uart8250_rx_byte(unsigned base_port);
int uart8250_can_rx_byte(unsigned base_port);
diff --git a/src/lib/uart8250.c b/src/lib/uart8250.c
index aa18d2a..9dcd388 100644
--- a/src/lib/uart8250.c
+++ b/src/lib/uart8250.c
@@ -19,16 +19,16 @@
*/
#include <arch/io.h>
+#include <uart.h>
#include <uart8250.h>
-#include <pc80/mc146818rtc.h>
#include <trace.h>
-#if CONFIG_USE_OPTION_TABLE
-#include "option_table.h"
-#endif
-
/* Should support 8250, 16450, 16550, 16550A type UARTs */
+/* No reports of super-IOs that would use different clock for
+ * baudrate reference. */
+#define BAUDRATE_REFCLK 115200
+
/* Expected character delay at 1200bps is 9ms for a working UART
* and no flow-control. Assume UART as stuck if shift register
* or FIFO takes more than 50ms per character to appear empty.
@@ -107,26 +107,6 @@ void uart8250_init(unsigned base_port, unsigned divisor)
void uart_init(void)
{
- /* TODO the divisor calculation is hard coded to standard UARTs. Some
- * UARTs won't work with these values. This should be a property of the
- * UART used, worst case a Kconfig variable. For now live with hard
- * codes as the only devices that might be different are the iWave
- * iRainbowG6 and the OXPCIe952 card (and the latter is memory mapped)
- */
- unsigned int div = (115200 / CONFIG_TTYS0_BAUD);
-
-#if !defined(__SMM__) && CONFIG_USE_OPTION_TABLE
- static const unsigned char divisor[8] = { 1, 2, 3, 6, 12, 24, 48, 96 };
- unsigned b_index = 0;
-#if defined(__PRE_RAM__)
- b_index = read_option(baud_rate, 0);
- b_index &= 7;
- div = divisor[b_index];
-#else
- if (get_option(&b_index, "baud_rate") == CB_SUCCESS)
- div = divisor[b_index];
-#endif
-#endif
-
+ unsigned int div = uart_baudrate_divisor(BAUDRATE_REFCLK);
uart8250_init(CONFIG_TTYS0_BASE, div);
}
diff --git a/src/lib/uart8250mem.c b/src/lib/uart8250mem.c
index 1482142..a370e50 100644
--- a/src/lib/uart8250mem.c
+++ b/src/lib/uart8250mem.c
@@ -19,11 +19,8 @@
*/
#include <arch/io.h>
+#include <uart.h>
#include <uart8250.h>
-#include <pc80/mc146818rtc.h>
-#if CONFIG_USE_OPTION_TABLE
-#include "option_table.h"
-#endif
#include <device/device.h>
#include <delay.h>
@@ -105,27 +102,10 @@ void uart8250_mem_init(unsigned base_port, unsigned divisor)
u32 uart_mem_init(void)
{
- unsigned uart_baud = CONFIG_TTYS0_BAUD;
u32 uart_bar = 0;
- unsigned div;
-
- /* find out the correct baud rate */
-#if !defined(__SMM__) && CONFIG_USE_OPTION_TABLE
- static const unsigned baud[8] = { 115200, 57600, 38400, 19200, 9600, 4800, 2400, 1200 };
- unsigned b_index = 0;
-#if defined(__PRE_RAM__)
- b_index = read_option(baud_rate, 0);
- b_index &= 7;
- uart_baud = baud[b_index];
-#else
- if (get_option(&b_index, "baud_rate") == CB_SUCCESS)
- uart_baud = baud[b_index];
-#endif
-#endif
/* Now find the UART base address and calculate the divisor */
#if CONFIG_DRIVERS_OXFORD_OXPCIE
-
#if defined(MORE_TESTING) && !defined(__SIMPLE_DEVICE__)
device_t dev = dev_find_device(0x1415, 0xc158, NULL);
if (!dev)
@@ -144,10 +124,10 @@ u32 uart_mem_init(void)
#endif
uart_bar = CONFIG_OXFORD_OXPCIE_BASE_ADDRESS + 0x1000; // 1st UART
// uart_bar = CONFIG_OXFORD_OXPCIE_BASE_ADDRESS + 0x2000; // 2nd UART
-
- div = 4000000 / uart_baud;
#endif
+ unsigned int refclk = uart_platform_refclk();
+ unsigned int div = uart_baudrate_divisor(refclk);
if (uart_bar)
uart8250_mem_init(uart_bar, div);