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