acpi_node_get_property_reference

如果bios 通过acpi 表传递给kernel如下code,要如何得到GPIo number呢?
 Package () {
      "cs-gpios",
      Package () {
         ^GPIO, 19, 0, 0,
         ^GPIO, 20, 0, 0,
         0,
         ^GPIO, 21, 0, 0,
      }
  }
这里的gpio都属于cs-gpios的属性,因此在kernel中可以通过下面的code 拿到
struct acpi_reference_args args;
ret = acpi_node_get_property_reference(dev->fwnode,"cs-gpios", 0, &args);
这里的第三个参数0,代表去GPIO, 19, 0, 0
如果第三个参数传递的是2的话,则返回的是0

int __acpi_node_get_property_reference(struct fwnode_handle *fwnode,
    const char *propname, size_t index, size_t num_args,
    struct acpi_reference_args *args)
{
    const union acpi_object *element, *end;
    const union acpi_object *obj;
    struct acpi_device_data *data;
    struct acpi_device *device;
    int ret, idx = 0;

    data = acpi_device_data_of_node(fwnode);
    if (!data)
        return -EINVAL;

    ret = acpi_data_get_property(data, propname, ACPI_TYPE_ANY, &obj);
    if (ret)
        return ret;

    /*
     * The simplest case is when the value is a single reference.  Just
     * return that reference then.
     */
    if (obj->type == ACPI_TYPE_LOCAL_REFERENCE) {
        if (index)
            return -EINVAL;

        ret = acpi_bus_get_device(obj->reference.handle, &device);
        if (ret)
            return ret;
// 这里以single mode 为例,原来通过会得到这个propname 所属的device。
        args->adev = device;
        args->nargs = 0;
        return 0;
    }

}
从__acpi_node_get_property_reference 中可以知道会给struct acpi_reference_args *args中的device赋值,这样就可以这个device得到fwnode。下面是acpi_node_get_property_reference的经典用法
        /* try to find port-idx-in-ae first */
        ret = acpi_node_get_property_reference(dev->fwnode,
                               "ae-handle", 0, &args);
        if (ret) {
            dev_err(dev, "not find ae-handle\n");
            goto out_read_prop_fail;
        }
        priv->fwnode = acpi_fwnode_handle(args.adev);


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值