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,
28 #include <asm/mcfuart.h>
31 #include <asm/m5271.h>
35 #include <asm/m5272.h>
39 #include <asm/m5282.h>
43 #include <asm/m5249.h>
46 DECLARE_GLOBAL_DATA_PTR
;
48 #if defined(CONFIG_M5249) || defined(CONFIG_M5271)
49 #define DoubleClock(a) ((double)(CFG_CLK/2) / 32.0 / (double)(a))
51 #define DoubleClock(a) ((double)(CFG_CLK) / 32.0 / (double)(a))
54 void rs_serial_setbaudrate(int port
,int baudrate
)
56 #if defined(CONFIG_M5272) || defined(CONFIG_M5249) || defined(CONFIG_M5271)
57 volatile unsigned char *uartp
;
64 uartp
= (volatile unsigned char *) (CFG_MBAR
+ MCFUART_BASE1
);
66 uartp
= (volatile unsigned char *) (CFG_MBAR
+ MCFUART_BASE2
);
68 clock
= DoubleClock(baudrate
); /* Set baud above */
70 uartp
[MCFUART_UBG1
] = (((int)clock
>> 8) & 0xff); /* set msb baud */
71 uartp
[MCFUART_UBG2
] = ((int)clock
& 0xff); /* set lsb baud */
74 fraction
= ((clock
- (int)clock
) * 16.0) + 0.5;
75 uartp
[MCFUART_UFPD
] = ((int)fraction
& 0xf); /* set baud fraction adjust */
79 #if defined(CONFIG_M5282)
80 volatile unsigned char *uartp
;
85 uartp
= (volatile unsigned char *) (CFG_MBAR
+ MCFUART_BASE2
);
88 uartp
= (volatile unsigned char *) (CFG_MBAR
+ MCFUART_BASE3
);
91 uartp
= (volatile unsigned char *) (CFG_MBAR
+ MCFUART_BASE1
);
94 clock
= (long) CFG_CLK
/ ((long) 32 * baudrate
); /* Set baud above */
96 uartp
[MCFUART_UBG1
] = (((int)clock
>> 8) & 0xff); /* set msb baud */
97 uartp
[MCFUART_UBG2
] = ((int) clock
& 0xff); /* set lsb baud */
102 void rs_serial_init (int port
, int baudrate
)
104 volatile unsigned char *uartp
;
107 * Reset UART, get it into known state...
111 uartp
= (volatile unsigned char *) (CFG_MBAR
+ MCFUART_BASE2
);
113 #if defined(CONFIG_M5282)
115 uartp
= (volatile unsigned char *) (CFG_MBAR
+ MCFUART_BASE3
);
119 uartp
= (volatile unsigned char *) (CFG_MBAR
+ MCFUART_BASE1
);
122 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETTX
; /* reset TX */
123 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETRX
; /* reset RX */
125 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETMRPTR
; /* reset MR pointer */
126 uartp
[MCFUART_UCR
] = MCFUART_UCR_CMDRESETERR
; /* reset Error pointer */
129 * Set port for CONSOLE_BAUD_RATE, 8 data bits, 1 stop bit, no parity.
131 uartp
[MCFUART_UMR
] = MCFUART_MR1_PARITYNONE
| MCFUART_MR1_CS8
;
132 uartp
[MCFUART_UMR
] = MCFUART_MR2_STOP1
;
134 /* Mask UART interrupts */
135 uartp
[MCFUART_UIMR
] = 0;
137 /* Set clock Select Register: Tx/Rx clock is timer */
138 uartp
[MCFUART_UCSR
] = MCFUART_UCSR_RXCLKTIMER
| MCFUART_UCSR_TXCLKTIMER
;
140 rs_serial_setbaudrate (port
, baudrate
);
143 uartp
[MCFUART_UCR
] = MCFUART_UCR_RXENABLE
| MCFUART_UCR_TXENABLE
;
148 /****************************************************************************/
150 * Output a single character, using UART polled mode.
151 * This is used for console output.
154 void rs_put_char(char ch
)
156 volatile unsigned char *uartp
;
159 uartp
= (volatile unsigned char *) (CFG_MBAR
+ MCFUART_BASE1
);
161 for (i
= 0; (i
< 0x10000); i
++) {
162 if (uartp
[MCFUART_USR
] & MCFUART_USR_TXREADY
)
165 uartp
[MCFUART_UTB
] = ch
;
171 volatile unsigned char *uartp
;
173 uartp
= (volatile unsigned char *) (CFG_MBAR
+ MCFUART_BASE1
);
174 return((uartp
[MCFUART_USR
] & MCFUART_USR_RXREADY
) ? 1 : 0);
177 int rs_get_char(void)
179 volatile unsigned char *uartp
;
181 uartp
= (volatile unsigned char *) (CFG_MBAR
+ MCFUART_BASE1
);
182 return(uartp
[MCFUART_URB
]);
185 void serial_setbrg(void) {
186 rs_serial_setbaudrate(0,gd
->bd
->bi_baudrate
);
189 int serial_init(void) {
190 rs_serial_init(0,gd
->baudrate
);
195 void serial_putc(const char c
) {
201 void serial_puts (const char *s
) {
206 int serial_getc(void) {
210 return rs_get_char();