TX1 spi slave mode

How to change spi to slave mode , I changed tegra210-jetson-tx1-p2597-2180-a01-devkit.dts file ,and add the slave module in kernel , but there is still get no data.
spi@7000d400 {
compatible = “nvidia,tegra210-spi-slave”;
reg = <0x0 0x7000d400 0x0 0x200>;
interrupts = <0x0 0x3b 0x4>;
nvidia,dma-request-selector = <0x5c 0xf>;
iommus = <0x57 0xe>;
#address-cells = <0x1>;
#size-cells = <0x0>;
dmas = <0x5c 0xf 0x5c 0xf>;
dma-names = “rx”, “tx”;
nvidia,clk-parents = “pll_p”, “clk_m”;
status = “okay”;

	prod-settings {

		prod {
			prod = <0x4 0xfffff000 0x0>;
		};

		prod_c_flash {
			status = "disabled";
			prod = <0x4 0xffffffc0 0x7>;
		};

		prod_c_loop {
			status = "disabled";
			prod = <0x4 0xfffff000 0x44b>;
		};
	};

	spi0_0 {
		#address-cells = <0x1>;
		#size-cells = <0x0>;
		compatible = "spidev";
		reg = <0x0>;
		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 flyCatDog

  1. Did you probe the single?
  2. Does any kernel message while you send the command to the spi bus?
  3. Could you tell how you test it.

Hi flyCatDog
Did you enable these kernel config? CONFIG_SPI_TEGRA114_SLAVE and CONFIG_SPI_SPIDEV=y
And you need to specify nvidia,clk-pin please see example dt node in Documentation/devicetree/bindings/spi/nvidia,spi-slave-tegra124.txt. If you don’t know clk-pin in the driver (drivers/spi/spi-tegra124-slave.c) return success always form below function for 1st round of verification.

static inline int tegra_spi_ext_clk_enable(bool enable,
struct tegra_spi_data *tspi)
{
unsigned long misc_reg = 0;
int ret = 0;

    if (tspi->chip_data->new_features) {
            /* Enable external clock bit in SPI_MISC_REG */
            if (enable)
                    misc_reg |= SPI_MISC_EXT_CLK_EN;
            else
                    misc_reg &= (~SPI_MISC_EXT_CLK_EN);

            tegra_spi_writel(tspi, misc_reg, SPI_MISC_REG);
    } else {
            /* Software based clock control for metastability */
            ret = tegra_clk_pin_control(enable, tspi);
    }

    return ret;

}

I’m also working on Slave SPI on the TX1.

Quick question about the driver :

You mention CONFIG_SPI_TEGRA114_SLAVE and from the config file, it seems load both spi-tegra124-slave.c and spi-tegra114-slave.c. Which of the two files are actually used in the kernel module? So if I’m loading the module manually using insmod, which file should I load?

For the TX1 you should load the spi-tegra-114-slave.c

OK. But spi-tegra114-slave.c doesn’t seem to be using nvidia,clk-pin in the driver code, unlike spi-tegra124-slave.c

Also, is there a need to change the dmas and iommus in device tree to use the SPI as a slave??

I am using the default device tree with the following values

spi@7000d400 {
		compatible = "nvidia,tegra210-spi-slave";
		reg = <0x0 0x7000d400 0x0 0x200>;
		interrupts = <0x0 0x3b 0x4>;
		nvidia,dma-request-selector = <0x5d 0xf>;
		iommus = <0x46 0xe>;
		#address-cells = <0x1>;
		#size-cells = <0x0>;
		dmas = <0x5d 0xf 0x5d 0xf>;
		dma-names = "rx", "tx";
		nvidia,clk-parents = "pll_p", "clk_m";
		status = "okay";

                spi1_0 {
			#address-cells = <0x1>;
			#size-cells = <0x0>;
			compatible = "spidev";
			reg = <0x1>;
			spi-max-frequency = <0x1c9c380>;
		};

Below is one of our reference board’s DT it’s using the spi-slave mode.
And apologize for the early comment to use the spi-tegra114-slave.c, it’s should be the spi-tegra124-slave.c for the TX1, could you try to use the spi-tegra124-slave.c and I will confirm this information once I got the correct information.

spi@7000d400 {
		status = "okay";
		compatible = "nvidia,tegra124-spi-slave";
		nvidia,clk-pin = "gpio_x5_aud_px5";
		nvidia,gpio-slave-ready = <&gpio TEGRA_GPIO(K, 4) 0>; /*PK4*/
		nvidia,gpio-slave-ready-active-high;
		nvidia,rx-trigger-words = <0>;
	};

Thanks ShaneCCC.

I also found another issue with using spi-tegra124-slave.c.

As per this code below, it seems to try to find the pinmix dt node with the name tegra124-pinmux. But the default dt is named tegra210-xxx

if (tspi->clk_pin) {
		tspi->clk_pin_state_enabled = true;
		tspi->pctl_dev = pinctrl_get_dev_from_of_compatible
			("nvidia,tegra124-pinmux");
		if (!tspi->pctl_dev) {
			ret = -EINVAL;
			dev_err(&pdev->dev, "invalid pinctrl\n");
			goto exit_free_master;
		}

Also, I’m getting this error for the clk_pin you mentioned.

[  110.771166] tegra210-pinctrl 700008d4.pinmux: does not have pin group gpio_x5_aud_px5
[  110.779699] spi-tegra124-slave 7000d400.spi: invalid clk_pin group

We are going to try the SPI slave mode with the loop back. Will update to you here once implement done.

Thank you ShaneCCC! While you are testing out SPI Slave, could you also look at multiple consecutive SPI Slave DMA transfers? I am having issues with that as I have been posting here : https://devtalk.nvidia.com/default/topic/982253/tx1-in-spi-slave-mode-to-an-adc-/#5047983

Hi, guys.

Can someone clear this up for me:

spi@7000d400 {
		status = "okay";
		compatible = "nvidia,tegra124-spi-slave";
		nvidia,clk-pin = "gpio_x5_aud_px5";
		nvidia,gpio-slave-ready = <&gpio TEGRA_GPIO(K, 4) 0>; /*PK4*/
		nvidia,gpio-slave-ready-active-high;
		nvidia,rx-trigger-words = <0>;
	};

What is “nvidia,gpio-slave-ready = <&gpio TEGRA_GPIO(K, 4) 0>; /PK4/”? I’ve been trying to add this to my device tree but I keep getting a ‘syntax error’ when I try to compile it. This is for the JetsonTX1

Can someone give me a straight forward device tree configuration for spi@7000d400 for use with Spi-Slave, please.

Or what ‘gpio_x5_aud_px5’ is? Is it the SPI Clock pin on the J21 header (pin 23 on J21)

@David
Please remove those gpio-slave-ready* looks like it’s not used any more.

Hi @ShaneCCC, was there any resolution to attempting slave mode?

I already activated the spi@3240000 master mode with the guide “http://elinux.org/Jetson/TX2_SPI” and verifed it with a loopback test and check signals on the pin header J21.
Actually, I have to change it to slave mode.
So, I made ‘spidev.ko’ including the ‘spi-tegra124-slave.c’ by 'CONFIG_SPI_TEGRA124_SLAVE=y’configuration.
Below is my DT for SPI slave.

spi@3240000 {
	reg = <0x0 0x3240000 0x0 0x10000>;
	dmas = <0x19 0x12 0x19 0x12>;
	interrupts = <0x0 0x27 0x4>;
	compatible = "nvidia,tegra124-spi-slave";
	nvidia,clk-pin = "gpio_x5_aud_px5";
	nvidia,gpio-slave-ready-active-high;
	nvidia,rx-trigger-words = <0>;
	clock-names = "spi", "pll_p", "clk_m";
	reset-names = "spi";
	clocks = <0xd 0x4a 0xd 0x10d 0xd 0x261>;
	nvidia,dma-request-selector = <0x19 0x12>;
	resets = <0xd 0x2b>;
	nvidia,clock-always-on;
	status = "okay";
	#address-cells = <0x1>;
	phandle = <0x7d>;
	nvidia,clk-parents = "pll_p", "clk_m";
	#stream-id-cells = <0x1>;
	#size-cells = <0x0>;
	dma-names = "rx", "tx";
	linux,phandle = <0x7d>;
	spi0_0{
		compatible = "spidev";
		reg = <0x0>;
		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-delau = <0x0>;
	};
};

My TX2 have to work with a simple device which is periodically spitting out a short bitstream on an SPI port.
The device transmits just 2 bytes at 500 KHz with appropriate CS and CLK signals every 1s.
Naturally, it was proven device in real situation.

I have been trying get TX2 to receive data from peer device. Unfortunately, I saw the ‘Invalid argument’ message when the ‘SPI_IOC_MESSAGE()’ called.

Let me know if you see anything obviously missing or wrong.

HI @kisk9fb9 ,I have the same problem with you. Is your problem solved?