Kyösti Mälkki | 8cde852 | 2014-02-09 23:35:39 +0200 | [diff] [blame] | 1 | /* |
| 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älkki | 8cde852 | 2014-02-09 23:35:39 +0200 | [diff] [blame] | 15 | */ |
| 16 | |
Kyösti Mälkki | 8cde852 | 2014-02-09 23:35:39 +0200 | [diff] [blame] | 17 | #include <console/usb.h> |
| 18 | #include "ehci_debug.h" |
| 19 | |
Kyösti Mälkki | ea6736a | 2014-02-10 00:00:44 +0200 | [diff] [blame] | 20 | static void usbdebug_tx_byte(struct dbgp_pipe *pipe, unsigned char data) |
Kyösti Mälkki | 8cde852 | 2014-02-09 23:35:39 +0200 | [diff] [blame] | 21 | { |
| 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älkki | ea6736a | 2014-02-10 00:00:44 +0200 | [diff] [blame] | 32 | static void usbdebug_tx_flush(struct dbgp_pipe *pipe) |
Kyösti Mälkki | 8cde852 | 2014-02-09 23:35:39 +0200 | [diff] [blame] | 33 | { |
| 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älkki | ea6736a | 2014-02-10 00:00:44 +0200 | [diff] [blame] | 43 | static unsigned char usbdebug_rx_byte(struct dbgp_pipe *pipe) |
Kyösti Mälkki | 8cde852 | 2014-02-09 23:35:39 +0200 | [diff] [blame] | 44 | { |
| 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älkki | ea6736a | 2014-02-10 00:00:44 +0200 | [diff] [blame] | 59 | |
| 60 | void usb_tx_byte(int idx, unsigned char data) |
| 61 | { |
| 62 | usbdebug_tx_byte(dbgp_console_output(), data); |
| 63 | } |
| 64 | |
| 65 | void usb_tx_flush(int idx) |
| 66 | { |
| 67 | usbdebug_tx_flush(dbgp_console_output()); |
| 68 | } |
| 69 | |
| 70 | unsigned char usb_rx_byte(int idx) |
| 71 | { |
| 72 | return usbdebug_rx_byte(dbgp_console_input()); |
| 73 | } |
| 74 | |
| 75 | int usb_can_rx_byte(int idx) |
| 76 | { |
| 77 | return dbgp_ep_is_active(dbgp_console_input()); |
| 78 | } |