2 * Generic serial console support
4 * Author: Mark A. Greer <mgreer@mvista.com>
6 * Code in serial_edit_cmdline() copied from <file:arch/ppc/boot/simple/misc.c>
7 * and was written by Matt Porter <mporter@kernel.crashing.org>.
9 * 2001,2006 (c) MontaVista Software, Inc. This file is licensed under
10 * the terms of the GNU General Public License version 2. This program
11 * is licensed "as is" without any warranty of any kind, whether express
22 extern void udelay(long delay);
24 static int serial_open(void)
26 struct serial_console_data *scdp = console_ops.data;
30 static void serial_write(const char *buf, int len)
32 struct serial_console_data *scdp = console_ops.data;
38 static void serial_edit_cmdline(char *buf, int len)
42 struct serial_console_data *scdp = console_ops.data;
49 while (timer++ < 5*1000) {
51 while (((ch = scdp->getc()) != '\n') && (ch != '\r')) {
52 /* Test for backspace/delete */
53 if ((ch == '\b') || (ch == '\177')) {
59 /* Test for ^x/^u (and wipe the line) */
60 } else if ((ch == '\030') || (ch == '\025')) {
66 } else if (count < len) {
72 break; /* Exit 'timer' loop */
74 udelay(1000); /* 1 msec */
79 static void serial_close(void)
81 struct serial_console_data *scdp = console_ops.data;
87 static void *serial_get_stdout_devp(void)
90 char devtype[MAX_PROP_LEN];
91 char path[MAX_PATH_LEN];
93 devp = finddevice("/chosen");
97 if (getprop(devp, "linux,stdout-path", path, MAX_PATH_LEN) > 0) {
98 devp = finddevice(path);
102 if ((getprop(devp, "device_type", devtype, sizeof(devtype)) > 0)
103 && !strcmp(devtype, "serial"))
110 static struct serial_console_data serial_cd;
112 /* Node's "compatible" property determines which serial driver to use */
113 int serial_console_init(void)
117 char compat[MAX_PROP_LEN];
119 devp = serial_get_stdout_devp();
123 if (getprop(devp, "compatible", compat, sizeof(compat)) < 0)
126 if (!strcmp(compat, "ns16550"))
127 rc = ns16550_console_init(devp, &serial_cd);
128 else if (!strcmp(compat, "marvell,mpsc"))
129 rc = mpsc_console_init(devp, &serial_cd);
131 /* Add other serial console driver calls here */
134 console_ops.open = serial_open;
135 console_ops.write = serial_write;
136 console_ops.edit_cmdline = serial_edit_cmdline;
137 console_ops.close = serial_close;
138 console_ops.data = &serial_cd;