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/platform_device.h>
23 #include <linux/acpi.h>
24 #include <linux/device.h>
25 #include <linux/dmi.h>
26 #include <linux/slab.h>
27 #include <asm/cpu_device_id.h>
28 #include <asm/platform_sst_audio.h>
29 #include <linux/clk.h>
30 #include <sound/pcm.h>
31 #include <sound/pcm_params.h>
32 #include <sound/soc.h>
33 #include <sound/jack.h>
34 #include "../../codecs/rt5640.h"
35 #include "../atom/sst-atom-controls.h"
36 #include "../common/sst-acpi.h"
37 #include "../common/sst-dsp.h"
46 #define BYT_RT5640_MAP(quirk) ((quirk) & 0xff)
47 #define BYT_RT5640_DMIC_EN BIT(16)
48 #define BYT_RT5640_MONO_SPEAKER BIT(17)
49 #define BYT_RT5640_DIFF_MIC BIT(18) /* defaut is single-ended */
50 #define BYT_RT5640_SSP2_AIF2 BIT(19) /* default is using AIF1 */
51 #define BYT_RT5640_SSP0_AIF1 BIT(20)
52 #define BYT_RT5640_SSP0_AIF2 BIT(21)
53 #define BYT_RT5640_MCLK_EN BIT(22)
54 #define BYT_RT5640_MCLK_25MHZ BIT(23)
56 struct byt_rt5640_private {
60 static unsigned long byt_rt5640_quirk = BYT_RT5640_MCLK_EN;
62 static void log_quirks(struct device *dev)
64 if (BYT_RT5640_MAP(byt_rt5640_quirk) == BYT_RT5640_DMIC1_MAP)
65 dev_info(dev, "quirk DMIC1_MAP enabled");
66 if (BYT_RT5640_MAP(byt_rt5640_quirk) == BYT_RT5640_DMIC2_MAP)
67 dev_info(dev, "quirk DMIC2_MAP enabled");
68 if (BYT_RT5640_MAP(byt_rt5640_quirk) == BYT_RT5640_IN1_MAP)
69 dev_info(dev, "quirk IN1_MAP enabled");
70 if (BYT_RT5640_MAP(byt_rt5640_quirk) == BYT_RT5640_IN3_MAP)
71 dev_info(dev, "quirk IN3_MAP enabled");
72 if (byt_rt5640_quirk & BYT_RT5640_DMIC_EN)
73 dev_info(dev, "quirk DMIC enabled");
74 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER)
75 dev_info(dev, "quirk MONO_SPEAKER enabled");
76 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
77 dev_info(dev, "quirk DIFF_MIC enabled");
78 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2)
79 dev_info(dev, "quirk SSP2_AIF2 enabled");
80 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1)
81 dev_info(dev, "quirk SSP0_AIF1 enabled");
82 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)
83 dev_info(dev, "quirk SSP0_AIF2 enabled");
84 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
85 dev_info(dev, "quirk MCLK_EN enabled");
86 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ)
87 dev_info(dev, "quirk MCLK_25MHZ enabled");
91 #define BYT_CODEC_DAI1 "rt5640-aif1"
92 #define BYT_CODEC_DAI2 "rt5640-aif2"
94 static inline struct snd_soc_dai *byt_get_codec_dai(struct snd_soc_card *card)
96 struct snd_soc_pcm_runtime *rtd;
98 list_for_each_entry(rtd, &card->rtd_list, list) {
99 if (!strncmp(rtd->codec_dai->name, BYT_CODEC_DAI1,
100 strlen(BYT_CODEC_DAI1)))
101 return rtd->codec_dai;
102 if (!strncmp(rtd->codec_dai->name, BYT_CODEC_DAI2,
103 strlen(BYT_CODEC_DAI2)))
104 return rtd->codec_dai;
110 static int platform_clock_control(struct snd_soc_dapm_widget *w,
111 struct snd_kcontrol *k, int event)
113 struct snd_soc_dapm_context *dapm = w->dapm;
114 struct snd_soc_card *card = dapm->card;
115 struct snd_soc_dai *codec_dai;
116 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
119 codec_dai = byt_get_codec_dai(card);
122 "Codec dai not found; Unable to set platform clock\n");
126 if (SND_SOC_DAPM_EVENT_ON(event)) {
127 if ((byt_rt5640_quirk & BYT_RT5640_MCLK_EN) && priv->mclk) {
128 ret = clk_prepare_enable(priv->mclk);
131 "could not configure MCLK state");
135 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
140 * Set codec clock source to internal clock before
141 * turning off the platform clock. Codec needs clock
142 * for Jack detection and button press
144 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_RCCLK,
148 if ((byt_rt5640_quirk & BYT_RT5640_MCLK_EN) && priv->mclk)
149 clk_disable_unprepare(priv->mclk);
154 dev_err(card->dev, "can't set codec sysclk: %d\n", ret);
161 static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
162 SND_SOC_DAPM_HP("Headphone", NULL),
163 SND_SOC_DAPM_MIC("Headset Mic", NULL),
164 SND_SOC_DAPM_MIC("Internal Mic", NULL),
165 SND_SOC_DAPM_SPK("Speaker", NULL),
166 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
167 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
168 SND_SOC_DAPM_POST_PMD),
172 static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
173 {"Headphone", NULL, "Platform Clock"},
174 {"Headset Mic", NULL, "Platform Clock"},
175 {"Headset Mic", NULL, "MICBIAS1"},
176 {"IN2P", NULL, "Headset Mic"},
177 {"Headphone", NULL, "HPOL"},
178 {"Headphone", NULL, "HPOR"},
181 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
182 {"Internal Mic", NULL, "Platform Clock"},
183 {"DMIC1", NULL, "Internal Mic"},
186 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
187 {"Internal Mic", NULL, "Platform Clock"},
188 {"DMIC2", NULL, "Internal Mic"},
191 static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
192 {"Internal Mic", NULL, "Platform Clock"},
193 {"Internal Mic", NULL, "MICBIAS1"},
194 {"IN1P", NULL, "Internal Mic"},
197 static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map[] = {
198 {"Internal Mic", NULL, "Platform Clock"},
199 {"Internal Mic", NULL, "MICBIAS1"},
200 {"IN3P", NULL, "Internal Mic"},
203 static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = {
204 {"ssp2 Tx", NULL, "codec_out0"},
205 {"ssp2 Tx", NULL, "codec_out1"},
206 {"codec_in0", NULL, "ssp2 Rx"},
207 {"codec_in1", NULL, "ssp2 Rx"},
209 {"AIF1 Playback", NULL, "ssp2 Tx"},
210 {"ssp2 Rx", NULL, "AIF1 Capture"},
213 static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_map[] = {
214 {"ssp2 Tx", NULL, "codec_out0"},
215 {"ssp2 Tx", NULL, "codec_out1"},
216 {"codec_in0", NULL, "ssp2 Rx"},
217 {"codec_in1", NULL, "ssp2 Rx"},
219 {"AIF2 Playback", NULL, "ssp2 Tx"},
220 {"ssp2 Rx", NULL, "AIF2 Capture"},
223 static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif1_map[] = {
224 {"ssp0 Tx", NULL, "modem_out"},
225 {"modem_in", NULL, "ssp0 Rx"},
227 {"AIF1 Playback", NULL, "ssp0 Tx"},
228 {"ssp0 Rx", NULL, "AIF1 Capture"},
231 static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif2_map[] = {
232 {"ssp0 Tx", NULL, "modem_out"},
233 {"modem_in", NULL, "ssp0 Rx"},
235 {"AIF2 Playback", NULL, "ssp0 Tx"},
236 {"ssp0 Rx", NULL, "AIF2 Capture"},
239 static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = {
240 {"Speaker", NULL, "Platform Clock"},
241 {"Speaker", NULL, "SPOLP"},
242 {"Speaker", NULL, "SPOLN"},
243 {"Speaker", NULL, "SPORP"},
244 {"Speaker", NULL, "SPORN"},
247 static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = {
248 {"Speaker", NULL, "Platform Clock"},
249 {"Speaker", NULL, "SPOLP"},
250 {"Speaker", NULL, "SPOLN"},
253 static const struct snd_kcontrol_new byt_rt5640_controls[] = {
254 SOC_DAPM_PIN_SWITCH("Headphone"),
255 SOC_DAPM_PIN_SWITCH("Headset Mic"),
256 SOC_DAPM_PIN_SWITCH("Internal Mic"),
257 SOC_DAPM_PIN_SWITCH("Speaker"),
260 static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream,
261 struct snd_pcm_hw_params *params)
263 struct snd_soc_pcm_runtime *rtd = substream->private_data;
264 struct snd_soc_dai *codec_dai = rtd->codec_dai;
267 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
268 params_rate(params) * 512,
272 dev_err(rtd->dev, "can't set codec clock %d\n", ret);
276 if (!(byt_rt5640_quirk & BYT_RT5640_MCLK_EN)) {
277 /* use bitclock as PLL input */
278 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
279 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
281 /* 2x16 bit slots on SSP0 */
282 ret = snd_soc_dai_set_pll(codec_dai, 0,
284 params_rate(params) * 32,
285 params_rate(params) * 512);
287 /* 2x15 bit slots on SSP2 */
288 ret = snd_soc_dai_set_pll(codec_dai, 0,
290 params_rate(params) * 50,
291 params_rate(params) * 512);
294 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
295 ret = snd_soc_dai_set_pll(codec_dai, 0,
298 params_rate(params) * 512);
300 ret = snd_soc_dai_set_pll(codec_dai, 0,
303 params_rate(params) * 512);
308 dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
315 static int byt_rt5640_quirk_cb(const struct dmi_system_id *id)
317 byt_rt5640_quirk = (unsigned long)id->driver_data;
321 static const struct dmi_system_id byt_rt5640_quirk_table[] = {
323 .callback = byt_rt5640_quirk_cb,
325 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
326 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
328 .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP |
332 .callback = byt_rt5640_quirk_cb,
334 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
335 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"),
337 .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP |
338 BYT_RT5640_MONO_SPEAKER |
339 BYT_RT5640_DIFF_MIC |
340 BYT_RT5640_SSP0_AIF2 |
345 .callback = byt_rt5640_quirk_cb,
347 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "DellInc."),
348 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
350 .driver_data = (unsigned long *)(BYT_RT5640_DMIC2_MAP |
355 .callback = byt_rt5640_quirk_cb,
357 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
358 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"),
360 .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP |
364 .callback = byt_rt5640_quirk_cb,
366 DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
367 DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"),
369 .driver_data = (unsigned long *)(BYT_RT5640_DMIC1_MAP |
373 .callback = byt_rt5640_quirk_cb,
375 DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"),
376 DMI_MATCH(DMI_BOARD_NAME, "tPAD"),
378 .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP |
380 BYT_RT5640_SSP0_AIF1),
383 .callback = byt_rt5640_quirk_cb,
385 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
386 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
388 .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP |
390 BYT_RT5640_SSP0_AIF1),
394 .callback = byt_rt5640_quirk_cb,
396 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
398 .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP |
400 BYT_RT5640_SSP0_AIF1),
406 static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
409 struct snd_soc_codec *codec = runtime->codec;
410 struct snd_soc_card *card = runtime->card;
411 const struct snd_soc_dapm_route *custom_map;
412 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
415 card->dapm.idle_bias_off = true;
417 rt5640_sel_asrc_clk_src(codec,
418 RT5640_DA_STEREO_FILTER |
419 RT5640_DA_MONO_L_FILTER |
420 RT5640_DA_MONO_R_FILTER |
421 RT5640_AD_STEREO_FILTER |
422 RT5640_AD_MONO_L_FILTER |
423 RT5640_AD_MONO_R_FILTER,
424 RT5640_CLK_SEL_ASRC);
426 ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
427 ARRAY_SIZE(byt_rt5640_controls));
429 dev_err(card->dev, "unable to add card controls\n");
433 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
434 case BYT_RT5640_IN1_MAP:
435 custom_map = byt_rt5640_intmic_in1_map;
436 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
438 case BYT_RT5640_IN3_MAP:
439 custom_map = byt_rt5640_intmic_in3_map;
440 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in3_map);
442 case BYT_RT5640_DMIC2_MAP:
443 custom_map = byt_rt5640_intmic_dmic2_map;
444 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
447 custom_map = byt_rt5640_intmic_dmic1_map;
448 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
451 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
455 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
456 ret = snd_soc_dapm_add_routes(&card->dapm,
457 byt_rt5640_ssp2_aif2_map,
458 ARRAY_SIZE(byt_rt5640_ssp2_aif2_map));
459 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
460 ret = snd_soc_dapm_add_routes(&card->dapm,
461 byt_rt5640_ssp0_aif1_map,
462 ARRAY_SIZE(byt_rt5640_ssp0_aif1_map));
463 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
464 ret = snd_soc_dapm_add_routes(&card->dapm,
465 byt_rt5640_ssp0_aif2_map,
466 ARRAY_SIZE(byt_rt5640_ssp0_aif2_map));
468 ret = snd_soc_dapm_add_routes(&card->dapm,
469 byt_rt5640_ssp2_aif1_map,
470 ARRAY_SIZE(byt_rt5640_ssp2_aif1_map));
475 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
476 ret = snd_soc_dapm_add_routes(&card->dapm,
477 byt_rt5640_mono_spk_map,
478 ARRAY_SIZE(byt_rt5640_mono_spk_map));
480 ret = snd_soc_dapm_add_routes(&card->dapm,
481 byt_rt5640_stereo_spk_map,
482 ARRAY_SIZE(byt_rt5640_stereo_spk_map));
487 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC) {
488 snd_soc_update_bits(codec, RT5640_IN1_IN2, RT5640_IN_DF1,
492 if (byt_rt5640_quirk & BYT_RT5640_DMIC_EN) {
493 ret = rt5640_dmic_enable(codec, 0, 0);
498 snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
499 snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
501 if ((byt_rt5640_quirk & BYT_RT5640_MCLK_EN) && priv->mclk) {
503 * The firmware might enable the clock at
504 * boot (this information may or may not
505 * be reflected in the enable clock register).
506 * To change the rate we must disable the clock
507 * first to cover these cases. Due to common
508 * clock framework restrictions that do not allow
509 * to disable a clock that has not been enabled,
510 * we need to enable the clock first.
512 ret = clk_prepare_enable(priv->mclk);
514 clk_disable_unprepare(priv->mclk);
516 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ)
517 ret = clk_set_rate(priv->mclk, 25000000);
519 ret = clk_set_rate(priv->mclk, 19200000);
522 dev_err(card->dev, "unable to set MCLK rate\n");
528 static const struct snd_soc_pcm_stream byt_rt5640_dai_params = {
529 .formats = SNDRV_PCM_FMTBIT_S24_LE,
536 static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd,
537 struct snd_pcm_hw_params *params)
539 struct snd_interval *rate = hw_param_interval(params,
540 SNDRV_PCM_HW_PARAM_RATE);
541 struct snd_interval *channels = hw_param_interval(params,
542 SNDRV_PCM_HW_PARAM_CHANNELS);
545 /* The DSP will covert the FE rate to 48k, stereo */
546 rate->min = rate->max = 48000;
547 channels->min = channels->max = 2;
549 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
550 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
552 /* set SSP0 to 16-bit */
553 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
556 * Default mode for SSP configuration is TDM 4 slot, override config
557 * with explicit setting to I2S 2ch 16-bit. The word length is set with
558 * dai_set_tdm_slot() since there is no other API exposed
560 ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
562 SND_SOC_DAIFMT_NB_IF |
563 SND_SOC_DAIFMT_CBS_CFS
566 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
570 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 16);
572 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
578 /* set SSP2 to 24-bit */
579 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
582 * Default mode for SSP configuration is TDM 4 slot, override config
583 * with explicit setting to I2S 2ch 24-bit. The word length is set with
584 * dai_set_tdm_slot() since there is no other API exposed
586 ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
588 SND_SOC_DAIFMT_NB_IF |
589 SND_SOC_DAIFMT_CBS_CFS
592 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
596 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24);
598 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
605 static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream)
607 return snd_pcm_hw_constraint_single(substream->runtime,
608 SNDRV_PCM_HW_PARAM_RATE, 48000);
611 static struct snd_soc_ops byt_rt5640_aif1_ops = {
612 .startup = byt_rt5640_aif1_startup,
615 static struct snd_soc_ops byt_rt5640_be_ssp2_ops = {
616 .hw_params = byt_rt5640_aif1_hw_params,
619 static struct snd_soc_dai_link byt_rt5640_dais[] = {
620 [MERR_DPCM_AUDIO] = {
621 .name = "Baytrail Audio Port",
622 .stream_name = "Baytrail Audio",
623 .cpu_dai_name = "media-cpu-dai",
624 .codec_dai_name = "snd-soc-dummy-dai",
625 .codec_name = "snd-soc-dummy",
626 .platform_name = "sst-mfld-platform",
631 .ops = &byt_rt5640_aif1_ops,
633 [MERR_DPCM_DEEP_BUFFER] = {
634 .name = "Deep-Buffer Audio Port",
635 .stream_name = "Deep-Buffer Audio",
636 .cpu_dai_name = "deepbuffer-cpu-dai",
637 .codec_dai_name = "snd-soc-dummy-dai",
638 .codec_name = "snd-soc-dummy",
639 .platform_name = "sst-mfld-platform",
643 .ops = &byt_rt5640_aif1_ops,
645 [MERR_DPCM_COMPR] = {
646 .name = "Baytrail Compressed Port",
647 .stream_name = "Baytrail Compress",
648 .cpu_dai_name = "compress-cpu-dai",
649 .codec_dai_name = "snd-soc-dummy-dai",
650 .codec_name = "snd-soc-dummy",
651 .platform_name = "sst-mfld-platform",
655 .name = "SSP2-Codec",
657 .cpu_dai_name = "ssp2-port", /* overwritten for ssp0 routing */
658 .platform_name = "sst-mfld-platform",
660 .codec_dai_name = "rt5640-aif1", /* changed w/ quirk */
661 .codec_name = "i2c-10EC5640:00", /* overwritten with HID */
662 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
663 | SND_SOC_DAIFMT_CBS_CFS,
664 .be_hw_params_fixup = byt_rt5640_codec_fixup,
669 .init = byt_rt5640_init,
670 .ops = &byt_rt5640_be_ssp2_ops,
675 static struct snd_soc_card byt_rt5640_card = {
676 .name = "bytcr-rt5640",
677 .owner = THIS_MODULE,
678 .dai_link = byt_rt5640_dais,
679 .num_links = ARRAY_SIZE(byt_rt5640_dais),
680 .dapm_widgets = byt_rt5640_widgets,
681 .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
682 .dapm_routes = byt_rt5640_audio_map,
683 .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
684 .fully_routed = true,
687 static char byt_rt5640_codec_name[16]; /* i2c-<HID>:00 with HID being 8 chars */
688 static char byt_rt5640_codec_aif_name[12]; /* = "rt5640-aif[1|2]" */
689 static char byt_rt5640_cpu_dai_name[10]; /* = "ssp[0|2]-port" */
691 static bool is_valleyview(void)
693 static const struct x86_cpu_id cpu_ids[] = {
694 { X86_VENDOR_INTEL, 6, 55 }, /* Valleyview, Bay Trail */
698 if (!x86_match_cpu(cpu_ids))
704 static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
707 struct sst_acpi_mach *mach;
708 const char *i2c_name = NULL;
711 struct byt_rt5640_private *priv;
713 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_ATOMIC);
717 /* register the soc card */
718 byt_rt5640_card.dev = &pdev->dev;
719 mach = byt_rt5640_card.dev->platform_data;
720 snd_soc_card_set_drvdata(&byt_rt5640_card, priv);
722 /* fix index of codec dai */
723 dai_index = MERR_DPCM_COMPR + 1;
724 for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) {
725 if (!strcmp(byt_rt5640_dais[i].codec_name, "i2c-10EC5640:00")) {
731 /* fixup codec name based on HID */
732 i2c_name = sst_acpi_find_name_from_hid(mach->id);
733 if (i2c_name != NULL) {
734 snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name),
735 "%s%s", "i2c-", i2c_name);
737 byt_rt5640_dais[dai_index].codec_name = byt_rt5640_codec_name;
741 * swap SSP0 if bytcr is detected
742 * (will be overridden if DMI quirk is detected)
744 if (is_valleyview()) {
745 struct sst_platform_info *p_info = mach->pdata;
746 const struct sst_res_info *res_info = p_info->res_info;
748 /* TODO: use CHAN package info from BIOS to detect AIF1/AIF2 */
749 if (res_info->acpi_ipc_irq_index == 0) {
750 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
753 /* change defaults for Baytrail-CR capture */
754 byt_rt5640_quirk |= BYT_RT5640_IN1_MAP;
755 byt_rt5640_quirk |= BYT_RT5640_DIFF_MIC;
757 byt_rt5640_quirk |= (BYT_RT5640_DMIC1_MAP |
761 /* check quirks before creating card */
762 dmi_check_system(byt_rt5640_quirk_table);
763 log_quirks(&pdev->dev);
765 if ((byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) ||
766 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
768 /* fixup codec aif name */
769 snprintf(byt_rt5640_codec_aif_name,
770 sizeof(byt_rt5640_codec_aif_name),
771 "%s", "rt5640-aif2");
773 byt_rt5640_dais[dai_index].codec_dai_name =
774 byt_rt5640_codec_aif_name;
777 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
778 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
780 /* fixup cpu dai name name */
781 snprintf(byt_rt5640_cpu_dai_name,
782 sizeof(byt_rt5640_cpu_dai_name),
785 byt_rt5640_dais[dai_index].cpu_dai_name =
786 byt_rt5640_cpu_dai_name;
789 if ((byt_rt5640_quirk & BYT_RT5640_MCLK_EN) && (is_valleyview())) {
790 priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
791 if (IS_ERR(priv->mclk)) {
793 "Failed to get MCLK from pmc_plt_clk_3: %ld\n",
794 PTR_ERR(priv->mclk));
795 return PTR_ERR(priv->mclk);
799 ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card);
802 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
806 platform_set_drvdata(pdev, &byt_rt5640_card);
810 static struct platform_driver snd_byt_rt5640_mc_driver = {
812 .name = "bytcr_rt5640",
814 .probe = snd_byt_rt5640_mc_probe,
817 module_platform_driver(snd_byt_rt5640_mc_driver);
819 MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
820 MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
821 MODULE_LICENSE("GPL v2");
822 MODULE_ALIAS("platform:bytcr_rt5640");