1e5e793a6SGabriel Fernandez // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause) 2e5e793a6SGabriel Fernandez /* 3e5e793a6SGabriel Fernandez * Copyright (C) STMicroelectronics 2022 - All Rights Reserved 4e5e793a6SGabriel Fernandez */ 5e5e793a6SGabriel Fernandez 6e5e793a6SGabriel Fernandez #include <assert.h> 7e5e793a6SGabriel Fernandez #include <drivers/clk.h> 8e5e793a6SGabriel Fernandez #include <drivers/clk_dt.h> 9e5e793a6SGabriel Fernandez #include <drivers/stm32mp_dt_bindings.h> 10e5e793a6SGabriel Fernandez #include <drivers/stm32mp13_rcc.h> 11e5e793a6SGabriel Fernandez #include <io.h> 12e5e793a6SGabriel Fernandez #include <kernel/boot.h> 13e5e793a6SGabriel Fernandez #include <libfdt.h> 14e5e793a6SGabriel Fernandez #include <stdio.h> 15e5e793a6SGabriel Fernandez 16e5e793a6SGabriel Fernandez #include "clk-stm32-core.h" 17e5e793a6SGabriel Fernandez 18e5e793a6SGabriel Fernandez #define MAX_HSI_HZ 64000000 19e5e793a6SGabriel Fernandez #define USB_PHY_48_MHZ 48000000 20e5e793a6SGabriel Fernandez 21e5e793a6SGabriel Fernandez #define TIMEOUT_US_200MS U(200000) 22e5e793a6SGabriel Fernandez #define HSIDIV_TIMEOUT TIMEOUT_US_200MS 23e5e793a6SGabriel Fernandez 24e5e793a6SGabriel Fernandez #define MAX_OPP CFG_STM32MP_OPP_COUNT 25e5e793a6SGabriel Fernandez 26e5e793a6SGabriel Fernandez #define RCC_PLL_NAME_SIZE 12 27e5e793a6SGabriel Fernandez 28e5e793a6SGabriel Fernandez struct stm32_osci_dt_cfg { 29e5e793a6SGabriel Fernandez unsigned long freq; 30e5e793a6SGabriel Fernandez bool bypass; 31e5e793a6SGabriel Fernandez bool digbyp; 32e5e793a6SGabriel Fernandez bool css; 33e5e793a6SGabriel Fernandez uint32_t drive; 34e5e793a6SGabriel Fernandez }; 35e5e793a6SGabriel Fernandez 36e5e793a6SGabriel Fernandez enum pll_mn { 37e5e793a6SGabriel Fernandez PLL_CFG_M, 38e5e793a6SGabriel Fernandez PLL_CFG_N, 39e5e793a6SGabriel Fernandez PLL_DIV_MN_NB 40e5e793a6SGabriel Fernandez }; 41e5e793a6SGabriel Fernandez 42e5e793a6SGabriel Fernandez enum pll_pqr { 43e5e793a6SGabriel Fernandez PLL_CFG_P, 44e5e793a6SGabriel Fernandez PLL_CFG_Q, 45e5e793a6SGabriel Fernandez PLL_CFG_R, 46e5e793a6SGabriel Fernandez PLL_DIV_PQR_NB 47e5e793a6SGabriel Fernandez }; 48e5e793a6SGabriel Fernandez 49e5e793a6SGabriel Fernandez enum pll_csg { 50e5e793a6SGabriel Fernandez PLL_CSG_MOD_PER, 51e5e793a6SGabriel Fernandez PLL_CSG_INC_STEP, 52e5e793a6SGabriel Fernandez PLL_CSG_SSCG_MODE, 53e5e793a6SGabriel Fernandez PLL_CSG_NB 54e5e793a6SGabriel Fernandez }; 55e5e793a6SGabriel Fernandez 56e5e793a6SGabriel Fernandez struct stm32_pll_vco { 57e5e793a6SGabriel Fernandez uint32_t status; 58e5e793a6SGabriel Fernandez uint32_t src; 59e5e793a6SGabriel Fernandez uint32_t div_mn[PLL_DIV_MN_NB]; 60e5e793a6SGabriel Fernandez uint32_t frac; 61e5e793a6SGabriel Fernandez bool csg_enabled; 62e5e793a6SGabriel Fernandez uint32_t csg[PLL_CSG_NB]; 63e5e793a6SGabriel Fernandez }; 64e5e793a6SGabriel Fernandez 65e5e793a6SGabriel Fernandez struct stm32_pll_output { 66e5e793a6SGabriel Fernandez uint32_t output[PLL_DIV_PQR_NB]; 67e5e793a6SGabriel Fernandez }; 68e5e793a6SGabriel Fernandez 69e5e793a6SGabriel Fernandez struct stm32_pll_dt_cfg { 70e5e793a6SGabriel Fernandez struct stm32_pll_vco vco; 71e5e793a6SGabriel Fernandez struct stm32_pll_output output; 72e5e793a6SGabriel Fernandez }; 73e5e793a6SGabriel Fernandez 74e5e793a6SGabriel Fernandez struct stm32_clk_opp_cfg { 75e5e793a6SGabriel Fernandez uint32_t frq; 76e5e793a6SGabriel Fernandez uint32_t src; 77e5e793a6SGabriel Fernandez uint32_t div; 78e5e793a6SGabriel Fernandez struct stm32_pll_dt_cfg pll_cfg; 79e5e793a6SGabriel Fernandez }; 80e5e793a6SGabriel Fernandez 81e5e793a6SGabriel Fernandez struct stm32_clk_opp_dt_cfg { 82e5e793a6SGabriel Fernandez struct stm32_clk_opp_cfg mpu_opp[MAX_OPP]; 83e5e793a6SGabriel Fernandez struct stm32_clk_opp_cfg axi_opp[MAX_OPP]; 84e5e793a6SGabriel Fernandez struct stm32_clk_opp_cfg mlahbs_opp[MAX_OPP]; 85e5e793a6SGabriel Fernandez }; 86e5e793a6SGabriel Fernandez 87e5e793a6SGabriel Fernandez struct stm32_clk_platdata { 88e5e793a6SGabriel Fernandez uintptr_t rcc_base; 89e5e793a6SGabriel Fernandez uint32_t nosci; 90e5e793a6SGabriel Fernandez struct stm32_osci_dt_cfg *osci; 91e5e793a6SGabriel Fernandez uint32_t npll; 92e5e793a6SGabriel Fernandez struct stm32_pll_dt_cfg *pll; 93e5e793a6SGabriel Fernandez struct stm32_clk_opp_dt_cfg *opp; 94e5e793a6SGabriel Fernandez uint32_t nclksrc; 95e5e793a6SGabriel Fernandez uint32_t *clksrc; 96e5e793a6SGabriel Fernandez uint32_t nclkdiv; 97e5e793a6SGabriel Fernandez uint32_t *clkdiv; 98e5e793a6SGabriel Fernandez }; 99e5e793a6SGabriel Fernandez 100e5e793a6SGabriel Fernandez /* 101e5e793a6SGabriel Fernandez * GATE CONFIG 102e5e793a6SGabriel Fernandez */ 103e5e793a6SGabriel Fernandez 104e5e793a6SGabriel Fernandez /* Warning GATE_XXX_RDY must follow GATE_XXX */ 105e5e793a6SGabriel Fernandez enum enum_gate_cfg { 106e5e793a6SGabriel Fernandez GATE_LSE, 107e5e793a6SGabriel Fernandez GATE_LSE_RDY, 108e5e793a6SGabriel Fernandez GATE_LSI, 109e5e793a6SGabriel Fernandez GATE_LSI_RDY, 110e5e793a6SGabriel Fernandez GATE_HSI, 111e5e793a6SGabriel Fernandez GATE_HSI_RDY, 112e5e793a6SGabriel Fernandez GATE_CSI, 113e5e793a6SGabriel Fernandez GATE_CSI_RDY, 114e5e793a6SGabriel Fernandez GATE_HSE, 115e5e793a6SGabriel Fernandez GATE_HSE_RDY, 116e5e793a6SGabriel Fernandez GATE_PLL1, 117e5e793a6SGabriel Fernandez GATE_PLL1_RDY, 118e5e793a6SGabriel Fernandez GATE_PLL2, 119e5e793a6SGabriel Fernandez GATE_PLL2_RDY, 120e5e793a6SGabriel Fernandez GATE_PLL3, 121e5e793a6SGabriel Fernandez GATE_PLL3_RDY, 122e5e793a6SGabriel Fernandez GATE_PLL4, 123e5e793a6SGabriel Fernandez GATE_PLL4_RDY, 124e5e793a6SGabriel Fernandez GATE_HSIDIVRDY, 125e5e793a6SGabriel Fernandez GATE_MPUSRCRDY, 126e5e793a6SGabriel Fernandez GATE_AXISSRCRDY, 127e5e793a6SGabriel Fernandez GATE_MCUSSRCRDY, 128e5e793a6SGabriel Fernandez GATE_PLL12SRCRDY, 129e5e793a6SGabriel Fernandez GATE_PLL3SRCRDY, 130e5e793a6SGabriel Fernandez GATE_PLL4SRCRDY, 131e5e793a6SGabriel Fernandez GATE_MPUDIVRDY, 132e5e793a6SGabriel Fernandez GATE_AXIDIVRDY, 133e5e793a6SGabriel Fernandez GATE_MLAHBDIVRDY, 134e5e793a6SGabriel Fernandez GATE_APB1DIVRDY, 135e5e793a6SGabriel Fernandez GATE_APB2DIVRDY, 136e5e793a6SGabriel Fernandez GATE_APB3DIVRDY, 137e5e793a6SGabriel Fernandez GATE_APB4DIVRDY, 138e5e793a6SGabriel Fernandez GATE_APB5DIVRDY, 139e5e793a6SGabriel Fernandez GATE_APB6DIVRDY, 140e5e793a6SGabriel Fernandez GATE_RTCCK, 141e5e793a6SGabriel Fernandez GATE_MCO1, 142e5e793a6SGabriel Fernandez GATE_MCO2, 143e5e793a6SGabriel Fernandez GATE_DBGCK, 144e5e793a6SGabriel Fernandez GATE_TRACECK, 145e5e793a6SGabriel Fernandez GATE_PLL1_DIVP, 146e5e793a6SGabriel Fernandez GATE_PLL1_DIVQ, 147e5e793a6SGabriel Fernandez GATE_PLL1_DIVR, 148e5e793a6SGabriel Fernandez GATE_PLL2_DIVP, 149e5e793a6SGabriel Fernandez GATE_PLL2_DIVQ, 150e5e793a6SGabriel Fernandez GATE_PLL2_DIVR, 151e5e793a6SGabriel Fernandez GATE_PLL3_DIVP, 152e5e793a6SGabriel Fernandez GATE_PLL3_DIVQ, 153e5e793a6SGabriel Fernandez GATE_PLL3_DIVR, 154e5e793a6SGabriel Fernandez GATE_PLL4_DIVP, 155e5e793a6SGabriel Fernandez GATE_PLL4_DIVQ, 156e5e793a6SGabriel Fernandez GATE_PLL4_DIVR, 157e5e793a6SGabriel Fernandez GATE_DDRC1, 158e5e793a6SGabriel Fernandez GATE_DDRC1LP, 159e5e793a6SGabriel Fernandez GATE_DDRPHYC, 160e5e793a6SGabriel Fernandez GATE_DDRPHYCLP, 161e5e793a6SGabriel Fernandez GATE_DDRCAPB, 162e5e793a6SGabriel Fernandez GATE_DDRCAPBLP, 163e5e793a6SGabriel Fernandez GATE_AXIDCG, 164e5e793a6SGabriel Fernandez GATE_DDRPHYCAPB, 165e5e793a6SGabriel Fernandez GATE_DDRPHYCAPBLP, 166e5e793a6SGabriel Fernandez GATE_TIM2, 167e5e793a6SGabriel Fernandez GATE_TIM3, 168e5e793a6SGabriel Fernandez GATE_TIM4, 169e5e793a6SGabriel Fernandez GATE_TIM5, 170e5e793a6SGabriel Fernandez GATE_TIM6, 171e5e793a6SGabriel Fernandez GATE_TIM7, 172e5e793a6SGabriel Fernandez GATE_LPTIM1, 173e5e793a6SGabriel Fernandez GATE_SPI2, 174e5e793a6SGabriel Fernandez GATE_SPI3, 175e5e793a6SGabriel Fernandez GATE_USART3, 176e5e793a6SGabriel Fernandez GATE_UART4, 177e5e793a6SGabriel Fernandez GATE_UART5, 178e5e793a6SGabriel Fernandez GATE_UART7, 179e5e793a6SGabriel Fernandez GATE_UART8, 180e5e793a6SGabriel Fernandez GATE_I2C1, 181e5e793a6SGabriel Fernandez GATE_I2C2, 182e5e793a6SGabriel Fernandez GATE_SPDIF, 183e5e793a6SGabriel Fernandez GATE_TIM1, 184e5e793a6SGabriel Fernandez GATE_TIM8, 185e5e793a6SGabriel Fernandez GATE_SPI1, 186e5e793a6SGabriel Fernandez GATE_USART6, 187e5e793a6SGabriel Fernandez GATE_SAI1, 188e5e793a6SGabriel Fernandez GATE_SAI2, 189e5e793a6SGabriel Fernandez GATE_DFSDM, 190e5e793a6SGabriel Fernandez GATE_ADFSDM, 191e5e793a6SGabriel Fernandez GATE_FDCAN, 192e5e793a6SGabriel Fernandez GATE_LPTIM2, 193e5e793a6SGabriel Fernandez GATE_LPTIM3, 194e5e793a6SGabriel Fernandez GATE_LPTIM4, 195e5e793a6SGabriel Fernandez GATE_LPTIM5, 196e5e793a6SGabriel Fernandez GATE_VREF, 197e5e793a6SGabriel Fernandez GATE_DTS, 198e5e793a6SGabriel Fernandez GATE_PMBCTRL, 199e5e793a6SGabriel Fernandez GATE_HDP, 200e5e793a6SGabriel Fernandez GATE_SYSCFG, 201e5e793a6SGabriel Fernandez GATE_DCMIPP, 202e5e793a6SGabriel Fernandez GATE_DDRPERFM, 203e5e793a6SGabriel Fernandez GATE_IWDG2APB, 204e5e793a6SGabriel Fernandez GATE_USBPHY, 205e5e793a6SGabriel Fernandez GATE_STGENRO, 206e5e793a6SGabriel Fernandez GATE_LTDC, 207e5e793a6SGabriel Fernandez GATE_RTCAPB, 208e5e793a6SGabriel Fernandez GATE_TZC, 209e5e793a6SGabriel Fernandez GATE_ETZPC, 210e5e793a6SGabriel Fernandez GATE_IWDG1APB, 211e5e793a6SGabriel Fernandez GATE_BSEC, 212e5e793a6SGabriel Fernandez GATE_STGENC, 213e5e793a6SGabriel Fernandez GATE_USART1, 214e5e793a6SGabriel Fernandez GATE_USART2, 215e5e793a6SGabriel Fernandez GATE_SPI4, 216e5e793a6SGabriel Fernandez GATE_SPI5, 217e5e793a6SGabriel Fernandez GATE_I2C3, 218e5e793a6SGabriel Fernandez GATE_I2C4, 219e5e793a6SGabriel Fernandez GATE_I2C5, 220e5e793a6SGabriel Fernandez GATE_TIM12, 221e5e793a6SGabriel Fernandez GATE_TIM13, 222e5e793a6SGabriel Fernandez GATE_TIM14, 223e5e793a6SGabriel Fernandez GATE_TIM15, 224e5e793a6SGabriel Fernandez GATE_TIM16, 225e5e793a6SGabriel Fernandez GATE_TIM17, 226e5e793a6SGabriel Fernandez GATE_DMA1, 227e5e793a6SGabriel Fernandez GATE_DMA2, 228e5e793a6SGabriel Fernandez GATE_DMAMUX1, 229e5e793a6SGabriel Fernandez GATE_DMA3, 230e5e793a6SGabriel Fernandez GATE_DMAMUX2, 231e5e793a6SGabriel Fernandez GATE_ADC1, 232e5e793a6SGabriel Fernandez GATE_ADC2, 233e5e793a6SGabriel Fernandez GATE_USBO, 234e5e793a6SGabriel Fernandez GATE_TSC, 235e5e793a6SGabriel Fernandez GATE_GPIOA, 236e5e793a6SGabriel Fernandez GATE_GPIOB, 237e5e793a6SGabriel Fernandez GATE_GPIOC, 238e5e793a6SGabriel Fernandez GATE_GPIOD, 239e5e793a6SGabriel Fernandez GATE_GPIOE, 240e5e793a6SGabriel Fernandez GATE_GPIOF, 241e5e793a6SGabriel Fernandez GATE_GPIOG, 242e5e793a6SGabriel Fernandez GATE_GPIOH, 243e5e793a6SGabriel Fernandez GATE_GPIOI, 244e5e793a6SGabriel Fernandez GATE_PKA, 245e5e793a6SGabriel Fernandez GATE_SAES, 246e5e793a6SGabriel Fernandez GATE_CRYP1, 247e5e793a6SGabriel Fernandez GATE_HASH1, 248e5e793a6SGabriel Fernandez GATE_RNG1, 249e5e793a6SGabriel Fernandez GATE_BKPSRAM, 250e5e793a6SGabriel Fernandez GATE_AXIMC, 251e5e793a6SGabriel Fernandez GATE_MCE, 252e5e793a6SGabriel Fernandez GATE_ETH1CK, 253e5e793a6SGabriel Fernandez GATE_ETH1TX, 254e5e793a6SGabriel Fernandez GATE_ETH1RX, 255e5e793a6SGabriel Fernandez GATE_ETH1MAC, 256e5e793a6SGabriel Fernandez GATE_FMC, 257e5e793a6SGabriel Fernandez GATE_QSPI, 258e5e793a6SGabriel Fernandez GATE_SDMMC1, 259e5e793a6SGabriel Fernandez GATE_SDMMC2, 260e5e793a6SGabriel Fernandez GATE_CRC1, 261e5e793a6SGabriel Fernandez GATE_USBH, 262e5e793a6SGabriel Fernandez GATE_ETH2CK, 263e5e793a6SGabriel Fernandez GATE_ETH2TX, 264e5e793a6SGabriel Fernandez GATE_ETH2RX, 265e5e793a6SGabriel Fernandez GATE_ETH2MAC, 266e5e793a6SGabriel Fernandez GATE_MDMA, 267e5e793a6SGabriel Fernandez GATE_NB 268e5e793a6SGabriel Fernandez }; 269e5e793a6SGabriel Fernandez 270e5e793a6SGabriel Fernandez #define GATE_CFG(_id, _offset, _bit_idx, _offset_clr)\ 271e5e793a6SGabriel Fernandez [(_id)] = {\ 272e5e793a6SGabriel Fernandez .offset = (_offset),\ 273e5e793a6SGabriel Fernandez .bit_idx = (_bit_idx),\ 274e5e793a6SGabriel Fernandez .set_clr = (_offset_clr),\ 275e5e793a6SGabriel Fernandez } 276e5e793a6SGabriel Fernandez 277e5e793a6SGabriel Fernandez static const struct gate_cfg gates_mp13[GATE_NB] = { 278e5e793a6SGabriel Fernandez GATE_CFG(GATE_LSE, RCC_BDCR, 0, 0), 279e5e793a6SGabriel Fernandez GATE_CFG(GATE_LSE_RDY, RCC_BDCR, 2, 0), 280e5e793a6SGabriel Fernandez GATE_CFG(GATE_RTCCK, RCC_BDCR, 20, 0), 281e5e793a6SGabriel Fernandez GATE_CFG(GATE_LSI, RCC_RDLSICR, 0, 0), 282e5e793a6SGabriel Fernandez GATE_CFG(GATE_LSI_RDY, RCC_RDLSICR, 1, 0), 283e5e793a6SGabriel Fernandez GATE_CFG(GATE_HSI, RCC_OCENSETR, 0, 1), 284e5e793a6SGabriel Fernandez GATE_CFG(GATE_HSI_RDY, RCC_OCRDYR, 0, 0), 285e5e793a6SGabriel Fernandez GATE_CFG(GATE_CSI, RCC_OCENSETR, 4, 1), 286e5e793a6SGabriel Fernandez GATE_CFG(GATE_CSI_RDY, RCC_OCRDYR, 4, 0), 287e5e793a6SGabriel Fernandez GATE_CFG(GATE_HSE, RCC_OCENSETR, 8, 1), 288e5e793a6SGabriel Fernandez GATE_CFG(GATE_HSE_RDY, RCC_OCRDYR, 8, 0), 289e5e793a6SGabriel Fernandez GATE_CFG(GATE_HSIDIVRDY, RCC_OCRDYR, 2, 0), 290e5e793a6SGabriel Fernandez GATE_CFG(GATE_MPUSRCRDY, RCC_MPCKSELR, 31, 0), 291e5e793a6SGabriel Fernandez GATE_CFG(GATE_AXISSRCRDY, RCC_ASSCKSELR, 31, 0), 292e5e793a6SGabriel Fernandez GATE_CFG(GATE_MCUSSRCRDY, RCC_MSSCKSELR, 31, 0), 293e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL12SRCRDY, RCC_RCK12SELR, 31, 0), 294e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL3SRCRDY, RCC_RCK3SELR, 31, 0), 295e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL4SRCRDY, RCC_RCK4SELR, 31, 0), 296e5e793a6SGabriel Fernandez GATE_CFG(GATE_MPUDIVRDY, RCC_MPCKDIVR, 31, 0), 297e5e793a6SGabriel Fernandez GATE_CFG(GATE_AXIDIVRDY, RCC_AXIDIVR, 31, 0), 298e5e793a6SGabriel Fernandez GATE_CFG(GATE_MLAHBDIVRDY, RCC_MLAHBDIVR, 31, 0), 299e5e793a6SGabriel Fernandez GATE_CFG(GATE_APB1DIVRDY, RCC_APB1DIVR, 31, 0), 300e5e793a6SGabriel Fernandez GATE_CFG(GATE_APB2DIVRDY, RCC_APB2DIVR, 31, 0), 301e5e793a6SGabriel Fernandez GATE_CFG(GATE_APB3DIVRDY, RCC_APB3DIVR, 31, 0), 302e5e793a6SGabriel Fernandez GATE_CFG(GATE_APB4DIVRDY, RCC_APB4DIVR, 31, 0), 303e5e793a6SGabriel Fernandez GATE_CFG(GATE_APB5DIVRDY, RCC_APB5DIVR, 31, 0), 304e5e793a6SGabriel Fernandez GATE_CFG(GATE_APB6DIVRDY, RCC_APB6DIVR, 31, 0), 305e5e793a6SGabriel Fernandez GATE_CFG(GATE_MCO1, RCC_MCO1CFGR, 12, 0), 306e5e793a6SGabriel Fernandez GATE_CFG(GATE_MCO2, RCC_MCO2CFGR, 12, 0), 307e5e793a6SGabriel Fernandez GATE_CFG(GATE_DBGCK, RCC_DBGCFGR, 8, 0), 308e5e793a6SGabriel Fernandez GATE_CFG(GATE_TRACECK, RCC_DBGCFGR, 9, 0), 309e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL1, RCC_PLL1CR, 0, 0), 310e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL1_RDY, RCC_PLL1CR, 1, 0), 311e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL1_DIVP, RCC_PLL1CR, 4, 0), 312e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL1_DIVQ, RCC_PLL1CR, 5, 0), 313e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL1_DIVR, RCC_PLL1CR, 6, 0), 314e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL2, RCC_PLL2CR, 0, 0), 315e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL2_RDY, RCC_PLL2CR, 1, 0), 316e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL2_DIVP, RCC_PLL2CR, 4, 0), 317e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL2_DIVQ, RCC_PLL2CR, 5, 0), 318e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL2_DIVR, RCC_PLL2CR, 6, 0), 319e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL3, RCC_PLL3CR, 0, 0), 320e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL3_RDY, RCC_PLL3CR, 1, 0), 321e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL3_DIVP, RCC_PLL3CR, 4, 0), 322e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL3_DIVQ, RCC_PLL3CR, 5, 0), 323e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL3_DIVR, RCC_PLL3CR, 6, 0), 324e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL4, RCC_PLL4CR, 0, 0), 325e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL4_RDY, RCC_PLL4CR, 1, 0), 326e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL4_DIVP, RCC_PLL4CR, 4, 0), 327e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL4_DIVQ, RCC_PLL4CR, 5, 0), 328e5e793a6SGabriel Fernandez GATE_CFG(GATE_PLL4_DIVR, RCC_PLL4CR, 6, 0), 329e5e793a6SGabriel Fernandez GATE_CFG(GATE_DDRC1, RCC_DDRITFCR, 0, 0), 330e5e793a6SGabriel Fernandez GATE_CFG(GATE_DDRC1LP, RCC_DDRITFCR, 1, 0), 331e5e793a6SGabriel Fernandez GATE_CFG(GATE_DDRPHYC, RCC_DDRITFCR, 4, 0), 332e5e793a6SGabriel Fernandez GATE_CFG(GATE_DDRPHYCLP, RCC_DDRITFCR, 5, 0), 333e5e793a6SGabriel Fernandez GATE_CFG(GATE_DDRCAPB, RCC_DDRITFCR, 6, 0), 334e5e793a6SGabriel Fernandez GATE_CFG(GATE_DDRCAPBLP, RCC_DDRITFCR, 7, 0), 335e5e793a6SGabriel Fernandez GATE_CFG(GATE_AXIDCG, RCC_DDRITFCR, 8, 0), 336e5e793a6SGabriel Fernandez GATE_CFG(GATE_DDRPHYCAPB, RCC_DDRITFCR, 9, 0), 337e5e793a6SGabriel Fernandez GATE_CFG(GATE_DDRPHYCAPBLP, RCC_DDRITFCR, 10, 0), 338e5e793a6SGabriel Fernandez GATE_CFG(GATE_TIM2, RCC_MP_APB1ENSETR, 0, 1), 339e5e793a6SGabriel Fernandez GATE_CFG(GATE_TIM3, RCC_MP_APB1ENSETR, 1, 1), 340e5e793a6SGabriel Fernandez GATE_CFG(GATE_TIM4, RCC_MP_APB1ENSETR, 2, 1), 341e5e793a6SGabriel Fernandez GATE_CFG(GATE_TIM5, RCC_MP_APB1ENSETR, 3, 1), 342e5e793a6SGabriel Fernandez GATE_CFG(GATE_TIM6, RCC_MP_APB1ENSETR, 4, 1), 343e5e793a6SGabriel Fernandez GATE_CFG(GATE_TIM7, RCC_MP_APB1ENSETR, 5, 1), 344e5e793a6SGabriel Fernandez GATE_CFG(GATE_LPTIM1, RCC_MP_APB1ENSETR, 9, 1), 345e5e793a6SGabriel Fernandez GATE_CFG(GATE_SPI2, RCC_MP_APB1ENSETR, 11, 1), 346e5e793a6SGabriel Fernandez GATE_CFG(GATE_SPI3, RCC_MP_APB1ENSETR, 12, 1), 347e5e793a6SGabriel Fernandez GATE_CFG(GATE_USART3, RCC_MP_APB1ENSETR, 15, 1), 348e5e793a6SGabriel Fernandez GATE_CFG(GATE_UART4, RCC_MP_APB1ENSETR, 16, 1), 349e5e793a6SGabriel Fernandez GATE_CFG(GATE_UART5, RCC_MP_APB1ENSETR, 17, 1), 350e5e793a6SGabriel Fernandez GATE_CFG(GATE_UART7, RCC_MP_APB1ENSETR, 18, 1), 351e5e793a6SGabriel Fernandez GATE_CFG(GATE_UART8, RCC_MP_APB1ENSETR, 19, 1), 352e5e793a6SGabriel Fernandez GATE_CFG(GATE_I2C1, RCC_MP_APB1ENSETR, 21, 1), 353e5e793a6SGabriel Fernandez GATE_CFG(GATE_I2C2, RCC_MP_APB1ENSETR, 22, 1), 354e5e793a6SGabriel Fernandez GATE_CFG(GATE_SPDIF, RCC_MP_APB1ENSETR, 26, 1), 355e5e793a6SGabriel Fernandez GATE_CFG(GATE_TIM1, RCC_MP_APB2ENSETR, 0, 1), 356e5e793a6SGabriel Fernandez GATE_CFG(GATE_TIM8, RCC_MP_APB2ENSETR, 1, 1), 357e5e793a6SGabriel Fernandez GATE_CFG(GATE_SPI1, RCC_MP_APB2ENSETR, 8, 1), 358e5e793a6SGabriel Fernandez GATE_CFG(GATE_USART6, RCC_MP_APB2ENSETR, 13, 1), 359e5e793a6SGabriel Fernandez GATE_CFG(GATE_SAI1, RCC_MP_APB2ENSETR, 16, 1), 360e5e793a6SGabriel Fernandez GATE_CFG(GATE_SAI2, RCC_MP_APB2ENSETR, 17, 1), 361e5e793a6SGabriel Fernandez GATE_CFG(GATE_DFSDM, RCC_MP_APB2ENSETR, 20, 1), 362e5e793a6SGabriel Fernandez GATE_CFG(GATE_ADFSDM, RCC_MP_APB2ENSETR, 21, 1), 363e5e793a6SGabriel Fernandez GATE_CFG(GATE_FDCAN, RCC_MP_APB2ENSETR, 24, 1), 364e5e793a6SGabriel Fernandez GATE_CFG(GATE_LPTIM2, RCC_MP_APB3ENSETR, 0, 1), 365e5e793a6SGabriel Fernandez GATE_CFG(GATE_LPTIM3, RCC_MP_APB3ENSETR, 1, 1), 366e5e793a6SGabriel Fernandez GATE_CFG(GATE_LPTIM4, RCC_MP_APB3ENSETR, 2, 1), 367e5e793a6SGabriel Fernandez GATE_CFG(GATE_LPTIM5, RCC_MP_APB3ENSETR, 3, 1), 368e5e793a6SGabriel Fernandez GATE_CFG(GATE_VREF, RCC_MP_APB3ENSETR, 13, 1), 369e5e793a6SGabriel Fernandez GATE_CFG(GATE_DTS, RCC_MP_APB3ENSETR, 16, 1), 370e5e793a6SGabriel Fernandez GATE_CFG(GATE_PMBCTRL, RCC_MP_APB3ENSETR, 17, 1), 371e5e793a6SGabriel Fernandez GATE_CFG(GATE_HDP, RCC_MP_APB3ENSETR, 20, 1), 372e5e793a6SGabriel Fernandez GATE_CFG(GATE_SYSCFG, RCC_MP_S_APB3ENSETR, 0, 1), 373e5e793a6SGabriel Fernandez GATE_CFG(GATE_DCMIPP, RCC_MP_APB4ENSETR, 1, 1), 374e5e793a6SGabriel Fernandez GATE_CFG(GATE_DDRPERFM, RCC_MP_APB4ENSETR, 8, 1), 375e5e793a6SGabriel Fernandez GATE_CFG(GATE_IWDG2APB, RCC_MP_APB4ENSETR, 15, 1), 376e5e793a6SGabriel Fernandez GATE_CFG(GATE_USBPHY, RCC_MP_APB4ENSETR, 16, 1), 377e5e793a6SGabriel Fernandez GATE_CFG(GATE_STGENRO, RCC_MP_APB4ENSETR, 20, 1), 378e5e793a6SGabriel Fernandez GATE_CFG(GATE_LTDC, RCC_MP_S_APB4ENSETR, 0, 1), 379e5e793a6SGabriel Fernandez GATE_CFG(GATE_RTCAPB, RCC_MP_APB5ENSETR, 8, 1), 380e5e793a6SGabriel Fernandez GATE_CFG(GATE_TZC, RCC_MP_APB5ENSETR, 11, 1), 381e5e793a6SGabriel Fernandez GATE_CFG(GATE_ETZPC, RCC_MP_APB5ENSETR, 13, 1), 382e5e793a6SGabriel Fernandez GATE_CFG(GATE_IWDG1APB, RCC_MP_APB5ENSETR, 15, 1), 383e5e793a6SGabriel Fernandez GATE_CFG(GATE_BSEC, RCC_MP_APB5ENSETR, 16, 1), 384e5e793a6SGabriel Fernandez GATE_CFG(GATE_STGENC, RCC_MP_APB5ENSETR, 20, 1), 385e5e793a6SGabriel Fernandez GATE_CFG(GATE_USART1, RCC_MP_APB6ENSETR, 0, 1), 386e5e793a6SGabriel Fernandez GATE_CFG(GATE_USART2, RCC_MP_APB6ENSETR, 1, 1), 387e5e793a6SGabriel Fernandez GATE_CFG(GATE_SPI4, RCC_MP_APB6ENSETR, 2, 1), 388e5e793a6SGabriel Fernandez GATE_CFG(GATE_SPI5, RCC_MP_APB6ENSETR, 3, 1), 389e5e793a6SGabriel Fernandez GATE_CFG(GATE_I2C3, RCC_MP_APB6ENSETR, 4, 1), 390e5e793a6SGabriel Fernandez GATE_CFG(GATE_I2C4, RCC_MP_APB6ENSETR, 5, 1), 391e5e793a6SGabriel Fernandez GATE_CFG(GATE_I2C5, RCC_MP_APB6ENSETR, 6, 1), 392e5e793a6SGabriel Fernandez GATE_CFG(GATE_TIM12, RCC_MP_APB6ENSETR, 7, 1), 393e5e793a6SGabriel Fernandez GATE_CFG(GATE_TIM13, RCC_MP_APB6ENSETR, 8, 1), 394e5e793a6SGabriel Fernandez GATE_CFG(GATE_TIM14, RCC_MP_APB6ENSETR, 9, 1), 395e5e793a6SGabriel Fernandez GATE_CFG(GATE_TIM15, RCC_MP_APB6ENSETR, 10, 1), 396e5e793a6SGabriel Fernandez GATE_CFG(GATE_TIM16, RCC_MP_APB6ENSETR, 11, 1), 397e5e793a6SGabriel Fernandez GATE_CFG(GATE_TIM17, RCC_MP_APB6ENSETR, 12, 1), 398e5e793a6SGabriel Fernandez GATE_CFG(GATE_DMA1, RCC_MP_AHB2ENSETR, 0, 1), 399e5e793a6SGabriel Fernandez GATE_CFG(GATE_DMA2, RCC_MP_AHB2ENSETR, 1, 1), 400e5e793a6SGabriel Fernandez GATE_CFG(GATE_DMAMUX1, RCC_MP_AHB2ENSETR, 2, 1), 401e5e793a6SGabriel Fernandez GATE_CFG(GATE_DMA3, RCC_MP_AHB2ENSETR, 3, 1), 402e5e793a6SGabriel Fernandez GATE_CFG(GATE_DMAMUX2, RCC_MP_AHB2ENSETR, 4, 1), 403e5e793a6SGabriel Fernandez GATE_CFG(GATE_ADC1, RCC_MP_AHB2ENSETR, 5, 1), 404e5e793a6SGabriel Fernandez GATE_CFG(GATE_ADC2, RCC_MP_AHB2ENSETR, 6, 1), 405e5e793a6SGabriel Fernandez GATE_CFG(GATE_USBO, RCC_MP_AHB2ENSETR, 8, 1), 406e5e793a6SGabriel Fernandez GATE_CFG(GATE_TSC, RCC_MP_AHB4ENSETR, 15, 1), 407e5e793a6SGabriel Fernandez GATE_CFG(GATE_GPIOA, RCC_MP_S_AHB4ENSETR, 0, 1), 408e5e793a6SGabriel Fernandez GATE_CFG(GATE_GPIOB, RCC_MP_S_AHB4ENSETR, 1, 1), 409e5e793a6SGabriel Fernandez GATE_CFG(GATE_GPIOC, RCC_MP_S_AHB4ENSETR, 2, 1), 410e5e793a6SGabriel Fernandez GATE_CFG(GATE_GPIOD, RCC_MP_S_AHB4ENSETR, 3, 1), 411e5e793a6SGabriel Fernandez GATE_CFG(GATE_GPIOE, RCC_MP_S_AHB4ENSETR, 4, 1), 412e5e793a6SGabriel Fernandez GATE_CFG(GATE_GPIOF, RCC_MP_S_AHB4ENSETR, 5, 1), 413e5e793a6SGabriel Fernandez GATE_CFG(GATE_GPIOG, RCC_MP_S_AHB4ENSETR, 6, 1), 414e5e793a6SGabriel Fernandez GATE_CFG(GATE_GPIOH, RCC_MP_S_AHB4ENSETR, 7, 1), 415e5e793a6SGabriel Fernandez GATE_CFG(GATE_GPIOI, RCC_MP_S_AHB4ENSETR, 8, 1), 416e5e793a6SGabriel Fernandez GATE_CFG(GATE_PKA, RCC_MP_AHB5ENSETR, 2, 1), 417e5e793a6SGabriel Fernandez GATE_CFG(GATE_SAES, RCC_MP_AHB5ENSETR, 3, 1), 418e5e793a6SGabriel Fernandez GATE_CFG(GATE_CRYP1, RCC_MP_AHB5ENSETR, 4, 1), 419e5e793a6SGabriel Fernandez GATE_CFG(GATE_HASH1, RCC_MP_AHB5ENSETR, 5, 1), 420e5e793a6SGabriel Fernandez GATE_CFG(GATE_RNG1, RCC_MP_AHB5ENSETR, 6, 1), 421e5e793a6SGabriel Fernandez GATE_CFG(GATE_BKPSRAM, RCC_MP_AHB5ENSETR, 8, 1), 422e5e793a6SGabriel Fernandez GATE_CFG(GATE_AXIMC, RCC_MP_AHB5ENSETR, 16, 1), 423e5e793a6SGabriel Fernandez GATE_CFG(GATE_MCE, RCC_MP_AHB6ENSETR, 1, 1), 424e5e793a6SGabriel Fernandez GATE_CFG(GATE_ETH1CK, RCC_MP_AHB6ENSETR, 7, 1), 425e5e793a6SGabriel Fernandez GATE_CFG(GATE_ETH1TX, RCC_MP_AHB6ENSETR, 8, 1), 426e5e793a6SGabriel Fernandez GATE_CFG(GATE_ETH1RX, RCC_MP_AHB6ENSETR, 9, 1), 427e5e793a6SGabriel Fernandez GATE_CFG(GATE_ETH1MAC, RCC_MP_AHB6ENSETR, 10, 1), 428e5e793a6SGabriel Fernandez GATE_CFG(GATE_FMC, RCC_MP_AHB6ENSETR, 12, 1), 429e5e793a6SGabriel Fernandez GATE_CFG(GATE_QSPI, RCC_MP_AHB6ENSETR, 14, 1), 430e5e793a6SGabriel Fernandez GATE_CFG(GATE_SDMMC1, RCC_MP_AHB6ENSETR, 16, 1), 431e5e793a6SGabriel Fernandez GATE_CFG(GATE_SDMMC2, RCC_MP_AHB6ENSETR, 17, 1), 432e5e793a6SGabriel Fernandez GATE_CFG(GATE_CRC1, RCC_MP_AHB6ENSETR, 20, 1), 433e5e793a6SGabriel Fernandez GATE_CFG(GATE_USBH, RCC_MP_AHB6ENSETR, 24, 1), 434e5e793a6SGabriel Fernandez GATE_CFG(GATE_ETH2CK, RCC_MP_AHB6ENSETR, 27, 1), 435e5e793a6SGabriel Fernandez GATE_CFG(GATE_ETH2TX, RCC_MP_AHB6ENSETR, 28, 1), 436e5e793a6SGabriel Fernandez GATE_CFG(GATE_ETH2RX, RCC_MP_AHB6ENSETR, 29, 1), 437e5e793a6SGabriel Fernandez GATE_CFG(GATE_ETH2MAC, RCC_MP_AHB6ENSETR, 30, 1), 438e5e793a6SGabriel Fernandez GATE_CFG(GATE_MDMA, RCC_MP_S_AHB6ENSETR, 0, 1), 439e5e793a6SGabriel Fernandez }; 440e5e793a6SGabriel Fernandez 441e5e793a6SGabriel Fernandez /* 442e5e793a6SGabriel Fernandez * MUX CONFIG 443e5e793a6SGabriel Fernandez */ 444e5e793a6SGabriel Fernandez #define MUXRDY_CFG(_id, _offset, _shift, _witdh, _rdy)\ 445e5e793a6SGabriel Fernandez [(_id)] = {\ 446e5e793a6SGabriel Fernandez .offset = (_offset),\ 447e5e793a6SGabriel Fernandez .shift = (_shift),\ 448e5e793a6SGabriel Fernandez .width = (_witdh),\ 449e5e793a6SGabriel Fernandez .ready = (_rdy),\ 450e5e793a6SGabriel Fernandez } 451e5e793a6SGabriel Fernandez 452e5e793a6SGabriel Fernandez #define MUX_CFG(_id, _offset, _shift, _witdh)\ 453e5e793a6SGabriel Fernandez MUXRDY_CFG(_id, _offset, _shift, _witdh, MUX_NO_RDY) 454e5e793a6SGabriel Fernandez 455e5e793a6SGabriel Fernandez static const struct mux_cfg parent_mp13[MUX_NB] = { 456e5e793a6SGabriel Fernandez MUXRDY_CFG(MUX_MPU, RCC_MPCKSELR, 0, 2, GATE_MPUSRCRDY), 457e5e793a6SGabriel Fernandez MUXRDY_CFG(MUX_AXI, RCC_ASSCKSELR, 0, 3, GATE_AXISSRCRDY), 458e5e793a6SGabriel Fernandez MUXRDY_CFG(MUX_MLAHB, RCC_MSSCKSELR, 0, 2, GATE_MCUSSRCRDY), 459e5e793a6SGabriel Fernandez MUXRDY_CFG(MUX_PLL12, RCC_RCK12SELR, 0, 2, GATE_PLL12SRCRDY), 460e5e793a6SGabriel Fernandez MUXRDY_CFG(MUX_PLL3, RCC_RCK3SELR, 0, 2, GATE_PLL3SRCRDY), 461e5e793a6SGabriel Fernandez MUXRDY_CFG(MUX_PLL4, RCC_RCK4SELR, 0, 2, GATE_PLL4SRCRDY), 462e5e793a6SGabriel Fernandez MUX_CFG(MUX_ADC1, RCC_ADC12CKSELR, 0, 2), 463e5e793a6SGabriel Fernandez MUX_CFG(MUX_ADC2, RCC_ADC12CKSELR, 2, 2), 464e5e793a6SGabriel Fernandez MUX_CFG(MUX_CKPER, RCC_CPERCKSELR, 0, 2), 465e5e793a6SGabriel Fernandez MUX_CFG(MUX_DCMIPP, RCC_DCMIPPCKSELR, 0, 2), 466e5e793a6SGabriel Fernandez MUX_CFG(MUX_ETH1, RCC_ETH12CKSELR, 0, 2), 467e5e793a6SGabriel Fernandez MUX_CFG(MUX_ETH2, RCC_ETH12CKSELR, 8, 2), 468e5e793a6SGabriel Fernandez MUX_CFG(MUX_FDCAN, RCC_FDCANCKSELR, 0, 2), 469e5e793a6SGabriel Fernandez MUX_CFG(MUX_FMC, RCC_FMCCKSELR, 0, 2), 470e5e793a6SGabriel Fernandez MUX_CFG(MUX_I2C12, RCC_I2C12CKSELR, 0, 3), 471e5e793a6SGabriel Fernandez MUX_CFG(MUX_I2C3, RCC_I2C345CKSELR, 0, 3), 472e5e793a6SGabriel Fernandez MUX_CFG(MUX_I2C4, RCC_I2C345CKSELR, 3, 3), 473e5e793a6SGabriel Fernandez MUX_CFG(MUX_I2C5, RCC_I2C345CKSELR, 6, 3), 474e5e793a6SGabriel Fernandez MUX_CFG(MUX_LPTIM1, RCC_LPTIM1CKSELR, 0, 3), 475e5e793a6SGabriel Fernandez MUX_CFG(MUX_LPTIM2, RCC_LPTIM23CKSELR, 0, 3), 476e5e793a6SGabriel Fernandez MUX_CFG(MUX_LPTIM3, RCC_LPTIM23CKSELR, 3, 3), 477e5e793a6SGabriel Fernandez MUX_CFG(MUX_LPTIM45, RCC_LPTIM45CKSELR, 0, 3), 478e5e793a6SGabriel Fernandez MUX_CFG(MUX_MCO1, RCC_MCO1CFGR, 0, 3), 479e5e793a6SGabriel Fernandez MUX_CFG(MUX_MCO2, RCC_MCO2CFGR, 0, 3), 480e5e793a6SGabriel Fernandez MUX_CFG(MUX_QSPI, RCC_QSPICKSELR, 0, 2), 481e5e793a6SGabriel Fernandez MUX_CFG(MUX_RNG1, RCC_RNG1CKSELR, 0, 2), 482e5e793a6SGabriel Fernandez MUX_CFG(MUX_RTC, RCC_BDCR, 16, 2), 483e5e793a6SGabriel Fernandez MUX_CFG(MUX_SAES, RCC_SAESCKSELR, 0, 2), 484e5e793a6SGabriel Fernandez MUX_CFG(MUX_SAI1, RCC_SAI1CKSELR, 0, 3), 485e5e793a6SGabriel Fernandez MUX_CFG(MUX_SAI2, RCC_SAI2CKSELR, 0, 3), 486e5e793a6SGabriel Fernandez MUX_CFG(MUX_SDMMC1, RCC_SDMMC12CKSELR, 0, 3), 487e5e793a6SGabriel Fernandez MUX_CFG(MUX_SDMMC2, RCC_SDMMC12CKSELR, 3, 3), 488e5e793a6SGabriel Fernandez MUX_CFG(MUX_SPDIF, RCC_SPDIFCKSELR, 0, 2), 489e5e793a6SGabriel Fernandez MUX_CFG(MUX_SPI1, RCC_SPI2S1CKSELR, 0, 3), 490e5e793a6SGabriel Fernandez MUX_CFG(MUX_SPI23, RCC_SPI2S23CKSELR, 0, 3), 491e5e793a6SGabriel Fernandez MUX_CFG(MUX_SPI4, RCC_SPI45CKSELR, 0, 3), 492e5e793a6SGabriel Fernandez MUX_CFG(MUX_SPI5, RCC_SPI45CKSELR, 3, 3), 493e5e793a6SGabriel Fernandez MUX_CFG(MUX_STGEN, RCC_STGENCKSELR, 0, 2), 494e5e793a6SGabriel Fernandez MUX_CFG(MUX_UART1, RCC_UART12CKSELR, 0, 3), 495e5e793a6SGabriel Fernandez MUX_CFG(MUX_UART2, RCC_UART12CKSELR, 3, 3), 496e5e793a6SGabriel Fernandez MUX_CFG(MUX_UART35, RCC_UART35CKSELR, 0, 3), 497e5e793a6SGabriel Fernandez MUX_CFG(MUX_UART4, RCC_UART4CKSELR, 0, 3), 498e5e793a6SGabriel Fernandez MUX_CFG(MUX_UART6, RCC_UART6CKSELR, 0, 3), 499e5e793a6SGabriel Fernandez MUX_CFG(MUX_UART78, RCC_UART78CKSELR, 0, 3), 500e5e793a6SGabriel Fernandez MUX_CFG(MUX_USBO, RCC_USBCKSELR, 4, 1), 501e5e793a6SGabriel Fernandez MUX_CFG(MUX_USBPHY, RCC_USBCKSELR, 0, 2), 502e5e793a6SGabriel Fernandez }; 503e5e793a6SGabriel Fernandez 504e5e793a6SGabriel Fernandez /* 505e5e793a6SGabriel Fernandez * DIV CONFIG 506e5e793a6SGabriel Fernandez */ 507e5e793a6SGabriel Fernandez static const struct div_table_cfg axi_div_table[] = { 508e5e793a6SGabriel Fernandez { 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 4 }, 509e5e793a6SGabriel Fernandez { 4, 4 }, { 5, 4 }, { 6, 4 }, { 7, 4 }, 510e5e793a6SGabriel Fernandez { 0 }, 511e5e793a6SGabriel Fernandez }; 512e5e793a6SGabriel Fernandez 513e5e793a6SGabriel Fernandez static const struct div_table_cfg mlahb_div_table[] = { 514e5e793a6SGabriel Fernandez { 0, 1 }, { 1, 2 }, { 2, 4 }, { 3, 8 }, 515e5e793a6SGabriel Fernandez { 4, 16 }, { 5, 32 }, { 6, 64 }, { 7, 128 }, 516e5e793a6SGabriel Fernandez { 8, 256 }, { 9, 512 }, { 10, 512}, { 11, 512 }, 517e5e793a6SGabriel Fernandez { 12, 512 }, { 13, 512 }, { 14, 512}, { 15, 512 }, 518e5e793a6SGabriel Fernandez { 0 }, 519e5e793a6SGabriel Fernandez }; 520e5e793a6SGabriel Fernandez 521e5e793a6SGabriel Fernandez static const struct div_table_cfg apb_div_table[] = { 522e5e793a6SGabriel Fernandez { 0, 1 }, { 1, 2 }, { 2, 4 }, { 3, 8 }, 523e5e793a6SGabriel Fernandez { 4, 16 }, { 5, 16 }, { 6, 16 }, { 7, 16 }, 524e5e793a6SGabriel Fernandez { 0 }, 525e5e793a6SGabriel Fernandez }; 526e5e793a6SGabriel Fernandez 527e5e793a6SGabriel Fernandez #define DIVRDY_CFG(_id, _offset, _shift, _width, _flags, _table, _ready)\ 528e5e793a6SGabriel Fernandez [(_id)] = {\ 529e5e793a6SGabriel Fernandez .offset = (_offset),\ 530e5e793a6SGabriel Fernandez .shift = (_shift),\ 531e5e793a6SGabriel Fernandez .width = (_width),\ 532e5e793a6SGabriel Fernandez .flags = (_flags),\ 533e5e793a6SGabriel Fernandez .table = (_table),\ 534e5e793a6SGabriel Fernandez .ready = (_ready),\ 535e5e793a6SGabriel Fernandez } 536e5e793a6SGabriel Fernandez 537e5e793a6SGabriel Fernandez #define DIV_CFG(_id, _offset, _shift, _width, _flags, _table)\ 538e5e793a6SGabriel Fernandez DIVRDY_CFG(_id, _offset, _shift, _width, _flags, _table, DIV_NO_RDY) 539e5e793a6SGabriel Fernandez 540e5e793a6SGabriel Fernandez static const struct div_cfg dividers_mp13[] = { 541e5e793a6SGabriel Fernandez DIVRDY_CFG(DIV_MPU, RCC_MPCKDIVR, 0, 4, 0, NULL, 542e5e793a6SGabriel Fernandez GATE_MPUDIVRDY), 543e5e793a6SGabriel Fernandez DIVRDY_CFG(DIV_AXI, RCC_AXIDIVR, 0, 3, 0, axi_div_table, 544e5e793a6SGabriel Fernandez GATE_AXIDIVRDY), 545e5e793a6SGabriel Fernandez DIVRDY_CFG(DIV_MLAHB, RCC_MLAHBDIVR, 0, 4, 0, mlahb_div_table, 546e5e793a6SGabriel Fernandez GATE_MLAHBDIVRDY), 547e5e793a6SGabriel Fernandez DIVRDY_CFG(DIV_APB1, RCC_APB1DIVR, 0, 3, 0, apb_div_table, 548e5e793a6SGabriel Fernandez GATE_APB1DIVRDY), 549e5e793a6SGabriel Fernandez DIVRDY_CFG(DIV_APB2, RCC_APB2DIVR, 0, 3, 0, apb_div_table, 550e5e793a6SGabriel Fernandez GATE_APB2DIVRDY), 551e5e793a6SGabriel Fernandez DIVRDY_CFG(DIV_APB3, RCC_APB3DIVR, 0, 3, 0, apb_div_table, 552e5e793a6SGabriel Fernandez GATE_APB3DIVRDY), 553e5e793a6SGabriel Fernandez DIVRDY_CFG(DIV_APB4, RCC_APB4DIVR, 0, 3, 0, apb_div_table, 554e5e793a6SGabriel Fernandez GATE_APB4DIVRDY), 555e5e793a6SGabriel Fernandez DIVRDY_CFG(DIV_APB5, RCC_APB5DIVR, 0, 3, 0, apb_div_table, 556e5e793a6SGabriel Fernandez GATE_APB5DIVRDY), 557e5e793a6SGabriel Fernandez DIVRDY_CFG(DIV_APB6, RCC_APB6DIVR, 0, 3, 0, apb_div_table, 558e5e793a6SGabriel Fernandez GATE_APB6DIVRDY), 559e5e793a6SGabriel Fernandez DIVRDY_CFG(DIV_HSI, RCC_HSICFGR, 0, 2, CLK_DIVIDER_POWER_OF_TWO, NULL, 560e5e793a6SGabriel Fernandez GATE_HSIDIVRDY), 561e5e793a6SGabriel Fernandez DIV_CFG(DIV_PLL1DIVP, RCC_PLL1CFGR2, 0, 7, 0, NULL), 562e5e793a6SGabriel Fernandez DIV_CFG(DIV_PLL2DIVP, RCC_PLL2CFGR2, 0, 7, 0, NULL), 563e5e793a6SGabriel Fernandez DIV_CFG(DIV_PLL2DIVQ, RCC_PLL2CFGR2, 8, 7, 0, NULL), 564e5e793a6SGabriel Fernandez DIV_CFG(DIV_PLL2DIVR, RCC_PLL2CFGR2, 16, 7, 0, NULL), 565e5e793a6SGabriel Fernandez DIV_CFG(DIV_PLL3DIVP, RCC_PLL3CFGR2, 0, 7, 0, NULL), 566e5e793a6SGabriel Fernandez DIV_CFG(DIV_PLL3DIVQ, RCC_PLL3CFGR2, 8, 7, 0, NULL), 567e5e793a6SGabriel Fernandez DIV_CFG(DIV_PLL3DIVR, RCC_PLL3CFGR2, 16, 7, 0, NULL), 568e5e793a6SGabriel Fernandez DIV_CFG(DIV_PLL4DIVP, RCC_PLL4CFGR2, 0, 7, 0, NULL), 569e5e793a6SGabriel Fernandez DIV_CFG(DIV_PLL4DIVQ, RCC_PLL4CFGR2, 8, 7, 0, NULL), 570e5e793a6SGabriel Fernandez DIV_CFG(DIV_PLL4DIVR, RCC_PLL4CFGR2, 16, 7, 0, NULL), 571e5e793a6SGabriel Fernandez DIV_CFG(DIV_RTC, RCC_RTCDIVR, 0, 6, 0, NULL), 572e5e793a6SGabriel Fernandez DIV_CFG(DIV_MCO1, RCC_MCO1CFGR, 4, 4, 0, NULL), 573e5e793a6SGabriel Fernandez DIV_CFG(DIV_MCO2, RCC_MCO2CFGR, 4, 4, 0, NULL), 574e5e793a6SGabriel Fernandez DIV_CFG(DIV_TRACE, RCC_DBGCFGR, 0, 3, CLK_DIVIDER_POWER_OF_TWO, NULL), 575e5e793a6SGabriel Fernandez DIV_CFG(DIV_ETH1PTP, RCC_ETH12CKSELR, 4, 4, 0, NULL), 576e5e793a6SGabriel Fernandez DIV_CFG(DIV_ETH2PTP, RCC_ETH12CKSELR, 12, 4, 0, NULL), 577e5e793a6SGabriel Fernandez }; 578e5e793a6SGabriel Fernandez 579e5e793a6SGabriel Fernandez enum stm32_osc { 580e5e793a6SGabriel Fernandez OSC_HSI, 581e5e793a6SGabriel Fernandez OSC_HSE, 582e5e793a6SGabriel Fernandez OSC_CSI, 583e5e793a6SGabriel Fernandez OSC_LSI, 584e5e793a6SGabriel Fernandez OSC_LSE, 585e5e793a6SGabriel Fernandez NB_OSCILLATOR 586e5e793a6SGabriel Fernandez }; 587e5e793a6SGabriel Fernandez 588e5e793a6SGabriel Fernandez struct stm32_osc_cfg { 589e5e793a6SGabriel Fernandez int osc_id; 590e5e793a6SGabriel Fernandez }; 591e5e793a6SGabriel Fernandez 592e5e793a6SGabriel Fernandez struct clk_stm32_bypass { 593e5e793a6SGabriel Fernandez uint16_t offset; 594e5e793a6SGabriel Fernandez uint8_t bit_byp; 595e5e793a6SGabriel Fernandez uint8_t bit_digbyp; 596e5e793a6SGabriel Fernandez }; 597e5e793a6SGabriel Fernandez 598e5e793a6SGabriel Fernandez struct clk_stm32_css { 599e5e793a6SGabriel Fernandez uint16_t offset; 600e5e793a6SGabriel Fernandez uint8_t bit_css; 601e5e793a6SGabriel Fernandez }; 602e5e793a6SGabriel Fernandez 603e5e793a6SGabriel Fernandez struct clk_stm32_drive { 604e5e793a6SGabriel Fernandez uint16_t offset; 605e5e793a6SGabriel Fernandez uint8_t drv_shift; 606e5e793a6SGabriel Fernandez uint8_t drv_width; 607e5e793a6SGabriel Fernandez uint8_t drv_default; 608e5e793a6SGabriel Fernandez }; 609e5e793a6SGabriel Fernandez 610e5e793a6SGabriel Fernandez struct clk_oscillator_data { 611e5e793a6SGabriel Fernandez const char *name; 612e5e793a6SGabriel Fernandez unsigned long frequency; 613e5e793a6SGabriel Fernandez uint16_t gate_id; 614e5e793a6SGabriel Fernandez struct clk_stm32_bypass *bypass; 615e5e793a6SGabriel Fernandez struct clk_stm32_css *css; 616e5e793a6SGabriel Fernandez struct clk_stm32_drive *drive; 617e5e793a6SGabriel Fernandez }; 618e5e793a6SGabriel Fernandez 619e5e793a6SGabriel Fernandez #define BYPASS(_offset, _bit_byp, _bit_digbyp) (&(struct clk_stm32_bypass){\ 620e5e793a6SGabriel Fernandez .offset = (_offset),\ 621e5e793a6SGabriel Fernandez .bit_byp = (_bit_byp),\ 622e5e793a6SGabriel Fernandez .bit_digbyp = (_bit_digbyp),\ 623e5e793a6SGabriel Fernandez }) 624e5e793a6SGabriel Fernandez 625e5e793a6SGabriel Fernandez #define CSS(_offset, _bit_css) (&(struct clk_stm32_css){\ 626e5e793a6SGabriel Fernandez .offset = (_offset),\ 627e5e793a6SGabriel Fernandez .bit_css = (_bit_css),\ 628e5e793a6SGabriel Fernandez }) 629e5e793a6SGabriel Fernandez 630e5e793a6SGabriel Fernandez #define DRIVE(_offset, _shift, _width, _default) (&(struct clk_stm32_drive){\ 631e5e793a6SGabriel Fernandez .offset = (_offset),\ 632e5e793a6SGabriel Fernandez .drv_shift = (_shift),\ 633e5e793a6SGabriel Fernandez .drv_width = (_width),\ 634e5e793a6SGabriel Fernandez .drv_default = (_default),\ 635e5e793a6SGabriel Fernandez }) 636e5e793a6SGabriel Fernandez 637e5e793a6SGabriel Fernandez #define OSCILLATOR(idx_osc, _name, _gate_id, _bypass, _css, _drive) \ 638e5e793a6SGabriel Fernandez [(idx_osc)] = (struct clk_oscillator_data){\ 639e5e793a6SGabriel Fernandez .name = (_name),\ 640e5e793a6SGabriel Fernandez .gate_id = (_gate_id),\ 641e5e793a6SGabriel Fernandez .bypass = (_bypass),\ 642e5e793a6SGabriel Fernandez .css = (_css),\ 643e5e793a6SGabriel Fernandez .drive = (_drive),\ 644e5e793a6SGabriel Fernandez } 645e5e793a6SGabriel Fernandez 646e5e793a6SGabriel Fernandez static struct clk_oscillator_data stm32mp13_osc_data[NB_OSCILLATOR] = { 647e5e793a6SGabriel Fernandez OSCILLATOR(OSC_HSI, "clk-hsi", GATE_HSI, 648e5e793a6SGabriel Fernandez NULL, NULL, NULL), 649e5e793a6SGabriel Fernandez 650e5e793a6SGabriel Fernandez OSCILLATOR(OSC_LSI, "clk-lsi", GATE_LSI, 651e5e793a6SGabriel Fernandez NULL, NULL, NULL), 652e5e793a6SGabriel Fernandez 653e5e793a6SGabriel Fernandez OSCILLATOR(OSC_CSI, "clk-csi", GATE_CSI, 654e5e793a6SGabriel Fernandez NULL, NULL, NULL), 655e5e793a6SGabriel Fernandez 656e5e793a6SGabriel Fernandez OSCILLATOR(OSC_LSE, "clk-lse", GATE_LSE, 657e5e793a6SGabriel Fernandez BYPASS(RCC_BDCR, 1, 3), 658e5e793a6SGabriel Fernandez CSS(RCC_BDCR, 8), 659e5e793a6SGabriel Fernandez DRIVE(RCC_BDCR, 4, 2, 2)), 660e5e793a6SGabriel Fernandez 661e5e793a6SGabriel Fernandez OSCILLATOR(OSC_HSE, "clk-hse", GATE_HSE, 662e5e793a6SGabriel Fernandez BYPASS(RCC_OCENSETR, 10, 7), 663e5e793a6SGabriel Fernandez CSS(RCC_OCENSETR, 11), 664e5e793a6SGabriel Fernandez NULL), 665e5e793a6SGabriel Fernandez }; 666e5e793a6SGabriel Fernandez 667e5e793a6SGabriel Fernandez static struct clk_oscillator_data *clk_oscillator_get_data(int osc_id) 668e5e793a6SGabriel Fernandez { 669e5e793a6SGabriel Fernandez assert(osc_id >= 0 && osc_id < (int)ARRAY_SIZE(stm32mp13_osc_data)); 670e5e793a6SGabriel Fernandez 671e5e793a6SGabriel Fernandez return &stm32mp13_osc_data[osc_id]; 672e5e793a6SGabriel Fernandez } 673e5e793a6SGabriel Fernandez 674e5e793a6SGabriel Fernandez static unsigned long clk_stm32_get_rate_oscillateur(int osc_id) 675e5e793a6SGabriel Fernandez { 676e5e793a6SGabriel Fernandez struct clk_stm32_priv *priv = clk_stm32_get_priv(); 677e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata = priv->pdata; 678e5e793a6SGabriel Fernandez struct stm32_osci_dt_cfg *osci = &pdata->osci[osc_id]; 679e5e793a6SGabriel Fernandez 680e5e793a6SGabriel Fernandez return osci->freq; 681e5e793a6SGabriel Fernandez } 682e5e793a6SGabriel Fernandez 683e5e793a6SGabriel Fernandez static void clk_oscillator_set_bypass(struct clk_stm32_priv *priv, 684e5e793a6SGabriel Fernandez struct clk_oscillator_data *osc_data, 685e5e793a6SGabriel Fernandez bool digbyp, bool bypass) 686e5e793a6SGabriel Fernandez { 687e5e793a6SGabriel Fernandez struct clk_stm32_bypass *bypass_data = osc_data->bypass; 688e5e793a6SGabriel Fernandez uintptr_t address = 0; 689e5e793a6SGabriel Fernandez 690e5e793a6SGabriel Fernandez if (!bypass_data) 691e5e793a6SGabriel Fernandez return; 692e5e793a6SGabriel Fernandez 693e5e793a6SGabriel Fernandez address = priv->base + bypass_data->offset; 694e5e793a6SGabriel Fernandez 695e5e793a6SGabriel Fernandez if (digbyp) 696e5e793a6SGabriel Fernandez io_setbits32(address, BIT(bypass_data->bit_digbyp)); 697e5e793a6SGabriel Fernandez 698e5e793a6SGabriel Fernandez if (bypass || digbyp) 699e5e793a6SGabriel Fernandez io_setbits32(address, BIT(bypass_data->bit_byp)); 700e5e793a6SGabriel Fernandez } 701e5e793a6SGabriel Fernandez 702e5e793a6SGabriel Fernandez static void clk_oscillator_set_css(struct clk_stm32_priv *priv, 703e5e793a6SGabriel Fernandez struct clk_oscillator_data *osc_data, 704e5e793a6SGabriel Fernandez bool css) 705e5e793a6SGabriel Fernandez { 706e5e793a6SGabriel Fernandez struct clk_stm32_css *css_data = osc_data->css; 707e5e793a6SGabriel Fernandez uintptr_t address = 0; 708e5e793a6SGabriel Fernandez 709e5e793a6SGabriel Fernandez if (!css_data) 710e5e793a6SGabriel Fernandez return; 711e5e793a6SGabriel Fernandez 712e5e793a6SGabriel Fernandez address = priv->base + css_data->offset; 713e5e793a6SGabriel Fernandez 714e5e793a6SGabriel Fernandez if (css) 715e5e793a6SGabriel Fernandez io_setbits32(address, BIT(css_data->bit_css)); 716e5e793a6SGabriel Fernandez } 717e5e793a6SGabriel Fernandez 718e5e793a6SGabriel Fernandez static void clk_oscillator_set_drive(struct clk_stm32_priv *priv, 719e5e793a6SGabriel Fernandez struct clk_oscillator_data *osc_data, 720e5e793a6SGabriel Fernandez uint8_t lsedrv) 721e5e793a6SGabriel Fernandez { 722e5e793a6SGabriel Fernandez struct clk_stm32_drive *drive_data = osc_data->drive; 723e5e793a6SGabriel Fernandez uintptr_t address = 0; 724e5e793a6SGabriel Fernandez uint32_t mask = 0; 725e5e793a6SGabriel Fernandez uint32_t value = 0; 726e5e793a6SGabriel Fernandez 727e5e793a6SGabriel Fernandez if (!drive_data) 728e5e793a6SGabriel Fernandez return; 729e5e793a6SGabriel Fernandez 730e5e793a6SGabriel Fernandez address = priv->base + drive_data->offset; 731e5e793a6SGabriel Fernandez 732e5e793a6SGabriel Fernandez mask = (BIT(drive_data->drv_width) - 1U) << drive_data->drv_shift; 733e5e793a6SGabriel Fernandez 734e5e793a6SGabriel Fernandez /* 735e5e793a6SGabriel Fernandez * Warning: not recommended to switch directly from "high drive" 736e5e793a6SGabriel Fernandez * to "medium low drive", and vice-versa. 737e5e793a6SGabriel Fernandez */ 738e5e793a6SGabriel Fernandez value = (io_read32(address) & mask) >> drive_data->drv_shift; 739e5e793a6SGabriel Fernandez 740e5e793a6SGabriel Fernandez while (value != lsedrv) { 741e5e793a6SGabriel Fernandez if (value > lsedrv) 742e5e793a6SGabriel Fernandez value--; 743e5e793a6SGabriel Fernandez else 744e5e793a6SGabriel Fernandez value++; 745e5e793a6SGabriel Fernandez 746e5e793a6SGabriel Fernandez io_clrsetbits32(address, mask, value << drive_data->drv_shift); 747e5e793a6SGabriel Fernandez } 748e5e793a6SGabriel Fernandez } 749e5e793a6SGabriel Fernandez 750e5e793a6SGabriel Fernandez static void stm32_enable_oscillator_hse(struct clk_stm32_priv *priv, 751e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata) 752e5e793a6SGabriel Fernandez { 753e5e793a6SGabriel Fernandez struct clk_oscillator_data *osc_data = clk_oscillator_get_data(OSC_HSE); 754e5e793a6SGabriel Fernandez struct stm32_osci_dt_cfg *osci = &pdata->osci[OSC_HSE]; 755e5e793a6SGabriel Fernandez 756e5e793a6SGabriel Fernandez if (osci->freq == 0U) 757e5e793a6SGabriel Fernandez return; 758e5e793a6SGabriel Fernandez 759e5e793a6SGabriel Fernandez clk_oscillator_set_bypass(priv, osc_data, osci->digbyp, osci->bypass); 760e5e793a6SGabriel Fernandez 761e5e793a6SGabriel Fernandez /* Enable clock and wait ready bit */ 762e5e793a6SGabriel Fernandez if (stm32_gate_rdy_enable(osc_data->gate_id)) { 763e5e793a6SGabriel Fernandez EMSG("timeout to enable hse clock"); 764e5e793a6SGabriel Fernandez panic(); 765e5e793a6SGabriel Fernandez } 766e5e793a6SGabriel Fernandez 767e5e793a6SGabriel Fernandez clk_oscillator_set_css(priv, osc_data, osci->css); 768e5e793a6SGabriel Fernandez } 769e5e793a6SGabriel Fernandez 770e5e793a6SGabriel Fernandez static void stm32_enable_oscillator_lse(struct clk_stm32_priv *priv, 771e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata) 772e5e793a6SGabriel Fernandez { 773e5e793a6SGabriel Fernandez struct clk_oscillator_data *osc_data = clk_oscillator_get_data(OSC_LSE); 774e5e793a6SGabriel Fernandez struct stm32_osci_dt_cfg *osci = &pdata->osci[OSC_LSE]; 775e5e793a6SGabriel Fernandez 776e5e793a6SGabriel Fernandez if (osci->freq == 0U) 777e5e793a6SGabriel Fernandez return; 778e5e793a6SGabriel Fernandez 779e5e793a6SGabriel Fernandez clk_oscillator_set_bypass(priv, osc_data, osci->digbyp, osci->bypass); 780e5e793a6SGabriel Fernandez 781e5e793a6SGabriel Fernandez clk_oscillator_set_drive(priv, osc_data, osci->drive); 782e5e793a6SGabriel Fernandez 783e5e793a6SGabriel Fernandez /* Enable lse clock, but don't wait ready bit */ 784e5e793a6SGabriel Fernandez stm32_gate_enable(osc_data->gate_id); 785e5e793a6SGabriel Fernandez } 786e5e793a6SGabriel Fernandez 787e5e793a6SGabriel Fernandez static void 788e5e793a6SGabriel Fernandez stm32_enable_oscillator_lsi(struct clk_stm32_priv *priv __maybe_unused, 789e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata) 790e5e793a6SGabriel Fernandez { 791e5e793a6SGabriel Fernandez struct clk_oscillator_data *osc_data = clk_oscillator_get_data(OSC_LSI); 792e5e793a6SGabriel Fernandez struct stm32_osci_dt_cfg *osci = &pdata->osci[OSC_LSI]; 793e5e793a6SGabriel Fernandez 794e5e793a6SGabriel Fernandez if (osci->freq == 0U) 795e5e793a6SGabriel Fernandez return; 796e5e793a6SGabriel Fernandez 797e5e793a6SGabriel Fernandez /* Enable clock and wait ready bit */ 798e5e793a6SGabriel Fernandez if (stm32_gate_rdy_enable(osc_data->gate_id)) { 799e5e793a6SGabriel Fernandez EMSG("timeout to enable lsi clock"); 800e5e793a6SGabriel Fernandez panic(); 801e5e793a6SGabriel Fernandez } 802e5e793a6SGabriel Fernandez } 803e5e793a6SGabriel Fernandez 804e5e793a6SGabriel Fernandez static void 805e5e793a6SGabriel Fernandez stm32_enable_oscillator_csi(struct clk_stm32_priv *priv __maybe_unused, 806e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata) 807e5e793a6SGabriel Fernandez { 808e5e793a6SGabriel Fernandez struct clk_oscillator_data *osc_data = clk_oscillator_get_data(OSC_CSI); 809e5e793a6SGabriel Fernandez struct stm32_osci_dt_cfg *osci = &pdata->osci[OSC_CSI]; 810e5e793a6SGabriel Fernandez 811e5e793a6SGabriel Fernandez if (osci->freq == 0U) 812e5e793a6SGabriel Fernandez return; 813e5e793a6SGabriel Fernandez 814e5e793a6SGabriel Fernandez /* Enable clock and wait ready bit */ 815e5e793a6SGabriel Fernandez if (stm32_gate_rdy_enable(osc_data->gate_id)) { 816e5e793a6SGabriel Fernandez EMSG("timeout to enable csi clock"); 817e5e793a6SGabriel Fernandez panic(); 818e5e793a6SGabriel Fernandez } 819e5e793a6SGabriel Fernandez } 820e5e793a6SGabriel Fernandez 821e5e793a6SGabriel Fernandez static int stm32_clk_oscillators_lse_set_css(struct clk_stm32_priv *priv, 822e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata) 823e5e793a6SGabriel Fernandez 824e5e793a6SGabriel Fernandez { 825e5e793a6SGabriel Fernandez struct clk_oscillator_data *osc_data = clk_oscillator_get_data(OSC_LSE); 826e5e793a6SGabriel Fernandez struct stm32_osci_dt_cfg *osci = &pdata->osci[OSC_LSE]; 827e5e793a6SGabriel Fernandez 828e5e793a6SGabriel Fernandez clk_oscillator_set_css(priv, osc_data, osci->css); 829e5e793a6SGabriel Fernandez 830e5e793a6SGabriel Fernandez return 0; 831e5e793a6SGabriel Fernandez } 832e5e793a6SGabriel Fernandez 833e5e793a6SGabriel Fernandez static int 834e5e793a6SGabriel Fernandez stm32_clk_oscillators_wait_lse_ready(struct clk_stm32_priv *priv __maybe_unused, 835e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata) 836e5e793a6SGabriel Fernandez { 837e5e793a6SGabriel Fernandez struct clk_oscillator_data *osc_data = clk_oscillator_get_data(OSC_LSE); 838e5e793a6SGabriel Fernandez struct stm32_osci_dt_cfg *osci = &pdata->osci[OSC_LSE]; 839e5e793a6SGabriel Fernandez 840e5e793a6SGabriel Fernandez if (osci->freq == 0U) 841e5e793a6SGabriel Fernandez return 0; 842e5e793a6SGabriel Fernandez 843e5e793a6SGabriel Fernandez if (stm32_gate_wait_ready(osc_data->gate_id, true)) 844e5e793a6SGabriel Fernandez return -1; 845e5e793a6SGabriel Fernandez 846e5e793a6SGabriel Fernandez return 0; 847e5e793a6SGabriel Fernandez } 848e5e793a6SGabriel Fernandez 849e5e793a6SGabriel Fernandez static void stm32_clk_oscillators_enable(struct clk_stm32_priv *priv, 850e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata) 851e5e793a6SGabriel Fernandez { 852e5e793a6SGabriel Fernandez stm32_enable_oscillator_hse(priv, pdata); 853e5e793a6SGabriel Fernandez stm32_enable_oscillator_lse(priv, pdata); 854e5e793a6SGabriel Fernandez stm32_enable_oscillator_lsi(priv, pdata); 855e5e793a6SGabriel Fernandez stm32_enable_oscillator_csi(priv, pdata); 856e5e793a6SGabriel Fernandez } 857e5e793a6SGabriel Fernandez 858e5e793a6SGabriel Fernandez enum stm32_pll_id { 859e5e793a6SGabriel Fernandez PLL1_ID, 860e5e793a6SGabriel Fernandez PLL2_ID, 861e5e793a6SGabriel Fernandez PLL3_ID, 862e5e793a6SGabriel Fernandez PLL4_ID, 863e5e793a6SGabriel Fernandez PLL_NB 864e5e793a6SGabriel Fernandez }; 865e5e793a6SGabriel Fernandez 866e5e793a6SGabriel Fernandez enum stm32mp1_plltype { 867e5e793a6SGabriel Fernandez PLL_800, 868e5e793a6SGabriel Fernandez PLL_1600, 869e5e793a6SGabriel Fernandez PLL_2000, 870e5e793a6SGabriel Fernandez PLL_TYPE_NB 871e5e793a6SGabriel Fernandez }; 872e5e793a6SGabriel Fernandez 873e5e793a6SGabriel Fernandez #define RCC_OFFSET_PLLXCR 0 874e5e793a6SGabriel Fernandez #define RCC_OFFSET_PLLXCFGR1 4 875e5e793a6SGabriel Fernandez #define RCC_OFFSET_PLLXCFGR2 8 876e5e793a6SGabriel Fernandez #define RCC_OFFSET_PLLXFRACR 12 877e5e793a6SGabriel Fernandez #define RCC_OFFSET_PLLXCSGR 16 878e5e793a6SGabriel Fernandez 879e5e793a6SGabriel Fernandez struct stm32_clk_pll { 880e5e793a6SGabriel Fernandez enum stm32mp1_plltype plltype; 881e5e793a6SGabriel Fernandez uint16_t gate_id; 882e5e793a6SGabriel Fernandez uint16_t mux_id; 883e5e793a6SGabriel Fernandez uint16_t reg_pllxcr; 884e5e793a6SGabriel Fernandez }; 885e5e793a6SGabriel Fernandez 886e5e793a6SGabriel Fernandez struct stm32mp1_pll { 887e5e793a6SGabriel Fernandez uint8_t refclk_min; 888e5e793a6SGabriel Fernandez uint8_t refclk_max; 889e5e793a6SGabriel Fernandez }; 890e5e793a6SGabriel Fernandez 891e5e793a6SGabriel Fernandez /* Define characteristic of PLL according type */ 892e5e793a6SGabriel Fernandez static const struct stm32mp1_pll stm32mp1_pll[PLL_TYPE_NB] = { 893e5e793a6SGabriel Fernandez [PLL_800] = { 894e5e793a6SGabriel Fernandez .refclk_min = 4, 895e5e793a6SGabriel Fernandez .refclk_max = 16, 896e5e793a6SGabriel Fernandez }, 897e5e793a6SGabriel Fernandez [PLL_1600] = { 898e5e793a6SGabriel Fernandez .refclk_min = 8, 899e5e793a6SGabriel Fernandez .refclk_max = 16, 900e5e793a6SGabriel Fernandez }, 901e5e793a6SGabriel Fernandez [PLL_2000] = { 902e5e793a6SGabriel Fernandez .refclk_min = 8, 903e5e793a6SGabriel Fernandez .refclk_max = 16, 904e5e793a6SGabriel Fernandez } 905e5e793a6SGabriel Fernandez }; 906e5e793a6SGabriel Fernandez 907e5e793a6SGabriel Fernandez #define CLK_PLL_CFG(_idx, _type, _gate_id, _mux_id, _reg)\ 908e5e793a6SGabriel Fernandez [(_idx)] = {\ 909e5e793a6SGabriel Fernandez .gate_id = (_gate_id),\ 910e5e793a6SGabriel Fernandez .mux_id = (_mux_id),\ 911e5e793a6SGabriel Fernandez .plltype = (_type),\ 912e5e793a6SGabriel Fernandez .reg_pllxcr = (_reg),\ 913e5e793a6SGabriel Fernandez } 914e5e793a6SGabriel Fernandez 915e5e793a6SGabriel Fernandez static const struct stm32_clk_pll stm32_mp13_clk_pll[PLL_NB] = { 916e5e793a6SGabriel Fernandez CLK_PLL_CFG(PLL1_ID, PLL_2000, GATE_PLL1, MUX_PLL12, RCC_PLL1CR), 917e5e793a6SGabriel Fernandez CLK_PLL_CFG(PLL2_ID, PLL_1600, GATE_PLL2, MUX_PLL12, RCC_PLL2CR), 918e5e793a6SGabriel Fernandez CLK_PLL_CFG(PLL3_ID, PLL_800, GATE_PLL3, MUX_PLL3, RCC_PLL3CR), 919e5e793a6SGabriel Fernandez CLK_PLL_CFG(PLL4_ID, PLL_800, GATE_PLL4, MUX_PLL4, RCC_PLL4CR), 920e5e793a6SGabriel Fernandez }; 921e5e793a6SGabriel Fernandez 922e5e793a6SGabriel Fernandez static const struct stm32_clk_pll *clk_stm32_pll_data(unsigned int idx) 923e5e793a6SGabriel Fernandez { 924e5e793a6SGabriel Fernandez return &stm32_mp13_clk_pll[idx]; 925e5e793a6SGabriel Fernandez } 926e5e793a6SGabriel Fernandez 927e5e793a6SGabriel Fernandez /* Clock TREE configuration */ 928e5e793a6SGabriel Fernandez 929e5e793a6SGabriel Fernandez static unsigned int stm32_clk_configure_clk_get_binding_id(uint32_t data) 930e5e793a6SGabriel Fernandez { 931e5e793a6SGabriel Fernandez return (data & CLK_ID_MASK) >> CLK_ID_SHIFT; 932e5e793a6SGabriel Fernandez } 933e5e793a6SGabriel Fernandez 934e5e793a6SGabriel Fernandez static int stm32_clk_configure_clk(struct clk_stm32_priv *priv __maybe_unused, 935e5e793a6SGabriel Fernandez uint32_t data) 936e5e793a6SGabriel Fernandez { 937e5e793a6SGabriel Fernandez int sel = (data & CLK_SEL_MASK) >> CLK_SEL_SHIFT; 938e5e793a6SGabriel Fernandez int enable = (data & CLK_ON_MASK) >> CLK_ON_SHIFT; 939e5e793a6SGabriel Fernandez int clk_id = 0; 940e5e793a6SGabriel Fernandez int ret = 0; 941e5e793a6SGabriel Fernandez int mux = -1; 942e5e793a6SGabriel Fernandez int gate = -1; 943e5e793a6SGabriel Fernandez 944e5e793a6SGabriel Fernandez clk_id = stm32_clk_configure_clk_get_binding_id(data); 945e5e793a6SGabriel Fernandez 946e5e793a6SGabriel Fernandez switch (clk_id) { 947e5e793a6SGabriel Fernandez case CK_MCO1: 948e5e793a6SGabriel Fernandez mux = MUX_MCO1; 949e5e793a6SGabriel Fernandez gate = GATE_MCO1; 950e5e793a6SGabriel Fernandez break; 951e5e793a6SGabriel Fernandez 952e5e793a6SGabriel Fernandez case CK_MCO2: 953e5e793a6SGabriel Fernandez mux = MUX_MCO2; 954e5e793a6SGabriel Fernandez gate = GATE_MCO2; 955e5e793a6SGabriel Fernandez break; 956e5e793a6SGabriel Fernandez default: 957e5e793a6SGabriel Fernandez ret = -1; 958e5e793a6SGabriel Fernandez break; 959e5e793a6SGabriel Fernandez } 960e5e793a6SGabriel Fernandez 961e5e793a6SGabriel Fernandez if (ret != 0) 962e5e793a6SGabriel Fernandez return ret; 963e5e793a6SGabriel Fernandez 964e5e793a6SGabriel Fernandez if (stm32_mux_set_parent(mux, sel)) 965e5e793a6SGabriel Fernandez return -1; 966e5e793a6SGabriel Fernandez 967e5e793a6SGabriel Fernandez if (enable) 968e5e793a6SGabriel Fernandez stm32_gate_enable(gate); 969e5e793a6SGabriel Fernandez else 970e5e793a6SGabriel Fernandez stm32_gate_disable(gate); 971e5e793a6SGabriel Fernandez 972e5e793a6SGabriel Fernandez return 0; 973e5e793a6SGabriel Fernandez } 974e5e793a6SGabriel Fernandez 975e5e793a6SGabriel Fernandez static int stm32_clk_configure_mux(__unused struct clk_stm32_priv *priv, 976e5e793a6SGabriel Fernandez uint32_t data) 977e5e793a6SGabriel Fernandez { 978e5e793a6SGabriel Fernandez int mux = (data & MUX_ID_MASK) >> MUX_ID_SHIFT; 979e5e793a6SGabriel Fernandez int sel = (data & MUX_SEL_MASK) >> MUX_SEL_SHIFT; 980e5e793a6SGabriel Fernandez 981e5e793a6SGabriel Fernandez if (mux == MUX_RTC) { 982e5e793a6SGabriel Fernandez /* Mux RTC clock only is selector is valid and RTC not yet 983e5e793a6SGabriel Fernandez * enabled 984e5e793a6SGabriel Fernandez */ 985e5e793a6SGabriel Fernandez if (sel == 0) 986e5e793a6SGabriel Fernandez return 0; 987e5e793a6SGabriel Fernandez 988e5e793a6SGabriel Fernandez if (stm32_gate_is_enabled(GATE_RTCCK)) 989e5e793a6SGabriel Fernandez return 0; 990e5e793a6SGabriel Fernandez } 991e5e793a6SGabriel Fernandez 992e5e793a6SGabriel Fernandez if (stm32_mux_set_parent(mux, sel)) 993e5e793a6SGabriel Fernandez return -1; 994e5e793a6SGabriel Fernandez 995e5e793a6SGabriel Fernandez return 0; 996e5e793a6SGabriel Fernandez } 997e5e793a6SGabriel Fernandez 998e5e793a6SGabriel Fernandez static TEE_Result 999e5e793a6SGabriel Fernandez stm32_clk_configure_div(struct clk_stm32_priv *priv __maybe_unused, 1000e5e793a6SGabriel Fernandez uint32_t data) 1001e5e793a6SGabriel Fernandez { 1002e5e793a6SGabriel Fernandez int div_id = (data & DIV_ID_MASK) >> DIV_ID_SHIFT; 1003e5e793a6SGabriel Fernandez int div_n = (data & DIV_DIVN_MASK) >> DIV_DIVN_SHIFT; 1004e5e793a6SGabriel Fernandez 1005e5e793a6SGabriel Fernandez return stm32_div_set_value(div_id, div_n); 1006e5e793a6SGabriel Fernandez } 1007e5e793a6SGabriel Fernandez 1008e5e793a6SGabriel Fernandez static int stm32_clk_dividers_configure(struct clk_stm32_priv *priv) 1009e5e793a6SGabriel Fernandez { 1010e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata = priv->pdata; 1011e5e793a6SGabriel Fernandez unsigned int i = 0; 1012e5e793a6SGabriel Fernandez 1013e5e793a6SGabriel Fernandez for (i = 0; i < pdata->nclkdiv; i++) { 1014e5e793a6SGabriel Fernandez if (stm32_clk_configure_div(priv, pdata->clkdiv[i])) 1015e5e793a6SGabriel Fernandez return -1; 1016e5e793a6SGabriel Fernandez } 1017e5e793a6SGabriel Fernandez 1018e5e793a6SGabriel Fernandez return 0; 1019e5e793a6SGabriel Fernandez } 1020e5e793a6SGabriel Fernandez 1021e5e793a6SGabriel Fernandez static int stm32_clk_source_configure(struct clk_stm32_priv *priv) 1022e5e793a6SGabriel Fernandez { 1023e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata = priv->pdata; 1024e5e793a6SGabriel Fernandez bool ckper_disabled = false; 1025e5e793a6SGabriel Fernandez int ret = 0; 1026e5e793a6SGabriel Fernandez size_t i = 0; 1027e5e793a6SGabriel Fernandez 1028e5e793a6SGabriel Fernandez for (i = 0; i < pdata->nclksrc; i++) { 1029e5e793a6SGabriel Fernandez uint32_t val = pdata->clksrc[i]; 1030e5e793a6SGabriel Fernandez uint32_t cmd = 0; 1031e5e793a6SGabriel Fernandez uint32_t cmd_data = 0; 1032e5e793a6SGabriel Fernandez 1033e5e793a6SGabriel Fernandez if (val == (uint32_t)CLK_CKPER_DISABLED) { 1034e5e793a6SGabriel Fernandez ckper_disabled = true; 1035e5e793a6SGabriel Fernandez continue; 1036e5e793a6SGabriel Fernandez } 1037e5e793a6SGabriel Fernandez 1038e5e793a6SGabriel Fernandez cmd = (val & CMD_MASK) >> CMD_SHIFT; 1039e5e793a6SGabriel Fernandez cmd_data = val & ~CMD_MASK; 1040e5e793a6SGabriel Fernandez 1041e5e793a6SGabriel Fernandez switch (cmd) { 1042e5e793a6SGabriel Fernandez case CMD_MUX: 1043e5e793a6SGabriel Fernandez ret = stm32_clk_configure_mux(priv, cmd_data); 1044e5e793a6SGabriel Fernandez break; 1045e5e793a6SGabriel Fernandez 1046e5e793a6SGabriel Fernandez case CMD_CLK: 1047e5e793a6SGabriel Fernandez ret = stm32_clk_configure_clk(priv, cmd_data); 1048e5e793a6SGabriel Fernandez break; 1049e5e793a6SGabriel Fernandez default: 1050e5e793a6SGabriel Fernandez ret = -1; 1051e5e793a6SGabriel Fernandez break; 1052e5e793a6SGabriel Fernandez } 1053e5e793a6SGabriel Fernandez 1054e5e793a6SGabriel Fernandez if (ret != 0) 1055e5e793a6SGabriel Fernandez return ret; 1056e5e793a6SGabriel Fernandez } 1057e5e793a6SGabriel Fernandez 1058e5e793a6SGabriel Fernandez /* 1059e5e793a6SGabriel Fernandez * CKPER is source for some peripheral clocks 1060e5e793a6SGabriel Fernandez * (FMC-NAND / QPSI-NOR) and switching source is allowed 1061e5e793a6SGabriel Fernandez * only if previous clock is still ON 1062e5e793a6SGabriel Fernandez * => deactivate CKPER only after switching clock 1063e5e793a6SGabriel Fernandez */ 1064e5e793a6SGabriel Fernandez if (ckper_disabled) { 1065e5e793a6SGabriel Fernandez ret = stm32_clk_configure_mux(priv, 1066e5e793a6SGabriel Fernandez CLK_CKPER_DISABLED & CMD_MASK); 1067e5e793a6SGabriel Fernandez if (ret != 0) 1068e5e793a6SGabriel Fernandez return ret; 1069e5e793a6SGabriel Fernandez } 1070e5e793a6SGabriel Fernandez 1071e5e793a6SGabriel Fernandez return 0; 1072e5e793a6SGabriel Fernandez } 1073e5e793a6SGabriel Fernandez 1074e5e793a6SGabriel Fernandez static unsigned long clk_stm32_pll_get_oscillator_rate(int sel) 1075e5e793a6SGabriel Fernandez { 1076e5e793a6SGabriel Fernandez const int osc[] = { OSC_HSI, OSC_HSE, OSC_CSI }; 1077e5e793a6SGabriel Fernandez 1078e5e793a6SGabriel Fernandez assert(sel >= 0 && sel < (int)ARRAY_SIZE(osc)); 1079e5e793a6SGabriel Fernandez 1080e5e793a6SGabriel Fernandez return clk_stm32_get_rate_oscillateur(osc[sel]); 1081e5e793a6SGabriel Fernandez } 1082e5e793a6SGabriel Fernandez 1083e5e793a6SGabriel Fernandez static int clk_stm32_pll_compute_cfgr1(const struct stm32_clk_pll *pll, 1084e5e793a6SGabriel Fernandez struct stm32_pll_vco *vco, 1085e5e793a6SGabriel Fernandez uint32_t *value) 1086e5e793a6SGabriel Fernandez { 1087e5e793a6SGabriel Fernandez int sel = (vco->src & MUX_SEL_MASK) >> MUX_SEL_SHIFT; 1088e5e793a6SGabriel Fernandez uint32_t divm = vco->div_mn[PLL_CFG_M]; 1089e5e793a6SGabriel Fernandez uint32_t divn = vco->div_mn[PLL_CFG_N]; 1090e5e793a6SGabriel Fernandez unsigned long refclk = 0UL; 1091e5e793a6SGabriel Fernandez 1092e5e793a6SGabriel Fernandez refclk = clk_stm32_pll_get_oscillator_rate(sel) / (divm + 1U); 1093e5e793a6SGabriel Fernandez 1094e5e793a6SGabriel Fernandez if ((refclk < (stm32mp1_pll[pll->plltype].refclk_min * 1000000U)) || 1095e5e793a6SGabriel Fernandez (refclk > (stm32mp1_pll[pll->plltype].refclk_max * 1000000U))) 1096e5e793a6SGabriel Fernandez return -1; 1097e5e793a6SGabriel Fernandez 1098e5e793a6SGabriel Fernandez *value = 0; 1099e5e793a6SGabriel Fernandez 1100e5e793a6SGabriel Fernandez if (pll->plltype == PLL_800 && refclk >= 8000000U) 1101e5e793a6SGabriel Fernandez *value = 1U << RCC_PLLNCFGR1_IFRGE_SHIFT; 1102e5e793a6SGabriel Fernandez 1103e5e793a6SGabriel Fernandez *value |= (divn << RCC_PLLNCFGR1_DIVN_SHIFT) & RCC_PLLNCFGR1_DIVN_MASK; 1104e5e793a6SGabriel Fernandez *value |= (divm << RCC_PLLNCFGR1_DIVM_SHIFT) & RCC_PLLNCFGR1_DIVM_MASK; 1105e5e793a6SGabriel Fernandez 1106e5e793a6SGabriel Fernandez return 0; 1107e5e793a6SGabriel Fernandez } 1108e5e793a6SGabriel Fernandez 1109e5e793a6SGabriel Fernandez static uint32_t clk_stm32_pll_compute_cfgr2(struct stm32_pll_output *out) 1110e5e793a6SGabriel Fernandez { 1111e5e793a6SGabriel Fernandez uint32_t value = 0; 1112e5e793a6SGabriel Fernandez 1113e5e793a6SGabriel Fernandez value |= (out->output[PLL_CFG_P] << RCC_PLLNCFGR2_DIVP_SHIFT) & 1114e5e793a6SGabriel Fernandez RCC_PLLNCFGR2_DIVP_MASK; 1115e5e793a6SGabriel Fernandez value |= (out->output[PLL_CFG_Q] << RCC_PLLNCFGR2_DIVQ_SHIFT) & 1116e5e793a6SGabriel Fernandez RCC_PLLNCFGR2_DIVQ_MASK; 1117e5e793a6SGabriel Fernandez value |= (out->output[PLL_CFG_R] << RCC_PLLNCFGR2_DIVR_SHIFT) & 1118e5e793a6SGabriel Fernandez RCC_PLLNCFGR2_DIVR_MASK; 1119e5e793a6SGabriel Fernandez 1120e5e793a6SGabriel Fernandez return value; 1121e5e793a6SGabriel Fernandez } 1122e5e793a6SGabriel Fernandez 1123e5e793a6SGabriel Fernandez /* 1124e5e793a6SGabriel Fernandez * Check if PLL1 can be configured on the fly. 1125e5e793a6SGabriel Fernandez * @result (-1) => config on the fly is not possible. 1126e5e793a6SGabriel Fernandez * (0) => config on the fly is possible. 1127e5e793a6SGabriel Fernandez * (+1) => same parameters, no need to reconfigure. 1128e5e793a6SGabriel Fernandez * Return value is 0 if no error. 1129e5e793a6SGabriel Fernandez */ 1130e5e793a6SGabriel Fernandez static int clk_stm32_is_pll_config_on_the_fly(struct clk_stm32_priv *priv, 1131e5e793a6SGabriel Fernandez const struct stm32_clk_pll *pll, 1132e5e793a6SGabriel Fernandez struct stm32_pll_dt_cfg *pll_conf, 1133e5e793a6SGabriel Fernandez int *result) 1134e5e793a6SGabriel Fernandez { 1135e5e793a6SGabriel Fernandez uintptr_t pll_base = priv->base + pll->reg_pllxcr; 1136e5e793a6SGabriel Fernandez struct stm32_pll_vco *vco = &pll_conf->vco; 1137e5e793a6SGabriel Fernandez struct stm32_pll_output *out = &pll_conf->output; 1138e5e793a6SGabriel Fernandez uint32_t fracr = 0; 1139e5e793a6SGabriel Fernandez uint32_t value = 0; 1140e5e793a6SGabriel Fernandez int ret = 0; 1141e5e793a6SGabriel Fernandez size_t sel = 0; 1142e5e793a6SGabriel Fernandez 1143e5e793a6SGabriel Fernandez ret = clk_stm32_pll_compute_cfgr1(pll, vco, &value); 1144e5e793a6SGabriel Fernandez if (ret != 0) 1145e5e793a6SGabriel Fernandez return ret; 1146e5e793a6SGabriel Fernandez 1147e5e793a6SGabriel Fernandez sel = (vco->src & MUX_SEL_MASK) >> MUX_SEL_SHIFT; 1148e5e793a6SGabriel Fernandez if (sel != stm32_mux_get_parent(pll->mux_id)) { 1149e5e793a6SGabriel Fernandez /* Clock source of the PLL is different */ 1150e5e793a6SGabriel Fernandez *result = -1; 1151e5e793a6SGabriel Fernandez return 0; 1152e5e793a6SGabriel Fernandez } 1153e5e793a6SGabriel Fernandez 1154e5e793a6SGabriel Fernandez if (io_read32(pll_base + RCC_OFFSET_PLLXCFGR1) != value) { 1155e5e793a6SGabriel Fernandez /* Different DIVN/DIVM, can't config on the fly */ 1156e5e793a6SGabriel Fernandez *result = -1; 1157e5e793a6SGabriel Fernandez return 0; 1158e5e793a6SGabriel Fernandez } 1159e5e793a6SGabriel Fernandez 1160e5e793a6SGabriel Fernandez *result = 1; 1161e5e793a6SGabriel Fernandez 1162e5e793a6SGabriel Fernandez fracr = vco->frac << RCC_PLLNFRACR_FRACV_SHIFT; 1163e5e793a6SGabriel Fernandez fracr |= RCC_PLLNCFGR1_DIVM_MASK; 1164e5e793a6SGabriel Fernandez value = clk_stm32_pll_compute_cfgr2(out); 1165e5e793a6SGabriel Fernandez 1166e5e793a6SGabriel Fernandez if ((io_read32(pll_base + RCC_OFFSET_PLLXFRACR) == fracr) && 1167e5e793a6SGabriel Fernandez (io_read32(pll_base + RCC_OFFSET_PLLXCFGR2) == value)) { 1168e5e793a6SGabriel Fernandez /* Same parameters, no need to config */ 1169e5e793a6SGabriel Fernandez *result = 1; 1170e5e793a6SGabriel Fernandez } else { 1171e5e793a6SGabriel Fernandez *result = 0; 1172e5e793a6SGabriel Fernandez } 1173e5e793a6SGabriel Fernandez 1174e5e793a6SGabriel Fernandez return 0; 1175e5e793a6SGabriel Fernandez } 1176e5e793a6SGabriel Fernandez 1177e5e793a6SGabriel Fernandez static int stm32_clk_hsidiv_configure(struct clk_stm32_priv *priv) 1178e5e793a6SGabriel Fernandez { 1179e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata = priv->pdata; 1180e5e793a6SGabriel Fernandez struct stm32_osci_dt_cfg *osci = &pdata->osci[OSC_HSI]; 1181e5e793a6SGabriel Fernandez 1182e5e793a6SGabriel Fernandez return stm32_div_set_rate(DIV_HSI, osci->freq, MAX_HSI_HZ); 1183e5e793a6SGabriel Fernandez } 1184e5e793a6SGabriel Fernandez 1185e5e793a6SGabriel Fernandez static void clk_stm32_pll_config_vco(struct clk_stm32_priv *priv, 1186e5e793a6SGabriel Fernandez const struct stm32_clk_pll *pll, 1187e5e793a6SGabriel Fernandez struct stm32_pll_vco *vco) 1188e5e793a6SGabriel Fernandez { 1189e5e793a6SGabriel Fernandez uintptr_t pll_base = priv->base + pll->reg_pllxcr; 1190e5e793a6SGabriel Fernandez uint32_t value = 0; 1191e5e793a6SGabriel Fernandez 1192e5e793a6SGabriel Fernandez if (clk_stm32_pll_compute_cfgr1(pll, vco, &value) != 0) { 1193e5e793a6SGabriel Fernandez EMSG("Invalid Vref clock"); 1194e5e793a6SGabriel Fernandez panic(); 1195e5e793a6SGabriel Fernandez } 1196e5e793a6SGabriel Fernandez 1197e5e793a6SGabriel Fernandez /* Write N / M / IFREGE fields */ 1198e5e793a6SGabriel Fernandez io_write32(pll_base + RCC_OFFSET_PLLXCFGR1, value); 1199e5e793a6SGabriel Fernandez 1200e5e793a6SGabriel Fernandez /* Fractional configuration */ 1201e5e793a6SGabriel Fernandez io_write32(pll_base + RCC_OFFSET_PLLXFRACR, 0); 1202e5e793a6SGabriel Fernandez 1203e5e793a6SGabriel Fernandez /* Frac must be enabled only once its configuration is loaded */ 1204e5e793a6SGabriel Fernandez io_write32(pll_base + RCC_OFFSET_PLLXFRACR, 1205e5e793a6SGabriel Fernandez vco->frac << RCC_PLLNFRACR_FRACV_SHIFT); 1206e5e793a6SGabriel Fernandez 1207e5e793a6SGabriel Fernandez io_setbits32(pll_base + RCC_OFFSET_PLLXFRACR, RCC_PLLNFRACR_FRACLE); 1208e5e793a6SGabriel Fernandez } 1209e5e793a6SGabriel Fernandez 1210e5e793a6SGabriel Fernandez static void clk_stm32_pll_config_csg(struct clk_stm32_priv *priv, 1211e5e793a6SGabriel Fernandez const struct stm32_clk_pll *pll, 1212e5e793a6SGabriel Fernandez struct stm32_pll_vco *vco) 1213e5e793a6SGabriel Fernandez { 1214e5e793a6SGabriel Fernandez uintptr_t pll_base = priv->base + pll->reg_pllxcr; 1215e5e793a6SGabriel Fernandez uint32_t mod_per = 0; 1216e5e793a6SGabriel Fernandez uint32_t inc_step = 0; 1217e5e793a6SGabriel Fernandez uint32_t sscg_mode = 0; 1218e5e793a6SGabriel Fernandez uint32_t value = 0; 1219e5e793a6SGabriel Fernandez 1220e5e793a6SGabriel Fernandez if (!vco->csg_enabled) 1221e5e793a6SGabriel Fernandez return; 1222e5e793a6SGabriel Fernandez 1223e5e793a6SGabriel Fernandez mod_per = vco->csg[PLL_CSG_MOD_PER]; 1224e5e793a6SGabriel Fernandez inc_step = vco->csg[PLL_CSG_INC_STEP]; 1225e5e793a6SGabriel Fernandez sscg_mode = vco->csg[PLL_CSG_SSCG_MODE]; 1226e5e793a6SGabriel Fernandez 1227e5e793a6SGabriel Fernandez value |= (mod_per << RCC_PLLNCSGR_MOD_PER_SHIFT) & 1228e5e793a6SGabriel Fernandez RCC_PLLNCSGR_MOD_PER_MASK; 1229e5e793a6SGabriel Fernandez value |= (inc_step << RCC_PLLNCSGR_INC_STEP_SHIFT) & 1230e5e793a6SGabriel Fernandez RCC_PLLNCSGR_INC_STEP_MASK; 1231e5e793a6SGabriel Fernandez value |= (sscg_mode << RCC_PLLNCSGR_SSCG_MODE_SHIFT) & 1232e5e793a6SGabriel Fernandez RCC_PLLNCSGR_SSCG_MODE_MASK; 1233e5e793a6SGabriel Fernandez 1234e5e793a6SGabriel Fernandez io_write32(pll_base + RCC_OFFSET_PLLXCSGR, value); 1235e5e793a6SGabriel Fernandez io_setbits32(pll_base + RCC_OFFSET_PLLXCR, RCC_PLLNCR_SSCG_CTRL); 1236e5e793a6SGabriel Fernandez } 1237e5e793a6SGabriel Fernandez 1238e5e793a6SGabriel Fernandez static void clk_stm32_pll_config_out(struct clk_stm32_priv *priv, 1239e5e793a6SGabriel Fernandez const struct stm32_clk_pll *pll, 1240e5e793a6SGabriel Fernandez struct stm32_pll_output *out) 1241e5e793a6SGabriel Fernandez { 1242e5e793a6SGabriel Fernandez uintptr_t pll_base = priv->base + pll->reg_pllxcr; 1243e5e793a6SGabriel Fernandez uint32_t value = 0; 1244e5e793a6SGabriel Fernandez 1245e5e793a6SGabriel Fernandez value = clk_stm32_pll_compute_cfgr2(out); 1246e5e793a6SGabriel Fernandez 1247e5e793a6SGabriel Fernandez io_write32(pll_base + RCC_OFFSET_PLLXCFGR2, value); 1248e5e793a6SGabriel Fernandez } 1249e5e793a6SGabriel Fernandez 1250e5e793a6SGabriel Fernandez static struct stm32_pll_dt_cfg *clk_stm32_pll_get_pdata(int pll_idx) 1251e5e793a6SGabriel Fernandez { 1252e5e793a6SGabriel Fernandez struct clk_stm32_priv *priv = clk_stm32_get_priv(); 1253e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata = priv->pdata; 1254e5e793a6SGabriel Fernandez 1255e5e793a6SGabriel Fernandez return &pdata->pll[pll_idx]; 1256e5e793a6SGabriel Fernandez } 1257e5e793a6SGabriel Fernandez 1258e5e793a6SGabriel Fernandez static int clk_stm32_pll_init_switch_to_hsi_clk_system(int mux_sys) 1259e5e793a6SGabriel Fernandez { 1260e5e793a6SGabriel Fernandez int sel = 0; 1261e5e793a6SGabriel Fernandez 1262e5e793a6SGabriel Fernandez if (mux_sys == -1) 1263e5e793a6SGabriel Fernandez return -1; 1264e5e793a6SGabriel Fernandez 1265e5e793a6SGabriel Fernandez /* Make a backup to the current parent */ 1266e5e793a6SGabriel Fernandez sel = stm32_mux_get_parent(mux_sys); 1267e5e793a6SGabriel Fernandez 1268e5e793a6SGabriel Fernandez /* Switch to HSI */ 1269e5e793a6SGabriel Fernandez if (stm32_mux_set_parent(mux_sys, 0)) 1270e5e793a6SGabriel Fernandez return -1; 1271e5e793a6SGabriel Fernandez 1272e5e793a6SGabriel Fernandez return sel; 1273e5e793a6SGabriel Fernandez } 1274e5e793a6SGabriel Fernandez 1275e5e793a6SGabriel Fernandez static uint32_t 1276e5e793a6SGabriel Fernandez clk_stm32_pll_backup_output_diven(const struct stm32_clk_pll *pll) 1277e5e793a6SGabriel Fernandez { 1278e5e793a6SGabriel Fernandez struct clk_stm32_priv *priv = clk_stm32_get_priv(); 1279e5e793a6SGabriel Fernandez uintptr_t addr = priv->base + pll->reg_pllxcr; 1280e5e793a6SGabriel Fernandez 1281e5e793a6SGabriel Fernandez return io_read32(addr + RCC_OFFSET_PLLXCR) & 1282e5e793a6SGabriel Fernandez (RCC_PLLNCR_DIVPEN | RCC_PLLNCR_DIVQEN | 1283e5e793a6SGabriel Fernandez RCC_PLLNCR_DIVREN); 1284e5e793a6SGabriel Fernandez } 1285e5e793a6SGabriel Fernandez 1286e5e793a6SGabriel Fernandez static void clk_stm32_pll_restore_output_diven(const struct stm32_clk_pll *pll, 1287e5e793a6SGabriel Fernandez uint32_t value) 1288e5e793a6SGabriel Fernandez { 1289e5e793a6SGabriel Fernandez struct clk_stm32_priv *priv = clk_stm32_get_priv(); 1290e5e793a6SGabriel Fernandez uintptr_t addr = priv->base + pll->reg_pllxcr; 1291e5e793a6SGabriel Fernandez const uint32_t mask = RCC_PLLNCR_DIVPEN | RCC_PLLNCR_DIVQEN | 1292e5e793a6SGabriel Fernandez RCC_PLLNCR_DIVREN; 1293e5e793a6SGabriel Fernandez 1294e5e793a6SGabriel Fernandez io_clrsetbits32(addr, mask, value & mask); 1295e5e793a6SGabriel Fernandez } 1296e5e793a6SGabriel Fernandez 1297e5e793a6SGabriel Fernandez static int clk_stm32_pll_init(struct clk_stm32_priv *priv, int pll_idx, 1298e5e793a6SGabriel Fernandez struct stm32_pll_dt_cfg *pll_conf) 1299e5e793a6SGabriel Fernandez { 1300e5e793a6SGabriel Fernandez const struct stm32_clk_pll *pll = clk_stm32_pll_data(pll_idx); 1301e5e793a6SGabriel Fernandez int config_on_the_fly = -1; 1302e5e793a6SGabriel Fernandez int ret = 0; 1303e5e793a6SGabriel Fernandez uint8_t sel = 0; 1304e5e793a6SGabriel Fernandez uint32_t save_div_pqr_en = 0; 1305e5e793a6SGabriel Fernandez int mux_system[] = { MUX_MPU, MUX_AXI, MUX_MLAHB, -1 }; 1306e5e793a6SGabriel Fernandez int mux_sys = mux_system[pll_idx]; 1307e5e793a6SGabriel Fernandez 1308e5e793a6SGabriel Fernandez ret = clk_stm32_is_pll_config_on_the_fly(priv, pll, pll_conf, 1309e5e793a6SGabriel Fernandez &config_on_the_fly); 1310e5e793a6SGabriel Fernandez if (ret != 0) 1311e5e793a6SGabriel Fernandez return ret; 1312e5e793a6SGabriel Fernandez 1313e5e793a6SGabriel Fernandez /* Backup status of DIV DIVPEN / DIVQEN / DIVREN */ 1314e5e793a6SGabriel Fernandez save_div_pqr_en = clk_stm32_pll_backup_output_diven(pll); 1315e5e793a6SGabriel Fernandez 1316e5e793a6SGabriel Fernandez if (config_on_the_fly == -1) { 1317e5e793a6SGabriel Fernandez /* Make a backup to the current parent and switch to HSI */ 1318e5e793a6SGabriel Fernandez sel = clk_stm32_pll_init_switch_to_hsi_clk_system(mux_sys); 1319e5e793a6SGabriel Fernandez 1320e5e793a6SGabriel Fernandez /* Stop the PLL before */ 1321e5e793a6SGabriel Fernandez if (stm32_gate_is_enabled(pll->gate_id)) { 1322e5e793a6SGabriel Fernandez io_clrbits32(priv->base + pll->reg_pllxcr, 1323e5e793a6SGabriel Fernandez RCC_PLLNCR_DIVPEN | RCC_PLLNCR_DIVQEN | 1324e5e793a6SGabriel Fernandez RCC_PLLNCR_DIVREN); 1325e5e793a6SGabriel Fernandez 1326e5e793a6SGabriel Fernandez if (stm32_gate_rdy_disable(pll->gate_id)) 1327e5e793a6SGabriel Fernandez return -1; 1328e5e793a6SGabriel Fernandez } 1329e5e793a6SGabriel Fernandez 1330e5e793a6SGabriel Fernandez /* Configure PLLs source */ 1331e5e793a6SGabriel Fernandez ret = stm32_clk_configure_mux(priv, pll_conf->vco.src); 1332e5e793a6SGabriel Fernandez if (ret) 1333e5e793a6SGabriel Fernandez return ret; 1334e5e793a6SGabriel Fernandez 1335e5e793a6SGabriel Fernandez clk_stm32_pll_config_vco(priv, pll, &pll_conf->vco); 1336e5e793a6SGabriel Fernandez } 1337e5e793a6SGabriel Fernandez 1338e5e793a6SGabriel Fernandez if (config_on_the_fly != 1) { 1339e5e793a6SGabriel Fernandez clk_stm32_pll_config_out(priv, pll, &pll_conf->output); 1340e5e793a6SGabriel Fernandez clk_stm32_pll_config_csg(priv, pll, &pll_conf->vco); 1341e5e793a6SGabriel Fernandez } 1342e5e793a6SGabriel Fernandez 1343e5e793a6SGabriel Fernandez if (!stm32_gate_is_enabled(pll->gate_id)) { 1344e5e793a6SGabriel Fernandez if (stm32_gate_rdy_enable(pll->gate_id)) 1345e5e793a6SGabriel Fernandez return -1; 1346e5e793a6SGabriel Fernandez 1347e5e793a6SGabriel Fernandez clk_stm32_pll_restore_output_diven(pll, save_div_pqr_en); 1348e5e793a6SGabriel Fernandez } 1349e5e793a6SGabriel Fernandez 1350e5e793a6SGabriel Fernandez if ((config_on_the_fly == -1) && (mux_sys != -1)) { 1351e5e793a6SGabriel Fernandez /* Restore to backup parent */ 1352e5e793a6SGabriel Fernandez if (stm32_mux_set_parent(mux_sys, sel)) 1353e5e793a6SGabriel Fernandez return -1; 1354e5e793a6SGabriel Fernandez } 1355e5e793a6SGabriel Fernandez 1356e5e793a6SGabriel Fernandez return 0; 1357e5e793a6SGabriel Fernandez } 1358e5e793a6SGabriel Fernandez 1359e5e793a6SGabriel Fernandez static int stm32_clk_pll_configure(struct clk_stm32_priv *priv) 1360e5e793a6SGabriel Fernandez { 1361e5e793a6SGabriel Fernandez struct stm32_pll_dt_cfg *pll_conf = NULL; 1362e5e793a6SGabriel Fernandez size_t i = 0; 1363e5e793a6SGabriel Fernandez const int plls[] = { PLL1_ID, PLL3_ID, PLL4_ID }; 1364e5e793a6SGabriel Fernandez 1365e5e793a6SGabriel Fernandez for (i = 0; i < ARRAY_SIZE(plls); i++) { 1366e5e793a6SGabriel Fernandez pll_conf = clk_stm32_pll_get_pdata(plls[i]); 1367e5e793a6SGabriel Fernandez 1368e5e793a6SGabriel Fernandez if (pll_conf->vco.status) { 1369e5e793a6SGabriel Fernandez int err = 0; 1370e5e793a6SGabriel Fernandez 1371e5e793a6SGabriel Fernandez err = clk_stm32_pll_init(priv, plls[i], pll_conf); 1372e5e793a6SGabriel Fernandez if (err) 1373e5e793a6SGabriel Fernandez return err; 1374e5e793a6SGabriel Fernandez } 1375e5e793a6SGabriel Fernandez } 1376e5e793a6SGabriel Fernandez 1377e5e793a6SGabriel Fernandez return 0; 1378e5e793a6SGabriel Fernandez } 1379e5e793a6SGabriel Fernandez 1380e5e793a6SGabriel Fernandez static int stm32mp1_init_clock_tree(struct clk_stm32_priv *priv, 1381e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata) 1382e5e793a6SGabriel Fernandez { 1383e5e793a6SGabriel Fernandez int ret = 0; 1384e5e793a6SGabriel Fernandez 1385e5e793a6SGabriel Fernandez /* 1386e5e793a6SGabriel Fernandez * Switch ON oscillators found in device-tree. 1387e5e793a6SGabriel Fernandez * Note: HSI already ON after BootROM stage. 1388e5e793a6SGabriel Fernandez */ 1389e5e793a6SGabriel Fernandez stm32_clk_oscillators_enable(priv, pdata); 1390e5e793a6SGabriel Fernandez 1391e5e793a6SGabriel Fernandez ret = stm32_clk_hsidiv_configure(priv); 1392e5e793a6SGabriel Fernandez if (ret != 0) 1393e5e793a6SGabriel Fernandez return ret; 1394e5e793a6SGabriel Fernandez 1395e5e793a6SGabriel Fernandez ret = stm32_clk_dividers_configure(priv); 1396e5e793a6SGabriel Fernandez if (ret != 0) 1397e5e793a6SGabriel Fernandez panic(); 1398e5e793a6SGabriel Fernandez 1399e5e793a6SGabriel Fernandez ret = stm32_clk_pll_configure(priv); 1400e5e793a6SGabriel Fernandez if (ret != 0) 1401e5e793a6SGabriel Fernandez panic(); 1402e5e793a6SGabriel Fernandez 1403e5e793a6SGabriel Fernandez /* Wait LSE ready before to use it */ 1404e5e793a6SGabriel Fernandez ret = stm32_clk_oscillators_wait_lse_ready(priv, pdata); 1405e5e793a6SGabriel Fernandez if (ret != 0) 1406e5e793a6SGabriel Fernandez panic(); 1407e5e793a6SGabriel Fernandez 1408e5e793a6SGabriel Fernandez /* Configure with expected clock source */ 1409e5e793a6SGabriel Fernandez ret = stm32_clk_source_configure(priv); 1410e5e793a6SGabriel Fernandez if (ret != 0) 1411e5e793a6SGabriel Fernandez panic(); 1412e5e793a6SGabriel Fernandez 1413e5e793a6SGabriel Fernandez /* Configure LSE CSS after RTC source configuration */ 1414e5e793a6SGabriel Fernandez ret = stm32_clk_oscillators_lse_set_css(priv, pdata); 1415e5e793a6SGabriel Fernandez if (ret != 0) 1416e5e793a6SGabriel Fernandez panic(); 1417e5e793a6SGabriel Fernandez 1418e5e793a6SGabriel Fernandez /* Software Self-Refresh mode (SSR) during DDR initilialization */ 1419e5e793a6SGabriel Fernandez io_clrsetbits32(priv->base + RCC_DDRITFCR, RCC_DDRITFCR_DDRCKMOD_MASK, 1420e5e793a6SGabriel Fernandez RCC_DDRITFCR_DDRCKMOD_SSR << 1421e5e793a6SGabriel Fernandez RCC_DDRITFCR_DDRCKMOD_SHIFT); 1422e5e793a6SGabriel Fernandez 1423e5e793a6SGabriel Fernandez return 0; 1424e5e793a6SGabriel Fernandez } 1425e5e793a6SGabriel Fernandez 1426e5e793a6SGabriel Fernandez static int clk_stm32_parse_oscillator_fdt(const void *fdt, int node, 1427e5e793a6SGabriel Fernandez const char *name, 1428e5e793a6SGabriel Fernandez struct stm32_osci_dt_cfg *osci) 1429e5e793a6SGabriel Fernandez { 1430e5e793a6SGabriel Fernandez int subnode = 0; 1431e5e793a6SGabriel Fernandez 1432e5e793a6SGabriel Fernandez fdt_for_each_subnode(subnode, fdt, node) { 1433e5e793a6SGabriel Fernandez const char *cchar = NULL; 1434e5e793a6SGabriel Fernandez const fdt32_t *cuint = NULL; 1435e5e793a6SGabriel Fernandez int ret = 0; 1436e5e793a6SGabriel Fernandez 1437e5e793a6SGabriel Fernandez cchar = fdt_get_name(fdt, subnode, &ret); 1438e5e793a6SGabriel Fernandez if (!cchar) 1439e5e793a6SGabriel Fernandez return ret; 1440e5e793a6SGabriel Fernandez 1441e5e793a6SGabriel Fernandez if (strncmp(cchar, name, (size_t)ret) || 1442e5e793a6SGabriel Fernandez _fdt_get_status(fdt, subnode) == DT_STATUS_DISABLED) 1443e5e793a6SGabriel Fernandez continue; 1444e5e793a6SGabriel Fernandez 1445e5e793a6SGabriel Fernandez cuint = fdt_getprop(fdt, subnode, "clock-frequency", &ret); 1446e5e793a6SGabriel Fernandez if (!cuint) 1447e5e793a6SGabriel Fernandez panic(); 1448e5e793a6SGabriel Fernandez 1449e5e793a6SGabriel Fernandez osci->freq = fdt32_to_cpu(*cuint); 1450e5e793a6SGabriel Fernandez 1451e5e793a6SGabriel Fernandez if (fdt_getprop(fdt, subnode, "st,bypass", NULL)) 1452e5e793a6SGabriel Fernandez osci->bypass = true; 1453e5e793a6SGabriel Fernandez 1454e5e793a6SGabriel Fernandez if (fdt_getprop(fdt, subnode, "st,digbypass", NULL)) 1455e5e793a6SGabriel Fernandez osci->digbyp = true; 1456e5e793a6SGabriel Fernandez 1457e5e793a6SGabriel Fernandez if (fdt_getprop(fdt, subnode, "st,css", NULL)) 1458e5e793a6SGabriel Fernandez osci->css = true; 1459e5e793a6SGabriel Fernandez 1460e5e793a6SGabriel Fernandez osci->drive = _fdt_read_uint32_default(fdt, subnode, "st,drive", 1461e5e793a6SGabriel Fernandez LSEDRV_MEDIUM_HIGH); 1462e5e793a6SGabriel Fernandez 1463e5e793a6SGabriel Fernandez return 0; 1464e5e793a6SGabriel Fernandez } 1465e5e793a6SGabriel Fernandez 1466e5e793a6SGabriel Fernandez return -FDT_ERR_NOTFOUND; 1467e5e793a6SGabriel Fernandez } 1468e5e793a6SGabriel Fernandez 1469e5e793a6SGabriel Fernandez static int stm32_clk_parse_fdt_all_oscillator(const void *fdt, 1470e5e793a6SGabriel Fernandez int node __maybe_unused, 1471e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata) 1472e5e793a6SGabriel Fernandez { 1473e5e793a6SGabriel Fernandez int fdt_err = 0; 1474e5e793a6SGabriel Fernandez size_t i = 0; 1475e5e793a6SGabriel Fernandez int osc_node = 0; 1476e5e793a6SGabriel Fernandez 1477e5e793a6SGabriel Fernandez osc_node = fdt_path_offset(fdt, "/clocks"); 1478e5e793a6SGabriel Fernandez if (osc_node < 0) 1479e5e793a6SGabriel Fernandez return -FDT_ERR_NOTFOUND; 1480e5e793a6SGabriel Fernandez 1481e5e793a6SGabriel Fernandez for (i = 0; i < NB_OSCILLATOR; i++) { 1482e5e793a6SGabriel Fernandez struct stm32_osci_dt_cfg *osci = &pdata->osci[i]; 1483e5e793a6SGabriel Fernandez struct clk_oscillator_data *osc_data = NULL; 1484e5e793a6SGabriel Fernandez 1485e5e793a6SGabriel Fernandez osc_data = clk_oscillator_get_data(i); 1486e5e793a6SGabriel Fernandez 1487e5e793a6SGabriel Fernandez fdt_err = clk_stm32_parse_oscillator_fdt(fdt, osc_node, 1488e5e793a6SGabriel Fernandez osc_data->name, osci); 1489e5e793a6SGabriel Fernandez if (fdt_err < 0) 1490e5e793a6SGabriel Fernandez panic(); 1491e5e793a6SGabriel Fernandez } 1492e5e793a6SGabriel Fernandez 1493e5e793a6SGabriel Fernandez return 0; 1494e5e793a6SGabriel Fernandez } 1495e5e793a6SGabriel Fernandez 1496e5e793a6SGabriel Fernandez static int clk_stm32_load_vco_config_fdt(const void *fdt, int subnode, 1497e5e793a6SGabriel Fernandez struct stm32_pll_vco *vco) 1498e5e793a6SGabriel Fernandez { 1499e5e793a6SGabriel Fernandez int ret = 0; 1500e5e793a6SGabriel Fernandez 1501e5e793a6SGabriel Fernandez ret = _fdt_read_uint32_array(fdt, subnode, "divmn", vco->div_mn, 1502e5e793a6SGabriel Fernandez PLL_DIV_MN_NB); 1503e5e793a6SGabriel Fernandez if (ret != 0) 1504e5e793a6SGabriel Fernandez return ret; 1505e5e793a6SGabriel Fernandez 1506e5e793a6SGabriel Fernandez ret = _fdt_read_uint32_array(fdt, subnode, "csg", vco->csg, 1507e5e793a6SGabriel Fernandez PLL_CSG_NB); 1508e5e793a6SGabriel Fernandez 1509e5e793a6SGabriel Fernandez vco->csg_enabled = (ret == 0); 1510e5e793a6SGabriel Fernandez 1511e5e793a6SGabriel Fernandez if (ret == -FDT_ERR_NOTFOUND) 1512e5e793a6SGabriel Fernandez ret = 0; 1513e5e793a6SGabriel Fernandez 1514e5e793a6SGabriel Fernandez if (ret != 0) 1515e5e793a6SGabriel Fernandez return ret; 1516e5e793a6SGabriel Fernandez 1517e5e793a6SGabriel Fernandez vco->status = RCC_PLLNCR_DIVPEN | RCC_PLLNCR_DIVQEN | 1518e5e793a6SGabriel Fernandez RCC_PLLNCR_DIVREN | RCC_PLLNCR_PLLON; 1519e5e793a6SGabriel Fernandez 1520e5e793a6SGabriel Fernandez vco->frac = _fdt_read_uint32_default(fdt, subnode, "frac", 0); 1521e5e793a6SGabriel Fernandez 1522e5e793a6SGabriel Fernandez vco->src = _fdt_read_uint32_default(fdt, subnode, "src", UINT32_MAX); 1523e5e793a6SGabriel Fernandez 1524e5e793a6SGabriel Fernandez return 0; 1525e5e793a6SGabriel Fernandez } 1526e5e793a6SGabriel Fernandez 1527e5e793a6SGabriel Fernandez static int clk_stm32_load_output_config_fdt(const void *fdt, int subnode, 1528e5e793a6SGabriel Fernandez struct stm32_pll_output *output) 1529e5e793a6SGabriel Fernandez { 1530e5e793a6SGabriel Fernandez return _fdt_read_uint32_array(fdt, subnode, "st,pll_div_pqr", 1531e5e793a6SGabriel Fernandez output->output, (int)PLL_DIV_PQR_NB); 1532e5e793a6SGabriel Fernandez } 1533e5e793a6SGabriel Fernandez 1534e5e793a6SGabriel Fernandez static int clk_stm32_parse_pll_fdt(const void *fdt, int subnode, 1535e5e793a6SGabriel Fernandez struct stm32_pll_dt_cfg *pll) 1536e5e793a6SGabriel Fernandez { 1537e5e793a6SGabriel Fernandez const fdt32_t *cuint = NULL; 1538e5e793a6SGabriel Fernandez int subnode_pll = 0; 1539e5e793a6SGabriel Fernandez int subnode_vco = 0; 1540e5e793a6SGabriel Fernandez int err = 0; 1541e5e793a6SGabriel Fernandez 1542e5e793a6SGabriel Fernandez cuint = fdt_getprop(fdt, subnode, "st,pll", NULL); 1543e5e793a6SGabriel Fernandez if (!cuint) 1544e5e793a6SGabriel Fernandez return -FDT_ERR_NOTFOUND; 1545e5e793a6SGabriel Fernandez 1546e5e793a6SGabriel Fernandez subnode_pll = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(*cuint)); 1547e5e793a6SGabriel Fernandez if (subnode_pll < 0) 1548e5e793a6SGabriel Fernandez return -FDT_ERR_NOTFOUND; 1549e5e793a6SGabriel Fernandez 1550e5e793a6SGabriel Fernandez cuint = fdt_getprop(fdt, subnode_pll, "st,pll_vco", NULL); 1551e5e793a6SGabriel Fernandez if (!cuint) 1552e5e793a6SGabriel Fernandez return -FDT_ERR_NOTFOUND; 1553e5e793a6SGabriel Fernandez 1554e5e793a6SGabriel Fernandez subnode_vco = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(*cuint)); 1555e5e793a6SGabriel Fernandez if (subnode_vco < 0) 1556e5e793a6SGabriel Fernandez return -FDT_ERR_NOTFOUND; 1557e5e793a6SGabriel Fernandez 1558e5e793a6SGabriel Fernandez err = clk_stm32_load_vco_config_fdt(fdt, subnode_vco, &pll->vco); 1559e5e793a6SGabriel Fernandez if (err != 0) 1560e5e793a6SGabriel Fernandez return err; 1561e5e793a6SGabriel Fernandez 1562e5e793a6SGabriel Fernandez err = clk_stm32_load_output_config_fdt(fdt, subnode_pll, &pll->output); 1563e5e793a6SGabriel Fernandez if (err != 0) 1564e5e793a6SGabriel Fernandez return err; 1565e5e793a6SGabriel Fernandez 1566e5e793a6SGabriel Fernandez return 0; 1567e5e793a6SGabriel Fernandez } 1568e5e793a6SGabriel Fernandez 1569e5e793a6SGabriel Fernandez static int stm32_clk_parse_fdt_all_pll(const void *fdt, int node, 1570e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata) 1571e5e793a6SGabriel Fernandez { 1572e5e793a6SGabriel Fernandez size_t i = 0; 1573e5e793a6SGabriel Fernandez 1574e5e793a6SGabriel Fernandez for (i = PLL1_ID; i < pdata->npll; i++) { 1575e5e793a6SGabriel Fernandez struct stm32_pll_dt_cfg *pll = pdata->pll + i; 1576e5e793a6SGabriel Fernandez char name[RCC_PLL_NAME_SIZE] = { 0 }; 1577e5e793a6SGabriel Fernandez int subnode = 0; 1578e5e793a6SGabriel Fernandez int err = 0; 1579e5e793a6SGabriel Fernandez 1580e5e793a6SGabriel Fernandez snprintf(name, sizeof(name), "st,pll@%d", i); 1581e5e793a6SGabriel Fernandez 1582e5e793a6SGabriel Fernandez subnode = fdt_subnode_offset(fdt, node, name); 1583e5e793a6SGabriel Fernandez if (subnode < 0) 1584e5e793a6SGabriel Fernandez continue; 1585e5e793a6SGabriel Fernandez 1586e5e793a6SGabriel Fernandez err = clk_stm32_parse_pll_fdt(fdt, subnode, pll); 1587e5e793a6SGabriel Fernandez if (err != 0) 1588e5e793a6SGabriel Fernandez panic(); 1589e5e793a6SGabriel Fernandez } 1590e5e793a6SGabriel Fernandez 1591e5e793a6SGabriel Fernandez return 0; 1592e5e793a6SGabriel Fernandez } 1593e5e793a6SGabriel Fernandez 1594e5e793a6SGabriel Fernandez static int stm32_clk_parse_fdt_opp(const void *fdt, int node, 1595e5e793a6SGabriel Fernandez const char *opp_name, 1596e5e793a6SGabriel Fernandez struct stm32_clk_opp_cfg *opp_cfg) 1597e5e793a6SGabriel Fernandez { 1598e5e793a6SGabriel Fernandez int subnode = 0; 1599e5e793a6SGabriel Fernandez int nb_opp = 0; 1600e5e793a6SGabriel Fernandez int ret = 0; 1601e5e793a6SGabriel Fernandez 1602e5e793a6SGabriel Fernandez node = fdt_subnode_offset(fdt, node, opp_name); 1603e5e793a6SGabriel Fernandez if (node == -FDT_ERR_NOTFOUND) 1604e5e793a6SGabriel Fernandez return 0; 1605e5e793a6SGabriel Fernandez if (node < 0) 1606e5e793a6SGabriel Fernandez return node; 1607e5e793a6SGabriel Fernandez 1608e5e793a6SGabriel Fernandez fdt_for_each_subnode(subnode, fdt, node) { 1609e5e793a6SGabriel Fernandez if (nb_opp >= MAX_OPP) { 1610e5e793a6SGabriel Fernandez EMSG("%d MAX opp in %s", MAX_OPP, opp_name); 1611e5e793a6SGabriel Fernandez panic(); 1612e5e793a6SGabriel Fernandez } 1613e5e793a6SGabriel Fernandez 1614e5e793a6SGabriel Fernandez opp_cfg->frq = _fdt_read_uint32_default(fdt, subnode, 1615e5e793a6SGabriel Fernandez "hz", 1616e5e793a6SGabriel Fernandez UINT32_MAX); 1617e5e793a6SGabriel Fernandez 1618e5e793a6SGabriel Fernandez opp_cfg->src = _fdt_read_uint32_default(fdt, subnode, 1619e5e793a6SGabriel Fernandez "st,clksrc", 1620e5e793a6SGabriel Fernandez UINT32_MAX); 1621e5e793a6SGabriel Fernandez 1622e5e793a6SGabriel Fernandez opp_cfg->div = _fdt_read_uint32_default(fdt, subnode, 1623e5e793a6SGabriel Fernandez "st,clkdiv", 1624e5e793a6SGabriel Fernandez UINT32_MAX); 1625e5e793a6SGabriel Fernandez 1626e5e793a6SGabriel Fernandez ret = clk_stm32_parse_pll_fdt(fdt, subnode, &opp_cfg->pll_cfg); 1627e5e793a6SGabriel Fernandez if (ret) 1628e5e793a6SGabriel Fernandez return ret; 1629e5e793a6SGabriel Fernandez 1630e5e793a6SGabriel Fernandez opp_cfg++; 1631e5e793a6SGabriel Fernandez nb_opp++; 1632e5e793a6SGabriel Fernandez } 1633e5e793a6SGabriel Fernandez 1634e5e793a6SGabriel Fernandez return 0; 1635e5e793a6SGabriel Fernandez } 1636e5e793a6SGabriel Fernandez 1637e5e793a6SGabriel Fernandez static int stm32_clk_parse_fdt_all_opp(const void *fdt, int node, 1638e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata) 1639e5e793a6SGabriel Fernandez { 1640e5e793a6SGabriel Fernandez struct stm32_clk_opp_dt_cfg *opp = pdata->opp; 1641e5e793a6SGabriel Fernandez int ret = 0; 1642e5e793a6SGabriel Fernandez 1643e5e793a6SGabriel Fernandez node = fdt_subnode_offset(fdt, node, "st,clk_opp"); 1644e5e793a6SGabriel Fernandez /* No opp are defined */ 1645e5e793a6SGabriel Fernandez if (node == -FDT_ERR_NOTFOUND) 1646e5e793a6SGabriel Fernandez return 0; 1647e5e793a6SGabriel Fernandez if (node < 0) 1648e5e793a6SGabriel Fernandez return node; 1649e5e793a6SGabriel Fernandez 1650e5e793a6SGabriel Fernandez ret = stm32_clk_parse_fdt_opp(fdt, node, "st,ck_mpu", opp->mpu_opp); 1651e5e793a6SGabriel Fernandez if (ret) 1652e5e793a6SGabriel Fernandez return ret; 1653e5e793a6SGabriel Fernandez 1654e5e793a6SGabriel Fernandez ret = stm32_clk_parse_fdt_opp(fdt, node, "st,ck_axi", opp->axi_opp); 1655e5e793a6SGabriel Fernandez if (ret) 1656e5e793a6SGabriel Fernandez return ret; 1657e5e793a6SGabriel Fernandez 1658e5e793a6SGabriel Fernandez ret = stm32_clk_parse_fdt_opp(fdt, node, "st,ck_mlahbs", 1659e5e793a6SGabriel Fernandez opp->mlahbs_opp); 1660e5e793a6SGabriel Fernandez if (ret) 1661e5e793a6SGabriel Fernandez return ret; 1662e5e793a6SGabriel Fernandez 1663e5e793a6SGabriel Fernandez return 0; 1664e5e793a6SGabriel Fernandez } 1665e5e793a6SGabriel Fernandez 1666e5e793a6SGabriel Fernandez static int stm32_clk_parse_fdt(const void *fdt, int node, 1667e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata) 1668e5e793a6SGabriel Fernandez { 1669e5e793a6SGabriel Fernandez int err = 0; 1670e5e793a6SGabriel Fernandez 1671e5e793a6SGabriel Fernandez err = stm32_clk_parse_fdt_all_oscillator(fdt, node, pdata); 1672e5e793a6SGabriel Fernandez if (err != 0) 1673e5e793a6SGabriel Fernandez return err; 1674e5e793a6SGabriel Fernandez 1675e5e793a6SGabriel Fernandez err = stm32_clk_parse_fdt_all_pll(fdt, node, pdata); 1676e5e793a6SGabriel Fernandez if (err != 0) 1677e5e793a6SGabriel Fernandez return err; 1678e5e793a6SGabriel Fernandez 1679e5e793a6SGabriel Fernandez err = stm32_clk_parse_fdt_all_opp(fdt, node, pdata); 1680e5e793a6SGabriel Fernandez if (err != 0) 1681e5e793a6SGabriel Fernandez return err; 1682e5e793a6SGabriel Fernandez 1683e5e793a6SGabriel Fernandez err = clk_stm32_parse_fdt_by_name(fdt, node, "st,clkdiv", pdata->clkdiv, 1684e5e793a6SGabriel Fernandez &pdata->nclkdiv); 1685e5e793a6SGabriel Fernandez if (err != 0) 1686e5e793a6SGabriel Fernandez return err; 1687e5e793a6SGabriel Fernandez 1688e5e793a6SGabriel Fernandez err = clk_stm32_parse_fdt_by_name(fdt, node, "st,clksrc", pdata->clksrc, 1689e5e793a6SGabriel Fernandez &pdata->nclksrc); 1690e5e793a6SGabriel Fernandez if (err != 0) 1691e5e793a6SGabriel Fernandez return err; 1692e5e793a6SGabriel Fernandez 1693e5e793a6SGabriel Fernandez return 0; 1694e5e793a6SGabriel Fernandez } 1695e5e793a6SGabriel Fernandez 1696*5436921fSGabriel Fernandez struct clk_stm32_pll_cfg { 1697*5436921fSGabriel Fernandez uint32_t reg_pllxcr; 1698*5436921fSGabriel Fernandez int gate_id; 1699*5436921fSGabriel Fernandez int mux_id; 1700*5436921fSGabriel Fernandez }; 1701*5436921fSGabriel Fernandez 1702*5436921fSGabriel Fernandez static size_t clk_stm32_pll_get_parent(struct clk *clk) 1703*5436921fSGabriel Fernandez { 1704*5436921fSGabriel Fernandez struct clk_stm32_pll_cfg *cfg = clk->priv; 1705*5436921fSGabriel Fernandez 1706*5436921fSGabriel Fernandez return stm32_mux_get_parent(cfg->mux_id); 1707*5436921fSGabriel Fernandez } 1708*5436921fSGabriel Fernandez 1709*5436921fSGabriel Fernandez static unsigned long clk_stm32_pll_get_rate(struct clk *clk, 1710*5436921fSGabriel Fernandez unsigned long prate) 1711*5436921fSGabriel Fernandez { 1712*5436921fSGabriel Fernandez struct clk_stm32_priv *priv = clk_stm32_get_priv(); 1713*5436921fSGabriel Fernandez struct clk_stm32_pll_cfg *cfg = clk->priv; 1714*5436921fSGabriel Fernandez uintptr_t pll_base = priv->base + cfg->reg_pllxcr; 1715*5436921fSGabriel Fernandez uint32_t cfgr1 = 0; 1716*5436921fSGabriel Fernandez uint32_t fracr = 0; 1717*5436921fSGabriel Fernandez uint32_t divm = 0; 1718*5436921fSGabriel Fernandez uint32_t divn = 0; 1719*5436921fSGabriel Fernandez unsigned long fvco = 0UL; 1720*5436921fSGabriel Fernandez 1721*5436921fSGabriel Fernandez cfgr1 = io_read32(pll_base + RCC_OFFSET_PLLXCFGR1); 1722*5436921fSGabriel Fernandez fracr = io_read32(pll_base + RCC_OFFSET_PLLXFRACR); 1723*5436921fSGabriel Fernandez 1724*5436921fSGabriel Fernandez divm = (cfgr1 & (RCC_PLLNCFGR1_DIVM_MASK)) >> RCC_PLLNCFGR1_DIVM_SHIFT; 1725*5436921fSGabriel Fernandez divn = cfgr1 & RCC_PLLNCFGR1_DIVN_MASK; 1726*5436921fSGabriel Fernandez 1727*5436921fSGabriel Fernandez /* 1728*5436921fSGabriel Fernandez * With FRACV : 1729*5436921fSGabriel Fernandez * Fvco = Fck_ref * ((DIVN + 1) + FRACV / 2^13) / (DIVM + 1) 1730*5436921fSGabriel Fernandez * Without FRACV 1731*5436921fSGabriel Fernandez * Fvco = Fck_ref * ((DIVN + 1) / (DIVM + 1) 1732*5436921fSGabriel Fernandez */ 1733*5436921fSGabriel Fernandez if ((fracr & RCC_PLLNFRACR_FRACLE) != 0U) { 1734*5436921fSGabriel Fernandez uint32_t fracv = (fracr & RCC_PLLNFRACR_FRACV_MASK) >> 1735*5436921fSGabriel Fernandez RCC_PLLNFRACR_FRACV_SHIFT; 1736*5436921fSGabriel Fernandez unsigned long long numerator = 0UL; 1737*5436921fSGabriel Fernandez unsigned long long denominator = 0UL; 1738*5436921fSGabriel Fernandez 1739*5436921fSGabriel Fernandez numerator = (((unsigned long long)divn + 1U) << 13) + fracv; 1740*5436921fSGabriel Fernandez numerator = prate * numerator; 1741*5436921fSGabriel Fernandez denominator = ((unsigned long long)divm + 1U) << 13; 1742*5436921fSGabriel Fernandez fvco = (unsigned long)(numerator / denominator); 1743*5436921fSGabriel Fernandez } else { 1744*5436921fSGabriel Fernandez fvco = (unsigned long)(prate * (divn + 1U) / (divm + 1U)); 1745*5436921fSGabriel Fernandez } 1746*5436921fSGabriel Fernandez 1747*5436921fSGabriel Fernandez return fvco; 1748*5436921fSGabriel Fernandez }; 1749*5436921fSGabriel Fernandez 1750*5436921fSGabriel Fernandez static bool clk_stm32_pll_is_enabled(struct clk *clk) 1751*5436921fSGabriel Fernandez { 1752*5436921fSGabriel Fernandez struct clk_stm32_pll_cfg *cfg = clk->priv; 1753*5436921fSGabriel Fernandez 1754*5436921fSGabriel Fernandez return stm32_gate_is_enabled(cfg->gate_id); 1755*5436921fSGabriel Fernandez } 1756*5436921fSGabriel Fernandez 1757*5436921fSGabriel Fernandez static TEE_Result clk_stm32_pll_enable(struct clk *clk) 1758*5436921fSGabriel Fernandez { 1759*5436921fSGabriel Fernandez struct clk_stm32_pll_cfg *cfg = clk->priv; 1760*5436921fSGabriel Fernandez 1761*5436921fSGabriel Fernandez if (clk_stm32_pll_is_enabled(clk)) 1762*5436921fSGabriel Fernandez return TEE_SUCCESS; 1763*5436921fSGabriel Fernandez 1764*5436921fSGabriel Fernandez return stm32_gate_rdy_enable(cfg->gate_id); 1765*5436921fSGabriel Fernandez } 1766*5436921fSGabriel Fernandez 1767*5436921fSGabriel Fernandez static void clk_stm32_pll_disable(struct clk *clk) 1768*5436921fSGabriel Fernandez { 1769*5436921fSGabriel Fernandez struct clk_stm32_pll_cfg *cfg = clk->priv; 1770*5436921fSGabriel Fernandez struct clk_stm32_priv *priv = clk_stm32_get_priv(); 1771*5436921fSGabriel Fernandez uintptr_t pll_base = priv->base + cfg->reg_pllxcr; 1772*5436921fSGabriel Fernandez 1773*5436921fSGabriel Fernandez if (!clk_stm32_pll_is_enabled(clk)) 1774*5436921fSGabriel Fernandez return; 1775*5436921fSGabriel Fernandez 1776*5436921fSGabriel Fernandez /* Stop all output */ 1777*5436921fSGabriel Fernandez io_clrbits32(pll_base, RCC_PLLNCR_DIVPEN | RCC_PLLNCR_DIVQEN | 1778*5436921fSGabriel Fernandez RCC_PLLNCR_DIVREN); 1779*5436921fSGabriel Fernandez 1780*5436921fSGabriel Fernandez stm32_gate_rdy_disable(cfg->gate_id); 1781*5436921fSGabriel Fernandez } 1782*5436921fSGabriel Fernandez 1783*5436921fSGabriel Fernandez static const struct clk_ops clk_stm32_pll_ops = { 1784*5436921fSGabriel Fernandez .get_parent = clk_stm32_pll_get_parent, 1785*5436921fSGabriel Fernandez .get_rate = clk_stm32_pll_get_rate, 1786*5436921fSGabriel Fernandez .enable = clk_stm32_pll_enable, 1787*5436921fSGabriel Fernandez .disable = clk_stm32_pll_disable, 1788*5436921fSGabriel Fernandez }; 1789*5436921fSGabriel Fernandez 1790*5436921fSGabriel Fernandez static struct 1791*5436921fSGabriel Fernandez stm32_clk_opp_cfg *clk_stm32_get_opp_config(struct stm32_clk_opp_cfg *opp_cfg, 1792*5436921fSGabriel Fernandez unsigned long rate) 1793*5436921fSGabriel Fernandez { 1794*5436921fSGabriel Fernandez unsigned int i = 0; 1795*5436921fSGabriel Fernandez 1796*5436921fSGabriel Fernandez for (i = 0; i < MAX_OPP; i++, opp_cfg++) { 1797*5436921fSGabriel Fernandez if (opp_cfg->frq == 0UL) 1798*5436921fSGabriel Fernandez break; 1799*5436921fSGabriel Fernandez 1800*5436921fSGabriel Fernandez if (opp_cfg->frq == rate) 1801*5436921fSGabriel Fernandez return opp_cfg; 1802*5436921fSGabriel Fernandez } 1803*5436921fSGabriel Fernandez 1804*5436921fSGabriel Fernandez return NULL; 1805*5436921fSGabriel Fernandez } 1806*5436921fSGabriel Fernandez 1807*5436921fSGabriel Fernandez static TEE_Result clk_stm32_pll1_set_rate(struct clk *clk __maybe_unused, 1808*5436921fSGabriel Fernandez unsigned long rate, 1809*5436921fSGabriel Fernandez unsigned long prate __maybe_unused) 1810*5436921fSGabriel Fernandez { 1811*5436921fSGabriel Fernandez const struct stm32_clk_pll *pll = clk_stm32_pll_data(PLL1_ID); 1812*5436921fSGabriel Fernandez struct clk_stm32_priv *priv = clk_stm32_get_priv(); 1813*5436921fSGabriel Fernandez struct stm32_clk_platdata *pdata = priv->pdata; 1814*5436921fSGabriel Fernandez struct stm32_pll_dt_cfg *pll_conf = NULL; 1815*5436921fSGabriel Fernandez struct stm32_clk_opp_cfg *opp = NULL; 1816*5436921fSGabriel Fernandez int config_on_the_fly = -1; 1817*5436921fSGabriel Fernandez int err = 0; 1818*5436921fSGabriel Fernandez size_t sel = stm32_mux_get_parent(MUX_MPU); 1819*5436921fSGabriel Fernandez 1820*5436921fSGabriel Fernandez opp = clk_stm32_get_opp_config(pdata->opp->mpu_opp, rate); 1821*5436921fSGabriel Fernandez if (!opp) 1822*5436921fSGabriel Fernandez return TEE_ERROR_GENERIC; 1823*5436921fSGabriel Fernandez 1824*5436921fSGabriel Fernandez pll_conf = &opp->pll_cfg; 1825*5436921fSGabriel Fernandez 1826*5436921fSGabriel Fernandez err = clk_stm32_is_pll_config_on_the_fly(priv, pll, pll_conf, 1827*5436921fSGabriel Fernandez &config_on_the_fly); 1828*5436921fSGabriel Fernandez if (err) 1829*5436921fSGabriel Fernandez return TEE_ERROR_GENERIC; 1830*5436921fSGabriel Fernandez 1831*5436921fSGabriel Fernandez if (config_on_the_fly == 1) 1832*5436921fSGabriel Fernandez return TEE_SUCCESS; 1833*5436921fSGabriel Fernandez 1834*5436921fSGabriel Fernandez if (config_on_the_fly == -1) { 1835*5436921fSGabriel Fernandez /* Switch to HSI and stop PLL1 before reconfiguration */ 1836*5436921fSGabriel Fernandez if (stm32_mux_set_parent(MUX_MPU, 0)) 1837*5436921fSGabriel Fernandez return TEE_ERROR_GENERIC; 1838*5436921fSGabriel Fernandez 1839*5436921fSGabriel Fernandez stm32_gate_disable(GATE_PLL1_DIVP); 1840*5436921fSGabriel Fernandez stm32_gate_rdy_disable(GATE_PLL1); 1841*5436921fSGabriel Fernandez clk_stm32_pll_config_vco(priv, pll, &pll_conf->vco); 1842*5436921fSGabriel Fernandez } 1843*5436921fSGabriel Fernandez 1844*5436921fSGabriel Fernandez clk_stm32_pll_config_out(priv, pll, &pll_conf->output); 1845*5436921fSGabriel Fernandez if (stm32_gate_rdy_enable(GATE_PLL1)) { 1846*5436921fSGabriel Fernandez EMSG("timeout to enable PLL1 clock"); 1847*5436921fSGabriel Fernandez panic(); 1848*5436921fSGabriel Fernandez } 1849*5436921fSGabriel Fernandez stm32_gate_enable(GATE_PLL1_DIVP); 1850*5436921fSGabriel Fernandez 1851*5436921fSGabriel Fernandez /* Restore MPU source */ 1852*5436921fSGabriel Fernandez if (stm32_mux_set_parent(MUX_MPU, sel)) 1853*5436921fSGabriel Fernandez return TEE_ERROR_GENERIC; 1854*5436921fSGabriel Fernandez 1855*5436921fSGabriel Fernandez return TEE_SUCCESS; 1856*5436921fSGabriel Fernandez } 1857*5436921fSGabriel Fernandez 1858*5436921fSGabriel Fernandez static const struct clk_ops clk_stm32_pll1_ops = { 1859*5436921fSGabriel Fernandez .set_rate = clk_stm32_pll1_set_rate, 1860*5436921fSGabriel Fernandez .get_parent = clk_stm32_pll_get_parent, 1861*5436921fSGabriel Fernandez .get_rate = clk_stm32_pll_get_rate, 1862*5436921fSGabriel Fernandez .enable = clk_stm32_pll_enable, 1863*5436921fSGabriel Fernandez .disable = clk_stm32_pll_disable, 1864*5436921fSGabriel Fernandez }; 1865*5436921fSGabriel Fernandez 1866*5436921fSGabriel Fernandez static const struct clk_ops clk_stm32_pll1p_ops = { 1867*5436921fSGabriel Fernandez .get_rate = clk_stm32_composite_get_rate, 1868*5436921fSGabriel Fernandez .enable = clk_stm32_composite_gate_enable, 1869*5436921fSGabriel Fernandez .disable = clk_stm32_composite_gate_disable, 1870*5436921fSGabriel Fernandez }; 1871*5436921fSGabriel Fernandez 1872*5436921fSGabriel Fernandez static const struct clk_ops clk_stm32_mpu_ops = { 1873*5436921fSGabriel Fernandez .get_parent = clk_stm32_composite_get_parent, 1874*5436921fSGabriel Fernandez .set_parent = clk_stm32_composite_set_parent, 1875*5436921fSGabriel Fernandez }; 1876*5436921fSGabriel Fernandez 1877*5436921fSGabriel Fernandez static const struct clk_ops clk_stm32_axi_ops = { 1878*5436921fSGabriel Fernandez .get_parent = clk_stm32_composite_get_parent, 1879*5436921fSGabriel Fernandez .set_parent = clk_stm32_composite_set_parent, 1880*5436921fSGabriel Fernandez .set_rate = clk_stm32_composite_set_rate, 1881*5436921fSGabriel Fernandez .get_rate = clk_stm32_composite_get_rate, 1882*5436921fSGabriel Fernandez }; 1883*5436921fSGabriel Fernandez 1884*5436921fSGabriel Fernandez const struct clk_ops clk_stm32_mlahb_ops = { 1885*5436921fSGabriel Fernandez .get_parent = clk_stm32_composite_get_parent, 1886*5436921fSGabriel Fernandez .set_parent = clk_stm32_composite_set_parent, 1887*5436921fSGabriel Fernandez .set_rate = clk_stm32_composite_set_rate, 1888*5436921fSGabriel Fernandez .get_rate = clk_stm32_composite_get_rate, 1889*5436921fSGabriel Fernandez }; 1890*5436921fSGabriel Fernandez 1891*5436921fSGabriel Fernandez #define APB_DIV_MASK GENMASK_32(2, 0) 1892*5436921fSGabriel Fernandez #define TIM_PRE_MASK BIT(0) 1893*5436921fSGabriel Fernandez 1894*5436921fSGabriel Fernandez static unsigned long ck_timer_get_rate_ops(struct clk *clk, unsigned long prate) 1895*5436921fSGabriel Fernandez { 1896*5436921fSGabriel Fernandez struct clk_stm32_priv *priv = clk_stm32_get_priv(); 1897*5436921fSGabriel Fernandez struct clk_stm32_timer_cfg *cfg = clk->priv; 1898*5436921fSGabriel Fernandez uint32_t prescaler, timpre; 1899*5436921fSGabriel Fernandez uintptr_t rcc_base = priv->base; 1900*5436921fSGabriel Fernandez 1901*5436921fSGabriel Fernandez prescaler = io_read32(rcc_base + cfg->apbdiv) & APB_DIV_MASK; 1902*5436921fSGabriel Fernandez 1903*5436921fSGabriel Fernandez timpre = io_read32(rcc_base + cfg->timpre) & TIM_PRE_MASK; 1904*5436921fSGabriel Fernandez 1905*5436921fSGabriel Fernandez if (prescaler == 0U) 1906*5436921fSGabriel Fernandez return prate; 1907*5436921fSGabriel Fernandez 1908*5436921fSGabriel Fernandez return prate * (timpre + 1U) * 2U; 1909*5436921fSGabriel Fernandez }; 1910*5436921fSGabriel Fernandez 1911*5436921fSGabriel Fernandez const struct clk_ops ck_timer_ops = { 1912*5436921fSGabriel Fernandez .get_rate = ck_timer_get_rate_ops, 1913*5436921fSGabriel Fernandez }; 1914*5436921fSGabriel Fernandez 1915*5436921fSGabriel Fernandez #define STM32_TIMER(_name, _parent, _flags, _apbdiv, _timpre)\ 1916*5436921fSGabriel Fernandez struct clk _name = {\ 1917*5436921fSGabriel Fernandez .ops = &ck_timer_ops,\ 1918*5436921fSGabriel Fernandez .priv = &(struct clk_stm32_timer_cfg) {\ 1919*5436921fSGabriel Fernandez .apbdiv = (_apbdiv),\ 1920*5436921fSGabriel Fernandez .timpre = (_timpre),\ 1921*5436921fSGabriel Fernandez },\ 1922*5436921fSGabriel Fernandez .name = #_name,\ 1923*5436921fSGabriel Fernandez .flags = (_flags),\ 1924*5436921fSGabriel Fernandez .num_parents = 1,\ 1925*5436921fSGabriel Fernandez .parents = { _parent },\ 1926*5436921fSGabriel Fernandez } 1927*5436921fSGabriel Fernandez 1928*5436921fSGabriel Fernandez #define STM32_KCLK(_name, _nb_parents, _parents, _flags, _gate_id, _mux_id)\ 1929*5436921fSGabriel Fernandez struct clk _name = {\ 1930*5436921fSGabriel Fernandez .ops = &clk_stm32_composite_ops,\ 1931*5436921fSGabriel Fernandez .priv = &(struct clk_stm32_composite_cfg) {\ 1932*5436921fSGabriel Fernandez .gate_id = (_gate_id),\ 1933*5436921fSGabriel Fernandez .div_id = (NO_DIV),\ 1934*5436921fSGabriel Fernandez .mux_id = (_mux_id),\ 1935*5436921fSGabriel Fernandez },\ 1936*5436921fSGabriel Fernandez .name = #_name,\ 1937*5436921fSGabriel Fernandez .flags = (_flags),\ 1938*5436921fSGabriel Fernandez .num_parents = (_nb_parents),\ 1939*5436921fSGabriel Fernandez .parents = _parents,\ 1940*5436921fSGabriel Fernandez } 1941*5436921fSGabriel Fernandez 1942*5436921fSGabriel Fernandez #define STM32_PLL_VCO(_name, _nb_parents, _parents, _flags, _reg,\ 1943*5436921fSGabriel Fernandez _gate_id, _mux_id)\ 1944*5436921fSGabriel Fernandez struct clk _name = {\ 1945*5436921fSGabriel Fernandez .ops = &clk_stm32_pll_ops,\ 1946*5436921fSGabriel Fernandez .priv = &(struct clk_stm32_pll_cfg) {\ 1947*5436921fSGabriel Fernandez .reg_pllxcr = (_reg),\ 1948*5436921fSGabriel Fernandez .gate_id = (_gate_id),\ 1949*5436921fSGabriel Fernandez .mux_id = (_mux_id),\ 1950*5436921fSGabriel Fernandez },\ 1951*5436921fSGabriel Fernandez .name = #_name,\ 1952*5436921fSGabriel Fernandez .flags = (_flags),\ 1953*5436921fSGabriel Fernandez .num_parents = (_nb_parents),\ 1954*5436921fSGabriel Fernandez .parents = _parents,\ 1955*5436921fSGabriel Fernandez } 1956*5436921fSGabriel Fernandez 1957*5436921fSGabriel Fernandez #define STM32_PLL_OUPUT(_name, _nb_parents, _parents, _flags,\ 1958*5436921fSGabriel Fernandez _gate_id, _div_id, _mux_id)\ 1959*5436921fSGabriel Fernandez struct clk _name = {\ 1960*5436921fSGabriel Fernandez .ops = &clk_stm32_composite_ops,\ 1961*5436921fSGabriel Fernandez .priv = &(struct clk_stm32_composite_cfg) {\ 1962*5436921fSGabriel Fernandez .gate_id = (_gate_id),\ 1963*5436921fSGabriel Fernandez .div_id = (_div_id),\ 1964*5436921fSGabriel Fernandez .mux_id = (_mux_id),\ 1965*5436921fSGabriel Fernandez },\ 1966*5436921fSGabriel Fernandez .name = #_name,\ 1967*5436921fSGabriel Fernandez .flags = (_flags),\ 1968*5436921fSGabriel Fernandez .num_parents = (_nb_parents),\ 1969*5436921fSGabriel Fernandez .parents = _parents,\ 1970*5436921fSGabriel Fernandez } 1971*5436921fSGabriel Fernandez 1972*5436921fSGabriel Fernandez /* Oscillator clocks */ 1973*5436921fSGabriel Fernandez static STM32_GATE_READY(ck_hsi, NULL, 0, GATE_HSI); 1974*5436921fSGabriel Fernandez static STM32_GATE_READY(ck_hse, NULL, 0, GATE_HSE); 1975*5436921fSGabriel Fernandez static STM32_GATE_READY(ck_csi, NULL, 0, GATE_CSI); 1976*5436921fSGabriel Fernandez static STM32_GATE_READY(ck_lsi, NULL, 0, GATE_LSI); 1977*5436921fSGabriel Fernandez static STM32_GATE_READY(ck_lse, NULL, 0, GATE_LSE); 1978*5436921fSGabriel Fernandez 1979*5436921fSGabriel Fernandez static STM32_FIXED_FACTOR(ck_i2sckin, NULL, 0, 1, 1); 1980*5436921fSGabriel Fernandez static STM32_FIXED_FACTOR(ck_hse_div2, &ck_hse, 0, 1, 2); 1981*5436921fSGabriel Fernandez 1982*5436921fSGabriel Fernandez static STM32_FIXED_RATE(ck_off, 0UL); 1983*5436921fSGabriel Fernandez static STM32_FIXED_RATE(ck_usb_phy_48Mhz, USB_PHY_48_MHZ); 1984*5436921fSGabriel Fernandez 1985*5436921fSGabriel Fernandez /* PLL1 clocks */ 1986*5436921fSGabriel Fernandez static struct clk ck_pll1_vco = { 1987*5436921fSGabriel Fernandez .ops = &clk_stm32_pll1_ops, 1988*5436921fSGabriel Fernandez .priv = &(struct clk_stm32_pll_cfg) { 1989*5436921fSGabriel Fernandez .reg_pllxcr = RCC_PLL1CR, 1990*5436921fSGabriel Fernandez .gate_id = GATE_PLL1, 1991*5436921fSGabriel Fernandez .mux_id = MUX_PLL12, 1992*5436921fSGabriel Fernandez }, 1993*5436921fSGabriel Fernandez .name = "ck_pll1_vco", 1994*5436921fSGabriel Fernandez .flags = 0, 1995*5436921fSGabriel Fernandez .num_parents = 2, 1996*5436921fSGabriel Fernandez .parents = { &ck_hsi, &ck_hse }, 1997*5436921fSGabriel Fernandez }; 1998*5436921fSGabriel Fernandez 1999*5436921fSGabriel Fernandez static struct clk ck_pll1p = { 2000*5436921fSGabriel Fernandez .ops = &clk_stm32_pll1p_ops, 2001*5436921fSGabriel Fernandez .priv = &(struct clk_stm32_composite_cfg) { 2002*5436921fSGabriel Fernandez .gate_id = GATE_PLL1_DIVP, 2003*5436921fSGabriel Fernandez .div_id = DIV_PLL1DIVP, 2004*5436921fSGabriel Fernandez .mux_id = NO_MUX, 2005*5436921fSGabriel Fernandez }, 2006*5436921fSGabriel Fernandez .name = "ck_pll1p", 2007*5436921fSGabriel Fernandez .flags = 0, 2008*5436921fSGabriel Fernandez .num_parents = 1, 2009*5436921fSGabriel Fernandez .parents = { &ck_pll1_vco }, 2010*5436921fSGabriel Fernandez }; 2011*5436921fSGabriel Fernandez 2012*5436921fSGabriel Fernandez const struct clk_ops clk_stm32_pll1p_div_ops = { 2013*5436921fSGabriel Fernandez .get_rate = clk_stm32_divider_get_rate, 2014*5436921fSGabriel Fernandez }; 2015*5436921fSGabriel Fernandez 2016*5436921fSGabriel Fernandez static struct clk ck_pll1p_div = { 2017*5436921fSGabriel Fernandez .ops = &clk_stm32_pll1p_div_ops, 2018*5436921fSGabriel Fernandez .priv = &(struct clk_stm32_div_cfg) { 2019*5436921fSGabriel Fernandez .div_id = DIV_MPU, 2020*5436921fSGabriel Fernandez }, 2021*5436921fSGabriel Fernandez .name = "ck_pll1p_div", 2022*5436921fSGabriel Fernandez .flags = 0, 2023*5436921fSGabriel Fernandez .num_parents = 1, 2024*5436921fSGabriel Fernandez .parents = { &ck_pll1p }, 2025*5436921fSGabriel Fernandez }; 2026*5436921fSGabriel Fernandez 2027*5436921fSGabriel Fernandez /* Other PLLs */ 2028*5436921fSGabriel Fernandez static STM32_PLL_VCO(ck_pll2_vco, 2, PARENT(&ck_hsi, &ck_hse), 2029*5436921fSGabriel Fernandez 0, RCC_PLL2CR, GATE_PLL2, MUX_PLL12); 2030*5436921fSGabriel Fernandez 2031*5436921fSGabriel Fernandez static STM32_PLL_VCO(ck_pll3_vco, 3, 2032*5436921fSGabriel Fernandez PARENT(&ck_hsi, &ck_hse, &ck_csi), 2033*5436921fSGabriel Fernandez 0, RCC_PLL3CR, GATE_PLL3, MUX_PLL3); 2034*5436921fSGabriel Fernandez 2035*5436921fSGabriel Fernandez static STM32_PLL_VCO(ck_pll4_vco, 4, 2036*5436921fSGabriel Fernandez PARENT(&ck_hsi, &ck_hse, &ck_csi, &ck_i2sckin), 2037*5436921fSGabriel Fernandez 0, RCC_PLL4CR, GATE_PLL4, MUX_PLL4); 2038*5436921fSGabriel Fernandez 2039*5436921fSGabriel Fernandez static STM32_PLL_OUPUT(ck_pll2p, 1, PARENT(&ck_pll2_vco), 0, 2040*5436921fSGabriel Fernandez GATE_PLL2_DIVP, DIV_PLL2DIVP, NO_MUX); 2041*5436921fSGabriel Fernandez 2042*5436921fSGabriel Fernandez static STM32_PLL_OUPUT(ck_pll2q, 1, PARENT(&ck_pll2_vco), 0, 2043*5436921fSGabriel Fernandez GATE_PLL2_DIVQ, DIV_PLL2DIVQ, NO_MUX); 2044*5436921fSGabriel Fernandez 2045*5436921fSGabriel Fernandez static STM32_PLL_OUPUT(ck_pll2r, 1, PARENT(&ck_pll2_vco), 0, 2046*5436921fSGabriel Fernandez GATE_PLL2_DIVR, DIV_PLL2DIVR, NO_MUX); 2047*5436921fSGabriel Fernandez 2048*5436921fSGabriel Fernandez static STM32_PLL_OUPUT(ck_pll3p, 1, PARENT(&ck_pll3_vco), 0, 2049*5436921fSGabriel Fernandez GATE_PLL3_DIVP, DIV_PLL3DIVP, NO_MUX); 2050*5436921fSGabriel Fernandez 2051*5436921fSGabriel Fernandez static STM32_PLL_OUPUT(ck_pll3q, 1, PARENT(&ck_pll3_vco), 0, 2052*5436921fSGabriel Fernandez GATE_PLL3_DIVQ, DIV_PLL3DIVQ, NO_MUX); 2053*5436921fSGabriel Fernandez 2054*5436921fSGabriel Fernandez static STM32_PLL_OUPUT(ck_pll3r, 1, PARENT(&ck_pll3_vco), 0, 2055*5436921fSGabriel Fernandez GATE_PLL3_DIVR, DIV_PLL3DIVR, NO_MUX); 2056*5436921fSGabriel Fernandez 2057*5436921fSGabriel Fernandez static STM32_PLL_OUPUT(ck_pll4p, 1, PARENT(&ck_pll4_vco), 0, 2058*5436921fSGabriel Fernandez GATE_PLL4_DIVP, DIV_PLL4DIVP, NO_MUX); 2059*5436921fSGabriel Fernandez 2060*5436921fSGabriel Fernandez static STM32_PLL_OUPUT(ck_pll4q, 1, PARENT(&ck_pll4_vco), 0, 2061*5436921fSGabriel Fernandez GATE_PLL4_DIVQ, DIV_PLL4DIVQ, NO_MUX); 2062*5436921fSGabriel Fernandez 2063*5436921fSGabriel Fernandez static STM32_PLL_OUPUT(ck_pll4r, 1, PARENT(&ck_pll4_vco), 0, 2064*5436921fSGabriel Fernandez GATE_PLL4_DIVR, DIV_PLL4DIVR, NO_MUX); 2065*5436921fSGabriel Fernandez 2066*5436921fSGabriel Fernandez /* System clocks */ 2067*5436921fSGabriel Fernandez static struct clk ck_mpu = { 2068*5436921fSGabriel Fernandez .ops = &clk_stm32_mpu_ops, 2069*5436921fSGabriel Fernandez .priv = &(struct clk_stm32_composite_cfg) { 2070*5436921fSGabriel Fernandez .mux_id = MUX_MPU, 2071*5436921fSGabriel Fernandez }, 2072*5436921fSGabriel Fernandez .name = "ck_mpu", 2073*5436921fSGabriel Fernandez .flags = 0, 2074*5436921fSGabriel Fernandez .num_parents = 4, 2075*5436921fSGabriel Fernandez .parents = { &ck_hsi, &ck_hse, &ck_pll1p, &ck_pll1p_div }, 2076*5436921fSGabriel Fernandez }; 2077*5436921fSGabriel Fernandez 2078*5436921fSGabriel Fernandez static struct clk ck_axi = { 2079*5436921fSGabriel Fernandez .ops = &clk_stm32_axi_ops, 2080*5436921fSGabriel Fernandez .priv = &(struct clk_stm32_composite_cfg) { 2081*5436921fSGabriel Fernandez .mux_id = MUX_AXI, 2082*5436921fSGabriel Fernandez .div_id = DIV_AXI, 2083*5436921fSGabriel Fernandez }, 2084*5436921fSGabriel Fernandez .name = "ck_axi", 2085*5436921fSGabriel Fernandez .flags = 0, 2086*5436921fSGabriel Fernandez .num_parents = 3, 2087*5436921fSGabriel Fernandez .parents = { &ck_hsi, &ck_hse, &ck_pll2p }, 2088*5436921fSGabriel Fernandez }; 2089*5436921fSGabriel Fernandez 2090*5436921fSGabriel Fernandez static struct clk ck_mlahb = { 2091*5436921fSGabriel Fernandez .ops = &clk_stm32_mlahb_ops, 2092*5436921fSGabriel Fernandez .priv = &(struct clk_stm32_composite_cfg) { 2093*5436921fSGabriel Fernandez .mux_id = MUX_MLAHB, 2094*5436921fSGabriel Fernandez .div_id = DIV_MLAHB, 2095*5436921fSGabriel Fernandez }, 2096*5436921fSGabriel Fernandez .name = "ck_mlahb", 2097*5436921fSGabriel Fernandez .flags = 0, 2098*5436921fSGabriel Fernandez .num_parents = 4, 2099*5436921fSGabriel Fernandez .parents = { &ck_hsi, &ck_hse, &ck_csi, &ck_pll3p }, 2100*5436921fSGabriel Fernandez }; 2101*5436921fSGabriel Fernandez 2102*5436921fSGabriel Fernandez static STM32_MUX(ck_per, 4, PARENT(&ck_hsi, &ck_csi, &ck_hse, &ck_off), 2103*5436921fSGabriel Fernandez 0, MUX_CKPER); 2104*5436921fSGabriel Fernandez 2105*5436921fSGabriel Fernandez /* Bus clocks */ 2106*5436921fSGabriel Fernandez static STM32_DIVIDER(ck_pclk1, &ck_mlahb, 0, DIV_APB1); 2107*5436921fSGabriel Fernandez static STM32_DIVIDER(ck_pclk2, &ck_mlahb, 0, DIV_APB2); 2108*5436921fSGabriel Fernandez static STM32_DIVIDER(ck_pclk3, &ck_mlahb, 0, DIV_APB3); 2109*5436921fSGabriel Fernandez static STM32_DIVIDER(ck_pclk4, &ck_axi, 0, DIV_APB4); 2110*5436921fSGabriel Fernandez static STM32_DIVIDER(ck_pclk5, &ck_axi, 0, DIV_APB5); 2111*5436921fSGabriel Fernandez static STM32_DIVIDER(ck_pclk6, &ck_mlahb, 0, DIV_APB6); 2112*5436921fSGabriel Fernandez 2113*5436921fSGabriel Fernandez /* Timer Clocks */ 2114*5436921fSGabriel Fernandez static STM32_TIMER(ck_timg1, &ck_pclk1, 0, RCC_APB1DIVR, RCC_TIMG1PRER); 2115*5436921fSGabriel Fernandez static STM32_TIMER(ck_timg2, &ck_pclk2, 0, RCC_APB2DIVR, RCC_TIMG2PRER); 2116*5436921fSGabriel Fernandez static STM32_TIMER(ck_timg3, &ck_pclk6, 0, RCC_APB6DIVR, RCC_TIMG3PRER); 2117*5436921fSGabriel Fernandez 2118*5436921fSGabriel Fernandez /* Peripheral and Kernel Clocks */ 2119*5436921fSGabriel Fernandez static STM32_GATE(ck_ddrc1, &ck_axi, 0, GATE_DDRC1); 2120*5436921fSGabriel Fernandez static STM32_GATE(ck_ddrc1lp, &ck_axi, 0, GATE_DDRC1LP); 2121*5436921fSGabriel Fernandez static STM32_GATE(ck_ddrphyc, &ck_pll2r, 0, GATE_DDRPHYC); 2122*5436921fSGabriel Fernandez static STM32_GATE(ck_ddrphyclp, &ck_pll2r, 0, GATE_DDRPHYCLP); 2123*5436921fSGabriel Fernandez static STM32_GATE(ck_ddrcapb, &ck_pclk4, 0, GATE_DDRCAPB); 2124*5436921fSGabriel Fernandez static STM32_GATE(ck_ddrcapblp, &ck_pclk4, 0, GATE_DDRCAPBLP); 2125*5436921fSGabriel Fernandez static STM32_GATE(ck_axidcg, &ck_axi, 0, GATE_AXIDCG); 2126*5436921fSGabriel Fernandez static STM32_GATE(ck_ddrphycapb, &ck_pclk4, 0, 0); 2127*5436921fSGabriel Fernandez static STM32_GATE(ck_ddrphycapblp, &ck_pclk4, 0, GATE_DDRPHYCAPBLP); 2128*5436921fSGabriel Fernandez static STM32_GATE(ck_syscfg, &ck_pclk3, 0, GATE_SYSCFG); 2129*5436921fSGabriel Fernandez static STM32_GATE(ck_ddrperfm, &ck_pclk4, 0, GATE_DDRPERFM); 2130*5436921fSGabriel Fernandez static STM32_GATE(ck_iwdg2, &ck_pclk4, 0, GATE_IWDG2APB); 2131*5436921fSGabriel Fernandez static STM32_GATE(ck_rtcapb, &ck_pclk5, 0, GATE_RTCAPB); 2132*5436921fSGabriel Fernandez static STM32_GATE(ck_tzc, &ck_pclk5, 0, GATE_TZC); 2133*5436921fSGabriel Fernandez static STM32_GATE(ck_etzpcb, &ck_pclk5, 0, GATE_ETZPC); 2134*5436921fSGabriel Fernandez static STM32_GATE(ck_iwdg1apb, &ck_pclk5, 0, GATE_IWDG1APB); 2135*5436921fSGabriel Fernandez static STM32_GATE(ck_bsec, &ck_pclk5, 0, GATE_BSEC); 2136*5436921fSGabriel Fernandez static STM32_GATE(ck_tim12_k, &ck_timg3, 0, GATE_TIM12); 2137*5436921fSGabriel Fernandez static STM32_GATE(ck_tim15_k, &ck_timg3, 0, GATE_TIM15); 2138*5436921fSGabriel Fernandez static STM32_GATE(ck_gpioa, &ck_mlahb, 0, GATE_GPIOA); 2139*5436921fSGabriel Fernandez static STM32_GATE(ck_gpiob, &ck_mlahb, 0, GATE_GPIOB); 2140*5436921fSGabriel Fernandez static STM32_GATE(ck_gpioc, &ck_mlahb, 0, GATE_GPIOC); 2141*5436921fSGabriel Fernandez static STM32_GATE(ck_gpiod, &ck_mlahb, 0, GATE_GPIOD); 2142*5436921fSGabriel Fernandez static STM32_GATE(ck_gpioe, &ck_mlahb, 0, GATE_GPIOE); 2143*5436921fSGabriel Fernandez static STM32_GATE(ck_gpiof, &ck_mlahb, 0, GATE_GPIOF); 2144*5436921fSGabriel Fernandez static STM32_GATE(ck_gpiog, &ck_mlahb, 0, GATE_GPIOG); 2145*5436921fSGabriel Fernandez static STM32_GATE(ck_gpioh, &ck_mlahb, 0, GATE_GPIOH); 2146*5436921fSGabriel Fernandez static STM32_GATE(ck_gpioi, &ck_mlahb, 0, GATE_GPIOI); 2147*5436921fSGabriel Fernandez static STM32_GATE(ck_pka, &ck_axi, 0, GATE_PKA); 2148*5436921fSGabriel Fernandez static STM32_GATE(ck_cryp1, &ck_pclk5, 0, GATE_CRYP1); 2149*5436921fSGabriel Fernandez static STM32_GATE(ck_hash1, &ck_pclk5, 0, GATE_HASH1); 2150*5436921fSGabriel Fernandez static STM32_GATE(ck_bkpsram, &ck_pclk5, 0, GATE_BKPSRAM); 2151*5436921fSGabriel Fernandez static STM32_GATE(ck_dbg, &ck_axi, 0, GATE_DBGCK); 2152*5436921fSGabriel Fernandez static STM32_GATE(ck_mce, &ck_axi, 0, GATE_MCE); 2153*5436921fSGabriel Fernandez static STM32_GATE(ck_tim2_k, &ck_timg1, 0, GATE_TIM2); 2154*5436921fSGabriel Fernandez static STM32_GATE(ck_tim3_k, &ck_timg1, 0, GATE_TIM3); 2155*5436921fSGabriel Fernandez static STM32_GATE(ck_tim4_k, &ck_timg1, 0, GATE_TIM4); 2156*5436921fSGabriel Fernandez static STM32_GATE(ck_tim5_k, &ck_timg1, 0, GATE_TIM5); 2157*5436921fSGabriel Fernandez static STM32_GATE(ck_tim6_k, &ck_timg1, 0, GATE_TIM6); 2158*5436921fSGabriel Fernandez static STM32_GATE(ck_tim7_k, &ck_timg1, 0, GATE_TIM7); 2159*5436921fSGabriel Fernandez static STM32_GATE(ck_tim13_k, &ck_timg3, 0, GATE_TIM13); 2160*5436921fSGabriel Fernandez static STM32_GATE(ck_tim14_k, &ck_timg3, 0, GATE_TIM14); 2161*5436921fSGabriel Fernandez static STM32_GATE(ck_tim1_k, &ck_timg2, 0, GATE_TIM1); 2162*5436921fSGabriel Fernandez static STM32_GATE(ck_tim8_k, &ck_timg2, 0, GATE_TIM8); 2163*5436921fSGabriel Fernandez static STM32_GATE(ck_tim16_k, &ck_timg3, 0, GATE_TIM16); 2164*5436921fSGabriel Fernandez static STM32_GATE(ck_tim17_k, &ck_timg3, 0, GATE_TIM17); 2165*5436921fSGabriel Fernandez static STM32_GATE(ck_ltdc_px, &ck_pll4q, 0, GATE_LTDC); 2166*5436921fSGabriel Fernandez static STM32_GATE(ck_dma1, &ck_mlahb, 0, GATE_DMA1); 2167*5436921fSGabriel Fernandez static STM32_GATE(ck_dma2, &ck_mlahb, 0, GATE_DMA2); 2168*5436921fSGabriel Fernandez static STM32_GATE(ck_mdma, &ck_axi, 0, GATE_MDMA); 2169*5436921fSGabriel Fernandez static STM32_GATE(ck_eth1mac, &ck_axi, 0, GATE_ETH1MAC); 2170*5436921fSGabriel Fernandez static STM32_GATE(ck_usbh, &ck_axi, 0, GATE_USBH); 2171*5436921fSGabriel Fernandez static STM32_GATE(ck_vref, &ck_pclk3, 0, GATE_VREF); 2172*5436921fSGabriel Fernandez static STM32_GATE(ck_tmpsens, &ck_pclk3, 0, GATE_DTS); 2173*5436921fSGabriel Fernandez static STM32_GATE(ck_pmbctrl, &ck_pclk3, 0, GATE_HDP); 2174*5436921fSGabriel Fernandez static STM32_GATE(ck_hdp, &ck_pclk3, 0, GATE_PMBCTRL); 2175*5436921fSGabriel Fernandez static STM32_GATE(ck_stgenro, &ck_pclk4, 0, GATE_DCMIPP); 2176*5436921fSGabriel Fernandez static STM32_GATE(ck_dmamux1, &ck_axi, 0, GATE_DMAMUX1); 2177*5436921fSGabriel Fernandez static STM32_GATE(ck_dmamux2, &ck_axi, 0, GATE_DMAMUX2); 2178*5436921fSGabriel Fernandez static STM32_GATE(ck_dma3, &ck_axi, 0, GATE_DMAMUX2); 2179*5436921fSGabriel Fernandez static STM32_GATE(ck_tsc, &ck_axi, 0, GATE_TSC); 2180*5436921fSGabriel Fernandez static STM32_GATE(ck_aximc, &ck_axi, 0, GATE_AXIMC); 2181*5436921fSGabriel Fernandez static STM32_GATE(ck_crc1, &ck_axi, 0, GATE_ETH1TX); 2182*5436921fSGabriel Fernandez static STM32_GATE(ck_eth1tx, &ck_axi, 0, GATE_ETH1TX); 2183*5436921fSGabriel Fernandez static STM32_GATE(ck_eth1rx, &ck_axi, 0, GATE_ETH1RX); 2184*5436921fSGabriel Fernandez static STM32_GATE(ck_eth2tx, &ck_axi, 0, GATE_ETH2TX); 2185*5436921fSGabriel Fernandez static STM32_GATE(ck_eth2rx, &ck_axi, 0, GATE_ETH2RX); 2186*5436921fSGabriel Fernandez static STM32_GATE(ck_eth2mac, &ck_axi, 0, GATE_ETH2MAC); 2187*5436921fSGabriel Fernandez 2188*5436921fSGabriel Fernandez /* Kernel Clocks */ 2189*5436921fSGabriel Fernandez static STM32_KCLK(ck_usbphy_k, 3, 2190*5436921fSGabriel Fernandez PARENT(&ck_hse, &ck_pll4r, &ck_hse_div2), 2191*5436921fSGabriel Fernandez 0, GATE_USBPHY, MUX_USBPHY); 2192*5436921fSGabriel Fernandez 2193*5436921fSGabriel Fernandez static STM32_KCLK(ck_usbo_k, 2, 2194*5436921fSGabriel Fernandez PARENT(&ck_pll4r, &ck_usb_phy_48Mhz), 0, 2195*5436921fSGabriel Fernandez GATE_USBO, MUX_USBO); 2196*5436921fSGabriel Fernandez 2197*5436921fSGabriel Fernandez static STM32_KCLK(ck_stgen_k, 2, 2198*5436921fSGabriel Fernandez PARENT(&ck_hsi, &ck_hse), 0, GATE_STGENC, MUX_STGEN); 2199*5436921fSGabriel Fernandez 2200*5436921fSGabriel Fernandez static STM32_KCLK(ck_usart1_k, 6, 2201*5436921fSGabriel Fernandez PARENT(&ck_pclk6, &ck_pll3q, &ck_hsi, 2202*5436921fSGabriel Fernandez &ck_csi, &ck_pll4q, &ck_hse), 2203*5436921fSGabriel Fernandez 0, GATE_USART1, MUX_UART1); 2204*5436921fSGabriel Fernandez 2205*5436921fSGabriel Fernandez static STM32_KCLK(ck_usart2_k, 6, 2206*5436921fSGabriel Fernandez PARENT(&ck_pclk6, &ck_pll3q, &ck_hsi, &ck_csi, &ck_pll4q, 2207*5436921fSGabriel Fernandez &ck_hse), 2208*5436921fSGabriel Fernandez 0, GATE_USART2, MUX_UART2); 2209*5436921fSGabriel Fernandez 2210*5436921fSGabriel Fernandez static STM32_KCLK(ck_i2c4_k, 4, 2211*5436921fSGabriel Fernandez PARENT(&ck_pclk6, &ck_pll4r, &ck_hsi, &ck_csi), 2212*5436921fSGabriel Fernandez 0, GATE_I2C4, MUX_I2C4); 2213*5436921fSGabriel Fernandez 2214*5436921fSGabriel Fernandez static STM32_KCLK(ck_rtc, 4, 2215*5436921fSGabriel Fernandez PARENT(&ck_off, &ck_lse, &ck_lsi, &ck_hse), 2216*5436921fSGabriel Fernandez 0, GATE_RTCCK, MUX_RTC); 2217*5436921fSGabriel Fernandez 2218*5436921fSGabriel Fernandez static STM32_KCLK(ck_saes_k, 4, 2219*5436921fSGabriel Fernandez PARENT(&ck_axi, &ck_per, &ck_pll4r, &ck_lsi), 2220*5436921fSGabriel Fernandez 0, GATE_SAES, MUX_SAES); 2221*5436921fSGabriel Fernandez 2222*5436921fSGabriel Fernandez static STM32_KCLK(ck_rng1_k, 4, 2223*5436921fSGabriel Fernandez PARENT(&ck_csi, &ck_pll4r, &ck_lse, &ck_lsi), 2224*5436921fSGabriel Fernandez 0, GATE_RNG1, MUX_RNG1); 2225*5436921fSGabriel Fernandez 2226*5436921fSGabriel Fernandez static STM32_KCLK(ck_sdmmc1_k, 4, 2227*5436921fSGabriel Fernandez PARENT(&ck_axi, &ck_pll3r, &ck_pll4p, &ck_hsi), 2228*5436921fSGabriel Fernandez 0, GATE_SDMMC1, MUX_SDMMC1); 2229*5436921fSGabriel Fernandez 2230*5436921fSGabriel Fernandez static STM32_KCLK(ck_sdmmc2_k, 4, 2231*5436921fSGabriel Fernandez PARENT(&ck_axi, &ck_pll3r, &ck_pll4p, &ck_hsi), 2232*5436921fSGabriel Fernandez 0, GATE_SDMMC2, MUX_SDMMC2); 2233*5436921fSGabriel Fernandez 2234*5436921fSGabriel Fernandez static STM32_KCLK(ck_usart3_k, 5, 2235*5436921fSGabriel Fernandez PARENT(&ck_pclk1, &ck_pll4q, &ck_hsi, &ck_csi, &ck_hse), 2236*5436921fSGabriel Fernandez 0, GATE_USART3, MUX_UART35); 2237*5436921fSGabriel Fernandez 2238*5436921fSGabriel Fernandez static STM32_KCLK(ck_uart4_k, 5, 2239*5436921fSGabriel Fernandez PARENT(&ck_pclk1, &ck_pll4q, &ck_hsi, &ck_csi, &ck_hse), 2240*5436921fSGabriel Fernandez 0, GATE_UART4, MUX_UART4); 2241*5436921fSGabriel Fernandez 2242*5436921fSGabriel Fernandez static STM32_KCLK(ck_uart5_k, 5, 2243*5436921fSGabriel Fernandez PARENT(&ck_pclk1, &ck_pll4q, &ck_hsi, &ck_csi, &ck_hse), 2244*5436921fSGabriel Fernandez 0, GATE_UART5, MUX_UART35); 2245*5436921fSGabriel Fernandez 2246*5436921fSGabriel Fernandez static STM32_KCLK(ck_uart7_k, 5, 2247*5436921fSGabriel Fernandez PARENT(&ck_pclk1, &ck_pll4q, &ck_hsi, &ck_csi, &ck_hse), 2248*5436921fSGabriel Fernandez 0, GATE_UART7, MUX_UART78); 2249*5436921fSGabriel Fernandez 2250*5436921fSGabriel Fernandez static STM32_KCLK(ck_uart8_k, 5, 2251*5436921fSGabriel Fernandez PARENT(&ck_pclk1, &ck_pll4q, &ck_hsi, &ck_csi, &ck_hse), 2252*5436921fSGabriel Fernandez 0, GATE_UART8, MUX_UART78); 2253*5436921fSGabriel Fernandez 2254*5436921fSGabriel Fernandez static STM32_KCLK(ck_usart6_k, 5, 2255*5436921fSGabriel Fernandez PARENT(&ck_pclk2, &ck_pll4q, &ck_hsi, &ck_csi, &ck_hse), 2256*5436921fSGabriel Fernandez 0, GATE_USART6, MUX_UART6); 2257*5436921fSGabriel Fernandez 2258*5436921fSGabriel Fernandez static STM32_KCLK(ck_fmc_k, 4, 2259*5436921fSGabriel Fernandez PARENT(&ck_axi, &ck_pll3r, &ck_pll4p, &ck_per), 2260*5436921fSGabriel Fernandez 0, GATE_FMC, MUX_FMC); 2261*5436921fSGabriel Fernandez 2262*5436921fSGabriel Fernandez static STM32_KCLK(ck_qspi_k, 4, 2263*5436921fSGabriel Fernandez PARENT(&ck_axi, &ck_pll3r, &ck_pll4p, &ck_per), 2264*5436921fSGabriel Fernandez 0, GATE_QSPI, MUX_QSPI); 2265*5436921fSGabriel Fernandez 2266*5436921fSGabriel Fernandez static STM32_KCLK(ck_lptim1_k, 6, 2267*5436921fSGabriel Fernandez PARENT(&ck_pclk1, &ck_pll4p, &ck_pll3q, &ck_lse, &ck_lsi, 2268*5436921fSGabriel Fernandez &ck_per), 2269*5436921fSGabriel Fernandez 0, GATE_LPTIM1, MUX_LPTIM1); 2270*5436921fSGabriel Fernandez 2271*5436921fSGabriel Fernandez static STM32_KCLK(ck_spi2_k, 5, 2272*5436921fSGabriel Fernandez PARENT(&ck_pll4p, &ck_pll3q, &ck_i2sckin, &ck_per, &ck_pll3r), 2273*5436921fSGabriel Fernandez 0, GATE_SPI2, MUX_SPI23); 2274*5436921fSGabriel Fernandez 2275*5436921fSGabriel Fernandez static STM32_KCLK(ck_spi3_k, 5, 2276*5436921fSGabriel Fernandez PARENT(&ck_pll4p, &ck_pll3q, &ck_i2sckin, &ck_per, &ck_pll3r), 2277*5436921fSGabriel Fernandez 0, GATE_SPI3, MUX_SPI23); 2278*5436921fSGabriel Fernandez 2279*5436921fSGabriel Fernandez static STM32_KCLK(ck_spdif_k, 3, 2280*5436921fSGabriel Fernandez PARENT(&ck_pll4p, &ck_pll3q, &ck_hsi), 2281*5436921fSGabriel Fernandez 0, GATE_SPDIF, MUX_SPDIF); 2282*5436921fSGabriel Fernandez 2283*5436921fSGabriel Fernandez static STM32_KCLK(ck_spi1_k, 5, 2284*5436921fSGabriel Fernandez PARENT(&ck_pll4p, &ck_pll3q, &ck_i2sckin, &ck_per, &ck_pll3r), 2285*5436921fSGabriel Fernandez 0, GATE_SPI1, MUX_SPI1); 2286*5436921fSGabriel Fernandez 2287*5436921fSGabriel Fernandez static STM32_KCLK(ck_spi4_k, 6, 2288*5436921fSGabriel Fernandez PARENT(&ck_pclk6, &ck_pll4q, &ck_hsi, &ck_csi, &ck_hse, 2289*5436921fSGabriel Fernandez &ck_i2sckin), 2290*5436921fSGabriel Fernandez 0, GATE_SPI4, MUX_SPI4); 2291*5436921fSGabriel Fernandez 2292*5436921fSGabriel Fernandez static STM32_KCLK(ck_spi5_k, 5, 2293*5436921fSGabriel Fernandez PARENT(&ck_pclk6, &ck_pll4q, &ck_hsi, &ck_csi, &ck_hse), 2294*5436921fSGabriel Fernandez 0, GATE_SPI5, MUX_SPI5); 2295*5436921fSGabriel Fernandez 2296*5436921fSGabriel Fernandez static STM32_KCLK(ck_sai1_k, 5, 2297*5436921fSGabriel Fernandez PARENT(&ck_pll4q, &ck_pll3q, &ck_i2sckin, &ck_per, &ck_pll3r), 2298*5436921fSGabriel Fernandez 0, GATE_SAI1, MUX_SAI1); 2299*5436921fSGabriel Fernandez 2300*5436921fSGabriel Fernandez static STM32_KCLK(ck_sai2_k, 6, 2301*5436921fSGabriel Fernandez PARENT(&ck_pll4q, &ck_pll3q, &ck_i2sckin, &ck_per, &ck_off, 2302*5436921fSGabriel Fernandez &ck_pll3r), 2303*5436921fSGabriel Fernandez 0, GATE_SAI2, MUX_SAI2); 2304*5436921fSGabriel Fernandez 2305*5436921fSGabriel Fernandez static STM32_KCLK(ck_dfsdm_k, 5, 2306*5436921fSGabriel Fernandez PARENT(&ck_pll4q, &ck_pll3q, &ck_i2sckin, &ck_per, &ck_pll3r), 2307*5436921fSGabriel Fernandez 0, GATE_DFSDM, MUX_SAI1); 2308*5436921fSGabriel Fernandez 2309*5436921fSGabriel Fernandez static STM32_KCLK(ck_fdcan_k, 4, 2310*5436921fSGabriel Fernandez PARENT(&ck_hse, &ck_pll3q, &ck_pll4q, &ck_pll4r), 2311*5436921fSGabriel Fernandez 0, GATE_FDCAN, MUX_FDCAN); 2312*5436921fSGabriel Fernandez 2313*5436921fSGabriel Fernandez static STM32_KCLK(ck_i2c1_k, 4, 2314*5436921fSGabriel Fernandez PARENT(&ck_pclk1, &ck_pll4r, &ck_hsi, &ck_csi), 2315*5436921fSGabriel Fernandez 0, GATE_I2C1, MUX_I2C12); 2316*5436921fSGabriel Fernandez 2317*5436921fSGabriel Fernandez static STM32_KCLK(ck_i2c2_k, 4, 2318*5436921fSGabriel Fernandez PARENT(&ck_pclk1, &ck_pll4r, &ck_hsi, &ck_csi), 2319*5436921fSGabriel Fernandez 0, GATE_I2C2, MUX_I2C12); 2320*5436921fSGabriel Fernandez 2321*5436921fSGabriel Fernandez static STM32_KCLK(ck_adfsdm_k, 5, 2322*5436921fSGabriel Fernandez PARENT(&ck_pll4q, &ck_pll3q, &ck_i2sckin, &ck_per, &ck_pll3r), 2323*5436921fSGabriel Fernandez 0, GATE_ADFSDM, MUX_SAI1); 2324*5436921fSGabriel Fernandez 2325*5436921fSGabriel Fernandez static STM32_KCLK(ck_lptim2_k, 5, 2326*5436921fSGabriel Fernandez PARENT(&ck_pclk3, &ck_pll4q, &ck_per, &ck_lse, &ck_lsi), 2327*5436921fSGabriel Fernandez 0, GATE_LPTIM2, MUX_LPTIM2); 2328*5436921fSGabriel Fernandez 2329*5436921fSGabriel Fernandez static STM32_KCLK(ck_lptim3_k, 5, 2330*5436921fSGabriel Fernandez PARENT(&ck_pclk3, &ck_pll4q, &ck_per, &ck_lse, &ck_lsi), 2331*5436921fSGabriel Fernandez 0, GATE_LPTIM3, MUX_LPTIM3); 2332*5436921fSGabriel Fernandez 2333*5436921fSGabriel Fernandez static STM32_KCLK(ck_lptim4_k, 6, 2334*5436921fSGabriel Fernandez PARENT(&ck_pclk3, &ck_pll4p, &ck_pll3q, &ck_lse, &ck_lsi, 2335*5436921fSGabriel Fernandez &ck_per), 2336*5436921fSGabriel Fernandez 0, GATE_LPTIM4, MUX_LPTIM45); 2337*5436921fSGabriel Fernandez 2338*5436921fSGabriel Fernandez static STM32_KCLK(ck_lptim5_k, 6, 2339*5436921fSGabriel Fernandez PARENT(&ck_pclk3, &ck_pll4p, &ck_pll3q, &ck_lse, &ck_lsi, 2340*5436921fSGabriel Fernandez &ck_per), 2341*5436921fSGabriel Fernandez 0, GATE_LPTIM5, MUX_LPTIM45); 2342*5436921fSGabriel Fernandez 2343*5436921fSGabriel Fernandez static STM32_KCLK(ck_i2c3_k, 4, 2344*5436921fSGabriel Fernandez PARENT(&ck_pclk6, &ck_pll4r, &ck_hsi, &ck_csi), 2345*5436921fSGabriel Fernandez 0, GATE_I2C3, MUX_I2C3); 2346*5436921fSGabriel Fernandez 2347*5436921fSGabriel Fernandez static STM32_KCLK(ck_i2c5_k, 4, 2348*5436921fSGabriel Fernandez PARENT(&ck_pclk6, &ck_pll4r, &ck_hsi, &ck_csi), 2349*5436921fSGabriel Fernandez 0, GATE_I2C5, MUX_I2C5); 2350*5436921fSGabriel Fernandez 2351*5436921fSGabriel Fernandez static STM32_KCLK(ck_dcmipp_k, 4, 2352*5436921fSGabriel Fernandez PARENT(&ck_axi, &ck_pll2q, &ck_pll4p, &ck_per), 2353*5436921fSGabriel Fernandez 0, GATE_DCMIPP, MUX_DCMIPP); 2354*5436921fSGabriel Fernandez 2355*5436921fSGabriel Fernandez static STM32_KCLK(ck_adc1_k, 3, PARENT(&ck_pll4r, &ck_per, &ck_pll3q), 2356*5436921fSGabriel Fernandez 0, GATE_ADC1, MUX_ADC1); 2357*5436921fSGabriel Fernandez 2358*5436921fSGabriel Fernandez static STM32_KCLK(ck_adc2_k, 3, PARENT(&ck_pll4r, &ck_per, &ck_pll3q), 2359*5436921fSGabriel Fernandez 0, GATE_ADC2, MUX_ADC2); 2360*5436921fSGabriel Fernandez 2361*5436921fSGabriel Fernandez static STM32_KCLK(ck_eth1ck_k, 2, PARENT(&ck_pll4p, &ck_pll3q), 2362*5436921fSGabriel Fernandez 0, GATE_ETH1CK, MUX_ETH1); 2363*5436921fSGabriel Fernandez 2364*5436921fSGabriel Fernandez static STM32_KCLK(ck_eth2ck_k, 2, PARENT(&ck_pll4p, &ck_pll3q), 2365*5436921fSGabriel Fernandez 0, GATE_ETH2CK, MUX_ETH2); 2366*5436921fSGabriel Fernandez 2367*5436921fSGabriel Fernandez static STM32_COMPOSITE(ck_mco1, 5, 2368*5436921fSGabriel Fernandez PARENT(&ck_hsi, &ck_hse, &ck_csi, &ck_lsi, &ck_lse), 2369*5436921fSGabriel Fernandez 0, GATE_MCO1, DIV_MCO1, MUX_MCO1); 2370*5436921fSGabriel Fernandez 2371*5436921fSGabriel Fernandez static STM32_COMPOSITE(ck_mco2, 6, 2372*5436921fSGabriel Fernandez PARENT(&ck_mpu, &ck_axi, &ck_mlahb, 2373*5436921fSGabriel Fernandez &ck_pll4p, &ck_hse, &ck_hsi), 2374*5436921fSGabriel Fernandez 0, GATE_MCO2, DIV_MCO2, MUX_MCO2); 2375*5436921fSGabriel Fernandez 2376*5436921fSGabriel Fernandez static STM32_COMPOSITE(ck_trace, 1, PARENT(&ck_axi), 2377*5436921fSGabriel Fernandez 0, GATE_TRACECK, DIV_TRACE, NO_MUX); 2378*5436921fSGabriel Fernandez 2379*5436921fSGabriel Fernandez enum { 2380*5436921fSGabriel Fernandez USB_PHY_48 = STM32MP1_LAST_CLK, 2381*5436921fSGabriel Fernandez PLL1P_DIV, 2382*5436921fSGabriel Fernandez CK_OFF, 2383*5436921fSGabriel Fernandez I2S_CKIN, 2384*5436921fSGabriel Fernandez STM32MP13_ALL_CLK_NB 2385*5436921fSGabriel Fernandez }; 2386*5436921fSGabriel Fernandez 2387*5436921fSGabriel Fernandez static struct clk *stm32mp13_clk_provided[STM32MP13_ALL_CLK_NB] = { 2388*5436921fSGabriel Fernandez [CK_HSE] = &ck_hse, 2389*5436921fSGabriel Fernandez [CK_CSI] = &ck_csi, 2390*5436921fSGabriel Fernandez [CK_LSI] = &ck_lsi, 2391*5436921fSGabriel Fernandez [CK_LSE] = &ck_lse, 2392*5436921fSGabriel Fernandez [CK_HSI] = &ck_hsi, 2393*5436921fSGabriel Fernandez [CK_HSE_DIV2] = &ck_hse_div2, 2394*5436921fSGabriel Fernandez [PLL1] = &ck_pll1_vco, 2395*5436921fSGabriel Fernandez [PLL2] = &ck_pll2_vco, 2396*5436921fSGabriel Fernandez [PLL3] = &ck_pll3_vco, 2397*5436921fSGabriel Fernandez [PLL4] = &ck_pll4_vco, 2398*5436921fSGabriel Fernandez [PLL1_P] = &ck_pll1p, 2399*5436921fSGabriel Fernandez [PLL2_P] = &ck_pll2p, 2400*5436921fSGabriel Fernandez [PLL2_Q] = &ck_pll2q, 2401*5436921fSGabriel Fernandez [PLL2_R] = &ck_pll2r, 2402*5436921fSGabriel Fernandez [PLL3_P] = &ck_pll3p, 2403*5436921fSGabriel Fernandez [PLL3_Q] = &ck_pll3q, 2404*5436921fSGabriel Fernandez [PLL3_R] = &ck_pll3r, 2405*5436921fSGabriel Fernandez [PLL4_P] = &ck_pll4p, 2406*5436921fSGabriel Fernandez [PLL4_Q] = &ck_pll4q, 2407*5436921fSGabriel Fernandez [PLL4_R] = &ck_pll4r, 2408*5436921fSGabriel Fernandez [PLL1P_DIV] = &ck_pll1p_div, 2409*5436921fSGabriel Fernandez [CK_MPU] = &ck_mpu, 2410*5436921fSGabriel Fernandez [CK_AXI] = &ck_axi, 2411*5436921fSGabriel Fernandez [CK_MLAHB] = &ck_mlahb, 2412*5436921fSGabriel Fernandez [CK_PER] = &ck_per, 2413*5436921fSGabriel Fernandez [PCLK1] = &ck_pclk1, 2414*5436921fSGabriel Fernandez [PCLK2] = &ck_pclk2, 2415*5436921fSGabriel Fernandez [PCLK3] = &ck_pclk3, 2416*5436921fSGabriel Fernandez [PCLK4] = &ck_pclk4, 2417*5436921fSGabriel Fernandez [PCLK5] = &ck_pclk5, 2418*5436921fSGabriel Fernandez [PCLK6] = &ck_pclk6, 2419*5436921fSGabriel Fernandez [CK_TIMG1] = &ck_timg1, 2420*5436921fSGabriel Fernandez [CK_TIMG2] = &ck_timg2, 2421*5436921fSGabriel Fernandez [CK_TIMG3] = &ck_timg3, 2422*5436921fSGabriel Fernandez [DDRC1] = &ck_ddrc1, 2423*5436921fSGabriel Fernandez [DDRC1LP] = &ck_ddrc1lp, 2424*5436921fSGabriel Fernandez [DDRPHYC] = &ck_ddrphyc, 2425*5436921fSGabriel Fernandez [DDRPHYCLP] = &ck_ddrphyclp, 2426*5436921fSGabriel Fernandez [DDRCAPB] = &ck_ddrcapb, 2427*5436921fSGabriel Fernandez [DDRCAPBLP] = &ck_ddrcapblp, 2428*5436921fSGabriel Fernandez [AXIDCG] = &ck_axidcg, 2429*5436921fSGabriel Fernandez [DDRPHYCAPB] = &ck_ddrphycapb, 2430*5436921fSGabriel Fernandez [DDRPHYCAPBLP] = &ck_ddrphycapblp, 2431*5436921fSGabriel Fernandez [SYSCFG] = &ck_syscfg, 2432*5436921fSGabriel Fernandez [DDRPERFM] = &ck_ddrperfm, 2433*5436921fSGabriel Fernandez [IWDG2] = &ck_iwdg2, 2434*5436921fSGabriel Fernandez [USBPHY_K] = &ck_usbphy_k, 2435*5436921fSGabriel Fernandez [USBO_K] = &ck_usbo_k, 2436*5436921fSGabriel Fernandez [RTCAPB] = &ck_rtcapb, 2437*5436921fSGabriel Fernandez [TZC] = &ck_tzc, 2438*5436921fSGabriel Fernandez [TZPC] = &ck_etzpcb, 2439*5436921fSGabriel Fernandez [IWDG1] = &ck_iwdg1apb, 2440*5436921fSGabriel Fernandez [BSEC] = &ck_bsec, 2441*5436921fSGabriel Fernandez [STGEN_K] = &ck_stgen_k, 2442*5436921fSGabriel Fernandez [USART1_K] = &ck_usart1_k, 2443*5436921fSGabriel Fernandez [USART2_K] = &ck_usart2_k, 2444*5436921fSGabriel Fernandez [I2C4_K] = &ck_i2c4_k, 2445*5436921fSGabriel Fernandez [TIM12_K] = &ck_tim12_k, 2446*5436921fSGabriel Fernandez [TIM15_K] = &ck_tim15_k, 2447*5436921fSGabriel Fernandez [RTC] = &ck_rtc, 2448*5436921fSGabriel Fernandez [GPIOA] = &ck_gpioa, 2449*5436921fSGabriel Fernandez [GPIOB] = &ck_gpiob, 2450*5436921fSGabriel Fernandez [GPIOC] = &ck_gpioc, 2451*5436921fSGabriel Fernandez [GPIOD] = &ck_gpiod, 2452*5436921fSGabriel Fernandez [GPIOE] = &ck_gpioe, 2453*5436921fSGabriel Fernandez [GPIOF] = &ck_gpiof, 2454*5436921fSGabriel Fernandez [GPIOG] = &ck_gpiog, 2455*5436921fSGabriel Fernandez [GPIOH] = &ck_gpioh, 2456*5436921fSGabriel Fernandez [GPIOI] = &ck_gpioi, 2457*5436921fSGabriel Fernandez [PKA] = &ck_pka, 2458*5436921fSGabriel Fernandez [SAES_K] = &ck_saes_k, 2459*5436921fSGabriel Fernandez [CRYP1] = &ck_cryp1, 2460*5436921fSGabriel Fernandez [HASH1] = &ck_hash1, 2461*5436921fSGabriel Fernandez [RNG1_K] = &ck_rng1_k, 2462*5436921fSGabriel Fernandez [BKPSRAM] = &ck_bkpsram, 2463*5436921fSGabriel Fernandez [SDMMC1_K] = &ck_sdmmc1_k, 2464*5436921fSGabriel Fernandez [SDMMC2_K] = &ck_sdmmc2_k, 2465*5436921fSGabriel Fernandez [CK_DBG] = &ck_dbg, 2466*5436921fSGabriel Fernandez [MCE] = &ck_mce, 2467*5436921fSGabriel Fernandez [TIM2_K] = &ck_tim2_k, 2468*5436921fSGabriel Fernandez [TIM3_K] = &ck_tim3_k, 2469*5436921fSGabriel Fernandez [TIM4_K] = &ck_tim4_k, 2470*5436921fSGabriel Fernandez [TIM5_K] = &ck_tim5_k, 2471*5436921fSGabriel Fernandez [TIM6_K] = &ck_tim6_k, 2472*5436921fSGabriel Fernandez [TIM7_K] = &ck_tim7_k, 2473*5436921fSGabriel Fernandez [TIM13_K] = &ck_tim13_k, 2474*5436921fSGabriel Fernandez [TIM14_K] = &ck_tim14_k, 2475*5436921fSGabriel Fernandez [TIM1_K] = &ck_tim1_k, 2476*5436921fSGabriel Fernandez [TIM8_K] = &ck_tim8_k, 2477*5436921fSGabriel Fernandez [TIM16_K] = &ck_tim16_k, 2478*5436921fSGabriel Fernandez [TIM17_K] = &ck_tim17_k, 2479*5436921fSGabriel Fernandez [LTDC_PX] = &ck_ltdc_px, 2480*5436921fSGabriel Fernandez [DMA1] = &ck_dma1, 2481*5436921fSGabriel Fernandez [DMA2] = &ck_dma2, 2482*5436921fSGabriel Fernandez [MDMA] = &ck_mdma, 2483*5436921fSGabriel Fernandez [ETH1MAC] = &ck_eth1mac, 2484*5436921fSGabriel Fernandez [USBH] = &ck_usbh, 2485*5436921fSGabriel Fernandez [VREF] = &ck_vref, 2486*5436921fSGabriel Fernandez [TMPSENS] = &ck_tmpsens, 2487*5436921fSGabriel Fernandez [PMBCTRL] = &ck_pmbctrl, 2488*5436921fSGabriel Fernandez [HDP] = &ck_hdp, 2489*5436921fSGabriel Fernandez [STGENRO] = &ck_stgenro, 2490*5436921fSGabriel Fernandez [DMAMUX1] = &ck_dmamux1, 2491*5436921fSGabriel Fernandez [DMAMUX2] = &ck_dmamux2, 2492*5436921fSGabriel Fernandez [DMA3] = &ck_dma3, 2493*5436921fSGabriel Fernandez [TSC] = &ck_tsc, 2494*5436921fSGabriel Fernandez [AXIMC] = &ck_aximc, 2495*5436921fSGabriel Fernandez [CRC1] = &ck_crc1, 2496*5436921fSGabriel Fernandez [ETH1TX] = &ck_eth1tx, 2497*5436921fSGabriel Fernandez [ETH1RX] = &ck_eth1rx, 2498*5436921fSGabriel Fernandez [ETH2TX] = &ck_eth2tx, 2499*5436921fSGabriel Fernandez [ETH2RX] = &ck_eth2rx, 2500*5436921fSGabriel Fernandez [ETH2MAC] = &ck_eth2mac, 2501*5436921fSGabriel Fernandez [USART3_K] = &ck_usart3_k, 2502*5436921fSGabriel Fernandez [UART4_K] = &ck_uart4_k, 2503*5436921fSGabriel Fernandez [UART5_K] = &ck_uart5_k, 2504*5436921fSGabriel Fernandez [UART7_K] = &ck_uart7_k, 2505*5436921fSGabriel Fernandez [UART8_K] = &ck_uart8_k, 2506*5436921fSGabriel Fernandez [USART6_K] = &ck_usart6_k, 2507*5436921fSGabriel Fernandez [FMC_K] = &ck_fmc_k, 2508*5436921fSGabriel Fernandez [QSPI_K] = &ck_qspi_k, 2509*5436921fSGabriel Fernandez [LPTIM1_K] = &ck_lptim1_k, 2510*5436921fSGabriel Fernandez [SPI2_K] = &ck_spi2_k, 2511*5436921fSGabriel Fernandez [SPI3_K] = &ck_spi3_k, 2512*5436921fSGabriel Fernandez [SPDIF_K] = &ck_spdif_k, 2513*5436921fSGabriel Fernandez [SPI1_K] = &ck_spi1_k, 2514*5436921fSGabriel Fernandez [SPI4_K] = &ck_spi4_k, 2515*5436921fSGabriel Fernandez [SPI5_K] = &ck_spi5_k, 2516*5436921fSGabriel Fernandez [SAI1_K] = &ck_sai1_k, 2517*5436921fSGabriel Fernandez [SAI2_K] = &ck_sai2_k, 2518*5436921fSGabriel Fernandez [DFSDM_K] = &ck_dfsdm_k, 2519*5436921fSGabriel Fernandez [FDCAN_K] = &ck_fdcan_k, 2520*5436921fSGabriel Fernandez [I2C1_K] = &ck_i2c1_k, 2521*5436921fSGabriel Fernandez [I2C2_K] = &ck_i2c2_k, 2522*5436921fSGabriel Fernandez [ADFSDM_K] = &ck_adfsdm_k, 2523*5436921fSGabriel Fernandez [LPTIM2_K] = &ck_lptim2_k, 2524*5436921fSGabriel Fernandez [LPTIM3_K] = &ck_lptim3_k, 2525*5436921fSGabriel Fernandez [LPTIM4_K] = &ck_lptim4_k, 2526*5436921fSGabriel Fernandez [LPTIM5_K] = &ck_lptim5_k, 2527*5436921fSGabriel Fernandez [I2C3_K] = &ck_i2c3_k, 2528*5436921fSGabriel Fernandez [I2C5_K] = &ck_i2c5_k, 2529*5436921fSGabriel Fernandez [DCMIPP_K] = &ck_dcmipp_k, 2530*5436921fSGabriel Fernandez [ADC1_K] = &ck_adc1_k, 2531*5436921fSGabriel Fernandez [ADC2_K] = &ck_adc2_k, 2532*5436921fSGabriel Fernandez [ETH1CK_K] = &ck_eth1ck_k, 2533*5436921fSGabriel Fernandez [ETH2CK_K] = &ck_eth2ck_k, 2534*5436921fSGabriel Fernandez [CK_MCO1] = &ck_mco1, 2535*5436921fSGabriel Fernandez [CK_MCO2] = &ck_mco2, 2536*5436921fSGabriel Fernandez [CK_TRACE] = &ck_trace, 2537*5436921fSGabriel Fernandez [CK_OFF] = &ck_off, 2538*5436921fSGabriel Fernandez [USB_PHY_48] = &ck_usb_phy_48Mhz, 2539*5436921fSGabriel Fernandez [I2S_CKIN] = &ck_i2sckin, 2540*5436921fSGabriel Fernandez }; 2541*5436921fSGabriel Fernandez 2542*5436921fSGabriel Fernandez static bool clk_stm32_clock_is_critical(struct clk *clk __maybe_unused) 2543*5436921fSGabriel Fernandez { 2544*5436921fSGabriel Fernandez struct clk *clk_criticals[] = { 2545*5436921fSGabriel Fernandez &ck_hsi, 2546*5436921fSGabriel Fernandez &ck_hse, 2547*5436921fSGabriel Fernandez &ck_csi, 2548*5436921fSGabriel Fernandez &ck_lsi, 2549*5436921fSGabriel Fernandez &ck_lse, 2550*5436921fSGabriel Fernandez &ck_pll2r, 2551*5436921fSGabriel Fernandez &ck_mpu, 2552*5436921fSGabriel Fernandez &ck_ddrc1, 2553*5436921fSGabriel Fernandez &ck_ddrc1lp, 2554*5436921fSGabriel Fernandez &ck_ddrphyc, 2555*5436921fSGabriel Fernandez &ck_ddrphyclp, 2556*5436921fSGabriel Fernandez &ck_ddrcapb, 2557*5436921fSGabriel Fernandez &ck_ddrcapblp, 2558*5436921fSGabriel Fernandez &ck_axidcg, 2559*5436921fSGabriel Fernandez &ck_ddrphycapb, 2560*5436921fSGabriel Fernandez &ck_ddrphycapblp, 2561*5436921fSGabriel Fernandez &ck_rtcapb, 2562*5436921fSGabriel Fernandez &ck_tzc, 2563*5436921fSGabriel Fernandez &ck_etzpcb, 2564*5436921fSGabriel Fernandez &ck_iwdg1apb, 2565*5436921fSGabriel Fernandez &ck_bsec, 2566*5436921fSGabriel Fernandez &ck_stgen_k, 2567*5436921fSGabriel Fernandez &ck_bkpsram, 2568*5436921fSGabriel Fernandez &ck_mce, 2569*5436921fSGabriel Fernandez &ck_mco1, 2570*5436921fSGabriel Fernandez &ck_rng1_k 2571*5436921fSGabriel Fernandez }; 2572*5436921fSGabriel Fernandez size_t i = 0; 2573*5436921fSGabriel Fernandez 2574*5436921fSGabriel Fernandez for (i = 0; i < ARRAY_SIZE(clk_criticals); i++) { 2575*5436921fSGabriel Fernandez struct clk *clk_critical = clk_criticals[i]; 2576*5436921fSGabriel Fernandez 2577*5436921fSGabriel Fernandez if (clk == clk_critical) 2578*5436921fSGabriel Fernandez return true; 2579*5436921fSGabriel Fernandez } 2580*5436921fSGabriel Fernandez 2581*5436921fSGabriel Fernandez return false; 2582*5436921fSGabriel Fernandez } 2583*5436921fSGabriel Fernandez 2584*5436921fSGabriel Fernandez static void clk_stm32_init_oscillators(const void *fdt, int node) 2585*5436921fSGabriel Fernandez { 2586*5436921fSGabriel Fernandez size_t i = 0; 2587*5436921fSGabriel Fernandez const char *name[6] = { "clk-hse", "clk-hsi", "clk-lse", 2588*5436921fSGabriel Fernandez "clk-lsi", "clk-csi", "clk-i2sin" }; 2589*5436921fSGabriel Fernandez struct clk *clks[6] = { &ck_hse, &ck_hsi, &ck_lse, 2590*5436921fSGabriel Fernandez &ck_lsi, &ck_csi, &ck_i2sckin }; 2591*5436921fSGabriel Fernandez 2592*5436921fSGabriel Fernandez for (i = 0; i < ARRAY_SIZE(clks); i++) { 2593*5436921fSGabriel Fernandez struct clk *clk = NULL; 2594*5436921fSGabriel Fernandez 2595*5436921fSGabriel Fernandez clk_dt_get_by_name(fdt, node, name[i], &clk); 2596*5436921fSGabriel Fernandez 2597*5436921fSGabriel Fernandez clks[i]->parents[0] = clk; 2598*5436921fSGabriel Fernandez } 2599*5436921fSGabriel Fernandez } 2600*5436921fSGabriel Fernandez 2601e5e793a6SGabriel Fernandez static struct stm32_pll_dt_cfg mp13_pll[PLL_NB]; 2602e5e793a6SGabriel Fernandez static struct stm32_clk_opp_dt_cfg mp13_clk_opp; 2603e5e793a6SGabriel Fernandez static struct stm32_osci_dt_cfg mp13_osci[NB_OSCILLATOR]; 2604e5e793a6SGabriel Fernandez static uint32_t mp13_clksrc[MUX_NB]; 2605e5e793a6SGabriel Fernandez static uint32_t mp13_clkdiv[DIV_NB]; 2606e5e793a6SGabriel Fernandez 2607e5e793a6SGabriel Fernandez static struct stm32_clk_platdata stm32mp13_clock_pdata = { 2608e5e793a6SGabriel Fernandez .osci = mp13_osci, 2609e5e793a6SGabriel Fernandez .nosci = NB_OSCILLATOR, 2610e5e793a6SGabriel Fernandez .pll = mp13_pll, 2611e5e793a6SGabriel Fernandez .opp = &mp13_clk_opp, 2612e5e793a6SGabriel Fernandez .npll = PLL_NB, 2613e5e793a6SGabriel Fernandez .clksrc = mp13_clksrc, 2614e5e793a6SGabriel Fernandez .nclksrc = MUX_NB, 2615e5e793a6SGabriel Fernandez .clkdiv = mp13_clkdiv, 2616e5e793a6SGabriel Fernandez .nclkdiv = DIV_NB, 2617e5e793a6SGabriel Fernandez }; 2618e5e793a6SGabriel Fernandez 2619e5e793a6SGabriel Fernandez static struct clk_stm32_priv stm32mp13_clock_data = { 2620e5e793a6SGabriel Fernandez .muxes = parent_mp13, 2621e5e793a6SGabriel Fernandez .nb_muxes = ARRAY_SIZE(parent_mp13), 2622e5e793a6SGabriel Fernandez .gates = gates_mp13, 2623e5e793a6SGabriel Fernandez .nb_gates = ARRAY_SIZE(gates_mp13), 2624e5e793a6SGabriel Fernandez .div = dividers_mp13, 2625e5e793a6SGabriel Fernandez .nb_div = ARRAY_SIZE(dividers_mp13), 2626e5e793a6SGabriel Fernandez .pdata = &stm32mp13_clock_pdata, 2627*5436921fSGabriel Fernandez .nb_clk_refs = STM32MP13_ALL_CLK_NB, 2628*5436921fSGabriel Fernandez .clk_refs = stm32mp13_clk_provided, 2629*5436921fSGabriel Fernandez .is_critical = clk_stm32_clock_is_critical, 2630e5e793a6SGabriel Fernandez }; 2631e5e793a6SGabriel Fernandez 2632e5e793a6SGabriel Fernandez static TEE_Result stm32mp13_clk_probe(const void *fdt, int node, 2633e5e793a6SGabriel Fernandez const void *compat_data __unused) 2634e5e793a6SGabriel Fernandez { 2635e5e793a6SGabriel Fernandez TEE_Result res = TEE_ERROR_GENERIC; 2636e5e793a6SGabriel Fernandez int fdt_rc = 0; 2637e5e793a6SGabriel Fernandez int rc = 0; 2638e5e793a6SGabriel Fernandez struct clk_stm32_priv *priv = &stm32mp13_clock_data; 2639e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata = &stm32mp13_clock_pdata; 2640e5e793a6SGabriel Fernandez 2641e5e793a6SGabriel Fernandez fdt_rc = stm32_clk_parse_fdt(fdt, node, pdata); 2642e5e793a6SGabriel Fernandez if (fdt_rc) { 2643e5e793a6SGabriel Fernandez EMSG("Failed to parse clock node: %d", fdt_rc); 2644e5e793a6SGabriel Fernandez return TEE_ERROR_GENERIC; 2645e5e793a6SGabriel Fernandez } 2646e5e793a6SGabriel Fernandez 2647e5e793a6SGabriel Fernandez res = clk_stm32_init(priv, stm32_rcc_base()); 2648e5e793a6SGabriel Fernandez if (res) 2649e5e793a6SGabriel Fernandez return res; 2650e5e793a6SGabriel Fernandez 2651e5e793a6SGabriel Fernandez rc = stm32mp1_init_clock_tree(priv, pdata); 2652e5e793a6SGabriel Fernandez if (rc) 2653e5e793a6SGabriel Fernandez return TEE_ERROR_GENERIC; 2654e5e793a6SGabriel Fernandez 2655*5436921fSGabriel Fernandez clk_stm32_init_oscillators(fdt, node); 2656*5436921fSGabriel Fernandez 2657*5436921fSGabriel Fernandez stm32mp_clk_provider_probe_final(fdt, node, priv); 2658*5436921fSGabriel Fernandez 2659e5e793a6SGabriel Fernandez return TEE_SUCCESS; 2660e5e793a6SGabriel Fernandez } 2661e5e793a6SGabriel Fernandez 2662e5e793a6SGabriel Fernandez CLK_DT_DECLARE(stm32mp13_clk, "st,stm32mp13-rcc", stm32mp13_clk_probe); 2663