Module Name:    src
Committed By:   christos
Date:           Thu Aug 11 09:05:43 UTC 2016

Modified Files:
        src/sys/dev/tc: files.tc tcdevs
Added Files:
        src/sys/dev/tc: slhci_tcu.c tcu.c

Log Message:
TURBOchannel usb/gpio driver from Felix Deichmann


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/dev/tc/files.tc
cvs rdiff -u -r0 -r1.1 src/sys/dev/tc/slhci_tcu.c src/sys/dev/tc/tcu.c
cvs rdiff -u -r1.21 -r1.22 src/sys/dev/tc/tcdevs

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/tc/files.tc
diff -u src/sys/dev/tc/files.tc:1.33 src/sys/dev/tc/files.tc:1.34
--- src/sys/dev/tc/files.tc:1.33	Wed Feb 27 18:49:11 2008
+++ src/sys/dev/tc/files.tc	Thu Aug 11 05:05:42 2016
@@ -1,4 +1,4 @@
-#	$NetBSD: files.tc,v 1.33 2008/02/27 23:49:11 matt Exp $
+#	$NetBSD: files.tc,v 1.34 2016/08/11 09:05:42 christos Exp $
 #
 # Config file and device description for machine-independent
 # TURBOchannel code.  Included by ports that need it.
@@ -100,3 +100,11 @@ file   dev/tc/pxg.c                    p
 device	sfbp: wsemuldisplaydev, rasops32, rasops8
 attach	sfbp at tc
 file	dev/tc/sfbplus.c		sfbp needs-flag
+
+# TC-USB
+device	tcu { } : gpiobus
+attach	tcu at tc
+file	dev/tc/tcu.c			tcu
+
+attach	slhci at tcu with slhci_tcu
+file	dev/tc/slhci_tcu.c		slhci_tcu needs-flag

