blob: b29075c490a48ce14e3c3c485fdb21bbcc198172 [file] [log] [blame]
wdenk7a8e9bed2003-05-31 18:35:21 +00001/*
2 * (C) Copyright 2002
Graeme Russdbf71152011-04-13 19:43:26 +10003 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
wdenk7a8e9bed2003-05-31 18:35:21 +00004 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
21 * MA 02111-1307 USA
22 */
23
wdenk8bde7f72003-06-27 21:31:46 +000024#include <common.h>
25#include <pci.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020026#include <stdio_dev.h>
wdenk7a8e9bed2003-05-31 18:35:21 +000027#include <i8042.h>
wdenk8bde7f72003-06-27 21:31:46 +000028#include <asm/ptrace.h>
29#include <asm/realmode.h>
30#include <asm/io.h>
31#include <asm/pci.h>
wdenk7a8e9bed2003-05-31 18:35:21 +000032
wdenk7a8e9bed2003-05-31 18:35:21 +000033/* basic textmode I/O from linux kernel */
34static char *vidmem = (char *)0xb8000;
35static int vidport;
36static int lines, cols;
37static int orig_x, orig_y;
38
39static void beep(int dur)
40{
41 int i;
wdenk8bde7f72003-06-27 21:31:46 +000042
wdenk7a8e9bed2003-05-31 18:35:21 +000043 outb_p(3, 0x61);
Graeme Russdbf71152011-04-13 19:43:26 +100044 for (i = 0; i < 10*dur; i++)
wdenk7a8e9bed2003-05-31 18:35:21 +000045 udelay(1000);
Graeme Russdbf71152011-04-13 19:43:26 +100046
wdenk7a8e9bed2003-05-31 18:35:21 +000047 outb_p(0, 0x61);
48}
49
50static void scroll(void)
51{
52 int i;
53
Graeme Russdbf71152011-04-13 19:43:26 +100054 memcpy(vidmem, vidmem + cols * 2, (lines - 1) * cols * 2);
55 for (i = (lines - 1) * cols * 2; i < lines * cols * 2; i += 2)
wdenk7a8e9bed2003-05-31 18:35:21 +000056 vidmem[i] = ' ';
57}
58
59static void __video_putc(const char c, int *x, int *y)
60{
61 if (c == '\n') {
wdenk8bde7f72003-06-27 21:31:46 +000062 (*x) = 0;
Graeme Russdbf71152011-04-13 19:43:26 +100063 if (++(*y) >= lines) {
wdenk7a8e9bed2003-05-31 18:35:21 +000064 scroll();
65 (*y)--;
66 }
wdenk8bde7f72003-06-27 21:31:46 +000067 } else if (c == '\b') {
wdenk7a8e9bed2003-05-31 18:35:21 +000068 if ((*x) != 0) {
69 --(*x);
Graeme Russdbf71152011-04-13 19:43:26 +100070 vidmem[((*x) + cols * (*y)) * 2] = ' ';
wdenk7a8e9bed2003-05-31 18:35:21 +000071 }
wdenk8bde7f72003-06-27 21:31:46 +000072 } else if (c == '\r') {
wdenk7a8e9bed2003-05-31 18:35:21 +000073 (*x) = 0;
wdenk8bde7f72003-06-27 21:31:46 +000074
75 } else if (c == '\a') {
wdenk7a8e9bed2003-05-31 18:35:21 +000076 beep(3);
wdenk8bde7f72003-06-27 21:31:46 +000077
78 } else if (c == '\t') {
wdenk7a8e9bed2003-05-31 18:35:21 +000079 __video_putc(' ', x, y);
80 __video_putc(' ', x, y);
81 __video_putc(' ', x, y);
82 __video_putc(' ', x, y);
83 __video_putc(' ', x, y);
84 __video_putc(' ', x, y);
85 __video_putc(' ', x, y);
86 __video_putc(' ', x, y);
wdenk8bde7f72003-06-27 21:31:46 +000087 } else if (c == '\v') {
wdenk7a8e9bed2003-05-31 18:35:21 +000088 switch ((*x) % 8) {
89 case 0:
90 __video_putc(' ', x, y);
91 case 7:
92 __video_putc(' ', x, y);
93 case 6:
94 __video_putc(' ', x, y);
95 case 5:
96 __video_putc(' ', x, y);
97 case 4:
98 __video_putc(' ', x, y);
99 case 3:
100 __video_putc(' ', x, y);
101 case 2:
102 __video_putc(' ', x, y);
103 case 1:
104 __video_putc(' ', x, y);
105 }
wdenk8bde7f72003-06-27 21:31:46 +0000106 } else if (c == '\f') {
wdenk7a8e9bed2003-05-31 18:35:21 +0000107 int i;
Graeme Russdbf71152011-04-13 19:43:26 +1000108 for (i = 0; i < lines * cols * 2; i += 2)
wdenk7a8e9bed2003-05-31 18:35:21 +0000109 vidmem[i] = 0;
wdenk7a8e9bed2003-05-31 18:35:21 +0000110 (*x) = 0;
111 (*y) = 0;
112 } else {
Graeme Russdbf71152011-04-13 19:43:26 +1000113 vidmem[((*x) + cols * (*y)) * 2] = c;
114 if (++(*x) >= cols) {
wdenk7a8e9bed2003-05-31 18:35:21 +0000115 (*x) = 0;
Graeme Russdbf71152011-04-13 19:43:26 +1000116 if (++(*y) >= lines) {
wdenk7a8e9bed2003-05-31 18:35:21 +0000117 scroll();
118 (*y)--;
119 }
120 }
121 }
122}
123
124static void video_putc(const char c)
125{
126 int x,y,pos;
wdenk8bde7f72003-06-27 21:31:46 +0000127
wdenk7a8e9bed2003-05-31 18:35:21 +0000128 x = orig_x;
129 y = orig_y;
wdenk8bde7f72003-06-27 21:31:46 +0000130
wdenk7a8e9bed2003-05-31 18:35:21 +0000131 __video_putc(c, &x, &y);
132
133 orig_x = x;
134 orig_y = y;
wdenk8bde7f72003-06-27 21:31:46 +0000135
wdenk7a8e9bed2003-05-31 18:35:21 +0000136 pos = (x + cols * y) * 2; /* Update cursor position */
137 outb_p(14, vidport);
138 outb_p(0xff & (pos >> 9), vidport+1);
139 outb_p(15, vidport);
140 outb_p(0xff & (pos >> 1), vidport+1);
141}
142
143static void video_puts(const char *s)
144{
145 int x,y,pos;
146 char c;
147
148 x = orig_x;
149 y = orig_y;
150
Graeme Russdbf71152011-04-13 19:43:26 +1000151 while ((c = *s++) != '\0')
wdenk7a8e9bed2003-05-31 18:35:21 +0000152 __video_putc(c, &x, &y);
wdenk7a8e9bed2003-05-31 18:35:21 +0000153
154 orig_x = x;
155 orig_y = y;
156
157 pos = (x + cols * y) * 2; /* Update cursor position */
158 outb_p(14, vidport);
159 outb_p(0xff & (pos >> 9), vidport+1);
160 outb_p(15, vidport);
161 outb_p(0xff & (pos >> 1), vidport+1);
162}
163
164int video_init(void)
165{
166 u16 pos;
wdenk8bde7f72003-06-27 21:31:46 +0000167
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200168 static struct stdio_dev vga_dev;
169 static struct stdio_dev kbd_dev;
wdenk8bde7f72003-06-27 21:31:46 +0000170
wdenk7a8e9bed2003-05-31 18:35:21 +0000171 vidmem = (char *) 0xb8000;
172 vidport = 0x3d4;
173
174 lines = 25;
175 cols = 80;
wdenk8bde7f72003-06-27 21:31:46 +0000176
wdenk7a8e9bed2003-05-31 18:35:21 +0000177 outb_p(14, vidport);
178 pos = inb_p(vidport+1);
179 pos <<= 8;
180 outb_p(15, vidport);
181 pos |= inb_p(vidport+1);
wdenk8bde7f72003-06-27 21:31:46 +0000182
wdenk7a8e9bed2003-05-31 18:35:21 +0000183 orig_x = pos%cols;
184 orig_y = pos/cols;
185
wdenk8bde7f72003-06-27 21:31:46 +0000186#if 0
wdenk7a8e9bed2003-05-31 18:35:21 +0000187 printf("pos %x %d %d\n", pos, orig_x, orig_y);
wdenk8bde7f72003-06-27 21:31:46 +0000188#endif
Graeme Russdbf71152011-04-13 19:43:26 +1000189 if (orig_y > lines)
wdenk7a8e9bed2003-05-31 18:35:21 +0000190 orig_x = orig_y =0;
wdenk8bde7f72003-06-27 21:31:46 +0000191
192 memset(&vga_dev, 0, sizeof(vga_dev));
193 strcpy(vga_dev.name, "vga");
194 vga_dev.ext = 0;
195 vga_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
196 vga_dev.putc = video_putc; /* 'putc' function */
197 vga_dev.puts = video_puts; /* 'puts' function */
198 vga_dev.tstc = NULL; /* 'tstc' function */
199 vga_dev.getc = NULL; /* 'getc' function */
200
Graeme Russdbf71152011-04-13 19:43:26 +1000201 if (stdio_register(&vga_dev) == 0)
wdenk7a8e9bed2003-05-31 18:35:21 +0000202 return 1;
Graeme Russdbf71152011-04-13 19:43:26 +1000203
204 if (i8042_kbd_init())
205 return 1;
wdenk7a8e9bed2003-05-31 18:35:21 +0000206
wdenk8bde7f72003-06-27 21:31:46 +0000207 memset(&kbd_dev, 0, sizeof(kbd_dev));
208 strcpy(kbd_dev.name, "kbd");
209 kbd_dev.ext = 0;
210 kbd_dev.flags = DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
211 kbd_dev.putc = NULL; /* 'putc' function */
212 kbd_dev.puts = NULL; /* 'puts' function */
213 kbd_dev.tstc = i8042_tstc; /* 'tstc' function */
214 kbd_dev.getc = i8042_getc; /* 'getc' function */
215
Graeme Russdbf71152011-04-13 19:43:26 +1000216 if (stdio_register(&kbd_dev) == 0)
217 return 1;
218
wdenk7a8e9bed2003-05-31 18:35:21 +0000219 return 0;
220}
221
222
wdenk8bde7f72003-06-27 21:31:46 +0000223int drv_video_init(void)
wdenk7a8e9bed2003-05-31 18:35:21 +0000224{
Graeme Russdbf71152011-04-13 19:43:26 +1000225 if (video_bios_init())
wdenk7a8e9bed2003-05-31 18:35:21 +0000226 return 1;
wdenk8bde7f72003-06-27 21:31:46 +0000227
228 return video_init();
wdenk7a8e9bed2003-05-31 18:35:21 +0000229}