3 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
5 * modified for marvell db64360 eval board by
6 * Ingo Assmus <ingo.assmus@keymile.com>
8 * SPDX-License-Identifier: GPL-2.0+
12 * serial.c - serial support for the gal ev board
15 /* supports both the 16650 duart and the MPSC */
20 #include <linux/compiler.h>
22 #include "../include/memory.h"
26 #include "../db64360/mpsc.h"
30 #include "../db64460/mpsc.h"
35 DECLARE_GLOBAL_DATA_PTR;
38 static int marvell_serial_init(void)
40 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
41 int clock_divisor = 230400 / gd->baudrate;
44 mpsc_init (gd->baudrate);
46 /* init the DUART chans so that KGDB in the kernel can use them */
47 #ifdef CONFIG_SYS_INIT_CHAN1
48 NS16550_reinit (COM_PORTS[0], clock_divisor);
50 #ifdef CONFIG_SYS_INIT_CHAN2
51 NS16550_reinit (COM_PORTS[1], clock_divisor);
56 static void marvell_serial_putc(const char c)
64 static int marvell_serial_getc(void)
66 return mpsc_getchar ();
69 static int marvell_serial_tstc(void)
71 return mpsc_test_char ();
74 static void marvell_serial_setbrg(void)
76 galbrg_set_baudrate (CONFIG_MPSC_PORT, gd->baudrate);
79 #else /* ! CONFIG_MPSC */
81 static int marvell_serial_init(void)
83 int clock_divisor = 230400 / gd->baudrate;
85 #ifdef CONFIG_SYS_INIT_CHAN1
86 (void) NS16550_init (0, clock_divisor);
88 #ifdef CONFIG_SYS_INIT_CHAN2
89 (void) NS16550_init (1, clock_divisor);
94 static void marvell_serial_putc(const char c)
97 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
99 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
102 static int marvell_serial_getc(void)
104 return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
107 static int marvell_serial_tstc(void)
109 return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
112 static void marvell_serial_setbrg(void)
114 int clock_divisor = 230400 / gd->baudrate;
116 #ifdef CONFIG_SYS_INIT_CHAN1
117 NS16550_reinit (COM_PORTS[0], clock_divisor);
119 #ifdef CONFIG_SYS_INIT_CHAN2
120 NS16550_reinit (COM_PORTS[1], clock_divisor);
124 #endif /* CONFIG_MPSC */
126 static struct serial_device marvell_serial_drv = {
127 .name = "marvell_serial",
128 .start = marvell_serial_init,
130 .setbrg = marvell_serial_setbrg,
131 .putc = marvell_serial_putc,
132 .puts = default_serial_puts,
133 .getc = marvell_serial_getc,
134 .tstc = marvell_serial_tstc,
137 void marvell_serial_initialize(void)
139 serial_register(&marvell_serial_drv);
142 __weak struct serial_device *default_serial_console(void)
144 return &marvell_serial_drv;
147 #if defined(CONFIG_CMD_KGDB)
148 void kgdb_serial_init (void)
152 void putDebugChar (int c)
157 void putDebugStr (const char *str)
162 int getDebugChar (void)
164 return serial_getc ();
167 void kgdb_interruptible (int yes)