1 // SPDX-License-Identifier: GPL-2.0
8 #include <clk-uclass.h>
11 #include <asm/arch/sci/sci.h>
12 #include <asm/arch/clock.h>
13 #include <dt-bindings/clock/imx8qm-clock.h>
14 #include <dt-bindings/soc/imx_rsrc.h>
19 #if CONFIG_IS_ENABLED(CMD_CLK)
20 struct imx8_clks imx8_clk_names[] = {
21 { IMX8QM_A53_DIV, "A53_DIV" },
22 { IMX8QM_UART0_CLK, "UART0" },
23 { IMX8QM_UART1_CLK, "UART1" },
24 { IMX8QM_UART2_CLK, "UART2" },
25 { IMX8QM_UART3_CLK, "UART3" },
26 { IMX8QM_SDHC0_CLK, "SDHC0" },
27 { IMX8QM_SDHC1_CLK, "SDHC1" },
28 { IMX8QM_SDHC2_CLK, "SDHC2" },
29 { IMX8QM_ENET0_AHB_CLK, "ENET0_AHB" },
30 { IMX8QM_ENET0_IPG_CLK, "ENET0_IPG" },
31 { IMX8QM_ENET0_REF_DIV, "ENET0_REF" },
32 { IMX8QM_ENET0_PTP_CLK, "ENET0_PTP" },
33 { IMX8QM_ENET1_AHB_CLK, "ENET1_AHB" },
34 { IMX8QM_ENET1_IPG_CLK, "ENET1_IPG" },
35 { IMX8QM_ENET1_REF_DIV, "ENET1_REF" },
36 { IMX8QM_ENET1_PTP_CLK, "ENET1_PTP" },
39 int num_clks = ARRAY_SIZE(imx8_clk_names);
42 ulong imx8_clk_get_rate(struct clk *clk)
49 debug("%s(#%lu)\n", __func__, clk->id);
54 pm_clk = SC_PM_CLK_CPU;
57 resource = SC_R_I2C_0;
58 pm_clk = SC_PM_CLK_PER;
61 resource = SC_R_I2C_1;
62 pm_clk = SC_PM_CLK_PER;
65 resource = SC_R_I2C_2;
66 pm_clk = SC_PM_CLK_PER;
69 resource = SC_R_I2C_3;
70 pm_clk = SC_PM_CLK_PER;
72 case IMX8QM_SDHC0_IPG_CLK:
73 case IMX8QM_SDHC0_CLK:
74 case IMX8QM_SDHC0_DIV:
75 resource = SC_R_SDHC_0;
76 pm_clk = SC_PM_CLK_PER;
78 case IMX8QM_SDHC1_IPG_CLK:
79 case IMX8QM_SDHC1_CLK:
80 case IMX8QM_SDHC1_DIV:
81 resource = SC_R_SDHC_1;
82 pm_clk = SC_PM_CLK_PER;
84 case IMX8QM_SDHC2_IPG_CLK:
85 case IMX8QM_SDHC2_CLK:
86 case IMX8QM_SDHC2_DIV:
87 resource = SC_R_SDHC_2;
88 pm_clk = SC_PM_CLK_PER;
90 case IMX8QM_UART0_IPG_CLK:
91 case IMX8QM_UART0_CLK:
92 resource = SC_R_UART_0;
93 pm_clk = SC_PM_CLK_PER;
95 case IMX8QM_UART1_CLK:
96 resource = SC_R_UART_1;
97 pm_clk = SC_PM_CLK_PER;
99 case IMX8QM_UART2_CLK:
100 resource = SC_R_UART_2;
101 pm_clk = SC_PM_CLK_PER;
103 case IMX8QM_UART3_CLK:
104 resource = SC_R_UART_3;
105 pm_clk = SC_PM_CLK_PER;
107 case IMX8QM_ENET0_IPG_CLK:
108 case IMX8QM_ENET0_AHB_CLK:
109 case IMX8QM_ENET0_REF_DIV:
110 case IMX8QM_ENET0_PTP_CLK:
111 resource = SC_R_ENET_0;
112 pm_clk = SC_PM_CLK_PER;
114 case IMX8QM_ENET1_IPG_CLK:
115 case IMX8QM_ENET1_AHB_CLK:
116 case IMX8QM_ENET1_REF_DIV:
117 case IMX8QM_ENET1_PTP_CLK:
118 resource = SC_R_ENET_1;
119 pm_clk = SC_PM_CLK_PER;
122 if (clk->id < IMX8QM_UART0_IPG_CLK ||
123 clk->id >= IMX8QM_CLK_END) {
124 printf("%s(Invalid clk ID #%lu)\n",
131 ret = sc_pm_get_clock_rate(-1, resource, pm_clk,
132 (sc_pm_clock_rate_t *)&rate);
134 printf("%s err %d\n", __func__, ret);
141 ulong imx8_clk_set_rate(struct clk *clk, unsigned long rate)
148 debug("%s(#%lu), rate: %lu\n", __func__, clk->id, rate);
151 case IMX8QM_I2C0_CLK:
152 resource = SC_R_I2C_0;
153 pm_clk = SC_PM_CLK_PER;
155 case IMX8QM_I2C1_CLK:
156 resource = SC_R_I2C_1;
157 pm_clk = SC_PM_CLK_PER;
159 case IMX8QM_I2C2_CLK:
160 resource = SC_R_I2C_2;
161 pm_clk = SC_PM_CLK_PER;
163 case IMX8QM_I2C3_CLK:
164 resource = SC_R_I2C_3;
165 pm_clk = SC_PM_CLK_PER;
167 case IMX8QM_UART0_CLK:
168 resource = SC_R_UART_0;
169 pm_clk = SC_PM_CLK_PER;
171 case IMX8QM_UART1_CLK:
172 resource = SC_R_UART_1;
173 pm_clk = SC_PM_CLK_PER;
175 case IMX8QM_UART2_CLK:
176 resource = SC_R_UART_2;
177 pm_clk = SC_PM_CLK_PER;
179 case IMX8QM_UART3_CLK:
180 resource = SC_R_UART_3;
181 pm_clk = SC_PM_CLK_PER;
183 case IMX8QM_SDHC0_IPG_CLK:
184 case IMX8QM_SDHC0_CLK:
185 case IMX8QM_SDHC0_DIV:
186 resource = SC_R_SDHC_0;
187 pm_clk = SC_PM_CLK_PER;
189 case IMX8QM_SDHC1_IPG_CLK:
190 case IMX8QM_SDHC1_CLK:
191 case IMX8QM_SDHC1_DIV:
192 resource = SC_R_SDHC_1;
193 pm_clk = SC_PM_CLK_PER;
195 case IMX8QM_SDHC2_IPG_CLK:
196 case IMX8QM_SDHC2_CLK:
197 case IMX8QM_SDHC2_DIV:
198 resource = SC_R_SDHC_2;
199 pm_clk = SC_PM_CLK_PER;
201 case IMX8QM_ENET0_IPG_CLK:
202 case IMX8QM_ENET0_AHB_CLK:
203 case IMX8QM_ENET0_REF_DIV:
204 case IMX8QM_ENET0_PTP_CLK:
205 case IMX8QM_ENET0_ROOT_DIV:
206 resource = SC_R_ENET_0;
207 pm_clk = SC_PM_CLK_PER;
209 case IMX8QM_ENET1_IPG_CLK:
210 case IMX8QM_ENET1_AHB_CLK:
211 case IMX8QM_ENET1_REF_DIV:
212 case IMX8QM_ENET1_PTP_CLK:
213 case IMX8QM_ENET1_ROOT_DIV:
214 resource = SC_R_ENET_1;
215 pm_clk = SC_PM_CLK_PER;
218 if (clk->id < IMX8QM_UART0_IPG_CLK ||
219 clk->id >= IMX8QM_CLK_END) {
220 printf("%s(Invalid clk ID #%lu)\n",
227 ret = sc_pm_set_clock_rate(-1, resource, pm_clk, &new_rate);
229 printf("%s err %d\n", __func__, ret);
236 int __imx8_clk_enable(struct clk *clk, bool enable)
242 debug("%s(#%lu)\n", __func__, clk->id);
245 case IMX8QM_I2C0_CLK:
246 resource = SC_R_I2C_0;
247 pm_clk = SC_PM_CLK_PER;
249 case IMX8QM_I2C1_CLK:
250 resource = SC_R_I2C_1;
251 pm_clk = SC_PM_CLK_PER;
253 case IMX8QM_I2C2_CLK:
254 resource = SC_R_I2C_2;
255 pm_clk = SC_PM_CLK_PER;
257 case IMX8QM_I2C3_CLK:
258 resource = SC_R_I2C_3;
259 pm_clk = SC_PM_CLK_PER;
261 case IMX8QM_UART0_CLK:
262 resource = SC_R_UART_0;
263 pm_clk = SC_PM_CLK_PER;
265 case IMX8QM_UART1_CLK:
266 resource = SC_R_UART_1;
267 pm_clk = SC_PM_CLK_PER;
269 case IMX8QM_UART2_CLK:
270 resource = SC_R_UART_2;
271 pm_clk = SC_PM_CLK_PER;
273 case IMX8QM_UART3_CLK:
274 resource = SC_R_UART_3;
275 pm_clk = SC_PM_CLK_PER;
277 case IMX8QM_SDHC0_IPG_CLK:
278 case IMX8QM_SDHC0_CLK:
279 case IMX8QM_SDHC0_DIV:
280 resource = SC_R_SDHC_0;
281 pm_clk = SC_PM_CLK_PER;
283 case IMX8QM_SDHC1_IPG_CLK:
284 case IMX8QM_SDHC1_CLK:
285 case IMX8QM_SDHC1_DIV:
286 resource = SC_R_SDHC_1;
287 pm_clk = SC_PM_CLK_PER;
289 case IMX8QM_SDHC2_IPG_CLK:
290 case IMX8QM_SDHC2_CLK:
291 case IMX8QM_SDHC2_DIV:
292 resource = SC_R_SDHC_2;
293 pm_clk = SC_PM_CLK_PER;
295 case IMX8QM_ENET0_IPG_CLK:
296 case IMX8QM_ENET0_AHB_CLK:
297 case IMX8QM_ENET0_REF_DIV:
298 case IMX8QM_ENET0_PTP_CLK:
299 resource = SC_R_ENET_0;
300 pm_clk = SC_PM_CLK_PER;
302 case IMX8QM_ENET1_IPG_CLK:
303 case IMX8QM_ENET1_AHB_CLK:
304 case IMX8QM_ENET1_REF_DIV:
305 case IMX8QM_ENET1_PTP_CLK:
306 resource = SC_R_ENET_1;
307 pm_clk = SC_PM_CLK_PER;
310 if (clk->id < IMX8QM_UART0_IPG_CLK ||
311 clk->id >= IMX8QM_CLK_END) {
312 printf("%s(Invalid clk ID #%lu)\n",
319 ret = sc_pm_clock_enable(-1, resource, pm_clk, enable, 0);
321 printf("%s err %d\n", __func__, ret);