18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Copyright (c) 2016 Maxime Ripard. All rights reserved.
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
78c2ecf20Sopenharmony_ci#include <linux/io.h>
88c2ecf20Sopenharmony_ci#include <linux/of_address.h>
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#include "ccu_common.h"
118c2ecf20Sopenharmony_ci#include "ccu_reset.h"
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include "ccu_div.h"
148c2ecf20Sopenharmony_ci#include "ccu_gate.h"
158c2ecf20Sopenharmony_ci#include "ccu_mp.h"
168c2ecf20Sopenharmony_ci#include "ccu_mult.h"
178c2ecf20Sopenharmony_ci#include "ccu_nk.h"
188c2ecf20Sopenharmony_ci#include "ccu_nkm.h"
198c2ecf20Sopenharmony_ci#include "ccu_nkmp.h"
208c2ecf20Sopenharmony_ci#include "ccu_nm.h"
218c2ecf20Sopenharmony_ci#include "ccu_phase.h"
228c2ecf20Sopenharmony_ci#include "ccu_sdm.h"
238c2ecf20Sopenharmony_ci
248c2ecf20Sopenharmony_ci#include "ccu-sun8i-a23-a33.h"
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_cistatic struct ccu_nkmp pll_cpux_clk = {
288c2ecf20Sopenharmony_ci	.enable = BIT(31),
298c2ecf20Sopenharmony_ci	.lock	= BIT(28),
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ci	.n	= _SUNXI_CCU_MULT(8, 5),
328c2ecf20Sopenharmony_ci	.k	= _SUNXI_CCU_MULT(4, 2),
338c2ecf20Sopenharmony_ci	.m	= _SUNXI_CCU_DIV(0, 2),
348c2ecf20Sopenharmony_ci	.p	= _SUNXI_CCU_DIV_MAX(16, 2, 4),
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	.common	= {
378c2ecf20Sopenharmony_ci		.reg		= 0x000,
388c2ecf20Sopenharmony_ci		.hw.init	= CLK_HW_INIT("pll-cpux", "osc24M",
398c2ecf20Sopenharmony_ci					      &ccu_nkmp_ops,
408c2ecf20Sopenharmony_ci					      0),
418c2ecf20Sopenharmony_ci	},
428c2ecf20Sopenharmony_ci};
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci/*
458c2ecf20Sopenharmony_ci * The Audio PLL is supposed to have 4 outputs: 3 fixed factors from
468c2ecf20Sopenharmony_ci * the base (2x, 4x and 8x), and one variable divider (the one true
478c2ecf20Sopenharmony_ci * pll audio).
488c2ecf20Sopenharmony_ci *
498c2ecf20Sopenharmony_ci * With sigma-delta modulation for fractional-N on the audio PLL,
508c2ecf20Sopenharmony_ci * we have to use specific dividers. This means the variable divider
518c2ecf20Sopenharmony_ci * can no longer be used, as the audio codec requests the exact clock
528c2ecf20Sopenharmony_ci * rates we support through this mechanism. So we now hard code the
538c2ecf20Sopenharmony_ci * variable divider to 1. This means the clock rates will no longer
548c2ecf20Sopenharmony_ci * match the clock names.
558c2ecf20Sopenharmony_ci */
568c2ecf20Sopenharmony_ci#define SUN8I_A23_PLL_AUDIO_REG	0x008
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_cistatic struct ccu_sdm_setting pll_audio_sdm_table[] = {
598c2ecf20Sopenharmony_ci	{ .rate = 22579200, .pattern = 0xc0010d84, .m = 8, .n = 7 },
608c2ecf20Sopenharmony_ci	{ .rate = 24576000, .pattern = 0xc000ac02, .m = 14, .n = 14 },
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_cistatic SUNXI_CCU_NM_WITH_SDM_GATE_LOCK(pll_audio_base_clk, "pll-audio-base",
648c2ecf20Sopenharmony_ci				       "osc24M", 0x008,
658c2ecf20Sopenharmony_ci				       8, 7,	/* N */
668c2ecf20Sopenharmony_ci				       0, 5,	/* M */
678c2ecf20Sopenharmony_ci				       pll_audio_sdm_table, BIT(24),
688c2ecf20Sopenharmony_ci				       0x284, BIT(31),
698c2ecf20Sopenharmony_ci				       BIT(31),	/* gate */
708c2ecf20Sopenharmony_ci				       BIT(28),	/* lock */
718c2ecf20Sopenharmony_ci				       CLK_SET_RATE_UNGATE);
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_cistatic SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_video_clk, "pll-video",
748c2ecf20Sopenharmony_ci					"osc24M", 0x010,
758c2ecf20Sopenharmony_ci					8, 7,		/* N */
768c2ecf20Sopenharmony_ci					0, 4,		/* M */
778c2ecf20Sopenharmony_ci					BIT(24),	/* frac enable */
788c2ecf20Sopenharmony_ci					BIT(25),	/* frac select */
798c2ecf20Sopenharmony_ci					270000000,	/* frac rate 0 */
808c2ecf20Sopenharmony_ci					297000000,	/* frac rate 1 */
818c2ecf20Sopenharmony_ci					BIT(31),	/* gate */
828c2ecf20Sopenharmony_ci					BIT(28),	/* lock */
838c2ecf20Sopenharmony_ci					CLK_SET_RATE_UNGATE);
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistatic SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_ve_clk, "pll-ve",
868c2ecf20Sopenharmony_ci					"osc24M", 0x018,
878c2ecf20Sopenharmony_ci					8, 7,		/* N */
888c2ecf20Sopenharmony_ci					0, 4,		/* M */
898c2ecf20Sopenharmony_ci					BIT(24),	/* frac enable */
908c2ecf20Sopenharmony_ci					BIT(25),	/* frac select */
918c2ecf20Sopenharmony_ci					270000000,	/* frac rate 0 */
928c2ecf20Sopenharmony_ci					297000000,	/* frac rate 1 */
938c2ecf20Sopenharmony_ci					BIT(31),	/* gate */
948c2ecf20Sopenharmony_ci					BIT(28),	/* lock */
958c2ecf20Sopenharmony_ci					CLK_SET_RATE_UNGATE);
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_cistatic SUNXI_CCU_NKM_WITH_GATE_LOCK(pll_ddr_clk, "pll-ddr",
988c2ecf20Sopenharmony_ci				    "osc24M", 0x020,
998c2ecf20Sopenharmony_ci				    8, 5,		/* N */
1008c2ecf20Sopenharmony_ci				    4, 2,		/* K */
1018c2ecf20Sopenharmony_ci				    0, 2,		/* M */
1028c2ecf20Sopenharmony_ci				    BIT(31),		/* gate */
1038c2ecf20Sopenharmony_ci				    BIT(28),		/* lock */
1048c2ecf20Sopenharmony_ci				    0);
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_cistatic SUNXI_CCU_NK_WITH_GATE_LOCK_POSTDIV(pll_periph_clk, "pll-periph",
1078c2ecf20Sopenharmony_ci					   "osc24M", 0x028,
1088c2ecf20Sopenharmony_ci					   8, 5,	/* N */
1098c2ecf20Sopenharmony_ci					   4, 2,	/* K */
1108c2ecf20Sopenharmony_ci					   BIT(31),	/* gate */
1118c2ecf20Sopenharmony_ci					   BIT(28),	/* lock */
1128c2ecf20Sopenharmony_ci					   2,		/* post-div */
1138c2ecf20Sopenharmony_ci					   CLK_SET_RATE_UNGATE);
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_cistatic SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_gpu_clk, "pll-gpu",
1168c2ecf20Sopenharmony_ci					"osc24M", 0x038,
1178c2ecf20Sopenharmony_ci					8, 7,		/* N */
1188c2ecf20Sopenharmony_ci					0, 4,		/* M */
1198c2ecf20Sopenharmony_ci					BIT(24),	/* frac enable */
1208c2ecf20Sopenharmony_ci					BIT(25),	/* frac select */
1218c2ecf20Sopenharmony_ci					270000000,	/* frac rate 0 */
1228c2ecf20Sopenharmony_ci					297000000,	/* frac rate 1 */
1238c2ecf20Sopenharmony_ci					BIT(31),	/* gate */
1248c2ecf20Sopenharmony_ci					BIT(28),	/* lock */
1258c2ecf20Sopenharmony_ci					CLK_SET_RATE_UNGATE);
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_ci/*
1288c2ecf20Sopenharmony_ci * The MIPI PLL has 2 modes: "MIPI" and "HDMI".
1298c2ecf20Sopenharmony_ci *
1308c2ecf20Sopenharmony_ci * The MIPI mode is a standard NKM-style clock. The HDMI mode is an
1318c2ecf20Sopenharmony_ci * integer / fractional clock with switchable multipliers and dividers.
1328c2ecf20Sopenharmony_ci * This is not supported here. We hardcode the PLL to MIPI mode.
1338c2ecf20Sopenharmony_ci */
1348c2ecf20Sopenharmony_ci#define SUN8I_A23_PLL_MIPI_REG	0x040
1358c2ecf20Sopenharmony_cistatic SUNXI_CCU_NKM_WITH_GATE_LOCK(pll_mipi_clk, "pll-mipi",
1368c2ecf20Sopenharmony_ci				    "pll-video", 0x040,
1378c2ecf20Sopenharmony_ci				    8, 4,		/* N */
1388c2ecf20Sopenharmony_ci				    4, 2,		/* K */
1398c2ecf20Sopenharmony_ci				    0, 4,		/* M */
1408c2ecf20Sopenharmony_ci				    BIT(31) | BIT(23) | BIT(22), /* gate */
1418c2ecf20Sopenharmony_ci				    BIT(28),		/* lock */
1428c2ecf20Sopenharmony_ci				    CLK_SET_RATE_UNGATE);
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_cistatic SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_hsic_clk, "pll-hsic",
1458c2ecf20Sopenharmony_ci					"osc24M", 0x044,
1468c2ecf20Sopenharmony_ci					8, 7,		/* N */
1478c2ecf20Sopenharmony_ci					0, 4,		/* M */
1488c2ecf20Sopenharmony_ci					BIT(24),	/* frac enable */
1498c2ecf20Sopenharmony_ci					BIT(25),	/* frac select */
1508c2ecf20Sopenharmony_ci					270000000,	/* frac rate 0 */
1518c2ecf20Sopenharmony_ci					297000000,	/* frac rate 1 */
1528c2ecf20Sopenharmony_ci					BIT(31),	/* gate */
1538c2ecf20Sopenharmony_ci					BIT(28),	/* lock */
1548c2ecf20Sopenharmony_ci					CLK_SET_RATE_UNGATE);
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_cistatic SUNXI_CCU_NM_WITH_FRAC_GATE_LOCK(pll_de_clk, "pll-de",
1578c2ecf20Sopenharmony_ci					"osc24M", 0x048,
1588c2ecf20Sopenharmony_ci					8, 7,		/* N */
1598c2ecf20Sopenharmony_ci					0, 4,		/* M */
1608c2ecf20Sopenharmony_ci					BIT(24),	/* frac enable */
1618c2ecf20Sopenharmony_ci					BIT(25),	/* frac select */
1628c2ecf20Sopenharmony_ci					270000000,	/* frac rate 0 */
1638c2ecf20Sopenharmony_ci					297000000,	/* frac rate 1 */
1648c2ecf20Sopenharmony_ci					BIT(31),	/* gate */
1658c2ecf20Sopenharmony_ci					BIT(28),	/* lock */
1668c2ecf20Sopenharmony_ci					CLK_SET_RATE_UNGATE);
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_cistatic const char * const cpux_parents[] = { "osc32k", "osc24M",
1698c2ecf20Sopenharmony_ci					     "pll-cpux" , "pll-cpux" };
1708c2ecf20Sopenharmony_cistatic SUNXI_CCU_MUX(cpux_clk, "cpux", cpux_parents,
1718c2ecf20Sopenharmony_ci		     0x050, 16, 2, CLK_IS_CRITICAL);
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_cistatic SUNXI_CCU_M(axi_clk, "axi", "cpux", 0x050, 0, 2, 0);
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_cistatic const char * const ahb1_parents[] = { "osc32k", "osc24M",
1768c2ecf20Sopenharmony_ci					     "axi" , "pll-periph" };
1778c2ecf20Sopenharmony_cistatic const struct ccu_mux_var_prediv ahb1_predivs[] = {
1788c2ecf20Sopenharmony_ci	{ .index = 3, .shift = 6, .width = 2 },
1798c2ecf20Sopenharmony_ci};
1808c2ecf20Sopenharmony_cistatic struct ccu_div ahb1_clk = {
1818c2ecf20Sopenharmony_ci	.div		= _SUNXI_CCU_DIV_FLAGS(4, 2, CLK_DIVIDER_POWER_OF_TWO),
1828c2ecf20Sopenharmony_ci
1838c2ecf20Sopenharmony_ci	.mux		= {
1848c2ecf20Sopenharmony_ci		.shift	= 12,
1858c2ecf20Sopenharmony_ci		.width	= 2,
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci		.var_predivs	= ahb1_predivs,
1888c2ecf20Sopenharmony_ci		.n_var_predivs	= ARRAY_SIZE(ahb1_predivs),
1898c2ecf20Sopenharmony_ci	},
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci	.common		= {
1928c2ecf20Sopenharmony_ci		.reg		= 0x054,
1938c2ecf20Sopenharmony_ci		.features	= CCU_FEATURE_VARIABLE_PREDIV,
1948c2ecf20Sopenharmony_ci		.hw.init	= CLK_HW_INIT_PARENTS("ahb1",
1958c2ecf20Sopenharmony_ci						      ahb1_parents,
1968c2ecf20Sopenharmony_ci						      &ccu_div_ops,
1978c2ecf20Sopenharmony_ci						      0),
1988c2ecf20Sopenharmony_ci	},
1998c2ecf20Sopenharmony_ci};
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_cistatic struct clk_div_table apb1_div_table[] = {
2028c2ecf20Sopenharmony_ci	{ .val = 0, .div = 2 },
2038c2ecf20Sopenharmony_ci	{ .val = 1, .div = 2 },
2048c2ecf20Sopenharmony_ci	{ .val = 2, .div = 4 },
2058c2ecf20Sopenharmony_ci	{ .val = 3, .div = 8 },
2068c2ecf20Sopenharmony_ci	{ /* Sentinel */ },
2078c2ecf20Sopenharmony_ci};
2088c2ecf20Sopenharmony_cistatic SUNXI_CCU_DIV_TABLE(apb1_clk, "apb1", "ahb1",
2098c2ecf20Sopenharmony_ci			   0x054, 8, 2, apb1_div_table, 0);
2108c2ecf20Sopenharmony_ci
2118c2ecf20Sopenharmony_cistatic const char * const apb2_parents[] = { "osc32k", "osc24M",
2128c2ecf20Sopenharmony_ci					     "pll-periph" , "pll-periph" };
2138c2ecf20Sopenharmony_cistatic SUNXI_CCU_MP_WITH_MUX(apb2_clk, "apb2", apb2_parents, 0x058,
2148c2ecf20Sopenharmony_ci			     0, 5,	/* M */
2158c2ecf20Sopenharmony_ci			     16, 2,	/* P */
2168c2ecf20Sopenharmony_ci			     24, 2,	/* mux */
2178c2ecf20Sopenharmony_ci			     0);
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_mipi_dsi_clk,	"bus-mipi-dsi",	"ahb1",
2208c2ecf20Sopenharmony_ci		      0x060, BIT(1), 0);
2218c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_dma_clk,	"bus-dma",	"ahb1",
2228c2ecf20Sopenharmony_ci		      0x060, BIT(6), 0);
2238c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_mmc0_clk,	"bus-mmc0",	"ahb1",
2248c2ecf20Sopenharmony_ci		      0x060, BIT(8), 0);
2258c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_mmc1_clk,	"bus-mmc1",	"ahb1",
2268c2ecf20Sopenharmony_ci		      0x060, BIT(9), 0);
2278c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_mmc2_clk,	"bus-mmc2",	"ahb1",
2288c2ecf20Sopenharmony_ci		      0x060, BIT(10), 0);
2298c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_nand_clk,	"bus-nand",	"ahb1",
2308c2ecf20Sopenharmony_ci		      0x060, BIT(13), 0);
2318c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_dram_clk,	"bus-dram",	"ahb1",
2328c2ecf20Sopenharmony_ci		      0x060, BIT(14), 0);
2338c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_hstimer_clk,	"bus-hstimer",	"ahb1",
2348c2ecf20Sopenharmony_ci		      0x060, BIT(19), 0);
2358c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_spi0_clk,	"bus-spi0",	"ahb1",
2368c2ecf20Sopenharmony_ci		      0x060, BIT(20), 0);
2378c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_spi1_clk,	"bus-spi1",	"ahb1",
2388c2ecf20Sopenharmony_ci		      0x060, BIT(21), 0);
2398c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_otg_clk,	"bus-otg",	"ahb1",
2408c2ecf20Sopenharmony_ci		      0x060, BIT(24), 0);
2418c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_ehci_clk,	"bus-ehci",	"ahb1",
2428c2ecf20Sopenharmony_ci		      0x060, BIT(26), 0);
2438c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_ohci_clk,	"bus-ohci",	"ahb1",
2448c2ecf20Sopenharmony_ci		      0x060, BIT(29), 0);
2458c2ecf20Sopenharmony_ci
2468c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_ve_clk,	"bus-ve",	"ahb1",
2478c2ecf20Sopenharmony_ci		      0x064, BIT(0), 0);
2488c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_lcd_clk,	"bus-lcd",	"ahb1",
2498c2ecf20Sopenharmony_ci		      0x064, BIT(4), 0);
2508c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_csi_clk,	"bus-csi",	"ahb1",
2518c2ecf20Sopenharmony_ci		      0x064, BIT(8), 0);
2528c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_de_be_clk,	"bus-de-be",	"ahb1",
2538c2ecf20Sopenharmony_ci		      0x064, BIT(12), 0);
2548c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_de_fe_clk,	"bus-de-fe",	"ahb1",
2558c2ecf20Sopenharmony_ci		      0x064, BIT(14), 0);
2568c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_gpu_clk,	"bus-gpu",	"ahb1",
2578c2ecf20Sopenharmony_ci		      0x064, BIT(20), 0);
2588c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_msgbox_clk,	"bus-msgbox",	"ahb1",
2598c2ecf20Sopenharmony_ci		      0x064, BIT(21), 0);
2608c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_spinlock_clk,	"bus-spinlock",	"ahb1",
2618c2ecf20Sopenharmony_ci		      0x064, BIT(22), 0);
2628c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_drc_clk,	"bus-drc",	"ahb1",
2638c2ecf20Sopenharmony_ci		      0x064, BIT(25), 0);
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_codec_clk,	"bus-codec",	"apb1",
2668c2ecf20Sopenharmony_ci		      0x068, BIT(0), 0);
2678c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_pio_clk,	"bus-pio",	"apb1",
2688c2ecf20Sopenharmony_ci		      0x068, BIT(5), 0);
2698c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_i2s0_clk,	"bus-i2s0",	"apb1",
2708c2ecf20Sopenharmony_ci		      0x068, BIT(12), 0);
2718c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_i2s1_clk,	"bus-i2s1",	"apb1",
2728c2ecf20Sopenharmony_ci		      0x068, BIT(13), 0);
2738c2ecf20Sopenharmony_ci
2748c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_i2c0_clk,	"bus-i2c0",	"apb2",
2758c2ecf20Sopenharmony_ci		      0x06c, BIT(0), 0);
2768c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_i2c1_clk,	"bus-i2c1",	"apb2",
2778c2ecf20Sopenharmony_ci		      0x06c, BIT(1), 0);
2788c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_i2c2_clk,	"bus-i2c2",	"apb2",
2798c2ecf20Sopenharmony_ci		      0x06c, BIT(2), 0);
2808c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_uart0_clk,	"bus-uart0",	"apb2",
2818c2ecf20Sopenharmony_ci		      0x06c, BIT(16), 0);
2828c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_uart1_clk,	"bus-uart1",	"apb2",
2838c2ecf20Sopenharmony_ci		      0x06c, BIT(17), 0);
2848c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_uart2_clk,	"bus-uart2",	"apb2",
2858c2ecf20Sopenharmony_ci		      0x06c, BIT(18), 0);
2868c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_uart3_clk,	"bus-uart3",	"apb2",
2878c2ecf20Sopenharmony_ci		      0x06c, BIT(19), 0);
2888c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(bus_uart4_clk,	"bus-uart4",	"apb2",
2898c2ecf20Sopenharmony_ci		      0x06c, BIT(20), 0);
2908c2ecf20Sopenharmony_ci
2918c2ecf20Sopenharmony_cistatic const char * const mod0_default_parents[] = { "osc24M", "pll-periph" };
2928c2ecf20Sopenharmony_cistatic SUNXI_CCU_MP_WITH_MUX_GATE(nand_clk, "nand", mod0_default_parents, 0x080,
2938c2ecf20Sopenharmony_ci				  0, 4,		/* M */
2948c2ecf20Sopenharmony_ci				  16, 2,	/* P */
2958c2ecf20Sopenharmony_ci				  24, 2,	/* mux */
2968c2ecf20Sopenharmony_ci				  BIT(31),	/* gate */
2978c2ecf20Sopenharmony_ci				  0);
2988c2ecf20Sopenharmony_ci
2998c2ecf20Sopenharmony_cistatic SUNXI_CCU_MP_WITH_MUX_GATE(mmc0_clk, "mmc0", mod0_default_parents, 0x088,
3008c2ecf20Sopenharmony_ci				  0, 4,		/* M */
3018c2ecf20Sopenharmony_ci				  16, 2,	/* P */
3028c2ecf20Sopenharmony_ci				  24, 2,	/* mux */
3038c2ecf20Sopenharmony_ci				  BIT(31),	/* gate */
3048c2ecf20Sopenharmony_ci				  0);
3058c2ecf20Sopenharmony_ci
3068c2ecf20Sopenharmony_cistatic SUNXI_CCU_PHASE(mmc0_sample_clk, "mmc0_sample", "mmc0",
3078c2ecf20Sopenharmony_ci		       0x088, 20, 3, 0);
3088c2ecf20Sopenharmony_cistatic SUNXI_CCU_PHASE(mmc0_output_clk, "mmc0_output", "mmc0",
3098c2ecf20Sopenharmony_ci		       0x088, 8, 3, 0);
3108c2ecf20Sopenharmony_ci
3118c2ecf20Sopenharmony_cistatic SUNXI_CCU_MP_WITH_MUX_GATE(mmc1_clk, "mmc1", mod0_default_parents, 0x08c,
3128c2ecf20Sopenharmony_ci				  0, 4,		/* M */
3138c2ecf20Sopenharmony_ci				  16, 2,	/* P */
3148c2ecf20Sopenharmony_ci				  24, 2,	/* mux */
3158c2ecf20Sopenharmony_ci				  BIT(31),	/* gate */
3168c2ecf20Sopenharmony_ci				  0);
3178c2ecf20Sopenharmony_ci
3188c2ecf20Sopenharmony_cistatic SUNXI_CCU_PHASE(mmc1_sample_clk, "mmc1_sample", "mmc1",
3198c2ecf20Sopenharmony_ci		       0x08c, 20, 3, 0);
3208c2ecf20Sopenharmony_cistatic SUNXI_CCU_PHASE(mmc1_output_clk, "mmc1_output", "mmc1",
3218c2ecf20Sopenharmony_ci		       0x08c, 8, 3, 0);
3228c2ecf20Sopenharmony_ci
3238c2ecf20Sopenharmony_cistatic SUNXI_CCU_MP_WITH_MUX_GATE(mmc2_clk, "mmc2", mod0_default_parents, 0x090,
3248c2ecf20Sopenharmony_ci				  0, 4,		/* M */
3258c2ecf20Sopenharmony_ci				  16, 2,	/* P */
3268c2ecf20Sopenharmony_ci				  24, 2,	/* mux */
3278c2ecf20Sopenharmony_ci				  BIT(31),	/* gate */
3288c2ecf20Sopenharmony_ci				  0);
3298c2ecf20Sopenharmony_ci
3308c2ecf20Sopenharmony_cistatic SUNXI_CCU_PHASE(mmc2_sample_clk, "mmc2_sample", "mmc2",
3318c2ecf20Sopenharmony_ci		       0x090, 20, 3, 0);
3328c2ecf20Sopenharmony_cistatic SUNXI_CCU_PHASE(mmc2_output_clk, "mmc2_output", "mmc2",
3338c2ecf20Sopenharmony_ci		       0x090, 8, 3, 0);
3348c2ecf20Sopenharmony_ci
3358c2ecf20Sopenharmony_cistatic SUNXI_CCU_MP_WITH_MUX_GATE(spi0_clk, "spi0", mod0_default_parents, 0x0a0,
3368c2ecf20Sopenharmony_ci				  0, 4,		/* M */
3378c2ecf20Sopenharmony_ci				  16, 2,	/* P */
3388c2ecf20Sopenharmony_ci				  24, 2,	/* mux */
3398c2ecf20Sopenharmony_ci				  BIT(31),	/* gate */
3408c2ecf20Sopenharmony_ci				  0);
3418c2ecf20Sopenharmony_ci
3428c2ecf20Sopenharmony_cistatic SUNXI_CCU_MP_WITH_MUX_GATE(spi1_clk, "spi1", mod0_default_parents, 0x0a4,
3438c2ecf20Sopenharmony_ci				  0, 4,		/* M */
3448c2ecf20Sopenharmony_ci				  16, 2,	/* P */
3458c2ecf20Sopenharmony_ci				  24, 2,	/* mux */
3468c2ecf20Sopenharmony_ci				  BIT(31),	/* gate */
3478c2ecf20Sopenharmony_ci				  0);
3488c2ecf20Sopenharmony_ci
3498c2ecf20Sopenharmony_cistatic const char * const i2s_parents[] = { "pll-audio-8x", "pll-audio-4x",
3508c2ecf20Sopenharmony_ci					    "pll-audio-2x", "pll-audio" };
3518c2ecf20Sopenharmony_cistatic SUNXI_CCU_MUX_WITH_GATE(i2s0_clk, "i2s0", i2s_parents,
3528c2ecf20Sopenharmony_ci			       0x0b0, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
3538c2ecf20Sopenharmony_ci
3548c2ecf20Sopenharmony_cistatic SUNXI_CCU_MUX_WITH_GATE(i2s1_clk, "i2s1", i2s_parents,
3558c2ecf20Sopenharmony_ci			       0x0b4, 16, 2, BIT(31), CLK_SET_RATE_PARENT);
3568c2ecf20Sopenharmony_ci
3578c2ecf20Sopenharmony_ci/* TODO: the parent for most of the USB clocks is not known */
3588c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(usb_phy0_clk,	"usb-phy0",	"osc24M",
3598c2ecf20Sopenharmony_ci		      0x0cc, BIT(8), 0);
3608c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(usb_phy1_clk,	"usb-phy1",	"osc24M",
3618c2ecf20Sopenharmony_ci		      0x0cc, BIT(9), 0);
3628c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(usb_hsic_clk,	"usb-hsic",	"pll-hsic",
3638c2ecf20Sopenharmony_ci		      0x0cc, BIT(10), 0);
3648c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(usb_hsic_12M_clk,	"usb-hsic-12M",	"osc24M",
3658c2ecf20Sopenharmony_ci		      0x0cc, BIT(11), 0);
3668c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(usb_ohci_clk,	"usb-ohci",	"osc24M",
3678c2ecf20Sopenharmony_ci		      0x0cc, BIT(16), 0);
3688c2ecf20Sopenharmony_ci
3698c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(dram_ve_clk,	"dram-ve",	"pll-ddr",
3708c2ecf20Sopenharmony_ci		      0x100, BIT(0), 0);
3718c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(dram_csi_clk,	"dram-csi",	"pll-ddr",
3728c2ecf20Sopenharmony_ci		      0x100, BIT(1), 0);
3738c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(dram_drc_clk,	"dram-drc",	"pll-ddr",
3748c2ecf20Sopenharmony_ci		      0x100, BIT(16), 0);
3758c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(dram_de_fe_clk,	"dram-de-fe",	"pll-ddr",
3768c2ecf20Sopenharmony_ci		      0x100, BIT(24), 0);
3778c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(dram_de_be_clk,	"dram-de-be",	"pll-ddr",
3788c2ecf20Sopenharmony_ci		      0x100, BIT(26), 0);
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_cistatic const char * const de_parents[] = { "pll-video", "pll-periph-2x",
3818c2ecf20Sopenharmony_ci					   "pll-gpu", "pll-de" };
3828c2ecf20Sopenharmony_cistatic const u8 de_table[] = { 0, 2, 3, 5 };
3838c2ecf20Sopenharmony_cistatic SUNXI_CCU_M_WITH_MUX_TABLE_GATE(de_be_clk, "de-be",
3848c2ecf20Sopenharmony_ci				       de_parents, de_table,
3858c2ecf20Sopenharmony_ci				       0x104, 0, 4, 24, 3, BIT(31), 0);
3868c2ecf20Sopenharmony_ci
3878c2ecf20Sopenharmony_cistatic SUNXI_CCU_M_WITH_MUX_TABLE_GATE(de_fe_clk, "de-fe",
3888c2ecf20Sopenharmony_ci				       de_parents, de_table,
3898c2ecf20Sopenharmony_ci				       0x10c, 0, 4, 24, 3, BIT(31), 0);
3908c2ecf20Sopenharmony_ci
3918c2ecf20Sopenharmony_cistatic const char * const lcd_ch0_parents[] = { "pll-video", "pll-video-2x",
3928c2ecf20Sopenharmony_ci						"pll-mipi" };
3938c2ecf20Sopenharmony_cistatic const u8 lcd_ch0_table[] = { 0, 2, 4 };
3948c2ecf20Sopenharmony_cistatic SUNXI_CCU_MUX_TABLE_WITH_GATE(lcd_ch0_clk, "lcd-ch0",
3958c2ecf20Sopenharmony_ci				     lcd_ch0_parents, lcd_ch0_table,
3968c2ecf20Sopenharmony_ci				     0x118, 24, 3, BIT(31),
3978c2ecf20Sopenharmony_ci				     CLK_SET_RATE_PARENT);
3988c2ecf20Sopenharmony_ci
3998c2ecf20Sopenharmony_cistatic const char * const lcd_ch1_parents[] = { "pll-video", "pll-video-2x" };
4008c2ecf20Sopenharmony_cistatic const u8 lcd_ch1_table[] = { 0, 2 };
4018c2ecf20Sopenharmony_cistatic SUNXI_CCU_M_WITH_MUX_TABLE_GATE(lcd_ch1_clk, "lcd-ch1",
4028c2ecf20Sopenharmony_ci				       lcd_ch1_parents, lcd_ch1_table,
4038c2ecf20Sopenharmony_ci				       0x12c, 0, 4, 24, 2, BIT(31), 0);
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_cistatic const char * const csi_sclk_parents[] = { "pll-video", "pll-de",
4068c2ecf20Sopenharmony_ci						 "pll-mipi", "pll-ve" };
4078c2ecf20Sopenharmony_cistatic const u8 csi_sclk_table[] = { 0, 3, 4, 5 };
4088c2ecf20Sopenharmony_cistatic SUNXI_CCU_M_WITH_MUX_TABLE_GATE(csi_sclk_clk, "csi-sclk",
4098c2ecf20Sopenharmony_ci				       csi_sclk_parents, csi_sclk_table,
4108c2ecf20Sopenharmony_ci				       0x134, 16, 4, 24, 3, BIT(31), 0);
4118c2ecf20Sopenharmony_ci
4128c2ecf20Sopenharmony_cistatic const char * const csi_mclk_parents[] = { "pll-video", "pll-de",
4138c2ecf20Sopenharmony_ci						 "osc24M" };
4148c2ecf20Sopenharmony_cistatic const u8 csi_mclk_table[] = { 0, 3, 5 };
4158c2ecf20Sopenharmony_cistatic SUNXI_CCU_M_WITH_MUX_TABLE_GATE(csi_mclk_clk, "csi-mclk",
4168c2ecf20Sopenharmony_ci				       csi_mclk_parents, csi_mclk_table,
4178c2ecf20Sopenharmony_ci				       0x134, 0, 5, 8, 3, BIT(15), 0);
4188c2ecf20Sopenharmony_ci
4198c2ecf20Sopenharmony_cistatic SUNXI_CCU_M_WITH_GATE(ve_clk, "ve", "pll-ve",
4208c2ecf20Sopenharmony_ci			     0x13c, 16, 3, BIT(31), CLK_SET_RATE_PARENT);
4218c2ecf20Sopenharmony_ci
4228c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(ac_dig_clk,	"ac-dig",	"pll-audio",
4238c2ecf20Sopenharmony_ci		      0x140, BIT(31), CLK_SET_RATE_PARENT);
4248c2ecf20Sopenharmony_cistatic SUNXI_CCU_GATE(avs_clk,		"avs",		"osc24M",
4258c2ecf20Sopenharmony_ci		      0x144, BIT(31), 0);
4268c2ecf20Sopenharmony_ci
4278c2ecf20Sopenharmony_cistatic const char * const mbus_parents[] = { "osc24M", "pll-periph-2x",
4288c2ecf20Sopenharmony_ci					     "pll-ddr" };
4298c2ecf20Sopenharmony_cistatic SUNXI_CCU_M_WITH_MUX_GATE(mbus_clk, "mbus", mbus_parents,
4308c2ecf20Sopenharmony_ci				 0x15c, 0, 3, 24, 2, BIT(31), CLK_IS_CRITICAL);
4318c2ecf20Sopenharmony_ci
4328c2ecf20Sopenharmony_cistatic const char * const dsi_sclk_parents[] = { "pll-video", "pll-video-2x" };
4338c2ecf20Sopenharmony_cistatic const u8 dsi_sclk_table[] = { 0, 2 };
4348c2ecf20Sopenharmony_cistatic SUNXI_CCU_M_WITH_MUX_TABLE_GATE(dsi_sclk_clk, "dsi-sclk",
4358c2ecf20Sopenharmony_ci				       dsi_sclk_parents, dsi_sclk_table,
4368c2ecf20Sopenharmony_ci				       0x168, 16, 4, 24, 2, BIT(31), 0);
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_cistatic const char * const dsi_dphy_parents[] = { "pll-video", "pll-periph" };
4398c2ecf20Sopenharmony_cistatic const u8 dsi_dphy_table[] = { 0, 2 };
4408c2ecf20Sopenharmony_cistatic SUNXI_CCU_M_WITH_MUX_TABLE_GATE(dsi_dphy_clk, "dsi-dphy",
4418c2ecf20Sopenharmony_ci				       dsi_dphy_parents, dsi_dphy_table,
4428c2ecf20Sopenharmony_ci				       0x168, 0, 4, 8, 2, BIT(15), 0);
4438c2ecf20Sopenharmony_ci
4448c2ecf20Sopenharmony_cistatic SUNXI_CCU_M_WITH_MUX_TABLE_GATE(drc_clk, "drc",
4458c2ecf20Sopenharmony_ci				       de_parents, de_table,
4468c2ecf20Sopenharmony_ci				       0x180, 0, 4, 24, 3, BIT(31), 0);
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_cistatic SUNXI_CCU_M_WITH_GATE(gpu_clk, "gpu", "pll-gpu",
4498c2ecf20Sopenharmony_ci			     0x1a0, 0, 3, BIT(31), 0);
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_cistatic const char * const ats_parents[] = { "osc24M", "pll-periph" };
4528c2ecf20Sopenharmony_cistatic SUNXI_CCU_M_WITH_MUX_GATE(ats_clk, "ats", ats_parents,
4538c2ecf20Sopenharmony_ci				 0x1b0, 0, 3, 24, 2, BIT(31), 0);
4548c2ecf20Sopenharmony_ci
4558c2ecf20Sopenharmony_cistatic struct ccu_common *sun8i_a23_ccu_clks[] = {
4568c2ecf20Sopenharmony_ci	&pll_cpux_clk.common,
4578c2ecf20Sopenharmony_ci	&pll_audio_base_clk.common,
4588c2ecf20Sopenharmony_ci	&pll_video_clk.common,
4598c2ecf20Sopenharmony_ci	&pll_ve_clk.common,
4608c2ecf20Sopenharmony_ci	&pll_ddr_clk.common,
4618c2ecf20Sopenharmony_ci	&pll_periph_clk.common,
4628c2ecf20Sopenharmony_ci	&pll_gpu_clk.common,
4638c2ecf20Sopenharmony_ci	&pll_mipi_clk.common,
4648c2ecf20Sopenharmony_ci	&pll_hsic_clk.common,
4658c2ecf20Sopenharmony_ci	&pll_de_clk.common,
4668c2ecf20Sopenharmony_ci	&cpux_clk.common,
4678c2ecf20Sopenharmony_ci	&axi_clk.common,
4688c2ecf20Sopenharmony_ci	&ahb1_clk.common,
4698c2ecf20Sopenharmony_ci	&apb1_clk.common,
4708c2ecf20Sopenharmony_ci	&apb2_clk.common,
4718c2ecf20Sopenharmony_ci	&bus_mipi_dsi_clk.common,
4728c2ecf20Sopenharmony_ci	&bus_dma_clk.common,
4738c2ecf20Sopenharmony_ci	&bus_mmc0_clk.common,
4748c2ecf20Sopenharmony_ci	&bus_mmc1_clk.common,
4758c2ecf20Sopenharmony_ci	&bus_mmc2_clk.common,
4768c2ecf20Sopenharmony_ci	&bus_nand_clk.common,
4778c2ecf20Sopenharmony_ci	&bus_dram_clk.common,
4788c2ecf20Sopenharmony_ci	&bus_hstimer_clk.common,
4798c2ecf20Sopenharmony_ci	&bus_spi0_clk.common,
4808c2ecf20Sopenharmony_ci	&bus_spi1_clk.common,
4818c2ecf20Sopenharmony_ci	&bus_otg_clk.common,
4828c2ecf20Sopenharmony_ci	&bus_ehci_clk.common,
4838c2ecf20Sopenharmony_ci	&bus_ohci_clk.common,
4848c2ecf20Sopenharmony_ci	&bus_ve_clk.common,
4858c2ecf20Sopenharmony_ci	&bus_lcd_clk.common,
4868c2ecf20Sopenharmony_ci	&bus_csi_clk.common,
4878c2ecf20Sopenharmony_ci	&bus_de_fe_clk.common,
4888c2ecf20Sopenharmony_ci	&bus_de_be_clk.common,
4898c2ecf20Sopenharmony_ci	&bus_gpu_clk.common,
4908c2ecf20Sopenharmony_ci	&bus_msgbox_clk.common,
4918c2ecf20Sopenharmony_ci	&bus_spinlock_clk.common,
4928c2ecf20Sopenharmony_ci	&bus_drc_clk.common,
4938c2ecf20Sopenharmony_ci	&bus_codec_clk.common,
4948c2ecf20Sopenharmony_ci	&bus_pio_clk.common,
4958c2ecf20Sopenharmony_ci	&bus_i2s0_clk.common,
4968c2ecf20Sopenharmony_ci	&bus_i2s1_clk.common,
4978c2ecf20Sopenharmony_ci	&bus_i2c0_clk.common,
4988c2ecf20Sopenharmony_ci	&bus_i2c1_clk.common,
4998c2ecf20Sopenharmony_ci	&bus_i2c2_clk.common,
5008c2ecf20Sopenharmony_ci	&bus_uart0_clk.common,
5018c2ecf20Sopenharmony_ci	&bus_uart1_clk.common,
5028c2ecf20Sopenharmony_ci	&bus_uart2_clk.common,
5038c2ecf20Sopenharmony_ci	&bus_uart3_clk.common,
5048c2ecf20Sopenharmony_ci	&bus_uart4_clk.common,
5058c2ecf20Sopenharmony_ci	&nand_clk.common,
5068c2ecf20Sopenharmony_ci	&mmc0_clk.common,
5078c2ecf20Sopenharmony_ci	&mmc0_sample_clk.common,
5088c2ecf20Sopenharmony_ci	&mmc0_output_clk.common,
5098c2ecf20Sopenharmony_ci	&mmc1_clk.common,
5108c2ecf20Sopenharmony_ci	&mmc1_sample_clk.common,
5118c2ecf20Sopenharmony_ci	&mmc1_output_clk.common,
5128c2ecf20Sopenharmony_ci	&mmc2_clk.common,
5138c2ecf20Sopenharmony_ci	&mmc2_sample_clk.common,
5148c2ecf20Sopenharmony_ci	&mmc2_output_clk.common,
5158c2ecf20Sopenharmony_ci	&spi0_clk.common,
5168c2ecf20Sopenharmony_ci	&spi1_clk.common,
5178c2ecf20Sopenharmony_ci	&i2s0_clk.common,
5188c2ecf20Sopenharmony_ci	&i2s1_clk.common,
5198c2ecf20Sopenharmony_ci	&usb_phy0_clk.common,
5208c2ecf20Sopenharmony_ci	&usb_phy1_clk.common,
5218c2ecf20Sopenharmony_ci	&usb_hsic_clk.common,
5228c2ecf20Sopenharmony_ci	&usb_hsic_12M_clk.common,
5238c2ecf20Sopenharmony_ci	&usb_ohci_clk.common,
5248c2ecf20Sopenharmony_ci	&dram_ve_clk.common,
5258c2ecf20Sopenharmony_ci	&dram_csi_clk.common,
5268c2ecf20Sopenharmony_ci	&dram_drc_clk.common,
5278c2ecf20Sopenharmony_ci	&dram_de_fe_clk.common,
5288c2ecf20Sopenharmony_ci	&dram_de_be_clk.common,
5298c2ecf20Sopenharmony_ci	&de_be_clk.common,
5308c2ecf20Sopenharmony_ci	&de_fe_clk.common,
5318c2ecf20Sopenharmony_ci	&lcd_ch0_clk.common,
5328c2ecf20Sopenharmony_ci	&lcd_ch1_clk.common,
5338c2ecf20Sopenharmony_ci	&csi_sclk_clk.common,
5348c2ecf20Sopenharmony_ci	&csi_mclk_clk.common,
5358c2ecf20Sopenharmony_ci	&ve_clk.common,
5368c2ecf20Sopenharmony_ci	&ac_dig_clk.common,
5378c2ecf20Sopenharmony_ci	&avs_clk.common,
5388c2ecf20Sopenharmony_ci	&mbus_clk.common,
5398c2ecf20Sopenharmony_ci	&dsi_sclk_clk.common,
5408c2ecf20Sopenharmony_ci	&dsi_dphy_clk.common,
5418c2ecf20Sopenharmony_ci	&drc_clk.common,
5428c2ecf20Sopenharmony_ci	&gpu_clk.common,
5438c2ecf20Sopenharmony_ci	&ats_clk.common,
5448c2ecf20Sopenharmony_ci};
5458c2ecf20Sopenharmony_ci
5468c2ecf20Sopenharmony_cistatic const struct clk_hw *clk_parent_pll_audio[] = {
5478c2ecf20Sopenharmony_ci	&pll_audio_base_clk.common.hw
5488c2ecf20Sopenharmony_ci};
5498c2ecf20Sopenharmony_ci
5508c2ecf20Sopenharmony_ci/* We hardcode the divider to 1 for now */
5518c2ecf20Sopenharmony_cistatic CLK_FIXED_FACTOR_HWS(pll_audio_clk, "pll-audio",
5528c2ecf20Sopenharmony_ci			    clk_parent_pll_audio,
5538c2ecf20Sopenharmony_ci			    1, 1, CLK_SET_RATE_PARENT);
5548c2ecf20Sopenharmony_cistatic CLK_FIXED_FACTOR_HWS(pll_audio_2x_clk, "pll-audio-2x",
5558c2ecf20Sopenharmony_ci			    clk_parent_pll_audio,
5568c2ecf20Sopenharmony_ci			    2, 1, CLK_SET_RATE_PARENT);
5578c2ecf20Sopenharmony_cistatic CLK_FIXED_FACTOR_HWS(pll_audio_4x_clk, "pll-audio-4x",
5588c2ecf20Sopenharmony_ci			    clk_parent_pll_audio,
5598c2ecf20Sopenharmony_ci			    1, 1, CLK_SET_RATE_PARENT);
5608c2ecf20Sopenharmony_cistatic CLK_FIXED_FACTOR_HWS(pll_audio_8x_clk, "pll-audio-8x",
5618c2ecf20Sopenharmony_ci			    clk_parent_pll_audio,
5628c2ecf20Sopenharmony_ci			    1, 2, CLK_SET_RATE_PARENT);
5638c2ecf20Sopenharmony_cistatic CLK_FIXED_FACTOR_HW(pll_periph_2x_clk, "pll-periph-2x",
5648c2ecf20Sopenharmony_ci			   &pll_periph_clk.common.hw,
5658c2ecf20Sopenharmony_ci			   1, 2, 0);
5668c2ecf20Sopenharmony_cistatic CLK_FIXED_FACTOR_HW(pll_video_2x_clk, "pll-video-2x",
5678c2ecf20Sopenharmony_ci			   &pll_video_clk.common.hw,
5688c2ecf20Sopenharmony_ci			   1, 2, 0);
5698c2ecf20Sopenharmony_ci
5708c2ecf20Sopenharmony_cistatic struct clk_hw_onecell_data sun8i_a23_hw_clks = {
5718c2ecf20Sopenharmony_ci	.hws	= {
5728c2ecf20Sopenharmony_ci		[CLK_PLL_CPUX]		= &pll_cpux_clk.common.hw,
5738c2ecf20Sopenharmony_ci		[CLK_PLL_AUDIO_BASE]	= &pll_audio_base_clk.common.hw,
5748c2ecf20Sopenharmony_ci		[CLK_PLL_AUDIO]		= &pll_audio_clk.hw,
5758c2ecf20Sopenharmony_ci		[CLK_PLL_AUDIO_2X]	= &pll_audio_2x_clk.hw,
5768c2ecf20Sopenharmony_ci		[CLK_PLL_AUDIO_4X]	= &pll_audio_4x_clk.hw,
5778c2ecf20Sopenharmony_ci		[CLK_PLL_AUDIO_8X]	= &pll_audio_8x_clk.hw,
5788c2ecf20Sopenharmony_ci		[CLK_PLL_VIDEO]		= &pll_video_clk.common.hw,
5798c2ecf20Sopenharmony_ci		[CLK_PLL_VIDEO_2X]	= &pll_video_2x_clk.hw,
5808c2ecf20Sopenharmony_ci		[CLK_PLL_VE]		= &pll_ve_clk.common.hw,
5818c2ecf20Sopenharmony_ci		[CLK_PLL_DDR0]		= &pll_ddr_clk.common.hw,
5828c2ecf20Sopenharmony_ci		[CLK_PLL_PERIPH]	= &pll_periph_clk.common.hw,
5838c2ecf20Sopenharmony_ci		[CLK_PLL_PERIPH_2X]	= &pll_periph_2x_clk.hw,
5848c2ecf20Sopenharmony_ci		[CLK_PLL_GPU]		= &pll_gpu_clk.common.hw,
5858c2ecf20Sopenharmony_ci		[CLK_PLL_MIPI]		= &pll_mipi_clk.common.hw,
5868c2ecf20Sopenharmony_ci		[CLK_PLL_HSIC]		= &pll_hsic_clk.common.hw,
5878c2ecf20Sopenharmony_ci		[CLK_PLL_DE]		= &pll_de_clk.common.hw,
5888c2ecf20Sopenharmony_ci		[CLK_CPUX]		= &cpux_clk.common.hw,
5898c2ecf20Sopenharmony_ci		[CLK_AXI]		= &axi_clk.common.hw,
5908c2ecf20Sopenharmony_ci		[CLK_AHB1]		= &ahb1_clk.common.hw,
5918c2ecf20Sopenharmony_ci		[CLK_APB1]		= &apb1_clk.common.hw,
5928c2ecf20Sopenharmony_ci		[CLK_APB2]		= &apb2_clk.common.hw,
5938c2ecf20Sopenharmony_ci		[CLK_BUS_MIPI_DSI]	= &bus_mipi_dsi_clk.common.hw,
5948c2ecf20Sopenharmony_ci		[CLK_BUS_DMA]		= &bus_dma_clk.common.hw,
5958c2ecf20Sopenharmony_ci		[CLK_BUS_MMC0]		= &bus_mmc0_clk.common.hw,
5968c2ecf20Sopenharmony_ci		[CLK_BUS_MMC1]		= &bus_mmc1_clk.common.hw,
5978c2ecf20Sopenharmony_ci		[CLK_BUS_MMC2]		= &bus_mmc2_clk.common.hw,
5988c2ecf20Sopenharmony_ci		[CLK_BUS_NAND]		= &bus_nand_clk.common.hw,
5998c2ecf20Sopenharmony_ci		[CLK_BUS_DRAM]		= &bus_dram_clk.common.hw,
6008c2ecf20Sopenharmony_ci		[CLK_BUS_HSTIMER]	= &bus_hstimer_clk.common.hw,
6018c2ecf20Sopenharmony_ci		[CLK_BUS_SPI0]		= &bus_spi0_clk.common.hw,
6028c2ecf20Sopenharmony_ci		[CLK_BUS_SPI1]		= &bus_spi1_clk.common.hw,
6038c2ecf20Sopenharmony_ci		[CLK_BUS_OTG]		= &bus_otg_clk.common.hw,
6048c2ecf20Sopenharmony_ci		[CLK_BUS_EHCI]		= &bus_ehci_clk.common.hw,
6058c2ecf20Sopenharmony_ci		[CLK_BUS_OHCI]		= &bus_ohci_clk.common.hw,
6068c2ecf20Sopenharmony_ci		[CLK_BUS_VE]		= &bus_ve_clk.common.hw,
6078c2ecf20Sopenharmony_ci		[CLK_BUS_LCD]		= &bus_lcd_clk.common.hw,
6088c2ecf20Sopenharmony_ci		[CLK_BUS_CSI]		= &bus_csi_clk.common.hw,
6098c2ecf20Sopenharmony_ci		[CLK_BUS_DE_BE]		= &bus_de_be_clk.common.hw,
6108c2ecf20Sopenharmony_ci		[CLK_BUS_DE_FE]		= &bus_de_fe_clk.common.hw,
6118c2ecf20Sopenharmony_ci		[CLK_BUS_GPU]		= &bus_gpu_clk.common.hw,
6128c2ecf20Sopenharmony_ci		[CLK_BUS_MSGBOX]	= &bus_msgbox_clk.common.hw,
6138c2ecf20Sopenharmony_ci		[CLK_BUS_SPINLOCK]	= &bus_spinlock_clk.common.hw,
6148c2ecf20Sopenharmony_ci		[CLK_BUS_DRC]		= &bus_drc_clk.common.hw,
6158c2ecf20Sopenharmony_ci		[CLK_BUS_CODEC]		= &bus_codec_clk.common.hw,
6168c2ecf20Sopenharmony_ci		[CLK_BUS_PIO]		= &bus_pio_clk.common.hw,
6178c2ecf20Sopenharmony_ci		[CLK_BUS_I2S0]		= &bus_i2s0_clk.common.hw,
6188c2ecf20Sopenharmony_ci		[CLK_BUS_I2S1]		= &bus_i2s1_clk.common.hw,
6198c2ecf20Sopenharmony_ci		[CLK_BUS_I2C0]		= &bus_i2c0_clk.common.hw,
6208c2ecf20Sopenharmony_ci		[CLK_BUS_I2C1]		= &bus_i2c1_clk.common.hw,
6218c2ecf20Sopenharmony_ci		[CLK_BUS_I2C2]		= &bus_i2c2_clk.common.hw,
6228c2ecf20Sopenharmony_ci		[CLK_BUS_UART0]		= &bus_uart0_clk.common.hw,
6238c2ecf20Sopenharmony_ci		[CLK_BUS_UART1]		= &bus_uart1_clk.common.hw,
6248c2ecf20Sopenharmony_ci		[CLK_BUS_UART2]		= &bus_uart2_clk.common.hw,
6258c2ecf20Sopenharmony_ci		[CLK_BUS_UART3]		= &bus_uart3_clk.common.hw,
6268c2ecf20Sopenharmony_ci		[CLK_BUS_UART4]		= &bus_uart4_clk.common.hw,
6278c2ecf20Sopenharmony_ci		[CLK_NAND]		= &nand_clk.common.hw,
6288c2ecf20Sopenharmony_ci		[CLK_MMC0]		= &mmc0_clk.common.hw,
6298c2ecf20Sopenharmony_ci		[CLK_MMC0_SAMPLE]	= &mmc0_sample_clk.common.hw,
6308c2ecf20Sopenharmony_ci		[CLK_MMC0_OUTPUT]	= &mmc0_output_clk.common.hw,
6318c2ecf20Sopenharmony_ci		[CLK_MMC1]		= &mmc1_clk.common.hw,
6328c2ecf20Sopenharmony_ci		[CLK_MMC1_SAMPLE]	= &mmc1_sample_clk.common.hw,
6338c2ecf20Sopenharmony_ci		[CLK_MMC1_OUTPUT]	= &mmc1_output_clk.common.hw,
6348c2ecf20Sopenharmony_ci		[CLK_MMC2]		= &mmc2_clk.common.hw,
6358c2ecf20Sopenharmony_ci		[CLK_MMC2_SAMPLE]	= &mmc2_sample_clk.common.hw,
6368c2ecf20Sopenharmony_ci		[CLK_MMC2_OUTPUT]	= &mmc2_output_clk.common.hw,
6378c2ecf20Sopenharmony_ci		[CLK_SPI0]		= &spi0_clk.common.hw,
6388c2ecf20Sopenharmony_ci		[CLK_SPI1]		= &spi1_clk.common.hw,
6398c2ecf20Sopenharmony_ci		[CLK_I2S0]		= &i2s0_clk.common.hw,
6408c2ecf20Sopenharmony_ci		[CLK_I2S1]		= &i2s1_clk.common.hw,
6418c2ecf20Sopenharmony_ci		[CLK_USB_PHY0]		= &usb_phy0_clk.common.hw,
6428c2ecf20Sopenharmony_ci		[CLK_USB_PHY1]		= &usb_phy1_clk.common.hw,
6438c2ecf20Sopenharmony_ci		[CLK_USB_HSIC]		= &usb_hsic_clk.common.hw,
6448c2ecf20Sopenharmony_ci		[CLK_USB_HSIC_12M]	= &usb_hsic_12M_clk.common.hw,
6458c2ecf20Sopenharmony_ci		[CLK_USB_OHCI]		= &usb_ohci_clk.common.hw,
6468c2ecf20Sopenharmony_ci		[CLK_DRAM_VE]		= &dram_ve_clk.common.hw,
6478c2ecf20Sopenharmony_ci		[CLK_DRAM_CSI]		= &dram_csi_clk.common.hw,
6488c2ecf20Sopenharmony_ci		[CLK_DRAM_DRC]		= &dram_drc_clk.common.hw,
6498c2ecf20Sopenharmony_ci		[CLK_DRAM_DE_FE]	= &dram_de_fe_clk.common.hw,
6508c2ecf20Sopenharmony_ci		[CLK_DRAM_DE_BE]	= &dram_de_be_clk.common.hw,
6518c2ecf20Sopenharmony_ci		[CLK_DE_BE]		= &de_be_clk.common.hw,
6528c2ecf20Sopenharmony_ci		[CLK_DE_FE]		= &de_fe_clk.common.hw,
6538c2ecf20Sopenharmony_ci		[CLK_LCD_CH0]		= &lcd_ch0_clk.common.hw,
6548c2ecf20Sopenharmony_ci		[CLK_LCD_CH1]		= &lcd_ch1_clk.common.hw,
6558c2ecf20Sopenharmony_ci		[CLK_CSI_SCLK]		= &csi_sclk_clk.common.hw,
6568c2ecf20Sopenharmony_ci		[CLK_CSI_MCLK]		= &csi_mclk_clk.common.hw,
6578c2ecf20Sopenharmony_ci		[CLK_VE]		= &ve_clk.common.hw,
6588c2ecf20Sopenharmony_ci		[CLK_AC_DIG]		= &ac_dig_clk.common.hw,
6598c2ecf20Sopenharmony_ci		[CLK_AVS]		= &avs_clk.common.hw,
6608c2ecf20Sopenharmony_ci		[CLK_MBUS]		= &mbus_clk.common.hw,
6618c2ecf20Sopenharmony_ci		[CLK_DSI_SCLK]		= &dsi_sclk_clk.common.hw,
6628c2ecf20Sopenharmony_ci		[CLK_DSI_DPHY]		= &dsi_dphy_clk.common.hw,
6638c2ecf20Sopenharmony_ci		[CLK_DRC]		= &drc_clk.common.hw,
6648c2ecf20Sopenharmony_ci		[CLK_GPU]		= &gpu_clk.common.hw,
6658c2ecf20Sopenharmony_ci		[CLK_ATS]		= &ats_clk.common.hw,
6668c2ecf20Sopenharmony_ci	},
6678c2ecf20Sopenharmony_ci	.num	= CLK_NUMBER,
6688c2ecf20Sopenharmony_ci};
6698c2ecf20Sopenharmony_ci
6708c2ecf20Sopenharmony_cistatic struct ccu_reset_map sun8i_a23_ccu_resets[] = {
6718c2ecf20Sopenharmony_ci	[RST_USB_PHY0]		=  { 0x0cc, BIT(0) },
6728c2ecf20Sopenharmony_ci	[RST_USB_PHY1]		=  { 0x0cc, BIT(1) },
6738c2ecf20Sopenharmony_ci	[RST_USB_HSIC]		=  { 0x0cc, BIT(2) },
6748c2ecf20Sopenharmony_ci
6758c2ecf20Sopenharmony_ci	[RST_MBUS]		=  { 0x0fc, BIT(31) },
6768c2ecf20Sopenharmony_ci
6778c2ecf20Sopenharmony_ci	[RST_BUS_MIPI_DSI]	=  { 0x2c0, BIT(1) },
6788c2ecf20Sopenharmony_ci	[RST_BUS_DMA]		=  { 0x2c0, BIT(6) },
6798c2ecf20Sopenharmony_ci	[RST_BUS_MMC0]		=  { 0x2c0, BIT(8) },
6808c2ecf20Sopenharmony_ci	[RST_BUS_MMC1]		=  { 0x2c0, BIT(9) },
6818c2ecf20Sopenharmony_ci	[RST_BUS_MMC2]		=  { 0x2c0, BIT(10) },
6828c2ecf20Sopenharmony_ci	[RST_BUS_NAND]		=  { 0x2c0, BIT(13) },
6838c2ecf20Sopenharmony_ci	[RST_BUS_DRAM]		=  { 0x2c0, BIT(14) },
6848c2ecf20Sopenharmony_ci	[RST_BUS_HSTIMER]	=  { 0x2c0, BIT(19) },
6858c2ecf20Sopenharmony_ci	[RST_BUS_SPI0]		=  { 0x2c0, BIT(20) },
6868c2ecf20Sopenharmony_ci	[RST_BUS_SPI1]		=  { 0x2c0, BIT(21) },
6878c2ecf20Sopenharmony_ci	[RST_BUS_OTG]		=  { 0x2c0, BIT(24) },
6888c2ecf20Sopenharmony_ci	[RST_BUS_EHCI]		=  { 0x2c0, BIT(26) },
6898c2ecf20Sopenharmony_ci	[RST_BUS_OHCI]		=  { 0x2c0, BIT(29) },
6908c2ecf20Sopenharmony_ci
6918c2ecf20Sopenharmony_ci	[RST_BUS_VE]		=  { 0x2c4, BIT(0) },
6928c2ecf20Sopenharmony_ci	[RST_BUS_LCD]		=  { 0x2c4, BIT(4) },
6938c2ecf20Sopenharmony_ci	[RST_BUS_CSI]		=  { 0x2c4, BIT(8) },
6948c2ecf20Sopenharmony_ci	[RST_BUS_DE_BE]		=  { 0x2c4, BIT(12) },
6958c2ecf20Sopenharmony_ci	[RST_BUS_DE_FE]		=  { 0x2c4, BIT(14) },
6968c2ecf20Sopenharmony_ci	[RST_BUS_GPU]		=  { 0x2c4, BIT(20) },
6978c2ecf20Sopenharmony_ci	[RST_BUS_MSGBOX]	=  { 0x2c4, BIT(21) },
6988c2ecf20Sopenharmony_ci	[RST_BUS_SPINLOCK]	=  { 0x2c4, BIT(22) },
6998c2ecf20Sopenharmony_ci	[RST_BUS_DRC]		=  { 0x2c4, BIT(25) },
7008c2ecf20Sopenharmony_ci
7018c2ecf20Sopenharmony_ci	[RST_BUS_LVDS]		=  { 0x2c8, BIT(0) },
7028c2ecf20Sopenharmony_ci
7038c2ecf20Sopenharmony_ci	[RST_BUS_CODEC]		=  { 0x2d0, BIT(0) },
7048c2ecf20Sopenharmony_ci	[RST_BUS_I2S0]		=  { 0x2d0, BIT(12) },
7058c2ecf20Sopenharmony_ci	[RST_BUS_I2S1]		=  { 0x2d0, BIT(13) },
7068c2ecf20Sopenharmony_ci
7078c2ecf20Sopenharmony_ci	[RST_BUS_I2C0]		=  { 0x2d8, BIT(0) },
7088c2ecf20Sopenharmony_ci	[RST_BUS_I2C1]		=  { 0x2d8, BIT(1) },
7098c2ecf20Sopenharmony_ci	[RST_BUS_I2C2]		=  { 0x2d8, BIT(2) },
7108c2ecf20Sopenharmony_ci	[RST_BUS_UART0]		=  { 0x2d8, BIT(16) },
7118c2ecf20Sopenharmony_ci	[RST_BUS_UART1]		=  { 0x2d8, BIT(17) },
7128c2ecf20Sopenharmony_ci	[RST_BUS_UART2]		=  { 0x2d8, BIT(18) },
7138c2ecf20Sopenharmony_ci	[RST_BUS_UART3]		=  { 0x2d8, BIT(19) },
7148c2ecf20Sopenharmony_ci	[RST_BUS_UART4]		=  { 0x2d8, BIT(20) },
7158c2ecf20Sopenharmony_ci};
7168c2ecf20Sopenharmony_ci
7178c2ecf20Sopenharmony_cistatic const struct sunxi_ccu_desc sun8i_a23_ccu_desc = {
7188c2ecf20Sopenharmony_ci	.ccu_clks	= sun8i_a23_ccu_clks,
7198c2ecf20Sopenharmony_ci	.num_ccu_clks	= ARRAY_SIZE(sun8i_a23_ccu_clks),
7208c2ecf20Sopenharmony_ci
7218c2ecf20Sopenharmony_ci	.hw_clks	= &sun8i_a23_hw_clks,
7228c2ecf20Sopenharmony_ci
7238c2ecf20Sopenharmony_ci	.resets		= sun8i_a23_ccu_resets,
7248c2ecf20Sopenharmony_ci	.num_resets	= ARRAY_SIZE(sun8i_a23_ccu_resets),
7258c2ecf20Sopenharmony_ci};
7268c2ecf20Sopenharmony_ci
7278c2ecf20Sopenharmony_cistatic void __init sun8i_a23_ccu_setup(struct device_node *node)
7288c2ecf20Sopenharmony_ci{
7298c2ecf20Sopenharmony_ci	void __iomem *reg;
7308c2ecf20Sopenharmony_ci	u32 val;
7318c2ecf20Sopenharmony_ci
7328c2ecf20Sopenharmony_ci	reg = of_io_request_and_map(node, 0, of_node_full_name(node));
7338c2ecf20Sopenharmony_ci	if (IS_ERR(reg)) {
7348c2ecf20Sopenharmony_ci		pr_err("%pOF: Could not map the clock registers\n", node);
7358c2ecf20Sopenharmony_ci		return;
7368c2ecf20Sopenharmony_ci	}
7378c2ecf20Sopenharmony_ci
7388c2ecf20Sopenharmony_ci	/* Force the PLL-Audio-1x divider to 1 */
7398c2ecf20Sopenharmony_ci	val = readl(reg + SUN8I_A23_PLL_AUDIO_REG);
7408c2ecf20Sopenharmony_ci	val &= ~GENMASK(19, 16);
7418c2ecf20Sopenharmony_ci	writel(val | (0 << 16), reg + SUN8I_A23_PLL_AUDIO_REG);
7428c2ecf20Sopenharmony_ci
7438c2ecf20Sopenharmony_ci	/* Force PLL-MIPI to MIPI mode */
7448c2ecf20Sopenharmony_ci	val = readl(reg + SUN8I_A23_PLL_MIPI_REG);
7458c2ecf20Sopenharmony_ci	val &= ~BIT(16);
7468c2ecf20Sopenharmony_ci	writel(val, reg + SUN8I_A23_PLL_MIPI_REG);
7478c2ecf20Sopenharmony_ci
7488c2ecf20Sopenharmony_ci	sunxi_ccu_probe(node, reg, &sun8i_a23_ccu_desc);
7498c2ecf20Sopenharmony_ci}
7508c2ecf20Sopenharmony_ciCLK_OF_DECLARE(sun8i_a23_ccu, "allwinner,sun8i-a23-ccu",
7518c2ecf20Sopenharmony_ci	       sun8i_a23_ccu_setup);
752