]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/xilinx/ml300/serial.c
Merge with /home/m8/git/u-boot
[karo-tx-uboot.git] / board / xilinx / ml300 / serial.c
1 /*
2  *     Author: Xilinx, Inc.
3  *
4  *
5  *     This program is free software; you can redistribute it and/or modify it
6  *     under the terms of the GNU General Public License as published by the
7  *     Free Software Foundation; either version 2 of the License, or (at your
8  *     option) any later version.
9  *
10  *
11  *     XILINX IS PROVIDING THIS DESIGN, CODE, OR INFORMATION "AS IS" AS A
12  *     COURTESY TO YOU. BY PROVIDING THIS DESIGN, CODE, OR INFORMATION AS
13  *     ONE POSSIBLE IMPLEMENTATION OF THIS FEATURE, APPLICATION OR STANDARD,
14  *     XILINX IS MAKING NO REPRESENTATION THAT THIS IMPLEMENTATION IS FREE
15  *     FROM ANY CLAIMS OF INFRINGEMENT, AND YOU ARE RESPONSIBLE FOR OBTAINING
16  *     ANY THIRD PARTY RIGHTS YOU MAY REQUIRE FOR YOUR IMPLEMENTATION.
17  *     XILINX EXPRESSLY DISCLAIMS ANY WARRANTY WHATSOEVER WITH RESPECT TO
18  *     THE ADEQUACY OF THE IMPLEMENTATION, INCLUDING BUT NOT LIMITED TO ANY
19  *     WARRANTIES OR REPRESENTATIONS THAT THIS IMPLEMENTATION IS FREE FROM
20  *     CLAIMS OF INFRINGEMENT, IMPLIED WARRANTIES OF MERCHANTABILITY AND
21  *     FITNESS FOR A PARTICULAR PURPOSE.
22  *
23  *
24  *     Xilinx hardware products are not intended for use in life support
25  *     appliances, devices, or systems. Use in such applications is
26  *     expressly prohibited.
27  *
28  *
29  *     (c) Copyright 2002-2004 Xilinx Inc.
30  *     All rights reserved.
31  *
32  *
33  *     You should have received a copy of the GNU General Public License along
34  *     with this program; if not, write to the Free Software Foundation, Inc.,
35  *     675 Mass Ave, Cambridge, MA 02139, USA.
36  *
37  */
38
39 #include <asm/u-boot.h>
40 #include <asm/processor.h>
41 #include <common.h>
42 #include <command.h>
43 #include <configs/ml300.h>
44 #include "xparameters.h"
45
46 DECLARE_GLOBAL_DATA_PTR;
47
48 #define USE_CHAN1 \
49         ((defined XPAR_UARTNS550_0_BASEADDR) && (defined CFG_INIT_CHAN1))
50 #define USE_CHAN2 \
51         ((defined XPAR_UARTNS550_1_BASEADDR) && (defined CFG_INIT_CHAN2))
52
53 #if USE_CHAN1
54 #include <ns16550.h>
55 #endif
56
57 #if USE_CHAN1
58 const NS16550_t COM_PORTS[] = { (NS16550_t) (XPAR_UARTNS550_0_BASEADDR + 3)
59 #if USE_CHAN2
60             , (NS16550_t) (XPAR_UARTNS550_1_BASEADDR + 3)
61 #endif
62 };
63 #endif
64
65 int
66 serial_init(void)
67 {
68 #if USE_CHAN1
69         int clock_divisor;
70
71         clock_divisor = XPAR_UARTNS550_0_CLOCK_FREQ_HZ / 16 / gd->baudrate;
72         (void) NS16550_init(COM_PORTS[0], clock_divisor);
73 #if USE_CHAN2
74         clock_divisor = XPAR_UARTNS550_1_CLOCK_FREQ_HZ / 16 / gd->baudrate;
75         (void) NS16550_init(COM_PORTS[1], clock_divisor);
76 #endif
77 #endif
78         return 0;
79
80 }
81
82 void
83 serial_putc(const char c)
84 {
85         if (c == '\n')
86                 NS16550_putc(COM_PORTS[CFG_DUART_CHAN], '\r');
87
88         NS16550_putc(COM_PORTS[CFG_DUART_CHAN], c);
89 }
90
91 int
92 serial_getc(void)
93 {
94         return NS16550_getc(COM_PORTS[CFG_DUART_CHAN]);
95 }
96
97 int
98 serial_tstc(void)
99 {
100         return NS16550_tstc(COM_PORTS[CFG_DUART_CHAN]);
101 }
102
103 void
104 serial_setbrg(void)
105 {
106 #if USE_CHAN1
107         int clock_divisor;
108
109         clock_divisor = XPAR_UARTNS550_0_CLOCK_FREQ_HZ / 16 / gd->baudrate;
110         NS16550_reinit(COM_PORTS[0], clock_divisor);
111 #if USE_CHAN2
112         clock_divisor = XPAR_UARTNS550_1_CLOCK_FREQ_HZ / 16 / gd->baudrate;
113         NS16550_reinit(COM_PORTS[1], clock_divisor);
114 #endif
115 #endif
116 }
117
118 void
119 serial_puts(const char *s)
120 {
121         while (*s) {
122                 serial_putc(*s++);
123         }
124 }
125
126 #if (CONFIG_COMMANDS & CFG_CMD_KGDB)
127 void
128 kgdb_serial_init(void)
129 {
130 }
131
132 void
133 putDebugChar(int c)
134 {
135         serial_putc(c);
136 }
137
138 void
139 putDebugStr(const char *str)
140 {
141         serial_puts(str);
142 }
143
144 int
145 getDebugChar(void)
146 {
147         return serial_getc();
148 }
149
150 void
151 kgdb_interruptible(int yes)
152 {
153         return;
154 }
155 #endif                          /* CFG_CMD_KGDB */