Skip to content

Commit e8ebbad

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 116e043 commit e8ebbad

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
@@ -35,7 +35,7 @@ static inline void lpspi_rx_word_write_bytes(const struct device *dev, size_t of
3535
struct spi_context *ctx = &data->ctx;
3636
uint8_t num_bytes = MIN(lpspi_data->word_size_bytes, ctx->rx_len);
3737
uint8_t *buf = ctx->rx_buf + offset;
38-
uint32_t word = LPSPI_ReadData(base);
38+
uint32_t word = base->RDR;
3939

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

80-
LPSPI_ClearStatusFlags(base, kLPSPI_RxDataReadyFlag);
80+
base->SR = LPSPI_SR_RDF_MASK;
8181

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

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

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

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

123123
for (offset = 0; offset < bytes_in_xfer; offset += lpspi_data->word_size_bytes) {
124-
LPSPI_WriteData(base, lpspi_next_tx_word(dev, offset));
124+
base->TDR = lpspi_next_tx_word(dev, offset);
125125
}
126126

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

136136
for (int i = 0; i < lpspi_data->fill_len; i++) {
137-
LPSPI_WriteData(base, 0);
137+
base->TDR = 0;
138138
}
139139

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

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

172-
LPSPI_ClearStatusFlags(base, kLPSPI_TxDataRequestFlag);
172+
base->SR = LPSPI_SR_TDF_MASK;
173173

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

@@ -183,16 +183,16 @@ static void lpspi_isr(const struct device *dev)
183183
{
184184
LPSPI_Type *base = (LPSPI_Type *)DEVICE_MMIO_NAMED_GET(dev, reg_base);
185185
const struct spi_mcux_config *config = dev->config;
186-
uint32_t status_flags = LPSPI_GetStatusFlags(base);
187186
struct spi_mcux_data *data = dev->data;
188187
struct lpspi_driver_data *lpspi_data = (struct lpspi_driver_data *)data->driver_data;
189188
struct spi_context *ctx = &data->ctx;
189+
uint32_t status_flags = base->SR;
190190

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

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

@@ -250,15 +250,15 @@ static int transceive(const struct device *dev, const struct spi_config *spi_cfg
250250
goto error;
251251
}
252252

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

257258
LOG_DBG("Starting LPSPI transfer");
258259
spi_context_cs_control(ctx, true);
259260

260-
LPSPI_SetFifoWatermarks(base, 0, 0);
261-
LPSPI_Enable(base, true);
261+
base->CR |= LPSPI_CR_MEN_MASK;
262262

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

271-
LPSPI_EnableInterrupts(base, (uint32_t)kLPSPI_TxInterruptEnable |
272-
(uint32_t)kLPSPI_RxInterruptEnable);
271+
base->IER |= LPSPI_IER_TDIE_MASK | LPSPI_IER_RDIE_MASK;
273272

274273
ret = spi_context_wait_for_completion(ctx);
275274
if (ret >= 0) {

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)