diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2017-08-30 16:21:30 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2017-08-30 16:21:30 +0000 |
commit | 5134147f40d6aae44af3e8197e5c6359a1e26595 (patch) | |
tree | fa3344f17d0a39569c5e154bfb266e4aa721cef5 /sys/dev/fdt | |
parent | a5d7a0657ae63111ba20c74cb7ebee561b06d7b1 (diff) |
Decode pin mux configuration correctly in gpio(4) support code such that
we knock out the correct pins. Sptted by Artturi Alm.
Diffstat (limited to 'sys/dev/fdt')
-rw-r--r-- | sys/dev/fdt/sxipio.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/sys/dev/fdt/sxipio.c b/sys/dev/fdt/sxipio.c index 643226ecd19..cd1905a60ee 100644 --- a/sys/dev/fdt/sxipio.c +++ b/sys/dev/fdt/sxipio.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sxipio.c,v 1.3 2017/08/13 00:13:07 kettenis Exp $ */ +/* $OpenBSD: sxipio.c,v 1.4 2017/08/30 16:21:29 kettenis Exp $ */ /* * Copyright (c) 2010 Miodrag Vallat. * Copyright (c) 2013 Artturi Alm @@ -445,7 +445,8 @@ sxipio_attach_gpio(struct device *parent) struct gpiobus_attach_args gba; uint32_t reg; int port, pin; - int cfg, state; + int off, mux; + int state; int i; for (i = 0; i < sc->sc_npins; i++) { @@ -459,10 +460,11 @@ sxipio_attach_gpio(struct device *parent) /* Get pin configuration. */ reg = SXIREAD4(sc, SXIPIO_CFG(port, pin)); - cfg = (reg >> (pin & 0x7)) & 0x7; + off = (pin & 0x7) << 2; + mux = (reg >> off) & 0x7; /* Skip pins that have been assigned other functions. */ - if (cfg != SXIPIO_GPIO_IN && cfg != SXIPIO_GPIO_OUT) + if (mux != SXIPIO_GPIO_IN && mux != SXIPIO_GPIO_OUT) continue; /* Get pin state. */ @@ -472,7 +474,7 @@ sxipio_attach_gpio(struct device *parent) sc->sc_gpio_pins[port][pin].pin_caps = GPIO_PIN_INPUT | GPIO_PIN_OUTPUT; sc->sc_gpio_pins[port][pin].pin_flags = - GPIO_PIN_SET | (cfg ? GPIO_PIN_OUTPUT : GPIO_PIN_INPUT); + GPIO_PIN_SET | (mux ? GPIO_PIN_OUTPUT : GPIO_PIN_INPUT); sc->sc_gpio_pins[port][pin].pin_state = state; sc->sc_gpio_pins[port][pin].pin_num = pin; } |