rasparator
Posts: 47
Joined: Wed Oct 14, 2020 5:39 am

Something wrong with my device tree for SPI slave device?

Mon Jan 11, 2021 10:05 am

Hello,
Below is my spi slave nfc device tree connected to spi0 of raspberry PI 4B running kernel 5.10.. Driver has been inbuilt and kernel is booted.
But when i do dmesg | grep spi or dmesg | grep nfc i get this output

https://imgur.com/MNnqsq7

My device tree is below :

Code: Select all

&spi0 {
        pinctrl-names = "default";
        pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
        cs-gpios = <&gpio 8 1>, <&gpio 7 1>;

        spidev0: spidev@0{
                compatible = "spidev";
                reg = <0>;      /* CE0 */
                #address-cells = <1>;
                #size-cells = <0>;
                spi-max-frequency = <125000000>;
        };

        spidev1: spidev@1{
                compatible = "spidev";
                reg = <1>;      /* CE1 */
                #address-cells = <1>;
                #size-cells = <0>;
                spi-max-frequency = <125000000>;
        };

         stnfc@0{
                reg = <0>;
                compatible = "st,stnfc";
                status = "okay";
                pinctrl-names = "default";
                spi-max-frequency = <1000000>;
                enable-gpio = <&gpio 16 GPIO_ACTIVE_LOW>;
                interrupt-parent = <&gpio>;
                interrupts = <19 2>;

        };
};
inside arch/arm/boot/dts/bcm2711-rpi-4-b.dts

i have already spi and can see spidev using lsmod and also /sys/bus/spi/devices/spi0.0 and spi0.1

https://imgur.com/TF7mVWz

thre is interrupt (gpio 6, pin 31) and wakeup (enable) pin connected to gpio 5 , pin 29)

i have below question ,
is the choice of pins correct?
is the device tree correct
If above two are true , should I be checking the hardware connections?


please assist.

Regards,
R

rasparator
Posts: 47
Joined: Wed Oct 14, 2020 5:39 am

Re: Something wrong with my device tree for SPI slave device?

Wed Jan 13, 2021 5:44 am

can any one please comment on this .
There is a separate thread for the same : viewtopic.php?f=28&t=298021&p=1795784#p1795784
Sorry for duplicating. May be we can discuss it there and I will request Moderator to delete this later.

in short I want to know the association of the new gpio pins (how and where to modify) associated with the driver in the device tree.
I have done a sample implementation in the linked forum.

Thanks in Advance !
Regards

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3600
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Something wrong with my device tree for SPI slave device?

Wed Jan 13, 2021 10:07 am

It's good that you posted a nudge - notifications seem to be unreliable, and this was the first I'd seen of your problem.

The reason it is failng to register the driver is that spidev has already claimed CS/CE 0 - you need to delete or disable ('status = "disabled";') the spidev@0 node.

rasparator
Posts: 47
Joined: Wed Oct 14, 2020 5:39 am

Re: Something wrong with my device tree for SPI slave device?

Wed Jan 13, 2021 5:27 pm

Sorry I didnt get.
Are you talking about deleting whole spidev block below

Code: Select all

spidev0: spidev@0{
                compatible = "spidev";
                reg = <0>;      /* CE0 */
                #address-cells = <1>;
                #size-cells = <0>;
                spi-max-frequency = <125000000>;
        };

I cant find 'status = "disabled" ?

what is notification you are talking about?

Regards

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3600
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Something wrong with my device tree for SPI slave device?

Wed Jan 13, 2021 5:32 pm

You would need to add it:

Code: Select all

spidev0: spidev@0{
                compatible = "spidev";
                reg = <0>;      /* CE0 */
                #address-cells = <1>;
                #size-cells = <0>;
                spi-max-frequency = <125000000>;
                status = "disabled";
        };

rasparator
Posts: 47
Joined: Wed Oct 14, 2020 5:39 am

Re: Something wrong with my device tree for SPI slave device?

Sat Jan 16, 2021 5:50 am

Seems like some kernel Panic.
Kernel is an a reboot loop after this change

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3600
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Something wrong with my device tree for SPI slave device?

