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>
54 terasic_mtl_nexus_probe(device_t dev)
57 device_set_desc(dev, "Terasic Multi-touch LCD (MTL)");
58 return (BUS_PROBE_NOWILDCARD);
62 terasic_mtl_nexus_attach(device_t dev)
64 struct terasic_mtl_softc *sc;
65 u_long pixel_maddr, text_maddr, reg_maddr;
66 u_long pixel_msize, text_msize, reg_msize;
69 sc = device_get_softc(dev);
71 sc->mtl_unit = device_get_unit(dev);
74 * Query non-standard hints to find the locations of our two memory
75 * regions. Enforce certain alignment and size requirements.
77 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
78 "reg_maddr", ®_maddr) != 0 || (reg_maddr % PAGE_SIZE != 0)) {
79 device_printf(dev, "improper register address");
82 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
83 "reg_msize", ®_msize) != 0 || (reg_msize % PAGE_SIZE != 0)) {
84 device_printf(dev, "improper register size");
87 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
88 "pixel_maddr", &pixel_maddr) != 0 ||
89 (pixel_maddr % PAGE_SIZE != 0)) {
90 device_printf(dev, "improper pixel frame buffer address");
93 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
94 "pixel_msize", &pixel_msize) != 0 ||
95 (pixel_msize % PAGE_SIZE != 0)) {
96 device_printf(dev, "improper pixel frame buffer size");
99 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
100 "text_maddr", &text_maddr) != 0 ||
101 (text_maddr % PAGE_SIZE != 0)) {
102 device_printf(dev, "improper text frame buffer address");
105 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
106 "text_msize", &text_msize) != 0 ||
107 (text_msize % PAGE_SIZE != 0)) {
108 device_printf(dev, "improper text frame buffer size");
113 * Allocate resources.
116 sc->mtl_reg_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
117 &sc->mtl_reg_rid, reg_maddr, reg_maddr + reg_msize - 1,
118 reg_msize, RF_ACTIVE);
119 if (sc->mtl_reg_res == NULL) {
120 device_printf(dev, "couldn't map register memory\n");
124 device_printf(sc->mtl_dev, "registers at mem %p-%p\n",
125 (void *)reg_maddr, (void *)(reg_maddr + reg_msize));
126 sc->mtl_pixel_rid = 0;
127 sc->mtl_pixel_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
128 &sc->mtl_pixel_rid, pixel_maddr, pixel_maddr + pixel_msize - 1,
129 pixel_msize, RF_ACTIVE);
130 if (sc->mtl_pixel_res == NULL) {
131 device_printf(dev, "couldn't map pixel memory\n");
135 device_printf(sc->mtl_dev, "pixel frame buffer at mem %p-%p\n",
136 (void *)pixel_maddr, (void *)(pixel_maddr + pixel_msize));
137 sc->mtl_text_rid = 0;
138 sc->mtl_text_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
139 &sc->mtl_text_rid, text_maddr, text_maddr + text_msize - 1,
140 text_msize, RF_ACTIVE);
141 if (sc->mtl_text_res == NULL) {
142 device_printf(dev, "couldn't map text memory\n");
146 device_printf(sc->mtl_dev, "text frame buffer at mem %p-%p\n",
147 (void *)text_maddr, (void *)(text_maddr + text_msize));
148 error = terasic_mtl_attach(sc);
152 if (sc->mtl_text_res != NULL)
153 bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_text_rid,
155 if (sc->mtl_pixel_res != NULL)
156 bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_pixel_rid,
158 if (sc->mtl_reg_res != NULL)
159 bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_reg_rid,
165 terasic_mtl_nexus_detach(device_t dev)
167 struct terasic_mtl_softc *sc;
169 sc = device_get_softc(dev);
170 terasic_mtl_detach(sc);
171 bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_text_rid,
173 bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_pixel_rid,
175 bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_reg_rid,
180 static device_method_t terasic_mtl_nexus_methods[] = {
181 DEVMETHOD(device_probe, terasic_mtl_nexus_probe),
182 DEVMETHOD(device_attach, terasic_mtl_nexus_attach),
183 DEVMETHOD(device_detach, terasic_mtl_nexus_detach),
187 static driver_t terasic_mtl_nexus_driver = {
189 terasic_mtl_nexus_methods,
190 sizeof(struct terasic_mtl_softc),
193 DRIVER_MODULE(mtl, nexus, terasic_mtl_nexus_driver, terasic_mtl_devclass, 0,