18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2016 MediaTek Inc.
48c2ecf20Sopenharmony_ci * Author: Kevin Chen <kevin-cw.chen@mediatek.com>
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/of.h>
88c2ecf20Sopenharmony_ci#include <linux/of_address.h>
98c2ecf20Sopenharmony_ci#include <linux/of_device.h>
108c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci#include "clk-mtk.h"
138c2ecf20Sopenharmony_ci#include "clk-gate.h"
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include <dt-bindings/clock/mt6797-clk.h>
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci/*
188c2ecf20Sopenharmony_ci * For some clocks, we don't care what their actual rates are. And these
198c2ecf20Sopenharmony_ci * clocks may change their rate on different products or different scenarios.
208c2ecf20Sopenharmony_ci * So we model these clocks' rate as 0, to denote it's not an actual rate.
218c2ecf20Sopenharmony_ci */
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(mt6797_clk_lock);
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cistatic const struct mtk_fixed_factor top_fixed_divs[] = {
268c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL_CK, "syspll_ck", "mainpll", 1, 1),
278c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL_D2, "syspll_d2", "mainpll", 1, 2),
288c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL1_D2, "syspll1_d2", "syspll_d2", 1, 2),
298c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL1_D4, "syspll1_d4", "syspll_d2", 1, 4),
308c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL1_D8, "syspll1_d8", "syspll_d2", 1, 8),
318c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL1_D16, "syspll1_d16", "syspll_d2", 1, 16),
328c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL_D3, "syspll_d3", "mainpll", 1, 3),
338c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL_D3_D3, "syspll_d3_d3", "syspll_d3", 1, 3),
348c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL2_D2, "syspll2_d2", "syspll_d3", 1, 2),
358c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL2_D4, "syspll2_d4", "syspll_d3", 1, 4),
368c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL2_D8, "syspll2_d8", "syspll_d3", 1, 8),
378c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", "mainpll", 1, 5),
388c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL3_D2, "syspll3_d2", "syspll_d5", 1, 2),
398c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL3_D4, "syspll3_d4", "syspll_d5", 1, 4),
408c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL_D7, "syspll_d7", "mainpll", 1, 7),
418c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL4_D2, "syspll4_d2", "syspll_d7", 1, 2),
428c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL4_D4, "syspll4_d4", "syspll_d7", 1, 4),
438c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL_CK, "univpll_ck", "univpll", 1, 1),
448c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL_D7, "univpll_d7", "univpll", 1, 7),
458c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL_D26, "univpll_d26", "univpll", 1, 26),
468c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SSUSB_PHY_48M_CK, "ssusb_phy_48m_ck", "univpll", 1, 1),
478c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_USB_PHY48M_CK, "usb_phy48m_ck", "univpll", 1, 1),
488c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll", 1, 2),
498c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL1_D2, "univpll1_d2", "univpll_d2", 1, 2),
508c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL1_D4, "univpll1_d4", "univpll_d2", 1, 4),
518c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL1_D8, "univpll1_d8", "univpll_d2", 1, 8),
528c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll", 1, 3),
538c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL2_D2, "univpll2_d2", "univpll", 1, 2),
548c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL2_D4, "univpll2_d4", "univpll", 1, 4),
558c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL2_D8, "univpll2_d8", "univpll", 1, 8),
568c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll", 1, 5),
578c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL3_D2, "univpll3_d2", "univpll_d5", 1, 2),
588c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL3_D4, "univpll3_d4", "univpll_d5", 1, 4),
598c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL3_D8, "univpll3_d8", "univpll_d5", 1, 8),
608c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_ULPOSC_CK_ORG, "ulposc_ck_org", "ulposc", 1, 1),
618c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_ULPOSC_CK, "ulposc_ck", "ulposc_ck_org", 1, 3),
628c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_ULPOSC_D2, "ulposc_d2", "ulposc_ck", 1, 2),
638c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_ULPOSC_D3, "ulposc_d3", "ulposc_ck", 1, 4),
648c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_ULPOSC_D4, "ulposc_d4", "ulposc_ck", 1, 8),
658c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_ULPOSC_D8, "ulposc_d8", "ulposc_ck", 1, 10),
668c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_ULPOSC_D10, "ulposc_d10", "ulposc_ck_org", 1, 1),
678c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_APLL1_CK, "apll1_ck", "apll1", 1, 1),
688c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_APLL2_CK, "apll2_ck", "apll2", 1, 1),
698c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_MFGPLL_CK, "mfgpll_ck", "mfgpll", 1, 1),
708c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_MFGPLL_D2, "mfgpll_d2", "mfgpll_ck", 1, 2),
718c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_IMGPLL_CK, "imgpll_ck", "imgpll", 1, 1),
728c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_IMGPLL_D2, "imgpll_d2", "imgpll_ck", 1, 2),
738c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_IMGPLL_D4, "imgpll_d4", "imgpll_ck", 1, 4),
748c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_CODECPLL_CK, "codecpll_ck", "codecpll", 1, 1),
758c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_CODECPLL_D2, "codecpll_d2", "codecpll_ck", 1, 2),
768c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_VDECPLL_CK, "vdecpll_ck", "vdecpll", 1, 1),
778c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_TVDPLL_CK, "tvdpll_ck", "tvdpll", 1, 1),
788c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_TVDPLL_D2, "tvdpll_d2", "tvdpll_ck", 1, 2),
798c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_TVDPLL_D4, "tvdpll_d4", "tvdpll_ck", 1, 4),
808c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_TVDPLL_D8, "tvdpll_d8", "tvdpll_ck", 1, 8),
818c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_TVDPLL_D16, "tvdpll_d16", "tvdpll_ck", 1, 16),
828c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_MSDCPLL_CK, "msdcpll_ck", "msdcpll", 1, 1),
838c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", "msdcpll_ck", 1, 2),
848c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_MSDCPLL_D4, "msdcpll_d4", "msdcpll_ck", 1, 4),
858c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_MSDCPLL_D8, "msdcpll_d8", "msdcpll_ck", 1, 8),
868c2ecf20Sopenharmony_ci};
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_cistatic const char * const axi_parents[] = {
898c2ecf20Sopenharmony_ci	"clk26m",
908c2ecf20Sopenharmony_ci	"syspll_d7",
918c2ecf20Sopenharmony_ci	"ulposc_axi_ck_mux",
928c2ecf20Sopenharmony_ci};
938c2ecf20Sopenharmony_ci
948c2ecf20Sopenharmony_cistatic const char * const ulposc_axi_ck_mux_parents[] = {
958c2ecf20Sopenharmony_ci	"syspll1_d4",
968c2ecf20Sopenharmony_ci	"ulposc_axi_ck_mux_pre",
978c2ecf20Sopenharmony_ci};
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_cistatic const char * const ulposc_axi_ck_mux_pre_parents[] = {
1008c2ecf20Sopenharmony_ci	"ulposc_d2",
1018c2ecf20Sopenharmony_ci	"ulposc_d3",
1028c2ecf20Sopenharmony_ci};
1038c2ecf20Sopenharmony_ci
1048c2ecf20Sopenharmony_cistatic const char * const ddrphycfg_parents[] = {
1058c2ecf20Sopenharmony_ci	"clk26m",
1068c2ecf20Sopenharmony_ci	"syspll3_d2",
1078c2ecf20Sopenharmony_ci	"syspll2_d4",
1088c2ecf20Sopenharmony_ci	"syspll1_d8",
1098c2ecf20Sopenharmony_ci};
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_cistatic const char * const mm_parents[] = {
1128c2ecf20Sopenharmony_ci	"clk26m",
1138c2ecf20Sopenharmony_ci	"imgpll_ck",
1148c2ecf20Sopenharmony_ci	"univpll1_d2",
1158c2ecf20Sopenharmony_ci	"syspll1_d2",
1168c2ecf20Sopenharmony_ci};
1178c2ecf20Sopenharmony_ci
1188c2ecf20Sopenharmony_cistatic const char * const pwm_parents[] = {
1198c2ecf20Sopenharmony_ci	"clk26m",
1208c2ecf20Sopenharmony_ci	"univpll2_d4",
1218c2ecf20Sopenharmony_ci	"ulposc_d2",
1228c2ecf20Sopenharmony_ci	"ulposc_d3",
1238c2ecf20Sopenharmony_ci	"ulposc_d8",
1248c2ecf20Sopenharmony_ci	"ulposc_d10",
1258c2ecf20Sopenharmony_ci	"ulposc_d4",
1268c2ecf20Sopenharmony_ci};
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_cistatic const char * const vdec_parents[] = {
1298c2ecf20Sopenharmony_ci	"clk26m",
1308c2ecf20Sopenharmony_ci	"vdecpll_ck",
1318c2ecf20Sopenharmony_ci	"imgpll_ck",
1328c2ecf20Sopenharmony_ci	"syspll_d3",
1338c2ecf20Sopenharmony_ci	"univpll_d5",
1348c2ecf20Sopenharmony_ci	"clk26m",
1358c2ecf20Sopenharmony_ci	"clk26m",
1368c2ecf20Sopenharmony_ci};
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_cistatic const char * const venc_parents[] = {
1398c2ecf20Sopenharmony_ci	"clk26m",
1408c2ecf20Sopenharmony_ci	"codecpll_ck",
1418c2ecf20Sopenharmony_ci	"syspll_d3",
1428c2ecf20Sopenharmony_ci};
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_cistatic const char * const mfg_parents[] = {
1458c2ecf20Sopenharmony_ci	"clk26m",
1468c2ecf20Sopenharmony_ci	"mfgpll_ck",
1478c2ecf20Sopenharmony_ci	"syspll_d3",
1488c2ecf20Sopenharmony_ci	"univpll_d3",
1498c2ecf20Sopenharmony_ci};
1508c2ecf20Sopenharmony_ci
1518c2ecf20Sopenharmony_cistatic const char * const camtg[] = {
1528c2ecf20Sopenharmony_ci	"clk26m",
1538c2ecf20Sopenharmony_ci	"univpll_d26",
1548c2ecf20Sopenharmony_ci	"univpll2_d2",
1558c2ecf20Sopenharmony_ci};
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_cistatic const char * const uart_parents[] = {
1588c2ecf20Sopenharmony_ci	"clk26m",
1598c2ecf20Sopenharmony_ci	"univpll2_d8",
1608c2ecf20Sopenharmony_ci};
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_cistatic const char * const spi_parents[] = {
1638c2ecf20Sopenharmony_ci	"clk26m",
1648c2ecf20Sopenharmony_ci	"syspll3_d2",
1658c2ecf20Sopenharmony_ci	"syspll2_d4",
1668c2ecf20Sopenharmony_ci	"ulposc_spi_ck_mux",
1678c2ecf20Sopenharmony_ci};
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_cistatic const char * const ulposc_spi_ck_mux_parents[] = {
1708c2ecf20Sopenharmony_ci	"ulposc_d2",
1718c2ecf20Sopenharmony_ci	"ulposc_d3",
1728c2ecf20Sopenharmony_ci};
1738c2ecf20Sopenharmony_ci
1748c2ecf20Sopenharmony_cistatic const char * const usb20_parents[] = {
1758c2ecf20Sopenharmony_ci	"clk26m",
1768c2ecf20Sopenharmony_ci	"univpll1_d8",
1778c2ecf20Sopenharmony_ci	"syspll4_d2",
1788c2ecf20Sopenharmony_ci};
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_cistatic const char * const msdc50_0_hclk_parents[] = {
1818c2ecf20Sopenharmony_ci	"clk26m",
1828c2ecf20Sopenharmony_ci	"syspll1_d2",
1838c2ecf20Sopenharmony_ci	"syspll2_d2",
1848c2ecf20Sopenharmony_ci	"syspll4_d2",
1858c2ecf20Sopenharmony_ci};
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_cistatic const char * const msdc50_0_parents[] = {
1888c2ecf20Sopenharmony_ci	"clk26m",
1898c2ecf20Sopenharmony_ci	"msdcpll",
1908c2ecf20Sopenharmony_ci	"syspll_d3",
1918c2ecf20Sopenharmony_ci	"univpll1_d4",
1928c2ecf20Sopenharmony_ci	"syspll2_d2",
1938c2ecf20Sopenharmony_ci	"syspll_d7",
1948c2ecf20Sopenharmony_ci	"msdcpll_d2",
1958c2ecf20Sopenharmony_ci	"univpll1_d2",
1968c2ecf20Sopenharmony_ci	"univpll_d3",
1978c2ecf20Sopenharmony_ci};
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_cistatic const char * const msdc30_1_parents[] = {
2008c2ecf20Sopenharmony_ci	"clk26m",
2018c2ecf20Sopenharmony_ci	"univpll2_d2",
2028c2ecf20Sopenharmony_ci	"msdcpll_d2",
2038c2ecf20Sopenharmony_ci	"univpll1_d4",
2048c2ecf20Sopenharmony_ci	"syspll2_d2",
2058c2ecf20Sopenharmony_ci	"syspll_d7",
2068c2ecf20Sopenharmony_ci	"univpll_d7",
2078c2ecf20Sopenharmony_ci};
2088c2ecf20Sopenharmony_ci
2098c2ecf20Sopenharmony_cistatic const char * const msdc30_2_parents[] = {
2108c2ecf20Sopenharmony_ci	"clk26m",
2118c2ecf20Sopenharmony_ci	"univpll2_d8",
2128c2ecf20Sopenharmony_ci	"syspll2_d8",
2138c2ecf20Sopenharmony_ci	"syspll1_d8",
2148c2ecf20Sopenharmony_ci	"msdcpll_d8",
2158c2ecf20Sopenharmony_ci	"syspll3_d4",
2168c2ecf20Sopenharmony_ci	"univpll_d26",
2178c2ecf20Sopenharmony_ci};
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_cistatic const char * const audio_parents[] = {
2208c2ecf20Sopenharmony_ci	"clk26m",
2218c2ecf20Sopenharmony_ci	"syspll3_d4",
2228c2ecf20Sopenharmony_ci	"syspll4_d4",
2238c2ecf20Sopenharmony_ci	"syspll1_d16",
2248c2ecf20Sopenharmony_ci};
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_cistatic const char * const aud_intbus_parents[] = {
2278c2ecf20Sopenharmony_ci	"clk26m",
2288c2ecf20Sopenharmony_ci	"syspll1_d4",
2298c2ecf20Sopenharmony_ci	"syspll4_d2",
2308c2ecf20Sopenharmony_ci};
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_cistatic const char * const pmicspi_parents[] = {
2338c2ecf20Sopenharmony_ci	"clk26m",
2348c2ecf20Sopenharmony_ci	"univpll_d26",
2358c2ecf20Sopenharmony_ci	"syspll3_d4",
2368c2ecf20Sopenharmony_ci	"syspll1_d8",
2378c2ecf20Sopenharmony_ci	"ulposc_d4",
2388c2ecf20Sopenharmony_ci	"ulposc_d8",
2398c2ecf20Sopenharmony_ci	"syspll2_d8",
2408c2ecf20Sopenharmony_ci};
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_cistatic const char * const scp_parents[] = {
2438c2ecf20Sopenharmony_ci	"clk26m",
2448c2ecf20Sopenharmony_ci	"syspll_d3",
2458c2ecf20Sopenharmony_ci	"ulposc_ck",
2468c2ecf20Sopenharmony_ci	"univpll_d5",
2478c2ecf20Sopenharmony_ci};
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_cistatic const char * const atb_parents[] = {
2508c2ecf20Sopenharmony_ci	"clk26m",
2518c2ecf20Sopenharmony_ci	"syspll1_d2",
2528c2ecf20Sopenharmony_ci	"syspll_d5",
2538c2ecf20Sopenharmony_ci};
2548c2ecf20Sopenharmony_ci
2558c2ecf20Sopenharmony_cistatic const char * const mjc_parents[] = {
2568c2ecf20Sopenharmony_ci	"clk26m",
2578c2ecf20Sopenharmony_ci	"imgpll_ck",
2588c2ecf20Sopenharmony_ci	"univpll_d5",
2598c2ecf20Sopenharmony_ci	"syspll1_d2",
2608c2ecf20Sopenharmony_ci};
2618c2ecf20Sopenharmony_ci
2628c2ecf20Sopenharmony_cistatic const char * const dpi0_parents[] = {
2638c2ecf20Sopenharmony_ci	"clk26m",
2648c2ecf20Sopenharmony_ci	"tvdpll_d2",
2658c2ecf20Sopenharmony_ci	"tvdpll_d4",
2668c2ecf20Sopenharmony_ci	"tvdpll_d8",
2678c2ecf20Sopenharmony_ci	"tvdpll_d16",
2688c2ecf20Sopenharmony_ci	"clk26m",
2698c2ecf20Sopenharmony_ci	"clk26m",
2708c2ecf20Sopenharmony_ci};
2718c2ecf20Sopenharmony_ci
2728c2ecf20Sopenharmony_cistatic const char * const aud_1_parents[] = {
2738c2ecf20Sopenharmony_ci	"clk26m",
2748c2ecf20Sopenharmony_ci	"apll1_ck",
2758c2ecf20Sopenharmony_ci};
2768c2ecf20Sopenharmony_ci
2778c2ecf20Sopenharmony_cistatic const char * const aud_2_parents[] = {
2788c2ecf20Sopenharmony_ci	"clk26m",
2798c2ecf20Sopenharmony_ci	"apll2_ck",
2808c2ecf20Sopenharmony_ci};
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_cistatic const char * const ssusb_top_sys_parents[] = {
2838c2ecf20Sopenharmony_ci	"clk26m",
2848c2ecf20Sopenharmony_ci	"univpll3_d2",
2858c2ecf20Sopenharmony_ci};
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_cistatic const char * const spm_parents[] = {
2888c2ecf20Sopenharmony_ci	"clk26m",
2898c2ecf20Sopenharmony_ci	"syspll1_d8",
2908c2ecf20Sopenharmony_ci};
2918c2ecf20Sopenharmony_ci
2928c2ecf20Sopenharmony_cistatic const char * const bsi_spi_parents[] = {
2938c2ecf20Sopenharmony_ci	"clk26m",
2948c2ecf20Sopenharmony_ci	"syspll_d3_d3",
2958c2ecf20Sopenharmony_ci	"syspll1_d4",
2968c2ecf20Sopenharmony_ci	"syspll_d7",
2978c2ecf20Sopenharmony_ci};
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_cistatic const char * const audio_h_parents[] = {
3008c2ecf20Sopenharmony_ci	"clk26m",
3018c2ecf20Sopenharmony_ci	"apll2_ck",
3028c2ecf20Sopenharmony_ci	"apll1_ck",
3038c2ecf20Sopenharmony_ci	"univpll_d7",
3048c2ecf20Sopenharmony_ci};
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_cistatic const char * const mfg_52m_parents[] = {
3078c2ecf20Sopenharmony_ci	"clk26m",
3088c2ecf20Sopenharmony_ci	"univpll2_d8",
3098c2ecf20Sopenharmony_ci	"univpll2_d4",
3108c2ecf20Sopenharmony_ci	"univpll2_d4",
3118c2ecf20Sopenharmony_ci};
3128c2ecf20Sopenharmony_ci
3138c2ecf20Sopenharmony_cistatic const char * const anc_md32_parents[] = {
3148c2ecf20Sopenharmony_ci	"clk26m",
3158c2ecf20Sopenharmony_ci	"syspll1_d2",
3168c2ecf20Sopenharmony_ci	"univpll_d5",
3178c2ecf20Sopenharmony_ci};
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci/*
3208c2ecf20Sopenharmony_ci * Clock mux ddrphycfg is needed by the DRAM controller. We mark it as
3218c2ecf20Sopenharmony_ci * critical as otherwise the system will hang after boot.
3228c2ecf20Sopenharmony_ci */
3238c2ecf20Sopenharmony_cistatic const struct mtk_composite top_muxes[] = {
3248c2ecf20Sopenharmony_ci	MUX(CLK_TOP_MUX_ULPOSC_AXI_CK_MUX_PRE, "ulposc_axi_ck_mux_pre",
3258c2ecf20Sopenharmony_ci	    ulposc_axi_ck_mux_pre_parents, 0x0040, 3, 1),
3268c2ecf20Sopenharmony_ci	MUX(CLK_TOP_MUX_ULPOSC_AXI_CK_MUX, "ulposc_axi_ck_mux",
3278c2ecf20Sopenharmony_ci	    ulposc_axi_ck_mux_parents, 0x0040, 2, 1),
3288c2ecf20Sopenharmony_ci	MUX(CLK_TOP_MUX_AXI, "axi_sel", axi_parents,
3298c2ecf20Sopenharmony_ci	    0x0040, 0, 2),
3308c2ecf20Sopenharmony_ci	MUX_FLAGS(CLK_TOP_MUX_DDRPHYCFG, "ddrphycfg_sel", ddrphycfg_parents,
3318c2ecf20Sopenharmony_ci		  0x0040, 16, 2, CLK_IS_CRITICAL | CLK_SET_RATE_PARENT),
3328c2ecf20Sopenharmony_ci	MUX(CLK_TOP_MUX_MM, "mm_sel", mm_parents,
3338c2ecf20Sopenharmony_ci	    0x0040, 24, 2),
3348c2ecf20Sopenharmony_ci	MUX_GATE(CLK_TOP_MUX_PWM, "pwm_sel", pwm_parents, 0x0050, 0, 3, 7),
3358c2ecf20Sopenharmony_ci	MUX_GATE(CLK_TOP_MUX_VDEC, "vdec_sel", vdec_parents, 0x0050, 8, 3, 15),
3368c2ecf20Sopenharmony_ci	MUX_GATE(CLK_TOP_MUX_VENC, "venc_sel", venc_parents, 0x0050, 16, 2, 23),
3378c2ecf20Sopenharmony_ci	MUX_GATE(CLK_TOP_MUX_MFG, "mfg_sel", mfg_parents, 0x0050, 24, 2, 31),
3388c2ecf20Sopenharmony_ci	MUX_GATE(CLK_TOP_MUX_CAMTG, "camtg_sel", camtg, 0x0060, 0, 2, 7),
3398c2ecf20Sopenharmony_ci	MUX_GATE(CLK_TOP_MUX_UART, "uart_sel", uart_parents, 0x0060, 8, 1, 15),
3408c2ecf20Sopenharmony_ci	MUX_GATE(CLK_TOP_MUX_SPI, "spi_sel", spi_parents, 0x0060, 16, 2, 23),
3418c2ecf20Sopenharmony_ci	MUX(CLK_TOP_MUX_ULPOSC_SPI_CK_MUX, "ulposc_spi_ck_mux",
3428c2ecf20Sopenharmony_ci	    ulposc_spi_ck_mux_parents, 0x0060, 18, 1),
3438c2ecf20Sopenharmony_ci	MUX_GATE(CLK_TOP_MUX_USB20, "usb20_sel", usb20_parents,
3448c2ecf20Sopenharmony_ci		 0x0060, 24, 2, 31),
3458c2ecf20Sopenharmony_ci	MUX(CLK_TOP_MUX_MSDC50_0_HCLK, "msdc50_0_hclk_sel",
3468c2ecf20Sopenharmony_ci	    msdc50_0_hclk_parents, 0x0070, 8, 2),
3478c2ecf20Sopenharmony_ci	MUX_GATE(CLK_TOP_MUX_MSDC50_0, "msdc50_0_sel", msdc50_0_parents,
3488c2ecf20Sopenharmony_ci		 0x0070, 16, 4, 23),
3498c2ecf20Sopenharmony_ci	MUX_GATE(CLK_TOP_MUX_MSDC30_1, "msdc30_1_sel", msdc30_1_parents,
3508c2ecf20Sopenharmony_ci		 0x0070, 24, 3, 31),
3518c2ecf20Sopenharmony_ci	MUX_GATE(CLK_TOP_MUX_MSDC30_2, "msdc30_2_sel", msdc30_2_parents,
3528c2ecf20Sopenharmony_ci		 0x0080, 0, 3, 7),
3538c2ecf20Sopenharmony_ci	MUX_GATE(CLK_TOP_MUX_AUDIO, "audio_sel", audio_parents,
3548c2ecf20Sopenharmony_ci		 0x0080, 16, 2, 23),
3558c2ecf20Sopenharmony_ci	MUX(CLK_TOP_MUX_AUD_INTBUS, "aud_intbus_sel", aud_intbus_parents,
3568c2ecf20Sopenharmony_ci	    0x0080, 24, 2),
3578c2ecf20Sopenharmony_ci	MUX(CLK_TOP_MUX_PMICSPI, "pmicspi_sel", pmicspi_parents,
3588c2ecf20Sopenharmony_ci	    0x0090, 0, 3),
3598c2ecf20Sopenharmony_ci	MUX(CLK_TOP_MUX_SCP, "scp_sel", scp_parents,
3608c2ecf20Sopenharmony_ci	    0x0090, 8, 2),
3618c2ecf20Sopenharmony_ci	MUX(CLK_TOP_MUX_ATB, "atb_sel", atb_parents,
3628c2ecf20Sopenharmony_ci	    0x0090, 16, 2),
3638c2ecf20Sopenharmony_ci	MUX_GATE(CLK_TOP_MUX_MJC, "mjc_sel", mjc_parents, 0x0090, 24, 2, 31),
3648c2ecf20Sopenharmony_ci	MUX_GATE(CLK_TOP_MUX_DPI0, "dpi0_sel", dpi0_parents, 0x00A0, 0, 3, 7),
3658c2ecf20Sopenharmony_ci	MUX_GATE(CLK_TOP_MUX_AUD_1, "aud_1_sel", aud_1_parents,
3668c2ecf20Sopenharmony_ci		 0x00A0, 16, 1, 23),
3678c2ecf20Sopenharmony_ci	MUX_GATE(CLK_TOP_MUX_AUD_2, "aud_2_sel", aud_2_parents,
3688c2ecf20Sopenharmony_ci		 0x00A0, 24, 1, 31),
3698c2ecf20Sopenharmony_ci	MUX(CLK_TOP_MUX_SSUSB_TOP_SYS, "ssusb_top_sys_sel",
3708c2ecf20Sopenharmony_ci	    ssusb_top_sys_parents, 0x00B0, 8, 1),
3718c2ecf20Sopenharmony_ci	MUX(CLK_TOP_MUX_SPM, "spm_sel", spm_parents,
3728c2ecf20Sopenharmony_ci	    0x00C0, 0, 1),
3738c2ecf20Sopenharmony_ci	MUX(CLK_TOP_MUX_BSI_SPI, "bsi_spi_sel", bsi_spi_parents,
3748c2ecf20Sopenharmony_ci	    0x00C0, 8, 2),
3758c2ecf20Sopenharmony_ci	MUX_GATE(CLK_TOP_MUX_AUDIO_H, "audio_h_sel", audio_h_parents,
3768c2ecf20Sopenharmony_ci		 0x00C0, 16, 2, 23),
3778c2ecf20Sopenharmony_ci	MUX_GATE(CLK_TOP_MUX_ANC_MD32, "anc_md32_sel", anc_md32_parents,
3788c2ecf20Sopenharmony_ci		 0x00C0, 24, 2, 31),
3798c2ecf20Sopenharmony_ci	MUX(CLK_TOP_MUX_MFG_52M, "mfg_52m_sel", mfg_52m_parents,
3808c2ecf20Sopenharmony_ci	    0x0104, 1, 2),
3818c2ecf20Sopenharmony_ci};
3828c2ecf20Sopenharmony_ci
3838c2ecf20Sopenharmony_cistatic int mtk_topckgen_init(struct platform_device *pdev)
3848c2ecf20Sopenharmony_ci{
3858c2ecf20Sopenharmony_ci	struct clk_onecell_data *clk_data;
3868c2ecf20Sopenharmony_ci	void __iomem *base;
3878c2ecf20Sopenharmony_ci	struct device_node *node = pdev->dev.of_node;
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	base = devm_platform_ioremap_resource(pdev, 0);
3908c2ecf20Sopenharmony_ci	if (IS_ERR(base))
3918c2ecf20Sopenharmony_ci		return PTR_ERR(base);
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci	clk_data = mtk_alloc_clk_data(CLK_TOP_NR);
3948c2ecf20Sopenharmony_ci	if (!clk_data)
3958c2ecf20Sopenharmony_ci		return -ENOMEM;
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	mtk_clk_register_factors(top_fixed_divs, ARRAY_SIZE(top_fixed_divs),
3988c2ecf20Sopenharmony_ci				 clk_data);
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci	mtk_clk_register_composites(top_muxes, ARRAY_SIZE(top_muxes), base,
4018c2ecf20Sopenharmony_ci				    &mt6797_clk_lock, clk_data);
4028c2ecf20Sopenharmony_ci
4038c2ecf20Sopenharmony_ci	return of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
4048c2ecf20Sopenharmony_ci}
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_cistatic const struct mtk_gate_regs infra0_cg_regs = {
4078c2ecf20Sopenharmony_ci	.set_ofs = 0x0080,
4088c2ecf20Sopenharmony_ci	.clr_ofs = 0x0084,
4098c2ecf20Sopenharmony_ci	.sta_ofs = 0x0090,
4108c2ecf20Sopenharmony_ci};
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_cistatic const struct mtk_gate_regs infra1_cg_regs = {
4138c2ecf20Sopenharmony_ci	.set_ofs = 0x0088,
4148c2ecf20Sopenharmony_ci	.clr_ofs = 0x008c,
4158c2ecf20Sopenharmony_ci	.sta_ofs = 0x0094,
4168c2ecf20Sopenharmony_ci};
4178c2ecf20Sopenharmony_ci
4188c2ecf20Sopenharmony_cistatic const struct mtk_gate_regs infra2_cg_regs = {
4198c2ecf20Sopenharmony_ci	.set_ofs = 0x00a8,
4208c2ecf20Sopenharmony_ci	.clr_ofs = 0x00ac,
4218c2ecf20Sopenharmony_ci	.sta_ofs = 0x00b0,
4228c2ecf20Sopenharmony_ci};
4238c2ecf20Sopenharmony_ci
4248c2ecf20Sopenharmony_ci#define GATE_ICG0(_id, _name, _parent, _shift) {		\
4258c2ecf20Sopenharmony_ci	.id = _id,						\
4268c2ecf20Sopenharmony_ci	.name = _name,						\
4278c2ecf20Sopenharmony_ci	.parent_name = _parent,					\
4288c2ecf20Sopenharmony_ci	.regs = &infra0_cg_regs,				\
4298c2ecf20Sopenharmony_ci	.shift = _shift,					\
4308c2ecf20Sopenharmony_ci	.ops = &mtk_clk_gate_ops_setclr,			\
4318c2ecf20Sopenharmony_ci}
4328c2ecf20Sopenharmony_ci
4338c2ecf20Sopenharmony_ci#define GATE_ICG1(_id, _name, _parent, _shift)			\
4348c2ecf20Sopenharmony_ci	GATE_ICG1_FLAGS(_id, _name, _parent, _shift, 0)
4358c2ecf20Sopenharmony_ci
4368c2ecf20Sopenharmony_ci#define GATE_ICG1_FLAGS(_id, _name, _parent, _shift, _flags) {	\
4378c2ecf20Sopenharmony_ci	.id = _id,						\
4388c2ecf20Sopenharmony_ci	.name = _name,						\
4398c2ecf20Sopenharmony_ci	.parent_name = _parent,					\
4408c2ecf20Sopenharmony_ci	.regs = &infra1_cg_regs,				\
4418c2ecf20Sopenharmony_ci	.shift = _shift,					\
4428c2ecf20Sopenharmony_ci	.ops = &mtk_clk_gate_ops_setclr,			\
4438c2ecf20Sopenharmony_ci	.flags = _flags,					\
4448c2ecf20Sopenharmony_ci}
4458c2ecf20Sopenharmony_ci
4468c2ecf20Sopenharmony_ci#define GATE_ICG2(_id, _name, _parent, _shift)			\
4478c2ecf20Sopenharmony_ci	GATE_ICG2_FLAGS(_id, _name, _parent, _shift, 0)
4488c2ecf20Sopenharmony_ci
4498c2ecf20Sopenharmony_ci#define GATE_ICG2_FLAGS(_id, _name, _parent, _shift, _flags) {	\
4508c2ecf20Sopenharmony_ci	.id = _id,						\
4518c2ecf20Sopenharmony_ci	.name = _name,						\
4528c2ecf20Sopenharmony_ci	.parent_name = _parent,					\
4538c2ecf20Sopenharmony_ci	.regs = &infra2_cg_regs,				\
4548c2ecf20Sopenharmony_ci	.shift = _shift,					\
4558c2ecf20Sopenharmony_ci	.ops = &mtk_clk_gate_ops_setclr,			\
4568c2ecf20Sopenharmony_ci	.flags = _flags,					\
4578c2ecf20Sopenharmony_ci}
4588c2ecf20Sopenharmony_ci
4598c2ecf20Sopenharmony_ci/*
4608c2ecf20Sopenharmony_ci * Clock gates dramc and dramc_b are needed by the DRAM controller.
4618c2ecf20Sopenharmony_ci * We mark them as critical as otherwise the system will hang after boot.
4628c2ecf20Sopenharmony_ci */
4638c2ecf20Sopenharmony_cistatic const struct mtk_gate infra_clks[] = {
4648c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_PMIC_TMR, "infra_pmic_tmr", "ulposc", 0),
4658c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_PMIC_AP, "infra_pmic_ap", "pmicspi_sel", 1),
4668c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_PMIC_MD, "infra_pmic_md", "pmicspi_sel", 2),
4678c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_PMIC_CONN, "infra_pmic_conn", "pmicspi_sel", 3),
4688c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_SCP, "infra_scp", "scp_sel", 4),
4698c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_SEJ, "infra_sej", "axi_sel", 5),
4708c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_APXGPT, "infra_apxgpt", "axi_sel", 6),
4718c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_SEJ_13M, "infra_sej_13m", "clk26m", 7),
4728c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_ICUSB, "infra_icusb", "usb20_sel", 8),
4738c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_GCE, "infra_gce", "axi_sel", 9),
4748c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_THERM, "infra_therm", "axi_sel", 10),
4758c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_I2C0, "infra_i2c0", "axi_sel", 11),
4768c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_I2C1, "infra_i2c1", "axi_sel", 12),
4778c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_I2C2, "infra_i2c2", "axi_sel", 13),
4788c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_I2C3, "infra_i2c3", "axi_sel", 14),
4798c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_PWM_HCLK, "infra_pwm_hclk", "axi_sel", 15),
4808c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_PWM1, "infra_pwm1", "axi_sel", 16),
4818c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_PWM2, "infra_pwm2", "axi_sel", 17),
4828c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_PWM3, "infra_pwm3", "axi_sel", 18),
4838c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_PWM4, "infra_pwm4", "axi_sel", 19),
4848c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_PWM, "infra_pwm", "axi_sel", 21),
4858c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_UART0, "infra_uart0", "uart_sel", 22),
4868c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_UART1, "infra_uart1", "uart_sel", 23),
4878c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_UART2, "infra_uart2", "uart_sel", 24),
4888c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_UART3, "infra_uart3", "uart_sel", 25),
4898c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_MD2MD_CCIF_0, "infra_md2md_ccif_0", "axi_sel", 27),
4908c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_MD2MD_CCIF_1, "infra_md2md_ccif_1", "axi_sel", 28),
4918c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_MD2MD_CCIF_2, "infra_md2md_ccif_2", "axi_sel", 29),
4928c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_FHCTL, "infra_fhctl", "clk26m", 30),
4938c2ecf20Sopenharmony_ci	GATE_ICG0(CLK_INFRA_BTIF, "infra_btif", "axi_sel", 31),
4948c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_MD2MD_CCIF_3, "infra_md2md_ccif_3", "axi_sel", 0),
4958c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_SPI, "infra_spi", "spi_sel", 1),
4968c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_MSDC0, "infra_msdc0", "msdc50_0_sel", 2),
4978c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_MD2MD_CCIF_4, "infra_md2md_ccif_4", "axi_sel", 3),
4988c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_MSDC1, "infra_msdc1", "msdc30_1_sel", 4),
4998c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_MSDC2, "infra_msdc2", "msdc30_2_sel", 5),
5008c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_MD2MD_CCIF_5, "infra_md2md_ccif_5", "axi_sel", 7),
5018c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_GCPU, "infra_gcpu", "axi_sel", 8),
5028c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_TRNG, "infra_trng", "axi_sel", 9),
5038c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_AUXADC, "infra_auxadc", "clk26m", 10),
5048c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_CPUM, "infra_cpum", "axi_sel", 11),
5058c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_AP_C2K_CCIF_0, "infra_ap_c2k_ccif_0",
5068c2ecf20Sopenharmony_ci		  "axi_sel", 12),
5078c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_AP_C2K_CCIF_1, "infra_ap_c2k_ccif_1",
5088c2ecf20Sopenharmony_ci		  "axi_sel", 13),
5098c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_CLDMA, "infra_cldma", "axi_sel", 16),
5108c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_DISP_PWM, "infra_disp_pwm", "pwm_sel", 17),
5118c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_AP_DMA, "infra_ap_dma", "axi_sel", 18),
5128c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_DEVICE_APC, "infra_device_apc", "axi_sel", 20),
5138c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_L2C_SRAM, "infra_l2c_sram", "mm_sel", 22),
5148c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_CCIF_AP, "infra_ccif_ap", "axi_sel", 23),
5158c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_AUDIO, "infra_audio", "axi_sel", 25),
5168c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_CCIF_MD, "infra_ccif_md", "axi_sel", 26),
5178c2ecf20Sopenharmony_ci	GATE_ICG1_FLAGS(CLK_INFRA_DRAMC_F26M, "infra_dramc_f26m",
5188c2ecf20Sopenharmony_ci			"clk26m", 31, CLK_IS_CRITICAL),
5198c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_I2C4, "infra_i2c4", "axi_sel", 0),
5208c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_I2C_APPM, "infra_i2c_appm", "axi_sel", 1),
5218c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_I2C_GPUPM, "infra_i2c_gpupm", "axi_sel", 2),
5228c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_I2C2_IMM, "infra_i2c2_imm", "axi_sel", 3),
5238c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_I2C2_ARB, "infra_i2c2_arb", "axi_sel", 4),
5248c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_I2C3_IMM, "infra_i2c3_imm", "axi_sel", 5),
5258c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_I2C3_ARB, "infra_i2c3_arb", "axi_sel", 6),
5268c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_I2C5, "infra_i2c5", "axi_sel", 7),
5278c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_SYS_CIRQ, "infra_sys_cirq", "axi_sel", 8),
5288c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_SPI1, "infra_spi1", "spi_sel", 10),
5298c2ecf20Sopenharmony_ci	GATE_ICG2_FLAGS(CLK_INFRA_DRAMC_B_F26M, "infra_dramc_b_f26m",
5308c2ecf20Sopenharmony_ci			"clk26m", 11, CLK_IS_CRITICAL),
5318c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_ANC_MD32, "infra_anc_md32", "anc_md32_sel", 12),
5328c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_ANC_MD32_32K, "infra_anc_md32_32k", "clk26m", 13),
5338c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_DVFS_SPM1, "infra_dvfs_spm1", "axi_sel", 15),
5348c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_AES_TOP0, "infra_aes_top0", "axi_sel", 16),
5358c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_AES_TOP1, "infra_aes_top1", "axi_sel", 17),
5368c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_SSUSB_BUS, "infra_ssusb_bus", "axi_sel", 18),
5378c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_SPI2, "infra_spi2", "spi_sel", 19),
5388c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_SPI3, "infra_spi3", "spi_sel", 20),
5398c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_SPI4, "infra_spi4", "spi_sel", 21),
5408c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_SPI5, "infra_spi5", "spi_sel", 22),
5418c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_IRTX, "infra_irtx", "spi_sel", 23),
5428c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_SSUSB_SYS, "infra_ssusb_sys",
5438c2ecf20Sopenharmony_ci		  "ssusb_top_sys_sel", 24),
5448c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_SSUSB_REF, "infra_ssusb_ref", "clk26m", 9),
5458c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_AUDIO_26M, "infra_audio_26m", "clk26m", 26),
5468c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_AUDIO_26M_PAD_TOP, "infra_audio_26m_pad_top",
5478c2ecf20Sopenharmony_ci		  "clk26m", 27),
5488c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_MODEM_TEMP_SHARE, "infra_modem_temp_share",
5498c2ecf20Sopenharmony_ci		  "axi_sel", 28),
5508c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_VAD_WRAP_SOC, "infra_vad_wrap_soc", "axi_sel", 29),
5518c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_DRAMC_CONF, "infra_dramc_conf", "axi_sel", 30),
5528c2ecf20Sopenharmony_ci	GATE_ICG2(CLK_INFRA_DRAMC_B_CONF, "infra_dramc_b_conf", "axi_sel", 31),
5538c2ecf20Sopenharmony_ci	GATE_ICG1(CLK_INFRA_MFG_VCG, "infra_mfg_vcg", "mfg_52m_sel", 14),
5548c2ecf20Sopenharmony_ci};
5558c2ecf20Sopenharmony_ci
5568c2ecf20Sopenharmony_cistatic const struct mtk_fixed_factor infra_fixed_divs[] = {
5578c2ecf20Sopenharmony_ci	FACTOR(CLK_INFRA_13M, "clk13m", "clk26m", 1, 2),
5588c2ecf20Sopenharmony_ci};
5598c2ecf20Sopenharmony_ci
5608c2ecf20Sopenharmony_cistatic struct clk_onecell_data *infra_clk_data;
5618c2ecf20Sopenharmony_ci
5628c2ecf20Sopenharmony_cistatic void mtk_infrasys_init_early(struct device_node *node)
5638c2ecf20Sopenharmony_ci{
5648c2ecf20Sopenharmony_ci	int r, i;
5658c2ecf20Sopenharmony_ci
5668c2ecf20Sopenharmony_ci	if (!infra_clk_data) {
5678c2ecf20Sopenharmony_ci		infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR);
5688c2ecf20Sopenharmony_ci		if (!infra_clk_data)
5698c2ecf20Sopenharmony_ci			return;
5708c2ecf20Sopenharmony_ci
5718c2ecf20Sopenharmony_ci		for (i = 0; i < CLK_INFRA_NR; i++)
5728c2ecf20Sopenharmony_ci			infra_clk_data->clks[i] = ERR_PTR(-EPROBE_DEFER);
5738c2ecf20Sopenharmony_ci	}
5748c2ecf20Sopenharmony_ci
5758c2ecf20Sopenharmony_ci	mtk_clk_register_factors(infra_fixed_divs, ARRAY_SIZE(infra_fixed_divs),
5768c2ecf20Sopenharmony_ci				 infra_clk_data);
5778c2ecf20Sopenharmony_ci
5788c2ecf20Sopenharmony_ci	r = of_clk_add_provider(node, of_clk_src_onecell_get, infra_clk_data);
5798c2ecf20Sopenharmony_ci	if (r)
5808c2ecf20Sopenharmony_ci		pr_err("%s(): could not register clock provider: %d\n",
5818c2ecf20Sopenharmony_ci		       __func__, r);
5828c2ecf20Sopenharmony_ci}
5838c2ecf20Sopenharmony_ci
5848c2ecf20Sopenharmony_ciCLK_OF_DECLARE_DRIVER(mtk_infra, "mediatek,mt6797-infracfg",
5858c2ecf20Sopenharmony_ci		      mtk_infrasys_init_early);
5868c2ecf20Sopenharmony_ci
5878c2ecf20Sopenharmony_cistatic int mtk_infrasys_init(struct platform_device *pdev)
5888c2ecf20Sopenharmony_ci{
5898c2ecf20Sopenharmony_ci	int i;
5908c2ecf20Sopenharmony_ci	struct device_node *node = pdev->dev.of_node;
5918c2ecf20Sopenharmony_ci
5928c2ecf20Sopenharmony_ci	if (!infra_clk_data) {
5938c2ecf20Sopenharmony_ci		infra_clk_data = mtk_alloc_clk_data(CLK_INFRA_NR);
5948c2ecf20Sopenharmony_ci		if (!infra_clk_data)
5958c2ecf20Sopenharmony_ci			return -ENOMEM;
5968c2ecf20Sopenharmony_ci	} else {
5978c2ecf20Sopenharmony_ci		for (i = 0; i < CLK_INFRA_NR; i++) {
5988c2ecf20Sopenharmony_ci			if (infra_clk_data->clks[i] == ERR_PTR(-EPROBE_DEFER))
5998c2ecf20Sopenharmony_ci				infra_clk_data->clks[i] = ERR_PTR(-ENOENT);
6008c2ecf20Sopenharmony_ci		}
6018c2ecf20Sopenharmony_ci	}
6028c2ecf20Sopenharmony_ci
6038c2ecf20Sopenharmony_ci	mtk_clk_register_gates(node, infra_clks, ARRAY_SIZE(infra_clks),
6048c2ecf20Sopenharmony_ci			       infra_clk_data);
6058c2ecf20Sopenharmony_ci	mtk_clk_register_factors(infra_fixed_divs, ARRAY_SIZE(infra_fixed_divs),
6068c2ecf20Sopenharmony_ci				 infra_clk_data);
6078c2ecf20Sopenharmony_ci
6088c2ecf20Sopenharmony_ci	return of_clk_add_provider(node, of_clk_src_onecell_get, infra_clk_data);
6098c2ecf20Sopenharmony_ci}
6108c2ecf20Sopenharmony_ci
6118c2ecf20Sopenharmony_ci#define MT6797_PLL_FMAX		(3000UL * MHZ)
6128c2ecf20Sopenharmony_ci
6138c2ecf20Sopenharmony_ci#define CON0_MT6797_RST_BAR	BIT(24)
6148c2ecf20Sopenharmony_ci
6158c2ecf20Sopenharmony_ci#define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits,	\
6168c2ecf20Sopenharmony_ci			_pd_reg, _pd_shift, _tuner_reg, _pcw_reg,	\
6178c2ecf20Sopenharmony_ci			_pcw_shift, _div_table) {			\
6188c2ecf20Sopenharmony_ci	.id = _id,						\
6198c2ecf20Sopenharmony_ci	.name = _name,						\
6208c2ecf20Sopenharmony_ci	.reg = _reg,						\
6218c2ecf20Sopenharmony_ci	.pwr_reg = _pwr_reg,					\
6228c2ecf20Sopenharmony_ci	.en_mask = _en_mask,					\
6238c2ecf20Sopenharmony_ci	.flags = _flags,					\
6248c2ecf20Sopenharmony_ci	.rst_bar_mask = CON0_MT6797_RST_BAR,			\
6258c2ecf20Sopenharmony_ci	.fmax = MT6797_PLL_FMAX,				\
6268c2ecf20Sopenharmony_ci	.pcwbits = _pcwbits,					\
6278c2ecf20Sopenharmony_ci	.pd_reg = _pd_reg,					\
6288c2ecf20Sopenharmony_ci	.pd_shift = _pd_shift,					\
6298c2ecf20Sopenharmony_ci	.tuner_reg = _tuner_reg,				\
6308c2ecf20Sopenharmony_ci	.pcw_reg = _pcw_reg,					\
6318c2ecf20Sopenharmony_ci	.pcw_shift = _pcw_shift,				\
6328c2ecf20Sopenharmony_ci	.div_table = _div_table,				\
6338c2ecf20Sopenharmony_ci}
6348c2ecf20Sopenharmony_ci
6358c2ecf20Sopenharmony_ci#define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits,	\
6368c2ecf20Sopenharmony_ci			_pd_reg, _pd_shift, _tuner_reg, _pcw_reg,	\
6378c2ecf20Sopenharmony_ci			_pcw_shift)					\
6388c2ecf20Sopenharmony_ci		PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits, \
6398c2ecf20Sopenharmony_ci			_pd_reg, _pd_shift, _tuner_reg, _pcw_reg, _pcw_shift, \
6408c2ecf20Sopenharmony_ci			NULL)
6418c2ecf20Sopenharmony_ci
6428c2ecf20Sopenharmony_cistatic const struct mtk_pll_data plls[] = {
6438c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x0220, 0x022C, 0xF0000101, PLL_AO,
6448c2ecf20Sopenharmony_ci	    21, 0x220, 4, 0x0, 0x224, 0),
6458c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_UNIVPLL, "univpll", 0x0230, 0x023C, 0xFE000011, 0, 7,
6468c2ecf20Sopenharmony_ci	    0x230, 4, 0x0, 0x234, 14),
6478c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_MFGPLL, "mfgpll", 0x0240, 0x024C, 0x00000101, 0, 21,
6488c2ecf20Sopenharmony_ci	    0x244, 24, 0x0, 0x244, 0),
6498c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x0250, 0x025C, 0x00000121, 0, 21,
6508c2ecf20Sopenharmony_ci	    0x250, 4, 0x0, 0x254, 0),
6518c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_IMGPLL, "imgpll", 0x0260, 0x026C, 0x00000121, 0, 21,
6528c2ecf20Sopenharmony_ci	    0x260, 4, 0x0, 0x264, 0),
6538c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_TVDPLL, "tvdpll", 0x0270, 0x027C, 0xC0000121, 0, 21,
6548c2ecf20Sopenharmony_ci	    0x270, 4, 0x0, 0x274, 0),
6558c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_CODECPLL, "codecpll", 0x0290, 0x029C, 0x00000121, 0, 21,
6568c2ecf20Sopenharmony_ci	    0x290, 4, 0x0, 0x294, 0),
6578c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_VDECPLL, "vdecpll", 0x02E4, 0x02F0, 0x00000121, 0, 21,
6588c2ecf20Sopenharmony_ci	    0x2E4, 4, 0x0, 0x2E8, 0),
6598c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_APLL1, "apll1", 0x02A0, 0x02B0, 0x00000131, 0, 31,
6608c2ecf20Sopenharmony_ci	    0x2A0, 4, 0x2A8, 0x2A4, 0),
6618c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_APLL2, "apll2", 0x02B4, 0x02C4, 0x00000131, 0, 31,
6628c2ecf20Sopenharmony_ci	    0x2B4, 4, 0x2BC, 0x2B8, 0),
6638c2ecf20Sopenharmony_ci};
6648c2ecf20Sopenharmony_ci
6658c2ecf20Sopenharmony_cistatic int mtk_apmixedsys_init(struct platform_device *pdev)
6668c2ecf20Sopenharmony_ci{
6678c2ecf20Sopenharmony_ci	struct clk_onecell_data *clk_data;
6688c2ecf20Sopenharmony_ci	struct device_node *node = pdev->dev.of_node;
6698c2ecf20Sopenharmony_ci
6708c2ecf20Sopenharmony_ci	clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR);
6718c2ecf20Sopenharmony_ci	if (!clk_data)
6728c2ecf20Sopenharmony_ci		return -ENOMEM;
6738c2ecf20Sopenharmony_ci
6748c2ecf20Sopenharmony_ci	mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
6758c2ecf20Sopenharmony_ci
6768c2ecf20Sopenharmony_ci	return of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
6778c2ecf20Sopenharmony_ci}
6788c2ecf20Sopenharmony_ci
6798c2ecf20Sopenharmony_cistatic const struct of_device_id of_match_clk_mt6797[] = {
6808c2ecf20Sopenharmony_ci	{
6818c2ecf20Sopenharmony_ci		.compatible = "mediatek,mt6797-topckgen",
6828c2ecf20Sopenharmony_ci		.data = mtk_topckgen_init,
6838c2ecf20Sopenharmony_ci	}, {
6848c2ecf20Sopenharmony_ci		.compatible = "mediatek,mt6797-infracfg",
6858c2ecf20Sopenharmony_ci		.data = mtk_infrasys_init,
6868c2ecf20Sopenharmony_ci	}, {
6878c2ecf20Sopenharmony_ci		.compatible = "mediatek,mt6797-apmixedsys",
6888c2ecf20Sopenharmony_ci		.data = mtk_apmixedsys_init,
6898c2ecf20Sopenharmony_ci	}, {
6908c2ecf20Sopenharmony_ci		/* sentinel */
6918c2ecf20Sopenharmony_ci	}
6928c2ecf20Sopenharmony_ci};
6938c2ecf20Sopenharmony_ci
6948c2ecf20Sopenharmony_cistatic int clk_mt6797_probe(struct platform_device *pdev)
6958c2ecf20Sopenharmony_ci{
6968c2ecf20Sopenharmony_ci	int (*clk_init)(struct platform_device *);
6978c2ecf20Sopenharmony_ci	int r;
6988c2ecf20Sopenharmony_ci
6998c2ecf20Sopenharmony_ci	clk_init = of_device_get_match_data(&pdev->dev);
7008c2ecf20Sopenharmony_ci	if (!clk_init)
7018c2ecf20Sopenharmony_ci		return -EINVAL;
7028c2ecf20Sopenharmony_ci
7038c2ecf20Sopenharmony_ci	r = clk_init(pdev);
7048c2ecf20Sopenharmony_ci	if (r)
7058c2ecf20Sopenharmony_ci		dev_err(&pdev->dev,
7068c2ecf20Sopenharmony_ci			"could not register clock provider: %s: %d\n",
7078c2ecf20Sopenharmony_ci			pdev->name, r);
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_ci	return r;
7108c2ecf20Sopenharmony_ci}
7118c2ecf20Sopenharmony_ci
7128c2ecf20Sopenharmony_cistatic struct platform_driver clk_mt6797_drv = {
7138c2ecf20Sopenharmony_ci	.probe = clk_mt6797_probe,
7148c2ecf20Sopenharmony_ci	.driver = {
7158c2ecf20Sopenharmony_ci		.name = "clk-mt6797",
7168c2ecf20Sopenharmony_ci		.of_match_table = of_match_clk_mt6797,
7178c2ecf20Sopenharmony_ci	},
7188c2ecf20Sopenharmony_ci};
7198c2ecf20Sopenharmony_ci
7208c2ecf20Sopenharmony_cistatic int __init clk_mt6797_init(void)
7218c2ecf20Sopenharmony_ci{
7228c2ecf20Sopenharmony_ci	return platform_driver_register(&clk_mt6797_drv);
7238c2ecf20Sopenharmony_ci}
7248c2ecf20Sopenharmony_ci
7258c2ecf20Sopenharmony_ciarch_initcall(clk_mt6797_init);
726