Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ASoC: soc-acpi: move link_slaves_found()

Move existing function in common library to make sure the code can be
reused by other SoC vendors.

No functionality change outside of the move and added prefix.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Reviewed-by: Rander Wang <rander.wang@intel.com>
Reviewed-by: Bard Liao <yung-chuan.liao@linux.intel.com>
Link: https://lore.kernel.org/r/20230731213242.434594-3-pierre-louis.bossart@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Pierre-Louis Bossart and committed by
Mark Brown
bb29a33c 799d9933

+88 -79
+5
include/linux/soundwire/sdw.h
··· 482 482 __u8 sdw_version:4; 483 483 }; 484 484 485 + struct sdw_extended_slave_id { 486 + int link_id; 487 + struct sdw_slave_id id; 488 + }; 489 + 485 490 /* 486 491 * Helper macros to extract the MIPI-defined IDs 487 492 *
+1 -6
include/linux/soundwire/sdw_intel.h
··· 264 264 */ 265 265 #define SDW_INTEL_CLK_STOP_BUS_RESET BIT(3) 266 266 267 - struct sdw_intel_slave_id { 268 - int link_id; 269 - struct sdw_slave_id id; 270 - }; 271 - 272 267 struct hdac_bus; 273 268 274 269 /** ··· 293 298 int num_slaves; 294 299 acpi_handle handle; 295 300 struct sdw_intel_link_dev **ldev; 296 - struct sdw_intel_slave_id *ids; 301 + struct sdw_extended_slave_id *ids; 297 302 struct list_head link_list; 298 303 struct mutex shim_lock; /* lock for access to shared SHIM registers */ 299 304 u32 shim_mask;
+6
include/sound/soc-acpi.h
··· 9 9 #include <linux/stddef.h> 10 10 #include <linux/acpi.h> 11 11 #include <linux/mod_devicetable.h> 12 + #include <linux/soundwire/sdw.h> 12 13 13 14 struct snd_soc_acpi_package_context { 14 15 char *name; /* package name */ ··· 208 207 return dev->parent && dev->parent->driver && dev->parent->driver->name && 209 208 !strncmp(dev->parent->driver->name, "sof-audio-acpi", strlen("sof-audio-acpi")); 210 209 } 210 + 211 + bool snd_soc_acpi_sdw_link_slaves_found(struct device *dev, 212 + const struct snd_soc_acpi_link_adr *link, 213 + struct sdw_extended_slave_id *ids, 214 + int num_slaves); 211 215 212 216 #endif
+73
sound/soc/soc-acpi.c
··· 125 125 } 126 126 EXPORT_SYMBOL_GPL(snd_soc_acpi_codec_list); 127 127 128 + #define SDW_CODEC_ADR_MASK(_adr) ((_adr) & (SDW_DISCO_LINK_ID_MASK | SDW_VERSION_MASK | \ 129 + SDW_MFG_ID_MASK | SDW_PART_ID_MASK)) 130 + 131 + /* Check if all Slaves defined on the link can be found */ 132 + bool snd_soc_acpi_sdw_link_slaves_found(struct device *dev, 133 + const struct snd_soc_acpi_link_adr *link, 134 + struct sdw_extended_slave_id *ids, 135 + int num_slaves) 136 + { 137 + unsigned int part_id, link_id, unique_id, mfg_id, version; 138 + int i, j, k; 139 + 140 + for (i = 0; i < link->num_adr; i++) { 141 + u64 adr = link->adr_d[i].adr; 142 + int reported_part_count = 0; 143 + 144 + mfg_id = SDW_MFG_ID(adr); 145 + part_id = SDW_PART_ID(adr); 146 + link_id = SDW_DISCO_LINK_ID(adr); 147 + version = SDW_VERSION(adr); 148 + 149 + for (j = 0; j < num_slaves; j++) { 150 + /* find out how many identical parts were reported on that link */ 151 + if (ids[j].link_id == link_id && 152 + ids[j].id.part_id == part_id && 153 + ids[j].id.mfg_id == mfg_id && 154 + ids[j].id.sdw_version == version) 155 + reported_part_count++; 156 + } 157 + 158 + for (j = 0; j < num_slaves; j++) { 159 + int expected_part_count = 0; 160 + 161 + if (ids[j].link_id != link_id || 162 + ids[j].id.part_id != part_id || 163 + ids[j].id.mfg_id != mfg_id || 164 + ids[j].id.sdw_version != version) 165 + continue; 166 + 167 + /* find out how many identical parts are expected */ 168 + for (k = 0; k < link->num_adr; k++) { 169 + u64 adr2 = link->adr_d[k].adr; 170 + 171 + if (SDW_CODEC_ADR_MASK(adr2) == SDW_CODEC_ADR_MASK(adr)) 172 + expected_part_count++; 173 + } 174 + 175 + if (reported_part_count == expected_part_count) { 176 + /* 177 + * we have to check unique id 178 + * if there is more than one 179 + * Slave on the link 180 + */ 181 + unique_id = SDW_UNIQUE_ID(adr); 182 + if (reported_part_count == 1 || 183 + ids[j].id.unique_id == unique_id) { 184 + dev_dbg(dev, "found %x at link %d\n", part_id, link_id); 185 + break; 186 + } 187 + } else { 188 + dev_dbg(dev, "part %x reported %d expected %d on link %d, skipping\n", 189 + part_id, reported_part_count, expected_part_count, link_id); 190 + } 191 + } 192 + if (j == num_slaves) { 193 + dev_dbg(dev, "Slave %x not found\n", part_id); 194 + return false; 195 + } 196 + } 197 + return true; 198 + } 199 + EXPORT_SYMBOL_GPL(snd_soc_acpi_sdw_link_slaves_found); 200 + 128 201 MODULE_LICENSE("GPL v2"); 129 202 MODULE_DESCRIPTION("ALSA SoC ACPI module");
+3 -73
sound/soc/sof/intel/hda.c
··· 1429 1429 1430 1430 #if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE) 1431 1431 1432 - #define SDW_CODEC_ADR_MASK(_adr) ((_adr) & (SDW_DISCO_LINK_ID_MASK | SDW_VERSION_MASK | \ 1433 - SDW_MFG_ID_MASK | SDW_PART_ID_MASK)) 1434 - 1435 - /* Check if all Slaves defined on the link can be found */ 1436 - static bool link_slaves_found(struct device *dev, 1437 - const struct snd_soc_acpi_link_adr *link, 1438 - struct sdw_intel_slave_id *ids, 1439 - int num_slaves) 1440 - { 1441 - unsigned int part_id, link_id, unique_id, mfg_id, version; 1442 - int i, j, k; 1443 - 1444 - for (i = 0; i < link->num_adr; i++) { 1445 - u64 adr = link->adr_d[i].adr; 1446 - int reported_part_count = 0; 1447 - 1448 - mfg_id = SDW_MFG_ID(adr); 1449 - part_id = SDW_PART_ID(adr); 1450 - link_id = SDW_DISCO_LINK_ID(adr); 1451 - version = SDW_VERSION(adr); 1452 - 1453 - for (j = 0; j < num_slaves; j++) { 1454 - /* find out how many identical parts were reported on that link */ 1455 - if (ids[j].link_id == link_id && 1456 - ids[j].id.part_id == part_id && 1457 - ids[j].id.mfg_id == mfg_id && 1458 - ids[j].id.sdw_version == version) 1459 - reported_part_count++; 1460 - } 1461 - 1462 - for (j = 0; j < num_slaves; j++) { 1463 - int expected_part_count = 0; 1464 - 1465 - if (ids[j].link_id != link_id || 1466 - ids[j].id.part_id != part_id || 1467 - ids[j].id.mfg_id != mfg_id || 1468 - ids[j].id.sdw_version != version) 1469 - continue; 1470 - 1471 - /* find out how many identical parts are expected */ 1472 - for (k = 0; k < link->num_adr; k++) { 1473 - u64 adr2 = link->adr_d[k].adr; 1474 - 1475 - if (SDW_CODEC_ADR_MASK(adr2) == SDW_CODEC_ADR_MASK(adr)) 1476 - expected_part_count++; 1477 - } 1478 - 1479 - if (reported_part_count == expected_part_count) { 1480 - /* 1481 - * we have to check unique id 1482 - * if there is more than one 1483 - * Slave on the link 1484 - */ 1485 - unique_id = SDW_UNIQUE_ID(adr); 1486 - if (reported_part_count == 1 || 1487 - ids[j].id.unique_id == unique_id) { 1488 - dev_dbg(dev, "found %x at link %d\n", part_id, link_id); 1489 - break; 1490 - } 1491 - } else { 1492 - dev_dbg(dev, "part %x reported %d expected %d on link %d, skipping\n", 1493 - part_id, reported_part_count, expected_part_count, link_id); 1494 - } 1495 - } 1496 - if (j == num_slaves) { 1497 - dev_dbg(dev, "Slave %x not found\n", part_id); 1498 - return false; 1499 - } 1500 - } 1501 - return true; 1502 - } 1503 - 1504 1432 static struct snd_soc_acpi_mach *hda_sdw_machine_select(struct snd_sof_dev *sdev) 1505 1433 { 1506 1434 struct snd_sof_pdata *pdata = sdev->pdata; ··· 1472 1544 * Try next machine if any expected Slaves 1473 1545 * are not found on this link. 1474 1546 */ 1475 - if (!link_slaves_found(sdev->dev, link, hdev->sdw->ids, hdev->sdw->num_slaves)) 1547 + if (!snd_soc_acpi_sdw_link_slaves_found(sdev->dev, link, 1548 + hdev->sdw->ids, 1549 + hdev->sdw->num_slaves)) 1476 1550 break; 1477 1551 } 1478 1552 /* Found if all Slaves are checked */