Home | History | Annotate | Line # | Download | only in dev
crmfb.c revision 1.31
      1  1.31  macallan /* $NetBSD: crmfb.c,v 1.31 2011/04/04 22:50:36 macallan Exp $ */
      2   1.1  jmcneill 
      3   1.1  jmcneill /*-
      4   1.1  jmcneill  * Copyright (c) 2007 Jared D. McNeill <jmcneill (at) invisible.ca>
      5  1.12  macallan  *               2008 Michael Lorenz <macallan (at) netbsd.org>
      6   1.1  jmcneill  * All rights reserved.
      7   1.1  jmcneill  *
      8   1.1  jmcneill  * Redistribution and use in source and binary forms, with or without
      9   1.1  jmcneill  * modification, are permitted provided that the following conditions
     10   1.1  jmcneill  * are met:
     11   1.1  jmcneill  * 1. Redistributions of source code must retain the above copyright
     12   1.1  jmcneill  *    notice, this list of conditions and the following disclaimer.
     13   1.1  jmcneill  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1  jmcneill  *    notice, this list of conditions and the following disclaimer in the
     15   1.1  jmcneill  *    documentation and/or other materials provided with the distribution.
     16   1.1  jmcneill  *
     17   1.1  jmcneill  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     18   1.1  jmcneill  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     19   1.1  jmcneill  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     20   1.1  jmcneill  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     21   1.1  jmcneill  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     22   1.1  jmcneill  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     23   1.1  jmcneill  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     24   1.1  jmcneill  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     25   1.1  jmcneill  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     26   1.1  jmcneill  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     27   1.1  jmcneill  * POSSIBILITY OF SUCH DAMAGE.
     28   1.1  jmcneill  */
     29   1.1  jmcneill 
     30   1.1  jmcneill /*
     31   1.1  jmcneill  * SGI-CRM (O2) Framebuffer driver
     32   1.1  jmcneill  */
     33   1.1  jmcneill 
     34   1.1  jmcneill #include <sys/cdefs.h>
     35  1.31  macallan __KERNEL_RCSID(0, "$NetBSD: crmfb.c,v 1.31 2011/04/04 22:50:36 macallan Exp $");
     36   1.1  jmcneill 
     37   1.1  jmcneill #include <sys/param.h>
     38   1.1  jmcneill #include <sys/systm.h>
     39   1.1  jmcneill #include <sys/device.h>
     40   1.1  jmcneill #include <sys/malloc.h>
     41   1.1  jmcneill 
     42   1.1  jmcneill #define _SGIMIPS_BUS_DMA_PRIVATE
     43   1.1  jmcneill #include <machine/autoconf.h>
     44   1.1  jmcneill #include <machine/bus.h>
     45   1.1  jmcneill #include <machine/machtype.h>
     46   1.1  jmcneill #include <machine/vmparam.h>
     47   1.1  jmcneill 
     48   1.2  jmcneill #include <dev/arcbios/arcbios.h>
     49   1.2  jmcneill #include <dev/arcbios/arcbiosvar.h>
     50   1.2  jmcneill 
     51   1.1  jmcneill #include <dev/wscons/wsdisplayvar.h>
     52   1.1  jmcneill #include <dev/wscons/wsconsio.h>
     53   1.1  jmcneill #include <dev/wsfont/wsfont.h>
     54   1.1  jmcneill #include <dev/rasops/rasops.h>
     55   1.1  jmcneill #include <dev/wscons/wsdisplay_vconsvar.h>
     56   1.1  jmcneill 
     57  1.30  macallan #include <dev/i2c/i2cvar.h>
     58  1.30  macallan #include <dev/i2c/i2c_bitbang.h>
     59  1.30  macallan #include <dev/i2c/ddcvar.h>
     60  1.30  macallan #include <dev/videomode/videomode.h>
     61  1.30  macallan #include <dev/videomode/edidvar.h>
     62  1.30  macallan 
     63   1.7  macallan #include <arch/sgimips/dev/crmfbreg.h>
     64   1.7  macallan 
     65  1.18  macallan /*#define CRMFB_DEBUG*/
     66   1.3  jmcneill 
     67   1.1  jmcneill struct wsscreen_descr crmfb_defaultscreen = {
     68   1.1  jmcneill 	"default",
     69   1.1  jmcneill 	0, 0,
     70   1.1  jmcneill 	NULL,
     71   1.1  jmcneill 	8, 16,
     72   1.1  jmcneill 	WSSCREEN_WSCOLORS,
     73   1.1  jmcneill 	NULL,
     74   1.1  jmcneill };
     75   1.1  jmcneill 
     76   1.1  jmcneill const struct wsscreen_descr *_crmfb_scrlist[] = {
     77   1.1  jmcneill 	&crmfb_defaultscreen,
     78   1.1  jmcneill };
     79   1.1  jmcneill 
     80   1.1  jmcneill struct wsscreen_list crmfb_screenlist = {
     81   1.1  jmcneill 	sizeof(_crmfb_scrlist) / sizeof(struct wsscreen_descr *),
     82   1.1  jmcneill 	_crmfb_scrlist
     83   1.1  jmcneill };
     84   1.1  jmcneill 
     85   1.1  jmcneill static struct vcons_screen crmfb_console_screen;
     86   1.1  jmcneill 
     87   1.1  jmcneill static int	crmfb_ioctl(void *, void *, u_long, void *, int, struct lwp *);
     88   1.1  jmcneill static paddr_t	crmfb_mmap(void *, void *, off_t, int);
     89   1.1  jmcneill static void	crmfb_init_screen(void *, struct vcons_screen *, int, long *);
     90   1.1  jmcneill 
     91   1.1  jmcneill struct wsdisplay_accessops crmfb_accessops = {
     92   1.1  jmcneill 	crmfb_ioctl,
     93   1.1  jmcneill 	crmfb_mmap,
     94   1.1  jmcneill 	NULL,	/* alloc_screen */
     95   1.1  jmcneill 	NULL,	/* free_screen */
     96   1.1  jmcneill 	NULL,	/* show_screen */
     97   1.1  jmcneill 	NULL,	/* load_font */
     98   1.1  jmcneill 	NULL,	/* pollc */
     99   1.1  jmcneill 	NULL,	/* scroll */
    100   1.1  jmcneill };
    101   1.1  jmcneill 
    102   1.1  jmcneill /* Memory to allocate to SGI-CRM -- remember, this is stolen from
    103   1.1  jmcneill  * host memory!
    104   1.1  jmcneill  */
    105   1.1  jmcneill #define CRMFB_TILESIZE	(512*128)
    106   1.1  jmcneill 
    107  1.29  macallan static int	crmfb_match(device_t, struct cfdata *, void *);
    108  1.29  macallan static void	crmfb_attach(device_t, device_t, void *);
    109   1.1  jmcneill int		crmfb_probe(void);
    110   1.1  jmcneill 
    111   1.1  jmcneill #define KERNADDR(p)	((void *)((p).addr))
    112   1.1  jmcneill #define DMAADDR(p)	((p).map->dm_segs[0].ds_addr)
    113   1.1  jmcneill 
    114  1.10    sekiya #define CRMFB_REG_MASK(msb, lsb) \
    115  1.10    sekiya 	( (((uint32_t) 1 << ((msb)-(lsb)+1)) - 1) << (lsb) )
    116  1.10    sekiya 
    117  1.10    sekiya 
    118   1.1  jmcneill struct crmfb_dma {
    119   1.1  jmcneill 	bus_dmamap_t		map;
    120   1.1  jmcneill 	void			*addr;
    121   1.1  jmcneill 	bus_dma_segment_t	segs[1];
    122   1.1  jmcneill 	int			nsegs;
    123   1.1  jmcneill 	size_t			size;
    124   1.1  jmcneill };
    125   1.1  jmcneill 
    126   1.1  jmcneill struct crmfb_softc {
    127  1.29  macallan 	device_t		sc_dev;
    128   1.1  jmcneill 	struct vcons_data	sc_vd;
    129  1.30  macallan 	struct i2c_controller	sc_i2c;
    130  1.30  macallan 	int sc_dir;
    131   1.1  jmcneill 
    132   1.1  jmcneill 	bus_space_tag_t		sc_iot;
    133   1.1  jmcneill 	bus_space_handle_t	sc_ioh;
    134  1.11  macallan 	bus_space_handle_t	sc_reh;
    135   1.7  macallan 
    136   1.1  jmcneill 	bus_dma_tag_t		sc_dmat;
    137   1.1  jmcneill 
    138   1.1  jmcneill 	struct crmfb_dma	sc_dma;
    139   1.1  jmcneill 	struct crmfb_dma	sc_dmai;
    140   1.1  jmcneill 
    141   1.1  jmcneill 	int			sc_width;
    142   1.1  jmcneill 	int			sc_height;
    143   1.1  jmcneill 	int			sc_depth;
    144  1.11  macallan 	int			sc_tiles_x, sc_tiles_y;
    145   1.1  jmcneill 	uint32_t		sc_fbsize;
    146  1.18  macallan 	int			sc_mte_direction;
    147  1.11  macallan 	uint8_t			*sc_scratch;
    148  1.21  macallan 	paddr_t			sc_linear;
    149   1.1  jmcneill 	int			sc_wsmode;
    150   1.6  macallan 
    151   1.6  macallan 	/* cursor stuff */
    152   1.6  macallan 	int			sc_cur_x;
    153   1.6  macallan 	int			sc_cur_y;
    154   1.6  macallan 	int			sc_hot_x;
    155   1.6  macallan 	int			sc_hot_y;
    156   1.6  macallan 
    157   1.1  jmcneill 	u_char			sc_cmap_red[256];
    158   1.1  jmcneill 	u_char			sc_cmap_green[256];
    159   1.1  jmcneill 	u_char			sc_cmap_blue[256];
    160   1.1  jmcneill };
    161   1.1  jmcneill 
    162   1.1  jmcneill static int	crmfb_putcmap(struct crmfb_softc *, struct wsdisplay_cmap *);
    163   1.1  jmcneill static int	crmfb_getcmap(struct crmfb_softc *, struct wsdisplay_cmap *);
    164   1.1  jmcneill static void	crmfb_set_palette(struct crmfb_softc *,
    165   1.1  jmcneill 				  int, uint8_t, uint8_t, uint8_t);
    166   1.6  macallan static int	crmfb_set_curpos(struct crmfb_softc *, int, int);
    167   1.6  macallan static int	crmfb_gcursor(struct crmfb_softc *, struct wsdisplay_cursor *);
    168   1.6  macallan static int	crmfb_scursor(struct crmfb_softc *, struct wsdisplay_cursor *);
    169   1.7  macallan static inline void	crmfb_write_reg(struct crmfb_softc *, int, uint32_t);
    170  1.11  macallan static inline uint32_t	crmfb_read_reg(struct crmfb_softc *, int);
    171  1.11  macallan static int	crmfb_wait_dma_idle(struct crmfb_softc *);
    172   1.7  macallan 
    173   1.7  macallan /* setup video hw in given colour depth */
    174   1.7  macallan static int	crmfb_setup_video(struct crmfb_softc *, int);
    175   1.7  macallan static void	crmfb_setup_palette(struct crmfb_softc *);
    176   1.1  jmcneill 
    177  1.11  macallan static void crmfb_fill_rect(struct crmfb_softc *, int, int, int, int, uint32_t);
    178  1.11  macallan static void crmfb_bitblt(struct crmfb_softc *, int, int, int, int, int, int,
    179  1.11  macallan 			 uint32_t);
    180  1.15  macallan static void crmfb_scroll(struct crmfb_softc *, int, int, int, int, int, int);
    181  1.11  macallan 
    182  1.11  macallan static void	crmfb_copycols(void *, int, int, int, int);
    183  1.11  macallan static void	crmfb_erasecols(void *, int, int, int, long);
    184  1.11  macallan static void	crmfb_copyrows(void *, int, int, int);
    185  1.11  macallan static void	crmfb_eraserows(void *, int, int, long);
    186  1.11  macallan static void	crmfb_cursor(void *, int, int, int);
    187  1.11  macallan static void	crmfb_putchar(void *, int, int, u_int, long);
    188  1.11  macallan 
    189  1.30  macallan /* I2C glue */
    190  1.30  macallan static int crmfb_i2c_acquire_bus(void *, int);
    191  1.30  macallan static void crmfb_i2c_release_bus(void *, int);
    192  1.30  macallan static int crmfb_i2c_send_start(void *, int);
    193  1.30  macallan static int crmfb_i2c_send_stop(void *, int);
    194  1.30  macallan static int crmfb_i2c_initiate_xfer(void *, i2c_addr_t, int);
    195  1.30  macallan static int crmfb_i2c_read_byte(void *, uint8_t *, int);
    196  1.30  macallan static int crmfb_i2c_write_byte(void *, uint8_t, int);
    197  1.30  macallan 
    198  1.30  macallan /* I2C bitbang glue */
    199  1.30  macallan static void crmfb_i2cbb_set_bits(void *, uint32_t);
    200  1.30  macallan static void crmfb_i2cbb_set_dir(void *, uint32_t);
    201  1.30  macallan static uint32_t crmfb_i2cbb_read(void *);
    202  1.30  macallan 
    203  1.30  macallan static const struct i2c_bitbang_ops crmfb_i2cbb_ops = {
    204  1.30  macallan 	crmfb_i2cbb_set_bits,
    205  1.30  macallan 	crmfb_i2cbb_set_dir,
    206  1.30  macallan 	crmfb_i2cbb_read,
    207  1.30  macallan 	{
    208  1.30  macallan 		CRMFB_I2C_SDA,
    209  1.30  macallan 		CRMFB_I2C_SCL,
    210  1.30  macallan 		0,
    211  1.30  macallan 		1
    212  1.30  macallan 	}
    213  1.30  macallan };
    214  1.30  macallan static void crmfb_setup_ddc(struct crmfb_softc *);
    215  1.30  macallan 
    216  1.29  macallan CFATTACH_DECL_NEW(crmfb, sizeof(struct crmfb_softc),
    217   1.1  jmcneill     crmfb_match, crmfb_attach, NULL, NULL);
    218   1.1  jmcneill 
    219   1.1  jmcneill static int
    220  1.29  macallan crmfb_match(device_t parent, struct cfdata *cf, void *opaque)
    221   1.1  jmcneill {
    222   1.1  jmcneill 	return crmfb_probe();
    223   1.1  jmcneill }
    224   1.1  jmcneill 
    225   1.1  jmcneill static void
    226  1.29  macallan crmfb_attach(device_t parent, device_t self, void *opaque)
    227   1.1  jmcneill {
    228   1.1  jmcneill 	struct mainbus_attach_args *ma;
    229   1.1  jmcneill 	struct crmfb_softc *sc;
    230   1.1  jmcneill 	struct rasops_info *ri;
    231   1.1  jmcneill 	struct wsemuldisplaydev_attach_args aa;
    232   1.1  jmcneill 	uint32_t d, h;
    233   1.1  jmcneill 	uint16_t *p;
    234   1.1  jmcneill 	unsigned long v;
    235   1.1  jmcneill 	long defattr;
    236   1.2  jmcneill 	const char *consdev;
    237  1.11  macallan 	int rv, i;
    238   1.1  jmcneill 
    239  1.29  macallan 	sc = device_private(self);
    240  1.29  macallan 	sc->sc_dev = self;
    241  1.29  macallan 
    242   1.1  jmcneill 	ma = (struct mainbus_attach_args *)opaque;
    243   1.1  jmcneill 
    244   1.1  jmcneill 	sc->sc_iot = SGIMIPS_BUS_SPACE_CRIME;
    245   1.1  jmcneill 	sc->sc_dmat = &sgimips_default_bus_dma_tag;
    246   1.1  jmcneill 	sc->sc_wsmode = WSDISPLAYIO_MODE_EMUL;
    247   1.1  jmcneill 
    248   1.1  jmcneill 	aprint_normal(": SGI CRIME Graphics Display Engine\n");
    249   1.1  jmcneill 	rv = bus_space_map(sc->sc_iot, ma->ma_addr, 0 /* XXX */,
    250   1.1  jmcneill 	    BUS_SPACE_MAP_LINEAR, &sc->sc_ioh);
    251   1.1  jmcneill 	if (rv)
    252   1.1  jmcneill 		panic("crmfb_attach: can't map I/O space");
    253  1.11  macallan 	rv = bus_space_map(sc->sc_iot, 0x15000000, 0x6000, 0, &sc->sc_reh);
    254  1.11  macallan 	if (rv)
    255  1.11  macallan 		panic("crmfb_attach: can't map rendering engine");
    256   1.1  jmcneill 
    257  1.30  macallan 	//crmfb_setup_ddc(sc);
    258  1.30  macallan 
    259   1.1  jmcneill 	/* determine mode configured by firmware */
    260   1.9  jmcneill 	d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_VT_HCMAP);
    261   1.9  jmcneill 	sc->sc_width = (d >> CRMFB_VT_HCMAP_ON_SHIFT) & 0xfff;
    262   1.1  jmcneill 	d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_VT_VCMAP);
    263   1.9  jmcneill 	sc->sc_height = (d >> CRMFB_VT_VCMAP_ON_SHIFT) & 0xfff;
    264   1.1  jmcneill 	d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_TILESIZE);
    265   1.1  jmcneill 	h = (d >> CRMFB_FRM_TILESIZE_DEPTH_SHIFT) & 0x3;
    266   1.1  jmcneill 	if (h == 0)
    267   1.1  jmcneill 		sc->sc_depth = 8;
    268   1.1  jmcneill 	else if (h == 1)
    269   1.1  jmcneill 		sc->sc_depth = 16;
    270   1.1  jmcneill 	else
    271   1.1  jmcneill 		sc->sc_depth = 32;
    272   1.1  jmcneill 
    273   1.4    martin 	if (sc->sc_width == 0 || sc->sc_height == 0) {
    274  1.29  macallan 		aprint_error_dev(sc->sc_dev,
    275  1.29  macallan 		    "device unusable if not setup by firmware\n");
    276   1.4    martin 		bus_space_unmap(sc->sc_iot, sc->sc_ioh, 0 /* XXX */);
    277   1.4    martin 		return;
    278   1.4    martin 	}
    279   1.4    martin 
    280  1.29  macallan 	aprint_normal_dev(sc->sc_dev, "initial resolution %dx%d\n",
    281  1.29  macallan 	    sc->sc_width, sc->sc_height);
    282   1.1  jmcneill 
    283   1.7  macallan 	/*
    284   1.7  macallan 	 * first determine how many tiles we need
    285   1.7  macallan 	 * in 32bit each tile is 128x128 pixels
    286   1.7  macallan 	 */
    287  1.11  macallan 	sc->sc_tiles_x = (sc->sc_width + 127) >> 7;
    288  1.11  macallan 	sc->sc_tiles_y = (sc->sc_height + 127) >> 7;
    289  1.11  macallan 	sc->sc_fbsize = 0x10000 * sc->sc_tiles_x * sc->sc_tiles_y;
    290   1.1  jmcneill 
    291   1.7  macallan 	sc->sc_dmai.size = 256 * sizeof(uint16_t);
    292   1.1  jmcneill 	rv = bus_dmamem_alloc(sc->sc_dmat, sc->sc_dmai.size, 65536, 0,
    293   1.1  jmcneill 	    sc->sc_dmai.segs,
    294   1.1  jmcneill 	    sizeof(sc->sc_dmai.segs) / sizeof(sc->sc_dmai.segs[0]),
    295   1.1  jmcneill 	    &sc->sc_dmai.nsegs, BUS_DMA_NOWAIT);
    296   1.1  jmcneill 	if (rv)
    297   1.1  jmcneill 		panic("crmfb_attach: can't allocate DMA memory");
    298   1.1  jmcneill 	rv = bus_dmamem_map(sc->sc_dmat, sc->sc_dmai.segs, sc->sc_dmai.nsegs,
    299   1.1  jmcneill 	    sc->sc_dmai.size, &sc->sc_dmai.addr,
    300   1.1  jmcneill 	    BUS_DMA_NOWAIT);
    301   1.1  jmcneill 	if (rv)
    302   1.1  jmcneill 		panic("crmfb_attach: can't map DMA memory");
    303   1.1  jmcneill 	rv = bus_dmamap_create(sc->sc_dmat, sc->sc_dmai.size, 1,
    304   1.1  jmcneill 	    sc->sc_dmai.size, 0, BUS_DMA_NOWAIT, &sc->sc_dmai.map);
    305   1.1  jmcneill 	if (rv)
    306   1.1  jmcneill 		panic("crmfb_attach: can't create DMA map");
    307   1.1  jmcneill 	rv = bus_dmamap_load(sc->sc_dmat, sc->sc_dmai.map, sc->sc_dmai.addr,
    308   1.1  jmcneill 	    sc->sc_dmai.size, NULL, BUS_DMA_NOWAIT);
    309   1.1  jmcneill 	if (rv)
    310   1.1  jmcneill 		panic("crmfb_attach: can't load DMA map");
    311   1.1  jmcneill 
    312  1.21  macallan 	/* allocate an extra 64Kb for a linear buffer */
    313  1.21  macallan 	sc->sc_dma.size = 0x10000 * (16 * sc->sc_tiles_x + 1);
    314   1.1  jmcneill 	rv = bus_dmamem_alloc(sc->sc_dmat, sc->sc_dma.size, 65536, 0,
    315   1.1  jmcneill 	    sc->sc_dma.segs,
    316   1.1  jmcneill 	    sizeof(sc->sc_dma.segs) / sizeof(sc->sc_dma.segs[0]),
    317   1.1  jmcneill 	    &sc->sc_dma.nsegs, BUS_DMA_NOWAIT);
    318   1.1  jmcneill 	if (rv)
    319   1.1  jmcneill 		panic("crmfb_attach: can't allocate DMA memory");
    320   1.1  jmcneill 	rv = bus_dmamem_map(sc->sc_dmat, sc->sc_dma.segs, sc->sc_dma.nsegs,
    321   1.1  jmcneill 	    sc->sc_dma.size, &sc->sc_dma.addr,
    322   1.1  jmcneill 	    BUS_DMA_NOWAIT | BUS_DMA_COHERENT);
    323   1.1  jmcneill 	if (rv)
    324   1.1  jmcneill 		panic("crmfb_attach: can't map DMA memory");
    325   1.1  jmcneill 	rv = bus_dmamap_create(sc->sc_dmat, sc->sc_dma.size, 1,
    326   1.1  jmcneill 	    sc->sc_dma.size, 0, BUS_DMA_NOWAIT, &sc->sc_dma.map);
    327   1.1  jmcneill 	if (rv)
    328   1.1  jmcneill 		panic("crmfb_attach: can't create DMA map");
    329   1.1  jmcneill 	rv = bus_dmamap_load(sc->sc_dmat, sc->sc_dma.map, sc->sc_dma.addr,
    330   1.1  jmcneill 	    sc->sc_dma.size, NULL, BUS_DMA_NOWAIT);
    331   1.1  jmcneill 	if (rv)
    332   1.1  jmcneill 		panic("crmfb_attach: can't load DMA map");
    333   1.1  jmcneill 
    334   1.1  jmcneill 	p = KERNADDR(sc->sc_dmai);
    335   1.1  jmcneill 	v = (unsigned long)DMAADDR(sc->sc_dma);
    336  1.11  macallan 	for (i = 0; i < (sc->sc_tiles_x * sc->sc_tiles_y); i++) {
    337   1.1  jmcneill 		p[i] = ((uint32_t)v >> 16) + i;
    338   1.1  jmcneill 	}
    339  1.26   tsutsui 	bus_dmamap_sync(sc->sc_dmat, sc->sc_dmai.map, 0, sc->sc_dmai.size,
    340  1.26   tsutsui 	    BUS_DMASYNC_PREWRITE);
    341  1.21  macallan 	sc->sc_scratch = (char *)KERNADDR(sc->sc_dma) + (0xf0000 * sc->sc_tiles_x);
    342  1.21  macallan 	sc->sc_linear = (paddr_t)DMAADDR(sc->sc_dma) + 0x100000 * sc->sc_tiles_x;
    343   1.1  jmcneill 
    344  1.29  macallan 	aprint_normal_dev(sc->sc_dev, "allocated %d byte fb @ %p (%p)\n",
    345   1.1  jmcneill 	    sc->sc_fbsize, KERNADDR(sc->sc_dmai), KERNADDR(sc->sc_dma));
    346   1.1  jmcneill 
    347  1.21  macallan 	crmfb_setup_video(sc, 8);
    348   1.1  jmcneill 	ri = &crmfb_console_screen.scr_ri;
    349   1.1  jmcneill 	memset(ri, 0, sizeof(struct rasops_info));
    350   1.1  jmcneill 
    351   1.1  jmcneill 	vcons_init(&sc->sc_vd, sc, &crmfb_defaultscreen, &crmfb_accessops);
    352   1.1  jmcneill 	sc->sc_vd.init_screen = crmfb_init_screen;
    353   1.1  jmcneill 	crmfb_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
    354   1.1  jmcneill 	vcons_init_screen(&sc->sc_vd, &crmfb_console_screen, 1, &defattr);
    355   1.1  jmcneill 
    356   1.1  jmcneill 	crmfb_defaultscreen.ncols = ri->ri_cols;
    357   1.1  jmcneill 	crmfb_defaultscreen.nrows = ri->ri_rows;
    358   1.1  jmcneill 	crmfb_defaultscreen.textops = &ri->ri_ops;
    359   1.1  jmcneill 	crmfb_defaultscreen.capabilities = ri->ri_caps;
    360   1.1  jmcneill 	crmfb_defaultscreen.modecookie = NULL;
    361   1.1  jmcneill 
    362   1.7  macallan 	crmfb_setup_palette(sc);
    363  1.14  macallan 	crmfb_fill_rect(sc, 0, 0, sc->sc_width, sc->sc_height,
    364  1.17  macallan 	    ri->ri_devcmap[(defattr >> 16) & 0xff]);
    365   1.1  jmcneill 
    366  1.27      matt 	consdev = arcbios_GetEnvironmentVariable("ConsoleOut");
    367   1.2  jmcneill 	if (consdev != NULL && strcmp(consdev, "video()") == 0) {
    368   1.2  jmcneill 		wsdisplay_cnattach(&crmfb_defaultscreen, ri, 0, 0, defattr);
    369  1.28  macallan 		vcons_replay_msgbuf(&crmfb_console_screen);
    370   1.2  jmcneill 		aa.console = 1;
    371   1.2  jmcneill 	} else
    372   1.2  jmcneill 		aa.console = 0;
    373   1.1  jmcneill 	aa.scrdata = &crmfb_screenlist;
    374   1.1  jmcneill 	aa.accessops = &crmfb_accessops;
    375   1.1  jmcneill 	aa.accesscookie = &sc->sc_vd;
    376   1.1  jmcneill 
    377   1.1  jmcneill 	config_found(self, &aa, wsemuldisplaydevprint);
    378   1.1  jmcneill 
    379   1.6  macallan 	sc->sc_cur_x = 0;
    380   1.6  macallan 	sc->sc_cur_y = 0;
    381   1.6  macallan 	sc->sc_hot_x = 0;
    382   1.6  macallan 	sc->sc_hot_y = 0;
    383   1.6  macallan 
    384  1.30  macallan 	crmfb_setup_ddc(sc);
    385   1.1  jmcneill 	return;
    386   1.1  jmcneill }
    387   1.1  jmcneill 
    388   1.1  jmcneill int
    389   1.1  jmcneill crmfb_probe(void)
    390   1.1  jmcneill {
    391   1.1  jmcneill 
    392   1.1  jmcneill         if (mach_type != MACH_SGI_IP32)
    393   1.1  jmcneill                 return 0;
    394   1.1  jmcneill 
    395   1.1  jmcneill 	return 1;
    396   1.1  jmcneill }
    397   1.1  jmcneill 
    398   1.1  jmcneill static int
    399   1.1  jmcneill crmfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
    400   1.1  jmcneill {
    401   1.1  jmcneill 	struct vcons_data *vd;
    402   1.1  jmcneill 	struct crmfb_softc *sc;
    403   1.1  jmcneill 	struct vcons_screen *ms;
    404   1.1  jmcneill 	struct wsdisplay_fbinfo *wdf;
    405   1.1  jmcneill 	int nmode;
    406   1.1  jmcneill 
    407   1.1  jmcneill 	vd = (struct vcons_data *)v;
    408   1.1  jmcneill 	sc = (struct crmfb_softc *)vd->cookie;
    409   1.1  jmcneill 	ms = (struct vcons_screen *)vd->active;
    410   1.1  jmcneill 
    411   1.1  jmcneill 	switch (cmd) {
    412   1.1  jmcneill 	case WSDISPLAYIO_GTYPE:
    413   1.1  jmcneill 		/* not really, but who cares? */
    414   1.7  macallan 		/* wsfb does */
    415   1.7  macallan 		*(u_int *)data = WSDISPLAY_TYPE_CRIME;
    416   1.1  jmcneill 		return 0;
    417   1.1  jmcneill 	case WSDISPLAYIO_GINFO:
    418   1.1  jmcneill 		if (vd->active != NULL) {
    419   1.1  jmcneill 			wdf = (void *)data;
    420   1.1  jmcneill 			wdf->height = sc->sc_height;
    421   1.1  jmcneill 			wdf->width = sc->sc_width;
    422   1.7  macallan 			wdf->depth = 32;
    423   1.1  jmcneill 			wdf->cmsize = 256;
    424   1.1  jmcneill 			return 0;
    425   1.1  jmcneill 		} else
    426   1.1  jmcneill 			return ENODEV;
    427   1.1  jmcneill 	case WSDISPLAYIO_GETCMAP:
    428   1.1  jmcneill 		if (sc->sc_depth == 8)
    429   1.1  jmcneill 			return crmfb_getcmap(sc, (struct wsdisplay_cmap *)data);
    430   1.1  jmcneill 		else
    431   1.1  jmcneill 			return EINVAL;
    432   1.1  jmcneill 	case WSDISPLAYIO_PUTCMAP:
    433   1.1  jmcneill 		if (sc->sc_depth == 8)
    434   1.1  jmcneill 			return crmfb_putcmap(sc, (struct wsdisplay_cmap *)data);
    435   1.1  jmcneill 		else
    436   1.1  jmcneill 			return EINVAL;
    437   1.1  jmcneill 	case WSDISPLAYIO_LINEBYTES:
    438   1.1  jmcneill 		*(u_int *)data = sc->sc_width * sc->sc_depth / 8;
    439   1.1  jmcneill 		return 0;
    440   1.1  jmcneill 	case WSDISPLAYIO_SMODE:
    441   1.1  jmcneill 		nmode = *(int *)data;
    442   1.1  jmcneill 		if (nmode != sc->sc_wsmode) {
    443   1.1  jmcneill 			sc->sc_wsmode = nmode;
    444   1.7  macallan 			if (nmode == WSDISPLAYIO_MODE_EMUL) {
    445   1.7  macallan 				crmfb_setup_video(sc, 8);
    446   1.7  macallan 				crmfb_setup_palette(sc);
    447   1.1  jmcneill 				vcons_redraw_screen(vd->active);
    448   1.7  macallan 			} else {
    449   1.7  macallan 				crmfb_setup_video(sc, 32);
    450   1.7  macallan 			}
    451   1.1  jmcneill 		}
    452   1.1  jmcneill 		return 0;
    453   1.5  jmcneill 	case WSDISPLAYIO_SVIDEO:
    454   1.5  jmcneill 	case WSDISPLAYIO_GVIDEO:
    455   1.5  jmcneill 		return ENODEV;	/* not supported yet */
    456   1.6  macallan 
    457   1.6  macallan 	case WSDISPLAYIO_GCURPOS:
    458   1.6  macallan 		{
    459   1.6  macallan 			struct wsdisplay_curpos *pos;
    460   1.6  macallan 
    461   1.6  macallan 			pos = (struct wsdisplay_curpos *)data;
    462   1.6  macallan 			pos->x = sc->sc_cur_x;
    463   1.6  macallan 			pos->y = sc->sc_cur_y;
    464   1.6  macallan 		}
    465   1.6  macallan 		return 0;
    466   1.6  macallan 	case WSDISPLAYIO_SCURPOS:
    467   1.6  macallan 		{
    468   1.6  macallan 			struct wsdisplay_curpos *pos;
    469   1.6  macallan 
    470   1.6  macallan 			pos = (struct wsdisplay_curpos *)data;
    471   1.6  macallan 			crmfb_set_curpos(sc, pos->x, pos->y);
    472   1.6  macallan 		}
    473   1.6  macallan 		return 0;
    474   1.6  macallan 	case WSDISPLAYIO_GCURMAX:
    475   1.6  macallan 		{
    476   1.6  macallan 			struct wsdisplay_curpos *pos;
    477   1.6  macallan 
    478   1.6  macallan 			pos = (struct wsdisplay_curpos *)data;
    479   1.6  macallan 			pos->x = 32;
    480   1.6  macallan 			pos->y = 32;
    481   1.6  macallan 		}
    482   1.6  macallan 		return 0;
    483   1.6  macallan 	case WSDISPLAYIO_GCURSOR:
    484   1.6  macallan 		{
    485   1.6  macallan 			struct wsdisplay_cursor *cu;
    486   1.6  macallan 
    487   1.6  macallan 			cu = (struct wsdisplay_cursor *)data;
    488   1.6  macallan 			return crmfb_gcursor(sc, cu);
    489   1.6  macallan 		}
    490   1.6  macallan 	case WSDISPLAYIO_SCURSOR:
    491   1.6  macallan 		{
    492   1.6  macallan 			struct wsdisplay_cursor *cu;
    493   1.6  macallan 
    494   1.6  macallan 			cu = (struct wsdisplay_cursor *)data;
    495   1.6  macallan 			return crmfb_scursor(sc, cu);
    496   1.6  macallan 		}
    497   1.1  jmcneill 	}
    498   1.1  jmcneill 	return EPASSTHROUGH;
    499   1.1  jmcneill }
    500   1.1  jmcneill 
    501   1.1  jmcneill static paddr_t
    502   1.1  jmcneill crmfb_mmap(void *v, void *vs, off_t offset, int prot)
    503   1.1  jmcneill {
    504   1.1  jmcneill 	struct vcons_data *vd;
    505   1.1  jmcneill 	struct crmfb_softc *sc;
    506   1.1  jmcneill 	paddr_t pa;
    507   1.1  jmcneill 
    508   1.1  jmcneill 	vd = (struct vcons_data *)v;
    509   1.1  jmcneill 	sc = (struct crmfb_softc *)vd->cookie;
    510   1.1  jmcneill 
    511  1.14  macallan 	/* we probably shouldn't let anyone mmap the framebuffer */
    512   1.7  macallan #if 1
    513  1.22  macallan 	if (offset >= 0 && offset < (0x100000 * sc->sc_tiles_x)) {
    514   1.1  jmcneill 		pa = bus_dmamem_mmap(sc->sc_dmat, sc->sc_dma.segs,
    515   1.1  jmcneill 		    sc->sc_dma.nsegs, offset, prot,
    516   1.3  jmcneill 		    BUS_DMA_WAITOK | BUS_DMA_COHERENT);
    517   1.1  jmcneill 		return pa;
    518   1.1  jmcneill 	}
    519   1.7  macallan #endif
    520  1.14  macallan 	/*
    521  1.14  macallan 	 * here would the TLBs be but we don't want to show them to userland
    522  1.14  macallan 	 * so we return the page containing the status register
    523  1.14  macallan 	 */
    524  1.14  macallan 	if ((offset >= 0x15000000) && (offset < 0x15002000))
    525  1.14  macallan 		return bus_space_mmap(sc->sc_iot, 0x15004000, 0, prot, 0);
    526  1.14  macallan 	/* now the actual engine registers */
    527  1.14  macallan 	if ((offset >= 0x15002000) && (offset < 0x15005000))
    528  1.14  macallan 		return bus_space_mmap(sc->sc_iot, offset, 0, prot, 0);
    529  1.14  macallan 	/* and now the scratch area */
    530  1.14  macallan 	if ((offset >= 0x15010000) && (offset < 0x15020000))
    531  1.14  macallan 		return bus_dmamem_mmap(sc->sc_dmat, sc->sc_dma.segs,
    532  1.21  macallan 		     sc->sc_dma.nsegs,
    533  1.21  macallan 		     offset + (0x100000 * sc->sc_tiles_x) - 0x15010000,
    534  1.21  macallan 		     prot, BUS_DMA_WAITOK | BUS_DMA_COHERENT);
    535   1.1  jmcneill 	return -1;
    536   1.1  jmcneill }
    537   1.1  jmcneill 
    538   1.1  jmcneill static void
    539   1.1  jmcneill crmfb_init_screen(void *c, struct vcons_screen *scr, int existing,
    540   1.1  jmcneill     long *defattr)
    541   1.1  jmcneill {
    542   1.1  jmcneill 	struct crmfb_softc *sc;
    543   1.1  jmcneill 	struct rasops_info *ri;
    544   1.1  jmcneill 
    545   1.1  jmcneill 	sc = (struct crmfb_softc *)c;
    546   1.1  jmcneill 	ri = &scr->scr_ri;
    547   1.1  jmcneill 
    548  1.11  macallan 	ri->ri_flg = RI_CENTER | RI_FULLCLEAR;
    549   1.1  jmcneill 	ri->ri_depth = sc->sc_depth;
    550   1.1  jmcneill 	ri->ri_width = sc->sc_width;
    551   1.1  jmcneill 	ri->ri_height = sc->sc_height;
    552   1.1  jmcneill 	ri->ri_stride = ri->ri_width * (ri->ri_depth / 8);
    553   1.1  jmcneill 
    554   1.1  jmcneill 	switch (ri->ri_depth) {
    555   1.1  jmcneill 	case 16:
    556   1.1  jmcneill 		ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 5;
    557   1.1  jmcneill 		ri->ri_rpos = 10;
    558   1.1  jmcneill 		ri->ri_gpos = 5;
    559   1.1  jmcneill 		ri->ri_bpos = 0;
    560   1.1  jmcneill 		break;
    561   1.1  jmcneill 	case 32:
    562   1.1  jmcneill 		ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 8;
    563   1.1  jmcneill 		ri->ri_rpos = 8;
    564   1.1  jmcneill 		ri->ri_gpos = 16;
    565   1.1  jmcneill 		ri->ri_bpos = 24;
    566   1.1  jmcneill 		break;
    567   1.1  jmcneill 	}
    568   1.1  jmcneill 
    569  1.11  macallan 	ri->ri_bits = KERNADDR(sc->sc_dma);
    570   1.1  jmcneill 
    571   1.1  jmcneill 	if (existing)
    572   1.1  jmcneill 		ri->ri_flg |= RI_CLEAR;
    573   1.1  jmcneill 
    574   1.1  jmcneill 	rasops_init(ri, ri->ri_height / 16, ri->ri_width / 8);
    575   1.1  jmcneill 	ri->ri_caps = WSSCREEN_WSCOLORS;
    576   1.1  jmcneill 	rasops_reconfig(ri, ri->ri_height / ri->ri_font->fontheight,
    577   1.1  jmcneill 	    ri->ri_width / ri->ri_font->fontwidth);
    578   1.1  jmcneill 	ri->ri_hw = scr;
    579   1.1  jmcneill 
    580  1.11  macallan 	ri->ri_ops.cursor    = crmfb_cursor;
    581  1.11  macallan 	ri->ri_ops.copyrows  = crmfb_copyrows;
    582  1.11  macallan 	ri->ri_ops.eraserows = crmfb_eraserows;
    583  1.11  macallan 	ri->ri_ops.copycols  = crmfb_copycols;
    584  1.11  macallan 	ri->ri_ops.erasecols = crmfb_erasecols;
    585  1.11  macallan 	ri->ri_ops.putchar   = crmfb_putchar;
    586  1.11  macallan 
    587   1.1  jmcneill 	return;
    588   1.1  jmcneill }
    589   1.1  jmcneill 
    590   1.1  jmcneill static int
    591   1.1  jmcneill crmfb_putcmap(struct crmfb_softc *sc, struct wsdisplay_cmap *cm)
    592   1.1  jmcneill {
    593   1.1  jmcneill 	u_int idx, cnt;
    594   1.1  jmcneill 	u_char r[256], g[256], b[256];
    595   1.1  jmcneill 	u_char *rp, *gp, *bp;
    596   1.1  jmcneill 	int rv, i;
    597   1.1  jmcneill 
    598   1.1  jmcneill 	idx = cm->index;
    599   1.1  jmcneill 	cnt = cm->count;
    600   1.1  jmcneill 
    601   1.1  jmcneill 	if (idx >= 255 || cnt > 256 || idx + cnt > 256)
    602   1.1  jmcneill 		return EINVAL;
    603   1.1  jmcneill 
    604   1.1  jmcneill 	rv = copyin(cm->red, &r[idx], cnt);
    605   1.1  jmcneill 	if (rv)
    606   1.1  jmcneill 		return rv;
    607   1.1  jmcneill 	rv = copyin(cm->green, &g[idx], cnt);
    608   1.1  jmcneill 	if (rv)
    609   1.1  jmcneill 		return rv;
    610   1.1  jmcneill 	rv = copyin(cm->blue, &b[idx], cnt);
    611   1.1  jmcneill 	if (rv)
    612   1.1  jmcneill 		return rv;
    613   1.1  jmcneill 
    614   1.1  jmcneill 	memcpy(&sc->sc_cmap_red[idx], &r[idx], cnt);
    615   1.1  jmcneill 	memcpy(&sc->sc_cmap_green[idx], &g[idx], cnt);
    616   1.1  jmcneill 	memcpy(&sc->sc_cmap_blue[idx], &b[idx], cnt);
    617   1.1  jmcneill 
    618   1.1  jmcneill 	rp = &sc->sc_cmap_red[idx];
    619   1.1  jmcneill 	gp = &sc->sc_cmap_green[idx];
    620   1.1  jmcneill 	bp = &sc->sc_cmap_blue[idx];
    621   1.1  jmcneill 
    622   1.1  jmcneill 	for (i = 0; i < cnt; i++) {
    623   1.1  jmcneill 		crmfb_set_palette(sc, idx, *rp, *gp, *bp);
    624   1.1  jmcneill 		idx++;
    625   1.1  jmcneill 		rp++, gp++, bp++;
    626   1.1  jmcneill 	}
    627   1.1  jmcneill 
    628   1.1  jmcneill 	return 0;
    629   1.1  jmcneill }
    630   1.1  jmcneill 
    631   1.1  jmcneill static int
    632   1.1  jmcneill crmfb_getcmap(struct crmfb_softc *sc, struct wsdisplay_cmap *cm)
    633   1.1  jmcneill {
    634   1.1  jmcneill 	u_int idx, cnt;
    635   1.1  jmcneill 	int rv;
    636   1.1  jmcneill 
    637   1.1  jmcneill 	idx = cm->index;
    638   1.1  jmcneill 	cnt = cm->count;
    639   1.1  jmcneill 
    640   1.1  jmcneill 	if (idx >= 255 || cnt > 256 || idx + cnt > 256)
    641   1.1  jmcneill 		return EINVAL;
    642   1.1  jmcneill 
    643   1.1  jmcneill 	rv = copyout(&sc->sc_cmap_red[idx], cm->red, cnt);
    644   1.1  jmcneill 	if (rv)
    645   1.1  jmcneill 		return rv;
    646   1.1  jmcneill 	rv = copyout(&sc->sc_cmap_green[idx], cm->green, cnt);
    647   1.1  jmcneill 	if (rv)
    648   1.1  jmcneill 		return rv;
    649   1.1  jmcneill 	rv = copyout(&sc->sc_cmap_blue[idx], cm->blue, cnt);
    650   1.1  jmcneill 	if (rv)
    651   1.1  jmcneill 		return rv;
    652   1.1  jmcneill 
    653   1.1  jmcneill 	return 0;
    654   1.1  jmcneill }
    655   1.1  jmcneill 
    656   1.1  jmcneill static void
    657   1.1  jmcneill crmfb_set_palette(struct crmfb_softc *sc, int reg, uint8_t r, uint8_t g,
    658   1.1  jmcneill     uint8_t b)
    659   1.1  jmcneill {
    660   1.1  jmcneill 	uint32_t val;
    661   1.1  jmcneill 
    662   1.1  jmcneill 	if (reg > 255 || sc->sc_depth != 8)
    663   1.1  jmcneill 		return;
    664   1.1  jmcneill 
    665   1.1  jmcneill 	while (bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_CMAP_FIFO) >= 63)
    666   1.1  jmcneill 		DELAY(10);
    667   1.1  jmcneill 
    668  1.23  jmcneill 	val = (r << 8) | (g << 16) | (b << 24);
    669   1.7  macallan 	crmfb_write_reg(sc, CRMFB_CMAP + (reg * 4), val);
    670   1.1  jmcneill 
    671   1.1  jmcneill 	return;
    672   1.1  jmcneill }
    673   1.6  macallan 
    674   1.6  macallan static int
    675   1.6  macallan crmfb_set_curpos(struct crmfb_softc *sc, int x, int y)
    676   1.6  macallan {
    677   1.6  macallan 	uint32_t val;
    678   1.6  macallan 
    679   1.6  macallan 	sc->sc_cur_x = x;
    680   1.6  macallan 	sc->sc_cur_y = y;
    681   1.6  macallan 
    682   1.6  macallan 	val = ((x - sc->sc_hot_x) & 0xffff) | ((y - sc->sc_hot_y) << 16);
    683   1.7  macallan 	crmfb_write_reg(sc, CRMFB_CURSOR_POS, val);
    684   1.6  macallan 
    685   1.6  macallan 	return 0;
    686   1.6  macallan }
    687   1.6  macallan 
    688   1.6  macallan static int
    689   1.6  macallan crmfb_gcursor(struct crmfb_softc *sc, struct wsdisplay_cursor *cur)
    690   1.6  macallan {
    691   1.6  macallan 	/* do nothing for now */
    692   1.6  macallan 	return 0;
    693   1.6  macallan }
    694   1.6  macallan 
    695   1.6  macallan static int
    696   1.6  macallan crmfb_scursor(struct crmfb_softc *sc, struct wsdisplay_cursor *cur)
    697   1.6  macallan {
    698   1.6  macallan 	if (cur->which & WSDISPLAY_CURSOR_DOCUR) {
    699   1.6  macallan 
    700   1.7  macallan 		crmfb_write_reg(sc, CRMFB_CURSOR_CONTROL, cur->enable ? 1 : 0);
    701   1.6  macallan 	}
    702   1.6  macallan 	if (cur->which & WSDISPLAY_CURSOR_DOHOT) {
    703   1.6  macallan 
    704   1.6  macallan 		sc->sc_hot_x = cur->hot.x;
    705   1.6  macallan 		sc->sc_hot_y = cur->hot.y;
    706   1.6  macallan 	}
    707   1.6  macallan 	if (cur->which & WSDISPLAY_CURSOR_DOPOS) {
    708   1.6  macallan 
    709   1.6  macallan 		crmfb_set_curpos(sc, cur->pos.x, cur->pos.y);
    710   1.6  macallan 	}
    711   1.6  macallan 	if (cur->which & WSDISPLAY_CURSOR_DOCMAP) {
    712   1.6  macallan 		int i;
    713   1.6  macallan 		uint32_t val;
    714   1.6  macallan 
    715   1.6  macallan 		for (i = 0; i < cur->cmap.count; i++) {
    716   1.6  macallan 			val = (cur->cmap.red[i] << 24) |
    717   1.6  macallan 			      (cur->cmap.green[i] << 16) |
    718   1.6  macallan 			      (cur->cmap.blue[i] << 8);
    719   1.7  macallan 			crmfb_write_reg(sc, CRMFB_CURSOR_CMAP0 +
    720   1.7  macallan 			    ((i + cur->cmap.index) << 2), val);
    721   1.6  macallan 		}
    722   1.6  macallan 	}
    723   1.6  macallan 	if (cur->which & WSDISPLAY_CURSOR_DOSHAPE) {
    724   1.6  macallan 
    725   1.6  macallan 		int i, j, cnt = 0;
    726   1.6  macallan 		uint32_t latch = 0, omask;
    727   1.6  macallan 		uint8_t imask;
    728   1.6  macallan 		for (i = 0; i < 64; i++) {
    729   1.6  macallan 			omask = 0x80000000;
    730   1.6  macallan 			imask = 0x01;
    731   1.6  macallan 			cur->image[cnt] &= cur->mask[cnt];
    732   1.6  macallan 			for (j = 0; j < 8; j++) {
    733   1.6  macallan 				if (cur->image[cnt] & imask)
    734   1.6  macallan 					latch |= omask;
    735   1.6  macallan 				omask >>= 1;
    736   1.6  macallan 				if (cur->mask[cnt] & imask)
    737   1.6  macallan 					latch |= omask;
    738   1.6  macallan 				omask >>= 1;
    739   1.6  macallan 				imask <<= 1;
    740   1.6  macallan 			}
    741   1.6  macallan 			cnt++;
    742   1.6  macallan 			imask = 0x01;
    743   1.6  macallan 			cur->image[cnt] &= cur->mask[cnt];
    744   1.6  macallan 			for (j = 0; j < 8; j++) {
    745   1.6  macallan 				if (cur->image[cnt] & imask)
    746   1.6  macallan 					latch |= omask;
    747   1.6  macallan 				omask >>= 1;
    748   1.6  macallan 				if (cur->mask[cnt] & imask)
    749   1.6  macallan 					latch |= omask;
    750   1.6  macallan 				omask >>= 1;
    751   1.6  macallan 				imask <<= 1;
    752   1.6  macallan 			}
    753   1.6  macallan 			cnt++;
    754   1.7  macallan 			crmfb_write_reg(sc, CRMFB_CURSOR_BITMAP + (i << 2),
    755   1.7  macallan 			    latch);
    756   1.6  macallan 			latch = 0;
    757   1.6  macallan 		}
    758   1.6  macallan 	}
    759   1.6  macallan 	return 0;
    760   1.6  macallan }
    761   1.7  macallan 
    762   1.7  macallan static inline void
    763   1.7  macallan crmfb_write_reg(struct crmfb_softc *sc, int offset, uint32_t val)
    764   1.7  macallan {
    765   1.7  macallan 
    766   1.7  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, offset, val);
    767   1.7  macallan 	wbflush();
    768   1.7  macallan }
    769   1.7  macallan 
    770  1.11  macallan static inline uint32_t
    771  1.11  macallan crmfb_read_reg(struct crmfb_softc *sc, int offset)
    772  1.11  macallan {
    773  1.11  macallan 
    774  1.11  macallan 	return bus_space_read_4(sc->sc_iot, sc->sc_ioh, offset);
    775  1.11  macallan }
    776  1.11  macallan 
    777  1.11  macallan static int
    778  1.11  macallan crmfb_wait_dma_idle(struct crmfb_softc *sc)
    779  1.11  macallan {
    780  1.11  macallan 	int bail = 100000, idle;
    781  1.11  macallan 
    782  1.11  macallan 	do {
    783  1.11  macallan 		idle = ((bus_space_read_4(sc->sc_iot, sc->sc_ioh,
    784  1.11  macallan 		         CRMFB_OVR_CONTROL) & 1) == 0) &&
    785  1.11  macallan 		       ((bus_space_read_4(sc->sc_iot, sc->sc_ioh,
    786  1.11  macallan 		         CRMFB_FRM_CONTROL) & 1) == 0) &&
    787  1.11  macallan 		       ((bus_space_read_4(sc->sc_iot, sc->sc_ioh,
    788  1.11  macallan 		         CRMFB_DID_CONTROL) & 1) == 0);
    789  1.11  macallan 		if (!idle)
    790  1.11  macallan 			delay(10);
    791  1.11  macallan 		bail--;
    792  1.11  macallan 	} while ((!idle) && (bail > 0));
    793  1.11  macallan 	return idle;
    794  1.11  macallan }
    795  1.11  macallan 
    796   1.7  macallan static int
    797   1.7  macallan crmfb_setup_video(struct crmfb_softc *sc, int depth)
    798   1.7  macallan {
    799  1.11  macallan 	uint64_t reg;
    800  1.21  macallan 	uint32_t d, h, mode, page;
    801  1.21  macallan 	int i, bail, tile_width, tlbptr, lptr, j, tx, shift;
    802  1.10    sekiya 	const char *wantsync;
    803  1.11  macallan 	uint16_t v;
    804  1.11  macallan 
    805   1.7  macallan 	/* disable DMA */
    806   1.7  macallan 	d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_OVR_CONTROL);
    807   1.7  macallan 	d &= ~(1 << CRMFB_OVR_CONTROL_DMAEN_SHIFT);
    808   1.7  macallan 	crmfb_write_reg(sc, CRMFB_OVR_CONTROL, d);
    809   1.7  macallan 	DELAY(50000);
    810   1.7  macallan 	d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_CONTROL);
    811   1.7  macallan 	d &= ~(1 << CRMFB_FRM_CONTROL_DMAEN_SHIFT);
    812   1.7  macallan 	crmfb_write_reg(sc, CRMFB_FRM_CONTROL, d);
    813   1.7  macallan 	DELAY(50000);
    814   1.7  macallan 	crmfb_write_reg(sc, CRMFB_DID_CONTROL, 0);
    815   1.7  macallan 	DELAY(50000);
    816   1.7  macallan 
    817  1.11  macallan 	if (!crmfb_wait_dma_idle(sc))
    818  1.11  macallan 		aprint_error("crmfb: crmfb_wait_dma_idle timed out\n");
    819  1.11  macallan 
    820   1.7  macallan 	/* ensure that CRM starts drawing at the top left of the screen
    821   1.7  macallan 	 * when we re-enable DMA later
    822   1.7  macallan 	 */
    823   1.7  macallan 	d = (1 << CRMFB_VT_XY_FREEZE_SHIFT);
    824   1.7  macallan 	crmfb_write_reg(sc, CRMFB_VT_XY, d);
    825   1.7  macallan 	delay(1000);
    826   1.7  macallan 	d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_DOTCLOCK);
    827   1.7  macallan 	d &= ~(1 << CRMFB_DOTCLOCK_CLKRUN_SHIFT);
    828   1.7  macallan 	crmfb_write_reg(sc, CRMFB_DOTCLOCK, d);
    829  1.11  macallan 
    830  1.11  macallan 	/* wait for dotclock to turn off */
    831  1.11  macallan 	bail = 10000;
    832  1.11  macallan 	while ((bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_DOTCLOCK) &
    833  1.11  macallan 	    (1 << CRMFB_DOTCLOCK_CLKRUN_SHIFT)) && (bail > 0)) {
    834  1.11  macallan 		delay(10);
    835  1.11  macallan 		bail--;
    836  1.11  macallan 	}
    837   1.7  macallan 
    838   1.7  macallan 	/* reset FIFO */
    839   1.7  macallan 	d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_TILESIZE);
    840   1.7  macallan 	d |= (1 << CRMFB_FRM_TILESIZE_FIFOR_SHIFT);
    841   1.7  macallan 	crmfb_write_reg(sc, CRMFB_FRM_TILESIZE, d);
    842   1.7  macallan 	d &= ~(1 << CRMFB_FRM_TILESIZE_FIFOR_SHIFT);
    843   1.7  macallan 	crmfb_write_reg(sc, CRMFB_FRM_TILESIZE, d);
    844   1.7  macallan 
    845   1.7  macallan 	/* setup colour mode */
    846   1.7  macallan 	switch (depth) {
    847   1.7  macallan 	case 8:
    848   1.7  macallan 		h = CRMFB_MODE_TYP_I8;
    849  1.11  macallan 		tile_width = 512;
    850   1.7  macallan 		break;
    851   1.7  macallan 	case 16:
    852   1.7  macallan 		h = CRMFB_MODE_TYP_ARGB5;
    853  1.11  macallan 		tile_width = 256;
    854   1.7  macallan 		break;
    855   1.7  macallan 	case 32:
    856   1.7  macallan 		h = CRMFB_MODE_TYP_RGB8;
    857  1.11  macallan 		tile_width = 128;
    858   1.7  macallan 		break;
    859   1.7  macallan 	default:
    860   1.7  macallan 		panic("Unsupported depth");
    861   1.7  macallan 	}
    862   1.7  macallan 	d = h << CRMFB_MODE_TYP_SHIFT;
    863   1.7  macallan 	d |= CRMFB_MODE_BUF_BOTH << CRMFB_MODE_BUF_SHIFT;
    864   1.7  macallan 	for (i = 0; i < (32 * 4); i += 4)
    865   1.7  macallan 		bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_MODE + i, d);
    866   1.7  macallan 	wbflush();
    867   1.7  macallan 
    868   1.7  macallan 	/* setup tile pointer, but don't turn on DMA yet! */
    869   1.7  macallan 	h = DMAADDR(sc->sc_dmai);
    870   1.7  macallan 	d = (h >> 9) << CRMFB_FRM_CONTROL_TILEPTR_SHIFT;
    871   1.7  macallan 	crmfb_write_reg(sc, CRMFB_FRM_CONTROL, d);
    872   1.7  macallan 
    873   1.7  macallan 	/* init framebuffer width and pixel size */
    874  1.11  macallan 	/*d = (1 << CRMFB_FRM_TILESIZE_WIDTH_SHIFT);*/
    875  1.11  macallan 
    876  1.11  macallan 	d = ((int)(sc->sc_width / tile_width)) <<
    877  1.11  macallan 	    CRMFB_FRM_TILESIZE_WIDTH_SHIFT;
    878  1.11  macallan 	if ((sc->sc_width & (tile_width - 1)) != 0)
    879  1.11  macallan 		d |= sc->sc_tiles_y;
    880  1.11  macallan 
    881   1.7  macallan 	switch (depth) {
    882   1.7  macallan 	case 8:
    883   1.7  macallan 		h = CRMFB_FRM_TILESIZE_DEPTH_8;
    884   1.7  macallan 		break;
    885   1.7  macallan 	case 16:
    886   1.7  macallan 		h = CRMFB_FRM_TILESIZE_DEPTH_16;
    887   1.7  macallan 		break;
    888   1.7  macallan 	case 32:
    889   1.7  macallan 		h = CRMFB_FRM_TILESIZE_DEPTH_32;
    890   1.7  macallan 		break;
    891   1.7  macallan 	default:
    892   1.7  macallan 		panic("Unsupported depth");
    893   1.7  macallan 	}
    894   1.7  macallan 	d |= (h << CRMFB_FRM_TILESIZE_DEPTH_SHIFT);
    895   1.7  macallan 	crmfb_write_reg(sc, CRMFB_FRM_TILESIZE, d);
    896   1.7  macallan 
    897  1.11  macallan 	/*h = sc->sc_width * sc->sc_height / (512 / (depth >> 3));*/
    898  1.11  macallan 	h = sc->sc_height;
    899   1.7  macallan 	d = h << CRMFB_FRM_PIXSIZE_HEIGHT_SHIFT;
    900   1.7  macallan 	crmfb_write_reg(sc, CRMFB_FRM_PIXSIZE, d);
    901   1.7  macallan 
    902   1.7  macallan 	/* turn off firmware overlay and hardware cursor */
    903   1.7  macallan 	crmfb_write_reg(sc, CRMFB_OVR_WIDTH_TILE, 0);
    904   1.7  macallan 	crmfb_write_reg(sc, CRMFB_CURSOR_CONTROL, 0);
    905   1.7  macallan 
    906   1.7  macallan 	/* enable drawing again */
    907   1.7  macallan 	d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_DOTCLOCK);
    908   1.7  macallan 	d |= (1 << CRMFB_DOTCLOCK_CLKRUN_SHIFT);
    909   1.7  macallan 	crmfb_write_reg(sc, CRMFB_DOTCLOCK, d);
    910   1.7  macallan 	crmfb_write_reg(sc, CRMFB_VT_XY, 0);
    911   1.7  macallan 
    912   1.7  macallan 	/* turn on DMA for the framebuffer */
    913   1.7  macallan 	d = bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_FRM_CONTROL);
    914   1.7  macallan 	d |= (1 << CRMFB_FRM_CONTROL_DMAEN_SHIFT);
    915   1.7  macallan 	crmfb_write_reg(sc, CRMFB_FRM_CONTROL, d);
    916   1.7  macallan 
    917  1.10    sekiya 	/* turn off sync-on-green */
    918  1.10    sekiya 
    919  1.27      matt 	wantsync = arcbios_GetEnvironmentVariable("SyncOnGreen");
    920  1.10    sekiya 	if ( (wantsync != NULL) && (wantsync[0] == 'n') ) {
    921  1.15  macallan 		d = ( 1 << CRMFB_VT_FLAGS_SYNC_LOW_LSB) &
    922  1.15  macallan 		    CRMFB_REG_MASK(CRMFB_VT_FLAGS_SYNC_LOW_MSB,
    923  1.15  macallan 		    CRMFB_VT_FLAGS_SYNC_LOW_LSB);
    924  1.10    sekiya 		crmfb_write_reg(sc, CRMFB_VT_FLAGS, d);
    925  1.10    sekiya 	}
    926  1.10    sekiya 
    927   1.7  macallan 	sc->sc_depth = depth;
    928  1.11  macallan 
    929  1.11  macallan 	/* finally set up the drawing engine's TLB A */
    930  1.11  macallan 	v = (DMAADDR(sc->sc_dma) >> 16) & 0xffff;
    931  1.11  macallan 	tlbptr = 0;
    932  1.15  macallan 	tx = ((sc->sc_width + (tile_width - 1)) & ~(tile_width - 1)) /
    933  1.15  macallan 	    tile_width;
    934  1.14  macallan 
    935  1.21  macallan #ifdef CRMFB_DEBUG
    936  1.21  macallan 	printf("tx: %d\n", tx);
    937  1.21  macallan #endif
    938  1.21  macallan 
    939  1.21  macallan 	for (i = 0; i < 16; i++) {
    940  1.11  macallan 		reg = 0;
    941  1.11  macallan 		shift = 64;
    942  1.21  macallan 		lptr = 0;
    943  1.11  macallan 		for (j = 0; j < tx; j++) {
    944  1.11  macallan 			shift -= 16;
    945  1.11  macallan 			reg |= (((uint64_t)(v | 0x8000)) << shift);
    946  1.11  macallan 			if (shift == 0) {
    947  1.11  macallan 				shift = 64;
    948  1.11  macallan 				bus_space_write_8(sc->sc_iot, sc->sc_reh,
    949  1.21  macallan 				    CRIME_RE_TLB_A + tlbptr + lptr,
    950  1.15  macallan 				    reg);
    951  1.21  macallan #ifdef CRMFB_DEBUG
    952  1.21  macallan 				printf("%04x: %016llx\n", tlbptr + lptr, reg);
    953  1.21  macallan #endif
    954  1.21  macallan 				reg = 0;
    955  1.21  macallan 				lptr += 8;
    956  1.11  macallan 			}
    957  1.11  macallan 			v++;
    958  1.11  macallan 		}
    959  1.11  macallan 		if (shift != 64) {
    960  1.11  macallan 			bus_space_write_8(sc->sc_iot, sc->sc_reh,
    961  1.21  macallan 			    CRIME_RE_TLB_A + tlbptr + lptr, reg);
    962  1.21  macallan #ifdef CRMFB_DEBUG
    963  1.21  macallan 			printf("%04x: %016llx\n", tlbptr + lptr, reg);
    964  1.21  macallan #endif
    965  1.11  macallan 		}
    966  1.11  macallan 		tlbptr += 32;
    967  1.11  macallan 	}
    968  1.21  macallan 	sc->sc_scratch = (char *)KERNADDR(sc->sc_dma) + (0xf0000 * tx);
    969  1.11  macallan 
    970  1.21  macallan 	/* now put the last 64kB into the 1st linear TLB */
    971  1.21  macallan 	page = (sc->sc_linear >> 12) | 0x80000000;
    972  1.21  macallan 	tlbptr = 0;
    973  1.21  macallan 	for (i = 0; i < 8; i++) {
    974  1.21  macallan 		reg = ((uint64_t)page << 32) | (page + 1);
    975  1.21  macallan 		bus_space_write_8(sc->sc_iot, sc->sc_reh,
    976  1.21  macallan 		    CRIME_RE_LINEAR_A + tlbptr, reg);
    977  1.21  macallan 		page += 2;
    978  1.21  macallan 		tlbptr += 8;
    979  1.21  macallan 	}
    980  1.11  macallan 	wbflush();
    981  1.11  macallan 
    982  1.11  macallan 	/* do some very basic engine setup */
    983  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_CLIPMODE, 0);
    984  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_WINOFFSET_SRC, 0);
    985  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_WINOFFSET_DST, 0);
    986  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_PLANEMASK,
    987  1.15  macallan 	    0xffffffff);
    988  1.11  macallan 
    989  1.11  macallan 	bus_space_write_8(sc->sc_iot, sc->sc_reh, 0x20, 0);
    990  1.11  macallan 	bus_space_write_8(sc->sc_iot, sc->sc_reh, 0x28, 0);
    991  1.11  macallan 	bus_space_write_8(sc->sc_iot, sc->sc_reh, 0x30, 0);
    992  1.11  macallan 	bus_space_write_8(sc->sc_iot, sc->sc_reh, 0x38, 0);
    993  1.11  macallan 	bus_space_write_8(sc->sc_iot, sc->sc_reh, 0x40, 0);
    994  1.11  macallan 
    995  1.11  macallan 	switch (depth) {
    996  1.11  macallan 		case 8:
    997  1.11  macallan 			mode = DE_MODE_TLB_A | DE_MODE_BUFDEPTH_8 |
    998  1.11  macallan 			    DE_MODE_TYPE_CI | DE_MODE_PIXDEPTH_8;
    999  1.11  macallan 			break;
   1000  1.11  macallan 		case 16:
   1001  1.11  macallan 			mode = DE_MODE_TLB_A | DE_MODE_BUFDEPTH_16 |
   1002  1.11  macallan 			    DE_MODE_TYPE_RGB | DE_MODE_PIXDEPTH_16;
   1003  1.14  macallan 			break;
   1004  1.11  macallan 		case 32:
   1005  1.11  macallan 			mode = DE_MODE_TLB_A | DE_MODE_BUFDEPTH_32 |
   1006  1.11  macallan 			    DE_MODE_TYPE_RGBA | DE_MODE_PIXDEPTH_32;
   1007  1.14  macallan 			break;
   1008  1.11  macallan 		default:
   1009  1.11  macallan 			panic("%s: unsuported colour depth %d\n", __func__,
   1010  1.11  macallan 			    depth);
   1011  1.11  macallan 	}
   1012  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_MODE_DST, mode);
   1013  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_MODE_SRC, mode);
   1014  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_XFER_STEP_X, 1);
   1015  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_XFER_STEP_Y, 1);
   1016  1.15  macallan 
   1017  1.15  macallan 	/* initialize memory transfer engine */
   1018  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_MODE,
   1019  1.15  macallan 	    MTE_MODE_DST_ECC |
   1020  1.15  macallan 	    (MTE_TLB_A << MTE_DST_TLB_SHIFT) |
   1021  1.15  macallan 	    (MTE_TLB_A << MTE_SRC_TLB_SHIFT) |
   1022  1.15  macallan 	    (MTE_DEPTH_8 << MTE_DEPTH_SHIFT) |
   1023  1.15  macallan 	    MTE_MODE_COPY);
   1024  1.18  macallan 	sc->sc_mte_direction = 1;
   1025  1.16  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_DST_Y_STEP, 1);
   1026  1.16  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_SRC_Y_STEP, 1);
   1027  1.15  macallan 
   1028   1.7  macallan 	return 0;
   1029   1.7  macallan }
   1030   1.7  macallan 
   1031  1.19  macallan static void
   1032  1.18  macallan crmfb_set_mte_direction(struct crmfb_softc *sc, int dir)
   1033  1.18  macallan {
   1034  1.18  macallan 	if (dir == sc->sc_mte_direction)
   1035  1.18  macallan 		return;
   1036  1.18  macallan 
   1037  1.18  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_DST_Y_STEP, dir);
   1038  1.18  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_SRC_Y_STEP, dir);
   1039  1.20  macallan 	sc->sc_mte_direction = dir;
   1040  1.18  macallan }
   1041  1.18  macallan 
   1042   1.7  macallan static void
   1043   1.7  macallan crmfb_setup_palette(struct crmfb_softc *sc)
   1044   1.7  macallan {
   1045   1.7  macallan 	int i;
   1046   1.7  macallan 
   1047   1.7  macallan 	for (i = 0; i < 256; i++) {
   1048   1.7  macallan 		crmfb_set_palette(sc, i, rasops_cmap[(i * 3) + 2],
   1049   1.7  macallan 		    rasops_cmap[(i * 3) + 1], rasops_cmap[(i * 3) + 0]);
   1050   1.7  macallan 		sc->sc_cmap_red[i] = rasops_cmap[(i * 3) + 2];
   1051   1.7  macallan 		sc->sc_cmap_green[i] = rasops_cmap[(i * 3) + 1];
   1052   1.7  macallan 		sc->sc_cmap_blue[i] = rasops_cmap[(i * 3) + 0];
   1053   1.7  macallan 	}
   1054   1.7  macallan }
   1055  1.11  macallan 
   1056  1.11  macallan static inline void
   1057  1.11  macallan crmfb_wait_idle(struct crmfb_softc *sc)
   1058  1.11  macallan {
   1059  1.11  macallan 	int i = 0;
   1060  1.11  macallan 
   1061  1.11  macallan 	do {
   1062  1.11  macallan 		i++;
   1063  1.11  macallan 	} while (((bus_space_read_4(sc->sc_iot, sc->sc_reh, CRIME_DE_STATUS) &
   1064  1.11  macallan 		   CRIME_DE_IDLE) == 0) && (i < 100000000));
   1065  1.11  macallan 	if (i >= 100000000)
   1066  1.11  macallan 		aprint_error("crmfb_wait_idle() timed out\n");
   1067  1.11  macallan }
   1068  1.11  macallan 
   1069  1.11  macallan static void
   1070  1.11  macallan crmfb_fill_rect(struct crmfb_softc *sc, int x, int y, int width, int height,
   1071  1.11  macallan     uint32_t colour)
   1072  1.11  macallan {
   1073  1.11  macallan 	crmfb_wait_idle(sc);
   1074  1.18  macallan 	crmfb_set_mte_direction(sc, 1);
   1075  1.17  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_MODE,
   1076  1.17  macallan 	    MTE_MODE_DST_ECC |
   1077  1.17  macallan 	    (MTE_TLB_A << MTE_DST_TLB_SHIFT) |
   1078  1.17  macallan 	    (MTE_TLB_A << MTE_SRC_TLB_SHIFT) |
   1079  1.17  macallan 	    (MTE_DEPTH_8 << MTE_DEPTH_SHIFT) |
   1080  1.17  macallan 	    0);
   1081  1.17  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_BG, colour);
   1082  1.17  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_DST0,
   1083  1.11  macallan 	    (x << 16) | (y & 0xffff));
   1084  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1085  1.17  macallan 	    CRIME_MTE_DST1 | CRIME_DE_START,
   1086  1.11  macallan 	    ((x + width - 1) << 16) | ((y + height - 1) & 0xffff));
   1087  1.11  macallan }
   1088  1.11  macallan 
   1089  1.11  macallan static void
   1090  1.11  macallan crmfb_bitblt(struct crmfb_softc *sc, int xs, int ys, int xd, int yd,
   1091  1.11  macallan     int wi, int he, uint32_t rop)
   1092  1.11  macallan {
   1093  1.11  macallan 	uint32_t prim = DE_PRIM_RECTANGLE;
   1094  1.11  macallan 	int rxa, rya, rxe, rye, rxs, rys;
   1095  1.11  macallan 	crmfb_wait_idle(sc);
   1096  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_DRAWMODE,
   1097  1.11  macallan 	    DE_DRAWMODE_PLANEMASK | DE_DRAWMODE_BYTEMASK | DE_DRAWMODE_ROP |
   1098  1.11  macallan 	    DE_DRAWMODE_XFER_EN);
   1099  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_ROP, rop);
   1100  1.11  macallan 	if (xs < xd) {
   1101  1.11  macallan 		prim |= DE_PRIM_RL;
   1102  1.11  macallan 		rxe = xd;
   1103  1.11  macallan 		rxa = xd + wi - 1;
   1104  1.11  macallan 		rxs = xs + wi - 1;
   1105  1.11  macallan 	} else {
   1106  1.11  macallan 		prim |= DE_PRIM_LR;
   1107  1.11  macallan 		rxe = xd + wi - 1;
   1108  1.11  macallan 		rxa = xd;
   1109  1.11  macallan 		rxs = xs;
   1110  1.11  macallan 	}
   1111  1.11  macallan 	if (ys < yd) {
   1112  1.11  macallan 		prim |= DE_PRIM_BT;
   1113  1.11  macallan 		rye = yd;
   1114  1.11  macallan 		rya = yd + he - 1;
   1115  1.11  macallan 		rys = ys + he - 1;
   1116  1.11  macallan 	} else {
   1117  1.11  macallan 		prim |= DE_PRIM_TB;
   1118  1.11  macallan 		rye = yd + he - 1;
   1119  1.11  macallan 		rya = yd;
   1120  1.11  macallan 		rys = ys;
   1121  1.11  macallan 	}
   1122  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_PRIMITIVE, prim);
   1123  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_XFER_ADDR_SRC,
   1124  1.11  macallan 	    (rxs << 16) | (rys & 0xffff));
   1125  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_X_VERTEX_0,
   1126  1.11  macallan 	    (rxa << 16) | (rya & 0xffff));
   1127  1.11  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1128  1.11  macallan 	    CRIME_DE_X_VERTEX_1 | CRIME_DE_START,
   1129  1.11  macallan 	    (rxe << 16) | (rye & 0xffff));
   1130  1.11  macallan }
   1131  1.11  macallan 
   1132  1.15  macallan static void
   1133  1.15  macallan crmfb_scroll(struct crmfb_softc *sc, int xs, int ys, int xd, int yd,
   1134  1.15  macallan     int wi, int he)
   1135  1.15  macallan {
   1136  1.15  macallan 	int rxa, rya, rxe, rye, rxd, ryd, rxde, ryde;
   1137  1.15  macallan 
   1138  1.16  macallan 	rxa = xs;
   1139  1.16  macallan 	rxe = xs + wi - 1;
   1140  1.16  macallan 	rxd = xd;
   1141  1.16  macallan 	rxde = xd + wi - 1;
   1142  1.16  macallan 
   1143  1.15  macallan 	crmfb_wait_idle(sc);
   1144  1.16  macallan 
   1145  1.17  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_MODE,
   1146  1.17  macallan 	    MTE_MODE_DST_ECC |
   1147  1.17  macallan 	    (MTE_TLB_A << MTE_DST_TLB_SHIFT) |
   1148  1.17  macallan 	    (MTE_TLB_A << MTE_SRC_TLB_SHIFT) |
   1149  1.17  macallan 	    (MTE_DEPTH_8 << MTE_DEPTH_SHIFT) |
   1150  1.17  macallan 	    MTE_MODE_COPY);
   1151  1.17  macallan 
   1152  1.15  macallan 	if (ys < yd) {
   1153  1.15  macallan 		/* bottom to top */
   1154  1.15  macallan 		rye = ys;
   1155  1.15  macallan 		rya = ys + he - 1;
   1156  1.15  macallan 		ryd = yd + he - 1;
   1157  1.15  macallan 		ryde = yd;
   1158  1.18  macallan 		crmfb_set_mte_direction(sc, -1);
   1159  1.15  macallan 	} else {
   1160  1.15  macallan 		/* top to bottom */
   1161  1.15  macallan 		rye = ys + he - 1;
   1162  1.15  macallan 		rya = ys;
   1163  1.15  macallan 		ryd = yd;
   1164  1.15  macallan 		ryde = yd + he - 1;
   1165  1.18  macallan 		crmfb_set_mte_direction(sc, 1);
   1166  1.15  macallan 	}
   1167  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_SRC0,
   1168  1.15  macallan 	    (rxa << 16) | rya);
   1169  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_SRC1,
   1170  1.15  macallan 	    (rxe << 16) | rye);
   1171  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1172  1.15  macallan 	    CRIME_MTE_DST0,
   1173  1.15  macallan 	    (rxd << 16) | ryd);
   1174  1.15  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_MTE_DST1 |
   1175  1.15  macallan 	    CRIME_DE_START,
   1176  1.15  macallan 	    (rxde << 16) | ryde);
   1177  1.15  macallan }
   1178  1.15  macallan 
   1179  1.11  macallan static void
   1180  1.11  macallan crmfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
   1181  1.11  macallan {
   1182  1.11  macallan 	struct rasops_info *ri = cookie;
   1183  1.11  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1184  1.11  macallan 	int32_t xs, xd, y, width, height;
   1185  1.11  macallan 
   1186  1.11  macallan 	xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol;
   1187  1.11  macallan 	xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol;
   1188  1.11  macallan 	y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   1189  1.11  macallan 	width = ri->ri_font->fontwidth * ncols;
   1190  1.11  macallan 	height = ri->ri_font->fontheight;
   1191  1.11  macallan 	crmfb_bitblt(scr->scr_cookie, xs, y, xd, y, width, height, 3);
   1192  1.11  macallan }
   1193  1.11  macallan 
   1194  1.11  macallan static void
   1195  1.11  macallan crmfb_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
   1196  1.11  macallan {
   1197  1.11  macallan 	struct rasops_info *ri = cookie;
   1198  1.11  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1199  1.11  macallan 	int32_t x, y, width, height, bg;
   1200  1.11  macallan 
   1201  1.11  macallan 	x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol;
   1202  1.11  macallan 	y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   1203  1.11  macallan 	width = ri->ri_font->fontwidth * ncols;
   1204  1.11  macallan 	height = ri->ri_font->fontheight;
   1205  1.11  macallan 	bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
   1206  1.11  macallan 	crmfb_fill_rect(scr->scr_cookie, x, y, width, height, bg);
   1207  1.11  macallan }
   1208  1.11  macallan 
   1209  1.11  macallan static void
   1210  1.11  macallan crmfb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
   1211  1.11  macallan {
   1212  1.11  macallan 	struct rasops_info *ri = cookie;
   1213  1.11  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1214  1.11  macallan 	int32_t x, ys, yd, width, height;
   1215  1.11  macallan 
   1216  1.11  macallan 	x = ri->ri_xorigin;
   1217  1.11  macallan 	ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow;
   1218  1.11  macallan 	yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow;
   1219  1.11  macallan 	width = ri->ri_emuwidth;
   1220  1.11  macallan 	height = ri->ri_font->fontheight * nrows;
   1221  1.15  macallan 
   1222  1.16  macallan 	crmfb_scroll(scr->scr_cookie, x, ys, x, yd, width, height);
   1223  1.11  macallan }
   1224  1.11  macallan 
   1225  1.11  macallan static void
   1226  1.11  macallan crmfb_eraserows(void *cookie, int row, int nrows, long fillattr)
   1227  1.11  macallan {
   1228  1.11  macallan 	struct rasops_info *ri = cookie;
   1229  1.11  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1230  1.11  macallan 	int32_t x, y, width, height, bg;
   1231  1.11  macallan 
   1232  1.11  macallan 	if ((row == 0) && (nrows == ri->ri_rows)) {
   1233  1.11  macallan 		x = y = 0;
   1234  1.11  macallan 		width = ri->ri_width;
   1235  1.11  macallan 		height = ri->ri_height;
   1236  1.11  macallan 	} else {
   1237  1.11  macallan 		x = ri->ri_xorigin;
   1238  1.11  macallan 		y = ri->ri_yorigin + ri->ri_font->fontheight * row;
   1239  1.11  macallan 		width = ri->ri_emuwidth;
   1240  1.11  macallan 		height = ri->ri_font->fontheight * nrows;
   1241  1.11  macallan 	}
   1242  1.11  macallan 	bg = (uint32_t)ri->ri_devcmap[(fillattr >> 16) & 0xff];
   1243  1.11  macallan 	crmfb_fill_rect(scr->scr_cookie, x, y, width, height, bg);
   1244  1.11  macallan }
   1245  1.11  macallan 
   1246  1.11  macallan static void
   1247  1.11  macallan crmfb_cursor(void *cookie, int on, int row, int col)
   1248  1.11  macallan {
   1249  1.11  macallan 	struct rasops_info *ri = cookie;
   1250  1.11  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1251  1.11  macallan 	struct crmfb_softc *sc = scr->scr_cookie;
   1252  1.11  macallan 	int x, y, wi,he;
   1253  1.11  macallan 
   1254  1.11  macallan 	wi = ri->ri_font->fontwidth;
   1255  1.11  macallan 	he = ri->ri_font->fontheight;
   1256  1.11  macallan 
   1257  1.11  macallan 	if (ri->ri_flg & RI_CURSOR) {
   1258  1.11  macallan 		x = ri->ri_ccol * wi + ri->ri_xorigin;
   1259  1.11  macallan 		y = ri->ri_crow * he + ri->ri_yorigin;
   1260  1.11  macallan 		crmfb_bitblt(sc, x, y, x, y, wi, he, 12);
   1261  1.11  macallan 		ri->ri_flg &= ~RI_CURSOR;
   1262  1.11  macallan 	}
   1263  1.11  macallan 
   1264  1.11  macallan 	ri->ri_crow = row;
   1265  1.11  macallan 	ri->ri_ccol = col;
   1266  1.11  macallan 
   1267  1.11  macallan 	if (on)
   1268  1.11  macallan 	{
   1269  1.11  macallan 		x = ri->ri_ccol * wi + ri->ri_xorigin;
   1270  1.11  macallan 		y = ri->ri_crow * he + ri->ri_yorigin;
   1271  1.11  macallan 		crmfb_bitblt(sc, x, y, x, y, wi, he, 12);
   1272  1.11  macallan 		ri->ri_flg |= RI_CURSOR;
   1273  1.11  macallan 	}
   1274  1.11  macallan }
   1275  1.11  macallan 
   1276  1.11  macallan static void
   1277  1.11  macallan crmfb_putchar(void *cookie, int row, int col, u_int c, long attr)
   1278  1.11  macallan {
   1279  1.11  macallan 	struct rasops_info *ri = cookie;
   1280  1.11  macallan 	struct vcons_screen *scr = ri->ri_hw;
   1281  1.11  macallan 	struct crmfb_softc *sc = scr->scr_cookie;
   1282  1.28  macallan 	struct wsdisplay_font *font = PICK_FONT(ri, c);
   1283  1.28  macallan 	uint32_t bg, fg;
   1284  1.28  macallan 	int x, y, wi, he, i, uc;
   1285  1.28  macallan 	uint8_t *fd8;
   1286  1.28  macallan 	uint16_t *fd16;
   1287  1.28  macallan 	void *fd;
   1288  1.11  macallan 
   1289  1.28  macallan 	wi = font->fontwidth;
   1290  1.28  macallan 	he = font->fontheight;
   1291  1.11  macallan 
   1292  1.11  macallan 	x = ri->ri_xorigin + col * wi;
   1293  1.11  macallan 	y = ri->ri_yorigin + row * he;
   1294  1.11  macallan 
   1295  1.17  macallan 	bg = ri->ri_devcmap[(attr >> 16) & 0xff];
   1296  1.28  macallan 	fg = ri->ri_devcmap[(attr >> 24) & 0xff];
   1297  1.28  macallan 	uc = c - font->firstchar;
   1298  1.28  macallan 	fd = (uint8_t *)font->data + uc * ri->ri_fontscale;
   1299  1.11  macallan 	if (c == 0x20) {
   1300  1.11  macallan 		crmfb_fill_rect(sc, x, y, wi, he, bg);
   1301  1.11  macallan 	} else {
   1302  1.28  macallan 		crmfb_wait_idle(sc);
   1303  1.28  macallan 		/* setup */
   1304  1.28  macallan 		bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_ROP, 3);
   1305  1.28  macallan 		bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_FG, fg);
   1306  1.28  macallan 		bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_BG, bg);
   1307  1.28  macallan 		bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_DRAWMODE,
   1308  1.28  macallan 		    DE_DRAWMODE_PLANEMASK | DE_DRAWMODE_BYTEMASK |
   1309  1.28  macallan 		    DE_DRAWMODE_ROP |
   1310  1.28  macallan 		    DE_DRAWMODE_OPAQUE_STIP | DE_DRAWMODE_POLY_STIP);
   1311  1.28  macallan 		bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_PRIMITIVE,
   1312  1.28  macallan 		    DE_PRIM_RECTANGLE | DE_PRIM_LR | DE_PRIM_TB);
   1313  1.28  macallan 		bus_space_write_4(sc->sc_iot, sc->sc_reh, CRIME_DE_STIPPLE_MODE,
   1314  1.28  macallan 		    0x001f0000);
   1315  1.28  macallan 		/* now let's feed the engine */
   1316  1.28  macallan 		if (font->stride == 1) {
   1317  1.28  macallan 			/* shovel in 8 bit quantities */
   1318  1.28  macallan 			fd8 = fd;
   1319  1.28  macallan 			for (i = 0; i < he; i++) {
   1320  1.28  macallan 				/*
   1321  1.28  macallan 				 * the pipeline should be long enough to
   1322  1.28  macallan 				 * draw any character without having to wait
   1323  1.28  macallan 				 */
   1324  1.28  macallan 				bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1325  1.28  macallan 				    CRIME_DE_STIPPLE_PAT, *fd8 << 24);
   1326  1.28  macallan 				bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1327  1.28  macallan 				    CRIME_DE_X_VERTEX_0, (x << 16) | y);
   1328  1.28  macallan 				bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1329  1.28  macallan 				    CRIME_DE_X_VERTEX_1 | CRIME_DE_START,
   1330  1.28  macallan 				    ((x + wi) << 16) | y);
   1331  1.28  macallan 				y++;
   1332  1.28  macallan 				fd8++;
   1333  1.28  macallan 			}
   1334  1.28  macallan 		} else if (font->stride == 2) {
   1335  1.28  macallan 			/* shovel in 16 bit quantities */
   1336  1.28  macallan 			fd16 = fd;
   1337  1.28  macallan 			for (i = 0; i < he; i++) {
   1338  1.28  macallan 				/*
   1339  1.28  macallan 				 * the pipeline should be long enough to
   1340  1.28  macallan 				 * draw any character without having to wait
   1341  1.28  macallan 				 */
   1342  1.28  macallan 				bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1343  1.28  macallan 				    CRIME_DE_STIPPLE_PAT, *fd16 << 16);
   1344  1.28  macallan 				bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1345  1.28  macallan 				    CRIME_DE_X_VERTEX_0, (x << 16) | y);
   1346  1.28  macallan 				bus_space_write_4(sc->sc_iot, sc->sc_reh,
   1347  1.28  macallan 				    CRIME_DE_X_VERTEX_1 | CRIME_DE_START,
   1348  1.28  macallan 				    ((x + wi) << 16) | y);
   1349  1.28  macallan 				y++;
   1350  1.28  macallan 				fd16++;
   1351  1.28  macallan 			}
   1352  1.28  macallan 		}
   1353  1.11  macallan 	}
   1354  1.11  macallan }
   1355  1.30  macallan 
   1356  1.30  macallan static void
   1357  1.30  macallan crmfb_setup_ddc(struct crmfb_softc *sc)
   1358  1.30  macallan {
   1359  1.30  macallan 	int i;
   1360  1.30  macallan 	char edid_data[128];
   1361  1.30  macallan 	struct edid_info ei;
   1362  1.30  macallan 
   1363  1.30  macallan 	memset(edid_data, 0, 128);
   1364  1.30  macallan 	sc->sc_i2c.ic_cookie = sc;
   1365  1.30  macallan 	sc->sc_i2c.ic_acquire_bus = crmfb_i2c_acquire_bus;
   1366  1.30  macallan 	sc->sc_i2c.ic_release_bus = crmfb_i2c_release_bus;
   1367  1.30  macallan 	sc->sc_i2c.ic_send_start = crmfb_i2c_send_start;
   1368  1.30  macallan 	sc->sc_i2c.ic_send_stop = crmfb_i2c_send_stop;
   1369  1.30  macallan 	sc->sc_i2c.ic_initiate_xfer = crmfb_i2c_initiate_xfer;
   1370  1.30  macallan 	sc->sc_i2c.ic_read_byte = crmfb_i2c_read_byte;
   1371  1.30  macallan 	sc->sc_i2c.ic_write_byte = crmfb_i2c_write_byte;
   1372  1.30  macallan 	sc->sc_i2c.ic_exec = NULL;
   1373  1.30  macallan 	i = 0;
   1374  1.30  macallan 	while (edid_data[1] == 0 && i++ < 10)
   1375  1.30  macallan 		ddc_read_edid(&sc->sc_i2c, edid_data, 128);
   1376  1.30  macallan 	if (i > 1)
   1377  1.30  macallan 		aprint_debug_dev(sc->sc_dev,
   1378  1.30  macallan 		    "had to try %d times to get EDID data\n", i);
   1379  1.30  macallan 	if (i < 11) {
   1380  1.30  macallan 		edid_parse(edid_data, &ei);
   1381  1.30  macallan 		edid_print(&ei);
   1382  1.30  macallan 	}
   1383  1.30  macallan }
   1384  1.30  macallan 
   1385  1.30  macallan /* I2C bitbanging */
   1386  1.30  macallan static void
   1387  1.30  macallan crmfb_i2cbb_set_bits(void *cookie, uint32_t bits)
   1388  1.30  macallan {
   1389  1.30  macallan 	struct crmfb_softc *sc = cookie;
   1390  1.30  macallan 
   1391  1.30  macallan 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, CRMFB_I2C_VGA, bits ^ 3);
   1392  1.30  macallan }
   1393  1.30  macallan 
   1394  1.30  macallan static void
   1395  1.30  macallan crmfb_i2cbb_set_dir(void *cookie, uint32_t dir)
   1396  1.30  macallan {
   1397  1.30  macallan 
   1398  1.30  macallan 	/* Nothing to do */
   1399  1.30  macallan }
   1400  1.30  macallan 
   1401  1.30  macallan static uint32_t
   1402  1.30  macallan crmfb_i2cbb_read(void *cookie)
   1403  1.30  macallan {
   1404  1.30  macallan 	struct crmfb_softc *sc = cookie;
   1405  1.30  macallan 
   1406  1.30  macallan 	return bus_space_read_4(sc->sc_iot, sc->sc_ioh, CRMFB_I2C_VGA) ^ 3;
   1407  1.30  macallan }
   1408  1.30  macallan 
   1409  1.30  macallan /* higher level I2C stuff */
   1410  1.30  macallan static int
   1411  1.30  macallan crmfb_i2c_acquire_bus(void *cookie, int flags)
   1412  1.30  macallan {
   1413  1.30  macallan 
   1414  1.30  macallan 	/* private bus */
   1415  1.30  macallan 	return 0;
   1416  1.30  macallan }
   1417  1.30  macallan 
   1418  1.30  macallan static void
   1419  1.30  macallan crmfb_i2c_release_bus(void *cookie, int flags)
   1420  1.30  macallan {
   1421  1.30  macallan 
   1422  1.30  macallan 	/* private bus */
   1423  1.30  macallan }
   1424  1.30  macallan 
   1425  1.30  macallan static int
   1426  1.30  macallan crmfb_i2c_send_start(void *cookie, int flags)
   1427  1.30  macallan {
   1428  1.30  macallan 
   1429  1.30  macallan 	return i2c_bitbang_send_start(cookie, flags, &crmfb_i2cbb_ops);
   1430  1.30  macallan }
   1431  1.30  macallan 
   1432  1.30  macallan static int
   1433  1.30  macallan crmfb_i2c_send_stop(void *cookie, int flags)
   1434  1.30  macallan {
   1435  1.30  macallan 
   1436  1.30  macallan 	return i2c_bitbang_send_stop(cookie, flags, &crmfb_i2cbb_ops);
   1437  1.30  macallan }
   1438  1.30  macallan 
   1439  1.30  macallan static int
   1440  1.30  macallan crmfb_i2c_initiate_xfer(void *cookie, i2c_addr_t addr, int flags)
   1441  1.30  macallan {
   1442  1.30  macallan 
   1443  1.30  macallan 	return i2c_bitbang_initiate_xfer(cookie, addr, flags,
   1444  1.30  macallan 	    &crmfb_i2cbb_ops);
   1445  1.30  macallan }
   1446  1.30  macallan 
   1447  1.30  macallan static int
   1448  1.30  macallan crmfb_i2c_read_byte(void *cookie, uint8_t *valp, int flags)
   1449  1.30  macallan {
   1450  1.30  macallan 
   1451  1.30  macallan 	return i2c_bitbang_read_byte(cookie, valp, flags, &crmfb_i2cbb_ops);
   1452  1.30  macallan }
   1453  1.30  macallan 
   1454  1.30  macallan static int
   1455  1.30  macallan crmfb_i2c_write_byte(void *cookie, uint8_t val, int flags)
   1456  1.30  macallan {
   1457  1.30  macallan 
   1458  1.30  macallan 	return i2c_bitbang_write_byte(cookie, val, flags, &crmfb_i2cbb_ops);
   1459  1.30  macallan }
   1460