2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2012 Robert N. M. Watson
7 * This software was developed by SRI International and the University of
8 * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
9 * ("CTSRD"), as part of the DARPA CRASH research programme.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #include <sys/cdefs.h>
34 __FBSDID("$FreeBSD$");
36 #include <sys/param.h>
38 #include <sys/condvar.h>
40 #include <sys/consio.h> /* struct vt_mode */
41 #include <sys/fbio.h> /* video_adapter_t */
42 #include <sys/kernel.h>
44 #include <sys/malloc.h>
45 #include <sys/module.h>
46 #include <sys/mutex.h>
48 #include <sys/systm.h>
50 #include <machine/bus.h>
51 #include <machine/resource.h>
53 #include <dev/terasic/mtl/terasic_mtl.h>
58 terasic_mtl_nexus_probe(device_t dev)
61 device_set_desc(dev, "Terasic Multi-touch LCD (MTL)");
62 return (BUS_PROBE_NOWILDCARD);
66 terasic_mtl_nexus_attach(device_t dev)
68 struct terasic_mtl_softc *sc;
69 u_long pixel_maddr, text_maddr, reg_maddr;
70 u_long pixel_msize, text_msize, reg_msize;
73 sc = device_get_softc(dev);
75 sc->mtl_unit = device_get_unit(dev);
78 * Query non-standard hints to find the locations of our two memory
79 * regions. Enforce certain alignment and size requirements.
81 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
82 "reg_maddr", ®_maddr) != 0 || (reg_maddr % PAGE_SIZE != 0)) {
83 device_printf(dev, "improper register address\n");
86 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
87 "reg_msize", ®_msize) != 0 || (reg_msize % PAGE_SIZE != 0)) {
88 device_printf(dev, "improper register size\n");
91 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
92 "pixel_maddr", &pixel_maddr) != 0 ||
93 (pixel_maddr % PAGE_SIZE != 0)) {
94 device_printf(dev, "improper pixel frame buffer address\n");
97 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
98 "pixel_msize", &pixel_msize) != 0 ||
99 (pixel_msize % PAGE_SIZE != 0)) {
100 device_printf(dev, "improper pixel frame buffer size\n");
103 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
104 "text_maddr", &text_maddr) != 0 ||
105 (text_maddr % PAGE_SIZE != 0)) {
106 device_printf(dev, "improper text frame buffer address\n");
109 if (resource_long_value(device_get_name(dev), device_get_unit(dev),
110 "text_msize", &text_msize) != 0 ||
111 (text_msize % PAGE_SIZE != 0)) {
112 device_printf(dev, "improper text frame buffer size\n");
117 * Allocate resources.
120 sc->mtl_reg_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
121 &sc->mtl_reg_rid, reg_maddr, reg_maddr + reg_msize - 1,
122 reg_msize, RF_ACTIVE);
123 if (sc->mtl_reg_res == NULL) {
124 device_printf(dev, "couldn't map register memory\n");
128 device_printf(sc->mtl_dev, "registers at mem %p-%p\n",
129 (void *)reg_maddr, (void *)(reg_maddr + reg_msize));
130 sc->mtl_pixel_rid = 0;
131 sc->mtl_pixel_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
132 &sc->mtl_pixel_rid, pixel_maddr, pixel_maddr + pixel_msize - 1,
133 pixel_msize, RF_ACTIVE);
134 if (sc->mtl_pixel_res == NULL) {
135 device_printf(dev, "couldn't map pixel memory\n");
139 device_printf(sc->mtl_dev, "pixel frame buffer at mem %p-%p\n",
140 (void *)pixel_maddr, (void *)(pixel_maddr + pixel_msize));
141 sc->mtl_text_rid = 0;
142 sc->mtl_text_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
143 &sc->mtl_text_rid, text_maddr, text_maddr + text_msize - 1,
144 text_msize, RF_ACTIVE);
145 if (sc->mtl_text_res == NULL) {
146 device_printf(dev, "couldn't map text memory\n");
150 device_printf(sc->mtl_dev, "text frame buffer at mem %p-%p\n",
151 (void *)text_maddr, (void *)(text_maddr + text_msize));
152 error = terasic_mtl_attach(sc);
156 if (sc->mtl_text_res != NULL)
157 bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_text_rid,
159 if (sc->mtl_pixel_res != NULL)
160 bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_pixel_rid,
162 if (sc->mtl_reg_res != NULL)
163 bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_reg_rid,
169 terasic_mtl_nexus_detach(device_t dev)
171 struct terasic_mtl_softc *sc;
173 sc = device_get_softc(dev);
174 terasic_mtl_detach(sc);
175 bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_text_rid,
177 bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_pixel_rid,
179 bus_release_resource(dev, SYS_RES_MEMORY, sc->mtl_reg_rid,
184 static struct fb_info *
185 terasic_mtl_fb_getinfo(device_t dev)
187 struct terasic_mtl_softc *sc;
189 sc = device_get_softc(dev);
190 return (&sc->mtl_fb_info);
193 static device_method_t terasic_mtl_nexus_methods[] = {
194 DEVMETHOD(device_probe, terasic_mtl_nexus_probe),
195 DEVMETHOD(device_attach, terasic_mtl_nexus_attach),
196 DEVMETHOD(device_detach, terasic_mtl_nexus_detach),
197 DEVMETHOD(fb_getinfo, terasic_mtl_fb_getinfo),
201 static driver_t terasic_mtl_nexus_driver = {
203 terasic_mtl_nexus_methods,
204 sizeof(struct terasic_mtl_softc),
207 DRIVER_MODULE(mtl, nexus, terasic_mtl_nexus_driver, terasic_mtl_devclass, 0,