ASoC: Intel: kbl: Add map for new DAIs for Multi-Playback & Echo Ref
[sfrench/cifs-2.6.git] / sound / soc / intel / boards / kbl_rt5663_max98927.c
1 /*
2  * Intel Kabylake I2S Machine Driver with MAXIM98927
3  * and RT5663 Codecs
4  *
5  * Copyright (C) 2017, Intel Corporation. All rights reserved.
6  *
7  * Modified from:
8  *   Intel Skylake I2S Machine driver
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License version
12  * 2 as published by the Free Software Foundation.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  */
19
20 #include <linux/module.h>
21 #include <linux/platform_device.h>
22 #include <sound/core.h>
23 #include <sound/jack.h>
24 #include <sound/pcm.h>
25 #include <sound/pcm_params.h>
26 #include <sound/soc.h>
27 #include "../../codecs/rt5663.h"
28 #include "../../codecs/hdac_hdmi.h"
29 #include "../skylake/skl.h"
30
31 #define KBL_REALTEK_CODEC_DAI "rt5663-aif"
32 #define KBL_MAXIM_CODEC_DAI "max98927-aif1"
33 #define DMIC_CH(p) p->list[p->count-1]
34 #define MAXIM_DEV0_NAME "i2c-MX98927:00"
35 #define MAXIM_DEV1_NAME "i2c-MX98927:01"
36
37 static struct snd_soc_card *kabylake_audio_card;
38 static const struct snd_pcm_hw_constraint_list *dmic_constraints;
39 static struct snd_soc_jack skylake_hdmi[3];
40
41 struct kbl_hdmi_pcm {
42         struct list_head head;
43         struct snd_soc_dai *codec_dai;
44         int device;
45 };
46
47 struct kbl_rt5663_private {
48         struct snd_soc_jack kabylake_headset;
49         struct list_head hdmi_pcm_list;
50 };
51
52 enum {
53         KBL_DPCM_AUDIO_PB = 0,
54         KBL_DPCM_AUDIO_CP,
55         KBL_DPCM_AUDIO_HS_PB,
56         KBL_DPCM_AUDIO_ECHO_REF_CP,
57         KBL_DPCM_AUDIO_REF_CP,
58         KBL_DPCM_AUDIO_DMIC_CP,
59         KBL_DPCM_AUDIO_HDMI1_PB,
60         KBL_DPCM_AUDIO_HDMI2_PB,
61         KBL_DPCM_AUDIO_HDMI3_PB,
62 };
63
64 static const struct snd_kcontrol_new kabylake_controls[] = {
65         SOC_DAPM_PIN_SWITCH("Headphone Jack"),
66         SOC_DAPM_PIN_SWITCH("Headset Mic"),
67         SOC_DAPM_PIN_SWITCH("Left Spk"),
68         SOC_DAPM_PIN_SWITCH("Right Spk"),
69 };
70
71 static const struct snd_soc_dapm_widget kabylake_widgets[] = {
72         SND_SOC_DAPM_HP("Headphone Jack", NULL),
73         SND_SOC_DAPM_MIC("Headset Mic", NULL),
74         SND_SOC_DAPM_SPK("Left Spk", NULL),
75         SND_SOC_DAPM_SPK("Right Spk", NULL),
76         SND_SOC_DAPM_MIC("SoC DMIC", NULL),
77         SND_SOC_DAPM_SPK("DP", NULL),
78         SND_SOC_DAPM_SPK("HDMI", NULL),
79
80 };
81
82 static const struct snd_soc_dapm_route kabylake_map[] = {
83         /* HP jack connectors - unknown if we have jack detection */
84         { "Headphone Jack", NULL, "HPOL" },
85         { "Headphone Jack", NULL, "HPOR" },
86
87         /* speaker */
88         { "Left Spk", NULL, "Left BE_OUT" },
89         { "Right Spk", NULL, "Right BE_OUT" },
90
91         /* other jacks */
92         { "IN1P", NULL, "Headset Mic" },
93         { "IN1N", NULL, "Headset Mic" },
94         { "DMic", NULL, "SoC DMIC" },
95
96         { "HDMI", NULL, "hif5 Output" },
97         { "DP", NULL, "hif6 Output" },
98
99         /* CODEC BE connections */
100         { "Left HiFi Playback", NULL, "ssp0 Tx" },
101         { "Right HiFi Playback", NULL, "ssp0 Tx" },
102         { "ssp0 Tx", NULL, "spk_out" },
103
104         { "AIF Playback", NULL, "ssp1 Tx" },
105         { "ssp1 Tx", NULL, "hs_out" },
106
107         { "hs_in", NULL, "ssp1 Rx" },
108         { "ssp1 Rx", NULL, "AIF Capture" },
109
110         /* DMIC */
111         { "dmic01_hifi", NULL, "DMIC01 Rx" },
112         { "DMIC01 Rx", NULL, "DMIC AIF" },
113
114         { "hifi3", NULL, "iDisp3 Tx"},
115         { "iDisp3 Tx", NULL, "iDisp3_out"},
116         { "hifi2", NULL, "iDisp2 Tx"},
117         { "iDisp2 Tx", NULL, "iDisp2_out"},
118         { "hifi1", NULL, "iDisp1 Tx"},
119         { "iDisp1 Tx", NULL, "iDisp1_out"},
120 };
121
122 enum {
123         KBL_DPCM_AUDIO_5663_PB = 0,
124         KBL_DPCM_AUDIO_5663_CP,
125         KBL_DPCM_AUDIO_5663_HDMI1_PB,
126         KBL_DPCM_AUDIO_5663_HDMI2_PB,
127 };
128
129 static const struct snd_kcontrol_new kabylake_5663_controls[] = {
130         SOC_DAPM_PIN_SWITCH("Headphone Jack"),
131         SOC_DAPM_PIN_SWITCH("Headset Mic"),
132 };
133
134 static const struct snd_soc_dapm_widget kabylake_5663_widgets[] = {
135         SND_SOC_DAPM_HP("Headphone Jack", NULL),
136         SND_SOC_DAPM_MIC("Headset Mic", NULL),
137         SND_SOC_DAPM_SPK("DP", NULL),
138         SND_SOC_DAPM_SPK("HDMI", NULL),
139 };
140
141 static const struct snd_soc_dapm_route kabylake_5663_map[] = {
142         { "Headphone Jack", NULL, "HPOL" },
143         { "Headphone Jack", NULL, "HPOR" },
144
145         /* other jacks */
146         { "IN1P", NULL, "Headset Mic" },
147         { "IN1N", NULL, "Headset Mic" },
148
149         { "HDMI", NULL, "hif5 Output" },
150         { "DP", NULL, "hif6 Output" },
151
152         /* CODEC BE connections */
153         { "AIF Playback", NULL, "ssp1 Tx" },
154         { "ssp1 Tx", NULL, "codec1_out" },
155
156         { "codec0_in", NULL, "ssp1 Rx" },
157         { "ssp1 Rx", NULL, "AIF Capture" },
158
159         { "hifi2", NULL, "iDisp2 Tx"},
160         { "iDisp2 Tx", NULL, "iDisp2_out"},
161         { "hifi1", NULL, "iDisp1 Tx"},
162         { "iDisp1 Tx", NULL, "iDisp1_out"},
163 };
164
165 static struct snd_soc_codec_conf max98927_codec_conf[] = {
166         {
167                 .dev_name = MAXIM_DEV0_NAME,
168                 .name_prefix = "Right",
169         },
170         {
171                 .dev_name = MAXIM_DEV1_NAME,
172                 .name_prefix = "Left",
173         },
174 };
175
176 static struct snd_soc_dai_link_component max98927_codec_components[] = {
177         { /* Left */
178                 .name = MAXIM_DEV0_NAME,
179                 .dai_name = KBL_MAXIM_CODEC_DAI,
180         },
181         { /* Right */
182                 .name = MAXIM_DEV1_NAME,
183                 .dai_name = KBL_MAXIM_CODEC_DAI,
184         },
185 };
186
187 static int kabylake_rt5663_fe_init(struct snd_soc_pcm_runtime *rtd)
188 {
189         int ret;
190         struct snd_soc_dapm_context *dapm;
191         struct snd_soc_component *component = rtd->cpu_dai->component;
192
193         dapm = snd_soc_component_get_dapm(component);
194         ret = snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
195         if (ret) {
196                 dev_err(rtd->dev, "Ref Cap ignore suspend failed %d\n", ret);
197                 return ret;
198         }
199
200         return ret;
201 }
202
203 static int kabylake_rt5663_codec_init(struct snd_soc_pcm_runtime *rtd)
204 {
205         int ret;
206         struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card);
207         struct snd_soc_codec *codec = rtd->codec;
208
209         /*
210          * Headset buttons map to the google Reference headset.
211          * These can be configured by userspace.
212          */
213         ret = snd_soc_card_jack_new(kabylake_audio_card, "Headset Jack",
214                         SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
215                         SND_JACK_BTN_2 | SND_JACK_BTN_3, &ctx->kabylake_headset,
216                         NULL, 0);
217         if (ret) {
218                 dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
219                 return ret;
220         }
221         rt5663_set_jack_detect(codec, &ctx->kabylake_headset);
222         return ret;
223 }
224
225 static int kabylake_rt5663_max98927_codec_init(struct snd_soc_pcm_runtime *rtd)
226 {
227         int ret;
228
229         ret = kabylake_rt5663_codec_init(rtd);
230         if (ret)
231                 return ret;
232
233         ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
234         if (ret) {
235                 dev_err(rtd->dev, "SoC DMIC ignore suspend failed %d\n", ret);
236                 return ret;
237         }
238
239         return ret;
240 }
241
242 static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device)
243 {
244         struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(rtd->card);
245         struct snd_soc_dai *dai = rtd->codec_dai;
246         struct kbl_hdmi_pcm *pcm;
247
248         pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
249         if (!pcm)
250                 return -ENOMEM;
251
252         pcm->device = device;
253         pcm->codec_dai = dai;
254
255         list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
256
257         return 0;
258 }
259
260 static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
261 {
262         return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB);
263 }
264
265 static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
266 {
267         return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB);
268 }
269
270 static int kabylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd)
271 {
272         return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI3_PB);
273 }
274
275 static int kabylake_5663_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
276 {
277         return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_5663_HDMI1_PB);
278 }
279
280 static int kabylake_5663_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
281 {
282         return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_5663_HDMI2_PB);
283 }
284
285 static unsigned int rates[] = {
286         48000,
287 };
288
289 static struct snd_pcm_hw_constraint_list constraints_rates = {
290         .count = ARRAY_SIZE(rates),
291         .list  = rates,
292         .mask = 0,
293 };
294
295 static unsigned int channels[] = {
296         2,
297 };
298
299 static struct snd_pcm_hw_constraint_list constraints_channels = {
300         .count = ARRAY_SIZE(channels),
301         .list = channels,
302         .mask = 0,
303 };
304
305 static int kbl_fe_startup(struct snd_pcm_substream *substream)
306 {
307         struct snd_pcm_runtime *runtime = substream->runtime;
308
309         /*
310          * On this platform for PCM device we support,
311          * 48Khz
312          * stereo
313          * 16 bit audio
314          */
315
316         runtime->hw.channels_max = 2;
317         snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
318                                            &constraints_channels);
319
320         runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
321         snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
322
323         snd_pcm_hw_constraint_list(runtime, 0,
324                                 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
325
326         return 0;
327 }
328
329 static const struct snd_soc_ops kabylake_rt5663_fe_ops = {
330         .startup = kbl_fe_startup,
331 };
332
333 static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
334         struct snd_pcm_hw_params *params)
335 {
336         struct snd_interval *rate = hw_param_interval(params,
337                         SNDRV_PCM_HW_PARAM_RATE);
338         struct snd_interval *channels = hw_param_interval(params,
339                         SNDRV_PCM_HW_PARAM_CHANNELS);
340         struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
341
342         /* The ADSP will convert the FE rate to 48k, stereo */
343         rate->min = rate->max = 48000;
344         channels->min = channels->max = 2;
345         /* set SSP1 to 24 bit */
346         snd_mask_none(fmt);
347         snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE);
348
349         return 0;
350 }
351
352 static int kabylake_rt5663_hw_params(struct snd_pcm_substream *substream,
353         struct snd_pcm_hw_params *params)
354 {
355         struct snd_soc_pcm_runtime *rtd = substream->private_data;
356         struct snd_soc_dai *codec_dai = rtd->codec_dai;
357         int ret;
358
359         ret = snd_soc_dai_set_sysclk(codec_dai,
360                         RT5663_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN);
361         /* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */
362         rt5663_sel_asrc_clk_src(codec_dai->codec, RT5663_DA_STEREO_FILTER, 1);
363
364         if (ret < 0)
365                 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
366
367         return ret;
368 }
369
370 static struct snd_soc_ops kabylake_rt5663_ops = {
371         .hw_params = kabylake_rt5663_hw_params,
372 };
373
374 static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
375                 struct snd_pcm_hw_params *params)
376 {
377         struct snd_interval *channels = hw_param_interval(params,
378                                 SNDRV_PCM_HW_PARAM_CHANNELS);
379
380         if (params_channels(params) == 2 || DMIC_CH(dmic_constraints) == 2)
381                 channels->min = channels->max = 2;
382         else
383                 channels->min = channels->max = 4;
384
385         return 0;
386 }
387
388 static unsigned int channels_dmic[] = {
389         2, 4,
390 };
391
392 static struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
393         .count = ARRAY_SIZE(channels_dmic),
394         .list = channels_dmic,
395         .mask = 0,
396 };
397
398 static const unsigned int dmic_2ch[] = {
399         2,
400 };
401
402 static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch = {
403         .count = ARRAY_SIZE(dmic_2ch),
404         .list = dmic_2ch,
405         .mask = 0,
406 };
407
408 static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
409 {
410         struct snd_pcm_runtime *runtime = substream->runtime;
411
412         runtime->hw.channels_max = DMIC_CH(dmic_constraints);
413         snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
414                         dmic_constraints);
415
416         return snd_pcm_hw_constraint_list(substream->runtime, 0,
417                         SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
418 }
419
420 static struct snd_soc_ops kabylake_dmic_ops = {
421         .startup = kabylake_dmic_startup,
422 };
423
424 static unsigned int rates_16000[] = {
425         16000,
426 };
427
428 static struct snd_pcm_hw_constraint_list constraints_16000 = {
429         .count = ARRAY_SIZE(rates_16000),
430         .list  = rates_16000,
431 };
432
433 static const unsigned int ch_mono[] = {
434         1,
435 };
436
437 static const struct snd_pcm_hw_constraint_list constraints_refcap = {
438         .count = ARRAY_SIZE(ch_mono),
439         .list  = ch_mono,
440 };
441
442 static int kabylake_refcap_startup(struct snd_pcm_substream *substream)
443 {
444         substream->runtime->hw.channels_max = 1;
445         snd_pcm_hw_constraint_list(substream->runtime, 0,
446                                         SNDRV_PCM_HW_PARAM_CHANNELS,
447                                         &constraints_refcap);
448
449         return snd_pcm_hw_constraint_list(substream->runtime, 0,
450                                 SNDRV_PCM_HW_PARAM_RATE,
451                                 &constraints_16000);
452 }
453
454 static struct snd_soc_ops skylaye_refcap_ops = {
455         .startup = kabylake_refcap_startup,
456 };
457
458 /* kabylake digital audio interface glue - connects codec <--> CPU */
459 static struct snd_soc_dai_link kabylake_dais[] = {
460         /* Front End DAI links */
461         [KBL_DPCM_AUDIO_PB] = {
462                 .name = "Kbl Audio Port",
463                 .stream_name = "Audio",
464                 .cpu_dai_name = "System Pin",
465                 .platform_name = "0000:00:1f.3",
466                 .dynamic = 1,
467                 .codec_name = "snd-soc-dummy",
468                 .codec_dai_name = "snd-soc-dummy-dai",
469                 .nonatomic = 1,
470                 .init = kabylake_rt5663_fe_init,
471                 .trigger = {
472                         SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
473                 .dpcm_playback = 1,
474                 .ops = &kabylake_rt5663_fe_ops,
475         },
476         [KBL_DPCM_AUDIO_CP] = {
477                 .name = "Kbl Audio Capture Port",
478                 .stream_name = "Audio Record",
479                 .cpu_dai_name = "System Pin",
480                 .platform_name = "0000:00:1f.3",
481                 .dynamic = 1,
482                 .codec_name = "snd-soc-dummy",
483                 .codec_dai_name = "snd-soc-dummy-dai",
484                 .nonatomic = 1,
485                 .trigger = {
486                         SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
487                 .dpcm_capture = 1,
488                 .ops = &kabylake_rt5663_fe_ops,
489         },
490         [KBL_DPCM_AUDIO_HS_PB] = {
491                 .name = "Kbl Audio Headset Playback",
492                 .stream_name = "Headset Audio",
493                 .cpu_dai_name = "System Pin2",
494                 .codec_name = "snd-soc-dummy",
495                 .codec_dai_name = "snd-soc-dummy-dai",
496                 .platform_name = "0000:00:1f.3",
497                 .dpcm_playback = 1,
498                 .nonatomic = 1,
499                 .dynamic = 1,
500         },
501         [KBL_DPCM_AUDIO_ECHO_REF_CP] = {
502                 .name = "Kbl Audio Echo Reference cap",
503                 .stream_name = "Echoreference Capture",
504                 .cpu_dai_name = "Echoref Pin",
505                 .codec_name = "snd-soc-dummy",
506                 .codec_dai_name = "snd-soc-dummy-dai",
507                 .platform_name = "0000:00:1f.3",
508                 .init = NULL,
509                 .capture_only = 1,
510                 .nonatomic = 1,
511         },
512         [KBL_DPCM_AUDIO_REF_CP] = {
513                 .name = "Kbl Audio Reference cap",
514                 .stream_name = "Wake on Voice",
515                 .cpu_dai_name = "Reference Pin",
516                 .codec_name = "snd-soc-dummy",
517                 .codec_dai_name = "snd-soc-dummy-dai",
518                 .platform_name = "0000:00:1f.3",
519                 .init = NULL,
520                 .dpcm_capture = 1,
521                 .nonatomic = 1,
522                 .dynamic = 1,
523                 .ops = &skylaye_refcap_ops,
524         },
525         [KBL_DPCM_AUDIO_DMIC_CP] = {
526                 .name = "Kbl Audio DMIC cap",
527                 .stream_name = "dmiccap",
528                 .cpu_dai_name = "DMIC Pin",
529                 .codec_name = "snd-soc-dummy",
530                 .codec_dai_name = "snd-soc-dummy-dai",
531                 .platform_name = "0000:00:1f.3",
532                 .init = NULL,
533                 .dpcm_capture = 1,
534                 .nonatomic = 1,
535                 .dynamic = 1,
536                 .ops = &kabylake_dmic_ops,
537         },
538         [KBL_DPCM_AUDIO_HDMI1_PB] = {
539                 .name = "Kbl HDMI Port1",
540                 .stream_name = "Hdmi1",
541                 .cpu_dai_name = "HDMI1 Pin",
542                 .codec_name = "snd-soc-dummy",
543                 .codec_dai_name = "snd-soc-dummy-dai",
544                 .platform_name = "0000:00:1f.3",
545                 .dpcm_playback = 1,
546                 .init = NULL,
547                 .trigger = {
548                         SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
549                 .nonatomic = 1,
550                 .dynamic = 1,
551         },
552         [KBL_DPCM_AUDIO_HDMI2_PB] = {
553                 .name = "Kbl HDMI Port2",
554                 .stream_name = "Hdmi2",
555                 .cpu_dai_name = "HDMI2 Pin",
556                 .codec_name = "snd-soc-dummy",
557                 .codec_dai_name = "snd-soc-dummy-dai",
558                 .platform_name = "0000:00:1f.3",
559                 .dpcm_playback = 1,
560                 .init = NULL,
561                 .trigger = {
562                         SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
563                 .nonatomic = 1,
564                 .dynamic = 1,
565         },
566         [KBL_DPCM_AUDIO_HDMI3_PB] = {
567                 .name = "Kbl HDMI Port3",
568                 .stream_name = "Hdmi3",
569                 .cpu_dai_name = "HDMI3 Pin",
570                 .codec_name = "snd-soc-dummy",
571                 .codec_dai_name = "snd-soc-dummy-dai",
572                 .platform_name = "0000:00:1f.3",
573                 .trigger = {
574                         SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
575                 .dpcm_playback = 1,
576                 .init = NULL,
577                 .nonatomic = 1,
578                 .dynamic = 1,
579         },
580
581         /* Back End DAI links */
582         {
583                 /* SSP0 - Codec */
584                 .name = "SSP0-Codec",
585                 .id = 0,
586                 .cpu_dai_name = "SSP0 Pin",
587                 .platform_name = "0000:00:1f.3",
588                 .no_pcm = 1,
589                 .codecs = max98927_codec_components,
590                 .num_codecs = ARRAY_SIZE(max98927_codec_components),
591                 .dai_fmt = SND_SOC_DAIFMT_I2S |
592                         SND_SOC_DAIFMT_NB_NF |
593                         SND_SOC_DAIFMT_CBS_CFS,
594                 .ignore_pmdown_time = 1,
595                 .be_hw_params_fixup = kabylake_ssp_fixup,
596                 .dpcm_playback = 1,
597         },
598         {
599                 /* SSP1 - Codec */
600                 .name = "SSP1-Codec",
601                 .id = 1,
602                 .cpu_dai_name = "SSP1 Pin",
603                 .platform_name = "0000:00:1f.3",
604                 .no_pcm = 1,
605                 .codec_name = "i2c-10EC5663:00",
606                 .codec_dai_name = KBL_REALTEK_CODEC_DAI,
607                 .init = kabylake_rt5663_max98927_codec_init,
608                 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
609                         SND_SOC_DAIFMT_CBS_CFS,
610                 .ignore_pmdown_time = 1,
611                 .be_hw_params_fixup = kabylake_ssp_fixup,
612                 .ops = &kabylake_rt5663_ops,
613                 .dpcm_playback = 1,
614                 .dpcm_capture = 1,
615         },
616         {
617                 .name = "dmic01",
618                 .id = 2,
619                 .cpu_dai_name = "DMIC01 Pin",
620                 .codec_name = "dmic-codec",
621                 .codec_dai_name = "dmic-hifi",
622                 .platform_name = "0000:00:1f.3",
623                 .be_hw_params_fixup = kabylake_dmic_fixup,
624                 .ignore_suspend = 1,
625                 .dpcm_capture = 1,
626                 .no_pcm = 1,
627         },
628         {
629                 .name = "iDisp1",
630                 .id = 3,
631                 .cpu_dai_name = "iDisp1 Pin",
632                 .codec_name = "ehdaudio0D2",
633                 .codec_dai_name = "intel-hdmi-hifi1",
634                 .platform_name = "0000:00:1f.3",
635                 .dpcm_playback = 1,
636                 .init = kabylake_hdmi1_init,
637                 .no_pcm = 1,
638         },
639         {
640                 .name = "iDisp2",
641                 .id = 4,
642                 .cpu_dai_name = "iDisp2 Pin",
643                 .codec_name = "ehdaudio0D2",
644                 .codec_dai_name = "intel-hdmi-hifi2",
645                 .platform_name = "0000:00:1f.3",
646                 .init = kabylake_hdmi2_init,
647                 .dpcm_playback = 1,
648                 .no_pcm = 1,
649         },
650         {
651                 .name = "iDisp3",
652                 .id = 5,
653                 .cpu_dai_name = "iDisp3 Pin",
654                 .codec_name = "ehdaudio0D2",
655                 .codec_dai_name = "intel-hdmi-hifi3",
656                 .platform_name = "0000:00:1f.3",
657                 .init = kabylake_hdmi3_init,
658                 .dpcm_playback = 1,
659                 .no_pcm = 1,
660         },
661 };
662
663 static struct snd_soc_dai_link kabylake_5663_dais[] = {
664         /* Front End DAI links */
665         [KBL_DPCM_AUDIO_5663_PB] = {
666                 .name = "Kbl Audio Port",
667                 .stream_name = "Audio",
668                 .cpu_dai_name = "System Pin",
669                 .platform_name = "0000:00:1f.3",
670                 .dynamic = 1,
671                 .codec_name = "snd-soc-dummy",
672                 .codec_dai_name = "snd-soc-dummy-dai",
673                 .nonatomic = 1,
674                 .trigger = {
675                         SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
676                 .dpcm_playback = 1,
677                 .ops = &kabylake_rt5663_fe_ops,
678         },
679         [KBL_DPCM_AUDIO_5663_CP] = {
680                 .name = "Kbl Audio Capture Port",
681                 .stream_name = "Audio Record",
682                 .cpu_dai_name = "System Pin",
683                 .platform_name = "0000:00:1f.3",
684                 .dynamic = 1,
685                 .codec_name = "snd-soc-dummy",
686                 .codec_dai_name = "snd-soc-dummy-dai",
687                 .nonatomic = 1,
688                 .trigger = {
689                         SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
690                 .dpcm_capture = 1,
691                 .ops = &kabylake_rt5663_fe_ops,
692         },
693         [KBL_DPCM_AUDIO_5663_HDMI1_PB] = {
694                 .name = "Kbl HDMI Port1",
695                 .stream_name = "Hdmi1",
696                 .cpu_dai_name = "HDMI1 Pin",
697                 .codec_name = "snd-soc-dummy",
698                 .codec_dai_name = "snd-soc-dummy-dai",
699                 .platform_name = "0000:00:1f.3",
700                 .dpcm_playback = 1,
701                 .init = NULL,
702                 .trigger = {
703                         SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
704                 .nonatomic = 1,
705                 .dynamic = 1,
706         },
707         [KBL_DPCM_AUDIO_5663_HDMI2_PB] = {
708                 .name = "Kbl HDMI Port2",
709                 .stream_name = "Hdmi2",
710                 .cpu_dai_name = "HDMI2 Pin",
711                 .codec_name = "snd-soc-dummy",
712                 .codec_dai_name = "snd-soc-dummy-dai",
713                 .platform_name = "0000:00:1f.3",
714                 .dpcm_playback = 1,
715                 .init = NULL,
716                 .trigger = {
717                         SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
718                 .nonatomic = 1,
719                 .dynamic = 1,
720         },
721
722         /* Back End DAI links */
723         {
724                 /* SSP1 - Codec */
725                 .name = "SSP1-Codec",
726                 .id = 0,
727                 .cpu_dai_name = "SSP1 Pin",
728                 .platform_name = "0000:00:1f.3",
729                 .no_pcm = 1,
730                 .codec_name = "i2c-10EC5663:00",
731                 .codec_dai_name = KBL_REALTEK_CODEC_DAI,
732                 .init = kabylake_rt5663_codec_init,
733                 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
734                         SND_SOC_DAIFMT_CBS_CFS,
735                 .ignore_pmdown_time = 1,
736                 .be_hw_params_fixup = kabylake_ssp_fixup,
737                 .ops = &kabylake_rt5663_ops,
738                 .dpcm_playback = 1,
739                 .dpcm_capture = 1,
740         },
741         {
742                 .name = "iDisp1",
743                 .id = 1,
744                 .cpu_dai_name = "iDisp1 Pin",
745                 .codec_name = "ehdaudio0D2",
746                 .codec_dai_name = "intel-hdmi-hifi1",
747                 .platform_name = "0000:00:1f.3",
748                 .dpcm_playback = 1,
749                 .init = kabylake_5663_hdmi1_init,
750                 .no_pcm = 1,
751         },
752         {
753                 .name = "iDisp2",
754                 .id = 2,
755                 .cpu_dai_name = "iDisp2 Pin",
756                 .codec_name = "ehdaudio0D2",
757                 .codec_dai_name = "intel-hdmi-hifi2",
758                 .platform_name = "0000:00:1f.3",
759                 .init = kabylake_5663_hdmi2_init,
760                 .dpcm_playback = 1,
761                 .no_pcm = 1,
762         },
763 };
764
765 #define NAME_SIZE       32
766 static int kabylake_card_late_probe(struct snd_soc_card *card)
767 {
768         struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(card);
769         struct kbl_hdmi_pcm *pcm;
770         int err, i = 0;
771         char jack_name[NAME_SIZE];
772
773         list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
774                 snprintf(jack_name, sizeof(jack_name),
775                         "HDMI/DP, pcm=%d Jack", pcm->device);
776                 err = snd_soc_card_jack_new(card, jack_name,
777                                         SND_JACK_AVOUT, &skylake_hdmi[i],
778                                         NULL, 0);
779
780                 if (err)
781                         return err;
782
783                 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
784                                                 &skylake_hdmi[i]);
785                 if (err < 0)
786                         return err;
787
788                 i++;
789         }
790
791         return 0;
792 }
793
794 /* kabylake audio machine driver for SPT + RT5663 */
795 static struct snd_soc_card kabylake_audio_card_rt5663_m98927 = {
796         .name = "kblrt5663max",
797         .owner = THIS_MODULE,
798         .dai_link = kabylake_dais,
799         .num_links = ARRAY_SIZE(kabylake_dais),
800         .controls = kabylake_controls,
801         .num_controls = ARRAY_SIZE(kabylake_controls),
802         .dapm_widgets = kabylake_widgets,
803         .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
804         .dapm_routes = kabylake_map,
805         .num_dapm_routes = ARRAY_SIZE(kabylake_map),
806         .codec_conf = max98927_codec_conf,
807         .num_configs = ARRAY_SIZE(max98927_codec_conf),
808         .fully_routed = true,
809         .late_probe = kabylake_card_late_probe,
810 };
811
812 /* kabylake audio machine driver for RT5663 */
813 static struct snd_soc_card kabylake_audio_card_rt5663 = {
814         .name = "kblrt5663",
815         .owner = THIS_MODULE,
816         .dai_link = kabylake_5663_dais,
817         .num_links = ARRAY_SIZE(kabylake_5663_dais),
818         .controls = kabylake_5663_controls,
819         .num_controls = ARRAY_SIZE(kabylake_5663_controls),
820         .dapm_widgets = kabylake_5663_widgets,
821         .num_dapm_widgets = ARRAY_SIZE(kabylake_5663_widgets),
822         .dapm_routes = kabylake_5663_map,
823         .num_dapm_routes = ARRAY_SIZE(kabylake_5663_map),
824         .fully_routed = true,
825         .late_probe = kabylake_card_late_probe,
826 };
827
828 static int kabylake_audio_probe(struct platform_device *pdev)
829 {
830         struct kbl_rt5663_private *ctx;
831         struct skl_machine_pdata *pdata;
832
833         ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_ATOMIC);
834         if (!ctx)
835                 return -ENOMEM;
836
837         INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
838
839         kabylake_audio_card =
840                 (struct snd_soc_card *)pdev->id_entry->driver_data;
841
842         kabylake_audio_card->dev = &pdev->dev;
843         snd_soc_card_set_drvdata(kabylake_audio_card, ctx);
844
845         pdata = dev_get_drvdata(&pdev->dev);
846         if (pdata)
847                 dmic_constraints = pdata->dmic_num == 2 ?
848                         &constraints_dmic_2ch : &constraints_dmic_channels;
849
850         return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card);
851 }
852
853 static const struct platform_device_id kbl_board_ids[] = {
854         {
855                 .name = "kbl_rt5663",
856                 .driver_data = (kernel_ulong_t)&kabylake_audio_card_rt5663,
857         },
858         {
859                 .name = "kbl_rt5663_m98927",
860                 .driver_data =
861                         (kernel_ulong_t)&kabylake_audio_card_rt5663_m98927,
862         },
863         { }
864 };
865
866 static struct platform_driver kabylake_audio = {
867         .probe = kabylake_audio_probe,
868         .driver = {
869                 .name = "kbl_rt5663_m98927",
870                 .pm = &snd_soc_pm_ops,
871         },
872         .id_table = kbl_board_ids,
873 };
874
875 module_platform_driver(kabylake_audio)
876
877 /* Module information */
878 MODULE_DESCRIPTION("Audio Machine driver-RT5663 & MAX98927 in I2S mode");
879 MODULE_AUTHOR("Naveen M <naveen.m@intel.com>");
880 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
881 MODULE_LICENSE("GPL v2");
882 MODULE_ALIAS("platform:kbl_rt5663");
883 MODULE_ALIAS("platform:kbl_rt5663_m98927");