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 #ifdef CONFIG_DEBUG_SERIAL
39 uint16_t cached_lsr[256];
40 uint16_t cached_rbr[256];
43 /* The LSR is read-to-clear on some parts, so we have to make sure status
44 * bits aren't inadvertently lost when doing various tests.
46 static uint16_t uart_lsr_save;
47 static uint16_t uart_lsr_read(void)
49 uint16_t lsr = *pUART_LSR;
50 uart_lsr_save |= (lsr & (OE|PE|FE|BI));
51 return lsr | uart_lsr_save;
53 /* Just do the clear for everyone since it can't hurt. */
54 static void uart_lsr_clear(void)
60 static inline uint16_t uart_lsr_read(void) { return *pUART_LSR; }
61 static inline void uart_lsr_clear(void) { *pUART_LSR = -1; }
64 /* Symbol for our assembly to call. */
65 void serial_set_baud(uint32_t baud)
67 serial_early_set_baud(baud);
70 /* Symbol for common u-boot code to call.
71 * Setup the baudrate (brg: baudrate generator).
73 void serial_setbrg(void)
75 DECLARE_GLOBAL_DATA_PTR;
76 serial_set_baud(gd->baudrate);
79 /* Symbol for our assembly to call. */
80 void serial_initialize(void)
85 /* Symbol for common u-boot code to call. */
91 #ifdef CONFIG_DEBUG_SERIAL
93 memset(cached_lsr, 0x00, sizeof(cached_lsr));
94 memset(cached_rbr, 0x00, sizeof(cached_rbr));
99 void serial_putc(const char c)
101 /* send a \r for compatibility */
107 /* wait for the hardware fifo to clear up */
108 while (!(uart_lsr_read() & THRE))
111 /* queue the character for transmission */
117 /* wait for the byte to be shifted over the line */
118 while (!(uart_lsr_read() & TEMT))
122 int serial_tstc(void)
125 return (uart_lsr_read() & DR) ? 1 : 0;
128 int serial_getc(void)
130 uint16_t uart_rbr_val;
132 /* wait for data ! */
133 while (!serial_tstc())
136 /* grab the new byte */
137 uart_rbr_val = *pUART_RBR;
139 #ifdef CONFIG_DEBUG_SERIAL
140 /* grab & clear the LSR */
141 uint16_t uart_lsr_val = uart_lsr_read();
143 cached_lsr[cache_count] = uart_lsr_val;
144 cached_rbr[cache_count] = uart_rbr_val;
145 cache_count = (cache_count + 1) % ARRAY_SIZE(cached_lsr);
147 if (uart_lsr_val & (OE|PE|FE|BI)) {
149 printf("\n[SERIAL ERROR]\n");
154 printf("\tDLL=0x%x DLH=0x%x\n", dll, dlh);
157 printf("\t%3i: RBR=0x%02x LSR=0x%02x\n", cache_count,
158 cached_rbr[cache_count], cached_lsr[cache_count]);
159 } while (cache_count > 0);
168 void serial_puts(const char *s)