|
| 1 | +// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause) |
| 2 | +// |
| 3 | +// This file is provided under a dual BSD/GPLv2 license. When using or |
| 4 | +// redistributing this file, you may do so under either license. |
| 5 | +// |
| 6 | +// Copyright(c) 2025 Intel Corporation. |
| 7 | +// |
| 8 | + |
| 9 | +#include <linux/device.h> |
| 10 | +#include <linux/errno.h> |
| 11 | +#include "sof-priv.h" |
| 12 | +#include "topology.h" |
| 13 | + |
| 14 | +enum tplg_device_id { |
| 15 | + TPLG_DEVICE_SDCA_JACK, |
| 16 | + TPLG_DEVICE_SDCA_AMP, |
| 17 | + TPLG_DEVICE_SDCA_MIC, |
| 18 | + TPLG_DEVICE_PCH_DMIC, |
| 19 | + TPLG_DEVICE_HDMI, |
| 20 | + TPLG_DEVICE_MAX |
| 21 | +}; |
| 22 | + |
| 23 | +#define SDCA_DEVICE_MASK (BIT(TPLG_DEVICE_SDCA_JACK) | BIT(TPLG_DEVICE_SDCA_AMP) | \ |
| 24 | + BIT(TPLG_DEVICE_SDCA_MIC)) |
| 25 | + |
| 26 | +#define SOF_INTEL_PLATFORM_NAME_MAX 4 |
| 27 | + |
| 28 | +int get_sof_sdw_tplg_files(struct snd_soc_component *scomp, const char *file, char ***tplg_files) |
| 29 | +{ |
| 30 | + struct snd_sof_dev *sdev = snd_soc_component_get_drvdata(scomp); |
| 31 | + struct snd_sof_pdata *sof_pdata = sdev->pdata; |
| 32 | + struct snd_soc_dai_link *dai_link; |
| 33 | + char platform[SOF_INTEL_PLATFORM_NAME_MAX]; |
| 34 | + unsigned long tplg_mask = 0; |
| 35 | + int tplg_num = 0; |
| 36 | + int tplg_dev; |
| 37 | + int ret; |
| 38 | + int i; |
| 39 | + |
| 40 | + if (sdev->pdata->ipc_type == SOF_IPC_TYPE_3) |
| 41 | + return 0; |
| 42 | + |
| 43 | + ret = sscanf(sof_pdata->tplg_filename, "sof-%3s-*.tplg", platform); |
| 44 | + if (ret != 1) |
| 45 | + return 0; |
| 46 | + |
| 47 | + /* tplg_num is always less or equal to dai_link numbers */ |
| 48 | + *tplg_files = kcalloc(scomp->card->num_links, sizeof(char *), GFP_KERNEL); |
| 49 | + if (!(*tplg_files)) |
| 50 | + return -ENOMEM; |
| 51 | + |
| 52 | + for_each_card_prelinks(scomp->card, i, dai_link) { |
| 53 | + char *tplg_device; |
| 54 | + |
| 55 | + dev_dbg(scomp->dev, "dai_link %s id %d\n", dai_link->name, dai_link->id); |
| 56 | + if (strstr(dai_link->name, "SimpleJack")) { |
| 57 | + tplg_dev = TPLG_DEVICE_SDCA_JACK; |
| 58 | + tplg_device = "sdca-jack"; |
| 59 | + } else if (strstr(dai_link->name, "SmartAmp")) { |
| 60 | + tplg_dev = TPLG_DEVICE_SDCA_AMP; |
| 61 | + tplg_device = devm_kasprintf(sdev->dev, GFP_KERNEL, |
| 62 | + "sdca-%damp", dai_link->num_cpus); |
| 63 | + if (!tplg_device) |
| 64 | + return -ENOMEM; |
| 65 | + } else if (strstr(dai_link->name, "SmartMic")) { |
| 66 | + tplg_dev = TPLG_DEVICE_SDCA_MIC; |
| 67 | + tplg_device = "sdca-mic"; |
| 68 | + } else if (strstr(dai_link->name, "dmic")) { |
| 69 | + if (strstr(file, "-2ch")) { |
| 70 | + tplg_device = "dmic-2ch"; |
| 71 | + } else if (strstr(file, "-4ch")) { |
| 72 | + tplg_device = "dmic-4ch"; |
| 73 | + } else { |
| 74 | + dev_warn(scomp->dev, |
| 75 | + "only -2ch and -4ch are supported for dmic\n"); |
| 76 | + continue; |
| 77 | + } |
| 78 | + tplg_dev = TPLG_DEVICE_PCH_DMIC; |
| 79 | + } else if (strstr(dai_link->name, "iDisp")) { |
| 80 | + tplg_dev = TPLG_DEVICE_HDMI; |
| 81 | + tplg_device = "hdmi-pcm5"; |
| 82 | + |
| 83 | + } else { |
| 84 | + /* The dai link is not supported by sperated tplg yet */ |
| 85 | + dev_dbg(scomp->dev, |
| 86 | + "dai_link %s is not supported by sperated tplg yet, Fail back to %s\n", |
| 87 | + dai_link->name, file); |
| 88 | + return 0; |
| 89 | + } |
| 90 | + if (tplg_mask & BIT(tplg_dev)) |
| 91 | + continue; |
| 92 | + |
| 93 | + tplg_mask |= BIT(tplg_dev); |
| 94 | + |
| 95 | + /* |
| 96 | + * The tplg file naming rule is sof-<platform>-<function>-id<BE id number>.tplg |
| 97 | + * where <platform> is only required for the DMIC function as the nhlt blob |
| 98 | + * is platform depentent. |
| 99 | + */ |
| 100 | + switch (tplg_dev) { |
| 101 | + case TPLG_DEVICE_PCH_DMIC: |
| 102 | + (*tplg_files)[tplg_num] = kasprintf(GFP_KERNEL, "%s/sof-%s-%s-id%d.tplg", |
| 103 | + sof_pdata->tplg_filename_prefix, |
| 104 | + platform, tplg_device, dai_link->id); |
| 105 | + break; |
| 106 | + default: |
| 107 | + (*tplg_files)[tplg_num] = kasprintf(GFP_KERNEL, "%s/sof-%s-id%d.tplg", |
| 108 | + sof_pdata->tplg_filename_prefix, |
| 109 | + tplg_device, dai_link->id); |
| 110 | + break; |
| 111 | + } |
| 112 | + if (!(*tplg_files)[tplg_num]) |
| 113 | + return -ENOMEM; |
| 114 | + tplg_num++; |
| 115 | + } |
| 116 | + |
| 117 | + dev_dbg(scomp->dev, "tplg_mask %#lx tplg_num %d\n", tplg_mask, tplg_num); |
| 118 | + return tplg_num; |
| 119 | +} |
| 120 | + |
0 commit comments