Home | History | Annotate | Line # | Download | only in ic
igsfb_subr.c revision 1.9.20.1
      1  1.9.20.1      yamt /*	$NetBSD: igsfb_subr.c,v 1.9.20.1 2010/03/11 15:03:31 yamt Exp $ */
      2       1.1       uwe 
      3       1.1       uwe /*
      4       1.1       uwe  * Copyright (c) 2002 Valeriy E. Ushakov
      5  1.9.20.1      yamt  *		 2009 Michael Lorenz
      6       1.1       uwe  * All rights reserved.
      7       1.1       uwe  *
      8       1.1       uwe  * Redistribution and use in source and binary forms, with or without
      9       1.1       uwe  * modification, are permitted provided that the following conditions
     10       1.1       uwe  * are met:
     11       1.1       uwe  * 1. Redistributions of source code must retain the above copyright
     12       1.1       uwe  *    notice, this list of conditions and the following disclaimer.
     13       1.1       uwe  * 2. Redistributions in binary form must reproduce the above copyright
     14       1.1       uwe  *    notice, this list of conditions and the following disclaimer in the
     15       1.1       uwe  *    documentation and/or other materials provided with the distribution.
     16       1.1       uwe  * 3. The name of the author may not be used to endorse or promote products
     17       1.1       uwe  *    derived from this software without specific prior written permission
     18       1.1       uwe  *
     19       1.1       uwe  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20       1.1       uwe  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21       1.1       uwe  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22       1.1       uwe  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23       1.1       uwe  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24       1.1       uwe  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25       1.1       uwe  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26       1.1       uwe  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27       1.1       uwe  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     28       1.1       uwe  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29       1.1       uwe  */
     30       1.1       uwe 
     31       1.1       uwe /*
     32       1.1       uwe  * Integraphics Systems IGA 168x and CyberPro series.
     33       1.1       uwe  */
     34       1.1       uwe #include <sys/cdefs.h>
     35  1.9.20.1      yamt __KERNEL_RCSID(0, "$NetBSD: igsfb_subr.c,v 1.9.20.1 2010/03/11 15:03:31 yamt Exp $");
     36       1.1       uwe 
     37       1.1       uwe #include <sys/param.h>
     38       1.1       uwe #include <sys/systm.h>
     39       1.1       uwe #include <sys/kernel.h>
     40       1.1       uwe #include <sys/device.h>
     41       1.1       uwe 
     42       1.9        ad #include <sys/bus.h>
     43       1.1       uwe 
     44       1.2       uwe #include <dev/wscons/wsdisplayvar.h>
     45       1.1       uwe #include <dev/wscons/wsconsio.h>
     46       1.2       uwe #include <dev/rasops/rasops.h>
     47       1.6  macallan #include <dev/wscons/wsdisplay_vconsvar.h>
     48       1.1       uwe 
     49       1.1       uwe #include <dev/ic/igsfbreg.h>
     50       1.1       uwe #include <dev/ic/igsfbvar.h>
     51       1.1       uwe 
     52  1.9.20.1      yamt #ifdef IGSFB_DEBUG
     53  1.9.20.1      yamt #define DPRINTF printf
     54  1.9.20.1      yamt #else
     55  1.9.20.1      yamt #define DPRINTF while (0) printf
     56  1.9.20.1      yamt #endif
     57       1.1       uwe 
     58       1.2       uwe static void	igsfb_init_seq(struct igsfb_devconfig *);
     59       1.2       uwe static void	igsfb_init_crtc(struct igsfb_devconfig *);
     60       1.2       uwe static void	igsfb_init_grfx(struct igsfb_devconfig *);
     61       1.2       uwe static void	igsfb_init_attr(struct igsfb_devconfig *);
     62       1.2       uwe static void	igsfb_init_ext(struct igsfb_devconfig *);
     63       1.2       uwe static void	igsfb_init_dac(struct igsfb_devconfig *);
     64       1.1       uwe 
     65       1.2       uwe static void	igsfb_freq_latch(struct igsfb_devconfig *);
     66       1.2       uwe static void	igsfb_video_on(struct igsfb_devconfig *);
     67  1.9.20.1      yamt static void	igsfb_calc_pll(int, int *, int *, int *, int, int, int, int);
     68       1.1       uwe 
     69       1.1       uwe 
     70       1.1       uwe 
     71       1.1       uwe /*
     72       1.1       uwe  * Enable chip.
     73       1.1       uwe  */
     74       1.1       uwe int
     75       1.7       uwe igsfb_enable(bus_space_tag_t iot, bus_addr_t iobase, int ioflags)
     76       1.1       uwe {
     77       1.1       uwe 	bus_space_handle_t vdoh;
     78       1.1       uwe 	bus_space_handle_t vseh;
     79       1.1       uwe 	bus_space_handle_t regh;
     80       1.1       uwe 	int ret;
     81       1.1       uwe 
     82       1.2       uwe 	ret = bus_space_map(iot, iobase + IGS_VDO, 1, ioflags, &vdoh);
     83       1.1       uwe 	if (ret != 0) {
     84       1.1       uwe 		printf("unable to map VDO register\n");
     85       1.1       uwe 		goto out0;
     86       1.1       uwe 	}
     87       1.1       uwe 
     88       1.2       uwe 	ret = bus_space_map(iot, iobase + IGS_VSE, 1, ioflags, &vseh);
     89       1.1       uwe 	if (ret != 0) {
     90       1.1       uwe 		printf("unable to map VSE register\n");
     91       1.1       uwe 		goto out1;
     92       1.1       uwe 	}
     93       1.1       uwe 
     94       1.2       uwe 	ret = bus_space_map(iot, iobase + IGS_REG_BASE, IGS_REG_SIZE, ioflags,
     95       1.2       uwe 			    &regh);
     96       1.1       uwe 	if (ret != 0) {
     97       1.1       uwe 		printf("unable to map I/O registers\n");
     98       1.1       uwe 		goto out2;
     99       1.1       uwe 	}
    100       1.1       uwe 
    101       1.1       uwe 	/*
    102       1.1       uwe 	 * Start decoding i/o space accesses.
    103       1.1       uwe 	 */
    104       1.1       uwe 	bus_space_write_1(iot, vdoh, 0, IGS_VDO_ENABLE | IGS_VDO_SETUP);
    105       1.1       uwe 	bus_space_write_1(iot, vseh, 0, IGS_VSE_ENABLE);
    106       1.1       uwe 	bus_space_write_1(iot, vdoh, 0, IGS_VDO_ENABLE);
    107       1.1       uwe 
    108       1.1       uwe 	/*
    109       1.1       uwe 	 * Start decoding memory space accesses (XXX: move out of here?
    110       1.1       uwe 	 * we program this register in igsfb_init_ext).
    111       1.1       uwe 	 * While here, enable coprocessor and select IGS_COP_BASE_B.
    112       1.1       uwe 	 */
    113       1.1       uwe 	igs_ext_write(iot, regh, IGS_EXT_BIU_MISC_CTL,
    114       1.1       uwe 		      (IGS_EXT_BIU_LINEAREN
    115       1.1       uwe 		       | IGS_EXT_BIU_COPREN | IGS_EXT_BIU_COPASELB));
    116       1.1       uwe 
    117       1.1       uwe 	bus_space_unmap(iot, regh, IGS_REG_SIZE);
    118       1.1       uwe   out2:	bus_space_unmap(iot, vseh, 1);
    119       1.1       uwe   out1:	bus_space_unmap(iot, vdoh, 1);
    120       1.8       uwe   out0: return ret;
    121       1.1       uwe }
    122       1.1       uwe 
    123       1.1       uwe 
    124       1.1       uwe /*
    125       1.1       uwe  * Init sequencer.
    126       1.1       uwe  * This is common for all video modes.
    127       1.1       uwe  */
    128       1.1       uwe static void
    129       1.7       uwe igsfb_init_seq(struct igsfb_devconfig *dc)
    130       1.1       uwe {
    131       1.2       uwe 	bus_space_tag_t iot = dc->dc_iot;
    132       1.2       uwe 	bus_space_handle_t ioh = dc->dc_ioh;
    133       1.1       uwe 
    134       1.1       uwe 	/* start messing with sequencer */
    135       1.1       uwe 	igs_seq_write(iot, ioh, IGS_SEQ_RESET, 0);
    136       1.1       uwe 
    137       1.1       uwe 	igs_seq_write(iot, ioh, 1, 0x01); /* 8 dot clock */
    138       1.1       uwe 	igs_seq_write(iot, ioh, 2, 0x0f); /* enable all maps */
    139       1.1       uwe 	igs_seq_write(iot, ioh, 3, 0x00); /* character generator */
    140       1.1       uwe 	igs_seq_write(iot, ioh, 4, 0x0e); /* memory mode */
    141       1.1       uwe 
    142       1.1       uwe 	/* this selects color mode among other things */
    143       1.1       uwe 	bus_space_write_1(iot, ioh, IGS_MISC_OUTPUT_W, 0xef);
    144       1.1       uwe 
    145       1.1       uwe 	/* normal sequencer operation */
    146       1.1       uwe 	igs_seq_write(iot, ioh, IGS_SEQ_RESET,
    147       1.1       uwe 		      IGS_SEQ_RESET_SYNC | IGS_SEQ_RESET_ASYNC);
    148       1.1       uwe }
    149       1.1       uwe 
    150       1.7       uwe 
    151       1.1       uwe /*
    152       1.1       uwe  * Init CRTC to 640x480 8bpp at 60Hz
    153       1.1       uwe  */
    154       1.1       uwe static void
    155       1.7       uwe igsfb_init_crtc(struct igsfb_devconfig *dc)
    156       1.1       uwe {
    157       1.2       uwe 	bus_space_tag_t iot = dc->dc_iot;
    158       1.2       uwe 	bus_space_handle_t ioh = dc->dc_ioh;
    159       1.1       uwe 
    160       1.1       uwe 	igs_crtc_write(iot, ioh, 0x00, 0x5f);
    161       1.1       uwe 	igs_crtc_write(iot, ioh, 0x01, 0x4f);
    162       1.1       uwe 	igs_crtc_write(iot, ioh, 0x02, 0x50);
    163       1.1       uwe 	igs_crtc_write(iot, ioh, 0x03, 0x80);
    164       1.1       uwe 	igs_crtc_write(iot, ioh, 0x04, 0x52);
    165       1.1       uwe 	igs_crtc_write(iot, ioh, 0x05, 0x9d);
    166       1.1       uwe 	igs_crtc_write(iot, ioh, 0x06, 0x0b);
    167       1.1       uwe 	igs_crtc_write(iot, ioh, 0x07, 0x3e);
    168       1.1       uwe 
    169       1.1       uwe 	/* next block is almost constant, only bit 6 in reg 9 differs */
    170       1.1       uwe 	igs_crtc_write(iot, ioh, 0x08, 0x00);
    171       1.1       uwe 	igs_crtc_write(iot, ioh, 0x09, 0x40); /* <- either 0x40 or 0x60 */
    172       1.1       uwe 	igs_crtc_write(iot, ioh, 0x0a, 0x00);
    173       1.1       uwe 	igs_crtc_write(iot, ioh, 0x0b, 0x00);
    174       1.1       uwe 	igs_crtc_write(iot, ioh, 0x0c, 0x00);
    175       1.1       uwe 	igs_crtc_write(iot, ioh, 0x0d, 0x00);
    176       1.1       uwe 	igs_crtc_write(iot, ioh, 0x0e, 0x00);
    177       1.1       uwe 	igs_crtc_write(iot, ioh, 0x0f, 0x00);
    178       1.1       uwe 
    179       1.1       uwe 	igs_crtc_write(iot, ioh, 0x10, 0xe9);
    180       1.1       uwe 	igs_crtc_write(iot, ioh, 0x11, 0x8b);
    181       1.1       uwe 	igs_crtc_write(iot, ioh, 0x12, 0xdf);
    182       1.1       uwe 	igs_crtc_write(iot, ioh, 0x13, 0x50);
    183       1.1       uwe 	igs_crtc_write(iot, ioh, 0x14, 0x00);
    184       1.1       uwe 	igs_crtc_write(iot, ioh, 0x15, 0xe6);
    185       1.1       uwe 	igs_crtc_write(iot, ioh, 0x16, 0x04);
    186       1.1       uwe 	igs_crtc_write(iot, ioh, 0x17, 0xc3);
    187       1.1       uwe 
    188       1.1       uwe 	igs_crtc_write(iot, ioh, 0x18, 0xff);
    189       1.1       uwe }
    190       1.1       uwe 
    191       1.1       uwe 
    192       1.1       uwe /*
    193       1.1       uwe  * Init graphics controller.
    194       1.1       uwe  * This is common for all video modes.
    195       1.1       uwe  */
    196       1.1       uwe static void
    197       1.7       uwe igsfb_init_grfx(struct igsfb_devconfig *dc)
    198       1.1       uwe {
    199       1.2       uwe 	bus_space_tag_t iot = dc->dc_iot;
    200       1.2       uwe 	bus_space_handle_t ioh = dc->dc_ioh;
    201       1.1       uwe 
    202       1.1       uwe 	igs_grfx_write(iot, ioh, 0, 0x00);
    203       1.1       uwe 	igs_grfx_write(iot, ioh, 1, 0x00);
    204       1.1       uwe 	igs_grfx_write(iot, ioh, 2, 0x00);
    205       1.1       uwe 	igs_grfx_write(iot, ioh, 3, 0x00);
    206       1.1       uwe 	igs_grfx_write(iot, ioh, 4, 0x00);
    207       1.1       uwe 	igs_grfx_write(iot, ioh, 5, 0x60); /* SRMODE, MODE256 */
    208       1.1       uwe 	igs_grfx_write(iot, ioh, 6, 0x05); /* 64k @ a0000, GRAPHICS */
    209       1.1       uwe 	igs_grfx_write(iot, ioh, 7, 0x0f); /* color compare all */
    210       1.1       uwe 	igs_grfx_write(iot, ioh, 8, 0xff); /* bitmask = all bits mutable */
    211       1.1       uwe }
    212       1.1       uwe 
    213       1.1       uwe 
    214       1.1       uwe /*
    215       1.1       uwe  * Init attribute controller.
    216       1.1       uwe  * This is common for all video modes.
    217       1.1       uwe  */
    218       1.1       uwe static void
    219       1.7       uwe igsfb_init_attr(struct igsfb_devconfig *dc)
    220       1.1       uwe {
    221       1.2       uwe 	bus_space_tag_t iot = dc->dc_iot;
    222       1.2       uwe 	bus_space_handle_t ioh = dc->dc_ioh;
    223       1.1       uwe 	int i;
    224       1.1       uwe 
    225       1.1       uwe 	igs_attr_flip_flop(iot, ioh);	/* reset attr flip-flop to address */
    226       1.1       uwe 
    227       1.1       uwe 	for (i = 0; i < 16; ++i)	/* crt palette */
    228       1.1       uwe 		igs_attr_write(iot, ioh, i, i);
    229       1.1       uwe 
    230       1.1       uwe 	igs_attr_write(iot, ioh, 0x10, 0x01); /* select graphic mode */
    231       1.1       uwe 	igs_attr_write(iot, ioh, 0x11, 0x00); /* crt overscan color */
    232       1.1       uwe 	igs_attr_write(iot, ioh, 0x12, 0x0f); /* color plane enable */
    233       1.1       uwe 	igs_attr_write(iot, ioh, 0x13, 0x00);
    234       1.1       uwe 	igs_attr_write(iot, ioh, 0x14, 0x00);
    235       1.1       uwe }
    236       1.1       uwe 
    237       1.1       uwe 
    238       1.1       uwe /*
    239       1.1       uwe  * When done with ATTR controller, call this to unblank the screen.
    240       1.1       uwe  */
    241       1.1       uwe static void
    242       1.7       uwe igsfb_video_on(struct igsfb_devconfig *dc)
    243       1.1       uwe {
    244       1.2       uwe 	bus_space_tag_t iot = dc->dc_iot;
    245       1.2       uwe 	bus_space_handle_t ioh = dc->dc_ioh;
    246       1.1       uwe 
    247       1.1       uwe 	igs_attr_flip_flop(iot, ioh);
    248       1.1       uwe 	bus_space_write_1(iot, ioh, IGS_ATTR_IDX, 0x20);
    249       1.1       uwe 	bus_space_write_1(iot, ioh, IGS_ATTR_IDX, 0x20);
    250       1.1       uwe }
    251       1.1       uwe 
    252       1.1       uwe 
    253       1.1       uwe /*
    254       1.1       uwe  * Latch VCLK (b0/b1) and MCLK (b2/b3) values.
    255       1.1       uwe  */
    256       1.1       uwe static void
    257       1.7       uwe igsfb_freq_latch(struct igsfb_devconfig *dc)
    258       1.1       uwe {
    259       1.2       uwe 	bus_space_tag_t iot = dc->dc_iot;
    260       1.2       uwe 	bus_space_handle_t ioh = dc->dc_ioh;
    261       1.1       uwe 
    262       1.1       uwe 	bus_space_write_1(iot, ioh, IGS_EXT_IDX, 0xb9);
    263       1.1       uwe 	bus_space_write_1(iot, ioh, IGS_EXT_PORT, 0x80);
    264       1.1       uwe 	bus_space_write_1(iot, ioh, IGS_EXT_PORT, 0x00);
    265       1.1       uwe }
    266       1.1       uwe 
    267       1.1       uwe 
    268       1.1       uwe static void
    269       1.7       uwe igsfb_init_ext(struct igsfb_devconfig *dc)
    270       1.1       uwe {
    271       1.2       uwe 	bus_space_tag_t iot = dc->dc_iot;
    272       1.2       uwe 	bus_space_handle_t ioh = dc->dc_ioh;
    273       1.2       uwe 	int is_cyberpro = (dc->dc_id >= 0x2000);
    274       1.1       uwe 
    275       1.1       uwe 	igs_ext_write(iot, ioh, 0x10, 0x10); /* IGS_EXT_START_ADDR enable */
    276       1.1       uwe 	igs_ext_write(iot, ioh, 0x12, 0x00); /* IGS_EXT_IRQ_CTL disable  */
    277       1.1       uwe 	igs_ext_write(iot, ioh, 0x13, 0x00); /* MBZ for normal operation */
    278       1.1       uwe 
    279       1.1       uwe 	igs_ext_write(iot, ioh, 0x31, 0x00); /* segment write ptr */
    280       1.1       uwe 	igs_ext_write(iot, ioh, 0x32, 0x00); /* segment read ptr */
    281       1.1       uwe 
    282       1.3       uwe 	/* IGS_EXT_BIU_MISC_CTL: linearen, copren, copaselb, segon */
    283       1.3       uwe 	igs_ext_write(iot, ioh, 0x33, 0x1d);
    284       1.1       uwe 
    285       1.1       uwe 	/* sprite location */
    286       1.1       uwe 	igs_ext_write(iot, ioh, 0x50, 0x00);
    287       1.1       uwe 	igs_ext_write(iot, ioh, 0x51, 0x00);
    288       1.1       uwe 	igs_ext_write(iot, ioh, 0x52, 0x00);
    289       1.1       uwe 	igs_ext_write(iot, ioh, 0x53, 0x00);
    290       1.1       uwe 	igs_ext_write(iot, ioh, 0x54, 0x00);
    291       1.1       uwe 	igs_ext_write(iot, ioh, 0x55, 0x00);
    292       1.1       uwe 	igs_ext_write(iot, ioh, 0x56, 0x00); /* sprite control */
    293       1.1       uwe 
    294       1.1       uwe 	/* IGS_EXT_GRFX_MODE */
    295       1.1       uwe 	igs_ext_write(iot, ioh, 0x57, 0x01); /* raster fb */
    296       1.1       uwe 
    297       1.1       uwe 	/* overscan R/G/B */
    298       1.1       uwe 	igs_ext_write(iot, ioh, 0x58, 0x00);
    299       1.1       uwe 	igs_ext_write(iot, ioh, 0x59, 0x00);
    300       1.1       uwe 	igs_ext_write(iot, ioh, 0x5A, 0x00);
    301       1.1       uwe 
    302       1.1       uwe 	/*
    303       1.1       uwe 	 * Video memory size &c.  We rely on firmware to program
    304       1.1       uwe 	 * BUS_CTL(30), MEM_CTL1(71), MEM_CTL2(72) appropriately.
    305       1.1       uwe 	 */
    306       1.1       uwe 
    307       1.1       uwe 	/* ext memory ctl0 */
    308       1.1       uwe 	igs_ext_write(iot, ioh, 0x70, 0x0B); /* enable fifo, seq */
    309       1.1       uwe 
    310       1.1       uwe 	/* ext hidden ctl1 */
    311       1.1       uwe 	igs_ext_write(iot, ioh, 0x73, 0x30); /* XXX: krups: 0x20 */
    312       1.1       uwe 
    313       1.1       uwe 	/* ext fifo control */
    314       1.1       uwe 	igs_ext_write(iot, ioh, 0x74, 0x10); /* XXX: krups: 0x1b */
    315       1.1       uwe 	igs_ext_write(iot, ioh, 0x75, 0x10); /* XXX: krups: 0x1e */
    316       1.1       uwe 
    317       1.1       uwe 	igs_ext_write(iot, ioh, 0x76, 0x00); /* ext seq. */
    318       1.1       uwe 	igs_ext_write(iot, ioh, 0x7A, 0xC8); /* ext. hidden ctl */
    319       1.1       uwe 
    320       1.1       uwe 	/* ext graphics ctl: GCEXTPATH.  krups 1, nettrom 1, docs 3 */
    321       1.1       uwe 	igs_ext_write(iot, ioh, 0x90, 0x01);
    322       1.1       uwe 
    323       1.2       uwe 	if (is_cyberpro)	/* select normal vclk/mclk registers */
    324       1.1       uwe 	    igs_ext_write(iot, ioh, 0xBF, 0x00);
    325       1.1       uwe 
    326       1.1       uwe 	igs_ext_write(iot, ioh, 0xB0, 0xD2); /* VCLK = 25.175MHz */
    327       1.1       uwe 	igs_ext_write(iot, ioh, 0xB1, 0xD3);
    328       1.1       uwe 	igs_ext_write(iot, ioh, 0xB2, 0xDB); /* MCLK = 75MHz*/
    329       1.1       uwe 	igs_ext_write(iot, ioh, 0xB3, 0x54);
    330       1.2       uwe 	igsfb_freq_latch(dc);
    331       1.1       uwe 
    332       1.2       uwe 	if (is_cyberpro)
    333       1.1       uwe 	    igs_ext_write(iot, ioh, 0xF8, 0x04); /* XXX: ??? */
    334       1.1       uwe 
    335       1.1       uwe 	/* 640x480 8bpp at 60Hz */
    336       1.1       uwe 	igs_ext_write(iot, ioh, 0x11, 0x00);
    337       1.1       uwe 	igs_ext_write(iot, ioh, 0x77, 0x01); /* 8bpp, indexed */
    338       1.1       uwe 	igs_ext_write(iot, ioh, 0x14, 0x51);
    339       1.1       uwe 	igs_ext_write(iot, ioh, 0x15, 0x00);
    340       1.1       uwe }
    341       1.1       uwe 
    342       1.1       uwe 
    343       1.1       uwe static void
    344       1.7       uwe igsfb_init_dac(struct igsfb_devconfig *dc)
    345       1.1       uwe {
    346       1.2       uwe 	bus_space_tag_t iot = dc->dc_iot;
    347       1.2       uwe 	bus_space_handle_t ioh = dc->dc_ioh;
    348       1.4       uwe 	uint8_t reg;
    349       1.1       uwe 
    350       1.1       uwe 	/* RAMDAC address 2 select */
    351       1.1       uwe 	reg = igs_ext_read(iot, ioh, IGS_EXT_SPRITE_CTL);
    352       1.1       uwe 	igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL,
    353       1.1       uwe 		      reg | IGS_EXT_SPRITE_DAC_PEL);
    354       1.1       uwe 
    355       1.1       uwe 	/* VREFEN, DAC8 */
    356       1.1       uwe 	bus_space_write_1(iot, ioh, IGS_DAC_CMD, 0x06);
    357       1.1       uwe 
    358       1.1       uwe 	/* restore */
    359       1.1       uwe 	igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL, reg);
    360       1.1       uwe 
    361       1.1       uwe 	bus_space_write_1(iot, ioh, IGS_PEL_MASK, 0xff);
    362       1.1       uwe }
    363       1.1       uwe 
    364       1.1       uwe 
    365       1.1       uwe void
    366       1.7       uwe igsfb_1024x768_8bpp_60Hz(struct igsfb_devconfig *dc)
    367       1.1       uwe {
    368       1.2       uwe 	bus_space_tag_t iot = dc->dc_iot;
    369       1.2       uwe 	bus_space_handle_t ioh = dc->dc_ioh;
    370       1.1       uwe 
    371       1.1       uwe 	igs_crtc_write(iot, ioh, 0x11, 0x00); /* write enable CRTC 0..7 */
    372       1.1       uwe 
    373       1.1       uwe 	igs_crtc_write(iot, ioh, 0x00, 0xa3);
    374       1.1       uwe 	igs_crtc_write(iot, ioh, 0x01, 0x7f);
    375       1.1       uwe 	igs_crtc_write(iot, ioh, 0x02, 0x7f); /* krups: 80 */
    376       1.1       uwe 	igs_crtc_write(iot, ioh, 0x03, 0x85); /* krups: 84 */
    377       1.1       uwe 	igs_crtc_write(iot, ioh, 0x04, 0x84); /* krups: 88 */
    378       1.1       uwe 	igs_crtc_write(iot, ioh, 0x05, 0x95); /* krups: 99 */
    379       1.1       uwe 	igs_crtc_write(iot, ioh, 0x06, 0x24);
    380       1.1       uwe 	igs_crtc_write(iot, ioh, 0x07, 0xfd);
    381       1.1       uwe 
    382       1.1       uwe 	/* next block is almost constant, only bit 6 in reg 9 differs */
    383       1.1       uwe 	igs_crtc_write(iot, ioh, 0x08, 0x00);
    384       1.1       uwe 	igs_crtc_write(iot, ioh, 0x09, 0x60); /* <- either 0x40 or 0x60 */
    385       1.1       uwe 	igs_crtc_write(iot, ioh, 0x0a, 0x00);
    386       1.1       uwe 	igs_crtc_write(iot, ioh, 0x0b, 0x00);
    387       1.1       uwe 	igs_crtc_write(iot, ioh, 0x0c, 0x00);
    388       1.1       uwe 	igs_crtc_write(iot, ioh, 0x0d, 0x00);
    389       1.1       uwe 	igs_crtc_write(iot, ioh, 0x0e, 0x00);
    390       1.1       uwe 	igs_crtc_write(iot, ioh, 0x0f, 0x00);
    391       1.1       uwe 
    392       1.1       uwe 	igs_crtc_write(iot, ioh, 0x10, 0x06);
    393       1.1       uwe 	igs_crtc_write(iot, ioh, 0x11, 0x8c);
    394       1.1       uwe 	igs_crtc_write(iot, ioh, 0x12, 0xff);
    395       1.1       uwe 	igs_crtc_write(iot, ioh, 0x13, 0x80); /* depends on BPP */
    396       1.1       uwe 	igs_crtc_write(iot, ioh, 0x14, 0x0f);
    397       1.1       uwe 	igs_crtc_write(iot, ioh, 0x15, 0x02);
    398       1.1       uwe 	igs_crtc_write(iot, ioh, 0x16, 0x21);
    399       1.1       uwe 	igs_crtc_write(iot, ioh, 0x17, 0xe3);
    400       1.1       uwe 	igs_crtc_write(iot, ioh, 0x18, 0xff);
    401       1.1       uwe 
    402       1.1       uwe 	igs_ext_write(iot, ioh, 0xB0, 0xE2); /* VCLK */
    403       1.1       uwe 	igs_ext_write(iot, ioh, 0xB1, 0x58);
    404       1.1       uwe #if 1
    405       1.1       uwe 	/* XXX: hmm, krups does this */
    406       1.1       uwe 	igs_ext_write(iot, ioh, 0xB2, 0xE2); /* MCLK */
    407       1.1       uwe 	igs_ext_write(iot, ioh, 0xB3, 0x58);
    408       1.1       uwe #endif
    409       1.2       uwe 	igsfb_freq_latch(dc);
    410       1.1       uwe 
    411       1.1       uwe 	igs_ext_write(iot, ioh, 0x11, 0x00);
    412       1.1       uwe 	igs_ext_write(iot, ioh, 0x77, 0x01); /* 8bpp, indexed */
    413       1.1       uwe 	igs_ext_write(iot, ioh, 0x14, 0x81);
    414       1.1       uwe 	igs_ext_write(iot, ioh, 0x15, 0x00);
    415  1.9.20.1      yamt 
    416  1.9.20.1      yamt 	dc->dc_width = 1024;
    417  1.9.20.1      yamt 	dc->dc_height = 768;
    418  1.9.20.1      yamt 	dc->dc_depth = 8;
    419  1.9.20.1      yamt 	dc->dc_stride = dc->dc_width;
    420       1.1       uwe }
    421       1.1       uwe 
    422       1.1       uwe 
    423       1.1       uwe /*
    424       1.1       uwe  * igs-video-init from krups prom
    425       1.1       uwe  */
    426       1.1       uwe void
    427       1.7       uwe igsfb_hw_setup(struct igsfb_devconfig *dc)
    428       1.1       uwe {
    429  1.9.20.1      yamt 	const struct videomode *mode = NULL;
    430  1.9.20.1      yamt 	int i, size, d;
    431       1.1       uwe 
    432       1.2       uwe 	igsfb_init_seq(dc);
    433       1.2       uwe 	igsfb_init_crtc(dc);
    434       1.2       uwe 	igsfb_init_attr(dc);
    435       1.2       uwe 	igsfb_init_grfx(dc);
    436       1.2       uwe 	igsfb_init_ext(dc);
    437       1.2       uwe 	igsfb_init_dac(dc);
    438       1.1       uwe 
    439  1.9.20.1      yamt 	i = 0;
    440  1.9.20.1      yamt 	while ((strcmp(dc->dc_modestring, videomode_list[i].name) != 0) &&
    441  1.9.20.1      yamt 	       ( i < videomode_count)) {
    442  1.9.20.1      yamt 		i++;
    443  1.9.20.1      yamt 	}
    444  1.9.20.1      yamt 
    445  1.9.20.1      yamt 	if (i < videomode_count) {
    446  1.9.20.1      yamt 		size = videomode_list[i].hdisplay * videomode_list[i].vdisplay;
    447  1.9.20.1      yamt 		/* found a mode, now let's see if we can display it */
    448  1.9.20.1      yamt 		if ((videomode_list[i].dot_clock <= IGS_MAX_CLOCK) &&
    449  1.9.20.1      yamt 		    (videomode_list[i].hdisplay <= 2048) &&
    450  1.9.20.1      yamt 		    (videomode_list[i].hdisplay >= 320) &&
    451  1.9.20.1      yamt 		    (videomode_list[i].vdisplay <= 2048) &&
    452  1.9.20.1      yamt 		    (videomode_list[i].vdisplay >= 200) &&
    453  1.9.20.1      yamt 		    (size <= (dc->dc_memsz - 0x1000))) {
    454  1.9.20.1      yamt 		 	mode = &videomode_list[i];
    455  1.9.20.1      yamt 			/*
    456  1.9.20.1      yamt 			 * now let's see which maximum depth we can support
    457  1.9.20.1      yamt 			 * in that mode
    458  1.9.20.1      yamt 			 */
    459  1.9.20.1      yamt 			d = (dc->dc_vmemsz - 0x1000) / size;
    460  1.9.20.1      yamt 			if (d >= 4) {
    461  1.9.20.1      yamt 				dc->dc_maxdepth = 32;
    462  1.9.20.1      yamt 			} else if (d >= 2) {
    463  1.9.20.1      yamt 				dc->dc_maxdepth = 16;
    464  1.9.20.1      yamt 			} else
    465  1.9.20.1      yamt 				dc->dc_maxdepth = 8;
    466  1.9.20.1      yamt 		}
    467  1.9.20.1      yamt 	}
    468  1.9.20.1      yamt 	dc->dc_mode = mode;
    469  1.9.20.1      yamt 
    470  1.9.20.1      yamt 	if (mode != NULL) {
    471  1.9.20.1      yamt 		igsfb_set_mode(dc, mode, 8);
    472  1.9.20.1      yamt 	} else {
    473  1.9.20.1      yamt 		igsfb_1024x768_8bpp_60Hz(dc);
    474  1.9.20.1      yamt 		dc->dc_maxdepth = 8;
    475  1.9.20.1      yamt 	}
    476  1.9.20.1      yamt 
    477  1.9.20.1      yamt 	igsfb_video_on(dc);
    478  1.9.20.1      yamt }
    479  1.9.20.1      yamt 
    480  1.9.20.1      yamt void
    481  1.9.20.1      yamt igsfb_set_mode(struct igsfb_devconfig *dc, const struct videomode *mode,
    482  1.9.20.1      yamt     int depth)
    483  1.9.20.1      yamt {
    484  1.9.20.1      yamt 	bus_space_tag_t iot = dc->dc_iot;
    485  1.9.20.1      yamt 	bus_space_handle_t ioh = dc->dc_ioh;
    486  1.9.20.1      yamt 	int i, m, n, p, hoffset, bytes_per_pixel, memfetch;
    487  1.9.20.1      yamt 	int vsync_start, hsync_start, vsync_end, hsync_end;
    488  1.9.20.1      yamt 	int vblank_start, vblank_end, hblank_start, hblank_end;
    489  1.9.20.1      yamt 	int croffset;
    490  1.9.20.1      yamt 	uint8_t vclk1, vclk2, vclk3, overflow, reg, seq_mode;
    491  1.9.20.1      yamt 
    492  1.9.20.1      yamt 	switch (depth) {
    493  1.9.20.1      yamt 		case 8:
    494  1.9.20.1      yamt 			seq_mode = IGS_EXT_SEQ_8BPP;
    495  1.9.20.1      yamt 			break;
    496  1.9.20.1      yamt 		case 15:
    497  1.9.20.1      yamt 			seq_mode = IGS_EXT_SEQ_15BPP; /* 5-5-5 */
    498  1.9.20.1      yamt 			break;
    499  1.9.20.1      yamt 		case 16:
    500  1.9.20.1      yamt 			seq_mode = IGS_EXT_SEQ_16BPP; /* 5-6-5 */
    501  1.9.20.1      yamt 			break;
    502  1.9.20.1      yamt 		case 24:
    503  1.9.20.1      yamt 			seq_mode = IGS_EXT_SEQ_24BPP; /* 8-8-8 */
    504  1.9.20.1      yamt 			break;
    505  1.9.20.1      yamt 		case 32:
    506  1.9.20.1      yamt 			seq_mode = IGS_EXT_SEQ_32BPP;
    507  1.9.20.1      yamt 			break;
    508  1.9.20.1      yamt 		default:
    509  1.9.20.1      yamt 			aprint_error("igsfb: unsupported depth (%d), reverting"
    510  1.9.20.1      yamt 				     " to 8 bit\n", depth);
    511  1.9.20.1      yamt 			depth = 8;
    512  1.9.20.1      yamt 			seq_mode = IGS_EXT_SEQ_8BPP;
    513  1.9.20.1      yamt 	}
    514  1.9.20.1      yamt 	bytes_per_pixel = depth >> 3;
    515  1.9.20.1      yamt 
    516  1.9.20.1      yamt 	hoffset = (mode->hdisplay >> 3) * bytes_per_pixel;
    517  1.9.20.1      yamt 	memfetch = hoffset + 1;
    518  1.9.20.1      yamt 	overflow = (((mode->vtotal - 2) & 0x400) >> 10) |
    519  1.9.20.1      yamt 	    (((mode->vdisplay -1) & 0x400) >> 9) |
    520  1.9.20.1      yamt 	    ((mode->vsync_start & 0x400) >> 8) |
    521  1.9.20.1      yamt 	    ((mode->vsync_start & 0x400) >> 7) |
    522  1.9.20.1      yamt 	    0x10;
    523  1.9.20.1      yamt 
    524  1.9.20.1      yamt 	/* RAMDAC address 2 select */
    525  1.9.20.1      yamt 	reg = igs_ext_read(iot, ioh, IGS_EXT_SPRITE_CTL);
    526  1.9.20.1      yamt 	igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL,
    527  1.9.20.1      yamt 		      reg | IGS_EXT_SPRITE_DAC_PEL);
    528  1.9.20.1      yamt 
    529  1.9.20.1      yamt 	if (depth == 8) {
    530  1.9.20.1      yamt 		/* palette mode */
    531  1.9.20.1      yamt 		bus_space_write_1(dc->dc_iot, dc->dc_ioh, IGS_DAC_CMD, 0x06);
    532  1.9.20.1      yamt 	} else {
    533  1.9.20.1      yamt 		/* bypass palette */
    534  1.9.20.1      yamt 		bus_space_write_1(dc->dc_iot, dc->dc_ioh, IGS_DAC_CMD, 0x16);
    535  1.9.20.1      yamt 	}
    536  1.9.20.1      yamt 	/* restore */
    537  1.9.20.1      yamt 	igs_ext_write(iot, ioh, IGS_EXT_SPRITE_CTL, reg);
    538  1.9.20.1      yamt 
    539  1.9.20.1      yamt 	bus_space_write_1(iot, ioh, IGS_PEL_MASK, 0xff);
    540  1.9.20.1      yamt 
    541  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x11, 0x00); /* write enable CRTC 0..7 */
    542  1.9.20.1      yamt 
    543  1.9.20.1      yamt 	hsync_start = mode->hsync_start;
    544  1.9.20.1      yamt 	hsync_end = mode->hsync_end;
    545  1.9.20.1      yamt 
    546  1.9.20.1      yamt 	hblank_start = min(mode->hsync_start, mode->hdisplay);
    547  1.9.20.1      yamt 	hblank_end = hsync_end;
    548  1.9.20.1      yamt 	if ((hblank_end - hblank_start) >= 63 * 8) {
    549  1.9.20.1      yamt 
    550  1.9.20.1      yamt 		/*
    551  1.9.20.1      yamt 		 * H Blanking size must be < 63*8. Same remark as above.
    552  1.9.20.1      yamt 		 */
    553  1.9.20.1      yamt 		hblank_start = hblank_end - 63 * 8;
    554  1.9.20.1      yamt 	}
    555  1.9.20.1      yamt 
    556  1.9.20.1      yamt 	vblank_start = min(mode->vsync_start, mode->vdisplay);
    557  1.9.20.1      yamt 	vblank_end = mode->vsync_end;
    558  1.9.20.1      yamt 
    559  1.9.20.1      yamt 	vsync_start = mode->vsync_start;
    560  1.9.20.1      yamt 	vsync_end = mode->vsync_end;
    561  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x00, (mode->htotal >> 3) - 5);
    562  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x01, (mode->hdisplay >> 3) - 1);
    563  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x02, (hblank_start >> 3) - 1);
    564  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x03, 0x80 | (((hblank_end >> 3) - 1) & 0x1f));
    565  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x04, hsync_start >> 3);
    566  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x05, ((((hblank_end >> 3) - 1)  & 0x20) << 2)
    567  1.9.20.1      yamt 	    | ((hsync_end >> 3) & 0x1f));
    568  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x06, (mode->vtotal - 2) & 0xff);
    569  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x07,
    570  1.9.20.1      yamt 	    ((vsync_start & 0x200) >> 2) |
    571  1.9.20.1      yamt 	    (((mode->vdisplay - 1) & 0x200) >> 3) |
    572  1.9.20.1      yamt 	    (((mode->vtotal - 2) & 0x200) >> 4) |
    573  1.9.20.1      yamt 	    0x10 |
    574  1.9.20.1      yamt 	    (((vblank_start - 1) & 0x100) >> 5) |
    575  1.9.20.1      yamt 	    ((vsync_start  & 0x100) >> 6) |
    576  1.9.20.1      yamt 	    (((mode->vdisplay - 1)  & 0x100) >> 7) |
    577  1.9.20.1      yamt 	    ((mode->vtotal  & 0x100) >> 8));
    578  1.9.20.1      yamt 
    579  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x08, 0x00);
    580  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x09, 0x40 |
    581  1.9.20.1      yamt 	    (((vblank_start - 1) & 0x200) >> 4));
    582  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x0a, 0x00);
    583  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x0b, 0x00);
    584  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x0c, 0x00);
    585  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x0d, 0x00);
    586  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x0e, 0x00);
    587  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x0f, 0x00);
    588  1.9.20.1      yamt 
    589  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x10, vsync_start & 0xff);
    590  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x11, (vsync_end & 0x0f) | 0x20);
    591  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x12, (mode->vdisplay - 1) & 0xff);
    592  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x13, hoffset & 0xff);
    593  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x14, 0x0f);
    594  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x15, (vblank_start - 1) & 0xff);
    595  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x16, (vblank_end - 1) & 0xff);
    596  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x17, 0xe3);
    597  1.9.20.1      yamt 	igs_crtc_write(iot, ioh, 0x18, 0xff);
    598  1.9.20.1      yamt 
    599  1.9.20.1      yamt 	for (i = 0; i < 0x10; i++)
    600  1.9.20.1      yamt 		igs_attr_write(iot, ioh, i, i);
    601  1.9.20.1      yamt 
    602  1.9.20.1      yamt 	igs_attr_write(iot, ioh, 0x10, 0x01);
    603  1.9.20.1      yamt 	igs_attr_write(iot, ioh, 0x11, 0x00);
    604  1.9.20.1      yamt 	igs_attr_write(iot, ioh, 0x12, 0x0f);
    605  1.9.20.1      yamt 	igs_attr_write(iot, ioh, 0x13, 0x00);
    606  1.9.20.1      yamt 
    607  1.9.20.1      yamt 	igs_grfx_write(iot, ioh, 0x00, 0x00);
    608  1.9.20.1      yamt 	igs_grfx_write(iot, ioh, 0x01, 0x00);
    609  1.9.20.1      yamt 	igs_grfx_write(iot, ioh, 0x02, 0x00);
    610  1.9.20.1      yamt 	igs_grfx_write(iot, ioh, 0x03, 0x00);
    611  1.9.20.1      yamt 	igs_grfx_write(iot, ioh, 0x04, 0x00);
    612  1.9.20.1      yamt 	igs_grfx_write(iot, ioh, 0x05, 0x60);
    613  1.9.20.1      yamt 	igs_grfx_write(iot, ioh, 0x06, 0x05);
    614  1.9.20.1      yamt 	igs_grfx_write(iot, ioh, 0x07, 0x0f);
    615  1.9.20.1      yamt 	igs_grfx_write(iot, ioh, 0x08, 0xff);
    616  1.9.20.1      yamt 
    617  1.9.20.1      yamt 	/* crank up memory clock to 95MHz - needed for higher resolutions */
    618  1.9.20.1      yamt 	igs_ext_write(iot, ioh, IGS_EXT_MCLK0, 0x91);
    619  1.9.20.1      yamt 	igs_ext_write(iot, ioh, IGS_EXT_MCLK1, 0x6a);
    620  1.9.20.1      yamt 	igsfb_freq_latch(dc);
    621  1.9.20.1      yamt 
    622  1.9.20.1      yamt 	igs_ext_write(iot, ioh, IGS_EXT_VOVFL, overflow);
    623  1.9.20.1      yamt 	igs_ext_write(iot, ioh, IGS_EXT_SEQ_MISC, seq_mode);
    624  1.9.20.1      yamt 	igs_ext_write(iot, ioh, 0x14, memfetch & 0xff);
    625  1.9.20.1      yamt 	igs_ext_write(iot, ioh, 0x15,
    626  1.9.20.1      yamt 	    ((memfetch & 0x300) >> 8) | ((hoffset & 0x300) >> 4));
    627  1.9.20.1      yamt 
    628  1.9.20.1      yamt 	/* finally set the dot clock */
    629  1.9.20.1      yamt 	igsfb_calc_pll(mode->dot_clock, &m, &n, &p, 2047, 255, 7, IGS_MIN_VCO);
    630  1.9.20.1      yamt 	DPRINTF("m: %x, n: %x, p: %x\n", m, n, p);
    631  1.9.20.1      yamt 	vclk1 = m & 0xff;
    632  1.9.20.1      yamt 	vclk2 = (n & 0x1f) | ((p << 6) & 0xc0) |
    633  1.9.20.1      yamt 	    (mode->dot_clock > 180000 ? 0x20 : 0);
    634  1.9.20.1      yamt 	vclk3 = ((m >> 8) & 0x7) | ((n >> 2) & 0x38) | ((p << 4) & 0x40);
    635  1.9.20.1      yamt 	DPRINTF("clk: %02x %02x %02x\n", vclk1, vclk2, vclk3);
    636  1.9.20.1      yamt 	igs_ext_write(iot, ioh, IGS_EXT_VCLK0, vclk1);
    637  1.9.20.1      yamt 	igs_ext_write(iot, ioh, IGS_EXT_VCLK1, vclk2);
    638  1.9.20.1      yamt 	igs_ext_write(iot, ioh, 0xBA, vclk3);
    639  1.9.20.1      yamt 	igsfb_freq_latch(dc);
    640  1.9.20.1      yamt 	DPRINTF("clock: %d\n", IGS_CLOCK(m, n, p));
    641  1.9.20.1      yamt 
    642  1.9.20.1      yamt 	if (dc->dc_id > 0x2000) {
    643  1.9.20.1      yamt 		/* we have a blitter, so configure it as well */
    644  1.9.20.1      yamt 		bus_space_write_1(dc->dc_iot, dc->dc_coph, IGS_COP_MAP_FMT_REG,
    645  1.9.20.1      yamt 		    bytes_per_pixel - 1);
    646  1.9.20.1      yamt 		bus_space_write_2(dc->dc_iot, dc->dc_coph,
    647  1.9.20.1      yamt 		    IGS_COP_SRC_MAP_WIDTH_REG, dc->dc_width - 1);
    648  1.9.20.1      yamt 		bus_space_write_2(dc->dc_iot, dc->dc_coph,
    649  1.9.20.1      yamt 		    IGS_COP_DST_MAP_WIDTH_REG, dc->dc_width - 1);
    650  1.9.20.1      yamt 	}
    651  1.9.20.1      yamt 
    652  1.9.20.1      yamt 	/* re-init the cursor data address too */
    653  1.9.20.1      yamt 	croffset = dc->dc_vmemsz - IGS_CURSOR_DATA_SIZE;
    654  1.9.20.1      yamt 	croffset >>= 10;	/* bytes -> kilobytes */
    655  1.9.20.1      yamt 	igs_ext_write(dc->dc_iot, dc->dc_ioh,
    656  1.9.20.1      yamt 		      IGS_EXT_SPRITE_DATA_LO, croffset & 0xff);
    657  1.9.20.1      yamt 	igs_ext_write(dc->dc_iot, dc->dc_ioh,
    658  1.9.20.1      yamt 		      IGS_EXT_SPRITE_DATA_HI, (croffset >> 8) & 0xf);
    659  1.9.20.1      yamt 
    660  1.9.20.1      yamt 	dc->dc_width = mode->hdisplay;
    661  1.9.20.1      yamt 	dc->dc_height = mode->vdisplay;
    662  1.9.20.1      yamt 	dc->dc_depth = depth;
    663  1.9.20.1      yamt 	dc->dc_stride = dc->dc_width * (depth >> 3);
    664  1.9.20.1      yamt 
    665       1.2       uwe 	igsfb_video_on(dc);
    666       1.1       uwe }
    667  1.9.20.1      yamt 
    668  1.9.20.1      yamt 
    669  1.9.20.1      yamt static void
    670  1.9.20.1      yamt igsfb_calc_pll(int target, int *Mp, int *Np, int *Pp, int maxM, int maxN,
    671  1.9.20.1      yamt     int maxP, int minVco)
    672  1.9.20.1      yamt {
    673  1.9.20.1      yamt     int	    M, N, P, bestM = 0, bestN = 0;
    674  1.9.20.1      yamt     int	    f_vco, f_out;
    675  1.9.20.1      yamt     int	    err, besterr;
    676  1.9.20.1      yamt 
    677  1.9.20.1      yamt     /*
    678  1.9.20.1      yamt      * Compute correct P value to keep VCO in range
    679  1.9.20.1      yamt      */
    680  1.9.20.1      yamt     for (P = 0; P <= maxP; P++)
    681  1.9.20.1      yamt     {
    682  1.9.20.1      yamt 	f_vco = target * IGS_SCALE(P);
    683  1.9.20.1      yamt 	if (f_vco >= minVco)
    684  1.9.20.1      yamt 	    break;
    685  1.9.20.1      yamt     }
    686  1.9.20.1      yamt 
    687  1.9.20.1      yamt     /* M = f_out / f_ref * ((N + 1) * IGS_SCALE(P)); */
    688  1.9.20.1      yamt     besterr = target;
    689  1.9.20.1      yamt     for (N = 1; N <= maxN; N++)
    690  1.9.20.1      yamt     {
    691  1.9.20.1      yamt 	M = ((target * (N + 1) * IGS_SCALE(P) + (IGS_CLOCK_REF/2)) +
    692  1.9.20.1      yamt 	    IGS_CLOCK_REF/2) / IGS_CLOCK_REF - 1;
    693  1.9.20.1      yamt 	if (0 <= M && M <= maxM)
    694  1.9.20.1      yamt 	{
    695  1.9.20.1      yamt 	    f_out = IGS_CLOCK(M,N,P);
    696  1.9.20.1      yamt 	    err = target - f_out;
    697  1.9.20.1      yamt 	    if (err < 0)
    698  1.9.20.1      yamt 		err = -err;
    699  1.9.20.1      yamt 	    if (err < besterr)
    700  1.9.20.1      yamt 	    {
    701  1.9.20.1      yamt 		besterr = err;
    702  1.9.20.1      yamt 		bestM = M;
    703  1.9.20.1      yamt 		bestN = N;
    704  1.9.20.1      yamt 	    }
    705  1.9.20.1      yamt 	}
    706  1.9.20.1      yamt     }
    707  1.9.20.1      yamt     *Mp = bestM;
    708  1.9.20.1      yamt     *Np = bestN;
    709  1.9.20.1      yamt     *Pp = P;
    710  1.9.20.1      yamt }
    711