First step to a framework that can be used to initialize vga-cards on the

pci-bus. The code is called early in the bootphase and tries to initialize
a known type of card into a 'standard' text mode. Wscons should be able
to handle these cards afterwards.
This commit is contained in:
leo 1999-03-15 15:47:11 +00:00
parent 9729dbb6ad
commit b9cb0eefd0
5 changed files with 444 additions and 2 deletions

View File

@ -1,5 +1,5 @@
#
# $NetBSD: files.atari,v 1.59 1998/12/15 19:36:58 itohy Exp $
# $NetBSD: files.atari,v 1.60 1999/03/15 15:47:11 leo Exp $
maxpartitions 16
@ -129,6 +129,8 @@ file arch/atari/dev/ms.c mouse needs-count
# PCI-devices
#
file arch/atari/pci/pci_machdep.c pci | grfet
file arch/atari/pci/pci_vga.c pci
file arch/atari/pci/pci_tseng.c pci
device pcibus
attach pcibus at mainbus

View File

@ -1,4 +1,4 @@
/* $NetBSD: pci_machdep.c,v 1.16 1999/02/19 20:57:15 leo Exp $ */
/* $NetBSD: pci_machdep.c,v 1.17 1999/03/15 15:47:22 leo Exp $ */
/*
* Copyright (c) 1996 Leo Weppelman. All rights reserved.
@ -52,6 +52,7 @@
#include <machine/bus.h>
#include <atari/atari/device.h>
#include <atari/pci/pci_vga.h>
/*
* Sizes of pci memory and I/O area.
@ -187,6 +188,12 @@ init_pci_bus()
csr &= ~PCI_COMMAND_MASTER_ENABLE;
pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, csr);
}
/*
* Scan the bus for a VGA-card that we support. If we find
* one, try to initialize it to a 'standard' text mode (80x25).
*/
check_for_vga();
}
/*

View File

@ -0,0 +1,190 @@
/* $NetBSD: pci_tseng.c,v 1.1 1999/03/15 15:47:22 leo Exp $ */
/*
* Copyright (c) 1999 Leo Weppelman. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Leo Weppelman.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/systm.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcidevs.h>
#include <atari/pci/pci_vga.h>
#include <atari/dev/grf_etreg.h>
#define PCI_LINMEMBASE 0x0e000000
#define PCI_IOBASE 0x800
static void et6000_init(volatile u_char *, u_char *);
/*
* Use tables for the card init...
*/
static u_char seq_tab[] = {
0x03, 0x01, 0x03, 0x00, 0x02, 0x00, 0x00, 0x00 };
static u_char gfx_tab[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x06, 0x0f, 0xff };
static u_char attr_tab[] = {
0x0a, 0x00, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x00 };
static u_char crt_tab[] = {
0x60, 0x53, 0x4f, 0x94, 0x56, 0x05, 0xc1, 0x1f,
0x00, 0x4f, 0x00, 0x0f, 0x00, 0x00, 0x07, 0x80,
0x98, 0x3d, 0x8f, 0x28, 0x0f, 0x8f, 0xc2, 0xa3,
0xff, 0x3d, 0x8f, 0x28, 0x0f, 0x8f, 0xc2, 0xa3,
0x60, 0x08, 0x00, 0x00, 0x56, 0x05, 0xc1, 0x1f,
0x00, 0x4f, 0x00, 0x0f, 0x00, 0x00, 0x07, 0x80,
0x85, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00,
0x05, 0x01, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00 };
void
tseng_init(pc, tag, id, ba, fb)
pci_chipset_tag_t pc;
pcitag_t tag;
int id;
volatile u_char *ba;
u_char *fb;
{
int i, csr;
int is_et6000 = 0;
is_et6000 = (id == PCI_PRODUCT_TSENG_ET6000) ? 1 : 0;
/* Turn on the card */
pci_conf_write(pc, tag, PCI_MAPREG_START, PCI_LINMEMBASE);
if (is_et6000)
pci_conf_write(pc, tag, PCI_MAPREG_START+4,
PCI_IOBASE | PCI_MAPREG_TYPE_IO);
csr = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
csr |= (PCI_COMMAND_MEM_ENABLE|PCI_COMMAND_IO_ENABLE);
csr |= PCI_COMMAND_MASTER_ENABLE;
pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, csr);
if (is_et6000)
et6000_init(ba, fb);
vgaw(ba, GREG_MISC_OUTPUT_W, 0x63);
vgaw(ba, GREG_VIDEOSYSENABLE, 0x01);
WCrt(ba, 0x17 , 0x00); /* color */
WCrt(ba, 0x11 , 0x00); /* color */
vgaw(ba, VDAC_MASK , 0xff);
WSeq(ba, SEQ_ID_RESET , 0x00);
vgaw(ba, GREG_HERCULESCOMPAT, 0x03);
vgaw(ba, GREG_DISPMODECONTROL, 0xa0);
/* Load sequencer */
for (i = 1; i < 8; i++)
WSeq(ba, i, seq_tab[i]);
WSeq(ba, SEQ_ID_RESET , 0x03);
vgar(ba, VDAC_ADDRESS); /* clear old state */
vgar(ba, VDAC_MASK);
vgar(ba, VDAC_MASK);
vgar(ba, VDAC_MASK);
vgar(ba, VDAC_MASK);
vgaw(ba, VDAC_MASK, 0); /* set to palette */
vgar(ba, VDAC_ADDRESS); /* clear state */
vgaw(ba, VDAC_MASK, 0xff);
/*
* Make sure we're allowed to write all crt-registers
*/
WCrt(ba, CRT_ID_END_VER_RETR, (RCrt(ba, CRT_ID_END_VER_RETR) & 0x7f));
/* CRT registers */
for (i = 0; i < 0x3e; i++)
WCrt(ba, i, crt_tab[i]);
/* GCT registers */
for (i = 0; i < 0x09; i++)
WGfx(ba, i, gfx_tab[i]);
for (i = 0; i < 0x10; i++)
WAttr(ba, i, i);
for (; i < 0x18; i++)
WAttr(ba, i, attr_tab[i - 0x10]);
WAttr(ba, 0x20, 0);
}
/*
* Initialize the et6000 specific (PCI) registers. Try to do it like the
* video-bios would have done it, so things like Xservers get what they
* expect. Most info was kindly provided by Koen Gadeyne.
*/
static void
et6000_init(ba, fb)
volatile u_char *ba;
u_char *fb;
{
int i;
u_char dac_tab[] = { 0x7d,0x67, 0x5d,0x64, 0x56,0x63,
0x28,0x22, 0x79,0x49, 0x6f,0x47,
0x28,0x41, 0x6b,0x44, 0x00,0x00,
0x00,0x00, 0x5d,0x25, 0x00,0x00,
0x00,0x00, 0x00,0x96 };
ba += 0x800;
ba[0x40] = 0x06; /* Use standard vga addressing */
ba[0x41] = 0x2a; /* Performance control */
ba[0x43] = 0x02; /* XCLK/SCLK config */
ba[0x44] = 0x11; /* RAS/CAS config */
ba[0x46] = 0x00; /* CRT display feature */
ba[0x47] = 0x10;
ba[0x58] = 0x00; /* Video Control 1 */
ba[0x59] = 0x04; /* Video Control 2 */
/*
* Setup a 'standard' CLKDAC
*/
ba[0x42] = 0x00; /* MCLK == CLK0 */
ba[0x67] = 0x00; /* Start filling from dac-reg 0 and up... */
for (i = 0; i < 0x16; i++)
ba[0x69] = dac_tab[i];
if (ba[8] == 0x70) { /* et6100, right? */
volatile u_char *ma = (volatile u_char *)fb;
u_char bv;
/*
* XXX Black magic to get the bloody MDRAM's to function...
* XXX _Only_ tested on my card! [leo]
*/
bv = ba[45];
ba[0x45] = bv | 0x40; /* Reset MDRAM's */
ba[0x45] = bv | 0x70; /* Program latency value */
ma[0x0] = 0; /* Yeah, right :-( */
ba[0x45] = bv; /* Back to normal */
ba[0x44] = 0x14; /* RAS/CAS config */
}
}

