blob: 01b8b140bb0874af87fa3ef98a4213bf7f6c74a5 [file] [log] [blame]
Harsha Priyaa86d5052015-11-05 22:53:07 +05301/*
2 * Intel Skylake I2S Machine Driver for NAU88L25+SSM4567
3 *
4 * Copyright (C) 2015, Intel Corporation. All rights reserved.
5 *
6 * Modified from:
7 * Intel Skylake I2S Machine Driver for NAU88L25 and SSM4567
8 *
9 * Copyright (C) 2015, Intel Corporation. All rights reserved.
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License version
13 * 2 as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 */
20
21#include <linux/module.h>
22#include <linux/platform_device.h>
23#include <sound/core.h>
24#include <sound/pcm.h>
25#include <sound/soc.h>
26#include <sound/jack.h>
27#include <sound/pcm_params.h>
28#include "../../codecs/nau8825.h"
Jeeja KPbc5f6ac2016-02-24 11:27:39 +053029#include "../../codecs/hdac_hdmi.h"
Yong Zhicfa12362016-05-31 10:22:48 -050030#include "../skylake/skl.h"
Harsha Priyaa86d5052015-11-05 22:53:07 +053031
32#define SKL_NUVOTON_CODEC_DAI "nau8825-hifi"
33#define SKL_SSM_CODEC_DAI "ssm4567-hifi"
Yong Zhicfa12362016-05-31 10:22:48 -050034#define DMIC_CH(p) p->list[p->count-1]
Harsha Priyaa86d5052015-11-05 22:53:07 +053035
36static struct snd_soc_jack skylake_headset;
37static struct snd_soc_card skylake_audio_card;
Yong Zhicfa12362016-05-31 10:22:48 -050038static const struct snd_pcm_hw_constraint_list *dmic_constraints;
Jeeja KP9e4278c2017-02-07 19:09:52 +053039static struct snd_soc_jack skylake_hdmi[3];
Harsha Priyaa86d5052015-11-05 22:53:07 +053040
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +053041struct skl_hdmi_pcm {
42 struct list_head head;
43 struct snd_soc_dai *codec_dai;
44 int device;
45};
46
47struct skl_nau88125_private {
48 struct list_head hdmi_pcm_list;
49};
Jeeja KPbc5f6ac2016-02-24 11:27:39 +053050enum {
51 SKL_DPCM_AUDIO_PB = 0,
52 SKL_DPCM_AUDIO_CP,
53 SKL_DPCM_AUDIO_REF_CP,
54 SKL_DPCM_AUDIO_DMIC_CP,
55 SKL_DPCM_AUDIO_HDMI1_PB,
56 SKL_DPCM_AUDIO_HDMI2_PB,
57 SKL_DPCM_AUDIO_HDMI3_PB,
58};
59
Harsha Priyaa86d5052015-11-05 22:53:07 +053060static inline struct snd_soc_dai *skl_get_codec_dai(struct snd_soc_card *card)
61{
Vinod Koul85af2a62015-11-20 22:34:41 +053062 struct snd_soc_pcm_runtime *rtd;
Harsha Priyaa86d5052015-11-05 22:53:07 +053063
Vinod Koul85af2a62015-11-20 22:34:41 +053064 list_for_each_entry(rtd, &card->rtd_list, list) {
Harsha Priyaa86d5052015-11-05 22:53:07 +053065
Harsha Priyaa86d5052015-11-05 22:53:07 +053066 if (!strncmp(rtd->codec_dai->name, SKL_NUVOTON_CODEC_DAI,
67 strlen(SKL_NUVOTON_CODEC_DAI)))
68 return rtd->codec_dai;
69 }
70
71 return NULL;
72}
73
74static const struct snd_kcontrol_new skylake_controls[] = {
75 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
76 SOC_DAPM_PIN_SWITCH("Headset Mic"),
77 SOC_DAPM_PIN_SWITCH("Left Speaker"),
78 SOC_DAPM_PIN_SWITCH("Right Speaker"),
79};
80
81static int platform_clock_control(struct snd_soc_dapm_widget *w,
82 struct snd_kcontrol *k, int event)
83{
84 struct snd_soc_dapm_context *dapm = w->dapm;
85 struct snd_soc_card *card = dapm->card;
86 struct snd_soc_dai *codec_dai;
87 int ret;
88
89 codec_dai = skl_get_codec_dai(card);
90 if (!codec_dai) {
91 dev_err(card->dev, "Codec dai not found\n");
92 return -EIO;
93 }
94
95 if (SND_SOC_DAPM_EVENT_ON(event)) {
96 ret = snd_soc_dai_set_sysclk(codec_dai,
97 NAU8825_CLK_MCLK, 24000000, SND_SOC_CLOCK_IN);
98 if (ret < 0) {
99 dev_err(card->dev, "set sysclk err = %d\n", ret);
100 return -EIO;
101 }
102 } else {
103 ret = snd_soc_dai_set_sysclk(codec_dai,
104 NAU8825_CLK_INTERNAL, 0, SND_SOC_CLOCK_IN);
105 if (ret < 0) {
106 dev_err(card->dev, "set sysclk err = %d\n", ret);
107 return -EIO;
108 }
109 }
110 return ret;
111}
112
113static const struct snd_soc_dapm_widget skylake_widgets[] = {
114 SND_SOC_DAPM_HP("Headphone Jack", NULL),
115 SND_SOC_DAPM_MIC("Headset Mic", NULL),
116 SND_SOC_DAPM_SPK("Left Speaker", NULL),
117 SND_SOC_DAPM_SPK("Right Speaker", NULL),
118 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
Jeeja KP8d136402017-02-06 12:09:16 +0530119 SND_SOC_DAPM_SPK("DP1", NULL),
120 SND_SOC_DAPM_SPK("DP2", NULL),
Harsha Priyaa86d5052015-11-05 22:53:07 +0530121 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
122 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
123 SND_SOC_DAPM_POST_PMD),
124};
125
126static const struct snd_soc_dapm_route skylake_map[] = {
127 /* HP jack connectors - unknown if we have jack detection */
128 {"Headphone Jack", NULL, "HPOL"},
129 {"Headphone Jack", NULL, "HPOR"},
130
131 /* speaker */
132 {"Left Speaker", NULL, "Left OUT"},
133 {"Right Speaker", NULL, "Right OUT"},
134
135 /* other jacks */
136 {"MIC", NULL, "Headset Mic"},
Fang, Yang A4c6ebc32015-12-11 11:29:09 -0800137 {"DMic", NULL, "SoC DMIC"},
Harsha Priyaa86d5052015-11-05 22:53:07 +0530138
139 /* CODEC BE connections */
140 { "Left Playback", NULL, "ssp0 Tx"},
141 { "Right Playback", NULL, "ssp0 Tx"},
142 { "ssp0 Tx", NULL, "codec0_out"},
143
Sathya Prakash M R5093f922016-02-24 11:27:41 +0530144 /* IV feedback path */
145 { "codec0_lp_in", NULL, "ssp0 Rx"},
Jeeja KP5188b952016-03-01 07:59:11 +0530146 { "ssp0 Rx", NULL, "Left Capture Sense" },
147 { "ssp0 Rx", NULL, "Right Capture Sense" },
Sathya Prakash M R5093f922016-02-24 11:27:41 +0530148
Fang, Yang A4c6ebc32015-12-11 11:29:09 -0800149 { "Playback", NULL, "ssp1 Tx"},
Harsha Priyaa86d5052015-11-05 22:53:07 +0530150 { "ssp1 Tx", NULL, "codec1_out"},
151
152 { "codec0_in", NULL, "ssp1 Rx" },
Fang, Yang A4c6ebc32015-12-11 11:29:09 -0800153 { "ssp1 Rx", NULL, "Capture" },
Harsha Priyaa86d5052015-11-05 22:53:07 +0530154
155 /* DMIC */
156 { "dmic01_hifi", NULL, "DMIC01 Rx" },
Fang, Yang A4c6ebc32015-12-11 11:29:09 -0800157 { "DMIC01 Rx", NULL, "DMIC AIF" },
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530158
159 { "hifi3", NULL, "iDisp3 Tx"},
160 { "iDisp3 Tx", NULL, "iDisp3_out"},
161 { "hifi2", NULL, "iDisp2 Tx"},
162 { "iDisp2 Tx", NULL, "iDisp2_out"},
163 { "hifi1", NULL, "iDisp1 Tx"},
164 { "iDisp1 Tx", NULL, "iDisp1_out"},
165
Harsha Priyaa86d5052015-11-05 22:53:07 +0530166 { "Headphone Jack", NULL, "Platform Clock" },
167 { "Headset Mic", NULL, "Platform Clock" },
168};
169
170static struct snd_soc_codec_conf ssm4567_codec_conf[] = {
171 {
172 .dev_name = "i2c-INT343B:00",
173 .name_prefix = "Left",
174 },
175 {
176 .dev_name = "i2c-INT343B:01",
177 .name_prefix = "Right",
178 },
179};
180
181static struct snd_soc_dai_link_component ssm4567_codec_components[] = {
182 { /* Left */
183 .name = "i2c-INT343B:00",
184 .dai_name = SKL_SSM_CODEC_DAI,
185 },
186 { /* Right */
187 .name = "i2c-INT343B:01",
188 .dai_name = SKL_SSM_CODEC_DAI,
189 },
190};
191
192static int skylake_ssm4567_codec_init(struct snd_soc_pcm_runtime *rtd)
193{
194 int ret;
195
196 /* Slot 1 for left */
197 ret = snd_soc_dai_set_tdm_slot(rtd->codec_dais[0], 0x01, 0x01, 2, 48);
198 if (ret < 0)
199 return ret;
200
201 /* Slot 2 for right */
202 ret = snd_soc_dai_set_tdm_slot(rtd->codec_dais[1], 0x02, 0x02, 2, 48);
203 if (ret < 0)
204 return ret;
205
206 return ret;
207}
208
209static int skylake_nau8825_codec_init(struct snd_soc_pcm_runtime *rtd)
210{
211 int ret;
212 struct snd_soc_codec *codec = rtd->codec;
213
214 /*
215 * 4 buttons here map to the google Reference headset
216 * The use of these buttons can be decided by the user space.
217 */
218 ret = snd_soc_card_jack_new(&skylake_audio_card, "Headset Jack",
219 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
220 SND_JACK_BTN_2 | SND_JACK_BTN_3, &skylake_headset,
221 NULL, 0);
222 if (ret) {
223 dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
224 return ret;
225 }
226
227 nau8825_enable_jack_detect(codec, &skylake_headset);
228
Yong Zhi941eee72015-12-11 11:29:10 -0800229 snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
230
Harsha Priyaa86d5052015-11-05 22:53:07 +0530231 return ret;
232}
233
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530234static int skylake_hdmi1_init(struct snd_soc_pcm_runtime *rtd)
235{
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +0530236 struct skl_nau88125_private *ctx = snd_soc_card_get_drvdata(rtd->card);
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530237 struct snd_soc_dai *dai = rtd->codec_dai;
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +0530238 struct skl_hdmi_pcm *pcm;
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530239
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +0530240 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
241 if (!pcm)
242 return -ENOMEM;
243
244 pcm->device = SKL_DPCM_AUDIO_HDMI1_PB;
245 pcm->codec_dai = dai;
246
247 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
248
249 return 0;
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530250}
251
252static int skylake_hdmi2_init(struct snd_soc_pcm_runtime *rtd)
253{
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +0530254 struct skl_nau88125_private *ctx = snd_soc_card_get_drvdata(rtd->card);
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530255 struct snd_soc_dai *dai = rtd->codec_dai;
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +0530256 struct skl_hdmi_pcm *pcm;
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530257
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +0530258 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
259 if (!pcm)
260 return -ENOMEM;
261
262 pcm->device = SKL_DPCM_AUDIO_HDMI2_PB;
263 pcm->codec_dai = dai;
264
265 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
266
267 return 0;
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530268}
269
270
271static int skylake_hdmi3_init(struct snd_soc_pcm_runtime *rtd)
272{
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +0530273 struct skl_nau88125_private *ctx = snd_soc_card_get_drvdata(rtd->card);
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530274 struct snd_soc_dai *dai = rtd->codec_dai;
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +0530275 struct skl_hdmi_pcm *pcm;
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530276
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +0530277 pcm = devm_kzalloc(rtd->card->dev, sizeof(*pcm), GFP_KERNEL);
278 if (!pcm)
279 return -ENOMEM;
280
281 pcm->device = SKL_DPCM_AUDIO_HDMI3_PB;
282 pcm->codec_dai = dai;
283
284 list_add_tail(&pcm->head, &ctx->hdmi_pcm_list);
285
286 return 0;
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530287}
288
Yong Zhi2616e272015-12-11 11:29:11 -0800289static int skylake_nau8825_fe_init(struct snd_soc_pcm_runtime *rtd)
290{
291 struct snd_soc_dapm_context *dapm;
292 struct snd_soc_component *component = rtd->cpu_dai->component;
293
294 dapm = snd_soc_component_get_dapm(component);
295 snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
296
297 return 0;
298}
299
Takashi Iwai617647a2017-06-08 23:37:23 +0200300static const unsigned int rates[] = {
Yong Zhi2616e272015-12-11 11:29:11 -0800301 48000,
302};
303
Takashi Iwai617647a2017-06-08 23:37:23 +0200304static const struct snd_pcm_hw_constraint_list constraints_rates = {
Yong Zhi2616e272015-12-11 11:29:11 -0800305 .count = ARRAY_SIZE(rates),
306 .list = rates,
307 .mask = 0,
308};
309
Takashi Iwai617647a2017-06-08 23:37:23 +0200310static const unsigned int channels[] = {
Yong Zhi2616e272015-12-11 11:29:11 -0800311 2,
312};
313
Takashi Iwai617647a2017-06-08 23:37:23 +0200314static const struct snd_pcm_hw_constraint_list constraints_channels = {
Yong Zhi2616e272015-12-11 11:29:11 -0800315 .count = ARRAY_SIZE(channels),
316 .list = channels,
317 .mask = 0,
318};
319
320static int skl_fe_startup(struct snd_pcm_substream *substream)
321{
322 struct snd_pcm_runtime *runtime = substream->runtime;
323
324 /*
325 * on this platform for PCM device we support,
326 * 48Khz
327 * stereo
328 * 16 bit audio
329 */
330
331 runtime->hw.channels_max = 2;
332 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
333 &constraints_channels);
334
335 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
336 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
337
338 snd_pcm_hw_constraint_list(runtime, 0,
339 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
340
341 return 0;
342}
343
344static const struct snd_soc_ops skylake_nau8825_fe_ops = {
345 .startup = skl_fe_startup,
346};
347
Harsha Priyaa86d5052015-11-05 22:53:07 +0530348static int skylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
349 struct snd_pcm_hw_params *params)
350{
351 struct snd_interval *rate = hw_param_interval(params,
352 SNDRV_PCM_HW_PARAM_RATE);
353 struct snd_interval *channels = hw_param_interval(params,
354 SNDRV_PCM_HW_PARAM_CHANNELS);
355 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
356
357 /* The ADSP will covert the FE rate to 48k, stereo */
358 rate->min = rate->max = 48000;
359 channels->min = channels->max = 2;
360
361 /* set SSP0 to 24 bit */
362 snd_mask_none(fmt);
363 snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE);
364 return 0;
365}
366
Yong Zhi2616e272015-12-11 11:29:11 -0800367static int skylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
368 struct snd_pcm_hw_params *params)
369{
370 struct snd_interval *channels = hw_param_interval(params,
371 SNDRV_PCM_HW_PARAM_CHANNELS);
Yong Zhicfa12362016-05-31 10:22:48 -0500372 if (params_channels(params) == 2 || DMIC_CH(dmic_constraints) == 2)
Yong Zhi2616e272015-12-11 11:29:11 -0800373 channels->min = channels->max = 2;
374 else
375 channels->min = channels->max = 4;
376
377 return 0;
378}
379
Harsha Priyaa86d5052015-11-05 22:53:07 +0530380static int skylake_nau8825_hw_params(struct snd_pcm_substream *substream,
381 struct snd_pcm_hw_params *params)
382{
383 struct snd_soc_pcm_runtime *rtd = substream->private_data;
384 struct snd_soc_dai *codec_dai = rtd->codec_dai;
385 int ret;
386
387 ret = snd_soc_dai_set_sysclk(codec_dai,
388 NAU8825_CLK_MCLK, 24000000, SND_SOC_CLOCK_IN);
389
390 if (ret < 0)
391 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
392
393 return ret;
394}
395
Julia Lawall9b6fdef2016-10-15 16:55:49 +0200396static const struct snd_soc_ops skylake_nau8825_ops = {
Harsha Priyaa86d5052015-11-05 22:53:07 +0530397 .hw_params = skylake_nau8825_hw_params,
398};
399
Takashi Iwai617647a2017-06-08 23:37:23 +0200400static const unsigned int channels_dmic[] = {
Yong Zhi2616e272015-12-11 11:29:11 -0800401 2, 4,
402};
403
Takashi Iwai617647a2017-06-08 23:37:23 +0200404static const struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
Yong Zhi2616e272015-12-11 11:29:11 -0800405 .count = ARRAY_SIZE(channels_dmic),
406 .list = channels_dmic,
407 .mask = 0,
408};
409
Yong Zhicfa12362016-05-31 10:22:48 -0500410static const unsigned int dmic_2ch[] = {
411 2,
412};
413
414static const struct snd_pcm_hw_constraint_list constraints_dmic_2ch = {
415 .count = ARRAY_SIZE(dmic_2ch),
416 .list = dmic_2ch,
417 .mask = 0,
418};
419
Yong Zhi2616e272015-12-11 11:29:11 -0800420static int skylake_dmic_startup(struct snd_pcm_substream *substream)
421{
422 struct snd_pcm_runtime *runtime = substream->runtime;
423
Yong Zhicfa12362016-05-31 10:22:48 -0500424 runtime->hw.channels_max = DMIC_CH(dmic_constraints);
Yong Zhi2616e272015-12-11 11:29:11 -0800425 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
Yong Zhicfa12362016-05-31 10:22:48 -0500426 dmic_constraints);
Yong Zhi2616e272015-12-11 11:29:11 -0800427
428 return snd_pcm_hw_constraint_list(substream->runtime, 0,
429 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
430}
431
Julia Lawall9b6fdef2016-10-15 16:55:49 +0200432static const struct snd_soc_ops skylake_dmic_ops = {
Yong Zhi2616e272015-12-11 11:29:11 -0800433 .startup = skylake_dmic_startup,
434};
435
Takashi Iwai617647a2017-06-08 23:37:23 +0200436static const unsigned int rates_16000[] = {
Yong Zhi2616e272015-12-11 11:29:11 -0800437 16000,
438};
439
Takashi Iwai617647a2017-06-08 23:37:23 +0200440static const struct snd_pcm_hw_constraint_list constraints_16000 = {
Yong Zhi2616e272015-12-11 11:29:11 -0800441 .count = ARRAY_SIZE(rates_16000),
442 .list = rates_16000,
443};
444
Yong Zhi0c7941a2016-05-17 09:43:05 -0700445static const unsigned int ch_mono[] = {
446 1,
447};
448
449static const struct snd_pcm_hw_constraint_list constraints_refcap = {
450 .count = ARRAY_SIZE(ch_mono),
451 .list = ch_mono,
452};
453
Yong Zhi2616e272015-12-11 11:29:11 -0800454static int skylake_refcap_startup(struct snd_pcm_substream *substream)
455{
Yong Zhi0c7941a2016-05-17 09:43:05 -0700456 substream->runtime->hw.channels_max = 1;
457 snd_pcm_hw_constraint_list(substream->runtime, 0,
458 SNDRV_PCM_HW_PARAM_CHANNELS,
459 &constraints_refcap);
460
Yong Zhi2616e272015-12-11 11:29:11 -0800461 return snd_pcm_hw_constraint_list(substream->runtime, 0,
462 SNDRV_PCM_HW_PARAM_RATE,
463 &constraints_16000);
464}
465
Julia Lawall9b6fdef2016-10-15 16:55:49 +0200466static const struct snd_soc_ops skylaye_refcap_ops = {
Yong Zhi2616e272015-12-11 11:29:11 -0800467 .startup = skylake_refcap_startup,
468};
469
Harsha Priyaa86d5052015-11-05 22:53:07 +0530470/* skylake digital audio interface glue - connects codec <--> CPU */
471static struct snd_soc_dai_link skylake_dais[] = {
472 /* Front End DAI links */
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530473 [SKL_DPCM_AUDIO_PB] = {
Harsha Priyaa86d5052015-11-05 22:53:07 +0530474 .name = "Skl Audio Port",
475 .stream_name = "Audio",
476 .cpu_dai_name = "System Pin",
477 .platform_name = "0000:00:1f.3",
478 .dynamic = 1,
479 .codec_name = "snd-soc-dummy",
480 .codec_dai_name = "snd-soc-dummy-dai",
481 .nonatomic = 1,
Yong Zhi2616e272015-12-11 11:29:11 -0800482 .init = skylake_nau8825_fe_init,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530483 .trigger = {
484 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
485 .dpcm_playback = 1,
Yong Zhi2616e272015-12-11 11:29:11 -0800486 .ops = &skylake_nau8825_fe_ops,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530487 },
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530488 [SKL_DPCM_AUDIO_CP] = {
Harsha Priyaa86d5052015-11-05 22:53:07 +0530489 .name = "Skl Audio Capture Port",
490 .stream_name = "Audio Record",
491 .cpu_dai_name = "System Pin",
492 .platform_name = "0000:00:1f.3",
493 .dynamic = 1,
494 .codec_name = "snd-soc-dummy",
495 .codec_dai_name = "snd-soc-dummy-dai",
496 .nonatomic = 1,
497 .trigger = {
498 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
499 .dpcm_capture = 1,
Yong Zhi2616e272015-12-11 11:29:11 -0800500 .ops = &skylake_nau8825_fe_ops,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530501 },
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530502 [SKL_DPCM_AUDIO_REF_CP] = {
Harsha Priyaa86d5052015-11-05 22:53:07 +0530503 .name = "Skl Audio Reference cap",
Sathyanarayana Nujella2154be32015-12-11 11:29:12 -0800504 .stream_name = "Wake on Voice",
Harsha Priyaa86d5052015-11-05 22:53:07 +0530505 .cpu_dai_name = "Reference Pin",
506 .codec_name = "snd-soc-dummy",
507 .codec_dai_name = "snd-soc-dummy-dai",
508 .platform_name = "0000:00:1f.3",
509 .init = NULL,
510 .dpcm_capture = 1,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530511 .nonatomic = 1,
512 .dynamic = 1,
Yong Zhi2616e272015-12-11 11:29:11 -0800513 .ops = &skylaye_refcap_ops,
514 },
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530515 [SKL_DPCM_AUDIO_DMIC_CP] = {
Yong Zhi2616e272015-12-11 11:29:11 -0800516 .name = "Skl Audio DMIC cap",
517 .stream_name = "dmiccap",
518 .cpu_dai_name = "DMIC Pin",
519 .codec_name = "snd-soc-dummy",
520 .codec_dai_name = "snd-soc-dummy-dai",
521 .platform_name = "0000:00:1f.3",
522 .init = NULL,
523 .dpcm_capture = 1,
524 .nonatomic = 1,
525 .dynamic = 1,
526 .ops = &skylake_dmic_ops,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530527 },
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530528 [SKL_DPCM_AUDIO_HDMI1_PB] = {
529 .name = "Skl HDMI Port1",
530 .stream_name = "Hdmi1",
531 .cpu_dai_name = "HDMI1 Pin",
Fang, Yang A743ad802015-12-11 11:29:13 -0800532 .codec_name = "snd-soc-dummy",
533 .codec_dai_name = "snd-soc-dummy-dai",
534 .platform_name = "0000:00:1f.3",
535 .dpcm_playback = 1,
536 .init = NULL,
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530537 .trigger = {
538 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
539 .nonatomic = 1,
540 .dynamic = 1,
541 },
542 [SKL_DPCM_AUDIO_HDMI2_PB] = {
543 .name = "Skl HDMI Port2",
544 .stream_name = "Hdmi2",
545 .cpu_dai_name = "HDMI2 Pin",
546 .codec_name = "snd-soc-dummy",
547 .codec_dai_name = "snd-soc-dummy-dai",
548 .platform_name = "0000:00:1f.3",
549 .dpcm_playback = 1,
550 .init = NULL,
551 .trigger = {
552 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
553 .nonatomic = 1,
554 .dynamic = 1,
555 },
556 [SKL_DPCM_AUDIO_HDMI3_PB] = {
557 .name = "Skl HDMI Port3",
558 .stream_name = "Hdmi3",
559 .cpu_dai_name = "HDMI3 Pin",
560 .codec_name = "snd-soc-dummy",
561 .codec_dai_name = "snd-soc-dummy-dai",
562 .platform_name = "0000:00:1f.3",
563 .trigger = {
564 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
565 .dpcm_playback = 1,
566 .init = NULL,
Fang, Yang A743ad802015-12-11 11:29:13 -0800567 .nonatomic = 1,
568 .dynamic = 1,
569 },
570
Harsha Priyaa86d5052015-11-05 22:53:07 +0530571 /* Back End DAI links */
572 {
573 /* SSP0 - Codec */
574 .name = "SSP0-Codec",
Mengdong Lin2f0ad492016-04-19 13:12:35 +0800575 .id = 0,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530576 .cpu_dai_name = "SSP0 Pin",
577 .platform_name = "0000:00:1f.3",
578 .no_pcm = 1,
579 .codecs = ssm4567_codec_components,
580 .num_codecs = ARRAY_SIZE(ssm4567_codec_components),
581 .dai_fmt = SND_SOC_DAIFMT_DSP_A |
582 SND_SOC_DAIFMT_IB_NF |
583 SND_SOC_DAIFMT_CBS_CFS,
584 .init = skylake_ssm4567_codec_init,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530585 .ignore_pmdown_time = 1,
586 .be_hw_params_fixup = skylake_ssp_fixup,
587 .dpcm_playback = 1,
Jeeja KP5188b952016-03-01 07:59:11 +0530588 .dpcm_capture = 1,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530589 },
590 {
591 /* SSP1 - Codec */
592 .name = "SSP1-Codec",
Mengdong Lin2f0ad492016-04-19 13:12:35 +0800593 .id = 1,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530594 .cpu_dai_name = "SSP1 Pin",
595 .platform_name = "0000:00:1f.3",
596 .no_pcm = 1,
597 .codec_name = "i2c-10508825:00",
598 .codec_dai_name = SKL_NUVOTON_CODEC_DAI,
599 .init = skylake_nau8825_codec_init,
600 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
601 SND_SOC_DAIFMT_CBS_CFS,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530602 .ignore_pmdown_time = 1,
603 .be_hw_params_fixup = skylake_ssp_fixup,
604 .ops = &skylake_nau8825_ops,
605 .dpcm_playback = 1,
606 .dpcm_capture = 1,
607 },
608 {
609 .name = "dmic01",
Mengdong Lin2f0ad492016-04-19 13:12:35 +0800610 .id = 2,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530611 .cpu_dai_name = "DMIC01 Pin",
612 .codec_name = "dmic-codec",
613 .codec_dai_name = "dmic-hifi",
614 .platform_name = "0000:00:1f.3",
615 .ignore_suspend = 1,
Yong Zhi2616e272015-12-11 11:29:11 -0800616 .be_hw_params_fixup = skylake_dmic_fixup,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530617 .dpcm_capture = 1,
618 .no_pcm = 1,
619 },
Fang, Yang A743ad802015-12-11 11:29:13 -0800620 {
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530621 .name = "iDisp1",
Mengdong Lin2f0ad492016-04-19 13:12:35 +0800622 .id = 3,
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530623 .cpu_dai_name = "iDisp1 Pin",
Fang, Yang A743ad802015-12-11 11:29:13 -0800624 .codec_name = "ehdaudio0D2",
625 .codec_dai_name = "intel-hdmi-hifi1",
626 .platform_name = "0000:00:1f.3",
627 .dpcm_playback = 1,
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530628 .init = skylake_hdmi1_init,
629 .no_pcm = 1,
630 },
631 {
632 .name = "iDisp2",
Mengdong Lin2f0ad492016-04-19 13:12:35 +0800633 .id = 4,
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530634 .cpu_dai_name = "iDisp2 Pin",
635 .codec_name = "ehdaudio0D2",
636 .codec_dai_name = "intel-hdmi-hifi2",
637 .platform_name = "0000:00:1f.3",
638 .init = skylake_hdmi2_init,
639 .dpcm_playback = 1,
640 .no_pcm = 1,
641 },
642 {
643 .name = "iDisp3",
Mengdong Lin2f0ad492016-04-19 13:12:35 +0800644 .id = 5,
Jeeja KPbc5f6ac2016-02-24 11:27:39 +0530645 .cpu_dai_name = "iDisp3 Pin",
646 .codec_name = "ehdaudio0D2",
647 .codec_dai_name = "intel-hdmi-hifi3",
648 .platform_name = "0000:00:1f.3",
649 .init = skylake_hdmi3_init,
650 .dpcm_playback = 1,
Fang, Yang A743ad802015-12-11 11:29:13 -0800651 .no_pcm = 1,
652 },
Harsha Priyaa86d5052015-11-05 22:53:07 +0530653};
654
Jeeja KP9e4278c2017-02-07 19:09:52 +0530655#define NAME_SIZE 32
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +0530656static int skylake_card_late_probe(struct snd_soc_card *card)
657{
658 struct skl_nau88125_private *ctx = snd_soc_card_get_drvdata(card);
659 struct skl_hdmi_pcm *pcm;
Jeeja KP86b57032017-02-07 19:09:58 +0530660 struct snd_soc_codec *codec = NULL;
Jeeja KP9e4278c2017-02-07 19:09:52 +0530661 int err, i = 0;
662 char jack_name[NAME_SIZE];
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +0530663
664 list_for_each_entry(pcm, &ctx->hdmi_pcm_list, head) {
Jeeja KP86b57032017-02-07 19:09:58 +0530665 codec = pcm->codec_dai->codec;
Jeeja KP9e4278c2017-02-07 19:09:52 +0530666 snprintf(jack_name, sizeof(jack_name),
667 "HDMI/DP, pcm=%d Jack", pcm->device);
668 err = snd_soc_card_jack_new(card, jack_name,
669 SND_JACK_AVOUT,
670 &skylake_hdmi[i],
671 NULL, 0);
672
673 if (err)
674 return err;
675
676 err = hdac_hdmi_jack_init(pcm->codec_dai, pcm->device,
677 &skylake_hdmi[i]);
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +0530678 if (err < 0)
679 return err;
Jeeja KP9e4278c2017-02-07 19:09:52 +0530680
681 i++;
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +0530682 }
683
Jeeja KP86b57032017-02-07 19:09:58 +0530684 if (!codec)
685 return -EINVAL;
686
687 return hdac_hdmi_jack_port_init(codec, &card->dapm);
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +0530688}
689
Harsha Priyaa86d5052015-11-05 22:53:07 +0530690/* skylake audio machine driver for SPT + NAU88L25 */
691static struct snd_soc_card skylake_audio_card = {
692 .name = "sklnau8825adi",
693 .owner = THIS_MODULE,
694 .dai_link = skylake_dais,
695 .num_links = ARRAY_SIZE(skylake_dais),
696 .controls = skylake_controls,
697 .num_controls = ARRAY_SIZE(skylake_controls),
698 .dapm_widgets = skylake_widgets,
699 .num_dapm_widgets = ARRAY_SIZE(skylake_widgets),
700 .dapm_routes = skylake_map,
701 .num_dapm_routes = ARRAY_SIZE(skylake_map),
702 .codec_conf = ssm4567_codec_conf,
703 .num_configs = ARRAY_SIZE(ssm4567_codec_conf),
Fang, Yang A4c6ebc32015-12-11 11:29:09 -0800704 .fully_routed = true,
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +0530705 .late_probe = skylake_card_late_probe,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530706};
707
708static int skylake_audio_probe(struct platform_device *pdev)
709{
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +0530710 struct skl_nau88125_private *ctx;
Yong Zhicfa12362016-05-31 10:22:48 -0500711 struct skl_machine_pdata *pdata;
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +0530712
713 ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_ATOMIC);
714 if (!ctx)
715 return -ENOMEM;
716
717 INIT_LIST_HEAD(&ctx->hdmi_pcm_list);
718
Harsha Priyaa86d5052015-11-05 22:53:07 +0530719 skylake_audio_card.dev = &pdev->dev;
Subhransu S. Prusty46ed1a22016-04-14 10:07:33 +0530720 snd_soc_card_set_drvdata(&skylake_audio_card, ctx);
Harsha Priyaa86d5052015-11-05 22:53:07 +0530721
Yong Zhicfa12362016-05-31 10:22:48 -0500722 pdata = dev_get_drvdata(&pdev->dev);
723 if (pdata)
724 dmic_constraints = pdata->dmic_num == 2 ?
725 &constraints_dmic_2ch : &constraints_dmic_channels;
726
Harsha Priyaa86d5052015-11-05 22:53:07 +0530727 return devm_snd_soc_register_card(&pdev->dev, &skylake_audio_card);
728}
729
Vinod Koul9dc201c2016-07-13 22:13:47 +0530730static const struct platform_device_id skl_board_ids[] = {
731 { .name = "skl_n88l25_s4567" },
732 { .name = "kbl_n88l25_s4567" },
733 { }
734};
735
Harsha Priyaa86d5052015-11-05 22:53:07 +0530736static struct platform_driver skylake_audio = {
737 .probe = skylake_audio_probe,
738 .driver = {
Vinod Koul400ada02016-07-13 22:13:43 +0530739 .name = "skl_n88l25_s4567",
Harsha Priyaa86d5052015-11-05 22:53:07 +0530740 .pm = &snd_soc_pm_ops,
741 },
Vinod Koul9dc201c2016-07-13 22:13:47 +0530742 .id_table = skl_board_ids,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530743};
744
745module_platform_driver(skylake_audio)
746
747/* Module information */
748MODULE_AUTHOR("Conrad Cooke <conrad.cooke@intel.com>");
749MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
750MODULE_AUTHOR("Naveen M <naveen.m@intel.com>");
751MODULE_AUTHOR("Sathya Prakash M R <sathya.prakash.m.r@intel.com>");
752MODULE_AUTHOR("Yong Zhi <yong.zhi@intel.com>");
753MODULE_DESCRIPTION("Intel Audio Machine driver for SKL with NAU88L25 and SSM4567 in I2S Mode");
754MODULE_LICENSE("GPL v2");
Vinod Koul400ada02016-07-13 22:13:43 +0530755MODULE_ALIAS("platform:skl_n88l25_s4567");
Vinod Koul9dc201c2016-07-13 22:13:47 +0530756MODULE_ALIAS("platform:kbl_n88l25_s4567");