Skip to content

Commit

Permalink
spi_mcux_lpspi: Move RTIO code to rtio functions
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
decsny authored and kartben committed Dec 14, 2024
1 parent 377e6bd commit 42511c8
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions drivers/spi/spi_mcux_lpspi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);

Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -537,6 +525,22 @@ static int transceive_dma(const struct device *dev, const struct spi_config *spi
#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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand Down

0 comments on commit 42511c8

Please sign in to comment.