1
2
3
4
5
6
7
8
9
10
11
12#include <linux/input.h>
13#include <linux/module.h>
14#include <linux/platform_device.h>
15#include <sound/core.h>
16#include <sound/jack.h>
17#include <sound/pcm.h>
18#include <sound/pcm_params.h>
19#include <sound/soc.h>
20#include "../../codecs/da7219.h"
21#include "../../codecs/hdac_hdmi.h"
22#include "../skylake/skl.h"
23#include "../../codecs/da7219-aad.h"
24
25#define KBL_DIALOG_CODEC_DAI "da7219-hifi"
26#define KBL_MAXIM_CODEC_DAI "HiFi"
27#define MAXIM_DEV0_NAME "MX98357A:00"
28#define DUAL_CHANNEL 2
29#define QUAD_CHANNEL 4
30
31static struct snd_soc_card *kabylake_audio_card;
32static struct snd_soc_jack skylake_hdmi[3];
33
34struct kbl_hdmi_pcm {
35 struct list_head head;
36 struct snd_soc_dai *codec_dai;
37 int device;
38};
39
40struct kbl_codec_private {
41 struct snd_soc_jack kabylake_headset;
42 struct list_head hdmi_pcm_list;
43};
44
45enum {
46 KBL_DPCM_AUDIO_PB = 0,
47 KBL_DPCM_AUDIO_CP,
48 KBL_DPCM_AUDIO_DMIC_CP,
49 KBL_DPCM_AUDIO_HDMI1_PB,
50 KBL_DPCM_AUDIO_HDMI2_PB,
51 KBL_DPCM_AUDIO_HDMI3_PB,
52};
53
54static int platform_clock_control(struct snd_soc_dapm_widget *w,
55 struct snd_kcontrol *k, int event)
56{
57 struct snd_soc_dapm_context *dapm = w->dapm;
58 struct snd_soc_card *card = dapm->card;
59 struct snd_soc_dai *codec_dai;
60 int ret = 0;
61
62 codec_dai = snd_soc_card_get_codec_dai(card, KBL_DIALOG_CODEC_DAI);
63 if (!codec_dai) {
64 dev_err(card->dev, "Codec dai not found; Unable to set/unset codec pll\n");
65 return -EIO;
66 }
67
68
69 ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK, 24576000,
70 SND_SOC_CLOCK_IN);
71 if (ret) {
72 dev_err(card->dev, "can't set codec sysclk configuration\n");
73 return ret;
74 }
75
76 if (SND_SOC_DAPM_EVENT_OFF(event)) {
77 ret = snd_soc_dai_set_pll(codec_dai, 0,
78 DA7219_SYSCLK_MCLK, 0, 0);
79 if (ret)
80 dev_err(card->dev, "failed to stop PLL: %d\n", ret);
81 } else if (SND_SOC_DAPM_EVENT_ON(event)) {
82 ret = snd_soc_dai_set_pll(codec_dai, 0, DA7219_SYSCLK_PLL_SRM,
83 0, DA7219_PLL_FREQ_OUT_98304);
84 if (ret)
85 dev_err(card->dev, "failed to start PLL: %d\n", ret);
86 }
87
88 return ret;
89}
90
91static const struct snd_kcontrol_new kabylake_controls[] = {
92 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
93 SOC_DAPM_PIN_SWITCH("Headset Mic"),
94 SOC_DAPM_PIN_SWITCH("Spk"),
95};
96
97static const struct snd_soc_dapm_widget kabylake_widgets[] = {
98 SND_SOC_DAPM_HP("Headphone Jack", NULL),
99 SND_SOC_DAPM_MIC("Headset Mic", NULL),
100 SND_SOC_DAPM_SPK("Spk", NULL),
101 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
102 SND_SOC_DAPM_SPK("DP", NULL),
103 SND_SOC_DAPM_SPK("HDMI", NULL),
104 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
105 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
106 SND_SOC_DAPM_POST_PMD),
107};
108
109static const struct snd_soc_dapm_route kabylake_map[] = {
110 { "Headphone Jack", NULL, "HPL" },
111 { "Headphone Jack", NULL, "HPR" },
112
113
114 { "Spk", NULL, "Speaker" },
115
116
117 { "MIC", NULL, "Headset Mic" },
118 { "DMic", NULL, "SoC DMIC" },
119
120 { "HDMI", NULL, "hif5 Output" },
121 { "DP", NULL, "hif6 Output" },
122
123
124 { "HiFi Playback", NULL, "ssp0 Tx" },
125 { "ssp0 Tx", NULL, "codec0_out" },
126
127 { "Playback", NULL, "ssp1 Tx" },
128 { "ssp1 Tx", NULL, "codec1_out" },
129
130 { "codec0_in", NULL, "ssp1 Rx" },
131 { "ssp1 Rx", NULL, "Capture" },
132
133
134 { "dmic01_hifi", NULL, "DMIC01 Rx" },
135 { "DMIC01 Rx", NULL, "DMIC AIF" },
136
137 { "hifi1", NULL, "iDisp1 Tx" },
138 { "iDisp1 Tx", NULL, "iDisp1_out" },
139 { "hifi2", NULL, "iDisp2 Tx" },
140 { "iDisp2 Tx", NULL, "iDisp2_out" },
141 { "hifi3", NULL, "iDisp3 Tx"},
142 { "iDisp3 Tx", NULL, "iDisp3_out"},
143
144 { "Headphone Jack", NULL, "Platform Clock" },
145 { "Headset Mic", NULL, "Platform Clock" },
146};
147
148static int kabylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
149 struct snd_pcm_hw_params *params)
150{
151 struct snd_interval *rate = hw_param_interval(params,
152 SNDRV_PCM_HW_PARAM_RATE);
153 struct snd_interval *channels = hw_param_interval(params,
154 SNDRV_PCM_HW_PARAM_CHANNELS);
155 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
156
157
158 rate->min = rate->max = 48000;
159 channels->min = channels->max = DUAL_CHANNEL;
160
161
162 snd_mask_none(fmt);
163 snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE);
164
165 return 0;
166}
167
168static int kabylake_da7219_codec_init(struct snd_soc_pcm_runtime *rtd)
169{
170 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
171 struct snd_soc_component *component = rtd->codec_dai->component;
172 struct snd_soc_jack *jack;
173 int ret;
174
175
176
177
178
179 ret = snd_soc_card_jack_new(kabylake_audio_card, "Headset Jack",
180 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
181 SND_JACK_BTN_2 | SND_JACK_BTN_3 | SND_JACK_LINEOUT,
182 &ctx->kabylake_headset, NULL, 0);
183 if (ret) {
184 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
185 return ret;
186 }
187
188 jack = &ctx->kabylake_headset;
189
190 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_MEDIA);
191 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOLUMEUP);
192 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEDOWN);
193 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOICECOMMAND);
194 da7219_aad_jack_det(component, &ctx->kabylake_headset);
195
196 ret = snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
197 if (ret)
198 dev_err(rtd->dev, "SoC DMIC - Ignore suspend failed %d\n", ret);
199
200 return ret;
201}
202
203static int kabylake_hdmi_init(struct snd_soc_pcm_runtime *rtd, int device)
204{
205 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(rtd->card);
206 struct snd_soc_dai *dai = rtd->codec_dai;
207 struct kbl_hdmi_pcm *pcm;
208
209 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
210 if (!pcm)
211 return -ENOMEM;
212
213 pcm->device = device;
214 pcm->codec_dai = dai;
215
216 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
217
218 return 0;
219}
220
221static int kabylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
222{
223 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI1_PB);
224}
225
226static int kabylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
227{
228 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI2_PB);
229}
230
231static int kabylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd)
232{
233 return kabylake_hdmi_init(rtd, KBL_DPCM_AUDIO_HDMI3_PB);
234}
235
236static int kabylake_da7219_fe_init(struct snd_soc_pcm_runtime *rtd)
237{
238 struct snd_soc_dapm_context *dapm;
239 struct snd_soc_component *component = rtd->cpu_dai->component;
240
241 dapm = snd_soc_component_get_dapm(component);
242 snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
243
244 return 0;
245}
246
247static const unsigned int rates[] = {
248 48000,
249};
250
251static const struct snd_pcm_hw_constraint_list constraints_rates = {
252 .count = ARRAY_SIZE(rates),
253 .list = rates,
254 .mask = 0,
255};
256
257static const unsigned int channels[] = {
258 DUAL_CHANNEL,
259};
260
261static const struct snd_pcm_hw_constraint_list constraints_channels = {
262 .count = ARRAY_SIZE(channels),
263 .list = channels,
264 .mask = 0,
265};
266
267static unsigned int channels_quad[] = {
268 QUAD_CHANNEL,
269};
270
271static struct snd_pcm_hw_constraint_list constraints_channels_quad = {
272 .count = ARRAY_SIZE(channels_quad),
273 .list = channels_quad,
274 .mask = 0,
275};
276
277static int kbl_fe_startup(struct snd_pcm_substream *substream)
278{
279 struct snd_pcm_runtime *runtime = substream->runtime;
280
281
282
283
284
285
286
287
288 runtime->hw.channels_max = DUAL_CHANNEL;
289 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
290 &constraints_channels);
291
292 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
293 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
294
295 snd_pcm_hw_constraint_list(runtime, 0,
296 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
297
298 return 0;
299}
300
301static const struct snd_soc_ops kabylake_da7219_fe_ops = {
302 .startup = kbl_fe_startup,
303};
304
305static int kabylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
306 struct snd_pcm_hw_params *params)
307{
308 struct snd_interval *channels = hw_param_interval(params,
309 SNDRV_PCM_HW_PARAM_CHANNELS);
310
311
312
313
314
315 if (params_channels(params) == 2)
316 channels->min = channels->max = 2;
317 else
318 channels->min = channels->max = 4;
319
320 return 0;
321}
322
323static int kabylake_dmic_startup(struct snd_pcm_substream *substream)
324{
325 struct snd_pcm_runtime *runtime = substream->runtime;
326
327 runtime->hw.channels_min = runtime->hw.channels_max = QUAD_CHANNEL;
328 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
329 &constraints_channels_quad);
330
331 return snd_pcm_hw_constraint_list(substream->runtime, 0,
332 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
333}
334
335static struct snd_soc_ops kabylake_dmic_ops = {
336 .startup = kabylake_dmic_startup,
337};
338
339static const unsigned int rates_16000[] = {
340 16000,
341};
342
343static const struct snd_pcm_hw_constraint_list constraints_16000 = {
344 .count = ARRAY_SIZE(rates_16000),
345 .list = rates_16000,
346};
347
348static const unsigned int ch_mono[] = {
349 1,
350};
351
352
353static struct snd_soc_dai_link kabylake_dais[] = {
354
355 [KBL_DPCM_AUDIO_PB] = {
356 .name = "Kbl Audio Port",
357 .stream_name = "Audio",
358 .cpu_dai_name = "System Pin",
359 .platform_name = "0000:00:1f.3",
360 .dynamic = 1,
361 .codec_name = "snd-soc-dummy",
362 .codec_dai_name = "snd-soc-dummy-dai",
363 .nonatomic = 1,
364 .init = kabylake_da7219_fe_init,
365 .trigger = {
366 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
367 .dpcm_playback = 1,
368 .ops = &kabylake_da7219_fe_ops,
369 },
370 [KBL_DPCM_AUDIO_CP] = {
371 .name = "Kbl Audio Capture Port",
372 .stream_name = "Audio Record",
373 .cpu_dai_name = "System Pin",
374 .platform_name = "0000:00:1f.3",
375 .dynamic = 1,
376 .codec_name = "snd-soc-dummy",
377 .codec_dai_name = "snd-soc-dummy-dai",
378 .nonatomic = 1,
379 .trigger = {
380 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
381 .dpcm_capture = 1,
382 },
383 [KBL_DPCM_AUDIO_DMIC_CP] = {
384 .name = "Kbl Audio DMIC cap",
385 .stream_name = "dmiccap",
386 .cpu_dai_name = "DMIC Pin",
387 .codec_name = "snd-soc-dummy",
388 .codec_dai_name = "snd-soc-dummy-dai",
389 .platform_name = "0000:00:1f.3",
390 .init = NULL,
391 .dpcm_capture = 1,
392 .nonatomic = 1,
393 .dynamic = 1,
394 .ops = &kabylake_dmic_ops,
395 },
396 [KBL_DPCM_AUDIO_HDMI1_PB] = {
397 .name = "Kbl HDMI Port1",
398 .stream_name = "Hdmi1",
399 .cpu_dai_name = "HDMI1 Pin",
400 .codec_name = "snd-soc-dummy",
401 .codec_dai_name = "snd-soc-dummy-dai",
402 .platform_name = "0000:00:1f.3",
403 .dpcm_playback = 1,
404 .init = NULL,
405 .trigger = {
406 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
407 .nonatomic = 1,
408 .dynamic = 1,
409 },
410 [KBL_DPCM_AUDIO_HDMI2_PB] = {
411 .name = "Kbl HDMI Port2",
412 .stream_name = "Hdmi2",
413 .cpu_dai_name = "HDMI2 Pin",
414 .codec_name = "snd-soc-dummy",
415 .codec_dai_name = "snd-soc-dummy-dai",
416 .platform_name = "0000:00:1f.3",
417 .dpcm_playback = 1,
418 .init = NULL,
419 .trigger = {
420 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
421 .nonatomic = 1,
422 .dynamic = 1,
423 },
424 [KBL_DPCM_AUDIO_HDMI3_PB] = {
425 .name = "Kbl HDMI Port3",
426 .stream_name = "Hdmi3",
427 .cpu_dai_name = "HDMI3 Pin",
428 .codec_name = "snd-soc-dummy",
429 .codec_dai_name = "snd-soc-dummy-dai",
430 .platform_name = "0000:00:1f.3",
431 .trigger = {
432 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
433 .dpcm_playback = 1,
434 .init = NULL,
435 .nonatomic = 1,
436 .dynamic = 1,
437 },
438
439
440 {
441
442 .name = "SSP0-Codec",
443 .id = 0,
444 .cpu_dai_name = "SSP0 Pin",
445 .platform_name = "0000:00:1f.3",
446 .no_pcm = 1,
447 .codec_name = MAXIM_DEV0_NAME,
448 .codec_dai_name = KBL_MAXIM_CODEC_DAI,
449 .dai_fmt = SND_SOC_DAIFMT_I2S |
450 SND_SOC_DAIFMT_NB_NF |
451 SND_SOC_DAIFMT_CBS_CFS,
452 .ignore_pmdown_time = 1,
453 .be_hw_params_fixup = kabylake_ssp_fixup,
454 .dpcm_playback = 1,
455 },
456 {
457
458 .name = "SSP1-Codec",
459 .id = 1,
460 .cpu_dai_name = "SSP1 Pin",
461 .platform_name = "0000:00:1f.3",
462 .no_pcm = 1,
463 .codec_name = "i2c-DLGS7219:00",
464 .codec_dai_name = KBL_DIALOG_CODEC_DAI,
465 .init = kabylake_da7219_codec_init,
466 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
467 SND_SOC_DAIFMT_CBS_CFS,
468 .ignore_pmdown_time = 1,
469 .be_hw_params_fixup = kabylake_ssp_fixup,
470 .dpcm_playback = 1,
471 .dpcm_capture = 1,
472 },
473 {
474 .name = "dmic01",
475 .id = 2,
476 .cpu_dai_name = "DMIC01 Pin",
477 .codec_name = "dmic-codec",
478 .codec_dai_name = "dmic-hifi",
479 .platform_name = "0000:00:1f.3",
480 .be_hw_params_fixup = kabylake_dmic_fixup,
481 .ignore_suspend = 1,
482 .dpcm_capture = 1,
483 .no_pcm = 1,
484 },
485 {
486 .name = "iDisp1",
487 .id = 3,
488 .cpu_dai_name = "iDisp1 Pin",
489 .codec_name = "ehdaudio0D2",
490 .codec_dai_name = "intel-hdmi-hifi1",
491 .platform_name = "0000:00:1f.3",
492 .dpcm_playback = 1,
493 .init = kabylake_hdmi1_init,
494 .no_pcm = 1,
495 },
496 {
497 .name = "iDisp2",
498 .id = 4,
499 .cpu_dai_name = "iDisp2 Pin",
500 .codec_name = "ehdaudio0D2",
501 .codec_dai_name = "intel-hdmi-hifi2",
502 .platform_name = "0000:00:1f.3",
503 .init = kabylake_hdmi2_init,
504 .dpcm_playback = 1,
505 .no_pcm = 1,
506 },
507 {
508 .name = "iDisp3",
509 .id = 5,
510 .cpu_dai_name = "iDisp3 Pin",
511 .codec_name = "ehdaudio0D2",
512 .codec_dai_name = "intel-hdmi-hifi3",
513 .platform_name = "0000:00:1f.3",
514 .init = kabylake_hdmi3_init,
515 .dpcm_playback = 1,
516 .no_pcm = 1,
517 },
518};
519
520#define NAME_SIZE 32
521static int kabylake_card_late_probe(struct snd_soc_card *card)
522{
523 struct kbl_codec_private *ctx = snd_soc_card_get_drvdata(card);
524 struct kbl_hdmi_pcm *pcm;
525 struct snd_soc_component *component = NULL;
526 int err, i = 0;
527 char jack_name[NAME_SIZE];
528
529 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
530 component = pcm->codec_dai->component;
531 snprintf(jack_name, sizeof(jack_name),
532 "HDMI/DP, pcm=%d Jack", pcm->device);
533 err = snd_soc_card_jack_new(card, jack_name,
534 SND_JACK_AVOUT, &skylake_hdmi[i],
535 NULL, 0);
536
537 if (err)
538 return err;
539
540 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
541 &skylake_hdmi[i]);
542 if (err < 0)
543 return err;
544
545 i++;
546
547 }
548
549 if (!component)
550 return -EINVAL;
551
552 return hdac_hdmi_jack_port_init(component, &card->dapm);
553}
554
555
556static struct snd_soc_card kabylake_audio_card_da7219_m98357a = {
557 .name = "kblda7219max",
558 .owner = THIS_MODULE,
559 .dai_link = kabylake_dais,
560 .num_links = ARRAY_SIZE(kabylake_dais),
561 .controls = kabylake_controls,
562 .num_controls = ARRAY_SIZE(kabylake_controls),
563 .dapm_widgets = kabylake_widgets,
564 .num_dapm_widgets = ARRAY_SIZE(kabylake_widgets),
565 .dapm_routes = kabylake_map,
566 .num_dapm_routes = ARRAY_SIZE(kabylake_map),
567 .fully_routed = true,
568 .late_probe = kabylake_card_late_probe,
569};
570
571static int kabylake_audio_probe(struct platform_device *pdev)
572{
573 struct kbl_codec_private *ctx;
574
575 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_ATOMIC);
576 if (!ctx)
577 return -ENOMEM;
578
579 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
580
581 kabylake_audio_card =
582 (struct snd_soc_card *)pdev->id_entry->driver_data;
583
584 kabylake_audio_card->dev = &pdev->dev;
585 snd_soc_card_set_drvdata(kabylake_audio_card, ctx);
586 return devm_snd_soc_register_card(&pdev->dev, kabylake_audio_card);
587}
588
589static const struct platform_device_id kbl_board_ids[] = {
590 {
591 .name = "kbl_da7219_max98357a",
592 .driver_data =
593 (kernel_ulong_t)&kabylake_audio_card_da7219_m98357a,
594 },
595 { }
596};
597
598static struct platform_driver kabylake_audio = {
599 .probe = kabylake_audio_probe,
600 .driver = {
601 .name = "kbl_da7219_max98357a",
602 .pm = &snd_soc_pm_ops,
603 },
604 .id_table = kbl_board_ids,
605};
606
607module_platform_driver(kabylake_audio)
608
609
610MODULE_DESCRIPTION("Audio Machine driver-DA7219 & MAX98357A in I2S mode");
611MODULE_AUTHOR("Naveen Manohar <naveen.m@intel.com>");
612MODULE_LICENSE("GPL v2");
613MODULE_ALIAS("platform:kbl_da7219_max98357a");
614