PERFORCE change 219938 for review

Robert Watson rwatson at FreeBSD.org
Wed Jan 2 23:39:05 UTC 2013


http://p4web.freebsd.org/@@219938?ac=10

Change 219938 by rwatson at rwatson_zenith_cl_cam_ac_uk on 2013/01/02 23:38:54

	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.  Use FDT instead of device.hints for mtl0.

Affected files ...

.. //depot/projects/ctsrd/beribsd/src/sys/boot/fdt/dts/beripad-de4.dts#9 edit
.. //depot/projects/ctsrd/beribsd/src/sys/dev/terasic/mtl/terasic_mtl_fdt.c#2 edit
.. //depot/projects/ctsrd/beribsd/src/sys/mips/beri/files.beri#26 edit
.. //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI_FDT_DE4.hints#8 edit

Differences ...

==== //depot/projects/ctsrd/beribsd/src/sys/boot/fdt/dts/beripad-de4.dts#9 (text+ko) ====

@@ -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
@@ -100,14 +100,12 @@
 			reg = <0x7f007000 0x540>;
 		};
 
-/*
 		touchscreen at 70400000 {
 			compatible = "cambridge,mtl";
 			reg = <0x70400000 0x1000
 			       0x70000000 0x177000
 			       0x70177000 0x2000>;
 		};
-*/
 
 		flash at 0x74000000 {
 			compatible = "intel,strataflash";

==== //depot/projects/ctsrd/beribsd/src/sys/dev/terasic/mtl/terasic_mtl_fdt.c#2 (text+ko) ====

@@ -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 @@
 #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 @@
 	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.
+	 * 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.
 	 */
-	if (resource_long_value(device_get_name(dev), device_get_unit(dev),
-	    "reg_maddr", &reg_maddr) != 0 || (reg_maddr % PAGE_SIZE != 0)) {
+	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");
-		return (ENXIO);
+		error = ENXIO;
+		goto error;
 	}
-	if (resource_long_value(device_get_name(dev), device_get_unit(dev),
-	    "reg_msize", &reg_msize) != 0 || (reg_msize % PAGE_SIZE != 0)) {
+	if (rman_get_size(sc->mtl_reg_res) % 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.
-	 */
-	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);
+            (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 @@
 }
 
 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 @@
 	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);

==== //depot/projects/ctsrd/beribsd/src/sys/mips/beri/files.beri#26 (text+ko) ====

@@ -8,6 +8,7 @@
 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

==== //depot/projects/ctsrd/beribsd/src/sys/mips/conf/BERI_FDT_DE4.hints#8 (text+ko) ====

@@ -42,13 +42,13 @@
 #
 # Terasic Multi-touch LCD (MTL), an optional feature in DE-4 configurations.
 #
-hint.terasic_mtl.0.at="nexus0"
-hint.terasic_mtl.0.reg_maddr=0x70400000
-hint.terasic_mtl.0.reg_msize=0x1000
-hint.terasic_mtl.0.pixel_maddr=0x70000000
-hint.terasic_mtl.0.pixel_msize=0x177000
-hint.terasic_mtl.0.text_maddr=0x70177000
-hint.terasic_mtl.0.text_msize=0x2000
+#hint.terasic_mtl.0.at="nexus0"
+#hint.terasic_mtl.0.reg_maddr=0x70400000
+#hint.terasic_mtl.0.reg_msize=0x1000
+#hint.terasic_mtl.0.pixel_maddr=0x70000000
+#hint.terasic_mtl.0.pixel_msize=0x177000
+#hint.terasic_mtl.0.text_maddr=0x70177000
+#hint.terasic_mtl.0.text_msize=0x2000
 
 #
 # BERI Hardware Version ROM


More information about the p4-projects mailing list