Home | History | Annotate | Line # | Download | only in ic
bt485.c revision 1.3.4.3
      1  1.3.4.3  nathanw /* $NetBSD: bt485.c,v 1.3.4.3 2001/11/14 19:14:18 nathanw Exp $ */
      2      1.1    elric 
      3      1.1    elric /*
      4      1.1    elric  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
      5      1.1    elric  * All rights reserved.
      6      1.1    elric  *
      7      1.1    elric  * Author: Chris G. Demetriou
      8      1.1    elric  *
      9      1.1    elric  * Permission to use, copy, modify and distribute this software and
     10      1.1    elric  * its documentation is hereby granted, provided that both the copyright
     11      1.1    elric  * notice and this permission notice appear in all copies of the
     12      1.1    elric  * software, derivative works or modified versions, and any portions
     13      1.1    elric  * thereof, and that both notices appear in supporting documentation.
     14      1.1    elric  *
     15      1.1    elric  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     16      1.1    elric  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     17      1.1    elric  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     18      1.1    elric  *
     19      1.1    elric  * Carnegie Mellon requests users of this software to return to
     20      1.1    elric  *
     21      1.1    elric  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     22      1.1    elric  *  School of Computer Science
     23      1.1    elric  *  Carnegie Mellon University
     24      1.1    elric  *  Pittsburgh PA 15213-3890
     25      1.1    elric  *
     26      1.1    elric  * any improvements or extensions that they make and grant Carnegie the
     27      1.1    elric  * rights to redistribute these changes.
     28      1.1    elric  */
     29      1.1    elric 
     30      1.1    elric  /* This code was derived from and originally located in sys/dev/pci/
     31      1.1    elric   *	 NetBSD: tga_bt485.c,v 1.4 1999/03/24 05:51:21 mrg Exp
     32      1.1    elric   */
     33  1.3.4.3  nathanw 
     34  1.3.4.3  nathanw #include <sys/cdefs.h>
     35  1.3.4.3  nathanw __KERNEL_RCSID(0, "$NetBSD: bt485.c,v 1.3.4.3 2001/11/14 19:14:18 nathanw Exp $");
     36      1.1    elric 
     37      1.1    elric #include <sys/param.h>
     38      1.1    elric #include <sys/systm.h>
     39      1.1    elric #include <sys/device.h>
     40      1.1    elric #include <sys/buf.h>
     41      1.1    elric #include <sys/kernel.h>
     42      1.1    elric #include <sys/malloc.h>
     43      1.3      mrg 
     44      1.3      mrg #include <uvm/uvm_extern.h>
     45      1.1    elric 
     46      1.1    elric #include <dev/pci/pcivar.h>
     47      1.1    elric #include <dev/ic/bt485reg.h>
     48      1.1    elric #include <dev/ic/bt485var.h>
     49      1.1    elric #include <dev/ic/ramdac.h>
     50      1.1    elric 
     51      1.1    elric #include <dev/wscons/wsconsio.h>
     52      1.1    elric 
     53      1.1    elric /*
     54      1.1    elric  * Functions exported via the RAMDAC configuration table.
     55      1.1    elric  */
     56      1.1    elric void	bt485_init __P((struct ramdac_cookie *));
     57      1.1    elric int	bt485_set_cmap __P((struct ramdac_cookie *,
     58      1.1    elric 	    struct wsdisplay_cmap *));
     59      1.1    elric int	bt485_get_cmap __P((struct ramdac_cookie *,
     60      1.1    elric 	    struct wsdisplay_cmap *));
     61      1.1    elric int	bt485_set_cursor __P((struct ramdac_cookie *,
     62      1.1    elric 	    struct wsdisplay_cursor *));
     63      1.1    elric int	bt485_get_cursor __P((struct ramdac_cookie *,
     64      1.1    elric 	    struct wsdisplay_cursor *));
     65      1.1    elric int	bt485_set_curpos __P((struct ramdac_cookie *,
     66      1.1    elric 	    struct wsdisplay_curpos *));
     67      1.1    elric int	bt485_get_curpos __P((struct ramdac_cookie *,
     68      1.1    elric 	    struct wsdisplay_curpos *));
     69      1.1    elric int	bt485_get_curmax __P((struct ramdac_cookie *,
     70      1.1    elric 	    struct wsdisplay_curpos *));
     71      1.1    elric 
     72      1.1    elric /* XXX const */
     73      1.1    elric struct ramdac_funcs bt485_funcsstruct = {
     74      1.1    elric 	"Bt485",
     75      1.2  nathanw 	bt485_register,
     76      1.1    elric 	bt485_init,
     77      1.1    elric 	bt485_set_cmap,
     78      1.1    elric 	bt485_get_cmap,
     79      1.1    elric 	bt485_set_cursor,
     80      1.1    elric 	bt485_get_cursor,
     81      1.1    elric 	bt485_set_curpos,
     82      1.1    elric 	bt485_get_curpos,
     83      1.1    elric 	bt485_get_curmax,
     84      1.1    elric 	NULL,			/* check_curcmap; not needed */
     85      1.1    elric 	NULL,			/* set_curcmap; not needed */
     86      1.1    elric 	NULL,			/* get_curcmap; not needed */
     87      1.1    elric };
     88      1.1    elric 
     89      1.1    elric /*
     90      1.1    elric  * Private data.
     91      1.1    elric  */
     92      1.1    elric struct bt485data {
     93      1.1    elric 	void            *cookie;        /* This is what is passed
     94      1.1    elric 					 * around, and is probably
     95      1.1    elric 					 * struct tga_devconfig *
     96      1.1    elric 					 */
     97      1.1    elric 
     98      1.1    elric 	int             (*ramdac_sched_update) __P((void *, void (*)(void *)));
     99      1.1    elric 	void            (*ramdac_wr) __P((void *, u_int, u_int8_t));
    100      1.1    elric 	u_int8_t        (*ramdac_rd) __P((void *, u_int));
    101      1.1    elric 
    102      1.1    elric 	int	changed;			/* what changed; see below */
    103      1.1    elric 	int	curenb;				/* cursor enabled */
    104      1.1    elric 	struct wsdisplay_curpos curpos;		/* current cursor position */
    105      1.1    elric 	struct wsdisplay_curpos curhot;		/* cursor hotspot */
    106      1.1    elric 	char curcmap_r[2];			/* cursor colormap */
    107      1.1    elric 	char curcmap_g[2];
    108      1.1    elric 	char curcmap_b[2];
    109      1.1    elric 	struct wsdisplay_curpos cursize;	/* current cursor size */
    110      1.1    elric 	char curimage[512];			/* cursor image data */
    111      1.1    elric 	char curmask[512];			/* cursor mask data */
    112      1.1    elric 	char cmap_r[256];				/* colormap */
    113      1.1    elric 	char cmap_g[256];
    114      1.1    elric 	char cmap_b[256];
    115      1.1    elric };
    116      1.1    elric 
    117      1.1    elric #define	DATA_ENB_CHANGED	0x01	/* cursor enable changed */
    118      1.1    elric #define	DATA_CURCMAP_CHANGED	0x02	/* cursor colormap changed */
    119      1.1    elric #define	DATA_CURSHAPE_CHANGED	0x04	/* cursor size, image, mask changed */
    120      1.1    elric #define	DATA_CMAP_CHANGED	0x08	/* colormap changed */
    121      1.1    elric #define	DATA_ALL_CHANGED	0x0f
    122      1.1    elric 
    123      1.1    elric #define	CURSOR_MAX_SIZE		64
    124      1.1    elric 
    125      1.1    elric /*
    126      1.1    elric  * Internal functions.
    127      1.1    elric  */
    128      1.1    elric inline void	bt485_wr_i  __P((struct bt485data *, u_int8_t, u_int8_t));
    129      1.1    elric inline u_int8_t bt485_rd_i __P((struct bt485data *, u_int8_t));
    130      1.1    elric void	bt485_update __P((void *));
    131      1.1    elric void	bt485_update_curpos __P((struct bt485data *));
    132      1.1    elric 
    133      1.1    elric /*****************************************************************************/
    134      1.1    elric 
    135      1.1    elric /*
    136      1.1    elric  * Functions exported via the RAMDAC configuration table.
    137      1.1    elric  */
    138      1.1    elric 
    139      1.1    elric struct ramdac_funcs *
    140      1.1    elric bt485_funcs(void)
    141      1.1    elric {
    142      1.1    elric 	return &bt485_funcsstruct;
    143      1.1    elric }
    144      1.1    elric 
    145      1.1    elric struct ramdac_cookie *
    146      1.1    elric bt485_register(v, sched_update, wr, rd)
    147      1.1    elric 	void *v;
    148      1.1    elric 	int (*sched_update)(void *, void (*)(void *));
    149      1.1    elric 	void (*wr)(void *, u_int, u_int8_t);
    150      1.1    elric 	u_int8_t (*rd)(void *, u_int);
    151      1.1    elric {
    152      1.1    elric 	struct bt485data *data;
    153      1.1    elric 	/*
    154      1.1    elric 	 * XXX -- comment out of date.  rcd.
    155      1.1    elric 	 * If we should allocate a new private info struct, do so.
    156      1.1    elric 	 * Otherwise, use the one we have (if it's there), or
    157      1.1    elric 	 * use the temporary one on the stack.
    158      1.1    elric 	 */
    159      1.1    elric 	data = malloc(sizeof *data, M_DEVBUF, M_WAITOK);
    160      1.1    elric 	/* XXX -- if !data */
    161      1.1    elric 	data->cookie = v;
    162      1.1    elric 	data->ramdac_sched_update = sched_update;
    163      1.1    elric 	data->ramdac_wr = wr;
    164      1.1    elric 	data->ramdac_rd = rd;
    165      1.1    elric 	return (struct ramdac_cookie *)data;
    166      1.1    elric }
    167      1.1    elric 
    168      1.1    elric /*
    169      1.1    elric  * This function exists solely to provide a means to init
    170      1.1    elric  * the RAMDAC without first registering.  It is useful for
    171      1.1    elric  * initializing the console early on.
    172      1.1    elric  */
    173      1.1    elric void
    174      1.1    elric bt485_cninit(v, sched_update, wr, rd)
    175      1.1    elric 	void *v;
    176      1.1    elric 	int (*sched_update)(void *, void (*)(void *));
    177      1.1    elric 	void (*wr)(void *, u_int, u_int8_t);
    178      1.1    elric 	u_int8_t (*rd)(void *, u_int);
    179      1.1    elric {
    180      1.1    elric 	struct bt485data tmp, *data = &tmp;
    181      1.1    elric 	data->cookie = v;
    182      1.1    elric 	data->ramdac_sched_update = sched_update;
    183      1.1    elric 	data->ramdac_wr = wr;
    184      1.1    elric 	data->ramdac_rd = rd;
    185      1.1    elric 	bt485_init((struct ramdac_cookie *)data);
    186      1.1    elric }
    187      1.1    elric 
    188      1.1    elric void
    189      1.1    elric bt485_init(rc)
    190      1.1    elric 	struct ramdac_cookie *rc;
    191      1.1    elric {
    192      1.1    elric 	u_int8_t regval;
    193      1.1    elric 	struct bt485data *data = (struct bt485data *)rc;
    194      1.1    elric 	int i;
    195      1.1    elric 
    196      1.1    elric 	/*
    197      1.1    elric 	 * Init the BT485 for normal operation.
    198      1.1    elric 	 */
    199      1.1    elric 
    200      1.1    elric 	/*
    201      1.1    elric 	 * Allow indirect register access.  (Actually, this is
    202      1.1    elric 	 * already enabled.  In fact, if it is _disabled_, for
    203      1.1    elric 	 * some reason the monitor appears to lose sync!!! (?!?!)
    204      1.1    elric 	 */
    205      1.1    elric 	regval = data->ramdac_rd(data->cookie, BT485_REG_COMMAND_0);
    206      1.1    elric 	regval |= 0x80;
    207      1.1    elric 	/*
    208      1.1    elric 	 * Set the RAMDAC to 8 bit resolution, rather than 6 bit
    209      1.1    elric 	 * resolution.
    210      1.1    elric 	 */
    211      1.1    elric 	regval |= 0x02;
    212      1.1    elric 	data->ramdac_wr(data->cookie, BT485_REG_COMMAND_0, regval);
    213      1.1    elric 
    214      1.1    elric 	/* Set the RAMDAC to 8BPP (no interestion options). */
    215      1.1    elric 	data->ramdac_wr(data->cookie, BT485_REG_COMMAND_1, 0x40);
    216      1.1    elric 
    217      1.1    elric 	/* Disable the cursor (for now) */
    218      1.1    elric 	regval = data->ramdac_rd(data->cookie, BT485_REG_COMMAND_2);
    219      1.1    elric 	regval &= ~0x03;
    220      1.1    elric 	regval |= 0x24;
    221      1.1    elric 	data->ramdac_wr(data->cookie, BT485_REG_COMMAND_2, regval);
    222      1.1    elric 
    223      1.1    elric 	/* Use a 64x64x2 cursor */
    224      1.1    elric 	regval = bt485_rd_i(data, BT485_IREG_COMMAND_3);
    225      1.1    elric 	regval |= 0x04;
    226      1.1    elric 	regval |= 0x08;
    227      1.1    elric 	bt485_wr_i(data, BT485_IREG_COMMAND_3, regval);
    228      1.1    elric 
    229      1.1    elric 	/* Set the Pixel Mask to something useful */
    230      1.1    elric 	data->ramdac_wr(data->cookie, BT485_REG_PIXMASK, 0xff);
    231      1.1    elric 
    232      1.1    elric 	/*
    233  1.3.4.2  nathanw 	 * Initialize the RAMDAC info struct to hold all of our
    234      1.1    elric 	 * data, and fill it in.
    235      1.1    elric 	 */
    236      1.1    elric 	data->changed = DATA_ALL_CHANGED;
    237      1.1    elric 
    238      1.1    elric 	data->curenb = 0;				/* cursor disabled */
    239      1.1    elric 	data->curpos.x = data->curpos.y = 0;		/* right now at 0,0 */
    240      1.1    elric 	data->curhot.x = data->curhot.y = 0;		/* hot spot at 0,0 */
    241      1.1    elric 
    242      1.1    elric 	/* initial cursor colormap: 0 is black, 1 is white */
    243      1.1    elric 	data->curcmap_r[0] = data->curcmap_g[0] = data->curcmap_b[0] = 0;
    244      1.1    elric 	data->curcmap_r[1] = data->curcmap_g[1] = data->curcmap_b[1] = 0xff;
    245      1.1    elric 
    246      1.1    elric 	/* initial cursor data: 64x64 block of white. */
    247      1.1    elric 	data->cursize.x = data->cursize.y = 64;
    248      1.1    elric 	for (i = 0; i < 512; i++)
    249      1.1    elric 		data->curimage[i] = data->curmask[i] = 0xff;
    250      1.1    elric 
    251      1.1    elric 	/* Initial colormap: 0 is black, everything else is white */
    252      1.1    elric 	data->cmap_r[0] = data->cmap_g[0] = data->cmap_b[0] = 0;
    253      1.1    elric 	for (i = 1; i < 256; i++)
    254      1.1    elric 		data->cmap_r[i] = data->cmap_g[i] = data->cmap_b[i] = 255;
    255      1.1    elric 
    256      1.1    elric 	bt485_update((void *)data);
    257      1.1    elric }
    258      1.1    elric 
    259      1.1    elric int
    260      1.1    elric bt485_set_cmap(rc, cmapp)
    261      1.1    elric 	struct ramdac_cookie *rc;
    262      1.1    elric 	struct wsdisplay_cmap *cmapp;
    263      1.1    elric {
    264      1.1    elric 	struct bt485data *data = (struct bt485data *)rc;
    265  1.3.4.1  nathanw 	u_int count, index;
    266  1.3.4.1  nathanw 	int s;
    267      1.1    elric 
    268  1.3.4.1  nathanw 	if (cmapp->index >= 256 || (cmapp->index + cmapp->count) > 256)
    269      1.1    elric 		return (EINVAL);
    270      1.1    elric 	if (!uvm_useracc(cmapp->red, cmapp->count, B_READ) ||
    271      1.1    elric 	    !uvm_useracc(cmapp->green, cmapp->count, B_READ) ||
    272      1.1    elric 	    !uvm_useracc(cmapp->blue, cmapp->count, B_READ))
    273      1.1    elric 		return (EFAULT);
    274      1.1    elric 
    275      1.1    elric 	s = spltty();
    276      1.1    elric 
    277      1.1    elric 	index = cmapp->index;
    278      1.1    elric 	count = cmapp->count;
    279      1.1    elric 	copyin(cmapp->red, &data->cmap_r[index], count);
    280      1.1    elric 	copyin(cmapp->green, &data->cmap_g[index], count);
    281      1.1    elric 	copyin(cmapp->blue, &data->cmap_b[index], count);
    282      1.1    elric 
    283      1.1    elric 	data->changed |= DATA_CMAP_CHANGED;
    284      1.1    elric 
    285      1.1    elric 	data->ramdac_sched_update(data->cookie, bt485_update);
    286      1.1    elric 	splx(s);
    287      1.1    elric 
    288      1.1    elric 	return (0);
    289      1.1    elric }
    290      1.1    elric 
    291      1.1    elric int
    292      1.1    elric bt485_get_cmap(rc, cmapp)
    293      1.1    elric 	struct ramdac_cookie *rc;
    294      1.1    elric 	struct wsdisplay_cmap *cmapp;
    295      1.1    elric {
    296      1.1    elric 	struct bt485data *data = (struct bt485data *)rc;
    297      1.1    elric 	int error, count, index;
    298      1.1    elric 
    299      1.1    elric 	if ((u_int)cmapp->index >= 256 ||
    300      1.1    elric 	    ((u_int)cmapp->index + (u_int)cmapp->count) > 256)
    301      1.1    elric 		return (EINVAL);
    302      1.1    elric 
    303      1.1    elric 	count = cmapp->count;
    304      1.1    elric 	index = cmapp->index;
    305      1.1    elric 
    306      1.1    elric 	error = copyout(&data->cmap_r[index], cmapp->red, count);
    307      1.1    elric 	if (error)
    308      1.1    elric 		return (error);
    309      1.1    elric 	error = copyout(&data->cmap_g[index], cmapp->green, count);
    310      1.1    elric 	if (error)
    311      1.1    elric 		return (error);
    312      1.1    elric 	error = copyout(&data->cmap_b[index], cmapp->blue, count);
    313      1.1    elric 	return (error);
    314      1.1    elric }
    315      1.1    elric 
    316      1.1    elric int
    317      1.1    elric bt485_set_cursor(rc, cursorp)
    318      1.1    elric 	struct ramdac_cookie *rc;
    319      1.1    elric 	struct wsdisplay_cursor *cursorp;
    320      1.1    elric {
    321      1.1    elric 	struct bt485data *data = (struct bt485data *)rc;
    322  1.3.4.1  nathanw 	u_int count, index, v;
    323  1.3.4.1  nathanw 	int s;
    324      1.1    elric 
    325      1.1    elric 	v = cursorp->which;
    326      1.1    elric 
    327      1.1    elric 	/*
    328      1.1    elric 	 * For DOCMAP and DOSHAPE, verify that parameters are OK
    329      1.1    elric 	 * before we do anything that we can't recover from.
    330      1.1    elric 	 */
    331      1.1    elric 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    332  1.3.4.1  nathanw 		if (cursorp->cmap.index > 2 ||
    333  1.3.4.1  nathanw 		    (cursorp->cmap.index + cursorp->cmap.count) > 2)
    334      1.1    elric 			return (EINVAL);
    335      1.1    elric 		count = cursorp->cmap.count;
    336      1.1    elric 		if (!uvm_useracc(cursorp->cmap.red, count, B_READ) ||
    337      1.1    elric 		    !uvm_useracc(cursorp->cmap.green, count, B_READ) ||
    338      1.1    elric 		    !uvm_useracc(cursorp->cmap.blue, count, B_READ))
    339      1.1    elric 			return (EFAULT);
    340      1.1    elric 	}
    341      1.1    elric 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    342  1.3.4.1  nathanw 		if (cursorp->size.x > CURSOR_MAX_SIZE ||
    343  1.3.4.1  nathanw 		    cursorp->size.y > CURSOR_MAX_SIZE)
    344      1.1    elric 			return (EINVAL);
    345      1.1    elric 		count = (CURSOR_MAX_SIZE / NBBY) * data->cursize.y;
    346      1.1    elric 		if (!uvm_useracc(cursorp->image, count, B_READ) ||
    347      1.1    elric 		    !uvm_useracc(cursorp->mask, count, B_READ))
    348      1.1    elric 			return (EFAULT);
    349      1.1    elric 	}
    350      1.1    elric 
    351      1.1    elric 	if (v & (WSDISPLAY_CURSOR_DOPOS | WSDISPLAY_CURSOR_DOCUR)) {
    352      1.1    elric 		if (v & WSDISPLAY_CURSOR_DOPOS)
    353      1.1    elric 			data->curpos = cursorp->pos;
    354      1.1    elric 		if (v & WSDISPLAY_CURSOR_DOCUR)
    355      1.1    elric 			data->curhot = cursorp->hot;
    356      1.1    elric 		bt485_update_curpos(data);
    357      1.1    elric 	}
    358      1.1    elric 
    359      1.1    elric 	s = spltty();
    360      1.1    elric 
    361      1.1    elric 	/* Parameters are OK; perform the requested operations. */
    362      1.1    elric 	if (v & WSDISPLAY_CURSOR_DOCUR) {
    363      1.1    elric 		data->curenb = cursorp->enable;
    364      1.1    elric 		data->changed |= DATA_ENB_CHANGED;
    365      1.1    elric 	}
    366      1.1    elric 	if (v & WSDISPLAY_CURSOR_DOCMAP) {
    367      1.1    elric 		count = cursorp->cmap.count;
    368      1.1    elric 		index = cursorp->cmap.index;
    369      1.1    elric 		copyin(cursorp->cmap.red, &data->curcmap_r[index], count);
    370      1.1    elric 		copyin(cursorp->cmap.green, &data->curcmap_g[index], count);
    371      1.1    elric 		copyin(cursorp->cmap.blue, &data->curcmap_b[index], count);
    372      1.1    elric 		data->changed |= DATA_CURCMAP_CHANGED;
    373      1.1    elric 	}
    374      1.1    elric 	if (v & WSDISPLAY_CURSOR_DOSHAPE) {
    375      1.1    elric 		data->cursize = cursorp->size;
    376      1.1    elric 		count = (CURSOR_MAX_SIZE / NBBY) * data->cursize.y;
    377  1.3.4.1  nathanw 		memset(data->curimage, 0, sizeof data->curimage);
    378  1.3.4.1  nathanw 		memset(data->curmask, 0, sizeof data->curmask);
    379      1.1    elric 		copyin(cursorp->image, data->curimage, count);	/* can't fail */
    380      1.1    elric 		copyin(cursorp->mask, data->curmask, count);	/* can't fail */
    381      1.1    elric 		data->changed |= DATA_CURSHAPE_CHANGED;
    382      1.1    elric 	}
    383      1.1    elric 
    384      1.1    elric 	if (data->changed)
    385      1.1    elric 		data->ramdac_sched_update(data->cookie, bt485_update);
    386      1.1    elric 	splx(s);
    387      1.1    elric 
    388      1.1    elric 	return (0);
    389      1.1    elric }
    390      1.1    elric 
    391      1.1    elric int
    392      1.1    elric bt485_get_cursor(rc, cursorp)
    393      1.1    elric 	struct ramdac_cookie *rc;
    394      1.1    elric 	struct wsdisplay_cursor *cursorp;
    395      1.1    elric {
    396      1.1    elric 	struct bt485data *data = (struct bt485data *)rc;
    397      1.1    elric 	int error, count;
    398      1.1    elric 
    399      1.1    elric 	/* we return everything they want */
    400      1.1    elric 	cursorp->which = WSDISPLAY_CURSOR_DOALL;
    401      1.1    elric 
    402      1.1    elric 	cursorp->enable = data->curenb;	/* DOCUR */
    403      1.1    elric 	cursorp->pos = data->curpos;	/* DOPOS */
    404      1.1    elric 	cursorp->hot = data->curhot;	/* DOHOT */
    405      1.1    elric 
    406      1.1    elric 	cursorp->cmap.index = 0;	/* DOCMAP */
    407      1.1    elric 	cursorp->cmap.count = 2;
    408      1.1    elric 	if (cursorp->cmap.red != NULL) {
    409      1.1    elric 		error = copyout(data->curcmap_r, cursorp->cmap.red, 2);
    410      1.1    elric 		if (error)
    411      1.1    elric 			return (error);
    412      1.1    elric 	}
    413      1.1    elric 	if (cursorp->cmap.green != NULL) {
    414      1.1    elric 		error = copyout(data->curcmap_g, cursorp->cmap.green, 2);
    415      1.1    elric 		if (error)
    416      1.1    elric 			return (error);
    417      1.1    elric 	}
    418      1.1    elric 	if (cursorp->cmap.blue != NULL) {
    419      1.1    elric 		error = copyout(data->curcmap_b, cursorp->cmap.blue, 2);
    420      1.1    elric 		if (error)
    421      1.1    elric 			return (error);
    422      1.1    elric 	}
    423      1.1    elric 
    424      1.1    elric 	cursorp->size = data->cursize;	/* DOSHAPE */
    425      1.1    elric 	if (cursorp->image != NULL) {
    426      1.1    elric 		count = (CURSOR_MAX_SIZE / NBBY) * data->cursize.y;
    427      1.1    elric 		error = copyout(data->curimage, cursorp->image, count);
    428      1.1    elric 		if (error)
    429      1.1    elric 			return (error);
    430      1.1    elric 		error = copyout(data->curmask, cursorp->mask, count);
    431      1.1    elric 		if (error)
    432      1.1    elric 			return (error);
    433      1.1    elric 	}
    434      1.1    elric 
    435      1.1    elric 	return (0);
    436      1.1    elric }
    437      1.1    elric 
    438      1.1    elric int
    439      1.1    elric bt485_set_curpos(rc, curposp)
    440      1.1    elric 	struct ramdac_cookie *rc;
    441      1.1    elric 	struct wsdisplay_curpos *curposp;
    442      1.1    elric {
    443      1.1    elric 	struct bt485data *data = (struct bt485data *)rc;
    444      1.1    elric 
    445      1.1    elric 	data->curpos = *curposp;
    446      1.1    elric 	bt485_update_curpos(data);
    447      1.1    elric 
    448      1.1    elric 	return (0);
    449      1.1    elric }
    450      1.1    elric 
    451      1.1    elric int
    452      1.1    elric bt485_get_curpos(rc, curposp)
    453      1.1    elric 	struct ramdac_cookie *rc;
    454      1.1    elric 	struct wsdisplay_curpos *curposp;
    455      1.1    elric {
    456      1.1    elric 	struct bt485data *data = (struct bt485data *)rc;
    457      1.1    elric 
    458      1.1    elric 	*curposp = data->curpos;
    459      1.1    elric 	return (0);
    460      1.1    elric }
    461      1.1    elric 
    462      1.1    elric int
    463      1.1    elric bt485_get_curmax(rc, curposp)
    464      1.1    elric 	struct ramdac_cookie *rc;
    465      1.1    elric 	struct wsdisplay_curpos *curposp;
    466      1.1    elric {
    467      1.1    elric 
    468      1.1    elric 	curposp->x = curposp->y = CURSOR_MAX_SIZE;
    469      1.1    elric 	return (0);
    470      1.1    elric }
    471      1.1    elric 
    472      1.1    elric /*****************************************************************************/
    473      1.1    elric 
    474      1.1    elric /*
    475      1.1    elric  * Internal functions.
    476      1.1    elric  */
    477      1.1    elric 
    478      1.1    elric inline void
    479      1.1    elric bt485_wr_i(data, ireg, val)
    480      1.1    elric 	struct bt485data *data;
    481      1.1    elric 	u_int8_t ireg;
    482      1.1    elric 	u_int8_t val;
    483      1.1    elric {
    484      1.1    elric 	data->ramdac_wr(data->cookie, BT485_REG_PCRAM_WRADDR, ireg);
    485      1.1    elric 	data->ramdac_wr(data->cookie, BT485_REG_EXTENDED, val);
    486      1.1    elric }
    487      1.1    elric 
    488      1.1    elric inline u_int8_t
    489      1.1    elric bt485_rd_i(data, ireg)
    490      1.1    elric 	struct bt485data *data;
    491      1.1    elric 	u_int8_t ireg;
    492      1.1    elric {
    493      1.1    elric 	data->ramdac_wr(data->cookie, BT485_REG_PCRAM_WRADDR, ireg);
    494      1.1    elric 	return (data->ramdac_rd(data->cookie, BT485_REG_EXTENDED));
    495      1.1    elric }
    496      1.1    elric 
    497      1.1    elric void
    498      1.1    elric bt485_update(vp)
    499      1.1    elric 	void *vp;
    500      1.1    elric {
    501      1.1    elric 	struct bt485data *data = vp;
    502      1.1    elric 	u_int8_t regval;
    503      1.1    elric 	int count, i, v;
    504      1.1    elric 
    505      1.1    elric 	v = data->changed;
    506      1.1    elric 	data->changed = 0;
    507      1.1    elric 
    508      1.1    elric 	if (v & DATA_ENB_CHANGED) {
    509      1.1    elric 		regval = data->ramdac_rd(data->cookie, BT485_REG_COMMAND_2);
    510      1.1    elric 		if (data->curenb)
    511      1.1    elric 			regval |= 0x01;
    512      1.1    elric 		else
    513      1.1    elric 			regval &= ~0x03;
    514      1.1    elric                 data->ramdac_wr(data->cookie, BT485_REG_COMMAND_2, regval);
    515      1.1    elric 	}
    516      1.1    elric 
    517      1.1    elric 	if (v & DATA_CURCMAP_CHANGED) {
    518      1.1    elric 		/* addr[9:0] assumed to be 0 */
    519      1.1    elric 		/* set addr[7:0] to 1 */
    520      1.1    elric                 data->ramdac_wr(data->cookie, BT485_REG_COC_WRADDR, 0x01);
    521      1.1    elric 
    522      1.1    elric 		/* spit out the cursor data */
    523      1.1    elric 		for (i = 0; i < 2; i++) {
    524      1.1    elric                 	data->ramdac_wr(data->cookie, BT485_REG_COCDATA,
    525      1.1    elric 			    data->curcmap_r[i]);
    526      1.1    elric                 	data->ramdac_wr(data->cookie, BT485_REG_COCDATA,
    527      1.1    elric 			    data->curcmap_g[i]);
    528      1.1    elric                 	data->ramdac_wr(data->cookie, BT485_REG_COCDATA,
    529      1.1    elric 			    data->curcmap_b[i]);
    530      1.1    elric 		}
    531      1.1    elric 	}
    532      1.1    elric 
    533      1.1    elric 	if (v & DATA_CURSHAPE_CHANGED) {
    534      1.1    elric 		count = (CURSOR_MAX_SIZE / NBBY) * data->cursize.y;
    535      1.1    elric 
    536      1.1    elric 		/*
    537      1.1    elric 		 * Write the cursor image data:
    538      1.1    elric 		 *	set addr[9:8] to 0,
    539      1.1    elric 		 *	set addr[7:0] to 0,
    540      1.1    elric 		 *	spit it all out.
    541      1.1    elric 		 */
    542      1.1    elric 		regval = bt485_rd_i(data, BT485_IREG_COMMAND_3);
    543      1.1    elric 		regval &= ~0x03;
    544      1.1    elric 		bt485_wr_i(data, BT485_IREG_COMMAND_3, regval);
    545      1.1    elric                 data->ramdac_wr(data->cookie, BT485_REG_PCRAM_WRADDR, 0);
    546      1.1    elric 		for (i = 0; i < count; i++)
    547      1.1    elric 			data->ramdac_wr(data->cookie, BT485_REG_CURSOR_RAM,
    548      1.1    elric 			    data->curimage[i]);
    549      1.1    elric 
    550      1.1    elric 		/*
    551      1.1    elric 		 * Write the cursor mask data:
    552      1.1    elric 		 *	set addr[9:8] to 2,
    553      1.1    elric 		 *	set addr[7:0] to 0,
    554      1.1    elric 		 *	spit it all out.
    555      1.1    elric 		 */
    556      1.1    elric 		regval = bt485_rd_i(data, BT485_IREG_COMMAND_3);
    557      1.1    elric 		regval &= ~0x03; regval |= 0x02;
    558      1.1    elric 		bt485_wr_i(data, BT485_IREG_COMMAND_3, regval);
    559      1.1    elric                 data->ramdac_wr(data->cookie, BT485_REG_PCRAM_WRADDR, 0);
    560      1.1    elric 		for (i = 0; i < count; i++)
    561      1.1    elric 			data->ramdac_wr(data->cookie, BT485_REG_CURSOR_RAM,
    562      1.1    elric 			    data->curmask[i]);
    563      1.1    elric 
    564      1.1    elric 		/* set addr[9:0] back to 0 */
    565      1.1    elric 		regval = bt485_rd_i(data, BT485_IREG_COMMAND_3);
    566      1.1    elric 		regval &= ~0x03;
    567      1.1    elric 		bt485_wr_i(data, BT485_IREG_COMMAND_3, regval);
    568      1.1    elric 	}
    569      1.1    elric 
    570      1.1    elric 	if (v & DATA_CMAP_CHANGED) {
    571      1.1    elric 		/* addr[9:0] assumed to be 0 */
    572      1.1    elric 		/* set addr[7:0] to 0 */
    573      1.1    elric                 data->ramdac_wr(data->cookie, BT485_REG_PCRAM_WRADDR, 0x00);
    574      1.1    elric 
    575      1.1    elric 		/* spit out the cursor data */
    576      1.1    elric 		for (i = 0; i < 256; i++) {
    577      1.1    elric                 	data->ramdac_wr(data->cookie, BT485_REG_PALETTE,
    578      1.1    elric 			    data->cmap_r[i]);
    579      1.1    elric                 	data->ramdac_wr(data->cookie, BT485_REG_PALETTE,
    580      1.1    elric 			    data->cmap_g[i]);
    581      1.1    elric                 	data->ramdac_wr(data->cookie, BT485_REG_PALETTE,
    582      1.1    elric 			    data->cmap_b[i]);
    583      1.1    elric 		}
    584      1.1    elric 	}
    585      1.1    elric }
    586      1.1    elric 
    587      1.1    elric void
    588      1.1    elric bt485_update_curpos(data)
    589      1.1    elric 	struct bt485data *data;
    590      1.1    elric {
    591      1.1    elric 	void *cookie = data->cookie;
    592      1.1    elric 	int s, x, y;
    593      1.1    elric 
    594      1.1    elric 	s = spltty();
    595      1.1    elric 
    596      1.1    elric 	x = data->curpos.x + CURSOR_MAX_SIZE - data->curhot.x;
    597      1.1    elric 	y = data->curpos.y + CURSOR_MAX_SIZE - data->curhot.y;
    598      1.1    elric 	data->ramdac_wr(cookie, BT485_REG_CURSOR_X_LOW, x & 0xff);
    599      1.1    elric 	data->ramdac_wr(cookie, BT485_REG_CURSOR_X_HIGH, (x >> 8) & 0x0f);
    600      1.1    elric 	data->ramdac_wr(cookie, BT485_REG_CURSOR_Y_LOW, y & 0xff);
    601      1.1    elric 	data->ramdac_wr(cookie, BT485_REG_CURSOR_Y_HIGH, (y >> 8) & 0x0f);
    602      1.1    elric 
    603      1.1    elric 	splx(s);
    604      1.1    elric }
    605