Home | History | Annotate | Line # | Download | only in ic
ibm561.c revision 1.1.2.4
      1  1.1.2.4  nathanw /* $NetBSD: ibm561.c,v 1.1.2.4 2002/08/13 02:19:23 nathanw Exp $ */
      2  1.1.2.2  nathanw 
      3  1.1.2.2  nathanw /*-
      4  1.1.2.2  nathanw  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  1.1.2.2  nathanw  * All rights reserved.
      6  1.1.2.2  nathanw  *
      7  1.1.2.2  nathanw  * This code is derived from software contributed to The NetBSD Foundation
      8  1.1.2.2  nathanw  * by Roland C. Dowdeswell of Ponte, Inc.
      9  1.1.2.2  nathanw  *
     10  1.1.2.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11  1.1.2.2  nathanw  * modification, are permitted provided that the following conditions
     12  1.1.2.2  nathanw  * are met:
     13  1.1.2.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14  1.1.2.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15  1.1.2.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.2.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.2.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18  1.1.2.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19  1.1.2.2  nathanw  *    must display the following acknowledgement:
     20  1.1.2.2  nathanw  *	This product includes software developed by the NetBSD
     21  1.1.2.2  nathanw  *	Foundation, Inc. and its contributors.
     22  1.1.2.2  nathanw  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1.2.2  nathanw  *    contributors may be used to endorse or promote products derived
     24  1.1.2.2  nathanw  *    from this software without specific prior written permission.
     25  1.1.2.2  nathanw  *
     26  1.1.2.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1.2.2  nathanw  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1.2.2  nathanw  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1.2.2  nathanw  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1.2.2  nathanw  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1.2.2  nathanw  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1.2.2  nathanw  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1.2.2  nathanw  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1.2.2  nathanw  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1.2.2  nathanw  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1.2.2  nathanw  * POSSIBILITY OF SUCH DAMAGE.
     37  1.1.2.2  nathanw  */
     38  1.1.2.2  nathanw 
     39  1.1.2.2  nathanw #include <sys/param.h>
     40  1.1.2.2  nathanw #include <sys/systm.h>
     41  1.1.2.2  nathanw #include <sys/device.h>
     42  1.1.2.2  nathanw #include <sys/buf.h>
     43  1.1.2.2  nathanw #include <sys/kernel.h>
     44  1.1.2.2  nathanw #include <sys/malloc.h>
     45  1.1.2.2  nathanw 
     46  1.1.2.2  nathanw #include <uvm/uvm_extern.h>
     47  1.1.2.2  nathanw 
     48  1.1.2.2  nathanw #include <dev/pci/pcivar.h>
     49  1.1.2.2  nathanw #include <dev/ic/ibm561reg.h>
     50  1.1.2.2  nathanw #include <dev/ic/ibm561var.h>
     51  1.1.2.2  nathanw #include <dev/ic/ramdac.h>
     52  1.1.2.2  nathanw 
     53  1.1.2.2  nathanw #include <dev/wscons/wsconsio.h>
     54  1.1.2.2  nathanw 
     55  1.1.2.2  nathanw /*
     56  1.1.2.2  nathanw  * Functions exported via the RAMDAC configuration table.
     57  1.1.2.2  nathanw  */
     58  1.1.2.2  nathanw void	ibm561_init __P((struct ramdac_cookie *));
     59  1.1.2.2  nathanw int	ibm561_set_cmap __P((struct ramdac_cookie *,
     60  1.1.2.2  nathanw 	    struct wsdisplay_cmap *));
     61  1.1.2.2  nathanw int	ibm561_get_cmap __P((struct ramdac_cookie *,
     62  1.1.2.2  nathanw 	    struct wsdisplay_cmap *));
     63  1.1.2.2  nathanw int	ibm561_set_cursor __P((struct ramdac_cookie *,
     64  1.1.2.2  nathanw 	    struct wsdisplay_cursor *));
     65  1.1.2.2  nathanw int	ibm561_get_cursor __P((struct ramdac_cookie *,
     66  1.1.2.2  nathanw 	    struct wsdisplay_cursor *));
     67  1.1.2.2  nathanw int	ibm561_set_curpos __P((struct ramdac_cookie *,
     68  1.1.2.2  nathanw 	    struct wsdisplay_curpos *));
     69  1.1.2.2  nathanw int	ibm561_get_curpos __P((struct ramdac_cookie *,
     70  1.1.2.2  nathanw 	    struct wsdisplay_curpos *));
     71  1.1.2.2  nathanw int	ibm561_get_curmax __P((struct ramdac_cookie *,
     72  1.1.2.2  nathanw 	    struct wsdisplay_curpos *));
     73  1.1.2.2  nathanw int	ibm561_set_dotclock __P((struct ramdac_cookie *,
     74  1.1.2.2  nathanw 	    unsigned));
     75  1.1.2.2  nathanw 
     76  1.1.2.2  nathanw /* XXX const */
     77  1.1.2.2  nathanw struct ramdac_funcs ibm561_funcsstruct = {
     78  1.1.2.2  nathanw 	"IBM561",
     79  1.1.2.2  nathanw 	ibm561_register,
     80  1.1.2.2  nathanw 	ibm561_init,
     81  1.1.2.2  nathanw 	ibm561_set_cmap,
     82  1.1.2.2  nathanw 	ibm561_get_cmap,
     83  1.1.2.2  nathanw 	ibm561_set_cursor,
     84  1.1.2.2  nathanw 	ibm561_get_cursor,
     85  1.1.2.2  nathanw 	ibm561_set_curpos,
     86  1.1.2.2  nathanw 	ibm561_get_curpos,
     87  1.1.2.2  nathanw 	ibm561_get_curmax,
     88  1.1.2.2  nathanw 	NULL,			/* check_curcmap; not needed */
     89  1.1.2.2  nathanw 	NULL,			/* set_curcmap; not needed */
     90  1.1.2.2  nathanw 	NULL,			/* get_curcmap; not needed */
     91  1.1.2.2  nathanw 	ibm561_set_dotclock,
     92  1.1.2.2  nathanw };
     93  1.1.2.2  nathanw 
     94  1.1.2.2  nathanw /*
     95  1.1.2.2  nathanw  * Private data.
     96  1.1.2.2  nathanw  */
     97  1.1.2.2  nathanw struct ibm561data {
     98  1.1.2.2  nathanw 	void            *cookie;
     99  1.1.2.2  nathanw 
    100  1.1.2.2  nathanw 	int             (*ramdac_sched_update) __P((void *, void (*)(void *)));
    101  1.1.2.2  nathanw 	void            (*ramdac_wr) __P((void *, u_int, u_int8_t));
    102  1.1.2.2  nathanw 	u_int8_t        (*ramdac_rd) __P((void *, u_int));
    103  1.1.2.2  nathanw 
    104  1.1.2.2  nathanw #define CHANGED_CURCMAP		0x0001	/* cursor cmap */
    105  1.1.2.2  nathanw #define CHANGED_CMAP		0x0002	/* color map */
    106  1.1.2.2  nathanw #define CHANGED_WTYPE		0x0004	/* window types */
    107  1.1.2.2  nathanw #define CHANGED_DOTCLOCK	0x0008	/* dot clock */
    108  1.1.2.2  nathanw #define CHANGED_ALL		0x000f	/* or of all above */
    109  1.1.2.2  nathanw 	u_int8_t	changed;
    110  1.1.2.2  nathanw 
    111  1.1.2.2  nathanw 	/* dotclock parameters */
    112  1.1.2.2  nathanw 	u_int8_t	vco_div;
    113  1.1.2.2  nathanw 	u_int8_t	pll_ref;
    114  1.1.2.2  nathanw 	u_int8_t	div_dotclock;
    115  1.1.2.2  nathanw 
    116  1.1.2.2  nathanw 	/* colormaps et al. */
    117  1.1.2.2  nathanw 	u_int8_t	curcmap_r[2];
    118  1.1.2.2  nathanw 	u_int8_t	curcmap_g[2];
    119  1.1.2.2  nathanw 	u_int8_t	curcmap_b[2];
    120  1.1.2.2  nathanw 
    121  1.1.2.2  nathanw 	u_int8_t	cmap_r[IBM561_NCMAP_ENTRIES];
    122  1.1.2.2  nathanw 	u_int8_t	cmap_g[IBM561_NCMAP_ENTRIES];
    123  1.1.2.2  nathanw 	u_int8_t	cmap_b[IBM561_NCMAP_ENTRIES];
    124  1.1.2.2  nathanw 
    125  1.1.2.2  nathanw 	u_int16_t	gamma_r[IBM561_NGAMMA_ENTRIES];
    126  1.1.2.2  nathanw 	u_int16_t	gamma_g[IBM561_NGAMMA_ENTRIES];
    127  1.1.2.2  nathanw 	u_int16_t	gamma_b[IBM561_NGAMMA_ENTRIES];
    128  1.1.2.2  nathanw 
    129  1.1.2.2  nathanw 	u_int16_t	wtype[IBM561_NWTYPES];
    130  1.1.2.2  nathanw };
    131  1.1.2.2  nathanw 
    132  1.1.2.2  nathanw /*
    133  1.1.2.2  nathanw  * private functions
    134  1.1.2.2  nathanw  */
    135  1.1.2.2  nathanw void	ibm561_update __P((void *));
    136  1.1.2.2  nathanw static void ibm561_load_cmap(struct ibm561data *);
    137  1.1.2.2  nathanw static void ibm561_load_dotclock(struct ibm561data *);
    138  1.1.2.2  nathanw static void ibm561_regbegin(struct ibm561data *, u_int16_t);
    139  1.1.2.2  nathanw static void ibm561_regcont(struct ibm561data *, u_int16_t, u_int8_t);
    140  1.1.2.2  nathanw static void ibm561_regcont10bit(struct ibm561data *, u_int16_t, u_int16_t);
    141  1.1.2.2  nathanw static void ibm561_regwr(struct ibm561data *, u_int16_t, u_int8_t);
    142  1.1.2.2  nathanw 
    143  1.1.2.2  nathanw struct ramdac_funcs *
    144  1.1.2.2  nathanw ibm561_funcs(void)
    145  1.1.2.2  nathanw {
    146  1.1.2.2  nathanw 	return &ibm561_funcsstruct;
    147  1.1.2.2  nathanw }
    148  1.1.2.2  nathanw 
    149  1.1.2.2  nathanw struct ramdac_cookie *
    150  1.1.2.2  nathanw ibm561_register(v, sched_update, wr, rd)
    151  1.1.2.2  nathanw 	void *v;
    152  1.1.2.2  nathanw 	int (*sched_update)(void *, void (*)(void *));
    153  1.1.2.2  nathanw 	void (*wr)(void *, u_int, u_int8_t);
    154  1.1.2.2  nathanw 	u_int8_t (*rd)(void *, u_int);
    155  1.1.2.2  nathanw {
    156  1.1.2.2  nathanw 	struct ibm561data *data;
    157  1.1.2.2  nathanw 
    158  1.1.2.3  nathanw 	data = malloc(sizeof *data, M_DEVBUF, M_WAITOK|M_ZERO);
    159  1.1.2.2  nathanw 	data->cookie = v;
    160  1.1.2.2  nathanw 	data->ramdac_sched_update = sched_update;
    161  1.1.2.2  nathanw 	data->ramdac_wr = wr;
    162  1.1.2.2  nathanw 	data->ramdac_rd = rd;
    163  1.1.2.2  nathanw 	return (struct ramdac_cookie *)data;
    164  1.1.2.2  nathanw }
    165  1.1.2.2  nathanw 
    166  1.1.2.2  nathanw /*
    167  1.1.2.2  nathanw  * This function exists solely to provide a means to init
    168  1.1.2.2  nathanw  * the RAMDAC without first registering.  It is useful for
    169  1.1.2.2  nathanw  * initializing the console early on.
    170  1.1.2.2  nathanw  */
    171  1.1.2.2  nathanw 
    172  1.1.2.2  nathanw struct ibm561data *saved_console_data;
    173  1.1.2.2  nathanw 
    174  1.1.2.2  nathanw void
    175  1.1.2.2  nathanw ibm561_cninit(v, sched_update, wr, rd, dotclock)
    176  1.1.2.2  nathanw 	void *v;
    177  1.1.2.2  nathanw 	int (*sched_update)(void *, void (*)(void *));
    178  1.1.2.2  nathanw 	void (*wr)(void *, u_int, u_int8_t);
    179  1.1.2.2  nathanw 	u_int8_t (*rd)(void *, u_int);
    180  1.1.2.2  nathanw 	u_int dotclock;
    181  1.1.2.2  nathanw {
    182  1.1.2.2  nathanw 	struct ibm561data tmp, *data = &tmp;
    183  1.1.2.2  nathanw 	memset(data, 0x0, sizeof *data);
    184  1.1.2.2  nathanw 	data->cookie = v;
    185  1.1.2.2  nathanw 	data->ramdac_sched_update = sched_update;
    186  1.1.2.2  nathanw 	data->ramdac_wr = wr;
    187  1.1.2.2  nathanw 	data->ramdac_rd = rd;
    188  1.1.2.2  nathanw 	ibm561_set_dotclock((struct ramdac_cookie *)data, dotclock);
    189  1.1.2.2  nathanw 	saved_console_data = data;
    190  1.1.2.2  nathanw 	ibm561_init((struct ramdac_cookie *)data);
    191  1.1.2.2  nathanw 	saved_console_data = NULL;
    192  1.1.2.2  nathanw }
    193  1.1.2.2  nathanw 
    194  1.1.2.2  nathanw void
    195  1.1.2.2  nathanw ibm561_init(rc)
    196  1.1.2.2  nathanw 	struct ramdac_cookie *rc;
    197  1.1.2.2  nathanw {
    198  1.1.2.2  nathanw 	struct	ibm561data *data = (struct ibm561data *)rc;
    199  1.1.2.2  nathanw 	int	i;
    200  1.1.2.2  nathanw 
    201  1.1.2.2  nathanw 	/* XXX this is _essential_ */
    202  1.1.2.2  nathanw 
    203  1.1.2.2  nathanw 	ibm561_load_dotclock(data);
    204  1.1.2.2  nathanw 
    205  1.1.2.2  nathanw 	/* XXXrcd: bunch of magic of which I have no current clue */
    206  1.1.2.2  nathanw 	ibm561_regwr(data, IBM561_CONFIG_REG1, 0x2a);
    207  1.1.2.2  nathanw 	ibm561_regwr(data, IBM561_CONFIG_REG3, 0x41);
    208  1.1.2.2  nathanw 	ibm561_regwr(data, IBM561_CONFIG_REG4, 0x20);
    209  1.1.2.2  nathanw 
    210  1.1.2.2  nathanw 	/* initialize the card a bit */
    211  1.1.2.2  nathanw 	ibm561_regwr(data, IBM561_SYNC_CNTL, 0x1);
    212  1.1.2.2  nathanw 	ibm561_regwr(data, IBM561_CONFIG_REG2, 0x19);
    213  1.1.2.2  nathanw 
    214  1.1.2.2  nathanw 	ibm561_regwr(data, IBM561_CONFIG_REG1, 0x2a);
    215  1.1.2.2  nathanw 	ibm561_regwr(data, IBM561_CONFIG_REG4, 0x20);
    216  1.1.2.2  nathanw 
    217  1.1.2.2  nathanw 	ibm561_regbegin(data, IBM561_WAT_SEG_REG);
    218  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0x00);
    219  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0x00);
    220  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0x00);
    221  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0x00);
    222  1.1.2.2  nathanw 	ibm561_regbegin(data, IBM561_CHROMAKEY0);
    223  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0x00);
    224  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0x00);
    225  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0x00);
    226  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0x00);
    227  1.1.2.2  nathanw 
    228  1.1.2.2  nathanw 	ibm561_regwr(data, IBM561_CURS_CNTL_REG, 0x00); /* XXX off? */
    229  1.1.2.2  nathanw 
    230  1.1.2.2  nathanw 	/* cursor `hot spot' registers */
    231  1.1.2.2  nathanw 	ibm561_regbegin(data, IBM561_HOTSPOT_REG);
    232  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0x00);
    233  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0x00);
    234  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0xff);
    235  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0x00);
    236  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0xff);
    237  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0x00);
    238  1.1.2.2  nathanw 
    239  1.1.2.2  nathanw 	/* VRAM Mask Registers (diagnostics) */
    240  1.1.2.2  nathanw 	ibm561_regbegin(data, IBM561_VRAM_MASK_REG);
    241  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0xff);
    242  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0xff);
    243  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0xff);
    244  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0xff);
    245  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0xff);
    246  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0xff);
    247  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, 0xff);
    248  1.1.2.2  nathanw 
    249  1.1.2.2  nathanw 	/* let's set up some decent default colour maps and gammas */
    250  1.1.2.2  nathanw 	for (i=0; i < IBM561_NCMAP_ENTRIES; i++)
    251  1.1.2.2  nathanw 		data->cmap_r[i] = data->cmap_g[i] = data->cmap_b[i] = 0xff;
    252  1.1.2.2  nathanw 	data->cmap_r[0]   = data->cmap_g[0]   = data->cmap_b[0]   = 0x00;
    253  1.1.2.2  nathanw 	data->cmap_r[256] = data->cmap_g[256] = data->cmap_b[256] = 0x00;
    254  1.1.2.2  nathanw 	data->cmap_r[512] = data->cmap_g[512] = data->cmap_b[512] = 0x00;
    255  1.1.2.2  nathanw 	data->cmap_r[768] = data->cmap_g[768] = data->cmap_b[768] = 0x00;
    256  1.1.2.2  nathanw 
    257  1.1.2.2  nathanw 	data->gamma_r[0] = data->gamma_g[0] = data->gamma_b[0] = 0x00;
    258  1.1.2.2  nathanw 	for (i=0; i < IBM561_NGAMMA_ENTRIES; i++)
    259  1.1.2.2  nathanw 		data->gamma_r[i] = data->gamma_g[i] = data->gamma_b[i] = 0xff;
    260  1.1.2.2  nathanw 
    261  1.1.2.2  nathanw 	for (i=0; i < IBM561_NWTYPES; i++)
    262  1.1.2.2  nathanw 		data->wtype[i] = 0x0036;
    263  1.1.2.2  nathanw 	data->wtype[1] = 0x0028;
    264  1.1.2.2  nathanw 
    265  1.1.2.2  nathanw 	/* the last step: */
    266  1.1.2.2  nathanw 	data->changed = CHANGED_ALL;
    267  1.1.2.2  nathanw 	data->ramdac_sched_update(data->cookie, ibm561_update);
    268  1.1.2.2  nathanw }
    269  1.1.2.2  nathanw 
    270  1.1.2.2  nathanw int
    271  1.1.2.2  nathanw ibm561_set_cmap(rc, cmapp)
    272  1.1.2.2  nathanw 	struct ramdac_cookie *rc;
    273  1.1.2.2  nathanw 	struct wsdisplay_cmap *cmapp;
    274  1.1.2.2  nathanw {
    275  1.1.2.2  nathanw 	struct ibm561data *data = (struct ibm561data *)rc;
    276  1.1.2.4  nathanw 	u_int count, index;
    277  1.1.2.2  nathanw 	int s;
    278  1.1.2.2  nathanw 
    279  1.1.2.4  nathanw 	if (cmapp->index >= IBM561_NCMAP_ENTRIES ||
    280  1.1.2.4  nathanw 	    cmapp->count > IBM561_NCMAP_ENTRIES - cmapp->index)
    281  1.1.2.2  nathanw 		return (EINVAL);
    282  1.1.2.2  nathanw 	if (!uvm_useracc(cmapp->red, cmapp->count, B_READ) ||
    283  1.1.2.2  nathanw 	    !uvm_useracc(cmapp->green, cmapp->count, B_READ) ||
    284  1.1.2.2  nathanw 	    !uvm_useracc(cmapp->blue, cmapp->count, B_READ))
    285  1.1.2.2  nathanw 		return (EFAULT);
    286  1.1.2.2  nathanw 
    287  1.1.2.2  nathanw 	s = spltty();
    288  1.1.2.2  nathanw 	index = cmapp->index;
    289  1.1.2.2  nathanw 	count = cmapp->count;
    290  1.1.2.2  nathanw 	copyin(cmapp->red, &data->cmap_r[index], count);
    291  1.1.2.2  nathanw 	copyin(cmapp->green, &data->cmap_g[index], count);
    292  1.1.2.2  nathanw 	copyin(cmapp->blue, &data->cmap_b[index], count);
    293  1.1.2.2  nathanw 	data->changed |= CHANGED_CMAP;
    294  1.1.2.2  nathanw 	data->ramdac_sched_update(data->cookie, ibm561_update);
    295  1.1.2.2  nathanw 	splx(s);
    296  1.1.2.2  nathanw 	return (0);
    297  1.1.2.2  nathanw }
    298  1.1.2.2  nathanw 
    299  1.1.2.2  nathanw int
    300  1.1.2.2  nathanw ibm561_get_cmap(rc, cmapp)
    301  1.1.2.2  nathanw 	struct ramdac_cookie *rc;
    302  1.1.2.2  nathanw 	struct wsdisplay_cmap *cmapp;
    303  1.1.2.2  nathanw {
    304  1.1.2.2  nathanw 	struct ibm561data *data = (struct ibm561data *)rc;
    305  1.1.2.4  nathanw 	u_int count, index;
    306  1.1.2.2  nathanw 	int error;
    307  1.1.2.2  nathanw 
    308  1.1.2.4  nathanw 	if (cmapp->index >= IBM561_NCMAP_ENTRIES ||
    309  1.1.2.4  nathanw 	    cmapp->count > IBM561_NCMAP_ENTRIES - cmapp->index)
    310  1.1.2.2  nathanw 		return (EINVAL);
    311  1.1.2.2  nathanw 	count = cmapp->count;
    312  1.1.2.2  nathanw 	index = cmapp->index;
    313  1.1.2.2  nathanw 	error = copyout(&data->cmap_r[index], cmapp->red, count);
    314  1.1.2.2  nathanw 	if (error)
    315  1.1.2.2  nathanw 		return (error);
    316  1.1.2.2  nathanw 	error = copyout(&data->cmap_g[index], cmapp->green, count);
    317  1.1.2.2  nathanw 	if (error)
    318  1.1.2.2  nathanw 		return (error);
    319  1.1.2.2  nathanw 	error = copyout(&data->cmap_b[index], cmapp->blue, count);
    320  1.1.2.2  nathanw 	return (error);
    321  1.1.2.2  nathanw }
    322  1.1.2.2  nathanw 
    323  1.1.2.2  nathanw /*
    324  1.1.2.2  nathanw  * XXX:
    325  1.1.2.2  nathanw  *  I am leaving these functions returning EINVAL, as they are
    326  1.1.2.2  nathanw  *  not strictly necessary for the correct functioning of the
    327  1.1.2.2  nathanw  *  card and in fact are not used on the other TGA variants, except
    328  1.1.2.2  nathanw  *  they are exported via ioctl(2) to userland, which does not in
    329  1.1.2.2  nathanw  *  fact use them.
    330  1.1.2.2  nathanw  */
    331  1.1.2.2  nathanw 
    332  1.1.2.2  nathanw int
    333  1.1.2.2  nathanw ibm561_set_cursor(rc, cursorp)
    334  1.1.2.2  nathanw 	struct ramdac_cookie *rc;
    335  1.1.2.2  nathanw 	struct wsdisplay_cursor *cursorp;
    336  1.1.2.2  nathanw {
    337  1.1.2.2  nathanw 	return EINVAL;
    338  1.1.2.2  nathanw }
    339  1.1.2.2  nathanw 
    340  1.1.2.2  nathanw int
    341  1.1.2.2  nathanw ibm561_get_cursor(rc, cursorp)
    342  1.1.2.2  nathanw 	struct ramdac_cookie *rc;
    343  1.1.2.2  nathanw 	struct wsdisplay_cursor *cursorp;
    344  1.1.2.2  nathanw {
    345  1.1.2.2  nathanw 	return EINVAL;
    346  1.1.2.2  nathanw }
    347  1.1.2.2  nathanw 
    348  1.1.2.2  nathanw int
    349  1.1.2.2  nathanw ibm561_set_curpos(rc, curposp)
    350  1.1.2.2  nathanw 	struct ramdac_cookie *rc;
    351  1.1.2.2  nathanw 	struct wsdisplay_curpos *curposp;
    352  1.1.2.2  nathanw {
    353  1.1.2.2  nathanw 	return EINVAL;
    354  1.1.2.2  nathanw }
    355  1.1.2.2  nathanw 
    356  1.1.2.2  nathanw int
    357  1.1.2.2  nathanw ibm561_get_curpos(rc, curposp)
    358  1.1.2.2  nathanw 	struct ramdac_cookie *rc;
    359  1.1.2.2  nathanw 	struct wsdisplay_curpos *curposp;
    360  1.1.2.2  nathanw {
    361  1.1.2.2  nathanw 	return EINVAL;
    362  1.1.2.2  nathanw }
    363  1.1.2.2  nathanw 
    364  1.1.2.2  nathanw int
    365  1.1.2.2  nathanw ibm561_get_curmax(rc, curposp)
    366  1.1.2.2  nathanw 	struct ramdac_cookie *rc;
    367  1.1.2.2  nathanw 	struct wsdisplay_curpos *curposp;
    368  1.1.2.2  nathanw {
    369  1.1.2.2  nathanw 	return EINVAL;
    370  1.1.2.2  nathanw }
    371  1.1.2.2  nathanw 
    372  1.1.2.2  nathanw int
    373  1.1.2.2  nathanw ibm561_set_dotclock(rc, dotclock)
    374  1.1.2.2  nathanw 	struct ramdac_cookie *rc;
    375  1.1.2.2  nathanw 	unsigned dotclock;
    376  1.1.2.2  nathanw {
    377  1.1.2.2  nathanw 	struct ibm561data *data = (struct ibm561data *)rc;
    378  1.1.2.2  nathanw 
    379  1.1.2.2  nathanw 	/* XXXrcd:  a couple of these are a little hazy, vis a vis
    380  1.1.2.2  nathanw 	 *          check 175MHz and 202MHz, which are wrong...
    381  1.1.2.2  nathanw 	 */
    382  1.1.2.2  nathanw 	switch (dotclock) {
    383  1.1.2.2  nathanw 	case  25175000: data->vco_div = 0x3e; data->pll_ref = 0x09; break;
    384  1.1.2.2  nathanw 	case  31500000: data->vco_div = 0x17; data->pll_ref = 0x05; break;
    385  1.1.2.2  nathanw 	case  40000000: data->vco_div = 0x42; data->pll_ref = 0x06; break;
    386  1.1.2.2  nathanw 	case  50000000: data->vco_div = 0x45; data->pll_ref = 0x05; break;
    387  1.1.2.2  nathanw 	case  65000000: data->vco_div = 0xac; data->pll_ref = 0x0c; break;
    388  1.1.2.2  nathanw 	case  69000000: data->vco_div = 0xa9; data->pll_ref = 0x0b; break;
    389  1.1.2.2  nathanw 	case  74000000: data->vco_div = 0x9c; data->pll_ref = 0x09; break;
    390  1.1.2.2  nathanw 	case  75000000: data->vco_div = 0x93; data->pll_ref = 0x08; break;
    391  1.1.2.2  nathanw 	case 103994000: data->vco_div = 0x96; data->pll_ref = 0x06; break;
    392  1.1.2.2  nathanw 	case 108180000: data->vco_div = 0xb8; data->pll_ref = 0x08; break;
    393  1.1.2.2  nathanw 	case 110000000: data->vco_div = 0xba; data->pll_ref = 0x08; break;
    394  1.1.2.2  nathanw 	case 119840000: data->vco_div = 0x82; data->pll_ref = 0x04; break;
    395  1.1.2.2  nathanw 	case 130808000: data->vco_div = 0xc8; data->pll_ref = 0x08; break;
    396  1.1.2.2  nathanw 	case 135000000: data->vco_div = 0xc1; data->pll_ref = 0x07; break;
    397  1.1.2.2  nathanw 	case 175000000: data->vco_div = 0xe2; data->pll_ref = 0x07; break;
    398  1.1.2.2  nathanw 	case 202500000: data->vco_div = 0xe2; data->pll_ref = 0x07; break;
    399  1.1.2.2  nathanw 	default:
    400  1.1.2.2  nathanw 		return EINVAL;
    401  1.1.2.2  nathanw 	}
    402  1.1.2.2  nathanw 
    403  1.1.2.2  nathanw 	data->div_dotclock = 0xb0;
    404  1.1.2.2  nathanw 	data->changed |= CHANGED_DOTCLOCK;
    405  1.1.2.2  nathanw 	return 0;
    406  1.1.2.2  nathanw }
    407  1.1.2.2  nathanw 
    408  1.1.2.2  nathanw /*
    409  1.1.2.2  nathanw  * Internal Functions
    410  1.1.2.2  nathanw  */
    411  1.1.2.2  nathanw 
    412  1.1.2.2  nathanw void
    413  1.1.2.2  nathanw ibm561_update(vp)
    414  1.1.2.2  nathanw 	void *vp;
    415  1.1.2.2  nathanw {
    416  1.1.2.2  nathanw 	struct ibm561data *data = (struct ibm561data *)vp;
    417  1.1.2.2  nathanw 	int	i;
    418  1.1.2.2  nathanw 
    419  1.1.2.2  nathanw 	/* XXX see comment above ibm561_cninit() */
    420  1.1.2.2  nathanw 	if (!data)
    421  1.1.2.2  nathanw 		data = saved_console_data;
    422  1.1.2.2  nathanw 
    423  1.1.2.2  nathanw 	if (data->changed & CHANGED_WTYPE) {
    424  1.1.2.2  nathanw 		ibm561_regbegin(data, IBM561_FB_WINTYPE);
    425  1.1.2.2  nathanw 		for (i=0; i < IBM561_NWTYPES; i++)
    426  1.1.2.2  nathanw 			ibm561_regcont10bit(data, IBM561_CMD_FB_WAT, data->wtype[i]);
    427  1.1.2.2  nathanw 
    428  1.1.2.2  nathanw 		/* XXXrcd:  quick hack here for AUX FB table */
    429  1.1.2.2  nathanw 		ibm561_regbegin(data, IBM561_AUXFB_WINTYPE);
    430  1.1.2.2  nathanw 		for (i=0; i < IBM561_NWTYPES; i++)
    431  1.1.2.2  nathanw 			ibm561_regcont(data, IBM561_CMD, 0x04);
    432  1.1.2.2  nathanw 
    433  1.1.2.2  nathanw 		/* XXXrcd:  quick hack here for OL WAT table */
    434  1.1.2.2  nathanw 		ibm561_regbegin(data, IBM561_OL_WINTYPE);
    435  1.1.2.2  nathanw 		for (i=0; i < IBM561_NWTYPES; i++)
    436  1.1.2.2  nathanw 			ibm561_regcont10bit(data, IBM561_CMD_FB_WAT, 0x0231);
    437  1.1.2.2  nathanw 
    438  1.1.2.2  nathanw 		/* XXXrcd:  quick hack here for AUX OL WAT table */
    439  1.1.2.2  nathanw 		ibm561_regbegin(data, IBM561_AUXOL_WINTYPE);
    440  1.1.2.2  nathanw 		for (i=0; i < IBM561_NWTYPES; i++)
    441  1.1.2.2  nathanw 			ibm561_regcont(data, IBM561_CMD, 0x0c);
    442  1.1.2.2  nathanw 	}
    443  1.1.2.2  nathanw 
    444  1.1.2.2  nathanw 	if (data->changed & CHANGED_CMAP)
    445  1.1.2.2  nathanw 		ibm561_load_cmap(data);
    446  1.1.2.2  nathanw 
    447  1.1.2.2  nathanw 	/* XXX:  I am not sure in what situations it is safe to
    448  1.1.2.2  nathanw 	 *       change the dotclock---hope this is good.
    449  1.1.2.2  nathanw 	 */
    450  1.1.2.2  nathanw 	if (data->changed & CHANGED_DOTCLOCK)
    451  1.1.2.2  nathanw 		ibm561_load_dotclock(data);
    452  1.1.2.2  nathanw }
    453  1.1.2.2  nathanw 
    454  1.1.2.2  nathanw static void
    455  1.1.2.2  nathanw ibm561_load_cmap(struct ibm561data *data)
    456  1.1.2.2  nathanw {
    457  1.1.2.2  nathanw 	int	i;
    458  1.1.2.2  nathanw 
    459  1.1.2.2  nathanw 	ibm561_regbegin(data, IBM561_CMAP_TABLE);
    460  1.1.2.2  nathanw 	for (i=0; i < IBM561_NCMAP_ENTRIES; i++) {
    461  1.1.2.2  nathanw 		ibm561_regcont(data, IBM561_CMD_CMAP, data->cmap_r[i]);
    462  1.1.2.2  nathanw 		ibm561_regcont(data, IBM561_CMD_CMAP, data->cmap_g[i]);
    463  1.1.2.2  nathanw 		ibm561_regcont(data, IBM561_CMD_CMAP, data->cmap_b[i]);
    464  1.1.2.2  nathanw 	}
    465  1.1.2.2  nathanw 
    466  1.1.2.2  nathanw 	ibm561_regbegin(data, IBM561_RED_GAMMA_TABLE);
    467  1.1.2.2  nathanw 	for (i=0; i < 256; i++)
    468  1.1.2.2  nathanw 		ibm561_regcont10bit(data, IBM561_CMD_GAMMA, data->gamma_r[i]);
    469  1.1.2.2  nathanw 
    470  1.1.2.2  nathanw 	ibm561_regbegin(data, IBM561_GREEN_GAMMA_TABLE);
    471  1.1.2.2  nathanw 	for (i=1; i < 256; i++)
    472  1.1.2.2  nathanw 		ibm561_regcont10bit(data, IBM561_CMD_GAMMA, data->gamma_g[i]);
    473  1.1.2.2  nathanw 
    474  1.1.2.2  nathanw 	ibm561_regbegin(data, IBM561_BLUE_GAMMA_TABLE);
    475  1.1.2.2  nathanw 	for (i=1; i < 256; i++)
    476  1.1.2.2  nathanw 		ibm561_regcont10bit(data, IBM561_CMD_GAMMA, data->gamma_b[i]);
    477  1.1.2.2  nathanw 
    478  1.1.2.2  nathanw }
    479  1.1.2.2  nathanw 
    480  1.1.2.2  nathanw static void
    481  1.1.2.2  nathanw ibm561_load_dotclock(struct ibm561data *data)
    482  1.1.2.2  nathanw {
    483  1.1.2.2  nathanw 	/* XXX
    484  1.1.2.2  nathanw 	 * we should probably be more pro-active here, but it shouldn't
    485  1.1.2.2  nathanw 	 * actually happen...
    486  1.1.2.2  nathanw 	 */
    487  1.1.2.2  nathanw 	if (!data->vco_div || !data->pll_ref || ! data->div_dotclock) {
    488  1.1.2.2  nathanw 		panic("ibm561_load_dotclock: called uninitialized");
    489  1.1.2.2  nathanw 	}
    490  1.1.2.2  nathanw 
    491  1.1.2.2  nathanw 	ibm561_regwr(data, IBM561_PLL_VCO_DIV,  data->vco_div);
    492  1.1.2.2  nathanw 	ibm561_regwr(data, IBM561_PLL_REF_REG, data->pll_ref);
    493  1.1.2.2  nathanw 	ibm561_regwr(data, IBM561_DIV_DOTCLCK, data->div_dotclock);
    494  1.1.2.2  nathanw }
    495  1.1.2.2  nathanw 
    496  1.1.2.2  nathanw static void
    497  1.1.2.2  nathanw ibm561_regcont10bit(struct ibm561data *data, u_int16_t reg, u_int16_t val)
    498  1.1.2.2  nathanw {
    499  1.1.2.2  nathanw 	data->ramdac_wr(data->cookie, IBM561_CMD_GAMMA, (val >> 2) & 0xff);
    500  1.1.2.2  nathanw 	data->ramdac_wr(data->cookie, IBM561_CMD_GAMMA, (val & 0x3) << 6);
    501  1.1.2.2  nathanw }
    502  1.1.2.2  nathanw 
    503  1.1.2.2  nathanw static void
    504  1.1.2.2  nathanw ibm561_regbegin(struct ibm561data *data, u_int16_t reg)
    505  1.1.2.2  nathanw {
    506  1.1.2.2  nathanw 	data->ramdac_wr(data->cookie, IBM561_ADDR_LOW, reg & 0xff);
    507  1.1.2.2  nathanw 	data->ramdac_wr(data->cookie, IBM561_ADDR_HIGH, (reg >> 8) & 0xff);
    508  1.1.2.2  nathanw }
    509  1.1.2.2  nathanw 
    510  1.1.2.2  nathanw static void
    511  1.1.2.2  nathanw ibm561_regcont(struct ibm561data *data, u_int16_t reg, u_int8_t val)
    512  1.1.2.2  nathanw {
    513  1.1.2.2  nathanw 	data->ramdac_wr(data->cookie, reg, val);
    514  1.1.2.2  nathanw }
    515  1.1.2.2  nathanw 
    516  1.1.2.2  nathanw static void
    517  1.1.2.2  nathanw ibm561_regwr(struct ibm561data *data, u_int16_t reg, u_int8_t val)
    518  1.1.2.2  nathanw {
    519  1.1.2.2  nathanw 	ibm561_regbegin(data, reg);
    520  1.1.2.2  nathanw 	ibm561_regcont(data, IBM561_CMD, val);
    521  1.1.2.2  nathanw }
    522