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
;
38 BXT_DPCM_AUDIO_PB
= 0,
40 BXT_DPCM_AUDIO_REF_CP
,
41 BXT_DPCM_AUDIO_DMIC_CP
,
42 BXT_DPCM_AUDIO_HDMI1_PB
,
43 BXT_DPCM_AUDIO_HDMI2_PB
,
44 BXT_DPCM_AUDIO_HDMI3_PB
,
47 static const struct snd_kcontrol_new broxton_controls
[] = {
48 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
49 SOC_DAPM_PIN_SWITCH("Headset Mic"),
50 SOC_DAPM_PIN_SWITCH("Spk"),
53 static const struct snd_soc_dapm_widget broxton_widgets
[] = {
54 SND_SOC_DAPM_HP("Headphone Jack", NULL
),
55 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
56 SND_SOC_DAPM_SPK("Spk", NULL
),
57 SND_SOC_DAPM_MIC("SoC DMIC", NULL
),
58 SND_SOC_DAPM_SPK("HDMI1", NULL
),
59 SND_SOC_DAPM_SPK("HDMI2", NULL
),
60 SND_SOC_DAPM_SPK("HDMI3", NULL
),
63 static const struct snd_soc_dapm_route broxton_map
[] = {
64 /* HP jack connectors - unknown if we have jack detection */
65 {"Headphone Jack", NULL
, "HPL"},
66 {"Headphone Jack", NULL
, "HPR"},
69 {"Spk", NULL
, "Speaker"},
72 {"MIC", NULL
, "Headset Mic"},
75 {"DMic", NULL
, "SoC DMIC"},
77 /* CODEC BE connections */
78 {"HiFi Playback", NULL
, "ssp5 Tx"},
79 {"ssp5 Tx", NULL
, "codec0_out"},
81 {"Playback", NULL
, "ssp1 Tx"},
82 {"ssp1 Tx", NULL
, "codec1_out"},
84 {"codec0_in", NULL
, "ssp1 Rx"},
85 {"ssp1 Rx", NULL
, "Capture"},
87 {"HDMI1", NULL
, "hif5 Output"},
88 {"HDMI2", NULL
, "hif6 Output"},
89 {"HDMI3", NULL
, "hif7 Output"},
91 {"hifi3", NULL
, "iDisp3 Tx"},
92 {"iDisp3 Tx", NULL
, "iDisp3_out"},
93 {"hifi2", NULL
, "iDisp2 Tx"},
94 {"iDisp2 Tx", NULL
, "iDisp2_out"},
95 {"hifi1", NULL
, "iDisp1 Tx"},
96 {"iDisp1 Tx", NULL
, "iDisp1_out"},
99 {"dmic01_hifi", NULL
, "DMIC01 Rx"},
100 {"DMIC01 Rx", NULL
, "DMIC AIF"},
103 static int broxton_ssp_fixup(struct snd_soc_pcm_runtime
*rtd
,
104 struct snd_pcm_hw_params
*params
)
106 struct snd_interval
*rate
= hw_param_interval(params
,
107 SNDRV_PCM_HW_PARAM_RATE
);
108 struct snd_interval
*channels
= hw_param_interval(params
,
109 SNDRV_PCM_HW_PARAM_CHANNELS
);
110 struct snd_mask
*fmt
= hw_param_mask(params
, SNDRV_PCM_HW_PARAM_FORMAT
);
112 /* The ADSP will convert the FE rate to 48k, stereo */
113 rate
->min
= rate
->max
= 48000;
114 channels
->min
= channels
->max
= DUAL_CHANNEL
;
116 /* set SSP to 24 bit */
118 snd_mask_set(fmt
, SNDRV_PCM_FORMAT_S24_LE
);
123 static int broxton_da7219_codec_init(struct snd_soc_pcm_runtime
*rtd
)
126 struct snd_soc_codec
*codec
= rtd
->codec
;
129 * Headset buttons map to the google Reference headset.
130 * These can be configured by userspace.
132 ret
= snd_soc_card_jack_new(rtd
->card
, "Headset Jack",
133 SND_JACK_HEADSET
| SND_JACK_BTN_0
| SND_JACK_BTN_1
|
134 SND_JACK_BTN_2
| SND_JACK_BTN_3
| SND_JACK_LINEOUT
,
135 &broxton_headset
, NULL
, 0);
137 dev_err(rtd
->dev
, "Headset Jack creation failed: %d\n", ret
);
141 da7219_aad_jack_det(codec
, &broxton_headset
);
143 snd_soc_dapm_ignore_suspend(&rtd
->card
->dapm
, "SoC DMIC");
148 static int broxton_hdmi_init(struct snd_soc_pcm_runtime
*rtd
)
150 struct snd_soc_dai
*dai
= rtd
->codec_dai
;
152 return hdac_hdmi_jack_init(dai
, BXT_DPCM_AUDIO_HDMI1_PB
+ dai
->id
);
155 static int broxton_da7219_fe_init(struct snd_soc_pcm_runtime
*rtd
)
157 struct snd_soc_dapm_context
*dapm
;
158 struct snd_soc_component
*component
= rtd
->cpu_dai
->component
;
160 dapm
= snd_soc_component_get_dapm(component
);
161 snd_soc_dapm_ignore_suspend(dapm
, "Reference Capture");
166 static unsigned int rates
[] = {
170 static struct snd_pcm_hw_constraint_list constraints_rates
= {
171 .count
= ARRAY_SIZE(rates
),
176 static unsigned int channels
[] = {
180 static struct snd_pcm_hw_constraint_list constraints_channels
= {
181 .count
= ARRAY_SIZE(channels
),
186 static unsigned int channels_quad
[] = {
190 static struct snd_pcm_hw_constraint_list constraints_channels_quad
= {
191 .count
= ARRAY_SIZE(channels_quad
),
192 .list
= channels_quad
,
196 static int bxt_fe_startup(struct snd_pcm_substream
*substream
)
198 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
201 * On this platform for PCM device we support,
207 runtime
->hw
.channels_max
= DUAL_CHANNEL
;
208 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
209 &constraints_channels
);
211 runtime
->hw
.formats
= SNDRV_PCM_FMTBIT_S16_LE
;
212 snd_pcm_hw_constraint_msbits(runtime
, 0, 16, 16);
214 snd_pcm_hw_constraint_list(runtime
, 0,
215 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
220 static const struct snd_soc_ops broxton_da7219_fe_ops
= {
221 .startup
= bxt_fe_startup
,
224 static int broxton_da7219_hw_params(struct snd_pcm_substream
*substream
,
225 struct snd_pcm_hw_params
*params
)
227 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
228 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
231 ret
= snd_soc_dai_set_sysclk(codec_dai
,
232 DA7219_CLKSRC_MCLK
, 19200000, SND_SOC_CLOCK_IN
);
234 dev_err(codec_dai
->dev
, "can't set codec sysclk configuration\n");
236 ret
= snd_soc_dai_set_pll(codec_dai
, 0,
237 DA7219_SYSCLK_PLL_SRM
, 0, DA7219_PLL_FREQ_OUT_98304
);
239 dev_err(codec_dai
->dev
, "failed to start PLL: %d\n", ret
);
246 static int broxton_da7219_hw_free(struct snd_pcm_substream
*substream
)
248 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
249 struct snd_soc_dai
*codec_dai
= rtd
->codec_dai
;
252 ret
= snd_soc_dai_set_pll(codec_dai
, 0,
253 DA7219_SYSCLK_MCLK
, 0, 0);
255 dev_err(codec_dai
->dev
, "failed to stop PLL: %d\n", ret
);
262 static const struct snd_soc_ops broxton_da7219_ops
= {
263 .hw_params
= broxton_da7219_hw_params
,
264 .hw_free
= broxton_da7219_hw_free
,
267 static int broxton_dmic_fixup(struct snd_soc_pcm_runtime
*rtd
,
268 struct snd_pcm_hw_params
*params
)
270 struct snd_interval
*channels
= hw_param_interval(params
,
271 SNDRV_PCM_HW_PARAM_CHANNELS
);
272 if (params_channels(params
) == 2)
273 channels
->min
= channels
->max
= 2;
275 channels
->min
= channels
->max
= 4;
280 static int broxton_dmic_startup(struct snd_pcm_substream
*substream
)
282 struct snd_pcm_runtime
*runtime
= substream
->runtime
;
284 runtime
->hw
.channels_min
= runtime
->hw
.channels_max
= QUAD_CHANNEL
;
285 snd_pcm_hw_constraint_list(runtime
, 0, SNDRV_PCM_HW_PARAM_CHANNELS
,
286 &constraints_channels_quad
);
288 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
289 SNDRV_PCM_HW_PARAM_RATE
, &constraints_rates
);
292 static const struct snd_soc_ops broxton_dmic_ops
= {
293 .startup
= broxton_dmic_startup
,
296 static const unsigned int rates_16000
[] = {
300 static const struct snd_pcm_hw_constraint_list constraints_16000
= {
301 .count
= ARRAY_SIZE(rates_16000
),
305 static int broxton_refcap_startup(struct snd_pcm_substream
*substream
)
307 return snd_pcm_hw_constraint_list(substream
->runtime
, 0,
308 SNDRV_PCM_HW_PARAM_RATE
,
312 static const struct snd_soc_ops broxton_refcap_ops
= {
313 .startup
= broxton_refcap_startup
,
316 /* broxton digital audio interface glue - connects codec <--> CPU */
317 static struct snd_soc_dai_link broxton_dais
[] = {
318 /* Front End DAI links */
319 [BXT_DPCM_AUDIO_PB
] =
321 .name
= "Bxt Audio Port",
322 .stream_name
= "Audio",
323 .cpu_dai_name
= "System Pin",
324 .platform_name
= "0000:00:0e.0",
326 .codec_name
= "snd-soc-dummy",
327 .codec_dai_name
= "snd-soc-dummy-dai",
329 .init
= broxton_da7219_fe_init
,
331 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
333 .ops
= &broxton_da7219_fe_ops
,
335 [BXT_DPCM_AUDIO_CP
] =
337 .name
= "Bxt Audio Capture Port",
338 .stream_name
= "Audio Record",
339 .cpu_dai_name
= "System Pin",
340 .platform_name
= "0000:00:0e.0",
342 .codec_name
= "snd-soc-dummy",
343 .codec_dai_name
= "snd-soc-dummy-dai",
346 SND_SOC_DPCM_TRIGGER_POST
, SND_SOC_DPCM_TRIGGER_POST
},
348 .ops
= &broxton_da7219_fe_ops
,
350 [BXT_DPCM_AUDIO_REF_CP
] =
352 .name
= "Bxt Audio Reference cap",
353 .stream_name
= "Refcap",
354 .cpu_dai_name
= "Reference Pin",
355 .codec_name
= "snd-soc-dummy",
356 .codec_dai_name
= "snd-soc-dummy-dai",
357 .platform_name
= "0000:00:0e.0",
363 .ops
= &broxton_refcap_ops
,
365 [BXT_DPCM_AUDIO_DMIC_CP
] =
367 .name
= "Bxt Audio DMIC cap",
368 .stream_name
= "dmiccap",
369 .cpu_dai_name
= "DMIC Pin",
370 .codec_name
= "snd-soc-dummy",
371 .codec_dai_name
= "snd-soc-dummy-dai",
372 .platform_name
= "0000:00:0e.0",
377 .ops
= &broxton_dmic_ops
,
379 [BXT_DPCM_AUDIO_HDMI1_PB
] =
381 .name
= "Bxt HDMI Port1",
382 .stream_name
= "Hdmi1",
383 .cpu_dai_name
= "HDMI1 Pin",
384 .codec_name
= "snd-soc-dummy",
385 .codec_dai_name
= "snd-soc-dummy-dai",
386 .platform_name
= "0000:00:0e.0",
392 [BXT_DPCM_AUDIO_HDMI2_PB
] =
394 .name
= "Bxt HDMI Port2",
395 .stream_name
= "Hdmi2",
396 .cpu_dai_name
= "HDMI2 Pin",
397 .codec_name
= "snd-soc-dummy",
398 .codec_dai_name
= "snd-soc-dummy-dai",
399 .platform_name
= "0000:00:0e.0",
405 [BXT_DPCM_AUDIO_HDMI3_PB
] =
407 .name
= "Bxt HDMI Port3",
408 .stream_name
= "Hdmi3",
409 .cpu_dai_name
= "HDMI3 Pin",
410 .codec_name
= "snd-soc-dummy",
411 .codec_dai_name
= "snd-soc-dummy-dai",
412 .platform_name
= "0000:00:0e.0",
418 /* Back End DAI links */
421 .name
= "SSP5-Codec",
423 .cpu_dai_name
= "SSP5 Pin",
424 .platform_name
= "0000:00:0e.0",
426 .codec_name
= "MX98357A:00",
427 .codec_dai_name
= BXT_MAXIM_CODEC_DAI
,
428 .dai_fmt
= SND_SOC_DAIFMT_I2S
|
429 SND_SOC_DAIFMT_NB_NF
|
430 SND_SOC_DAIFMT_CBS_CFS
,
431 .ignore_pmdown_time
= 1,
432 .be_hw_params_fixup
= broxton_ssp_fixup
,
437 .name
= "SSP1-Codec",
439 .cpu_dai_name
= "SSP1 Pin",
440 .platform_name
= "0000:00:0e.0",
442 .codec_name
= "i2c-DLGS7219:00",
443 .codec_dai_name
= BXT_DIALOG_CODEC_DAI
,
444 .init
= broxton_da7219_codec_init
,
445 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
|
446 SND_SOC_DAIFMT_CBS_CFS
,
447 .ignore_pmdown_time
= 1,
448 .be_hw_params_fixup
= broxton_ssp_fixup
,
449 .ops
= &broxton_da7219_ops
,
456 .cpu_dai_name
= "DMIC01 Pin",
457 .codec_name
= "dmic-codec",
458 .codec_dai_name
= "dmic-hifi",
459 .platform_name
= "0000:00:0e.0",
461 .be_hw_params_fixup
= broxton_dmic_fixup
,
468 .cpu_dai_name
= "iDisp1 Pin",
469 .codec_name
= "ehdaudio0D2",
470 .codec_dai_name
= "intel-hdmi-hifi1",
471 .platform_name
= "0000:00:0e.0",
472 .init
= broxton_hdmi_init
,
479 .cpu_dai_name
= "iDisp2 Pin",
480 .codec_name
= "ehdaudio0D2",
481 .codec_dai_name
= "intel-hdmi-hifi2",
482 .platform_name
= "0000:00:0e.0",
483 .init
= broxton_hdmi_init
,
490 .cpu_dai_name
= "iDisp3 Pin",
491 .codec_name
= "ehdaudio0D2",
492 .codec_dai_name
= "intel-hdmi-hifi3",
493 .platform_name
= "0000:00:0e.0",
494 .init
= broxton_hdmi_init
,
500 /* broxton audio machine driver for SPT + da7219 */
501 static struct snd_soc_card broxton_audio_card
= {
502 .name
= "bxtda7219max",
503 .owner
= THIS_MODULE
,
504 .dai_link
= broxton_dais
,
505 .num_links
= ARRAY_SIZE(broxton_dais
),
506 .controls
= broxton_controls
,
507 .num_controls
= ARRAY_SIZE(broxton_controls
),
508 .dapm_widgets
= broxton_widgets
,
509 .num_dapm_widgets
= ARRAY_SIZE(broxton_widgets
),
510 .dapm_routes
= broxton_map
,
511 .num_dapm_routes
= ARRAY_SIZE(broxton_map
),
512 .fully_routed
= true,
515 static int broxton_audio_probe(struct platform_device
*pdev
)
517 broxton_audio_card
.dev
= &pdev
->dev
;
518 return devm_snd_soc_register_card(&pdev
->dev
, &broxton_audio_card
);
521 static struct platform_driver broxton_audio
= {
522 .probe
= broxton_audio_probe
,
524 .name
= "bxt_da7219_max98357a_i2s",
525 .pm
= &snd_soc_pm_ops
,
528 module_platform_driver(broxton_audio
)
530 /* Module information */
531 MODULE_DESCRIPTION("Audio Machine driver-DA7219 & MAX98357A in I2S mode");
532 MODULE_AUTHOR("Sathyanarayana Nujella <sathyanarayana.nujella@intel.com>");
533 MODULE_AUTHOR("Rohit Ainapure <rohit.m.ainapure@intel.com>");
534 MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
535 MODULE_AUTHOR("Conrad Cooke <conrad.cooke@intel.com>");
536 MODULE_LICENSE("GPL v2");
537 MODULE_ALIAS("platform:bxt_da7219_max98357a_i2s");