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)
28 DECLARE_GLOBAL_DATA_PTR;
30 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
31 const NS16550_t COM_PORTS[] = { (NS16550_t) CONFIG_SYS_NS16550_COM1,
32 (NS16550_t) CONFIG_SYS_NS16550_COM2 };
37 static int evb64260_serial_init(void)
39 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
40 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / 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 evb64260_serial_putc(const char c)
63 static int evb64260_serial_getc(void)
65 return mpsc_getchar();
68 static int evb64260_serial_tstc(void)
70 return mpsc_test_char();
73 static void evb64260_serial_setbrg(void)
75 galbrg_set_baudrate(CONFIG_MPSC_PORT, gd->baudrate);
78 #else /* ! CONFIG_MPSC */
80 static int evb64260_serial_init(void)
82 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
84 #ifdef CONFIG_SYS_INIT_CHAN1
85 (void)NS16550_init(COM_PORTS[0], clock_divisor);
87 #ifdef CONFIG_SYS_INIT_CHAN2
88 (void)NS16550_init(COM_PORTS[1], clock_divisor);
94 static void evb64260_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 evb64260_serial_getc(void)
104 return NS16550_getc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
107 static int evb64260_serial_tstc(void)
109 return NS16550_tstc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
112 static void evb64260_serial_setbrg(void)
114 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / 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 evb64260_serial_drv = {
127 .name = "evb64260_serial",
128 .start = evb64260_serial_init,
130 .setbrg = evb64260_serial_setbrg,
131 .putc = evb64260_serial_putc,
132 .puts = default_serial_puts,
133 .getc = evb64260_serial_getc,
134 .tstc = evb64260_serial_tstc,
137 void evb64260_serial_initialize(void)
139 serial_register(&evb64260_serial_drv);
142 __weak struct serial_device *default_serial_console(void)
144 return &evb64260_serial_drv;
147 #if defined(CONFIG_CMD_KGDB)
149 kgdb_serial_init(void)
160 putDebugStr (const char *str)
168 return serial_getc();
172 kgdb_interruptible (int yes)