manonline
Posts: 11
Joined: Tue May 03, 2016 6:48 pm

SC16IS752 (SC16IS7XX driver) Device Tree problem

Tue May 03, 2016 9:50 pm

Hi all,

I'm new to Raspberry Pi and I'm already dealing with the Device Tree monster.

I'm trying to port an old project in which, over the years, I ran out of RAM. I want to re-use almost all the old hardware, which means I need to get multiple SC16IS752 chips running over SPI.

After hours of research about this, I found out that the RPI can use more than the HW CS by using GPIO CS. Running some tests I could add more CS with a DTO with kernel 4.1, but the SC16IS7XX SPI drivers are on 4.4 so I ran the rpi-update. Now, the additionals chip selects are nowhere to be seen :(

This is the DTO I used for the SC16IS752:

Code: Select all

/dts-v1/;
/plugin/;

/ {
   compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";

   fragment@0 {
      target = <&spi0>;
      frag0: __overlay__ {
         #address-cells = <1>;
         #size-cells = <0>;
         pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
         status = "okay";
         cs-gpios = <0>, <0>, <&gpio 23 1>, <&gpio 24 1>;

         spidev@2{
            compatible = "spidev";
            reg = <2>;   /* CE2 */
            #address-cells = <1>;
            #size-cells = <0>;
            spi-max-frequency = <500000>;
         };

         spidev@3{
            compatible = "spidev";
            reg = <3>;   /* CE3 */
            #address-cells = <1>;
            #size-cells = <0>;
            spi-max-frequency = <500000>;
         };
		 
		 sc16is752@2 {
			compatible = "nxp,sc16is752";
			reg = <2>;
			clocks = <&sc16is752_clk>;
			interrupt-parent = <&gpio>;
			interrupts = <2 2>; /* IRQ_TYPE_EDGE_FALLING */
			#gpio-controller;
			#gpio-cells = <2>;
			#spi-max-frequency = <4000000>;

			sc16is752_clk: sc16is752_clk {
			   compatible = "fixed-clock";
			   #clock-cells = <0>;
			   clock-frequency = <1843200>;
			};
		 };
      };
   };

   fragment@1 {
      target = <&gpio>;
      __overlay__ {
         spi0_cs_pins: spi0_cs_pins {
            brcm,pins = <23 24>;
            brcm,function = <1>; /* out */
         };
      };
   };

   __overrides__ {
      cs2_pin = <&frag0>,"cs-gpios:12", <&spi0_cs_pins>,"brcm,pins:0";
      cs3_pin = <&frag0>,"cs-gpios:24", <&spi0_cs_pins>,"brcm,pins:4";
   };
};
Am I missing something for the 4.4.y kernel?

Thanks in advance,
Mariano.

manonline
Posts: 11
Joined: Tue May 03, 2016 6:48 pm

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Wed May 04, 2016 6:32 pm

Well, I tried the DTS to add "spidev0.2" and "spidev0.3" and it failed to load:

Code: Select all

001710.416: Failed to load overlay 'spi-gpio-cs'
This is the DTS:

Code: Select all

/dts-v1/;
/plugin/;

/ {
   compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";

   fragment@0 {
      target = <&spi0>;
      frag0: __overlay__ {
         #address-cells = <1>;
         #size-cells = <0>;
         pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
         status = "okay";
         cs-gpios = <0>, <0>, <&gpio 20 1>, <&gpio 21 1>;

         spidev@2{
            compatible = "spidev";
            reg = <2>;   /* CE2 */
            #address-cells = <1>;
            #size-cells = <0>;
            spi-max-frequency = <500000>;
         };

         spidev@3{
            compatible = "spidev";
            reg = <3>;   /* CE3 */
            #address-cells = <1>;
            #size-cells = <0>;
            spi-max-frequency = <500000>;
         };
      };
   };

   fragment@1 {
      target = <&gpio>;
      __overlay__ {
         spi0_cs_pins: spi0_cs_pins {
            brcm,pins = <20 21>;
            brcm,function = <1>; /* out */
         };
      };
   };

   __overrides__ {
      cs2_pin = <&frag0>,"cs-gpios:12", <&spi0_cs_pins>,"brcm,pins:0";
      cs3_pin = <&frag0>,"cs-gpios:24", <&spi0_cs_pins>,"brcm,pins:4";
   };
};
Compiled it and copied to /boot/overlays.

Looks like there is something different in 4.4.y, since this was working on 4.1. I'm new to Raspberry and Linux development, and most of all Device Tree.

Any guidance will be most welcome!

Regards,
Mariano.

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

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Wed May 04, 2016 6:54 pm

The 4.4 kernel changes the internals of the compiled overlays slightly, and the names also change to avoid versioning problems. You should really use an updated dtc - there's one in the kernel tree, and the Raspbian package is about to be updated - but for now you could get away with just calling your output 'spi-gpio-cs.dtbo'.

manonline
Posts: 11
Joined: Tue May 03, 2016 6:48 pm

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Wed May 04, 2016 8:03 pm

PhilE wrote:The 4.4 kernel changes the internals of the compiled overlays slightly, and the names also change to avoid versioning problems. You should really use an updated dtc - there's one in the kernel tree, and the Raspbian package is about to be updated - but for now you could get away with just calling your output 'spi-gpio-cs.dtbo'.
Phil, thanks for your response.

I tried renaming the file to *.dtbo and I'm still getting the error message in the log. Can you point me to the DTC in the repo so I can compile and try it?

Regards,
Mariano.

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

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Wed May 04, 2016 8:25 pm

dtc can be found in scripts/dtc.

What does:

Code: Select all

sudo vcdbg log msg |& grep -v -E "(gpioman|HDMI|clock):" 
show?

manonline
Posts: 11
Joined: Tue May 03, 2016 6:48 pm

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Wed May 04, 2016 8:28 pm

Output:

Code: Select all

001206.286: *** Restart logging
001207.442: Read command line from file 'cmdline.txt'
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
001456.616: Loading 'kernel7.img' to 0x8000 size 0x406e00
001460.255: Kernel trailer DTOK property says yes
001460.271: Kernel trailer DDTK property says yes
001463.711: Loading 'bcm2710-rpi-3-b.dtb' to 0x40ee00 size 0x3518
001531.229: dtparam: uart0_clkrate=48000000
001542.997: dtparam: i2c_arm=on
001551.242: dtparam: spi=on
001558.431: dtparam: audio=on
001582.802: Loaded overlay 'i2c-rtc'
001582.818: dtparam: pcf8563=true
001645.975: Failed to load overlay 'spi-gpio-cs'
001710.981: dtparam: arm_freq=1200000000
001751.892: dtparam: core_freq=400000000
001762.691: dtparam: cache_line_size=64
001786.928: Device tree loaded to 0x2fffc200 (size 0x3d6e)
004779.699: vchiq_core: vchiq_init_state: slot_zero = 0xfac80000, is_master = 1
004788.779: TV service:host side not connected, dropping notification 0x00000002, 0x00000002, 0x00000051

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

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Wed May 04, 2016 8:31 pm

And what does "ls /boot/overlays/spi*" show?

manonline
Posts: 11
Joined: Tue May 03, 2016 6:48 pm

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Wed May 04, 2016 8:36 pm

Code: Select all

-rwxr-xr-x 1 root root 1547 May  3 17:51 /boot/overlays/spi1-1cs.dtbo
-rwxr-xr-x 1 root root 1920 May  3 17:51 /boot/overlays/spi1-2cs.dtbo
-rwxr-xr-x 1 root root 2293 May  3 17:51 /boot/overlays/spi1-3cs.dtbo
-rwxr-xr-x 1 root root 1547 May  3 17:51 /boot/overlays/spi2-1cs.dtbo
-rwxr-xr-x 1 root root 1920 May  3 17:51 /boot/overlays/spi2-2cs.dtbo
-rwxr-xr-x 1 root root 2293 May  3 17:51 /boot/overlays/spi2-3cs.dtbo
-rwxr-xr-x 1 root root  330 Sep 23  2015 /boot/overlays/spi-bcm2708-overlay.dtb
-rwxr-xr-x 1 root root  330 Aug 21  2015 /boot/overlays/spi-bcm2835-overlay.dtb
-rwxr-xr-x 1 root root  473 Sep 23  2015 /boot/overlays/spi-dma-overlay.dtb
-rwxr-xr-x 1 root root  666 May  3 17:51 /boot/overlays/spi-gpio35-39.dtbo
-rwxr-xr-x 1 root root 1496 May  4 16:58 /boot/overlays/spi-gpio-cs-overlay.dtbo

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

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Wed May 04, 2016 8:37 pm

You got the name wrong - it should be spi-gpio-cs.dtbo not spi-gpio-cs-overlay.dtbo .

manonline
Posts: 11
Joined: Tue May 03, 2016 6:48 pm

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Wed May 04, 2016 8:52 pm

You got it right! Now I can see spidev0.2 and spidev0.3, thanks!

So, it seems that the DTB file name matters. What should be the name for the following DTB?
SC16IS752 Device Tree:
/dts-v1/;
/plugin/;

/ {
compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";

fragment@0 {
target = <&spi0>;
frag0: __overlay__ {
#address-cells = <1>;
#size-cells = <0>;
pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
status = "okay";
cs-gpios = <0>, <0>, <&gpio 23 1>, <&gpio 24 1>;

spidev@2{
compatible = "spidev";
reg = <2>; /* CE2 */
#address-cells = <1>;
#size-cells = <0>;
spi-max-frequency = <500000>;
};

spidev@3{
compatible = "spidev";
reg = <3>; /* CE3 */
#address-cells = <1>;
#size-cells = <0>;
spi-max-frequency = <500000>;
};

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

sc16is752_clk: sc16is752_clk {
compatible = "fixed-clock";
#clock-cells = <0>;
clock-frequency = <1843200>;
};
};
};
};

fragment@1 {
target = <&gpio>;
__overlay__ {
spi0_cs_pins: spi0_cs_pins {
brcm,pins = <23 24>;
brcm,function = <1>; /* out */
};
};
};

__overrides__ {
cs2_pin = <&frag0>,"cs-gpios:12", <&spi0_cs_pins>,"brcm,pins:0";
cs3_pin = <&frag0>,"cs-gpios:24", <&spi0_cs_pins>,"brcm,pins:4";
};
};

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

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Wed May 04, 2016 9:00 pm

