Home | History | Annotate | Line # | Download | only in ic
vga_subr.c revision 1.22.4.1
      1  1.22.4.1        ad /* $NetBSD: vga_subr.c,v 1.22.4.1 2007/12/26 19:46:25 ad Exp $ */
      2       1.1  drochner 
      3       1.1  drochner /*
      4       1.1  drochner  * Copyright (c) 1998
      5       1.1  drochner  *	Matthias Drochner.  All rights reserved.
      6       1.1  drochner  *
      7       1.1  drochner  * Redistribution and use in source and binary forms, with or without
      8       1.1  drochner  * modification, are permitted provided that the following conditions
      9       1.1  drochner  * are met:
     10       1.1  drochner  * 1. Redistributions of source code must retain the above copyright
     11       1.1  drochner  *    notice, this list of conditions and the following disclaimer.
     12       1.1  drochner  * 2. Redistributions in binary form must reproduce the above copyright
     13       1.1  drochner  *    notice, this list of conditions and the following disclaimer in the
     14       1.1  drochner  *    documentation and/or other materials provided with the distribution.
     15       1.1  drochner  *
     16       1.1  drochner  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17       1.1  drochner  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18       1.1  drochner  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19       1.1  drochner  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20       1.1  drochner  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     21       1.1  drochner  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     22       1.1  drochner  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     23       1.1  drochner  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     24       1.1  drochner  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     25       1.1  drochner  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     26       1.1  drochner  *
     27       1.1  drochner  */
     28       1.7     lukem 
     29      1.21       dsl #include <sys/cdefs.h>
     30  1.22.4.1        ad __KERNEL_RCSID(0, "$NetBSD: vga_subr.c,v 1.22.4.1 2007/12/26 19:46:25 ad Exp $");
     31      1.21       dsl 
     32      1.18      jmmv /* for WSDISPLAY_BORDER_COLOR */
     33      1.18      jmmv #include "opt_wsdisplay_border.h"
     34      1.18      jmmv 
     35       1.1  drochner #include <sys/param.h>
     36       1.1  drochner #include <sys/systm.h>
     37       1.1  drochner #include <sys/device.h>
     38       1.1  drochner #include <sys/queue.h>
     39      1.22        ad #include <sys/bus.h>
     40       1.1  drochner 
     41       1.2  drochner #include <dev/ic/mc6845reg.h>
     42      1.14   tsutsui #include <dev/ic/pcdisplay.h>
     43       1.2  drochner #include <dev/ic/pcdisplayvar.h>
     44       1.1  drochner #include <dev/ic/vgareg.h>
     45       1.1  drochner #include <dev/ic/vgavar.h>
     46       1.1  drochner 
     47       1.1  drochner #include <dev/wscons/wsdisplayvar.h>
     48       1.1  drochner 
     49       1.8  junyoung static void fontram(struct vga_handle *);
     50       1.8  junyoung static void textram(struct vga_handle *);
     51       1.1  drochner 
     52       1.1  drochner static void
     53       1.8  junyoung fontram(struct vga_handle *vh)
     54       1.1  drochner {
     55      1.12   tsutsui 
     56       1.1  drochner 	/* program sequencer to access character generator */
     57       1.1  drochner 
     58       1.1  drochner 	vga_ts_write(vh, syncreset, 0x01);	/* synchronous reset */
     59       1.1  drochner 	vga_ts_write(vh, wrplmask, 0x04);	/* write to map 2 */
     60       1.1  drochner 	vga_ts_write(vh, memmode, 0x07);	/* sequential addressing */
     61       1.1  drochner 	vga_ts_write(vh, syncreset, 0x03);	/* clear synchronous reset */
     62       1.1  drochner 
     63       1.1  drochner 	/* program graphics controller to access character generator */
     64       1.1  drochner 
     65      1.16       wiz 	vga_gdc_write(vh, rdplanesel, 0x02);	/* select map 2 for CPU reads */
     66       1.1  drochner 	vga_gdc_write(vh, mode, 0x00);	/* disable odd-even addressing */
     67       1.1  drochner 	vga_gdc_write(vh, misc, 0x04);	/* map starts at 0xA000 */
     68       1.1  drochner }
     69       1.1  drochner 
     70       1.1  drochner static void
     71       1.8  junyoung textram(struct vga_handle *vh)
     72       1.1  drochner {
     73      1.12   tsutsui 
     74       1.1  drochner 	/* program sequencer to access video ram */
     75       1.1  drochner 
     76       1.1  drochner 	vga_ts_write(vh, syncreset, 0x01);	/* synchronous reset */
     77       1.1  drochner 	vga_ts_write(vh, wrplmask, 0x03);	/* write to map 0 & 1 */
     78       1.1  drochner 	vga_ts_write(vh, memmode, 0x03);	/* odd-even addressing */
     79       1.1  drochner 	vga_ts_write(vh, syncreset, 0x03);	/* clear synchronous reset */
     80       1.1  drochner 
     81       1.1  drochner 	/* program graphics controller for text mode */
     82       1.1  drochner 
     83      1.16       wiz 	vga_gdc_write(vh, rdplanesel, 0x00);	/* select map 0 for CPU reads */
     84       1.1  drochner 	vga_gdc_write(vh, mode, 0x10);		/* enable odd-even addressing */
     85       1.1  drochner 	/* map starts at 0xb800 or 0xb000 (mono) */
     86       1.2  drochner 	vga_gdc_write(vh, misc, (vh->vh_mono ? 0x0a : 0x0e));
     87       1.1  drochner }
     88       1.1  drochner 
     89      1.11  junyoung #ifndef VGA_RASTERCONSOLE
     90       1.1  drochner void
     91      1.10  drochner vga_loadchars(struct vga_handle *vh, int fontset, int first, int num, int lpc,
     92      1.15  jdolecek 	      const char *data)
     93       1.1  drochner {
     94       1.1  drochner 	int offset, i, j, s;
     95       1.1  drochner 
     96       1.1  drochner 	/* fontset number swizzle done in vga_setfontset() */
     97       1.1  drochner 	offset = (fontset << 13) | (first << 5);
     98       1.1  drochner 
     99       1.1  drochner 	s = splhigh();
    100       1.1  drochner 	fontram(vh);
    101       1.1  drochner 
    102      1.10  drochner 	for (i = 0; i < num; i++)
    103      1.10  drochner 		for (j = 0; j < lpc; j++)
    104      1.10  drochner 			bus_space_write_1(vh->vh_memt, vh->vh_allmemh,
    105      1.12   tsutsui 			    offset + (i << 5) + j, data[i * lpc + j]);
    106       1.1  drochner 
    107       1.1  drochner 	textram(vh);
    108       1.1  drochner 	splx(s);
    109       1.1  drochner }
    110       1.1  drochner 
    111       1.1  drochner void
    112      1.12   tsutsui vga_readoutchars(struct vga_handle *vh, int fontset, int first, int num,
    113      1.12   tsutsui 		 int lpc, char *data)
    114       1.1  drochner {
    115      1.10  drochner 	int offset, i, j, s;
    116      1.10  drochner 
    117      1.10  drochner 	/* fontset number swizzle done in vga_setfontset() */
    118      1.10  drochner 	offset = (fontset << 13) | (first << 5);
    119      1.10  drochner 
    120      1.10  drochner 	s = splhigh();
    121      1.10  drochner 	fontram(vh);
    122      1.10  drochner 
    123      1.10  drochner 	for (i = 0; i < num; i++)
    124      1.10  drochner 		for (j = 0; j < lpc; j++)
    125      1.12   tsutsui 			data[i * lpc + j] = bus_space_read_1(vh->vh_memt,
    126      1.12   tsutsui 			    vh->vh_allmemh, offset + (i << 5) + j);
    127      1.10  drochner 
    128      1.10  drochner 	textram(vh);
    129      1.10  drochner 	splx(s);
    130      1.10  drochner }
    131      1.10  drochner 
    132       1.9  junyoung #ifdef VGA_CONSOLE_ATI_BROKEN_FONTSEL
    133      1.10  drochner void
    134      1.10  drochner vga_copyfont01(struct vga_handle *vh)
    135      1.10  drochner {
    136       1.9  junyoung 	int s;
    137       1.9  junyoung 
    138       1.9  junyoung 	s = splhigh();
    139       1.9  junyoung 	fontram(vh);
    140      1.10  drochner 
    141      1.12   tsutsui 	bus_space_copy_region_1(vh->vh_memt, vh->vh_allmemh, 0,
    142      1.12   tsutsui 	    vh->vh_allmemh, 1 << 13, 1 << 13);
    143      1.10  drochner 
    144       1.9  junyoung 	textram(vh);
    145       1.9  junyoung 	splx(s);
    146      1.10  drochner }
    147      1.10  drochner #endif
    148      1.10  drochner 
    149      1.10  drochner void
    150      1.10  drochner vga_setfontset(struct vga_handle *vh, int fontset1, int fontset2)
    151      1.10  drochner {
    152       1.1  drochner 	u_int8_t cmap;
    153      1.13   tsutsui 	static const u_int8_t cmaptaba[] = {
    154       1.3  drochner 		0x00, 0x10, 0x01, 0x11,
    155       1.3  drochner 		0x02, 0x12, 0x03, 0x13
    156       1.1  drochner 	};
    157      1.13   tsutsui 	static const u_int8_t cmaptabb[] = {
    158       1.3  drochner 		0x00, 0x20, 0x04, 0x24,
    159       1.3  drochner 		0x08, 0x28, 0x0c, 0x2c
    160       1.1  drochner 	};
    161       1.1  drochner 
    162       1.4  drochner 	/* extended font if fontset1 != fontset2 */
    163       1.3  drochner 	cmap = cmaptaba[fontset1] | cmaptabb[fontset2];
    164       1.1  drochner 
    165       1.1  drochner 	vga_ts_write(vh, fontsel, cmap);
    166       1.1  drochner }
    167       1.1  drochner 
    168       1.1  drochner void
    169       1.8  junyoung vga_setscreentype(struct vga_handle *vh, const struct wsscreen_descr *type)
    170       1.1  drochner {
    171      1.12   tsutsui 
    172       1.1  drochner 	vga_6845_write(vh, maxrow, type->fontheight - 1);
    173       1.1  drochner 
    174       1.1  drochner 	/* lo byte */
    175       1.1  drochner 	vga_6845_write(vh, vde, type->fontheight * type->nrows - 1);
    176       1.1  drochner 
    177       1.6        ad #ifndef PCDISPLAY_SOFTCURSOR
    178       1.1  drochner 	/* set cursor to last 2 lines */
    179       1.1  drochner 	vga_6845_write(vh, curstart, type->fontheight - 2);
    180       1.1  drochner 	vga_6845_write(vh, curend, type->fontheight - 1);
    181       1.5        ad #endif
    182       1.3  drochner 	/*
    183       1.3  drochner 	 * disable colour plane 3 if needed for font selection
    184       1.3  drochner 	 */
    185       1.3  drochner 	if (type->capabilities & WSSCREEN_HILIT) {
    186       1.3  drochner 		/*
    187       1.3  drochner 		 * these are the screens which don't support
    188       1.3  drochner 		 * 512-character fonts
    189       1.3  drochner 		 */
    190       1.3  drochner 		vga_attr_write(vh, colplen, 0x0f);
    191       1.3  drochner 	} else
    192       1.3  drochner 		vga_attr_write(vh, colplen, 0x07);
    193       1.1  drochner }
    194      1.11  junyoung 
    195      1.11  junyoung #else /* !VGA_RASTERCONSOLE */
    196      1.11  junyoung void
    197      1.11  junyoung vga_load_builtinfont(struct vga_handle *vh, u_int8_t *font, int firstchar,
    198      1.11  junyoung 	int numchars)
    199      1.11  junyoung {
    200      1.11  junyoung 	int i, s;
    201      1.12   tsutsui 
    202      1.11  junyoung 	s = splhigh();
    203      1.11  junyoung 	fontram(vh);
    204      1.11  junyoung 
    205      1.11  junyoung 	for (i = firstchar; i < firstchar + numchars; i++)
    206      1.11  junyoung 		bus_space_read_region_1(vh->vh_memt, vh->vh_allmemh, i * 32,
    207      1.12   tsutsui 		    font + i * 16, 16);
    208      1.12   tsutsui 
    209      1.11  junyoung 	textram(vh);
    210      1.11  junyoung 	splx(s);
    211      1.11  junyoung }
    212      1.11  junyoung #endif /* !VGA_RASTERCONSOLE */
    213      1.14   tsutsui 
    214      1.14   tsutsui /*
    215      1.14   tsutsui  * vga_reset():
    216      1.14   tsutsui  *	Reset VGA registers to put it into 80x25 text mode. (mode 3)
    217      1.14   tsutsui  *	This function should be called from MD consinit() on ports
    218      1.14   tsutsui  *	whose firmware does not use text mode at boot time.
    219      1.14   tsutsui  */
    220      1.14   tsutsui void
    221      1.14   tsutsui vga_reset(vh, md_initfunc)
    222      1.14   tsutsui 	struct vga_handle *vh;
    223      1.14   tsutsui 	void (*md_initfunc)(struct vga_handle *);
    224      1.14   tsutsui {
    225      1.14   tsutsui 	u_int8_t reg;
    226      1.14   tsutsui 
    227      1.14   tsutsui 	if (bus_space_map(vh->vh_iot, 0x3c0, 0x10, 0, &vh->vh_ioh_vga))
    228      1.14   tsutsui 		return;
    229      1.14   tsutsui 
    230      1.14   tsutsui 	reg = bus_space_read_1(vh->vh_iot, vh->vh_ioh_vga, VGA_MISC_DATAR);
    231      1.14   tsutsui 	vh->vh_mono = !(reg & 0x01);
    232      1.14   tsutsui 
    233      1.14   tsutsui 	if (bus_space_map(vh->vh_iot, vh->vh_mono ? 0x3b0 : 0x3d0, 0x10,
    234      1.14   tsutsui 	    0, &vh->vh_ioh_6845))
    235      1.14   tsutsui 		goto out1;
    236      1.14   tsutsui 
    237      1.14   tsutsui 	if (bus_space_map(vh->vh_memt, 0xa0000, 0x20000, 0, &vh->vh_allmemh))
    238      1.14   tsutsui 		goto out2;
    239      1.14   tsutsui 
    240      1.14   tsutsui 	if (bus_space_subregion(vh->vh_memt, vh->vh_allmemh,
    241      1.14   tsutsui 	    vh->vh_mono ? 0x10000 : 0x18000, 0x8000, &vh->vh_memh))
    242      1.14   tsutsui 		goto out3;
    243      1.14   tsutsui 
    244      1.14   tsutsui 	/* check if VGA already in text mode. */
    245      1.14   tsutsui 	if ((vga_gdc_read(vh, misc) & 0x01) == 0)
    246      1.14   tsutsui 		goto out3;
    247      1.14   tsutsui 
    248      1.14   tsutsui 	/* initialize common VGA registers */
    249      1.14   tsutsui 	vga_initregs(vh);
    250      1.14   tsutsui 
    251      1.14   tsutsui 	/* initialize chipset specific registers */
    252      1.14   tsutsui 	if (md_initfunc != NULL)
    253      1.14   tsutsui 		(*md_initfunc)(vh);
    254      1.14   tsutsui 
    255      1.14   tsutsui 	delay(10000);
    256      1.14   tsutsui 
    257      1.14   tsutsui 	/* clear text buffer RAM */
    258      1.14   tsutsui 	bus_space_set_region_2(vh->vh_memt, vh->vh_memh, 0,
    259      1.14   tsutsui 	    ((BG_BLACK | FG_LIGHTGREY) << 8) | ' ', 80 * 25 /*XXX*/);
    260      1.14   tsutsui 
    261      1.14   tsutsui  out3:
    262      1.14   tsutsui 	bus_space_unmap(vh->vh_memt, vh->vh_allmemh, 0x20000);
    263      1.14   tsutsui  out2:
    264      1.14   tsutsui 	bus_space_unmap(vh->vh_iot, vh->vh_ioh_6845, 0x10);
    265      1.14   tsutsui  out1:
    266      1.14   tsutsui 	bus_space_unmap(vh->vh_iot, vh->vh_ioh_vga, 0x10);
    267      1.14   tsutsui }
    268      1.14   tsutsui 
    269      1.14   tsutsui /*
    270      1.14   tsutsui  * values to initialize registers.
    271      1.14   tsutsui  */
    272      1.14   tsutsui 
    273      1.14   tsutsui /* miscellaneous output register */
    274      1.14   tsutsui #define VGA_MISCOUT	0x66
    275      1.14   tsutsui 
    276      1.14   tsutsui /* sequencer registers */
    277      1.14   tsutsui static const u_int8_t vga_ts[] = {
    278      1.14   tsutsui 	0x03,	/* 00: reset */
    279      1.14   tsutsui 	0x00,	/* 01: clocking mode */
    280      1.14   tsutsui 	0x03,	/* 02: map mask */
    281      1.14   tsutsui 	0x00,	/* 03: character map select */
    282      1.14   tsutsui 	0x02	/* 04: memory mode */
    283      1.14   tsutsui };
    284      1.14   tsutsui 
    285      1.14   tsutsui /* CRT controller registers */
    286      1.14   tsutsui static const u_int8_t vga_crtc[] = {
    287      1.14   tsutsui 	0x5f,	/* 00: horizontal total */
    288      1.14   tsutsui 	0x4f,	/* 01: horizontal display-enable end */
    289      1.14   tsutsui 	0x50,	/* 02: start horizontal blanking */
    290      1.14   tsutsui 	0x82,	/* 03: display skew control / end horizontal blanking */
    291      1.14   tsutsui 	0x55,	/* 04: start horizontal retrace pulse */
    292      1.14   tsutsui 	0x81,	/* 05: horizontal retrace delay / end horizontal retrace */
    293      1.19   tsutsui 	0xbf,	/* 06: vertical total */
    294      1.14   tsutsui 	0x1f,	/* 07: overflow register */
    295      1.14   tsutsui 	0x00,	/* 08: preset row scan */
    296      1.14   tsutsui 	0x4f,	/* 09: overflow / maximum scan line */
    297      1.14   tsutsui 	0x0d,	/* 0A: cursor off / cursor start */
    298      1.14   tsutsui 	0x0e,	/* 0B: cursor skew / cursor end */
    299      1.14   tsutsui 	0x00,	/* 0C: start regenerative buffer address high */
    300      1.14   tsutsui 	0x00,	/* 0D: start regenerative buffer address low */
    301      1.14   tsutsui 	0x00,	/* 0E: cursor location high */
    302      1.14   tsutsui 	0x00,	/* 0F: cursor location low */
    303      1.14   tsutsui 	0x9c,	/* 10: vertical retrace start */
    304      1.14   tsutsui 	0x8e,	/* 11: vertical interrupt / vertical retrace end */
    305      1.14   tsutsui 	0x8f,	/* 12: vertical display enable end */
    306      1.14   tsutsui 	0x28,	/* 13: logical line width */
    307      1.14   tsutsui 	0x00,	/* 14: underline location */
    308      1.14   tsutsui 	0x96,	/* 15: start vertical blanking */
    309      1.14   tsutsui 	0xb9,	/* 16: end vertical blanking */
    310      1.14   tsutsui 	0xa3,	/* 17: CRT mode control */
    311      1.14   tsutsui 	0xff	/* 18: line compare */
    312      1.14   tsutsui };
    313      1.14   tsutsui 
    314      1.14   tsutsui /* graphics controller registers */
    315      1.14   tsutsui static const u_int8_t vga_gdc[] = {
    316      1.14   tsutsui 	0x00,	/* 00: set/reset map */
    317      1.14   tsutsui 	0x00,	/* 01: enable set/reset */
    318      1.14   tsutsui 	0x00,	/* 02: color compare */
    319      1.14   tsutsui 	0x00,	/* 03: data rotate */
    320      1.14   tsutsui 	0x00,	/* 04: read map select */
    321      1.14   tsutsui 	0x10,	/* 05: graphics mode */
    322      1.14   tsutsui 	0x0e,	/* 06: miscellaneous */
    323      1.14   tsutsui 	0x00,	/* 07: color don't care */
    324      1.14   tsutsui 	0xff	/* 08: bit mask */
    325      1.14   tsutsui };
    326      1.14   tsutsui 
    327      1.14   tsutsui /* attribute controller registers */
    328      1.14   tsutsui static const u_int8_t vga_atc[] = {
    329      1.14   tsutsui 	0x00,	/* 00: internal palette  0 */
    330      1.14   tsutsui 	0x01,	/* 01: internal palette  1 */
    331      1.14   tsutsui 	0x02,	/* 02: internal palette  2 */
    332      1.14   tsutsui 	0x03,	/* 03: internal palette  3 */
    333      1.14   tsutsui 	0x04,	/* 04: internal palette  4 */
    334      1.14   tsutsui 	0x05,	/* 05: internal palette  5 */
    335      1.14   tsutsui 	0x14,	/* 06: internal palette  6 */
    336      1.14   tsutsui 	0x07,	/* 07: internal palette  7 */
    337      1.14   tsutsui 	0x38,	/* 08: internal palette  8 */
    338      1.14   tsutsui 	0x39,	/* 09: internal palette  9 */
    339      1.14   tsutsui 	0x3a,	/* 0A: internal palette 10 */
    340      1.14   tsutsui 	0x3b,	/* 0B: internal palette 11 */
    341      1.14   tsutsui 	0x3c,	/* 0C: internal palette 12 */
    342      1.14   tsutsui 	0x3d,	/* 0D: internal palette 13 */
    343      1.14   tsutsui 	0x3e,	/* 0E: internal palette 14 */
    344      1.14   tsutsui 	0x3f,	/* 0F: internal palette 15 */
    345      1.14   tsutsui 	0x0c,	/* 10: attribute mode control */
    346      1.18      jmmv 	WSDISPLAY_BORDER_COLOR,	/* 11: overscan color */
    347      1.14   tsutsui 	0x0f,	/* 12: color plane enable */
    348      1.14   tsutsui 	0x08,	/* 13: horizontal PEL panning */
    349      1.14   tsutsui 	0x00	/* 14: color select */
    350      1.14   tsutsui };
    351      1.14   tsutsui 
    352      1.14   tsutsui /* video DAC palette registers */
    353      1.14   tsutsui /* XXX only set up 16 colors used by internal palette in ATC regsters */
    354      1.14   tsutsui static const u_int8_t vga_dacpal[] = {
    355      1.14   tsutsui 	/* R     G     B */
    356      1.14   tsutsui 	0x00, 0x00, 0x00,	/* BLACK        */
    357      1.14   tsutsui 	0x00, 0x00, 0x2a,	/* BLUE	        */
    358      1.14   tsutsui 	0x00, 0x2a, 0x00,	/* GREEN        */
    359      1.14   tsutsui 	0x00, 0x2a, 0x2a,	/* CYAN         */
    360      1.14   tsutsui 	0x2a, 0x00, 0x00,	/* RED          */
    361      1.14   tsutsui 	0x2a, 0x00, 0x2a,	/* MAGENTA      */
    362      1.14   tsutsui 	0x2a, 0x15, 0x00,	/* BROWN        */
    363      1.14   tsutsui 	0x2a, 0x2a, 0x2a,	/* LIGHTGREY    */
    364      1.14   tsutsui 	0x15, 0x15, 0x15,	/* DARKGREY     */
    365      1.14   tsutsui 	0x15, 0x15, 0x3f,	/* LIGHTBLUE    */
    366      1.14   tsutsui 	0x15, 0x3f, 0x15,	/* LIGHTGREEN   */
    367      1.14   tsutsui 	0x15, 0x3f, 0x3f,	/* LIGHTCYAN    */
    368      1.14   tsutsui 	0x3f, 0x15, 0x15,	/* LIGHTRED     */
    369      1.14   tsutsui 	0x3f, 0x15, 0x3f,	/* LIGHTMAGENTA */
    370      1.14   tsutsui 	0x3f, 0x3f, 0x15,	/* YELLOW       */
    371      1.14   tsutsui 	0x3f, 0x3f, 0x3f	/* WHITE        */
    372      1.14   tsutsui };
    373      1.14   tsutsui 
    374  1.22.4.1        ad void
    375      1.14   tsutsui vga_initregs(vh)
    376      1.14   tsutsui 	struct vga_handle *vh;
    377      1.14   tsutsui {
    378      1.14   tsutsui 	int i;
    379      1.14   tsutsui 
    380      1.14   tsutsui 	/* disable video */
    381      1.14   tsutsui 	vga_ts_write(vh, mode, vga_ts[1] | VGA_TS_MODE_BLANK);
    382      1.14   tsutsui 
    383      1.14   tsutsui 	/* synchronous reset */
    384      1.14   tsutsui 	vga_ts_write(vh, syncreset, 0x01);
    385      1.14   tsutsui 	/* set TS regsters */
    386      1.14   tsutsui 	for (i = 2; i < VGA_TS_NREGS; i++)
    387      1.14   tsutsui 		_vga_ts_write(vh, i, vga_ts[i]);
    388      1.14   tsutsui 	/* clear synchronous reset */
    389      1.14   tsutsui 	vga_ts_write(vh, syncreset, 0x03);
    390      1.14   tsutsui 
    391      1.14   tsutsui 	/* unprotect CRTC regsters */
    392      1.14   tsutsui 	vga_6845_write(vh, vsynce, vga_6845_read(vh, vsynce) & ~0x80);
    393      1.14   tsutsui 	/* set CRTC regsters */
    394      1.14   tsutsui 	for (i = 0; i < MC6845_NREGS; i++)
    395      1.14   tsutsui 		_vga_6845_write(vh, i, vga_crtc[i]);
    396      1.14   tsutsui 
    397      1.14   tsutsui 	/* set GDC regsters */
    398      1.14   tsutsui 	for (i = 0; i < VGA_GDC_NREGS; i++)
    399      1.14   tsutsui 		_vga_gdc_write(vh, i, vga_gdc[i]);
    400      1.14   tsutsui 
    401      1.14   tsutsui 	/* set ATC regsters */
    402      1.14   tsutsui 	for (i = 0; i < VGA_ATC_NREGS; i++)
    403      1.14   tsutsui 		_vga_attr_write(vh, i, vga_atc[i]);
    404      1.14   tsutsui 
    405      1.14   tsutsui 	/* set DAC palette */
    406      1.14   tsutsui 	if (!vh->vh_mono) {
    407      1.14   tsutsui 		for (i = 0; i < 16; i++) {
    408      1.14   tsutsui 			bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga,
    409      1.14   tsutsui 			    VGA_DAC_ADDRW, vga_atc[i]);
    410      1.14   tsutsui 			bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga,
    411      1.14   tsutsui 			    VGA_DAC_PALETTE, vga_dacpal[i * 3 + 0]);
    412      1.14   tsutsui 			bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga,
    413      1.14   tsutsui 			    VGA_DAC_PALETTE, vga_dacpal[i * 3 + 1]);
    414      1.14   tsutsui 			bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga,
    415      1.14   tsutsui 			    VGA_DAC_PALETTE, vga_dacpal[i * 3 + 2]);
    416      1.14   tsutsui 		}
    417      1.14   tsutsui 	}
    418      1.14   tsutsui 
    419      1.14   tsutsui 	/* set misc output register */
    420      1.14   tsutsui 	bus_space_write_1(vh->vh_iot, vh->vh_ioh_vga,
    421      1.14   tsutsui 	    VGA_MISC_DATAW, VGA_MISCOUT | (vh->vh_mono ? 0 : 0x01));
    422      1.14   tsutsui 
    423      1.14   tsutsui 	/* reenable video */
    424      1.14   tsutsui 	vga_ts_write(vh, mode, vga_ts[1] & ~VGA_TS_MODE_BLANK);
    425      1.14   tsutsui }
    426