Skip to content

Commit 595e16c

Browse files
decsnynashif
authored andcommitted
drivers: spi_mcux_lpspi: Consolidate IRQ handle
Small change to consolidate the amount of lines of code in the spi_mcux_isr by making a macro for the argument and removing a line of code that was commented out. Also move the ISR to be the first function in the file which is common in many other drivers, instead of randomly in the middle of the file. And move the isr callback to be next to the isr. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
1 parent e21bf37 commit 595e16c

File tree

1 file changed

+32
-34
lines changed

1 file changed

+32
-34
lines changed

drivers/spi/spi_mcux_lpspi.c

Lines changed: 32 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ LOG_MODULE_REGISTER(spi_mcux_lpspi, CONFIG_SPI_LOG_LEVEL);
3636
#define DEV_CFG(_dev) ((const struct spi_mcux_config *)(_dev)->config)
3737
#define DEV_DATA(_dev) ((struct spi_mcux_data *)(_dev)->data)
3838

39+
/* Argument to MCUX SDK IRQ handler */
40+
#define LPSPI_IRQ_HANDLE_ARG COND_CODE_1(CONFIG_NXP_LP_FLEXCOMM, (LPSPI_GetInstance(base)), (base))
41+
3942
#ifdef CONFIG_SPI_MCUX_LPSPI_DMA
4043
#include <zephyr/drivers/dma.h>
4144

@@ -85,13 +88,41 @@ struct spi_mcux_data {
8588
#endif
8689
};
8790

91+
static int spi_mcux_transfer_next_packet(const struct device *dev);
8892
#ifdef CONFIG_SPI_RTIO
8993
static void spi_mcux_iodev_complete(const struct device *dev, int status);
9094
static inline int transceive_rtio(const struct device *dev, const struct spi_config *spi_cfg,
9195
const struct spi_buf_set *tx_bufs,
9296
const struct spi_buf_set *rx_bufs);
9397
#endif
9498

99+
static void spi_mcux_isr(const struct device *dev)
100+
{
101+
struct spi_mcux_data *data = dev->data;
102+
LPSPI_Type *base = (LPSPI_Type *)DEVICE_MMIO_NAMED_GET(dev, reg_base);
103+
104+
LPSPI_MasterTransferHandleIRQ(LPSPI_IRQ_HANDLE_ARG, &data->handle);
105+
}
106+
107+
static void spi_mcux_master_callback(LPSPI_Type *base, lpspi_master_handle_t *handle,
108+
status_t status, void *userData)
109+
{
110+
struct spi_mcux_data *data = userData;
111+
112+
#ifdef CONFIG_SPI_RTIO
113+
struct spi_rtio *rtio_ctx = data->rtio_ctx;
114+
115+
if (rtio_ctx->txn_head != NULL) {
116+
spi_mcux_iodev_complete(data->dev, status);
117+
return;
118+
}
119+
#endif
120+
spi_context_update_tx(&data->ctx, 1, data->transfer_len);
121+
spi_context_update_rx(&data->ctx, 1, data->transfer_len);
122+
123+
spi_mcux_transfer_next_packet(data->dev);
124+
}
125+
95126
static int spi_mcux_transfer_next_packet(const struct device *dev)
96127
{
97128
/* const struct spi_mcux_config *config = dev->config; */
@@ -155,38 +186,6 @@ static int spi_mcux_transfer_next_packet(const struct device *dev)
155186
return 0;
156187
}
157188

158-
static void spi_mcux_isr(const struct device *dev)
159-
{
160-
/* const struct spi_mcux_config *config = dev->config; */
161-
struct spi_mcux_data *data = dev->data;
162-
LPSPI_Type *base = (LPSPI_Type *)DEVICE_MMIO_NAMED_GET(dev, reg_base);
163-
164-
#if CONFIG_NXP_LP_FLEXCOMM
165-
LPSPI_MasterTransferHandleIRQ(LPSPI_GetInstance(base), &data->handle);
166-
#else
167-
LPSPI_MasterTransferHandleIRQ(base, &data->handle);
168-
#endif
169-
}
170-
171-
static void spi_mcux_master_transfer_callback(LPSPI_Type *base, lpspi_master_handle_t *handle,
172-
status_t status, void *userData)
173-
{
174-
struct spi_mcux_data *data = userData;
175-
176-
#ifdef CONFIG_SPI_RTIO
177-
struct spi_rtio *rtio_ctx = data->rtio_ctx;
178-
179-
if (rtio_ctx->txn_head != NULL) {
180-
spi_mcux_iodev_complete(data->dev, status);
181-
return;
182-
}
183-
#endif
184-
spi_context_update_tx(&data->ctx, 1, data->transfer_len);
185-
spi_context_update_rx(&data->ctx, 1, data->transfer_len);
186-
187-
spi_mcux_transfer_next_packet(data->dev);
188-
}
189-
190189
static int spi_mcux_configure(const struct device *dev, const struct spi_config *spi_cfg)
191190
{
192191
const struct spi_mcux_config *config = dev->config;
@@ -264,8 +263,7 @@ static int spi_mcux_configure(const struct device *dev, const struct spi_config
264263
base->CR |= LPSPI_CR_DBGEN_MASK;
265264
}
266265

267-
LPSPI_MasterTransferCreateHandle(base, &data->handle, spi_mcux_master_transfer_callback,
268-
data);
266+
LPSPI_MasterTransferCreateHandle(base, &data->handle, spi_mcux_master_callback, data);
269267

270268
LPSPI_SetDummyData(base, 0);
271269

0 commit comments

Comments
 (0)