From 3a603445221635aec185ad960566e7ce6f6f6223 Mon Sep 17 00:00:00 2001 From: Alexandre Bourdiol Date: Wed, 20 Oct 2021 19:43:08 +0200 Subject: [PATCH] drivers: pwm: stm32: move "st,prescaler" to timers instead of pwm Prescaler was misplaced in pwm binding, instead of timers binding. For example, TIM6/TIM7 doesn't have PWM capability, but have a prescaler. This change also prepares the introduction of timer based counter (which requires prescaler at timer level) For compatibility reason temporarily use pwm prescaler if it exists, otehrwise use timers prescaler. And thus avoid to avoid breaking boards out of tree. Signed-off-by: Alexandre Bourdiol --- drivers/pwm/pwm_stm32.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/drivers/pwm/pwm_stm32.c b/drivers/pwm/pwm_stm32.c index b05208673ff..8275bd5685e 100644 --- a/drivers/pwm/pwm_stm32.c +++ b/drivers/pwm/pwm_stm32.c @@ -340,6 +340,13 @@ static int pwm_stm32_init(const struct device *dev) .enr = DT_CLOCKS_CELL(DT_PARENT(DT_DRV_INST(index)), bits) \ } +/* Print warning if any pwm node has 'st,prescaler' property */ +#define PRESCALER_PWM(index) DT_INST_NODE_HAS_PROP(index, st_prescaler) || +#if (DT_INST_FOREACH_STATUS_OKAY(PRESCALER_PWM) 0) +#warning "DT property 'st,prescaler' in pwm node is deprecated and should be \ +replaced by 'st,prescaler' property in parent node, aka timers" +#endif + #define PWM_DEVICE_INIT(index) \ static struct pwm_stm32_data pwm_stm32_data_##index; \ \ @@ -349,7 +356,11 @@ static int pwm_stm32_init(const struct device *dev) static const struct pwm_stm32_config pwm_stm32_config_##index = { \ .timer = (TIM_TypeDef *)DT_REG_ADDR( \ DT_PARENT(DT_DRV_INST(index))), \ - .prescaler = DT_INST_PROP(index, st_prescaler), \ + /* For compatibility reason, use pwm st_prescaler property */ \ + /* if exist, otherwise use parent (timers) property */ \ + .prescaler = DT_PROP_OR(DT_DRV_INST(index), st_prescaler, \ + (DT_PROP(DT_PARENT(DT_DRV_INST(index)), \ + st_prescaler))), \ .pclken = DT_INST_CLK(index, timer), \ .pinctrl = pwm_pins_##index, \ .pinctrl_len = ARRAY_SIZE(pwm_pins_##index), \