Home | History | Annotate | Line # | Download | only in dev
dvbox.c revision 1.1.2.2
      1  1.1.2.2  bouyer /*	$NetBSD: dvbox.c,v 1.1.2.2 2011/02/08 16:19:21 bouyer Exp $	*/
      2  1.1.2.2  bouyer /*	$OpenBSD: dvbox.c,v 1.13 2006/08/11 18:33:13 miod Exp $	*/
      3  1.1.2.2  bouyer 
      4  1.1.2.2  bouyer /*
      5  1.1.2.2  bouyer  * Copyright (c) 2005, Miodrag Vallat
      6  1.1.2.2  bouyer  *
      7  1.1.2.2  bouyer  * Redistribution and use in source and binary forms, with or without
      8  1.1.2.2  bouyer  * modification, are permitted provided that the following conditions
      9  1.1.2.2  bouyer  * are met:
     10  1.1.2.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     11  1.1.2.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     12  1.1.2.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1.2.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     14  1.1.2.2  bouyer  *    documentation and/or other materials provided with the distribution.
     15  1.1.2.2  bouyer  *
     16  1.1.2.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  1.1.2.2  bouyer  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     18  1.1.2.2  bouyer  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     19  1.1.2.2  bouyer  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
     20  1.1.2.2  bouyer  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     21  1.1.2.2  bouyer  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     22  1.1.2.2  bouyer  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  1.1.2.2  bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     24  1.1.2.2  bouyer  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
     25  1.1.2.2  bouyer  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.1.2.2  bouyer  * POSSIBILITY OF SUCH DAMAGE.
     27  1.1.2.2  bouyer  */
     28  1.1.2.2  bouyer /*-
     29  1.1.2.2  bouyer  * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
     30  1.1.2.2  bouyer  * All rights reserved.
     31  1.1.2.2  bouyer  *
     32  1.1.2.2  bouyer  * This code is derived from software contributed to The NetBSD Foundation
     33  1.1.2.2  bouyer  * by Jason R. Thorpe.
     34  1.1.2.2  bouyer  *
     35  1.1.2.2  bouyer  * Redistribution and use in source and binary forms, with or without
     36  1.1.2.2  bouyer  * modification, are permitted provided that the following conditions
     37  1.1.2.2  bouyer  * are met:
     38  1.1.2.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     39  1.1.2.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     40  1.1.2.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     41  1.1.2.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     42  1.1.2.2  bouyer  *    documentation and/or other materials provided with the distribution.
     43  1.1.2.2  bouyer  *
     44  1.1.2.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     45  1.1.2.2  bouyer  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     46  1.1.2.2  bouyer  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     47  1.1.2.2  bouyer  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     48  1.1.2.2  bouyer  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     49  1.1.2.2  bouyer  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     50  1.1.2.2  bouyer  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     51  1.1.2.2  bouyer  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     52  1.1.2.2  bouyer  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     53  1.1.2.2  bouyer  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     54  1.1.2.2  bouyer  * POSSIBILITY OF SUCH DAMAGE.
     55  1.1.2.2  bouyer  */
     56  1.1.2.2  bouyer 
     57  1.1.2.2  bouyer /*
     58  1.1.2.2  bouyer  * Copyright (c) 1988 University of Utah.
     59  1.1.2.2  bouyer  * Copyright (c) 1990, 1993
     60  1.1.2.2  bouyer  *	The Regents of the University of California.  All rights reserved.
     61  1.1.2.2  bouyer  *
     62  1.1.2.2  bouyer  * This code is derived from software contributed to Berkeley by
     63  1.1.2.2  bouyer  * the Systems Programming Group of the University of Utah Computer
     64  1.1.2.2  bouyer  * Science Department.
     65  1.1.2.2  bouyer  *
     66  1.1.2.2  bouyer  * Redistribution and use in source and binary forms, with or without
     67  1.1.2.2  bouyer  * modification, are permitted provided that the following conditions
     68  1.1.2.2  bouyer  * are met:
     69  1.1.2.2  bouyer  * 1. Redistributions of source code must retain the above copyright
     70  1.1.2.2  bouyer  *    notice, this list of conditions and the following disclaimer.
     71  1.1.2.2  bouyer  * 2. Redistributions in binary form must reproduce the above copyright
     72  1.1.2.2  bouyer  *    notice, this list of conditions and the following disclaimer in the
     73  1.1.2.2  bouyer  *    documentation and/or other materials provided with the distribution.
     74  1.1.2.2  bouyer  * 3. Neither the name of the University nor the names of its contributors
     75  1.1.2.2  bouyer  *    may be used to endorse or promote products derived from this software
     76  1.1.2.2  bouyer  *    without specific prior written permission.
     77  1.1.2.2  bouyer  *
     78  1.1.2.2  bouyer  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     79  1.1.2.2  bouyer  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     80  1.1.2.2  bouyer  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     81  1.1.2.2  bouyer  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     82  1.1.2.2  bouyer  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     83  1.1.2.2  bouyer  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     84  1.1.2.2  bouyer  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     85  1.1.2.2  bouyer  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     86  1.1.2.2  bouyer  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     87  1.1.2.2  bouyer  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     88  1.1.2.2  bouyer  * SUCH DAMAGE.
     89  1.1.2.2  bouyer  *
     90  1.1.2.2  bouyer  * from: Utah $Hdr: grf_dv.c 1.12 93/08/13$
     91  1.1.2.2  bouyer  *
     92  1.1.2.2  bouyer  *	@(#)grf_dv.c	8.4 (Berkeley) 1/12/94
     93  1.1.2.2  bouyer  */
     94  1.1.2.2  bouyer 
     95  1.1.2.2  bouyer /*
     96  1.1.2.2  bouyer  * Graphics routines for the DaVinci, HP98730/98731 Graphics system.
     97  1.1.2.2  bouyer  */
     98  1.1.2.2  bouyer 
     99  1.1.2.2  bouyer #include <sys/param.h>
    100  1.1.2.2  bouyer #include <sys/systm.h>
    101  1.1.2.2  bouyer #include <sys/conf.h>
    102  1.1.2.2  bouyer #include <sys/device.h>
    103  1.1.2.2  bouyer #include <sys/proc.h>
    104  1.1.2.2  bouyer #include <sys/ioctl.h>
    105  1.1.2.2  bouyer #include <sys/bus.h>
    106  1.1.2.2  bouyer #include <sys/cpu.h>
    107  1.1.2.2  bouyer 
    108  1.1.2.2  bouyer #include <machine/autoconf.h>
    109  1.1.2.2  bouyer 
    110  1.1.2.2  bouyer #include <hp300/dev/dioreg.h>
    111  1.1.2.2  bouyer #include <hp300/dev/diovar.h>
    112  1.1.2.2  bouyer #include <hp300/dev/diodevs.h>
    113  1.1.2.2  bouyer #include <hp300/dev/intiovar.h>
    114  1.1.2.2  bouyer 
    115  1.1.2.2  bouyer #include <dev/wscons/wsconsio.h>
    116  1.1.2.2  bouyer #include <dev/wscons/wsdisplayvar.h>
    117  1.1.2.2  bouyer #include <dev/rasops/rasops.h>
    118  1.1.2.2  bouyer 
    119  1.1.2.2  bouyer #include <hp300/dev/diofbreg.h>
    120  1.1.2.2  bouyer #include <hp300/dev/diofbvar.h>
    121  1.1.2.2  bouyer #include <hp300/dev/dvboxreg.h>
    122  1.1.2.2  bouyer 
    123  1.1.2.2  bouyer struct	dvbox_softc {
    124  1.1.2.2  bouyer 	device_t	sc_dev;
    125  1.1.2.2  bouyer 	struct diofb	*sc_fb;
    126  1.1.2.2  bouyer 	struct diofb	sc_fb_store;
    127  1.1.2.2  bouyer 	int		sc_scode;
    128  1.1.2.2  bouyer };
    129  1.1.2.2  bouyer 
    130  1.1.2.2  bouyer int	dvbox_dio_match(device_t, cfdata_t, void *);
    131  1.1.2.2  bouyer void	dvbox_dio_attach(device_t, device_t, void *);
    132  1.1.2.2  bouyer int	dvbox_intio_match(device_t, cfdata_t, void *);
    133  1.1.2.2  bouyer void	dvbox_intio_attach(device_t, device_t, void *);
    134  1.1.2.2  bouyer 
    135  1.1.2.2  bouyer CFATTACH_DECL_NEW(dvbox_dio, sizeof(struct dvbox_softc),
    136  1.1.2.2  bouyer     dvbox_dio_match, dvbox_dio_attach, NULL, NULL);
    137  1.1.2.2  bouyer 
    138  1.1.2.2  bouyer CFATTACH_DECL_NEW(dvbox_intio, sizeof(struct dvbox_softc),
    139  1.1.2.2  bouyer     dvbox_intio_match, dvbox_intio_attach, NULL, NULL);
    140  1.1.2.2  bouyer 
    141  1.1.2.2  bouyer int	dvbox_reset(struct diofb *, int, struct diofbreg *);
    142  1.1.2.2  bouyer void	dvbox_restore(struct diofb *);
    143  1.1.2.2  bouyer void	dvbox_setcolor(struct diofb *, u_int,
    144  1.1.2.2  bouyer 	    u_int8_t, u_int8_t, u_int8_t);
    145  1.1.2.2  bouyer int	dvbox_windowmove(struct diofb *, u_int16_t, u_int16_t, u_int16_t,
    146  1.1.2.2  bouyer 	    u_int16_t, u_int16_t, u_int16_t, int16_t, int16_t);
    147  1.1.2.2  bouyer 
    148  1.1.2.2  bouyer int	dvbox_ioctl(void *, void *, u_long, void *, int, struct lwp *);
    149  1.1.2.2  bouyer 
    150  1.1.2.2  bouyer struct	wsdisplay_accessops	dvbox_accessops = {
    151  1.1.2.2  bouyer 	dvbox_ioctl,
    152  1.1.2.2  bouyer 	diofb_mmap,
    153  1.1.2.2  bouyer 	diofb_alloc_screen,
    154  1.1.2.2  bouyer 	diofb_free_screen,
    155  1.1.2.2  bouyer 	diofb_show_screen,
    156  1.1.2.2  bouyer 	NULL,   /* load_font */
    157  1.1.2.2  bouyer };
    158  1.1.2.2  bouyer 
    159  1.1.2.2  bouyer /*
    160  1.1.2.2  bouyer  * Attachment glue
    161  1.1.2.2  bouyer  */
    162  1.1.2.2  bouyer 
    163  1.1.2.2  bouyer int
    164  1.1.2.2  bouyer dvbox_intio_match(device_t parent, cfdata_t cf, void *aux)
    165  1.1.2.2  bouyer {
    166  1.1.2.2  bouyer 	struct intio_attach_args *ia = aux;
    167  1.1.2.2  bouyer 	struct diofbreg *fbr;
    168  1.1.2.2  bouyer 
    169  1.1.2.2  bouyer 	if (strcmp("fb", ia->ia_modname) != 0)
    170  1.1.2.2  bouyer 		return 0;
    171  1.1.2.2  bouyer 
    172  1.1.2.2  bouyer 	fbr = (struct diofbreg *)ia->ia_addr;
    173  1.1.2.2  bouyer 
    174  1.1.2.2  bouyer 	if (badaddr((void *)fbr))
    175  1.1.2.2  bouyer 		return (0);
    176  1.1.2.2  bouyer 
    177  1.1.2.2  bouyer 	if (fbr->id == GRFHWID && fbr->fbid == GID_DAVINCI) {
    178  1.1.2.2  bouyer 		return (1);
    179  1.1.2.2  bouyer 	}
    180  1.1.2.2  bouyer 
    181  1.1.2.2  bouyer 	return (0);
    182  1.1.2.2  bouyer }
    183  1.1.2.2  bouyer 
    184  1.1.2.2  bouyer void
    185  1.1.2.2  bouyer dvbox_intio_attach(device_t parent, device_t self, void *aux)
    186  1.1.2.2  bouyer {
    187  1.1.2.2  bouyer 	struct dvbox_softc *sc = device_private(self);
    188  1.1.2.2  bouyer 	struct intio_attach_args *ia = aux;
    189  1.1.2.2  bouyer 	struct diofbreg *fbr;
    190  1.1.2.2  bouyer 
    191  1.1.2.2  bouyer 	sc->sc_dev = self;
    192  1.1.2.2  bouyer 	fbr = (struct diofbreg *)ia->ia_addr;
    193  1.1.2.2  bouyer 	sc->sc_scode = CONSCODE_INTERNAL;
    194  1.1.2.2  bouyer 
    195  1.1.2.2  bouyer         if (sc->sc_scode == conscode) {
    196  1.1.2.2  bouyer                 sc->sc_fb = &diofb_cn;
    197  1.1.2.2  bouyer         } else {
    198  1.1.2.2  bouyer                 sc->sc_fb = &sc->sc_fb_store;
    199  1.1.2.2  bouyer                 dvbox_reset(sc->sc_fb, sc->sc_scode, fbr);
    200  1.1.2.2  bouyer         }
    201  1.1.2.2  bouyer 
    202  1.1.2.2  bouyer 	diofb_end_attach(self, &dvbox_accessops, sc->sc_fb,
    203  1.1.2.2  bouyer 	    sc->sc_scode == conscode, NULL);
    204  1.1.2.2  bouyer }
    205  1.1.2.2  bouyer 
    206  1.1.2.2  bouyer int
    207  1.1.2.2  bouyer dvbox_dio_match(device_t parent, cfdata_t cf, void *aux)
    208  1.1.2.2  bouyer {
    209  1.1.2.2  bouyer 	struct dio_attach_args *da = aux;
    210  1.1.2.2  bouyer 
    211  1.1.2.2  bouyer 	if (da->da_id == DIO_DEVICE_ID_FRAMEBUFFER &&
    212  1.1.2.2  bouyer 	    da->da_secid == DIO_DEVICE_SECID_DAVINCI)
    213  1.1.2.2  bouyer 		return (1);
    214  1.1.2.2  bouyer 
    215  1.1.2.2  bouyer 	return (0);
    216  1.1.2.2  bouyer }
    217  1.1.2.2  bouyer 
    218  1.1.2.2  bouyer void
    219  1.1.2.2  bouyer dvbox_dio_attach(device_t parent, device_t self, void *aux)
    220  1.1.2.2  bouyer {
    221  1.1.2.2  bouyer 	struct dvbox_softc *sc = device_private(self);
    222  1.1.2.2  bouyer 	struct dio_attach_args *da = aux;
    223  1.1.2.2  bouyer 	bus_space_handle_t bsh;
    224  1.1.2.2  bouyer 	struct diofbreg *fbr;
    225  1.1.2.2  bouyer 
    226  1.1.2.2  bouyer 	sc->sc_dev = self;
    227  1.1.2.2  bouyer 	sc->sc_scode = da->da_scode;
    228  1.1.2.2  bouyer 	if (sc->sc_scode == conscode) {
    229  1.1.2.2  bouyer 		fbr = (struct diofbreg *)conaddr;	/* already mapped */
    230  1.1.2.2  bouyer 		sc->sc_fb = &diofb_cn;
    231  1.1.2.2  bouyer 	} else {
    232  1.1.2.2  bouyer 		sc->sc_fb = &sc->sc_fb_store;
    233  1.1.2.2  bouyer 		if (bus_space_map(da->da_bst, da->da_addr, da->da_size, 0,
    234  1.1.2.2  bouyer 		    &bsh)) {
    235  1.1.2.2  bouyer 			aprint_error(": can't map framebuffer\n");
    236  1.1.2.2  bouyer 			return;
    237  1.1.2.2  bouyer 		}
    238  1.1.2.2  bouyer 		fbr = bus_space_vaddr(da->da_bst, bsh);
    239  1.1.2.2  bouyer 		if (dvbox_reset(sc->sc_fb, sc->sc_scode, fbr) != 0) {
    240  1.1.2.2  bouyer 			printf(": can't map framebuffer\n");
    241  1.1.2.2  bouyer 			return;
    242  1.1.2.2  bouyer 		}
    243  1.1.2.2  bouyer 	}
    244  1.1.2.2  bouyer 
    245  1.1.2.2  bouyer 	diofb_end_attach(self, &dvbox_accessops, sc->sc_fb,
    246  1.1.2.2  bouyer 	    sc->sc_scode == conscode, NULL);
    247  1.1.2.2  bouyer }
    248  1.1.2.2  bouyer 
    249  1.1.2.2  bouyer /*
    250  1.1.2.2  bouyer  * Initialize hardware and display routines.
    251  1.1.2.2  bouyer  */
    252  1.1.2.2  bouyer int
    253  1.1.2.2  bouyer dvbox_reset(struct diofb *fb, int scode, struct diofbreg *fbr)
    254  1.1.2.2  bouyer {
    255  1.1.2.2  bouyer 	int rc;
    256  1.1.2.2  bouyer 
    257  1.1.2.2  bouyer 	if ((rc = diofb_fbinquire(fb, scode, fbr)) != 0)
    258  1.1.2.2  bouyer 		return (rc);
    259  1.1.2.2  bouyer 
    260  1.1.2.2  bouyer 	/*
    261  1.1.2.2  bouyer 	 * Restrict the framebuffer to a monochrome view for now, until
    262  1.1.2.2  bouyer 	 * I know better how to detect and frob overlay planes, and
    263  1.1.2.2  bouyer 	 * setup a proper colormap. -- miod
    264  1.1.2.2  bouyer 	 */
    265  1.1.2.2  bouyer 	fb->planes = fb->planemask = 1;
    266  1.1.2.2  bouyer 
    267  1.1.2.2  bouyer 	fb->bmv = dvbox_windowmove;
    268  1.1.2.2  bouyer 	dvbox_restore(fb);
    269  1.1.2.2  bouyer 	diofb_fbsetup(fb);
    270  1.1.2.2  bouyer 
    271  1.1.2.2  bouyer 	return (0);
    272  1.1.2.2  bouyer }
    273  1.1.2.2  bouyer 
    274  1.1.2.2  bouyer /*
    275  1.1.2.2  bouyer  * Magic initialization code.
    276  1.1.2.2  bouyer  */
    277  1.1.2.2  bouyer void
    278  1.1.2.2  bouyer dvbox_restore(struct diofb *fb)
    279  1.1.2.2  bouyer {
    280  1.1.2.2  bouyer 	volatile struct dvboxfb *db = (struct dvboxfb *)fb->regkva;
    281  1.1.2.2  bouyer 	u_int i;
    282  1.1.2.2  bouyer 
    283  1.1.2.2  bouyer   	db->regs.id = 0x80;
    284  1.1.2.2  bouyer 	DELAY(100);
    285  1.1.2.2  bouyer 
    286  1.1.2.2  bouyer 	db->regs.interrupt = 0x04;
    287  1.1.2.2  bouyer 	db->en_scan = 0x01;
    288  1.1.2.2  bouyer 	db->fbwen = ~0;
    289  1.1.2.2  bouyer 	db->opwen = ~0;
    290  1.1.2.2  bouyer 	db->fold = 0x01;	/* 8bpp */
    291  1.1.2.2  bouyer 	db->drive = 0x01;	/* use FB plane */
    292  1.1.2.2  bouyer 	db->rep_rule = DVBOX_DUALROP(RR_COPY);
    293  1.1.2.2  bouyer 	db->alt_rr = DVBOX_DUALROP(RR_COPY);
    294  1.1.2.2  bouyer 	db->zrr = DVBOX_DUALROP(RR_COPY);
    295  1.1.2.2  bouyer 
    296  1.1.2.2  bouyer 	db->fbvenp = 0xFF;	/* enable video */
    297  1.1.2.2  bouyer 	db->dispen = 0x01;	/* enable display */
    298  1.1.2.2  bouyer 	db->fbvens = 0x0;
    299  1.1.2.2  bouyer 	db->fv_trig = 0x01;
    300  1.1.2.2  bouyer 	DELAY(100);
    301  1.1.2.2  bouyer 	db->vdrive = 0x0;
    302  1.1.2.2  bouyer 	db->zconfig = 0x0;
    303  1.1.2.2  bouyer 
    304  1.1.2.2  bouyer 	while (db->wbusy & 0x01)
    305  1.1.2.2  bouyer 		DELAY(10);
    306  1.1.2.2  bouyer 
    307  1.1.2.2  bouyer 	db->cmapbank = 0;
    308  1.1.2.2  bouyer 
    309  1.1.2.2  bouyer 	db->red0 = 0;
    310  1.1.2.2  bouyer 	db->red1 = 0;
    311  1.1.2.2  bouyer 	db->green0 = 0;
    312  1.1.2.2  bouyer 	db->green1 = 0;
    313  1.1.2.2  bouyer 	db->blue0 = 0;
    314  1.1.2.2  bouyer 	db->blue1 = 0;
    315  1.1.2.2  bouyer 
    316  1.1.2.2  bouyer 	db->panxh = 0;
    317  1.1.2.2  bouyer 	db->panxl = 0;
    318  1.1.2.2  bouyer 	db->panyh = 0;
    319  1.1.2.2  bouyer 	db->panyl = 0;
    320  1.1.2.2  bouyer 	db->zoom = 0;
    321  1.1.2.2  bouyer 	db->cdwidth = 0x50;
    322  1.1.2.2  bouyer 	db->chstart = 0x52;
    323  1.1.2.2  bouyer 	db->cvwidth = 0x22;
    324  1.1.2.2  bouyer 	db->pz_trig = 1;
    325  1.1.2.2  bouyer 
    326  1.1.2.2  bouyer 	/*
    327  1.1.2.2  bouyer 	 * Turn on frame buffer, turn on overlay planes, set replacement
    328  1.1.2.2  bouyer 	 * rule, enable top overlay plane writes for ite, disable all frame
    329  1.1.2.2  bouyer 	 * buffer planes, set byte per pixel, and display frame buffer 0.
    330  1.1.2.2  bouyer 	 * Lastly, turn on the box.
    331  1.1.2.2  bouyer 	 */
    332  1.1.2.2  bouyer 	db->regs.interrupt = 0x04;
    333  1.1.2.2  bouyer 	db->drive = 0x10;
    334  1.1.2.2  bouyer  	db->rep_rule = DVBOX_DUALROP(RR_COPY);
    335  1.1.2.2  bouyer 	db->opwen = 0x01;
    336  1.1.2.2  bouyer 	db->fbwen = 0x0;
    337  1.1.2.2  bouyer 	db->fold = 0x01;
    338  1.1.2.2  bouyer 	db->vdrive = 0x0;
    339  1.1.2.2  bouyer 	db->dispen = 0x01;
    340  1.1.2.2  bouyer 
    341  1.1.2.2  bouyer 	/*
    342  1.1.2.2  bouyer 	 * Video enable top overlay plane.
    343  1.1.2.2  bouyer 	 */
    344  1.1.2.2  bouyer 	db->opvenp = 0x01;
    345  1.1.2.2  bouyer 	db->opvens = 0x01;
    346  1.1.2.2  bouyer 
    347  1.1.2.2  bouyer 	/*
    348  1.1.2.2  bouyer 	 * Make sure that overlay planes override frame buffer planes.
    349  1.1.2.2  bouyer 	 */
    350  1.1.2.2  bouyer 	db->ovly0p = 0x0;
    351  1.1.2.2  bouyer 	db->ovly0s = 0x0;
    352  1.1.2.2  bouyer 	db->ovly1p = 0x0;
    353  1.1.2.2  bouyer 	db->ovly1s = 0x0;
    354  1.1.2.2  bouyer 	db->fv_trig = 0x1;
    355  1.1.2.2  bouyer 	DELAY(100);
    356  1.1.2.2  bouyer 
    357  1.1.2.2  bouyer 	/*
    358  1.1.2.2  bouyer 	 * Setup the overlay colormaps. Need to set the 0,1 (black/white)
    359  1.1.2.2  bouyer 	 * color for both banks.
    360  1.1.2.2  bouyer 	 */
    361  1.1.2.2  bouyer 	db_waitbusy(db);
    362  1.1.2.2  bouyer 	for (i = 0; i <= 1; i++) {
    363  1.1.2.2  bouyer 		db->cmapbank = i;
    364  1.1.2.2  bouyer 		db->rgb[0].red = 0x00;
    365  1.1.2.2  bouyer 		db->rgb[0].green = 0x00;
    366  1.1.2.2  bouyer 		db->rgb[0].blue = 0x00;
    367  1.1.2.2  bouyer 		db->rgb[1].red = 0xff;
    368  1.1.2.2  bouyer 		db->rgb[1].green = 0xff;
    369  1.1.2.2  bouyer 		db->rgb[1].blue = 0xff;
    370  1.1.2.2  bouyer 	}
    371  1.1.2.2  bouyer 	db->cmapbank = 0;
    372  1.1.2.2  bouyer 	db_waitbusy(db);
    373  1.1.2.2  bouyer }
    374  1.1.2.2  bouyer 
    375  1.1.2.2  bouyer int
    376  1.1.2.2  bouyer dvbox_ioctl(void *v, void *vs, u_long cmd, void *data, int flags, struct lwp *l)
    377  1.1.2.2  bouyer {
    378  1.1.2.2  bouyer 	struct diofb *fb = v;
    379  1.1.2.2  bouyer 	struct wsdisplay_fbinfo *wdf;
    380  1.1.2.2  bouyer 
    381  1.1.2.2  bouyer 	switch (cmd) {
    382  1.1.2.2  bouyer 	case WSDISPLAYIO_GTYPE:
    383  1.1.2.2  bouyer 		*(u_int *)data = WSDISPLAY_TYPE_DVBOX;
    384  1.1.2.2  bouyer 		return 0;
    385  1.1.2.2  bouyer 	case WSDISPLAYIO_SMODE:
    386  1.1.2.2  bouyer 		fb->mapmode = *(u_int *)data;
    387  1.1.2.2  bouyer 		if (fb->mapmode == WSDISPLAYIO_MODE_EMUL)
    388  1.1.2.2  bouyer 			dvbox_restore(fb);
    389  1.1.2.2  bouyer 		return 0;
    390  1.1.2.2  bouyer 	case WSDISPLAYIO_GINFO:
    391  1.1.2.2  bouyer 		wdf = (void *)data;
    392  1.1.2.2  bouyer 		wdf->width = fb->ri.ri_width;
    393  1.1.2.2  bouyer 		wdf->height = fb->ri.ri_height;
    394  1.1.2.2  bouyer 		wdf->depth = fb->ri.ri_depth;
    395  1.1.2.2  bouyer 		wdf->cmsize = 0;	/* XXX */
    396  1.1.2.2  bouyer 		return 0;
    397  1.1.2.2  bouyer 	case WSDISPLAYIO_LINEBYTES:
    398  1.1.2.2  bouyer 		*(u_int *)data = fb->ri.ri_stride;
    399  1.1.2.2  bouyer 		return 0;
    400  1.1.2.2  bouyer 	case WSDISPLAYIO_GETCMAP:
    401  1.1.2.2  bouyer 	case WSDISPLAYIO_PUTCMAP:
    402  1.1.2.2  bouyer 		/* XXX until color support is implemented */
    403  1.1.2.2  bouyer 		return EPASSTHROUGH;
    404  1.1.2.2  bouyer 	case WSDISPLAYIO_GVIDEO:
    405  1.1.2.2  bouyer 	case WSDISPLAYIO_SVIDEO:
    406  1.1.2.2  bouyer 		return EPASSTHROUGH;
    407  1.1.2.2  bouyer 	}
    408  1.1.2.2  bouyer 
    409  1.1.2.2  bouyer 	return EPASSTHROUGH;
    410  1.1.2.2  bouyer }
    411  1.1.2.2  bouyer 
    412  1.1.2.2  bouyer int
    413  1.1.2.2  bouyer dvbox_windowmove(struct diofb *fb, u_int16_t sx, u_int16_t sy,
    414  1.1.2.2  bouyer     u_int16_t dx, u_int16_t dy, u_int16_t cx, u_int16_t cy, int16_t rop,
    415  1.1.2.2  bouyer     int16_t planemask)
    416  1.1.2.2  bouyer {
    417  1.1.2.2  bouyer 	volatile struct dvboxfb *db = (struct dvboxfb *)fb->regkva;
    418  1.1.2.2  bouyer 
    419  1.1.2.2  bouyer 	if (planemask != 0xff)
    420  1.1.2.2  bouyer 		return (EINVAL);
    421  1.1.2.2  bouyer 
    422  1.1.2.2  bouyer 	db_waitbusy(db);
    423  1.1.2.2  bouyer 
    424  1.1.2.2  bouyer 	db->rep_rule = DVBOX_DUALROP(rop);
    425  1.1.2.2  bouyer 	db->source_y = sy;
    426  1.1.2.2  bouyer 	db->source_x = sx;
    427  1.1.2.2  bouyer 	db->dest_y = dy;
    428  1.1.2.2  bouyer 	db->dest_x = dx;
    429  1.1.2.2  bouyer 	db->wheight = cy;
    430  1.1.2.2  bouyer 	db->wwidth = cx;
    431  1.1.2.2  bouyer 	db->wmove = 1;
    432  1.1.2.2  bouyer 
    433  1.1.2.2  bouyer 	db_waitbusy(db);
    434  1.1.2.2  bouyer 
    435  1.1.2.2  bouyer 	return (0);
    436  1.1.2.2  bouyer }
    437  1.1.2.2  bouyer 
    438  1.1.2.2  bouyer /*
    439  1.1.2.2  bouyer  * DaVinci console support
    440  1.1.2.2  bouyer  */
    441  1.1.2.2  bouyer 
    442  1.1.2.2  bouyer int
    443  1.1.2.2  bouyer dvboxcnattach(bus_space_tag_t bst, bus_addr_t addr, int scode)
    444  1.1.2.2  bouyer {
    445  1.1.2.2  bouyer 	bus_space_handle_t bsh;
    446  1.1.2.2  bouyer 	void *va;
    447  1.1.2.2  bouyer 	struct diofbreg *fbr;
    448  1.1.2.2  bouyer 	struct diofb *fb = &diofb_cn;
    449  1.1.2.2  bouyer 	int size;
    450  1.1.2.2  bouyer 
    451  1.1.2.2  bouyer 	if (bus_space_map(bst, addr, PAGE_SIZE, 0, &bsh))
    452  1.1.2.2  bouyer 		return 1;
    453  1.1.2.2  bouyer 	va = bus_space_vaddr(bst, bsh);
    454  1.1.2.2  bouyer 	fbr = va;
    455  1.1.2.2  bouyer 
    456  1.1.2.2  bouyer 	if (badaddr(va) ||
    457  1.1.2.2  bouyer 	    (fbr->id != GRFHWID) || (fbr->fbid != GID_DAVINCI)) {
    458  1.1.2.2  bouyer 		bus_space_unmap(bst, bsh, PAGE_SIZE);
    459  1.1.2.2  bouyer 		return 1;
    460  1.1.2.2  bouyer 	}
    461  1.1.2.2  bouyer 
    462  1.1.2.2  bouyer 	size = DIO_SIZE(scode, va);
    463  1.1.2.2  bouyer 
    464  1.1.2.2  bouyer 	bus_space_unmap(bst, bsh, PAGE_SIZE);
    465  1.1.2.2  bouyer 	if (bus_space_map(bst, addr, size, 0, &bsh))
    466  1.1.2.2  bouyer 		return 1;
    467  1.1.2.2  bouyer 	va = bus_space_vaddr(bst, bsh);
    468  1.1.2.2  bouyer 
    469  1.1.2.2  bouyer 	/*
    470  1.1.2.2  bouyer 	 * Initialize the framebuffer hardware.
    471  1.1.2.2  bouyer 	 */
    472  1.1.2.2  bouyer 	conscode = scode;
    473  1.1.2.2  bouyer 	conaddr = va;
    474  1.1.2.2  bouyer 	dvbox_reset(fb, conscode, (struct diofbreg *)conaddr);
    475  1.1.2.2  bouyer 
    476  1.1.2.2  bouyer 	/*
    477  1.1.2.2  bouyer 	 * Initialize the terminal emulator.
    478  1.1.2.2  bouyer 	 */
    479  1.1.2.2  bouyer 	diofb_cnattach(fb);
    480  1.1.2.2  bouyer 	return 0;
    481  1.1.2.2  bouyer }
    482