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
34 static struct snd_soc_jack broxton_headset
;
37 BXT_DPCM_AUDIO_PB
= 0,
39 BXT_DPCM_AUDIO_REF_CP
,
40 BXT_DPCM_AUDIO_DMIC_CP
,
41 BXT_DPCM_AUDIO_HDMI1_PB
,
42 BXT_DPCM_AUDIO_HDMI2_PB
,
43 BXT_DPCM_AUDIO_HDMI3_PB
,
46 static const struct snd_kcontrol_new broxton_controls
[] = {
47 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
48 SOC_DAPM_PIN_SWITCH("Headset Mic"),
49 SOC_DAPM_PIN_SWITCH("Spk"),
52 static const struct snd_soc_dapm_widget broxton_widgets
[] = {
53 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
54 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
55 SND_SOC_DAPM_SPK("Spk", NULL
),
56 SND_SOC_DAPM_MIC("SoC DMIC", NULL
),
57 SND_SOC_DAPM_SPK("HDMI1", NULL
),
58 SND_SOC_DAPM_SPK("HDMI2", NULL
),
59 SND_SOC_DAPM_SPK("HDMI3", NULL
),
62 static const struct snd_soc_dapm_route broxton_map
[] = {
63 /* HP jack connectors - unknown if we have jack detection */
64 {"Headphone Jack", NULL
, "HPL"},
65 {"Headphone Jack", NULL
, "HPR"},
68 {"Spk", NULL
, "Speaker"},
71 {"MIC", NULL
, "Headset Mic"},
74 {"DMic", NULL
, "SoC DMIC"},
76 /* CODEC BE connections */
77 {"HiFi Playback", NULL
, "ssp5 Tx"},
78 {"ssp5 Tx", NULL
, "codec0_out"},
80 {"Playback", NULL
, "ssp1 Tx"},
81 {"ssp1 Tx", NULL
, "codec1_out"},
83 {"codec0_in", NULL
, "ssp1 Rx"},
84 {"ssp1 Rx", NULL
, "Capture"},
86 {"HDMI1", NULL
, "hif5 Output"},
87 {"HDMI2", NULL
, "hif6 Output"},
88 {"HDMI3", NULL
, "hif7 Output"},
90 {"hifi3", NULL
, "iDisp3 Tx"},
91 {"iDisp3 Tx", NULL
, "iDisp3_out"},
92 {"hifi2", NULL
, "iDisp2 Tx"},
93 {"iDisp2 Tx", NULL
, "iDisp2_out"},
94 {"hifi1", NULL
, "iDisp1 Tx"},
95 {"iDisp1 Tx", NULL
, "iDisp1_out"},
98 {"dmic01_hifi", NULL
, "DMIC01 Rx"},
99 {"DMIC01 Rx", NULL
, "DMIC AIF"},
102 static int broxton_ssp_fixup(struct snd_soc_pcm_runtime
*rtd
,
103 struct snd_pcm_hw_params
*params
)
105 struct snd_interval
*rate
= hw_param_interval(params
,
106 SNDRV_PCM_HW_PARAM_RATE
);
107 struct snd_interval
*channels
= hw_param_interval(params
,
108 SNDRV_PCM_HW_PARAM_CHANNELS
);
109 struct snd_mask
*fmt
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
111 /* The ADSP will convert the FE rate to 48k, stereo */
112 rate
->min
= rate
->max
= 48000;
113 channels
->min
= channels
->max
= DUAL_CHANNEL
;
115 /* set SSP to 24 bit */
117 snd_mask_set(fmt
, SNDRV_PCM_FORMAT_S24_LE
);
122 static int broxton_da7219_codec_init(struct snd_soc_pcm_runtime
*rtd
)
125 struct snd_soc_codec
*codec
= rtd
->codec
;
128 * Headset buttons map to the google Reference headset.
129 * These can be configured by userspace.
131 ret
= snd_soc_card_jack_new(rtd
->card
, "Headset Jack",
132 SND_JACK_HEADSET
| SND_JACK_BTN_0
| SND_JACK_BTN_1
|
133 SND_JACK_BTN_2
| SND_JACK_BTN_3
| SND_JACK_LINEOUT
,
134 &broxton_headset
, NULL
, 0);
136 dev_err(rtd
->dev
, "Headset Jack creation failed: %d\n", ret
);
140 da7219_aad_jack_det(codec
, &broxton_headset
);
142 snd_soc_dapm_ignore_suspend(&rtd
->card
->dapm
, "SoC DMIC");
147 static int broxton_hdmi_init(struct snd_soc_pcm_runtime
*rtd
)
149 struct snd_soc_dai
*dai
= rtd
->codec_dai
;
151 return hdac_hdmi_jack_init(dai
, BXT_DPCM_AUDIO_HDMI1_PB
+ dai
->id
);
154 static int broxton_da7219_fe_init(struct snd_soc_pcm_runtime
*rtd
)
156 struct snd_soc_dapm_context
*dapm
;
157 struct snd_soc_component
*component
= rtd
->cpu_dai
->component
;
159 dapm
= snd_soc_component_get_dapm(component
);
160 snd_soc_dapm_ignore_suspend(dapm
, "Reference Capture");
165 static unsigned int rates
[] = {
169 static struct snd_pcm_hw_constraint_list constraints_rates
= {
170 .count
= ARRAY_SIZE(rates
),
175 static unsigned int channels
[] = {
179 static struct snd_pcm_hw_constraint_list constraints_channels
= {
180 .count
= ARRAY_SIZE(channels
),
185 static int bxt_fe_startup(struct snd_pcm_substream
*substream
)
187 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
190 * On this platform for PCM device we support,
196 runtime
->hw
.channels_max
= DUAL_CHANNEL
;
197 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
198 &constraints_channels
);
200 runtime
->hw
.formats
= SNDRV_PCM_FMTBIT_S16_LE
;
201 snd_pcm_hw_constraint_msbits(runtime
, 0, 16, 16);
203 snd_pcm_hw_constraint_list(runtime
, 0,
204 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
209 static const struct snd_soc_ops broxton_da7219_fe_ops
= {
210 .startup
= bxt_fe_startup
,
213 static int broxton_da7219_hw_params(struct snd_pcm_substream
*substream
,
214 struct snd_pcm_hw_params
*params
)
216 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
217 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
220 ret
= snd_soc_dai_set_sysclk(codec_dai
,
221 DA7219_CLKSRC_MCLK
, 19200000, SND_SOC_CLOCK_IN
);
223 dev_err(codec_dai
->dev
, "can't set codec sysclk configuration\n");
225 ret
= snd_soc_dai_set_pll(codec_dai
, 0,
226 DA7219_SYSCLK_PLL_SRM
, 0, DA7219_PLL_FREQ_OUT_98304
);
228 dev_err(codec_dai
->dev
, "failed to start PLL: %d\n", ret
);
235 static int broxton_da7219_hw_free(struct snd_pcm_substream
*substream
)
237 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
238 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
241 ret
= snd_soc_dai_set_pll(codec_dai
, 0,
242 DA7219_SYSCLK_MCLK
, 0, 0);
244 dev_err(codec_dai
->dev
, "failed to stop PLL: %d\n", ret
);
251 static struct snd_soc_ops broxton_da7219_ops
= {
252 .hw_params
= broxton_da7219_hw_params
,
253 .hw_free
= broxton_da7219_hw_free
,
256 static int broxton_dmic_fixup(struct snd_soc_pcm_runtime
*rtd
,
257 struct snd_pcm_hw_params
*params
)
259 struct snd_interval
*channels
= hw_param_interval(params
,
260 SNDRV_PCM_HW_PARAM_CHANNELS
);
261 channels
->min
= channels
->max
= DUAL_CHANNEL
;
266 static int broxton_dmic_startup(struct snd_pcm_substream
*substream
)
268 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
270 runtime
->hw
.channels_max
= DUAL_CHANNEL
;
271 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
272 &constraints_channels
);
274 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
275 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
278 static const struct snd_soc_ops broxton_dmic_ops
= {
279 .startup
= broxton_dmic_startup
,
282 static const unsigned int rates_16000
[] = {
286 static const struct snd_pcm_hw_constraint_list constraints_16000
= {
287 .count
= ARRAY_SIZE(rates_16000
),
291 static int broxton_refcap_startup(struct snd_pcm_substream
*substream
)
293 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
294 SNDRV_PCM_HW_PARAM_RATE
,
298 static struct snd_soc_ops broxton_refcap_ops
= {
299 .startup
= broxton_refcap_startup
,
302 /* broxton digital audio interface glue - connects codec <--> CPU */
303 static struct snd_soc_dai_link broxton_dais
[] = {
304 /* Front End DAI links */
305 [BXT_DPCM_AUDIO_PB
] =
307 .name
= "Bxt Audio Port",
308 .stream_name
= "Audio",
309 .cpu_dai_name
= "System Pin",
310 .platform_name
= "0000:00:0e.0",
312 .codec_name
= "snd-soc-dummy",
313 .codec_dai_name
= "snd-soc-dummy-dai",
315 .init
= broxton_da7219_fe_init
,
317 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
319 .ops
= &broxton_da7219_fe_ops
,
321 [BXT_DPCM_AUDIO_CP
] =
323 .name
= "Bxt Audio Capture Port",
324 .stream_name
= "Audio Record",
325 .cpu_dai_name
= "System Pin",
326 .platform_name
= "0000:00:0e.0",
328 .codec_name
= "snd-soc-dummy",
329 .codec_dai_name
= "snd-soc-dummy-dai",
332 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
334 .ops
= &broxton_da7219_fe_ops
,
336 [BXT_DPCM_AUDIO_REF_CP
] =
338 .name
= "Bxt Audio Reference cap",
339 .stream_name
= "Refcap",
340 .cpu_dai_name
= "Reference Pin",
341 .codec_name
= "snd-soc-dummy",
342 .codec_dai_name
= "snd-soc-dummy-dai",
343 .platform_name
= "0000:00:0e.0",
349 .ops
= &broxton_refcap_ops
,
351 [BXT_DPCM_AUDIO_DMIC_CP
]
353 .name
= "Bxt Audio DMIC cap",
354 .stream_name
= "dmiccap",
355 .cpu_dai_name
= "DMIC Pin",
356 .codec_name
= "snd-soc-dummy",
357 .codec_dai_name
= "snd-soc-dummy-dai",
358 .platform_name
= "0000:00:0e.0",
363 .ops
= &broxton_dmic_ops
,
365 [BXT_DPCM_AUDIO_HDMI1_PB
] =
367 .name
= "Bxt HDMI Port1",
368 .stream_name
= "Hdmi1",
369 .cpu_dai_name
= "HDMI1 Pin",
370 .codec_name
= "snd-soc-dummy",
371 .codec_dai_name
= "snd-soc-dummy-dai",
372 .platform_name
= "0000:00:0e.0",
378 [BXT_DPCM_AUDIO_HDMI2_PB
] =
380 .name
= "Bxt HDMI Port2",
381 .stream_name
= "Hdmi2",
382 .cpu_dai_name
= "HDMI2 Pin",
383 .codec_name
= "snd-soc-dummy",
384 .codec_dai_name
= "snd-soc-dummy-dai",
385 .platform_name
= "0000:00:0e.0",
391 [BXT_DPCM_AUDIO_HDMI3_PB
] =
393 .name
= "Bxt HDMI Port3",
394 .stream_name
= "Hdmi3",
395 .cpu_dai_name
= "HDMI3 Pin",
396 .codec_name
= "snd-soc-dummy",
397 .codec_dai_name
= "snd-soc-dummy-dai",
398 .platform_name
= "0000:00:0e.0",
404 /* Back End DAI links */
407 .name
= "SSP5-Codec",
409 .cpu_dai_name
= "SSP5 Pin",
410 .platform_name
= "0000:00:0e.0",
412 .codec_name
= "MX98357A:00",
413 .codec_dai_name
= BXT_MAXIM_CODEC_DAI
,
414 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
415 SND_SOC_DAIFMT_NB_NF
|
416 SND_SOC_DAIFMT_CBS_CFS
,
417 .ignore_pmdown_time
= 1,
418 .be_hw_params_fixup
= broxton_ssp_fixup
,
423 .name
= "SSP1-Codec",
425 .cpu_dai_name
= "SSP1 Pin",
426 .platform_name
= "0000:00:0e.0",
428 .codec_name
= "i2c-DLGS7219:00",
429 .codec_dai_name
= BXT_DIALOG_CODEC_DAI
,
430 .init
= broxton_da7219_codec_init
,
431 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
432 SND_SOC_DAIFMT_CBS_CFS
,
433 .ignore_pmdown_time
= 1,
434 .be_hw_params_fixup
= broxton_ssp_fixup
,
435 .ops
= &broxton_da7219_ops
,
442 .cpu_dai_name
= "DMIC01 Pin",
443 .codec_name
= "dmic-codec",
444 .codec_dai_name
= "dmic-hifi",
445 .platform_name
= "0000:00:0e.0",
447 .be_hw_params_fixup
= broxton_dmic_fixup
,
454 .cpu_dai_name
= "iDisp1 Pin",
455 .codec_name
= "ehdaudio0D2",
456 .codec_dai_name
= "intel-hdmi-hifi1",
457 .platform_name
= "0000:00:0e.0",
458 .init
= broxton_hdmi_init
,
465 .cpu_dai_name
= "iDisp2 Pin",
466 .codec_name
= "ehdaudio0D2",
467 .codec_dai_name
= "intel-hdmi-hifi2",
468 .platform_name
= "0000:00:0e.0",
469 .init
= broxton_hdmi_init
,
476 .cpu_dai_name
= "iDisp3 Pin",
477 .codec_name
= "ehdaudio0D2",
478 .codec_dai_name
= "intel-hdmi-hifi3",
479 .platform_name
= "0000:00:0e.0",
480 .init
= broxton_hdmi_init
,
486 /* broxton audio machine driver for SPT + da7219 */
487 static struct snd_soc_card broxton_audio_card
= {
488 .name
= "bxtda7219max",
489 .owner
= THIS_MODULE
,
490 .dai_link
= broxton_dais
,
491 .num_links
= ARRAY_SIZE(broxton_dais
),
492 .controls
= broxton_controls
,
493 .num_controls
= ARRAY_SIZE(broxton_controls
),
494 .dapm_widgets
= broxton_widgets
,
495 .num_dapm_widgets
= ARRAY_SIZE(broxton_widgets
),
496 .dapm_routes
= broxton_map
,
497 .num_dapm_routes
= ARRAY_SIZE(broxton_map
),
498 .fully_routed
= true,
501 static int broxton_audio_probe(struct platform_device
*pdev
)
503 broxton_audio_card
.dev
= &pdev
->dev
;
504 return devm_snd_soc_register_card(&pdev
->dev
, &broxton_audio_card
);
507 static struct platform_driver broxton_audio
= {
508 .probe
= broxton_audio_probe
,
510 .name
= "bxt_da7219_max98357a_i2s",
511 .pm
= &snd_soc_pm_ops
,
514 module_platform_driver(broxton_audio
)
516 /* Module information */
517 MODULE_DESCRIPTION("Audio Machine driver-DA7219 & MAX98357A in I2S mode");
518 MODULE_AUTHOR("Sathyanarayana Nujella <sathyanarayana.nujella@intel.com>");
519 MODULE_AUTHOR("Rohit Ainapure <rohit.m.ainapure@intel.com>");
520 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
521 MODULE_AUTHOR("Conrad Cooke <conrad.cooke@intel.com>");
522 MODULE_LICENSE("GPL v2");
523 MODULE_ALIAS("platform:bxt_da7219_max98357a_i2s");