/*-
* Copyright (c) 2010 Michael Lorenz
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
* ``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 FOUNDATION OR CONTRIBUTORS
* 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.
*/
/* a console driver for the Sun CG12 / Matrox SG3 graphics board */
if (strcmp("cgtwelve", sa->sa_name) == 0)
return 100;
return 0;
}
/*
* Attach a display. We need to notice if it is the console, too.
*/
static void
cgtwelve_attach(device_t parent, device_t self, void *args)
{
struct cgtwelve_softc *sc = device_private(self);
struct sbus_attach_args *sa = args;
struct wsemuldisplaydev_attach_args aa;
struct rasops_info *ri;
unsigned long defattr;
bus_space_handle_t bh;
int node = sa->sa_node;
int isconsole;
static void
cgtwelve_write_dac(struct cgtwelve_softc *sc, int idx, int r, int g, int b)
{
uint32_t lo = (idx & 0xff);
uint32_t hi = (idx >> 8) & 0xff;
lo |= lo << 8 | lo << 16;
hi |= hi << 8 | hi << 16;
bus_space_write_4(sc->sc_tag, sc->sc_regh, CG12DAC_ADDR0, lo);
bus_space_write_4(sc->sc_tag, sc->sc_regh, CG12DAC_ADDR1, hi);
bus_space_write_4(sc->sc_tag, sc->sc_regh, CG12DAC_DATA,
b << 16 | g << 8 | r);
}
static void
cgtwelve_setup(struct cgtwelve_softc *sc, int depth)
{
int i, j;
/* first let's put some stuff into the WID table */
cgtwelve_write_wid(sc, 0, CG12_WID_8_BIT);
cgtwelve_write_wid(sc, 1, CG12_WID_24_BIT);
/* a linear ramp for the gamma table */
for (i = 0; i < 256; i++)
cgtwelve_write_dac(sc, i + 0x100, i, i, i);
j = 0;
/* rasops' ANSI colour map */
for (i = 0; i < 256; i++) {
cgtwelve_write_dac(sc, i,
rasops_cmap[j],
rasops_cmap[j + 1],
rasops_cmap[j + 2]);
j += 3;
}
switch(depth) {
case 1:
/* setup the console */
/* first, make the overlay all opaque */
cgtwelve_select_ovl(sc, CG12_SEL_ENABLE);
memset(sc->sc_fbaddr, 0xff, 0x20000);
/* now write the right thing into the WID plane */
cgtwelve_select_ovl(sc, CG12_SEL_WID);
memset(sc->sc_wids, 0, 0x100000);
/* now clean the plane */
cgtwelve_select_ovl(sc, CG12_SEL_OVL);
memset(sc->sc_fbaddr, 0, 0x20000);
break;
case 8:
/* setup the 8bit fb */
/*
* first clean the 8bit fb - for aesthetic reasons do it while
* it's still not visible ( we hope... )
*/
cgtwelve_select_ovl(sc, CG12_SEL_8BIT);
memset(sc->sc_int, 0x00, 0x100000);
/* now write the right thing into the WID plane */
cgtwelve_select_ovl(sc, CG12_SEL_WID);
memset(sc->sc_wids, 0, 0x100000);
/* hide the overlay */
cgtwelve_select_ovl(sc, CG12_SEL_ENABLE);
memset(sc->sc_fbaddr, 0, 0x20000);
/* now clean the plane */
cgtwelve_select_ovl(sc, CG12_SEL_OVL);
memset(sc->sc_fbaddr, 0, 0x20000);
/* and make sure we can write the 8bit fb */
cgtwelve_select_ovl(sc, CG12_SEL_8BIT);
break;
case 24:
case 32:
/* setup the 24bit fb for X */
/*
* first clean the 24bit fb - for aesthetic reasons do it while
* it's still not visible ( we hope... )
*/
cgtwelve_select_ovl(sc, CG12_SEL_24BIT);
memset(sc->sc_int, 0x80, 0x400000);
/* now write the right thing into the WID plane */
cgtwelve_select_ovl(sc, CG12_SEL_WID);
memset(sc->sc_wids, 1, 0x100000);
/* hide the overlay */
cgtwelve_select_ovl(sc, CG12_SEL_ENABLE);
memset(sc->sc_fbaddr, 0, 0x20000);
/* now clean the plane */
cgtwelve_select_ovl(sc, CG12_SEL_OVL);
memset(sc->sc_fbaddr, 0, 0x20000);
/* and make sure we can write the 24bit fb */
cgtwelve_select_ovl(sc, CG12_SEL_24BIT);
break;
}
}