2 * Copyright (c) 2012 Robert N. M. Watson
5 * This software was developed by SRI International and the University of
6 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
7 * ("CTSRD"), as part of the DARPA CRASH research programme.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include <sys/param.h>
37 #include <sys/consio.h>
40 #include <sys/kernel.h>
42 #include <sys/malloc.h>
43 #include <sys/mutex.h>
44 #include <sys/module.h>
46 #include <sys/systm.h>
49 #include <machine/bus.h>
50 #include <machine/resource.h>
51 #include <machine/vm.h>
53 #include <dev/fb/fbreg.h>
55 #include <dev/kbd/kbdreg.h>
57 #include <dev/syscons/syscons.h>
59 #include <dev/terasic/mtl/terasic_mtl.h>
62 * Terasic Multitouch LCD (MTL) syscons driver. Implement syscons(4)'s
63 * video_switch_t KPI using MTL's text frame buffer. In principle, we could
64 * actually implement sc_rndr_sw_t, since the MTL text frame buffer implements
65 * a VGA-like memory mapping. However, this requires a lot more book-keeping
66 * with only minor performance improvements (avoiding indirection), as well as
67 * introducing potential endianness issues. Instead we accept one additional
68 * memory copy between a software frame buffer and the hardware frame buffer
69 * and the generic frame buffer (gfb) framework.
72 MALLOC_DEFINE(M_TERASIC_MTL, "mtl_syscons", "MTL syscons frame buffer");
75 * Run early so that boot-time console support can be initialised before
76 * newbus gets around to configuring syscons.
78 * XXXRW: We may need to do more here in order to see earlier boot messages.
81 terasic_mtl_syscons_configure(int flags)
84 printf("%s: not yet\n", __func__);
89 terasic_mtl_vidsw_probe(int unit, video_adapter_t **adp, void *args,
93 printf("%s: not yet\n", __func__);
98 terasic_mtl_vidsw_init(int unit, video_adapter_t *adp, int flags)
100 struct terasic_mtl_softc *sc;
103 sc = (struct terasic_mtl_softc *)adp;
106 vid_init_struct(adp, "terasic_mtl_syscons", -1, unit);
108 vi->vi_width = TERASIC_MTL_COLS;
109 if (vi->vi_width > COL)
111 vi->vi_height = TERASIC_MTL_ROWS;
112 if (vi->vi_height > ROW)
116 * XXXRW: It's not quite clear how these should be initialised.
120 vi->vi_flags = V_INFO_COLOR;
121 vi->vi_mem_model = V_INFO_MM_OTHER;
124 * Software text frame buffer from which we update the actual MTL
125 * frame buffer when asked to.
127 adp->va_window = (vm_offset_t)sc->mtl_text_soft;
130 * Declare video adapter capabilities -- at this point, simply color
131 * support, as MTL doesn't support screen borders, font loading, or
134 * XXXRW: It's unclear if V_ADP_INITIALIZED is needed here; other
135 * syscons(4) drivers are inconsistent about this and
138 adp->va_flags |= V_ADP_COLOR | V_ADP_INITIALIZED;
139 if (vid_register(adp) < 0) {
140 device_printf(sc->mtl_dev, "%s: vid_register failed\n",
144 adp->va_flags |= V_ADP_REGISTERED;
149 terasic_mtl_vidsw_get_info(video_adapter_t *adp, int mode, video_info_t *info)
152 bcopy(&adp->va_info, info, sizeof(*info));
157 terasic_mtl_vidsw_query_mode(video_adapter_t *adp, video_info_t *info)
160 printf("%s: not yet\n", __func__);
165 terasic_mtl_vidsw_set_mode(video_adapter_t *adp, int mode)
168 printf("%s: not yet\n", __func__);
173 terasic_mtl_vidsw_save_font(video_adapter_t *adp, int page, int size,
174 int width, u_char *data, int c, int count)
177 printf("%s: not yet\n", __func__);
182 terasic_mtl_vidsw_load_font(video_adapter_t *adp, int page, int size,
183 int width, u_char *data, int c, int count)
186 printf("%s: not yet\n", __func__);
191 terasic_mtl_vidsw_show_font(video_adapter_t *adp, int page)
194 printf("%s: not yet\n", __func__);
199 terasic_mtl_vidsw_save_palette(video_adapter_t *adp, u_char *palette)
202 printf("%s: not yet\n", __func__);
207 terasic_mtl_vidsw_load_palette(video_adapter_t *adp, u_char *palette)
210 printf("%s: not yet\n", __func__);
215 terasic_mtl_vidsw_set_border(video_adapter_t *adp, int border)
218 printf("%s: not yet\n", __func__);
223 terasic_mtl_vidsw_save_state(video_adapter_t *adp, void *p, size_t size)
226 printf("%s: not yet\n", __func__);
231 terasic_mtl_vidsw_load_state(video_adapter_t *adp, void *p)
234 printf("%s: not yet\n", __func__);
239 terasic_mtl_vidsw_set_win_org(video_adapter_t *adp, off_t offset)
242 printf("%s: not yet\n", __func__);
247 terasic_mtl_vidsw_read_hw_cursor(video_adapter_t *adp, int *colp, int *rowp)
249 struct terasic_mtl_softc *sc;
252 sc = (struct terasic_mtl_softc *)adp;
253 terasic_mtl_reg_textcursor_get(sc, &col, &row);
260 terasic_mtl_vidsw_set_hw_cursor(video_adapter_t *adp, int col, int row)
262 struct terasic_mtl_softc *sc;
264 sc = (struct terasic_mtl_softc *)adp;
265 terasic_mtl_reg_textcursor_set(sc, col, row);
270 terasic_mtl_vidsw_set_hw_cursor_shape(video_adapter_t *adp, int base,
271 int height, int celsize, int blink)
274 printf("%s: not yet\n", __func__);
279 terasic_mtl_vidsw_blank_display(video_adapter_t *adp, int mode)
281 struct terasic_mtl_softc *sc;
283 sc = (struct terasic_mtl_softc *)adp;
284 terasic_mtl_reg_blank(sc);
289 terasic_mtl_vidsw_mmap(video_adapter_t *adp, vm_ooffset_t offset,
290 vm_paddr_t *paddr, int prot, vm_memattr_t *memattr)
293 printf("%s: not yet\n", __func__);
298 terasic_mtl_vidsw_ioctl(video_adapter_t *adp, u_long cmd, caddr_t data)
301 return (fb_commonioctl(adp, cmd, data));
305 terasic_mtl_vidsw_clear(video_adapter_t *adp)
307 struct terasic_mtl_softc *sc;
309 sc = (struct terasic_mtl_softc *)adp;
310 printf("%s: not yet terasic_mtl_io_clear(sc);\n", __func__);
315 terasic_mtl_vidsw_fill_rect(video_adapter_t *adp, int val, int x, int y,
319 printf("%s: not yet\n", __func__);
324 terasic_mtl_vidsw_bitblt(video_adapter_t *adp, ...)
327 printf("%s: not yet\n", __func__);
332 terasic_mtl_vidsw_diag(video_adapter_t *adp, int level)
335 printf("%s: not yet\n", __func__);
340 terasic_mtl_vidsw_save_cursor_palette(video_adapter_t *adp, u_char *palette)
343 printf("%s: not yet\n", __func__);
348 terasic_mtl_vidsw_load_cursor_palette(video_adapter_t *adp, u_char *palette)
351 printf("%s: not yet\n", __func__);
356 terasic_mtl_vidsw_copy(video_adapter_t *adp, vm_offset_t src, vm_offset_t dst,
360 printf("%s: not yet\n", __func__);
365 terasic_mtl_vidsw_putp(video_adapter_t *adp, vm_offset_t off, uint32_t p,
366 uint32_t a, int size, int bpp, int bit_ltor, int byte_ltor)
369 printf("%s: not yet\n", __func__);
374 terasic_mtl_vidsw_putc(video_adapter_t *adp, vm_offset_t off, uint8_t c,
377 struct terasic_mtl_softc *sc;
380 sc = (struct terasic_mtl_softc *)adp;
381 col = (off % adp->va_info.vi_width);
382 row = (off / adp->va_info.vi_width);
383 terasic_mtl_text_putc(sc, col, row, c, a);
388 terasic_mtl_vidsw_puts(video_adapter_t *adp, vm_offset_t off, u_int16_t *s,
393 for (i = 0; i < len; i++)
394 vidd_putc(adp, off + i, s[i] & 0xff, (s[i] & 0xff00) >> 8);
399 terasic_mtl_vidsw_putm(video_adapter_t *adp, int x, int y,
400 uint8_t *pixel_image, uint32_t pixel_mask, int size, int width)
403 printf("%s: not yet\n", __func__);
408 * XXXRW: For historical reasons, syscons can't register video consoles
409 * without a keyboard implementation. Provide a dummy.
411 static keyboard_switch_t terasic_mtl_keyboard_switch;
414 terasic_mtl_kbd_configure(int flags)
420 KEYBOARD_DRIVER(mtl_kbd, terasic_mtl_keyboard_switch,
421 terasic_mtl_kbd_configure);
424 terasic_mtl_syscons_attach(struct terasic_mtl_softc *sc)
429 malloc(sizeof(uint16_t) * TERASIC_MTL_ROWS * TERASIC_MTL_COLS,
430 M_TERASIC_MTL, M_WAITOK | M_ZERO);
431 error = terasic_mtl_vidsw_init(0, &sc->mtl_va, 0);
434 error = sc_attach_unit(sc->mtl_unit, device_get_flags(sc->mtl_dev) |
437 device_printf(sc->mtl_dev, "%s: sc_attach_unit failed (%d)\n",
441 free(sc->mtl_text_soft, M_TERASIC_MTL);
446 terasic_mtl_syscons_detach(struct terasic_mtl_softc *sc)
449 free(sc->mtl_text_soft, M_TERASIC_MTL);
450 panic("%s: not supported by syscons", __func__);
453 static video_switch_t terasic_mtl_vidsw = {
454 .probe = terasic_mtl_vidsw_probe,
455 .init = terasic_mtl_vidsw_init,
456 .get_info = terasic_mtl_vidsw_get_info,
457 .query_mode = terasic_mtl_vidsw_query_mode,
458 .set_mode = terasic_mtl_vidsw_set_mode,
459 .save_font = terasic_mtl_vidsw_save_font,
460 .load_font = terasic_mtl_vidsw_load_font,
461 .show_font = terasic_mtl_vidsw_show_font,
462 .save_palette = terasic_mtl_vidsw_save_palette,
463 .load_palette = terasic_mtl_vidsw_load_palette,
464 .set_border = terasic_mtl_vidsw_set_border,
465 .save_state = terasic_mtl_vidsw_save_state,
466 .load_state = terasic_mtl_vidsw_load_state,
467 .set_win_org = terasic_mtl_vidsw_set_win_org,
468 .read_hw_cursor = terasic_mtl_vidsw_read_hw_cursor,
469 .set_hw_cursor = terasic_mtl_vidsw_set_hw_cursor,
470 .set_hw_cursor_shape = terasic_mtl_vidsw_set_hw_cursor_shape,
471 .blank_display = terasic_mtl_vidsw_blank_display,
472 .mmap = terasic_mtl_vidsw_mmap,
473 .ioctl = terasic_mtl_vidsw_ioctl,
474 .clear = terasic_mtl_vidsw_clear,
475 .fill_rect = terasic_mtl_vidsw_fill_rect,
476 .bitblt = terasic_mtl_vidsw_bitblt,
477 .diag = terasic_mtl_vidsw_diag,
478 .save_cursor_palette = terasic_mtl_vidsw_save_cursor_palette,
479 .load_cursor_palette = terasic_mtl_vidsw_load_cursor_palette,
480 .copy = terasic_mtl_vidsw_copy,
481 .putp = terasic_mtl_vidsw_putp,
482 .putc = terasic_mtl_vidsw_putc,
483 .puts = terasic_mtl_vidsw_puts,
484 .putm = terasic_mtl_vidsw_putm,
486 VIDEO_DRIVER(terasic_mtl_syscons, terasic_mtl_vidsw,
487 terasic_mtl_syscons_configure);
488 extern sc_rndr_sw_t txtrndrsw;
489 RENDERER(terasic_mtl_syscons, 0, txtrndrsw, gfb_set);
490 RENDERER_MODULE(terasic_mtl_syscons, gfb_set);