You can call the overlay whatever you like, but the filename must be <overlay>.dtbo, i.e. whatever you want to put in the dtoverlay= line, add .dtbo and use that as the filename. I would recommend sticking to alphanumerics and hyphens/dashes.

manonline
Posts: 11
Joined: Tue May 03, 2016 6:48 pm

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Wed May 04, 2016 9:11 pm

Crystal clear.

I was able to load the DTO but the /dev/ttySCx ports are not appearing yet. I will play around with this and let you know the results.

Thanks for your assistance!

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

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Thu May 05, 2016 9:54 am

Now the overlay is loading and doing something, lets take a look at what's in the SC16IS752 overlay.

The first thing I notice is that you have both an spidev and a real device with a driver configured to use CS/CE 2. This is wrong, although I'm not sure what will happen when you try. If you look at other SPI overlays (e.g. enc28j60) you will see they disable the spidev nodes for CSs they use for their devices:

Code: Select all

        fragment@1 {
                target = <&spidev0>;
                __overlay__ {
                        status = "disabled";
                };
        };
In your case you can just delete spidev@2.

Secondly, I've not seen a clock being declared inside another device like that. Does it work? I would expect to see it created by its own fragment targeting the "clocks" node ("target = <&clocks>;"), but being a fixed clock it might work as it is.

