drivers: pwm: nrf_sw: convert to timer phandle instead instance number

So far 'timer-instance' DT property was the way to configure TIMER which
was used for generating PWM signal. Replace that by using 'generator'
phandle, so we get prepared for supporting RTC instances as PWM signal
generator.

Signed-off-by: Marcin Niestroj <m.niestroj@grinn-global.com>
This commit is contained in:
Marcin Niestroj 2020-11-11 15:01:54 +01:00 committed by Carles Cufí
commit 0d58960abb
10 changed files with 34 additions and 15 deletions

View file

@ -16,11 +16,22 @@
#include <logging/log.h> #include <logging/log.h>
LOG_MODULE_REGISTER(pwm_nrf5_sw); LOG_MODULE_REGISTER(pwm_nrf5_sw);
BUILD_ASSERT(DT_INST_NODE_HAS_PROP(0, timer_instance) !=
DT_INST_NODE_HAS_PROP(0, generator),
"Please define either the timer-instance or generator property, but not both");
#if DT_INST_NODE_HAS_PROP(0, timer_instance)
#define GENERATOR_ADDR _CONCAT(NRF_TIMER, DT_INST_PROP(0, timer_instance))
#define GENERATOR_CC_NUM \
_CONCAT(_CONCAT(TIMER, DT_INST_PROP(0, timer_instance)), _CC_NUM)
#else /* DT_INST_NODE_HAS_PROP(0, timer_instance) */
#define GENERATOR_NODE DT_PHANDLE(DT_DRV_INST(0), generator)
#define GENERATOR_ADDR ((NRF_TIMER_Type *) DT_REG_ADDR(GENERATOR_NODE))
#define GENERATOR_CC_NUM DT_PROP(GENERATOR_NODE, cc_num)
#endif /* DT_INST_NODE_HAS_PROP(0, timer_instance) */
/* One compare channel is needed to set the PWM period, hence +1. */ /* One compare channel is needed to set the PWM period, hence +1. */
#if ((DT_INST_PROP(0, channel_count) + 1) > \ #if ((DT_INST_PROP(0, channel_count) + 1) > GENERATOR_CC_NUM)
(_CONCAT( \
_CONCAT(TIMER, DT_INST_PROP(0, timer_instance)), \
_CC_NUM)))
#error "Invalid number of PWM channels configured." #error "Invalid number of PWM channels configured."
#endif #endif
#define PWM_0_MAP_SIZE DT_INST_PROP(0, channel_count) #define PWM_0_MAP_SIZE DT_INST_PROP(0, channel_count)
@ -257,7 +268,7 @@ static int pwm_nrf5_sw_init(const struct device *dev)
} }
static const struct pwm_config pwm_nrf5_sw_0_config = { static const struct pwm_config pwm_nrf5_sw_0_config = {
.timer = _CONCAT(NRF_TIMER, DT_INST_PROP(0, timer_instance)), .timer = GENERATOR_ADDR,
.ppi_base = DT_INST_PROP(0, ppi_base), .ppi_base = DT_INST_PROP(0, ppi_base),
.gpiote_base = DT_INST_PROP(0, gpiote_base), .gpiote_base = DT_INST_PROP(0, gpiote_base),
.map_size = PWM_0_MAP_SIZE, .map_size = PWM_0_MAP_SIZE,

View file

@ -231,7 +231,7 @@
&sw_pwm { &sw_pwm {
timer-instance = <1>; generator = <&timer1>;
channel-count = <3>; channel-count = <3>;
clock-prescaler = <0>; clock-prescaler = <0>;
ppi-base = <7>; ppi-base = <7>;

View file

@ -219,7 +219,7 @@
}; };
&sw_pwm { &sw_pwm {
timer-instance = <2>; generator = <&timer2>;
channel-count = <3>; channel-count = <3>;
clock-prescaler = <0>; clock-prescaler = <0>;
ppi-base = <7>; ppi-base = <7>;

View file

@ -221,7 +221,7 @@
}; };
&sw_pwm { &sw_pwm {
timer-instance = <2>; generator = <&timer2>;
channel-count = <3>; channel-count = <3>;
clock-prescaler = <0>; clock-prescaler = <0>;
ppi-base = <14>; ppi-base = <14>;

View file

@ -244,7 +244,7 @@
}; };
&sw_pwm { &sw_pwm {
timer-instance = <2>; generator = <&timer2>;
channel-count = <3>; channel-count = <3>;
clock-prescaler = <0>; clock-prescaler = <0>;
ppi-base = <14>; ppi-base = <14>;

View file

@ -255,7 +255,7 @@
}; };
&sw_pwm { &sw_pwm {
timer-instance = <2>; generator = <&timer2>;
channel-count = <3>; channel-count = <3>;
clock-prescaler = <0>; clock-prescaler = <0>;
ppi-base = <14>; ppi-base = <14>;

View file

@ -319,7 +319,7 @@
}; };
&sw_pwm { &sw_pwm {
timer-instance = <2>; generator = <&timer2>;
channel-count = <3>; channel-count = <3>;
clock-prescaler = <0>; clock-prescaler = <0>;
ppi-base = <14>; ppi-base = <14>;

View file

@ -375,7 +375,7 @@
}; };
&sw_pwm { &sw_pwm {
timer-instance = <2>; generator = <&timer2>;
channel-count = <3>; channel-count = <3>;
clock-prescaler = <0>; clock-prescaler = <0>;
ppi-base = <14>; ppi-base = <14>;

View file

@ -396,7 +396,7 @@
}; };
&sw_pwm { &sw_pwm {
timer-instance = <2>; generator = <&timer2>;
channel-count = <3>; channel-count = <3>;
clock-prescaler = <0>; clock-prescaler = <0>;
ppi-base = <14>; ppi-base = <14>;

View file

@ -5,10 +5,18 @@ compatible: "nordic,nrf-sw-pwm"
include: [pwm-controller.yaml, base.yaml] include: [pwm-controller.yaml, base.yaml]
properties: properties:
generator:
type: phandle
description: Reference to TIMER instance for generating PWM output signals
required: false
timer-instance: timer-instance:
type: int type: int
description: Timer instance to use for generating the PWM output signals description: |
required: true Timer instance to use for generating the PWM output signals. Deprecated
in favour of 'generator' property.
required: false
deprecated: true
channel-count: channel-count:
type: int type: int