Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 26 Aug 2012 09:22:00 +0000 (UTC)
From:      Robert Watson <rwatson@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r239709 - in head/sys: dev/terasic/de4led mips/beri mips/conf
Message-ID:  <201208260922.q7Q9M0S9096188@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rwatson
Date: Sun Aug 26 09:21:59 2012
New Revision: 239709
URL: http://svn.freebsd.org/changeset/base/239709

Log:
  Add terasic_de4led, a led(4) driver for the on-board 8-element LED on the
  Terasic DE-4 board.  Allow LED configuration to be set using loader
  tunables, not just from userspace, and preconfigure LED 8 as a kernel
  heartbeat.  For now, this is a Nexus-attached, BERI-only driver, but it
  could be used with other hard and soft cores on Altera FPGAs as well, in
  principle.
  
  Sponsored by:	DARPA, AFRL

Added:
  head/sys/dev/terasic/de4led/
  head/sys/dev/terasic/de4led/terasic_de4led.c   (contents, props changed)
  head/sys/dev/terasic/de4led/terasic_de4led.h   (contents, props changed)
  head/sys/dev/terasic/de4led/terasic_de4led_nexus.c   (contents, props changed)
Modified:
  head/sys/mips/beri/files.beri
  head/sys/mips/conf/BERI_DE4.hints
  head/sys/mips/conf/BERI_DE4_MDROOT
  head/sys/mips/conf/BERI_DE4_SDROOT

