1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
 firmware/target/arm/as3525/sd-as3525v2.c |   38 +++++++++++++++++++++++++----
 1 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/firmware/target/arm/as3525/sd-as3525v2.c b/firmware/target/arm/as3525/sd-as3525v2.c
index 65fc13f..4b58d1d 100644
--- a/firmware/target/arm/as3525/sd-as3525v2.c
+++ b/firmware/target/arm/as3525/sd-as3525v2.c
@@ -243,6 +243,7 @@
  * bits 31, 15:12 : unused
  */
 #define MCI_FIFOTH_MASK 0x8000f000
+#define MCI_FIFO_COUNT  ((MCI_STATUS >> 17) & 0x1FFF)

 #define MCI_CDETECT     SD_REG(0x50)    /* card detect */

@@ -347,6 +348,10 @@ int active_card = 0;

 static inline void mci_delay(void) { udelay(1000); }

+unsigned long my_response;
+
+static volatile bool mci_write;
+
 void INT_NAND(void)
 {
     MCI_CTRL &= ~INT_ENABLE;
@@ -357,6 +362,15 @@ void INT_NAND(void)
     if(status & MCI_DATA_ERROR)
         retry = true;

+   if(/*mci_write &&*/ retry)
+        panicf("NAND isr %8x  FIFO bytes: %d     CIU: %d  BIU %d   resp: %8x  sts: %8x",
+              (status & MCI_DATA_ERROR),
+              (unsigned int)MCI_FIFO_COUNT,
+              (unsigned int)MCI_TCBCNT,
+              (unsigned int)MCI_TBBCNT,
+              (unsigned int)my_response,
+              (unsigned int)status);
+
     if( status & (MCI_INT_DTO|MCI_DATA_ERROR))
         wakeup_signal(&transfer_completion_signal);

@@ -751,6 +765,8 @@ static int sd_wait_for_state(const int drive, unsigned int state)
 static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start,
                                 int count, void* buf, bool write)
 {
+    mci_write = write;
+
     int ret = 0;
 #ifndef HAVE_MULTIDRIVE
     const int drive = 0;
@@ -785,7 +801,7 @@ static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start,
     last_disk_activity = current_tick;
     dma_retain();

-    const int cmd = write ? SD_WRITE_MULTIPLE_BLOCK : SD_READ_MULTIPLE_BLOCK;
+//    const int cmd = write ? SD_WRITE_MULTIPLE_BLOCK : SD_READ_MULTIPLE_BLOCK;

     do
     {
@@ -817,22 +833,29 @@ static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start,
             goto sd_transfer_error;
         }

-        MCI_MASK |= (MCI_DATA_ERROR | MCI_INT_DTO);
-        MCI_CTRL |= DMA_ENABLE;
-
         int arg = start;
         if(!(card_info[drive].ocr & (1<<30))) /* not SDHC */
             arg *= SD_BLOCK_SIZE;

-        if(!send_cmd(drive, cmd, arg, MCI_NO_RESP, NULL))
-            panicf("%s multiple blocks failed", write ? "write" : "read");
+        MCI_MASK |= (MCI_DATA_ERROR | MCI_INT_DTO);
+        MCI_CTRL |= DMA_ENABLE;

         if(write)
+        {
+            if(!send_cmd(drive, SD_WRITE_MULTIPLE_BLOCK, arg, MCI_RESP, &my_response))
+                    panicf("write multiple blocks failed");
+
             dma_enable_channel(0, dma_buf, MCI_FIFO, DMA_PERI_SD,
                 DMAC_FLOWCTRL_PERI_MEM_TO_PERI, true, false, 0, DMA_S8, NULL);
+        }
         else
+        {
+            if(!send_cmd(drive, SD_READ_MULTIPLE_BLOCK, arg, MCI_RESP, &my_response))
+                panicf("read multiple blocks failed");
+
             dma_enable_channel(0, MCI_FIFO, dma_buf, DMA_PERI_SD,
                 DMAC_FLOWCTRL_PERI_PERI_TO_MEM, false, true, 0, DMA_S8, NULL);
+        }

         wakeup_wait(&transfer_completion_signal, TIMEOUT_BLOCK);

@@ -849,6 +872,9 @@ static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start,

         if(!retry)
         {
+            if (write)
+                panicf("here!");
+
             if(!write)
                 memcpy(buf, uncached_buffer, transfer * SD_BLOCK_SIZE);
             buf += transfer * SD_BLOCK_SIZE;