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