summaryrefslogtreecommitdiff
path: root/cpu/blackfin/serial.c
diff options
context:
space:
mode:
authorWolfgang Denk <wd@denx.de>2008-04-08 00:06:47 +0200
committerWolfgang Denk <wd@denx.de>2008-04-08 00:06:47 +0200
commit34e6cb8d1d9dc8194b2d8cad1cc39273ac58f8d8 (patch)
treeb771597b2864542865bfad1e56ecaf4f5641acf9 /cpu/blackfin/serial.c
parent62479b181460f5bf99517b68059d5ba87908edd3 (diff)
parentd5bffeb868d6b4d462f558dac43011027b6644b7 (diff)
downloadu-boot-imx-34e6cb8d1d9dc8194b2d8cad1cc39273ac58f8d8.zip
u-boot-imx-34e6cb8d1d9dc8194b2d8cad1cc39273ac58f8d8.tar.gz
u-boot-imx-34e6cb8d1d9dc8194b2d8cad1cc39273ac58f8d8.tar.bz2
Merge branch 'master' of git://www.denx.de/git/u-boot-blackfin
Diffstat (limited to 'cpu/blackfin/serial.c')
-rw-r--r--cpu/blackfin/serial.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/cpu/blackfin/serial.c b/cpu/blackfin/serial.c
new file mode 100644
index 0000000..0dfee51
--- /dev/null
+++ b/cpu/blackfin/serial.c
@@ -0,0 +1,124 @@
+/*
+ * U-boot - serial.c Blackfin Serial Driver
+ *
+ * Copyright (c) 2005-2008 Analog Devices Inc.
+ *
+ * Copyright (c) 2003 Bas Vermeulen <bas@buyways.nl>,
+ * BuyWays B.V. (www.buyways.nl)
+ *
+ * Based heavily on:
+ * blkfinserial.c: Serial driver for BlackFin DSP internal USRTs.
+ * Copyright(c) 2003 Metrowerks <mwaddel@metrowerks.com>
+ * Copyright(c) 2001 Tony Z. Kou <tonyko@arcturusnetworks.com>
+ * Copyright(c) 2001-2002 Arcturus Networks Inc. <www.arcturusnetworks.com>
+ *
+ * Based on code from 68328 version serial driver imlpementation which was:
+ * Copyright (C) 1995 David S. Miller <davem@caip.rutgers.edu>
+ * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>
+ * Copyright (C) 1998, 1999 D. Jeff Dionne <jeff@uclinux.org>
+ * Copyright (C) 1999 Vladimir Gurevich <vgurevic@cisco.com>
+ *
+ * (C) Copyright 2000-2004
+ * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
+ *
+ * Licensed under the GPL-2 or later.
+ */
+
+#include <common.h>
+#include <watchdog.h>
+#include <asm/blackfin.h>
+#include <asm/mach-common/bits/uart.h>
+
+#if defined(UART_LSR) && (CONFIG_UART_CONSOLE != 0)
+# error CONFIG_UART_CONSOLE must be 0 on parts with only one UART
+#endif
+
+#include "serial.h"
+
+/* Symbol for our assembly to call. */
+void serial_set_baud(uint32_t baud)
+{
+ serial_early_set_baud(baud);
+}
+
+/* Symbol for common u-boot code to call.
+ * Setup the baudrate (brg: baudrate generator).
+ */
+void serial_setbrg(void)
+{
+ DECLARE_GLOBAL_DATA_PTR;
+ serial_set_baud(gd->baudrate);
+}
+
+/* Symbol for our assembly to call. */
+void serial_initialize(void)
+{
+ serial_early_init();
+}
+
+/* Symbol for common u-boot code to call. */
+int serial_init(void)
+{
+ serial_initialize();
+ serial_setbrg();
+ return 0;
+}
+
+void serial_putc(const char c)
+{
+ /* send a \r for compatibility */
+ if (c == '\n')
+ serial_putc('\r');
+
+ WATCHDOG_RESET();
+
+ /* wait for the hardware fifo to clear up */
+ while (!(*pUART_LSR & THRE))
+ continue;
+
+ /* queue the character for transmission */
+ *pUART_THR = c;
+ SSYNC();
+
+ WATCHDOG_RESET();
+
+ /* wait for the byte to be shifted over the line */
+ while (!(*pUART_LSR & TEMT))
+ continue;
+}
+
+int serial_tstc(void)
+{
+ WATCHDOG_RESET();
+ return (*pUART_LSR & DR) ? 1 : 0;
+}
+
+int serial_getc(void)
+{
+ uint16_t uart_lsr_val, uart_rbr_val;
+
+ /* wait for data ! */
+ while (!serial_tstc())
+ continue;
+
+ /* clear the status and grab the new byte */
+ uart_lsr_val = *pUART_LSR;
+ uart_rbr_val = *pUART_RBR;
+
+ if (uart_lsr_val & (OE|PE|FE|BI)) {
+ /* Some parts are read-to-clear while others are
+ * write-to-clear. Just do the write for everyone
+ * since it cant hurt (other than code size).
+ */
+ *pUART_LSR = (OE|PE|FE|BI);
+ return -1;
+ }
+
+ return uart_rbr_val & 0xFF;
+}
+
+void serial_puts(const char *s)
+{
+ while (*s)
+ serial_putc(*s++);
+}