pci_vga.c revision 1.1 1 /* $NetBSD: pci_vga.c,v 1.1 1999/03/15 15:47:22 leo Exp $ */
2
3 /*
4 * Copyright (c) 1999 Leo Weppelman. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Leo Weppelman.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31 #include <sys/param.h>
32 #include <sys/queue.h>
33 #include <sys/systm.h>
34 #include <dev/pci/pcireg.h>
35 #include <dev/pci/pcivar.h>
36 #include <dev/pci/pcidevs.h>
37 #include <atari/pci/pci_vga.h>
38 #include <atari/dev/grf_etreg.h>
39 #include <atari/include/iomap.h>
40
41 #include <atari/dev/font.h>
42
43 static void loadfont(volatile u_char *, u_char *fb);
44
45 /* XXX: Shouldn't these be in font.h???? */
46 extern font_info font_info_8x8;
47 extern font_info font_info_8x16;
48
49 /* Console colors */
50 static u_char conscolors[3][3] = { /* background, foreground, hilite */
51 {0x0, 0x0, 0x0}, {0x30, 0x30, 0x30}, { 0x3f, 0x3f, 0x3f}
52 };
53
54 /*
55 * Go look for a VGA card on the PCI-bus. This search is a
56 * stripped down version of the PCI-probe. It only looks on
57 * bus0 for VGA cards. The first card found is used.
58 */
59 int
60 check_for_vga()
61 {
62 pci_chipset_tag_t pc = NULL; /* XXX */
63 pcitag_t tag;
64 int device, found, id, maxndevs, i, j;
65 volatile u_char *regs;
66 u_char *fb;
67 char *nbd = "NetBSD/Atari";
68
69 found = 0;
70 tag = 0;
71 id = 0;
72 maxndevs = pci_bus_maxdevs(pc, 0);
73
74 /*
75 * These are setup in atari_init.c
76 */
77 regs = (volatile caddr_t)pci_io_addr;
78 fb = (caddr_t)pci_mem_addr;
79
80 for (device = 0; !found && (device < maxndevs); device++) {
81
82 tag = pci_make_tag(pc, 0, device, 0);
83 id = pci_conf_read(pc, tag, PCI_ID_REG);
84 if (id == 0 || id == 0xffffffff)
85 continue;
86 switch (id = PCI_PRODUCT(id)) {
87
88 /*
89 * XXX Make the inclusion of the cases dependend
90 * on config options!
91 */
92 case PCI_PRODUCT_TSENG_ET6000:
93 case PCI_PRODUCT_TSENG_ET4000_W32P_A:
94 case PCI_PRODUCT_TSENG_ET4000_W32P_B:
95 case PCI_PRODUCT_TSENG_ET4000_W32P_C:
96 case PCI_PRODUCT_TSENG_ET4000_W32P_D:
97 tseng_init(pc, tag, id, regs, fb);
98 found = 1;
99 break;
100 default:
101 break;
102 }
103 }
104 if (!found)
105 return (0);
106
107 /*
108 * Generic parts of the initialization...
109 */
110
111 /* B&W colors */
112 vgaw(regs, VDAC_ADDRESS_W, 0);
113 for (i = 0; i < 256; i++) {
114 j = (i & 1) ? ((i > 7) ? 2 : 1) : 0;
115 vgaw(regs, VDAC_DATA, conscolors[j][0]);
116 vgaw(regs, VDAC_DATA, conscolors[j][1]);
117 vgaw(regs, VDAC_DATA, conscolors[j][2]);
118 }
119
120 loadfont(regs, fb);
121
122 /*
123 * Clear the screen and print a message. The latter
124 * is of diagnostic/debug use only.
125 */
126 for (i = 50 * 80; i >= 0; i -= 2) {
127 fb[i] = 0x20; fb[i+1] = 0x07;
128 }
129 for (i = 56; *nbd; i += 2)
130 fb[i] = *nbd++;
131
132 return (1);
133 }
134
135 /*
136 * Generic VGA. Load the configured kernel font into the videomemory and
137 * place the card into textmode.
138 */
139 static void
140 loadfont(ba, fb)
141 volatile u_char *ba; /* Register area KVA */
142 u_char *fb; /* Frame buffer KVA */
143 {
144 font_info *fd;
145 u_char *c, *f, tmp;
146 u_short z, y;
147
148 #if defined(KFONT_8X8)
149 fd = &font_info_8x8;
150 #else
151 fd = &font_info_8x16;
152 #endif
153
154 WAttr(ba, 0x20 | ACT_ID_ATTR_MODE_CNTL, 0x0a);
155 WSeq(ba, SEQ_ID_MAP_MASK, 0x04);
156 WSeq(ba, SEQ_ID_MEMORY_MODE, 0x06);
157 WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x02);
158 WGfx(ba, GCT_ID_GRAPHICS_MODE, 0x00);
159 WGfx(ba, GCT_ID_MISC, 0x04);
160
161 /*
162 * load text font into beginning of display memory. Each
163 * character cell is 32 bytes long (enough for 4 planes)
164 */
165 for (z = 0, c = fb; z < 256 * 32; z++)
166 *c++ = 0;
167
168 c = (unsigned char *) (fb) + (32 * fd->font_lo);
169 f = fd->font_p;
170 z = fd->font_lo;
171 for (; z <= fd->font_hi; z++, c += (32 - fd->height))
172 for (y = 0; y < fd->height; y++) {
173 *c++ = *f++;
174 }
175
176 /*
177 * Odd/Even addressing
178 */
179 WSeq(ba, SEQ_ID_MAP_MASK, 0x03);
180 WSeq(ba, SEQ_ID_MEMORY_MODE, 0x03);
181 WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x00);
182 WGfx(ba, GCT_ID_GRAPHICS_MODE, 0x10);
183 WGfx(ba, GCT_ID_MISC, 0x06);
184
185 /*
186 * Font height + underline location
187 */
188 tmp = RCrt(ba, CRT_ID_MAX_ROW_ADDRESS) & 0xe0;
189 WCrt(ba, CRT_ID_MAX_ROW_ADDRESS, tmp | (fd->height - 1));
190 tmp = RCrt(ba, CRT_ID_UNDERLINE_LOC) & 0xe0;
191 WCrt(ba, CRT_ID_UNDERLINE_LOC, tmp | (fd->height - 1));
192
193 /*
194 * Cursor setup
195 */
196 WCrt(ba, CRT_ID_CURSOR_START , 0x00);
197 WCrt(ba, CRT_ID_CURSOR_END , fd->height - 1);
198 WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, 0x00);
199 WCrt(ba, CRT_ID_CURSOR_LOC_LOW , 0x00);
200
201 /*
202 * Enter text mode
203 */
204 WCrt(ba, CRT_ID_MODE_CONTROL , 0xa3);
205 WAttr(ba, ACT_ID_ATTR_MODE_CNTL | 0x20, 0x0a);
206 }
207