Added: head/sys/dev/terasic/de4led/terasic_de4led.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/terasic/de4led/terasic_de4led.c	Sun Aug 26 09:21:59 2012	(r239709)
@@ -0,0 +1,188 @@
+/*-
+ * Copyright (c) 2012 Robert N. M. Watson
+ * All rights reserved.
+ *
+ * This software was developed by SRI International and the University of
+ * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
+ * ("CTSRD"), as part of the DARPA CRASH research programme.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/rman.h>
+
+#include <machine/bus.h>
+#include <machine/resource.h>
+
+#include <dev/led/led.h>
+#include <dev/terasic/de4led/terasic_de4led.h>
+
+static void
+terasic_de4led_update(struct terasic_de4led_softc *sc)
+{
+
+	TERASIC_DE4LED_LOCK_ASSERT(sc);
+
+	bus_write_1(sc->tdl_res, TERASIC_DE4LED_OFF_LED, sc->tdl_bits);
+}
+
+static void
+led_update(struct terasic_de4led_softc *sc, int bit, int onoff)
+{
+
+	TERASIC_DE4LED_LOCK(sc);
+	TERASIC_DE4LED_SETLED(sc, bit, onoff);
+	terasic_de4led_update(sc);
+	TERASIC_DE4LED_UNLOCK(sc);
+}
+
+static void
+led_0(void *arg, int onoff)
+{
+
+	led_update(arg, 0, onoff);
+}
+
+static void
+led_1(void *arg, int onoff)
+{
+
+	led_update(arg, 1, onoff);
+}
+
+static void
+led_2(void *arg, int onoff)
+{
+
+	led_update(arg, 2, onoff);
+}
+
+static void
+led_3(void *arg, int onoff)
+{
+
+	led_update(arg, 3, onoff);
+}
+
+static void
+led_4(void *arg, int onoff)
+{
+
+	led_update(arg, 4, onoff);
+}
+
+static void
+led_5(void *arg, int onoff)
+{
+
+	led_update(arg, 5, onoff);
+}
+
+static void
+led_6(void *arg, int onoff)
+{
+
+	led_update(arg, 6, onoff);
+}
+
+static void
+led_7(void *arg, int onoff)
+{
+
+	led_update(arg, 7, onoff);
+}
+
+void
+terasic_de4led_attach(struct terasic_de4led_softc *sc)
+{
+	const char *cmd;
+
+	TERASIC_DE4LED_LOCK_INIT(sc);
+
+	/*
+	 * Clear the LED array before we start.
+	 */
+	TERASIC_DE4LED_LOCK(sc);
+	TERASIC_DE4LED_CLEARBAR(sc);
+	terasic_de4led_update(sc);
+	TERASIC_DE4LED_UNLOCK(sc);
+
+	/*
+	 * Register the LED array with led(4).
+	 */
+	sc->tdl_leds[0] = led_create(led_0, sc, "de4led_0");
+	sc->tdl_leds[1] = led_create(led_1, sc, "de4led_1");
+	sc->tdl_leds[2] = led_create(led_2, sc, "de4led_2");
+	sc->tdl_leds[3] = led_create(led_3, sc, "de4led_3");
+	sc->tdl_leds[4] = led_create(led_4, sc, "de4led_4");
+	sc->tdl_leds[5] = led_create(led_5, sc, "de4led_5");
+	sc->tdl_leds[6] = led_create(led_6, sc, "de4led_6");
+	sc->tdl_leds[7] = led_create(led_7, sc, "de4led_7");
+
+	if (resource_string_value(device_get_name(sc->tdl_dev),
+	    sc->tdl_unit, "de4led_0_cmd", &cmd) == 0)
+		led_set("de4led_0", cmd);
+	if (resource_string_value(device_get_name(sc->tdl_dev),
+	    sc->tdl_unit, "de4led_1_cmd", &cmd) == 0)
+		led_set("de4led_1", cmd);
+	if (resource_string_value(device_get_name(sc->tdl_dev),
+	    sc->tdl_unit, "de4led_2_cmd", &cmd) == 0)
+		led_set("de4led_2", cmd);
+	if (resource_string_value(device_get_name(sc->tdl_dev),
+	    sc->tdl_unit, "de4led_3_cmd", &cmd) == 0)
+		led_set("de4led_3", cmd);
+	if (resource_string_value(device_get_name(sc->tdl_dev),
+	    sc->tdl_unit, "de4led_4_cmd", &cmd) == 0)
+		led_set("de4led_4", cmd);
+	if (resource_string_value(device_get_name(sc->tdl_dev),
+	    sc->tdl_unit, "de4led_5_cmd", &cmd) == 0)
+		led_set("de4led_5", cmd);
+	if (resource_string_value(device_get_name(sc->tdl_dev),
+	    sc->tdl_unit, "de4led_6_cmd", &cmd) == 0)
+		led_set("de4led_6", cmd);
+	if (resource_string_value(device_get_name(sc->tdl_dev),
+	    sc->tdl_unit, "de4led_7_cmd", &cmd) == 0)
+		led_set("de4led_7", cmd);
+}
+
+void
+terasic_de4led_detach(struct terasic_de4led_softc *sc)
+{
+	int i;
+
+	for (i = 0; i < 8; i++) {
+		led_destroy(sc->tdl_leds[i]);
+		sc->tdl_leds[i] = NULL;
+	}
+	TERASIC_DE4LED_LOCK(sc);
+	TERASIC_DE4LED_CLEARBAR(sc);
+	terasic_de4led_update(sc);
+	TERASIC_DE4LED_UNLOCK(sc);
+	TERASIC_DE4LED_LOCK_DESTROY(sc);
+}