There's also something funny about the pinctrl declarations. The base .dts file reserves pins 7 & 8 for chip selects; you are adding two more, but only reserving the new pins not the original ones. Fortunately the pins are being used as GPIOs and they can be claimed at run-time - reserving them in this way is just to prevent one application trying to use them for a device-specific function (Alt0 for SPI0) while another uses the same pin for GPIO; it is a quirk of the GPIO/pinctrl mechanisms that their reservation mechanisms are intentionally (brokenly, in my opinion) independent.

manonline
Posts: 11
Joined: Tue May 03, 2016 6:48 pm

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Thu May 05, 2016 3:03 pm

Ok, I just deleted the spidev@2 and spidev@3 since I added them to use them for the SC16IS752. I think I can redefine the SPI to replace the original CS pins:

Code: Select all

cs-gpios = <&gpio 23 1>, <&gpio 24 1>;
Instead of

Code: Select all

cs-gpios = <0>, <0>, <&gpio 23 1>, <&gpio 24 1>;
I'm trying to use those pins because the board I'm trying to use is an Arduino-like shield board using the ARPI600 adapter. But looking closer the CS pins should be pin 29 and 31 (GPIO 5 and 6 respectively), so I will change the DTS to say:

Code: Select all

cs-gpios = <&gpio 5 1>, <&gpio 6 1>;
About the clock being inside another device, I copied from another post (viewtopic.php?t=128892&p=904524). There you propose the clock being outside the device, but another member there shared his working DTS (for I2C), and I just stuck to that. I will have in mind adding a new fragment targeting clocks.

