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