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 {"Internal Mic", NULL, "Platform Clock"},
230 {"Speaker", NULL, "Platform Clock"},
232 {"Headset Mic", NULL, "MICBIAS1"},
233 {"IN2P", NULL, "Headset Mic"},
234 {"Headphone", NULL, "HPOL"},
235 {"Headphone", NULL, "HPOR"},
238 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
239 {"DMIC1", NULL, "Internal Mic"},
242 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
243 {"DMIC2", NULL, "Internal Mic"},
246 static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
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, "MICBIAS1"},
253 {"IN3P", NULL, "Internal Mic"},
256 static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = {
257 {"ssp2 Tx", NULL, "codec_out0"},
258 {"ssp2 Tx", NULL, "codec_out1"},
259 {"codec_in0", NULL, "ssp2 Rx"},
260 {"codec_in1", NULL, "ssp2 Rx"},
262 {"AIF1 Playback", NULL, "ssp2 Tx"},
263 {"ssp2 Rx", NULL, "AIF1 Capture"},
266 static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_map[] = {
267 {"ssp2 Tx", NULL, "codec_out0"},
268 {"ssp2 Tx", NULL, "codec_out1"},
269 {"codec_in0", NULL, "ssp2 Rx"},
270 {"codec_in1", NULL, "ssp2 Rx"},
272 {"AIF2 Playback", NULL, "ssp2 Tx"},
273 {"ssp2 Rx", NULL, "AIF2 Capture"},
276 static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif1_map[] = {
277 {"ssp0 Tx", NULL, "modem_out"},
278 {"modem_in", NULL, "ssp0 Rx"},
280 {"AIF1 Playback", NULL, "ssp0 Tx"},
281 {"ssp0 Rx", NULL, "AIF1 Capture"},
284 static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif2_map[] = {
285 {"ssp0 Tx", NULL, "modem_out"},
286 {"modem_in", NULL, "ssp0 Rx"},
288 {"AIF2 Playback", NULL, "ssp0 Tx"},
289 {"ssp0 Rx", NULL, "AIF2 Capture"},
292 static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = {
293 {"Speaker", NULL, "SPOLP"},
294 {"Speaker", NULL, "SPOLN"},
295 {"Speaker", NULL, "SPORP"},
296 {"Speaker", NULL, "SPORN"},
299 static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = {
300 {"Speaker", NULL, "SPOLP"},
301 {"Speaker", NULL, "SPOLN"},
304 static const struct snd_kcontrol_new byt_rt5640_controls[] = {
305 SOC_DAPM_PIN_SWITCH("Headphone"),
306 SOC_DAPM_PIN_SWITCH("Headset Mic"),
307 SOC_DAPM_PIN_SWITCH("Internal Mic"),
308 SOC_DAPM_PIN_SWITCH("Speaker"),
311 static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream,
312 struct snd_pcm_hw_params *params)
314 struct snd_soc_pcm_runtime *rtd = substream->private_data;
315 struct snd_soc_dai *codec_dai = rtd->codec_dai;
318 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
319 params_rate(params) * 512,
323 dev_err(rtd->dev, "can't set codec clock %d\n", ret);
327 if (!(byt_rt5640_quirk & BYT_RT5640_MCLK_EN)) {
328 /* use bitclock as PLL input */
329 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
330 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
332 /* 2x16 bit slots on SSP0 */
333 ret = snd_soc_dai_set_pll(codec_dai, 0,
335 params_rate(params) * 32,
336 params_rate(params) * 512);
338 /* 2x15 bit slots on SSP2 */
339 ret = snd_soc_dai_set_pll(codec_dai, 0,
341 params_rate(params) * 50,
342 params_rate(params) * 512);
345 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
346 ret = snd_soc_dai_set_pll(codec_dai, 0,
349 params_rate(params) * 512);
351 ret = snd_soc_dai_set_pll(codec_dai, 0,
354 params_rate(params) * 512);
359 dev_err(rtd->dev, "can't set codec pll: %d\n", ret);
366 static int byt_rt5640_quirk_cb(const struct dmi_system_id *id)
368 byt_rt5640_quirk = (unsigned long)id->driver_data;
372 static const struct dmi_system_id byt_rt5640_quirk_table[] = {
374 .callback = byt_rt5640_quirk_cb,
376 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
377 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
379 .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP |
383 .callback = byt_rt5640_quirk_cb,
385 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
386 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"),
388 .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP |
389 BYT_RT5640_MONO_SPEAKER |
390 BYT_RT5640_DIFF_MIC |
391 BYT_RT5640_SSP0_AIF2 |
396 .callback = byt_rt5640_quirk_cb,
398 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "DellInc."),
399 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
401 .driver_data = (unsigned long *)(BYT_RT5640_DMIC2_MAP |
406 .callback = byt_rt5640_quirk_cb,
408 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
409 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"),
411 .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP |
415 .callback = byt_rt5640_quirk_cb,
417 DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
418 DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"),
420 .driver_data = (unsigned long *)(BYT_RT5640_DMIC1_MAP |
424 .callback = byt_rt5640_quirk_cb,
426 DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"),
427 DMI_MATCH(DMI_BOARD_NAME, "tPAD"),
429 .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP |
431 BYT_RT5640_SSP0_AIF1),
434 .callback = byt_rt5640_quirk_cb,
436 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
437 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
439 .driver_data = (unsigned long *)(BYT_RT5640_IN1_MAP |
441 BYT_RT5640_SSP0_AIF1),
445 .callback = byt_rt5640_quirk_cb,
447 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
449 .driver_data = (unsigned long *)(BYT_RT5640_IN3_MAP |
451 BYT_RT5640_SSP0_AIF1),
457 static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
460 struct snd_soc_codec *codec = runtime->codec;
461 struct snd_soc_card *card = runtime->card;
462 const struct snd_soc_dapm_route *custom_map;
463 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
466 card->dapm.idle_bias_off = true;
468 rt5640_sel_asrc_clk_src(codec,
469 RT5640_DA_STEREO_FILTER |
470 RT5640_DA_MONO_L_FILTER |
471 RT5640_DA_MONO_R_FILTER |
472 RT5640_AD_STEREO_FILTER |
473 RT5640_AD_MONO_L_FILTER |
474 RT5640_AD_MONO_R_FILTER,
475 RT5640_CLK_SEL_ASRC);
477 ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
478 ARRAY_SIZE(byt_rt5640_controls));
480 dev_err(card->dev, "unable to add card controls\n");
484 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
485 case BYT_RT5640_IN1_MAP:
486 custom_map = byt_rt5640_intmic_in1_map;
487 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
489 case BYT_RT5640_IN3_MAP:
490 custom_map = byt_rt5640_intmic_in3_map;
491 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in3_map);
493 case BYT_RT5640_DMIC2_MAP:
494 custom_map = byt_rt5640_intmic_dmic2_map;
495 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
498 custom_map = byt_rt5640_intmic_dmic1_map;
499 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
502 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
506 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
507 ret = snd_soc_dapm_add_routes(&card->dapm,
508 byt_rt5640_ssp2_aif2_map,
509 ARRAY_SIZE(byt_rt5640_ssp2_aif2_map));
510 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
511 ret = snd_soc_dapm_add_routes(&card->dapm,
512 byt_rt5640_ssp0_aif1_map,
513 ARRAY_SIZE(byt_rt5640_ssp0_aif1_map));
514 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
515 ret = snd_soc_dapm_add_routes(&card->dapm,
516 byt_rt5640_ssp0_aif2_map,
517 ARRAY_SIZE(byt_rt5640_ssp0_aif2_map));
519 ret = snd_soc_dapm_add_routes(&card->dapm,
520 byt_rt5640_ssp2_aif1_map,
521 ARRAY_SIZE(byt_rt5640_ssp2_aif1_map));
526 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
527 ret = snd_soc_dapm_add_routes(&card->dapm,
528 byt_rt5640_mono_spk_map,
529 ARRAY_SIZE(byt_rt5640_mono_spk_map));
531 ret = snd_soc_dapm_add_routes(&card->dapm,
532 byt_rt5640_stereo_spk_map,
533 ARRAY_SIZE(byt_rt5640_stereo_spk_map));
538 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC) {
539 snd_soc_update_bits(codec, RT5640_IN1_IN2, RT5640_IN_DF1,
543 if (byt_rt5640_quirk & BYT_RT5640_DMIC_EN) {
544 ret = rt5640_dmic_enable(codec, 0, 0);
549 snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
550 snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
552 if ((byt_rt5640_quirk & BYT_RT5640_MCLK_EN) && priv->mclk) {
554 * The firmware might enable the clock at
555 * boot (this information may or may not
556 * be reflected in the enable clock register).
557 * To change the rate we must disable the clock
558 * first to cover these cases. Due to common
559 * clock framework restrictions that do not allow
560 * to disable a clock that has not been enabled,
561 * we need to enable the clock first.
563 ret = clk_prepare_enable(priv->mclk);
565 clk_disable_unprepare(priv->mclk);
567 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ)
568 ret = clk_set_rate(priv->mclk, 25000000);
570 ret = clk_set_rate(priv->mclk, 19200000);
573 dev_err(card->dev, "unable to set MCLK rate\n");
579 static const struct snd_soc_pcm_stream byt_rt5640_dai_params = {
580 .formats = SNDRV_PCM_FMTBIT_S24_LE,
587 static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd,
588 struct snd_pcm_hw_params *params)
590 struct snd_interval *rate = hw_param_interval(params,
591 SNDRV_PCM_HW_PARAM_RATE);
592 struct snd_interval *channels = hw_param_interval(params,
593 SNDRV_PCM_HW_PARAM_CHANNELS);
596 /* The DSP will covert the FE rate to 48k, stereo */
597 rate->min = rate->max = 48000;
598 channels->min = channels->max = 2;
600 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
601 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
603 /* set SSP0 to 16-bit */
604 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
607 * Default mode for SSP configuration is TDM 4 slot, override config
608 * with explicit setting to I2S 2ch 16-bit. The word length is set with
609 * dai_set_tdm_slot() since there is no other API exposed
611 ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
613 SND_SOC_DAIFMT_NB_NF |
614 SND_SOC_DAIFMT_CBS_CFS
617 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
621 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 16);
623 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
629 /* set SSP2 to 24-bit */
630 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
633 * Default mode for SSP configuration is TDM 4 slot, override config
634 * with explicit setting to I2S 2ch 24-bit. The word length is set with
635 * dai_set_tdm_slot() since there is no other API exposed
637 ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
639 SND_SOC_DAIFMT_NB_NF |
640 SND_SOC_DAIFMT_CBS_CFS
643 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
647 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24);
649 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
656 static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream)
658 return snd_pcm_hw_constraint_single(substream->runtime,
659 SNDRV_PCM_HW_PARAM_RATE, 48000);
662 static const struct snd_soc_ops byt_rt5640_aif1_ops = {
663 .startup = byt_rt5640_aif1_startup,
666 static const struct snd_soc_ops byt_rt5640_be_ssp2_ops = {
667 .hw_params = byt_rt5640_aif1_hw_params,
670 static struct snd_soc_dai_link byt_rt5640_dais[] = {
671 [MERR_DPCM_AUDIO] = {
672 .name = "Baytrail Audio Port",
673 .stream_name = "Baytrail Audio",
674 .cpu_dai_name = "media-cpu-dai",
675 .codec_dai_name = "snd-soc-dummy-dai",
676 .codec_name = "snd-soc-dummy",
677 .platform_name = "sst-mfld-platform",
682 .ops = &byt_rt5640_aif1_ops,
684 [MERR_DPCM_DEEP_BUFFER] = {
685 .name = "Deep-Buffer Audio Port",
686 .stream_name = "Deep-Buffer Audio",
687 .cpu_dai_name = "deepbuffer-cpu-dai",
688 .codec_dai_name = "snd-soc-dummy-dai",
689 .codec_name = "snd-soc-dummy",
690 .platform_name = "sst-mfld-platform",
694 .ops = &byt_rt5640_aif1_ops,
696 [MERR_DPCM_COMPR] = {
697 .name = "Baytrail Compressed Port",
698 .stream_name = "Baytrail Compress",
699 .cpu_dai_name = "compress-cpu-dai",
700 .codec_dai_name = "snd-soc-dummy-dai",
701 .codec_name = "snd-soc-dummy",
702 .platform_name = "sst-mfld-platform",
706 .name = "SSP2-Codec",
708 .cpu_dai_name = "ssp2-port", /* overwritten for ssp0 routing */
709 .platform_name = "sst-mfld-platform",
711 .codec_dai_name = "rt5640-aif1", /* changed w/ quirk */
712 .codec_name = "i2c-10EC5640:00", /* overwritten with HID */
713 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
714 | SND_SOC_DAIFMT_CBS_CFS,
715 .be_hw_params_fixup = byt_rt5640_codec_fixup,
720 .init = byt_rt5640_init,
721 .ops = &byt_rt5640_be_ssp2_ops,
726 static struct snd_soc_card byt_rt5640_card = {
727 .name = "bytcr-rt5640",
728 .owner = THIS_MODULE,
729 .dai_link = byt_rt5640_dais,
730 .num_links = ARRAY_SIZE(byt_rt5640_dais),
731 .dapm_widgets = byt_rt5640_widgets,
732 .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
733 .dapm_routes = byt_rt5640_audio_map,
734 .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
735 .fully_routed = true,
738 static char byt_rt5640_codec_name[16]; /* i2c-<HID>:00 with HID being 8 chars */
739 static char byt_rt5640_codec_aif_name[12]; /* = "rt5640-aif[1|2]" */
740 static char byt_rt5640_cpu_dai_name[10]; /* = "ssp[0|2]-port" */
742 static bool is_valleyview(void)
744 static const struct x86_cpu_id cpu_ids[] = {
745 { X86_VENDOR_INTEL, 6, 55 }, /* Valleyview, Bay Trail */
749 if (!x86_match_cpu(cpu_ids))
754 struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */
755 u64 aif_value; /* 1: AIF1, 2: AIF2 */
756 u64 mclock_value; /* usually 25MHz (0x17d7940), ignored */
759 static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
762 struct sst_acpi_mach *mach;
763 const char *i2c_name = NULL;
766 struct byt_rt5640_private *priv;
769 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_ATOMIC);
773 /* register the soc card */
774 byt_rt5640_card.dev = &pdev->dev;
775 mach = byt_rt5640_card.dev->platform_data;
776 snd_soc_card_set_drvdata(&byt_rt5640_card, priv);
778 /* fix index of codec dai */
779 dai_index = MERR_DPCM_COMPR + 1;
780 for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) {
781 if (!strcmp(byt_rt5640_dais[i].codec_name, "i2c-10EC5640:00")) {
787 /* fixup codec name based on HID */
788 i2c_name = sst_acpi_find_name_from_hid(mach->id);
789 if (i2c_name != NULL) {
790 snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name),
791 "%s%s", "i2c-", i2c_name);
793 byt_rt5640_dais[dai_index].codec_name = byt_rt5640_codec_name;
797 * swap SSP0 if bytcr is detected
798 * (will be overridden if DMI quirk is detected)
800 if (is_valleyview()) {
801 struct sst_platform_info *p_info = mach->pdata;
802 const struct sst_res_info *res_info = p_info->res_info;
804 if (res_info->acpi_ipc_irq_index == 0)
810 * Baytrail CR platforms may have CHAN package in BIOS, try
811 * to find relevant routing quirk based as done on Windows
812 * platforms. We have to read the information directly from the
813 * BIOS, at this stage the card is not created and the links
814 * with the codec driver/pdata are non-existent
817 struct acpi_chan_package chan_package;
819 /* format specified: 2 64-bit integers */
820 struct acpi_buffer format = {sizeof("NN"), "NN"};
821 struct acpi_buffer state = {0, NULL};
822 struct sst_acpi_package_context pkg_ctx;
823 bool pkg_found = false;
825 state.length = sizeof(chan_package);
826 state.pointer = &chan_package;
828 pkg_ctx.name = "CHAN";
830 pkg_ctx.format = &format;
831 pkg_ctx.state = &state;
832 pkg_ctx.data_valid = false;
834 pkg_found = sst_acpi_find_package_from_hid(mach->id, &pkg_ctx);
836 if (chan_package.aif_value == 1) {
837 dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n");
838 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF1;
839 } else if (chan_package.aif_value == 2) {
840 dev_info(&pdev->dev, "BIOS Routing: AIF2 connected\n");
841 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
843 dev_info(&pdev->dev, "BIOS Routing isn't valid, ignored\n");
849 /* no BIOS indications, assume SSP0-AIF2 connection */
850 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
853 /* change defaults for Baytrail-CR capture */
854 byt_rt5640_quirk |= BYT_RT5640_IN1_MAP;
855 byt_rt5640_quirk |= BYT_RT5640_DIFF_MIC;
857 byt_rt5640_quirk |= (BYT_RT5640_DMIC1_MAP |
861 /* check quirks before creating card */
862 dmi_check_system(byt_rt5640_quirk_table);
863 if (quirk_override) {
864 dev_info(&pdev->dev, "Overriding quirk 0x%x => 0x%x\n",
865 (unsigned int)byt_rt5640_quirk, quirk_override);
866 byt_rt5640_quirk = quirk_override;
868 log_quirks(&pdev->dev);
870 if ((byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) ||
871 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
873 /* fixup codec aif name */
874 snprintf(byt_rt5640_codec_aif_name,
875 sizeof(byt_rt5640_codec_aif_name),
876 "%s", "rt5640-aif2");
878 byt_rt5640_dais[dai_index].codec_dai_name =
879 byt_rt5640_codec_aif_name;
882 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
883 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
885 /* fixup cpu dai name name */
886 snprintf(byt_rt5640_cpu_dai_name,
887 sizeof(byt_rt5640_cpu_dai_name),
890 byt_rt5640_dais[dai_index].cpu_dai_name =
891 byt_rt5640_cpu_dai_name;
894 if ((byt_rt5640_quirk & BYT_RT5640_MCLK_EN) && (is_valleyview())) {
895 priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
896 if (IS_ERR(priv->mclk)) {
897 ret_val = PTR_ERR(priv->mclk);
900 "Failed to get MCLK from pmc_plt_clk_3: %d\n",
904 * Fall back to bit clock usage for -ENOENT (clock not
905 * available likely due to missing dependencies), bail
906 * for all other errors, including -EPROBE_DEFER
908 if (ret_val != -ENOENT)
910 byt_rt5640_quirk &= ~BYT_RT5640_MCLK_EN;
914 ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card);
917 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
921 platform_set_drvdata(pdev, &byt_rt5640_card);
925 static struct platform_driver snd_byt_rt5640_mc_driver = {
927 .name = "bytcr_rt5640",
929 .probe = snd_byt_rt5640_mc_probe,
932 module_platform_driver(snd_byt_rt5640_mc_driver);
934 MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
935 MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
936 MODULE_LICENSE("GPL v2");
937 MODULE_ALIAS("platform:bytcr_rt5640");