blob: f6c252cccdb453a32da8bd95d3e85cd46802875b [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"
29
30#define SKL_NUVOTON_CODEC_DAI "nau8825-hifi"
31#define SKL_SSM_CODEC_DAI "ssm4567-hifi"
32
33static struct snd_soc_jack skylake_headset;
34static struct snd_soc_card skylake_audio_card;
35
36static inline struct snd_soc_dai *skl_get_codec_dai(struct snd_soc_card *card)
37{
Vinod Koul85af2a62015-11-20 22:34:41 +053038 struct snd_soc_pcm_runtime *rtd;
Harsha Priyaa86d5052015-11-05 22:53:07 +053039
Vinod Koul85af2a62015-11-20 22:34:41 +053040 list_for_each_entry(rtd, &card->rtd_list, list) {
Harsha Priyaa86d5052015-11-05 22:53:07 +053041
Harsha Priyaa86d5052015-11-05 22:53:07 +053042 if (!strncmp(rtd->codec_dai->name, SKL_NUVOTON_CODEC_DAI,
43 strlen(SKL_NUVOTON_CODEC_DAI)))
44 return rtd->codec_dai;
45 }
46
47 return NULL;
48}
49
50static const struct snd_kcontrol_new skylake_controls[] = {
51 SOC_DAPM_PIN_SWITCH("Headphone Jack"),
52 SOC_DAPM_PIN_SWITCH("Headset Mic"),
53 SOC_DAPM_PIN_SWITCH("Left Speaker"),
54 SOC_DAPM_PIN_SWITCH("Right Speaker"),
55};
56
57static int platform_clock_control(struct snd_soc_dapm_widget *w,
58 struct snd_kcontrol *k, int event)
59{
60 struct snd_soc_dapm_context *dapm = w->dapm;
61 struct snd_soc_card *card = dapm->card;
62 struct snd_soc_dai *codec_dai;
63 int ret;
64
65 codec_dai = skl_get_codec_dai(card);
66 if (!codec_dai) {
67 dev_err(card->dev, "Codec dai not found\n");
68 return -EIO;
69 }
70
71 if (SND_SOC_DAPM_EVENT_ON(event)) {
72 ret = snd_soc_dai_set_sysclk(codec_dai,
73 NAU8825_CLK_MCLK, 24000000, SND_SOC_CLOCK_IN);
74 if (ret < 0) {
75 dev_err(card->dev, "set sysclk err = %d\n", ret);
76 return -EIO;
77 }
78 } else {
79 ret = snd_soc_dai_set_sysclk(codec_dai,
80 NAU8825_CLK_INTERNAL, 0, SND_SOC_CLOCK_IN);
81 if (ret < 0) {
82 dev_err(card->dev, "set sysclk err = %d\n", ret);
83 return -EIO;
84 }
85 }
86 return ret;
87}
88
89static const struct snd_soc_dapm_widget skylake_widgets[] = {
90 SND_SOC_DAPM_HP("Headphone Jack", NULL),
91 SND_SOC_DAPM_MIC("Headset Mic", NULL),
92 SND_SOC_DAPM_SPK("Left Speaker", NULL),
93 SND_SOC_DAPM_SPK("Right Speaker", NULL),
94 SND_SOC_DAPM_MIC("SoC DMIC", NULL),
Sathyanarayana Nujella2154be32015-12-11 11:29:12 -080095 SND_SOC_DAPM_SINK("WoV Sink"),
Harsha Priyaa86d5052015-11-05 22:53:07 +053096 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
97 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
98 SND_SOC_DAPM_POST_PMD),
99};
100
101static const struct snd_soc_dapm_route skylake_map[] = {
102 /* HP jack connectors - unknown if we have jack detection */
103 {"Headphone Jack", NULL, "HPOL"},
104 {"Headphone Jack", NULL, "HPOR"},
105
106 /* speaker */
107 {"Left Speaker", NULL, "Left OUT"},
108 {"Right Speaker", NULL, "Right OUT"},
109
110 /* other jacks */
111 {"MIC", NULL, "Headset Mic"},
Fang, Yang A4c6ebc32015-12-11 11:29:09 -0800112 {"DMic", NULL, "SoC DMIC"},
Harsha Priyaa86d5052015-11-05 22:53:07 +0530113
Sathyanarayana Nujella2154be32015-12-11 11:29:12 -0800114 {"WoV Sink", NULL, "hwd_in sink"},
Harsha Priyaa86d5052015-11-05 22:53:07 +0530115 /* CODEC BE connections */
116 { "Left Playback", NULL, "ssp0 Tx"},
117 { "Right Playback", NULL, "ssp0 Tx"},
118 { "ssp0 Tx", NULL, "codec0_out"},
119
Fang, Yang A4c6ebc32015-12-11 11:29:09 -0800120 { "Playback", NULL, "ssp1 Tx"},
Harsha Priyaa86d5052015-11-05 22:53:07 +0530121 { "ssp1 Tx", NULL, "codec1_out"},
122
123 { "codec0_in", NULL, "ssp1 Rx" },
Fang, Yang A4c6ebc32015-12-11 11:29:09 -0800124 { "ssp1 Rx", NULL, "Capture" },
Harsha Priyaa86d5052015-11-05 22:53:07 +0530125
126 /* DMIC */
127 { "dmic01_hifi", NULL, "DMIC01 Rx" },
Fang, Yang A4c6ebc32015-12-11 11:29:09 -0800128 { "DMIC01 Rx", NULL, "DMIC AIF" },
Harsha Priyaa86d5052015-11-05 22:53:07 +0530129 { "Headphone Jack", NULL, "Platform Clock" },
130 { "Headset Mic", NULL, "Platform Clock" },
131};
132
133static struct snd_soc_codec_conf ssm4567_codec_conf[] = {
134 {
135 .dev_name = "i2c-INT343B:00",
136 .name_prefix = "Left",
137 },
138 {
139 .dev_name = "i2c-INT343B:01",
140 .name_prefix = "Right",
141 },
142};
143
144static struct snd_soc_dai_link_component ssm4567_codec_components[] = {
145 { /* Left */
146 .name = "i2c-INT343B:00",
147 .dai_name = SKL_SSM_CODEC_DAI,
148 },
149 { /* Right */
150 .name = "i2c-INT343B:01",
151 .dai_name = SKL_SSM_CODEC_DAI,
152 },
153};
154
155static int skylake_ssm4567_codec_init(struct snd_soc_pcm_runtime *rtd)
156{
157 int ret;
158
159 /* Slot 1 for left */
160 ret = snd_soc_dai_set_tdm_slot(rtd->codec_dais[0], 0x01, 0x01, 2, 48);
161 if (ret < 0)
162 return ret;
163
164 /* Slot 2 for right */
165 ret = snd_soc_dai_set_tdm_slot(rtd->codec_dais[1], 0x02, 0x02, 2, 48);
166 if (ret < 0)
167 return ret;
168
169 return ret;
170}
171
172static int skylake_nau8825_codec_init(struct snd_soc_pcm_runtime *rtd)
173{
174 int ret;
175 struct snd_soc_codec *codec = rtd->codec;
176
177 /*
178 * 4 buttons here map to the google Reference headset
179 * The use of these buttons can be decided by the user space.
180 */
181 ret = snd_soc_card_jack_new(&skylake_audio_card, "Headset Jack",
182 SND_JACK_HEADSET | SND_JACK_BTN_0 | SND_JACK_BTN_1 |
183 SND_JACK_BTN_2 | SND_JACK_BTN_3, &skylake_headset,
184 NULL, 0);
185 if (ret) {
186 dev_err(rtd->dev, "Headset Jack creation failed %d\n", ret);
187 return ret;
188 }
189
190 nau8825_enable_jack_detect(codec, &skylake_headset);
191
Yong Zhi941eee72015-12-11 11:29:10 -0800192 snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "SoC DMIC");
Sathyanarayana Nujella2154be32015-12-11 11:29:12 -0800193 snd_soc_dapm_ignore_suspend(&rtd->card->dapm, "WoV Sink");
Yong Zhi941eee72015-12-11 11:29:10 -0800194
Harsha Priyaa86d5052015-11-05 22:53:07 +0530195 return ret;
196}
197
Yong Zhi2616e272015-12-11 11:29:11 -0800198static int skylake_nau8825_fe_init(struct snd_soc_pcm_runtime *rtd)
199{
200 struct snd_soc_dapm_context *dapm;
201 struct snd_soc_component *component = rtd->cpu_dai->component;
202
203 dapm = snd_soc_component_get_dapm(component);
204 snd_soc_dapm_ignore_suspend(dapm, "Reference Capture");
205
206 return 0;
207}
208
209static unsigned int rates[] = {
210 48000,
211};
212
213static struct snd_pcm_hw_constraint_list constraints_rates = {
214 .count = ARRAY_SIZE(rates),
215 .list = rates,
216 .mask = 0,
217};
218
219static unsigned int channels[] = {
220 2,
221};
222
223static struct snd_pcm_hw_constraint_list constraints_channels = {
224 .count = ARRAY_SIZE(channels),
225 .list = channels,
226 .mask = 0,
227};
228
229static int skl_fe_startup(struct snd_pcm_substream *substream)
230{
231 struct snd_pcm_runtime *runtime = substream->runtime;
232
233 /*
234 * on this platform for PCM device we support,
235 * 48Khz
236 * stereo
237 * 16 bit audio
238 */
239
240 runtime->hw.channels_max = 2;
241 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
242 &constraints_channels);
243
244 runtime->hw.formats = SNDRV_PCM_FMTBIT_S16_LE;
245 snd_pcm_hw_constraint_msbits(runtime, 0, 16, 16);
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 skylake_nau8825_fe_ops = {
254 .startup = skl_fe_startup,
255};
256
Harsha Priyaa86d5052015-11-05 22:53:07 +0530257static int skylake_ssp_fixup(struct snd_soc_pcm_runtime *rtd,
258 struct snd_pcm_hw_params *params)
259{
260 struct snd_interval *rate = hw_param_interval(params,
261 SNDRV_PCM_HW_PARAM_RATE);
262 struct snd_interval *channels = hw_param_interval(params,
263 SNDRV_PCM_HW_PARAM_CHANNELS);
264 struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
265
266 /* The ADSP will covert the FE rate to 48k, stereo */
267 rate->min = rate->max = 48000;
268 channels->min = channels->max = 2;
269
270 /* set SSP0 to 24 bit */
271 snd_mask_none(fmt);
272 snd_mask_set(fmt, SNDRV_PCM_FORMAT_S24_LE);
273 return 0;
274}
275
Yong Zhi2616e272015-12-11 11:29:11 -0800276static int skylake_dmic_fixup(struct snd_soc_pcm_runtime *rtd,
277 struct snd_pcm_hw_params *params)
278{
279 struct snd_interval *channels = hw_param_interval(params,
280 SNDRV_PCM_HW_PARAM_CHANNELS);
281 if (params_channels(params) == 2)
282 channels->min = channels->max = 2;
283 else
284 channels->min = channels->max = 4;
285
286 return 0;
287}
288
Harsha Priyaa86d5052015-11-05 22:53:07 +0530289static int skylake_nau8825_hw_params(struct snd_pcm_substream *substream,
290 struct snd_pcm_hw_params *params)
291{
292 struct snd_soc_pcm_runtime *rtd = substream->private_data;
293 struct snd_soc_dai *codec_dai = rtd->codec_dai;
294 int ret;
295
296 ret = snd_soc_dai_set_sysclk(codec_dai,
297 NAU8825_CLK_MCLK, 24000000, SND_SOC_CLOCK_IN);
298
299 if (ret < 0)
300 dev_err(rtd->dev, "snd_soc_dai_set_sysclk err = %d\n", ret);
301
302 return ret;
303}
304
305static struct snd_soc_ops skylake_nau8825_ops = {
306 .hw_params = skylake_nau8825_hw_params,
307};
308
Yong Zhi2616e272015-12-11 11:29:11 -0800309static unsigned int channels_dmic[] = {
310 2, 4,
311};
312
313static struct snd_pcm_hw_constraint_list constraints_dmic_channels = {
314 .count = ARRAY_SIZE(channels_dmic),
315 .list = channels_dmic,
316 .mask = 0,
317};
318
319static int skylake_dmic_startup(struct snd_pcm_substream *substream)
320{
321 struct snd_pcm_runtime *runtime = substream->runtime;
322
323 runtime->hw.channels_max = 4;
324 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
325 &constraints_dmic_channels);
326
327 return snd_pcm_hw_constraint_list(substream->runtime, 0,
328 SNDRV_PCM_HW_PARAM_RATE, &constraints_rates);
329}
330
331static struct snd_soc_ops skylake_dmic_ops = {
332 .startup = skylake_dmic_startup,
333};
334
335static unsigned int rates_16000[] = {
336 16000,
337};
338
339static struct snd_pcm_hw_constraint_list constraints_16000 = {
340 .count = ARRAY_SIZE(rates_16000),
341 .list = rates_16000,
342};
343
344static int skylake_refcap_startup(struct snd_pcm_substream *substream)
345{
346 return snd_pcm_hw_constraint_list(substream->runtime, 0,
347 SNDRV_PCM_HW_PARAM_RATE,
348 &constraints_16000);
349}
350
351static struct snd_soc_ops skylaye_refcap_ops = {
352 .startup = skylake_refcap_startup,
353};
354
Harsha Priyaa86d5052015-11-05 22:53:07 +0530355/* skylake digital audio interface glue - connects codec <--> CPU */
356static struct snd_soc_dai_link skylake_dais[] = {
357 /* Front End DAI links */
358 {
359 .name = "Skl Audio Port",
360 .stream_name = "Audio",
361 .cpu_dai_name = "System Pin",
362 .platform_name = "0000:00:1f.3",
363 .dynamic = 1,
364 .codec_name = "snd-soc-dummy",
365 .codec_dai_name = "snd-soc-dummy-dai",
366 .nonatomic = 1,
Yong Zhi2616e272015-12-11 11:29:11 -0800367 .init = skylake_nau8825_fe_init,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530368 .trigger = {
369 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
370 .dpcm_playback = 1,
Yong Zhi2616e272015-12-11 11:29:11 -0800371 .ops = &skylake_nau8825_fe_ops,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530372 },
373 {
374 .name = "Skl Audio Capture Port",
375 .stream_name = "Audio Record",
376 .cpu_dai_name = "System Pin",
377 .platform_name = "0000:00:1f.3",
378 .dynamic = 1,
379 .codec_name = "snd-soc-dummy",
380 .codec_dai_name = "snd-soc-dummy-dai",
381 .nonatomic = 1,
382 .trigger = {
383 SND_SOC_DPCM_TRIGGER_POST, SND_SOC_DPCM_TRIGGER_POST},
384 .dpcm_capture = 1,
Yong Zhi2616e272015-12-11 11:29:11 -0800385 .ops = &skylake_nau8825_fe_ops,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530386 },
387 {
388 .name = "Skl Audio Reference cap",
Sathyanarayana Nujella2154be32015-12-11 11:29:12 -0800389 .stream_name = "Wake on Voice",
Harsha Priyaa86d5052015-11-05 22:53:07 +0530390 .cpu_dai_name = "Reference Pin",
391 .codec_name = "snd-soc-dummy",
392 .codec_dai_name = "snd-soc-dummy-dai",
393 .platform_name = "0000:00:1f.3",
394 .init = NULL,
395 .dpcm_capture = 1,
396 .ignore_suspend = 1,
397 .nonatomic = 1,
398 .dynamic = 1,
Yong Zhi2616e272015-12-11 11:29:11 -0800399 .ops = &skylaye_refcap_ops,
400 },
401 {
402 .name = "Skl 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:1f.3",
408 .init = NULL,
409 .dpcm_capture = 1,
410 .nonatomic = 1,
411 .dynamic = 1,
412 .ops = &skylake_dmic_ops,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530413 },
414 /* Back End DAI links */
415 {
416 /* SSP0 - Codec */
417 .name = "SSP0-Codec",
418 .be_id = 0,
419 .cpu_dai_name = "SSP0 Pin",
420 .platform_name = "0000:00:1f.3",
421 .no_pcm = 1,
422 .codecs = ssm4567_codec_components,
423 .num_codecs = ARRAY_SIZE(ssm4567_codec_components),
424 .dai_fmt = SND_SOC_DAIFMT_DSP_A |
425 SND_SOC_DAIFMT_IB_NF |
426 SND_SOC_DAIFMT_CBS_CFS,
427 .init = skylake_ssm4567_codec_init,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530428 .ignore_pmdown_time = 1,
429 .be_hw_params_fixup = skylake_ssp_fixup,
430 .dpcm_playback = 1,
431 },
432 {
433 /* SSP1 - Codec */
434 .name = "SSP1-Codec",
435 .be_id = 0,
436 .cpu_dai_name = "SSP1 Pin",
437 .platform_name = "0000:00:1f.3",
438 .no_pcm = 1,
439 .codec_name = "i2c-10508825:00",
440 .codec_dai_name = SKL_NUVOTON_CODEC_DAI,
441 .init = skylake_nau8825_codec_init,
442 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF |
443 SND_SOC_DAIFMT_CBS_CFS,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530444 .ignore_pmdown_time = 1,
445 .be_hw_params_fixup = skylake_ssp_fixup,
446 .ops = &skylake_nau8825_ops,
447 .dpcm_playback = 1,
448 .dpcm_capture = 1,
449 },
450 {
451 .name = "dmic01",
452 .be_id = 1,
453 .cpu_dai_name = "DMIC01 Pin",
454 .codec_name = "dmic-codec",
455 .codec_dai_name = "dmic-hifi",
456 .platform_name = "0000:00:1f.3",
457 .ignore_suspend = 1,
Yong Zhi2616e272015-12-11 11:29:11 -0800458 .be_hw_params_fixup = skylake_dmic_fixup,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530459 .dpcm_capture = 1,
460 .no_pcm = 1,
461 },
462};
463
464/* skylake audio machine driver for SPT + NAU88L25 */
465static struct snd_soc_card skylake_audio_card = {
466 .name = "sklnau8825adi",
467 .owner = THIS_MODULE,
468 .dai_link = skylake_dais,
469 .num_links = ARRAY_SIZE(skylake_dais),
470 .controls = skylake_controls,
471 .num_controls = ARRAY_SIZE(skylake_controls),
472 .dapm_widgets = skylake_widgets,
473 .num_dapm_widgets = ARRAY_SIZE(skylake_widgets),
474 .dapm_routes = skylake_map,
475 .num_dapm_routes = ARRAY_SIZE(skylake_map),
476 .codec_conf = ssm4567_codec_conf,
477 .num_configs = ARRAY_SIZE(ssm4567_codec_conf),
Fang, Yang A4c6ebc32015-12-11 11:29:09 -0800478 .fully_routed = true,
Harsha Priyaa86d5052015-11-05 22:53:07 +0530479};
480
481static int skylake_audio_probe(struct platform_device *pdev)
482{
483 skylake_audio_card.dev = &pdev->dev;
484
485 return devm_snd_soc_register_card(&pdev->dev, &skylake_audio_card);
486}
487
488static struct platform_driver skylake_audio = {
489 .probe = skylake_audio_probe,
490 .driver = {
491 .name = "skl_nau88l25_ssm4567_i2s",
492 .pm = &snd_soc_pm_ops,
493 },
494};
495
496module_platform_driver(skylake_audio)
497
498/* Module information */
499MODULE_AUTHOR("Conrad Cooke <conrad.cooke@intel.com>");
500MODULE_AUTHOR("Harsha Priya <harshapriya.n@intel.com>");
501MODULE_AUTHOR("Naveen M <naveen.m@intel.com>");
502MODULE_AUTHOR("Sathya Prakash M R <sathya.prakash.m.r@intel.com>");
503MODULE_AUTHOR("Yong Zhi <yong.zhi@intel.com>");
504MODULE_DESCRIPTION("Intel Audio Machine driver for SKL with NAU88L25 and SSM4567 in I2S Mode");
505MODULE_LICENSE("GPL v2");
506MODULE_ALIAS("platform:skl_nau88l25_ssm4567_i2s");