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 "skl_hda_dsp_common.h"
16 
17 #include <sound/hda_codec.h>
18 #include "../../codecs/hdac_hda.h"
19 
20 #define NAME_SIZE	32
21 
22 int skl_hda_hdmi_add_pcm(struct snd_soc_card *card, int device)
23 {
24 	struct skl_hda_private *ctx = snd_soc_card_get_drvdata(card);
25 	struct skl_hda_hdmi_pcm *pcm;
26 	char dai_name[NAME_SIZE];
27 
28 	pcm = devm_kzalloc(card->dev, sizeof(*pcm), GFP_KERNEL);
29 	if (!pcm)
30 		return -ENOMEM;
31 
32 	snprintf(dai_name, sizeof(dai_name), "intel-hdmi-hifi%d",
33 		 ctx->dai_index);
34 	pcm->codec_dai = snd_soc_card_get_codec_dai(card, dai_name);
35 	if (!pcm->codec_dai)
36 		return -EINVAL;
37 
38 	pcm->device = device;
39 	list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
40 
41 	return 0;
42 }
43 
44 SND_SOC_DAILINK_DEFS(idisp1,
45 	DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")),
46 	DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi1")));
47 
48 SND_SOC_DAILINK_DEFS(idisp2,
49 	DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")),
50 	DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2")));
51 
52 SND_SOC_DAILINK_DEFS(idisp3,
53 	DAILINK_COMP_ARRAY(COMP_CPU("iDisp3 Pin")),
54 	DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi3")));
55 
56 SND_SOC_DAILINK_DEF(analog_cpu,
57 	DAILINK_COMP_ARRAY(COMP_CPU("Analog CPU DAI")));
58 SND_SOC_DAILINK_DEF(analog_codec,
59 	DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D0", "Analog Codec DAI")));
60 
61 SND_SOC_DAILINK_DEF(digital_cpu,
62 	DAILINK_COMP_ARRAY(COMP_CPU("Digital CPU DAI")));
63 SND_SOC_DAILINK_DEF(digital_codec,
64 	DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D0", "Digital Codec DAI")));
65 
66 SND_SOC_DAILINK_DEF(dmic_pin,
67 	DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
68 
69 SND_SOC_DAILINK_DEF(dmic_codec,
70 	DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
71 
72 SND_SOC_DAILINK_DEF(dmic16k,
73 	DAILINK_COMP_ARRAY(COMP_CPU("DMIC16k Pin")));
74 
75 SND_SOC_DAILINK_DEF(platform,
76 	DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3")));
77 
78 /* skl_hda_digital audio interface glue - connects codec <--> CPU */
79 struct snd_soc_dai_link skl_hda_be_dai_links[HDA_DSP_MAX_BE_DAI_LINKS] = {
80 	/* Back End DAI links */
81 	{
82 		.name = "iDisp1",
83 		.id = 1,
84 		.dpcm_playback = 1,
85 		.no_pcm = 1,
86 		SND_SOC_DAILINK_REG(idisp1),
87 	},
88 	{
89 		.name = "iDisp2",
90 		.id = 2,
91 		.dpcm_playback = 1,
92 		.no_pcm = 1,
93 		SND_SOC_DAILINK_REG(idisp2),
94 	},
95 	{
96 		.name = "iDisp3",
97 		.id = 3,
98 		.dpcm_playback = 1,
99 		.no_pcm = 1,
100 		SND_SOC_DAILINK_REG(idisp3),
101 	},
102 	{
103 		.name = "Analog Playback and Capture",
104 		.id = 4,
105 		.dpcm_playback = 1,
106 		.dpcm_capture = 1,
107 		.no_pcm = 1,
108 		SND_SOC_DAILINK_REG(analog_cpu, analog_codec, platform),
109 	},
110 	{
111 		.name = "Digital Playback and Capture",
112 		.id = 5,
113 		.dpcm_playback = 1,
114 		.dpcm_capture = 1,
115 		.no_pcm = 1,
116 		SND_SOC_DAILINK_REG(digital_cpu, digital_codec, platform),
117 	},
118 	{
119 		.name = "dmic01",
120 		.id = 6,
121 		.dpcm_capture = 1,
122 		.no_pcm = 1,
123 		SND_SOC_DAILINK_REG(dmic_pin, dmic_codec, platform),
124 	},
125 	{
126 		.name = "dmic16k",
127 		.id = 7,
128 		.dpcm_capture = 1,
129 		.no_pcm = 1,
130 		SND_SOC_DAILINK_REG(dmic16k, dmic_codec, platform),
131 	},
132 };
133 
134 int skl_hda_hdmi_jack_init(struct snd_soc_card *card)
135 {
136 	struct skl_hda_private *ctx = snd_soc_card_get_drvdata(card);
137 	struct snd_soc_component *component = NULL;
138 	struct skl_hda_hdmi_pcm *pcm;
139 	char jack_name[NAME_SIZE];
140 	int err;
141 
142 	if (ctx->common_hdmi_codec_drv)
143 		return skl_hda_hdmi_build_controls(card);
144 
145 	list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
146 		component = pcm->codec_dai->component;
147 		snprintf(jack_name, sizeof(jack_name),
148 			 "HDMI/DP, pcm=%d Jack", pcm->device);
149 		err = snd_soc_card_jack_new(card, jack_name,
150 					    SND_JACK_AVOUT, &pcm->hdmi_jack,
151 					    NULL, 0);
152 
153 		if (err)
154 			return err;
155 
156 		err = snd_jack_add_new_kctl(pcm->hdmi_jack.jack,
157 					    jack_name, SND_JACK_AVOUT);
158 		if (err)
159 			dev_warn(component->dev, "failed creating Jack kctl\n");
160 
161 		err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
162 					  &pcm->hdmi_jack);
163 		if (err < 0)
164 			return err;
165 	}
166 
167 	if (!component)
168 		return -EINVAL;
169 
170 	return hdac_hdmi_jack_port_init(component, &card->dapm);
171 }
172