2 * STM32L4X5 RCC (Reset and clock control)
4 * Copyright (c) 2023 Arnaud Minier <arnaud.minier@telecom-paris.fr>
5 * Copyright (c) 2023 Inès Varhol <ines.varhol@telecom-paris.fr>
7 * SPDX-License-Identifier: GPL-2.0-or-later
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
12 * The reference used is the STMicroElectronics RM0351 Reference manual
13 * for STM32L4x5 and STM32L4x6 advanced Arm ® -based 32-bit MCUs.
15 * Inspired by the BCM2835 CPRMAN clock manager by Luc Michel.
18 #ifndef HW_STM32L4X5_RCC_H
19 #define HW_STM32L4X5_RCC_H
21 #include "hw/sysbus.h"
22 #include "qom/object.h"
24 #define TYPE_STM32L4X5_RCC "stm32l4x5-rcc"
25 OBJECT_DECLARE_SIMPLE_TYPE(Stm32l4x5RccState
, STM32L4X5_RCC
)
27 /* In the Stm32l4x5 clock tree, mux have at most 7 sources */
28 #define RCC_NUM_CLOCK_MUX_SRC 7
30 typedef enum PllCommonChannels
{
31 RCC_PLL_COMMON_CHANNEL_P
= 0,
32 RCC_PLL_COMMON_CHANNEL_Q
= 1,
33 RCC_PLL_COMMON_CHANNEL_R
= 2,
35 RCC_NUM_CHANNEL_PLL_OUT
= 3
38 /* NB: Prescaler are assimilated to mux with one source and one output */
39 typedef enum RccClockMux
{
40 /* Internal muxes that arent't exposed publicly to other peripherals */
42 RCC_CLOCK_MUX_PLL_INPUT
,
46 RCC_CLOCK_MUX_HSE_OVER_32
,
47 RCC_CLOCK_MUX_LCD_AND_RTC_COMMON
,
49 /* Muxes with a publicly available output */
50 RCC_CLOCK_MUX_CORTEX_REFCLK
,
56 RCC_CLOCK_MUX_LPUART1
,
72 * Mux that have only one input and one output assigned to as peripheral.
73 * They could be direct lines but it is simpler
74 * to use the same logic for all outputs.
123 RCC_CLOCK_MUX_SDMMC1
,
125 RCC_CLOCK_MUX_SYSCFG
,
131 RCC_CLOCK_MUX_CORTEX_FCLK
,
136 typedef enum RccPll
{
144 typedef struct RccClockMuxState
{
145 DeviceState parent_obj
;
148 Clock
*srcs
[RCC_NUM_CLOCK_MUX_SRC
];
156 * Used by clock srcs update callback to retrieve both the clock and the
159 struct RccClockMuxState
*backref
[RCC_NUM_CLOCK_MUX_SRC
];
162 typedef struct RccPllState
{
163 DeviceState parent_obj
;
167 uint32_t vco_multiplier
;
168 Clock
*channels
[RCC_NUM_CHANNEL_PLL_OUT
];
169 /* Global pll enabled flag */
171 /* 'enabled' refers to the runtime configuration */
172 bool channel_enabled
[RCC_NUM_CHANNEL_PLL_OUT
];
174 * 'exists' refers to the physical configuration
175 * It should only be set at pll initialization.
176 * e.g. pllsai2 doesn't have a Q output.
178 bool channel_exists
[RCC_NUM_CHANNEL_PLL_OUT
];
179 uint32_t channel_divider
[RCC_NUM_CHANNEL_PLL_OUT
];
182 struct Stm32l4x5RccState
{
183 SysBusDevice parent_obj
;
191 uint32_t pllsai1cfgr
;
192 uint32_t pllsai2cfgr
;
228 RccPllState plls
[RCC_NUM_PLL
];
230 /* Muxes ~= outputs */
231 RccClockMuxState clock_muxes
[RCC_NUM_CLOCK_MUX
];
234 uint64_t hse_frequency
;
235 uint64_t sai1_extclk_frequency
;
236 uint64_t sai2_extclk_frequency
;
239 #endif /* HW_STM32L4X5_RCC_H */