diff options
author | Alexander Yurchenko <grange@cvs.openbsd.org> | 2006-01-20 21:39:10 +0000 |
---|---|---|
committer | Alexander Yurchenko <grange@cvs.openbsd.org> | 2006-01-20 21:39:10 +0000 |
commit | c6e008387ae44436a39082ee794cc142c5037b1c (patch) | |
tree | 088ac4e660375bbb1d7f5ce93a6027b67e062a08 | |
parent | 810a9002232b4f8918839a5f0405b52e1c29ab45 (diff) |
Add support for driving SDA in push-pull + tri-state mode.
-rw-r--r-- | sys/dev/gpio/gpioiic.c | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/sys/dev/gpio/gpioiic.c b/sys/dev/gpio/gpioiic.c index 080fe6ea662..2d3a5580f33 100644 --- a/sys/dev/gpio/gpioiic.c +++ b/sys/dev/gpio/gpioiic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gpioiic.c,v 1.5 2006/01/18 21:47:08 grange Exp $ */ +/* $OpenBSD: gpioiic.c,v 1.6 2006/01/20 21:39:09 grange Exp $ */ /* * Copyright (c) 2006 Alexander Yurchenko <grange@openbsd.org> @@ -131,10 +131,13 @@ gpioiic_attach(struct device *parent, struct device *self, void *aux) if (caps & GPIO_PIN_OPENDRAIN) { printf(" open-drain"); sc->sc_sda |= GPIO_PIN_OPENDRAIN; - if (caps & GPIO_PIN_PULLUP) { - printf(" pull-up"); - sc->sc_sda |= GPIO_PIN_PULLUP; - } + } else if ((caps & GPIO_PIN_PUSHPULL) && (caps & GPIO_PIN_TRISTATE)) { + printf(" push-pull tri-state"); + sc->sc_sda |= GPIO_PIN_PUSHPULL; + } + if (caps & GPIO_PIN_PULLUP) { + printf(" pull-up"); + sc->sc_sda |= GPIO_PIN_PULLUP; } gpio_pin_ctl(sc->sc_gpio, &sc->sc_map, GPIOIIC_PIN_SDA, sc->sc_sda); @@ -256,11 +259,14 @@ void gpioiic_bb_set_dir(void *cookie, u_int32_t bits) { struct gpioiic_softc *sc = cookie; - - if (!(sc->sc_sda & GPIO_PIN_OPENDRAIN)) { - sc->sc_sda &= ~(GPIO_PIN_INPUT | GPIO_PIN_OUTPUT); - sc->sc_sda |= (bits & GPIOIIC_SDA ? GPIO_PIN_OUTPUT : - GPIO_PIN_INPUT); + int sda = sc->sc_sda; + + sda &= ~(GPIO_PIN_INPUT | GPIO_PIN_OUTPUT | GPIO_PIN_TRISTATE); + sda |= (bits & GPIOIIC_SDA ? GPIO_PIN_OUTPUT : GPIO_PIN_INPUT); + if ((sda & GPIO_PIN_PUSHPULL) && !(bits & GPIOIIC_SDA)) + sda |= GPIO_PIN_TRISTATE; + if (sc->sc_sda != sda) { + sc->sc_sda = sda; gpio_pin_ctl(sc->sc_gpio, &sc->sc_map, GPIOIIC_PIN_SDA, sc->sc_sda); } |