1 /*
2  *
3  * Copyright (c) 2018 Ilya Tagunov
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 
9 #include <soc.h>
10 #include <stm32_ll_bus.h>
11 #include <stm32_ll_rcc.h>
12 #include <stm32_ll_utils.h>
13 #include <drivers/clock_control.h>
14 #include <sys/util.h>
15 #include <drivers/clock_control/stm32_clock_control.h>
16 #include "clock_stm32_ll_common.h"
17 
18 
19 #if STM32_SYSCLK_SRC_PLL
20 
21 /* Macros to fill up multiplication and division factors values */
22 #define z_pll_mul(v) LL_RCC_PLL_MUL_ ## v
23 #define pll_mul(v) z_pll_mul(v)
24 
25 #define z_pll_div(v) LL_RCC_PLL_DIV_ ## v
26 #define pll_div(v) z_pll_div(v)
27 
28 /**
29  * @brief Fill PLL configuration structure
30  */
config_pll_init(LL_UTILS_PLLInitTypeDef * pllinit)31 void config_pll_init(LL_UTILS_PLLInitTypeDef *pllinit)
32 {
33 	pllinit->PLLMul = pll_mul(STM32_PLL_MULTIPLIER);
34 	pllinit->PLLDiv = pll_div(STM32_PLL_DIVISOR);
35 }
36 
37 #endif /* STM32_SYSCLK_SRC_PLL */
38 
39 /**
40  * @brief Activate default clocks
41  */
config_enable_default_clocks(void)42 void config_enable_default_clocks(void)
43 {
44 #if defined(CONFIG_EXTI_STM32) || defined(CONFIG_USB_DC_STM32) || \
45 	(defined(CONFIG_SOC_SERIES_STM32L0X) &&			  \
46 	 defined(CONFIG_ENTROPY_STM32_RNG))
47 	/* Enable System Configuration Controller clock. */
48 	LL_APB2_GRP1_EnableClock(LL_APB2_GRP1_PERIPH_SYSCFG);
49 #endif
50 }
51