Home | History | Annotate | Line # | Download | only in pci
pci_vga.c revision 1.2
      1 /*	$NetBSD: pci_vga.c,v 1.2 2001/05/21 14:30:42 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 	 * Assume the device is in CGA mode. Wscons expects this too...
    109 	 */
    110 	fb = fb + 0x18000;
    111 
    112 	/*
    113 	 * Generic parts of the initialization...
    114 	 */
    115 
    116 	/* B&W colors */
    117 	vgaw(regs, VDAC_ADDRESS_W, 0);
    118 	for (i = 0; i < 256; i++) {
    119 		j = (i & 1) ? ((i > 7) ? 2 : 1) : 0;
    120 		vgaw(regs, VDAC_DATA, conscolors[j][0]);
    121 		vgaw(regs, VDAC_DATA, conscolors[j][1]);
    122 		vgaw(regs, VDAC_DATA, conscolors[j][2]);
    123 	}
    124 
    125 	loadfont(regs, fb);
    126 
    127 	/*
    128 	 * Clear the screen and print a message. The latter
    129 	 * is of diagnostic/debug use only.
    130 	 */
    131 	for (i = 50 * 80; i >= 0; i -= 2) {
    132 		fb[i] = 0x20; fb[i+1] = 0x07;
    133 	}
    134 	for (i = 56; *nbd; i += 2)
    135 		fb[i] = *nbd++;
    136 
    137 	return (1);
    138 }
    139 
    140 /*
    141  * Generic VGA. Load the configured kernel font into the videomemory and
    142  * place the card into textmode.
    143  */
    144 static void
    145 loadfont(ba, fb)
    146 	volatile u_char *ba;	/* Register area KVA */
    147 	u_char		*fb;	/* Frame buffer	KVA  */
    148 {
    149 	font_info	*fd;
    150 	u_char		*c, *f, tmp;
    151 	u_short		z, y;
    152 
    153 #if defined(KFONT_8X8)
    154 	fd = &font_info_8x8;
    155 #else
    156 	fd = &font_info_8x16;
    157 #endif
    158 
    159 	WAttr(ba, 0x20 | ACT_ID_ATTR_MODE_CNTL, 0x0a);
    160 	WSeq(ba, SEQ_ID_MAP_MASK,	 0x04);
    161 	WSeq(ba, SEQ_ID_MEMORY_MODE,	 0x06);
    162 	WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x02);
    163 	WGfx(ba, GCT_ID_GRAPHICS_MODE,	 0x00);
    164 	WGfx(ba, GCT_ID_MISC,		 0x0c);
    165 
    166 	/*
    167 	 * load text font into beginning of display memory. Each
    168 	 * character cell is 32 bytes long (enough for 4 planes)
    169 	 */
    170 	for (z = 0, c = fb; z < 256 * 32; z++)
    171 		*c++ = 0;
    172 
    173 	c = (unsigned char *) (fb) + (32 * fd->font_lo);
    174 	f = fd->font_p;
    175 	z = fd->font_lo;
    176 	for (; z <= fd->font_hi; z++, c += (32 - fd->height))
    177 		for (y = 0; y < fd->height; y++) {
    178 			*c++ = *f++;
    179 		}
    180 
    181 	/*
    182 	 * Odd/Even addressing
    183 	 */
    184 	WSeq(ba, SEQ_ID_MAP_MASK,	 0x03);
    185 	WSeq(ba, SEQ_ID_MEMORY_MODE,	 0x03);
    186 	WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x00);
    187 	WGfx(ba, GCT_ID_GRAPHICS_MODE,	 0x10);
    188 	WGfx(ba, GCT_ID_MISC,		 0x0e);
    189 
    190 	/*
    191 	 * Font height + underline location
    192 	 */
    193 	tmp = RCrt(ba, CRT_ID_MAX_ROW_ADDRESS) & 0xe0;
    194 	WCrt(ba, CRT_ID_MAX_ROW_ADDRESS, tmp | (fd->height - 1));
    195 	tmp = RCrt(ba, CRT_ID_UNDERLINE_LOC)   & 0xe0;
    196 	WCrt(ba, CRT_ID_UNDERLINE_LOC,   tmp | (fd->height - 1));
    197 
    198 	/*
    199 	 * Cursor setup
    200 	 */
    201 	WCrt(ba, CRT_ID_CURSOR_START   , 0x00);
    202 	WCrt(ba, CRT_ID_CURSOR_END     , fd->height - 1);
    203 	WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, 0x00);
    204 	WCrt(ba, CRT_ID_CURSOR_LOC_LOW , 0x00);
    205 
    206 	/*
    207 	 * Enter text mode
    208 	 */
    209 	WCrt(ba, CRT_ID_MODE_CONTROL   , 0xa3);
    210 	WAttr(ba, ACT_ID_ATTR_MODE_CNTL | 0x20, 0x0a);
    211 }
    212