mirror of
https://github.com/Rockbox/rockbox.git
synced 2025-11-09 21:22:39 -05:00
imx233: introduce generic audio routing driver
Change-Id: Icd439e02dd9835778d2733fc01a9306552b36966
This commit is contained in:
parent
d8368d58b0
commit
e735ce4693
2 changed files with 178 additions and 0 deletions
130
firmware/target/arm/imx233/audio-imx233.c
Normal file
130
firmware/target/arm/imx233/audio-imx233.c
Normal file
|
|
@ -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();
|
||||||
|
}
|
||||||
48
firmware/target/arm/imx233/audio-imx233.h
Normal file
48
firmware/target/arm/imx233/audio-imx233.h
Normal file
|
|
@ -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__ */
|
||||||
Loading…
Add table
Add a link
Reference in a new issue