Pergunta

The explanation in struct device says

Associated device tree node.

But, I didn't clearly understand this.

Can anyone provide an example?

Foi útil?

Solução

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";
        };
    };
};

Outras dicas

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top