Search code examples
linux-device-driverembedded-linuxspidevice-tree

Warnings in DTS Linux


While I compile DTS for my device, it gives me warnings, that don't really make sense to me. There are two spi-chips on my device, their description is DTS is the following:

spi-gpio {
    compatible = "spi-gpio";
    #address-cells = <0x1>;
    ranges;
    status = "okay";

    sck-gpios   = <&pio 4 9 GPIO_ACTIVE_HIGH>;  // PE9
    mosi-gpios  = <&pio 4 6 GPIO_ACTIVE_HIGH>;  // PE6
    miso-gpios  = <&pio 4 8 GPIO_ACTIVE_HIGH>;  // PE8
    cs-gpios    = <&pio 4 4 GPIO_ACTIVE_HIGH>,  // PE4
                  <&pio 4 17 GPIO_ACTIVE_HIGH>; // PE17
    num-chipselects = <2>;

    /* Clients */
    m90e32@0 {
        reg = <0>;
        compatible = "atmel,m90e32";
        spi-max-frequency = <1000>;
        reset-gpios = <&pio 4 18 GPIO_ACTIVE_HIGH>; // PE17
    };

    m90e32@1 {
        reg = <1>;
        compatible = "atmel,m90e32";
        spi-max-frequency = <1000>;
        reset-gpios = <&pio 4 18 GPIO_ACTIVE_HIGH>; // PE17
    };
};

The warnings are:

Warning (reg_format): /spi-gpio/m90e32@0:reg: property has invalid length (4 bytes) (#address-cells == 1, #size-cells == 1)

Warning (reg_format): /spi-gpio/m90e32@1:reg: property has invalid length (4 bytes) (#address-cells == 1, #size-cells == 1)

I've read documentation for DTS and I've seen a similar question on SO, but it' doesn't really suit my situation. What am I missing?


Solution

  • You need to add a size value to the reg property for each SPI device. Since these are SPI devices, the size is typically not used (or can be set to 0). Here's the corrected DTS:

    spi-gpio {
        compatible = "spi-gpio";
        #address-cells = <0x1>;
        #size-cells = <0x1>; // Ensure this is set to 1
        ranges;
        status = "okay";
    
        sck-gpios   = <&pio 4 9 GPIO_ACTIVE_HIGH>;  // PE9
        mosi-gpios  = <&pio 4 6 GPIO_ACTIVE_HIGH>;  // PE6
        miso-gpios  = <&pio 4 8 GPIO_ACTIVE_HIGH>;  // PE8
        cs-gpios    = <&pio 4 4 GPIO_ACTIVE_HIGH>,  // PE4
                      <&pio 4 17 GPIO_ACTIVE_HIGH>; // PE17
        num-chipselects = <2>;
    
        /* Clients */
        m90e32@0 {
            reg = <0 0>; // Address = 0, Size = 0
            compatible = "atmel,m90e32";
            spi-max-frequency = <1000>;
            reset-gpios = <&pio 4 18 GPIO_ACTIVE_HIGH>; // PE17
        };
    
        m90e32@1 {
            reg = <1 0>; // Address = 1, Size = 0
            compatible = "atmel,m90e32";
            spi-max-frequency = <1000>;
            reset-gpios = <&pio 4 18 GPIO_ACTIVE_HIGH>; // PE17
        };
    };
    

    Explanation

    The reg property must match the format defined by #address-cells and #size-cells. After adding the size value the reg property now has the correct length (8 bytes: 4 bytes for address + 4 bytes for size), which resolves the warning you're getting.