Merge branch 'origin'
[platform/kernel/u-boot.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 #define USE_CHAN1 \
47         ((defined XPAR_UARTNS550_0_BASEADDR) && (defined CFG_INIT_CHAN1))
48 #define USE_CHAN2 \
49         ((defined XPAR_UARTNS550_1_BASEADDR) && (defined CFG_INIT_CHAN2))
50
51 #if USE_CHAN1
52 #include <ns16550.h>
53 #endif
54
55 #if USE_CHAN1
56 const NS16550_t COM_PORTS[] = { (NS16550_t) (XPAR_UARTNS550_0_BASEADDR + 3)
57 #if USE_CHAN2
58             , (NS16550_t) (XPAR_UARTNS550_1_BASEADDR + 3)
59 #endif
60 };
61 #endif
62
63 int
64 serial_init(void)
65 {
66 #if USE_CHAN1
67         DECLARE_GLOBAL_DATA_PTR;
68         int clock_divisor;
69
70         clock_divisor = XPAR_UARTNS550_0_CLOCK_FREQ_HZ / 16 / gd->baudrate;
71         (void) NS16550_init(COM_PORTS[0], clock_divisor);
72 #if USE_CHAN2
73         clock_divisor = XPAR_UARTNS550_1_CLOCK_FREQ_HZ / 16 / gd->baudrate;
74         (void) NS16550_init(COM_PORTS[1], clock_divisor);
75 #endif
76 #endif
77         return 0;
78
79 }
80
81 void
82 serial_putc(const char c)
83 {
84         if (c == '\n')
85                 NS16550_putc(COM_PORTS[CFG_DUART_CHAN], '\r');
86
87         NS16550_putc(COM_PORTS[CFG_DUART_CHAN], c);
88 }
89
90 int
91 serial_getc(void)
92 {
93         return NS16550_getc(COM_PORTS[CFG_DUART_CHAN]);
94 }
95
96 int
97 serial_tstc(void)
98 {
99         return NS16550_tstc(COM_PORTS[CFG_DUART_CHAN]);
100 }
101
102 void
103 serial_setbrg(void)
104 {
105 #if USE_CHAN1
106         DECLARE_GLOBAL_DATA_PTR;
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 */