Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rfsoc.c and xrfclk_example_app.c: Incorrect Linux gpio ID passed to XRFClk_Init() for GPIO to control the SPI SDO Mux on the CLK104 #284

Open
devradu opened this issue Jan 12, 2024 · 14 comments

Comments

@devradu
Copy link

devradu commented Jan 12, 2024

For the ZCU216, the Linux gpio id passed to XRFClk_Init() is incorrect on line 276 of rfsoc.c ret = XRFClk_Init(485);, is incorrect. The same applies to line 142 of xrfclk_example_app.c that passes gpio486, XRFClk_Init(486);. This causes RfclkReadReg commands from the RF Evaluation GUI to return an incorrect value because the SPI SDO mux is not properly controlled. It is possible that the Linux gpio specified for the ZCU208 might also be incorrect. In the Vivado block design of the GEN3 RF Evaluation for the ZCU216, the axi_gpio_spi_mux block is assigned a base address of 0x00_A020_5000. The gpiochip corresponding to this base address is gpiochip481 (see below).

xilinx-zcu216-20222:~$ cat /sys/class/gpio/gpiochip481/label
a0205000.gpio

For the ZCU216, both files should be corrected to XRFClk_Init(481); to enable proper control the SPI SDO Mux on the CLK104 to enable valid register reads of the PLLs on the CLK104.

@xlnx-dcvetic
Copy link
Contributor

Yes, Linux assignes arbitrary index to gpio device and can vary for different IP design.
And we are going to add comment into the example code explaining the issue and what user should do.

@devradu
Copy link
Author

devradu commented Jan 17, 2024

The issue exists using the factory evaluation build for the ZCU216. Why would you not default the value to the value in the factory evaluation design for each board? The main issue is that this error exists in the factory rftool included wtihin the ZCU216 BSP included in the Zynq UltraScale+ RFSoC Gen 3 RF Data Converter Evaluation Tool v2022.2. In particular rfsoc.c.

@anishk-xlnx
Copy link

Thanks for reporting. We acknowledge it as a bug. We will fix in the next release.

@joeisnotfromthewoods
Copy link

joeisnotfromthewoods commented Feb 26, 2024

I struggled with the GPIO settings for quite a while, so I'm sharing my discoveries in the hope it helps someone else.
I have a ZCU208 with the CLK104 and had bare-metal code I've been asked to convert to Linux.

While it isn't clear at all how the GPIO is setup from the .xsa file I was provided (from the bare-metal project I mentioned), a0205000.gpio isn't showing up on my system as mentioned here, and XRFClk_Init(481); does nothing useful on my system to allow SPI/SDO control.

I found /amba_pl@0/gpio@a0050000 in my device tree labeled as axi_gpio_spi_mux using the shell of the zcu208 via:

$ dtc -I fs /sys/firmware/devicetree/base 2> /dev/null | grep amba | grep gpio
# returned several things, but relevant is:
		axi_gpio_spi_mux = "/amba_pl@0/gpio@a0050000";

Next I had to find out which gpiochip number was associated with a0050000 and used the shell on the zcu208 to learn via:

$ grep a0050000 /sys/class/gpio/gpiochip*/label
# returned:
/sys/class/gpio/gpiochip503/label:a0050000.gpio

With all this info, I changed the call to XRFClk_Init(503); and was able to clock data into / out-of the LMX and LMK devices.

Hope this helps, and if there's a better or more accurate way to do this, please update this thread.

@anishk-xlnx
Copy link

Hi,

The method mentioned in the comment by @joeisnotfromthewoods is correct.

Linux assigns arbitrary index to gpio device and it can vary with IP design. The gpio number in the argument of XRFClk_Init() function is wrong in rfsoc.c. This is fixed in 2024.1 release.

To solve the problem in previous releases or any custom design we can use the below steps. The below example is taken from 2023.2 evaltool factory release. The steps are exactly same as mentioned by @joeisnotfromthewoods.

Step 1: Find the GPIO address from the device tree label

$ dtc -I fs /sys/firmware/devicetree/base 2> /dev/null | grep gpio_spi_mux
# Return: PS_Subsystem_axi_gpio_spi_mux = "/amba_pl@0/gpio@a0205000";

Step 2: Find the number to which the gpio is mapped by Linux from the gpio address

$ grep a0205000 /sys/class/gpio/gpiochip*/label
# Return: /sys/class/gpio/gpiochip481/label:a0205000.gpio
# Here 481 is the GPIO number

For evaltool factory releases from 2021.1 to 2023.2, the gpio number is 481 for zcu216 and 489 for zcu208.

