Skip to content

Commit d7ebf67

Browse files
ubiedakartben
authored andcommitted
drivers: i2c_rtio: MCUX LPflexcomm determine by inst
Determine if lpflexcomm wrapped lpi2c by instance and connect irq differently dependending on that to support platforms with both flexcomm wrapped and unwrapped lpi2c's. Applying c1286a8d8d425805fcceb3b872325fb4c439a572 to RTIO version. Authored-by: Declan Snyder <declan.snyder@nxp.com> Signed-off-by: Luis Ubieda <luisf@croxel.com>
1 parent c7a0024 commit d7ebf67

File tree

1 file changed

+19
-25
lines changed

1 file changed

+19
-25
lines changed

drivers/i2c/i2c_mcux_lpi2c_rtio.c

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ LOG_MODULE_REGISTER(mcux_lpi2c);
4343

4444
struct mcux_lpi2c_config {
4545
DEVICE_MMIO_NAMED_ROM(reg_base);
46-
#ifdef CONFIG_NXP_LP_FLEXCOMM
47-
const struct device *parent_dev;
48-
#endif
4946
const struct device *clock_dev;
5047
clock_control_subsys_t clock_subsys;
5148
void (*irq_config_func)(const struct device *dev);
@@ -335,15 +332,7 @@ static int mcux_lpi2c_init(const struct device *dev)
335332
return error;
336333
}
337334

338-
#if CONFIG_NXP_LP_FLEXCOMM
339-
/* When using LP Flexcomm driver, register the interrupt handler
340-
* so we receive notification from the LP Flexcomm interrupt handler.
341-
*/
342-
nxp_lp_flexcomm_setirqhandler(config->parent_dev, dev,
343-
LP_FLEXCOMM_PERIPH_LPI2C, mcux_lpi2c_isr);
344-
#else
345335
config->irq_config_func(dev);
346-
#endif
347336

348337
i2c_rtio_init(data->ctx, dev);
349338

@@ -377,21 +366,31 @@ static DEVICE_API(i2c, mcux_lpi2c_driver_api) = {
377366
IF_ENABLED(DT_INST_IRQ_HAS_IDX(n, 0), \
378367
(I2C_MCUX_LPI2C_MODULE_IRQ_CONNECT(n)))
379368

380-
#ifdef CONFIG_NXP_LP_FLEXCOMM
381-
#define PARENT_DEV(n) \
382-
.parent_dev = DEVICE_DT_GET(DT_INST_PARENT(n)),
383-
#else
384-
#define PARENT_DEV(n)
385-
#endif /* CONFIG_NXP_LP_FLEXCOMM */
369+
/* When using LP Flexcomm driver, register the interrupt handler
370+
* so we receive notification from the LP Flexcomm interrupt handler.
371+
*/
372+
#define I2C_MCUX_LPI2C_LPFLEXCOMM_IRQ_FUNC(n) \
373+
nxp_lp_flexcomm_setirqhandler(DEVICE_DT_GET(DT_INST_PARENT(n)), \
374+
DEVICE_DT_INST_GET(n), \
375+
LP_FLEXCOMM_PERIPH_LPI2C, \
376+
mcux_lpi2c_isr)
377+
378+
#define I2C_MCUX_LPI2C_IRQ_SETUP_FUNC(n) \
379+
COND_CODE_1(DT_NODE_HAS_COMPAT(DT_INST_PARENT(n), \
380+
nxp_lp_flexcomm), \
381+
(I2C_MCUX_LPI2C_LPFLEXCOMM_IRQ_FUNC(n)), \
382+
(I2C_MCUX_LPI2C_MODULE_IRQ(n)))
386383

387384
#define I2C_MCUX_LPI2C_INIT(n) \
388385
PINCTRL_DT_INST_DEFINE(n); \
389386
\
390-
static void mcux_lpi2c_config_func_##n(const struct device *dev); \
387+
static void mcux_lpi2c_config_func_##n(const struct device *dev)\
388+
{ \
389+
I2C_MCUX_LPI2C_IRQ_SETUP_FUNC(n); \
390+
} \
391391
\
392392
static const struct mcux_lpi2c_config mcux_lpi2c_config_##n = { \
393393
DEVICE_MMIO_NAMED_ROM_INIT(reg_base, DT_DRV_INST(n)), \
394-
PARENT_DEV(n) \
395394
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \
396395
.clock_subsys = \
397396
(clock_control_subsys_t)DT_INST_CLOCKS_CELL(n, name),\
@@ -417,11 +416,6 @@ static DEVICE_API(i2c, mcux_lpi2c_driver_api) = {
417416
&mcux_lpi2c_data_##n, \
418417
&mcux_lpi2c_config_##n, POST_KERNEL, \
419418
CONFIG_I2C_INIT_PRIORITY, \
420-
&mcux_lpi2c_driver_api); \
421-
\
422-
static void mcux_lpi2c_config_func_##n(const struct device *dev)\
423-
{ \
424-
I2C_MCUX_LPI2C_MODULE_IRQ(n); \
425-
}
419+
&mcux_lpi2c_driver_api);
426420

427421
DT_INST_FOREACH_STATUS_OKAY(I2C_MCUX_LPI2C_INIT)

0 commit comments

Comments
 (0)