Index: head/sys/boot/fdt/dts/mips/beripad-de4.dts =================================================================== --- head/sys/boot/fdt/dts/mips/beripad-de4.dts (revision 274822) +++ head/sys/boot/fdt/dts/mips/beripad-de4.dts (revision 274823) @@ -1,257 +1,258 @@ /*- * Copyright (c) 2012-2013 Robert N. M. Watson * Copyright (c) 2013 SRI International * 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. * * $FreeBSD$ */ /dts-v1/; /* * Device names here have been largely made up on the spot, especially for the * "compatible" strings, and might want to be revised. * * For now, use 32-bit addressing as our Avalon bus is 32-bit. However, in * the future, we should likely change to 64-bit. */ / { model = "SRI/Cambridge BeriPad (DE4)"; compatible = "sri-cambridge,beripad-de4"; #address-cells = <1>; #size-cells = <1>; cpus { #address-cells = <1>; #size-cells = <1>; /* * Secondary CPUs all start disabled and use the * spin-table enable method. cpu-release-addr must be * specified for each cpu other than cpu@0. Values of * cpu-release-addr grow down from 0x100000 (kernel). */ status = "disabled"; enable-method = "spin-table"; cpu@0 { device-type = "cpu"; compatible = "sri-cambridge,beri"; reg = <0 1>; status = "okay"; }; /* cpu@1 { device-type = "cpu"; compatible = "sri-cambridge,beri"; reg = <1 1>; // XXX: should we need cached prefix? cpu-release-addr = <0xffffffff 0x800fffe0>; }; */ }; soc { #address-cells = <1>; #size-cells = <1>; #interrupt-cells = <1>; /* * Declare mips,mips4k since BERI doesn't (yet) have a PIC, so * we use mips4k coprocessor 0 interrupt management directly. */ compatible = "simple-bus", "mips,mips4k"; ranges = <>; memory { device_type = "memory"; reg = <0x0 0x40000000>; // 1G at 0x0 }; beripic0: beripic@7f804000 { compatible = "sri-cambridge,beri-pic"; interrupt-controller; #address-cells = <0>; #interrupt-cells = <1>; reg = <0x7f804000 0x400 0x7f806000 0x10 0x7f806080 0x10 0x7f806100 0x10>; interrupts = <0 1 2 3 4>; hard-interrupt-sources = <64>; soft-interrupt-sources = <64>; }; serial@7f002100 { compatible = "ns16550"; reg = <0x7f002100 0x20>; reg-shift = <2>; clock-frequency = <50000000>; interrupts = <6>; interrupt-parent = <&beripic0>; }; serial@7f000000 { compatible = "altera,jtag_uart-11_0"; reg = <0x7f000000 0x40>; interrupts = <0>; interrupt-parent = <&beripic0>; }; serial@7f001000 { compatible = "altera,jtag_uart-11_0"; reg = <0x7f001000 0x40>; }; serial@7f002000 { compatible = "altera,jtag_uart-11_0"; reg = <0x7f002000 0x40>; }; sdcard@7f008000 { compatible = "altera,sdcard_11_2011"; reg = <0x7f008000 0x400>; }; led@7f006000 { compatible = "sri-cambridge,de4led"; reg = <0x7f006000 0x1>; }; /* * XXX-BZ keep flash before ethernet so that atse can read the * Ethernet addresses for now. */ flash@74000000 { #address-cells = <1>; #size-cells = <1>; compatible = "cfi-flash"; reg = <0x74000000 0x4000000>; /* Board configuration */ partition@0 { reg = <0x0 0x20000>; label = "config"; }; /* Power up FPGA image */ partition@20000 { reg = <0x20000 0xc00000>; label = "fpga0"; }; /* Secondary FPGA image (on RE_CONFIGn button) */ partition@C20000 { reg = <0xc20000 0xc00000>; label = "fpga1"; }; /* Space for operating system use */ partition@1820000 { reg = <0x1820000 0x027c0000>; label = "os"; }; /* Second stage bootloader */ parition@3fe0000 { reg = <0x3fe0000 0x20000>; label = "boot"; }; }; ethernet@7f007000 { compatible = "altera,atse"; // MAC, RX+RXC, TX+TXC. reg = <0x7f007000 0x400 0x7f007500 0x8 0x7f007520 0x20 0x7f007400 0x8 0x7f007420 0x20>; // RX, TX interrupts = <1 2>; interrupt-parent = <&beripic0>; }; ethernet@7f005000 { compatible = "altera,atse"; // MAC, RX+RXC, TX+TXC. reg = <0x7f005000 0x400 0x7f005500 0x8 0x7f005520 0x20 0x7f005400 0x8 0x7f005420 0x20>; // RX, TX interrupts = <11 12>; interrupt-parent = <&beripic0>; }; touchscreen@70400000 { compatible = "sri-cambridge,mtl"; + panel-size = < 800 480 >; reg = <0x70400000 0x1000 0x70000000 0x177000 0x70177000 0x2000>; }; usb@0x7f100000 { compatible = "nxp,usb-isp1761"; reg = <0x7f100000 0x40000 0x7f140000 0x4>; // IRQ 4 is DC, IRQ 5 is HC. interrupts = <4 5>; interrupt-parent = <&beripic0>; }; avgen@0x7f009000 { compatible = "sri-cambridge,avgen"; reg = <0x7f009000 0x2>; sri-cambridge,width = <1>; sri-cambridge,fileio = "r"; sri-cambridge,devname = "de4bsw"; }; avgen@0x7f00a000 { compatible = "sri-cambridge,avgen"; reg = <0x7f00a000 0x14>; sri-cambridge,width = <4>; sri-cambridge,fileio = "rw"; sri-cambridge,devname = "berirom"; }; avgen@0x7f00c000 { compatible = "sri-cambridge,avgen"; reg = <0x7f00c000 0x8>; sri-cambridge,width = <4>; sri-cambridge,fileio = "rw"; sri-cambridge,devname = "de4tempfan"; }; }; }; Index: head/sys/dev/terasic/mtl/terasic_mtl.c =================================================================== --- head/sys/dev/terasic/mtl/terasic_mtl.c (revision 274822) +++ head/sys/dev/terasic/mtl/terasic_mtl.c (revision 274823) @@ -1,113 +1,132 @@ /*- * Copyright (c) 2012 Robert N. M. Watson * 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 "opt_syscons.h" + #include #include #include #include #include /* struct vt_mode */ +#include #include /* video_adapter_t */ #include #include #include #include #include #include #include #include #include #include /* * Device driver for the Terasic Multitouch LCD (MTL). Three separate * sub-drivers that support, respectively, access to device control registers, - * the pixel frame buffer, and the text frame buffer. The last of these is - * also hooked up to syscons. + * the pixel frame buffer, and the text frame buffer. The pixel frame buffer + * is hooked up to vt(4), and the text frame buffer to syscons(4). * * Eventually, the frame buffer control registers and touch screen input FIFO * will end up being separate sub-drivers as well. * * Note: sub-driver detach routines must check whether or not they have * attached as they may be called even if the attach routine hasn't been, on * an error. */ devclass_t terasic_mtl_devclass; int terasic_mtl_attach(struct terasic_mtl_softc *sc) { int error; error = terasic_mtl_reg_attach(sc); if (error) goto error; error = terasic_mtl_pixel_attach(sc); if (error) goto error; error = terasic_mtl_text_attach(sc); if (error) goto error; /* - * XXXRW: Once we've attached syscons, we can't detach it, so do it - * last. + * XXXRW: Once we've attached syscons or vt, we can't detach it, so do + * it last. */ +#if defined(DEV_VT) + terasic_mtl_reg_pixel_endian_set(sc, BYTE_ORDER == BIG_ENDIAN); + error = terasic_mtl_fbd_attach(sc); + if (error) + goto error; + terasic_mtl_blend_pixel_set(sc, TERASIC_MTL_ALPHA_OPAQUE); + terasic_mtl_blend_textfg_set(sc, TERASIC_MTL_ALPHA_TRANSPARENT); + terasic_mtl_blend_textbg_set(sc, TERASIC_MTL_ALPHA_TRANSPARENT); +#endif +#if defined(DEV_SC) error = terasic_mtl_syscons_attach(sc); if (error) goto error; - 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); terasic_mtl_blend_textbg_set(sc, TERASIC_MTL_ALPHA_OPAQUE); +#endif + terasic_mtl_blend_default_set(sc, TERASIC_MTL_COLOR_BLACK); return (0); error: terasic_mtl_text_detach(sc); terasic_mtl_pixel_detach(sc); terasic_mtl_reg_detach(sc); return (error); } void terasic_mtl_detach(struct terasic_mtl_softc *sc) { - /* XXXRW: syscons can't detach, but we try anyway, only to panic. */ + /* XXXRW: syscons and vt can't detach, but try anyway, only to panic. */ +#if defined(DEV_SC) 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); terasic_mtl_pixel_detach(sc); terasic_mtl_reg_detach(sc); } Index: head/sys/dev/terasic/mtl/terasic_mtl.h =================================================================== --- head/sys/dev/terasic/mtl/terasic_mtl.h (revision 274822) +++ head/sys/dev/terasic/mtl/terasic_mtl.h (revision 274823) @@ -1,212 +1,233 @@ /*- * Copyright (c) 2012 Robert N. M. Watson * 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. * * $FreeBSD$ */ #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. */ device_t mtl_dev; int mtl_unit; /* * The MTL driver doesn't require a lot of synchronisation; however, * the lock is used to protect read-modify-write operations on MTL * registers. */ struct mtx mtl_lock; /* * Control register device -- mappable from userspace. */ struct cdev *mtl_reg_cdev; struct resource *mtl_reg_res; 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; int mtl_pixel_rid; /* * Text frame buffer device -- mappable from userspace, and syscons * hookup. */ struct cdev *mtl_text_cdev; 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) #define TERASIC_MTL_LOCK_ASSERT(sc) mtx_assert(&(sc)->mtl_lock, MA_OWNED) #define TERASIC_MTL_LOCK_DESTROY(sc) mtx_destroy(&(sc)->mtl_lock) #define TERASIC_MTL_LOCK_INIT(sc) mtx_init(&(sc)->mtl_lock, \ "terasic_mtl", NULL, MTX_DEF) #define TERASIC_MTL_UNLOCK(sc) mtx_unlock(&(sc)->mtl_lock) /* * Constant properties of the MTL text frame buffer. */ #define TERASIC_MTL_COLS 100 #define TERASIC_MTL_ROWS 40 /* * MTL control register offsets. */ #define TERASIC_MTL_OFF_BLEND 0 #define TERASIC_MTL_OFF_TEXTCURSOR 4 #define TERASIC_MTL_OFF_TEXTFRAMEBUFADDR 8 #define TERASIC_MTL_OFF_TOUCHPOINT_X1 12 #define TERASIC_MTL_OFF_TOUCHPOINT_Y1 16 #define TERASIC_MTL_OFF_TOUCHPOINT_X2 20 #define TERASIC_MTL_OFF_TOUCHPOINT_Y2 24 #define TERASIC_MTL_OFF_TOUCHGESTURE 28 /* * Constants to help interpret various control registers. */ +#define TERASIC_MTL_BLEND_PIXEL_ENDIAN_SWAP 0x10000000 #define TERASIC_MTL_BLEND_DEFAULT_MASK 0x0f000000 #define TERASIC_MTL_BLEND_DEFAULT_SHIFT 24 #define TERASIC_MTL_BLEND_PIXEL_MASK 0x00ff0000 #define TERASIC_MTL_BLEND_PIXEL_SHIFT 16 #define TERASIC_MTL_BLEND_TEXTFG_MASK 0x0000ff00 #define TERASIC_MTL_BLEND_TEXTFG_SHIFT 8 #define TERASIC_MTL_BLEND_TEXTBG_MASK 0x000000ff #define TERASIC_MTL_BLEND_TEXTBG_SHIFT 0 #define TERASIC_MTL_TEXTCURSOR_COL_MASK 0xff00 #define TERASIC_MTL_TEXTCURSOR_COL_SHIFT 8 #define TERASIC_MTL_TEXTCURSOR_ROW_MASK 0xff /* * Colours used both by VGA-like text rendering, and for the default display * colour. */ #define TERASIC_MTL_COLOR_BLACK 0 #define TERASIC_MTL_COLOR_DARKBLUE 1 #define TERASIC_MTL_COLOR_DARKGREEN 2 #define TERASIC_MTL_COLOR_DARKCYAN 3 #define TERASIC_MTL_COLOR_DARKRED 4 #define TERASIC_MTL_COLOR_DARKMAGENTA 5 #define TERASIC_MTL_COLOR_BROWN 6 #define TERASIC_MTL_COLOR_LIGHTGREY 7 #define TERASIC_MTL_COLOR_DARKGREY 8 #define TERASIC_MTL_COLOR_LIGHTBLUE 9 #define TERASIC_MTL_COLOR_LIGHTGREEN 10 #define TERASIC_MTL_COLOR_LIGHTCYAN 11 #define TERASIC_MTL_COLOR_LIGHTRED 12 #define TERASIC_MTL_COLOR_LIGHTMAGENTA 13 #define TERASIC_MTL_COLOR_LIGHTYELLOW 14 #define TERASIC_MTL_COLOR_WHITE 15 #define TERASIC_MTL_COLORMASK_BLINK 0x80 /* * Constants to help interpret the text frame buffer. */ #define TERASIC_MTL_TEXTFRAMEBUF_EXPECTED_ADDR 0x0177000 #define TERASIC_MTL_TEXTFRAMEBUF_CHAR_SHIFT 0 #define TERASIC_MTL_TEXTFRAMEBUF_ATTR_SHIFT 8 /* + * Framebuffer constants. + */ +#define TERASIC_MTL_FB_WIDTH 800 +#define TERASIC_MTL_FB_HEIGHT 640 + +/* * Alpha-blending constants. */ #define TERASIC_MTL_ALPHA_TRANSPARENT 0 #define TERASIC_MTL_ALPHA_OPAQUE 255 /* * Driver setup routines from the bus attachment/teardown. */ int terasic_mtl_attach(struct terasic_mtl_softc *sc); void terasic_mtl_detach(struct terasic_mtl_softc *sc); 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); void terasic_mtl_reg_detach(struct terasic_mtl_softc *sc); int terasic_mtl_syscons_attach(struct terasic_mtl_softc *sc); void terasic_mtl_syscons_detach(struct terasic_mtl_softc *sc); int terasic_mtl_text_attach(struct terasic_mtl_softc *sc); void terasic_mtl_text_detach(struct terasic_mtl_softc *sc); /* * Control register I/O routines. */ void terasic_mtl_reg_blank(struct terasic_mtl_softc *sc); void terasic_mtl_reg_blend_get(struct terasic_mtl_softc *sc, uint32_t *blendp); void terasic_mtl_reg_blend_set(struct terasic_mtl_softc *sc, uint32_t blend); void terasic_mtl_reg_textcursor_get(struct terasic_mtl_softc *sc, uint8_t *colp, uint8_t *rowp); void terasic_mtl_reg_textcursor_set(struct terasic_mtl_softc *sc, uint8_t col, uint8_t row); void terasic_mtl_reg_textframebufaddr_get(struct terasic_mtl_softc *sc, uint32_t *addrp); void terasic_mtl_reg_textframebufaddr_set(struct terasic_mtl_softc *sc, uint32_t addr); /* * Read-modify-write updates of sub-bytes of the blend register. */ void terasic_mtl_blend_default_set(struct terasic_mtl_softc *sc, uint8_t colour); void terasic_mtl_blend_pixel_set(struct terasic_mtl_softc *sc, uint8_t alpha); void terasic_mtl_blend_textfg_set(struct terasic_mtl_softc *sc, uint8_t alpha); void terasic_mtl_blend_textbg_set(struct terasic_mtl_softc *sc, uint8_t alpha); +void terasic_mtl_reg_pixel_endian_set(struct terasic_mtl_softc *sc, + int endian_swap); /* * Text frame buffer I/O routines. */ void terasic_mtl_text_putc(struct terasic_mtl_softc *sc, u_int x, u_int y, uint8_t c, uint8_t a); #endif /* _DEV_TERASIC_MTL_H_ */ Index: head/sys/dev/terasic/mtl/terasic_mtl_fdt.c =================================================================== --- head/sys/dev/terasic/mtl/terasic_mtl_fdt.c (revision 274822) +++ head/sys/dev/terasic/mtl/terasic_mtl_fdt.c (revision 274823) @@ -1,203 +1,215 @@ /*- * Copyright (c) 2012-2013 Robert N. M. Watson * 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 /* struct vt_mode */ #include /* video_adapter_t */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include +#include "fb_if.h" + static int terasic_mtl_fdt_probe(device_t dev) { if (!ofw_bus_status_okay(dev)) return (ENXIO); if (ofw_bus_is_compatible(dev, "sri-cambridge,mtl")) { device_set_desc(dev, "Terasic Multi-touch LCD (MTL)"); return (BUS_PROBE_DEFAULT); } return (ENXIO); } static int terasic_mtl_fdt_attach(device_t dev) { struct terasic_mtl_softc *sc; int error; sc = device_get_softc(dev); sc->mtl_dev = dev; sc->mtl_unit = device_get_unit(dev); /* * FDT allows multiple memory resources to be defined for a device; * query them in the order registers, pixel buffer, text buffer. * However, we need to sanity-check that they are page-aligned and * page-sized, so we may still abort. */ sc->mtl_reg_rid = 0; sc->mtl_reg_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mtl_reg_rid, RF_ACTIVE); if (sc->mtl_reg_res == NULL) { device_printf(dev, "couldn't map register memory\n"); error = ENXIO; goto error; } if (rman_get_start(sc->mtl_reg_res) % PAGE_SIZE != 0) { - device_printf(dev, "improper register address"); + device_printf(dev, "improper register address\n"); error = ENXIO; goto error; } if (rman_get_size(sc->mtl_reg_res) % PAGE_SIZE != 0) { - device_printf(dev, "improper register size"); + device_printf(dev, "improper register size\n"); error = ENXIO; goto error; } device_printf(sc->mtl_dev, "registers at mem %p-%p\n", (void *)rman_get_start(sc->mtl_reg_res), (void *)(rman_get_start(sc->mtl_reg_res) + rman_get_size(sc->mtl_reg_res))); sc->mtl_pixel_rid = 1; sc->mtl_pixel_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mtl_pixel_rid, RF_ACTIVE); if (sc->mtl_pixel_res == NULL) { device_printf(dev, "couldn't map pixel memory\n"); error = ENXIO; goto error; } if (rman_get_start(sc->mtl_pixel_res) % PAGE_SIZE != 0) { - device_printf(dev, "improper pixel address"); + device_printf(dev, "improper pixel address\n"); error = ENXIO; goto error; } if (rman_get_size(sc->mtl_pixel_res) % PAGE_SIZE != 0) { - device_printf(dev, "improper pixel size"); + device_printf(dev, "improper pixel size\n"); error = ENXIO; goto error; } device_printf(sc->mtl_dev, "pixel frame buffer at mem %p-%p\n", (void *)rman_get_start(sc->mtl_pixel_res), (void *)(rman_get_start(sc->mtl_pixel_res) + rman_get_size(sc->mtl_pixel_res))); sc->mtl_text_rid = 2; sc->mtl_text_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mtl_text_rid, RF_ACTIVE); if (sc->mtl_text_res == NULL) { device_printf(dev, "couldn't map text memory\n"); error = ENXIO; goto error; } if (rman_get_start(sc->mtl_text_res) % PAGE_SIZE != 0) { - device_printf(dev, "improper text address"); + device_printf(dev, "improper text address\n"); error = ENXIO; goto error; } if (rman_get_size(sc->mtl_text_res) % PAGE_SIZE != 0) { - device_printf(dev, "improper text size"); + device_printf(dev, "improper text size\n"); error = ENXIO; goto error; } device_printf(sc->mtl_dev, "text frame buffer at mem %p-%p\n", (void *)rman_get_start(sc->mtl_text_res), (void *)(rman_get_start(sc->mtl_text_res) + rman_get_size(sc->mtl_text_res))); error = terasic_mtl_attach(sc); if (error == 0) return (0); error: if (sc->mtl_text_res != NULL) bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_text_rid, sc->mtl_text_res); if (sc->mtl_pixel_res != NULL) bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_pixel_rid, sc->mtl_pixel_res); if (sc->mtl_reg_res != NULL) bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_reg_rid, sc->mtl_reg_res); return (error); } static int terasic_mtl_fdt_detach(device_t dev) { struct terasic_mtl_softc *sc; sc = device_get_softc(dev); terasic_mtl_detach(sc); bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_text_rid, sc->mtl_text_res); bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_pixel_rid, sc->mtl_pixel_res); bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_reg_rid, sc->mtl_reg_res); 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 } }; static driver_t terasic_mtl_fdt_driver = { "terasic_mtl", terasic_mtl_fdt_methods, sizeof(struct terasic_mtl_softc), }; DRIVER_MODULE(mtl, simplebus, terasic_mtl_fdt_driver, terasic_mtl_devclass, 0, 0); Index: head/sys/dev/terasic/mtl/terasic_mtl_nexus.c =================================================================== --- head/sys/dev/terasic/mtl/terasic_mtl_nexus.c (revision 274822) +++ head/sys/dev/terasic/mtl/terasic_mtl_nexus.c (revision 274823) @@ -1,194 +1,206 @@ /*- * Copyright (c) 2012 Robert N. M. Watson * 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 /* struct vt_mode */ #include /* video_adapter_t */ #include #include #include #include #include #include #include #include #include #include +#include "fb_if.h" + static int terasic_mtl_nexus_probe(device_t dev) { device_set_desc(dev, "Terasic Multi-touch LCD (MTL)"); return (BUS_PROBE_NOWILDCARD); } static int terasic_mtl_nexus_attach(device_t dev) { struct terasic_mtl_softc *sc; u_long pixel_maddr, text_maddr, reg_maddr; u_long pixel_msize, text_msize, reg_msize; int error; sc = device_get_softc(dev); sc->mtl_dev = dev; sc->mtl_unit = device_get_unit(dev); /* * Query non-standard hints to find the locations of our two memory * regions. Enforce certain alignment and size requirements. */ if (resource_long_value(device_get_name(dev), device_get_unit(dev), "reg_maddr", ®_maddr) != 0 || (reg_maddr % PAGE_SIZE != 0)) { - device_printf(dev, "improper register address"); + device_printf(dev, "improper register address\n"); return (ENXIO); } if (resource_long_value(device_get_name(dev), device_get_unit(dev), "reg_msize", ®_msize) != 0 || (reg_msize % PAGE_SIZE != 0)) { - device_printf(dev, "improper register size"); + device_printf(dev, "improper register size\n"); return (ENXIO); } if (resource_long_value(device_get_name(dev), device_get_unit(dev), "pixel_maddr", &pixel_maddr) != 0 || (pixel_maddr % PAGE_SIZE != 0)) { - device_printf(dev, "improper pixel frame buffer address"); + device_printf(dev, "improper pixel frame buffer address\n"); return (ENXIO); } if (resource_long_value(device_get_name(dev), device_get_unit(dev), "pixel_msize", &pixel_msize) != 0 || (pixel_msize % PAGE_SIZE != 0)) { - device_printf(dev, "improper pixel frame buffer size"); + device_printf(dev, "improper pixel frame buffer size\n"); return (ENXIO); } if (resource_long_value(device_get_name(dev), device_get_unit(dev), "text_maddr", &text_maddr) != 0 || (text_maddr % PAGE_SIZE != 0)) { - device_printf(dev, "improper text frame buffer address"); + device_printf(dev, "improper text frame buffer address\n"); return (ENXIO); } if (resource_long_value(device_get_name(dev), device_get_unit(dev), "text_msize", &text_msize) != 0 || (text_msize % PAGE_SIZE != 0)) { - device_printf(dev, "improper text frame buffer size"); + device_printf(dev, "improper text frame buffer size\n"); return (ENXIO); } /* * Allocate resources. */ sc->mtl_reg_rid = 0; sc->mtl_reg_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->mtl_reg_rid, reg_maddr, reg_maddr + reg_msize - 1, reg_msize, RF_ACTIVE); if (sc->mtl_reg_res == NULL) { device_printf(dev, "couldn't map register memory\n"); error = ENXIO; goto error; } device_printf(sc->mtl_dev, "registers at mem %p-%p\n", (void *)reg_maddr, (void *)(reg_maddr + reg_msize)); sc->mtl_pixel_rid = 0; sc->mtl_pixel_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->mtl_pixel_rid, pixel_maddr, pixel_maddr + pixel_msize - 1, pixel_msize, RF_ACTIVE); if (sc->mtl_pixel_res == NULL) { device_printf(dev, "couldn't map pixel memory\n"); error = ENXIO; goto error; } device_printf(sc->mtl_dev, "pixel frame buffer at mem %p-%p\n", (void *)pixel_maddr, (void *)(pixel_maddr + pixel_msize)); sc->mtl_text_rid = 0; sc->mtl_text_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &sc->mtl_text_rid, text_maddr, text_maddr + text_msize - 1, text_msize, RF_ACTIVE); if (sc->mtl_text_res == NULL) { device_printf(dev, "couldn't map text memory\n"); error = ENXIO; goto error; } device_printf(sc->mtl_dev, "text frame buffer at mem %p-%p\n", (void *)text_maddr, (void *)(text_maddr + text_msize)); error = terasic_mtl_attach(sc); if (error == 0) return (0); error: if (sc->mtl_text_res != NULL) bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_text_rid, sc->mtl_text_res); if (sc->mtl_pixel_res != NULL) bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_pixel_rid, sc->mtl_pixel_res); if (sc->mtl_reg_res != NULL) bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_reg_rid, sc->mtl_reg_res); return (error); } static int terasic_mtl_nexus_detach(device_t dev) { struct terasic_mtl_softc *sc; sc = device_get_softc(dev); terasic_mtl_detach(sc); bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_text_rid, sc->mtl_text_res); bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_pixel_rid, sc->mtl_pixel_res); bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_reg_rid, sc->mtl_reg_res); 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 } }; static driver_t terasic_mtl_nexus_driver = { "terasic_mtl", terasic_mtl_nexus_methods, sizeof(struct terasic_mtl_softc), }; DRIVER_MODULE(mtl, nexus, terasic_mtl_nexus_driver, terasic_mtl_devclass, 0, 0); Index: head/sys/dev/terasic/mtl/terasic_mtl_reg.c =================================================================== --- head/sys/dev/terasic/mtl/terasic_mtl_reg.c (revision 274822) +++ head/sys/dev/terasic/mtl/terasic_mtl_reg.c (revision 274823) @@ -1,278 +1,293 @@ /*- * Copyright (c) 2012 Robert N. M. Watson * 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 /* struct vt_mode */ #include #include /* video_adapter_t */ #include #include #include #include #include #include #include #include #include static d_mmap_t terasic_mtl_reg_mmap; static d_read_t terasic_mtl_reg_read; static d_write_t terasic_mtl_reg_write; static struct cdevsw terasic_mtl_reg_cdevsw = { .d_version = D_VERSION, .d_mmap = terasic_mtl_reg_mmap, .d_read = terasic_mtl_reg_read, .d_write = terasic_mtl_reg_write, .d_name = "terasic_mtl_reg", }; /* * All I/O to/from the MTL register device must be 32-bit, and aligned to * 32-bit. */ static int terasic_mtl_reg_read(struct cdev *dev, struct uio *uio, int flag) { struct terasic_mtl_softc *sc; u_long offset, size; uint32_t v; int error; if (uio->uio_offset < 0 || uio->uio_offset % 4 != 0 || uio->uio_resid % 4 != 0) return (ENODEV); sc = dev->si_drv1; size = rman_get_size(sc->mtl_reg_res); error = 0; if ((uio->uio_offset + uio->uio_resid < 0) || (uio->uio_offset + uio->uio_resid > size)) return (ENODEV); while (uio->uio_resid > 0) { offset = uio->uio_offset; if (offset + sizeof(v) > size) return (ENODEV); v = bus_read_4(sc->mtl_reg_res, offset); error = uiomove(&v, sizeof(v), uio); if (error) return (error); } return (error); } static int terasic_mtl_reg_write(struct cdev *dev, struct uio *uio, int flag) { struct terasic_mtl_softc *sc; u_long offset, size; uint32_t v; int error; if (uio->uio_offset < 0 || uio->uio_offset % 4 != 0 || uio->uio_resid % 4 != 0) return (ENODEV); sc = dev->si_drv1; size = rman_get_size(sc->mtl_reg_res); error = 0; while (uio->uio_resid > 0) { offset = uio->uio_offset; if (offset + sizeof(v) > size) return (ENODEV); error = uiomove(&v, sizeof(v), uio); if (error) return (error); bus_write_4(sc->mtl_reg_res, offset, v); } return (error); } static int terasic_mtl_reg_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, int nprot, vm_memattr_t *memattr) { struct terasic_mtl_softc *sc; int error; sc = dev->si_drv1; error = 0; if (trunc_page(offset) == offset && rman_get_size(sc->mtl_reg_res) >= offset + PAGE_SIZE) { *paddr = rman_get_start(sc->mtl_reg_res) + offset; *memattr = VM_MEMATTR_UNCACHEABLE; } else error = ENODEV; return (error); } void terasic_mtl_reg_blend_get(struct terasic_mtl_softc *sc, uint32_t *blendp) { *blendp = le32toh(bus_read_4(sc->mtl_reg_res, TERASIC_MTL_OFF_BLEND)); } void terasic_mtl_reg_blend_set(struct terasic_mtl_softc *sc, uint32_t blend) { bus_write_4(sc->mtl_reg_res, TERASIC_MTL_OFF_BLEND, htole32(blend)); } void terasic_mtl_blend_default_set(struct terasic_mtl_softc *sc, uint8_t colour) { uint32_t v; TERASIC_MTL_LOCK(sc); terasic_mtl_reg_blend_get(sc, &v); v &= ~TERASIC_MTL_BLEND_DEFAULT_MASK; v |= colour << TERASIC_MTL_BLEND_DEFAULT_SHIFT; terasic_mtl_reg_blend_set(sc, v); TERASIC_MTL_UNLOCK(sc); } void terasic_mtl_blend_pixel_set(struct terasic_mtl_softc *sc, uint8_t alpha) { uint32_t v; TERASIC_MTL_LOCK(sc); terasic_mtl_reg_blend_get(sc, &v); v &= ~TERASIC_MTL_BLEND_PIXEL_MASK; v |= alpha << TERASIC_MTL_BLEND_PIXEL_SHIFT; terasic_mtl_reg_blend_set(sc, v); TERASIC_MTL_UNLOCK(sc); } void terasic_mtl_blend_textfg_set(struct terasic_mtl_softc *sc, uint8_t alpha) { uint32_t v; TERASIC_MTL_LOCK(sc); terasic_mtl_reg_blend_get(sc, &v); v &= ~TERASIC_MTL_BLEND_TEXTFG_MASK; v |= alpha << TERASIC_MTL_BLEND_TEXTFG_SHIFT; terasic_mtl_reg_blend_set(sc, v); TERASIC_MTL_UNLOCK(sc); } void terasic_mtl_blend_textbg_set(struct terasic_mtl_softc *sc, uint8_t alpha) { uint32_t v; TERASIC_MTL_LOCK(sc); terasic_mtl_reg_blend_get(sc, &v); v &= ~TERASIC_MTL_BLEND_TEXTBG_MASK; v |= alpha << TERASIC_MTL_BLEND_TEXTBG_SHIFT; terasic_mtl_reg_blend_set(sc, v); TERASIC_MTL_UNLOCK(sc); } void +terasic_mtl_reg_pixel_endian_set(struct terasic_mtl_softc *sc, int endian_swap) +{ + uint32_t v; + + TERASIC_MTL_LOCK(sc); + terasic_mtl_reg_blend_get(sc, &v); + if (endian_swap) + v |= TERASIC_MTL_BLEND_PIXEL_ENDIAN_SWAP; + else + v &= ~TERASIC_MTL_BLEND_PIXEL_ENDIAN_SWAP; + terasic_mtl_reg_blend_set(sc, v); + TERASIC_MTL_UNLOCK(sc); +} + +void terasic_mtl_reg_textcursor_get(struct terasic_mtl_softc *sc, uint8_t *colp, uint8_t *rowp) { uint32_t v; v = bus_read_4(sc->mtl_reg_res, TERASIC_MTL_OFF_TEXTCURSOR); v = le32toh(v); *colp = (v & TERASIC_MTL_TEXTCURSOR_COL_MASK) >> TERASIC_MTL_TEXTCURSOR_COL_SHIFT; *rowp = (v & TERASIC_MTL_TEXTCURSOR_ROW_MASK); } void terasic_mtl_reg_textcursor_set(struct terasic_mtl_softc *sc, uint8_t col, uint8_t row) { uint32_t v; v = (col << TERASIC_MTL_TEXTCURSOR_COL_SHIFT) | row; v = htole32(v); bus_write_4(sc->mtl_reg_res, TERASIC_MTL_OFF_TEXTCURSOR, v); } void terasic_mtl_reg_blank(struct terasic_mtl_softc *sc) { - device_printf(sc->mtl_dev, "%s: not yet", __func__); + device_printf(sc->mtl_dev, "%s: not yet\n", __func__); } void terasic_mtl_reg_textframebufaddr_get(struct terasic_mtl_softc *sc, uint32_t *addrp) { uint32_t addr; addr = bus_read_4(sc->mtl_reg_res, TERASIC_MTL_OFF_TEXTFRAMEBUFADDR); *addrp = le32toh(addr); } void terasic_mtl_reg_textframebufaddr_set(struct terasic_mtl_softc *sc, uint32_t addr) { addr = htole32(addr); bus_write_4(sc->mtl_reg_res, TERASIC_MTL_OFF_TEXTFRAMEBUFADDR, addr); } int terasic_mtl_reg_attach(struct terasic_mtl_softc *sc) { sc->mtl_reg_cdev = make_dev(&terasic_mtl_reg_cdevsw, sc->mtl_unit, UID_ROOT, GID_WHEEL, 0400, "mtl_reg%d", sc->mtl_unit); if (sc->mtl_reg_cdev == NULL) { device_printf(sc->mtl_dev, "%s: make_dev failed\n", __func__); return (ENXIO); } /* XXXRW: Slight race between make_dev(9) and here. */ sc->mtl_reg_cdev->si_drv1 = sc; return (0); } void terasic_mtl_reg_detach(struct terasic_mtl_softc *sc) { if (sc->mtl_reg_cdev != NULL) destroy_dev(sc->mtl_reg_cdev); } Index: head/sys/dev/terasic/mtl/terasic_mtl_text.c =================================================================== --- head/sys/dev/terasic/mtl/terasic_mtl_text.c (revision 274822) +++ head/sys/dev/terasic/mtl/terasic_mtl_text.c (revision 274823) @@ -1,189 +1,193 @@ /*- * Copyright (c) 2012 Robert N. M. Watson * 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 /* struct vt_mode */ #include #include /* video_adapter_t */ #include #include #include #include #include #include #include #include #include static d_mmap_t terasic_mtl_text_mmap; static d_read_t terasic_mtl_text_read; static d_write_t terasic_mtl_text_write; static struct cdevsw terasic_mtl_text_cdevsw = { .d_version = D_VERSION, .d_mmap = terasic_mtl_text_mmap, .d_read = terasic_mtl_text_read, .d_write = terasic_mtl_text_write, .d_name = "terasic_mtl_text", }; /* * All I/O to/from the mtl device must be 16-bit, and aligned to 16-bit. */ static int terasic_mtl_text_read(struct cdev *dev, struct uio *uio, int flag) { struct terasic_mtl_softc *sc; u_long offset, size; uint16_t v; int error; if (uio->uio_offset < 0 || uio->uio_offset % 2 != 0 || uio->uio_resid % 2 != 0) return (ENODEV); sc = dev->si_drv1; size = rman_get_size(sc->mtl_text_res); error = 0; if ((uio->uio_offset + uio->uio_resid < 0) || (uio->uio_offset + uio->uio_resid > size)) return (ENODEV); while (uio->uio_resid > 0) { offset = uio->uio_offset; if (offset + sizeof(v) > size) return (ENODEV); v = bus_read_2(sc->mtl_text_res, offset); error = uiomove(&v, sizeof(v), uio); if (error) return (error); } return (error); } static int terasic_mtl_text_write(struct cdev *dev, struct uio *uio, int flag) { struct terasic_mtl_softc *sc; u_long offset, size; uint16_t v; int error; if (uio->uio_offset < 0 || uio->uio_offset % 2 != 0 || uio->uio_resid % 2 != 0) return (ENODEV); sc = dev->si_drv1; size = rman_get_size(sc->mtl_text_res); error = 0; while (uio->uio_resid > 0) { offset = uio->uio_offset; if (offset + sizeof(v) > size) return (ENODEV); error = uiomove(&v, sizeof(v), uio); if (error) return (error); bus_write_2(sc->mtl_text_res, offset, v); } return (error); } static int terasic_mtl_text_mmap(struct cdev *dev, vm_ooffset_t offset, vm_paddr_t *paddr, int nprot, vm_memattr_t *memattr) { struct terasic_mtl_softc *sc; int error; sc = dev->si_drv1; error = 0; if (trunc_page(offset) == offset && rman_get_size(sc->mtl_text_res) >= offset + PAGE_SIZE) { *paddr = rman_get_start(sc->mtl_text_res) + offset; *memattr = VM_MEMATTR_UNCACHEABLE; } else error = ENODEV; return (error); } void terasic_mtl_text_putc(struct terasic_mtl_softc *sc, u_int x, u_int y, uint8_t c, uint8_t a) { u_int offset; uint16_t v; KASSERT(x < TERASIC_MTL_COLS, ("%s: TERASIC_MTL_COLS", __func__)); KASSERT(y < TERASIC_MTL_ROWS, ("%s: TERASIC_MTL_ROWS", __func__)); offset = sizeof(uint16_t) * (x + y * TERASIC_MTL_COLS); v = (c << TERASIC_MTL_TEXTFRAMEBUF_CHAR_SHIFT) | (a << TERASIC_MTL_TEXTFRAMEBUF_ATTR_SHIFT); v = htole16(v); bus_write_2(sc->mtl_text_res, offset, v); } int terasic_mtl_text_attach(struct terasic_mtl_softc *sc) { uint32_t v; + u_int offset; terasic_mtl_reg_textframebufaddr_get(sc, &v); if (v != TERASIC_MTL_TEXTFRAMEBUF_EXPECTED_ADDR) { device_printf(sc->mtl_dev, "%s: unexpected text frame buffer " "address (%08x); cannot attach\n", __func__, v); return (ENXIO); } + for (offset = 0; offset < rman_get_size(sc->mtl_text_res); + offset += sizeof(uint16_t)) + bus_write_2(sc->mtl_text_res, offset, 0); sc->mtl_text_cdev = make_dev(&terasic_mtl_text_cdevsw, sc->mtl_unit, UID_ROOT, GID_WHEEL, 0400, "mtl_text%d", sc->mtl_unit); if (sc->mtl_text_cdev == NULL) { device_printf(sc->mtl_dev, "%s: make_dev failed\n", __func__); return (ENXIO); } /* XXXRW: Slight race between make_dev(9) and here. */ TERASIC_MTL_LOCK_INIT(sc); sc->mtl_text_cdev->si_drv1 = sc; return (0); } void terasic_mtl_text_detach(struct terasic_mtl_softc *sc) { if (sc->mtl_text_cdev != NULL) { destroy_dev(sc->mtl_text_cdev); TERASIC_MTL_LOCK_DESTROY(sc); } } Index: head/sys/dev/terasic/mtl/terasic_mtl_vt.c =================================================================== --- head/sys/dev/terasic/mtl/terasic_mtl_vt.c (nonexistent) +++ head/sys/dev/terasic/mtl/terasic_mtl_vt.c (revision 274823) @@ -0,0 +1,133 @@ +/*- + * 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")) != sizeof(dts_value)) + return (ENXIO); + OF_getencprop(node, "panel-size", dts_value, len); + info->fb_width = dts_value[0]; + info->fb_height = dts_value[1]; + info->fb_bpp = info->fb_depth = 32; + info->fb_stride = info->fb_width * (info->fb_depth / 8); + + /* + * Safety belt to ensure framebuffer params are as expected. May be + * removed when we have full confidence in fdt / hints params. + */ + if (info->fb_width != TERASIC_MTL_FB_WIDTH || + info->fb_height != TERASIC_MTL_FB_HEIGHT || + info->fb_stride != 3200 || + info->fb_bpp != 32 || info->fb_depth != 32) { + device_printf(sc->mtl_dev, + "rejecting invalid panel params width=%u height=%u\n", + (unsigned)info->fb_width, (unsigned)info->fb_height); + return (EINVAL); + } + + 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); + } + 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); Property changes on: head/sys/dev/terasic/mtl/terasic_mtl_vt.c ___________________________________________________________________ Added: svn:eol-style ## -0,0 +1 ## +native \ No newline at end of property Added: svn:keywords ## -0,0 +1 ## +FreeBSD=%H \ No newline at end of property Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Index: head/sys/mips/beri/files.beri =================================================================== --- head/sys/mips/beri/files.beri (revision 274822) +++ head/sys/mips/beri/files.beri (revision 274823) @@ -1,26 +1,27 @@ # $FreeBSD$ dev/altera/atse/if_atse.c optional altera_atse dev/altera/atse/if_atse_fdt.c optional altera_atse fdt dev/altera/atse/if_atse_nexus.c optional altera_atse dev/altera/jtag_uart/altera_jtag_uart_cons.c optional altera_jtag_uart dev/altera/jtag_uart/altera_jtag_uart_tty.c optional altera_jtag_uart dev/altera/jtag_uart/altera_jtag_uart_fdt.c optional altera_jtag_uart fdt dev/altera/jtag_uart/altera_jtag_uart_nexus.c optional altera_jtag_uart dev/netfpga10g/nf10bmac/if_nf10bmac_fdt.c optional netfpga10g_nf10bmac fdt dev/netfpga10g/nf10bmac/if_nf10bmac.c optional netfpga10g_nf10bmac dev/terasic/de4led/terasic_de4led.c optional terasic_de4led dev/terasic/de4led/terasic_de4led_fdt.c optional terasic_de4led fdt dev/terasic/de4led/terasic_de4led_nexus.c optional terasic_de4led dev/terasic/mtl/terasic_mtl.c optional terasic_mtl 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_pic.c optional fdt mips/beri/beri_simplebus.c optional fdt mips/beri/fdt_ic_if.m optional fdt mips/mips/intr_machdep.c standard mips/mips/tick.c standard Index: head/sys/mips/conf/BERI_DE4_BASE =================================================================== --- head/sys/mips/conf/BERI_DE4_BASE (revision 274822) +++ head/sys/mips/conf/BERI_DE4_BASE (revision 274823) @@ -1,51 +1,52 @@ # # BERI_DE4_BASE -- Kernel for the SRI/Cambridge "BERI" (Bluespec Extensible RISC # Implementation) FPGA soft core, as configured in its Terasic DE-4 reference # configuration. This kernel configration must be further specialized to # to include a root filesystem specification. # # $FreeBSD$ # include "BERI_TEMPLATE" ident BERI_DE4_BASE options NFSCL # New Network Filesystem Client options NFSLOCKD # Network Lock Manager options NFS_ROOT # NFS usable as /, requires NFSCL options FDT options FDT_DTB_STATIC makeoptions FDT_DTS_FILE=beripad-de4.dts hints "BERI_DE4.hints" # Flash partitions still use hints. device altera_atse device altera_avgen device altera_jtag_uart device altera_sdcard device terasic_de4led device terasic_mtl device bpf device cfi device cfid options CFI_SUPPORT_STRATAFLASH options ATSE_CFI_HACK -device sc +device vt +device kbdmux device uart device miibus options DEVICE_POLLING # # USB support # #options USB_DEBUG #options USB_REQ_DEBUG #options USB_VERBOSE device usb device saf1761otg