3 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * serial.c - serial support for the gal ev board
28 /* supports both the 16650 duart and the MPSC */
32 #include <galileo/memory.h>
34 #include <linux/compiler.h>
36 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
44 DECLARE_GLOBAL_DATA_PTR;
46 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
47 const NS16550_t COM_PORTS[] = { (NS16550_t) CONFIG_SYS_NS16550_COM1,
48 (NS16550_t) CONFIG_SYS_NS16550_COM2 };
53 static int evb64260_serial_init(void)
55 #if (defined CONFIG_SYS_INIT_CHAN1) || (defined CONFIG_SYS_INIT_CHAN2)
56 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
59 mpsc_init(gd->baudrate);
61 /* init the DUART chans so that KGDB in the kernel can use them */
62 #ifdef CONFIG_SYS_INIT_CHAN1
63 NS16550_reinit(COM_PORTS[0], clock_divisor);
65 #ifdef CONFIG_SYS_INIT_CHAN2
66 NS16550_reinit(COM_PORTS[1], clock_divisor);
71 static void evb64260_serial_putc(const char c)
79 static int evb64260_serial_getc(void)
81 return mpsc_getchar();
84 static int evb64260_serial_tstc(void)
86 return mpsc_test_char();
89 static void evb64260_serial_setbrg(void)
91 galbrg_set_baudrate(CONFIG_MPSC_PORT, gd->baudrate);
94 #else /* ! CONFIG_MPSC */
96 static int evb64260_serial_init(void)
98 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
100 #ifdef CONFIG_SYS_INIT_CHAN1
101 (void)NS16550_init(COM_PORTS[0], clock_divisor);
103 #ifdef CONFIG_SYS_INIT_CHAN2
104 (void)NS16550_init(COM_PORTS[1], clock_divisor);
110 static void evb64260_serial_putc(const char c)
113 NS16550_putc(COM_PORTS[CONFIG_SYS_DUART_CHAN], '\r');
115 NS16550_putc(COM_PORTS[CONFIG_SYS_DUART_CHAN], c);
118 static int evb64260_serial_getc(void)
120 return NS16550_getc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
123 static int evb64260_serial_tstc(void)
125 return NS16550_tstc(COM_PORTS[CONFIG_SYS_DUART_CHAN]);
128 static void evb64260_serial_setbrg(void)
130 int clock_divisor = CONFIG_SYS_NS16550_CLK / 16 / gd->baudrate;
132 #ifdef CONFIG_SYS_INIT_CHAN1
133 NS16550_reinit(COM_PORTS[0], clock_divisor);
135 #ifdef CONFIG_SYS_INIT_CHAN2
136 NS16550_reinit(COM_PORTS[1], clock_divisor);
140 #endif /* CONFIG_MPSC */
142 static void evb64260_serial_puts(const char *s)
149 static struct serial_device evb64260_serial_drv = {
150 .name = "evb64260_serial",
151 .start = evb64260_serial_init,
153 .setbrg = evb64260_serial_setbrg,
154 .putc = evb64260_serial_putc,
155 .puts = evb64260_serial_puts,
156 .getc = evb64260_serial_getc,
157 .tstc = evb64260_serial_tstc,
160 void evb64260_serial_initialize(void)
162 serial_register(&evb64260_serial_drv);
165 __weak struct serial_device *default_serial_console(void)
167 return &evb64260_serial_drv;
170 #if defined(CONFIG_CMD_KGDB)
172 kgdb_serial_init(void)
183 putDebugStr (const char *str)
191 return serial_getc();
195 kgdb_interruptible (int yes)