Skip to content

Commit 791667f

Browse files
committed
add es8326 dt-bindings, commonize headset codec
Merge series from Rui Zhou <zhourui@huaqin.corp-partner.google.com>: Add dt-bindings for es8326 and codec es8326 support. Remove duplicate code, commonize headset codec init/exit API. At the same time, Enable dual amp max98390 for rt5682s.
2 parents f51daa7 + 3423c3d commit 791667f

3 files changed

Lines changed: 63 additions & 64 deletions

File tree

Documentation/devicetree/bindings/sound/mediatek,mt8188-mt6359.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ allOf:
1515
properties:
1616
compatible:
1717
enum:
18+
- mediatek,mt8188-es8326
1819
- mediatek,mt8188-mt6359-evb
1920
- mediatek,mt8188-nau8825
2021
- mediatek,mt8188-rt5682s

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: 61 additions & 64 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"
@@ -726,7 +733,7 @@ static int mt8188_max98390_codec_init(struct snd_soc_pcm_runtime *rtd)
726733
return 0;
727734
}
728735

729-
static int mt8188_nau8825_codec_init(struct snd_soc_pcm_runtime *rtd)
736+
static int mt8188_headset_codec_init(struct snd_soc_pcm_runtime *rtd)
730737
{
731738
struct snd_soc_card *card = rtd->card;
732739
struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card);
@@ -775,68 +782,13 @@ static int mt8188_nau8825_codec_init(struct snd_soc_pcm_runtime *rtd)
775782
return 0;
776783
};
777784

778-
static int mt8188_rt5682s_codec_init(struct snd_soc_pcm_runtime *rtd)
779-
{
780-
struct snd_soc_card *card = rtd->card;
781-
struct mtk_soc_card_data *soc_card_data = snd_soc_card_get_drvdata(card);
782-
struct mt8188_mt6359_priv *priv = soc_card_data->mach_priv;
783-
struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
784-
struct snd_soc_jack *jack = &priv->headset_jack;
785-
int ret;
786-
787-
ret = snd_soc_dapm_new_controls(&card->dapm, mt8188_nau8825_widgets,
788-
ARRAY_SIZE(mt8188_nau8825_widgets));
789-
if (ret) {
790-
dev_err(rtd->dev, "unable to add rt5682s card widget, ret %d\n", ret);
791-
return ret;
792-
}
793-
794-
ret = snd_soc_add_card_controls(card, mt8188_nau8825_controls,
795-
ARRAY_SIZE(mt8188_nau8825_controls));
796-
if (ret) {
797-
dev_err(rtd->dev, "unable to add rt5682s card controls, ret %d\n", ret);
798-
return ret;
799-
}
800-
801-
ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
802-
SND_JACK_HEADSET | SND_JACK_BTN_0 |
803-
SND_JACK_BTN_1 | SND_JACK_BTN_2 |
804-
SND_JACK_BTN_3,
805-
jack,
806-
nau8825_jack_pins,
807-
ARRAY_SIZE(nau8825_jack_pins));
808-
if (ret) {
809-
dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
810-
return ret;
811-
}
812-
813-
snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
814-
snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
815-
snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
816-
snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
817-
ret = snd_soc_component_set_jack(component, jack, NULL);
818-
819-
if (ret) {
820-
dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
821-
return ret;
822-
}
823-
824-
return 0;
825-
};
826-
827-
static void mt8188_nau8825_codec_exit(struct snd_soc_pcm_runtime *rtd)
785+
static void mt8188_headset_codec_exit(struct snd_soc_pcm_runtime *rtd)
828786
{
829787
struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
830788

831789
snd_soc_component_set_jack(component, NULL, NULL);
832790
}
833791

834-
static void mt8188_rt5682s_codec_exit(struct snd_soc_pcm_runtime *rtd)
835-
{
836-
struct snd_soc_component *component = snd_soc_rtd_to_codec(rtd, 0)->component;
837-
838-
snd_soc_component_set_jack(component, NULL, NULL);
839-
}
840792

