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