blob: 6b18483c81425f6271856e8f34ca6173a270f132 [file] [log] [blame]
Peng Fanc4cc2832019-12-30 17:39:18 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright 2019 NXP
4 * Peng Fan <peng.fan@nxp.com>
5 */
6
Peng Fanc4cc2832019-12-30 17:39:18 +08007#include <clk.h>
8#include <clk-uclass.h>
9#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060010#include <log.h>
Peng Fanc4cc2832019-12-30 17:39:18 +080011#include <asm/arch/clock.h>
12#include <asm/arch/imx-regs.h>
13#include <dt-bindings/clock/imx8mp-clock.h>
14
15#include "clk.h"
16
Michael Trimarchibd090572024-07-07 10:20:01 +020017static const char * const pll_ref_sels[] = { "clock-osc-24m", "dummy", "dummy", "dummy", };
18static const char * const dram_pll_bypass_sels[] = {"dram_pll", "dram_pll_ref_sel", };
19static const char * const arm_pll_bypass_sels[] = {"arm_pll", "arm_pll_ref_sel", };
20static const char * const sys_pll1_bypass_sels[] = {"sys_pll1", "sys_pll1_ref_sel", };
21static const char * const sys_pll2_bypass_sels[] = {"sys_pll2", "sys_pll2_ref_sel", };
22static const char * const sys_pll3_bypass_sels[] = {"sys_pll3", "sys_pll3_ref_sel", };
Peng Fanc4cc2832019-12-30 17:39:18 +080023
Michael Trimarchibd090572024-07-07 10:20:01 +020024static const char * const imx8mp_a53_sels[] = {"clock-osc-24m", "arm_pll_out", "sys_pll2_500m",
25 "sys_pll2_1000m", "sys_pll1_800m", "sys_pll1_400m",
26 "audio_pll1_out", "sys_pll3_out", };
Peng Fanc4cc2832019-12-30 17:39:18 +080027
Michael Trimarchibd090572024-07-07 10:20:01 +020028static const char * const imx8mp_hsio_axi_sels[] = {"clock-osc-24m", "sys_pll2_500m", "sys_pll1_800m",
29 "sys_pll2_100m", "sys_pll2_200m", "clk_ext2",
30 "clk_ext4", "audio_pll2_out", };
Marek Vasut7a2c3be2022-04-01 03:17:29 +020031
Michael Trimarchibd090572024-07-07 10:20:01 +020032static const char * const imx8mp_main_axi_sels[] = {"clock-osc-24m", "sys_pll2_333m", "sys_pll1_800m",
33 "sys_pll2_250m", "sys_pll2_1000m", "audio_pll1_out",
34 "video_pll1_out", "sys_pll1_100m",};
Peng Fanc4cc2832019-12-30 17:39:18 +080035
Michael Trimarchibd090572024-07-07 10:20:01 +020036static const char * const imx8mp_enet_axi_sels[] = {"clock-osc-24m", "sys_pll1_266m", "sys_pll1_800m",
37 "sys_pll2_250m", "sys_pll2_200m", "audio_pll1_out",
38 "video_pll1_out", "sys_pll3_out", };
Ye Liac9a4512020-04-21 20:19:24 -070039
Michael Trimarchibd090572024-07-07 10:20:01 +020040static const char * const imx8mp_nand_usdhc_sels[] = {"clock-osc-24m", "sys_pll1_266m", "sys_pll1_800m",
41 "sys_pll2_200m", "sys_pll1_133m", "sys_pll3_out",
42 "sys_pll2_250m", "audio_pll1_out", };
Peng Fanc4cc2832019-12-30 17:39:18 +080043
Michael Trimarchibd090572024-07-07 10:20:01 +020044static const char * const imx8mp_noc_sels[] = {"clock-osc-24m", "sys_pll1_800m", "sys_pll3_out",
45 "sys_pll2_1000m", "sys_pll2_500m", "audio_pll1_out",
46 "video_pll1_out", "audio_pll2_out", };
Peng Fanc4cc2832019-12-30 17:39:18 +080047
Michael Trimarchibd090572024-07-07 10:20:01 +020048static const char * const imx8mp_noc_io_sels[] = {"clock-osc-24m", "sys_pll1_800m", "sys_pll3_out",
49 "sys_pll2_1000m", "sys_pll2_500m", "audio_pll1_out",
50 "video_pll1_out", "audio_pll2_out", };
Peng Fanc4cc2832019-12-30 17:39:18 +080051
Michael Trimarchibd090572024-07-07 10:20:01 +020052static const char * const imx8mp_ahb_sels[] = {"clock-osc-24m", "sys_pll1_133m", "sys_pll1_800m",
53 "sys_pll1_400m", "sys_pll2_125m", "sys_pll3_out",
54 "audio_pll1_out", "video_pll1_out", };
Peng Fanc4cc2832019-12-30 17:39:18 +080055
Michael Trimarchibd090572024-07-07 10:20:01 +020056static const char * const imx8mp_dram_alt_sels[] = {"clock-osc-24m", "sys_pll1_800m", "sys_pll1_100m",
57 "sys_pll2_500m", "sys_pll2_1000m", "sys_pll3_out",
58 "audio_pll1_out", "sys_pll1_266m", };
Peng Fanc4cc2832019-12-30 17:39:18 +080059
Michael Trimarchibd090572024-07-07 10:20:01 +020060static const char * const imx8mp_dram_apb_sels[] = {"clock-osc-24m", "sys_pll2_200m", "sys_pll1_40m",
61 "sys_pll1_160m", "sys_pll1_800m", "sys_pll3_out",
62 "sys_pll2_250m", "audio_pll2_out", };
Peng Fanc4cc2832019-12-30 17:39:18 +080063
Sumit Garg2e1d9012024-03-21 20:24:57 +053064static const char * const imx8mp_pcie_aux_sels[] = {"clock-osc-24m", "sys_pll2_200m", "sys_pll2_50m",
65 "sys_pll3_out", "sys_pll2_100m", "sys_pll1_80m",
66 "sys_pll1_160m", "sys_pll1_200m", };
67
Michael Trimarchibd090572024-07-07 10:20:01 +020068static const char * const imx8mp_i2c5_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m",
69 "sys_pll3_out", "audio_pll1_out", "video_pll1_out",
70 "audio_pll2_out", "sys_pll1_133m", };
Peng Fanc4cc2832019-12-30 17:39:18 +080071
Michael Trimarchibd090572024-07-07 10:20:01 +020072static const char * const imx8mp_i2c6_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m",
73 "sys_pll3_out", "audio_pll1_out", "video_pll1_out",
74 "audio_pll2_out", "sys_pll1_133m", };
Peng Fanc4cc2832019-12-30 17:39:18 +080075
Michael Trimarchibd090572024-07-07 10:20:01 +020076static const char * const imx8mp_enet_qos_sels[] = {"clock-osc-24m", "sys_pll2_125m", "sys_pll2_50m",
77 "sys_pll2_100m", "sys_pll1_160m", "audio_pll1_out",
78 "video_pll1_out", "clk_ext4", };
Marek Vasutecb1c372023-03-06 15:53:41 +010079
Michael Trimarchibd090572024-07-07 10:20:01 +020080static const char * const imx8mp_enet_qos_timer_sels[] = {"clock-osc-24m", "sys_pll2_100m", "audio_pll1_out",
81 "clk_ext1", "clk_ext2", "clk_ext3",
82 "clk_ext4", "video_pll1_out", };
Marek Vasutecb1c372023-03-06 15:53:41 +010083
Michael Trimarchibd090572024-07-07 10:20:01 +020084static const char * const imx8mp_usdhc1_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll1_800m",
85 "sys_pll2_500m", "sys_pll3_out", "sys_pll1_266m",
86 "audio_pll2_out", "sys_pll1_100m", };
Peng Fanc4cc2832019-12-30 17:39:18 +080087
Michael Trimarchibd090572024-07-07 10:20:01 +020088static const char * const imx8mp_usdhc2_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll1_800m",
89 "sys_pll2_500m", "sys_pll3_out", "sys_pll1_266m",
90 "audio_pll2_out", "sys_pll1_100m", };
Peng Fanc4cc2832019-12-30 17:39:18 +080091
Michael Trimarchibd090572024-07-07 10:20:01 +020092static const char * const imx8mp_i2c1_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m",
93 "sys_pll3_out", "audio_pll1_out", "video_pll1_out",
94 "audio_pll2_out", "sys_pll1_133m", };
Peng Fanc4cc2832019-12-30 17:39:18 +080095
Michael Trimarchibd090572024-07-07 10:20:01 +020096static const char * const imx8mp_i2c2_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m",
97 "sys_pll3_out", "audio_pll1_out", "video_pll1_out",
98 "audio_pll2_out", "sys_pll1_133m", };
Peng Fanc4cc2832019-12-30 17:39:18 +080099
Michael Trimarchibd090572024-07-07 10:20:01 +0200100static const char * const imx8mp_i2c3_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m",
101 "sys_pll3_out", "audio_pll1_out", "video_pll1_out",
102 "audio_pll2_out", "sys_pll1_133m", };
Peng Fanc4cc2832019-12-30 17:39:18 +0800103
Michael Trimarchibd090572024-07-07 10:20:01 +0200104static const char * const imx8mp_i2c4_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m",
105 "sys_pll3_out", "audio_pll1_out", "video_pll1_out",
106 "audio_pll2_out", "sys_pll1_133m", };
Peng Fanc4cc2832019-12-30 17:39:18 +0800107
Michael Trimarchibd090572024-07-07 10:20:01 +0200108static const char * const imx8mp_uart1_sels[] = {"clock-osc-24m", "sys_pll1_80m", "sys_pll2_200m",
109 "sys_pll2_100m", "sys_pll3_out", "clk_ext2",
110 "clk_ext4", "audio_pll2_out", };
Peng Fanc4cc2832019-12-30 17:39:18 +0800111
Michael Trimarchibd090572024-07-07 10:20:01 +0200112static const char * const imx8mp_uart2_sels[] = {"clock-osc-24m", "sys_pll1_80m", "sys_pll2_200m",
113 "sys_pll2_100m", "sys_pll3_out", "clk_ext2",
Marek Vasut7a2c3be2022-04-01 03:17:29 +0200114 "clk_ext3", "audio_pll2_out", };
115
Michael Trimarchibd090572024-07-07 10:20:01 +0200116static const char * const imx8mp_uart3_sels[] = {"clock-osc-24m", "sys_pll1_80m", "sys_pll2_200m",
117 "sys_pll2_100m", "sys_pll3_out", "clk_ext2",
118 "clk_ext4", "audio_pll2_out", };
Marek Vasut7a2c3be2022-04-01 03:17:29 +0200119
Michael Trimarchibd090572024-07-07 10:20:01 +0200120static const char * const imx8mp_uart4_sels[] = {"clock-osc-24m", "sys_pll1_80m", "sys_pll2_200m",
121 "sys_pll2_100m", "sys_pll3_out", "clk_ext2",
122 "clk_ext3", "audio_pll2_out", };
Peng Fanc4cc2832019-12-30 17:39:18 +0800123
Michael Trimarchibd090572024-07-07 10:20:01 +0200124static const char * const imx8mp_usb_core_ref_sels[] = {"clock-osc-24m", "sys_pll1_100m", "sys_pll1_40m",
125 "sys_pll2_100m", "sys_pll2_200m", "clk_ext2",
126 "clk_ext3", "audio_pll2_out", };
Tommaso Merciaif2165802023-03-10 16:24:24 +0100127
Michael Trimarchibd090572024-07-07 10:20:01 +0200128static const char * const imx8mp_usb_phy_ref_sels[] = {"clock-osc-24m", "sys_pll1_100m", "sys_pll1_40m",
129 "sys_pll2_100m", "sys_pll2_200m", "clk_ext2",
130 "clk_ext3", "audio_pll2_out", };
Tommaso Merciaif2165802023-03-10 16:24:24 +0100131
Michael Trimarchibd090572024-07-07 10:20:01 +0200132static const char * const imx8mp_gic_sels[] = {"clock-osc-24m", "sys_pll2_200m", "sys_pll1_40m",
133 "sys_pll2_100m", "sys_pll1_800m",
134 "sys_pll2_500m", "clk_ext4", "audio_pll2_out" };
Tommaso Merciaif2165802023-03-10 16:24:24 +0100135
Michael Trimarchibd090572024-07-07 10:20:01 +0200136static const char * const imx8mp_pwm1_sels[] = {"clock-osc-24m", "sys_pll2_100m", "sys_pll1_160m",
137 "sys_pll1_40m", "sys_pll3_out", "clk_ext1",
138 "sys_pll1_80m", "video_pll1_out", };
Tommaso Merciaif2165802023-03-10 16:24:24 +0100139
Michael Trimarchibd090572024-07-07 10:20:01 +0200140static const char * const imx8mp_pwm2_sels[] = {"clock-osc-24m", "sys_pll2_100m", "sys_pll1_160m",
141 "sys_pll1_40m", "sys_pll3_out", "clk_ext1",
142 "sys_pll1_80m", "video_pll1_out", };
143
144static const char * const imx8mp_pwm3_sels[] = {"clock-osc-24m", "sys_pll2_100m", "sys_pll1_160m",
145 "sys_pll1_40m", "sys_pll3_out", "clk_ext2",
146 "sys_pll1_80m", "video_pll1_out", };
147
148static const char * const imx8mp_pwm4_sels[] = {"clock-osc-24m", "sys_pll2_100m", "sys_pll1_160m",
149 "sys_pll1_40m", "sys_pll3_out", "clk_ext2",
150 "sys_pll1_80m", "video_pll1_out", };
151
152static const char * const imx8mp_ecspi1_sels[] = {"clock-osc-24m", "sys_pll2_200m", "sys_pll1_40m",
Elmar Albert87f95882022-04-06 13:39:50 +0200153 "sys_pll1_160m", "sys_pll1_800m", "sys_pll3_out",
154 "sys_pll2_250m", "audio_pll2_out", };
155
Michael Trimarchibd090572024-07-07 10:20:01 +0200156static const char * const imx8mp_ecspi2_sels[] = {"clock-osc-24m", "sys_pll2_200m", "sys_pll1_40m",
Elmar Albert87f95882022-04-06 13:39:50 +0200157 "sys_pll1_160m", "sys_pll1_800m", "sys_pll3_out",
158 "sys_pll2_250m", "audio_pll2_out", };
159
Michael Trimarchibd090572024-07-07 10:20:01 +0200160static const char * const imx8mp_ecspi3_sels[] = {"clock-osc-24m", "sys_pll2_200m", "sys_pll1_40m",
Elmar Albert87f95882022-04-06 13:39:50 +0200161 "sys_pll1_160m", "sys_pll1_800m", "sys_pll3_out",
162 "sys_pll2_250m", "audio_pll2_out", };
163
Michael Trimarchibd090572024-07-07 10:20:01 +0200164static const char * const imx8mp_wdog_sels[] = {"clock-osc-24m", "sys_pll1_133m", "sys_pll1_160m",
165 "vpu_pll_out", "sys_pll2_125m", "sys_pll3_out",
166 "sys_pll1_80m", "sys_pll2_166m" };
Peng Fanc4cc2832019-12-30 17:39:18 +0800167
Michael Trimarchibd090572024-07-07 10:20:01 +0200168static const char * const imx8mp_qspi_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll2_333m",
169 "sys_pll2_500m", "audio_pll2_out", "sys_pll1_266m",
170 "sys_pll3_out", "sys_pll1_100m", };
Ye Liac9a4512020-04-21 20:19:24 -0700171
Michael Trimarchibd090572024-07-07 10:20:01 +0200172static const char * const imx8mp_usdhc3_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll1_800m",
173 "sys_pll2_500m", "sys_pll3_out", "sys_pll1_266m",
174 "audio_pll2_out", "sys_pll1_100m", };
Peng Fanc4cc2832019-12-30 17:39:18 +0800175
Michael Trimarchibd090572024-07-07 10:20:01 +0200176static const char * const imx8mp_enet_ref_sels[] = {"clock-osc-24m", "sys_pll2_125m", "sys_pll2_50m",
177 "sys_pll2_100m", "sys_pll1_160m", "audio_pll1_out",
178 "video_pll1_out", "clk_ext4", };
Ye Liac9a4512020-04-21 20:19:24 -0700179
Michael Trimarchibd090572024-07-07 10:20:01 +0200180static const char * const imx8mp_enet_timer_sels[] = {"clock-osc-24m", "sys_pll2_100m", "audio_pll1_out",
181 "clk_ext1", "clk_ext2", "clk_ext3",
182 "clk_ext4", "video_pll1_out", };
Ye Liac9a4512020-04-21 20:19:24 -0700183
Michael Trimarchibd090572024-07-07 10:20:01 +0200184static const char * const imx8mp_enet_phy_ref_sels[] = {"clock-osc-24m", "sys_pll2_50m", "sys_pll2_125m",
185 "sys_pll2_200m", "sys_pll2_500m", "audio_pll1_out",
186 "video_pll1_out", "audio_pll2_out", };
Ye Liac9a4512020-04-21 20:19:24 -0700187
Michael Trimarchibd090572024-07-07 10:20:01 +0200188static const char * const imx8mp_dram_core_sels[] = {"dram_pll_out", "dram_alt_root", };
Peng Fanc4cc2832019-12-30 17:39:18 +0800189
Peng Fanc4cc2832019-12-30 17:39:18 +0800190static int imx8mp_clk_probe(struct udevice *dev)
191{
Marek Vasut2c6ae0a2022-04-13 00:41:10 +0200192 struct clk osc_24m_clk, osc_32k_clk;
Peng Fanc4cc2832019-12-30 17:39:18 +0800193 void __iomem *base;
Marek Vasut2c6ae0a2022-04-13 00:41:10 +0200194 int ret;
Peng Fanc4cc2832019-12-30 17:39:18 +0800195
196 base = (void *)ANATOP_BASE_ADDR;
197
198 clk_dm(IMX8MP_DRAM_PLL_REF_SEL, imx_clk_mux("dram_pll_ref_sel", base + 0x50, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
199 clk_dm(IMX8MP_ARM_PLL_REF_SEL, imx_clk_mux("arm_pll_ref_sel", base + 0x84, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
200 clk_dm(IMX8MP_SYS_PLL1_REF_SEL, imx_clk_mux("sys_pll1_ref_sel", base + 0x94, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
201 clk_dm(IMX8MP_SYS_PLL2_REF_SEL, imx_clk_mux("sys_pll2_ref_sel", base + 0x104, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
202 clk_dm(IMX8MP_SYS_PLL3_REF_SEL, imx_clk_mux("sys_pll3_ref_sel", base + 0x114, 0, 2, pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
203
Angus Ainslie129f5102022-03-29 07:02:40 -0700204 clk_dm(IMX8MP_DRAM_PLL, imx_clk_pll14xx("dram_pll", "dram_pll_ref_sel", base + 0x50,
205 &imx_1443x_dram_pll));
206 clk_dm(IMX8MP_ARM_PLL, imx_clk_pll14xx("arm_pll", "arm_pll_ref_sel", base + 0x84,
207 &imx_1416x_pll));
208 clk_dm(IMX8MP_SYS_PLL1, imx_clk_pll14xx("sys_pll1", "sys_pll1_ref_sel", base + 0x94,
209 &imx_1416x_pll));
210 clk_dm(IMX8MP_SYS_PLL2, imx_clk_pll14xx("sys_pll2", "sys_pll2_ref_sel", base + 0x104,
211 &imx_1416x_pll));
212 clk_dm(IMX8MP_SYS_PLL3, imx_clk_pll14xx("sys_pll3", "sys_pll3_ref_sel", base + 0x114,
213 &imx_1416x_pll));
Peng Fanc4cc2832019-12-30 17:39:18 +0800214
215 clk_dm(IMX8MP_DRAM_PLL_BYPASS, imx_clk_mux_flags("dram_pll_bypass", base + 0x50, 4, 1, dram_pll_bypass_sels, ARRAY_SIZE(dram_pll_bypass_sels), CLK_SET_RATE_PARENT));
216 clk_dm(IMX8MP_ARM_PLL_BYPASS, imx_clk_mux_flags("arm_pll_bypass", base + 0x84, 4, 1, arm_pll_bypass_sels, ARRAY_SIZE(arm_pll_bypass_sels), CLK_SET_RATE_PARENT));
217 clk_dm(IMX8MP_SYS_PLL1_BYPASS, imx_clk_mux_flags("sys_pll1_bypass", base + 0x94, 4, 1, sys_pll1_bypass_sels, ARRAY_SIZE(sys_pll1_bypass_sels), CLK_SET_RATE_PARENT));
218 clk_dm(IMX8MP_SYS_PLL2_BYPASS, imx_clk_mux_flags("sys_pll2_bypass", base + 0x104, 4, 1, sys_pll2_bypass_sels, ARRAY_SIZE(sys_pll2_bypass_sels), CLK_SET_RATE_PARENT));
219 clk_dm(IMX8MP_SYS_PLL3_BYPASS, imx_clk_mux_flags("sys_pll3_bypass", base + 0x114, 4, 1, sys_pll3_bypass_sels, ARRAY_SIZE(sys_pll3_bypass_sels), CLK_SET_RATE_PARENT));
220
221 clk_dm(IMX8MP_DRAM_PLL_OUT, imx_clk_gate("dram_pll_out", "dram_pll_bypass", base + 0x50, 13));
222 clk_dm(IMX8MP_ARM_PLL_OUT, imx_clk_gate("arm_pll_out", "arm_pll_bypass", base + 0x84, 11));
223 clk_dm(IMX8MP_SYS_PLL1_OUT, imx_clk_gate("sys_pll1_out", "sys_pll1_bypass", base + 0x94, 11));
224 clk_dm(IMX8MP_SYS_PLL2_OUT, imx_clk_gate("sys_pll2_out", "sys_pll2_bypass", base + 0x104, 11));
225 clk_dm(IMX8MP_SYS_PLL3_OUT, imx_clk_gate("sys_pll3_out", "sys_pll3_bypass", base + 0x114, 11));
226
227 clk_dm(IMX8MP_SYS_PLL1_40M, imx_clk_fixed_factor("sys_pll1_40m", "sys_pll1_out", 1, 20));
228 clk_dm(IMX8MP_SYS_PLL1_80M, imx_clk_fixed_factor("sys_pll1_80m", "sys_pll1_out", 1, 10));
229 clk_dm(IMX8MP_SYS_PLL1_100M, imx_clk_fixed_factor("sys_pll1_100m", "sys_pll1_out", 1, 8));
230 clk_dm(IMX8MP_SYS_PLL1_133M, imx_clk_fixed_factor("sys_pll1_133m", "sys_pll1_out", 1, 6));
231 clk_dm(IMX8MP_SYS_PLL1_160M, imx_clk_fixed_factor("sys_pll1_160m", "sys_pll1_out", 1, 5));
232 clk_dm(IMX8MP_SYS_PLL1_200M, imx_clk_fixed_factor("sys_pll1_200m", "sys_pll1_out", 1, 4));
233 clk_dm(IMX8MP_SYS_PLL1_266M, imx_clk_fixed_factor("sys_pll1_266m", "sys_pll1_out", 1, 3));
234 clk_dm(IMX8MP_SYS_PLL1_400M, imx_clk_fixed_factor("sys_pll1_400m", "sys_pll1_out", 1, 2));
235 clk_dm(IMX8MP_SYS_PLL1_800M, imx_clk_fixed_factor("sys_pll1_800m", "sys_pll1_out", 1, 1));
236
237 clk_dm(IMX8MP_SYS_PLL2_50M, imx_clk_fixed_factor("sys_pll2_50m", "sys_pll2_out", 1, 20));
238 clk_dm(IMX8MP_SYS_PLL2_100M, imx_clk_fixed_factor("sys_pll2_100m", "sys_pll2_out", 1, 10));
239 clk_dm(IMX8MP_SYS_PLL2_125M, imx_clk_fixed_factor("sys_pll2_125m", "sys_pll2_out", 1, 8));
240 clk_dm(IMX8MP_SYS_PLL2_166M, imx_clk_fixed_factor("sys_pll2_166m", "sys_pll2_out", 1, 6));
241 clk_dm(IMX8MP_SYS_PLL2_200M, imx_clk_fixed_factor("sys_pll2_200m", "sys_pll2_out", 1, 5));
242 clk_dm(IMX8MP_SYS_PLL2_250M, imx_clk_fixed_factor("sys_pll2_250m", "sys_pll2_out", 1, 4));
243 clk_dm(IMX8MP_SYS_PLL2_333M, imx_clk_fixed_factor("sys_pll2_333m", "sys_pll2_out", 1, 3));
244 clk_dm(IMX8MP_SYS_PLL2_500M, imx_clk_fixed_factor("sys_pll2_500m", "sys_pll2_out", 1, 2));
245 clk_dm(IMX8MP_SYS_PLL2_1000M, imx_clk_fixed_factor("sys_pll2_1000m", "sys_pll2_out", 1, 1));
246
Marek Vasut2c6ae0a2022-04-13 00:41:10 +0200247 ret = clk_get_by_name(dev, "osc_24m", &osc_24m_clk);
248 if (ret)
249 return ret;
250 clk_dm(IMX8MP_CLK_24M, dev_get_clk_ptr(osc_24m_clk.dev));
251
252 ret = clk_get_by_name(dev, "osc_32k", &osc_32k_clk);
253 if (ret)
254 return ret;
255 clk_dm(IMX8MP_CLK_32K, dev_get_clk_ptr(osc_32k_clk.dev));
Marek Vasut7a2c3be2022-04-01 03:17:29 +0200256
Peng Fanc4cc2832019-12-30 17:39:18 +0800257 base = dev_read_addr_ptr(dev);
Sean Anderson082faeb2020-06-24 06:41:13 -0400258 if (!base)
Peng Fanc4cc2832019-12-30 17:39:18 +0800259 return -EINVAL;
260
261 clk_dm(IMX8MP_CLK_A53_SRC, imx_clk_mux2("arm_a53_src", base + 0x8000, 24, 3, imx8mp_a53_sels, ARRAY_SIZE(imx8mp_a53_sels)));
262 clk_dm(IMX8MP_CLK_A53_CG, imx_clk_gate3("arm_a53_cg", "arm_a53_src", base + 0x8000, 28));
263 clk_dm(IMX8MP_CLK_A53_DIV, imx_clk_divider2("arm_a53_div", "arm_a53_cg", base + 0x8000, 0, 3));
264
Marek Vasut7a2c3be2022-04-01 03:17:29 +0200265 clk_dm(IMX8MP_CLK_HSIO_AXI, imx8m_clk_composite("hsio_axi", imx8mp_hsio_axi_sels, base + 0x8380));
Peng Fanc4cc2832019-12-30 17:39:18 +0800266 clk_dm(IMX8MP_CLK_MAIN_AXI, imx8m_clk_composite_critical("main_axi", imx8mp_main_axi_sels, base + 0x8800));
Ye Liac9a4512020-04-21 20:19:24 -0700267 clk_dm(IMX8MP_CLK_ENET_AXI, imx8m_clk_composite_critical("enet_axi", imx8mp_enet_axi_sels, base + 0x8880));
Peng Fanc4cc2832019-12-30 17:39:18 +0800268 clk_dm(IMX8MP_CLK_NAND_USDHC_BUS, imx8m_clk_composite_critical("nand_usdhc_bus", imx8mp_nand_usdhc_sels, base + 0x8900));
269 clk_dm(IMX8MP_CLK_NOC, imx8m_clk_composite_critical("noc", imx8mp_noc_sels, base + 0x8d00));
270 clk_dm(IMX8MP_CLK_NOC_IO, imx8m_clk_composite_critical("noc_io", imx8mp_noc_io_sels, base + 0x8d80));
271
272 clk_dm(IMX8MP_CLK_AHB, imx8m_clk_composite_critical("ahb_root", imx8mp_ahb_sels, base + 0x9000));
273
274 clk_dm(IMX8MP_CLK_IPG_ROOT, imx_clk_divider2("ipg_root", "ahb_root", base + 0x9080, 0, 1));
275
276 clk_dm(IMX8MP_CLK_DRAM_ALT, imx8m_clk_composite("dram_alt", imx8mp_dram_alt_sels, base + 0xa000));
277 clk_dm(IMX8MP_CLK_DRAM_APB, imx8m_clk_composite_critical("dram_apb", imx8mp_dram_apb_sels, base + 0xa080));
Sumit Garg2e1d9012024-03-21 20:24:57 +0530278 clk_dm(IMX8MP_CLK_PCIE_AUX, imx8m_clk_composite("pcie_aux", imx8mp_pcie_aux_sels, base + 0xa400));
Peng Fanc4cc2832019-12-30 17:39:18 +0800279 clk_dm(IMX8MP_CLK_I2C5, imx8m_clk_composite("i2c5", imx8mp_i2c5_sels, base + 0xa480));
280 clk_dm(IMX8MP_CLK_I2C6, imx8m_clk_composite("i2c6", imx8mp_i2c6_sels, base + 0xa500));
Marek Vasutecb1c372023-03-06 15:53:41 +0100281 clk_dm(IMX8MP_CLK_ENET_QOS, imx8m_clk_composite("enet_qos", imx8mp_enet_qos_sels, base + 0xa880));
282 clk_dm(IMX8MP_CLK_ENET_QOS_TIMER, imx8m_clk_composite("enet_qos_timer", imx8mp_enet_qos_timer_sels, base + 0xa900));
Ye Liac9a4512020-04-21 20:19:24 -0700283 clk_dm(IMX8MP_CLK_ENET_REF, imx8m_clk_composite("enet_ref", imx8mp_enet_ref_sels, base + 0xa980));
284 clk_dm(IMX8MP_CLK_ENET_TIMER, imx8m_clk_composite("enet_timer", imx8mp_enet_timer_sels, base + 0xaa00));
285 clk_dm(IMX8MP_CLK_ENET_PHY_REF, imx8m_clk_composite("enet_phy_ref", imx8mp_enet_phy_ref_sels, base + 0xaa80));
286 clk_dm(IMX8MP_CLK_QSPI, imx8m_clk_composite("qspi", imx8mp_qspi_sels, base + 0xab80));
Peng Fanc4cc2832019-12-30 17:39:18 +0800287 clk_dm(IMX8MP_CLK_USDHC1, imx8m_clk_composite("usdhc1", imx8mp_usdhc1_sels, base + 0xac00));
288 clk_dm(IMX8MP_CLK_USDHC2, imx8m_clk_composite("usdhc2", imx8mp_usdhc2_sels, base + 0xac80));
289 clk_dm(IMX8MP_CLK_I2C1, imx8m_clk_composite("i2c1", imx8mp_i2c1_sels, base + 0xad00));
290 clk_dm(IMX8MP_CLK_I2C2, imx8m_clk_composite("i2c2", imx8mp_i2c2_sels, base + 0xad80));
291 clk_dm(IMX8MP_CLK_I2C3, imx8m_clk_composite("i2c3", imx8mp_i2c3_sels, base + 0xae00));
292 clk_dm(IMX8MP_CLK_I2C4, imx8m_clk_composite("i2c4", imx8mp_i2c4_sels, base + 0xae80));
293
294 clk_dm(IMX8MP_CLK_UART1, imx8m_clk_composite("uart1", imx8mp_uart1_sels, base + 0xaf00));
295 clk_dm(IMX8MP_CLK_UART2, imx8m_clk_composite("uart2", imx8mp_uart2_sels, base + 0xaf80));
296 clk_dm(IMX8MP_CLK_UART3, imx8m_clk_composite("uart3", imx8mp_uart3_sels, base + 0xb000));
297 clk_dm(IMX8MP_CLK_UART4, imx8m_clk_composite("uart4", imx8mp_uart4_sels, base + 0xb080));
Marek Vasut7a2c3be2022-04-01 03:17:29 +0200298 clk_dm(IMX8MP_CLK_USB_CORE_REF, imx8m_clk_composite("usb_core_ref", imx8mp_usb_core_ref_sels, base + 0xb100));
299 clk_dm(IMX8MP_CLK_USB_PHY_REF, imx8m_clk_composite("usb_phy_ref", imx8mp_usb_phy_ref_sels, base + 0xb180));
Peng Fanc4cc2832019-12-30 17:39:18 +0800300 clk_dm(IMX8MP_CLK_GIC, imx8m_clk_composite_critical("gic", imx8mp_gic_sels, base + 0xb200));
Elmar Albert87f95882022-04-06 13:39:50 +0200301 clk_dm(IMX8MP_CLK_ECSPI1, imx8m_clk_composite("ecspi1", imx8mp_ecspi1_sels, base + 0xb280));
302 clk_dm(IMX8MP_CLK_ECSPI2, imx8m_clk_composite("ecspi2", imx8mp_ecspi2_sels, base + 0xb300));
Tommaso Merciaif2165802023-03-10 16:24:24 +0100303 clk_dm(IMX8MP_CLK_PWM1, imx8m_clk_composite_critical("pwm1", imx8mp_pwm1_sels, base + 0xb380));
304 clk_dm(IMX8MP_CLK_PWM2, imx8m_clk_composite_critical("pwm2", imx8mp_pwm2_sels, base + 0xb400));
305 clk_dm(IMX8MP_CLK_PWM3, imx8m_clk_composite_critical("pwm3", imx8mp_pwm3_sels, base + 0xb480));
306 clk_dm(IMX8MP_CLK_PWM4, imx8m_clk_composite_critical("pwm4", imx8mp_pwm4_sels, base + 0xb500));
Elmar Albert87f95882022-04-06 13:39:50 +0200307 clk_dm(IMX8MP_CLK_ECSPI3, imx8m_clk_composite("ecspi3", imx8mp_ecspi3_sels, base + 0xc180));
Peng Fanc4cc2832019-12-30 17:39:18 +0800308
309 clk_dm(IMX8MP_CLK_WDOG, imx8m_clk_composite("wdog", imx8mp_wdog_sels, base + 0xb900));
310 clk_dm(IMX8MP_CLK_USDHC3, imx8m_clk_composite("usdhc3", imx8mp_usdhc3_sels, base + 0xbc80));
311
312 clk_dm(IMX8MP_CLK_DRAM_ALT_ROOT, imx_clk_fixed_factor("dram_alt_root", "dram_alt", 1, 4));
313 clk_dm(IMX8MP_CLK_DRAM_CORE, imx_clk_mux2_flags("dram_core_clk", base + 0x9800, 24, 1, imx8mp_dram_core_sels, ARRAY_SIZE(imx8mp_dram_core_sels), CLK_IS_CRITICAL));
314
315 clk_dm(IMX8MP_CLK_DRAM1_ROOT, imx_clk_gate4_flags("dram1_root_clk", "dram_core_clk", base + 0x4050, 0, CLK_IS_CRITICAL));
Elmar Albert87f95882022-04-06 13:39:50 +0200316 clk_dm(IMX8MP_CLK_ECSPI1_ROOT, imx_clk_gate4("ecspi1_root_clk", "ecspi1", base + 0x4070, 0));
317 clk_dm(IMX8MP_CLK_ECSPI2_ROOT, imx_clk_gate4("ecspi2_root_clk", "ecspi2", base + 0x4080, 0));
318 clk_dm(IMX8MP_CLK_ECSPI3_ROOT, imx_clk_gate4("ecspi3_root_clk", "ecspi3", base + 0x4090, 0));
Ye Liac9a4512020-04-21 20:19:24 -0700319 clk_dm(IMX8MP_CLK_ENET1_ROOT, imx_clk_gate4("enet1_root_clk", "enet_axi", base + 0x40a0, 0));
Peng Fanc4cc2832019-12-30 17:39:18 +0800320 clk_dm(IMX8MP_CLK_GPIO1_ROOT, imx_clk_gate4("gpio1_root_clk", "ipg_root", base + 0x40b0, 0));
321 clk_dm(IMX8MP_CLK_GPIO2_ROOT, imx_clk_gate4("gpio2_root_clk", "ipg_root", base + 0x40c0, 0));
322 clk_dm(IMX8MP_CLK_GPIO3_ROOT, imx_clk_gate4("gpio3_root_clk", "ipg_root", base + 0x40d0, 0));
323 clk_dm(IMX8MP_CLK_GPIO4_ROOT, imx_clk_gate4("gpio4_root_clk", "ipg_root", base + 0x40e0, 0));
324 clk_dm(IMX8MP_CLK_GPIO5_ROOT, imx_clk_gate4("gpio5_root_clk", "ipg_root", base + 0x40f0, 0));
325 clk_dm(IMX8MP_CLK_I2C1_ROOT, imx_clk_gate4("i2c1_root_clk", "i2c1", base + 0x4170, 0));
326 clk_dm(IMX8MP_CLK_I2C2_ROOT, imx_clk_gate4("i2c2_root_clk", "i2c2", base + 0x4180, 0));
327 clk_dm(IMX8MP_CLK_I2C3_ROOT, imx_clk_gate4("i2c3_root_clk", "i2c3", base + 0x4190, 0));
328 clk_dm(IMX8MP_CLK_I2C4_ROOT, imx_clk_gate4("i2c4_root_clk", "i2c4", base + 0x41a0, 0));
Sumit Garg2e1d9012024-03-21 20:24:57 +0530329 clk_dm(IMX8MP_CLK_PCIE_ROOT, imx_clk_gate4("pcie_root_clk", "pcie_aux", base + 0x4250, 0));
Tommaso Merciaif2165802023-03-10 16:24:24 +0100330 clk_dm(IMX8MP_CLK_PWM1_ROOT, imx_clk_gate4("pwm1_root_clk", "pwm1", base + 0x4280, 0));
331 clk_dm(IMX8MP_CLK_PWM2_ROOT, imx_clk_gate4("pwm2_root_clk", "pwm2", base + 0x4290, 0));
332 clk_dm(IMX8MP_CLK_PWM3_ROOT, imx_clk_gate4("pwm3_root_clk", "pwm3", base + 0x42a0, 0));
333 clk_dm(IMX8MP_CLK_PWM4_ROOT, imx_clk_gate4("pwm4_root_clk", "pwm4", base + 0x42b0, 0));
Marek Vasutecb1c372023-03-06 15:53:41 +0100334 clk_dm(IMX8MP_CLK_QOS_ROOT, imx_clk_gate4("qos_root_clk", "ipg_root", base + 0x42c0, 0));
335 clk_dm(IMX8MP_CLK_QOS_ENET_ROOT, imx_clk_gate4("qos_enet_root_clk", "ipg_root", base + 0x42e0, 0));
Ye Liac9a4512020-04-21 20:19:24 -0700336 clk_dm(IMX8MP_CLK_QSPI_ROOT, imx_clk_gate4("qspi_root_clk", "qspi", base + 0x42f0, 0));
Peng Fanc4cc2832019-12-30 17:39:18 +0800337 clk_dm(IMX8MP_CLK_I2C5_ROOT, imx_clk_gate2("i2c5_root_clk", "i2c5", base + 0x4330, 0));
338 clk_dm(IMX8MP_CLK_I2C6_ROOT, imx_clk_gate2("i2c6_root_clk", "i2c6", base + 0x4340, 0));
Ye Liac9a4512020-04-21 20:19:24 -0700339 clk_dm(IMX8MP_CLK_SIM_ENET_ROOT, imx_clk_gate4("sim_enet_root_clk", "enet_axi", base + 0x4400, 0));
Marek Vasutecb1c372023-03-06 15:53:41 +0100340 clk_dm(IMX8MP_CLK_ENET_QOS_ROOT, imx_clk_gate4("enet_qos_root_clk", "sim_enet_root_clk", base + 0x43b0, 0));
Peng Fanc4cc2832019-12-30 17:39:18 +0800341 clk_dm(IMX8MP_CLK_UART1_ROOT, imx_clk_gate4("uart1_root_clk", "uart1", base + 0x4490, 0));
342 clk_dm(IMX8MP_CLK_UART2_ROOT, imx_clk_gate4("uart2_root_clk", "uart2", base + 0x44a0, 0));
343 clk_dm(IMX8MP_CLK_UART3_ROOT, imx_clk_gate4("uart3_root_clk", "uart3", base + 0x44b0, 0));
344 clk_dm(IMX8MP_CLK_UART4_ROOT, imx_clk_gate4("uart4_root_clk", "uart4", base + 0x44c0, 0));
Adam Fordd90d6072023-05-30 17:45:57 -0500345 clk_dm(IMX8MP_CLK_USB_ROOT, imx_clk_gate2("usb_root_clk", "hsio_axi", base + 0x44d0, 0));
346 clk_dm(IMX8MP_CLK_USB_SUSP, imx_clk_gate2("usb_suspend_clk", "clock-osc-24m", base + 0x44d0, 0));
Marek Vasut7a2c3be2022-04-01 03:17:29 +0200347 clk_dm(IMX8MP_CLK_USB_PHY_ROOT, imx_clk_gate4("usb_phy_root_clk", "usb_phy_ref", base + 0x44f0, 0));
Peng Fanc4cc2832019-12-30 17:39:18 +0800348 clk_dm(IMX8MP_CLK_USDHC1_ROOT, imx_clk_gate4("usdhc1_root_clk", "usdhc1", base + 0x4510, 0));
349 clk_dm(IMX8MP_CLK_USDHC2_ROOT, imx_clk_gate4("usdhc2_root_clk", "usdhc2", base + 0x4520, 0));
350 clk_dm(IMX8MP_CLK_WDOG1_ROOT, imx_clk_gate4("wdog1_root_clk", "wdog", base + 0x4530, 0));
351 clk_dm(IMX8MP_CLK_WDOG2_ROOT, imx_clk_gate4("wdog2_root_clk", "wdog", base + 0x4540, 0));
352 clk_dm(IMX8MP_CLK_WDOG3_ROOT, imx_clk_gate4("wdog3_root_clk", "wdog", base + 0x4550, 0));
Marek Vasut7a2c3be2022-04-01 03:17:29 +0200353 clk_dm(IMX8MP_CLK_HSIO_ROOT, imx_clk_gate4("hsio_root_clk", "ipg_root", base + 0x45c0, 0));
Peng Fanc4cc2832019-12-30 17:39:18 +0800354
355 clk_dm(IMX8MP_CLK_USDHC3_ROOT, imx_clk_gate4("usdhc3_root_clk", "usdhc3", base + 0x45e0, 0));
356
357 return 0;
358}
359
360static const struct udevice_id imx8mp_clk_ids[] = {
361 { .compatible = "fsl,imx8mp-ccm" },
362 { },
363};
364
365U_BOOT_DRIVER(imx8mp_clk) = {
366 .name = "clk_imx8mp",
367 .id = UCLASS_CLK,
368 .of_match = imx8mp_clk_ids,
Sean Anderson682e73d2022-03-20 16:34:46 -0400369 .ops = &ccf_clk_ops,
Peng Fanc4cc2832019-12-30 17:39:18 +0800370 .probe = imx8mp_clk_probe,
371 .flags = DM_FLAG_PRE_RELOC,
372};