I have the following questions for enabling SPI slave:
(1). What DTB changes are needed to configure a SPI bus as slave instead of master?
(2). What kernel configuration changes or patches are needed to enable SPI slave for R28.1?
(3). What software changes are needed to use TX2 as SPI slave?
I was able to have spi0@3210000 and spi3@3240000 working as SPI masters and would like to configure spi0 as master and spi3 as slave and test spi0<->spi3 with jumpers between them.
Thanks in advanced for any input.
I was able to verify spi@c260000 (/dev/spidev1.0) in master mode and changed it to slave mode with the following DTB changes:
spi@c260000 {
compatible = "nvidia,tegra186-spi-slave";
reg = <0x0 0xc260000 0x0 0x10000>;
interrupts = <0x0 0x25 0x4>;
nvidia,dma-request-selector = <0x19 0x10>;
nvidia,rx-trigger-words = <0x0>;
#address-cells = <0x1>;
#size-cells = <0x0>;
#stream-id-cells = <0x1>;
dmas = <0x19 0x10 0x19 0x10>;
dma-names = "rx", "tx";
nvidia,clk-parents = "pll_p", "osc";
spi-max-frequency = <0x17d7840>;
clocks = <0xd 0xde 0xd 0x10d 0xd 0x264>;
clock-names = "spi", "pll_p", "osc";
resets = <0xd 0x29>;
reset-names = "spi";
status = "okay";
linux,phandle = <0x78>;
phandle = <0x78>;
spi@0 {
compatible = "spidev";
reg = <0x0>;
spi-max-frequency = <0x17d7840>;
};
};
I re-built kernel by adding “CONFIG_SPI_TEGRA124_SLAVE=y” to “tegra18_defconfig” and made changes to “spi-tegra124-slave.c” (attached).
I connected SPI master (/dev/spidev0.0) to slave in the following way:
SPI1.0_SCK <= SCI0.0_SCK
SPI1.0_MOSI <= SPI0.0_MOSI
SPI1.0_CS <= SPI0.0_CS.
and run test:
./spidev_test -D /dev/spidev1.0 -s 1000000 -d 1000000 & ./spidev_test -D /dev/spidev0.0 -s 1000000
but I got error in “dmesg”:
spi-tegra124-slave c260000.spi: Timeout waiting for master
spi_master spi1: failed to transfer one message from queue
spi-tegra124-slave.c (66 KB)
I believe one issue is how can I change directions of “/dev/spidev1.0”.
E.g.,
(1) how to change spi_sck, spi_cs and spi_mosi from output to input.
(2).how to change spi_miso from input to output.
I could not find the above pins in TX2 pinmux spreadsheet.
I was able to change pin directions of “/dev/spidev1.0” by adding the folloing pinmux dtsi file.
#include <dt-bindings/pinctrl/pinctrl-tegra.h>
/ {
pinmux@2430000 {
pinctrl-names = "default", "drive", "unused";
pinctrl-0 = <&pinmux_default>;
pinctrl-1 = <&drive_default>;
pinctrl-2 = <&pinmux_unused_lowpower>;
pinmux_default: common {
gpio_sen1_pv1 {
nvidia,pins = "gpio_sen1_pv1";
nvidia,function = "spi2";
nvidia,pull = <TEGRA_PIN_PULL_NONE>;
nvidia,tristate = <TEGRA_PIN_ENABLE>;
nvidia,enable-input = <TEGRA_PIN_ENABLE>;
nvidia,lpdr = <TEGRA_PIN_DISABLE>;
};
gpio_sen2_pv2 {
nvidia,pins = "gpio_sen2_pv2";
nvidia,function = "spi2";
nvidia,pull = <TEGRA_PIN_PULL_NONE>;
nvidia,tristate = <TEGRA_PIN_ENABLE>;
nvidia,enable-input = <TEGRA_PIN_ENABLE>;
nvidia,lpdr = <TEGRA_PIN_DISABLE>;
};
gpio_sen3_pv3 {
nvidia,pins = "gpio_sen3_pv3";
nvidia,function = "spi2";
nvidia,pull = <TEGRA_PIN_PULL_NONE>;
nvidia,tristate = <TEGRA_PIN_ENABLE>;
nvidia,enable-input = <TEGRA_PIN_ENABLE>;
nvidia,lpdr = <TEGRA_PIN_DISABLE>;
};
gpio_sen4_pv4 {
nvidia,pins = "gpio_sen4_pv4";
nvidia,function = "spi2";
nvidia,pull = <TEGRA_PIN_PULL_NONE>;
nvidia,tristate = <TEGRA_PIN_ENABLE>;
nvidia,enable-input = <TEGRA_PIN_ENABLE>;
nvidia,lpdr = <TEGRA_PIN_DISABLE>;
};
};
pinmux_unused_lowpower: unused_lowpower {
};
drive_default: drive {
};
};
};
When I rerun the test:
./spidev_test -D /dev/spidev1.0 -s 1000000 -d 1000000 & ./spidev_test -D /dev/spidev0.0 -s 1000000
I still got errors:
spi-tegra124-slave c260000.spi: Probe Deferred, ret -517
spi-tegra124-slave c260000.spi: Timeout waiting for master
Hi yahoo2016
There should be delay between running slave and master to avoid master test starting before slave is properly configured to receive data.
./spidev_test -D /dev/spidev1.0 -s 1000000 -d 1000000 & ./spidev_test -D /dev/spidev0.0 -s 1000000
Should be replace with
./spidev_test -D /dev/spidev1.0 -s 1000000 -d 1000000 & sleep 0.5 & ./spidev_test -D /dev/spidev0.0 -s 1000000
In case it still fails, you can get more info about failure by enabling debug logs
Using option -zzz for spidev_test could print more debug info about test
Debug logs for driver can print info about drivers.
echo -n “file drivers/spi/spi-tegra114.c +p” > /sys/kernel/debug/dynamic_debug/control
echo -n “file drivers/spi/spi-tegra124-slave.c +p” > /sys/kernel/debug/dynamic_debug/control
Hi ShaneCCC,
I tried you suggested but still got the same errors.
I changed /dev/spidev1.0 back to SPI master mode without changing pinmux dtsi file, the SPI master mode still works.
It appears pinmax changing SPI pins to slave mode did not work.
Is it necessary to change pin directions of SPI bus in dtis file? What is the correct way to change SPI bus pin direction? I have my pinmux dtsi file included in post #4.
Thanks
Any update about this topic?
I had same issue like this:
spi-tegra124-slave 3240000.spi: Probe Deferred, ret -517