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