1 // SPDX-License-Identifier: GPL-2.0
3 * Generic serial console support
5 * Author: Mark A. Greer <mgreer@mvista.com>
7 * Code in serial_edit_cmdline() copied from <file:arch/ppc/boot/simple/misc.c>
8 * and was written by Matt Porter <mporter@kernel.crashing.org>.
10 * 2001,2006 (c) MontaVista Software, Inc.
20 static int serial_open(void)
22 struct serial_console_data
*scdp
= console_ops
.data
;
26 static void serial_write(const char *buf
, int len
)
28 struct serial_console_data
*scdp
= console_ops
.data
;
34 static void serial_edit_cmdline(char *buf
, int len
, unsigned int timeout
)
38 struct serial_console_data
*scdp
= console_ops
.data
;
47 while (((ch
= scdp
->getc()) != '\n') && (ch
!= '\r')) {
48 /* Test for backspace/delete */
49 if ((ch
== '\b') || (ch
== '\177')) {
55 /* Test for ^x/^u (and wipe the line) */
56 } else if ((ch
== '\030') || (ch
== '\025')) {
62 } else if (count
< len
) {
68 break; /* Exit 'timer' loop */
70 udelay(1000); /* 1 msec */
71 } while (timer
++ < timeout
);
75 static void serial_close(void)
77 struct serial_console_data
*scdp
= console_ops
.data
;
83 static void *serial_get_stdout_devp(void)
86 char devtype
[MAX_PROP_LEN
];
87 char path
[MAX_PATH_LEN
];
89 devp
= finddevice("/chosen");
93 if (getprop(devp
, "linux,stdout-path", path
, MAX_PATH_LEN
) > 0 ||
94 getprop(devp
, "stdout-path", path
, MAX_PATH_LEN
) > 0) {
95 devp
= finddevice(path
);
99 if ((getprop(devp
, "device_type", devtype
, sizeof(devtype
)) > 0)
100 && !strcmp(devtype
, "serial"))
107 static struct serial_console_data serial_cd
;
109 /* Node's "compatible" property determines which serial driver to use */
110 int serial_console_init(void)
115 devp
= serial_get_stdout_devp();
119 if (dt_is_compatible(devp
, "ns16550") ||
120 dt_is_compatible(devp
, "pnpPNP,501"))
121 rc
= ns16550_console_init(devp
, &serial_cd
);
123 else if (dt_is_compatible(devp
, "fsl,cpm1-scc-uart") ||
124 dt_is_compatible(devp
, "fsl,cpm1-smc-uart") ||
125 dt_is_compatible(devp
, "fsl,cpm2-scc-uart") ||
126 dt_is_compatible(devp
, "fsl,cpm2-smc-uart"))
127 rc
= cpm_console_init(devp
, &serial_cd
);
129 #ifdef CONFIG_PPC_MPC52xx
130 else if (dt_is_compatible(devp
, "fsl,mpc5200-psc-uart"))
131 rc
= mpc5200_psc_console_init(devp
, &serial_cd
);
133 #ifdef CONFIG_PPC_POWERNV
134 else if (dt_is_compatible(devp
, "ibm,opal-console-raw"))
135 rc
= opal_console_init(devp
, &serial_cd
);
138 /* Add other serial console driver calls here */
141 console_ops
.open
= serial_open
;
142 console_ops
.write
= serial_write
;
143 console_ops
.close
= serial_close
;
144 console_ops
.data
= &serial_cd
;
147 console_ops
.edit_cmdline
= serial_edit_cmdline
;