Exemplo n.º 1
0
/**
 * Uninitialise an I2C device
 */
int up_i2cuninitialize(struct i2c_dev_s *dev)
{
    irqstate_t flags;

    i2cvdbg("Deinit I2C port\n");

    flags = irqsave();

    if (!refcount)
        goto out;

    if (--refcount)
        goto out;

    tsb_release_pinshare(TSB_PIN_GPIO21 | TSB_PIN_GPIO22);

    /* Detach Interrupt Handler */
    irq_detach(TSB_IRQ_I2C);

    wd_delete(g_timeout);

out:
    irqrestore(flags);
    return 0;
}
Exemplo n.º 2
0
/**
 * @brief Hardware de-initialization
 *
 * The function will restore original pinshare value and deactivate GPIO pins.
 *
 * @param dev pointer to structure of device data
 * @return 0 on success, negative errno on error
 */
static int tsb_spi_hw_deinit(struct device *dev) {
    struct tsb_spi_info *info = NULL;
    uint32_t pinshare = 0;
    int i = 0;

    /* check input parameters */
    if (!dev || !device_get_private(dev)) {
        return -EINVAL;
    }

    info = device_get_private(dev);

    /* release GPIO pins */
    for (i = 0; i < info->caps.csnum; i++) {
        gpio_deactivate(info->chipselect[i]);
    }
    gpio_deactivate(SPI_SDO);
    gpio_deactivate(SPI_SDI);
    gpio_deactivate(SPI_SCK);

    /* restore pinshare#5 setting */
    pinshare = tsb_get_pinshare() & TSB_PIN_GPIO10; /* current setting */
    if ((info->pinshare & TSB_PIN_GPIO10)) {
        if (!pinshare) {
            tsb_set_pinshare(TSB_PIN_GPIO10);
        }
    } else {
        if (pinshare) {
            tsb_clr_pinshare(TSB_PIN_GPIO10);
        }
    }

    tsb_release_pinshare(TSB_PIN_GPIO10);

    return 0;
}