Regards,
Anish

@joeisnotfromthewoods
Copy link

Thanks for the feedback Anish. One question though, where is rfsoc.c ? I've been working with xrfclk_example_app.c . Is there another app file I missed?

@anishk-xlnx
Copy link

Hi,

The evaluation tool can be downloaded from https://www.xilinx.com/products/silicon-devices/soc/rfsoc.html#resources

The file rfsoc.c is part of rftool application. Rftool is a C based application running in the Linux user layer of the board. The LabVIEW evaltool gui communicates from host PC with Rftool in the board.

Regards,
Anish

@jieerxxxx
Copy link

你好,我在zcu208板子上运行rfclk的测试程序时,产生了如下报错:
RFCLK error in XRFClk_InitI2C: i2c2spi bridge open
RFCLK error in XRFClk_Init: i2c init

通过查找代码发现是
fd_bridge = open(RFCLK_I2C_I2C2SPI_BRIDGE_DEVICE_PATH, O_RDWR);
if (fd_bridge < 0) {
LOG("i2c2spi bridge open");
return XST_FAILURE;
}
而上面代码中的RFCLK_I2C_I2C2SPI_BRIDGE_DEVICE_PATH是一个宏定义,设置为
#define RFCLK_I2C_I2C2SPI_BRIDGE_DEVICE_PATH "/dev/i2c-20" /* i2c2spi bridge device */

然而我的/dev下没有i2c-20这个设备,我使用ls -la /dev/i2c*命令查看后,i2c的设备只有如下信息:
crw------- 1 root root 89, 0 Jul 5 06:09 /dev/i2c-0
crw------- 1 root root 89, 1 Jul 5 06:09 /dev/i2c-1
crw------- 1 root root 89, 2 Jul 5 06:09 /dev/i2c-2

我查看xilinx内核的arch/arm64/boot/dts/xilinx/目录下的zynqmp-zcu208-revA.dts 文件,发现在&i2c1节点下有clk104的子节点,
i2c_clk104: i2c@5 {
#address-cells = <1>;
#size-cells = <0>;
reg = <5>;

   /* CLK104_SDA */

};

我认为我需要在设备树中添加i2c和CLK104的相关配置,但是 /* CLK104_SDA */这个应该如何填写呢?它与pl.dtsi文件中的axi_gpio_spi_mux设备节点有关吗?axi_gpio_spi_mux节点的内容如下:

axi_gpio_spi_mux: gpio@a0040000 {
15 #gpio-cells = <3>;
16 clock-names = "s_axi_aclk";
17 clocks = <&zynqmp_clk 71>;
18 compatible = "xlnx,axi-gpio-2.0", "xlnx,xps-gpio-1.00.a";
19 gpio-controller ;
20 reg = <0x0 0xa0040000 0x0 0x10000>;
21 xlnx,all-inputs = <0x0>;
22 xlnx,all-inputs-2 = <0x0>;
23 xlnx,all-outputs = <0x1>;
24 xlnx,all-outputs-2 = <0x0>;
25 xlnx,dout-default = <0x00000000>;
26 xlnx,dout-default-2 = <0x00000000>;
27 xlnx,gpio-width = <0x2>;
28 xlnx,gpio2-width = <0x20>;
29 xlnx,interrupt-present = <0x0>;
30 xlnx,is-dual = <0x0>;
31 xlnx,tri-default = <0xFFFFFFFF>;
32 xlnx,tri-default-2 = <0xFFFFFFFF>;
33 };
我的vivado是2023.2,petalinux是2020.2,开发板是zcu208,我应该如何在设备树中关于clk104和 i2c2spi bridge添加信息呢?或者是在内核中启用什么设置吗?

@NghiSpectrohm
Copy link

@jieerxxxx You have the same issue we reported to xilinx for both zcu111 and zcu208 with Vivado 2024.1 and Petalinux 2024.1 update. For some unknown reason, the i2c-20 bridge is not enable while both i2c-0 and i2c1 enable. Thus rfsoc clk104 module could not initialized and failed detecting i2c-20 bridge.

See the issue on: https://support.xilinx.com/s/question/0D54U00008TbxsGSAR/warning-do-not-upgrade-to-version-20241-if-you-are-running-zcu-rfsoc-and-dynamically-change-pl-rf-clock-lmxlmk-at-petalinux-runtime-with-clk104-i2c-applications?language=en_US

I downgrade the design to Vivado 2023.2 and Petalinux 2023.2, and the project runs clk104 as the i2c-20 is enable again in petalinux.

