Home | History | Annotate | Line # | Download | only in dev
fb_elb.c revision 1.2.2.4
      1  1.2.2.4    skrll /*	$NetBSD: fb_elb.c,v 1.2.2.4 2005/01/17 08:25:44 skrll Exp $	*/
      2      1.1  hannken 
      3      1.1  hannken /*-
      4      1.1  hannken  * Copyright (c) 2003 The NetBSD Foundation, Inc.
      5      1.1  hannken  * All rights reserved.
      6      1.1  hannken  *
      7      1.1  hannken  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1  hannken  * by Juergen Hannken-Illjes.
      9      1.1  hannken  *
     10      1.1  hannken  * Redistribution and use in source and binary forms, with or without
     11      1.1  hannken  * modification, are permitted provided that the following conditions
     12      1.1  hannken  * are met:
     13      1.1  hannken  * 1. Redistributions of source code must retain the above copyright
     14      1.1  hannken  *    notice, this list of conditions and the following disclaimer.
     15      1.1  hannken  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1  hannken  *    notice, this list of conditions and the following disclaimer in the
     17      1.1  hannken  *    documentation and/or other materials provided with the distribution.
     18      1.1  hannken  * 3. All advertising materials mentioning features or use of this software
     19      1.1  hannken  *    must display the following acknowledgement:
     20      1.1  hannken  *      This product includes software developed by the NetBSD
     21      1.1  hannken  *      Foundation, Inc. and its contributors.
     22      1.1  hannken  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1  hannken  *    contributors may be used to endorse or promote products derived
     24      1.1  hannken  *    from this software without specific prior written permission.
     25      1.1  hannken  *
     26      1.1  hannken  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1  hannken  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1  hannken  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1  hannken  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1  hannken  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1  hannken  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1  hannken  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1  hannken  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1  hannken  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1  hannken  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1  hannken  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1  hannken  */
     38      1.1  hannken 
     39  1.2.2.1    skrll #include <sys/cdefs.h>
     40  1.2.2.4    skrll __KERNEL_RCSID(0, "$NetBSD: fb_elb.c,v 1.2.2.4 2005/01/17 08:25:44 skrll Exp $");
     41  1.2.2.1    skrll 
     42      1.1  hannken #include <sys/param.h>
     43      1.1  hannken #include <sys/conf.h>
     44      1.1  hannken #include <sys/device.h>
     45      1.1  hannken #include <sys/ioctl.h>
     46      1.1  hannken #include <sys/malloc.h>
     47      1.1  hannken #include <sys/systm.h>
     48      1.1  hannken 
     49      1.1  hannken #include <dev/wscons/wsconsio.h>
     50      1.1  hannken #include <dev/wscons/wsdisplayvar.h>
     51      1.1  hannken #include <dev/rasops/rasops.h>
     52      1.1  hannken 
     53      1.1  hannken #include <machine/explora.h>
     54      1.1  hannken #include <machine/bus.h>
     55      1.1  hannken 
     56      1.1  hannken #include <evbppc/explora/dev/elbvar.h>
     57      1.1  hannken 
     58      1.1  hannken #define FB_NPORTS		65536
     59      1.1  hannken 
     60      1.1  hannken struct fb_dev {
     61      1.1  hannken 	void *fb_vram;
     62      1.1  hannken 	bus_space_tag_t fb_iot;
     63      1.1  hannken 	bus_space_handle_t fb_ioh;
     64      1.1  hannken 	struct rasops_info fb_ri;
     65      1.1  hannken };
     66      1.1  hannken 
     67      1.1  hannken struct fb_elb_softc {
     68      1.1  hannken 	struct device sc_dev;
     69      1.1  hannken 	struct fb_dev *sc_fb;
     70      1.1  hannken 	int sc_nscreens;
     71      1.1  hannken };
     72      1.1  hannken 
     73      1.1  hannken static int	fb_elb_probe(struct device *, struct cfdata *, void *);
     74      1.1  hannken static void	fb_elb_attach(struct device *, struct device *, void *);
     75      1.1  hannken void		fb_cnattach(bus_space_tag_t, bus_addr_t, void *);
     76      1.1  hannken static void	fb_init(struct fb_dev *, int);
     77  1.2.2.4    skrll static int	fb_ioctl(void *, u_long, caddr_t, int, struct lwp *);
     78      1.1  hannken static paddr_t	fb_mmap(void *, off_t, int);
     79      1.1  hannken static int	fb_alloc_screen(void *, const struct wsscreen_descr *, void **,
     80      1.1  hannken                     int *, int *, long *);
     81      1.1  hannken static void	fb_free_screen(void *, void *);
     82      1.1  hannken static int	fb_show_screen(void *, void *, int, void (*)(void *, int, int),
     83      1.1  hannken                     void *);
     84      1.1  hannken 
     85      1.2  hannken static void	fb_eraserows(void *, int, int, long);
     86      1.2  hannken static void	fb_erasecols(void *, int, int, int, long);
     87      1.2  hannken static void	fb_copyrows(void *, int, int, int);
     88      1.2  hannken static void	fb_copycols(void *, int, int, int, int);
     89      1.2  hannken 
     90      1.1  hannken static void	s3_init(struct fb_dev *, int *, int *);
     91      1.2  hannken static void	s3_copy(struct fb_dev *, int, int, int, int, int, int, int);
     92      1.2  hannken static void	s3_fill(struct fb_dev *, int, int, int, int, int, int);
     93      1.1  hannken 
     94      1.1  hannken static struct fb_dev console_dev;
     95      1.1  hannken 
     96      1.1  hannken static struct wsdisplay_accessops accessops = {
     97      1.1  hannken 	fb_ioctl,
     98      1.1  hannken 	fb_mmap,
     99      1.1  hannken 	fb_alloc_screen,
    100      1.1  hannken 	fb_free_screen,
    101      1.1  hannken 	fb_show_screen,
    102      1.1  hannken 	NULL
    103      1.1  hannken };
    104      1.1  hannken 
    105      1.1  hannken static struct wsscreen_descr stdscreen = {
    106      1.1  hannken 	"std",
    107      1.1  hannken 	0, 0,
    108      1.1  hannken 	0,
    109      1.1  hannken 	0, 0,
    110      1.1  hannken 	0
    111      1.1  hannken };
    112      1.1  hannken 
    113      1.1  hannken static const struct wsscreen_descr *scrlist[] = {
    114      1.1  hannken 	&stdscreen
    115      1.1  hannken };
    116      1.1  hannken 
    117      1.1  hannken static struct wsscreen_list screenlist = {
    118      1.1  hannken 	sizeof(scrlist)/sizeof(scrlist[0]), scrlist
    119      1.1  hannken };
    120      1.1  hannken 
    121      1.1  hannken CFATTACH_DECL(fb_elb, sizeof(struct fb_elb_softc),
    122      1.1  hannken     fb_elb_probe, fb_elb_attach, NULL, NULL);
    123      1.1  hannken 
    124      1.1  hannken static int
    125      1.1  hannken fb_elb_probe(struct device *parent, struct cfdata *cf, void *aux)
    126      1.1  hannken {
    127      1.1  hannken 	struct elb_attach_args *oaa = aux;
    128      1.1  hannken 
    129      1.1  hannken 	if (strcmp(oaa->elb_name, cf->cf_name) != 0)
    130      1.1  hannken 		return 0;
    131      1.1  hannken 
    132      1.1  hannken 	return (1);
    133      1.1  hannken }
    134      1.1  hannken 
    135      1.1  hannken static void
    136      1.1  hannken fb_elb_attach(struct device *parent, struct device *self, void *aux)
    137      1.1  hannken {
    138      1.1  hannken 	struct fb_elb_softc *sc = (void *)self;
    139      1.1  hannken 	struct elb_attach_args *eaa = aux;
    140      1.1  hannken 	struct wsemuldisplaydev_attach_args waa;
    141      1.1  hannken 	struct rasops_info *ri;
    142      1.1  hannken 	bus_space_handle_t ioh;
    143      1.1  hannken 	int is_console;
    144      1.1  hannken 
    145      1.1  hannken 	is_console = ((void *)eaa->elb_base == console_dev.fb_vram);
    146      1.1  hannken 
    147      1.1  hannken 	if (is_console) {
    148      1.1  hannken 		sc->sc_fb = &console_dev;
    149      1.1  hannken 	} else {
    150      1.1  hannken 		sc->sc_fb = malloc(sizeof(struct fb_dev), M_DEVBUF, M_WAITOK);
    151      1.1  hannken 		memset(sc->sc_fb, 0, sizeof(struct fb_dev));
    152      1.1  hannken 	}
    153      1.1  hannken 
    154      1.1  hannken 	sc->sc_fb->fb_iot = eaa->elb_bt;
    155      1.1  hannken 	bus_space_map(sc->sc_fb->fb_iot, eaa->elb_base, SIZE_FB,
    156      1.1  hannken 	    BUS_SPACE_MAP_LINEAR, &ioh);
    157      1.1  hannken 	sc->sc_fb->fb_vram = bus_space_vaddr(sc->sc_fb->fb_iot, ioh);
    158      1.1  hannken 	bus_space_map(sc->sc_fb->fb_iot, eaa->elb_base2, FB_NPORTS,
    159      1.1  hannken 	    0, &sc->sc_fb->fb_ioh);
    160      1.1  hannken 
    161      1.1  hannken 	fb_init(sc->sc_fb, !is_console);
    162      1.1  hannken 
    163      1.1  hannken 	ri = &sc->sc_fb->fb_ri;
    164      1.1  hannken 
    165      1.1  hannken 	printf(": %d x %d\n", ri->ri_rows, ri->ri_cols);
    166      1.1  hannken 
    167      1.1  hannken 	waa.console = is_console;
    168      1.1  hannken 	waa.scrdata = &screenlist;
    169      1.1  hannken 	waa.accessops = &accessops;
    170      1.1  hannken 	waa.accesscookie = sc;
    171      1.1  hannken 
    172  1.2.2.2    skrll 	config_found(self, &waa, wsemuldisplaydevprint);
    173      1.1  hannken }
    174      1.1  hannken 
    175      1.1  hannken static void
    176      1.1  hannken fb_init(struct fb_dev *fb, int full)
    177      1.1  hannken {
    178      1.1  hannken 	struct rasops_info *ri = &fb->fb_ri;
    179      1.1  hannken 
    180      1.1  hannken 	if (full) {
    181      1.1  hannken 		s3_init(fb, &ri->ri_width, &ri->ri_height);
    182      1.1  hannken 		ri->ri_depth = 8;
    183      1.1  hannken 		ri->ri_stride = ri->ri_width;
    184      1.1  hannken 		ri->ri_bits = fb->fb_vram;
    185      1.1  hannken 		ri->ri_flg = RI_CENTER;
    186      1.1  hannken 
    187      1.1  hannken 		rasops_init(ri, 500, 500);
    188      1.1  hannken 	} else {
    189      1.1  hannken 		ri->ri_origbits = fb->fb_vram;	/*XXX*/
    190      1.1  hannken 		rasops_reconfig(ri, 500, 500);
    191      1.1  hannken 	}
    192      1.1  hannken 
    193      1.2  hannken 	/* Replace the copy/erase ops. */
    194      1.2  hannken 	ri->ri_hw = fb;
    195      1.2  hannken 	ri->ri_ops.eraserows = fb_eraserows;
    196      1.2  hannken 	ri->ri_ops.erasecols = fb_erasecols;
    197      1.2  hannken 	ri->ri_ops.copyrows = fb_copyrows;
    198      1.2  hannken 	ri->ri_ops.copycols = fb_copycols;
    199      1.2  hannken 
    200      1.1  hannken 	stdscreen.nrows = ri->ri_rows;
    201      1.1  hannken 	stdscreen.ncols = ri->ri_cols;
    202      1.1  hannken 	stdscreen.textops = &ri->ri_ops;
    203      1.1  hannken 	stdscreen.capabilities = ri->ri_caps;
    204      1.1  hannken }
    205      1.1  hannken 
    206      1.1  hannken static int
    207  1.2.2.4    skrll fb_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct lwp *l)
    208      1.1  hannken {
    209      1.1  hannken 	struct fb_elb_softc *sc = v;
    210      1.1  hannken 	struct rasops_info *ri = &sc->sc_fb->fb_ri;
    211      1.1  hannken 	struct wsdisplay_fbinfo *wdf;
    212      1.1  hannken 
    213      1.1  hannken 	switch (cmd) {
    214      1.1  hannken 	case WSDISPLAYIO_GTYPE:
    215      1.1  hannken 		*(int *)data = WSDISPLAY_TYPE_UNKNOWN;	/* XXX */
    216      1.1  hannken 		return(0);
    217      1.1  hannken 
    218      1.1  hannken 	case WSDISPLAYIO_GINFO:
    219      1.1  hannken 		wdf = (void *)data;
    220      1.1  hannken 		wdf->height = ri->ri_height;
    221      1.1  hannken 		wdf->width = ri->ri_width;
    222      1.1  hannken 		wdf->depth = ri->ri_depth;
    223      1.1  hannken 		wdf->cmsize = 16; /*XXX*/
    224      1.1  hannken 		return(0);
    225      1.1  hannken 
    226      1.1  hannken 	case WSDISPLAYIO_SVIDEO:
    227      1.1  hannken 	case WSDISPLAYIO_GETCMAP:
    228      1.1  hannken 	case WSDISPLAYIO_PUTCMAP:
    229      1.1  hannken 		break;
    230      1.1  hannken 	}
    231      1.1  hannken 
    232      1.1  hannken 	return(EPASSTHROUGH);
    233      1.1  hannken }
    234      1.1  hannken 
    235      1.1  hannken static paddr_t
    236      1.1  hannken fb_mmap(void *v, off_t offset, int prot)
    237      1.1  hannken {
    238  1.2.2.1    skrll 	struct fb_elb_softc *sc = v;
    239  1.2.2.1    skrll 
    240  1.2.2.1    skrll 	if (offset < 0 || offset >= SIZE_FB)
    241  1.2.2.1    skrll 		return -1;
    242  1.2.2.1    skrll 
    243  1.2.2.1    skrll 	return bus_space_mmap(sc->sc_fb->fb_iot, BASE_FB, offset, prot,
    244  1.2.2.1    skrll 	    BUS_SPACE_MAP_LINEAR);
    245      1.1  hannken }
    246      1.1  hannken 
    247      1.1  hannken static int
    248      1.1  hannken fb_alloc_screen(void *v, const struct wsscreen_descr *scrdesc, void **cookiep,
    249      1.1  hannken     int *ccolp, int *crowp, long *attrp)
    250      1.1  hannken {
    251      1.1  hannken 	struct fb_elb_softc *sc = v;
    252      1.1  hannken 	struct rasops_info *ri = &sc->sc_fb->fb_ri;
    253      1.1  hannken 
    254      1.1  hannken 	if (sc->sc_nscreens > 0)
    255      1.1  hannken 		return ENOMEM;
    256      1.1  hannken 
    257      1.1  hannken 	*cookiep = ri;
    258      1.1  hannken 	*ccolp = *crowp = 0;
    259      1.1  hannken 	(*ri->ri_ops.allocattr)(ri, 0, 0, 0, attrp);
    260      1.1  hannken 	sc->sc_nscreens++;
    261      1.1  hannken 
    262      1.1  hannken 	return(0);
    263      1.1  hannken }
    264      1.1  hannken 
    265      1.1  hannken static void
    266      1.1  hannken fb_free_screen(void *v, void *cookie)
    267      1.1  hannken {
    268      1.1  hannken 	struct fb_elb_softc *sc = v;
    269      1.1  hannken 
    270      1.1  hannken 	if (sc->sc_fb == &console_dev)
    271      1.1  hannken 		panic("fb_free_screen: freeing console");
    272      1.1  hannken 
    273      1.1  hannken 	sc->sc_nscreens--;
    274      1.1  hannken }
    275      1.1  hannken 
    276      1.1  hannken static int
    277      1.1  hannken fb_show_screen(void *v, void *cookie, int waitok, void (*cb)(void *, int, int),
    278      1.1  hannken     void *cbarg)
    279      1.1  hannken {
    280      1.1  hannken 	return(0);
    281      1.1  hannken }
    282      1.1  hannken 
    283      1.1  hannken void
    284      1.1  hannken fb_cnattach(bus_space_tag_t iot, bus_addr_t iobase, void *vram)
    285      1.1  hannken {
    286      1.1  hannken 	struct rasops_info *ri = &console_dev.fb_ri;
    287      1.1  hannken 	long defattr;
    288      1.1  hannken 
    289      1.1  hannken 	console_dev.fb_iot = iot;
    290      1.1  hannken 	console_dev.fb_ioh = iobase;
    291      1.1  hannken 	console_dev.fb_vram = vram;
    292      1.1  hannken 
    293      1.1  hannken 	fb_init(&console_dev, 1);
    294      1.1  hannken 
    295      1.1  hannken 	(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
    296      1.1  hannken 
    297      1.1  hannken 	wsdisplay_cnattach(&stdscreen, ri, 0, 0, defattr);
    298      1.1  hannken }
    299      1.1  hannken 
    300      1.2  hannken static void
    301      1.2  hannken fb_eraserows(void *v, int row, int nrows, long attr)
    302      1.2  hannken {
    303      1.2  hannken 	struct rasops_info *ri = v;
    304      1.2  hannken 	struct fb_dev *fb = ri->ri_hw;
    305      1.2  hannken 
    306      1.2  hannken 	row *= ri->ri_font->fontheight;
    307      1.2  hannken 	nrows *= ri->ri_font->fontheight;
    308      1.2  hannken 
    309      1.2  hannken 	s3_fill(fb, 0, row, ri->ri_stride, nrows, (attr >> 16)&0x0f, 0x0f);
    310      1.2  hannken }
    311      1.2  hannken 
    312      1.2  hannken static void
    313      1.2  hannken fb_erasecols(void *v, int row, int startcol, int ncols, long attr)
    314      1.2  hannken {
    315      1.2  hannken 	struct rasops_info *ri = v;
    316      1.2  hannken 	struct fb_dev *fb = ri->ri_hw;
    317      1.2  hannken 
    318      1.2  hannken 	row *= ri->ri_font->fontheight;
    319      1.2  hannken 	startcol *= ri->ri_font->fontwidth;
    320      1.2  hannken 	ncols *= ri->ri_font->fontwidth;
    321      1.2  hannken 
    322      1.2  hannken 	s3_fill(fb, startcol, row, ncols, ri->ri_font->fontheight,
    323      1.2  hannken 	    (attr >> 16)&0x0f, 0x0f);
    324      1.2  hannken }
    325      1.2  hannken 
    326      1.2  hannken static void
    327      1.2  hannken fb_copyrows(void *v, int srcrow, int dstrow, int nrows)
    328      1.2  hannken {
    329      1.2  hannken 	struct rasops_info *ri = v;
    330      1.2  hannken 	struct fb_dev *fb = ri->ri_hw;
    331      1.2  hannken 
    332      1.2  hannken 	srcrow *= ri->ri_font->fontheight;
    333      1.2  hannken 	dstrow *= ri->ri_font->fontheight;
    334      1.2  hannken 	nrows *= ri->ri_font->fontheight;
    335      1.2  hannken 
    336      1.2  hannken 	s3_copy(fb, 0, srcrow, 0, dstrow, ri->ri_stride, nrows, 0x0f);
    337      1.2  hannken }
    338      1.2  hannken 
    339      1.2  hannken static void
    340      1.2  hannken fb_copycols(void *v, int row, int srccol, int dstcol, int ncols)
    341      1.2  hannken {
    342      1.2  hannken 	struct rasops_info *ri = v;
    343      1.2  hannken 	struct fb_dev *fb = ri->ri_hw;
    344      1.2  hannken 
    345      1.2  hannken 	row *= ri->ri_font->fontheight;
    346      1.2  hannken 	srccol *= ri->ri_font->fontwidth;
    347      1.2  hannken 	dstcol *= ri->ri_font->fontwidth;
    348      1.2  hannken 	ncols *= ri->ri_font->fontwidth;
    349      1.2  hannken 
    350      1.2  hannken 	s3_copy(fb, srccol, row, dstcol, row,
    351      1.2  hannken 	    ncols, ri->ri_font->fontheight, 0x0f);
    352      1.2  hannken }
    353      1.2  hannken 
    354      1.1  hannken /*
    355      1.1  hannken  * S3 support routines
    356      1.1  hannken  */
    357      1.1  hannken 
    358      1.1  hannken #define S3_CRTC_INDEX		0x83d4
    359      1.1  hannken #define S3_CRTC_DATA		0x83d5
    360      1.1  hannken 
    361      1.1  hannken #define S3_DAC_RD_INDEX		0x83c7
    362      1.1  hannken #define S3_DAC_WR_INDEX		0x83c8
    363      1.1  hannken #define S3_DAC_DATA		0x83c9
    364      1.1  hannken 
    365      1.2  hannken #define S3_CUR_Y		0x82e8
    366      1.2  hannken #define S3_CUR_X		0x86e8
    367      1.2  hannken #define S3_DESTY_AXSTP		0x8ae8
    368      1.2  hannken #define S3_DESTX_DIASTP		0x8ee8
    369      1.2  hannken #define S3_MAJ_AXIS_PCNT	0x96e8
    370      1.2  hannken #define S3_GP_STAT		0x9ae8
    371      1.2  hannken #define S3_CMD			0x9ae8
    372      1.2  hannken #define S3_BKGD_COLOR		0xa2e8
    373      1.2  hannken #define S3_FRGD_COLOR		0xa6e8
    374      1.2  hannken #define S3_WRT_MASK		0xaae8
    375      1.2  hannken #define S3_RD_MASK		0xaee8
    376      1.2  hannken #define S3_BKGD_MIX		0xb6e8
    377      1.2  hannken #define S3_FRGD_MIX		0xbae8
    378      1.2  hannken #define S3_MULTIFUNC_CNTL	0xbee8
    379      1.2  hannken 
    380      1.2  hannken #define S3_GP_STAT_FIFO_1	0x0080
    381      1.2  hannken #define S3_GP_STAT_BSY		0x0200
    382      1.2  hannken 
    383      1.2  hannken #define S3_CMD_BITBLT		0xc001
    384      1.2  hannken #define S3_CMD_RECT		0x4001
    385      1.2  hannken #define S3_INC_Y		0x0080
    386      1.2  hannken #define S3_INC_X		0x0020
    387      1.2  hannken #define S3_DRAW			0x0010
    388      1.2  hannken #define S3_MULTI		0x0002
    389      1.2  hannken 
    390      1.2  hannken #define S3_CSRC_BKGDCOL		0x0000
    391      1.2  hannken #define S3_CSRC_FRGDCOL		0x0020
    392      1.2  hannken #define S3_CSRC_DISPMEM		0x0060
    393      1.2  hannken #define S3_MIX_NEW		0x0007
    394      1.2  hannken 
    395      1.1  hannken #define CMAP_SIZE		256
    396      1.1  hannken 
    397      1.1  hannken static u_int8_t default_cmap[] = {
    398      1.1  hannken 	/* black */		  0,   0,   0,
    399      1.1  hannken 	/* blue */		  0,   0, 192,
    400      1.1  hannken 	/* green */		  0, 192,   0,
    401      1.1  hannken 	/* cyan */		  0, 192, 192,
    402      1.1  hannken 	/* red */		192,   0,   0,
    403      1.1  hannken 	/* magenta */		192,   0, 192,
    404      1.1  hannken 	/* brown */		192, 192,   0,
    405      1.1  hannken 	/* lightgrey */		212, 208, 200,
    406      1.1  hannken 	/* darkgrey */		200, 192, 188,
    407      1.1  hannken 	/* lightblue */		  0,   0, 255,
    408      1.1  hannken 	/* lightgreen */	  0, 255,   0,
    409      1.1  hannken 	/* lightcyan */		  0, 255, 255,
    410      1.1  hannken 	/* lightred */		255,   0,   0,
    411      1.1  hannken 	/* lightmagenta */	255,   0, 255,
    412      1.1  hannken 	/* yellow */		255, 255,   0,
    413      1.1  hannken 	/* white */		255, 255, 255,
    414      1.1  hannken };
    415      1.1  hannken 
    416      1.1  hannken static void
    417      1.1  hannken s3_init(struct fb_dev *fb, int *width, int *height)
    418      1.1  hannken {
    419      1.1  hannken 	int i, j, w, h;
    420      1.1  hannken 	bus_space_tag_t iot = fb->fb_iot;
    421      1.1  hannken 	bus_space_handle_t ioh = fb->fb_ioh;
    422      1.1  hannken 
    423      1.1  hannken 	/* Initialize colormap */
    424      1.1  hannken 
    425      1.1  hannken 	bus_space_write_1(iot, ioh, S3_DAC_WR_INDEX, 0);
    426      1.1  hannken 
    427      1.1  hannken 	for (i = j = 0; i < CMAP_SIZE*3; i++) {
    428      1.1  hannken 		bus_space_write_1(iot, ioh, S3_DAC_DATA, default_cmap[j] >> 2);
    429      1.1  hannken 		j = (j+1) % sizeof(default_cmap)/sizeof(default_cmap[0]);
    430      1.1  hannken 	}
    431      1.1  hannken 
    432      1.1  hannken 	/* Retrieve frame buffer geometry */
    433      1.1  hannken 
    434      1.1  hannken 	bus_space_write_1(iot, ioh, S3_CRTC_INDEX, 1);
    435      1.1  hannken 	w = bus_space_read_1(iot, ioh, S3_CRTC_DATA);
    436      1.1  hannken 
    437      1.1  hannken 	bus_space_write_1(iot, ioh, S3_CRTC_INDEX, 18);
    438      1.1  hannken 	h = bus_space_read_1(iot, ioh, S3_CRTC_DATA);
    439      1.1  hannken 
    440      1.1  hannken 	bus_space_write_1(iot, ioh, S3_CRTC_INDEX, 7);
    441      1.1  hannken 	i = bus_space_read_1(iot, ioh, S3_CRTC_DATA);
    442      1.1  hannken 
    443      1.1  hannken 	h += (i << 7) & 0x100;
    444      1.1  hannken 	h += (i << 3) & 0x200;
    445      1.1  hannken 
    446      1.1  hannken 	*width = (w+1) << 3;
    447      1.1  hannken 	*height = h+1;
    448      1.2  hannken }
    449      1.2  hannken 
    450      1.2  hannken static void
    451      1.2  hannken s3_copy(struct fb_dev *fb, int src_x, int src_y, int dest_x, int dest_y,
    452      1.2  hannken     int width, int height, int mask)
    453      1.2  hannken {
    454      1.2  hannken 	bus_space_tag_t iot = fb->fb_iot;
    455      1.2  hannken 	bus_space_handle_t ioh = fb->fb_ioh;
    456      1.2  hannken 	u_int16_t cmd = S3_CMD_BITBLT | S3_DRAW;
    457      1.2  hannken 
    458      1.2  hannken 	if (src_x > dest_x)
    459      1.2  hannken 		cmd |= S3_INC_X;
    460      1.2  hannken 	else {
    461      1.2  hannken 		src_x += width-1;
    462      1.2  hannken 		dest_x += width-1;
    463      1.2  hannken 	}
    464      1.2  hannken 
    465      1.2  hannken 	if (src_y > dest_y)
    466      1.2  hannken 		cmd |= S3_INC_Y;
    467      1.2  hannken 	else {
    468      1.2  hannken 		src_y += height-1;
    469      1.2  hannken 		dest_y += height-1;
    470      1.2  hannken 	}
    471      1.2  hannken 
    472      1.2  hannken 	while (bus_space_read_2(iot, ioh, S3_GP_STAT) & S3_GP_STAT_FIFO_1)
    473      1.2  hannken 		;
    474      1.2  hannken 
    475      1.2  hannken 	bus_space_write_2(iot, ioh, S3_FRGD_MIX, S3_CSRC_DISPMEM | S3_MIX_NEW);
    476      1.2  hannken 	bus_space_write_2(iot, ioh, S3_WRT_MASK, mask);
    477      1.2  hannken 	bus_space_write_2(iot, ioh, S3_CUR_X, src_x);
    478      1.2  hannken 	bus_space_write_2(iot, ioh, S3_CUR_Y, src_y);
    479      1.2  hannken 	bus_space_write_2(iot, ioh, S3_DESTX_DIASTP, dest_x);
    480      1.2  hannken 	bus_space_write_2(iot, ioh, S3_DESTY_AXSTP, dest_y);
    481      1.2  hannken 	bus_space_write_2(iot, ioh, S3_MULTIFUNC_CNTL, height-1);
    482      1.2  hannken 	bus_space_write_2(iot, ioh, S3_MAJ_AXIS_PCNT, width-1);
    483      1.2  hannken 	bus_space_write_2(iot, ioh, S3_CMD, cmd);
    484      1.2  hannken 
    485      1.2  hannken 	while (bus_space_read_2(iot, ioh, S3_GP_STAT) & S3_GP_STAT_BSY)
    486      1.2  hannken 		;
    487      1.2  hannken }
    488      1.2  hannken 
    489      1.2  hannken static void
    490      1.2  hannken s3_fill(struct fb_dev *fb, int x, int y, int width, int height,
    491      1.2  hannken     int color, int mask)
    492      1.2  hannken {
    493      1.2  hannken 	bus_space_tag_t iot = fb->fb_iot;
    494      1.2  hannken 	bus_space_handle_t ioh = fb->fb_ioh;
    495      1.2  hannken 	u_int16_t cmd = S3_CMD_RECT | S3_INC_X | S3_INC_Y | S3_DRAW;
    496      1.2  hannken 
    497      1.2  hannken 	while (bus_space_read_2(iot, ioh, S3_GP_STAT) & S3_GP_STAT_FIFO_1)
    498      1.2  hannken 		;
    499      1.2  hannken 
    500      1.2  hannken 	bus_space_write_2(iot, ioh, S3_FRGD_MIX, S3_CSRC_FRGDCOL | S3_MIX_NEW);
    501      1.2  hannken 	bus_space_write_2(iot, ioh, S3_FRGD_COLOR, color);
    502      1.2  hannken 	bus_space_write_2(iot, ioh, S3_WRT_MASK, mask);
    503      1.2  hannken 	bus_space_write_2(iot, ioh, S3_CUR_X, x);
    504      1.2  hannken 	bus_space_write_2(iot, ioh, S3_CUR_Y, y);
    505      1.2  hannken 	bus_space_write_2(iot, ioh, S3_MULTIFUNC_CNTL, height-1);
    506      1.2  hannken 	bus_space_write_2(iot, ioh, S3_MAJ_AXIS_PCNT, width-1);
    507      1.2  hannken 	bus_space_write_2(iot, ioh, S3_CMD, cmd);
    508      1.2  hannken 
    509      1.2  hannken 	while (bus_space_read_2(iot, ioh, S3_GP_STAT) & S3_GP_STAT_BSY)
    510      1.2  hannken 		;
    511      1.1  hannken }
    512