1 /*
2  *
3  * Copyright (c) 2019 Ilya Tagunov
4  * Copyright (c) 2019 STMicroelectronics
5  *
6  * SPDX-License-Identifier: Apache-2.0
7  */
8 
9 
10 #include <soc.h>
11 #include <stm32_ll_bus.h>
12 #include <stm32_ll_rcc.h>
13 #include <stm32_ll_utils.h>
14 #include <zephyr/drivers/clock_control.h>
15 #include <zephyr/sys/util.h>
16 #include <zephyr/drivers/clock_control/stm32_clock_control.h>
17 #include "clock_stm32_ll_common.h"
18 
19 #if defined(STM32_PLL_ENABLED)
20 
21 /**
22  * @brief Return PLL source
23  */
24 __unused
get_pll_source(void)25 static uint32_t get_pll_source(void)
26 {
27 	/* Configure PLL source */
28 	if (IS_ENABLED(STM32_PLL_SRC_HSI)) {
29 		return LL_RCC_PLLSOURCE_HSI;
30 	} else if (IS_ENABLED(STM32_PLL_SRC_HSE)) {
31 		return LL_RCC_PLLSOURCE_HSE;
32 	}
33 
34 	__ASSERT(0, "Invalid source");
35 	return 0;
36 }
37 
38 /**
39  * @brief get the pll source frequency
40  */
41 __unused
get_pllsrc_frequency(void)42 uint32_t get_pllsrc_frequency(void)
43 {
44 	if (IS_ENABLED(STM32_PLL_SRC_HSI)) {
45 		return STM32_HSI_FREQ;
46 	} else if (IS_ENABLED(STM32_PLL_SRC_HSE)) {
47 		return STM32_HSE_FREQ;
48 	}
49 
50 	__ASSERT(0, "Invalid source");
51 	return 0;
52 }
53 
54 /**
55  * @brief Set up pll configuration
56  */
57 __unused
config_pll_sysclock(void)58 void config_pll_sysclock(void)
59 {
60 	LL_RCC_PLL_ConfigDomain_SYS(get_pll_source(),
61 				    pllm(STM32_PLL_M_DIVISOR),
62 				    STM32_PLL_N_MULTIPLIER,
63 				    pllr(STM32_PLL_R_DIVISOR));
64 
65 	LL_RCC_PLL_EnableDomain_SYS();
66 }
67 
68 #endif /* defined(STM32_PLL_ENABLED) */
69 
70 /**
71  * @brief Activate default clocks
72  */
config_enable_default_clocks(void)73 void config_enable_default_clocks(void)
74 {
75 	/* Enable the power interface clock */
76 	LL_APB1_GRP1_EnableClock(LL_APB1_GRP1_PERIPH_PWR);
77 }
78