@@ -296,13 +296,13 @@ static inline int qspi_isr_wait(uint32_t wait_mask, uint32_t wait_val)
296
296
}
297
297
return 0 ;
298
298
}
299
- #ifdef GQSPI_DMA
299
+ #ifndef GQSPI_MODE_IO
300
300
static inline int qspi_dmaisr_wait (uint32_t wait_mask , uint32_t wait_val )
301
301
{
302
302
uint32_t timeout = 0 ;
303
303
while ((GQSPIDMA_ISR & wait_mask ) == wait_val &&
304
- ++ timeout < GQSPI_TIMEOUT_TRIES );
305
- if (timeout == GQSPI_TIMEOUT_TRIES ) {
304
+ ++ timeout < GQSPIDMA_TIMEOUT_TRIES );
305
+ if (timeout == GQSPIDMA_TIMEOUT_TRIES ) {
306
306
return -1 ;
307
307
}
308
308
return 0 ;
@@ -362,7 +362,7 @@ static int gspi_fifo_tx(const uint8_t* data, uint32_t sz)
362
362
return GQSPI_CODE_SUCCESS ;
363
363
}
364
364
365
- #ifndef GQSPI_DMA
365
+ #ifdef GQSPI_MODE_IO
366
366
static int gspi_fifo_rx (uint8_t * data , uint32_t sz )
367
367
{
368
368
uint32_t tmp32 ;
@@ -415,28 +415,28 @@ static int qspi_cs(QspiDev_t* pDev, int csAssert)
415
415
416
416
static uint32_t qspi_calc_exp (uint32_t xferSz , uint32_t * reg_genfifo )
417
417
{
418
- uint32_t expval = 8 ;
418
+ uint32_t expval ;
419
419
* reg_genfifo &= ~(GQSPI_GEN_FIFO_IMM_MASK | GQSPI_GEN_FIFO_EXP_MASK );
420
420
if (xferSz > GQSPI_GEN_FIFO_IMM_MASK ) {
421
- /* Use exponent mode */
422
- while (1 ) {
421
+ /* Use exponent mode (DMA max is 2^28) */
422
+ for (expval = 28 ; expval >=8 ; expval -- ) {
423
+ /* find highest bit set */
423
424
if (xferSz & (1 << expval )) {
424
425
* reg_genfifo |= GQSPI_GEN_FIFO_EXP_MASK ;
425
- * reg_genfifo |= GQSPI_GEN_FIFO_IMM (expval ); /* IMM is exponent */
426
+ * reg_genfifo |= GQSPI_GEN_FIFO_IMM (expval ); /* IMM= exponent */
426
427
xferSz = (1 << expval );
427
428
break ;
428
429
}
429
- expval ++ ;
430
430
}
431
431
}
432
432
else {
433
433
/* Use length mode */
434
- * reg_genfifo |= GQSPI_GEN_FIFO_IMM (xferSz ); /* IMM is length */
434
+ * reg_genfifo |= GQSPI_GEN_FIFO_IMM (xferSz ); /* IMM=actual length */
435
435
}
436
436
return xferSz ;
437
437
}
438
438
439
- #ifdef GQSPI_DMA
439
+ #ifndef GQSPI_MODE_IO
440
440
static uint8_t XALIGNED (QQSPI_DMA_ALIGN ) dmatmp [GQSPI_DMA_TMPSZ ];
441
441
#endif
442
442
@@ -448,7 +448,7 @@ static int qspi_transfer(QspiDev_t* pDev,
448
448
{
449
449
int ret = GQSPI_CODE_SUCCESS ;
450
450
uint32_t reg_genfifo , xferSz ;
451
- #ifdef GQSPI_DMA
451
+ #ifndef GQSPI_MODE_IO
452
452
uint8_t * dmarxptr = NULL ;
453
453
#endif
454
454
GQSPI_EN = 1 ; /* Enable device */
@@ -529,27 +529,26 @@ static int qspi_transfer(QspiDev_t* pDev,
529
529
reg_genfifo |= (GQSPI_GEN_FIFO_RX | GQSPI_GEN_FIFO_DATA_XFER );
530
530
reg_genfifo |= (pDev -> stripe & GQSPI_GEN_FIFO_STRIPE );
531
531
532
- xferSz = rxSz ;
533
- #ifdef GQSPI_DMA
534
- /* if xferSz or rxData is not QQSPI_DMA_ALIGN aligned use tmp */
532
+ xferSz = qspi_calc_exp ( rxSz , & reg_genfifo ) ;
533
+ #ifndef GQSPI_MODE_IO
534
+ /* check if pointer is aligned or odd remainder */
535
535
dmarxptr = rxData ;
536
- if ((rxSz & (QQSPI_DMA_ALIGN - 1 )) ||
537
- (((size_t )rxData ) & (QQSPI_DMA_ALIGN - 1 ))) {
536
+ if (((size_t )rxData & (QQSPI_DMA_ALIGN - 1 )) || (xferSz & 3 )) {
538
537
dmarxptr = (uint8_t * )dmatmp ;
539
- /* round up */
540
538
xferSz = ((xferSz + (QQSPI_DMA_ALIGN - 1 )) & ~(QQSPI_DMA_ALIGN - 1 ));
541
539
if (xferSz > (uint32_t )sizeof (dmatmp )) {
542
540
xferSz = (uint32_t )sizeof (dmatmp );
543
541
}
542
+ /* re-adjust transfer */
543
+ xferSz = qspi_calc_exp (xferSz , & reg_genfifo );
544
544
}
545
545
546
546
GQSPIDMA_DST = (unsigned long )dmarxptr ;
547
547
GQSPIDMA_SIZE = xferSz ;
548
- GQSPIDMA_IER = GQSPIDMA_ISR_ALL_MASK ;
548
+ GQSPIDMA_IER = GQSPIDMA_ISR_DONE ; /* enable DMA done interrupt */
549
549
flush_dcache_range ((unsigned long )dmarxptr ,
550
550
(unsigned long )dmarxptr + xferSz );
551
551
#endif
552
- xferSz = qspi_calc_exp (xferSz , & reg_genfifo );
553
552
554
553
/* Submit general FIFO operation */
555
554
ret = qspi_gen_fifo_write (reg_genfifo );
@@ -558,7 +557,7 @@ static int qspi_transfer(QspiDev_t* pDev,
558
557
break ;
559
558
}
560
559
561
- #ifndef GQSPI_DMA
560
+ #ifdef GQSPI_MODE_IO
562
561
/* Read FIFO */
563
562
ret = gspi_fifo_rx (rxData , xferSz );
564
563
if (ret != GQSPI_CODE_SUCCESS ) {
@@ -569,14 +568,21 @@ static int qspi_transfer(QspiDev_t* pDev,
569
568
if (qspi_dmaisr_wait (GQSPIDMA_ISR_DONE , 0 )) {
570
569
return GQSPI_CODE_TIMEOUT ;
571
570
}
572
- GQSPIDMA_ISR = GQSPIDMA_ISR_DONE ;
571
+ GQSPIDMA_ISR = GQSPIDMA_ISR_DONE ; /* clear DMA interrupt */
573
572
/* adjust xfer sz */
574
573
if (xferSz > rxSz )
575
574
xferSz = rxSz ;
576
575
/* copy result if not aligned */
577
576
if (dmarxptr != rxData ) {
578
577
memcpy (rxData , dmarxptr , xferSz );
579
578
}
579
+ #if defined(DEBUG_ZYNQ ) && DEBUG_ZYNQ >= 3
580
+ if (xferSz <= 1024 ) {
581
+ for (uint32_t i = 0 ; i < xferSz ; i += 4 ) {
582
+ wolfBoot_printf ("RXD=%08x\n" , * ((uint32_t * )& rxData [i ]));
583
+ }
584
+ }
585
+ #endif
580
586
#endif
581
587
582
588
/* offset size and buffer */
@@ -594,7 +600,7 @@ static int qspi_transfer(QspiDev_t* pDev,
594
600
static int qspi_flash_read_id (QspiDev_t * dev , uint8_t * id , uint32_t idSz )
595
601
{
596
602
int ret ;
597
- uint8_t cmd [20 ]; /* size multiple of uint32_t */
603
+ uint8_t cmd [4 ]; /* size multiple of uint32_t */
598
604
uint8_t status = 0 ;
599
605
600
606
memset (cmd , 0 , sizeof (cmd ));
@@ -846,53 +852,47 @@ void qspi_init(uint32_t cpu_clock, uint32_t flash_freq)
846
852
/* Select Generic Quad-SPI */
847
853
GQSPI_SEL = 1 ;
848
854
849
- /* Clear and disable interrupts */
855
+ /* Clear and disable all interrupts */
850
856
reg_isr = GQSPI_ISR ;
851
- GQSPI_ISR |= GQSPI_ISR_WR_TO_CLR_MASK ; /* Clear poll timeout counter interrupt */
857
+ GQSPI_ISR = ( reg_isr | GQSPI_ISR_WR_TO_CLR_MASK ) ; /* Clear poll timeout counter interrupt */
852
858
reg_cfg = GQSPIDMA_ISR ;
853
859
GQSPIDMA_ISR = reg_cfg ; /* clear all active interrupts */
854
- GQSPIDMA_STS |= GQSPIDMA_STS_WTC ; /* mark outstanding DMA's done */
855
860
GQSPI_IDR = GQSPI_IXR_ALL_MASK ; /* disable interrupts */
856
- GQSPIDMA_ISR = GQSPIDMA_ISR_ALL_MASK ; /* disable interrupts */
857
- /* Reset FIFOs */
858
- if (GQSPI_ISR & GQSPI_IXR_RX_FIFO_EMPTY ) {
859
- GQSPI_FIFO_CTRL |= (GQSPI_FIFO_CTRL_RST_TX_FIFO | GQSPI_FIFO_CTRL_RST_RX_FIFO );
860
- }
861
- if (reg_isr & GQSPI_IXR_RX_FIFO_EMPTY ) {
862
- GQSPI_FIFO_CTRL |= GQSPI_FIFO_CTRL_RST_RX_FIFO ;
863
- }
861
+ GQSPIDMA_IDR = GQSPIDMA_ISR_ALL_MASK ;
864
862
865
863
GQSPI_EN = 0 ; /* Disable device */
866
864
867
865
/* Initialize clock divisor, write protect hold and start mode */
868
- #ifdef GQSPI_DMA
869
- reg_cfg = GQSPI_CFG_MODE_EN_DMA ; /* Use DMA Transfer Mode */
870
- #else
866
+ #ifdef GQSPI_MODE_IO
871
867
reg_cfg = GQSPI_CFG_MODE_EN_IO ; /* Use I/O Transfer Mode */
872
868
reg_cfg |= GQSPI_CFG_START_GEN_FIFO ; /* Auto start GFIFO cmd execution */
869
+ #else
870
+ reg_cfg = GQSPI_CFG_MODE_EN_DMA ; /* Use DMA Transfer Mode */
873
871
#endif
874
872
reg_cfg |= GQSPI_CFG_BAUD_RATE_DIV (GQSPI_CLK_DIV ); /* Clock Divider */
875
873
reg_cfg |= GQSPI_CFG_WP_HOLD ; /* Use WP Hold */
876
874
reg_cfg &= ~(GQSPI_CFG_CLK_POL | GQSPI_CFG_CLK_PH ); /* Use POL=0,PH=0 */
877
875
GQSPI_CFG = reg_cfg ;
878
876
879
- #if GQSPI_CLK_DIV >= 2 /* 300/8=37.5MHz */
880
- /* At 40 MHz, the Quad-SPI controller should be in non-loopback mode with
877
+ #if GQSPI_CLK_DIV >= 1 /* 125/4=31.25MHz */
878
+ /* At < 40 MHz, the Quad-SPI controller should be in non-loopback mode with
881
879
* the clock and data tap delays bypassed. */
882
880
IOU_TAPDLY_BYPASS |= IOU_TAPDLY_BYPASS_LQSPI_RX ;
883
881
GQSPI_LPBK_DLY_ADJ = 0 ;
884
882
GQSPI_DATA_DLY_ADJ = 0 ;
885
- #elif GQSPI_CLK_DIV >= 1 /* 300/4=75MHz */
886
- /* At 100 MHz, the Quad-SPI controller should be in clock loopback mode
883
+ #elif GQSPI_CLK_DIV >= 0 /* 125/2 = 62.5MHz */
884
+ /* At < 100 MHz, the Quad-SPI controller should be in clock loopback mode
887
885
* with the clock tap delay bypassed, but the data tap delay enabled. */
888
886
IOU_TAPDLY_BYPASS |= IOU_TAPDLY_BYPASS_LQSPI_RX ;
889
887
GQSPI_LPBK_DLY_ADJ = GQSPI_LPBK_DLY_ADJ_USE_LPBK ;
890
888
GQSPI_DATA_DLY_ADJ = (GQSPI_DATA_DLY_ADJ_USE_DATA_DLY |
891
889
GQSPI_DATA_DLY_ADJ_DATA_DLY_ADJ (2 ));
892
- #else
893
- /* At 150 MHz, only the generic controller can be used.
890
+ #endif
891
+ #if 0
892
+ /* At <150 MHz, only the generic controller can be used.
894
893
* The generic controller should be in clock loopback mode and the clock
895
894
* tap delay enabled, but the data tap delay disabled. */
895
+ /* For EL2 or lower must use IOCTL_SET_TAPDELAY_BYPASS ARG1=2, ARG2=0 */
896
896
IOU_TAPDLY_BYPASS = 0 ;
897
897
GQSPI_LPBK_DLY_ADJ = GQSPI_LPBK_DLY_ADJ_USE_LPBK ;
898
898
GQSPI_DATA_DLY_ADJ = 0 ;
@@ -907,10 +907,6 @@ void qspi_init(uint32_t cpu_clock, uint32_t flash_freq)
907
907
GQSPIDMA_CTRL = GQSPIDMA_CTRL_DEF ;
908
908
GQSPIDMA_CTRL2 = GQSPIDMA_CTRL2_DEF ;
909
909
910
- /* Interrupts unmask and enable */
911
- GQSPI_IMR = GQSPI_IXR_ALL_MASK ;
912
- GQSPI_IER = GQSPI_IXR_ALL_MASK ;
913
-
914
910
GQSPI_EN = 1 ; /* Enable Device */
915
911
#endif /* USE_QNX */
916
912
(void )reg_cfg ;
0 commit comments