From 42511c80bacee5f072fc64b0c9d6dc068005e31b Mon Sep 17 00:00:00 2001 From: Declan Snyder Date: Wed, 4 Dec 2024 14:55:30 -0600 Subject: [PATCH] spi_mcux_lpspi: Move RTIO code to rtio functions To facilitate changing this driver, decouple rtio from functions not specific to RTIO. This also requires moving the sdk driver handle creation outside of the configure call. An effect of this is we can stop initializing an unused sdk driver handle for the dma path. Signed-off-by: Declan Snyder --- drivers/spi/spi_mcux_lpspi.c | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/drivers/spi/spi_mcux_lpspi.c b/drivers/spi/spi_mcux_lpspi.c index a763e921b47..6ac17c16f7c 100644 --- a/drivers/spi/spi_mcux_lpspi.c +++ b/drivers/spi/spi_mcux_lpspi.c @@ -91,9 +91,6 @@ struct spi_mcux_data { }; static int spi_mcux_transfer_next_packet(const struct device *dev); -#ifdef CONFIG_SPI_RTIO -static void spi_mcux_iodev_complete(const struct device *dev, int status); -#endif static void spi_mcux_isr(const struct device *dev) { @@ -108,14 +105,6 @@ static void spi_mcux_master_callback(LPSPI_Type *base, lpspi_master_handle_t *ha { struct spi_mcux_data *data = userData; -#ifdef CONFIG_SPI_RTIO - struct spi_rtio *rtio_ctx = data->rtio_ctx; - - if (rtio_ctx->txn_head != NULL) { - spi_mcux_iodev_complete(data->dev, status); - return; - } -#endif spi_context_update_tx(&data->ctx, 1, data->transfer_len); spi_context_update_rx(&data->ctx, 1, data->transfer_len); @@ -226,7 +215,6 @@ static int spi_mcux_configure(const struct device *dev, const struct spi_config master_config.pinCfg = config->data_pin_config; LPSPI_MasterInit(base, &master_config, clock_freq); - LPSPI_MasterTransferCreateHandle(base, &data->handle, spi_mcux_master_callback, data); LPSPI_SetDummyData(base, 0); if (IS_ENABLED(CONFIG_DEBUG)) { @@ -537,6 +525,22 @@ out: #endif /* CONFIG_SPI_MCUX_LPSPI_DMA */ #ifdef CONFIG_SPI_RTIO +static void spi_mcux_iodev_complete(const struct device *dev, int status); + +static void spi_mcux_master_rtio_callback(LPSPI_Type *base, lpspi_master_handle_t *handle, + status_t status, void *userData) +{ + struct spi_mcux_data *data = userData; + struct spi_rtio *rtio_ctx = data->rtio_ctx; + + if (rtio_ctx->txn_head != NULL) { + spi_mcux_iodev_complete(data->dev, status); + return; + } + + spi_mcux_master_callback(base, handle, status, userData); +} + static void spi_mcux_iodev_start(const struct device *dev) { struct spi_mcux_data *data = dev->data; @@ -554,6 +558,8 @@ static void spi_mcux_iodev_start(const struct device *dev) return; } + LPSPI_MasterTransferCreateHandle(base, &data->handle, spi_mcux_master_rtio_callback, data); + transfer.configFlags = LPSPI_MASTER_XFER_CFG_FLAGS(spi_cfg->slave); switch (sqe->op) { @@ -647,6 +653,7 @@ static int transceive(const struct device *dev, const struct spi_config *spi_cfg const struct spi_buf_set *tx_bufs, const struct spi_buf_set *rx_bufs, bool asynchronous, spi_callback_t cb, void *userdata) { + LPSPI_Type *base = (LPSPI_Type *)DEVICE_MMIO_NAMED_GET(dev, reg_base); struct spi_mcux_data *data = dev->data; int ret; @@ -657,6 +664,8 @@ static int transceive(const struct device *dev, const struct spi_config *spi_cfg goto out; } + LPSPI_MasterTransferCreateHandle(base, &data->handle, spi_mcux_master_callback, data); + spi_context_buffers_setup(&data->ctx, tx_bufs, rx_bufs, 1); spi_context_cs_control(&data->ctx, true);