blob: 7b25dee55f3eaf85f3dd1a4d91bb28a68cf403f0 [file] [log] [blame]
Kyösti Mälkki8cde8522014-02-09 23:35:39 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2006 Eric Biederman (ebiederm@xmission.com)
5 * Copyright (C) 2007 AMD
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Kyösti Mälkki8cde8522014-02-09 23:35:39 +020015 */
16
Kyösti Mälkki8cde8522014-02-09 23:35:39 +020017#include <console/usb.h>
18#include "ehci_debug.h"
19
Kyösti Mälkkiea6736a2014-02-10 00:00:44 +020020static void usbdebug_tx_byte(struct dbgp_pipe *pipe, unsigned char data)
Kyösti Mälkki8cde8522014-02-09 23:35:39 +020021{
22 if (!dbgp_try_get(pipe))
23 return;
24 pipe->buf[pipe->bufidx++] = data;
25 if (pipe->bufidx >= 8) {
26 dbgp_bulk_write_x(pipe, pipe->buf, pipe->bufidx);
27 pipe->bufidx = 0;
28 }
29 dbgp_put(pipe);
30}
31
Kyösti Mälkkiea6736a2014-02-10 00:00:44 +020032static void usbdebug_tx_flush(struct dbgp_pipe *pipe)
Kyösti Mälkki8cde8522014-02-09 23:35:39 +020033{
34 if (!dbgp_try_get(pipe))
35 return;
36 if (pipe->bufidx > 0) {
37 dbgp_bulk_write_x(pipe, pipe->buf, pipe->bufidx);
38 pipe->bufidx = 0;
39 }
40 dbgp_put(pipe);
41}
42
Kyösti Mälkkiea6736a2014-02-10 00:00:44 +020043static unsigned char usbdebug_rx_byte(struct dbgp_pipe *pipe)
Kyösti Mälkki8cde8522014-02-09 23:35:39 +020044{
45 unsigned char data = 0xff;
46 if (!dbgp_try_get(pipe))
47 return 0xff;
48 while (pipe->bufidx >= pipe->buflen) {
49 pipe->buflen = 0;
50 pipe->bufidx = 0;
51 int count = dbgp_bulk_read_x(pipe, pipe->buf, 8);
52 if (count>0)
53 pipe->buflen = count;
54 }
55 data = pipe->buf[pipe->bufidx++];
56 dbgp_put(pipe);
57 return data;
58}
Kyösti Mälkkiea6736a2014-02-10 00:00:44 +020059
60void usb_tx_byte(int idx, unsigned char data)
61{
62 usbdebug_tx_byte(dbgp_console_output(), data);
63}
64
65void usb_tx_flush(int idx)
66{
67 usbdebug_tx_flush(dbgp_console_output());
68}
69
70unsigned char usb_rx_byte(int idx)
71{
72 return usbdebug_rx_byte(dbgp_console_input());
73}
74
75int usb_can_rx_byte(int idx)
76{
77 return dbgp_ep_is_active(dbgp_console_input());
78}