Added: head/sys/dev/terasic/de4led/terasic_de4led.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/terasic/de4led/terasic_de4led.h	Sun Aug 26 09:21:59 2012	(r239709)
@@ -0,0 +1,75 @@
+/*-
+ * Copyright (c) 2012 Robert N. M. Watson
+ * All rights reserved.
+ *
+ * This software was developed by SRI International and the University of
+ * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
+ * ("CTSRD"), as part of the DARPA CRASH research programme.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _DEV_TERASIC_DE4LED_H_
+#define	_DEV_TERASIC_DE4LED_H_
+
+#define	TERASIC_DE4LED_NUMLEDS	8
+struct terasic_de4led_softc {
+	device_t	 tdl_dev;
+	int		 tdl_unit;
+	struct resource	*tdl_res;
+	int		 tdl_rid;
+	struct mtx	 tdl_lock;
+	uint8_t		 tdl_bits;
+	struct cdev	*tdl_leds[TERASIC_DE4LED_NUMLEDS];
+};
+
+#define	TERASIC_DE4LED_LOCK(sc)		mtx_lock(&(sc)->tdl_lock)
+#define	TERASIC_DE4LED_LOCK_ASSERT(sc)	mtx_assert(&(sc)->tdl_lock, MA_OWNED)
+#define	TERASIC_DE4LED_LOCK_DESTROY(sc)	mtx_destroy(&(sc)->tdl_lock)
+#define	TERASIC_DE4LED_LOCK_INIT(sc)	mtx_init(&(sc)->tdl_lock,	\
+					    "terasic_de4led", NULL, MTX_DEF)
+#define	TERASIC_DE4LED_UNLOCK(sc)	mtx_unlock(&(sc)->tdl_lock)
+
+/*
+ * Setting and clearing LEDs.  tdl_bits is in the bit order preferred for I/O.
+ * The LED elements are labelled 1..8 on the DE-4, so bit 0 is LED 1, and so
+ * on.
+ */
+#define	TERASIC_DE4LED_CLEARBAR(sc) do {				\
+	(sc)->tdl_bits = 0;						\
+} while (0)
+#define	TERASIC_DE4LED_SETLED(sc, led, onoff) do {			\
+	(sc)->tdl_bits &= ~(1 << (led));				\
+	(sc)->tdl_bits |= ((onoff != 0) ? 1 : 0) << (led);		\
+} while (0)
+
+/*
+ * Only one offset matters for this device -- 0.
+ */
+#define	TERASIC_DE4LED_OFF_LED		0
+
+void	terasic_de4led_attach(struct terasic_de4led_softc *sc);
+void	terasic_de4led_detach(struct terasic_de4led_softc *sc);
+
+#endif /* _DEV_TERASIC_DE4LED_H_ */

Added: head/sys/dev/terasic/de4led/terasic_de4led_nexus.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/sys/dev/terasic/de4led/terasic_de4led_nexus.c	Sun Aug 26 09:21:59 2012	(r239709)
@@ -0,0 +1,112 @@
+/*-
+ * Copyright (c) 2012 Robert N. M. Watson
+ * All rights reserved.
+ *
+ * This software was developed by SRI International and the University of
+ * Cambridge Computer Laboratory under DARPA/AFRL contract (FA8750-10-C-0237)
+ * ("CTSRD"), as part of the DARPA CRASH research programme.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <sys/condvar.h>
+#include <sys/conf.h>
+#include <sys/bio.h>
+#include <sys/kernel.h>
+#include <sys/lock.h>
+#include <sys/malloc.h>
+#include <sys/module.h>
+#include <sys/mutex.h>
+#include <sys/rman.h>
+#include <sys/systm.h>
+
+#include <machine/bus.h>
+#include <machine/resource.h>
+
+#include <dev/terasic/de4led/terasic_de4led.h>
+
+/*
+ * Nexus bus attachment for the 8-element LED on the Terasic DE-4 FPGA board,
+ * which is hooked up to the processor via a memory-mapped Avalon bus.
+ */
+static int
+terasic_de4led_nexus_probe(device_t dev)
+{
+
+	device_set_desc(dev, "Terasic DE4 8-element LED");
+	return (BUS_PROBE_DEFAULT);
+}
+
+static int
+terasic_de4led_nexus_attach(device_t dev)
+{
+	struct terasic_de4led_softc *sc;
+
+	sc = device_get_softc(dev);
+	sc->tdl_dev = dev;
+	sc->tdl_unit = device_get_unit(dev);
+	sc->tdl_rid = 0;
+	sc->tdl_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
+	    &sc->tdl_rid, RF_ACTIVE);
+	if (sc->tdl_res == NULL) {
+		device_printf(dev, "couldn't map memory\n");
+		return (ENXIO);
+	}
+	terasic_de4led_attach(sc);
+	return (0);
+}
+
+static int
+terasic_de4led_nexus_detach(device_t dev)
+{
+	struct terasic_de4led_softc *sc;
+
+	sc = device_get_softc(dev);
+	KASSERT(sc->tdl_res != NULL, ("%s: resources not allocated",
+	    __func__));
+	terasic_de4led_detach(sc);
+	bus_release_resource(dev, SYS_RES_MEMORY, sc->tdl_rid, sc->tdl_res);
+	return (0);
+}
+
+static device_method_t terasic_de4led_nexus_methods[] = {
+	DEVMETHOD(device_probe,		terasic_de4led_nexus_probe),
+	DEVMETHOD(device_attach,	terasic_de4led_nexus_attach),
+	DEVMETHOD(device_detach,	terasic_de4led_nexus_detach),
+	{ 0, 0 }
+};
+
+static driver_t terasic_de4led_nexus_driver = {
+	"terasic_de4led",
+	terasic_de4led_nexus_methods,
+	sizeof(struct terasic_de4led_softc),
+};
+
+static devclass_t terasic_de4led_devclass;
+
+DRIVER_MODULE(terasic_de4led, nexus, terasic_de4led_nexus_driver,
+    terasic_de4led_devclass, 0, 0);