Sat Jan 16, 2021 3:54 pm

I suggest you disable the stnfc node to confirm that is the cause of the problem.

rasparator
Posts: 47
Joined: Wed Oct 14, 2020 5:39 am

Re: Something wrong with my device tree for SPI slave device?

Tue Jan 19, 2021 6:53 am

OK i rebuild and did it on fresh sd card

I am getting this :

Linux raspberrypi 5.10.4-v8 #10 SMP PREEMPT Tue Jan 19 11:27:24 IST 2021 aarch64 GNU/Linux
pi@raspberrypi:~ $ dmesg | grep nfc
[ 0.151828] nfc: nfc_init: NFC Core ver 0.1
[ 1.318274] DIGITAL uart driver 'nfcst_uart [0]' registered
[ 4.906362] stnfc spi0.0: Error applying setting, reverse things back
[ 4.906398] stnfc: probe of spi0.0 failed with error -22
pi@raspberrypi:~ $ dmesg | grep spi
[ 4.906273] pinctrl-bcm2835 fe200000.gpio: pin gpio31 already requested by fe201000.serial; cannot claim for spi0.0
[ 4.906333] pinctrl-bcm2835 fe200000.gpio: pin-31 (spi0.0) status -22
[ 4.906362] stnfc spi0.0: Error applying setting, reverse things back
[ 4.906398] stnfc: probe of spi0.0 failed with error -22 pi@raspberrypi:~ $
my device tree is this one :

&spi0 {
pinctrl-names = "default";
pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
cs-gpios = <&gpio 8 1>, <&gpio 7 1>;

spidev0: spidev@0{
compatible = "spidev";
reg = <0>; /* CE0 */
#address-cells = <1>;
#size-cells = <0>;
spi-max-frequency = <125000000>;
status = "disabled";

};

spidev1: spidev@1{
compatible = "spidev";
reg = <1>; /* CE1 */
#address-cells = <1>;
#size-cells = <0>;
spi-max-frequency = <125000000>;
};

stnfc@0{
reg = <0>;
compatible = "st,stnfc";
status = "okay";
pinctrl-names = "default";
spi-max-frequency = <1000000>;
+pinctrl-0 = <&nfcdrv_spi0_pins>;
enable-gpio = <&gpio 29 GPIO_ACTIVE_LOW>;
interrupt-parent = <&gpio>;
interrupts = <31 2>;

};

};

&gpio {
spi0_pins: spi0_pins {
brcm,pins = <9 10 11>;
brcm,function = <BCM2835_FSEL_ALT0>;
};

+nfcdrv_spi0_pins: nfcdrv_spi0_pins {
+ brcm,pins = <29 31>;
+ brcm,function = <BCM2835_FSEL_ALT0>;
+ };


spi0_cs_pins: spi0_cs_pins {
brcm,pins = <8 7>;
brcm,function = <BCM2835_FSEL_GPIO_OUT>;
};

the modules are built inbuilt

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3600
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Something wrong with my device tree for SPI slave device?

Tue Jan 19, 2021 8:52 am

That error message doesn't leave much room for doubt:

Code: Select all

[ 4.906273] pinctrl-bcm2835 fe200000.gpio: pin gpio31 already requested by fe201000.serial; cannot claim for spi0.0
[ 4.906333] pinctrl-bcm2835 fe200000.gpio: pin-31 (spi0.0) status -22
Are you perhaps using header pin numbers? The pinctrl/gpio driver expects the "Broadcom" GPIO numbers. For example, header pins 8 and 10 usually carry GPIOs 14 and 15. On most Pis, GPIO31 is wired to the UART RX line from the Bluetooth modem, and this is preventing the stnfc driver from also using it.

29 & 31 sound like adjacent pins on the 40-pin header, which would make them GPIOs 5 & 6 respectively. Replace 29 with 5, 31 with 6, and try again.

rasparator
Posts: 47
Joined: Wed Oct 14, 2020 5:39 am

Re: Something wrong with my device tree for SPI slave device?

Tue Jan 19, 2021 12:11 pm

29 & 31 sound like adjacent pins on the 40-pin header, which would make them GPIOs 5 & 6 respectively. Replace 29 with 5, 31 with 6, and try again.

Modifications(done in vi arch/arm/boot/dts/bcm2711-rpi-4-b.dts ) in bold :
why do i see spi_bcm2835 and not spi_bcm2711?? its raspberry Pi 4 b .
.
.
spi-max-frequency = <1000000>;
pinctrl-0 = <&nfcdrv_spi0_pins>;
enable-gpio = <&gpio 5 GPIO_ACTIVE_LOW>;
interrupt-parent = <&gpio>;
interrupts = <6 2>;

};

