From e735ce4693f85dc2ecb5d7290d1298f8b12c1e27 Mon Sep 17 00:00:00 2001 From: Amaury Pouly Date: Tue, 18 Jun 2013 16:11:51 +0200 Subject: imx233: introduce generic audio routing driver Change-Id: Icd439e02dd9835778d2733fc01a9306552b36966 --- firmware/target/arm/imx233/audio-imx233.c | 130 ++++++++++++++++++++++++++++++ firmware/target/arm/imx233/audio-imx233.h | 48 +++++++++++ 2 files changed, 178 insertions(+) create mode 100644 firmware/target/arm/imx233/audio-imx233.c create mode 100644 firmware/target/arm/imx233/audio-imx233.h (limited to 'firmware') diff --git a/firmware/target/arm/imx233/audio-imx233.c b/firmware/target/arm/imx233/audio-imx233.c new file mode 100644 index 0000000000..54b1784cfa --- /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 0000000000..dd0cdeb63a --- /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 -- cgit v1.2.3