Sc16is7xx-spi & Rock-CM3

Hello ,

it is possible to use this chip with rock-CM3 via spi interface ?

I’m trying , but can’t find either a driver or an overlay .

os is deban 11.5,
kernel 4.19.193-56-rockchip-gf62b47f70096:

root@radxa-cm3-io:~# modprobe sc16is7xx
modprobe: FATAL: Module sc16is7xx not found in directory /lib/modules/4.19.193-56-rockchip-gf62b47f70096
root@radxa-cm3-io:~# 
root@radxa-cm3-io:~# find /boot/ -name sc16\*
root@radxa-cm3-io:~#

Some progress (dirty scratch):

  1. driver:
    https://wiki.radxa.com/Rock3/dev/Debian
    https://wiki.archlinux.org/title/Compile_kernel_module
    https://gist.github.com/Josua-SR/3ee497179b75e8e164e508f98b12d810

    wget https://releases.linaro.org/components/toolchain/binaries/7.3-2018.05/aarch64-linux-gnu/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz
    sudo tar xvf gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu.tar.xz -C /opt

    git clone -b stable-4.19-rock3 https://github.com/radxa/rockchip-bsp.git
    cd rockchip-bsp
    git submodule init
    git submodule update

    git checkout stable-4.19-rock3
    git fetch origin
    git rebase origin/stable-4.19-rock3
    git submodule update

    cd kernel
    export PATH="/opt/gcc-linaro-7.3.1-2018.05-x86_64_aarch64-linux-gnu/bin:${PATH}"
    export ARCH=arm64
    export CROSS_COMPILE=aarch64-linux-gnu-

    rock=192.168.10.98
    ssh -l rock $rock3 cat /proc/config.gz | gzip -dc > .config
    make EXTRAVERSION=-58-rockchip menuconfig
    #Device Drivers => Character devices => Serial drivers => SC16IS7xx serial support(M) => SC16IS7xx for I2C interface (*), SC16IS7xx for spi interface
    #Save, Exit, Exti …

    make EXTRAVERSION=-58-rockchip modules_prepare
    make EXTRAVERSION=-58-rockchip drivers/tty/serial/sc16is7xx.ko
    scp drivers/tty/serial/sc16is7xx.ko root@${rock3}:/lib/modules/4.19.193-58-rockchip-

    ssh -l root $rock
    depmod
    modprobe sc16is7xx

  2. dt-overlay
    based on https://github.com/Ysurac/raspberry_kernel_mptcp/blob/master/arch/arm/boot/dts/overlays/sc16is752-spi1-overlay.dts
    prepared such a file:
    cat sc16is752-spi1-overlay-rock.dts
    /dts-v1/;
    /plugin/;

    / {
    compatible = “radxa,radxa-cm3-io”, “rockchip,rk3566”;

     fragment@0 {
             target = <&spi3>;
             frag1: __overlay__ {
                     sc16is752: sc16is752@0 {
                             compatible = "nxp,sc16is752";
                             reg = <0>; /* CE0 */
                             clocks = <&sc16is752_clk>;
                             interrupt-parent = <&gpio3>;
                             interrupts = <3 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 = <14745600>;
                             };
                     };
             };
     };
    
     __overrides__ {
       int_pin = <&sc16is752>,"interrupts:0";
     };
    

    };

    dtc -I dts -O dtb sc16is752-spi1-overlay-rock.dts > sc16is752-spi1-overlay-rock.dtb
    scp sc16is752-spi1-overlay-rock.dtbo root@${rock3}:/boot/dtbs

    ssh -l root $rock3
    cd /boot/extlinux
    mv extlinux.conf extlinux.conf.orig
    cat >extlinux.conf <<EOF
    timeout 100
    menu title select kernel

    label kernel-4.19.193-58-rockchip-gbac1feba87f0
    kernel /vmlinuz-4.19.193-58-rockchip-gbac1feba87f0
    initrd /initrd.img-4.19.193-58-rockchip-gbac1feba87f0
    devicetreedir /dtbs/4.19.193-58-rockchip-gbac1feba87f0
    fdtoverlays /dtbs/4.19.193-58-rockchip-gbac1feba87f0/rockchip/overlay/rk3568-fiq-debugger-uart2m0.dtbo /dtbs/4.19.193-58-rockchip-gbac1feba87f0/rockchip/overlay/rk3568-disable-npu.dtbo /dtbs/4.19.193-58-rockchip-gbac1feba87f0/rockchip/overlay/rk3568-spi3-m0-cs0-spidev.dtbo /dtbs/sc16is752-spi1-overlay-rock.dtbo
    append root=UUID=00c3a219-6a77-4651-8508-8afe4ed8c9ec earlyprintk console=ttyFIQ0,1500000n8 console=tty1 consoleblank=0 loglevel=7 panic=10 rootwait rw init=/sbin/init rootfstype=ext4 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory swapaccount=1 switolb=1 coherent_pool=1m

    label kernel-backup
    kernel /vmlinuz-4.19.193-58-rockchip-gbac1feba87f0
    initrd /initrd.img-4.19.193-58-rockchip-gbac1feba87f0
    devicetreedir /dtbs/4.19.193-58-rockchip-gbac1feba87f0
    fdtoverlays /dtbs/4.19.193-58-rockchip-gbac1feba87f0/rockchip/overlay/rk3568-fiq-debugger-uart2m0.dtbo /dtbs/4.19.193-58-rockchip-gbac1feba87f0/rockchip/overlay/rk3568-disable-npu.dtbo
    append root=UUID=00c3a219-6a77-4651-8508-8afe4ed8c9ec earlyprintk console=ttyFIQ0,1500000n8 console=tty1 consoleblank=0 loglevel=7 panic=10 rootwait rw init=/sbin/init rootfstype=ext4 cgroup_enable=cpuset cgroup_memory=1 cgroup_enable=memory swapaccount=1 switolb=1 coherent_pool=1m
    EOF
    reboot

    ssh -l root $rock3
    ls -l /dev/ttySC*
    crw-rw---- 1 root dialout 238, 0 Nov 11 05:31 /dev/ttySC0
    crw-rw---- 1 root dialout 238, 1 Nov 11 05:31 /dev/ttySC1

  3. Connect port by wires and test. looks it works:
    root@radxa-cm3-io:~# while date; do date > /dev/ttySC0 ; sleep 1; done
    Fri Nov 11 13:52:00 UTC 2022
    Fri Nov 11 13:52:01 UTC 2022
    Fri Nov 11 13:52:02 UTC 2022
    Fri Nov 11 13:52:03 UTC 2022
    Fri Nov 11 13:52:04 UTC 2022
    Fri Nov 11 13:52:05 UTC 2022

    root@radxa-cm3-io:~# dd if=/dev/ttySC1 bs=1
    Fri Nov 11 13:52:00 UTC 2022

    Fri Nov 11 13:52:01 UTC 2022

    Fri Nov 11 13:52:02 UTC 2022

    Fri Nov 11 13:52:03 UTC 2022

    Fri Nov 11 13:52:04 UTC 2022

    Fri Nov 11 13:52:05 UTC 2022