1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2015 Google, Inc
4 * Written by Simon Glass <sjg@chromium.org>
8 #include <debug_uart.h>
14 #include <linux/compiler.h>
18 /* Information about the efi console */
19 struct serial_efi_priv {
20 struct efi_simple_text_input_protocol *con_in;
21 struct efi_simple_text_output_protocol *con_out;
22 struct efi_input_key key;
26 int serial_efi_setbrg(struct udevice *dev, int baudrate)
31 static int serial_efi_get_key(struct serial_efi_priv *priv)
37 ret = priv->con_in->read_key_stroke(priv->con_in, &priv->key);
38 if (ret == EFI_NOT_READY)
40 else if (ret != EFI_SUCCESS)
43 priv->have_key = true;
48 static int serial_efi_getc(struct udevice *dev)
50 struct serial_efi_priv *priv = dev_get_priv(dev);
53 ret = serial_efi_get_key(priv);
57 priv->have_key = false;
58 ch = priv->key.unicode_char;
61 * Unicode char 8 (for backspace) is never returned. Instead we get a
62 * key scan code of 8. Handle this so that backspace works correctly
63 * in the U-Boot command line.
65 if (!ch && priv->key.scan_code == 8)
67 debug(" [%x %x %x] ", ch, priv->key.unicode_char, priv->key.scan_code);
72 static int serial_efi_putc(struct udevice *dev, const char ch)
74 struct serial_efi_priv *priv = dev_get_priv(dev);
80 ret = priv->con_out->output_string(priv->con_out, ucode);
87 static int serial_efi_pending(struct udevice *dev, bool input)
89 struct serial_efi_priv *priv = dev_get_priv(dev);
92 /* We assume that EFI will stall if its output buffer fills up */
96 ret = serial_efi_get_key(priv);
106 * There is nothing to init here since the EFI console is already running by
107 * the time we enter U-Boot.
109 static inline void _debug_uart_init(void)
113 static inline void _debug_uart_putc(int ch)
115 struct efi_system_table *sys_table = efi_get_sys_table();
120 sys_table->con_out->output_string(sys_table->con_out, ucode);
125 static int serial_efi_probe(struct udevice *dev)
127 struct efi_system_table *table = efi_get_sys_table();
128 struct serial_efi_priv *priv = dev_get_priv(dev);
130 priv->con_in = table->con_in;
131 priv->con_out = table->con_out;
136 static const struct dm_serial_ops serial_efi_ops = {
137 .putc = serial_efi_putc,
138 .getc = serial_efi_getc,
139 .pending = serial_efi_pending,
140 .setbrg = serial_efi_setbrg,
143 static const struct udevice_id serial_efi_ids[] = {
144 { .compatible = "efi,uart" },
148 U_BOOT_DRIVER(serial_efi) = {
149 .name = "serial_efi",
151 .of_match = serial_efi_ids,
152 .priv_auto_alloc_size = sizeof(struct serial_efi_priv),
153 .probe = serial_efi_probe,
154 .ops = &serial_efi_ops,