0

I been trying to read child node property in a Device Tree. Could not figured it out, can any one help here?

I have a dts file

AA {
    child 1: {
            property 1 : XXX
            property 2 : XXX
    }
    child 2: {
            property 1 : XXX
            property 2 : XXX
    }
BB {
    child 1: {
            property 1 : XXX
            property 2 : XXX
    }
    child 2: {
            property 1 : XXX
            property 2 : XXX
    }

Is there any way of reading properies of child 2 in AA node of given dts?

2 Answers 2

3

Yes, you can do it. Just write a similar function as below and call it in AA with the path of the child node of BB.

For example, From AA if you need to access BB/child_2 property then pass the absolute path to of_find_node_by_path() function.

Also, check of_* family of function in the kernel that might be useful.

static void access_dt(void)                                                      
{                                                                                
    /* device node path - check it from /proc/device-tree/ */                    
    char *path = "/path/to/BB/child_2";                                            
    struct device_node *dt_node;                                                 
    const u8 *prop = NULL;                                                       
    int ret;                                                                     

    dt_node = of_find_node_by_path(path);                                        
    if (!dt_node) {                                                              
        printk(KERN_ERR "Failed to find node by path: %s.\n");                   
    } else {                                                                     
        printk(KERN_INFO "Found the node for %s.\n", path);                      
        prop = of_get_property(dt_node, "property 2", &ret);                      
        if(!prop) {
             //You are still in trouble!
        } else {
            //You have got property 2 of BB!
        }                                                                        
    }                                                                            
}
Sign up to request clarification or add additional context in comments.

1 Comment

And if path has been changed, what to do with this?
3

If I understood correctly you have to use something like for_each_child_of_node(). Check for example drivers/input/keyboard/gpio_keys.c and Documentation/devicetree/bindings/input/gpio-keys.txt.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.