18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Hisilicon Hi6220 clock driver
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (c) 2015 Hisilicon Limited.
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * Author: Bintian Wang <bintian.wang@huawei.com>
88c2ecf20Sopenharmony_ci */
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include <linux/kernel.h>
118c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
128c2ecf20Sopenharmony_ci#include <linux/clkdev.h>
138c2ecf20Sopenharmony_ci#include <linux/io.h>
148c2ecf20Sopenharmony_ci#include <linux/of.h>
158c2ecf20Sopenharmony_ci#include <linux/of_address.h>
168c2ecf20Sopenharmony_ci#include <linux/of_device.h>
178c2ecf20Sopenharmony_ci#include <linux/slab.h>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#include <dt-bindings/clock/hi6220-clock.h>
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_ci#include "clk.h"
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci/* clocks in AO (always on) controller */
258c2ecf20Sopenharmony_cistatic struct hisi_fixed_rate_clock hi6220_fixed_rate_clks[] __initdata = {
268c2ecf20Sopenharmony_ci	{ HI6220_REF32K,	"ref32k",	NULL, 0, 32764,     },
278c2ecf20Sopenharmony_ci	{ HI6220_CLK_TCXO,	"clk_tcxo",	NULL, 0, 19200000,  },
288c2ecf20Sopenharmony_ci	{ HI6220_MMC1_PAD,	"mmc1_pad",	NULL, 0, 100000000, },
298c2ecf20Sopenharmony_ci	{ HI6220_MMC2_PAD,	"mmc2_pad",	NULL, 0, 100000000, },
308c2ecf20Sopenharmony_ci	{ HI6220_MMC0_PAD,	"mmc0_pad",	NULL, 0, 200000000, },
318c2ecf20Sopenharmony_ci	{ HI6220_PLL_BBP,	"bbppll0",	NULL, 0, 245760000, },
328c2ecf20Sopenharmony_ci	{ HI6220_PLL_GPU,	"gpupll",	NULL, 0, 1000000000,},
338c2ecf20Sopenharmony_ci	{ HI6220_PLL1_DDR,	"ddrpll1",	NULL, 0, 1066000000,},
348c2ecf20Sopenharmony_ci	{ HI6220_PLL_SYS,	"syspll",	NULL, 0, 1190400000,},
358c2ecf20Sopenharmony_ci	{ HI6220_PLL_SYS_MEDIA,	"media_syspll",	NULL, 0, 1190400000,},
368c2ecf20Sopenharmony_ci	{ HI6220_DDR_SRC,	"ddr_sel_src",  NULL, 0, 1200000000,},
378c2ecf20Sopenharmony_ci	{ HI6220_PLL_MEDIA,	"media_pll",    NULL, 0, 1440000000,},
388c2ecf20Sopenharmony_ci	{ HI6220_PLL_DDR,	"ddrpll0",      NULL, 0, 1600000000,},
398c2ecf20Sopenharmony_ci};
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_cistatic struct hisi_fixed_factor_clock hi6220_fixed_factor_clks[] __initdata = {
428c2ecf20Sopenharmony_ci	{ HI6220_300M,         "clk_300m",    "syspll",          1, 4, 0, },
438c2ecf20Sopenharmony_ci	{ HI6220_150M,         "clk_150m",    "clk_300m",        1, 2, 0, },
448c2ecf20Sopenharmony_ci	{ HI6220_PICOPHY_SRC,  "picophy_src", "clk_150m",        1, 4, 0, },
458c2ecf20Sopenharmony_ci	{ HI6220_MMC0_SRC_SEL, "mmc0srcsel",  "mmc0_sel",        1, 8, 0, },
468c2ecf20Sopenharmony_ci	{ HI6220_MMC1_SRC_SEL, "mmc1srcsel",  "mmc1_sel",        1, 8, 0, },
478c2ecf20Sopenharmony_ci	{ HI6220_MMC2_SRC_SEL, "mmc2srcsel",  "mmc2_sel",        1, 8, 0, },
488c2ecf20Sopenharmony_ci	{ HI6220_VPU_CODEC,    "vpucodec",    "codec_jpeg_aclk", 1, 2, 0, },
498c2ecf20Sopenharmony_ci	{ HI6220_MMC0_SMP,     "mmc0_sample", "mmc0_sel",        1, 8, 0, },
508c2ecf20Sopenharmony_ci	{ HI6220_MMC1_SMP,     "mmc1_sample", "mmc1_sel",        1, 8, 0, },
518c2ecf20Sopenharmony_ci	{ HI6220_MMC2_SMP,     "mmc2_sample", "mmc2_sel",        1, 8, 0, },
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistatic struct hisi_gate_clock hi6220_separated_gate_clks_ao[] __initdata = {
558c2ecf20Sopenharmony_ci	{ HI6220_WDT0_PCLK,   "wdt0_pclk",   "ref32k",   CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 12, 0, },
568c2ecf20Sopenharmony_ci	{ HI6220_WDT1_PCLK,   "wdt1_pclk",   "ref32k",   CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 13, 0, },
578c2ecf20Sopenharmony_ci	{ HI6220_WDT2_PCLK,   "wdt2_pclk",   "ref32k",   CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 14, 0, },
588c2ecf20Sopenharmony_ci	{ HI6220_TIMER0_PCLK, "timer0_pclk", "clk_tcxo", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 15, 0, },
598c2ecf20Sopenharmony_ci	{ HI6220_TIMER1_PCLK, "timer1_pclk", "clk_tcxo", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 16, 0, },
608c2ecf20Sopenharmony_ci	{ HI6220_TIMER2_PCLK, "timer2_pclk", "clk_tcxo", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 17, 0, },
618c2ecf20Sopenharmony_ci	{ HI6220_TIMER3_PCLK, "timer3_pclk", "clk_tcxo", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 18, 0, },
628c2ecf20Sopenharmony_ci	{ HI6220_TIMER4_PCLK, "timer4_pclk", "clk_tcxo", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 19, 0, },
638c2ecf20Sopenharmony_ci	{ HI6220_TIMER5_PCLK, "timer5_pclk", "clk_tcxo", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 20, 0, },
648c2ecf20Sopenharmony_ci	{ HI6220_TIMER6_PCLK, "timer6_pclk", "clk_tcxo", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 21, 0, },
658c2ecf20Sopenharmony_ci	{ HI6220_TIMER7_PCLK, "timer7_pclk", "clk_tcxo", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 22, 0, },
668c2ecf20Sopenharmony_ci	{ HI6220_TIMER8_PCLK, "timer8_pclk", "clk_tcxo", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 23, 0, },
678c2ecf20Sopenharmony_ci	{ HI6220_UART0_PCLK,  "uart0_pclk",  "clk_tcxo", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 24, 0, },
688c2ecf20Sopenharmony_ci	{ HI6220_RTC0_PCLK,   "rtc0_pclk",   "clk_tcxo", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 25, 0, },
698c2ecf20Sopenharmony_ci	{ HI6220_RTC1_PCLK,   "rtc1_pclk",   "clk_tcxo", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x630, 26, 0, },
708c2ecf20Sopenharmony_ci};
718c2ecf20Sopenharmony_ci
728c2ecf20Sopenharmony_cistatic void __init hi6220_clk_ao_init(struct device_node *np)
738c2ecf20Sopenharmony_ci{
748c2ecf20Sopenharmony_ci	struct hisi_clock_data *clk_data_ao;
758c2ecf20Sopenharmony_ci
768c2ecf20Sopenharmony_ci	clk_data_ao = hisi_clk_init(np, HI6220_AO_NR_CLKS);
778c2ecf20Sopenharmony_ci	if (!clk_data_ao)
788c2ecf20Sopenharmony_ci		return;
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	hisi_clk_register_fixed_rate(hi6220_fixed_rate_clks,
818c2ecf20Sopenharmony_ci				ARRAY_SIZE(hi6220_fixed_rate_clks), clk_data_ao);
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci	hisi_clk_register_fixed_factor(hi6220_fixed_factor_clks,
848c2ecf20Sopenharmony_ci				ARRAY_SIZE(hi6220_fixed_factor_clks), clk_data_ao);
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	hisi_clk_register_gate_sep(hi6220_separated_gate_clks_ao,
878c2ecf20Sopenharmony_ci				ARRAY_SIZE(hi6220_separated_gate_clks_ao), clk_data_ao);
888c2ecf20Sopenharmony_ci}
898c2ecf20Sopenharmony_ci/* Allow reset driver to probe as well */
908c2ecf20Sopenharmony_ciCLK_OF_DECLARE_DRIVER(hi6220_clk_ao, "hisilicon,hi6220-aoctrl", hi6220_clk_ao_init);
918c2ecf20Sopenharmony_ci
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ci/* clocks in sysctrl */
948c2ecf20Sopenharmony_cistatic const char *mmc0_mux0_p[] __initdata = { "pll_ddr_gate", "syspll", };
958c2ecf20Sopenharmony_cistatic const char *mmc0_mux1_p[] __initdata = { "mmc0_mux0", "pll_media_gate", };
968c2ecf20Sopenharmony_cistatic const char *mmc0_src_p[] __initdata = { "mmc0srcsel", "mmc0_div", };
978c2ecf20Sopenharmony_cistatic const char *mmc1_mux0_p[] __initdata = { "pll_ddr_gate", "syspll", };
988c2ecf20Sopenharmony_cistatic const char *mmc1_mux1_p[] __initdata = { "mmc1_mux0", "pll_media_gate", };
998c2ecf20Sopenharmony_cistatic const char *mmc1_src_p[]  __initdata = { "mmc1srcsel", "mmc1_div", };
1008c2ecf20Sopenharmony_cistatic const char *mmc2_mux0_p[] __initdata = { "pll_ddr_gate", "syspll", };
1018c2ecf20Sopenharmony_cistatic const char *mmc2_mux1_p[] __initdata = { "mmc2_mux0", "pll_media_gate", };
1028c2ecf20Sopenharmony_cistatic const char *mmc2_src_p[]  __initdata = { "mmc2srcsel", "mmc2_div", };
1038c2ecf20Sopenharmony_cistatic const char *mmc0_sample_in[] __initdata = { "mmc0_sample", "mmc0_pad", };
1048c2ecf20Sopenharmony_cistatic const char *mmc1_sample_in[] __initdata = { "mmc1_sample", "mmc1_pad", };
1058c2ecf20Sopenharmony_cistatic const char *mmc2_sample_in[] __initdata = { "mmc2_sample", "mmc2_pad", };
1068c2ecf20Sopenharmony_cistatic const char *uart1_src[] __initdata = { "clk_tcxo", "clk_150m", };
1078c2ecf20Sopenharmony_cistatic const char *uart2_src[] __initdata = { "clk_tcxo", "clk_150m", };
1088c2ecf20Sopenharmony_cistatic const char *uart3_src[] __initdata = { "clk_tcxo", "clk_150m", };
1098c2ecf20Sopenharmony_cistatic const char *uart4_src[] __initdata = { "clk_tcxo", "clk_150m", };
1108c2ecf20Sopenharmony_cistatic const char *hifi_src[] __initdata = { "syspll", "pll_media_gate", };
1118c2ecf20Sopenharmony_ci
1128c2ecf20Sopenharmony_cistatic struct hisi_gate_clock hi6220_separated_gate_clks_sys[] __initdata = {
1138c2ecf20Sopenharmony_ci	{ HI6220_MMC0_CLK,      "mmc0_clk",      "mmc0_src",       CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x200, 0,  0, },
1148c2ecf20Sopenharmony_ci	{ HI6220_MMC0_CIUCLK,   "mmc0_ciuclk",   "mmc0_smp_in",    CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x200, 0,  0, },
1158c2ecf20Sopenharmony_ci	{ HI6220_MMC1_CLK,      "mmc1_clk",      "mmc1_src",       CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x200, 1,  0, },
1168c2ecf20Sopenharmony_ci	{ HI6220_MMC1_CIUCLK,   "mmc1_ciuclk",   "mmc1_smp_in",    CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x200, 1,  0, },
1178c2ecf20Sopenharmony_ci	{ HI6220_MMC2_CLK,      "mmc2_clk",      "mmc2_src",       CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x200, 2,  0, },
1188c2ecf20Sopenharmony_ci	{ HI6220_MMC2_CIUCLK,   "mmc2_ciuclk",   "mmc2_smp_in",    CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x200, 2,  0, },
1198c2ecf20Sopenharmony_ci	{ HI6220_USBOTG_HCLK,   "usbotg_hclk",   "clk_bus",        CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x200, 4,  0, },
1208c2ecf20Sopenharmony_ci	{ HI6220_CLK_PICOPHY,   "clk_picophy",   "cs_dapb",        CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x200, 5,  0, },
1218c2ecf20Sopenharmony_ci	{ HI6220_HIFI,          "hifi_clk",      "hifi_div",       CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x210, 0,  0, },
1228c2ecf20Sopenharmony_ci	{ HI6220_DACODEC_PCLK,  "dacodec_pclk",  "clk_bus",        CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x210, 5,  0, },
1238c2ecf20Sopenharmony_ci	{ HI6220_EDMAC_ACLK,    "edmac_aclk",    "clk_bus",        CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x220, 2,  0, },
1248c2ecf20Sopenharmony_ci	{ HI6220_CS_ATB,        "cs_atb",        "cs_atb_div",     CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x230, 0,  0, },
1258c2ecf20Sopenharmony_ci	{ HI6220_I2C0_CLK,      "i2c0_clk",      "clk_150m",       CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x230, 1,  0, },
1268c2ecf20Sopenharmony_ci	{ HI6220_I2C1_CLK,      "i2c1_clk",      "clk_150m",       CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x230, 2,  0, },
1278c2ecf20Sopenharmony_ci	{ HI6220_I2C2_CLK,      "i2c2_clk",      "clk_150m",       CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x230, 3,  0, },
1288c2ecf20Sopenharmony_ci	{ HI6220_I2C3_CLK,      "i2c3_clk",      "clk_150m",       CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x230, 4,  0, },
1298c2ecf20Sopenharmony_ci	{ HI6220_UART1_PCLK,    "uart1_pclk",    "uart1_src",      CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x230, 5,  0, },
1308c2ecf20Sopenharmony_ci	{ HI6220_UART2_PCLK,    "uart2_pclk",    "uart2_src",      CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x230, 6,  0, },
1318c2ecf20Sopenharmony_ci	{ HI6220_UART3_PCLK,    "uart3_pclk",    "uart3_src",      CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x230, 7,  0, },
1328c2ecf20Sopenharmony_ci	{ HI6220_UART4_PCLK,    "uart4_pclk",    "uart4_src",      CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x230, 8,  0, },
1338c2ecf20Sopenharmony_ci	{ HI6220_SPI_CLK,       "spi_clk",       "clk_150m",       CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x230, 9,  0, },
1348c2ecf20Sopenharmony_ci	{ HI6220_TSENSOR_CLK,   "tsensor_clk",   "clk_bus",        CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x230, 12, 0, },
1358c2ecf20Sopenharmony_ci	{ HI6220_DAPB_CLK,      "dapb_clk",      "cs_dapb",        CLK_SET_RATE_PARENT|CLK_IS_CRITICAL,   0x230, 18, 0, },
1368c2ecf20Sopenharmony_ci	{ HI6220_MMU_CLK,       "mmu_clk",       "ddrc_axi1",      CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x240, 11, 0, },
1378c2ecf20Sopenharmony_ci	{ HI6220_HIFI_SEL,      "hifi_sel",      "hifi_src",       CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x270, 0,  0, },
1388c2ecf20Sopenharmony_ci	{ HI6220_MMC0_SYSPLL,   "mmc0_syspll",   "syspll",         CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x270, 1,  0, },
1398c2ecf20Sopenharmony_ci	{ HI6220_MMC1_SYSPLL,   "mmc1_syspll",   "syspll",         CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x270, 2,  0, },
1408c2ecf20Sopenharmony_ci	{ HI6220_MMC2_SYSPLL,   "mmc2_syspll",   "syspll",         CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x270, 3,  0, },
1418c2ecf20Sopenharmony_ci	{ HI6220_MMC0_SEL,      "mmc0_sel",      "mmc0_mux1",      CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x270, 6,  0, },
1428c2ecf20Sopenharmony_ci	{ HI6220_MMC1_SEL,      "mmc1_sel",      "mmc1_mux1",      CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x270, 7,  0, },
1438c2ecf20Sopenharmony_ci	{ HI6220_BBPPLL_SEL,    "bbppll_sel",    "pll0_bbp_gate",  CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x270, 9,  0, },
1448c2ecf20Sopenharmony_ci	{ HI6220_MEDIA_PLL_SRC, "media_pll_src", "pll_media_gate", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x270, 10, 0, },
1458c2ecf20Sopenharmony_ci	{ HI6220_MMC2_SEL,      "mmc2_sel",      "mmc2_mux1",      CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x270, 11, 0, },
1468c2ecf20Sopenharmony_ci	{ HI6220_CS_ATB_SYSPLL, "cs_atb_syspll", "syspll",         CLK_SET_RATE_PARENT|CLK_IS_CRITICAL,   0x270, 12, 0, },
1478c2ecf20Sopenharmony_ci};
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_cistatic struct hisi_mux_clock hi6220_mux_clks_sys[] __initdata = {
1508c2ecf20Sopenharmony_ci	{ HI6220_MMC0_SRC,    "mmc0_src",    mmc0_src_p,     ARRAY_SIZE(mmc0_src_p),     CLK_SET_RATE_PARENT, 0x4,   0,  1, 0, },
1518c2ecf20Sopenharmony_ci	{ HI6220_MMC0_SMP_IN, "mmc0_smp_in", mmc0_sample_in, ARRAY_SIZE(mmc0_sample_in), CLK_SET_RATE_PARENT, 0x4,   0,  1, 0, },
1528c2ecf20Sopenharmony_ci	{ HI6220_MMC1_SRC,    "mmc1_src",    mmc1_src_p,     ARRAY_SIZE(mmc1_src_p),     CLK_SET_RATE_PARENT, 0x4,   2,  1, 0, },
1538c2ecf20Sopenharmony_ci	{ HI6220_MMC1_SMP_IN, "mmc1_smp_in", mmc1_sample_in, ARRAY_SIZE(mmc1_sample_in), CLK_SET_RATE_PARENT, 0x4,   2,  1, 0, },
1548c2ecf20Sopenharmony_ci	{ HI6220_MMC2_SRC,    "mmc2_src",    mmc2_src_p,     ARRAY_SIZE(mmc2_src_p),     CLK_SET_RATE_PARENT, 0x4,   4,  1, 0, },
1558c2ecf20Sopenharmony_ci	{ HI6220_MMC2_SMP_IN, "mmc2_smp_in", mmc2_sample_in, ARRAY_SIZE(mmc2_sample_in), CLK_SET_RATE_PARENT, 0x4,   4,  1, 0, },
1568c2ecf20Sopenharmony_ci	{ HI6220_HIFI_SRC,    "hifi_src",    hifi_src,       ARRAY_SIZE(hifi_src),       CLK_SET_RATE_PARENT, 0x400, 0,  1, CLK_MUX_HIWORD_MASK,},
1578c2ecf20Sopenharmony_ci	{ HI6220_UART1_SRC,   "uart1_src",   uart1_src,      ARRAY_SIZE(uart1_src),      CLK_SET_RATE_PARENT, 0x400, 1,  1, CLK_MUX_HIWORD_MASK,},
1588c2ecf20Sopenharmony_ci	{ HI6220_UART2_SRC,   "uart2_src",   uart2_src,      ARRAY_SIZE(uart2_src),      CLK_SET_RATE_PARENT, 0x400, 2,  1, CLK_MUX_HIWORD_MASK,},
1598c2ecf20Sopenharmony_ci	{ HI6220_UART3_SRC,   "uart3_src",   uart3_src,      ARRAY_SIZE(uart3_src),      CLK_SET_RATE_PARENT, 0x400, 3,  1, CLK_MUX_HIWORD_MASK,},
1608c2ecf20Sopenharmony_ci	{ HI6220_UART4_SRC,   "uart4_src",   uart4_src,      ARRAY_SIZE(uart4_src),      CLK_SET_RATE_PARENT, 0x400, 4,  1, CLK_MUX_HIWORD_MASK,},
1618c2ecf20Sopenharmony_ci	{ HI6220_MMC0_MUX0,   "mmc0_mux0",   mmc0_mux0_p,    ARRAY_SIZE(mmc0_mux0_p),    CLK_SET_RATE_PARENT, 0x400, 5,  1, CLK_MUX_HIWORD_MASK,},
1628c2ecf20Sopenharmony_ci	{ HI6220_MMC1_MUX0,   "mmc1_mux0",   mmc1_mux0_p,    ARRAY_SIZE(mmc1_mux0_p),    CLK_SET_RATE_PARENT, 0x400, 11, 1, CLK_MUX_HIWORD_MASK,},
1638c2ecf20Sopenharmony_ci	{ HI6220_MMC2_MUX0,   "mmc2_mux0",   mmc2_mux0_p,    ARRAY_SIZE(mmc2_mux0_p),    CLK_SET_RATE_PARENT, 0x400, 12, 1, CLK_MUX_HIWORD_MASK,},
1648c2ecf20Sopenharmony_ci	{ HI6220_MMC0_MUX1,   "mmc0_mux1",   mmc0_mux1_p,    ARRAY_SIZE(mmc0_mux1_p),    CLK_SET_RATE_PARENT, 0x400, 13, 1, CLK_MUX_HIWORD_MASK,},
1658c2ecf20Sopenharmony_ci	{ HI6220_MMC1_MUX1,   "mmc1_mux1",   mmc1_mux1_p,    ARRAY_SIZE(mmc1_mux1_p),    CLK_SET_RATE_PARENT, 0x400, 14, 1, CLK_MUX_HIWORD_MASK,},
1668c2ecf20Sopenharmony_ci	{ HI6220_MMC2_MUX1,   "mmc2_mux1",   mmc2_mux1_p,    ARRAY_SIZE(mmc2_mux1_p),    CLK_SET_RATE_PARENT, 0x400, 15, 1, CLK_MUX_HIWORD_MASK,},
1678c2ecf20Sopenharmony_ci};
1688c2ecf20Sopenharmony_ci
1698c2ecf20Sopenharmony_cistatic struct hi6220_divider_clock hi6220_div_clks_sys[] __initdata = {
1708c2ecf20Sopenharmony_ci	{ HI6220_CLK_BUS,     "clk_bus",     "clk_300m",      CLK_SET_RATE_PARENT, 0x490, 0,  4, 7, },
1718c2ecf20Sopenharmony_ci	{ HI6220_MMC0_DIV,    "mmc0_div",    "mmc0_syspll",   CLK_SET_RATE_PARENT, 0x494, 0,  6, 7, },
1728c2ecf20Sopenharmony_ci	{ HI6220_MMC1_DIV,    "mmc1_div",    "mmc1_syspll",   CLK_SET_RATE_PARENT, 0x498, 0,  6, 7, },
1738c2ecf20Sopenharmony_ci	{ HI6220_MMC2_DIV,    "mmc2_div",    "mmc2_syspll",   CLK_SET_RATE_PARENT, 0x49c, 0,  6, 7, },
1748c2ecf20Sopenharmony_ci	{ HI6220_HIFI_DIV,    "hifi_div",    "hifi_sel",      CLK_SET_RATE_PARENT, 0x4a0, 0,  4, 7, },
1758c2ecf20Sopenharmony_ci	{ HI6220_BBPPLL0_DIV, "bbppll0_div", "bbppll_sel",    CLK_SET_RATE_PARENT, 0x4a0, 8,  6, 15,},
1768c2ecf20Sopenharmony_ci	{ HI6220_CS_DAPB,     "cs_dapb",     "picophy_src",   CLK_SET_RATE_PARENT, 0x4a0, 24, 2, 31,},
1778c2ecf20Sopenharmony_ci	{ HI6220_CS_ATB_DIV,  "cs_atb_div",  "cs_atb_syspll", CLK_SET_RATE_PARENT, 0x4a4, 0,  4, 7, },
1788c2ecf20Sopenharmony_ci};
1798c2ecf20Sopenharmony_ci
1808c2ecf20Sopenharmony_cistatic void __init hi6220_clk_sys_init(struct device_node *np)
1818c2ecf20Sopenharmony_ci{
1828c2ecf20Sopenharmony_ci	struct hisi_clock_data *clk_data;
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ci	clk_data = hisi_clk_init(np, HI6220_SYS_NR_CLKS);
1858c2ecf20Sopenharmony_ci	if (!clk_data)
1868c2ecf20Sopenharmony_ci		return;
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci	hisi_clk_register_gate_sep(hi6220_separated_gate_clks_sys,
1898c2ecf20Sopenharmony_ci			ARRAY_SIZE(hi6220_separated_gate_clks_sys), clk_data);
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci	hisi_clk_register_mux(hi6220_mux_clks_sys,
1928c2ecf20Sopenharmony_ci			ARRAY_SIZE(hi6220_mux_clks_sys), clk_data);
1938c2ecf20Sopenharmony_ci
1948c2ecf20Sopenharmony_ci	hi6220_clk_register_divider(hi6220_div_clks_sys,
1958c2ecf20Sopenharmony_ci			ARRAY_SIZE(hi6220_div_clks_sys), clk_data);
1968c2ecf20Sopenharmony_ci}
1978c2ecf20Sopenharmony_ciCLK_OF_DECLARE_DRIVER(hi6220_clk_sys, "hisilicon,hi6220-sysctrl", hi6220_clk_sys_init);
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci
2008c2ecf20Sopenharmony_ci/* clocks in media controller */
2018c2ecf20Sopenharmony_cistatic const char *clk_1000_1200_src[] __initdata = { "pll_gpu_gate", "media_syspll_src", };
2028c2ecf20Sopenharmony_cistatic const char *clk_1440_1200_src[] __initdata = { "media_syspll_src", "media_pll_src", };
2038c2ecf20Sopenharmony_cistatic const char *clk_1000_1440_src[] __initdata = { "pll_gpu_gate", "media_pll_src", };
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_cistatic struct hisi_gate_clock hi6220_separated_gate_clks_media[] __initdata = {
2068c2ecf20Sopenharmony_ci	{ HI6220_DSI_PCLK,       "dsi_pclk",         "vpucodec",      CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x520, 0,  0, },
2078c2ecf20Sopenharmony_ci	{ HI6220_G3D_PCLK,       "g3d_pclk",         "vpucodec",      CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x520, 1,  0, },
2088c2ecf20Sopenharmony_ci	{ HI6220_ACLK_CODEC_VPU, "aclk_codec_vpu",   "ade_core_src",  CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x520, 3,  0, },
2098c2ecf20Sopenharmony_ci	{ HI6220_ISP_SCLK,       "isp_sclk",         "isp_sclk_src",  CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x520, 5,  0, },
2108c2ecf20Sopenharmony_ci	{ HI6220_ADE_CORE,	 "ade_core",	     "ade_core_src",  CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x520, 6,  0, },
2118c2ecf20Sopenharmony_ci	{ HI6220_MED_MMU,        "media_mmu",        "mmu_clk",       CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x520, 8,  0, },
2128c2ecf20Sopenharmony_ci	{ HI6220_CFG_CSI4PHY,    "cfg_csi4phy",      "clk_tcxo",      CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x520, 9,  0, },
2138c2ecf20Sopenharmony_ci	{ HI6220_CFG_CSI2PHY,    "cfg_csi2phy",      "clk_tcxo",      CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x520, 10, 0, },
2148c2ecf20Sopenharmony_ci	{ HI6220_ISP_SCLK_GATE,  "isp_sclk_gate",    "media_pll_src", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x520, 11, 0, },
2158c2ecf20Sopenharmony_ci	{ HI6220_ISP_SCLK_GATE1, "isp_sclk_gate1",   "media_pll_src", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x520, 12, 0, },
2168c2ecf20Sopenharmony_ci	{ HI6220_ADE_CORE_GATE,  "ade_core_gate",    "media_pll_src", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x520, 14, 0, },
2178c2ecf20Sopenharmony_ci	{ HI6220_CODEC_VPU_GATE, "codec_vpu_gate",   "clk_1000_1440", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x520, 15, 0, },
2188c2ecf20Sopenharmony_ci	{ HI6220_MED_SYSPLL,     "media_syspll_src", "media_syspll",  CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x520, 17, 0, },
2198c2ecf20Sopenharmony_ci};
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_cistatic struct hisi_mux_clock hi6220_mux_clks_media[] __initdata = {
2228c2ecf20Sopenharmony_ci	{ HI6220_1440_1200, "clk_1440_1200", clk_1440_1200_src, ARRAY_SIZE(clk_1440_1200_src), CLK_SET_RATE_PARENT, 0x51c, 0, 1, 0, },
2238c2ecf20Sopenharmony_ci	{ HI6220_1000_1200, "clk_1000_1200", clk_1000_1200_src, ARRAY_SIZE(clk_1000_1200_src), CLK_SET_RATE_PARENT, 0x51c, 1, 1, 0, },
2248c2ecf20Sopenharmony_ci	{ HI6220_1000_1440, "clk_1000_1440", clk_1000_1440_src, ARRAY_SIZE(clk_1000_1440_src), CLK_SET_RATE_PARENT, 0x51c, 6, 1, 0, },
2258c2ecf20Sopenharmony_ci};
2268c2ecf20Sopenharmony_ci
2278c2ecf20Sopenharmony_cistatic struct hi6220_divider_clock hi6220_div_clks_media[] __initdata = {
2288c2ecf20Sopenharmony_ci	{ HI6220_CODEC_JPEG,    "codec_jpeg_aclk", "media_pll_src",  CLK_SET_RATE_PARENT, 0xcbc, 0,  4, 23, },
2298c2ecf20Sopenharmony_ci	{ HI6220_ISP_SCLK_SRC,  "isp_sclk_src",    "isp_sclk_gate",  CLK_SET_RATE_PARENT, 0xcbc, 8,  4, 15, },
2308c2ecf20Sopenharmony_ci	{ HI6220_ISP_SCLK1,     "isp_sclk1",       "isp_sclk_gate1", CLK_SET_RATE_PARENT, 0xcbc, 24, 4, 31, },
2318c2ecf20Sopenharmony_ci	{ HI6220_ADE_CORE_SRC,  "ade_core_src",    "ade_core_gate",  CLK_SET_RATE_PARENT, 0xcc0, 16, 3, 23, },
2328c2ecf20Sopenharmony_ci	{ HI6220_ADE_PIX_SRC,   "ade_pix_src",     "clk_1440_1200",  CLK_SET_RATE_PARENT, 0xcc0, 24, 6, 31, },
2338c2ecf20Sopenharmony_ci	{ HI6220_G3D_CLK,       "g3d_clk",         "clk_1000_1200",  CLK_SET_RATE_PARENT, 0xcc4, 8,  4, 15, },
2348c2ecf20Sopenharmony_ci	{ HI6220_CODEC_VPU_SRC, "codec_vpu_src",   "codec_vpu_gate", CLK_SET_RATE_PARENT, 0xcc4, 24, 6, 31, },
2358c2ecf20Sopenharmony_ci};
2368c2ecf20Sopenharmony_ci
2378c2ecf20Sopenharmony_cistatic void __init hi6220_clk_media_init(struct device_node *np)
2388c2ecf20Sopenharmony_ci{
2398c2ecf20Sopenharmony_ci	struct hisi_clock_data *clk_data;
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_ci	clk_data = hisi_clk_init(np, HI6220_MEDIA_NR_CLKS);
2428c2ecf20Sopenharmony_ci	if (!clk_data)
2438c2ecf20Sopenharmony_ci		return;
2448c2ecf20Sopenharmony_ci
2458c2ecf20Sopenharmony_ci	hisi_clk_register_gate_sep(hi6220_separated_gate_clks_media,
2468c2ecf20Sopenharmony_ci				ARRAY_SIZE(hi6220_separated_gate_clks_media), clk_data);
2478c2ecf20Sopenharmony_ci
2488c2ecf20Sopenharmony_ci	hisi_clk_register_mux(hi6220_mux_clks_media,
2498c2ecf20Sopenharmony_ci				ARRAY_SIZE(hi6220_mux_clks_media), clk_data);
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_ci	hi6220_clk_register_divider(hi6220_div_clks_media,
2528c2ecf20Sopenharmony_ci				ARRAY_SIZE(hi6220_div_clks_media), clk_data);
2538c2ecf20Sopenharmony_ci}
2548c2ecf20Sopenharmony_ciCLK_OF_DECLARE_DRIVER(hi6220_clk_media, "hisilicon,hi6220-mediactrl", hi6220_clk_media_init);
2558c2ecf20Sopenharmony_ci
2568c2ecf20Sopenharmony_ci
2578c2ecf20Sopenharmony_ci/* clocks in pmctrl */
2588c2ecf20Sopenharmony_cistatic struct hisi_gate_clock hi6220_gate_clks_power[] __initdata = {
2598c2ecf20Sopenharmony_ci	{ HI6220_PLL_GPU_GATE,   "pll_gpu_gate",   "gpupll",    CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x8,  0,  0, },
2608c2ecf20Sopenharmony_ci	{ HI6220_PLL1_DDR_GATE,  "pll1_ddr_gate",  "ddrpll1",   CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x10, 0,  0, },
2618c2ecf20Sopenharmony_ci	{ HI6220_PLL_DDR_GATE,   "pll_ddr_gate",   "ddrpll0",   CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x18, 0,  0, },
2628c2ecf20Sopenharmony_ci	{ HI6220_PLL_MEDIA_GATE, "pll_media_gate", "media_pll", CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x38, 0,  0, },
2638c2ecf20Sopenharmony_ci	{ HI6220_PLL0_BBP_GATE,  "pll0_bbp_gate",  "bbppll0",   CLK_SET_RATE_PARENT|CLK_IGNORE_UNUSED, 0x48, 0,  0, },
2648c2ecf20Sopenharmony_ci};
2658c2ecf20Sopenharmony_ci
2668c2ecf20Sopenharmony_cistatic struct hi6220_divider_clock hi6220_div_clks_power[] __initdata = {
2678c2ecf20Sopenharmony_ci	{ HI6220_DDRC_SRC,  "ddrc_src",  "ddr_sel_src", CLK_SET_RATE_PARENT, 0x5a8, 0, 4, 0, },
2688c2ecf20Sopenharmony_ci	{ HI6220_DDRC_AXI1, "ddrc_axi1", "ddrc_src",    CLK_SET_RATE_PARENT, 0x5a8, 8, 2, 0, },
2698c2ecf20Sopenharmony_ci};
2708c2ecf20Sopenharmony_ci
2718c2ecf20Sopenharmony_cistatic void __init hi6220_clk_power_init(struct device_node *np)
2728c2ecf20Sopenharmony_ci{
2738c2ecf20Sopenharmony_ci	struct hisi_clock_data *clk_data;
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci	clk_data = hisi_clk_init(np, HI6220_POWER_NR_CLKS);
2768c2ecf20Sopenharmony_ci	if (!clk_data)
2778c2ecf20Sopenharmony_ci		return;
2788c2ecf20Sopenharmony_ci
2798c2ecf20Sopenharmony_ci	hisi_clk_register_gate(hi6220_gate_clks_power,
2808c2ecf20Sopenharmony_ci				ARRAY_SIZE(hi6220_gate_clks_power), clk_data);
2818c2ecf20Sopenharmony_ci
2828c2ecf20Sopenharmony_ci	hi6220_clk_register_divider(hi6220_div_clks_power,
2838c2ecf20Sopenharmony_ci				ARRAY_SIZE(hi6220_div_clks_power), clk_data);
2848c2ecf20Sopenharmony_ci}
2858c2ecf20Sopenharmony_ciCLK_OF_DECLARE(hi6220_clk_power, "hisilicon,hi6220-pmctrl", hi6220_clk_power_init);
2868c2ecf20Sopenharmony_ci
2878c2ecf20Sopenharmony_ci/* clocks in acpu */
2888c2ecf20Sopenharmony_cistatic const struct hisi_gate_clock hi6220_acpu_sc_gate_sep_clks[] = {
2898c2ecf20Sopenharmony_ci	{ HI6220_ACPU_SFT_AT_S, "sft_at_s", "cs_atb",
2908c2ecf20Sopenharmony_ci	  CLK_SET_RATE_PARENT | CLK_IGNORE_UNUSED, 0xc, 11, 0, },
2918c2ecf20Sopenharmony_ci};
2928c2ecf20Sopenharmony_ci
2938c2ecf20Sopenharmony_cistatic void __init hi6220_clk_acpu_init(struct device_node *np)
2948c2ecf20Sopenharmony_ci{
2958c2ecf20Sopenharmony_ci	struct hisi_clock_data *clk_data;
2968c2ecf20Sopenharmony_ci	int nr = ARRAY_SIZE(hi6220_acpu_sc_gate_sep_clks);
2978c2ecf20Sopenharmony_ci
2988c2ecf20Sopenharmony_ci	clk_data = hisi_clk_init(np, nr);
2998c2ecf20Sopenharmony_ci	if (!clk_data)
3008c2ecf20Sopenharmony_ci		return;
3018c2ecf20Sopenharmony_ci
3028c2ecf20Sopenharmony_ci	hisi_clk_register_gate_sep(hi6220_acpu_sc_gate_sep_clks,
3038c2ecf20Sopenharmony_ci				   ARRAY_SIZE(hi6220_acpu_sc_gate_sep_clks),
3048c2ecf20Sopenharmony_ci				   clk_data);
3058c2ecf20Sopenharmony_ci}
3068c2ecf20Sopenharmony_ci
3078c2ecf20Sopenharmony_ciCLK_OF_DECLARE(hi6220_clk_acpu, "hisilicon,hi6220-acpu-sctrl", hi6220_clk_acpu_init);
308