Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.

My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.


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
diff --git a/firmware/target/arm/as3525/sd-as3525v2.c b/firmware/target/arm/as3525/sd-as3525v2.c
index 9756d9e..4b556e8 100644
--- a/firmware/target/arm/as3525/sd-as3525v2.c
+++ b/firmware/target/arm/as3525/sd-as3525v2.c
@@ -64,6 +64,10 @@
 #define MCI_RESP        (1<<0)
 #define MCI_LONG_RESP   (1<<1)

+#ifdef SANSA_FUZEV2
+int model = 1;
+#endif
+
 /* controller registers */
 #define SD_BASE 0xC6070000

@@ -327,7 +331,6 @@
 static unsigned char aligned_buffer[UNALIGNED_NUM_SECTORS* SD_BLOCK_SIZE] __attribute__((aligned(32)));   /* align on cache line size */
 static unsigned char *uncached_buffer = AS3525_UNCACHED_ADDR(&aligned_buffer[0]);

-static void init_controller(void);
 static int sd_wait_for_tran_state(const int drive);

 static tCardInfo card_info[NUM_DRIVES];
@@ -405,6 +408,11 @@ static bool send_cmd(const int drive, const int cmd, const int arg, const int fl
     MCI_ARGUMENT = arg;

     /* Construct MCI_COMMAND  */
+    int card_no = CMD_CARD_NO(drive);
+#ifdef SANSA_FUZEV2
+    if (model == 1)
+        card_no = 1<<16;
+#endif
     MCI_COMMAND =
       /*b5:0*/    cmd
       /*b6  */  | ((flags & MCI_RESP)                ? CMD_RESP_EXP_BIT:      0)
@@ -417,13 +425,13 @@ static bool send_cmd(const int drive, const int cmd, const int arg, const int fl
       /*b13 */  | (TRANSFER_CMD                      ? CMD_WAIT_PRV_DAT_BIT:  0)
       /*b14     | CMD_ABRT_CMD_BIT        unused  */
       /*b15     | CMD_SEND_INIT_BIT       unused  */
-   /*b20:16 */  |                                      CMD_CARD_NO(drive)
+   /*b20:16 */  |                                      card_no
       /*b21     | CMD_SEND_CLK_ONLY       unused  */
       /*b22     | CMD_READ_CEATA          unused  */
       /*b23     | CMD_CCS_EXPECTED        unused  */
       /*b31 */  |                                      CMD_DONE_BIT;

-#ifdef SANSA_FUZEV2
+#if 0 //def SANSA_FUZEV2
     extern int buttonlight_is_on;
     if(buttonlight_is_on)
         _buttonlight_on();
@@ -436,7 +444,10 @@ static bool send_cmd(const int drive, const int cmd, const int arg, const int fl
     if(flags & MCI_RESP)
     {
         if(cmd_error & (MCI_INT_RCRC | MCI_INT_RTO))
+        {
+            panicf("error 0x%x", cmd_error);
             return false;
+        }

         if(flags & MCI_LONG_RESP)
         {
@@ -457,6 +468,8 @@ static int sd_init_card(const int drive)
     long init_timeout;
     bool sd_v2 = false;

+    GPIOB_DIR |= 1<<5;
+
     /*  assume 24 MHz clock / 60 = 400 kHz  */
     MCI_CLKDIV = (MCI_CLKDIV & ~(0xFF)) | 0x3C;    /* CLK_DIV_0 : bits 7:0  */

@@ -661,13 +674,18 @@ static void init_controller(void)
 {
     int hcon_numcards = ((MCI_HCON>>1) & 0x1F) + 1;
     int card_mask = (1 << hcon_numcards) - 1;
+    int pwr_mask = card_mask;
+#ifdef SANSA_FUZEV2
+    if (model == 1)
+        pwr_mask = 2;
+#endif

-    MCI_PWREN &= ~card_mask;            /*  power off all cards  */
+    MCI_PWREN &= ~pwr_mask;             /*  power off all cards  */

     MCI_CLKSRC = 0x00;                  /* All CLK_SRC_CRD set to 0*/
     MCI_CLKDIV = 0x00;                  /* CLK_DIV_0 : bits 7:0  */

-    MCI_PWREN |= card_mask;             /*  power up cards  */
+    MCI_PWREN |= pwr_mask;              /*  power up cards  */
     mci_delay();

     MCI_CTRL |= CTRL_RESET;