zephyr/drivers/clock_control/clock_stm32_mux.c
Erwan Gouriou bced529f78 include: stm32: clock_control: Ease usage of STM32_DT_CLOCKS macro
STM32_DT_CLOCKS was designed to take a device tree node label name as
argument: STM32_DT_CLOCKS(uart1)
Change its implementation to take a node identifier instead:
STM32_DT_CLOCKS(DT_NODELABEL(uart1)).

This make its usage more flexible since the argument can now be extracted
from other DT macros such as DT_PARENT. Then, the following can be done:
STM32_DT_CLOCKS(DT_PARENT(child_node_label)).

Since it is now possible implement STM32_DT_INST_CLOCKS using
STM32_DT_CLOCKS.

Finally, update existing STM32_DT_CLOCKS users and convert
STM32_INST_CLOCK_INFO users to STM32_CLOCK_INFO.

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2022-06-28 11:07:29 +02:00

49 lines
1.1 KiB
C

/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright (C) 2022, Linaro Ltd
*
*/
#include <zephyr/drivers/clock_control.h>
#include <zephyr/sys/util.h>
#include <zephyr/drivers/clock_control/stm32_clock_control.h>
#include <zephyr/logging/log.h>
#include <soc.h>
#define DT_DRV_COMPAT st_stm32_clock_mux
LOG_MODULE_REGISTER(clock_mux, CONFIG_CLOCK_CONTROL_LOG_LEVEL);
struct stm32_clk_mux_config {
const struct stm32_pclken pclken;
};
static int stm32_clk_mux_init(const struct device *dev)
{
const struct stm32_clk_mux_config *cfg = dev->config;
if (clock_control_on(DEVICE_DT_GET(STM32_CLOCK_CONTROL_NODE),
(clock_control_subsys_t) &cfg->pclken) != 0) {
LOG_ERR("Could not enable clock mux");
return -EIO;
}
return 0;
}
#define STM32_MUX_CLK_INIT(id) \
\
static const struct stm32_clk_mux_config stm32_clk_mux_cfg_##id = { \
.pclken = STM32_CLOCK_INFO(0, DT_DRV_INST(id)) \
}; \
\
DEVICE_DT_INST_DEFINE(id, &stm32_clk_mux_init, NULL, \
NULL, &stm32_clk_mux_cfg_##id, \
PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_OBJECTS,\
NULL);
DT_INST_FOREACH_STATUS_OKAY(STM32_MUX_CLK_INIT)