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
))
10 pipe
->buf
[pipe
->bufidx
++] = data
;
11 if (pipe
->bufidx
>= 8) {
12 dbgp_bulk_write_x(pipe
, pipe
->buf
, pipe
->bufidx
);
18 static void usbdebug_tx_flush(struct dbgp_pipe
*pipe
)
20 if (!dbgp_try_get(pipe
))
22 if (pipe
->bufidx
> 0) {
23 dbgp_bulk_write_x(pipe
, pipe
->buf
, pipe
->bufidx
);
29 static unsigned char usbdebug_rx_byte(struct dbgp_pipe
*pipe
)
31 unsigned char data
= 0xff;
32 if (!dbgp_try_get(pipe
))
34 while (pipe
->bufidx
>= pipe
->buflen
) {
37 int count
= dbgp_bulk_read_x(pipe
, pipe
->buf
, 8);
41 data
= pipe
->buf
[pipe
->bufidx
++];
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());