After all, this is the resulted DTS:

Code: Select all

/dts-v1/;
/plugin/;

/	{
	compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";

	fragment@0 {
		target = <&spi0>;
		frag0: __overlay__ {
			#address-cells = <1>;
			#size-cells = <0>;
			pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
			status = "okay";
			cs-gpios = <&gpio 5 1>, <&gpio 6 1>;
			
			sc16is752: sc16is752@0 {
				compatible = "nxp,sc16is752";
				reg = <0>;
				clocks = <&sc16is752_clk>;
				interrupt-parent = <&gpio>;
				interrupts = <2 2>; /* IRQ_TYPE_EDGE_FALLING */
				#gpio-controller;
				#gpio-cells = <2>;
				#spi-max-frequency = <4000000>;

				sc16is752_clk: sc16is752_clk {
					compatible = "fixed-clock";
					#clock-cells = <0>;
					clock-frequency = <1843200>;
				};
			};
		};
	};

	fragment@1 {
		target = <&gpio>;
		__overlay__ {
			spi0_cs_pins: spi0_cs_pins {
				brcm,pins = <5 6>;
				brcm,function = <1>; /* out */
			};
		};
	};
   
	fragment@2 {
		target = <&spidev0>;
		__overlay__ {
			status = "disabled";
		};
	};

	__overrides__ {
		cs2_pin = <&frag0>,"cs-gpios:12", <&spi0_cs_pins>,"brcm,pins:0";
		cs3_pin = <&frag0>,"cs-gpios:24", <&spi0_cs_pins>,"brcm,pins:4";
	};
};
I compiled and installed it. This is the output log:

Code: Select all

pi@raspberrypi:~ $ sudo vcdbg log msg |& grep -v -E "(gpioman|HDMI|clock):"     001210.316: *** Restart logging
001211.472: Read command line from file 'cmdline.txt'
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
001460.645: Loading 'kernel7.img' to 0x8000 size 0x406e00
001464.283: Kernel trailer DTOK property says yes
001464.298: Kernel trailer DDTK property says yes
001467.734: Loading 'bcm2710-rpi-3-b.dtb' to 0x40ee00 size 0x3518
001535.312: dtparam: uart0_clkrate=48000000
001547.068: dtparam: i2c_arm=on
001555.310: dtparam: spi=on
001562.508: dtparam: audio=on
001586.879: Loaded overlay 'i2c-rtc'
001586.895: dtparam: pcf8563=true
001662.873: Loaded overlay 'sc16is752-spi'
001778.568: dtparam: arm_freq=1200000000
001819.781: dtparam: core_freq=400000000
001830.824: dtparam: cache_line_size=64
001856.278: Device tree loaded to 0x2fffc100 (size 0x3ef8)
004833.600: vchiq_core: vchiq_init_state: slot_zero = 0xfac80000, is_master = 1
004842.686: TV service:host side not connected, dropping notification 0x00000002, 0x00000002, 0x00000051
The overlay is loaded successfully, but there is no log entry about being working, and there is no ttySCx in /dev. I will test the CS pins with a scope. Is there a way to know if the driver is loaded correctly? Checking the driver code I see some "#ifdef CONFIG_SERIAL_SC16IS7XX_SPI" but no definitions. I can only assume this symbol is defined elsewhere, but I'm not yet familiar with Linux kernel.

I will let you know the scope results and I'm going to try to move the clock definition to its own fragment.

Thanks for all the help, it's really enlightening.

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

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Thu May 05, 2016 5:07 pm

Hmm - are you building your own kernel? Foundation defconfigs (bcmrpi_defconfig and bcm2709_defconfig) don't set SERIAL_SC16IS7XX_CORE, so the module isn't built.

If you are building your own kernel, you can see if the module is loaded using lsmod.

manonline
Posts: 11
Joined: Tue May 03, 2016 6:48 pm

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Thu May 05, 2016 6:04 pm

Well, that could be the issue. I'm using the default 4.4.y build, downloaded by rpi-update. I will try compiling the kernel using the kernel build tutorial in the documentation section of the site. Where should I set the SERIAL_SC16IS7XX_CORE?

lsmod didn't return anything like SC16IS7XX, and the scope tests resulted in no CS activity, so it looks like I have to build the kernel.

