2 * U-boot - serial.c Blackfin Serial Driver
4 * Copyright (c) 2005-2008 Analog Devices Inc.
6 * Copyright (c) 2003 Bas Vermeulen <bas@buyways.nl>,
7 * BuyWays B.V. (www.buyways.nl)
10 * blkfinserial.c: Serial driver for BlackFin DSP internal USRTs.
11 * Copyright(c) 2003 Metrowerks <mwaddel@metrowerks.com>
12 * Copyright(c) 2001 Tony Z. Kou <tonyko@arcturusnetworks.com>
13 * Copyright(c) 2001-2002 Arcturus Networks Inc. <www.arcturusnetworks.com>
15 * Based on code from 68328 version serial driver imlpementation which was:
16 * Copyright (C) 1995 David S. Miller <davem@caip.rutgers.edu>
17 * Copyright (C) 1998 Kenneth Albanowski <kjahds@kjahds.com>
18 * Copyright (C) 1998, 1999 D. Jeff Dionne <jeff@uclinux.org>
19 * Copyright (C) 1999 Vladimir Gurevich <vgurevic@cisco.com>
21 * (C) Copyright 2000-2004
22 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
24 * Licensed under the GPL-2 or later.
29 #include <asm/blackfin.h>
30 #include <asm/mach-common/bits/uart.h>
32 #if defined(UART_LSR) && (CONFIG_UART_CONSOLE != 0)
33 # error CONFIG_UART_CONSOLE must be 0 on parts with only one UART
38 /* Symbol for our assembly to call. */
39 void serial_set_baud(uint32_t baud)
41 serial_early_set_baud(baud);
44 /* Symbol for common u-boot code to call.
45 * Setup the baudrate (brg: baudrate generator).
47 void serial_setbrg(void)
49 DECLARE_GLOBAL_DATA_PTR;
50 serial_set_baud(gd->baudrate);
53 /* Symbol for our assembly to call. */
54 void serial_initialize(void)
59 /* Symbol for common u-boot code to call. */
67 void serial_putc(const char c)
69 /* send a \r for compatibility */
75 /* wait for the hardware fifo to clear up */
76 while (!(*pUART_LSR & THRE))
79 /* queue the character for transmission */
85 /* wait for the byte to be shifted over the line */
86 while (!(*pUART_LSR & TEMT))
93 return (*pUART_LSR & DR) ? 1 : 0;
98 uint16_t uart_lsr_val, uart_rbr_val;
100 /* wait for data ! */
101 while (!serial_tstc())
104 /* clear the status and grab the new byte */
105 uart_lsr_val = *pUART_LSR;
106 uart_rbr_val = *pUART_RBR;
108 if (uart_lsr_val & (OE|PE|FE|BI)) {
109 /* Some parts are read-to-clear while others are
110 * write-to-clear. Just do the write for everyone
111 * since it cant hurt (other than code size).
113 *pUART_LSR = (OE|PE|FE|BI);
117 return uart_rbr_val & 0xFF;
120 void serial_puts(const char *s)