內核相關的獲取節點屬性函數


1、

of_find_property:獲取節點里的某個屬性結構體

read_lock(&devtree_lock);
for (pp = np->properties; pp != 0; pp = pp->next) {
if (of_prop_cmp(pp->name, name) == 0) {//獲取相應的屬性,一個設備節點里面包含不同屬性,確定屬性是否存在例如compatible
if (lenp != 0)
*lenp = pp->length; //並且將屬性的值的長度保存
break;
}
}
read_unlock(&devtree_lock);


return pp; 返回相應的屬性結構體

2、of_get_property 返回該節點下這個屬性的值 例如:compatible=qcom,imx135

const void *of_get_property(const struct device_node *np, const char *name,
int *lenp)
{
struct property *pp = of_find_property(np, name, lenp);


return pp ? pp->value : NULL;
}

3、of_device_is_compatible    驅動driver.compatible= (設備樹)設備節點下對應的compatible

int of_device_is_compatible(const struct device_node *device,
const char *compat)
{
const char* cp;
int cplen, l;


cp = of_get_property(device, "compatible", &cplen);//返回屬性的值compatible=imx135
if (cp == NULL)
return 0;
while (cplen > 0) {
if (of_compat_cmp(cp, compat, strlen(compat)) == 0)
return 1;                                                  //成功的話,返回1
l = strlen(cp) + 1;
cp += l;
cplen -= l;
}


return 0;


4\ of_match_node

const struct of_device_id *of_match_node(const struct of_device_id *matches,
const struct device_node *node)
{
if (!matches)
return NULL;


while (matches->name[0] || matches->type[0] || matches->compatible[0]) {
int match = 1;
if (matches->name[0])
match &= node->name
&& !strcmp(matches->name, node->name);
if (matches->type[0])
match &= node->type
&& !strcmp(matches->type, node->type);
if (matches->compatible[0])
match &= of_device_is_compatible(node,
matches->compatible);
if (match)
return matches;//成功的話,返回match結構體,
matches++;
}
return NULL;

5、of_match_device  成功返回match結構體,失敗NUll

const struct of_device_id *of_match_device(const struct of_device_id *matches,
  const struct device *dev)
{
if ((!matches) || (!dev->of_node))
return NULL;
return of_match_node(matches, dev->of_node);
}


注意!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系我们删除。



 
粤ICP备14056181号  © 2014-2021 ITdaan.com