plumvideo.c revision 1.1 1 /* $NetBSD: plumvideo.c,v 1.1 1999/11/21 06:50:27 uch 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
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/device.h>
35
36 #include <machine/bus.h>
37 #include <machine/intr.h>
38
39 #include <hpcmips/tx/tx39var.h>
40 #include <hpcmips/dev/plumvar.h>
41 #include <hpcmips/dev/plumicuvar.h>
42 #include <hpcmips/dev/plumpowervar.h>
43 #include <hpcmips/dev/plumvideoreg.h>
44
45 #if NBICONSDEV > 0
46 #include <machine/bootinfo.h>
47 #include <hpcmips/dev/biconsvar.h>
48 #include <hpcmips/dev/bicons.h>
49 #endif /* NBICONSDEV */
50
51 int plumvideo_match __P((struct device*, struct cfdata*, void*));
52 void plumvideo_attach __P((struct device*, struct device*, void*));
53 int plumvideo_print __P((void*, const char*));
54
55 struct plumvideo_softc {
56 struct device sc_dev;
57 plum_chipset_tag_t sc_pc;
58 bus_space_tag_t sc_regt;
59 bus_space_handle_t sc_regh;
60 bus_space_tag_t sc_iot;
61 bus_space_handle_t sc_ioh;
62 };
63
64 struct cfattach plumvideo_ca = {
65 sizeof(struct plumvideo_softc), plumvideo_match, plumvideo_attach
66 };
67
68 struct fb_attach_args {
69 const char *fba_name;
70 };
71
72 void plumvideo_dump __P((struct plumvideo_softc*));
73 #if NBICONSDEV > 0
74 void plumvideo_biconsinit __P((struct plumvideo_softc*));
75 #endif /* NBICONSDEV */
76
77 int
78 plumvideo_match(parent, cf, aux)
79 struct device *parent;
80 struct cfdata *cf;
81 void *aux;
82 {
83 return 1;
84 }
85
86 void
87 plumvideo_attach(parent, self, aux)
88 struct device *parent;
89 struct device *self;
90 void *aux;
91 {
92 struct plum_attach_args *pa = aux;
93 struct plumvideo_softc *sc = (void*)self;
94 struct fb_attach_args fba;
95
96 sc->sc_pc = pa->pa_pc;
97 sc->sc_regt = pa->pa_regt;
98 sc->sc_iot = pa->pa_iot;
99
100 if (bus_space_map(sc->sc_regt, PLUM_VIDEO_REGBASE,
101 PLUM_VIDEO_REGSIZE, 0, &sc->sc_regh)) {
102 printf(": register map failed\n");
103 return;
104 }
105 if (bus_space_map(sc->sc_iot, PLUM_VIDEO_VRAM_IOBASE,
106 PLUM_VIDEO_VRAM_IOSIZE, 0, &sc->sc_ioh)) {
107 printf(": V-RAM map failed\n");
108 return;
109 }
110
111 printf("\n");
112 plum_power_disestablish(sc->sc_pc, PLUM_PWR_LCD);
113 plum_power_disestablish(sc->sc_pc, PLUM_PWR_BKL);
114 delay(100);
115 plum_power_establish(sc->sc_pc, PLUM_PWR_LCD);
116 plum_power_establish(sc->sc_pc, PLUM_PWR_BKL);
117 delay(100);
118
119 // plumvideo_dump(sc);
120 #if NBICONSDEV > 0
121 /* Enable builtin console */
122 plumvideo_biconsinit(sc);
123 #endif /* NBICONSDEV */
124
125 /* Attach frame buffer device */
126 fba.fba_name = "fb";
127 config_found(self, &fba, plumvideo_print);
128 }
129
130 int
131 plumvideo_print(aux, pnp)
132 void *aux;
133 const char *pnp;
134 {
135 return pnp ? QUIET : UNCONF;
136 }
137
138
139 #if NBICONSDEV > 0
140 void
141 plumvideo_biconsinit(sc)
142 struct plumvideo_softc *sc;
143 {
144 bus_space_tag_t regt = sc->sc_regt;
145 bus_space_handle_t regh = sc->sc_regh;
146 bus_space_handle_t ioh = sc->sc_ioh;
147 plumreg_t reg;
148
149 reg = plum_conf_read(regt, regh, PLUM_VIDEO_PLGMD_REG);
150 switch (reg & PLUM_VIDEO_PLGMD_MASK) {
151 default:
152 reg |= PLUM_VIDEO_PLGMD_8BPP; /* XXX */
153 plum_conf_write(regt, regh, PLUM_VIDEO_PLGMD_REG, reg);
154 /* FALLTHROUGH */
155 case PLUM_VIDEO_PLGMD_8BPP:
156 bootinfo->fb_line_bytes = bootinfo->fb_width * 8 / 8;
157 break;
158 case PLUM_VIDEO_PLGMD_16BPP:
159 bootinfo->fb_line_bytes = bootinfo->fb_width * 16 / 8;
160 break;
161 }
162
163 bootinfo->fb_addr = (unsigned char *)ioh;
164
165 /* re-install */
166 bicons_init();
167 }
168 #endif /* NBICONSDEV */
169
170 void
171 plumvideo_dump(sc)
172 struct plumvideo_softc *sc;
173 {
174 bus_space_tag_t regt = sc->sc_regt;
175 bus_space_handle_t regh = sc->sc_regh;
176 bus_space_tag_t iot = sc->sc_iot;
177 bus_space_handle_t ioh = sc->sc_ioh;
178
179 plumreg_t reg;
180 int i, j;
181
182 for (i = 0; i < 0x200; i+=4) {
183 reg = plum_conf_read(regt, regh, i);
184 printf("%03x %08x", i, reg);
185 bitdisp(reg);
186 }
187 for (j = 0; j < 10; j++) {
188 reg = plum_conf_read(regt, regh, PLUM_VIDEO_PLILN_REG);
189 printf("%d, %d\n", reg,
190 plum_conf_read(regt, regh, PLUM_VIDEO_PLCLN_REG));
191 for (i = 0; i < PLUM_VIDEO_VRAM_IOSIZE; i += 4) {
192 bus_space_write_4(iot, ioh, i, 0);
193 }
194 for (i = 0; i < PLUM_VIDEO_VRAM_IOSIZE; i += 4) {
195 bus_space_write_4(iot, ioh, i, ~0);
196 }
197 }
198 }
199
200