Skip to content

Commit

Permalink
ASoC: Intel: sof_rt5682: use common module for DMIC links
Browse files Browse the repository at this point in the history
Use intel_board module for dmic01 and dmic16k DAI link initialization.

Reviewed-by: Bard Liao <[email protected]>
Signed-off-by: Brent Lu <[email protected]>
Signed-off-by: Pierre-Louis Bossart <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
Signed-off-by: Mark Brown <[email protected]>
  • Loading branch information
brentlu authored and broonie committed Oct 19, 2023
1 parent f56daaf commit c51fc25
Showing 1 changed file with 17 additions and 64 deletions.
81 changes: 17 additions & 64 deletions sound/soc/intel/boards/sof_rt5682.c
Original file line number Diff line number Diff line change
Expand Up @@ -503,10 +503,6 @@ static const struct snd_soc_dapm_widget sof_widgets[] = {
SND_SOC_DAPM_SPK("Right Spk", NULL),
};

static const struct snd_soc_dapm_widget dmic_widgets[] = {
SND_SOC_DAPM_MIC("SoC DMIC", NULL),
};

static const struct snd_soc_dapm_route sof_map[] = {
/* HP jack connectors - unknown if we have jack detection */
{ "Headphone Jack", NULL, "HPOL" },
Expand All @@ -522,11 +518,6 @@ static const struct snd_soc_dapm_route rt5650_spk_dapm_routes[] = {
{ "Right Spk", NULL, "SPOR" },
};

static const struct snd_soc_dapm_route dmic_map[] = {
/* digital mics */
{"DMic", NULL, "SoC DMIC"},
};

static int rt5650_spk_init(struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_card *card = rtd->card;
Expand All @@ -540,28 +531,6 @@ static int rt5650_spk_init(struct snd_soc_pcm_runtime *rtd)
return ret;
}

static int dmic_init(struct snd_soc_pcm_runtime *rtd)
{
struct snd_soc_card *card = rtd->card;
int ret;

ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets,
ARRAY_SIZE(dmic_widgets));
if (ret) {
dev_err(card->dev, "DMic widget addition failed: %d\n", ret);
/* Don't need to add routes if widget addition failed */
return ret;
}

ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map,
ARRAY_SIZE(dmic_map));

if (ret)
dev_err(card->dev, "DMic map addition failed: %d\n", ret);

return ret;
}

/* sof audio machine driver for rt5682 codec */
static struct snd_soc_card sof_audio_card_rt5682 = {
.name = "rt5682", /* the sof- prefix is added by the core */
Expand Down Expand Up @@ -601,13 +570,6 @@ static struct snd_soc_dai_link_component rt5650_components[] = {
}
};

static struct snd_soc_dai_link_component dmic_component[] = {
{
.name = "dmic-codec",
.dai_name = "dmic-hifi",
}
};

static struct snd_soc_dai_link *
sof_card_dai_links_create(struct device *dev, enum sof_ssp_codec codec_type,
enum sof_ssp_codec amp_type, int ssp_codec,
Expand Down Expand Up @@ -692,29 +654,21 @@ sof_card_dai_links_create(struct device *dev, enum sof_ssp_codec codec_type,
/* dmic */
if (dmic_be_num > 0) {
/* at least we have dmic01 */
links[id].name = "dmic01";
links[id].cpus = &cpus[id];
links[id].cpus->dai_name = "DMIC01 Pin";
links[id].init = dmic_init;
if (dmic_be_num > 1) {
/* set up 2 BE links at most */
links[id + 1].name = "dmic16k";
links[id + 1].cpus = &cpus[id + 1];
links[id + 1].cpus->dai_name = "DMIC16k Pin";
dmic_be_num = 2;
}
ret = sof_intel_board_set_dmic_link(dev, &links[id], id,
SOF_DMIC_01);
if (ret)
return NULL;

id++;
}

for (i = 0; i < dmic_be_num; i++) {
links[id].id = id;
links[id].num_cpus = 1;
links[id].codecs = dmic_component;
links[id].num_codecs = ARRAY_SIZE(dmic_component);
links[id].platforms = platform_component;
links[id].num_platforms = ARRAY_SIZE(platform_component);
links[id].ignore_suspend = 1;
links[id].dpcm_capture = 1;
links[id].no_pcm = 1;
if (dmic_be_num > 1) {
/* set up 2 BE links at most */
ret = sof_intel_board_set_dmic_link(dev, &links[id], id,
SOF_DMIC_16K);
if (ret)
return NULL;

id++;
}

Expand Down Expand Up @@ -865,7 +819,6 @@ static int sof_audio_probe(struct platform_device *pdev)
struct snd_soc_acpi_mach *mach = pdev->dev.platform_data;
struct snd_soc_dai_link *dai_links;
struct sof_card_private *ctx;
int dmic_be_num;
int ret, ssp_amp, ssp_codec;

ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
Expand All @@ -891,15 +844,15 @@ static int sof_audio_probe(struct platform_device *pdev)

if (soc_intel_is_byt() || soc_intel_is_cht()) {
ctx->rt5682.is_legacy_cpu = true;
dmic_be_num = 0;
ctx->dmic_be_num = 0;
/* HDMI is not supported by SOF on Baytrail/CherryTrail */
ctx->hdmi_num = 0;
/* default quirk for legacy cpu */
sof_rt5682_quirk = SOF_RT5682_MCLK_EN |
SOF_RT5682_MCLK_BYTCHT_EN |
SOF_RT5682_SSP_CODEC(2);
} else {
dmic_be_num = 2;
ctx->dmic_be_num = 2;
ctx->hdmi_num = (sof_rt5682_quirk & SOF_RT5682_NUM_HDMIDEV_MASK) >>
SOF_RT5682_NUM_HDMIDEV_SHIFT;
/* default number of HDMI DAI's */
Expand Down Expand Up @@ -938,7 +891,7 @@ static int sof_audio_probe(struct platform_device *pdev)
ssp_codec = sof_rt5682_quirk & SOF_RT5682_SSP_CODEC_MASK;

/* compute number of dai links */
sof_audio_card_rt5682.num_links = 1 + dmic_be_num + ctx->hdmi_num;
sof_audio_card_rt5682.num_links = 1 + ctx->dmic_be_num + ctx->hdmi_num;

if (ctx->amp_type != CODEC_NONE)
sof_audio_card_rt5682.num_links++;
Expand All @@ -953,7 +906,7 @@ static int sof_audio_probe(struct platform_device *pdev)

dai_links = sof_card_dai_links_create(&pdev->dev, ctx->codec_type,
ctx->amp_type, ssp_codec, ssp_amp,
dmic_be_num, ctx->hdmi_num,
ctx->dmic_be_num, ctx->hdmi_num,
ctx->hdmi.idisp_codec,
ctx->rt5682.is_legacy_cpu);
if (!dai_links)
Expand Down

0 comments on commit c51fc25

Please sign in to comment.