diff --git a/drivers/i2c/i2c_mcux_lpi2c_rtio.c b/drivers/i2c/i2c_mcux_lpi2c_rtio.c index f267b7ada4ce1..a4ac9a2f20c38 100644 --- a/drivers/i2c/i2c_mcux_lpi2c_rtio.c +++ b/drivers/i2c/i2c_mcux_lpi2c_rtio.c @@ -16,6 +16,9 @@ #include #include #include +#if CONFIG_NXP_LP_FLEXCOMM +#include +#endif #include @@ -280,7 +283,11 @@ static void mcux_lpi2c_isr(const struct device *dev) struct mcux_lpi2c_data *data = dev->data; LPI2C_Type *base = (LPI2C_Type *)DEVICE_MMIO_NAMED_GET(dev, reg_base); +#if CONFIG_HAS_MCUX_FLEXCOMM + LPI2C_MasterTransferHandleIRQ(LPI2C_GetInstance(base), &data->handle); +#else LPI2C_MasterTransferHandleIRQ(base, &data->handle); +#endif } static int mcux_lpi2c_init(const struct device *dev) @@ -346,10 +353,41 @@ static DEVICE_API(i2c, mcux_lpi2c_driver_api) = { #define I2C_MCUX_LPI2C_SDA_INIT(n) #endif /* CONFIG_I2C_MCUX_LPI2C_BUS_RECOVERY */ +#define I2C_MCUX_LPI2C_MODULE_IRQ_CONNECT(n) \ + do { \ + IRQ_CONNECT(DT_INST_IRQN(n), \ + DT_INST_IRQ(n, priority), \ + mcux_lpi2c_isr, \ + DEVICE_DT_INST_GET(n), 0); \ + irq_enable(DT_INST_IRQN(n)); \ + } while (false) + +#define I2C_MCUX_LPI2C_MODULE_IRQ(n) \ + IF_ENABLED(DT_INST_IRQ_HAS_IDX(n, 0), \ + (I2C_MCUX_LPI2C_MODULE_IRQ_CONNECT(n))) + +/* When using LP Flexcomm driver, register the interrupt handler + * so we receive notification from the LP Flexcomm interrupt handler. + */ +#define I2C_MCUX_LPI2C_LPFLEXCOMM_IRQ_FUNC(n) \ + nxp_lp_flexcomm_setirqhandler(DEVICE_DT_GET(DT_INST_PARENT(n)), \ + DEVICE_DT_INST_GET(n), \ + LP_FLEXCOMM_PERIPH_LPI2C, \ + mcux_lpi2c_isr) + +#define I2C_MCUX_LPI2C_IRQ_SETUP_FUNC(n) \ + COND_CODE_1(DT_NODE_HAS_COMPAT(DT_INST_PARENT(n), \ + nxp_lp_flexcomm), \ + (I2C_MCUX_LPI2C_LPFLEXCOMM_IRQ_FUNC(n)), \ + (I2C_MCUX_LPI2C_MODULE_IRQ(n))) + #define I2C_MCUX_LPI2C_INIT(n) \ PINCTRL_DT_INST_DEFINE(n); \ \ - static void mcux_lpi2c_config_func_##n(const struct device *dev); \ + static void mcux_lpi2c_config_func_##n(const struct device *dev)\ + { \ + I2C_MCUX_LPI2C_IRQ_SETUP_FUNC(n); \ + } \ \ static const struct mcux_lpi2c_config mcux_lpi2c_config_##n = { \ DEVICE_MMIO_NAMED_ROM_INIT(reg_base, DT_DRV_INST(n)), \ @@ -378,16 +416,6 @@ static DEVICE_API(i2c, mcux_lpi2c_driver_api) = { &mcux_lpi2c_data_##n, \ &mcux_lpi2c_config_##n, POST_KERNEL, \ CONFIG_I2C_INIT_PRIORITY, \ - &mcux_lpi2c_driver_api); \ - \ - static void mcux_lpi2c_config_func_##n(const struct device *dev)\ - { \ - IRQ_CONNECT(DT_INST_IRQN(n), \ - DT_INST_IRQ(n, priority), \ - mcux_lpi2c_isr, \ - DEVICE_DT_INST_GET(n), 0); \ - \ - irq_enable(DT_INST_IRQN(n)); \ - } + &mcux_lpi2c_driver_api); DT_INST_FOREACH_STATUS_OKAY(I2C_MCUX_LPI2C_INIT)