From edababb17ba471dad42fd836db16c3eeb4a97336 Mon Sep 17 00:00:00 2001 From: Mark Kettenis Date: Sun, 8 May 2016 11:08:02 +0000 Subject: Add support for writing gpio pins. --- sys/dev/acpi/amltypes.h | 3 ++- sys/dev/acpi/bytgpio.c | 18 +++++++++++++++++- sys/dev/acpi/chvgpio.c | 21 ++++++++++++++++++++- sys/dev/acpi/dsdt.c | 12 ++++++------ 4 files changed, 45 insertions(+), 9 deletions(-) (limited to 'sys') 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 * @@ -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; @@ -268,6 +270,20 @@ bytgpio_read_pin(void *cookie, int pin) return (reg & BYTGPIO_PAD_VAL); } +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; @@ -306,6 +309,22 @@ chvgpio_read_pin(void *cookie, int pin) return (reg & CHVGPIO_PAD_CFG0_GPIORXSTATE); } +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 * @@ -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 -- cgit v1.2.3