Support Lenovo laptop with rt722 and rt1320#5709
Support Lenovo laptop with rt722 and rt1320#5709oortcomet wants to merge 3 commits intothesofproject:topic/sof-devfrom
Conversation
…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>
|
Can one of the admins verify this patch?
|
|
test this please |
There was a problem hiding this comment.
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_listto 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_ampflag. - Update Realtek DMIC runtime init to append
cfg-micsfor 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.
| @@ -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, | |||
| }, | |||
There was a problem hiding this comment.
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.
| 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); |
There was a problem hiding this comment.
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.
| 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); | |
| } |
09c6855 to
00b27a0
Compare
There was a problem hiding this comment.
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.
| 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; |
There was a problem hiding this comment.
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().
| card->components = devm_kasprintf(card->dev, GFP_KERNEL, | ||
| "%s mic:%s cfg-mics:%d", card->components, | ||
| mic_name, rt1320_dmic_num); |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
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>
00b27a0 to
474336c
Compare
Add 'rt1320-aif2' dai infos for rt1320 and rt1321 dmic function. Signed-off-by: Derek Fang <derek.fang@realtek.com>
474336c to
b54daf9
Compare
There was a problem hiding this comment.
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.
| /* | ||
| * If there is any rt1320/rt1321 DMIC belonging to this card, try to count the `cfg-mics` | ||
| * to be used in card->components. | ||
| * Note: The rt1320 drivers register the peripheral dev to component->dev, so get the | ||
| * sdw_peripheral from component->dev. | ||
| */ | ||
| if (is_sdw_slave(component->dev)) | ||
| sdw_peripheral = dev_to_sdw_dev(component->dev); | ||
| if (sdw_peripheral && | ||
| (sdw_peripheral->id.part_id == 0x1320 || sdw_peripheral->id.part_id == 0x1321)) { | ||
| part_id = sdw_peripheral->id.part_id; | ||
| /* | ||
| * This rtd init callback is called once, so count the rt1320/rt1321 with SDCA | ||
| * function SmartMic type in this card. | ||
| */ | ||
| for_each_card_components(card, component) { | ||
| if (!is_sdw_slave(component->dev)) |
There was a problem hiding this comment.
The comment and logic assume this rtd_init helper is called only once, but the caller guards rtd_init_done per codec DAI (not per card). On platforms with multiple rt1320/rt1321 peripherals exposing the MIC DAI, this can append cfg-mics: multiple times to card->components. Consider either (1) making the update idempotent (skip if cfg-mics: already present), or (2) tracking a per-card flag (e.g., via card private data) so the cfg-mics token is set exactly once.
| static const struct snd_soc_acpi_adr_device rt722_0_agg_adr[] = { | ||
| { | ||
| .adr = 0x000030025d072201ull, | ||
| .num_endpoints = ARRAY_SIZE(jack_amp_g1_dmic_endpoints), | ||
| .endpoints = jack_amp_g1_dmic_endpoints, | ||
| .name_prefix = "rt722" | ||
| } | ||
| }; |
There was a problem hiding this comment.
The PTL match table no longer contains any rt722 ADR entry for link3 (only rt722_0_agg_adr remains for link0). This seems to conflict with the PR goal of supporting rt722 on Link3, and it likely regresses existing PTL designs where rt722 is wired on link1/link3. Consider adding the missing rt722 link3 (and/or link1) snd_soc_acpi_adr_device definitions and corresponding snd_soc_acpi_link_adr/snd_soc_acpi_mach entries (or documenting why those platforms are now expected to match a different table).
| .link_mask = BIT(0), | ||
| .links = ptl_rvp, | ||
| .drv_name = "sof_sdw", | ||
| .sof_tplg_filename = "sof-ptl-rt711.tplg", | ||
| }, | ||
| { | ||
| .link_mask = BIT(0), | ||
| .links = ptl_rt722_only, | ||
| .drv_name = "sof_sdw", | ||
| .sof_tplg_filename = "sof-ptl-rt722.tplg", | ||
| .get_function_tplg_files = sof_sdw_get_tplg_files, | ||
| }, | ||
| { | ||
| .link_mask = BIT(1), | ||
| .links = ptl_rt722_l1, | ||
| .drv_name = "sof_sdw", | ||
| .sof_tplg_filename = "sof-ptl-rt722.tplg", | ||
| .get_function_tplg_files = sof_sdw_get_tplg_files, | ||
| }, | ||
| { | ||
| .link_mask = BIT(3), | ||
| .links = ptl_sdw_rt712_vb_l3_rt1320_l3, | ||
| .drv_name = "sof_sdw", | ||
| .machine_check = snd_soc_acpi_intel_sdca_is_device_rt712_vb, | ||
| .sof_tplg_filename = "sof-ptl-rt712-l3-rt1320-l3.tplg", | ||
| .get_function_tplg_files = sof_sdw_get_tplg_files, | ||
| }, |
There was a problem hiding this comment.
This file removed the snd_soc_acpi_mach entries that matched rt722-only systems on link0/link1/link3, but there is no replacement entry for rt722 on link3 (or link1). If PTL systems still exist with an rt722-only (or rt722-on-link3) configuration, they will no longer match any machine and audio will fail to probe. Please add an appropriate machine entry for the rt722 link placement(s) you need to support, or keep the removed entries if they’re still required.
These commits support the combination with rt722 and rt1320 soundwire devices.