1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright(c) 2019 Intel Corporation.
3 
4 /*
5  * Intel Cometlake I2S Machine driver for RT1011 + RT5682 codec
6  */
7 
8 #include <linux/input.h>
9 #include <linux/module.h>
10 #include <linux/platform_device.h>
11 #include <linux/clk.h>
12 #include <linux/dmi.h>
13 #include <linux/slab.h>
14 #include <linux/acpi.h>
15 #include <sound/core.h>
16 #include <sound/jack.h>
17 #include <sound/pcm.h>
18 #include <sound/pcm_params.h>
19 #include <sound/soc.h>
20 #include <sound/rt5682.h>
21 #include <sound/soc-acpi.h>
22 #include "../../codecs/rt1011.h"
23 #include "../../codecs/rt5682.h"
24 #include "../../codecs/hdac_hdmi.h"
25 #include "hda_dsp_common.h"
26 
27 /* The platform clock outputs 24Mhz clock to codec as I2S MCLK */
28 #define CML_PLAT_CLK	24000000
29 #define CML_RT1011_CODEC_DAI "rt1011-aif"
30 #define CML_RT5682_CODEC_DAI "rt5682-aif1"
31 #define NAME_SIZE 32
32 
33 #define SOF_RT1011_SPEAKER_WL		BIT(0)
34 #define SOF_RT1011_SPEAKER_WR		BIT(1)
35 #define SOF_RT1011_SPEAKER_TL		BIT(2)
36 #define SOF_RT1011_SPEAKER_TR		BIT(3)
37 
38 /* Default: Woofer speakers  */
39 static unsigned long sof_rt1011_quirk = SOF_RT1011_SPEAKER_WL |
40 					SOF_RT1011_SPEAKER_WR;
41 
sof_rt1011_quirk_cb(const struct dmi_system_id * id)42 static int sof_rt1011_quirk_cb(const struct dmi_system_id *id)
43 {
44 	sof_rt1011_quirk = (unsigned long)id->driver_data;
45 	return 1;
46 }
47 
48 static const struct dmi_system_id sof_rt1011_quirk_table[] = {
49 	{
50 		.callback = sof_rt1011_quirk_cb,
51 		.matches = {
52 			DMI_MATCH(DMI_SYS_VENDOR, "Google"),
53 			DMI_MATCH(DMI_PRODUCT_NAME, "Helios"),
54 	},
55 		.driver_data = (void *)(SOF_RT1011_SPEAKER_WL | SOF_RT1011_SPEAKER_WR |
56 					SOF_RT1011_SPEAKER_TL | SOF_RT1011_SPEAKER_TR),
57 	},
58 	{
59 	}
60 };
61 
62 static struct snd_soc_jack hdmi_jack[3];
63 
64 struct hdmi_pcm {
65 	struct list_head head;
66 	struct snd_soc_dai *codec_dai;
67 	int device;
68 };
69 
70 struct card_private {
71 	char codec_name[SND_ACPI_I2C_ID_LEN];
72 	struct snd_soc_jack headset;
73 	struct list_head hdmi_pcm_list;
74 	bool common_hdmi_codec_drv;
75 };
76 
77 static const struct snd_kcontrol_new cml_controls[] = {
78 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
79 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
80 	SOC_DAPM_PIN_SWITCH("WL Ext Spk"),
81 	SOC_DAPM_PIN_SWITCH("WR Ext Spk"),
82 };
83 
84 static const struct snd_kcontrol_new cml_rt1011_tt_controls[] = {
85 	SOC_DAPM_PIN_SWITCH("TL Ext Spk"),
86 	SOC_DAPM_PIN_SWITCH("TR Ext Spk"),
87 };
88 
89 static const struct snd_soc_dapm_widget cml_rt1011_rt5682_widgets[] = {
90 	SND_SOC_DAPM_SPK("WL Ext Spk", NULL),
91 	SND_SOC_DAPM_SPK("WR Ext Spk", NULL),
92 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
93 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
94 	SND_SOC_DAPM_MIC("SoC DMIC", NULL),
95 };
96 
97 static const struct snd_soc_dapm_widget cml_rt1011_tt_widgets[] = {
98 	SND_SOC_DAPM_SPK("TL Ext Spk", NULL),
99 	SND_SOC_DAPM_SPK("TR Ext Spk", NULL),
100 };
101 
102 static const struct snd_soc_dapm_route cml_rt1011_rt5682_map[] = {
103 	/*WL/WR speaker*/
104 	{"WL Ext Spk", NULL, "WL SPO"},
105 	{"WR Ext Spk", NULL, "WR SPO"},
106 
107 	/* HP jack connectors - unknown if we have jack detection */
108 	{ "Headphone Jack", NULL, "HPOL" },
109 	{ "Headphone Jack", NULL, "HPOR" },
110 
111 	/* other jacks */
112 	{ "IN1P", NULL, "Headset Mic" },
113 
114 	/* DMIC */
115 	{"DMic", NULL, "SoC DMIC"},
116 };
117 
118 static const struct snd_soc_dapm_route cml_rt1011_tt_map[] = {
119 	/*TL/TR speaker*/
120 	{"TL Ext Spk", NULL, "TL SPO" },
121 	{"TR Ext Spk", NULL, "TR SPO" },
122 };
123 
124 static struct snd_soc_jack_pin jack_pins[] = {
125 	{
126 		.pin    = "Headphone Jack",
127 		.mask   = SND_JACK_HEADPHONE,
128 	},
129 	{
130 		.pin    = "Headset Mic",
131 		.mask   = SND_JACK_MICROPHONE,
132 	},
133 };
134 
cml_rt5682_codec_init(struct snd_soc_pcm_runtime * rtd)135 static int cml_rt5682_codec_init(struct snd_soc_pcm_runtime *rtd)
136 {
137 	struct card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
138 	struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
139 	struct snd_soc_jack *jack;
140 	int ret;
141 
142 	/* need to enable ASRC function for 24MHz mclk rate */
143 	rt5682_sel_asrc_clk_src(component, RT5682_DA_STEREO1_FILTER |
144 					RT5682_AD_STEREO1_FILTER,
145 					RT5682_CLK_SEL_I2S1_ASRC);
146 
147 	/*
148 	 * Headset buttons map to the google Reference headset.
149 	 * These can be configured by userspace.
150 	 */
151 	ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
152 					 SND_JACK_HEADSET | SND_JACK_BTN_0 |
153 					 SND_JACK_BTN_1 | SND_JACK_BTN_2 |
154 					 SND_JACK_BTN_3,
155 					 &ctx->headset,
156 					 jack_pins,
157 					 ARRAY_SIZE(jack_pins));
158 	if (ret) {
159 		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
160 		return ret;
161 	}
162 
163 	jack = &ctx->headset;
164 
165 	snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
166 	snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
167 	snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
168 	snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
169 	ret = snd_soc_component_set_jack(component, jack, NULL);
170 	if (ret)
171 		dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
172 
173 	return ret;
174 };
175 
cml_rt5682_codec_exit(struct snd_soc_pcm_runtime * rtd)176 static void cml_rt5682_codec_exit(struct snd_soc_pcm_runtime *rtd)
177 {
178 	struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
179 
180 	snd_soc_component_set_jack(component, NULL, NULL);
181 }
182 
cml_rt1011_spk_init(struct snd_soc_pcm_runtime * rtd)183 static int cml_rt1011_spk_init(struct snd_soc_pcm_runtime *rtd)
184 {
185 	int ret = 0;
186 	struct snd_soc_card *card = rtd->card;
187 
188 	if (sof_rt1011_quirk & (SOF_RT1011_SPEAKER_TL |
189 				SOF_RT1011_SPEAKER_TR)) {
190 
191 		ret = snd_soc_add_card_controls(card, cml_rt1011_tt_controls,
192 					ARRAY_SIZE(cml_rt1011_tt_controls));
193 		if (ret)
194 			return ret;
195 
196 		ret = snd_soc_dapm_new_controls(&card->dapm,
197 					cml_rt1011_tt_widgets,
198 					ARRAY_SIZE(cml_rt1011_tt_widgets));
199 		if (ret)
200 			return ret;
201 
202 		ret = snd_soc_dapm_add_routes(&card->dapm, cml_rt1011_tt_map,
203 					ARRAY_SIZE(cml_rt1011_tt_map));
204 
205 		if (ret)
206 			return ret;
207 	}
208 
209 	return ret;
210 }
211 
cml_rt5682_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params)212 static int cml_rt5682_hw_params(struct snd_pcm_substream *substream,
213 				struct snd_pcm_hw_params *params)
214 {
215 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
216 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
217 	int clk_id, clk_freq, pll_out, ret;
218 
219 	clk_id = RT5682_PLL1_S_MCLK;
220 	clk_freq = CML_PLAT_CLK;
221 
222 	pll_out = params_rate(params) * 512;
223 
224 	ret = snd_soc_dai_set_pll(codec_dai, 0, clk_id, clk_freq, pll_out);
225 	if (ret < 0)
226 		dev_warn(rtd->dev, "snd_soc_dai_set_pll err = %d\n", ret);
227 
228 	/* Configure sysclk for codec */
229 	ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL1,
230 				     pll_out, SND_SOC_CLOCK_IN);
231 	if (ret < 0)
232 		dev_warn(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
233 
234 	/*
235 	 * slot_width should be equal or large than data length, set them
236 	 * be the same
237 	 */
238 	ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x0, 0x0, 2,
239 				       params_width(params));
240 	if (ret < 0)
241 		dev_warn(rtd->dev, "set TDM slot err:%d\n", ret);
242 	return ret;
243 }
244 
cml_rt1011_hw_params(struct snd_pcm_substream * substream,struct snd_pcm_hw_params * params)245 static int cml_rt1011_hw_params(struct snd_pcm_substream *substream,
246 				struct snd_pcm_hw_params *params)
247 {
248 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
249 	struct snd_soc_dai *codec_dai;
250 	struct snd_soc_card *card = rtd->card;
251 	int srate, i, ret = 0;
252 
253 	srate = params_rate(params);
254 
255 	for_each_rtd_codec_dais(rtd, i, codec_dai) {
256 
257 		/* 100 Fs to drive 24 bit data */
258 		ret = snd_soc_dai_set_pll(codec_dai, 0, RT1011_PLL1_S_BCLK,
259 					  100 * srate, 256 * srate);
260 		if (ret < 0) {
261 			dev_err(card->dev, "codec_dai clock not set\n");
262 			return ret;
263 		}
264 
265 		ret = snd_soc_dai_set_sysclk(codec_dai,
266 					     RT1011_FS_SYS_PRE_S_PLL1,
267 					     256 * srate, SND_SOC_CLOCK_IN);
268 		if (ret < 0) {
269 			dev_err(card->dev, "codec_dai clock not set\n");
270 			return ret;
271 		}
272 
273 		/*
274 		 * Codec TDM is configured as 24 bit capture/ playback.
275 		 * 2 CH PB is done over 4 codecs - 2 Woofers and 2 Tweeters.
276 		 * The Left woofer and tweeter plays the Left playback data
277 		 * and  similar by the Right.
278 		 * Hence 2 codecs (1 T and 1 W pair) share same Rx slot.
279 		 * The feedback is captured for each codec individually.
280 		 * Hence all 4 codecs use 1 Tx slot each for feedback.
281 		 */
282 		if (sof_rt1011_quirk & (SOF_RT1011_SPEAKER_WL |
283 					SOF_RT1011_SPEAKER_WR)) {
284 			if (!strcmp(codec_dai->component->name, "i2c-10EC1011:00")) {
285 				ret = snd_soc_dai_set_tdm_slot(codec_dai,
286 							       0x4, 0x1, 4, 24);
287 				if (ret < 0)
288 					break;
289 			}
290 
291 			if (!strcmp(codec_dai->component->name, "i2c-10EC1011:01")) {
292 				ret = snd_soc_dai_set_tdm_slot(codec_dai,
293 							       0x8, 0x2, 4, 24);
294 				if (ret < 0)
295 					break;
296 			}
297 		}
298 
299 		if (sof_rt1011_quirk & (SOF_RT1011_SPEAKER_TL |
300 					SOF_RT1011_SPEAKER_TR)) {
301 			if (!strcmp(codec_dai->component->name, "i2c-10EC1011:02")) {
302 				ret = snd_soc_dai_set_tdm_slot(codec_dai,
303 							       0x1, 0x1, 4, 24);
304 				if (ret < 0)
305 					break;
306 			}
307 
308 			if (!strcmp(codec_dai->component->name, "i2c-10EC1011:03")) {
309 				ret = snd_soc_dai_set_tdm_slot(codec_dai,
310 							       0x2, 0x2, 4, 24);
311 				if (ret < 0)
312 					break;
313 			}
314 		}
315 	}
316 	if (ret < 0)
317 		dev_err(rtd->dev,
318 			"set codec TDM slot for %s failed with error %d\n",
319 			codec_dai->component->name, ret);
320 	return ret;
321 }
322 
323 static struct snd_soc_ops cml_rt5682_ops = {
324 	.hw_params = cml_rt5682_hw_params,
325 };
326 
327 static const struct snd_soc_ops cml_rt1011_ops = {
328 	.hw_params = cml_rt1011_hw_params,
329 };
330 
sof_card_late_probe(struct snd_soc_card * card)331 static int sof_card_late_probe(struct snd_soc_card *card)
332 {
333 	struct card_private *ctx = snd_soc_card_get_drvdata(card);
334 	struct snd_soc_component *component = NULL;
335 	char jack_name[NAME_SIZE];
336 	struct hdmi_pcm *pcm;
337 	int ret, i = 0;
338 
339 	if (list_empty(&ctx->hdmi_pcm_list))
340 		return -EINVAL;
341 
342 	if (ctx->common_hdmi_codec_drv) {
343 		pcm = list_first_entry(&ctx->hdmi_pcm_list, struct hdmi_pcm,
344 				       head);
345 		component = pcm->codec_dai->component;
346 		return hda_dsp_hdmi_build_controls(card, component);
347 	}
348 
349 	list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
350 		component = pcm->codec_dai->component;
351 		snprintf(jack_name, sizeof(jack_name),
352 			 "HDMI/DP, pcm=%d Jack", pcm->device);
353 		ret = snd_soc_card_jack_new(card, jack_name,
354 					    SND_JACK_AVOUT, &hdmi_jack[i]);
355 		if (ret)
356 			return ret;
357 
358 		ret = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
359 					  &hdmi_jack[i]);
360 		if (ret < 0)
361 			return ret;
362 
363 		i++;
364 	}
365 
366 	return hdac_hdmi_jack_port_init(component, &card->dapm);
367 }
368 
hdmi_init(struct snd_soc_pcm_runtime * rtd)369 static int hdmi_init(struct snd_soc_pcm_runtime *rtd)
370 {
371 	struct card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
372 	struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
373 	struct hdmi_pcm *pcm;
374 
375 	pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
376 	if (!pcm)
377 		return -ENOMEM;
378 
379 	pcm->device = dai->id;
380 	pcm->codec_dai = dai;
381 
382 	list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
383 
384 	return 0;
385 }
386 
387 /* Cometlake digital audio interface glue - connects codec <--> CPU */
388 
389 SND_SOC_DAILINK_DEF(ssp0_pin,
390 	DAILINK_COMP_ARRAY(COMP_CPU("SSP0 Pin")));
391 SND_SOC_DAILINK_DEF(ssp0_codec,
392 	DAILINK_COMP_ARRAY(COMP_CODEC("i2c-10EC5682:00",
393 				CML_RT5682_CODEC_DAI)));
394 
395 SND_SOC_DAILINK_DEF(ssp1_pin,
396 	DAILINK_COMP_ARRAY(COMP_CPU("SSP1 Pin")));
397 SND_SOC_DAILINK_DEF(ssp1_codec_2spk,
398 	DAILINK_COMP_ARRAY(
399 	/* WL */ COMP_CODEC("i2c-10EC1011:00", CML_RT1011_CODEC_DAI),
400 	/* WR */ COMP_CODEC("i2c-10EC1011:01", CML_RT1011_CODEC_DAI)));
401 SND_SOC_DAILINK_DEF(ssp1_codec_4spk,
402 	DAILINK_COMP_ARRAY(
403 	/* WL */ COMP_CODEC("i2c-10EC1011:00", CML_RT1011_CODEC_DAI),
404 	/* WR */ COMP_CODEC("i2c-10EC1011:01", CML_RT1011_CODEC_DAI),
405 	/* TL */ COMP_CODEC("i2c-10EC1011:02", CML_RT1011_CODEC_DAI),
406 	/* TR */ COMP_CODEC("i2c-10EC1011:03", CML_RT1011_CODEC_DAI)));
407 
408 
409 SND_SOC_DAILINK_DEF(dmic_pin,
410 	DAILINK_COMP_ARRAY(COMP_CPU("DMIC01 Pin")));
411 
412 SND_SOC_DAILINK_DEF(dmic16k_pin,
413 	DAILINK_COMP_ARRAY(COMP_CPU("DMIC16k Pin")));
414 
415 SND_SOC_DAILINK_DEF(dmic_codec,
416 	DAILINK_COMP_ARRAY(COMP_CODEC("dmic-codec", "dmic-hifi")));
417 
418 SND_SOC_DAILINK_DEF(idisp1_pin,
419 	DAILINK_COMP_ARRAY(COMP_CPU("iDisp1 Pin")));
420 SND_SOC_DAILINK_DEF(idisp1_codec,
421 	DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi1")));
422 
423 SND_SOC_DAILINK_DEF(idisp2_pin,
424 	DAILINK_COMP_ARRAY(COMP_CPU("iDisp2 Pin")));
425 SND_SOC_DAILINK_DEF(idisp2_codec,
426 	DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi2")));
427 
428 SND_SOC_DAILINK_DEF(idisp3_pin,
429 	DAILINK_COMP_ARRAY(COMP_CPU("iDisp3 Pin")));
430 SND_SOC_DAILINK_DEF(idisp3_codec,
431 	DAILINK_COMP_ARRAY(COMP_CODEC("ehdaudio0D2", "intel-hdmi-hifi3")));
432 
433 SND_SOC_DAILINK_DEF(platform,
434 	DAILINK_COMP_ARRAY(COMP_PLATFORM("0000:00:1f.3")));
435 
436 static struct snd_soc_dai_link cml_rt1011_rt5682_dailink[] = {
437 	/* Back End DAI links */
438 	{
439 		/* SSP0 - Codec */
440 		.name = "SSP0-Codec",
441 		.id = 0,
442 		.init = cml_rt5682_codec_init,
443 		.exit = cml_rt5682_codec_exit,
444 		.ignore_pmdown_time = 1,
445 		.ops = &cml_rt5682_ops,
446 		.dpcm_playback = 1,
447 		.dpcm_capture = 1,
448 		.no_pcm = 1,
449 		SND_SOC_DAILINK_REG(ssp0_pin, ssp0_codec, platform),
450 	},
451 	{
452 		.name = "dmic01",
453 		.id = 1,
454 		.ignore_suspend = 1,
455 		.dpcm_capture = 1,
456 		.no_pcm = 1,
457 		SND_SOC_DAILINK_REG(dmic_pin, dmic_codec, platform),
458 	},
459 	{
460 		.name = "dmic16k",
461 		.id = 2,
462 		.ignore_suspend = 1,
463 		.dpcm_capture = 1,
464 		.no_pcm = 1,
465 		SND_SOC_DAILINK_REG(dmic16k_pin, dmic_codec, platform),
466 	},
467 	{
468 		.name = "iDisp1",
469 		.id = 3,
470 		.init = hdmi_init,
471 		.dpcm_playback = 1,
472 		.no_pcm = 1,
473 		SND_SOC_DAILINK_REG(idisp1_pin, idisp1_codec, platform),
474 	},
475 	{
476 		.name = "iDisp2",
477 		.id = 4,
478 		.init = hdmi_init,
479 		.dpcm_playback = 1,
480 		.no_pcm = 1,
481 		SND_SOC_DAILINK_REG(idisp2_pin, idisp2_codec, platform),
482 	},
483 	{
484 		.name = "iDisp3",
485 		.id = 5,
486 		.init = hdmi_init,
487 		.dpcm_playback = 1,
488 		.no_pcm = 1,
489 		SND_SOC_DAILINK_REG(idisp3_pin, idisp3_codec, platform),
490 	},
491 	{
492 		/*
493 		 * SSP1 - Codec : added to end of list ensuring
494 		 * reuse of common topologies for other end points
495 		 * and changing only SSP1's codec
496 		 */
497 		.name = "SSP1-Codec",
498 		.id = 6,
499 		.dpcm_playback = 1,
500 		.dpcm_capture = 1, /* Capture stream provides Feedback */
501 		.no_pcm = 1,
502 		.init = cml_rt1011_spk_init,
503 		.ops = &cml_rt1011_ops,
504 		SND_SOC_DAILINK_REG(ssp1_pin, ssp1_codec_2spk, platform),
505 	},
506 };
507 
508 static struct snd_soc_codec_conf rt1011_conf[] = {
509 	{
510 		.dlc = COMP_CODEC_CONF("i2c-10EC1011:00"),
511 		.name_prefix = "WL",
512 	},
513 	{
514 		.dlc = COMP_CODEC_CONF("i2c-10EC1011:01"),
515 		.name_prefix = "WR",
516 	},
517 	/* single configuration structure for 2 and 4 channels */
518 	{
519 		.dlc = COMP_CODEC_CONF("i2c-10EC1011:02"),
520 		.name_prefix = "TL",
521 	},
522 	{
523 		.dlc = COMP_CODEC_CONF("i2c-10EC1011:03"),
524 		.name_prefix = "TR",
525 	},
526 };
527 
528 /* Cometlake audio machine driver for RT1011 and RT5682 */
529 static struct snd_soc_card snd_soc_card_cml = {
530 	.name = "cml_rt1011_rt5682",
531 	.owner = THIS_MODULE,
532 	.dai_link = cml_rt1011_rt5682_dailink,
533 	.num_links = ARRAY_SIZE(cml_rt1011_rt5682_dailink),
534 	.codec_conf = rt1011_conf,
535 	.num_configs = ARRAY_SIZE(rt1011_conf),
536 	.dapm_widgets = cml_rt1011_rt5682_widgets,
537 	.num_dapm_widgets = ARRAY_SIZE(cml_rt1011_rt5682_widgets),
538 	.dapm_routes = cml_rt1011_rt5682_map,
539 	.num_dapm_routes = ARRAY_SIZE(cml_rt1011_rt5682_map),
540 	.controls = cml_controls,
541 	.num_controls = ARRAY_SIZE(cml_controls),
542 	.fully_routed = true,
543 	.late_probe = sof_card_late_probe,
544 };
545 
snd_cml_rt1011_probe(struct platform_device * pdev)546 static int snd_cml_rt1011_probe(struct platform_device *pdev)
547 {
548 	struct snd_soc_dai_link *dai_link;
549 	struct card_private *ctx;
550 	struct snd_soc_acpi_mach *mach;
551 	const char *platform_name;
552 	int ret, i;
553 
554 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
555 	if (!ctx)
556 		return -ENOMEM;
557 
558 	INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
559 	mach = pdev->dev.platform_data;
560 	snd_soc_card_cml.dev = &pdev->dev;
561 	platform_name = mach->mach_params.platform;
562 
563 	dmi_check_system(sof_rt1011_quirk_table);
564 
565 	dev_dbg(&pdev->dev, "sof_rt1011_quirk = %lx\n", sof_rt1011_quirk);
566 
567 	/* when 4 speaker is available, update codec config */
568 	if (sof_rt1011_quirk & (SOF_RT1011_SPEAKER_TL |
569 				SOF_RT1011_SPEAKER_TR)) {
570 		for_each_card_prelinks(&snd_soc_card_cml, i, dai_link) {
571 			if (!strcmp(dai_link->codecs[0].dai_name,
572 				    CML_RT1011_CODEC_DAI)) {
573 				dai_link->codecs = ssp1_codec_4spk;
574 				dai_link->num_codecs = ARRAY_SIZE(ssp1_codec_4spk);
575 			}
576 		}
577 	}
578 
579 	/* set platform name for each dailink */
580 	ret = snd_soc_fixup_dai_links_platform_name(&snd_soc_card_cml,
581 						    platform_name);
582 	if (ret)
583 		return ret;
584 
585 	ctx->common_hdmi_codec_drv = mach->mach_params.common_hdmi_codec_drv;
586 
587 	snd_soc_card_set_drvdata(&snd_soc_card_cml, ctx);
588 
589 	return devm_snd_soc_register_card(&pdev->dev, &snd_soc_card_cml);
590 }
591 
592 static struct platform_driver snd_cml_rt1011_rt5682_driver = {
593 	.probe = snd_cml_rt1011_probe,
594 	.driver = {
595 		.name = "cml_rt1011_rt5682",
596 		.pm = &snd_soc_pm_ops,
597 	},
598 };
599 module_platform_driver(snd_cml_rt1011_rt5682_driver);
600 
601 /* Module information */
602 MODULE_DESCRIPTION("Cometlake Audio Machine driver - RT1011 and RT5682 in I2S mode");
603 MODULE_AUTHOR("Naveen Manohar <naveen.m@intel.com>");
604 MODULE_AUTHOR("Sathya Prakash M R <sathya.prakash.m.r@intel.com>");
605 MODULE_AUTHOR("Shuming Fan <shumingf@realtek.com>");
606 MODULE_AUTHOR("Mac Chiang <mac.chiang@intel.com>");
607 MODULE_LICENSE("GPL v2");
608 MODULE_ALIAS("platform:cml_rt1011_rt5682");
609 MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);
610