1 // SPDX-License-Identifier: GPL-2.0 2 // Copyright(c) 2015-18 Intel Corporation. 3 4 /* 5 * Common functions used in different Intel machine drivers 6 */ 7 #include <linux/module.h> 8 #include <linux/platform_device.h> 9 #include <sound/core.h> 10 #include <sound/jack.h> 11 #include <sound/pcm.h> 12 #include <sound/pcm_params.h> 13 #include <sound/soc.h> 14 #include "../../codecs/hdac_hdmi.h" 15 #include "../skylake/skl.h" 16 #include "skl_hda_dsp_common.h" 17 18 #define NAME_SIZE 32 19 20 int skl_hda_hdmi_add_pcm(struct snd_soc_card *card, int device) 21 { 22 struct skl_hda_private *ctx = snd_soc_card_get_drvdata(card); 23 struct skl_hda_hdmi_pcm *pcm; 24 char dai_name[NAME_SIZE]; 25 26 pcm = devm_kzalloc(card->dev, sizeof(*pcm), GFP_KERNEL); 27 if (!pcm) 28 return -ENOMEM; 29 30 snprintf(dai_name, sizeof(dai_name), "intel-hdmi-hifi%d", 31 ctx->dai_index); 32 pcm->codec_dai = snd_soc_card_get_codec_dai(card, dai_name); 33 if (!pcm->codec_dai) 34 return -EINVAL; 35 36 pcm->device = device; 37 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list); 38 39 return 0; 40 } 41 42 /* skl_hda_digital audio interface glue - connects codec <--> CPU */ 43 struct snd_soc_dai_link skl_hda_be_dai_links[HDA_DSP_MAX_BE_DAI_LINKS] = { 44 /* Back End DAI links */ 45 { 46 .name = "iDisp1", 47 .id = 1, 48 .cpu_dai_name = "iDisp1 Pin", 49 .codec_name = "ehdaudio0D2", 50 .codec_dai_name = "intel-hdmi-hifi1", 51 .dpcm_playback = 1, 52 .no_pcm = 1, 53 }, 54 { 55 .name = "iDisp2", 56 .id = 2, 57 .cpu_dai_name = "iDisp2 Pin", 58 .codec_name = "ehdaudio0D2", 59 .codec_dai_name = "intel-hdmi-hifi2", 60 .dpcm_playback = 1, 61 .no_pcm = 1, 62 }, 63 { 64 .name = "iDisp3", 65 .id = 3, 66 .cpu_dai_name = "iDisp3 Pin", 67 .codec_name = "ehdaudio0D2", 68 .codec_dai_name = "intel-hdmi-hifi3", 69 .dpcm_playback = 1, 70 .no_pcm = 1, 71 }, 72 { 73 .name = "Analog Playback and Capture", 74 .id = 4, 75 .cpu_dai_name = "Analog CPU DAI", 76 .codec_name = "ehdaudio0D0", 77 .codec_dai_name = "Analog Codec DAI", 78 .platform_name = "0000:00:1f.3", 79 .dpcm_playback = 1, 80 .dpcm_capture = 1, 81 .init = NULL, 82 .no_pcm = 1, 83 }, 84 { 85 .name = "Digital Playback and Capture", 86 .id = 5, 87 .cpu_dai_name = "Digital CPU DAI", 88 .codec_name = "ehdaudio0D0", 89 .codec_dai_name = "Digital Codec DAI", 90 .platform_name = "0000:00:1f.3", 91 .dpcm_playback = 1, 92 .dpcm_capture = 1, 93 .init = NULL, 94 .no_pcm = 1, 95 }, 96 }; 97 98 int skl_hda_hdmi_jack_init(struct snd_soc_card *card) 99 { 100 struct skl_hda_private *ctx = snd_soc_card_get_drvdata(card); 101 struct snd_soc_component *component = NULL; 102 struct skl_hda_hdmi_pcm *pcm; 103 char jack_name[NAME_SIZE]; 104 int err; 105 106 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) { 107 component = pcm->codec_dai->component; 108 snprintf(jack_name, sizeof(jack_name), 109 "HDMI/DP, pcm=%d Jack", pcm->device); 110 err = snd_soc_card_jack_new(card, jack_name, 111 SND_JACK_AVOUT, &pcm->hdmi_jack, 112 NULL, 0); 113 114 if (err) 115 return err; 116 117 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device, 118 &pcm->hdmi_jack); 119 if (err < 0) 120 return err; 121 } 122 123 if (!component) 124 return -EINVAL; 125 126 return hdac_hdmi_jack_port_init(component, &card->dapm); 127 } 128