Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

board_helper: support amp link #4666

Merged
merged 6 commits into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions sound/soc/intel/boards/sof_board_helpers.c
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,48 @@ int sof_intel_board_set_intel_hdmi_link(struct device *dev,
}
EXPORT_SYMBOL_NS(sof_intel_board_set_intel_hdmi_link, SND_SOC_INTEL_SOF_BOARD_HELPERS);

int sof_intel_board_set_ssp_amp_link(struct device *dev,
struct snd_soc_dai_link *link, int be_id,
enum sof_ssp_codec amp_type, int ssp_amp)
{
struct snd_soc_dai_link_component *cpus;

dev_dbg(dev, "link %d: ssp amp %s, ssp %d\n", be_id,
sof_ssp_get_codec_name(amp_type), ssp_amp);

/* link name */
link->name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec", ssp_amp);
if (!link->name)
return -ENOMEM;

/* cpus */
cpus = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component),
GFP_KERNEL);
if (!cpus)
return -ENOMEM;

cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d Pin", ssp_amp);
if (!cpus->dai_name)
return -ENOMEM;

link->cpus = cpus;
link->num_cpus = 1;

/* codecs - caller to handle */

/* platforms */
link->platforms = platform_component;
link->num_platforms = ARRAY_SIZE(platform_component);

link->id = be_id;
link->no_pcm = 1;
link->dpcm_capture = 1; /* feedback stream or firmware-generated echo reference */
link->dpcm_playback = 1;

return 0;
}
EXPORT_SYMBOL_NS(sof_intel_board_set_ssp_amp_link, SND_SOC_INTEL_SOF_BOARD_HELPERS);

