summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2013-06-18 16:11:51 +0200
committerAmaury Pouly <amaury.pouly@gmail.com>2013-06-18 16:11:51 +0200
commite735ce4693f85dc2ecb5d7290d1298f8b12c1e27 (patch)
tree891a0e103fcfa8aa01970d70a7c09961f2a26f34
parentd8368d58b0bd073ef6bed6a7b7d51c671b8ea4ae (diff)
downloadrockbox-e735ce4693f85dc2ecb5d7290d1298f8b12c1e27.zip
rockbox-e735ce4693f85dc2ecb5d7290d1298f8b12c1e27.tar.gz
rockbox-e735ce4693f85dc2ecb5d7290d1298f8b12c1e27.tar.bz2
rockbox-e735ce4693f85dc2ecb5d7290d1298f8b12c1e27.tar.xz
imx233: introduce generic audio routing driver
Change-Id: Icd439e02dd9835778d2733fc01a9306552b36966
-rw-r--r--firmware/target/arm/imx233/audio-imx233.c130
-rw-r--r--firmware/target/arm/imx233/audio-imx233.h48
2 files changed, 178 insertions, 0 deletions
diff --git a/firmware/target/arm/imx233/audio-imx233.c b/firmware/target/arm/imx233/audio-imx233.c
new file mode 100644
index 0000000..54b1784
--- /dev/null
+++ b/firmware/target/arm/imx233/audio-imx233.c
@@ -0,0 +1,130 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2013 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#include "audiohw.h"
+#include "audio-imx233.h"
+#include "pinctrl-imx233.h"
+
+void __attribute__((weak)) imx233_audio_preinit(void)
+{
+#ifdef IMX233_AUDIO_HP_GATE_BANK
+ imx233_pinctrl_acquire(IMX233_AUDIO_HP_GATE_BANK, IMX233_AUDIO_HP_GATE_PIN, "hp_gate");
+ imx233_pinctrl_set_function(IMX233_AUDIO_HP_GATE_BANK, IMX233_AUDIO_HP_GATE_PIN, PINCTRL_FUNCTION_GPIO);
+ imx233_pinctrl_enable_gpio(IMX233_AUDIO_HP_GATE_BANK, IMX233_AUDIO_HP_GATE_PIN, true);
+ imx233_audio_enable_hp(false);
+#endif
+#ifdef IMX233_AUDIO_SPKR_GATE_BANK
+ imx233_pinctrl_acquire(IMX233_AUDIO_SPKR_GATE_BANK, IMX233_AUDIO_SPKR_GATE_PIN, "spkr_gate");
+ imx233_pinctrl_set_function(IMX233_AUDIO_SPKR_GATE_BANK, IMX233_AUDIO_SPKR_GATE_PIN, PINCTRL_FUNCTION_GPIO);
+ imx233_pinctrl_enable_gpio(IMX233_AUDIO_SPKR_GATE_BANK, IMX233_AUDIO_SPKR_GATE_PIN, true);
+ imx233_audio_enable_spkr(false);
+#endif
+}
+
+void __attribute__((weak)) imx233_audio_postinit(void)
+{
+ imx233_audio_enable_hp(true);
+}
+// enable/disable the HP audio gate (typically using a GPIO)
+void __attribute__((weak)) imx233_audio_enable_hp(bool en)
+{
+#ifdef IMX233_AUDIO_HP_GATE_BANK
+# ifdef IMX233_AUDIO_HP_GATE_INVERTED
+ en = !en;
+# endif
+ imx233_pinctrl_set_gpio(IMX233_AUDIO_HP_GATE_BANK, IMX233_AUDIO_HP_GATE_PIN, en);
+#else
+ (void) en;
+#endif
+}
+// enable/disable the speaker audio gate (typically using a GPIO)
+void __attribute__((weak)) imx233_audio_enable_spkr(bool en)
+{
+#ifdef IMX233_AUDIO_SPKR_GATE_BANK
+# ifdef IMX233_AUDIO_SPKR_GATE_INVERTED
+ en = !en;
+# endif
+ imx233_pinctrl_set_gpio(IMX233_AUDIO_SPKR_GATE_BANK, IMX233_AUDIO_SPKR_GATE_PIN, en);
+#else
+ (void) en;
+#endif
+}
+
+static int input_source = AUDIO_SRC_PLAYBACK;
+static unsigned input_flags = 0;
+static int output_source = AUDIO_SRC_PLAYBACK;
+
+static void select_audio_path(void)
+{
+#if defined(HAVE_RECORDING)
+ const bool recording = input_flags & SRCF_RECORDING;
+#else
+ const bool recording = false;
+#endif
+
+ switch(input_source)
+ {
+ default:
+ /* playback and no recording */
+ input_source = AUDIO_SRC_PLAYBACK;
+ /* fallthrough */
+ case AUDIO_SRC_PLAYBACK:
+ audiohw_set_monitor(false);
+ audiohw_disable_recording();
+ break;
+
+#if defined(HAVE_RECORDING) && (INPUT_SRC_CAPS & SRC_CAP_MIC)
+ /* recording only */
+ case AUDIO_SRC_MIC:
+ audiohw_set_monitor(false);
+ audiohw_enable_recording(true);
+ break;
+#endif
+
+#if (INPUT_SRC_CAPS & SRC_CAP_FMRADIO)
+ /* recording and playback */
+ case AUDIO_SRC_FMRADIO:
+ if (recording)
+ {
+ audiohw_set_monitor(false);
+ audiohw_enable_recording(false);
+ }
+ else
+ {
+ audiohw_disable_recording();
+ audiohw_set_monitor(true); /* line 2 analog audio path */
+ }
+ break;
+#endif /* (INPUT_SRC_CAPS & SRC_CAP_FMRADIO) */
+ }
+}
+
+void __attribute__((weak)) audio_input_mux(int source, unsigned flags)
+{
+ input_source = source;
+ input_flags = flags;
+ select_audio_path();
+}
+
+void __attribute__((weak)) audio_set_output_source(int source)
+{
+ output_source = source;
+ select_audio_path();
+}
diff --git a/firmware/target/arm/imx233/audio-imx233.h b/firmware/target/arm/imx233/audio-imx233.h
new file mode 100644
index 0000000..dd0cdeb
--- /dev/null
+++ b/firmware/target/arm/imx233/audio-imx233.h
@@ -0,0 +1,48 @@
+/***************************************************************************
+ * __________ __ ___.
+ * Open \______ \ ____ ____ | | _\_ |__ _______ ___
+ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
+ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
+ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
+ * \/ \/ \/ \/ \/
+ * $Id$
+ *
+ * Copyright (C) 2013 by Amaury Pouly
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
+ * KIND, either express or implied.
+ *
+ ****************************************************************************/
+#ifndef __audio_imx233__
+#define __audio_imx233__
+
+#include "audio.h"
+#include "audio-target.h"
+
+/* target can override those functions to provide hooks to the audio code
+ * alternativelly, the default implementation provide support for GPIO
+ * controlled gates using the following defines
+ * NOTE by default gates are enabled by setting GPIO to 1 (except if inverted)
+ *
+ * IMX233_AUDIO_HP_GATE_BANK (gpio bank)
+ * IMX233_AUDIO_HP_GATE_PIN (gpio pin)
+ * IMX233_AUDIO_HP_GATE_INVERTED (define if inverted)
+ *
+ * IMX233_AUDIO_SPKR_GATE_BANK (gpio bank)
+ * IMX233_AUDIO_SPKR_GATE_PIN (gpio pin)
+ * IMX233_AUDIO_SPKR_GATE_INVERTED (define if inverted)
+ */
+// do some initialisation related to next functions
+void imx233_audio_preinit(void);
+void imx233_audio_postinit(void);
+// enable/disable the HP audio gate (typically using a GPIO)
+void imx233_audio_enable_hp(bool en);
+// enable/disable the speaker audio gate (typically using a GPIO)
+void imx233_audio_enable_spkr(bool en);
+
+#endif /* __audio_imx233__ */ \ No newline at end of file