Skip to content

Commit 7bbbb56

Browse files
committed
spi_nxp_lpspi: Convert CPU version to native code
Convert the CPU-based lpspi driver to native code. Signed-off-by: Declan Snyder <declan.snyder@nxp.com>
1 parent b0732f5 commit 7bbbb56

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi.c

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static inline void lpspi_rx_word_write_bytes(const struct device *dev, size_t of
3636
struct spi_context *ctx = &data->ctx;
3737
uint8_t num_bytes = MIN(lpspi_data->word_size_bytes, ctx->rx_len);
3838
uint8_t *buf = ctx->rx_buf + offset;
39-
uint32_t word = LPSPI_ReadData(base);
39+
uint32_t word = base->RDR;
4040

4141
if (!spi_context_rx_buf_on(ctx) && spi_context_rx_on(ctx)) {
4242
/* receive no actual data if rx buf is NULL */
@@ -78,7 +78,7 @@ static inline void lpspi_handle_rx_irq(const struct device *dev)
7878
uint8_t total_words_read = 0;
7979
uint8_t words_read;
8080

81-
LPSPI_ClearStatusFlags(base, kLPSPI_RxDataReadyFlag);
81+
base->SR = LPSPI_SR_RDF_MASK;
8282

8383
LOG_DBG("RX FIFO: %d, RX BUF: %p", rx_fsr, ctx->rx_buf);
8484

@@ -92,8 +92,8 @@ static inline void lpspi_handle_rx_irq(const struct device *dev)
9292
LOG_DBG("RX done %d words to spi buf", total_words_written);
9393

9494
if (spi_context_rx_len_left(ctx) == 0) {
95-
LPSPI_DisableInterrupts(base, (uint32_t)kLPSPI_RxInterruptEnable);
96-
LPSPI_FlushFifo(base, false, true);
95+
base->IER &= ~LPSPI_IER_RDIE_MASK;
96+
base->CR |= LPSPI_CR_RRF_MASK; /* flush rx fifo */
9797
}
9898
}
9999

@@ -122,7 +122,7 @@ static inline void lpspi_fill_tx_fifo(const struct device *dev)
122122
size_t offset;
123123

124124
for (offset = 0; offset < bytes_in_xfer; offset += lpspi_data->word_size_bytes) {
125-
LPSPI_WriteData(base, lpspi_next_tx_word(dev, offset));
125+
base->TDR = lpspi_next_tx_word(dev, offset);
126126
}
127127

128128
LOG_DBG("Filled TX FIFO to %d words (%d bytes)", lpspi_data->fill_len, offset);
@@ -135,7 +135,7 @@ static void lpspi_fill_tx_fifo_nop(const struct device *dev)
135135
struct lpspi_driver_data *lpspi_data = (struct lpspi_driver_data *)data->driver_data;
136136

137137
for (int i = 0; i < lpspi_data->fill_len; i++) {
138-
LPSPI_WriteData(base, 0);
138+
base->TDR = 0;
139139
}
140140

141141
LOG_DBG("Filled TX fifo with %d NOPs", lpspi_data->fill_len);
@@ -170,10 +170,10 @@ static inline void lpspi_handle_tx_irq(const struct device *dev)
170170

171171
spi_context_update_tx(ctx, lpspi_data->word_size_bytes, lpspi_data->fill_len);
172172

173-
LPSPI_ClearStatusFlags(base, kLPSPI_TxDataRequestFlag);
173+
base->SR = LPSPI_SR_TDF_MASK;
174174

175175
if (!spi_context_tx_on(ctx)) {
176-
LPSPI_DisableInterrupts(base, (uint32_t)kLPSPI_TxInterruptEnable);
176+
base->IER &= ~LPSPI_IER_TDIE_MASK;
177177
return;
178178
}
179179

@@ -184,16 +184,16 @@ static void lpspi_isr(const struct device *dev)
184184
{
185185
LPSPI_Type *base = (LPSPI_Type *)DEVICE_MMIO_NAMED_GET(dev, reg_base);
186186
const struct spi_mcux_config *config = dev->config;
187-
uint32_t status_flags = LPSPI_GetStatusFlags(base);
188187
struct spi_mcux_data *data = dev->data;
189188
struct lpspi_driver_data *lpspi_data = (struct lpspi_driver_data *)data->driver_data;
190189
struct spi_context *ctx = &data->ctx;
190+
uint32_t status_flags = base->SR;
191191

192-
if (status_flags & kLPSPI_RxDataReadyFlag) {
192+
if (status_flags & LPSPI_SR_RDF_MASK) {
193193
lpspi_handle_rx_irq(dev);
194194
}
195195

196-
if (status_flags & kLPSPI_TxDataRequestFlag) {
196+
if (status_flags & LPSPI_SR_TDF_MASK) {
197197
lpspi_handle_tx_irq(dev);
198198
}
199199

@@ -248,15 +248,15 @@ static int transceive(const struct device *dev, const struct spi_config *spi_cfg
248248
return ret;
249249
}
250250

251-
LPSPI_FlushFifo(base, true, true);
252-
LPSPI_ClearStatusFlags(base, (uint32_t)kLPSPI_AllStatusFlag);
253-
LPSPI_DisableInterrupts(base, (uint32_t)kLPSPI_AllInterruptEnable);
251+
base->CR |= LPSPI_CR_RTF_MASK | LPSPI_CR_RRF_MASK; /* flush fifos */
252+
base->IER = 0; /* disable all interrupts */
253+
base->FCR = 0; /* set watermarks to 0 */
254+
base->SR |= LPSPI_INTERRUPT_BITS;
254255

255256
LOG_DBG("Starting LPSPI transfer");
256257
spi_context_cs_control(&data->ctx, true);
257258

258-
LPSPI_SetFifoWatermarks(base, 0, 0);
259-
LPSPI_Enable(base, true);
259+
base->CR |= LPSPI_CR_MEN_MASK;
260260

261261
/* keep the chip select asserted until the end of the zephyr xfer */
262262
base->TCR |= LPSPI_TCR_CONT_MASK;
@@ -266,8 +266,7 @@ static int transceive(const struct device *dev, const struct spi_config *spi_cfg
266266
/* start the transfer sequence which are handled by irqs */
267267
lpspi_next_tx_fill(dev);
268268

269-
LPSPI_EnableInterrupts(base, (uint32_t)kLPSPI_TxInterruptEnable |
270-
(uint32_t)kLPSPI_RxInterruptEnable);
269+
base->IER |= LPSPI_IER_TDIE_MASK | LPSPI_IER_RDIE_MASK;
271270

272271
return spi_context_wait_for_completion(&data->ctx);
273272
}

drivers/spi/spi_nxp_lpspi/spi_nxp_lpspi_priv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
#define LPSPI_CHIP_SELECT_COUNT 4
2525
#define LPSPI_MIN_FRAME_SIZE_BITS 8
2626

27+
#define LPSPI_INTERRUPT_BITS GENMASK(8, 13)
28+
2729
/* Required by DEVICE_MMIO_NAMED_* macros */
2830
#define DEV_CFG(_dev) ((const struct spi_mcux_config *)(_dev)->config)
2931
#define DEV_DATA(_dev) ((struct spi_mcux_data *)(_dev)->data)

0 commit comments

Comments
 (0)