blob: 823e4a972353684b488ffeadd3ca94ab682cae01 [file] [log] [blame]
Yann Gautier9aea69e2018-07-24 17:13:36 +02001/*
Yann Gautiera2e2a302019-02-14 11:13:39 +01002 * Copyright (C) 2018-2019, STMicroelectronics - All Rights Reserved
Yann Gautier9aea69e2018-07-24 17:13:36 +02003 *
4 * SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause
5 */
6
Yann Gautier9aea69e2018-07-24 17:13:36 +02007#include <assert.h>
Yann Gautier9aea69e2018-07-24 17:13:36 +02008#include <errno.h>
Yann Gautier9aea69e2018-07-24 17:13:36 +02009#include <stdint.h>
Antonio Nino Diaz00086e32018-08-16 16:46:06 +010010#include <stdio.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000011
12#include <libfdt.h>
13
Yann Gautier57e282b2019-01-07 11:17:24 +010014#include <platform_def.h>
15
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000016#include <arch.h>
17#include <arch_helpers.h>
18#include <common/debug.h>
Andre Przywaracc99f3f2020-03-26 12:51:21 +000019#include <common/fdt_wrappers.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000020#include <drivers/delay_timer.h>
21#include <drivers/generic_delay_timer.h>
Yann Gautier4d429472019-02-14 11:15:20 +010022#include <drivers/st/stm32mp_clkfunc.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000023#include <drivers/st/stm32mp1_clk.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000024#include <drivers/st/stm32mp1_rcc.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000025#include <dt-bindings/clock/stm32mp1-clksrc.h>
26#include <lib/mmio.h>
Yann Gautiere4a3c352019-02-14 10:53:33 +010027#include <lib/spinlock.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000028#include <lib/utils_def.h>
29#include <plat/common/platform.h>
30
Yann Gautier2299d572019-02-14 11:14:39 +010031#define MAX_HSI_HZ 64000000
Yann Gautiere4a3c352019-02-14 10:53:33 +010032#define USB_PHY_48_MHZ 48000000
Yann Gautier9aea69e2018-07-24 17:13:36 +020033
Yann Gautier2299d572019-02-14 11:14:39 +010034#define TIMEOUT_US_200MS U(200000)
35#define TIMEOUT_US_1S U(1000000)
Yann Gautier9aea69e2018-07-24 17:13:36 +020036
Yann Gautier2299d572019-02-14 11:14:39 +010037#define PLLRDY_TIMEOUT TIMEOUT_US_200MS
38#define CLKSRC_TIMEOUT TIMEOUT_US_200MS
39#define CLKDIV_TIMEOUT TIMEOUT_US_200MS
40#define HSIDIV_TIMEOUT TIMEOUT_US_200MS
41#define OSCRDY_TIMEOUT TIMEOUT_US_1S
Yann Gautier9aea69e2018-07-24 17:13:36 +020042
Yann Gautier5f2e8742019-05-17 15:57:56 +020043const char *stm32mp_osc_node_label[NB_OSC] = {
44 [_LSI] = "clk-lsi",
45 [_LSE] = "clk-lse",
46 [_HSI] = "clk-hsi",
47 [_HSE] = "clk-hse",
48 [_CSI] = "clk-csi",
49 [_I2S_CKIN] = "i2s_ckin",
50};
51
Yann Gautier9aea69e2018-07-24 17:13:36 +020052enum stm32mp1_parent_id {
53/* Oscillators are defined in enum stm32mp_osc_id */
54
55/* Other parent source */
56 _HSI_KER = NB_OSC,
57 _HSE_KER,
58 _HSE_KER_DIV2,
59 _CSI_KER,
60 _PLL1_P,
61 _PLL1_Q,
62 _PLL1_R,
63 _PLL2_P,
64 _PLL2_Q,
65 _PLL2_R,
66 _PLL3_P,
67 _PLL3_Q,
68 _PLL3_R,
69 _PLL4_P,
70 _PLL4_Q,
71 _PLL4_R,
72 _ACLK,
73 _PCLK1,
74 _PCLK2,
75 _PCLK3,
76 _PCLK4,
77 _PCLK5,
78 _HCLK6,
79 _HCLK2,
80 _CK_PER,
81 _CK_MPU,
Yann Gautiered342322019-02-15 17:33:27 +010082 _CK_MCU,
Yann Gautiere4a3c352019-02-14 10:53:33 +010083 _USB_PHY_48,
Yann Gautier9aea69e2018-07-24 17:13:36 +020084 _PARENT_NB,
85 _UNKNOWN_ID = 0xff,
86};
87
Yann Gautiere4a3c352019-02-14 10:53:33 +010088/* Lists only the parent clock we are interested in */
Yann Gautier9aea69e2018-07-24 17:13:36 +020089enum stm32mp1_parent_sel {
Yann Gautiere4a3c352019-02-14 10:53:33 +010090 _I2C12_SEL,
91 _I2C35_SEL,
92 _STGEN_SEL,
Yann Gautier9aea69e2018-07-24 17:13:36 +020093 _I2C46_SEL,
Yann Gautiere4a3c352019-02-14 10:53:33 +010094 _SPI6_SEL,
Yann Gautier9d8bbcd2019-05-07 18:49:33 +020095 _UART1_SEL,
Yann Gautiere4a3c352019-02-14 10:53:33 +010096 _RNG1_SEL,
Yann Gautier9aea69e2018-07-24 17:13:36 +020097 _UART6_SEL,
98 _UART24_SEL,
99 _UART35_SEL,
100 _UART78_SEL,
101 _SDMMC12_SEL,
102 _SDMMC3_SEL,
103 _QSPI_SEL,
104 _FMC_SEL,
Yann Gautier9d8bbcd2019-05-07 18:49:33 +0200105 _AXIS_SEL,
106 _MCUS_SEL,
Yann Gautier9aea69e2018-07-24 17:13:36 +0200107 _USBPHY_SEL,
108 _USBO_SEL,
Etienne Carriere04132612019-12-08 08:20:12 +0100109 _MPU_SEL,
110 _PER_SEL,
Yann Gautier9aea69e2018-07-24 17:13:36 +0200111 _PARENT_SEL_NB,
112 _UNKNOWN_SEL = 0xff,
113};
114
Etienne Carriere04132612019-12-08 08:20:12 +0100115/* State the parent clock ID straight related to a clock */
116static const uint8_t parent_id_clock_id[_PARENT_NB] = {
117 [_HSE] = CK_HSE,
118 [_HSI] = CK_HSI,
119 [_CSI] = CK_CSI,
120 [_LSE] = CK_LSE,
121 [_LSI] = CK_LSI,
122 [_I2S_CKIN] = _UNKNOWN_ID,
123 [_USB_PHY_48] = _UNKNOWN_ID,
124 [_HSI_KER] = CK_HSI,
125 [_HSE_KER] = CK_HSE,
126 [_HSE_KER_DIV2] = CK_HSE_DIV2,
127 [_CSI_KER] = CK_CSI,
128 [_PLL1_P] = PLL1_P,
129 [_PLL1_Q] = PLL1_Q,
130 [_PLL1_R] = PLL1_R,
131 [_PLL2_P] = PLL2_P,
132 [_PLL2_Q] = PLL2_Q,
133 [_PLL2_R] = PLL2_R,
134 [_PLL3_P] = PLL3_P,
135 [_PLL3_Q] = PLL3_Q,
136 [_PLL3_R] = PLL3_R,
137 [_PLL4_P] = PLL4_P,
138 [_PLL4_Q] = PLL4_Q,
139 [_PLL4_R] = PLL4_R,
140 [_ACLK] = CK_AXI,
141 [_PCLK1] = CK_AXI,
142 [_PCLK2] = CK_AXI,
143 [_PCLK3] = CK_AXI,
144 [_PCLK4] = CK_AXI,
145 [_PCLK5] = CK_AXI,
146 [_CK_PER] = CK_PER,
147 [_CK_MPU] = CK_MPU,
148 [_CK_MCU] = CK_MCU,
149};
150
151static unsigned int clock_id2parent_id(unsigned long id)
152{
153 unsigned int n;
154
155 for (n = 0U; n < ARRAY_SIZE(parent_id_clock_id); n++) {
156 if (parent_id_clock_id[n] == id) {
157 return n;
158 }
159 }
160
161 return _UNKNOWN_ID;
162}
163
Yann Gautier9aea69e2018-07-24 17:13:36 +0200164enum stm32mp1_pll_id {
165 _PLL1,
166 _PLL2,
167 _PLL3,
168 _PLL4,
169 _PLL_NB
170};
171
172enum stm32mp1_div_id {
173 _DIV_P,
174 _DIV_Q,
175 _DIV_R,
176 _DIV_NB,
177};
178
179enum stm32mp1_clksrc_id {
180 CLKSRC_MPU,
181 CLKSRC_AXI,
Yann Gautiered342322019-02-15 17:33:27 +0100182 CLKSRC_MCU,
Yann Gautier9aea69e2018-07-24 17:13:36 +0200183 CLKSRC_PLL12,
184 CLKSRC_PLL3,
185 CLKSRC_PLL4,
186 CLKSRC_RTC,
187 CLKSRC_MCO1,
188 CLKSRC_MCO2,
189 CLKSRC_NB
190};
191
192enum stm32mp1_clkdiv_id {
193 CLKDIV_MPU,
194 CLKDIV_AXI,
Yann Gautiered342322019-02-15 17:33:27 +0100195 CLKDIV_MCU,
Yann Gautier9aea69e2018-07-24 17:13:36 +0200196 CLKDIV_APB1,
197 CLKDIV_APB2,
198 CLKDIV_APB3,
199 CLKDIV_APB4,
200 CLKDIV_APB5,
201 CLKDIV_RTC,
202 CLKDIV_MCO1,
203 CLKDIV_MCO2,
204 CLKDIV_NB
205};
206
207enum stm32mp1_pllcfg {
208 PLLCFG_M,
209 PLLCFG_N,
210 PLLCFG_P,
211 PLLCFG_Q,
212 PLLCFG_R,
213 PLLCFG_O,
214 PLLCFG_NB
215};
216
217enum stm32mp1_pllcsg {
218 PLLCSG_MOD_PER,
219 PLLCSG_INC_STEP,
220 PLLCSG_SSCG_MODE,
221 PLLCSG_NB
222};
223
224enum stm32mp1_plltype {
225 PLL_800,
226 PLL_1600,
227 PLL_TYPE_NB
228};
229
230struct stm32mp1_pll {
231 uint8_t refclk_min;
232 uint8_t refclk_max;
233 uint8_t divn_max;
234};
235
236struct stm32mp1_clk_gate {
237 uint16_t offset;
238 uint8_t bit;
239 uint8_t index;
240 uint8_t set_clr;
Yann Gautiere4a3c352019-02-14 10:53:33 +0100241 uint8_t sel; /* Relates to enum stm32mp1_parent_sel */
242 uint8_t fixed; /* Relates to enum stm32mp1_parent_id */
Yann Gautier9aea69e2018-07-24 17:13:36 +0200243};
244
245struct stm32mp1_clk_sel {
246 uint16_t offset;
247 uint8_t src;
248 uint8_t msk;
249 uint8_t nb_parent;
250 const uint8_t *parent;
251};
252
253#define REFCLK_SIZE 4
254struct stm32mp1_clk_pll {
255 enum stm32mp1_plltype plltype;
256 uint16_t rckxselr;
257 uint16_t pllxcfgr1;
258 uint16_t pllxcfgr2;
259 uint16_t pllxfracr;
260 uint16_t pllxcr;
261 uint16_t pllxcsgr;
262 enum stm32mp_osc_id refclk[REFCLK_SIZE];
263};
264
Yann Gautiere4a3c352019-02-14 10:53:33 +0100265/* Clocks with selectable source and non set/clr register access */
266#define _CLK_SELEC(off, b, idx, s) \
Yann Gautier9aea69e2018-07-24 17:13:36 +0200267 { \
268 .offset = (off), \
269 .bit = (b), \
270 .index = (idx), \
271 .set_clr = 0, \
272 .sel = (s), \
273 .fixed = _UNKNOWN_ID, \
Yann Gautier9aea69e2018-07-24 17:13:36 +0200274 }
275
Yann Gautiere4a3c352019-02-14 10:53:33 +0100276/* Clocks with fixed source and non set/clr register access */
277#define _CLK_FIXED(off, b, idx, f) \
Yann Gautier9aea69e2018-07-24 17:13:36 +0200278 { \
279 .offset = (off), \
280 .bit = (b), \
281 .index = (idx), \
282 .set_clr = 0, \
283 .sel = _UNKNOWN_SEL, \
284 .fixed = (f), \
Yann Gautier9aea69e2018-07-24 17:13:36 +0200285 }
286
Yann Gautiere4a3c352019-02-14 10:53:33 +0100287/* Clocks with selectable source and set/clr register access */
288#define _CLK_SC_SELEC(off, b, idx, s) \
Yann Gautier9aea69e2018-07-24 17:13:36 +0200289 { \
290 .offset = (off), \
291 .bit = (b), \
292 .index = (idx), \
293 .set_clr = 1, \
294 .sel = (s), \
295 .fixed = _UNKNOWN_ID, \
Yann Gautier9aea69e2018-07-24 17:13:36 +0200296 }
297
Yann Gautiere4a3c352019-02-14 10:53:33 +0100298/* Clocks with fixed source and set/clr register access */
299#define _CLK_SC_FIXED(off, b, idx, f) \
Yann Gautier9aea69e2018-07-24 17:13:36 +0200300 { \
301 .offset = (off), \
302 .bit = (b), \
303 .index = (idx), \
304 .set_clr = 1, \
305 .sel = _UNKNOWN_SEL, \
306 .fixed = (f), \
Yann Gautier9aea69e2018-07-24 17:13:36 +0200307 }
308
Yann Gautier9d8bbcd2019-05-07 18:49:33 +0200309#define _CLK_PARENT_SEL(_label, _rcc_selr, _parents) \
310 [_ ## _label ## _SEL] = { \
311 .offset = _rcc_selr, \
312 .src = _rcc_selr ## _ ## _label ## SRC_SHIFT, \
Etienne Carrierec164ce22019-12-08 08:20:40 +0100313 .msk = (_rcc_selr ## _ ## _label ## SRC_MASK) >> \
314 (_rcc_selr ## _ ## _label ## SRC_SHIFT), \
Yann Gautier9d8bbcd2019-05-07 18:49:33 +0200315 .parent = (_parents), \
316 .nb_parent = ARRAY_SIZE(_parents) \
Yann Gautier9aea69e2018-07-24 17:13:36 +0200317 }
318
Yann Gautiere4a3c352019-02-14 10:53:33 +0100319#define _CLK_PLL(idx, type, off1, off2, off3, \
320 off4, off5, off6, \
321 p1, p2, p3, p4) \
Yann Gautier9aea69e2018-07-24 17:13:36 +0200322 [(idx)] = { \
323 .plltype = (type), \
324 .rckxselr = (off1), \
325 .pllxcfgr1 = (off2), \
326 .pllxcfgr2 = (off3), \
327 .pllxfracr = (off4), \
328 .pllxcr = (off5), \
329 .pllxcsgr = (off6), \
330 .refclk[0] = (p1), \
331 .refclk[1] = (p2), \
332 .refclk[2] = (p3), \
333 .refclk[3] = (p4), \
334 }
335
Yann Gautiere4a3c352019-02-14 10:53:33 +0100336#define NB_GATES ARRAY_SIZE(stm32mp1_clk_gate)
337
Yann Gautier9aea69e2018-07-24 17:13:36 +0200338static const struct stm32mp1_clk_gate stm32mp1_clk_gate[] = {
Yann Gautiere4a3c352019-02-14 10:53:33 +0100339 _CLK_FIXED(RCC_DDRITFCR, 0, DDRC1, _ACLK),
340 _CLK_FIXED(RCC_DDRITFCR, 1, DDRC1LP, _ACLK),
341 _CLK_FIXED(RCC_DDRITFCR, 2, DDRC2, _ACLK),
342 _CLK_FIXED(RCC_DDRITFCR, 3, DDRC2LP, _ACLK),
343 _CLK_FIXED(RCC_DDRITFCR, 4, DDRPHYC, _PLL2_R),
344 _CLK_FIXED(RCC_DDRITFCR, 5, DDRPHYCLP, _PLL2_R),
345 _CLK_FIXED(RCC_DDRITFCR, 6, DDRCAPB, _PCLK4),
346 _CLK_FIXED(RCC_DDRITFCR, 7, DDRCAPBLP, _PCLK4),
347 _CLK_FIXED(RCC_DDRITFCR, 8, AXIDCG, _ACLK),
348 _CLK_FIXED(RCC_DDRITFCR, 9, DDRPHYCAPB, _PCLK4),
349 _CLK_FIXED(RCC_DDRITFCR, 10, DDRPHYCAPBLP, _PCLK4),
350
351 _CLK_SC_FIXED(RCC_MP_APB1ENSETR, 6, TIM12_K, _PCLK1),
352 _CLK_SC_SELEC(RCC_MP_APB1ENSETR, 14, USART2_K, _UART24_SEL),
353 _CLK_SC_SELEC(RCC_MP_APB1ENSETR, 15, USART3_K, _UART35_SEL),
354 _CLK_SC_SELEC(RCC_MP_APB1ENSETR, 16, UART4_K, _UART24_SEL),
355 _CLK_SC_SELEC(RCC_MP_APB1ENSETR, 17, UART5_K, _UART35_SEL),
356 _CLK_SC_SELEC(RCC_MP_APB1ENSETR, 18, UART7_K, _UART78_SEL),
357 _CLK_SC_SELEC(RCC_MP_APB1ENSETR, 19, UART8_K, _UART78_SEL),
358 _CLK_SC_SELEC(RCC_MP_APB1ENSETR, 21, I2C1_K, _I2C12_SEL),
359 _CLK_SC_SELEC(RCC_MP_APB1ENSETR, 22, I2C2_K, _I2C12_SEL),
360 _CLK_SC_SELEC(RCC_MP_APB1ENSETR, 23, I2C3_K, _I2C35_SEL),
361 _CLK_SC_SELEC(RCC_MP_APB1ENSETR, 24, I2C5_K, _I2C35_SEL),
362
363 _CLK_SC_FIXED(RCC_MP_APB2ENSETR, 2, TIM15_K, _PCLK2),
364 _CLK_SC_SELEC(RCC_MP_APB2ENSETR, 13, USART6_K, _UART6_SEL),
365
Yann Gautier3edc7c32019-05-20 19:17:08 +0200366 _CLK_SC_FIXED(RCC_MP_APB3ENSETR, 11, SYSCFG, _UNKNOWN_ID),
367
Yann Gautiere4a3c352019-02-14 10:53:33 +0100368 _CLK_SC_SELEC(RCC_MP_APB4ENSETR, 8, DDRPERFM, _UNKNOWN_SEL),
369 _CLK_SC_SELEC(RCC_MP_APB4ENSETR, 15, IWDG2, _UNKNOWN_SEL),
370 _CLK_SC_SELEC(RCC_MP_APB4ENSETR, 16, USBPHY_K, _USBPHY_SEL),
371
372 _CLK_SC_SELEC(RCC_MP_APB5ENSETR, 0, SPI6_K, _SPI6_SEL),
373 _CLK_SC_SELEC(RCC_MP_APB5ENSETR, 2, I2C4_K, _I2C46_SEL),
374 _CLK_SC_SELEC(RCC_MP_APB5ENSETR, 3, I2C6_K, _I2C46_SEL),
Yann Gautier9d8bbcd2019-05-07 18:49:33 +0200375 _CLK_SC_SELEC(RCC_MP_APB5ENSETR, 4, USART1_K, _UART1_SEL),
Yann Gautiere4a3c352019-02-14 10:53:33 +0100376 _CLK_SC_FIXED(RCC_MP_APB5ENSETR, 8, RTCAPB, _PCLK5),
377 _CLK_SC_FIXED(RCC_MP_APB5ENSETR, 11, TZC1, _PCLK5),
378 _CLK_SC_FIXED(RCC_MP_APB5ENSETR, 12, TZC2, _PCLK5),
379 _CLK_SC_FIXED(RCC_MP_APB5ENSETR, 13, TZPC, _PCLK5),
380 _CLK_SC_FIXED(RCC_MP_APB5ENSETR, 15, IWDG1, _PCLK5),
381 _CLK_SC_FIXED(RCC_MP_APB5ENSETR, 16, BSEC, _PCLK5),
382 _CLK_SC_SELEC(RCC_MP_APB5ENSETR, 20, STGEN_K, _STGEN_SEL),
383
384 _CLK_SC_SELEC(RCC_MP_AHB2ENSETR, 8, USBO_K, _USBO_SEL),
385 _CLK_SC_SELEC(RCC_MP_AHB2ENSETR, 16, SDMMC3_K, _SDMMC3_SEL),
386
387 _CLK_SC_SELEC(RCC_MP_AHB4ENSETR, 0, GPIOA, _UNKNOWN_SEL),
388 _CLK_SC_SELEC(RCC_MP_AHB4ENSETR, 1, GPIOB, _UNKNOWN_SEL),
389 _CLK_SC_SELEC(RCC_MP_AHB4ENSETR, 2, GPIOC, _UNKNOWN_SEL),
390 _CLK_SC_SELEC(RCC_MP_AHB4ENSETR, 3, GPIOD, _UNKNOWN_SEL),
391 _CLK_SC_SELEC(RCC_MP_AHB4ENSETR, 4, GPIOE, _UNKNOWN_SEL),
392 _CLK_SC_SELEC(RCC_MP_AHB4ENSETR, 5, GPIOF, _UNKNOWN_SEL),
393 _CLK_SC_SELEC(RCC_MP_AHB4ENSETR, 6, GPIOG, _UNKNOWN_SEL),
394 _CLK_SC_SELEC(RCC_MP_AHB4ENSETR, 7, GPIOH, _UNKNOWN_SEL),
395 _CLK_SC_SELEC(RCC_MP_AHB4ENSETR, 8, GPIOI, _UNKNOWN_SEL),
396 _CLK_SC_SELEC(RCC_MP_AHB4ENSETR, 9, GPIOJ, _UNKNOWN_SEL),
397 _CLK_SC_SELEC(RCC_MP_AHB4ENSETR, 10, GPIOK, _UNKNOWN_SEL),
398
399 _CLK_SC_FIXED(RCC_MP_AHB5ENSETR, 0, GPIOZ, _PCLK5),
400 _CLK_SC_FIXED(RCC_MP_AHB5ENSETR, 4, CRYP1, _PCLK5),
401 _CLK_SC_FIXED(RCC_MP_AHB5ENSETR, 5, HASH1, _PCLK5),
402 _CLK_SC_SELEC(RCC_MP_AHB5ENSETR, 6, RNG1_K, _RNG1_SEL),
403 _CLK_SC_FIXED(RCC_MP_AHB5ENSETR, 8, BKPSRAM, _PCLK5),
404
405 _CLK_SC_SELEC(RCC_MP_AHB6ENSETR, 12, FMC_K, _FMC_SEL),
406 _CLK_SC_SELEC(RCC_MP_AHB6ENSETR, 14, QSPI_K, _QSPI_SEL),
407 _CLK_SC_SELEC(RCC_MP_AHB6ENSETR, 16, SDMMC1_K, _SDMMC12_SEL),
408 _CLK_SC_SELEC(RCC_MP_AHB6ENSETR, 17, SDMMC2_K, _SDMMC12_SEL),
409 _CLK_SC_SELEC(RCC_MP_AHB6ENSETR, 24, USBH, _UNKNOWN_SEL),
410
411 _CLK_SELEC(RCC_DBGCFGR, 8, CK_DBG, _UNKNOWN_SEL),
412};
413
414static const uint8_t i2c12_parents[] = {
415 _PCLK1, _PLL4_R, _HSI_KER, _CSI_KER
416};
417
418static const uint8_t i2c35_parents[] = {
419 _PCLK1, _PLL4_R, _HSI_KER, _CSI_KER
420};
421
422static const uint8_t stgen_parents[] = {
423 _HSI_KER, _HSE_KER
424};
425
426static const uint8_t i2c46_parents[] = {
427 _PCLK5, _PLL3_Q, _HSI_KER, _CSI_KER
428};
429
430static const uint8_t spi6_parents[] = {
431 _PCLK5, _PLL4_Q, _HSI_KER, _CSI_KER, _HSE_KER, _PLL3_Q
432};
Yann Gautier9aea69e2018-07-24 17:13:36 +0200433
Yann Gautiere4a3c352019-02-14 10:53:33 +0100434static const uint8_t usart1_parents[] = {
435 _PCLK5, _PLL3_Q, _HSI_KER, _CSI_KER, _PLL4_Q, _HSE_KER
436};
Yann Gautier9aea69e2018-07-24 17:13:36 +0200437
Yann Gautiere4a3c352019-02-14 10:53:33 +0100438static const uint8_t rng1_parents[] = {
439 _CSI, _PLL4_R, _LSE, _LSI
440};
Yann Gautier9aea69e2018-07-24 17:13:36 +0200441
Yann Gautiere4a3c352019-02-14 10:53:33 +0100442static const uint8_t uart6_parents[] = {
443 _PCLK2, _PLL4_Q, _HSI_KER, _CSI_KER, _HSE_KER
444};
Yann Gautier9aea69e2018-07-24 17:13:36 +0200445
Yann Gautiere4a3c352019-02-14 10:53:33 +0100446static const uint8_t uart234578_parents[] = {
447 _PCLK1, _PLL4_Q, _HSI_KER, _CSI_KER, _HSE_KER
448};
Yann Gautier9aea69e2018-07-24 17:13:36 +0200449
Yann Gautiere4a3c352019-02-14 10:53:33 +0100450static const uint8_t sdmmc12_parents[] = {
451 _HCLK6, _PLL3_R, _PLL4_P, _HSI_KER
452};
Yann Gautier9aea69e2018-07-24 17:13:36 +0200453
Yann Gautiere4a3c352019-02-14 10:53:33 +0100454static const uint8_t sdmmc3_parents[] = {
455 _HCLK2, _PLL3_R, _PLL4_P, _HSI_KER
456};
Yann Gautier9aea69e2018-07-24 17:13:36 +0200457
Yann Gautiere4a3c352019-02-14 10:53:33 +0100458static const uint8_t qspi_parents[] = {
459 _ACLK, _PLL3_R, _PLL4_P, _CK_PER
460};
Yann Gautier9aea69e2018-07-24 17:13:36 +0200461
Yann Gautiere4a3c352019-02-14 10:53:33 +0100462static const uint8_t fmc_parents[] = {
463 _ACLK, _PLL3_R, _PLL4_P, _CK_PER
464};
Yann Gautier9aea69e2018-07-24 17:13:36 +0200465
Yann Gautiere4a3c352019-02-14 10:53:33 +0100466static const uint8_t ass_parents[] = {
467 _HSI, _HSE, _PLL2
Yann Gautier9aea69e2018-07-24 17:13:36 +0200468};
469
Yann Gautiered342322019-02-15 17:33:27 +0100470static const uint8_t mss_parents[] = {
471 _HSI, _HSE, _CSI, _PLL3
472};
473
Yann Gautiere4a3c352019-02-14 10:53:33 +0100474static const uint8_t usbphy_parents[] = {
475 _HSE_KER, _PLL4_R, _HSE_KER_DIV2
476};
477
478static const uint8_t usbo_parents[] = {
479 _PLL4_R, _USB_PHY_48
480};
Yann Gautier9aea69e2018-07-24 17:13:36 +0200481
Etienne Carriere04132612019-12-08 08:20:12 +0100482static const uint8_t mpu_parents[] = {
483 _HSI, _HSE, _PLL1_P, _PLL1_P /* specific div */
484};
485
486static const uint8_t per_parents[] = {
487 _HSI, _HSE, _CSI,
488};
489
Yann Gautier9aea69e2018-07-24 17:13:36 +0200490static const struct stm32mp1_clk_sel stm32mp1_clk_sel[_PARENT_SEL_NB] = {
Yann Gautier9d8bbcd2019-05-07 18:49:33 +0200491 _CLK_PARENT_SEL(I2C12, RCC_I2C12CKSELR, i2c12_parents),
492 _CLK_PARENT_SEL(I2C35, RCC_I2C35CKSELR, i2c35_parents),
493 _CLK_PARENT_SEL(STGEN, RCC_STGENCKSELR, stgen_parents),
494 _CLK_PARENT_SEL(I2C46, RCC_I2C46CKSELR, i2c46_parents),
495 _CLK_PARENT_SEL(SPI6, RCC_SPI6CKSELR, spi6_parents),
496 _CLK_PARENT_SEL(UART1, RCC_UART1CKSELR, usart1_parents),
497 _CLK_PARENT_SEL(RNG1, RCC_RNG1CKSELR, rng1_parents),
Etienne Carriere04132612019-12-08 08:20:12 +0100498 _CLK_PARENT_SEL(MPU, RCC_MPCKSELR, mpu_parents),
499 _CLK_PARENT_SEL(PER, RCC_CPERCKSELR, per_parents),
Yann Gautier9d8bbcd2019-05-07 18:49:33 +0200500 _CLK_PARENT_SEL(UART6, RCC_UART6CKSELR, uart6_parents),
501 _CLK_PARENT_SEL(UART24, RCC_UART24CKSELR, uart234578_parents),
502 _CLK_PARENT_SEL(UART35, RCC_UART35CKSELR, uart234578_parents),
503 _CLK_PARENT_SEL(UART78, RCC_UART78CKSELR, uart234578_parents),
504 _CLK_PARENT_SEL(SDMMC12, RCC_SDMMC12CKSELR, sdmmc12_parents),
505 _CLK_PARENT_SEL(SDMMC3, RCC_SDMMC3CKSELR, sdmmc3_parents),
506 _CLK_PARENT_SEL(QSPI, RCC_QSPICKSELR, qspi_parents),
507 _CLK_PARENT_SEL(FMC, RCC_FMCCKSELR, fmc_parents),
508 _CLK_PARENT_SEL(AXIS, RCC_ASSCKSELR, ass_parents),
509 _CLK_PARENT_SEL(MCUS, RCC_MSSCKSELR, mss_parents),
510 _CLK_PARENT_SEL(USBPHY, RCC_USBCKSELR, usbphy_parents),
511 _CLK_PARENT_SEL(USBO, RCC_USBCKSELR, usbo_parents),
Yann Gautier9aea69e2018-07-24 17:13:36 +0200512};
513
514/* Define characteristic of PLL according type */
515#define DIVN_MIN 24
516static const struct stm32mp1_pll stm32mp1_pll[PLL_TYPE_NB] = {
517 [PLL_800] = {
518 .refclk_min = 4,
519 .refclk_max = 16,
520 .divn_max = 99,
521 },
522 [PLL_1600] = {
523 .refclk_min = 8,
524 .refclk_max = 16,
525 .divn_max = 199,
526 },
527};
528
529/* PLLNCFGR2 register divider by output */
530static const uint8_t pllncfgr2[_DIV_NB] = {
531 [_DIV_P] = RCC_PLLNCFGR2_DIVP_SHIFT,
532 [_DIV_Q] = RCC_PLLNCFGR2_DIVQ_SHIFT,
Yann Gautiere4a3c352019-02-14 10:53:33 +0100533 [_DIV_R] = RCC_PLLNCFGR2_DIVR_SHIFT,
Yann Gautier9aea69e2018-07-24 17:13:36 +0200534};
535
536static const struct stm32mp1_clk_pll stm32mp1_clk_pll[_PLL_NB] = {
Yann Gautiere4a3c352019-02-14 10:53:33 +0100537 _CLK_PLL(_PLL1, PLL_1600,
538 RCC_RCK12SELR, RCC_PLL1CFGR1, RCC_PLL1CFGR2,
539 RCC_PLL1FRACR, RCC_PLL1CR, RCC_PLL1CSGR,
540 _HSI, _HSE, _UNKNOWN_OSC_ID, _UNKNOWN_OSC_ID),
541 _CLK_PLL(_PLL2, PLL_1600,
542 RCC_RCK12SELR, RCC_PLL2CFGR1, RCC_PLL2CFGR2,
543 RCC_PLL2FRACR, RCC_PLL2CR, RCC_PLL2CSGR,
544 _HSI, _HSE, _UNKNOWN_OSC_ID, _UNKNOWN_OSC_ID),
545 _CLK_PLL(_PLL3, PLL_800,
546 RCC_RCK3SELR, RCC_PLL3CFGR1, RCC_PLL3CFGR2,
547 RCC_PLL3FRACR, RCC_PLL3CR, RCC_PLL3CSGR,
548 _HSI, _HSE, _CSI, _UNKNOWN_OSC_ID),
549 _CLK_PLL(_PLL4, PLL_800,
550 RCC_RCK4SELR, RCC_PLL4CFGR1, RCC_PLL4CFGR2,
551 RCC_PLL4FRACR, RCC_PLL4CR, RCC_PLL4CSGR,
552 _HSI, _HSE, _CSI, _I2S_CKIN),
Yann Gautier9aea69e2018-07-24 17:13:36 +0200553};
554
555/* Prescaler table lookups for clock computation */
Yann Gautiered342322019-02-15 17:33:27 +0100556/* div = /1 /2 /4 /8 / 16 /64 /128 /512 */
557static const uint8_t stm32mp1_mcu_div[16] = {
558 0, 1, 2, 3, 4, 6, 7, 8, 9, 9, 9, 9, 9, 9, 9, 9
559};
Yann Gautier9aea69e2018-07-24 17:13:36 +0200560
561/* div = /1 /2 /4 /8 /16 : same divider for PMU and APBX */
562#define stm32mp1_mpu_div stm32mp1_mpu_apbx_div
563#define stm32mp1_apbx_div stm32mp1_mpu_apbx_div
564static const uint8_t stm32mp1_mpu_apbx_div[8] = {
565 0, 1, 2, 3, 4, 4, 4, 4
566};
567
568/* div = /1 /2 /3 /4 */
569static const uint8_t stm32mp1_axi_div[8] = {
570 1, 2, 3, 4, 4, 4, 4, 4
571};
572
Yann Gautiere4a3c352019-02-14 10:53:33 +0100573/* RCC clock device driver private */
574static unsigned long stm32mp1_osc[NB_OSC];
575static struct spinlock reg_lock;
576static unsigned int gate_refcounts[NB_GATES];
577static struct spinlock refcount_lock;
578
579static const struct stm32mp1_clk_gate *gate_ref(unsigned int idx)
580{
581 return &stm32mp1_clk_gate[idx];
582}
Yann Gautier9aea69e2018-07-24 17:13:36 +0200583
Yann Gautiere4a3c352019-02-14 10:53:33 +0100584static const struct stm32mp1_clk_sel *clk_sel_ref(unsigned int idx)
585{
586 return &stm32mp1_clk_sel[idx];
587}
Yann Gautier9aea69e2018-07-24 17:13:36 +0200588
Yann Gautiere4a3c352019-02-14 10:53:33 +0100589static const struct stm32mp1_clk_pll *pll_ref(unsigned int idx)
590{
591 return &stm32mp1_clk_pll[idx];
592}
593
Yann Gautiere4a3c352019-02-14 10:53:33 +0100594static void stm32mp1_clk_lock(struct spinlock *lock)
595{
Yann Gautierf540a592019-05-22 19:13:51 +0200596 if (stm32mp_lock_available()) {
597 /* Assume interrupts are masked */
598 spin_lock(lock);
Yann Gautiere4a3c352019-02-14 10:53:33 +0100599 }
Yann Gautiere4a3c352019-02-14 10:53:33 +0100600}
601
602static void stm32mp1_clk_unlock(struct spinlock *lock)
603{
Yann Gautierf540a592019-05-22 19:13:51 +0200604 if (stm32mp_lock_available()) {
605 spin_unlock(lock);
Yann Gautiere4a3c352019-02-14 10:53:33 +0100606 }
Yann Gautiere4a3c352019-02-14 10:53:33 +0100607}
608
609bool stm32mp1_rcc_is_secure(void)
610{
611 uintptr_t rcc_base = stm32mp_rcc_base();
612
613 return (mmio_read_32(rcc_base + RCC_TZCR) & RCC_TZCR_TZEN) != 0;
614}
615
Yann Gautiered342322019-02-15 17:33:27 +0100616bool stm32mp1_rcc_is_mckprot(void)
617{
618 uintptr_t rcc_base = stm32mp_rcc_base();
619
620 return (mmio_read_32(rcc_base + RCC_TZCR) & RCC_TZCR_MCKPROT) != 0;
621}
622
Yann Gautiere4a3c352019-02-14 10:53:33 +0100623void stm32mp1_clk_rcc_regs_lock(void)
624{
625 stm32mp1_clk_lock(&reg_lock);
626}
627
628void stm32mp1_clk_rcc_regs_unlock(void)
629{
630 stm32mp1_clk_unlock(&reg_lock);
631}
632
633static unsigned long stm32mp1_clk_get_fixed(enum stm32mp_osc_id idx)
Yann Gautier9aea69e2018-07-24 17:13:36 +0200634{
635 if (idx >= NB_OSC) {
636 return 0;
637 }
638
Yann Gautiere4a3c352019-02-14 10:53:33 +0100639 return stm32mp1_osc[idx];
Yann Gautier9aea69e2018-07-24 17:13:36 +0200640}
641
Yann Gautiere4a3c352019-02-14 10:53:33 +0100642static int stm32mp1_clk_get_gated_id(unsigned long id)
Yann Gautier9aea69e2018-07-24 17:13:36 +0200643{
Yann Gautiere4a3c352019-02-14 10:53:33 +0100644 unsigned int i;
Yann Gautier9aea69e2018-07-24 17:13:36 +0200645
Yann Gautiere4a3c352019-02-14 10:53:33 +0100646 for (i = 0U; i < NB_GATES; i++) {
647 if (gate_ref(i)->index == id) {
Yann Gautier9aea69e2018-07-24 17:13:36 +0200648 return i;
649 }
650 }
651
652 ERROR("%s: clk id %d not found\n", __func__, (uint32_t)id);
653
654 return -EINVAL;
655}
656
Yann Gautiere4a3c352019-02-14 10:53:33 +0100657static enum stm32mp1_parent_sel stm32mp1_clk_get_sel(int i)
Yann Gautier9aea69e2018-07-24 17:13:36 +0200658{
Yann Gautiere4a3c352019-02-14 10:53:33 +0100659 return (enum stm32mp1_parent_sel)(gate_ref(i)->sel);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200660}
661
Yann Gautiere4a3c352019-02-14 10:53:33 +0100662static enum stm32mp1_parent_id stm32mp1_clk_get_fixed_parent(int i)
Yann Gautier9aea69e2018-07-24 17:13:36 +0200663{
Yann Gautiere4a3c352019-02-14 10:53:33 +0100664 return (enum stm32mp1_parent_id)(gate_ref(i)->fixed);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200665}
666
Yann Gautiere4a3c352019-02-14 10:53:33 +0100667static int stm32mp1_clk_get_parent(unsigned long id)
Yann Gautier9aea69e2018-07-24 17:13:36 +0200668{
Yann Gautiere4a3c352019-02-14 10:53:33 +0100669 const struct stm32mp1_clk_sel *sel;
Etienne Carriere04132612019-12-08 08:20:12 +0100670 uint32_t p_sel;
Yann Gautier9aea69e2018-07-24 17:13:36 +0200671 int i;
672 enum stm32mp1_parent_id p;
673 enum stm32mp1_parent_sel s;
Yann Gautiere4a3c352019-02-14 10:53:33 +0100674 uintptr_t rcc_base = stm32mp_rcc_base();
Yann Gautier9aea69e2018-07-24 17:13:36 +0200675
Etienne Carriere04132612019-12-08 08:20:12 +0100676 /* Few non gateable clock have a static parent ID, find them */
677 i = (int)clock_id2parent_id(id);
678 if (i != _UNKNOWN_ID) {
679 return i;
Yann Gautier9aea69e2018-07-24 17:13:36 +0200680 }
681
Yann Gautiere4a3c352019-02-14 10:53:33 +0100682 i = stm32mp1_clk_get_gated_id(id);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200683 if (i < 0) {
Yann Gautiere4a3c352019-02-14 10:53:33 +0100684 panic();
Yann Gautier9aea69e2018-07-24 17:13:36 +0200685 }
686
Yann Gautiere4a3c352019-02-14 10:53:33 +0100687 p = stm32mp1_clk_get_fixed_parent(i);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200688 if (p < _PARENT_NB) {
689 return (int)p;
690 }
691
Yann Gautiere4a3c352019-02-14 10:53:33 +0100692 s = stm32mp1_clk_get_sel(i);
693 if (s == _UNKNOWN_SEL) {
Yann Gautier9aea69e2018-07-24 17:13:36 +0200694 return -EINVAL;
695 }
Yann Gautiere4a3c352019-02-14 10:53:33 +0100696 if (s >= _PARENT_SEL_NB) {
697 panic();
Yann Gautier9aea69e2018-07-24 17:13:36 +0200698 }
699
Yann Gautiere4a3c352019-02-14 10:53:33 +0100700 sel = clk_sel_ref(s);
Etienne Carrierec164ce22019-12-08 08:20:40 +0100701 p_sel = (mmio_read_32(rcc_base + sel->offset) &
702 (sel->msk << sel->src)) >> sel->src;
Yann Gautiere4a3c352019-02-14 10:53:33 +0100703 if (p_sel < sel->nb_parent) {
704 return (int)sel->parent[p_sel];
705 }
Yann Gautier9aea69e2018-07-24 17:13:36 +0200706
707 return -EINVAL;
708}
709
Yann Gautiere4a3c352019-02-14 10:53:33 +0100710static unsigned long stm32mp1_pll_get_fref(const struct stm32mp1_clk_pll *pll)
Yann Gautier9aea69e2018-07-24 17:13:36 +0200711{
Yann Gautiere4a3c352019-02-14 10:53:33 +0100712 uint32_t selr = mmio_read_32(stm32mp_rcc_base() + pll->rckxselr);
713 uint32_t src = selr & RCC_SELR_REFCLK_SRC_MASK;
Yann Gautier9aea69e2018-07-24 17:13:36 +0200714
Yann Gautiere4a3c352019-02-14 10:53:33 +0100715 return stm32mp1_clk_get_fixed(pll->refclk[src]);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200716}
717
718/*
719 * pll_get_fvco() : return the VCO or (VCO / 2) frequency for the requested PLL
720 * - PLL1 & PLL2 => return VCO / 2 with Fpll_y_ck = FVCO / 2 * (DIVy + 1)
721 * - PLL3 & PLL4 => return VCO with Fpll_y_ck = FVCO / (DIVy + 1)
722 * => in all cases Fpll_y_ck = pll_get_fvco() / (DIVy + 1)
723 */
Yann Gautiere4a3c352019-02-14 10:53:33 +0100724static unsigned long stm32mp1_pll_get_fvco(const struct stm32mp1_clk_pll *pll)
Yann Gautier9aea69e2018-07-24 17:13:36 +0200725{
Yann Gautier9aea69e2018-07-24 17:13:36 +0200726 unsigned long refclk, fvco;
727 uint32_t cfgr1, fracr, divm, divn;
Yann Gautiere4a3c352019-02-14 10:53:33 +0100728 uintptr_t rcc_base = stm32mp_rcc_base();
Yann Gautier9aea69e2018-07-24 17:13:36 +0200729
Yann Gautiere4a3c352019-02-14 10:53:33 +0100730 cfgr1 = mmio_read_32(rcc_base + pll->pllxcfgr1);
731 fracr = mmio_read_32(rcc_base + pll->pllxfracr);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200732
733 divm = (cfgr1 & (RCC_PLLNCFGR1_DIVM_MASK)) >> RCC_PLLNCFGR1_DIVM_SHIFT;
734 divn = cfgr1 & RCC_PLLNCFGR1_DIVN_MASK;
735
Yann Gautiere4a3c352019-02-14 10:53:33 +0100736 refclk = stm32mp1_pll_get_fref(pll);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200737
738 /*
739 * With FRACV :
740 * Fvco = Fck_ref * ((DIVN + 1) + FRACV / 2^13) / (DIVM + 1)
741 * Without FRACV
742 * Fvco = Fck_ref * ((DIVN + 1) / (DIVM + 1)
743 */
744 if ((fracr & RCC_PLLNFRACR_FRACLE) != 0U) {
Yann Gautiere4a3c352019-02-14 10:53:33 +0100745 uint32_t fracv = (fracr & RCC_PLLNFRACR_FRACV_MASK) >>
746 RCC_PLLNFRACR_FRACV_SHIFT;
Yann Gautier9aea69e2018-07-24 17:13:36 +0200747 unsigned long long numerator, denominator;
748
Yann Gautiere4a3c352019-02-14 10:53:33 +0100749 numerator = (((unsigned long long)divn + 1U) << 13) + fracv;
750 numerator = refclk * numerator;
751 denominator = ((unsigned long long)divm + 1U) << 13;
Yann Gautier9aea69e2018-07-24 17:13:36 +0200752 fvco = (unsigned long)(numerator / denominator);
753 } else {
754 fvco = (unsigned long)(refclk * (divn + 1U) / (divm + 1U));
755 }
756
757 return fvco;
758}
759
Yann Gautiere4a3c352019-02-14 10:53:33 +0100760static unsigned long stm32mp1_read_pll_freq(enum stm32mp1_pll_id pll_id,
Yann Gautier9aea69e2018-07-24 17:13:36 +0200761 enum stm32mp1_div_id div_id)
762{
Yann Gautiere4a3c352019-02-14 10:53:33 +0100763 const struct stm32mp1_clk_pll *pll = pll_ref(pll_id);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200764 unsigned long dfout;
765 uint32_t cfgr2, divy;
766
767 if (div_id >= _DIV_NB) {
768 return 0;
769 }
770
Yann Gautiere4a3c352019-02-14 10:53:33 +0100771 cfgr2 = mmio_read_32(stm32mp_rcc_base() + pll->pllxcfgr2);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200772 divy = (cfgr2 >> pllncfgr2[div_id]) & RCC_PLLNCFGR2_DIVX_MASK;
773
Yann Gautiere4a3c352019-02-14 10:53:33 +0100774 dfout = stm32mp1_pll_get_fvco(pll) / (divy + 1U);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200775
776 return dfout;
777}
778
Yann Gautiere4a3c352019-02-14 10:53:33 +0100779static unsigned long get_clock_rate(int p)
Yann Gautier9aea69e2018-07-24 17:13:36 +0200780{
781 uint32_t reg, clkdiv;
782 unsigned long clock = 0;
Yann Gautiere4a3c352019-02-14 10:53:33 +0100783 uintptr_t rcc_base = stm32mp_rcc_base();
Yann Gautier9aea69e2018-07-24 17:13:36 +0200784
785 switch (p) {
786 case _CK_MPU:
787 /* MPU sub system */
Yann Gautiere4a3c352019-02-14 10:53:33 +0100788 reg = mmio_read_32(rcc_base + RCC_MPCKSELR);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200789 switch (reg & RCC_SELR_SRC_MASK) {
790 case RCC_MPCKSELR_HSI:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100791 clock = stm32mp1_clk_get_fixed(_HSI);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200792 break;
793 case RCC_MPCKSELR_HSE:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100794 clock = stm32mp1_clk_get_fixed(_HSE);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200795 break;
796 case RCC_MPCKSELR_PLL:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100797 clock = stm32mp1_read_pll_freq(_PLL1, _DIV_P);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200798 break;
799 case RCC_MPCKSELR_PLL_MPUDIV:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100800 clock = stm32mp1_read_pll_freq(_PLL1, _DIV_P);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200801
Yann Gautiere4a3c352019-02-14 10:53:33 +0100802 reg = mmio_read_32(rcc_base + RCC_MPCKDIVR);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200803 clkdiv = reg & RCC_MPUDIV_MASK;
804 if (clkdiv != 0U) {
805 clock /= stm32mp1_mpu_div[clkdiv];
806 }
Yann Gautier9aea69e2018-07-24 17:13:36 +0200807 break;
808 default:
809 break;
810 }
811 break;
812 /* AXI sub system */
813 case _ACLK:
814 case _HCLK2:
815 case _HCLK6:
816 case _PCLK4:
817 case _PCLK5:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100818 reg = mmio_read_32(rcc_base + RCC_ASSCKSELR);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200819 switch (reg & RCC_SELR_SRC_MASK) {
820 case RCC_ASSCKSELR_HSI:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100821 clock = stm32mp1_clk_get_fixed(_HSI);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200822 break;
823 case RCC_ASSCKSELR_HSE:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100824 clock = stm32mp1_clk_get_fixed(_HSE);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200825 break;
826 case RCC_ASSCKSELR_PLL:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100827 clock = stm32mp1_read_pll_freq(_PLL2, _DIV_P);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200828 break;
829 default:
830 break;
831 }
832
833 /* System clock divider */
Yann Gautiere4a3c352019-02-14 10:53:33 +0100834 reg = mmio_read_32(rcc_base + RCC_AXIDIVR);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200835 clock /= stm32mp1_axi_div[reg & RCC_AXIDIV_MASK];
836
837 switch (p) {
838 case _PCLK4:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100839 reg = mmio_read_32(rcc_base + RCC_APB4DIVR);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200840 clock >>= stm32mp1_apbx_div[reg & RCC_APBXDIV_MASK];
841 break;
842 case _PCLK5:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100843 reg = mmio_read_32(rcc_base + RCC_APB5DIVR);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200844 clock >>= stm32mp1_apbx_div[reg & RCC_APBXDIV_MASK];
845 break;
846 default:
847 break;
848 }
849 break;
Yann Gautiered342322019-02-15 17:33:27 +0100850 /* MCU sub system */
851 case _CK_MCU:
852 case _PCLK1:
853 case _PCLK2:
854 case _PCLK3:
855 reg = mmio_read_32(rcc_base + RCC_MSSCKSELR);
856 switch (reg & RCC_SELR_SRC_MASK) {
857 case RCC_MSSCKSELR_HSI:
858 clock = stm32mp1_clk_get_fixed(_HSI);
859 break;
860 case RCC_MSSCKSELR_HSE:
861 clock = stm32mp1_clk_get_fixed(_HSE);
862 break;
863 case RCC_MSSCKSELR_CSI:
864 clock = stm32mp1_clk_get_fixed(_CSI);
865 break;
866 case RCC_MSSCKSELR_PLL:
867 clock = stm32mp1_read_pll_freq(_PLL3, _DIV_P);
868 break;
869 default:
870 break;
871 }
872
873 /* MCU clock divider */
874 reg = mmio_read_32(rcc_base + RCC_MCUDIVR);
875 clock >>= stm32mp1_mcu_div[reg & RCC_MCUDIV_MASK];
876
877 switch (p) {
878 case _PCLK1:
879 reg = mmio_read_32(rcc_base + RCC_APB1DIVR);
880 clock >>= stm32mp1_apbx_div[reg & RCC_APBXDIV_MASK];
881 break;
882 case _PCLK2:
883 reg = mmio_read_32(rcc_base + RCC_APB2DIVR);
884 clock >>= stm32mp1_apbx_div[reg & RCC_APBXDIV_MASK];
885 break;
886 case _PCLK3:
887 reg = mmio_read_32(rcc_base + RCC_APB3DIVR);
888 clock >>= stm32mp1_apbx_div[reg & RCC_APBXDIV_MASK];
889 break;
890 case _CK_MCU:
891 default:
892 break;
893 }
894 break;
Yann Gautier9aea69e2018-07-24 17:13:36 +0200895 case _CK_PER:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100896 reg = mmio_read_32(rcc_base + RCC_CPERCKSELR);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200897 switch (reg & RCC_SELR_SRC_MASK) {
898 case RCC_CPERCKSELR_HSI:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100899 clock = stm32mp1_clk_get_fixed(_HSI);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200900 break;
901 case RCC_CPERCKSELR_HSE:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100902 clock = stm32mp1_clk_get_fixed(_HSE);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200903 break;
904 case RCC_CPERCKSELR_CSI:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100905 clock = stm32mp1_clk_get_fixed(_CSI);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200906 break;
907 default:
908 break;
909 }
910 break;
911 case _HSI:
912 case _HSI_KER:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100913 clock = stm32mp1_clk_get_fixed(_HSI);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200914 break;
915 case _CSI:
916 case _CSI_KER:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100917 clock = stm32mp1_clk_get_fixed(_CSI);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200918 break;
919 case _HSE:
920 case _HSE_KER:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100921 clock = stm32mp1_clk_get_fixed(_HSE);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200922 break;
923 case _HSE_KER_DIV2:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100924 clock = stm32mp1_clk_get_fixed(_HSE) >> 1;
Yann Gautier9aea69e2018-07-24 17:13:36 +0200925 break;
926 case _LSI:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100927 clock = stm32mp1_clk_get_fixed(_LSI);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200928 break;
929 case _LSE:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100930 clock = stm32mp1_clk_get_fixed(_LSE);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200931 break;
932 /* PLL */
933 case _PLL1_P:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100934 clock = stm32mp1_read_pll_freq(_PLL1, _DIV_P);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200935 break;
936 case _PLL1_Q:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100937 clock = stm32mp1_read_pll_freq(_PLL1, _DIV_Q);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200938 break;
939 case _PLL1_R:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100940 clock = stm32mp1_read_pll_freq(_PLL1, _DIV_R);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200941 break;
942 case _PLL2_P:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100943 clock = stm32mp1_read_pll_freq(_PLL2, _DIV_P);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200944 break;
945 case _PLL2_Q:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100946 clock = stm32mp1_read_pll_freq(_PLL2, _DIV_Q);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200947 break;
948 case _PLL2_R:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100949 clock = stm32mp1_read_pll_freq(_PLL2, _DIV_R);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200950 break;
951 case _PLL3_P:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100952 clock = stm32mp1_read_pll_freq(_PLL3, _DIV_P);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200953 break;
954 case _PLL3_Q:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100955 clock = stm32mp1_read_pll_freq(_PLL3, _DIV_Q);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200956 break;
957 case _PLL3_R:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100958 clock = stm32mp1_read_pll_freq(_PLL3, _DIV_R);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200959 break;
960 case _PLL4_P:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100961 clock = stm32mp1_read_pll_freq(_PLL4, _DIV_P);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200962 break;
963 case _PLL4_Q:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100964 clock = stm32mp1_read_pll_freq(_PLL4, _DIV_Q);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200965 break;
966 case _PLL4_R:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100967 clock = stm32mp1_read_pll_freq(_PLL4, _DIV_R);
Yann Gautier9aea69e2018-07-24 17:13:36 +0200968 break;
969 /* Other */
970 case _USB_PHY_48:
Yann Gautiere4a3c352019-02-14 10:53:33 +0100971 clock = USB_PHY_48_MHZ;
Yann Gautier9aea69e2018-07-24 17:13:36 +0200972 break;
973 default:
974 break;
975 }
976
977 return clock;
978}
979
Yann Gautiere4a3c352019-02-14 10:53:33 +0100980static void __clk_enable(struct stm32mp1_clk_gate const *gate)
981{
982 uintptr_t rcc_base = stm32mp_rcc_base();
983
984 if (gate->set_clr != 0U) {
985 mmio_write_32(rcc_base + gate->offset, BIT(gate->bit));
986 } else {
987 mmio_setbits_32(rcc_base + gate->offset, BIT(gate->bit));
988 }
989
990 VERBOSE("Clock %d has been enabled", gate->index);
991}
992
993static void __clk_disable(struct stm32mp1_clk_gate const *gate)
994{
995 uintptr_t rcc_base = stm32mp_rcc_base();
996
997 if (gate->set_clr != 0U) {
998 mmio_write_32(rcc_base + gate->offset + RCC_MP_ENCLRR_OFFSET,
999 BIT(gate->bit));
1000 } else {
1001 mmio_clrbits_32(rcc_base + gate->offset, BIT(gate->bit));
1002 }
1003
1004 VERBOSE("Clock %d has been disabled", gate->index);
1005}
1006
1007static bool __clk_is_enabled(struct stm32mp1_clk_gate const *gate)
1008{
1009 uintptr_t rcc_base = stm32mp_rcc_base();
1010
1011 return mmio_read_32(rcc_base + gate->offset) & BIT(gate->bit);
1012}
1013
1014unsigned int stm32mp1_clk_get_refcount(unsigned long id)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001015{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001016 int i = stm32mp1_clk_get_gated_id(id);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001017
1018 if (i < 0) {
Yann Gautiere4a3c352019-02-14 10:53:33 +01001019 panic();
Yann Gautier9aea69e2018-07-24 17:13:36 +02001020 }
1021
Yann Gautiere4a3c352019-02-14 10:53:33 +01001022 return gate_refcounts[i];
Yann Gautier9aea69e2018-07-24 17:13:36 +02001023}
1024
Yann Gautiere4a3c352019-02-14 10:53:33 +01001025void __stm32mp1_clk_enable(unsigned long id, bool secure)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001026{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001027 const struct stm32mp1_clk_gate *gate;
1028 int i = stm32mp1_clk_get_gated_id(id);
1029 unsigned int *refcnt;
Yann Gautier9aea69e2018-07-24 17:13:36 +02001030
1031 if (i < 0) {
Yann Gautiere4a3c352019-02-14 10:53:33 +01001032 ERROR("Clock %d can't be enabled\n", (uint32_t)id);
1033 panic();
Yann Gautier9aea69e2018-07-24 17:13:36 +02001034 }
1035
Yann Gautiere4a3c352019-02-14 10:53:33 +01001036 gate = gate_ref(i);
1037 refcnt = &gate_refcounts[i];
1038
1039 stm32mp1_clk_lock(&refcount_lock);
1040
1041 if (stm32mp_incr_shrefcnt(refcnt, secure) != 0) {
1042 __clk_enable(gate);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001043 }
1044
Yann Gautiere4a3c352019-02-14 10:53:33 +01001045 stm32mp1_clk_unlock(&refcount_lock);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001046}
1047
Yann Gautiere4a3c352019-02-14 10:53:33 +01001048void __stm32mp1_clk_disable(unsigned long id, bool secure)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001049{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001050 const struct stm32mp1_clk_gate *gate;
1051 int i = stm32mp1_clk_get_gated_id(id);
1052 unsigned int *refcnt;
Yann Gautier9aea69e2018-07-24 17:13:36 +02001053
1054 if (i < 0) {
Yann Gautiere4a3c352019-02-14 10:53:33 +01001055 ERROR("Clock %d can't be disabled\n", (uint32_t)id);
1056 panic();
Yann Gautier9aea69e2018-07-24 17:13:36 +02001057 }
1058
Yann Gautiere4a3c352019-02-14 10:53:33 +01001059 gate = gate_ref(i);
1060 refcnt = &gate_refcounts[i];
1061
1062 stm32mp1_clk_lock(&refcount_lock);
1063
1064 if (stm32mp_decr_shrefcnt(refcnt, secure) != 0) {
1065 __clk_disable(gate);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001066 }
1067
Yann Gautiere4a3c352019-02-14 10:53:33 +01001068 stm32mp1_clk_unlock(&refcount_lock);
1069}
1070
1071void stm32mp_clk_enable(unsigned long id)
1072{
1073 __stm32mp1_clk_enable(id, true);
1074}
1075
1076void stm32mp_clk_disable(unsigned long id)
1077{
1078 __stm32mp1_clk_disable(id, true);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001079}
1080
Yann Gautiere4a3c352019-02-14 10:53:33 +01001081bool stm32mp_clk_is_enabled(unsigned long id)
1082{
1083 int i = stm32mp1_clk_get_gated_id(id);
1084
1085 if (i < 0) {
1086 panic();
1087 }
1088
1089 return __clk_is_enabled(gate_ref(i));
1090}
1091
Yann Gautiera2e2a302019-02-14 11:13:39 +01001092unsigned long stm32mp_clk_get_rate(unsigned long id)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001093{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001094 int p = stm32mp1_clk_get_parent(id);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001095
1096 if (p < 0) {
1097 return 0;
1098 }
1099
Yann Gautiere4a3c352019-02-14 10:53:33 +01001100 return get_clock_rate(p);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001101}
1102
Yann Gautiere4a3c352019-02-14 10:53:33 +01001103static void stm32mp1_ls_osc_set(bool enable, uint32_t offset, uint32_t mask_on)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001104{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001105 uintptr_t address = stm32mp_rcc_base() + offset;
Yann Gautier9aea69e2018-07-24 17:13:36 +02001106
Yann Gautiere4a3c352019-02-14 10:53:33 +01001107 if (enable) {
Yann Gautier9aea69e2018-07-24 17:13:36 +02001108 mmio_setbits_32(address, mask_on);
1109 } else {
1110 mmio_clrbits_32(address, mask_on);
1111 }
1112}
1113
Yann Gautiere4a3c352019-02-14 10:53:33 +01001114static void stm32mp1_hs_ocs_set(bool enable, uint32_t mask_on)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001115{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001116 uint32_t offset = enable ? RCC_OCENSETR : RCC_OCENCLRR;
1117 uintptr_t address = stm32mp_rcc_base() + offset;
1118
1119 mmio_write_32(address, mask_on);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001120}
1121
Yann Gautiere4a3c352019-02-14 10:53:33 +01001122static int stm32mp1_osc_wait(bool enable, uint32_t offset, uint32_t mask_rdy)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001123{
Yann Gautier2299d572019-02-14 11:14:39 +01001124 uint64_t timeout;
Yann Gautier9aea69e2018-07-24 17:13:36 +02001125 uint32_t mask_test;
Yann Gautiere4a3c352019-02-14 10:53:33 +01001126 uintptr_t address = stm32mp_rcc_base() + offset;
Yann Gautier9aea69e2018-07-24 17:13:36 +02001127
Yann Gautiere4a3c352019-02-14 10:53:33 +01001128 if (enable) {
Yann Gautier9aea69e2018-07-24 17:13:36 +02001129 mask_test = mask_rdy;
1130 } else {
1131 mask_test = 0;
1132 }
1133
Yann Gautier2299d572019-02-14 11:14:39 +01001134 timeout = timeout_init_us(OSCRDY_TIMEOUT);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001135 while ((mmio_read_32(address) & mask_rdy) != mask_test) {
Yann Gautier2299d572019-02-14 11:14:39 +01001136 if (timeout_elapsed(timeout)) {
Yann Gautiere4a3c352019-02-14 10:53:33 +01001137 ERROR("OSC %x @ %lx timeout for enable=%d : 0x%x\n",
Yann Gautier9aea69e2018-07-24 17:13:36 +02001138 mask_rdy, address, enable, mmio_read_32(address));
1139 return -ETIMEDOUT;
1140 }
1141 }
1142
1143 return 0;
1144}
1145
Yann Gautiere4a3c352019-02-14 10:53:33 +01001146static void stm32mp1_lse_enable(bool bypass, bool digbyp, uint32_t lsedrv)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001147{
1148 uint32_t value;
Yann Gautiere4a3c352019-02-14 10:53:33 +01001149 uintptr_t rcc_base = stm32mp_rcc_base();
Yann Gautier9aea69e2018-07-24 17:13:36 +02001150
Yann Gautiere4a3c352019-02-14 10:53:33 +01001151 if (digbyp) {
1152 mmio_setbits_32(rcc_base + RCC_BDCR, RCC_BDCR_DIGBYP);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001153 }
1154
Yann Gautiere4a3c352019-02-14 10:53:33 +01001155 if (bypass || digbyp) {
1156 mmio_setbits_32(rcc_base + RCC_BDCR, RCC_BDCR_LSEBYP);
1157 }
1158
Yann Gautier9aea69e2018-07-24 17:13:36 +02001159 /*
1160 * Warning: not recommended to switch directly from "high drive"
1161 * to "medium low drive", and vice-versa.
1162 */
Yann Gautiere4a3c352019-02-14 10:53:33 +01001163 value = (mmio_read_32(rcc_base + RCC_BDCR) & RCC_BDCR_LSEDRV_MASK) >>
Yann Gautier9aea69e2018-07-24 17:13:36 +02001164 RCC_BDCR_LSEDRV_SHIFT;
1165
1166 while (value != lsedrv) {
1167 if (value > lsedrv) {
1168 value--;
1169 } else {
1170 value++;
1171 }
1172
Yann Gautiere4a3c352019-02-14 10:53:33 +01001173 mmio_clrsetbits_32(rcc_base + RCC_BDCR,
Yann Gautier9aea69e2018-07-24 17:13:36 +02001174 RCC_BDCR_LSEDRV_MASK,
1175 value << RCC_BDCR_LSEDRV_SHIFT);
1176 }
1177
Yann Gautiere4a3c352019-02-14 10:53:33 +01001178 stm32mp1_ls_osc_set(true, RCC_BDCR, RCC_BDCR_LSEON);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001179}
1180
Yann Gautiere4a3c352019-02-14 10:53:33 +01001181static void stm32mp1_lse_wait(void)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001182{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001183 if (stm32mp1_osc_wait(true, RCC_BDCR, RCC_BDCR_LSERDY) != 0) {
Yann Gautier9aea69e2018-07-24 17:13:36 +02001184 VERBOSE("%s: failed\n", __func__);
1185 }
1186}
1187
Yann Gautiere4a3c352019-02-14 10:53:33 +01001188static void stm32mp1_lsi_set(bool enable)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001189{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001190 stm32mp1_ls_osc_set(enable, RCC_RDLSICR, RCC_RDLSICR_LSION);
1191
1192 if (stm32mp1_osc_wait(enable, RCC_RDLSICR, RCC_RDLSICR_LSIRDY) != 0) {
Yann Gautier9aea69e2018-07-24 17:13:36 +02001193 VERBOSE("%s: failed\n", __func__);
1194 }
1195}
1196
Yann Gautiere4a3c352019-02-14 10:53:33 +01001197static void stm32mp1_hse_enable(bool bypass, bool digbyp, bool css)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001198{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001199 uintptr_t rcc_base = stm32mp_rcc_base();
1200
1201 if (digbyp) {
1202 mmio_write_32(rcc_base + RCC_OCENSETR, RCC_OCENR_DIGBYP);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001203 }
1204
Yann Gautiere4a3c352019-02-14 10:53:33 +01001205 if (bypass || digbyp) {
1206 mmio_write_32(rcc_base + RCC_OCENSETR, RCC_OCENR_HSEBYP);
1207 }
1208
1209 stm32mp1_hs_ocs_set(true, RCC_OCENR_HSEON);
1210 if (stm32mp1_osc_wait(true, RCC_OCRDYR, RCC_OCRDYR_HSERDY) != 0) {
Yann Gautier9aea69e2018-07-24 17:13:36 +02001211 VERBOSE("%s: failed\n", __func__);
1212 }
1213
1214 if (css) {
Yann Gautiere4a3c352019-02-14 10:53:33 +01001215 mmio_write_32(rcc_base + RCC_OCENSETR, RCC_OCENR_HSECSSON);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001216 }
1217}
1218
Yann Gautiere4a3c352019-02-14 10:53:33 +01001219static void stm32mp1_csi_set(bool enable)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001220{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001221 stm32mp1_hs_ocs_set(enable, RCC_OCENR_CSION);
1222 if (stm32mp1_osc_wait(enable, RCC_OCRDYR, RCC_OCRDYR_CSIRDY) != 0) {
Yann Gautier9aea69e2018-07-24 17:13:36 +02001223 VERBOSE("%s: failed\n", __func__);
1224 }
1225}
1226
Yann Gautiere4a3c352019-02-14 10:53:33 +01001227static void stm32mp1_hsi_set(bool enable)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001228{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001229 stm32mp1_hs_ocs_set(enable, RCC_OCENR_HSION);
1230 if (stm32mp1_osc_wait(enable, RCC_OCRDYR, RCC_OCRDYR_HSIRDY) != 0) {
Yann Gautier9aea69e2018-07-24 17:13:36 +02001231 VERBOSE("%s: failed\n", __func__);
1232 }
1233}
1234
Yann Gautiere4a3c352019-02-14 10:53:33 +01001235static int stm32mp1_set_hsidiv(uint8_t hsidiv)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001236{
Yann Gautier2299d572019-02-14 11:14:39 +01001237 uint64_t timeout;
Yann Gautiere4a3c352019-02-14 10:53:33 +01001238 uintptr_t rcc_base = stm32mp_rcc_base();
1239 uintptr_t address = rcc_base + RCC_OCRDYR;
Yann Gautier9aea69e2018-07-24 17:13:36 +02001240
Yann Gautiere4a3c352019-02-14 10:53:33 +01001241 mmio_clrsetbits_32(rcc_base + RCC_HSICFGR,
Yann Gautier9aea69e2018-07-24 17:13:36 +02001242 RCC_HSICFGR_HSIDIV_MASK,
1243 RCC_HSICFGR_HSIDIV_MASK & (uint32_t)hsidiv);
1244
Yann Gautier2299d572019-02-14 11:14:39 +01001245 timeout = timeout_init_us(HSIDIV_TIMEOUT);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001246 while ((mmio_read_32(address) & RCC_OCRDYR_HSIDIVRDY) == 0U) {
Yann Gautier2299d572019-02-14 11:14:39 +01001247 if (timeout_elapsed(timeout)) {
Yann Gautiere4a3c352019-02-14 10:53:33 +01001248 ERROR("HSIDIV failed @ 0x%lx: 0x%x\n",
Yann Gautier9aea69e2018-07-24 17:13:36 +02001249 address, mmio_read_32(address));
1250 return -ETIMEDOUT;
1251 }
1252 }
1253
1254 return 0;
1255}
1256
Yann Gautiere4a3c352019-02-14 10:53:33 +01001257static int stm32mp1_hsidiv(unsigned long hsifreq)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001258{
1259 uint8_t hsidiv;
1260 uint32_t hsidivfreq = MAX_HSI_HZ;
1261
1262 for (hsidiv = 0; hsidiv < 4U; hsidiv++) {
1263 if (hsidivfreq == hsifreq) {
1264 break;
1265 }
1266
1267 hsidivfreq /= 2U;
1268 }
1269
1270 if (hsidiv == 4U) {
1271 ERROR("Invalid clk-hsi frequency\n");
1272 return -1;
1273 }
1274
1275 if (hsidiv != 0U) {
Yann Gautiere4a3c352019-02-14 10:53:33 +01001276 return stm32mp1_set_hsidiv(hsidiv);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001277 }
1278
1279 return 0;
1280}
1281
Yann Gautiere4a3c352019-02-14 10:53:33 +01001282static bool stm32mp1_check_pll_conf(enum stm32mp1_pll_id pll_id,
1283 unsigned int clksrc,
1284 uint32_t *pllcfg, int plloff)
1285{
1286 const struct stm32mp1_clk_pll *pll = pll_ref(pll_id);
1287 uintptr_t rcc_base = stm32mp_rcc_base();
1288 uintptr_t pllxcr = rcc_base + pll->pllxcr;
1289 enum stm32mp1_plltype type = pll->plltype;
1290 uintptr_t clksrc_address = rcc_base + (clksrc >> 4);
1291 unsigned long refclk;
1292 uint32_t ifrge = 0U;
Andre Przywara2d5690c2020-03-26 11:50:33 +00001293 uint32_t src, value, fracv = 0;
1294 void *fdt;
Yann Gautiere4a3c352019-02-14 10:53:33 +01001295
1296 /* Check PLL output */
1297 if (mmio_read_32(pllxcr) != RCC_PLLNCR_PLLON) {
1298 return false;
1299 }
1300
1301 /* Check current clksrc */
1302 src = mmio_read_32(clksrc_address) & RCC_SELR_SRC_MASK;
1303 if (src != (clksrc & RCC_SELR_SRC_MASK)) {
1304 return false;
1305 }
1306
1307 /* Check Div */
1308 src = mmio_read_32(rcc_base + pll->rckxselr) & RCC_SELR_REFCLK_SRC_MASK;
1309
1310 refclk = stm32mp1_clk_get_fixed(pll->refclk[src]) /
1311 (pllcfg[PLLCFG_M] + 1U);
1312
1313 if ((refclk < (stm32mp1_pll[type].refclk_min * 1000000U)) ||
1314 (refclk > (stm32mp1_pll[type].refclk_max * 1000000U))) {
1315 return false;
1316 }
1317
1318 if ((type == PLL_800) && (refclk >= 8000000U)) {
1319 ifrge = 1U;
1320 }
1321
1322 value = (pllcfg[PLLCFG_N] << RCC_PLLNCFGR1_DIVN_SHIFT) &
1323 RCC_PLLNCFGR1_DIVN_MASK;
1324 value |= (pllcfg[PLLCFG_M] << RCC_PLLNCFGR1_DIVM_SHIFT) &
1325 RCC_PLLNCFGR1_DIVM_MASK;
1326 value |= (ifrge << RCC_PLLNCFGR1_IFRGE_SHIFT) &
1327 RCC_PLLNCFGR1_IFRGE_MASK;
1328 if (mmio_read_32(rcc_base + pll->pllxcfgr1) != value) {
1329 return false;
1330 }
1331
1332 /* Fractional configuration */
Andre Przywara2d5690c2020-03-26 11:50:33 +00001333 if (fdt_get_address(&fdt) == 1) {
1334 fracv = fdt_read_uint32_default(fdt, plloff, "frac", 0);
1335 }
Yann Gautiere4a3c352019-02-14 10:53:33 +01001336
1337 value = fracv << RCC_PLLNFRACR_FRACV_SHIFT;
1338 value |= RCC_PLLNFRACR_FRACLE;
1339 if (mmio_read_32(rcc_base + pll->pllxfracr) != value) {
1340 return false;
1341 }
1342
1343 /* Output config */
1344 value = (pllcfg[PLLCFG_P] << RCC_PLLNCFGR2_DIVP_SHIFT) &
1345 RCC_PLLNCFGR2_DIVP_MASK;
1346 value |= (pllcfg[PLLCFG_Q] << RCC_PLLNCFGR2_DIVQ_SHIFT) &
1347 RCC_PLLNCFGR2_DIVQ_MASK;
1348 value |= (pllcfg[PLLCFG_R] << RCC_PLLNCFGR2_DIVR_SHIFT) &
1349 RCC_PLLNCFGR2_DIVR_MASK;
1350 if (mmio_read_32(rcc_base + pll->pllxcfgr2) != value) {
1351 return false;
1352 }
1353
1354 return true;
1355}
1356
1357static void stm32mp1_pll_start(enum stm32mp1_pll_id pll_id)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001358{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001359 const struct stm32mp1_clk_pll *pll = pll_ref(pll_id);
1360 uintptr_t pllxcr = stm32mp_rcc_base() + pll->pllxcr;
Yann Gautier9aea69e2018-07-24 17:13:36 +02001361
Yann Gautierd0dcbaa2019-06-04 15:55:37 +02001362 /* Preserve RCC_PLLNCR_SSCG_CTRL value */
1363 mmio_clrsetbits_32(pllxcr,
1364 RCC_PLLNCR_DIVPEN | RCC_PLLNCR_DIVQEN |
1365 RCC_PLLNCR_DIVREN,
1366 RCC_PLLNCR_PLLON);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001367}
1368
Yann Gautiere4a3c352019-02-14 10:53:33 +01001369static int stm32mp1_pll_output(enum stm32mp1_pll_id pll_id, uint32_t output)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001370{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001371 const struct stm32mp1_clk_pll *pll = pll_ref(pll_id);
1372 uintptr_t pllxcr = stm32mp_rcc_base() + pll->pllxcr;
Yann Gautier2299d572019-02-14 11:14:39 +01001373 uint64_t timeout = timeout_init_us(PLLRDY_TIMEOUT);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001374
Yann Gautier9aea69e2018-07-24 17:13:36 +02001375 /* Wait PLL lock */
1376 while ((mmio_read_32(pllxcr) & RCC_PLLNCR_PLLRDY) == 0U) {
Yann Gautier2299d572019-02-14 11:14:39 +01001377 if (timeout_elapsed(timeout)) {
Yann Gautiere4a3c352019-02-14 10:53:33 +01001378 ERROR("PLL%d start failed @ 0x%lx: 0x%x\n",
Yann Gautier9aea69e2018-07-24 17:13:36 +02001379 pll_id, pllxcr, mmio_read_32(pllxcr));
1380 return -ETIMEDOUT;
1381 }
1382 }
1383
1384 /* Start the requested output */
1385 mmio_setbits_32(pllxcr, output << RCC_PLLNCR_DIVEN_SHIFT);
1386
1387 return 0;
1388}
1389
Yann Gautiere4a3c352019-02-14 10:53:33 +01001390static int stm32mp1_pll_stop(enum stm32mp1_pll_id pll_id)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001391{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001392 const struct stm32mp1_clk_pll *pll = pll_ref(pll_id);
1393 uintptr_t pllxcr = stm32mp_rcc_base() + pll->pllxcr;
Yann Gautier2299d572019-02-14 11:14:39 +01001394 uint64_t timeout;
Yann Gautier9aea69e2018-07-24 17:13:36 +02001395
1396 /* Stop all output */
1397 mmio_clrbits_32(pllxcr, RCC_PLLNCR_DIVPEN | RCC_PLLNCR_DIVQEN |
1398 RCC_PLLNCR_DIVREN);
1399
1400 /* Stop PLL */
1401 mmio_clrbits_32(pllxcr, RCC_PLLNCR_PLLON);
1402
Yann Gautier2299d572019-02-14 11:14:39 +01001403 timeout = timeout_init_us(PLLRDY_TIMEOUT);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001404 /* Wait PLL stopped */
1405 while ((mmio_read_32(pllxcr) & RCC_PLLNCR_PLLRDY) != 0U) {
Yann Gautier2299d572019-02-14 11:14:39 +01001406 if (timeout_elapsed(timeout)) {
Yann Gautiere4a3c352019-02-14 10:53:33 +01001407 ERROR("PLL%d stop failed @ 0x%lx: 0x%x\n",
Yann Gautier9aea69e2018-07-24 17:13:36 +02001408 pll_id, pllxcr, mmio_read_32(pllxcr));
1409 return -ETIMEDOUT;
1410 }
1411 }
1412
1413 return 0;
1414}
1415
Yann Gautiere4a3c352019-02-14 10:53:33 +01001416static void stm32mp1_pll_config_output(enum stm32mp1_pll_id pll_id,
Yann Gautier9aea69e2018-07-24 17:13:36 +02001417 uint32_t *pllcfg)
1418{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001419 const struct stm32mp1_clk_pll *pll = pll_ref(pll_id);
1420 uintptr_t rcc_base = stm32mp_rcc_base();
Yann Gautier9aea69e2018-07-24 17:13:36 +02001421 uint32_t value;
1422
1423 value = (pllcfg[PLLCFG_P] << RCC_PLLNCFGR2_DIVP_SHIFT) &
1424 RCC_PLLNCFGR2_DIVP_MASK;
1425 value |= (pllcfg[PLLCFG_Q] << RCC_PLLNCFGR2_DIVQ_SHIFT) &
1426 RCC_PLLNCFGR2_DIVQ_MASK;
1427 value |= (pllcfg[PLLCFG_R] << RCC_PLLNCFGR2_DIVR_SHIFT) &
1428 RCC_PLLNCFGR2_DIVR_MASK;
Yann Gautiere4a3c352019-02-14 10:53:33 +01001429 mmio_write_32(rcc_base + pll->pllxcfgr2, value);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001430}
1431
Yann Gautiere4a3c352019-02-14 10:53:33 +01001432static int stm32mp1_pll_config(enum stm32mp1_pll_id pll_id,
Yann Gautier9aea69e2018-07-24 17:13:36 +02001433 uint32_t *pllcfg, uint32_t fracv)
1434{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001435 const struct stm32mp1_clk_pll *pll = pll_ref(pll_id);
1436 uintptr_t rcc_base = stm32mp_rcc_base();
1437 enum stm32mp1_plltype type = pll->plltype;
Yann Gautier9aea69e2018-07-24 17:13:36 +02001438 unsigned long refclk;
1439 uint32_t ifrge = 0;
1440 uint32_t src, value;
1441
Yann Gautiere4a3c352019-02-14 10:53:33 +01001442 src = mmio_read_32(rcc_base + pll->rckxselr) &
Yann Gautier9aea69e2018-07-24 17:13:36 +02001443 RCC_SELR_REFCLK_SRC_MASK;
1444
Yann Gautiere4a3c352019-02-14 10:53:33 +01001445 refclk = stm32mp1_clk_get_fixed(pll->refclk[src]) /
Yann Gautier9aea69e2018-07-24 17:13:36 +02001446 (pllcfg[PLLCFG_M] + 1U);
1447
1448 if ((refclk < (stm32mp1_pll[type].refclk_min * 1000000U)) ||
1449 (refclk > (stm32mp1_pll[type].refclk_max * 1000000U))) {
1450 return -EINVAL;
1451 }
1452
1453 if ((type == PLL_800) && (refclk >= 8000000U)) {
1454 ifrge = 1U;
1455 }
1456
1457 value = (pllcfg[PLLCFG_N] << RCC_PLLNCFGR1_DIVN_SHIFT) &
1458 RCC_PLLNCFGR1_DIVN_MASK;
1459 value |= (pllcfg[PLLCFG_M] << RCC_PLLNCFGR1_DIVM_SHIFT) &
1460 RCC_PLLNCFGR1_DIVM_MASK;
1461 value |= (ifrge << RCC_PLLNCFGR1_IFRGE_SHIFT) &
1462 RCC_PLLNCFGR1_IFRGE_MASK;
Yann Gautiere4a3c352019-02-14 10:53:33 +01001463 mmio_write_32(rcc_base + pll->pllxcfgr1, value);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001464
1465 /* Fractional configuration */
1466 value = 0;
Yann Gautiere4a3c352019-02-14 10:53:33 +01001467 mmio_write_32(rcc_base + pll->pllxfracr, value);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001468
1469 value = fracv << RCC_PLLNFRACR_FRACV_SHIFT;
Yann Gautiere4a3c352019-02-14 10:53:33 +01001470 mmio_write_32(rcc_base + pll->pllxfracr, value);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001471
1472 value |= RCC_PLLNFRACR_FRACLE;
Yann Gautiere4a3c352019-02-14 10:53:33 +01001473 mmio_write_32(rcc_base + pll->pllxfracr, value);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001474
Yann Gautiere4a3c352019-02-14 10:53:33 +01001475 stm32mp1_pll_config_output(pll_id, pllcfg);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001476
1477 return 0;
1478}
1479
Yann Gautiere4a3c352019-02-14 10:53:33 +01001480static void stm32mp1_pll_csg(enum stm32mp1_pll_id pll_id, uint32_t *csg)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001481{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001482 const struct stm32mp1_clk_pll *pll = pll_ref(pll_id);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001483 uint32_t pllxcsg = 0;
1484
1485 pllxcsg |= (csg[PLLCSG_MOD_PER] << RCC_PLLNCSGR_MOD_PER_SHIFT) &
1486 RCC_PLLNCSGR_MOD_PER_MASK;
1487
1488 pllxcsg |= (csg[PLLCSG_INC_STEP] << RCC_PLLNCSGR_INC_STEP_SHIFT) &
1489 RCC_PLLNCSGR_INC_STEP_MASK;
1490
1491 pllxcsg |= (csg[PLLCSG_SSCG_MODE] << RCC_PLLNCSGR_SSCG_MODE_SHIFT) &
1492 RCC_PLLNCSGR_SSCG_MODE_MASK;
1493
Yann Gautiere4a3c352019-02-14 10:53:33 +01001494 mmio_write_32(stm32mp_rcc_base() + pll->pllxcsgr, pllxcsg);
Yann Gautierd0dcbaa2019-06-04 15:55:37 +02001495
1496 mmio_setbits_32(stm32mp_rcc_base() + pll->pllxcr,
1497 RCC_PLLNCR_SSCG_CTRL);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001498}
1499
Yann Gautiere4a3c352019-02-14 10:53:33 +01001500static int stm32mp1_set_clksrc(unsigned int clksrc)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001501{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001502 uintptr_t clksrc_address = stm32mp_rcc_base() + (clksrc >> 4);
Yann Gautier2299d572019-02-14 11:14:39 +01001503 uint64_t timeout;
Yann Gautier9aea69e2018-07-24 17:13:36 +02001504
Yann Gautiere4a3c352019-02-14 10:53:33 +01001505 mmio_clrsetbits_32(clksrc_address, RCC_SELR_SRC_MASK,
Yann Gautier9aea69e2018-07-24 17:13:36 +02001506 clksrc & RCC_SELR_SRC_MASK);
1507
Yann Gautier2299d572019-02-14 11:14:39 +01001508 timeout = timeout_init_us(CLKSRC_TIMEOUT);
Yann Gautiere4a3c352019-02-14 10:53:33 +01001509 while ((mmio_read_32(clksrc_address) & RCC_SELR_SRCRDY) == 0U) {
Yann Gautier2299d572019-02-14 11:14:39 +01001510 if (timeout_elapsed(timeout)) {
Yann Gautiere4a3c352019-02-14 10:53:33 +01001511 ERROR("CLKSRC %x start failed @ 0x%lx: 0x%x\n", clksrc,
1512 clksrc_address, mmio_read_32(clksrc_address));
Yann Gautier9aea69e2018-07-24 17:13:36 +02001513 return -ETIMEDOUT;
1514 }
1515 }
1516
1517 return 0;
1518}
1519
Yann Gautiere4a3c352019-02-14 10:53:33 +01001520static int stm32mp1_set_clkdiv(unsigned int clkdiv, uintptr_t address)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001521{
Yann Gautier2299d572019-02-14 11:14:39 +01001522 uint64_t timeout;
Yann Gautier9aea69e2018-07-24 17:13:36 +02001523
1524 mmio_clrsetbits_32(address, RCC_DIVR_DIV_MASK,
1525 clkdiv & RCC_DIVR_DIV_MASK);
1526
Yann Gautier2299d572019-02-14 11:14:39 +01001527 timeout = timeout_init_us(CLKDIV_TIMEOUT);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001528 while ((mmio_read_32(address) & RCC_DIVR_DIVRDY) == 0U) {
Yann Gautier2299d572019-02-14 11:14:39 +01001529 if (timeout_elapsed(timeout)) {
Yann Gautiere4a3c352019-02-14 10:53:33 +01001530 ERROR("CLKDIV %x start failed @ 0x%lx: 0x%x\n",
Yann Gautier9aea69e2018-07-24 17:13:36 +02001531 clkdiv, address, mmio_read_32(address));
1532 return -ETIMEDOUT;
1533 }
1534 }
1535
1536 return 0;
1537}
1538
Yann Gautiere4a3c352019-02-14 10:53:33 +01001539static void stm32mp1_mco_csg(uint32_t clksrc, uint32_t clkdiv)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001540{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001541 uintptr_t clksrc_address = stm32mp_rcc_base() + (clksrc >> 4);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001542
1543 /*
1544 * Binding clksrc :
1545 * bit15-4 offset
1546 * bit3: disable
1547 * bit2-0: MCOSEL[2:0]
1548 */
1549 if ((clksrc & 0x8U) != 0U) {
Yann Gautiere4a3c352019-02-14 10:53:33 +01001550 mmio_clrbits_32(clksrc_address, RCC_MCOCFG_MCOON);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001551 } else {
Yann Gautiere4a3c352019-02-14 10:53:33 +01001552 mmio_clrsetbits_32(clksrc_address,
Yann Gautier9aea69e2018-07-24 17:13:36 +02001553 RCC_MCOCFG_MCOSRC_MASK,
1554 clksrc & RCC_MCOCFG_MCOSRC_MASK);
Yann Gautiere4a3c352019-02-14 10:53:33 +01001555 mmio_clrsetbits_32(clksrc_address,
Yann Gautier9aea69e2018-07-24 17:13:36 +02001556 RCC_MCOCFG_MCODIV_MASK,
1557 clkdiv << RCC_MCOCFG_MCODIV_SHIFT);
Yann Gautiere4a3c352019-02-14 10:53:33 +01001558 mmio_setbits_32(clksrc_address, RCC_MCOCFG_MCOON);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001559 }
1560}
1561
Yann Gautiere4a3c352019-02-14 10:53:33 +01001562static void stm32mp1_set_rtcsrc(unsigned int clksrc, bool lse_css)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001563{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001564 uintptr_t address = stm32mp_rcc_base() + RCC_BDCR;
Yann Gautier9aea69e2018-07-24 17:13:36 +02001565
1566 if (((mmio_read_32(address) & RCC_BDCR_RTCCKEN) == 0U) ||
1567 (clksrc != (uint32_t)CLK_RTC_DISABLED)) {
1568 mmio_clrsetbits_32(address,
1569 RCC_BDCR_RTCSRC_MASK,
1570 clksrc << RCC_BDCR_RTCSRC_SHIFT);
1571
1572 mmio_setbits_32(address, RCC_BDCR_RTCCKEN);
1573 }
1574
1575 if (lse_css) {
1576 mmio_setbits_32(address, RCC_BDCR_LSECSSON);
1577 }
1578}
1579
Yann Gautiere4a3c352019-02-14 10:53:33 +01001580static void stm32mp1_stgen_config(void)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001581{
1582 uintptr_t stgen;
Yann Gautier9aea69e2018-07-24 17:13:36 +02001583 uint32_t cntfid0;
1584 unsigned long rate;
Yann Gautiere4a3c352019-02-14 10:53:33 +01001585 unsigned long long counter;
Yann Gautier9aea69e2018-07-24 17:13:36 +02001586
1587 stgen = fdt_get_stgen_base();
Yann Gautier9aea69e2018-07-24 17:13:36 +02001588 cntfid0 = mmio_read_32(stgen + CNTFID_OFF);
Yann Gautiere4a3c352019-02-14 10:53:33 +01001589 rate = get_clock_rate(stm32mp1_clk_get_parent(STGEN_K));
Yann Gautier9aea69e2018-07-24 17:13:36 +02001590
Yann Gautiere4a3c352019-02-14 10:53:33 +01001591 if (cntfid0 == rate) {
1592 return;
1593 }
Yann Gautier9aea69e2018-07-24 17:13:36 +02001594
Yann Gautiere4a3c352019-02-14 10:53:33 +01001595 mmio_clrbits_32(stgen + CNTCR_OFF, CNTCR_EN);
1596 counter = (unsigned long long)mmio_read_32(stgen + CNTCVL_OFF);
1597 counter |= ((unsigned long long)mmio_read_32(stgen + CNTCVU_OFF)) << 32;
1598 counter = (counter * rate / cntfid0);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001599
Yann Gautiere4a3c352019-02-14 10:53:33 +01001600 mmio_write_32(stgen + CNTCVL_OFF, (uint32_t)counter);
1601 mmio_write_32(stgen + CNTCVU_OFF, (uint32_t)(counter >> 32));
1602 mmio_write_32(stgen + CNTFID_OFF, rate);
1603 mmio_setbits_32(stgen + CNTCR_OFF, CNTCR_EN);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001604
Yann Gautiere4a3c352019-02-14 10:53:33 +01001605 write_cntfrq((u_register_t)rate);
1606
1607 /* Need to update timer with new frequency */
1608 generic_delay_timer_init();
Yann Gautier9aea69e2018-07-24 17:13:36 +02001609}
1610
1611void stm32mp1_stgen_increment(unsigned long long offset_in_ms)
1612{
1613 uintptr_t stgen;
1614 unsigned long long cnt;
1615
1616 stgen = fdt_get_stgen_base();
1617
1618 cnt = ((unsigned long long)mmio_read_32(stgen + CNTCVU_OFF) << 32) |
1619 mmio_read_32(stgen + CNTCVL_OFF);
1620
1621 cnt += (offset_in_ms * mmio_read_32(stgen + CNTFID_OFF)) / 1000U;
1622
1623 mmio_clrbits_32(stgen + CNTCR_OFF, CNTCR_EN);
1624 mmio_write_32(stgen + CNTCVL_OFF, (uint32_t)cnt);
1625 mmio_write_32(stgen + CNTCVU_OFF, (uint32_t)(cnt >> 32));
1626 mmio_setbits_32(stgen + CNTCR_OFF, CNTCR_EN);
1627}
1628
Yann Gautiere4a3c352019-02-14 10:53:33 +01001629static void stm32mp1_pkcs_config(uint32_t pkcs)
Yann Gautier9aea69e2018-07-24 17:13:36 +02001630{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001631 uintptr_t address = stm32mp_rcc_base() + ((pkcs >> 4) & 0xFFFU);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001632 uint32_t value = pkcs & 0xFU;
1633 uint32_t mask = 0xFU;
1634
1635 if ((pkcs & BIT(31)) != 0U) {
1636 mask <<= 4;
1637 value <<= 4;
1638 }
1639
1640 mmio_clrsetbits_32(address, mask, value);
1641}
1642
1643int stm32mp1_clk_init(void)
1644{
Yann Gautiere4a3c352019-02-14 10:53:33 +01001645 uintptr_t rcc_base = stm32mp_rcc_base();
Yann Gautier9aea69e2018-07-24 17:13:36 +02001646 unsigned int clksrc[CLKSRC_NB];
1647 unsigned int clkdiv[CLKDIV_NB];
1648 unsigned int pllcfg[_PLL_NB][PLLCFG_NB];
1649 int plloff[_PLL_NB];
1650 int ret, len;
1651 enum stm32mp1_pll_id i;
1652 bool lse_css = false;
Yann Gautiere4a3c352019-02-14 10:53:33 +01001653 bool pll3_preserve = false;
1654 bool pll4_preserve = false;
1655 bool pll4_bootrom = false;
Yann Gautierf9af3bc2018-11-09 15:57:18 +01001656 const fdt32_t *pkcs_cell;
Andre Przywaracc99f3f2020-03-26 12:51:21 +00001657 void *fdt;
1658
1659 if (fdt_get_address(&fdt) == 0) {
1660 return false;
1661 }
Yann Gautier9aea69e2018-07-24 17:13:36 +02001662
1663 /* Check status field to disable security */
1664 if (!fdt_get_rcc_secure_status()) {
Yann Gautiere4a3c352019-02-14 10:53:33 +01001665 mmio_write_32(rcc_base + RCC_TZCR, 0);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001666 }
1667
Andre Przywaracc99f3f2020-03-26 12:51:21 +00001668 ret = fdt_rcc_read_uint32_array("st,clksrc", (uint32_t)CLKSRC_NB,
1669 clksrc);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001670 if (ret < 0) {
1671 return -FDT_ERR_NOTFOUND;
1672 }
1673
Andre Przywaracc99f3f2020-03-26 12:51:21 +00001674 ret = fdt_rcc_read_uint32_array("st,clkdiv", (uint32_t)CLKDIV_NB,
1675 clkdiv);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001676 if (ret < 0) {
1677 return -FDT_ERR_NOTFOUND;
1678 }
1679
1680 for (i = (enum stm32mp1_pll_id)0; i < _PLL_NB; i++) {
1681 char name[12];
1682
Antonio Nino Diaz00086e32018-08-16 16:46:06 +01001683 snprintf(name, sizeof(name), "st,pll@%d", i);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001684 plloff[i] = fdt_rcc_subnode_offset(name);
1685
1686 if (!fdt_check_node(plloff[i])) {
1687 continue;
1688 }
1689
Andre Przywaracc99f3f2020-03-26 12:51:21 +00001690 ret = fdt_read_uint32_array(fdt, plloff[i], "cfg",
1691 (int)PLLCFG_NB, pllcfg[i]);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001692 if (ret < 0) {
1693 return -FDT_ERR_NOTFOUND;
1694 }
1695 }
1696
Yann Gautiere4a3c352019-02-14 10:53:33 +01001697 stm32mp1_mco_csg(clksrc[CLKSRC_MCO1], clkdiv[CLKDIV_MCO1]);
1698 stm32mp1_mco_csg(clksrc[CLKSRC_MCO2], clkdiv[CLKDIV_MCO2]);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001699
1700 /*
1701 * Switch ON oscillator found in device-tree.
1702 * Note: HSI already ON after BootROM stage.
1703 */
Yann Gautiere4a3c352019-02-14 10:53:33 +01001704 if (stm32mp1_osc[_LSI] != 0U) {
1705 stm32mp1_lsi_set(true);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001706 }
Yann Gautiere4a3c352019-02-14 10:53:33 +01001707 if (stm32mp1_osc[_LSE] != 0U) {
1708 bool bypass, digbyp;
Yann Gautier9aea69e2018-07-24 17:13:36 +02001709 uint32_t lsedrv;
1710
1711 bypass = fdt_osc_read_bool(_LSE, "st,bypass");
Yann Gautiere4a3c352019-02-14 10:53:33 +01001712 digbyp = fdt_osc_read_bool(_LSE, "st,digbypass");
Yann Gautier9aea69e2018-07-24 17:13:36 +02001713 lse_css = fdt_osc_read_bool(_LSE, "st,css");
1714 lsedrv = fdt_osc_read_uint32_default(_LSE, "st,drive",
1715 LSEDRV_MEDIUM_HIGH);
Yann Gautiere4a3c352019-02-14 10:53:33 +01001716 stm32mp1_lse_enable(bypass, digbyp, lsedrv);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001717 }
Yann Gautiere4a3c352019-02-14 10:53:33 +01001718 if (stm32mp1_osc[_HSE] != 0U) {
1719 bool bypass, digbyp, css;
Yann Gautier9aea69e2018-07-24 17:13:36 +02001720
Yann Gautiere4a3c352019-02-14 10:53:33 +01001721 bypass = fdt_osc_read_bool(_HSE, "st,bypass");
1722 digbyp = fdt_osc_read_bool(_HSE, "st,digbypass");
1723 css = fdt_osc_read_bool(_HSE, "st,css");
1724 stm32mp1_hse_enable(bypass, digbyp, css);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001725 }
1726 /*
1727 * CSI is mandatory for automatic I/O compensation (SYSCFG_CMPCR)
1728 * => switch on CSI even if node is not present in device tree
1729 */
Yann Gautiere4a3c352019-02-14 10:53:33 +01001730 stm32mp1_csi_set(true);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001731
1732 /* Come back to HSI */
Yann Gautiere4a3c352019-02-14 10:53:33 +01001733 ret = stm32mp1_set_clksrc(CLK_MPU_HSI);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001734 if (ret != 0) {
1735 return ret;
1736 }
Yann Gautiere4a3c352019-02-14 10:53:33 +01001737 ret = stm32mp1_set_clksrc(CLK_AXI_HSI);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001738 if (ret != 0) {
1739 return ret;
1740 }
Yann Gautiered342322019-02-15 17:33:27 +01001741 ret = stm32mp1_set_clksrc(CLK_MCU_HSI);
1742 if (ret != 0) {
1743 return ret;
1744 }
Yann Gautier9aea69e2018-07-24 17:13:36 +02001745
Yann Gautiere4a3c352019-02-14 10:53:33 +01001746 if ((mmio_read_32(rcc_base + RCC_MP_RSTSCLRR) &
1747 RCC_MP_RSTSCLRR_MPUP0RSTF) != 0) {
1748 pll3_preserve = stm32mp1_check_pll_conf(_PLL3,
1749 clksrc[CLKSRC_PLL3],
1750 pllcfg[_PLL3],
1751 plloff[_PLL3]);
1752 pll4_preserve = stm32mp1_check_pll_conf(_PLL4,
1753 clksrc[CLKSRC_PLL4],
1754 pllcfg[_PLL4],
1755 plloff[_PLL4]);
1756 }
1757
Yann Gautier9aea69e2018-07-24 17:13:36 +02001758 for (i = (enum stm32mp1_pll_id)0; i < _PLL_NB; i++) {
Yann Gautiere4a3c352019-02-14 10:53:33 +01001759 if (((i == _PLL3) && pll3_preserve) ||
1760 ((i == _PLL4) && pll4_preserve)) {
Yann Gautier9aea69e2018-07-24 17:13:36 +02001761 continue;
Yann Gautiere4a3c352019-02-14 10:53:33 +01001762 }
1763
1764 ret = stm32mp1_pll_stop(i);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001765 if (ret != 0) {
1766 return ret;
1767 }
1768 }
1769
1770 /* Configure HSIDIV */
Yann Gautiere4a3c352019-02-14 10:53:33 +01001771 if (stm32mp1_osc[_HSI] != 0U) {
1772 ret = stm32mp1_hsidiv(stm32mp1_osc[_HSI]);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001773 if (ret != 0) {
1774 return ret;
1775 }
Yann Gautiere4a3c352019-02-14 10:53:33 +01001776 stm32mp1_stgen_config();
Yann Gautier9aea69e2018-07-24 17:13:36 +02001777 }
1778
1779 /* Select DIV */
1780 /* No ready bit when MPUSRC != CLK_MPU_PLL1P_DIV, MPUDIV is disabled */
Yann Gautiere4a3c352019-02-14 10:53:33 +01001781 mmio_write_32(rcc_base + RCC_MPCKDIVR,
Yann Gautier9aea69e2018-07-24 17:13:36 +02001782 clkdiv[CLKDIV_MPU] & RCC_DIVR_DIV_MASK);
Yann Gautiere4a3c352019-02-14 10:53:33 +01001783 ret = stm32mp1_set_clkdiv(clkdiv[CLKDIV_AXI], rcc_base + RCC_AXIDIVR);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001784 if (ret != 0) {
1785 return ret;
1786 }
Yann Gautiere4a3c352019-02-14 10:53:33 +01001787 ret = stm32mp1_set_clkdiv(clkdiv[CLKDIV_APB4], rcc_base + RCC_APB4DIVR);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001788 if (ret != 0) {
1789 return ret;
1790 }
Yann Gautiere4a3c352019-02-14 10:53:33 +01001791 ret = stm32mp1_set_clkdiv(clkdiv[CLKDIV_APB5], rcc_base + RCC_APB5DIVR);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001792 if (ret != 0) {
1793 return ret;
1794 }
Yann Gautiered342322019-02-15 17:33:27 +01001795 ret = stm32mp1_set_clkdiv(clkdiv[CLKDIV_MCU], rcc_base + RCC_MCUDIVR);
1796 if (ret != 0) {
1797 return ret;
1798 }
Yann Gautiere4a3c352019-02-14 10:53:33 +01001799 ret = stm32mp1_set_clkdiv(clkdiv[CLKDIV_APB1], rcc_base + RCC_APB1DIVR);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001800 if (ret != 0) {
1801 return ret;
1802 }
Yann Gautiere4a3c352019-02-14 10:53:33 +01001803 ret = stm32mp1_set_clkdiv(clkdiv[CLKDIV_APB2], rcc_base + RCC_APB2DIVR);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001804 if (ret != 0) {
1805 return ret;
1806 }
Yann Gautiere4a3c352019-02-14 10:53:33 +01001807 ret = stm32mp1_set_clkdiv(clkdiv[CLKDIV_APB3], rcc_base + RCC_APB3DIVR);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001808 if (ret != 0) {
1809 return ret;
1810 }
1811
1812 /* No ready bit for RTC */
Yann Gautiere4a3c352019-02-14 10:53:33 +01001813 mmio_write_32(rcc_base + RCC_RTCDIVR,
Yann Gautier9aea69e2018-07-24 17:13:36 +02001814 clkdiv[CLKDIV_RTC] & RCC_DIVR_DIV_MASK);
1815
1816 /* Configure PLLs source */
Yann Gautiere4a3c352019-02-14 10:53:33 +01001817 ret = stm32mp1_set_clksrc(clksrc[CLKSRC_PLL12]);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001818 if (ret != 0) {
1819 return ret;
1820 }
Yann Gautiere4a3c352019-02-14 10:53:33 +01001821
1822 if (!pll3_preserve) {
1823 ret = stm32mp1_set_clksrc(clksrc[CLKSRC_PLL3]);
1824 if (ret != 0) {
1825 return ret;
1826 }
Yann Gautier9aea69e2018-07-24 17:13:36 +02001827 }
1828
Yann Gautiere4a3c352019-02-14 10:53:33 +01001829 if (!pll4_preserve) {
1830 ret = stm32mp1_set_clksrc(clksrc[CLKSRC_PLL4]);
1831 if (ret != 0) {
1832 return ret;
1833 }
Yann Gautier9aea69e2018-07-24 17:13:36 +02001834 }
1835
1836 /* Configure and start PLLs */
1837 for (i = (enum stm32mp1_pll_id)0; i < _PLL_NB; i++) {
1838 uint32_t fracv;
1839 uint32_t csg[PLLCSG_NB];
1840
Yann Gautiere4a3c352019-02-14 10:53:33 +01001841 if (((i == _PLL3) && pll3_preserve) ||
1842 ((i == _PLL4) && pll4_preserve && !pll4_bootrom)) {
1843 continue;
1844 }
1845
Yann Gautier9aea69e2018-07-24 17:13:36 +02001846 if (!fdt_check_node(plloff[i])) {
1847 continue;
1848 }
1849
Yann Gautiere4a3c352019-02-14 10:53:33 +01001850 if ((i == _PLL4) && pll4_bootrom) {
1851 /* Set output divider if not done by the Bootrom */
1852 stm32mp1_pll_config_output(i, pllcfg[i]);
1853 continue;
1854 }
1855
Andre Przywara2d5690c2020-03-26 11:50:33 +00001856 fracv = fdt_read_uint32_default(fdt, plloff[i], "frac", 0);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001857
Yann Gautiere4a3c352019-02-14 10:53:33 +01001858 ret = stm32mp1_pll_config(i, pllcfg[i], fracv);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001859 if (ret != 0) {
1860 return ret;
1861 }
Andre Przywaracc99f3f2020-03-26 12:51:21 +00001862 ret = fdt_read_uint32_array(fdt, plloff[i], "csg",
1863 (uint32_t)PLLCSG_NB, csg);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001864 if (ret == 0) {
Yann Gautiere4a3c352019-02-14 10:53:33 +01001865 stm32mp1_pll_csg(i, csg);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001866 } else if (ret != -FDT_ERR_NOTFOUND) {
1867 return ret;
1868 }
1869
Yann Gautiere4a3c352019-02-14 10:53:33 +01001870 stm32mp1_pll_start(i);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001871 }
1872 /* Wait and start PLLs ouptut when ready */
1873 for (i = (enum stm32mp1_pll_id)0; i < _PLL_NB; i++) {
1874 if (!fdt_check_node(plloff[i])) {
1875 continue;
1876 }
1877
Yann Gautiere4a3c352019-02-14 10:53:33 +01001878 ret = stm32mp1_pll_output(i, pllcfg[i][PLLCFG_O]);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001879 if (ret != 0) {
1880 return ret;
1881 }
1882 }
1883 /* Wait LSE ready before to use it */
Yann Gautiere4a3c352019-02-14 10:53:33 +01001884 if (stm32mp1_osc[_LSE] != 0U) {
1885 stm32mp1_lse_wait();
Yann Gautier9aea69e2018-07-24 17:13:36 +02001886 }
1887
1888 /* Configure with expected clock source */
Yann Gautiere4a3c352019-02-14 10:53:33 +01001889 ret = stm32mp1_set_clksrc(clksrc[CLKSRC_MPU]);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001890 if (ret != 0) {
1891 return ret;
1892 }
Yann Gautiere4a3c352019-02-14 10:53:33 +01001893 ret = stm32mp1_set_clksrc(clksrc[CLKSRC_AXI]);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001894 if (ret != 0) {
1895 return ret;
1896 }
Yann Gautiered342322019-02-15 17:33:27 +01001897 ret = stm32mp1_set_clksrc(clksrc[CLKSRC_MCU]);
1898 if (ret != 0) {
1899 return ret;
1900 }
Yann Gautiere4a3c352019-02-14 10:53:33 +01001901 stm32mp1_set_rtcsrc(clksrc[CLKSRC_RTC], lse_css);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001902
1903 /* Configure PKCK */
1904 pkcs_cell = fdt_rcc_read_prop("st,pkcs", &len);
1905 if (pkcs_cell != NULL) {
1906 bool ckper_disabled = false;
1907 uint32_t j;
1908
Yann Gautier9aea69e2018-07-24 17:13:36 +02001909 for (j = 0; j < ((uint32_t)len / sizeof(uint32_t)); j++) {
Yann Gautierf9af3bc2018-11-09 15:57:18 +01001910 uint32_t pkcs = fdt32_to_cpu(pkcs_cell[j]);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001911
1912 if (pkcs == (uint32_t)CLK_CKPER_DISABLED) {
1913 ckper_disabled = true;
1914 continue;
1915 }
Yann Gautiere4a3c352019-02-14 10:53:33 +01001916 stm32mp1_pkcs_config(pkcs);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001917 }
1918
1919 /*
1920 * CKPER is source for some peripheral clocks
1921 * (FMC-NAND / QPSI-NOR) and switching source is allowed
1922 * only if previous clock is still ON
1923 * => deactivated CKPER only after switching clock
1924 */
1925 if (ckper_disabled) {
Yann Gautiere4a3c352019-02-14 10:53:33 +01001926 stm32mp1_pkcs_config(CLK_CKPER_DISABLED);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001927 }
1928 }
1929
1930 /* Switch OFF HSI if not found in device-tree */
Yann Gautiere4a3c352019-02-14 10:53:33 +01001931 if (stm32mp1_osc[_HSI] == 0U) {
1932 stm32mp1_hsi_set(false);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001933 }
Yann Gautiere4a3c352019-02-14 10:53:33 +01001934 stm32mp1_stgen_config();
Yann Gautier9aea69e2018-07-24 17:13:36 +02001935
1936 /* Software Self-Refresh mode (SSR) during DDR initilialization */
Yann Gautiere4a3c352019-02-14 10:53:33 +01001937 mmio_clrsetbits_32(rcc_base + RCC_DDRITFCR,
Yann Gautier9aea69e2018-07-24 17:13:36 +02001938 RCC_DDRITFCR_DDRCKMOD_MASK,
1939 RCC_DDRITFCR_DDRCKMOD_SSR <<
1940 RCC_DDRITFCR_DDRCKMOD_SHIFT);
1941
1942 return 0;
1943}
1944
1945static void stm32mp1_osc_clk_init(const char *name,
Yann Gautier9aea69e2018-07-24 17:13:36 +02001946 enum stm32mp_osc_id index)
1947{
1948 uint32_t frequency;
1949
Yann Gautiere4a3c352019-02-14 10:53:33 +01001950 if (fdt_osc_read_freq(name, &frequency) == 0) {
1951 stm32mp1_osc[index] = frequency;
Yann Gautier9aea69e2018-07-24 17:13:36 +02001952 }
1953}
1954
1955static void stm32mp1_osc_init(void)
1956{
Yann Gautier9aea69e2018-07-24 17:13:36 +02001957 enum stm32mp_osc_id i;
1958
1959 for (i = (enum stm32mp_osc_id)0 ; i < NB_OSC; i++) {
Yann Gautiere4a3c352019-02-14 10:53:33 +01001960 stm32mp1_osc_clk_init(stm32mp_osc_node_label[i], i);
Yann Gautier9aea69e2018-07-24 17:13:36 +02001961 }
1962}
1963
Yann Gautierc7f9e962019-05-20 14:39:26 +02001964static void sync_earlyboot_clocks_state(void)
1965{
1966 if (!stm32mp_is_single_core()) {
1967 stm32mp1_clk_enable_secure(RTCAPB);
1968 }
1969}
1970
Yann Gautier9aea69e2018-07-24 17:13:36 +02001971int stm32mp1_clk_probe(void)
1972{
Yann Gautier9aea69e2018-07-24 17:13:36 +02001973 stm32mp1_osc_init();
1974
Yann Gautierc7f9e962019-05-20 14:39:26 +02001975 sync_earlyboot_clocks_state();
1976
Yann Gautier9aea69e2018-07-24 17:13:36 +02001977 return 0;
1978}