This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TDA4VM: WKUP_GPIO as SPIDEV in Linux

Part Number: TDA4VM

Hi everybody,

on our custom board we have the following SPI connection to the WKUP domain.

I want to use it as SPIDEV master in Linux, and I have done the following configuration:

diff --git a/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts b/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts
index 6788a3611..a5c63f6da 100644
--- a/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts
+++ b/arch/arm64/boot/dts/ti/k3-j721e-common-proc-board.dts
@@ -283,6 +283,16 @@
 			J721E_WKUP_IOPAD(0x38, PIN_INPUT, 0) /* (A23) MCU_OSPI1_LBCLKO */
 		>;
 	};
+
+	mymcu_spi1_pins_default: mymcu_spi1_pins_default {
+		pinctrl-single,pins = <
+			J721E_WKUP_IOPAD(0xb0, PIN_OUTPUT, 0) /* (F26) WKUP_GPIO0_0.MCU_SPI1_CLK */
+			J721E_WKUP_IOPAD(0xb4, PIN_OUTPUT, 0) /* (F25) WKUP_GPIO0_1.MCU_SPI1_D0 */
+			J721E_WKUP_IOPAD(0xb8, PIN_INPUT, 0) /* (F28) WKUP_GPIO0_2.MCU_SPI1_D1 */
+			J721E_WKUP_IOPAD(0xc4, PIN_OUTPUT, 2) /* (G24) WKUP_GPIO0_5.MCU_SPI1_CS3 */
+		>;
+	};
+
 };
 
 &wkup_pmx0 {
@@ -309,6 +319,16 @@
 			J721E_WKUP_IOPAD(0x0088, PIN_INPUT, 0) /* MCU_MDIO0_MDIO */
 		>;
 	};
+
+	mymcu_spi1_pins_default: mymcu_spi1_pins_default {
+		pinctrl-single,pins = <
+			J721E_WKUP_IOPAD(0xb0, PIN_OUTPUT, 0) /* (F26) WKUP_GPIO0_0.MCU_SPI1_CLK */
+			J721E_WKUP_IOPAD(0xb4, PIN_OUTPUT, 0) /* (F25) WKUP_GPIO0_1.MCU_SPI1_D0 */
+			J721E_WKUP_IOPAD(0xb8, PIN_INPUT, 0) /* (F28) WKUP_GPIO0_2.MCU_SPI1_D1 */
+			J721E_WKUP_IOPAD(0xc4, PIN_OUTPUT, 2) /* (G24) WKUP_GPIO0_5.MCU_SPI1_CS3 */
+		>;
+	};
+
 };
 
 &wkup_uart0 {
@@ -913,3 +933,16 @@
 &main_uart2 {
 	status = "disabled";
 };
+
+
+&mcu_spi0 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&mymcu_spi1_pins_default>;
+	ti,spi-num-cs = <2>;
+	status = "okay";
+	spidev@1{
+		reg = <1>;
+		spi-max-frequency = <24000000>;
+		compatible = "linux,spidev";
+	};
+};
\ No newline at end of file
diff --git a/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi b/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi
index 31875a917..25168cc23 100644
--- a/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi
+++ b/arch/arm64/boot/dts/ti/k3-j721e-mcu-wakeup.dtsi
@@ -386,4 +386,14 @@
 			loczrama = <1>;
 		};
 	};
+	
+	mcu_spi0: spi@40300000 {
+		compatible = "ti,am654-mcspi","ti,omap4-mcspi";
+		reg = <0x0 0x40300000 0x0 0x400>;
+		interrupts = <GIC_SPI 848 IRQ_TYPE_LEVEL_HIGH>;
+		clocks = <&k3_clks 274 1>;
+		power-domains = <&k3_pds 274 TI_SCI_PD_EXCLUSIVE>;
+		#address-cells = <1>;
+		#size-cells = <0>;
+	};
 };
diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig
index c9a867ac3..0f04144bc 100644
--- a/arch/arm64/configs/defconfig
+++ b/arch/arm64/configs/defconfig
@@ -392,7 +392,7 @@ CONFIG_SPI_PL022=y
 CONFIG_SPI_ROCKCHIP=y
 CONFIG_SPI_QUP=y
 CONFIG_SPI_S3C64XX=y
-CONFIG_SPI_SPIDEV=m
+CONFIG_SPI_SPIDEV=y
 CONFIG_SPI_SUN6I=y
 CONFIG_SPMI=y
 CONFIG_PINCTRL_SINGLE=y

Is this correct or I am missing something here? At the moment whatever I send with spidev_test I get 0s back. The journalclt has the following logs:

root@j7-evm:~# journalctl | grep spi
Jun 17 14:17:21 j7-evm kernel: Kernel command line: console=ttyS2,115200n8 earlycon=ns16550a,mmio32,0x02800000 mtdparts=47040000.spi.0:512k(ospi.tiboot3),2m(ospi.tispl),4m(ospi.u-boot),128k(ospi.env),128k(ospi.env.backup),1m(ospi.sysfw),-@8m(ospi.rootfs);47034000.hyperbus:512k(hbmc.tiboot3),2m(hbmc.tispl),4m(hbmc.u-boot),256k(hbmc.env),1m(hbmc.sysfw),-@8m(hbmc.rootfs) root=PARTUUID=4109accf-02 rw rootfstype=ext4 rootwait
Jun 17 14:17:21 j7-evm kernel: cadence-qspi 47040000.spi: Controller calibration failed
Jun 17 14:17:21 j7-evm kernel: cadence-qspi 47040000.spi: Cadence QSPI NOR probe failed -22
Jun 17 14:17:21 j7-evm kernel: cadence-qspi: probe of 47040000.spi failed with error -22
Jun 17 14:17:21 j7-evm kernel: cadence-qspi 47050000.spi: unrecognized JEDEC id bytes: 00 00 00 00 00 00
Jun 17 14:17:21 j7-evm kernel: cadence-qspi 47050000.spi: Cadence QSPI NOR probe failed -2
Jun 17 14:17:21 j7-evm kernel: cadence-qspi: probe of 47050000.spi failed with error -2
Jun 17 14:17:22 j7-evm /usr/sbin/irqbalance[313]: No directory /sys/devices/platform/40300000.spi/: No such file or directory
Jun 17 14:17:22 j7-evm /usr/sbin/irqbalance[313]: IRQ 40300000.spi(15) guessed as class 0
Jun 17 14:17:22 j7-evm /usr/sbin/irqbalance[313]: IRQ 40300000.spi(15) guessed as class 0
Jun 17 14:17:22 j7-evm /usr/sbin/irqbalance[313]: IRQ 2100000.spi(22) guessed as class 0
Jun 17 14:17:22 j7-evm systemd-udevd[264]: 2100000.spi: Process '/sbin/modprobe of:NspiT(null)Cti,am654-mcspiCti,omap4-mcspi' failed with exit code 1.
Jun 17 14:17:22 j7-evm systemd-udevd[262]: spi1.1: Process '/sbin/modprobe spi:spidev' failed with exit code 1.
Jun 17 14:17:23 j7-evm systemd-udevd[265]: 40300000.spi: Process '/sbin/modprobe of:NspiT(null)Cti,am654-mcspiCti,omap4-mcspi' failed with exit code 1.
Jun 17 14:17:23 j7-evm systemd-udevd[262]: spi0.1: Process '/sbin/modprobe spi:spidev' failed with exit code 1.
Jun 17 14:17:23 j7-evm systemd-udevd[271]: 47040000.spi: Process '/sbin/modprobe of:NspiT(null)Cti,am654-ospi' failed with exit code 1.
Jun 17 14:17:23 j7-evm systemd-udevd[265]: 47050000.spi: Process '/sbin/modprobe of:NspiT(null)Cti,am654-ospi' failed with exit code 1.
Jun 17 14:17:24 j7-evm systemd-udevd[271]: 30e00000.spinlock: Process '/sbin/modprobe of:NspinlockT(null)Cti,am654-hwspinlock' failed with exit code 1.
Jun 17 14:17:32 j7-evm /usr/sbin/irqbalance[313]: No directory /sys/devices/platform/40300000.spi/: No such file or directory
Jun 17 14:17:32 j7-evm /usr/sbin/irqbalance[313]: IRQ 40300000.spi(15) guessed as class 0
Jun 17 14:17:32 j7-evm /usr/sbin/irqbalance[313]: IRQ 40300000.spi(15) guessed as class 0
Jun 17 14:17:32 j7-evm /usr/sbin/irqbalance[313]: IRQ 2100000.spi(22) guessed as class 0

