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