MODULE_DESCRIPTION("ASoC Intel SOF Machine Driver Board Helpers");
MODULE_AUTHOR("Brent Lu <[email protected]>");
MODULE_LICENSE("GPL");
Expand Down
5 changes: 5 additions & 0 deletions sound/soc/intel/boards/sof_board_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ struct sof_rt5682_private {
* @dmic_be_num: number of Intel PCH DMIC BE link
* @hdmi_num: number of Intel HDMI BE link
* @ssp_codec: ssp port number of headphone BE link
* @ssp_amp: ssp port number of speaker BE link
* @rt5682: private data for rt5682 machine driver
*/
struct sof_card_private {
Expand All @@ -44,6 +45,7 @@ struct sof_card_private {
int hdmi_num;

int ssp_codec;
int ssp_amp;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, where will ctx->ssp_amp be used?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I planned to submit another PR later which implements a helper function to generate entire DAI link array according to the content of sof_card_private structure. You could check the code here:

brentlu@e259c8a


union {
struct sof_rt5682_private rt5682;
Expand All @@ -66,5 +68,8 @@ int sof_intel_board_set_dmic_link(struct device *dev,
int sof_intel_board_set_intel_hdmi_link(struct device *dev,
struct snd_soc_dai_link *link, int be_id,
int hdmi_id, bool idisp_codec);
int sof_intel_board_set_ssp_amp_link(struct device *dev,
struct snd_soc_dai_link *link, int be_id,
enum sof_ssp_codec amp_type, int ssp_amp);

#endif /* __SOF_INTEL_BOARD_HELPERS_H */
98 changes: 32 additions & 66 deletions sound/soc/intel/boards/sof_cs42l42.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,62 +189,6 @@ static struct snd_soc_dai_link_component cs42l42_component[] = {
}
};

static int create_spk_amp_dai_links(struct device *dev,
struct snd_soc_dai_link *links,
struct snd_soc_dai_link_component *cpus,
int *id, enum sof_ssp_codec amp_type,
int ssp_amp)
{
int ret = 0;

/* speaker amp */
if (amp_type == CODEC_NONE)
return 0;

links[*id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec",
ssp_amp);
if (!links[*id].name) {
ret = -ENOMEM;
goto devm_err;
}

links[*id].id = *id;

switch (amp_type) {
case CODEC_MAX98357A:
max_98357a_dai_link(&links[*id]);
break;
case CODEC_MAX98360A:
max_98360a_dai_link(&links[*id]);
break;
default:
dev_err(dev, "invalid amp type %d\n", amp_type);
return -EINVAL;
}

links[*id].platforms = platform_component;
links[*id].num_platforms = ARRAY_SIZE(platform_component);
links[*id].dpcm_playback = 1;
/* firmware-generated echo reference */
links[*id].dpcm_capture = 1;

links[*id].no_pcm = 1;
links[*id].cpus = &cpus[*id];
links[*id].num_cpus = 1;

links[*id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
"SSP%d Pin", ssp_amp);
if (!links[*id].cpus->dai_name) {
ret = -ENOMEM;
goto devm_err;
}

(*id)++;

devm_err:
return ret;
}

static int create_bt_offload_dai_links(struct device *dev,
struct snd_soc_dai_link *links,
struct snd_soc_dai_link_component *cpus,
Expand Down Expand Up @@ -330,12 +274,33 @@ sof_card_dai_links_create(struct device *dev, enum sof_ssp_codec amp_type,
id++;
break;
case LINK_SPK:
ret = create_spk_amp_dai_links(dev, links, cpus, &id,
amp_type, ssp_amp);
if (ret < 0) {
dev_err(dev, "fail to create spk amp dai links, ret %d\n",
ret);
goto devm_err;
if (amp_type != CODEC_NONE) {
ret = sof_intel_board_set_ssp_amp_link(dev,
&links[id],
id,
amp_type,
ssp_amp);
if (ret) {
dev_err(dev, "fail to create spk amp dai links, ret %d\n",
ret);
goto devm_err;
}

/* codec-specific fields */
switch (amp_type) {
case CODEC_MAX98357A:
max_98357a_dai_link(&links[id]);
break;
case CODEC_MAX98360A:
max_98360a_dai_link(&links[id]);
break;
default:
dev_err(dev, "invalid amp type %d\n",
amp_type);
goto devm_err;
}

id++;
}
break;
case LINK_DMIC:
Expand Down Expand Up @@ -412,7 +377,7 @@ 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 ret, ssp_bt, ssp_amp;
int ret, ssp_bt;

ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
if (!ctx)
Expand Down Expand Up @@ -444,7 +409,7 @@ static int sof_audio_probe(struct platform_device *pdev)
ssp_bt = (sof_cs42l42_quirk & SOF_CS42L42_SSP_BT_MASK) >>
SOF_CS42L42_SSP_BT_SHIFT;

ssp_amp = (sof_cs42l42_quirk & SOF_CS42L42_SSP_AMP_MASK) >>
ctx->ssp_amp = (sof_cs42l42_quirk & SOF_CS42L42_SSP_AMP_MASK) >>
SOF_CS42L42_SSP_AMP_SHIFT;

ctx->ssp_codec = sof_cs42l42_quirk & SOF_CS42L42_SSP_CODEC_MASK;
Expand All @@ -458,8 +423,9 @@ static int sof_audio_probe(struct platform_device *pdev)
sof_audio_card_cs42l42.num_links++;

dai_links = sof_card_dai_links_create(&pdev->dev, ctx->amp_type,
ctx->ssp_codec, ssp_amp, ssp_bt,
ctx->dmic_be_num, ctx->hdmi_num,
ctx->ssp_codec, ctx->ssp_amp,
ssp_bt, ctx->dmic_be_num,
ctx->hdmi_num,
ctx->hdmi.idisp_codec);
if (!dai_links)
return -ENOMEM;
Expand Down
31 changes: 8 additions & 23 deletions sound/soc/intel/boards/sof_nau8825.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,13 +273,12 @@ sof_card_dai_links_create(struct device *dev, enum sof_ssp_codec amp_type,

/* speaker amp */
if (amp_type != CODEC_NONE) {
links[id].name = devm_kasprintf(dev, GFP_KERNEL,
"SSP%d-Codec", ssp_amp);
if (!links[id].name)
goto devm_err;

links[id].id = id;
ret = sof_intel_board_set_ssp_amp_link(dev, &links[id], id,
amp_type, ssp_amp);
if (ret)
return NULL;

/* codec-specific fields */
switch (amp_type) {
case CODEC_MAX98360A:
max_98360a_dai_link(&links[id]);
Expand All @@ -304,20 +303,6 @@ sof_card_dai_links_create(struct device *dev, enum sof_ssp_codec amp_type,
return NULL;
}

links[id].platforms = platform_component;
links[id].num_platforms = ARRAY_SIZE(platform_component);
links[id].dpcm_playback = 1;
/* feedback stream or firmware-generated echo reference */
links[id].dpcm_capture = 1;

links[id].no_pcm = 1;
links[id].cpus = &cpus[id];
links[id].num_cpus = 1;
links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
"SSP%d Pin",
ssp_amp);
if (!links[id].cpus->dai_name)
goto devm_err;
id++;
}

Expand Down Expand Up @@ -355,7 +340,7 @@ 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 ret, ssp_amp;
int ret;

ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
if (!ctx)
Expand All @@ -380,7 +365,7 @@ static int sof_audio_probe(struct platform_device *pdev)
if (mach->mach_params.codec_mask & IDISP_CODEC_MASK)
ctx->hdmi.idisp_codec = true;

ssp_amp = (sof_nau8825_quirk & SOF_NAU8825_SSP_AMP_MASK) >>
ctx->ssp_amp = (sof_nau8825_quirk & SOF_NAU8825_SSP_AMP_MASK) >>
SOF_NAU8825_SSP_AMP_SHIFT;

ctx->ssp_codec = sof_nau8825_quirk & SOF_NAU8825_SSP_CODEC_MASK;
Expand All @@ -395,7 +380,7 @@ static int sof_audio_probe(struct platform_device *pdev)
sof_audio_card_nau8825.num_links++;

dai_links = sof_card_dai_links_create(&pdev->dev, ctx->amp_type,
ctx->ssp_codec, ssp_amp,
ctx->ssp_codec, ctx->ssp_amp,
ctx->dmic_be_num, ctx->hdmi_num,
ctx->hdmi.idisp_codec);
if (!dai_links)
Expand Down
43 changes: 10 additions & 33 deletions sound/soc/intel/boards/sof_rt5682.c
Original file line number Diff line number Diff line change
Expand Up @@ -666,13 +666,12 @@ sof_card_dai_links_create(struct device *dev, enum sof_ssp_codec codec_type,

/* speaker amp */
if (amp_type != CODEC_NONE) {
links[id].name = devm_kasprintf(dev, GFP_KERNEL,
"SSP%d-Codec", ssp_amp);
if (!links[id].name)
goto devm_err;

links[id].id = id;
ret = sof_intel_board_set_ssp_amp_link(dev, &links[id], id,
amp_type, ssp_amp);
if (ret)
return NULL;

/* codec-specific fields */
switch (amp_type) {
case CODEC_MAX98357A:
max_98357a_dai_link(&links[id]);
Expand Down Expand Up @@ -713,29 +712,6 @@ sof_card_dai_links_create(struct device *dev, enum sof_ssp_codec codec_type,
return NULL;
}

links[id].platforms = platform_component;
links[id].num_platforms = ARRAY_SIZE(platform_component);
links[id].dpcm_playback = 1;
/* feedback stream or firmware-generated echo reference */
links[id].dpcm_capture = 1;

links[id].no_pcm = 1;
links[id].cpus = &cpus[id];
links[id].num_cpus = 1;
if (is_legacy_cpu) {
links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
"ssp%d-port",
ssp_amp);
if (!links[id].cpus->dai_name)
goto devm_err;

} else {
links[id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
"SSP%d Pin",
ssp_amp);
if (!links[id].cpus->dai_name)
goto devm_err;
}
id++;
}

Expand Down Expand Up @@ -801,7 +777,7 @@ 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 ret, ssp_amp;
int ret;

ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
if (!ctx)
Expand Down Expand Up @@ -867,7 +843,7 @@ static int sof_audio_probe(struct platform_device *pdev)

dev_dbg(&pdev->dev, "sof_rt5682_quirk = %lx\n", sof_rt5682_quirk);

ssp_amp = (sof_rt5682_quirk & SOF_RT5682_SSP_AMP_MASK) >>
ctx->ssp_amp = (sof_rt5682_quirk & SOF_RT5682_SSP_AMP_MASK) >>
SOF_RT5682_SSP_AMP_SHIFT;

ctx->ssp_codec = sof_rt5682_quirk & SOF_RT5682_SSP_CODEC_MASK;
Expand All @@ -887,8 +863,9 @@ static int sof_audio_probe(struct platform_device *pdev)
SOF_NO_OF_HDMI_CAPTURE_SSP_SHIFT);

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