2 * (C) Copyright 2000-2004
3 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #include <asm/mcfuart.h>
30 #include <asm/m5271.h>
34 #include <asm/m5272.h>
38 #include <asm/m5282.h>
42 #include <asm/m5249.h>
45 DECLARE_GLOBAL_DATA_PTR;
47 #if defined(CONFIG_M5249) || defined(CONFIG_M5271)
48 #define DoubleClock(a) ((double)(CFG_CLK/2) / 32.0 / (double)(a))
50 #define DoubleClock(a) ((double)(CFG_CLK) / 32.0 / (double)(a))
53 void rs_serial_setbaudrate(int port,int baudrate)
55 #if defined(CONFIG_M5272) || defined(CONFIG_M5249) || defined(CONFIG_M5271)
56 volatile unsigned char *uartp;
63 uartp = (volatile unsigned char *) (CFG_MBAR + MCFUART_BASE1);
65 uartp = (volatile unsigned char *) (CFG_MBAR + MCFUART_BASE2);
67 clock = DoubleClock(baudrate); /* Set baud above */
69 uartp[MCFUART_UBG1] = (((int)clock >> 8) & 0xff); /* set msb baud */
70 uartp[MCFUART_UBG2] = ((int)clock & 0xff); /* set lsb baud */
73 fraction = ((clock - (int)clock) * 16.0) + 0.5;
74 uartp[MCFUART_UFPD] = ((int)fraction & 0xf); /* set baud fraction adjust */
79 void rs_serial_init(int port,int baudrate)
81 volatile unsigned char *uartp;
84 * Reset UART, get it into known state...
87 uartp = (volatile unsigned char *) (CFG_MBAR + MCFUART_BASE1);
89 uartp = (volatile unsigned char *) (CFG_MBAR + MCFUART_BASE2);
91 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETTX; /* reset TX */
92 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETRX; /* reset RX */
94 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETMRPTR; /* reset MR pointer */
95 uartp[MCFUART_UCR] = MCFUART_UCR_CMDRESETERR; /* reset Error pointer */
98 * Set port for CONSOLE_BAUD_RATE, 8 data bits, 1 stop bit, no parity.
100 uartp[MCFUART_UMR] = MCFUART_MR1_PARITYNONE | MCFUART_MR1_CS8;
101 uartp[MCFUART_UMR] = MCFUART_MR2_STOP1;
103 /* Mask UART interrupts */
104 uartp[MCFUART_UIMR] = 0;
106 /* Set clock Select Register: Tx/Rx clock is timer */
107 uartp[MCFUART_UCSR] = MCFUART_UCSR_RXCLKTIMER | MCFUART_UCSR_TXCLKTIMER;
109 rs_serial_setbaudrate(port,baudrate);
112 uartp[MCFUART_UCR] = MCFUART_UCR_RXENABLE | MCFUART_UCR_TXENABLE;
117 /****************************************************************************/
119 * Output a single character, using UART polled mode.
120 * This is used for console output.
123 void rs_put_char(char ch)
125 volatile unsigned char *uartp;
128 uartp = (volatile unsigned char *) (CFG_MBAR + MCFUART_BASE1);
130 for (i = 0; (i < 0x10000); i++) {
131 if (uartp[MCFUART_USR] & MCFUART_USR_TXREADY)
134 uartp[MCFUART_UTB] = ch;
140 volatile unsigned char *uartp;
142 uartp = (volatile unsigned char *) (CFG_MBAR + MCFUART_BASE1);
143 return((uartp[MCFUART_USR] & MCFUART_USR_RXREADY) ? 1 : 0);
146 int rs_get_char(void)
148 volatile unsigned char *uartp;
150 uartp = (volatile unsigned char *) (CFG_MBAR + MCFUART_BASE1);
151 return(uartp[MCFUART_URB]);
154 void serial_setbrg(void) {
155 rs_serial_setbaudrate(0,gd->bd->bi_baudrate);
158 int serial_init(void) {
159 rs_serial_init(0,gd->baudrate);
164 void serial_putc(const char c) {
170 void serial_puts (const char *s) {
176 int serial_getc(void) {
177 while(!rs_is_char());
178 return rs_get_char();