077ef70b0c
* arch: cxd56xx: Add size limitation for I2C SCU xfer This is a fw restriction, unroll loop because it can be transfer up to 16 bytes. * arch: cxd56xx: Fix lack of leave_critical_section add the missing leave_critical_section * arch: cxd56xx: Remove unnecessary file this header is duplicate and we can remove it * arch: cxd56xx: Cosmetic change remove space after function * arch: cxd56xx: update topreg registers the topreg registers are updated to match the cxd5602 HW * arch: cxd56xx: Add voltage setting for low battery notification Add voltage setting for low battery notification * arch: cxd56xx: Improve perfomance of SD card Improve a problem that the clock of SD Host Controller is lower than the expected value in SDR25 transfer mode. * arch: cxd56xx: Cosmetic changes cleanup to comply with coding standard * boards: cxd56xx: Cosmetic changes updates to comply with coding standard * boards: cxd56xx: Fix SD card cannot mount issue SD card cannot mount when connecting and disconnecting three times or more due to wrong state of parameter 'initialized'. This change enables to skip swtching initialized state when mount failed.
230 lines
6.6 KiB
C
230 lines
6.6 KiB
C
/***************************************************************************
|
|
* boards/arm/cxd56xx/drivers/audio/cxd56_audio_mic.c
|
|
*
|
|
* Copyright 2018 Sony Semiconductor Solutions Corporation
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
*
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in
|
|
* the documentation and/or other materials provided with the
|
|
* distribution.
|
|
* 3. Neither the name of Sony Semiconductor Solutions Corporation nor
|
|
* the names of its contributors may be used to endorse or promote
|
|
* products derived from this software without specific prior written
|
|
* permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
****************************************************************************/
|
|
|
|
/***************************************************************************
|
|
* Included Files
|
|
****************************************************************************/
|
|
|
|
#include <nuttx/config.h>
|
|
#include <arch/chip/audio.h>
|
|
|
|
#include "cxd56_audio_config.h"
|
|
#include "cxd56_audio_mic.h"
|
|
#include "cxd56_audio_ac_reg.h"
|
|
|
|
/***************************************************************************
|
|
* Pre-processor Definitions
|
|
****************************************************************************/
|
|
|
|
#define CIC_NUM 4
|
|
#define CIC_MIC_CH_NUM 2
|
|
|
|
#define MIC_CH_BITNUM 4
|
|
#define MIC_CH_BITMAP 0xf
|
|
|
|
/***************************************************************************
|
|
* Public Function Prototypes
|
|
****************************************************************************/
|
|
|
|
/***************************************************************************
|
|
* Private Data
|
|
****************************************************************************/
|
|
|
|
/***************************************************************************
|
|
* Public Data
|
|
****************************************************************************/
|
|
|
|
/***************************************************************************
|
|
* Private Functions
|
|
****************************************************************************/
|
|
|
|
/***************************************************************************
|
|
* Public Functions
|
|
****************************************************************************/
|
|
|
|
CXD56_AUDIO_ECODE cxd56_audio_mic_enable(FAR cxd56_audio_mic_gain_t *gain)
|
|
{
|
|
CXD56_AUDIO_ECODE ret = CXD56_AUDIO_ECODE_OK;
|
|
uint8_t mic_num;
|
|
uint8_t cic_num;
|
|
uint8_t mic_sel;
|
|
uint8_t mic_mode;
|
|
uint32_t mic_map;
|
|
cxd56_audio_mic_gain_t cic_gain;
|
|
cxd56_audio_clkmode_t clk_mode;
|
|
uint8_t i;
|
|
|
|
/* Get mic number. */
|
|
|
|
mic_num = cxd56_audio_config_get_micnum();
|
|
|
|
/* Get CIC filter number. */
|
|
|
|
cic_num = (mic_num + 1) / CIC_MIC_CH_NUM;
|
|
|
|
/* Get mic mode. */
|
|
|
|
mic_mode = cxd56_audio_config_get_micmode();
|
|
|
|
/* Set cic gain. */
|
|
|
|
mic_map = cxd56_audio_config_get_micmap();
|
|
|
|
for (i = 0; i < CXD56_AUDIO_MIC_CH_MAX; i++)
|
|
{
|
|
mic_sel = (mic_map >> (i * MIC_CH_BITNUM)) &
|
|
MIC_CH_BITMAP;
|
|
if ((mic_sel >= 1) && (mic_sel <= 4))
|
|
{
|
|
cic_gain.gain[i] = 0;
|
|
}
|
|
else
|
|
{
|
|
cic_gain.gain[i] = gain->gain[i];
|
|
}
|
|
}
|
|
|
|
ret = cxd56_audio_ac_reg_poweron_cic(CXD56_AUDIO_CFG_CIC_IN,
|
|
mic_mode,
|
|
cic_num,
|
|
&cic_gain);
|
|
if (CXD56_AUDIO_ECODE_OK != ret)
|
|
{
|
|
return ret;
|
|
}
|
|
|
|
clk_mode = cxd56_audio_config_get_clkmode();
|
|
ret = cxd56_audio_ac_reg_poweron_decim(mic_mode, clk_mode);
|
|
if (CXD56_AUDIO_ECODE_OK != ret)
|
|
{
|
|
return ret;
|
|
}
|
|
|
|
return ret;
|
|
}
|
|
|
|
CXD56_AUDIO_ECODE cxd56_audio_mic_disable(void)
|
|
{
|
|
/* Disable DECIM. */
|
|
|
|
cxd56_audio_ac_reg_poweroff_decim();
|
|
|
|
/* Power off CIC. */
|
|
|
|
cxd56_audio_ac_reg_poweroff_cic();
|
|
|
|
return CXD56_AUDIO_ECODE_OK;
|
|
}
|
|
|
|
CXD56_AUDIO_ECODE cxd56_audio_mic_set_gain(FAR cxd56_audio_mic_gain_t *gain)
|
|
{
|
|
CXD56_AUDIO_ECODE ret = CXD56_AUDIO_ECODE_OK;
|
|
uint8_t mic_num;
|
|
uint8_t cic_num;
|
|
uint8_t mic_sel;
|
|
uint32_t mic_map;
|
|
cxd56_audio_mic_gain_t cic_gain;
|
|
uint8_t i;
|
|
|
|
/* Get mic number. */
|
|
|
|
mic_num = cxd56_audio_config_get_micnum();
|
|
|
|
/* Get CIC filter number. */
|
|
|
|
cic_num = (mic_num + 1) / CIC_MIC_CH_NUM;
|
|
|
|
/* Set cic gain. */
|
|
|
|
mic_map = cxd56_audio_config_get_micmap();
|
|
|
|
for (i = 0; i < CXD56_AUDIO_MIC_CH_MAX; i++)
|
|
{
|
|
mic_sel = (mic_map >> (i * MIC_CH_BITNUM)) &
|
|
MIC_CH_BITMAP;
|
|
if ((mic_sel >= 1) && (mic_sel <= 4))
|
|
{
|
|
cic_gain.gain[i] = 0;
|
|
}
|
|
else
|
|
{
|
|
cic_gain.gain[i] = gain->gain[i];
|
|
}
|
|
}
|
|
|
|
cxd56_audio_ac_reg_set_cicgain(cic_num, &cic_gain);
|
|
|
|
return ret;
|
|
}
|
|
|
|
CXD56_AUDIO_ECODE cxd56_audio_mic_set_seloutch(uint8_t dma_mic_num,
|
|
cxd56_audio_samp_fmt_t format)
|
|
{
|
|
uint8_t i;
|
|
cxd56_audio_ac_reg_seloutch_t seloutch;
|
|
|
|
if ((format == CXD56_AUDIO_SAMP_FMT_16) &&
|
|
(CXD56_AUDIO_CFG_DMA_FORMAT == CXD56_AUDIO_CFG_DMA_FORMAT_RL))
|
|
{
|
|
for (i = 0; i < CXD56_AUDIO_MIC_CH_MAX; i++)
|
|
{
|
|
seloutch.ch[i] = (i & 1) ? i - 1 : i + 1;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
for (i = 0; i < CXD56_AUDIO_MIC_CH_MAX; i++)
|
|
{
|
|
seloutch.ch[i] = i;
|
|
}
|
|
}
|
|
|
|
if ((format == CXD56_AUDIO_SAMP_FMT_16) && ((dma_mic_num & 1) == 1))
|
|
{
|
|
if (CXD56_AUDIO_CFG_DMA_FORMAT == CXD56_AUDIO_CFG_DMA_FORMAT_LR)
|
|
{
|
|
seloutch.ch[dma_mic_num] = seloutch.ch[dma_mic_num - 1];
|
|
}
|
|
else
|
|
{
|
|
seloutch.ch[dma_mic_num - 1] = seloutch.ch[dma_mic_num];
|
|
}
|
|
}
|
|
|
|
cxd56_audio_ac_reg_set_seloutch(&seloutch);
|
|
|
|
return CXD56_AUDIO_ECODE_OK;
|
|
}
|