Skip to content

Commit eaa4677

Browse files
brentluplbossart
authored andcommitted
ASoC: Intel: sof_rt5682: code refactory for max98357a
Refactor the machine driver by using the common code in maxim-common module to support max98357a. Signed-off-by: Brent Lu <brent.lu@intel.com>
1 parent 1f5b707 commit eaa4677

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

sound/soc/intel/boards/sof_rt5682.c

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -451,20 +451,26 @@ static int sof_card_late_probe(struct snd_soc_card *card)
451451
static const struct snd_kcontrol_new sof_controls[] = {
452452
SOC_DAPM_PIN_SWITCH("Headphone Jack"),
453453
SOC_DAPM_PIN_SWITCH("Headset Mic"),
454-
SOC_DAPM_PIN_SWITCH("Spk"),
455454
SOC_DAPM_PIN_SWITCH("Left Spk"),
456455
SOC_DAPM_PIN_SWITCH("Right Spk"),
457456

458457
};
459458

459+
static const struct snd_kcontrol_new speaker_controls[] = {
460+
SOC_DAPM_PIN_SWITCH("Spk"),
461+
};
462+
460463
static const struct snd_soc_dapm_widget sof_widgets[] = {
461464
SND_SOC_DAPM_HP("Headphone Jack", NULL),
462465
SND_SOC_DAPM_MIC("Headset Mic", NULL),
463-
SND_SOC_DAPM_SPK("Spk", NULL),
464466
SND_SOC_DAPM_SPK("Left Spk", NULL),
465467
SND_SOC_DAPM_SPK("Right Spk", NULL),
466468
};
467469

470+
static const struct snd_soc_dapm_widget speaker_widgets[] = {
471+
SND_SOC_DAPM_SPK("Spk", NULL),
472+
};
473+
468474
static const struct snd_soc_dapm_widget dmic_widgets[] = {
469475
SND_SOC_DAPM_MIC("SoC DMIC", NULL),
470476
};
@@ -504,6 +510,21 @@ static int speaker_codec_init(struct snd_soc_pcm_runtime *rtd)
504510
struct snd_soc_card *card = rtd->card;
505511
int ret;
506512

513+
ret = snd_soc_dapm_new_controls(&card->dapm, speaker_widgets,
514+
ARRAY_SIZE(speaker_widgets));
515+
if (ret) {
516+
dev_err(rtd->dev, "unable to add dapm controls, ret %d\n", ret);
517+
/* Don't need to add routes if widget addition failed */
518+
return ret;
519+
}
520+
521+
ret = snd_soc_add_card_controls(card, speaker_controls,
522+
ARRAY_SIZE(speaker_controls));
523+
if (ret) {
524+
dev_err(rtd->dev, "unable to add card controls, ret %d\n", ret);
525+
return ret;
526+
}
527+
507528
ret = snd_soc_dapm_add_routes(&card->dapm, speaker_map,
508529
ARRAY_SIZE(speaker_map));
509530

@@ -573,13 +594,6 @@ static struct snd_soc_dai_link_component dmic_component[] = {
573594
}
574595
};
575596

576-
static struct snd_soc_dai_link_component max98357a_component[] = {
577-
{
578-
.name = "MX98357A:00",
579-
.dai_name = "HiFi",
580-
}
581-
};
582-
583597
static struct snd_soc_dai_link_component max98360a_component[] = {
584598
{
585599
.name = "MX98360A:00",
@@ -768,9 +782,7 @@ static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
768782
SOF_RT1011_SPEAKER_AMP_PRESENT) {
769783
sof_rt1011_dai_link(&links[id]);
770784
} else {
771-
links[id].codecs = max98357a_component;
772-
links[id].num_codecs = ARRAY_SIZE(max98357a_component);
773-
links[id].init = speaker_codec_init;
785+
max_98357a_dai_link(&links[id]);
774786
}
775787
links[id].platforms = platform_component;
776788
links[id].num_platforms = ARRAY_SIZE(platform_component);

0 commit comments

Comments
 (0)