enable start-stop-daemon by default, i want to use this to clean up a few init script...
[openwrt/openwrt.git] / target / linux / brcm63xx-2.6 / files / arch / mips / bcm963xx / ser_init.c
1 /*
2 <:copyright-gpl
3 Copyright 2004 Broadcom Corp. All Rights Reserved.
4
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.
8
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
12 for more details.
13
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.
17 :>
18 */
19 /*
20 * Broadcom bcm63xx serial port initialization, also prepare for printk
21 * by registering with console_init
22 *
23 */
24
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>
32
33 #include <asm/addrspace.h>
34 #include <asm/irq.h>
35 #include <asm/reboot.h>
36 #include <asm/gdb-stub.h>
37 #include <asm/mc146818rtc.h>
38
39 #include <bcm_map_part.h>
40 #include <6348_map_part.h>
41 #include <board.h>
42
43 #define SER63XX_DEFAULT_BAUD 115200
44 #define BD_BCM63XX_TIMER_CLOCK_INPUT (FPERIPH)
45 #define stUart ((volatile Uart * const) UART_BASE)
46
47 // Transmit interrupts
48 #define TXINT (TXFIFOEMT | TXUNDERR | TXOVFERR)
49 // Receive interrupts
50 #define RXINT (RXFIFONE | RXOVFERR)
51
52 /* --------------------------------------------------------------------------
53 Name: serial_init
54 Purpose: Initalize the UART
55 -------------------------------------------------------------------------- */
56 void __init serial_init(void)
57 {
58 u32 tmpVal = SER63XX_DEFAULT_BAUD;
59 ULONG clockFreqHz;
60
61 #if defined(CONFIG_BCM96345)
62 // Make sure clock is ticking
63 PERF->blkEnables |= UART_CLK_EN;
64 #endif
65
66 /* Dissable channel's receiver and transmitter. */
67 stUart->control &= ~(BRGEN|TXEN|RXEN);
68
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;
79 if( tmpVal & 0x01 )
80 tmpVal /= 2; //Rounding up, so sub is already accounted for
81 else
82 tmpVal = (tmpVal / 2) - 1; // Rounding down so we must sub 1
83 stUart->baudword = tmpVal;
84
85 /* Finally, re-enable the transmitter and receiver. */
86 stUart->control |= (BRGEN|TXEN|RXEN);
87
88 stUart->config = (BITS8SYM | ONESTOP);
89 // Set the FIFO interrupt depth ... stUart->fifocfg = 0xAA;
90 stUart->fifoctl = RSTTXFIFOS | RSTRXFIFOS;
91 stUart->intMask = 0;
92 stUart->intMask = RXINT | TXINT;
93 }
94
95
96 /* prom_putc()
97 * Output a character to the UART
98 */
99 void prom_putc(char c)
100 {
101 /* Wait for Tx uffer to empty */
102 while (! (READ16(stUart->intStatus) & TXFIFOEMT));
103 /* Send character */
104 stUart->Data = c;
105 }
106
107 /* prom_puts()
108 * Write a string to the UART
109 */
110 void prom_puts(const char *s)
111 {
112 while (*s) {
113 if (*s == '\n') {
114 prom_putc('\r');
115 }
116 prom_putc(*s++);
117 }
118 }
119
120
121 /* prom_getc_nowait()
122 * Returns a character from the UART
123 * Returns -1 if no characters available or corrupted
124 */
125 int prom_getc_nowait(void)
126 {
127 uint16 uStatus;
128 int cData = -1;
129
130 uStatus = READ16(stUart->intStatus);
131
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 */
135 cData = -1;
136 }
137 }
138
139 return cData;
140 }
141
142 /* prom_getc()
143 * Returns a charcter from the serial port
144 * Will block until it receives a valid character
145 */
146 char prom_getc(void)
147 {
148 int cData = -1;
149
150 /* Loop until we get a valid character */
151 while(cData == -1) {
152 cData = prom_getc_nowait();
153 }
154 return (char) cData;
155 }
156
157 /* prom_testc()
158 * Returns 0 if no characters available
159 */
160 int prom_testc(void)
161 {
162 uint16 uStatus;
163
164 uStatus = READ16(stUart->intStatus);
165
166 return (uStatus & RXFIFONE);
167 }
168
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) { }
173 #else
174 /* Low level outputs call prom routines */
175 void _putc(char c) {
176 prom_putc(c);
177 }
178 void _puts(const char *ptr) {
179 prom_puts(ptr);
180 }
181 #endif