2 * byt_cr_dpcm_rt5640.c - ASoc Machine driver for Intel Byt CR platform
4 * Copyright (C) 2014 Intel Corp
5 * Author: Subhransu S. Prusty <subhransu.s.prusty@intel.com>
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/moduleparam.h>
23 #include <linux/platform_device.h>
24 #include <linux/acpi.h>
25 #include <linux/device.h>
26 #include <linux/dmi.h>
27 #include <linux/slab.h>
28 #include <asm/cpu_device_id.h>
29 #include <asm/platform_sst_audio.h>
30 #include <linux/clk.h>
31 #include <sound/pcm.h>
32 #include <sound/pcm_params.h>
33 #include <sound/soc.h>
34 #include <sound/jack.h>
35 #include "../../codecs/rt5640.h"
36 #include "../atom/sst-atom-controls.h"
37 #include "../common/sst-acpi.h"
38 #include "../common/sst-dsp.h"
47 #define BYT_RT5640_MAP(quirk) ((quirk) & 0xff)
48 #define BYT_RT5640_DMIC_EN BIT(16)
49 #define BYT_RT5640_MONO_SPEAKER BIT(17)
50 #define BYT_RT5640_DIFF_MIC BIT(18) /* defaut is single-ended */
51 #define BYT_RT5640_SSP2_AIF2 BIT(19) /* default is using AIF1 */
52 #define BYT_RT5640_SSP0_AIF1 BIT(20)
53 #define BYT_RT5640_SSP0_AIF2 BIT(21)
54 #define BYT_RT5640_MCLK_EN BIT(22)
55 #define BYT_RT5640_MCLK_25MHZ BIT(23)
57 struct byt_rt5640_private {
62 static unsigned long byt_rt5640_quirk = BYT_RT5640_MCLK_EN;
63 static unsigned int quirk_override;
64 module_param_named(quirk, quirk_override, uint, 0444);
65 MODULE_PARM_DESC(quirk, "Board-specific quirk override");
67 static void log_quirks(struct device *dev)
70 bool has_dmic = false;
71 bool has_mclk = false;
72 bool has_ssp0 = false;
73 bool has_ssp0_aif1 = false;
74 bool has_ssp0_aif2 = false;
75 bool has_ssp2_aif2 = false;
77 map = BYT_RT5640_MAP(byt_rt5640_quirk);
79 case BYT_RT5640_DMIC1_MAP:
80 dev_info(dev, "quirk DMIC1_MAP enabled\n");
83 case BYT_RT5640_DMIC2_MAP:
84 dev_info(dev, "quirk DMIC2_MAP enabled\n");
87 case BYT_RT5640_IN1_MAP:
88 dev_info(dev, "quirk IN1_MAP enabled\n");
90 case BYT_RT5640_IN3_MAP:
91 dev_info(dev, "quirk IN3_MAP enabled\n");
94 dev_err(dev, "quirk map 0x%x is not supported, microphone input will not work\n", map);
97 if (byt_rt5640_quirk & BYT_RT5640_DMIC_EN) {
99 dev_info(dev, "quirk DMIC enabled\n");
101 dev_err(dev, "quirk DMIC enabled but no DMIC input set, will be ignored\n");
103 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER)
104 dev_info(dev, "quirk MONO_SPEAKER enabled\n");
105 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC) {
107 dev_info(dev, "quirk DIFF_MIC enabled\n");
109 dev_info(dev, "quirk DIFF_MIC enabled but DMIC input selected, will be ignored\n");
111 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
112 dev_info(dev, "quirk SSP0_AIF1 enabled\n");
114 has_ssp0_aif1 = true;
116 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
117 dev_info(dev, "quirk SSP0_AIF2 enabled\n");
119 has_ssp0_aif2 = true;
121 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
122 dev_info(dev, "quirk SSP2_AIF2 enabled\n");
123 has_ssp2_aif2 = true;
125 if (is_bytcr && !has_ssp0)
126 dev_err(dev, "Invalid routing, bytcr detected but no SSP0-based quirk, audio cannot work with SSP2 on bytcr\n");
127 if (has_ssp0_aif1 && has_ssp0_aif2)
128 dev_err(dev, "Invalid routing, SSP0 cannot be connected to both AIF1 and AIF2\n");
129 if (has_ssp0 && has_ssp2_aif2)
130 dev_err(dev, "Invalid routing, cannot have both SSP0 and SSP2 connected to codec\n");
132 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
133 dev_info(dev, "quirk MCLK_EN enabled\n");
136 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
138 dev_info(dev, "quirk MCLK_25MHZ enabled\n");
140 dev_err(dev, "quirk MCLK_25MHZ enabled but quirk MCLK not selected, will be ignored\n");
145 #define BYT_CODEC_DAI1 "rt5640-aif1"
146 #define BYT_CODEC_DAI2 "rt5640-aif2"
148 static inline struct snd_soc_dai *byt_get_codec_dai(struct snd_soc_card *card)
150 struct snd_soc_pcm_runtime *rtd;
152 list_for_each_entry(rtd, &card->rtd_list, list) {
153 if (!strncmp(rtd->codec_dai->name, BYT_CODEC_DAI1,
154 strlen(BYT_CODEC_DAI1)))
155 return rtd->codec_dai;
156 if (!strncmp(rtd->codec_dai->name, BYT_CODEC_DAI2,
157 strlen(BYT_CODEC_DAI2)))
158 return rtd->codec_dai;
164 static int platform_clock_control(struct snd_soc_dapm_widget *w,
165 struct snd_kcontrol *k, int event)
167 struct snd_soc_dapm_context *dapm = w->dapm;
168 struct snd_soc_card *card = dapm->card;
169 struct snd_soc_dai *codec_dai;
170 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
173 codec_dai = byt_get_codec_dai(card);
176 "Codec dai not found; Unable to set platform clock\n");
180 if (SND_SOC_DAPM_EVENT_ON(event)) {
181 if ((byt_rt5640_quirk & BYT_RT5640_MCLK_EN) && priv->mclk) {
182 ret = clk_prepare_enable(priv->mclk);
185 "could not configure MCLK state\n");
189 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
194 * Set codec clock source to internal clock before
195 * turning off the platform clock. Codec needs clock
196 * for Jack detection and button press
198 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_RCCLK,
202 if ((byt_rt5640_quirk & BYT_RT5640_MCLK_EN) && priv->mclk)
203 clk_disable_unprepare(priv->mclk);
208 dev_err(card->dev, "can't set codec sysclk: %d\n", ret);
215 static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
216 SND_SOC_DAPM_HP("Headphone", NULL),
217 SND_SOC_DAPM_MIC("Headset Mic", NULL),
218 SND_SOC_DAPM_MIC("Internal Mic", NULL),
219 SND_SOC_DAPM_SPK("Speaker", NULL),
220 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
221 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
222 SND_SOC_DAPM_POST_PMD),
226 static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
227 {"Headphone", NULL, "Platform Clock"},
228 {"Headset Mic", NULL, "Platform Clock"},
229 {"Headset Mic", NULL, "MICBIAS1"},
230 {"IN2P", NULL, "Headset Mic"},
231 {"Headphone", NULL, "HPOL"},
232 {"Headphone", NULL, "HPOR"},
235 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
236 {"Internal Mic", NULL, "Platform Clock"},
237 {"DMIC1", NULL, "Internal Mic"},
240 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
241 {"Internal Mic", NULL, "Platform Clock"},
242 {"DMIC2", NULL, "Internal Mic"},
245 static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
246 {"Internal Mic", NULL, "Platform Clock"},
247 {"Internal Mic", NULL, "MICBIAS1"},
248 {"IN1P", NULL, "Internal Mic"},
251 static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map[] = {
252 {"Internal Mic", NULL, "Platform Clock"},
253 {"Internal Mic", NULL, "MICBIAS1"},
254 {"IN3P", NULL, "Internal Mic"},
257 static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = {
258 {"ssp2 Tx", NULL, "codec_out0"},
259 {"ssp2 Tx", NULL, "codec_out1"},
260 {"codec_in0", NULL, "ssp2 Rx"},
261 {"codec_in1", NULL, "ssp2 Rx"},
263 {"AIF1 Playback", NULL, "ssp2 Tx"},
264 {"ssp2 Rx", NULL, "AIF1 Capture"},
267 static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_map[] = {
268 {"ssp2 Tx", NULL, "codec_out0"},
269 {"ssp2 Tx", NULL, "codec_out1"},
270 {"codec_in0", NULL, "ssp2 Rx"},
271 {"codec_in1", NULL, "ssp2 Rx"},
273 {"AIF2 Playback", NULL, "ssp2 Tx"},
274 {"ssp2 Rx", NULL, "AIF2 Capture"},
277 static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif1_map[] = {
278 {"ssp0 Tx", NULL, "modem_out"},
279 {"modem_in", NULL, "ssp0 Rx"},
281 {"AIF1 Playback", NULL, "ssp0 Tx"},
282 {"ssp0 Rx", NULL, "AIF1 Capture"},
285 static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif2_map[] = {
286 {"ssp0 Tx", NULL, "modem_out"},
287 {"modem_in", NULL, "ssp0 Rx"},
289 {"AIF2 Playback", NULL, "ssp0 Tx"},
290 {"ssp0 Rx", NULL, "AIF2 Capture"},
293 static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = {
294 {"Speaker", NULL, "Platform Clock"},
295 {"Speaker", NULL, "SPOLP"},
296 {"Speaker", NULL, "SPOLN"},
297 {"Speaker", NULL, "SPORP"},
298 {"Speaker", NULL, "SPORN"},
301 static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = {
302 {"Speaker", NULL, "Platform Clock"},
303 {"Speaker", NULL, "SPOLP"},
304 {"Speaker", NULL, "SPOLN"},
307 static const struct snd_kcontrol_new byt_rt5640_controls[] = {
308 SOC_DAPM_PIN_SWITCH("Headphone"),
309 SOC_DAPM_PIN_SWITCH("Headset Mic"),
310 SOC_DAPM_PIN_SWITCH("Internal Mic"),
311 SOC_DAPM_PIN_SWITCH("Speaker"),
314 static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream,
315 struct snd_pcm_hw_params *params)
317 struct snd_soc_pcm_runtime *rtd = substream->private_data;
318 struct snd_soc_dai *codec_dai = rtd->codec_dai;
321 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
322 params_rate(params) * 512,
326 dev_err(rtd->dev, "can't set codec clock %d\n", ret);
330 if (!(byt_rt5640_quirk & BYT_RT5640_MCLK_EN)) {
331 /* use bitclock as PLL input */
332 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
333 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
335 /* 2x16 bit slots on SSP0 */
336 ret = snd_soc_dai_set_pll(codec_dai, 0,
338 params_rate(params) * 32,
339 params_rate(params) * 512);
341 /* 2x15 bit slots on SSP2 */
342 ret = snd_soc_dai_set_pll(codec_dai, 0,
344 params_rate(params) * 50,
345 params_rate(params) * 512);
348 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
349 ret = snd_soc_dai_set_pll(codec_dai, 0,
352 params_rate(params) * 512);
354 ret = snd_soc_dai_set_pll(codec_dai, 0,
357 params_rate(params) * 512);
362 dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
369 static int byt_rt5640_quirk_cb(const struct dmi_system_id *id)
371 byt_rt5640_quirk = (unsigned long)id->driver_data;
375 static const struct dmi_system_id byt_rt5640_quirk_table[] = {
377 .callback = byt_rt5640_quirk_cb,
379 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
380 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
382 .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP |
386 .callback = byt_rt5640_quirk_cb,
388 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
389 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"),
391 .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP |
392 BYT_RT5640_MONO_SPEAKER |
393 BYT_RT5640_DIFF_MIC |
394 BYT_RT5640_SSP0_AIF2 |
399 .callback = byt_rt5640_quirk_cb,
401 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "DellInc."),
402 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
404 .driver_data = (unsigned long *)(BYT_RT5640_DMIC2_MAP |
409 .callback = byt_rt5640_quirk_cb,
411 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
412 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"),
414 .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP |
418 .callback = byt_rt5640_quirk_cb,
420 DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
421 DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"),
423 .driver_data = (unsigned long *)(BYT_RT5640_DMIC1_MAP |
427 .callback = byt_rt5640_quirk_cb,
429 DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"),
430 DMI_MATCH(DMI_BOARD_NAME, "tPAD"),
432 .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP |
434 BYT_RT5640_SSP0_AIF1),
437 .callback = byt_rt5640_quirk_cb,
439 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
440 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
442 .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP |
444 BYT_RT5640_SSP0_AIF1),
448 .callback = byt_rt5640_quirk_cb,
450 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
452 .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP |
454 BYT_RT5640_SSP0_AIF1),
460 static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
463 struct snd_soc_codec *codec = runtime->codec;
464 struct snd_soc_card *card = runtime->card;
465 const struct snd_soc_dapm_route *custom_map;
466 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
469 card->dapm.idle_bias_off = true;
471 rt5640_sel_asrc_clk_src(codec,
472 RT5640_DA_STEREO_FILTER |
473 RT5640_DA_MONO_L_FILTER |
474 RT5640_DA_MONO_R_FILTER |
475 RT5640_AD_STEREO_FILTER |
476 RT5640_AD_MONO_L_FILTER |
477 RT5640_AD_MONO_R_FILTER,
478 RT5640_CLK_SEL_ASRC);
480 ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
481 ARRAY_SIZE(byt_rt5640_controls));
483 dev_err(card->dev, "unable to add card controls\n");
487 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
488 case BYT_RT5640_IN1_MAP:
489 custom_map = byt_rt5640_intmic_in1_map;
490 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
492 case BYT_RT5640_IN3_MAP:
493 custom_map = byt_rt5640_intmic_in3_map;
494 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in3_map);
496 case BYT_RT5640_DMIC2_MAP:
497 custom_map = byt_rt5640_intmic_dmic2_map;
498 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
501 custom_map = byt_rt5640_intmic_dmic1_map;
502 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
505 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
509 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
510 ret = snd_soc_dapm_add_routes(&card->dapm,
511 byt_rt5640_ssp2_aif2_map,
512 ARRAY_SIZE(byt_rt5640_ssp2_aif2_map));
513 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
514 ret = snd_soc_dapm_add_routes(&card->dapm,
515 byt_rt5640_ssp0_aif1_map,
516 ARRAY_SIZE(byt_rt5640_ssp0_aif1_map));
517 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
518 ret = snd_soc_dapm_add_routes(&card->dapm,
519 byt_rt5640_ssp0_aif2_map,
520 ARRAY_SIZE(byt_rt5640_ssp0_aif2_map));
522 ret = snd_soc_dapm_add_routes(&card->dapm,
523 byt_rt5640_ssp2_aif1_map,
524 ARRAY_SIZE(byt_rt5640_ssp2_aif1_map));
529 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
530 ret = snd_soc_dapm_add_routes(&card->dapm,
531 byt_rt5640_mono_spk_map,
532 ARRAY_SIZE(byt_rt5640_mono_spk_map));
534 ret = snd_soc_dapm_add_routes(&card->dapm,
535 byt_rt5640_stereo_spk_map,
536 ARRAY_SIZE(byt_rt5640_stereo_spk_map));
541 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC) {
542 snd_soc_update_bits(codec, RT5640_IN1_IN2, RT5640_IN_DF1,
546 if (byt_rt5640_quirk & BYT_RT5640_DMIC_EN) {
547 ret = rt5640_dmic_enable(codec, 0, 0);
552 snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
553 snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
555 if ((byt_rt5640_quirk & BYT_RT5640_MCLK_EN) && priv->mclk) {
557 * The firmware might enable the clock at
558 * boot (this information may or may not
559 * be reflected in the enable clock register).
560 * To change the rate we must disable the clock
561 * first to cover these cases. Due to common
562 * clock framework restrictions that do not allow
563 * to disable a clock that has not been enabled,
564 * we need to enable the clock first.
566 ret = clk_prepare_enable(priv->mclk);
568 clk_disable_unprepare(priv->mclk);
570 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ)
571 ret = clk_set_rate(priv->mclk, 25000000);
573 ret = clk_set_rate(priv->mclk, 19200000);
576 dev_err(card->dev, "unable to set MCLK rate\n");
582 static const struct snd_soc_pcm_stream byt_rt5640_dai_params = {
583 .formats = SNDRV_PCM_FMTBIT_S24_LE,
590 static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd,
591 struct snd_pcm_hw_params *params)
593 struct snd_interval *rate = hw_param_interval(params,
594 SNDRV_PCM_HW_PARAM_RATE);
595 struct snd_interval *channels = hw_param_interval(params,
596 SNDRV_PCM_HW_PARAM_CHANNELS);
599 /* The DSP will covert the FE rate to 48k, stereo */
600 rate->min = rate->max = 48000;
601 channels->min = channels->max = 2;
603 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
604 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
606 /* set SSP0 to 16-bit */
607 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
610 * Default mode for SSP configuration is TDM 4 slot, override config
611 * with explicit setting to I2S 2ch 16-bit. The word length is set with
612 * dai_set_tdm_slot() since there is no other API exposed
614 ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
616 SND_SOC_DAIFMT_NB_NF |
617 SND_SOC_DAIFMT_CBS_CFS
620 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
624 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 16);
626 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
632 /* set SSP2 to 24-bit */
633 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
636 * Default mode for SSP configuration is TDM 4 slot, override config
637 * with explicit setting to I2S 2ch 24-bit. The word length is set with
638 * dai_set_tdm_slot() since there is no other API exposed
640 ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
642 SND_SOC_DAIFMT_NB_NF |
643 SND_SOC_DAIFMT_CBS_CFS
646 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
650 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24);
652 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
659 static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream)
661 return snd_pcm_hw_constraint_single(substream->runtime,
662 SNDRV_PCM_HW_PARAM_RATE, 48000);
665 static const struct snd_soc_ops byt_rt5640_aif1_ops = {
666 .startup = byt_rt5640_aif1_startup,
669 static const struct snd_soc_ops byt_rt5640_be_ssp2_ops = {
670 .hw_params = byt_rt5640_aif1_hw_params,
673 static struct snd_soc_dai_link byt_rt5640_dais[] = {
674 [MERR_DPCM_AUDIO] = {
675 .name = "Baytrail Audio Port",
676 .stream_name = "Baytrail Audio",
677 .cpu_dai_name = "media-cpu-dai",
678 .codec_dai_name = "snd-soc-dummy-dai",
679 .codec_name = "snd-soc-dummy",
680 .platform_name = "sst-mfld-platform",
685 .ops = &byt_rt5640_aif1_ops,
687 [MERR_DPCM_DEEP_BUFFER] = {
688 .name = "Deep-Buffer Audio Port",
689 .stream_name = "Deep-Buffer Audio",
690 .cpu_dai_name = "deepbuffer-cpu-dai",
691 .codec_dai_name = "snd-soc-dummy-dai",
692 .codec_name = "snd-soc-dummy",
693 .platform_name = "sst-mfld-platform",
697 .ops = &byt_rt5640_aif1_ops,
699 [MERR_DPCM_COMPR] = {
700 .name = "Baytrail Compressed Port",
701 .stream_name = "Baytrail Compress",
702 .cpu_dai_name = "compress-cpu-dai",
703 .codec_dai_name = "snd-soc-dummy-dai",
704 .codec_name = "snd-soc-dummy",
705 .platform_name = "sst-mfld-platform",
709 .name = "SSP2-Codec",
711 .cpu_dai_name = "ssp2-port", /* overwritten for ssp0 routing */
712 .platform_name = "sst-mfld-platform",
714 .codec_dai_name = "rt5640-aif1", /* changed w/ quirk */
715 .codec_name = "i2c-10EC5640:00", /* overwritten with HID */
716 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
717 | SND_SOC_DAIFMT_CBS_CFS,
718 .be_hw_params_fixup = byt_rt5640_codec_fixup,
723 .init = byt_rt5640_init,
724 .ops = &byt_rt5640_be_ssp2_ops,
729 static struct snd_soc_card byt_rt5640_card = {
730 .name = "bytcr-rt5640",
731 .owner = THIS_MODULE,
732 .dai_link = byt_rt5640_dais,
733 .num_links = ARRAY_SIZE(byt_rt5640_dais),
734 .dapm_widgets = byt_rt5640_widgets,
735 .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
736 .dapm_routes = byt_rt5640_audio_map,
737 .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
738 .fully_routed = true,
741 static char byt_rt5640_codec_name[16]; /* i2c-<HID>:00 with HID being 8 chars */
742 static char byt_rt5640_codec_aif_name[12]; /* = "rt5640-aif[1|2]" */
743 static char byt_rt5640_cpu_dai_name[10]; /* = "ssp[0|2]-port" */
745 static bool is_valleyview(void)
747 static const struct x86_cpu_id cpu_ids[] = {
748 { X86_VENDOR_INTEL, 6, 55 }, /* Valleyview, Bay Trail */
752 if (!x86_match_cpu(cpu_ids))
757 struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */
758 u64 aif_value; /* 1: AIF1, 2: AIF2 */
759 u64 mclock_value; /* usually 25MHz (0x17d7940), ignored */
762 static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
765 struct sst_acpi_mach *mach;
766 const char *i2c_name = NULL;
769 struct byt_rt5640_private *priv;
772 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_ATOMIC);
776 /* register the soc card */
777 byt_rt5640_card.dev = &pdev->dev;
778 mach = byt_rt5640_card.dev->platform_data;
779 snd_soc_card_set_drvdata(&byt_rt5640_card, priv);
781 /* fix index of codec dai */
782 dai_index = MERR_DPCM_COMPR + 1;
783 for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) {
784 if (!strcmp(byt_rt5640_dais[i].codec_name, "i2c-10EC5640:00")) {
790 /* fixup codec name based on HID */
791 i2c_name = sst_acpi_find_name_from_hid(mach->id);
792 if (i2c_name != NULL) {
793 snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name),
794 "%s%s", "i2c-", i2c_name);
796 byt_rt5640_dais[dai_index].codec_name = byt_rt5640_codec_name;
800 * swap SSP0 if bytcr is detected
801 * (will be overridden if DMI quirk is detected)
803 if (is_valleyview()) {
804 struct sst_platform_info *p_info = mach->pdata;
805 const struct sst_res_info *res_info = p_info->res_info;
807 if (res_info->acpi_ipc_irq_index == 0)
813 * Baytrail CR platforms may have CHAN package in BIOS, try
814 * to find relevant routing quirk based as done on Windows
815 * platforms. We have to read the information directly from the
816 * BIOS, at this stage the card is not created and the links
817 * with the codec driver/pdata are non-existent
820 struct acpi_chan_package chan_package;
822 /* format specified: 2 64-bit integers */
823 struct acpi_buffer format = {sizeof("NN"), "NN"};
824 struct acpi_buffer state = {0, NULL};
825 struct sst_acpi_package_context pkg_ctx;
826 bool pkg_found = false;
828 state.length = sizeof(chan_package);
829 state.pointer = &chan_package;
831 pkg_ctx.name = "CHAN";
833 pkg_ctx.format = &format;
834 pkg_ctx.state = &state;
835 pkg_ctx.data_valid = false;
837 pkg_found = sst_acpi_find_package_from_hid(mach->id, &pkg_ctx);
839 if (chan_package.aif_value == 1) {
840 dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n");
841 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF1;
842 } else if (chan_package.aif_value == 2) {
843 dev_info(&pdev->dev, "BIOS Routing: AIF2 connected\n");
844 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
846 dev_info(&pdev->dev, "BIOS Routing isn't valid, ignored\n");
852 /* no BIOS indications, assume SSP0-AIF2 connection */
853 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
856 /* change defaults for Baytrail-CR capture */
857 byt_rt5640_quirk |= BYT_RT5640_IN1_MAP;
858 byt_rt5640_quirk |= BYT_RT5640_DIFF_MIC;
860 byt_rt5640_quirk |= (BYT_RT5640_DMIC1_MAP |
864 /* check quirks before creating card */
865 dmi_check_system(byt_rt5640_quirk_table);
866 if (quirk_override) {
867 dev_info(&pdev->dev, "Overriding quirk 0x%x => 0x%x\n",
868 (unsigned int)byt_rt5640_quirk, quirk_override);
869 byt_rt5640_quirk = quirk_override;
871 log_quirks(&pdev->dev);
873 if ((byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) ||
874 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
876 /* fixup codec aif name */
877 snprintf(byt_rt5640_codec_aif_name,
878 sizeof(byt_rt5640_codec_aif_name),
879 "%s", "rt5640-aif2");
881 byt_rt5640_dais[dai_index].codec_dai_name =
882 byt_rt5640_codec_aif_name;
885 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
886 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
888 /* fixup cpu dai name name */
889 snprintf(byt_rt5640_cpu_dai_name,
890 sizeof(byt_rt5640_cpu_dai_name),
893 byt_rt5640_dais[dai_index].cpu_dai_name =
894 byt_rt5640_cpu_dai_name;
897 if ((byt_rt5640_quirk & BYT_RT5640_MCLK_EN) && (is_valleyview())) {
898 priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
899 if (IS_ERR(priv->mclk)) {
900 ret_val = PTR_ERR(priv->mclk);
903 "Failed to get MCLK from pmc_plt_clk_3: %d\n",
907 * Fall back to bit clock usage for -ENOENT (clock not
908 * available likely due to missing dependencies), bail
909 * for all other errors, including -EPROBE_DEFER
911 if (ret_val != -ENOENT)
913 byt_rt5640_quirk &= ~BYT_RT5640_MCLK_EN;
917 ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card);
920 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
924 platform_set_drvdata(pdev, &byt_rt5640_card);
928 static struct platform_driver snd_byt_rt5640_mc_driver = {
930 .name = "bytcr_rt5640",
932 .probe = snd_byt_rt5640_mc_probe,
935 module_platform_driver(snd_byt_rt5640_mc_driver);
937 MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
938 MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
939 MODULE_LICENSE("GPL v2");
940 MODULE_ALIAS("platform:bytcr_rt5640");