hd64461video.c revision 1.4 1 1.4 jdolecek /* $NetBSD: hd64461video.c,v 1.4 2001/08/05 18:07:54 jdolecek Exp $ */
2 1.1 uch
3 1.1 uch /*-
4 1.1 uch * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.1 uch * All rights reserved.
6 1.1 uch *
7 1.1 uch * This code is derived from software contributed to The NetBSD Foundation
8 1.1 uch * by UCHIYAMA Yasushi.
9 1.1 uch *
10 1.1 uch * Redistribution and use in source and binary forms, with or without
11 1.1 uch * modification, are permitted provided that the following conditions
12 1.1 uch * are met:
13 1.1 uch * 1. Redistributions of source code must retain the above copyright
14 1.1 uch * notice, this list of conditions and the following disclaimer.
15 1.1 uch * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 uch * notice, this list of conditions and the following disclaimer in the
17 1.1 uch * documentation and/or other materials provided with the distribution.
18 1.1 uch * 3. All advertising materials mentioning features or use of this software
19 1.1 uch * must display the following acknowledgement:
20 1.1 uch * This product includes software developed by the NetBSD
21 1.1 uch * Foundation, Inc. and its contributors.
22 1.1 uch * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 uch * contributors may be used to endorse or promote products derived
24 1.1 uch * from this software without specific prior written permission.
25 1.1 uch *
26 1.1 uch * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 uch * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 uch * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 uch * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 uch * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 uch * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 uch * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 uch * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 uch * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 uch * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 uch * POSSIBILITY OF SUCH DAMAGE.
37 1.1 uch */
38 1.1 uch // #define HD64461VIDEO_DEBUG
39 1.1 uch // #define HD64461VIDEO_HWACCEL
40 1.1 uch
41 1.1 uch #include <sys/param.h>
42 1.1 uch #include <sys/systm.h>
43 1.1 uch #include <sys/device.h>
44 1.1 uch #include <sys/malloc.h>
45 1.1 uch
46 1.1 uch #include <sys/conf.h> /* cdev_decl */
47 1.1 uch #include <dev/cons.h> /* consdev */
48 1.1 uch
49 1.1 uch /* ioctl */
50 1.1 uch #include <sys/ioctl.h>
51 1.1 uch #include <sys/buf.h>
52 1.1 uch #include <uvm/uvm_extern.h>
53 1.1 uch
54 1.1 uch #include <machine/bus.h>
55 1.1 uch #include <machine/intr.h>
56 1.1 uch
57 1.1 uch #include <hpcsh/dev/hd64461/hd64461var.h>
58 1.1 uch #include <hpcsh/dev/hd64461/hd64461reg.h>
59 1.1 uch #include <hpcsh/dev/hd64461/hd64461videoreg.h>
60 1.1 uch
61 1.1 uch #include <dev/wscons/wsdisplayvar.h>
62 1.1 uch #include <dev/rasops/rasops.h>
63 1.1 uch
64 1.1 uch #include <dev/wscons/wsconsio.h>
65 1.1 uch #include <dev/hpc/hpcfbvar.h>
66 1.1 uch #include <dev/hpc/hpcfbio.h>
67 1.1 uch #include <dev/hpc/video_subr.h>
68 1.1 uch
69 1.1 uch #include <machine/bootinfo.h>
70 1.1 uch
71 1.1 uch #ifdef HD64461VIDEO_DEBUG
72 1.1 uch #include <hpcsh/hpcsh/debug.h>
73 1.1 uch #endif
74 1.1 uch
75 1.1 uch #ifdef HD64461VIDEO_DEBUG
76 1.1 uch int hd64461video_debug = 1;
77 1.1 uch #define DPRINTF(fmt, args...) \
78 1.1 uch if (hd64461video_debug) \
79 1.1 uch printf("%s: " fmt, __FUNCTION__ , ##args)
80 1.1 uch #define DPRINTFN(n, arg) \
81 1.1 uch if (hd64461video_debug > (n)) \
82 1.1 uch printf("%s: " fmt, __FUNCTION__ , ##args)
83 1.1 uch #else
84 1.1 uch #define DPRINTF(arg...) ((void)0)
85 1.1 uch #define DPRINTFN(n, arg...) ((void)0)
86 1.1 uch #endif
87 1.1 uch
88 1.1 uch struct hd64461video_chip;
89 1.1 uch struct hd64461video_font {
90 1.1 uch struct wsdisplay_font wsfont;
91 1.1 uch int c, cw, cstep;
92 1.1 uch int loaded;
93 1.1 uch };
94 1.1 uch
95 1.1 uch struct hd64461video_softc {
96 1.1 uch struct device sc_dev;
97 1.1 uch enum hd64461_module_id sc_module_id;
98 1.1 uch struct hd64461video_chip *sc_vc;
99 1.1 uch
100 1.1 uch struct hd64461video_font sc_font;
101 1.1 uch };
102 1.1 uch
103 1.1 uch static struct hd64461video_chip {
104 1.1 uch struct video_chip vc;
105 1.1 uch enum hd64461video_display_mode {
106 1.1 uch LCD256_C,
107 1.1 uch LCD64K_C,
108 1.1 uch LCD64_MONO,
109 1.1 uch LCD16_MONO,
110 1.1 uch LCD4_MONO,
111 1.1 uch LCD2_MONO,
112 1.1 uch CRT256_C,
113 1.1 uch LCDCRT
114 1.1 uch };
115 1.1 uch enum hd64461video_display_mode mode;
116 1.1 uch struct hpcfb_dspconf hd;
117 1.1 uch struct hpcfb_fbconf hf;
118 1.1 uch u_int8_t *off_screen_addr;
119 1.1 uch size_t off_screen_size;
120 1.1 uch
121 1.1 uch int console;
122 1.1 uch } hd64461video_chip;
123 1.1 uch
124 1.1 uch static int hd64461video_match(struct device *, struct cfdata *, void *);
125 1.1 uch static void hd64461video_attach(struct device *, struct device *, void *);
126 1.1 uch void hd64461video_cnprobe(struct consdev *);
127 1.1 uch void hd64461video_cninit(struct consdev *);
128 1.1 uch
129 1.1 uch static void setup_hpcfbif(struct hd64461video_chip *);
130 1.1 uch static void update_videochip_status(struct hd64461video_chip *);
131 1.1 uch static size_t frame_buffer_size(struct hd64461video_chip *);
132 1.1 uch static void hwaccel_init(struct hd64461video_chip *);
133 1.1 uch
134 1.1 uch static void set_clut(struct hd64461video_chip *, int, int, u_int8_t *,
135 1.1 uch u_int8_t *, u_int8_t *);
136 1.1 uch static void get_clut(struct hd64461video_chip *, int, int, u_int8_t *,
137 1.1 uch u_int8_t *, u_int8_t *);
138 1.1 uch static void set_display_mode(struct hd64461video_chip *) __attribute__((__unused__));
139 1.1 uch static void set_display_mode_lcdc(struct hd64461video_chip *);
140 1.1 uch static void set_display_mode_crtc(struct hd64461video_chip *);
141 1.1 uch
142 1.1 uch #ifdef HD64461VIDEO_DEBUG
143 1.1 uch static void _info(struct hd64461video_softc *) __attribute__((__unused__));
144 1.1 uch static void _dump(void) __attribute__((__unused__));
145 1.1 uch #endif
146 1.1 uch
147 1.1 uch struct cfattach hd64461video_ca = {
148 1.1 uch sizeof(struct hd64461video_softc), hd64461video_match,
149 1.1 uch hd64461video_attach
150 1.1 uch };
151 1.1 uch
152 1.1 uch int hd64461video_ioctl(void *, u_long, caddr_t, int, struct proc *);
153 1.1 uch paddr_t hd64461video_mmap(void *, off_t, int);
154 1.1 uch void hd64461video_cursor(void *, int, int, int, int, int);
155 1.1 uch void hd64461video_bitblit(void *, int, int, int, int, int, int);
156 1.1 uch void hd64461video_erase(void *, int, int, int, int, int);
157 1.1 uch void hd64461video_putchar(void *, int, int, struct wsdisplay_font *, int, int,
158 1.1 uch u_int, int);
159 1.1 uch void hd64461video_setclut(void *, struct rasops_info *);
160 1.1 uch void hd64461video_font(void *, struct wsdisplay_font *);
161 1.1 uch void hd64461video_iodone(void *);
162 1.1 uch
163 1.1 uch struct hpcfb_accessops hd64461video_ha = {
164 1.1 uch .ioctl = hd64461video_ioctl,
165 1.1 uch .mmap = hd64461video_mmap,
166 1.1 uch #ifdef HD64461VIDEO_HWACCEL
167 1.1 uch .cursor = hd64461video_cursor,
168 1.1 uch .bitblit= hd64461video_bitblit,
169 1.1 uch .erase = hd64461video_erase,
170 1.1 uch .putchar= hd64461video_putchar,
171 1.1 uch .setclut= hd64461video_setclut,
172 1.1 uch .font = hd64461video_font,
173 1.1 uch .iodone = hd64461video_iodone
174 1.1 uch #endif /* HD64461VIDEO_HWACCEL */
175 1.1 uch };
176 1.1 uch
177 1.1 uch /* font */
178 1.1 uch static void font_load_16bpp(u_int16_t *, u_int8_t *, int, int, int);
179 1.1 uch static void font_load_8bpp(u_int8_t *, u_int8_t *, int, int, int);
180 1.1 uch static void font_set_attr(struct hd64461video_softc *, struct wsdisplay_font *);
181 1.1 uch static void font_load(struct hd64461video_softc *);
182 1.1 uch static vaddr_t font_start_addr(struct hd64461video_softc *, int);
183 1.1 uch
184 1.1 uch static int
185 1.1 uch hd64461video_match(struct device *parent, struct cfdata *cf, void *aux)
186 1.1 uch {
187 1.1 uch struct hd64461_attach_args *ha = aux;
188 1.1 uch
189 1.1 uch return (ha->ha_module_id == HD64461_MODULE_VIDEO);
190 1.1 uch }
191 1.1 uch
192 1.1 uch static void
193 1.1 uch hd64461video_attach(struct device *parent, struct device *self, void *aux)
194 1.1 uch {
195 1.1 uch struct hd64461_attach_args *ha = aux;
196 1.1 uch struct hd64461video_softc *sc = (struct hd64461video_softc *)self;
197 1.1 uch struct hpcfb_attach_args hfa;
198 1.1 uch struct video_chip *vc = &hd64461video_chip.vc;
199 1.1 uch char pbuf[9];
200 1.1 uch size_t fbsize, on_screen_size;
201 1.1 uch
202 1.1 uch sc->sc_module_id = ha->ha_module_id;
203 1.1 uch sc->sc_vc = &hd64461video_chip;
204 1.1 uch printf(": ");
205 1.1 uch
206 1.1 uch /* detect frame buffer size */
207 1.1 uch fbsize = frame_buffer_size(&hd64461video_chip);
208 1.1 uch format_bytes(pbuf, sizeof(pbuf), fbsize);
209 1.1 uch printf("frame buffer = %s ", pbuf);
210 1.1 uch
211 1.1 uch /* update chip status */
212 1.1 uch update_videochip_status(&hd64461video_chip);
213 1.1 uch // set_display_mode(&hd64461video_chip);
214 1.1 uch
215 1.1 uch if (hd64461video_chip.console)
216 1.1 uch printf(", console");
217 1.1 uch
218 1.1 uch printf("\n");
219 1.1 uch #ifdef HD64461VIDEO_DEBUG
220 1.1 uch _info(sc);
221 1.1 uch _dump();
222 1.1 uch #endif
223 1.1 uch
224 1.1 uch
225 1.1 uch /* setup hpcfb interface */
226 1.1 uch setup_hpcfbif(&hd64461video_chip);
227 1.1 uch
228 1.1 uch /* setup off-screen buffer */
229 1.1 uch on_screen_size = (vc->vc_fbwidth * vc->vc_fbheight * vc->vc_fbdepth) /
230 1.1 uch NBBY;
231 1.1 uch hd64461video_chip.off_screen_addr = (u_int8_t *)vc->vc_fbvaddr +
232 1.1 uch on_screen_size;
233 1.1 uch hd64461video_chip.off_screen_size = fbsize - on_screen_size;
234 1.1 uch /* clean up off-screen area */
235 1.1 uch {
236 1.1 uch u_int8_t *p = hd64461video_chip.off_screen_addr;
237 1.1 uch u_int8_t *end = p + hd64461video_chip.off_screen_size;
238 1.1 uch while (p < end)
239 1.1 uch *p++ = 0xff;
240 1.1 uch }
241 1.1 uch
242 1.1 uch /* initialize hardware acceralation */
243 1.1 uch hwaccel_init(&hd64461video_chip);
244 1.1 uch
245 1.1 uch /* register interface to hpcfb */
246 1.1 uch hfa.ha_console = hd64461video_chip.console;
247 1.1 uch hfa.ha_accessops = &hd64461video_ha;
248 1.1 uch hfa.ha_accessctx = sc;
249 1.1 uch hfa.ha_curfbconf = 0;
250 1.1 uch hfa.ha_nfbconf = 1;
251 1.1 uch hfa.ha_fbconflist = &hd64461video_chip.hf;
252 1.1 uch hfa.ha_curdspconf = 0;
253 1.1 uch hfa.ha_ndspconf = 1;
254 1.1 uch hfa.ha_dspconflist = &hd64461video_chip.hd;
255 1.1 uch
256 1.1 uch config_found(self, &hfa, hpcfbprint);
257 1.1 uch }
258 1.1 uch
259 1.1 uch /* console support */
260 1.1 uch void
261 1.1 uch hd64461video_cninit(struct consdev *cndev)
262 1.1 uch {
263 1.1 uch hd64461video_chip.console = 1;
264 1.1 uch hd64461video_chip.vc.vc_reverse = video_reverse_color();
265 1.1 uch
266 1.1 uch update_videochip_status(&hd64461video_chip);
267 1.1 uch setup_hpcfbif(&hd64461video_chip);
268 1.1 uch hpcfb_cnattach(&hd64461video_chip.hf);
269 1.1 uch
270 1.1 uch cn_tab->cn_pri = CN_INTERNAL;
271 1.1 uch }
272 1.1 uch
273 1.1 uch void
274 1.1 uch hd64461video_cnprobe(struct consdev *cndev)
275 1.1 uch {
276 1.1 uch #if NWSDISPLAY > 0
277 1.1 uch int maj, unit;
278 1.1 uch #endif
279 1.1 uch cndev->cn_dev = NODEV;
280 1.1 uch cndev->cn_pri = CN_NORMAL;
281 1.1 uch
282 1.1 uch #if NWSDISPLAY > 0
283 1.1 uch unit = 0;
284 1.1 uch for (maj = 0; maj < nchrdev; maj++) {
285 1.1 uch if (cdevsw[maj].d_open == wsdisplayopen)
286 1.1 uch break;
287 1.1 uch }
288 1.1 uch
289 1.1 uch if (maj != nchrdev) {
290 1.1 uch cndev->cn_pri = CN_INTERNAL;
291 1.1 uch cndev->cn_dev = makedev(maj, unit);
292 1.1 uch }
293 1.1 uch #endif /* NWSDISPLAY > 0 */
294 1.1 uch }
295 1.1 uch
296 1.1 uch /* hpcfb support */
297 1.1 uch static void
298 1.1 uch setup_hpcfbif(struct hd64461video_chip *hvc)
299 1.1 uch {
300 1.1 uch struct video_chip *vc = &hvc->vc;
301 1.1 uch struct hpcfb_fbconf *fb = &hvc->hf;
302 1.1 uch vaddr_t fbvaddr = vc->vc_fbvaddr;
303 1.1 uch int height = vc->vc_fbheight;
304 1.1 uch int width = vc->vc_fbwidth;
305 1.1 uch int depth = vc->vc_fbdepth;
306 1.1 uch
307 1.1 uch memset(fb, 0, sizeof(struct hpcfb_fbconf));
308 1.1 uch
309 1.1 uch fb->hf_conf_index = 0; /* configuration index */
310 1.1 uch fb->hf_nconfs = 1; /* how many configurations */
311 1.1 uch strncpy(fb->hf_name, "HD64461 video module", HPCFB_MAXNAMELEN);
312 1.2 uch
313 1.2 uch /* frame buffer name */
314 1.1 uch strncpy(fb->hf_conf_name, "LCD", HPCFB_MAXNAMELEN);
315 1.2 uch
316 1.2 uch /* configuration name */
317 1.1 uch fb->hf_height = height;
318 1.1 uch fb->hf_width = width;
319 1.1 uch fb->hf_baseaddr = (u_long)fbvaddr;
320 1.1 uch fb->hf_offset = (u_long)fbvaddr -
321 1.1 uch sh3_ptob(sh3_btop(fbvaddr));
322 1.2 uch
323 1.2 uch /* frame buffer start offset */
324 1.1 uch fb->hf_bytes_per_line = (width * depth) / NBBY;
325 1.1 uch fb->hf_nplanes = 1;
326 1.1 uch fb->hf_bytes_per_plane = height * fb->hf_bytes_per_line;
327 1.1 uch
328 1.1 uch fb->hf_access_flags |= HPCFB_ACCESS_BYTE;
329 1.1 uch fb->hf_access_flags |= HPCFB_ACCESS_WORD;
330 1.1 uch fb->hf_access_flags |= HPCFB_ACCESS_DWORD;
331 1.1 uch if (vc->vc_reverse)
332 1.1 uch fb->hf_access_flags |= HPCFB_ACCESS_REVERSE;
333 1.1 uch
334 1.1 uch switch (depth) {
335 1.1 uch default:
336 1.1 uch panic("%s: not supported color depth\n", __FUNCTION__);
337 1.1 uch /* NOTREACHED */
338 1.1 uch case 16:
339 1.1 uch fb->hf_class = HPCFB_CLASS_RGBCOLOR;
340 1.1 uch fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
341 1.1 uch fb->hf_pack_width = 16;
342 1.1 uch fb->hf_pixels_per_pack = 1;
343 1.1 uch fb->hf_pixel_width = 16;
344 1.1 uch
345 1.1 uch fb->hf_class_data_length = sizeof(struct hf_rgb_tag);
346 1.1 uch /* reserved for future use */
347 1.1 uch fb->hf_u.hf_rgb.hf_flags = 0;
348 1.1 uch
349 1.1 uch fb->hf_u.hf_rgb.hf_red_width = 5;
350 1.1 uch fb->hf_u.hf_rgb.hf_red_shift = 11;
351 1.1 uch fb->hf_u.hf_rgb.hf_green_width = 6;
352 1.1 uch fb->hf_u.hf_rgb.hf_green_shift = 5;
353 1.1 uch fb->hf_u.hf_rgb.hf_blue_width = 5;
354 1.1 uch fb->hf_u.hf_rgb.hf_blue_shift = 0;
355 1.1 uch fb->hf_u.hf_rgb.hf_alpha_width = 0;
356 1.1 uch fb->hf_u.hf_rgb.hf_alpha_shift = 0;
357 1.1 uch break;
358 1.1 uch
359 1.1 uch case 8:
360 1.1 uch fb->hf_class = HPCFB_CLASS_INDEXCOLOR;
361 1.1 uch fb->hf_access_flags |= HPCFB_ACCESS_STATIC;
362 1.1 uch fb->hf_pack_width = 8;
363 1.1 uch fb->hf_pixels_per_pack = 1;
364 1.1 uch fb->hf_pixel_width = 8;
365 1.1 uch fb->hf_class_data_length = sizeof(struct hf_indexed_tag);
366 1.1 uch /* reserved for future use */
367 1.1 uch fb->hf_u.hf_indexed.hf_flags = 0;
368 1.1 uch break;
369 1.1 uch }
370 1.1 uch }
371 1.1 uch
372 1.1 uch static void
373 1.1 uch hwaccel_init(struct hd64461video_chip *hvc)
374 1.1 uch {
375 1.1 uch u_int16_t r;
376 1.1 uch
377 1.1 uch r = HD64461_LCDGRCFGR_ACCRESET;
378 1.1 uch switch (hvc->vc.vc_fbdepth) {
379 1.1 uch default:
380 1.1 uch panic("no bitblit acceralation.");
381 1.1 uch case 16:
382 1.1 uch break;
383 1.1 uch case 8:
384 1.1 uch r |= HD64461_LCDGRCFGR_COLORDEPTH_8BPP;
385 1.1 uch break;
386 1.1 uch }
387 1.1 uch hd64461_reg_write_2(HD64461_LCDGRCFGR_REG16, r);
388 1.1 uch
389 1.1 uch while ((hd64461_reg_read_2(HD64461_LCDGRCFGR_REG16) &
390 1.1 uch HD64461_LCDGRCFGR_ACCSTATUS) != 0)
391 1.1 uch /* busy loop */;
392 1.1 uch r &= ~HD64461_LCDGRCFGR_ACCRESET;
393 1.1 uch hd64461_reg_write_2(HD64461_LCDGRCFGR_REG16, r);
394 1.1 uch
395 1.1 uch while ((hd64461_reg_read_2(HD64461_LCDGRCFGR_REG16) &
396 1.1 uch HD64461_LCDGRCFGR_ACCSTATUS) != 0)
397 1.1 uch /* busy loop */;
398 1.1 uch
399 1.1 uch hd64461_reg_write_2(HD64461_LCDGRDOR_REG16,
400 1.1 uch (hvc->vc.vc_fbwidth - 1) & HD64461_LCDGRDOR_MASK);
401 1.1 uch }
402 1.1 uch
403 1.1 uch /* hpcfb ops */
404 1.1 uch int
405 1.1 uch hd64461video_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
406 1.1 uch {
407 1.1 uch struct hd64461video_softc *sc = (struct hd64461video_softc *)v;
408 1.1 uch struct hpcfb_fbconf *hf = &sc->sc_vc->hf;
409 1.1 uch struct hpcfb_fbconf *fbconf;
410 1.1 uch struct hpcfb_dspconf *dspconf;
411 1.1 uch struct wsdisplay_cmap *cmap;
412 1.1 uch u_int8_t *r, *g, *b;
413 1.4 jdolecek int error;
414 1.4 jdolecek size_t idx, cnt;
415 1.1 uch
416 1.1 uch switch (cmd) {
417 1.1 uch case WSDISPLAYIO_GETCMAP:
418 1.1 uch cmap = (struct wsdisplay_cmap*)data;
419 1.1 uch cnt = cmap->count;
420 1.1 uch idx = cmap->index;
421 1.1 uch
422 1.1 uch if (hf->hf_class != HPCFB_CLASS_INDEXCOLOR ||
423 1.1 uch hf->hf_pack_width != 8 ||
424 1.1 uch !LEGAL_CLUT_INDEX(idx) ||
425 1.1 uch !LEGAL_CLUT_INDEX(idx + cnt -1)) {
426 1.1 uch return (EINVAL);
427 1.1 uch }
428 1.1 uch
429 1.1 uch if (!uvm_useracc(cmap->red, cnt, B_WRITE) ||
430 1.1 uch !uvm_useracc(cmap->green, cnt, B_WRITE) ||
431 1.1 uch !uvm_useracc(cmap->blue, cnt, B_WRITE)) {
432 1.1 uch return (EFAULT);
433 1.1 uch }
434 1.1 uch
435 1.1 uch error = cmap_work_alloc(&r, &g, &b, 0, cnt);
436 1.1 uch if (error != 0) {
437 1.1 uch cmap_work_free(r, g, b, 0);
438 1.1 uch return (ENOMEM);
439 1.1 uch }
440 1.1 uch
441 1.1 uch get_clut(sc->sc_vc, idx, cnt, r, g, b);
442 1.1 uch copyout(r, cmap->red, cnt);
443 1.1 uch copyout(g, cmap->green,cnt);
444 1.1 uch copyout(b, cmap->blue, cnt);
445 1.1 uch cmap_work_free(r, g, b, 0);
446 1.1 uch
447 1.1 uch return (0);
448 1.1 uch
449 1.1 uch case WSDISPLAYIO_PUTCMAP:
450 1.1 uch cmap = (struct wsdisplay_cmap *)data;
451 1.1 uch cnt = cmap->count;
452 1.1 uch idx = cmap->index;
453 1.1 uch
454 1.1 uch if (hf->hf_class != HPCFB_CLASS_INDEXCOLOR ||
455 1.1 uch hf->hf_pack_width != 8 ||
456 1.1 uch !LEGAL_CLUT_INDEX(idx) ||
457 1.1 uch !LEGAL_CLUT_INDEX(idx + cnt -1)) {
458 1.1 uch return (EINVAL);
459 1.1 uch }
460 1.1 uch
461 1.1 uch if (!uvm_useracc(cmap->red, cnt, B_WRITE) ||
462 1.1 uch !uvm_useracc(cmap->green, cnt, B_WRITE) ||
463 1.1 uch !uvm_useracc(cmap->blue, cnt, B_WRITE)) {
464 1.1 uch return (EFAULT);
465 1.1 uch }
466 1.1 uch
467 1.1 uch error = cmap_work_alloc(&r, &g, &b, 0, cnt);
468 1.1 uch if (error != 0) {
469 1.1 uch cmap_work_free(r, g, b, 0);
470 1.1 uch return (ENOMEM);
471 1.1 uch }
472 1.1 uch
473 1.1 uch copyin(cmap->red, r, cnt);
474 1.1 uch copyin(cmap->green,g, cnt);
475 1.1 uch copyin(cmap->blue, b, cnt);
476 1.1 uch set_clut(sc->sc_vc, idx, cnt, r, g, b);
477 1.1 uch cmap_work_free(r, g, b, 0);
478 1.1 uch
479 1.1 uch return (0);
480 1.1 uch
481 1.1 uch case HPCFBIO_GCONF:
482 1.1 uch fbconf = (struct hpcfb_fbconf *)data;
483 1.1 uch if (fbconf->hf_conf_index != 0 &&
484 1.1 uch fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
485 1.1 uch return (EINVAL);
486 1.1 uch }
487 1.1 uch *fbconf = *hf; /* structure assignment */
488 1.1 uch return (0);
489 1.1 uch
490 1.1 uch case HPCFBIO_SCONF:
491 1.1 uch fbconf = (struct hpcfb_fbconf *)data;
492 1.1 uch if (fbconf->hf_conf_index != 0 &&
493 1.1 uch fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) {
494 1.1 uch return (EINVAL);
495 1.1 uch }
496 1.1 uch /*
497 1.1 uch * nothing to do because we have only one configration
498 1.1 uch */
499 1.1 uch return (0);
500 1.1 uch
501 1.1 uch case HPCFBIO_GDSPCONF:
502 1.1 uch dspconf = (struct hpcfb_dspconf *)data;
503 1.1 uch if ((dspconf->hd_unit_index != 0 &&
504 1.1 uch dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
505 1.1 uch (dspconf->hd_conf_index != 0 &&
506 1.1 uch dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
507 1.1 uch return (EINVAL);
508 1.1 uch }
509 1.1 uch *dspconf = sc->sc_vc->hd; /* structure assignment */
510 1.1 uch return (0);
511 1.1 uch
512 1.1 uch case HPCFBIO_SDSPCONF:
513 1.1 uch dspconf = (struct hpcfb_dspconf *)data;
514 1.1 uch if ((dspconf->hd_unit_index != 0 &&
515 1.1 uch dspconf->hd_unit_index != HPCFB_CURRENT_UNIT) ||
516 1.1 uch (dspconf->hd_conf_index != 0 &&
517 1.1 uch dspconf->hd_conf_index != HPCFB_CURRENT_CONFIG)) {
518 1.1 uch return (EINVAL);
519 1.1 uch }
520 1.1 uch /*
521 1.1 uch * nothing to do
522 1.1 uch * because we have only one unit and one configration
523 1.1 uch */
524 1.1 uch return (0);
525 1.1 uch
526 1.1 uch case HPCFBIO_GOP:
527 1.1 uch case HPCFBIO_SOP:
528 1.1 uch /* XXX not implemented yet */
529 1.1 uch return (EINVAL);
530 1.1 uch }
531 1.1 uch
532 1.1 uch return (ENOTTY);
533 1.1 uch }
534 1.1 uch
535 1.1 uch paddr_t
536 1.1 uch hd64461video_mmap(void *ctx, off_t offset, int prot)
537 1.1 uch {
538 1.1 uch struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
539 1.1 uch struct hpcfb_fbconf *hf = &sc->sc_vc->hf;
540 1.1 uch
541 1.1 uch if (offset < 0 || (hf->hf_bytes_per_plane + hf->hf_offset) < offset)
542 1.1 uch return (-1);
543 1.1 uch
544 1.1 uch return (sh3_btop(HD64461_FBBASE + offset));
545 1.1 uch }
546 1.1 uch
547 1.1 uch void
548 1.1 uch hd64461video_cursor(void *ctx, int on, int xd, int yd, int w, int h)
549 1.1 uch {
550 1.1 uch struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
551 1.1 uch int xw, yh, width, bpp, adr;
552 1.1 uch u_int16_t r;
553 1.1 uch
554 1.1 uch width = sc->sc_vc->vc.vc_fbwidth;
555 1.1 uch bpp = sc->sc_vc->vc.vc_fbdepth;
556 1.1 uch xw = w - 1;
557 1.1 uch yh = h - 1;
558 1.1 uch
559 1.1 uch /* Wait until previous command done. */
560 1.1 uch hd64461video_iodone(ctx);
561 1.1 uch
562 1.1 uch /* Destination addr */
563 1.1 uch adr = width * yd + xd;
564 1.1 uch if (bpp == 16)
565 1.1 uch adr *= 2;
566 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTDSARH_REG16,
567 1.1 uch HD64461_LCDBBTDSARH(adr));
568 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTDSARL_REG16,
569 1.1 uch HD64461_LCDBBTDSARL(adr));
570 1.1 uch
571 1.1 uch // Width
572 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTDWR_REG16,
573 1.1 uch xw & HD64461_LCDBBTDWR_MASK);
574 1.1 uch
575 1.1 uch // Height
576 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTDHR_REG16,
577 1.1 uch yh & HD64461_LCDBBTDHR_MASK);
578 1.1 uch
579 1.1 uch // Operation (Destination Invert)
580 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTROPR_REG16,
581 1.1 uch HD64461_LCDC_BITBLT_DSTINVERT);
582 1.1 uch
583 1.1 uch // BitBLT mode (Destination Invert)
584 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTMDR_REG16, 0);
585 1.1 uch
586 1.1 uch // Kick.
587 1.1 uch r = hd64461_reg_read_2(HD64461_LCDGRCFGR_REG16);
588 1.1 uch r &= ~HD64461_LCDGRCFGR_ACCSTART_MASK;
589 1.1 uch r |= HD64461_LCDGRCFGR_ACCSTART_BITBLT;
590 1.1 uch hd64461_reg_write_2(HD64461_LCDGRCFGR_REG16, r);
591 1.1 uch }
592 1.1 uch
593 1.1 uch void
594 1.1 uch hd64461video_bitblit(void *ctx, int xs, int ys, int xd, int yd, int h, int w)
595 1.1 uch {
596 1.1 uch struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
597 1.1 uch int xw, yh, width, bpp, condition_a, adr;
598 1.1 uch u_int16_t r;
599 1.1 uch
600 1.1 uch xw = w - 1;
601 1.1 uch yh = h - 1;
602 1.1 uch width = sc->sc_vc->vc.vc_fbwidth;
603 1.1 uch bpp = sc->sc_vc->vc.vc_fbdepth;
604 1.1 uch condition_a = ((ys == yd) && (xs <= xd)) || (ys < yd);
605 1.1 uch
606 1.1 uch hd64461video_iodone(ctx);
607 1.1 uch
608 1.1 uch // Source addr
609 1.1 uch if (condition_a)
610 1.1 uch adr = (width * (ys + yh)) + (xs + xw);
611 1.1 uch else
612 1.1 uch adr = width * ys + xs;
613 1.1 uch if (bpp == 16)
614 1.1 uch adr *= 2;
615 1.1 uch
616 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTSSARH_REG16,
617 1.1 uch HD64461_LCDBBTSSARH(adr));
618 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTSSARL_REG16,
619 1.1 uch HD64461_LCDBBTSSARL(adr));
620 1.1 uch
621 1.1 uch // Destination addr
622 1.1 uch if (condition_a)
623 1.1 uch adr = (width * (yd + yh)) + (xd + xw);
624 1.1 uch else
625 1.1 uch adr = width * yd + xd;
626 1.1 uch if (bpp == 16)
627 1.1 uch adr *= 2;
628 1.1 uch
629 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTDSARH_REG16,
630 1.1 uch HD64461_LCDBBTDSARH(adr));
631 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTDSARL_REG16,
632 1.1 uch HD64461_LCDBBTDSARL(adr));
633 1.1 uch
634 1.1 uch // Width
635 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTDWR_REG16,
636 1.1 uch xw & HD64461_LCDBBTDWR_MASK);
637 1.1 uch
638 1.1 uch // Height
639 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTDHR_REG16,
640 1.1 uch yh & HD64461_LCDBBTDHR_MASK);
641 1.1 uch
642 1.1 uch // Operation (source copy)
643 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTROPR_REG16,
644 1.1 uch HD64461_LCDC_BITBLT_SRCCOPY);
645 1.1 uch
646 1.1 uch // BitBLT mode (on screen to on screen)
647 1.1 uch r = HD64461_LCDBBTMDR_SET(0,
648 1.1 uch HD64461_LCDBBTMDR_ON_SCREEN_TO_ON_SCREEN);
649 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTMDR_REG16, r);
650 1.1 uch
651 1.1 uch // Kick.
652 1.1 uch r = hd64461_reg_read_2(HD64461_LCDGRCFGR_REG16);
653 1.1 uch r &= ~HD64461_LCDGRCFGR_ACCSTART_MASK;
654 1.1 uch r |= HD64461_LCDGRCFGR_ACCSTART_BITBLT;
655 1.1 uch hd64461_reg_write_2(HD64461_LCDGRCFGR_REG16, r);
656 1.1 uch }
657 1.1 uch
658 1.1 uch void
659 1.1 uch hd64461video_erase(void *ctx, int xd, int yd, int h, int w, int attr)
660 1.1 uch {
661 1.1 uch struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
662 1.1 uch int xw, yh, width, bpp, adr;
663 1.1 uch u_int16_t r;
664 1.1 uch
665 1.1 uch width = sc->sc_vc->vc.vc_fbwidth;
666 1.1 uch bpp = sc->sc_vc->vc.vc_fbdepth;
667 1.1 uch xw = w - 1;
668 1.1 uch yh = h - 1;
669 1.1 uch
670 1.1 uch /* Wait until previous command done. */
671 1.1 uch hd64461video_iodone(ctx);
672 1.1 uch
673 1.1 uch /* Destination addr */
674 1.1 uch adr = width * yd + xd;
675 1.1 uch if (bpp == 16)
676 1.1 uch adr *= 2;
677 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTDSARH_REG16,
678 1.1 uch HD64461_LCDBBTDSARH(adr));
679 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTDSARL_REG16,
680 1.1 uch HD64461_LCDBBTDSARL(adr));
681 1.1 uch
682 1.1 uch // Width
683 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTDWR_REG16,
684 1.1 uch xw & HD64461_LCDBBTDWR_MASK);
685 1.1 uch
686 1.1 uch // Height
687 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTDHR_REG16,
688 1.1 uch yh & HD64461_LCDBBTDHR_MASK);
689 1.1 uch
690 1.1 uch // Color
691 1.1 uch hd64461_reg_write_2(HD64461_LCDGRSCR_REG16, 0); //XXX black only
692 1.1 uch
693 1.1 uch // Operation (Solid Color Fill)
694 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTROPR_REG16,
695 1.1 uch HD64461_LCDC_BITBLT_PATCOPY);
696 1.1 uch
697 1.1 uch // BitBLT mode (Solid Color)
698 1.1 uch hd64461_reg_write_2(HD64461_LCDBBTMDR_REG16,
699 1.1 uch HD64461_LCDBBTMDR_PATSELECT_SOLIDCOLOR);
700 1.1 uch
701 1.1 uch // Kick.
702 1.1 uch r = hd64461_reg_read_2(HD64461_LCDGRCFGR_REG16);
703 1.1 uch r &= ~HD64461_LCDGRCFGR_ACCSTART_MASK;
704 1.1 uch r |= HD64461_LCDGRCFGR_ACCSTART_BITBLT;
705 1.1 uch hd64461_reg_write_2(HD64461_LCDGRCFGR_REG16, r);
706 1.1 uch }
707 1.1 uch
708 1.1 uch void
709 1.1 uch hd64461video_putchar(void *ctx, int row, int col, struct wsdisplay_font *font,
710 1.1 uch int fclr, int uclr, u_int uc, int attr)
711 1.1 uch {
712 1.1 uch struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
713 1.1 uch int w, h, cw;
714 1.1 uch
715 1.1 uch w = font->fontwidth;
716 1.1 uch h = font->fontheight;
717 1.1 uch cw = sc->sc_font.cw;
718 1.1 uch hd64461video_bitblit(ctx, (uc % cw) * w,
719 1.1 uch sc->sc_vc->vc.vc_fbheight + (uc / cw) * h, row, col, h, w);
720 1.1 uch }
721 1.1 uch
722 1.1 uch void
723 1.1 uch hd64461video_setclut(void *ctx, struct rasops_info *info)
724 1.1 uch {
725 1.1 uch struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
726 1.1 uch
727 1.1 uch if (sc->sc_vc->vc.vc_fbdepth != 8)
728 1.1 uch return;
729 1.1 uch }
730 1.1 uch
731 1.1 uch void
732 1.1 uch hd64461video_font(void *ctx, struct wsdisplay_font *font)
733 1.1 uch {
734 1.1 uch struct hd64461video_softc *sc = (struct hd64461video_softc *)ctx;
735 1.1 uch
736 1.1 uch font_set_attr(sc, font);
737 1.1 uch font_load(sc);
738 1.1 uch }
739 1.1 uch
740 1.1 uch void
741 1.1 uch hd64461video_iodone(void *ctx)
742 1.1 uch {
743 1.1 uch while ((hd64461_reg_read_2(HD64461_LCDGRCFGR_REG16) &
744 1.1 uch HD64461_LCDGRCFGR_ACCSTATUS) != 0)
745 1.1 uch /* busy loop */;
746 1.1 uch }
747 1.1 uch
748 1.1 uch /* internal */
749 1.1 uch static void
750 1.1 uch font_load_16bpp(u_int16_t *d, u_int8_t *s, int w, int h, int step)
751 1.1 uch {
752 1.1 uch int i, j, n;
753 1.1 uch n = step / sizeof(u_int16_t);
754 1.1 uch
755 1.1 uch for (i = 0; i < h; i++, d += n) {
756 1.1 uch for (j = 0; j < w; j++) {
757 1.1 uch d[j] = *s & (1 << w - j - 1) ? 0xffff : 0x0000;
758 1.1 uch }
759 1.1 uch s++;
760 1.1 uch }
761 1.1 uch }
762 1.1 uch
763 1.1 uch static void
764 1.1 uch font_load_8bpp(u_int8_t *d, u_int8_t *s, int w, int h, int step)
765 1.1 uch {
766 1.1 uch int i, j, n;
767 1.1 uch n = step / sizeof(u_int8_t);
768 1.1 uch
769 1.1 uch for (i = 0; i < h; i++, d += n) {
770 1.1 uch for (j = 0; j < w; j++) {
771 1.1 uch d[j] = *s & (1 << w - j - 1) ? 0xff : 0x00;
772 1.1 uch }
773 1.1 uch s++;
774 1.1 uch }
775 1.1 uch }
776 1.1 uch
777 1.1 uch static void
778 1.1 uch font_set_attr(struct hd64461video_softc *sc, struct wsdisplay_font *f)
779 1.1 uch {
780 1.1 uch struct hd64461video_chip *hvc = sc->sc_vc;
781 1.1 uch struct wsdisplay_font *font = (struct wsdisplay_font *)&sc->sc_font;
782 1.1 uch int w, h, bpp;
783 1.1 uch
784 1.1 uch w = f->fontwidth;
785 1.1 uch h = f->fontheight;
786 1.1 uch bpp = hvc->vc.vc_fbdepth;
787 1.1 uch
788 1.1 uch *font = *f;
789 1.1 uch sc->sc_font.c = (w * bpp) / NBBY;
790 1.1 uch sc->sc_font.cw = hvc->hf.hf_width / w;
791 1.1 uch sc->sc_font.cstep = ((w * h * bpp) / NBBY) * sc->sc_font.cw;
792 1.1 uch
793 1.1 uch DPRINTF("c = %d cw = %d cstep = %d\n", sc->sc_font.c,
794 1.1 uch sc->sc_font.cw, sc->sc_font.cstep);
795 1.1 uch
796 1.1 uch }
797 1.1 uch
798 1.1 uch /* return frame buffer virtual address of charcter #n */
799 1.1 uch static vaddr_t
800 1.1 uch font_start_addr(struct hd64461video_softc *sc, int n)
801 1.1 uch {
802 1.1 uch struct hd64461video_chip *hvc = sc->sc_vc;
803 1.1 uch struct hd64461video_font *font = &sc->sc_font;
804 1.1 uch vaddr_t base;
805 1.1 uch
806 1.1 uch base = (vaddr_t)hvc->off_screen_addr;
807 1.1 uch base += (n / font->cw) * font->cstep + font->c * (n % font->cw);
808 1.1 uch
809 1.1 uch return base;
810 1.1 uch }
811 1.1 uch
812 1.1 uch static void
813 1.1 uch font_load(struct hd64461video_softc *sc)
814 1.1 uch {
815 1.1 uch struct hd64461video_chip *hvc = sc->sc_vc;
816 1.1 uch struct wsdisplay_font *font = (struct wsdisplay_font *)&sc->sc_font;
817 1.1 uch u_int8_t *q;
818 1.1 uch int w, h, step, i, n;
819 1.1 uch
820 1.1 uch if (sc->sc_font.loaded) {
821 1.1 uch printf("reload font\n");
822 1.1 uch }
823 1.1 uch
824 1.1 uch w = font->fontwidth;
825 1.1 uch h = font->fontheight;
826 1.1 uch step = sc->sc_font.cw * sc->sc_font.c;
827 1.1 uch n = (w * h) / NBBY;
828 1.1 uch q = font->data;
829 1.1 uch
830 1.1 uch DPRINTF("%s (%dx%d) %d+%d\n", font->name, w, h, font->firstchar,
831 1.1 uch font->numchars);
832 1.1 uch DPRINTF("bitorder %d byteorder %d stride %d\n", font->bitorder,
833 1.1 uch font->byteorder, font->stride);
834 1.1 uch
835 1.1 uch switch (hvc->vc.vc_fbdepth) {
836 1.1 uch case 8:
837 1.1 uch for (i = font->firstchar; i < font->numchars; i++) {
838 1.1 uch font_load_8bpp((u_int8_t *)font_start_addr(sc, i),
839 1.1 uch q, w, h, step);
840 1.1 uch q += n;
841 1.1 uch }
842 1.1 uch break;
843 1.1 uch case 16:
844 1.1 uch for (i = font->firstchar; i < font->numchars; i++) {
845 1.1 uch font_load_16bpp((u_int16_t *)font_start_addr(sc, i),
846 1.1 uch q, w, h, step);
847 1.1 uch q += n;
848 1.1 uch }
849 1.1 uch break;
850 1.1 uch }
851 1.1 uch
852 1.1 uch sc->sc_font.loaded = TRUE;
853 1.1 uch }
854 1.1 uch
855 1.1 uch static void
856 1.1 uch update_videochip_status(struct hd64461video_chip *hvc)
857 1.1 uch {
858 1.1 uch struct video_chip *vc = &hvc->vc;
859 1.1 uch u_int16_t r;
860 1.1 uch int i;
861 1.1 uch int depth, width, height;
862 1.1 uch
863 1.1 uch /* display mode */
864 1.1 uch r = hd64461_reg_read_2(HD64461_LCDLDR3_REG16);
865 1.1 uch i = HD64461_LCDLDR3_CG(r);
866 1.1 uch switch (i) {
867 1.1 uch case HD64461_LCDLDR3_CG_COLOR16:
868 1.1 uch depth = 16;
869 1.1 uch hvc->mode = LCD64K_C;
870 1.1 uch break;
871 1.1 uch case HD64461_LCDLDR3_CG_COLOR8:
872 1.1 uch depth = 8;
873 1.1 uch hvc->mode = LCD256_C;
874 1.1 uch break;
875 1.1 uch case HD64461_LCDLDR3_CG_GRAY6:
876 1.1 uch depth = 6;
877 1.1 uch hvc->mode = LCD64_MONO;
878 1.1 uch break;
879 1.1 uch case HD64461_LCDLDR3_CG_GRAY4:
880 1.1 uch depth = 4;
881 1.1 uch hvc->mode = LCD16_MONO;
882 1.1 uch break;
883 1.1 uch case HD64461_LCDLDR3_CG_GRAY2:
884 1.1 uch depth = 2;
885 1.1 uch hvc->mode = LCD4_MONO;
886 1.1 uch break;
887 1.1 uch case HD64461_LCDLDR3_CG_GRAY1:
888 1.1 uch depth = 1;
889 1.1 uch hvc->mode = LCD2_MONO;
890 1.1 uch break;
891 1.1 uch }
892 1.1 uch
893 1.1 uch r = hd64461_reg_read_2(HD64461_LCDCCR_REG16);
894 1.1 uch i = HD64461_LCDCCR_DSPSEL(i);
895 1.1 uch switch (i) {
896 1.1 uch case HD64461_LCDCCR_DSPSEL_LCD_CRT:
897 1.1 uch depth = 8;
898 1.1 uch hvc->mode = LCDCRT;
899 1.1 uch break;
900 1.1 uch case HD64461_LCDCCR_DSPSEL_CRT:
901 1.1 uch depth = 8;
902 1.1 uch hvc->mode = CRT256_C;
903 1.1 uch break;
904 1.1 uch case HD64461_LCDCCR_DSPSEL_LCD:
905 1.1 uch /* nothing to do */
906 1.1 uch break;
907 1.1 uch }
908 1.1 uch
909 1.1 uch width = bootinfo->fb_width;
910 1.1 uch height = bootinfo->fb_height;
911 1.1 uch
912 1.1 uch vc->vc_fbvaddr = HD64461_FBBASE;
913 1.1 uch vc->vc_fbpaddr = HD64461_FBBASE;
914 1.1 uch vc->vc_fbdepth = depth;
915 1.1 uch vc->vc_fbsize = (width * height * depth) / NBBY;
916 1.1 uch vc->vc_fbwidth = width;
917 1.1 uch vc->vc_fbheight = height;
918 1.1 uch }
919 1.1 uch
920 1.1 uch static void
921 1.1 uch set_display_mode(struct hd64461video_chip *hvc)
922 1.1 uch {
923 1.1 uch
924 1.1 uch if (hvc->mode == LCDCRT || hvc->mode == CRT256_C)
925 1.1 uch set_display_mode_crtc(hvc);
926 1.1 uch
927 1.1 uch set_display_mode_lcdc(hvc);
928 1.1 uch }
929 1.1 uch
930 1.1 uch static void
931 1.1 uch set_display_mode_lcdc(struct hd64461video_chip *hvc)
932 1.1 uch {
933 1.1 uch static struct {
934 1.1 uch u_int16_t clor; /* display size 640 x 240 */
935 1.1 uch u_int16_t ldr3;
936 1.1 uch const char *name;
937 1.1 uch } disp_conf[] = {
938 1.1 uch [LCD256_C] = { 0x280 , HD64461_LCDLDR3_CG_COLOR8 ,
939 1.1 uch "8bit color" },
940 1.1 uch [LCD64K_C] = { 0x500 , HD64461_LCDLDR3_CG_COLOR16 ,
941 1.1 uch "16bit color" },
942 1.1 uch [LCD64_MONO] = { 0x280 , HD64461_LCDLDR3_CG_GRAY6 ,
943 1.1 uch "6bit gray scale" },
944 1.1 uch [LCD16_MONO] = { 0x140 , HD64461_LCDLDR3_CG_GRAY4 ,
945 1.1 uch "4bit gray scale" },
946 1.1 uch [LCD4_MONO] = { 0x0a0 , HD64461_LCDLDR3_CG_GRAY2 ,
947 1.1 uch "2bit gray scale" },
948 1.1 uch [LCD2_MONO] = { 0x050 , HD64461_LCDLDR3_CG_GRAY1 ,
949 1.1 uch "mono chrome" },
950 1.1 uch }, *conf;
951 1.1 uch u_int16_t r;
952 1.1 uch int omode;
953 1.1 uch
954 1.1 uch conf = &disp_conf[hvc->mode];
955 1.1 uch
956 1.1 uch hd64461_reg_write_2(HD64461_LCDCLOR_REG16, conf->clor);
957 1.1 uch r = hd64461_reg_read_2(HD64461_LCDLDR3_REG16);
958 1.1 uch omode = HD64461_LCDLDR3_CG(r);
959 1.1 uch r = HD64461_LCDLDR3_CG_CLR(r);
960 1.1 uch r = HD64461_LCDLDR3_CG_SET(r, conf->ldr3);
961 1.1 uch hd64461_reg_write_2(HD64461_LCDLDR3_REG16, r);
962 1.1 uch
963 1.1 uch printf("%s ", conf->name);
964 1.1 uch }
965 1.1 uch
966 1.1 uch static void
967 1.1 uch set_display_mode_crtc(struct hd64461video_chip *hvc)
968 1.1 uch {
969 1.1 uch /* not yet */
970 1.1 uch }
971 1.1 uch
972 1.1 uch static size_t
973 1.1 uch frame_buffer_size(struct hd64461video_chip *hvc)
974 1.1 uch {
975 1.1 uch vaddr_t page, startaddr, endaddr;
976 1.1 uch int x;
977 1.1 uch
978 1.1 uch startaddr = HD64461_FBBASE;
979 1.1 uch endaddr = startaddr + HD64461_FBSIZE - 1;
980 1.1 uch
981 1.1 uch page = startaddr;
982 1.1 uch
983 1.1 uch x = random();
984 1.1 uch *(volatile int *)(page + 0) = x;
985 1.1 uch *(volatile int *)(page + 4) = ~x;
986 1.1 uch
987 1.1 uch if (*(volatile int *)(page + 0) != x ||
988 1.1 uch *(volatile int *)(page + 4) != ~x)
989 1.1 uch return (0);
990 1.1 uch
991 1.1 uch for (page += HD64461_FBPAGESIZE; page < endaddr;
992 1.1 uch page += HD64461_FBPAGESIZE) {
993 1.1 uch if (*(volatile int *)(page + 0) == x &&
994 1.1 uch *(volatile int *)(page + 4) == ~x)
995 1.1 uch goto fbend_found;
996 1.1 uch }
997 1.1 uch
998 1.1 uch page -= HD64461_FBPAGESIZE;
999 1.1 uch *(volatile int *)(page + 0) = x;
1000 1.1 uch *(volatile int *)(page + 4) = ~x;
1001 1.1 uch
1002 1.1 uch if (*(volatile int *)(page + 0) != x ||
1003 1.1 uch *(volatile int *)(page + 4) != ~x)
1004 1.1 uch return (0);
1005 1.1 uch
1006 1.1 uch fbend_found:
1007 1.1 uch return (page - startaddr);
1008 1.1 uch }
1009 1.1 uch
1010 1.1 uch static void
1011 1.1 uch set_clut(struct hd64461video_chip *vc, int idx, int cnt,
1012 1.1 uch u_int8_t *r, u_int8_t *g, u_int8_t *b)
1013 1.1 uch {
1014 1.1 uch KASSERT(r && g && b);
1015 1.1 uch
1016 1.1 uch /* index pallete */
1017 1.1 uch hd64461_reg_write_2(HD64461_LCDCPTWAR_REG16,
1018 1.1 uch HD64461_LCDCPTWAR_SET(0, idx));
1019 1.1 uch /* set data */
1020 1.1 uch while (cnt && LEGAL_CLUT_INDEX(idx)) {
1021 1.1 uch u_int16_t v;
1022 1.1 uch #define SET_CLUT(x) \
1023 1.1 uch v = (x >> 2) & 0x3f; \
1024 1.1 uch hd64461_reg_write_2(HD64461_LCDCPTWDR_REG16, v)
1025 1.1 uch SET_CLUT(*r);
1026 1.1 uch SET_CLUT(*g);
1027 1.1 uch SET_CLUT(*b);
1028 1.1 uch #undef SET_CLUT
1029 1.1 uch r++, g++, b++;
1030 1.1 uch idx++, cnt--;
1031 1.1 uch }
1032 1.1 uch }
1033 1.1 uch
1034 1.1 uch static void
1035 1.1 uch get_clut(struct hd64461video_chip *vc, int idx, int cnt,
1036 1.1 uch u_int8_t *r, u_int8_t *g, u_int8_t *b)
1037 1.1 uch {
1038 1.1 uch KASSERT(r && g && b);
1039 1.1 uch
1040 1.1 uch /* index pallete */
1041 1.1 uch hd64461_reg_write_2(HD64461_LCDCPTRAR_REG16,
1042 1.1 uch HD64461_LCDCPTRAR_SET(0, idx));
1043 1.1 uch
1044 1.1 uch /* get data */
1045 1.1 uch while (cnt && LEGAL_CLUT_INDEX(idx)) {
1046 1.1 uch u_int16_t v;
1047 1.1 uch #define GET_CLUT(x) \
1048 1.1 uch v = hd64461_reg_read_2(HD64461_LCDCPTWDR_REG16); \
1049 1.1 uch x = HD64461_LCDCPTRDR(v); \
1050 1.1 uch x <<= 2
1051 1.1 uch GET_CLUT(*r);
1052 1.1 uch GET_CLUT(*g);
1053 1.1 uch GET_CLUT(*b);
1054 1.1 uch #undef GET_CLUT
1055 1.1 uch r++, g++, b++;
1056 1.1 uch idx++, cnt--;
1057 1.1 uch }
1058 1.1 uch }
1059 1.1 uch
1060 1.1 uch #ifdef HD64461VIDEO_DEBUG
1061 1.1 uch static void
1062 1.1 uch _info(struct hd64461video_softc *sc)
1063 1.1 uch {
1064 1.1 uch const char name[] = __FUNCTION__;
1065 1.1 uch u_int16_t r;
1066 1.1 uch int color;
1067 1.1 uch int i;
1068 1.1 uch
1069 1.1 uch dbg_banner_start(name, sizeof name);
1070 1.1 uch printf("---[LCD]---\n");
1071 1.1 uch /* Base Address Register */
1072 1.1 uch r = hd64461_reg_read_2(HD64461_LCDCBAR_REG16);
1073 1.1 uch printf("LCDCBAR Frame buffer base address (4k Byte align): 0x%08x\n",
1074 1.1 uch HD64461_LCDCBAR_BASEADDR(r));
1075 1.1 uch
1076 1.1 uch /* Line Address Offset Register */
1077 1.1 uch r = hd64461_reg_read_2(HD64461_LCDCLOR_REG16);
1078 1.1 uch printf("LCDCLOR Line address offset: %d\n", HD64461_LCDCLOR(r));
1079 1.1 uch
1080 1.1 uch /* LCDC Control Register */
1081 1.1 uch r = hd64461_reg_read_2(HD64461_LCDCCR_REG16);
1082 1.1 uch i = HD64461_LCDCCR_DSPSEL(r);
1083 1.1 uch #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_LCDCCR_##m, #m)
1084 1.1 uch printf("LCDCCR (LCD Control Register)\n");
1085 1.1 uch DBG_BIT_PRINT(r, STBAK);
1086 1.1 uch DBG_BIT_PRINT(r, STREQ);
1087 1.1 uch DBG_BIT_PRINT(r, MOFF);
1088 1.1 uch DBG_BIT_PRINT(r, REFSEL);
1089 1.1 uch DBG_BIT_PRINT(r, EPON);
1090 1.1 uch DBG_BIT_PRINT(r, SPON);
1091 1.1 uch printf("\n");
1092 1.1 uch #undef DBG_BIT_PRINT
1093 1.1 uch printf("LCDCCR Display selct LCD[%c] CRT[%c]\n",
1094 1.1 uch i == HD64461_LCDCCR_DSPSEL_LCD_CRT ||
1095 1.1 uch i == HD64461_LCDCCR_DSPSEL_LCD ? 'x' : '_',
1096 1.1 uch i == HD64461_LCDCCR_DSPSEL_LCD_CRT ||
1097 1.1 uch i == HD64461_LCDCCR_DSPSEL_CRT ? 'x' : '_');
1098 1.1 uch
1099 1.1 uch /* LCD Display Register */
1100 1.1 uch /* 1 */
1101 1.1 uch r = hd64461_reg_read_2(HD64461_LCDLDR1_REG16);
1102 1.1 uch printf("(LCD Display Register)\n");
1103 1.1 uch #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_LCDLDR1_##m, #m)
1104 1.1 uch printf("LCDLDR1: ");
1105 1.1 uch DBG_BIT_PRINT(r, DINV);
1106 1.1 uch DBG_BIT_PRINT(r, DON);
1107 1.1 uch printf("\n");
1108 1.1 uch #undef DBG_BIT_PRINT
1109 1.1 uch /* 2 */
1110 1.1 uch r = hd64461_reg_read_2(HD64461_LCDLDR2_REG16);
1111 1.1 uch i = HD64461_LCDLDR2_LM(r);
1112 1.1 uch #define DBG_BIT_PRINT(r, m) dbg_bit_print(r, HD64461_LCDLDR2_##m, #m)
1113 1.1 uch printf("LCDLDR2: ");
1114 1.1 uch DBG_BIT_PRINT(r, CC1);
1115 1.1 uch DBG_BIT_PRINT(r, CC2);
1116 1.1 uch #undef DBG_BIT_PRINT
1117 1.1 uch color = 0;
1118 1.1 uch switch (i) {
1119 1.1 uch default:
1120 1.1 uch panic("unknown unknown LCD interface.");
1121 1.1 uch break;
1122 1.1 uch case HD64461_LCDLDR2_LM_COLOR:
1123 1.1 uch color = 1;
1124 1.1 uch printf("Color");
1125 1.1 uch break;
1126 1.1 uch case HD64461_LCDLDR2_LM_GRAY8:
1127 1.1 uch printf("8-bit grayscale");
1128 1.1 uch break;
1129 1.1 uch case HD64461_LCDLDR2_LM_GRAY4:
1130 1.1 uch printf("8-bit grayscale");
1131 1.1 uch break;
1132 1.1 uch }
1133 1.1 uch printf(" LCD interface\n");
1134 1.1 uch /* 3 */
1135 1.1 uch printf("LCDLDR3: ");
1136 1.1 uch r = hd64461_reg_read_2(HD64461_LCDLDR3_REG16);
1137 1.1 uch i = HD64461_LCDLDR3_CS(r);
1138 1.1 uch printf("CS ");
1139 1.1 uch switch (i) {
1140 1.1 uch case 0:
1141 1.1 uch printf("15");
1142 1.1 uch break;
1143 1.1 uch case 1:
1144 1.1 uch printf("2.5");
1145 1.1 uch break;
1146 1.1 uch case 2:
1147 1.1 uch printf("3.75");
1148 1.1 uch break;
1149 1.1 uch case 4:
1150 1.1 uch printf("5");
1151 1.1 uch break;
1152 1.1 uch case 8:
1153 1.1 uch printf("7.5");
1154 1.1 uch break;
1155 1.1 uch case 16:
1156 1.1 uch printf("10");
1157 1.1 uch break;
1158 1.1 uch }
1159 1.1 uch printf("%s MHz ", color ? "" : "/2");
1160 1.1 uch i = HD64461_LCDLDR3_CG(r);
1161 1.1 uch switch (i) {
1162 1.1 uch case HD64461_LCDLDR3_CG_COLOR16:
1163 1.1 uch printf("Color 64K colors\n");
1164 1.1 uch break;
1165 1.1 uch case HD64461_LCDLDR3_CG_COLOR8:
1166 1.1 uch printf("Color 256 colors\n");
1167 1.1 uch break;
1168 1.1 uch case HD64461_LCDLDR3_CG_GRAY6:
1169 1.1 uch printf("6-bit Grayscale\n");
1170 1.1 uch break;
1171 1.1 uch case HD64461_LCDLDR3_CG_GRAY4:
1172 1.1 uch printf("4-bit Grayscale\n");
1173 1.1 uch break;
1174 1.1 uch case HD64461_LCDLDR3_CG_GRAY2:
1175 1.1 uch printf("2-bit Grayscale\n");
1176 1.1 uch break;
1177 1.1 uch case HD64461_LCDLDR3_CG_GRAY1:
1178 1.1 uch printf("1-bit Grayscale\n");
1179 1.1 uch break;
1180 1.1 uch }
1181 1.1 uch
1182 1.1 uch /* LCD Number of Characters in Horizontal Register */
1183 1.1 uch r = hd64461_reg_read_2(HD64461_LCDLDHNCR_REG16);
1184 1.1 uch printf("LDHNCR: NHD %d NHT %d (# of horizontal characters)\n",
1185 1.1 uch HD64461_LCDLDHNCR_NHD(r), HD64461_LCDLDHNCR_NHT(r));
1186 1.1 uch
1187 1.1 uch /* Start Position of Horizontal Register */
1188 1.1 uch r = hd64461_reg_read_2(HD64461_LCDLDHNSR_REG16);
1189 1.1 uch printf("LDHNSR: HSW %d HSP %d (start position of horizontal)\n",
1190 1.1 uch HD64461_LCDLDHNSR_HSW(r), HD64461_LCDLDHNSR_HSP(r));
1191 1.1 uch
1192 1.1 uch /* Total Vertical Lines Register */
1193 1.1 uch r = hd64461_reg_read_2(HD64461_LCDLDVNTR_REG16);
1194 1.1 uch printf("LDVNTR: %d (total vertical lines)\n",
1195 1.1 uch HD64461_LCDLDVNTR_VTL(r));
1196 1.1 uch
1197 1.1 uch /* Display Vertical Lines Register */
1198 1.1 uch r = hd64461_reg_read_2(HD64461_LCDLDVNDR_REG16);
1199 1.1 uch printf("LDVNDR: %d (display vertical lines)\n",
1200 1.1 uch HD64461_LCDLDVSPR_VSP(r));
1201 1.1 uch
1202 1.1 uch /* Vertical Synchronization Position Register */
1203 1.1 uch r = hd64461_reg_read_2(HD64461_LCDLDVSPR_REG16);
1204 1.1 uch printf("LDVSPR: %d (vertical synchronization position)\n",
1205 1.1 uch HD64461_LCDLDVSPR_VSP(r));
1206 1.1 uch
1207 1.1 uch /*
1208 1.1 uch * CRT Control Register
1209 1.1 uch */
1210 1.1 uch printf("---[CRT]---\n");
1211 1.1 uch r = hd64461_reg_read_2(HD64461_LCDCRTVTR_REG16);
1212 1.1 uch printf("CRTVTR: %d (CRTC total vertical lines)\n",
1213 1.1 uch HD64461_LCDCRTVTR(r));
1214 1.1 uch r = hd64461_reg_read_2(HD64461_LCDCRTVRSR_REG16);
1215 1.1 uch printf("CRTVRSR: %d (CRTC vertical retrace start line)\n",
1216 1.1 uch HD64461_LCDCRTVRSR(r));
1217 1.1 uch r = hd64461_reg_read_2(HD64461_LCDCRTVRER_REG16);
1218 1.1 uch printf("CRTVRER: %d (CRTC vertical retrace end line)\n",
1219 1.1 uch HD64461_LCDCRTVRER(r));
1220 1.1 uch
1221 1.1 uch dbg_banner_end();
1222 1.1 uch }
1223 1.1 uch
1224 1.1 uch static void
1225 1.1 uch _dump()
1226 1.1 uch {
1227 1.1 uch u_int16_t r;
1228 1.1 uch printf("---Display Mode Setting---\n");
1229 1.1 uch #define DUMPREG(x) \
1230 1.1 uch r = hd64461_reg_read_2(HD64461_LCD ## x ## _REG16); \
1231 1.1 uch printf("%-10s 0x%04x ", #x, r); \
1232 1.1 uch bitdisp(r)
1233 1.1 uch DUMPREG(CBAR);
1234 1.1 uch DUMPREG(CLOR);
1235 1.1 uch DUMPREG(CCR);
1236 1.1 uch DUMPREG(LDR1);
1237 1.1 uch DUMPREG(LDR2);
1238 1.1 uch DUMPREG(LDHNCR);
1239 1.1 uch DUMPREG(LDHNSR);
1240 1.1 uch DUMPREG(LDVNTR);
1241 1.1 uch DUMPREG(LDVNDR);
1242 1.1 uch DUMPREG(LDVSPR);
1243 1.1 uch DUMPREG(LDR3);
1244 1.1 uch DUMPREG(CRTVTR);
1245 1.1 uch DUMPREG(CRTVRSR);
1246 1.1 uch DUMPREG(CRTVRER);
1247 1.1 uch #undef DUMPREG
1248 1.1 uch }
1249 1.1 uch
1250 1.1 uch #endif /* HD64461VIDEO_DEBUG */
1251