blob: 3081fad21a7501781a7e257d62bc160380a2646f [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/*
2 * (C) Copyright 2001
3 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
4 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkc6097192002-11-03 00:24:07 +00006 */
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>
Marek Vasutadede692012-09-13 12:33:50 +020017#include <serial.h>
18#include <linux/compiler.h>
wdenkc6097192002-11-03 00:24:07 +000019
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020020#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
wdenkc6097192002-11-03 00:24:07 +000021#include <ns16550.h>
22#endif
23
24#include "serial.h"
25
26#include "mpsc.h"
27
Wolfgang Denk6405a152006-03-31 18:32:53 +020028DECLARE_GLOBAL_DATA_PTR;
29
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020030#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 };
wdenkc6097192002-11-03 00:24:07 +000033#endif
34
35#ifdef CONFIG_MPSC
36
Marek Vasutadede692012-09-13 12:33:50 +020037static int evb64260_serial_init(void)
wdenkc6097192002-11-03 00:24:07 +000038{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020039#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
40 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
wdenkc6097192002-11-03 00:24:07 +000041#endif
42
43 mpsc_init(gd->baudrate);
44
45 /* init the DUART chans so that KGDB in the kernel can use them */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020046#ifdef CONFIG_SYS_INIT_CHAN1
wdenkc6097192002-11-03 00:24:07 +000047 NS16550_reinit(COM_PORTS[0], clock_divisor);
48#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020049#ifdef CONFIG_SYS_INIT_CHAN2
wdenkc6097192002-11-03 00:24:07 +000050 NS16550_reinit(COM_PORTS[1], clock_divisor);
51#endif
52 return (0);
53}
54
Marek Vasutadede692012-09-13 12:33:50 +020055static void evb64260_serial_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +000056{
57 if (c == '\n')
58 mpsc_putchar('\r');
59
60 mpsc_putchar(c);
61}
62
Marek Vasutadede692012-09-13 12:33:50 +020063static int evb64260_serial_getc(void)
wdenkc6097192002-11-03 00:24:07 +000064{
65 return mpsc_getchar();
66}
67
Marek Vasutadede692012-09-13 12:33:50 +020068static int evb64260_serial_tstc(void)
wdenkc6097192002-11-03 00:24:07 +000069{
70 return mpsc_test_char();
71}
72
Marek Vasutadede692012-09-13 12:33:50 +020073static void evb64260_serial_setbrg(void)
wdenkc6097192002-11-03 00:24:07 +000074{
wdenkc6097192002-11-03 00:24:07 +000075 galbrg_set_baudrate(CONFIG_MPSC_PORT, gd->baudrate);
76}
77
78#else /* ! CONFIG_MPSC */
79
Marek Vasutadede692012-09-13 12:33:50 +020080static int evb64260_serial_init(void)
wdenkc6097192002-11-03 00:24:07 +000081{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020082 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
wdenkc6097192002-11-03 00:24:07 +000083
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020084#ifdef CONFIG_SYS_INIT_CHAN1
wdenkc6097192002-11-03 00:24:07 +000085 (void)NS16550_init(COM_PORTS[0], clock_divisor);
86#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020087#ifdef CONFIG_SYS_INIT_CHAN2
wdenkc6097192002-11-03 00:24:07 +000088 (void)NS16550_init(COM_PORTS[1], clock_divisor);
89#endif
90
91 return (0);
92}
93
Marek Vasutadede692012-09-13 12:33:50 +020094static void evb64260_serial_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +000095{
96 if (c == '\n')
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020097 NS16550_putc(COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
wdenkc6097192002-11-03 00:24:07 +000098
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020099 NS16550_putc(COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
wdenkc6097192002-11-03 00:24:07 +0000100}
101
Marek Vasutadede692012-09-13 12:33:50 +0200102static int evb64260_serial_getc(void)
wdenkc6097192002-11-03 00:24:07 +0000103{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200104 return NS16550_getc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
wdenkc6097192002-11-03 00:24:07 +0000105}
106
Marek Vasutadede692012-09-13 12:33:50 +0200107static int evb64260_serial_tstc(void)
wdenkc6097192002-11-03 00:24:07 +0000108{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200109 return NS16550_tstc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
wdenkc6097192002-11-03 00:24:07 +0000110}
111
Marek Vasutadede692012-09-13 12:33:50 +0200112static void evb64260_serial_setbrg(void)
wdenkc6097192002-11-03 00:24:07 +0000113{
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200114 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
wdenkc6097192002-11-03 00:24:07 +0000115
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200116#ifdef CONFIG_SYS_INIT_CHAN1
wdenkc6097192002-11-03 00:24:07 +0000117 NS16550_reinit(COM_PORTS[0], clock_divisor);
118#endif
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200119#ifdef CONFIG_SYS_INIT_CHAN2
wdenkc6097192002-11-03 00:24:07 +0000120 NS16550_reinit(COM_PORTS[1], clock_divisor);
121#endif
122}
123
124#endif /* CONFIG_MPSC */
125
Marek Vasutadede692012-09-13 12:33:50 +0200126static 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,
Marek Vasutd9c64492012-10-06 14:07:02 +0000132 .puts = default_serial_puts,
Marek Vasutadede692012-09-13 12:33:50 +0200133 .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}
Marek Vasutadede692012-09-13 12:33:50 +0200146
Jon Loeliger4ed9ed62007-07-09 18:24:55 -0500147#if defined(CONFIG_CMD_KGDB)
wdenkc6097192002-11-03 00:24:07 +0000148void
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}
Jon Loeliger13f75992007-07-10 10:39:10 -0500176#endif