Linux Audio

Check our new training course

Loading...
Note: File does not exist in v6.13.7.
  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_sdw_common.h"
 17
 18static const struct snd_soc_dapm_widget rt712_spk_widgets[] = {
 19	SND_SOC_DAPM_SPK("Speaker", NULL),
 20};
 21
 22/*
 23 * dapm routes for rt712 spk will be registered dynamically according
 24 * to the number of rt712 spk used. The first two entries will be registered
 25 * for one codec case, and the last two entries are also registered
 26 * if two rt712s are used.
 27 */
 28static const struct snd_soc_dapm_route rt712_spk_map[] = {
 29	{ "Speaker", NULL, "rt712 SPOL" },
 30	{ "Speaker", NULL, "rt712 SPOR" },
 31};
 32
 33static const struct snd_kcontrol_new rt712_spk_controls[] = {
 34	SOC_DAPM_PIN_SWITCH("Speaker"),
 35};
 36
 37static int rt712_spk_init(struct snd_soc_pcm_runtime *rtd)
 38{
 39	struct snd_soc_card *card = rtd->card;
 40	int ret;
 41
 42	card->components = devm_kasprintf(card->dev, GFP_KERNEL,
 43					  "%s spk:rt712",
 44					  card->components);
 45	if (!card->components)
 46		return -ENOMEM;
 47
 48	ret = snd_soc_add_card_controls(card, rt712_spk_controls,
 49					ARRAY_SIZE(rt712_spk_controls));
 50	if (ret) {
 51		dev_err(card->dev, "rt712 spk controls addition failed: %d\n", ret);
 52		return ret;
 53	}
 54
 55	ret = snd_soc_dapm_new_controls(&card->dapm, rt712_spk_widgets,
 56					ARRAY_SIZE(rt712_spk_widgets));
 57	if (ret) {
 58		dev_err(card->dev, "rt712 spk widgets addition failed: %d\n", ret);
 59		return ret;
 60	}
 61
 62	ret = snd_soc_dapm_add_routes(&card->dapm, rt712_spk_map, ARRAY_SIZE(rt712_spk_map));
 63	if (ret)
 64		dev_err(rtd->dev, "failed to add SPK map: %d\n", ret);
 65
 66	return ret;
 67}
 68
 69int sof_sdw_rt712_spk_init(struct snd_soc_card *card,
 70			   const struct snd_soc_acpi_link_adr *link,
 71			   struct snd_soc_dai_link *dai_links,
 72			   struct sof_sdw_codec_info *info,
 73			   bool playback)
 74{
 75	dai_links->init = rt712_spk_init;
 76
 77	return 0;
 78}
 79
 80static int rt712_sdca_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd)
 81{
 82	struct snd_soc_card *card = rtd->card;
 83	struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0);
 84	struct snd_soc_component *component = codec_dai->component;
 85
 86	card->components = devm_kasprintf(card->dev, GFP_KERNEL,
 87					  "%s mic:%s",
 88					  card->components, component->name_prefix);
 89	if (!card->components)
 90		return -ENOMEM;
 91
 92	return 0;
 93}
 94
 95int sof_sdw_rt712_sdca_dmic_init(struct snd_soc_card *card,
 96				 const struct snd_soc_acpi_link_adr *link,
 97				 struct snd_soc_dai_link *dai_links,
 98				 struct sof_sdw_codec_info *info,
 99				 bool playback)
100{
101	dai_links->init = rt712_sdca_dmic_rtd_init;
102
103	return 0;
104}