2 * Intel Broxton-P I2S Machine Driver
4 * Copyright (C) 2016, Intel Corporation. All rights reserved.
7 * Intel Skylake I2S Machine driver
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License version
11 * 2 as published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
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"
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
35 static struct snd_soc_jack broxton_headset;
36 static struct snd_soc_jack broxton_hdmi[3];
39 struct list_head head;
40 struct snd_soc_dai *codec_dai;
44 struct bxt_card_private {
45 struct list_head hdmi_pcm_list;
49 BXT_DPCM_AUDIO_PB = 0,
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,
58 static int platform_clock_control(struct snd_soc_dapm_widget *w,
59 struct snd_kcontrol *k, int event)
62 struct snd_soc_dapm_context *dapm = w->dapm;
63 struct snd_soc_card *card = dapm->card;
64 struct snd_soc_dai *codec_dai;
66 codec_dai = snd_soc_card_get_codec_dai(card, BXT_DIALOG_CODEC_DAI);
68 dev_err(card->dev, "Codec dai not found; Unable to set/unset codec pll\n");
72 if (SND_SOC_DAPM_EVENT_OFF(event)) {
73 ret = snd_soc_dai_set_pll(codec_dai, 0,
74 DA7219_SYSCLK_MCLK, 0, 0);
76 dev_err(card->dev, "failed to stop PLL: %d\n", ret);
77 } else if(SND_SOC_DAPM_EVENT_ON(event)) {
78 ret = snd_soc_dai_set_pll(codec_dai, 0,
79 DA7219_SYSCLK_PLL_SRM, 0, DA7219_PLL_FREQ_OUT_98304);
81 dev_err(card->dev, "failed to start PLL: %d\n", ret);
87 static const struct snd_kcontrol_new broxton_controls[] = {
88 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
89 SOC_DAPM_PIN_SWITCH("Headset Mic"),
90 SOC_DAPM_PIN_SWITCH("Spk"),
93 static const struct snd_soc_dapm_widget broxton_widgets[] = {
94 SND_SOC_DAPM_HP("Headphone Jack", NULL),
95 SND_SOC_DAPM_MIC("Headset Mic", NULL),
96 SND_SOC_DAPM_SPK("Spk", NULL),
97 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
98 SND_SOC_DAPM_SPK("HDMI1", NULL),
99 SND_SOC_DAPM_SPK("HDMI2", NULL),
100 SND_SOC_DAPM_SPK("HDMI3", NULL),
101 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
102 platform_clock_control, SND_SOC_DAPM_POST_PMD|SND_SOC_DAPM_PRE_PMU),
105 static const struct snd_soc_dapm_route broxton_map[] = {
106 /* HP jack connectors - unknown if we have jack detection */
107 {"Headphone Jack", NULL, "HPL"},
108 {"Headphone Jack", NULL, "HPR"},
111 {"Spk", NULL, "Speaker"},
114 {"MIC", NULL, "Headset Mic"},
117 {"DMic", NULL, "SoC DMIC"},
119 /* CODEC BE connections */
120 {"HiFi Playback", NULL, "ssp5 Tx"},
121 {"ssp5 Tx", NULL, "codec0_out"},
123 {"Playback", NULL, "ssp1 Tx"},
124 {"ssp1 Tx", NULL, "codec1_out"},
126 {"codec0_in", NULL, "ssp1 Rx"},
127 {"ssp1 Rx", NULL, "Capture"},
129 {"HDMI1", NULL, "hif5-0 Output"},
130 {"HDMI2", NULL, "hif6-0 Output"},
131 {"HDMI2", NULL, "hif7-0 Output"},
133 {"hifi3", NULL, "iDisp3 Tx"},
134 {"iDisp3 Tx", NULL, "iDisp3_out"},
135 {"hifi2", NULL, "iDisp2 Tx"},
136 {"iDisp2 Tx", NULL, "iDisp2_out"},
137 {"hifi1", NULL, "iDisp1 Tx"},
138 {"iDisp1 Tx", NULL, "iDisp1_out"},
141 {"dmic01_hifi", NULL, "DMIC01 Rx"},
142 {"DMIC01 Rx", NULL, "DMIC AIF"},
144 { "Headphone Jack", NULL, "Platform Clock" },
145 { "Headset Mic", NULL, "Platform Clock" },
148 static int broxton_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
149 struct snd_pcm_hw_params *params)
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);
157 /* The ADSP will convert the FE rate to 48k, stereo */
158 rate->min = rate->max = 48000;
159 channels->min = channels->max = DUAL_CHANNEL;
161 /* set SSP to 24 bit */
163 snd_mask_set_format(fmt, SNDRV_PCM_FORMAT_S24_LE);
168 static int broxton_da7219_codec_init(struct snd_soc_pcm_runtime *rtd)
171 struct snd_soc_dai *codec_dai = rtd->codec_dai;
172 struct snd_soc_component *component = rtd->codec_dai->component;
174 /* Configure sysclk for codec */
175 ret = snd_soc_dai_set_sysclk(codec_dai, DA7219_CLKSRC_MCLK, 19200000,
178 dev_err(rtd->dev, "can't set codec sysclk configuration\n");
183 * Headset buttons map to the google Reference headset.
184 * These can be configured by userspace.
186 ret = snd_soc_card_jack_new(rtd->card, "Headset Jack",
187 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
188 SND_JACK_BTN_2 | SND_JACK_BTN_3 | SND_JACK_LINEOUT,
189 &broxton_headset, NULL, 0);
191 dev_err(rtd->dev, "Headset Jack creation failed: %d\n", ret);
195 da7219_aad_jack_det(component, &broxton_headset);
197 snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
202 static int broxton_hdmi_init(struct snd_soc_pcm_runtime *rtd)
204 struct bxt_card_private *ctx = snd_soc_card_get_drvdata(rtd->card);
205 struct snd_soc_dai *dai = rtd->codec_dai;
206 struct bxt_hdmi_pcm *pcm;
208 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
212 pcm->device = BXT_DPCM_AUDIO_HDMI1_PB + dai->id;
213 pcm->codec_dai = dai;
215 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
220 static int broxton_da7219_fe_init(struct snd_soc_pcm_runtime *rtd)
222 struct snd_soc_dapm_context *dapm;
223 struct snd_soc_component *component = rtd->cpu_dai->component;
225 dapm = snd_soc_component_get_dapm(component);
226 snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
231 static const unsigned int rates[] = {
235 static const struct snd_pcm_hw_constraint_list constraints_rates = {
236 .count = ARRAY_SIZE(rates),
241 static const unsigned int channels[] = {
245 static const struct snd_pcm_hw_constraint_list constraints_channels = {
246 .count = ARRAY_SIZE(channels),
251 static const unsigned int channels_quad[] = {
255 static const struct snd_pcm_hw_constraint_list constraints_channels_quad = {
256 .count = ARRAY_SIZE(channels_quad),
257 .list = channels_quad,
261 static int bxt_fe_startup(struct snd_pcm_substream *substream)
263 struct snd_pcm_runtime *runtime = substream->runtime;
266 * On this platform for PCM device we support,
272 runtime->hw.channels_max = DUAL_CHANNEL;
273 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
274 &constraints_channels);
276 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
277 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
279 snd_pcm_hw_constraint_list(runtime, 0,
280 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
285 static const struct snd_soc_ops broxton_da7219_fe_ops = {
286 .startup = bxt_fe_startup,
289 static int broxton_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
290 struct snd_pcm_hw_params *params)
292 struct snd_interval *channels = hw_param_interval(params,
293 SNDRV_PCM_HW_PARAM_CHANNELS);
294 if (params_channels(params) == 2)
295 channels->min = channels->max = 2;
297 channels->min = channels->max = 4;
302 static int broxton_dmic_startup(struct snd_pcm_substream *substream)
304 struct snd_pcm_runtime *runtime = substream->runtime;
306 runtime->hw.channels_min = runtime->hw.channels_max = QUAD_CHANNEL;
307 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
308 &constraints_channels_quad);
310 return snd_pcm_hw_constraint_list(substream->runtime, 0,
311 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
314 static const struct snd_soc_ops broxton_dmic_ops = {
315 .startup = broxton_dmic_startup,
318 static const unsigned int rates_16000[] = {
322 static const struct snd_pcm_hw_constraint_list constraints_16000 = {
323 .count = ARRAY_SIZE(rates_16000),
327 static const unsigned int ch_mono[] = {
331 static const struct snd_pcm_hw_constraint_list constraints_refcap = {
332 .count = ARRAY_SIZE(ch_mono),
336 static int broxton_refcap_startup(struct snd_pcm_substream *substream)
338 substream->runtime->hw.channels_max = 1;
339 snd_pcm_hw_constraint_list(substream->runtime, 0,
340 SNDRV_PCM_HW_PARAM_CHANNELS,
341 &constraints_refcap);
343 return snd_pcm_hw_constraint_list(substream->runtime, 0,
344 SNDRV_PCM_HW_PARAM_RATE,
348 static const struct snd_soc_ops broxton_refcap_ops = {
349 .startup = broxton_refcap_startup,
352 /* broxton digital audio interface glue - connects codec <--> CPU */
353 static struct snd_soc_dai_link broxton_dais[] = {
354 /* Front End DAI links */
355 [BXT_DPCM_AUDIO_PB] =
357 .name = "Bxt Audio Port",
358 .stream_name = "Audio",
359 .cpu_dai_name = "System Pin",
360 .platform_name = "0000:00:0e.0",
362 .codec_name = "snd-soc-dummy",
363 .codec_dai_name = "snd-soc-dummy-dai",
365 .init = broxton_da7219_fe_init,
367 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
369 .ops = &broxton_da7219_fe_ops,
371 [BXT_DPCM_AUDIO_CP] =
373 .name = "Bxt Audio Capture Port",
374 .stream_name = "Audio Record",
375 .cpu_dai_name = "System Pin",
376 .platform_name = "0000:00:0e.0",
378 .codec_name = "snd-soc-dummy",
379 .codec_dai_name = "snd-soc-dummy-dai",
382 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
384 .ops = &broxton_da7219_fe_ops,
386 [BXT_DPCM_AUDIO_REF_CP] =
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",
398 .ops = &broxton_refcap_ops,
400 [BXT_DPCM_AUDIO_DMIC_CP] =
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",
412 .ops = &broxton_dmic_ops,
414 [BXT_DPCM_AUDIO_HDMI1_PB] =
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",
427 [BXT_DPCM_AUDIO_HDMI2_PB] =
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",
440 [BXT_DPCM_AUDIO_HDMI3_PB] =
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",
453 /* Back End DAI links */
456 .name = "SSP5-Codec",
458 .cpu_dai_name = "SSP5 Pin",
459 .platform_name = "0000:00:0e.0",
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,
472 .name = "SSP1-Codec",
474 .cpu_dai_name = "SSP1 Pin",
475 .platform_name = "0000:00:0e.0",
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,
490 .cpu_dai_name = "DMIC01 Pin",
491 .codec_name = "dmic-codec",
492 .codec_dai_name = "dmic-hifi",
493 .platform_name = "0000:00:0e.0",
495 .be_hw_params_fixup = broxton_dmic_fixup,
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,
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,
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,
535 static int bxt_card_late_probe(struct snd_soc_card *card)
537 struct bxt_card_private *ctx = snd_soc_card_get_drvdata(card);
538 struct bxt_hdmi_pcm *pcm;
539 struct snd_soc_component *component = NULL;
541 char jack_name[NAME_SIZE];
543 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
544 component = pcm->codec_dai->component;
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],
554 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
565 return hdac_hdmi_jack_port_init(component, &card->dapm);
568 /* broxton audio machine driver for SPT + da7219 */
569 static 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,
584 static int broxton_audio_probe(struct platform_device *pdev)
586 struct bxt_card_private *ctx;
588 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
592 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
594 broxton_audio_card.dev = &pdev->dev;
595 snd_soc_card_set_drvdata(&broxton_audio_card, ctx);
597 return devm_snd_soc_register_card(&pdev->dev, &broxton_audio_card);
600 static struct platform_driver broxton_audio = {
601 .probe = broxton_audio_probe,
603 .name = "bxt_da7219_max98357a",
604 .pm = &snd_soc_pm_ops,
607 module_platform_driver(broxton_audio)
609 /* Module information */
610 MODULE_DESCRIPTION("Audio Machine driver-DA7219 & MAX98357A in I2S mode");
611 MODULE_AUTHOR("Sathyanarayana Nujella <sathyanarayana.nujella@intel.com>");
612 MODULE_AUTHOR("Rohit Ainapure <rohit.m.ainapure@intel.com>");
613 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
614 MODULE_AUTHOR("Conrad Cooke <conrad.cooke@intel.com>");
615 MODULE_LICENSE("GPL v2");
616 MODULE_ALIAS("platform:bxt_da7219_max98357a");