1 // SPDX-License-Identifier: GPL-2.0-only
2 // Copyright(c) 2021 Intel Corporation.
3 
4 /*
5  * Intel SOF Machine Driver with Cirrus Logic CS42L42 Codec
6  * and speaker codec MAX98357A
7  */
8 #include <linux/i2c.h>
9 #include <linux/input.h>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
12 #include <linux/regulator/consumer.h>
13 #include <linux/dmi.h>
14 #include <sound/core.h>
15 #include <sound/jack.h>
16 #include <sound/pcm.h>
17 #include <sound/pcm_params.h>
18 #include <sound/soc.h>
19 #include <sound/sof.h>
20 #include <sound/soc-acpi.h>
21 #include <dt-bindings/sound/cs42l42.h>
22 #include "../../codecs/hdac_hdmi.h"
23 #include "../common/soc-intel-quirks.h"
24 #include "hda_dsp_common.h"
25 #include "sof_maxim_common.h"
26 
27 #define NAME_SIZE 32
28 
29 #define SOF_CS42L42_SSP_CODEC(quirk)		((quirk) & GENMASK(2, 0))
30 #define SOF_CS42L42_SSP_CODEC_MASK		(GENMASK(2, 0))
31 #define SOF_SPEAKER_AMP_PRESENT			BIT(3)
32 #define SOF_CS42L42_SSP_AMP_SHIFT		4
33 #define SOF_CS42L42_SSP_AMP_MASK		(GENMASK(6, 4))
34 #define SOF_CS42L42_SSP_AMP(quirk)	\
35 	(((quirk) << SOF_CS42L42_SSP_AMP_SHIFT) & SOF_CS42L42_SSP_AMP_MASK)
36 #define SOF_CS42L42_NUM_HDMIDEV_SHIFT		7
37 #define SOF_CS42L42_NUM_HDMIDEV_MASK		(GENMASK(9, 7))
38 #define SOF_CS42L42_NUM_HDMIDEV(quirk)	\
39 	(((quirk) << SOF_CS42L42_NUM_HDMIDEV_SHIFT) & SOF_CS42L42_NUM_HDMIDEV_MASK)
40 #define SOF_CS42L42_DAILINK_SHIFT		10
41 #define SOF_CS42L42_DAILINK_MASK		(GENMASK(24, 10))
42 #define SOF_CS42L42_DAILINK(link1, link2, link3, link4, link5) \
43 	((((link1) | ((link2) << 3) | ((link3) << 6) | ((link4) << 9) | ((link5) << 12)) << SOF_CS42L42_DAILINK_SHIFT) & SOF_CS42L42_DAILINK_MASK)
44 #define SOF_MAX98357A_SPEAKER_AMP_PRESENT	BIT(25)
45 #define SOF_MAX98360A_SPEAKER_AMP_PRESENT	BIT(26)
46 
47 enum {
48 	LINK_NONE = 0,
49 	LINK_HP = 1,
50 	LINK_SPK = 2,
51 	LINK_DMIC = 3,
52 	LINK_HDMI = 4,
53 };
54 
55 static struct snd_soc_jack_pin jack_pins[] = {
56 	{
57 		.pin    = "Headphone Jack",
58 		.mask   = SND_JACK_HEADPHONE,
59 	},
60 	{
61 		.pin    = "Headset Mic",
62 		.mask   = SND_JACK_MICROPHONE,
63 	},
64 };
65 
66 /* Default: SSP2 */
67 static unsigned long sof_cs42l42_quirk = SOF_CS42L42_SSP_CODEC(2);
68 
69 struct sof_hdmi_pcm {
70 	struct list_head head;
71 	struct snd_soc_dai *codec_dai;
72 	struct snd_soc_jack hdmi_jack;
73 	int device;
74 };
75 
76 struct sof_card_private {
77 	struct snd_soc_jack headset_jack;
78 	struct list_head hdmi_pcm_list;
79 	bool common_hdmi_codec_drv;
80 };
81 
82 static int sof_hdmi_init(struct snd_soc_pcm_runtime *rtd)
83 {
84 	struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
85 	struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
86 	struct sof_hdmi_pcm *pcm;
87 
88 	pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
89 	if (!pcm)
90 		return -ENOMEM;
91 
92 	/* dai_link id is 1:1 mapped to the PCM device */
93 	pcm->device = rtd->dai_link->id;
94 	pcm->codec_dai = dai;
95 
96 	list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
97 
98 	return 0;
99 }
100 
101 static int sof_cs42l42_init(struct snd_soc_pcm_runtime *rtd)
102 {
103 	struct sof_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
104 	struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
105 	struct snd_soc_jack *jack = &ctx->headset_jack;
106 	int ret;
107 
108 	/*
109 	 * Headset buttons map to the google Reference headset.
110 	 * These can be configured by userspace.
111 	 */
112 	ret = snd_soc_card_jack_new_pins(rtd->card, "Headset Jack",
113 					 SND_JACK_HEADSET | SND_JACK_BTN_0 |
114 					 SND_JACK_BTN_1 | SND_JACK_BTN_2 |
115 					 SND_JACK_BTN_3,
116 					 jack,
117 					 jack_pins,
118 					 ARRAY_SIZE(jack_pins));
119 	if (ret) {
120 		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
121 		return ret;
122 	}
123 
124 	snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
125 	snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
126 	snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
127 	snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
128 
129 	ret = snd_soc_component_set_jack(component, jack, NULL);
130 	if (ret) {
131 		dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
132 		return ret;
133 	}
134 
135 	return ret;
136 };
137 
138 static void sof_cs42l42_exit(struct snd_soc_pcm_runtime *rtd)
139 {
140 	struct snd_soc_component *component = asoc_rtd_to_codec(rtd, 0)->component;
141 
142 	snd_soc_component_set_jack(component, NULL, NULL);
143 }
144 
145 static int sof_cs42l42_hw_params(struct snd_pcm_substream *substream,
146 				 struct snd_pcm_hw_params *params)
147 {
148 	struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
149 	struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
150 	int clk_freq, ret;
151 
152 	clk_freq = sof_dai_get_bclk(rtd); /* BCLK freq */
153 
154 	if (clk_freq <= 0) {
155 		dev_err(rtd->dev, "get bclk freq failed: %d\n", clk_freq);
156 		return -EINVAL;
157 	}
158 
159 	/* Configure sysclk for codec */
160 	ret = snd_soc_dai_set_sysclk(codec_dai, 0,
161 				     clk_freq, SND_SOC_CLOCK_IN);
162 	if (ret < 0)
163 		dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
164 
165 	return ret;
166 }
167 
168 static const struct snd_soc_ops sof_cs42l42_ops = {
169 	.hw_params = sof_cs42l42_hw_params,
170 };
171 
172 static struct snd_soc_dai_link_component platform_component[] = {
173 	{
174 		/* name might be overridden during probe */
175 		.name = "0000:00:1f.3"
176 	}
177 };
178 
179 static int sof_card_late_probe(struct snd_soc_card *card)
180 {
181 	struct sof_card_private *ctx = snd_soc_card_get_drvdata(card);
182 	struct snd_soc_component *component = NULL;
183 	char jack_name[NAME_SIZE];
184 	struct sof_hdmi_pcm *pcm;
185 	int err;
186 
187 	if (list_empty(&ctx->hdmi_pcm_list))
188 		return -EINVAL;
189 
190 	if (ctx->common_hdmi_codec_drv) {
191 		pcm = list_first_entry(&ctx->hdmi_pcm_list, struct sof_hdmi_pcm,
192 				       head);
193 		component = pcm->codec_dai->component;
194 		return hda_dsp_hdmi_build_controls(card, component);
195 	}
196 
197 	list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
198 		component = pcm->codec_dai->component;
199 		snprintf(jack_name, sizeof(jack_name),
200 			 "HDMI/DP, pcm=%d Jack", pcm->device);
201 		err = snd_soc_card_jack_new(card, jack_name,
202 					    SND_JACK_AVOUT, &pcm->hdmi_jack);
203 
204 		if (err)
205 			return err;
206 
207 		err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
208 					  &pcm->hdmi_jack);
209 		if (err < 0)
210 			return err;
211 	}
212 
213 	return hdac_hdmi_jack_port_init(component, &card->dapm);
214 }
215 
216 static const struct snd_kcontrol_new sof_controls[] = {
217 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
218 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
219 };
220 
221 static const struct snd_soc_dapm_widget sof_widgets[] = {
222 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
223 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
224 };
225 
226 static const struct snd_soc_dapm_widget dmic_widgets[] = {
227 	SND_SOC_DAPM_MIC("SoC DMIC", NULL),
228 };
229 
230 static const struct snd_soc_dapm_route sof_map[] = {
231 	/* HP jack connectors - unknown if we have jack detection */
232 	{"Headphone Jack", NULL, "HP"},
233 
234 	/* other jacks */
235 	{"HS", NULL, "Headset Mic"},
236 };
237 
238 static const struct snd_soc_dapm_route dmic_map[] = {
239 	/* digital mics */
240 	{"DMic", NULL, "SoC DMIC"},
241 };
242 
243 static int dmic_init(struct snd_soc_pcm_runtime *rtd)
244 {
245 	struct snd_soc_card *card = rtd->card;
246 	int ret;
247 
248 	ret = snd_soc_dapm_new_controls(&card->dapm, dmic_widgets,
249 					ARRAY_SIZE(dmic_widgets));
250 	if (ret) {
251 		dev_err(card->dev, "DMic widget addition failed: %d\n", ret);
252 		/* Don't need to add routes if widget addition failed */
253 		return ret;
254 	}
255 
256 	ret = snd_soc_dapm_add_routes(&card->dapm, dmic_map,
257 				      ARRAY_SIZE(dmic_map));
258 
259 	if (ret)
260 		dev_err(card->dev, "DMic map addition failed: %d\n", ret);
261 
262 	return ret;
263 }
264 
265 /* sof audio machine driver for cs42l42 codec */
266 static struct snd_soc_card sof_audio_card_cs42l42 = {
267 	.name = "cs42l42", /* the sof- prefix is added by the core */
268 	.owner = THIS_MODULE,
269 	.controls = sof_controls,
270 	.num_controls = ARRAY_SIZE(sof_controls),
271 	.dapm_widgets = sof_widgets,
272 	.num_dapm_widgets = ARRAY_SIZE(sof_widgets),
273 	.dapm_routes = sof_map,
274 	.num_dapm_routes = ARRAY_SIZE(sof_map),
275 	.fully_routed = true,
276 	.late_probe = sof_card_late_probe,
277 };
278 
279 static struct snd_soc_dai_link_component cs42l42_component[] = {
280 	{
281 		.name = "i2c-10134242:00",
282 		.dai_name = "cs42l42",
283 	}
284 };
285 
286 static struct snd_soc_dai_link_component dmic_component[] = {
287 	{
288 		.name = "dmic-codec",
289 		.dai_name = "dmic-hifi",
290 	}
291 };
292 
293 static int create_spk_amp_dai_links(struct device *dev,
294 				    struct snd_soc_dai_link *links,
295 				    struct snd_soc_dai_link_component *cpus,
296 				    int *id, int ssp_amp)
297 {
298 	int ret = 0;
299 
300 	/* speaker amp */
301 	if (!(sof_cs42l42_quirk & SOF_SPEAKER_AMP_PRESENT))
302 		return 0;
303 
304 	links[*id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec",
305 					 ssp_amp);
306 	if (!links[*id].name) {
307 		ret = -ENOMEM;
308 		goto devm_err;
309 	}
310 
311 	links[*id].id = *id;
312 
313 	if (sof_cs42l42_quirk & SOF_MAX98357A_SPEAKER_AMP_PRESENT) {
314 		max_98357a_dai_link(&links[*id]);
315 	} else if (sof_cs42l42_quirk & SOF_MAX98360A_SPEAKER_AMP_PRESENT) {
316 		max_98360a_dai_link(&links[*id]);
317 	} else {
318 		dev_err(dev, "no amp defined\n");
319 		ret = -EINVAL;
320 		goto devm_err;
321 	}
322 
323 	links[*id].platforms = platform_component;
324 	links[*id].num_platforms = ARRAY_SIZE(platform_component);
325 	links[*id].dpcm_playback = 1;
326 	links[*id].no_pcm = 1;
327 	links[*id].cpus = &cpus[*id];
328 	links[*id].num_cpus = 1;
329 
330 	links[*id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
331 						   "SSP%d Pin", ssp_amp);
332 	if (!links[*id].cpus->dai_name) {
333 		ret = -ENOMEM;
334 		goto devm_err;
335 	}
336 
337 	(*id)++;
338 
339 devm_err:
340 	return ret;
341 }
342 
343 static int create_hp_codec_dai_links(struct device *dev,
344 				     struct snd_soc_dai_link *links,
345 				     struct snd_soc_dai_link_component *cpus,
346 				     int *id, int ssp_codec)
347 {
348 	/* codec SSP */
349 	links[*id].name = devm_kasprintf(dev, GFP_KERNEL, "SSP%d-Codec",
350 					 ssp_codec);
351 	if (!links[*id].name)
352 		goto devm_err;
353 
354 	links[*id].id = *id;
355 	links[*id].codecs = cs42l42_component;
356 	links[*id].num_codecs = ARRAY_SIZE(cs42l42_component);
357 	links[*id].platforms = platform_component;
358 	links[*id].num_platforms = ARRAY_SIZE(platform_component);
359 	links[*id].init = sof_cs42l42_init;
360 	links[*id].exit = sof_cs42l42_exit;
361 	links[*id].ops = &sof_cs42l42_ops;
362 	links[*id].dpcm_playback = 1;
363 	links[*id].dpcm_capture = 1;
364 	links[*id].no_pcm = 1;
365 	links[*id].cpus = &cpus[*id];
366 	links[*id].num_cpus = 1;
367 
368 	links[*id].cpus->dai_name = devm_kasprintf(dev, GFP_KERNEL,
369 						   "SSP%d Pin",
370 						   ssp_codec);
371 	if (!links[*id].cpus->dai_name)
372 		goto devm_err;
373 
374 	(*id)++;
375 
376 	return 0;
377 
378 devm_err:
379 	return -ENOMEM;
380 }
381 
382 static int create_dmic_dai_links(struct device *dev,
383 				 struct snd_soc_dai_link *links,
384 				 struct snd_soc_dai_link_component *cpus,
385 				 int *id, int dmic_be_num)
386 {
387 	int i;
388 
389 	/* dmic */
390 	if (dmic_be_num <= 0)
391 		return 0;
392 
393 	/* at least we have dmic01 */
394 	links[*id].name = "dmic01";
395 	links[*id].cpus = &cpus[*id];
396 	links[*id].cpus->dai_name = "DMIC01 Pin";
397 	links[*id].init = dmic_init;
398 	if (dmic_be_num > 1) {
399 		/* set up 2 BE links at most */
400 		links[*id + 1].name = "dmic16k";
401 		links[*id + 1].cpus = &cpus[*id + 1];
402 		links[*id + 1].cpus->dai_name = "DMIC16k Pin";
403 		dmic_be_num = 2;
404 	}
405 
406 	for (i = 0; i < dmic_be_num; i++) {
407 		links[*id].id = *id;
408 		links[*id].num_cpus = 1;
409 		links[*id].codecs = dmic_component;
410 		links[*id].num_codecs = ARRAY_SIZE(dmic_component);
411 		links[*id].platforms = platform_component;
412 		links[*id].num_platforms = ARRAY_SIZE(platform_component);
413 		links[*id].ignore_suspend = 1;
414 		links[*id].dpcm_capture = 1;
415 		links[*id].no_pcm = 1;
416 
417 		(*id)++;
418 	}
419 
420 	return 0;
421 }
422 
423 static int create_hdmi_dai_links(struct device *dev,
424 				 struct snd_soc_dai_link *links,
425 				 struct snd_soc_dai_link_component *cpus,
426 				 int *id, int hdmi_num)
427 {
428 	struct snd_soc_dai_link_component *idisp_components;
429 	int i;
430 
431 	/* HDMI */
432 	if (hdmi_num <= 0)
433 		return 0;
434 
435 	idisp_components = devm_kzalloc(dev,
436 					sizeof(struct snd_soc_dai_link_component) *
437 					hdmi_num, GFP_KERNEL);
438 	if (!idisp_components)
439 		goto devm_err;
440 
441 	for (i = 1; i <= hdmi_num; i++) {
442 		links[*id].name = devm_kasprintf(dev, GFP_KERNEL,
443 						 "iDisp%d", i);
444 		if (!links[*id].name)
445 			goto devm_err;
446 
447 		links[*id].id = *id;
448 		links[*id].cpus = &cpus[*id];
449 		links[*id].num_cpus = 1;
450 		links[*id].cpus->dai_name = devm_kasprintf(dev,
451 							   GFP_KERNEL,
452 							   "iDisp%d Pin",
453 							   i);
454 		if (!links[*id].cpus->dai_name)
455 			goto devm_err;
456 
457 		idisp_components[i - 1].name = "ehdaudio0D2";
458 		idisp_components[i - 1].dai_name = devm_kasprintf(dev,
459 								  GFP_KERNEL,
460 								  "intel-hdmi-hifi%d",
461 								  i);
462 		if (!idisp_components[i - 1].dai_name)
463 			goto devm_err;
464 
465 		links[*id].codecs = &idisp_components[i - 1];
466 		links[*id].num_codecs = 1;
467 		links[*id].platforms = platform_component;
468 		links[*id].num_platforms = ARRAY_SIZE(platform_component);
469 		links[*id].init = sof_hdmi_init;
470 		links[*id].dpcm_playback = 1;
471 		links[*id].no_pcm = 1;
472 
473 		(*id)++;
474 	}
475 
476 	return 0;
477 
478 devm_err:
479 	return -ENOMEM;
480 }
481 
482 static struct snd_soc_dai_link *sof_card_dai_links_create(struct device *dev,
483 							  int ssp_codec,
484 							  int ssp_amp,
485 							  int dmic_be_num,
486 							  int hdmi_num)
487 {
488 	struct snd_soc_dai_link_component *cpus;
489 	struct snd_soc_dai_link *links;
490 	int ret, id = 0, link_seq;
491 
492 	links = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link) *
493 			     sof_audio_card_cs42l42.num_links, GFP_KERNEL);
494 	cpus = devm_kzalloc(dev, sizeof(struct snd_soc_dai_link_component) *
495 			     sof_audio_card_cs42l42.num_links, GFP_KERNEL);
496 	if (!links || !cpus)
497 		goto devm_err;
498 
499 	link_seq = (sof_cs42l42_quirk & SOF_CS42L42_DAILINK_MASK) >> SOF_CS42L42_DAILINK_SHIFT;
500 
501 	while (link_seq) {
502 		int link_type = link_seq & 0x07;
503 
504 		switch (link_type) {
505 		case LINK_HP:
506 			ret = create_hp_codec_dai_links(dev, links, cpus, &id, ssp_codec);
507 			if (ret < 0) {
508 				dev_err(dev, "fail to create hp codec dai links, ret %d\n",
509 					ret);
510 				goto devm_err;
511 			}
512 			break;
513 		case LINK_SPK:
514 			ret = create_spk_amp_dai_links(dev, links, cpus, &id, ssp_amp);
515 			if (ret < 0) {
516 				dev_err(dev, "fail to create spk amp dai links, ret %d\n",
517 					ret);
518 				goto devm_err;
519 			}
520 			break;
521 		case LINK_DMIC:
522 			ret = create_dmic_dai_links(dev, links, cpus, &id, dmic_be_num);
523 			if (ret < 0) {
524 				dev_err(dev, "fail to create dmic dai links, ret %d\n",
525 					ret);
526 				goto devm_err;
527 			}
528 			break;
529 		case LINK_HDMI:
530 			ret = create_hdmi_dai_links(dev, links, cpus, &id, hdmi_num);
531 			if (ret < 0) {
532 				dev_err(dev, "fail to create hdmi dai links, ret %d\n",
533 					ret);
534 				goto devm_err;
535 			}
536 			break;
537 		case LINK_NONE:
538 			/* caught here if it's not used as terminator in macro */
539 		default:
540 			dev_err(dev, "invalid link type %d\n", link_type);
541 			goto devm_err;
542 		}
543 
544 		link_seq >>= 3;
545 	}
546 
547 	return links;
548 devm_err:
549 	return NULL;
550 }
551 
552 static int sof_audio_probe(struct platform_device *pdev)
553 {
554 	struct snd_soc_dai_link *dai_links;
555 	struct snd_soc_acpi_mach *mach;
556 	struct sof_card_private *ctx;
557 	int dmic_be_num, hdmi_num;
558 	int ret, ssp_amp, ssp_codec;
559 
560 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
561 	if (!ctx)
562 		return -ENOMEM;
563 
564 	if (pdev->id_entry && pdev->id_entry->driver_data)
565 		sof_cs42l42_quirk = (unsigned long)pdev->id_entry->driver_data;
566 
567 	mach = pdev->dev.platform_data;
568 
569 	if (soc_intel_is_glk()) {
570 		dmic_be_num = 1;
571 		hdmi_num = 3;
572 	} else {
573 		dmic_be_num = 2;
574 		hdmi_num = (sof_cs42l42_quirk & SOF_CS42L42_NUM_HDMIDEV_MASK) >>
575 			 SOF_CS42L42_NUM_HDMIDEV_SHIFT;
576 		/* default number of HDMI DAI's */
577 		if (!hdmi_num)
578 			hdmi_num = 3;
579 	}
580 
581 	dev_dbg(&pdev->dev, "sof_cs42l42_quirk = %lx\n", sof_cs42l42_quirk);
582 
583 	ssp_amp = (sof_cs42l42_quirk & SOF_CS42L42_SSP_AMP_MASK) >>
584 			SOF_CS42L42_SSP_AMP_SHIFT;
585 
586 	ssp_codec = sof_cs42l42_quirk & SOF_CS42L42_SSP_CODEC_MASK;
587 
588 	/* compute number of dai links */
589 	sof_audio_card_cs42l42.num_links = 1 + dmic_be_num + hdmi_num;
590 
591 	if (sof_cs42l42_quirk & SOF_SPEAKER_AMP_PRESENT)
592 		sof_audio_card_cs42l42.num_links++;
593 
594 	dai_links = sof_card_dai_links_create(&pdev->dev, ssp_codec, ssp_amp,
595 					      dmic_be_num, hdmi_num);
596 	if (!dai_links)
597 		return -ENOMEM;
598 
599 	sof_audio_card_cs42l42.dai_link = dai_links;
600 
601 	INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
602 
603 	sof_audio_card_cs42l42.dev = &pdev->dev;
604 
605 	/* set platform name for each dailink */
606 	ret = snd_soc_fixup_dai_links_platform_name(&sof_audio_card_cs42l42,
607 						    mach->mach_params.platform);
608 	if (ret)
609 		return ret;
610 
611 	ctx->common_hdmi_codec_drv = mach->mach_params.common_hdmi_codec_drv;
612 
613 	snd_soc_card_set_drvdata(&sof_audio_card_cs42l42, ctx);
614 
615 	return devm_snd_soc_register_card(&pdev->dev,
616 					  &sof_audio_card_cs42l42);
617 }
618 
619 static const struct platform_device_id board_ids[] = {
620 	{
621 		.name = "glk_cs4242_mx98357a",
622 		.driver_data = (kernel_ulong_t)(SOF_CS42L42_SSP_CODEC(2) |
623 					SOF_SPEAKER_AMP_PRESENT |
624 					SOF_MAX98357A_SPEAKER_AMP_PRESENT |
625 					SOF_CS42L42_SSP_AMP(1)) |
626 					SOF_CS42L42_DAILINK(LINK_SPK, LINK_HP, LINK_DMIC, LINK_HDMI, LINK_NONE),
627 	},
628 	{
629 		.name = "jsl_cs4242_mx98360a",
630 		.driver_data = (kernel_ulong_t)(SOF_CS42L42_SSP_CODEC(0) |
631 					SOF_SPEAKER_AMP_PRESENT |
632 					SOF_MAX98360A_SPEAKER_AMP_PRESENT |
633 					SOF_CS42L42_SSP_AMP(1)) |
634 					SOF_CS42L42_DAILINK(LINK_HP, LINK_DMIC, LINK_HDMI, LINK_SPK, LINK_NONE),
635 	},
636 	{ }
637 };
638 MODULE_DEVICE_TABLE(platform, board_ids);
639 
640 static struct platform_driver sof_audio = {
641 	.probe = sof_audio_probe,
642 	.driver = {
643 		.name = "sof_cs42l42",
644 		.pm = &snd_soc_pm_ops,
645 	},
646 	.id_table = board_ids,
647 };
648 module_platform_driver(sof_audio)
649 
650 /* Module information */
651 MODULE_DESCRIPTION("SOF Audio Machine driver for CS42L42");
652 MODULE_AUTHOR("Brent Lu <brent.lu@intel.com>");
653 MODULE_LICENSE("GPL");
654 MODULE_IMPORT_NS(SND_SOC_INTEL_HDA_DSP_COMMON);
655 MODULE_IMPORT_NS(SND_SOC_INTEL_SOF_MAXIM_COMMON);
656