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) || 1442f354a5d8SGatien Chevallier 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 1460f354a5d8SGatien Chevallier 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); 1489*95f2142bSEtienne Carriere if (fdt_err) { 1490*95f2142bSEtienne Carriere if (fdt_err == -FDT_ERR_NOTFOUND) { 1491*95f2142bSEtienne Carriere /* Oscillator not found means it is not wired */ 1492*95f2142bSEtienne Carriere osci->freq = 0; 1493*95f2142bSEtienne Carriere } else { 1494e5e793a6SGabriel Fernandez panic(); 1495e5e793a6SGabriel Fernandez } 1496*95f2142bSEtienne Carriere } 1497*95f2142bSEtienne Carriere } 1498e5e793a6SGabriel Fernandez 1499e5e793a6SGabriel Fernandez return 0; 1500e5e793a6SGabriel Fernandez } 1501e5e793a6SGabriel Fernandez 1502e5e793a6SGabriel Fernandez static int clk_stm32_load_vco_config_fdt(const void *fdt, int subnode, 1503e5e793a6SGabriel Fernandez struct stm32_pll_vco *vco) 1504e5e793a6SGabriel Fernandez { 1505e5e793a6SGabriel Fernandez int ret = 0; 1506e5e793a6SGabriel Fernandez 1507f354a5d8SGatien Chevallier ret = fdt_read_uint32_array(fdt, subnode, "divmn", vco->div_mn, 1508e5e793a6SGabriel Fernandez PLL_DIV_MN_NB); 1509e5e793a6SGabriel Fernandez if (ret != 0) 1510e5e793a6SGabriel Fernandez return ret; 1511e5e793a6SGabriel Fernandez 1512f354a5d8SGatien Chevallier ret = fdt_read_uint32_array(fdt, subnode, "csg", vco->csg, 1513e5e793a6SGabriel Fernandez PLL_CSG_NB); 1514e5e793a6SGabriel Fernandez 1515e5e793a6SGabriel Fernandez vco->csg_enabled = (ret == 0); 1516e5e793a6SGabriel Fernandez 1517e5e793a6SGabriel Fernandez if (ret == -FDT_ERR_NOTFOUND) 1518e5e793a6SGabriel Fernandez ret = 0; 1519e5e793a6SGabriel Fernandez 1520e5e793a6SGabriel Fernandez if (ret != 0) 1521e5e793a6SGabriel Fernandez return ret; 1522e5e793a6SGabriel Fernandez 1523e5e793a6SGabriel Fernandez vco->status = RCC_PLLNCR_DIVPEN | RCC_PLLNCR_DIVQEN | 1524e5e793a6SGabriel Fernandez RCC_PLLNCR_DIVREN | RCC_PLLNCR_PLLON; 1525e5e793a6SGabriel Fernandez 1526f354a5d8SGatien Chevallier vco->frac = fdt_read_uint32_default(fdt, subnode, "frac", 0); 1527e5e793a6SGabriel Fernandez 1528f354a5d8SGatien Chevallier vco->src = fdt_read_uint32_default(fdt, subnode, "src", UINT32_MAX); 1529e5e793a6SGabriel Fernandez 1530e5e793a6SGabriel Fernandez return 0; 1531e5e793a6SGabriel Fernandez } 1532e5e793a6SGabriel Fernandez 1533e5e793a6SGabriel Fernandez static int clk_stm32_load_output_config_fdt(const void *fdt, int subnode, 1534e5e793a6SGabriel Fernandez struct stm32_pll_output *output) 1535e5e793a6SGabriel Fernandez { 1536f354a5d8SGatien Chevallier return fdt_read_uint32_array(fdt, subnode, "st,pll_div_pqr", 1537e5e793a6SGabriel Fernandez output->output, (int)PLL_DIV_PQR_NB); 1538e5e793a6SGabriel Fernandez } 1539e5e793a6SGabriel Fernandez 1540e5e793a6SGabriel Fernandez static int clk_stm32_parse_pll_fdt(const void *fdt, int subnode, 1541e5e793a6SGabriel Fernandez struct stm32_pll_dt_cfg *pll) 1542e5e793a6SGabriel Fernandez { 1543e5e793a6SGabriel Fernandez const fdt32_t *cuint = NULL; 1544e5e793a6SGabriel Fernandez int subnode_pll = 0; 1545e5e793a6SGabriel Fernandez int subnode_vco = 0; 1546e5e793a6SGabriel Fernandez int err = 0; 1547e5e793a6SGabriel Fernandez 1548e5e793a6SGabriel Fernandez cuint = fdt_getprop(fdt, subnode, "st,pll", NULL); 1549e5e793a6SGabriel Fernandez if (!cuint) 1550e5e793a6SGabriel Fernandez return -FDT_ERR_NOTFOUND; 1551e5e793a6SGabriel Fernandez 1552e5e793a6SGabriel Fernandez subnode_pll = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(*cuint)); 1553e5e793a6SGabriel Fernandez if (subnode_pll < 0) 1554e5e793a6SGabriel Fernandez return -FDT_ERR_NOTFOUND; 1555e5e793a6SGabriel Fernandez 1556e5e793a6SGabriel Fernandez cuint = fdt_getprop(fdt, subnode_pll, "st,pll_vco", NULL); 1557e5e793a6SGabriel Fernandez if (!cuint) 1558e5e793a6SGabriel Fernandez return -FDT_ERR_NOTFOUND; 1559e5e793a6SGabriel Fernandez 1560e5e793a6SGabriel Fernandez subnode_vco = fdt_node_offset_by_phandle(fdt, fdt32_to_cpu(*cuint)); 1561e5e793a6SGabriel Fernandez if (subnode_vco < 0) 1562e5e793a6SGabriel Fernandez return -FDT_ERR_NOTFOUND; 1563e5e793a6SGabriel Fernandez 1564e5e793a6SGabriel Fernandez err = clk_stm32_load_vco_config_fdt(fdt, subnode_vco, &pll->vco); 1565e5e793a6SGabriel Fernandez if (err != 0) 1566e5e793a6SGabriel Fernandez return err; 1567e5e793a6SGabriel Fernandez 1568e5e793a6SGabriel Fernandez err = clk_stm32_load_output_config_fdt(fdt, subnode_pll, &pll->output); 1569e5e793a6SGabriel Fernandez if (err != 0) 1570e5e793a6SGabriel Fernandez return err; 1571e5e793a6SGabriel Fernandez 1572e5e793a6SGabriel Fernandez return 0; 1573e5e793a6SGabriel Fernandez } 1574e5e793a6SGabriel Fernandez 1575e5e793a6SGabriel Fernandez static int stm32_clk_parse_fdt_all_pll(const void *fdt, int node, 1576e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata) 1577e5e793a6SGabriel Fernandez { 1578e5e793a6SGabriel Fernandez size_t i = 0; 1579e5e793a6SGabriel Fernandez 1580e5e793a6SGabriel Fernandez for (i = PLL1_ID; i < pdata->npll; i++) { 1581e5e793a6SGabriel Fernandez struct stm32_pll_dt_cfg *pll = pdata->pll + i; 1582e5e793a6SGabriel Fernandez char name[RCC_PLL_NAME_SIZE] = { 0 }; 1583e5e793a6SGabriel Fernandez int subnode = 0; 1584e5e793a6SGabriel Fernandez int err = 0; 1585e5e793a6SGabriel Fernandez 1586e5e793a6SGabriel Fernandez snprintf(name, sizeof(name), "st,pll@%d", i); 1587e5e793a6SGabriel Fernandez 1588e5e793a6SGabriel Fernandez subnode = fdt_subnode_offset(fdt, node, name); 1589e5e793a6SGabriel Fernandez if (subnode < 0) 1590e5e793a6SGabriel Fernandez continue; 1591e5e793a6SGabriel Fernandez 1592e5e793a6SGabriel Fernandez err = clk_stm32_parse_pll_fdt(fdt, subnode, pll); 1593e5e793a6SGabriel Fernandez if (err != 0) 1594e5e793a6SGabriel Fernandez panic(); 1595e5e793a6SGabriel Fernandez } 1596e5e793a6SGabriel Fernandez 1597e5e793a6SGabriel Fernandez return 0; 1598e5e793a6SGabriel Fernandez } 1599e5e793a6SGabriel Fernandez 1600e5e793a6SGabriel Fernandez static int stm32_clk_parse_fdt_opp(const void *fdt, int node, 1601e5e793a6SGabriel Fernandez const char *opp_name, 1602e5e793a6SGabriel Fernandez struct stm32_clk_opp_cfg *opp_cfg) 1603e5e793a6SGabriel Fernandez { 1604e5e793a6SGabriel Fernandez int subnode = 0; 1605e5e793a6SGabriel Fernandez int nb_opp = 0; 1606e5e793a6SGabriel Fernandez int ret = 0; 1607e5e793a6SGabriel Fernandez 1608e5e793a6SGabriel Fernandez node = fdt_subnode_offset(fdt, node, opp_name); 1609e5e793a6SGabriel Fernandez if (node == -FDT_ERR_NOTFOUND) 1610e5e793a6SGabriel Fernandez return 0; 1611e5e793a6SGabriel Fernandez if (node < 0) 1612e5e793a6SGabriel Fernandez return node; 1613e5e793a6SGabriel Fernandez 1614e5e793a6SGabriel Fernandez fdt_for_each_subnode(subnode, fdt, node) { 1615e5e793a6SGabriel Fernandez if (nb_opp >= MAX_OPP) { 1616e5e793a6SGabriel Fernandez EMSG("%d MAX opp in %s", MAX_OPP, opp_name); 1617e5e793a6SGabriel Fernandez panic(); 1618e5e793a6SGabriel Fernandez } 1619e5e793a6SGabriel Fernandez 1620f354a5d8SGatien Chevallier opp_cfg->frq = fdt_read_uint32_default(fdt, subnode, 1621e5e793a6SGabriel Fernandez "hz", 1622e5e793a6SGabriel Fernandez UINT32_MAX); 1623e5e793a6SGabriel Fernandez 1624f354a5d8SGatien Chevallier opp_cfg->src = fdt_read_uint32_default(fdt, subnode, 1625e5e793a6SGabriel Fernandez "st,clksrc", 1626e5e793a6SGabriel Fernandez UINT32_MAX); 1627e5e793a6SGabriel Fernandez 1628f354a5d8SGatien Chevallier opp_cfg->div = fdt_read_uint32_default(fdt, subnode, 1629e5e793a6SGabriel Fernandez "st,clkdiv", 1630e5e793a6SGabriel Fernandez UINT32_MAX); 1631e5e793a6SGabriel Fernandez 1632e5e793a6SGabriel Fernandez ret = clk_stm32_parse_pll_fdt(fdt, subnode, &opp_cfg->pll_cfg); 1633e5e793a6SGabriel Fernandez if (ret) 1634e5e793a6SGabriel Fernandez return ret; 1635e5e793a6SGabriel Fernandez 1636e5e793a6SGabriel Fernandez opp_cfg++; 1637e5e793a6SGabriel Fernandez nb_opp++; 1638e5e793a6SGabriel Fernandez } 1639e5e793a6SGabriel Fernandez 1640e5e793a6SGabriel Fernandez return 0; 1641e5e793a6SGabriel Fernandez } 1642e5e793a6SGabriel Fernandez 1643e5e793a6SGabriel Fernandez static int stm32_clk_parse_fdt_all_opp(const void *fdt, int node, 1644e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata) 1645e5e793a6SGabriel Fernandez { 1646e5e793a6SGabriel Fernandez struct stm32_clk_opp_dt_cfg *opp = pdata->opp; 1647e5e793a6SGabriel Fernandez int ret = 0; 1648e5e793a6SGabriel Fernandez 1649e5e793a6SGabriel Fernandez node = fdt_subnode_offset(fdt, node, "st,clk_opp"); 1650e5e793a6SGabriel Fernandez /* No opp are defined */ 1651e5e793a6SGabriel Fernandez if (node == -FDT_ERR_NOTFOUND) 1652e5e793a6SGabriel Fernandez return 0; 1653e5e793a6SGabriel Fernandez if (node < 0) 1654e5e793a6SGabriel Fernandez return node; 1655e5e793a6SGabriel Fernandez 1656e5e793a6SGabriel Fernandez ret = stm32_clk_parse_fdt_opp(fdt, node, "st,ck_mpu", opp->mpu_opp); 1657e5e793a6SGabriel Fernandez if (ret) 1658e5e793a6SGabriel Fernandez return ret; 1659e5e793a6SGabriel Fernandez 1660e5e793a6SGabriel Fernandez ret = stm32_clk_parse_fdt_opp(fdt, node, "st,ck_axi", opp->axi_opp); 1661e5e793a6SGabriel Fernandez if (ret) 1662e5e793a6SGabriel Fernandez return ret; 1663e5e793a6SGabriel Fernandez 1664e5e793a6SGabriel Fernandez ret = stm32_clk_parse_fdt_opp(fdt, node, "st,ck_mlahbs", 1665e5e793a6SGabriel Fernandez opp->mlahbs_opp); 1666e5e793a6SGabriel Fernandez if (ret) 1667e5e793a6SGabriel Fernandez return ret; 1668e5e793a6SGabriel Fernandez 1669e5e793a6SGabriel Fernandez return 0; 1670e5e793a6SGabriel Fernandez } 1671e5e793a6SGabriel Fernandez 1672e5e793a6SGabriel Fernandez static int stm32_clk_parse_fdt(const void *fdt, int node, 1673e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata) 1674e5e793a6SGabriel Fernandez { 1675e5e793a6SGabriel Fernandez int err = 0; 1676e5e793a6SGabriel Fernandez 1677e5e793a6SGabriel Fernandez err = stm32_clk_parse_fdt_all_oscillator(fdt, node, pdata); 1678e5e793a6SGabriel Fernandez if (err != 0) 1679e5e793a6SGabriel Fernandez return err; 1680e5e793a6SGabriel Fernandez 1681e5e793a6SGabriel Fernandez err = stm32_clk_parse_fdt_all_pll(fdt, node, pdata); 1682e5e793a6SGabriel Fernandez if (err != 0) 1683e5e793a6SGabriel Fernandez return err; 1684e5e793a6SGabriel Fernandez 1685e5e793a6SGabriel Fernandez err = stm32_clk_parse_fdt_all_opp(fdt, node, pdata); 1686e5e793a6SGabriel Fernandez if (err != 0) 1687e5e793a6SGabriel Fernandez return err; 1688e5e793a6SGabriel Fernandez 1689e5e793a6SGabriel Fernandez err = clk_stm32_parse_fdt_by_name(fdt, node, "st,clkdiv", pdata->clkdiv, 1690e5e793a6SGabriel Fernandez &pdata->nclkdiv); 1691e5e793a6SGabriel Fernandez if (err != 0) 1692e5e793a6SGabriel Fernandez return err; 1693e5e793a6SGabriel Fernandez 1694e5e793a6SGabriel Fernandez err = clk_stm32_parse_fdt_by_name(fdt, node, "st,clksrc", pdata->clksrc, 1695e5e793a6SGabriel Fernandez &pdata->nclksrc); 1696e5e793a6SGabriel Fernandez if (err != 0) 1697e5e793a6SGabriel Fernandez return err; 1698e5e793a6SGabriel Fernandez 1699e5e793a6SGabriel Fernandez return 0; 1700e5e793a6SGabriel Fernandez } 1701e5e793a6SGabriel Fernandez 17025436921fSGabriel Fernandez struct clk_stm32_pll_cfg { 17035436921fSGabriel Fernandez uint32_t reg_pllxcr; 17045436921fSGabriel Fernandez int gate_id; 17055436921fSGabriel Fernandez int mux_id; 17065436921fSGabriel Fernandez }; 17075436921fSGabriel Fernandez 17085436921fSGabriel Fernandez static size_t clk_stm32_pll_get_parent(struct clk *clk) 17095436921fSGabriel Fernandez { 17105436921fSGabriel Fernandez struct clk_stm32_pll_cfg *cfg = clk->priv; 17115436921fSGabriel Fernandez 17125436921fSGabriel Fernandez return stm32_mux_get_parent(cfg->mux_id); 17135436921fSGabriel Fernandez } 17145436921fSGabriel Fernandez 17155436921fSGabriel Fernandez static unsigned long clk_stm32_pll_get_rate(struct clk *clk, 17165436921fSGabriel Fernandez unsigned long prate) 17175436921fSGabriel Fernandez { 17185436921fSGabriel Fernandez struct clk_stm32_priv *priv = clk_stm32_get_priv(); 17195436921fSGabriel Fernandez struct clk_stm32_pll_cfg *cfg = clk->priv; 17205436921fSGabriel Fernandez uintptr_t pll_base = priv->base + cfg->reg_pllxcr; 17215436921fSGabriel Fernandez uint32_t cfgr1 = 0; 17225436921fSGabriel Fernandez uint32_t fracr = 0; 17235436921fSGabriel Fernandez uint32_t divm = 0; 17245436921fSGabriel Fernandez uint32_t divn = 0; 17255436921fSGabriel Fernandez unsigned long fvco = 0UL; 17265436921fSGabriel Fernandez 17275436921fSGabriel Fernandez cfgr1 = io_read32(pll_base + RCC_OFFSET_PLLXCFGR1); 17285436921fSGabriel Fernandez fracr = io_read32(pll_base + RCC_OFFSET_PLLXFRACR); 17295436921fSGabriel Fernandez 17305436921fSGabriel Fernandez divm = (cfgr1 & (RCC_PLLNCFGR1_DIVM_MASK)) >> RCC_PLLNCFGR1_DIVM_SHIFT; 17315436921fSGabriel Fernandez divn = cfgr1 & RCC_PLLNCFGR1_DIVN_MASK; 17325436921fSGabriel Fernandez 17335436921fSGabriel Fernandez /* 17345436921fSGabriel Fernandez * With FRACV : 17355436921fSGabriel Fernandez * Fvco = Fck_ref * ((DIVN + 1) + FRACV / 2^13) / (DIVM + 1) 17365436921fSGabriel Fernandez * Without FRACV 17375436921fSGabriel Fernandez * Fvco = Fck_ref * ((DIVN + 1) / (DIVM + 1) 17385436921fSGabriel Fernandez */ 17395436921fSGabriel Fernandez if ((fracr & RCC_PLLNFRACR_FRACLE) != 0U) { 17405436921fSGabriel Fernandez uint32_t fracv = (fracr & RCC_PLLNFRACR_FRACV_MASK) >> 17415436921fSGabriel Fernandez RCC_PLLNFRACR_FRACV_SHIFT; 17425436921fSGabriel Fernandez unsigned long long numerator = 0UL; 17435436921fSGabriel Fernandez unsigned long long denominator = 0UL; 17445436921fSGabriel Fernandez 17455436921fSGabriel Fernandez numerator = (((unsigned long long)divn + 1U) << 13) + fracv; 17465436921fSGabriel Fernandez numerator = prate * numerator; 17475436921fSGabriel Fernandez denominator = ((unsigned long long)divm + 1U) << 13; 17485436921fSGabriel Fernandez fvco = (unsigned long)(numerator / denominator); 17495436921fSGabriel Fernandez } else { 17505436921fSGabriel Fernandez fvco = (unsigned long)(prate * (divn + 1U) / (divm + 1U)); 17515436921fSGabriel Fernandez } 17525436921fSGabriel Fernandez 17535436921fSGabriel Fernandez return fvco; 17545436921fSGabriel Fernandez }; 17555436921fSGabriel Fernandez 17565436921fSGabriel Fernandez static bool clk_stm32_pll_is_enabled(struct clk *clk) 17575436921fSGabriel Fernandez { 17585436921fSGabriel Fernandez struct clk_stm32_pll_cfg *cfg = clk->priv; 17595436921fSGabriel Fernandez 17605436921fSGabriel Fernandez return stm32_gate_is_enabled(cfg->gate_id); 17615436921fSGabriel Fernandez } 17625436921fSGabriel Fernandez 17635436921fSGabriel Fernandez static TEE_Result clk_stm32_pll_enable(struct clk *clk) 17645436921fSGabriel Fernandez { 17655436921fSGabriel Fernandez struct clk_stm32_pll_cfg *cfg = clk->priv; 17665436921fSGabriel Fernandez 17675436921fSGabriel Fernandez if (clk_stm32_pll_is_enabled(clk)) 17685436921fSGabriel Fernandez return TEE_SUCCESS; 17695436921fSGabriel Fernandez 17705436921fSGabriel Fernandez return stm32_gate_rdy_enable(cfg->gate_id); 17715436921fSGabriel Fernandez } 17725436921fSGabriel Fernandez 17735436921fSGabriel Fernandez static void clk_stm32_pll_disable(struct clk *clk) 17745436921fSGabriel Fernandez { 17755436921fSGabriel Fernandez struct clk_stm32_pll_cfg *cfg = clk->priv; 17765436921fSGabriel Fernandez struct clk_stm32_priv *priv = clk_stm32_get_priv(); 17775436921fSGabriel Fernandez uintptr_t pll_base = priv->base + cfg->reg_pllxcr; 17785436921fSGabriel Fernandez 17795436921fSGabriel Fernandez if (!clk_stm32_pll_is_enabled(clk)) 17805436921fSGabriel Fernandez return; 17815436921fSGabriel Fernandez 17825436921fSGabriel Fernandez /* Stop all output */ 17835436921fSGabriel Fernandez io_clrbits32(pll_base, RCC_PLLNCR_DIVPEN | RCC_PLLNCR_DIVQEN | 17845436921fSGabriel Fernandez RCC_PLLNCR_DIVREN); 17855436921fSGabriel Fernandez 17865436921fSGabriel Fernandez stm32_gate_rdy_disable(cfg->gate_id); 17875436921fSGabriel Fernandez } 17885436921fSGabriel Fernandez 17895436921fSGabriel Fernandez static const struct clk_ops clk_stm32_pll_ops = { 17905436921fSGabriel Fernandez .get_parent = clk_stm32_pll_get_parent, 17915436921fSGabriel Fernandez .get_rate = clk_stm32_pll_get_rate, 17925436921fSGabriel Fernandez .enable = clk_stm32_pll_enable, 17935436921fSGabriel Fernandez .disable = clk_stm32_pll_disable, 17945436921fSGabriel Fernandez }; 17955436921fSGabriel Fernandez 17965436921fSGabriel Fernandez static struct 17975436921fSGabriel Fernandez stm32_clk_opp_cfg *clk_stm32_get_opp_config(struct stm32_clk_opp_cfg *opp_cfg, 17985436921fSGabriel Fernandez unsigned long rate) 17995436921fSGabriel Fernandez { 18005436921fSGabriel Fernandez unsigned int i = 0; 18015436921fSGabriel Fernandez 18025436921fSGabriel Fernandez for (i = 0; i < MAX_OPP; i++, opp_cfg++) { 18035436921fSGabriel Fernandez if (opp_cfg->frq == 0UL) 18045436921fSGabriel Fernandez break; 18055436921fSGabriel Fernandez 18065436921fSGabriel Fernandez if (opp_cfg->frq == rate) 18075436921fSGabriel Fernandez return opp_cfg; 18085436921fSGabriel Fernandez } 18095436921fSGabriel Fernandez 18105436921fSGabriel Fernandez return NULL; 18115436921fSGabriel Fernandez } 18125436921fSGabriel Fernandez 18135436921fSGabriel Fernandez static TEE_Result clk_stm32_pll1_set_rate(struct clk *clk __maybe_unused, 18145436921fSGabriel Fernandez unsigned long rate, 18155436921fSGabriel Fernandez unsigned long prate __maybe_unused) 18165436921fSGabriel Fernandez { 18175436921fSGabriel Fernandez const struct stm32_clk_pll *pll = clk_stm32_pll_data(PLL1_ID); 18185436921fSGabriel Fernandez struct clk_stm32_priv *priv = clk_stm32_get_priv(); 18195436921fSGabriel Fernandez struct stm32_clk_platdata *pdata = priv->pdata; 18205436921fSGabriel Fernandez struct stm32_pll_dt_cfg *pll_conf = NULL; 18215436921fSGabriel Fernandez struct stm32_clk_opp_cfg *opp = NULL; 18225436921fSGabriel Fernandez int config_on_the_fly = -1; 18235436921fSGabriel Fernandez int err = 0; 18245436921fSGabriel Fernandez size_t sel = stm32_mux_get_parent(MUX_MPU); 18255436921fSGabriel Fernandez 18265436921fSGabriel Fernandez opp = clk_stm32_get_opp_config(pdata->opp->mpu_opp, rate); 18275436921fSGabriel Fernandez if (!opp) 18285436921fSGabriel Fernandez return TEE_ERROR_GENERIC; 18295436921fSGabriel Fernandez 18305436921fSGabriel Fernandez pll_conf = &opp->pll_cfg; 18315436921fSGabriel Fernandez 18325436921fSGabriel Fernandez err = clk_stm32_is_pll_config_on_the_fly(priv, pll, pll_conf, 18335436921fSGabriel Fernandez &config_on_the_fly); 18345436921fSGabriel Fernandez if (err) 18355436921fSGabriel Fernandez return TEE_ERROR_GENERIC; 18365436921fSGabriel Fernandez 18375436921fSGabriel Fernandez if (config_on_the_fly == 1) 18385436921fSGabriel Fernandez return TEE_SUCCESS; 18395436921fSGabriel Fernandez 18405436921fSGabriel Fernandez if (config_on_the_fly == -1) { 18415436921fSGabriel Fernandez /* Switch to HSI and stop PLL1 before reconfiguration */ 18425436921fSGabriel Fernandez if (stm32_mux_set_parent(MUX_MPU, 0)) 18435436921fSGabriel Fernandez return TEE_ERROR_GENERIC; 18445436921fSGabriel Fernandez 18455436921fSGabriel Fernandez stm32_gate_disable(GATE_PLL1_DIVP); 18465436921fSGabriel Fernandez stm32_gate_rdy_disable(GATE_PLL1); 18475436921fSGabriel Fernandez clk_stm32_pll_config_vco(priv, pll, &pll_conf->vco); 18485436921fSGabriel Fernandez } 18495436921fSGabriel Fernandez 18505436921fSGabriel Fernandez clk_stm32_pll_config_out(priv, pll, &pll_conf->output); 18515436921fSGabriel Fernandez if (stm32_gate_rdy_enable(GATE_PLL1)) { 18525436921fSGabriel Fernandez EMSG("timeout to enable PLL1 clock"); 18535436921fSGabriel Fernandez panic(); 18545436921fSGabriel Fernandez } 18555436921fSGabriel Fernandez stm32_gate_enable(GATE_PLL1_DIVP); 18565436921fSGabriel Fernandez 18575436921fSGabriel Fernandez /* Restore MPU source */ 18585436921fSGabriel Fernandez if (stm32_mux_set_parent(MUX_MPU, sel)) 18595436921fSGabriel Fernandez return TEE_ERROR_GENERIC; 18605436921fSGabriel Fernandez 18615436921fSGabriel Fernandez return TEE_SUCCESS; 18625436921fSGabriel Fernandez } 18635436921fSGabriel Fernandez 18645436921fSGabriel Fernandez static const struct clk_ops clk_stm32_pll1_ops = { 18655436921fSGabriel Fernandez .set_rate = clk_stm32_pll1_set_rate, 18665436921fSGabriel Fernandez .get_parent = clk_stm32_pll_get_parent, 18675436921fSGabriel Fernandez .get_rate = clk_stm32_pll_get_rate, 18685436921fSGabriel Fernandez .enable = clk_stm32_pll_enable, 18695436921fSGabriel Fernandez .disable = clk_stm32_pll_disable, 18705436921fSGabriel Fernandez }; 18715436921fSGabriel Fernandez 18725436921fSGabriel Fernandez static const struct clk_ops clk_stm32_pll1p_ops = { 18735436921fSGabriel Fernandez .get_rate = clk_stm32_composite_get_rate, 18745436921fSGabriel Fernandez .enable = clk_stm32_composite_gate_enable, 18755436921fSGabriel Fernandez .disable = clk_stm32_composite_gate_disable, 18765436921fSGabriel Fernandez }; 18775436921fSGabriel Fernandez 18785436921fSGabriel Fernandez static const struct clk_ops clk_stm32_mpu_ops = { 18795436921fSGabriel Fernandez .get_parent = clk_stm32_composite_get_parent, 18805436921fSGabriel Fernandez .set_parent = clk_stm32_composite_set_parent, 18815436921fSGabriel Fernandez }; 18825436921fSGabriel Fernandez 18835436921fSGabriel Fernandez static const struct clk_ops clk_stm32_axi_ops = { 18845436921fSGabriel Fernandez .get_parent = clk_stm32_composite_get_parent, 18855436921fSGabriel Fernandez .set_parent = clk_stm32_composite_set_parent, 18865436921fSGabriel Fernandez .set_rate = clk_stm32_composite_set_rate, 18875436921fSGabriel Fernandez .get_rate = clk_stm32_composite_get_rate, 18885436921fSGabriel Fernandez }; 18895436921fSGabriel Fernandez 18905436921fSGabriel Fernandez const struct clk_ops clk_stm32_mlahb_ops = { 18915436921fSGabriel Fernandez .get_parent = clk_stm32_composite_get_parent, 18925436921fSGabriel Fernandez .set_parent = clk_stm32_composite_set_parent, 18935436921fSGabriel Fernandez .set_rate = clk_stm32_composite_set_rate, 18945436921fSGabriel Fernandez .get_rate = clk_stm32_composite_get_rate, 18955436921fSGabriel Fernandez }; 18965436921fSGabriel Fernandez 18975436921fSGabriel Fernandez #define APB_DIV_MASK GENMASK_32(2, 0) 18985436921fSGabriel Fernandez #define TIM_PRE_MASK BIT(0) 18995436921fSGabriel Fernandez 19005436921fSGabriel Fernandez static unsigned long ck_timer_get_rate_ops(struct clk *clk, unsigned long prate) 19015436921fSGabriel Fernandez { 19025436921fSGabriel Fernandez struct clk_stm32_priv *priv = clk_stm32_get_priv(); 19035436921fSGabriel Fernandez struct clk_stm32_timer_cfg *cfg = clk->priv; 19045436921fSGabriel Fernandez uint32_t prescaler, timpre; 19055436921fSGabriel Fernandez uintptr_t rcc_base = priv->base; 19065436921fSGabriel Fernandez 19075436921fSGabriel Fernandez prescaler = io_read32(rcc_base + cfg->apbdiv) & APB_DIV_MASK; 19085436921fSGabriel Fernandez 19095436921fSGabriel Fernandez timpre = io_read32(rcc_base + cfg->timpre) & TIM_PRE_MASK; 19105436921fSGabriel Fernandez 19115436921fSGabriel Fernandez if (prescaler == 0U) 19125436921fSGabriel Fernandez return prate; 19135436921fSGabriel Fernandez 19145436921fSGabriel Fernandez return prate * (timpre + 1U) * 2U; 19155436921fSGabriel Fernandez }; 19165436921fSGabriel Fernandez 19175436921fSGabriel Fernandez const struct clk_ops ck_timer_ops = { 19185436921fSGabriel Fernandez .get_rate = ck_timer_get_rate_ops, 19195436921fSGabriel Fernandez }; 19205436921fSGabriel Fernandez 19215436921fSGabriel Fernandez #define STM32_TIMER(_name, _parent, _flags, _apbdiv, _timpre)\ 19225436921fSGabriel Fernandez struct clk _name = {\ 19235436921fSGabriel Fernandez .ops = &ck_timer_ops,\ 19245436921fSGabriel Fernandez .priv = &(struct clk_stm32_timer_cfg) {\ 19255436921fSGabriel Fernandez .apbdiv = (_apbdiv),\ 19265436921fSGabriel Fernandez .timpre = (_timpre),\ 19275436921fSGabriel Fernandez },\ 19285436921fSGabriel Fernandez .name = #_name,\ 19295436921fSGabriel Fernandez .flags = (_flags),\ 19305436921fSGabriel Fernandez .num_parents = 1,\ 19315436921fSGabriel Fernandez .parents = { _parent },\ 19325436921fSGabriel Fernandez } 19335436921fSGabriel Fernandez 19345436921fSGabriel Fernandez #define STM32_KCLK(_name, _nb_parents, _parents, _flags, _gate_id, _mux_id)\ 19355436921fSGabriel Fernandez struct clk _name = {\ 19365436921fSGabriel Fernandez .ops = &clk_stm32_composite_ops,\ 19375436921fSGabriel Fernandez .priv = &(struct clk_stm32_composite_cfg) {\ 19385436921fSGabriel Fernandez .gate_id = (_gate_id),\ 19395436921fSGabriel Fernandez .div_id = (NO_DIV),\ 19405436921fSGabriel Fernandez .mux_id = (_mux_id),\ 19415436921fSGabriel Fernandez },\ 19425436921fSGabriel Fernandez .name = #_name,\ 19435436921fSGabriel Fernandez .flags = (_flags),\ 19445436921fSGabriel Fernandez .num_parents = (_nb_parents),\ 19455436921fSGabriel Fernandez .parents = _parents,\ 19465436921fSGabriel Fernandez } 19475436921fSGabriel Fernandez 19485436921fSGabriel Fernandez #define STM32_PLL_VCO(_name, _nb_parents, _parents, _flags, _reg,\ 19495436921fSGabriel Fernandez _gate_id, _mux_id)\ 19505436921fSGabriel Fernandez struct clk _name = {\ 19515436921fSGabriel Fernandez .ops = &clk_stm32_pll_ops,\ 19525436921fSGabriel Fernandez .priv = &(struct clk_stm32_pll_cfg) {\ 19535436921fSGabriel Fernandez .reg_pllxcr = (_reg),\ 19545436921fSGabriel Fernandez .gate_id = (_gate_id),\ 19555436921fSGabriel Fernandez .mux_id = (_mux_id),\ 19565436921fSGabriel Fernandez },\ 19575436921fSGabriel Fernandez .name = #_name,\ 19585436921fSGabriel Fernandez .flags = (_flags),\ 19595436921fSGabriel Fernandez .num_parents = (_nb_parents),\ 19605436921fSGabriel Fernandez .parents = _parents,\ 19615436921fSGabriel Fernandez } 19625436921fSGabriel Fernandez 19635436921fSGabriel Fernandez #define STM32_PLL_OUPUT(_name, _nb_parents, _parents, _flags,\ 19645436921fSGabriel Fernandez _gate_id, _div_id, _mux_id)\ 19655436921fSGabriel Fernandez struct clk _name = {\ 19665436921fSGabriel Fernandez .ops = &clk_stm32_composite_ops,\ 19675436921fSGabriel Fernandez .priv = &(struct clk_stm32_composite_cfg) {\ 19685436921fSGabriel Fernandez .gate_id = (_gate_id),\ 19695436921fSGabriel Fernandez .div_id = (_div_id),\ 19705436921fSGabriel Fernandez .mux_id = (_mux_id),\ 19715436921fSGabriel Fernandez },\ 19725436921fSGabriel Fernandez .name = #_name,\ 19735436921fSGabriel Fernandez .flags = (_flags),\ 19745436921fSGabriel Fernandez .num_parents = (_nb_parents),\ 19755436921fSGabriel Fernandez .parents = _parents,\ 19765436921fSGabriel Fernandez } 19775436921fSGabriel Fernandez 19785436921fSGabriel Fernandez /* Oscillator clocks */ 1979*95f2142bSEtienne Carriere 1980*95f2142bSEtienne Carriere static TEE_Result clk_stm32_oscillator_enable(struct clk *clk) 1981*95f2142bSEtienne Carriere { 1982*95f2142bSEtienne Carriere struct clk_stm32_gate_cfg *cfg = clk->priv; 1983*95f2142bSEtienne Carriere 1984*95f2142bSEtienne Carriere if (clk->rate == 0U) 1985*95f2142bSEtienne Carriere return TEE_SUCCESS; 1986*95f2142bSEtienne Carriere 1987*95f2142bSEtienne Carriere return stm32_gate_rdy_enable(cfg->gate_id); 1988*95f2142bSEtienne Carriere } 1989*95f2142bSEtienne Carriere 1990*95f2142bSEtienne Carriere static void clk_stm32_oscillator_disable(struct clk *clk) 1991*95f2142bSEtienne Carriere { 1992*95f2142bSEtienne Carriere struct clk_stm32_gate_cfg *cfg = clk->priv; 1993*95f2142bSEtienne Carriere 1994*95f2142bSEtienne Carriere if (clk->rate == 0U) 1995*95f2142bSEtienne Carriere return; 1996*95f2142bSEtienne Carriere 1997*95f2142bSEtienne Carriere if (stm32_gate_rdy_disable(cfg->gate_id)) 1998*95f2142bSEtienne Carriere panic(); 1999*95f2142bSEtienne Carriere } 2000*95f2142bSEtienne Carriere 2001*95f2142bSEtienne Carriere static const struct clk_ops clk_stm32_oscillator_ops = { 2002*95f2142bSEtienne Carriere .enable = clk_stm32_oscillator_enable, 2003*95f2142bSEtienne Carriere .disable = clk_stm32_oscillator_disable, 2004*95f2142bSEtienne Carriere }; 2005*95f2142bSEtienne Carriere 2006*95f2142bSEtienne Carriere #define STM32_OSCILLATOR(_name, _gate_id)\ 2007*95f2142bSEtienne Carriere struct clk _name = {\ 2008*95f2142bSEtienne Carriere .ops = &clk_stm32_oscillator_ops,\ 2009*95f2142bSEtienne Carriere .priv = &(struct clk_stm32_gate_cfg) {\ 2010*95f2142bSEtienne Carriere .gate_id = (_gate_id),\ 2011*95f2142bSEtienne Carriere },\ 2012*95f2142bSEtienne Carriere .name = #_name,\ 2013*95f2142bSEtienne Carriere } 2014*95f2142bSEtienne Carriere 2015*95f2142bSEtienne Carriere static STM32_OSCILLATOR(ck_hsi, GATE_HSI); 2016*95f2142bSEtienne Carriere static STM32_OSCILLATOR(ck_hse, GATE_HSE); 2017*95f2142bSEtienne Carriere static STM32_OSCILLATOR(ck_csi, GATE_CSI); 2018*95f2142bSEtienne Carriere static STM32_OSCILLATOR(ck_lsi, GATE_LSI); 2019*95f2142bSEtienne Carriere static STM32_OSCILLATOR(ck_lse, GATE_LSE); 20205436921fSGabriel Fernandez 20215436921fSGabriel Fernandez static STM32_FIXED_FACTOR(ck_i2sckin, NULL, 0, 1, 1); 20225436921fSGabriel Fernandez static STM32_FIXED_FACTOR(ck_hse_div2, &ck_hse, 0, 1, 2); 20235436921fSGabriel Fernandez 20245436921fSGabriel Fernandez static STM32_FIXED_RATE(ck_off, 0UL); 20255436921fSGabriel Fernandez static STM32_FIXED_RATE(ck_usb_phy_48Mhz, USB_PHY_48_MHZ); 20265436921fSGabriel Fernandez 20275436921fSGabriel Fernandez /* PLL1 clocks */ 20285436921fSGabriel Fernandez static struct clk ck_pll1_vco = { 20295436921fSGabriel Fernandez .ops = &clk_stm32_pll1_ops, 20305436921fSGabriel Fernandez .priv = &(struct clk_stm32_pll_cfg) { 20315436921fSGabriel Fernandez .reg_pllxcr = RCC_PLL1CR, 20325436921fSGabriel Fernandez .gate_id = GATE_PLL1, 20335436921fSGabriel Fernandez .mux_id = MUX_PLL12, 20345436921fSGabriel Fernandez }, 20355436921fSGabriel Fernandez .name = "ck_pll1_vco", 20365436921fSGabriel Fernandez .flags = 0, 20375436921fSGabriel Fernandez .num_parents = 2, 20385436921fSGabriel Fernandez .parents = { &ck_hsi, &ck_hse }, 20395436921fSGabriel Fernandez }; 20405436921fSGabriel Fernandez 20415436921fSGabriel Fernandez static struct clk ck_pll1p = { 20425436921fSGabriel Fernandez .ops = &clk_stm32_pll1p_ops, 20435436921fSGabriel Fernandez .priv = &(struct clk_stm32_composite_cfg) { 20445436921fSGabriel Fernandez .gate_id = GATE_PLL1_DIVP, 20455436921fSGabriel Fernandez .div_id = DIV_PLL1DIVP, 20465436921fSGabriel Fernandez .mux_id = NO_MUX, 20475436921fSGabriel Fernandez }, 20485436921fSGabriel Fernandez .name = "ck_pll1p", 20495436921fSGabriel Fernandez .flags = 0, 20505436921fSGabriel Fernandez .num_parents = 1, 20515436921fSGabriel Fernandez .parents = { &ck_pll1_vco }, 20525436921fSGabriel Fernandez }; 20535436921fSGabriel Fernandez 20545436921fSGabriel Fernandez const struct clk_ops clk_stm32_pll1p_div_ops = { 20555436921fSGabriel Fernandez .get_rate = clk_stm32_divider_get_rate, 20565436921fSGabriel Fernandez }; 20575436921fSGabriel Fernandez 20585436921fSGabriel Fernandez static struct clk ck_pll1p_div = { 20595436921fSGabriel Fernandez .ops = &clk_stm32_pll1p_div_ops, 20605436921fSGabriel Fernandez .priv = &(struct clk_stm32_div_cfg) { 20615436921fSGabriel Fernandez .div_id = DIV_MPU, 20625436921fSGabriel Fernandez }, 20635436921fSGabriel Fernandez .name = "ck_pll1p_div", 20645436921fSGabriel Fernandez .flags = 0, 20655436921fSGabriel Fernandez .num_parents = 1, 20665436921fSGabriel Fernandez .parents = { &ck_pll1p }, 20675436921fSGabriel Fernandez }; 20685436921fSGabriel Fernandez 20695436921fSGabriel Fernandez /* Other PLLs */ 20705436921fSGabriel Fernandez static STM32_PLL_VCO(ck_pll2_vco, 2, PARENT(&ck_hsi, &ck_hse), 20715436921fSGabriel Fernandez 0, RCC_PLL2CR, GATE_PLL2, MUX_PLL12); 20725436921fSGabriel Fernandez 20735436921fSGabriel Fernandez static STM32_PLL_VCO(ck_pll3_vco, 3, 20745436921fSGabriel Fernandez PARENT(&ck_hsi, &ck_hse, &ck_csi), 20755436921fSGabriel Fernandez 0, RCC_PLL3CR, GATE_PLL3, MUX_PLL3); 20765436921fSGabriel Fernandez 20775436921fSGabriel Fernandez static STM32_PLL_VCO(ck_pll4_vco, 4, 20785436921fSGabriel Fernandez PARENT(&ck_hsi, &ck_hse, &ck_csi, &ck_i2sckin), 20795436921fSGabriel Fernandez 0, RCC_PLL4CR, GATE_PLL4, MUX_PLL4); 20805436921fSGabriel Fernandez 20815436921fSGabriel Fernandez static STM32_PLL_OUPUT(ck_pll2p, 1, PARENT(&ck_pll2_vco), 0, 20825436921fSGabriel Fernandez GATE_PLL2_DIVP, DIV_PLL2DIVP, NO_MUX); 20835436921fSGabriel Fernandez 20845436921fSGabriel Fernandez static STM32_PLL_OUPUT(ck_pll2q, 1, PARENT(&ck_pll2_vco), 0, 20855436921fSGabriel Fernandez GATE_PLL2_DIVQ, DIV_PLL2DIVQ, NO_MUX); 20865436921fSGabriel Fernandez 20875436921fSGabriel Fernandez static STM32_PLL_OUPUT(ck_pll2r, 1, PARENT(&ck_pll2_vco), 0, 20885436921fSGabriel Fernandez GATE_PLL2_DIVR, DIV_PLL2DIVR, NO_MUX); 20895436921fSGabriel Fernandez 20905436921fSGabriel Fernandez static STM32_PLL_OUPUT(ck_pll3p, 1, PARENT(&ck_pll3_vco), 0, 20915436921fSGabriel Fernandez GATE_PLL3_DIVP, DIV_PLL3DIVP, NO_MUX); 20925436921fSGabriel Fernandez 20935436921fSGabriel Fernandez static STM32_PLL_OUPUT(ck_pll3q, 1, PARENT(&ck_pll3_vco), 0, 20945436921fSGabriel Fernandez GATE_PLL3_DIVQ, DIV_PLL3DIVQ, NO_MUX); 20955436921fSGabriel Fernandez 20965436921fSGabriel Fernandez static STM32_PLL_OUPUT(ck_pll3r, 1, PARENT(&ck_pll3_vco), 0, 20975436921fSGabriel Fernandez GATE_PLL3_DIVR, DIV_PLL3DIVR, NO_MUX); 20985436921fSGabriel Fernandez 20995436921fSGabriel Fernandez static STM32_PLL_OUPUT(ck_pll4p, 1, PARENT(&ck_pll4_vco), 0, 21005436921fSGabriel Fernandez GATE_PLL4_DIVP, DIV_PLL4DIVP, NO_MUX); 21015436921fSGabriel Fernandez 21025436921fSGabriel Fernandez static STM32_PLL_OUPUT(ck_pll4q, 1, PARENT(&ck_pll4_vco), 0, 21035436921fSGabriel Fernandez GATE_PLL4_DIVQ, DIV_PLL4DIVQ, NO_MUX); 21045436921fSGabriel Fernandez 21055436921fSGabriel Fernandez static STM32_PLL_OUPUT(ck_pll4r, 1, PARENT(&ck_pll4_vco), 0, 21065436921fSGabriel Fernandez GATE_PLL4_DIVR, DIV_PLL4DIVR, NO_MUX); 21075436921fSGabriel Fernandez 21085436921fSGabriel Fernandez /* System clocks */ 21095436921fSGabriel Fernandez static struct clk ck_mpu = { 21105436921fSGabriel Fernandez .ops = &clk_stm32_mpu_ops, 21115436921fSGabriel Fernandez .priv = &(struct clk_stm32_composite_cfg) { 21125436921fSGabriel Fernandez .mux_id = MUX_MPU, 21135436921fSGabriel Fernandez }, 21145436921fSGabriel Fernandez .name = "ck_mpu", 21155436921fSGabriel Fernandez .flags = 0, 21165436921fSGabriel Fernandez .num_parents = 4, 21175436921fSGabriel Fernandez .parents = { &ck_hsi, &ck_hse, &ck_pll1p, &ck_pll1p_div }, 21185436921fSGabriel Fernandez }; 21195436921fSGabriel Fernandez 21205436921fSGabriel Fernandez static struct clk ck_axi = { 21215436921fSGabriel Fernandez .ops = &clk_stm32_axi_ops, 21225436921fSGabriel Fernandez .priv = &(struct clk_stm32_composite_cfg) { 21235436921fSGabriel Fernandez .mux_id = MUX_AXI, 21245436921fSGabriel Fernandez .div_id = DIV_AXI, 21255436921fSGabriel Fernandez }, 21265436921fSGabriel Fernandez .name = "ck_axi", 21275436921fSGabriel Fernandez .flags = 0, 21285436921fSGabriel Fernandez .num_parents = 3, 21295436921fSGabriel Fernandez .parents = { &ck_hsi, &ck_hse, &ck_pll2p }, 21305436921fSGabriel Fernandez }; 21315436921fSGabriel Fernandez 21325436921fSGabriel Fernandez static struct clk ck_mlahb = { 21335436921fSGabriel Fernandez .ops = &clk_stm32_mlahb_ops, 21345436921fSGabriel Fernandez .priv = &(struct clk_stm32_composite_cfg) { 21355436921fSGabriel Fernandez .mux_id = MUX_MLAHB, 21365436921fSGabriel Fernandez .div_id = DIV_MLAHB, 21375436921fSGabriel Fernandez }, 21385436921fSGabriel Fernandez .name = "ck_mlahb", 21395436921fSGabriel Fernandez .flags = 0, 21405436921fSGabriel Fernandez .num_parents = 4, 21415436921fSGabriel Fernandez .parents = { &ck_hsi, &ck_hse, &ck_csi, &ck_pll3p }, 21425436921fSGabriel Fernandez }; 21435436921fSGabriel Fernandez 21445436921fSGabriel Fernandez static STM32_MUX(ck_per, 4, PARENT(&ck_hsi, &ck_csi, &ck_hse, &ck_off), 21455436921fSGabriel Fernandez 0, MUX_CKPER); 21465436921fSGabriel Fernandez 21475436921fSGabriel Fernandez /* Bus clocks */ 21485436921fSGabriel Fernandez static STM32_DIVIDER(ck_pclk1, &ck_mlahb, 0, DIV_APB1); 21495436921fSGabriel Fernandez static STM32_DIVIDER(ck_pclk2, &ck_mlahb, 0, DIV_APB2); 21505436921fSGabriel Fernandez static STM32_DIVIDER(ck_pclk3, &ck_mlahb, 0, DIV_APB3); 21515436921fSGabriel Fernandez static STM32_DIVIDER(ck_pclk4, &ck_axi, 0, DIV_APB4); 21525436921fSGabriel Fernandez static STM32_DIVIDER(ck_pclk5, &ck_axi, 0, DIV_APB5); 21535436921fSGabriel Fernandez static STM32_DIVIDER(ck_pclk6, &ck_mlahb, 0, DIV_APB6); 21545436921fSGabriel Fernandez 21555436921fSGabriel Fernandez /* Timer Clocks */ 21565436921fSGabriel Fernandez static STM32_TIMER(ck_timg1, &ck_pclk1, 0, RCC_APB1DIVR, RCC_TIMG1PRER); 21575436921fSGabriel Fernandez static STM32_TIMER(ck_timg2, &ck_pclk2, 0, RCC_APB2DIVR, RCC_TIMG2PRER); 21585436921fSGabriel Fernandez static STM32_TIMER(ck_timg3, &ck_pclk6, 0, RCC_APB6DIVR, RCC_TIMG3PRER); 21595436921fSGabriel Fernandez 21605436921fSGabriel Fernandez /* Peripheral and Kernel Clocks */ 21615436921fSGabriel Fernandez static STM32_GATE(ck_ddrc1, &ck_axi, 0, GATE_DDRC1); 21625436921fSGabriel Fernandez static STM32_GATE(ck_ddrc1lp, &ck_axi, 0, GATE_DDRC1LP); 21635436921fSGabriel Fernandez static STM32_GATE(ck_ddrphyc, &ck_pll2r, 0, GATE_DDRPHYC); 21645436921fSGabriel Fernandez static STM32_GATE(ck_ddrphyclp, &ck_pll2r, 0, GATE_DDRPHYCLP); 21655436921fSGabriel Fernandez static STM32_GATE(ck_ddrcapb, &ck_pclk4, 0, GATE_DDRCAPB); 21665436921fSGabriel Fernandez static STM32_GATE(ck_ddrcapblp, &ck_pclk4, 0, GATE_DDRCAPBLP); 21675436921fSGabriel Fernandez static STM32_GATE(ck_axidcg, &ck_axi, 0, GATE_AXIDCG); 21685436921fSGabriel Fernandez static STM32_GATE(ck_ddrphycapb, &ck_pclk4, 0, 0); 21695436921fSGabriel Fernandez static STM32_GATE(ck_ddrphycapblp, &ck_pclk4, 0, GATE_DDRPHYCAPBLP); 21705436921fSGabriel Fernandez static STM32_GATE(ck_syscfg, &ck_pclk3, 0, GATE_SYSCFG); 21715436921fSGabriel Fernandez static STM32_GATE(ck_ddrperfm, &ck_pclk4, 0, GATE_DDRPERFM); 21725436921fSGabriel Fernandez static STM32_GATE(ck_iwdg2, &ck_pclk4, 0, GATE_IWDG2APB); 21735436921fSGabriel Fernandez static STM32_GATE(ck_rtcapb, &ck_pclk5, 0, GATE_RTCAPB); 21745436921fSGabriel Fernandez static STM32_GATE(ck_tzc, &ck_pclk5, 0, GATE_TZC); 21755436921fSGabriel Fernandez static STM32_GATE(ck_etzpcb, &ck_pclk5, 0, GATE_ETZPC); 21765436921fSGabriel Fernandez static STM32_GATE(ck_iwdg1apb, &ck_pclk5, 0, GATE_IWDG1APB); 21775436921fSGabriel Fernandez static STM32_GATE(ck_bsec, &ck_pclk5, 0, GATE_BSEC); 21785436921fSGabriel Fernandez static STM32_GATE(ck_tim12_k, &ck_timg3, 0, GATE_TIM12); 21795436921fSGabriel Fernandez static STM32_GATE(ck_tim15_k, &ck_timg3, 0, GATE_TIM15); 21805436921fSGabriel Fernandez static STM32_GATE(ck_gpioa, &ck_mlahb, 0, GATE_GPIOA); 21815436921fSGabriel Fernandez static STM32_GATE(ck_gpiob, &ck_mlahb, 0, GATE_GPIOB); 21825436921fSGabriel Fernandez static STM32_GATE(ck_gpioc, &ck_mlahb, 0, GATE_GPIOC); 21835436921fSGabriel Fernandez static STM32_GATE(ck_gpiod, &ck_mlahb, 0, GATE_GPIOD); 21845436921fSGabriel Fernandez static STM32_GATE(ck_gpioe, &ck_mlahb, 0, GATE_GPIOE); 21855436921fSGabriel Fernandez static STM32_GATE(ck_gpiof, &ck_mlahb, 0, GATE_GPIOF); 21865436921fSGabriel Fernandez static STM32_GATE(ck_gpiog, &ck_mlahb, 0, GATE_GPIOG); 21875436921fSGabriel Fernandez static STM32_GATE(ck_gpioh, &ck_mlahb, 0, GATE_GPIOH); 21885436921fSGabriel Fernandez static STM32_GATE(ck_gpioi, &ck_mlahb, 0, GATE_GPIOI); 21895436921fSGabriel Fernandez static STM32_GATE(ck_pka, &ck_axi, 0, GATE_PKA); 21905436921fSGabriel Fernandez static STM32_GATE(ck_cryp1, &ck_pclk5, 0, GATE_CRYP1); 21915436921fSGabriel Fernandez static STM32_GATE(ck_hash1, &ck_pclk5, 0, GATE_HASH1); 21925436921fSGabriel Fernandez static STM32_GATE(ck_bkpsram, &ck_pclk5, 0, GATE_BKPSRAM); 21935436921fSGabriel Fernandez static STM32_GATE(ck_dbg, &ck_axi, 0, GATE_DBGCK); 21945436921fSGabriel Fernandez static STM32_GATE(ck_mce, &ck_axi, 0, GATE_MCE); 21955436921fSGabriel Fernandez static STM32_GATE(ck_tim2_k, &ck_timg1, 0, GATE_TIM2); 21965436921fSGabriel Fernandez static STM32_GATE(ck_tim3_k, &ck_timg1, 0, GATE_TIM3); 21975436921fSGabriel Fernandez static STM32_GATE(ck_tim4_k, &ck_timg1, 0, GATE_TIM4); 21985436921fSGabriel Fernandez static STM32_GATE(ck_tim5_k, &ck_timg1, 0, GATE_TIM5); 21995436921fSGabriel Fernandez static STM32_GATE(ck_tim6_k, &ck_timg1, 0, GATE_TIM6); 22005436921fSGabriel Fernandez static STM32_GATE(ck_tim7_k, &ck_timg1, 0, GATE_TIM7); 22015436921fSGabriel Fernandez static STM32_GATE(ck_tim13_k, &ck_timg3, 0, GATE_TIM13); 22025436921fSGabriel Fernandez static STM32_GATE(ck_tim14_k, &ck_timg3, 0, GATE_TIM14); 22035436921fSGabriel Fernandez static STM32_GATE(ck_tim1_k, &ck_timg2, 0, GATE_TIM1); 22045436921fSGabriel Fernandez static STM32_GATE(ck_tim8_k, &ck_timg2, 0, GATE_TIM8); 22055436921fSGabriel Fernandez static STM32_GATE(ck_tim16_k, &ck_timg3, 0, GATE_TIM16); 22065436921fSGabriel Fernandez static STM32_GATE(ck_tim17_k, &ck_timg3, 0, GATE_TIM17); 22075436921fSGabriel Fernandez static STM32_GATE(ck_ltdc_px, &ck_pll4q, 0, GATE_LTDC); 22085436921fSGabriel Fernandez static STM32_GATE(ck_dma1, &ck_mlahb, 0, GATE_DMA1); 22095436921fSGabriel Fernandez static STM32_GATE(ck_dma2, &ck_mlahb, 0, GATE_DMA2); 2210e84c2998SEtienne Carriere static STM32_GATE(ck_adc1, &ck_mlahb, 0, GATE_ADC1); 2211e84c2998SEtienne Carriere static STM32_GATE(ck_adc2, &ck_mlahb, 0, GATE_ADC2); 22125436921fSGabriel Fernandez static STM32_GATE(ck_mdma, &ck_axi, 0, GATE_MDMA); 22135436921fSGabriel Fernandez static STM32_GATE(ck_eth1mac, &ck_axi, 0, GATE_ETH1MAC); 22145436921fSGabriel Fernandez static STM32_GATE(ck_usbh, &ck_axi, 0, GATE_USBH); 22155436921fSGabriel Fernandez static STM32_GATE(ck_vref, &ck_pclk3, 0, GATE_VREF); 22165436921fSGabriel Fernandez static STM32_GATE(ck_tmpsens, &ck_pclk3, 0, GATE_DTS); 2217f4dba325SEtienne Carriere static STM32_GATE(ck_pmbctrl, &ck_pclk3, 0, GATE_PMBCTRL); 2218f4dba325SEtienne Carriere static STM32_GATE(ck_hdp, &ck_pclk3, 0, GATE_HDP); 2219f4dba325SEtienne Carriere static STM32_GATE(ck_stgenro, &ck_pclk4, 0, GATE_STGENRO); 22205436921fSGabriel Fernandez static STM32_GATE(ck_dmamux1, &ck_axi, 0, GATE_DMAMUX1); 22215436921fSGabriel Fernandez static STM32_GATE(ck_dmamux2, &ck_axi, 0, GATE_DMAMUX2); 2222f4dba325SEtienne Carriere static STM32_GATE(ck_dma3, &ck_axi, 0, GATE_DMA3); 22235436921fSGabriel Fernandez static STM32_GATE(ck_tsc, &ck_axi, 0, GATE_TSC); 22245436921fSGabriel Fernandez static STM32_GATE(ck_aximc, &ck_axi, 0, GATE_AXIMC); 2225f4dba325SEtienne Carriere static STM32_GATE(ck_crc1, &ck_axi, 0, GATE_CRC1); 22265436921fSGabriel Fernandez static STM32_GATE(ck_eth1tx, &ck_axi, 0, GATE_ETH1TX); 22275436921fSGabriel Fernandez static STM32_GATE(ck_eth1rx, &ck_axi, 0, GATE_ETH1RX); 22285436921fSGabriel Fernandez static STM32_GATE(ck_eth2tx, &ck_axi, 0, GATE_ETH2TX); 22295436921fSGabriel Fernandez static STM32_GATE(ck_eth2rx, &ck_axi, 0, GATE_ETH2RX); 22305436921fSGabriel Fernandez static STM32_GATE(ck_eth2mac, &ck_axi, 0, GATE_ETH2MAC); 2231e84c2998SEtienne Carriere static STM32_GATE(ck_spi1, &ck_pclk2, 0, GATE_SPI1); 2232e84c2998SEtienne Carriere static STM32_GATE(ck_spi2, &ck_pclk1, 0, GATE_SPI2); 2233e84c2998SEtienne Carriere static STM32_GATE(ck_spi3, &ck_pclk1, 0, GATE_SPI3); 2234e84c2998SEtienne Carriere static STM32_GATE(ck_spi4, &ck_pclk6, 0, GATE_SPI4); 2235e84c2998SEtienne Carriere static STM32_GATE(ck_spi5, &ck_pclk6, 0, GATE_SPI5); 22365436921fSGabriel Fernandez 22375436921fSGabriel Fernandez /* Kernel Clocks */ 22385436921fSGabriel Fernandez static STM32_KCLK(ck_usbphy_k, 3, 22395436921fSGabriel Fernandez PARENT(&ck_hse, &ck_pll4r, &ck_hse_div2), 22405436921fSGabriel Fernandez 0, GATE_USBPHY, MUX_USBPHY); 22415436921fSGabriel Fernandez 22425436921fSGabriel Fernandez static STM32_KCLK(ck_usbo_k, 2, 22435436921fSGabriel Fernandez PARENT(&ck_pll4r, &ck_usb_phy_48Mhz), 0, 22445436921fSGabriel Fernandez GATE_USBO, MUX_USBO); 22455436921fSGabriel Fernandez 22465436921fSGabriel Fernandez static STM32_KCLK(ck_stgen_k, 2, 22475436921fSGabriel Fernandez PARENT(&ck_hsi, &ck_hse), 0, GATE_STGENC, MUX_STGEN); 22485436921fSGabriel Fernandez 22495436921fSGabriel Fernandez static STM32_KCLK(ck_usart1_k, 6, 22505436921fSGabriel Fernandez PARENT(&ck_pclk6, &ck_pll3q, &ck_hsi, 22515436921fSGabriel Fernandez &ck_csi, &ck_pll4q, &ck_hse), 22525436921fSGabriel Fernandez 0, GATE_USART1, MUX_UART1); 22535436921fSGabriel Fernandez 22545436921fSGabriel Fernandez static STM32_KCLK(ck_usart2_k, 6, 22555436921fSGabriel Fernandez PARENT(&ck_pclk6, &ck_pll3q, &ck_hsi, &ck_csi, &ck_pll4q, 22565436921fSGabriel Fernandez &ck_hse), 22575436921fSGabriel Fernandez 0, GATE_USART2, MUX_UART2); 22585436921fSGabriel Fernandez 22595436921fSGabriel Fernandez static STM32_KCLK(ck_i2c4_k, 4, 22605436921fSGabriel Fernandez PARENT(&ck_pclk6, &ck_pll4r, &ck_hsi, &ck_csi), 22615436921fSGabriel Fernandez 0, GATE_I2C4, MUX_I2C4); 22625436921fSGabriel Fernandez 22635436921fSGabriel Fernandez static STM32_KCLK(ck_rtc, 4, 22645436921fSGabriel Fernandez PARENT(&ck_off, &ck_lse, &ck_lsi, &ck_hse), 22655436921fSGabriel Fernandez 0, GATE_RTCCK, MUX_RTC); 22665436921fSGabriel Fernandez 22675436921fSGabriel Fernandez static STM32_KCLK(ck_saes_k, 4, 22685436921fSGabriel Fernandez PARENT(&ck_axi, &ck_per, &ck_pll4r, &ck_lsi), 22695436921fSGabriel Fernandez 0, GATE_SAES, MUX_SAES); 22705436921fSGabriel Fernandez 22715436921fSGabriel Fernandez static STM32_KCLK(ck_rng1_k, 4, 2272a32213b8SEtienne Carriere PARENT(&ck_csi, &ck_pll4r, &ck_off, &ck_lsi), 22735436921fSGabriel Fernandez 0, GATE_RNG1, MUX_RNG1); 22745436921fSGabriel Fernandez 22755436921fSGabriel Fernandez static STM32_KCLK(ck_sdmmc1_k, 4, 22765436921fSGabriel Fernandez PARENT(&ck_axi, &ck_pll3r, &ck_pll4p, &ck_hsi), 22775436921fSGabriel Fernandez 0, GATE_SDMMC1, MUX_SDMMC1); 22785436921fSGabriel Fernandez 22795436921fSGabriel Fernandez static STM32_KCLK(ck_sdmmc2_k, 4, 22805436921fSGabriel Fernandez PARENT(&ck_axi, &ck_pll3r, &ck_pll4p, &ck_hsi), 22815436921fSGabriel Fernandez 0, GATE_SDMMC2, MUX_SDMMC2); 22825436921fSGabriel Fernandez 22835436921fSGabriel Fernandez static STM32_KCLK(ck_usart3_k, 5, 22845436921fSGabriel Fernandez PARENT(&ck_pclk1, &ck_pll4q, &ck_hsi, &ck_csi, &ck_hse), 22855436921fSGabriel Fernandez 0, GATE_USART3, MUX_UART35); 22865436921fSGabriel Fernandez 22875436921fSGabriel Fernandez static STM32_KCLK(ck_uart4_k, 5, 22885436921fSGabriel Fernandez PARENT(&ck_pclk1, &ck_pll4q, &ck_hsi, &ck_csi, &ck_hse), 22895436921fSGabriel Fernandez 0, GATE_UART4, MUX_UART4); 22905436921fSGabriel Fernandez 22915436921fSGabriel Fernandez static STM32_KCLK(ck_uart5_k, 5, 22925436921fSGabriel Fernandez PARENT(&ck_pclk1, &ck_pll4q, &ck_hsi, &ck_csi, &ck_hse), 22935436921fSGabriel Fernandez 0, GATE_UART5, MUX_UART35); 22945436921fSGabriel Fernandez 22955436921fSGabriel Fernandez static STM32_KCLK(ck_uart7_k, 5, 22965436921fSGabriel Fernandez PARENT(&ck_pclk1, &ck_pll4q, &ck_hsi, &ck_csi, &ck_hse), 22975436921fSGabriel Fernandez 0, GATE_UART7, MUX_UART78); 22985436921fSGabriel Fernandez 22995436921fSGabriel Fernandez static STM32_KCLK(ck_uart8_k, 5, 23005436921fSGabriel Fernandez PARENT(&ck_pclk1, &ck_pll4q, &ck_hsi, &ck_csi, &ck_hse), 23015436921fSGabriel Fernandez 0, GATE_UART8, MUX_UART78); 23025436921fSGabriel Fernandez 23035436921fSGabriel Fernandez static STM32_KCLK(ck_usart6_k, 5, 23045436921fSGabriel Fernandez PARENT(&ck_pclk2, &ck_pll4q, &ck_hsi, &ck_csi, &ck_hse), 23055436921fSGabriel Fernandez 0, GATE_USART6, MUX_UART6); 23065436921fSGabriel Fernandez 23075436921fSGabriel Fernandez static STM32_KCLK(ck_fmc_k, 4, 23085436921fSGabriel Fernandez PARENT(&ck_axi, &ck_pll3r, &ck_pll4p, &ck_per), 23095436921fSGabriel Fernandez 0, GATE_FMC, MUX_FMC); 23105436921fSGabriel Fernandez 23115436921fSGabriel Fernandez static STM32_KCLK(ck_qspi_k, 4, 23125436921fSGabriel Fernandez PARENT(&ck_axi, &ck_pll3r, &ck_pll4p, &ck_per), 23135436921fSGabriel Fernandez 0, GATE_QSPI, MUX_QSPI); 23145436921fSGabriel Fernandez 23155436921fSGabriel Fernandez static STM32_KCLK(ck_lptim1_k, 6, 23165436921fSGabriel Fernandez PARENT(&ck_pclk1, &ck_pll4p, &ck_pll3q, &ck_lse, &ck_lsi, 23175436921fSGabriel Fernandez &ck_per), 23185436921fSGabriel Fernandez 0, GATE_LPTIM1, MUX_LPTIM1); 23195436921fSGabriel Fernandez 23205436921fSGabriel Fernandez static STM32_KCLK(ck_spi2_k, 5, 23215436921fSGabriel Fernandez PARENT(&ck_pll4p, &ck_pll3q, &ck_i2sckin, &ck_per, &ck_pll3r), 23225436921fSGabriel Fernandez 0, GATE_SPI2, MUX_SPI23); 23235436921fSGabriel Fernandez 23245436921fSGabriel Fernandez static STM32_KCLK(ck_spi3_k, 5, 23255436921fSGabriel Fernandez PARENT(&ck_pll4p, &ck_pll3q, &ck_i2sckin, &ck_per, &ck_pll3r), 23265436921fSGabriel Fernandez 0, GATE_SPI3, MUX_SPI23); 23275436921fSGabriel Fernandez 23285436921fSGabriel Fernandez static STM32_KCLK(ck_spdif_k, 3, 23295436921fSGabriel Fernandez PARENT(&ck_pll4p, &ck_pll3q, &ck_hsi), 23305436921fSGabriel Fernandez 0, GATE_SPDIF, MUX_SPDIF); 23315436921fSGabriel Fernandez 23325436921fSGabriel Fernandez static STM32_KCLK(ck_spi1_k, 5, 23335436921fSGabriel Fernandez PARENT(&ck_pll4p, &ck_pll3q, &ck_i2sckin, &ck_per, &ck_pll3r), 23345436921fSGabriel Fernandez 0, GATE_SPI1, MUX_SPI1); 23355436921fSGabriel Fernandez 23365436921fSGabriel Fernandez static STM32_KCLK(ck_spi4_k, 6, 23375436921fSGabriel Fernandez PARENT(&ck_pclk6, &ck_pll4q, &ck_hsi, &ck_csi, &ck_hse, 23385436921fSGabriel Fernandez &ck_i2sckin), 23395436921fSGabriel Fernandez 0, GATE_SPI4, MUX_SPI4); 23405436921fSGabriel Fernandez 23415436921fSGabriel Fernandez static STM32_KCLK(ck_spi5_k, 5, 23425436921fSGabriel Fernandez PARENT(&ck_pclk6, &ck_pll4q, &ck_hsi, &ck_csi, &ck_hse), 23435436921fSGabriel Fernandez 0, GATE_SPI5, MUX_SPI5); 23445436921fSGabriel Fernandez 23455436921fSGabriel Fernandez static STM32_KCLK(ck_sai1_k, 5, 23465436921fSGabriel Fernandez PARENT(&ck_pll4q, &ck_pll3q, &ck_i2sckin, &ck_per, &ck_pll3r), 23475436921fSGabriel Fernandez 0, GATE_SAI1, MUX_SAI1); 23485436921fSGabriel Fernandez 23495436921fSGabriel Fernandez static STM32_KCLK(ck_sai2_k, 6, 23505436921fSGabriel Fernandez PARENT(&ck_pll4q, &ck_pll3q, &ck_i2sckin, &ck_per, &ck_off, 23515436921fSGabriel Fernandez &ck_pll3r), 23525436921fSGabriel Fernandez 0, GATE_SAI2, MUX_SAI2); 23535436921fSGabriel Fernandez 23545436921fSGabriel Fernandez static STM32_KCLK(ck_dfsdm_k, 5, 23555436921fSGabriel Fernandez PARENT(&ck_pll4q, &ck_pll3q, &ck_i2sckin, &ck_per, &ck_pll3r), 23565436921fSGabriel Fernandez 0, GATE_DFSDM, MUX_SAI1); 23575436921fSGabriel Fernandez 23585436921fSGabriel Fernandez static STM32_KCLK(ck_fdcan_k, 4, 23595436921fSGabriel Fernandez PARENT(&ck_hse, &ck_pll3q, &ck_pll4q, &ck_pll4r), 23605436921fSGabriel Fernandez 0, GATE_FDCAN, MUX_FDCAN); 23615436921fSGabriel Fernandez 23625436921fSGabriel Fernandez static STM32_KCLK(ck_i2c1_k, 4, 23635436921fSGabriel Fernandez PARENT(&ck_pclk1, &ck_pll4r, &ck_hsi, &ck_csi), 23645436921fSGabriel Fernandez 0, GATE_I2C1, MUX_I2C12); 23655436921fSGabriel Fernandez 23665436921fSGabriel Fernandez static STM32_KCLK(ck_i2c2_k, 4, 23675436921fSGabriel Fernandez PARENT(&ck_pclk1, &ck_pll4r, &ck_hsi, &ck_csi), 23685436921fSGabriel Fernandez 0, GATE_I2C2, MUX_I2C12); 23695436921fSGabriel Fernandez 23705436921fSGabriel Fernandez static STM32_KCLK(ck_adfsdm_k, 5, 23715436921fSGabriel Fernandez PARENT(&ck_pll4q, &ck_pll3q, &ck_i2sckin, &ck_per, &ck_pll3r), 23725436921fSGabriel Fernandez 0, GATE_ADFSDM, MUX_SAI1); 23735436921fSGabriel Fernandez 23745436921fSGabriel Fernandez static STM32_KCLK(ck_lptim2_k, 5, 23755436921fSGabriel Fernandez PARENT(&ck_pclk3, &ck_pll4q, &ck_per, &ck_lse, &ck_lsi), 23765436921fSGabriel Fernandez 0, GATE_LPTIM2, MUX_LPTIM2); 23775436921fSGabriel Fernandez 23785436921fSGabriel Fernandez static STM32_KCLK(ck_lptim3_k, 5, 23795436921fSGabriel Fernandez PARENT(&ck_pclk3, &ck_pll4q, &ck_per, &ck_lse, &ck_lsi), 23805436921fSGabriel Fernandez 0, GATE_LPTIM3, MUX_LPTIM3); 23815436921fSGabriel Fernandez 23825436921fSGabriel Fernandez static STM32_KCLK(ck_lptim4_k, 6, 23835436921fSGabriel Fernandez PARENT(&ck_pclk3, &ck_pll4p, &ck_pll3q, &ck_lse, &ck_lsi, 23845436921fSGabriel Fernandez &ck_per), 23855436921fSGabriel Fernandez 0, GATE_LPTIM4, MUX_LPTIM45); 23865436921fSGabriel Fernandez 23875436921fSGabriel Fernandez static STM32_KCLK(ck_lptim5_k, 6, 23885436921fSGabriel Fernandez PARENT(&ck_pclk3, &ck_pll4p, &ck_pll3q, &ck_lse, &ck_lsi, 23895436921fSGabriel Fernandez &ck_per), 23905436921fSGabriel Fernandez 0, GATE_LPTIM5, MUX_LPTIM45); 23915436921fSGabriel Fernandez 23925436921fSGabriel Fernandez static STM32_KCLK(ck_i2c3_k, 4, 23935436921fSGabriel Fernandez PARENT(&ck_pclk6, &ck_pll4r, &ck_hsi, &ck_csi), 23945436921fSGabriel Fernandez 0, GATE_I2C3, MUX_I2C3); 23955436921fSGabriel Fernandez 23965436921fSGabriel Fernandez static STM32_KCLK(ck_i2c5_k, 4, 23975436921fSGabriel Fernandez PARENT(&ck_pclk6, &ck_pll4r, &ck_hsi, &ck_csi), 23985436921fSGabriel Fernandez 0, GATE_I2C5, MUX_I2C5); 23995436921fSGabriel Fernandez 24005436921fSGabriel Fernandez static STM32_KCLK(ck_dcmipp_k, 4, 24015436921fSGabriel Fernandez PARENT(&ck_axi, &ck_pll2q, &ck_pll4p, &ck_per), 24025436921fSGabriel Fernandez 0, GATE_DCMIPP, MUX_DCMIPP); 24035436921fSGabriel Fernandez 24045436921fSGabriel Fernandez static STM32_KCLK(ck_adc1_k, 3, PARENT(&ck_pll4r, &ck_per, &ck_pll3q), 24055436921fSGabriel Fernandez 0, GATE_ADC1, MUX_ADC1); 24065436921fSGabriel Fernandez 24075436921fSGabriel Fernandez static STM32_KCLK(ck_adc2_k, 3, PARENT(&ck_pll4r, &ck_per, &ck_pll3q), 24085436921fSGabriel Fernandez 0, GATE_ADC2, MUX_ADC2); 24095436921fSGabriel Fernandez 24105436921fSGabriel Fernandez static STM32_KCLK(ck_eth1ck_k, 2, PARENT(&ck_pll4p, &ck_pll3q), 24115436921fSGabriel Fernandez 0, GATE_ETH1CK, MUX_ETH1); 24125436921fSGabriel Fernandez 24135436921fSGabriel Fernandez static STM32_KCLK(ck_eth2ck_k, 2, PARENT(&ck_pll4p, &ck_pll3q), 24145436921fSGabriel Fernandez 0, GATE_ETH2CK, MUX_ETH2); 24155436921fSGabriel Fernandez 24165436921fSGabriel Fernandez static STM32_COMPOSITE(ck_mco1, 5, 24175436921fSGabriel Fernandez PARENT(&ck_hsi, &ck_hse, &ck_csi, &ck_lsi, &ck_lse), 24185436921fSGabriel Fernandez 0, GATE_MCO1, DIV_MCO1, MUX_MCO1); 24195436921fSGabriel Fernandez 24205436921fSGabriel Fernandez static STM32_COMPOSITE(ck_mco2, 6, 24215436921fSGabriel Fernandez PARENT(&ck_mpu, &ck_axi, &ck_mlahb, 24225436921fSGabriel Fernandez &ck_pll4p, &ck_hse, &ck_hsi), 24235436921fSGabriel Fernandez 0, GATE_MCO2, DIV_MCO2, MUX_MCO2); 24245436921fSGabriel Fernandez 24255436921fSGabriel Fernandez static STM32_COMPOSITE(ck_trace, 1, PARENT(&ck_axi), 24265436921fSGabriel Fernandez 0, GATE_TRACECK, DIV_TRACE, NO_MUX); 24275436921fSGabriel Fernandez 24285436921fSGabriel Fernandez enum { 24295436921fSGabriel Fernandez USB_PHY_48 = STM32MP1_LAST_CLK, 24305436921fSGabriel Fernandez PLL1P_DIV, 24315436921fSGabriel Fernandez CK_OFF, 24325436921fSGabriel Fernandez I2S_CKIN, 24335436921fSGabriel Fernandez STM32MP13_ALL_CLK_NB 24345436921fSGabriel Fernandez }; 24355436921fSGabriel Fernandez 24365436921fSGabriel Fernandez static struct clk *stm32mp13_clk_provided[STM32MP13_ALL_CLK_NB] = { 24375436921fSGabriel Fernandez [CK_HSE] = &ck_hse, 24385436921fSGabriel Fernandez [CK_CSI] = &ck_csi, 24395436921fSGabriel Fernandez [CK_LSI] = &ck_lsi, 24405436921fSGabriel Fernandez [CK_LSE] = &ck_lse, 24415436921fSGabriel Fernandez [CK_HSI] = &ck_hsi, 24425436921fSGabriel Fernandez [CK_HSE_DIV2] = &ck_hse_div2, 24435436921fSGabriel Fernandez [PLL1] = &ck_pll1_vco, 24445436921fSGabriel Fernandez [PLL2] = &ck_pll2_vco, 24455436921fSGabriel Fernandez [PLL3] = &ck_pll3_vco, 24465436921fSGabriel Fernandez [PLL4] = &ck_pll4_vco, 24475436921fSGabriel Fernandez [PLL1_P] = &ck_pll1p, 24485436921fSGabriel Fernandez [PLL2_P] = &ck_pll2p, 24495436921fSGabriel Fernandez [PLL2_Q] = &ck_pll2q, 24505436921fSGabriel Fernandez [PLL2_R] = &ck_pll2r, 24515436921fSGabriel Fernandez [PLL3_P] = &ck_pll3p, 24525436921fSGabriel Fernandez [PLL3_Q] = &ck_pll3q, 24535436921fSGabriel Fernandez [PLL3_R] = &ck_pll3r, 24545436921fSGabriel Fernandez [PLL4_P] = &ck_pll4p, 24555436921fSGabriel Fernandez [PLL4_Q] = &ck_pll4q, 24565436921fSGabriel Fernandez [PLL4_R] = &ck_pll4r, 24575436921fSGabriel Fernandez [PLL1P_DIV] = &ck_pll1p_div, 24585436921fSGabriel Fernandez [CK_MPU] = &ck_mpu, 24595436921fSGabriel Fernandez [CK_AXI] = &ck_axi, 24605436921fSGabriel Fernandez [CK_MLAHB] = &ck_mlahb, 24615436921fSGabriel Fernandez [CK_PER] = &ck_per, 24625436921fSGabriel Fernandez [PCLK1] = &ck_pclk1, 24635436921fSGabriel Fernandez [PCLK2] = &ck_pclk2, 24645436921fSGabriel Fernandez [PCLK3] = &ck_pclk3, 24655436921fSGabriel Fernandez [PCLK4] = &ck_pclk4, 24665436921fSGabriel Fernandez [PCLK5] = &ck_pclk5, 24675436921fSGabriel Fernandez [PCLK6] = &ck_pclk6, 24685436921fSGabriel Fernandez [CK_TIMG1] = &ck_timg1, 24695436921fSGabriel Fernandez [CK_TIMG2] = &ck_timg2, 24705436921fSGabriel Fernandez [CK_TIMG3] = &ck_timg3, 24715436921fSGabriel Fernandez [DDRC1] = &ck_ddrc1, 24725436921fSGabriel Fernandez [DDRC1LP] = &ck_ddrc1lp, 24735436921fSGabriel Fernandez [DDRPHYC] = &ck_ddrphyc, 24745436921fSGabriel Fernandez [DDRPHYCLP] = &ck_ddrphyclp, 24755436921fSGabriel Fernandez [DDRCAPB] = &ck_ddrcapb, 24765436921fSGabriel Fernandez [DDRCAPBLP] = &ck_ddrcapblp, 24775436921fSGabriel Fernandez [AXIDCG] = &ck_axidcg, 24785436921fSGabriel Fernandez [DDRPHYCAPB] = &ck_ddrphycapb, 24795436921fSGabriel Fernandez [DDRPHYCAPBLP] = &ck_ddrphycapblp, 24805436921fSGabriel Fernandez [SYSCFG] = &ck_syscfg, 24815436921fSGabriel Fernandez [DDRPERFM] = &ck_ddrperfm, 24825436921fSGabriel Fernandez [IWDG2] = &ck_iwdg2, 24835436921fSGabriel Fernandez [USBPHY_K] = &ck_usbphy_k, 24845436921fSGabriel Fernandez [USBO_K] = &ck_usbo_k, 24855436921fSGabriel Fernandez [RTCAPB] = &ck_rtcapb, 24865436921fSGabriel Fernandez [TZC] = &ck_tzc, 24875436921fSGabriel Fernandez [TZPC] = &ck_etzpcb, 24885436921fSGabriel Fernandez [IWDG1] = &ck_iwdg1apb, 24895436921fSGabriel Fernandez [BSEC] = &ck_bsec, 24905436921fSGabriel Fernandez [STGEN_K] = &ck_stgen_k, 24915436921fSGabriel Fernandez [USART1_K] = &ck_usart1_k, 24925436921fSGabriel Fernandez [USART2_K] = &ck_usart2_k, 24935436921fSGabriel Fernandez [I2C4_K] = &ck_i2c4_k, 24945436921fSGabriel Fernandez [TIM12_K] = &ck_tim12_k, 24955436921fSGabriel Fernandez [TIM15_K] = &ck_tim15_k, 24965436921fSGabriel Fernandez [RTC] = &ck_rtc, 24975436921fSGabriel Fernandez [GPIOA] = &ck_gpioa, 24985436921fSGabriel Fernandez [GPIOB] = &ck_gpiob, 24995436921fSGabriel Fernandez [GPIOC] = &ck_gpioc, 25005436921fSGabriel Fernandez [GPIOD] = &ck_gpiod, 25015436921fSGabriel Fernandez [GPIOE] = &ck_gpioe, 25025436921fSGabriel Fernandez [GPIOF] = &ck_gpiof, 25035436921fSGabriel Fernandez [GPIOG] = &ck_gpiog, 25045436921fSGabriel Fernandez [GPIOH] = &ck_gpioh, 25055436921fSGabriel Fernandez [GPIOI] = &ck_gpioi, 25065436921fSGabriel Fernandez [PKA] = &ck_pka, 25075436921fSGabriel Fernandez [SAES_K] = &ck_saes_k, 25085436921fSGabriel Fernandez [CRYP1] = &ck_cryp1, 25095436921fSGabriel Fernandez [HASH1] = &ck_hash1, 25105436921fSGabriel Fernandez [RNG1_K] = &ck_rng1_k, 25115436921fSGabriel Fernandez [BKPSRAM] = &ck_bkpsram, 25125436921fSGabriel Fernandez [SDMMC1_K] = &ck_sdmmc1_k, 25135436921fSGabriel Fernandez [SDMMC2_K] = &ck_sdmmc2_k, 25145436921fSGabriel Fernandez [CK_DBG] = &ck_dbg, 25155436921fSGabriel Fernandez [MCE] = &ck_mce, 25165436921fSGabriel Fernandez [TIM2_K] = &ck_tim2_k, 25175436921fSGabriel Fernandez [TIM3_K] = &ck_tim3_k, 25185436921fSGabriel Fernandez [TIM4_K] = &ck_tim4_k, 25195436921fSGabriel Fernandez [TIM5_K] = &ck_tim5_k, 25205436921fSGabriel Fernandez [TIM6_K] = &ck_tim6_k, 25215436921fSGabriel Fernandez [TIM7_K] = &ck_tim7_k, 25225436921fSGabriel Fernandez [TIM13_K] = &ck_tim13_k, 25235436921fSGabriel Fernandez [TIM14_K] = &ck_tim14_k, 25245436921fSGabriel Fernandez [TIM1_K] = &ck_tim1_k, 25255436921fSGabriel Fernandez [TIM8_K] = &ck_tim8_k, 25265436921fSGabriel Fernandez [TIM16_K] = &ck_tim16_k, 25275436921fSGabriel Fernandez [TIM17_K] = &ck_tim17_k, 25285436921fSGabriel Fernandez [LTDC_PX] = &ck_ltdc_px, 25295436921fSGabriel Fernandez [DMA1] = &ck_dma1, 25305436921fSGabriel Fernandez [DMA2] = &ck_dma2, 2531e84c2998SEtienne Carriere [ADC1] = &ck_adc1, 2532e84c2998SEtienne Carriere [ADC2] = &ck_adc2, 25335436921fSGabriel Fernandez [MDMA] = &ck_mdma, 25345436921fSGabriel Fernandez [ETH1MAC] = &ck_eth1mac, 25355436921fSGabriel Fernandez [USBH] = &ck_usbh, 25365436921fSGabriel Fernandez [VREF] = &ck_vref, 25375436921fSGabriel Fernandez [TMPSENS] = &ck_tmpsens, 25385436921fSGabriel Fernandez [PMBCTRL] = &ck_pmbctrl, 25395436921fSGabriel Fernandez [HDP] = &ck_hdp, 25405436921fSGabriel Fernandez [STGENRO] = &ck_stgenro, 25415436921fSGabriel Fernandez [DMAMUX1] = &ck_dmamux1, 25425436921fSGabriel Fernandez [DMAMUX2] = &ck_dmamux2, 25435436921fSGabriel Fernandez [DMA3] = &ck_dma3, 25445436921fSGabriel Fernandez [TSC] = &ck_tsc, 25455436921fSGabriel Fernandez [AXIMC] = &ck_aximc, 25465436921fSGabriel Fernandez [CRC1] = &ck_crc1, 25475436921fSGabriel Fernandez [ETH1TX] = &ck_eth1tx, 25485436921fSGabriel Fernandez [ETH1RX] = &ck_eth1rx, 25495436921fSGabriel Fernandez [ETH2TX] = &ck_eth2tx, 25505436921fSGabriel Fernandez [ETH2RX] = &ck_eth2rx, 25515436921fSGabriel Fernandez [ETH2MAC] = &ck_eth2mac, 25525436921fSGabriel Fernandez [USART3_K] = &ck_usart3_k, 25535436921fSGabriel Fernandez [UART4_K] = &ck_uart4_k, 25545436921fSGabriel Fernandez [UART5_K] = &ck_uart5_k, 25555436921fSGabriel Fernandez [UART7_K] = &ck_uart7_k, 25565436921fSGabriel Fernandez [UART8_K] = &ck_uart8_k, 25575436921fSGabriel Fernandez [USART6_K] = &ck_usart6_k, 25585436921fSGabriel Fernandez [FMC_K] = &ck_fmc_k, 25595436921fSGabriel Fernandez [QSPI_K] = &ck_qspi_k, 25605436921fSGabriel Fernandez [LPTIM1_K] = &ck_lptim1_k, 25615436921fSGabriel Fernandez [SPI2_K] = &ck_spi2_k, 25625436921fSGabriel Fernandez [SPI3_K] = &ck_spi3_k, 25635436921fSGabriel Fernandez [SPDIF_K] = &ck_spdif_k, 25645436921fSGabriel Fernandez [SPI1_K] = &ck_spi1_k, 25655436921fSGabriel Fernandez [SPI4_K] = &ck_spi4_k, 25665436921fSGabriel Fernandez [SPI5_K] = &ck_spi5_k, 25675436921fSGabriel Fernandez [SAI1_K] = &ck_sai1_k, 25685436921fSGabriel Fernandez [SAI2_K] = &ck_sai2_k, 25695436921fSGabriel Fernandez [DFSDM_K] = &ck_dfsdm_k, 25705436921fSGabriel Fernandez [FDCAN_K] = &ck_fdcan_k, 25715436921fSGabriel Fernandez [I2C1_K] = &ck_i2c1_k, 25725436921fSGabriel Fernandez [I2C2_K] = &ck_i2c2_k, 25735436921fSGabriel Fernandez [ADFSDM_K] = &ck_adfsdm_k, 25745436921fSGabriel Fernandez [LPTIM2_K] = &ck_lptim2_k, 25755436921fSGabriel Fernandez [LPTIM3_K] = &ck_lptim3_k, 25765436921fSGabriel Fernandez [LPTIM4_K] = &ck_lptim4_k, 25775436921fSGabriel Fernandez [LPTIM5_K] = &ck_lptim5_k, 25785436921fSGabriel Fernandez [I2C3_K] = &ck_i2c3_k, 25795436921fSGabriel Fernandez [I2C5_K] = &ck_i2c5_k, 25805436921fSGabriel Fernandez [DCMIPP_K] = &ck_dcmipp_k, 25815436921fSGabriel Fernandez [ADC1_K] = &ck_adc1_k, 25825436921fSGabriel Fernandez [ADC2_K] = &ck_adc2_k, 25835436921fSGabriel Fernandez [ETH1CK_K] = &ck_eth1ck_k, 25845436921fSGabriel Fernandez [ETH2CK_K] = &ck_eth2ck_k, 2585e84c2998SEtienne Carriere [SPI1] = &ck_spi1, 2586e84c2998SEtienne Carriere [SPI2] = &ck_spi2, 2587e84c2998SEtienne Carriere [SPI3] = &ck_spi3, 2588e84c2998SEtienne Carriere [SPI4] = &ck_spi4, 2589e84c2998SEtienne Carriere [SPI5] = &ck_spi5, 25905436921fSGabriel Fernandez [CK_MCO1] = &ck_mco1, 25915436921fSGabriel Fernandez [CK_MCO2] = &ck_mco2, 25925436921fSGabriel Fernandez [CK_TRACE] = &ck_trace, 25935436921fSGabriel Fernandez [CK_OFF] = &ck_off, 25945436921fSGabriel Fernandez [USB_PHY_48] = &ck_usb_phy_48Mhz, 25955436921fSGabriel Fernandez [I2S_CKIN] = &ck_i2sckin, 25965436921fSGabriel Fernandez }; 25975436921fSGabriel Fernandez 25985436921fSGabriel Fernandez static bool clk_stm32_clock_is_critical(struct clk *clk __maybe_unused) 25995436921fSGabriel Fernandez { 26005436921fSGabriel Fernandez struct clk *clk_criticals[] = { 26015436921fSGabriel Fernandez &ck_hsi, 26025436921fSGabriel Fernandez &ck_hse, 26035436921fSGabriel Fernandez &ck_csi, 26045436921fSGabriel Fernandez &ck_lsi, 26055436921fSGabriel Fernandez &ck_lse, 26065436921fSGabriel Fernandez &ck_pll2r, 26075436921fSGabriel Fernandez &ck_mpu, 26085436921fSGabriel Fernandez &ck_ddrc1, 26095436921fSGabriel Fernandez &ck_ddrc1lp, 26105436921fSGabriel Fernandez &ck_ddrphyc, 26115436921fSGabriel Fernandez &ck_ddrphyclp, 26125436921fSGabriel Fernandez &ck_ddrcapb, 26135436921fSGabriel Fernandez &ck_ddrcapblp, 26145436921fSGabriel Fernandez &ck_axidcg, 26155436921fSGabriel Fernandez &ck_ddrphycapb, 26165436921fSGabriel Fernandez &ck_ddrphycapblp, 26175436921fSGabriel Fernandez &ck_rtcapb, 26185436921fSGabriel Fernandez &ck_tzc, 26195436921fSGabriel Fernandez &ck_etzpcb, 26205436921fSGabriel Fernandez &ck_iwdg1apb, 26215436921fSGabriel Fernandez &ck_bsec, 26225436921fSGabriel Fernandez &ck_stgen_k, 26235436921fSGabriel Fernandez &ck_bkpsram, 26245436921fSGabriel Fernandez &ck_mce, 26255436921fSGabriel Fernandez &ck_mco1, 2626f73343d3SGatien Chevallier &ck_rng1_k, 2627f73343d3SGatien Chevallier &ck_mlahb, 26285436921fSGabriel Fernandez }; 26295436921fSGabriel Fernandez size_t i = 0; 26305436921fSGabriel Fernandez 26315436921fSGabriel Fernandez for (i = 0; i < ARRAY_SIZE(clk_criticals); i++) { 26325436921fSGabriel Fernandez struct clk *clk_critical = clk_criticals[i]; 26335436921fSGabriel Fernandez 26345436921fSGabriel Fernandez if (clk == clk_critical) 26355436921fSGabriel Fernandez return true; 26365436921fSGabriel Fernandez } 26375436921fSGabriel Fernandez 26385436921fSGabriel Fernandez return false; 26395436921fSGabriel Fernandez } 26405436921fSGabriel Fernandez 26415436921fSGabriel Fernandez static void clk_stm32_init_oscillators(const void *fdt, int node) 26425436921fSGabriel Fernandez { 26435436921fSGabriel Fernandez size_t i = 0; 26445436921fSGabriel Fernandez const char *name[6] = { "clk-hse", "clk-hsi", "clk-lse", 26455436921fSGabriel Fernandez "clk-lsi", "clk-csi", "clk-i2sin" }; 26465436921fSGabriel Fernandez struct clk *clks[6] = { &ck_hse, &ck_hsi, &ck_lse, 26475436921fSGabriel Fernandez &ck_lsi, &ck_csi, &ck_i2sckin }; 26485436921fSGabriel Fernandez 26495436921fSGabriel Fernandez for (i = 0; i < ARRAY_SIZE(clks); i++) { 26505436921fSGabriel Fernandez struct clk *clk = NULL; 26515436921fSGabriel Fernandez 26525436921fSGabriel Fernandez clk_dt_get_by_name(fdt, node, name[i], &clk); 26535436921fSGabriel Fernandez 26545436921fSGabriel Fernandez clks[i]->parents[0] = clk; 26555436921fSGabriel Fernandez } 26565436921fSGabriel Fernandez } 26575436921fSGabriel Fernandez 2658e5e793a6SGabriel Fernandez static struct stm32_pll_dt_cfg mp13_pll[PLL_NB]; 2659e5e793a6SGabriel Fernandez static struct stm32_clk_opp_dt_cfg mp13_clk_opp; 2660e5e793a6SGabriel Fernandez static struct stm32_osci_dt_cfg mp13_osci[NB_OSCILLATOR]; 2661e5e793a6SGabriel Fernandez static uint32_t mp13_clksrc[MUX_NB]; 2662e5e793a6SGabriel Fernandez static uint32_t mp13_clkdiv[DIV_NB]; 2663e5e793a6SGabriel Fernandez 2664e5e793a6SGabriel Fernandez static struct stm32_clk_platdata stm32mp13_clock_pdata = { 2665e5e793a6SGabriel Fernandez .osci = mp13_osci, 2666e5e793a6SGabriel Fernandez .nosci = NB_OSCILLATOR, 2667e5e793a6SGabriel Fernandez .pll = mp13_pll, 2668e5e793a6SGabriel Fernandez .opp = &mp13_clk_opp, 2669e5e793a6SGabriel Fernandez .npll = PLL_NB, 2670e5e793a6SGabriel Fernandez .clksrc = mp13_clksrc, 2671e5e793a6SGabriel Fernandez .nclksrc = MUX_NB, 2672e5e793a6SGabriel Fernandez .clkdiv = mp13_clkdiv, 2673e5e793a6SGabriel Fernandez .nclkdiv = DIV_NB, 2674e5e793a6SGabriel Fernandez }; 2675e5e793a6SGabriel Fernandez 2676e5e793a6SGabriel Fernandez static struct clk_stm32_priv stm32mp13_clock_data = { 2677e5e793a6SGabriel Fernandez .muxes = parent_mp13, 2678e5e793a6SGabriel Fernandez .nb_muxes = ARRAY_SIZE(parent_mp13), 2679e5e793a6SGabriel Fernandez .gates = gates_mp13, 2680e5e793a6SGabriel Fernandez .nb_gates = ARRAY_SIZE(gates_mp13), 2681e5e793a6SGabriel Fernandez .div = dividers_mp13, 2682e5e793a6SGabriel Fernandez .nb_div = ARRAY_SIZE(dividers_mp13), 2683e5e793a6SGabriel Fernandez .pdata = &stm32mp13_clock_pdata, 26845436921fSGabriel Fernandez .nb_clk_refs = STM32MP13_ALL_CLK_NB, 26855436921fSGabriel Fernandez .clk_refs = stm32mp13_clk_provided, 26865436921fSGabriel Fernandez .is_critical = clk_stm32_clock_is_critical, 2687e5e793a6SGabriel Fernandez }; 2688e5e793a6SGabriel Fernandez 2689e5e793a6SGabriel Fernandez static TEE_Result stm32mp13_clk_probe(const void *fdt, int node, 2690e5e793a6SGabriel Fernandez const void *compat_data __unused) 2691e5e793a6SGabriel Fernandez { 2692e5e793a6SGabriel Fernandez TEE_Result res = TEE_ERROR_GENERIC; 2693e5e793a6SGabriel Fernandez int fdt_rc = 0; 2694e5e793a6SGabriel Fernandez int rc = 0; 2695e5e793a6SGabriel Fernandez struct clk_stm32_priv *priv = &stm32mp13_clock_data; 2696e5e793a6SGabriel Fernandez struct stm32_clk_platdata *pdata = &stm32mp13_clock_pdata; 2697e5e793a6SGabriel Fernandez 2698e5e793a6SGabriel Fernandez fdt_rc = stm32_clk_parse_fdt(fdt, node, pdata); 2699e5e793a6SGabriel Fernandez if (fdt_rc) { 2700e5e793a6SGabriel Fernandez EMSG("Failed to parse clock node: %d", fdt_rc); 2701e5e793a6SGabriel Fernandez return TEE_ERROR_GENERIC; 2702e5e793a6SGabriel Fernandez } 2703e5e793a6SGabriel Fernandez 2704e5e793a6SGabriel Fernandez res = clk_stm32_init(priv, stm32_rcc_base()); 2705e5e793a6SGabriel Fernandez if (res) 2706e5e793a6SGabriel Fernandez return res; 2707e5e793a6SGabriel Fernandez 2708e5e793a6SGabriel Fernandez rc = stm32mp1_init_clock_tree(priv, pdata); 2709e5e793a6SGabriel Fernandez if (rc) 2710e5e793a6SGabriel Fernandez return TEE_ERROR_GENERIC; 2711e5e793a6SGabriel Fernandez 27125436921fSGabriel Fernandez clk_stm32_init_oscillators(fdt, node); 27135436921fSGabriel Fernandez 27145436921fSGabriel Fernandez stm32mp_clk_provider_probe_final(fdt, node, priv); 27155436921fSGabriel Fernandez 2716e5e793a6SGabriel Fernandez return TEE_SUCCESS; 2717e5e793a6SGabriel Fernandez } 2718e5e793a6SGabriel Fernandez 2719e5e793a6SGabriel Fernandez CLK_DT_DECLARE(stm32mp13_clk, "st,stm32mp13-rcc", stm32mp13_clk_probe); 2720