]> git.ipfire.org Git - people/ms/u-boot.git/blob - board/evb64260/serial.c
Add GPL-2.0+ SPDX-License-Identifier to source files
[people/ms/u-boot.git] / board / evb64260 / serial.c
1 /*
2 * (C) Copyright 2001
3 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
4 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8 /*
9 * serial.c - serial support for the gal ev board
10 */
11
12 /* supports both the 16650 duart and the MPSC */
13
14 #include <common.h>
15 #include <command.h>
16 #include <galileo/memory.h>
17 #include <serial.h>
18 #include <linux/compiler.h>
19
20 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
21 #include <ns16550.h>
22 #endif
23
24 #include "serial.h"
25
26 #include "mpsc.h"
27
28 DECLARE_GLOBAL_DATA_PTR;
29
30 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
31 const NS16550_t COM_PORTS[] = { (NS16550_t) CONFIG_SYS_NS16550_COM1,
32 (NS16550_t) CONFIG_SYS_NS16550_COM2 };
33 #endif
34
35 #ifdef CONFIG_MPSC
36
37 static int evb64260_serial_init(void)
38 {
39 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
40 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
41 #endif
42
43 mpsc_init(gd->baudrate);
44
45 /* init the DUART chans so that KGDB in the kernel can use them */
46 #ifdef CONFIG_SYS_INIT_CHAN1
47 NS16550_reinit(COM_PORTS[0], clock_divisor);
48 #endif
49 #ifdef CONFIG_SYS_INIT_CHAN2
50 NS16550_reinit(COM_PORTS[1], clock_divisor);
51 #endif
52 return (0);
53 }
54
55 static void evb64260_serial_putc(const char c)
56 {
57 if (c == '\n')
58 mpsc_putchar('\r');
59
60 mpsc_putchar(c);
61 }
62
63 static int evb64260_serial_getc(void)
64 {
65 return mpsc_getchar();
66 }
67
68 static int evb64260_serial_tstc(void)
69 {
70 return mpsc_test_char();
71 }
72
73 static void evb64260_serial_setbrg(void)
74 {
75 galbrg_set_baudrate(CONFIG_MPSC_PORT, gd->baudrate);
76 }
77
78 #else /* ! CONFIG_MPSC */
79
80 static int evb64260_serial_init(void)
81 {
82 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
83
84 #ifdef CONFIG_SYS_INIT_CHAN1
85 (void)NS16550_init(COM_PORTS[0], clock_divisor);
86 #endif
87 #ifdef CONFIG_SYS_INIT_CHAN2
88 (void)NS16550_init(COM_PORTS[1], clock_divisor);
89 #endif
90
91 return (0);
92 }
93
94 static void evb64260_serial_putc(const char c)
95 {
96 if (c == '\n')
97 NS16550_putc(COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
98
99 NS16550_putc(COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
100 }
101
102 static int evb64260_serial_getc(void)
103 {
104 return NS16550_getc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
105 }
106
107 static int evb64260_serial_tstc(void)
108 {
109 return NS16550_tstc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
110 }
111
112 static void evb64260_serial_setbrg(void)
113 {
114 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
115
116 #ifdef CONFIG_SYS_INIT_CHAN1
117 NS16550_reinit(COM_PORTS[0], clock_divisor);
118 #endif
119 #ifdef CONFIG_SYS_INIT_CHAN2
120 NS16550_reinit(COM_PORTS[1], clock_divisor);
121 #endif
122 }
123
124 #endif /* CONFIG_MPSC */
125
126 static struct serial_device evb64260_serial_drv = {
127 .name = "evb64260_serial",
128 .start = evb64260_serial_init,
129 .stop = NULL,
130 .setbrg = evb64260_serial_setbrg,
131 .putc = evb64260_serial_putc,
132 .puts = default_serial_puts,
133 .getc = evb64260_serial_getc,
134 .tstc = evb64260_serial_tstc,
135 };
136
137 void evb64260_serial_initialize(void)
138 {
139 serial_register(&evb64260_serial_drv);
140 }
141
142 __weak struct serial_device *default_serial_console(void)
143 {
144 return &evb64260_serial_drv;
145 }
146
147 #if defined(CONFIG_CMD_KGDB)
148 void
149 kgdb_serial_init(void)
150 {
151 }
152
153 void
154 putDebugChar (int c)
155 {
156 serial_putc (c);
157 }
158
159 void
160 putDebugStr (const char *str)
161 {
162 serial_puts (str);
163 }
164
165 int
166 getDebugChar (void)
167 {
168 return serial_getc();
169 }
170
171 void
172 kgdb_interruptible (int yes)
173 {
174 return;
175 }
176 #endif