summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Yurchenko <grange@cvs.openbsd.org>2006-03-26 20:19:55 +0000
committerAlexander Yurchenko <grange@cvs.openbsd.org>2006-03-26 20:19:55 +0000
commitee2d921ca303adcd8f3ba8e406cf890bfeb83b50 (patch)
treebc5e3780c9524f7a019ae1aa3a0e4fa15f74d613
parent451027a5515cb6c06d9cbd9d766be3a4d72bde95 (diff)
Support for accesing 8-bit ISA I/O throught the gpio(4)
framework. Allows to use stupid GPIO device on the Acrosser AR-B1662 board. Work by form@.
-rw-r--r--share/man/man4/Makefile5
-rw-r--r--share/man/man4/gpio.43
-rw-r--r--share/man/man4/isagpio.459
-rw-r--r--sys/arch/i386/conf/GENERIC5
-rw-r--r--sys/dev/isa/files.isa7
-rw-r--r--sys/dev/isa/isagpio.c154
6 files changed, 228 insertions, 5 deletions
diff --git a/share/man/man4/Makefile b/share/man/man4/Makefile
index 42d255f395c..2bdea8f685d 100644
--- a/share/man/man4/Makefile
+++ b/share/man/man4/Makefile
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile,v 1.347 2006/03/24 10:31:21 jsg Exp $
+# $OpenBSD: Makefile,v 1.348 2006/03/26 20:19:54 grange Exp $
MAN= aac.4 ac97.4 acphy.4 acpi.4 acpihpet.4 acpitimer.4 \
adc.4 addcom.4 admcts.4 admlc.4 admtemp.4 \
@@ -18,7 +18,8 @@ MAN= aac.4 ac97.4 acphy.4 acpi.4 acpihpet.4 acpitimer.4 \
hifn.4 hil.4 hilid.4 hilkbd.4 hilms.4 hme.4 hotplug.4 hsq.4 \
ichiic.4 ichwdt.4 icmp.4 icmp6.4 icsphy.4 idp.4 ifmedia.4 \
iha.4 iic.4 inet.4 inet6.4 inphy.4 iop.4 iophy.4 ioprbs.4 \
- iopsp.4 ip.4 ip6.4 ipcomp.4 ipmi.4 ipsec.4 ipw.4 isa.4 isapnp.4 \
+ iopsp.4 ip.4 ip6.4 ipcomp.4 ipmi.4 ipsec.4 ipw.4 \
+ isa.4 isagpio.4 isapnp.4 \
ises.4 isp.4 it.4 iwi.4 ixgb.4 ksyms.4 kue.4 lc.4 lge.4 lkm.4 lm.4 \
lmc.4 lmenv.4 lmtemp.4 lo.4 lofn.4 lpt.4 lxtphy.4 luphy.4 \
maestro.4 maxds.4 maxtmp.4 midi.4 \
diff --git a/share/man/man4/gpio.4 b/share/man/man4/gpio.4
index eabd134450a..a2949111899 100644
--- a/share/man/man4/gpio.4
+++ b/share/man/man4/gpio.4
@@ -1,4 +1,4 @@
-.\" $OpenBSD: gpio.4,v 1.5 2004/11/23 09:39:29 reyk Exp $
+.\" $OpenBSD: gpio.4,v 1.6 2006/03/26 20:19:54 grange Exp $
.\"
.\" Copyright (c) 2004 Alexander Yurchenko <grange@openbsd.org>
.\"
@@ -150,6 +150,7 @@ file.
.Xr ath 4 ,
.Xr elansc 4 ,
.Xr gscpcib 4 ,
+.Xr isagpio.4 ,
.Xr nsclpcsio 4 ,
.Xr gpioctl 8
.Sh HISTORY
diff --git a/share/man/man4/isagpio.4 b/share/man/man4/isagpio.4
new file mode 100644
index 00000000000..b87cc39707e
--- /dev/null
+++ b/share/man/man4/isagpio.4
@@ -0,0 +1,59 @@
+.\" $OpenBSD: isagpio.4,v 1.1 2006/03/26 20:19:54 grange Exp $
+.\"
+.\" Copyright (c) 2006 Oleg Safiullin <form@pdp-11.org.ru>
+.\" 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 unmodified, 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.
+.\"
+.Dd March 25, 2006
+.Dt ISAGPIO 4
+.Os
+.Sh NAME
+.Nm isagpio
+.Nd ISA I/O mapped as GPIO
+.Sh SYNOPSIS
+.Cd "isagpio0 at isa? port 0x78"
+.Cd "isagpio1 at isa? port 0x80"
+.Cd "gpio* at isagpio?"
+.Sh DESCRIPTION
+The
+.Nm
+driver allows to access 8-bit ISA I/O space through the
+.Xr gpio 4
+framework.
+Each bit represents one GPIO pin.
+.Sh SEE ALSO
+.Xr gpio 4 ,
+.Xr intro 4 ,
+.Xr isa 4 ,
+.Xr gpioctl 8
+.Sh HISTORY
+The
+.Nm
+driver first appeared in
+.Ox 4.0 .
+.Sh AUTHORS
+The
+.Nm
+driver was written by
+.An Oleg Safiullin Aq form@pdp-11.org.ru .
diff --git a/sys/arch/i386/conf/GENERIC b/sys/arch/i386/conf/GENERIC
index 08ffb417937..3d84d229cd8 100644
--- a/sys/arch/i386/conf/GENERIC
+++ b/sys/arch/i386/conf/GENERIC
@@ -1,4 +1,4 @@
-# $OpenBSD: GENERIC,v 1.477 2006/03/24 10:39:08 jsg Exp $
+# $OpenBSD: GENERIC,v 1.478 2006/03/26 20:19:53 grange Exp $
#
# For further information on compiling OpenBSD kernels, see the config(8)
# man page.
@@ -140,6 +140,9 @@ asbtm* at iic? # Asus ASB100
wbenv* at iic? # Winbond W83L784R/W83L785R/W83L785TS-L
glenv* at iic? # Genesys Logic GL518SM
+#isagpio0 at isa? port 0x78 # ISA I/O mapped as GPIO
+#isagpio1 at isa? port 0x80
+
# ISA PCMCIA controllers
#option PCMCIAVERBOSE
pcic0 at isa? port 0x3e0 iomem 0xd0000 iosiz 0x10000
diff --git a/sys/dev/isa/files.isa b/sys/dev/isa/files.isa
index 71d74c49453..4bfb490ca32 100644
--- a/sys/dev/isa/files.isa
+++ b/sys/dev/isa/files.isa
@@ -1,4 +1,4 @@
-# $OpenBSD: files.isa,v 1.93 2006/01/28 11:25:17 kettenis Exp $
+# $OpenBSD: files.isa,v 1.94 2006/03/26 20:19:53 grange Exp $
# $NetBSD: files.isa,v 1.21 1996/05/16 03:45:55 mycroft Exp $
#
# Config file and device description for machine-independent ISA code.
@@ -403,6 +403,11 @@ device aps
attach aps at isa
file dev/isa/aps.c aps
+# ISA I/O mapped as GPIO
+device isagpio: gpiobus
+attach isagpio at isa
+file dev/isa/isagpio.c isagpio
+
#
# PCMCIA PCIC (i82365SL and compatibles):
#
diff --git a/sys/dev/isa/isagpio.c b/sys/dev/isa/isagpio.c
new file mode 100644
index 00000000000..63b7485a2d4
--- /dev/null
+++ b/sys/dev/isa/isagpio.c
@@ -0,0 +1,154 @@
+/* $OpenBSD: isagpio.c,v 1.1 2006/03/26 20:19:53 grange Exp $ */
+
+/*
+ * Copyright (c) 2006 Oleg Safiullin <form@pdp-11.org.ru>
+ * 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 unmodified, 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/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 ISAGPIO_IOSIZE 1
+#define ISAGPIO_NPINS 8
+
+struct isagpio_softc {
+ struct device sc_dev;
+
+ bus_space_tag_t sc_iot;
+ bus_space_handle_t sc_ioh;
+
+ struct gpio_chipset_tag sc_gpio_gc;
+ struct gpio_pin sc_gpio_pins[ISAGPIO_NPINS];
+ u_int8_t sc_gpio_mask;
+};
+
+int isagpio_match(struct device *, void *, void *);
+void isagpio_attach(struct device *, struct device *, void *);
+int isagpio_pin_read(void *, int);
+void isagpio_pin_write(void *, int, int);
+void isagpio_pin_ctl(void *, int, int);
+
+struct cfattach isagpio_ca = {
+ sizeof(struct isagpio_softc), isagpio_match, isagpio_attach
+};
+
+struct cfdriver isagpio_cd = {
+ NULL, "isagpio", DV_DULL
+};
+
+int
+isagpio_match(struct device *parent, void *match, void *aux)
+{
+ struct isa_attach_args *ia = aux;
+ bus_space_handle_t ioh;
+
+ if (bus_space_map(ia->ia_iot, ia->ia_iobase, ISAGPIO_IOSIZE, 0, &ioh))
+ return (0);
+
+ bus_space_unmap(ia->ia_iot, ioh, ISAGPIO_IOSIZE);
+ ia->ia_iosize = ISAGPIO_IOSIZE;
+ ia->ipa_nio = 1;
+ ia->ipa_nmem = 0;
+ ia->ipa_nirq = 0;
+ ia->ipa_ndrq = 0;
+
+ return (1);
+}
+
+void
+isagpio_attach(struct device *parent, struct device *self, void *aux)
+{
+ struct isagpio_softc *sc = (void *)self;
+ struct isa_attach_args *ia = aux;
+ struct gpiobus_attach_args gba;
+ u_int16_t mask;
+ int i;
+
+ if (bus_space_map(ia->ia_iot, ia->ia_iobase, ia->ia_iosize, 0,
+ &sc->sc_ioh) != 0) {
+ printf(": couldn't map I/O space\n");
+ return;
+ }
+
+ printf("\n");
+
+ sc->sc_iot = ia->ia_iot;
+ sc->sc_gpio_mask = 0;
+
+ for (i = 0, mask = 0x01; i < ISAGPIO_NPINS; mask <<= 1, 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_state = 0;
+ }
+
+ sc->sc_gpio_gc.gp_cookie = sc;
+ sc->sc_gpio_gc.gp_pin_read = isagpio_pin_read;
+ sc->sc_gpio_gc.gp_pin_write = isagpio_pin_write;
+ sc->sc_gpio_gc.gp_pin_ctl = isagpio_pin_ctl;
+
+ gba.gba_name = "gpio";
+ gba.gba_gc = &sc->sc_gpio_gc;
+ gba.gba_pins = sc->sc_gpio_pins;
+ gba.gba_npins = ISAGPIO_NPINS;
+
+ (void)config_found(&sc->sc_dev, &gba, gpiobus_print);
+}
+
+int
+isagpio_pin_read(void *arg, int pin)
+{
+ struct isagpio_softc *sc = arg;
+ u_int8_t mask;
+
+ mask = bus_space_read_1(sc->sc_iot, sc->sc_ioh, 0);
+ return ((mask >> pin) & 0x0001);
+}
+
+void
+isagpio_pin_write(void *arg, int pin, int value)
+{
+ struct isagpio_softc *sc = arg;
+
+ if (value == GPIO_PIN_LOW)
+ sc->sc_gpio_mask &= ~(0x01 << pin);
+ else if (value == GPIO_PIN_HIGH)
+ sc->sc_gpio_mask |= 0x01 << pin;
+ bus_space_write_1(sc->sc_iot, sc->sc_ioh, 0, sc->sc_gpio_mask);
+}
+
+void
+isagpio_pin_ctl(void *arg, int pin, int flags)
+{
+}