summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2014-12-10 05:42:26 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2014-12-10 05:42:26 +0000
commit328ea310d58078d09d3d3d617abbec9157899c08 (patch)
tree1ae093fea45e6d6ab117ee4758636948881932dc
parent17615668abb24b17d317c1b146b23a87e97c3ea2 (diff)
Add skgpio(4) a driver for the Soekris net6501 GPIO and LEDs
from Matt Dainty.
-rw-r--r--share/man/man4/gpio.45
-rw-r--r--share/man/man4/isa.46
-rw-r--r--share/man/man4/man4.amd64/Makefile4
-rw-r--r--share/man/man4/man4.amd64/skgpio.457
-rw-r--r--share/man/man4/man4.i386/Makefile4
-rw-r--r--share/man/man4/man4.i386/skgpio.457
-rw-r--r--sys/arch/amd64/conf/files.amd647
-rw-r--r--sys/arch/i386/conf/files.i3867
-rw-r--r--sys/dev/isa/skgpio.c239
9 files changed, 376 insertions, 10 deletions
diff --git a/share/man/man4/gpio.4 b/share/man/man4/gpio.4
index c0e4489635a..e84efbcea99 100644
--- a/share/man/man4/gpio.4
+++ b/share/man/man4/gpio.4
@@ -1,4 +1,4 @@
-.\" $OpenBSD: gpio.4,v 1.22 2014/01/21 11:02:00 schwarze Exp $
+.\" $OpenBSD: gpio.4,v 1.23 2014/12/10 05:42:25 jsg Exp $
.\"
.\" Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org>
.\"
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: January 21 2014 $
+.Dd $Mdocdate: December 10 2014 $
.Dt GPIO 4
.Os
.Sh NAME
@@ -30,6 +30,7 @@
.Cd "gpio* at omgpio?" Pq armv7
.Cd "gpio* at pcagpio?"
.Cd "gpio* at pcaled?"
+.Cd "gpio* at skgpio?" Pq amd64, i386
.Cd "gpio0 at voyager?" Pq loongson
.Pp
.Fd #include <sys/types.h>
diff --git a/share/man/man4/isa.4 b/share/man/man4/isa.4
index 66eb2fa9cfb..1658a68a10d 100644
--- a/share/man/man4/isa.4
+++ b/share/man/man4/isa.4
@@ -1,4 +1,4 @@
-.\" $OpenBSD: isa.4,v 1.72 2014/03/18 22:36:31 miod Exp $
+.\" $OpenBSD: isa.4,v 1.73 2014/12/10 05:42:25 jsg Exp $
.\" $NetBSD: isa.4,v 1.19 2000/03/18 16:54:37 augustss Exp $
.\"
.\" Copyright (c) 2000 Theo de Raadt. All rights reserved.
@@ -31,7 +31,7 @@
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.Dd $Mdocdate: March 18 2014 $
+.Dd $Mdocdate: December 10 2014 $
.Dt ISA 4
.Os
.Sh NAME
@@ -222,6 +222,8 @@ PCMCIA controllers
PC (ISA) keyboard controller driver
.It Xr pcppi 4
PC (ISA) control and timer port driver
+.It Xr skgpio 4
+Soekris net6501 GPIO and LEDs driver
.It Xr vga 4
VGA graphics driver for wscons
.El
diff --git a/share/man/man4/man4.amd64/Makefile b/share/man/man4/man4.amd64/Makefile
index ae24f06c785..989521204d7 100644
--- a/share/man/man4/man4.amd64/Makefile
+++ b/share/man/man4/man4.amd64/Makefile
@@ -1,7 +1,7 @@
-# $OpenBSD: Makefile,v 1.15 2012/05/27 12:24:33 jsg Exp $
+# $OpenBSD: Makefile,v 1.16 2014/12/10 05:42:25 jsg Exp $
MAN= amdpcib.4 apm.4 autoconf.4 bios.4 cpu.4 intro.4 ioapic.4 \
- mem.4 mpbios.4 nvram.4 mtrr.4 pctr.4 tcpcib.4
+ mem.4 mpbios.4 nvram.4 mtrr.4 pctr.4 skgpio.4 tcpcib.4
MLINKS+= mem.4 kmem.4
MANSUBDIR=amd64
diff --git a/share/man/man4/man4.amd64/skgpio.4 b/share/man/man4/man4.amd64/skgpio.4
new file mode 100644
index 00000000000..b0c5744bc1e
--- /dev/null
+++ b/share/man/man4/man4.amd64/skgpio.4
@@ -0,0 +1,57 @@
+.\" $OpenBSD: skgpio.4,v 1.1 2014/12/10 05:42:25 jsg Exp $
+.\"
+.\" Copyright (c) 2014 Matt Dainty <matt@bodgit-n-scarper.com>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd $Mdocdate: December 10 2014 $
+.Dt SKGPIO 4 amd64
+.Os
+.Sh NAME
+.Nm skgpio
+.Nd Soekris net6501 GPIO and LEDs
+.Sh SYNOPSIS
+.Cd "skgpio0 at isa? port 0x680"
+.Cd "gpio* at skgpio?"
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for the GPIO and LEDs as implemented by the Xilinx
+Spartan FGPA integrated into the Soekris net6501 programmed with the default
+bitstream found in the BIOS.
+.Pp
+Two standard
+.Xr gpio 4
+interfaces are provided, one for the 16 real pins which can be configured as
+either inputs or outputs and another with 2 output-only pins that map
+to the error and ready LEDs respectively.
+Both may be used with
+.Xr gpioctl 8 .
+.Sh SEE ALSO
+.Xr gpio 4 ,
+.Xr intro 4 ,
+.Xr isa 4 ,
+.Xr gpioctl 8
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Ox 5.7 .
+.Sh AUTHORS
+The
+.Nm
+driver was written by
+.An Matt Dainty Aq matt@bodgit-n-scarper.com .
+.Sh BUGS
+If the Xilinx FPGA is programmed with a different bistream, the driver will
+likely not function.
diff --git a/share/man/man4/man4.i386/Makefile b/share/man/man4/man4.i386/Makefile
index 5d315619ecc..cef018c2baa 100644
--- a/share/man/man4/man4.i386/Makefile
+++ b/share/man/man4/man4.i386/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.72 2012/05/27 12:24:33 jsg Exp $
+# $OpenBSD: Makefile,v 1.73 2014/12/10 05:42:25 jsg Exp $
# from: @(#)Makefile 5.1 (Berkeley) 2/12/91
# Id: Makefile,v 1.4 1995/12/14 05:41:38 deraadt Exp $
@@ -7,7 +7,7 @@ MAN= amdpcib.4 amdmsr.4 apm.4 autoconf.4 bios.4 cpu.4 elansc.4 \
ichpcib.4 intro.4 ioapic.4 \
joy.4 le.4 lms.4 mem.4 mms.4 mpbios.4 mtrr.4 npx.4 nvram.4 \
pas.4 pcibios.4 pctr.4 piixpcib.4 sb.4 \
- sea.4 tcpcib.4 uha.4 wds.4 wdt.4 wss.4
+ sea.4 skgpio.4 tcpcib.4 uha.4 wds.4 wdt.4 wss.4
MLINKS+= mem.4 kmem.4
MANSUBDIR=i386
diff --git a/share/man/man4/man4.i386/skgpio.4 b/share/man/man4/man4.i386/skgpio.4
new file mode 100644
index 00000000000..d172dab8ac5
--- /dev/null
+++ b/share/man/man4/man4.i386/skgpio.4
@@ -0,0 +1,57 @@
+.\" $OpenBSD: skgpio.4,v 1.1 2014/12/10 05:42:25 jsg Exp $
+.\"
+.\" Copyright (c) 2014 Matt Dainty <matt@bodgit-n-scarper.com>
+.\"
+.\" Permission to use, copy, modify, and distribute this software for any
+.\" purpose with or without fee is hereby granted, provided that the above
+.\" copyright notice and this permission notice appear in all copies.
+.\"
+.\" THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+.\" WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+.\" MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+.\" ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+.\" WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+.\"
+.Dd $Mdocdate: December 10 2014 $
+.Dt SKGPIO 4 i386
+.Os
+.Sh NAME
+.Nm skgpio
+.Nd Soekris net6501 GPIO and LEDs
+.Sh SYNOPSIS
+.Cd "skgpio0 at isa? port 0x680"
+.Cd "gpio* at skgpio?"
+.Sh DESCRIPTION
+The
+.Nm
+driver provides support for the GPIO and LEDs as implemented by the Xilinx
+Spartan FGPA integrated into the Soekris net6501 programmed with the default
+bitstream found in the BIOS.
+.Pp
+Two standard
+.Xr gpio 4
+interfaces are provided, one for the 16 real pins which can be configured as
+either inputs or outputs and another with 2 output-only pins that map
+to the error and ready LEDs respectively.
+Both may be used with
+.Xr gpioctl 8 .
+.Sh SEE ALSO
+.Xr gpio 4 ,
+.Xr intro 4 ,
+.Xr isa 4 ,
+.Xr gpioctl 8
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Ox 5.7 .
+.Sh AUTHORS
+The
+.Nm
+driver was written by
+.An Matt Dainty Aq matt@bodgit-n-scarper.com .
+.Sh BUGS
+If the Xilinx FPGA is programmed with a different bistream, the driver will
+likely not function.
diff --git a/sys/arch/amd64/conf/files.amd64 b/sys/arch/amd64/conf/files.amd64
index 103b653baa0..d5a1c6e0c43 100644
--- a/sys/arch/amd64/conf/files.amd64
+++ b/sys/arch/amd64/conf/files.amd64
@@ -1,4 +1,4 @@
-# $OpenBSD: files.amd64,v 1.75 2014/12/04 21:03:50 tedu Exp $
+# $OpenBSD: files.amd64,v 1.76 2014/12/10 05:42:25 jsg Exp $
maxpartitions 16
maxusers 2 16 128
@@ -183,6 +183,11 @@ include "dev/pckbc/files.pckbc"
file arch/amd64/amd64/wscons_machdep.c wsdisplay
+# Soekris GPIO & LEDs driver
+device skgpio: gpiobus
+attach skgpio at isa
+file dev/isa/skgpio.c skgpio
+
pseudo-device pctr
file arch/amd64/amd64/pctr.c pctr needs-flag
diff --git a/sys/arch/i386/conf/files.i386 b/sys/arch/i386/conf/files.i386
index 86edfb58219..1962f5ed836 100644
--- a/sys/arch/i386/conf/files.i386
+++ b/sys/arch/i386/conf/files.i386
@@ -1,4 +1,4 @@
-# $OpenBSD: files.i386,v 1.219 2014/12/04 21:03:51 tedu Exp $
+# $OpenBSD: files.i386,v 1.220 2014/12/10 05:42:25 jsg Exp $
#
# new style config file for i386 architecture
#
@@ -210,6 +210,11 @@ include "dev/pckbc/files.pckbc"
attach ahc at isa with ahc_isa
file arch/i386/isa/ahc_isa.c ahc_isa
+# Soekris GPIO & LEDs driver
+device skgpio: gpiobus
+attach skgpio at isa
+file dev/isa/skgpio.c skgpio
+
# Pentium performance counters
pseudo-device pctr
file arch/i386/i386/pctr.c pctr needs-flag
diff --git a/sys/dev/isa/skgpio.c b/sys/dev/isa/skgpio.c
new file mode 100644
index 00000000000..af303ab4dd1
--- /dev/null
+++ b/sys/dev/isa/skgpio.c
@@ -0,0 +1,239 @@
+/* $OpenBSD: skgpio.c,v 1.1 2014/12/10 05:42:25 jsg Exp $ */
+
+/*
+ * Copyright (c) 2014 Matt Dainty <matt@bodgit-n-scarper.com>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
+ * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/*
+ * Soekris net6501 GPIO and LEDs as implemented by the onboard Xilinx FPGA
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/device.h>
+#include <sys/gpio.h>
+
+#include <machine/bus.h>
+#include <machine/intr.h>
+
+#include <dev/isa/isavar.h>
+
+#include <dev/gpio/gpiovar.h>
+
+#define SKGPIO_BASE 0x680 /* Base address of FPGA I/O */
+#define SKGPIO_IOSIZE 32 /* I/O region size */
+
+#define SKGPIO_NPINS 16 /* Number of Pins */
+#define SKGPIO_GPIO_INPUT 0x000 /* Current state of pins */
+#define SKGPIO_GPIO_OUTPUT 0x004 /* Set state of output pins */
+#define SKGPIO_GPIO_RESET 0x008 /* Reset output pins */
+#define SKGPIO_GPIO_SET 0x00c /* Set output pins */
+#define SKGPIO_GPIO_DIR 0x010 /* Direction, set for output */
+
+#define SKGPIO_NLEDS 2 /* Number of LEDs */
+#define SKGPIO_LED_ERROR 0x01c /* Offset to error LED */
+#define SKGPIO_LED_READY 0x01d /* Offset to ready LED */
+
+extern char *hw_vendor, *hw_prod;
+
+const u_int skgpio_led_offset[SKGPIO_NLEDS] = {
+ SKGPIO_LED_ERROR, SKGPIO_LED_READY
+};
+
+struct skgpio_softc {
+ struct device sc_dev;
+
+ bus_space_tag_t sc_iot;
+ bus_space_handle_t sc_ioh;
+
+ struct gpio_chipset_tag sc_gpio_gc;
+ gpio_pin_t sc_gpio_pins[SKGPIO_NPINS];
+
+ /* Fake GPIO device for the LEDs */
+ struct gpio_chipset_tag sc_led_gc;
+ gpio_pin_t sc_led_pins[SKGPIO_NLEDS];
+};
+
+int skgpio_match(struct device *, void *, void *);
+void skgpio_attach(struct device *, struct device *, void *);
+int skgpio_gpio_read(void *, int);
+void skgpio_gpio_write(void *, int, int);
+void skgpio_gpio_ctl(void *, int, int);
+int skgpio_led_read(void *, int);
+void skgpio_led_write(void *, int, int);
+void skgpio_led_ctl(void *, int, int);
+
+struct cfattach skgpio_ca = {
+ sizeof(struct skgpio_softc), skgpio_match, skgpio_attach
+};
+
+struct cfdriver skgpio_cd = {
+ NULL, "skgpio", DV_DULL
+};
+
+int
+skgpio_match(struct device *parent, void *match, void *aux)
+{
+ struct isa_attach_args *ia = aux;
+ bus_space_handle_t ioh;
+
+ if (strcmp(hw_vendor, "Soekris Engineering") ||
+ strcmp(hw_prod, "net6501"))
+ return (0);
+
+ if (ia->ia_iobase != SKGPIO_BASE || bus_space_map(ia->ia_iot,
+ ia->ia_iobase, SKGPIO_IOSIZE, 0, &ioh) != 0)
+ return (0);
+
+ bus_space_unmap(ia->ia_iot, ioh, SKGPIO_IOSIZE);
+ ia->ia_iosize = SKGPIO_IOSIZE;
+ ia->ipa_nio = 1;
+ ia->ipa_nmem = 0;
+ ia->ipa_nirq = 0;
+ ia->ipa_ndrq = 0;
+
+ return (1);
+}
+
+void
+skgpio_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct skgpio_softc *sc = (void *)self;
+ struct isa_attach_args *ia = aux;
+ struct gpiobus_attach_args gba1, gba2;
+ u_int data;
+ int i;
+
+ if (bus_space_map(ia->ia_iot, ia->ia_iobase, ia->ia_iosize, 0,
+ &sc->sc_ioh) != 0) {
+ printf(": can't map i/o space\n");
+ return;
+ }
+
+ printf("\n");
+
+ sc->sc_iot = ia->ia_iot;
+
+ data = bus_space_read_2(sc->sc_iot, sc->sc_ioh, SKGPIO_GPIO_DIR);
+
+ for (i = 0; i < SKGPIO_NPINS; i++) {
+ sc->sc_gpio_pins[i].pin_num = i;
+ sc->sc_gpio_pins[i].pin_caps = GPIO_PIN_INPUT |
+ GPIO_PIN_OUTPUT;
+ sc->sc_gpio_pins[i].pin_flags = (data & (1 << i)) ?
+ GPIO_PIN_OUTPUT : GPIO_PIN_INPUT;
+ sc->sc_gpio_pins[i].pin_state = skgpio_gpio_read(sc, i);
+ }
+
+ sc->sc_gpio_gc.gp_cookie = sc;
+ sc->sc_gpio_gc.gp_pin_read = skgpio_gpio_read;
+ sc->sc_gpio_gc.gp_pin_write = skgpio_gpio_write;
+ sc->sc_gpio_gc.gp_pin_ctl = skgpio_gpio_ctl;
+
+ gba1.gba_name = "gpio";
+ gba1.gba_gc = &sc->sc_gpio_gc;
+ gba1.gba_pins = sc->sc_gpio_pins;
+ gba1.gba_npins = SKGPIO_NPINS;
+
+ (void)config_found(&sc->sc_dev, &gba1, gpiobus_print);
+
+ for (i = 0; i < SKGPIO_NLEDS; i++) {
+ sc->sc_led_pins[i].pin_num = i;
+ sc->sc_led_pins[i].pin_caps = GPIO_PIN_OUTPUT;
+ sc->sc_led_pins[i].pin_flags = GPIO_PIN_OUTPUT;
+ sc->sc_led_pins[i].pin_state = skgpio_led_read(sc, i);
+ }
+
+ sc->sc_led_gc.gp_cookie = sc;
+ sc->sc_led_gc.gp_pin_read = skgpio_led_read;
+ sc->sc_led_gc.gp_pin_write = skgpio_led_write;
+ sc->sc_led_gc.gp_pin_ctl = skgpio_led_ctl;
+
+ gba2.gba_name = "gpio";
+ gba2.gba_gc = &sc->sc_led_gc;
+ gba2.gba_pins = sc->sc_led_pins;
+ gba2.gba_npins = SKGPIO_NLEDS;
+
+ (void)config_found(&sc->sc_dev, &gba2, gpiobus_print);
+}
+
+int
+skgpio_gpio_read(void *arg, int pin)
+{
+ struct skgpio_softc *sc = arg;
+ u_int16_t data;
+
+ data = bus_space_read_2(sc->sc_iot, sc->sc_ioh, SKGPIO_GPIO_INPUT);
+
+ return (data & (1 << pin)) ? GPIO_PIN_HIGH : GPIO_PIN_LOW;
+}
+
+void
+skgpio_gpio_write(void *arg, int pin, int value)
+{
+ struct skgpio_softc *sc = arg;
+ u_int16_t data;
+
+ data = bus_space_read_2(sc->sc_iot, sc->sc_ioh, SKGPIO_GPIO_INPUT);
+
+ if (value == GPIO_PIN_LOW)
+ data &= ~(1 << pin);
+ else if (value == GPIO_PIN_HIGH)
+ data |= (1 << pin);
+
+ bus_space_write_2(sc->sc_iot, sc->sc_ioh, SKGPIO_GPIO_OUTPUT, data);
+}
+
+void
+skgpio_gpio_ctl(void *arg, int pin, int flags)
+{
+ struct skgpio_softc *sc = arg;
+ u_int16_t data;
+
+ data = bus_space_read_2(sc->sc_iot, sc->sc_ioh, SKGPIO_GPIO_DIR);
+
+ if (flags & GPIO_PIN_INPUT)
+ data &= ~(1 << pin);
+ if (flags & GPIO_PIN_OUTPUT)
+ data |= (1 << pin);
+
+ bus_space_write_2(sc->sc_iot, sc->sc_ioh, SKGPIO_GPIO_DIR, data);
+}
+
+int
+skgpio_led_read(void *arg, int pin)
+{
+ struct skgpio_softc *sc = arg;
+ u_int8_t value;
+
+ value = bus_space_read_1(sc->sc_iot, sc->sc_ioh,
+ skgpio_led_offset[pin]);
+
+ return (value & 0x1) ? GPIO_PIN_HIGH : GPIO_PIN_LOW;
+}
+
+void
+skgpio_led_write(void *arg, int pin, int value)
+{
+ struct skgpio_softc *sc = arg;
+
+ bus_space_write_1(sc->sc_iot, sc->sc_ioh, skgpio_led_offset[pin],
+ value);
+}
+
+void
+skgpio_led_ctl(void *arg, int pin, int flags)
+{
+}