diff --git a/drivers/pwm/pwm_nrfx.c b/drivers/pwm/pwm_nrfx.c index 373f8eef7e2..52257dce104 100644 --- a/drivers/pwm/pwm_nrfx.c +++ b/drivers/pwm/pwm_nrfx.c @@ -15,6 +15,22 @@ LOG_MODULE_REGISTER(pwm_nrfx, CONFIG_PWM_LOG_LEVEL); +/* NRFX_PWM_NRF52_ANOMALY_109_WORKAROUND_ENABLED can be undefined or defined + * to 0 or 1, hence the use of #if IS_ENABLED(). + */ +#if IS_ENABLED(NRFX_PWM_NRF52_ANOMALY_109_WORKAROUND_ENABLED) +#define ANOMALY_109_IRQ_CONNECT(...) IRQ_CONNECT(__VA_ARGS__) +#define ANOMALY_109_EGU_IRQ_CONNECT(idx) _EGU_IRQ_CONNECT(idx) +#define _EGU_IRQ_CONNECT(idx) \ + extern void nrfx_egu_##idx##_irq_handler(void); \ + IRQ_CONNECT(DT_IRQN(DT_NODELABEL(egu##idx)), \ + DT_IRQ(DT_NODELABEL(egu##idx), priority), \ + nrfx_isr, nrfx_egu_##idx##_irq_handler, 0) +#else +#define ANOMALY_109_IRQ_CONNECT(...) +#define ANOMALY_109_EGU_IRQ_CONNECT(idx) +#endif + #define PWM_NRFX_CH_POLARITY_MASK BIT(15) #define PWM_NRFX_CH_COMPARE_MASK BIT_MASK(15) #define PWM_NRFX_CH_VALUE(compare_value, inverted) \ @@ -238,6 +254,8 @@ static int pwm_nrfx_init(const struct device *dev) int ret = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); + ANOMALY_109_EGU_IRQ_CONNECT(NRFX_PWM_NRF52_ANOMALY_109_EGU_INSTANCE); + if (ret < 0) { return ret; } @@ -343,9 +361,16 @@ static int pwm_nrfx_pm_action(const struct device *dev, .seq.length = NRF_PWM_CHANNEL_COUNT, \ .pcfg = PINCTRL_DT_DEV_CONFIG_GET(PWM(idx)), \ }; \ + static int pwm_nrfx_init##idx(const struct device *dev) \ + { \ + ANOMALY_109_IRQ_CONNECT( \ + DT_IRQN(PWM(idx)), DT_IRQ(PWM(idx), priority), \ + nrfx_isr, nrfx_pwm_##idx##_irq_handler, 0); \ + return pwm_nrfx_init(dev); \ + }; \ PM_DEVICE_DT_DEFINE(PWM(idx), pwm_nrfx_pm_action); \ DEVICE_DT_DEFINE(PWM(idx), \ - pwm_nrfx_init, PM_DEVICE_DT_GET(PWM(idx)), \ + pwm_nrfx_init##idx, PM_DEVICE_DT_GET(PWM(idx)), \ &pwm_nrfx_##idx##_data, \ &pwm_nrfx_##idx##_config, \ POST_KERNEL, CONFIG_PWM_INIT_PRIORITY, \