tx3912video.c revision 1.5 1 1.5 uch /* $NetBSD: tx3912video.c,v 1.5 2000/01/03 18:29:04 uch Exp $ */
2 1.1 uch
3 1.1 uch /*
4 1.5 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.2 uch #include "fb.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 #include <sys/extent.h>
35 1.1 uch
36 1.1 uch #include <machine/bus.h>
37 1.2 uch #include <machine/bootinfo.h> /* bootinfo */
38 1.1 uch
39 1.1 uch #include <hpcmips/tx/tx39var.h>
40 1.1 uch #include <hpcmips/tx/tx3912videovar.h>
41 1.1 uch #include <hpcmips/tx/tx3912videoreg.h>
42 1.1 uch
43 1.2 uch #if NFB > 0
44 1.2 uch #include <dev/rcons/raster.h>
45 1.2 uch #include <dev/wscons/wsdisplayvar.h>
46 1.2 uch #include <arch/hpcmips/dev/fbvar.h>
47 1.2 uch #endif
48 1.2 uch
49 1.3 uch void tx3912video_framebuffer_init __P((tx_chipset_tag_t, u_int32_t,
50 1.3 uch u_int32_t));
51 1.3 uch int tx3912video_framebuffer_alloc __P((tx_chipset_tag_t, u_int32_t,
52 1.3 uch int, int, int, u_int32_t*,
53 1.3 uch u_int32_t*));
54 1.1 uch void tx3912video_reset __P((tx_chipset_tag_t));
55 1.1 uch void tx3912video_resolution_init __P((tx_chipset_tag_t, int, int));
56 1.1 uch int tx3912video_fbdepth __P((tx_chipset_tag_t, int));
57 1.1 uch
58 1.1 uch static u_int32_t framebuffer, framebuffersize;
59 1.1 uch
60 1.1 uch int tx3912video_match __P((struct device*, struct cfdata*, void*));
61 1.1 uch void tx3912video_attach __P((struct device*, struct device*, void*));
62 1.1 uch int tx3912video_print __P((void*, const char*));
63 1.1 uch
64 1.1 uch struct tx3912video_softc {
65 1.1 uch struct device sc_dev;
66 1.1 uch u_int32_t sc_fbaddr;
67 1.1 uch u_int32_t sc_fbsize;
68 1.1 uch };
69 1.1 uch
70 1.1 uch struct fb_attach_args {
71 1.1 uch const char *fba_name;
72 1.1 uch };
73 1.1 uch
74 1.1 uch struct cfattach tx3912video_ca = {
75 1.3 uch sizeof(struct tx3912video_softc), tx3912video_match,
76 1.3 uch tx3912video_attach
77 1.1 uch };
78 1.1 uch
79 1.1 uch int
80 1.1 uch tx3912video_match(parent, cf, aux)
81 1.1 uch struct device *parent;
82 1.1 uch struct cfdata *cf;
83 1.1 uch void *aux;
84 1.1 uch {
85 1.1 uch return 1;
86 1.1 uch }
87 1.1 uch
88 1.1 uch void
89 1.1 uch tx3912video_attach(parent, self, aux)
90 1.1 uch struct device *parent;
91 1.1 uch struct device *self;
92 1.1 uch void *aux;
93 1.1 uch {
94 1.1 uch struct txsim_attach_args *ta = aux;
95 1.1 uch struct tx3912video_softc *sc = (void*)self;
96 1.1 uch tx_chipset_tag_t tc = ta->ta_tc;
97 1.1 uch struct fb_attach_args fba;
98 1.4 uch txreg_t reg;
99 1.1 uch
100 1.1 uch sc->sc_fbaddr = framebuffer;
101 1.1 uch sc->sc_fbsize = framebuffersize;
102 1.5 uch
103 1.5 uch printf(": ");
104 1.1 uch tx3912video_fbdepth(tc, 1);
105 1.5 uch printf(", frame buffer 0x%08x-0x%08x", sc->sc_fbaddr,
106 1.1 uch sc->sc_fbaddr + sc->sc_fbsize);
107 1.4 uch
108 1.5 uch printf("\n");
109 1.5 uch
110 1.4 uch if (bootinfo->bi_cnuse & BI_CNUSE_SERIAL) {
111 1.5 uch printf("%s: power off\n", sc->sc_dev.dv_xname);
112 1.4 uch reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
113 1.4 uch reg &= ~(TX3912_VIDEOCTRL1_DISPON |
114 1.4 uch TX3912_VIDEOCTRL1_ENVID);
115 1.4 uch tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
116 1.4 uch }
117 1.1 uch
118 1.1 uch /* Attach frame buffer device */
119 1.2 uch #if NFB > 0
120 1.2 uch if (!(bootinfo->bi_cnuse & BI_CNUSE_SERIAL)) {
121 1.2 uch if (fb_cnattach(0, 0, 0, 0)) {
122 1.2 uch panic("tx3912video_attach: can't init fb console");
123 1.2 uch }
124 1.2 uch }
125 1.1 uch fba.fba_name = "fb";
126 1.1 uch config_found(self, &fba, tx3912video_print);
127 1.2 uch #endif
128 1.1 uch }
129 1.1 uch
130 1.1 uch int
131 1.1 uch tx3912video_print(aux, pnp)
132 1.1 uch void *aux;
133 1.1 uch const char *pnp;
134 1.1 uch {
135 1.1 uch return pnp ? QUIET : UNCONF;
136 1.1 uch }
137 1.1 uch
138 1.1 uch int
139 1.1 uch tx3912video_init(tc, fb_start, fb_width, fb_height, fb_addr, fb_size,
140 1.1 uch fb_line_bytes)
141 1.1 uch tx_chipset_tag_t tc;
142 1.1 uch u_int32_t fb_start; /* Physical address */
143 1.1 uch int fb_width, fb_height;
144 1.1 uch u_int32_t *fb_addr, *fb_size;
145 1.1 uch int *fb_line_bytes;
146 1.1 uch {
147 1.1 uch u_int32_t addr, size;
148 1.1 uch int fb_depth;
149 1.1 uch
150 1.1 uch /* Inquire bit depth */
151 1.1 uch fb_depth = tx3912video_fbdepth(tc, 0);
152 1.1 uch
153 1.1 uch /* Allocate framebuffer area */
154 1.1 uch if (tx3912video_framebuffer_alloc(tc, fb_start, fb_width, fb_height,
155 1.1 uch fb_depth, &addr, &size)) {
156 1.1 uch return 1;
157 1.1 uch }
158 1.1 uch #if notyet
159 1.1 uch tx3912video_resolution_init(tc, fb_width, fb_height);
160 1.1 uch #else
161 1.1 uch /* Use Windows CE setting. */
162 1.1 uch #endif
163 1.1 uch /* Set DMA transfer address to VID module */
164 1.1 uch tx3912video_framebuffer_init(tc, addr, size);
165 1.1 uch
166 1.1 uch /* Syncronize framebuffer addr to frame signal */
167 1.1 uch tx3912video_reset(tc);
168 1.1 uch
169 1.1 uch *fb_line_bytes = (fb_width * fb_depth) / 8;
170 1.1 uch *fb_addr = addr; /* Phsical address */
171 1.1 uch *fb_size = size;
172 1.1 uch
173 1.1 uch return 0;
174 1.1 uch }
175 1.1 uch
176 1.1 uch int
177 1.1 uch tx3912video_framebuffer_alloc(tc, start, h, v, depth, fb_addr, fb_size)
178 1.1 uch tx_chipset_tag_t tc;
179 1.1 uch u_int32_t start;
180 1.1 uch int h, v, depth;
181 1.1 uch u_int32_t *fb_addr, *fb_size;
182 1.1 uch {
183 1.1 uch struct extent_fixed ex_fixed[2];
184 1.1 uch struct extent *ex;
185 1.1 uch u_long addr, size;
186 1.1 uch int err;
187 1.1 uch
188 1.1 uch /* Calcurate frame buffer size */
189 1.1 uch size = (h * v * depth) / 8;
190 1.1 uch
191 1.1 uch /* Allocate V-RAM area */
192 1.1 uch if (!(ex = extent_create("Frame buffer address", start,
193 1.1 uch start + TX3912_FRAMEBUFFER_MAX,
194 1.1 uch 0, (caddr_t)ex_fixed, sizeof ex_fixed,
195 1.1 uch EX_NOWAIT))) {
196 1.1 uch return 1;
197 1.1 uch }
198 1.1 uch if((err = extent_alloc_subregion(ex, start, start + size, size,
199 1.1 uch TX3912_FRAMEBUFFER_ALIGNMENT,
200 1.1 uch TX3912_FRAMEBUFFER_BOUNDARY,
201 1.1 uch EX_FAST|EX_NOWAIT, &addr))) {
202 1.1 uch return 1;
203 1.1 uch }
204 1.1 uch framebuffer = addr;
205 1.1 uch framebuffersize = size;
206 1.1 uch *fb_addr = addr;
207 1.1 uch *fb_size = size;
208 1.1 uch
209 1.1 uch return 0;
210 1.1 uch }
211 1.1 uch
212 1.1 uch void
213 1.1 uch tx3912video_framebuffer_init(tc, fb_addr, fb_size)
214 1.1 uch tx_chipset_tag_t tc;
215 1.1 uch u_int32_t fb_addr, fb_size;
216 1.1 uch {
217 1.1 uch u_int32_t reg, vaddr, bank, base;
218 1.1 uch
219 1.1 uch /* XXX currently I don't set DFVAL, so force DF signal toggled on
220 1.1 uch * XXX each frame. */
221 1.1 uch reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
222 1.1 uch reg &= ~TX3912_VIDEOCTRL1_DFMODE;
223 1.1 uch tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
224 1.1 uch
225 1.1 uch /* Set DMA transfer start and end address */
226 1.1 uch
227 1.1 uch bank = TX3912_VIDEOCTRL3_VIDBANK(fb_addr);
228 1.1 uch base = TX3912_VIDEOCTRL3_VIDBASEHI(fb_addr);
229 1.1 uch reg = TX3912_VIDEOCTRL3_VIDBANK_SET(0, bank);
230 1.1 uch /* Upper address counter */
231 1.1 uch reg = TX3912_VIDEOCTRL3_VIDBASEHI_SET(reg, base);
232 1.1 uch tx_conf_write(tc, TX3912_VIDEOCTRL3_REG, reg);
233 1.1 uch
234 1.1 uch /* Lower address counter */
235 1.1 uch base = TX3912_VIDEOCTRL4_VIDBASELO(fb_addr + fb_size);
236 1.1 uch reg = TX3912_VIDEOCTRL4_VIDBASELO_SET(0, base);
237 1.1 uch
238 1.1 uch /* Set DF-signal rate */
239 1.1 uch reg = TX3912_VIDEOCTRL4_DFVAL_SET(reg, 0); /* XXX not yet*/
240 1.1 uch
241 1.1 uch /* Set VIDDONE signal delay after FRAME signal */
242 1.1 uch /* XXX not yet*/
243 1.1 uch tx_conf_write(tc, TX3912_VIDEOCTRL4_REG, reg);
244 1.1 uch
245 1.1 uch /* Clear frame buffer */
246 1.1 uch vaddr = MIPS_PHYS_TO_KSEG1(fb_addr);
247 1.1 uch bzero((void*)vaddr, fb_size);
248 1.1 uch }
249 1.1 uch
250 1.1 uch void
251 1.1 uch tx3912video_resolution_init(tc, h, v)
252 1.1 uch tx_chipset_tag_t tc;
253 1.1 uch int h;
254 1.1 uch int v;
255 1.1 uch {
256 1.1 uch u_int32_t reg, val;
257 1.1 uch int split, bit8, horzval, lineval;
258 1.1 uch
259 1.1 uch reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
260 1.1 uch split = reg & TX3912_VIDEOCTRL1_DISPSPLIT;
261 1.1 uch bit8 = (TX3912_VIDEOCTRL1_BITSEL(reg) ==
262 1.1 uch TX3912_VIDEOCTRL1_BITSEL_8BITCOLOR);
263 1.1 uch val = TX3912_VIDEOCTRL1_BITSEL(reg);
264 1.1 uch
265 1.1 uch if ((val == TX3912_VIDEOCTRL1_BITSEL_8BITCOLOR) &&
266 1.1 uch !split) {
267 1.3 uch /* (LCD horizontal pixels / 8bit) * RGB - 1 */
268 1.3 uch horzval = (h / 8) * 3 - 1;
269 1.1 uch } else {
270 1.1 uch horzval = h / 4 - 1;
271 1.1 uch }
272 1.1 uch lineval = (split ? v / 2 : v) - 1;
273 1.1 uch
274 1.1 uch /* Video rate */
275 1.3 uch /* XXX
276 1.3 uch * probably This value should be determined from DFINT and LCDINT
277 1.3 uch */
278 1.1 uch reg = TX3912_VIDEOCTRL2_VIDRATE_SET(0, horzval + 1);
279 1.1 uch /* Horizontal size of LCD */
280 1.1 uch reg = TX3912_VIDEOCTRL2_HORZVAL_SET(reg, horzval);
281 1.1 uch /* # of lines for the LCD */
282 1.1 uch reg = TX3912_VIDEOCTRL2_LINEVAL_SET(reg, lineval);
283 1.1 uch
284 1.1 uch tx_conf_write(tc, TX3912_VIDEOCTRL2_REG, reg);
285 1.1 uch }
286 1.1 uch
287 1.1 uch int
288 1.1 uch tx3912video_fbdepth(tc, verbose)
289 1.1 uch tx_chipset_tag_t tc;
290 1.1 uch int verbose;
291 1.1 uch {
292 1.1 uch u_int32_t reg, val;
293 1.1 uch
294 1.1 uch reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
295 1.1 uch val = TX3912_VIDEOCTRL1_BITSEL(reg);
296 1.1 uch switch (val) {
297 1.1 uch case TX3912_VIDEOCTRL1_BITSEL_8BITCOLOR:
298 1.1 uch if (verbose)
299 1.1 uch printf("8bit color");
300 1.1 uch return 8;
301 1.1 uch case TX3912_VIDEOCTRL1_BITSEL_4BITGREYSCALE:
302 1.1 uch if (verbose)
303 1.1 uch printf("4bit greyscale");
304 1.1 uch return 4;
305 1.1 uch case TX3912_VIDEOCTRL1_BITSEL_2BITGREYSCALE:
306 1.1 uch if (verbose)
307 1.1 uch printf("2bit greyscale");
308 1.1 uch return 2;
309 1.1 uch case TX3912_VIDEOCTRL1_BITSEL_MONOCHROME:
310 1.1 uch if (verbose)
311 1.1 uch printf("monochrome");
312 1.1 uch return 1;
313 1.1 uch }
314 1.1 uch return 0;
315 1.1 uch }
316 1.1 uch
317 1.1 uch void
318 1.1 uch tx3912video_reset(tc)
319 1.1 uch tx_chipset_tag_t tc;
320 1.1 uch {
321 1.1 uch u_int32_t reg;
322 1.1 uch
323 1.1 uch reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
324 1.3 uch
325 1.1 uch /* Disable video logic at end of this frame */
326 1.1 uch reg |= TX3912_VIDEOCTRL1_ENFREEZEFRAME;
327 1.1 uch tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
328 1.3 uch
329 1.1 uch /* Wait for end of frame */
330 1.1 uch delay(300 * 1000);
331 1.3 uch
332 1.1 uch /* Make sure to disable video logic */
333 1.1 uch reg &= ~TX3912_VIDEOCTRL1_ENVID;
334 1.1 uch tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
335 1.3 uch
336 1.1 uch delay(1000);
337 1.3 uch
338 1.1 uch /* Enable video logic again */
339 1.1 uch reg &= ~TX3912_VIDEOCTRL1_ENFREEZEFRAME;
340 1.1 uch reg |= TX3912_VIDEOCTRL1_ENVID;
341 1.1 uch tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
342 1.3 uch
343 1.1 uch delay(1000);
344 1.1 uch }
345 1.1 uch
346 1.1 uch
347