@NghiSpectrohm
Copy link

NghiSpectrohm commented Jul 5, 2024

@jieerxxxx I may found the root cause of missing i2c-xxx, from missing bsp hardware specific device-tree if petalinux is not build correctly.

Go to your petalinux folder, and view system-top.dts that generated by Xilinx petalinux. The system device-tree should have zcu208-reva.dtsi included.

In my case of 2024.1, even though I used generated petalinux with zcu208 bsp, sdt-gen build process expected zcu2-8-reva included in the sdt-gen while XSCT build would automatically included board specific parameter from bsp.

$ more ./project-spec/hw-description/system-top.dts
/dts-v1/;
#include "zynqmp.dtsi"
#include "zynqmp-clk-ccf.dtsi"
#include "zcu208-reva.dtsi"
#include "pl.dtsi"
#include "pcw.dtsi"

If your build is missing the board specific parameter "zcu208-reva", here is how you should build your project from BSP; tthis command is assumed BSP from 2023.2, rename it to your BSP version:

$ petalinux-create -t project -n MYPROJECT -s xilinx-zcu208-v2023.2-10140544.bsp

Without board specific parameter, your ZCU208 petalinux build is missing the i2c-bridge while i2c-0/1/2 sda ports are enable:

		i2c_si5341: i2c@1 {
			#address-cells = <1>;
			#size-cells = <0>;
			reg = <1>;
			si5341: clock-generator@36 { /* SI5341 - u43 */
				compatible = "silabs,si5341";
				reg = <0x36>;
				#clock-cells = <2>;
				#address-cells = <1>;
				#size-cells = <0>;
				clocks = <&ref48>;
				clock-names = "xtal";
				clock-output-names = "si5341";

				si5341_2: out@2 {
					/* refclk2 for PS-GT, used for USB3 */
					reg = <2>;
					always-on; /* assigned-clocks does not enable, so do it here */
				};
				si5341_3: out@3 {
					/* refclk3 for PS-GT, used for SATA */
					reg = <3>;
					always-on; /* assigned-clocks does not enable, so do it here */
				};
				si5341_5: out@5 {
					/* refclk5 PL CLK100 */
					reg = <5>;
					always-on; /* assigned-clocks does not enable, so do it here */
				};
				si5341_6: out@6 {
					/* refclk6 PL CLK125 */
					reg = <6>;
					always-on; /* assigned-clocks does not enable, so do it here */
				};
				si5341_9: out@9 {
					/* refclk9 used for PS_REF_CLK 33.3 MHz */
					reg = <9>;
					always-on; /* assigned-clocks does not enable, so do it here */
				};
			};

@NghiSpectrohm
Copy link

@anishk-xlnx

My 2024.1 clk104 application failed in XRFCLK_Init() during the third check spi init(). I debugged and all the i2c ports and bridges are correct. The gpio is updated in vitis code for the 2024.1 bsp petalinux build to gpio ID=512. What should I debug further?

My system project:
Vivado: 2024.1 -> xsa
Vitis Unified: 2024.1 - cortexa52 linux hardware, linux application clk104
Petalinux 2024.1: build with xilinx-zcu208-sdt-v2024.1-05230256.bsp

 $ dtc -I fs /sys/firmware/devicetree/base 2> /dev/null | grep gpio_spi_mux
                        xlnx,name = "axi_gpio_spi_mux";
                axi_gpio_spi_mux = "/amba_pl/axi_gpio@b0060000";
$ grep b0060000 /sys/class/gpio/gpiochip*/label
/sys/class/gpio/gpiochip512/label:b0060000.axi_gpio

image

@jieerxxxx
Copy link

@NghiSpectrohm
非常感谢您的回复,我还想知道,除了需要在设备树中包含zcu208-reva.dtsi文件,我还需要在内核配置中开启什么SPI或者I2C的配置吗?非常感谢您!

@jieerxxxx
Copy link

@NghiSpectrohm
另外还想请教您,在zcu208-reva.dtsi文件中,我在i2c1节点下看见您所提供的关于si5341的代码,它与CLK104之间有什么联系吗?我还在i2c1节点中发现了i2c_clk104的子节点
i2c_clk104: i2c@5 { #address-cells = <1>; #size-cells = <0>; reg = <5>; /* CLK104_SDA */ };
请问这个/* CLK104_SDA */部分我应该如何填写,才能正确使能i2c-bridge呢?
非常感谢您!

@xlnx-dcvetic
Copy link
Contributor

This thread is a duplicate of the thread #252

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants