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 DECLARE_GLOBAL_DATA_PTR;
29 static int marvell_serial_init(void)
31 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
32 int clock_divisor = 230400 / gd->baudrate;
35 mpsc_init (gd->baudrate);
37 /* init the DUART chans so that KGDB in the kernel can use them */
38 #ifdef CONFIG_SYS_INIT_CHAN1
39 NS16550_reinit (COM_PORTS[0], clock_divisor);
41 #ifdef CONFIG_SYS_INIT_CHAN2
42 NS16550_reinit (COM_PORTS[1], clock_divisor);
47 static void marvell_serial_putc(const char c)
55 static int marvell_serial_getc(void)
57 return mpsc_getchar ();
60 static int marvell_serial_tstc(void)
62 return mpsc_test_char ();
65 static void marvell_serial_setbrg(void)
67 galbrg_set_baudrate (CONFIG_MPSC_PORT, gd->baudrate);
70 #else /* ! CONFIG_MPSC */
72 static int marvell_serial_init(void)
74 int clock_divisor = 230400 / gd->baudrate;
76 #ifdef CONFIG_SYS_INIT_CHAN1
77 (void) NS16550_init (0, clock_divisor);
79 #ifdef CONFIG_SYS_INIT_CHAN2
80 (void) NS16550_init (1, clock_divisor);
85 static void marvell_serial_putc(const char c)
88 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
90 NS16550_putc (COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
93 static int marvell_serial_getc(void)
95 return NS16550_getc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
98 static int marvell_serial_tstc(void)
100 return NS16550_tstc (COM_PORTS[CONFIG_SYS_DUART_CHAN]);
103 static void marvell_serial_setbrg(void)
105 int clock_divisor = 230400 / gd->baudrate;
107 #ifdef CONFIG_SYS_INIT_CHAN1
108 NS16550_reinit (COM_PORTS[0], clock_divisor);
110 #ifdef CONFIG_SYS_INIT_CHAN2
111 NS16550_reinit (COM_PORTS[1], clock_divisor);
115 #endif /* CONFIG_MPSC */
117 static struct serial_device marvell_serial_drv = {
118 .name = "marvell_serial",
119 .start = marvell_serial_init,
121 .setbrg = marvell_serial_setbrg,
122 .putc = marvell_serial_putc,
123 .puts = default_serial_puts,
124 .getc = marvell_serial_getc,
125 .tstc = marvell_serial_tstc,
128 void marvell_serial_initialize(void)
130 serial_register(&marvell_serial_drv);
133 __weak struct serial_device *default_serial_console(void)
135 return &marvell_serial_drv;
138 #if defined(CONFIG_CMD_KGDB)
139 void kgdb_serial_init (void)
143 void putDebugChar (int c)
148 void putDebugStr (const char *str)
153 int getDebugChar (void)
155 return serial_getc ();
158 void kgdb_interruptible (int yes)