blob: 975949daa3e689495cb3146118cdd30bd649110b [file] [log] [blame]
wdenkabda5ca2003-05-31 18:35:21 +00001/*
2 * (C) Copyright 2002
Albert ARIBAUD60fbc8d2011-08-04 18:45:45 +02003 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
wdenkabda5ca2003-05-31 18:35:21 +00004 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02005 * SPDX-License-Identifier: GPL-2.0+
wdenkabda5ca2003-05-31 18:35:21 +00006 */
7
wdenk57b2d802003-06-27 21:31:46 +00008#include <common.h>
9#include <pci.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +020010#include <stdio_dev.h>
wdenkabda5ca2003-05-31 18:35:21 +000011#include <i8042.h>
wdenk57b2d802003-06-27 21:31:46 +000012#include <asm/ptrace.h>
wdenk57b2d802003-06-27 21:31:46 +000013#include <asm/io.h>
14#include <asm/pci.h>
wdenkabda5ca2003-05-31 18:35:21 +000015
wdenkabda5ca2003-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;
wdenk57b2d802003-06-27 21:31:46 +000025
wdenkabda5ca2003-05-31 18:35:21 +000026 outb_p(3, 0x61);
Graeme Russ45fc1d82011-04-13 19:43:26 +100027 for (i = 0; i < 10*dur; i++)
wdenkabda5ca2003-05-31 18:35:21 +000028 udelay(1000);
Graeme Russ45fc1d82011-04-13 19:43:26 +100029
wdenkabda5ca2003-05-31 18:35:21 +000030 outb_p(0, 0x61);
31}
32
33static void scroll(void)
34{
35 int i;
36
Graeme Russ45fc1d82011-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)
wdenkabda5ca2003-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') {
wdenk57b2d802003-06-27 21:31:46 +000045 (*x) = 0;
Graeme Russ45fc1d82011-04-13 19:43:26 +100046 if (++(*y) >= lines) {
wdenkabda5ca2003-05-31 18:35:21 +000047 scroll();
48 (*y)--;
49 }
wdenk57b2d802003-06-27 21:31:46 +000050 } else if (c == '\b') {
wdenkabda5ca2003-05-31 18:35:21 +000051 if ((*x) != 0) {
52 --(*x);
Graeme Russ45fc1d82011-04-13 19:43:26 +100053 vidmem[((*x) + cols * (*y)) * 2] = ' ';
wdenkabda5ca2003-05-31 18:35:21 +000054 }
wdenk57b2d802003-06-27 21:31:46 +000055 } else if (c == '\r') {
wdenkabda5ca2003-05-31 18:35:21 +000056 (*x) = 0;
wdenk57b2d802003-06-27 21:31:46 +000057
58 } else if (c == '\a') {
wdenkabda5ca2003-05-31 18:35:21 +000059 beep(3);
wdenk57b2d802003-06-27 21:31:46 +000060
61 } else if (c == '\t') {
wdenkabda5ca2003-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);
wdenk57b2d802003-06-27 21:31:46 +000070 } else if (c == '\v') {
wdenkabda5ca2003-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 }
wdenk57b2d802003-06-27 21:31:46 +000089 } else if (c == '\f') {
wdenkabda5ca2003-05-31 18:35:21 +000090 int i;
Graeme Russ45fc1d82011-04-13 19:43:26 +100091 for (i = 0; i < lines * cols * 2; i += 2)
wdenkabda5ca2003-05-31 18:35:21 +000092 vidmem[i] = 0;
wdenkabda5ca2003-05-31 18:35:21 +000093 (*x) = 0;
94 (*y) = 0;
95 } else {
Graeme Russ45fc1d82011-04-13 19:43:26 +100096 vidmem[((*x) + cols * (*y)) * 2] = c;
97 if (++(*x) >= cols) {
wdenkabda5ca2003-05-31 18:35:21 +000098 (*x) = 0;
Graeme Russ45fc1d82011-04-13 19:43:26 +100099 if (++(*y) >= lines) {
wdenkabda5ca2003-05-31 18:35:21 +0000100 scroll();
101 (*y)--;
102 }
103 }
104 }
105}
106
Simon Glass0d1e1f72014-07-23 06:54:59 -0600107static void video_putc(struct stdio_dev *dev, const char c)
wdenkabda5ca2003-05-31 18:35:21 +0000108{
Graeme Russ883c6032011-11-08 02:33:15 +0000109 int x, y, pos;
wdenk57b2d802003-06-27 21:31:46 +0000110
wdenkabda5ca2003-05-31 18:35:21 +0000111 x = orig_x;
112 y = orig_y;
wdenk57b2d802003-06-27 21:31:46 +0000113
wdenkabda5ca2003-05-31 18:35:21 +0000114 __video_putc(c, &x, &y);
115
116 orig_x = x;
117 orig_y = y;
wdenk57b2d802003-06-27 21:31:46 +0000118
wdenkabda5ca2003-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
Simon Glass0d1e1f72014-07-23 06:54:59 -0600126static void video_puts(struct stdio_dev *dev, const char *s)
wdenkabda5ca2003-05-31 18:35:21 +0000127{
Graeme Russ883c6032011-11-08 02:33:15 +0000128 int x, y, pos;
wdenkabda5ca2003-05-31 18:35:21 +0000129 char c;
130
131 x = orig_x;
132 y = orig_y;
133
Graeme Russ45fc1d82011-04-13 19:43:26 +1000134 while ((c = *s++) != '\0')
wdenkabda5ca2003-05-31 18:35:21 +0000135 __video_putc(c, &x, &y);
wdenkabda5ca2003-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;
wdenk57b2d802003-06-27 21:31:46 +0000150
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200151 static struct stdio_dev vga_dev;
152 static struct stdio_dev kbd_dev;
wdenk57b2d802003-06-27 21:31:46 +0000153
wdenkabda5ca2003-05-31 18:35:21 +0000154 vidmem = (char *) 0xb8000;
155 vidport = 0x3d4;
156
157 lines = 25;
158 cols = 80;
wdenk57b2d802003-06-27 21:31:46 +0000159
wdenkabda5ca2003-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);
wdenk57b2d802003-06-27 21:31:46 +0000165
wdenkabda5ca2003-05-31 18:35:21 +0000166 orig_x = pos%cols;
167 orig_y = pos/cols;
168
wdenk57b2d802003-06-27 21:31:46 +0000169#if 0
wdenkabda5ca2003-05-31 18:35:21 +0000170 printf("pos %x %d %d\n", pos, orig_x, orig_y);
wdenk57b2d802003-06-27 21:31:46 +0000171#endif
Graeme Russ45fc1d82011-04-13 19:43:26 +1000172 if (orig_y > lines)
Graeme Russ883c6032011-11-08 02:33:15 +0000173 orig_x = orig_y = 0;
wdenk57b2d802003-06-27 21:31:46 +0000174
wdenkabda5ca2003-05-31 18:35:21 +0000175 memset(&vga_dev, 0, sizeof(vga_dev));
wdenk57b2d802003-06-27 21:31:46 +0000176 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 */
wdenkabda5ca2003-05-31 18:35:21 +0000181
Graeme Russ45fc1d82011-04-13 19:43:26 +1000182 if (stdio_register(&vga_dev) == 0)
183 return 1;
wdenk57b2d802003-06-27 21:31:46 +0000184
Graeme Russ45fc1d82011-04-13 19:43:26 +1000185 if (i8042_kbd_init())
wdenkabda5ca2003-05-31 18:35:21 +0000186 return 1;
wdenk57b2d802003-06-27 21:31:46 +0000187
wdenkabda5ca2003-05-31 18:35:21 +0000188 memset(&kbd_dev, 0, sizeof(kbd_dev));
wdenk57b2d802003-06-27 21:31:46 +0000189 strcpy(kbd_dev.name, "kbd");
190 kbd_dev.ext = 0;
191 kbd_dev.flags = DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
wdenk57b2d802003-06-27 21:31:46 +0000192 kbd_dev.tstc = i8042_tstc; /* 'tstc' function */
193 kbd_dev.getc = i8042_getc; /* 'getc' function */
wdenkabda5ca2003-05-31 18:35:21 +0000194
Graeme Russ45fc1d82011-04-13 19:43:26 +1000195 if (stdio_register(&kbd_dev) == 0)
196 return 1;
197
wdenkabda5ca2003-05-31 18:35:21 +0000198 return 0;
199}
200
201
wdenk57b2d802003-06-27 21:31:46 +0000202int drv_video_init(void)
wdenkabda5ca2003-05-31 18:35:21 +0000203{
wdenk57b2d802003-06-27 21:31:46 +0000204 return video_init();
wdenkabda5ca2003-05-31 18:35:21 +0000205}