manonline
Posts: 11
Joined: Tue May 03, 2016 6:48 pm

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Thu May 05, 2016 8:01 pm

Figured out how to enable the SC16IS7XX driver with "make menuconfig". I started compiling locally but a quick search in the forum tells me it will take 5hs or more. I will set up a VM with Ubuntu tonight and cross-compile.

manonline
Posts: 11
Joined: Tue May 03, 2016 6:48 pm

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Fri May 06, 2016 7:26 pm

Well, I recompiled the kernel with the SC16IS7XX driver enabled with menuconfig prior to build (Device drivers -> Character devices -> Serial drivers -> <*> SC16IS7xx serial support -> [*] SC16IS7xx for spi interface).

I can see the driver module is kind of compiled:

Code: Select all

pi@raspberrypi:~/dev/linux $ cat /lib/modules/$(uname -r)/modules.builtin | grep "sc16"
kernel/drivers/tty/serial/sc16is7xx.ko
But I see no other traces.

Code: Select all

pi@raspberrypi:~/dev/linux $ sudo vcdbg log msg |& grep -v -E "(gpioman|HDMI|clock):"
001276.508: *** Restart logging
001277.667: Read command line from file 'cmdline.txt'
dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait
001528.064: Loading 'kernel7.img' to 0x8000 size 0x40768c
001531.706: Kernel trailer DTOK property says yes
001531.719: Kernel trailer DDTK property says yes
001534.044: Loading 'bcm2710-rpi-3-b.dtb' to 0x40f68c size 0x3518
001601.683: dtparam: uart0_clkrate=48000000
001613.474: dtparam: i2c_arm=on
001621.786: dtparam: spi=on
001628.999: dtparam: audio=on
001653.254: Loaded overlay 'i2c-rtc'
001653.270: dtparam: pcf8563=true
001729.202: Loaded overlay 'sc16is752-spi'
001844.548: dtparam: arm_freq=1200000000
001885.812: dtparam: core_freq=400000000
001896.868: dtparam: cache_line_size=64
001921.823: Device tree loaded to 0x2fffc100 (size 0x3ef8)
004892.479: vchiq_core: vchiq_init_state: slot_zero = 0xfac80000, is_master = 1
004901.601: TV service:host side not connected, dropping notification 0x00000002, 0x00000002, 0x00000051

Code: Select all

pi@raspberrypi:~/dev/linux $ lsmod
Module                  Size  Used by
bnep                   10340  2
hci_uart               17943  1
btbcm                   5929  1 hci_uart
bluetooth             326067  22 bnep,btbcm,hci_uart
evdev                  11396  4
joydev                  9024  0
brcmfmac              186478  0
rtc_pcf8563             6264  0
brcmutil                5661  1 brcmfmac
cfg80211              427817  1 brcmfmac
rfkill                 16018  4 cfg80211,bluetooth
snd_bcm2835            20511  3
snd_pcm                75826  1 snd_bcm2835
snd_timer              19160  1 snd_pcm
snd                    51844  9 snd_bcm2835,snd_timer,snd_pcm
i2c_bcm2708             4770  0
spi_bcm2835             7286  0
bcm2835_gpiomem         3040  0
bcm2835_wdt             3225  0
uio_pdrv_genirq         3164  0
uio                     8000  1 uio_pdrv_genirq
i2c_dev                 5859  0
fuse                   83461  3
ipv6                  347473  30
The overlay seems to load ok, but no port descriptor is created under /dev.

Has anyone tried this driver over SPI and got it working?

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

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Wed Jun 29, 2016 10:11 am

Now that another user is trying to bring up the SC16IS752 I had quick go at loading the overlay with some kernel tracing enabled. This is what I got:

Code: Select all

