/*-
* Copyright (c) 2000 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
* by Tohru Nishimura.
*
* 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.
*/
#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
struct om_hwdevconfig {
int dc_wid; /* width of frame buffer */
int dc_ht; /* height of frame buffer */
int dc_depth; /* depth, bits per pixel */
int dc_rowbytes; /* bytes in a FB scan line */
int dc_cmsize; /* colormap size */
struct hwcmap dc_cmap; /* software copy of colormap */
vaddr_t dc_videobase; /* base of flat frame buffer */
struct rasops_info dc_ri; /* raster blitter variables */
};
struct omfb_softc {
device_t sc_dev; /* base device */
struct om_hwdevconfig *sc_dc; /* device configuration */
int sc_nscreens;
int sc_mode;
};
static int omgetcmap(struct omfb_softc *, struct wsdisplay_cmap *);
static int omsetcmap(struct omfb_softc *, struct wsdisplay_cmap *);
case WSDISPLAYIO_LINEBYTES:
*(u_int *)data = dc->dc_rowbytes;
return 0;
case WSDISPLAYIO_GETCMAP:
return omgetcmap(sc, (struct wsdisplay_cmap *)data);
case WSDISPLAYIO_PUTCMAP:
return omsetcmap(sc, (struct wsdisplay_cmap *)data);
case WSDISPLAYIO_SMODE:
new_mode = *(int *)data;
if (new_mode != sc->sc_mode) {
sc->sc_mode = new_mode;
if (new_mode == WSDISPLAYIO_MODE_EMUL)
omfb_resetcmap(dc);
}
return 0;
case WSDISPLAYIO_SVIDEO:
case WSDISPLAYIO_GVIDEO:
case WSDISPLAYIO_GCURPOS:
case WSDISPLAYIO_SCURPOS:
case WSDISPLAYIO_GCURMAX:
case WSDISPLAYIO_GCURSOR:
case WSDISPLAYIO_SCURSOR:
break;
}
return EPASSTHROUGH;
}
/*
* Return the address that would map the given device at the given
* offset, allowing for the given protection, or return -1 for error.
*/
static paddr_t
omfbmmap(void *v, void *vs, off_t offset, int prot)
{
struct omfb_softc *sc = v;
struct om_hwdevconfig *dc = sc->sc_dc;
paddr_t cookie = -1;
/*
* On 1bpp framebuffer, only plane P0 has framebuffer memory
* and other planes seems pulled up, i.e. always 1.
* Set white only for a palette (P0,P1,P2,P3) = (1,1,1,1).
*/
odac->bt_addr = 0;
for (i = 0; i < 15; i++) {
odac->bt_cmap = dc->dc_cmap.r[i] = 0;
odac->bt_cmap = dc->dc_cmap.g[i] = 0;
odac->bt_cmap = dc->dc_cmap.b[i] = 0;
}
/*
* The B/W video connector is connected to IOG of Bt454,
* and IOR and IOB are unused.
*/
odac->bt_cmap = dc->dc_cmap.r[15] = 0;
odac->bt_cmap = dc->dc_cmap.g[15] = 255;
odac->bt_cmap = dc->dc_cmap.b[15] = 0;
} else if (hwplanemask == 0x0f) {
struct bt454 *odac = (struct bt454 *)OMFB_RAMDAC;
/*
* Initialize the Bt458. When we write to control registers,
* the address is not incremented automatically. So we specify
* it ourselves for each control register.
*/
ndac->bt_addr = 0x04;
ndac->bt_ctrl = 0xff; /* all planes will be read */
ndac->bt_addr = 0x05;
ndac->bt_ctrl = 0x00; /* all planes have non-blink */
ndac->bt_addr = 0x06;
ndac->bt_ctrl = 0x40; /* palette enabled, ovly plane disabled */
ndac->bt_addr = 0x07;
ndac->bt_ctrl = 0x00; /* no test mode */
/*
* Set ANSI 16 colors. We only supports 4bpp console right
* now, repeat 16 colors in 256 colormap.
*/
ndac->bt_addr = 0;
for (i = 0; i < 256; i++) {
ndac->bt_cmap = dc->dc_cmap.r[i] = ansicmap[i % 16].r;
ndac->bt_cmap = dc->dc_cmap.g[i] = ansicmap[i % 16].g;
ndac->bt_cmap = dc->dc_cmap.b[i] = ansicmap[i % 16].b;
}
}
}
static void
omfb_getdevconfig(paddr_t paddr, struct om_hwdevconfig *dc)
{
int bpp, i;
struct rasops_info *ri;
union {
struct { short h, v; } p;
uint32_t u;
} rfcnt;
switch (hwplanemask) {
case 0xff:
bpp = 8; /* XXX check monochrome bit in DIPSW */
break;
default:
case 0x0f:
bpp = 4; /* XXX check monochrome bit in DIPSW */
break;
case 1:
bpp = 1;
break;
}
dc->dc_wid = 1280;
dc->dc_ht = 1024;
dc->dc_depth = bpp;
dc->dc_rowbytes = 2048 / 8;
dc->dc_cmsize = (bpp == 1) ? 0 : 1 << bpp;
dc->dc_videobase = paddr;
omfb_resetcmap(dc);
/* adjust h/v origin on screen */
rfcnt.p.h = 7;
rfcnt.p.v = -27;
/* single write of 0x007ffe6 */
*(volatile uint32_t *)OMFB_RFCNT = rfcnt.u;