]> git.ipfire.org Git - people/ms/u-boot.git/blame - cpu/nios2/serial.c
rename CFG_ macros to CONFIG_SYS
[people/ms/u-boot.git] / cpu / nios2 / serial.c
CommitLineData
5c952cf0
WD
1/*
2 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
3 * Scott McNutt <smcnutt@psyent.com>
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
24
25#include <common.h>
26#include <watchdog.h>
c2ced000 27#include <asm/io.h>
5c952cf0
WD
28#include <nios2-io.h>
29
d87080b7
WD
30DECLARE_GLOBAL_DATA_PTR;
31
5c952cf0
WD
32/*------------------------------------------------------------------
33 * JTAG acts as the serial port
34 *-----------------------------------------------------------------*/
35#if defined(CONFIG_CONSOLE_JTAG)
36
6d0f6bcf 37static nios_jtag_t *jtag = (nios_jtag_t *)CONFIG_SYS_NIOS_CONSOLE;
5c952cf0
WD
38
39void serial_setbrg( void ){ return; }
40int serial_init( void ) { return(0);}
41
42void serial_putc (char c)
43{
44 unsigned val;
45
c2ced000 46 while (NIOS_JTAG_WSPACE ( readl (&jtag->control)) == 0)
5c952cf0 47 WATCHDOG_RESET ();
c2ced000 48 writel (&jtag->data, (unsigned char)c);
5c952cf0
WD
49}
50
51void serial_puts (const char *s)
52{
53 while (*s != 0)
54 serial_putc (*s++);
55}
56
57int serial_tstc (void)
58{
c2ced000 59 return ( readl (&jtag->control) & NIOS_JTAG_RRDY);
5c952cf0
WD
60}
61
62int serial_getc (void)
63{
64 int c;
65 unsigned val;
66
67 while (1) {
68 WATCHDOG_RESET ();
c2ced000 69 val = readl (&jtag->data);
5c952cf0
WD
70 if (val & NIOS_JTAG_RVALID)
71 break;
72 }
73 c = val & 0x0ff;
74 return (c);
75}
76
77/*------------------------------------------------------------------
78 * UART the serial port
79 *-----------------------------------------------------------------*/
80#else
81
6d0f6bcf 82static nios_uart_t *uart = (nios_uart_t *) CONFIG_SYS_NIOS_CONSOLE;
5c952cf0 83
6d0f6bcf 84#if defined(CONFIG_SYS_NIOS_FIXEDBAUD)
5c952cf0
WD
85
86/* Everything's already setup for fixed-baud PTF
87 * assignment
88 */
89void serial_setbrg (void){ return; }
90int serial_init (void) { return (0);}
91
92#else
93
94void serial_setbrg (void)
95{
5c952cf0
WD
96 unsigned div;
97
98 div = (CONFIG_SYS_CLK_FREQ/gd->baudrate)-1;
c2ced000 99 writel (&uart->divisor,div);
5c952cf0
WD
100 return;
101}
102
103int serial_init (void)
104{
105 serial_setbrg ();
106 return (0);
107}
108
6d0f6bcf 109#endif /* CONFIG_SYS_NIOS_FIXEDBAUD */
5c952cf0
WD
110
111
112/*-----------------------------------------------------------------------
113 * UART CONSOLE
114 *---------------------------------------------------------------------*/
115void serial_putc (char c)
116{
117 if (c == '\n')
118 serial_putc ('\r');
c2ced000 119 while ((readl (&uart->status) & NIOS_UART_TRDY) == 0)
5c952cf0 120 WATCHDOG_RESET ();
c2ced000 121 writel (&uart->txdata,(unsigned char)c);
5c952cf0
WD
122}
123
124void serial_puts (const char *s)
125{
126 while (*s != 0) {
127 serial_putc (*s++);
128 }
129}
130
131int serial_tstc (void)
132{
c2ced000 133 return (readl (&uart->status) & NIOS_UART_RRDY);
5c952cf0
WD
134}
135
136int serial_getc (void)
137{
138 while (serial_tstc () == 0)
139 WATCHDOG_RESET ();
c2ced000 140 return (readl (&uart->rxdata) & 0x00ff );
5c952cf0
WD
141}
142
143#endif /* CONFIG_JTAG_CONSOLE */