&gpio {
spi0_pins: spi0_pins {
brcm,pins = <9 10 11>;
brcm,function = <BCM2835_FSEL_ALT0>;
};

***I doubt below code ..is it correct. I just need 2 gpios , one for interrupt , another for wakeup)****
nfcdrv_spi0_pins: nfcdrv_spi0_pins {
brcm,pins = <5 6>;
brcm,function = <BCM2835_FSEL_ALT0>;
};


pi@raspberrypi:~ $ dmesg | grep nfc
[ 0.151746] nfc: nfc_init: NFC Core ver 0.1
[ 1.322199] DIGITAL uart driver 'nfcst_uart [0]' registered
[ 4.857241] stnfc spi0.0: NFC: nfc_st_spi driver probe called
[ 4.869001] genirq: Failed to request resources for nfcst (irq 50) on irqchip pinctrl-bcm2835
[ 4.869126] stnfc spi0.0: err: irq request for nfc_st_spi is failed
[ 4.872273] nfcst_spi_probe+0x280/0x2b4
pi@raspberrypi:~ $ dmesg | grep spi
[ 4.857241] stnfc spi0.0: NFC: nfc_st_spi driver probe called
[ 4.869126] stnfc spi0.0: err: irq request for nfc_st_spi is failed
[ 4.870023] Modules linked in: spi_bcm2835(+) vc4(+) bcm2835_isp(C) bcm2835_v4l2(C) bcm2835_codec(C+) bcm2835_mmal_vchiq(C) v4l2_mem2mem cec videobuf2_vmalloc videobuf2_dma_contig videobuf2_memops videobuf2_v4l2 vc_sm_cma(C) videobuf2_common drm_kms_helper snd_bcm2835(C) videodev mc drm drm_panel_orientation_quirks snd_soc_core snd_compress snd_pcm_dmaengine snd_pcm snd_timer snd sg syscopyarea sysfillrect sysimgblt fb_sys_fops backlight uio_pdrv_genirq uio i2c_dev ip_tables x_tables ipv6
[ 4.872273] nfcst_spi_probe+0x280/0x2b4
[ 4.872327] spi_drv_probe+0x8c/0xf0
[ 4.872797] spi_add_device+0xc4/0x190
[ 4.872847] of_register_spi_device+0x208/0x390
[ 4.872905] spi_register_controller+0x440/0x7d0
[ 4.872976] bcm2835_spi_probe+0x17c/0x2f0 [spi_bcm2835]
[ 4.873571] bcm2835_spi_driver_init+0x2c/0x1000 [spi_bcm2835]

regards,

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3600
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Something wrong with my device tree for SPI slave device?

Tue Jan 19, 2021 12:20 pm

The SPI interfaces on BCM2711 are the same as on older SoCs, so we don't need a new driver.

1. What exactly are these GPIOs meant to do?

2. Why are you declaring them as requiring ALT0? For GPIOs 5 & 6 this makes them GPCLK1 and GPCLK2.

rasparator
Posts: 47
Joined: Wed Oct 14, 2020 5:39 am

Re: Something wrong with my device tree for SPI slave device?

Tue Jan 19, 2021 1:07 pm

1. What exactly are these GPIOs meant to do?
thre is interrupt (gpio 6, pin 31) and another wakeup (enable) pin connected to gpio 5 , pin 29.
one interrupts the Host , another host to slave for wake up ( active low )

2. Why are you declaring them as requiring ALT0? For GPIOs 5 & 6 this makes them GPCLK1 and GPCLK2.
I am not clear what to define for these two pins (interrupts and wakeup) and where?


