tx3912video.c revision 1.23.8.6 1 1.23.8.6 nathanw /* $NetBSD: tx3912video.c,v 1.23.8.6 2002/10/18 02:37:12 nathanw Exp $ */
2 1.23.8.2 nathanw
3 1.23.8.2 nathanw /*-
4 1.23.8.3 nathanw * Copyright (c) 1999-2002 The NetBSD Foundation, Inc.
5 1.23.8.2 nathanw * All rights reserved.
6 1.23.8.2 nathanw *
7 1.23.8.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.23.8.2 nathanw * by UCHIYAMA Yasushi.
9 1.23.8.2 nathanw *
10 1.23.8.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.23.8.2 nathanw * modification, are permitted provided that the following conditions
12 1.23.8.2 nathanw * are met:
13 1.23.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.23.8.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.23.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.23.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.23.8.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.23.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.23.8.2 nathanw * must display the following acknowledgement:
20 1.23.8.2 nathanw * This product includes software developed by the NetBSD
21 1.23.8.2 nathanw * Foundation, Inc. and its contributors.
22 1.23.8.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.23.8.2 nathanw * contributors may be used to endorse or promote products derived
24 1.23.8.2 nathanw * from this software without specific prior written permission.
25 1.23.8.2 nathanw *
26 1.23.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.23.8.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.23.8.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.23.8.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.23.8.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.23.8.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.23.8.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.23.8.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.23.8.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.23.8.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.23.8.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.23.8.2 nathanw */
38 1.23.8.2 nathanw
39 1.23.8.2 nathanw #define TX3912VIDEO_DEBUG
40 1.23.8.2 nathanw
41 1.23.8.2 nathanw #include "hpcfb.h"
42 1.23.8.3 nathanw #include "bivideo.h"
43 1.23.8.2 nathanw
44 1.23.8.2 nathanw #include <sys/param.h>
45 1.23.8.2 nathanw #include <sys/systm.h>
46 1.23.8.2 nathanw #include <sys/device.h>
47 1.23.8.2 nathanw #include <sys/extent.h>
48 1.23.8.2 nathanw
49 1.23.8.2 nathanw #include <sys/ioctl.h>
50 1.23.8.2 nathanw #include <sys/buf.h>
51 1.23.8.2 nathanw
52 1.23.8.2 nathanw #include <uvm/uvm_extern.h>
53 1.23.8.2 nathanw
54 1.23.8.2 nathanw #include <dev/cons.h> /* consdev */
55 1.23.8.2 nathanw
56 1.23.8.2 nathanw #include <machine/bus.h>
57 1.23.8.2 nathanw #include <machine/bootinfo.h>
58 1.23.8.2 nathanw #include <machine/config_hook.h>
59 1.23.8.2 nathanw
60 1.23.8.2 nathanw #include <hpcmips/tx/tx39var.h>
61 1.23.8.2 nathanw #include <hpcmips/tx/tx3912videovar.h>
62 1.23.8.2 nathanw #include <hpcmips/tx/tx3912videoreg.h>
63 1.23.8.2 nathanw
64 1.23.8.2 nathanw /* CLUT */
65 1.23.8.2 nathanw #include <dev/wscons/wsdisplayvar.h>
66 1.23.8.2 nathanw #include <dev/rasops/rasops.h>
67 1.23.8.2 nathanw #include <dev/hpc/video_subr.h>
68 1.23.8.2 nathanw
69 1.23.8.2 nathanw #include <dev/wscons/wsconsio.h>
70 1.23.8.2 nathanw #include <dev/hpc/hpcfbvar.h>
71 1.23.8.2 nathanw #include <dev/hpc/hpcfbio.h>
72 1.23.8.3 nathanw #if NBIVIDEO > 0
73 1.23.8.3 nathanw #include <dev/hpc/bivideovar.h>
74 1.23.8.3 nathanw #endif
75 1.23.8.2 nathanw
76 1.23.8.2 nathanw #ifdef TX3912VIDEO_DEBUG
77 1.23.8.2 nathanw int tx3912video_debug = 1;
78 1.23.8.2 nathanw #define DPRINTF(arg) if (tx3912video_debug) printf arg;
79 1.23.8.2 nathanw #define DPRINTFN(n, arg) if (tx3912video_debug > (n)) printf arg;
80 1.23.8.2 nathanw #else
81 1.23.8.2 nathanw #define DPRINTF(arg)
82 1.23.8.2 nathanw #define DPRINTFN(n, arg)
83 1.23.8.2 nathanw #endif
84 1.23.8.2 nathanw
85 1.23.8.2 nathanw struct tx3912video_softc {
86 1.23.8.2 nathanw struct device sc_dev;
87 1.23.8.2 nathanw void *sc_powerhook; /* power management hook */
88 1.23.8.2 nathanw int sc_console;
89 1.23.8.2 nathanw struct hpcfb_fbconf sc_fbconf;
90 1.23.8.2 nathanw struct hpcfb_dspconf sc_dspconf;
91 1.23.8.2 nathanw struct video_chip *sc_chip;
92 1.23.8.2 nathanw };
93 1.23.8.2 nathanw
94 1.23.8.2 nathanw /* TX3912 built-in video chip itself */
95 1.23.8.2 nathanw static struct video_chip tx3912video_chip;
96 1.23.8.2 nathanw
97 1.23.8.2 nathanw int tx3912video_power(void *, int, long, void *);
98 1.23.8.2 nathanw void tx3912video_framebuffer_init(struct video_chip *);
99 1.23.8.2 nathanw int tx3912video_framebuffer_alloc(struct video_chip *, paddr_t, paddr_t *);
100 1.23.8.2 nathanw void tx3912video_reset(struct video_chip *);
101 1.23.8.2 nathanw void tx3912video_resolution_init(struct video_chip *);
102 1.23.8.2 nathanw int tx3912video_match(struct device *, struct cfdata *, void *);
103 1.23.8.2 nathanw void tx3912video_attach(struct device *, struct device *, void *);
104 1.23.8.2 nathanw int tx3912video_print(void *, const char *);
105 1.23.8.2 nathanw
106 1.23.8.2 nathanw void tx3912video_hpcfbinit(struct tx3912video_softc *);
107 1.23.8.2 nathanw int tx3912video_ioctl(void *, u_long, caddr_t, int, struct proc *);
108 1.23.8.2 nathanw paddr_t tx3912video_mmap(void *, off_t, int);
109 1.23.8.2 nathanw
110 1.23.8.2 nathanw void tx3912video_clut_init(struct tx3912video_softc *);
111 1.23.8.2 nathanw void tx3912video_clut_install(void *, struct rasops_info *);
112 1.23.8.2 nathanw void tx3912video_clut_get(struct tx3912video_softc *, u_int32_t *, int,
113 1.23.8.2 nathanw int);
114 1.23.8.2 nathanw
115 1.23.8.2 nathanw static int __get_color8(int);
116 1.23.8.2 nathanw static int __get_color4(int);
117 1.23.8.2 nathanw
118 1.23.8.6 nathanw CFATTACH_DECL(tx3912video, sizeof(struct tx3912video_softc),
119 1.23.8.6 nathanw tx3912video_match, tx3912video_attach, NULL, NULL);
120 1.23.8.2 nathanw
121 1.23.8.2 nathanw struct hpcfb_accessops tx3912video_ha = {
122 1.23.8.2 nathanw tx3912video_ioctl, tx3912video_mmap, 0, 0, 0, 0,
123 1.23.8.2 nathanw tx3912video_clut_install
124 1.23.8.2 nathanw };
125 1.23.8.2 nathanw
126 1.23.8.2 nathanw int
127 1.23.8.2 nathanw tx3912video_match(struct device *parent, struct cfdata *cf, void *aux)
128 1.23.8.2 nathanw {
129 1.23.8.2 nathanw return (ATTACH_NORMAL);
130 1.23.8.2 nathanw }
131 1.23.8.2 nathanw
132 1.23.8.2 nathanw void
133 1.23.8.2 nathanw tx3912video_attach(struct device *parent, struct device *self, void *aux)
134 1.23.8.2 nathanw {
135 1.23.8.2 nathanw struct tx3912video_softc *sc = (void *)self;
136 1.23.8.2 nathanw struct video_chip *chip;
137 1.23.8.5 nathanw static const char *const depth_print[] = {
138 1.23.8.2 nathanw [TX3912_VIDEOCTRL1_BITSEL_MONOCHROME] = "monochrome",
139 1.23.8.2 nathanw [TX3912_VIDEOCTRL1_BITSEL_2BITGREYSCALE] = "2bit greyscale",
140 1.23.8.2 nathanw [TX3912_VIDEOCTRL1_BITSEL_4BITGREYSCALE] = "4bit greyscale",
141 1.23.8.2 nathanw [TX3912_VIDEOCTRL1_BITSEL_8BITCOLOR] = "8bit color"
142 1.23.8.2 nathanw };
143 1.23.8.2 nathanw struct hpcfb_attach_args ha;
144 1.23.8.2 nathanw tx_chipset_tag_t tc;
145 1.23.8.2 nathanw txreg_t val;
146 1.23.8.2 nathanw int console;
147 1.23.8.2 nathanw
148 1.23.8.2 nathanw sc->sc_console = console = cn_tab ? 0 : 1;
149 1.23.8.2 nathanw sc->sc_chip = chip = &tx3912video_chip;
150 1.23.8.2 nathanw
151 1.23.8.2 nathanw /* print video module information */
152 1.23.8.2 nathanw printf(": %s, frame buffer 0x%08x-0x%08x\n",
153 1.23.8.2 nathanw depth_print[(ffs(chip->vc_fbdepth) - 1) & 0x3],
154 1.23.8.2 nathanw (unsigned)chip->vc_fbpaddr,
155 1.23.8.2 nathanw (unsigned)(chip->vc_fbpaddr + chip->vc_fbsize));
156 1.23.8.2 nathanw
157 1.23.8.2 nathanw /* don't inverse VDAT[3:0] signal */
158 1.23.8.2 nathanw tc = chip->vc_v;
159 1.23.8.2 nathanw val = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
160 1.23.8.2 nathanw val &= ~TX3912_VIDEOCTRL1_INVVID;
161 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, val);
162 1.23.8.2 nathanw
163 1.23.8.2 nathanw /* install default CLUT */
164 1.23.8.2 nathanw tx3912video_clut_init(sc);
165 1.23.8.2 nathanw
166 1.23.8.2 nathanw /* if serial console, power off video module */
167 1.23.8.2 nathanw tx3912video_power(sc, 0, 0, (void *)
168 1.23.8.2 nathanw (console ? PWR_RESUME : PWR_SUSPEND));
169 1.23.8.2 nathanw
170 1.23.8.2 nathanw /* Add a hard power hook to power saving */
171 1.23.8.2 nathanw sc->sc_powerhook = config_hook(CONFIG_HOOK_PMEVENT,
172 1.23.8.2 nathanw CONFIG_HOOK_PMEVENT_HARDPOWER, CONFIG_HOOK_SHARE,
173 1.23.8.2 nathanw tx3912video_power, sc);
174 1.23.8.2 nathanw if (sc->sc_powerhook == 0)
175 1.23.8.2 nathanw printf("WARNING unable to establish hard power hook");
176 1.23.8.2 nathanw
177 1.23.8.2 nathanw #ifdef TX3912VIDEO_DEBUG
178 1.23.8.2 nathanw /* attach debug draw routine (debugging use) */
179 1.23.8.2 nathanw video_attach_drawfunc(sc->sc_chip);
180 1.23.8.2 nathanw tx_conf_register_video(tc, sc->sc_chip);
181 1.23.8.2 nathanw #endif
182 1.23.8.2 nathanw
183 1.23.8.2 nathanw /* Attach frame buffer device */
184 1.23.8.2 nathanw tx3912video_hpcfbinit(sc);
185 1.23.8.2 nathanw
186 1.23.8.2 nathanw if (console && hpcfb_cnattach(&sc->sc_fbconf) != 0) {
187 1.23.8.2 nathanw panic("tx3912video_attach: can't init fb console");
188 1.23.8.2 nathanw }
189 1.23.8.2 nathanw
190 1.23.8.2 nathanw ha.ha_console = console;
191 1.23.8.2 nathanw ha.ha_accessops = &tx3912video_ha;
192 1.23.8.2 nathanw ha.ha_accessctx = sc;
193 1.23.8.2 nathanw ha.ha_curfbconf = 0;
194 1.23.8.2 nathanw ha.ha_nfbconf = 1;
195 1.23.8.2 nathanw ha.ha_fbconflist = &sc->sc_fbconf;
196 1.23.8.2 nathanw ha.ha_curdspconf = 0;
197 1.23.8.2 nathanw ha.ha_ndspconf = 1;
198 1.23.8.2 nathanw ha.ha_dspconflist = &sc->sc_dspconf;
199 1.23.8.2 nathanw
200 1.23.8.2 nathanw config_found(self, &ha, hpcfbprint);
201 1.23.8.3 nathanw #if NBIVIDEO > 0
202 1.23.8.3 nathanw /* bivideo is no longer need */
203 1.23.8.3 nathanw bivideo_dont_attach = 1;
204 1.23.8.3 nathanw #endif /* NBIVIDEO > 0 */
205 1.23.8.2 nathanw }
206 1.23.8.2 nathanw
207 1.23.8.2 nathanw int
208 1.23.8.2 nathanw tx3912video_power(void *ctx, int type, long id, void *msg)
209 1.23.8.2 nathanw {
210 1.23.8.2 nathanw struct tx3912video_softc *sc = ctx;
211 1.23.8.2 nathanw struct video_chip *chip = sc->sc_chip;
212 1.23.8.2 nathanw tx_chipset_tag_t tc = chip->vc_v;
213 1.23.8.2 nathanw int why = (int)msg;
214 1.23.8.2 nathanw txreg_t val;
215 1.23.8.2 nathanw
216 1.23.8.2 nathanw switch (why) {
217 1.23.8.2 nathanw case PWR_RESUME:
218 1.23.8.2 nathanw if (!sc->sc_console)
219 1.23.8.2 nathanw return (0); /* serial console */
220 1.23.8.2 nathanw
221 1.23.8.2 nathanw DPRINTF(("%s: ON\n", sc->sc_dev.dv_xname));
222 1.23.8.2 nathanw val = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
223 1.23.8.2 nathanw val |= (TX3912_VIDEOCTRL1_DISPON | TX3912_VIDEOCTRL1_ENVID);
224 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, val);
225 1.23.8.2 nathanw break;
226 1.23.8.2 nathanw case PWR_SUSPEND:
227 1.23.8.2 nathanw /* FALLTHROUGH */
228 1.23.8.2 nathanw case PWR_STANDBY:
229 1.23.8.2 nathanw DPRINTF(("%s: OFF\n", sc->sc_dev.dv_xname));
230 1.23.8.2 nathanw val = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
231 1.23.8.2 nathanw val &= ~(TX3912_VIDEOCTRL1_DISPON | TX3912_VIDEOCTRL1_ENVID);
232 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, val);
233 1.23.8.2 nathanw break;
234 1.23.8.2 nathanw }
235 1.23.8.2 nathanw
236 1.23.8.2 nathanw return (0);
237 1.23.8.2 nathanw }
238 1.23.8.2 nathanw
239 1.23.8.2 nathanw void
240 1.23.8.2 nathanw tx3912video_hpcfbinit(sc)
241 1.23.8.2 nathanw struct tx3912video_softc *sc;
242 1.23.8.2 nathanw {
243 1.23.8.2 nathanw struct video_chip *chip = sc->sc_chip;
244 1.23.8.2 nathanw struct hpcfb_fbconf *fb = &sc->sc_fbconf;
245 1.23.8.2 nathanw vaddr_t fbvaddr = (vaddr_t)MIPS_PHYS_TO_KSEG1(chip->vc_fbpaddr);
246 1.23.8.2 nathanw
247 1.23.8.2 nathanw memset(fb, 0, sizeof(struct hpcfb_fbconf));
248 1.23.8.2 nathanw
249 1.23.8.2 nathanw fb->hf_conf_index = 0; /* configuration index */
250 1.23.8.2 nathanw fb->hf_nconfs = 1; /* how many configurations */
251 1.23.8.2 nathanw strncpy(fb->hf_name, "TX3912 built-in video", HPCFB_MAXNAMELEN);
252 1.23.8.2 nathanw /* frame buffer name */
253 1.23.8.2 nathanw strncpy(fb->hf_conf_name, "LCD", HPCFB_MAXNAMELEN);
254 1.23.8.2 nathanw /* configuration name */
255 1.23.8.2 nathanw fb->hf_height = chip->vc_fbheight;
256 1.23.8.2 nathanw fb->hf_width = chip->vc_fbwidth;
257 1.23.8.2 nathanw fb->hf_baseaddr = (u_long)fbvaddr;
258 1.23.8.2 nathanw fb->hf_offset = (u_long)fbvaddr -
259 1.23.8.2 nathanw mips_ptob(mips_btop(fbvaddr));
260 1.23.8.2 nathanw /* frame buffer start offset */
261 1.23.8.2 nathanw fb->hf_bytes_per_line = (chip->vc_fbwidth * chip->vc_fbdepth)
262 1.23.8.2 nathanw / NBBY;
263 1.23.8.2 nathanw fb->hf_nplanes = 1;
264 1.23.8.2 nathanw fb->hf_bytes_per_plane = chip->vc_fbheight * fb->hf_bytes_per_line;
265 1.23.8.2 nathanw
266 1.23.8.2 nathanw fb->hf_access_flags |= HPCFB_ACCESS_BYTE;
267 1.23.8.2 nathanw fb->hf_access_flags |= HPCFB_ACCESS_WORD;
268 1.23.8.2 nathanw fb->hf_access_flags |= HPCFB_ACCESS_DWORD;
269 1.23.8.2 nathanw if (video_reverse_color())
270 1.23.8.2 nathanw fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
271 1.23.8.2 nathanw
272 1.23.8.2 nathanw
273 1.23.8.2 nathanw switch (chip->vc_fbdepth) {
274 1.23.8.2 nathanw default:
275 1.23.8.6 nathanw panic("tx3912video_hpcfbinit: not supported color depth");
276 1.23.8.2 nathanw /* NOTREACHED */
277 1.23.8.2 nathanw case 2:
278 1.23.8.2 nathanw fb->hf_class = HPCFB_CLASS_GRAYSCALE;
279 1.23.8.2 nathanw fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
280 1.23.8.2 nathanw fb->hf_pack_width = 8;
281 1.23.8.2 nathanw fb->hf_pixels_per_pack = 4;
282 1.23.8.2 nathanw fb->hf_pixel_width = 2;
283 1.23.8.2 nathanw fb->hf_class_data_length = sizeof(struct hf_gray_tag);
284 1.23.8.2 nathanw /* reserved for future use */
285 1.23.8.2 nathanw fb->hf_u.hf_gray.hf_flags = 0;
286 1.23.8.2 nathanw break;
287 1.23.8.2 nathanw case 8:
288 1.23.8.2 nathanw fb->hf_class = HPCFB_CLASS_INDEXCOLOR;
289 1.23.8.2 nathanw fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
290 1.23.8.2 nathanw fb->hf_pack_width = 8;
291 1.23.8.2 nathanw fb->hf_pixels_per_pack = 1;
292 1.23.8.2 nathanw fb->hf_pixel_width = 8;
293 1.23.8.2 nathanw fb->hf_class_data_length = sizeof(struct hf_indexed_tag);
294 1.23.8.2 nathanw /* reserved for future use */
295 1.23.8.2 nathanw fb->hf_u.hf_indexed.hf_flags = 0;
296 1.23.8.2 nathanw break;
297 1.23.8.2 nathanw }
298 1.23.8.2 nathanw }
299 1.23.8.2 nathanw
300 1.23.8.2 nathanw int
301 1.23.8.2 nathanw tx3912video_init(paddr_t fb_start, paddr_t *fb_end)
302 1.23.8.2 nathanw {
303 1.23.8.2 nathanw struct video_chip *chip = &tx3912video_chip;
304 1.23.8.2 nathanw tx_chipset_tag_t tc;
305 1.23.8.2 nathanw txreg_t reg;
306 1.23.8.2 nathanw int fbdepth, reverse, error;
307 1.23.8.2 nathanw
308 1.23.8.2 nathanw reverse = video_reverse_color();
309 1.23.8.2 nathanw chip->vc_v = tc = tx_conf_get_tag();
310 1.23.8.2 nathanw
311 1.23.8.2 nathanw reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
312 1.23.8.2 nathanw fbdepth = 1 << (TX3912_VIDEOCTRL1_BITSEL(reg));
313 1.23.8.2 nathanw
314 1.23.8.2 nathanw switch (fbdepth) {
315 1.23.8.2 nathanw case 2:
316 1.23.8.2 nathanw bootinfo->fb_type = reverse ? BIFB_D2_M2L_3 : BIFB_D2_M2L_0;
317 1.23.8.2 nathanw break;
318 1.23.8.2 nathanw case 4:
319 1.23.8.2 nathanw /* XXX should implement rasops4.c */
320 1.23.8.2 nathanw fbdepth = 2;
321 1.23.8.2 nathanw bootinfo->fb_type = reverse ? BIFB_D2_M2L_3 : BIFB_D2_M2L_0;
322 1.23.8.2 nathanw reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
323 1.23.8.2 nathanw TX3912_VIDEOCTRL1_BITSEL_CLR(reg);
324 1.23.8.2 nathanw reg = TX3912_VIDEOCTRL1_BITSEL_SET(reg,
325 1.23.8.2 nathanw TX3912_VIDEOCTRL1_BITSEL_2BITGREYSCALE);
326 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
327 1.23.8.2 nathanw break;
328 1.23.8.2 nathanw case 8:
329 1.23.8.2 nathanw bootinfo->fb_type = reverse ? BIFB_D8_FF : BIFB_D8_00;
330 1.23.8.2 nathanw break;
331 1.23.8.2 nathanw }
332 1.23.8.2 nathanw
333 1.23.8.2 nathanw chip->vc_fbdepth = fbdepth;
334 1.23.8.2 nathanw chip->vc_fbwidth = bootinfo->fb_width;
335 1.23.8.2 nathanw chip->vc_fbheight= bootinfo->fb_height;
336 1.23.8.2 nathanw
337 1.23.8.2 nathanw /* Allocate framebuffer area */
338 1.23.8.2 nathanw error = tx3912video_framebuffer_alloc(chip, fb_start, fb_end);
339 1.23.8.2 nathanw if (error != 0)
340 1.23.8.2 nathanw return (1);
341 1.23.8.2 nathanw
342 1.23.8.2 nathanw #if notyet
343 1.23.8.2 nathanw tx3912video_resolution_init(chip);
344 1.23.8.2 nathanw #else
345 1.23.8.2 nathanw /* Use Windows CE setting. */
346 1.23.8.2 nathanw #endif
347 1.23.8.2 nathanw /* Set DMA transfer address to VID module */
348 1.23.8.2 nathanw tx3912video_framebuffer_init(chip);
349 1.23.8.2 nathanw
350 1.23.8.2 nathanw /* Syncronize framebuffer addr to frame signal */
351 1.23.8.2 nathanw tx3912video_reset(chip);
352 1.23.8.2 nathanw
353 1.23.8.2 nathanw bootinfo->fb_line_bytes = (chip->vc_fbwidth * fbdepth) / NBBY;
354 1.23.8.2 nathanw bootinfo->fb_addr = (void *)MIPS_PHYS_TO_KSEG1(chip->vc_fbpaddr);
355 1.23.8.2 nathanw
356 1.23.8.2 nathanw return (0);
357 1.23.8.2 nathanw }
358 1.23.8.2 nathanw
359 1.23.8.2 nathanw int
360 1.23.8.2 nathanw tx3912video_framebuffer_alloc(struct video_chip *chip, paddr_t fb_start,
361 1.23.8.2 nathanw paddr_t *fb_end /* buffer allocation hint */)
362 1.23.8.2 nathanw {
363 1.23.8.2 nathanw struct extent_fixed ex_fixed[10];
364 1.23.8.2 nathanw struct extent *ex;
365 1.23.8.2 nathanw u_long addr, size;
366 1.23.8.2 nathanw int error;
367 1.23.8.2 nathanw
368 1.23.8.2 nathanw /* calcurate frame buffer size */
369 1.23.8.2 nathanw size = (chip->vc_fbwidth * chip->vc_fbheight * chip->vc_fbdepth) /
370 1.23.8.2 nathanw NBBY;
371 1.23.8.2 nathanw
372 1.23.8.2 nathanw /* extent V-RAM region */
373 1.23.8.2 nathanw ex = extent_create("Frame buffer address", fb_start, *fb_end,
374 1.23.8.2 nathanw 0, (caddr_t)ex_fixed, sizeof ex_fixed,
375 1.23.8.2 nathanw EX_NOWAIT);
376 1.23.8.2 nathanw if (ex == 0)
377 1.23.8.2 nathanw return (1);
378 1.23.8.2 nathanw
379 1.23.8.2 nathanw /* Allocate V-RAM area */
380 1.23.8.2 nathanw error = extent_alloc_subregion(ex, fb_start, fb_start + size - 1,
381 1.23.8.2 nathanw size, TX3912_FRAMEBUFFER_ALIGNMENT,
382 1.23.8.2 nathanw TX3912_FRAMEBUFFER_BOUNDARY, EX_FAST|EX_NOWAIT, &addr);
383 1.23.8.2 nathanw extent_destroy(ex);
384 1.23.8.2 nathanw
385 1.23.8.2 nathanw if (error != 0)
386 1.23.8.2 nathanw return (1);
387 1.23.8.2 nathanw
388 1.23.8.2 nathanw chip->vc_fbpaddr = addr;
389 1.23.8.2 nathanw chip->vc_fbvaddr = MIPS_PHYS_TO_KSEG1(addr);
390 1.23.8.2 nathanw chip->vc_fbsize = size;
391 1.23.8.2 nathanw
392 1.23.8.2 nathanw *fb_end = addr + size;
393 1.23.8.2 nathanw
394 1.23.8.2 nathanw return (0);
395 1.23.8.2 nathanw }
396 1.23.8.2 nathanw
397 1.23.8.2 nathanw void
398 1.23.8.2 nathanw tx3912video_framebuffer_init(struct video_chip *chip)
399 1.23.8.2 nathanw {
400 1.23.8.2 nathanw u_int32_t fb_addr, fb_size, vaddr, bank, base;
401 1.23.8.2 nathanw txreg_t reg;
402 1.23.8.2 nathanw tx_chipset_tag_t tc = chip->vc_v;
403 1.23.8.2 nathanw
404 1.23.8.2 nathanw fb_addr = chip->vc_fbpaddr;
405 1.23.8.2 nathanw fb_size = chip->vc_fbsize;
406 1.23.8.2 nathanw
407 1.23.8.2 nathanw /* XXX currently I don't set DFVAL, so force DF signal toggled on
408 1.23.8.2 nathanw * XXX each frame. */
409 1.23.8.2 nathanw reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
410 1.23.8.2 nathanw reg &= ~TX3912_VIDEOCTRL1_DFMODE;
411 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
412 1.23.8.2 nathanw
413 1.23.8.2 nathanw /* Set DMA transfer start and end address */
414 1.23.8.2 nathanw
415 1.23.8.2 nathanw bank = TX3912_VIDEOCTRL3_VIDBANK(fb_addr);
416 1.23.8.2 nathanw base = TX3912_VIDEOCTRL3_VIDBASEHI(fb_addr);
417 1.23.8.2 nathanw reg = TX3912_VIDEOCTRL3_VIDBANK_SET(0, bank);
418 1.23.8.2 nathanw /* Upper address counter */
419 1.23.8.2 nathanw reg = TX3912_VIDEOCTRL3_VIDBASEHI_SET(reg, base);
420 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL3_REG, reg);
421 1.23.8.2 nathanw
422 1.23.8.2 nathanw /* Lower address counter */
423 1.23.8.2 nathanw base = TX3912_VIDEOCTRL4_VIDBASELO(fb_addr + fb_size);
424 1.23.8.2 nathanw reg = TX3912_VIDEOCTRL4_VIDBASELO_SET(0, base);
425 1.23.8.2 nathanw
426 1.23.8.2 nathanw /* Set DF-signal rate */
427 1.23.8.2 nathanw reg = TX3912_VIDEOCTRL4_DFVAL_SET(reg, 0); /* XXX not yet*/
428 1.23.8.2 nathanw
429 1.23.8.2 nathanw /* Set VIDDONE signal delay after FRAME signal */
430 1.23.8.2 nathanw /* XXX not yet*/
431 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL4_REG, reg);
432 1.23.8.2 nathanw
433 1.23.8.2 nathanw /* Clear frame buffer */
434 1.23.8.2 nathanw vaddr = MIPS_PHYS_TO_KSEG1(fb_addr);
435 1.23.8.2 nathanw memset((void*)vaddr, 0, fb_size);
436 1.23.8.2 nathanw }
437 1.23.8.2 nathanw
438 1.23.8.2 nathanw void
439 1.23.8.2 nathanw tx3912video_resolution_init(struct video_chip *chip)
440 1.23.8.2 nathanw {
441 1.23.8.2 nathanw int h, v, split, bit8, horzval, lineval;
442 1.23.8.2 nathanw tx_chipset_tag_t tc = chip->vc_v;
443 1.23.8.2 nathanw txreg_t reg;
444 1.23.8.2 nathanw u_int32_t val;
445 1.23.8.2 nathanw
446 1.23.8.2 nathanw h = chip->vc_fbwidth;
447 1.23.8.2 nathanw v = chip->vc_fbheight;
448 1.23.8.2 nathanw reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
449 1.23.8.2 nathanw split = reg & TX3912_VIDEOCTRL1_DISPSPLIT;
450 1.23.8.2 nathanw bit8 = (TX3912_VIDEOCTRL1_BITSEL(reg) ==
451 1.23.8.2 nathanw TX3912_VIDEOCTRL1_BITSEL_8BITCOLOR);
452 1.23.8.2 nathanw val = TX3912_VIDEOCTRL1_BITSEL(reg);
453 1.23.8.2 nathanw
454 1.23.8.2 nathanw if ((val == TX3912_VIDEOCTRL1_BITSEL_8BITCOLOR) && !split) {
455 1.23.8.2 nathanw /* (LCD horizontal pixels / 8bit) * RGB - 1 */
456 1.23.8.2 nathanw horzval = (h / 8) * 3 - 1;
457 1.23.8.2 nathanw } else {
458 1.23.8.2 nathanw horzval = h / 4 - 1;
459 1.23.8.2 nathanw }
460 1.23.8.2 nathanw lineval = (split ? v / 2 : v) - 1;
461 1.23.8.2 nathanw
462 1.23.8.2 nathanw /* Video rate */
463 1.23.8.2 nathanw /* XXX
464 1.23.8.2 nathanw * probably This value should be determined from DFINT and LCDINT
465 1.23.8.2 nathanw */
466 1.23.8.2 nathanw reg = TX3912_VIDEOCTRL2_VIDRATE_SET(0, horzval + 1);
467 1.23.8.2 nathanw /* Horizontal size of LCD */
468 1.23.8.2 nathanw reg = TX3912_VIDEOCTRL2_HORZVAL_SET(reg, horzval);
469 1.23.8.2 nathanw /* # of lines for the LCD */
470 1.23.8.2 nathanw reg = TX3912_VIDEOCTRL2_LINEVAL_SET(reg, lineval);
471 1.23.8.2 nathanw
472 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL2_REG, reg);
473 1.23.8.2 nathanw }
474 1.23.8.2 nathanw
475 1.23.8.2 nathanw void
476 1.23.8.2 nathanw tx3912video_reset(struct video_chip *chip)
477 1.23.8.2 nathanw {
478 1.23.8.2 nathanw tx_chipset_tag_t tc = chip->vc_v;
479 1.23.8.2 nathanw txreg_t reg;
480 1.23.8.2 nathanw
481 1.23.8.2 nathanw reg = tx_conf_read(tc, TX3912_VIDEOCTRL1_REG);
482 1.23.8.2 nathanw
483 1.23.8.2 nathanw /* Disable video logic at end of this frame */
484 1.23.8.2 nathanw reg |= TX3912_VIDEOCTRL1_ENFREEZEFRAME;
485 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
486 1.23.8.2 nathanw
487 1.23.8.2 nathanw /* Wait for end of frame */
488 1.23.8.2 nathanw delay(30 * 1000);
489 1.23.8.2 nathanw
490 1.23.8.2 nathanw /* Make sure to disable video logic */
491 1.23.8.2 nathanw reg &= ~TX3912_VIDEOCTRL1_ENVID;
492 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
493 1.23.8.2 nathanw
494 1.23.8.2 nathanw delay(1000);
495 1.23.8.2 nathanw
496 1.23.8.2 nathanw /* Enable video logic again */
497 1.23.8.2 nathanw reg &= ~TX3912_VIDEOCTRL1_ENFREEZEFRAME;
498 1.23.8.2 nathanw reg |= TX3912_VIDEOCTRL1_ENVID;
499 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL1_REG, reg);
500 1.23.8.2 nathanw
501 1.23.8.2 nathanw delay(1000);
502 1.23.8.2 nathanw }
503 1.23.8.2 nathanw
504 1.23.8.2 nathanw int
505 1.23.8.2 nathanw tx3912video_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
506 1.23.8.2 nathanw {
507 1.23.8.2 nathanw struct tx3912video_softc *sc = (struct tx3912video_softc *)v;
508 1.23.8.2 nathanw struct hpcfb_fbconf *fbconf;
509 1.23.8.2 nathanw struct hpcfb_dspconf *dspconf;
510 1.23.8.2 nathanw struct wsdisplay_cmap *cmap;
511 1.23.8.2 nathanw u_int8_t *r, *g, *b;
512 1.23.8.2 nathanw u_int32_t *rgb;
513 1.23.8.2 nathanw int idx, cnt, error;
514 1.23.8.2 nathanw
515 1.23.8.2 nathanw switch (cmd) {
516 1.23.8.2 nathanw case WSDISPLAYIO_GETCMAP:
517 1.23.8.2 nathanw cmap = (struct wsdisplay_cmap*)data;
518 1.23.8.2 nathanw cnt = cmap->count;
519 1.23.8.2 nathanw idx = cmap->index;
520 1.23.8.2 nathanw
521 1.23.8.2 nathanw if (sc->sc_fbconf.hf_class != HPCFB_CLASS_INDEXCOLOR ||
522 1.23.8.2 nathanw sc->sc_fbconf.hf_pack_width != 8 ||
523 1.23.8.2 nathanw !LEGAL_CLUT_INDEX(idx) ||
524 1.23.8.2 nathanw !LEGAL_CLUT_INDEX(idx + cnt -1)) {
525 1.23.8.2 nathanw return (EINVAL);
526 1.23.8.2 nathanw }
527 1.23.8.2 nathanw
528 1.23.8.2 nathanw if (!uvm_useracc(cmap->red, cnt, B_WRITE) ||
529 1.23.8.2 nathanw !uvm_useracc(cmap->green, cnt, B_WRITE) ||
530 1.23.8.2 nathanw !uvm_useracc(cmap->blue, cnt, B_WRITE)) {
531 1.23.8.2 nathanw return (EFAULT);
532 1.23.8.2 nathanw }
533 1.23.8.2 nathanw
534 1.23.8.2 nathanw error = cmap_work_alloc(&r, &g, &b, &rgb, cnt);
535 1.23.8.2 nathanw if (error != 0) {
536 1.23.8.2 nathanw cmap_work_free(r, g, b, rgb);
537 1.23.8.2 nathanw return (ENOMEM);
538 1.23.8.2 nathanw }
539 1.23.8.2 nathanw tx3912video_clut_get(sc, rgb, idx, cnt);
540 1.23.8.2 nathanw rgb24_decompose(rgb, r, g, b, cnt);
541 1.23.8.2 nathanw
542 1.23.8.2 nathanw copyout(r, cmap->red, cnt);
543 1.23.8.2 nathanw copyout(g, cmap->green,cnt);
544 1.23.8.2 nathanw copyout(b, cmap->blue, cnt);
545 1.23.8.2 nathanw
546 1.23.8.2 nathanw cmap_work_free(r, g, b, rgb);
547 1.23.8.2 nathanw
548 1.23.8.2 nathanw return (0);
549 1.23.8.2 nathanw
550 1.23.8.2 nathanw case WSDISPLAYIO_PUTCMAP:
551 1.23.8.2 nathanw /*
552 1.23.8.2 nathanw * TX3912 can't change CLUT index. R:G:B = 3:3:2
553 1.23.8.2 nathanw */
554 1.23.8.2 nathanw return (0);
555 1.23.8.2 nathanw
556 1.23.8.2 nathanw case HPCFBIO_GCONF:
557 1.23.8.2 nathanw fbconf = (struct hpcfb_fbconf *)data;
558 1.23.8.2 nathanw if (fbconf->hf_conf_index != 0 &&
559 1.23.8.2 nathanw fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
560 1.23.8.2 nathanw return (EINVAL);
561 1.23.8.2 nathanw }
562 1.23.8.2 nathanw *fbconf = sc->sc_fbconf; /* structure assignment */
563 1.23.8.2 nathanw return (0);
564 1.23.8.2 nathanw
565 1.23.8.2 nathanw case HPCFBIO_SCONF:
566 1.23.8.2 nathanw fbconf = (struct hpcfb_fbconf *)data;
567 1.23.8.2 nathanw if (fbconf->hf_conf_index != 0 &&
568 1.23.8.2 nathanw fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
569 1.23.8.2 nathanw return (EINVAL);
570 1.23.8.2 nathanw }
571 1.23.8.2 nathanw /*
572 1.23.8.2 nathanw * nothing to do because we have only one configration
573 1.23.8.2 nathanw */
574 1.23.8.2 nathanw return (0);
575 1.23.8.2 nathanw
576 1.23.8.2 nathanw case HPCFBIO_GDSPCONF:
577 1.23.8.2 nathanw dspconf = (struct hpcfb_dspconf *)data;
578 1.23.8.2 nathanw if ((dspconf->hd_unit_index != 0 &&
579 1.23.8.2 nathanw dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
580 1.23.8.2 nathanw (dspconf->hd_conf_index != 0 &&
581 1.23.8.2 nathanw dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
582 1.23.8.2 nathanw return (EINVAL);
583 1.23.8.2 nathanw }
584 1.23.8.2 nathanw *dspconf = sc->sc_dspconf; /* structure assignment */
585 1.23.8.2 nathanw return (0);
586 1.23.8.2 nathanw
587 1.23.8.2 nathanw case HPCFBIO_SDSPCONF:
588 1.23.8.2 nathanw dspconf = (struct hpcfb_dspconf *)data;
589 1.23.8.2 nathanw if ((dspconf->hd_unit_index != 0 &&
590 1.23.8.2 nathanw dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
591 1.23.8.2 nathanw (dspconf->hd_conf_index != 0 &&
592 1.23.8.2 nathanw dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
593 1.23.8.2 nathanw return (EINVAL);
594 1.23.8.2 nathanw }
595 1.23.8.2 nathanw /*
596 1.23.8.2 nathanw * nothing to do
597 1.23.8.2 nathanw * because we have only one unit and one configration
598 1.23.8.2 nathanw */
599 1.23.8.2 nathanw return (0);
600 1.23.8.2 nathanw
601 1.23.8.2 nathanw case HPCFBIO_GOP:
602 1.23.8.2 nathanw case HPCFBIO_SOP:
603 1.23.8.2 nathanw /* XXX not implemented yet */
604 1.23.8.2 nathanw return (EINVAL);
605 1.23.8.2 nathanw }
606 1.23.8.2 nathanw
607 1.23.8.3 nathanw return (EPASSTHROUGH);
608 1.23.8.2 nathanw }
609 1.23.8.2 nathanw
610 1.23.8.2 nathanw paddr_t
611 1.23.8.2 nathanw tx3912video_mmap(void *ctx, off_t offset, int prot)
612 1.23.8.2 nathanw {
613 1.23.8.2 nathanw struct tx3912video_softc *sc = (struct tx3912video_softc *)ctx;
614 1.23.8.2 nathanw
615 1.23.8.2 nathanw if (offset < 0 || (sc->sc_fbconf.hf_bytes_per_plane +
616 1.23.8.2 nathanw sc->sc_fbconf.hf_offset) < offset) {
617 1.23.8.2 nathanw return (-1);
618 1.23.8.2 nathanw }
619 1.23.8.2 nathanw
620 1.23.8.2 nathanw return (mips_btop(sc->sc_chip->vc_fbpaddr + offset));
621 1.23.8.2 nathanw }
622 1.23.8.2 nathanw
623 1.23.8.2 nathanw /*
624 1.23.8.2 nathanw * CLUT staff
625 1.23.8.2 nathanw */
626 1.23.8.2 nathanw static const struct {
627 1.23.8.2 nathanw int mul, div;
628 1.23.8.2 nathanw } dither_list [] = {
629 1.23.8.2 nathanw [TX3912_VIDEO_DITHER_DUTYCYCLE_1] = { 1, 1 },
630 1.23.8.2 nathanw [TX3912_VIDEO_DITHER_DUTYCYCLE_6_7] = { 6, 7 },
631 1.23.8.2 nathanw [TX3912_VIDEO_DITHER_DUTYCYCLE_4_5] = { 4, 5 },
632 1.23.8.2 nathanw [TX3912_VIDEO_DITHER_DUTYCYCLE_3_4] = { 3, 4 },
633 1.23.8.2 nathanw [TX3912_VIDEO_DITHER_DUTYCYCLE_5_7] = { 5, 7 },
634 1.23.8.2 nathanw [TX3912_VIDEO_DITHER_DUTYCYCLE_2_3] = { 2, 3 },
635 1.23.8.2 nathanw [TX3912_VIDEO_DITHER_DUTYCYCLE_3_5] = { 3, 5 },
636 1.23.8.2 nathanw [TX3912_VIDEO_DITHER_DUTYCYCLE_4_7] = { 4, 7 },
637 1.23.8.2 nathanw [TX3912_VIDEO_DITHER_DUTYCYCLE_2_4] = { 2, 4 },
638 1.23.8.2 nathanw [TX3912_VIDEO_DITHER_DUTYCYCLE_3_7] = { 3, 7 },
639 1.23.8.2 nathanw [TX3912_VIDEO_DITHER_DUTYCYCLE_2_5] = { 2, 5 },
640 1.23.8.2 nathanw [TX3912_VIDEO_DITHER_DUTYCYCLE_1_3] = { 1, 3 },
641 1.23.8.2 nathanw [TX3912_VIDEO_DITHER_DUTYCYCLE_2_7] = { 2, 7 },
642 1.23.8.2 nathanw [TX3912_VIDEO_DITHER_DUTYCYCLE_1_5] = { 1, 5 },
643 1.23.8.2 nathanw [TX3912_VIDEO_DITHER_DUTYCYCLE_1_7] = { 1, 7 },
644 1.23.8.2 nathanw [TX3912_VIDEO_DITHER_DUTYCYCLE_0] = { 0, 1 }
645 1.23.8.2 nathanw }, *dlp;
646 1.23.8.2 nathanw
647 1.23.8.2 nathanw static const int dither_level8[8] = {
648 1.23.8.2 nathanw TX3912_VIDEO_DITHER_DUTYCYCLE_0,
649 1.23.8.2 nathanw TX3912_VIDEO_DITHER_DUTYCYCLE_2_7,
650 1.23.8.2 nathanw TX3912_VIDEO_DITHER_DUTYCYCLE_2_5,
651 1.23.8.2 nathanw TX3912_VIDEO_DITHER_DUTYCYCLE_2_4,
652 1.23.8.2 nathanw TX3912_VIDEO_DITHER_DUTYCYCLE_3_5,
653 1.23.8.2 nathanw TX3912_VIDEO_DITHER_DUTYCYCLE_5_7,
654 1.23.8.2 nathanw TX3912_VIDEO_DITHER_DUTYCYCLE_4_5,
655 1.23.8.2 nathanw TX3912_VIDEO_DITHER_DUTYCYCLE_1,
656 1.23.8.2 nathanw };
657 1.23.8.2 nathanw
658 1.23.8.2 nathanw static const int dither_level4[4] = {
659 1.23.8.2 nathanw TX3912_VIDEO_DITHER_DUTYCYCLE_0,
660 1.23.8.2 nathanw TX3912_VIDEO_DITHER_DUTYCYCLE_1_3,
661 1.23.8.2 nathanw TX3912_VIDEO_DITHER_DUTYCYCLE_5_7,
662 1.23.8.2 nathanw TX3912_VIDEO_DITHER_DUTYCYCLE_1,
663 1.23.8.2 nathanw };
664 1.23.8.2 nathanw
665 1.23.8.2 nathanw static int
666 1.23.8.2 nathanw __get_color8(int luti)
667 1.23.8.2 nathanw {
668 1.23.8.2 nathanw KASSERT(luti >=0 && luti < 8);
669 1.23.8.2 nathanw dlp = &dither_list[dither_level8[luti]];
670 1.23.8.2 nathanw
671 1.23.8.2 nathanw return ((0xff * dlp->mul) / dlp->div);
672 1.23.8.2 nathanw }
673 1.23.8.2 nathanw
674 1.23.8.2 nathanw static int
675 1.23.8.2 nathanw __get_color4(int luti)
676 1.23.8.2 nathanw {
677 1.23.8.2 nathanw KASSERT(luti >=0 && luti < 4);
678 1.23.8.2 nathanw dlp = &dither_list[dither_level4[luti]];
679 1.23.8.2 nathanw
680 1.23.8.2 nathanw return ((0xff * dlp->mul) / dlp->div);
681 1.23.8.2 nathanw }
682 1.23.8.2 nathanw
683 1.23.8.2 nathanw void
684 1.23.8.2 nathanw tx3912video_clut_get(struct tx3912video_softc *sc, u_int32_t *rgb, int beg,
685 1.23.8.2 nathanw int cnt)
686 1.23.8.2 nathanw {
687 1.23.8.2 nathanw int i;
688 1.23.8.2 nathanw
689 1.23.8.2 nathanw KASSERT(rgb);
690 1.23.8.2 nathanw KASSERT(LEGAL_CLUT_INDEX(beg));
691 1.23.8.2 nathanw KASSERT(LEGAL_CLUT_INDEX(beg + cnt - 1));
692 1.23.8.2 nathanw
693 1.23.8.2 nathanw for (i = beg; i < beg + cnt; i++) {
694 1.23.8.2 nathanw *rgb++ = RGB24(__get_color8((i >> 5) & 0x7),
695 1.23.8.2 nathanw __get_color8((i >> 2) & 0x7),
696 1.23.8.2 nathanw __get_color4(i & 0x3));
697 1.23.8.2 nathanw }
698 1.23.8.2 nathanw }
699 1.23.8.2 nathanw
700 1.23.8.2 nathanw void
701 1.23.8.2 nathanw tx3912video_clut_install(void *ctx, struct rasops_info *ri)
702 1.23.8.2 nathanw {
703 1.23.8.2 nathanw struct tx3912video_softc *sc = ctx;
704 1.23.8.5 nathanw static const int system_cmap[0x10] = {
705 1.23.8.2 nathanw TX3912VIDEO_BLACK,
706 1.23.8.2 nathanw TX3912VIDEO_RED,
707 1.23.8.2 nathanw TX3912VIDEO_GREEN,
708 1.23.8.2 nathanw TX3912VIDEO_YELLOW,
709 1.23.8.2 nathanw TX3912VIDEO_BLUE,
710 1.23.8.2 nathanw TX3912VIDEO_MAGENTA,
711 1.23.8.2 nathanw TX3912VIDEO_CYAN,
712 1.23.8.2 nathanw TX3912VIDEO_WHITE,
713 1.23.8.2 nathanw TX3912VIDEO_DARK_BLACK,
714 1.23.8.2 nathanw TX3912VIDEO_DARK_RED,
715 1.23.8.2 nathanw TX3912VIDEO_DARK_GREEN,
716 1.23.8.2 nathanw TX3912VIDEO_DARK_YELLOW,
717 1.23.8.2 nathanw TX3912VIDEO_DARK_BLUE,
718 1.23.8.2 nathanw TX3912VIDEO_DARK_MAGENTA,
719 1.23.8.2 nathanw TX3912VIDEO_DARK_CYAN,
720 1.23.8.2 nathanw TX3912VIDEO_DARK_WHITE,
721 1.23.8.2 nathanw };
722 1.23.8.2 nathanw
723 1.23.8.2 nathanw KASSERT(ri);
724 1.23.8.2 nathanw
725 1.23.8.2 nathanw if (sc->sc_chip->vc_fbdepth == 8) {
726 1.23.8.2 nathanw /* XXX 2bit gray scale LUT not supported */
727 1.23.8.2 nathanw memcpy(ri->ri_devcmap, system_cmap, sizeof system_cmap);
728 1.23.8.2 nathanw }
729 1.23.8.2 nathanw }
730 1.23.8.2 nathanw
731 1.23.8.2 nathanw void
732 1.23.8.2 nathanw tx3912video_clut_init(struct tx3912video_softc *sc)
733 1.23.8.2 nathanw {
734 1.23.8.2 nathanw tx_chipset_tag_t tc = sc->sc_chip->vc_v;
735 1.23.8.2 nathanw
736 1.23.8.2 nathanw if (sc->sc_chip->vc_fbdepth != 8) {
737 1.23.8.2 nathanw return; /* XXX 2bit gray scale LUT not supported */
738 1.23.8.2 nathanw }
739 1.23.8.2 nathanw
740 1.23.8.2 nathanw /*
741 1.23.8.2 nathanw * time-based dithering pattern (TOSHIBA recommended pattern)
742 1.23.8.2 nathanw */
743 1.23.8.2 nathanw /* 2/3, 1/3 */
744 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL8_REG,
745 1.23.8.2 nathanw TX3912_VIDEOCTRL8_PAT2_3_DEFAULT);
746 1.23.8.2 nathanw /* 3/4, 2/4 */
747 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL9_REG,
748 1.23.8.2 nathanw (TX3912_VIDEOCTRL9_PAT3_4_DEFAULT << 16) |
749 1.23.8.2 nathanw TX3912_VIDEOCTRL9_PAT2_4_DEFAULT);
750 1.23.8.2 nathanw /* 4/5, 1/5 */
751 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL10_REG,
752 1.23.8.2 nathanw TX3912_VIDEOCTRL10_PAT4_5_DEFAULT);
753 1.23.8.2 nathanw /* 3/5, 2/5 */
754 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL11_REG,
755 1.23.8.2 nathanw TX3912_VIDEOCTRL11_PAT3_5_DEFAULT);
756 1.23.8.2 nathanw /* 6/7, 1/7 */
757 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL12_REG,
758 1.23.8.2 nathanw TX3912_VIDEOCTRL12_PAT6_7_DEFAULT);
759 1.23.8.2 nathanw /* 5/7, 2/7 */
760 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL13_REG,
761 1.23.8.2 nathanw TX3912_VIDEOCTRL13_PAT5_7_DEFAULT);
762 1.23.8.2 nathanw /* 4/7, 3/7 */
763 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL14_REG,
764 1.23.8.2 nathanw TX3912_VIDEOCTRL14_PAT4_7_DEFAULT);
765 1.23.8.2 nathanw
766 1.23.8.2 nathanw /*
767 1.23.8.2 nathanw * dither-pattern look-up table. (selected by uch)
768 1.23.8.2 nathanw */
769 1.23.8.2 nathanw /* red */
770 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL5_REG,
771 1.23.8.2 nathanw (dither_level8[7] << 28) |
772 1.23.8.2 nathanw (dither_level8[6] << 24) |
773 1.23.8.2 nathanw (dither_level8[5] << 20) |
774 1.23.8.2 nathanw (dither_level8[4] << 16) |
775 1.23.8.2 nathanw (dither_level8[3] << 12) |
776 1.23.8.2 nathanw (dither_level8[2] << 8) |
777 1.23.8.2 nathanw (dither_level8[1] << 4) |
778 1.23.8.2 nathanw (dither_level8[0] << 0));
779 1.23.8.2 nathanw /* green */
780 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL6_REG,
781 1.23.8.2 nathanw (dither_level8[7] << 28) |
782 1.23.8.2 nathanw (dither_level8[6] << 24) |
783 1.23.8.2 nathanw (dither_level8[5] << 20) |
784 1.23.8.2 nathanw (dither_level8[4] << 16) |
785 1.23.8.2 nathanw (dither_level8[3] << 12) |
786 1.23.8.2 nathanw (dither_level8[2] << 8) |
787 1.23.8.2 nathanw (dither_level8[1] << 4) |
788 1.23.8.2 nathanw (dither_level8[0] << 0));
789 1.23.8.2 nathanw /* blue (2bit gray scale also use this look-up table) */
790 1.23.8.2 nathanw tx_conf_write(tc, TX3912_VIDEOCTRL7_REG,
791 1.23.8.2 nathanw (dither_level4[3] << 12) |
792 1.23.8.2 nathanw (dither_level4[2] << 8) |
793 1.23.8.2 nathanw (dither_level4[1] << 4) |
794 1.23.8.2 nathanw (dither_level4[0] << 0));
795 1.23.8.2 nathanw
796 1.23.8.2 nathanw tx3912video_reset(sc->sc_chip);
797 1.23.8.2 nathanw }
798