2 * (c) 2007 Sascha Hauer <s.hauer@pengutronix.de>
4 * (C) Copyright 2009 Freescale Semiconductor, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #ifdef CONFIG_STMP3XXX_DBGUART
25 #include "stmp3xxx_dbguart.h"
27 DECLARE_GLOBAL_DATA_PTR;
30 * Set baud rate. The settings are always 8n1:
31 * 8 data bits, no parity, 1 stop bit
33 void serial_setbrg(void)
38 /* Disable everything */
39 cr = REG_RD(DBGUART_BASE + UARTDBGCR);
40 REG_WR(DBGUART_BASE + UARTDBGCR, 0);
42 /* Calculate and set baudrate */
43 quot = (CONFIG_DBGUART_CLK * 4) / gd->baudrate;
44 REG_WR(DBGUART_BASE + UARTDBGFBRD, quot & 0x3f);
45 REG_WR(DBGUART_BASE + UARTDBGIBRD, quot >> 6);
47 /* Set 8n1 mode, enable FIFOs */
49 REG_WR(DBGUART_BASE + UARTDBGLCR_H, lcr_h);
51 /* Enable Debug UART */
52 REG_WR(DBGUART_BASE + UARTDBGCR, cr);
60 REG_WR(DBGUART_BASE + UARTDBGCR, 0);
63 REG_WR(DBGUART_BASE + UARTDBGIMSC, 0);
65 /* Set default baudrate */
69 cr = TXE | RXE | UARTEN;
70 REG_WR(DBGUART_BASE + UARTDBGCR, cr);
75 /* Send a character */
76 void serial_putc(const char c)
78 /* Wait for room in TX FIFO */
79 while (REG_RD(DBGUART_BASE + UARTDBGFR) & TXFF)
82 /* Write the data byte */
83 REG_WR(DBGUART_BASE + UARTDBGDR, c);
89 void serial_puts(const char *s)
96 /* Test whether a character is in TX buffer */
99 /* Check if RX FIFO is not empty */
100 return !(REG_RD(DBGUART_BASE + UARTDBGFR) & RXFE);
103 /* Receive character */
104 int serial_getc(void)
106 /* Wait while TX FIFO is empty */
107 while (REG_RD(DBGUART_BASE + UARTDBGFR) & RXFE)
111 return REG_RD(DBGUART_BASE + UARTDBGDR) & 0xff;
114 #endif /* CONFIG_STMP378X_DBGUART */