18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2014 MundoReader S.L.
48c2ecf20Sopenharmony_ci * Author: Heiko Stuebner <heiko@sntech.de>
58c2ecf20Sopenharmony_ci */
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci#include <linux/clk.h>
88c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
98c2ecf20Sopenharmony_ci#include <linux/io.h>
108c2ecf20Sopenharmony_ci#include <linux/of.h>
118c2ecf20Sopenharmony_ci#include <linux/of_address.h>
128c2ecf20Sopenharmony_ci#include <dt-bindings/clock/rk3188-cru-common.h>
138c2ecf20Sopenharmony_ci#include "clk.h"
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#define RK3066_GRF_SOC_STATUS	0x15c
168c2ecf20Sopenharmony_ci#define RK3188_GRF_SOC_STATUS	0xac
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_cienum rk3188_plls {
198c2ecf20Sopenharmony_ci	apll, cpll, dpll, gpll,
208c2ecf20Sopenharmony_ci};
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cistatic struct rockchip_pll_rate_table rk3188_pll_rates[] = {
238c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(2208000000, 1, 92, 1),
248c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(2184000000, 1, 91, 1),
258c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(2160000000, 1, 90, 1),
268c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(2136000000, 1, 89, 1),
278c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(2112000000, 1, 88, 1),
288c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(2088000000, 1, 87, 1),
298c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(2064000000, 1, 86, 1),
308c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(2040000000, 1, 85, 1),
318c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(2016000000, 1, 84, 1),
328c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1992000000, 1, 83, 1),
338c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1968000000, 1, 82, 1),
348c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1944000000, 1, 81, 1),
358c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1920000000, 1, 80, 1),
368c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1896000000, 1, 79, 1),
378c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1872000000, 1, 78, 1),
388c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1848000000, 1, 77, 1),
398c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1824000000, 1, 76, 1),
408c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1800000000, 1, 75, 1),
418c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1776000000, 1, 74, 1),
428c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1752000000, 1, 73, 1),
438c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1728000000, 1, 72, 1),
448c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1704000000, 1, 71, 1),
458c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1680000000, 1, 70, 1),
468c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1656000000, 1, 69, 1),
478c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1632000000, 1, 68, 1),
488c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1608000000, 1, 67, 1),
498c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1560000000, 1, 65, 1),
508c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1512000000, 1, 63, 1),
518c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1488000000, 1, 62, 1),
528c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1464000000, 1, 61, 1),
538c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1440000000, 1, 60, 1),
548c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1416000000, 1, 59, 1),
558c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1392000000, 1, 58, 1),
568c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1368000000, 1, 57, 1),
578c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1344000000, 1, 56, 1),
588c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1320000000, 1, 55, 1),
598c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1296000000, 1, 54, 1),
608c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1272000000, 1, 53, 1),
618c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1248000000, 1, 52, 1),
628c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1224000000, 1, 51, 1),
638c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1200000000, 1, 50, 1),
648c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1188000000, 2, 99, 1),
658c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1176000000, 1, 49, 1),
668c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1128000000, 1, 47, 1),
678c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1104000000, 1, 46, 1),
688c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(1008000000, 1, 84, 2),
698c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 912000000, 1, 76, 2),
708c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 891000000, 8, 594, 2),
718c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 888000000, 1, 74, 2),
728c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 816000000, 1, 68, 2),
738c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 798000000, 2, 133, 2),
748c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 792000000, 1, 66, 2),
758c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 768000000, 1, 64, 2),
768c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 742500000, 8, 495, 2),
778c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 696000000, 1, 58, 2),
788c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 600000000, 1, 50, 2),
798c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 594000000, 2, 198, 4),
808c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 552000000, 1, 46, 2),
818c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 504000000, 1, 84, 4),
828c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 456000000, 1, 76, 4),
838c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 408000000, 1, 68, 4),
848c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 400000000, 3, 100, 2),
858c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 384000000, 2, 128, 4),
868c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 360000000, 1, 60, 4),
878c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 312000000, 1, 52, 4),
888c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 300000000, 1, 50, 4),
898c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 297000000, 2, 198, 8),
908c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 252000000, 1, 84, 8),
918c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 216000000, 1, 72, 8),
928c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 148500000, 2, 99, 8),
938c2ecf20Sopenharmony_ci	RK3066_PLL_RATE( 126000000, 1, 84, 16),
948c2ecf20Sopenharmony_ci	RK3066_PLL_RATE(  48000000, 1, 64, 32),
958c2ecf20Sopenharmony_ci	{ /* sentinel */ },
968c2ecf20Sopenharmony_ci};
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci#define RK3066_DIV_CORE_PERIPH_MASK	0x3
998c2ecf20Sopenharmony_ci#define RK3066_DIV_CORE_PERIPH_SHIFT	6
1008c2ecf20Sopenharmony_ci#define RK3066_DIV_ACLK_CORE_MASK	0x7
1018c2ecf20Sopenharmony_ci#define RK3066_DIV_ACLK_CORE_SHIFT	0
1028c2ecf20Sopenharmony_ci#define RK3066_DIV_ACLK_HCLK_MASK	0x3
1038c2ecf20Sopenharmony_ci#define RK3066_DIV_ACLK_HCLK_SHIFT	8
1048c2ecf20Sopenharmony_ci#define RK3066_DIV_ACLK_PCLK_MASK	0x3
1058c2ecf20Sopenharmony_ci#define RK3066_DIV_ACLK_PCLK_SHIFT	12
1068c2ecf20Sopenharmony_ci#define RK3066_DIV_AHB2APB_MASK		0x3
1078c2ecf20Sopenharmony_ci#define RK3066_DIV_AHB2APB_SHIFT	14
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ci#define RK3066_CLKSEL0(_core_peri)					\
1108c2ecf20Sopenharmony_ci	{								\
1118c2ecf20Sopenharmony_ci		.reg = RK2928_CLKSEL_CON(0),				\
1128c2ecf20Sopenharmony_ci		.val = HIWORD_UPDATE(_core_peri, RK3066_DIV_CORE_PERIPH_MASK, \
1138c2ecf20Sopenharmony_ci				RK3066_DIV_CORE_PERIPH_SHIFT)		\
1148c2ecf20Sopenharmony_ci	}
1158c2ecf20Sopenharmony_ci#define RK3066_CLKSEL1(_aclk_core, _aclk_hclk, _aclk_pclk, _ahb2apb)	\
1168c2ecf20Sopenharmony_ci	{								\
1178c2ecf20Sopenharmony_ci		.reg = RK2928_CLKSEL_CON(1),				\
1188c2ecf20Sopenharmony_ci		.val = HIWORD_UPDATE(_aclk_core, RK3066_DIV_ACLK_CORE_MASK, \
1198c2ecf20Sopenharmony_ci				RK3066_DIV_ACLK_CORE_SHIFT) |		\
1208c2ecf20Sopenharmony_ci		       HIWORD_UPDATE(_aclk_hclk, RK3066_DIV_ACLK_HCLK_MASK, \
1218c2ecf20Sopenharmony_ci				RK3066_DIV_ACLK_HCLK_SHIFT) |		\
1228c2ecf20Sopenharmony_ci		       HIWORD_UPDATE(_aclk_pclk, RK3066_DIV_ACLK_PCLK_MASK, \
1238c2ecf20Sopenharmony_ci				RK3066_DIV_ACLK_PCLK_SHIFT) |		\
1248c2ecf20Sopenharmony_ci		       HIWORD_UPDATE(_ahb2apb, RK3066_DIV_AHB2APB_MASK,	\
1258c2ecf20Sopenharmony_ci				RK3066_DIV_AHB2APB_SHIFT),		\
1268c2ecf20Sopenharmony_ci	}
1278c2ecf20Sopenharmony_ci
1288c2ecf20Sopenharmony_ci#define RK3066_CPUCLK_RATE(_prate, _core_peri, _acore, _ahclk, _apclk, _h2p) \
1298c2ecf20Sopenharmony_ci	{								\
1308c2ecf20Sopenharmony_ci		.prate = _prate,					\
1318c2ecf20Sopenharmony_ci		.divs = {						\
1328c2ecf20Sopenharmony_ci			RK3066_CLKSEL0(_core_peri),			\
1338c2ecf20Sopenharmony_ci			RK3066_CLKSEL1(_acore, _ahclk, _apclk, _h2p),	\
1348c2ecf20Sopenharmony_ci		},							\
1358c2ecf20Sopenharmony_ci	}
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_cistatic struct rockchip_cpuclk_rate_table rk3066_cpuclk_rates[] __initdata = {
1388c2ecf20Sopenharmony_ci	RK3066_CPUCLK_RATE(1416000000, 2, 3, 1, 2, 1),
1398c2ecf20Sopenharmony_ci	RK3066_CPUCLK_RATE(1200000000, 2, 3, 1, 2, 1),
1408c2ecf20Sopenharmony_ci	RK3066_CPUCLK_RATE(1008000000, 2, 2, 1, 2, 1),
1418c2ecf20Sopenharmony_ci	RK3066_CPUCLK_RATE( 816000000, 2, 2, 1, 2, 1),
1428c2ecf20Sopenharmony_ci	RK3066_CPUCLK_RATE( 600000000, 1, 2, 1, 2, 1),
1438c2ecf20Sopenharmony_ci	RK3066_CPUCLK_RATE( 504000000, 1, 1, 1, 2, 1),
1448c2ecf20Sopenharmony_ci	RK3066_CPUCLK_RATE( 312000000, 0, 1, 1, 1, 0),
1458c2ecf20Sopenharmony_ci};
1468c2ecf20Sopenharmony_ci
1478c2ecf20Sopenharmony_cistatic const struct rockchip_cpuclk_reg_data rk3066_cpuclk_data = {
1488c2ecf20Sopenharmony_ci	.core_reg = RK2928_CLKSEL_CON(0),
1498c2ecf20Sopenharmony_ci	.div_core_shift = 0,
1508c2ecf20Sopenharmony_ci	.div_core_mask = 0x1f,
1518c2ecf20Sopenharmony_ci	.mux_core_alt = 1,
1528c2ecf20Sopenharmony_ci	.mux_core_main = 0,
1538c2ecf20Sopenharmony_ci	.mux_core_shift = 8,
1548c2ecf20Sopenharmony_ci	.mux_core_mask = 0x1,
1558c2ecf20Sopenharmony_ci};
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ci#define RK3188_DIV_ACLK_CORE_MASK	0x7
1588c2ecf20Sopenharmony_ci#define RK3188_DIV_ACLK_CORE_SHIFT	3
1598c2ecf20Sopenharmony_ci
1608c2ecf20Sopenharmony_ci#define RK3188_CLKSEL1(_aclk_core)		\
1618c2ecf20Sopenharmony_ci	{					\
1628c2ecf20Sopenharmony_ci		.reg = RK2928_CLKSEL_CON(1),	\
1638c2ecf20Sopenharmony_ci		.val = HIWORD_UPDATE(_aclk_core, RK3188_DIV_ACLK_CORE_MASK,\
1648c2ecf20Sopenharmony_ci				 RK3188_DIV_ACLK_CORE_SHIFT) \
1658c2ecf20Sopenharmony_ci	}
1668c2ecf20Sopenharmony_ci#define RK3188_CPUCLK_RATE(_prate, _core_peri, _aclk_core)	\
1678c2ecf20Sopenharmony_ci	{							\
1688c2ecf20Sopenharmony_ci		.prate = _prate,				\
1698c2ecf20Sopenharmony_ci		.divs = {					\
1708c2ecf20Sopenharmony_ci			RK3066_CLKSEL0(_core_peri),		\
1718c2ecf20Sopenharmony_ci			RK3188_CLKSEL1(_aclk_core),		\
1728c2ecf20Sopenharmony_ci		},						\
1738c2ecf20Sopenharmony_ci	}
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_cistatic struct rockchip_cpuclk_rate_table rk3188_cpuclk_rates[] __initdata = {
1768c2ecf20Sopenharmony_ci	RK3188_CPUCLK_RATE(1608000000, 2, 3),
1778c2ecf20Sopenharmony_ci	RK3188_CPUCLK_RATE(1416000000, 2, 3),
1788c2ecf20Sopenharmony_ci	RK3188_CPUCLK_RATE(1200000000, 2, 3),
1798c2ecf20Sopenharmony_ci	RK3188_CPUCLK_RATE(1008000000, 2, 3),
1808c2ecf20Sopenharmony_ci	RK3188_CPUCLK_RATE( 816000000, 2, 3),
1818c2ecf20Sopenharmony_ci	RK3188_CPUCLK_RATE( 600000000, 1, 3),
1828c2ecf20Sopenharmony_ci	RK3188_CPUCLK_RATE( 504000000, 1, 3),
1838c2ecf20Sopenharmony_ci	RK3188_CPUCLK_RATE( 312000000, 0, 1),
1848c2ecf20Sopenharmony_ci};
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_cistatic const struct rockchip_cpuclk_reg_data rk3188_cpuclk_data = {
1878c2ecf20Sopenharmony_ci	.core_reg = RK2928_CLKSEL_CON(0),
1888c2ecf20Sopenharmony_ci	.div_core_shift = 9,
1898c2ecf20Sopenharmony_ci	.div_core_mask = 0x1f,
1908c2ecf20Sopenharmony_ci	.mux_core_alt = 1,
1918c2ecf20Sopenharmony_ci	.mux_core_main = 0,
1928c2ecf20Sopenharmony_ci	.mux_core_shift = 8,
1938c2ecf20Sopenharmony_ci	.mux_core_mask = 0x1,
1948c2ecf20Sopenharmony_ci};
1958c2ecf20Sopenharmony_ci
1968c2ecf20Sopenharmony_ciPNAME(mux_pll_p)		= { "xin24m", "xin32k" };
1978c2ecf20Sopenharmony_ciPNAME(mux_armclk_p)		= { "apll", "gpll_armclk" };
1988c2ecf20Sopenharmony_ciPNAME(mux_ddrphy_p)		= { "dpll", "gpll_ddr" };
1998c2ecf20Sopenharmony_ciPNAME(mux_pll_src_gpll_cpll_p)	= { "gpll", "cpll" };
2008c2ecf20Sopenharmony_ciPNAME(mux_pll_src_cpll_gpll_p)	= { "cpll", "gpll" };
2018c2ecf20Sopenharmony_ciPNAME(mux_aclk_cpu_p)		= { "apll", "gpll" };
2028c2ecf20Sopenharmony_ciPNAME(mux_sclk_cif0_p)		= { "cif0_pre", "xin24m" };
2038c2ecf20Sopenharmony_ciPNAME(mux_sclk_i2s0_p)		= { "i2s0_pre", "i2s0_frac", "xin12m" };
2048c2ecf20Sopenharmony_ciPNAME(mux_sclk_spdif_p)		= { "spdif_pre", "spdif_frac", "xin12m" };
2058c2ecf20Sopenharmony_ciPNAME(mux_sclk_uart0_p)		= { "uart0_pre", "uart0_frac", "xin24m" };
2068c2ecf20Sopenharmony_ciPNAME(mux_sclk_uart1_p)		= { "uart1_pre", "uart1_frac", "xin24m" };
2078c2ecf20Sopenharmony_ciPNAME(mux_sclk_uart2_p)		= { "uart2_pre", "uart2_frac", "xin24m" };
2088c2ecf20Sopenharmony_ciPNAME(mux_sclk_uart3_p)		= { "uart3_pre", "uart3_frac", "xin24m" };
2098c2ecf20Sopenharmony_ciPNAME(mux_sclk_hsadc_p)		= { "hsadc_src", "hsadc_frac", "ext_hsadc" };
2108c2ecf20Sopenharmony_ciPNAME(mux_mac_p)		= { "gpll", "dpll" };
2118c2ecf20Sopenharmony_ciPNAME(mux_sclk_macref_p)	= { "mac_src", "ext_rmii" };
2128c2ecf20Sopenharmony_ci
2138c2ecf20Sopenharmony_cistatic struct rockchip_pll_clock rk3066_pll_clks[] __initdata = {
2148c2ecf20Sopenharmony_ci	[apll] = PLL(pll_rk3066, PLL_APLL, "apll", mux_pll_p, 0, RK2928_PLL_CON(0),
2158c2ecf20Sopenharmony_ci		     RK2928_MODE_CON, 0, 5, 0, rk3188_pll_rates),
2168c2ecf20Sopenharmony_ci	[dpll] = PLL(pll_rk3066, PLL_DPLL, "dpll", mux_pll_p, 0, RK2928_PLL_CON(4),
2178c2ecf20Sopenharmony_ci		     RK2928_MODE_CON, 4, 4, 0, NULL),
2188c2ecf20Sopenharmony_ci	[cpll] = PLL(pll_rk3066, PLL_CPLL, "cpll", mux_pll_p, 0, RK2928_PLL_CON(8),
2198c2ecf20Sopenharmony_ci		     RK2928_MODE_CON, 8, 6, ROCKCHIP_PLL_SYNC_RATE, rk3188_pll_rates),
2208c2ecf20Sopenharmony_ci	[gpll] = PLL(pll_rk3066, PLL_GPLL, "gpll", mux_pll_p, 0, RK2928_PLL_CON(12),
2218c2ecf20Sopenharmony_ci		     RK2928_MODE_CON, 12, 7, ROCKCHIP_PLL_SYNC_RATE, rk3188_pll_rates),
2228c2ecf20Sopenharmony_ci};
2238c2ecf20Sopenharmony_ci
2248c2ecf20Sopenharmony_cistatic struct rockchip_pll_clock rk3188_pll_clks[] __initdata = {
2258c2ecf20Sopenharmony_ci	[apll] = PLL(pll_rk3066, PLL_APLL, "apll", mux_pll_p, 0, RK2928_PLL_CON(0),
2268c2ecf20Sopenharmony_ci		     RK2928_MODE_CON, 0, 6, 0, rk3188_pll_rates),
2278c2ecf20Sopenharmony_ci	[dpll] = PLL(pll_rk3066, PLL_DPLL, "dpll", mux_pll_p, 0, RK2928_PLL_CON(4),
2288c2ecf20Sopenharmony_ci		     RK2928_MODE_CON, 4, 5, 0, NULL),
2298c2ecf20Sopenharmony_ci	[cpll] = PLL(pll_rk3066, PLL_CPLL, "cpll", mux_pll_p, 0, RK2928_PLL_CON(8),
2308c2ecf20Sopenharmony_ci		     RK2928_MODE_CON, 8, 7, ROCKCHIP_PLL_SYNC_RATE, rk3188_pll_rates),
2318c2ecf20Sopenharmony_ci	[gpll] = PLL(pll_rk3066, PLL_GPLL, "gpll", mux_pll_p, 0, RK2928_PLL_CON(12),
2328c2ecf20Sopenharmony_ci		     RK2928_MODE_CON, 12, 8, ROCKCHIP_PLL_SYNC_RATE, rk3188_pll_rates),
2338c2ecf20Sopenharmony_ci};
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_ci#define MFLAGS CLK_MUX_HIWORD_MASK
2368c2ecf20Sopenharmony_ci#define DFLAGS CLK_DIVIDER_HIWORD_MASK
2378c2ecf20Sopenharmony_ci#define GFLAGS (CLK_GATE_HIWORD_MASK | CLK_GATE_SET_TO_DISABLE)
2388c2ecf20Sopenharmony_ci#define IFLAGS ROCKCHIP_INVERTER_HIWORD_MASK
2398c2ecf20Sopenharmony_ci
2408c2ecf20Sopenharmony_ci/* 2 ^ (val + 1) */
2418c2ecf20Sopenharmony_cistatic struct clk_div_table div_core_peri_t[] = {
2428c2ecf20Sopenharmony_ci	{ .val = 0, .div = 2 },
2438c2ecf20Sopenharmony_ci	{ .val = 1, .div = 4 },
2448c2ecf20Sopenharmony_ci	{ .val = 2, .div = 8 },
2458c2ecf20Sopenharmony_ci	{ .val = 3, .div = 16 },
2468c2ecf20Sopenharmony_ci	{ /* sentinel */ },
2478c2ecf20Sopenharmony_ci};
2488c2ecf20Sopenharmony_ci
2498c2ecf20Sopenharmony_cistatic struct rockchip_clk_branch common_hsadc_out_fracmux __initdata =
2508c2ecf20Sopenharmony_ci	MUX(0, "sclk_hsadc_out", mux_sclk_hsadc_p, 0,
2518c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(22), 4, 2, MFLAGS);
2528c2ecf20Sopenharmony_ci
2538c2ecf20Sopenharmony_cistatic struct rockchip_clk_branch common_spdif_fracmux __initdata =
2548c2ecf20Sopenharmony_ci	MUX(SCLK_SPDIF, "sclk_spdif", mux_sclk_spdif_p, CLK_SET_RATE_PARENT,
2558c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(5), 8, 2, MFLAGS);
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_cistatic struct rockchip_clk_branch common_uart0_fracmux __initdata =
2588c2ecf20Sopenharmony_ci	MUX(SCLK_UART0, "sclk_uart0", mux_sclk_uart0_p, 0,
2598c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(13), 8, 2, MFLAGS);
2608c2ecf20Sopenharmony_ci
2618c2ecf20Sopenharmony_cistatic struct rockchip_clk_branch common_uart1_fracmux __initdata =
2628c2ecf20Sopenharmony_ci	MUX(SCLK_UART1, "sclk_uart1", mux_sclk_uart1_p, 0,
2638c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(14), 8, 2, MFLAGS);
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_cistatic struct rockchip_clk_branch common_uart2_fracmux __initdata =
2668c2ecf20Sopenharmony_ci	MUX(SCLK_UART2, "sclk_uart2", mux_sclk_uart2_p, 0,
2678c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(15), 8, 2, MFLAGS);
2688c2ecf20Sopenharmony_ci
2698c2ecf20Sopenharmony_cistatic struct rockchip_clk_branch common_uart3_fracmux __initdata =
2708c2ecf20Sopenharmony_ci	MUX(SCLK_UART3, "sclk_uart3", mux_sclk_uart3_p, 0,
2718c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(16), 8, 2, MFLAGS);
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_cistatic struct rockchip_clk_branch common_clk_branches[] __initdata = {
2748c2ecf20Sopenharmony_ci	/*
2758c2ecf20Sopenharmony_ci	 * Clock-Architecture Diagram 2
2768c2ecf20Sopenharmony_ci	 */
2778c2ecf20Sopenharmony_ci
2788c2ecf20Sopenharmony_ci	GATE(0, "gpll_armclk", "gpll", 0, RK2928_CLKGATE_CON(0), 1, GFLAGS),
2798c2ecf20Sopenharmony_ci
2808c2ecf20Sopenharmony_ci	/* these two are set by the cpuclk and should not be changed */
2818c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX_DIVTBL(CORE_PERI, "core_peri", "armclk", 0,
2828c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(0), 6, 2, DFLAGS | CLK_DIVIDER_READ_ONLY,
2838c2ecf20Sopenharmony_ci			div_core_peri_t, RK2928_CLKGATE_CON(0), 0, GFLAGS),
2848c2ecf20Sopenharmony_ci
2858c2ecf20Sopenharmony_ci	COMPOSITE(ACLK_VEPU, "aclk_vepu", mux_pll_src_cpll_gpll_p, 0,
2868c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(32), 7, 1, MFLAGS, 0, 5, DFLAGS,
2878c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(3), 9, GFLAGS),
2888c2ecf20Sopenharmony_ci	GATE(HCLK_VEPU, "hclk_vepu", "aclk_vepu", 0,
2898c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(3), 10, GFLAGS),
2908c2ecf20Sopenharmony_ci	COMPOSITE(ACLK_VDPU, "aclk_vdpu", mux_pll_src_cpll_gpll_p, 0,
2918c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(32), 15, 1, MFLAGS, 8, 5, DFLAGS,
2928c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(3), 11, GFLAGS),
2938c2ecf20Sopenharmony_ci	GATE(HCLK_VDPU, "hclk_vdpu", "aclk_vdpu", 0,
2948c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(3), 12, GFLAGS),
2958c2ecf20Sopenharmony_ci
2968c2ecf20Sopenharmony_ci	GATE(0, "gpll_ddr", "gpll", CLK_IGNORE_UNUSED,
2978c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(1), 7, GFLAGS),
2988c2ecf20Sopenharmony_ci	COMPOSITE(0, "ddrphy", mux_ddrphy_p, CLK_IGNORE_UNUSED,
2998c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(26), 8, 1, MFLAGS, 0, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO,
3008c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(0), 2, GFLAGS),
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci	GATE(ACLK_CPU, "aclk_cpu", "aclk_cpu_pre", 0,
3038c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(0), 3, GFLAGS),
3048c2ecf20Sopenharmony_ci
3058c2ecf20Sopenharmony_ci	GATE(0, "atclk_cpu", "pclk_cpu_pre", 0,
3068c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(0), 6, GFLAGS),
3078c2ecf20Sopenharmony_ci	GATE(PCLK_CPU, "pclk_cpu", "pclk_cpu_pre", 0,
3088c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(0), 5, GFLAGS),
3098c2ecf20Sopenharmony_ci	GATE(HCLK_CPU, "hclk_cpu", "hclk_cpu_pre", CLK_IGNORE_UNUSED,
3108c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(0), 4, GFLAGS),
3118c2ecf20Sopenharmony_ci
3128c2ecf20Sopenharmony_ci	COMPOSITE(0, "aclk_lcdc0_pre", mux_pll_src_cpll_gpll_p, CLK_IGNORE_UNUSED,
3138c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(31), 7, 1, MFLAGS, 0, 5, DFLAGS,
3148c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(3), 0, GFLAGS),
3158c2ecf20Sopenharmony_ci	COMPOSITE(0, "aclk_lcdc1_pre", mux_pll_src_cpll_gpll_p, 0,
3168c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(31), 15, 1, MFLAGS, 8, 5, DFLAGS,
3178c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(1), 4, GFLAGS),
3188c2ecf20Sopenharmony_ci
3198c2ecf20Sopenharmony_ci	GATE(ACLK_PERI, "aclk_peri", "aclk_peri_pre", 0,
3208c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(2), 1, GFLAGS),
3218c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(HCLK_PERI, "hclk_peri", "aclk_peri_pre", 0,
3228c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(10), 8, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO,
3238c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(2), 2, GFLAGS),
3248c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(PCLK_PERI, "pclk_peri", "aclk_peri_pre", 0,
3258c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(10), 12, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO,
3268c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(2), 3, GFLAGS),
3278c2ecf20Sopenharmony_ci
3288c2ecf20Sopenharmony_ci	MUX(0, "cif_src", mux_pll_src_cpll_gpll_p, 0,
3298c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(29), 0, 1, MFLAGS),
3308c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(0, "cif0_pre", "cif_src", 0,
3318c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(29), 1, 5, DFLAGS,
3328c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(3), 7, GFLAGS),
3338c2ecf20Sopenharmony_ci	MUX(SCLK_CIF0, "sclk_cif0", mux_sclk_cif0_p, 0,
3348c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(29), 7, 1, MFLAGS),
3358c2ecf20Sopenharmony_ci
3368c2ecf20Sopenharmony_ci	GATE(0, "pclkin_cif0", "ext_cif0", 0,
3378c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(3), 3, GFLAGS),
3388c2ecf20Sopenharmony_ci	INVERTER(0, "pclk_cif0", "pclkin_cif0",
3398c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(30), 8, IFLAGS),
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci	FACTOR(0, "xin12m", "xin24m", 0, 1, 2),
3428c2ecf20Sopenharmony_ci
3438c2ecf20Sopenharmony_ci	/*
3448c2ecf20Sopenharmony_ci	 * the 480m are generated inside the usb block from these clocks,
3458c2ecf20Sopenharmony_ci	 * but they are also a source for the hsicphy clock.
3468c2ecf20Sopenharmony_ci	 */
3478c2ecf20Sopenharmony_ci	GATE(SCLK_OTGPHY0, "sclk_otgphy0", "xin24m", CLK_IGNORE_UNUSED,
3488c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(1), 5, GFLAGS),
3498c2ecf20Sopenharmony_ci	GATE(SCLK_OTGPHY1, "sclk_otgphy1", "xin24m", CLK_IGNORE_UNUSED,
3508c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(1), 6, GFLAGS),
3518c2ecf20Sopenharmony_ci
3528c2ecf20Sopenharmony_ci	COMPOSITE(0, "mac_src", mux_mac_p, 0,
3538c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(21), 0, 1, MFLAGS, 8, 5, DFLAGS,
3548c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(2), 5, GFLAGS),
3558c2ecf20Sopenharmony_ci	MUX(SCLK_MAC, "sclk_macref", mux_sclk_macref_p, CLK_SET_RATE_PARENT,
3568c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(21), 4, 1, MFLAGS),
3578c2ecf20Sopenharmony_ci	GATE(0, "sclk_mac_lbtest", "sclk_macref", 0,
3588c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(2), 12, GFLAGS),
3598c2ecf20Sopenharmony_ci
3608c2ecf20Sopenharmony_ci	COMPOSITE(0, "hsadc_src", mux_pll_src_gpll_cpll_p, 0,
3618c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(22), 0, 1, MFLAGS, 8, 8, DFLAGS,
3628c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(2), 6, GFLAGS),
3638c2ecf20Sopenharmony_ci	COMPOSITE_FRACMUX(0, "hsadc_frac", "hsadc_src", 0,
3648c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(23), 0,
3658c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(2), 7, GFLAGS,
3668c2ecf20Sopenharmony_ci			&common_hsadc_out_fracmux),
3678c2ecf20Sopenharmony_ci	INVERTER(SCLK_HSADC, "sclk_hsadc", "sclk_hsadc_out",
3688c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(22), 7, IFLAGS),
3698c2ecf20Sopenharmony_ci
3708c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(SCLK_SARADC, "sclk_saradc", "xin24m", 0,
3718c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(24), 8, 8, DFLAGS,
3728c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(2), 8, GFLAGS),
3738c2ecf20Sopenharmony_ci
3748c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(0, "spdif_pre", "i2s_src", 0,
3758c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(5), 0, 7, DFLAGS,
3768c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(0), 13, GFLAGS),
3778c2ecf20Sopenharmony_ci	COMPOSITE_FRACMUX(0, "spdif_frac", "spdif_pre", CLK_SET_RATE_PARENT,
3788c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(9), 0,
3798c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(0), 14, GFLAGS,
3808c2ecf20Sopenharmony_ci			&common_spdif_fracmux),
3818c2ecf20Sopenharmony_ci
3828c2ecf20Sopenharmony_ci	/*
3838c2ecf20Sopenharmony_ci	 * Clock-Architecture Diagram 4
3848c2ecf20Sopenharmony_ci	 */
3858c2ecf20Sopenharmony_ci
3868c2ecf20Sopenharmony_ci	GATE(SCLK_SMC, "sclk_smc", "hclk_peri", 0,
3878c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(2), 4, GFLAGS),
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(SCLK_SPI0, "sclk_spi0", "pclk_peri", 0,
3908c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(25), 0, 7, DFLAGS,
3918c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(2), 9, GFLAGS),
3928c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(SCLK_SPI1, "sclk_spi1", "pclk_peri", 0,
3938c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(25), 8, 7, DFLAGS,
3948c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(2), 10, GFLAGS),
3958c2ecf20Sopenharmony_ci
3968c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(SCLK_SDMMC, "sclk_sdmmc", "hclk_peri", 0,
3978c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(11), 0, 6, DFLAGS,
3988c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(2), 11, GFLAGS),
3998c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(SCLK_SDIO, "sclk_sdio", "hclk_peri", 0,
4008c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(12), 0, 6, DFLAGS,
4018c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(2), 13, GFLAGS),
4028c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(SCLK_EMMC, "sclk_emmc", "hclk_peri", 0,
4038c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(12), 8, 6, DFLAGS,
4048c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(2), 14, GFLAGS),
4058c2ecf20Sopenharmony_ci
4068c2ecf20Sopenharmony_ci	MUX(0, "uart_src", mux_pll_src_gpll_cpll_p, 0,
4078c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(12), 15, 1, MFLAGS),
4088c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(0, "uart0_pre", "uart_src", 0,
4098c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(13), 0, 7, DFLAGS,
4108c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(1), 8, GFLAGS),
4118c2ecf20Sopenharmony_ci	COMPOSITE_FRACMUX(0, "uart0_frac", "uart0_pre", 0,
4128c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(17), 0,
4138c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(1), 9, GFLAGS,
4148c2ecf20Sopenharmony_ci			&common_uart0_fracmux),
4158c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(0, "uart1_pre", "uart_src", 0,
4168c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(14), 0, 7, DFLAGS,
4178c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(1), 10, GFLAGS),
4188c2ecf20Sopenharmony_ci	COMPOSITE_FRACMUX(0, "uart1_frac", "uart1_pre", 0,
4198c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(18), 0,
4208c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(1), 11, GFLAGS,
4218c2ecf20Sopenharmony_ci			&common_uart1_fracmux),
4228c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(0, "uart2_pre", "uart_src", 0,
4238c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(15), 0, 7, DFLAGS,
4248c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(1), 12, GFLAGS),
4258c2ecf20Sopenharmony_ci	COMPOSITE_FRACMUX(0, "uart2_frac", "uart2_pre", 0,
4268c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(19), 0,
4278c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(1), 13, GFLAGS,
4288c2ecf20Sopenharmony_ci			&common_uart2_fracmux),
4298c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(0, "uart3_pre", "uart_src", 0,
4308c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(16), 0, 7, DFLAGS,
4318c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(1), 14, GFLAGS),
4328c2ecf20Sopenharmony_ci	COMPOSITE_FRACMUX(0, "uart3_frac", "uart3_pre", 0,
4338c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(20), 0,
4348c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(1), 15, GFLAGS,
4358c2ecf20Sopenharmony_ci			&common_uart3_fracmux),
4368c2ecf20Sopenharmony_ci
4378c2ecf20Sopenharmony_ci	GATE(SCLK_JTAG, "jtag", "ext_jtag", 0, RK2928_CLKGATE_CON(1), 3, GFLAGS),
4388c2ecf20Sopenharmony_ci
4398c2ecf20Sopenharmony_ci	GATE(SCLK_TIMER0, "timer0", "xin24m", 0, RK2928_CLKGATE_CON(1), 0, GFLAGS),
4408c2ecf20Sopenharmony_ci	GATE(SCLK_TIMER1, "timer1", "xin24m", 0, RK2928_CLKGATE_CON(1), 1, GFLAGS),
4418c2ecf20Sopenharmony_ci
4428c2ecf20Sopenharmony_ci	/* clk_core_pre gates */
4438c2ecf20Sopenharmony_ci	GATE(0, "core_dbg", "armclk", 0, RK2928_CLKGATE_CON(9), 0, GFLAGS),
4448c2ecf20Sopenharmony_ci
4458c2ecf20Sopenharmony_ci	/* aclk_cpu gates */
4468c2ecf20Sopenharmony_ci	GATE(ACLK_DMA1, "aclk_dma1", "aclk_cpu", 0, RK2928_CLKGATE_CON(5), 0, GFLAGS),
4478c2ecf20Sopenharmony_ci	GATE(0, "aclk_intmem", "aclk_cpu", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 12, GFLAGS),
4488c2ecf20Sopenharmony_ci	GATE(0, "aclk_strc_sys", "aclk_cpu", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 10, GFLAGS),
4498c2ecf20Sopenharmony_ci
4508c2ecf20Sopenharmony_ci	/* hclk_cpu gates */
4518c2ecf20Sopenharmony_ci	GATE(HCLK_ROM, "hclk_rom", "hclk_cpu", 0, RK2928_CLKGATE_CON(5), 6, GFLAGS),
4528c2ecf20Sopenharmony_ci	GATE(HCLK_I2S0, "hclk_i2s0", "hclk_cpu", 0, RK2928_CLKGATE_CON(7), 2, GFLAGS),
4538c2ecf20Sopenharmony_ci	GATE(HCLK_SPDIF, "hclk_spdif", "hclk_cpu", 0, RK2928_CLKGATE_CON(7), 1, GFLAGS),
4548c2ecf20Sopenharmony_ci	GATE(0, "hclk_cpubus", "hclk_cpu", 0, RK2928_CLKGATE_CON(4), 8, GFLAGS),
4558c2ecf20Sopenharmony_ci	/* hclk_ahb2apb is part of a clk branch */
4568c2ecf20Sopenharmony_ci	GATE(0, "hclk_vio_bus", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 12, GFLAGS),
4578c2ecf20Sopenharmony_ci	GATE(HCLK_LCDC0, "hclk_lcdc0", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 1, GFLAGS),
4588c2ecf20Sopenharmony_ci	GATE(HCLK_LCDC1, "hclk_lcdc1", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 2, GFLAGS),
4598c2ecf20Sopenharmony_ci	GATE(HCLK_CIF0, "hclk_cif0", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 4, GFLAGS),
4608c2ecf20Sopenharmony_ci	GATE(HCLK_IPP, "hclk_ipp", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 9, GFLAGS),
4618c2ecf20Sopenharmony_ci	GATE(HCLK_RGA, "hclk_rga", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 10, GFLAGS),
4628c2ecf20Sopenharmony_ci
4638c2ecf20Sopenharmony_ci	/* hclk_peri gates */
4648c2ecf20Sopenharmony_ci	GATE(0, "hclk_peri_axi_matrix", "hclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 0, GFLAGS),
4658c2ecf20Sopenharmony_ci	GATE(0, "hclk_peri_ahb_arbi", "hclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 6, GFLAGS),
4668c2ecf20Sopenharmony_ci	GATE(0, "hclk_emem_peri", "hclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 7, GFLAGS),
4678c2ecf20Sopenharmony_ci	GATE(HCLK_EMAC, "hclk_emac", "hclk_peri", 0, RK2928_CLKGATE_CON(7), 0, GFLAGS),
4688c2ecf20Sopenharmony_ci	GATE(HCLK_NANDC0, "hclk_nandc0", "hclk_peri", 0, RK2928_CLKGATE_CON(5), 9, GFLAGS),
4698c2ecf20Sopenharmony_ci	GATE(0, "hclk_usb_peri", "hclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 5, GFLAGS),
4708c2ecf20Sopenharmony_ci	GATE(HCLK_OTG0, "hclk_usbotg0", "hclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(5), 13, GFLAGS),
4718c2ecf20Sopenharmony_ci	GATE(HCLK_HSADC, "hclk_hsadc", "hclk_peri", 0, RK2928_CLKGATE_CON(7), 5, GFLAGS),
4728c2ecf20Sopenharmony_ci	GATE(HCLK_PIDF, "hclk_pidfilter", "hclk_peri", 0, RK2928_CLKGATE_CON(7), 6, GFLAGS),
4738c2ecf20Sopenharmony_ci	GATE(HCLK_SDMMC, "hclk_sdmmc", "hclk_peri", 0, RK2928_CLKGATE_CON(5), 10, GFLAGS),
4748c2ecf20Sopenharmony_ci	GATE(HCLK_SDIO, "hclk_sdio", "hclk_peri", 0, RK2928_CLKGATE_CON(5), 11, GFLAGS),
4758c2ecf20Sopenharmony_ci	GATE(HCLK_EMMC, "hclk_emmc", "hclk_peri", 0, RK2928_CLKGATE_CON(5), 12, GFLAGS),
4768c2ecf20Sopenharmony_ci
4778c2ecf20Sopenharmony_ci	/* aclk_lcdc0_pre gates */
4788c2ecf20Sopenharmony_ci	GATE(0, "aclk_vio0", "aclk_lcdc0_pre", 0, RK2928_CLKGATE_CON(6), 13, GFLAGS),
4798c2ecf20Sopenharmony_ci	GATE(ACLK_LCDC0, "aclk_lcdc0", "aclk_vio0", 0, RK2928_CLKGATE_CON(6), 0, GFLAGS),
4808c2ecf20Sopenharmony_ci	GATE(ACLK_CIF0, "aclk_cif0", "aclk_vio0", 0, RK2928_CLKGATE_CON(6), 5, GFLAGS),
4818c2ecf20Sopenharmony_ci	GATE(ACLK_IPP, "aclk_ipp", "aclk_vio0", 0, RK2928_CLKGATE_CON(6), 8, GFLAGS),
4828c2ecf20Sopenharmony_ci
4838c2ecf20Sopenharmony_ci	/* aclk_lcdc1_pre gates */
4848c2ecf20Sopenharmony_ci	GATE(0, "aclk_vio1", "aclk_lcdc1_pre", 0, RK2928_CLKGATE_CON(9), 5, GFLAGS),
4858c2ecf20Sopenharmony_ci	GATE(ACLK_LCDC1, "aclk_lcdc1", "aclk_vio1", 0, RK2928_CLKGATE_CON(6), 3, GFLAGS),
4868c2ecf20Sopenharmony_ci	GATE(ACLK_RGA, "aclk_rga", "aclk_vio1", 0, RK2928_CLKGATE_CON(6), 11, GFLAGS),
4878c2ecf20Sopenharmony_ci
4888c2ecf20Sopenharmony_ci	/* atclk_cpu gates */
4898c2ecf20Sopenharmony_ci	GATE(0, "atclk", "atclk_cpu", 0, RK2928_CLKGATE_CON(9), 3, GFLAGS),
4908c2ecf20Sopenharmony_ci	GATE(0, "trace", "atclk_cpu", 0, RK2928_CLKGATE_CON(9), 2, GFLAGS),
4918c2ecf20Sopenharmony_ci
4928c2ecf20Sopenharmony_ci	/* pclk_cpu gates */
4938c2ecf20Sopenharmony_ci	GATE(PCLK_PWM01, "pclk_pwm01", "pclk_cpu", 0, RK2928_CLKGATE_CON(7), 10, GFLAGS),
4948c2ecf20Sopenharmony_ci	GATE(PCLK_TIMER0, "pclk_timer0", "pclk_cpu", 0, RK2928_CLKGATE_CON(7), 7, GFLAGS),
4958c2ecf20Sopenharmony_ci	GATE(PCLK_I2C0, "pclk_i2c0", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 4, GFLAGS),
4968c2ecf20Sopenharmony_ci	GATE(PCLK_I2C1, "pclk_i2c1", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 5, GFLAGS),
4978c2ecf20Sopenharmony_ci	GATE(PCLK_GPIO0, "pclk_gpio0", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 9, GFLAGS),
4988c2ecf20Sopenharmony_ci	GATE(PCLK_GPIO1, "pclk_gpio1", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 10, GFLAGS),
4998c2ecf20Sopenharmony_ci	GATE(PCLK_GPIO2, "pclk_gpio2", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 11, GFLAGS),
5008c2ecf20Sopenharmony_ci	GATE(PCLK_EFUSE, "pclk_efuse", "pclk_cpu", 0, RK2928_CLKGATE_CON(5), 2, GFLAGS),
5018c2ecf20Sopenharmony_ci	GATE(PCLK_TZPC, "pclk_tzpc", "pclk_cpu", 0, RK2928_CLKGATE_CON(5), 3, GFLAGS),
5028c2ecf20Sopenharmony_ci	GATE(PCLK_DDRUPCTL, "pclk_ddrupctl", "pclk_cpu", 0, RK2928_CLKGATE_CON(5), 7, GFLAGS),
5038c2ecf20Sopenharmony_ci	GATE(PCLK_PUBL, "pclk_ddrpubl", "pclk_cpu", 0, RK2928_CLKGATE_CON(9), 6, GFLAGS),
5048c2ecf20Sopenharmony_ci	GATE(0, "pclk_dbg", "pclk_cpu", 0, RK2928_CLKGATE_CON(9), 1, GFLAGS),
5058c2ecf20Sopenharmony_ci	GATE(PCLK_GRF, "pclk_grf", "pclk_cpu", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(5), 4, GFLAGS),
5068c2ecf20Sopenharmony_ci	GATE(PCLK_PMU, "pclk_pmu", "pclk_cpu", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(5), 5, GFLAGS),
5078c2ecf20Sopenharmony_ci
5088c2ecf20Sopenharmony_ci	/* aclk_peri */
5098c2ecf20Sopenharmony_ci	GATE(ACLK_DMA2, "aclk_dma2", "aclk_peri", 0, RK2928_CLKGATE_CON(5), 1, GFLAGS),
5108c2ecf20Sopenharmony_ci	GATE(ACLK_SMC, "aclk_smc", "aclk_peri", 0, RK2928_CLKGATE_CON(5), 8, GFLAGS),
5118c2ecf20Sopenharmony_ci	GATE(0, "aclk_peri_niu", "aclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 4, GFLAGS),
5128c2ecf20Sopenharmony_ci	GATE(0, "aclk_cpu_peri", "aclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 2, GFLAGS),
5138c2ecf20Sopenharmony_ci	GATE(0, "aclk_peri_axi_matrix", "aclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 3, GFLAGS),
5148c2ecf20Sopenharmony_ci
5158c2ecf20Sopenharmony_ci	/* pclk_peri gates */
5168c2ecf20Sopenharmony_ci	GATE(0, "pclk_peri_axi_matrix", "pclk_peri", CLK_IGNORE_UNUSED, RK2928_CLKGATE_CON(4), 1, GFLAGS),
5178c2ecf20Sopenharmony_ci	GATE(PCLK_PWM23, "pclk_pwm23", "pclk_peri", 0, RK2928_CLKGATE_CON(7), 11, GFLAGS),
5188c2ecf20Sopenharmony_ci	GATE(PCLK_WDT, "pclk_wdt", "pclk_peri", 0, RK2928_CLKGATE_CON(7), 15, GFLAGS),
5198c2ecf20Sopenharmony_ci	GATE(PCLK_SPI0, "pclk_spi0", "pclk_peri", 0, RK2928_CLKGATE_CON(7), 12, GFLAGS),
5208c2ecf20Sopenharmony_ci	GATE(PCLK_SPI1, "pclk_spi1", "pclk_peri", 0, RK2928_CLKGATE_CON(7), 13, GFLAGS),
5218c2ecf20Sopenharmony_ci	GATE(PCLK_UART2, "pclk_uart2", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 2, GFLAGS),
5228c2ecf20Sopenharmony_ci	GATE(PCLK_UART3, "pclk_uart3", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 3, GFLAGS),
5238c2ecf20Sopenharmony_ci	GATE(PCLK_I2C2, "pclk_i2c2", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 6, GFLAGS),
5248c2ecf20Sopenharmony_ci	GATE(PCLK_I2C3, "pclk_i2c3", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 7, GFLAGS),
5258c2ecf20Sopenharmony_ci	GATE(PCLK_I2C4, "pclk_i2c4", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 8, GFLAGS),
5268c2ecf20Sopenharmony_ci	GATE(PCLK_GPIO3, "pclk_gpio3", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 12, GFLAGS),
5278c2ecf20Sopenharmony_ci	GATE(PCLK_SARADC, "pclk_saradc", "pclk_peri", 0, RK2928_CLKGATE_CON(7), 14, GFLAGS),
5288c2ecf20Sopenharmony_ci};
5298c2ecf20Sopenharmony_ci
5308c2ecf20Sopenharmony_ciPNAME(mux_rk3066_lcdc0_p)	= { "dclk_lcdc0_src", "xin27m" };
5318c2ecf20Sopenharmony_ciPNAME(mux_rk3066_lcdc1_p)	= { "dclk_lcdc1_src", "xin27m" };
5328c2ecf20Sopenharmony_ciPNAME(mux_sclk_cif1_p)		= { "cif1_pre", "xin24m" };
5338c2ecf20Sopenharmony_ciPNAME(mux_sclk_i2s1_p)		= { "i2s1_pre", "i2s1_frac", "xin12m" };
5348c2ecf20Sopenharmony_ciPNAME(mux_sclk_i2s2_p)		= { "i2s2_pre", "i2s2_frac", "xin12m" };
5358c2ecf20Sopenharmony_ci
5368c2ecf20Sopenharmony_cistatic struct clk_div_table div_aclk_cpu_t[] = {
5378c2ecf20Sopenharmony_ci	{ .val = 0, .div = 1 },
5388c2ecf20Sopenharmony_ci	{ .val = 1, .div = 2 },
5398c2ecf20Sopenharmony_ci	{ .val = 2, .div = 3 },
5408c2ecf20Sopenharmony_ci	{ .val = 3, .div = 4 },
5418c2ecf20Sopenharmony_ci	{ .val = 4, .div = 8 },
5428c2ecf20Sopenharmony_ci	{ /* sentinel */ },
5438c2ecf20Sopenharmony_ci};
5448c2ecf20Sopenharmony_ci
5458c2ecf20Sopenharmony_cistatic struct rockchip_clk_branch rk3066a_i2s0_fracmux __initdata =
5468c2ecf20Sopenharmony_ci	MUX(SCLK_I2S0, "sclk_i2s0", mux_sclk_i2s0_p, 0,
5478c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(2), 8, 2, MFLAGS);
5488c2ecf20Sopenharmony_ci
5498c2ecf20Sopenharmony_cistatic struct rockchip_clk_branch rk3066a_i2s1_fracmux __initdata =
5508c2ecf20Sopenharmony_ci	MUX(SCLK_I2S1, "sclk_i2s1", mux_sclk_i2s1_p, 0,
5518c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(3), 8, 2, MFLAGS);
5528c2ecf20Sopenharmony_ci
5538c2ecf20Sopenharmony_cistatic struct rockchip_clk_branch rk3066a_i2s2_fracmux __initdata =
5548c2ecf20Sopenharmony_ci	MUX(SCLK_I2S2, "sclk_i2s2", mux_sclk_i2s2_p, 0,
5558c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(4), 8, 2, MFLAGS);
5568c2ecf20Sopenharmony_ci
5578c2ecf20Sopenharmony_cistatic struct rockchip_clk_branch rk3066a_clk_branches[] __initdata = {
5588c2ecf20Sopenharmony_ci	DIVTBL(0, "aclk_cpu_pre", "armclk", 0,
5598c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(1), 0, 3, DFLAGS | CLK_DIVIDER_READ_ONLY, div_aclk_cpu_t),
5608c2ecf20Sopenharmony_ci	DIV(0, "pclk_cpu_pre", "aclk_cpu_pre", 0,
5618c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(1), 12, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO
5628c2ecf20Sopenharmony_ci							    | CLK_DIVIDER_READ_ONLY),
5638c2ecf20Sopenharmony_ci	DIV(0, "hclk_cpu_pre", "aclk_cpu_pre", 0,
5648c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(1), 8, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO
5658c2ecf20Sopenharmony_ci							   | CLK_DIVIDER_READ_ONLY),
5668c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(0, "hclk_ahb2apb", "hclk_cpu_pre", 0,
5678c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(1), 14, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO
5688c2ecf20Sopenharmony_ci							    | CLK_DIVIDER_READ_ONLY,
5698c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(4), 9, GFLAGS),
5708c2ecf20Sopenharmony_ci
5718c2ecf20Sopenharmony_ci	GATE(CORE_L2C, "core_l2c", "aclk_cpu", CLK_IGNORE_UNUSED,
5728c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(9), 4, GFLAGS),
5738c2ecf20Sopenharmony_ci
5748c2ecf20Sopenharmony_ci	COMPOSITE(0, "aclk_peri_pre", mux_pll_src_gpll_cpll_p, 0,
5758c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(10), 15, 1, MFLAGS, 0, 5, DFLAGS,
5768c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(2), 0, GFLAGS),
5778c2ecf20Sopenharmony_ci
5788c2ecf20Sopenharmony_ci	COMPOSITE(0, "dclk_lcdc0_src", mux_pll_src_cpll_gpll_p, 0,
5798c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(27), 0, 1, MFLAGS, 8, 8, DFLAGS,
5808c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(3), 1, GFLAGS),
5818c2ecf20Sopenharmony_ci	MUX(DCLK_LCDC0, "dclk_lcdc0", mux_rk3066_lcdc0_p, CLK_SET_RATE_PARENT,
5828c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(27), 4, 1, MFLAGS),
5838c2ecf20Sopenharmony_ci	COMPOSITE(0, "dclk_lcdc1_src", mux_pll_src_cpll_gpll_p, 0,
5848c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(28), 0, 1, MFLAGS, 8, 8, DFLAGS,
5858c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(3), 2, GFLAGS),
5868c2ecf20Sopenharmony_ci	MUX(DCLK_LCDC1, "dclk_lcdc1", mux_rk3066_lcdc1_p, CLK_SET_RATE_PARENT,
5878c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(28), 4, 1, MFLAGS),
5888c2ecf20Sopenharmony_ci
5898c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(0, "cif1_pre", "cif_src", 0,
5908c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(29), 8, 5, DFLAGS,
5918c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(3), 8, GFLAGS),
5928c2ecf20Sopenharmony_ci	MUX(SCLK_CIF1, "sclk_cif1", mux_sclk_cif1_p, 0,
5938c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(29), 15, 1, MFLAGS),
5948c2ecf20Sopenharmony_ci
5958c2ecf20Sopenharmony_ci	GATE(0, "pclkin_cif1", "ext_cif1", 0,
5968c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(3), 4, GFLAGS),
5978c2ecf20Sopenharmony_ci	INVERTER(0, "pclk_cif1", "pclkin_cif1",
5988c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(30), 12, IFLAGS),
5998c2ecf20Sopenharmony_ci
6008c2ecf20Sopenharmony_ci	COMPOSITE(0, "aclk_gpu_src", mux_pll_src_cpll_gpll_p, 0,
6018c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(33), 8, 1, MFLAGS, 0, 5, DFLAGS,
6028c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(3), 13, GFLAGS),
6038c2ecf20Sopenharmony_ci	GATE(ACLK_GPU, "aclk_gpu", "aclk_gpu_src", 0,
6048c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(5), 15, GFLAGS),
6058c2ecf20Sopenharmony_ci
6068c2ecf20Sopenharmony_ci	GATE(SCLK_TIMER2, "timer2", "xin24m", 0,
6078c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(3), 2, GFLAGS),
6088c2ecf20Sopenharmony_ci
6098c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(SCLK_TSADC, "sclk_tsadc", "xin24m", 0,
6108c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(34), 0, 16, DFLAGS,
6118c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(2), 15, GFLAGS),
6128c2ecf20Sopenharmony_ci
6138c2ecf20Sopenharmony_ci	MUX(0, "i2s_src", mux_pll_src_gpll_cpll_p, 0,
6148c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(2), 15, 1, MFLAGS),
6158c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(0, "i2s0_pre", "i2s_src", 0,
6168c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(2), 0, 7, DFLAGS,
6178c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(0), 7, GFLAGS),
6188c2ecf20Sopenharmony_ci	COMPOSITE_FRACMUX(0, "i2s0_frac", "i2s0_pre", 0,
6198c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(6), 0,
6208c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(0), 8, GFLAGS,
6218c2ecf20Sopenharmony_ci			&rk3066a_i2s0_fracmux),
6228c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(0, "i2s1_pre", "i2s_src", 0,
6238c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(3), 0, 7, DFLAGS,
6248c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(0), 9, GFLAGS),
6258c2ecf20Sopenharmony_ci	COMPOSITE_FRACMUX(0, "i2s1_frac", "i2s1_pre", 0,
6268c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(7), 0,
6278c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(0), 10, GFLAGS,
6288c2ecf20Sopenharmony_ci			&rk3066a_i2s1_fracmux),
6298c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(0, "i2s2_pre", "i2s_src", 0,
6308c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(4), 0, 7, DFLAGS,
6318c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(0), 11, GFLAGS),
6328c2ecf20Sopenharmony_ci	COMPOSITE_FRACMUX(0, "i2s2_frac", "i2s2_pre", 0,
6338c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(8), 0,
6348c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(0), 12, GFLAGS,
6358c2ecf20Sopenharmony_ci			&rk3066a_i2s2_fracmux),
6368c2ecf20Sopenharmony_ci
6378c2ecf20Sopenharmony_ci	GATE(HCLK_I2S1, "hclk_i2s1", "hclk_cpu", 0, RK2928_CLKGATE_CON(7), 3, GFLAGS),
6388c2ecf20Sopenharmony_ci	GATE(HCLK_I2S2, "hclk_i2s2", "hclk_cpu", 0, RK2928_CLKGATE_CON(7), 4, GFLAGS),
6398c2ecf20Sopenharmony_ci	GATE(HCLK_CIF1, "hclk_cif1", "hclk_cpu", 0, RK2928_CLKGATE_CON(6), 6, GFLAGS),
6408c2ecf20Sopenharmony_ci	GATE(HCLK_HDMI, "hclk_hdmi", "hclk_cpu", 0, RK2928_CLKGATE_CON(4), 14, GFLAGS),
6418c2ecf20Sopenharmony_ci
6428c2ecf20Sopenharmony_ci	GATE(HCLK_OTG1, "hclk_usbotg1", "hclk_peri", CLK_IGNORE_UNUSED,
6438c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(5), 14, GFLAGS),
6448c2ecf20Sopenharmony_ci
6458c2ecf20Sopenharmony_ci	GATE(ACLK_CIF1, "aclk_cif1", "aclk_vio1", 0, RK2928_CLKGATE_CON(6), 7, GFLAGS),
6468c2ecf20Sopenharmony_ci
6478c2ecf20Sopenharmony_ci	GATE(PCLK_TIMER1, "pclk_timer1", "pclk_cpu", 0, RK2928_CLKGATE_CON(7), 8, GFLAGS),
6488c2ecf20Sopenharmony_ci	GATE(PCLK_TIMER2, "pclk_timer2", "pclk_cpu", 0, RK2928_CLKGATE_CON(7), 9, GFLAGS),
6498c2ecf20Sopenharmony_ci	GATE(PCLK_GPIO6, "pclk_gpio6", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 15, GFLAGS),
6508c2ecf20Sopenharmony_ci	GATE(PCLK_UART0, "pclk_uart0", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 0, GFLAGS),
6518c2ecf20Sopenharmony_ci	GATE(PCLK_UART1, "pclk_uart1", "pclk_cpu", 0, RK2928_CLKGATE_CON(8), 1, GFLAGS),
6528c2ecf20Sopenharmony_ci
6538c2ecf20Sopenharmony_ci	GATE(PCLK_GPIO4, "pclk_gpio4", "pclk_peri", 0, RK2928_CLKGATE_CON(8), 13, GFLAGS),
6548c2ecf20Sopenharmony_ci	GATE(PCLK_TSADC, "pclk_tsadc", "pclk_peri", 0, RK2928_CLKGATE_CON(4), 13, GFLAGS),
6558c2ecf20Sopenharmony_ci};
6568c2ecf20Sopenharmony_ci
6578c2ecf20Sopenharmony_cistatic struct clk_div_table div_rk3188_aclk_core_t[] = {
6588c2ecf20Sopenharmony_ci	{ .val = 0, .div = 1 },
6598c2ecf20Sopenharmony_ci	{ .val = 1, .div = 2 },
6608c2ecf20Sopenharmony_ci	{ .val = 2, .div = 3 },
6618c2ecf20Sopenharmony_ci	{ .val = 3, .div = 4 },
6628c2ecf20Sopenharmony_ci	{ .val = 4, .div = 8 },
6638c2ecf20Sopenharmony_ci	{ /* sentinel */ },
6648c2ecf20Sopenharmony_ci};
6658c2ecf20Sopenharmony_ci
6668c2ecf20Sopenharmony_ciPNAME(mux_hsicphy_p)		= { "sclk_otgphy0_480m", "sclk_otgphy1_480m",
6678c2ecf20Sopenharmony_ci				    "gpll", "cpll" };
6688c2ecf20Sopenharmony_ci
6698c2ecf20Sopenharmony_cistatic struct rockchip_clk_branch rk3188_i2s0_fracmux __initdata =
6708c2ecf20Sopenharmony_ci	MUX(SCLK_I2S0, "sclk_i2s0", mux_sclk_i2s0_p, CLK_SET_RATE_PARENT,
6718c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(3), 8, 2, MFLAGS);
6728c2ecf20Sopenharmony_ci
6738c2ecf20Sopenharmony_cistatic struct rockchip_clk_branch rk3188_clk_branches[] __initdata = {
6748c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX_DIVTBL(0, "aclk_core", "armclk", CLK_IGNORE_UNUSED,
6758c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(1), 3, 3, DFLAGS | CLK_DIVIDER_READ_ONLY,
6768c2ecf20Sopenharmony_ci			div_rk3188_aclk_core_t, RK2928_CLKGATE_CON(0), 7, GFLAGS),
6778c2ecf20Sopenharmony_ci
6788c2ecf20Sopenharmony_ci	/* do not source aclk_cpu_pre from the apll, to keep complexity down */
6798c2ecf20Sopenharmony_ci	COMPOSITE_NOGATE(0, "aclk_cpu_pre", mux_aclk_cpu_p, CLK_SET_RATE_NO_REPARENT,
6808c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(0), 5, 1, MFLAGS, 0, 5, DFLAGS),
6818c2ecf20Sopenharmony_ci	DIV(0, "pclk_cpu_pre", "aclk_cpu_pre", 0,
6828c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(1), 12, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO),
6838c2ecf20Sopenharmony_ci	DIV(0, "hclk_cpu_pre", "aclk_cpu_pre", 0,
6848c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(1), 8, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO),
6858c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(0, "hclk_ahb2apb", "hclk_cpu_pre", 0,
6868c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(1), 14, 2, DFLAGS | CLK_DIVIDER_POWER_OF_TWO,
6878c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(4), 9, GFLAGS),
6888c2ecf20Sopenharmony_ci
6898c2ecf20Sopenharmony_ci	GATE(CORE_L2C, "core_l2c", "armclk", CLK_IGNORE_UNUSED,
6908c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(9), 4, GFLAGS),
6918c2ecf20Sopenharmony_ci
6928c2ecf20Sopenharmony_ci	COMPOSITE(0, "aclk_peri_pre", mux_pll_src_cpll_gpll_p, 0,
6938c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(10), 15, 1, MFLAGS, 0, 5, DFLAGS,
6948c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(2), 0, GFLAGS),
6958c2ecf20Sopenharmony_ci
6968c2ecf20Sopenharmony_ci	COMPOSITE(DCLK_LCDC0, "dclk_lcdc0", mux_pll_src_cpll_gpll_p, 0,
6978c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(27), 0, 1, MFLAGS, 8, 8, DFLAGS,
6988c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(3), 1, GFLAGS),
6998c2ecf20Sopenharmony_ci	COMPOSITE(DCLK_LCDC1, "dclk_lcdc1", mux_pll_src_cpll_gpll_p, 0,
7008c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(28), 0, 1, MFLAGS, 8, 8, DFLAGS,
7018c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(3), 2, GFLAGS),
7028c2ecf20Sopenharmony_ci
7038c2ecf20Sopenharmony_ci	COMPOSITE(0, "aclk_gpu_src", mux_pll_src_cpll_gpll_p, 0,
7048c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(34), 7, 1, MFLAGS, 0, 5, DFLAGS,
7058c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(3), 15, GFLAGS),
7068c2ecf20Sopenharmony_ci	GATE(ACLK_GPU, "aclk_gpu", "aclk_gpu_src", 0,
7078c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(9), 7, GFLAGS),
7088c2ecf20Sopenharmony_ci
7098c2ecf20Sopenharmony_ci	GATE(SCLK_TIMER2, "timer2", "xin24m", 0, RK2928_CLKGATE_CON(3), 4, GFLAGS),
7108c2ecf20Sopenharmony_ci	GATE(SCLK_TIMER3, "timer3", "xin24m", 0, RK2928_CLKGATE_CON(1), 2, GFLAGS),
7118c2ecf20Sopenharmony_ci	GATE(SCLK_TIMER4, "timer4", "xin24m", 0, RK2928_CLKGATE_CON(3), 5, GFLAGS),
7128c2ecf20Sopenharmony_ci	GATE(SCLK_TIMER5, "timer5", "xin24m", 0, RK2928_CLKGATE_CON(3), 8, GFLAGS),
7138c2ecf20Sopenharmony_ci	GATE(SCLK_TIMER6, "timer6", "xin24m", 0, RK2928_CLKGATE_CON(3), 14, GFLAGS),
7148c2ecf20Sopenharmony_ci
7158c2ecf20Sopenharmony_ci	COMPOSITE_NODIV(0, "sclk_hsicphy_480m", mux_hsicphy_p, 0,
7168c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(30), 0, 2, DFLAGS,
7178c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(3), 6, GFLAGS),
7188c2ecf20Sopenharmony_ci	DIV(0, "sclk_hsicphy_12m", "sclk_hsicphy_480m", 0,
7198c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(11), 8, 6, DFLAGS),
7208c2ecf20Sopenharmony_ci
7218c2ecf20Sopenharmony_ci	MUX(0, "i2s_src", mux_pll_src_gpll_cpll_p, 0,
7228c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(2), 15, 1, MFLAGS),
7238c2ecf20Sopenharmony_ci	COMPOSITE_NOMUX(0, "i2s0_pre", "i2s_src", 0,
7248c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(3), 0, 7, DFLAGS,
7258c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(0), 9, GFLAGS),
7268c2ecf20Sopenharmony_ci	COMPOSITE_FRACMUX(0, "i2s0_frac", "i2s0_pre", CLK_SET_RATE_PARENT,
7278c2ecf20Sopenharmony_ci			RK2928_CLKSEL_CON(7), 0,
7288c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(0), 10, GFLAGS,
7298c2ecf20Sopenharmony_ci			&rk3188_i2s0_fracmux),
7308c2ecf20Sopenharmony_ci
7318c2ecf20Sopenharmony_ci	GATE(0, "hclk_imem0", "hclk_cpu", 0, RK2928_CLKGATE_CON(4), 14, GFLAGS),
7328c2ecf20Sopenharmony_ci	GATE(0, "hclk_imem1", "hclk_cpu", 0, RK2928_CLKGATE_CON(4), 15, GFLAGS),
7338c2ecf20Sopenharmony_ci
7348c2ecf20Sopenharmony_ci	GATE(HCLK_OTG1, "hclk_usbotg1", "hclk_peri", CLK_IGNORE_UNUSED,
7358c2ecf20Sopenharmony_ci			RK2928_CLKGATE_CON(7), 3, GFLAGS),
7368c2ecf20Sopenharmony_ci	GATE(HCLK_HSIC, "hclk_hsic", "hclk_peri", 0, RK2928_CLKGATE_CON(7), 4, GFLAGS),
7378c2ecf20Sopenharmony_ci
7388c2ecf20Sopenharmony_ci	GATE(PCLK_TIMER3, "pclk_timer3", "pclk_cpu", 0, RK2928_CLKGATE_CON(7), 9, GFLAGS),
7398c2ecf20Sopenharmony_ci
7408c2ecf20Sopenharmony_ci	GATE(PCLK_UART0, "pclk_uart0", "hclk_ahb2apb", 0, RK2928_CLKGATE_CON(8), 0, GFLAGS),
7418c2ecf20Sopenharmony_ci	GATE(PCLK_UART1, "pclk_uart1", "hclk_ahb2apb", 0, RK2928_CLKGATE_CON(8), 1, GFLAGS),
7428c2ecf20Sopenharmony_ci
7438c2ecf20Sopenharmony_ci	GATE(ACLK_GPS, "aclk_gps", "aclk_peri", 0, RK2928_CLKGATE_CON(8), 13, GFLAGS),
7448c2ecf20Sopenharmony_ci};
7458c2ecf20Sopenharmony_ci
7468c2ecf20Sopenharmony_cistatic const char *const rk3188_critical_clocks[] __initconst = {
7478c2ecf20Sopenharmony_ci	"aclk_cpu",
7488c2ecf20Sopenharmony_ci	"aclk_peri",
7498c2ecf20Sopenharmony_ci	"hclk_peri",
7508c2ecf20Sopenharmony_ci	"pclk_cpu",
7518c2ecf20Sopenharmony_ci	"pclk_peri",
7528c2ecf20Sopenharmony_ci	"hclk_cpubus",
7538c2ecf20Sopenharmony_ci	"hclk_vio_bus",
7548c2ecf20Sopenharmony_ci	"sclk_mac_lbtest",
7558c2ecf20Sopenharmony_ci};
7568c2ecf20Sopenharmony_ci
7578c2ecf20Sopenharmony_cistatic struct rockchip_clk_provider *__init rk3188_common_clk_init(struct device_node *np)
7588c2ecf20Sopenharmony_ci{
7598c2ecf20Sopenharmony_ci	struct rockchip_clk_provider *ctx;
7608c2ecf20Sopenharmony_ci	void __iomem *reg_base;
7618c2ecf20Sopenharmony_ci
7628c2ecf20Sopenharmony_ci	reg_base = of_iomap(np, 0);
7638c2ecf20Sopenharmony_ci	if (!reg_base) {
7648c2ecf20Sopenharmony_ci		pr_err("%s: could not map cru region\n", __func__);
7658c2ecf20Sopenharmony_ci		return ERR_PTR(-ENOMEM);
7668c2ecf20Sopenharmony_ci	}
7678c2ecf20Sopenharmony_ci
7688c2ecf20Sopenharmony_ci	ctx = rockchip_clk_init(np, reg_base, CLK_NR_CLKS);
7698c2ecf20Sopenharmony_ci	if (IS_ERR(ctx)) {
7708c2ecf20Sopenharmony_ci		pr_err("%s: rockchip clk init failed\n", __func__);
7718c2ecf20Sopenharmony_ci		iounmap(reg_base);
7728c2ecf20Sopenharmony_ci		return ERR_PTR(-ENOMEM);
7738c2ecf20Sopenharmony_ci	}
7748c2ecf20Sopenharmony_ci
7758c2ecf20Sopenharmony_ci	rockchip_clk_register_branches(ctx, common_clk_branches,
7768c2ecf20Sopenharmony_ci				  ARRAY_SIZE(common_clk_branches));
7778c2ecf20Sopenharmony_ci
7788c2ecf20Sopenharmony_ci	rockchip_register_softrst(np, 9, reg_base + RK2928_SOFTRST_CON(0),
7798c2ecf20Sopenharmony_ci				  ROCKCHIP_SOFTRST_HIWORD_MASK);
7808c2ecf20Sopenharmony_ci
7818c2ecf20Sopenharmony_ci	rockchip_register_restart_notifier(ctx, RK2928_GLB_SRST_FST, NULL);
7828c2ecf20Sopenharmony_ci
7838c2ecf20Sopenharmony_ci	return ctx;
7848c2ecf20Sopenharmony_ci}
7858c2ecf20Sopenharmony_ci
7868c2ecf20Sopenharmony_cistatic void __init rk3066a_clk_init(struct device_node *np)
7878c2ecf20Sopenharmony_ci{
7888c2ecf20Sopenharmony_ci	struct rockchip_clk_provider *ctx;
7898c2ecf20Sopenharmony_ci
7908c2ecf20Sopenharmony_ci	ctx = rk3188_common_clk_init(np);
7918c2ecf20Sopenharmony_ci	if (IS_ERR(ctx))
7928c2ecf20Sopenharmony_ci		return;
7938c2ecf20Sopenharmony_ci
7948c2ecf20Sopenharmony_ci	rockchip_clk_register_plls(ctx, rk3066_pll_clks,
7958c2ecf20Sopenharmony_ci				   ARRAY_SIZE(rk3066_pll_clks),
7968c2ecf20Sopenharmony_ci				   RK3066_GRF_SOC_STATUS);
7978c2ecf20Sopenharmony_ci	rockchip_clk_register_branches(ctx, rk3066a_clk_branches,
7988c2ecf20Sopenharmony_ci				  ARRAY_SIZE(rk3066a_clk_branches));
7998c2ecf20Sopenharmony_ci	rockchip_clk_register_armclk(ctx, ARMCLK, "armclk",
8008c2ecf20Sopenharmony_ci			mux_armclk_p, ARRAY_SIZE(mux_armclk_p),
8018c2ecf20Sopenharmony_ci			&rk3066_cpuclk_data, rk3066_cpuclk_rates,
8028c2ecf20Sopenharmony_ci			ARRAY_SIZE(rk3066_cpuclk_rates));
8038c2ecf20Sopenharmony_ci	rockchip_clk_protect_critical(rk3188_critical_clocks,
8048c2ecf20Sopenharmony_ci				      ARRAY_SIZE(rk3188_critical_clocks));
8058c2ecf20Sopenharmony_ci	rockchip_clk_of_add_provider(np, ctx);
8068c2ecf20Sopenharmony_ci}
8078c2ecf20Sopenharmony_ciCLK_OF_DECLARE(rk3066a_cru, "rockchip,rk3066a-cru", rk3066a_clk_init);
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_cistatic void __init rk3188a_clk_init(struct device_node *np)
8108c2ecf20Sopenharmony_ci{
8118c2ecf20Sopenharmony_ci	struct rockchip_clk_provider *ctx;
8128c2ecf20Sopenharmony_ci	struct clk *clk1, *clk2;
8138c2ecf20Sopenharmony_ci	unsigned long rate;
8148c2ecf20Sopenharmony_ci	int ret;
8158c2ecf20Sopenharmony_ci
8168c2ecf20Sopenharmony_ci	ctx = rk3188_common_clk_init(np);
8178c2ecf20Sopenharmony_ci	if (IS_ERR(ctx))
8188c2ecf20Sopenharmony_ci		return;
8198c2ecf20Sopenharmony_ci
8208c2ecf20Sopenharmony_ci	rockchip_clk_register_plls(ctx, rk3188_pll_clks,
8218c2ecf20Sopenharmony_ci				   ARRAY_SIZE(rk3188_pll_clks),
8228c2ecf20Sopenharmony_ci				   RK3188_GRF_SOC_STATUS);
8238c2ecf20Sopenharmony_ci	rockchip_clk_register_branches(ctx, rk3188_clk_branches,
8248c2ecf20Sopenharmony_ci				  ARRAY_SIZE(rk3188_clk_branches));
8258c2ecf20Sopenharmony_ci	rockchip_clk_register_armclk(ctx, ARMCLK, "armclk",
8268c2ecf20Sopenharmony_ci				  mux_armclk_p, ARRAY_SIZE(mux_armclk_p),
8278c2ecf20Sopenharmony_ci				  &rk3188_cpuclk_data, rk3188_cpuclk_rates,
8288c2ecf20Sopenharmony_ci				  ARRAY_SIZE(rk3188_cpuclk_rates));
8298c2ecf20Sopenharmony_ci
8308c2ecf20Sopenharmony_ci	/* reparent aclk_cpu_pre from apll */
8318c2ecf20Sopenharmony_ci	clk1 = __clk_lookup("aclk_cpu_pre");
8328c2ecf20Sopenharmony_ci	clk2 = __clk_lookup("gpll");
8338c2ecf20Sopenharmony_ci	if (clk1 && clk2) {
8348c2ecf20Sopenharmony_ci		rate = clk_get_rate(clk1);
8358c2ecf20Sopenharmony_ci
8368c2ecf20Sopenharmony_ci		ret = clk_set_parent(clk1, clk2);
8378c2ecf20Sopenharmony_ci		if (ret < 0)
8388c2ecf20Sopenharmony_ci			pr_warn("%s: could not reparent aclk_cpu_pre to gpll\n",
8398c2ecf20Sopenharmony_ci				__func__);
8408c2ecf20Sopenharmony_ci
8418c2ecf20Sopenharmony_ci		clk_set_rate(clk1, rate);
8428c2ecf20Sopenharmony_ci	} else {
8438c2ecf20Sopenharmony_ci		pr_warn("%s: missing clocks to reparent aclk_cpu_pre to gpll\n",
8448c2ecf20Sopenharmony_ci			__func__);
8458c2ecf20Sopenharmony_ci	}
8468c2ecf20Sopenharmony_ci
8478c2ecf20Sopenharmony_ci	rockchip_clk_protect_critical(rk3188_critical_clocks,
8488c2ecf20Sopenharmony_ci				      ARRAY_SIZE(rk3188_critical_clocks));
8498c2ecf20Sopenharmony_ci	rockchip_clk_of_add_provider(np, ctx);
8508c2ecf20Sopenharmony_ci}
8518c2ecf20Sopenharmony_ciCLK_OF_DECLARE(rk3188a_cru, "rockchip,rk3188a-cru", rk3188a_clk_init);
8528c2ecf20Sopenharmony_ci
8538c2ecf20Sopenharmony_cistatic void __init rk3188_clk_init(struct device_node *np)
8548c2ecf20Sopenharmony_ci{
8558c2ecf20Sopenharmony_ci	int i;
8568c2ecf20Sopenharmony_ci
8578c2ecf20Sopenharmony_ci	for (i = 0; i < ARRAY_SIZE(rk3188_pll_clks); i++) {
8588c2ecf20Sopenharmony_ci		struct rockchip_pll_clock *pll = &rk3188_pll_clks[i];
8598c2ecf20Sopenharmony_ci		struct rockchip_pll_rate_table *rate;
8608c2ecf20Sopenharmony_ci
8618c2ecf20Sopenharmony_ci		if (!pll->rate_table)
8628c2ecf20Sopenharmony_ci			continue;
8638c2ecf20Sopenharmony_ci
8648c2ecf20Sopenharmony_ci		rate = pll->rate_table;
8658c2ecf20Sopenharmony_ci		while (rate->rate > 0) {
8668c2ecf20Sopenharmony_ci			rate->nb = 1;
8678c2ecf20Sopenharmony_ci			rate++;
8688c2ecf20Sopenharmony_ci		}
8698c2ecf20Sopenharmony_ci	}
8708c2ecf20Sopenharmony_ci
8718c2ecf20Sopenharmony_ci	rk3188a_clk_init(np);
8728c2ecf20Sopenharmony_ci}
8738c2ecf20Sopenharmony_ciCLK_OF_DECLARE(rk3188_cru, "rockchip,rk3188-cru", rk3188_clk_init);
874