Skip to content

Support Lenovo laptop with rt722 and rt1320#5709

Open
oortcomet wants to merge 3 commits intothesofproject:topic/sof-devfrom
oortcomet:lnv-rt722-rt1320-2
Open

Support Lenovo laptop with rt722 and rt1320#5709
oortcomet wants to merge 3 commits intothesofproject:topic/sof-devfrom
oortcomet:lnv-rt722-rt1320-2

Conversation

@oortcomet
Copy link

These commits support the combination with rt722 and rt1320 soundwire devices.

  • rt722 in Link3 -> UAJ
  • rt1320 in Link2 -> AMP & MIC

…bles

Use functional topologies to support RT722 topologies with/without
amplifiers,
e.g. sof-ptl-rt722.tplg, sof-ptl-rt722-rt1320.tplg...

If these entries are not removed, they will find the first same link of
sof-ptl-rt722.tplg.

Signed-off-by: Mac Chiang <mac.chiang@intel.com>
Co-developed-by: Derek Fang <derek.fang@realtek.com>
Signed-off-by: Derek Fang <derek.fang@realtek.com>
Copilot AI review requested due to automatic review settings March 23, 2026 12:18
@sofci
Copy link
Collaborator

sofci commented Mar 23, 2026

Can one of the admins verify this patch?

reply test this please to run this test once

@bardliao
Copy link
Collaborator

test this please

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the SoundWire generic machine support to handle Lenovo platforms using an rt722 SoundWire codec together with an rt1320 device providing both speaker amp and DMIC functionality.

Changes:

  • Extend codec_info_list to describe rt1320 as an amp device with an additional DMIC capture DAI.
  • Adjust SOF HDA SoundWire machine selection to allow amp-style naming for multi-function codecs via a new is_amp flag.
  • Update Realtek DMIC runtime init to append cfg-mics for rt1320 based on SDCA “SmartMic” function discovery; simplify PTL match tables by removing rt722-only entries that could match as subsets.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
sound/soc/sof/intel/hda.c Uses new codec flag to force amp-style naming even for multi-function codecs (amp+mic).
sound/soc/sdw_utils/soc_sdw_utils.c Adds rt1320 DMIC DAI description and marks rt1320 as amp for naming/indexing purposes.
sound/soc/sdw_utils/soc_sdw_rt_dmic.c Adds rt1320-specific cfg-mics computation based on SDCA SmartMic functions.
sound/soc/intel/common/soc-acpi-intel-ptl-match.c Removes rt722-only endpoint/link/machine definitions to avoid incorrect subset matches.
include/sound/soc_sdw_utils.h Adds is_amp field to codec info structure.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 319 to 350
@@ -334,8 +335,18 @@ struct asoc_sdw_codec_info codec_info_list[] = {
.widgets = generic_spk_widgets,
.num_widgets = ARRAY_SIZE(generic_spk_widgets),
},
{
.direction = {false, true},
.dai_name = "rt1320-aif2",
.component_name = "rt1320",
.dai_type = SOC_SDW_DAI_TYPE_MIC,
.dailink = {SOC_SDW_UNUSED_DAI_ID, SOC_SDW_DMIC_DAI_ID},
.rtd_init = asoc_sdw_rt_dmic_rtd_init,
.widgets = generic_dmic_widgets,
.num_widgets = ARRAY_SIZE(generic_dmic_widgets),
},
},
.dai_num = 1,
.dai_num = 2,
},
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

rt1321 (part_id 0x1321) is also supported by the rt1320-sdw driver (it registers an SDW ID for 0x1321 and exposes the same rt1320-aif2 capture DAI). This change adds the DMIC DAI + AMP override only for part_id 0x1320, so systems reporting 0x1321 may still miss the MIC endpoint and/or AMP-style naming. Consider mirroring the new MIC DAI and is_amp handling for the 0x1321 entry as well if the hardware exposes SmartMic/DMIC.

Copilot uses AI. Check for mistakes.
Comment on lines +46 to +67
if (!codec_info)
return -EINVAL;
part_id = codec_info->part_id;

/* count the rt1320 with SDCA function SmartMic type in this card */
for_each_card_components(card, component) {
if (!is_sdw_slave(component->dev))
continue;
sdw_peripheral = dev_to_sdw_dev(component->dev);
if (sdw_peripheral->id.part_id != part_id)
continue;
for (i = 0; i < sdw_peripheral->sdca_data.num_functions; i++) {
if (sdw_peripheral->sdca_data.function[i].type ==
SDCA_FUNCTION_TYPE_SMART_MIC) {
rt1320_dmic_num++;
break;
}
}
}
card->components = devm_kasprintf(card->dev, GFP_KERNEL,
"%s mic:%s cfg-mics:%d", card->components,
mic_name, rt1320_dmic_num);
Copy link

Copilot AI Mar 23, 2026

Choose a reason for hiding this comment

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

