7
7
#define DT_DRV_COMPAT nxp_lpspi
8
8
9
9
#include <zephyr/logging/log.h>
10
- LOG_MODULE_REGISTER (spi_mcux_lpspi , CONFIG_SPI_LOG_LEVEL );
10
+ LOG_MODULE_REGISTER (spi_nxp_lpspi , CONFIG_SPI_LOG_LEVEL );
11
11
12
12
#include "spi_nxp_lpspi_priv.h"
13
13
@@ -18,24 +18,16 @@ struct lpspi_driver_data {
18
18
uint8_t word_size_bytes ;
19
19
};
20
20
21
- static inline void lpspi_wait_tx_fifo_empty (const struct device * dev )
22
- {
23
- LPSPI_Type * base = (LPSPI_Type * )DEVICE_MMIO_NAMED_GET (dev , reg_base );
24
-
25
- while (LPSPI_GetTxFifoCount (base ) != 0 ) {
26
- }
27
- }
28
-
29
21
/* Reads a word from the RX fifo and handles writing it into the RX spi buf */
30
22
static inline void lpspi_rx_word_write_bytes (const struct device * dev , size_t offset )
31
23
{
32
24
LPSPI_Type * base = (LPSPI_Type * )DEVICE_MMIO_NAMED_GET (dev , reg_base );
33
- struct spi_mcux_data * data = dev -> data ;
25
+ struct spi_nxp_data * data = dev -> data ;
34
26
struct lpspi_driver_data * lpspi_data = (struct lpspi_driver_data * )data -> driver_data ;
35
27
struct spi_context * ctx = & data -> ctx ;
36
28
uint8_t num_bytes = MIN (lpspi_data -> word_size_bytes , ctx -> rx_len );
37
29
uint8_t * buf = ctx -> rx_buf + offset ;
38
- uint32_t word = LPSPI_ReadData ( base ) ;
30
+ uint32_t word = base -> RDR ;
39
31
40
32
if (!spi_context_rx_buf_on (ctx ) && spi_context_rx_on (ctx )) {
41
33
/* receive no actual data if rx buf is NULL */
@@ -50,7 +42,7 @@ static inline void lpspi_rx_word_write_bytes(const struct device *dev, size_t of
50
42
/* Reads a maximum number of words from RX fifo and writes them to the remainder of the RX buf */
51
43
static inline size_t lpspi_rx_buf_write_words (const struct device * dev , uint8_t max_read )
52
44
{
53
- struct spi_mcux_data * data = dev -> data ;
45
+ struct spi_nxp_data * data = dev -> data ;
54
46
struct lpspi_driver_data * lpspi_data = (struct lpspi_driver_data * )data -> driver_data ;
55
47
struct spi_context * ctx = & data -> ctx ;
56
48
size_t buf_len = ctx -> rx_len / lpspi_data -> word_size_bytes ;
@@ -68,21 +60,21 @@ static inline size_t lpspi_rx_buf_write_words(const struct device *dev, uint8_t
68
60
69
61
static inline uint8_t rx_fifo_cur_len (LPSPI_Type * base )
70
62
{
71
- return ( base -> FSR & LPSPI_FSR_RXCOUNT_MASK ) >> LPSPI_FSR_RXCOUNT_SHIFT ;
63
+ return FIELD_GET ( LPSPI_FSR_RXCOUNT_MASK , base -> FSR ) ;
72
64
}
73
65
74
66
static inline void lpspi_handle_rx_irq (const struct device * dev )
75
67
{
76
68
LPSPI_Type * base = (LPSPI_Type * )DEVICE_MMIO_NAMED_GET (dev , reg_base );
77
- struct spi_mcux_data * data = dev -> data ;
69
+ struct spi_nxp_data * data = dev -> data ;
78
70
struct lpspi_driver_data * lpspi_data = (struct lpspi_driver_data * )data -> driver_data ;
79
71
struct spi_context * ctx = & data -> ctx ;
80
72
uint8_t total_words_written = 0 ;
81
73
uint8_t total_words_read = 0 ;
82
74
uint8_t words_read ;
83
75
uint8_t rx_fsr ;
84
76
85
- LPSPI_ClearStatusFlags ( base , kLPSPI_RxDataReadyFlag ) ;
77
+ base -> SR = LPSPI_SR_RDF_MASK ;
86
78
87
79
LOG_DBG ("RX FIFO: %d, RX BUF: %p" , rx_fsr , ctx -> rx_buf );
88
80
@@ -96,14 +88,14 @@ static inline void lpspi_handle_rx_irq(const struct device *dev)
96
88
LOG_DBG ("RX done %d words to spi buf" , total_words_written );
97
89
98
90
if (!spi_context_rx_on (ctx )) {
99
- LPSPI_DisableInterrupts ( base , ( uint32_t ) kLPSPI_RxInterruptEnable ) ;
100
- LPSPI_FlushFifo ( base , false, true);
91
+ base -> IER &= ~ LPSPI_IER_RDIE_MASK ;
92
+ base -> CR |= LPSPI_CR_RRF_MASK ; /* flush rx fifo */
101
93
}
102
94
}
103
95
104
96
static inline uint32_t lpspi_next_tx_word (const struct device * dev , int offset )
105
97
{
106
- struct spi_mcux_data * data = dev -> data ;
98
+ struct spi_nxp_data * data = dev -> data ;
107
99
struct lpspi_driver_data * lpspi_data = (struct lpspi_driver_data * )data -> driver_data ;
108
100
struct spi_context * ctx = & data -> ctx ;
109
101
const uint8_t * byte = ctx -> tx_buf + offset ;
@@ -120,13 +112,13 @@ static inline uint32_t lpspi_next_tx_word(const struct device *dev, int offset)
120
112
static inline void lpspi_fill_tx_fifo (const struct device * dev )
121
113
{
122
114
LPSPI_Type * base = (LPSPI_Type * )DEVICE_MMIO_NAMED_GET (dev , reg_base );
123
- struct spi_mcux_data * data = dev -> data ;
115
+ struct spi_nxp_data * data = dev -> data ;
124
116
struct lpspi_driver_data * lpspi_data = (struct lpspi_driver_data * )data -> driver_data ;
125
117
size_t bytes_in_xfer = lpspi_data -> fill_len * lpspi_data -> word_size_bytes ;
126
118
size_t offset ;
127
119
128
120
for (offset = 0 ; offset < bytes_in_xfer ; offset += lpspi_data -> word_size_bytes ) {
129
- LPSPI_WriteData ( base , lpspi_next_tx_word (dev , offset ) );
121
+ base -> TDR = lpspi_next_tx_word (dev , offset );
130
122
}
131
123
132
124
LOG_DBG ("Filled TX FIFO to %d words (%d bytes)" , lpspi_data -> fill_len , offset );
@@ -135,20 +127,20 @@ static inline void lpspi_fill_tx_fifo(const struct device *dev)
135
127
static inline void lpspi_fill_tx_fifo_nop (const struct device * dev )
136
128
{
137
129
LPSPI_Type * base = (LPSPI_Type * )DEVICE_MMIO_NAMED_GET (dev , reg_base );
138
- struct spi_mcux_data * data = dev -> data ;
130
+ struct spi_nxp_data * data = dev -> data ;
139
131
struct lpspi_driver_data * lpspi_data = (struct lpspi_driver_data * )data -> driver_data ;
140
132
141
133
for (int i = 0 ; i < lpspi_data -> fill_len ; i ++ ) {
142
- LPSPI_WriteData ( base , 0 ) ;
134
+ base -> TDR = 0 ;
143
135
}
144
136
145
137
LOG_DBG ("Filled TX fifo with %d NOPs" , lpspi_data -> fill_len );
146
138
}
147
139
148
140
static void lpspi_next_tx_fill (const struct device * dev )
149
141
{
150
- const struct spi_mcux_config * config = dev -> config ;
151
- struct spi_mcux_data * data = dev -> data ;
142
+ const struct spi_nxp_config * config = dev -> config ;
143
+ struct spi_nxp_data * data = dev -> data ;
152
144
struct lpspi_driver_data * lpspi_data = (struct lpspi_driver_data * )data -> driver_data ;
153
145
struct spi_context * ctx = & data -> ctx ;
154
146
size_t max_chunk ;
@@ -168,13 +160,13 @@ static void lpspi_next_tx_fill(const struct device *dev)
168
160
static inline void lpspi_handle_tx_irq (const struct device * dev )
169
161
{
170
162
LPSPI_Type * base = (LPSPI_Type * )DEVICE_MMIO_NAMED_GET (dev , reg_base );
171
- struct spi_mcux_data * data = dev -> data ;
163
+ struct spi_nxp_data * data = dev -> data ;
172
164
struct lpspi_driver_data * lpspi_data = (struct lpspi_driver_data * )data -> driver_data ;
173
165
struct spi_context * ctx = & data -> ctx ;
174
166
175
167
spi_context_update_tx (ctx , lpspi_data -> word_size_bytes , lpspi_data -> fill_len );
176
168
177
- LPSPI_ClearStatusFlags ( base , kLPSPI_TxDataRequestFlag ) ;
169
+ base -> SR = LPSPI_SR_TDF_MASK ;
178
170
179
171
/* Having no buffer length left indicates transfer is done, if there
180
172
* was RX to do left, the TX buf would be null but
@@ -185,7 +177,7 @@ static inline void lpspi_handle_tx_irq(const struct device *dev)
185
177
base -> TCR = 0 ;
186
178
lpspi_wait_tx_fifo_empty (dev );
187
179
spi_context_cs_control (ctx , false);
188
- LPSPI_DisableInterrupts ( base , ( uint32_t ) kLPSPI_TxInterruptEnable ) ;
180
+ base -> IER &= ~ LPSPI_IER_TDIE_MASK ;
189
181
return ;
190
182
}
191
183
@@ -194,7 +186,7 @@ static inline void lpspi_handle_tx_irq(const struct device *dev)
194
186
195
187
static inline bool lpspi_is_rx_done (const struct device * dev )
196
188
{
197
- struct spi_mcux_data * data = dev -> data ;
189
+ struct spi_nxp_data * data = dev -> data ;
198
190
struct lpspi_driver_data * lpspi_data = (struct lpspi_driver_data * )data -> driver_data ;
199
191
struct spi_context * ctx = & data -> ctx ;
200
192
size_t tx_total = lpspi_data -> tx_total_len ;
@@ -222,16 +214,16 @@ static inline void lpspi_clear_remaining_rx(struct spi_context *ctx)
222
214
static void lpspi_isr (const struct device * dev )
223
215
{
224
216
LPSPI_Type * base = (LPSPI_Type * )DEVICE_MMIO_NAMED_GET (dev , reg_base );
225
- const struct spi_mcux_config * config = dev -> config ;
226
- uint32_t status_flags = LPSPI_GetStatusFlags ( base ) ;
227
- struct spi_mcux_data * data = dev -> data ;
217
+ const struct spi_nxp_config * config = dev -> config ;
218
+ uint32_t status_flags = base -> SR ;
219
+ struct spi_nxp_data * data = dev -> data ;
228
220
struct spi_context * ctx = & data -> ctx ;
229
221
230
- if (status_flags & kLPSPI_RxDataReadyFlag ) {
222
+ if (status_flags & LPSPI_SR_RDF_MASK ) {
231
223
lpspi_handle_rx_irq (dev );
232
224
}
233
225
234
- if (status_flags & kLPSPI_TxDataRequestFlag ) {
226
+ if (status_flags & LPSPI_SR_TDF_MASK ) {
235
227
lpspi_handle_tx_irq (dev );
236
228
}
237
229
@@ -247,7 +239,7 @@ static int transceive(const struct device *dev, const struct spi_config *spi_cfg
247
239
bool asynchronous , spi_callback_t cb , void * userdata )
248
240
{
249
241
LPSPI_Type * base = (LPSPI_Type * )DEVICE_MMIO_NAMED_GET (dev , reg_base );
250
- struct spi_mcux_data * data = dev -> data ;
242
+ struct spi_nxp_data * data = dev -> data ;
251
243
struct lpspi_driver_data * lpspi_data = (struct lpspi_driver_data * )data -> driver_data ;
252
244
int ret ;
253
245
@@ -265,21 +257,14 @@ static int transceive(const struct device *dev, const struct spi_config *spi_cfg
265
257
lpspi_data -> tx_total_len = spi_context_total_tx_len (& data -> ctx );
266
258
lpspi_data -> rx_total_len = spi_context_total_rx_len (& data -> ctx );
267
259
268
- ret = spi_mcux_configure (dev , spi_cfg );
260
+ ret = spi_nxp_configure (dev , spi_cfg );
269
261
if (ret ) {
270
262
goto out ;
271
263
}
272
264
273
- LPSPI_FlushFifo (base , true, true);
274
- LPSPI_ClearStatusFlags (base , (uint32_t )kLPSPI_AllStatusFlag );
275
- LPSPI_DisableInterrupts (base , (uint32_t )kLPSPI_AllInterruptEnable );
276
-
277
265
LOG_DBG ("Starting LPSPI transfer" );
278
266
spi_context_cs_control (& data -> ctx , true);
279
267
280
- LPSPI_SetFifoWatermarks (base , 0 , 0 );
281
- LPSPI_Enable (base , true);
282
-
283
268
/* keep the chip select asserted until the end of the zephyr xfer */
284
269
base -> TCR |= LPSPI_TCR_CONT_MASK | LPSPI_TCR_CONTC_MASK ;
285
270
/* tcr is written to tx fifo */
@@ -288,8 +273,7 @@ static int transceive(const struct device *dev, const struct spi_config *spi_cfg
288
273
/* start the transfer sequence which are handled by irqs */
289
274
lpspi_next_tx_fill (dev );
290
275
291
- LPSPI_EnableInterrupts (base , (uint32_t )kLPSPI_TxInterruptEnable |
292
- (uint32_t )kLPSPI_RxInterruptEnable );
276
+ base -> IER |= LPSPI_IER_TDIE_MASK | LPSPI_IER_RDIE_MASK ;
293
277
294
278
ret = spi_context_wait_for_completion (& data -> ctx );
295
279
out :
@@ -298,15 +282,15 @@ static int transceive(const struct device *dev, const struct spi_config *spi_cfg
298
282
return ret ;
299
283
}
300
284
301
- static int spi_mcux_transceive_sync (const struct device * dev , const struct spi_config * spi_cfg ,
285
+ static int spi_nxp_transceive_sync (const struct device * dev , const struct spi_config * spi_cfg ,
302
286
const struct spi_buf_set * tx_bufs ,
303
287
const struct spi_buf_set * rx_bufs )
304
288
{
305
289
return transceive (dev , spi_cfg , tx_bufs , rx_bufs , false, NULL , NULL );
306
290
}
307
291
308
292
#ifdef CONFIG_SPI_ASYNC
309
- static int spi_mcux_transceive_async (const struct device * dev , const struct spi_config * spi_cfg ,
293
+ static int spi_nxp_transceive_async (const struct device * dev , const struct spi_config * spi_cfg ,
310
294
const struct spi_buf_set * tx_bufs ,
311
295
const struct spi_buf_set * rx_bufs , spi_callback_t cb ,
312
296
void * userdata )
@@ -315,20 +299,20 @@ static int spi_mcux_transceive_async(const struct device *dev, const struct spi_
315
299
}
316
300
#endif /* CONFIG_SPI_ASYNC */
317
301
318
- static DEVICE_API (spi , spi_mcux_driver_api ) = {
319
- .transceive = spi_mcux_transceive_sync ,
302
+ static DEVICE_API (spi , spi_nxp_driver_api ) = {
303
+ .transceive = spi_nxp_transceive_sync ,
320
304
#ifdef CONFIG_SPI_ASYNC
321
- .transceive_async = spi_mcux_transceive_async ,
305
+ .transceive_async = spi_nxp_transceive_async ,
322
306
#endif
323
307
#ifdef CONFIG_SPI_RTIO
324
308
.iodev_submit = spi_rtio_iodev_default_submit ,
325
309
#endif
326
- .release = spi_mcux_release ,
310
+ .release = spi_nxp_release ,
327
311
};
328
312
329
- static int spi_mcux_init (const struct device * dev )
313
+ static int spi_nxp_init (const struct device * dev )
330
314
{
331
- struct spi_mcux_data * data = dev -> data ;
315
+ struct spi_nxp_data * data = dev -> data ;
332
316
int err = 0 ;
333
317
334
318
err = spi_nxp_init_common (dev );
@@ -343,23 +327,23 @@ static int spi_mcux_init(const struct device *dev)
343
327
344
328
#define LPSPI_INIT (n ) \
345
329
SPI_NXP_LPSPI_COMMON_INIT(n) \
346
- SPI_MCUX_LPSPI_CONFIG_INIT (n) \
330
+ SPI_NXP_LPSPI_CONFIG_INIT (n) \
347
331
\
348
332
static struct lpspi_driver_data lpspi_##n##_driver_data; \
349
333
\
350
- static struct spi_mcux_data spi_mcux_data_ ##n = { \
334
+ static struct spi_nxp_data spi_nxp_data_ ##n = { \
351
335
SPI_NXP_LPSPI_COMMON_DATA_INIT(n) \
352
336
.driver_data = &lpspi_##n##_driver_data, \
353
337
}; \
354
338
\
355
- SPI_DEVICE_DT_INST_DEFINE(n, spi_mcux_init , NULL, &spi_mcux_data_ ##n, \
356
- &spi_mcux_config_ ##n, POST_KERNEL, CONFIG_SPI_INIT_PRIORITY, \
357
- &spi_mcux_driver_api );
339
+ SPI_DEVICE_DT_INST_DEFINE(n, spi_nxp_init , NULL, &spi_nxp_data_ ##n, \
340
+ &spi_nxp_config_ ##n, POST_KERNEL, CONFIG_SPI_INIT_PRIORITY, \
341
+ &spi_nxp_driver_api );
358
342
359
- #define SPI_MCUX_LPSPI_INIT_IF_DMA (n ) IF_DISABLED(SPI_NXP_LPSPI_HAS_DMAS(n), (LPSPI_INIT(n)))
343
+ #define SPI_NXP_LPSPI_INIT_IF_DMA (n ) IF_DISABLED(SPI_NXP_LPSPI_HAS_DMAS(n), (LPSPI_INIT(n)))
360
344
361
- #define SPI_MCUX_LPSPI_INIT (n ) \
362
- COND_CODE_1(CONFIG_SPI_MCUX_LPSPI_DMA, \
363
- (SPI_MCUX_LPSPI_INIT_IF_DMA (n)), (LPSPI_INIT(n)))
345
+ #define SPI_NXP_LPSPI_INIT (n ) \
346
+ COND_CODE_1(CONFIG_SPI_NXP_LPSPI_DMA, \
347
+ (SPI_NXP_LPSPI_INIT_IF_DMA (n)), (LPSPI_INIT(n)))
364
348
365
- DT_INST_FOREACH_STATUS_OKAY (SPI_MCUX_LPSPI_INIT )
349
+ DT_INST_FOREACH_STATUS_OKAY (SPI_NXP_LPSPI_INIT )
0 commit comments