I want to add new /dev.spidev0.1 in the system on agx xavier, what should I do?

I have agx xavier on hand, it’s official kit,.
run ubuntu 18.04,
kernel version 4.9.140-tegra,
use SDKmanager 4.3.

There is already one /dev/spidev0.0 on system, and I configure with this cmd ‘sudo /opt/nvidia/jetson-io/jetson-io.py’, now the /dev/spidev0.0 working fine.

Now I want add new spidev on system, like /dev/spidev0.1, use chip select signals for control,no relevant information found,what should I do?

Add spi@1 to the spi@xxxx in the device tree.
https://elinux.org/Jetson/TX2_SPI

    spi@1 {
      compatible = "spidev";
      reg = <0x1>;
      spi-max-frequency = <0x1312D00>;
      nvidia,enable-hw-based-cs;
      nvidia,cs-setup-clk-count = <0x1e>;
      nvidia,cs-hold-clk-count = <0x1e>;
      nvidia,rx-clk-tap-delay = <0x1f>;
      nvidia,tx-clk-tap-delay = <0x0>;
    }; 

hi, I I have gotten /dev/spidev0.1 on system. I tested it with driver/spi/spidev_test, and then grabbed SCK CS0 CS1 with an oscilloscope. I checked the information and found that the SPI is configured with hardware cs. I want to change it to GPIO contorl (software) cs. What should I do?

spi1-cs0-experience-negative-pulse-during-soft-reboot

can follow this TX2_SPI
add " cs-gpios = <&gpio TEGRA_GPIO(C, 3) GPIO_ACTIVE_LOW>; " to dtb file?

but I don’t know where to add, can you give me some guidance.

[image]

Follow document to sync the source and modify the device tree and build it then apply it by flash command.

https://docs.nvidia.com/jetson/l4t/index.html#page/Tegra%2520Linux%2520Driver%2520Package%2520Development%2520Guide%2Fkernel_custom.html%23

Thank you for your quick reply. I already have the latest kernel source code, but I don’t know which device tree to modify and which line to modify to configure the GPIO control (software) cs.
and Need to be shielded “nvidia, enable-hw-based-cs;” ?
I have no experience in this area.

Have a reference to below link.
Yes, may need to comment the “nvidia, enable-hw-based-cs;”

hi CCC, in xavier_kernel/sources/kernel/hardware/nvidia/platform/t19x/galen/kernel-dts/common/tegra194-p2888-0001-p2822-0000-common.dtsi , line 73,

	spi@3210000 {
	status = "okay";
	cs-gpios = <&gpio TEGRA_GPIO(C, 3) GPIO_ACTIVE_LOW>;
	spi@0 {
		compatible = "spidev";
		reg = <0x0>;
		spi-max-frequency = <33000000>;
		nvidia,rx-clk-tap-delay = <0x11>;
	};
};

change this , build report error:

Blockquote
xavier_kernel/sources/kernel/kernel/kernel-4.9/arch/arm64/boot/dts/…/…/…/…/…/…/hardware/nvidia/platform/t19x/galen/kernel-dts/common/tegra194-p2888-0001-p2822-0000-common.dtsi:75.21-22 syntax error
FATAL ERROR: Unable to parse input tree
/home/yang/Downloads/NVIDIA_file/xavier_kernel/sources/kernel/kernel/kernel-4.9/arch/arm64/boot/dts/Makefile:120: recipe for target ‘arch/arm64/boot/dts/ddot/ddot/ddot/ddot/ddot/ddot/hardware/nvidia/platform/t19x/galen/kernel-dts/tegra194-p2888-0001-p2822-0000.dtb’ failed
make[2]: *** [arch/arm64/boot/dts/ddot/ddot/ddot/ddot/ddot/ddot/hardware/nvidia/platform/t19x/galen/kernel-dts/tegra194-p2888-0001-p2822-0000.dtb] Error 1
make[2]: *** Waiting for unfinished jobs…
Error: /home/yang/Downloads/NVIDIA_file/xavier_kernel/sources/kernel/kernel/kernel-4.9/arch/arm64/boot/dts/…/…/…/…/…/…/hardware/nvidia/platform/t19x/galen/kernel-dts/common/tegra194-p2888-0001-p2822-0000-common.dtsi:75.21-22 syntax error
FATAL ERROR: Unable to parse input tree
/home/yang/Downloads/NVIDIA_file/xavier_kernel/sources/kernel/kernel/kernel-4.9/arch/arm64/boot/dts/Makefile:120: recipe for target ‘arch/arm64/boot/dts/ddot/ddot/ddot/ddot/ddot/ddot/hardware/nvidia/platform/t19x/galen/kernel-dts/tegra194-p2888-0001-p2822-0000-imx185_v1.dtb’ failed
make[2]: *** [arch/arm64/boot/dts/ddot/ddot/ddot/ddot/ddot/ddot/hardware/nvidia/platform/t19x/galen/kernel-dts/tegra194-p2888-0001-p2822-0000-imx185_v1.dtb] Error 1
Error: /home/yang/Downloads/NVIDIA_file/xavier_kernel/sources/kernel/kernel/kernel-4.9/arch/arm64/boot/dts/…/…/…/…/…/…/hardware/nvidia/platform/t19x/galen/kernel-dts/common/tegra194-p2888-0001-p2822-0000-common.dtsi:75.21-22 syntax error
FATAL ERROR: Unable to parse input tree

