dts使用学习

dts使用学习

gpio_keys_get_devtree_pdata(struct device *dev)
{
    struct device_node *node, *pp;
    struct gpio_keys_platform_data *pdata;
    struct gpio_keys_button *button;
    int error;
    int nbuttons;
    int i;
    char *input_name = NULL;
    int ret = -1;

    node = dev->of_node;
    if (!node) {
        error = -ENODEV;
        goto err_out;
    }

    nbuttons = of_get_child_count(node);
    if (nbuttons == 0) {
        error = -ENODEV;
        goto err_out;
    }

    pdata = kzalloc(sizeof(*pdata) + nbuttons * (sizeof *button),
            GFP_KERNEL);
    if (!pdata) {
        error = -ENOMEM;
        goto err_out;
    }

    pdata->buttons = (struct gpio_keys_button *)(pdata + 1);
    pdata->nbuttons = nbuttons;

    pdata->rep = !!of_get_property(node, "autorepeat", NULL);

    ret = of_property_read_string(node, "input-name", &input_name);
    if (0 == ret) {
        pdata->name = input_name;
        PRINT_INFO("input-name=\"%s\"\n", input_name);
    }
    else
        PRINT_WARN("failed to get input-name\n");

    i = 0;
    for_each_child_of_node(node, pp) {
        int gpio;
        enum of_gpio_flags flags;

        if (!of_find_property(pp, "gpios", NULL)) {
            pdata->nbuttons--;
            dev_warn(dev, "Found button without gpios\n");
            continue;
        }

        gpio = of_get_gpio_flags(pp, 0, &flags);
        if (gpio < 0) {
            error = gpio;
            if (error != -EPROBE_DEFER)
                dev_err(dev,
                    "Failed to get gpio flags, error: %d\n",
                    error);
            goto err_free_pdata;
        }

        button = &pdata->buttons[i++];

        button->gpio = gpio;
        button->active_low = flags & OF_GPIO_ACTIVE_LOW;

        if (of_property_read_u32(pp, "linux,code", &button->code)) {
            dev_err(dev, "Button without keycode: 0x%x\n",
                button->gpio);
            error = -EINVAL;
            goto err_free_pdata;
        }

        button->desc = of_get_property(pp, "label", NULL);

        if (of_property_read_u32(pp, "linux,input-type", &button->type))
            button->type = EV_KEY;

        button->wakeup = !!of_get_property(pp, "gpio-key,wakeup", NULL);

        if (of_property_read_u32(pp, "debounce-interval",
                     &button->debounce_interval))
            button->debounce_interval = 5;
    }

    if (pdata->nbuttons == 0) {
        error = -EINVAL;
        goto err_free_pdata;
    }

    return pdata;

err_free_pdata:
    kfree(pdata);
err_out:
    return ERR_PTR(error);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值