Path: blob/master/sound/soc/intel/boards/hda_dsp_common.c
51948 views
// SPDX-License-Identifier: GPL-2.0-only1//2// Copyright(c) 2019 Intel Corporation34#include <linux/module.h>5#include <sound/pcm.h>6#include <sound/soc.h>7#include <sound/hda_codec.h>8#include <sound/hda_i915.h>9#include "../../codecs/hdac_hda.h"1011#include "hda_dsp_common.h"1213#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)1415/*16* Search card topology and return PCM device number17* matching Nth playback HDMI device (zero-based index).18*/19static struct snd_pcm *hda_dsp_hdmi_pcm_handle(struct snd_soc_card *card,20int hdmi_idx)21{22struct snd_soc_pcm_runtime *rtd;23struct snd_pcm *spcm;24int i = 0;2526for_each_card_rtds(card, rtd) {27/* ignore BE PCMs */28if (rtd->dai_link && rtd->dai_link->no_pcm)29continue;3031spcm = rtd->pcm;3233/* ignore PCMs with no playback streams */34if (!spcm || !spcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream)35continue;3637/* look for FE PCMs with name "HDMI x" */38if (spcm && strstr(spcm->id, "HDMI")) {39if (i == hdmi_idx)40return rtd->pcm;41++i;42}43}4445return NULL;46}4748/*49* Search card topology and register HDMI PCM related controls50* to codec driver.51*/52int hda_dsp_hdmi_build_controls(struct snd_soc_card *card,53struct snd_soc_component *comp)54{55struct hdac_hda_priv *hda_pvt;56struct hda_codec *hcodec;57struct snd_pcm *spcm;58struct hda_pcm *hpcm;59int err = 0, i = 0;6061if (!comp)62return -EINVAL;6364hda_pvt = snd_soc_component_get_drvdata(comp);65hcodec = hda_pvt->codec;6667list_for_each_entry(hpcm, &hcodec->pcm_list_head, list) {68spcm = hda_dsp_hdmi_pcm_handle(card, i);69if (spcm) {70hpcm->pcm = spcm;71hpcm->device = spcm->device;72dev_dbg(card->dev,73"mapping HDMI converter %d to PCM %d (%p)\n",74i, hpcm->device, spcm);75} else {76hpcm->pcm = NULL;77hpcm->device = SNDRV_PCM_INVALID_DEVICE;78dev_warn(card->dev,79"%s: no PCM in topology for HDMI converter %d\n",80__func__, i);81}82i++;83}84snd_hdac_display_power(hcodec->core.bus,85HDA_CODEC_IDX_CONTROLLER, true);86err = snd_hda_codec_build_controls(hcodec);87if (err < 0)88dev_err(card->dev, "unable to create controls %d\n", err);89snd_hdac_display_power(hcodec->core.bus,90HDA_CODEC_IDX_CONTROLLER, false);9192return err;93}94EXPORT_SYMBOL_NS(hda_dsp_hdmi_build_controls, "SND_SOC_INTEL_HDA_DSP_COMMON");9596#endif9798MODULE_DESCRIPTION("ASoC Intel HDMI helpers");99MODULE_LICENSE("GPL");100101102