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"
25 #include "../db64360/mpsc.h"
29 #include "../db64460/mpsc.h"
34 DECLARE_GLOBAL_DATA_PTR;
37 static int marvell_serial_init(void)
39 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
40 int clock_divisor = 230400 / gd->baudrate;
43 mpsc_init (gd->baudrate);
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);
49 #ifdef CONFIG_SYS_INIT_CHAN2
50 NS16550_reinit (COM_PORTS[1], clock_divisor);
55 static void marvell_serial_putc(const char c)
63 static int marvell_serial_getc(void)
65 return mpsc_getchar ();
68 static int marvell_serial_tstc(void)
70 return mpsc_test_char ();
73 static void marvell_serial_setbrg(void)
75 galbrg_set_baudrate (CONFIG_MPSC_PORT, gd->baudrate);
78 #else /* ! CONFIG_MPSC */
80 static int marvell_serial_init(void)
82 int clock_divisor = 230400 / gd->baudrate;
84 #ifdef CONFIG_SYS_INIT_CHAN1
85 (void) NS16550_init (0, clock_divisor);
87 #ifdef CONFIG_SYS_INIT_CHAN2
88 (void) NS16550_init (1, clock_divisor);
93 static void marvell_serial_putc(const char c)
96 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
98 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
101 static int marvell_serial_getc(void)
103 return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
106 static int marvell_serial_tstc(void)
108 return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
111 static void marvell_serial_setbrg(void)
113 int clock_divisor = 230400 / gd->baudrate;
115 #ifdef CONFIG_SYS_INIT_CHAN1
116 NS16550_reinit (COM_PORTS[0], clock_divisor);
118 #ifdef CONFIG_SYS_INIT_CHAN2
119 NS16550_reinit (COM_PORTS[1], clock_divisor);
123 #endif /* CONFIG_MPSC */
125 static struct serial_device marvell_serial_drv = {
126 .name = "marvell_serial",
127 .start = marvell_serial_init,
129 .setbrg = marvell_serial_setbrg,
130 .putc = marvell_serial_putc,
131 .puts = default_serial_puts,
132 .getc = marvell_serial_getc,
133 .tstc = marvell_serial_tstc,
136 void marvell_serial_initialize(void)
138 serial_register(&marvell_serial_drv);
141 __weak struct serial_device *default_serial_console(void)
143 return &marvell_serial_drv;
146 #if defined(CONFIG_CMD_KGDB)
147 void kgdb_serial_init (void)
151 void putDebugChar (int c)
156 void putDebugStr (const char *str)
161 int getDebugChar (void)
163 return serial_getc ();
166 void kgdb_interruptible (int yes)