pasting the DT configuration which works on BeagleboneBlack . I am looking for the similar one for RPI4B. Interrupt and wakeup pins are different there.
+&am33xx_pinmux {
+ spi0_pins: pinmux_spi0_pins {
+ pinctrl-single,pins = <
+ 0x150 (PIN_INPUT | MUX_MODE0) /* P9_22 (A17) spi0_sclk.spi0_sclk */
+ 0x154 (PIN_INPUT | MUX_MODE0) /* P9_21 (B17) spi0_d0.spi0_d0 */
+ 0x158 (PIN_INPUT | MUX_MODE0) /* P9_18 (B16) spi0_d1.spi0_d1 */
+ 0x15c (PIN_INPUT | MUX_MODE0) /* P9_17 (A16) spi0_cs0.spi0_cs0 */
+ >;
+ };
+
+ spi0_nfc_pins: pinmux_spi0_nfc_pins {
+ pinctrl-single,pins = <
+ 0x040 (PIN_OUTPUT_PULLDOWN | MUX_MODE7) /* P9_15 (R13) gpmc_a0.gpio1_16 EN */
+ 0x04C (PIN_INPUT_PULLDOWN | MUX_MODE7) /* P9_16 (T14) gpmc_a3.gpio1_19 IRQ */
+ >;
+ };
+};
+
+&spi0 {
+ status = "okay";
+ pinctrl-names = "default";
+ pinctrl-0 = <&spi0_pins>;
+
+ stnfc@0{
+ reg = <0>;
+ compatible = "st,stnfc";
+ status = "okay";
+ pinctrl-names = "default";
+ pinctrl-0 = <&spi0_nfc_pins>;
+
+ spi-max-frequency = <1000000>;
+
+ enable-gpio = <&gpio1 16 GPIO_ACTIVE_HIGH>;
+ //enable-gpio = <&gpio1 16 GPIO_ACTIVE_LOW>;
+
+ interrupt-parent = <&gpio1>;
+ interrupts = <19 IRQ_TYPE_EDGE_RISING>;
+ //interrupts = <19 IRQ_TYPE_EDGE_FALLING>;
+ };
+};
+
Regards

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 3600
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Something wrong with my device tree for SPI slave device?

Tue Jan 19, 2021 2:01 pm

If the pins are to be used for real GPIO (input and output controlled by the CPU) then it isn't necessary to declare the pins through pinctrl, but it does help to detect clashes (as you've seen).
An input is declared with BCM2835_FSEL_GPIO_IN, and an output with BCM2835_FSEL_GPIO_OUT. If you want to set the pulls as well, include "brcm.pull = ...".

In your case you probably want:

Code: Select all

nfcdrv_spi0_pins: nfcdrv_spi0_pins {
	brcm,pins = <5 6>;
	brcm,function = <BCM2835_FSEL_GPIO_OUT BCM2835_FSEL_GPIO_IN>;
	brcm,pull = <BCM2835_PUD_DOWN>;
};

rasparator
Posts: 47
Joined: Wed Oct 14, 2020 5:39 am

Re: Something wrong with my device tree for SPI slave device?

Tue Jan 19, 2021 3:16 pm

nfcdrv_spi0_pins: nfcdrv_spi0_pins {
brcm,pins = <5 6>;
brcm,function = <BCM2835_FSEL_GPIO_OUT BCM2835_FSEL_GPIO_IN>;
brcm,pull = <BCM2835_PUD_DOWN>;
};
after 13 posts and 2 weeks , it worked !!! Thank a ton !!
driver is probed now and an entry has been made in the spi0.1 . Behaviour is same as BBB now.

Regards,R

rasparator
Posts: 47
Joined: Wed Oct 14, 2020 5:39 am

Re: Something wrong with my device tree for SPI slave device?

Wed Jan 20, 2021 6:42 pm

back again !!
while interacting with the hardware using som user space programme , I get this :
nfcdriver spi0.0 phy timeout error
nfcdriver spi0.0 send recieve of frame fail with -110
Is this due to some incorrect default polarity of the interrupt or wake up?
or something else?
How to trouble shoot?
Regards

Return to “Device Tree”