wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 |
Albert ARIBAUD | 60fbc8d | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 3 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> |
wdenk | abda5ca | 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 | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 24 | #include <common.h> |
| 25 | #include <pci.h> |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 26 | #include <stdio_dev.h> |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 27 | #include <i8042.h> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 28 | #include <asm/ptrace.h> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 29 | #include <asm/io.h> |
| 30 | #include <asm/pci.h> |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 31 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 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; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 41 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 42 | outb_p(3, 0x61); |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 43 | for (i = 0; i < 10*dur; i++) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 44 | udelay(1000); |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 45 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 46 | outb_p(0, 0x61); |
| 47 | } |
| 48 | |
| 49 | static void scroll(void) |
| 50 | { |
| 51 | int i; |
| 52 | |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 53 | memcpy(vidmem, vidmem + cols * 2, (lines - 1) * cols * 2); |
| 54 | for (i = (lines - 1) * cols * 2; i < lines * cols * 2; i += 2) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 55 | vidmem[i] = ' '; |
| 56 | } |
| 57 | |
| 58 | static void __video_putc(const char c, int *x, int *y) |
| 59 | { |
| 60 | if (c == '\n') { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 61 | (*x) = 0; |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 62 | if (++(*y) >= lines) { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 63 | scroll(); |
| 64 | (*y)--; |
| 65 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 66 | } else if (c == '\b') { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 67 | if ((*x) != 0) { |
| 68 | --(*x); |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 69 | vidmem[((*x) + cols * (*y)) * 2] = ' '; |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 70 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 71 | } else if (c == '\r') { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 72 | (*x) = 0; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 73 | |
| 74 | } else if (c == '\a') { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 75 | beep(3); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 76 | |
| 77 | } else if (c == '\t') { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 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); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 86 | } else if (c == '\v') { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 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 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 105 | } else if (c == '\f') { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 106 | int i; |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 107 | for (i = 0; i < lines * cols * 2; i += 2) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 108 | vidmem[i] = 0; |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 109 | (*x) = 0; |
| 110 | (*y) = 0; |
| 111 | } else { |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 112 | vidmem[((*x) + cols * (*y)) * 2] = c; |
| 113 | if (++(*x) >= cols) { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 114 | (*x) = 0; |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 115 | if (++(*y) >= lines) { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 116 | scroll(); |
| 117 | (*y)--; |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | static void video_putc(const char c) |
| 124 | { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 125 | int x, y, pos; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 126 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 127 | x = orig_x; |
| 128 | y = orig_y; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 129 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 130 | __video_putc(c, &x, &y); |
| 131 | |
| 132 | orig_x = x; |
| 133 | orig_y = y; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 134 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 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 | { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 144 | int x, y, pos; |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 145 | char c; |
| 146 | |
| 147 | x = orig_x; |
| 148 | y = orig_y; |
| 149 | |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 150 | while ((c = *s++) != '\0') |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 151 | __video_putc(c, &x, &y); |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 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; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 166 | |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 167 | static struct stdio_dev vga_dev; |
| 168 | static struct stdio_dev kbd_dev; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 169 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 170 | vidmem = (char *) 0xb8000; |
| 171 | vidport = 0x3d4; |
| 172 | |
| 173 | lines = 25; |
| 174 | cols = 80; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 175 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 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); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 181 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 182 | orig_x = pos%cols; |
| 183 | orig_y = pos/cols; |
| 184 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 185 | #if 0 |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 186 | printf("pos %x %d %d\n", pos, orig_x, orig_y); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 187 | #endif |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 188 | if (orig_y > lines) |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 189 | orig_x = orig_y = 0; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 190 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 191 | memset(&vga_dev, 0, sizeof(vga_dev)); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 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 */ |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 199 | |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 200 | if (stdio_register(&vga_dev) == 0) |
| 201 | return 1; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 202 | |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 203 | if (i8042_kbd_init()) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 204 | return 1; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 205 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 206 | memset(&kbd_dev, 0, sizeof(kbd_dev)); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 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 */ |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 214 | |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 215 | if (stdio_register(&kbd_dev) == 0) |
| 216 | return 1; |
| 217 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 222 | int drv_video_init(void) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 223 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 224 | return video_init(); |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 225 | } |