imx233: add the possibility to choose audio output coupling mode
via target-defined option

Change-Id: I1bffbc7f17a11cf690a771057c2e4a7ba6a5faaa
Reviewed-on: http://gerrit.rockbox.org/678
Reviewed-by: Amaury Pouly <amaury.pouly@gmail.com>
diff --git a/firmware/target/arm/imx233/audioout-imx233.c b/firmware/target/arm/imx233/audioout-imx233.c
index b27f7b3..26a480d 100644
--- a/firmware/target/arm/imx233/audioout-imx233.c
+++ b/firmware/target/arm/imx233/audioout-imx233.c
@@ -23,6 +23,15 @@
 #include "rtc-imx233.h"
 #include "pcm_sampr.h"
 #include "string.h"
+#include "audio-target.h"
+
+#ifndef IMX233_AUDIO_COUPLING_MODE
+#error You must define IMX233_AUDIO_COUPLING_MODE
+#endif
+
+#if IMX233_AUDIO_COUPLING_MODE != ACM_CAP && IMX233_AUDIO_COUPLING_MODE != ACM_CAPLESS
+#error Invalid value for IMX233_AUDIO_COUPLING_MODE
+#endif
 
 static int hp_vol_l, hp_vol_r;
 static bool input_line1;
@@ -46,7 +55,11 @@
     /* Enable DAC */
     BF_CLR(AUDIOOUT_ANACLKCTRL, CLKGATE);
     /* Set capless mode */
+#if IMX233_AUDIO_COUPLING_MODE == ACM_CAP
+    BF_SET(AUDIOOUT_PWRDN, CAPLESS);
+#else
     BF_CLR(AUDIOOUT_PWRDN, CAPLESS);
+#endif
     /* Set word-length to 16-bit */
     BF_SET(AUDIOOUT_CTRL, WORD_LENGTH);
     /* Power up DAC */
diff --git a/firmware/target/arm/imx233/audioout-imx233.h b/firmware/target/arm/imx233/audioout-imx233.h
index b5c1676..88163e7 100644
--- a/firmware/target/arm/imx233/audioout-imx233.h
+++ b/firmware/target/arm/imx233/audioout-imx233.h
@@ -27,6 +27,14 @@
 
 #include "regs/regs-audioout.h"
 
+/* target-defined output stage coupling method
+ * its setting is IMX233_AUDIO_COUPLING_MODE and must be set for every target
+ * Use ACM_CAP if output stage (i.e. headphones) have output capacitors,
+ * ACM_CAPLESS (DC-coupled) otherwise.
+ */
+#define ACM_CAPLESS    0
+#define ACM_CAP        1
+
 struct imx233_audioout_info_t
 {
     // NOTE there is a convention here: dac -> dacvol -> dacmute
diff --git a/firmware/target/arm/imx233/creative-zen/audio-target.h b/firmware/target/arm/imx233/creative-zen/audio-target.h
index 4ee2e2f..1925392 100644
--- a/firmware/target/arm/imx233/creative-zen/audio-target.h
+++ b/firmware/target/arm/imx233/creative-zen/audio-target.h
@@ -21,5 +21,7 @@
 #ifndef __audio_target__
 #define __audio_target__
 
+#define IMX233_AUDIO_COUPLING_MODE ACM_CAPLESS
+
 #endif /* __audio_target__ */
  
diff --git a/firmware/target/arm/imx233/creative-zenxfi2/audio-target.h b/firmware/target/arm/imx233/creative-zenxfi2/audio-target.h
index afa3d96..59e8fd6 100644
--- a/firmware/target/arm/imx233/creative-zenxfi2/audio-target.h
+++ b/firmware/target/arm/imx233/creative-zenxfi2/audio-target.h
@@ -21,4 +21,6 @@
 #ifndef __audio_target__
 #define __audio_target__
 
+#define IMX233_AUDIO_COUPLING_MODE ACM_CAPLESS
+
 #endif /* __audio_target__ */
diff --git a/firmware/target/arm/imx233/creative-zenxfi3/audio-target.h b/firmware/target/arm/imx233/creative-zenxfi3/audio-target.h
index 0b4610c..bdb6b4a 100644
--- a/firmware/target/arm/imx233/creative-zenxfi3/audio-target.h
+++ b/firmware/target/arm/imx233/creative-zenxfi3/audio-target.h
@@ -27,4 +27,6 @@
 #define IMX233_AUDIO_SPKR_GATE_BANK 1
 #define IMX233_AUDIO_SPKR_GATE_PIN  22
 
+#define IMX233_AUDIO_COUPLING_MODE ACM_CAPLESS
+
 #endif /* __audio_target__ */
diff --git a/firmware/target/arm/imx233/sansa-fuzeplus/audio-target.h b/firmware/target/arm/imx233/sansa-fuzeplus/audio-target.h
index afa3d96..59e8fd6 100644
--- a/firmware/target/arm/imx233/sansa-fuzeplus/audio-target.h
+++ b/firmware/target/arm/imx233/sansa-fuzeplus/audio-target.h
@@ -21,4 +21,6 @@
 #ifndef __audio_target__
 #define __audio_target__
 
+#define IMX233_AUDIO_COUPLING_MODE ACM_CAPLESS
+
 #endif /* __audio_target__ */
diff --git a/firmware/target/arm/imx233/sony-nwz/audio-target.h b/firmware/target/arm/imx233/sony-nwz/audio-target.h
index afa3d96..59e8fd6 100644
--- a/firmware/target/arm/imx233/sony-nwz/audio-target.h
+++ b/firmware/target/arm/imx233/sony-nwz/audio-target.h
@@ -21,4 +21,6 @@
 #ifndef __audio_target__
 #define __audio_target__
 
+#define IMX233_AUDIO_COUPLING_MODE ACM_CAPLESS
+
 #endif /* __audio_target__ */