1// SPDX-License-Identifier: GPL-2.0-only 2// Copyright (c) 2023 Intel Corporation 3 4/* 5 * sof_sdw_rt712_sdca - Helpers to handle RT712-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_board_helpers.h" 17#include "sof_sdw_common.h" 18 19static const struct snd_soc_dapm_widget rt712_spk_widgets[] = { 20 SND_SOC_DAPM_SPK("Speaker", NULL), 21}; 22 23/* 24 * dapm routes for rt712 spk will be registered dynamically according 25 * to the number of rt712 spk used. The first two entries will be registered 26 * for one codec case, and the last two entries are also registered 27 * if two rt712s are used. 28 */ 29static const struct snd_soc_dapm_route rt712_spk_map[] = { 30 { "Speaker", NULL, "rt712 SPOL" }, 31 { "Speaker", NULL, "rt712 SPOR" }, 32}; 33 34static const struct snd_kcontrol_new rt712_spk_controls[] = { 35 SOC_DAPM_PIN_SWITCH("Speaker"), 36}; 37 38int rt712_spk_rtd_init(struct snd_soc_pcm_runtime *rtd) 39{ 40 struct snd_soc_card *card = rtd->card; 41 int ret; 42 43 card->components = devm_kasprintf(card->dev, GFP_KERNEL, 44 "%s spk:rt712", 45 card->components); 46 if (!card->components) 47 return -ENOMEM; 48 49 ret = snd_soc_add_card_controls(card, rt712_spk_controls, 50 ARRAY_SIZE(rt712_spk_controls)); 51 if (ret) { 52 dev_err(card->dev, "rt712 spk controls addition failed: %d\n", ret); 53 return ret; 54 } 55 56 ret = snd_soc_dapm_new_controls(&card->dapm, rt712_spk_widgets, 57 ARRAY_SIZE(rt712_spk_widgets)); 58 if (ret) { 59 dev_err(card->dev, "rt712 spk widgets addition failed: %d\n", ret); 60 return ret; 61 } 62 63 ret = snd_soc_dapm_add_routes(&card->dapm, rt712_spk_map, ARRAY_SIZE(rt712_spk_map)); 64 if (ret) 65 dev_err(rtd->dev, "failed to add SPK map: %d\n", ret); 66 67 return ret; 68} 69 70static const char * const dmics[] = { 71 "rt712-sdca-dmic" 72}; 73 74int rt712_sdca_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd) 75{ 76 struct snd_soc_card *card = rtd->card; 77 struct snd_soc_dai *codec_dai; 78 struct snd_soc_component *component; 79 80 codec_dai = get_codec_dai_by_name(rtd, dmics, ARRAY_SIZE(dmics)); 81 if (!codec_dai) 82 return -EINVAL; 83 84 component = codec_dai->component; 85 card->components = devm_kasprintf(card->dev, GFP_KERNEL, 86 "%s mic:%s", 87 card->components, component->name_prefix); 88 if (!card->components) 89 return -ENOMEM; 90 91 return 0; 92} 93MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_BOARD_HELPERS); 94