[alsa-devel] [PATCH 1/3] ASoC: mediatek: add sub dai to mtk_base_afe
In MediaTek SoC chip we have multiple DAI, such as I2S, ADDA, PCM, etc.
Organize each DAI in to one sub dai, with its dai driver, controls, widgets, routes.
add mtk_afe_combine_sub_dai() to combine dai driver from each DAI.
add mtk_afe_add_sub_dai_control() to register the control, widget, routes to component.
Signed-off-by: KaiChieh Chuang kaichieh.chuang@mediatek.com --- .../soc/mediatek/common/mtk-afe-platform-driver.c | 78 ++++++++++++++++++++++ .../soc/mediatek/common/mtk-afe-platform-driver.h | 5 ++ sound/soc/mediatek/common/mtk-base-afe.h | 18 +++++ 3 files changed, 101 insertions(+)
diff --git a/sound/soc/mediatek/common/mtk-afe-platform-driver.c b/sound/soc/mediatek/common/mtk-afe-platform-driver.c index 8966ee1..c449188 100644 --- a/sound/soc/mediatek/common/mtk-afe-platform-driver.c +++ b/sound/soc/mediatek/common/mtk-afe-platform-driver.c @@ -13,6 +13,84 @@ #include "mtk-afe-platform-driver.h" #include "mtk-base-afe.h"
+int mtk_afe_combine_sub_dai(struct mtk_base_afe *afe) +{ + struct snd_soc_dai_driver *sub_dai_drivers; + size_t num_dai_drivers = 0, dai_idx = 0; + int i; + + if (!afe->sub_dais) { + dev_err(afe->dev, "%s(), sub_dais == NULL\n", __func__); + return -EINVAL; + } + + /* calcualte total dai driver size */ + for (i = 0; i < afe->num_sub_dais; i++) { + if (afe->sub_dais[i].dai_drivers && + afe->sub_dais[i].num_dai_drivers != 0) + num_dai_drivers += afe->sub_dais[i].num_dai_drivers; + } + + dev_info(afe->dev, "%s(), num of dai %zd\n", __func__, num_dai_drivers); + + /* combine sub_dais */ + afe->num_dai_drivers = num_dai_drivers; + afe->dai_drivers = devm_kcalloc(afe->dev, + num_dai_drivers, + sizeof(struct snd_soc_dai_driver), + GFP_KERNEL); + if (!afe->dai_drivers) + return -ENOMEM; + + for (i = 0; i < afe->num_sub_dais; i++) { + if (afe->sub_dais[i].dai_drivers && + afe->sub_dais[i].num_dai_drivers != 0) { + sub_dai_drivers = afe->sub_dais[i].dai_drivers; + /* dai driver */ + memcpy(&afe->dai_drivers[dai_idx], + sub_dai_drivers, + afe->sub_dais[i].num_dai_drivers * + sizeof(struct snd_soc_dai_driver)); + dai_idx += afe->sub_dais[i].num_dai_drivers; + } + } + + return 0; +} + +int mtk_afe_add_sub_dai_control(struct snd_soc_component *component) +{ + struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component); + int i; + + if (!afe->sub_dais) { + dev_err(afe->dev, "%s(), sub_dais == NULL\n", __func__); + return -EINVAL; + } + + for (i = 0; i < afe->num_sub_dais; i++) { + if (afe->sub_dais[i].controls) + snd_soc_add_component_controls(component, + afe->sub_dais[i].controls, + afe->sub_dais[i].num_controls); + + if (afe->sub_dais[i].dapm_widgets) + snd_soc_dapm_new_controls(&component->dapm, + afe->sub_dais[i].dapm_widgets, + afe->sub_dais[i].num_dapm_widgets); + + if (afe->sub_dais[i].dapm_routes) + snd_soc_dapm_add_routes(&component->dapm, + afe->sub_dais[i].dapm_routes, + afe->sub_dais[i].num_dapm_routes); + } + + snd_soc_dapm_new_widgets(component->dapm.card); + + return 0; + +} + static snd_pcm_uframes_t mtk_afe_pcm_pointer (struct snd_pcm_substream *substream) { diff --git a/sound/soc/mediatek/common/mtk-afe-platform-driver.h b/sound/soc/mediatek/common/mtk-afe-platform-driver.h index 1c81d91..0c31fa4 100644 --- a/sound/soc/mediatek/common/mtk-afe-platform-driver.h +++ b/sound/soc/mediatek/common/mtk-afe-platform-driver.h @@ -12,5 +12,10 @@ #define AFE_PCM_NAME "mtk-afe-pcm" extern const struct snd_soc_component_driver mtk_afe_pcm_platform;
+struct mtk_base_afe; +struct snd_soc_component; + +int mtk_afe_combine_sub_dai(struct mtk_base_afe *afe); +int mtk_afe_add_sub_dai_control(struct snd_soc_component *component); #endif
diff --git a/sound/soc/mediatek/common/mtk-base-afe.h b/sound/soc/mediatek/common/mtk-base-afe.h index c2c5a6c..bcf562f0 100644 --- a/sound/soc/mediatek/common/mtk-base-afe.h +++ b/sound/soc/mediatek/common/mtk-base-afe.h @@ -48,6 +48,7 @@ struct mtk_base_irq_data { struct device; struct mtk_base_afe_memif; struct mtk_base_afe_irq; +struct mtk_base_afe_dai; struct regmap; struct snd_pcm_substream; struct snd_soc_dai; @@ -71,6 +72,11 @@ struct mtk_base_afe { struct mtk_base_afe_irq *irqs; int irqs_size;
+ struct mtk_base_afe_dai *sub_dais; + int num_sub_dais; + struct snd_soc_dai_driver *dai_drivers; + unsigned int num_dai_drivers; + const struct snd_pcm_hardware *mtk_afe_hardware; int (*memif_fs)(struct snd_pcm_substream *substream, unsigned int rate); @@ -94,5 +100,17 @@ struct mtk_base_afe_irq { int irq_occupyed; };
+struct mtk_base_afe_dai { + struct snd_soc_dai_driver *dai_drivers; + unsigned int num_dai_drivers; + + const struct snd_kcontrol_new *controls; + unsigned int num_controls; + const struct snd_soc_dapm_widget *dapm_widgets; + unsigned int num_dapm_widgets; + const struct snd_soc_dapm_route *dapm_routes; + unsigned int num_dapm_routes; +}; + #endif
Signed-off-by: KaiChieh Chuang kaichieh.chuang@mediatek.com --- sound/soc/mediatek/mt6797/Makefile | 6 +- sound/soc/mediatek/mt6797/mt6797-afe-common.h | 3 + sound/soc/mediatek/mt6797/mt6797-afe-pcm.c | 353 ----------------------- sound/soc/mediatek/mt6797/mt6797-dai-adda.c | 384 ++++++++++++++++++++++++++ 4 files changed, 392 insertions(+), 354 deletions(-) create mode 100644 sound/soc/mediatek/mt6797/mt6797-dai-adda.c
diff --git a/sound/soc/mediatek/mt6797/Makefile b/sound/soc/mediatek/mt6797/Makefile index 50fd50f..4cbdc4d 100644 --- a/sound/soc/mediatek/mt6797/Makefile +++ b/sound/soc/mediatek/mt6797/Makefile @@ -1,7 +1,11 @@ # SPDX-License-Identifier: GPL-2.0
# platform driver -snd-soc-mt6797-afe-objs := mt6797-afe-pcm.o mt6797-afe-clk.o +snd-soc-mt6797-afe-objs := \ + mt6797-afe-pcm.o \ + mt6797-afe-clk.o \ + mt6797-dai-adda.o + obj-$(CONFIG_SND_SOC_MT6797) += snd-soc-mt6797-afe.o
# machine driver diff --git a/sound/soc/mediatek/mt6797/mt6797-afe-common.h b/sound/soc/mediatek/mt6797/mt6797-afe-common.h index c1de3fc..d53654f 100644 --- a/sound/soc/mediatek/mt6797/mt6797-afe-common.h +++ b/sound/soc/mediatek/mt6797/mt6797-afe-common.h @@ -46,4 +46,7 @@ unsigned int mt6797_general_rate_transform(struct device *dev, unsigned int rate); unsigned int mt6797_rate_transform(struct device *dev, unsigned int rate, int aud_blk); + +/* dai register */ +int mt6797_dai_adda_register(struct mtk_base_afe *afe); #endif diff --git a/sound/soc/mediatek/mt6797/mt6797-afe-pcm.c b/sound/soc/mediatek/mt6797/mt6797-afe-pcm.c index 79a3551..c892b7f 100644 --- a/sound/soc/mediatek/mt6797/mt6797-afe-pcm.c +++ b/sound/soc/mediatek/mt6797/mt6797-afe-pcm.c @@ -158,206 +158,6 @@ static int mt6797_irq_fs(struct snd_pcm_substream *substream, unsigned int rate) return mt6797_general_rate_transform(afe->dev, rate); }
-/* ADDA BE DAIs */ -enum { - MTK_AFE_ADDA_DL_RATE_8K = 0, - MTK_AFE_ADDA_DL_RATE_11K = 1, - MTK_AFE_ADDA_DL_RATE_12K = 2, - MTK_AFE_ADDA_DL_RATE_16K = 3, - MTK_AFE_ADDA_DL_RATE_22K = 4, - MTK_AFE_ADDA_DL_RATE_24K = 5, - MTK_AFE_ADDA_DL_RATE_32K = 6, - MTK_AFE_ADDA_DL_RATE_44K = 7, - MTK_AFE_ADDA_DL_RATE_48K = 8, - MTK_AFE_ADDA_DL_RATE_96K = 9, - MTK_AFE_ADDA_DL_RATE_192K = 10, -}; - -enum { - MTK_AFE_ADDA_UL_RATE_8K = 0, - MTK_AFE_ADDA_UL_RATE_16K = 1, - MTK_AFE_ADDA_UL_RATE_32K = 2, - MTK_AFE_ADDA_UL_RATE_48K = 3, - MTK_AFE_ADDA_UL_RATE_96K = 4, - MTK_AFE_ADDA_UL_RATE_192K = 5, - MTK_AFE_ADDA_UL_RATE_48K_HD = 6, -}; - -static unsigned int adda_dl_rate_transform(struct mtk_base_afe *afe, - unsigned int rate) -{ - switch (rate) { - case 8000: - return MTK_AFE_ADDA_DL_RATE_8K; - case 11025: - return MTK_AFE_ADDA_DL_RATE_11K; - case 12000: - return MTK_AFE_ADDA_DL_RATE_12K; - case 16000: - return MTK_AFE_ADDA_DL_RATE_16K; - case 22050: - return MTK_AFE_ADDA_DL_RATE_22K; - case 24000: - return MTK_AFE_ADDA_DL_RATE_24K; - case 32000: - return MTK_AFE_ADDA_DL_RATE_32K; - case 44100: - return MTK_AFE_ADDA_DL_RATE_44K; - case 48000: - return MTK_AFE_ADDA_DL_RATE_48K; - case 96000: - return MTK_AFE_ADDA_DL_RATE_96K; - case 192000: - return MTK_AFE_ADDA_DL_RATE_192K; - default: - dev_warn(afe->dev, "%s(), rate %d invalid, use 48kHz!!!\n", - __func__, rate); - return MTK_AFE_ADDA_DL_RATE_48K; - } -} - -static unsigned int adda_ul_rate_transform(struct mtk_base_afe *afe, - unsigned int rate) -{ - switch (rate) { - case 8000: - return MTK_AFE_ADDA_UL_RATE_8K; - case 16000: - return MTK_AFE_ADDA_UL_RATE_16K; - case 32000: - return MTK_AFE_ADDA_UL_RATE_32K; - case 48000: - return MTK_AFE_ADDA_UL_RATE_48K; - case 96000: - return MTK_AFE_ADDA_UL_RATE_96K; - case 192000: - return MTK_AFE_ADDA_UL_RATE_192K; - default: - dev_warn(afe->dev, "%s(), rate %d invalid, use 48kHz!!!\n", - __func__, rate); - return MTK_AFE_ADDA_UL_RATE_48K; - } -} - -static int mtk_dai_adda_hw_params(struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *params, - struct snd_soc_dai *dai) -{ - struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_component *component = - snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); - struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component); - unsigned int rate = params_rate(params); - - dev_dbg(afe->dev, "%s(), id %d, stream %d, rate %d\n", - __func__, dai->id, substream->stream, rate); - - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { - unsigned int dl_src2_con0 = 0; - unsigned int dl_src2_con1 = 0; - - /* clean predistortion */ - regmap_write(afe->regmap, AFE_ADDA_PREDIS_CON0, 0); - regmap_write(afe->regmap, AFE_ADDA_PREDIS_CON1, 0); - - /* set input sampling rate */ - dl_src2_con0 = adda_dl_rate_transform(afe, rate) << 28; - - /* set output mode */ - switch (rate) { - case 192000: - dl_src2_con0 |= (0x1 << 24); /* UP_SAMPLING_RATE_X2 */ - dl_src2_con0 |= 1 << 14; - break; - case 96000: - dl_src2_con0 |= (0x2 << 24); /* UP_SAMPLING_RATE_X4 */ - dl_src2_con0 |= 1 << 14; - break; - default: - dl_src2_con0 |= (0x3 << 24); /* UP_SAMPLING_RATE_X8 */ - break; - } - - /* turn off mute function */ - dl_src2_con0 |= (0x03 << 11); - - /* set voice input data if input sample rate is 8k or 16k */ - if (rate == 8000 || rate == 16000) - dl_src2_con0 |= 0x01 << 5; - - if (rate < 96000) { - /* SA suggest apply -0.3db to audio/speech path */ - dl_src2_con1 = 0xf74f0000; - } else { - /* SA suggest apply -0.3db to audio/speech path - * with DL gain set to half, - * 0xFFFF = 0dB -> 0x8000 = 0dB when 96k, 192k - */ - dl_src2_con1 = 0x7ba70000; - } - - /* turn on down-link gain */ - dl_src2_con0 = dl_src2_con0 | (0x01 << 1); - - regmap_write(afe->regmap, AFE_ADDA_DL_SRC2_CON0, dl_src2_con0); - regmap_write(afe->regmap, AFE_ADDA_DL_SRC2_CON1, dl_src2_con1); - } else { - unsigned int voice_mode = 0; - unsigned int ul_src_con0 = 0; /* default value */ - - /* Using Internal ADC */ - regmap_update_bits(afe->regmap, - AFE_ADDA_TOP_CON0, - 0x1 << 0, - 0x0 << 0); - - voice_mode = adda_ul_rate_transform(afe, rate); - - ul_src_con0 |= (voice_mode << 17) & (0x7 << 17); - - /* up8x txif sat on */ - regmap_write(afe->regmap, AFE_ADDA_NEWIF_CFG0, 0x03F87201); - - if (rate >= 96000) { /* hires */ - /* use hires format [1 0 23] */ - regmap_update_bits(afe->regmap, - AFE_ADDA_NEWIF_CFG0, - 0x1 << 5, - 0x1 << 5); - - regmap_update_bits(afe->regmap, - AFE_ADDA_NEWIF_CFG2, - 0xf << 28, - voice_mode << 28); - } else { /* normal 8~48k */ - /* use fixed 260k anc path */ - regmap_update_bits(afe->regmap, - AFE_ADDA_NEWIF_CFG2, - 0xf << 28, - 8 << 28); - - /* ul_use_cic_out */ - ul_src_con0 |= 0x1 << 20; - } - - regmap_update_bits(afe->regmap, - AFE_ADDA_NEWIF_CFG2, - 0xf << 28, - 8 << 28); - - regmap_update_bits(afe->regmap, - AFE_ADDA_UL_SRC_CON0, - 0xfffffffe, - ul_src_con0); - } - - return 0; -} - -static const struct snd_soc_dai_ops mtk_dai_adda_ops = { - .hw_params = mtk_dai_adda_hw_params, -}; - #define MTK_PCM_RATES (SNDRV_PCM_RATE_8000_48000 |\ SNDRV_PCM_RATE_88200 |\ SNDRV_PCM_RATE_96000 |\ @@ -372,21 +172,6 @@ static int mtk_dai_adda_hw_params(struct snd_pcm_substream *substream, SNDRV_PCM_FMTBIT_S24_LE |\ SNDRV_PCM_FMTBIT_S32_LE)
-#define MTK_ADDA_PLAYBACK_RATES (SNDRV_PCM_RATE_8000_48000 |\ - SNDRV_PCM_RATE_96000 |\ - SNDRV_PCM_RATE_192000) - -#define MTK_ADDA_CAPTURE_RATES (SNDRV_PCM_RATE_8000 |\ - SNDRV_PCM_RATE_16000 |\ - SNDRV_PCM_RATE_32000 |\ - SNDRV_PCM_RATE_48000 |\ - SNDRV_PCM_RATE_96000 |\ - SNDRV_PCM_RATE_192000) - -#define MTK_ADDA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\ - SNDRV_PCM_FMTBIT_S24_LE |\ - SNDRV_PCM_FMTBIT_S32_LE) - static struct snd_soc_dai_driver mt6797_afe_pcm_dais[] = { /* FE DAIs: memory intefaces to CPU */ { @@ -485,26 +270,6 @@ static int mtk_dai_adda_hw_params(struct snd_pcm_substream *substream, }, .ops = &mtk_afe_fe_ops, }, - /* BE DAIs */ - { - .name = "ADDA", - .id = MT6797_DAI_ADDA, - .playback = { - .stream_name = "ADDA Playback", - .channels_min = 1, - .channels_max = 2, - .rates = MTK_ADDA_PLAYBACK_RATES, - .formats = MTK_ADDA_FORMATS, - }, - .capture = { - .stream_name = "ADDA Capture", - .channels_min = 1, - .channels_max = 2, - .rates = MTK_ADDA_CAPTURE_RATES, - .formats = MTK_ADDA_FORMATS, - }, - .ops = &mtk_dai_adda_ops, - }, };
/* dma widget & routes*/ @@ -564,58 +329,6 @@ static int mtk_dai_adda_hw_params(struct snd_pcm_substream *substream, I_ADDA_UL_CH2, 1, 0), };
-static const struct snd_kcontrol_new mtk_adda_dl_ch1_mix[] = { - SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH1", AFE_CONN3, I_DL1_CH1, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH1", AFE_CONN3, I_DL2_CH1, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH1", AFE_CONN3, I_DL3_CH1, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH2", AFE_CONN3, - I_ADDA_UL_CH2, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH1", AFE_CONN3, - I_ADDA_UL_CH1, 1, 0), -}; - -static const struct snd_kcontrol_new mtk_adda_dl_ch2_mix[] = { - SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH1", AFE_CONN4, I_DL1_CH1, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH2", AFE_CONN4, I_DL1_CH2, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH1", AFE_CONN4, I_DL2_CH1, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH2", AFE_CONN4, I_DL2_CH2, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH1", AFE_CONN4, I_DL3_CH1, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH2", AFE_CONN4, I_DL3_CH2, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH2", AFE_CONN4, - I_ADDA_UL_CH2, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH1", AFE_CONN4, - I_ADDA_UL_CH1, 1, 0), -}; - -static int mtk_adda_ul_event(struct snd_soc_dapm_widget *w, - struct snd_kcontrol *kcontrol, - int event) -{ - struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); - struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt); - - dev_dbg(afe->dev, "%s(), name %s, event 0x%x\n", - __func__, w->name, event); - - switch (event) { - case SND_SOC_DAPM_POST_PMD: - /* should delayed 1/fs(smallest is 8k) = 125us before afe off */ - usleep_range(125, 135); - break; - default: - break; - } - - return 0; -} - -enum { - SUPPLY_SEQ_AUD_TOP_PDN, - SUPPLY_SEQ_ADDA_AFE_ON, - SUPPLY_SEQ_ADDA_DL_ON, - SUPPLY_SEQ_ADDA_UL_ON, -}; - static const struct snd_soc_dapm_widget mt6797_afe_pcm_widgets[] = { /* memif */ SND_SOC_DAPM_MIXER("UL1_CH1", SND_SOC_NOPM, 0, 0, @@ -640,42 +353,6 @@ enum { SND_SOC_DAPM_MIXER("UL_MONO_2_CH1", SND_SOC_NOPM, 0, 0, memif_ul_mono_2_mix, ARRAY_SIZE(memif_ul_mono_2_mix)), - - /* adda */ - SND_SOC_DAPM_MIXER("ADDA_DL_CH1", SND_SOC_NOPM, 0, 0, - mtk_adda_dl_ch1_mix, - ARRAY_SIZE(mtk_adda_dl_ch1_mix)), - SND_SOC_DAPM_MIXER("ADDA_DL_CH2", SND_SOC_NOPM, 0, 0, - mtk_adda_dl_ch2_mix, - ARRAY_SIZE(mtk_adda_dl_ch2_mix)), - - SND_SOC_DAPM_SUPPLY_S("ADDA Enable", SUPPLY_SEQ_ADDA_AFE_ON, - AFE_ADDA_UL_DL_CON0, ADDA_AFE_ON_SFT, 0, - NULL, 0), - - SND_SOC_DAPM_SUPPLY_S("ADDA Playback Enable", SUPPLY_SEQ_ADDA_DL_ON, - AFE_ADDA_DL_SRC2_CON0, - DL_2_SRC_ON_TMP_CTL_PRE_SFT, 0, - NULL, 0), - - SND_SOC_DAPM_SUPPLY_S("ADDA Capture Enable", SUPPLY_SEQ_ADDA_UL_ON, - AFE_ADDA_UL_SRC_CON0, - UL_SRC_ON_TMP_CTL_SFT, 0, - mtk_adda_ul_event, - SND_SOC_DAPM_POST_PMD), - - SND_SOC_DAPM_SUPPLY_S("aud_dac_clk", SUPPLY_SEQ_AUD_TOP_PDN, - AUDIO_TOP_CON0, PDN_DAC_SFT, 1, - NULL, 0), - SND_SOC_DAPM_SUPPLY_S("aud_dac_predis_clk", SUPPLY_SEQ_AUD_TOP_PDN, - AUDIO_TOP_CON0, PDN_DAC_PREDIS_SFT, 1, - NULL, 0), - - SND_SOC_DAPM_SUPPLY_S("aud_adc_clk", SUPPLY_SEQ_AUD_TOP_PDN, - AUDIO_TOP_CON0, PDN_ADC_SFT, 1, - NULL, 0), - - SND_SOC_DAPM_CLOCK_SUPPLY("mtkaif_26m_clk"), };
static const struct snd_soc_dapm_route mt6797_afe_pcm_routes[] = { @@ -702,36 +379,6 @@ enum { {"UL_MONO_2", NULL, "UL_MONO_2_CH1"}, {"UL_MONO_2_CH1", "ADDA_UL_CH1", "ADDA Capture"}, {"UL_MONO_2_CH1", "ADDA_UL_CH2", "ADDA Capture"}, - - /* playback */ - {"ADDA_DL_CH1", "DL1_CH1", "DL1"}, - {"ADDA_DL_CH2", "DL1_CH1", "DL1"}, - {"ADDA_DL_CH2", "DL1_CH2", "DL1"}, - - {"ADDA_DL_CH1", "DL2_CH1", "DL2"}, - {"ADDA_DL_CH2", "DL2_CH1", "DL2"}, - {"ADDA_DL_CH2", "DL2_CH2", "DL2"}, - - {"ADDA_DL_CH1", "DL3_CH1", "DL3"}, - {"ADDA_DL_CH2", "DL3_CH1", "DL3"}, - {"ADDA_DL_CH2", "DL3_CH2", "DL3"}, - - {"ADDA Playback", NULL, "ADDA_DL_CH1"}, - {"ADDA Playback", NULL, "ADDA_DL_CH2"}, - - /* adda enable */ - {"ADDA Playback", NULL, "ADDA Enable"}, - {"ADDA Playback", NULL, "ADDA Playback Enable"}, - {"ADDA Capture", NULL, "ADDA Enable"}, - {"ADDA Capture", NULL, "ADDA Capture Enable"}, - - /* clk */ - {"ADDA Playback", NULL, "mtkaif_26m_clk"}, - {"ADDA Playback", NULL, "aud_dac_clk"}, - {"ADDA Playback", NULL, "aud_dac_predis_clk"}, - - {"ADDA Capture", NULL, "mtkaif_26m_clk"}, - {"ADDA Capture", NULL, "aud_adc_clk"}, };
static const struct snd_soc_component_driver mt6797_afe_pcm_dai_component = { diff --git a/sound/soc/mediatek/mt6797/mt6797-dai-adda.c b/sound/soc/mediatek/mt6797/mt6797-dai-adda.c new file mode 100644 index 0000000..f38e35e --- /dev/null +++ b/sound/soc/mediatek/mt6797/mt6797-dai-adda.c @@ -0,0 +1,384 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// MediaTek ALSA SoC Audio DAI ADDA Control +// +// Copyright (c) 2018 MediaTek Inc. +// Author: KaiChieh Chuang kaichieh.chuang@mediatek.com + +#include <linux/regmap.h> +#include <linux/delay.h> +#include "mt6797-afe-common.h" +#include "mt6797-interconnection.h" +#include "mt6797-reg.h" + +enum { + MTK_AFE_ADDA_DL_RATE_8K = 0, + MTK_AFE_ADDA_DL_RATE_11K = 1, + MTK_AFE_ADDA_DL_RATE_12K = 2, + MTK_AFE_ADDA_DL_RATE_16K = 3, + MTK_AFE_ADDA_DL_RATE_22K = 4, + MTK_AFE_ADDA_DL_RATE_24K = 5, + MTK_AFE_ADDA_DL_RATE_32K = 6, + MTK_AFE_ADDA_DL_RATE_44K = 7, + MTK_AFE_ADDA_DL_RATE_48K = 8, + MTK_AFE_ADDA_DL_RATE_96K = 9, + MTK_AFE_ADDA_DL_RATE_192K = 10, +}; + +enum { + MTK_AFE_ADDA_UL_RATE_8K = 0, + MTK_AFE_ADDA_UL_RATE_16K = 1, + MTK_AFE_ADDA_UL_RATE_32K = 2, + MTK_AFE_ADDA_UL_RATE_48K = 3, + MTK_AFE_ADDA_UL_RATE_96K = 4, + MTK_AFE_ADDA_UL_RATE_192K = 5, + MTK_AFE_ADDA_UL_RATE_48K_HD = 6, +}; + +static unsigned int adda_dl_rate_transform(struct mtk_base_afe *afe, + unsigned int rate) +{ + switch (rate) { + case 8000: + return MTK_AFE_ADDA_DL_RATE_8K; + case 11025: + return MTK_AFE_ADDA_DL_RATE_11K; + case 12000: + return MTK_AFE_ADDA_DL_RATE_12K; + case 16000: + return MTK_AFE_ADDA_DL_RATE_16K; + case 22050: + return MTK_AFE_ADDA_DL_RATE_22K; + case 24000: + return MTK_AFE_ADDA_DL_RATE_24K; + case 32000: + return MTK_AFE_ADDA_DL_RATE_32K; + case 44100: + return MTK_AFE_ADDA_DL_RATE_44K; + case 48000: + return MTK_AFE_ADDA_DL_RATE_48K; + case 96000: + return MTK_AFE_ADDA_DL_RATE_96K; + case 192000: + return MTK_AFE_ADDA_DL_RATE_192K; + default: + dev_warn(afe->dev, "%s(), rate %d invalid, use 48kHz!!!\n", + __func__, rate); + return MTK_AFE_ADDA_DL_RATE_48K; + } +} + +static unsigned int adda_ul_rate_transform(struct mtk_base_afe *afe, + unsigned int rate) +{ + switch (rate) { + case 8000: + return MTK_AFE_ADDA_UL_RATE_8K; + case 16000: + return MTK_AFE_ADDA_UL_RATE_16K; + case 32000: + return MTK_AFE_ADDA_UL_RATE_32K; + case 48000: + return MTK_AFE_ADDA_UL_RATE_48K; + case 96000: + return MTK_AFE_ADDA_UL_RATE_96K; + case 192000: + return MTK_AFE_ADDA_UL_RATE_192K; + default: + dev_warn(afe->dev, "%s(), rate %d invalid, use 48kHz!!!\n", + __func__, rate); + return MTK_AFE_ADDA_UL_RATE_48K; + } +} + +/* dai component */ +static const struct snd_kcontrol_new mtk_adda_dl_ch1_mix[] = { + SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH1", AFE_CONN3, I_DL1_CH1, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH1", AFE_CONN3, I_DL2_CH1, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH1", AFE_CONN3, I_DL3_CH1, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH2", AFE_CONN3, + I_ADDA_UL_CH2, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH1", AFE_CONN3, + I_ADDA_UL_CH1, 1, 0), +}; + +static const struct snd_kcontrol_new mtk_adda_dl_ch2_mix[] = { + SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH1", AFE_CONN4, I_DL1_CH1, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH2", AFE_CONN4, I_DL1_CH2, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH1", AFE_CONN4, I_DL2_CH1, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH2", AFE_CONN4, I_DL2_CH2, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH1", AFE_CONN4, I_DL3_CH1, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH2", AFE_CONN4, I_DL3_CH2, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH2", AFE_CONN4, + I_ADDA_UL_CH2, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH1", AFE_CONN4, + I_ADDA_UL_CH1, 1, 0), +}; + +static int mtk_adda_ul_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, + int event) +{ + struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); + struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt); + + dev_dbg(afe->dev, "%s(), name %s, event 0x%x\n", + __func__, w->name, event); + + switch (event) { + case SND_SOC_DAPM_POST_PMD: + /* should delayed 1/fs(smallest is 8k) = 125us before afe off */ + usleep_range(125, 135); + break; + default: + break; + } + + return 0; +} + +enum { + SUPPLY_SEQ_AUD_TOP_PDN, + SUPPLY_SEQ_ADDA_AFE_ON, + SUPPLY_SEQ_ADDA_DL_ON, + SUPPLY_SEQ_ADDA_UL_ON, +}; + +static const struct snd_soc_dapm_widget mtk_dai_adda_widgets[] = { + /* adda */ + SND_SOC_DAPM_MIXER("ADDA_DL_CH1", SND_SOC_NOPM, 0, 0, + mtk_adda_dl_ch1_mix, + ARRAY_SIZE(mtk_adda_dl_ch1_mix)), + SND_SOC_DAPM_MIXER("ADDA_DL_CH2", SND_SOC_NOPM, 0, 0, + mtk_adda_dl_ch2_mix, + ARRAY_SIZE(mtk_adda_dl_ch2_mix)), + + SND_SOC_DAPM_SUPPLY_S("ADDA Enable", SUPPLY_SEQ_ADDA_AFE_ON, + AFE_ADDA_UL_DL_CON0, ADDA_AFE_ON_SFT, 0, + NULL, 0), + + SND_SOC_DAPM_SUPPLY_S("ADDA Playback Enable", SUPPLY_SEQ_ADDA_DL_ON, + AFE_ADDA_DL_SRC2_CON0, + DL_2_SRC_ON_TMP_CTL_PRE_SFT, 0, + NULL, 0), + + SND_SOC_DAPM_SUPPLY_S("ADDA Capture Enable", SUPPLY_SEQ_ADDA_UL_ON, + AFE_ADDA_UL_SRC_CON0, + UL_SRC_ON_TMP_CTL_SFT, 0, + mtk_adda_ul_event, + SND_SOC_DAPM_POST_PMD), + + SND_SOC_DAPM_SUPPLY_S("aud_dac_clk", SUPPLY_SEQ_AUD_TOP_PDN, + AUDIO_TOP_CON0, PDN_DAC_SFT, 1, + NULL, 0), + SND_SOC_DAPM_SUPPLY_S("aud_dac_predis_clk", SUPPLY_SEQ_AUD_TOP_PDN, + AUDIO_TOP_CON0, PDN_DAC_PREDIS_SFT, 1, + NULL, 0), + + SND_SOC_DAPM_SUPPLY_S("aud_adc_clk", SUPPLY_SEQ_AUD_TOP_PDN, + AUDIO_TOP_CON0, PDN_ADC_SFT, 1, + NULL, 0), + + SND_SOC_DAPM_CLOCK_SUPPLY("mtkaif_26m_clk"), +}; + +static const struct snd_soc_dapm_route mtk_dai_adda_routes[] = { + /* playback */ + {"ADDA_DL_CH1", "DL1_CH1", "DL1"}, + {"ADDA_DL_CH2", "DL1_CH1", "DL1"}, + {"ADDA_DL_CH2", "DL1_CH2", "DL1"}, + + {"ADDA_DL_CH1", "DL2_CH1", "DL2"}, + {"ADDA_DL_CH2", "DL2_CH1", "DL2"}, + {"ADDA_DL_CH2", "DL2_CH2", "DL2"}, + + {"ADDA_DL_CH1", "DL3_CH1", "DL3"}, + {"ADDA_DL_CH2", "DL3_CH1", "DL3"}, + {"ADDA_DL_CH2", "DL3_CH2", "DL3"}, + + {"ADDA Playback", NULL, "ADDA_DL_CH1"}, + {"ADDA Playback", NULL, "ADDA_DL_CH2"}, + + /* adda enable */ + {"ADDA Playback", NULL, "ADDA Enable"}, + {"ADDA Playback", NULL, "ADDA Playback Enable"}, + {"ADDA Capture", NULL, "ADDA Enable"}, + {"ADDA Capture", NULL, "ADDA Capture Enable"}, + + /* clk */ + {"ADDA Playback", NULL, "mtkaif_26m_clk"}, + {"ADDA Playback", NULL, "aud_dac_clk"}, + {"ADDA Playback", NULL, "aud_dac_predis_clk"}, + + {"ADDA Capture", NULL, "mtkaif_26m_clk"}, + {"ADDA Capture", NULL, "aud_adc_clk"}, +}; + +/* dai ops */ +static int mtk_dai_adda_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); + unsigned int rate = params_rate(params); + + dev_dbg(afe->dev, "%s(), id %d, stream %d, rate %d\n", + __func__, dai->id, substream->stream, rate); + + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + unsigned int dl_src2_con0 = 0; + unsigned int dl_src2_con1 = 0; + + /* clean predistortion */ + regmap_write(afe->regmap, AFE_ADDA_PREDIS_CON0, 0); + regmap_write(afe->regmap, AFE_ADDA_PREDIS_CON1, 0); + + /* set input sampling rate */ + dl_src2_con0 = adda_dl_rate_transform(afe, rate) << 28; + + /* set output mode */ + switch (rate) { + case 192000: + dl_src2_con0 |= (0x1 << 24); /* UP_SAMPLING_RATE_X2 */ + dl_src2_con0 |= 1 << 14; + break; + case 96000: + dl_src2_con0 |= (0x2 << 24); /* UP_SAMPLING_RATE_X4 */ + dl_src2_con0 |= 1 << 14; + break; + default: + dl_src2_con0 |= (0x3 << 24); /* UP_SAMPLING_RATE_X8 */ + break; + } + + /* turn off mute function */ + dl_src2_con0 |= (0x03 << 11); + + /* set voice input data if input sample rate is 8k or 16k */ + if (rate == 8000 || rate == 16000) + dl_src2_con0 |= 0x01 << 5; + + if (rate < 96000) { + /* SA suggest apply -0.3db to audio/speech path */ + dl_src2_con1 = 0xf74f0000; + } else { + /* SA suggest apply -0.3db to audio/speech path + * with DL gain set to half, + * 0xFFFF = 0dB -> 0x8000 = 0dB when 96k, 192k + */ + dl_src2_con1 = 0x7ba70000; + } + + /* turn on down-link gain */ + dl_src2_con0 = dl_src2_con0 | (0x01 << 1); + + regmap_write(afe->regmap, AFE_ADDA_DL_SRC2_CON0, dl_src2_con0); + regmap_write(afe->regmap, AFE_ADDA_DL_SRC2_CON1, dl_src2_con1); + } else { + unsigned int voice_mode = 0; + unsigned int ul_src_con0 = 0; /* default value */ + + /* Using Internal ADC */ + regmap_update_bits(afe->regmap, + AFE_ADDA_TOP_CON0, + 0x1 << 0, + 0x0 << 0); + + voice_mode = adda_ul_rate_transform(afe, rate); + + ul_src_con0 |= (voice_mode << 17) & (0x7 << 17); + + /* up8x txif sat on */ + regmap_write(afe->regmap, AFE_ADDA_NEWIF_CFG0, 0x03F87201); + + if (rate >= 96000) { /* hires */ + /* use hires format [1 0 23] */ + regmap_update_bits(afe->regmap, + AFE_ADDA_NEWIF_CFG0, + 0x1 << 5, + 0x1 << 5); + + regmap_update_bits(afe->regmap, + AFE_ADDA_NEWIF_CFG2, + 0xf << 28, + voice_mode << 28); + } else { /* normal 8~48k */ + /* use fixed 260k anc path */ + regmap_update_bits(afe->regmap, + AFE_ADDA_NEWIF_CFG2, + 0xf << 28, + 8 << 28); + + /* ul_use_cic_out */ + ul_src_con0 |= 0x1 << 20; + } + + regmap_update_bits(afe->regmap, + AFE_ADDA_NEWIF_CFG2, + 0xf << 28, + 8 << 28); + + regmap_update_bits(afe->regmap, + AFE_ADDA_UL_SRC_CON0, + 0xfffffffe, + ul_src_con0); + } + + return 0; +} + +static const struct snd_soc_dai_ops mtk_dai_adda_ops = { + .hw_params = mtk_dai_adda_hw_params, +}; + +/* dai driver */ +#define MTK_ADDA_PLAYBACK_RATES (SNDRV_PCM_RATE_8000_48000 |\ + SNDRV_PCM_RATE_96000 |\ + SNDRV_PCM_RATE_192000) + +#define MTK_ADDA_CAPTURE_RATES (SNDRV_PCM_RATE_8000 |\ + SNDRV_PCM_RATE_16000 |\ + SNDRV_PCM_RATE_32000 |\ + SNDRV_PCM_RATE_48000 |\ + SNDRV_PCM_RATE_96000 |\ + SNDRV_PCM_RATE_192000) + +#define MTK_ADDA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\ + SNDRV_PCM_FMTBIT_S24_LE |\ + SNDRV_PCM_FMTBIT_S32_LE) + +static struct snd_soc_dai_driver mtk_dai_adda_driver[] = { + { + .name = "ADDA", + .id = MT6797_DAI_ADDA, + .playback = { + .stream_name = "ADDA Playback", + .channels_min = 1, + .channels_max = 2, + .rates = MTK_ADDA_PLAYBACK_RATES, + .formats = MTK_ADDA_FORMATS, + }, + .capture = { + .stream_name = "ADDA Capture", + .channels_min = 1, + .channels_max = 2, + .rates = MTK_ADDA_CAPTURE_RATES, + .formats = MTK_ADDA_FORMATS, + }, + .ops = &mtk_dai_adda_ops, + }, +}; + +int mt6797_dai_adda_register(struct mtk_base_afe *afe) +{ + int id = MT6797_DAI_ADDA; + + afe->sub_dais[id].dai_drivers = mtk_dai_adda_driver; + afe->sub_dais[id].num_dai_drivers = ARRAY_SIZE(mtk_dai_adda_driver); + + afe->sub_dais[id].dapm_widgets = mtk_dai_adda_widgets; + afe->sub_dais[id].num_dapm_widgets = ARRAY_SIZE(mtk_dai_adda_widgets); + afe->sub_dais[id].dapm_routes = mtk_dai_adda_routes; + afe->sub_dais[id].num_dapm_routes = ARRAY_SIZE(mtk_dai_adda_routes); + return 0; +}
The patch
ASoC: mt6797: extract DAI adda in separate file
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks, Mark
From 42a589e8339517f9dc4e4184f5345d6965331c9c Mon Sep 17 00:00:00 2001
From: KaiChieh Chuang kaichieh.chuang@mediatek.com Date: Fri, 25 May 2018 11:48:17 +0800 Subject: [PATCH] ASoC: mt6797: extract DAI adda in separate file
Signed-off-by: KaiChieh Chuang kaichieh.chuang@mediatek.com Signed-off-by: Mark Brown broonie@kernel.org --- sound/soc/mediatek/mt6797/Makefile | 6 +- sound/soc/mediatek/mt6797/mt6797-afe-common.h | 3 + sound/soc/mediatek/mt6797/mt6797-afe-pcm.c | 353 ---------------- sound/soc/mediatek/mt6797/mt6797-dai-adda.c | 384 ++++++++++++++++++ 4 files changed, 392 insertions(+), 354 deletions(-) create mode 100644 sound/soc/mediatek/mt6797/mt6797-dai-adda.c
diff --git a/sound/soc/mediatek/mt6797/Makefile b/sound/soc/mediatek/mt6797/Makefile index 50fd50f7aa6a..4cbdc4d7da85 100644 --- a/sound/soc/mediatek/mt6797/Makefile +++ b/sound/soc/mediatek/mt6797/Makefile @@ -1,7 +1,11 @@ # SPDX-License-Identifier: GPL-2.0
# platform driver -snd-soc-mt6797-afe-objs := mt6797-afe-pcm.o mt6797-afe-clk.o +snd-soc-mt6797-afe-objs := \ + mt6797-afe-pcm.o \ + mt6797-afe-clk.o \ + mt6797-dai-adda.o + obj-$(CONFIG_SND_SOC_MT6797) += snd-soc-mt6797-afe.o
# machine driver diff --git a/sound/soc/mediatek/mt6797/mt6797-afe-common.h b/sound/soc/mediatek/mt6797/mt6797-afe-common.h index c1de3fc5dc3d..d53654f6e8aa 100644 --- a/sound/soc/mediatek/mt6797/mt6797-afe-common.h +++ b/sound/soc/mediatek/mt6797/mt6797-afe-common.h @@ -46,4 +46,7 @@ unsigned int mt6797_general_rate_transform(struct device *dev, unsigned int rate); unsigned int mt6797_rate_transform(struct device *dev, unsigned int rate, int aud_blk); + +/* dai register */ +int mt6797_dai_adda_register(struct mtk_base_afe *afe); #endif diff --git a/sound/soc/mediatek/mt6797/mt6797-afe-pcm.c b/sound/soc/mediatek/mt6797/mt6797-afe-pcm.c index 79a3551eb485..c892b7fbb6a8 100644 --- a/sound/soc/mediatek/mt6797/mt6797-afe-pcm.c +++ b/sound/soc/mediatek/mt6797/mt6797-afe-pcm.c @@ -158,206 +158,6 @@ static int mt6797_irq_fs(struct snd_pcm_substream *substream, unsigned int rate) return mt6797_general_rate_transform(afe->dev, rate); }
-/* ADDA BE DAIs */ -enum { - MTK_AFE_ADDA_DL_RATE_8K = 0, - MTK_AFE_ADDA_DL_RATE_11K = 1, - MTK_AFE_ADDA_DL_RATE_12K = 2, - MTK_AFE_ADDA_DL_RATE_16K = 3, - MTK_AFE_ADDA_DL_RATE_22K = 4, - MTK_AFE_ADDA_DL_RATE_24K = 5, - MTK_AFE_ADDA_DL_RATE_32K = 6, - MTK_AFE_ADDA_DL_RATE_44K = 7, - MTK_AFE_ADDA_DL_RATE_48K = 8, - MTK_AFE_ADDA_DL_RATE_96K = 9, - MTK_AFE_ADDA_DL_RATE_192K = 10, -}; - -enum { - MTK_AFE_ADDA_UL_RATE_8K = 0, - MTK_AFE_ADDA_UL_RATE_16K = 1, - MTK_AFE_ADDA_UL_RATE_32K = 2, - MTK_AFE_ADDA_UL_RATE_48K = 3, - MTK_AFE_ADDA_UL_RATE_96K = 4, - MTK_AFE_ADDA_UL_RATE_192K = 5, - MTK_AFE_ADDA_UL_RATE_48K_HD = 6, -}; - -static unsigned int adda_dl_rate_transform(struct mtk_base_afe *afe, - unsigned int rate) -{ - switch (rate) { - case 8000: - return MTK_AFE_ADDA_DL_RATE_8K; - case 11025: - return MTK_AFE_ADDA_DL_RATE_11K; - case 12000: - return MTK_AFE_ADDA_DL_RATE_12K; - case 16000: - return MTK_AFE_ADDA_DL_RATE_16K; - case 22050: - return MTK_AFE_ADDA_DL_RATE_22K; - case 24000: - return MTK_AFE_ADDA_DL_RATE_24K; - case 32000: - return MTK_AFE_ADDA_DL_RATE_32K; - case 44100: - return MTK_AFE_ADDA_DL_RATE_44K; - case 48000: - return MTK_AFE_ADDA_DL_RATE_48K; - case 96000: - return MTK_AFE_ADDA_DL_RATE_96K; - case 192000: - return MTK_AFE_ADDA_DL_RATE_192K; - default: - dev_warn(afe->dev, "%s(), rate %d invalid, use 48kHz!!!\n", - __func__, rate); - return MTK_AFE_ADDA_DL_RATE_48K; - } -} - -static unsigned int adda_ul_rate_transform(struct mtk_base_afe *afe, - unsigned int rate) -{ - switch (rate) { - case 8000: - return MTK_AFE_ADDA_UL_RATE_8K; - case 16000: - return MTK_AFE_ADDA_UL_RATE_16K; - case 32000: - return MTK_AFE_ADDA_UL_RATE_32K; - case 48000: - return MTK_AFE_ADDA_UL_RATE_48K; - case 96000: - return MTK_AFE_ADDA_UL_RATE_96K; - case 192000: - return MTK_AFE_ADDA_UL_RATE_192K; - default: - dev_warn(afe->dev, "%s(), rate %d invalid, use 48kHz!!!\n", - __func__, rate); - return MTK_AFE_ADDA_UL_RATE_48K; - } -} - -static int mtk_dai_adda_hw_params(struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *params, - struct snd_soc_dai *dai) -{ - struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_soc_component *component = - snd_soc_rtdcom_lookup(rtd, AFE_PCM_NAME); - struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component); - unsigned int rate = params_rate(params); - - dev_dbg(afe->dev, "%s(), id %d, stream %d, rate %d\n", - __func__, dai->id, substream->stream, rate); - - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { - unsigned int dl_src2_con0 = 0; - unsigned int dl_src2_con1 = 0; - - /* clean predistortion */ - regmap_write(afe->regmap, AFE_ADDA_PREDIS_CON0, 0); - regmap_write(afe->regmap, AFE_ADDA_PREDIS_CON1, 0); - - /* set input sampling rate */ - dl_src2_con0 = adda_dl_rate_transform(afe, rate) << 28; - - /* set output mode */ - switch (rate) { - case 192000: - dl_src2_con0 |= (0x1 << 24); /* UP_SAMPLING_RATE_X2 */ - dl_src2_con0 |= 1 << 14; - break; - case 96000: - dl_src2_con0 |= (0x2 << 24); /* UP_SAMPLING_RATE_X4 */ - dl_src2_con0 |= 1 << 14; - break; - default: - dl_src2_con0 |= (0x3 << 24); /* UP_SAMPLING_RATE_X8 */ - break; - } - - /* turn off mute function */ - dl_src2_con0 |= (0x03 << 11); - - /* set voice input data if input sample rate is 8k or 16k */ - if (rate == 8000 || rate == 16000) - dl_src2_con0 |= 0x01 << 5; - - if (rate < 96000) { - /* SA suggest apply -0.3db to audio/speech path */ - dl_src2_con1 = 0xf74f0000; - } else { - /* SA suggest apply -0.3db to audio/speech path - * with DL gain set to half, - * 0xFFFF = 0dB -> 0x8000 = 0dB when 96k, 192k - */ - dl_src2_con1 = 0x7ba70000; - } - - /* turn on down-link gain */ - dl_src2_con0 = dl_src2_con0 | (0x01 << 1); - - regmap_write(afe->regmap, AFE_ADDA_DL_SRC2_CON0, dl_src2_con0); - regmap_write(afe->regmap, AFE_ADDA_DL_SRC2_CON1, dl_src2_con1); - } else { - unsigned int voice_mode = 0; - unsigned int ul_src_con0 = 0; /* default value */ - - /* Using Internal ADC */ - regmap_update_bits(afe->regmap, - AFE_ADDA_TOP_CON0, - 0x1 << 0, - 0x0 << 0); - - voice_mode = adda_ul_rate_transform(afe, rate); - - ul_src_con0 |= (voice_mode << 17) & (0x7 << 17); - - /* up8x txif sat on */ - regmap_write(afe->regmap, AFE_ADDA_NEWIF_CFG0, 0x03F87201); - - if (rate >= 96000) { /* hires */ - /* use hires format [1 0 23] */ - regmap_update_bits(afe->regmap, - AFE_ADDA_NEWIF_CFG0, - 0x1 << 5, - 0x1 << 5); - - regmap_update_bits(afe->regmap, - AFE_ADDA_NEWIF_CFG2, - 0xf << 28, - voice_mode << 28); - } else { /* normal 8~48k */ - /* use fixed 260k anc path */ - regmap_update_bits(afe->regmap, - AFE_ADDA_NEWIF_CFG2, - 0xf << 28, - 8 << 28); - - /* ul_use_cic_out */ - ul_src_con0 |= 0x1 << 20; - } - - regmap_update_bits(afe->regmap, - AFE_ADDA_NEWIF_CFG2, - 0xf << 28, - 8 << 28); - - regmap_update_bits(afe->regmap, - AFE_ADDA_UL_SRC_CON0, - 0xfffffffe, - ul_src_con0); - } - - return 0; -} - -static const struct snd_soc_dai_ops mtk_dai_adda_ops = { - .hw_params = mtk_dai_adda_hw_params, -}; - #define MTK_PCM_RATES (SNDRV_PCM_RATE_8000_48000 |\ SNDRV_PCM_RATE_88200 |\ SNDRV_PCM_RATE_96000 |\ @@ -372,21 +172,6 @@ static const struct snd_soc_dai_ops mtk_dai_adda_ops = { SNDRV_PCM_FMTBIT_S24_LE |\ SNDRV_PCM_FMTBIT_S32_LE)
-#define MTK_ADDA_PLAYBACK_RATES (SNDRV_PCM_RATE_8000_48000 |\ - SNDRV_PCM_RATE_96000 |\ - SNDRV_PCM_RATE_192000) - -#define MTK_ADDA_CAPTURE_RATES (SNDRV_PCM_RATE_8000 |\ - SNDRV_PCM_RATE_16000 |\ - SNDRV_PCM_RATE_32000 |\ - SNDRV_PCM_RATE_48000 |\ - SNDRV_PCM_RATE_96000 |\ - SNDRV_PCM_RATE_192000) - -#define MTK_ADDA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\ - SNDRV_PCM_FMTBIT_S24_LE |\ - SNDRV_PCM_FMTBIT_S32_LE) - static struct snd_soc_dai_driver mt6797_afe_pcm_dais[] = { /* FE DAIs: memory intefaces to CPU */ { @@ -485,26 +270,6 @@ static struct snd_soc_dai_driver mt6797_afe_pcm_dais[] = { }, .ops = &mtk_afe_fe_ops, }, - /* BE DAIs */ - { - .name = "ADDA", - .id = MT6797_DAI_ADDA, - .playback = { - .stream_name = "ADDA Playback", - .channels_min = 1, - .channels_max = 2, - .rates = MTK_ADDA_PLAYBACK_RATES, - .formats = MTK_ADDA_FORMATS, - }, - .capture = { - .stream_name = "ADDA Capture", - .channels_min = 1, - .channels_max = 2, - .rates = MTK_ADDA_CAPTURE_RATES, - .formats = MTK_ADDA_FORMATS, - }, - .ops = &mtk_dai_adda_ops, - }, };
/* dma widget & routes*/ @@ -564,58 +329,6 @@ static const struct snd_kcontrol_new memif_ul_mono_2_mix[] = { I_ADDA_UL_CH2, 1, 0), };
-static const struct snd_kcontrol_new mtk_adda_dl_ch1_mix[] = { - SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH1", AFE_CONN3, I_DL1_CH1, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH1", AFE_CONN3, I_DL2_CH1, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH1", AFE_CONN3, I_DL3_CH1, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH2", AFE_CONN3, - I_ADDA_UL_CH2, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH1", AFE_CONN3, - I_ADDA_UL_CH1, 1, 0), -}; - -static const struct snd_kcontrol_new mtk_adda_dl_ch2_mix[] = { - SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH1", AFE_CONN4, I_DL1_CH1, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH2", AFE_CONN4, I_DL1_CH2, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH1", AFE_CONN4, I_DL2_CH1, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH2", AFE_CONN4, I_DL2_CH2, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH1", AFE_CONN4, I_DL3_CH1, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH2", AFE_CONN4, I_DL3_CH2, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH2", AFE_CONN4, - I_ADDA_UL_CH2, 1, 0), - SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH1", AFE_CONN4, - I_ADDA_UL_CH1, 1, 0), -}; - -static int mtk_adda_ul_event(struct snd_soc_dapm_widget *w, - struct snd_kcontrol *kcontrol, - int event) -{ - struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); - struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt); - - dev_dbg(afe->dev, "%s(), name %s, event 0x%x\n", - __func__, w->name, event); - - switch (event) { - case SND_SOC_DAPM_POST_PMD: - /* should delayed 1/fs(smallest is 8k) = 125us before afe off */ - usleep_range(125, 135); - break; - default: - break; - } - - return 0; -} - -enum { - SUPPLY_SEQ_AUD_TOP_PDN, - SUPPLY_SEQ_ADDA_AFE_ON, - SUPPLY_SEQ_ADDA_DL_ON, - SUPPLY_SEQ_ADDA_UL_ON, -}; - static const struct snd_soc_dapm_widget mt6797_afe_pcm_widgets[] = { /* memif */ SND_SOC_DAPM_MIXER("UL1_CH1", SND_SOC_NOPM, 0, 0, @@ -640,42 +353,6 @@ static const struct snd_soc_dapm_widget mt6797_afe_pcm_widgets[] = { SND_SOC_DAPM_MIXER("UL_MONO_2_CH1", SND_SOC_NOPM, 0, 0, memif_ul_mono_2_mix, ARRAY_SIZE(memif_ul_mono_2_mix)), - - /* adda */ - SND_SOC_DAPM_MIXER("ADDA_DL_CH1", SND_SOC_NOPM, 0, 0, - mtk_adda_dl_ch1_mix, - ARRAY_SIZE(mtk_adda_dl_ch1_mix)), - SND_SOC_DAPM_MIXER("ADDA_DL_CH2", SND_SOC_NOPM, 0, 0, - mtk_adda_dl_ch2_mix, - ARRAY_SIZE(mtk_adda_dl_ch2_mix)), - - SND_SOC_DAPM_SUPPLY_S("ADDA Enable", SUPPLY_SEQ_ADDA_AFE_ON, - AFE_ADDA_UL_DL_CON0, ADDA_AFE_ON_SFT, 0, - NULL, 0), - - SND_SOC_DAPM_SUPPLY_S("ADDA Playback Enable", SUPPLY_SEQ_ADDA_DL_ON, - AFE_ADDA_DL_SRC2_CON0, - DL_2_SRC_ON_TMP_CTL_PRE_SFT, 0, - NULL, 0), - - SND_SOC_DAPM_SUPPLY_S("ADDA Capture Enable", SUPPLY_SEQ_ADDA_UL_ON, - AFE_ADDA_UL_SRC_CON0, - UL_SRC_ON_TMP_CTL_SFT, 0, - mtk_adda_ul_event, - SND_SOC_DAPM_POST_PMD), - - SND_SOC_DAPM_SUPPLY_S("aud_dac_clk", SUPPLY_SEQ_AUD_TOP_PDN, - AUDIO_TOP_CON0, PDN_DAC_SFT, 1, - NULL, 0), - SND_SOC_DAPM_SUPPLY_S("aud_dac_predis_clk", SUPPLY_SEQ_AUD_TOP_PDN, - AUDIO_TOP_CON0, PDN_DAC_PREDIS_SFT, 1, - NULL, 0), - - SND_SOC_DAPM_SUPPLY_S("aud_adc_clk", SUPPLY_SEQ_AUD_TOP_PDN, - AUDIO_TOP_CON0, PDN_ADC_SFT, 1, - NULL, 0), - - SND_SOC_DAPM_CLOCK_SUPPLY("mtkaif_26m_clk"), };
static const struct snd_soc_dapm_route mt6797_afe_pcm_routes[] = { @@ -702,36 +379,6 @@ static const struct snd_soc_dapm_route mt6797_afe_pcm_routes[] = { {"UL_MONO_2", NULL, "UL_MONO_2_CH1"}, {"UL_MONO_2_CH1", "ADDA_UL_CH1", "ADDA Capture"}, {"UL_MONO_2_CH1", "ADDA_UL_CH2", "ADDA Capture"}, - - /* playback */ - {"ADDA_DL_CH1", "DL1_CH1", "DL1"}, - {"ADDA_DL_CH2", "DL1_CH1", "DL1"}, - {"ADDA_DL_CH2", "DL1_CH2", "DL1"}, - - {"ADDA_DL_CH1", "DL2_CH1", "DL2"}, - {"ADDA_DL_CH2", "DL2_CH1", "DL2"}, - {"ADDA_DL_CH2", "DL2_CH2", "DL2"}, - - {"ADDA_DL_CH1", "DL3_CH1", "DL3"}, - {"ADDA_DL_CH2", "DL3_CH1", "DL3"}, - {"ADDA_DL_CH2", "DL3_CH2", "DL3"}, - - {"ADDA Playback", NULL, "ADDA_DL_CH1"}, - {"ADDA Playback", NULL, "ADDA_DL_CH2"}, - - /* adda enable */ - {"ADDA Playback", NULL, "ADDA Enable"}, - {"ADDA Playback", NULL, "ADDA Playback Enable"}, - {"ADDA Capture", NULL, "ADDA Enable"}, - {"ADDA Capture", NULL, "ADDA Capture Enable"}, - - /* clk */ - {"ADDA Playback", NULL, "mtkaif_26m_clk"}, - {"ADDA Playback", NULL, "aud_dac_clk"}, - {"ADDA Playback", NULL, "aud_dac_predis_clk"}, - - {"ADDA Capture", NULL, "mtkaif_26m_clk"}, - {"ADDA Capture", NULL, "aud_adc_clk"}, };
static const struct snd_soc_component_driver mt6797_afe_pcm_dai_component = { diff --git a/sound/soc/mediatek/mt6797/mt6797-dai-adda.c b/sound/soc/mediatek/mt6797/mt6797-dai-adda.c new file mode 100644 index 000000000000..f38e35edfd44 --- /dev/null +++ b/sound/soc/mediatek/mt6797/mt6797-dai-adda.c @@ -0,0 +1,384 @@ +// SPDX-License-Identifier: GPL-2.0 +// +// MediaTek ALSA SoC Audio DAI ADDA Control +// +// Copyright (c) 2018 MediaTek Inc. +// Author: KaiChieh Chuang kaichieh.chuang@mediatek.com + +#include <linux/regmap.h> +#include <linux/delay.h> +#include "mt6797-afe-common.h" +#include "mt6797-interconnection.h" +#include "mt6797-reg.h" + +enum { + MTK_AFE_ADDA_DL_RATE_8K = 0, + MTK_AFE_ADDA_DL_RATE_11K = 1, + MTK_AFE_ADDA_DL_RATE_12K = 2, + MTK_AFE_ADDA_DL_RATE_16K = 3, + MTK_AFE_ADDA_DL_RATE_22K = 4, + MTK_AFE_ADDA_DL_RATE_24K = 5, + MTK_AFE_ADDA_DL_RATE_32K = 6, + MTK_AFE_ADDA_DL_RATE_44K = 7, + MTK_AFE_ADDA_DL_RATE_48K = 8, + MTK_AFE_ADDA_DL_RATE_96K = 9, + MTK_AFE_ADDA_DL_RATE_192K = 10, +}; + +enum { + MTK_AFE_ADDA_UL_RATE_8K = 0, + MTK_AFE_ADDA_UL_RATE_16K = 1, + MTK_AFE_ADDA_UL_RATE_32K = 2, + MTK_AFE_ADDA_UL_RATE_48K = 3, + MTK_AFE_ADDA_UL_RATE_96K = 4, + MTK_AFE_ADDA_UL_RATE_192K = 5, + MTK_AFE_ADDA_UL_RATE_48K_HD = 6, +}; + +static unsigned int adda_dl_rate_transform(struct mtk_base_afe *afe, + unsigned int rate) +{ + switch (rate) { + case 8000: + return MTK_AFE_ADDA_DL_RATE_8K; + case 11025: + return MTK_AFE_ADDA_DL_RATE_11K; + case 12000: + return MTK_AFE_ADDA_DL_RATE_12K; + case 16000: + return MTK_AFE_ADDA_DL_RATE_16K; + case 22050: + return MTK_AFE_ADDA_DL_RATE_22K; + case 24000: + return MTK_AFE_ADDA_DL_RATE_24K; + case 32000: + return MTK_AFE_ADDA_DL_RATE_32K; + case 44100: + return MTK_AFE_ADDA_DL_RATE_44K; + case 48000: + return MTK_AFE_ADDA_DL_RATE_48K; + case 96000: + return MTK_AFE_ADDA_DL_RATE_96K; + case 192000: + return MTK_AFE_ADDA_DL_RATE_192K; + default: + dev_warn(afe->dev, "%s(), rate %d invalid, use 48kHz!!!\n", + __func__, rate); + return MTK_AFE_ADDA_DL_RATE_48K; + } +} + +static unsigned int adda_ul_rate_transform(struct mtk_base_afe *afe, + unsigned int rate) +{ + switch (rate) { + case 8000: + return MTK_AFE_ADDA_UL_RATE_8K; + case 16000: + return MTK_AFE_ADDA_UL_RATE_16K; + case 32000: + return MTK_AFE_ADDA_UL_RATE_32K; + case 48000: + return MTK_AFE_ADDA_UL_RATE_48K; + case 96000: + return MTK_AFE_ADDA_UL_RATE_96K; + case 192000: + return MTK_AFE_ADDA_UL_RATE_192K; + default: + dev_warn(afe->dev, "%s(), rate %d invalid, use 48kHz!!!\n", + __func__, rate); + return MTK_AFE_ADDA_UL_RATE_48K; + } +} + +/* dai component */ +static const struct snd_kcontrol_new mtk_adda_dl_ch1_mix[] = { + SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH1", AFE_CONN3, I_DL1_CH1, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH1", AFE_CONN3, I_DL2_CH1, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH1", AFE_CONN3, I_DL3_CH1, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH2", AFE_CONN3, + I_ADDA_UL_CH2, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH1", AFE_CONN3, + I_ADDA_UL_CH1, 1, 0), +}; + +static const struct snd_kcontrol_new mtk_adda_dl_ch2_mix[] = { + SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH1", AFE_CONN4, I_DL1_CH1, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("DL1_CH2", AFE_CONN4, I_DL1_CH2, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH1", AFE_CONN4, I_DL2_CH1, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("DL2_CH2", AFE_CONN4, I_DL2_CH2, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH1", AFE_CONN4, I_DL3_CH1, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("DL3_CH2", AFE_CONN4, I_DL3_CH2, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH2", AFE_CONN4, + I_ADDA_UL_CH2, 1, 0), + SOC_DAPM_SINGLE_AUTODISABLE("ADDA_UL_CH1", AFE_CONN4, + I_ADDA_UL_CH1, 1, 0), +}; + +static int mtk_adda_ul_event(struct snd_soc_dapm_widget *w, + struct snd_kcontrol *kcontrol, + int event) +{ + struct snd_soc_component *cmpnt = snd_soc_dapm_to_component(w->dapm); + struct mtk_base_afe *afe = snd_soc_component_get_drvdata(cmpnt); + + dev_dbg(afe->dev, "%s(), name %s, event 0x%x\n", + __func__, w->name, event); + + switch (event) { + case SND_SOC_DAPM_POST_PMD: + /* should delayed 1/fs(smallest is 8k) = 125us before afe off */ + usleep_range(125, 135); + break; + default: + break; + } + + return 0; +} + +enum { + SUPPLY_SEQ_AUD_TOP_PDN, + SUPPLY_SEQ_ADDA_AFE_ON, + SUPPLY_SEQ_ADDA_DL_ON, + SUPPLY_SEQ_ADDA_UL_ON, +}; + +static const struct snd_soc_dapm_widget mtk_dai_adda_widgets[] = { + /* adda */ + SND_SOC_DAPM_MIXER("ADDA_DL_CH1", SND_SOC_NOPM, 0, 0, + mtk_adda_dl_ch1_mix, + ARRAY_SIZE(mtk_adda_dl_ch1_mix)), + SND_SOC_DAPM_MIXER("ADDA_DL_CH2", SND_SOC_NOPM, 0, 0, + mtk_adda_dl_ch2_mix, + ARRAY_SIZE(mtk_adda_dl_ch2_mix)), + + SND_SOC_DAPM_SUPPLY_S("ADDA Enable", SUPPLY_SEQ_ADDA_AFE_ON, + AFE_ADDA_UL_DL_CON0, ADDA_AFE_ON_SFT, 0, + NULL, 0), + + SND_SOC_DAPM_SUPPLY_S("ADDA Playback Enable", SUPPLY_SEQ_ADDA_DL_ON, + AFE_ADDA_DL_SRC2_CON0, + DL_2_SRC_ON_TMP_CTL_PRE_SFT, 0, + NULL, 0), + + SND_SOC_DAPM_SUPPLY_S("ADDA Capture Enable", SUPPLY_SEQ_ADDA_UL_ON, + AFE_ADDA_UL_SRC_CON0, + UL_SRC_ON_TMP_CTL_SFT, 0, + mtk_adda_ul_event, + SND_SOC_DAPM_POST_PMD), + + SND_SOC_DAPM_SUPPLY_S("aud_dac_clk", SUPPLY_SEQ_AUD_TOP_PDN, + AUDIO_TOP_CON0, PDN_DAC_SFT, 1, + NULL, 0), + SND_SOC_DAPM_SUPPLY_S("aud_dac_predis_clk", SUPPLY_SEQ_AUD_TOP_PDN, + AUDIO_TOP_CON0, PDN_DAC_PREDIS_SFT, 1, + NULL, 0), + + SND_SOC_DAPM_SUPPLY_S("aud_adc_clk", SUPPLY_SEQ_AUD_TOP_PDN, + AUDIO_TOP_CON0, PDN_ADC_SFT, 1, + NULL, 0), + + SND_SOC_DAPM_CLOCK_SUPPLY("mtkaif_26m_clk"), +}; + +static const struct snd_soc_dapm_route mtk_dai_adda_routes[] = { + /* playback */ + {"ADDA_DL_CH1", "DL1_CH1", "DL1"}, + {"ADDA_DL_CH2", "DL1_CH1", "DL1"}, + {"ADDA_DL_CH2", "DL1_CH2", "DL1"}, + + {"ADDA_DL_CH1", "DL2_CH1", "DL2"}, + {"ADDA_DL_CH2", "DL2_CH1", "DL2"}, + {"ADDA_DL_CH2", "DL2_CH2", "DL2"}, + + {"ADDA_DL_CH1", "DL3_CH1", "DL3"}, + {"ADDA_DL_CH2", "DL3_CH1", "DL3"}, + {"ADDA_DL_CH2", "DL3_CH2", "DL3"}, + + {"ADDA Playback", NULL, "ADDA_DL_CH1"}, + {"ADDA Playback", NULL, "ADDA_DL_CH2"}, + + /* adda enable */ + {"ADDA Playback", NULL, "ADDA Enable"}, + {"ADDA Playback", NULL, "ADDA Playback Enable"}, + {"ADDA Capture", NULL, "ADDA Enable"}, + {"ADDA Capture", NULL, "ADDA Capture Enable"}, + + /* clk */ + {"ADDA Playback", NULL, "mtkaif_26m_clk"}, + {"ADDA Playback", NULL, "aud_dac_clk"}, + {"ADDA Playback", NULL, "aud_dac_predis_clk"}, + + {"ADDA Capture", NULL, "mtkaif_26m_clk"}, + {"ADDA Capture", NULL, "aud_adc_clk"}, +}; + +/* dai ops */ +static int mtk_dai_adda_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + struct mtk_base_afe *afe = snd_soc_dai_get_drvdata(dai); + unsigned int rate = params_rate(params); + + dev_dbg(afe->dev, "%s(), id %d, stream %d, rate %d\n", + __func__, dai->id, substream->stream, rate); + + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { + unsigned int dl_src2_con0 = 0; + unsigned int dl_src2_con1 = 0; + + /* clean predistortion */ + regmap_write(afe->regmap, AFE_ADDA_PREDIS_CON0, 0); + regmap_write(afe->regmap, AFE_ADDA_PREDIS_CON1, 0); + + /* set input sampling rate */ + dl_src2_con0 = adda_dl_rate_transform(afe, rate) << 28; + + /* set output mode */ + switch (rate) { + case 192000: + dl_src2_con0 |= (0x1 << 24); /* UP_SAMPLING_RATE_X2 */ + dl_src2_con0 |= 1 << 14; + break; + case 96000: + dl_src2_con0 |= (0x2 << 24); /* UP_SAMPLING_RATE_X4 */ + dl_src2_con0 |= 1 << 14; + break; + default: + dl_src2_con0 |= (0x3 << 24); /* UP_SAMPLING_RATE_X8 */ + break; + } + + /* turn off mute function */ + dl_src2_con0 |= (0x03 << 11); + + /* set voice input data if input sample rate is 8k or 16k */ + if (rate == 8000 || rate == 16000) + dl_src2_con0 |= 0x01 << 5; + + if (rate < 96000) { + /* SA suggest apply -0.3db to audio/speech path */ + dl_src2_con1 = 0xf74f0000; + } else { + /* SA suggest apply -0.3db to audio/speech path + * with DL gain set to half, + * 0xFFFF = 0dB -> 0x8000 = 0dB when 96k, 192k + */ + dl_src2_con1 = 0x7ba70000; + } + + /* turn on down-link gain */ + dl_src2_con0 = dl_src2_con0 | (0x01 << 1); + + regmap_write(afe->regmap, AFE_ADDA_DL_SRC2_CON0, dl_src2_con0); + regmap_write(afe->regmap, AFE_ADDA_DL_SRC2_CON1, dl_src2_con1); + } else { + unsigned int voice_mode = 0; + unsigned int ul_src_con0 = 0; /* default value */ + + /* Using Internal ADC */ + regmap_update_bits(afe->regmap, + AFE_ADDA_TOP_CON0, + 0x1 << 0, + 0x0 << 0); + + voice_mode = adda_ul_rate_transform(afe, rate); + + ul_src_con0 |= (voice_mode << 17) & (0x7 << 17); + + /* up8x txif sat on */ + regmap_write(afe->regmap, AFE_ADDA_NEWIF_CFG0, 0x03F87201); + + if (rate >= 96000) { /* hires */ + /* use hires format [1 0 23] */ + regmap_update_bits(afe->regmap, + AFE_ADDA_NEWIF_CFG0, + 0x1 << 5, + 0x1 << 5); + + regmap_update_bits(afe->regmap, + AFE_ADDA_NEWIF_CFG2, + 0xf << 28, + voice_mode << 28); + } else { /* normal 8~48k */ + /* use fixed 260k anc path */ + regmap_update_bits(afe->regmap, + AFE_ADDA_NEWIF_CFG2, + 0xf << 28, + 8 << 28); + + /* ul_use_cic_out */ + ul_src_con0 |= 0x1 << 20; + } + + regmap_update_bits(afe->regmap, + AFE_ADDA_NEWIF_CFG2, + 0xf << 28, + 8 << 28); + + regmap_update_bits(afe->regmap, + AFE_ADDA_UL_SRC_CON0, + 0xfffffffe, + ul_src_con0); + } + + return 0; +} + +static const struct snd_soc_dai_ops mtk_dai_adda_ops = { + .hw_params = mtk_dai_adda_hw_params, +}; + +/* dai driver */ +#define MTK_ADDA_PLAYBACK_RATES (SNDRV_PCM_RATE_8000_48000 |\ + SNDRV_PCM_RATE_96000 |\ + SNDRV_PCM_RATE_192000) + +#define MTK_ADDA_CAPTURE_RATES (SNDRV_PCM_RATE_8000 |\ + SNDRV_PCM_RATE_16000 |\ + SNDRV_PCM_RATE_32000 |\ + SNDRV_PCM_RATE_48000 |\ + SNDRV_PCM_RATE_96000 |\ + SNDRV_PCM_RATE_192000) + +#define MTK_ADDA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\ + SNDRV_PCM_FMTBIT_S24_LE |\ + SNDRV_PCM_FMTBIT_S32_LE) + +static struct snd_soc_dai_driver mtk_dai_adda_driver[] = { + { + .name = "ADDA", + .id = MT6797_DAI_ADDA, + .playback = { + .stream_name = "ADDA Playback", + .channels_min = 1, + .channels_max = 2, + .rates = MTK_ADDA_PLAYBACK_RATES, + .formats = MTK_ADDA_FORMATS, + }, + .capture = { + .stream_name = "ADDA Capture", + .channels_min = 1, + .channels_max = 2, + .rates = MTK_ADDA_CAPTURE_RATES, + .formats = MTK_ADDA_FORMATS, + }, + .ops = &mtk_dai_adda_ops, + }, +}; + +int mt6797_dai_adda_register(struct mtk_base_afe *afe) +{ + int id = MT6797_DAI_ADDA; + + afe->sub_dais[id].dai_drivers = mtk_dai_adda_driver; + afe->sub_dais[id].num_dai_drivers = ARRAY_SIZE(mtk_dai_adda_driver); + + afe->sub_dais[id].dapm_widgets = mtk_dai_adda_widgets; + afe->sub_dais[id].num_dapm_widgets = ARRAY_SIZE(mtk_dai_adda_widgets); + afe->sub_dais[id].dapm_routes = mtk_dai_adda_routes; + afe->sub_dais[id].num_dapm_routes = ARRAY_SIZE(mtk_dai_adda_routes); + return 0; +}
Signed-off-by: KaiChieh Chuang kaichieh.chuang@mediatek.com --- .../soc/mediatek/common/mtk-afe-platform-driver.c | 6 +-- .../soc/mediatek/common/mtk-afe-platform-driver.h | 6 +++ sound/soc/mediatek/mt6797/mt6797-afe-pcm.c | 53 ++++++++++++++++++---- 3 files changed, 52 insertions(+), 13 deletions(-)
diff --git a/sound/soc/mediatek/common/mtk-afe-platform-driver.c b/sound/soc/mediatek/common/mtk-afe-platform-driver.c index c449188..0061858 100644 --- a/sound/soc/mediatek/common/mtk-afe-platform-driver.c +++ b/sound/soc/mediatek/common/mtk-afe-platform-driver.c @@ -126,12 +126,12 @@ int mtk_afe_add_sub_dai_control(struct snd_soc_component *component) return bytes_to_frames(substream->runtime, pcm_ptr_bytes); }
-static const struct snd_pcm_ops mtk_afe_pcm_ops = { +const struct snd_pcm_ops mtk_afe_pcm_ops = { .ioctl = snd_pcm_lib_ioctl, .pointer = mtk_afe_pcm_pointer, };
-static int mtk_afe_pcm_new(struct snd_soc_pcm_runtime *rtd) +int mtk_afe_pcm_new(struct snd_soc_pcm_runtime *rtd) { size_t size; struct snd_pcm *pcm = rtd->pcm; @@ -144,7 +144,7 @@ static int mtk_afe_pcm_new(struct snd_soc_pcm_runtime *rtd) size, size); }
-static void mtk_afe_pcm_free(struct snd_pcm *pcm) +void mtk_afe_pcm_free(struct snd_pcm *pcm) { snd_pcm_lib_preallocate_free_for_all(pcm); } diff --git a/sound/soc/mediatek/mt6797/mt6797-afe-pcm.c b/sound/soc/mediatek/mt6797/mt6797-afe-pcm.c index c892b7f..1286c6e 100644 --- a/sound/soc/mediatek/mt6797/mt6797-afe-pcm.c +++ b/sound/soc/mediatek/mt6797/mt6797-afe-pcm.c @@ -172,7 +172,7 @@ static int mt6797_irq_fs(struct snd_pcm_substream *substream, unsigned int rate) SNDRV_PCM_FMTBIT_S24_LE |\ SNDRV_PCM_FMTBIT_S32_LE)
-static struct snd_soc_dai_driver mt6797_afe_pcm_dais[] = { +static struct snd_soc_dai_driver mt6797_memif_dai_driver[] = { /* FE DAIs: memory intefaces to CPU */ { .name = "DL1", @@ -329,7 +329,7 @@ static int mt6797_irq_fs(struct snd_pcm_substream *substream, unsigned int rate) I_ADDA_UL_CH2, 1, 0), };
-static const struct snd_soc_dapm_widget mt6797_afe_pcm_widgets[] = { +static const struct snd_soc_dapm_widget mt6797_memif_widgets[] = { /* memif */ SND_SOC_DAPM_MIXER("UL1_CH1", SND_SOC_NOPM, 0, 0, memif_ul1_ch1_mix, ARRAY_SIZE(memif_ul1_ch1_mix)), @@ -355,7 +355,7 @@ static int mt6797_irq_fs(struct snd_pcm_substream *substream, unsigned int rate) ARRAY_SIZE(memif_ul_mono_2_mix)), };
-static const struct snd_soc_dapm_route mt6797_afe_pcm_routes[] = { +static const struct snd_soc_dapm_route mt6797_memif_routes[] = { /* capture */ {"UL1", NULL, "UL1_CH1"}, {"UL1", NULL, "UL1_CH2"}, @@ -383,10 +383,6 @@ static int mt6797_irq_fs(struct snd_pcm_substream *substream, unsigned int rate)
static const struct snd_soc_component_driver mt6797_afe_pcm_dai_component = { .name = "mt6797-afe-pcm-dai", - .dapm_widgets = mt6797_afe_pcm_widgets, - .num_dapm_widgets = ARRAY_SIZE(mt6797_afe_pcm_widgets), - .dapm_routes = mt6797_afe_pcm_routes, - .num_dapm_routes = ARRAY_SIZE(mt6797_afe_pcm_routes), };
static const struct mtk_base_memif_data memif_data[MT6797_MEMIF_NUM] = { @@ -724,6 +720,19 @@ static int mt6797_afe_runtime_resume(struct device *dev) return 0; }
+static int mt6797_afe_component_probe(struct snd_soc_component *component) +{ + return mtk_afe_add_sub_dai_control(component); +} + +static const struct snd_soc_component_driver mt6797_afe_component = { + .name = AFE_PCM_NAME, + .ops = &mtk_afe_pcm_ops, + .pcm_new = mtk_afe_pcm_new, + .pcm_free = mtk_afe_pcm_free, + .probe = mt6797_afe_component_probe, +}; + static int mt6797_afe_pcm_dev_probe(struct platform_device *pdev) { struct mtk_base_afe *afe; @@ -801,6 +810,29 @@ static int mt6797_afe_pcm_dev_probe(struct platform_device *pdev) return ret; }
+ /* init sub_dais */ + afe->num_sub_dais = MT6797_DAI_NUM; + afe->sub_dais = devm_kcalloc(dev, afe->num_sub_dais, + sizeof(*afe->sub_dais), + GFP_KERNEL); + if (!afe->sub_dais) + return -ENOMEM; + + mt6797_dai_adda_register(afe); + + afe->sub_dais[MT6797_MEMIF_DL1].dai_drivers = mt6797_memif_dai_driver; + afe->sub_dais[MT6797_MEMIF_DL1].num_dai_drivers = + ARRAY_SIZE(mt6797_memif_dai_driver); + afe->sub_dais[MT6797_MEMIF_DL1].dapm_widgets = mt6797_memif_widgets; + afe->sub_dais[MT6797_MEMIF_DL1].num_dapm_widgets = + ARRAY_SIZE(mt6797_memif_widgets); + afe->sub_dais[MT6797_MEMIF_DL1].dapm_routes = mt6797_memif_routes; + afe->sub_dais[MT6797_MEMIF_DL1].num_dapm_routes = + ARRAY_SIZE(mt6797_memif_routes); + + /* init dai_driver and component_driver */ + mtk_afe_combine_sub_dai(afe); + afe->mtk_afe_hardware = &mt6797_afe_hardware; afe->memif_fs = mt6797_memif_fs; afe->irq_fs = mt6797_irq_fs; @@ -815,7 +847,8 @@ static int mt6797_afe_pcm_dev_probe(struct platform_device *pdev) goto err_pm_disable; pm_runtime_get_sync(&pdev->dev);
- ret = devm_snd_soc_register_component(dev, &mtk_afe_pcm_platform, + /* register component */ + ret = devm_snd_soc_register_component(dev, &mt6797_afe_component, NULL, 0); if (ret) { dev_warn(dev, "err_platform\n"); @@ -824,8 +857,8 @@ static int mt6797_afe_pcm_dev_probe(struct platform_device *pdev)
ret = devm_snd_soc_register_component(afe->dev, &mt6797_afe_pcm_dai_component, - mt6797_afe_pcm_dais, - ARRAY_SIZE(mt6797_afe_pcm_dais)); + afe->dai_drivers, + afe->num_dai_drivers); if (ret) { dev_warn(dev, "err_dai_component\n"); goto err_pm_disable;
Hi KaiChieh,
Thank you for the patch! Yet something to improve:
[auto build test ERROR on asoc/for-next] [also build test ERROR on next-20180517] [cannot apply to v4.17-rc6] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
url: https://github.com/0day-ci/linux/commits/KaiChieh-Chuang/ASoC-mediatek-add-s... base: https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next config: arm-allmodconfig (attached as .config) compiler: arm-linux-gnueabi-gcc (Debian 7.2.0-11) 7.2.0 reproduce: wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross # save the attached .config to linux build tree make.cross ARCH=arm
All errors (new ones prefixed by >>):
sound/soc/mediatek/mt6797/mt6797-afe-pcm.c:730:10: error: 'mtk_afe_pcm_ops' undeclared here (not in a function); did you mean 'mtk_afe_fe_ops'?
.ops = &mtk_afe_pcm_ops, ^~~~~~~~~~~~~~~ mtk_afe_fe_ops
sound/soc/mediatek/mt6797/mt6797-afe-pcm.c:731:13: error: 'mtk_afe_pcm_new' undeclared here (not in a function); did you mean 'mtk_afe_pcm_ops'?
.pcm_new = mtk_afe_pcm_new, ^~~~~~~~~~~~~~~ mtk_afe_pcm_ops
sound/soc/mediatek/mt6797/mt6797-afe-pcm.c:732:14: error: 'mtk_afe_pcm_free' undeclared here (not in a function); did you mean 'mtk_afe_pcm_new'?
.pcm_free = mtk_afe_pcm_free, ^~~~~~~~~~~~~~~~ mtk_afe_pcm_new
vim +730 sound/soc/mediatek/mt6797/mt6797-afe-pcm.c
727 728 static const struct snd_soc_component_driver mt6797_afe_component = { 729 .name = AFE_PCM_NAME,
730 .ops = &mtk_afe_pcm_ops, 731 .pcm_new = mtk_afe_pcm_new, 732 .pcm_free = mtk_afe_pcm_free,
733 .probe = mt6797_afe_component_probe, 734 }; 735
--- 0-DAY kernel test infrastructure Open Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation
The patch
ASoC: mediatek: add sub dai to mtk_base_afe
has been applied to the asoc tree at
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks, Mark
From 13be427e5df4cea08c2d48017aabe112400e1b2f Mon Sep 17 00:00:00 2001
From: KaiChieh Chuang kaichieh.chuang@mediatek.com Date: Fri, 25 May 2018 11:48:16 +0800 Subject: [PATCH] ASoC: mediatek: add sub dai to mtk_base_afe
In MediaTek SoC chip we have multiple DAI, such as I2S, ADDA, PCM, etc.
Organize each DAI in to one sub dai, with its dai driver, controls, widgets, routes.
add mtk_afe_combine_sub_dai() to combine dai driver from each DAI.
add mtk_afe_add_sub_dai_control() to register the control, widget, routes to component.
Signed-off-by: KaiChieh Chuang kaichieh.chuang@mediatek.com Signed-off-by: Mark Brown broonie@kernel.org --- .../mediatek/common/mtk-afe-platform-driver.c | 78 +++++++++++++++++++ .../mediatek/common/mtk-afe-platform-driver.h | 5 ++ sound/soc/mediatek/common/mtk-base-afe.h | 18 +++++ 3 files changed, 101 insertions(+)
diff --git a/sound/soc/mediatek/common/mtk-afe-platform-driver.c b/sound/soc/mediatek/common/mtk-afe-platform-driver.c index 8966ee138387..c4491883090d 100644 --- a/sound/soc/mediatek/common/mtk-afe-platform-driver.c +++ b/sound/soc/mediatek/common/mtk-afe-platform-driver.c @@ -13,6 +13,84 @@ #include "mtk-afe-platform-driver.h" #include "mtk-base-afe.h"
+int mtk_afe_combine_sub_dai(struct mtk_base_afe *afe) +{ + struct snd_soc_dai_driver *sub_dai_drivers; + size_t num_dai_drivers = 0, dai_idx = 0; + int i; + + if (!afe->sub_dais) { + dev_err(afe->dev, "%s(), sub_dais == NULL\n", __func__); + return -EINVAL; + } + + /* calcualte total dai driver size */ + for (i = 0; i < afe->num_sub_dais; i++) { + if (afe->sub_dais[i].dai_drivers && + afe->sub_dais[i].num_dai_drivers != 0) + num_dai_drivers += afe->sub_dais[i].num_dai_drivers; + } + + dev_info(afe->dev, "%s(), num of dai %zd\n", __func__, num_dai_drivers); + + /* combine sub_dais */ + afe->num_dai_drivers = num_dai_drivers; + afe->dai_drivers = devm_kcalloc(afe->dev, + num_dai_drivers, + sizeof(struct snd_soc_dai_driver), + GFP_KERNEL); + if (!afe->dai_drivers) + return -ENOMEM; + + for (i = 0; i < afe->num_sub_dais; i++) { + if (afe->sub_dais[i].dai_drivers && + afe->sub_dais[i].num_dai_drivers != 0) { + sub_dai_drivers = afe->sub_dais[i].dai_drivers; + /* dai driver */ + memcpy(&afe->dai_drivers[dai_idx], + sub_dai_drivers, + afe->sub_dais[i].num_dai_drivers * + sizeof(struct snd_soc_dai_driver)); + dai_idx += afe->sub_dais[i].num_dai_drivers; + } + } + + return 0; +} + +int mtk_afe_add_sub_dai_control(struct snd_soc_component *component) +{ + struct mtk_base_afe *afe = snd_soc_component_get_drvdata(component); + int i; + + if (!afe->sub_dais) { + dev_err(afe->dev, "%s(), sub_dais == NULL\n", __func__); + return -EINVAL; + } + + for (i = 0; i < afe->num_sub_dais; i++) { + if (afe->sub_dais[i].controls) + snd_soc_add_component_controls(component, + afe->sub_dais[i].controls, + afe->sub_dais[i].num_controls); + + if (afe->sub_dais[i].dapm_widgets) + snd_soc_dapm_new_controls(&component->dapm, + afe->sub_dais[i].dapm_widgets, + afe->sub_dais[i].num_dapm_widgets); + + if (afe->sub_dais[i].dapm_routes) + snd_soc_dapm_add_routes(&component->dapm, + afe->sub_dais[i].dapm_routes, + afe->sub_dais[i].num_dapm_routes); + } + + snd_soc_dapm_new_widgets(component->dapm.card); + + return 0; + +} + static snd_pcm_uframes_t mtk_afe_pcm_pointer (struct snd_pcm_substream *substream) { diff --git a/sound/soc/mediatek/common/mtk-afe-platform-driver.h b/sound/soc/mediatek/common/mtk-afe-platform-driver.h index 1c81d911cf2a..0c31fa4b6f8c 100644 --- a/sound/soc/mediatek/common/mtk-afe-platform-driver.h +++ b/sound/soc/mediatek/common/mtk-afe-platform-driver.h @@ -12,5 +12,10 @@ #define AFE_PCM_NAME "mtk-afe-pcm" extern const struct snd_soc_component_driver mtk_afe_pcm_platform;
+struct mtk_base_afe; +struct snd_soc_component; + +int mtk_afe_combine_sub_dai(struct mtk_base_afe *afe); +int mtk_afe_add_sub_dai_control(struct snd_soc_component *component); #endif
diff --git a/sound/soc/mediatek/common/mtk-base-afe.h b/sound/soc/mediatek/common/mtk-base-afe.h index c2c5a6c5751d..bcf562f029b6 100644 --- a/sound/soc/mediatek/common/mtk-base-afe.h +++ b/sound/soc/mediatek/common/mtk-base-afe.h @@ -48,6 +48,7 @@ struct mtk_base_irq_data { struct device; struct mtk_base_afe_memif; struct mtk_base_afe_irq; +struct mtk_base_afe_dai; struct regmap; struct snd_pcm_substream; struct snd_soc_dai; @@ -71,6 +72,11 @@ struct mtk_base_afe { struct mtk_base_afe_irq *irqs; int irqs_size;
+ struct mtk_base_afe_dai *sub_dais; + int num_sub_dais; + struct snd_soc_dai_driver *dai_drivers; + unsigned int num_dai_drivers; + const struct snd_pcm_hardware *mtk_afe_hardware; int (*memif_fs)(struct snd_pcm_substream *substream, unsigned int rate); @@ -94,5 +100,17 @@ struct mtk_base_afe_irq { int irq_occupyed; };
+struct mtk_base_afe_dai { + struct snd_soc_dai_driver *dai_drivers; + unsigned int num_dai_drivers; + + const struct snd_kcontrol_new *controls; + unsigned int num_controls; + const struct snd_soc_dapm_widget *dapm_widgets; + unsigned int num_dapm_widgets; + const struct snd_soc_dapm_route *dapm_routes; + unsigned int num_dapm_routes; +}; + #endif
participants (3)
-
KaiChieh Chuang
-
kbuild test robot
-
Mark Brown