]> git.ipfire.org Git - people/ms/u-boot.git/blame - cpu/arm720t/serial_netarm.c
rename CFG_ macros to CONFIG_SYS
[people/ms/u-boot.git] / cpu / arm720t / serial_netarm.c
CommitLineData
2d1a537d
WD
1/*
2 * Serial Port stuff - taken from Linux
3 *
4 * (C) Copyright 2002
5 * MAZeT GmbH <www.mazet.de>
6 * Stephan Linz <linz@mazet.de>, <linz@li-pro.net>
7 *
8 * (c) 2004
9 * IMMS gGmbH <www.imms.de>
10 * Thomas Elste <info@elste.org>
11 *
12 * See file CREDITS for list of people who contributed to this
13 * project.
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 *
29 */
30
31#include <common.h>
2d1a537d
WD
32
33#ifdef CONFIG_NETARM
34
39539887
WD
35#include <asm/hardware.h>
36
d87080b7
WD
37DECLARE_GLOBAL_DATA_PTR;
38
2d1a537d 39#define PORTA (*(volatile unsigned int *)(NETARM_GEN_MODULE_BASE + NETARM_GEN_PORTA))
3df5bea0 40#if !defined(CONFIG_NETARM_NS7520)
2d1a537d 41#define PORTB (*(volatile unsigned int *)(NETARM_GEN_MODULE_BASE + NETARM_GEN_PORTB))
3df5bea0
WD
42#else
43#define PORTC (*(volatile unsigned int *)(NETARM_GEN_MODULE_BASE + NETARM_GEN_PORTC))
44#endif
2d1a537d
WD
45
46/* wait until transmitter is ready for another character */
53677ef1 47#define TXWAITRDY(registers) \
2d1a537d 48{ \
6d0f6bcf 49 ulong tmo = get_timer(0) + 1 * CONFIG_SYS_HZ; \
2d1a537d
WD
50 while (((registers)->status_a & NETARM_SER_STATA_TX_RDY) == 0 ) { \
51 if (get_timer(0) > tmo) \
52 break; \
53 } \
54}
55
56
3df5bea0 57#ifndef CONFIG_UART1_CONSOLE
2d1a537d
WD
58volatile netarm_serial_channel_t *serial_reg_ch1 = get_serial_channel(0);
59volatile netarm_serial_channel_t *serial_reg_ch2 = get_serial_channel(1);
3df5bea0
WD
60#else
61volatile netarm_serial_channel_t *serial_reg_ch1 = get_serial_channel(1);
62volatile netarm_serial_channel_t *serial_reg_ch2 = get_serial_channel(0);
63#endif
2d1a537d
WD
64
65extern void _netarm_led_FAIL1(void);
66
67/*
68 * Setup both serial i/f with given baudrate
69 */
70void serial_setbrg (void)
71{
2d1a537d 72 /* set 0 ... make sure pins are configured for serial */
3df5bea0 73#if !defined(CONFIG_NETARM_NS7520)
2d1a537d
WD
74 PORTA = PORTB =
75 NETARM_GEN_PORT_MODE (0xef) | NETARM_GEN_PORT_DIR (0xe0);
3df5bea0
WD
76#else
77 PORTA = NETARM_GEN_PORT_MODE (0xef) | NETARM_GEN_PORT_DIR (0xe0);
78 PORTC = NETARM_GEN_PORT_CSF (0xef) | NETARM_GEN_PORT_MODE (0xef) | NETARM_GEN_PORT_DIR (0xe0);
79#endif
2d1a537d
WD
80
81 /* first turn em off */
82 serial_reg_ch1->ctrl_a = serial_reg_ch2->ctrl_a = 0;
83
84 /* clear match register, we don't need it */
85 serial_reg_ch1->rx_match = serial_reg_ch2->rx_match = 0;
86
87 /* setup bit rate generator and rx buffer gap timer (1 byte only) */
88 if ((gd->baudrate >= MIN_BAUD_RATE)
89 && (gd->baudrate <= MAX_BAUD_RATE)) {
90 serial_reg_ch1->bitrate = serial_reg_ch2->bitrate =
91 NETARM_SER_BR_X16 (gd->baudrate);
92 serial_reg_ch1->rx_buf_timer = serial_reg_ch2->rx_buf_timer =
93 0;
94 serial_reg_ch1->rx_char_timer = serial_reg_ch2->rx_char_timer =
95 NETARM_SER_RXGAP (gd->baudrate);
96 } else {
97 hang ();
98 }
99
100 /* setup port mode */
101 serial_reg_ch1->ctrl_b = serial_reg_ch2->ctrl_b =
102 ( NETARM_SER_CTLB_RCGT_EN |
103 NETARM_SER_CTLB_UART_MODE);
104 serial_reg_ch1->ctrl_a = serial_reg_ch2->ctrl_a =
105 ( NETARM_SER_CTLA_ENABLE |
106 NETARM_SER_CTLA_P_NONE |
107 /* see errata */
108 NETARM_SER_CTLA_2STOP |
109 NETARM_SER_CTLA_8BITS |
110 NETARM_SER_CTLA_DTR_EN |
111 NETARM_SER_CTLA_RTS_EN);
112}
113
114
115/*
116 * Initialise the serial port with the given baudrate. The settings
117 * are always 8 data bits, no parity, 1 stop bit, no start bits.
118 */
119int serial_init (void)
120{
121 serial_setbrg ();
122 return 0;
123}
124
125
126/*
127 * Output a single byte to the serial port.
128 */
129void serial_putc (const char c)
130{
131 volatile unsigned char *fifo;
132
133 /* If \n, also do \r */
134 if (c == '\n')
135 serial_putc ('\r');
136
137 fifo = (volatile unsigned char *) &(serial_reg_ch1->fifo);
138 TXWAITRDY (serial_reg_ch1);
139 *fifo = c;
140}
141
142/*
143 * Test of a single byte from the serial port. Returns 1 on success, 0
144 * otherwise.
145 */
146int serial_tstc(void)
147{
148 return serial_reg_ch1->status_a & NETARM_SER_STATA_RX_RDY;
149}
150
151/*
152 * Read a single byte from the serial port. Returns 1 on success, 0
153 * otherwise.
154 */
155int serial_getc (void)
156{
157 unsigned int ch_uint;
158 volatile unsigned int *fifo;
159 volatile unsigned char *fifo_char = NULL;
160 int buf_count = 0;
161
162 while (!(serial_reg_ch1->status_a & NETARM_SER_STATA_RX_RDY))
163 /* NOP */ ;
164
165 fifo = (volatile unsigned int *) &(serial_reg_ch1->fifo);
166 fifo_char = (unsigned char *) &ch_uint;
167 ch_uint = *fifo;
168
169 buf_count = NETARM_SER_STATA_RXFDB (serial_reg_ch1->status_a);
170 switch (buf_count) {
171 case NETARM_SER_STATA_RXFDB_4BYTES:
172 buf_count = 4;
173 break;
174 case NETARM_SER_STATA_RXFDB_3BYTES:
175 buf_count = 3;
176 break;
177 case NETARM_SER_STATA_RXFDB_2BYTES:
178 buf_count = 2;
179 break;
180 case NETARM_SER_STATA_RXFDB_1BYTES:
181 buf_count = 1;
182 break;
183 default:
184 /* panic, be never here */
e86e5a07 185 break;
2d1a537d
WD
186 }
187
188 serial_reg_ch1->status_a |= NETARM_SER_STATA_RX_CLOSED;
189
190 return ch_uint & 0xff;
191}
192
193void serial_puts (const char *s)
194{
195 while (*s) {
196 serial_putc (*s++);
197 }
198}
199
200#endif /* CONFIG_NETARM */