1 /* GRLIB APBUART Serial controller driver
4 * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com.
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>
31 DECLARE_GLOBAL_DATA_PTR
;
33 /* Force cache miss each time a serial controller reg is read */
34 #define CACHE_BYPASS 1
37 #define READ_BYTE(var) SPARC_NOCACHE_READ_BYTE((unsigned int)&(var))
38 #define READ_HWORD(var) SPARC_NOCACHE_READ_HWORD((unsigned int)&(var))
39 #define READ_WORD(var) SPARC_NOCACHE_READ((unsigned int)&(var))
40 #define READ_DWORD(var) SPARC_NOCACHE_READ_DWORD((unsigned int)&(var))
43 ambapp_dev_apbuart
*leon3_apbuart
= NULL
;
51 if (ambapp_apb_first(VENDOR_GAISLER
, GAISLER_APBUART
, &apbdev
) == 1) {
53 leon3_apbuart
= (ambapp_dev_apbuart
*) apbdev
.address
;
55 /* found apbuart, let's init...
57 * Set scaler / baud rate
59 * Receiver & transmitter enable
61 leon3_apbuart
->scaler
= CONFIG_SYS_GRLIB_APBUART_SCALER
;
63 /* Let bit 11 be unchanged (debug bit for GRMON) */
64 tmp
= READ_WORD(leon3_apbuart
->ctrl
);
66 leon3_apbuart
->ctrl
= ((tmp
& LEON_REG_UART_CTRL_DBG
) |
67 LEON_REG_UART_CTRL_RE
|
68 LEON_REG_UART_CTRL_TE
);
72 return -1; /* didn't find hardware */
75 void serial_putc(const char c
)
78 serial_putc_raw('\r');
83 void serial_putc_raw(const char c
)
88 /* Wait for last character to go. */
89 while (!(READ_WORD(leon3_apbuart
->status
) & LEON_REG_UART_STATUS_THE
)) ;
92 leon3_apbuart
->data
= c
;
95 /* Wait for data to be sent */
96 while (!(READ_WORD(leon3_apbuart
->status
) & LEON_REG_UART_STATUS_TSE
)) ;
100 void serial_puts(const char *s
)
107 int serial_getc(void)
112 /* Wait for a character to arrive. */
113 while (!(READ_WORD(leon3_apbuart
->status
) & LEON_REG_UART_STATUS_DR
)) ;
116 return READ_WORD(leon3_apbuart
->data
);
119 int serial_tstc(void)
122 return (READ_WORD(leon3_apbuart
->status
) &
123 LEON_REG_UART_STATUS_DR
);
127 /* set baud rate for uart */
128 void serial_setbrg(void)
130 /* update baud rate settings, read it from gd->baudrate */
132 if (leon3_apbuart
&& (gd
->baudrate
> 0)) {
134 (((CONFIG_SYS_CLK_FREQ
* 10) / (gd
->baudrate
* 8)) -
136 leon3_apbuart
->scaler
= scaler
;