ASoC: Intel: bytcr_rt5640: Add line-out support
[linux-2.6-microblaze.git] / sound / soc / intel / boards / bytcr_rt5640.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  *  byt_cr_dpcm_rt5640.c - ASoc Machine driver for Intel Byt CR platform
4  *
5  *  Copyright (C) 2014 Intel Corp
6  *  Author: Subhransu S. Prusty <subhransu.s.prusty@intel.com>
7  *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8  *
9  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10  */
11
12 #include <linux/i2c.h>
13 #include <linux/init.h>
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/platform_device.h>
17 #include <linux/acpi.h>
18 #include <linux/clk.h>
19 #include <linux/device.h>
20 #include <linux/dmi.h>
21 #include <linux/input.h>
22 #include <linux/slab.h>
23 #include <sound/pcm.h>
24 #include <sound/pcm_params.h>
25 #include <sound/soc.h>
26 #include <sound/jack.h>
27 #include <sound/soc-acpi.h>
28 #include <dt-bindings/sound/rt5640.h>
29 #include "../../codecs/rt5640.h"
30 #include "../atom/sst-atom-controls.h"
31 #include "../common/soc-intel-quirks.h"
32
33 enum {
34         BYT_RT5640_DMIC1_MAP,
35         BYT_RT5640_DMIC2_MAP,
36         BYT_RT5640_IN1_MAP,
37         BYT_RT5640_IN3_MAP,
38         BYT_RT5640_NO_INTERNAL_MIC_MAP,
39 };
40
41 enum {
42         BYT_RT5640_JD_SRC_GPIO1         = (RT5640_JD_SRC_GPIO1 << 4),
43         BYT_RT5640_JD_SRC_JD1_IN4P      = (RT5640_JD_SRC_JD1_IN4P << 4),
44         BYT_RT5640_JD_SRC_JD2_IN4N      = (RT5640_JD_SRC_JD2_IN4N << 4),
45         BYT_RT5640_JD_SRC_GPIO2         = (RT5640_JD_SRC_GPIO2 << 4),
46         BYT_RT5640_JD_SRC_GPIO3         = (RT5640_JD_SRC_GPIO3 << 4),
47         BYT_RT5640_JD_SRC_GPIO4         = (RT5640_JD_SRC_GPIO4 << 4),
48 };
49
50 enum {
51         BYT_RT5640_OVCD_TH_600UA        = (6 << 8),
52         BYT_RT5640_OVCD_TH_1500UA       = (15 << 8),
53         BYT_RT5640_OVCD_TH_2000UA       = (20 << 8),
54 };
55
56 enum {
57         BYT_RT5640_OVCD_SF_0P5          = (RT5640_OVCD_SF_0P5 << 13),
58         BYT_RT5640_OVCD_SF_0P75         = (RT5640_OVCD_SF_0P75 << 13),
59         BYT_RT5640_OVCD_SF_1P0          = (RT5640_OVCD_SF_1P0 << 13),
60         BYT_RT5640_OVCD_SF_1P5          = (RT5640_OVCD_SF_1P5 << 13),
61 };
62
63 #define BYT_RT5640_MAP(quirk)           ((quirk) &  GENMASK(3, 0))
64 #define BYT_RT5640_JDSRC(quirk)         (((quirk) & GENMASK(7, 4)) >> 4)
65 #define BYT_RT5640_OVCD_TH(quirk)       (((quirk) & GENMASK(12, 8)) >> 8)
66 #define BYT_RT5640_OVCD_SF(quirk)       (((quirk) & GENMASK(14, 13)) >> 13)
67 #define BYT_RT5640_JD_NOT_INV           BIT(16)
68 #define BYT_RT5640_MONO_SPEAKER         BIT(17)
69 #define BYT_RT5640_DIFF_MIC             BIT(18) /* default is single-ended */
70 #define BYT_RT5640_SSP2_AIF2            BIT(19) /* default is using AIF1  */
71 #define BYT_RT5640_SSP0_AIF1            BIT(20)
72 #define BYT_RT5640_SSP0_AIF2            BIT(21)
73 #define BYT_RT5640_MCLK_EN              BIT(22)
74 #define BYT_RT5640_MCLK_25MHZ           BIT(23)
75 #define BYT_RT5640_NO_SPEAKERS          BIT(24)
76 #define BYT_RT5640_LINEOUT              BIT(25)
77
78 #define BYTCR_INPUT_DEFAULTS                            \
79         (BYT_RT5640_IN3_MAP |                           \
80          BYT_RT5640_JD_SRC_JD1_IN4P |                   \
81          BYT_RT5640_OVCD_TH_2000UA |                    \
82          BYT_RT5640_OVCD_SF_0P75 |                      \
83          BYT_RT5640_DIFF_MIC)
84
85 /* in-diff or dmic-pin + jdsrc + ovcd-th + -sf + jd-inv + terminating entry */
86 #define MAX_NO_PROPS 6
87
88 struct byt_rt5640_private {
89         struct snd_soc_jack jack;
90         struct clk *mclk;
91 };
92 static bool is_bytcr;
93
94 static unsigned long byt_rt5640_quirk = BYT_RT5640_MCLK_EN;
95 static int quirk_override = -1;
96 module_param_named(quirk, quirk_override, int, 0444);
97 MODULE_PARM_DESC(quirk, "Board-specific quirk override");
98
99 static void log_quirks(struct device *dev)
100 {
101         int map;
102         bool has_mclk = false;
103         bool has_ssp0 = false;
104         bool has_ssp0_aif1 = false;
105         bool has_ssp0_aif2 = false;
106         bool has_ssp2_aif2 = false;
107
108         map = BYT_RT5640_MAP(byt_rt5640_quirk);
109         switch (map) {
110         case BYT_RT5640_DMIC1_MAP:
111                 dev_info(dev, "quirk DMIC1_MAP enabled\n");
112                 break;
113         case BYT_RT5640_DMIC2_MAP:
114                 dev_info(dev, "quirk DMIC2_MAP enabled\n");
115                 break;
116         case BYT_RT5640_IN1_MAP:
117                 dev_info(dev, "quirk IN1_MAP enabled\n");
118                 break;
119         case BYT_RT5640_IN3_MAP:
120                 dev_info(dev, "quirk IN3_MAP enabled\n");
121                 break;
122         case BYT_RT5640_NO_INTERNAL_MIC_MAP:
123                 dev_info(dev, "quirk NO_INTERNAL_MIC_MAP enabled\n");
124                 break;
125         default:
126                 dev_err(dev, "quirk map 0x%x is not supported, microphone input will not work\n", map);
127                 break;
128         }
129         if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
130                 dev_info(dev, "quirk realtek,jack-detect-source %ld\n",
131                          BYT_RT5640_JDSRC(byt_rt5640_quirk));
132                 dev_info(dev, "quirk realtek,over-current-threshold-microamp %ld\n",
133                          BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
134                 dev_info(dev, "quirk realtek,over-current-scale-factor %ld\n",
135                          BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
136         }
137         if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
138                 dev_info(dev, "quirk JD_NOT_INV enabled\n");
139         if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER)
140                 dev_info(dev, "quirk MONO_SPEAKER enabled\n");
141         if (byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS)
142                 dev_info(dev, "quirk NO_SPEAKERS enabled\n");
143         if (byt_rt5640_quirk & BYT_RT5640_LINEOUT)
144                 dev_info(dev, "quirk LINEOUT enabled\n");
145         if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
146                 dev_info(dev, "quirk DIFF_MIC enabled\n");
147         if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
148                 dev_info(dev, "quirk SSP0_AIF1 enabled\n");
149                 has_ssp0 = true;
150                 has_ssp0_aif1 = true;
151         }
152         if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
153                 dev_info(dev, "quirk SSP0_AIF2 enabled\n");
154                 has_ssp0 = true;
155                 has_ssp0_aif2 = true;
156         }
157         if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
158                 dev_info(dev, "quirk SSP2_AIF2 enabled\n");
159                 has_ssp2_aif2 = true;
160         }
161         if (is_bytcr && !has_ssp0)
162                 dev_err(dev, "Invalid routing, bytcr detected but no SSP0-based quirk, audio cannot work with SSP2 on bytcr\n");
163         if (has_ssp0_aif1 && has_ssp0_aif2)
164                 dev_err(dev, "Invalid routing, SSP0 cannot be connected to both AIF1 and AIF2\n");
165         if (has_ssp0 && has_ssp2_aif2)
166                 dev_err(dev, "Invalid routing, cannot have both SSP0 and SSP2 connected to codec\n");
167
168         if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
169                 dev_info(dev, "quirk MCLK_EN enabled\n");
170                 has_mclk = true;
171         }
172         if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
173                 if (has_mclk)
174                         dev_info(dev, "quirk MCLK_25MHZ enabled\n");
175                 else
176                         dev_err(dev, "quirk MCLK_25MHZ enabled but quirk MCLK not selected, will be ignored\n");
177         }
178 }
179
180 static int byt_rt5640_prepare_and_enable_pll1(struct snd_soc_dai *codec_dai,
181                                               int rate)
182 {
183         int ret;
184
185         /* Configure the PLL before selecting it */
186         if (!(byt_rt5640_quirk & BYT_RT5640_MCLK_EN)) {
187                 /* use bitclock as PLL input */
188                 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
189                     (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
190                         /* 2x16 bit slots on SSP0 */
191                         ret = snd_soc_dai_set_pll(codec_dai, 0,
192                                                   RT5640_PLL1_S_BCLK1,
193                                                   rate * 32, rate * 512);
194                 } else {
195                         /* 2x15 bit slots on SSP2 */
196                         ret = snd_soc_dai_set_pll(codec_dai, 0,
197                                                   RT5640_PLL1_S_BCLK1,
198                                                   rate * 50, rate * 512);
199                 }
200         } else {
201                 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
202                         ret = snd_soc_dai_set_pll(codec_dai, 0,
203                                                   RT5640_PLL1_S_MCLK,
204                                                   25000000, rate * 512);
205                 } else {
206                         ret = snd_soc_dai_set_pll(codec_dai, 0,
207                                                   RT5640_PLL1_S_MCLK,
208                                                   19200000, rate * 512);
209                 }
210         }
211
212         if (ret < 0) {
213                 dev_err(codec_dai->component->dev, "can't set pll: %d\n", ret);
214                 return ret;
215         }
216
217         ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
218                                      rate * 512, SND_SOC_CLOCK_IN);
219         if (ret < 0) {
220                 dev_err(codec_dai->component->dev, "can't set clock %d\n", ret);
221                 return ret;
222         }
223
224         return 0;
225 }
226
227 #define BYT_CODEC_DAI1  "rt5640-aif1"
228 #define BYT_CODEC_DAI2  "rt5640-aif2"
229
230 static int platform_clock_control(struct snd_soc_dapm_widget *w,
231                                   struct snd_kcontrol *k, int  event)
232 {
233         struct snd_soc_dapm_context *dapm = w->dapm;
234         struct snd_soc_card *card = dapm->card;
235         struct snd_soc_dai *codec_dai;
236         struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
237         int ret;
238
239         codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI1);
240         if (!codec_dai)
241                 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI2);
242
243         if (!codec_dai) {
244                 dev_err(card->dev,
245                         "Codec dai not found; Unable to set platform clock\n");
246                 return -EIO;
247         }
248
249         if (SND_SOC_DAPM_EVENT_ON(event)) {
250                 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
251                         ret = clk_prepare_enable(priv->mclk);
252                         if (ret < 0) {
253                                 dev_err(card->dev,
254                                         "could not configure MCLK state\n");
255                                 return ret;
256                         }
257                 }
258                 ret = byt_rt5640_prepare_and_enable_pll1(codec_dai, 48000);
259         } else {
260                 /*
261                  * Set codec clock source to internal clock before
262                  * turning off the platform clock. Codec needs clock
263                  * for Jack detection and button press
264                  */
265                 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_RCCLK,
266                                              48000 * 512,
267                                              SND_SOC_CLOCK_IN);
268                 if (!ret) {
269                         if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
270                                 clk_disable_unprepare(priv->mclk);
271                 }
272         }
273
274         if (ret < 0) {
275                 dev_err(card->dev, "can't set codec sysclk: %d\n", ret);
276                 return ret;
277         }
278
279         return 0;
280 }
281
282 static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
283         SND_SOC_DAPM_HP("Headphone", NULL),
284         SND_SOC_DAPM_MIC("Headset Mic", NULL),
285         SND_SOC_DAPM_MIC("Internal Mic", NULL),
286         SND_SOC_DAPM_SPK("Speaker", NULL),
287         SND_SOC_DAPM_LINE("Line Out", NULL),
288         SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
289                             platform_clock_control, SND_SOC_DAPM_PRE_PMU |
290                             SND_SOC_DAPM_POST_PMD),
291 };
292
293 static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
294         {"Headphone", NULL, "Platform Clock"},
295         {"Headset Mic", NULL, "Platform Clock"},
296         {"Headset Mic", NULL, "MICBIAS1"},
297         {"IN2P", NULL, "Headset Mic"},
298         {"Headphone", NULL, "HPOL"},
299         {"Headphone", NULL, "HPOR"},
300 };
301
302 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
303         {"Internal Mic", NULL, "Platform Clock"},
304         {"DMIC1", NULL, "Internal Mic"},
305 };
306
307 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
308         {"Internal Mic", NULL, "Platform Clock"},
309         {"DMIC2", NULL, "Internal Mic"},
310 };
311
312 static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
313         {"Internal Mic", NULL, "Platform Clock"},
314         {"Internal Mic", NULL, "MICBIAS1"},
315         {"IN1P", NULL, "Internal Mic"},
316 };
317
318 static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map[] = {
319         {"Internal Mic", NULL, "Platform Clock"},
320         {"Internal Mic", NULL, "MICBIAS1"},
321         {"IN3P", NULL, "Internal Mic"},
322 };
323
324 static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = {
325         {"ssp2 Tx", NULL, "codec_out0"},
326         {"ssp2 Tx", NULL, "codec_out1"},
327         {"codec_in0", NULL, "ssp2 Rx"},
328         {"codec_in1", NULL, "ssp2 Rx"},
329
330         {"AIF1 Playback", NULL, "ssp2 Tx"},
331         {"ssp2 Rx", NULL, "AIF1 Capture"},
332 };
333
334 static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_map[] = {
335         {"ssp2 Tx", NULL, "codec_out0"},
336         {"ssp2 Tx", NULL, "codec_out1"},
337         {"codec_in0", NULL, "ssp2 Rx"},
338         {"codec_in1", NULL, "ssp2 Rx"},
339
340         {"AIF2 Playback", NULL, "ssp2 Tx"},
341         {"ssp2 Rx", NULL, "AIF2 Capture"},
342 };
343
344 static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif1_map[] = {
345         {"ssp0 Tx", NULL, "modem_out"},
346         {"modem_in", NULL, "ssp0 Rx"},
347
348         {"AIF1 Playback", NULL, "ssp0 Tx"},
349         {"ssp0 Rx", NULL, "AIF1 Capture"},
350 };
351
352 static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif2_map[] = {
353         {"ssp0 Tx", NULL, "modem_out"},
354         {"modem_in", NULL, "ssp0 Rx"},
355
356         {"AIF2 Playback", NULL, "ssp0 Tx"},
357         {"ssp0 Rx", NULL, "AIF2 Capture"},
358 };
359
360 static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = {
361         {"Speaker", NULL, "Platform Clock"},
362         {"Speaker", NULL, "SPOLP"},
363         {"Speaker", NULL, "SPOLN"},
364         {"Speaker", NULL, "SPORP"},
365         {"Speaker", NULL, "SPORN"},
366 };
367
368 static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = {
369         {"Speaker", NULL, "Platform Clock"},
370         {"Speaker", NULL, "SPOLP"},
371         {"Speaker", NULL, "SPOLN"},
372 };
373
374 static const struct snd_soc_dapm_route byt_rt5640_lineout_map[] = {
375         {"Line Out", NULL, "Platform Clock"},
376         {"Line Out", NULL, "LOUTR"},
377         {"Line Out", NULL, "LOUTL"},
378 };
379
380 static const struct snd_kcontrol_new byt_rt5640_controls[] = {
381         SOC_DAPM_PIN_SWITCH("Headphone"),
382         SOC_DAPM_PIN_SWITCH("Headset Mic"),
383         SOC_DAPM_PIN_SWITCH("Internal Mic"),
384         SOC_DAPM_PIN_SWITCH("Speaker"),
385         SOC_DAPM_PIN_SWITCH("Line Out"),
386 };
387
388 static struct snd_soc_jack_pin rt5640_pins[] = {
389         {
390                 .pin    = "Headphone",
391                 .mask   = SND_JACK_HEADPHONE,
392         },
393         {
394                 .pin    = "Headset Mic",
395                 .mask   = SND_JACK_MICROPHONE,
396         },
397 };
398
399 static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream,
400                                         struct snd_pcm_hw_params *params)
401 {
402         struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
403         struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
404
405         return byt_rt5640_prepare_and_enable_pll1(dai, params_rate(params));
406 }
407
408 /* Please keep this list alphabetically sorted */
409 static const struct dmi_system_id byt_rt5640_quirk_table[] = {
410         {       /* Acer Iconia Tab 8 W1-810 */
411                 .matches = {
412                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"),
413                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Iconia W1-810"),
414                 },
415                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
416                                         BYT_RT5640_JD_SRC_JD1_IN4P |
417                                         BYT_RT5640_OVCD_TH_1500UA |
418                                         BYT_RT5640_OVCD_SF_0P75 |
419                                         BYT_RT5640_SSP0_AIF1 |
420                                         BYT_RT5640_MCLK_EN),
421         },
422         {       /* Acer One 10 S1002 */
423                 .matches = {
424                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
425                         DMI_MATCH(DMI_PRODUCT_NAME, "One S1002"),
426                 },
427                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
428                                         BYT_RT5640_JD_SRC_JD2_IN4N |
429                                         BYT_RT5640_OVCD_TH_2000UA |
430                                         BYT_RT5640_OVCD_SF_0P75 |
431                                         BYT_RT5640_DIFF_MIC |
432                                         BYT_RT5640_SSP0_AIF2 |
433                                         BYT_RT5640_MCLK_EN),
434         },
435         {
436                 .matches = {
437                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
438                         DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
439                 },
440                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
441                                         BYT_RT5640_JD_SRC_JD2_IN4N |
442                                         BYT_RT5640_OVCD_TH_2000UA |
443                                         BYT_RT5640_OVCD_SF_0P75 |
444                                         BYT_RT5640_SSP0_AIF1 |
445                                         BYT_RT5640_MCLK_EN),
446         },
447         {
448                 .matches = {
449                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
450                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 80 Cesium"),
451                 },
452                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
453                                         BYT_RT5640_MONO_SPEAKER |
454                                         BYT_RT5640_SSP0_AIF1 |
455                                         BYT_RT5640_MCLK_EN),
456         },
457         {
458                 .matches = {
459                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
460                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 140 CESIUM"),
461                 },
462                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
463                                         BYT_RT5640_JD_SRC_JD2_IN4N |
464                                         BYT_RT5640_OVCD_TH_2000UA |
465                                         BYT_RT5640_OVCD_SF_0P75 |
466                                         BYT_RT5640_SSP0_AIF1 |
467                                         BYT_RT5640_MCLK_EN),
468         },
469         {
470                 .matches = {
471                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
472                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ME176C"),
473                 },
474                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
475                                         BYT_RT5640_JD_SRC_JD2_IN4N |
476                                         BYT_RT5640_OVCD_TH_2000UA |
477                                         BYT_RT5640_OVCD_SF_0P75 |
478                                         BYT_RT5640_SSP0_AIF1 |
479                                         BYT_RT5640_MCLK_EN),
480         },
481         {
482                 .matches = {
483                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
484                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
485                 },
486                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
487                                         BYT_RT5640_JD_SRC_JD2_IN4N |
488                                         BYT_RT5640_OVCD_TH_2000UA |
489                                         BYT_RT5640_OVCD_SF_0P75 |
490                                         BYT_RT5640_MCLK_EN),
491         },
492         {
493                 .matches = {
494                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
495                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"),
496                 },
497                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
498                                         BYT_RT5640_JD_SRC_JD2_IN4N |
499                                         BYT_RT5640_OVCD_TH_2000UA |
500                                         BYT_RT5640_OVCD_SF_0P75 |
501                                         BYT_RT5640_MONO_SPEAKER |
502                                         BYT_RT5640_DIFF_MIC |
503                                         BYT_RT5640_SSP0_AIF2 |
504                                         BYT_RT5640_MCLK_EN),
505         },
506         {       /* Chuwi Vi8 (CWI506) */
507                 .matches = {
508                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Insyde"),
509                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "i86"),
510                         /* The above are too generic, also match BIOS info */
511                         DMI_MATCH(DMI_BIOS_VERSION, "CHUWI.D86JLBNR"),
512                 },
513                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
514                                         BYT_RT5640_MONO_SPEAKER |
515                                         BYT_RT5640_SSP0_AIF1 |
516                                         BYT_RT5640_MCLK_EN),
517         },
518         {
519                 /* Chuwi Vi10 (CWI505) */
520                 .matches = {
521                         DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
522                         DMI_MATCH(DMI_BOARD_NAME, "BYT-PF02"),
523                         DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
524                         DMI_MATCH(DMI_PRODUCT_NAME, "S165"),
525                 },
526                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
527                                         BYT_RT5640_JD_SRC_JD2_IN4N |
528                                         BYT_RT5640_OVCD_TH_2000UA |
529                                         BYT_RT5640_OVCD_SF_0P75 |
530                                         BYT_RT5640_DIFF_MIC |
531                                         BYT_RT5640_SSP0_AIF1 |
532                                         BYT_RT5640_MCLK_EN),
533         },
534         {
535                 /* Chuwi Hi8 (CWI509) */
536                 .matches = {
537                         DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
538                         DMI_MATCH(DMI_BOARD_NAME, "BYT-PA03C"),
539                         DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
540                         DMI_MATCH(DMI_PRODUCT_NAME, "S806"),
541                 },
542                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
543                                         BYT_RT5640_JD_SRC_JD2_IN4N |
544                                         BYT_RT5640_OVCD_TH_2000UA |
545                                         BYT_RT5640_OVCD_SF_0P75 |
546                                         BYT_RT5640_MONO_SPEAKER |
547                                         BYT_RT5640_DIFF_MIC |
548                                         BYT_RT5640_SSP0_AIF1 |
549                                         BYT_RT5640_MCLK_EN),
550         },
551         {
552                 .matches = {
553                         DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
554                         DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"),
555                 },
556                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP),
557         },
558         {       /* Connect Tablet 9 */
559                 .matches = {
560                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Connect"),
561                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Tablet 9"),
562                 },
563                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
564                                         BYT_RT5640_MONO_SPEAKER |
565                                         BYT_RT5640_SSP0_AIF1 |
566                                         BYT_RT5640_MCLK_EN),
567         },
568         {
569                 .matches = {
570                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
571                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
572                 },
573                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
574                                         BYT_RT5640_JD_SRC_JD2_IN4N |
575                                         BYT_RT5640_OVCD_TH_2000UA |
576                                         BYT_RT5640_OVCD_SF_0P75 |
577                                         BYT_RT5640_MONO_SPEAKER |
578                                         BYT_RT5640_MCLK_EN),
579         },
580         {       /* Estar Beauty HD MID 7316R */
581                 .matches = {
582                         DMI_MATCH(DMI_SYS_VENDOR, "Estar"),
583                         DMI_MATCH(DMI_PRODUCT_NAME, "eSTAR BEAUTY HD Intel Quad core"),
584                 },
585                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
586                                         BYT_RT5640_MONO_SPEAKER |
587                                         BYT_RT5640_SSP0_AIF1 |
588                                         BYT_RT5640_MCLK_EN),
589         },
590         {       /* Glavey TM800A550L */
591                 .matches = {
592                         DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
593                         DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
594                         /* Above strings are too generic, also match on BIOS version */
595                         DMI_MATCH(DMI_BIOS_VERSION, "ZY-8-BI-PX4S70VTR400-X423B-005-D"),
596                 },
597                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
598                                         BYT_RT5640_SSP0_AIF1 |
599                                         BYT_RT5640_MCLK_EN),
600         },
601         {
602                 .matches = {
603                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
604                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"),
605                 },
606                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
607                                         BYT_RT5640_MCLK_EN),
608         },
609         {       /* HP Pavilion x2 10-k0XX, 10-n0XX */
610                 .matches = {
611                         DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
612                         DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion x2 Detachable"),
613                 },
614                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
615                                         BYT_RT5640_JD_SRC_JD2_IN4N |
616                                         BYT_RT5640_OVCD_TH_1500UA |
617                                         BYT_RT5640_OVCD_SF_0P75 |
618                                         BYT_RT5640_SSP0_AIF1 |
619                                         BYT_RT5640_MCLK_EN),
620         },
621         {       /* HP Pavilion x2 10-p0XX */
622                 .matches = {
623                         DMI_MATCH(DMI_SYS_VENDOR, "HP"),
624                         DMI_MATCH(DMI_PRODUCT_NAME, "HP x2 Detachable 10-p0XX"),
625                 },
626                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
627                                         BYT_RT5640_JD_SRC_JD1_IN4P |
628                                         BYT_RT5640_OVCD_TH_2000UA |
629                                         BYT_RT5640_OVCD_SF_0P75 |
630                                         BYT_RT5640_MCLK_EN),
631         },
632         {       /* HP Stream 7 */
633                 .matches = {
634                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
635                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP Stream 7 Tablet"),
636                 },
637                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
638                                         BYT_RT5640_MONO_SPEAKER |
639                                         BYT_RT5640_JD_NOT_INV |
640                                         BYT_RT5640_SSP0_AIF1 |
641                                         BYT_RT5640_MCLK_EN),
642         },
643         {       /* I.T.Works TW891 */
644                 .matches = {
645                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "To be filled by O.E.M."),
646                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TW891"),
647                         DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "To be filled by O.E.M."),
648                         DMI_EXACT_MATCH(DMI_BOARD_NAME, "TW891"),
649                 },
650                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
651                                         BYT_RT5640_MONO_SPEAKER |
652                                         BYT_RT5640_SSP0_AIF1 |
653                                         BYT_RT5640_MCLK_EN),
654         },
655         {       /* Lamina I8270 / T701BR.SE */
656                 .matches = {
657                         DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Lamina"),
658                         DMI_EXACT_MATCH(DMI_BOARD_NAME, "T701BR.SE"),
659                 },
660                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
661                                         BYT_RT5640_MONO_SPEAKER |
662                                         BYT_RT5640_JD_NOT_INV |
663                                         BYT_RT5640_SSP0_AIF1 |
664                                         BYT_RT5640_MCLK_EN),
665         },
666         {       /* Lenovo Miix 2 8 */
667                 .matches = {
668                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
669                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "20326"),
670                         DMI_EXACT_MATCH(DMI_BOARD_NAME, "Hiking"),
671                 },
672                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
673                                         BYT_RT5640_JD_SRC_JD2_IN4N |
674                                         BYT_RT5640_OVCD_TH_2000UA |
675                                         BYT_RT5640_OVCD_SF_0P75 |
676                                         BYT_RT5640_MONO_SPEAKER |
677                                         BYT_RT5640_MCLK_EN),
678         },
679         {       /* Lenovo Miix 3-830 */
680                 .matches = {
681                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
682                         DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 3-830"),
683                 },
684                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
685                                         BYT_RT5640_JD_SRC_JD2_IN4N |
686                                         BYT_RT5640_OVCD_TH_2000UA |
687                                         BYT_RT5640_OVCD_SF_0P75 |
688                                         BYT_RT5640_MONO_SPEAKER |
689                                         BYT_RT5640_DIFF_MIC |
690                                         BYT_RT5640_SSP0_AIF1 |
691                                         BYT_RT5640_MCLK_EN),
692         },
693         {       /* Linx Linx7 tablet */
694                 .matches = {
695                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LINX"),
696                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "LINX7"),
697                 },
698                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
699                                         BYT_RT5640_MONO_SPEAKER |
700                                         BYT_RT5640_JD_NOT_INV |
701                                         BYT_RT5640_SSP0_AIF1 |
702                                         BYT_RT5640_MCLK_EN),
703         },
704         {       /* Mele PCG03 Mini PC */
705                 .matches = {
706                         DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Mini PC"),
707                         DMI_EXACT_MATCH(DMI_BOARD_NAME, "Mini PC"),
708                 },
709                 .driver_data = (void *)(BYT_RT5640_NO_INTERNAL_MIC_MAP |
710                                         BYT_RT5640_NO_SPEAKERS |
711                                         BYT_RT5640_SSP0_AIF1),
712         },
713         {       /* MPMAN Converter 9, similar hw as the I.T.Works TW891 2-in-1 */
714                 .matches = {
715                         DMI_MATCH(DMI_SYS_VENDOR, "MPMAN"),
716                         DMI_MATCH(DMI_PRODUCT_NAME, "Converter9"),
717                 },
718                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
719                                         BYT_RT5640_MONO_SPEAKER |
720                                         BYT_RT5640_SSP0_AIF1 |
721                                         BYT_RT5640_MCLK_EN),
722         },
723         {
724                 /* MPMAN MPWIN895CL */
725                 .matches = {
726                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "MPMAN"),
727                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MPWIN8900CL"),
728                 },
729                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
730                                         BYT_RT5640_MONO_SPEAKER |
731                                         BYT_RT5640_SSP0_AIF1 |
732                                         BYT_RT5640_MCLK_EN),
733         },
734         {       /* MSI S100 tablet */
735                 .matches = {
736                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Micro-Star International Co., Ltd."),
737                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "S100"),
738                 },
739                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
740                                         BYT_RT5640_JD_SRC_JD2_IN4N |
741                                         BYT_RT5640_OVCD_TH_2000UA |
742                                         BYT_RT5640_OVCD_SF_0P75 |
743                                         BYT_RT5640_MONO_SPEAKER |
744                                         BYT_RT5640_DIFF_MIC |
745                                         BYT_RT5640_MCLK_EN),
746         },
747         {       /* Nuvison/TMax TM800W560 */
748                 .matches = {
749                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TMAX"),
750                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TM800W560L"),
751                 },
752                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
753                                         BYT_RT5640_JD_SRC_JD2_IN4N |
754                                         BYT_RT5640_OVCD_TH_2000UA |
755                                         BYT_RT5640_OVCD_SF_0P75 |
756                                         BYT_RT5640_JD_NOT_INV |
757                                         BYT_RT5640_DIFF_MIC |
758                                         BYT_RT5640_SSP0_AIF1 |
759                                         BYT_RT5640_MCLK_EN),
760         },
761         {       /* Onda v975w */
762                 .matches = {
763                         DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
764                         DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
765                         /* The above are too generic, also match BIOS info */
766                         DMI_EXACT_MATCH(DMI_BIOS_VERSION, "5.6.5"),
767                         DMI_EXACT_MATCH(DMI_BIOS_DATE, "07/25/2014"),
768                 },
769                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
770                                         BYT_RT5640_JD_SRC_JD2_IN4N |
771                                         BYT_RT5640_OVCD_TH_2000UA |
772                                         BYT_RT5640_OVCD_SF_0P75 |
773                                         BYT_RT5640_DIFF_MIC |
774                                         BYT_RT5640_MCLK_EN),
775         },
776         {       /* Pipo W4 */
777                 .matches = {
778                         DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
779                         DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
780                         /* The above are too generic, also match BIOS info */
781                         DMI_MATCH(DMI_BIOS_VERSION, "V8L_WIN32_CHIPHD"),
782                 },
783                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
784                                         BYT_RT5640_MONO_SPEAKER |
785                                         BYT_RT5640_SSP0_AIF1 |
786                                         BYT_RT5640_MCLK_EN),
787         },
788         {       /* Point of View Mobii TAB-P800W (V2.0) */
789                 .matches = {
790                         DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
791                         DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
792                         /* The above are too generic, also match BIOS info */
793                         DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1014"),
794                         DMI_EXACT_MATCH(DMI_BIOS_DATE, "10/24/2014"),
795                 },
796                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
797                                         BYT_RT5640_JD_SRC_JD2_IN4N |
798                                         BYT_RT5640_OVCD_TH_2000UA |
799                                         BYT_RT5640_OVCD_SF_0P75 |
800                                         BYT_RT5640_MONO_SPEAKER |
801                                         BYT_RT5640_DIFF_MIC |
802                                         BYT_RT5640_SSP0_AIF2 |
803                                         BYT_RT5640_MCLK_EN),
804         },
805         {       /* Point of View Mobii TAB-P800W (V2.1) */
806                 .matches = {
807                         DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
808                         DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
809                         /* The above are too generic, also match BIOS info */
810                         DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1013"),
811                         DMI_EXACT_MATCH(DMI_BIOS_DATE, "08/22/2014"),
812                 },
813                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
814                                         BYT_RT5640_JD_SRC_JD2_IN4N |
815                                         BYT_RT5640_OVCD_TH_2000UA |
816                                         BYT_RT5640_OVCD_SF_0P75 |
817                                         BYT_RT5640_MONO_SPEAKER |
818                                         BYT_RT5640_DIFF_MIC |
819                                         BYT_RT5640_SSP0_AIF2 |
820                                         BYT_RT5640_MCLK_EN),
821         },
822         {       /* Point of View Mobii TAB-P1005W-232 (V2.0) */
823                 .matches = {
824                         DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "POV"),
825                         DMI_EXACT_MATCH(DMI_BOARD_NAME, "I102A"),
826                 },
827                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
828                                         BYT_RT5640_JD_SRC_JD2_IN4N |
829                                         BYT_RT5640_OVCD_TH_2000UA |
830                                         BYT_RT5640_OVCD_SF_0P75 |
831                                         BYT_RT5640_DIFF_MIC |
832                                         BYT_RT5640_SSP0_AIF1 |
833                                         BYT_RT5640_MCLK_EN),
834         },
835         {
836                 /* Prowise PT301 */
837                 .matches = {
838                         DMI_MATCH(DMI_SYS_VENDOR, "Prowise"),
839                         DMI_MATCH(DMI_PRODUCT_NAME, "PT301"),
840                 },
841                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
842                                         BYT_RT5640_JD_SRC_JD2_IN4N |
843                                         BYT_RT5640_OVCD_TH_2000UA |
844                                         BYT_RT5640_OVCD_SF_0P75 |
845                                         BYT_RT5640_DIFF_MIC |
846                                         BYT_RT5640_SSP0_AIF1 |
847                                         BYT_RT5640_MCLK_EN),
848         },
849         {
850                 /* Teclast X89 */
851                 .matches = {
852                         DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"),
853                         DMI_MATCH(DMI_BOARD_NAME, "tPAD"),
854                 },
855                 .driver_data = (void *)(BYT_RT5640_IN3_MAP |
856                                         BYT_RT5640_JD_SRC_JD1_IN4P |
857                                         BYT_RT5640_OVCD_TH_2000UA |
858                                         BYT_RT5640_OVCD_SF_1P0 |
859                                         BYT_RT5640_SSP0_AIF1 |
860                                         BYT_RT5640_MCLK_EN),
861         },
862         {       /* Toshiba Satellite Click Mini L9W-B */
863                 .matches = {
864                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
865                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "SATELLITE Click Mini L9W-B"),
866                 },
867                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
868                                         BYT_RT5640_JD_SRC_JD2_IN4N |
869                                         BYT_RT5640_OVCD_TH_1500UA |
870                                         BYT_RT5640_OVCD_SF_0P75 |
871                                         BYT_RT5640_SSP0_AIF1 |
872                                         BYT_RT5640_MCLK_EN),
873         },
874         {       /* Toshiba Encore WT8-A */
875                 .matches = {
876                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
877                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT8-A"),
878                 },
879                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
880                                         BYT_RT5640_JD_SRC_JD2_IN4N |
881                                         BYT_RT5640_OVCD_TH_2000UA |
882                                         BYT_RT5640_OVCD_SF_0P75 |
883                                         BYT_RT5640_JD_NOT_INV |
884                                         BYT_RT5640_MCLK_EN),
885         },
886         {       /* Toshiba Encore WT10-A */
887                 .matches = {
888                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
889                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT10-A-103"),
890                 },
891                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
892                                         BYT_RT5640_JD_SRC_JD1_IN4P |
893                                         BYT_RT5640_OVCD_TH_2000UA |
894                                         BYT_RT5640_OVCD_SF_0P75 |
895                                         BYT_RT5640_SSP0_AIF2 |
896                                         BYT_RT5640_MCLK_EN),
897         },
898         {       /* Voyo Winpad A15 */
899                 .matches = {
900                         DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
901                         DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
902                         /* Above strings are too generic, also match on BIOS date */
903                         DMI_MATCH(DMI_BIOS_DATE, "11/20/2014"),
904                 },
905                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
906                                         BYT_RT5640_JD_SRC_JD2_IN4N |
907                                         BYT_RT5640_OVCD_TH_2000UA |
908                                         BYT_RT5640_OVCD_SF_0P75 |
909                                         BYT_RT5640_DIFF_MIC |
910                                         BYT_RT5640_MCLK_EN),
911         },
912         {       /* Catch-all for generic Insyde tablets, must be last */
913                 .matches = {
914                         DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
915                 },
916                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
917                                         BYT_RT5640_MCLK_EN |
918                                         BYT_RT5640_SSP0_AIF1),
919
920         },
921         {}
922 };
923
924 /*
925  * Note this MUST be called before snd_soc_register_card(), so that the props
926  * are in place before the codec component driver's probe function parses them.
927  */
928 static int byt_rt5640_add_codec_device_props(const char *i2c_dev_name)
929 {
930         struct property_entry props[MAX_NO_PROPS] = {};
931         struct device *i2c_dev;
932         int ret, cnt = 0;
933
934         i2c_dev = bus_find_device_by_name(&i2c_bus_type, NULL, i2c_dev_name);
935         if (!i2c_dev)
936                 return -EPROBE_DEFER;
937
938         switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
939         case BYT_RT5640_DMIC1_MAP:
940                 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic1-data-pin",
941                                                   RT5640_DMIC1_DATA_PIN_IN1P);
942                 break;
943         case BYT_RT5640_DMIC2_MAP:
944                 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic2-data-pin",
945                                                   RT5640_DMIC2_DATA_PIN_IN1N);
946                 break;
947         case BYT_RT5640_IN1_MAP:
948                 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
949                         props[cnt++] =
950                                 PROPERTY_ENTRY_BOOL("realtek,in1-differential");
951                 break;
952         case BYT_RT5640_IN3_MAP:
953                 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
954                         props[cnt++] =
955                                 PROPERTY_ENTRY_BOOL("realtek,in3-differential");
956                 break;
957         }
958
959         if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
960                 props[cnt++] = PROPERTY_ENTRY_U32(
961                                     "realtek,jack-detect-source",
962                                     BYT_RT5640_JDSRC(byt_rt5640_quirk));
963
964                 props[cnt++] = PROPERTY_ENTRY_U32(
965                                     "realtek,over-current-threshold-microamp",
966                                     BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
967
968                 props[cnt++] = PROPERTY_ENTRY_U32(
969                                     "realtek,over-current-scale-factor",
970                                     BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
971         }
972
973         if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
974                 props[cnt++] = PROPERTY_ENTRY_BOOL("realtek,jack-detect-not-inverted");
975
976         ret = device_add_properties(i2c_dev, props);
977         put_device(i2c_dev);
978
979         return ret;
980 }
981
982 static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
983 {
984         struct snd_soc_card *card = runtime->card;
985         struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
986         struct snd_soc_component *component = asoc_rtd_to_codec(runtime, 0)->component;
987         const struct snd_soc_dapm_route *custom_map = NULL;
988         int num_routes = 0;
989         int ret;
990
991         card->dapm.idle_bias_off = true;
992
993         /* Start with RC clk for jack-detect (we disable MCLK below) */
994         if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
995                 snd_soc_component_update_bits(component, RT5640_GLB_CLK,
996                         RT5640_SCLK_SRC_MASK, RT5640_SCLK_SRC_RCCLK);
997
998         rt5640_sel_asrc_clk_src(component,
999                                 RT5640_DA_STEREO_FILTER |
1000                                 RT5640_DA_MONO_L_FILTER |
1001                                 RT5640_DA_MONO_R_FILTER |
1002                                 RT5640_AD_STEREO_FILTER |
1003                                 RT5640_AD_MONO_L_FILTER |
1004                                 RT5640_AD_MONO_R_FILTER,
1005                                 RT5640_CLK_SEL_ASRC);
1006
1007         ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
1008                                         ARRAY_SIZE(byt_rt5640_controls));
1009         if (ret) {
1010                 dev_err(card->dev, "unable to add card controls\n");
1011                 return ret;
1012         }
1013
1014         switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
1015         case BYT_RT5640_IN1_MAP:
1016                 custom_map = byt_rt5640_intmic_in1_map;
1017                 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
1018                 break;
1019         case BYT_RT5640_IN3_MAP:
1020                 custom_map = byt_rt5640_intmic_in3_map;
1021                 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in3_map);
1022                 break;
1023         case BYT_RT5640_DMIC1_MAP:
1024                 custom_map = byt_rt5640_intmic_dmic1_map;
1025                 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
1026                 break;
1027         case BYT_RT5640_DMIC2_MAP:
1028                 custom_map = byt_rt5640_intmic_dmic2_map;
1029                 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
1030                 break;
1031         }
1032
1033         ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
1034         if (ret)
1035                 return ret;
1036
1037         if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
1038                 ret = snd_soc_dapm_add_routes(&card->dapm,
1039                                         byt_rt5640_ssp2_aif2_map,
1040                                         ARRAY_SIZE(byt_rt5640_ssp2_aif2_map));
1041         } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
1042                 ret = snd_soc_dapm_add_routes(&card->dapm,
1043                                         byt_rt5640_ssp0_aif1_map,
1044                                         ARRAY_SIZE(byt_rt5640_ssp0_aif1_map));
1045         } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
1046                 ret = snd_soc_dapm_add_routes(&card->dapm,
1047                                         byt_rt5640_ssp0_aif2_map,
1048                                         ARRAY_SIZE(byt_rt5640_ssp0_aif2_map));
1049         } else {
1050                 ret = snd_soc_dapm_add_routes(&card->dapm,
1051                                         byt_rt5640_ssp2_aif1_map,
1052                                         ARRAY_SIZE(byt_rt5640_ssp2_aif1_map));
1053         }
1054         if (ret)
1055                 return ret;
1056
1057         if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
1058                 ret = snd_soc_dapm_add_routes(&card->dapm,
1059                                         byt_rt5640_mono_spk_map,
1060                                         ARRAY_SIZE(byt_rt5640_mono_spk_map));
1061         } else if (!(byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS)) {
1062                 ret = snd_soc_dapm_add_routes(&card->dapm,
1063                                         byt_rt5640_stereo_spk_map,
1064                                         ARRAY_SIZE(byt_rt5640_stereo_spk_map));
1065         }
1066         if (ret)
1067                 return ret;
1068
1069         if (byt_rt5640_quirk & BYT_RT5640_LINEOUT) {
1070                 ret = snd_soc_dapm_add_routes(&card->dapm,
1071                                         byt_rt5640_lineout_map,
1072                                         ARRAY_SIZE(byt_rt5640_lineout_map));
1073                 if (ret)
1074                         return ret;
1075         }
1076
1077         if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
1078                 /*
1079                  * The firmware might enable the clock at
1080                  * boot (this information may or may not
1081                  * be reflected in the enable clock register).
1082                  * To change the rate we must disable the clock
1083                  * first to cover these cases. Due to common
1084                  * clock framework restrictions that do not allow
1085                  * to disable a clock that has not been enabled,
1086                  * we need to enable the clock first.
1087                  */
1088                 ret = clk_prepare_enable(priv->mclk);
1089                 if (!ret)
1090                         clk_disable_unprepare(priv->mclk);
1091
1092                 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ)
1093                         ret = clk_set_rate(priv->mclk, 25000000);
1094                 else
1095                         ret = clk_set_rate(priv->mclk, 19200000);
1096
1097                 if (ret) {
1098                         dev_err(card->dev, "unable to set MCLK rate\n");
1099                         return ret;
1100                 }
1101         }
1102
1103         if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
1104                 ret = snd_soc_card_jack_new(card, "Headset",
1105                                             SND_JACK_HEADSET | SND_JACK_BTN_0,
1106                                             &priv->jack, rt5640_pins,
1107                                             ARRAY_SIZE(rt5640_pins));
1108                 if (ret) {
1109                         dev_err(card->dev, "Jack creation failed %d\n", ret);
1110                         return ret;
1111                 }
1112                 snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0,
1113                                  KEY_PLAYPAUSE);
1114                 snd_soc_component_set_jack(component, &priv->jack, NULL);
1115         }
1116
1117         return 0;
1118 }
1119
1120 static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd,
1121                             struct snd_pcm_hw_params *params)
1122 {
1123         struct snd_interval *rate = hw_param_interval(params,
1124                         SNDRV_PCM_HW_PARAM_RATE);
1125         struct snd_interval *channels = hw_param_interval(params,
1126                                                 SNDRV_PCM_HW_PARAM_CHANNELS);
1127         int ret, bits;
1128
1129         /* The DSP will covert the FE rate to 48k, stereo */
1130         rate->min = rate->max = 48000;
1131         channels->min = channels->max = 2;
1132
1133         if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
1134             (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
1135                 /* set SSP0 to 16-bit */
1136                 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
1137                 bits = 16;
1138         } else {
1139                 /* set SSP2 to 24-bit */
1140                 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
1141                 bits = 24;
1142         }
1143
1144         /*
1145          * Default mode for SSP configuration is TDM 4 slot, override config
1146          * with explicit setting to I2S 2ch. The word length is set with
1147          * dai_set_tdm_slot() since there is no other API exposed
1148          */
1149         ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
1150                                   SND_SOC_DAIFMT_I2S     |
1151                                   SND_SOC_DAIFMT_NB_NF   |
1152                                   SND_SOC_DAIFMT_CBS_CFS);
1153         if (ret < 0) {
1154                 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
1155                 return ret;
1156         }
1157
1158         ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, bits);
1159         if (ret < 0) {
1160                 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
1161                 return ret;
1162         }
1163
1164         return 0;
1165 }
1166
1167 static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream)
1168 {
1169         return snd_pcm_hw_constraint_single(substream->runtime,
1170                         SNDRV_PCM_HW_PARAM_RATE, 48000);
1171 }
1172
1173 static const struct snd_soc_ops byt_rt5640_aif1_ops = {
1174         .startup = byt_rt5640_aif1_startup,
1175 };
1176
1177 static const struct snd_soc_ops byt_rt5640_be_ssp2_ops = {
1178         .hw_params = byt_rt5640_aif1_hw_params,
1179 };
1180
1181 SND_SOC_DAILINK_DEF(dummy,
1182         DAILINK_COMP_ARRAY(COMP_DUMMY()));
1183
1184 SND_SOC_DAILINK_DEF(media,
1185         DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
1186
1187 SND_SOC_DAILINK_DEF(deepbuffer,
1188         DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
1189
1190 SND_SOC_DAILINK_DEF(ssp2_port,
1191         /* overwritten for ssp0 routing */
1192         DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));
1193 SND_SOC_DAILINK_DEF(ssp2_codec,
1194         DAILINK_COMP_ARRAY(COMP_CODEC(
1195         /* overwritten with HID */ "i2c-10EC5640:00",
1196         /* changed w/ quirk */  "rt5640-aif1")));
1197
1198 SND_SOC_DAILINK_DEF(platform,
1199         DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
1200
1201 static struct snd_soc_dai_link byt_rt5640_dais[] = {
1202         [MERR_DPCM_AUDIO] = {
1203                 .name = "Baytrail Audio Port",
1204                 .stream_name = "Baytrail Audio",
1205                 .nonatomic = true,
1206                 .dynamic = 1,
1207                 .dpcm_playback = 1,
1208                 .dpcm_capture = 1,
1209                 .ops = &byt_rt5640_aif1_ops,
1210                 SND_SOC_DAILINK_REG(media, dummy, platform),
1211         },
1212         [MERR_DPCM_DEEP_BUFFER] = {
1213                 .name = "Deep-Buffer Audio Port",
1214                 .stream_name = "Deep-Buffer Audio",
1215                 .nonatomic = true,
1216                 .dynamic = 1,
1217                 .dpcm_playback = 1,
1218                 .ops = &byt_rt5640_aif1_ops,
1219                 SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),
1220         },
1221                 /* back ends */
1222         {
1223                 .name = "SSP2-Codec",
1224                 .id = 0,
1225                 .no_pcm = 1,
1226                 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
1227                                                 | SND_SOC_DAIFMT_CBS_CFS,
1228                 .be_hw_params_fixup = byt_rt5640_codec_fixup,
1229                 .dpcm_playback = 1,
1230                 .dpcm_capture = 1,
1231                 .init = byt_rt5640_init,
1232                 .ops = &byt_rt5640_be_ssp2_ops,
1233                 SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform),
1234         },
1235 };
1236
1237 /* SoC card */
1238 static char byt_rt5640_codec_name[SND_ACPI_I2C_ID_LEN];
1239 #if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
1240 static char byt_rt5640_long_name[40]; /* = "bytcr-rt5640-*-spk-*-mic" */
1241 #endif
1242 static char byt_rt5640_components[64]; /* = "cfg-spk:* cfg-mic:* ..." */
1243
1244 static int byt_rt5640_suspend(struct snd_soc_card *card)
1245 {
1246         struct snd_soc_component *component;
1247
1248         if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1249                 return 0;
1250
1251         for_each_card_components(card, component) {
1252                 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1253                         dev_dbg(component->dev, "disabling jack detect before suspend\n");
1254                         snd_soc_component_set_jack(component, NULL, NULL);
1255                         break;
1256                 }
1257         }
1258
1259         return 0;
1260 }
1261
1262 static int byt_rt5640_resume(struct snd_soc_card *card)
1263 {
1264         struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
1265         struct snd_soc_component *component;
1266
1267         if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1268                 return 0;
1269
1270         for_each_card_components(card, component) {
1271                 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1272                         dev_dbg(component->dev, "re-enabling jack detect after resume\n");
1273                         snd_soc_component_set_jack(component, &priv->jack, NULL);
1274                         break;
1275                 }
1276         }
1277
1278         return 0;
1279 }
1280
1281 /* use space before codec name to simplify card ID, and simplify driver name */
1282 #define SOF_CARD_NAME "bytcht rt5640" /* card name will be 'sof-bytcht rt5640' */
1283 #define SOF_DRIVER_NAME "SOF"
1284
1285 #define CARD_NAME "bytcr-rt5640"
1286 #define DRIVER_NAME NULL /* card name will be used for driver name */
1287
1288 static struct snd_soc_card byt_rt5640_card = {
1289         .owner = THIS_MODULE,
1290         .dai_link = byt_rt5640_dais,
1291         .num_links = ARRAY_SIZE(byt_rt5640_dais),
1292         .dapm_widgets = byt_rt5640_widgets,
1293         .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
1294         .dapm_routes = byt_rt5640_audio_map,
1295         .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
1296         .fully_routed = true,
1297         .suspend_pre = byt_rt5640_suspend,
1298         .resume_post = byt_rt5640_resume,
1299 };
1300
1301 struct acpi_chan_package {   /* ACPICA seems to require 64 bit integers */
1302         u64 aif_value;       /* 1: AIF1, 2: AIF2 */
1303         u64 mclock_value;    /* usually 25MHz (0x17d7940), ignored */
1304 };
1305
1306 static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
1307 {
1308         struct device *dev = &pdev->dev;
1309         static const char * const map_name[] = { "dmic1", "dmic2", "in1", "in3", "none" };
1310         __maybe_unused const char *spk_type;
1311         const struct dmi_system_id *dmi_id;
1312         const char *lineout_string = "";
1313         struct byt_rt5640_private *priv;
1314         struct snd_soc_acpi_mach *mach;
1315         const char *platform_name;
1316         struct acpi_device *adev;
1317         bool sof_parent;
1318         int ret_val = 0;
1319         int dai_index = 0;
1320         int i, cfg_spk;
1321         int aif;
1322
1323         is_bytcr = false;
1324         priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
1325         if (!priv)
1326                 return -ENOMEM;
1327
1328         /* register the soc card */
1329         byt_rt5640_card.dev = &pdev->dev;
1330         mach = byt_rt5640_card.dev->platform_data;
1331         snd_soc_card_set_drvdata(&byt_rt5640_card, priv);
1332
1333         /* fix index of codec dai */
1334         for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) {
1335                 if (!strcmp(byt_rt5640_dais[i].codecs->name,
1336                             "i2c-10EC5640:00")) {
1337                         dai_index = i;
1338                         break;
1339                 }
1340         }
1341
1342         /* fixup codec name based on HID */
1343         adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);
1344         if (adev) {
1345                 snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name),
1346                          "i2c-%s", acpi_dev_name(adev));
1347                 put_device(&adev->dev);
1348                 byt_rt5640_dais[dai_index].codecs->name = byt_rt5640_codec_name;
1349         }
1350
1351         /*
1352          * swap SSP0 if bytcr is detected
1353          * (will be overridden if DMI quirk is detected)
1354          */
1355         if (soc_intel_is_byt()) {
1356                 if (mach->mach_params.acpi_ipc_irq_index == 0)
1357                         is_bytcr = true;
1358         }
1359
1360         if (is_bytcr) {
1361                 /*
1362                  * Baytrail CR platforms may have CHAN package in BIOS, try
1363                  * to find relevant routing quirk based as done on Windows
1364                  * platforms. We have to read the information directly from the
1365                  * BIOS, at this stage the card is not created and the links
1366                  * with the codec driver/pdata are non-existent
1367                  */
1368
1369                 struct acpi_chan_package chan_package;
1370
1371                 /* format specified: 2 64-bit integers */
1372                 struct acpi_buffer format = {sizeof("NN"), "NN"};
1373                 struct acpi_buffer state = {0, NULL};
1374                 struct snd_soc_acpi_package_context pkg_ctx;
1375                 bool pkg_found = false;
1376
1377                 state.length = sizeof(chan_package);
1378                 state.pointer = &chan_package;
1379
1380                 pkg_ctx.name = "CHAN";
1381                 pkg_ctx.length = 2;
1382                 pkg_ctx.format = &format;
1383                 pkg_ctx.state = &state;
1384                 pkg_ctx.data_valid = false;
1385
1386                 pkg_found = snd_soc_acpi_find_package_from_hid(mach->id,
1387                                                                &pkg_ctx);
1388                 if (pkg_found) {
1389                         if (chan_package.aif_value == 1) {
1390                                 dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n");
1391                                 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF1;
1392                         } else  if (chan_package.aif_value == 2) {
1393                                 dev_info(&pdev->dev, "BIOS Routing: AIF2 connected\n");
1394                                 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1395                         } else {
1396                                 dev_info(&pdev->dev, "BIOS Routing isn't valid, ignored\n");
1397                                 pkg_found = false;
1398                         }
1399                 }
1400
1401                 if (!pkg_found) {
1402                         /* no BIOS indications, assume SSP0-AIF2 connection */
1403                         byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1404                 }
1405
1406                 /* change defaults for Baytrail-CR capture */
1407                 byt_rt5640_quirk |= BYTCR_INPUT_DEFAULTS;
1408         } else {
1409                 byt_rt5640_quirk |= BYT_RT5640_DMIC1_MAP |
1410                                     BYT_RT5640_JD_SRC_JD2_IN4N |
1411                                     BYT_RT5640_OVCD_TH_2000UA |
1412                                     BYT_RT5640_OVCD_SF_0P75;
1413         }
1414
1415         /* check quirks before creating card */
1416         dmi_id = dmi_first_match(byt_rt5640_quirk_table);
1417         if (dmi_id)
1418                 byt_rt5640_quirk = (unsigned long)dmi_id->driver_data;
1419         if (quirk_override != -1) {
1420                 dev_info(&pdev->dev, "Overriding quirk 0x%lx => 0x%x\n",
1421                          byt_rt5640_quirk, quirk_override);
1422                 byt_rt5640_quirk = quirk_override;
1423         }
1424
1425         /* Must be called before register_card, also see declaration comment. */
1426         ret_val = byt_rt5640_add_codec_device_props(byt_rt5640_codec_name);
1427         if (ret_val)
1428                 return ret_val;
1429
1430         log_quirks(&pdev->dev);
1431
1432         if ((byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) ||
1433             (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
1434                 byt_rt5640_dais[dai_index].codecs->dai_name = "rt5640-aif2";
1435                 aif = 2;
1436         } else {
1437                 aif = 1;
1438         }
1439
1440         if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
1441             (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2))
1442                 byt_rt5640_dais[dai_index].cpus->dai_name = "ssp0-port";
1443
1444         if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
1445                 priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
1446                 if (IS_ERR(priv->mclk)) {
1447                         ret_val = PTR_ERR(priv->mclk);
1448
1449                         dev_err(&pdev->dev,
1450                                 "Failed to get MCLK from pmc_plt_clk_3: %d\n",
1451                                 ret_val);
1452
1453                         /*
1454                          * Fall back to bit clock usage for -ENOENT (clock not
1455                          * available likely due to missing dependencies), bail
1456                          * for all other errors, including -EPROBE_DEFER
1457                          */
1458                         if (ret_val != -ENOENT)
1459                                 return ret_val;
1460                         byt_rt5640_quirk &= ~BYT_RT5640_MCLK_EN;
1461                 }
1462         }
1463
1464         if (byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS) {
1465                 cfg_spk = 0;
1466                 spk_type = "none";
1467         } else if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
1468                 cfg_spk = 1;
1469                 spk_type = "mono";
1470         } else {
1471                 cfg_spk = 2;
1472                 spk_type = "stereo";
1473         }
1474
1475         if (byt_rt5640_quirk & BYT_RT5640_LINEOUT)
1476                 lineout_string = " cfg-lineout:1";
1477
1478         snprintf(byt_rt5640_components, sizeof(byt_rt5640_components),
1479                  "cfg-spk:%d cfg-mic:%s aif:%d%s", cfg_spk,
1480                  map_name[BYT_RT5640_MAP(byt_rt5640_quirk)], aif,
1481                  lineout_string);
1482         byt_rt5640_card.components = byt_rt5640_components;
1483 #if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
1484         snprintf(byt_rt5640_long_name, sizeof(byt_rt5640_long_name),
1485                  "bytcr-rt5640-%s-spk-%s-mic", spk_type,
1486                  map_name[BYT_RT5640_MAP(byt_rt5640_quirk)]);
1487         byt_rt5640_card.long_name = byt_rt5640_long_name;
1488 #endif
1489
1490         /* override plaform name, if required */
1491         platform_name = mach->mach_params.platform;
1492
1493         ret_val = snd_soc_fixup_dai_links_platform_name(&byt_rt5640_card,
1494                                                         platform_name);
1495         if (ret_val)
1496                 return ret_val;
1497
1498         sof_parent = snd_soc_acpi_sof_parent(&pdev->dev);
1499
1500         /* set card and driver name */
1501         if (sof_parent) {
1502                 byt_rt5640_card.name = SOF_CARD_NAME;
1503                 byt_rt5640_card.driver_name = SOF_DRIVER_NAME;
1504         } else {
1505                 byt_rt5640_card.name = CARD_NAME;
1506                 byt_rt5640_card.driver_name = DRIVER_NAME;
1507         }
1508
1509         /* set pm ops */
1510         if (sof_parent)
1511                 dev->driver->pm = &snd_soc_pm_ops;
1512
1513         ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card);
1514
1515         if (ret_val) {
1516                 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
1517                         ret_val);
1518                 return ret_val;
1519         }
1520         platform_set_drvdata(pdev, &byt_rt5640_card);
1521         return ret_val;
1522 }
1523
1524 static struct platform_driver snd_byt_rt5640_mc_driver = {
1525         .driver = {
1526                 .name = "bytcr_rt5640",
1527         },
1528         .probe = snd_byt_rt5640_mc_probe,
1529 };
1530
1531 module_platform_driver(snd_byt_rt5640_mc_driver);
1532
1533 MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
1534 MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
1535 MODULE_LICENSE("GPL v2");
1536 MODULE_ALIAS("platform:bytcr_rt5640");