Thanks,

Best regards,

Pouyan

  • Hi,

    One comment on dts. If you are using chip select 3 (CS3), then the 'reg' property spidev should be set to 3.


    Regards,
    Vishal

  • Hi Vishal,

    Thanks for the hint.

    I changed the reg to 3, for that I needed to change the 'ti,spi-num-cs' to 4 instead of 2.

    Also the memory and interrupt were configured for the MCU_SPI0 and I changed them accordingly to values for the MCU_SPI1

    I also disabled the connection between MCU_SP1 with MCSPI3 as described here. using the devmem2:

    devmem2 0x40F04060 w 0x00000001

    I can send the following command:

    ./spidev_test -D /dev/spidev0.3 -s 100000 -p "\x02\x00\x00\x00\x00\x00\x00\x00\x00" -v 

    and I can see the signal being sent with logic analyzer. I also receive information from my slave device (also visible on logic analyzer) but on Linux my RX is still shown as 0s. Did I still miss something here? (Green is RX, Yellow is Clock, Red is TX)

    Best regards,

    Pouyan

  • Looks like issue is with MISO connection to SoC.

    One experiment would be to change the mux of MISO line to GPIO and check if the SoC is able to read the status of the line properly.

    Which SDK version are you using? SDK 6.2 or SDK 7.0?
    If you are using SDK 7.0,, wkup_gpio is broken by default and needs additional changes.


    Regards,
    Vishal

  • Hi Vishal,

    We are using the SDK7.0.

    I did apply the patch you mentioned there, as it is part of our bringup. How can I change the MUX to GPIO? by not configuring it in the device tree?

    Thanks,

    Pouyan

  • Change the mux mode to 7

    J721E_WKUP_IOPAD(0xb8, PIN_INPUT, 7)

  • Hi Vishal,

    I set this as resolved wrongly, could you please set it as unresolved again. Thanks.

    We tested both MOSI and MISO as GPIO Inputs with this settings:

                            J721E_WKUP_IOPAD(0xb4, PIN_INPUT, 7) 
                            J721E_WKUP_IOPAD(0xb8, PIN_INPUT, 7) 
    

    I can see the changes, in Linux for both. 0 -> 1 in gpioxxxx/value

    And what is the next step?

    Best regards,

    Pouyan

  • Hi Pouyan,

    Is the pinmux direction correct for the D0 and D1 pins?
    Can you try reversing them?

    +			J721E_WKUP_IOPAD(0xb4, PIN_OUTPUT, 0) /* (F25) WKUP_GPIO0_1.MCU_SPI1_D0 */
    +			J721E_WKUP_IOPAD(0xb8, PIN_INPUT, 0) /* (F28) WKUP_GPIO0_2.MCU_SPI1_D1 */


    Regards,
    Vishal

  • Hi Vishal,

    we changed the settings to this and still have the same effect. So still getting zeros in RX

    +			J721E_WKUP_IOPAD(0xb4, PIN_INPUT, 0) /* (F25) WKUP_GPIO0_1.MCU_SPI1_D0 */
    +			J721E_WKUP_IOPAD(0xb8, PIN_OUTPUT, 0) /* (F28) WKUP_GPIO0_2.MCU_SPI1_D1 */

    Best regards,

    Pouyan

  • In the initial dts you shared, why is pinmux done twice? Can you share the full current dts again?
    Also, can you check what does /proc/interrupts show for spidev?



  • Hi Vishal,

    here is the content of our /proc/interrupts:

               CPU0       CPU1
      3:      10794       9467     GICv3  30 Level     arch_timer
      6:          0          0     GICv3  23 Level     arm-pmu
      8:          0          0     GICv3 884 Level     40b00000.i2c
      9:          0          0     GICv3 885 Level     40b10000.i2c
     10:          0          0     GICv3 928 Level     42120000.i2c
     13:          0          0     GICv3 892 Level     TI-am335x-adc.0.auto
     14:          0          0     GICv3 893 Level     TI-am335x-adc.1.auto
     15:          0          0     GICv3 881 Level     40310000.spi
     16:       1397          0     GICv3  69 Level     32c00000.mailbox thr_011
     17:          0          0     GICv3 804 Edge      arm-smmu-v3-evtq
     18:          0          0     GICv3 800 Edge      arm-smmu-v3-gerror
     19:       1306          0     GICv3 224 Level     2800000.serial
     20:         51          0     GICv3 225 Level     2810000.serial
     22:          0          0     GICv3 216 Level     2100000.spi
     23:          4          0     GICv3 232 Level     2000000.i2c
     24:          2          0     GICv3 233 Level     2010000.i2c
     25:          0          0     GICv3 234 Level     2020000.i2c
     26:          2          0     GICv3 235 Level     2030000.i2c
     27:          0          0     GICv3 236 Level     2040000.i2c
     28:          0          0     GICv3 237 Level     2050000.i2c
     29:          0          0     GICv3 238 Level     2060000.i2c
     31:          0          0     GICv3 596 Level     2ba0000.mcasp_tx
     32:          0          0     GICv3 597 Level     2ba0000.mcasp_rx
     33:        199          0     GICv3  35 Level     mmc0
     34:       9840          0     GICv3  36 Level     mmc1
     35:          0          0     GICv3 634 Level     tidss
     42:         31          0  MSI-INTA 15401056 Level     46000000.ethernet-tx0
     43:          0          0  MSI-INTA 15401057 Level     46000000.ethernet
     62:          0          0  MSI-INTA 13828536 Level     31150000.dma-controller chan0
     63:          0          0  MSI-INTA 13828537 Level     31150000.dma-controller chan1
     64:          0          0  MSI-INTA 13828538 Level     31150000.dma-controller chan2
     65:          0          0  MSI-INTA 13828539 Level     31150000.dma-controller chan3
     66:          0          0  MSI-INTA 13828540 Level     31150000.dma-controller chan4
    212:          8          0     GICv3  49 Level     ufshcd
    213:          0          0      INTR 391 Level     310d0000.cpts
    227:          0          0      GPIO   7 Edge    -davinci_gpio  GPIO Key USER2
    312:          0          0      GPIO   0 Edge    -davinci_gpio  GPIO Key USER1
    508:          0          0  MSI-INTA 13893648 Edge      31150000.dma-controller chan0
    550:          0          0  MSI-INTA 13894672 Edge      31150000.dma-controller chan1
    592:          0          0     GICv3 890 Level     46000000.ethernet
    596:          0          0     GICv3 152 Level     6000000.usb
    597:          0          0     GICv3 136 Level     xhci-hcd:usb1
    599:          0          0     GICv3 153 Level     6400000.usb
    600:          0          0     GICv3  43 Level     4e10000.trng
    IPI0:      5036       8320       Rescheduling interrupts
    IPI1:       186        307       Function call interrupts
    IPI2:         0          0       CPU stop interrupts
    IPI3:         0          0       CPU stop (for crash dump) interrupts
    IPI4:         0          0       Timer broadcast interrupts
    IPI5:         0          0       IRQ work interrupts
    IPI6:         0          0       CPU wake-up interrupts
    Err:          0
    

    The device tree configuration look like this at the moment:

    7384.dts.zip

    Thanks,

    Pouyan

  • Hi Pouyan,

    Does the interrupt count increase for 40310000.spi after you run your test?

    Regards,
    Vishal

  • Hi Pouyan,

    Could you try below test as well?
    Set all pins as input and then run spidev for a longer time.. Say for 32 bytes or more and see if we receive something after 8 bytes are sent

    + J721E_WKUP_IOPAD(0xb0, PIN_INPUT, 0) /* (F26) WKUP_GPIO0_0.MCU_SPI1_CLK */
    + J721E_WKUP_IOPAD(0xb4, PIN_INPUT, 0) /* (F25) WKUP_GPIO0_1.MCU_SPI1_D0 */
    + J721E_WKUP_IOPAD(0xb8, PIN_INPUT, 0) /* (F28) WKUP_GPIO0_2.MCU_SPI1_D1 */
    + J721E_WKUP_IOPAD(0xc4, PIN_INPUT, 2) /* (G24) WKUP_GPIO0_5.MCU_SPI1_CS3 */


    Regards,
    Vishal

  • Hi Vishal, 

    there was no change in the numbers of /proc/intterupts.

    But changing both of the D0/D1 to Input and set the register to disable the internal connection between mcuspi and main spi made the spidev work.

    Do you have any Suggestion why both of the DO/D1 should be configured as INPUT?
    Also do have a possibility to test the MCU_SPI1 on your samples?

    Thanks,

    Pouyan

  • Hi Pouyan,

    We think its the clk pin that needs to being set as input that helped. Could you try a test to confirm?

    Snippet below from TRM (Table 12-855. MCSPI I/O Signals (Master Mode))

    For SPI[7-5]_CLK, SPI[3-0]_CLK, and MCU_SPI[1-0]_CLK signals to work properly, the
    RXACTIVE bit of the appropriate CTRLMMR_WKUP_PADCONFIGx/
    CTRLMMR_PADCONFIGy registers should be set to 0x1 because of retiming purposes.

    ----

    On TI TDA4 EVM we don't have any SPI slaves populated, so we have not tested on TDA4.
    But the same IP is used on other chips and the same driver is used there and validated.

    Regards,
    Vishal

  • Hi Vishal,

    I did not understand this "We think its the clk pin that needs to being set as input that helped. Could you try a test to confirm?" , what should I Change now exactly in the device tree?

    Regards,

    Pouyan

  • Hi Pouyan,

    We are referring to MCU_SPI1_CLK pin. Changing this to input would have resolved the issue.
    Could you do a test where you change this pin to INPUT and leave D0 and D1 as how it was.

    Regards,
    Vishal

  • Hi Vishal,

    Thanks for the info I tested this and it also works:

           mymcu_spi1_pins_default: mymcu_spi1_pins_default {
                   pinctrl-single,pins = <
                            J721E_WKUP_IOPAD(0xb0, PIN_INPUT, 0) /* (F26) WKUP_GPIO0_0.MCU_SPI1_CLK */
                            J721E_WKUP_IOPAD(0xb4, PIN_INPUT, 0) /* (F25) WKUP_GPIO0_1.MCU_SPI1_D0 */
                            J721E_WKUP_IOPAD(0xb8, PIN_OUTPUT, 0) /* (F28) WKUP_GPIO0_2.MCU_SPI1_D1 */
                            J721E_WKUP_IOPAD(0xc4, PIN_OUTPUT, 2) /* (G24) WKUP_GPIO0_5.MCU_SPI1_CS3 */
                            J721E_WKUP_IOPAD(0x44, PIN_OUTPUT, 5) /* (G22) MCU_OSPI1_D1.MCU_SPI1_CS1 */
                   >;
            };

    Best regards,

    Pouyan

  • Hi Pouyan,

    Thanks for the test.
    So the issue is rootcaused to pinmux of CLK line.

    If the issue is resolved, can we close this?

    Regards,
    Vishal

  • Yes Vishal,

    thanks, yes this can be closed.