run uart_init() from console_init, just like the other console initialization functions.
[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
26 #include <uart8250.h>
27 #endif
28
29 #if CONFIG_CONSOLE_NE2K
30 #include <console/ne2k.h>
31 #endif
32
33 #ifndef __PRE_RAM__
34 #include <string.h>
35 #include <pc80/mc146818rtc.h>
36
37 /* initialize the console */
38 void console_init(void)
39 {
40         struct console_driver *driver;
41         if(get_option(&console_loglevel, "debug_level"))
42                 console_loglevel=CONFIG_DEFAULT_CONSOLE_LOGLEVEL;
43
44         for(driver = console_drivers; driver < econsole_drivers; driver++) {
45                 if (!driver->init)
46                         continue;
47                 driver->init();
48         }
49 }
50
51 static void __console_tx_byte(unsigned char byte)
52 {
53         struct console_driver *driver;
54         for(driver = console_drivers; driver < econsole_drivers; driver++) {
55                 driver->tx_byte(byte);
56         }
57 }
58
59 void console_tx_flush(void)
60 {
61         struct console_driver *driver;
62         for(driver = console_drivers; driver < econsole_drivers; driver++) {
63                 if (!driver->tx_flush)
64                         continue;
65                 driver->tx_flush();
66         }
67 }
68
69 void console_tx_byte(unsigned char byte)
70 {
71         if (byte == '\n')
72                 __console_tx_byte('\r');
73         __console_tx_byte(byte);
74 }
75
76 unsigned char console_rx_byte(void)
77 {
78         struct console_driver *driver;
79         for(driver = console_drivers; driver < econsole_drivers; driver++) {
80                 if (driver->tst_byte)
81                         break;
82         }
83         if (driver == econsole_drivers)
84                 return 0;
85         while (!driver->tst_byte());
86         return driver->rx_byte();
87 }
88
89 int console_tst_byte(void)
90 {
91         struct console_driver *driver;
92         for(driver = console_drivers; driver < econsole_drivers; driver++)
93                 if (driver->tst_byte)
94                         return driver->tst_byte();
95         return 0;
96 }
97
98 #else
99
100 void console_init(void)
101 {
102 #if CONFIG_USBDEBUG
103         enable_usbdebug(CONFIG_USBDEBUG_DEFAULT_PORT);
104         early_usbdebug_init();
105 #endif
106 #if CONFIG_CONSOLE_SERIAL8250
107         uart_init();
108 #endif
109 #if CONFIG_CONSOLE_NE2K
110         ne2k_init(CONFIG_CONSOLE_NE2K_IO_PORT);
111 #endif
112         static const char console_test[] =
113                 "\n\ncoreboot-"
114                 COREBOOT_VERSION
115                 COREBOOT_EXTRA_VERSION
116                 " "
117                 COREBOOT_BUILD
118                 " starting...\n";
119         print_info(console_test);
120 }
121 #endif