summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorMark Kettenis <kettenis@cvs.openbsd.org>2016-05-08 11:08:02 +0000
committerMark Kettenis <kettenis@cvs.openbsd.org>2016-05-08 11:08:02 +0000
commitedababb17ba471dad42fd836db16c3eeb4a97336 (patch)
treeef382a3ce4270079d068d6e39b62559969c93260 /sys
parent466b594238d8c02209610e93543379e8e52f6e2a (diff)
Add support for writing gpio pins.
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/acpi/amltypes.h3
-rw-r--r--sys/dev/acpi/bytgpio.c18
-rw-r--r--sys/dev/acpi/chvgpio.c21
-rw-r--r--sys/dev/acpi/dsdt.c12
4 files changed, 45 insertions, 9 deletions
diff --git a/sys/dev/acpi/amltypes.h b/sys/dev/acpi/amltypes.h
index 1f9bbedfa14..ad90260070a 100644
--- a/sys/dev/acpi/amltypes.h
+++ b/sys/dev/acpi/amltypes.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: amltypes.h,v 1.44 2016/05/08 10:09:25 kettenis Exp $ */
+/* $OpenBSD: amltypes.h,v 1.45 2016/05/08 11:08:01 kettenis Exp $ */
/*
* Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org>
*
@@ -367,6 +367,7 @@ struct acpi_pci {
struct acpi_gpio {
void *cookie;
int (*read_pin)(void *, int);
+ void (*write_pin)(void *, int, int);
void (*intr_establish)(void *, int, int, int (*)(void *), void *);
};
diff --git a/sys/dev/acpi/bytgpio.c b/sys/dev/acpi/bytgpio.c
index 5b43e3b5902..611285f19a6 100644
--- a/sys/dev/acpi/bytgpio.c
+++ b/sys/dev/acpi/bytgpio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bytgpio.c,v 1.10 2016/05/08 09:30:23 kettenis Exp $ */
+/* $OpenBSD: bytgpio.c,v 1.11 2016/05/08 11:08:01 kettenis Exp $ */
/*
* Copyright (c) 2016 Mark Kettenis
*
@@ -106,6 +106,7 @@ const int byt_sus_pins[] = {
int bytgpio_parse_resources(union acpi_resource *, void *);
int bytgpio_read_pin(void *, int);
+void bytgpio_write_pin(void *, int, int);
void bytgpio_intr_establish(void *, int, int, int (*)(), void *);
int bytgpio_intr(void *);
@@ -197,6 +198,7 @@ bytgpio_attach(struct device *parent, struct device *self, void *aux)
sc->sc_gpio.cookie = sc;
sc->sc_gpio.read_pin = bytgpio_read_pin;
+ sc->sc_gpio.write_pin = bytgpio_write_pin;
sc->sc_gpio.intr_establish = bytgpio_intr_establish;
sc->sc_node->gpio = &sc->sc_gpio;
@@ -269,6 +271,20 @@ bytgpio_read_pin(void *cookie, int pin)
}
void
+bytgpio_write_pin(void *cookie, int pin, int value)
+{
+ struct bytgpio_softc *sc = cookie;
+ uint32_t reg;
+
+ reg = bus_space_read_4(sc->sc_memt, sc->sc_memh, sc->sc_pins[pin] * 16 + 8);
+ if (value)
+ reg |= BYTGPIO_PAD_VAL;
+ else
+ reg &= ~BYTGPIO_PAD_VAL;
+ bus_space_write_4(sc->sc_memt, sc->sc_memh, sc->sc_pins[pin] * 16 + 8, reg);
+}
+
+void
bytgpio_intr_establish(void *cookie, int pin, int flags,
int (*func)(void *), void *arg)
{
diff --git a/sys/dev/acpi/chvgpio.c b/sys/dev/acpi/chvgpio.c
index 0691ace2b9f..2997a64cfaa 100644
--- a/sys/dev/acpi/chvgpio.c
+++ b/sys/dev/acpi/chvgpio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: chvgpio.c,v 1.3 2016/05/08 10:03:14 kettenis Exp $ */
+/* $OpenBSD: chvgpio.c,v 1.4 2016/05/08 11:08:01 kettenis Exp $ */
/*
* Copyright (c) 2016 Mark Kettenis
*
@@ -31,6 +31,7 @@
#define CHVGPIO_PAD_CFG1 0x4404
#define CHVGPIO_PAD_CFG0_GPIORXSTATE 0x00000001
+#define CHVGPIO_PAD_CFG0_GPIOTXSTATE 0x00000002
#define CHVGPIO_PAD_CFG0_INTSEL_MASK 0xf0000000
#define CHVGPIO_PAD_CFG0_INTSEL_SHIFT 28
@@ -143,6 +144,7 @@ const int chv_southeast_pins[] = {
int chvgpio_parse_resources(union acpi_resource *, void *);
int chvgpio_check_pin(struct chvgpio_softc *, int);
int chvgpio_read_pin(void *, int);
+void chvgpio_write_pin(void *, int, int);
void chvgpio_intr_establish(void *, int, int, int (*)(), void *);
int chvgpio_intr(void *);
@@ -231,6 +233,7 @@ chvgpio_attach(struct device *parent, struct device *self, void *aux)
sc->sc_gpio.cookie = sc;
sc->sc_gpio.read_pin = chvgpio_read_pin;
+ sc->sc_gpio.write_pin = chvgpio_write_pin;
sc->sc_gpio.intr_establish = chvgpio_intr_establish;
sc->sc_node->gpio = &sc->sc_gpio;
@@ -307,6 +310,22 @@ chvgpio_read_pin(void *cookie, int pin)
}
void
+chvgpio_write_pin(void *cookie, int pin, int value)
+{
+ struct chvgpio_softc *sc = cookie;
+ uint32_t reg;
+
+ KASSERT(chvgpio_check_pin(sc, pin) == 0);
+
+ reg = chvgpio_read_pad_cfg0(sc, pin);
+ if (value)
+ reg |= CHVGPIO_PAD_CFG0_GPIOTXSTATE;
+ else
+ reg &= ~CHVGPIO_PAD_CFG0_GPIOTXSTATE;
+ chvgpio_write_pad_cfg0(sc, pin, reg);
+}
+
+void
chvgpio_intr_establish(void *cookie, int pin, int flags,
int (*func)(void *), void *arg)
{
diff --git a/sys/dev/acpi/dsdt.c b/sys/dev/acpi/dsdt.c
index 60e659e1383..a39e6c6ba9e 100644
--- a/sys/dev/acpi/dsdt.c
+++ b/sys/dev/acpi/dsdt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dsdt.c,v 1.222 2016/05/07 18:08:27 kettenis Exp $ */
+/* $OpenBSD: dsdt.c,v 1.223 2016/05/08 11:08:01 kettenis Exp $ */
/*
* Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org>
*
@@ -2355,12 +2355,12 @@ aml_rwgpio(struct aml_value *conn, int bpos, int blen, struct aml_value *val,
aml_die("Could not find GpioIo pin");
if (mode == ACPI_IOWRITE) {
- printf("GpioIO write unimplemented\n");
- return;
+ v = aml_val2int(val);
+ node->gpio->write_pin(node->gpio->cookie, pin, v);
+ } else {
+ v = node->gpio->read_pin(node->gpio->cookie, pin);
+ _aml_setvalue(val, AML_OBJTYPE_INTEGER, v, NULL);
}
-
- v = node->gpio->read_pin(node->gpio->cookie, pin);
- _aml_setvalue(val, AML_OBJTYPE_INTEGER, v, NULL);
}
void