blob: 83a421708bdfd746360fa538c0cb969e4003bdc4 [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 Denk1a459662013-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 Vasut829b3b22012-09-13 12:33:50 +020017#include <serial.h>
18#include <linux/compiler.h>
wdenkc6097192002-11-03 00:24:07 +000019
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-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
wdenkc6097192002-11-03 00:24:07 +000024#include "mpsc.h"
25
Wolfgang Denkd87080b2006-03-31 18:32:53 +020026DECLARE_GLOBAL_DATA_PTR;
27
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020028#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
29const NS16550_t COM_PORTS[] = { (NS16550_t) CONFIG_SYS_NS16550_COM1,
30 (NS16550_t) CONFIG_SYS_NS16550_COM2 };
wdenkc6097192002-11-03 00:24:07 +000031#endif
32
33#ifdef CONFIG_MPSC
34
Marek Vasut829b3b22012-09-13 12:33:50 +020035static int evb64260_serial_init(void)
wdenkc6097192002-11-03 00:24:07 +000036{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020037#if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
38 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
wdenkc6097192002-11-03 00:24:07 +000039#endif
40
41 mpsc_init(gd->baudrate);
42
43 /* init the DUART chans so that KGDB in the kernel can use them */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020044#ifdef CONFIG_SYS_INIT_CHAN1
wdenkc6097192002-11-03 00:24:07 +000045 NS16550_reinit(COM_PORTS[0], clock_divisor);
46#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020047#ifdef CONFIG_SYS_INIT_CHAN2
wdenkc6097192002-11-03 00:24:07 +000048 NS16550_reinit(COM_PORTS[1], clock_divisor);
49#endif
50 return (0);
51}
52
Marek Vasut829b3b22012-09-13 12:33:50 +020053static void evb64260_serial_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +000054{
55 if (c == '\n')
56 mpsc_putchar('\r');
57
58 mpsc_putchar(c);
59}
60
Marek Vasut829b3b22012-09-13 12:33:50 +020061static int evb64260_serial_getc(void)
wdenkc6097192002-11-03 00:24:07 +000062{
63 return mpsc_getchar();
64}
65
Marek Vasut829b3b22012-09-13 12:33:50 +020066static int evb64260_serial_tstc(void)
wdenkc6097192002-11-03 00:24:07 +000067{
68 return mpsc_test_char();
69}
70
Marek Vasut829b3b22012-09-13 12:33:50 +020071static void evb64260_serial_setbrg(void)
wdenkc6097192002-11-03 00:24:07 +000072{
wdenkc6097192002-11-03 00:24:07 +000073 galbrg_set_baudrate(CONFIG_MPSC_PORT, gd->baudrate);
74}
75
76#else /* ! CONFIG_MPSC */
77
Marek Vasut829b3b22012-09-13 12:33:50 +020078static int evb64260_serial_init(void)
wdenkc6097192002-11-03 00:24:07 +000079{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020080 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
wdenkc6097192002-11-03 00:24:07 +000081
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020082#ifdef CONFIG_SYS_INIT_CHAN1
wdenkc6097192002-11-03 00:24:07 +000083 (void)NS16550_init(COM_PORTS[0], clock_divisor);
84#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020085#ifdef CONFIG_SYS_INIT_CHAN2
wdenkc6097192002-11-03 00:24:07 +000086 (void)NS16550_init(COM_PORTS[1], clock_divisor);
87#endif
88
89 return (0);
90}
91
Marek Vasut829b3b22012-09-13 12:33:50 +020092static void evb64260_serial_putc(const char c)
wdenkc6097192002-11-03 00:24:07 +000093{
94 if (c == '\n')
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020095 NS16550_putc(COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
wdenkc6097192002-11-03 00:24:07 +000096
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +020097 NS16550_putc(COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
wdenkc6097192002-11-03 00:24:07 +000098}
99
Marek Vasut829b3b22012-09-13 12:33:50 +0200100static int evb64260_serial_getc(void)
wdenkc6097192002-11-03 00:24:07 +0000101{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200102 return NS16550_getc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
wdenkc6097192002-11-03 00:24:07 +0000103}
104
Marek Vasut829b3b22012-09-13 12:33:50 +0200105static int evb64260_serial_tstc(void)
wdenkc6097192002-11-03 00:24:07 +0000106{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200107 return NS16550_tstc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
wdenkc6097192002-11-03 00:24:07 +0000108}
109
Marek Vasut829b3b22012-09-13 12:33:50 +0200110static void evb64260_serial_setbrg(void)
wdenkc6097192002-11-03 00:24:07 +0000111{
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200112 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
wdenkc6097192002-11-03 00:24:07 +0000113
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200114#ifdef CONFIG_SYS_INIT_CHAN1
wdenkc6097192002-11-03 00:24:07 +0000115 NS16550_reinit(COM_PORTS[0], clock_divisor);
116#endif
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200117#ifdef CONFIG_SYS_INIT_CHAN2
wdenkc6097192002-11-03 00:24:07 +0000118 NS16550_reinit(COM_PORTS[1], clock_divisor);
119#endif
120}
121
122#endif /* CONFIG_MPSC */
123
Marek Vasut829b3b22012-09-13 12:33:50 +0200124static struct serial_device evb64260_serial_drv = {
125 .name = "evb64260_serial",
126 .start = evb64260_serial_init,
127 .stop = NULL,
128 .setbrg = evb64260_serial_setbrg,
129 .putc = evb64260_serial_putc,
Marek Vasutec3fd682012-10-06 14:07:02 +0000130 .puts = default_serial_puts,
Marek Vasut829b3b22012-09-13 12:33:50 +0200131 .getc = evb64260_serial_getc,
132 .tstc = evb64260_serial_tstc,
133};
134
135void evb64260_serial_initialize(void)
136{
137 serial_register(&evb64260_serial_drv);
138}
139
140__weak struct serial_device *default_serial_console(void)
141{
142 return &evb64260_serial_drv;
143}
Marek Vasut829b3b22012-09-13 12:33:50 +0200144
Jon Loeligerb9307262007-07-09 18:24:55 -0500145#if defined(CONFIG_CMD_KGDB)
wdenkc6097192002-11-03 00:24:07 +0000146void
147kgdb_serial_init(void)
148{
149}
150
151void
152putDebugChar (int c)
153{
154 serial_putc (c);
155}
156
157void
158putDebugStr (const char *str)
159{
160 serial_puts (str);
161}
162
163int
164getDebugChar (void)
165{
166 return serial_getc();
167}
168
169void
170kgdb_interruptible (int yes)
171{
172 return;
173}
Jon Loeliger77a31852007-07-10 10:39:10 -0500174#endif