1 /*
2 * Copyright (c) 2012 Oleksandr Tymoshenko <gonzo@freebsd.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD: releng/10.0/sys/arm/versatile/versatile_clcd.c 245071 2013-01-05 21:05:16Z gonzo $");
29
30 #include <sys/param.h>
31 #include <sys/systm.h>
32 #include <sys/bus.h>
33 #include <sys/kernel.h>
34 #include <sys/module.h>
35 #include <sys/malloc.h>
36 #include <sys/rman.h>
37 #include <sys/fbio.h>
38 #include <sys/consio.h>
39 #include <sys/kdb.h>
40
41 #include <machine/bus.h>
42 #include <machine/cpu.h>
43 #include <machine/frame.h>
44 #include <machine/intr.h>
45
46 #include <dev/fdt/fdt_common.h>
47 #include <dev/ofw/openfirm.h>
48 #include <dev/ofw/ofw_bus.h>
49 #include <dev/ofw/ofw_bus_subr.h>
50
51 #include <dev/fb/fbreg.h>
52 #include <dev/syscons/syscons.h>
53
54 #include <machine/bus.h>
55 #include <machine/fdt.h>
56
57 #define PL110_VENDOR_ARM926PXP 1
58
59 #define MEM_SYS 0
60 #define MEM_CLCD 1
61 #define MEM_REGIONS 2
62
63 #define SYS_CLCD 0x00
64 #define SYS_CLCD_CLCDID_SHIFT 0x08
65 #define SYS_CLCD_CLCDID_MASK 0x1f
66 #define SYS_CLCD_PWR3V5VSWITCH (1 << 4)
67 #define SYS_CLCD_VDDPOSSWITCH (1 << 3)
68 #define SYS_CLCD_NLCDIOON (1 << 2)
69 #define SYS_CLCD_LCD_MODE_MASK 0x03
70
71 #define CLCD_MODE_RGB888 0x0
72 #define CLCD_MODE_RGB555 0x01
73 #define CLCD_MODE_RBG565 0x02
74 #define CLCD_MODE_RGB565 0x03
75
76 #define CLCDC_TIMING0 0x00
77 #define CLCDC_TIMING1 0x04
78 #define CLCDC_TIMING2 0x08
79 #define CLCDC_TIMING3 0x0C
80 #define CLCDC_TIMING3 0x0C
81 #define CLCDC_UPBASE 0x10
82 #define CLCDC_LPBASE 0x14
83 #ifdef PL110_VENDOR_ARM926PXP
84 #define CLCDC_CONTROL 0x18
85 #define CLCDC_IMSC 0x1C
86 #else
87 #define CLCDC_IMSC 0x18
88 #define CLCDC_CONTROL 0x1C
89 #endif
90 #define CONTROL_WATERMARK (1 << 16)
91 #define CONTROL_VCOMP_VS (0 << 12)
92 #define CONTROL_VCOMP_BP (1 << 12)
93 #define CONTROL_VCOMP_SAV (2 << 12)
94 #define CONTROL_VCOMP_FP (3 << 12)
95 #define CONTROL_PWR (1 << 11)
96 #define CONTROL_BEPO (1 << 10)
97 #define CONTROL_BEBO (1 << 9)
98 #define CONTROL_BGR (1 << 8)
99 #define CONTROL_DUAL (1 << 7)
100 #define CONTROL_MONO8 (1 << 6)
101 #define CONTROL_TFT (1 << 5)
102 #define CONTROL_BW (1 << 4)
103 #define CONTROL_BPP1 (0x00 << 1)
104 #define CONTROL_BPP2 (0x01 << 1)
105 #define CONTROL_BPP4 (0x02 << 1)
106 #define CONTROL_BPP8 (0x03 << 1)
107 #define CONTROL_BPP16 (0x04 << 1)
108 #define CONTROL_BPP24 (0x05 << 1)
109 #define CONTROL_EN (1 << 0)
110 #define CLCDC_RIS 0x20
111 #define CLCDC_MIS 0x24
112 #define INTR_MBERR (1 << 4)
113 #define INTR_VCOMP (1 << 3)
114 #define INTR_LNB (1 << 2)
115 #define INTR_FUF (1 << 1)
116 #define CLCDC_ICR 0x28
117
118 #ifdef DEBUG
119 #define dprintf(fmt, args...) do { printf("%s(): ", __func__); \
120 printf(fmt,##args); } while (0)
121 #else
122 #define dprintf(fmt, args...)
123 #endif
124
125 #define versatile_clcdc_sys_read_4(sc, reg) \
126 bus_read_4((sc)->mem_res[MEM_SYS], (reg))
127 #define versatile_clcdc_sys_write_4(sc, reg, val) \
128 bus_write_4((sc)->mem_res[MEM_SYS], (reg), (val))
129
130 #define versatile_clcdc_read_4(sc, reg) \
131 bus_read_4((sc)->mem_res[MEM_CLCD], (reg))
132 #define versatile_clcdc_write_4(sc, reg, val) \
133 bus_write_4((sc)->mem_res[MEM_CLCD], (reg), (val))
134
135 struct versatile_clcdc_softc {
136 struct resource* mem_res[MEM_REGIONS];
137
138 struct mtx mtx;
139
140 int width;
141 int height;
142 int mode;
143
144 bus_dma_tag_t dma_tag;
145 bus_dmamap_t dma_map;
146 bus_addr_t fb_phys;
147 uint8_t *fb_base;
148
149 };
150
151 struct video_adapter_softc {
152 /* Videoadpater part */
153 video_adapter_t va;
154 int console;
155
156 intptr_t fb_addr;
157 unsigned int fb_size;
158
159 unsigned int height;
160 unsigned int width;
161 unsigned int depth;
162 unsigned int stride;
163
164 unsigned int xmargin;
165 unsigned int ymargin;
166
167 unsigned char *font;
168 int initialized;
169 };
170
171 struct argb {
172 uint8_t a;
173 uint8_t r;
174 uint8_t g;
175 uint8_t b;
176 };
177
178 static struct argb versatilefb_palette[16] = {
179 {0x00, 0x00, 0x00, 0x00},
180 {0x00, 0x00, 0x00, 0xaa},
181 {0x00, 0x00, 0xaa, 0x00},
182 {0x00, 0x00, 0xaa, 0xaa},
183 {0x00, 0xaa, 0x00, 0x00},
184 {0x00, 0xaa, 0x00, 0xaa},
185 {0x00, 0xaa, 0x55, 0x00},
186 {0x00, 0xaa, 0xaa, 0xaa},
187 {0x00, 0x55, 0x55, 0x55},
188 {0x00, 0x55, 0x55, 0xff},
189 {0x00, 0x55, 0xff, 0x55},
190 {0x00, 0x55, 0xff, 0xff},
191 {0x00, 0xff, 0x55, 0x55},
192 {0x00, 0xff, 0x55, 0xff},
193 {0x00, 0xff, 0xff, 0x55},
194 {0x00, 0xff, 0xff, 0xff}
195 };
196
197 /* mouse pointer from dev/syscons/scgfbrndr.c */
198 static u_char mouse_pointer[16] = {
199 0x00, 0x40, 0x60, 0x70, 0x78, 0x7c, 0x7e, 0x68,
200 0x0c, 0x0c, 0x06, 0x06, 0x00, 0x00, 0x00, 0x00
201 };
202
203 #define FB_WIDTH 640
204 #define FB_HEIGHT 480
205 #define FB_DEPTH 16
206
207 #define VERSATILE_FONT_HEIGHT 16
208
209 static struct video_adapter_softc va_softc;
210
211 static struct resource_spec versatile_clcdc_mem_spec[] = {
212 { SYS_RES_MEMORY, 0, RF_ACTIVE },
213 { SYS_RES_MEMORY, 1, RF_ACTIVE },
214 { -1, 0, 0 }
215 };
216
217 static int versatilefb_configure(int);
218 static void versatilefb_update_margins(video_adapter_t *adp);
219
220 static void
221 versatile_fb_dmamap_cb(void *arg, bus_dma_segment_t *segs, int nseg, int err)
222 {
223 bus_addr_t *addr;
224
225 if (err)
226 return;
227
228 addr = (bus_addr_t*)arg;
229 *addr = segs[0].ds_addr;
230 }
231
232 static int
233 versatile_clcdc_probe(device_t dev)
234 {
235
236 if (ofw_bus_is_compatible(dev, "arm,pl110")) {
237 device_set_desc(dev, "PL110 CLCD controller");
238 return (BUS_PROBE_DEFAULT);
239 }
240
241 return (ENXIO);
242 }
243
244 static int
245 versatile_clcdc_attach(device_t dev)
246 {
247 struct versatile_clcdc_softc *sc = device_get_softc(dev);
248 struct video_adapter_softc *va_sc = &va_softc;
249 int err;
250 uint32_t reg;
251 int clcdid;
252 int dma_size;
253
254 /* Request memory resources */
255 err = bus_alloc_resources(dev, versatile_clcdc_mem_spec,
256 sc->mem_res);
257 if (err) {
258 device_printf(dev, "Error: could not allocate memory resources\n");
259 return (ENXIO);
260 }
261
262 reg = versatile_clcdc_sys_read_4(sc, SYS_CLCD);
263 clcdid = (reg >> SYS_CLCD_CLCDID_SHIFT) & SYS_CLCD_CLCDID_MASK;
264 switch (clcdid) {
265 case 31:
266 device_printf(dev, "QEMU VGA 640x480\n");
267 sc->width = 640;
268 sc->height = 480;
269 break;
270 default:
271 device_printf(dev, "Unsupported: %d\n", clcdid);
272 goto fail;
273 }
274
275 reg &= ~SYS_CLCD_LCD_MODE_MASK;
276 reg |= CLCD_MODE_RGB565;
277 sc->mode = CLCD_MODE_RGB565;
278 versatile_clcdc_sys_write_4(sc, SYS_CLCD, reg);
279 dma_size = sc->width*sc->height*2;
280
281 /*
282 * Power on LCD
283 */
284 reg |= SYS_CLCD_PWR3V5VSWITCH | SYS_CLCD_NLCDIOON;
285 versatile_clcdc_sys_write_4(sc, SYS_CLCD, reg);
286
287 /*
288 * XXX: hardcoded timing for VGA. For other modes/panels
289 * we need to keep table of timing register values
290 */
291 /*
292 * XXX: set SYS_OSC1
293 */
294 versatile_clcdc_write_4(sc, CLCDC_TIMING0, 0x3F1F3F9C);
295 versatile_clcdc_write_4(sc, CLCDC_TIMING1, 0x090B61DF);
296 versatile_clcdc_write_4(sc, CLCDC_TIMING2, 0x067F1800);
297 /* XXX: timing 3? */
298
299 /*
300 * Now allocate framebuffer memory
301 */
302 err = bus_dma_tag_create(
303 bus_get_dma_tag(dev),
304 4, 0, /* alignment, boundary */
305 BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
306 BUS_SPACE_MAXADDR, /* highaddr */
307 NULL, NULL, /* filter, filterarg */
308 dma_size, 1, /* maxsize, nsegments */
309 dma_size, 0, /* maxsegsize, flags */
310 NULL, NULL, /* lockfunc, lockarg */
311 &sc->dma_tag);
312
313 err = bus_dmamem_alloc(sc->dma_tag, (void **)&sc->fb_base,
314 0, &sc->dma_map);
315 if (err) {
316 device_printf(dev, "cannot allocate framebuffer\n");
317 goto fail;
318 }
319
320 err = bus_dmamap_load(sc->dma_tag, sc->dma_map, sc->fb_base,
321 dma_size, versatile_fb_dmamap_cb, &sc->fb_phys, BUS_DMA_NOWAIT);
322
323 if (err) {
324 device_printf(dev, "cannot load DMA map\n");
325 goto fail;
326 }
327
328 /* Make sure it's blank */
329 memset(sc->fb_base, 0x00, dma_size);
330
331 versatile_clcdc_write_4(sc, CLCDC_UPBASE, sc->fb_phys);
332
333 err = (sc_attach_unit(device_get_unit(dev),
334 device_get_flags(dev) | SC_AUTODETECT_KBD));
335
336 if (err) {
337 device_printf(dev, "failed to attach syscons\n");
338 goto fail;
339 }
340
341 /*
342 * XXX: hardcoded for VGA
343 */
344 reg = CONTROL_VCOMP_BP | CONTROL_TFT | CONTROL_BGR | CONTROL_EN;
345 reg |= CONTROL_BPP16;
346 versatile_clcdc_write_4(sc, CLCDC_CONTROL, reg);
347 DELAY(20);
348 reg |= CONTROL_PWR;
349 versatile_clcdc_write_4(sc, CLCDC_CONTROL, reg);
350
351 va_sc->fb_addr = (vm_offset_t)sc->fb_base;
352 va_sc->fb_size = dma_size;
353 va_sc->width = sc->width;
354 va_sc->height = sc->height;
355 va_sc->depth = 16;
356 va_sc->stride = sc->width * 2;
357 versatilefb_update_margins(&va_sc->va);
358
359 return (0);
360
361 fail:
362 if (sc->fb_base)
363 bus_dmamem_free(sc->dma_tag, sc->fb_base, sc->dma_map);
364 if (sc->dma_map)
365 bus_dmamap_destroy(sc->dma_tag, sc->dma_map);
366 if (sc->dma_tag)
367 bus_dma_tag_destroy(sc->dma_tag);
368 return (err);
369 }
370
371 static device_method_t versatile_clcdc_methods[] = {
372 DEVMETHOD(device_probe, versatile_clcdc_probe),
373 DEVMETHOD(device_attach, versatile_clcdc_attach),
374
375 DEVMETHOD_END
376 };
377
378 static driver_t versatile_clcdc_driver = {
379 "clcdc",
380 versatile_clcdc_methods,
381 sizeof(struct versatile_clcdc_softc),
382 };
383
384 static devclass_t versatile_clcdc_devclass;
385
386 DRIVER_MODULE(versatile_clcdc, simplebus, versatile_clcdc_driver, versatile_clcdc_devclass, 0, 0);
387
388 /*
389 * Video driver routines and glue.
390 */
391 static vi_probe_t versatilefb_probe;
392 static vi_init_t versatilefb_init;
393 static vi_get_info_t versatilefb_get_info;
394 static vi_query_mode_t versatilefb_query_mode;
395 static vi_set_mode_t versatilefb_set_mode;
396 static vi_save_font_t versatilefb_save_font;
397 static vi_load_font_t versatilefb_load_font;
398 static vi_show_font_t versatilefb_show_font;
399 static vi_save_palette_t versatilefb_save_palette;
400 static vi_load_palette_t versatilefb_load_palette;
401 static vi_set_border_t versatilefb_set_border;
402 static vi_save_state_t versatilefb_save_state;
403 static vi_load_state_t versatilefb_load_state;
404 static vi_set_win_org_t versatilefb_set_win_org;
405 static vi_read_hw_cursor_t versatilefb_read_hw_cursor;
406 static vi_set_hw_cursor_t versatilefb_set_hw_cursor;
407 static vi_set_hw_cursor_shape_t versatilefb_set_hw_cursor_shape;
408 static vi_blank_display_t versatilefb_blank_display;
409 static vi_mmap_t versatilefb_mmap;
410 static vi_ioctl_t versatilefb_ioctl;
411 static vi_clear_t versatilefb_clear;
412 static vi_fill_rect_t versatilefb_fill_rect;
413 static vi_bitblt_t versatilefb_bitblt;
414 static vi_diag_t versatilefb_diag;
415 static vi_save_cursor_palette_t versatilefb_save_cursor_palette;
416 static vi_load_cursor_palette_t versatilefb_load_cursor_palette;
417 static vi_copy_t versatilefb_copy;
418 static vi_putp_t versatilefb_putp;
419 static vi_putc_t versatilefb_putc;
420 static vi_puts_t versatilefb_puts;
421 static vi_putm_t versatilefb_putm;
422
423 static video_switch_t versatilefbvidsw = {
424 .probe = versatilefb_probe,
425 .init = versatilefb_init,
426 .get_info = versatilefb_get_info,
427 .query_mode = versatilefb_query_mode,
428 .set_mode = versatilefb_set_mode,
429 .save_font = versatilefb_save_font,
430 .load_font = versatilefb_load_font,
431 .show_font = versatilefb_show_font,
432 .save_palette = versatilefb_save_palette,
433 .load_palette = versatilefb_load_palette,
434 .set_border = versatilefb_set_border,
435 .save_state = versatilefb_save_state,
436 .load_state = versatilefb_load_state,
437 .set_win_org = versatilefb_set_win_org,
438 .read_hw_cursor = versatilefb_read_hw_cursor,
439 .set_hw_cursor = versatilefb_set_hw_cursor,
440 .set_hw_cursor_shape = versatilefb_set_hw_cursor_shape,
441 .blank_display = versatilefb_blank_display,
442 .mmap = versatilefb_mmap,
443 .ioctl = versatilefb_ioctl,
444 .clear = versatilefb_clear,
445 .fill_rect = versatilefb_fill_rect,
446 .bitblt = versatilefb_bitblt,
447 .diag = versatilefb_diag,
448 .save_cursor_palette = versatilefb_save_cursor_palette,
449 .load_cursor_palette = versatilefb_load_cursor_palette,
450 .copy = versatilefb_copy,
451 .putp = versatilefb_putp,
452 .putc = versatilefb_putc,
453 .puts = versatilefb_puts,
454 .putm = versatilefb_putm,
455 };
456
457 VIDEO_DRIVER(versatilefb, versatilefbvidsw, versatilefb_configure);
458
459 static vr_init_t clcdr_init;
460 static vr_clear_t clcdr_clear;
461 static vr_draw_border_t clcdr_draw_border;
462 static vr_draw_t clcdr_draw;
463 static vr_set_cursor_t clcdr_set_cursor;
464 static vr_draw_cursor_t clcdr_draw_cursor;
465 static vr_blink_cursor_t clcdr_blink_cursor;
466 static vr_set_mouse_t clcdr_set_mouse;
467 static vr_draw_mouse_t clcdr_draw_mouse;
468
469 /*
470 * We use our own renderer; this is because we must emulate a hardware
471 * cursor.
472 */
473 static sc_rndr_sw_t clcdrend = {
474 clcdr_init,
475 clcdr_clear,
476 clcdr_draw_border,
477 clcdr_draw,
478 clcdr_set_cursor,
479 clcdr_draw_cursor,
480 clcdr_blink_cursor,
481 clcdr_set_mouse,
482 clcdr_draw_mouse
483 };
484
485 RENDERER(versatilefb, 0, clcdrend, gfb_set);
486 RENDERER_MODULE(versatilefb, gfb_set);
487
488 static void
489 clcdr_init(scr_stat* scp)
490 {
491 }
492
493 static void
494 clcdr_clear(scr_stat* scp, int c, int attr)
495 {
496 }
497
498 static void
499 clcdr_draw_border(scr_stat* scp, int color)
500 {
501 }
502
503 static void
504 clcdr_draw(scr_stat* scp, int from, int count, int flip)
505 {
506 video_adapter_t* adp = scp->sc->adp;
507 int i, c, a;
508
509 if (!flip) {
510 /* Normal printing */
511 vidd_puts(adp, from, (uint16_t*)sc_vtb_pointer(&scp->vtb, from), count);
512 } else {
513 /* This is for selections and such: invert the color attribute */
514 for (i = count; i-- > 0; ++from) {
515 c = sc_vtb_getc(&scp->vtb, from);
516 a = sc_vtb_geta(&scp->vtb, from) >> 8;
517 vidd_putc(adp, from, c, (a >> 4) | ((a & 0xf) << 4));
518 }
519 }
520 }
521
522 static void
523 clcdr_set_cursor(scr_stat* scp, int base, int height, int blink)
524 {
525 }
526
527 static void
528 clcdr_draw_cursor(scr_stat* scp, int off, int blink, int on, int flip)
529 {
530 video_adapter_t* adp = scp->sc->adp;
531 struct video_adapter_softc *sc;
532 int row, col;
533 uint8_t *addr;
534 int i,j;
535
536 sc = (struct video_adapter_softc *)adp;
537
538 if (scp->curs_attr.height <= 0)
539 return;
540
541 if (sc->fb_addr == 0)
542 return;
543
544 if (off >= adp->va_info.vi_width * adp->va_info.vi_height)
545 return;
546
547 /* calculate the coordinates in the video buffer */
548 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
549 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
550
551 addr = (uint8_t *)sc->fb_addr
552 + (row + sc->ymargin)*(sc->stride)
553 + (sc->depth/8) * (col + sc->xmargin);
554
555 /* our cursor consists of simply inverting the char under it */
556 for (i = 0; i < adp->va_info.vi_cheight; i++) {
557 for (j = 0; j < adp->va_info.vi_cwidth; j++) {
558
559 addr[2*j] ^= 0xff;
560 addr[2*j + 1] ^= 0xff;
561 }
562
563 addr += sc->stride;
564 }
565 }
566
567 static void
568 clcdr_blink_cursor(scr_stat* scp, int at, int flip)
569 {
570 }
571
572 static void
573 clcdr_set_mouse(scr_stat* scp)
574 {
575 }
576
577 static void
578 clcdr_draw_mouse(scr_stat* scp, int x, int y, int on)
579 {
580 vidd_putm(scp->sc->adp, x, y, mouse_pointer, 0xffffffff, 16, 8);
581
582 }
583
584 static uint16_t versatilefb_static_window[ROW*COL];
585 extern u_char dflt_font_16[];
586
587 /*
588 * Update videoadapter settings after changing resolution
589 */
590 static void
591 versatilefb_update_margins(video_adapter_t *adp)
592 {
593 struct video_adapter_softc *sc;
594 video_info_t *vi;
595
596 sc = (struct video_adapter_softc *)adp;
597 vi = &adp->va_info;
598
599 sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
600 sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2;
601 }
602
603 static int
604 versatilefb_configure(int flags)
605 {
606 struct video_adapter_softc *va_sc;
607
608 va_sc = &va_softc;
609
610 if (va_sc->initialized)
611 return (0);
612
613 va_sc->width = FB_WIDTH;
614 va_sc->height = FB_HEIGHT;
615 va_sc->depth = FB_DEPTH;
616
617 versatilefb_init(0, &va_sc->va, 0);
618
619 va_sc->initialized = 1;
620
621 return (0);
622 }
623
624 static int
625 versatilefb_probe(int unit, video_adapter_t **adp, void *arg, int flags)
626 {
627
628 return (0);
629 }
630
631 static int
632 versatilefb_init(int unit, video_adapter_t *adp, int flags)
633 {
634 struct video_adapter_softc *sc;
635 video_info_t *vi;
636
637 sc = (struct video_adapter_softc *)adp;
638 vi = &adp->va_info;
639
640 vid_init_struct(adp, "versatilefb", -1, unit);
641
642 sc->font = dflt_font_16;
643 vi->vi_cheight = VERSATILE_FONT_HEIGHT;
644 vi->vi_cwidth = 8;
645
646 vi->vi_width = sc->width/8;
647 vi->vi_height = sc->height/vi->vi_cheight;
648
649 /*
650 * Clamp width/height to syscons maximums
651 */
652 if (vi->vi_width > COL)
653 vi->vi_width = COL;
654 if (vi->vi_height > ROW)
655 vi->vi_height = ROW;
656
657 sc->xmargin = (sc->width - (vi->vi_width * vi->vi_cwidth)) / 2;
658 sc->ymargin = (sc->height - (vi->vi_height * vi->vi_cheight))/2;
659
660
661 adp->va_window = (vm_offset_t) versatilefb_static_window;
662 adp->va_flags |= V_ADP_FONT /* | V_ADP_COLOR | V_ADP_MODECHANGE */;
663
664 vid_register(&sc->va);
665
666 return (0);
667 }
668
669 static int
670 versatilefb_get_info(video_adapter_t *adp, int mode, video_info_t *info)
671 {
672 bcopy(&adp->va_info, info, sizeof(*info));
673 return (0);
674 }
675
676 static int
677 versatilefb_query_mode(video_adapter_t *adp, video_info_t *info)
678 {
679 return (0);
680 }
681
682 static int
683 versatilefb_set_mode(video_adapter_t *adp, int mode)
684 {
685 return (0);
686 }
687
688 static int
689 versatilefb_save_font(video_adapter_t *adp, int page, int size, int width,
690 u_char *data, int c, int count)
691 {
692 return (0);
693 }
694
695 static int
696 versatilefb_load_font(video_adapter_t *adp, int page, int size, int width,
697 u_char *data, int c, int count)
698 {
699 struct video_adapter_softc *sc = (struct video_adapter_softc *)adp;
700
701 sc->font = data;
702
703 return (0);
704 }
705
706 static int
707 versatilefb_show_font(video_adapter_t *adp, int page)
708 {
709 return (0);
710 }
711
712 static int
713 versatilefb_save_palette(video_adapter_t *adp, u_char *palette)
714 {
715 return (0);
716 }
717
718 static int
719 versatilefb_load_palette(video_adapter_t *adp, u_char *palette)
720 {
721 return (0);
722 }
723
724 static int
725 versatilefb_set_border(video_adapter_t *adp, int border)
726 {
727 return (versatilefb_blank_display(adp, border));
728 }
729
730 static int
731 versatilefb_save_state(video_adapter_t *adp, void *p, size_t size)
732 {
733 return (0);
734 }
735
736 static int
737 versatilefb_load_state(video_adapter_t *adp, void *p)
738 {
739 return (0);
740 }
741
742 static int
743 versatilefb_set_win_org(video_adapter_t *adp, off_t offset)
744 {
745 return (0);
746 }
747
748 static int
749 versatilefb_read_hw_cursor(video_adapter_t *adp, int *col, int *row)
750 {
751 *col = *row = 0;
752
753 return (0);
754 }
755
756 static int
757 versatilefb_set_hw_cursor(video_adapter_t *adp, int col, int row)
758 {
759
760 return (0);
761 }
762
763 static int
764 versatilefb_set_hw_cursor_shape(video_adapter_t *adp, int base, int height,
765 int celsize, int blink)
766 {
767 return (0);
768 }
769
770 static int
771 versatilefb_blank_display(video_adapter_t *adp, int mode)
772 {
773
774 struct video_adapter_softc *sc;
775
776 sc = (struct video_adapter_softc *)adp;
777 if (sc && sc->fb_addr)
778 memset((void*)sc->fb_addr, 0, sc->fb_size);
779
780 return (0);
781 }
782
783 static int
784 versatilefb_mmap(video_adapter_t *adp, vm_ooffset_t offset, vm_paddr_t *paddr,
785 int prot, vm_memattr_t *memattr)
786 {
787 struct video_adapter_softc *sc;
788
789 sc = (struct video_adapter_softc *)adp;
790
791 /*
792 * This might be a legacy VGA mem request: if so, just point it at the
793 * framebuffer, since it shouldn't be touched
794 */
795 if (offset < sc->stride*sc->height) {
796 *paddr = sc->fb_addr + offset;
797 return (0);
798 }
799
800 return (EINVAL);
801 }
802
803 static int
804 versatilefb_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
805 {
806
807 return (0);
808 }
809
810 static int
811 versatilefb_clear(video_adapter_t *adp)
812 {
813
814 return (versatilefb_blank_display(adp, 0));
815 }
816
817 static int
818 versatilefb_fill_rect(video_adapter_t *adp, int val, int x, int y, int cx, int cy)
819 {
820
821 return (0);
822 }
823
824 static int
825 versatilefb_bitblt(video_adapter_t *adp, ...)
826 {
827
828 return (0);
829 }
830
831 static int
832 versatilefb_diag(video_adapter_t *adp, int level)
833 {
834
835 return (0);
836 }
837
838 static int
839 versatilefb_save_cursor_palette(video_adapter_t *adp, u_char *palette)
840 {
841
842 return (0);
843 }
844
845 static int
846 versatilefb_load_cursor_palette(video_adapter_t *adp, u_char *palette)
847 {
848
849 return (0);
850 }
851
852 static int
853 versatilefb_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst, int n)
854 {
855
856 return (0);
857 }
858
859 static int
860 versatilefb_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p, uint32_t a,
861 int size, int bpp, int bit_ltor, int byte_ltor)
862 {
863
864 return (0);
865 }
866
867 static int
868 versatilefb_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c, uint8_t a)
869 {
870 struct video_adapter_softc *sc;
871 int row;
872 int col;
873 int i, j, k;
874 uint8_t *addr;
875 u_char *p;
876 uint8_t fg, bg, color;
877 uint16_t rgb;
878
879 sc = (struct video_adapter_softc *)adp;
880
881 if (sc->fb_addr == 0)
882 return (0);
883
884 if (off >= adp->va_info.vi_width * adp->va_info.vi_height)
885 return (0);
886
887 row = (off / adp->va_info.vi_width) * adp->va_info.vi_cheight;
888 col = (off % adp->va_info.vi_width) * adp->va_info.vi_cwidth;
889 p = sc->font + c*VERSATILE_FONT_HEIGHT;
890 addr = (uint8_t *)sc->fb_addr
891 + (row + sc->ymargin)*(sc->stride)
892 + (sc->depth/8) * (col + sc->xmargin);
893
894 fg = a & 0xf ;
895 bg = (a >> 4) & 0xf;
896
897 for (i = 0; i < VERSATILE_FONT_HEIGHT; i++) {
898 for (j = 0, k = 7; j < 8; j++, k--) {
899 if ((p[i] & (1 << k)) == 0)
900 color = bg;
901 else
902 color = fg;
903
904 switch (sc->depth) {
905 case 16:
906 rgb = (versatilefb_palette[color].r >> 3) << 11;
907 rgb |= (versatilefb_palette[color].g >> 2) << 5;
908 rgb |= (versatilefb_palette[color].b >> 3);
909 addr[2*j] = rgb & 0xff;
910 addr[2*j + 1] = (rgb >> 8) & 0xff;
911 default:
912 /* Not supported yet */
913 break;
914 }
915 }
916
917 addr += (sc->stride);
918 }
919
920 return (0);
921 }
922
923 static int
924 versatilefb_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s, int len)
925 {
926 int i;
927
928 for (i = 0; i < len; i++)
929 versatilefb_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8);
930
931 return (0);
932 }
933
934 static int
935 versatilefb_putm(video_adapter_t *adp, int x, int y, uint8_t *pixel_image,
936 uint32_t pixel_mask, int size, int width)
937 {
938
939 return (0);
940 }
941
942 /*
943 * Define a stub keyboard driver in case one hasn't been
944 * compiled into the kernel
945 */
946 #include <sys/kbio.h>
947 #include <dev/kbd/kbdreg.h>
948
949 static int dummy_kbd_configure(int flags);
950
951 keyboard_switch_t bcmdummysw;
952
953 static int
954 dummy_kbd_configure(int flags)
955 {
956
957 return (0);
958 }
959 KEYBOARD_DRIVER(bcmdummy, bcmdummysw, dummy_kbd_configure);
Cache object: 4d85211b7432fcfb09beea6252f28980
|