]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/x86/lib/video.c
mxc_ipuv3: fix memory alignment of framebuffer
[karo-tx-uboot.git] / arch / x86 / lib / video.c
1 /*
2  * (C) Copyright 2002
3  * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
4  *
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
24 #include <common.h>
25 #include <pci.h>
26 #include <stdio_dev.h>
27 #include <i8042.h>
28 #include <asm/ptrace.h>
29 #include <asm/io.h>
30 #include <asm/pci.h>
31
32 /* basic textmode I/O from linux kernel */
33 static char *vidmem = (char *)0xb8000;
34 static int vidport;
35 static int lines, cols;
36 static int orig_x, orig_y;
37
38 static void beep(int dur)
39 {
40         int i;
41
42         outb_p(3, 0x61);
43         for (i = 0; i < 10*dur; i++)
44                 udelay(1000);
45
46         outb_p(0, 0x61);
47 }
48
49 static void scroll(void)
50 {
51         int i;
52
53         memcpy(vidmem, vidmem + cols * 2, (lines - 1) * cols * 2);
54         for (i = (lines - 1) * cols * 2; i < lines * cols * 2; i += 2)
55                 vidmem[i] = ' ';
56 }
57
58 static void __video_putc(const char c, int *x, int *y)
59 {
60         if (c == '\n') {
61                 (*x) = 0;
62                 if (++(*y) >= lines) {
63                         scroll();
64                         (*y)--;
65                 }
66         } else if (c == '\b') {
67                 if ((*x) != 0) {
68                         --(*x);
69                         vidmem[((*x) + cols * (*y)) * 2] = ' ';
70                 }
71         } else if (c == '\r') {
72                 (*x) = 0;
73
74         } else if (c == '\a') {
75                 beep(3);
76
77         } else if (c == '\t') {
78                 __video_putc(' ', x, y);
79                 __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         } else if (c == '\v') {
87                 switch ((*x) % 8) {
88                 case 0:
89                         __video_putc(' ', x, y);
90                 case 7:
91                         __video_putc(' ', x, y);
92                 case 6:
93                         __video_putc(' ', x, y);
94                 case 5:
95                         __video_putc(' ', x, y);
96                 case 4:
97                         __video_putc(' ', x, y);
98                 case 3:
99                         __video_putc(' ', x, y);
100                 case 2:
101                         __video_putc(' ', x, y);
102                 case 1:
103                         __video_putc(' ', x, y);
104                 }
105         } else if (c == '\f') {
106                 int i;
107                 for (i = 0; i < lines * cols * 2; i += 2)
108                         vidmem[i] = 0;
109                 (*x) = 0;
110                 (*y) = 0;
111         } else {
112                 vidmem[((*x) + cols * (*y)) * 2] = c;
113                 if (++(*x) >= cols) {
114                         (*x) = 0;
115                         if (++(*y) >= lines) {
116                                 scroll();
117                                 (*y)--;
118                         }
119                 }
120         }
121 }
122
123 static void video_putc(const char c)
124 {
125         int x, y, pos;
126
127         x = orig_x;
128         y = orig_y;
129
130         __video_putc(c, &x, &y);
131
132         orig_x = x;
133         orig_y = y;
134
135         pos = (x + cols * y) * 2;       /* Update cursor position */
136         outb_p(14, vidport);
137         outb_p(0xff & (pos >> 9), vidport+1);
138         outb_p(15, vidport);
139         outb_p(0xff & (pos >> 1), vidport+1);
140 }
141
142 static void video_puts(const char *s)
143 {
144         int x, y, pos;
145         char c;
146
147         x = orig_x;
148         y = orig_y;
149
150         while ((c = *s++) != '\0')
151                 __video_putc(c, &x, &y);
152
153         orig_x = x;
154         orig_y = y;
155
156         pos = (x + cols * y) * 2;       /* Update cursor position */
157         outb_p(14, vidport);
158         outb_p(0xff & (pos >> 9), vidport+1);
159         outb_p(15, vidport);
160         outb_p(0xff & (pos >> 1), vidport+1);
161 }
162
163 int video_init(void)
164 {
165         u16 pos;
166
167         static struct stdio_dev vga_dev;
168         static struct stdio_dev kbd_dev;
169
170         vidmem = (char *) 0xb8000;
171         vidport = 0x3d4;
172
173         lines = 25;
174         cols = 80;
175
176         outb_p(14, vidport);
177         pos = inb_p(vidport+1);
178         pos <<= 8;
179         outb_p(15, vidport);
180         pos |= inb_p(vidport+1);
181
182         orig_x = pos%cols;
183         orig_y = pos/cols;
184
185 #if 0
186         printf("pos %x %d %d\n", pos, orig_x, orig_y);
187 #endif
188         if (orig_y > lines)
189                 orig_x = orig_y = 0;
190
191         memset(&vga_dev, 0, sizeof(vga_dev));
192         strcpy(vga_dev.name, "vga");
193         vga_dev.ext   = 0;
194         vga_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
195         vga_dev.putc  = video_putc;        /* 'putc' function */
196         vga_dev.puts  = video_puts;        /* 'puts' function */
197         vga_dev.tstc  = NULL;              /* 'tstc' function */
198         vga_dev.getc  = NULL;              /* 'getc' function */
199
200         if (stdio_register(&vga_dev) == 0)
201                 return 1;
202
203         if (i8042_kbd_init())
204                 return 1;
205
206         memset(&kbd_dev, 0, sizeof(kbd_dev));
207         strcpy(kbd_dev.name, "kbd");
208         kbd_dev.ext   = 0;
209         kbd_dev.flags = DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
210         kbd_dev.putc  = NULL;        /* 'putc' function */
211         kbd_dev.puts  = NULL;        /* 'puts' function */
212         kbd_dev.tstc  = i8042_tstc;  /* 'tstc' function */
213         kbd_dev.getc  = i8042_getc;  /* 'getc' function */
214
215         if (stdio_register(&kbd_dev) == 0)
216                 return 1;
217
218         return 0;
219 }
220
221
222 int drv_video_init(void)
223 {
224         return video_init();
225 }