1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
4 * Author(s): Vikas Manocha, <vikas.manocha@st.com> for STMicroelectronics.
8 #include <clk-uclass.h>
11 #include <stm32_rcc.h>
12 #include <linux/bitops.h>
15 #include <asm/arch/stm32.h>
16 #include <asm/arch/stm32_pwr.h>
18 #include <dt-bindings/mfd/stm32f7-rcc.h>
20 #define RCC_CR_HSION BIT(0)
21 #define RCC_CR_HSEON BIT(16)
22 #define RCC_CR_HSERDY BIT(17)
23 #define RCC_CR_HSEBYP BIT(18)
24 #define RCC_CR_CSSON BIT(19)
25 #define RCC_CR_PLLON BIT(24)
26 #define RCC_CR_PLLRDY BIT(25)
27 #define RCC_CR_PLLSAION BIT(28)
28 #define RCC_CR_PLLSAIRDY BIT(29)
30 #define RCC_PLLCFGR_PLLM_MASK GENMASK(5, 0)
31 #define RCC_PLLCFGR_PLLN_MASK GENMASK(14, 6)
32 #define RCC_PLLCFGR_PLLP_MASK GENMASK(17, 16)
33 #define RCC_PLLCFGR_PLLQ_MASK GENMASK(27, 24)
34 #define RCC_PLLCFGR_PLLSRC BIT(22)
35 #define RCC_PLLCFGR_PLLM_SHIFT 0
36 #define RCC_PLLCFGR_PLLN_SHIFT 6
37 #define RCC_PLLCFGR_PLLP_SHIFT 16
38 #define RCC_PLLCFGR_PLLQ_SHIFT 24
40 #define RCC_CFGR_AHB_PSC_MASK GENMASK(7, 4)
41 #define RCC_CFGR_APB1_PSC_MASK GENMASK(12, 10)
42 #define RCC_CFGR_APB2_PSC_MASK GENMASK(15, 13)
43 #define RCC_CFGR_SW0 BIT(0)
44 #define RCC_CFGR_SW1 BIT(1)
45 #define RCC_CFGR_SW_MASK GENMASK(1, 0)
46 #define RCC_CFGR_SW_HSI 0
47 #define RCC_CFGR_SW_HSE RCC_CFGR_SW0
48 #define RCC_CFGR_SW_PLL RCC_CFGR_SW1
49 #define RCC_CFGR_SWS0 BIT(2)
50 #define RCC_CFGR_SWS1 BIT(3)
51 #define RCC_CFGR_SWS_MASK GENMASK(3, 2)
52 #define RCC_CFGR_SWS_HSI 0
53 #define RCC_CFGR_SWS_HSE RCC_CFGR_SWS0
54 #define RCC_CFGR_SWS_PLL RCC_CFGR_SWS1
55 #define RCC_CFGR_HPRE_SHIFT 4
56 #define RCC_CFGR_PPRE1_SHIFT 10
57 #define RCC_CFGR_PPRE2_SHIFT 13
59 #define RCC_PLLSAICFGR_PLLSAIN_MASK GENMASK(14, 6)
60 #define RCC_PLLSAICFGR_PLLSAIP_MASK GENMASK(17, 16)
61 #define RCC_PLLSAICFGR_PLLSAIQ_MASK GENMASK(27, 24)
62 #define RCC_PLLSAICFGR_PLLSAIR_MASK GENMASK(30, 28)
63 #define RCC_PLLSAICFGR_PLLSAIN_SHIFT 6
64 #define RCC_PLLSAICFGR_PLLSAIP_SHIFT 16
65 #define RCC_PLLSAICFGR_PLLSAIQ_SHIFT 24
66 #define RCC_PLLSAICFGR_PLLSAIR_SHIFT 28
67 #define RCC_PLLSAICFGR_PLLSAIP_4 BIT(16)
68 #define RCC_PLLSAICFGR_PLLSAIQ_4 BIT(26)
69 #define RCC_PLLSAICFGR_PLLSAIR_3 BIT(29) | BIT(28)
71 #define RCC_DCKCFGRX_TIMPRE BIT(24)
72 #define RCC_DCKCFGRX_CK48MSEL BIT(27)
73 #define RCC_DCKCFGRX_SDMMC1SEL BIT(28)
74 #define RCC_DCKCFGR2_SDMMC2SEL BIT(29)
76 #define RCC_DCKCFGR_PLLSAIDIVR_SHIFT 16
77 #define RCC_DCKCFGR_PLLSAIDIVR_MASK GENMASK(17, 16)
78 #define RCC_DCKCFGR_PLLSAIDIVR_2 0
81 * RCC AHB1ENR specific definitions
83 #define RCC_AHB1ENR_ETHMAC_EN BIT(25)
84 #define RCC_AHB1ENR_ETHMAC_TX_EN BIT(26)
85 #define RCC_AHB1ENR_ETHMAC_RX_EN BIT(27)
88 * RCC APB1ENR specific definitions
90 #define RCC_APB1ENR_TIM2EN BIT(0)
91 #define RCC_APB1ENR_PWREN BIT(28)
94 * RCC APB2ENR specific definitions
96 #define RCC_APB2ENR_SYSCFGEN BIT(14)
97 #define RCC_APB2ENR_SAI1EN BIT(22)
105 static const struct stm32_clk_info stm32f4_clk_info = {
111 .ahb_psc = AHB_PSC_1,
112 .apb1_psc = APB_PSC_4,
113 .apb2_psc = APB_PSC_2,
115 .has_overdrive = false,
119 static const struct stm32_clk_info stm32f7_clk_info = {
125 .ahb_psc = AHB_PSC_1,
126 .apb1_psc = APB_PSC_4,
127 .apb2_psc = APB_PSC_2,
129 .has_overdrive = true,
134 struct stm32_rcc_regs *base;
135 struct stm32_pwr_regs *pwr_regs;
136 struct stm32_clk_info info;
137 unsigned long hse_rate;
141 #ifdef CONFIG_VIDEO_STM32
142 static const u8 plldivr_table[] = { 0, 0, 2, 3, 4, 5, 6, 7 };
144 static const u8 pllsaidivr_table[] = { 2, 4, 8, 16 };
146 static int configure_clocks(struct udevice *dev)
148 struct stm32_clk *priv = dev_get_priv(dev);
149 struct stm32_rcc_regs *regs = priv->base;
150 struct stm32_pwr_regs *pwr = priv->pwr_regs;
151 struct pll_psc *sys_pll_psc = &priv->info.sys_pll_psc;
153 /* Reset RCC configuration */
154 setbits_le32(®s->cr, RCC_CR_HSION);
155 writel(0, ®s->cfgr); /* Reset CFGR */
156 clrbits_le32(®s->cr, (RCC_CR_HSEON | RCC_CR_CSSON
157 | RCC_CR_PLLON | RCC_CR_PLLSAION));
158 writel(0x24003010, ®s->pllcfgr); /* Reset value from RM */
159 clrbits_le32(®s->cr, RCC_CR_HSEBYP);
160 writel(0, ®s->cir); /* Disable all interrupts */
162 /* Configure for HSE+PLL operation */
163 setbits_le32(®s->cr, RCC_CR_HSEON);
164 while (!(readl(®s->cr) & RCC_CR_HSERDY))
167 setbits_le32(®s->cfgr, ((
168 sys_pll_psc->ahb_psc << RCC_CFGR_HPRE_SHIFT)
169 | (sys_pll_psc->apb1_psc << RCC_CFGR_PPRE1_SHIFT)
170 | (sys_pll_psc->apb2_psc << RCC_CFGR_PPRE2_SHIFT)));
172 /* Configure the main PLL */
173 setbits_le32(®s->pllcfgr, RCC_PLLCFGR_PLLSRC); /* pll source HSE */
174 clrsetbits_le32(®s->pllcfgr, RCC_PLLCFGR_PLLM_MASK,
175 sys_pll_psc->pll_m << RCC_PLLCFGR_PLLM_SHIFT);
176 clrsetbits_le32(®s->pllcfgr, RCC_PLLCFGR_PLLN_MASK,
177 sys_pll_psc->pll_n << RCC_PLLCFGR_PLLN_SHIFT);
178 clrsetbits_le32(®s->pllcfgr, RCC_PLLCFGR_PLLP_MASK,
179 ((sys_pll_psc->pll_p >> 1) - 1) << RCC_PLLCFGR_PLLP_SHIFT);
180 clrsetbits_le32(®s->pllcfgr, RCC_PLLCFGR_PLLQ_MASK,
181 sys_pll_psc->pll_q << RCC_PLLCFGR_PLLQ_SHIFT);
183 /* configure SDMMC clock */
184 if (priv->info.v2) { /*stm32f7 case */
186 /* select PLLSAIP as 48MHz clock source */
187 setbits_le32(®s->dckcfgr2, RCC_DCKCFGRX_CK48MSEL);
189 /* select PLLQ as 48MHz clock source */
190 clrbits_le32(®s->dckcfgr2, RCC_DCKCFGRX_CK48MSEL);
192 /* select 48MHz as SDMMC1 clock source */
193 clrbits_le32(®s->dckcfgr2, RCC_DCKCFGRX_SDMMC1SEL);
195 /* select 48MHz as SDMMC2 clock source */
196 clrbits_le32(®s->dckcfgr2, RCC_DCKCFGR2_SDMMC2SEL);
197 } else { /* stm32f4 case */
199 /* select PLLSAIP as 48MHz clock source */
200 setbits_le32(®s->dckcfgr, RCC_DCKCFGRX_CK48MSEL);
202 /* select PLLQ as 48MHz clock source */
203 clrbits_le32(®s->dckcfgr, RCC_DCKCFGRX_CK48MSEL);
205 /* select 48MHz as SDMMC1 clock source */
206 clrbits_le32(®s->dckcfgr, RCC_DCKCFGRX_SDMMC1SEL);
210 * Configure the SAI PLL to generate LTDC pixel clock and
211 * 48 Mhz for SDMMC and USB
213 clrsetbits_le32(®s->pllsaicfgr, RCC_PLLSAICFGR_PLLSAIP_MASK,
214 RCC_PLLSAICFGR_PLLSAIP_4);
215 clrsetbits_le32(®s->pllsaicfgr, RCC_PLLSAICFGR_PLLSAIR_MASK,
216 RCC_PLLSAICFGR_PLLSAIR_3);
217 clrsetbits_le32(®s->pllsaicfgr, RCC_PLLSAICFGR_PLLSAIN_MASK,
218 195 << RCC_PLLSAICFGR_PLLSAIN_SHIFT);
220 clrsetbits_le32(®s->dckcfgr, RCC_DCKCFGR_PLLSAIDIVR_MASK,
221 RCC_DCKCFGR_PLLSAIDIVR_2 << RCC_DCKCFGR_PLLSAIDIVR_SHIFT);
223 /* Enable the main PLL */
224 setbits_le32(®s->cr, RCC_CR_PLLON);
225 while (!(readl(®s->cr) & RCC_CR_PLLRDY))
228 /* Enable the SAI PLL */
229 setbits_le32(®s->cr, RCC_CR_PLLSAION);
230 while (!(readl(®s->cr) & RCC_CR_PLLSAIRDY))
232 setbits_le32(®s->apb1enr, RCC_APB1ENR_PWREN);
234 if (priv->info.has_overdrive) {
236 * Enable high performance mode
237 * System frequency up to 200 MHz
239 setbits_le32(&pwr->cr1, PWR_CR1_ODEN);
241 while (!(readl(&pwr->csr1) & PWR_CSR1_ODRDY))
243 /* Enable the Over-drive switch */
244 setbits_le32(&pwr->cr1, PWR_CR1_ODSWEN);
246 while (!(readl(&pwr->csr1) & PWR_CSR1_ODSWRDY))
250 stm32_flash_latency_cfg(5);
251 clrbits_le32(®s->cfgr, (RCC_CFGR_SW0 | RCC_CFGR_SW1));
252 setbits_le32(®s->cfgr, RCC_CFGR_SW_PLL);
254 while ((readl(®s->cfgr) & RCC_CFGR_SWS_MASK) !=
258 #ifdef CONFIG_ETH_DESIGNWARE
259 /* gate the SYSCFG clock, needed to set RMII ethernet interface */
260 setbits_le32(®s->apb2enr, RCC_APB2ENR_SYSCFGEN);
266 static bool stm32_clk_get_ck48msel(struct stm32_clk *priv)
268 struct stm32_rcc_regs *regs = priv->base;
270 if (priv->info.v2) /*stm32f7 case */
271 return readl(®s->dckcfgr2) & RCC_DCKCFGRX_CK48MSEL;
274 return readl(®s->dckcfgr) & RCC_DCKCFGRX_CK48MSEL;
277 static unsigned long stm32_clk_get_pllsai_vco_rate(struct stm32_clk *priv)
279 struct stm32_rcc_regs *regs = priv->base;
282 pllm = (readl(®s->pllcfgr) & RCC_PLLCFGR_PLLM_MASK);
283 pllsain = ((readl(®s->pllsaicfgr) & RCC_PLLSAICFGR_PLLSAIN_MASK)
284 >> RCC_PLLSAICFGR_PLLSAIN_SHIFT);
286 return ((priv->hse_rate / pllm) * pllsain);
289 static unsigned long stm32_clk_get_pllsai_rate(struct stm32_clk *priv,
290 enum pllsai_div output)
292 struct stm32_rcc_regs *regs = priv->base;
297 pll_div_output = ((((readl(®s->pllsaicfgr)
298 & RCC_PLLSAICFGR_PLLSAIP_MASK)
299 >> RCC_PLLSAICFGR_PLLSAIP_SHIFT) + 1) << 1);
302 pll_div_output = (readl(®s->pllsaicfgr)
303 & RCC_PLLSAICFGR_PLLSAIQ_MASK)
304 >> RCC_PLLSAICFGR_PLLSAIQ_SHIFT;
307 pll_div_output = (readl(®s->pllsaicfgr)
308 & RCC_PLLSAICFGR_PLLSAIR_MASK)
309 >> RCC_PLLSAICFGR_PLLSAIR_SHIFT;
312 pr_err("incorrect PLLSAI output %d\n", output);
316 return (stm32_clk_get_pllsai_vco_rate(priv) / pll_div_output);
319 static bool stm32_get_timpre(struct stm32_clk *priv)
321 struct stm32_rcc_regs *regs = priv->base;
324 if (priv->info.v2) /*stm32f7 case */
325 val = readl(®s->dckcfgr2);
327 val = readl(®s->dckcfgr);
328 /* get timer prescaler */
329 return !!(val & RCC_DCKCFGRX_TIMPRE);
332 static u32 stm32_get_hclk_rate(struct stm32_rcc_regs *regs, u32 sysclk)
335 /* Prescaler table lookups for clock computation */
336 u8 ahb_psc_table[16] = {
337 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 6, 7, 8, 9
340 shift = ahb_psc_table[(
341 (readl(®s->cfgr) & RCC_CFGR_AHB_PSC_MASK)
342 >> RCC_CFGR_HPRE_SHIFT)];
344 return sysclk >> shift;
347 static u8 stm32_get_apb_shift(struct stm32_rcc_regs *regs, enum apb apb)
349 /* Prescaler table lookups for clock computation */
350 u8 apb_psc_table[8] = {
351 0, 0, 0, 0, 1, 2, 3, 4
355 return apb_psc_table[(
356 (readl(®s->cfgr) & RCC_CFGR_APB1_PSC_MASK)
357 >> RCC_CFGR_PPRE1_SHIFT)];
359 return apb_psc_table[(
360 (readl(®s->cfgr) & RCC_CFGR_APB2_PSC_MASK)
361 >> RCC_CFGR_PPRE2_SHIFT)];
364 static u32 stm32_get_timer_rate(struct stm32_clk *priv, u32 sysclk,
367 struct stm32_rcc_regs *regs = priv->base;
368 u8 shift = stm32_get_apb_shift(regs, apb);
370 if (stm32_get_timpre(priv))
372 * if APB prescaler is configured to a
373 * division factor of 1, 2 or 4
379 return stm32_get_hclk_rate(regs, sysclk);
381 return (sysclk >> shift) * 4;
385 * if APB prescaler is configured to a
386 * division factor of 1
391 return (sysclk >> shift) * 2;
394 static ulong stm32_clk_get_rate(struct clk *clk)
396 struct stm32_clk *priv = dev_get_priv(clk->dev);
397 struct stm32_rcc_regs *regs = priv->base;
403 u16 pllm, plln, pllp, pllq;
405 if ((readl(®s->cfgr) & RCC_CFGR_SWS_MASK) ==
407 pllm = (readl(®s->pllcfgr) & RCC_PLLCFGR_PLLM_MASK);
408 plln = ((readl(®s->pllcfgr) & RCC_PLLCFGR_PLLN_MASK)
409 >> RCC_PLLCFGR_PLLN_SHIFT);
410 pllp = ((((readl(®s->pllcfgr) & RCC_PLLCFGR_PLLP_MASK)
411 >> RCC_PLLCFGR_PLLP_SHIFT) + 1) << 1);
412 pllq = ((readl(®s->pllcfgr) & RCC_PLLCFGR_PLLQ_MASK)
413 >> RCC_PLLCFGR_PLLQ_SHIFT);
414 vco = (priv->hse_rate / pllm) * plln;
422 * AHB CLOCK: 3 x 32 bits consecutive registers are used :
423 * AHB1, AHB2 and AHB3
425 case STM32F7_AHB1_CLOCK(GPIOA) ... STM32F7_AHB3_CLOCK(QSPI):
426 return stm32_get_hclk_rate(regs, sysclk);
428 case STM32F7_APB1_CLOCK(TIM2) ... STM32F7_APB1_CLOCK(UART8):
429 /* For timer clock, an additionnal prescaler is used*/
431 case STM32F7_APB1_CLOCK(TIM2):
432 case STM32F7_APB1_CLOCK(TIM3):
433 case STM32F7_APB1_CLOCK(TIM4):
434 case STM32F7_APB1_CLOCK(TIM5):
435 case STM32F7_APB1_CLOCK(TIM6):
436 case STM32F7_APB1_CLOCK(TIM7):
437 case STM32F7_APB1_CLOCK(TIM12):
438 case STM32F7_APB1_CLOCK(TIM13):
439 case STM32F7_APB1_CLOCK(TIM14):
440 return stm32_get_timer_rate(priv, sysclk, APB1);
442 return (sysclk >> stm32_get_apb_shift(regs, APB1));
445 case STM32F7_APB2_CLOCK(TIM1) ... STM32F7_APB2_CLOCK(DSI):
448 * particular case for SDMMC1 and SDMMC2 :
449 * 48Mhz source clock can be from main PLL or from
452 case STM32F7_APB2_CLOCK(SDMMC1):
453 case STM32F7_APB2_CLOCK(SDMMC2):
454 if (clk->id == STM32F7_APB2_CLOCK(SDMMC1))
455 sdmmcxsel_bit = RCC_DCKCFGRX_SDMMC1SEL;
457 sdmmcxsel_bit = RCC_DCKCFGR2_SDMMC2SEL;
459 if (readl(®s->dckcfgr2) & sdmmcxsel_bit)
460 /* System clock is selected as SDMMC1 clock */
463 * 48 MHz can be generated by either PLLSAIP
464 * or by PLLQ depending of CK48MSEL bit of RCC_DCKCFGR
466 if (stm32_clk_get_ck48msel(priv))
467 return stm32_clk_get_pllsai_rate(priv, PLLSAIP);
472 /* For timer clock, an additionnal prescaler is used*/
473 case STM32F7_APB2_CLOCK(TIM1):
474 case STM32F7_APB2_CLOCK(TIM8):
475 case STM32F7_APB2_CLOCK(TIM9):
476 case STM32F7_APB2_CLOCK(TIM10):
477 case STM32F7_APB2_CLOCK(TIM11):
478 return stm32_get_timer_rate(priv, sysclk, APB2);
481 /* particular case for LTDC clock */
482 case STM32F7_APB2_CLOCK(LTDC):
483 saidivr = readl(®s->dckcfgr);
484 saidivr = (saidivr & RCC_DCKCFGR_PLLSAIDIVR_MASK)
485 >> RCC_DCKCFGR_PLLSAIDIVR_SHIFT;
486 pllsai_rate = stm32_clk_get_pllsai_rate(priv, PLLSAIR);
488 return pllsai_rate / pllsaidivr_table[saidivr];
490 return (sysclk >> stm32_get_apb_shift(regs, APB2));
493 pr_err("clock index %ld out of range\n", clk->id);
498 static ulong stm32_set_rate(struct clk *clk, ulong rate)
500 #ifdef CONFIG_VIDEO_STM32
501 struct stm32_clk *priv = dev_get_priv(clk->dev);
502 struct stm32_rcc_regs *regs = priv->base;
503 u32 pllsair_rate, pllsai_vco_rate, current_rate;
504 u32 best_div, best_diff, diff;
506 u8 best_plldivr, best_pllsaidivr;
510 /* Only set_rate for LTDC clock is implemented */
511 if (clk->id != STM32F7_APB2_CLOCK(LTDC)) {
512 pr_err("set_rate not implemented for clock index %ld\n",
517 if (rate == stm32_clk_get_rate(clk))
518 /* already set to requested rate */
521 /* get the current PLLSAIR output freq */
522 pllsair_rate = stm32_clk_get_pllsai_rate(priv, PLLSAIR);
523 best_div = pllsair_rate / rate;
525 /* look into pllsaidivr_table if this divider is available*/
526 for (i = 0 ; i < sizeof(pllsaidivr_table); i++)
527 if (best_div == pllsaidivr_table[i]) {
528 /* set pll_saidivr with found value */
529 clrsetbits_le32(®s->dckcfgr,
530 RCC_DCKCFGR_PLLSAIDIVR_MASK,
531 pllsaidivr_table[i]);
536 * As no pllsaidivr value is suitable to obtain requested freq,
537 * test all combination of pllsaidivr * pllsair and find the one
538 * which give freq closest to requested rate.
541 pllsai_vco_rate = stm32_clk_get_pllsai_vco_rate(priv);
542 best_diff = ULONG_MAX;
546 * start at index 2 of plldivr_table as divider value at index 0
549 for (i = 2; i < sizeof(plldivr_table); i++) {
550 for (j = 0; j < sizeof(pllsaidivr_table); j++) {
551 div = plldivr_table[i] * pllsaidivr_table[j];
552 current_rate = pllsai_vco_rate / div;
553 /* perfect combination is found ? */
554 if (current_rate == rate) {
561 diff = (current_rate > rate) ?
562 current_rate - rate : rate - current_rate;
564 /* found a better combination ? */
565 if (diff < best_diff) {
576 /* Disable the SAI PLL */
577 clrbits_le32(®s->cr, RCC_CR_PLLSAION);
579 /* set pll_saidivr with found value */
580 clrsetbits_le32(®s->dckcfgr, RCC_DCKCFGR_PLLSAIDIVR_MASK,
581 best_pllsaidivr << RCC_DCKCFGR_PLLSAIDIVR_SHIFT);
583 /* set pllsair with found value */
584 clrsetbits_le32(®s->pllsaicfgr, RCC_PLLSAICFGR_PLLSAIR_MASK,
585 plldivr_table[best_plldivr]
586 << RCC_PLLSAICFGR_PLLSAIR_SHIFT);
588 /* Enable the SAI PLL */
589 setbits_le32(®s->cr, RCC_CR_PLLSAION);
590 while (!(readl(®s->cr) & RCC_CR_PLLSAIRDY))
593 div = plldivr_table[best_plldivr] * pllsaidivr_table[best_pllsaidivr];
594 return pllsai_vco_rate / div;
600 static int stm32_clk_enable(struct clk *clk)
602 struct stm32_clk *priv = dev_get_priv(clk->dev);
603 struct stm32_rcc_regs *regs = priv->base;
604 u32 offset = clk->id / 32;
605 u32 bit_index = clk->id % 32;
607 debug("%s: clkid = %ld, offset from AHB1ENR is %d, bit_index = %d\n",
608 __func__, clk->id, offset, bit_index);
609 setbits_le32(®s->ahb1enr + offset, BIT(bit_index));
614 static int stm32_clk_probe(struct udevice *dev)
616 struct ofnode_phandle_args args;
617 struct udevice *fixed_clock_dev = NULL;
621 debug("%s\n", __func__);
623 struct stm32_clk *priv = dev_get_priv(dev);
626 addr = dev_read_addr(dev);
627 if (addr == FDT_ADDR_T_NONE)
630 priv->base = (struct stm32_rcc_regs *)addr;
631 priv->pllsaip = true;
633 switch (dev_get_driver_data(dev)) {
635 priv->pllsaip = false;
636 /* fallback into STM32F469 case */
638 memcpy(&priv->info, &stm32f4_clk_info,
639 sizeof(struct stm32_clk_info));
643 memcpy(&priv->info, &stm32f7_clk_info,
644 sizeof(struct stm32_clk_info));
650 /* retrieve HSE frequency (external oscillator) */
651 err = uclass_get_device_by_name(UCLASS_CLK, "clk-hse",
655 pr_err("Can't find fixed clock (%d)", err);
659 err = clk_request(fixed_clock_dev, &clk);
661 pr_err("Can't request %s clk (%d)", fixed_clock_dev->name,
667 * set pllm factor accordingly to the external oscillator
668 * frequency (HSE). For STM32F4 and STM32F7, we want VCO
670 * if input PLL frequency is 25Mhz, divide it by 25
673 priv->hse_rate = clk_get_rate(&clk);
675 if (priv->hse_rate < 1000000) {
676 pr_err("%s: unexpected HSE clock rate = %ld \"n", __func__,
681 priv->info.sys_pll_psc.pll_m = priv->hse_rate / 1000000;
683 if (priv->info.has_overdrive) {
684 err = dev_read_phandle_with_args(dev, "st,syscfg", NULL, 0, 0,
687 debug("%s: can't find syscon device (%d)\n", __func__,
692 priv->pwr_regs = (struct stm32_pwr_regs *)ofnode_get_addr(args.node);
695 configure_clocks(dev);
700 static int stm32_clk_of_xlate(struct clk *clk, struct ofnode_phandle_args *args)
702 debug("%s(clk=%p)\n", __func__, clk);
704 if (args->args_count != 2) {
705 debug("Invaild args_count: %d\n", args->args_count);
709 if (args->args_count)
710 clk->id = args->args[1];
717 static struct clk_ops stm32_clk_ops = {
718 .of_xlate = stm32_clk_of_xlate,
719 .enable = stm32_clk_enable,
720 .get_rate = stm32_clk_get_rate,
721 .set_rate = stm32_set_rate,
724 U_BOOT_DRIVER(stm32fx_clk) = {
725 .name = "stm32fx_rcc_clock",
727 .ops = &stm32_clk_ops,
728 .probe = stm32_clk_probe,
729 .priv_auto_alloc_size = sizeof(struct stm32_clk),
730 .flags = DM_FLAG_PRE_RELOC,