summaryrefslogtreecommitdiffstats
path: root/target/linux/brcm63xx-2.6/files/arch/mips/bcm963xx/ser_init.c
blob: bb745aec6edbac4bdd7dd8347d95c6cbf57a47f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
<:copyright-gpl 
 Copyright 2004 Broadcom Corp. All Rights Reserved. 
 
 This program is free software; you can distribute it and/or modify it 
 under the terms of the GNU General Public License (Version 2) as 
 published by the Free Software Foundation. 
 
 This program is distributed in the hope it will be useful, but WITHOUT 
 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License 
 for more details. 
 
 You should have received a copy of the GNU General Public License along 
 with this program; if not, write to the Free Software Foundation, Inc., 
 59 Temple Place - Suite 330, Boston MA 02111-1307, USA. 
:>
*/
/*
 *  Broadcom bcm63xx serial port initialization, also prepare for printk
 *  by registering with console_init
 *   
 */

#include <linux/autoconf.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/kernel.h>
#include <linux/types.h>
#include <linux/console.h>
#include <linux/sched.h>

#include <asm/addrspace.h>
#include <asm/irq.h>
#include <asm/reboot.h>
#include <asm/gdb-stub.h>
#include <asm/mc146818rtc.h> 

#include <bcm_map_part.h>
#include <6348_map_part.h>
#include <board.h>

#define  SER63XX_DEFAULT_BAUD      115200
#define BD_BCM63XX_TIMER_CLOCK_INPUT    (FPERIPH)
#define stUart ((volatile Uart * const) UART_BASE)

// Transmit interrupts
#define TXINT       (TXFIFOEMT | TXUNDERR | TXOVFERR)
// Receive interrupts
#define RXINT       (RXFIFONE | RXOVFERR)

/* --------------------------------------------------------------------------
    Name: serial_init
 Purpose: Initalize the UART
-------------------------------------------------------------------------- */
void __init serial_init(void)
{
    u32 tmpVal = SER63XX_DEFAULT_BAUD;
    ULONG clockFreqHz;    

#if defined(CONFIG_BCM96345)
    // Make sure clock is ticking
    PERF->blkEnables |= UART_CLK_EN;
#endif
		
    /* Dissable channel's receiver and transmitter.                */
    stUart->control &= ~(BRGEN|TXEN|RXEN);
		
    /*--------------------------------------------------------------------*/
    /* Write the table value to the clock select register.                */
    /* DPullen - this is the equation to use:                             */
    /*       value = clockFreqHz / baud / 32-1;                           */
    /*   (snmod) Actually you should also take into account any necessary */
    /*           rounding.  Divide by 16, look at lsb, if 0, divide by 2  */
    /*           and subtract 1.  If 1, just divide by 2                  */
    /*--------------------------------------------------------------------*/
    clockFreqHz = BD_BCM63XX_TIMER_CLOCK_INPUT;
    tmpVal = (clockFreqHz / tmpVal) / 16;
    if( tmpVal & 0x01 )
        tmpVal /= 2;  //Rounding up, so sub is already accounted for
    else
        tmpVal = (tmpVal / 2) - 1; // Rounding down so we must sub 1
    stUart->baudword = tmpVal;
        
    /* Finally, re-enable the transmitter and receiver.            */
    stUart->control |= (BRGEN|TXEN|RXEN);

    stUart->config   = (BITS8SYM | ONESTOP);
    // Set the FIFO interrupt depth ... stUart->fifocfg  = 0xAA;
    stUart->fifoctl  =  RSTTXFIFOS | RSTRXFIFOS;
    stUart->intMask  = 0;       
    stUart->intMask = RXINT | TXINT;
}


/* prom_putc()
 * Output a character to the UART
 */
void prom_putc(char c)
{
	/* Wait for Tx uffer to empty */
	while (! (READ16(stUart->intStatus) & TXFIFOEMT));
	/* Send character */
	stUart->Data = c;
}

/* prom_puts()
 * Write a string to the UART
 */
void prom_puts(const char *s)
{
	while (*s) {
		if (*s == '\n') {
			prom_putc('\r');
		}
		prom_putc(*s++);
	}
}


/* prom_getc_nowait()
 * Returns a character from the UART
 * Returns -1 if no characters available or corrupted
 */
int prom_getc_nowait(void)
{
    uint16  uStatus;
    int    cData = -1;

     uStatus = READ16(stUart->intStatus);

     if (uStatus & RXFIFONE) { /* Do we have a character? */
           cData =  READ16(stUart->Data) & 0xff; /* Read character */
           if (uStatus & (RXFRAMERR | RXPARERR)) {  /* If we got an error, throw it away */
               cData = -1;
           }
  }

   return cData;
}

/* prom_getc()
 * Returns a charcter from the serial port
 * Will block until it receives a valid character
*/
char prom_getc(void)
{
    int    cData = -1;

    /* Loop until we get a valid character */
    while(cData == -1) {
	cData = prom_getc_nowait();
    }
   return (char) cData;
}

/* prom_testc()
 * Returns 0 if no characters available
 */
int prom_testc(void)
{
    uint16  uStatus;

     uStatus = READ16(stUart->intStatus);

     return (uStatus & RXFIFONE);
}

#if defined (CONFIG_REMOTE_DEBUG)
/* Prevent other code from writing to the serial port */
void _putc(char c) { }
void _puts(const char *ptr) { }
#else
/* Low level outputs call prom routines */
void _putc(char c) {
	prom_putc(c);
}
void _puts(const char *ptr) {
	prom_puts(ptr);
}
#endif