pi@raspberrypi:~$ sudo dtoverlay sc16is752.dtbo
[  317.850757] bus: 'platform': driver_probe_device: matched device 3f204000.spi with driver spi-bcm2835
[  317.860420] bus: 'platform': really_probe: probing driver spi-bcm2835 with device 3f204000.spi
[  317.870333] spi-bcm2835 3f204000.spi: prop pinctrl-0 index 1 invalid phandle
[  317.878893] spi-bcm2835 3f204000.spi: no pinctrl handle
[  317.886688] spi_master spi0: /soc/spi@7e204000/sc16is752@2 has no valid 'spi-max-frequency' property (-22)
[  317.896766] spi_master spi0: Failed to create SPI device for /soc/spi@7e204000/sc16is752@2
[  317.905856] bus: 'spi': driver_probe_device: matched device spi0.3 with driver spidev
[  317.914015] bus: 'spi': really_probe: probing driver spidev with device spi0.3
[  317.921559] spidev spi0.3: no default pinctrl state
[  317.926956] driver: 'spidev': driver_bound: bound to device 'spi0.3'
[  317.933613] bus: 'spi': really_probe: bound device spi0.3 to driver spidev
[  317.940953] bus: 'spi': driver_probe_device: matched device spi0.2 with driver spidev
[  317.949056] bus: 'spi': really_probe: probing driver spidev with device spi0.2
[  317.956533] spidev spi0.2: no default pinctrl state
[  317.961882] driver: 'spidev': driver_bound: bound to device 'spi0.2'
[  317.968433] bus: 'spi': really_probe: bound device spi0.2 to driver spidev
[  317.975649] /soc/spi@7e204000: could not find phandle
[  317.980846] spi spi0.0: setting up native-CS0 as GPIO 8
[  317.986319] pinctrl-bcm2835 3f200000.gpio: read 00000000 (8 => gpio_in)
[  317.993170] pinctrl-bcm2835 3f200000.gpio: write 01000000 (8 <= gpio_out)
[  318.000398] bus: 'spi': driver_probe_device: matched device spi0.0 with driver spidev
[  318.008496] bus: 'spi': really_probe: probing driver spidev with device spi0.0
[  318.015966] spidev spi0.0: no default pinctrl state
[  318.021269] driver: 'spidev': driver_bound: bound to device 'spi0.0'
[  318.027813] bus: 'spi': really_probe: bound device spi0.0 to driver spidev
[  318.035386] /soc/spi@7e204000: could not find phandle
[  318.040578] spi spi0.1: setting up native-CS1 as GPIO 7
[  318.045991] pinctrl-bcm2835 3f200000.gpio: read 01000000 (7 => gpio_in)
[  318.052822] pinctrl-bcm2835 3f200000.gpio: write 01200000 (7 <= gpio_out)
[  318.060052] bus: 'spi': driver_probe_device: matched device spi0.1 with driver spidev
[  318.068137] bus: 'spi': really_probe: probing driver spidev with device spi0.1
[  318.075599] spidev spi0.1: no default pinctrl state
[  318.080836] driver: 'spidev': driver_bound: bound to device 'spi0.1'
[  318.087507] bus: 'spi': really_probe: bound device spi0.1 to driver spidev
[  318.094688] driver: 'spi-bcm2835': driver_bound: bound to device '3f204000.spi'
[  318.102258] bus: 'platform': really_probe: bound device 3f204000.spi to driver spi-bcm2835
There are several problems here:
1) Through working with loading overlays at runtime I've discovered that creating a node in an overlay that writes over an existing node is a bad idea. Instead you have to use the existing node as the target of a fragment, otherwise you may disrupt the internal phandle links within the base DTB; this is the cause of the phandle errors.
2) The "spi-max-frequency" property of the sc16is752@2 node has a spurious "#" at the beginning.

After fixing those problems and the cs pin declarations as mentioned earlier I ended up with this:

Code: Select all

/dts-v1/;
/plugin/;

/ {
   compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";

   fragment@0 {
      target = <&spi0>;
      frag0: __overlay__ {
         #address-cells = <1>;
         #size-cells = <0>;
         status = "okay";
         cs-gpios = <&gpio 8 1>, <&gpio 7 1>, <&gpio 23 1>, <&gpio 24 1>;

         spidev@3{
            compatible = "spidev";
            reg = <3>;   /* CE3 */
            #address-cells = <1>;
            #size-cells = <0>;
            spi-max-frequency = <500000>;
         };
       
       sc16is752@2 {
         compatible = "nxp,sc16is752";
         reg = <2>;
         clocks = <&sc16is752_clk>;
         interrupt-parent = <&gpio>;
         interrupts = <2 2>; /* IRQ_TYPE_EDGE_FALLING */
         #gpio-controller;
         #gpio-cells = <2>;
         spi-max-frequency = <4000000>;

         sc16is752_clk: sc16is752_clk {
            compatible = "fixed-clock";
            #clock-cells = <0>;
            clock-frequency = <1843200>;
         };
       };
     };
   };

   fragment@1 {
      target = <&spi0_cs_pins>;
      __overlay__ {
         brcm,pins = <8 7 23 24>;
         brcm,function = <1>; /* out */
      };
   };

   __overrides__ {
      cs2_pin = <&frag0>,"cs-gpios:28", <&spi0_cs_pins>,"brcm,pins:8";
      cs3_pin = <&frag0>,"cs-gpios:40", <&spi0_cs_pins>,"brcm,pins:12";
   };
};
I can't get this overlay to work at runtime - the clock doesn't seem to be created - but when applied in config.txt it appears to be doing the right thing:

