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 		.no_pcm = 1,
82 	},
83 	{
84 		.name = "Digital Playback and Capture",
85 		.id = 5,
86 		.cpu_dai_name = "Digital CPU DAI",
87 		.codec_name = "ehdaudio0D0",
88 		.codec_dai_name = "Digital Codec DAI",
89 		.platform_name = "0000:00:1f.3",
90 		.dpcm_playback = 1,
91 		.dpcm_capture = 1,
92 		.no_pcm = 1,
93 	},
94 	{
95 		.name = "dmic01",
96 		.id = 6,
97 		.cpu_dai_name = "DMIC01 Pin",
98 		.codec_name = "dmic-codec",
99 		.codec_dai_name = "dmic-hifi",
100 		.platform_name = "0000:00:1f.3",
101 		.dpcm_capture = 1,
102 		.no_pcm = 1,
103 	},
104 	{
105 		.name = "dmic16k",
106 		.id = 7,
107 		.cpu_dai_name = "DMIC16k Pin",
108 		.codec_name = "dmic-codec",
109 		.codec_dai_name = "dmic-hifi",
110 		.platform_name = "0000:00:1f.3",
111 		.dpcm_capture = 1,
112 		.no_pcm = 1,
113 	},
114 };
115 
116 int skl_hda_hdmi_jack_init(struct snd_soc_card *card)
117 {
118 	struct skl_hda_private *ctx = snd_soc_card_get_drvdata(card);
119 	struct snd_soc_component *component = NULL;
120 	struct skl_hda_hdmi_pcm *pcm;
121 	char jack_name[NAME_SIZE];
122 	int err;
123 
124 	list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
125 		component = pcm->codec_dai->component;
126 		snprintf(jack_name, sizeof(jack_name),
127 			 "HDMI/DP, pcm=%d Jack", pcm->device);
128 		err = snd_soc_card_jack_new(card, jack_name,
129 					    SND_JACK_AVOUT, &pcm->hdmi_jack,
130 					    NULL, 0);
131 
132 		if (err)
133 			return err;
134 
135 		err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
136 					  &pcm->hdmi_jack);
137 		if (err < 0)
138 			return err;
139 	}
140 
141 	if (!component)
142 		return -EINVAL;
143 
144 	return hdac_hdmi_jack_port_init(component, &card->dapm);
145 }
146