3

The explanation in struct device says

Associated device tree node.

But, I didn't clearly understand this.

Can anyone provide an example?

2 Answers 2

5

of_node is related to Open Firmware it holds the information of a device tree.

Device Tree is like config file (named nodes and properties) which describes hardware in detail.

The main advantage of device tree is you don't have to keep modifying kernel for specific hardware. All you have to do is define your h/w in device tree fmt and feed it to bootloader. Boot loader, for example uboot, passes the device tree information to kernel and kernel initializes the devices based on those information it received from boot-loader.

the below is example of device tree.

{
    compatible = "acme,coyotes-revenge";

    cpus {
        cpu@0 {
            compatible = "arm,cortex-a9";
        };
        cpu@1 {
            compatible = "arm,cortex-a9";
        };
    };

    serial@101F0000 {
        compatible = "arm,pl011";
    };

    serial@101F2000 {
        compatible = "arm,pl011";
    };

    interrupt-controller@10140000 {
        compatible = "arm,pl190";
    };

    external-bus {
        ethernet@0,0 {
            compatible = "smc,smc91c111";
        };

        i2c@1,0 {
            compatible = "acme,a1234-i2c-bus";
            rtc@58 {
                compatible = "maxim,ds1338";
            };
        };

        flash@2,0 {
            compatible = "samsung,k8f1315ebm", "cfi-flash";
        };
    };
};
Sign up to request clarification or add additional context in comments.

2 Comments

can you please explain the above example?
Lets take CPU. The board has Two CPUs (cpu1 and cpu0) which is compatible to "arm,cortex-a9" i.e two cpus are ARM cortex-a9 models cpu@0 { compatible = "arm,cortex-a9"; }; cpu@1 { compatible = "arm,cortex-a9"; }; Similarly RTC clock (i2c device because it is under i2c) device is DS1338 model. rtc@58 { compatible = "maxim,ds1338"; ; The better way to write is to specify the I2C address(i2c probe address) too So kernel bind the device at the address. rtc@58 { compatible = "maxim,ds1338"; reg = <0x58> }; The example posted was very simple one
1

struct device_node (type of of_node) contains struct property which contains all properties of device tree node. It also has pointer to other properties and other node (siblings and parent) and a name variable which is name of the property (eg, register). So that's how we can have diffrent data like address from device tree in our driver code.

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.