Fix usb debug dongle support
[coreboot.git] / src / console / console.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2003 Eric Biederman
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; version 2 of the License.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19
20 #include <console/console.h>
21 #include <build.h>
22 #include <arch/hlt.h>
23 #include <arch/io.h>
24
25 #if CONFIG_CONSOLE_SERIAL8250 || CONFIG_CONSOLE_SERIAL8250MEM
26 #include <uart8250.h>
27 #endif
28
29 #if CONFIG_CONSOLE_NE2K
30 #include <console/ne2k.h>
31 #endif
32
33 #if CONFIG_USBDEBUG
34 #include <usbdebug.h>
35 #endif
36
37 #ifndef __PRE_RAM__
38 #include <string.h>
39 #include <pc80/mc146818rtc.h>
40
41 /* initialize the console */
42 void console_init(void)
43 {
44         struct console_driver *driver;
45         if(get_option(&console_loglevel, "debug_level"))
46                 console_loglevel=CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
47
48         for(driver = console_drivers; driver < econsole_drivers; driver++) {
49                 if (!driver->init)
50                         continue;
51                 driver->init();
52         }
53 }
54
55 static void __console_tx_byte(unsigned char byte)
56 {
57         struct console_driver *driver;
58         for(driver = console_drivers; driver < econsole_drivers; driver++) {
59                 driver->tx_byte(byte);
60         }
61 }
62
63 void console_tx_flush(void)
64 {
65         struct console_driver *driver;
66         for(driver = console_drivers; driver < econsole_drivers; driver++) {
67                 if (!driver->tx_flush)
68                         continue;
69                 driver->tx_flush();
70         }
71 }
72
73 void console_tx_byte(unsigned char byte)
74 {
75         if (byte == '\n')
76                 __console_tx_byte('\r');
77         __console_tx_byte(byte);
78 }
79
80 unsigned char console_rx_byte(void)
81 {
82         struct console_driver *driver;
83         for(driver = console_drivers; driver < econsole_drivers; driver++) {
84                 if (driver->tst_byte)
85                         break;
86         }
87         if (driver == econsole_drivers)
88                 return 0;
89         while (!driver->tst_byte());
90         return driver->rx_byte();
91 }
92
93 int console_tst_byte(void)
94 {
95         struct console_driver *driver;
96         for(driver = console_drivers; driver < econsole_drivers; driver++)
97                 if (driver->tst_byte)
98                         return driver->tst_byte();
99         return 0;
100 }
101
102 #else
103
104 void console_init(void)
105 {
106 #if CONFIG_USBDEBUG
107         enable_usbdebug(CONFIG_USBDEBUG_DEFAULT_PORT);
108         early_usbdebug_init();
109 #endif
110 #if CONFIG_CONSOLE_SERIAL8250
111         uart_init();
112 #endif
113 #if CONFIG_DRIVERS_OXFORD_OXPCIE && CONFIG_CONSOLE_SERIAL8250MEM
114         oxford_init();
115 #endif
116 #if CONFIG_CONSOLE_NE2K
117         ne2k_init(CONFIG_CONSOLE_NE2K_IO_PORT);
118 #endif
119         static const char console_test[] =
120                 "\n\ncoreboot-"
121                 COREBOOT_VERSION
122                 COREBOOT_EXTRA_VERSION
123                 " "
124                 COREBOOT_BUILD
125                 " starting...\n";
126         print_info(console_test);
127 }
128 #endif