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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 8 | #include <common.h> |
| 9 | #include <pci.h> |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 10 | #include <stdio_dev.h> |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 11 | #include <i8042.h> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 12 | #include <asm/ptrace.h> |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 13 | #include <asm/io.h> |
| 14 | #include <asm/pci.h> |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 15 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 16 | /* basic textmode I/O from linux kernel */ |
| 17 | static char *vidmem = (char *)0xb8000; |
| 18 | static int vidport; |
| 19 | static int lines, cols; |
| 20 | static int orig_x, orig_y; |
| 21 | |
| 22 | static void beep(int dur) |
| 23 | { |
| 24 | int i; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 25 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 26 | outb_p(3, 0x61); |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 27 | for (i = 0; i < 10*dur; i++) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 28 | udelay(1000); |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 29 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 30 | outb_p(0, 0x61); |
| 31 | } |
| 32 | |
| 33 | static void scroll(void) |
| 34 | { |
| 35 | int i; |
| 36 | |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 37 | memcpy(vidmem, vidmem + cols * 2, (lines - 1) * cols * 2); |
| 38 | for (i = (lines - 1) * cols * 2; i < lines * cols * 2; i += 2) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 39 | vidmem[i] = ' '; |
| 40 | } |
| 41 | |
| 42 | static void __video_putc(const char c, int *x, int *y) |
| 43 | { |
| 44 | if (c == '\n') { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 45 | (*x) = 0; |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 46 | if (++(*y) >= lines) { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 47 | scroll(); |
| 48 | (*y)--; |
| 49 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 50 | } else if (c == '\b') { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 51 | if ((*x) != 0) { |
| 52 | --(*x); |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 53 | vidmem[((*x) + cols * (*y)) * 2] = ' '; |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 54 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 55 | } else if (c == '\r') { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 56 | (*x) = 0; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 57 | |
| 58 | } else if (c == '\a') { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 59 | beep(3); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 60 | |
| 61 | } else if (c == '\t') { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 62 | __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); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 70 | } else if (c == '\v') { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 71 | 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 | } |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 89 | } else if (c == '\f') { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 90 | int i; |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 91 | for (i = 0; i < lines * cols * 2; i += 2) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 92 | vidmem[i] = 0; |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 93 | (*x) = 0; |
| 94 | (*y) = 0; |
| 95 | } else { |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 96 | vidmem[((*x) + cols * (*y)) * 2] = c; |
| 97 | if (++(*x) >= cols) { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 98 | (*x) = 0; |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 99 | if (++(*y) >= lines) { |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 100 | scroll(); |
| 101 | (*y)--; |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 107 | static void video_putc(struct stdio_dev *dev, const char c) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 108 | { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 109 | int x, y, pos; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 110 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 111 | x = orig_x; |
| 112 | y = orig_y; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 113 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 114 | __video_putc(c, &x, &y); |
| 115 | |
| 116 | orig_x = x; |
| 117 | orig_y = y; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 118 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 119 | 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 Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 126 | static void video_puts(struct stdio_dev *dev, const char *s) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 127 | { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 128 | int x, y, pos; |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 129 | char c; |
| 130 | |
| 131 | x = orig_x; |
| 132 | y = orig_y; |
| 133 | |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 134 | while ((c = *s++) != '\0') |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 135 | __video_putc(c, &x, &y); |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 136 | |
| 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 | |
| 147 | int video_init(void) |
| 148 | { |
| 149 | u16 pos; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 150 | |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 151 | static struct stdio_dev vga_dev; |
| 152 | static struct stdio_dev kbd_dev; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 153 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 154 | vidmem = (char *) 0xb8000; |
| 155 | vidport = 0x3d4; |
| 156 | |
| 157 | lines = 25; |
| 158 | cols = 80; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 159 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 160 | outb_p(14, vidport); |
| 161 | pos = inb_p(vidport+1); |
| 162 | pos <<= 8; |
| 163 | outb_p(15, vidport); |
| 164 | pos |= inb_p(vidport+1); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 165 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 166 | orig_x = pos%cols; |
| 167 | orig_y = pos/cols; |
| 168 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 169 | #if 0 |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 170 | printf("pos %x %d %d\n", pos, orig_x, orig_y); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 171 | #endif |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 172 | if (orig_y > lines) |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 173 | orig_x = orig_y = 0; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 174 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 175 | memset(&vga_dev, 0, sizeof(vga_dev)); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 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 */ |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 181 | |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 182 | if (stdio_register(&vga_dev) == 0) |
| 183 | return 1; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 184 | |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 185 | if (i8042_kbd_init()) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 186 | return 1; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 187 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 188 | memset(&kbd_dev, 0, sizeof(kbd_dev)); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 189 | strcpy(kbd_dev.name, "kbd"); |
| 190 | kbd_dev.ext = 0; |
| 191 | kbd_dev.flags = DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 192 | kbd_dev.tstc = i8042_tstc; /* 'tstc' function */ |
| 193 | kbd_dev.getc = i8042_getc; /* 'getc' function */ |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 194 | |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 195 | if (stdio_register(&kbd_dev) == 0) |
| 196 | return 1; |
| 197 | |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 198 | return 0; |
| 199 | } |
| 200 | |
| 201 | |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 202 | int drv_video_init(void) |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 203 | { |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 204 | return video_init(); |
wdenk | abda5ca | 2003-05-31 18:35:21 +0000 | [diff] [blame] | 205 | } |