/* * Reset bus by setting SDA first and then SCL. * Must always be called with gpio bus locked. */ static void gpioiic_reset_bus(device_t dev) { struct gpioiic_softc *sc = device_get_softc(dev); GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->sda_pin, GPIO_PIN_INPUT); GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->scl_pin, GPIO_PIN_INPUT); }
static void gpioiic_setscl(device_t dev, int val) { struct gpioiic_softc *sc = device_get_softc(dev); if (val == 0) { GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, sc->scl_pin, 0); GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->scl_pin, GPIO_PIN_OUTPUT); } else { GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->scl_pin, GPIO_PIN_INPUT); } }
static void gpioiic_setsda(device_t dev, int val) { struct gpioiic_softc *sc = device_get_softc(dev); GPIOBUS_LOCK_BUS(sc->sc_busdev); if (val == 0) { GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, SDA_PIN, 0); GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, SDA_PIN, GPIO_PIN_OUTPUT); } else { GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, SDA_PIN, GPIO_PIN_INPUT); } GPIOBUS_UNLOCK_BUS(sc->sc_busdev); }
static int gpioiic_getsda(device_t dev) { struct gpioiic_softc *sc = device_get_softc(dev); unsigned int val; GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, sc->sda_pin, GPIO_PIN_INPUT); GPIOBUS_PIN_GET(sc->sc_busdev, sc->sc_dev, sc->sda_pin, &val); return ((int)val); }
static int gpioiic_getscl(device_t dev) { struct gpioiic_softc *sc = device_get_softc(dev); unsigned int val; GPIOBUS_LOCK_BUS(sc->sc_busdev); GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, SCL_PIN, GPIO_PIN_INPUT); GPIOBUS_PIN_GET(sc->sc_busdev, sc->sc_dev, SCL_PIN, &val); GPIOBUS_UNLOCK_BUS(sc->sc_busdev); return ((int)val); }
static void gpioled_control(void *priv, int onoff) { struct gpioled_softc *sc; sc = (struct gpioled_softc *)priv; GPIOLED_LOCK(sc); if (GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, GPIOLED_PIN, GPIO_PIN_OUTPUT) == 0) { if (sc->sc_invert) onoff = !onoff; GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, GPIOLED_PIN, onoff ? GPIO_PIN_HIGH : GPIO_PIN_LOW); } GPIOLED_UNLOCK(sc); }
static void gpioled_control(void *priv, int onoff) { int error; struct gpioled_softc *sc; sc = (struct gpioled_softc *)priv; GPIOLED_LOCK(sc); error = GPIOBUS_ACQUIRE_BUS(sc->sc_busdev, sc->sc_dev, GPIOBUS_DONTWAIT); if (error != 0) { GPIOLED_UNLOCK(sc); return; } error = GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, GPIOLED_PIN, GPIO_PIN_OUTPUT); if (error == 0) GPIOBUS_PIN_SET(sc->sc_busdev, sc->sc_dev, GPIOLED_PIN, onoff ? GPIO_PIN_HIGH : GPIO_PIN_LOW); GPIOBUS_RELEASE_BUS(sc->sc_busdev, sc->sc_dev); GPIOLED_UNLOCK(sc); }