e622ad090cb6f35b25d59cb83df1097884cafd17
[coreboot.git] / src / console / uart8250mem_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 <uart8250.h>
22 #include <pc80/mc146818rtc.h>
23
24 static u32 uart_bar = 0;
25
26 static void uartmem_init(void)
27 {
28         uart_bar = uart_mem_init();
29 }
30
31 static void uartmem_tx_byte(unsigned char data)
32 {
33         if (!uart_bar)
34                 return;
35
36         uart8250_mem_tx_byte(uart_bar, data);
37 }
38
39 static void uartmem_tx_flush(void)
40 {
41         uart8250_mem_tx_flush(uart_bar);
42 }
43
44 static unsigned char uartmem_rx_byte(void)
45 {
46         if (!uart_bar)
47                 return 0;
48
49         return uart8250_mem_rx_byte(uart_bar);
50 }
51
52 static int uartmem_tst_byte(void)
53 {
54         if (!uart_bar)
55                 return 0;
56
57         return uart8250_mem_can_rx_byte(uart_bar);
58 }
59
60 static const struct console_driver uart8250mem_console __console = {
61         .init     = uartmem_init,
62         .tx_byte  = uartmem_tx_byte,
63         .tx_flush = uartmem_tx_flush,
64         .rx_byte  = uartmem_rx_byte,
65         .tst_byte = uartmem_tst_byte,
66 };