1 /* $NetBSD: plumvideo.c,v 1.4 2000/03/13 18:49:17 uch 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 29 #include "opt_tx39_debug.h" 30 #include "hpcfb.h" 31 32 #include <sys/param.h> 33 #include <sys/systm.h> 34 #include <sys/device.h> 35 36 #include <dev/cons.h> /* consdev */ 37 38 #include <machine/bus.h> 39 #include <machine/intr.h> 40 41 #include <hpcmips/tx/tx39var.h> 42 #include <hpcmips/dev/plumvar.h> 43 #include <hpcmips/dev/plumicuvar.h> 44 #include <hpcmips/dev/plumpowervar.h> 45 #include <hpcmips/dev/plumvideoreg.h> 46 47 #include <machine/bootinfo.h> 48 49 #if NHPCFB > 0 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 void plumvideo_bootinforefil __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 if (bus_space_map(sc->sc_regt, PLUM_VIDEO_REGBASE, 118 PLUM_VIDEO_REGSIZE, 0, &sc->sc_regh)) { 119 printf(": register map failed\n"); 120 return; 121 } 122 if (bus_space_map(sc->sc_iot, PLUM_VIDEO_VRAM_IOBASE, 123 PLUM_VIDEO_VRAM_IOSIZE, 0, &sc->sc_ioh)) { 124 printf(": V-RAM map failed\n"); 125 return; 126 } 127 128 printf("\n"); 129 130 /* 131 * Power control 132 */ 133 #ifndef PLUMVIDEODEBUG 134 if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) { 135 /* LCD power on and display off */ 136 plum_power_disestablish(sc->sc_pc, PLUM_PWR_LCD); 137 /* power off V-RAM */ 138 plum_power_disestablish(sc->sc_pc, PLUM_PWR_EXTPW2); 139 /* power off LCD */ 140 plum_power_disestablish(sc->sc_pc, PLUM_PWR_EXTPW1); 141 /* power off RAMDAC */ 142 plum_power_disestablish(sc->sc_pc, PLUM_PWR_EXTPW0); 143 /* back-light off */ 144 plum_power_disestablish(sc->sc_pc, PLUM_PWR_BKL); 145 } else 146 #endif 147 { 148 /* LCD power on and display on */ 149 plum_power_establish(sc->sc_pc, PLUM_PWR_LCD); 150 /* supply power to V-RAM */ 151 plum_power_establish(sc->sc_pc, PLUM_PWR_EXTPW2); 152 /* supply power to LCD */ 153 plum_power_establish(sc->sc_pc, PLUM_PWR_EXTPW1); 154 /* back-light on */ 155 plum_power_establish(sc->sc_pc, PLUM_PWR_BKL); 156 } 157 158 /* 159 * reinstall bootinfo 160 */ 161 plumvideo_bootinforefil(sc); 162 163 #ifdef PLUMVIDEODEBUG 164 if (plumvideo_debug) 165 plumvideo_dump(sc); 166 #endif 167 168 #if NHPCFB > 0 169 if(!cn_tab && hpcfb_cnattach(0, 0, 0, 0)) { 170 panic("plumvideo_attach: can't init fb console"); 171 } 172 /* Attach frame buffer device */ 173 ma.ma_name = "bivideo"; /* XXX */ 174 config_found(self, &ma, plumvideo_print); 175 #endif 176 } 177 178 int 179 plumvideo_print(aux, pnp) 180 void *aux; 181 const char *pnp; 182 { 183 return pnp ? QUIET : UNCONF; 184 } 185 186 void 187 plumvideo_bootinforefil(sc) 188 struct plumvideo_softc *sc; 189 { 190 bus_space_tag_t regt = sc->sc_regt; 191 bus_space_handle_t regh = sc->sc_regh; 192 bus_space_handle_t ioh = sc->sc_ioh; 193 plumreg_t reg; 194 195 reg = plum_conf_read(regt, regh, PLUM_VIDEO_PLGMD_REG); 196 switch (reg & PLUM_VIDEO_PLGMD_MASK) { 197 default: 198 reg |= PLUM_VIDEO_PLGMD_8BPP; /* XXX */ 199 plum_conf_write(regt, regh, PLUM_VIDEO_PLGMD_REG, reg); 200 /* FALLTHROUGH */ 201 case PLUM_VIDEO_PLGMD_8BPP: 202 bootinfo->fb_line_bytes = bootinfo->fb_width * 8 / 8; 203 break; 204 case PLUM_VIDEO_PLGMD_16BPP: 205 bootinfo->fb_line_bytes = bootinfo->fb_width * 16 / 8; 206 break; 207 } 208 209 bootinfo->fb_addr = (unsigned char *)ioh; 210 } 211 212 #ifdef PLUMVIDEODEBUG 213 void 214 plumvideo_dump(sc) 215 struct plumvideo_softc *sc; 216 { 217 bus_space_tag_t regt = sc->sc_regt; 218 bus_space_handle_t regh = sc->sc_regh; 219 220 plumreg_t reg; 221 int i; 222 223 for (i = 0; i < 0x160; i+=4) { 224 reg = plum_conf_read(regt, regh, i); 225 printf("0x%03x %08x", i, reg); 226 bitdisp(reg); 227 } 228 } 229 #endif /* PLUMVIDEODEBUG */ 230