18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2018 MediaTek Inc.
48c2ecf20Sopenharmony_ci * Author: Owen Chen <owen.chen@mediatek.com>
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
88c2ecf20Sopenharmony_ci#include <linux/of.h>
98c2ecf20Sopenharmony_ci#include <linux/of_address.h>
108c2ecf20Sopenharmony_ci#include <linux/slab.h>
118c2ecf20Sopenharmony_ci#include <linux/mfd/syscon.h>
128c2ecf20Sopenharmony_ci#include <linux/of_device.h>
138c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#include "clk-mtk.h"
168c2ecf20Sopenharmony_ci#include "clk-gate.h"
178c2ecf20Sopenharmony_ci#include "clk-mux.h"
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include <dt-bindings/clock/mt6765-clk.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci/*fmeter div select 4*/
228c2ecf20Sopenharmony_ci#define _DIV4_ 1
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_cistatic DEFINE_SPINLOCK(mt6765_clk_lock);
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/* Total 12 subsys */
278c2ecf20Sopenharmony_cistatic void __iomem *cksys_base;
288c2ecf20Sopenharmony_cistatic void __iomem *apmixed_base;
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* CKSYS */
318c2ecf20Sopenharmony_ci#define CLK_SCP_CFG_0		(cksys_base + 0x200)
328c2ecf20Sopenharmony_ci#define CLK_SCP_CFG_1		(cksys_base + 0x204)
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ci/* CG */
358c2ecf20Sopenharmony_ci#define AP_PLL_CON3		(apmixed_base + 0x0C)
368c2ecf20Sopenharmony_ci#define PLLON_CON0		(apmixed_base + 0x44)
378c2ecf20Sopenharmony_ci#define PLLON_CON1		(apmixed_base + 0x48)
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci/* clk cfg update */
408c2ecf20Sopenharmony_ci#define CLK_CFG_0		0x40
418c2ecf20Sopenharmony_ci#define CLK_CFG_0_SET		0x44
428c2ecf20Sopenharmony_ci#define CLK_CFG_0_CLR		0x48
438c2ecf20Sopenharmony_ci#define CLK_CFG_1		0x50
448c2ecf20Sopenharmony_ci#define CLK_CFG_1_SET		0x54
458c2ecf20Sopenharmony_ci#define CLK_CFG_1_CLR		0x58
468c2ecf20Sopenharmony_ci#define CLK_CFG_2		0x60
478c2ecf20Sopenharmony_ci#define CLK_CFG_2_SET		0x64
488c2ecf20Sopenharmony_ci#define CLK_CFG_2_CLR		0x68
498c2ecf20Sopenharmony_ci#define CLK_CFG_3		0x70
508c2ecf20Sopenharmony_ci#define CLK_CFG_3_SET		0x74
518c2ecf20Sopenharmony_ci#define CLK_CFG_3_CLR		0x78
528c2ecf20Sopenharmony_ci#define CLK_CFG_4		0x80
538c2ecf20Sopenharmony_ci#define CLK_CFG_4_SET		0x84
548c2ecf20Sopenharmony_ci#define CLK_CFG_4_CLR		0x88
558c2ecf20Sopenharmony_ci#define CLK_CFG_5		0x90
568c2ecf20Sopenharmony_ci#define CLK_CFG_5_SET		0x94
578c2ecf20Sopenharmony_ci#define CLK_CFG_5_CLR		0x98
588c2ecf20Sopenharmony_ci#define CLK_CFG_6		0xa0
598c2ecf20Sopenharmony_ci#define CLK_CFG_6_SET		0xa4
608c2ecf20Sopenharmony_ci#define CLK_CFG_6_CLR		0xa8
618c2ecf20Sopenharmony_ci#define CLK_CFG_7		0xb0
628c2ecf20Sopenharmony_ci#define CLK_CFG_7_SET		0xb4
638c2ecf20Sopenharmony_ci#define CLK_CFG_7_CLR		0xb8
648c2ecf20Sopenharmony_ci#define CLK_CFG_8		0xc0
658c2ecf20Sopenharmony_ci#define CLK_CFG_8_SET		0xc4
668c2ecf20Sopenharmony_ci#define CLK_CFG_8_CLR		0xc8
678c2ecf20Sopenharmony_ci#define CLK_CFG_9		0xd0
688c2ecf20Sopenharmony_ci#define CLK_CFG_9_SET		0xd4
698c2ecf20Sopenharmony_ci#define CLK_CFG_9_CLR		0xd8
708c2ecf20Sopenharmony_ci#define CLK_CFG_10		0xe0
718c2ecf20Sopenharmony_ci#define CLK_CFG_10_SET		0xe4
728c2ecf20Sopenharmony_ci#define CLK_CFG_10_CLR		0xe8
738c2ecf20Sopenharmony_ci#define CLK_CFG_UPDATE		0x004
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cistatic const struct mtk_fixed_clk fixed_clks[] = {
768c2ecf20Sopenharmony_ci	FIXED_CLK(CLK_TOP_F_FRTC, "f_frtc_ck", "clk32k", 32768),
778c2ecf20Sopenharmony_ci	FIXED_CLK(CLK_TOP_CLK26M, "clk_26m_ck", "clk26m", 26000000),
788c2ecf20Sopenharmony_ci	FIXED_CLK(CLK_TOP_DMPLL, "dmpll_ck", NULL, 466000000),
798c2ecf20Sopenharmony_ci};
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_cistatic const struct mtk_fixed_factor top_divs[] = {
828c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL, "syspll_ck", "mainpll", 1, 1),
838c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL_D2, "syspll_d2", "mainpll", 1, 2),
848c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL1_D2, "syspll1_d2", "syspll_d2", 1, 2),
858c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL1_D4, "syspll1_d4", "syspll_d2", 1, 4),
868c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL1_D8, "syspll1_d8", "syspll_d2", 1, 8),
878c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL1_D16, "syspll1_d16", "syspll_d2", 1, 16),
888c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL_D3, "syspll_d3", "mainpll", 1, 3),
898c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL2_D2, "syspll2_d2", "syspll_d3", 1, 2),
908c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL2_D4, "syspll2_d4", "syspll_d3", 1, 4),
918c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL2_D8, "syspll2_d8", "syspll_d3", 1, 8),
928c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL_D5, "syspll_d5", "mainpll", 1, 5),
938c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL3_D2, "syspll3_d2", "syspll_d5", 1, 2),
948c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL3_D4, "syspll3_d4", "syspll_d5", 1, 4),
958c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL_D7, "syspll_d7", "mainpll", 1, 7),
968c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL4_D2, "syspll4_d2", "syspll_d7", 1, 2),
978c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SYSPLL4_D4, "syspll4_d4", "syspll_d7", 1, 4),
988c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL, "univpll", "univ2pll", 1, 2),
998c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_USB20_192M, "usb20_192m_ck", "univpll", 2, 13),
1008c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_USB20_192M_D4, "usb20_192m_d4", "usb20_192m_ck", 1, 4),
1018c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_USB20_192M_D8, "usb20_192m_d8", "usb20_192m_ck", 1, 8),
1028c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_USB20_192M_D16,
1038c2ecf20Sopenharmony_ci	       "usb20_192m_d16", "usb20_192m_ck", 1, 16),
1048c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_USB20_192M_D32,
1058c2ecf20Sopenharmony_ci	       "usb20_192m_d32", "usb20_192m_ck", 1, 32),
1068c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL_D2, "univpll_d2", "univpll", 1, 2),
1078c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL1_D2, "univpll1_d2", "univpll_d2", 1, 2),
1088c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL1_D4, "univpll1_d4", "univpll_d2", 1, 4),
1098c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL_D3, "univpll_d3", "univpll", 1, 3),
1108c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL2_D2, "univpll2_d2", "univpll_d3", 1, 2),
1118c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL2_D4, "univpll2_d4", "univpll_d3", 1, 4),
1128c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL2_D8, "univpll2_d8", "univpll_d3", 1, 8),
1138c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL2_D32, "univpll2_d32", "univpll_d3", 1, 32),
1148c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL_D5, "univpll_d5", "univpll", 1, 5),
1158c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL3_D2, "univpll3_d2", "univpll_d5", 1, 2),
1168c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_UNIVPLL3_D4, "univpll3_d4", "univpll_d5", 1, 4),
1178c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_MMPLL, "mmpll_ck", "mmpll", 1, 1),
1188c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_MMPLL_D2, "mmpll_d2", "mmpll_ck", 1, 2),
1198c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_MPLL, "mpll_ck", "mpll", 1, 1),
1208c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_DA_MPLL_104M_DIV, "mpll_104m_div", "mpll_ck", 1, 2),
1218c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_DA_MPLL_52M_DIV, "mpll_52m_div", "mpll_ck", 1, 4),
1228c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_MFGPLL, "mfgpll_ck", "mfgpll", 1, 1),
1238c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_MSDCPLL, "msdcpll_ck", "msdcpll", 1, 1),
1248c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_MSDCPLL_D2, "msdcpll_d2", "msdcpll_ck", 1, 2),
1258c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_APLL1, "apll1_ck", "apll1", 1, 1),
1268c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_APLL1_D2, "apll1_d2", "apll1_ck", 1, 2),
1278c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_APLL1_D4, "apll1_d4", "apll1_ck", 1, 4),
1288c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_APLL1_D8, "apll1_d8", "apll1_ck", 1, 8),
1298c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_ULPOSC1, "ulposc1_ck", "ulposc1", 1, 1),
1308c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_ULPOSC1_D2, "ulposc1_d2", "ulposc1_ck", 1, 2),
1318c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_ULPOSC1_D4, "ulposc1_d4", "ulposc1_ck", 1, 4),
1328c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_ULPOSC1_D8, "ulposc1_d8", "ulposc1_ck", 1, 8),
1338c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_ULPOSC1_D16, "ulposc1_d16", "ulposc1_ck", 1, 16),
1348c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_ULPOSC1_D32, "ulposc1_d32", "ulposc1_ck", 1, 32),
1358c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_F_F26M, "f_f26m_ck", "clk_26m_ck", 1, 1),
1368c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_AXI, "axi_ck", "axi_sel", 1, 1),
1378c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_MM, "mm_ck", "mm_sel", 1, 1),
1388c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SCP, "scp_ck", "scp_sel", 1, 1),
1398c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_MFG, "mfg_ck", "mfg_sel", 1, 1),
1408c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_F_FUART, "f_fuart_ck", "uart_sel", 1, 1),
1418c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SPI, "spi_ck", "spi_sel", 1, 1),
1428c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_MSDC50_0, "msdc50_0_ck", "msdc50_0_sel", 1, 1),
1438c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_MSDC30_1, "msdc30_1_ck", "msdc30_1_sel", 1, 1),
1448c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_AUDIO, "audio_ck", "audio_sel", 1, 1),
1458c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_AUD_1, "aud_1_ck", "aud_1_sel", 1, 1),
1468c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_AUD_ENGEN1, "aud_engen1_ck", "aud_engen1_sel", 1, 1),
1478c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_F_FDISP_PWM, "f_fdisp_pwm_ck", "disp_pwm_sel", 1, 1),
1488c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_SSPM, "sspm_ck", "sspm_sel", 1, 1),
1498c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_DXCC, "dxcc_ck", "dxcc_sel", 1, 1),
1508c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_I2C, "i2c_ck", "i2c_sel", 1, 1),
1518c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_F_FPWM, "f_fpwm_ck", "pwm_sel", 1, 1),
1528c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_F_FSENINF, "f_fseninf_ck", "seninf_sel", 1, 1),
1538c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_AES_FDE, "aes_fde_ck", "aes_fde_sel", 1, 1),
1548c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_F_BIST2FPC, "f_bist2fpc_ck", "univpll2_d2", 1, 1),
1558c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_ARMPLL_DIVIDER_PLL0, "arm_div_pll0", "syspll_d2", 1, 1),
1568c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_ARMPLL_DIVIDER_PLL1, "arm_div_pll1", "syspll_ck", 1, 1),
1578c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_ARMPLL_DIVIDER_PLL2, "arm_div_pll2", "univpll_d2", 1, 1),
1588c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_DA_USB20_48M_DIV,
1598c2ecf20Sopenharmony_ci	       "usb20_48m_div", "usb20_192m_d4", 1, 1),
1608c2ecf20Sopenharmony_ci	FACTOR(CLK_TOP_DA_UNIV_48M_DIV, "univ_48m_div", "usb20_192m_d4", 1, 1),
1618c2ecf20Sopenharmony_ci};
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_cistatic const char * const axi_parents[] = {
1648c2ecf20Sopenharmony_ci	"clk26m",
1658c2ecf20Sopenharmony_ci	"syspll_d7",
1668c2ecf20Sopenharmony_ci	"syspll1_d4",
1678c2ecf20Sopenharmony_ci	"syspll3_d2"
1688c2ecf20Sopenharmony_ci};
1698c2ecf20Sopenharmony_ci
1708c2ecf20Sopenharmony_cistatic const char * const mem_parents[] = {
1718c2ecf20Sopenharmony_ci	"clk26m",
1728c2ecf20Sopenharmony_ci	"dmpll_ck",
1738c2ecf20Sopenharmony_ci	"apll1_ck"
1748c2ecf20Sopenharmony_ci};
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_cistatic const char * const mm_parents[] = {
1778c2ecf20Sopenharmony_ci	"clk26m",
1788c2ecf20Sopenharmony_ci	"mmpll_ck",
1798c2ecf20Sopenharmony_ci	"syspll1_d2",
1808c2ecf20Sopenharmony_ci	"syspll_d5",
1818c2ecf20Sopenharmony_ci	"syspll1_d4",
1828c2ecf20Sopenharmony_ci	"univpll_d5",
1838c2ecf20Sopenharmony_ci	"univpll1_d2",
1848c2ecf20Sopenharmony_ci	"mmpll_d2"
1858c2ecf20Sopenharmony_ci};
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_cistatic const char * const scp_parents[] = {
1888c2ecf20Sopenharmony_ci	"clk26m",
1898c2ecf20Sopenharmony_ci	"syspll4_d2",
1908c2ecf20Sopenharmony_ci	"univpll2_d2",
1918c2ecf20Sopenharmony_ci	"syspll1_d2",
1928c2ecf20Sopenharmony_ci	"univpll1_d2",
1938c2ecf20Sopenharmony_ci	"syspll_d3",
1948c2ecf20Sopenharmony_ci	"univpll_d3"
1958c2ecf20Sopenharmony_ci};
1968c2ecf20Sopenharmony_ci
1978c2ecf20Sopenharmony_cistatic const char * const mfg_parents[] = {
1988c2ecf20Sopenharmony_ci	"clk26m",
1998c2ecf20Sopenharmony_ci	"mfgpll_ck",
2008c2ecf20Sopenharmony_ci	"syspll_d3",
2018c2ecf20Sopenharmony_ci	"univpll_d3"
2028c2ecf20Sopenharmony_ci};
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_cistatic const char * const atb_parents[] = {
2058c2ecf20Sopenharmony_ci	"clk26m",
2068c2ecf20Sopenharmony_ci	"syspll1_d4",
2078c2ecf20Sopenharmony_ci	"syspll1_d2"
2088c2ecf20Sopenharmony_ci};
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_cistatic const char * const camtg_parents[] = {
2118c2ecf20Sopenharmony_ci	"clk26m",
2128c2ecf20Sopenharmony_ci	"usb20_192m_d8",
2138c2ecf20Sopenharmony_ci	"univpll2_d8",
2148c2ecf20Sopenharmony_ci	"usb20_192m_d4",
2158c2ecf20Sopenharmony_ci	"univpll2_d32",
2168c2ecf20Sopenharmony_ci	"usb20_192m_d16",
2178c2ecf20Sopenharmony_ci	"usb20_192m_d32"
2188c2ecf20Sopenharmony_ci};
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_cistatic const char * const uart_parents[] = {
2218c2ecf20Sopenharmony_ci	"clk26m",
2228c2ecf20Sopenharmony_ci	"univpll2_d8"
2238c2ecf20Sopenharmony_ci};
2248c2ecf20Sopenharmony_ci
2258c2ecf20Sopenharmony_cistatic const char * const spi_parents[] = {
2268c2ecf20Sopenharmony_ci	"clk26m",
2278c2ecf20Sopenharmony_ci	"syspll3_d2",
2288c2ecf20Sopenharmony_ci	"syspll4_d2",
2298c2ecf20Sopenharmony_ci	"syspll2_d4"
2308c2ecf20Sopenharmony_ci};
2318c2ecf20Sopenharmony_ci
2328c2ecf20Sopenharmony_cistatic const char * const msdc5hclk_parents[] = {
2338c2ecf20Sopenharmony_ci	"clk26m",
2348c2ecf20Sopenharmony_ci	"syspll1_d2",
2358c2ecf20Sopenharmony_ci	"univpll1_d4",
2368c2ecf20Sopenharmony_ci	"syspll2_d2"
2378c2ecf20Sopenharmony_ci};
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_cistatic const char * const msdc50_0_parents[] = {
2408c2ecf20Sopenharmony_ci	"clk26m",
2418c2ecf20Sopenharmony_ci	"msdcpll_ck",
2428c2ecf20Sopenharmony_ci	"syspll2_d2",
2438c2ecf20Sopenharmony_ci	"syspll4_d2",
2448c2ecf20Sopenharmony_ci	"univpll1_d2",
2458c2ecf20Sopenharmony_ci	"syspll1_d2",
2468c2ecf20Sopenharmony_ci	"univpll_d5",
2478c2ecf20Sopenharmony_ci	"univpll1_d4"
2488c2ecf20Sopenharmony_ci};
2498c2ecf20Sopenharmony_ci
2508c2ecf20Sopenharmony_cistatic const char * const msdc30_1_parents[] = {
2518c2ecf20Sopenharmony_ci	"clk26m",
2528c2ecf20Sopenharmony_ci	"msdcpll_d2",
2538c2ecf20Sopenharmony_ci	"univpll2_d2",
2548c2ecf20Sopenharmony_ci	"syspll2_d2",
2558c2ecf20Sopenharmony_ci	"syspll1_d4",
2568c2ecf20Sopenharmony_ci	"univpll1_d4",
2578c2ecf20Sopenharmony_ci	"usb20_192m_d4",
2588c2ecf20Sopenharmony_ci	"syspll2_d4"
2598c2ecf20Sopenharmony_ci};
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_cistatic const char * const audio_parents[] = {
2628c2ecf20Sopenharmony_ci	"clk26m",
2638c2ecf20Sopenharmony_ci	"syspll3_d4",
2648c2ecf20Sopenharmony_ci	"syspll4_d4",
2658c2ecf20Sopenharmony_ci	"syspll1_d16"
2668c2ecf20Sopenharmony_ci};
2678c2ecf20Sopenharmony_ci
2688c2ecf20Sopenharmony_cistatic const char * const aud_intbus_parents[] = {
2698c2ecf20Sopenharmony_ci	"clk26m",
2708c2ecf20Sopenharmony_ci	"syspll1_d4",
2718c2ecf20Sopenharmony_ci	"syspll4_d2"
2728c2ecf20Sopenharmony_ci};
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_cistatic const char * const aud_1_parents[] = {
2758c2ecf20Sopenharmony_ci	"clk26m",
2768c2ecf20Sopenharmony_ci	"apll1_ck"
2778c2ecf20Sopenharmony_ci};
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_cistatic const char * const aud_engen1_parents[] = {
2808c2ecf20Sopenharmony_ci	"clk26m",
2818c2ecf20Sopenharmony_ci	"apll1_d2",
2828c2ecf20Sopenharmony_ci	"apll1_d4",
2838c2ecf20Sopenharmony_ci	"apll1_d8"
2848c2ecf20Sopenharmony_ci};
2858c2ecf20Sopenharmony_ci
2868c2ecf20Sopenharmony_cistatic const char * const disp_pwm_parents[] = {
2878c2ecf20Sopenharmony_ci	"clk26m",
2888c2ecf20Sopenharmony_ci	"univpll2_d4",
2898c2ecf20Sopenharmony_ci	"ulposc1_d2",
2908c2ecf20Sopenharmony_ci	"ulposc1_d8"
2918c2ecf20Sopenharmony_ci};
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_cistatic const char * const sspm_parents[] = {
2948c2ecf20Sopenharmony_ci	"clk26m",
2958c2ecf20Sopenharmony_ci	"syspll1_d2",
2968c2ecf20Sopenharmony_ci	"syspll_d3"
2978c2ecf20Sopenharmony_ci};
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_cistatic const char * const dxcc_parents[] = {
3008c2ecf20Sopenharmony_ci	"clk26m",
3018c2ecf20Sopenharmony_ci	"syspll1_d2",
3028c2ecf20Sopenharmony_ci	"syspll1_d4",
3038c2ecf20Sopenharmony_ci	"syspll1_d8"
3048c2ecf20Sopenharmony_ci};
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_cistatic const char * const usb_top_parents[] = {
3078c2ecf20Sopenharmony_ci	"clk26m",
3088c2ecf20Sopenharmony_ci	"univpll3_d4"
3098c2ecf20Sopenharmony_ci};
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_cistatic const char * const spm_parents[] = {
3128c2ecf20Sopenharmony_ci	"clk26m",
3138c2ecf20Sopenharmony_ci	"syspll1_d8"
3148c2ecf20Sopenharmony_ci};
3158c2ecf20Sopenharmony_ci
3168c2ecf20Sopenharmony_cistatic const char * const i2c_parents[] = {
3178c2ecf20Sopenharmony_ci	"clk26m",
3188c2ecf20Sopenharmony_ci	"univpll3_d4",
3198c2ecf20Sopenharmony_ci	"univpll3_d2",
3208c2ecf20Sopenharmony_ci	"syspll1_d8",
3218c2ecf20Sopenharmony_ci	"syspll2_d8"
3228c2ecf20Sopenharmony_ci};
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_cistatic const char * const pwm_parents[] = {
3258c2ecf20Sopenharmony_ci	"clk26m",
3268c2ecf20Sopenharmony_ci	"univpll3_d4",
3278c2ecf20Sopenharmony_ci	"syspll1_d8"
3288c2ecf20Sopenharmony_ci};
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_cistatic const char * const seninf_parents[] = {
3318c2ecf20Sopenharmony_ci	"clk26m",
3328c2ecf20Sopenharmony_ci	"univpll1_d4",
3338c2ecf20Sopenharmony_ci	"univpll1_d2",
3348c2ecf20Sopenharmony_ci	"univpll2_d2"
3358c2ecf20Sopenharmony_ci};
3368c2ecf20Sopenharmony_ci
3378c2ecf20Sopenharmony_cistatic const char * const aes_fde_parents[] = {
3388c2ecf20Sopenharmony_ci	"clk26m",
3398c2ecf20Sopenharmony_ci	"msdcpll_ck",
3408c2ecf20Sopenharmony_ci	"univpll_d3",
3418c2ecf20Sopenharmony_ci	"univpll2_d2",
3428c2ecf20Sopenharmony_ci	"univpll1_d2",
3438c2ecf20Sopenharmony_ci	"syspll1_d2"
3448c2ecf20Sopenharmony_ci};
3458c2ecf20Sopenharmony_ci
3468c2ecf20Sopenharmony_cistatic const char * const ulposc_parents[] = {
3478c2ecf20Sopenharmony_ci	"clk26m",
3488c2ecf20Sopenharmony_ci	"ulposc1_d4",
3498c2ecf20Sopenharmony_ci	"ulposc1_d8",
3508c2ecf20Sopenharmony_ci	"ulposc1_d16",
3518c2ecf20Sopenharmony_ci	"ulposc1_d32"
3528c2ecf20Sopenharmony_ci};
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_cistatic const char * const camtm_parents[] = {
3558c2ecf20Sopenharmony_ci	"clk26m",
3568c2ecf20Sopenharmony_ci	"univpll1_d4",
3578c2ecf20Sopenharmony_ci	"univpll1_d2",
3588c2ecf20Sopenharmony_ci	"univpll2_d2"
3598c2ecf20Sopenharmony_ci};
3608c2ecf20Sopenharmony_ci
3618c2ecf20Sopenharmony_ci#define INVALID_UPDATE_REG 0xFFFFFFFF
3628c2ecf20Sopenharmony_ci#define INVALID_UPDATE_SHIFT -1
3638c2ecf20Sopenharmony_ci#define INVALID_MUX_GATE -1
3648c2ecf20Sopenharmony_ci
3658c2ecf20Sopenharmony_cistatic const struct mtk_mux top_muxes[] = {
3668c2ecf20Sopenharmony_ci	/* CLK_CFG_0 */
3678c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_AXI_SEL, "axi_sel", axi_parents,
3688c2ecf20Sopenharmony_ci			      CLK_CFG_0, CLK_CFG_0_SET, CLK_CFG_0_CLR,
3698c2ecf20Sopenharmony_ci			      0, 2, 7, CLK_CFG_UPDATE, 0, CLK_IS_CRITICAL),
3708c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_MEM_SEL, "mem_sel", mem_parents,
3718c2ecf20Sopenharmony_ci			      CLK_CFG_0, CLK_CFG_0_SET, CLK_CFG_0_CLR,
3728c2ecf20Sopenharmony_ci			      8, 2, 15, CLK_CFG_UPDATE, 1, CLK_IS_CRITICAL),
3738c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_MM_SEL, "mm_sel", mm_parents, CLK_CFG_0,
3748c2ecf20Sopenharmony_ci			CLK_CFG_0_SET, CLK_CFG_0_CLR, 16, 3, 23,
3758c2ecf20Sopenharmony_ci			CLK_CFG_UPDATE, 2),
3768c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_SCP_SEL, "scp_sel", scp_parents, CLK_CFG_0,
3778c2ecf20Sopenharmony_ci			CLK_CFG_0_SET, CLK_CFG_0_CLR, 24, 3, 31,
3788c2ecf20Sopenharmony_ci			CLK_CFG_UPDATE, 3),
3798c2ecf20Sopenharmony_ci	/* CLK_CFG_1 */
3808c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_MFG_SEL, "mfg_sel", mfg_parents, CLK_CFG_1,
3818c2ecf20Sopenharmony_ci			CLK_CFG_1_SET, CLK_CFG_1_CLR, 0, 2, 7,
3828c2ecf20Sopenharmony_ci			CLK_CFG_UPDATE, 4),
3838c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_ATB_SEL, "atb_sel", atb_parents, CLK_CFG_1,
3848c2ecf20Sopenharmony_ci			CLK_CFG_1_SET, CLK_CFG_1_CLR, 8, 2, 15,
3858c2ecf20Sopenharmony_ci			CLK_CFG_UPDATE, 5),
3868c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTG_SEL, "camtg_sel",
3878c2ecf20Sopenharmony_ci			camtg_parents, CLK_CFG_1, CLK_CFG_1_SET,
3888c2ecf20Sopenharmony_ci			CLK_CFG_1_CLR, 16, 3, 23, CLK_CFG_UPDATE, 6),
3898c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTG1_SEL, "camtg1_sel", camtg_parents,
3908c2ecf20Sopenharmony_ci			CLK_CFG_1, CLK_CFG_1_SET, CLK_CFG_1_CLR,
3918c2ecf20Sopenharmony_ci			24, 3, 31, CLK_CFG_UPDATE, 7),
3928c2ecf20Sopenharmony_ci	/* CLK_CFG_2 */
3938c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTG2_SEL, "camtg2_sel",
3948c2ecf20Sopenharmony_ci			camtg_parents, CLK_CFG_2, CLK_CFG_2_SET,
3958c2ecf20Sopenharmony_ci			CLK_CFG_2_CLR, 0, 3, 7, CLK_CFG_UPDATE, 8),
3968c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTG3_SEL, "camtg3_sel", camtg_parents,
3978c2ecf20Sopenharmony_ci			CLK_CFG_2, CLK_CFG_2_SET, CLK_CFG_2_CLR,
3988c2ecf20Sopenharmony_ci			8, 3, 15, CLK_CFG_UPDATE, 9),
3998c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_UART_SEL, "uart_sel", uart_parents,
4008c2ecf20Sopenharmony_ci			CLK_CFG_2, CLK_CFG_2_SET, CLK_CFG_2_CLR, 16, 1, 23,
4018c2ecf20Sopenharmony_ci			CLK_CFG_UPDATE, 10),
4028c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_SPI_SEL, "spi_sel", spi_parents, CLK_CFG_2,
4038c2ecf20Sopenharmony_ci			CLK_CFG_2_SET, CLK_CFG_2_CLR, 24, 2, 31,
4048c2ecf20Sopenharmony_ci			CLK_CFG_UPDATE, 11),
4058c2ecf20Sopenharmony_ci	/* CLK_CFG_3 */
4068c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_MSDC50_0_HCLK_SEL, "msdc5hclk",
4078c2ecf20Sopenharmony_ci			msdc5hclk_parents, CLK_CFG_3, CLK_CFG_3_SET,
4088c2ecf20Sopenharmony_ci			CLK_CFG_3_CLR, 0, 2, 7, CLK_CFG_UPDATE, 12),
4098c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_MSDC50_0_SEL, "msdc50_0_sel",
4108c2ecf20Sopenharmony_ci			msdc50_0_parents, CLK_CFG_3, CLK_CFG_3_SET,
4118c2ecf20Sopenharmony_ci			CLK_CFG_3_CLR, 8, 3, 15, CLK_CFG_UPDATE, 13),
4128c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_MSDC30_1_SEL, "msdc30_1_sel",
4138c2ecf20Sopenharmony_ci			msdc30_1_parents, CLK_CFG_3, CLK_CFG_3_SET,
4148c2ecf20Sopenharmony_ci			CLK_CFG_3_CLR, 16, 3, 23, CLK_CFG_UPDATE, 14),
4158c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_AUDIO_SEL, "audio_sel", audio_parents,
4168c2ecf20Sopenharmony_ci			CLK_CFG_3, CLK_CFG_3_SET, CLK_CFG_3_CLR,
4178c2ecf20Sopenharmony_ci			24, 2, 31, CLK_CFG_UPDATE, 15),
4188c2ecf20Sopenharmony_ci	/* CLK_CFG_4 */
4198c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_AUD_INTBUS_SEL, "aud_intbus_sel",
4208c2ecf20Sopenharmony_ci			aud_intbus_parents, CLK_CFG_4, CLK_CFG_4_SET,
4218c2ecf20Sopenharmony_ci			CLK_CFG_4_CLR, 0, 2, 7, CLK_CFG_UPDATE, 16),
4228c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_AUD_1_SEL, "aud_1_sel", aud_1_parents,
4238c2ecf20Sopenharmony_ci			CLK_CFG_4, CLK_CFG_4_SET, CLK_CFG_4_CLR,
4248c2ecf20Sopenharmony_ci			8, 1, 15, CLK_CFG_UPDATE, 17),
4258c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_AUD_ENGEN1_SEL, "aud_engen1_sel",
4268c2ecf20Sopenharmony_ci			aud_engen1_parents, CLK_CFG_4, CLK_CFG_4_SET,
4278c2ecf20Sopenharmony_ci			CLK_CFG_4_CLR, 16, 2, 23, CLK_CFG_UPDATE, 18),
4288c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_DISP_PWM_SEL, "disp_pwm_sel",
4298c2ecf20Sopenharmony_ci			disp_pwm_parents, CLK_CFG_4, CLK_CFG_4_SET,
4308c2ecf20Sopenharmony_ci			CLK_CFG_4_CLR, 24, 2, 31, CLK_CFG_UPDATE, 19),
4318c2ecf20Sopenharmony_ci	/* CLK_CFG_5 */
4328c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_SSPM_SEL, "sspm_sel", sspm_parents,
4338c2ecf20Sopenharmony_ci			CLK_CFG_5, CLK_CFG_5_SET, CLK_CFG_5_CLR, 0, 2, 7,
4348c2ecf20Sopenharmony_ci			CLK_CFG_UPDATE, 20),
4358c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_DXCC_SEL, "dxcc_sel", dxcc_parents,
4368c2ecf20Sopenharmony_ci			CLK_CFG_5, CLK_CFG_5_SET, CLK_CFG_5_CLR, 8, 2, 15,
4378c2ecf20Sopenharmony_ci			CLK_CFG_UPDATE, 21),
4388c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_USB_TOP_SEL, "usb_top_sel",
4398c2ecf20Sopenharmony_ci			usb_top_parents, CLK_CFG_5, CLK_CFG_5_SET,
4408c2ecf20Sopenharmony_ci			CLK_CFG_5_CLR, 16, 1, 23, CLK_CFG_UPDATE, 22),
4418c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_SPM_SEL, "spm_sel", spm_parents, CLK_CFG_5,
4428c2ecf20Sopenharmony_ci			CLK_CFG_5_SET, CLK_CFG_5_CLR, 24, 1, 31,
4438c2ecf20Sopenharmony_ci			CLK_CFG_UPDATE, 23),
4448c2ecf20Sopenharmony_ci	/* CLK_CFG_6 */
4458c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_I2C_SEL, "i2c_sel", i2c_parents, CLK_CFG_6,
4468c2ecf20Sopenharmony_ci			CLK_CFG_6_SET, CLK_CFG_6_CLR, 0, 3, 7, CLK_CFG_UPDATE,
4478c2ecf20Sopenharmony_ci			24),
4488c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_PWM_SEL, "pwm_sel", pwm_parents, CLK_CFG_6,
4498c2ecf20Sopenharmony_ci			CLK_CFG_6_SET, CLK_CFG_6_CLR, 8, 2, 15, CLK_CFG_UPDATE,
4508c2ecf20Sopenharmony_ci			25),
4518c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_SENINF_SEL, "seninf_sel", seninf_parents,
4528c2ecf20Sopenharmony_ci			CLK_CFG_6, CLK_CFG_6_SET, CLK_CFG_6_CLR, 16, 2, 23,
4538c2ecf20Sopenharmony_ci			CLK_CFG_UPDATE, 26),
4548c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_AES_FDE_SEL, "aes_fde_sel",
4558c2ecf20Sopenharmony_ci			aes_fde_parents, CLK_CFG_6, CLK_CFG_6_SET,
4568c2ecf20Sopenharmony_ci			CLK_CFG_6_CLR, 24, 3, 31, CLK_CFG_UPDATE, 27),
4578c2ecf20Sopenharmony_ci	/* CLK_CFG_7 */
4588c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD_FLAGS(CLK_TOP_PWRAP_ULPOSC_SEL, "ulposc_sel",
4598c2ecf20Sopenharmony_ci			      ulposc_parents, CLK_CFG_7, CLK_CFG_7_SET,
4608c2ecf20Sopenharmony_ci			      CLK_CFG_7_CLR, 0, 3, 7, CLK_CFG_UPDATE, 28,
4618c2ecf20Sopenharmony_ci			      CLK_IS_CRITICAL),
4628c2ecf20Sopenharmony_ci	MUX_GATE_CLR_SET_UPD(CLK_TOP_CAMTM_SEL, "camtm_sel", camtm_parents,
4638c2ecf20Sopenharmony_ci			CLK_CFG_7, CLK_CFG_7_SET, CLK_CFG_7_CLR, 8, 2, 15,
4648c2ecf20Sopenharmony_ci			CLK_CFG_UPDATE, 29),
4658c2ecf20Sopenharmony_ci};
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_cistatic const struct mtk_gate_regs top0_cg_regs = {
4688c2ecf20Sopenharmony_ci	.set_ofs = 0x0,
4698c2ecf20Sopenharmony_ci	.clr_ofs = 0x0,
4708c2ecf20Sopenharmony_ci	.sta_ofs = 0x0,
4718c2ecf20Sopenharmony_ci};
4728c2ecf20Sopenharmony_ci
4738c2ecf20Sopenharmony_cistatic const struct mtk_gate_regs top1_cg_regs = {
4748c2ecf20Sopenharmony_ci	.set_ofs = 0x104,
4758c2ecf20Sopenharmony_ci	.clr_ofs = 0x104,
4768c2ecf20Sopenharmony_ci	.sta_ofs = 0x104,
4778c2ecf20Sopenharmony_ci};
4788c2ecf20Sopenharmony_ci
4798c2ecf20Sopenharmony_cistatic const struct mtk_gate_regs top2_cg_regs = {
4808c2ecf20Sopenharmony_ci	.set_ofs = 0x320,
4818c2ecf20Sopenharmony_ci	.clr_ofs = 0x320,
4828c2ecf20Sopenharmony_ci	.sta_ofs = 0x320,
4838c2ecf20Sopenharmony_ci};
4848c2ecf20Sopenharmony_ci
4858c2ecf20Sopenharmony_ci#define GATE_TOP0(_id, _name, _parent, _shift) {	\
4868c2ecf20Sopenharmony_ci		.id = _id,				\
4878c2ecf20Sopenharmony_ci		.name = _name,				\
4888c2ecf20Sopenharmony_ci		.parent_name = _parent,			\
4898c2ecf20Sopenharmony_ci		.regs = &top0_cg_regs,			\
4908c2ecf20Sopenharmony_ci		.shift = _shift,			\
4918c2ecf20Sopenharmony_ci		.ops = &mtk_clk_gate_ops_no_setclr,	\
4928c2ecf20Sopenharmony_ci	}
4938c2ecf20Sopenharmony_ci
4948c2ecf20Sopenharmony_ci#define GATE_TOP1(_id, _name, _parent, _shift) {	\
4958c2ecf20Sopenharmony_ci		.id = _id,				\
4968c2ecf20Sopenharmony_ci		.name = _name,				\
4978c2ecf20Sopenharmony_ci		.parent_name = _parent,			\
4988c2ecf20Sopenharmony_ci		.regs = &top1_cg_regs,			\
4998c2ecf20Sopenharmony_ci		.shift = _shift,			\
5008c2ecf20Sopenharmony_ci		.ops = &mtk_clk_gate_ops_no_setclr_inv,	\
5018c2ecf20Sopenharmony_ci	}
5028c2ecf20Sopenharmony_ci
5038c2ecf20Sopenharmony_ci#define GATE_TOP2(_id, _name, _parent, _shift) {	\
5048c2ecf20Sopenharmony_ci		.id = _id,				\
5058c2ecf20Sopenharmony_ci		.name = _name,				\
5068c2ecf20Sopenharmony_ci		.parent_name = _parent,			\
5078c2ecf20Sopenharmony_ci		.regs = &top2_cg_regs,			\
5088c2ecf20Sopenharmony_ci		.shift = _shift,			\
5098c2ecf20Sopenharmony_ci		.ops = &mtk_clk_gate_ops_no_setclr,	\
5108c2ecf20Sopenharmony_ci	}
5118c2ecf20Sopenharmony_ci
5128c2ecf20Sopenharmony_cistatic const struct mtk_gate top_clks[] = {
5138c2ecf20Sopenharmony_ci	/* TOP0 */
5148c2ecf20Sopenharmony_ci	GATE_TOP0(CLK_TOP_MD_32K, "md_32k", "f_frtc_ck", 8),
5158c2ecf20Sopenharmony_ci	GATE_TOP0(CLK_TOP_MD_26M, "md_26m", "f_f26m_ck", 9),
5168c2ecf20Sopenharmony_ci	GATE_TOP0(CLK_TOP_MD2_32K, "md2_32k", "f_frtc_ck", 10),
5178c2ecf20Sopenharmony_ci	GATE_TOP0(CLK_TOP_MD2_26M, "md2_26m", "f_f26m_ck", 11),
5188c2ecf20Sopenharmony_ci	/* TOP1 */
5198c2ecf20Sopenharmony_ci	GATE_TOP1(CLK_TOP_ARMPLL_DIVIDER_PLL0_EN,
5208c2ecf20Sopenharmony_ci		  "arm_div_pll0_en", "arm_div_pll0", 3),
5218c2ecf20Sopenharmony_ci	GATE_TOP1(CLK_TOP_ARMPLL_DIVIDER_PLL1_EN,
5228c2ecf20Sopenharmony_ci		  "arm_div_pll1_en", "arm_div_pll1", 4),
5238c2ecf20Sopenharmony_ci	GATE_TOP1(CLK_TOP_ARMPLL_DIVIDER_PLL2_EN,
5248c2ecf20Sopenharmony_ci		  "arm_div_pll2_en", "arm_div_pll2", 5),
5258c2ecf20Sopenharmony_ci	GATE_TOP1(CLK_TOP_FMEM_OCC_DRC_EN, "drc_en", "univpll2_d2", 6),
5268c2ecf20Sopenharmony_ci	GATE_TOP1(CLK_TOP_USB20_48M_EN, "usb20_48m_en", "usb20_48m_div", 8),
5278c2ecf20Sopenharmony_ci	GATE_TOP1(CLK_TOP_UNIVPLL_48M_EN, "univpll_48m_en", "univ_48m_div", 9),
5288c2ecf20Sopenharmony_ci	GATE_TOP1(CLK_TOP_F_UFS_MP_SAP_CFG_EN, "ufs_sap", "f_f26m_ck", 12),
5298c2ecf20Sopenharmony_ci	GATE_TOP1(CLK_TOP_F_BIST2FPC_EN, "bist2fpc", "f_bist2fpc_ck", 16),
5308c2ecf20Sopenharmony_ci	/* TOP2 */
5318c2ecf20Sopenharmony_ci	GATE_TOP2(CLK_TOP_APLL12_DIV0, "apll12_div0", "aud_1_ck", 2),
5328c2ecf20Sopenharmony_ci	GATE_TOP2(CLK_TOP_APLL12_DIV1, "apll12_div1", "aud_1_ck", 3),
5338c2ecf20Sopenharmony_ci	GATE_TOP2(CLK_TOP_APLL12_DIV2, "apll12_div2", "aud_1_ck", 4),
5348c2ecf20Sopenharmony_ci	GATE_TOP2(CLK_TOP_APLL12_DIV3, "apll12_div3", "aud_1_ck", 5),
5358c2ecf20Sopenharmony_ci};
5368c2ecf20Sopenharmony_ci
5378c2ecf20Sopenharmony_cistatic const struct mtk_gate_regs ifr2_cg_regs = {
5388c2ecf20Sopenharmony_ci	.set_ofs = 0x80,
5398c2ecf20Sopenharmony_ci	.clr_ofs = 0x84,
5408c2ecf20Sopenharmony_ci	.sta_ofs = 0x90,
5418c2ecf20Sopenharmony_ci};
5428c2ecf20Sopenharmony_ci
5438c2ecf20Sopenharmony_cistatic const struct mtk_gate_regs ifr3_cg_regs = {
5448c2ecf20Sopenharmony_ci	.set_ofs = 0x88,
5458c2ecf20Sopenharmony_ci	.clr_ofs = 0x8c,
5468c2ecf20Sopenharmony_ci	.sta_ofs = 0x94,
5478c2ecf20Sopenharmony_ci};
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_cistatic const struct mtk_gate_regs ifr4_cg_regs = {
5508c2ecf20Sopenharmony_ci	.set_ofs = 0xa4,
5518c2ecf20Sopenharmony_ci	.clr_ofs = 0xa8,
5528c2ecf20Sopenharmony_ci	.sta_ofs = 0xac,
5538c2ecf20Sopenharmony_ci};
5548c2ecf20Sopenharmony_ci
5558c2ecf20Sopenharmony_cistatic const struct mtk_gate_regs ifr5_cg_regs = {
5568c2ecf20Sopenharmony_ci	.set_ofs = 0xc0,
5578c2ecf20Sopenharmony_ci	.clr_ofs = 0xc4,
5588c2ecf20Sopenharmony_ci	.sta_ofs = 0xc8,
5598c2ecf20Sopenharmony_ci};
5608c2ecf20Sopenharmony_ci
5618c2ecf20Sopenharmony_ci#define GATE_IFR2(_id, _name, _parent, _shift) {	\
5628c2ecf20Sopenharmony_ci		.id = _id,				\
5638c2ecf20Sopenharmony_ci		.name = _name,				\
5648c2ecf20Sopenharmony_ci		.parent_name = _parent,			\
5658c2ecf20Sopenharmony_ci		.regs = &ifr2_cg_regs,			\
5668c2ecf20Sopenharmony_ci		.shift = _shift,			\
5678c2ecf20Sopenharmony_ci		.ops = &mtk_clk_gate_ops_setclr,	\
5688c2ecf20Sopenharmony_ci	}
5698c2ecf20Sopenharmony_ci
5708c2ecf20Sopenharmony_ci#define GATE_IFR3(_id, _name, _parent, _shift) {	\
5718c2ecf20Sopenharmony_ci		.id = _id,				\
5728c2ecf20Sopenharmony_ci		.name = _name,				\
5738c2ecf20Sopenharmony_ci		.parent_name = _parent,			\
5748c2ecf20Sopenharmony_ci		.regs = &ifr3_cg_regs,			\
5758c2ecf20Sopenharmony_ci		.shift = _shift,			\
5768c2ecf20Sopenharmony_ci		.ops = &mtk_clk_gate_ops_setclr,	\
5778c2ecf20Sopenharmony_ci	}
5788c2ecf20Sopenharmony_ci
5798c2ecf20Sopenharmony_ci#define GATE_IFR4(_id, _name, _parent, _shift) {	\
5808c2ecf20Sopenharmony_ci		.id = _id,				\
5818c2ecf20Sopenharmony_ci		.name = _name,				\
5828c2ecf20Sopenharmony_ci		.parent_name = _parent,			\
5838c2ecf20Sopenharmony_ci		.regs = &ifr4_cg_regs,			\
5848c2ecf20Sopenharmony_ci		.shift = _shift,			\
5858c2ecf20Sopenharmony_ci		.ops = &mtk_clk_gate_ops_setclr,	\
5868c2ecf20Sopenharmony_ci	}
5878c2ecf20Sopenharmony_ci
5888c2ecf20Sopenharmony_ci#define GATE_IFR5(_id, _name, _parent, _shift) {	\
5898c2ecf20Sopenharmony_ci		.id = _id,				\
5908c2ecf20Sopenharmony_ci		.name = _name,				\
5918c2ecf20Sopenharmony_ci		.parent_name = _parent,			\
5928c2ecf20Sopenharmony_ci		.regs = &ifr5_cg_regs,			\
5938c2ecf20Sopenharmony_ci		.shift = _shift,			\
5948c2ecf20Sopenharmony_ci		.ops = &mtk_clk_gate_ops_setclr,	\
5958c2ecf20Sopenharmony_ci	}
5968c2ecf20Sopenharmony_ci
5978c2ecf20Sopenharmony_cistatic const struct mtk_gate ifr_clks[] = {
5988c2ecf20Sopenharmony_ci	/* INFRA_TOPAXI */
5998c2ecf20Sopenharmony_ci	/* INFRA PERI */
6008c2ecf20Sopenharmony_ci	/* INFRA mode 0 */
6018c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_ICUSB, "ifr_icusb", "axi_ck", 8),
6028c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_GCE, "ifr_gce", "axi_ck", 9),
6038c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_THERM, "ifr_therm", "axi_ck", 10),
6048c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_I2C_AP, "ifr_i2c_ap", "i2c_ck", 11),
6058c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_I2C_CCU, "ifr_i2c_ccu", "i2c_ck", 12),
6068c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_I2C_SSPM, "ifr_i2c_sspm", "i2c_ck", 13),
6078c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_I2C_RSV, "ifr_i2c_rsv", "i2c_ck", 14),
6088c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_PWM_HCLK, "ifr_pwm_hclk", "axi_ck", 15),
6098c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_PWM1, "ifr_pwm1", "f_fpwm_ck", 16),
6108c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_PWM2, "ifr_pwm2", "f_fpwm_ck", 17),
6118c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_PWM3, "ifr_pwm3", "f_fpwm_ck", 18),
6128c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_PWM4, "ifr_pwm4", "f_fpwm_ck", 19),
6138c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_PWM5, "ifr_pwm5", "f_fpwm_ck", 20),
6148c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_PWM, "ifr_pwm", "f_fpwm_ck", 21),
6158c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_UART0, "ifr_uart0", "f_fuart_ck", 22),
6168c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_UART1, "ifr_uart1", "f_fuart_ck", 23),
6178c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_GCE_26M, "ifr_gce_26m", "f_f26m_ck", 27),
6188c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_CQ_DMA_FPC, "ifr_dma", "axi_ck", 28),
6198c2ecf20Sopenharmony_ci	GATE_IFR2(CLK_IFR_BTIF, "ifr_btif", "axi_ck", 31),
6208c2ecf20Sopenharmony_ci	/* INFRA mode 1 */
6218c2ecf20Sopenharmony_ci	GATE_IFR3(CLK_IFR_SPI0, "ifr_spi0", "spi_ck", 1),
6228c2ecf20Sopenharmony_ci	GATE_IFR3(CLK_IFR_MSDC0, "ifr_msdc0", "msdc5hclk", 2),
6238c2ecf20Sopenharmony_ci	GATE_IFR3(CLK_IFR_MSDC1, "ifr_msdc1", "axi_ck", 4),
6248c2ecf20Sopenharmony_ci	GATE_IFR3(CLK_IFR_TRNG, "ifr_trng", "axi_ck", 9),
6258c2ecf20Sopenharmony_ci	GATE_IFR3(CLK_IFR_AUXADC, "ifr_auxadc", "f_f26m_ck", 10),
6268c2ecf20Sopenharmony_ci	GATE_IFR3(CLK_IFR_CCIF1_AP, "ifr_ccif1_ap", "axi_ck", 12),
6278c2ecf20Sopenharmony_ci	GATE_IFR3(CLK_IFR_CCIF1_MD, "ifr_ccif1_md", "axi_ck", 13),
6288c2ecf20Sopenharmony_ci	GATE_IFR3(CLK_IFR_AUXADC_MD, "ifr_auxadc_md", "f_f26m_ck", 14),
6298c2ecf20Sopenharmony_ci	GATE_IFR3(CLK_IFR_AP_DMA, "ifr_ap_dma", "axi_ck", 18),
6308c2ecf20Sopenharmony_ci	GATE_IFR3(CLK_IFR_DEVICE_APC, "ifr_dapc", "axi_ck", 20),
6318c2ecf20Sopenharmony_ci	GATE_IFR3(CLK_IFR_CCIF_AP, "ifr_ccif_ap", "axi_ck", 23),
6328c2ecf20Sopenharmony_ci	GATE_IFR3(CLK_IFR_AUDIO, "ifr_audio", "axi_ck", 25),
6338c2ecf20Sopenharmony_ci	GATE_IFR3(CLK_IFR_CCIF_MD, "ifr_ccif_md", "axi_ck", 26),
6348c2ecf20Sopenharmony_ci	/* INFRA mode 2 */
6358c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_RG_PWM_FBCLK6, "ifr_pwmfb", "f_f26m_ck", 0),
6368c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_DISP_PWM, "ifr_disp_pwm", "f_fdisp_pwm_ck", 2),
6378c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_CLDMA_BCLK, "ifr_cldmabclk", "axi_ck", 3),
6388c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_AUDIO_26M_BCLK, "ifr_audio26m", "f_f26m_ck", 4),
6398c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_SPI1, "ifr_spi1", "spi_ck", 6),
6408c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_I2C4, "ifr_i2c4", "i2c_ck", 7),
6418c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_SPI2, "ifr_spi2", "spi_ck", 9),
6428c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_SPI3, "ifr_spi3", "spi_ck", 10),
6438c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_I2C5, "ifr_i2c5", "i2c_ck", 18),
6448c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_I2C5_ARBITER, "ifr_i2c5a", "i2c_ck", 19),
6458c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_I2C5_IMM, "ifr_i2c5_imm", "i2c_ck", 20),
6468c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_I2C1_ARBITER, "ifr_i2c1a", "i2c_ck", 21),
6478c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_I2C1_IMM, "ifr_i2c1_imm", "i2c_ck", 22),
6488c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_I2C2_ARBITER, "ifr_i2c2a", "i2c_ck", 23),
6498c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_I2C2_IMM, "ifr_i2c2_imm", "i2c_ck", 24),
6508c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_SPI4, "ifr_spi4", "spi_ck", 25),
6518c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_SPI5, "ifr_spi5", "spi_ck", 26),
6528c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_CQ_DMA, "ifr_cq_dma", "axi_ck", 27),
6538c2ecf20Sopenharmony_ci	GATE_IFR4(CLK_IFR_FAES_FDE, "ifr_faes_fde_ck", "aes_fde_ck", 29),
6548c2ecf20Sopenharmony_ci	/* INFRA mode 3 */
6558c2ecf20Sopenharmony_ci	GATE_IFR5(CLK_IFR_MSDC0_SELF, "ifr_msdc0sf", "msdc50_0_ck", 0),
6568c2ecf20Sopenharmony_ci	GATE_IFR5(CLK_IFR_MSDC1_SELF, "ifr_msdc1sf", "msdc50_0_ck", 1),
6578c2ecf20Sopenharmony_ci	GATE_IFR5(CLK_IFR_I2C6, "ifr_i2c6", "i2c_ck", 6),
6588c2ecf20Sopenharmony_ci	GATE_IFR5(CLK_IFR_AP_MSDC0, "ifr_ap_msdc0", "msdc50_0_ck", 7),
6598c2ecf20Sopenharmony_ci	GATE_IFR5(CLK_IFR_MD_MSDC0, "ifr_md_msdc0", "msdc50_0_ck", 8),
6608c2ecf20Sopenharmony_ci	GATE_IFR5(CLK_IFR_MSDC0_SRC, "ifr_msdc0_clk", "msdc50_0_ck", 9),
6618c2ecf20Sopenharmony_ci	GATE_IFR5(CLK_IFR_MSDC1_SRC, "ifr_msdc1_clk", "msdc30_1_ck", 10),
6628c2ecf20Sopenharmony_ci	GATE_IFR5(CLK_IFR_MCU_PM_BCLK, "ifr_mcu_pm_bclk", "axi_ck", 17),
6638c2ecf20Sopenharmony_ci	GATE_IFR5(CLK_IFR_CCIF2_AP, "ifr_ccif2_ap", "axi_ck", 18),
6648c2ecf20Sopenharmony_ci	GATE_IFR5(CLK_IFR_CCIF2_MD, "ifr_ccif2_md", "axi_ck", 19),
6658c2ecf20Sopenharmony_ci	GATE_IFR5(CLK_IFR_CCIF3_AP, "ifr_ccif3_ap", "axi_ck", 20),
6668c2ecf20Sopenharmony_ci	GATE_IFR5(CLK_IFR_CCIF3_MD, "ifr_ccif3_md", "axi_ck", 21),
6678c2ecf20Sopenharmony_ci};
6688c2ecf20Sopenharmony_ci
6698c2ecf20Sopenharmony_ci/* additional CCF control for mipi26M race condition(disp/camera) */
6708c2ecf20Sopenharmony_cistatic const struct mtk_gate_regs apmixed_cg_regs = {
6718c2ecf20Sopenharmony_ci	.set_ofs = 0x14,
6728c2ecf20Sopenharmony_ci	.clr_ofs = 0x14,
6738c2ecf20Sopenharmony_ci	.sta_ofs = 0x14,
6748c2ecf20Sopenharmony_ci};
6758c2ecf20Sopenharmony_ci
6768c2ecf20Sopenharmony_ci#define GATE_APMIXED(_id, _name, _parent, _shift) {	\
6778c2ecf20Sopenharmony_ci		.id = _id,				\
6788c2ecf20Sopenharmony_ci		.name = _name,				\
6798c2ecf20Sopenharmony_ci		.parent_name = _parent,			\
6808c2ecf20Sopenharmony_ci		.regs = &apmixed_cg_regs,		\
6818c2ecf20Sopenharmony_ci		.shift = _shift,			\
6828c2ecf20Sopenharmony_ci		.ops = &mtk_clk_gate_ops_no_setclr_inv,		\
6838c2ecf20Sopenharmony_ci	}
6848c2ecf20Sopenharmony_ci
6858c2ecf20Sopenharmony_cistatic const struct mtk_gate apmixed_clks[] = {
6868c2ecf20Sopenharmony_ci	/* AUDIO0 */
6878c2ecf20Sopenharmony_ci	GATE_APMIXED(CLK_APMIXED_SSUSB26M, "apmixed_ssusb26m", "f_f26m_ck",
6888c2ecf20Sopenharmony_ci		     4),
6898c2ecf20Sopenharmony_ci	GATE_APMIXED(CLK_APMIXED_APPLL26M, "apmixed_appll26m", "f_f26m_ck",
6908c2ecf20Sopenharmony_ci		     5),
6918c2ecf20Sopenharmony_ci	GATE_APMIXED(CLK_APMIXED_MIPIC0_26M, "apmixed_mipic026m", "f_f26m_ck",
6928c2ecf20Sopenharmony_ci		     6),
6938c2ecf20Sopenharmony_ci	GATE_APMIXED(CLK_APMIXED_MDPLLGP26M, "apmixed_mdpll26m", "f_f26m_ck",
6948c2ecf20Sopenharmony_ci		     7),
6958c2ecf20Sopenharmony_ci	GATE_APMIXED(CLK_APMIXED_MMSYS_F26M, "apmixed_mmsys26m", "f_f26m_ck",
6968c2ecf20Sopenharmony_ci		     8),
6978c2ecf20Sopenharmony_ci	GATE_APMIXED(CLK_APMIXED_UFS26M, "apmixed_ufs26m", "f_f26m_ck",
6988c2ecf20Sopenharmony_ci		     9),
6998c2ecf20Sopenharmony_ci	GATE_APMIXED(CLK_APMIXED_MIPIC1_26M, "apmixed_mipic126m", "f_f26m_ck",
7008c2ecf20Sopenharmony_ci		     11),
7018c2ecf20Sopenharmony_ci	GATE_APMIXED(CLK_APMIXED_MEMPLL26M, "apmixed_mempll26m", "f_f26m_ck",
7028c2ecf20Sopenharmony_ci		     13),
7038c2ecf20Sopenharmony_ci	GATE_APMIXED(CLK_APMIXED_CLKSQ_LVPLL_26M, "apmixed_lvpll26m",
7048c2ecf20Sopenharmony_ci		     "f_f26m_ck", 14),
7058c2ecf20Sopenharmony_ci	GATE_APMIXED(CLK_APMIXED_MIPID0_26M, "apmixed_mipid026m", "f_f26m_ck",
7068c2ecf20Sopenharmony_ci		     16),
7078c2ecf20Sopenharmony_ci};
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_ci#define MT6765_PLL_FMAX		(3800UL * MHZ)
7108c2ecf20Sopenharmony_ci#define MT6765_PLL_FMIN		(1500UL * MHZ)
7118c2ecf20Sopenharmony_ci
7128c2ecf20Sopenharmony_ci#define CON0_MT6765_RST_BAR	BIT(23)
7138c2ecf20Sopenharmony_ci
7148c2ecf20Sopenharmony_ci#define PLL_INFO_NULL		(0xFF)
7158c2ecf20Sopenharmony_ci
7168c2ecf20Sopenharmony_ci#define PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits,	\
7178c2ecf20Sopenharmony_ci		_pcwibits, _pd_reg, _pd_shift, _tuner_reg, _tuner_en_reg,\
7188c2ecf20Sopenharmony_ci		_tuner_en_bit, _pcw_reg, _pcw_shift, _div_table) {\
7198c2ecf20Sopenharmony_ci		.id = _id,						\
7208c2ecf20Sopenharmony_ci		.name = _name,						\
7218c2ecf20Sopenharmony_ci		.reg = _reg,						\
7228c2ecf20Sopenharmony_ci		.pwr_reg = _pwr_reg,					\
7238c2ecf20Sopenharmony_ci		.en_mask = _en_mask,					\
7248c2ecf20Sopenharmony_ci		.flags = _flags,					\
7258c2ecf20Sopenharmony_ci		.rst_bar_mask = CON0_MT6765_RST_BAR,			\
7268c2ecf20Sopenharmony_ci		.fmax = MT6765_PLL_FMAX,				\
7278c2ecf20Sopenharmony_ci		.fmin = MT6765_PLL_FMIN,				\
7288c2ecf20Sopenharmony_ci		.pcwbits = _pcwbits,					\
7298c2ecf20Sopenharmony_ci		.pcwibits = _pcwibits,					\
7308c2ecf20Sopenharmony_ci		.pd_reg = _pd_reg,					\
7318c2ecf20Sopenharmony_ci		.pd_shift = _pd_shift,					\
7328c2ecf20Sopenharmony_ci		.tuner_reg = _tuner_reg,				\
7338c2ecf20Sopenharmony_ci		.tuner_en_reg = _tuner_en_reg,				\
7348c2ecf20Sopenharmony_ci		.tuner_en_bit = _tuner_en_bit,				\
7358c2ecf20Sopenharmony_ci		.pcw_reg = _pcw_reg,					\
7368c2ecf20Sopenharmony_ci		.pcw_shift = _pcw_shift,				\
7378c2ecf20Sopenharmony_ci		.div_table = _div_table,				\
7388c2ecf20Sopenharmony_ci	}
7398c2ecf20Sopenharmony_ci
7408c2ecf20Sopenharmony_ci#define PLL(_id, _name, _reg, _pwr_reg, _en_mask, _flags, _pcwbits,	\
7418c2ecf20Sopenharmony_ci			_pcwibits, _pd_reg, _pd_shift, _tuner_reg,	\
7428c2ecf20Sopenharmony_ci			_tuner_en_reg, _tuner_en_bit, _pcw_reg,	\
7438c2ecf20Sopenharmony_ci			_pcw_shift)	\
7448c2ecf20Sopenharmony_ci		PLL_B(_id, _name, _reg, _pwr_reg, _en_mask, _flags,	\
7458c2ecf20Sopenharmony_ci			_pcwbits, _pcwibits, _pd_reg, _pd_shift,	\
7468c2ecf20Sopenharmony_ci			_tuner_reg, _tuner_en_reg, _tuner_en_bit,	\
7478c2ecf20Sopenharmony_ci			_pcw_reg, _pcw_shift, NULL)	\
7488c2ecf20Sopenharmony_ci
7498c2ecf20Sopenharmony_cistatic const struct mtk_pll_data plls[] = {
7508c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_ARMPLL_L, "armpll_l", 0x021C, 0x0228, BIT(0),
7518c2ecf20Sopenharmony_ci	    PLL_AO, 22, 8, 0x0220, 24, 0, 0, 0, 0x0220, 0),
7528c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_ARMPLL, "armpll", 0x020C, 0x0218, BIT(0),
7538c2ecf20Sopenharmony_ci	    PLL_AO, 22, 8, 0x0210, 24, 0, 0, 0, 0x0210, 0),
7548c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_CCIPLL, "ccipll", 0x022C, 0x0238, BIT(0),
7558c2ecf20Sopenharmony_ci	    PLL_AO, 22, 8, 0x0230, 24, 0, 0, 0, 0x0230, 0),
7568c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_MAINPLL, "mainpll", 0x023C, 0x0248, BIT(0),
7578c2ecf20Sopenharmony_ci	    (HAVE_RST_BAR | PLL_AO), 22, 8, 0x0240, 24, 0, 0, 0, 0x0240,
7588c2ecf20Sopenharmony_ci	    0),
7598c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_MFGPLL, "mfgpll", 0x024C, 0x0258, BIT(0),
7608c2ecf20Sopenharmony_ci	    0, 22, 8, 0x0250, 24, 0, 0, 0, 0x0250, 0),
7618c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_MMPLL, "mmpll", 0x025C, 0x0268, BIT(0),
7628c2ecf20Sopenharmony_ci	    0, 22, 8, 0x0260, 24, 0, 0, 0, 0x0260, 0),
7638c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_UNIV2PLL, "univ2pll", 0x026C, 0x0278, BIT(0),
7648c2ecf20Sopenharmony_ci	    HAVE_RST_BAR, 22, 8, 0x0270, 24, 0, 0, 0, 0x0270, 0),
7658c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_MSDCPLL, "msdcpll", 0x027C, 0x0288, BIT(0),
7668c2ecf20Sopenharmony_ci	    0, 22, 8, 0x0280, 24, 0, 0, 0, 0x0280, 0),
7678c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_APLL1, "apll1", 0x028C, 0x029C, BIT(0),
7688c2ecf20Sopenharmony_ci	    0, 32, 8, 0x0290, 24, 0x0040, 0x000C, 0, 0x0294, 0),
7698c2ecf20Sopenharmony_ci	PLL(CLK_APMIXED_MPLL, "mpll", 0x02A0, 0x02AC, BIT(0),
7708c2ecf20Sopenharmony_ci	    PLL_AO, 22, 8, 0x02A4, 24, 0, 0, 0, 0x02A4, 0),
7718c2ecf20Sopenharmony_ci};
7728c2ecf20Sopenharmony_ci
7738c2ecf20Sopenharmony_cistatic int clk_mt6765_apmixed_probe(struct platform_device *pdev)
7748c2ecf20Sopenharmony_ci{
7758c2ecf20Sopenharmony_ci	struct clk_onecell_data *clk_data;
7768c2ecf20Sopenharmony_ci	int r;
7778c2ecf20Sopenharmony_ci	struct device_node *node = pdev->dev.of_node;
7788c2ecf20Sopenharmony_ci	void __iomem *base;
7798c2ecf20Sopenharmony_ci	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
7808c2ecf20Sopenharmony_ci
7818c2ecf20Sopenharmony_ci	base = devm_ioremap_resource(&pdev->dev, res);
7828c2ecf20Sopenharmony_ci	if (IS_ERR(base)) {
7838c2ecf20Sopenharmony_ci		pr_err("%s(): ioremap failed\n", __func__);
7848c2ecf20Sopenharmony_ci		return PTR_ERR(base);
7858c2ecf20Sopenharmony_ci	}
7868c2ecf20Sopenharmony_ci
7878c2ecf20Sopenharmony_ci	clk_data = mtk_alloc_clk_data(CLK_APMIXED_NR_CLK);
7888c2ecf20Sopenharmony_ci	if (!clk_data)
7898c2ecf20Sopenharmony_ci		return -ENOMEM;
7908c2ecf20Sopenharmony_ci
7918c2ecf20Sopenharmony_ci	mtk_clk_register_plls(node, plls, ARRAY_SIZE(plls), clk_data);
7928c2ecf20Sopenharmony_ci
7938c2ecf20Sopenharmony_ci	mtk_clk_register_gates(node, apmixed_clks,
7948c2ecf20Sopenharmony_ci			       ARRAY_SIZE(apmixed_clks), clk_data);
7958c2ecf20Sopenharmony_ci	r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
7968c2ecf20Sopenharmony_ci
7978c2ecf20Sopenharmony_ci	if (r)
7988c2ecf20Sopenharmony_ci		pr_err("%s(): could not register clock provider: %d\n",
7998c2ecf20Sopenharmony_ci		       __func__, r);
8008c2ecf20Sopenharmony_ci
8018c2ecf20Sopenharmony_ci	apmixed_base = base;
8028c2ecf20Sopenharmony_ci	/* MPLL, CCIPLL, MAINPLL set HW mode, TDCLKSQ, CLKSQ1 */
8038c2ecf20Sopenharmony_ci	writel(readl(AP_PLL_CON3) & 0xFFFFFFE1, AP_PLL_CON3);
8048c2ecf20Sopenharmony_ci	writel(readl(PLLON_CON0) & 0x01041041, PLLON_CON0);
8058c2ecf20Sopenharmony_ci	writel(readl(PLLON_CON1) & 0x01041041, PLLON_CON1);
8068c2ecf20Sopenharmony_ci
8078c2ecf20Sopenharmony_ci	return r;
8088c2ecf20Sopenharmony_ci}
8098c2ecf20Sopenharmony_ci
8108c2ecf20Sopenharmony_cistatic int clk_mt6765_top_probe(struct platform_device *pdev)
8118c2ecf20Sopenharmony_ci{
8128c2ecf20Sopenharmony_ci	int r;
8138c2ecf20Sopenharmony_ci	struct device_node *node = pdev->dev.of_node;
8148c2ecf20Sopenharmony_ci	void __iomem *base;
8158c2ecf20Sopenharmony_ci	struct clk_onecell_data *clk_data;
8168c2ecf20Sopenharmony_ci	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
8178c2ecf20Sopenharmony_ci
8188c2ecf20Sopenharmony_ci	base = devm_ioremap_resource(&pdev->dev, res);
8198c2ecf20Sopenharmony_ci	if (IS_ERR(base)) {
8208c2ecf20Sopenharmony_ci		pr_err("%s(): ioremap failed\n", __func__);
8218c2ecf20Sopenharmony_ci		return PTR_ERR(base);
8228c2ecf20Sopenharmony_ci	}
8238c2ecf20Sopenharmony_ci
8248c2ecf20Sopenharmony_ci	clk_data = mtk_alloc_clk_data(CLK_TOP_NR_CLK);
8258c2ecf20Sopenharmony_ci	if (!clk_data)
8268c2ecf20Sopenharmony_ci		return -ENOMEM;
8278c2ecf20Sopenharmony_ci
8288c2ecf20Sopenharmony_ci	mtk_clk_register_fixed_clks(fixed_clks, ARRAY_SIZE(fixed_clks),
8298c2ecf20Sopenharmony_ci				    clk_data);
8308c2ecf20Sopenharmony_ci	mtk_clk_register_factors(top_divs, ARRAY_SIZE(top_divs),
8318c2ecf20Sopenharmony_ci				 clk_data);
8328c2ecf20Sopenharmony_ci	mtk_clk_register_muxes(top_muxes, ARRAY_SIZE(top_muxes), node,
8338c2ecf20Sopenharmony_ci			       &mt6765_clk_lock, clk_data);
8348c2ecf20Sopenharmony_ci	mtk_clk_register_gates(node, top_clks, ARRAY_SIZE(top_clks),
8358c2ecf20Sopenharmony_ci			       clk_data);
8368c2ecf20Sopenharmony_ci
8378c2ecf20Sopenharmony_ci	r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
8388c2ecf20Sopenharmony_ci
8398c2ecf20Sopenharmony_ci	if (r)
8408c2ecf20Sopenharmony_ci		pr_err("%s(): could not register clock provider: %d\n",
8418c2ecf20Sopenharmony_ci		       __func__, r);
8428c2ecf20Sopenharmony_ci
8438c2ecf20Sopenharmony_ci	cksys_base = base;
8448c2ecf20Sopenharmony_ci	/* [4]:no need */
8458c2ecf20Sopenharmony_ci	writel(readl(CLK_SCP_CFG_0) | 0x3EF, CLK_SCP_CFG_0);
8468c2ecf20Sopenharmony_ci	/*[1,2,3,8]: no need*/
8478c2ecf20Sopenharmony_ci	writel(readl(CLK_SCP_CFG_1) | 0x1, CLK_SCP_CFG_1);
8488c2ecf20Sopenharmony_ci
8498c2ecf20Sopenharmony_ci	return r;
8508c2ecf20Sopenharmony_ci}
8518c2ecf20Sopenharmony_ci
8528c2ecf20Sopenharmony_cistatic int clk_mt6765_ifr_probe(struct platform_device *pdev)
8538c2ecf20Sopenharmony_ci{
8548c2ecf20Sopenharmony_ci	struct clk_onecell_data *clk_data;
8558c2ecf20Sopenharmony_ci	int r;
8568c2ecf20Sopenharmony_ci	struct device_node *node = pdev->dev.of_node;
8578c2ecf20Sopenharmony_ci	void __iomem *base;
8588c2ecf20Sopenharmony_ci	struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
8598c2ecf20Sopenharmony_ci
8608c2ecf20Sopenharmony_ci	base = devm_ioremap_resource(&pdev->dev, res);
8618c2ecf20Sopenharmony_ci	if (IS_ERR(base)) {
8628c2ecf20Sopenharmony_ci		pr_err("%s(): ioremap failed\n", __func__);
8638c2ecf20Sopenharmony_ci		return PTR_ERR(base);
8648c2ecf20Sopenharmony_ci	}
8658c2ecf20Sopenharmony_ci
8668c2ecf20Sopenharmony_ci	clk_data = mtk_alloc_clk_data(CLK_IFR_NR_CLK);
8678c2ecf20Sopenharmony_ci	if (!clk_data)
8688c2ecf20Sopenharmony_ci		return -ENOMEM;
8698c2ecf20Sopenharmony_ci
8708c2ecf20Sopenharmony_ci	mtk_clk_register_gates(node, ifr_clks, ARRAY_SIZE(ifr_clks),
8718c2ecf20Sopenharmony_ci			       clk_data);
8728c2ecf20Sopenharmony_ci	r = of_clk_add_provider(node, of_clk_src_onecell_get, clk_data);
8738c2ecf20Sopenharmony_ci
8748c2ecf20Sopenharmony_ci	if (r)
8758c2ecf20Sopenharmony_ci		pr_err("%s(): could not register clock provider: %d\n",
8768c2ecf20Sopenharmony_ci		       __func__, r);
8778c2ecf20Sopenharmony_ci
8788c2ecf20Sopenharmony_ci	return r;
8798c2ecf20Sopenharmony_ci}
8808c2ecf20Sopenharmony_ci
8818c2ecf20Sopenharmony_cistatic const struct of_device_id of_match_clk_mt6765[] = {
8828c2ecf20Sopenharmony_ci	{
8838c2ecf20Sopenharmony_ci		.compatible = "mediatek,mt6765-apmixedsys",
8848c2ecf20Sopenharmony_ci		.data = clk_mt6765_apmixed_probe,
8858c2ecf20Sopenharmony_ci	}, {
8868c2ecf20Sopenharmony_ci		.compatible = "mediatek,mt6765-topckgen",
8878c2ecf20Sopenharmony_ci		.data = clk_mt6765_top_probe,
8888c2ecf20Sopenharmony_ci	}, {
8898c2ecf20Sopenharmony_ci		.compatible = "mediatek,mt6765-infracfg",
8908c2ecf20Sopenharmony_ci		.data = clk_mt6765_ifr_probe,
8918c2ecf20Sopenharmony_ci	}, {
8928c2ecf20Sopenharmony_ci		/* sentinel */
8938c2ecf20Sopenharmony_ci	}
8948c2ecf20Sopenharmony_ci};
8958c2ecf20Sopenharmony_ci
8968c2ecf20Sopenharmony_cistatic int clk_mt6765_probe(struct platform_device *pdev)
8978c2ecf20Sopenharmony_ci{
8988c2ecf20Sopenharmony_ci	int (*clk_probe)(struct platform_device *d);
8998c2ecf20Sopenharmony_ci	int r;
9008c2ecf20Sopenharmony_ci
9018c2ecf20Sopenharmony_ci	clk_probe = of_device_get_match_data(&pdev->dev);
9028c2ecf20Sopenharmony_ci	if (!clk_probe)
9038c2ecf20Sopenharmony_ci		return -EINVAL;
9048c2ecf20Sopenharmony_ci
9058c2ecf20Sopenharmony_ci	r = clk_probe(pdev);
9068c2ecf20Sopenharmony_ci	if (r)
9078c2ecf20Sopenharmony_ci		dev_err(&pdev->dev,
9088c2ecf20Sopenharmony_ci			"could not register clock provider: %s: %d\n",
9098c2ecf20Sopenharmony_ci			pdev->name, r);
9108c2ecf20Sopenharmony_ci
9118c2ecf20Sopenharmony_ci	return r;
9128c2ecf20Sopenharmony_ci}
9138c2ecf20Sopenharmony_ci
9148c2ecf20Sopenharmony_cistatic struct platform_driver clk_mt6765_drv = {
9158c2ecf20Sopenharmony_ci	.probe = clk_mt6765_probe,
9168c2ecf20Sopenharmony_ci	.driver = {
9178c2ecf20Sopenharmony_ci		.name = "clk-mt6765",
9188c2ecf20Sopenharmony_ci		.of_match_table = of_match_clk_mt6765,
9198c2ecf20Sopenharmony_ci	},
9208c2ecf20Sopenharmony_ci};
9218c2ecf20Sopenharmony_ci
9228c2ecf20Sopenharmony_cistatic int __init clk_mt6765_init(void)
9238c2ecf20Sopenharmony_ci{
9248c2ecf20Sopenharmony_ci	return platform_driver_register(&clk_mt6765_drv);
9258c2ecf20Sopenharmony_ci}
9268c2ecf20Sopenharmony_ci
9278c2ecf20Sopenharmony_ciarch_initcall(clk_mt6765_init);
928