blob: 10eb5cbf57e44834f78f7bafdc1a9e9d70da655a [file] [log] [blame]
Ramesh Babu76016322016-05-10 22:02:06 +05301/*
2 * Intel Broxton-P I2S Machine Driver
3 *
4 * Copyright (C) 2014-2016, Intel Corporation. All rights reserved.
5 *
6 * Modified from:
7 * Intel Skylake I2S Machine driver
8 *
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.
12 *
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.
17 */
18
19#include <linux/module.h>
20#include <linux/platform_device.h>
21#include <sound/core.h>
22#include <sound/pcm.h>
23#include <sound/soc.h>
24#include <sound/jack.h>
25#include <sound/pcm_params.h>
26#include "../../codecs/hdac_hdmi.h"
27#include "../../codecs/rt298.h"
28
29static struct snd_soc_jack broxton_headset;
30/* Headset jack detection DAPM pins */
31
32enum {
33 BXT_DPCM_AUDIO_PB = 0,
34 BXT_DPCM_AUDIO_CP,
35 BXT_DPCM_AUDIO_REF_CP,
Senthilnathan Veppurbfcdc6d2016-06-13 17:58:58 +053036 BXT_DPCM_AUDIO_DMIC_CP,
Ramesh Babu76016322016-05-10 22:02:06 +053037 BXT_DPCM_AUDIO_HDMI1_PB,
38 BXT_DPCM_AUDIO_HDMI2_PB,
39 BXT_DPCM_AUDIO_HDMI3_PB,
40};
41
42static struct snd_soc_jack_pin broxton_headset_pins[] = {
43 {
44 .pin = "Mic Jack",
45 .mask = SND_JACK_MICROPHONE,
46 },
47 {
48 .pin = "Headphone Jack",
49 .mask = SND_JACK_HEADPHONE,
50 },
51};
52
53static const struct snd_kcontrol_new broxton_controls[] = {
54 SOC_DAPM_PIN_SWITCH("Speaker"),
55 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
56 SOC_DAPM_PIN_SWITCH("Mic Jack"),
57};
58
59static const struct snd_soc_dapm_widget broxton_widgets[] = {
60 SND_SOC_DAPM_HP("Headphone Jack", NULL),
61 SND_SOC_DAPM_SPK("Speaker", NULL),
62 SND_SOC_DAPM_MIC("Mic Jack", NULL),
63 SND_SOC_DAPM_MIC("DMIC2", NULL),
64 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
65 SND_SOC_DAPM_SPK("HDMI1", NULL),
66 SND_SOC_DAPM_SPK("HDMI2", NULL),
67 SND_SOC_DAPM_SPK("HDMI3", NULL),
68};
69
70static const struct snd_soc_dapm_route broxton_rt298_map[] = {
71 /* speaker */
72 {"Speaker", NULL, "SPOR"},
73 {"Speaker", NULL, "SPOL"},
74
75 /* HP jack connectors - unknown if we have jack detect */
76 {"Headphone Jack", NULL, "HPO Pin"},
77
78 /* other jacks */
79 {"MIC1", NULL, "Mic Jack"},
80
81 /* digital mics */
82 {"DMIC1 Pin", NULL, "DMIC2"},
83 {"DMic", NULL, "SoC DMIC"},
84
85 {"HDMI1", NULL, "hif5 Output"},
86 {"HDMI2", NULL, "hif6 Output"},
87 {"HDMI3", NULL, "hif7 Output"},
88
89 /* CODEC BE connections */
90 { "AIF1 Playback", NULL, "ssp5 Tx"},
91 { "ssp5 Tx", NULL, "codec0_out"},
Senthilnathan Veppurbfcdc6d2016-06-13 17:58:58 +053092 { "ssp5 Tx", NULL, "codec1_out"},
Ramesh Babu76016322016-05-10 22:02:06 +053093
94 { "codec0_in", NULL, "ssp5 Rx" },
95 { "ssp5 Rx", NULL, "AIF1 Capture" },
96
97 { "dmic01_hifi", NULL, "DMIC01 Rx" },
98 { "DMIC01 Rx", NULL, "Capture" },
99
100 { "hifi3", NULL, "iDisp3 Tx"},
101 { "iDisp3 Tx", NULL, "iDisp3_out"},
102 { "hifi2", NULL, "iDisp2 Tx"},
103 { "iDisp2 Tx", NULL, "iDisp2_out"},
104 { "hifi1", NULL, "iDisp1 Tx"},
105 { "iDisp1 Tx", NULL, "iDisp1_out"},
106
107};
108
109static int broxton_rt298_codec_init(struct snd_soc_pcm_runtime *rtd)
110{
111 struct snd_soc_codec *codec = rtd->codec;
112 int ret = 0;
113
114 ret = snd_soc_card_jack_new(rtd->card, "Headset",
115 SND_JACK_HEADSET | SND_JACK_BTN_0,
116 &broxton_headset,
117 broxton_headset_pins, ARRAY_SIZE(broxton_headset_pins));
118
119 if (ret)
120 return ret;
121
122 rt298_mic_detect(codec, &broxton_headset);
123 return 0;
124}
125
126static int broxton_hdmi_init(struct snd_soc_pcm_runtime *rtd)
127{
128 struct snd_soc_dai *dai = rtd->codec_dai;
129
130 return hdac_hdmi_jack_init(dai, BXT_DPCM_AUDIO_HDMI1_PB + dai->id);
131}
132
133static int broxton_ssp5_fixup(struct snd_soc_pcm_runtime *rtd,
134 struct snd_pcm_hw_params *params)
135{
136 struct snd_interval *rate = hw_param_interval(params,
137 SNDRV_PCM_HW_PARAM_RATE);
138 struct snd_interval *channels = hw_param_interval(params,
139 SNDRV_PCM_HW_PARAM_CHANNELS);
140 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
141
142 /* The ADSP will covert the FE rate to 48k, stereo */
143 rate->min = rate->max = 48000;
144 channels->min = channels->max = 2;
145
146 /* set SSP5 to 24 bit */
147 snd_mask_none(fmt);
148 snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE);
149
150 return 0;
151}
152
153static int broxton_rt298_hw_params(struct snd_pcm_substream *substream,
154 struct snd_pcm_hw_params *params)
155{
156 struct snd_soc_pcm_runtime *rtd = substream->private_data;
157 struct snd_soc_dai *codec_dai = rtd->codec_dai;
158 int ret;
159
160 ret = snd_soc_dai_set_sysclk(codec_dai, RT298_SCLK_S_PLL,
161 19200000, SND_SOC_CLOCK_IN);
162 if (ret < 0) {
163 dev_err(rtd->dev, "can't set codec sysclk configuration\n");
164 return ret;
165 }
166
167 return ret;
168}
169
170static struct snd_soc_ops broxton_rt298_ops = {
171 .hw_params = broxton_rt298_hw_params,
172};
173
Senthilnathan Veppurbfcdc6d2016-06-13 17:58:58 +0530174static unsigned int rates[] = {
175 48000,
176};
177
178static struct snd_pcm_hw_constraint_list constraints_rates = {
179 .count = ARRAY_SIZE(rates),
180 .list = rates,
181 .mask = 0,
182};
183
184static int broxton_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
185 struct snd_pcm_hw_params *params)
186{
187 struct snd_interval *channels = hw_param_interval(params,
188 SNDRV_PCM_HW_PARAM_CHANNELS);
189 if (params_channels(params) == 2)
190 channels->min = channels->max = 2;
191 else
192 channels->min = channels->max = 4;
193
194 return 0;
195}
196
197static unsigned int channels_dmic[] = {
198 2, 4,
199};
200
201static struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
202 .count = ARRAY_SIZE(channels_dmic),
203 .list = channels_dmic,
204 .mask = 0,
205};
206
207static int broxton_dmic_startup(struct snd_pcm_substream *substream)
208{
209 struct snd_pcm_runtime *runtime = substream->runtime;
210
211 runtime->hw.channels_max = 4;
212 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
213 &constraints_dmic_channels);
214
215 return snd_pcm_hw_constraint_list(substream->runtime, 0,
216 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
217}
218
219static struct snd_soc_ops broxton_dmic_ops = {
220 .startup = broxton_dmic_startup,
221};
222
Senthilnathan Veppur4cdf33f2016-06-13 17:58:59 +0530223static unsigned int channels[] = {
224 2,
225};
226
227static struct snd_pcm_hw_constraint_list constraints_channels = {
228 .count = ARRAY_SIZE(channels),
229 .list = channels,
230 .mask = 0,
231};
232
233static int bxt_fe_startup(struct snd_pcm_substream *substream)
234{
235 struct snd_pcm_runtime *runtime = substream->runtime;
236
237 /*
238 * on this platform for PCM device we support:
239 * 48Khz
240 * stereo
241 */
242
243 runtime->hw.channels_max = 2;
244 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
245 &constraints_channels);
246
247 snd_pcm_hw_constraint_list(runtime, 0,
248 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
249
250 return 0;
251}
252
253static const struct snd_soc_ops broxton_rt286_fe_ops = {
254 .startup = bxt_fe_startup,
255};
256
Ramesh Babu76016322016-05-10 22:02:06 +0530257/* broxton digital audio interface glue - connects codec <--> CPU */
258static struct snd_soc_dai_link broxton_rt298_dais[] = {
259 /* Front End DAI links */
260 [BXT_DPCM_AUDIO_PB]
261 {
262 .name = "Bxt Audio Port",
263 .stream_name = "Audio",
264 .cpu_dai_name = "System Pin",
265 .platform_name = "0000:00:0e.0",
266 .nonatomic = 1,
267 .dynamic = 1,
268 .codec_name = "snd-soc-dummy",
269 .codec_dai_name = "snd-soc-dummy-dai",
270 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
271 .dpcm_playback = 1,
Senthilnathan Veppur4cdf33f2016-06-13 17:58:59 +0530272 .ops = &broxton_rt286_fe_ops,
Ramesh Babu76016322016-05-10 22:02:06 +0530273 },
274 [BXT_DPCM_AUDIO_CP]
275 {
276 .name = "Bxt Audio Capture Port",
277 .stream_name = "Audio Record",
278 .cpu_dai_name = "System Pin",
279 .platform_name = "0000:00:0e.0",
280 .nonatomic = 1,
281 .dynamic = 1,
282 .codec_name = "snd-soc-dummy",
283 .codec_dai_name = "snd-soc-dummy-dai",
284 .trigger = {SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
285 .dpcm_capture = 1,
Senthilnathan Veppur4cdf33f2016-06-13 17:58:59 +0530286 .ops = &broxton_rt286_fe_ops,
Ramesh Babu76016322016-05-10 22:02:06 +0530287 },
288 [BXT_DPCM_AUDIO_REF_CP]
289 {
290 .name = "Bxt Audio Reference cap",
291 .stream_name = "refcap",
292 .cpu_dai_name = "Reference Pin",
293 .codec_name = "snd-soc-dummy",
294 .codec_dai_name = "snd-soc-dummy-dai",
295 .platform_name = "0000:00:0e.0",
296 .init = NULL,
297 .dpcm_capture = 1,
298 .nonatomic = 1,
299 .dynamic = 1,
300 },
Senthilnathan Veppurbfcdc6d2016-06-13 17:58:58 +0530301 [BXT_DPCM_AUDIO_DMIC_CP]
302 {
303 .name = "Bxt Audio DMIC cap",
304 .stream_name = "dmiccap",
305 .cpu_dai_name = "DMIC Pin",
306 .codec_name = "snd-soc-dummy",
307 .codec_dai_name = "snd-soc-dummy-dai",
308 .platform_name = "0000:00:0e.0",
309 .init = NULL,
310 .dpcm_capture = 1,
311 .nonatomic = 1,
312 .dynamic = 1,
313 .ops = &broxton_dmic_ops,
314 },
Ramesh Babu76016322016-05-10 22:02:06 +0530315 [BXT_DPCM_AUDIO_HDMI1_PB]
316 {
317 .name = "Bxt HDMI Port1",
318 .stream_name = "Hdmi1",
319 .cpu_dai_name = "HDMI1 Pin",
320 .codec_name = "snd-soc-dummy",
321 .codec_dai_name = "snd-soc-dummy-dai",
322 .platform_name = "0000:00:0e.0",
323 .dpcm_playback = 1,
324 .init = NULL,
325 .nonatomic = 1,
326 .dynamic = 1,
327 },
328 [BXT_DPCM_AUDIO_HDMI2_PB]
329 {
330 .name = "Bxt HDMI Port2",
331 .stream_name = "Hdmi2",
332 .cpu_dai_name = "HDMI2 Pin",
333 .codec_name = "snd-soc-dummy",
334 .codec_dai_name = "snd-soc-dummy-dai",
335 .platform_name = "0000:00:0e.0",
336 .dpcm_playback = 1,
337 .init = NULL,
338 .nonatomic = 1,
339 .dynamic = 1,
340 },
341 [BXT_DPCM_AUDIO_HDMI3_PB]
342 {
343 .name = "Bxt HDMI Port3",
344 .stream_name = "Hdmi3",
345 .cpu_dai_name = "HDMI3 Pin",
346 .codec_name = "snd-soc-dummy",
347 .codec_dai_name = "snd-soc-dummy-dai",
348 .platform_name = "0000:00:0e.0",
349 .dpcm_playback = 1,
350 .init = NULL,
351 .nonatomic = 1,
352 .dynamic = 1,
353 },
354 /* Back End DAI links */
355 {
356 /* SSP5 - Codec */
357 .name = "SSP5-Codec",
Stephen Rothwellbfb78022016-05-11 11:07:02 +1000358 .id = 0,
Ramesh Babu76016322016-05-10 22:02:06 +0530359 .cpu_dai_name = "SSP5 Pin",
360 .platform_name = "0000:00:0e.0",
361 .no_pcm = 1,
362 .codec_name = "i2c-INT343A:00",
363 .codec_dai_name = "rt298-aif1",
364 .init = broxton_rt298_codec_init,
365 .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_NB_NF |
366 SND_SOC_DAIFMT_CBS_CFS,
367 .ignore_pmdown_time = 1,
368 .be_hw_params_fixup = broxton_ssp5_fixup,
369 .ops = &broxton_rt298_ops,
370 .dpcm_playback = 1,
371 .dpcm_capture = 1,
372 },
373 {
374 .name = "dmic01",
Stephen Rothwellbfb78022016-05-11 11:07:02 +1000375 .id = 1,
Ramesh Babu76016322016-05-10 22:02:06 +0530376 .cpu_dai_name = "DMIC01 Pin",
377 .codec_name = "dmic-codec",
378 .codec_dai_name = "dmic-hifi",
379 .platform_name = "0000:00:0e.0",
Senthilnathan Veppurbfcdc6d2016-06-13 17:58:58 +0530380 .be_hw_params_fixup = broxton_dmic_fixup,
Ramesh Babu76016322016-05-10 22:02:06 +0530381 .ignore_suspend = 1,
382 .dpcm_capture = 1,
383 .no_pcm = 1,
384 },
385 {
386 .name = "iDisp1",
Stephen Rothwellbfb78022016-05-11 11:07:02 +1000387 .id = 3,
Ramesh Babu76016322016-05-10 22:02:06 +0530388 .cpu_dai_name = "iDisp1 Pin",
389 .codec_name = "ehdaudio0D2",
390 .codec_dai_name = "intel-hdmi-hifi1",
391 .platform_name = "0000:00:0e.0",
392 .init = broxton_hdmi_init,
393 .dpcm_playback = 1,
394 .no_pcm = 1,
395 },
396 {
397 .name = "iDisp2",
Stephen Rothwellbfb78022016-05-11 11:07:02 +1000398 .id = 4,
Ramesh Babu76016322016-05-10 22:02:06 +0530399 .cpu_dai_name = "iDisp2 Pin",
400 .codec_name = "ehdaudio0D2",
401 .codec_dai_name = "intel-hdmi-hifi2",
402 .platform_name = "0000:00:0e.0",
403 .init = broxton_hdmi_init,
404 .dpcm_playback = 1,
405 .no_pcm = 1,
406 },
407 {
408 .name = "iDisp3",
Stephen Rothwellbfb78022016-05-11 11:07:02 +1000409 .id = 5,
Ramesh Babu76016322016-05-10 22:02:06 +0530410 .cpu_dai_name = "iDisp3 Pin",
411 .codec_name = "ehdaudio0D2",
412 .codec_dai_name = "intel-hdmi-hifi3",
413 .platform_name = "0000:00:0e.0",
414 .init = broxton_hdmi_init,
415 .dpcm_playback = 1,
416 .no_pcm = 1,
417 },
418};
419
420/* broxton audio machine driver for SPT + RT298S */
421static struct snd_soc_card broxton_rt298 = {
422 .name = "broxton-rt298",
423 .owner = THIS_MODULE,
424 .dai_link = broxton_rt298_dais,
425 .num_links = ARRAY_SIZE(broxton_rt298_dais),
426 .controls = broxton_controls,
427 .num_controls = ARRAY_SIZE(broxton_controls),
428 .dapm_widgets = broxton_widgets,
429 .num_dapm_widgets = ARRAY_SIZE(broxton_widgets),
430 .dapm_routes = broxton_rt298_map,
431 .num_dapm_routes = ARRAY_SIZE(broxton_rt298_map),
432 .fully_routed = true,
433};
434
435static int broxton_audio_probe(struct platform_device *pdev)
436{
437 broxton_rt298.dev = &pdev->dev;
438
439 return devm_snd_soc_register_card(&pdev->dev, &broxton_rt298);
440}
441
442static struct platform_driver broxton_audio = {
443 .probe = broxton_audio_probe,
444 .driver = {
445 .name = "bxt_alc298s_i2s",
446 },
447};
448module_platform_driver(broxton_audio)
449
450/* Module information */
451MODULE_AUTHOR("Ramesh Babu <Ramesh.Babu@intel.com>");
452MODULE_AUTHOR("Senthilnathan Veppur <senthilnathanx.veppur@intel.com>");
453MODULE_DESCRIPTION("Intel SST Audio for Broxton");
454MODULE_LICENSE("GPL v2");
455MODULE_ALIAS("platform:bxt_alc298s_i2s");