3 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
5 * SPDX-License-Identifier: GPL-2.0+
9 * serial.c - serial support for the gal ev board
12 /* supports both the 16650 duart and the MPSC */
16 #include <galileo/memory.h>
18 #include <linux/compiler.h>
20 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
26 DECLARE_GLOBAL_DATA_PTR;
28 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
29 const NS16550_t COM_PORTS[] = { (NS16550_t) CONFIG_SYS_NS16550_COM1,
30 (NS16550_t) CONFIG_SYS_NS16550_COM2 };
35 static int evb64260_serial_init(void)
37 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
38 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
41 mpsc_init(gd->baudrate);
43 /* init the DUART chans so that KGDB in the kernel can use them */
44 #ifdef CONFIG_SYS_INIT_CHAN1
45 NS16550_reinit(COM_PORTS[0], clock_divisor);
47 #ifdef CONFIG_SYS_INIT_CHAN2
48 NS16550_reinit(COM_PORTS[1], clock_divisor);
53 static void evb64260_serial_putc(const char c)
61 static int evb64260_serial_getc(void)
63 return mpsc_getchar();
66 static int evb64260_serial_tstc(void)
68 return mpsc_test_char();
71 static void evb64260_serial_setbrg(void)
73 galbrg_set_baudrate(CONFIG_MPSC_PORT, gd->baudrate);
76 #else /* ! CONFIG_MPSC */
78 static int evb64260_serial_init(void)
80 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
82 #ifdef CONFIG_SYS_INIT_CHAN1
83 (void)NS16550_init(COM_PORTS[0], clock_divisor);
85 #ifdef CONFIG_SYS_INIT_CHAN2
86 (void)NS16550_init(COM_PORTS[1], clock_divisor);
92 static void evb64260_serial_putc(const char c)
95 NS16550_putc(COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
97 NS16550_putc(COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
100 static int evb64260_serial_getc(void)
102 return NS16550_getc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
105 static int evb64260_serial_tstc(void)
107 return NS16550_tstc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
110 static void evb64260_serial_setbrg(void)
112 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
114 #ifdef CONFIG_SYS_INIT_CHAN1
115 NS16550_reinit(COM_PORTS[0], clock_divisor);
117 #ifdef CONFIG_SYS_INIT_CHAN2
118 NS16550_reinit(COM_PORTS[1], clock_divisor);
122 #endif /* CONFIG_MPSC */
124 static struct serial_device evb64260_serial_drv = {
125 .name = "evb64260_serial",
126 .start = evb64260_serial_init,
128 .setbrg = evb64260_serial_setbrg,
129 .putc = evb64260_serial_putc,
130 .puts = default_serial_puts,
131 .getc = evb64260_serial_getc,
132 .tstc = evb64260_serial_tstc,
135 void evb64260_serial_initialize(void)
137 serial_register(&evb64260_serial_drv);
140 __weak struct serial_device *default_serial_console(void)
142 return &evb64260_serial_drv;
145 #if defined(CONFIG_CMD_KGDB)
147 kgdb_serial_init(void)
158 putDebugStr (const char *str)
166 return serial_getc();
170 kgdb_interruptible (int yes)