162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0+
262306a36Sopenharmony_ci/*
362306a36Sopenharmony_ci * Copyright (C) 2016 Freescale Semiconductor, Inc.
462306a36Sopenharmony_ci * Copyright 2017~2018 NXP
562306a36Sopenharmony_ci *
662306a36Sopenharmony_ci * Author: Dong Aisheng <aisheng.dong@nxp.com>
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci */
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <dt-bindings/clock/imx7ulp-clock.h>
1162306a36Sopenharmony_ci#include <linux/clk-provider.h>
1262306a36Sopenharmony_ci#include <linux/err.h>
1362306a36Sopenharmony_ci#include <linux/init.h>
1462306a36Sopenharmony_ci#include <linux/io.h>
1562306a36Sopenharmony_ci#include <linux/of.h>
1662306a36Sopenharmony_ci#include <linux/of_address.h>
1762306a36Sopenharmony_ci#include <linux/platform_device.h>
1862306a36Sopenharmony_ci#include <linux/slab.h>
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci#include "clk.h"
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_cistatic const char * const pll_pre_sels[]	= { "sosc", "firc", };
2362306a36Sopenharmony_cistatic const char * const spll_pfd_sels[]	= { "spll_pfd0", "spll_pfd1", "spll_pfd2", "spll_pfd3", };
2462306a36Sopenharmony_cistatic const char * const spll_sels[]		= { "spll", "spll_pfd_sel", };
2562306a36Sopenharmony_cistatic const char * const apll_pfd_sels[]	= { "apll_pfd0", "apll_pfd1", "apll_pfd2", "apll_pfd3", };
2662306a36Sopenharmony_cistatic const char * const apll_sels[]		= { "apll", "apll_pfd_sel", };
2762306a36Sopenharmony_cistatic const char * const scs_sels[]		= { "dummy", "sosc", "sirc", "firc", "dummy", "apll_sel", "spll_sel", "dummy", };
2862306a36Sopenharmony_cistatic const char * const ddr_sels[]		= { "apll_pfd_sel", "dummy", "dummy", "dummy", };
2962306a36Sopenharmony_cistatic const char * const nic_sels[]		= { "firc", "ddr_clk", };
3062306a36Sopenharmony_cistatic const char * const periph_plat_sels[]	= { "dummy", "nic1_bus_clk", "nic1_clk", "ddr_clk", "apll_pfd2", "apll_pfd1", "apll_pfd0", "upll", };
3162306a36Sopenharmony_cistatic const char * const periph_bus_sels[]	= { "dummy", "sosc_bus_clk", "dummy", "firc_bus_clk", "rosc", "nic1_bus_clk", "nic1_clk", "spll_bus_clk", };
3262306a36Sopenharmony_cistatic const char * const arm_sels[]		= { "core", "dummy", "dummy", "hsrun_core", };
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci/* used by sosc/sirc/firc/ddr/spll/apll dividers */
3562306a36Sopenharmony_cistatic const struct clk_div_table ulp_div_table[] = {
3662306a36Sopenharmony_ci	{ .val = 1, .div = 1, },
3762306a36Sopenharmony_ci	{ .val = 2, .div = 2, },
3862306a36Sopenharmony_ci	{ .val = 3, .div = 4, },
3962306a36Sopenharmony_ci	{ .val = 4, .div = 8, },
4062306a36Sopenharmony_ci	{ .val = 5, .div = 16, },
4162306a36Sopenharmony_ci	{ .val = 6, .div = 32, },
4262306a36Sopenharmony_ci	{ .val = 7, .div = 64, },
4362306a36Sopenharmony_ci	{ /* sentinel */ },
4462306a36Sopenharmony_ci};
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_cistatic void __init imx7ulp_clk_scg1_init(struct device_node *np)
4762306a36Sopenharmony_ci{
4862306a36Sopenharmony_ci	struct clk_hw_onecell_data *clk_data;
4962306a36Sopenharmony_ci	struct clk_hw **hws;
5062306a36Sopenharmony_ci	void __iomem *base;
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_SCG1_END),
5362306a36Sopenharmony_ci			   GFP_KERNEL);
5462306a36Sopenharmony_ci	if (!clk_data)
5562306a36Sopenharmony_ci		return;
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci	clk_data->num = IMX7ULP_CLK_SCG1_END;
5862306a36Sopenharmony_ci	hws = clk_data->hws;
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci	hws[IMX7ULP_CLK_DUMMY]		= imx_clk_hw_fixed("dummy", 0);
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ci	hws[IMX7ULP_CLK_ROSC]		= imx_get_clk_hw_by_name(np, "rosc");
6362306a36Sopenharmony_ci	hws[IMX7ULP_CLK_SOSC]		= imx_get_clk_hw_by_name(np, "sosc");
6462306a36Sopenharmony_ci	hws[IMX7ULP_CLK_SIRC]		= imx_get_clk_hw_by_name(np, "sirc");
6562306a36Sopenharmony_ci	hws[IMX7ULP_CLK_FIRC]		= imx_get_clk_hw_by_name(np, "firc");
6662306a36Sopenharmony_ci	hws[IMX7ULP_CLK_UPLL]		= imx_get_clk_hw_by_name(np, "upll");
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci	/* SCG1 */
6962306a36Sopenharmony_ci	base = of_iomap(np, 0);
7062306a36Sopenharmony_ci	WARN_ON(!base);
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci	/* NOTE: xPLL config can't be changed when xPLL is enabled */
7362306a36Sopenharmony_ci	hws[IMX7ULP_CLK_APLL_PRE_SEL]	= imx_clk_hw_mux_flags("apll_pre_sel", base + 0x508, 0, 1, pll_pre_sels, ARRAY_SIZE(pll_pre_sels), CLK_SET_PARENT_GATE);
7462306a36Sopenharmony_ci	hws[IMX7ULP_CLK_SPLL_PRE_SEL]	= imx_clk_hw_mux_flags("spll_pre_sel", base + 0x608, 0, 1, pll_pre_sels, ARRAY_SIZE(pll_pre_sels), CLK_SET_PARENT_GATE);
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci	/*							   name		    parent_name	   reg			shift	width	flags */
7762306a36Sopenharmony_ci	hws[IMX7ULP_CLK_APLL_PRE_DIV]	= imx_clk_hw_divider_flags("apll_pre_div", "apll_pre_sel", base + 0x508,	8,	3,	CLK_SET_RATE_GATE);
7862306a36Sopenharmony_ci	hws[IMX7ULP_CLK_SPLL_PRE_DIV]	= imx_clk_hw_divider_flags("spll_pre_div", "spll_pre_sel", base + 0x608,	8,	3,	CLK_SET_RATE_GATE);
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci	/*						name	 parent_name	 base */
8162306a36Sopenharmony_ci	hws[IMX7ULP_CLK_APLL]		= imx_clk_hw_pllv4(IMX_PLLV4_IMX7ULP, "apll",  "apll_pre_div", base + 0x500);
8262306a36Sopenharmony_ci	hws[IMX7ULP_CLK_SPLL]		= imx_clk_hw_pllv4(IMX_PLLV4_IMX7ULP, "spll",  "spll_pre_div", base + 0x600);
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci	/* APLL PFDs */
8562306a36Sopenharmony_ci	hws[IMX7ULP_CLK_APLL_PFD0]	= imx_clk_hw_pfdv2(IMX_PFDV2_IMX7ULP, "apll_pfd0", "apll", base + 0x50c, 0);
8662306a36Sopenharmony_ci	hws[IMX7ULP_CLK_APLL_PFD1]	= imx_clk_hw_pfdv2(IMX_PFDV2_IMX7ULP, "apll_pfd1", "apll", base + 0x50c, 1);
8762306a36Sopenharmony_ci	hws[IMX7ULP_CLK_APLL_PFD2]	= imx_clk_hw_pfdv2(IMX_PFDV2_IMX7ULP, "apll_pfd2", "apll", base + 0x50c, 2);
8862306a36Sopenharmony_ci	hws[IMX7ULP_CLK_APLL_PFD3]	= imx_clk_hw_pfdv2(IMX_PFDV2_IMX7ULP, "apll_pfd3", "apll", base + 0x50c, 3);
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci	/* SPLL PFDs */
9162306a36Sopenharmony_ci	hws[IMX7ULP_CLK_SPLL_PFD0]	= imx_clk_hw_pfdv2(IMX_PFDV2_IMX7ULP, "spll_pfd0", "spll", base + 0x60C, 0);
9262306a36Sopenharmony_ci	hws[IMX7ULP_CLK_SPLL_PFD1]	= imx_clk_hw_pfdv2(IMX_PFDV2_IMX7ULP, "spll_pfd1", "spll", base + 0x60C, 1);
9362306a36Sopenharmony_ci	hws[IMX7ULP_CLK_SPLL_PFD2]	= imx_clk_hw_pfdv2(IMX_PFDV2_IMX7ULP, "spll_pfd2", "spll", base + 0x60C, 2);
9462306a36Sopenharmony_ci	hws[IMX7ULP_CLK_SPLL_PFD3]	= imx_clk_hw_pfdv2(IMX_PFDV2_IMX7ULP, "spll_pfd3", "spll", base + 0x60C, 3);
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci	/* PLL Mux */
9762306a36Sopenharmony_ci	hws[IMX7ULP_CLK_APLL_PFD_SEL]	= imx_clk_hw_mux_flags("apll_pfd_sel", base + 0x508, 14, 2, apll_pfd_sels, ARRAY_SIZE(apll_pfd_sels), CLK_SET_RATE_PARENT | CLK_SET_PARENT_GATE);
9862306a36Sopenharmony_ci	hws[IMX7ULP_CLK_SPLL_PFD_SEL]	= imx_clk_hw_mux_flags("spll_pfd_sel", base + 0x608, 14, 2, spll_pfd_sels, ARRAY_SIZE(spll_pfd_sels), CLK_SET_RATE_PARENT | CLK_SET_PARENT_GATE);
9962306a36Sopenharmony_ci	hws[IMX7ULP_CLK_APLL_SEL]	= imx_clk_hw_mux_flags("apll_sel", base + 0x508, 1, 1, apll_sels, ARRAY_SIZE(apll_sels), CLK_SET_RATE_PARENT | CLK_SET_PARENT_GATE);
10062306a36Sopenharmony_ci	hws[IMX7ULP_CLK_SPLL_SEL]	= imx_clk_hw_mux_flags("spll_sel", base + 0x608, 1, 1, spll_sels, ARRAY_SIZE(spll_sels), CLK_SET_RATE_PARENT | CLK_SET_PARENT_GATE);
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci	hws[IMX7ULP_CLK_SPLL_BUS_CLK]	= imx_clk_hw_divider_gate("spll_bus_clk", "spll_sel", CLK_SET_RATE_GATE, base + 0x604, 8, 3, 0, ulp_div_table, &imx_ccm_lock);
10362306a36Sopenharmony_ci
10462306a36Sopenharmony_ci	/* scs/ddr/nic select different clock source requires that clock to be enabled first */
10562306a36Sopenharmony_ci	hws[IMX7ULP_CLK_SYS_SEL]	= imx_clk_hw_mux2("scs_sel", base + 0x14, 24, 4, scs_sels, ARRAY_SIZE(scs_sels));
10662306a36Sopenharmony_ci	hws[IMX7ULP_CLK_HSRUN_SYS_SEL] = imx_clk_hw_mux2("hsrun_scs_sel", base + 0x1c, 24, 4, scs_sels, ARRAY_SIZE(scs_sels));
10762306a36Sopenharmony_ci	hws[IMX7ULP_CLK_NIC_SEL]	= imx_clk_hw_mux2("nic_sel", base + 0x40, 28, 1, nic_sels, ARRAY_SIZE(nic_sels));
10862306a36Sopenharmony_ci	hws[IMX7ULP_CLK_DDR_SEL]	= imx_clk_hw_mux_flags("ddr_sel", base + 0x30, 24, 2, ddr_sels, ARRAY_SIZE(ddr_sels), CLK_SET_RATE_PARENT | CLK_OPS_PARENT_ENABLE);
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci	hws[IMX7ULP_CLK_CORE_DIV]	= imx_clk_hw_divider_flags("divcore",	"scs_sel",  base + 0x14, 16, 4, CLK_SET_RATE_PARENT);
11162306a36Sopenharmony_ci	hws[IMX7ULP_CLK_CORE]		= imx_clk_hw_cpu("core", "divcore", hws[IMX7ULP_CLK_CORE_DIV]->clk, hws[IMX7ULP_CLK_SYS_SEL]->clk, hws[IMX7ULP_CLK_SPLL_SEL]->clk, hws[IMX7ULP_CLK_FIRC]->clk);
11262306a36Sopenharmony_ci	hws[IMX7ULP_CLK_HSRUN_CORE_DIV] = imx_clk_hw_divider_flags("hsrun_divcore", "hsrun_scs_sel", base + 0x1c, 16, 4, CLK_SET_RATE_PARENT);
11362306a36Sopenharmony_ci	hws[IMX7ULP_CLK_HSRUN_CORE] = imx_clk_hw_cpu("hsrun_core", "hsrun_divcore", hws[IMX7ULP_CLK_HSRUN_CORE_DIV]->clk, hws[IMX7ULP_CLK_HSRUN_SYS_SEL]->clk, hws[IMX7ULP_CLK_SPLL_SEL]->clk, hws[IMX7ULP_CLK_FIRC]->clk);
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ci	hws[IMX7ULP_CLK_DDR_DIV]	= imx_clk_hw_divider_gate("ddr_clk", "ddr_sel", CLK_SET_RATE_PARENT | CLK_IS_CRITICAL, base + 0x30, 0, 3,
11662306a36Sopenharmony_ci							       0, ulp_div_table, &imx_ccm_lock);
11762306a36Sopenharmony_ci
11862306a36Sopenharmony_ci	hws[IMX7ULP_CLK_NIC0_DIV]	= imx_clk_hw_divider_flags("nic0_clk",		"nic_sel",  base + 0x40, 24, 4, CLK_SET_RATE_PARENT | CLK_IS_CRITICAL);
11962306a36Sopenharmony_ci	hws[IMX7ULP_CLK_NIC1_DIV]	= imx_clk_hw_divider_flags("nic1_clk",		"nic0_clk", base + 0x40, 16, 4, CLK_SET_RATE_PARENT | CLK_IS_CRITICAL);
12062306a36Sopenharmony_ci	hws[IMX7ULP_CLK_NIC1_BUS_DIV]	= imx_clk_hw_divider_flags("nic1_bus_clk",	"nic0_clk", base + 0x40, 4,  4, CLK_SET_RATE_PARENT | CLK_IS_CRITICAL);
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci	hws[IMX7ULP_CLK_GPU_DIV]	= imx_clk_hw_divider("gpu_clk", "nic0_clk", base + 0x40, 20, 4);
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci	hws[IMX7ULP_CLK_SOSC_BUS_CLK]	= imx_clk_hw_divider_gate("sosc_bus_clk", "sosc", 0, base + 0x104, 8, 3,
12562306a36Sopenharmony_ci							       CLK_DIVIDER_READ_ONLY, ulp_div_table, &imx_ccm_lock);
12662306a36Sopenharmony_ci	hws[IMX7ULP_CLK_FIRC_BUS_CLK]	= imx_clk_hw_divider_gate("firc_bus_clk", "firc", 0, base + 0x304, 8, 3,
12762306a36Sopenharmony_ci							       CLK_DIVIDER_READ_ONLY, ulp_div_table, &imx_ccm_lock);
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci	imx_check_clk_hws(hws, clk_data->num);
13062306a36Sopenharmony_ci
13162306a36Sopenharmony_ci	of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
13262306a36Sopenharmony_ci}
13362306a36Sopenharmony_ciCLK_OF_DECLARE(imx7ulp_clk_scg1, "fsl,imx7ulp-scg1", imx7ulp_clk_scg1_init);
13462306a36Sopenharmony_ci
13562306a36Sopenharmony_cistatic void __init imx7ulp_clk_pcc2_init(struct device_node *np)
13662306a36Sopenharmony_ci{
13762306a36Sopenharmony_ci	struct clk_hw_onecell_data *clk_data;
13862306a36Sopenharmony_ci	struct clk_hw **hws;
13962306a36Sopenharmony_ci	void __iomem *base;
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_PCC2_END),
14262306a36Sopenharmony_ci			   GFP_KERNEL);
14362306a36Sopenharmony_ci	if (!clk_data)
14462306a36Sopenharmony_ci		return;
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ci	clk_data->num = IMX7ULP_CLK_PCC2_END;
14762306a36Sopenharmony_ci	hws = clk_data->hws;
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci	/* PCC2 */
15062306a36Sopenharmony_ci	base = of_iomap(np, 0);
15162306a36Sopenharmony_ci	WARN_ON(!base);
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ci	hws[IMX7ULP_CLK_DMA1]		= imx_clk_hw_gate("dma1", "nic1_clk", base + 0x20, 30);
15462306a36Sopenharmony_ci	hws[IMX7ULP_CLK_RGPIO2P1]	= imx_clk_hw_gate("rgpio2p1", "nic1_bus_clk", base + 0x3c, 30);
15562306a36Sopenharmony_ci	hws[IMX7ULP_CLK_DMA_MUX1]	= imx_clk_hw_gate("dma_mux1", "nic1_bus_clk", base + 0x84, 30);
15662306a36Sopenharmony_ci	hws[IMX7ULP_CLK_CAAM]		= imx_clk_hw_gate("caam", "nic1_clk", base + 0x90, 30);
15762306a36Sopenharmony_ci	hws[IMX7ULP_CLK_LPTPM4]		= imx7ulp_clk_hw_composite("lptpm4",  periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, false, true, base + 0x94);
15862306a36Sopenharmony_ci	hws[IMX7ULP_CLK_LPTPM5]		= imx7ulp_clk_hw_composite("lptpm5",  periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, false, true, base + 0x98);
15962306a36Sopenharmony_ci	hws[IMX7ULP_CLK_LPIT1]		= imx7ulp_clk_hw_composite("lpit1",   periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, false, true, base + 0x9c);
16062306a36Sopenharmony_ci	hws[IMX7ULP_CLK_LPSPI2]		= imx7ulp_clk_hw_composite("lpspi2",  periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, false, true, base + 0xa4);
16162306a36Sopenharmony_ci	hws[IMX7ULP_CLK_LPSPI3]		= imx7ulp_clk_hw_composite("lpspi3",  periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, false, true, base + 0xa8);
16262306a36Sopenharmony_ci	hws[IMX7ULP_CLK_LPI2C4]		= imx7ulp_clk_hw_composite("lpi2c4",  periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, false, true, base + 0xac);
16362306a36Sopenharmony_ci	hws[IMX7ULP_CLK_LPI2C5]		= imx7ulp_clk_hw_composite("lpi2c5",  periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, false, true, base + 0xb0);
16462306a36Sopenharmony_ci	hws[IMX7ULP_CLK_LPUART4]	= imx7ulp_clk_hw_composite("lpuart4", periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, false, true, base + 0xb4);
16562306a36Sopenharmony_ci	hws[IMX7ULP_CLK_LPUART5]	= imx7ulp_clk_hw_composite("lpuart5", periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, false, true, base + 0xb8);
16662306a36Sopenharmony_ci	hws[IMX7ULP_CLK_FLEXIO1]	= imx7ulp_clk_hw_composite("flexio1", periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, false, true, base + 0xc4);
16762306a36Sopenharmony_ci	hws[IMX7ULP_CLK_USB0]		= imx7ulp_clk_hw_composite("usb0",    periph_plat_sels, ARRAY_SIZE(periph_plat_sels), true, true,  true, base + 0xcc);
16862306a36Sopenharmony_ci	hws[IMX7ULP_CLK_USB1]		= imx7ulp_clk_hw_composite("usb1",    periph_plat_sels, ARRAY_SIZE(periph_plat_sels), true, true,  true, base + 0xd0);
16962306a36Sopenharmony_ci	hws[IMX7ULP_CLK_USB_PHY]	= imx_clk_hw_gate("usb_phy", "nic1_bus_clk", base + 0xd4, 30);
17062306a36Sopenharmony_ci	hws[IMX7ULP_CLK_USDHC0]		= imx7ulp_clk_hw_composite("usdhc0",  periph_plat_sels, ARRAY_SIZE(periph_plat_sels), true, true,  true, base + 0xdc);
17162306a36Sopenharmony_ci	hws[IMX7ULP_CLK_USDHC1]		= imx7ulp_clk_hw_composite("usdhc1",  periph_plat_sels, ARRAY_SIZE(periph_plat_sels), true, true,  true, base + 0xe0);
17262306a36Sopenharmony_ci	hws[IMX7ULP_CLK_WDG1]		= imx7ulp_clk_hw_composite("wdg1",    periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, true,  true, base + 0xf4);
17362306a36Sopenharmony_ci	hws[IMX7ULP_CLK_WDG2]		= imx7ulp_clk_hw_composite("wdg2",    periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, true,  true, base + 0x10c);
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci	imx_check_clk_hws(hws, clk_data->num);
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ci	of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
17862306a36Sopenharmony_ci
17962306a36Sopenharmony_ci	imx_register_uart_clocks();
18062306a36Sopenharmony_ci}
18162306a36Sopenharmony_ciCLK_OF_DECLARE(imx7ulp_clk_pcc2, "fsl,imx7ulp-pcc2", imx7ulp_clk_pcc2_init);
18262306a36Sopenharmony_ci
18362306a36Sopenharmony_cistatic void __init imx7ulp_clk_pcc3_init(struct device_node *np)
18462306a36Sopenharmony_ci{
18562306a36Sopenharmony_ci	struct clk_hw_onecell_data *clk_data;
18662306a36Sopenharmony_ci	struct clk_hw **hws;
18762306a36Sopenharmony_ci	void __iomem *base;
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_PCC3_END),
19062306a36Sopenharmony_ci			   GFP_KERNEL);
19162306a36Sopenharmony_ci	if (!clk_data)
19262306a36Sopenharmony_ci		return;
19362306a36Sopenharmony_ci
19462306a36Sopenharmony_ci	clk_data->num = IMX7ULP_CLK_PCC3_END;
19562306a36Sopenharmony_ci	hws = clk_data->hws;
19662306a36Sopenharmony_ci
19762306a36Sopenharmony_ci	/* PCC3 */
19862306a36Sopenharmony_ci	base = of_iomap(np, 0);
19962306a36Sopenharmony_ci	WARN_ON(!base);
20062306a36Sopenharmony_ci
20162306a36Sopenharmony_ci	hws[IMX7ULP_CLK_LPTPM6]	= imx7ulp_clk_hw_composite("lptpm6",  periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, false, true, base + 0x84);
20262306a36Sopenharmony_ci	hws[IMX7ULP_CLK_LPTPM7]	= imx7ulp_clk_hw_composite("lptpm7",  periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, false, true, base + 0x88);
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ci	hws[IMX7ULP_CLK_MMDC]		= clk_hw_register_gate(NULL, "mmdc", "nic1_clk", CLK_SET_RATE_PARENT | CLK_IS_CRITICAL,
20562306a36Sopenharmony_ci							       base + 0xac, 30, 0, &imx_ccm_lock);
20662306a36Sopenharmony_ci	hws[IMX7ULP_CLK_LPI2C6]	= imx7ulp_clk_hw_composite("lpi2c6",  periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, false, true, base + 0x90);
20762306a36Sopenharmony_ci	hws[IMX7ULP_CLK_LPI2C7]	= imx7ulp_clk_hw_composite("lpi2c7",  periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, false, true, base + 0x94);
20862306a36Sopenharmony_ci	hws[IMX7ULP_CLK_LPUART6]	= imx7ulp_clk_hw_composite("lpuart6", periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, false, true, base + 0x98);
20962306a36Sopenharmony_ci	hws[IMX7ULP_CLK_LPUART7]	= imx7ulp_clk_hw_composite("lpuart7", periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, false, true, base + 0x9c);
21062306a36Sopenharmony_ci	hws[IMX7ULP_CLK_DSI]		= imx7ulp_clk_hw_composite("dsi",     periph_bus_sels, ARRAY_SIZE(periph_bus_sels), true, true,  true, base + 0xa4);
21162306a36Sopenharmony_ci	hws[IMX7ULP_CLK_LCDIF]		= imx7ulp_clk_hw_composite("lcdif",   periph_plat_sels, ARRAY_SIZE(periph_plat_sels), true, true,  true, base + 0xa8);
21262306a36Sopenharmony_ci
21362306a36Sopenharmony_ci	hws[IMX7ULP_CLK_VIU]		= imx_clk_hw_gate("viu",   "nic1_clk",	   base + 0xa0, 30);
21462306a36Sopenharmony_ci	hws[IMX7ULP_CLK_PCTLC]		= imx_clk_hw_gate("pctlc", "nic1_bus_clk", base + 0xb8, 30);
21562306a36Sopenharmony_ci	hws[IMX7ULP_CLK_PCTLD]		= imx_clk_hw_gate("pctld", "nic1_bus_clk", base + 0xbc, 30);
21662306a36Sopenharmony_ci	hws[IMX7ULP_CLK_PCTLE]		= imx_clk_hw_gate("pctle", "nic1_bus_clk", base + 0xc0, 30);
21762306a36Sopenharmony_ci	hws[IMX7ULP_CLK_PCTLF]		= imx_clk_hw_gate("pctlf", "nic1_bus_clk", base + 0xc4, 30);
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci	hws[IMX7ULP_CLK_GPU3D]		= imx7ulp_clk_hw_composite("gpu3d",   periph_plat_sels, ARRAY_SIZE(periph_plat_sels), true, false, true, base + 0x140);
22062306a36Sopenharmony_ci	hws[IMX7ULP_CLK_GPU2D]		= imx7ulp_clk_hw_composite("gpu2d",   periph_plat_sels, ARRAY_SIZE(periph_plat_sels), true, false, true, base + 0x144);
22162306a36Sopenharmony_ci
22262306a36Sopenharmony_ci	imx_check_clk_hws(hws, clk_data->num);
22362306a36Sopenharmony_ci
22462306a36Sopenharmony_ci	of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_ci	imx_register_uart_clocks();
22762306a36Sopenharmony_ci}
22862306a36Sopenharmony_ciCLK_OF_DECLARE(imx7ulp_clk_pcc3, "fsl,imx7ulp-pcc3", imx7ulp_clk_pcc3_init);
22962306a36Sopenharmony_ci
23062306a36Sopenharmony_cistatic void __init imx7ulp_clk_smc1_init(struct device_node *np)
23162306a36Sopenharmony_ci{
23262306a36Sopenharmony_ci	struct clk_hw_onecell_data *clk_data;
23362306a36Sopenharmony_ci	struct clk_hw **hws;
23462306a36Sopenharmony_ci	void __iomem *base;
23562306a36Sopenharmony_ci
23662306a36Sopenharmony_ci	clk_data = kzalloc(struct_size(clk_data, hws, IMX7ULP_CLK_SMC1_END),
23762306a36Sopenharmony_ci			   GFP_KERNEL);
23862306a36Sopenharmony_ci	if (!clk_data)
23962306a36Sopenharmony_ci		return;
24062306a36Sopenharmony_ci
24162306a36Sopenharmony_ci	clk_data->num = IMX7ULP_CLK_SMC1_END;
24262306a36Sopenharmony_ci	hws = clk_data->hws;
24362306a36Sopenharmony_ci
24462306a36Sopenharmony_ci	/* SMC1 */
24562306a36Sopenharmony_ci	base = of_iomap(np, 0);
24662306a36Sopenharmony_ci	WARN_ON(!base);
24762306a36Sopenharmony_ci
24862306a36Sopenharmony_ci	hws[IMX7ULP_CLK_ARM] = imx_clk_hw_mux_flags("arm", base + 0x10, 8, 2, arm_sels, ARRAY_SIZE(arm_sels), CLK_SET_RATE_PARENT);
24962306a36Sopenharmony_ci
25062306a36Sopenharmony_ci	imx_check_clk_hws(hws, clk_data->num);
25162306a36Sopenharmony_ci
25262306a36Sopenharmony_ci	of_clk_add_hw_provider(np, of_clk_hw_onecell_get, clk_data);
25362306a36Sopenharmony_ci}
25462306a36Sopenharmony_ciCLK_OF_DECLARE(imx7ulp_clk_smc1, "fsl,imx7ulp-smc1", imx7ulp_clk_smc1_init);
255