Home | History | Annotate | Line # | Download | only in dev
plumvideo.c revision 1.6
      1 /*	$NetBSD: plumvideo.c,v 1.6 2000/04/03 03:35:37 sato Exp $ */
      2 
      3 /*
      4  * Copyright (c) 1999, 2000, 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 #include "opt_tx39_debug.h"
     29 #include "hpcfb.h"
     30 
     31 #include <sys/param.h>
     32 #include <sys/systm.h>
     33 #include <sys/device.h>
     34 
     35 #include <dev/cons.h> /* consdev */
     36 
     37 #include <machine/bus.h>
     38 #include <machine/intr.h>
     39 
     40 #include <hpcmips/tx/tx39var.h>
     41 #include <hpcmips/dev/plumvar.h>
     42 #include <hpcmips/dev/plumicuvar.h>
     43 #include <hpcmips/dev/plumpowervar.h>
     44 #include <hpcmips/dev/plumvideoreg.h>
     45 
     46 #include <machine/bootinfo.h>
     47 
     48 #if NHPCFB > 0
     49 #include <dev/wscons/wsconsio.h>
     50 #include <arch/hpcmips/dev/hpcfbvar.h>
     51 #include <arch/hpcmips/dev/hpcfbio.h>
     52 #include <arch/hpcmips/dev/bivideovar.h>
     53 #endif
     54 #include <machine/autoconf.h> /* XXX */
     55 
     56 #ifdef PLUMVIDEODEBUG
     57 int	plumvideo_debug = 1;
     58 #define	DPRINTF(arg) if (plumvideo_debug) printf arg;
     59 #define	DPRINTFN(n, arg) if (plumvideo_debug > (n)) printf arg;
     60 #else
     61 #define	DPRINTF(arg)
     62 #define DPRINTFN(n, arg)
     63 #endif
     64 
     65 int	plumvideo_match __P((struct device*, struct cfdata*, void*));
     66 void	plumvideo_attach __P((struct device*, struct device*, void*));
     67 int	plumvideo_print __P((void*, const char*));
     68 
     69 struct plumvideo_softc {
     70 	struct	device		sc_dev;
     71 	plum_chipset_tag_t	sc_pc;
     72 	bus_space_tag_t		sc_regt;
     73 	bus_space_handle_t	sc_regh;
     74 	bus_space_tag_t		sc_iot;
     75 	bus_space_handle_t	sc_ioh;
     76 };
     77 
     78 struct cfattach plumvideo_ca = {
     79 	sizeof(struct plumvideo_softc), plumvideo_match, plumvideo_attach
     80 };
     81 
     82 struct fb_attach_args {
     83 	const char *fba_name;
     84 };
     85 
     86 int	plumvideo_init __P((struct plumvideo_softc*));
     87 #ifdef PLUMVIDEODEBUG
     88 void	plumvideo_dump __P((struct plumvideo_softc*));
     89 #endif
     90 
     91 int
     92 plumvideo_match(parent, cf, aux)
     93 	struct device *parent;
     94 	struct cfdata *cf;
     95 	void *aux;
     96 {
     97 	/*
     98 	 * VRAM area also uses as UHOSTC shared RAM.
     99 	 */
    100 	return 2; /* 1st attach group */
    101 }
    102 
    103 void
    104 plumvideo_attach(parent, self, aux)
    105 	struct device *parent;
    106 	struct device *self;
    107 	void *aux;
    108 {
    109 	struct plum_attach_args *pa = aux;
    110 	struct plumvideo_softc *sc = (void*)self;
    111 	struct mainbus_attach_args ma; /* XXX */
    112 
    113 	sc->sc_pc	= pa->pa_pc;
    114 	sc->sc_regt	= pa->pa_regt;
    115 	sc->sc_iot	= pa->pa_iot;
    116 
    117 	/*
    118 	 * map register area
    119 	 */
    120 	if (bus_space_map(sc->sc_regt, PLUM_VIDEO_REGBASE,
    121 			  PLUM_VIDEO_REGSIZE, 0, &sc->sc_regh)) {
    122 		printf(": register map failed\n");
    123 		return;
    124 	}
    125 
    126 	/*
    127 	 * Power control
    128 	 */
    129 #ifndef PLUMVIDEODEBUG
    130 	if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
    131 		/* LCD power on and display off */
    132 		plum_power_disestablish(sc->sc_pc, PLUM_PWR_LCD);
    133 		/* power off V-RAM */
    134 		plum_power_disestablish(sc->sc_pc, PLUM_PWR_EXTPW2);
    135 		/* power off LCD */
    136 		plum_power_disestablish(sc->sc_pc, PLUM_PWR_EXTPW1);
    137 		/* power off RAMDAC */
    138 		plum_power_disestablish(sc->sc_pc, PLUM_PWR_EXTPW0);
    139 		/* back-light off */
    140 		plum_power_disestablish(sc->sc_pc, PLUM_PWR_BKL);
    141 	} else
    142 #endif
    143 	{
    144 		/* LCD power on and display on */
    145 		plum_power_establish(sc->sc_pc, PLUM_PWR_LCD);
    146 		/* supply power to V-RAM */
    147 		plum_power_establish(sc->sc_pc, PLUM_PWR_EXTPW2);
    148 		/* supply power to LCD */
    149 		plum_power_establish(sc->sc_pc, PLUM_PWR_EXTPW1);
    150 		/* back-light on */
    151 		plum_power_establish(sc->sc_pc, PLUM_PWR_BKL);
    152 	}
    153 
    154 	/*
    155 	 *  Initialize LCD controller
    156 	 *	map V-RAM area.
    157 	 *	reinstall bootinfo structure.
    158 	 *	some OHCI shared-buffer hack. XXX
    159 	 */
    160 	if (plumvideo_init(sc) != 0)
    161 		return;
    162 
    163 	printf("\n");
    164 
    165 #ifdef PLUMVIDEODEBUG
    166 	if (plumvideo_debug)
    167 		plumvideo_dump(sc);
    168 #endif
    169 
    170 #if NHPCFB > 0
    171 	if(!cn_tab && hpcfb_cnattach(0, 0, 0, 0)) {
    172 		panic("plumvideo_attach: can't init fb console");
    173 	}
    174 	/* Attach frame buffer device */
    175 	ma.ma_name = "bivideo"; /* XXX */
    176 	config_found(self, &ma, plumvideo_print);
    177 #endif
    178 }
    179 
    180 int
    181 plumvideo_print(aux, pnp)
    182 	void *aux;
    183 	const char *pnp;
    184 {
    185 	return pnp ? QUIET : UNCONF;
    186 }
    187 
    188 int
    189 plumvideo_init(sc)
    190 	struct plumvideo_softc *sc;
    191 {
    192 	bus_space_tag_t regt = sc->sc_regt;
    193 	bus_space_handle_t regh = sc->sc_regh;
    194 	plumreg_t reg;
    195 	size_t vram_size;
    196 	int bpp, vram_pitch;
    197 
    198 	reg = plum_conf_read(regt, regh, PLUM_VIDEO_PLGMD_REG);
    199 	switch (reg & PLUM_VIDEO_PLGMD_MASK) {
    200 	case PLUM_VIDEO_PLGMD_16BPP:
    201 #ifdef PLUM_BIG_OHCI_BUFFER
    202 		printf("(16bpp disabled) ");
    203 		/* FALLTHROUGH */
    204 #else /* PLUM_BIG_OHCI_BUFFER */
    205 		bpp = 16;
    206 		break;
    207 #endif /* PLUM_BIG_OHCI_BUFFER */
    208 	default:
    209 		bootinfo->fb_type = BIFB_D8_FF; /* over ride */
    210 		reg &= ~PLUM_VIDEO_PLGMD_MASK;
    211 		reg |= PLUM_VIDEO_PLGMD_8BPP;
    212 		plum_conf_write(regt, regh, PLUM_VIDEO_PLGMD_REG, reg);
    213 		/* FALLTHROUGH */
    214 	case PLUM_VIDEO_PLGMD_8BPP:
    215 		bpp = 8;
    216 		break;
    217 	}
    218 
    219 	/*
    220 	 * set line byte length to bootinfo and LCD controller.
    221 	 */
    222 	bootinfo->fb_line_bytes = (bootinfo->fb_width * bpp) / 8;
    223 
    224 	vram_pitch = bootinfo->fb_width / (8 / bpp);
    225 	plum_conf_write(regt, regh, PLUM_VIDEO_PLPIT1_REG, vram_pitch);
    226 	plum_conf_write(regt, regh, PLUM_VIDEO_PLPIT2_REG,
    227 			vram_pitch & PLUM_VIDEO_PLPIT2_MASK);
    228 	plum_conf_write(regt, regh, PLUM_VIDEO_PLOFS_REG, vram_pitch);
    229 
    230 	/*
    231 	 * boot messages.
    232 	 */
    233 	printf("display mode: ");
    234 	reg = plum_conf_read(regt, regh, PLUM_VIDEO_PLGMD_REG);
    235 	switch (reg & PLUM_VIDEO_PLGMD_MASK) {
    236 	case PLUM_VIDEO_PLGMD_DISABLE:
    237 		printf("disabled ");
    238 		break;
    239 	case PLUM_VIDEO_PLGMD_8BPP:
    240 		printf("8bpp ");
    241 		break;
    242 	case PLUM_VIDEO_PLGMD_16BPP:
    243 		printf("16bpp ");
    244 		break;
    245 	}
    246 
    247 	/*
    248 	 * calcurate frame buffer size.
    249 	 */
    250 	reg = plum_conf_read(regt, regh, PLUM_VIDEO_PLGMD_REG);
    251 	vram_size = (bootinfo->fb_width * bootinfo->fb_height *
    252 		     (((reg & PLUM_VIDEO_PLGMD_MASK) == PLUM_VIDEO_PLGMD_16BPP)
    253 		      ? 16 : 8)) / 8;
    254 	vram_size = mips_round_page(vram_size);
    255 
    256 	/*
    257 	 * map V-RAM area.
    258 	 */
    259 	if (bus_space_map(sc->sc_iot, PLUM_VIDEO_VRAM_IOBASE,
    260 			  vram_size, 0, &sc->sc_ioh)) {
    261 		printf(": V-RAM map failed\n");
    262 		return (1);
    263 	}
    264 
    265 	bootinfo->fb_addr = (unsigned char *)sc->sc_ioh;
    266 
    267 	return (0);
    268 }
    269 
    270 #ifdef PLUMVIDEODEBUG
    271 void
    272 plumvideo_dump(sc)
    273 	struct plumvideo_softc *sc;
    274 {
    275 	bus_space_tag_t regt = sc->sc_regt;
    276 	bus_space_handle_t regh = sc->sc_regh;
    277 
    278 	plumreg_t reg;
    279 	int i;
    280 
    281 	for (i = 0; i < 0x160; i += 4) {
    282 		reg = plum_conf_read(regt, regh, i);
    283 		printf("0x%03x %08x", i, reg);
    284 		bitdisp(reg);
    285 	}
    286 }
    287 #endif /* PLUMVIDEODEBUG */
    288