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
diff --git a/rbutil/mkamsboot/dualboot/dualboot.S b/rbutil/mkamsboot/dualboot/dualboot.S
index 309aa67..4a4e87f 100644
--- a/rbutil/mkamsboot/dualboot/dualboot.S
+++ b/rbutil/mkamsboot/dualboot/dualboot.S
@@ -102,7 +102,7 @@ uclcopy:
 /* TODO : M200V4 ? */
 #if defined(SANSA_CLIP) || defined(SANSA_CLIPV2)
 #define USB_PIN 6
-#elif defined(SANSA_FUZE) || defined(SANSA_E200V2) || defined(SANSA_FUZEV2)
+#elif defined(SANSA_FUZE) || defined(SANSA_E200V2)
 #define USB_PIN 3
 #endif

@@ -214,19 +214,85 @@ uclcopy:

         cmp     r1, #0
         beq     boot_of
-#elif defined(SANSA_E200V2) || defined(SANSA_FUZE) || defined(SANSA_FUZEV2)
+#elif defined(SANSA_E200V2) || defined(SANSA_FUZE)
         ldr     r0, =GPIOC
         mov     r1, #0
         str     r1, [r0, #0x400]
         ldr     r1, [r0, #0x20]    /* read pin C3 */

         cmp     r1, #0             /* C3 = #0 means button pressed */
-#ifdef SANSA_FUZEV2
-        /* the logic is reversed on the fuzev2 */
-        bne     boot_of
-#else
         beq     boot_of
-#endif /* SANSA_FUZEV2 */
+
+#elif defined(SANSA_FUZEV2)
+        ldr     r0, =GPIOC
+        mov     r1, #0
+        str     r1, [r0, #0x400]
+        ldr     r1, [r0, #0x20]    /* read pin C3 */
+
+        cmp     r1, #0             /* C3 != #0 means button pressed */
+        bne     boot_of
+
+
+        @ check USB connection
+
+        ldr     r0, =CGU_PROC
+        mov     r1, #0
+        str     r1, [r0]    @ fclk = 24MHz
+
+        ldr     r0, =CGU_PERI
+        ldr     r1, [r0]
+        /* enable i2c audio master clock */
+        orr     r1, r1, #(1<<17)
+        /* pclk = fclk = 24MHz */
+        bic     r1, r1, #0x7f
+        str     r1, [r0]
+
+        ldr     r0, =I2C_BASE
+        /* disable i2c interrupts */
+        mov     r1, #0
+        str     r1, [r0, #I2C_IMR]
+        /* setup prescaler */
+        mov     r1, #I2C_PRESCALER_LOW
+        str     r1, [r0, #I2C_CPSR0]
+        mov     r1, #I2C_PRESCALER_HIGH
+        str     r1, [r0, #I2C_CPSR1]
+        /* setup i2c slave address */
+        mov     r1, #(AS3514_I2C_ADDR << 1)
+        str     r1, [r0, #I2C_SLAD0]
+        mov     r2, #0x51
+        str     r2, [r0, #I2C_CNTRL]
+
+        /* wait for not busy */
+1:
+        ldr     r1, [r0, #I2C_SR]
+        tst     r1, #1
+        bne 1b
+
+        /* wait a bit (~100ms) else detection fails */
+        mov     r1, #0x80000
+1:      subs    r1, r1, #1
+        bne 1b
+
+        /* start read of irq_enrd0 */
+        mov     r1, #AS3514_IRQ_ENRD0
+        str     r1, [r0, #I2C_SADDR]
+        orr     r2, r2, #(1 << 1)
+        str     r2, [r0, #I2C_CNTRL]
+        mov     r1, #1
+        str     r1, [r0, #I2C_DACNT]
+
+        /* wait for transfer to finish */
+1:
+        ldr     r1, [r0, #I2C_DACNT]
+        cmp     r1, #0
+        bne     1b
+
+        /* load result and test USB_STATUS bit */
+        ldr     r1, [r0, #I2C_DATA]
+        tst     r1, #(1 << 3)
+        bne     boot_of
+
+

 #elif defined(SANSA_CLIPPLUS)
         @ read pins