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