841793
static int mt8188_nau8825_hw_params(struct snd_pcm_substream *substream,
842794
struct snd_pcm_hw_params *params)
@@ -943,6 +895,30 @@ static const struct snd_soc_ops mt8188_sof_be_ops = {
943895
.hw_params = mt8188_sof_be_hw_params,
944896
};
945897

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+
946922
static struct snd_soc_dai_link mt8188_mt6359_dai_links[] = {
947923
/* FE */
948924
[DAI_LINK_DL2_FE] = {
@@ -1252,7 +1228,7 @@ static void mt8188_fixup_controls(struct snd_soc_card *card)
12521228
struct mt8188_card_data *card_data = (struct mt8188_card_data *)priv->private_data;
12531229
struct snd_kcontrol *kctl;
12541230

1255-
if (card_data->quirk & (NAU8825_HS_PRESENT | RT5682S_HS_PRESENT)) {
1231+
if (card_data->quirk & (NAU8825_HS_PRESENT | RT5682S_HS_PRESENT | ES8326_HS_PRESENT)) {
12561232
struct snd_soc_dapm_widget *w, *next_w;
12571233

12581234
for_each_card_widgets_safe(card, w, next_w) {
@@ -1293,6 +1269,7 @@ static int mt8188_mt6359_dev_probe(struct platform_device *pdev)
12931269
struct mt8188_card_data *card_data;
12941270
struct snd_soc_dai_link *dai_link;
12951271
bool init_mt6359 = false;
1272+
bool init_es8326 = false;
12961273
bool init_nau8825 = false;
12971274
bool init_rt5682s = false;
12981275
bool init_max98390 = false;
@@ -1399,25 +1376,39 @@ static int mt8188_mt6359_dev_probe(struct platform_device *pdev)
13991376
strcmp(dai_link->name, "ETDM1_IN_BE") == 0 ||
14001377
strcmp(dai_link->name, "ETDM2_IN_BE") == 0) {
14011378
if (!strcmp(dai_link->codecs->dai_name, MAX98390_CODEC_DAI)) {
1402-
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+
}
14031387
if (!init_max98390) {
14041388
dai_link->init = mt8188_max98390_codec_init;
14051389
init_max98390 = true;
14061390
}
14071391
} else if (!strcmp(dai_link->codecs->dai_name, NAU8825_CODEC_DAI)) {
14081392
dai_link->ops = &mt8188_nau8825_ops;
14091393
if (!init_nau8825) {
1410-
dai_link->init = mt8188_nau8825_codec_init;
1411-
dai_link->exit = mt8188_nau8825_codec_exit;
1394+
dai_link->init = mt8188_headset_codec_init;
1395+
dai_link->exit = mt8188_headset_codec_exit;
14121396
init_nau8825 = true;
14131397
}
14141398
} else if (!strcmp(dai_link->codecs->dai_name, RT5682S_CODEC_DAI)) {
14151399
dai_link->ops = &mt8188_rt5682s_i2s_ops;
14161400
if (!init_rt5682s) {
1417-
dai_link->init = mt8188_rt5682s_codec_init;
1418-
dai_link->exit = mt8188_rt5682s_codec_exit;
1401+
dai_link->init = mt8188_headset_codec_init;
1402+
dai_link->exit = mt8188_headset_codec_exit;
14191403
init_rt5682s = true;
14201404
}
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+
}
14211412
} else {
14221413
if (strcmp(dai_link->codecs->dai_name, "snd-soc-dummy-dai")) {
14231414
if (!init_dumb) {
@@ -1457,13 +1448,19 @@ static struct mt8188_card_data mt8188_nau8825_card = {
14571448

14581449
static struct mt8188_card_data mt8188_rt5682s_card = {
14591450
.name = "mt8188_rt5682s",
1460-
.quirk = RT5682S_HS_PRESENT,
1451+
.quirk = RT5682S_HS_PRESENT | MAX98390_TWO_AMP,
1452+
};
1453+
1454+
static struct mt8188_card_data mt8188_es8326_card = {
1455+
.name = "mt8188_es8326",
1456+
.quirk = ES8326_HS_PRESENT | MAX98390_TWO_AMP,
14611457
};
14621458

14631459
static const struct of_device_id mt8188_mt6359_dt_match[] = {
14641460
{ .compatible = "mediatek,mt8188-mt6359-evb", .data = &mt8188_evb_card, },
14651461
{ .compatible = "mediatek,mt8188-nau8825", .data = &mt8188_nau8825_card, },
14661462
{ .compatible = "mediatek,mt8188-rt5682s", .data = &mt8188_rt5682s_card, },
1463+
{ .compatible = "mediatek,mt8188-es8326", .data = &mt8188_es8326_card, },
14671464
{ /* sentinel */ },
14681465
};
14691466
MODULE_DEVICE_TABLE(of, mt8188_mt6359_dt_match);

0 commit comments

Comments
 (0)