blob: dfd2a8496e72e10fcec3fcbad750babac54aea8e [file] [log] [blame]
wdenk7a8e9bed2003-05-31 18:35:21 +00001/*
2 * (C) Copyright 2002
Albert ARIBAUDfa82f872011-08-04 18:45:45 +02003 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
wdenk7a8e9bed2003-05-31 18:35:21 +00004 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenk7a8e9bed2003-05-31 18:35:21 +00006 */
7
wdenk8bde7f72003-06-27 21:31:46 +00008#include <common.h>
9#include <pci.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020010#include <stdio_dev.h>
wdenk7a8e9bed2003-05-31 18:35:21 +000011#include <i8042.h>
wdenk8bde7f72003-06-27 21:31:46 +000012#include <asm/ptrace.h>
wdenk8bde7f72003-06-27 21:31:46 +000013#include <asm/io.h>
14#include <asm/pci.h>
wdenk7a8e9bed2003-05-31 18:35:21 +000015
wdenk7a8e9bed2003-05-31 18:35:21 +000016/* basic textmode I/O from linux kernel */
17static char *vidmem = (char *)0xb8000;
18static int vidport;
19static int lines, cols;
20static int orig_x, orig_y;
21
22static void beep(int dur)
23{
24 int i;
wdenk8bde7f72003-06-27 21:31:46 +000025
wdenk7a8e9bed2003-05-31 18:35:21 +000026 outb_p(3, 0x61);
Graeme Russdbf71152011-04-13 19:43:26 +100027 for (i = 0; i < 10*dur; i++)
wdenk7a8e9bed2003-05-31 18:35:21 +000028 udelay(1000);
Graeme Russdbf71152011-04-13 19:43:26 +100029
wdenk7a8e9bed2003-05-31 18:35:21 +000030 outb_p(0, 0x61);
31}
32
33static void scroll(void)
34{
35 int i;
36
Graeme Russdbf71152011-04-13 19:43:26 +100037 memcpy(vidmem, vidmem + cols * 2, (lines - 1) * cols * 2);
38 for (i = (lines - 1) * cols * 2; i < lines * cols * 2; i += 2)
wdenk7a8e9bed2003-05-31 18:35:21 +000039 vidmem[i] = ' ';
40}
41
42static void __video_putc(const char c, int *x, int *y)
43{
44 if (c == '\n') {
wdenk8bde7f72003-06-27 21:31:46 +000045 (*x) = 0;
Graeme Russdbf71152011-04-13 19:43:26 +100046 if (++(*y) >= lines) {
wdenk7a8e9bed2003-05-31 18:35:21 +000047 scroll();
48 (*y)--;
49 }
wdenk8bde7f72003-06-27 21:31:46 +000050 } else if (c == '\b') {
wdenk7a8e9bed2003-05-31 18:35:21 +000051 if ((*x) != 0) {
52 --(*x);
Graeme Russdbf71152011-04-13 19:43:26 +100053 vidmem[((*x) + cols * (*y)) * 2] = ' ';
wdenk7a8e9bed2003-05-31 18:35:21 +000054 }
wdenk8bde7f72003-06-27 21:31:46 +000055 } else if (c == '\r') {
wdenk7a8e9bed2003-05-31 18:35:21 +000056 (*x) = 0;
wdenk8bde7f72003-06-27 21:31:46 +000057
58 } else if (c == '\a') {
wdenk7a8e9bed2003-05-31 18:35:21 +000059 beep(3);
wdenk8bde7f72003-06-27 21:31:46 +000060
61 } else if (c == '\t') {
wdenk7a8e9bed2003-05-31 18:35:21 +000062 __video_putc(' ', x, y);
63 __video_putc(' ', x, y);
64 __video_putc(' ', x, y);
65 __video_putc(' ', x, y);
66 __video_putc(' ', x, y);
67 __video_putc(' ', x, y);
68 __video_putc(' ', x, y);
69 __video_putc(' ', x, y);
wdenk8bde7f72003-06-27 21:31:46 +000070 } else if (c == '\v') {
wdenk7a8e9bed2003-05-31 18:35:21 +000071 switch ((*x) % 8) {
72 case 0:
73 __video_putc(' ', x, y);
74 case 7:
75 __video_putc(' ', x, y);
76 case 6:
77 __video_putc(' ', x, y);
78 case 5:
79 __video_putc(' ', x, y);
80 case 4:
81 __video_putc(' ', x, y);
82 case 3:
83 __video_putc(' ', x, y);
84 case 2:
85 __video_putc(' ', x, y);
86 case 1:
87 __video_putc(' ', x, y);
88 }
wdenk8bde7f72003-06-27 21:31:46 +000089 } else if (c == '\f') {
wdenk7a8e9bed2003-05-31 18:35:21 +000090 int i;
Graeme Russdbf71152011-04-13 19:43:26 +100091 for (i = 0; i < lines * cols * 2; i += 2)
wdenk7a8e9bed2003-05-31 18:35:21 +000092 vidmem[i] = 0;
wdenk7a8e9bed2003-05-31 18:35:21 +000093 (*x) = 0;
94 (*y) = 0;
95 } else {
Graeme Russdbf71152011-04-13 19:43:26 +100096 vidmem[((*x) + cols * (*y)) * 2] = c;
97 if (++(*x) >= cols) {
wdenk7a8e9bed2003-05-31 18:35:21 +000098 (*x) = 0;
Graeme Russdbf71152011-04-13 19:43:26 +100099 if (++(*y) >= lines) {
wdenk7a8e9bed2003-05-31 18:35:21 +0000100 scroll();
101 (*y)--;
102 }
103 }
104 }
105}
106
107static void video_putc(const char c)
108{
Graeme Russ83088af2011-11-08 02:33:15 +0000109 int x, y, pos;
wdenk8bde7f72003-06-27 21:31:46 +0000110
wdenk7a8e9bed2003-05-31 18:35:21 +0000111 x = orig_x;
112 y = orig_y;
wdenk8bde7f72003-06-27 21:31:46 +0000113
wdenk7a8e9bed2003-05-31 18:35:21 +0000114 __video_putc(c, &x, &y);
115
116 orig_x = x;
117 orig_y = y;
wdenk8bde7f72003-06-27 21:31:46 +0000118
wdenk7a8e9bed2003-05-31 18:35:21 +0000119 pos = (x + cols * y) * 2; /* Update cursor position */
120 outb_p(14, vidport);
121 outb_p(0xff & (pos >> 9), vidport+1);
122 outb_p(15, vidport);
123 outb_p(0xff & (pos >> 1), vidport+1);
124}
125
126static void video_puts(const char *s)
127{
Graeme Russ83088af2011-11-08 02:33:15 +0000128 int x, y, pos;
wdenk7a8e9bed2003-05-31 18:35:21 +0000129 char c;
130
131 x = orig_x;
132 y = orig_y;
133
Graeme Russdbf71152011-04-13 19:43:26 +1000134 while ((c = *s++) != '\0')
wdenk7a8e9bed2003-05-31 18:35:21 +0000135 __video_putc(c, &x, &y);
wdenk7a8e9bed2003-05-31 18:35:21 +0000136
137 orig_x = x;
138 orig_y = y;
139
140 pos = (x + cols * y) * 2; /* Update cursor position */
141 outb_p(14, vidport);
142 outb_p(0xff & (pos >> 9), vidport+1);
143 outb_p(15, vidport);
144 outb_p(0xff & (pos >> 1), vidport+1);
145}
146
147int video_init(void)
148{
149 u16 pos;
wdenk8bde7f72003-06-27 21:31:46 +0000150
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200151 static struct stdio_dev vga_dev;
152 static struct stdio_dev kbd_dev;
wdenk8bde7f72003-06-27 21:31:46 +0000153
wdenk7a8e9bed2003-05-31 18:35:21 +0000154 vidmem = (char *) 0xb8000;
155 vidport = 0x3d4;
156
157 lines = 25;
158 cols = 80;
wdenk8bde7f72003-06-27 21:31:46 +0000159
wdenk7a8e9bed2003-05-31 18:35:21 +0000160 outb_p(14, vidport);
161 pos = inb_p(vidport+1);
162 pos <<= 8;
163 outb_p(15, vidport);
164 pos |= inb_p(vidport+1);
wdenk8bde7f72003-06-27 21:31:46 +0000165
wdenk7a8e9bed2003-05-31 18:35:21 +0000166 orig_x = pos%cols;
167 orig_y = pos/cols;
168
wdenk8bde7f72003-06-27 21:31:46 +0000169#if 0
wdenk7a8e9bed2003-05-31 18:35:21 +0000170 printf("pos %x %d %d\n", pos, orig_x, orig_y);
wdenk8bde7f72003-06-27 21:31:46 +0000171#endif
Graeme Russdbf71152011-04-13 19:43:26 +1000172 if (orig_y > lines)
Graeme Russ83088af2011-11-08 02:33:15 +0000173 orig_x = orig_y = 0;
wdenk8bde7f72003-06-27 21:31:46 +0000174
175 memset(&vga_dev, 0, sizeof(vga_dev));
176 strcpy(vga_dev.name, "vga");
177 vga_dev.ext = 0;
178 vga_dev.flags = DEV_FLAGS_OUTPUT | DEV_FLAGS_SYSTEM;
179 vga_dev.putc = video_putc; /* 'putc' function */
180 vga_dev.puts = video_puts; /* 'puts' function */
181 vga_dev.tstc = NULL; /* 'tstc' function */
182 vga_dev.getc = NULL; /* 'getc' function */
183
Graeme Russdbf71152011-04-13 19:43:26 +1000184 if (stdio_register(&vga_dev) == 0)
wdenk7a8e9bed2003-05-31 18:35:21 +0000185 return 1;
Graeme Russdbf71152011-04-13 19:43:26 +1000186
187 if (i8042_kbd_init())
188 return 1;
wdenk7a8e9bed2003-05-31 18:35:21 +0000189
wdenk8bde7f72003-06-27 21:31:46 +0000190 memset(&kbd_dev, 0, sizeof(kbd_dev));
191 strcpy(kbd_dev.name, "kbd");
192 kbd_dev.ext = 0;
193 kbd_dev.flags = DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
194 kbd_dev.putc = NULL; /* 'putc' function */
195 kbd_dev.puts = NULL; /* 'puts' function */
196 kbd_dev.tstc = i8042_tstc; /* 'tstc' function */
197 kbd_dev.getc = i8042_getc; /* 'getc' function */
198
Graeme Russdbf71152011-04-13 19:43:26 +1000199 if (stdio_register(&kbd_dev) == 0)
200 return 1;
201
wdenk7a8e9bed2003-05-31 18:35:21 +0000202 return 0;
203}
204
205
wdenk8bde7f72003-06-27 21:31:46 +0000206int drv_video_init(void)
wdenk7a8e9bed2003-05-31 18:35:21 +0000207{
wdenk8bde7f72003-06-27 21:31:46 +0000208 return video_init();
wdenk7a8e9bed2003-05-31 18:35:21 +0000209}