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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
Index: ascodec-as3525.c
===================================================================
--- ascodec-as3525.c  (revision 25304)
+++ ascodec-as3525.c  (working copy)
@@ -96,6 +96,7 @@
 static struct ascodec_request *req_head = NULL;
 static struct ascodec_request *req_tail = NULL;

+#if CONFIG_CPU == AS3525
 static struct wakeup adc_wkup;

 #ifdef DEBUG
@@ -107,7 +108,8 @@
 static int int_usb_remove = 0;
 static int int_rtc = 0;
 static int int_adc = 0;
-#endif
+#endif /* DEBUG */
+#endif /* CONFIG_CPU == AS3525 */

 static struct ascodec_request as_audio_req;

@@ -116,6 +118,7 @@
 static void ascodec_finish_req(struct ascodec_request *req);
 static void ascodec_read_cb(unsigned const char *data, unsigned int len);

+#if CONFIG_CPU == AS3525
 void INT_AUDIO(void)
 {
     VIC_INT_EN_CLEAR = INTERRUPT_AUDIO;
@@ -123,6 +126,7 @@

     ascodec_async_read(AS3514_IRQ_ENRD0, 3, &as_audio_req, ascodec_read_cb);
 }
+#endif /* CONFIG_CPU == AS3525 */

 void INT_I2C_AUDIO(void)
 {
@@ -162,7 +166,9 @@
     int prescaler;

     mutex_init(&as_mtx);
+#if CONFIG_CPU == AS3525
     wakeup_init(&adc_wkup);
+#endif

     /* enable clock */
     CGU_PERI |= CGU_I2C_AUDIO_MASTER_CLOCK_ENABLE;
@@ -423,6 +429,7 @@
     return i;
 }

+#if CONFIG_CPU == AS3525
 static void ascodec_read_cb(unsigned const char *data, unsigned int len)
 {
     if (len != 3) /* some error happened? */
@@ -465,6 +472,7 @@
 {
     wakeup_wait(&adc_wkup, TIMEOUT_BLOCK);
 }
+#endif /* CONFIG_CPU == AS3525 */


 void ascodec_enable_endofch_irq(void)
Index: ascodec-target.h
===================================================================
--- ascodec-target.h  (revision 25304)
+++ ascodec-target.h  (working copy)
@@ -28,7 +28,8 @@
 #ifndef SIMULATOR

 #include "as3514.h"
-#include "kernel.h" /* for struct wakeup */
+#include "kernel.h"       /* for struct wakeup */
+#include "clock-target.h" /* for AS3525_I2C_PRESCALER */

 /*  Charge Pump and Power management Settings  */
 #define AS314_CP_DCDC3_SETTING    \
@@ -70,8 +71,6 @@

 void ascodec_init(void);

-void ascodec_init_late(void);
-
 int ascodec_write(unsigned int index, unsigned int value);

 int ascodec_read(unsigned int index);
@@ -106,7 +105,14 @@

 void ascodec_unlock(void);

+#if CONFIG_CPU == AS3525
 void ascodec_wait_adc_finished(void);
+#else
+static inline void ascodec_wait_adc_finished(void)
+{
+    /* FIXME: Doesn't work yet on AS3525v2 */
+}
+#endif
 
 void ascodec_enable_endofch_irq(void);
 
Index: usb-target.h
===================================================================
--- usb-target.h  (revision 25304)
+++ usb-target.h  (working copy)
@@ -22,8 +22,10 @@
 #define USB_TARGET_H
 
 void usb_init_device(void);
+int usb_detect(void);
+#if CONFIG_CPU == AS3525
 void usb_insert_int(void);
 void usb_remove_int(void);
-int usb_detect(void);
+#endif /* CONFIG_CPU == AS3525 */
 
-#endif
+#endif /* USB_TARGET_H */
Index: usb-as3525.c
===================================================================
--- usb-as3525.c  (revision 25304)
+++ usb-as3525.c  (working copy)
@@ -29,7 +29,19 @@
 #include "power.h"
 #include "as3525.h"
 
+#if defined(SANSA_CLIP)
+#define USB_DETECT_PIN 6
+
+#elif defined(SANSA_FUZE) || defined(SANSA_E200V2)
+#define USB_DETECT_PIN 3
+
+#elif defined(SANSA_C200V2)
+#define USB_DETECT_PIN 1 /* only on one variant */
+#endif
+
+#if CONFIG_CPU == AS3525
 static int usb_status = USB_EXTRACTED;
+#endif
 
 void usb_enable(bool on)
 {
@@ -43,6 +55,14 @@
 #endif
 }
 
+void usb_init_device(void)
+{
+#ifdef USB_DETECT_PIN
+    GPIOA_DIR &= ~(1 << USB_DETECT_PIN); /* set as input */
+#endif
+}
+
+#if CONFIG_CPU == AS3525
 void usb_insert_int(void)
 {
     usb_status = USB_INSERTED;
@@ -53,11 +73,18 @@
     usb_status = USB_EXTRACTED;
 }
 
-void usb_init_device(void)
+int usb_detect(void)
 {
+    return usb_status;
 }
-
+#else
 int usb_detect(void)
 {
-    return usb_status;
+#ifdef USB_DETECT_PIN
+    if (GPIOA_PIN( USB_DETECT_PIN ))
+        return USB_INSERTED;
+    else
+#endif
+        return USB_EXTRACTED;
 }
+#endif