1 // SPDX-License-Identifier: GPL-2.0-only 2 // Copyright (c) 2023 Intel Corporation 3 4 /* 5 * sof_sdw_rt722_sdca - Helpers to handle RT722-SDCA from generic machine driver 6 */ 7 8 #include <linux/device.h> 9 #include <linux/errno.h> 10 #include <linux/soundwire/sdw.h> 11 #include <linux/soundwire/sdw_type.h> 12 #include <sound/control.h> 13 #include <sound/soc.h> 14 #include <sound/soc-acpi.h> 15 #include <sound/soc-dapm.h> 16 #include "sof_sdw_common.h" 17 18 static const struct snd_soc_dapm_widget rt722_spk_widgets[] = { 19 SND_SOC_DAPM_SPK("Speaker", NULL), 20 }; 21 22 static const struct snd_soc_dapm_route rt722_spk_map[] = { 23 { "Speaker", NULL, "rt722 SPK" }, 24 }; 25 26 static const struct snd_kcontrol_new rt722_spk_controls[] = { 27 SOC_DAPM_PIN_SWITCH("Speaker"), 28 }; 29 30 static int rt722_spk_init(struct snd_soc_pcm_runtime *rtd) 31 { 32 struct snd_soc_card *card = rtd->card; 33 int ret; 34 35 card->components = devm_kasprintf(card->dev, GFP_KERNEL, 36 "%s spk:rt722", 37 card->components); 38 if (!card->components) 39 return -ENOMEM; 40 41 ret = snd_soc_add_card_controls(card, rt722_spk_controls, 42 ARRAY_SIZE(rt722_spk_controls)); 43 if (ret) { 44 dev_err(card->dev, "failed to add rt722 spk controls: %d\n", ret); 45 return ret; 46 } 47 48 ret = snd_soc_dapm_new_controls(&card->dapm, rt722_spk_widgets, 49 ARRAY_SIZE(rt722_spk_widgets)); 50 if (ret) { 51 dev_err(card->dev, "failed to add rt722 spk widgets: %d\n", ret); 52 return ret; 53 } 54 55 ret = snd_soc_dapm_add_routes(&card->dapm, rt722_spk_map, ARRAY_SIZE(rt722_spk_map)); 56 if (ret) 57 dev_err(rtd->dev, "failed to add rt722 spk map: %d\n", ret); 58 59 return ret; 60 } 61 62 int sof_sdw_rt722_spk_init(struct snd_soc_card *card, 63 const struct snd_soc_acpi_link_adr *link, 64 struct snd_soc_dai_link *dai_links, 65 struct sof_sdw_codec_info *info, 66 bool playback) 67 { 68 dai_links->init = rt722_spk_init; 69 70 return 0; 71 } 72 73 static int rt722_sdca_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd) 74 { 75 struct snd_soc_card *card = rtd->card; 76 struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); 77 struct snd_soc_component *component = codec_dai->component; 78 79 card->components = devm_kasprintf(card->dev, GFP_KERNEL, 80 "%s mic:%s", 81 card->components, component->name_prefix); 82 if (!card->components) 83 return -ENOMEM; 84 85 return 0; 86 } 87 88 int sof_sdw_rt722_sdca_dmic_init(struct snd_soc_card *card, 89 const struct snd_soc_acpi_link_adr *link, 90 struct snd_soc_dai_link *dai_links, 91 struct sof_sdw_codec_info *info, 92 bool playback) 93 { 94 dai_links->init = rt722_sdca_dmic_rtd_init; 95 96 return 0; 97 } 98