Code: Select all

[   13.012717] driver: 'sc16is7xx': driver_bound: bound to device 'spi0.2'
[   13.025604] bus: 'spi': really_probe: bound device spi0.2 to driver sc16is7xx

chadsey
Posts: 3
Joined: Tue Jul 12, 2016 12:04 am

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Tue Jul 12, 2016 12:21 am

I am also trying to get two SC16IS752 devices working on a raspberry pi. The devices are connected to spi0 on CS0 and CS1. I have been able to successfully get either device working, but not both together. When I try loading both instances of the driver, the second to load simply overwrites the /dev/ttysc0/1 nodes instead of creating /dev/ttysc2/3 nodes. I have created separate .dts overlay files and invoke them separately in the /boot/config.txt, but no joy.

DTS # 1 (sc16is752_1-overlay.dts

Code: Select all

/dts-v1/;
/plugin/;

/ {
   compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";

   fragment@0 {
      target = <&spidev0>;
      __overlay__ {
         status = "disabled";
      };
   };

   fragment@1 {
        target = <&spi0>;
        frag1: __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;
            pinctrl-names = "default";
            pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
            status = "okay";

            sc16is752: sc16is752@1 {
                compatible = "nxp,sc16is752";
                reg = <0>; /* CE0 */
                clocks = <&sc16is752_clk>;
                interrupt-parent = <&gpio>;  /* Could be 3? */
                interrupts = <20 2>; /* IRQ_TYPE_EDGE_FALLING */
                gpio-controller;
                #gpio-cells = <2>;
                spi-max-frequency = <4000000>;

                sc16is752_clk: sc16is752_clk {
                   compatible = "fixed-clock";
                   #clock-cells = <0>;
                   clock-frequency = <1843200>;
                };
           };
        };
   };

   fragment@2 {
      target = <&aux>;
      __overlay__ {
         status = "okay";
      };
   };


    __overrides__ {
      int_pin = <&sc16is752>,"interrupts:0";
    };
};


DTS # 2 (sc16is752_2-overlay.dts

Code: Select all

/dts-v1/;
/plugin/;

/ {
   compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";

   fragment@0 {
      target = <&spidev1>;
      __overlay__ {
         status = "disabled";
      };
   };

   fragment@1 {
        target = <&spi0>;
        frag1: __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;
            pinctrl-names = "default";
            pinctrl-0 = <&spi0_pins &spi0_cs_pins>;
            status = "okay";

            sc16is752: sc16is752@2 {
                compatible = "nxp,sc16is752";
                reg = <1>; /* CE1 */
                clocks = <&sc16is752_clk>;
                interrupt-parent = <&gpio>;  /* Could be 3? */
                interrupts = <21 2>; /* IRQ_TYPE_EDGE_FALLING */
                gpio-controller;
                #gpio-cells = <2>;
                spi-max-frequency = <4000000>;

                sc16is752_clk: sc16is752_clk {
                   compatible = "fixed-clock";
                   #clock-cells = <0>;
                   clock-frequency = <1843200>;
                };
           };
        };
   };

   fragment@2 {
      target = <&aux>;
      __overlay__ {
         status = "okay";
      };
   };


    __overrides__ {
      int_pin = <&sc16is752>,"interrupts:0";
    };
};
I would appreciate any help / Ideas

Cheers

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

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Tue Jul 12, 2016 10:08 am

The node naming in your overlay doesn't fit the conventions: with spi node names (e.g. "sc16is752@1"), the number after the "@" should match the "reg" value and contain the CE number. But this is a cosmetic issue and shouldn't cause a problem.

There might be a bug with using multiple instances of the driver. Does "dmesg -l err" show anything interesting?

chadsey
Posts: 3
Joined: Tue Jul 12, 2016 12:04 am

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Tue Jul 12, 2016 5:09 pm

Thanks for the prompt reply.

My thought at this point is that it may be a problem with the driver as well, however other people seem to be doing this (maybe with IIC?)

