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

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

No, you can’t using dd to update the partition. The dtb need encrypt then write to the partition and also need remove the dtb from FDT line in the extlinux.conf

What should I do to make new dtb and jetson_io take effect at the same time?

need your help@ShaneCCC