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