cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Observer
Observer
1,978 Views
Registered: ‎02-05-2018

Trouble Adding AXI QSPI to Device Tree

Hello all,

 

Fair warning, I'm still new to the building device trees stuff and the following will probably be a "facepalm" moment for many of you.  I'm struggling to add the axi_quad_spi device to my device tree.  Most of my problem is likely my ignorance.  I've been searching the forums looking for a "fish", but now I'm hoping someone could "teach me how to fish" on this one.  I appreciate in advance any help.  This is one of the last obstacles I need to get through for my project and haven't had the best luck searching for a solution.  I've noticed a number of similar posts, but they either end unanswered, or the solution is to jump to 2018.

 

I'm using 2017.1 and am hoping to stick with this version (for a number of schedule based reasons).

 

My system-top.dts is as follows.  This was generated for me.

 

/dts-v1/;
/include/ "zynq-7000.dtsi"
/include/ "pl.dtsi"
/include/ "pcw.dtsi"
/ {
	chosen {
		bootargs = "earlycon";
		stdout-path = "serial0:115200n8";
	};
	aliases {
		ethernet0 = &gem0;
		serial0 = &uart1;
		spi0 = &qspi;
		spi1 = &axi_quad_spi_0;
		spi2 = &spi1;
	};
	memory {
		device_type = "memory";
		reg = <0x0 0x40000000>;
	};
	cpus {
	};
};
#include "system-user.dtsi"

  

In the pl.dtsi, is see the following for the device (at the end):

 

		axi_quad_spi_0: axi_quad_spi@41e00000 {
			bits-per-word = <8>;
			compatible = "xlnx,xps-spi-2.00.a";
			fifo-size = <16>;
			num-cs = <0x3>;
			reg = <0x41e00000 0x10000>;
			xlnx,num-ss-bits = <0x3>;
			xlnx,spi-mode = <0>;
		};

 

