2 * Copyright (c) 2015 Google, Inc
3 * Written by Simon Glass <sjg@chromium.org>
5 * SPDX-License-Identifier: GPL-2.0+
9 #include <debug_uart.h>
15 #include <linux/compiler.h>
19 /* Information about the efi console */
20 struct serial_efi_priv
{
21 struct efi_simple_input_interface
*con_in
;
22 struct efi_simple_text_output_protocol
*con_out
;
23 struct efi_input_key key
;
27 int serial_efi_setbrg(struct udevice
*dev
, int baudrate
)
32 static int serial_efi_get_key(struct serial_efi_priv
*priv
)
38 ret
= priv
->con_in
->read_key_stroke(priv
->con_in
, &priv
->key
);
39 if (ret
== EFI_NOT_READY
)
41 else if (ret
!= EFI_SUCCESS
)
44 priv
->have_key
= true;
49 static int serial_efi_getc(struct udevice
*dev
)
51 struct serial_efi_priv
*priv
= dev_get_priv(dev
);
54 ret
= serial_efi_get_key(priv
);
58 priv
->have_key
= false;
59 ch
= priv
->key
.unicode_char
;
62 * Unicode char 8 (for backspace) is never returned. Instead we get a
63 * key scan code of 8. Handle this so that backspace works correctly
64 * in the U-Boot command line.
66 if (!ch
&& priv
->key
.scan_code
== 8)
68 debug(" [%x %x %x] ", ch
, priv
->key
.unicode_char
, priv
->key
.scan_code
);
73 static int serial_efi_putc(struct udevice
*dev
, const char ch
)
75 struct serial_efi_priv
*priv
= dev_get_priv(dev
);
81 ret
= priv
->con_out
->output_string(priv
->con_out
, ucode
);
88 static int serial_efi_pending(struct udevice
*dev
, bool input
)
90 struct serial_efi_priv
*priv
= dev_get_priv(dev
);
93 /* We assume that EFI will stall if its output buffer fills up */
97 ret
= serial_efi_get_key(priv
);
107 * There is nothing to init here since the EFI console is already running by
108 * the time we enter U-Boot.
110 static inline void _debug_uart_init(void)
114 static inline void _debug_uart_putc(int ch
)
116 struct efi_system_table
*sys_table
= efi_get_sys_table();
121 sys_table
->con_out
->output_string(sys_table
->con_out
, ucode
);
126 static int serial_efi_probe(struct udevice
*dev
)
128 struct efi_system_table
*table
= efi_get_sys_table();
129 struct serial_efi_priv
*priv
= dev_get_priv(dev
);
131 priv
->con_in
= table
->con_in
;
132 priv
->con_out
= table
->con_out
;
137 static const struct dm_serial_ops serial_efi_ops
= {
138 .putc
= serial_efi_putc
,
139 .getc
= serial_efi_getc
,
140 .pending
= serial_efi_pending
,
141 .setbrg
= serial_efi_setbrg
,
144 static const struct udevice_id serial_efi_ids
[] = {
145 { .compatible
= "efi,uart" },
149 U_BOOT_DRIVER(serial_efi
) = {
150 .name
= "serial_efi",
152 .of_match
= serial_efi_ids
,
153 .priv_auto_alloc_size
= sizeof(struct serial_efi_priv
),
154 .probe
= serial_efi_probe
,
155 .ops
= &serial_efi_ops
,
156 .flags
= DM_FLAG_PRE_RELOC
,