Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 //
0003 // Copyright(c) 2019 Intel Corporation. All rights reserved.
0004 
0005 #include <linux/module.h>
0006 #include <sound/pcm.h>
0007 #include <sound/soc.h>
0008 #include <sound/hda_codec.h>
0009 #include <sound/hda_i915.h>
0010 #include "../../codecs/hdac_hda.h"
0011 
0012 #include "hda_dsp_common.h"
0013 
0014 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
0015 
0016 /*
0017  * Search card topology and return PCM device number
0018  * matching Nth HDMI device (zero-based index).
0019  */
0020 static struct snd_pcm *hda_dsp_hdmi_pcm_handle(struct snd_soc_card *card,
0021                            int hdmi_idx)
0022 {
0023     struct snd_soc_pcm_runtime *rtd;
0024     struct snd_pcm *spcm;
0025     int i = 0;
0026 
0027     for_each_card_rtds(card, rtd) {
0028         spcm = rtd->pcm ?
0029             rtd->pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].pcm : NULL;
0030         if (spcm && strstr(spcm->id, "HDMI")) {
0031             if (i == hdmi_idx)
0032                 return rtd->pcm;
0033             ++i;
0034         }
0035     }
0036 
0037     return NULL;
0038 }
0039 
0040 /*
0041  * Search card topology and register HDMI PCM related controls
0042  * to codec driver.
0043  */
0044 int hda_dsp_hdmi_build_controls(struct snd_soc_card *card,
0045                 struct snd_soc_component *comp)
0046 {
0047     struct hdac_hda_priv *hda_pvt;
0048     struct hda_codec *hcodec;
0049     struct snd_pcm *spcm;
0050     struct hda_pcm *hpcm;
0051     int err = 0, i = 0;
0052 
0053     if (!comp)
0054         return -EINVAL;
0055 
0056     hda_pvt = snd_soc_component_get_drvdata(comp);
0057     hcodec = &hda_pvt->codec;
0058 
0059     list_for_each_entry(hpcm, &hcodec->pcm_list_head, list) {
0060         spcm = hda_dsp_hdmi_pcm_handle(card, i);
0061         if (spcm) {
0062             hpcm->pcm = spcm;
0063             hpcm->device = spcm->device;
0064             dev_dbg(card->dev,
0065                 "mapping HDMI converter %d to PCM %d (%p)\n",
0066                 i, hpcm->device, spcm);
0067         } else {
0068             hpcm->pcm = NULL;
0069             hpcm->device = SNDRV_PCM_INVALID_DEVICE;
0070             dev_warn(card->dev,
0071                  "%s: no PCM in topology for HDMI converter %d\n",
0072                  __func__, i);
0073         }
0074         i++;
0075     }
0076     snd_hdac_display_power(hcodec->core.bus,
0077                    HDA_CODEC_IDX_CONTROLLER, true);
0078     err = snd_hda_codec_build_controls(hcodec);
0079     if (err < 0)
0080         dev_err(card->dev, "unable to create controls %d\n", err);
0081     snd_hdac_display_power(hcodec->core.bus,
0082                    HDA_CODEC_IDX_CONTROLLER, false);
0083 
0084     return err;
0085 }
0086 EXPORT_SYMBOL_NS(hda_dsp_hdmi_build_controls, SND_SOC_INTEL_HDA_DSP_COMMON);
0087 
0088 #endif
0089 
0090 MODULE_DESCRIPTION("ASoC Intel HDMI helpers");
0091 MODULE_LICENSE("GPL");