Skip to content

Commit fc61680

Browse files
committed
drivers: clock_control: Add STM32 clock multiplexer driver
Add a clock multiplexer driver. Its only function is to select a clock input. Signed-off-by: Erwan Gouriou <[email protected]>
1 parent 15bdee2 commit fc61680

File tree

3 files changed

+60
-1
lines changed

3 files changed

+60
-1
lines changed

drivers/clock_control/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_RCAR_CPG_MSSR clock_cont
2121
zephyr_library_sources_ifdef(CONFIG_CLOCK_CONTROL_RV32M1_PCC clock_control_rv32m1_pcc.c)
2222

2323
if(CONFIG_CLOCK_CONTROL_STM32_CUBE)
24+
zephyr_library_sources_ifdef(CONFIG_CLOCK_STM32_MUX clock_stm32_mux.c)
2425
if(CONFIG_SOC_SERIES_STM32MP1X)
2526
zephyr_library_sources(clock_stm32_ll_mp1.c)
2627
elseif(CONFIG_SOC_SERIES_STM32H7X)

drivers/clock_control/Kconfig.stm32

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ menuconfig CLOCK_CONTROL_STM32_CUBE
88
bool "STM32 Reset & Clock Control"
99
depends on SOC_FAMILY_STM32
1010
select USE_STM32_LL_UTILS
11-
select USE_STM32_LL_RCC if SOC_SERIES_STM32MP1X
11+
select USE_STM32_LL_RCC if (SOC_SERIES_STM32MP1X || SOC_SERIES_STM32H7X)
1212
help
1313
Enable driver for Reset & Clock Control subsystem found
1414
in STM32 family of MCUs
@@ -17,6 +17,7 @@ if CLOCK_CONTROL_STM32_CUBE
1717

1818
DT_STM32_HSE_CLOCK := $(dt_nodelabel_path,clk_hse)
1919
DT_STM32_HSE_CLOCK_FREQ := $(dt_node_int_prop_int,$(DT_STM32_HSE_CLOCK),clock-frequency)
20+
DT_COMPAT_ST_MUX_CLOCK := st,stm32-clock-mux
2021

2122
config CLOCK_STM32_HSE_CLOCK
2223
int "HSE clock value"
@@ -33,6 +34,15 @@ config CLOCK_STM32_HSE_CLOCK
3334
Note: Device tree configuration is overridden when current symbol is set:
3435
CONFIG_CLOCK_STM32_HSE_CLOCK=32000000
3536

37+
config CLOCK_STM32_MUX
38+
bool "STM32 clock mux driver"
39+
default $(dt_compat_enabled,$(DT_COMPAT_ST_MUX_CLOCK))
40+
help
41+
Enable driver for STM32 clock mux which don't match an
42+
existing clock hardware block but allows to select a clock
43+
for a specific domain. For instance per_ck clock on STM32H7 or
44+
CLK48 clock
45+
3646
# Micro-controller Clock output configuration options
3747

3848
choice
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (C) 2022, Linaro Ltd
5+
*
6+
*/
7+
8+
#include <drivers/clock_control.h>
9+
#include <sys/util.h>
10+
#include <drivers/clock_control/stm32_clock_control.h>
11+
12+
#include <logging/log.h>
13+
#include <soc.h>
14+
15+
#define DT_DRV_COMPAT st_stm32_clock_mux
16+
17+
LOG_MODULE_REGISTER(clock_mux, CONFIG_CLOCK_CONTROL_LOG_LEVEL);
18+
19+
20+
struct stm32_clk_mux_config {
21+
const struct stm32_pclken pclken;
22+
};
23+
24+
static int stm32_clk_mux_init(const struct device *dev)
25+
{
26+
const struct stm32_clk_mux_config *cfg = dev->config;
27+
28+
if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
29+
(clock_control_subsys_t) &cfg->pclken) != 0) {
30+
LOG_ERR("Could not enable clock mux");
31+
return -EIO;
32+
}
33+
34+
return 0;
35+
}
36+
37+
#define STM32_MUX_CLK_INIT(id) \
38+
\
39+
static const struct stm32_clk_mux_config stm32_clk_mux_cfg_##id = { \
40+
.pclken = STM32_INST_CLOCK_INFO(id, 0) \
41+
}; \
42+
\
43+
DEVICE_DT_INST_DEFINE(id, &stm32_clk_mux_init, NULL, \
44+
NULL, &stm32_clk_mux_cfg_##id, \
45+
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_OBJECTS, \
46+
NULL);
47+
48+
DT_INST_FOREACH_STATUS_OKAY(STM32_MUX_CLK_INIT)

0 commit comments

Comments
 (0)