blob: c1442147d138dc08e852c2c5332c17c4cd916dfc [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,
Naveen Manoharb32ee382017-08-02 11:43:34 +053055 KBL_DPCM_AUDIO_HS_PB,
56 KBL_DPCM_AUDIO_ECHO_REF_CP,
Naveen Mec040dd2017-05-15 13:42:16 +053057 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
64static 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
71static 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
82static 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" },
Naveen Manohar0b061222017-08-02 11:43:35 +0530102 { "ssp0 Tx", NULL, "spk_out" },
Naveen Mec040dd2017-05-15 13:42:16 +0530103
104 { "AIF Playback", NULL, "ssp1 Tx" },
Naveen Manohar0b061222017-08-02 11:43:35 +0530105 { "ssp1 Tx", NULL, "hs_out" },
Naveen Mec040dd2017-05-15 13:42:16 +0530106
Naveen Manohar0b061222017-08-02 11:43:35 +0530107 { "hs_in", NULL, "ssp1 Rx" },
Naveen Mec040dd2017-05-15 13:42:16 +0530108 { "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
Kevin Chengc0642572017-07-27 16:38:36 +0800122enum {
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
129static const struct snd_kcontrol_new kabylake_5663_controls[] = {
130 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
131 SOC_DAPM_PIN_SWITCH("Headset Mic"),
132};
133
134static 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
141static 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
Naveen Mec040dd2017-05-15 13:42:16 +0530165static 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
176static 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
187static 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
203static 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 */
Kevin Chengc0642572017-07-27 16:38:36 +0800213 ret = snd_soc_card_jack_new(kabylake_audio_card, "Headset Jack",
Naveen Mec040dd2017-05-15 13:42:16 +0530214 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 }
Naveen Mec040dd2017-05-15 13:42:16 +0530221 rt5663_set_jack_detect(codec, &ctx->kabylake_headset);
Kevin Chengc0642572017-07-27 16:38:36 +0800222 return ret;
223}
224
225static 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
Naveen Mec040dd2017-05-15 13:42:16 +0530233 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
Kevin Chengc0642572017-07-27 16:38:36 +0800242static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device)
Naveen Mec040dd2017-05-15 13:42:16 +0530243{
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
Kevin Chengc0642572017-07-27 16:38:36 +0800252 pcm->device = device;
Naveen Mec040dd2017-05-15 13:42:16 +0530253 pcm->codec_dai = dai;
254
255 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
256
257 return 0;
258}
259
Kevin Chengc0642572017-07-27 16:38:36 +0800260static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
261{
262 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB);
263}
264
Naveen Mec040dd2017-05-15 13:42:16 +0530265static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
266{
Kevin Chengc0642572017-07-27 16:38:36 +0800267 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB);
Naveen Mec040dd2017-05-15 13:42:16 +0530268}
269
270static int kabylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd)
271{
Kevin Chengc0642572017-07-27 16:38:36 +0800272 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI3_PB);
273}
Naveen Mec040dd2017-05-15 13:42:16 +0530274
Kevin Chengc0642572017-07-27 16:38:36 +0800275static 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}
Naveen Mec040dd2017-05-15 13:42:16 +0530279
Kevin Chengc0642572017-07-27 16:38:36 +0800280static int kabylake_5663_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
281{
282 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_5663_HDMI2_PB);
Naveen Mec040dd2017-05-15 13:42:16 +0530283}
284
285static unsigned int rates[] = {
286 48000,
287};
288
Bhumika Goyal2d5f8482017-08-11 21:26:49 +0530289static const struct snd_pcm_hw_constraint_list constraints_rates = {
Naveen Mec040dd2017-05-15 13:42:16 +0530290 .count = ARRAY_SIZE(rates),
291 .list = rates,
292 .mask = 0,
293};
294
295static unsigned int channels[] = {
296 2,
297};
298
Bhumika Goyal2d5f8482017-08-11 21:26:49 +0530299static const struct snd_pcm_hw_constraint_list constraints_channels = {
Naveen Mec040dd2017-05-15 13:42:16 +0530300 .count = ARRAY_SIZE(channels),
301 .list = channels,
302 .mask = 0,
303};
304
305static 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
329static const struct snd_soc_ops kabylake_rt5663_fe_ops = {
330 .startup = kbl_fe_startup,
331};
332
333static 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
352static 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
Harsha Priya Nd46b1822017-08-16 16:19:55 +0530359 /* use ASRC for internal clocks, as PLL rate isn't multiple of BCLK */
360 rt5663_sel_asrc_clk_src(codec_dai->codec,
361 RT5663_DA_STEREO_FILTER | RT5663_AD_STEREO_FILTER,
362 RT5663_CLK_SEL_I2S1_ASRC);
363
Naveen Mec040dd2017-05-15 13:42:16 +0530364 ret = snd_soc_dai_set_sysclk(codec_dai,
365 RT5663_SCLK_S_MCLK, 24576000, SND_SOC_CLOCK_IN);
Naveen Mec040dd2017-05-15 13:42:16 +0530366 if (ret < 0)
367 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
368
369 return ret;
370}
371
372static struct snd_soc_ops kabylake_rt5663_ops = {
373 .hw_params = kabylake_rt5663_hw_params,
374};
375
376static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
377 struct snd_pcm_hw_params *params)
378{
379 struct snd_interval *channels = hw_param_interval(params,
380 SNDRV_PCM_HW_PARAM_CHANNELS);
381
382 if (params_channels(params) == 2 || DMIC_CH(dmic_constraints) == 2)
383 channels->min = channels->max = 2;
384 else
385 channels->min = channels->max = 4;
386
387 return 0;
388}
389
390static unsigned int channels_dmic[] = {
391 2, 4,
392};
393
394static struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
395 .count = ARRAY_SIZE(channels_dmic),
396 .list = channels_dmic,
397 .mask = 0,
398};
399
400static const unsigned int dmic_2ch[] = {
401 2,
402};
403
404static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch = {
405 .count = ARRAY_SIZE(dmic_2ch),
406 .list = dmic_2ch,
407 .mask = 0,
408};
409
410static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
411{
412 struct snd_pcm_runtime *runtime = substream->runtime;
413
414 runtime->hw.channels_max = DMIC_CH(dmic_constraints);
415 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
416 dmic_constraints);
417
418 return snd_pcm_hw_constraint_list(substream->runtime, 0,
419 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
420}
421
422static struct snd_soc_ops kabylake_dmic_ops = {
423 .startup = kabylake_dmic_startup,
424};
425
426static unsigned int rates_16000[] = {
427 16000,
428};
429
Bhumika Goyal2d5f8482017-08-11 21:26:49 +0530430static const struct snd_pcm_hw_constraint_list constraints_16000 = {
Naveen Mec040dd2017-05-15 13:42:16 +0530431 .count = ARRAY_SIZE(rates_16000),
432 .list = rates_16000,
433};
434
435static const unsigned int ch_mono[] = {
436 1,
437};
438
439static const struct snd_pcm_hw_constraint_list constraints_refcap = {
440 .count = ARRAY_SIZE(ch_mono),
441 .list = ch_mono,
442};
443
444static int kabylake_refcap_startup(struct snd_pcm_substream *substream)
445{
446 substream->runtime->hw.channels_max = 1;
447 snd_pcm_hw_constraint_list(substream->runtime, 0,
448 SNDRV_PCM_HW_PARAM_CHANNELS,
449 &constraints_refcap);
450
451 return snd_pcm_hw_constraint_list(substream->runtime, 0,
452 SNDRV_PCM_HW_PARAM_RATE,
453 &constraints_16000);
454}
455
456static struct snd_soc_ops skylaye_refcap_ops = {
457 .startup = kabylake_refcap_startup,
458};
459
460/* kabylake digital audio interface glue - connects codec <--> CPU */
461static struct snd_soc_dai_link kabylake_dais[] = {
462 /* Front End DAI links */
463 [KBL_DPCM_AUDIO_PB] = {
464 .name = "Kbl Audio Port",
465 .stream_name = "Audio",
466 .cpu_dai_name = "System Pin",
467 .platform_name = "0000:00:1f.3",
468 .dynamic = 1,
469 .codec_name = "snd-soc-dummy",
470 .codec_dai_name = "snd-soc-dummy-dai",
471 .nonatomic = 1,
472 .init = kabylake_rt5663_fe_init,
473 .trigger = {
474 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
475 .dpcm_playback = 1,
476 .ops = &kabylake_rt5663_fe_ops,
477 },
478 [KBL_DPCM_AUDIO_CP] = {
479 .name = "Kbl Audio Capture Port",
480 .stream_name = "Audio Record",
481 .cpu_dai_name = "System Pin",
482 .platform_name = "0000:00:1f.3",
483 .dynamic = 1,
484 .codec_name = "snd-soc-dummy",
485 .codec_dai_name = "snd-soc-dummy-dai",
486 .nonatomic = 1,
487 .trigger = {
488 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
489 .dpcm_capture = 1,
490 .ops = &kabylake_rt5663_fe_ops,
491 },
Naveen Manoharb32ee382017-08-02 11:43:34 +0530492 [KBL_DPCM_AUDIO_HS_PB] = {
493 .name = "Kbl Audio Headset Playback",
494 .stream_name = "Headset Audio",
495 .cpu_dai_name = "System Pin2",
496 .codec_name = "snd-soc-dummy",
497 .codec_dai_name = "snd-soc-dummy-dai",
498 .platform_name = "0000:00:1f.3",
499 .dpcm_playback = 1,
500 .nonatomic = 1,
501 .dynamic = 1,
502 },
503 [KBL_DPCM_AUDIO_ECHO_REF_CP] = {
504 .name = "Kbl Audio Echo Reference cap",
505 .stream_name = "Echoreference Capture",
506 .cpu_dai_name = "Echoref Pin",
507 .codec_name = "snd-soc-dummy",
508 .codec_dai_name = "snd-soc-dummy-dai",
509 .platform_name = "0000:00:1f.3",
510 .init = NULL,
511 .capture_only = 1,
512 .nonatomic = 1,
513 },
Naveen Mec040dd2017-05-15 13:42:16 +0530514 [KBL_DPCM_AUDIO_REF_CP] = {
515 .name = "Kbl Audio Reference cap",
516 .stream_name = "Wake on Voice",
517 .cpu_dai_name = "Reference Pin",
518 .codec_name = "snd-soc-dummy",
519 .codec_dai_name = "snd-soc-dummy-dai",
520 .platform_name = "0000:00:1f.3",
521 .init = NULL,
522 .dpcm_capture = 1,
523 .nonatomic = 1,
524 .dynamic = 1,
525 .ops = &skylaye_refcap_ops,
526 },
527 [KBL_DPCM_AUDIO_DMIC_CP] = {
528 .name = "Kbl Audio DMIC cap",
529 .stream_name = "dmiccap",
530 .cpu_dai_name = "DMIC Pin",
531 .codec_name = "snd-soc-dummy",
532 .codec_dai_name = "snd-soc-dummy-dai",
533 .platform_name = "0000:00:1f.3",
534 .init = NULL,
535 .dpcm_capture = 1,
536 .nonatomic = 1,
537 .dynamic = 1,
538 .ops = &kabylake_dmic_ops,
539 },
540 [KBL_DPCM_AUDIO_HDMI1_PB] = {
541 .name = "Kbl HDMI Port1",
542 .stream_name = "Hdmi1",
543 .cpu_dai_name = "HDMI1 Pin",
544 .codec_name = "snd-soc-dummy",
545 .codec_dai_name = "snd-soc-dummy-dai",
546 .platform_name = "0000:00:1f.3",
547 .dpcm_playback = 1,
548 .init = NULL,
549 .trigger = {
550 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
551 .nonatomic = 1,
552 .dynamic = 1,
553 },
554 [KBL_DPCM_AUDIO_HDMI2_PB] = {
555 .name = "Kbl HDMI Port2",
556 .stream_name = "Hdmi2",
557 .cpu_dai_name = "HDMI2 Pin",
558 .codec_name = "snd-soc-dummy",
559 .codec_dai_name = "snd-soc-dummy-dai",
560 .platform_name = "0000:00:1f.3",
561 .dpcm_playback = 1,
562 .init = NULL,
563 .trigger = {
564 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
565 .nonatomic = 1,
566 .dynamic = 1,
567 },
568 [KBL_DPCM_AUDIO_HDMI3_PB] = {
569 .name = "Kbl HDMI Port3",
570 .stream_name = "Hdmi3",
571 .cpu_dai_name = "HDMI3 Pin",
572 .codec_name = "snd-soc-dummy",
573 .codec_dai_name = "snd-soc-dummy-dai",
574 .platform_name = "0000:00:1f.3",
575 .trigger = {
576 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
577 .dpcm_playback = 1,
578 .init = NULL,
579 .nonatomic = 1,
580 .dynamic = 1,
581 },
582
583 /* Back End DAI links */
584 {
585 /* SSP0 - Codec */
586 .name = "SSP0-Codec",
587 .id = 0,
588 .cpu_dai_name = "SSP0 Pin",
589 .platform_name = "0000:00:1f.3",
590 .no_pcm = 1,
591 .codecs = max98927_codec_components,
592 .num_codecs = ARRAY_SIZE(max98927_codec_components),
593 .dai_fmt = SND_SOC_DAIFMT_I2S |
594 SND_SOC_DAIFMT_NB_NF |
595 SND_SOC_DAIFMT_CBS_CFS,
596 .ignore_pmdown_time = 1,
597 .be_hw_params_fixup = kabylake_ssp_fixup,
598 .dpcm_playback = 1,
599 },
600 {
601 /* SSP1 - Codec */
602 .name = "SSP1-Codec",
603 .id = 1,
604 .cpu_dai_name = "SSP1 Pin",
605 .platform_name = "0000:00:1f.3",
606 .no_pcm = 1,
607 .codec_name = "i2c-10EC5663:00",
608 .codec_dai_name = KBL_REALTEK_CODEC_DAI,
Kevin Chengc0642572017-07-27 16:38:36 +0800609 .init = kabylake_rt5663_max98927_codec_init,
Naveen Mec040dd2017-05-15 13:42:16 +0530610 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
611 SND_SOC_DAIFMT_CBS_CFS,
612 .ignore_pmdown_time = 1,
613 .be_hw_params_fixup = kabylake_ssp_fixup,
614 .ops = &kabylake_rt5663_ops,
615 .dpcm_playback = 1,
616 .dpcm_capture = 1,
617 },
618 {
619 .name = "dmic01",
620 .id = 2,
621 .cpu_dai_name = "DMIC01 Pin",
622 .codec_name = "dmic-codec",
623 .codec_dai_name = "dmic-hifi",
624 .platform_name = "0000:00:1f.3",
625 .be_hw_params_fixup = kabylake_dmic_fixup,
626 .ignore_suspend = 1,
627 .dpcm_capture = 1,
628 .no_pcm = 1,
629 },
630 {
631 .name = "iDisp1",
632 .id = 3,
633 .cpu_dai_name = "iDisp1 Pin",
634 .codec_name = "ehdaudio0D2",
635 .codec_dai_name = "intel-hdmi-hifi1",
636 .platform_name = "0000:00:1f.3",
637 .dpcm_playback = 1,
638 .init = kabylake_hdmi1_init,
639 .no_pcm = 1,
640 },
641 {
642 .name = "iDisp2",
643 .id = 4,
644 .cpu_dai_name = "iDisp2 Pin",
645 .codec_name = "ehdaudio0D2",
646 .codec_dai_name = "intel-hdmi-hifi2",
647 .platform_name = "0000:00:1f.3",
648 .init = kabylake_hdmi2_init,
649 .dpcm_playback = 1,
650 .no_pcm = 1,
651 },
652 {
653 .name = "iDisp3",
654 .id = 5,
655 .cpu_dai_name = "iDisp3 Pin",
656 .codec_name = "ehdaudio0D2",
657 .codec_dai_name = "intel-hdmi-hifi3",
658 .platform_name = "0000:00:1f.3",
659 .init = kabylake_hdmi3_init,
660 .dpcm_playback = 1,
661 .no_pcm = 1,
662 },
663};
664
Kevin Chengc0642572017-07-27 16:38:36 +0800665static struct snd_soc_dai_link kabylake_5663_dais[] = {
666 /* Front End DAI links */
667 [KBL_DPCM_AUDIO_5663_PB] = {
668 .name = "Kbl Audio Port",
669 .stream_name = "Audio",
670 .cpu_dai_name = "System Pin",
671 .platform_name = "0000:00:1f.3",
672 .dynamic = 1,
673 .codec_name = "snd-soc-dummy",
674 .codec_dai_name = "snd-soc-dummy-dai",
675 .nonatomic = 1,
676 .trigger = {
677 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
678 .dpcm_playback = 1,
679 .ops = &kabylake_rt5663_fe_ops,
680 },
681 [KBL_DPCM_AUDIO_5663_CP] = {
682 .name = "Kbl Audio Capture Port",
683 .stream_name = "Audio Record",
684 .cpu_dai_name = "System Pin",
685 .platform_name = "0000:00:1f.3",
686 .dynamic = 1,
687 .codec_name = "snd-soc-dummy",
688 .codec_dai_name = "snd-soc-dummy-dai",
689 .nonatomic = 1,
690 .trigger = {
691 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
692 .dpcm_capture = 1,
693 .ops = &kabylake_rt5663_fe_ops,
694 },
695 [KBL_DPCM_AUDIO_5663_HDMI1_PB] = {
696 .name = "Kbl HDMI Port1",
697 .stream_name = "Hdmi1",
698 .cpu_dai_name = "HDMI1 Pin",
699 .codec_name = "snd-soc-dummy",
700 .codec_dai_name = "snd-soc-dummy-dai",
701 .platform_name = "0000:00:1f.3",
702 .dpcm_playback = 1,
703 .init = NULL,
704 .trigger = {
705 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
706 .nonatomic = 1,
707 .dynamic = 1,
708 },
709 [KBL_DPCM_AUDIO_5663_HDMI2_PB] = {
710 .name = "Kbl HDMI Port2",
711 .stream_name = "Hdmi2",
712 .cpu_dai_name = "HDMI2 Pin",
713 .codec_name = "snd-soc-dummy",
714 .codec_dai_name = "snd-soc-dummy-dai",
715 .platform_name = "0000:00:1f.3",
716 .dpcm_playback = 1,
717 .init = NULL,
718 .trigger = {
719 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
720 .nonatomic = 1,
721 .dynamic = 1,
722 },
723
724 /* Back End DAI links */
725 {
726 /* SSP1 - Codec */
727 .name = "SSP1-Codec",
728 .id = 0,
729 .cpu_dai_name = "SSP1 Pin",
730 .platform_name = "0000:00:1f.3",
731 .no_pcm = 1,
732 .codec_name = "i2c-10EC5663:00",
733 .codec_dai_name = KBL_REALTEK_CODEC_DAI,
734 .init = kabylake_rt5663_codec_init,
735 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
736 SND_SOC_DAIFMT_CBS_CFS,
737 .ignore_pmdown_time = 1,
738 .be_hw_params_fixup = kabylake_ssp_fixup,
739 .ops = &kabylake_rt5663_ops,
740 .dpcm_playback = 1,
741 .dpcm_capture = 1,
742 },
743 {
744 .name = "iDisp1",
745 .id = 1,
746 .cpu_dai_name = "iDisp1 Pin",
747 .codec_name = "ehdaudio0D2",
748 .codec_dai_name = "intel-hdmi-hifi1",
749 .platform_name = "0000:00:1f.3",
750 .dpcm_playback = 1,
751 .init = kabylake_5663_hdmi1_init,
752 .no_pcm = 1,
753 },
754 {
755 .name = "iDisp2",
756 .id = 2,
757 .cpu_dai_name = "iDisp2 Pin",
758 .codec_name = "ehdaudio0D2",
759 .codec_dai_name = "intel-hdmi-hifi2",
760 .platform_name = "0000:00:1f.3",
761 .init = kabylake_5663_hdmi2_init,
762 .dpcm_playback = 1,
763 .no_pcm = 1,
764 },
765};
766
Naveen Mec040dd2017-05-15 13:42:16 +0530767#define NAME_SIZE 32
768static int kabylake_card_late_probe(struct snd_soc_card *card)
769{
770 struct kbl_rt5663_private *ctx = snd_soc_card_get_drvdata(card);
771 struct kbl_hdmi_pcm *pcm;
772 int err, i = 0;
773 char jack_name[NAME_SIZE];
774
775 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
776 snprintf(jack_name, sizeof(jack_name),
777 "HDMI/DP, pcm=%d Jack", pcm->device);
778 err = snd_soc_card_jack_new(card, jack_name,
779 SND_JACK_AVOUT, &skylake_hdmi[i],
780 NULL, 0);
781
782 if (err)
783 return err;
784
785 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
786 &skylake_hdmi[i]);
787 if (err < 0)
788 return err;
789
790 i++;
791 }
792
793 return 0;
794}
795
796/* kabylake audio machine driver for SPT + RT5663 */
Kevin Chengc0642572017-07-27 16:38:36 +0800797static struct snd_soc_card kabylake_audio_card_rt5663_m98927 = {
Naveen Mec040dd2017-05-15 13:42:16 +0530798 .name = "kblrt5663max",
799 .owner = THIS_MODULE,
800 .dai_link = kabylake_dais,
801 .num_links = ARRAY_SIZE(kabylake_dais),
802 .controls = kabylake_controls,
803 .num_controls = ARRAY_SIZE(kabylake_controls),
804 .dapm_widgets = kabylake_widgets,
805 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
806 .dapm_routes = kabylake_map,
807 .num_dapm_routes = ARRAY_SIZE(kabylake_map),
808 .codec_conf = max98927_codec_conf,
809 .num_configs = ARRAY_SIZE(max98927_codec_conf),
810 .fully_routed = true,
811 .late_probe = kabylake_card_late_probe,
812};
813
Kevin Chengc0642572017-07-27 16:38:36 +0800814/* kabylake audio machine driver for RT5663 */
815static struct snd_soc_card kabylake_audio_card_rt5663 = {
816 .name = "kblrt5663",
817 .owner = THIS_MODULE,
818 .dai_link = kabylake_5663_dais,
819 .num_links = ARRAY_SIZE(kabylake_5663_dais),
820 .controls = kabylake_5663_controls,
821 .num_controls = ARRAY_SIZE(kabylake_5663_controls),
822 .dapm_widgets = kabylake_5663_widgets,
823 .num_dapm_widgets = ARRAY_SIZE(kabylake_5663_widgets),
824 .dapm_routes = kabylake_5663_map,
825 .num_dapm_routes = ARRAY_SIZE(kabylake_5663_map),
826 .fully_routed = true,
827 .late_probe = kabylake_card_late_probe,
828};
829
Naveen Mec040dd2017-05-15 13:42:16 +0530830static int kabylake_audio_probe(struct platform_device *pdev)
831{
832 struct kbl_rt5663_private *ctx;
833 struct skl_machine_pdata *pdata;
834
835 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_ATOMIC);
836 if (!ctx)
837 return -ENOMEM;
838
839 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
840
Kevin Chengc0642572017-07-27 16:38:36 +0800841 kabylake_audio_card =
842 (struct snd_soc_card *)pdev->id_entry->driver_data;
843
844 kabylake_audio_card->dev = &pdev->dev;
845 snd_soc_card_set_drvdata(kabylake_audio_card, ctx);
Naveen Mec040dd2017-05-15 13:42:16 +0530846
847 pdata = dev_get_drvdata(&pdev->dev);
848 if (pdata)
849 dmic_constraints = pdata->dmic_num == 2 ?
850 &constraints_dmic_2ch : &constraints_dmic_channels;
851
Kevin Chengc0642572017-07-27 16:38:36 +0800852 return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card);
Naveen Mec040dd2017-05-15 13:42:16 +0530853}
854
855static const struct platform_device_id kbl_board_ids[] = {
Kevin Chengc0642572017-07-27 16:38:36 +0800856 {
857 .name = "kbl_rt5663",
858 .driver_data = (kernel_ulong_t)&kabylake_audio_card_rt5663,
859 },
860 {
861 .name = "kbl_rt5663_m98927",
862 .driver_data =
863 (kernel_ulong_t)&kabylake_audio_card_rt5663_m98927,
864 },
Naveen Mec040dd2017-05-15 13:42:16 +0530865 { }
866};
867
868static struct platform_driver kabylake_audio = {
869 .probe = kabylake_audio_probe,
870 .driver = {
871 .name = "kbl_rt5663_m98927",
872 .pm = &snd_soc_pm_ops,
873 },
874 .id_table = kbl_board_ids,
875};
876
877module_platform_driver(kabylake_audio)
878
879/* Module information */
880MODULE_DESCRIPTION("Audio Machine driver-RT5663 & MAX98927 in I2S mode");
881MODULE_AUTHOR("Naveen M <naveen.m@intel.com>");
882MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
883MODULE_LICENSE("GPL v2");
Kevin Chengc0642572017-07-27 16:38:36 +0800884MODULE_ALIAS("platform:kbl_rt5663");
Naveen Mec040dd2017-05-15 13:42:16 +0530885MODULE_ALIAS("platform:kbl_rt5663_m98927");