2 * This file is part of the libpayload project.
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <libpayload.h>
32 #include <video_console.h>
34 #ifdef CONFIG_GEODELX_VIDEO_CONSOLE
35 extern struct video_console geodelx_video_console;
38 #ifdef CONFIG_VGA_VIDEO_CONSOLE
39 extern struct video_console vga_video_console;
42 static struct video_console *console_list[] =
44 #ifdef CONFIG_GEODELX_VIDEO_CONSOLE
45 &geodelx_video_console,
47 #ifdef CONFIG_VGA_VIDEO_CONSOLE
52 static struct video_console *console;
56 static unsigned int cursor_enabled = 1;
58 static void video_console_fixup_cursor(void)
69 if (cursorx > VIDEO_COLS) {
74 while(cursory >= VIDEO_ROWS) {
79 if (console && console->set_cursor)
80 console->set_cursor(cursorx, cursory);
83 void video_console_cursor_enable(int state)
85 if (console && console->enable_cursor)
86 console->enable_cursor(state);
88 cursor_enabled = state;
91 video_console_fixup_cursor();
94 void video_console_clear(void)
102 if (console && console->set_cursor)
103 console->set_cursor(cursorx, cursory);
106 void video_console_putc(u8 row, u8 col, unsigned int ch)
109 console->putc(row, col, ch);
112 void video_console_putchar(unsigned int ch)
114 /* replace black-on-black with light-gray-on-black.
115 do it here, instead of in libc/console.c */
116 if ((ch & 0xFF00) == 0) {
132 cursorx = VIDEO_COLS;
137 while(cursorx % 8 && cursorx < VIDEO_COLS) {
139 console->putc(cursory, cursorx, (ch & 0xFF00) | ' ');
146 console->putc(cursory, cursorx++, ch);
150 video_console_fixup_cursor();
153 void video_console_get_cursor(unsigned int *x, unsigned int *y, unsigned int *en)
159 if (console->get_cursor)
160 console->get_cursor(x, y, en);
166 void video_console_set_cursor(unsigned int x, unsigned int y)
170 video_console_fixup_cursor();
173 static struct console_output_driver cons = {
174 .putchar = video_console_putchar
177 int video_console_init(void)
181 for(i = 0; i < ARRAY_SIZE(console_list); i++) {
182 if (console_list[i]->init())
185 console = console_list[i];
187 if (console->get_cursor)
188 console->get_cursor((unsigned int*)&cursorx, (unsigned int*)&cursory, &cursor_enabled);
195 video_console_fixup_cursor();
196 console_add_output_driver(&cons);