Within my system-user.dtsi, I added the &axi_quad_spi_0 entry... and I'm very convinced it is wrong, but I am unfamiliar with the workflow to figure out how to fix it.  The &spi1 entry successfully maps to the /dev/spidev2.0[.1, .2].  I'll admit, I simply mimicked the entry for &spi1, hoping it would work.  (UPDATED 7/20/18: I've updated the file shown below: 1) added the #address-cells and #size-cells to the &axi_quad_spi_0 node, and this eliminated the warning messages when running dtc,  2) removed the is-decoded-sc property from the &axi_quad_spi_0 node... which was wrong.)

 

/include/ "system-conf.dtsi"
/ {
};
&spi1 {
  is-decoded-cs = <0>;
  num-cs = <3>;
  status = "okay";
  spidev@0x00 {
    compatible = "spidev";
    spi-max-frequency = <17000000>;
    reg = <0>;
  };
  spidev@0x01 {
    compatible = "spidev";
    spi-max-frequency = <17000000>;
    reg = <1>;
  };
  spidev@0x02 {
    compatible = "spidev";
    spi-max-frequency = <17000000>;
    reg = <2>;
  };
};
&axi_quad_spi_0 {
  num-cs = <3>;
  status = "okay";
  #address-cells = <1>;
  #size-cells = <0>;
  spidev@0x00 {
    compatible = "spidev";
    spi-max-frequency = <17000000>;
    reg = <0>;
  };
  spidev@0x01 {
    compatible = "spidev";
    spi-max-frequency = <17000000>;
    reg = <1>;
  };
  spidev@0x02 {
    compatible = "spidev";
    spi-max-frequency = <17000000>;
    reg = <2>;
  };
};
&gem0 {
        phy-handle = <&phy0>;
        phy0: phy0@0 {
                device_type = "ethernet-phy";
                reg = <0>;
        };
};

The kernel boots but outputs the following errors, and of course, spidev1.0[.1, .2] does not appear in /dev

 

spidev spi2.0: buggy DT: spidev listed directly in DT
spidev spi2.1: buggy DT: spidev listed directly in DT
spidev spi2.2: buggy DT: spidev listed directly in DT
xilinx_spi 41e00000.axi_quad_spi: can't setup spi1.0, status -13
spi_master spi1: spi_device register error /amba_pl/axi_quad_spi@41e00000/spidev@0x00
spi_master spi1: Failed to create SPI device for /amba_pl/axi_quad_spi@41e00000/spidev@0x00
xilinx_spi 41e00000.axi_quad_spi: can't setup spi1.1, status -13
spi_master spi1: spi_device register error /amba_pl/axi_quad_spi@41e00000/spidev@0x01
spi_master spi1: Failed to create SPI device for /amba_pl/axi_quad_spi@41e00000/spidev@0x01
xilinx_spi 41e00000.axi_quad_spi: can't setup spi1.2, status -13
spi_master spi1: spi_device register error /amba_pl/axi_quad_spi@41e00000/spidev@0x02
spi_master spi1: Failed to create SPI device for /amba_pl/axi_quad_spi@41e00000/spidev@0x02

When I convert the system.dtb to a .dts, dtc gives me the following warnings, which seems to point to the fact that my system-user.dtsi file is incorrect.  (UPDATED: 7/20/18: This was fixed by adding the #address-cells and #size-cells properties, as explained above)

 

Warning (reg_format): "reg" property in /amba_pl/axi_quad_spi@41e00000/spidev@0x00 has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1)
Warning (reg_format): "reg" property in /amba_pl/axi_quad_spi@41e00000/spidev@0x01 has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1)
Warning (reg_format): "reg" property in /amba_pl/axi_quad_spi@41e00000/spidev@0x02 has invalid length (4 bytes) (#address-cells == 2, #size-cells == 1)
Warning (avoid_default_addr_size): Relying on default #address-cells value for /amba_pl/axi_quad_spi@41e00000/spidev@0x00
Warning (avoid_default_addr_size): Relying on default #size-cells value for /amba_pl/axi_quad_spi@41e00000/spidev@0x00
Warning (avoid_default_addr_size): Relying on default #address-cells value for /amba_pl/axi_quad_spi@41e00000/spidev@0x01
Warning (avoid_default_addr_size): Relying on default #size-cells value for /amba_pl/axi_quad_spi@41e00000/spidev@0x01
Warning (avoid_default_addr_size): Relying on default #address-cells value for /amba_pl/axi_quad_spi@41e00000/spidev@0x02
Warning (avoid_default_addr_size): Relying on default #size-cells value for /amba_pl/axi_quad_spi@41e00000/spidev@0x02

 

The tail end of the system.dtb (after it's converted back a .dts) is shown below with the amba, amba_pl, and aliases snippets.  The amba portion is include simply to show the effect of the first part of the system-user.dtsi, and to provide context to the aliases.

 

amba {
...
...
		spi@e0007000 {
			compatible = "xlnx,zynq-spi-r1p6";
			reg = <0xe0007000 0x1000>;
			status = "okay";
			interrupt-parent = <0x4>;
			interrupts = <0x0 0x31 0x4>;
			clocks = <0x1 0x1a 0x1 0x23>;
			clock-names = "ref_clk", "pclk";
			#address-cells = <0x1>;
			#size-cells = <0x0>;
			is-decoded-cs = <0x0>;
			num-cs = <0x3>;

			spidev@0x00 {
				compatible = "spidev";
				spi-max-frequency = <0x1036640>;
				reg = <0x0>;
			};

			spidev@0x01 {
				compatible = "spidev";
				spi-max-frequency = <0x1036640>;
				reg = <0x1>;
			};

			spidev@0x02 {
				compatible = "spidev";
				spi-max-frequency = <0x1036640>;
				reg = <0x2>;
			};
		};

 

     amba_pl {
...
...
axi_quad_spi@41e00000 { bits-per-word = <0x8>; compatible = "xlnx,xps-spi-2.00.a"; fifo-size = <0x10>; num-cs = <0x3>; reg = <0x41e00000 0x10000>; xlnx,num-ss-bits = <0x3>; xlnx,spi-mode = <0x0>; status = "okay"; #address-cells = <0x1>; #size-cells = <0x0>; spidev@0x00 { compatible = "spidev"; spi-max-frequency = <0x1036640>; reg = <0x0>; }; spidev@0x01 { compatible = "spidev"; spi-max-frequency = <0x1036640>; reg = <0x1>; }; spidev@0x02 { compatible = "spidev"; spi-max-frequency = <0x1036640>; reg = <0x2>; }; };
}; chosen { bootargs = "console=ttyPS0,115200 earlyprintk"; stdout-path = "serial0:115200n8"; }; aliases { ethernet0 = "/amba/ethernet@e000b000"; serial0 = "/amba/serial@e0001000"; spi0 = "/amba/spi@e000d000"; spi1 = "/amba_pl/axi_quad_spi@41e00000"; spi2 = "/amba/spi@e0007000"; }; memory { device_type = "memory"; reg = <0x0 0x40000000>; }; };

 

 

A number of users refer to the kernel config showing all the flags they are using.  Could someone point me to where I can find that?  All I've been able to find is a bunch of user_<date>.cfg files at ./project-spec/meta-user/recipes-kernel/lijux/linux-xlnx

Is there a flattened version of this somewhere?  Looking through them, I'm not seeing CONFIG_SPI_XILINX getting set. 

 

(Updated... here's the content of plnx_kernel.cfg)

 

CONFIG_MTD=y
CONFIG_MTD_OF_PARTS=y
CONFIG_SERIAL_OF_PLATFORM=y
CONFIG_NET=y
CONFIG_PACKET=y
CONFIG_UNIX=y
CONFIG_INET=y
# CONFIG_DEBUG_ZYNQ_UART0 is not set
CONFIG_DEBUG_LL=y
CONFIG_DEBUG_ZYNQ_UART1=y
CONFIG_EARLY_PRINTK=y
CONFIG_GPIOLIB=y
CONFIG_GPIO_XILINX=y
CONFIG_GPIO_ZYNQ=y
CONFIG_HWMON=y
CONFIG_I2C=y
CONFIG_I2C_CADENCE=y
CONFIG_MMC=y
CONFIG_MMC_BLOCK=y
CONFIG_MMC_SDHCI=y
CONFIG_MMC_SDHCI_OF_XILINX_PS=y
CONFIG_MMC_SDHCI_PLTFM=y
CONFIG_MTD=y
CONFIG_MTD_M25P80=y
CONFIG_MTD_OF_PARTS=y
CONFIG_MTD_SPI_NOR=y
CONFIG_NET_CORE=y
CONFIG_SERIAL_OF_PLATFORM=y
CONFIG_SERIAL_XILINX_PS_UART=y
CONFIG_SERIAL_XILINX_PS_UART_CONSOLE=y
CONFIG_SPI=y
CONFIG_SPI_CADENCE=y
CONFIG_SPI_XILINX=y
CONFIG_SPI_XILINX_PS_QSPI=y
CONFIG_USB=y
CONFIG_USB_EHCI_HCD=y
CONFIG_USB_EHCI_XUSBPS=y
CONFIG_USB_GADGET_XUSBPS=y
CONFIG_USB_OTG=y
CONFIG_USB_SUPPORT=y
CONFIG_USB_XUSBP=y
CONFIG_USB_XUSBPS_DR_OF=y
CONFIG_USB_XUSBPS_OTG=y
CONFIG_XILINX_DEVCFG=y
CONFIG_XILINX_PS_EMAC=y
CONFIG_XILINX_XADC=y

 

Here is a screenshot of the kernel config page for the SPI drivers.

 

Screenshot from 2018-07-19 18-41-35.png

 

Here's some extras:

root@plnx_arm:/sys/devices/soc0/amba_pl# ls
41200000.gpio           41220000.gpio           41e00000.axi_quad_spi   driver_override         of_node                 subsystem
41210000.gpio           41600000.i2c            modalias                power                   uevent



root@plnx_arm:/sys/firmware/devicetree/base/amba_pl# ls -al
total 0
-r--r--r--    1 root     root             4 Jul 20 00:48 #address-cells
-r--r--r--    1 root     root             4 Jul 20 00:48 #size-cells
drwxr-xr-x    8 root     root             0 Jul 20 00:48 .
drwxr-xr-x   11 root     root             0 Jul 20 00:48 ..
drwxr-xr-x    5 root     root             0 Jul 20 00:48 axi_quad_spi@41e00000
-r--r--r--    1 root     root            11 Jul 20 00:48 compatible
drwxr-xr-x    2 root     root             0 Jul 20 00:48 gpio@41200000
drwxr-xr-x    2 root     root             0 Jul 20 00:48 gpio@41210000
drwxr-xr-x    2 root     root             0 Jul 20 00:48 gpio@41220000
drwxr-xr-x    2 root     root             0 Jul 20 00:48 i2c@41600000
-r--r--r--    1 root     root             8 Jul 20 00:48 name
-r--r--r--    1 root     root             0 Jul 20 00:48 ranges

 

I would really appreciate the help and will give kudos and a reply to the solution if anyone could help me out on this.

 

Thanks!

-Phil

0 Kudos
Reply
3 Replies
Contributor
Contributor
1,950 Views
Registered: ‎07-18-2018

Hello @philtempblue,

 

I hope I can help you.

First of all, why do you need to "Within my system-user.dtsi, i added the &axi_quad_spi_0 entry"? It is already in the pl.dtsi and pl.dtsi is already included in the system-top.dts.

 

you can flatten your device tree by running a command like this (you can use the dtc binary from xilinx linux, or the dtc installed on your Linux OS):

dtc -I dts -O dts system-top.dts > mydt.dts

and then you can build the dtb by running this command:

 

linux-xlnx/scripts/dtc/dtc -I dts -O dtb -o <devicetree name>.dtb mydt.dts

Let me know if it can solve any problem.

\Razi

\Razi
-- Don’t forget to Reply, Kudo, and Accept as Solution --
Observer
Observer
1,932 Views
Registered: ‎02-05-2018

Thanks Razi!

 

I appreciate the reply. 

 

In regards to "flattening", I was trying to figure out how to flatten all the user_YYYY-MM-DD-HH-MM-SS.cfg files found within:  .../project-spec/meta-user/recipes-kernel/linux/linux-xlnx

 

I think I found the answer to that... they are flattened into plnx_kernel.cfg found here: .../project-spec/meta-plnx-generated/recipes-kernel/linux/configs  I will updated my original post to show the content of that file.

 

The reason I was including it in the system-user.dtsi is because I thought that is the only way to expose the spi device in /dev as a spidev device.  Is this not the case?  When i omitted this entry, it did not show up in /dev.  Again, this is totally a lack of understanding on my part.  Perhaps I can't even use the AXI Quad SPI IP using spidev?

 

Thanks

Phil 

0 Kudos
Reply
Observer
Observer
1,907 Views
Registered: ‎02-05-2018

Alright... I think it's been solved.

 

Here's a similar post...

https://forums.xilinx.com/t5/Embedded-Linux/Petalinux-2017-1-AXI-QUAD-SPI-warning/td-p/768875

 

...which then links to this as the solution...

https://forums.xilinx.com/t5/Embedded-Linux/SPIDEV-problems-on-Xilinx-Linux-2017-1/m-p/774078#M20198

 

I disabled the CONFIG_SUSPEND and CONFIG_PM and apparently this made enough difference to now expose the spidev entries.

 

Someone showed me the handy feature of using the forward slash "/" in the kernel config page (petalinux-config -c kernel) to search for the flag names "SUSPEND" and "PM".

 

Have yet to test if the SPI bus actually works, but one step closer.