1 // SPDX-License-Identifier: GPL-2.0
4 * Peng Fan <peng.fan@nxp.com>
8 #include <clk-uclass.h>
10 #include <asm/arch/sci/sci.h>
11 #include <asm/arch/clock.h>
12 #include <dt-bindings/clock/imx8qm-clock.h>
13 #include <dt-bindings/soc/imx_rsrc.h>
18 #if CONFIG_IS_ENABLED(CMD_CLK)
19 struct imx8_clks imx8_clk_names[] = {
20 { IMX8QM_A53_DIV, "A53_DIV" },
21 { IMX8QM_UART0_CLK, "UART0" },
22 { IMX8QM_UART1_CLK, "UART1" },
23 { IMX8QM_UART2_CLK, "UART2" },
24 { IMX8QM_UART3_CLK, "UART3" },
25 { IMX8QM_SDHC0_CLK, "SDHC0" },
26 { IMX8QM_SDHC1_CLK, "SDHC1" },
27 { IMX8QM_SDHC2_CLK, "SDHC2" },
28 { IMX8QM_ENET0_AHB_CLK, "ENET0_AHB" },
29 { IMX8QM_ENET0_IPG_CLK, "ENET0_IPG" },
30 { IMX8QM_ENET0_REF_DIV, "ENET0_REF" },
31 { IMX8QM_ENET0_PTP_CLK, "ENET0_PTP" },
32 { IMX8QM_ENET1_AHB_CLK, "ENET1_AHB" },
33 { IMX8QM_ENET1_IPG_CLK, "ENET1_IPG" },
34 { IMX8QM_ENET1_REF_DIV, "ENET1_REF" },
35 { IMX8QM_ENET1_PTP_CLK, "ENET1_PTP" },
38 int num_clks = ARRAY_SIZE(imx8_clk_names);
41 ulong imx8_clk_get_rate(struct clk *clk)
48 debug("%s(#%lu)\n", __func__, clk->id);
53 pm_clk = SC_PM_CLK_CPU;
56 resource = SC_R_I2C_0;
57 pm_clk = SC_PM_CLK_PER;
60 resource = SC_R_I2C_1;
61 pm_clk = SC_PM_CLK_PER;
64 resource = SC_R_I2C_2;
65 pm_clk = SC_PM_CLK_PER;
68 resource = SC_R_I2C_3;
69 pm_clk = SC_PM_CLK_PER;
71 case IMX8QM_SDHC0_IPG_CLK:
72 case IMX8QM_SDHC0_CLK:
73 case IMX8QM_SDHC0_DIV:
74 resource = SC_R_SDHC_0;
75 pm_clk = SC_PM_CLK_PER;
77 case IMX8QM_SDHC1_IPG_CLK:
78 case IMX8QM_SDHC1_CLK:
79 case IMX8QM_SDHC1_DIV:
80 resource = SC_R_SDHC_1;
81 pm_clk = SC_PM_CLK_PER;
83 case IMX8QM_SDHC2_IPG_CLK:
84 case IMX8QM_SDHC2_CLK:
85 case IMX8QM_SDHC2_DIV:
86 resource = SC_R_SDHC_2;
87 pm_clk = SC_PM_CLK_PER;
89 case IMX8QM_UART0_IPG_CLK:
90 case IMX8QM_UART0_CLK:
91 resource = SC_R_UART_0;
92 pm_clk = SC_PM_CLK_PER;
94 case IMX8QM_UART1_CLK:
95 resource = SC_R_UART_1;
96 pm_clk = SC_PM_CLK_PER;
98 case IMX8QM_UART2_CLK:
99 resource = SC_R_UART_2;
100 pm_clk = SC_PM_CLK_PER;
102 case IMX8QM_UART3_CLK:
103 resource = SC_R_UART_3;
104 pm_clk = SC_PM_CLK_PER;
106 case IMX8QM_ENET0_IPG_CLK:
107 case IMX8QM_ENET0_AHB_CLK:
108 case IMX8QM_ENET0_REF_DIV:
109 case IMX8QM_ENET0_PTP_CLK:
110 resource = SC_R_ENET_0;
111 pm_clk = SC_PM_CLK_PER;
113 case IMX8QM_ENET1_IPG_CLK:
114 case IMX8QM_ENET1_AHB_CLK:
115 case IMX8QM_ENET1_REF_DIV:
116 case IMX8QM_ENET1_PTP_CLK:
117 resource = SC_R_ENET_1;
118 pm_clk = SC_PM_CLK_PER;
121 if (clk->id < IMX8QM_UART0_IPG_CLK ||
122 clk->id >= IMX8QM_CLK_END) {
123 printf("%s(Invalid clk ID #%lu)\n",
130 ret = sc_pm_get_clock_rate(-1, resource, pm_clk,
131 (sc_pm_clock_rate_t *)&rate);
133 printf("%s err %d\n", __func__, ret);
140 ulong imx8_clk_set_rate(struct clk *clk, unsigned long rate)
147 debug("%s(#%lu), rate: %lu\n", __func__, clk->id, rate);
150 case IMX8QM_I2C0_CLK:
151 resource = SC_R_I2C_0;
152 pm_clk = SC_PM_CLK_PER;
154 case IMX8QM_I2C1_CLK:
155 resource = SC_R_I2C_1;
156 pm_clk = SC_PM_CLK_PER;
158 case IMX8QM_I2C2_CLK:
159 resource = SC_R_I2C_2;
160 pm_clk = SC_PM_CLK_PER;
162 case IMX8QM_I2C3_CLK:
163 resource = SC_R_I2C_3;
164 pm_clk = SC_PM_CLK_PER;
166 case IMX8QM_UART0_CLK:
167 resource = SC_R_UART_0;
168 pm_clk = SC_PM_CLK_PER;
170 case IMX8QM_UART1_CLK:
171 resource = SC_R_UART_1;
172 pm_clk = SC_PM_CLK_PER;
174 case IMX8QM_UART2_CLK:
175 resource = SC_R_UART_2;
176 pm_clk = SC_PM_CLK_PER;
178 case IMX8QM_UART3_CLK:
179 resource = SC_R_UART_3;
180 pm_clk = SC_PM_CLK_PER;
182 case IMX8QM_SDHC0_IPG_CLK:
183 case IMX8QM_SDHC0_CLK:
184 case IMX8QM_SDHC0_DIV:
185 resource = SC_R_SDHC_0;
186 pm_clk = SC_PM_CLK_PER;
188 case IMX8QM_SDHC1_IPG_CLK:
189 case IMX8QM_SDHC1_CLK:
190 case IMX8QM_SDHC1_DIV:
191 resource = SC_R_SDHC_1;
192 pm_clk = SC_PM_CLK_PER;
194 case IMX8QM_SDHC2_IPG_CLK:
195 case IMX8QM_SDHC2_CLK:
196 case IMX8QM_SDHC2_DIV:
197 resource = SC_R_SDHC_2;
198 pm_clk = SC_PM_CLK_PER;
200 case IMX8QM_ENET0_IPG_CLK:
201 case IMX8QM_ENET0_AHB_CLK:
202 case IMX8QM_ENET0_REF_DIV:
203 case IMX8QM_ENET0_PTP_CLK:
204 case IMX8QM_ENET0_ROOT_DIV:
205 resource = SC_R_ENET_0;
206 pm_clk = SC_PM_CLK_PER;
208 case IMX8QM_ENET1_IPG_CLK:
209 case IMX8QM_ENET1_AHB_CLK:
210 case IMX8QM_ENET1_REF_DIV:
211 case IMX8QM_ENET1_PTP_CLK:
212 case IMX8QM_ENET1_ROOT_DIV:
213 resource = SC_R_ENET_1;
214 pm_clk = SC_PM_CLK_PER;
217 if (clk->id < IMX8QM_UART0_IPG_CLK ||
218 clk->id >= IMX8QM_CLK_END) {
219 printf("%s(Invalid clk ID #%lu)\n",
226 ret = sc_pm_set_clock_rate(-1, resource, pm_clk, &new_rate);
228 printf("%s err %d\n", __func__, ret);
235 int __imx8_clk_enable(struct clk *clk, bool enable)
241 debug("%s(#%lu)\n", __func__, clk->id);
244 case IMX8QM_I2C0_CLK:
245 resource = SC_R_I2C_0;
246 pm_clk = SC_PM_CLK_PER;
248 case IMX8QM_I2C1_CLK:
249 resource = SC_R_I2C_1;
250 pm_clk = SC_PM_CLK_PER;
252 case IMX8QM_I2C2_CLK:
253 resource = SC_R_I2C_2;
254 pm_clk = SC_PM_CLK_PER;
256 case IMX8QM_I2C3_CLK:
257 resource = SC_R_I2C_3;
258 pm_clk = SC_PM_CLK_PER;
260 case IMX8QM_UART0_CLK:
261 resource = SC_R_UART_0;
262 pm_clk = SC_PM_CLK_PER;
264 case IMX8QM_UART1_CLK:
265 resource = SC_R_UART_1;
266 pm_clk = SC_PM_CLK_PER;
268 case IMX8QM_UART2_CLK:
269 resource = SC_R_UART_2;
270 pm_clk = SC_PM_CLK_PER;
272 case IMX8QM_UART3_CLK:
273 resource = SC_R_UART_3;
274 pm_clk = SC_PM_CLK_PER;
276 case IMX8QM_SDHC0_IPG_CLK:
277 case IMX8QM_SDHC0_CLK:
278 case IMX8QM_SDHC0_DIV:
279 resource = SC_R_SDHC_0;
280 pm_clk = SC_PM_CLK_PER;
282 case IMX8QM_SDHC1_IPG_CLK:
283 case IMX8QM_SDHC1_CLK:
284 case IMX8QM_SDHC1_DIV:
285 resource = SC_R_SDHC_1;
286 pm_clk = SC_PM_CLK_PER;
288 case IMX8QM_SDHC2_IPG_CLK:
289 case IMX8QM_SDHC2_CLK:
290 case IMX8QM_SDHC2_DIV:
291 resource = SC_R_SDHC_2;
292 pm_clk = SC_PM_CLK_PER;
294 case IMX8QM_ENET0_IPG_CLK:
295 case IMX8QM_ENET0_AHB_CLK:
296 case IMX8QM_ENET0_REF_DIV:
297 case IMX8QM_ENET0_PTP_CLK:
298 resource = SC_R_ENET_0;
299 pm_clk = SC_PM_CLK_PER;
301 case IMX8QM_ENET1_IPG_CLK:
302 case IMX8QM_ENET1_AHB_CLK:
303 case IMX8QM_ENET1_REF_DIV:
304 case IMX8QM_ENET1_PTP_CLK:
305 resource = SC_R_ENET_1;
306 pm_clk = SC_PM_CLK_PER;
309 if (clk->id < IMX8QM_UART0_IPG_CLK ||
310 clk->id >= IMX8QM_CLK_END) {
311 printf("%s(Invalid clk ID #%lu)\n",
318 ret = sc_pm_clock_enable(-1, resource, pm_clk, enable, 0);
320 printf("%s err %d\n", __func__, ret);