danergo
Posts: 28
Joined: Thu Oct 12, 2017 1:44 pm

[SOLVED] Multiple SC16IS752s on the same SPI causes an SPI error in dmesg

Wed Oct 06, 2021 11:03 am

Folks,

I have attached 2 SC16IS752 breakout boards to SPI0.

This way I can have 4 UARTs (SC0..3).

All four ports are working, but I have these strange lines during boot (in dmesg):

Code: Select all

[   13.239108] spi-bcm2835 20204000.spi: chipselect 1 already in use
[   13.239160] spi_master spi0: spi_device register error /soc/spi@7e204000/spidev@1
[   13.239198] spi_master spi0: Failed to create SPI device for /soc/spi@7e204000/spidev@1
For the two boards I'm using SPI0 on GPIO9,10,11; Board1 uses CE0 (GPIO8), Board2 uses CE1 (GPIO7).

What can cause this error message, and do I have to fear of it?

This is my DTS I'm using for this purpose:

Code: Select all

    
/dts-v1/;
/plugin/;
    
/{
    compatible = "brcm,bcm2835";
    
    fragment@0 {
        target = <&spidev0>;
        __overlay__ {
            status = "disabled";
        };
    };
    
    fragment@1 {
        target = <&spi0>;
        __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;
            status = "okay";

            sc16is752_0: sc16is752@0 {
                compatible = "nxp,sc16is752";
                reg = <0>; /* CE0 */
                clocks = <&sc16is752_0_clk>;
                interrupt-parent = <&gpio>;
                interrupts = <24 2>; /* IRQ_TYPE_EDGE_FALLING */
                gpio-controller;
                #gpio-cells = <2>;
                spi-max-frequency = <4000000>;
            };
        };
    };

    fragment@2 {
        target = <&spi0>;
        __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;
            status = "okay";

            sc16is752_1 sc16is752@1 {
                compatible = "nxp,sc16is752";
                reg = <1>; /* CE1 */
                clocks = <&sc16is752_1_clk>;
                interrupt-parent = <&gpio>;
                interrupts = <26 2>; /* IRQ_TYPE_EDGE_FALLING */
                gpio-controller;
                #gpio-cells = <2>;
                spi-max-frequency = <4000000>;
            };
        };
    };

    fragment@3 {
        target-path = "/";
        __overlay__ {
            sc16is752_0_clk: sc16is752_spi0_0_clk {
                compatible = "fixed-clock";
                #clock-cells = <0>;
                clock-frequency = <14745600>;
            };
        };
    };
    
    fragment@4 {
        target-path = "/";
        __overlay__ {
            sc16is752_1_clk: sc16is752_spi0_1_clk {
                compatible = "fixed-clock";
                #clock-cells = <0>;
                clock-frequency = <14745600>;
            };
        };
    };
    
    __overrides__ {
        int0_pin = <&sc16is752_0>,"interrupts:0";
        xtal0 = <&sc16is752_0_clk>,"clock-frequency:0";

        int1_pin = <&sc16is752_1>,"interrupts:0";
        xtal1 = <&sc16is752_1_clk>,"clock-frequency:0";
    };
};
If I leave out one board from the DTS, this error message above is not coming. (Doesn't matter which board I'm leaving out).

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

Re: Multiple SC16IS752s on the same SPI causes an SPI error in dmesg

Wed Oct 06, 2021 11:11 am

That's an easy one. Have a look at fragment 0:

Code: Select all

    fragment@0 {
        target = <&spidev0>;
        __overlay__ {
            status = "disabled";
        };
    };
This prevents the spidev (SPI from user space) driver from grabbing CS 0 of SPI0. What you are missing is the equivalent for CS 1:

Code: Select all

    fragment@1 {
        target = <&spidev1>;
        __overlay__ {
            status = "disabled";
        };
    };
I've made it fragment 1, so you'll need to renumber the remaining fragments.

danergo
Posts: 28
Joined: Thu Oct 12, 2017 1:44 pm

Re: Multiple SC16IS752s on the same SPI causes an SPI error in dmesg

Wed Oct 06, 2021 1:36 pm

PhilE, thanks for the quick reply, I thought this will be easy for you. :)

I thought "spidev0" is for preventing the whole SPI0 device from using from user-space (whole including CS0,CS1,CS2).

In case "spidev0" does the prevention only for SPI0 CS0, how you would prevent accessing SPI1 CS0?

That's only for curiosity, but I'd like to understand the terminology :)

Thank you,
Cheers,
Dan

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

Re: Multiple SC16IS752s on the same SPI causes an SPI error in dmesg

Wed Oct 06, 2021 1:59 pm

This isn't so much terminology as names we have chosen. spidev0 and spidev1 are labels on some nodes in the Pi Device Tree files:

Code: Select all

		spi: spi0: spi@7e204000 {
			compatible = "brcm,bcm2835-spi";
			...
			spidev0: spidev@0 {
				compatible = "spidev";
				reg = <0>;
				#address-cells = <1>;
				#size-cells = <0>;
				spi-max-frequency = <125000000>;
			};
			spidev1: spidev@1 {
				compatible = "spidev";
				reg = <1>;
				#address-cells = <1>;
				#size-cells = <0>;
				spi-max-frequency = <125000000>;
			};
		};
With hindsight we should have called them spidev0_0 and spidev0_1, but we're here now.

The spi<n>-<m>cs overlays are different in that they provide the means for the user to disable the spidev nodes:

Code: Select all

Name:   spi1-2cs

Info:   Enables spi1 with two chip select (CS) lines and associated spidev
        dev nodes. The gpio pin numbers for the CS lines and spidev device node
        creation are configurable.
        N.B.: spi1 is only accessible on devices with a 40pin header, eg:
              A+, B+, Zero and PI2 B; as well as the Compute Module.

Usage:  dtoverlay=spi1-2cs,<param>=<val>

Params: cs0_pin                 GPIO pin for CS0 (default 18 - BCM SPI1_CE0).
        cs1_pin                 GPIO pin for CS1 (default 17 - BCM SPI1_CE1).
        cs0_spidev              Set to 'disabled' to stop the creation of a
                                userspace device node /dev/spidev1.0 (default
                                is 'okay' or enabled).
        cs1_spidev              Set to 'disabled' to stop the creation of a
                                userspace device node /dev/spidev1.1 (default
                                is 'okay' or enabled).
The idea here is that the responsibility for disabling spidev for a CS moves to the user, via the overlay, rather than falling on any other overlay that needs to use the CS.

By the way, I notice that the documentation about cs0_spidev and cs1_spidev, although correct, isn't as helpful as it could be - the following also works and requires less typing:

Code: Select all

dtoverlay=spi1_1cs,cs0_spidev=off

danergo
Posts: 28
Joined: Thu Oct 12, 2017 1:44 pm

Re: Multiple SC16IS752s on the same SPI causes an SPI error in dmesg

Wed Oct 06, 2021 3:37 pm

Thanks, appreciated.

We can change this one to [solved]. :)

Return to “Device Tree”