Home | History | Annotate | Line # | Download | only in dev
plumvideo.c revision 1.1
      1  1.1  uch /*	$NetBSD: plumvideo.c,v 1.1 1999/11/21 06:50:27 uch Exp $ */
      2  1.1  uch 
      3  1.1  uch /*
      4  1.1  uch  * Copyright (c) 1999, by UCHIYAMA Yasushi
      5  1.1  uch  * All rights reserved.
      6  1.1  uch  *
      7  1.1  uch  * Redistribution and use in source and binary forms, with or without
      8  1.1  uch  * modification, are permitted provided that the following conditions
      9  1.1  uch  * are met:
     10  1.1  uch  * 1. Redistributions of source code must retain the above copyright
     11  1.1  uch  *    notice, this list of conditions and the following disclaimer.
     12  1.1  uch  * 2. The name of the developer may NOT be used to endorse or promote products
     13  1.1  uch  *    derived from this software without specific prior written permission.
     14  1.1  uch  *
     15  1.1  uch  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     16  1.1  uch  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     17  1.1  uch  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     18  1.1  uch  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19  1.1  uch  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  1.1  uch  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     21  1.1  uch  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  1.1  uch  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  1.1  uch  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  1.1  uch  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  1.1  uch  * SUCH DAMAGE.
     26  1.1  uch  *
     27  1.1  uch  */
     28  1.1  uch 
     29  1.1  uch #include "opt_tx39_debug.h"
     30  1.1  uch #include "biconsdev.h"
     31  1.1  uch 
     32  1.1  uch #include <sys/param.h>
     33  1.1  uch #include <sys/systm.h>
     34  1.1  uch #include <sys/device.h>
     35  1.1  uch 
     36  1.1  uch #include <machine/bus.h>
     37  1.1  uch #include <machine/intr.h>
     38  1.1  uch 
     39  1.1  uch #include <hpcmips/tx/tx39var.h>
     40  1.1  uch #include <hpcmips/dev/plumvar.h>
     41  1.1  uch #include <hpcmips/dev/plumicuvar.h>
     42  1.1  uch #include <hpcmips/dev/plumpowervar.h>
     43  1.1  uch #include <hpcmips/dev/plumvideoreg.h>
     44  1.1  uch 
     45  1.1  uch #if NBICONSDEV > 0
     46  1.1  uch #include <machine/bootinfo.h>
     47  1.1  uch #include <hpcmips/dev/biconsvar.h>
     48  1.1  uch #include <hpcmips/dev/bicons.h>
     49  1.1  uch #endif /* NBICONSDEV */
     50  1.1  uch 
     51  1.1  uch int	plumvideo_match __P((struct device*, struct cfdata*, void*));
     52  1.1  uch void	plumvideo_attach __P((struct device*, struct device*, void*));
     53  1.1  uch int	plumvideo_print __P((void*, const char*));
     54  1.1  uch 
     55  1.1  uch struct plumvideo_softc {
     56  1.1  uch 	struct	device		sc_dev;
     57  1.1  uch 	plum_chipset_tag_t	sc_pc;
     58  1.1  uch 	bus_space_tag_t		sc_regt;
     59  1.1  uch 	bus_space_handle_t	sc_regh;
     60  1.1  uch 	bus_space_tag_t		sc_iot;
     61  1.1  uch 	bus_space_handle_t	sc_ioh;
     62  1.1  uch };
     63  1.1  uch 
     64  1.1  uch struct cfattach plumvideo_ca = {
     65  1.1  uch 	sizeof(struct plumvideo_softc), plumvideo_match, plumvideo_attach
     66  1.1  uch };
     67  1.1  uch 
     68  1.1  uch struct fb_attach_args {
     69  1.1  uch 	const char *fba_name;
     70  1.1  uch };
     71  1.1  uch 
     72  1.1  uch void	plumvideo_dump __P((struct plumvideo_softc*));
     73  1.1  uch #if NBICONSDEV > 0
     74  1.1  uch void	plumvideo_biconsinit __P((struct plumvideo_softc*));
     75  1.1  uch #endif /* NBICONSDEV */
     76  1.1  uch 
     77  1.1  uch int
     78  1.1  uch plumvideo_match(parent, cf, aux)
     79  1.1  uch 	struct device *parent;
     80  1.1  uch 	struct cfdata *cf;
     81  1.1  uch 	void *aux;
     82  1.1  uch {
     83  1.1  uch 	return 1;
     84  1.1  uch }
     85  1.1  uch 
     86  1.1  uch void
     87  1.1  uch plumvideo_attach(parent, self, aux)
     88  1.1  uch 	struct device *parent;
     89  1.1  uch 	struct device *self;
     90  1.1  uch 	void *aux;
     91  1.1  uch {
     92  1.1  uch 	struct plum_attach_args *pa = aux;
     93  1.1  uch 	struct plumvideo_softc *sc = (void*)self;
     94  1.1  uch 	struct fb_attach_args fba;
     95  1.1  uch 
     96  1.1  uch 	sc->sc_pc	= pa->pa_pc;
     97  1.1  uch 	sc->sc_regt	= pa->pa_regt;
     98  1.1  uch 	sc->sc_iot	= pa->pa_iot;
     99  1.1  uch 
    100  1.1  uch 	if (bus_space_map(sc->sc_regt, PLUM_VIDEO_REGBASE,
    101  1.1  uch 			  PLUM_VIDEO_REGSIZE, 0, &sc->sc_regh)) {
    102  1.1  uch 		printf(": register map failed\n");
    103  1.1  uch 		return;
    104  1.1  uch 	}
    105  1.1  uch 	if (bus_space_map(sc->sc_iot, PLUM_VIDEO_VRAM_IOBASE,
    106  1.1  uch 			  PLUM_VIDEO_VRAM_IOSIZE, 0, &sc->sc_ioh)) {
    107  1.1  uch 		printf(": V-RAM map failed\n");
    108  1.1  uch 		return;
    109  1.1  uch 	}
    110  1.1  uch 
    111  1.1  uch 	printf("\n");
    112  1.1  uch 	plum_power_disestablish(sc->sc_pc, PLUM_PWR_LCD);
    113  1.1  uch 	plum_power_disestablish(sc->sc_pc, PLUM_PWR_BKL);
    114  1.1  uch 	delay(100);
    115  1.1  uch 	plum_power_establish(sc->sc_pc, PLUM_PWR_LCD);
    116  1.1  uch 	plum_power_establish(sc->sc_pc, PLUM_PWR_BKL);
    117  1.1  uch 	delay(100);
    118  1.1  uch 
    119  1.1  uch //	plumvideo_dump(sc);
    120  1.1  uch #if NBICONSDEV > 0
    121  1.1  uch 	/* Enable builtin console */
    122  1.1  uch 	plumvideo_biconsinit(sc);
    123  1.1  uch #endif /* NBICONSDEV */
    124  1.1  uch 
    125  1.1  uch 	/* Attach frame buffer device */
    126  1.1  uch 	fba.fba_name = "fb";
    127  1.1  uch 	config_found(self, &fba, plumvideo_print);
    128  1.1  uch }
    129  1.1  uch 
    130  1.1  uch int
    131  1.1  uch plumvideo_print(aux, pnp)
    132  1.1  uch 	void *aux;
    133  1.1  uch 	const char *pnp;
    134  1.1  uch {
    135  1.1  uch 	return pnp ? QUIET : UNCONF;
    136  1.1  uch }
    137  1.1  uch 
    138  1.1  uch 
    139  1.1  uch #if NBICONSDEV > 0
    140  1.1  uch void
    141  1.1  uch plumvideo_biconsinit(sc)
    142  1.1  uch 	struct plumvideo_softc *sc;
    143  1.1  uch {
    144  1.1  uch 	bus_space_tag_t regt = sc->sc_regt;
    145  1.1  uch 	bus_space_handle_t regh = sc->sc_regh;
    146  1.1  uch 	bus_space_handle_t ioh = sc->sc_ioh;
    147  1.1  uch 	plumreg_t reg;
    148  1.1  uch 
    149  1.1  uch 	reg = plum_conf_read(regt, regh, PLUM_VIDEO_PLGMD_REG);
    150  1.1  uch 	switch (reg & PLUM_VIDEO_PLGMD_MASK) {
    151  1.1  uch 	default:
    152  1.1  uch 		reg |= PLUM_VIDEO_PLGMD_8BPP; /* XXX */
    153  1.1  uch 		plum_conf_write(regt, regh, PLUM_VIDEO_PLGMD_REG, reg);
    154  1.1  uch 		/* FALLTHROUGH */
    155  1.1  uch 	case PLUM_VIDEO_PLGMD_8BPP:
    156  1.1  uch 		bootinfo->fb_line_bytes = bootinfo->fb_width * 8 / 8;
    157  1.1  uch 		break;
    158  1.1  uch 	case PLUM_VIDEO_PLGMD_16BPP:
    159  1.1  uch 		bootinfo->fb_line_bytes = bootinfo->fb_width * 16 / 8;
    160  1.1  uch 		break;
    161  1.1  uch 	}
    162  1.1  uch 
    163  1.1  uch 	bootinfo->fb_addr = (unsigned char *)ioh;
    164  1.1  uch 
    165  1.1  uch 	/* re-install */
    166  1.1  uch 	bicons_init();
    167  1.1  uch }
    168  1.1  uch #endif /* NBICONSDEV */
    169  1.1  uch 
    170  1.1  uch void
    171  1.1  uch plumvideo_dump(sc)
    172  1.1  uch 	struct plumvideo_softc *sc;
    173  1.1  uch {
    174  1.1  uch 	bus_space_tag_t regt = sc->sc_regt;
    175  1.1  uch 	bus_space_handle_t regh = sc->sc_regh;
    176  1.1  uch 	bus_space_tag_t iot = sc->sc_iot;
    177  1.1  uch 	bus_space_handle_t ioh = sc->sc_ioh;
    178  1.1  uch 
    179  1.1  uch 	plumreg_t reg;
    180  1.1  uch 	int i, j;
    181  1.1  uch 
    182  1.1  uch 	for (i = 0; i < 0x200; i+=4) {
    183  1.1  uch 		reg = plum_conf_read(regt, regh, i);
    184  1.1  uch 		printf("%03x %08x", i, reg);
    185  1.1  uch 		bitdisp(reg);
    186  1.1  uch 	}
    187  1.1  uch 	for (j = 0; j < 10; j++) {
    188  1.1  uch 		reg = plum_conf_read(regt, regh, PLUM_VIDEO_PLILN_REG);
    189  1.1  uch 		printf("%d, %d\n", reg,
    190  1.1  uch 		       plum_conf_read(regt, regh, PLUM_VIDEO_PLCLN_REG));
    191  1.1  uch 		for (i = 0; i < PLUM_VIDEO_VRAM_IOSIZE; i += 4) {
    192  1.1  uch 			bus_space_write_4(iot, ioh, i, 0);
    193  1.1  uch 		}
    194  1.1  uch 		for (i = 0; i < PLUM_VIDEO_VRAM_IOSIZE; i += 4) {
    195  1.1  uch 			bus_space_write_4(iot, ioh, i, ~0);
    196  1.1  uch 		}
    197  1.1  uch 	}
    198  1.1  uch }
    199  1.1  uch 
    200