Skip to content

Commit bced529

Browse files
erwangocarlescufi
authored andcommitted
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 <[email protected]>
1 parent d0f497c commit bced529

File tree

5 files changed

+12
-20
lines changed

5 files changed

+12
-20
lines changed

drivers/clock_control/clock_stm32_mux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static int stm32_clk_mux_init(const struct device *dev)
3737
#define STM32_MUX_CLK_INIT(id) \
3838
\
3939
static const struct stm32_clk_mux_config stm32_clk_mux_cfg_##id = { \
40-
.pclken = STM32_INST_CLOCK_INFO(id, 0) \
40+
.pclken = STM32_CLOCK_INFO(0, DT_DRV_INST(id)) \
4141
}; \
4242
\
4343
DEVICE_DT_INST_DEFINE(id, &stm32_clk_mux_init, NULL, \

include/zephyr/drivers/clock_control/stm32_clock_control.h

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -281,27 +281,19 @@ struct stm32_pclken {
281281

282282
/** Device tree clocks helpers */
283283

284-
#define STM32_CLOCK_INFO(clk_index, id) \
284+
#define STM32_CLOCK_INFO(clk_index, node_id) \
285285
{ \
286-
.enr = DT_CLOCKS_CELL_BY_IDX(DT_NODELABEL(id), clk_index, bits),\
287-
.bus = DT_CLOCKS_CELL_BY_IDX(DT_NODELABEL(id), clk_index, bus) \
286+
.enr = DT_CLOCKS_CELL_BY_IDX(node_id, clk_index, bits), \
287+
.bus = DT_CLOCKS_CELL_BY_IDX(node_id, clk_index, bus) \
288288
}
289-
#define STM32_DT_CLOCKS(id) \
289+
#define STM32_DT_CLOCKS(node_id) \
290290
{ \
291-
LISTIFY(DT_NUM_CLOCKS(DT_NODELABEL(id)), \
292-
STM32_CLOCK_INFO, (,), id) \
291+
LISTIFY(DT_NUM_CLOCKS(node_id), \
292+
STM32_CLOCK_INFO, (,), node_id) \
293293
}
294294

295-
#define STM32_INST_CLOCK_INFO(clk_index, inst) \
296-
{ \
297-
.enr = DT_INST_CLOCKS_CELL_BY_IDX(inst, clk_index, bits), \
298-
.bus = DT_INST_CLOCKS_CELL_BY_IDX(inst, clk_index, bus) \
299-
}
300295
#define STM32_DT_INST_CLOCKS(inst) \
301-
{ \
302-
LISTIFY(DT_INST_NUM_CLOCKS(inst), \
303-
STM32_INST_CLOCK_INFO, (,), inst) \
304-
}
296+
STM32_DT_CLOCKS(DT_DRV_INST(inst))
305297

306298
#define STM32_OPT_CLOCK_INST_SUPPORT(inst) DT_INST_CLOCKS_HAS_IDX(inst, 1) ||
307299
#define STM32_DT_INST_DEV_OPT_CLOCK_SUPPORT \

tests/drivers/clock_control/stm32_clock_configuration/stm32_common_devices/src/test_stm32_clock_configuration.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ static void test_sysclk_freq(void)
4141

4242
static void test_i2c_clk_config(void)
4343
{
44-
static const struct stm32_pclken pclken[] = STM32_DT_CLOCKS(i2c1);
44+
static const struct stm32_pclken pclken[] = STM32_DT_CLOCKS(DT_NODELABEL(i2c1));
4545

4646
uint32_t dev_dt_clk_freq, dev_actual_clk_freq;
4747
uint32_t dev_actual_clk_src;
@@ -136,7 +136,7 @@ static void test_i2c_clk_config(void) {}
136136

137137
static void test_lptim_clk_config(void)
138138
{
139-
static const struct stm32_pclken pclken[] = STM32_DT_CLOCKS(lptim1);
139+
static const struct stm32_pclken pclken[] = STM32_DT_CLOCKS(DT_NODELABEL(lptim1));
140140

141141
uint32_t dev_dt_clk_freq, dev_actual_clk_freq;
142142
uint32_t dev_actual_clk_src;

tests/drivers/clock_control/stm32_clock_configuration/stm32h7_devices/src/test_stm32_clock_configuration.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static void test_sysclk_freq(void)
3535

3636
static void test_spi_clk_config(void)
3737
{
38-
static const struct stm32_pclken pclken[] = STM32_DT_CLOCKS(spi1);
38+
static const struct stm32_pclken pclken[] = STM32_DT_CLOCKS(DT_NODELABEL(spi1));
3939
struct stm32_pclken spi1_reg_clk_cfg = pclken[0];
4040

4141
uint32_t spi1_actual_clk_src, spi1_dt_ker_clk_src;

tests/drivers/clock_control/stm32_clock_configuration/stm32u5_devices/src/test_stm32_clock_configuration.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static void test_sysclk_freq(void)
3535

3636
static void test_spi_clk_config(void)
3737
{
38-
static const struct stm32_pclken pclken[] = STM32_DT_CLOCKS(spi1);
38+
static const struct stm32_pclken pclken[] = STM32_DT_CLOCKS(DT_NODELABEL(spi1));
3939

4040
uint32_t spi1_actual_clk_src;
4141
uint32_t spi1_dt_clk_freq, spi1_actual_clk_freq;

0 commit comments

Comments
 (0)