Using TEGRA194_MAIN_GPIO instead of TEGRA_GPIO for Xavier.

Blockquote
spi@3210000 {
status = “okay”;
cs-gpios = <&tegra_main_gpio TEGRA194_MAIN_GPIO(C, 3) GPIO_ACTIVE_LOW>;
spi@0 {
compatible = “spidev”;
reg = <0x0>;
spi-max-frequency = <33000000>;
nvidia,rx-clk-tap-delay = <0x11>;
};
};

1, C,3 is right?
2, compile and flash after modification directly? it’s need to change pinmux cfg?

Which GPIO depend on it which pin connect to your device cs.

sudo /opt/nvidia/jetson-io/jetson-io.py,
[*] sp1 (19,21,23,24,26)
cs0 pin is 24
cs1 pin is 26

I don’t know how to change it, need your support or advice, thank you.

These pins is native SPI cs pin don’t need to add cs-gpios, just configure it as SPI function.
You can try the jetson-io and confirm with sudo “cat /sys/kernel/debug/tegra_pinctrl_reg | grep -i spi” command to confirm the REG changed after save and reboot otherwise need to configure the cfg file as the reference link.

I follow you suggest, but I can’t found tegra_pinctrl_reg in /sys/kernel/debug/ (root user), what’s happening here? need JetPack4.4 ?

run the command by sudo

Blockquote
spi@3210000 {
status = “okay”;
cs-gpios =
<&tegra_main_gpio TEGRA194_MAIN_GPIO(Z, 6) GPIO_ACTIVE_LOW>,
<&tegra_main_gpio TEGRA194_MAIN_GPIO(Z, 7) GPIO_ACTIVE_LOW>;
spi@0 {
compatible = “spidev”;
reg = <0x0>;
spi-max-frequency = <33000000>;
nvidia,rx-clk-tap-delay = <0x11>;
};
};

You don’t need add “cs-gpios = <>” for these cs pins. The cs-gpios means you want to use any others gpio pin as cs. These two pin already configure as cs already.

How to change this part of cs hardware control to software GPIO control to achieve the purpose I want?
just delete “nvidia,enable-hw-based-cs;” ?
or “nvidia,disbale-hw-based-cs;” ?
or …

Blockquote
spi@3210000 {
status = “okay”;
spi@0 {
compatible = “spidev”;
reg = <0x0>;
spi-max-frequency = <33000000>;
nvidia,rx-clk-tap-delay = <0x11>;
};
};

I delete all “nvidia,enable-hw-based-cs;” in all dts
xavier_kernel/sources/kernel/kernel/kernel-4.9/drivers/spi/spi-tegra114.c

Blockquote
ret = of_property_read_bool(data_np, “nvidia,enable-hw-based-cs”);
if (ret)
{
cdata->is_hw_based_cs = 1;
printk(KERN_INFO “SPI: Define enable-hw-based-cs”);
}
else
{
printk(KERN_INFO “SPI: NOT Define enable-hw-based-cs”);
}

then recompile and flash Image, kernel module, dtb.

Blockquote
sudo ./flash.sh -k kernel-dtb jetson-xavier mmcblk0p1

but still output this, where is the problem?

Blockquote
nvidia@nvidia-desktop:~$ dmesg | grep SPI
[ 1.839267] SPI: Define enable-hw-based-cs
[ 1.839445] SPI: Define enable-hw-based-cs

I use this command “$ sudo dtc -I fs -O dts -o extracted_proc.dts /proc/device-tree” found “nvidia, enable-hw-based-cs”, recompile not success.

Don’t modify the spi-tegra114.c to remove the “nvidia,enable-hw-based-cs” you should remove it from the dts.
If you ever run the jetson_io have a check /boot/extlinux/extlinux.conf to update the dtb by replace it at /boot/
It could be like below.

LABEL JetsonIO
        MENU LABEL Custom 40-pin Header Config
        LINUX /boot/Image
        FDT /boot/tegra194-p3668-all-p3509-0000-user-custom.dtb
        INITRD /boot/initrd
        APPEND ${cbootargs} quiet root=/dev/mmcblk0p1 rw rootwait rootfstype=ext4 console=ttyTCU0,115200n8 console=tty0 fbcon=map:0 net.ifnames=0

I tried the method you mentioned and it was successful, dmesg not output enable-hw.
But!!! I still need to use SPI, and I will continue to execute jetson_io.py to check SPI, and then restart /boot/dtb will update to user-custom.dtb…

Can I only use this method?

Blockquote
sudo dtc -I fs -O dts -o extracted_proc.dts /proc/device-tree
$ sudo vi extracted_proc.dts # edited device tree.
$ sudo dtc -I dts -O dtb -o tegra194-p2888-0001-p2822-0000-base.dtb extracted_proc.dts
$ sudo dd if=tegra194-p2888-0001-p2822-0000-base.dtb of=/dev/mmcblk0p31