blob: 125215e84f41c952eb55259820d52d9865cc468b [file] [log] [blame]
Peng Fane2f674d2019-09-16 03:09:47 +00001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright 2019 NXP
4 * Peng Fan <peng.fan@nxp.com>
5 */
6
Peng Fane2f674d2019-09-16 03:09:47 +00007#include <clk.h>
8#include <clk-uclass.h>
9#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -060010#include <log.h>
Peng Fane2f674d2019-09-16 03:09:47 +000011#include <asm/arch/clock.h>
12#include <asm/arch/imx-regs.h>
13#include <dt-bindings/clock/imx8mn-clock.h>
14
15#include "clk.h"
16
Michael Trimarchi252e54e2022-08-30 16:45:20 +020017static u32 share_count_nand;
18
Michael Trimarchia5e83042024-07-07 10:19:59 +020019static const char * const pll_ref_sels[] = { "clock-osc-24m", "dummy", "dummy", "dummy", };
20static const char * const dram_pll_bypass_sels[] = {"dram_pll", "dram_pll_ref_sel", };
21static const char * const arm_pll_bypass_sels[] = {"arm_pll", "arm_pll_ref_sel", };
22static const char * const sys_pll1_bypass_sels[] = {"sys_pll1", "sys_pll1_ref_sel", };
23static const char * const sys_pll2_bypass_sels[] = {"sys_pll2", "sys_pll2_ref_sel", };
24static const char * const sys_pll3_bypass_sels[] = {"sys_pll3", "sys_pll3_ref_sel", };
Peng Fane2f674d2019-09-16 03:09:47 +000025
Hou Zhiqiang04a06432024-08-01 11:59:46 +080026static const char * const imx8mn_arm_core_sels[] = {"arm_a53_src", "arm_pll_out", };
27
Michael Trimarchia5e83042024-07-07 10:19:59 +020028static const char * const imx8mn_a53_sels[] = {"clock-osc-24m", "arm_pll_out", "sys_pll2_500m",
29 "sys_pll2_1000m", "sys_pll1_800m", "sys_pll1_400m",
30 "audio_pll1_out", "sys_pll3_out", };
Peng Fane2f674d2019-09-16 03:09:47 +000031
Michael Trimarchia5e83042024-07-07 10:19:59 +020032static const char * const imx8mn_ahb_sels[] = {"clock-osc-24m", "sys_pll1_133m", "sys_pll1_800m",
33 "sys_pll1_400m", "sys_pll2_125m", "sys_pll3_out",
34 "audio_pll1_out", "video_pll_out", };
Peng Fane2f674d2019-09-16 03:09:47 +000035
Michael Trimarchia5e83042024-07-07 10:19:59 +020036static const char * const imx8mn_enet_axi_sels[] = {"clock-osc-24m", "sys_pll1_266m", "sys_pll1_800m",
37 "sys_pll2_250m", "sys_pll2_200m", "audio_pll1_out",
38 "video_pll_out", "sys_pll3_out", };
Peng Fane2f674d2019-09-16 03:09:47 +000039
Ye Li418c1fc2020-04-18 08:19:12 -070040#ifndef CONFIG_SPL_BUILD
Michael Trimarchia5e83042024-07-07 10:19:59 +020041static const char * const imx8mn_enet_ref_sels[] = {"clock-osc-24m", "sys_pll2_125m", "sys_pll2_50m",
42 "sys_pll2_100m", "sys_pll1_160m", "audio_pll1_out",
43 "video_pll_out", "clk_ext4", };
Ye Li418c1fc2020-04-18 08:19:12 -070044
Michael Trimarchia5e83042024-07-07 10:19:59 +020045static const char * const imx8mn_enet_timer_sels[] = {"clock-osc-24m", "sys_pll2_100m", "audio_pll1_out",
46 "clk_ext1", "clk_ext2", "clk_ext3",
47 "clk_ext4", "video_pll_out", };
Ye Li418c1fc2020-04-18 08:19:12 -070048
Michael Trimarchia5e83042024-07-07 10:19:59 +020049static const char * const imx8mn_enet_phy_sels[] = {"clock-osc-24m", "sys_pll2_50m", "sys_pll2_125m",
50 "sys_pll2_200m", "sys_pll2_500m", "audio_pll1_out",
51 "video_pll_out", "audio_pll2_out", };
Ye Li418c1fc2020-04-18 08:19:12 -070052#endif
53
Michael Trimarchia5e83042024-07-07 10:19:59 +020054static const char * const imx8mn_nand_usdhc_sels[] = {"clock-osc-24m", "sys_pll1_266m", "sys_pll1_800m",
55 "sys_pll2_200m", "sys_pll1_133m", "sys_pll3_out",
56 "sys_pll2_250m", "audio_pll1_out", };
Peng Fane2f674d2019-09-16 03:09:47 +000057
Ye Li0321edb2020-04-19 02:22:09 -070058static const char * const imx8mn_usb_bus_sels[] = {"clock-osc-24m", "sys_pll2_500m", "sys_pll1_800m",
Michael Trimarchia5e83042024-07-07 10:19:59 +020059 "sys_pll2_100m", "sys_pll2_200m", "clk_ext2",
60 "clk_ext4", "audio_pll2_out", };
Ye Li0321edb2020-04-19 02:22:09 -070061
Michael Trimarchia5e83042024-07-07 10:19:59 +020062static const char * const imx8mn_usdhc1_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll1_800m",
63 "sys_pll2_500m", "sys_pll3_out", "sys_pll1_266m",
64 "audio_pll2_out", "sys_pll1_100m", };
Peng Fane2f674d2019-09-16 03:09:47 +000065
Michael Trimarchia5e83042024-07-07 10:19:59 +020066static const char * const imx8mn_usdhc2_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll1_800m",
67 "sys_pll2_500m", "sys_pll3_out", "sys_pll1_266m",
68 "audio_pll2_out", "sys_pll1_100m", };
Peng Fane2f674d2019-09-16 03:09:47 +000069
Marek Vasutb1a8bb02021-01-19 00:58:31 +010070#if CONFIG_IS_ENABLED(DM_SPI)
Michael Trimarchia5e83042024-07-07 10:19:59 +020071static const char * const imx8mn_ecspi1_sels[] = {"clock-osc-24m", "sys_pll2_200m", "sys_pll1_40m",
72 "sys_pll1_160m", "sys_pll1_800m", "sys_pll3_out",
73 "sys_pll2_250m", "audio_pll2_out", };
Marek Vasutb1a8bb02021-01-19 00:58:31 +010074
Michael Trimarchia5e83042024-07-07 10:19:59 +020075static const char * const imx8mn_ecspi2_sels[] = {"clock-osc-24m", "sys_pll2_200m", "sys_pll1_40m",
76 "sys_pll1_160m", "sys_pll1_800m", "sys_pll3_out",
77 "sys_pll2_250m", "audio_pll2_out", };
Marek Vasutb1a8bb02021-01-19 00:58:31 +010078
Michael Trimarchia5e83042024-07-07 10:19:59 +020079static const char * const imx8mn_ecspi3_sels[] = {"clock-osc-24m", "sys_pll2_200m", "sys_pll1_40m",
80 "sys_pll1_160m", "sys_pll1_800m", "sys_pll3_out",
81 "sys_pll2_250m", "audio_pll2_out", };
Marek Vasutb1a8bb02021-01-19 00:58:31 +010082#endif
83
Michael Trimarchia5e83042024-07-07 10:19:59 +020084static const char * const imx8mn_i2c1_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m",
85 "sys_pll3_out", "audio_pll1_out", "video_pll_out",
86 "audio_pll2_out", "sys_pll1_133m", };
Peng Fane2f674d2019-09-16 03:09:47 +000087
Michael Trimarchia5e83042024-07-07 10:19:59 +020088static const char * const imx8mn_i2c2_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m",
89 "sys_pll3_out", "audio_pll1_out", "video_pll_out",
90 "audio_pll2_out", "sys_pll1_133m", };
Peng Fane2f674d2019-09-16 03:09:47 +000091
Michael Trimarchia5e83042024-07-07 10:19:59 +020092static const char * const imx8mn_i2c3_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m",
93 "sys_pll3_out", "audio_pll1_out", "video_pll_out",
94 "audio_pll2_out", "sys_pll1_133m", };
Peng Fane2f674d2019-09-16 03:09:47 +000095
Michael Trimarchia5e83042024-07-07 10:19:59 +020096static const char * const imx8mn_i2c4_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m",
97 "sys_pll3_out", "audio_pll1_out", "video_pll_out",
98 "audio_pll2_out", "sys_pll1_133m", };
Peng Fane2f674d2019-09-16 03:09:47 +000099
Nicolas Heemerycke5e85232023-12-11 11:06:13 +0100100#ifndef CONFIG_SPL_BUILD
Michael Trimarchia5e83042024-07-07 10:19:59 +0200101static const char * const imx8mn_pwm1_sels[] = {"clock-osc-24m", "sys_pll2_100m", "sys_pll1_160m",
102 "sys_pll1_40m", "sys_pll3_out", "clk_ext1",
103 "sys_pll1_80m", "video_pll_out", };
Nicolas Heemerycke5e85232023-12-11 11:06:13 +0100104
Michael Trimarchia5e83042024-07-07 10:19:59 +0200105static const char * const imx8mn_pwm2_sels[] = {"clock-osc-24m", "sys_pll2_100m", "sys_pll1_160m",
106 "sys_pll1_40m", "sys_pll3_out", "clk_ext1",
107 "sys_pll1_80m", "video_pll_out", };
Nicolas Heemerycke5e85232023-12-11 11:06:13 +0100108
Michael Trimarchia5e83042024-07-07 10:19:59 +0200109static const char * const imx8mn_pwm3_sels[] = {"clock-osc-24m", "sys_pll2_100m", "sys_pll1_160m",
110 "sys_pll1_40m", "sys_pll3_out", "clk_ext2",
111 "sys_pll1_80m", "video_pll_out", };
Nicolas Heemerycke5e85232023-12-11 11:06:13 +0100112
Michael Trimarchia5e83042024-07-07 10:19:59 +0200113static const char * const imx8mn_pwm4_sels[] = {"clock-osc-24m", "sys_pll2_100m", "sys_pll1_160m",
114 "sys_pll1_40m", "sys_pll3_out", "clk_ext2",
115 "sys_pll1_80m", "video_pll_out", };
Nicolas Heemerycke5e85232023-12-11 11:06:13 +0100116#endif
117
Michael Trimarchia5e83042024-07-07 10:19:59 +0200118static const char * const imx8mn_wdog_sels[] = {"clock-osc-24m", "sys_pll1_133m", "sys_pll1_160m",
119 "m7_alt_pll", "sys_pll2_125m", "sys_pll3_out",
120 "sys_pll1_80m", "sys_pll2_166m", };
Peng Fane2f674d2019-09-16 03:09:47 +0000121
Michael Trimarchia5e83042024-07-07 10:19:59 +0200122static const char * const imx8mn_usdhc3_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll1_800m",
123 "sys_pll2_500m", "sys_pll3_out", "sys_pll1_266m",
124 "audio_pll2_clk", "sys_pll1_100m", };
Peng Fane2f674d2019-09-16 03:09:47 +0000125
Michael Trimarchia5e83042024-07-07 10:19:59 +0200126static const char * const imx8mn_qspi_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll2_333m",
127 "sys_pll2_500m", "audio_pll2_out", "sys_pll1_266m",
128 "sys_pll3_out", "sys_pll1_100m", };
Ye Li418c1fc2020-04-18 08:19:12 -0700129
Michael Trimarchi24685832024-07-07 10:19:58 +0200130static const char * const imx8mn_nand_sels[] = {"clock-osc-24m", "sys_pll2_500m", "audio_pll1_out",
Michael Trimarchi252e54e2022-08-30 16:45:20 +0200131 "sys_pll1_400m", "audio_pll2_out", "sys_pll3_out",
Dario Binacchi2f51cf92022-12-19 12:31:25 +0100132 "sys_pll2_250m", "video_pll_out", };
Michael Trimarchi252e54e2022-08-30 16:45:20 +0200133
Ye Li0321edb2020-04-19 02:22:09 -0700134static const char * const imx8mn_usb_core_sels[] = {"clock-osc-24m", "sys_pll1_100m", "sys_pll1_40m",
Michael Trimarchia5e83042024-07-07 10:19:59 +0200135 "sys_pll2_100m", "sys_pll2_200m", "clk_ext2",
136 "clk_ext3", "audio_pll2_out", };
Ye Li0321edb2020-04-19 02:22:09 -0700137
138static const char * const imx8mn_usb_phy_sels[] = {"clock-osc-24m", "sys_pll1_100m", "sys_pll1_40m",
Michael Trimarchia5e83042024-07-07 10:19:59 +0200139 "sys_pll2_100m", "sys_pll2_200m", "clk_ext2",
140 "clk_ext3", "audio_pll2_out", };
Ye Li0321edb2020-04-19 02:22:09 -0700141
Peng Fane2f674d2019-09-16 03:09:47 +0000142static int imx8mn_clk_probe(struct udevice *dev)
143{
Michael Trimarchi24685832024-07-07 10:19:58 +0200144 struct clk osc_24m_clk;
Peng Fane2f674d2019-09-16 03:09:47 +0000145 void __iomem *base;
Michael Trimarchi24685832024-07-07 10:19:58 +0200146 int ret;
Peng Fane2f674d2019-09-16 03:09:47 +0000147
148 base = (void *)ANATOP_BASE_ADDR;
149
150 clk_dm(IMX8MN_DRAM_PLL_REF_SEL,
151 imx_clk_mux("dram_pll_ref_sel", base + 0x50, 0, 2,
152 pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
153 clk_dm(IMX8MN_ARM_PLL_REF_SEL,
154 imx_clk_mux("arm_pll_ref_sel", base + 0x84, 0, 2,
155 pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
156 clk_dm(IMX8MN_SYS_PLL1_REF_SEL,
157 imx_clk_mux("sys_pll1_ref_sel", base + 0x94, 0, 2,
158 pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
159 clk_dm(IMX8MN_SYS_PLL2_REF_SEL,
160 imx_clk_mux("sys_pll2_ref_sel", base + 0x104, 0, 2,
161 pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
162 clk_dm(IMX8MN_SYS_PLL3_REF_SEL,
163 imx_clk_mux("sys_pll3_ref_sel", base + 0x114, 0, 2,
164 pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
165
166 clk_dm(IMX8MN_DRAM_PLL,
167 imx_clk_pll14xx("dram_pll", "dram_pll_ref_sel",
Angus Ainslie73d75ec2022-03-29 07:02:40 -0700168 base + 0x50, &imx_1443x_dram_pll));
Peng Fane2f674d2019-09-16 03:09:47 +0000169 clk_dm(IMX8MN_ARM_PLL,
170 imx_clk_pll14xx("arm_pll", "arm_pll_ref_sel",
Angus Ainslie73d75ec2022-03-29 07:02:40 -0700171 base + 0x84, &imx_1416x_pll));
Peng Fane2f674d2019-09-16 03:09:47 +0000172 clk_dm(IMX8MN_SYS_PLL1,
173 imx_clk_pll14xx("sys_pll1", "sys_pll1_ref_sel",
Angus Ainslie73d75ec2022-03-29 07:02:40 -0700174 base + 0x94, &imx_1416x_pll));
Peng Fane2f674d2019-09-16 03:09:47 +0000175 clk_dm(IMX8MN_SYS_PLL2,
176 imx_clk_pll14xx("sys_pll2", "sys_pll2_ref_sel",
Angus Ainslie73d75ec2022-03-29 07:02:40 -0700177 base + 0x104, &imx_1416x_pll));
Peng Fane2f674d2019-09-16 03:09:47 +0000178 clk_dm(IMX8MN_SYS_PLL3,
179 imx_clk_pll14xx("sys_pll3", "sys_pll3_ref_sel",
Angus Ainslie73d75ec2022-03-29 07:02:40 -0700180 base + 0x114, &imx_1416x_pll));
Peng Fane2f674d2019-09-16 03:09:47 +0000181
182 /* PLL bypass out */
183 clk_dm(IMX8MN_DRAM_PLL_BYPASS,
184 imx_clk_mux_flags("dram_pll_bypass", base + 0x50, 4, 1,
185 dram_pll_bypass_sels,
186 ARRAY_SIZE(dram_pll_bypass_sels),
187 CLK_SET_RATE_PARENT));
188 clk_dm(IMX8MN_ARM_PLL_BYPASS,
189 imx_clk_mux_flags("arm_pll_bypass", base + 0x84, 4, 1,
190 arm_pll_bypass_sels,
191 ARRAY_SIZE(arm_pll_bypass_sels),
192 CLK_SET_RATE_PARENT));
193 clk_dm(IMX8MN_SYS_PLL1_BYPASS,
194 imx_clk_mux_flags("sys_pll1_bypass", base + 0x94, 4, 1,
195 sys_pll1_bypass_sels,
196 ARRAY_SIZE(sys_pll1_bypass_sels),
197 CLK_SET_RATE_PARENT));
198 clk_dm(IMX8MN_SYS_PLL2_BYPASS,
199 imx_clk_mux_flags("sys_pll2_bypass", base + 0x104, 4, 1,
200 sys_pll2_bypass_sels,
201 ARRAY_SIZE(sys_pll2_bypass_sels),
202 CLK_SET_RATE_PARENT));
203 clk_dm(IMX8MN_SYS_PLL3_BYPASS,
204 imx_clk_mux_flags("sys_pll3_bypass", base + 0x114, 4, 1,
205 sys_pll3_bypass_sels,
206 ARRAY_SIZE(sys_pll3_bypass_sels),
207 CLK_SET_RATE_PARENT));
208
209 /* PLL out gate */
210 clk_dm(IMX8MN_DRAM_PLL_OUT,
211 imx_clk_gate("dram_pll_out", "dram_pll_bypass",
212 base + 0x50, 13));
213 clk_dm(IMX8MN_ARM_PLL_OUT,
214 imx_clk_gate("arm_pll_out", "arm_pll_bypass",
215 base + 0x84, 11));
216 clk_dm(IMX8MN_SYS_PLL1_OUT,
217 imx_clk_gate("sys_pll1_out", "sys_pll1_bypass",
218 base + 0x94, 11));
219 clk_dm(IMX8MN_SYS_PLL2_OUT,
220 imx_clk_gate("sys_pll2_out", "sys_pll2_bypass",
221 base + 0x104, 11));
222 clk_dm(IMX8MN_SYS_PLL3_OUT,
223 imx_clk_gate("sys_pll3_out", "sys_pll3_bypass",
224 base + 0x114, 11));
225
226 /* SYS PLL fixed output */
227 clk_dm(IMX8MN_SYS_PLL1_40M,
228 imx_clk_fixed_factor("sys_pll1_40m", "sys_pll1_out", 1, 20));
229 clk_dm(IMX8MN_SYS_PLL1_80M,
230 imx_clk_fixed_factor("sys_pll1_80m", "sys_pll1_out", 1, 10));
231 clk_dm(IMX8MN_SYS_PLL1_100M,
232 imx_clk_fixed_factor("sys_pll1_100m", "sys_pll1_out", 1, 8));
233 clk_dm(IMX8MN_SYS_PLL1_133M,
234 imx_clk_fixed_factor("sys_pll1_133m", "sys_pll1_out", 1, 6));
235 clk_dm(IMX8MN_SYS_PLL1_160M,
236 imx_clk_fixed_factor("sys_pll1_160m", "sys_pll1_out", 1, 5));
237 clk_dm(IMX8MN_SYS_PLL1_200M,
238 imx_clk_fixed_factor("sys_pll1_200m", "sys_pll1_out", 1, 4));
239 clk_dm(IMX8MN_SYS_PLL1_266M,
240 imx_clk_fixed_factor("sys_pll1_266m", "sys_pll1_out", 1, 3));
241 clk_dm(IMX8MN_SYS_PLL1_400M,
242 imx_clk_fixed_factor("sys_pll1_400m", "sys_pll1_out", 1, 2));
243 clk_dm(IMX8MN_SYS_PLL1_800M,
244 imx_clk_fixed_factor("sys_pll1_800m", "sys_pll1_out", 1, 1));
245
246 clk_dm(IMX8MN_SYS_PLL2_50M,
247 imx_clk_fixed_factor("sys_pll2_50m", "sys_pll2_out", 1, 20));
248 clk_dm(IMX8MN_SYS_PLL2_100M,
249 imx_clk_fixed_factor("sys_pll2_100m", "sys_pll2_out", 1, 10));
250 clk_dm(IMX8MN_SYS_PLL2_125M,
251 imx_clk_fixed_factor("sys_pll2_125m", "sys_pll2_out", 1, 8));
252 clk_dm(IMX8MN_SYS_PLL2_166M,
253 imx_clk_fixed_factor("sys_pll2_166m", "sys_pll2_out", 1, 6));
254 clk_dm(IMX8MN_SYS_PLL2_200M,
255 imx_clk_fixed_factor("sys_pll2_200m", "sys_pll2_out", 1, 5));
256 clk_dm(IMX8MN_SYS_PLL2_250M,
257 imx_clk_fixed_factor("sys_pll2_250m", "sys_pll2_out", 1, 4));
258 clk_dm(IMX8MN_SYS_PLL2_333M,
259 imx_clk_fixed_factor("sys_pll2_333m", "sys_pll2_out", 1, 3));
260 clk_dm(IMX8MN_SYS_PLL2_500M,
261 imx_clk_fixed_factor("sys_pll2_500m", "sys_pll2_out", 1, 2));
262 clk_dm(IMX8MN_SYS_PLL2_1000M,
263 imx_clk_fixed_factor("sys_pll2_1000m", "sys_pll2_out", 1, 1));
264
Michael Trimarchi24685832024-07-07 10:19:58 +0200265 ret = clk_get_by_name(dev, "osc_24m", &osc_24m_clk);
266 if (ret)
267 return ret;
268 clk_dm(IMX8MN_CLK_24M, dev_get_clk_ptr(osc_24m_clk.dev));
269
Peng Fane2f674d2019-09-16 03:09:47 +0000270 base = dev_read_addr_ptr(dev);
Sean Andersonb58106d2019-12-24 23:57:47 -0500271 if (!base)
Peng Fane2f674d2019-09-16 03:09:47 +0000272 return -EINVAL;
273
274 clk_dm(IMX8MN_CLK_A53_SRC,
275 imx_clk_mux2("arm_a53_src", base + 0x8000, 24, 3,
276 imx8mn_a53_sels, ARRAY_SIZE(imx8mn_a53_sels)));
277 clk_dm(IMX8MN_CLK_A53_CG,
278 imx_clk_gate3("arm_a53_cg", "arm_a53_src", base + 0x8000, 28));
279 clk_dm(IMX8MN_CLK_A53_DIV,
280 imx_clk_divider2("arm_a53_div", "arm_a53_cg",
281 base + 0x8000, 0, 3));
282
283 clk_dm(IMX8MN_CLK_AHB,
284 imx8m_clk_composite_critical("ahb", imx8mn_ahb_sels,
285 base + 0x9000));
286 clk_dm(IMX8MN_CLK_IPG_ROOT,
287 imx_clk_divider2("ipg_root", "ahb", base + 0x9080, 0, 1));
288
289 clk_dm(IMX8MN_CLK_ENET_AXI,
290 imx8m_clk_composite("enet_axi", imx8mn_enet_axi_sels,
291 base + 0x8880));
292 clk_dm(IMX8MN_CLK_NAND_USDHC_BUS,
293 imx8m_clk_composite_critical("nand_usdhc_bus",
294 imx8mn_nand_usdhc_sels,
295 base + 0x8900));
Ye Li0321edb2020-04-19 02:22:09 -0700296 clk_dm(IMX8MN_CLK_USB_BUS,
297 imx8m_clk_composite("usb_bus", imx8mn_usb_bus_sels, base + 0x8b80));
Peng Fane2f674d2019-09-16 03:09:47 +0000298
299 /* IP */
300 clk_dm(IMX8MN_CLK_USDHC1,
301 imx8m_clk_composite("usdhc1", imx8mn_usdhc1_sels,
302 base + 0xac00));
303 clk_dm(IMX8MN_CLK_USDHC2,
304 imx8m_clk_composite("usdhc2", imx8mn_usdhc2_sels,
305 base + 0xac80));
306 clk_dm(IMX8MN_CLK_I2C1,
307 imx8m_clk_composite("i2c1", imx8mn_i2c1_sels, base + 0xad00));
308 clk_dm(IMX8MN_CLK_I2C2,
309 imx8m_clk_composite("i2c2", imx8mn_i2c2_sels, base + 0xad80));
310 clk_dm(IMX8MN_CLK_I2C3,
311 imx8m_clk_composite("i2c3", imx8mn_i2c3_sels, base + 0xae00));
312 clk_dm(IMX8MN_CLK_I2C4,
313 imx8m_clk_composite("i2c4", imx8mn_i2c4_sels, base + 0xae80));
314 clk_dm(IMX8MN_CLK_WDOG,
315 imx8m_clk_composite("wdog", imx8mn_wdog_sels, base + 0xb900));
316 clk_dm(IMX8MN_CLK_USDHC3,
317 imx8m_clk_composite("usdhc3", imx8mn_usdhc3_sels,
318 base + 0xbc80));
Michael Trimarchi252e54e2022-08-30 16:45:20 +0200319 clk_dm(IMX8MN_CLK_NAND,
320 imx8m_clk_composite("nand", imx8mn_nand_sels, base + 0xab00));
Ye Li418c1fc2020-04-18 08:19:12 -0700321 clk_dm(IMX8MN_CLK_QSPI,
322 imx8m_clk_composite("qspi", imx8mn_qspi_sels, base + 0xab80));
Ye Li0321edb2020-04-19 02:22:09 -0700323 clk_dm(IMX8MN_CLK_USB_CORE_REF,
324 imx8m_clk_composite("usb_core_ref", imx8mn_usb_core_sels, base + 0xb100));
325 clk_dm(IMX8MN_CLK_USB_PHY_REF,
326 imx8m_clk_composite("usb_phy_ref", imx8mn_usb_phy_sels, base + 0xb180));
Peng Fane2f674d2019-09-16 03:09:47 +0000327
328 clk_dm(IMX8MN_CLK_I2C1_ROOT,
329 imx_clk_gate4("i2c1_root_clk", "i2c1", base + 0x4170, 0));
330 clk_dm(IMX8MN_CLK_I2C2_ROOT,
331 imx_clk_gate4("i2c2_root_clk", "i2c2", base + 0x4180, 0));
332 clk_dm(IMX8MN_CLK_I2C3_ROOT,
333 imx_clk_gate4("i2c3_root_clk", "i2c3", base + 0x4190, 0));
334 clk_dm(IMX8MN_CLK_I2C4_ROOT,
335 imx_clk_gate4("i2c4_root_clk", "i2c4", base + 0x41a0, 0));
336 clk_dm(IMX8MN_CLK_OCOTP_ROOT,
337 imx_clk_gate4("ocotp_root_clk", "ipg_root", base + 0x4220, 0));
338 clk_dm(IMX8MN_CLK_USDHC1_ROOT,
339 imx_clk_gate4("usdhc1_root_clk", "usdhc1", base + 0x4510, 0));
340 clk_dm(IMX8MN_CLK_USDHC2_ROOT,
341 imx_clk_gate4("usdhc2_root_clk", "usdhc2", base + 0x4520, 0));
342 clk_dm(IMX8MN_CLK_WDOG1_ROOT,
343 imx_clk_gate4("wdog1_root_clk", "wdog", base + 0x4530, 0));
344 clk_dm(IMX8MN_CLK_WDOG2_ROOT,
345 imx_clk_gate4("wdog2_root_clk", "wdog", base + 0x4540, 0));
346 clk_dm(IMX8MN_CLK_WDOG3_ROOT,
347 imx_clk_gate4("wdog3_root_clk", "wdog", base + 0x4550, 0));
348 clk_dm(IMX8MN_CLK_USDHC3_ROOT,
349 imx_clk_gate4("usdhc3_root_clk", "usdhc3", base + 0x45e0, 0));
Ye Li418c1fc2020-04-18 08:19:12 -0700350 clk_dm(IMX8MN_CLK_QSPI_ROOT,
351 imx_clk_gate4("qspi_root_clk", "qspi", base + 0x42f0, 0));
Michael Trimarchi252e54e2022-08-30 16:45:20 +0200352 clk_dm(IMX8MN_CLK_NAND_ROOT,
353 imx_clk_gate2_shared2("nand_root_clk", "nand", base + 0x4300, 0, &share_count_nand));
354 clk_dm(IMX8MN_CLK_NAND_USDHC_BUS_RAWNAND_CLK,
355 imx_clk_gate2_shared2("nand_usdhc_rawnand_clk",
356 "nand_usdhc_bus", base + 0x4300, 0,
357 &share_count_nand));
Ye Li0321edb2020-04-19 02:22:09 -0700358 clk_dm(IMX8MN_CLK_USB1_CTRL_ROOT,
359 imx_clk_gate4("usb1_ctrl_root_clk", "usb_bus", base + 0x44d0, 0));
Ye Li418c1fc2020-04-18 08:19:12 -0700360
361 /* clks not needed in SPL stage */
362#ifndef CONFIG_SPL_BUILD
363 clk_dm(IMX8MN_CLK_ENET_REF,
364 imx8m_clk_composite("enet_ref", imx8mn_enet_ref_sels,
365 base + 0xa980));
366 clk_dm(IMX8MN_CLK_ENET_TIMER,
367 imx8m_clk_composite("enet_timer", imx8mn_enet_timer_sels,
368 base + 0xaa00));
369 clk_dm(IMX8MN_CLK_ENET_PHY_REF,
370 imx8m_clk_composite("enet_phy", imx8mn_enet_phy_sels,
371 base + 0xaa80));
372 clk_dm(IMX8MN_CLK_ENET1_ROOT,
373 imx_clk_gate4("enet1_root_clk", "enet_axi",
374 base + 0x40a0, 0));
Nicolas Heemerycke5e85232023-12-11 11:06:13 +0100375 clk_dm(IMX8MN_CLK_PWM1,
376 imx8m_clk_composite("pwm1", imx8mn_pwm1_sels, base + 0xb380));
377 clk_dm(IMX8MN_CLK_PWM2,
378 imx8m_clk_composite("pwm2", imx8mn_pwm2_sels, base + 0xb400));
379 clk_dm(IMX8MN_CLK_PWM3,
380 imx8m_clk_composite("pwm3", imx8mn_pwm3_sels, base + 0xb480));
381 clk_dm(IMX8MN_CLK_PWM4,
382 imx8m_clk_composite("pwm4", imx8mn_pwm4_sels, base + 0xb500));
383 clk_dm(IMX8MN_CLK_PWM1_ROOT,
384 imx_clk_gate4("pwm1_root_clk", "pwm1", base + 0x4280, 0));
385 clk_dm(IMX8MN_CLK_PWM2_ROOT,
386 imx_clk_gate4("pwm2_root_clk", "pwm2", base + 0x4290, 0));
387 clk_dm(IMX8MN_CLK_PWM3_ROOT,
388 imx_clk_gate4("pwm3_root_clk", "pwm3", base + 0x42a0, 0));
389 clk_dm(IMX8MN_CLK_PWM4_ROOT,
390 imx_clk_gate4("pwm4_root_clk", "pwm4", base + 0x42b0, 0));
Ye Li418c1fc2020-04-18 08:19:12 -0700391#endif
Peng Fane2f674d2019-09-16 03:09:47 +0000392
Marek Vasutb1a8bb02021-01-19 00:58:31 +0100393#if CONFIG_IS_ENABLED(DM_SPI)
394 clk_dm(IMX8MN_CLK_ECSPI1,
395 imx8m_clk_composite("ecspi1", imx8mn_ecspi1_sels, base + 0xb280));
396 clk_dm(IMX8MN_CLK_ECSPI2,
397 imx8m_clk_composite("ecspi2", imx8mn_ecspi2_sels, base + 0xb300));
398 clk_dm(IMX8MN_CLK_ECSPI3,
399 imx8m_clk_composite("ecspi3", imx8mn_ecspi3_sels, base + 0xc180));
400 clk_dm(IMX8MN_CLK_ECSPI1_ROOT,
401 imx_clk_gate4("ecspi1_root_clk", "ecspi1", base + 0x4070, 0));
402 clk_dm(IMX8MN_CLK_ECSPI2_ROOT,
403 imx_clk_gate4("ecspi2_root_clk", "ecspi2", base + 0x4080, 0));
404 clk_dm(IMX8MN_CLK_ECSPI3_ROOT,
405 imx_clk_gate4("ecspi3_root_clk", "ecspi3", base + 0x4090, 0));
406#endif
407
Hou Zhiqiang04a06432024-08-01 11:59:46 +0800408 clk_dm(IMX8MN_CLK_ARM,
409 imx_clk_mux2_flags("arm_core", base + 0x9880, 24, 1,
410 imx8mn_arm_core_sels,
411 ARRAY_SIZE(imx8mn_arm_core_sels),
412 CLK_IS_CRITICAL));
413
Peng Fane2f674d2019-09-16 03:09:47 +0000414 return 0;
415}
416
417static const struct udevice_id imx8mn_clk_ids[] = {
418 { .compatible = "fsl,imx8mn-ccm" },
419 { },
420};
421
422U_BOOT_DRIVER(imx8mn_clk) = {
423 .name = "clk_imx8mn",
424 .id = UCLASS_CLK,
425 .of_match = imx8mn_clk_ids,
Sean Anderson35c84642022-03-20 16:34:46 -0400426 .ops = &ccf_clk_ops,
Peng Fane2f674d2019-09-16 03:09:47 +0000427 .probe = imx8mn_clk_probe,
428 .flags = DM_FLAG_PRE_RELOC,
429};