acpi: Add IORT helper functions
[coreboot2.git] / src / drivers / usb / console.c
blobe3abdb90f5b705000c7f97af138fece57bdd194f
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/usb.h>
4 #include "ehci_debug.h"
6 static void usbdebug_tx_byte(struct dbgp_pipe *pipe, unsigned char data)
8 if (!dbgp_try_get(pipe))
9 return;
10 pipe->buf[pipe->bufidx++] = data;
11 if (pipe->bufidx >= 8) {
12 dbgp_bulk_write_x(pipe, pipe->buf, pipe->bufidx);
13 pipe->bufidx = 0;
15 dbgp_put(pipe);
18 static void usbdebug_tx_flush(struct dbgp_pipe *pipe)
20 if (!dbgp_try_get(pipe))
21 return;
22 if (pipe->bufidx > 0) {
23 dbgp_bulk_write_x(pipe, pipe->buf, pipe->bufidx);
24 pipe->bufidx = 0;
26 dbgp_put(pipe);
29 static unsigned char usbdebug_rx_byte(struct dbgp_pipe *pipe)
31 unsigned char data = 0xff;
32 if (!dbgp_try_get(pipe))
33 return 0xff;
34 while (pipe->bufidx >= pipe->buflen) {
35 pipe->buflen = 0;
36 pipe->bufidx = 0;
37 int count = dbgp_bulk_read_x(pipe, pipe->buf, 8);
38 if (count>0)
39 pipe->buflen = count;
41 data = pipe->buf[pipe->bufidx++];
42 dbgp_put(pipe);
43 return data;
46 void usb_tx_byte(int idx, unsigned char data)
48 usbdebug_tx_byte(dbgp_console_output(), data);
51 void usb_tx_flush(int idx)
53 usbdebug_tx_flush(dbgp_console_output());
56 unsigned char usb_rx_byte(int idx)
58 return usbdebug_rx_byte(dbgp_console_input());
61 int usb_can_rx_byte(int idx)
63 return dbgp_ep_is_active(dbgp_console_input());