Index: src/sys/dev/tc/tcdevs
diff -u src/sys/dev/tc/tcdevs:1.21 src/sys/dev/tc/tcdevs:1.22
--- src/sys/dev/tc/tcdevs:1.21	Wed Jan 21 09:34:18 2009
+++ src/sys/dev/tc/tcdevs	Thu Aug 11 05:05:42 2016
@@ -1,4 +1,4 @@
-$NetBSD: tcdevs,v 1.21 2009/01/21 14:34:18 jnemeth Exp $
+$NetBSD: tcdevs,v 1.22 2016/08/11 09:05:42 christos Exp $
 
 /*
  * Copyright (c) 1996 Christopher G. Demetriou
@@ -83,6 +83,7 @@ device	PMAZC-AA	tcds	53c94 TCDS Fast SCS
 device	PMTNV-AA	???	Non-volatile RAM option card
 device	T1D4PKT		ds	DECWRL Turbochannel T1
 device	T3PKT		tt	DECWRL Turbochannel T3
+device	TC-USB  	tcu	flxd TC-USB
 
 # the following entries are unconfirmed
 #device	PMAF-CA		fza	DEC FDDIcontroller 700C (DEFZA; copper)

Added files:

Index: src/sys/dev/tc/slhci_tcu.c
diff -u /dev/null src/sys/dev/tc/slhci_tcu.c:1.1
--- /dev/null	Thu Aug 11 05:05:43 2016
+++ src/sys/dev/tc/slhci_tcu.c	Thu Aug 11 05:05:42 2016
@@ -0,0 +1,101 @@
+/* $NetBSD: slhci_tcu.c,v 1.1 2016/08/11 09:05:42 christos Exp $ */
+
+/*-
+ * Copyright (c) 2016, Felix Deichmann
+ * All rights reserved.
+ *
+ * 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 COPYRIGHT HOLDERS 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 FOUNDATION 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.
+ */
+
+/*
+ * flxd TC-USB - TURBOchannel USB host option
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: slhci_tcu.c,v 1.1 2016/08/11 09:05:42 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+
+#include <sys/bus.h>
+
+#include <dev/usb/usb.h>
+#include <dev/usb/usbdi.h>
+#include <dev/usb/usbdivar.h>
+
+#include <dev/ic/sl811hsreg.h>
+#include <dev/ic/sl811hsvar.h>
+
+#include <dev/tc/tcvar.h>
+
+struct slhci_tcu_softc {
+	struct slhci_softc sc;
+};
+
+static int  slhci_tcu_match(device_t, cfdata_t, void *);
+static void slhci_tcu_attach(device_t, device_t, void *);
+
+CFATTACH_DECL_NEW(slhci_tcu, sizeof(struct slhci_tcu_softc),
+    slhci_tcu_match, slhci_tcu_attach, NULL, slhci_activate);
+
+static int
+slhci_tcu_match(device_t parent, cfdata_t cf, void *aux)
+{
+
+	/* Always match. */
+	return 1;
+}
+
+#define SLHCI_TCU_STRIDE	4
+#define SLHCI_TCU_IMAX		500 /* mA */
+
+static void
+slhci_tcu_attach(device_t parent, device_t self, void *aux)
+{
+	struct slhci_tcu_softc *tsc = device_private(self);
+	struct slhci_softc *sc = &tsc->sc;
+	struct tc_attach_args *ta = aux;
+	bus_space_tag_t iot = ta->ta_memt;
+	bus_space_handle_t ioh;
+	int error;
+
+	sc->sc_dev = self;
+	sc->sc_bus.ub_hcpriv = sc;
+
+	aprint_normal("\n");
+
+	error = bus_space_map(iot, ta->ta_addr,
+	    SLHCI_TCU_STRIDE * SL11_PORTSIZE, 0, &ioh);
+	if (error) {
+		aprint_error_dev(self, "bus_space_map() failed (%d)\n", error);
+		return;
+	}
+
+	slhci_preinit(sc, NULL, iot, ioh, SLHCI_TCU_IMAX, SLHCI_TCU_STRIDE);
+
+	tc_intr_establish(device_parent(parent), ta->ta_cookie, IPL_USB,
+	    slhci_intr, sc);
+
+	if (slhci_attach(sc))
+		aprint_error_dev(self, "slhci_attach() failed\n");
+}
Index: src/sys/dev/tc/tcu.c
diff -u /dev/null src/sys/dev/tc/tcu.c:1.1
--- /dev/null	Thu Aug 11 05:05:43 2016
+++ src/sys/dev/tc/tcu.c	Thu Aug 11 05:05:42 2016
@@ -0,0 +1,221 @@
+/* $NetBSD: tcu.c,v 1.1 2016/08/11 09:05:42 christos Exp $ */
+
+/*-
+ * Copyright (c) 2016, Felix Deichmann
+ * All rights reserved.
+ *
+ * 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 COPYRIGHT HOLDERS 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 FOUNDATION 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.
+ */
+
+/*
+ * flxd TC-USB - TURBOchannel USB host option
+ */
+
+#include <sys/cdefs.h>
+__KERNEL_RCSID(0, "$NetBSD: tcu.c,v 1.1 2016/08/11 09:05:42 christos Exp $");
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/gpio.h>
+
+#include <sys/bus.h>
+
+#include <dev/tc/tcvar.h>
+
+#include <dev/gpio/gpiovar.h>
+
+#include "gpio.h"
+#include "slhci_tcu.h"
+
+#define TCU_GPIO_NPINS	8
+#define TCU_GPIO_OFFS	0x80
+#define TCU_GPIO_SIZE	(3 * 4)
+#define TCU_GPIO_DIR	0x0
+#define TCU_GPIO_IN	0x4
+#define TCU_GPIO_OUT	0x8
+
+struct tcu_softc {
+#if NGPIO > 0
+	kmutex_t		sc_gpio_mtx;
+	struct gpio_chipset_tag	sc_gpio_gc;
+	gpio_pin_t		sc_gpio_pins[TCU_GPIO_NPINS];
+	bus_space_tag_t		sc_gpio_iot;
+	bus_space_handle_t	sc_gpio_ioh;
+#endif /* NGPIO > 0 */
+};
+
+static int  tcu_match(device_t, cfdata_t, void *);
+static void tcu_attach(device_t, device_t, void *);
+
+#if NSLHCI_TCU > 0
+static int  tcu_print(void *, const char *);
+#endif /* NSLHCI_TCU > 0 */
+#if NGPIO > 0
+static void tcu_gpio_attach(device_t, device_t, void *);
+static int  tcu_gpio_read(void *, int);
+static void tcu_gpio_write(void *, int, int);
+static void tcu_gpio_ctl(void *, int, int);
+#endif /* NGPIO > 0 */
+
+CFATTACH_DECL_NEW(tcu, sizeof(struct tcu_softc),
+    tcu_match, tcu_attach, NULL, NULL);
+
+static int
+tcu_match(device_t parent, cfdata_t cf, void *aux)
+{
+	struct tc_attach_args *ta = aux;
+
+	if (strncmp("TC-USB  ", ta->ta_modname, TC_ROM_LLEN))
+		return 0;
+
+	return 1;
+}
+
+static void
+tcu_attach(device_t parent, device_t self, void *aux)
+{
+
+	printf(": TC-USB\n");
+#if NSLHCI_TCU > 0
+	/* Attach slhci. */
+	(void)config_found_ia(self, "tcu", aux, tcu_print);
+#endif /* NSLHCI_TCU > 0 */
+#if NGPIO > 0
+	/* Attach gpio(bus). */
+	tcu_gpio_attach(parent, self, aux);
+#endif /* NGPIO > 0 */
+}
+
+#if NSLHCI_TCU > 0
+static int
+tcu_print(void *aux, const char *pnp)
+{
+
+	/* This function is only used for "slhci at tcu". */
+	if (pnp)
+		aprint_normal("slhci at %s", pnp);
+
+	return UNCONF;
+}
+#endif /* NSLHCI_TCU > 0 */
+
+#if NGPIO > 0
+static void
+tcu_gpio_attach(device_t parent, device_t self, void *aux)
+{
+	struct tcu_softc *sc = device_private(self);
+	struct tc_attach_args *ta = aux;
+	struct gpiobus_attach_args gba;
+	bus_space_tag_t iot = ta->ta_memt;
+	uint32_t v;
+	int error;
+
+	sc->sc_gpio_iot = iot;
+
+	error = bus_space_map(iot, ta->ta_addr + TCU_GPIO_OFFS, TCU_GPIO_SIZE,
+	    0, &sc->sc_gpio_ioh);
+	if (error) {
+		aprint_error_dev(self, "bus_space_map() failed (%d)\n", error);
+		return;
+	}
+
+	mutex_init(&sc->sc_gpio_mtx, MUTEX_DEFAULT, IPL_NONE);
+
+	v = bus_space_read_4(sc->sc_gpio_iot, sc->sc_gpio_ioh, TCU_GPIO_DIR);
+
+	for (int pin = 0; pin < TCU_GPIO_NPINS; pin++) {
+		sc->sc_gpio_pins[pin].pin_num = pin;
+		sc->sc_gpio_pins[pin].pin_caps = GPIO_PIN_INPUT |
+		    GPIO_PIN_OUTPUT;
+		sc->sc_gpio_pins[pin].pin_flags = (v & (UINT32_C(1) << pin)) ?
+		    GPIO_PIN_OUTPUT : GPIO_PIN_INPUT;
+		sc->sc_gpio_pins[pin].pin_state = tcu_gpio_read(sc, pin);
+	}
+
+	sc->sc_gpio_gc.gp_cookie = sc;
+	sc->sc_gpio_gc.gp_pin_read = tcu_gpio_read;
+	sc->sc_gpio_gc.gp_pin_write = tcu_gpio_write;
+	sc->sc_gpio_gc.gp_pin_ctl = tcu_gpio_ctl;
+
+	memset(&gba, 0, sizeof(gba));
+
+	gba.gba_gc = &sc->sc_gpio_gc;
+	gba.gba_pins = sc->sc_gpio_pins;
+	gba.gba_npins = TCU_GPIO_NPINS;
+
+	(void)config_found_ia(self, "gpiobus", &gba, gpiobus_print);
+}
+
+static int
+tcu_gpio_read(void *arg, int pin)
+{
+	struct tcu_softc *sc = arg;
+	uint32_t v;
+
+	mutex_enter(&sc->sc_gpio_mtx);
+	v = bus_space_read_4(sc->sc_gpio_iot, sc->sc_gpio_ioh, TCU_GPIO_IN);
+	mutex_exit(&sc->sc_gpio_mtx);
+
+	return (v & (UINT32_C(1) << pin)) ? GPIO_PIN_HIGH : GPIO_PIN_LOW;
+}
+
+static void
+tcu_gpio_write(void *arg, int pin, int val)
+{
+	struct tcu_softc *sc = arg;
+	uint32_t v;
+
+	mutex_enter(&sc->sc_gpio_mtx);
+
+	v = bus_space_read_4(sc->sc_gpio_iot, sc->sc_gpio_ioh, TCU_GPIO_OUT);
+
+	if (val == GPIO_PIN_LOW)
+		v &= ~(UINT32_C(1) << pin);
+	else if (val == GPIO_PIN_HIGH)
+		v |= (UINT32_C(1) << pin);
+
+	bus_space_write_4(sc->sc_gpio_iot, sc->sc_gpio_ioh, TCU_GPIO_OUT, v);
+
+	mutex_exit(&sc->sc_gpio_mtx);
+}
+
+static void
+tcu_gpio_ctl(void *arg, int pin, int flags)
+{
+	struct tcu_softc *sc = arg;
+	uint32_t v;
+
+	mutex_enter(&sc->sc_gpio_mtx);
+
+	v = bus_space_read_4(sc->sc_gpio_iot, sc->sc_gpio_ioh, TCU_GPIO_DIR);
+
+	if (flags & GPIO_PIN_INPUT)
+		v &= ~(UINT32_C(1) << pin);
+	if (flags & GPIO_PIN_OUTPUT)
+		v |= (UINT32_C(1) << pin);
+
+	bus_space_write_4(sc->sc_gpio_iot, sc->sc_gpio_ioh, TCU_GPIO_DIR, v);
+
+	mutex_exit(&sc->sc_gpio_mtx);
+}
+#endif /* NGPIO > 0 */

Reply via email to