diff --git a/sys/boot/fdt/dts/mips/beripad-de4.dts b/sys/boot/fdt/dts/mips/beripad-de4.dts index 0eec98a..fc61310 100644 --- a/sys/boot/fdt/dts/mips/beripad-de4.dts +++ b/sys/boot/fdt/dts/mips/beripad-de4.dts @@ -216,6 +216,7 @@ touchscreen@70400000 { compatible = "sri-cambridge,mtl"; + panel-size = < 800 480 >; reg = <0x70400000 0x1000 0x70000000 0x177000 0x70177000 0x2000>; diff --git a/sys/dev/terasic/mtl/terasic_mtl.c b/sys/dev/terasic/mtl/terasic_mtl.c index 5305172..88e9844 100644 --- a/sys/dev/terasic/mtl/terasic_mtl.c +++ b/sys/dev/terasic/mtl/terasic_mtl.c @@ -31,6 +31,8 @@ #include __FBSDID("$FreeBSD$"); +#include "opt_syscons.h" + #include #include #include @@ -80,6 +82,12 @@ terasic_mtl_attach(struct terasic_mtl_softc *sc) error = terasic_mtl_text_attach(sc); if (error) goto error; +#if defined(DEV_VT) + error = terasic_mtl_fbd_attach(sc); + if (error) + goto error; +#endif +#if defined(DEV_SC) /* * XXXRW: Once we've attached syscons, we can't detach it, so do it * last. @@ -87,6 +95,7 @@ terasic_mtl_attach(struct terasic_mtl_softc *sc) error = terasic_mtl_syscons_attach(sc); if (error) goto error; +#endif terasic_mtl_blend_default_set(sc, TERASIC_MTL_COLOR_BLACK); terasic_mtl_blend_pixel_set(sc, TERASIC_MTL_ALPHA_TRANSPARENT); terasic_mtl_blend_textfg_set(sc, TERASIC_MTL_ALPHA_OPAQUE); @@ -103,8 +112,13 @@ void terasic_mtl_detach(struct terasic_mtl_softc *sc) { +#if defined(DEV_SC) /* XXXRW: syscons can't detach, but we try anyway, only to panic. */ terasic_mtl_syscons_detach(sc); +#endif +#if defined(DEV_VT) + terasic_mtl_fbd_detach(sc); +#endif /* All other aspects of the driver can detach just fine. */ terasic_mtl_text_detach(sc); diff --git a/sys/dev/terasic/mtl/terasic_mtl.h b/sys/dev/terasic/mtl/terasic_mtl.h index ad77248..9669c12 100644 --- a/sys/dev/terasic/mtl/terasic_mtl.h +++ b/sys/dev/terasic/mtl/terasic_mtl.h @@ -33,13 +33,17 @@ #ifndef _DEV_TERASIC_MTL_H_ #define _DEV_TERASIC_MTL_H_ +#include "opt_syscons.h" + struct terasic_mtl_softc { +#if defined(DEV_SC) /* * syscons requires that its video_adapter_t be at the front of the * softc, so place syscons fields first, which we otherwise would * probably not do. */ video_adapter_t mtl_va; +#endif /* * Bus-related fields. @@ -62,7 +66,8 @@ struct terasic_mtl_softc { int mtl_reg_rid; /* - * Graphics frame buffer device -- mappable from userspace. + * Graphics frame buffer device -- mappable from userspace, and used + * by the vt framebuffer interface. */ struct cdev *mtl_pixel_cdev; struct resource *mtl_pixel_res; @@ -76,6 +81,11 @@ struct terasic_mtl_softc { struct resource *mtl_text_res; int mtl_text_rid; uint16_t *mtl_text_soft; + + /* + * Framebuffer hookup for vt(4). + */ + struct fb_info mtl_fb_info; }; #define TERASIC_MTL_LOCK(sc) mtx_lock(&(sc)->mtl_lock) @@ -164,6 +174,8 @@ extern devclass_t terasic_mtl_devclass; /* * Sub-driver setup routines. */ +int terasic_mtl_fbd_attach(struct terasic_mtl_softc *sc); +void terasic_mtl_fbd_detach(struct terasic_mtl_softc *sc); int terasic_mtl_pixel_attach(struct terasic_mtl_softc *sc); void terasic_mtl_pixel_detach(struct terasic_mtl_softc *sc); int terasic_mtl_reg_attach(struct terasic_mtl_softc *sc); diff --git a/sys/dev/terasic/mtl/terasic_mtl_fdt.c b/sys/dev/terasic/mtl/terasic_mtl_fdt.c index 0a9b268..fad6559 100644 --- a/sys/dev/terasic/mtl/terasic_mtl_fdt.c +++ b/sys/dev/terasic/mtl/terasic_mtl_fdt.c @@ -55,6 +55,8 @@ __FBSDID("$FreeBSD$"); #include +#include "fb_if.h" + static int terasic_mtl_fdt_probe(device_t dev) { @@ -186,10 +188,20 @@ terasic_mtl_fdt_detach(device_t dev) return (0); } +static struct fb_info * +terasic_mtl_fb_getinfo(device_t dev) +{ + struct terasic_mtl_softc *sc; + + sc = device_get_softc(dev); + return (&sc->mtl_fb_info); +} + static device_method_t terasic_mtl_fdt_methods[] = { DEVMETHOD(device_probe, terasic_mtl_fdt_probe), DEVMETHOD(device_attach, terasic_mtl_fdt_attach), DEVMETHOD(device_detach, terasic_mtl_fdt_detach), + DEVMETHOD(fb_getinfo, terasic_mtl_fb_getinfo), { 0, 0 } }; diff --git a/sys/dev/terasic/mtl/terasic_mtl_nexus.c b/sys/dev/terasic/mtl/terasic_mtl_nexus.c index b1d13db..e56dc4c 100644 --- a/sys/dev/terasic/mtl/terasic_mtl_nexus.c +++ b/sys/dev/terasic/mtl/terasic_mtl_nexus.c @@ -50,6 +50,8 @@ __FBSDID("$FreeBSD$"); #include +#include "fb_if.h" + static int terasic_mtl_nexus_probe(device_t dev) { @@ -177,10 +179,20 @@ terasic_mtl_nexus_detach(device_t dev) return (0); } +static struct fb_info * +terasic_mtl_fb_getinfo(device_t dev) +{ + struct terasic_mtl_softc *sc; + + sc = device_get_softc(dev); + return (&sc->mtl_fb_info); +} + static device_method_t terasic_mtl_nexus_methods[] = { DEVMETHOD(device_probe, terasic_mtl_nexus_probe), DEVMETHOD(device_attach, terasic_mtl_nexus_attach), DEVMETHOD(device_detach, terasic_mtl_nexus_detach), + DEVMETHOD(fb_getinfo, terasic_mtl_fb_getinfo), { 0, 0 } }; diff --git a/sys/dev/terasic/mtl/terasic_mtl_vt.c b/sys/dev/terasic/mtl/terasic_mtl_vt.c new file mode 100644 index 0000000..be8f41a --- /dev/null +++ b/sys/dev/terasic/mtl/terasic_mtl_vt.c @@ -0,0 +1,120 @@ +/*- + * Copyright (c) 2014 Ed Maste + * All rights reserved. + * + * This software was developed by SRI International and the University of + * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237) + * ("CTSRD"), as part of the DARPA CRASH research programme. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include + +#include + +/* + * Terasic Multitouch LCD (MTL) vt(4) framebuffer driver. + */ + +#include +#include + +static int +terasic_mtl_fbd_panel_info(struct terasic_mtl_softc *sc, struct fb_info *info) +{ + phandle_t node; + pcell_t dts_value[2]; + int len; + + if ((node = ofw_bus_get_node(sc->mtl_dev)) == -1) + return (ENXIO); + + /* panel size */ + if ((len = OF_getproplen(node, "panel-size")) <= 0) + return (ENXIO); + OF_getprop(node, "panel-size", &dts_value, len); + info->fb_width = fdt32_to_cpu(dts_value[0]); + info->fb_height = fdt32_to_cpu(dts_value[1]); + info->fb_stride = info->fb_width * (info->fb_depth / 8); + info->fb_bpp = info->fb_depth = 32; + return (0); +} + +int +terasic_mtl_fbd_attach(struct terasic_mtl_softc *sc) +{ + struct fb_info *info; + device_t fbd; + + info = &sc->mtl_fb_info; + info->fb_name = device_get_nameunit(sc->mtl_dev); + info->fb_pbase = rman_get_start(sc->mtl_pixel_res); + info->fb_size = rman_get_size(sc->mtl_pixel_res); + info->fb_vbase = (intptr_t)pmap_mapdev(info->fb_pbase, info->fb_size); + if (terasic_mtl_fbd_panel_info(sc, info) != 0) { + device_printf(sc->mtl_dev, "using default panel params\n"); + info->fb_bpp = info->fb_depth = 32; + info->fb_width = 800; + info->fb_height = 480; + info->fb_stride = info->fb_width * (info->fb_depth / 8); + } + + fbd = device_add_child(sc->mtl_dev, "fbd", + device_get_unit(sc->mtl_dev)); + if (fbd == NULL) { + device_printf(sc->mtl_dev, "Failed to attach fbd child\n"); + return (ENXIO); + } + if (device_probe_and_attach(fbd) != 0) { + device_printf(sc->mtl_dev, + "Failed to attach fbd device\n"); + return (ENXIO); + } + (void)vt_generate_vga_palette(info->fb_cmap, COLOR_FORMAT_RGB, + 0xff, 8, 0xff, 16, 0xff, 24); + return (0); +} + +void +terasic_mtl_fbd_detach(struct terasic_mtl_softc *sc) +{ + panic("%s: detach not implemented", __func__); +} + +extern device_t fbd_driver; +extern devclass_t fbd_devclass; +DRIVER_MODULE(fbd, terasic_mtl, fbd_driver, fbd_devclass, 0, 0); diff --git a/sys/mips/beri/files.beri b/sys/mips/beri/files.beri index 3ec3822..8ff2532 100644 --- a/sys/mips/beri/files.beri +++ b/sys/mips/beri/files.beri @@ -23,8 +23,9 @@ dev/terasic/mtl/terasic_mtl_fdt.c optional terasic_mtl fdt dev/terasic/mtl/terasic_mtl_nexus.c optional terasic_mtl dev/terasic/mtl/terasic_mtl_pixel.c optional terasic_mtl dev/terasic/mtl/terasic_mtl_reg.c optional terasic_mtl -dev/terasic/mtl/terasic_mtl_syscons.c optional terasic_mtl +dev/terasic/mtl/terasic_mtl_syscons.c optional terasic_mtl sc dev/terasic/mtl/terasic_mtl_text.c optional terasic_mtl +dev/terasic/mtl/terasic_mtl_vt.c optional terasic_mtl vt mips/beri/beri_machdep.c standard mips/beri/beri_mp.c optional smp mips/beri/beri_pic.c optional fdt diff --git a/sys/mips/conf/BERI_DE4_BASE b/sys/mips/conf/BERI_DE4_BASE index 5d9142d..eccf6186 100644 --- a/sys/mips/conf/BERI_DE4_BASE +++ b/sys/mips/conf/BERI_DE4_BASE @@ -33,7 +33,7 @@ device cfi device cfid options CFI_SUPPORT_STRATAFLASH options ATSE_CFI_HACK -device sc +device vt device uart