1 /* GRLIB APBUART Serial controller driver
6 * See file CREDITS for list of people who contributed to this
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
27 #include <asm/processor.h>
30 DECLARE_GLOBAL_DATA_PTR;
32 /* Force cache miss each time a serial controller reg is read */
33 #define CACHE_BYPASS 1
36 #define READ_BYTE(var) SPARC_NOCACHE_READ_BYTE((unsigned int)&(var))
37 #define READ_HWORD(var) SPARC_NOCACHE_READ_HWORD((unsigned int)&(var))
38 #define READ_WORD(var) SPARC_NOCACHE_READ((unsigned int)&(var))
39 #define READ_DWORD(var) SPARC_NOCACHE_READ_DWORD((unsigned int)&(var))
44 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
45 LEON2_Uart_regs *regs;
50 * Set scaler / baud rate
52 * Receiver & transmitter enable
54 #if LEON2_CONSOLE_SELECT == LEON_CONSOLE_UART1
55 regs = (LEON2_Uart_regs *) & leon2->UART_Channel_1;
57 regs = (LEON2_Uart_regs *) & leon2->UART_Channel_2;
60 regs->UART_Scaler = CONFIG_SYS_LEON2_UART1_SCALER;
62 /* Let bit 11 be unchanged (debug bit for GRMON) */
63 tmp = READ_WORD(regs->UART_Control);
65 regs->UART_Control = ((tmp & LEON2_UART_CTRL_DBG) |
66 (LEON2_UART1_LOOPBACK_ENABLE << 7) |
67 (LEON2_UART1_FLOWCTRL_ENABLE << 6) |
68 (LEON2_UART1_PARITY_ENABLE << 5) |
69 (LEON2_UART1_ODDPAR_ENABLE << 4) |
70 LEON2_UART_CTRL_RE | LEON2_UART_CTRL_TE);
75 void serial_putc(const char c)
78 serial_putc_raw('\r');
83 void serial_putc_raw(const char c)
85 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
86 LEON2_Uart_regs *regs;
88 #if LEON2_CONSOLE_SELECT == LEON_CONSOLE_UART1
89 regs = (LEON2_Uart_regs *) & leon2->UART_Channel_1;
91 regs = (LEON2_Uart_regs *) & leon2->UART_Channel_2;
94 /* Wait for last character to go. */
95 while (!(READ_WORD(regs->UART_Status) & LEON2_UART_STAT_THE)) ;
98 regs->UART_Channel = c;
101 /* Wait for data to be sent */
102 while (!(READ_WORD(regs->UART_Status) & LEON2_UART_STAT_TSE)) ;
106 void serial_puts(const char *s)
113 int serial_getc(void)
115 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
116 LEON2_Uart_regs *regs;
118 #if LEON2_CONSOLE_SELECT == LEON_CONSOLE_UART1
119 regs = (LEON2_Uart_regs *) & leon2->UART_Channel_1;
121 regs = (LEON2_Uart_regs *) & leon2->UART_Channel_2;
124 /* Wait for a character to arrive. */
125 while (!(READ_WORD(regs->UART_Status) & LEON2_UART_STAT_DR)) ;
128 return READ_WORD(regs->UART_Channel);
131 int serial_tstc(void)
133 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
134 LEON2_Uart_regs *regs;
136 #if LEON2_CONSOLE_SELECT == LEON_CONSOLE_UART1
137 regs = (LEON2_Uart_regs *) & leon2->UART_Channel_1;
139 regs = (LEON2_Uart_regs *) & leon2->UART_Channel_2;
142 return (READ_WORD(regs->UART_Status) & LEON2_UART_STAT_DR);
145 /* set baud rate for uart */
146 void serial_setbrg(void)
148 /* update baud rate settings, read it from gd->baudrate */
150 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
151 LEON2_Uart_regs *regs;
153 #if LEON2_CONSOLE_SELECT == LEON_CONSOLE_UART1
154 regs = (LEON2_Uart_regs *) & leon2->UART_Channel_1;
156 regs = (LEON2_Uart_regs *) & leon2->UART_Channel_2;
159 if (gd->baudrate > 0) {
161 (((CONFIG_SYS_CLK_FREQ * 10) / (gd->baudrate * 8)) -
163 regs->UART_Scaler = scaler;