[SCSI] lpfc 8.2.2 : Attribute and Parameter splits for vport and physical port
[linux-2.6/mini2440.git] / arch / powerpc / boot / serial.c
blobeaa0d3ae351861957ec2fbe7cad0debce1a2a779
1 /*
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
12 * or implied.
14 #include <stdarg.h>
15 #include <stddef.h>
16 #include "types.h"
17 #include "string.h"
18 #include "stdio.h"
19 #include "io.h"
20 #include "ops.h"
22 extern void udelay(long delay);
24 static int serial_open(void)
26 struct serial_console_data *scdp = console_ops.data;
27 return scdp->open();
30 static void serial_write(const char *buf, int len)
32 struct serial_console_data *scdp = console_ops.data;
34 while (*buf != '\0')
35 scdp->putc(*buf++);
38 static void serial_edit_cmdline(char *buf, int len)
40 int timer = 0, count;
41 char ch, *cp;
42 struct serial_console_data *scdp = console_ops.data;
44 cp = buf;
45 count = strlen(buf);
46 cp = &buf[count];
47 count++;
49 while (timer++ < 5*1000) {
50 if (scdp->tstc()) {
51 while (((ch = scdp->getc()) != '\n') && (ch != '\r')) {
52 /* Test for backspace/delete */
53 if ((ch == '\b') || (ch == '\177')) {
54 if (cp != buf) {
55 cp--;
56 count--;
57 printf("\b \b");
59 /* Test for ^x/^u (and wipe the line) */
60 } else if ((ch == '\030') || (ch == '\025')) {
61 while (cp != buf) {
62 cp--;
63 count--;
64 printf("\b \b");
66 } else if (count < len) {
67 *cp++ = ch;
68 count++;
69 scdp->putc(ch);
72 break; /* Exit 'timer' loop */
74 udelay(1000); /* 1 msec */
76 *cp = 0;
79 static void serial_close(void)
81 struct serial_console_data *scdp = console_ops.data;
83 if (scdp->close)
84 scdp->close();
87 static void *serial_get_stdout_devp(void)
89 void *devp;
90 char devtype[MAX_PROP_LEN];
91 char path[MAX_PATH_LEN];
93 devp = finddevice("/chosen");
94 if (devp == NULL)
95 goto err_out;
97 if (getprop(devp, "linux,stdout-path", path, MAX_PATH_LEN) > 0) {
98 devp = finddevice(path);
99 if (devp == NULL)
100 goto err_out;
102 if ((getprop(devp, "device_type", devtype, sizeof(devtype)) > 0)
103 && !strcmp(devtype, "serial"))
104 return devp;
106 err_out:
107 return NULL;
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)
115 void *devp;
116 int rc = -1;
117 char compat[MAX_PROP_LEN];
119 devp = serial_get_stdout_devp();
120 if (devp == NULL)
121 goto err_out;
123 if (getprop(devp, "compatible", compat, sizeof(compat)) < 0)
124 goto err_out;
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 */
133 if (!rc) {
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;
140 return 0;
142 err_out:
143 return -1;