18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci *  Copyright (C) 2008 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#include <linux/clkdev.h>
78c2ecf20Sopenharmony_ci#include <linux/clk-provider.h>
88c2ecf20Sopenharmony_ci#include <linux/err.h>
98c2ecf20Sopenharmony_ci#include <linux/init.h>
108c2ecf20Sopenharmony_ci#include <linux/of.h>
118c2ecf20Sopenharmony_ci#include <linux/of_address.h>
128c2ecf20Sopenharmony_ci#include <dt-bindings/clock/imx1-clock.h>
138c2ecf20Sopenharmony_ci#include <soc/imx/timer.h>
148c2ecf20Sopenharmony_ci#include <asm/irq.h>
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ci#include "clk.h"
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci#define MX1_CCM_BASE_ADDR	0x0021b000
198c2ecf20Sopenharmony_ci#define MX1_TIM1_BASE_ADDR	0x00220000
208c2ecf20Sopenharmony_ci#define MX1_TIM1_INT		(NR_IRQS_LEGACY + 59)
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cistatic const char *prem_sel_clks[] = { "clk32_premult", "clk16m", };
238c2ecf20Sopenharmony_cistatic const char *clko_sel_clks[] = { "per1", "hclk", "clk48m", "clk16m",
248c2ecf20Sopenharmony_ci				       "prem", "fclk", };
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_cistatic struct clk *clk[IMX1_CLK_MAX];
278c2ecf20Sopenharmony_cistatic struct clk_onecell_data clk_data;
288c2ecf20Sopenharmony_ci
298c2ecf20Sopenharmony_cistatic void __iomem *ccm __initdata;
308c2ecf20Sopenharmony_ci#define CCM_CSCR	(ccm + 0x0000)
318c2ecf20Sopenharmony_ci#define CCM_MPCTL0	(ccm + 0x0004)
328c2ecf20Sopenharmony_ci#define CCM_SPCTL0	(ccm + 0x000c)
338c2ecf20Sopenharmony_ci#define CCM_PCDR	(ccm + 0x0020)
348c2ecf20Sopenharmony_ci#define SCM_GCCR	(ccm + 0x0810)
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistatic void __init mx1_clocks_init_dt(struct device_node *np)
378c2ecf20Sopenharmony_ci{
388c2ecf20Sopenharmony_ci	ccm = of_iomap(np, 0);
398c2ecf20Sopenharmony_ci	BUG_ON(!ccm);
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	clk[IMX1_CLK_DUMMY] = imx_clk_fixed("dummy", 0);
428c2ecf20Sopenharmony_ci	clk[IMX1_CLK_CLK32] = imx_obtain_fixed_clock("clk32", 32768);
438c2ecf20Sopenharmony_ci	clk[IMX1_CLK_CLK16M_EXT] = imx_clk_fixed("clk16m_ext", 16000000);
448c2ecf20Sopenharmony_ci	clk[IMX1_CLK_CLK16M] = imx_clk_gate("clk16m", "clk16m_ext", CCM_CSCR, 17);
458c2ecf20Sopenharmony_ci	clk[IMX1_CLK_CLK32_PREMULT] = imx_clk_fixed_factor("clk32_premult", "clk32", 512, 1);
468c2ecf20Sopenharmony_ci	clk[IMX1_CLK_PREM] = imx_clk_mux("prem", CCM_CSCR, 16, 1, prem_sel_clks, ARRAY_SIZE(prem_sel_clks));
478c2ecf20Sopenharmony_ci	clk[IMX1_CLK_MPLL] = imx_clk_pllv1(IMX_PLLV1_IMX1, "mpll", "clk32_premult", CCM_MPCTL0);
488c2ecf20Sopenharmony_ci	clk[IMX1_CLK_MPLL_GATE] = imx_clk_gate("mpll_gate", "mpll", CCM_CSCR, 0);
498c2ecf20Sopenharmony_ci	clk[IMX1_CLK_SPLL] = imx_clk_pllv1(IMX_PLLV1_IMX1, "spll", "prem", CCM_SPCTL0);
508c2ecf20Sopenharmony_ci	clk[IMX1_CLK_SPLL_GATE] = imx_clk_gate("spll_gate", "spll", CCM_CSCR, 1);
518c2ecf20Sopenharmony_ci	clk[IMX1_CLK_MCU] = imx_clk_divider("mcu", "clk32_premult", CCM_CSCR, 15, 1);
528c2ecf20Sopenharmony_ci	clk[IMX1_CLK_FCLK] = imx_clk_divider("fclk", "mpll_gate", CCM_CSCR, 15, 1);
538c2ecf20Sopenharmony_ci	clk[IMX1_CLK_HCLK] = imx_clk_divider("hclk", "spll_gate", CCM_CSCR, 10, 4);
548c2ecf20Sopenharmony_ci	clk[IMX1_CLK_CLK48M] = imx_clk_divider("clk48m", "spll_gate", CCM_CSCR, 26, 3);
558c2ecf20Sopenharmony_ci	clk[IMX1_CLK_PER1] = imx_clk_divider("per1", "spll_gate", CCM_PCDR, 0, 4);
568c2ecf20Sopenharmony_ci	clk[IMX1_CLK_PER2] = imx_clk_divider("per2", "spll_gate", CCM_PCDR, 4, 4);
578c2ecf20Sopenharmony_ci	clk[IMX1_CLK_PER3] = imx_clk_divider("per3", "spll_gate", CCM_PCDR, 16, 7);
588c2ecf20Sopenharmony_ci	clk[IMX1_CLK_CLKO] = imx_clk_mux("clko", CCM_CSCR, 29, 3, clko_sel_clks, ARRAY_SIZE(clko_sel_clks));
598c2ecf20Sopenharmony_ci	clk[IMX1_CLK_UART3_GATE] = imx_clk_gate("uart3_gate", "hclk", SCM_GCCR, 6);
608c2ecf20Sopenharmony_ci	clk[IMX1_CLK_SSI2_GATE] = imx_clk_gate("ssi2_gate", "hclk", SCM_GCCR, 5);
618c2ecf20Sopenharmony_ci	clk[IMX1_CLK_BROM_GATE] = imx_clk_gate("brom_gate", "hclk", SCM_GCCR, 4);
628c2ecf20Sopenharmony_ci	clk[IMX1_CLK_DMA_GATE] = imx_clk_gate("dma_gate", "hclk", SCM_GCCR, 3);
638c2ecf20Sopenharmony_ci	clk[IMX1_CLK_CSI_GATE] = imx_clk_gate("csi_gate", "hclk", SCM_GCCR, 2);
648c2ecf20Sopenharmony_ci	clk[IMX1_CLK_MMA_GATE] = imx_clk_gate("mma_gate", "hclk", SCM_GCCR, 1);
658c2ecf20Sopenharmony_ci	clk[IMX1_CLK_USBD_GATE] = imx_clk_gate("usbd_gate", "clk48m", SCM_GCCR, 0);
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	imx_check_clocks(clk, ARRAY_SIZE(clk));
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci	clk_data.clks = clk;
708c2ecf20Sopenharmony_ci	clk_data.clk_num = ARRAY_SIZE(clk);
718c2ecf20Sopenharmony_ci	of_clk_add_provider(np, of_clk_src_onecell_get, &clk_data);
728c2ecf20Sopenharmony_ci}
738c2ecf20Sopenharmony_ciCLK_OF_DECLARE(imx1_ccm, "fsl,imx1-ccm", mx1_clocks_init_dt);
74