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 static int serial_open(void)
24 struct serial_console_data
*scdp
= console_ops
.data
;
28 static void serial_write(const char *buf
, int len
)
30 struct serial_console_data
*scdp
= console_ops
.data
;
36 static void serial_edit_cmdline(char *buf
, int len
, unsigned int timeout
)
40 struct serial_console_data
*scdp
= console_ops
.data
;
49 while (((ch
= scdp
->getc()) != '\n') && (ch
!= '\r')) {
50 /* Test for backspace/delete */
51 if ((ch
== '\b') || (ch
== '\177')) {
57 /* Test for ^x/^u (and wipe the line) */
58 } else if ((ch
== '\030') || (ch
== '\025')) {
64 } else if (count
< len
) {
70 break; /* Exit 'timer' loop */
72 udelay(1000); /* 1 msec */
73 } while (timer
++ < timeout
);
77 static void serial_close(void)
79 struct serial_console_data
*scdp
= console_ops
.data
;
85 static void *serial_get_stdout_devp(void)
88 char devtype
[MAX_PROP_LEN
];
89 char path
[MAX_PATH_LEN
];
91 devp
= finddevice("/chosen");
95 if (getprop(devp
, "linux,stdout-path", path
, MAX_PATH_LEN
) > 0) {
96 devp
= finddevice(path
);
100 if ((getprop(devp
, "device_type", devtype
, sizeof(devtype
)) > 0)
101 && !strcmp(devtype
, "serial"))
108 static struct serial_console_data serial_cd
;
110 /* Node's "compatible" property determines which serial driver to use */
111 int serial_console_init(void)
116 devp
= serial_get_stdout_devp();
120 if (dt_is_compatible(devp
, "ns16550") ||
121 dt_is_compatible(devp
, "pnpPNP,501"))
122 rc
= ns16550_console_init(devp
, &serial_cd
);
123 #ifdef CONFIG_EMBEDDED6xx
124 else if (dt_is_compatible(devp
, "marvell,mv64360-mpsc"))
125 rc
= mpsc_console_init(devp
, &serial_cd
);
128 else if (dt_is_compatible(devp
, "fsl,cpm1-scc-uart") ||
129 dt_is_compatible(devp
, "fsl,cpm1-smc-uart") ||
130 dt_is_compatible(devp
, "fsl,cpm2-scc-uart") ||
131 dt_is_compatible(devp
, "fsl,cpm2-smc-uart"))
132 rc
= cpm_console_init(devp
, &serial_cd
);
134 #ifdef CONFIG_PPC_MPC52XX
135 else if (dt_is_compatible(devp
, "fsl,mpc5200-psc-uart"))
136 rc
= mpc5200_psc_console_init(devp
, &serial_cd
);
138 #ifdef CONFIG_XILINX_VIRTEX
139 else if (dt_is_compatible(devp
, "xlnx,opb-uartlite-1.00.b") ||
140 dt_is_compatible(devp
, "xlnx,xps-uartlite-1.00.a"))
141 rc
= uartlite_console_init(devp
, &serial_cd
);
143 #ifdef CONFIG_PPC64_BOOT_WRAPPER
144 else if (dt_is_compatible(devp
, "ibm,opal-console-raw"))
145 rc
= opal_console_init(devp
, &serial_cd
);
148 /* Add other serial console driver calls here */
151 console_ops
.open
= serial_open
;
152 console_ops
.write
= serial_write
;
153 console_ops
.close
= serial_close
;
154 console_ops
.data
= &serial_cd
;
157 console_ops
.edit_cmdline
= serial_edit_cmdline
;