blob: 8df6417e6049275a136087aa7eceecd10b3cfbb0 [file] [log] [blame]
Stefan Reinauerbb01f602009-07-21 21:20:45 +00001/*
2 * This file is part of the coreboot project.
3 *
Uwe Hermann06694a82010-09-23 18:16:46 +00004 * Copyright (C) 2007 AMD
5 * Written by Yinghai Lu <yinghai.lu@amd.com> for AMD.
6 *
Stefan Reinauerbb01f602009-07-21 21:20:45 +00007 * 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.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
19 */
20
Patrick Georgi16cdbb22009-04-21 20:14:31 +000021#include <string.h>
Yinghai Lud57241f2007-02-28 11:17:02 +000022#include <console/console.h>
Stefan Reinauerda323732010-05-25 16:17:45 +000023#include <usbdebug.h>
Kyösti Mälkkifb387df2013-06-07 22:16:52 +030024
Yinghai Lud57241f2007-02-28 11:17:02 +000025static void dbgp_init(void)
26{
Kyösti Mälkki9e7806a2013-07-06 11:56:49 +030027 usbdebug_init();
Yinghai Lud57241f2007-02-28 11:17:02 +000028}
29
Stefan Reinauerbb01f602009-07-21 21:20:45 +000030static void dbgp_tx_byte(unsigned char data)
Yinghai Lud57241f2007-02-28 11:17:02 +000031{
Kyösti Mälkki9e7806a2013-07-06 11:56:49 +030032 usbdebug_tx_byte(dbgp_console_output(), data);
Yinghai Lud57241f2007-02-28 11:17:02 +000033}
34
Stefan Reinauerbb01f602009-07-21 21:20:45 +000035static unsigned char dbgp_rx_byte(void)
Yinghai Lud57241f2007-02-28 11:17:02 +000036{
37 unsigned char data = 0xff;
Stefan Reinauerbb01f602009-07-21 21:20:45 +000038
Kyösti Mälkki9e7806a2013-07-06 11:56:49 +030039 if (dbgp_ep_is_active(dbgp_console_input()))
40 dbgp_bulk_read_x(dbgp_console_input(), &data, 1);
Stefan Reinauerbb01f602009-07-21 21:20:45 +000041
Yinghai Lud57241f2007-02-28 11:17:02 +000042 return data;
43}
44
Sven Schnelle82704c62012-07-26 14:31:40 +020045static void dbgp_tx_flush(void)
46{
Kyösti Mälkki9e7806a2013-07-06 11:56:49 +030047 usbdebug_tx_flush(dbgp_console_output());
Sven Schnelle82704c62012-07-26 14:31:40 +020048}
49
Stefan Reinauerbb01f602009-07-21 21:20:45 +000050static int dbgp_tst_byte(void)
Yinghai Lud57241f2007-02-28 11:17:02 +000051{
Kyösti Mälkki9e7806a2013-07-06 11:56:49 +030052 return dbgp_ep_is_active(dbgp_console_input());
Yinghai Lud57241f2007-02-28 11:17:02 +000053}
54
Stefan Reinauerbf873e42007-10-24 14:42:12 +000055static const struct console_driver usbdebug_direct_console __console = {
Stefan Reinauerbb01f602009-07-21 21:20:45 +000056 .init = dbgp_init,
57 .tx_byte = dbgp_tx_byte,
Sven Schnelle82704c62012-07-26 14:31:40 +020058 .tx_flush = dbgp_tx_flush,
Stefan Reinauerbb01f602009-07-21 21:20:45 +000059 .rx_byte = dbgp_rx_byte,
Yinghai Lud57241f2007-02-28 11:17:02 +000060 .tst_byte = dbgp_tst_byte,
61};