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