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
Index: firmware/target/arm/as3525/ata_sd_as3525.c
===================================================================
--- firmware/target/arm/as3525/ata_sd_as3525.c	(Revision 19767)
+++ firmware/target/arm/as3525/ata_sd_as3525.c	(Arbeitskopie)
@@ -110,7 +110,7 @@
 #endif

 static struct wakeup transfer_completion_signal;
-bool retry;
+static volatile bool retry;

 static inline void mci_delay(void) { int i = 0xffff; while(i--) ; }

@@ -383,9 +383,10 @@
             {
                 sd_enable(true);
                 init_pl180_controller(SD_SLOT_AS3525);
-                disk_mount(1);
+                sd_init_card(SD_SLOT_AS3525);
+                disk_mount(SD_SLOT_AS3525);
             }
-
+            
             queue_broadcast(SYS_FS_CHANGED, 0);

             /* Access is now safe */
@@ -427,6 +428,11 @@

 static void init_pl180_controller(const int drive)
 {
+    if (drive == SD_SLOT_AS3525)
+    {        
+        CCU_IO &= ~(1<<3);           /* bits 3:2 = 01, xpd is SD interface */
+        CCU_IO |= (1<<2);
+    }
     MCI_COMMAND(drive) = MCI_DATA_CTRL(drive) = 0;
     MCI_CLEAR(drive) = 0x7ff;

@@ -445,6 +451,7 @@
     GPIOA_IS &= ~(1<<2);
     /* detect both raising and falling edges */
     GPIOA_IBE |= (1<<2);
+
 #endif

 #else
@@ -488,19 +495,11 @@
     if(ret < 0)
         return ret;

-#ifdef HAVE_MULTIVOLUME
-    CCU_IO &= ~8;           /* bits 3:2 = 01, xpd is SD interface */
-    CCU_IO |= 4;
-
-    init_pl180_controller(SD_SLOT_AS3525);
-    sd_init_card(SD_SLOT_AS3525);
-#endif
-    /* init mutex */
-
 #ifndef BOOTLOADER
     sd_enable(false);
 #endif

+    /* init mutex */
     mutex_init(&sd_mtx);

     queue_init(&sd_queue, true);
@@ -603,10 +602,10 @@

     if (card_info[drive].initialized <= 0)
     {
-        sd_init_card(drive);
+        ret = sd_init_card(drive);
         if (!(card_info[drive].initialized))
         {
-            panicf("card not initialised");
+            panicf("card not initialised (%d)", ret);
             goto sd_transfer_error;
         }
     }
@@ -623,6 +622,8 @@

     while(count)
     {
+        /* Interrupt handler might set this to true during transfer */
+        retry = false;
         /* 128 * 512 = 2^16, and doesn't fit in the 16 bits of DATA_LENGTH
          * register, so we have to transfer maximum 127 sectors at a time. */
         unsigned int transfer = (count >= 128) ? 127 : count; /* sectors */
@@ -657,7 +658,7 @@
                                 (1<<3) /* DMA */                        |
                                 (9<<4) /* 2^9 = 512 */ ;

-        retry = false;
+
         wakeup_wait(&transfer_completion_signal, TIMEOUT_BLOCK);
         if(!retry)
         {