Skip to content

Commit 4bdc8d4

Browse files
Garlic Tsengbroonie
authored andcommitted
ASoC: mediatek: add BT implementation
Add BT implementation for mt2701 platform driver. Signed-off-by: Garlic Tseng <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent 1f458d5 commit 4bdc8d4

File tree

1 file changed

+139
-0
lines changed

1 file changed

+139
-0
lines changed

sound/soc/mediatek/mt2701/mt2701-afe-pcm.c

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,86 @@ static int mt2701_afe_i2s_set_sysclk(struct snd_soc_dai *dai, int clk_id,
333333
return 0;
334334
}
335335

336+
static int mt2701_btmrg_startup(struct snd_pcm_substream *substream,
337+
struct snd_soc_dai *dai)
338+
{
339+
struct snd_soc_pcm_runtime *rtd = substream->private_data;
340+
struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
341+
struct mt2701_afe_private *afe_priv = afe->platform_priv;
342+
343+
regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
344+
AUDIO_TOP_CON4_PDN_MRGIF, 0);
345+
346+
afe_priv->mrg_enable[substream->stream] = 1;
347+
return 0;
348+
}
349+
350+
static int mt2701_btmrg_hw_params(struct snd_pcm_substream *substream,
351+
struct snd_pcm_hw_params *params,
352+
struct snd_soc_dai *dai)
353+
{
354+
struct snd_soc_pcm_runtime *rtd = substream->private_data;
355+
struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
356+
int stream_fs;
357+
u32 val, msk;
358+
359+
stream_fs = params_rate(params);
360+
361+
if ((stream_fs != 8000) && (stream_fs != 16000)) {
362+
dev_err(afe->dev, "%s() btmgr not supprt this stream_fs %d\n",
363+
__func__, stream_fs);
364+
return -EINVAL;
365+
}
366+
367+
regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
368+
AFE_MRGIF_CON_I2S_MODE_MASK,
369+
AFE_MRGIF_CON_I2S_MODE_32K);
370+
371+
val = AFE_DAIBT_CON0_BT_FUNC_EN | AFE_DAIBT_CON0_BT_FUNC_RDY
372+
| AFE_DAIBT_CON0_MRG_USE;
373+
msk = val;
374+
375+
if (stream_fs == 16000)
376+
val |= AFE_DAIBT_CON0_BT_WIDE_MODE_EN;
377+
378+
msk |= AFE_DAIBT_CON0_BT_WIDE_MODE_EN;
379+
380+
regmap_update_bits(afe->regmap, AFE_DAIBT_CON0, msk, val);
381+
382+
regmap_update_bits(afe->regmap, AFE_DAIBT_CON0,
383+
AFE_DAIBT_CON0_DAIBT_EN,
384+
AFE_DAIBT_CON0_DAIBT_EN);
385+
regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
386+
AFE_MRGIF_CON_MRG_I2S_EN,
387+
AFE_MRGIF_CON_MRG_I2S_EN);
388+
regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
389+
AFE_MRGIF_CON_MRG_EN,
390+
AFE_MRGIF_CON_MRG_EN);
391+
return 0;
392+
}
393+
394+
static void mt2701_btmrg_shutdown(struct snd_pcm_substream *substream,
395+
struct snd_soc_dai *dai)
396+
{
397+
struct snd_soc_pcm_runtime *rtd = substream->private_data;
398+
struct mtk_base_afe *afe = snd_soc_platform_get_drvdata(rtd->platform);
399+
struct mt2701_afe_private *afe_priv = afe->platform_priv;
400+
401+
/* if the other direction stream is not occupied */
402+
if (!afe_priv->mrg_enable[!substream->stream]) {
403+
regmap_update_bits(afe->regmap, AFE_DAIBT_CON0,
404+
AFE_DAIBT_CON0_DAIBT_EN, 0);
405+
regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
406+
AFE_MRGIF_CON_MRG_EN, 0);
407+
regmap_update_bits(afe->regmap, AFE_MRGIF_CON,
408+
AFE_MRGIF_CON_MRG_I2S_EN, 0);
409+
regmap_update_bits(afe->regmap, AUDIO_TOP_CON4,
410+
AUDIO_TOP_CON4_PDN_MRGIF,
411+
AUDIO_TOP_CON4_PDN_MRGIF);
412+
}
413+
afe_priv->mrg_enable[substream->stream] = 0;
414+
}
415+
336416
static int mt2701_simple_fe_startup(struct snd_pcm_substream *substream,
337417
struct snd_soc_dai *dai)
338418
{
@@ -514,6 +594,13 @@ static const struct snd_soc_dai_ops mt2701_afe_i2s_ops = {
514594
.set_sysclk = mt2701_afe_i2s_set_sysclk,
515595
};
516596

597+
/* MRG BE DAIs */
598+
static struct snd_soc_dai_ops mt2701_btmrg_ops = {
599+
.startup = mt2701_btmrg_startup,
600+
.shutdown = mt2701_btmrg_shutdown,
601+
.hw_params = mt2701_btmrg_hw_params,
602+
};
603+
517604
static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
518605
/* FE DAIs: memory intefaces to CPU */
519606
{
@@ -566,6 +653,36 @@ static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
566653
},
567654
.ops = &mt2701_single_memif_dai_ops,
568655
},
656+
{
657+
.name = "PCM_BT_DL",
658+
.id = MT2701_MEMIF_DLBT,
659+
.suspend = mtk_afe_dai_suspend,
660+
.resume = mtk_afe_dai_resume,
661+
.playback = {
662+
.stream_name = "DLBT",
663+
.channels_min = 1,
664+
.channels_max = 1,
665+
.rates = (SNDRV_PCM_RATE_8000
666+
| SNDRV_PCM_RATE_16000),
667+
.formats = SNDRV_PCM_FMTBIT_S16_LE,
668+
},
669+
.ops = &mt2701_single_memif_dai_ops,
670+
},
671+
{
672+
.name = "PCM_BT_UL",
673+
.id = MT2701_MEMIF_ULBT,
674+
.suspend = mtk_afe_dai_suspend,
675+
.resume = mtk_afe_dai_resume,
676+
.capture = {
677+
.stream_name = "ULBT",
678+
.channels_min = 1,
679+
.channels_max = 1,
680+
.rates = (SNDRV_PCM_RATE_8000
681+
| SNDRV_PCM_RATE_16000),
682+
.formats = SNDRV_PCM_FMTBIT_S16_LE,
683+
},
684+
.ops = &mt2701_single_memif_dai_ops,
685+
},
569686
/* BE DAIs */
570687
{
571688
.name = "I2S0",
@@ -665,6 +782,28 @@ static struct snd_soc_dai_driver mt2701_afe_pcm_dais[] = {
665782
.ops = &mt2701_afe_i2s_ops,
666783
.symmetric_rates = 1,
667784
},
785+
{
786+
.name = "MRG BT",
787+
.id = MT2701_IO_MRG,
788+
.playback = {
789+
.stream_name = "BT Playback",
790+
.channels_min = 1,
791+
.channels_max = 1,
792+
.rates = (SNDRV_PCM_RATE_8000
793+
| SNDRV_PCM_RATE_16000),
794+
.formats = SNDRV_PCM_FMTBIT_S16_LE,
795+
},
796+
.capture = {
797+
.stream_name = "BT Capture",
798+
.channels_min = 1,
799+
.channels_max = 1,
800+
.rates = (SNDRV_PCM_RATE_8000
801+
| SNDRV_PCM_RATE_16000),
802+
.formats = SNDRV_PCM_FMTBIT_S16_LE,
803+
},
804+
.ops = &mt2701_btmrg_ops,
805+
.symmetric_rates = 1,
806+
}
668807
};
669808

670809
static const struct snd_kcontrol_new mt2701_afe_o00_mix[] = {

0 commit comments

Comments
 (0)