Skip to content

Commit 9bc78cf

Browse files
youssefz24kartben
authored andcommitted
drivers: clock_control: add mp2 clock driver
Add the stm32mp2 clock driver to the clock_control subsystem. The driver is a reduced version of the generic stm32 clock driver. Signed-off-by: Youssef Zini <youssef.zini@savoirfairelinux.com>
1 parent 7f23ce2 commit 9bc78cf

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

drivers/clock_control/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ if(CONFIG_SOC_SERIES_STM32MP1X)
6767
zephyr_library_sources(clock_stm32_ll_mp1.c)
6868
elseif(CONFIG_SOC_SERIES_STM32MP13X)
6969
zephyr_library_sources(clock_stm32_ll_mp13.c)
70+
elseif(CONFIG_SOC_SERIES_STM32MP2X)
71+
zephyr_library_sources(clock_stm32_ll_mp2.c)
7072
elseif(CONFIG_SOC_SERIES_STM32H7X)
7173
zephyr_library_sources(clock_stm32_ll_h7.c)
7274
elseif(CONFIG_SOC_SERIES_STM32H7RSX)
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (C) 2025 Savoir-faire Linux, Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <soc.h>
8+
#include <stm32_ll_bus.h>
9+
#include <stm32_ll_rcc.h>
10+
#include <zephyr/arch/cpu.h>
11+
#include <zephyr/drivers/clock_control/stm32_clock_control.h>
12+
#include <zephyr/sys/util.h>
13+
14+
static int stm32_clock_control_on(const struct device *dev, clock_control_subsys_t sub_system)
15+
{
16+
struct stm32_pclken *pclken = (struct stm32_pclken *) sub_system;
17+
18+
ARG_UNUSED(dev);
19+
20+
if (!IN_RANGE(pclken->bus, STM32_CLOCK_PERIPH_MIN, STM32_CLOCK_PERIPH_MAX)) {
21+
/* Attempt to change a wrong periph clock bit */
22+
return -ENOTSUP;
23+
}
24+
25+
sys_set_bits(DT_REG_ADDR(DT_NODELABEL(rcc)) + pclken->bus, pclken->enr);
26+
27+
return 0;
28+
}
29+
30+
static int stm32_clock_control_off(const struct device *dev, clock_control_subsys_t sub_system)
31+
{
32+
struct stm32_pclken *pclken = (struct stm32_pclken *) sub_system;
33+
34+
ARG_UNUSED(dev);
35+
36+
if (!IN_RANGE(pclken->bus, STM32_CLOCK_PERIPH_MIN, STM32_CLOCK_PERIPH_MAX)) {
37+
/* Attempt to toggle a wrong periph clock bit */
38+
return -ENOTSUP;
39+
}
40+
41+
sys_clear_bits(DT_REG_ADDR(DT_NODELABEL(rcc)) + pclken->bus, pclken->enr);
42+
43+
return 0;
44+
}
45+
46+
static int stm32_clock_control_get_subsys_rate(const struct device *dev,
47+
clock_control_subsys_t sub_system, uint32_t *rate)
48+
{
49+
ARG_UNUSED(dev);
50+
ARG_UNUSED(sub_system);
51+
ARG_UNUSED(rate);
52+
return -ENOTSUP;
53+
}
54+
55+
static DEVICE_API(clock_control, stm32_clock_control_api) = {
56+
.on = stm32_clock_control_on,
57+
.off = stm32_clock_control_off,
58+
.get_rate = stm32_clock_control_get_subsys_rate,
59+
};
60+
61+
static int stm32_clock_control_init(const struct device *dev)
62+
{
63+
ARG_UNUSED(dev);
64+
return 0;
65+
}
66+
67+
/**
68+
* @brief RCC device, note that priority is intentionally set to 1 so
69+
* that the device init runs just after SOC init
70+
*/
71+
DEVICE_DT_DEFINE(DT_NODELABEL(rcc), stm32_clock_control_init, NULL, NULL, NULL, PRE_KERNEL_1,
72+
CONFIG_CLOCK_CONTROL_INIT_PRIORITY, &stm32_clock_control_api);

include/zephyr/drivers/clock_control/stm32_clock_control.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
#elif defined(CONFIG_SOC_SERIES_STM32L4X) || \
4242
defined(CONFIG_SOC_SERIES_STM32L5X)
4343
#include <zephyr/dt-bindings/clock/stm32l4_clock.h>
44+
#elif defined(CONFIG_SOC_SERIES_STM32MP2X)
45+
#include <zephyr/dt-bindings/clock/stm32mp2_clock.h>
4446
#elif defined(CONFIG_SOC_SERIES_STM32WBX)
4547
#include <zephyr/dt-bindings/clock/stm32wb_clock.h>
4648
#elif defined(CONFIG_SOC_SERIES_STM32WB0X)

0 commit comments

Comments
 (0)