Long ago we agreed on kicking the _direct appendix because everything in
[coreboot.git] / src / console / usbdebug_console.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; version 2 of the License.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA
16  */
17
18 #include <string.h>
19 #include <console/console.h>
20 #include <usbdebug.h>
21 #include <pc80/mc146818rtc.h>
22
23 static struct ehci_debug_info dbg_info;
24
25 void set_ehci_base(unsigned ehci_base)
26 {
27         unsigned diff;
28
29         if (!dbg_info.ehci_debug)
30                 return;
31
32         diff = dbg_info.ehci_caps - ehci_base;
33         dbg_info.ehci_regs -= diff;
34         dbg_info.ehci_debug -= diff;
35         dbg_info.ehci_caps = ehci_base;
36 }
37
38 void set_ehci_debug(unsigned ehci_debug)
39 {
40         dbg_info.ehci_debug = ehci_debug;
41 }
42
43 unsigned get_ehci_debug(void)
44 {
45         return dbg_info.ehci_debug;
46 }
47
48 static void dbgp_init(void)
49 {
50         struct ehci_debug_info *dbg_infox;
51
52         /* At this point, all we have to do is copy the fixed address
53          * debug_info data structure to our version defined above. */
54
55         dbg_infox = (struct ehci_debug_info *)
56                 ((CONFIG_RAMTOP) - sizeof(struct ehci_debug_info));
57
58         memcpy(&dbg_info, dbg_infox, sizeof(struct ehci_debug_info));
59 }
60
61 static void dbgp_tx_byte(unsigned char data)
62 {
63         if (dbg_info.ehci_debug)
64                 dbgp_bulk_write_x(&dbg_info, &data, 1);
65 }
66
67 static unsigned char dbgp_rx_byte(void)
68 {
69         unsigned char data = 0xff;
70
71         if (dbg_info.ehci_debug)
72                 dbgp_bulk_read_x(&dbg_info, &data, 1);
73
74         return data;
75 }
76
77 static int dbgp_tst_byte(void)
78 {
79         return dbg_info.ehci_debug;
80 }
81
82 static const struct console_driver usbdebug_direct_console __console = {
83         .init     = dbgp_init,
84         .tx_byte  = dbgp_tx_byte,
85         .rx_byte  = dbgp_rx_byte,
86         .tst_byte = dbgp_tst_byte,
87 };