drivers: counter: nrf: use new DT API

These drivers use legacy DT APIs to access data by node label. Update
them to use the new API.

Leave the existing Kconfig options in place. This helps with
bisectability in case of regressions and lets us proceed
incrementally. Removing the per-instance Kconfigs is also nontrivial
in these cases because of hard-coded dependencies in other subsystems.

Signed-off-by: Martí Bolívar <marti.bolivar@nordicsemi.no>
This commit is contained in:
Martí Bolívar 2020-04-10 15:00:32 -07:00 committed by Carles Cufí
commit 3a8aabd774
2 changed files with 41 additions and 26 deletions

View file

@ -654,18 +654,25 @@ static const struct counter_driver_api counter_nrfx_driver_api = {
.set_guard_period = set_guard_period, .set_guard_period = set_guard_period,
}; };
#define COUNTER_NRF_RTC_DEVICE(idx) \ /*
BUILD_ASSERT((DT_NORDIC_NRF_RTC_RTC_##idx##_PRESCALER - 1) <= \ * Devicetree access is done with node labels due to HAL API
RTC_PRESCALER_PRESCALER_Msk, \ * requirements. In particular, RTCx_CC_NUM values from HALs
"RTC prescaler out of range"); \ * are indexed by peripheral number, so DT_INST APIs won't work.
*/
#define RTC(idx) DT_NODELABEL(rtc##idx)
#define RTC_PROP(idx, prop) DT_PROP(RTC(idx), prop)
#define COUNTER_NRF_RTC_DEVICE(idx) \
BUILD_ASSERT((RTC_PROP(idx, prescaler) - 1) <= \
RTC_PRESCALER_PRESCALER_Msk, \
"RTC prescaler out of range"); \
DEVICE_DECLARE(rtc_##idx); \ DEVICE_DECLARE(rtc_##idx); \
static int counter_##idx##_init(struct device *dev) \ static int counter_##idx##_init(struct device *dev) \
{ \ { \
IRQ_CONNECT(DT_NORDIC_NRF_RTC_RTC_##idx##_IRQ_0, \ IRQ_CONNECT(DT_IRQN(RTC(idx)), DT_IRQ(RTC(idx), priority), \
DT_NORDIC_NRF_RTC_RTC_##idx##_IRQ_0_PRIORITY, \
irq_handler, DEVICE_GET(rtc_##idx), 0); \ irq_handler, DEVICE_GET(rtc_##idx), 0); \
return init_rtc(dev, \ return init_rtc(dev, RTC_PROP(idx, prescaler) - 1); \
DT_NORDIC_NRF_RTC_RTC_##idx##_PRESCALER - 1); \
} \ } \
static struct counter_nrfx_data counter_##idx##_data; \ static struct counter_nrfx_data counter_##idx##_data; \
static struct counter_nrfx_ch_data \ static struct counter_nrfx_ch_data \
@ -674,22 +681,22 @@ static const struct counter_driver_api counter_nrfx_driver_api = {
static const struct counter_nrfx_config nrfx_counter_##idx##_config = {\ static const struct counter_nrfx_config nrfx_counter_##idx##_config = {\
.info = { \ .info = { \
.max_top_value = COUNTER_MAX_TOP_VALUE, \ .max_top_value = COUNTER_MAX_TOP_VALUE, \
.freq = DT_NORDIC_NRF_RTC_RTC_##idx##_CLOCK_FREQUENCY /\ .freq = RTC_PROP(idx, clock_frequency) / \
(DT_NORDIC_NRF_RTC_RTC_##idx##_PRESCALER), \ RTC_PROP(idx, prescaler), \
.flags = COUNTER_CONFIG_INFO_COUNT_UP, \ .flags = COUNTER_CONFIG_INFO_COUNT_UP, \
.channels = DT_NORDIC_NRF_RTC_RTC_##idx##_FIXED_TOP ? \ .channels = RTC_PROP(idx, fixed_top) ? \
RTC##idx##_CC_NUM : RTC##idx##_CC_NUM - 1 \ RTC##idx##_CC_NUM : RTC##idx##_CC_NUM - 1 \
}, \ }, \
.ch_data = counter##idx##_ch_data, \ .ch_data = counter##idx##_ch_data, \
.rtc = NRF_RTC##idx, \ .rtc = (NRF_RTC_Type *)DT_REG_ADDR(RTC(idx)), \
IF_ENABLED(DT_NORDIC_NRF_RTC_RTC_##idx##_PPI_WRAP, \ IF_ENABLED(CONFIG_COUNTER_RTC_WITH_PPI_WRAP, \
(.use_ppi = true,)) \ (.use_ppi = RTC_PROP(idx, ppi_wrap),)) \
IF_ENABLED(CONFIG_COUNTER_RTC_CUSTOM_TOP_SUPPORT, \ IF_ENABLED(CONFIG_COUNTER_RTC_CUSTOM_TOP_SUPPORT, \
(.fixed_top = DT_NORDIC_NRF_RTC_RTC_##idx##_FIXED_TOP,)) \ (.fixed_top = RTC_PROP(idx, fixed_top),)) \
LOG_INSTANCE_PTR_INIT(log, LOG_MODULE_NAME, idx) \ LOG_INSTANCE_PTR_INIT(log, LOG_MODULE_NAME, idx) \
}; \ }; \
DEVICE_AND_API_INIT(rtc_##idx, \ DEVICE_AND_API_INIT(rtc_##idx, \
DT_NORDIC_NRF_RTC_RTC_##idx##_LABEL, \ DT_LABEL(RTC(idx)), \
counter_##idx##_init, \ counter_##idx##_init, \
&counter_##idx##_data, \ &counter_##idx##_data, \
&nrfx_counter_##idx##_config.info, \ &nrfx_counter_##idx##_config.info, \

View file

@ -382,18 +382,26 @@ static const struct counter_driver_api counter_nrfx_driver_api = {
.set_guard_period = set_guard_period, .set_guard_period = set_guard_period,
}; };
#define COUNTER_NRFX_TIMER_DEVICE(idx) \ /*
BUILD_ASSERT(DT_NORDIC_NRF_TIMER_TIMER_##idx##_PRESCALER <= \ * Device instantiation is done with node labels due to HAL API
TIMER_PRESCALER_PRESCALER_Msk, \ * requirements. In particular, TIMERx_MAX_SIZE values from HALs
"TIMER prescaler out of range"); \ * are indexed by peripheral number, so DT_INST APIs won't work.
*/
#define TIMER(idx) DT_NODELABEL(timer##idx)
#define TIMER_PROP(idx, prop) DT_PROP(TIMER(idx), prop)
#define COUNTER_NRFX_TIMER_DEVICE(idx) \
BUILD_ASSERT(TIMER_PROP(idx, prescaler) <= \
TIMER_PRESCALER_PRESCALER_Msk, \
"TIMER prescaler out of range"); \
DEVICE_DECLARE(timer_##idx); \ DEVICE_DECLARE(timer_##idx); \
static int counter_##idx##_init(struct device *dev) \ static int counter_##idx##_init(struct device *dev) \
{ \ { \
IRQ_CONNECT(DT_NORDIC_NRF_TIMER_TIMER_##idx##_IRQ_0, \ IRQ_CONNECT(DT_IRQN(TIMER(idx)), DT_IRQ(TIMER(idx), priority), \
DT_NORDIC_NRF_TIMER_TIMER_##idx##_IRQ_0_PRIORITY, \
irq_handler, DEVICE_GET(timer_##idx), 0); \ irq_handler, DEVICE_GET(timer_##idx), 0); \
static const struct counter_timer_config config = { \ static const struct counter_timer_config config = { \
.freq = DT_NORDIC_NRF_TIMER_TIMER_##idx##_PRESCALER, \ .freq = TIMER_PROP(idx, prescaler), \
.mode = NRF_TIMER_MODE_TIMER, \ .mode = NRF_TIMER_MODE_TIMER, \
.bit_width = (TIMER##idx##_MAX_SIZE == 32) ? \ .bit_width = (TIMER##idx##_MAX_SIZE == 32) ? \
NRF_TIMER_BIT_WIDTH_32 : \ NRF_TIMER_BIT_WIDTH_32 : \
@ -410,16 +418,16 @@ static const struct counter_driver_api counter_nrfx_driver_api = {
.max_top_value = (TIMER##idx##_MAX_SIZE == 32) ? \ .max_top_value = (TIMER##idx##_MAX_SIZE == 32) ? \
0xffffffff : 0x0000ffff, \ 0xffffffff : 0x0000ffff, \
.freq = TIMER_CLOCK / \ .freq = TIMER_CLOCK / \
(1 << DT_NORDIC_NRF_TIMER_TIMER_##idx##_PRESCALER), \ (1 << TIMER_PROP(idx, prescaler)), \
.flags = COUNTER_CONFIG_INFO_COUNT_UP, \ .flags = COUNTER_CONFIG_INFO_COUNT_UP, \
.channels = CC_TO_ID(TIMER##idx##_CC_NUM), \ .channels = CC_TO_ID(TIMER##idx##_CC_NUM), \
}, \ }, \
.ch_data = counter##idx##_ch_data, \ .ch_data = counter##idx##_ch_data, \
.timer = NRF_TIMER##idx, \ .timer = (NRF_TIMER_Type *)DT_REG_ADDR(TIMER(idx)), \
LOG_INSTANCE_PTR_INIT(log, LOG_MODULE_NAME, idx) \ LOG_INSTANCE_PTR_INIT(log, LOG_MODULE_NAME, idx) \
}; \ }; \
DEVICE_AND_API_INIT(timer_##idx, \ DEVICE_AND_API_INIT(timer_##idx, \
DT_NORDIC_NRF_TIMER_TIMER_##idx##_LABEL, \ DT_LABEL(TIMER(idx)), \
counter_##idx##_init, \ counter_##idx##_init, \
&counter_##idx##_data, \ &counter_##idx##_data, \
&nrfx_counter_##idx##_config.info, \ &nrfx_counter_##idx##_config.info, \