View File

@ -0,0 +1,206 @@
/* $NetBSD: pci_vga.c,v 1.1 1999/03/15 15:47:22 leo Exp $ */
/*
* Copyright (c) 1999 Leo Weppelman. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Leo Weppelman.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <sys/param.h>
#include <sys/queue.h>
#include <sys/systm.h>
#include <dev/pci/pcireg.h>
#include <dev/pci/pcivar.h>
#include <dev/pci/pcidevs.h>
#include <atari/pci/pci_vga.h>
#include <atari/dev/grf_etreg.h>
#include <atari/include/iomap.h>
#include <atari/dev/font.h>
static void loadfont(volatile u_char *, u_char *fb);
/* XXX: Shouldn't these be in font.h???? */
extern font_info font_info_8x8;
extern font_info font_info_8x16;
/* Console colors */
static u_char conscolors[3][3] = { /* background, foreground, hilite */
{0x0, 0x0, 0x0}, {0x30, 0x30, 0x30}, { 0x3f, 0x3f, 0x3f}
};
/*
* Go look for a VGA card on the PCI-bus. This search is a
* stripped down version of the PCI-probe. It only looks on
* bus0 for VGA cards. The first card found is used.
*/
int
check_for_vga()
{
pci_chipset_tag_t pc = NULL; /* XXX */
pcitag_t tag;
int device, found, id, maxndevs, i, j;
volatile u_char *regs;
u_char *fb;
char *nbd = "NetBSD/Atari";
found = 0;
tag = 0;
id = 0;
maxndevs = pci_bus_maxdevs(pc, 0);
/*
* These are setup in atari_init.c
*/
regs = (volatile caddr_t)pci_io_addr;
fb = (caddr_t)pci_mem_addr;
for (device = 0; !found && (device < maxndevs); device++) {
tag = pci_make_tag(pc, 0, device, 0);
id = pci_conf_read(pc, tag, PCI_ID_REG);
if (id == 0 || id == 0xffffffff)
continue;
switch (id = PCI_PRODUCT(id)) {
/*
* XXX Make the inclusion of the cases dependend
* on config options!
*/
case PCI_PRODUCT_TSENG_ET6000:
case PCI_PRODUCT_TSENG_ET4000_W32P_A:
case PCI_PRODUCT_TSENG_ET4000_W32P_B:
case PCI_PRODUCT_TSENG_ET4000_W32P_C:
case PCI_PRODUCT_TSENG_ET4000_W32P_D:
tseng_init(pc, tag, id, regs, fb);
found = 1;
break;
default:
break;
}
}
if (!found)
return (0);
/*
* Generic parts of the initialization...
*/
/* B&W colors */
vgaw(regs, VDAC_ADDRESS_W, 0);
for (i = 0; i < 256; i++) {
j = (i & 1) ? ((i > 7) ? 2 : 1) : 0;
vgaw(regs, VDAC_DATA, conscolors[j][0]);
vgaw(regs, VDAC_DATA, conscolors[j][1]);
vgaw(regs, VDAC_DATA, conscolors[j][2]);
}
loadfont(regs, fb);
/*
* Clear the screen and print a message. The latter
* is of diagnostic/debug use only.
*/
for (i = 50 * 80; i >= 0; i -= 2) {
fb[i] = 0x20; fb[i+1] = 0x07;
}
for (i = 56; *nbd; i += 2)
fb[i] = *nbd++;
return (1);
}
/*
* Generic VGA. Load the configured kernel font into the videomemory and
* place the card into textmode.
*/
static void
loadfont(ba, fb)
volatile u_char *ba; /* Register area KVA */
u_char *fb; /* Frame buffer KVA */
{
font_info *fd;
u_char *c, *f, tmp;
u_short z, y;
#if defined(KFONT_8X8)
fd = &font_info_8x8;
#else
fd = &font_info_8x16;
#endif
WAttr(ba, 0x20 | ACT_ID_ATTR_MODE_CNTL, 0x0a);
WSeq(ba, SEQ_ID_MAP_MASK, 0x04);
WSeq(ba, SEQ_ID_MEMORY_MODE, 0x06);
WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x02);
WGfx(ba, GCT_ID_GRAPHICS_MODE, 0x00);
WGfx(ba, GCT_ID_MISC, 0x04);
/*
* load text font into beginning of display memory. Each
* character cell is 32 bytes long (enough for 4 planes)
*/
for (z = 0, c = fb; z < 256 * 32; z++)
*c++ = 0;
c = (unsigned char *) (fb) + (32 * fd->font_lo);
f = fd->font_p;
z = fd->font_lo;
for (; z <= fd->font_hi; z++, c += (32 - fd->height))
for (y = 0; y < fd->height; y++) {
*c++ = *f++;
}
/*
* Odd/Even addressing
*/
WSeq(ba, SEQ_ID_MAP_MASK, 0x03);
WSeq(ba, SEQ_ID_MEMORY_MODE, 0x03);
WGfx(ba, GCT_ID_READ_MAP_SELECT, 0x00);
WGfx(ba, GCT_ID_GRAPHICS_MODE, 0x10);
WGfx(ba, GCT_ID_MISC, 0x06);
/*
* Font height + underline location
*/
tmp = RCrt(ba, CRT_ID_MAX_ROW_ADDRESS) & 0xe0;
WCrt(ba, CRT_ID_MAX_ROW_ADDRESS, tmp | (fd->height - 1));
tmp = RCrt(ba, CRT_ID_UNDERLINE_LOC) & 0xe0;
WCrt(ba, CRT_ID_UNDERLINE_LOC, tmp | (fd->height - 1));
/*
* Cursor setup
*/
WCrt(ba, CRT_ID_CURSOR_START , 0x00);
WCrt(ba, CRT_ID_CURSOR_END , fd->height - 1);
WCrt(ba, CRT_ID_CURSOR_LOC_HIGH, 0x00);
WCrt(ba, CRT_ID_CURSOR_LOC_LOW , 0x00);
/*
* Enter text mode
*/
WCrt(ba, CRT_ID_MODE_CONTROL , 0xa3);
WAttr(ba, ACT_ID_ATTR_MODE_CNTL | 0x20, 0x0a);
}

View File

@ -0,0 +1,37 @@
/* $NetBSD: pci_vga.h,v 1.1 1999/03/15 15:47:22 leo Exp $ */
/*
* Copyright (c) 1999 Leo Weppelman. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Leo Weppelman.
* 4. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
int check_for_vga __P((void));
/*
* Card specific functions
*/
void tseng_init __P((pci_chipset_tag_t, pcitag_t, int, volatile u_char *,
u_char *));