Skip to content

Commit e794a89

Browse files
Rui Zhoubroonie
authored andcommitted
ASoC: mediatek: mt8188-mt6359: add es8326 support
To use ES8326 as the codec, add a new sound card named mt8186_es8326. Reviewed-by: Trevor Wu <trevor.wu@mediatek.com> Signed-off-by: Rui Zhou <zhourui@huaqin.corp-partner.google.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Link: https://msgid.link/r/20231212123050.4080083-4-zhourui@huaqin.corp-partner.google.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 1a26800 commit e794a89

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

sound/soc/mediatek/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ config SND_SOC_MT8188_MT6359
252252
select SND_SOC_NAU8315
253253
select SND_SOC_NAU8825
254254
select SND_SOC_RT5682S
255+
select SND_SOC_ES8326
255256
help
256257
This adds support for ASoC machine driver for MediaTek MT8188
257258
boards with the MT6359 and other I2S audio codecs.

sound/soc/mediatek/mt8188/mt8188-mt6359.c

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
#define NAU8825_HS_PRESENT BIT(0)
3636
#define RT5682S_HS_PRESENT BIT(1)
37+
#define ES8326_HS_PRESENT BIT(2)
38+
#define MAX98390_TWO_AMP BIT(3)
3739
/*
3840
* Maxim MAX98390
3941
*/
@@ -48,6 +50,11 @@
4850
*/
4951
#define NAU8825_CODEC_DAI "nau8825-hifi"
5052

53+
/*
54+
* ES8326
55+
*/
56+
#define ES8326_CODEC_DAI "ES8326 HiFi"
57+
5158
#define SOF_DMA_DL2 "SOF_DMA_DL2"
5259
#define SOF_DMA_DL3 "SOF_DMA_DL3"
5360
#define SOF_DMA_UL4 "SOF_DMA_UL4"
@@ -888,6 +895,30 @@ static const struct snd_soc_ops mt8188_sof_be_ops = {
888895
.hw_params = mt8188_sof_be_hw_params,
889896
};
890897

898+
static int mt8188_es8326_hw_params(struct snd_pcm_substream *substream,
899+
struct snd_pcm_hw_params *params)
900+
{
901+
struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
902+
struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0);
903+
struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
904+
unsigned int rate = params_rate(params);
905+
int ret;
906+
907+
/* Configure MCLK for codec */
908+
ret = snd_soc_dai_set_sysclk(codec_dai, 0, rate * 256, SND_SOC_CLOCK_IN);
909+
if (ret < 0) {
910+
dev_err(codec_dai->dev, "can't set MCLK %d\n", ret);
911+
return ret;
912+
}
913+
914+
/* Configure MCLK for cpu */
915+
return snd_soc_dai_set_sysclk(cpu_dai, 0, rate * 256, SND_SOC_CLOCK_OUT);
916+
}
917+
918+
static const struct snd_soc_ops mt8188_es8326_ops = {
919+
.hw_params = mt8188_es8326_hw_params,
920+
};
921+
891922
static struct snd_soc_dai_link mt8188_mt6359_dai_links[] = {
892923
/* FE */
893924
[DAI_LINK_DL2_FE] = {
@@ -1197,7 +1228,7 @@ static void mt8188_fixup_controls(struct snd_soc_card *card)
11971228
struct mt8188_card_data *card_data = (struct mt8188_card_data *)priv->private_data;
11981229
struct snd_kcontrol *kctl;
11991230

1200-
if (card_data->quirk & (NAU8825_HS_PRESENT | RT5682S_HS_PRESENT)) {
1231+
if (card_data->quirk & (NAU8825_HS_PRESENT | RT5682S_HS_PRESENT | ES8326_HS_PRESENT)) {
12011232
struct snd_soc_dapm_widget *w, *next_w;
12021233

12031234
for_each_card_widgets_safe(card, w, next_w) {
@@ -1238,6 +1269,7 @@ static int mt8188_mt6359_dev_probe(struct platform_device *pdev)
12381269
struct mt8188_card_data *card_data;
12391270
struct snd_soc_dai_link *dai_link;
12401271
bool init_mt6359 = false;
1272+
bool init_es8326 = false;
12411273
bool init_nau8825 = false;
12421274
bool init_rt5682s = false;
12431275
bool init_max98390 = false;
@@ -1344,7 +1376,14 @@ static int mt8188_mt6359_dev_probe(struct platform_device *pdev)
13441376
strcmp(dai_link->name, "ETDM1_IN_BE") == 0 ||
13451377
strcmp(dai_link->name, "ETDM2_IN_BE") == 0) {
13461378
if (!strcmp(dai_link->codecs->dai_name, MAX98390_CODEC_DAI)) {
1347-
dai_link->ops = &mt8188_max98390_ops;
1379+
/*
1380+
* The TDM protocol settings with fixed 4 slots are defined in
1381+
* mt8188_max98390_ops. Two amps is I2S mode,
1382+
* SOC and codec don't require TDM settings.
1383+
*/
1384+
if (!(card_data->quirk & MAX98390_TWO_AMP)) {
1385+
dai_link->ops = &mt8188_max98390_ops;
1386+
}
13481387
if (!init_max98390) {
13491388
dai_link->init = mt8188_max98390_codec_init;
13501389
init_max98390 = true;
@@ -1363,6 +1402,13 @@ static int mt8188_mt6359_dev_probe(struct platform_device *pdev)
13631402
dai_link->exit = mt8188_headset_codec_exit;
13641403
init_rt5682s = true;
13651404
}
1405+
} else if (!strcmp(dai_link->codecs->dai_name, ES8326_CODEC_DAI)) {
1406+
dai_link->ops = &mt8188_es8326_ops;
1407+
if (!init_es8326) {
1408+
dai_link->init = mt8188_headset_codec_init;
1409+
dai_link->exit = mt8188_headset_codec_exit;
1410+
init_es8326 = true;
1411+
}
13661412
} else {
13671413
if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) {
13681414
if (!init_dumb) {
@@ -1405,10 +1451,16 @@ static struct mt8188_card_data mt8188_rt5682s_card = {
14051451
.quirk = RT5682S_HS_PRESENT,
14061452
};
14071453

1454+
static struct mt8188_card_data mt8188_es8326_card = {
1455+
.name = "mt8188_es8326",
1456+
.quirk = ES8326_HS_PRESENT | MAX98390_TWO_AMP,
1457+
};
1458+
14081459
static const struct of_device_id mt8188_mt6359_dt_match[] = {
14091460
{ .compatible = "mediatek,mt8188-mt6359-evb", .data = &mt8188_evb_card, },
14101461
{ .compatible = "mediatek,mt8188-nau8825", .data = &mt8188_nau8825_card, },
14111462
{ .compatible = "mediatek,mt8188-rt5682s", .data = &mt8188_rt5682s_card, },
1463+
{ .compatible = "mediatek,mt8188-es8326", .data = &mt8188_es8326_card, },
14121464
{ /* sentinel */ },
14131465
};
14141466
MODULE_DEVICE_TABLE(of, mt8188_mt6359_dt_match);

0 commit comments

Comments
 (0)