Partially merge Perforce changeset 219938 to head:
Write FDT attachment for the Terasic MTL (multitouch LCD) driver. Exploit the fact that FDT allows multiple memory ranges to be assigned to a device, giving us a cleaner description than device.hints does. Portions of this changeset that remove mtl from BERI device.hints and add to DTS will be merged separately. Sponsored by: DARPA, AFRL
This commit is contained in:
parent
22f6fb27d5
commit
0ccb306ce9
@ -1,5 +1,5 @@
|
||||
/*-
|
||||
* Copyright (c) 2012 Robert N. M. Watson
|
||||
* Copyright (c) 2012-2013 Robert N. M. Watson
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software was developed by SRI International and the University of
|
||||
@ -48,22 +48,28 @@ __FBSDID("$FreeBSD$");
|
||||
#include <machine/bus.h>
|
||||
#include <machine/resource.h>
|
||||
|
||||
#include <dev/fdt/fdt_common.h>
|
||||
#include <dev/ofw/openfirm.h>
|
||||
#include <dev/ofw/ofw_bus.h>
|
||||
#include <dev/ofw/ofw_bus_subr.h>
|
||||
|
||||
#include <dev/terasic/mtl/terasic_mtl.h>
|
||||
|
||||
static int
|
||||
terasic_mtl_nexus_probe(device_t dev)
|
||||
terasic_mtl_fdt_probe(device_t dev)
|
||||
{
|
||||
|
||||
device_set_desc(dev, "Terasic Multi-touch LCD (MTL)");
|
||||
return (BUS_PROBE_DEFAULT);
|
||||
if (ofw_bus_is_compatible(dev, "cambridge,mtl")) {
|
||||
device_set_desc(dev, "Terasic Multi-touch LCD (MTL)");
|
||||
return (BUS_PROBE_DEFAULT);
|
||||
}
|
||||
return (ENXIO);
|
||||
}
|
||||
|
||||
static int
|
||||
terasic_mtl_nexus_attach(device_t dev)
|
||||
terasic_mtl_fdt_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);
|
||||
@ -71,80 +77,80 @@ terasic_mtl_nexus_attach(device_t 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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
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");
|
||||
return (ENXIO);
|
||||
}
|
||||
|
||||
/*
|
||||
* Allocate resources.
|
||||
* 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(dev, SYS_RES_MEMORY,
|
||||
&sc->mtl_reg_rid, reg_maddr, reg_maddr + reg_msize - 1,
|
||||
reg_msize, RF_ACTIVE);
|
||||
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");
|
||||
error = ENXIO;
|
||||
goto error;
|
||||
}
|
||||
if (rman_get_size(sc->mtl_reg_res) % PAGE_SIZE != 0) {
|
||||
device_printf(dev, "improper register size");
|
||||
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);
|
||||
(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");
|
||||
error = ENXIO;
|
||||
goto error;
|
||||
}
|
||||
if (rman_get_size(sc->mtl_pixel_res) % PAGE_SIZE != 0) {
|
||||
device_printf(dev, "improper pixel size");
|
||||
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);
|
||||
(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");
|
||||
error = ENXIO;
|
||||
goto error;
|
||||
}
|
||||
if (rman_get_size(sc->mtl_text_res) % PAGE_SIZE != 0) {
|
||||
device_printf(dev, "improper text size");
|
||||
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));
|
||||
(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);
|
||||
@ -162,7 +168,7 @@ error:
|
||||
}
|
||||
|
||||
static int
|
||||
terasic_mtl_nexus_detach(device_t dev)
|
||||
terasic_mtl_fdt_detach(device_t dev)
|
||||
{
|
||||
struct terasic_mtl_softc *sc;
|
||||
|
||||
@ -177,20 +183,20 @@ terasic_mtl_nexus_detach(device_t dev)
|
||||
return (0);
|
||||
}
|
||||
|
||||
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),
|
||||
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),
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
static driver_t terasic_mtl_nexus_driver = {
|
||||
static driver_t terasic_mtl_fdt_driver = {
|
||||
"terasic_mtl",
|
||||
terasic_mtl_nexus_methods,
|
||||
terasic_mtl_fdt_methods,
|
||||
sizeof(struct terasic_mtl_softc),
|
||||
};
|
||||
|
||||
static devclass_t terasic_mtl_devclass;
|
||||
|
||||
DRIVER_MODULE(mtl, nexus, terasic_mtl_nexus_driver, terasic_mtl_devclass, 0,
|
||||
DRIVER_MODULE(mtl, simplebus, terasic_mtl_fdt_driver, terasic_mtl_devclass, 0,
|
||||
0);
|
||||
|
@ -7,6 +7,7 @@ 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user