3 Copyright 2004 Broadcom Corp. All Rights Reserved.
5 This program is free software; you can distribute it and/or modify it
6 under the terms of the GNU General Public License (Version 2) as
7 published by the Free Software Foundation.
9 This program is distributed in the hope it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
20 * Broadcom bcm63xx serial port initialization, also prepare for printk
21 * by registering with console_init
25 #include <linux/config.h>
26 #include <linux/init.h>
27 #include <linux/interrupt.h>
28 #include <linux/kernel.h>
29 #include <linux/types.h>
30 #include <linux/console.h>
31 #include <linux/sched.h>
33 #include <asm/addrspace.h>
35 #include <asm/reboot.h>
36 #include <asm/gdb-stub.h>
37 #include <asm/mc146818rtc.h>
39 #include <bcm_map_part.h>
42 #define SER63XX_DEFAULT_BAUD 115200
43 #define BD_BCM63XX_TIMER_CLOCK_INPUT (FPERIPH)
44 #define stUart ((volatile Uart * const) UART_BASE)
46 // Transmit interrupts
47 #define TXINT (TXFIFOEMT | TXUNDERR | TXOVFERR)
49 #define RXINT (RXFIFONE | RXOVFERR)
51 /* --------------------------------------------------------------------------
53 Purpose: Initalize the UART
54 -------------------------------------------------------------------------- */
55 void __init serial_init(void)
57 UINT32 tmpVal = SER63XX_DEFAULT_BAUD;
60 /* Dissable channel's receiver and transmitter. */
61 stUart->control &= ~(BRGEN|TXEN|RXEN);
63 /*--------------------------------------------------------------------*/
64 /* Write the table value to the clock select register. */
65 /* DPullen - this is the equation to use: */
66 /* value = clockFreqHz / baud / 32-1; */
67 /* (snmod) Actually you should also take into account any necessary */
68 /* rounding. Divide by 16, look at lsb, if 0, divide by 2 */
69 /* and subtract 1. If 1, just divide by 2 */
70 /*--------------------------------------------------------------------*/
71 clockFreqHz = BD_BCM63XX_TIMER_CLOCK_INPUT;
72 tmpVal = (clockFreqHz / tmpVal) / 16;
74 tmpVal /= 2; //Rounding up, so sub is already accounted for
76 tmpVal = (tmpVal / 2) - 1; // Rounding down so we must sub 1
77 stUart->baudword = tmpVal;
79 /* Finally, re-enable the transmitter and receiver. */
80 stUart->control |= (BRGEN|TXEN|RXEN);
82 stUart->config = (BITS8SYM | ONESTOP);
83 // Set the FIFO interrupt depth ... stUart->fifocfg = 0xAA;
84 stUart->fifoctl = RSTTXFIFOS | RSTRXFIFOS;
86 stUart->intMask = RXINT | TXINT;
91 * Output a character to the UART
93 void prom_putc(char c)
95 /* Wait for Tx uffer to empty */
96 while (! (READ16(stUart->intStatus) & TXFIFOEMT));
102 * Write a string to the UART
104 void prom_puts(const char *s)
115 /* prom_getc_nowait()
116 * Returns a character from the UART
117 * Returns -1 if no characters available or corrupted
119 int prom_getc_nowait(void)
124 uStatus = READ16(stUart->intStatus);
126 if (uStatus & RXFIFONE) { /* Do we have a character? */
127 cData = READ16(stUart->Data) & 0xff; /* Read character */
128 if (uStatus & (RXFRAMERR | RXPARERR)) { /* If we got an error, throw it away */
137 * Returns a charcter from the serial port
138 * Will block until it receives a valid character
144 /* Loop until we get a valid character */
146 cData = prom_getc_nowait();
152 * Returns 0 if no characters available
158 uStatus = READ16(stUart->intStatus);
160 return (uStatus & RXFIFONE);
163 #if CONFIG_REMOTE_DEBUG
164 /* Prevent other code from writing to the serial port */
165 void _putc(char c) { }
166 void _puts(const char *ptr) { }
168 /* Low level outputs call prom routines */
172 void _puts(const char *ptr) {