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/autoconf.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>
40 #include <6348_map_part.h>
43 #define SER63XX_DEFAULT_BAUD 115200
44 #define BD_BCM63XX_TIMER_CLOCK_INPUT (FPERIPH)
45 #define stUart ((volatile Uart * const) UART_BASE)
47 // Transmit interrupts
48 #define TXINT (TXFIFOEMT | TXUNDERR | TXOVFERR)
50 #define RXINT (RXFIFONE | RXOVFERR)
52 /* --------------------------------------------------------------------------
54 Purpose: Initalize the UART
55 -------------------------------------------------------------------------- */
56 void __init
serial_init(void)
58 u32 tmpVal
= SER63XX_DEFAULT_BAUD
;
61 #if defined(CONFIG_BCM96345)
62 // Make sure clock is ticking
63 PERF
->blkEnables
|= UART_CLK_EN
;
66 /* Dissable channel's receiver and transmitter. */
67 stUart
->control
&= ~(BRGEN
|TXEN
|RXEN
);
69 /*--------------------------------------------------------------------*/
70 /* Write the table value to the clock select register. */
71 /* DPullen - this is the equation to use: */
72 /* value = clockFreqHz / baud / 32-1; */
73 /* (snmod) Actually you should also take into account any necessary */
74 /* rounding. Divide by 16, look at lsb, if 0, divide by 2 */
75 /* and subtract 1. If 1, just divide by 2 */
76 /*--------------------------------------------------------------------*/
77 clockFreqHz
= BD_BCM63XX_TIMER_CLOCK_INPUT
;
78 tmpVal
= (clockFreqHz
/ tmpVal
) / 16;
80 tmpVal
/= 2; //Rounding up, so sub is already accounted for
82 tmpVal
= (tmpVal
/ 2) - 1; // Rounding down so we must sub 1
83 stUart
->baudword
= tmpVal
;
85 /* Finally, re-enable the transmitter and receiver. */
86 stUart
->control
|= (BRGEN
|TXEN
|RXEN
);
88 stUart
->config
= (BITS8SYM
| ONESTOP
);
89 // Set the FIFO interrupt depth ... stUart->fifocfg = 0xAA;
90 stUart
->fifoctl
= RSTTXFIFOS
| RSTRXFIFOS
;
92 stUart
->intMask
= RXINT
| TXINT
;
97 * Output a character to the UART
99 void prom_putc(char c
)
101 /* Wait for Tx uffer to empty */
102 while (! (READ16(stUart
->intStatus
) & TXFIFOEMT
));
108 * Write a string to the UART
110 void prom_puts(const char *s
)
121 /* prom_getc_nowait()
122 * Returns a character from the UART
123 * Returns -1 if no characters available or corrupted
125 int prom_getc_nowait(void)
130 uStatus
= READ16(stUart
->intStatus
);
132 if (uStatus
& RXFIFONE
) { /* Do we have a character? */
133 cData
= READ16(stUart
->Data
) & 0xff; /* Read character */
134 if (uStatus
& (RXFRAMERR
| RXPARERR
)) { /* If we got an error, throw it away */
143 * Returns a charcter from the serial port
144 * Will block until it receives a valid character
150 /* Loop until we get a valid character */
152 cData
= prom_getc_nowait();
158 * Returns 0 if no characters available
164 uStatus
= READ16(stUart
->intStatus
);
166 return (uStatus
& RXFIFONE
);
169 #if defined (CONFIG_REMOTE_DEBUG)
170 /* Prevent other code from writing to the serial port */
171 void _putc(char c
) { }
172 void _puts(const char *ptr
) { }
174 /* Low level outputs call prom routines */
178 void _puts(const char *ptr
) {