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