Modified: head/sys/mips/beri/files.beri
==============================================================================
--- head/sys/mips/beri/files.beri	Sun Aug 26 05:20:32 2012	(r239708)
+++ head/sys/mips/beri/files.beri	Sun Aug 26 09:21:59 2012	(r239709)
@@ -2,6 +2,8 @@
 dev/altera/jtag_uart/altera_jtag_uart_cons.c	optional altera_jtag_uart
 dev/altera/jtag_uart/altera_jtag_uart_tty.c	optional altera_jtag_uart
 dev/altera/jtag_uart/altera_jtag_uart_nexus.c	optional altera_jtag_uart
+dev/terasic/de4led/terasic_de4led.c	optional terasic_de4led
+dev/terasic/de4led/terasic_de4led_nexus.c	optional terasic_de4led
 dev/terasic/mtl/terasic_mtl.c		optional terasic_mtl
 dev/terasic/mtl/terasic_mtl_nexus.c	optional terasic_mtl
 dev/terasic/mtl/terasic_mtl_pixel.c	optional terasic_mtl

Modified: head/sys/mips/conf/BERI_DE4.hints
==============================================================================
--- head/sys/mips/conf/BERI_DE4.hints	Sun Aug 26 05:20:32 2012	(r239708)
+++ head/sys/mips/conf/BERI_DE4.hints	Sun Aug 26 09:21:59 2012	(r239709)
@@ -25,6 +25,14 @@ hint.altera_sdcardc.0.maddr=0x7f008000
 hint.altera_sdcardc.0.msize=0x400
 
 #
+# On-board DE4 8-element LED
+#
+hint.terasic_de4led.0.at="nexus0"
+hint.terasic_de4led.0.maddr=0x7f006000
+hint.terasic_de4led.0.msize=1
+hint.terasic_de4led.0.de4led_0_cmd="f9"
+
+#
 # Terasic Multi-touch LCD (MTL), an optional feature in DE-4 configurations.
 #
 hint.terasic_mtl.0.at="nexus0"

Modified: head/sys/mips/conf/BERI_DE4_MDROOT
==============================================================================
--- head/sys/mips/conf/BERI_DE4_MDROOT	Sun Aug 26 05:20:32 2012	(r239708)
+++ head/sys/mips/conf/BERI_DE4_MDROOT	Sun Aug 26 09:21:59 2012	(r239709)
@@ -24,6 +24,7 @@ options 	ROOTDEVNAME=\"ufs:md0\"
 device		altera_avgen
 device		altera_jtag_uart
 device		altera_sdcard
+device		terasic_de4led
 device		terasic_mtl
 
 device		isf

Modified: head/sys/mips/conf/BERI_DE4_SDROOT
==============================================================================
--- head/sys/mips/conf/BERI_DE4_SDROOT	Sun Aug 26 05:20:32 2012	(r239708)
+++ head/sys/mips/conf/BERI_DE4_SDROOT	Sun Aug 26 09:21:59 2012	(r239709)
@@ -17,6 +17,7 @@ options 	ROOTDEVNAME=\"ufs:altera_sdcard
 device		altera_avgen
 device		altera_jtag_uart
 device		altera_sdcard
+device		terasic_de4led
 device		terasic_mtl
 
 device		isf



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201208260922.q7Q9M0S9096188>