1 // SPDX-License-Identifier: GPL-2.0-only
2 // This file incorporates work covered by the following copyright notice:
3 // Copyright (c) 2024 Intel Corporation
4 // Copyright (c) 2024 Advanced Micro Devices, Inc.
5
6 /*
7 * soc_sdw_rt_dmic - Helpers to handle Realtek SDW DMIC from generic machine driver
8 */
9
10 #include <linux/device.h>
11 #include <linux/errno.h>
12 #include <sound/soc.h>
13 #include <sound/soc-acpi.h>
14 #include <sound/soc_sdw_utils.h>
15
asoc_sdw_rt_dmic_rtd_init(struct snd_soc_pcm_runtime * rtd,struct snd_soc_dai * dai)16 int asoc_sdw_rt_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd, struct snd_soc_dai *dai)
17 {
18 struct snd_soc_card *card = rtd->card;
19 struct snd_soc_component *component;
20 char *mic_name;
21
22 component = dai->component;
23
24 /*
25 * rt715-sdca (aka rt714) is a special case that uses different name in card->components
26 * and component->name_prefix.
27 */
28 if (!strcmp(component->name_prefix, "rt714"))
29 mic_name = devm_kasprintf(card->dev, GFP_KERNEL, "rt715-sdca");
30 else
31 mic_name = devm_kasprintf(card->dev, GFP_KERNEL, "%s", component->name_prefix);
32
33 card->components = devm_kasprintf(card->dev, GFP_KERNEL,
34 "%s mic:%s", card->components,
35 mic_name);
36 if (!card->components)
37 return -ENOMEM;
38
39 dev_dbg(card->dev, "card->components: %s\n", card->components);
40
41 return 0;
42 }
43 EXPORT_SYMBOL_NS(asoc_sdw_rt_dmic_rtd_init, SND_SOC_SDW_UTILS);
44