wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 3 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 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 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 24 | #include <common.h> |
| 25 | #include <pci.h> |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 26 | #include <stdio_dev.h> |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 27 | #include <i8042.h> |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 28 | #include <asm/ptrace.h> |
| 29 | #include <asm/realmode.h> |
| 30 | #include <asm/io.h> |
| 31 | #include <asm/pci.h> |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 32 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 33 | /* basic textmode I/O from linux kernel */ |
| 34 | static char *vidmem = (char *)0xb8000; |
| 35 | static int vidport; |
| 36 | static int lines, cols; |
| 37 | static int orig_x, orig_y; |
| 38 | |
| 39 | static void beep(int dur) |
| 40 | { |
| 41 | int i; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 42 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 43 | outb_p(3, 0x61); |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 44 | for (i = 0; i < 10*dur; i++) |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 45 | udelay(1000); |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 46 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 47 | outb_p(0, 0x61); |
| 48 | } |
| 49 | |
| 50 | static void scroll(void) |
| 51 | { |
| 52 | int i; |
| 53 | |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 54 | memcpy(vidmem, vidmem + cols * 2, (lines - 1) * cols * 2); |
| 55 | for (i = (lines - 1) * cols * 2; i < lines * cols * 2; i += 2) |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 56 | vidmem[i] = ' '; |
| 57 | } |
| 58 | |
| 59 | static void __video_putc(const char c, int *x, int *y) |
| 60 | { |
| 61 | if (c == '\n') { |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 62 | (*x) = 0; |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 63 | if (++(*y) >= lines) { |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 64 | scroll(); |
| 65 | (*y)--; |
| 66 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 67 | } else if (c == '\b') { |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 68 | if ((*x) != 0) { |
| 69 | --(*x); |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 70 | vidmem[((*x) + cols * (*y)) * 2] = ' '; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 71 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 72 | } else if (c == '\r') { |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 73 | (*x) = 0; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 74 | |
| 75 | } else if (c == '\a') { |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 76 | beep(3); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 77 | |
| 78 | } else if (c == '\t') { |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 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 | __video_putc(' ', x, y); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 87 | } else if (c == '\v') { |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 88 | 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 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 106 | } else if (c == '\f') { |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 107 | int i; |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 108 | for (i = 0; i < lines * cols * 2; i += 2) |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 109 | vidmem[i] = 0; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 110 | (*x) = 0; |
| 111 | (*y) = 0; |
| 112 | } else { |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 113 | vidmem[((*x) + cols * (*y)) * 2] = c; |
| 114 | if (++(*x) >= cols) { |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 115 | (*x) = 0; |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 116 | if (++(*y) >= lines) { |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 117 | scroll(); |
| 118 | (*y)--; |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | static void video_putc(const char c) |
| 125 | { |
| 126 | int x,y,pos; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 127 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 128 | x = orig_x; |
| 129 | y = orig_y; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 130 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 131 | __video_putc(c, &x, &y); |
| 132 | |
| 133 | orig_x = x; |
| 134 | orig_y = y; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 135 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 136 | 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 | |
| 143 | static 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 Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 151 | while ((c = *s++) != '\0') |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 152 | __video_putc(c, &x, &y); |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 153 | |
| 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 | |
| 164 | int video_init(void) |
| 165 | { |
| 166 | u16 pos; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 167 | |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 168 | static struct stdio_dev vga_dev; |
| 169 | static struct stdio_dev kbd_dev; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 170 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 171 | vidmem = (char *) 0xb8000; |
| 172 | vidport = 0x3d4; |
| 173 | |
| 174 | lines = 25; |
| 175 | cols = 80; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 176 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 177 | outb_p(14, vidport); |
| 178 | pos = inb_p(vidport+1); |
| 179 | pos <<= 8; |
| 180 | outb_p(15, vidport); |
| 181 | pos |= inb_p(vidport+1); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 182 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 183 | orig_x = pos%cols; |
| 184 | orig_y = pos/cols; |
| 185 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 186 | #if 0 |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 187 | printf("pos %x %d %d\n", pos, orig_x, orig_y); |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 188 | #endif |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 189 | if (orig_y > lines) |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 190 | orig_x = orig_y =0; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 191 | |
| 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 Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 201 | if (stdio_register(&vga_dev) == 0) |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 202 | return 1; |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 203 | |
| 204 | if (i8042_kbd_init()) |
| 205 | return 1; |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 206 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 207 | 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 Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 216 | if (stdio_register(&kbd_dev) == 0) |
| 217 | return 1; |
| 218 | |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 223 | int drv_video_init(void) |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 224 | { |
Graeme Russ | dbf7115 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 225 | if (video_bios_init()) |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 226 | return 1; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 227 | |
| 228 | return video_init(); |
wdenk | 7a8e9bed | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 229 | } |