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>
36 #include <sys/condvar.h>
38 #include <sys/consio.h> /* struct vt_mode */
39 #include <sys/fbio.h> /* video_adapter_t */
40 #include <sys/kernel.h>
42 #include <sys/malloc.h>
43 #include <sys/module.h>
44 #include <sys/mutex.h>
46 #include <sys/systm.h>
48 #include <machine/bus.h>
49 #include <machine/resource.h>
51 #include <dev/terasic/mtl/terasic_mtl.h>
56 terasic_mtl_nexus_probe(device_t dev)
59 device_set_desc(dev, "Terasic Multi-touch LCD (MTL)");
60 return (BUS_PROBE_NOWILDCARD);
64 terasic_mtl_nexus_attach(device_t dev)
66 struct terasic_mtl_softc *sc;
67 u_long pixel_maddr, text_maddr, reg_maddr;
68 u_long pixel_msize, text_msize, reg_msize;
71 sc = device_get_softc(dev);
73 sc->mtl_unit = device_get_unit(dev);
76 * Query non-standard hints to find the locations of our two memory
77 * regions. Enforce certain alignment and size requirements.
79 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
80 "reg_maddr", ®_maddr) != 0 || (reg_maddr % PAGE_SIZE != 0)) {
81 device_printf(dev, "improper register address\n");
84 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
85 "reg_msize", ®_msize) != 0 || (reg_msize % PAGE_SIZE != 0)) {
86 device_printf(dev, "improper register size\n");
89 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
90 "pixel_maddr", &pixel_maddr) != 0 ||
91 (pixel_maddr % PAGE_SIZE != 0)) {
92 device_printf(dev, "improper pixel frame buffer address\n");
95 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
96 "pixel_msize", &pixel_msize) != 0 ||
97 (pixel_msize % PAGE_SIZE != 0)) {
98 device_printf(dev, "improper pixel frame buffer size\n");
101 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
102 "text_maddr", &text_maddr) != 0 ||
103 (text_maddr % PAGE_SIZE != 0)) {
104 device_printf(dev, "improper text frame buffer address\n");
107 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
108 "text_msize", &text_msize) != 0 ||
109 (text_msize % PAGE_SIZE != 0)) {
110 device_printf(dev, "improper text frame buffer size\n");
115 * Allocate resources.
118 sc->mtl_reg_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
119 &sc->mtl_reg_rid, reg_maddr, reg_maddr + reg_msize - 1,
120 reg_msize, RF_ACTIVE);
121 if (sc->mtl_reg_res == NULL) {
122 device_printf(dev, "couldn't map register memory\n");
126 device_printf(sc->mtl_dev, "registers at mem %p-%p\n",
127 (void *)reg_maddr, (void *)(reg_maddr + reg_msize));
128 sc->mtl_pixel_rid = 0;
129 sc->mtl_pixel_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
130 &sc->mtl_pixel_rid, pixel_maddr, pixel_maddr + pixel_msize - 1,
131 pixel_msize, RF_ACTIVE);
132 if (sc->mtl_pixel_res == NULL) {
133 device_printf(dev, "couldn't map pixel memory\n");
137 device_printf(sc->mtl_dev, "pixel frame buffer at mem %p-%p\n",
138 (void *)pixel_maddr, (void *)(pixel_maddr + pixel_msize));
139 sc->mtl_text_rid = 0;
140 sc->mtl_text_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
141 &sc->mtl_text_rid, text_maddr, text_maddr + text_msize - 1,
142 text_msize, RF_ACTIVE);
143 if (sc->mtl_text_res == NULL) {
144 device_printf(dev, "couldn't map text memory\n");
148 device_printf(sc->mtl_dev, "text frame buffer at mem %p-%p\n",
149 (void *)text_maddr, (void *)(text_maddr + text_msize));
150 error = terasic_mtl_attach(sc);
154 if (sc->mtl_text_res != NULL)
155 bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_text_rid,
157 if (sc->mtl_pixel_res != NULL)
158 bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_pixel_rid,
160 if (sc->mtl_reg_res != NULL)
161 bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_reg_rid,
167 terasic_mtl_nexus_detach(device_t dev)
169 struct terasic_mtl_softc *sc;
171 sc = device_get_softc(dev);
172 terasic_mtl_detach(sc);
173 bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_text_rid,
175 bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_pixel_rid,
177 bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_reg_rid,
182 static struct fb_info *
183 terasic_mtl_fb_getinfo(device_t dev)
185 struct terasic_mtl_softc *sc;
187 sc = device_get_softc(dev);
188 return (&sc->mtl_fb_info);
191 static device_method_t terasic_mtl_nexus_methods[] = {
192 DEVMETHOD(device_probe, terasic_mtl_nexus_probe),
193 DEVMETHOD(device_attach, terasic_mtl_nexus_attach),
194 DEVMETHOD(device_detach, terasic_mtl_nexus_detach),
195 DEVMETHOD(fb_getinfo, terasic_mtl_fb_getinfo),
199 static driver_t terasic_mtl_nexus_driver = {
201 terasic_mtl_nexus_methods,
202 sizeof(struct terasic_mtl_softc),
205 DRIVER_MODULE(mtl, nexus, terasic_mtl_nexus_driver, terasic_mtl_devclass, 0,