예제 #1
0
파일: gpio_pad_det.c 프로젝트: jksim/nuttx
static int gpio_pad_detect_probe(struct device *dev)
{
    struct device_resource *r;
    int retval;

    g_info = zalloc(sizeof(*g_info));
    if (!g_info) {
        dbg("failed to allocate memory\n");
        return -ENOMEM;
    }

    r = device_resource_get_by_name(dev, DEVICE_RESOURCE_TYPE_GPIO, "pad_det");
    if (!r) {
        r = device_resource_get_by_name(dev, DEVICE_RESOURCE_TYPE_GPIO, "pad_det_n");
        if (!r) {
            dbg("failed to get pad det gpio\n");
            retval = -EINVAL;
            goto probe_err;
        } else
            g_info->active_low = true;
    } else
        g_info->active_low = false;

    g_info->gpio = r->start;
    gpio_direction_in(g_info->gpio);

    return 0;

probe_err:
    free(g_info);
    return retval;
}
예제 #2
0
/**
 * @brief Probe SPI device
 *
 * This function is called by the system to register the driver when the system
 * boots up. This function allocates memory for the private SPI device
 * information, and then sets up the hardware resource and interrupt handler.
 *
 * @param dev pointer to structure of device data
 * @return 0 on success, negative errno on error
 */
static int tsb_spi_dev_probe(struct device *dev)
{
    struct tsb_spi_dev_info *info;
    struct device_resource *r;
    int ret = 0;

    if (tsb_get_rev_id() == tsb_rev_es2) {
        return -ENODEV;
    }

    if (!dev) {
        return -EINVAL;
    }

    info = zalloc(sizeof(*info));
    if (!info) {
        return -ENOMEM;
    }

    /* get register data from resource block */
    r = device_resource_get_by_name(dev, DEVICE_RESOURCE_TYPE_REG, "reg_base");
    if (!r) {
        ret = -EINVAL;
        goto err_freemem;
    }

    info->reg_base = (uint32_t)r->start;
    info->state = TSB_SPI_STATE_CLOSED;
    info->spi_pmstate = PM_SLEEP;
    device_set_private(dev, info);
    spi_dev = dev;

    sem_init(&info->bus, 0, 1);
    sem_init(&info->lock, 0, 1);
    sem_init(&info->xfer_completed, 0, 0);

    ret = tsb_pm_register(tsb_spi_pm_prepare, tsb_spi_pm_notify, dev);
    if (ret) {
        goto err_freemem;
    }
    return 0;

err_freemem:
    free(info);
    return ret;
}
예제 #3
0
파일: gpio_wrls_tx.c 프로젝트: jksim/nuttx
static int gpio_wrls_tx_probe(struct device *dev)
{
    struct gpio_wrls_tx_info *info = zalloc(sizeof(*info));
    struct device_resource *r;

    if (!info) {
        dbg("failed to allocate memory\n");
        return -ENOMEM;
    }

    r = device_resource_get_by_name(dev, DEVICE_RESOURCE_TYPE_GPIO,
                                    "wrls_tx_cntrl");
    if (!r) {
        dbg("failed to get wrls_tx_cntrl gpio\n");
        return -EINVAL;
    }

    info->gpio = r->start;
    gpio_direction_out(info->gpio, WCHG_TX_ENABLE);

    device_set_private(dev, info);
    return 0;
}