From 499ab1a3cd379fc24ba579c16e1bbb220f4dc4c1 Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Tue, 17 Nov 2026 15:58:14 +0800 Subject: [PATCH 01/11] ASoC: Intel: sof_sdw: free sof_ends when sof_aux fail to allocate sof_ends has already been allocated by kzalloc_objs() when sof_aux fail to allocate. goto err_end to free sof_ends Fixes: c66297d09e1a ("ASoC: intel: sof_sdw: Add ability to have auxiliary devices") Signed-off-by: Bard Liao --- sound/soc/intel/boards/sof_sdw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sound/soc/intel/boards/sof_sdw.c b/sound/soc/intel/boards/sof_sdw.c index 5a4620faa9514f..a6a4766113419d 100644 --- a/sound/soc/intel/boards/sof_sdw.c +++ b/sound/soc/intel/boards/sof_sdw.c @@ -1304,7 +1304,7 @@ static int sof_card_dai_links_create(struct snd_soc_card *card) sof_aux = devm_kcalloc(dev, num_aux, sizeof(*sof_aux), GFP_KERNEL); if (!sof_aux) { ret = -ENOMEM; - goto err_dai; + goto err_end; } ret = asoc_sdw_parse_sdw_endpoints(dev, ctx, sof_aux, sof_dais, sof_ends, &num_confs); From ce7563709b638aef4b1fcd2bc9aa163530611016 Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Thu, 29 Oct 2026 08:48:28 +0800 Subject: [PATCH 02/11] ASoC: sdw_utils: add companion amp support Add asoc_sdw_companion_amp_endpoint struct to help machine driver to create codec to codec dai links for SoundWire companion amps. Signed-off-by: Bard Liao --- include/sound/soc_sdw_utils.h | 19 +++- sound/soc/amd/acp/acp-sdw-legacy-mach.c | 17 ++- sound/soc/amd/acp/acp-sdw-sof-mach.c | 17 ++- sound/soc/intel/boards/sof_sdw.c | 135 +++++++++++++++++++++++- sound/soc/sdw_utils/soc_sdw_utils.c | 105 ++++++++++++++++-- 5 files changed, 271 insertions(+), 22 deletions(-) diff --git a/include/sound/soc_sdw_utils.h b/include/sound/soc_sdw_utils.h index 418466438ea1cb..3502548c9a6b90 100644 --- a/include/sound/soc_sdw_utils.h +++ b/include/sound/soc_sdw_utils.h @@ -30,6 +30,14 @@ */ #define SOC_SDW_SIDECAR_AMPS BIT(16) #define SOC_SDW_CODEC_MIC BIT(17) +/* + * Unlike the sidecar amps, which are not on the SoundWire bus the companion amps are SoundWire + * peripherals. They get their audio data from another SoundWire peripheral (the main amp) over + * the SoundWire bus instead of from the host, so a codec-to-codec dai link is created between + * the main amp and the companion amps. + */ +/* BIT 18:21 is used by SOF_SSP_BT_OFFLOAD which are defined in sof_sdw_common.h */ +#define SOC_SDW_COMPANION_AMPS BIT(22) #define SOC_SDW_UNUSED_DAI_ID -1 #define SOC_SDW_JACK_OUT_DAI_ID 0 @@ -128,6 +136,11 @@ struct asoc_sdw_dailink { struct list_head endpoints; }; +struct asoc_sdw_companion_amp_endpoint { + struct asoc_sdw_endpoint *main_amp; + struct list_head comp_ends; +}; + extern struct asoc_sdw_codec_info codec_info_list[]; int asoc_sdw_get_codec_info_list_count(void); @@ -176,10 +189,13 @@ int asoc_sdw_init_simple_dai_link(struct device *dev, struct snd_soc_dai_link *d const struct snd_soc_ops *ops); int asoc_sdw_count_sdw_endpoints(struct snd_soc_card *card, - int *num_devs, int *num_ends, int *num_aux); + int *num_devs, int *num_ends, int *num_aux, int *num_comp_amps); struct asoc_sdw_dailink *asoc_sdw_find_dailink(struct asoc_sdw_dailink *dailinks, const struct snd_soc_acpi_endpoint *new); +int asoc_sdw_find_amp_endpoints(struct asoc_sdw_dailink *dailink, + struct asoc_sdw_endpoint **amp_ends, + int max_ends); int asoc_sdw_get_dai_type(u32 type); int asoc_sdw_parse_sdw_endpoints(struct device *dev, @@ -187,6 +203,7 @@ int asoc_sdw_parse_sdw_endpoints(struct device *dev, struct snd_soc_aux_dev *soc_aux, struct asoc_sdw_dailink *soc_dais, struct asoc_sdw_endpoint *soc_ends, + struct asoc_sdw_companion_amp_endpoint *comp_ends, int *num_devs); int asoc_sdw_rtd_init(struct snd_soc_pcm_runtime *rtd); diff --git a/sound/soc/amd/acp/acp-sdw-legacy-mach.c b/sound/soc/amd/acp/acp-sdw-legacy-mach.c index a8b62817b2344e..0a6d1d91a5c4fa 100644 --- a/sound/soc/amd/acp/acp-sdw-legacy-mach.c +++ b/sound/soc/amd/acp/acp-sdw-legacy-mach.c @@ -415,9 +415,11 @@ static int soc_card_dai_links_create(struct snd_soc_card *card) struct device *dev = card->dev; int sdw_be_num = 0, dmic_num = 0; struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); + struct asoc_sdw_companion_amp_endpoint *sof_comp_ends; struct snd_soc_aux_dev *soc_aux; struct snd_soc_codec_conf *codec_conf; struct snd_soc_dai_link *dai_links; + int num_comp_amps = 0; int num_devs = 0; int num_ends = 0; int num_aux = 0; @@ -425,8 +427,9 @@ static int soc_card_dai_links_create(struct snd_soc_card *card) int num_links; int be_id = 0; int ret; + int i; - ret = asoc_sdw_count_sdw_endpoints(card, &num_devs, &num_ends, &num_aux); + ret = asoc_sdw_count_sdw_endpoints(card, &num_devs, &num_ends, &num_aux, &num_comp_amps); if (ret < 0) { dev_err(dev, "failed to count devices/endpoints: %d\n", ret); return ret; @@ -442,7 +445,7 @@ static int soc_card_dai_links_create(struct snd_soc_card *card) /* One per endpoint, ie. each DAI on each codec/amp */ struct asoc_sdw_endpoint *soc_ends __free(kfree) = - kzalloc_objs(*soc_ends, num_ends); + kzalloc_objs(*soc_ends, num_ends + num_comp_amps); if (!soc_ends) return -ENOMEM; @@ -450,7 +453,15 @@ static int soc_card_dai_links_create(struct snd_soc_card *card) if (!soc_aux) return -ENOMEM; - ret = asoc_sdw_parse_sdw_endpoints(dev, ctx, soc_aux, soc_dais, soc_ends, &num_confs); + sof_comp_ends = devm_kcalloc(dev, num_comp_amps, sizeof(*sof_comp_ends), GFP_KERNEL); + if (!sof_comp_ends) + return -ENOMEM; + + for (i = 0; i < num_comp_amps; i++) + INIT_LIST_HEAD(&sof_comp_ends[i].comp_ends); + + ret = asoc_sdw_parse_sdw_endpoints(dev, ctx, soc_aux, soc_dais, soc_ends, sof_comp_ends, + &num_confs); if (ret < 0) return ret; diff --git a/sound/soc/amd/acp/acp-sdw-sof-mach.c b/sound/soc/amd/acp/acp-sdw-sof-mach.c index ec3e1f5f1052c5..73a6b71ac95397 100644 --- a/sound/soc/amd/acp/acp-sdw-sof-mach.c +++ b/sound/soc/amd/acp/acp-sdw-sof-mach.c @@ -280,9 +280,11 @@ static int sof_card_dai_links_create(struct snd_soc_card *card) int sdw_be_num = 0, dmic_num = 0; struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); struct snd_soc_acpi_mach_params *mach_params = &mach->mach_params; + struct asoc_sdw_companion_amp_endpoint *sof_comp_ends; struct snd_soc_aux_dev *sof_aux; struct snd_soc_codec_conf *codec_conf; struct snd_soc_dai_link *dai_links; + int num_comp_amps = 0; int num_devs = 0; int num_ends = 0; int num_aux = 0; @@ -290,8 +292,9 @@ static int sof_card_dai_links_create(struct snd_soc_card *card) int num_links; int be_id = 0; int ret; + int i; - ret = asoc_sdw_count_sdw_endpoints(card, &num_devs, &num_ends, &num_aux); + ret = asoc_sdw_count_sdw_endpoints(card, &num_devs, &num_ends, &num_aux, &num_comp_amps); if (ret < 0) { dev_err(dev, "failed to count devices/endpoints: %d\n", ret); return ret; @@ -306,7 +309,7 @@ static int sof_card_dai_links_create(struct snd_soc_card *card) /* One per endpoint, ie. each DAI on each codec/amp */ struct asoc_sdw_endpoint *sof_ends __free(kfree) = - kzalloc_objs(*sof_ends, num_ends); + kzalloc_objs(*sof_ends, num_ends + num_comp_amps); if (!sof_ends) return -ENOMEM; @@ -314,7 +317,15 @@ static int sof_card_dai_links_create(struct snd_soc_card *card) if (!sof_aux) return -ENOMEM; - ret = asoc_sdw_parse_sdw_endpoints(dev, ctx, sof_aux, sof_dais, sof_ends, &num_confs); + sof_comp_ends = devm_kcalloc(dev, num_comp_amps, sizeof(*sof_comp_ends), GFP_KERNEL); + if (!sof_comp_ends) + return -ENOMEM; + + for (i = 0; i < num_comp_amps; i++) + INIT_LIST_HEAD(&sof_comp_ends[i].comp_ends); + + ret = asoc_sdw_parse_sdw_endpoints(dev, ctx, sof_aux, sof_dais, sof_ends, sof_comp_ends, + &num_confs); if (ret < 0) return ret; diff --git a/sound/soc/intel/boards/sof_sdw.c b/sound/soc/intel/boards/sof_sdw.c index a6a4766113419d..6a2e1f93af89ae 100644 --- a/sound/soc/intel/boards/sof_sdw.c +++ b/sound/soc/intel/boards/sof_sdw.c @@ -1225,6 +1225,100 @@ static int create_bt_dailinks(struct snd_soc_card *card, return 0; } +static const struct snd_soc_pcm_stream asoc_sdw_bridge_params = { + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | + SNDRV_PCM_FMTBIT_S24_LE, + .rate_min = 48000, + .rate_max = 48000, + .channels_min = 2, + .channels_max = 2, +}; + +static const struct snd_soc_dai_link bridge_dai_template = { + .name = "SDW Companion Amp", + .stream_name = "Companion Amp", + .c2c_params = &asoc_sdw_bridge_params, + .num_c2c_params = 1, +}; + +static int create_sdw_comp_dailinks(struct snd_soc_card *card, + struct snd_soc_dai_link **dai_links, int *be_id, + struct snd_soc_codec_conf **codec_conf, + struct asoc_sdw_companion_amp_endpoint *comp_ends, + int comp_ends_num) +{ + struct device *dev = card->dev; + struct asoc_sdw_endpoint *end; + struct snd_soc_dai_link_component *platform; + struct snd_soc_dai_link_component *codecs; + struct snd_soc_dai_link_component *cpus; + char *name; + int num_codecs; + int i; + + for (i = 0; i < comp_ends_num; i++) { + if (!comp_ends[i].main_amp || list_empty(&comp_ends[i].comp_ends)) { + dev_err(dev, "companion amp group %d: missing main amp or companion amps\n", i); + return -EINVAL; + } + + num_codecs = 0; + list_for_each_entry(end, &comp_ends[i].comp_ends, list) + num_codecs++; + + cpus = devm_kzalloc(dev, sizeof(*cpus), GFP_KERNEL); + if (!cpus) + return -ENOMEM; + + codecs = devm_kcalloc(dev, num_codecs, sizeof(*codecs), GFP_KERNEL); + if (!codecs) + return -ENOMEM; + + platform = devm_kzalloc(dev, sizeof(*platform), GFP_KERNEL); + if (!platform) + return -ENOMEM; + + name = devm_kasprintf(dev, GFP_KERNEL, "SDW Companion Amp %d", i); + if (!name) + return -ENOMEM; + + cpus[0].name = comp_ends[i].main_amp->codec_name; + cpus[0].dai_name = comp_ends[i].main_amp->dai_info->dai_name; + platform->name = cpus[0].name; + + (*codec_conf)->dlc.name = comp_ends[i].main_amp->codec_name; + (*codec_conf)->name_prefix = comp_ends[i].main_amp->name_prefix; + (*codec_conf)++; + + num_codecs = 0; + list_for_each_entry(end, &comp_ends[i].comp_ends, list) { + codecs[num_codecs].name = end->codec_name; + codecs[num_codecs].dai_name = end->dai_info->dai_name; + num_codecs++; + + (*codec_conf)->dlc.name = end->codec_name; + (*codec_conf)->name_prefix = end->name_prefix; + (*codec_conf)++; + } + + **dai_links = bridge_dai_template; + (*dai_links)->name = name; + (*dai_links)->stream_name = name; + (*dai_links)->cpus = cpus; + (*dai_links)->num_cpus = 1; + (*dai_links)->codecs = codecs; + (*dai_links)->num_codecs = num_codecs; + (*dai_links)->platforms = platform; + (*dai_links)->num_platforms = 1; + (*dai_links)->init = asoc_sdw_rtd_init; + (*dai_links)++; + } + + dev_dbg(dev, "Added SDW Companion AMP Codec to Codec link\n"); + + return 0; +} + static int create_echoref_dailink(struct snd_soc_card *card, struct snd_soc_dai_link **dai_links, int *be_id) { @@ -1261,11 +1355,13 @@ static int sof_card_dai_links_create(struct snd_soc_card *card) struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); struct intel_mc_ctx *intel_ctx = (struct intel_mc_ctx *)ctx->private; struct snd_soc_acpi_mach_params *mach_params = &mach->mach_params; + struct asoc_sdw_companion_amp_endpoint *sof_comp_ends; struct snd_soc_codec_conf *codec_conf; struct asoc_sdw_codec_info *ssp_info; struct asoc_sdw_endpoint *sof_ends; struct asoc_sdw_dailink *sof_dais; struct snd_soc_aux_dev *sof_aux; + int num_comp_amps = 0; int num_devs = 0; int num_ends = 0; int num_aux = 0; @@ -1276,8 +1372,9 @@ static int sof_card_dai_links_create(struct snd_soc_card *card) int hdmi_num; unsigned long ssp_mask; int ret; + int i; - ret = asoc_sdw_count_sdw_endpoints(card, &num_devs, &num_ends, &num_aux); + ret = asoc_sdw_count_sdw_endpoints(card, &num_devs, &num_ends, &num_aux, &num_comp_amps); if (ret < 0) { dev_err(dev, "failed to count devices/endpoints: %d\n", ret); return ret; @@ -1307,12 +1404,31 @@ static int sof_card_dai_links_create(struct snd_soc_card *card) goto err_end; } - ret = asoc_sdw_parse_sdw_endpoints(dev, ctx, sof_aux, sof_dais, sof_ends, &num_confs); + sof_comp_ends = devm_kcalloc(dev, num_comp_amps, sizeof(*sof_comp_ends), GFP_KERNEL); + if (!sof_comp_ends) { + ret = -ENOMEM; + goto err_end; + } + + for (i = 0; i < num_comp_amps; i++) + INIT_LIST_HEAD(&sof_comp_ends[i].comp_ends); + + ret = asoc_sdw_parse_sdw_endpoints(dev, ctx, sof_aux, sof_dais, sof_ends, sof_comp_ends, + &num_confs); if (ret < 0) goto err_end; sdw_be_num = ret; + /* Companion amps are not in num_ends but still need a name_prefix codec_conf */ + for (i = 0; i < num_comp_amps; i++) { + struct asoc_sdw_endpoint *comp_end; + + if (sof_comp_ends[i].main_amp) + num_confs++; + list_for_each_entry(comp_end, &sof_comp_ends[i].comp_ends, list) + num_confs++; + } /* * on generic tgl platform, I2S or sdw mode is supported * based on board rework. A ACPI device is registered in @@ -1366,8 +1482,8 @@ static int sof_card_dai_links_create(struct snd_soc_card *card) * This should be the last DAI link and it is expected both for monolithic * and functional SOF topologies to support echo reference. */ - num_links = sdw_be_num + ssp_num + dmic_num + hdmi_num + bt_num + 1; - dai_links = devm_kcalloc(dev, num_links, sizeof(*dai_links), GFP_KERNEL); + num_links = sdw_be_num + ssp_num + dmic_num + hdmi_num + bt_num + num_comp_amps + 1; + dai_links = devm_kcalloc(dev, num_links + 1, sizeof(*dai_links), GFP_KERNEL); if (!dai_links) { ret = -ENOMEM; goto err_end; @@ -1415,6 +1531,17 @@ static int sof_card_dai_links_create(struct snd_soc_card *card) goto err_end; } + /* + * Companion amps are SoundWire peripherals. They get their audio data from another + * SoundWire peripheral (the main amp) over the SoundWire bus instead of from the host, + * so a codec-to-codec dai link is created between the main amp and the companion amps. + */ + if (num_comp_amps) { + ret = create_sdw_comp_dailinks(card, &dai_links, &be_id, &codec_conf, + sof_comp_ends, num_comp_amps); + if (ret) + goto err_end; + } /* dummy echo ref link. keep this as the last DAI link. The DAI link ID does not matter */ ret = create_echoref_dailink(card, &dai_links, &be_id); if (ret) { diff --git a/sound/soc/sdw_utils/soc_sdw_utils.c b/sound/soc/sdw_utils/soc_sdw_utils.c index 7a19de75f32b53..7c20ee811d6564 100644 --- a/sound/soc/sdw_utils/soc_sdw_utils.c +++ b/sound/soc/sdw_utils/soc_sdw_utils.c @@ -2269,12 +2269,14 @@ static int is_sdca_aux_dev_present(struct device *dev, } int asoc_sdw_count_sdw_endpoints(struct snd_soc_card *card, - int *num_devs, int *num_ends, int *num_aux) + int *num_devs, int *num_ends, int *num_aux, int *num_comp_amps) { struct device *dev = card->dev; + struct asoc_sdw_mc_private *ctx = snd_soc_card_get_drvdata(card); struct snd_soc_acpi_mach *mach = dev_get_platdata(dev); struct snd_soc_acpi_mach_params *mach_params = &mach->mach_params; const struct snd_soc_acpi_link_adr *adr_link; + u32 companion_amp_mask = 0; int i, j, ret; for (adr_link = mach_params->links; adr_link->num_adr; adr_link++) { @@ -2284,12 +2286,30 @@ int asoc_sdw_count_sdw_endpoints(struct snd_soc_card *card, const struct snd_soc_acpi_adr_device *adr_dev = &adr_link->adr_d[i]; struct asoc_sdw_codec_info *codec_info; - *num_ends += adr_dev->num_endpoints; - codec_info = asoc_sdw_find_codec_info_part(adr_dev->adr); if (!codec_info) return -EINVAL; + for (j = 0; j < adr_dev->num_endpoints; j++) { + /* Skip companion amps */ + if (adr_dev->endpoints[j].num >= codec_info->dai_num) + continue; + if (codec_info->dais[adr_dev->endpoints[j].num].quirk & SOC_SDW_COMPANION_AMPS) { + if (adr_dev->endpoints[j].group_id >= + BITS_PER_TYPE(companion_amp_mask)) { + dev_err(dev, "invalid companion group_id %d\n", + adr_dev->endpoints[j].group_id); + return -EINVAL; + } + /* The companion amp is only present when the quirk is set */ + if (!(ctx->mc_quirk & SOC_SDW_COMPANION_AMPS)) + continue; + companion_amp_mask |= BIT(adr_dev->endpoints[j].group_id); + continue; + } + (*num_ends)++; + } + for (j = 0; j < codec_info->aux_num; j++) { ret = is_sdca_aux_dev_present(dev, codec_info->auxs[j].codec_name, adr_link, i); @@ -2301,6 +2321,7 @@ int asoc_sdw_count_sdw_endpoints(struct snd_soc_card *card, } } + *num_comp_amps = hweight32(companion_amp_mask); dev_dbg(dev, "Found %d devices with %d endpoints\n", *num_devs, *num_ends); return 0; @@ -2412,16 +2433,41 @@ int asoc_sdw_parse_sdw_endpoints(struct device *dev, struct snd_soc_aux_dev *soc_aux, struct asoc_sdw_dailink *soc_dais, struct asoc_sdw_endpoint *soc_ends, + struct asoc_sdw_companion_amp_endpoint *comp_ends, int *num_devs) { struct snd_soc_acpi_mach *mach = dev_get_platdata(dev); struct snd_soc_acpi_mach_params *mach_params = &mach->mach_params; const struct snd_soc_acpi_link_adr *adr_link; struct asoc_sdw_endpoint *soc_end = soc_ends; + u32 companion_amp_mask = 0; int num_dais = 0; int i, j; int ret; + /* Get companion_amp_mask to calculate the companion amp group array index */ + for (adr_link = mach_params->links; adr_link->num_adr; adr_link++) { + for (i = 0; i < adr_link->num_adr; i++) { + const struct snd_soc_acpi_adr_device *adr_dev = &adr_link->adr_d[i]; + struct asoc_sdw_codec_info *codec_info; + + codec_info = asoc_sdw_find_codec_info_part(adr_dev->adr); + if (!codec_info) + return -EINVAL; + + for (j = 0; j < adr_dev->num_endpoints; j++) { + if (adr_dev->endpoints[j].num >= codec_info->dai_num) + continue; + if (!(codec_info->dais[adr_dev->endpoints[j].num].quirk & + SOC_SDW_COMPANION_AMPS)) + continue; + if (!(ctx->mc_quirk & SOC_SDW_COMPANION_AMPS)) + continue; + companion_amp_mask |= BIT(adr_dev->endpoints[j].group_id); + } + } + } + for (adr_link = mach_params->links; adr_link->num_adr; adr_link++) { int num_link_dailinks = 0; @@ -2492,9 +2538,53 @@ int asoc_sdw_parse_sdw_endpoints(struct device *dev, int stream; adr_end = &adr_dev->endpoints[j]; + if (adr_end->num >= codec_info->dai_num) { + dev_err(dev, + "%d is too many endpoints for codec: 0x%x\n", + adr_end->num, codec_info->part_id); + return -EINVAL; + } dai_info = &codec_info->dais[adr_end->num]; - soc_dai = asoc_sdw_find_dailink(soc_dais, adr_end); + if (dai_info->quirk & SOC_SDW_COMPANION_AMPS) { + struct asoc_sdw_endpoint *comp_end; + int comp_index; + + if (!(ctx->mc_quirk & SOC_SDW_COMPANION_AMPS)) + continue; + + comp_index = hweight32(companion_amp_mask & + (BIT(adr_end->group_id) - 1)); + + codec_name = asoc_sdw_get_codec_name(dev, dai_info, + adr_link, i); + if (IS_ERR(codec_name)) + return PTR_ERR(codec_name); + if (!codec_name) + return -ENOMEM; + + comp_end = devm_kcalloc(dev, 1, sizeof(*comp_end), + GFP_KERNEL); + if (!comp_end) + return -ENOMEM; + comp_end->name_prefix = adr_dev->name_prefix; + + comp_end->link_mask = adr_link->mask; + comp_end->codec_name = codec_name; + comp_end->codec_info = codec_info; + comp_end->dai_info = dai_info; + + /* group_position = 0 is the main amp */ + if (!adr_end->group_position) + comp_ends[comp_index].main_amp = comp_end; + else + list_add_tail(&comp_end->list, + &comp_ends[comp_index].comp_ends); + + continue; + } + + soc_dai = asoc_sdw_find_dailink(soc_dais, adr_end); /* * quirk should have higher priority than the sdca properties * in the BIOS. We can't always check the DAI quirk because we @@ -2538,13 +2628,6 @@ int asoc_sdw_parse_sdw_endpoints(struct device *dev, adr_end->aggregated ? "group" : "solo", adr_end->group_id); - if (adr_end->num >= codec_info->dai_num) { - dev_err(dev, - "%d is too many endpoints for codec: 0x%x\n", - adr_end->num, codec_info->part_id); - return -EINVAL; - } - for_each_pcm_streams(stream) { if (dai_info->direction[stream] && dai_info->dailink[stream] < 0) { From 8f1666fce9b4d3f960dc70ecb56ab672965b2ed2 Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Tue, 10 Nov 2026 11:33:48 +0800 Subject: [PATCH 03/11] soundwire: zero-initialize struct sdw_stream_config in manager drivers The sdw_stream_config structures in the manager drivers are not initialized and only some of the fields are set. Initialize them to zero so that any field added to the structure later, and not explicitly set by these drivers, gets its default value instead of stack garbage. Signed-off-by: Bard Liao --- drivers/soundwire/amd_manager.c | 2 +- drivers/soundwire/intel.c | 2 +- drivers/soundwire/intel_ace2x.c | 4 ++-- drivers/soundwire/qcom.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/soundwire/amd_manager.c b/drivers/soundwire/amd_manager.c index f40a3af4351f6e..c36f7ef5a6cc8a 100644 --- a/drivers/soundwire/amd_manager.c +++ b/drivers/soundwire/amd_manager.c @@ -770,7 +770,7 @@ static int amd_sdw_hw_params(struct snd_pcm_substream *substream, { struct amd_sdw_manager *amd_manager = snd_soc_dai_get_drvdata(dai); struct sdw_amd_dai_runtime *dai_runtime; - struct sdw_stream_config sconfig; + struct sdw_stream_config sconfig = {0}; int ch, dir; int ret; diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c index af65214836b4d0..8d769e5864ed09 100644 --- a/drivers/soundwire/intel.c +++ b/drivers/soundwire/intel.c @@ -725,7 +725,7 @@ static int intel_hw_params(struct snd_pcm_substream *substream, struct sdw_intel *sdw = cdns_to_intel(cdns); struct sdw_cdns_dai_runtime *dai_runtime; struct sdw_cdns_pdi *pdi; - struct sdw_stream_config sconfig; + struct sdw_stream_config sconfig = {0}; int ch, dir; int ret; diff --git a/drivers/soundwire/intel_ace2x.c b/drivers/soundwire/intel_ace2x.c index 642b33ab552606..f7a256adc85331 100644 --- a/drivers/soundwire/intel_ace2x.c +++ b/drivers/soundwire/intel_ace2x.c @@ -53,7 +53,7 @@ static int intel_ace2x_bpt_open_stream(struct sdw_intel *sdw, struct sdw_slave * struct sdw_bus *bus = &cdns->bus; struct sdw_master_prop *prop = &bus->prop; struct sdw_stream_runtime *stream; - struct sdw_stream_config sconfig; + struct sdw_stream_config sconfig = {0}; struct sdw_port_config *pconfig; unsigned int pdi0_buf_size_pre_frame; unsigned int pdi1_buf_size_pre_frame; @@ -724,7 +724,7 @@ static int intel_hw_params(struct snd_pcm_substream *substream, struct sdw_intel *sdw = cdns_to_intel(cdns); struct sdw_cdns_dai_runtime *dai_runtime; struct sdw_cdns_pdi *pdi; - struct sdw_stream_config sconfig; + struct sdw_stream_config sconfig = {0}; int ch, dir; int ret; diff --git a/drivers/soundwire/qcom.c b/drivers/soundwire/qcom.c index f9500d387c7b49..cafe0e66095ea9 100644 --- a/drivers/soundwire/qcom.c +++ b/drivers/soundwire/qcom.c @@ -1302,7 +1302,7 @@ static int qcom_swrm_stream_alloc_ports(struct qcom_swrm_ctrl *ctrl, struct snd_pcm_hw_params *params, int direction) { - struct sdw_stream_config sconfig; + struct sdw_stream_config sconfig = {0}; struct sdw_master_runtime *m_rt; struct sdw_slave_runtime *s_rt; struct sdw_port_runtime *p_rt; From dc5a57be1ff9b180fcfcaed09d9546445a26e593 Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Tue, 8 Sep 2026 10:58:14 +0800 Subject: [PATCH 04/11] soundwire: add companion stream support The companion stream is from peripheral to peripheral and all peripherals need to use the same SoundWire frame area to transfer the stream data. Signed-off-by: Bard Liao --- drivers/soundwire/generic_bandwidth_allocation.c | 4 ++++ drivers/soundwire/stream.c | 4 ++++ include/linux/soundwire/sdw.h | 15 +++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/drivers/soundwire/generic_bandwidth_allocation.c b/drivers/soundwire/generic_bandwidth_allocation.c index 3ca15a612833c1..9afb0044607562 100644 --- a/drivers/soundwire/generic_bandwidth_allocation.c +++ b/drivers/soundwire/generic_bandwidth_allocation.c @@ -70,7 +70,11 @@ void sdw_compute_slave_ports(struct sdw_master_runtime *m_rt, port_bo += bps * ch; slave_total_ch += ch; + } + /* Make sure all Peripherals use the same bit slots */ + if (m_rt->stream->transport_type == SDW_TRANSPORT_PERIPHERAL_PERIPHERAL) + port_bo = t_data->block_offset; if (m_rt->direction == SDW_DATA_DIR_TX && m_rt->ch_count == slave_total_ch) { diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c index 403e00b7327a8a..51d9a4ae742081 100644 --- a/drivers/soundwire/stream.c +++ b/drivers/soundwire/stream.c @@ -412,6 +412,9 @@ static int sdw_enable_disable_ports(struct sdw_master_runtime *m_rt, bool en) } } + if (m_rt->stream->transport_type == SDW_TRANSPORT_PERIPHERAL_PERIPHERAL) + return 0; + /* Enable/Disable Master port(s) */ list_for_each_entry(m_port, &m_rt->port_list, port_node) { ret = sdw_enable_disable_master_ports(m_rt, m_port, en); @@ -1391,6 +1394,7 @@ static int sdw_config_stream(struct device *dev, } stream->type = stream_config->type; + stream->transport_type = stream_config->transport_type; stream->params.rate = stream_config->frame_rate; stream->params.bps = stream_config->bps; diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h index 9e71ae68e9d927..a681d9ec923f21 100644 --- a/include/linux/soundwire/sdw.h +++ b/include/linux/soundwire/sdw.h @@ -760,6 +760,17 @@ struct sdw_port_params { unsigned int data_mode; }; +/** + * enum sdw_transport_type: Data Port transport type + * + * @SDW_TRANSPORT_MANAGER_PERIPHERAL: Data is exchanged between the Manager and a Peripheral + * @SDW_TRANSPORT_PERIPHERAL_PERIPHERAL: Data is exchanged between Peripherals + */ +enum sdw_transport_type { + SDW_TRANSPORT_MANAGER_PERIPHERAL = 0, + SDW_TRANSPORT_PERIPHERAL_PERIPHERAL = 1, +}; + /** * struct sdw_transport_params: Data Port Transport Parameters * @@ -924,6 +935,7 @@ struct sdw_port_config { * @bps: Number of bits per audio sample * @direction: Data direction * @type: Stream type PCM, PDM or BPT + * @transport_type: Manager-Peripheral (default) or Peripheral-Peripheral transport */ struct sdw_stream_config { unsigned int frame_rate; @@ -931,6 +943,7 @@ struct sdw_stream_config { unsigned int bps; enum sdw_data_direction direction; enum sdw_stream_type type; + enum sdw_transport_type transport_type; }; /** @@ -974,6 +987,7 @@ struct sdw_stream_params { * @params: Stream parameters * @state: Current state of the stream * @type: Stream type PCM, PDM or BPT + * @transport_type: Manager-Peripheral or Peripheral-Peripheral transport * @m_rt_count: Count of Master runtime(s) in this stream * @master_list: List of Master runtime(s) in this stream. * master_list can contain only one m_rt per Master instance @@ -984,6 +998,7 @@ struct sdw_stream_runtime { struct sdw_stream_params params; enum sdw_stream_state state; enum sdw_stream_type type; + enum sdw_transport_type transport_type; int m_rt_count; struct list_head master_list; }; From add7f5bf38c5af573436f8779bd2b7b71da4d86e Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Fri, 13 Nov 2026 21:16:32 +0800 Subject: [PATCH 05/11] SoundWire: allocate manager ports for P2P streams Add manager callbacks to reserve and release ports for peripheral-to-peripheral streams. Track DAI-linked and reserved ports on Intel managers, and reuse a stream's existing port when it is reconfigured. Signed-off-by: Bard Liao --- drivers/soundwire/intel.c | 2 + drivers/soundwire/intel.h | 4 ++ drivers/soundwire/intel_ace2x.c | 2 + drivers/soundwire/intel_auxdevice.c | 56 +++++++++++++++++++++ drivers/soundwire/stream.c | 77 +++++++++++++++++++++++++++-- include/linux/soundwire/sdw.h | 5 ++ 6 files changed, 142 insertions(+), 4 deletions(-) diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c index 8d769e5864ed09..d0788f1c3cfe21 100644 --- a/drivers/soundwire/intel.c +++ b/drivers/soundwire/intel.c @@ -963,6 +963,8 @@ static int intel_component_dais_suspend(struct snd_soc_component *component) } static const struct snd_soc_dai_ops intel_pcm_dai_ops = { + .probe = intel_dai_probe, + .remove = intel_dai_remove, .hw_params = intel_hw_params, .prepare = intel_prepare, .hw_free = intel_hw_free, diff --git a/drivers/soundwire/intel.h b/drivers/soundwire/intel.h index 7a2e7e73ad632a..a2a5e9048fee5e 100644 --- a/drivers/soundwire/intel.h +++ b/drivers/soundwire/intel.h @@ -75,6 +75,7 @@ struct sdw_intel_bpt { struct sdw_intel { struct sdw_cdns cdns; int instance; + unsigned long used_ports; struct sdw_intel_link_res *link_res; bool startup_done; struct sdw_intel_bpt bpt_ctx; @@ -126,6 +127,9 @@ static inline void intel_writew(void __iomem *base, int offset, u16 value) #define cdns_to_intel(_cdns) container_of(_cdns, struct sdw_intel, cdns) +int intel_dai_probe(struct snd_soc_dai *dai); +int intel_dai_remove(struct snd_soc_dai *dai); + #define INTEL_MASTER_RESET_ITERATIONS 10 #define SDW_INTEL_DELAYED_ENUMERATION_MS 100 diff --git a/drivers/soundwire/intel_ace2x.c b/drivers/soundwire/intel_ace2x.c index f7a256adc85331..945c497429d4cf 100644 --- a/drivers/soundwire/intel_ace2x.c +++ b/drivers/soundwire/intel_ace2x.c @@ -928,6 +928,8 @@ static int intel_trigger(struct snd_pcm_substream *substream, int cmd, struct sn } static const struct snd_soc_dai_ops intel_pcm_dai_ops = { + .probe = intel_dai_probe, + .remove = intel_dai_remove, .hw_params = intel_hw_params, .prepare = intel_prepare, .hw_free = intel_hw_free, diff --git a/drivers/soundwire/intel_auxdevice.c b/drivers/soundwire/intel_auxdevice.c index 5983fbc5725a26..04c2058f248f24 100644 --- a/drivers/soundwire/intel_auxdevice.c +++ b/drivers/soundwire/intel_auxdevice.c @@ -289,6 +289,60 @@ static void intel_put_device_num_ida(struct sdw_bus *bus, struct sdw_slave *slav ida_free(&intel_peripheral_ida, slave->dev_num); } +static int intel_get_port(struct sdw_bus *bus) +{ + struct sdw_cdns *cdns = bus_to_cdns(bus); + struct sdw_intel *sdw = cdns_to_intel(cdns); + unsigned int limit = min_t(unsigned int, cdns->num_ports, SDW_MAX_PORTS); + unsigned int port; + + port = find_next_zero_bit(&sdw->used_ports, limit, 2); + if (port >= limit) + return -ENOSPC; + + set_bit(port, &sdw->used_ports); + return port; +} + +static void intel_put_port(struct sdw_bus *bus, unsigned int port) +{ + struct sdw_intel *sdw = cdns_to_intel(bus_to_cdns(bus)); + + clear_bit(port, &sdw->used_ports); +} + +int intel_dai_probe(struct snd_soc_dai *dai) +{ + struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai); + struct sdw_intel *sdw = cdns_to_intel(cdns); + int ret = 0; + + if (dai->id >= SDW_MAX_PORTS) + return 0; + + mutex_lock(&cdns->bus.bus_lock); + if (test_and_set_bit(dai->id, &sdw->used_ports)) + ret = -EBUSY; + mutex_unlock(&cdns->bus.bus_lock); + + return ret; +} + +int intel_dai_remove(struct snd_soc_dai *dai) +{ + struct sdw_cdns *cdns = snd_soc_dai_get_drvdata(dai); + struct sdw_intel *sdw = cdns_to_intel(cdns); + + if (dai->id >= SDW_MAX_PORTS) + return 0; + + mutex_lock(&cdns->bus.bus_lock); + clear_bit(dai->id, &sdw->used_ports); + mutex_unlock(&cdns->bus.bus_lock); + + return 0; +} + static struct sdw_master_ops sdw_intel_ops = { .read_prop = intel_prop_read, .override_adr = sdw_dmi_override_adr, @@ -300,6 +354,8 @@ static struct sdw_master_ops sdw_intel_ops = { .read_ping_status = cdns_read_ping_status, .get_device_num = intel_get_device_num_ida, .put_device_num = intel_put_device_num_ida, + .get_port = intel_get_port, + .put_port = intel_put_port, .new_peripheral_assigned = generic_new_peripheral_assigned, .bpt_send_async = generic_bpt_send_async, diff --git a/drivers/soundwire/stream.c b/drivers/soundwire/stream.c index 51d9a4ae742081..6e75426852d299 100644 --- a/drivers/soundwire/stream.c +++ b/drivers/soundwire/stream.c @@ -2023,6 +2023,14 @@ void sdw_release_stream(struct sdw_stream_runtime *stream) } EXPORT_SYMBOL(sdw_release_stream); +static int sdw_get_port(struct sdw_bus *bus) +{ + if (!bus->ops || !bus->ops->get_port || !bus->ops->put_port) + return -EOPNOTSUPP; + + return bus->ops->get_port(bus); +} + /** * sdw_stream_add_master() - Allocate and add master runtime to a stream * @@ -2039,17 +2047,22 @@ int sdw_stream_add_master(struct sdw_bus *bus, struct sdw_stream_runtime *stream) { struct sdw_master_runtime *m_rt; + struct sdw_port_config p2p_port_config; bool alloc_master_rt = false; + bool alloc_master_port = false; + int reserved_port = -1; int ret; mutex_lock(&bus->bus_lock); + m_rt = sdw_master_rt_find(bus, stream); /* * For multi link streams, add the second master only if * the bus supports it. * Check if bus->multi_link is set */ - if (!bus->multi_link && stream->m_rt_count > 0) { + if (!bus->multi_link && stream->m_rt_count > 0 && + (!m_rt || !sdw_master_port_allocated(m_rt))) { dev_err(bus->dev, "Multilink not supported, link %d\n", bus->link_id); ret = -EINVAL; @@ -2060,7 +2073,6 @@ int sdw_stream_add_master(struct sdw_bus *bus, * check if Master is already allocated (e.g. as a result of Slave adding * it first), if so skip allocation and go to configuration */ - m_rt = sdw_master_rt_find(bus, stream); if (!m_rt) { m_rt = sdw_master_rt_alloc(bus, stream); if (IS_ERR(m_rt)) { @@ -2084,28 +2096,79 @@ int sdw_stream_add_master(struct sdw_bus *bus, if (ret) goto alloc_error; + alloc_master_port = true; stream->m_rt_count++; } ret = sdw_master_rt_config(m_rt, stream_config); if (ret < 0) - goto unlock; + goto config_error; ret = sdw_config_stream(bus->dev, stream, stream_config, false); if (ret) - goto unlock; + goto config_error; + + if (stream_config->transport_type == SDW_TRANSPORT_PERIPHERAL_PERIPHERAL) { + struct sdw_port_runtime *p_rt; + + if (num_ports != 1) { + ret = -EOPNOTSUPP; + goto config_error; + } + + if (!list_is_singular(&m_rt->port_list)) { + ret = -EINVAL; + goto config_error; + } + + p_rt = list_first_entry(&m_rt->port_list, struct sdw_port_runtime, port_node); + if (!alloc_master_port && SDW_VALID_PORT_RANGE(p_rt->num)) { + ret = p_rt->num; + } else { + ret = sdw_get_port(bus); + if (ret < 0) + goto config_error; + reserved_port = ret; + if (!SDW_VALID_PORT_RANGE(ret)) { + ret = -EINVAL; + goto config_error; + } + } + + p2p_port_config = *port_config; + p2p_port_config.num = ret; + port_config = &p2p_port_config; + } ret = sdw_master_port_config(m_rt, port_config); + if (ret) + goto config_error; + reserved_port = -1; goto unlock; +config_error: + if (stream_config->transport_type == SDW_TRANSPORT_PERIPHERAL_PERIPHERAL) { + if (alloc_master_port) { + sdw_master_port_free(m_rt); + stream->m_rt_count--; + } + if (alloc_master_rt) + sdw_master_rt_free(m_rt, stream); + } + goto unlock; + alloc_error: /* * we only cleanup what was allocated in this routine */ + if (stream_config->transport_type == SDW_TRANSPORT_PERIPHERAL_PERIPHERAL) + sdw_master_port_free(m_rt); if (alloc_master_rt) sdw_master_rt_free(m_rt, stream); unlock: + if (reserved_port >= 0) + bus->ops->put_port(bus, reserved_port); mutex_unlock(&bus->bus_lock); return ret; } @@ -2123,6 +2186,7 @@ int sdw_stream_remove_master(struct sdw_bus *bus, struct sdw_stream_runtime *stream) { struct sdw_master_runtime *m_rt, *_m_rt; + struct sdw_port_runtime *p_rt; mutex_lock(&bus->bus_lock); @@ -2131,6 +2195,11 @@ int sdw_stream_remove_master(struct sdw_bus *bus, if (m_rt->bus != bus) continue; + if (stream->transport_type == SDW_TRANSPORT_PERIPHERAL_PERIPHERAL && + bus->ops && bus->ops->put_port) { + list_for_each_entry(p_rt, &m_rt->port_list, port_node) + bus->ops->put_port(bus, p_rt->num); + } sdw_master_port_free(m_rt); sdw_master_rt_free(m_rt, stream); stream->m_rt_count--; diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h index a681d9ec923f21..d1df3148913773 100644 --- a/include/linux/soundwire/sdw.h +++ b/include/linux/soundwire/sdw.h @@ -884,6 +884,9 @@ struct sdw_bpt_msg; * Bits 31:24 are reserved. * @get_device_num: Callback for vendor-specific device_number allocation * @put_device_num: Callback for vendor-specific device_number release + * @get_port: Reserve an available manager data port, or return a negative error. + * Called with bus_lock held. + * @put_port: Release a port reserved by get_port, with bus_lock held. * @new_peripheral_assigned: Callback to handle enumeration of new peripheral. * @bpt_send_async: reserve resources for BPT stream and send message * using BTP protocol @@ -902,6 +905,8 @@ struct sdw_master_ops { u32 (*read_ping_status)(struct sdw_bus *bus); int (*get_device_num)(struct sdw_bus *bus, struct sdw_slave *slave); void (*put_device_num)(struct sdw_bus *bus, struct sdw_slave *slave); + int (*get_port)(struct sdw_bus *bus); + void (*put_port)(struct sdw_bus *bus, unsigned int port); void (*new_peripheral_assigned)(struct sdw_bus *bus, struct sdw_slave *slave, int dev_num); From 72795f1fdc4b0fb118c2b36c4f0f18e5694d6765 Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Tue, 8 Sep 2026 11:34:15 +0800 Subject: [PATCH 06/11] ASoC: SOF: Intel: skip companion amp dai The companion amp dai links should not be created by the default machine driver. We will create a mach table for the config that companion amp is used. Signed-off-by: Bard Liao --- sound/soc/sof/intel/hda.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/sound/soc/sof/intel/hda.c b/sound/soc/sof/intel/hda.c index 45e968fb19104b..cec2a4b3ef0ea4 100644 --- a/sound/soc/sof/intel/hda.c +++ b/sound/soc/sof/intel/hda.c @@ -1213,8 +1213,13 @@ static struct snd_soc_acpi_adr_device *find_acpi_adr_device(struct device *dev, return NULL; } for (j = 0; j < codec_info_list[i].dai_num; j++) { - /* Check if the endpoint is present by the SDCA DisCo table */ - if (!is_endpoint_present(sdw_device, codec_info_list[i].dais[j].dai_type)) + /* + * Check if the endpoint is present by the SDCA DisCo table. Also skip the + * companion amp endpoints. The companion amp endpoints should be added in + * the mach table if it is present. + */ + if (!is_endpoint_present(sdw_device, codec_info_list[i].dais[j].dai_type) || + (codec_info_list[i].dais[j].quirk & SOC_SDW_COMPANION_AMPS)) continue; endpoints[ep_index].num = j; From 3fcd79eeb5f4670fcebcb3dedad3036aeed8bdba Mon Sep 17 00:00:00 2001 From: Shuming Fan Date: Thu, 5 Nov 2026 14:45:18 +0800 Subject: [PATCH 07/11] ASoC: sdw_utils: add companion amp dai ops A companion amp gets its audio data from another SoundWire peripheral (the main amp) instead of from the host, so the machine driver does not open a host DMA stream for it. Add common dai ops that the companion amp codec drivers can plug into their dai to handle the peripheral to peripheral stream. Signed-off-by: Shuming Fan Co-developed-by: Bard Liao Signed-off-by: Bard Liao --- include/sound/soc_sdw_utils.h | 11 ++ sound/soc/sdw_utils/soc_sdw_utils.c | 221 +++++++++++++++++++++++++++- 2 files changed, 229 insertions(+), 3 deletions(-) diff --git a/include/sound/soc_sdw_utils.h b/include/sound/soc_sdw_utils.h index 3502548c9a6b90..7f0af8d6745d04 100644 --- a/include/sound/soc_sdw_utils.h +++ b/include/sound/soc_sdw_utils.h @@ -153,6 +153,17 @@ int asoc_sdw_hw_params(struct snd_pcm_substream *substream, int asoc_sdw_hw_free(struct snd_pcm_substream *substream); void asoc_sdw_shutdown(struct snd_pcm_substream *substream); +int asoc_sdw_c_amp_probe(struct snd_soc_dai *dai); +void *asoc_sdw_c_amp_get_sdw_stream(struct snd_soc_dai *dai, int direction); +int asoc_sdw_c_amp_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai); +int asoc_sdw_c_amp_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, struct snd_soc_dai *dai); +int asoc_sdw_c_amp_hw_free(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai); +int asoc_sdw_c_amp_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai); +void asoc_sdw_c_amp_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai); + const char *asoc_sdw_get_codec_name(struct device *dev, const struct asoc_sdw_dai_info *dai_info, const struct snd_soc_acpi_link_adr *adr_link, diff --git a/sound/soc/sdw_utils/soc_sdw_utils.c b/sound/soc/sdw_utils/soc_sdw_utils.c index 7c20ee811d6564..e225c4bab20ec5 100644 --- a/sound/soc/sdw_utils/soc_sdw_utils.c +++ b/sound/soc/sdw_utils/soc_sdw_utils.c @@ -10,6 +10,8 @@ #include #include #include +#include +#include #include #include @@ -1871,7 +1873,7 @@ int asoc_sdw_prepare(struct snd_pcm_substream *substream) struct sdw_stream_runtime *sdw_stream; struct snd_soc_dai *dai; - /* Find stream from first CPU DAI */ + /* Assume there is only one main amp */ dai = snd_soc_rtd_to_cpu(rtd, 0); sdw_stream = snd_soc_dai_get_stream(dai, substream->stream); @@ -1891,7 +1893,7 @@ int asoc_sdw_trigger(struct snd_pcm_substream *substream, int cmd) struct snd_soc_dai *dai; int ret; - /* Find stream from first CPU DAI */ + /* Assume there is only one main amp */ dai = snd_soc_rtd_to_cpu(rtd, 0); sdw_stream = snd_soc_dai_get_stream(dai, substream->stream); @@ -1996,7 +1998,7 @@ int asoc_sdw_hw_free(struct snd_pcm_substream *substream) struct sdw_stream_runtime *sdw_stream; struct snd_soc_dai *dai; - /* Find stream from first CPU DAI */ + /* Assume there is only one main amp */ dai = snd_soc_rtd_to_cpu(rtd, 0); sdw_stream = snd_soc_dai_get_stream(dai, substream->stream); @@ -2015,6 +2017,219 @@ void asoc_sdw_shutdown(struct snd_pcm_substream *substream) } EXPORT_SYMBOL_NS(asoc_sdw_shutdown, "SND_SOC_SDW_UTILS"); +int asoc_sdw_c_amp_probe(struct snd_soc_dai *dai) +{ + void *data = dev_get_drvdata(dai->dev); + + dev_dbg(dai->dev, "%s %s id %d", __func__, dai->name, dai->id); + + snd_soc_dai_set_drvdata(dai, data); + + return 0; +} +EXPORT_SYMBOL_NS(asoc_sdw_c_amp_probe, "SND_SOC_SDW_UTILS"); + +void *asoc_sdw_c_amp_get_sdw_stream(struct snd_soc_dai *dai, int direction) +{ + void *data = snd_soc_dai_get_drvdata(dai); + + dev_dbg(dai->dev, "%s %s id %d direction %d", __func__, dai->name, dai->id, direction); + + if (data && dai->stream[direction].dma_data) + return dai->stream[direction].dma_data; + else + return ERR_PTR(-EINVAL); +} +EXPORT_SYMBOL_NS(asoc_sdw_c_amp_get_sdw_stream, "SND_SOC_SDW_UTILS"); + +int asoc_sdw_c_amp_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) +{ + struct sdw_stream_runtime *sdw_stream = NULL; + int ret; + + dev_dbg(dai->dev, "%s substream stream %d dai %s id %d", + __func__, substream->stream, dai->name, dai->id); + + /* Reuse the shared DAI stream if another DAPM path already started it. */ + sdw_stream = snd_soc_dai_get_stream(dai, substream->stream); + if (!IS_ERR_OR_NULL(sdw_stream)) + return 0; + + ret = sdw_startup_stream(substream); + if (ret) { + dev_err(dai->dev, "%s startup failed: %d\n", __func__, ret); + return ret; + } + + /* Retrieve the newly allocated stream to configure its transport type. */ + sdw_stream = snd_soc_dai_get_stream(dai, substream->stream); + if (IS_ERR(sdw_stream)) { + dev_err(dai->dev, "no stream found for DAI %s\n", dai->name); + return PTR_ERR(sdw_stream); + } + + sdw_stream->transport_type = SDW_TRANSPORT_PERIPHERAL_PERIPHERAL; + + return 0; +} +EXPORT_SYMBOL_NS(asoc_sdw_c_amp_startup, "SND_SOC_SDW_UTILS"); + +int asoc_sdw_c_amp_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) +{ + struct sdw_slave *slave = dev_to_sdw_dev(dai->dev); + struct sdw_stream_runtime *sdw_stream = NULL; + struct sdw_stream_config sconfig = {0}; + struct sdw_port_config pconfig = {0}; + int retval; + + dev_dbg(dai->dev, "%s substream stream %d", __func__, substream->stream); + + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); + if (!sdw_stream) + return -EINVAL; + + snd_sdw_params_to_config(substream, params, &sconfig, &pconfig); + + sconfig.type = SDW_STREAM_PCM; + sconfig.transport_type = SDW_TRANSPORT_PERIPHERAL_PERIPHERAL; + + retval = sdw_stream_add_master(slave->bus, &sconfig, &pconfig, 1, sdw_stream); + if (retval) { + dev_err(dai->dev, "%s: Unable to add master, ret=%d\n", __func__, retval); + return retval; + } + + snd_soc_dai_set_stream(dai, sdw_stream, SNDRV_PCM_STREAM_PLAYBACK); + snd_soc_dai_set_stream(dai, sdw_stream, SNDRV_PCM_STREAM_CAPTURE); + + return 0; +} +EXPORT_SYMBOL_NS(asoc_sdw_c_amp_hw_params, "SND_SOC_SDW_UTILS"); + +int asoc_sdw_c_amp_prepare(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) +{ + struct sdw_stream_runtime *sdw_stream; + int ret; + + /* + * whether SNDRV_PCM_STREAM_PLAYBACK/SNDRV_PCM_STREAM_CAPTURE direction is used + * all can enables the companion stream + */ + + dev_dbg(dai->dev, "%s %s id %d", __func__, dai->name, dai->id); + dev_dbg(dai->dev, "%s substream stream %d", __func__, substream->stream); + + /* Assume there is only one main amp */ + + sdw_stream = snd_soc_dai_get_stream(dai, substream->stream); + if (IS_ERR(sdw_stream)) { + dev_err(dai->dev, "%s no stream found for DAI %s id %d\n", __func__, dai->name, dai->id); + return PTR_ERR(sdw_stream); + } + + if (sdw_stream->state == SDW_STREAM_ENABLED) + return 0; + + ret = sdw_prepare_stream(sdw_stream); + if (ret) { + dev_err(dai->dev, "%s prepare failed: %d\n", __func__, ret); + return ret; + } + + ret = sdw_enable_stream(sdw_stream); + if (ret) + dev_err(dai->dev, "%s trigger failed: %d\n", __func__, ret); + + return ret; +} +EXPORT_SYMBOL_NS(asoc_sdw_c_amp_prepare, "SND_SOC_SDW_UTILS"); + +int asoc_sdw_c_amp_hw_free(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct sdw_slave *slave = dev_to_sdw_dev(dai->dev); + struct sdw_stream_runtime *sdw_stream = + snd_soc_dai_get_dma_data(dai, substream); + int ret = 0; + int cleanup_ret; + + dev_dbg(dai->dev, "%s substream stream %d dai %s id %d", + __func__, substream->stream, dai->name, dai->id); + + /* Assume there is only one main amp */ + sdw_stream = snd_soc_dai_get_stream(dai, substream->stream); + if (IS_ERR(sdw_stream)) { + dev_err(dai->dev, "%s no stream found for DAI %s\n", __func__, dai->name); + return PTR_ERR(sdw_stream); + } + + /* A failed prepare/enable leaves the stream CONFIGURED/PREPARED; still remove it from the bus */ + if (sdw_stream->state == SDW_STREAM_ENABLED) { + cleanup_ret = sdw_disable_stream(sdw_stream); + if (cleanup_ret) { + dev_err(dai->dev, "%s trigger (disable stream) failed: %d\n", + __func__, cleanup_ret); + ret = cleanup_ret; + if (sdw_stream->state == SDW_STREAM_ENABLED) + return ret; + } + } + + if (sdw_stream->state == SDW_STREAM_PREPARED || + sdw_stream->state == SDW_STREAM_DISABLED) { + cleanup_ret = sdw_deprepare_stream(sdw_stream); + if (cleanup_ret) { + dev_err(dai->dev, "%s deprepare failed: %d\n", + __func__, cleanup_ret); + if (!ret) + ret = cleanup_ret; + return ret; + } + } + + cleanup_ret = sdw_stream_remove_slave(slave, sdw_stream); + if (cleanup_ret < 0) { + dev_err(dai->dev, "%s: remove slave failed: %d\n", + __func__, cleanup_ret); + if (!ret) + ret = cleanup_ret; + return ret; + } + + cleanup_ret = sdw_stream_remove_master(slave->bus, sdw_stream); + if (cleanup_ret < 0) { + dev_err(dai->dev, "remove master from stream %s failed: %d\n", + sdw_stream->name, cleanup_ret); + if (!ret) + ret = cleanup_ret; + } + + return ret; +} +EXPORT_SYMBOL_NS(asoc_sdw_c_amp_hw_free, "SND_SOC_SDW_UTILS"); + +void asoc_sdw_c_amp_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct sdw_stream_runtime *sdw_stream; + + dev_dbg(dai->dev, "%s %s id %d", __func__, dai->name, dai->id); + dev_dbg(dai->dev, "%s substream stream %d", __func__, substream->stream); + + sdw_stream = snd_soc_dai_get_stream(dai, substream->stream); + if (!IS_ERR_OR_NULL(sdw_stream) && !list_empty(&sdw_stream->master_list)) { + dev_err(dai->dev, "%s stream still has master runtimes\n", __func__); + return; + } + + sdw_shutdown_stream(substream); + + snd_soc_dai_stream_dma_data_set_playback(dai, NULL); + snd_soc_dai_stream_dma_data_set_capture(dai, NULL); +} +EXPORT_SYMBOL_NS(asoc_sdw_c_amp_shutdown, "SND_SOC_SDW_UTILS"); + static bool asoc_sdw_is_unique_device(const struct snd_soc_acpi_link_adr *adr_link, unsigned int sdw_version, unsigned int mfg_id, From 578bd8aa1e7f73efd74e1f1368e22508cc4ba0c9 Mon Sep 17 00:00:00 2001 From: Shuming Fan Date: Wed, 18 Nov 2026 14:09:19 +0800 Subject: [PATCH 08/11] ASoC: rt712: add companion data input DAI Add a companion input DAI to the RT712 SoundWire codec to support codec-to-codec audio streaming with the main amp. For the companion DAI, retrieve the SoundWire stream from the CPU DAI instead of using the codec DAI's DMA data, allowing the RT712 to add the slave to master stream with the companion c2c link. Signed-off-by: Shuming Fan --- sound/soc/codecs/rt712-sdca.c | 38 +++++++++++++++++++++++++++++++++-- sound/soc/codecs/rt712-sdca.h | 1 + 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/rt712-sdca.c b/sound/soc/codecs/rt712-sdca.c index 08e08ec96bc503..f0eb5015ebb6c6 100644 --- a/sound/soc/codecs/rt712-sdca.c +++ b/sound/soc/codecs/rt712-sdca.c @@ -1197,6 +1197,7 @@ static const struct snd_soc_dapm_route rt712_sdca_audio_map[] = { static const struct snd_soc_dapm_widget rt712_sdca_spk_dapm_widgets[] = { SND_SOC_DAPM_AIF_IN("DP3RX", "DP3 Playback", 0, SND_SOC_NOPM, 0, 0), + SND_SOC_DAPM_AIF_IN("DP3RX-Comp", "DP3 Comp-In", 0, SND_SOC_NOPM, 0, 0), /* Digital Interface */ SND_SOC_DAPM_PGA("FU06", SND_SOC_NOPM, 0, 0, NULL, 0), @@ -1214,6 +1215,7 @@ static const struct snd_soc_dapm_widget rt712_sdca_spk_dapm_widgets[] = { static const struct snd_soc_dapm_route rt712_sdca_spk_dapm_routes[] = { { "FU06", NULL, "DP3RX" }, + { "FU06", NULL, "DP3RX-Comp" }, { "FU06", NULL, "PDE 23" }, { "OT23 L", "Switch", "FU06" }, { "OT23 R", "Switch", "FU06" }, @@ -1671,9 +1673,25 @@ static int rt712_sdca_pcm_hw_params(struct snd_pcm_substream *substream, struct sdw_stream_runtime *sdw_stream; int retval, port; unsigned int sampling_rate; + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); + struct snd_soc_dai *cpu_dai; dev_dbg(dai->dev, "%s %s id %d", __func__, dai->name, dai->id); - sdw_stream = snd_soc_dai_get_dma_data(dai, substream); + dev_dbg(dai->dev, "%s substream stream %d", __func__, substream->stream); + + if (dai->id == RT712_AIF4) { + cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); + dev_dbg(dai->dev, "%s cpu_dai %s id %d", __func__, cpu_dai->name, cpu_dai->id); + + sdw_stream = snd_soc_dai_get_stream(cpu_dai, 1); + if (IS_ERR(sdw_stream)) { + dev_err(rtd->dev, "%s no stream found for DAI %s id %d\n", + __func__, cpu_dai->name, cpu_dai->id); + return PTR_ERR(sdw_stream); + } + } else { + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); + } if (!sdw_stream) return -EINVAL; @@ -1689,7 +1707,7 @@ static int rt712_sdca_pcm_hw_params(struct snd_pcm_substream *substream, if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { if (dai->id == RT712_AIF1) port = 1; - else if (dai->id == RT712_AIF2) + else if (dai->id == RT712_AIF2 || dai->id == RT712_AIF4) port = 3; else return -EINVAL; @@ -1704,6 +1722,9 @@ static int rt712_sdca_pcm_hw_params(struct snd_pcm_substream *substream, /* SoundWire specific configuration */ snd_sdw_params_to_config(substream, params, &stream_config, &port_config); + + if (dai->id == RT712_AIF4) + stream_config.transport_type = SDW_TRANSPORT_PERIPHERAL_PERIPHERAL; port_config.num = port; retval = sdw_stream_add_slave(rt712->slave, &stream_config, @@ -1750,6 +1771,7 @@ static int rt712_sdca_pcm_hw_params(struct snd_pcm_substream *substream, sampling_rate); break; case RT712_AIF2: + case RT712_AIF4: regmap_write(rt712->regmap, SDW_SDCA_CTL(FUNC_NUM_AMP, RT712_SDCA_ENT_CS31, RT712_SDCA_CTL_SAMPLE_FREQ_INDEX, 0), sampling_rate); @@ -1828,6 +1850,18 @@ static struct snd_soc_dai_driver rt712_sdca_dai[] = { .formats = RT712_FORMATS, }, .ops = &rt712_sdca_ops, + }, + { + .name = "rt712-sdca-aif4", + .id = RT712_AIF4, + .playback = { + .stream_name = "DP3 Comp-In", + .channels_min = 2, + .channels_max = 2, + .rates = RT712_STEREO_RATES, + .formats = RT712_FORMATS, + }, + .ops = &rt712_sdca_ops, } }; diff --git a/sound/soc/codecs/rt712-sdca.h b/sound/soc/codecs/rt712-sdca.h index 7e6ee21c8a172d..0ea6568c6edb66 100644 --- a/sound/soc/codecs/rt712-sdca.h +++ b/sound/soc/codecs/rt712-sdca.h @@ -249,6 +249,7 @@ enum { RT712_AIF1, RT712_AIF2, RT712_AIF3, + RT712_AIF4, }; enum rt712_sdca_jd_src { From a5c7c3c9f39f071616a39ed7c5367b795775e8d4 Mon Sep 17 00:00:00 2001 From: Shuming Fan Date: Wed, 18 Nov 2026 14:10:39 +0800 Subject: [PATCH 09/11] ASoC: rt721: add companion data input DAI Add a companion input DAI to the RT721 SoundWire codec to support codec-to-codec audio streaming with the main amp. For the companion DAI, retrieve the SoundWire stream from the CPU DAI instead of using the codec DAI's DMA data, allowing the RT721 to add the slave to master stream with the companion c2c link. Signed-off-by: Shuming Fan --- sound/soc/codecs/rt721-sdca.c | 40 +++++++++++++++++++++++++++++++---- sound/soc/codecs/rt721-sdca.h | 1 + 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/sound/soc/codecs/rt721-sdca.c b/sound/soc/codecs/rt721-sdca.c index 82ef8245474cb3..cd68cfc1d9ecdd 100644 --- a/sound/soc/codecs/rt721-sdca.c +++ b/sound/soc/codecs/rt721-sdca.c @@ -1641,12 +1641,15 @@ static const struct snd_soc_dapm_widget rt721_sdca_dapm_widgets[] = { SND_SOC_DAPM_AIF_OUT("DP2TX", "DP2 Headset Capture", 0, SND_SOC_NOPM, 0, 0), SND_SOC_DAPM_AIF_IN("DP3RX", "DP3 Speaker Playback", 0, SND_SOC_NOPM, 0, 0), SND_SOC_DAPM_AIF_OUT("DP6TX", "DP6 DMic Capture", 0, SND_SOC_NOPM, 0, 0), + SND_SOC_DAPM_AIF_IN("DP3RX-Comp", "DP3 Comp-In", 0, SND_SOC_NOPM, 0, 0), }; static const struct snd_soc_dapm_route rt721_sdca_audio_map[] = { {"FU 42", NULL, "DP1RX"}, {"FU 21", NULL, "DP3RX"}, {"FU 23", NULL, "DP3RX"}, + {"FU 21", NULL, "DP3RX-Comp" }, + {"FU 23", NULL, "DP3RX-Comp" }, {"ADC 09 Mux", "MIC2", "MIC2"}, {"ADC 09 Mux", "LINE1", "LINE1"}, @@ -1755,14 +1758,29 @@ static int rt721_sdca_pcm_hw_params(struct snd_pcm_substream *substream, { struct snd_soc_component *component = dai->component; struct rt721_sdca_priv *rt721 = snd_soc_component_get_drvdata(component); + struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream); struct sdw_stream_config stream_config = {0}; struct sdw_port_config port_config; struct sdw_stream_runtime *sdw_stream; + struct snd_soc_dai *cpu_dai; int retval, port; unsigned int sampling_rate; dev_dbg(dai->dev, "%s %s", __func__, dai->name); - sdw_stream = snd_soc_dai_get_dma_data(dai, substream); + + if (dai->id == RT721_AIF4) { + cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); + dev_dbg(dai->dev, "%s cpu_dai %s id %d", __func__, cpu_dai->name, cpu_dai->id); + + sdw_stream = snd_soc_dai_get_stream(cpu_dai, 1); + if (IS_ERR(sdw_stream)) { + dev_err(rtd->dev, "%s no stream found for DAI %s id %d\n", + __func__, cpu_dai->name, cpu_dai->id); + return PTR_ERR(sdw_stream); + } + } else { + sdw_stream = snd_soc_dai_get_dma_data(dai, substream); + } if (!sdw_stream) return -EINVAL; @@ -1779,7 +1797,7 @@ static int rt721_sdca_pcm_hw_params(struct snd_pcm_substream *substream, if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { if (dai->id == RT721_AIF1) port = 1; - else if (dai->id == RT721_AIF2) + else if (dai->id == RT721_AIF2 || dai->id == RT721_AIF4) port = 3; else return -EINVAL; @@ -1795,6 +1813,8 @@ static int rt721_sdca_pcm_hw_params(struct snd_pcm_substream *substream, /* SoundWire specific configuration */ snd_sdw_params_to_config(substream, params, &stream_config, &port_config); port_config.num = port; + if (dai->id == RT721_AIF4) + stream_config.transport_type = SDW_TRANSPORT_PERIPHERAL_PERIPHERAL; retval = sdw_stream_add_slave(rt721->slave, &stream_config, &port_config, 1, sdw_stream); @@ -1857,7 +1877,7 @@ static int rt721_sdca_pcm_hw_params(struct snd_pcm_substream *substream, RT721_SDCA_CTL_SAMPLE_FREQ_INDEX, 0), sampling_rate); } - if (dai->id == RT721_AIF2) + if (dai->id == RT721_AIF2 || dai->id == RT721_AIF4) regmap_write(rt721->regmap, SDW_SDCA_CTL(FUNC_NUM_AMP, RT721_SDCA_ENT_CS31, RT721_SDCA_CTL_SAMPLE_FREQ_INDEX, 0), sampling_rate); @@ -1940,7 +1960,19 @@ static struct snd_soc_dai_driver rt721_sdca_dai[] = { .formats = RT721_FORMATS, }, .ops = &rt721_sdca_ops, - } + }, + { + .name = "rt721-sdca-aif4", + .id = RT721_AIF4, + .playback = { + .stream_name = "DP3 Comp-In", + .channels_min = 2, + .channels_max = 2, + .rates = RT721_STEREO_RATES, + .formats = RT721_FORMATS, + }, + .ops = &rt721_sdca_ops, + } }; int rt721_sdca_init(struct device *dev, struct regmap *regmap, diff --git a/sound/soc/codecs/rt721-sdca.h b/sound/soc/codecs/rt721-sdca.h index cc3bce0ba51786..e9b24f517312e1 100644 --- a/sound/soc/codecs/rt721-sdca.h +++ b/sound/soc/codecs/rt721-sdca.h @@ -299,6 +299,7 @@ enum { RT721_AIF1, /* For headset mic and headphone */ RT721_AIF2, /* For speaker */ RT721_AIF3, /* For dmic */ + RT721_AIF4, /* For comp-in */ RT721_AIFS, }; From c6089d4af9b458941f2ffbc397bbe8643da17adb Mon Sep 17 00:00:00 2001 From: Shuming Fan Date: Wed, 18 Nov 2026 14:11:04 +0800 Subject: [PATCH 10/11] ASoC: rt1320: add companion data output DAI Add a companion DAI to the RT1320 SoundWire codec to support codec-to-codec audio streaming. SoundWire peripheral-to-peripheral transport and add the corresponding DAPM widgets and routes. Use the ASoC SoundWire companion amplifier helpers to manage the companion stream, including startup, preparation, and cleanup. Signed-off-by: Shuming Fan --- sound/soc/codecs/Kconfig | 1 + sound/soc/codecs/rt1320-sdw.c | 69 ++++++++++++++++++++++++++++++++++- sound/soc/codecs/rt1320-sdw.h | 1 + 3 files changed, 69 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig index 3e379a8d5b1c82..14dff9af449e1c 100644 --- a/sound/soc/codecs/Kconfig +++ b/sound/soc/codecs/Kconfig @@ -1855,6 +1855,7 @@ config SND_SOC_RT1320_SDW depends on SOUNDWIRE select REGMAP_SOUNDWIRE select REGMAP_SOUNDWIRE_MBQ + select SND_SOC_SDW_UTILS config SND_SOC_RT5514 tristate diff --git a/sound/soc/codecs/rt1320-sdw.c b/sound/soc/codecs/rt1320-sdw.c index fa89db09665149..2a98e5183551a3 100644 --- a/sound/soc/codecs/rt1320-sdw.c +++ b/sound/soc/codecs/rt1320-sdw.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -251,6 +252,7 @@ static const struct reg_sequence rt1320_vc_blind_write[] = { { 0xc06b, 0x0a }, { 0xd172, 0x2a }, { 0xc5d6, 0x01 }, + { 0xc5d0, 0x8f }, /* DP6 Data Select: SRCIN OUT for companion output setting */ { SDW_SDCA_CTL(FUNC_NUM_AMP, RT1320_SDCA_ENT_PDE23, RT1320_SDCA_CTL_REQ_POWER_STATE, 0), 0x03 }, }; @@ -1090,7 +1092,7 @@ static int rt1320_read_prop(struct sdw_slave *slave) prop->lane_control_support = true; /* first we need to allocate memory for set bits in port lists */ - prop->source_ports = BIT(4) | BIT(8) | BIT(10); + prop->source_ports = BIT(4) | BIT(6) | BIT(8) | BIT(10); prop->sink_ports = BIT(1); nval = hweight32(prop->source_ports); @@ -3183,6 +3185,9 @@ static const struct snd_soc_dapm_widget rt1320_dapm_widgets[] = { /* Audio Interface */ SND_SOC_DAPM_AIF_IN("DP1RX", "DP1 Playback", 0, SND_SOC_NOPM, 0, 0), SND_SOC_DAPM_AIF_OUT("DP4TX", "DP4 Capture", 0, SND_SOC_NOPM, 0, 0), + SND_SOC_DAPM_AIF_OUT("DP6TX", "DP6 Comp-Out", 0, SND_SOC_NOPM, 0, 0), + SND_SOC_DAPM_AIF_IN("DP6RX", "DP6 Comp-Playback", 0, SND_SOC_NOPM, 0, 0), + SND_SOC_DAPM_AIF_OUT("DP8-10TX", "DP8-10 Capture", 0, SND_SOC_NOPM, 0, 0), /* Digital Interface */ @@ -3221,6 +3226,9 @@ static const struct snd_soc_dapm_route rt1320_dapm_routes[] = { { "AEC Data", NULL, "AEC Gen" }, { "DP4TX", NULL, "AEC Data" }, + { "DP6TX", NULL, "DP1RX" }, + { "DP6RX", NULL, "DP1RX" }, + {"DP8-10TX", NULL, "FU"}, {"FU", NULL, "PDE 11"}, {"FU", NULL, "FU 113"}, @@ -3251,6 +3259,10 @@ static int rt1320_sdw_hw_params(struct snd_pcm_substream *substream, struct sdw_stream_config stream_config = {0}; struct sdw_port_config port_config; struct sdw_port_config dmic_port_config[2]; + struct sdw_port_config companion_config = { + .num = 6, + .ch_mask = BIT(0) | BIT(1), + }; struct sdw_stream_runtime *sdw_stream; int retval, num_channels; unsigned int sampling_rate; @@ -3267,6 +3279,9 @@ static int rt1320_sdw_hw_params(struct snd_pcm_substream *substream, /* SoundWire specific configuration */ snd_sdw_params_to_config(substream, params, &stream_config, &port_config); + if (dai->id == RT1320_AIF3) + goto _add_slave_; + if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { if (dai->id == RT1320_AIF1) port_config.num = 1; @@ -3295,6 +3310,7 @@ static int rt1320_sdw_hw_params(struct snd_pcm_substream *substream, return -EINVAL; } +_add_slave_: if (dai->id == RT1320_AIF1) retval = sdw_stream_add_slave(rt1320->sdw_slave, &stream_config, &port_config, 1, sdw_stream); @@ -3312,6 +3328,21 @@ static int rt1320_sdw_hw_params(struct snd_pcm_substream *substream, dev_err(dai->dev, "%s: Unknown device ID %d\n", __func__, rt1320->dev_id); return -EINVAL; } + } else if (dai->id == RT1320_AIF3) { + retval = asoc_sdw_c_amp_hw_params(substream, params, dai); + if (retval) { + dev_err(dai->dev, "%s: master companion stream configuration failed, ret=%d\n", + __func__, retval); + return retval; + } + stream_config.transport_type = SDW_TRANSPORT_PERIPHERAL_PERIPHERAL; + retval = sdw_stream_add_slave(rt1320->sdw_slave, &stream_config, + &companion_config, 1, sdw_stream); + if (retval) { + sdw_stream_remove_master(rt1320->sdw_slave->bus, sdw_stream); + dev_err(dai->dev, "%s: Unable to add slave, ret=%d\n", __func__, retval); + return retval; + } } else return -EINVAL; if (retval) { @@ -3350,7 +3381,7 @@ static int rt1320_sdw_hw_params(struct snd_pcm_substream *substream, regmap_write(rt1320->regmap, SDW_SDCA_CTL(FUNC_NUM_AMP, RT1320_SDCA_ENT_CS21, RT1320_SDCA_CTL_SAMPLE_FREQ_INDEX, 0), sampling_rate); - else { + else if (dai->id == RT1320_AIF2) { regmap_write(rt1320->regmap, SDW_SDCA_CTL(FUNC_NUM_MIC, RT1320_SDCA_ENT_CS113, RT1320_SDCA_CTL_SAMPLE_FREQ_INDEX, 0), sampling_rate); @@ -3469,6 +3500,17 @@ static const struct snd_soc_dai_ops rt1320_aif_dai_ops = { .shutdown = rt1320_sdw_shutdown, }; +static const struct snd_soc_dai_ops rt1320_comp_dai_asoc_ops = { + .probe = asoc_sdw_c_amp_probe, + .startup = asoc_sdw_c_amp_startup, + .prepare = asoc_sdw_c_amp_prepare, + .hw_params = rt1320_sdw_hw_params, + .hw_free = asoc_sdw_c_amp_hw_free, + .set_stream = rt1320_set_sdw_stream, + .shutdown = asoc_sdw_c_amp_shutdown, + .get_stream = asoc_sdw_c_amp_get_sdw_stream, +}; + #define RT1320_STEREO_RATES (SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \ SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_192000) #define RT1320_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S24_LE | \ @@ -3507,6 +3549,28 @@ static struct snd_soc_dai_driver rt1320_sdw_dai[] = { }, .ops = &rt1320_aif_dai_ops, }, + /* Companion stream output */ + { + .name = "rt1320-aif3", + .id = RT1320_AIF3, + .playback = { + .stream_name = "DP6 Comp-Playback", + .channels_min = 2, + .channels_max = 2, + .rates = RT1320_STEREO_RATES, + .formats = RT1320_FORMATS, + }, + .capture = { + .stream_name = "DP6 Comp-Out", + .channels_min = 2, + .channels_max = 2, + .rates = RT1320_STEREO_RATES, + .formats = RT1320_FORMATS, + }, + .ops = &rt1320_comp_dai_asoc_ops, + .symmetric_rate = 1, + .symmetric_channels = 1, + }, }; static int rt1320_parse_dp(struct rt1320_sdw_priv *rt1320, struct device *dev) @@ -3694,3 +3758,4 @@ module_sdw_driver(rt1320_sdw_driver); MODULE_DESCRIPTION("ASoC RT1320 driver SDCA SDW"); MODULE_AUTHOR("Shuming Fan "); MODULE_LICENSE("GPL"); +MODULE_IMPORT_NS("SND_SOC_SDW_UTILS"); diff --git a/sound/soc/codecs/rt1320-sdw.h b/sound/soc/codecs/rt1320-sdw.h index df9ccdf92d361c..9af4670f2fbb01 100644 --- a/sound/soc/codecs/rt1320-sdw.h +++ b/sound/soc/codecs/rt1320-sdw.h @@ -87,6 +87,7 @@ enum { RT1320_AIF1, RT1320_AIF2, + RT1320_AIF3, }; /* From 37f44f640ddf83b96fc90140529365a0a0eec52b Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Tue, 8 Sep 2026 11:29:38 +0800 Subject: [PATCH 11/11] ASoC: soc_sdw_utils: add componion amp dai for Realtek codecs Add the componion amp dai info for rt712 ,rt721 and rt1320. Signed-off-by: Bard Liao --- sound/soc/sdw_utils/soc_sdw_utils.c | 43 ++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/sound/soc/sdw_utils/soc_sdw_utils.c b/sound/soc/sdw_utils/soc_sdw_utils.c index e225c4bab20ec5..4cbbbf33522bd5 100644 --- a/sound/soc/sdw_utils/soc_sdw_utils.c +++ b/sound/soc/sdw_utils/soc_sdw_utils.c @@ -372,8 +372,17 @@ struct asoc_sdw_codec_info codec_info_list[] = { .quirk = SOC_SDW_CODEC_MIC, .quirk_exclude = true, }, + /* Companion amp */ + { + .direction = {true, true}, + .dai_name = "rt712-sdca-aif4", + .dai_type = SOC_SDW_DAI_TYPE_AMP, + .dailink = {SOC_SDW_AMP_OUT_DAI_ID, SOC_SDW_AMP_IN_DAI_ID}, + .rtd_init = asoc_sdw_rt_mf_sdca_spk_rtd_init, + .quirk = SOC_SDW_COMPANION_AMPS, + }, }, - .dai_num = 3, + .dai_num = 4, }, { .vendor_id = 0x025d, @@ -537,8 +546,16 @@ struct asoc_sdw_codec_info codec_info_list[] = { .widgets = generic_dmic_widgets, .num_widgets = ARRAY_SIZE(generic_dmic_widgets), }, + /* Companion amp */ + { + .direction = {true, true}, + .dai_name = "rt1320-aif3", + .dai_type = SOC_SDW_DAI_TYPE_AMP, + .dailink = {SOC_SDW_AMP_OUT_DAI_ID, SOC_SDW_AMP_IN_DAI_ID}, + .quirk = SOC_SDW_COMPANION_AMPS, + }, }, - .dai_num = 2, + .dai_num = 3, }, { .vendor_id = 0x025d, @@ -684,8 +701,17 @@ struct asoc_sdw_codec_info codec_info_list[] = { .quirk = SOC_SDW_CODEC_MIC, .quirk_exclude = true, }, + /* Companion amp */ + { + .direction = {true, false}, + .dai_name = "rt721-sdca-aif4", + .dai_type = SOC_SDW_DAI_TYPE_AMP, + .dailink = {SOC_SDW_AMP_OUT_DAI_ID, SOC_SDW_AMP_IN_DAI_ID}, + .rtd_init = asoc_sdw_rt_mf_sdca_spk_rtd_init, + .quirk = SOC_SDW_COMPANION_AMPS, + }, }, - .dai_num = 3, + .dai_num = 4, }, { .vendor_id = 0x025d, @@ -730,8 +756,17 @@ struct asoc_sdw_codec_info codec_info_list[] = { .quirk = SOC_SDW_CODEC_MIC, .quirk_exclude = true, }, + /* Companion amp */ + { + .direction = {true, false}, + .dai_name = "rt721-sdca-aif4", + .dai_type = SOC_SDW_DAI_TYPE_AMP, + .dailink = {SOC_SDW_AMP_OUT_DAI_ID, SOC_SDW_AMP_IN_DAI_ID}, + .rtd_init = asoc_sdw_rt_mf_sdca_spk_rtd_init, + .quirk = SOC_SDW_COMPANION_AMPS, + }, }, - .dai_num = 3, + .dai_num = 4, }, { .vendor_id = 0x025d,