blob: bfd1677520520d5bb28a9cacc78fc6f4e3c50fcf [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
Peng Fane2f674d2019-09-16 03:09:47 +000019static const char *pll_ref_sels[] = { "clock-osc-24m", "dummy", "dummy", "dummy", };
20static const char *dram_pll_bypass_sels[] = {"dram_pll", "dram_pll_ref_sel", };
21static const char *arm_pll_bypass_sels[] = {"arm_pll", "arm_pll_ref_sel", };
22static const char *sys_pll1_bypass_sels[] = {"sys_pll1", "sys_pll1_ref_sel", };
23static const char *sys_pll2_bypass_sels[] = {"sys_pll2", "sys_pll2_ref_sel", };
24static const char *sys_pll3_bypass_sels[] = {"sys_pll3", "sys_pll3_ref_sel", };
25
26static const char *imx8mn_a53_sels[] = {"clock-osc-24m", "arm_pll_out", "sys_pll2_500m", "sys_pll2_1000m",
27 "sys_pll1_800m", "sys_pll1_400m", "audio_pll1_out", "sys_pll3_out", };
28
29static const char *imx8mn_ahb_sels[] = {"clock-osc-24m", "sys_pll1_133m", "sys_pll1_800m", "sys_pll1_400m",
Dario Binacchi2f51cf92022-12-19 12:31:25 +010030 "sys_pll2_125m", "sys_pll3_out", "audio_pll1_out", "video_pll_out", };
Peng Fane2f674d2019-09-16 03:09:47 +000031
32static const char *imx8mn_enet_axi_sels[] = {"clock-osc-24m", "sys_pll1_266m", "sys_pll1_800m", "sys_pll2_250m",
Dario Binacchi2f51cf92022-12-19 12:31:25 +010033 "sys_pll2_200m", "audio_pll1_out", "video_pll_out", "sys_pll3_out", };
Peng Fane2f674d2019-09-16 03:09:47 +000034
Ye Li418c1fc2020-04-18 08:19:12 -070035#ifndef CONFIG_SPL_BUILD
36static const char *imx8mn_enet_ref_sels[] = {"clock-osc-24m", "sys_pll2_125m", "sys_pll2_50m", "sys_pll2_100m",
Dario Binacchi2f51cf92022-12-19 12:31:25 +010037 "sys_pll1_160m", "audio_pll1_out", "video_pll_out", "clk_ext4", };
Ye Li418c1fc2020-04-18 08:19:12 -070038
39static const char *imx8mn_enet_timer_sels[] = {"clock-osc-24m", "sys_pll2_100m", "audio_pll1_out", "clk_ext1", "clk_ext2",
Dario Binacchi2f51cf92022-12-19 12:31:25 +010040 "clk_ext3", "clk_ext4", "video_pll_out", };
Ye Li418c1fc2020-04-18 08:19:12 -070041
42static const char *imx8mn_enet_phy_sels[] = {"clock-osc-24m", "sys_pll2_50m", "sys_pll2_125m", "sys_pll2_200m",
Dario Binacchi91f8c0b2022-12-19 12:31:26 +010043 "sys_pll2_500m", "audio_pll1_out", "video_pll_out", "audio_pll2_out", };
Ye Li418c1fc2020-04-18 08:19:12 -070044#endif
45
Peng Fane2f674d2019-09-16 03:09:47 +000046static const char *imx8mn_nand_usdhc_sels[] = {"clock-osc-24m", "sys_pll1_266m", "sys_pll1_800m", "sys_pll2_200m",
47 "sys_pll1_133m", "sys_pll3_out", "sys_pll2_250m", "audio_pll1_out", };
48
Ye Li0321edb2020-04-19 02:22:09 -070049static const char * const imx8mn_usb_bus_sels[] = {"clock-osc-24m", "sys_pll2_500m", "sys_pll1_800m",
50 "sys_pll2_100m", "sys_pll2_200m", "clk_ext2",
51 "clk_ext4", "audio_pll2_out", };
52
Peng Fane2f674d2019-09-16 03:09:47 +000053static const char *imx8mn_usdhc1_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll1_800m", "sys_pll2_500m",
54 "sys_pll3_out", "sys_pll1_266m", "audio_pll2_out", "sys_pll1_100m", };
55
56static const char *imx8mn_usdhc2_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll1_800m", "sys_pll2_500m",
57 "sys_pll3_out", "sys_pll1_266m", "audio_pll2_out", "sys_pll1_100m", };
58
Marek Vasutb1a8bb02021-01-19 00:58:31 +010059#if CONFIG_IS_ENABLED(DM_SPI)
Michael Trimarchi24685832024-07-07 10:19:58 +020060static const char *imx8mn_ecspi1_sels[] = {"clock-osc-24m", "sys_pll2_200m", "sys_pll1_40m",
Marek Vasutb1a8bb02021-01-19 00:58:31 +010061 "sys_pll1_160m", "sys_pll1_800m", "sys_pll3_out",
62 "sys_pll2_250m", "audio_pll2_out", };
63
Michael Trimarchi24685832024-07-07 10:19:58 +020064static const char *imx8mn_ecspi2_sels[] = {"clock-osc-24m", "sys_pll2_200m", "sys_pll1_40m",
Marek Vasutb1a8bb02021-01-19 00:58:31 +010065 "sys_pll1_160m", "sys_pll1_800m", "sys_pll3_out",
66 "sys_pll2_250m", "audio_pll2_out", };
67
Michael Trimarchi24685832024-07-07 10:19:58 +020068static const char *imx8mn_ecspi3_sels[] = {"clock-osc-24m", "sys_pll2_200m", "sys_pll1_40m",
Marek Vasutb1a8bb02021-01-19 00:58:31 +010069 "sys_pll1_160m", "sys_pll1_800m", "sys_pll3_out",
70 "sys_pll2_250m", "audio_pll2_out", };
71#endif
72
Peng Fane2f674d2019-09-16 03:09:47 +000073static const char *imx8mn_i2c1_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m", "sys_pll3_out", "audio_pll1_out",
Dario Binacchi2f51cf92022-12-19 12:31:25 +010074 "video_pll_out", "audio_pll2_out", "sys_pll1_133m", };
Peng Fane2f674d2019-09-16 03:09:47 +000075
76static const char *imx8mn_i2c2_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m", "sys_pll3_out", "audio_pll1_out",
Dario Binacchi2f51cf92022-12-19 12:31:25 +010077 "video_pll_out", "audio_pll2_out", "sys_pll1_133m", };
Peng Fane2f674d2019-09-16 03:09:47 +000078
79static const char *imx8mn_i2c3_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m", "sys_pll3_out", "audio_pll1_out",
Dario Binacchi2f51cf92022-12-19 12:31:25 +010080 "video_pll_out", "audio_pll2_out", "sys_pll1_133m", };
Peng Fane2f674d2019-09-16 03:09:47 +000081
82static const char *imx8mn_i2c4_sels[] = {"clock-osc-24m", "sys_pll1_160m", "sys_pll2_50m", "sys_pll3_out", "audio_pll1_out",
Dario Binacchi2f51cf92022-12-19 12:31:25 +010083 "video_pll_out", "audio_pll2_out", "sys_pll1_133m", };
Peng Fane2f674d2019-09-16 03:09:47 +000084
Nicolas Heemerycke5e85232023-12-11 11:06:13 +010085#ifndef CONFIG_SPL_BUILD
86static const char *imx8mn_pwm1_sels[] = {"clock-osc-24m", "sys_pll2_100m", "sys_pll1_160m", "sys_pll1_40m",
87 "sys_pll3_out", "clk_ext1", "sys_pll1_80m", "video_pll_out", };
88
89static const char *imx8mn_pwm2_sels[] = {"clock-osc-24m", "sys_pll2_100m", "sys_pll1_160m", "sys_pll1_40m",
90 "sys_pll3_out", "clk_ext1", "sys_pll1_80m", "video_pll_out", };
91
92static const char *imx8mn_pwm3_sels[] = {"clock-osc-24m", "sys_pll2_100m", "sys_pll1_160m", "sys_pll1_40m",
93 "sys_pll3_out", "clk_ext2", "sys_pll1_80m", "video_pll_out", };
94
95static const char *imx8mn_pwm4_sels[] = {"clock-osc-24m", "sys_pll2_100m", "sys_pll1_160m", "sys_pll1_40m",
96 "sys_pll3_out", "clk_ext2", "sys_pll1_80m", "video_pll_out", };
97#endif
98
Dario Binacchi22d85d22022-12-19 12:31:24 +010099static const char *imx8mn_wdog_sels[] = {"clock-osc-24m", "sys_pll1_133m", "sys_pll1_160m", "m7_alt_pll",
Peng Fane2f674d2019-09-16 03:09:47 +0000100 "sys_pll2_125m", "sys_pll3_out", "sys_pll1_80m", "sys_pll2_166m", };
101
102static const char *imx8mn_usdhc3_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll1_800m", "sys_pll2_500m",
103 "sys_pll3_out", "sys_pll1_266m", "audio_pll2_clk", "sys_pll1_100m", };
104
Ye Li418c1fc2020-04-18 08:19:12 -0700105static const char *imx8mn_qspi_sels[] = {"clock-osc-24m", "sys_pll1_400m", "sys_pll2_333m", "sys_pll2_500m",
106 "audio_pll2_out", "sys_pll1_266m", "sys_pll3_out", "sys_pll1_100m", };
107
Michael Trimarchi24685832024-07-07 10:19:58 +0200108static const char * const imx8mn_nand_sels[] = {"clock-osc-24m", "sys_pll2_500m", "audio_pll1_out",
Michael Trimarchi252e54e2022-08-30 16:45:20 +0200109 "sys_pll1_400m", "audio_pll2_out", "sys_pll3_out",
Dario Binacchi2f51cf92022-12-19 12:31:25 +0100110 "sys_pll2_250m", "video_pll_out", };
Michael Trimarchi252e54e2022-08-30 16:45:20 +0200111
Ye Li0321edb2020-04-19 02:22:09 -0700112static const char * const imx8mn_usb_core_sels[] = {"clock-osc-24m", "sys_pll1_100m", "sys_pll1_40m",
113 "sys_pll2_100m", "sys_pll2_200m", "clk_ext2",
114 "clk_ext3", "audio_pll2_out", };
115
116static const char * const imx8mn_usb_phy_sels[] = {"clock-osc-24m", "sys_pll1_100m", "sys_pll1_40m",
117 "sys_pll2_100m", "sys_pll2_200m", "clk_ext2",
118 "clk_ext3", "audio_pll2_out", };
119
Peng Fane2f674d2019-09-16 03:09:47 +0000120static int imx8mn_clk_probe(struct udevice *dev)
121{
Michael Trimarchi24685832024-07-07 10:19:58 +0200122 struct clk osc_24m_clk;
Peng Fane2f674d2019-09-16 03:09:47 +0000123 void __iomem *base;
Michael Trimarchi24685832024-07-07 10:19:58 +0200124 int ret;
Peng Fane2f674d2019-09-16 03:09:47 +0000125
126 base = (void *)ANATOP_BASE_ADDR;
127
128 clk_dm(IMX8MN_DRAM_PLL_REF_SEL,
129 imx_clk_mux("dram_pll_ref_sel", base + 0x50, 0, 2,
130 pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
131 clk_dm(IMX8MN_ARM_PLL_REF_SEL,
132 imx_clk_mux("arm_pll_ref_sel", base + 0x84, 0, 2,
133 pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
134 clk_dm(IMX8MN_SYS_PLL1_REF_SEL,
135 imx_clk_mux("sys_pll1_ref_sel", base + 0x94, 0, 2,
136 pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
137 clk_dm(IMX8MN_SYS_PLL2_REF_SEL,
138 imx_clk_mux("sys_pll2_ref_sel", base + 0x104, 0, 2,
139 pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
140 clk_dm(IMX8MN_SYS_PLL3_REF_SEL,
141 imx_clk_mux("sys_pll3_ref_sel", base + 0x114, 0, 2,
142 pll_ref_sels, ARRAY_SIZE(pll_ref_sels)));
143
144 clk_dm(IMX8MN_DRAM_PLL,
145 imx_clk_pll14xx("dram_pll", "dram_pll_ref_sel",
Angus Ainslie73d75ec2022-03-29 07:02:40 -0700146 base + 0x50, &imx_1443x_dram_pll));
Peng Fane2f674d2019-09-16 03:09:47 +0000147 clk_dm(IMX8MN_ARM_PLL,
148 imx_clk_pll14xx("arm_pll", "arm_pll_ref_sel",
Angus Ainslie73d75ec2022-03-29 07:02:40 -0700149 base + 0x84, &imx_1416x_pll));
Peng Fane2f674d2019-09-16 03:09:47 +0000150 clk_dm(IMX8MN_SYS_PLL1,
151 imx_clk_pll14xx("sys_pll1", "sys_pll1_ref_sel",
Angus Ainslie73d75ec2022-03-29 07:02:40 -0700152 base + 0x94, &imx_1416x_pll));
Peng Fane2f674d2019-09-16 03:09:47 +0000153 clk_dm(IMX8MN_SYS_PLL2,
154 imx_clk_pll14xx("sys_pll2", "sys_pll2_ref_sel",
Angus Ainslie73d75ec2022-03-29 07:02:40 -0700155 base + 0x104, &imx_1416x_pll));
Peng Fane2f674d2019-09-16 03:09:47 +0000156 clk_dm(IMX8MN_SYS_PLL3,
157 imx_clk_pll14xx("sys_pll3", "sys_pll3_ref_sel",
Angus Ainslie73d75ec2022-03-29 07:02:40 -0700158 base + 0x114, &imx_1416x_pll));
Peng Fane2f674d2019-09-16 03:09:47 +0000159
160 /* PLL bypass out */
161 clk_dm(IMX8MN_DRAM_PLL_BYPASS,
162 imx_clk_mux_flags("dram_pll_bypass", base + 0x50, 4, 1,
163 dram_pll_bypass_sels,
164 ARRAY_SIZE(dram_pll_bypass_sels),
165 CLK_SET_RATE_PARENT));
166 clk_dm(IMX8MN_ARM_PLL_BYPASS,
167 imx_clk_mux_flags("arm_pll_bypass", base + 0x84, 4, 1,
168 arm_pll_bypass_sels,
169 ARRAY_SIZE(arm_pll_bypass_sels),
170 CLK_SET_RATE_PARENT));
171 clk_dm(IMX8MN_SYS_PLL1_BYPASS,
172 imx_clk_mux_flags("sys_pll1_bypass", base + 0x94, 4, 1,
173 sys_pll1_bypass_sels,
174 ARRAY_SIZE(sys_pll1_bypass_sels),
175 CLK_SET_RATE_PARENT));
176 clk_dm(IMX8MN_SYS_PLL2_BYPASS,
177 imx_clk_mux_flags("sys_pll2_bypass", base + 0x104, 4, 1,
178 sys_pll2_bypass_sels,
179 ARRAY_SIZE(sys_pll2_bypass_sels),
180 CLK_SET_RATE_PARENT));
181 clk_dm(IMX8MN_SYS_PLL3_BYPASS,
182 imx_clk_mux_flags("sys_pll3_bypass", base + 0x114, 4, 1,
183 sys_pll3_bypass_sels,
184 ARRAY_SIZE(sys_pll3_bypass_sels),
185 CLK_SET_RATE_PARENT));
186
187 /* PLL out gate */
188 clk_dm(IMX8MN_DRAM_PLL_OUT,
189 imx_clk_gate("dram_pll_out", "dram_pll_bypass",
190 base + 0x50, 13));
191 clk_dm(IMX8MN_ARM_PLL_OUT,
192 imx_clk_gate("arm_pll_out", "arm_pll_bypass",
193 base + 0x84, 11));
194 clk_dm(IMX8MN_SYS_PLL1_OUT,
195 imx_clk_gate("sys_pll1_out", "sys_pll1_bypass",
196 base + 0x94, 11));
197 clk_dm(IMX8MN_SYS_PLL2_OUT,
198 imx_clk_gate("sys_pll2_out", "sys_pll2_bypass",
199 base + 0x104, 11));
200 clk_dm(IMX8MN_SYS_PLL3_OUT,
201 imx_clk_gate("sys_pll3_out", "sys_pll3_bypass",
202 base + 0x114, 11));
203
204 /* SYS PLL fixed output */
205 clk_dm(IMX8MN_SYS_PLL1_40M,
206 imx_clk_fixed_factor("sys_pll1_40m", "sys_pll1_out", 1, 20));
207 clk_dm(IMX8MN_SYS_PLL1_80M,
208 imx_clk_fixed_factor("sys_pll1_80m", "sys_pll1_out", 1, 10));
209 clk_dm(IMX8MN_SYS_PLL1_100M,
210 imx_clk_fixed_factor("sys_pll1_100m", "sys_pll1_out", 1, 8));
211 clk_dm(IMX8MN_SYS_PLL1_133M,
212 imx_clk_fixed_factor("sys_pll1_133m", "sys_pll1_out", 1, 6));
213 clk_dm(IMX8MN_SYS_PLL1_160M,
214 imx_clk_fixed_factor("sys_pll1_160m", "sys_pll1_out", 1, 5));
215 clk_dm(IMX8MN_SYS_PLL1_200M,
216 imx_clk_fixed_factor("sys_pll1_200m", "sys_pll1_out", 1, 4));
217 clk_dm(IMX8MN_SYS_PLL1_266M,
218 imx_clk_fixed_factor("sys_pll1_266m", "sys_pll1_out", 1, 3));
219 clk_dm(IMX8MN_SYS_PLL1_400M,
220 imx_clk_fixed_factor("sys_pll1_400m", "sys_pll1_out", 1, 2));
221 clk_dm(IMX8MN_SYS_PLL1_800M,
222 imx_clk_fixed_factor("sys_pll1_800m", "sys_pll1_out", 1, 1));
223
224 clk_dm(IMX8MN_SYS_PLL2_50M,
225 imx_clk_fixed_factor("sys_pll2_50m", "sys_pll2_out", 1, 20));
226 clk_dm(IMX8MN_SYS_PLL2_100M,
227 imx_clk_fixed_factor("sys_pll2_100m", "sys_pll2_out", 1, 10));
228 clk_dm(IMX8MN_SYS_PLL2_125M,
229 imx_clk_fixed_factor("sys_pll2_125m", "sys_pll2_out", 1, 8));
230 clk_dm(IMX8MN_SYS_PLL2_166M,
231 imx_clk_fixed_factor("sys_pll2_166m", "sys_pll2_out", 1, 6));
232 clk_dm(IMX8MN_SYS_PLL2_200M,
233 imx_clk_fixed_factor("sys_pll2_200m", "sys_pll2_out", 1, 5));
234 clk_dm(IMX8MN_SYS_PLL2_250M,
235 imx_clk_fixed_factor("sys_pll2_250m", "sys_pll2_out", 1, 4));
236 clk_dm(IMX8MN_SYS_PLL2_333M,
237 imx_clk_fixed_factor("sys_pll2_333m", "sys_pll2_out", 1, 3));
238 clk_dm(IMX8MN_SYS_PLL2_500M,
239 imx_clk_fixed_factor("sys_pll2_500m", "sys_pll2_out", 1, 2));
240 clk_dm(IMX8MN_SYS_PLL2_1000M,
241 imx_clk_fixed_factor("sys_pll2_1000m", "sys_pll2_out", 1, 1));
242
Michael Trimarchi24685832024-07-07 10:19:58 +0200243 ret = clk_get_by_name(dev, "osc_24m", &osc_24m_clk);
244 if (ret)
245 return ret;
246 clk_dm(IMX8MN_CLK_24M, dev_get_clk_ptr(osc_24m_clk.dev));
247
Peng Fane2f674d2019-09-16 03:09:47 +0000248 base = dev_read_addr_ptr(dev);
Sean Andersonb58106d2019-12-24 23:57:47 -0500249 if (!base)
Peng Fane2f674d2019-09-16 03:09:47 +0000250 return -EINVAL;
251
252 clk_dm(IMX8MN_CLK_A53_SRC,
253 imx_clk_mux2("arm_a53_src", base + 0x8000, 24, 3,
254 imx8mn_a53_sels, ARRAY_SIZE(imx8mn_a53_sels)));
255 clk_dm(IMX8MN_CLK_A53_CG,
256 imx_clk_gate3("arm_a53_cg", "arm_a53_src", base + 0x8000, 28));
257 clk_dm(IMX8MN_CLK_A53_DIV,
258 imx_clk_divider2("arm_a53_div", "arm_a53_cg",
259 base + 0x8000, 0, 3));
260
261 clk_dm(IMX8MN_CLK_AHB,
262 imx8m_clk_composite_critical("ahb", imx8mn_ahb_sels,
263 base + 0x9000));
264 clk_dm(IMX8MN_CLK_IPG_ROOT,
265 imx_clk_divider2("ipg_root", "ahb", base + 0x9080, 0, 1));
266
267 clk_dm(IMX8MN_CLK_ENET_AXI,
268 imx8m_clk_composite("enet_axi", imx8mn_enet_axi_sels,
269 base + 0x8880));
270 clk_dm(IMX8MN_CLK_NAND_USDHC_BUS,
271 imx8m_clk_composite_critical("nand_usdhc_bus",
272 imx8mn_nand_usdhc_sels,
273 base + 0x8900));
Ye Li0321edb2020-04-19 02:22:09 -0700274 clk_dm(IMX8MN_CLK_USB_BUS,
275 imx8m_clk_composite("usb_bus", imx8mn_usb_bus_sels, base + 0x8b80));
Peng Fane2f674d2019-09-16 03:09:47 +0000276
277 /* IP */
278 clk_dm(IMX8MN_CLK_USDHC1,
279 imx8m_clk_composite("usdhc1", imx8mn_usdhc1_sels,
280 base + 0xac00));
281 clk_dm(IMX8MN_CLK_USDHC2,
282 imx8m_clk_composite("usdhc2", imx8mn_usdhc2_sels,
283 base + 0xac80));
284 clk_dm(IMX8MN_CLK_I2C1,
285 imx8m_clk_composite("i2c1", imx8mn_i2c1_sels, base + 0xad00));
286 clk_dm(IMX8MN_CLK_I2C2,
287 imx8m_clk_composite("i2c2", imx8mn_i2c2_sels, base + 0xad80));
288 clk_dm(IMX8MN_CLK_I2C3,
289 imx8m_clk_composite("i2c3", imx8mn_i2c3_sels, base + 0xae00));
290 clk_dm(IMX8MN_CLK_I2C4,
291 imx8m_clk_composite("i2c4", imx8mn_i2c4_sels, base + 0xae80));
292 clk_dm(IMX8MN_CLK_WDOG,
293 imx8m_clk_composite("wdog", imx8mn_wdog_sels, base + 0xb900));
294 clk_dm(IMX8MN_CLK_USDHC3,
295 imx8m_clk_composite("usdhc3", imx8mn_usdhc3_sels,
296 base + 0xbc80));
Michael Trimarchi252e54e2022-08-30 16:45:20 +0200297 clk_dm(IMX8MN_CLK_NAND,
298 imx8m_clk_composite("nand", imx8mn_nand_sels, base + 0xab00));
Ye Li418c1fc2020-04-18 08:19:12 -0700299 clk_dm(IMX8MN_CLK_QSPI,
300 imx8m_clk_composite("qspi", imx8mn_qspi_sels, base + 0xab80));
Ye Li0321edb2020-04-19 02:22:09 -0700301 clk_dm(IMX8MN_CLK_USB_CORE_REF,
302 imx8m_clk_composite("usb_core_ref", imx8mn_usb_core_sels, base + 0xb100));
303 clk_dm(IMX8MN_CLK_USB_PHY_REF,
304 imx8m_clk_composite("usb_phy_ref", imx8mn_usb_phy_sels, base + 0xb180));
Peng Fane2f674d2019-09-16 03:09:47 +0000305
306 clk_dm(IMX8MN_CLK_I2C1_ROOT,
307 imx_clk_gate4("i2c1_root_clk", "i2c1", base + 0x4170, 0));
308 clk_dm(IMX8MN_CLK_I2C2_ROOT,
309 imx_clk_gate4("i2c2_root_clk", "i2c2", base + 0x4180, 0));
310 clk_dm(IMX8MN_CLK_I2C3_ROOT,
311 imx_clk_gate4("i2c3_root_clk", "i2c3", base + 0x4190, 0));
312 clk_dm(IMX8MN_CLK_I2C4_ROOT,
313 imx_clk_gate4("i2c4_root_clk", "i2c4", base + 0x41a0, 0));
314 clk_dm(IMX8MN_CLK_OCOTP_ROOT,
315 imx_clk_gate4("ocotp_root_clk", "ipg_root", base + 0x4220, 0));
316 clk_dm(IMX8MN_CLK_USDHC1_ROOT,
317 imx_clk_gate4("usdhc1_root_clk", "usdhc1", base + 0x4510, 0));
318 clk_dm(IMX8MN_CLK_USDHC2_ROOT,
319 imx_clk_gate4("usdhc2_root_clk", "usdhc2", base + 0x4520, 0));
320 clk_dm(IMX8MN_CLK_WDOG1_ROOT,
321 imx_clk_gate4("wdog1_root_clk", "wdog", base + 0x4530, 0));
322 clk_dm(IMX8MN_CLK_WDOG2_ROOT,
323 imx_clk_gate4("wdog2_root_clk", "wdog", base + 0x4540, 0));
324 clk_dm(IMX8MN_CLK_WDOG3_ROOT,
325 imx_clk_gate4("wdog3_root_clk", "wdog", base + 0x4550, 0));
326 clk_dm(IMX8MN_CLK_USDHC3_ROOT,
327 imx_clk_gate4("usdhc3_root_clk", "usdhc3", base + 0x45e0, 0));
Ye Li418c1fc2020-04-18 08:19:12 -0700328 clk_dm(IMX8MN_CLK_QSPI_ROOT,
329 imx_clk_gate4("qspi_root_clk", "qspi", base + 0x42f0, 0));
Michael Trimarchi252e54e2022-08-30 16:45:20 +0200330 clk_dm(IMX8MN_CLK_NAND_ROOT,
331 imx_clk_gate2_shared2("nand_root_clk", "nand", base + 0x4300, 0, &share_count_nand));
332 clk_dm(IMX8MN_CLK_NAND_USDHC_BUS_RAWNAND_CLK,
333 imx_clk_gate2_shared2("nand_usdhc_rawnand_clk",
334 "nand_usdhc_bus", base + 0x4300, 0,
335 &share_count_nand));
Ye Li0321edb2020-04-19 02:22:09 -0700336 clk_dm(IMX8MN_CLK_USB1_CTRL_ROOT,
337 imx_clk_gate4("usb1_ctrl_root_clk", "usb_bus", base + 0x44d0, 0));
Ye Li418c1fc2020-04-18 08:19:12 -0700338
339 /* clks not needed in SPL stage */
340#ifndef CONFIG_SPL_BUILD
341 clk_dm(IMX8MN_CLK_ENET_REF,
342 imx8m_clk_composite("enet_ref", imx8mn_enet_ref_sels,
343 base + 0xa980));
344 clk_dm(IMX8MN_CLK_ENET_TIMER,
345 imx8m_clk_composite("enet_timer", imx8mn_enet_timer_sels,
346 base + 0xaa00));
347 clk_dm(IMX8MN_CLK_ENET_PHY_REF,
348 imx8m_clk_composite("enet_phy", imx8mn_enet_phy_sels,
349 base + 0xaa80));
350 clk_dm(IMX8MN_CLK_ENET1_ROOT,
351 imx_clk_gate4("enet1_root_clk", "enet_axi",
352 base + 0x40a0, 0));
Nicolas Heemerycke5e85232023-12-11 11:06:13 +0100353 clk_dm(IMX8MN_CLK_PWM1,
354 imx8m_clk_composite("pwm1", imx8mn_pwm1_sels, base + 0xb380));
355 clk_dm(IMX8MN_CLK_PWM2,
356 imx8m_clk_composite("pwm2", imx8mn_pwm2_sels, base + 0xb400));
357 clk_dm(IMX8MN_CLK_PWM3,
358 imx8m_clk_composite("pwm3", imx8mn_pwm3_sels, base + 0xb480));
359 clk_dm(IMX8MN_CLK_PWM4,
360 imx8m_clk_composite("pwm4", imx8mn_pwm4_sels, base + 0xb500));
361 clk_dm(IMX8MN_CLK_PWM1_ROOT,
362 imx_clk_gate4("pwm1_root_clk", "pwm1", base + 0x4280, 0));
363 clk_dm(IMX8MN_CLK_PWM2_ROOT,
364 imx_clk_gate4("pwm2_root_clk", "pwm2", base + 0x4290, 0));
365 clk_dm(IMX8MN_CLK_PWM3_ROOT,
366 imx_clk_gate4("pwm3_root_clk", "pwm3", base + 0x42a0, 0));
367 clk_dm(IMX8MN_CLK_PWM4_ROOT,
368 imx_clk_gate4("pwm4_root_clk", "pwm4", base + 0x42b0, 0));
Ye Li418c1fc2020-04-18 08:19:12 -0700369#endif
Peng Fane2f674d2019-09-16 03:09:47 +0000370
Marek Vasutb1a8bb02021-01-19 00:58:31 +0100371#if CONFIG_IS_ENABLED(DM_SPI)
372 clk_dm(IMX8MN_CLK_ECSPI1,
373 imx8m_clk_composite("ecspi1", imx8mn_ecspi1_sels, base + 0xb280));
374 clk_dm(IMX8MN_CLK_ECSPI2,
375 imx8m_clk_composite("ecspi2", imx8mn_ecspi2_sels, base + 0xb300));
376 clk_dm(IMX8MN_CLK_ECSPI3,
377 imx8m_clk_composite("ecspi3", imx8mn_ecspi3_sels, base + 0xc180));
378 clk_dm(IMX8MN_CLK_ECSPI1_ROOT,
379 imx_clk_gate4("ecspi1_root_clk", "ecspi1", base + 0x4070, 0));
380 clk_dm(IMX8MN_CLK_ECSPI2_ROOT,
381 imx_clk_gate4("ecspi2_root_clk", "ecspi2", base + 0x4080, 0));
382 clk_dm(IMX8MN_CLK_ECSPI3_ROOT,
383 imx_clk_gate4("ecspi3_root_clk", "ecspi3", base + 0x4090, 0));
384#endif
385
Peng Fane2f674d2019-09-16 03:09:47 +0000386 return 0;
387}
388
389static const struct udevice_id imx8mn_clk_ids[] = {
390 { .compatible = "fsl,imx8mn-ccm" },
391 { },
392};
393
394U_BOOT_DRIVER(imx8mn_clk) = {
395 .name = "clk_imx8mn",
396 .id = UCLASS_CLK,
397 .of_match = imx8mn_clk_ids,
Sean Anderson35c84642022-03-20 16:34:46 -0400398 .ops = &ccf_clk_ops,
Peng Fane2f674d2019-09-16 03:09:47 +0000399 .probe = imx8mn_clk_probe,
400 .flags = DM_FLAG_PRE_RELOC,
401};