Skip to content

Commit 9931763

Browse files
mstrozekbardliao
authored andcommitted
ASoC: soc_sdw_utils: skip aux device if it is not present
Similarly to codec endpoints that may not be used [1], aux devices (like HID) also may not be used. Hence skip aux devices which are not present. [1] https://lore.kernel.org/all/20250414063239.85200-12-yung-chuan.liao@linux.intel.com/ Signed-off-by: Maciej Strozek <mstrozek@opensource.cirrus.com>
1 parent 9ee2666 commit 9931763

1 file changed

Lines changed: 74 additions & 2 deletions

File tree

sound/soc/sdw_utils/soc_sdw_utils.c

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1553,14 +1553,71 @@ int asoc_sdw_init_simple_dai_link(struct device *dev, struct snd_soc_dai_link *d
15531553
}
15541554
EXPORT_SYMBOL_NS(asoc_sdw_init_simple_dai_link, "SND_SOC_SDW_UTILS");
15551555

1556+
/**
1557+
* is_sdca_aux_dev_present - Check if an SDCA aux device is present on the SDW peripheral
1558+
* @dev: Device pointer
1559+
* @aux_codec_name: Aux codec name from the codec info (e.g. "snd_soc_sdca.HID.2")
1560+
* @adr_link: ACPI link address
1561+
* @adr_index: Index of the ACPI link address
1562+
*
1563+
* Return: 1 if the aux is present, 0 if the aux is not present, or negative error code.
1564+
*/
1565+
static int is_sdca_aux_dev_present(struct device *dev,
1566+
const char *aux_codec_name,
1567+
const struct snd_soc_acpi_link_adr *adr_link,
1568+
int adr_index)
1569+
{
1570+
struct sdw_slave *slave;
1571+
struct device *sdw_dev;
1572+
const char *sdw_codec_name;
1573+
int ret = 0;
1574+
int i;
1575+
1576+
if (!aux_codec_name)
1577+
return 0;
1578+
1579+
sdw_codec_name = _asoc_sdw_get_codec_name(dev, adr_link, adr_index);
1580+
if (!sdw_codec_name)
1581+
return -ENOMEM;
1582+
1583+
sdw_dev = bus_find_device_by_name(&sdw_bus_type, NULL, sdw_codec_name);
1584+
if (!sdw_dev) {
1585+
dev_err(dev, "codec %s not found\n", sdw_codec_name);
1586+
return -EINVAL;
1587+
}
1588+
1589+
slave = dev_to_sdw_dev(sdw_dev);
1590+
1591+
if (!slave->sdca_data.interface_revision) {
1592+
dev_warn(dev, "No SDCA properties, assuming aux '%s' present\n", aux_codec_name);
1593+
ret = 1;
1594+
goto put_dev;
1595+
}
1596+
1597+
for (i = 0; i < slave->sdca_data.num_functions; i++) {
1598+
const char *fname = slave->sdca_data.function[i].name;
1599+
1600+
if (fname && strstr(aux_codec_name, fname)) {
1601+
ret = 1;
1602+
goto put_dev;
1603+
}
1604+
}
1605+
1606+
dev_dbg(dev, "SDCA function for aux '%s' NOT FOUND on slave, skipping\n", aux_codec_name);
1607+
1608+
put_dev:
1609+
put_device(sdw_dev);
1610+
return ret;
1611+
}
1612+
15561613
int asoc_sdw_count_sdw_endpoints(struct snd_soc_card *card,
15571614
int *num_devs, int *num_ends, int *num_aux)
15581615
{
15591616
struct device *dev = card->dev;
15601617
struct snd_soc_acpi_mach *mach = dev_get_platdata(dev);
15611618
struct snd_soc_acpi_mach_params *mach_params = &mach->mach_params;
15621619
const struct snd_soc_acpi_link_adr *adr_link;
1563-
int i;
1620+
int i, j, ret;
15641621

15651622
for (adr_link = mach_params->links; adr_link->num_adr; adr_link++) {
15661623
*num_devs += adr_link->num_adr;
@@ -1575,7 +1632,14 @@ int asoc_sdw_count_sdw_endpoints(struct snd_soc_card *card,
15751632
if (!codec_info)
15761633
return -EINVAL;
15771634

1578-
*num_aux += codec_info->aux_num;
1635+
for (j = 0; j < codec_info->aux_num; j++) {
1636+
ret = is_sdca_aux_dev_present(dev, codec_info->auxs[j].codec_name,
1637+
adr_link, i);
1638+
if (ret < 0)
1639+
return ret;
1640+
if (ret)
1641+
(*num_aux)++;
1642+
}
15791643
}
15801644
}
15811645

@@ -1739,6 +1803,14 @@ int asoc_sdw_parse_sdw_endpoints(struct snd_soc_card *card,
17391803
for (j = 0; j < codec_info->aux_num; j++) {
17401804
struct snd_soc_component *component;
17411805

1806+
ret = is_sdca_aux_dev_present(dev, codec_info->auxs[j].codec_name,
1807+
adr_link, i);
1808+
if (ret < 0)
1809+
return ret;
1810+
1811+
if (ret == 0)
1812+
continue;
1813+
17421814
component = snd_soc_lookup_component_by_name(codec_info->auxs[j].codec_name);
17431815
if (component) {
17441816
dev_dbg(dev, "%s found component %s for aux name %s\n",

0 commit comments

Comments
 (0)