In the new rt1320-specific path, failing asoc_sdw_find_codec_info_dai() returns -EINVAL without any log, which can make bring-up failures hard to diagnose and may abort card init for what could be a recoverable condition. Consider logging a warning/error with the DAI name and falling back to the previous behavior (append mic:<name> without cfg-mics) instead of hard-failing.

Suggested change
if (!codec_info)
return -EINVAL;
part_id = codec_info->part_id;
/* count the rt1320 with SDCA function SmartMic type in this card */
for_each_card_components(card, component) {
if (!is_sdw_slave(component->dev))
continue;
sdw_peripheral = dev_to_sdw_dev(component->dev);
if (sdw_peripheral->id.part_id != part_id)
continue;
for (i = 0; i < sdw_peripheral->sdca_data.num_functions; i++) {
if (sdw_peripheral->sdca_data.function[i].type ==
SDCA_FUNCTION_TYPE_SMART_MIC) {
rt1320_dmic_num++;
break;
}
}
}
card->components = devm_kasprintf(card->dev, GFP_KERNEL,
"%s mic:%s cfg-mics:%d", card->components,
mic_name, rt1320_dmic_num);
if (codec_info) {
part_id = codec_info->part_id;
/* count the rt1320 with SDCA function SmartMic type in this card */
for_each_card_components(card, component) {
if (!is_sdw_slave(component->dev))
continue;
sdw_peripheral = dev_to_sdw_dev(component->dev);
if (sdw_peripheral->id.part_id != part_id)
continue;
for (i = 0; i < sdw_peripheral->sdca_data.num_functions; i++) {
if (sdw_peripheral->sdca_data.function[i].type ==
SDCA_FUNCTION_TYPE_SMART_MIC) {
rt1320_dmic_num++;
break;
}
}
}
card->components = devm_kasprintf(card->dev, GFP_KERNEL,
"%s mic:%s cfg-mics:%d",
card->components,
mic_name, rt1320_dmic_num);
} else {
dev_warn(card->dev,
"Failed to find codec info for DAI %s, falling back without cfg-mics\n",
dai->name);
card->components = devm_kasprintf(card->dev, GFP_KERNEL,
"%s mic:%s", card->components,
mic_name);
}

Copilot uses AI. Check for mistakes.
According to the Intel sof design, it will create the name prefix
appended with amp index for the amp codec only, such as:
rt1318-1, rt1318-2, etc...

But the rt1320 is a codec with amp and mic codec functions, it doesn't
have the amp index in its name prefix as above.
And then it will be hard to identify the codec if in multi-rt1320 case.
So we add a flag to force the amp index to be appended.

Signed-off-by: Derek Fang <derek.fang@realtek.com>
Add 'rt1320-aif2' dai infos for rt1320 and rt1321 dmic function.

Signed-off-by: Derek Fang <derek.fang@realtek.com>
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +39 to +45
sdw_peripheral = dev_to_sdw_dev(component->dev);
/*
* If there is any rt1320/rt1321 DMIC belonging to this card, try to count the `cfg-mics`
* to be used in card->components.
*/
if (sdw_peripheral->id.part_id == 0x1320 || sdw_peripheral->id.part_id == 0x1321) {
part_id = sdw_peripheral->id.part_id;
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

asoc_sdw_rt_dmic_rtd_init() now unconditionally calls dev_to_sdw_dev(component->dev), which assumes the component device is a SoundWire slave. This function is exported and will crash if it’s ever invoked with a non-SDW component. Please guard this with is_sdw_slave(component->dev) (and fall back to the non-rt1320 path / return an error) before calling dev_to_sdw_dev().

Copilot uses AI. Check for mistakes.
Comment on lines +61 to +63
card->components = devm_kasprintf(card->dev, GFP_KERNEL,
"%s mic:%s cfg-mics:%d", card->components,
mic_name, rt1320_dmic_num);
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

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

The cfg-mics:%d token is appended inside the per-DAI rtd_init callback. If this init runs more than once on the same card (e.g. multiple MIC DAIs using this helper), card->components can end up with repeated cfg-mics: entries, which is hard for UCM/userspace to interpret. Consider only setting cfg-mics once (e.g. check if it’s already present in card->components, or store a per-card flag in driver data).

Copilot uses AI. Check for mistakes.
Copy link
Collaborator

Choose a reason for hiding this comment

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

rtd_init_done will be set once the DAI rtd_init callback is called. And "in theory", there will not be 2 SDW DMIC enabled in a device. But, yeah, it is a potential issue.

card->components = devm_kasprintf(card->dev, GFP_KERNEL,
"%s mic:%s", card->components,
mic_name);
sdw_peripheral = dev_to_sdw_dev(component->dev);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It is fine as asoc_sdw_rt_dmic_rtd_init() is only used by the rt codecs and codec drivers register the peripheral dev to component->dev. Please keep in mind that the peripheral dev could be dai->component->dev->parent, too. It is worthy to add a comment here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants