static int gpioiic_callback(device_t dev, int index, caddr_t data) { struct gpioiic_softc *sc = device_get_softc(dev); int error = 0; switch (index) { case IIC_REQUEST_BUS: GPIOBUS_LOCK_BUS(sc->sc_busdev); GPIOBUS_ACQUIRE_BUS(sc->sc_busdev, sc->sc_dev); GPIOBUS_UNLOCK_BUS(sc->sc_busdev); break; case IIC_RELEASE_BUS: GPIOBUS_LOCK_BUS(sc->sc_busdev); GPIOBUS_RELEASE_BUS(sc->sc_busdev, sc->sc_dev); GPIOBUS_UNLOCK_BUS(sc->sc_busdev); break; default: error = EINVAL; } return (error); }
static int gpioiic_getsda(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, SDA_PIN, GPIO_PIN_INPUT); GPIOBUS_PIN_GET(sc->sc_busdev, sc->sc_dev, SDA_PIN, &val); GPIOBUS_UNLOCK_BUS(sc->sc_busdev); return ((int)val); }
static int gpioiic_reset(device_t dev, u_char speed, u_char addr, u_char *oldaddr) { struct gpioiic_softc *sc = device_get_softc(dev); GPIOBUS_LOCK_BUS(sc->sc_busdev); GPIOBUS_ACQUIRE_BUS(sc->sc_busdev, sc->sc_dev); gpioiic_reset_bus(sc->sc_dev); GPIOBUS_RELEASE_BUS(sc->sc_busdev, sc->sc_dev); GPIOBUS_UNLOCK_BUS(sc->sc_busdev); return (IIC_ENOADDR); }
static void gpioiic_setscl(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, SCL_PIN, 0); GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, SCL_PIN, GPIO_PIN_OUTPUT); } else { GPIOBUS_PIN_SETFLAGS(sc->sc_busdev, sc->sc_dev, SCL_PIN, GPIO_PIN_INPUT); } GPIOBUS_UNLOCK_BUS(sc->sc_busdev); }