Here is the output from "dmesg -l err" with both instances loading
[ 0.963778] bcm2708_fb soc:fb: couldn't allocate a DMA channel
[ 0.969762] bcm2708_fb soc:fb: probe failed, err -19
[ 8.084093] Error: Driver 'spi-bcm2835' is already registered, aborting...
[ 8.210689] regmap_spi: exports duplicate symbol __devm_regmap_init_spi (owned by kernel)
[ 8.216608] regmap_spi: exports duplicate symbol __devm_regmap_init_spi (owned by kernel)
BTW I am using rpi-4.4.y kernel source
Cheers

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

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Wed Jul 13, 2016 9:25 am

I think I've found the problem. Although DT clocks are located using their phandles (references to labels - "<&sc16is752_clk>"), the clock framework expects clocks to have unique names. In the DT case the name can either come from the "clock-output-names" property or, in its absence, the name of the node that declares the clock. Because in your case the clock nodes both have the same name (which in my opinion ought to be OK because they are effectively local to each device), the second clock instance never gets created and the second driver instance hangs around waiting for it.

Renaming the clock nodes (and the overlays themselves to be more logical), I ended up with these:

sc16is752_0-overlay.dts

Code: Select all

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";

    fragment@0 {
        target = <&spidev0>;
        __overlay__ {
            status = "disabled";
        };
    };

    fragment@1 {
        target = <&spi0>;

        frag1: __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;
            status = "okay";

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

                sc16is752_clk: sc16is752_0_clk {
                    compatible = "fixed-clock";
                    #clock-cells = <0>;
                    clock-frequency = <1843200>;
                };
            };
        };
    };

    __overrides__ {
        int_pin = <&sc16is752>,"interrupts:0";
    };
};
sc16is752_1-overlay.dts

Code: Select all

/dts-v1/;
/plugin/;

/ {
    compatible = "brcm,bcm2835", "brcm,bcm2836", "brcm,bcm2708", "brcm,bcm2709";

    fragment@0 {
        target = <&spidev1>;
        __overlay__ {
            status = "disabled";
        };
    };

    fragment@1 {
        target = <&spi0>;
        frag1: __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;

            status = "okay";

            sc16is752: sc16is752@1 {
                compatible = "nxp,sc16is752";
                reg = <1>; /* CE1 */
                clocks = <&sc16is752_clk>;
                interrupt-parent = <&gpio>;
                interrupts = <21 2>; /* IRQ_TYPE_EDGE_FALLING */
                gpio-controller;
                #gpio-cells = <2>;
                spi-max-frequency = <4000000>;
		status = "okay";

                sc16is752_clk: sc16is752_1_clk {
                    compatible = "fixed-clock";
                    #clock-cells = <0>;
                    clock-frequency = <1843200>;
                };
            };
        };
    };

    __overrides__ {
        int_pin = <&sc16is752>,"interrupts:0";
    };
};
Despite the fact that those devices weren't present in my system, when I load both overlays I end up with:

Code: Select all

pi@raspberrypi:~$ ls /dev/ttySC*
/dev/ttySC0  /dev/ttySC1  /dev/ttySC2  /dev/ttySC3

chadsey
Posts: 3
Joined: Tue Jul 12, 2016 12:04 am

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Thu Jul 14, 2016 3:21 am

Thank you, that seems to work now, all 4 ttySC devices are present and seem to be working.

Cheers

MasterWuff
Posts: 10
Joined: Thu Jul 14, 2016 10:24 am
Location: Munich

Re: SC16IS752 (SC16IS7XX driver) Device Tree problem

Thu Aug 11, 2016 3:35 pm

Hi, I came across this post while I was looking after an overlay for the SC16IS752.
The post was very usefull and I managed to load two overlays for two SC16IS752 successfully.
But besides that I need to recompile the kernel and so on I I read about that here: https://www.raspberrypi.org/documentati ... uilding.md

Now I'm not really sure what to do. Yes of course I can follow the instructions on the side, but do I still get updates after recompiling the kernel? Is rpi-upgrade still possible or do I have to compile the kernel after each upgrade?
Besides that, can't I just compile the c-File (https://github.com/raspberrypi/linux/bl ... c16is7xx.c) to create a driver and load this one?

I'm asking that, cause I'm prototyping with the Raspberry Pi. Therefore I have more then one Raspberry and I don't want to compile each of them.

Return to “Device Tree”

Who is online

Users browsing this forum: No registered users and 1 guest