Home | History | Annotate | Line # | Download | only in ic
bt463.c revision 1.8.6.1
      1 /* $NetBSD: bt463.c,v 1.8.6.1 2004/08/03 10:46:12 skrll Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
      9  * NASA Ames Research Center.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. All advertising materials mentioning features or use of this software
     20  *    must display the following acknowledgement:
     21  *	This product includes software developed by the NetBSD
     22  *	Foundation, Inc. and its contributors.
     23  * 4. Neither the name of The NetBSD Foundation nor the names of its
     24  *    contributors may be used to endorse or promote products derived
     25  *    from this software without specific prior written permission.
     26  *
     27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     37  * POSSIBILITY OF SUCH DAMAGE.
     38  */
     39 
     40 /*
     41  * Copyright (c) 1995, 1996 Carnegie-Mellon University.
     42  * All rights reserved.
     43  *
     44  * Author: Chris G. Demetriou
     45  *
     46  * Permission to use, copy, modify and distribute this software and
     47  * its documentation is hereby granted, provided that both the copyright
     48  * notice and this permission notice appear in all copies of the
     49  * software, derivative works or modified versions, and any portions
     50  * thereof, and that both notices appear in supporting documentation.
     51  *
     52  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     53  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
     54  * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     55  *
     56  * Carnegie Mellon requests users of this software to return to
     57  *
     58  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     59  *  School of Computer Science
     60  *  Carnegie Mellon University
     61  *  Pittsburgh PA 15213-3890
     62  *
     63  * any improvements or extensions that they make and grant Carnegie the
     64  * rights to redistribute these changes.
     65  */
     66 
     67  /* This code was derived from and originally located in sys/dev/pci/
     68   *	 NetBSD: tga_bt463.c,v 1.5 2000/03/04 10:27:59 elric Exp
     69   */
     70 
     71 #include <sys/cdefs.h>
     72 __KERNEL_RCSID(0, "$NetBSD: bt463.c,v 1.8.6.1 2004/08/03 10:46:12 skrll Exp $");
     73 
     74 #include <sys/param.h>
     75 #include <sys/systm.h>
     76 #include <sys/device.h>
     77 #include <sys/buf.h>
     78 #include <sys/kernel.h>
     79 #include <sys/malloc.h>
     80 
     81 #include <uvm/uvm_extern.h>
     82 
     83 #include <dev/pci/pcivar.h>
     84 #include <dev/pci/tgareg.h>
     85 #include <dev/pci/tgavar.h>
     86 #include <dev/ic/bt463reg.h>
     87 #include <dev/ic/bt463var.h>
     88 
     89 #include <dev/wscons/wsconsio.h>
     90 
     91 /*
     92  * Functions exported via the RAMDAC configuration table.
     93  */
     94 void	bt463_init __P((struct ramdac_cookie *));
     95 int	bt463_set_cmap __P((struct ramdac_cookie *,
     96 	    struct wsdisplay_cmap *));
     97 int	bt463_get_cmap __P((struct ramdac_cookie *,
     98 	    struct wsdisplay_cmap *));
     99 int	bt463_set_cursor __P((struct ramdac_cookie *,
    100 	    struct wsdisplay_cursor *));
    101 int	bt463_get_cursor __P((struct ramdac_cookie *,
    102 	    struct wsdisplay_cursor *));
    103 int	bt463_set_curpos __P((struct ramdac_cookie *,
    104 	    struct wsdisplay_curpos *));
    105 int	bt463_get_curpos __P((struct ramdac_cookie *,
    106 	    struct wsdisplay_curpos *));
    107 int	bt463_get_curmax __P((struct ramdac_cookie *,
    108 	    struct wsdisplay_curpos *));
    109 int	bt463_check_curcmap __P((struct ramdac_cookie *,
    110 	    struct wsdisplay_cursor *cursorp));
    111 void	bt463_set_curcmap __P((struct ramdac_cookie *,
    112 	    struct wsdisplay_cursor *cursorp));
    113 int	bt463_get_curcmap __P((struct ramdac_cookie *,
    114 	    struct wsdisplay_cursor *cursorp));
    115 
    116 #ifdef BT463_DEBUG
    117 int bt463_store __P((void *));
    118 int bt463_debug __P((void *));
    119 int bt463_readback __P((void *));
    120 void	bt463_copyback __P((void *));
    121 #endif
    122 
    123 struct ramdac_funcs bt463_funcsstruct = {
    124 	"Bt463",
    125 	bt463_register,
    126 	bt463_init,
    127 	bt463_set_cmap,
    128 	bt463_get_cmap,
    129 	bt463_set_cursor,
    130 	bt463_get_cursor,
    131 	bt463_set_curpos,
    132 	bt463_get_curpos,
    133 	bt463_get_curmax,
    134 	bt463_check_curcmap,
    135 	bt463_set_curcmap,
    136 	bt463_get_curcmap,
    137 	NULL,
    138 };
    139 
    140 /*
    141  * Private data.
    142  */
    143 struct bt463data {
    144 	void            *cookie;        /* This is what is passed
    145 					 * around, and is probably
    146 					 * struct tga_devconfig *
    147 					 */
    148 
    149 	int             (*ramdac_sched_update) __P((void *, void (*)(void *)));
    150 	void            (*ramdac_wr) __P((void *, u_int, u_int8_t));
    151 	u_int8_t        (*ramdac_rd) __P((void *, u_int));
    152 
    153 	int	changed;			/* what changed; see below */
    154 	char curcmap_r[2];			/* cursor colormap */
    155 	char curcmap_g[2];
    156 	char curcmap_b[2];
    157 	char tmpcurcmap_r[2];			/* tmp cursor colormap */
    158 	char tmpcurcmap_g[2];
    159 	char tmpcurcmap_b[2];
    160 	char cmap_r[BT463_NCMAP_ENTRIES];	/* colormap */
    161 	char cmap_g[BT463_NCMAP_ENTRIES];
    162 	char cmap_b[BT463_NCMAP_ENTRIES];
    163 	int window_type[16]; /* 16 24-bit window type table entries */
    164 };
    165 
    166 /* When we're doing console initialization, there's no
    167  * way to get our cookie back to the video card's softc
    168  * before we call sched_update. So we stash it here,
    169  * and bt463_update will look for it here first.
    170  */
    171 static struct bt463data *console_data;
    172 
    173 
    174 #define BTWREG(data, addr, val) do { bt463_wraddr((data), (addr)); \
    175 	(data)->ramdac_wr((data)->cookie, BT463_REG_IREG_DATA, (val)); } while (0)
    176 #define BTWNREG(data, val) (data)->ramdac_wr((data)->cookie, \
    177 	BT463_REG_IREG_DATA, (val))
    178 #define BTRREG(data, addr) (bt463_wraddr((data), (addr)), \
    179 	(data)->ramdac_rd((data)->cookie, BT463_REG_IREG_DATA))
    180 #define BTRNREG(data) ((data)->ramdac_rd((data)->cookie, BT463_REG_IREG_DATA))
    181 
    182 #define	DATA_CURCMAP_CHANGED	0x01	/* cursor colormap changed */
    183 #define	DATA_CMAP_CHANGED	0x02	/* colormap changed */
    184 #define	DATA_WTYPE_CHANGED	0x04	/* window type table changed */
    185 #define	DATA_ALL_CHANGED	0x07
    186 
    187 /*
    188  * Internal functions.
    189  */
    190 inline void bt463_wraddr __P((struct bt463data *, u_int16_t));
    191 
    192 void	bt463_update __P((void *));
    193 
    194 
    195 /*****************************************************************************/
    196 
    197 /*
    198  * Functions exported via the RAMDAC configuration table.
    199  */
    200 
    201 struct ramdac_funcs *
    202 bt463_funcs(void)
    203 {
    204 	return &bt463_funcsstruct;
    205 }
    206 
    207 struct ramdac_cookie *
    208 bt463_register(v, sched_update, wr, rd)
    209 	void *v;
    210 	int (*sched_update)(void *, void (*)(void *));
    211 	void (*wr)(void *, u_int, u_int8_t);
    212 	u_int8_t (*rd)(void *, u_int);
    213 {
    214 	struct bt463data *data;
    215 	/*
    216 	 * XXX -- comment out of date.  rcd.
    217 	 * If we should allocate a new private info struct, do so.
    218 	 * Otherwise, use the one we have (if it's there), or
    219 	 * use the temporary one on the stack.
    220 	 */
    221 	data = malloc(sizeof *data, M_DEVBUF, M_WAITOK);
    222 	/* XXX -- if !data */
    223 	data->cookie = v;
    224 	data->ramdac_sched_update = sched_update;
    225 	data->ramdac_wr = wr;
    226 	data->ramdac_rd = rd;
    227 	return (struct ramdac_cookie *)data;
    228 }
    229 
    230 /*
    231  * This function exists solely to provide a means to init
    232  * the RAMDAC without first registering.  It is useful for
    233  * initializing the console early on.
    234  */
    235 void
    236 bt463_cninit(v, sched_update, wr, rd)
    237 	void *v;
    238 	int (*sched_update)(void *, void (*)(void *));
    239 	void (*wr)(void *, u_int, u_int8_t);
    240 	u_int8_t (*rd)(void *, u_int);
    241 {
    242 	struct bt463data tmp, *data = &tmp;
    243 	data->cookie = v;
    244 	data->ramdac_sched_update = sched_update;
    245 	data->ramdac_wr = wr;
    246 	data->ramdac_rd = rd;
    247 	/* Set up console_data so that when bt463_update is called back,
    248 	 * it can use the right information.
    249 	 */
    250 	console_data = data;
    251 	bt463_init((struct ramdac_cookie *)data);
    252 	console_data = NULL;
    253 }
    254 
    255 void
    256 bt463_init(rc)
    257 	struct ramdac_cookie *rc;
    258 {
    259 	struct bt463data *data = (struct bt463data *)rc;
    260 
    261 	int i;
    262 
    263 	/*
    264 	 * Init the BT463 for normal operation.
    265 	 */
    266 
    267 
    268 	/*
    269 	 * Setup:
    270 	 * reg 0: 4:1 multiplexing, 25/75 blink.
    271 	 * reg 1: Overlay mapping: mapped to common palette,
    272 	 *        14 window type entries, 24-plane configuration mode,
    273 	 *        4 overlay planes, underlays disabled, no cursor.
    274 	 * reg 2: sync-on-green enabled, pedestal enabled.
    275 	 */
    276 
    277 	BTWREG(data, BT463_IREG_COMMAND_0, 0x40);
    278 	BTWREG(data, BT463_IREG_COMMAND_1, 0x48);
    279 	BTWREG(data, BT463_IREG_COMMAND_2, 0x40);
    280 
    281 	/*
    282 	 * Initialize the read mask.
    283 	 */
    284 	bt463_wraddr(data, BT463_IREG_READ_MASK_P0_P7);
    285 	for (i = 0; i < 4; i++)
    286 		BTWNREG(data, 0xff);
    287 
    288 	/*
    289 	 * Initialize the blink mask.
    290 	 */
    291 	bt463_wraddr(data, BT463_IREG_BLINK_MASK_P0_P7);
    292 	for (i = 0; i < 4; i++)
    293 		BTWNREG(data, 0);
    294 
    295 
    296 	/*
    297 	 * Clear test register
    298 	 */
    299 	BTWREG(data, BT463_IREG_TEST, 0);
    300 
    301 	/*
    302 	 * Initialize the RAMDAC info struct to hold all of our
    303 	 * data, and fill it in.
    304 	 */
    305 	data->changed = DATA_ALL_CHANGED;
    306 
    307 	/* initial cursor colormap: 0 is black, 1 is white */
    308 	data->curcmap_r[0] = data->curcmap_g[0] = data->curcmap_b[0] = 0;
    309 	data->curcmap_r[1] = data->curcmap_g[1] = data->curcmap_b[1] = 0xff;
    310 
    311 	/* Initial colormap: 0 is black, everything else is white */
    312 	data->cmap_r[0] = data->cmap_g[0] = data->cmap_b[0] = 0;
    313 	for (i = 1; i < 256; i++)
    314 		data->cmap_r[i] = data->cmap_g[i] = data->cmap_b[i] = 255;
    315 
    316 
    317 	/* Initialize the window type table:
    318 	 *
    319 	 * Entry 0: 24-plane truecolor, overlays enabled, bypassed.
    320 	 *
    321 	 *  Lookup table bypass:      yes (    1 << 23 & 0x800000)  800000
    322 	 *  Colormap address:       0x000 (0x000 << 17 & 0x7e0000)       0
    323 	 *  Overlay mask:             0xf (  0xf << 13 & 0x01e000)   1e000
    324 	 *  Overlay location:    P<27:24> (    0 << 12 & 0x001000)       0
    325 	 *  Display mode:       Truecolor (    0 <<  9 & 0x000e00)     000
    326 	 *  Number of planes:           8 (    8 <<  5 & 0x0001e0)     100
    327 	 *  Plane shift:                0 (    0 <<  0 & 0x00001f)       0
    328 	 *                                                        --------
    329 	 *                                                        0x81e100
    330 	 */
    331 	data->window_type[0] = 0x81e100;
    332 
    333 	/* Entry 1: 8-plane pseudocolor in the bottom 8 bits,
    334 	 *          overlays enabled, colormap starting at 0.
    335 	 *
    336 	 *  Lookup table bypass:       no (    0 << 23 & 0x800000)       0
    337 	 *  Colormap address:       0x000 (0x000 << 17 & 0x7e0000)       0
    338 	 *  Overlay mask:             0xf (  0xf << 13 & 0x01e000) 0x1e000
    339 	 *  Overlay location:    P<27:24> (    0 << 12 & 0x001000)       0
    340 	 *  Display mode:     Pseudocolor (    1 <<  9 & 0x000e00)   0x200
    341 	 *  Number of planes:           8 (    8 <<  5 & 0x0001e0)   0x100
    342 	 *  Plane shift:               16 ( 0x10 <<  0 & 0x00001f)      10
    343 	 *                                                        --------
    344 	 *                                                        0x01e310
    345 	 */
    346 	data->window_type[1] = 0x01e310;
    347 
    348 	/* The colormap interface to the world only supports one colormap,
    349 	 * so having an entry for the 'alternate' colormap in the bt463
    350 	 * probably isn't useful.
    351 	 */
    352 
    353 	/* Fill the remaining table entries with clones of entry 0 until we
    354 	 * figure out a better use for them.
    355 	 */
    356 
    357 	for (i = 2; i < BT463_NWTYPE_ENTRIES; i++) {
    358 		data->window_type[i] = 0x81e100;
    359 	}
    360 
    361 	data->ramdac_sched_update(data->cookie, bt463_update);
    362 
    363 }
    364 
    365 int
    366 bt463_set_cmap(rc, cmapp)
    367 	struct ramdac_cookie *rc;
    368 	struct wsdisplay_cmap *cmapp;
    369 {
    370 	struct bt463data *data = (struct bt463data *)rc;
    371 	u_int count, index;
    372 	uint8_t r[BT463_NCMAP_ENTRIES];
    373 	uint8_t g[BT463_NCMAP_ENTRIES];
    374 	uint8_t b[BT463_NCMAP_ENTRIES];
    375 	int s, error;
    376 
    377 	if (cmapp->index >= BT463_NCMAP_ENTRIES ||
    378 	    cmapp->count > BT463_NCMAP_ENTRIES - cmapp->index)
    379 		return (EINVAL);
    380 
    381 	index = cmapp->index;
    382 	count = cmapp->count;
    383 	error = copyin(cmapp->red, &r[index], count);
    384 	if (error)
    385 		return error;
    386 	error = copyin(cmapp->green, &g[index], count);
    387 	if (error)
    388 		return error;
    389 	error = copyin(cmapp->blue, &b[index], count);
    390 	if (error)
    391 		return error;
    392 	s = spltty();
    393 	memcpy(&data->cmap_r[index], &r[index], count);
    394 	memcpy(&data->cmap_g[index], &g[index], count);
    395 	memcpy(&data->cmap_b[index], &b[index], count);
    396  	data->changed |= DATA_CMAP_CHANGED;
    397 	data->ramdac_sched_update(data->cookie, bt463_update);
    398 	splx(s);
    399 	return (0);
    400 }
    401 
    402 int
    403 bt463_get_cmap(rc, cmapp)
    404 	struct ramdac_cookie *rc;
    405 	struct wsdisplay_cmap *cmapp;
    406 {
    407 	struct bt463data *data = (struct bt463data *)rc;
    408 	u_int count, index;
    409 	int error;
    410 
    411 	if (cmapp->index >= BT463_NCMAP_ENTRIES ||
    412 	    cmapp->count > BT463_NCMAP_ENTRIES - cmapp->index)
    413 		return (EINVAL);
    414 
    415 	count = cmapp->count;
    416 	index = cmapp->index;
    417 
    418 	error = copyout(&data->cmap_r[index], cmapp->red, count);
    419 	if (error)
    420 		return (error);
    421 	error = copyout(&data->cmap_g[index], cmapp->green, count);
    422 	if (error)
    423 		return (error);
    424 	error = copyout(&data->cmap_b[index], cmapp->blue, count);
    425 	return (error);
    426 }
    427 
    428 int
    429 bt463_check_curcmap(rc, cursorp)
    430 	struct ramdac_cookie *rc;
    431 	struct wsdisplay_cursor *cursorp;
    432 {
    433 	struct bt463data *data = (struct bt463data *)rc;
    434 	int count, index, error;
    435 
    436 	if (cursorp->cmap.index > 2 ||
    437 	    (cursorp->cmap.index + cursorp->cmap.count) > 2)
    438 		return (EINVAL);
    439 	count = cursorp->cmap.count;
    440 	index = cursorp->cmap.index;
    441 	error = copyin(cursorp->cmap.red, &data->tmpcurcmap_r[index], count);
    442 	if (error)
    443 		return error;
    444 	error = copyin(cursorp->cmap.green, &data->tmpcurcmap_g[index], count);
    445 	if (error)
    446 		return error;
    447 	error = copyin(cursorp->cmap.blue, &data->tmpcurcmap_b[index], count);
    448 	if (error)
    449 		return error;
    450 	return (0);
    451 }
    452 
    453 void
    454 bt463_set_curcmap(rc, cursorp)
    455 	struct ramdac_cookie *rc;
    456 	struct wsdisplay_cursor *cursorp;
    457 {
    458 	struct bt463data *data = (struct bt463data *)rc;
    459 	int count, index;
    460 
    461 	count = cursorp->cmap.count;
    462 	index = cursorp->cmap.index;
    463 	memcpy(&data->curcmap_r[index], &data->tmpcurcmap_r[index], count);
    464 	memcpy(&data->curcmap_g[index], &data->tmpcurcmap_g[index], count);
    465 	memcpy(&data->curcmap_b[index], &data->tmpcurcmap_b[index], count);
    466 	data->changed |= DATA_CURCMAP_CHANGED;
    467 	data->ramdac_sched_update(data->cookie, bt463_update);
    468 }
    469 
    470 int
    471 bt463_get_curcmap(rc, cursorp)
    472 	struct ramdac_cookie *rc;
    473 	struct wsdisplay_cursor *cursorp;
    474 {
    475 	struct bt463data *data = (struct bt463data *)rc;
    476 	int error;
    477 
    478 	cursorp->cmap.index = 0;	/* DOCMAP */
    479 	cursorp->cmap.count = 2;
    480 	if (cursorp->cmap.red != NULL) {
    481 		error = copyout(data->curcmap_r, cursorp->cmap.red, 2);
    482 		if (error)
    483 			return (error);
    484 	}
    485 	if (cursorp->cmap.green != NULL) {
    486 		error = copyout(data->curcmap_g, cursorp->cmap.green, 2);
    487 		if (error)
    488 			return (error);
    489 	}
    490 	if (cursorp->cmap.blue != NULL) {
    491 		error = copyout(data->curcmap_b, cursorp->cmap.blue, 2);
    492 		if (error)
    493 			return (error);
    494 	}
    495 	return (0);
    496 }
    497 
    498 
    499 /*****************************************************************************/
    500 
    501 /*
    502  * Internal functions.
    503  */
    504 
    505 #ifdef BT463_DEBUG
    506 int bt463_store(void *v)
    507 {
    508 	struct bt463data *data = (struct bt463data *)v;
    509 
    510 	data->changed = DATA_ALL_CHANGED;
    511 	data->ramdac_sched_update(data->cookie, bt463_update);
    512 	printf("Scheduled bt463 store\n");
    513 
    514 	return 0;
    515 }
    516 
    517 
    518 int bt463_readback(void *v)
    519 {
    520 	struct bt463data *data = (struct bt463data *)v;
    521 
    522 	data->ramdac_sched_update(data->cookie, bt463_copyback);
    523 	printf("Scheduled bt463 copyback\n");
    524 	return 0;
    525 }
    526 
    527 int
    528 bt463_debug(v)
    529 	void *v;
    530 {
    531 	struct bt463data *data = (struct bt463data *)v;
    532 	int i;
    533 	u_int8_t val;
    534 
    535 	printf("BT463 main regs:\n");
    536 	for (i = 0x200; i < 0x20F; i ++) {
    537 	  val = BTRREG(data, i);
    538 	  printf("  $%04x %02x\n", i, val);
    539 	}
    540 
    541 	printf("BT463 revision register:\n");
    542 	  val = BTRREG(data, 0x220);
    543 	  printf("  $%04x %02x\n", 0x220, val);
    544 
    545 	printf("BT463 window type table (from softc):\n");
    546 
    547 	for (i = 0; i < BT463_NWTYPE_ENTRIES; i++) {
    548 	  printf("%02x %06x\n", i, data->window_type[i]);
    549 	}
    550 
    551 	return 0;
    552 }
    553 
    554 void
    555 bt463_copyback(p)
    556 	 void *p;
    557 {
    558 	struct bt463data *data = (struct bt463data *)p;
    559 	int i;
    560 
    561 		for (i = 0; i < BT463_NWTYPE_ENTRIES; i++) {
    562 			bt463_wraddr(data, BT463_IREG_WINDOW_TYPE_TABLE + i);
    563 			data->window_type[i] = (BTRNREG(data) & 0xff);        /* B0-7   */
    564 			data->window_type[i] |= (BTRNREG(data) & 0xff) << 8;  /* B8-15  */
    565 			data->window_type[i] |= (BTRNREG(data) & 0xff) << 16; /* B16-23 */
    566 		}
    567 }
    568 #endif
    569 
    570 inline void
    571 bt463_wraddr(data, ireg)
    572 	struct bt463data *data;
    573 	u_int16_t ireg;
    574 {
    575 	data->ramdac_wr(data->cookie, BT463_REG_ADDR_LOW, ireg & 0xff);
    576 	data->ramdac_wr(data->cookie, BT463_REG_ADDR_HIGH, (ireg >> 8) & 0xff);
    577 }
    578 
    579 void
    580 bt463_update(p)
    581 	void *p;
    582 {
    583 	struct bt463data *data = (struct bt463data *)p;
    584 	int i, v;
    585 
    586 	if (console_data != NULL) {
    587 		/* The cookie passed in from sched_update is incorrect. Use the
    588 		 * right one.
    589 		 */
    590 		data = console_data;
    591 	}
    592 
    593 	v = data->changed;
    594 
    595 	/* The Bt463 won't accept window type data except during a blanking
    596 	 * interval, so we do this early in the interrupt.
    597 	 * Blanking the screen might also be a good idea, but it can cause
    598 	 * unpleasant flashing and is hard to do from this side of the
    599 	 * ramdac interface.
    600 	 */
    601 	if (v & DATA_WTYPE_CHANGED) {
    602 		/* spit out the window type data */
    603 		for (i = 0; i < BT463_NWTYPE_ENTRIES; i++) {
    604 			bt463_wraddr(data, BT463_IREG_WINDOW_TYPE_TABLE + i);
    605 			BTWNREG(data, (data->window_type[i]) & 0xff);       /* B0-7   */
    606 			BTWNREG(data, (data->window_type[i] >> 8) & 0xff);  /* B8-15   */
    607 			BTWNREG(data, (data->window_type[i] >> 16) & 0xff); /* B16-23  */
    608 		}
    609 	}
    610 
    611 	if (v & DATA_CURCMAP_CHANGED) {
    612 		bt463_wraddr(data, BT463_IREG_CURSOR_COLOR_0);
    613 		/* spit out the cursor data */
    614 		for (i = 0; i < 2; i++) {
    615 			BTWNREG(data, data->curcmap_r[i]);
    616 			BTWNREG(data, data->curcmap_g[i]);
    617 			BTWNREG(data, data->curcmap_b[i]);
    618 		}
    619 	}
    620 
    621 	if (v & DATA_CMAP_CHANGED) {
    622 		bt463_wraddr(data, BT463_IREG_CPALETTE_RAM);
    623 		/* spit out the colormap data */
    624 		for (i = 0; i < BT463_NCMAP_ENTRIES; i++) {
    625 			data->ramdac_wr(data->cookie, BT463_REG_CMAP_DATA,
    626 				data->cmap_r[i]);
    627 			data->ramdac_wr(data->cookie, BT463_REG_CMAP_DATA,
    628 				data->cmap_g[i]);
    629 			data->ramdac_wr(data->cookie, BT463_REG_CMAP_DATA,
    630 				data->cmap_b[i]);
    631 		}
    632 	}
    633 
    634 	data->changed = 0;
    635 }
    636 
    637 int	bt463_set_cursor (rc, cur)
    638 	struct ramdac_cookie *rc;
    639 	struct wsdisplay_cursor *cur;
    640 {
    641 	struct bt463data *data = (struct bt463data *)rc;
    642 	return tga_builtin_set_cursor(data->cookie, cur);
    643 }
    644 
    645 int	bt463_get_cursor (rc, cur)
    646 	struct ramdac_cookie *rc;
    647 	struct wsdisplay_cursor *cur;
    648 {
    649 	struct bt463data *data = (struct bt463data *)rc;
    650 	return tga_builtin_get_cursor(data->cookie, cur);
    651 }
    652 
    653 int	bt463_set_curpos (rc, cur)
    654 	struct ramdac_cookie *rc;
    655 	struct wsdisplay_curpos *cur;
    656 {
    657 	struct bt463data *data = (struct bt463data *)rc;
    658 	return tga_builtin_set_curpos(data->cookie, cur);
    659 }
    660 
    661 int	bt463_get_curpos (rc, cur)
    662 	struct ramdac_cookie *rc;
    663 	struct wsdisplay_curpos *cur;
    664 {
    665 	struct bt463data *data = (struct bt463data *)rc;
    666 	return tga_builtin_get_curpos(data->cookie, cur);
    667 }
    668 
    669 int	bt463_get_curmax (rc, cur)
    670 	struct ramdac_cookie *rc;
    671 	struct wsdisplay_curpos *cur;
    672 {
    673 	struct bt463data *data = (struct bt463data *)rc;
    674 	return tga_builtin_get_curmax(data->cookie, cur);
    675 }
    676