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