驱动中常用的获取devices tree属性的api

例如dts文件中设置如下:

	qcom,sw-jeita-enable;
	qcom,usb-icl-ua = <2500000>;
	qcom,thermal-mitigation
				= <1800000 1600000 1400000 1200000 1000000 1000000 1000000>;

1.获取是否存在该属性:

chg->sw_jeita_enabled = of_property_read_bool(node,"qcom,sw-jeita-enable");

2.获取属性的值

	rc = of_property_read_u32(node,"qcom,usb-icl-ua", &chip->dt.usb_icl_ua);
	if (rc < 0)
		chip->dt.usb_icl_ua = -EINVAL;		

获取属性数组的值

    //获取该数组的长度存放到byte_len中并且分配相应内存
	if (of_find_property(node, "qcom,thermal-mitigation", &byte_len)) {
		chg->thermal_mitigation = devm_kzalloc(chg->dev, byte_len,
			GFP_KERNEL);
        //内存不足
		if (chg->thermal_mitigation == NULL)
			return -ENOMEM;

        //属性是U32的,总字节数/sizeof(u32)就是数组元素个数
		chg->thermal_levels = byte_len / sizeof(u32);
		
		rc = of_property_read_u32_array(node,
				"qcom,thermal-mitigation",
				chg->thermal_mitigation,
				chg->thermal_levels);
		if (rc < 0) {
			dev_err(chg->dev,
				"Couldn't read threm limits rc = %d\n", rc);
			return rc;
		}
	}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值