@@ -28,8 +28,13 @@ LOG_MODULE_REGISTER(spi_mcux_lpspi, CONFIG_SPI_LOG_LEVEL);
28
28
#define CHIP_SELECT_COUNT 4
29
29
#define MAX_DATA_WIDTH 4096
30
30
31
+ /* Required by DEVICE_MMIO_NAMED_* macros */
32
+ #define DEV_CFG (_dev ) \
33
+ ((const struct spi_mcux_config *)(_dev)->config)
34
+ #define DEV_DATA (_dev ) ((struct spi_mcux_data *)(_dev)->data)
35
+
31
36
struct spi_mcux_config {
32
- LPSPI_Type * base ;
37
+ DEVICE_MMIO_NAMED_ROM ( reg_base ) ;
33
38
const struct device * clock_dev ;
34
39
clock_control_subsys_t clock_subsys ;
35
40
void (* irq_config_func )(const struct device * dev );
@@ -56,6 +61,7 @@ struct stream {
56
61
#endif
57
62
58
63
struct spi_mcux_data {
64
+ DEVICE_MMIO_NAMED_RAM (reg_base );
59
65
const struct device * dev ;
60
66
lpspi_master_handle_t handle ;
61
67
struct spi_context ctx ;
@@ -83,9 +89,9 @@ struct spi_mcux_data {
83
89
84
90
static int spi_mcux_transfer_next_packet (const struct device * dev )
85
91
{
86
- const struct spi_mcux_config * config = dev -> config ;
92
+ /* const struct spi_mcux_config *config = dev->config; */
87
93
struct spi_mcux_data * data = dev -> data ;
88
- LPSPI_Type * base = config -> base ;
94
+ LPSPI_Type * base = ( LPSPI_Type * ) DEVICE_MMIO_NAMED_GET ( dev , reg_base ) ;
89
95
struct spi_context * ctx = & data -> ctx ;
90
96
lpspi_transfer_t transfer ;
91
97
status_t status ;
@@ -98,7 +104,7 @@ static int spi_mcux_transfer_next_packet(const struct device *dev)
98
104
}
99
105
100
106
transfer .configFlags = kLPSPI_MasterPcsContinuous |
101
- (ctx -> config -> slave << LPSPI_MASTER_PCS_SHIFT );
107
+ (ctx -> config -> slave << LPSPI_MASTER_PCS_SHIFT );
102
108
103
109
if (ctx -> tx_len == 0 ) {
104
110
/* rx only, nothing to tx */
@@ -153,9 +159,9 @@ static int spi_mcux_transfer_next_packet(const struct device *dev)
153
159
154
160
static void spi_mcux_isr (const struct device * dev )
155
161
{
156
- const struct spi_mcux_config * config = dev -> config ;
162
+ /* const struct spi_mcux_config *config = dev->config; */
157
163
struct spi_mcux_data * data = dev -> data ;
158
- LPSPI_Type * base = config -> base ;
164
+ LPSPI_Type * base = ( LPSPI_Type * ) DEVICE_MMIO_NAMED_GET ( dev , reg_base ) ;
159
165
160
166
LPSPI_MasterTransferHandleIRQ (base , & data -> handle );
161
167
}
@@ -182,11 +188,11 @@ static void spi_mcux_master_transfer_callback(LPSPI_Type *base,
182
188
}
183
189
184
190
static int spi_mcux_configure (const struct device * dev ,
185
- const struct spi_config * spi_cfg )
191
+ const struct spi_config * spi_cfg )
186
192
{
187
193
const struct spi_mcux_config * config = dev -> config ;
188
194
struct spi_mcux_data * data = dev -> data ;
189
- LPSPI_Type * base = config -> base ;
195
+ LPSPI_Type * base = ( LPSPI_Type * ) DEVICE_MMIO_NAMED_GET ( dev , reg_base ) ;
190
196
lpspi_master_config_t master_config ;
191
197
uint32_t clock_freq ;
192
198
uint32_t word_size ;
@@ -205,15 +211,15 @@ static int spi_mcux_configure(const struct device *dev,
205
211
206
212
if (spi_cfg -> slave > CHIP_SELECT_COUNT ) {
207
213
LOG_ERR ("Slave %d is greater than %d" ,
208
- spi_cfg -> slave ,
209
- CHIP_SELECT_COUNT );
214
+ spi_cfg -> slave ,
215
+ CHIP_SELECT_COUNT );
210
216
return - EINVAL ;
211
217
}
212
218
213
219
word_size = SPI_WORD_SIZE_GET (spi_cfg -> operation );
214
220
if (word_size > MAX_DATA_WIDTH ) {
215
221
LOG_ERR ("Word size %d is greater than %d" ,
216
- word_size , MAX_DATA_WIDTH );
222
+ word_size , MAX_DATA_WIDTH );
217
223
return - EINVAL ;
218
224
}
219
225
@@ -335,10 +341,10 @@ static void spi_mcux_dma_callback(const struct device *dev, void *arg,
335
341
336
342
static int spi_mcux_dma_tx_load (const struct device * dev , const uint8_t * buf , size_t len )
337
343
{
338
- const struct spi_mcux_config * cfg = dev -> config ;
344
+ /* const struct spi_mcux_config *cfg = dev->config; */
339
345
struct spi_mcux_data * data = dev -> data ;
340
346
struct dma_block_config * blk_cfg ;
341
- LPSPI_Type * base = cfg -> base ;
347
+ LPSPI_Type * base = ( LPSPI_Type * ) DEVICE_MMIO_NAMED_GET ( dev , reg_base ) ;
342
348
343
349
/* remember active TX DMA channel (used in callback) */
344
350
struct stream * stream = & data -> dma_tx ;
@@ -378,10 +384,10 @@ static int spi_mcux_dma_tx_load(const struct device *dev, const uint8_t *buf, si
378
384
static int spi_mcux_dma_rx_load (const struct device * dev , uint8_t * buf ,
379
385
size_t len )
380
386
{
381
- const struct spi_mcux_config * cfg = dev -> config ;
387
+ /* const struct spi_mcux_config *cfg = dev->config; */
382
388
struct spi_mcux_data * data = dev -> data ;
383
389
struct dma_block_config * blk_cfg ;
384
- LPSPI_Type * base = cfg -> base ;
390
+ LPSPI_Type * base = ( LPSPI_Type * ) DEVICE_MMIO_NAMED_GET ( dev , reg_base ) ;
385
391
386
392
/* retrieve active RX DMA channel (used in callback) */
387
393
struct stream * stream = & data -> dma_rx ;
@@ -480,16 +486,16 @@ static inline int spi_mcux_dma_rxtx_load(const struct device *dev,
480
486
}
481
487
482
488
static int transceive_dma (const struct device * dev ,
483
- const struct spi_config * spi_cfg ,
484
- const struct spi_buf_set * tx_bufs ,
485
- const struct spi_buf_set * rx_bufs ,
486
- bool asynchronous ,
487
- spi_callback_t cb ,
488
- void * userdata )
489
+ const struct spi_config * spi_cfg ,
490
+ const struct spi_buf_set * tx_bufs ,
491
+ const struct spi_buf_set * rx_bufs ,
492
+ bool asynchronous ,
493
+ spi_callback_t cb ,
494
+ void * userdata )
489
495
{
490
- const struct spi_mcux_config * config = dev -> config ;
496
+ /* const struct spi_mcux_config *config = dev->config; */
491
497
struct spi_mcux_data * data = dev -> data ;
492
- LPSPI_Type * base = config -> base ;
498
+ LPSPI_Type * base = ( LPSPI_Type * ) DEVICE_MMIO_NAMED_GET ( dev , reg_base ) ;
493
499
int ret ;
494
500
size_t dma_size ;
495
501
@@ -564,12 +570,12 @@ static int transceive_dma(const struct device *dev,
564
570
#endif
565
571
566
572
static int transceive (const struct device * dev ,
567
- const struct spi_config * spi_cfg ,
568
- const struct spi_buf_set * tx_bufs ,
569
- const struct spi_buf_set * rx_bufs ,
570
- bool asynchronous ,
571
- spi_callback_t cb ,
572
- void * userdata )
573
+ const struct spi_config * spi_cfg ,
574
+ const struct spi_buf_set * tx_bufs ,
575
+ const struct spi_buf_set * rx_bufs ,
576
+ bool asynchronous ,
577
+ spi_callback_t cb ,
578
+ void * userdata )
573
579
{
574
580
struct spi_mcux_data * data = dev -> data ;
575
581
int ret ;
@@ -599,9 +605,9 @@ static int transceive(const struct device *dev,
599
605
600
606
601
607
static int spi_mcux_transceive (const struct device * dev ,
602
- const struct spi_config * spi_cfg ,
603
- const struct spi_buf_set * tx_bufs ,
604
- const struct spi_buf_set * rx_bufs )
608
+ const struct spi_config * spi_cfg ,
609
+ const struct spi_buf_set * tx_bufs ,
610
+ const struct spi_buf_set * rx_bufs )
605
611
{
606
612
#ifdef CONFIG_SPI_MCUX_LPSPI_DMA
607
613
const struct spi_mcux_data * data = dev -> data ;
@@ -616,11 +622,11 @@ static int spi_mcux_transceive(const struct device *dev,
616
622
617
623
#ifdef CONFIG_SPI_ASYNC
618
624
static int spi_mcux_transceive_async (const struct device * dev ,
619
- const struct spi_config * spi_cfg ,
620
- const struct spi_buf_set * tx_bufs ,
621
- const struct spi_buf_set * rx_bufs ,
622
- spi_callback_t cb ,
623
- void * userdata )
625
+ const struct spi_config * spi_cfg ,
626
+ const struct spi_buf_set * tx_bufs ,
627
+ const struct spi_buf_set * rx_bufs ,
628
+ spi_callback_t cb ,
629
+ void * userdata )
624
630
{
625
631
#ifdef CONFIG_SPI_MCUX_LPSPI_DMA
626
632
struct spi_mcux_data * data = dev -> data ;
@@ -637,7 +643,7 @@ static int spi_mcux_transceive_async(const struct device *dev,
637
643
#endif /* CONFIG_SPI_ASYNC */
638
644
639
645
static int spi_mcux_release (const struct device * dev ,
640
- const struct spi_config * spi_cfg )
646
+ const struct spi_config * spi_cfg )
641
647
{
642
648
struct spi_mcux_data * data = dev -> data ;
643
649
@@ -652,6 +658,8 @@ static int spi_mcux_init(const struct device *dev)
652
658
const struct spi_mcux_config * config = dev -> config ;
653
659
struct spi_mcux_data * data = dev -> data ;
654
660
661
+ DEVICE_MMIO_NAMED_MAP (dev , reg_base , K_MEM_CACHE_NONE | K_MEM_DIRECT_MAP );
662
+
655
663
config -> irq_config_func (dev );
656
664
657
665
err = spi_context_cs_configure_all (& data -> ctx );
@@ -714,19 +722,19 @@ static void spi_mcux_iodev_next(const struct device *dev, bool completion);
714
722
715
723
static void spi_mcux_iodev_start (const struct device * dev )
716
724
{
717
- const struct spi_mcux_config * config = dev -> config ;
725
+ /* const struct spi_mcux_config *config = dev->config; */
718
726
struct spi_mcux_data * data = dev -> data ;
719
727
struct rtio_sqe * sqe = & data -> txn_curr -> sqe ;
720
728
struct spi_dt_spec * spi_dt_spec = sqe -> iodev -> data ;
721
729
struct spi_config * spi_cfg = & spi_dt_spec -> config ;
722
730
struct rtio_iodev_sqe * txn_head = data -> txn_head ;
723
731
724
- LPSPI_Type * base = config -> base ;
732
+ LPSPI_Type * base = ( LPSPI_Type * ) DEVICE_MMIO_NAMED_GET ( dev , reg_base ) ;
725
733
lpspi_transfer_t transfer ;
726
734
status_t status ;
727
735
728
736
transfer .configFlags = kLPSPI_MasterPcsContinuous |
729
- (spi_cfg -> slave << LPSPI_MASTER_PCS_SHIFT );
737
+ (spi_cfg -> slave << LPSPI_MASTER_PCS_SHIFT );
730
738
731
739
switch (sqe -> op ) {
732
740
case RTIO_OP_RX :
@@ -895,7 +903,7 @@ static const struct spi_driver_api spi_mcux_driver_api = {
895
903
static void spi_mcux_config_func_##n(const struct device *dev); \
896
904
\
897
905
static const struct spi_mcux_config spi_mcux_config_##n = { \
898
- .base = (LPSPI_Type *) DT_INST_REG_ADDR (n), \
906
+ DEVICE_MMIO_NAMED_ROM_INIT(reg_base, DT_DRV_INST (n)), \
899
907
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(n)), \
900
908
.clock_subsys = \
901
909
(clock_control_subsys_t)DT_INST_CLOCKS_CELL(n, name), \
@@ -924,15 +932,15 @@ static const struct spi_driver_api spi_mcux_driver_api = {
924
932
}; \
925
933
\
926
934
DEVICE_DT_INST_DEFINE(n, &spi_mcux_init, NULL, \
927
- &spi_mcux_data_##n, \
928
- &spi_mcux_config_##n, POST_KERNEL, \
929
- CONFIG_SPI_INIT_PRIORITY, \
930
- &spi_mcux_driver_api); \
935
+ &spi_mcux_data_##n, \
936
+ &spi_mcux_config_##n, POST_KERNEL, \
937
+ CONFIG_SPI_INIT_PRIORITY, \
938
+ &spi_mcux_driver_api); \
931
939
\
932
940
static void spi_mcux_config_func_##n(const struct device *dev) \
933
941
{ \
934
942
IRQ_CONNECT(DT_INST_IRQN(n), DT_INST_IRQ(n, priority), \
935
- spi_mcux_isr, DEVICE_DT_INST_GET(n), 0); \
943
+ spi_mcux_isr, DEVICE_DT_INST_GET(n), 0); \
936
944
\
937
945
irq_enable(DT_INST_IRQN(n)); \
938
946
}
0 commit comments