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