]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - board/Marvell/common/serial.c
socfpga: Move board/socfpga_cyclone5 to board/socfpga
[karo-tx-uboot.git] / board / Marvell / common / serial.c
1 /*
2  * (C) Copyright 2001
3  * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
4  *
5  * modified for marvell db64360 eval board by
6  * Ingo Assmus <ingo.assmus@keymile.com>
7  *
8  * See file CREDITS for list of people who contributed to this
9  * project.
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License as
13  * published by the Free Software Foundation; either version 2 of
14  * the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
24  * MA 02111-1307 USA
25  */
26
27 /*
28  * serial.c - serial support for the gal ev board
29  */
30
31 /* supports both the 16650 duart and the MPSC */
32
33 #include <common.h>
34 #include <command.h>
35 #include <serial.h>
36 #include <linux/compiler.h>
37
38 #include "../include/memory.h"
39 #include "serial.h"
40
41 #ifdef CONFIG_DB64360
42 #include "../db64360/mpsc.h"
43 #endif
44
45 #ifdef CONFIG_DB64460
46 #include "../db64460/mpsc.h"
47 #endif
48
49 #include "ns16550.h"
50
51 DECLARE_GLOBAL_DATA_PTR;
52
53 #ifdef CONFIG_MPSC
54 static int marvell_serial_init(void)
55 {
56 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
57         int clock_divisor = 230400 / gd->baudrate;
58 #endif
59
60         mpsc_init (gd->baudrate);
61
62         /* init the DUART chans so that KGDB in the kernel can use them */
63 #ifdef CONFIG_SYS_INIT_CHAN1
64         NS16550_reinit (COM_PORTS[0], clock_divisor);
65 #endif
66 #ifdef CONFIG_SYS_INIT_CHAN2
67         NS16550_reinit (COM_PORTS[1], clock_divisor);
68 #endif
69         return (0);
70 }
71
72 static void marvell_serial_putc(const char c)
73 {
74         if (c == '\n')
75                 mpsc_putchar ('\r');
76
77         mpsc_putchar (c);
78 }
79
80 static int marvell_serial_getc(void)
81 {
82         return mpsc_getchar ();
83 }
84
85 static int marvell_serial_tstc(void)
86 {
87         return mpsc_test_char ();
88 }
89
90 static void marvell_serial_setbrg(void)
91 {
92         galbrg_set_baudrate (CONFIG_MPSC_PORT, gd->baudrate);
93 }
94
95 #else  /* ! CONFIG_MPSC */
96
97 static int marvell_serial_init(void)
98 {
99         int clock_divisor = 230400 / gd->baudrate;
100
101 #ifdef CONFIG_SYS_INIT_CHAN1
102         (void) NS16550_init (0, clock_divisor);
103 #endif
104 #ifdef CONFIG_SYS_INIT_CHAN2
105         (void) NS16550_init (1, clock_divisor);
106 #endif
107         return (0);
108 }
109
110 static void marvell_serial_putc(const char c)
111 {
112         if (c == '\n')
113                 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
114
115         NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
116 }
117
118 static int marvell_serial_getc(void)
119 {
120         return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
121 }
122
123 static int marvell_serial_tstc(void)
124 {
125         return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
126 }
127
128 static void marvell_serial_setbrg(void)
129 {
130         int clock_divisor = 230400 / gd->baudrate;
131
132 #ifdef CONFIG_SYS_INIT_CHAN1
133         NS16550_reinit (COM_PORTS[0], clock_divisor);
134 #endif
135 #ifdef CONFIG_SYS_INIT_CHAN2
136         NS16550_reinit (COM_PORTS[1], clock_divisor);
137 #endif
138 }
139
140 #endif /* CONFIG_MPSC */
141
142 static struct serial_device marvell_serial_drv = {
143         .name   = "marvell_serial",
144         .start  = marvell_serial_init,
145         .stop   = NULL,
146         .setbrg = marvell_serial_setbrg,
147         .putc   = marvell_serial_putc,
148         .puts   = default_serial_puts,
149         .getc   = marvell_serial_getc,
150         .tstc   = marvell_serial_tstc,
151 };
152
153 void marvell_serial_initialize(void)
154 {
155         serial_register(&marvell_serial_drv);
156 }
157
158 __weak struct serial_device *default_serial_console(void)
159 {
160         return &marvell_serial_drv;
161 }
162
163 #if defined(CONFIG_CMD_KGDB)
164 void kgdb_serial_init (void)
165 {
166 }
167
168 void putDebugChar (int c)
169 {
170         serial_putc (c);
171 }
172
173 void putDebugStr (const char *str)
174 {
175         serial_puts (str);
176 }
177
178 int getDebugChar (void)
179 {
180         return serial_getc ();
181 }
182
183 void kgdb_interruptible (int yes)
184 {
185         return;
186 }
187 #endif