MT7628: Problem with fixed-clock

Hello, i develop my own board with Mediatek MT7628 chip (with module: HLK-7628N).

This board has a chip SPI -> UART bridge (SC16IS750).
This chip has an external crystal oscillator, connected directly to the chip.

Here is a fragment of my DTS file:

&spi0 {
        status = "okay";

        flash@0 {
        
		...
		
                };
        };
        uart3@0 {
                compatible = "nxp,sc16is750";
                reg = <1>;
                clocks = <&sc16is7xx_clk>;
                spi-max-frequency = <4000000>;

                    sc16is7xx_clk: clock-sc16is7xx {
                    compatible = "fixed-clock";
                    #clock-cells = <0>;
                    clock-frequency = <14745600>;
                };
        };
};

When I try to download the module, I get:

root@areal705:/# modprobe sc16is7xx
[  148.239301] sc16is7xx spi0.1: devm_clk_get: -2
[  148.248416] sc16is7xx: probe of spi0.1 failed with error -2

As I understand it, the problem with the clock.
As mentioned here: https://community.onion.io/topic/4847/dts-fixed-clock-and-devm_clk_get

Looks like the fixed-clock driver is provided by CONFIG_COMMON_CLK which isn't available in the mt76x8 config. I'll try to figure out
another solution.

My question is as follows:

  1. how to add "fixed-clock" code to the kernel for the SoC ?
  2. (ugly hack) hardcode clock into bridge driver ?

You cant add the clock as a subnode of the consumer.
Just put it in the in DTS root as its not MMIO and then reference it.

I changed the DTS file but it didn't solve the problem.
Here is a fragments of my DTS file:

// SPDX-License-Identifier: GPL-2.0-or-later OR MIT
/dts-v1/;

#include "mt7628an.dtsi"

#include <dt-bindings/gpio/gpio.h>
#include <dt-bindings/input/input.h>

/ {
        compatible = "areal705", "mediatek,mt7628an-soc";
.....

        sc16is7xx_clk: clock-sc16is7xx {
            compatible = "fixed-clock";
            #clock-cells = <0>;
            clock-frequency = <14745600>;
        };

};

.....

&spi0 {
        status = "okay";

        flash@0 {
        
		...
		
                };
        };
        uart3@0 {
                compatible = "nxp,sc16is750";
                reg = <1>;
                clocks = <&sc16is7xx_clk>;
                spi-max-frequency = <4000000>;
        };
};

I try load module and get:

root@areal705:/# modprobe sc16is7xx
[  145.407860] sc16is7xx spi0.1: devm_clk_get: -2
[  145.417117] sc16is7xx: probe of spi0.1 failed with error -2

Do you see that clock in /sys/kernel/debug/clk/clk_summary ?

No, this path is not exists.

root@areal705:/# ls -l /sys/kernel/debug/
drwxr-xr-x   10 root     root             0 Jan  1  1970 bdi
drwxr-xr-x    2 root     root             0 Jan  1  1970 block
-r--r--r--    1 root     root             0 Jan  1  1970 bootrom
drwxr-xr-x    2 root     root             0 Jan  1  1970 extfrag
-rw-r--r--    1 root     root             0 Jan  1  1970 fault_around_bytes
-r--r--r--    1 root     root             0 Jan  1  1970 gpio
drwxr-xr-x    2 root     root             0 Feb 28 14:18 hid
drwxr-xr-x    3 root     root             0 Feb 28 14:18 ieee80211
drwxr-xr-x    2 root     root             0 Jan  1  1970 mips
drwxr-xr-x    9 root     root             0 Jan  1  1970 mtd
drwxr-xr-x    3 root     root             0 Jan  1  1970 pinctrl
drwxr-xr-x    2 root     root             0 Jan  1  1970 pm_qos
drwxr-xr-x    4 root     root             0 Jan  1  1970 regmap
drwxr-xr-x    3 root     root             0 Jan  1  1970 regulator
-r--r--r--    1 root     root             0 Jan  1  1970 sleep_time
drwxr-xr-x    3 root     root             0 Jan  1  1970 usb

Hm, so something basic is missing as CONFIG_COMMON_CLK is there in mt76x8 config but you dont have the clock debugfs registered at all.

Can you post the kernel bootlog?

Here my kernel bootlog:

