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>
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 #if defined(CONFIG_BCM96345)
61 // Make sure clock is ticking
62 PERF->blkEnables |= UART_CLK_EN;
65 /* Dissable channel's receiver and transmitter. */
66 stUart->control &= ~(BRGEN|TXEN|RXEN);
68 /*--------------------------------------------------------------------*/
69 /* Write the table value to the clock select register. */
70 /* DPullen - this is the equation to use: */
71 /* value = clockFreqHz / baud / 32-1; */
72 /* (snmod) Actually you should also take into account any necessary */
73 /* rounding. Divide by 16, look at lsb, if 0, divide by 2 */
74 /* and subtract 1. If 1, just divide by 2 */
75 /*--------------------------------------------------------------------*/
76 clockFreqHz = BD_BCM63XX_TIMER_CLOCK_INPUT;
77 tmpVal = (clockFreqHz / tmpVal) / 16;
79 tmpVal /= 2; //Rounding up, so sub is already accounted for
81 tmpVal = (tmpVal / 2) - 1; // Rounding down so we must sub 1
82 stUart->baudword = tmpVal;
84 /* Finally, re-enable the transmitter and receiver. */
85 stUart->control |= (BRGEN|TXEN|RXEN);
87 stUart->config = (BITS8SYM | ONESTOP);
88 // Set the FIFO interrupt depth ... stUart->fifocfg = 0xAA;
89 stUart->fifoctl = RSTTXFIFOS | RSTRXFIFOS;
91 stUart->intMask = RXINT | TXINT;
96 * Output a character to the UART
98 void prom_putc(char c)
100 /* Wait for Tx uffer to empty */
101 while (! (READ16(stUart->intStatus) & TXFIFOEMT));
107 * Write a string to the UART
109 void prom_puts(const char *s)
120 /* prom_getc_nowait()
121 * Returns a character from the UART
122 * Returns -1 if no characters available or corrupted
124 int prom_getc_nowait(void)
129 uStatus = READ16(stUart->intStatus);
131 if (uStatus & RXFIFONE) { /* Do we have a character? */
132 cData = READ16(stUart->Data) & 0xff; /* Read character */
133 if (uStatus & (RXFRAMERR | RXPARERR)) { /* If we got an error, throw it away */
142 * Returns a charcter from the serial port
143 * Will block until it receives a valid character
149 /* Loop until we get a valid character */
151 cData = prom_getc_nowait();
157 * Returns 0 if no characters available
163 uStatus = READ16(stUart->intStatus);
165 return (uStatus & RXFIFONE);
168 #if defined (CONFIG_REMOTE_DEBUG)
169 /* Prevent other code from writing to the serial port */
170 void _putc(char c) { }
171 void _puts(const char *ptr) { }
173 /* Low level outputs call prom routines */
177 void _puts(const char *ptr) {