]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - cpu/nios2/serial.c
rename CFG_ macros to CONFIG_SYS
[karo-tx-uboot.git] / cpu / nios2 / serial.c
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>
27 #include <asm/io.h>
28 #include <nios2-io.h>
29
30 DECLARE_GLOBAL_DATA_PTR;
31
32 /*------------------------------------------------------------------
33  * JTAG acts as the serial port
34  *-----------------------------------------------------------------*/
35 #if defined(CONFIG_CONSOLE_JTAG)
36
37 static nios_jtag_t *jtag = (nios_jtag_t *)CONFIG_SYS_NIOS_CONSOLE;
38
39 void serial_setbrg( void ){ return; }
40 int serial_init( void ) { return(0);}
41
42 void serial_putc (char c)
43 {
44         unsigned val;
45
46         while (NIOS_JTAG_WSPACE ( readl (&jtag->control)) == 0)
47                 WATCHDOG_RESET ();
48         writel (&jtag->data, (unsigned char)c);
49 }
50
51 void serial_puts (const char *s)
52 {
53         while (*s != 0)
54                 serial_putc (*s++);
55 }
56
57 int serial_tstc (void)
58 {
59         return ( readl (&jtag->control) & NIOS_JTAG_RRDY);
60 }
61
62 int serial_getc (void)
63 {
64         int c;
65         unsigned val;
66
67         while (1) {
68                 WATCHDOG_RESET ();
69                 val = readl (&jtag->data);
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
82 static nios_uart_t *uart = (nios_uart_t *) CONFIG_SYS_NIOS_CONSOLE;
83
84 #if defined(CONFIG_SYS_NIOS_FIXEDBAUD)
85
86 /* Everything's already setup for fixed-baud PTF
87  * assignment
88  */
89 void serial_setbrg (void){ return; }
90 int serial_init (void) { return (0);}
91
92 #else
93
94 void serial_setbrg (void)
95 {
96         unsigned div;
97
98         div = (CONFIG_SYS_CLK_FREQ/gd->baudrate)-1;
99         writel (&uart->divisor,div);
100         return;
101 }
102
103 int serial_init (void)
104 {
105         serial_setbrg ();
106         return (0);
107 }
108
109 #endif /* CONFIG_SYS_NIOS_FIXEDBAUD */
110
111
112 /*-----------------------------------------------------------------------
113  * UART CONSOLE
114  *---------------------------------------------------------------------*/
115 void serial_putc (char c)
116 {
117         if (c == '\n')
118                 serial_putc ('\r');
119         while ((readl (&uart->status) & NIOS_UART_TRDY) == 0)
120                 WATCHDOG_RESET ();
121         writel (&uart->txdata,(unsigned char)c);
122 }
123
124 void serial_puts (const char *s)
125 {
126         while (*s != 0) {
127                 serial_putc (*s++);
128         }
129 }
130
131 int serial_tstc (void)
132 {
133         return (readl (&uart->status) & NIOS_UART_RRDY);
134 }
135
136 int serial_getc (void)
137 {
138         while (serial_tstc () == 0)
139                 WATCHDOG_RESET ();
140         return (readl (&uart->rxdata) & 0x00ff );
141 }
142
143 #endif /* CONFIG_JTAG_CONSOLE */