[    0.000000] Linux version 4.14.275 (sadmitry@infinity) (gcc version 7.5.0 (OpenWrt GCC 7.5.0 unknown)) #0 Sat Jun 18 20:14:29 2022
[    0.000000] Board has DDR2
[    0.000000] Analog PMU set to hw control
[    0.000000] Digital PMU set to hw control
[    0.000000] SoC Type: MediaTek MT7628AN ver:1 eco:2
[    0.000000] bootconsole [early0] enabled
[    0.000000] CPU0 revision is: 00019655 (MIPS 24KEc)
[    0.000000] MIPS: machine is A-ReAL 705
[    0.000000] Determined physical RAM map:
[    0.000000]  memory: 08000000 @ 00000000 (usable)
[    0.000000] Initrd not found or empty - disabling initrd
[    0.000000] Primary instruction cache 64kB, VIPT, 4-way, linesize 32 bytes.
[    0.000000] Primary data cache 32kB, 4-way, PIPT, no aliases, linesize 32 bytes
[    0.000000] Zone ranges:
[    0.000000]   Normal   [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] Movable zone start for each node
[    0.000000] Early memory node ranges
[    0.000000]   node   0: [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] Initmem setup node 0 [mem 0x0000000000000000-0x0000000007ffffff]
[    0.000000] On node 0 totalpages: 32768
[    0.000000] free_area_init_node: node 0, pgdat 804b19b0, node_mem_map 81000040
[    0.000000]   Normal zone: 256 pages used for memmap
[    0.000000]   Normal zone: 0 pages reserved
[    0.000000]   Normal zone: 32768 pages, LIFO batch:7
[    0.000000] random: get_random_bytes called from start_kernel+0x90/0x47c with crng_init=0
[    0.000000] pcpu-alloc: s0 r0 d32768 u32768 alloc=1*32768
[    0.000000] pcpu-alloc: [0] 0 
[    0.000000] Built 1 zonelists, mobility grouping on.  Total pages: 32512
[    0.000000] Kernel command line: console=ttyS0,57600 rootfstype=squashfs,jffs2
[    0.000000] PID hash table entries: 512 (order: -1, 2048 bytes)
[    0.000000] Dentry cache hash table entries: 16384 (order: 4, 65536 bytes)
[    0.000000] Inode-cache hash table entries: 8192 (order: 3, 32768 bytes)
[    0.000000] Writing ErrCtl register=000487e0
[    0.000000] Readback ErrCtl register=000487e0
[    0.000000] Memory: 123604K/131072K available (3754K kernel code, 170K rwdata, 876K rodata, 1204K init, 201K bss, 7468K reserved, 0K cma-r)
[    0.000000] SLUB: HWalign=32, Order=0-3, MinObjects=0, CPUs=1, Nodes=1
[    0.000000] NR_IRQS: 256
[    0.000000] intc: using register map from devicetree
[    0.000000] CPU Clock: 580MHz
[    0.000000] timer_probe: no matching timers found
[    0.000000] clocksource: MIPS: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 6590553264 ns
[    0.000011] sched_clock: 32 bits at 290MHz, resolution 3ns, wraps every 7405115902ns
[    0.015389] Calibrating delay loop... 385.84 BogoMIPS (lpj=1929216)
[    0.087604] pid_max: default: 32768 minimum: 301
[    0.096955] Mount-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.109917] Mountpoint-cache hash table entries: 1024 (order: 0, 4096 bytes)
[    0.129698] clocksource: jiffies: mask: 0xffffffff max_cycles: 0xffffffff, max_idle_ns: 19112604462750000 ns
[    0.149079] futex hash table entries: 256 (order: -1, 3072 bytes)
[    0.161170] pinctrl core: initialized pinctrl subsystem
[    0.172479] NET: Registered protocol family 16
[    0.208130] mt7621_gpio 10000600.gpio: registering 32 gpios
[    0.219361] mt7621_gpio 10000600.gpio: registering 32 gpios
[    0.230526] mt7621_gpio 10000600.gpio: registering 32 gpios
[    0.246552] clocksource: Switched to clocksource MIPS
[    0.257832] NET: Registered protocol family 2
[    0.266497] IP idents hash table entries: 2048 (order: 2, 16384 bytes)
[    0.280047] TCP established hash table entries: 1024 (order: 0, 4096 bytes)
[    0.293757] TCP bind hash table entries: 1024 (order: 0, 4096 bytes)
[    0.306274] TCP: Hash tables configured (established 1024 bind 1024)
[    0.318978] UDP hash table entries: 256 (order: 0, 4096 bytes)
[    0.330454] UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
[    0.342988] NET: Registered protocol family 1
[    0.351525] PCI: CLS 0 bytes, default 32
[    0.355293] Crashlog allocated RAM at address 0x3f00000
[    0.367293] workingset: timestamp_bits=30 max_order=15 bucket_order=0
[    0.385690] squashfs: version 4.0 (2009/01/31) Phillip Lougher
[    0.397143] jffs2: version 2.2 (NAND) (SUMMARY) (LZMA) (RTIME) (CMODE_PRIORITY) (c) 2001-2006 Red Hat, Inc.
[    0.427051] io scheduler noop registered
[    0.434665] io scheduler deadline registered (default)
[    0.445808] Serial: 8250/16550 driver, 3 ports, IRQ sharing disabled
[    0.459498] console [ttyS0] disabled
[    0.466468] 10000c00.uartlite: ttyS0 at MMIO 0x10000c00 (irq = 28, base_baud = 2500000) is a 16550A
[    0.484400] console [ttyS0] enabled
[    0.498090] bootconsole [early0] disabled
[    0.514547] 10000d00.uart1: ttyS1 at MMIO 0x10000d00 (irq = 29, base_baud = 2500000) is a 16550A
[    0.533348] spi-mt7621 10000b00.spi: sys_freq: 193333333
[    0.558230] m25p80 spi0.0: w25q256 (32768 Kbytes)
[    0.567617] 4 fixed-partitions partitions found on MTD device spi0.0
[    0.580208] Creating 4 MTD partitions on "spi0.0":
[    0.589713] 0x000000000000-0x000000030000 : "u-boot"
[    0.600506] 0x000000030000-0x000000040000 : "u-boot-env"
[    0.611973] 0x000000040000-0x000000050000 : "factory"
[    0.622938] 0x000000050000-0x000002000000 : "firmware"
[    0.637025] 2 uimage-fw partitions found on MTD device firmware
[    0.648800] Creating 2 MTD partitions on "firmware":
[    0.658655] 0x000000000000-0x00000018a3da : "kernel"
[    0.669441] 0x00000018a3da-0x000001fb0000 : "rootfs"
[    0.680160] mtd: device 5 (rootfs) set to be root filesystem
[    0.692947] 1 squashfs-split partitions found on MTD device rootfs
[    0.705264] 0x000000fa0000-0x000001fb0000 : "rootfs_data"
[    0.728032] rt3050-esw 10110000.esw: link changed 0x00
[    0.740733] mtk_soc_eth 10100000.ethernet: generated random MAC address 4a:df:e0:7a:87:1f
[    0.757695] mtk_soc_eth 10100000.ethernet eth0: mediatek frame engine at 0xb0100000, irq 5
[    0.775860] NET: Registered protocol family 10
[    0.788807] Segment Routing with IPv6
[    0.796165] NET: Registered protocol family 17
[    0.805089] 8021q: 802.1Q VLAN Support v1.8
[    0.823524] VFS: Mounted root (squashfs filesystem) readonly on device 31:5.
[    0.844211] Freeing unused kernel memory: 1204K
[    0.853217] This architecture does not have kernel memory protection.
[    2.077032] init: Console is alive
[    2.084013] init: - watchdog -
[    2.496574] random: fast init done
[    4.493377] kmodloader: loading kernel modules from /etc/modules-boot.d/*
[    4.696731] usbcore: registered new interface driver usbfs
[    4.707732] usbcore: registered new interface driver hub
[    4.718395] usbcore: registered new device driver usb
[    4.734957] exFAT: Version 1.2.9
[    4.775670] ehci_hcd: USB 2.0 'Enhanced' Host Controller (EHCI) Driver
[    4.797915] SCSI subsystem initialized
[    4.811024] ehci-platform: EHCI generic platform driver
[    4.831779] phy phy-10120000.usbphy.0: remote usb device wakeup disabled
[    4.845074] phy phy-10120000.usbphy.0: UTMI 16bit 30MHz
[    4.855450] ehci-platform 101c0000.ehci: EHCI Host Controller
[    4.866883] ehci-platform 101c0000.ehci: new USB bus registered, assigned bus number 1
[    4.882698] ehci-platform 101c0000.ehci: irq 26, io mem 0x101c0000
[    4.916595] ehci-platform 101c0000.ehci: USB 2.0 started, EHCI 1.00
[    4.930065] hub 1-0:1.0: USB hub found
[    4.937947] hub 1-0:1.0: 1 port detected
[    4.949403] ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
[    4.963572] ohci-platform: OHCI generic platform driver
[    4.974293] ohci-platform 101c1000.ohci: Generic Platform OHCI controller
[    4.987826] ohci-platform 101c1000.ohci: new USB bus registered, assigned bus number 2
[    5.003622] ohci-platform 101c1000.ohci: irq 26, io mem 0x101c1000
[    5.081544] hub 2-0:1.0: USB hub found
[    5.089471] hub 2-0:1.0: 1 port detected
[    5.105242] usbcore: registered new interface driver usb-storage
[    5.118081] kmodloader: done loading kernel modules from /etc/modules-boot.d/*

4.14 kernel?

What OpenWrt version is this, or is this a vendor SDK?

openwrt-19.07 branch git-22.264.46202-f25285a
from openwrt git

I try to compile last version of openwrt.
Compilation errors

Well, 19.07 is not supported anymore and it uses old clock drivers and not CCF.

Just use 22.03 at least