Xilinx / embeddedsw

Xilinx Embedded Software (embeddedsw) Development
Other
885 stars 1.05k forks source link

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 5 months ago

devradu commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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 commented 5 months ago

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

joeisnotfromthewoods commented 4 months ago

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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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