linux-kernellinux-device-driveryoctoxilinxdevice-tree

of_node_name_eq for device tree node label


I am trying to read the label from my devices, but I keep reading pid@43c00000 instead of pid_0 when I use ->full_name on a struct device_node *. Is there a method to reading the label, or do I need to change the device tree entry of the node name to look something like pid0@43c00000 for pid_0.

                pid_0: pid@43c00000 {
                        clock-names = "s00_axi_aclk";
                        clocks = <&clkc 15>;
                        compatible = "xlnx,pid-1.0";
                        reg = <0x43c00000 0x10000>;
                        xlnx,adc-width = <0xc>;
                        xlnx,integrator-cycles = <0x186a0>;
                        xlnx,op-width = <0x13>;
                        xlnx,q = <0x6>;
                        xlnx,s00-axi-addr-width = <0x5>;
                        xlnx,s00-axi-data-width = <0x20>;
                };
                pid_1: pid@43c10000 {
                        clock-names = "s00_axi_aclk";
                        clocks = <&clkc 15>;
                        compatible = "xlnx,pid-1.0";
                        reg = <0x43c10000 0x10000>;
                        xlnx,adc-width = <0xc>;
                        xlnx,integrator-cycles = <0xa>;
                        xlnx,op-width = <0x13>;
                        xlnx,q = <0x6>;
                        xlnx,s00-axi-addr-width = <0x5>;
                        xlnx,s00-axi-data-width = <0x20>;
                };

Solution

  • Is there a method to reading the label

    No, there is no "method to reading the label" from the struct device_node because labels are not saved in that data structure.
    From section 6.2 of the DeviceTree Specification, v0.4-rc1:

    Labels are only used in the devicetree source format and are not encoded into the DTB binary
    

    Your driver at runtime only has access to the DTB, so there are no labels.


    I keep reading pid@43c00000 instead of pid_0 when I use ->full_name on a struct device_node *.

    Simply because pid@43c00000 is the (full) name of that node.
    pid_0 is the label, and should not be confused with the node name.

    Note that you can also review the contents of the DTB at /proc/device-tree, where nodes are (sub)directories and properties are files.


    ADDENDUM: CORRECTION

    Contrary to the cited DeviceTree Specification, there does seems to be a way to save the labels from the dts during compilation. This label capability is used by the DT overlay handler in the kernel.
    The Devicetree Overlay Notes mentions:

    If the base DT was not compiled with the -@ option then the "&ocp" label 
    will not be available to resolve the overlay node(s) to the proper 
    location in the base DT. 
    

    A gotcha is that not every version of the dtc supports this -@ flag.
    One man page describes this -@ option as:

        -@       Emit a __symbols__ node to allow plugins to be loaded.
    

    This suggests that a second gotcha may be that the label you want to use will not be contained in the device_node structure passed to the driver.