1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright(c) 2018 Intel Corporation.
3 
4 /*
5  * Intel Geminilake I2S Machine Driver with MAX98357A & RT5682 Codecs
6  *
7  * Modified from:
8  *   Intel Apollolake I2S Machine driver
9  */
10 
11 #include <linux/input.h>
12 #include <linux/module.h>
13 #include <linux/platform_device.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/soc-acpi.h>
20 #include "../skylake/skl.h"
21 #include "../../codecs/rt5682.h"
22 #include "../../codecs/hdac_hdmi.h"
23 
24 /* The platform clock outputs 19.2Mhz clock to codec as I2S MCLK */
25 #define GLK_PLAT_CLK_FREQ 19200000
26 #define RT5682_PLL_FREQ (48000 * 512)
27 #define GLK_REALTEK_CODEC_DAI "rt5682-aif1"
28 #define GLK_MAXIM_CODEC_DAI "HiFi"
29 #define MAXIM_DEV0_NAME "MX98357A:00"
30 #define DUAL_CHANNEL 2
31 #define QUAD_CHANNEL 4
32 #define NAME_SIZE 32
33 
34 static struct snd_soc_jack geminilake_hdmi[3];
35 
36 struct glk_hdmi_pcm {
37 	struct list_head head;
38 	struct snd_soc_dai *codec_dai;
39 	int device;
40 };
41 
42 struct glk_card_private {
43 	struct snd_soc_jack geminilake_headset;
44 	struct list_head hdmi_pcm_list;
45 };
46 
47 enum {
48 	GLK_DPCM_AUDIO_PB = 0,
49 	GLK_DPCM_AUDIO_CP,
50 	GLK_DPCM_AUDIO_HS_PB,
51 	GLK_DPCM_AUDIO_ECHO_REF_CP,
52 	GLK_DPCM_AUDIO_REF_CP,
53 	GLK_DPCM_AUDIO_DMIC_CP,
54 	GLK_DPCM_AUDIO_HDMI1_PB,
55 	GLK_DPCM_AUDIO_HDMI2_PB,
56 	GLK_DPCM_AUDIO_HDMI3_PB,
57 };
58 
59 static const struct snd_kcontrol_new geminilake_controls[] = {
60 	SOC_DAPM_PIN_SWITCH("Headphone Jack"),
61 	SOC_DAPM_PIN_SWITCH("Headset Mic"),
62 	SOC_DAPM_PIN_SWITCH("Spk"),
63 };
64 
65 static const struct snd_soc_dapm_widget geminilake_widgets[] = {
66 	SND_SOC_DAPM_HP("Headphone Jack", NULL),
67 	SND_SOC_DAPM_MIC("Headset Mic", NULL),
68 	SND_SOC_DAPM_SPK("Spk", NULL),
69 	SND_SOC_DAPM_MIC("SoC DMIC", NULL),
70 	SND_SOC_DAPM_SPK("HDMI1", NULL),
71 	SND_SOC_DAPM_SPK("HDMI2", NULL),
72 	SND_SOC_DAPM_SPK("HDMI3", NULL),
73 };
74 
75 static const struct snd_soc_dapm_route geminilake_map[] = {
76 	/* HP jack connectors - unknown if we have jack detection */
77 	{ "Headphone Jack", NULL, "HPOL" },
78 	{ "Headphone Jack", NULL, "HPOR" },
79 
80 	/* speaker */
81 	{ "Spk", NULL, "Speaker" },
82 
83 	/* other jacks */
84 	{ "IN1P", NULL, "Headset Mic" },
85 
86 	/* digital mics */
87 	{ "DMic", NULL, "SoC DMIC" },
88 
89 	/* CODEC BE connections */
90 	{ "HiFi Playback", NULL, "ssp1 Tx" },
91 	{ "ssp1 Tx", NULL, "codec0_out" },
92 
93 	{ "AIF1 Playback", NULL, "ssp2 Tx" },
94 	{ "ssp2 Tx", NULL, "codec1_out" },
95 
96 	{ "codec0_in", NULL, "ssp2 Rx" },
97 	{ "ssp2 Rx", NULL, "AIF1 Capture" },
98 
99 	{ "HDMI1", NULL, "hif5-0 Output" },
100 	{ "HDMI2", NULL, "hif6-0 Output" },
101 	{ "HDMI2", NULL, "hif7-0 Output" },
102 
103 	{ "hifi3", NULL, "iDisp3 Tx" },
104 	{ "iDisp3 Tx", NULL, "iDisp3_out" },
105 	{ "hifi2", NULL, "iDisp2 Tx" },
106 	{ "iDisp2 Tx", NULL, "iDisp2_out" },
107 	{ "hifi1", NULL, "iDisp1 Tx" },
108 	{ "iDisp1 Tx", NULL, "iDisp1_out" },
109 
110 	/* DMIC */
111 	{ "dmic01_hifi", NULL, "DMIC01 Rx" },
112 	{ "DMIC01 Rx", NULL, "DMIC AIF" },
113 };
114 
115 static int geminilake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
116 			struct snd_pcm_hw_params *params)
117 {
118 	struct snd_interval *rate = hw_param_interval(params,
119 			SNDRV_PCM_HW_PARAM_RATE);
120 	struct snd_interval *channels = hw_param_interval(params,
121 			SNDRV_PCM_HW_PARAM_CHANNELS);
122 	struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
123 
124 	/* The ADSP will convert the FE rate to 48k, stereo */
125 	rate->min = rate->max = 48000;
126 	channels->min = channels->max = DUAL_CHANNEL;
127 
128 	/* set SSP to 24 bit */
129 	snd_mask_none(fmt);
130 	snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
131 
132 	return 0;
133 }
134 
135 static int geminilake_rt5682_codec_init(struct snd_soc_pcm_runtime *rtd)
136 {
137 	struct glk_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
138 	struct snd_soc_component *component = rtd->codec_dai->component;
139 	struct snd_soc_dai *codec_dai = rtd->codec_dai;
140 	struct snd_soc_jack *jack;
141 	int ret;
142 
143 	ret = snd_soc_dai_set_pll(codec_dai, 0, RT5682_PLL1_S_MCLK,
144 					GLK_PLAT_CLK_FREQ, RT5682_PLL_FREQ);
145 	if (ret < 0) {
146 		dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
147 		return ret;
148 	}
149 
150 	/* Configure sysclk for codec */
151 	ret = snd_soc_dai_set_sysclk(codec_dai, RT5682_SCLK_S_PLL1,
152 					RT5682_PLL_FREQ, SND_SOC_CLOCK_IN);
153 	if (ret < 0)
154 		dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
155 
156 	/*
157 	 * Headset buttons map to the google Reference headset.
158 	 * These can be configured by userspace.
159 	 */
160 	ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
161 			SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
162 			SND_JACK_BTN_2 | SND_JACK_BTN_3 | SND_JACK_LINEOUT,
163 			&ctx->geminilake_headset, NULL, 0);
164 	if (ret) {
165 		dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
166 		return ret;
167 	}
168 
169 	jack = &ctx->geminilake_headset;
170 
171 	snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_PLAYPAUSE);
172 	snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
173 	snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
174 	snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
175 	ret = snd_soc_component_set_jack(component, jack, NULL);
176 
177 	if (ret) {
178 		dev_err(rtd->dev, "Headset Jack call-back failed: %d\n", ret);
179 		return ret;
180 	}
181 
182 	return ret;
183 };
184 
185 static int geminilake_rt5682_hw_params(struct snd_pcm_substream *substream,
186 	struct snd_pcm_hw_params *params)
187 {
188 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
189 	struct snd_soc_dai *codec_dai = rtd->codec_dai;
190 	int ret;
191 
192 	/* Set valid bitmask & configuration for I2S in 24 bit */
193 	ret = snd_soc_dai_set_tdm_slot(codec_dai, 0x0, 0x0, 2, 24);
194 	if (ret < 0) {
195 		dev_err(rtd->dev, "set TDM slot err:%d\n", ret);
196 		return ret;
197 	}
198 
199 	return ret;
200 }
201 
202 static struct snd_soc_ops geminilake_rt5682_ops = {
203 	.hw_params = geminilake_rt5682_hw_params,
204 };
205 
206 static int geminilake_hdmi_init(struct snd_soc_pcm_runtime *rtd)
207 {
208 	struct glk_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
209 	struct snd_soc_dai *dai = rtd->codec_dai;
210 	struct glk_hdmi_pcm *pcm;
211 
212 	pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
213 	if (!pcm)
214 		return -ENOMEM;
215 
216 	pcm->device = GLK_DPCM_AUDIO_HDMI1_PB + dai->id;
217 	pcm->codec_dai = dai;
218 
219 	list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
220 
221 	return 0;
222 }
223 
224 static int geminilake_rt5682_fe_init(struct snd_soc_pcm_runtime *rtd)
225 {
226 	struct snd_soc_component *component = rtd->cpu_dai->component;
227 	struct snd_soc_dapm_context *dapm;
228 	int ret;
229 
230 	dapm = snd_soc_component_get_dapm(component);
231 	ret = snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
232 	if (ret) {
233 		dev_err(rtd->dev, "Ref Cap ignore suspend failed %d\n", ret);
234 		return ret;
235 	}
236 
237 	return ret;
238 }
239 
240 static const unsigned int rates[] = {
241 	48000,
242 };
243 
244 static const struct snd_pcm_hw_constraint_list constraints_rates = {
245 	.count = ARRAY_SIZE(rates),
246 	.list  = rates,
247 	.mask = 0,
248 };
249 
250 static const unsigned int channels[] = {
251 	DUAL_CHANNEL,
252 };
253 
254 static const struct snd_pcm_hw_constraint_list constraints_channels = {
255 	.count = ARRAY_SIZE(channels),
256 	.list = channels,
257 	.mask = 0,
258 };
259 
260 static unsigned int channels_quad[] = {
261 	QUAD_CHANNEL,
262 };
263 
264 static struct snd_pcm_hw_constraint_list constraints_channels_quad = {
265 	.count = ARRAY_SIZE(channels_quad),
266 	.list = channels_quad,
267 	.mask = 0,
268 };
269 
270 static int geminilake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
271 		struct snd_pcm_hw_params *params)
272 {
273 	struct snd_interval *channels = hw_param_interval(params,
274 				SNDRV_PCM_HW_PARAM_CHANNELS);
275 
276 	/*
277 	 * set BE channel constraint as user FE channels
278 	 */
279 	channels->min = channels->max = 4;
280 
281 	return 0;
282 }
283 
284 static int geminilake_dmic_startup(struct snd_pcm_substream *substream)
285 {
286 	struct snd_pcm_runtime *runtime = substream->runtime;
287 
288 	runtime->hw.channels_min = runtime->hw.channels_max = QUAD_CHANNEL;
289 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
290 			&constraints_channels_quad);
291 
292 	return snd_pcm_hw_constraint_list(substream->runtime, 0,
293 			SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
294 }
295 
296 static const struct snd_soc_ops geminilake_dmic_ops = {
297 	.startup = geminilake_dmic_startup,
298 };
299 
300 static const unsigned int rates_16000[] = {
301 	16000,
302 };
303 
304 static const struct snd_pcm_hw_constraint_list constraints_16000 = {
305 	.count = ARRAY_SIZE(rates_16000),
306 	.list  = rates_16000,
307 };
308 
309 static int geminilake_refcap_startup(struct snd_pcm_substream *substream)
310 {
311 	return snd_pcm_hw_constraint_list(substream->runtime, 0,
312 				SNDRV_PCM_HW_PARAM_RATE,
313 				&constraints_16000);
314 };
315 
316 static const struct snd_soc_ops geminilake_refcap_ops = {
317 	.startup = geminilake_refcap_startup,
318 };
319 
320 /* geminilake digital audio interface glue - connects codec <--> CPU */
321 static struct snd_soc_dai_link geminilake_dais[] = {
322 	/* Front End DAI links */
323 	[GLK_DPCM_AUDIO_PB] = {
324 		.name = "Glk Audio Port",
325 		.stream_name = "Audio",
326 		.cpu_dai_name = "System Pin",
327 		.platform_name = "0000:00:0e.0",
328 		.dynamic = 1,
329 		.codec_name = "snd-soc-dummy",
330 		.codec_dai_name = "snd-soc-dummy-dai",
331 		.nonatomic = 1,
332 		.init = geminilake_rt5682_fe_init,
333 		.trigger = {
334 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
335 		.dpcm_playback = 1,
336 	},
337 	[GLK_DPCM_AUDIO_CP] = {
338 		.name = "Glk Audio Capture Port",
339 		.stream_name = "Audio Record",
340 		.cpu_dai_name = "System Pin",
341 		.platform_name = "0000:00:0e.0",
342 		.dynamic = 1,
343 		.codec_name = "snd-soc-dummy",
344 		.codec_dai_name = "snd-soc-dummy-dai",
345 		.nonatomic = 1,
346 		.trigger = {
347 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
348 		.dpcm_capture = 1,
349 	},
350 	[GLK_DPCM_AUDIO_HS_PB] = {
351 		.name = "Glk Audio Headset Playback",
352 		.stream_name = "Headset Audio",
353 		.cpu_dai_name = "System Pin2",
354 		.platform_name = "0000:00:0e.0",
355 		.codec_name = "snd-soc-dummy",
356 		.codec_dai_name = "snd-soc-dummy-dai",
357 		.dpcm_playback = 1,
358 		.nonatomic = 1,
359 		.dynamic = 1,
360 	},
361 	[GLK_DPCM_AUDIO_ECHO_REF_CP] = {
362 		.name = "Glk Audio Echo Reference cap",
363 		.stream_name = "Echoreference Capture",
364 		.cpu_dai_name = "Echoref Pin",
365 		.platform_name = "0000:00:0e.0",
366 		.codec_name = "snd-soc-dummy",
367 		.codec_dai_name = "snd-soc-dummy-dai",
368 		.init = NULL,
369 		.capture_only = 1,
370 		.nonatomic = 1,
371 	},
372 	[GLK_DPCM_AUDIO_REF_CP] = {
373 		.name = "Glk Audio Reference cap",
374 		.stream_name = "Refcap",
375 		.cpu_dai_name = "Reference Pin",
376 		.codec_name = "snd-soc-dummy",
377 		.codec_dai_name = "snd-soc-dummy-dai",
378 		.platform_name = "0000:00:0e.0",
379 		.init = NULL,
380 		.dpcm_capture = 1,
381 		.nonatomic = 1,
382 		.dynamic = 1,
383 		.ops = &geminilake_refcap_ops,
384 	},
385 	[GLK_DPCM_AUDIO_DMIC_CP] = {
386 		.name = "Glk Audio DMIC cap",
387 		.stream_name = "dmiccap",
388 		.cpu_dai_name = "DMIC Pin",
389 		.codec_name = "snd-soc-dummy",
390 		.codec_dai_name = "snd-soc-dummy-dai",
391 		.platform_name = "0000:00:0e.0",
392 		.init = NULL,
393 		.dpcm_capture = 1,
394 		.nonatomic = 1,
395 		.dynamic = 1,
396 		.ops = &geminilake_dmic_ops,
397 	},
398 	[GLK_DPCM_AUDIO_HDMI1_PB] = {
399 		.name = "Glk HDMI Port1",
400 		.stream_name = "Hdmi1",
401 		.cpu_dai_name = "HDMI1 Pin",
402 		.codec_name = "snd-soc-dummy",
403 		.codec_dai_name = "snd-soc-dummy-dai",
404 		.platform_name = "0000:00:0e.0",
405 		.dpcm_playback = 1,
406 		.init = NULL,
407 		.trigger = {
408 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
409 		.nonatomic = 1,
410 		.dynamic = 1,
411 	},
412 	[GLK_DPCM_AUDIO_HDMI2_PB] =	{
413 		.name = "Glk HDMI Port2",
414 		.stream_name = "Hdmi2",
415 		.cpu_dai_name = "HDMI2 Pin",
416 		.codec_name = "snd-soc-dummy",
417 		.codec_dai_name = "snd-soc-dummy-dai",
418 		.platform_name = "0000:00:0e.0",
419 		.dpcm_playback = 1,
420 		.init = NULL,
421 		.trigger = {
422 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
423 		.nonatomic = 1,
424 		.dynamic = 1,
425 	},
426 	[GLK_DPCM_AUDIO_HDMI3_PB] =	{
427 		.name = "Glk HDMI Port3",
428 		.stream_name = "Hdmi3",
429 		.cpu_dai_name = "HDMI3 Pin",
430 		.codec_name = "snd-soc-dummy",
431 		.codec_dai_name = "snd-soc-dummy-dai",
432 		.platform_name = "0000:00:0e.0",
433 		.trigger = {
434 			SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
435 		.dpcm_playback = 1,
436 		.init = NULL,
437 		.nonatomic = 1,
438 		.dynamic = 1,
439 	},
440 	/* Back End DAI links */
441 	{
442 		/* SSP1 - Codec */
443 		.name = "SSP1-Codec",
444 		.id = 0,
445 		.cpu_dai_name = "SSP1 Pin",
446 		.platform_name = "0000:00:0e.0",
447 		.no_pcm = 1,
448 		.codec_name = MAXIM_DEV0_NAME,
449 		.codec_dai_name = GLK_MAXIM_CODEC_DAI,
450 		.dai_fmt = SND_SOC_DAIFMT_I2S |
451 			SND_SOC_DAIFMT_NB_NF |
452 			SND_SOC_DAIFMT_CBS_CFS,
453 		.ignore_pmdown_time = 1,
454 		.be_hw_params_fixup = geminilake_ssp_fixup,
455 		.dpcm_playback = 1,
456 	},
457 	{
458 		/* SSP2 - Codec */
459 		.name = "SSP2-Codec",
460 		.id = 1,
461 		.cpu_dai_name = "SSP2 Pin",
462 		.platform_name = "0000:00:0e.0",
463 		.no_pcm = 1,
464 		.codec_name = "i2c-10EC5682:00",
465 		.codec_dai_name = GLK_REALTEK_CODEC_DAI,
466 		.init = geminilake_rt5682_codec_init,
467 		.dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
468 			SND_SOC_DAIFMT_CBS_CFS,
469 		.ignore_pmdown_time = 1,
470 		.be_hw_params_fixup = geminilake_ssp_fixup,
471 		.ops = &geminilake_rt5682_ops,
472 		.dpcm_playback = 1,
473 		.dpcm_capture = 1,
474 	},
475 	{
476 		.name = "dmic01",
477 		.id = 2,
478 		.cpu_dai_name = "DMIC01 Pin",
479 		.codec_name = "dmic-codec",
480 		.codec_dai_name = "dmic-hifi",
481 		.platform_name = "0000:00:0e.0",
482 		.ignore_suspend = 1,
483 		.be_hw_params_fixup = geminilake_dmic_fixup,
484 		.dpcm_capture = 1,
485 		.no_pcm = 1,
486 	},
487 	{
488 		.name = "iDisp1",
489 		.id = 3,
490 		.cpu_dai_name = "iDisp1 Pin",
491 		.codec_name = "ehdaudio0D2",
492 		.codec_dai_name = "intel-hdmi-hifi1",
493 		.platform_name = "0000:00:0e.0",
494 		.init = geminilake_hdmi_init,
495 		.dpcm_playback = 1,
496 		.no_pcm = 1,
497 	},
498 	{
499 		.name = "iDisp2",
500 		.id = 4,
501 		.cpu_dai_name = "iDisp2 Pin",
502 		.codec_name = "ehdaudio0D2",
503 		.codec_dai_name = "intel-hdmi-hifi2",
504 		.platform_name = "0000:00:0e.0",
505 		.init = geminilake_hdmi_init,
506 		.dpcm_playback = 1,
507 		.no_pcm = 1,
508 	},
509 	{
510 		.name = "iDisp3",
511 		.id = 5,
512 		.cpu_dai_name = "iDisp3 Pin",
513 		.codec_name = "ehdaudio0D2",
514 		.codec_dai_name = "intel-hdmi-hifi3",
515 		.platform_name = "0000:00:0e.0",
516 		.init = geminilake_hdmi_init,
517 		.dpcm_playback = 1,
518 		.no_pcm = 1,
519 	},
520 };
521 
522 static int glk_card_late_probe(struct snd_soc_card *card)
523 {
524 	struct glk_card_private *ctx = snd_soc_card_get_drvdata(card);
525 	struct snd_soc_component *component = NULL;
526 	char jack_name[NAME_SIZE];
527 	struct glk_hdmi_pcm *pcm;
528 	int err = 0;
529 	int i = 0;
530 
531 	list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
532 		component = pcm->codec_dai->component;
533 		snprintf(jack_name, sizeof(jack_name),
534 			"HDMI/DP, pcm=%d Jack", pcm->device);
535 		err = snd_soc_card_jack_new(card, jack_name,
536 					SND_JACK_AVOUT, &geminilake_hdmi[i],
537 					NULL, 0);
538 
539 		if (err)
540 			return err;
541 
542 		err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
543 						&geminilake_hdmi[i]);
544 		if (err < 0)
545 			return err;
546 
547 		i++;
548 	}
549 
550 	if (!component)
551 		return -EINVAL;
552 
553 	return hdac_hdmi_jack_port_init(component, &card->dapm);
554 }
555 
556 /* geminilake audio machine driver for SPT + RT5682 */
557 static struct snd_soc_card glk_audio_card_rt5682_m98357a = {
558 	.name = "glkrt5682max",
559 	.owner = THIS_MODULE,
560 	.dai_link = geminilake_dais,
561 	.num_links = ARRAY_SIZE(geminilake_dais),
562 	.controls = geminilake_controls,
563 	.num_controls = ARRAY_SIZE(geminilake_controls),
564 	.dapm_widgets = geminilake_widgets,
565 	.num_dapm_widgets = ARRAY_SIZE(geminilake_widgets),
566 	.dapm_routes = geminilake_map,
567 	.num_dapm_routes = ARRAY_SIZE(geminilake_map),
568 	.fully_routed = true,
569 	.late_probe = glk_card_late_probe,
570 };
571 
572 static int geminilake_audio_probe(struct platform_device *pdev)
573 {
574 	struct glk_card_private *ctx;
575 	struct snd_soc_acpi_mach *mach;
576 	const char *platform_name;
577 	struct snd_soc_card *card;
578 	int ret;
579 
580 	ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
581 	if (!ctx)
582 		return -ENOMEM;
583 
584 	INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
585 
586 	card = &glk_audio_card_rt5682_m98357a;
587 	card->dev = &pdev->dev;
588 	snd_soc_card_set_drvdata(card, ctx);
589 
590 	/* override plaform name, if required */
591 	mach = (&pdev->dev)->platform_data;
592 	platform_name = mach->mach_params.platform;
593 
594 	ret = snd_soc_fixup_dai_links_platform_name(card, platform_name);
595 	if (ret)
596 		return ret;
597 
598 	return devm_snd_soc_register_card(&pdev->dev, card);
599 }
600 
601 static const struct platform_device_id glk_board_ids[] = {
602 	{
603 		.name = "glk_rt5682_max98357a",
604 		.driver_data =
605 			(kernel_ulong_t)&glk_audio_card_rt5682_m98357a,
606 	},
607 	{ }
608 };
609 
610 static struct platform_driver geminilake_audio = {
611 	.probe = geminilake_audio_probe,
612 	.driver = {
613 		.name = "glk_rt5682_max98357a",
614 		.pm = &snd_soc_pm_ops,
615 	},
616 	.id_table = glk_board_ids,
617 };
618 module_platform_driver(geminilake_audio)
619 
620 /* Module information */
621 MODULE_DESCRIPTION("Geminilake Audio Machine driver-RT5682 & MAX98357A in I2S mode");
622 MODULE_AUTHOR("Naveen Manohar <naveen.m@intel.com>");
623 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
624 MODULE_LICENSE("GPL v2");
625 MODULE_ALIAS("platform:glk_rt5682_max98357a");
626