Lines Matching +full:be +full:- +full:dai +full:- +full:link
1 // SPDX-License-Identifier: GPL-2.0-only
5 * sof_sdw - ASOC Machine driver for Intel SoundWire platforms
14 #include <sound/soc-acpi.h>
19 static int quirk_override = -1;
21 MODULE_PARM_DESC(quirk, "Board-specific quirk override");
23 #define INC_ID(BE, CPU, LINK) do { (BE)++; (CPU)++; (LINK)++; } while (0)
27 /* To store SDW Pin index for each SoundWire link */
33 dev_dbg(dev, "quirk realtek,jack-detect-source %ld\n",
50 sof_sdw_quirk = (unsigned long)id->driver_data;
188 * (e.g. 15-eb1xxx, 14t-ea000 or 13-aw2xxx)
257 /* TigerLake-SDCA devices */
441 DMI_MATCH(DMI_PRODUCT_NAME, "OMEN by HP Gaming Laptop 16-k0xxx"),
555 .name = "dmic-codec",
556 .dai_name = "dmic-hifi",
562 /* name might be overridden during probe */
577 struct snd_soc_dai *dai;
579 /* Find stream from first CPU DAI */
580 dai = asoc_rtd_to_cpu(rtd, 0);
582 sdw_stream = snd_soc_dai_get_stream(dai, substream->stream);
584 dev_err(rtd->dev, "no stream found for DAI %s\n", dai->name);
595 struct snd_soc_dai *dai;
598 /* Find stream from first CPU DAI */
599 dai = asoc_rtd_to_cpu(rtd, 0);
601 sdw_stream = snd_soc_dai_get_stream(dai, substream->stream);
603 dev_err(rtd->dev, "no stream found for DAI %s\n", dai->name);
620 ret = -EINVAL;
625 dev_err(rtd->dev, "%s trigger %d failed: %d\n", __func__, cmd, ret);
643 if (!rtd->dai_link->codec_ch_maps)
646 /* Identical data will be sent to all codecs in playback */
647 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
648 ch_mask = GENMASK(ch - 1, 0);
651 num_codecs = rtd->dai_link->num_codecs;
654 dev_err(rtd->dev, "Channels number %d is invalid when codec number = %d\n",
656 return -EINVAL;
659 ch_mask = GENMASK(ch / num_codecs - 1, 0);
665 * The captured data will be combined from each cpu DAI if the dai
666 * link has more than one codec DAIs. Set codec channel mask and
667 * ASoC will set the corresponding channel numbers for each cpu dai.
671 if (rtd->dai_link->codec_ch_maps[j].connected_cpu_id != i)
673 rtd->dai_link->codec_ch_maps[j].ch_mask = ch_mask << (j * step);
683 struct snd_soc_dai *dai;
685 /* Find stream from first CPU DAI */
686 dai = asoc_rtd_to_cpu(rtd, 0);
688 sdw_stream = snd_soc_dai_get_stream(dai, substream->stream);
690 dev_err(rtd->dev, "no stream found for DAI %s\n", dai->name);
717 .dai_name = "rt700-aif1",
731 .dai_name = "rt711-sdca-aif1",
746 .dai_name = "rt711-aif1",
761 .dai_name = "rt712-sdca-aif1",
769 .dai_name = "rt712-sdca-aif2",
783 .dai_name = "rt712-sdca-dmic-aif1",
797 .dai_name = "rt712-sdca-aif1",
812 .dai_name = "rt712-sdca-dmic-aif1",
826 .dai_name = "rt1308-aif",
841 .dai_name = "rt1316-aif",
855 .dai_name = "rt1318-aif",
871 .dai_name = "rt715-aif2",
886 .dai_name = "rt715-aif2",
901 .dai_name = "rt715-aif2",
916 .dai_name = "rt715-aif2",
929 .dai_name = "max98373-aif1",
942 .dai_name = "max98363-aif1",
955 .dai_name = "rt5682-sdw",
968 .dai_name = "cs35l56-sdw1",
981 .dai_name = "cs42l42-sdw",
995 .dai_name = "sdw-mockup-aif1",
1009 .dai_name = "sdw-mockup-aif1",
1023 .dai_name = "sdw-mockup-aif1",
1036 .dai_name = "sdw-mockup-aif1",
1064 return -EINVAL;
1073 return -EINVAL;
1079 return -EINVAL;
1083 * get BE dailink number and CPU DAI number based on sdw link adr.
1084 * Since some sdw slaves may be aggregated, the CPU DAI number
1085 * may be larger than the number of BE dailinks.
1101 return -EINVAL;
1106 for (; adr_link->num_adr; adr_link++) {
1113 /* make sure the link mask has a single bit set */
1114 if (!is_power_of_2(adr_link->mask))
1115 return -EINVAL;
1117 for (i = 0; i < adr_link->num_adr; i++) {
1118 adr = adr_link->adr_d[i].adr;
1125 *codecs_num += codec_info->dai_num;
1127 if (!adr_link->adr_d[i].name_prefix) {
1129 adr_link->adr_d[i].adr);
1130 return -EINVAL;
1133 endpoint = adr_link->adr_d[i].endpoints;
1134 if (endpoint->aggregated && !endpoint->group_id) {
1135 dev_err(dev, "invalid group id on link %x\n",
1136 adr_link->mask);
1137 return -EINVAL;
1140 for (j = 0; j < codec_info->dai_num; j++) {
1141 /* count DAI number for playback and capture */
1143 if (!codec_info->dais[j].direction[stream])
1148 /* count BE for each non-aggregated slave or group */
1149 if (!endpoint->aggregated || no_aggregation ||
1150 !group_visited[endpoint->group_id])
1155 if (endpoint->aggregated)
1156 group_visited[endpoint->group_id] = true;
1170 dev_dbg(dev, "create dai link %s, id %d\n", name, be_id);
1171 dai_links->id = be_id;
1172 dai_links->name = name;
1173 dai_links->platforms = platform_component;
1174 dai_links->num_platforms = ARRAY_SIZE(platform_component);
1175 dai_links->no_pcm = 1;
1176 dai_links->cpus = cpus;
1177 dai_links->num_cpus = cpus_num;
1178 dai_links->codecs = codecs;
1179 dai_links->num_codecs = codecs_num;
1180 dai_links->dpcm_playback = playback;
1181 dai_links->dpcm_capture = capture;
1182 dai_links->init = init;
1183 dai_links->ops = ops;
1195 for (i = 0; i < adr_link->num_adr; i++) {
1203 adr = adr_link->adr_d[i].adr;
1226 u64 adr = adr_link->adr_d[adr_index].adr;
1241 codec->name = devm_kstrdup(dev,
1246 codec->name = devm_kasprintf(dev, GFP_KERNEL,
1250 codec->name = devm_kasprintf(dev, GFP_KERNEL,
1254 if (!codec->name)
1255 return -ENOMEM;
1257 codec->dai_name = codec_info_list[codec_index].dais[dai_index].dai_name;
1274 * The first link should start with adr_link->adr_d[adr_index]
1278 for ( ; i < adr_link->num_adr; i++) {
1281 codec_index = find_codec_info_part(adr_link->adr_d[i].adr);
1286 if (adr_link->adr_d[i].endpoints->group_id != group_id)
1301 } while (adr_link->mask);
1307 * check endpoint status in slaves and gather link ID for all slaves in
1308 * the same group to generate different CPU DAI. Now only support
1309 * one sdw link with all slaves set with only single group id.
1311 * one slave on one sdw link with aggregated = 0
1312 * one sdw BE DAI <---> one-cpu DAI <---> one-codec DAI
1314 * two or more slaves on one sdw link with aggregated = 0
1315 * one sdw BE DAI <---> one-cpu DAI <---> multi-codec DAIs
1318 * one sdw BE DAI <---> 1 .. N CPU DAIs <----> 1 .. N codec DAIs
1328 if (!adr_link->adr_d[adr_index].endpoints->aggregated || no_aggregation) {
1329 cpu_dai_id[0] = ffs(adr_link->mask) - 1;
1338 *group_id = adr_link->adr_d[adr_index].endpoints->group_id;
1341 for (; adr_link && adr_link->num_adr; adr_link++) {
1344 for (i = 0; i < adr_link->num_adr; i++) {
1345 if (adr_link->adr_d[i].endpoints->aggregated &&
1346 adr_link->adr_d[i].endpoints->group_id == *group_id)
1355 return -EINVAL;
1358 cpu_dai_id[(*cpu_dai_num)++] = ffs(adr_link->mask) - 1;
1391 struct device *dev = card->dev;
1413 return -ENOMEM;
1417 for (adr_link_next = adr_link; adr_link_next && adr_link_next->num_adr &&
1419 /* skip the link excluded by this processed group */
1420 if (cpu_dai_id[i] != ffs(adr_link_next->mask) - 1)
1423 /* j reset after loop, adr_index only applies to first link */
1424 for (; j < adr_link_next->num_adr && codec_dlc_index < codec_num; j++) {
1427 endpoints = adr_link_next->adr_d[j].endpoints;
1429 if (group_id && (!endpoints->aggregated ||
1430 endpoints->group_id != group_id))
1436 return -EINVAL;
1447 adr_link_next->adr_d[j].name_prefix;
1454 /* check next link to create codec dai in the processed group */
1458 /* find codec info to create BE DAI */
1459 codec_index = find_codec_info_part(adr_link->adr_d[adr_index].adr);
1464 if (codec_info->ignore_pch_dmic)
1473 "SDW%d-Playback",
1474 "SDW%d-Capture",
1475 "SDW%d-Playback-%s",
1476 "SDW%d-Capture-%s",
1479 if (!codec_info->dais[dai_index].direction[stream])
1482 *be_id = codec_info->dais[dai_index].dailink[stream];
1485 return -EINVAL;
1491 return -ENOMEM;
1493 /* create stream name according to first link id */
1497 type_strings[codec_info->dais[dai_index].dai_type]);
1503 return -ENOMEM;
1506 * generate CPU DAI name base on the sdw link ID and
1507 * PIN ID with offset of 2 according to sdw dai driver.
1514 return -ENOMEM;
1517 dev_err(dev, "invalid cpu dai index %d\n",
1519 return -EINVAL;
1526 * We create sdw dai links at first stage, so link index should
1527 * not be larger than sdw_be_num
1530 dev_err(dev, "invalid dai link index %d\n", *link_index);
1531 return -EINVAL;
1535 dev_err(dev, "invalid cpu dai index %d\n", *cpu_id);
1536 return -EINVAL;
1572 struct device *dev = card->dev;
1573 struct snd_soc_acpi_mach *mach = dev_get_platdata(card->dev);
1578 struct snd_soc_acpi_mach_params *mach_params = &mach->mach_params;
1579 const struct snd_soc_acpi_link_adr *adr_link = mach_params->links;
1602 dev_err(dev, "failed to get sdw link info %d\n", ret);
1612 ssp_codec_index = find_codec_info_acpi(mach->id);
1618 if (mach_params->codec_mask & IDISP_CODEC_MASK) {
1619 ctx->idisp_codec = true;
1628 if (sof_sdw_quirk & SOF_SDW_PCH_DMIC || mach_params->dmic_num)
1637 /* allocate BE dailinks */
1641 return -ENOMEM;
1647 return -ENOMEM;
1649 /* allocate codec conf, will be populated when dailinks are created */
1653 return -ENOMEM;
1662 for (; adr_link->num_adr; adr_link++) {
1664 * If there are two or more different devices on the same sdw link, we have to
1665 * append the codec type to the dai link name to prevent duplicated dai link name.
1666 * The same type devices on the same sdw link will be in the same
1667 * snd_soc_acpi_adr_device array. They won't be described in different adr_links.
1669 for (i = 0; i < adr_link->num_adr; i++) {
1671 codec_index = find_codec_info_part(adr_link->adr_d[i].adr);
1679 if ((SDW_PART_ID(adr_link->adr_d[i].adr) !=
1680 SDW_PART_ID(adr_link->adr_d[j].adr)) ||
1681 (SDW_MFG_ID(adr_link->adr_d[i].adr) !=
1682 SDW_MFG_ID(adr_link->adr_d[j].adr))) {
1691 /* generate DAI links by each sdw link */
1692 for (adr_link = mach_params->links ; adr_link->num_adr; adr_link++) {
1693 for (i = 0; i < adr_link->num_adr; i++) {
1696 endpoint = adr_link->adr_d[i].endpoints;
1699 if (endpoint->aggregated &&
1700 group_generated[endpoint->group_id])
1704 codec_index = find_codec_info_part(adr_link->adr_d[i].adr);
1716 dev_err(dev, "failed to create dai link %d\n", link_index);
1721 if (aggregation && endpoint->aggregated)
1722 group_generated[endpoint->group_id] = true;
1740 "SSP%d-Codec", i);
1742 return -ENOMEM;
1746 return -ENOMEM;
1751 return -ENOMEM;
1754 codec_name = devm_kasprintf(dev, GFP_KERNEL, "i2c-%s:0%d",
1755 info->acpi_id, j++);
1757 return -ENOMEM;
1759 ssp_components->name = codec_name;
1760 /* TODO: support multi codec dai on SSP when it is needed */
1761 ssp_components->dai_name = info->dais[0].dai_name;
1764 playback = info->dais[0].direction[SNDRV_PCM_STREAM_PLAYBACK];
1765 capture = info->dais[0].direction[SNDRV_PCM_STREAM_CAPTURE];
1770 NULL, info->ops);
1772 ret = info->dais[0].init(card, NULL, dai_links + link_index, info, 0);
1811 return -ENOMEM;
1818 return -ENOMEM;
1820 if (ctx->idisp_codec) {
1824 "intel-hdmi-hifi%d",
1827 return -ENOMEM;
1835 return -ENOMEM;
1850 name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-BT", port);
1852 return -ENOMEM;
1856 return -ENOMEM;
1863 card->dai_link = dai_links;
1864 card->num_links = num_links;
1866 card->codec_conf = codec_conf;
1867 card->num_configs = codec_conf_num;
1887 if (ctx->idisp_codec)
1902 /* helper to get the link that the codec DAI is used */
1911 for (j = 0; j < dai_link->num_codecs; j++) {
1912 /* Check each codec in a link */
1913 if (!strcmp(dai_link->codecs[j].dai_name, dai_name))
1928 /* Check each dai in codec_info_lis to see if it is used in the link */
1933 * dai link found.
1938 /* Do the .exit function if the codec dai is used in the link */
1941 dev_warn(card->dev,
1953 struct snd_soc_acpi_mach *mach = dev_get_platdata(&pdev->dev);
1958 card->dev = &pdev->dev;
1960 dev_dbg(card->dev, "Entry\n");
1962 ctx = devm_kzalloc(card->dev, sizeof(*ctx), GFP_KERNEL);
1964 return -ENOMEM;
1966 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
1972 if (quirk_override != -1) {
1973 dev_info(card->dev, "Overriding quirk 0x%lx => 0x%x\n",
1978 log_quirks(card->dev);
1984 if (mach->mach_params.subsystem_id_set) {
1986 mach->mach_params.subsystem_vendor,
1987 mach->mach_params.subsystem_device);
1996 * amp_num will only be increased for active amp
2002 card->components = devm_kasprintf(card->dev, GFP_KERNEL,
2003 "cfg-spk:%d cfg-amp:%d",
2006 if (!card->components)
2007 return -ENOMEM;
2009 if (mach->mach_params.dmic_num) {
2010 card->components = devm_kasprintf(card->dev, GFP_KERNEL,
2011 "%s mic:dmic cfg-mics:%d",
2012 card->components,
2013 mach->mach_params.dmic_num);
2014 if (!card->components)
2015 return -ENOMEM;
2018 card->long_name = sdw_card_long_name;
2021 ret = devm_snd_soc_register_card(card->dev, card);
2023 dev_err(card->dev, "snd_soc_register_card failed %d\n", ret);
2059 MODULE_AUTHOR("Bard Liao <yung-chuan.liao@linux.intel.com>");
2061 MODULE_AUTHOR("Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>");