GNU Linux-libre 4.19.286-gnu1
[releases.git] / sound / soc / intel / boards / bytcr_rt5640.c
1 /*
2  *  byt_cr_dpcm_rt5640.c - ASoc Machine driver for Intel Byt CR platform
3  *
4  *  Copyright (C) 2014 Intel Corp
5  *  Author: Subhransu S. Prusty <subhransu.s.prusty@intel.com>
6  *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7  *
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.
11  *
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.
16  *
17  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
18  */
19
20 #include <linux/i2c.h>
21 #include <linux/init.h>
22 #include <linux/module.h>
23 #include <linux/moduleparam.h>
24 #include <linux/platform_device.h>
25 #include <linux/acpi.h>
26 #include <linux/clk.h>
27 #include <linux/device.h>
28 #include <linux/dmi.h>
29 #include <linux/input.h>
30 #include <linux/slab.h>
31 #include <asm/cpu_device_id.h>
32 #include <asm/platform_sst_audio.h>
33 #include <sound/pcm.h>
34 #include <sound/pcm_params.h>
35 #include <sound/soc.h>
36 #include <sound/jack.h>
37 #include <sound/soc-acpi.h>
38 #include <dt-bindings/sound/rt5640.h>
39 #include "../../codecs/rt5640.h"
40 #include "../atom/sst-atom-controls.h"
41 #include "../common/sst-dsp.h"
42
43 enum {
44         BYT_RT5640_DMIC1_MAP,
45         BYT_RT5640_DMIC2_MAP,
46         BYT_RT5640_IN1_MAP,
47         BYT_RT5640_IN3_MAP,
48 };
49
50 enum {
51         BYT_RT5640_JD_SRC_GPIO1         = (RT5640_JD_SRC_GPIO1 << 4),
52         BYT_RT5640_JD_SRC_JD1_IN4P      = (RT5640_JD_SRC_JD1_IN4P << 4),
53         BYT_RT5640_JD_SRC_JD2_IN4N      = (RT5640_JD_SRC_JD2_IN4N << 4),
54         BYT_RT5640_JD_SRC_GPIO2         = (RT5640_JD_SRC_GPIO2 << 4),
55         BYT_RT5640_JD_SRC_GPIO3         = (RT5640_JD_SRC_GPIO3 << 4),
56         BYT_RT5640_JD_SRC_GPIO4         = (RT5640_JD_SRC_GPIO4 << 4),
57 };
58
59 enum {
60         BYT_RT5640_OVCD_TH_600UA        = (6 << 8),
61         BYT_RT5640_OVCD_TH_1500UA       = (15 << 8),
62         BYT_RT5640_OVCD_TH_2000UA       = (20 << 8),
63 };
64
65 enum {
66         BYT_RT5640_OVCD_SF_0P5          = (RT5640_OVCD_SF_0P5 << 13),
67         BYT_RT5640_OVCD_SF_0P75         = (RT5640_OVCD_SF_0P75 << 13),
68         BYT_RT5640_OVCD_SF_1P0          = (RT5640_OVCD_SF_1P0 << 13),
69         BYT_RT5640_OVCD_SF_1P5          = (RT5640_OVCD_SF_1P5 << 13),
70 };
71
72 #define BYT_RT5640_MAP(quirk)           ((quirk) &  GENMASK(3, 0))
73 #define BYT_RT5640_JDSRC(quirk)         (((quirk) & GENMASK(7, 4)) >> 4)
74 #define BYT_RT5640_OVCD_TH(quirk)       (((quirk) & GENMASK(12, 8)) >> 8)
75 #define BYT_RT5640_OVCD_SF(quirk)       (((quirk) & GENMASK(14, 13)) >> 13)
76 #define BYT_RT5640_JD_NOT_INV           BIT(16)
77 #define BYT_RT5640_MONO_SPEAKER         BIT(17)
78 #define BYT_RT5640_DIFF_MIC             BIT(18) /* default is single-ended */
79 #define BYT_RT5640_SSP2_AIF2            BIT(19) /* default is using AIF1  */
80 #define BYT_RT5640_SSP0_AIF1            BIT(20)
81 #define BYT_RT5640_SSP0_AIF2            BIT(21)
82 #define BYT_RT5640_MCLK_EN              BIT(22)
83 #define BYT_RT5640_MCLK_25MHZ           BIT(23)
84
85 #define BYTCR_INPUT_DEFAULTS                            \
86         (BYT_RT5640_IN3_MAP |                           \
87          BYT_RT5640_JD_SRC_JD1_IN4P |                   \
88          BYT_RT5640_OVCD_TH_2000UA |                    \
89          BYT_RT5640_OVCD_SF_0P75 |                      \
90          BYT_RT5640_DIFF_MIC)
91
92 /* in-diff or dmic-pin + jdsrc + ovcd-th + -sf + jd-inv + terminating entry */
93 #define MAX_NO_PROPS 6
94
95 struct byt_rt5640_private {
96         struct snd_soc_jack jack;
97         struct clk *mclk;
98 };
99 static bool is_bytcr;
100
101 static unsigned long byt_rt5640_quirk = BYT_RT5640_MCLK_EN;
102 static unsigned int quirk_override;
103 module_param_named(quirk, quirk_override, uint, 0444);
104 MODULE_PARM_DESC(quirk, "Board-specific quirk override");
105
106 static void log_quirks(struct device *dev)
107 {
108         int map;
109         bool has_mclk = false;
110         bool has_ssp0 = false;
111         bool has_ssp0_aif1 = false;
112         bool has_ssp0_aif2 = false;
113         bool has_ssp2_aif2 = false;
114
115         map = BYT_RT5640_MAP(byt_rt5640_quirk);
116         switch (map) {
117         case BYT_RT5640_DMIC1_MAP:
118                 dev_info(dev, "quirk DMIC1_MAP enabled\n");
119                 break;
120         case BYT_RT5640_DMIC2_MAP:
121                 dev_info(dev, "quirk DMIC2_MAP enabled\n");
122                 break;
123         case BYT_RT5640_IN1_MAP:
124                 dev_info(dev, "quirk IN1_MAP enabled\n");
125                 break;
126         case BYT_RT5640_IN3_MAP:
127                 dev_info(dev, "quirk IN3_MAP enabled\n");
128                 break;
129         default:
130                 dev_err(dev, "quirk map 0x%x is not supported, microphone input will not work\n", map);
131                 break;
132         }
133         if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
134                 dev_info(dev, "quirk realtek,jack-detect-source %ld\n",
135                          BYT_RT5640_JDSRC(byt_rt5640_quirk));
136                 dev_info(dev, "quirk realtek,over-current-threshold-microamp %ld\n",
137                          BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
138                 dev_info(dev, "quirk realtek,over-current-scale-factor %ld\n",
139                          BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
140         }
141         if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
142                 dev_info(dev, "quirk JD_NOT_INV enabled\n");
143         if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER)
144                 dev_info(dev, "quirk MONO_SPEAKER 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_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
288                             platform_clock_control, SND_SOC_DAPM_PRE_PMU |
289                             SND_SOC_DAPM_POST_PMD),
290
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_kcontrol_new byt_rt5640_controls[] = {
375         SOC_DAPM_PIN_SWITCH("Headphone"),
376         SOC_DAPM_PIN_SWITCH("Headset Mic"),
377         SOC_DAPM_PIN_SWITCH("Internal Mic"),
378         SOC_DAPM_PIN_SWITCH("Speaker"),
379 };
380
381 static struct snd_soc_jack_pin rt5640_pins[] = {
382         {
383                 .pin    = "Headphone",
384                 .mask   = SND_JACK_HEADPHONE,
385         },
386         {
387                 .pin    = "Headset Mic",
388                 .mask   = SND_JACK_MICROPHONE,
389         },
390 };
391
392 static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream,
393                                         struct snd_pcm_hw_params *params)
394 {
395         struct snd_soc_pcm_runtime *rtd = substream->private_data;
396         struct snd_soc_dai *dai = rtd->codec_dai;
397
398         return byt_rt5640_prepare_and_enable_pll1(dai, params_rate(params));
399 }
400
401 /* Please keep this list alphabetically sorted */
402 static const struct dmi_system_id byt_rt5640_quirk_table[] = {
403         {       /* Acer Iconia One 7 B1-750 */
404                 .matches = {
405                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Insyde"),
406                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "VESPA2"),
407                 },
408                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
409                                         BYT_RT5640_JD_SRC_JD1_IN4P |
410                                         BYT_RT5640_OVCD_TH_1500UA |
411                                         BYT_RT5640_OVCD_SF_0P75 |
412                                         BYT_RT5640_SSP0_AIF1 |
413                                         BYT_RT5640_MCLK_EN),
414         },
415         {       /* Acer Iconia Tab 8 W1-810 */
416                 .matches = {
417                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"),
418                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Iconia W1-810"),
419                 },
420                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
421                                         BYT_RT5640_JD_SRC_JD1_IN4P |
422                                         BYT_RT5640_OVCD_TH_1500UA |
423                                         BYT_RT5640_OVCD_SF_0P75 |
424                                         BYT_RT5640_SSP0_AIF1 |
425                                         BYT_RT5640_MCLK_EN),
426         },
427         {       /* Acer One 10 S1002 */
428                 .matches = {
429                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
430                         DMI_MATCH(DMI_PRODUCT_NAME, "One S1002"),
431                 },
432                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
433                                         BYT_RT5640_JD_SRC_JD2_IN4N |
434                                         BYT_RT5640_OVCD_TH_2000UA |
435                                         BYT_RT5640_OVCD_SF_0P75 |
436                                         BYT_RT5640_DIFF_MIC |
437                                         BYT_RT5640_SSP0_AIF2 |
438                                         BYT_RT5640_MCLK_EN),
439         },
440         {
441                 .matches = {
442                         DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
443                         DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
444                 },
445                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
446                                         BYT_RT5640_JD_SRC_JD2_IN4N |
447                                         BYT_RT5640_OVCD_TH_2000UA |
448                                         BYT_RT5640_OVCD_SF_0P75 |
449                                         BYT_RT5640_SSP0_AIF1 |
450                                         BYT_RT5640_MCLK_EN),
451         },
452         {
453                 /* Advantech MICA-071 */
454                 .matches = {
455                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Advantech"),
456                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MICA-071"),
457                 },
458                 /* OVCD Th = 1500uA to reliable detect head-phones vs -set */
459                 .driver_data = (void *)(BYT_RT5640_IN3_MAP |
460                                         BYT_RT5640_JD_SRC_JD2_IN4N |
461                                         BYT_RT5640_OVCD_TH_1500UA |
462                                         BYT_RT5640_OVCD_SF_0P75 |
463                                         BYT_RT5640_MONO_SPEAKER |
464                                         BYT_RT5640_DIFF_MIC |
465                                         BYT_RT5640_MCLK_EN),
466         },
467         {
468                 .matches = {
469                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
470                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 80 Cesium"),
471                 },
472                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
473                                         BYT_RT5640_MONO_SPEAKER |
474                                         BYT_RT5640_SSP0_AIF1 |
475                                         BYT_RT5640_MCLK_EN),
476         },
477         {
478                 .matches = {
479                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
480                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 140 CESIUM"),
481                 },
482                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
483                                         BYT_RT5640_JD_SRC_JD2_IN4N |
484                                         BYT_RT5640_OVCD_TH_2000UA |
485                                         BYT_RT5640_OVCD_SF_0P75 |
486                                         BYT_RT5640_SSP0_AIF1 |
487                                         BYT_RT5640_MCLK_EN),
488         },
489         {
490                 .matches = {
491                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
492                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
493                 },
494                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
495                                         BYT_RT5640_JD_SRC_JD2_IN4N |
496                                         BYT_RT5640_OVCD_TH_2000UA |
497                                         BYT_RT5640_OVCD_SF_0P75 |
498                                         BYT_RT5640_MCLK_EN),
499         },
500         {
501                 .matches = {
502                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
503                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"),
504                 },
505                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
506                                         BYT_RT5640_JD_SRC_JD2_IN4N |
507                                         BYT_RT5640_OVCD_TH_2000UA |
508                                         BYT_RT5640_OVCD_SF_0P75 |
509                                         BYT_RT5640_MONO_SPEAKER |
510                                         BYT_RT5640_DIFF_MIC |
511                                         BYT_RT5640_SSP0_AIF2 |
512                                         BYT_RT5640_MCLK_EN),
513         },
514         {       /* Chuwi Vi8 (CWI506) */
515                 .matches = {
516                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Insyde"),
517                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "i86"),
518                         /* The above are too generic, also match BIOS info */
519                         DMI_MATCH(DMI_BIOS_VERSION, "CHUWI.D86JLBNR"),
520                 },
521                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
522                                         BYT_RT5640_MONO_SPEAKER |
523                                         BYT_RT5640_SSP0_AIF1 |
524                                         BYT_RT5640_MCLK_EN),
525         },
526         {
527                 /* Chuwi Vi10 (CWI505) */
528                 .matches = {
529                         DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
530                         DMI_MATCH(DMI_BOARD_NAME, "BYT-PF02"),
531                         DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
532                         DMI_MATCH(DMI_PRODUCT_NAME, "S165"),
533                 },
534                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
535                                         BYT_RT5640_JD_SRC_JD2_IN4N |
536                                         BYT_RT5640_OVCD_TH_2000UA |
537                                         BYT_RT5640_OVCD_SF_0P75 |
538                                         BYT_RT5640_DIFF_MIC |
539                                         BYT_RT5640_SSP0_AIF1 |
540                                         BYT_RT5640_MCLK_EN),
541         },
542         {
543                 /* Chuwi Hi8 (CWI509) */
544                 .matches = {
545                         DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
546                         DMI_MATCH(DMI_BOARD_NAME, "BYT-PA03C"),
547                         DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
548                         DMI_MATCH(DMI_PRODUCT_NAME, "S806"),
549                 },
550                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
551                                         BYT_RT5640_JD_SRC_JD2_IN4N |
552                                         BYT_RT5640_OVCD_TH_2000UA |
553                                         BYT_RT5640_OVCD_SF_0P75 |
554                                         BYT_RT5640_MONO_SPEAKER |
555                                         BYT_RT5640_DIFF_MIC |
556                                         BYT_RT5640_SSP0_AIF1 |
557                                         BYT_RT5640_MCLK_EN),
558         },
559         {
560                 .matches = {
561                         DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
562                         DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"),
563                 },
564                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP),
565         },
566         {       /* Connect Tablet 9 */
567                 .matches = {
568                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Connect"),
569                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Tablet 9"),
570                 },
571                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
572                                         BYT_RT5640_MONO_SPEAKER |
573                                         BYT_RT5640_SSP0_AIF1 |
574                                         BYT_RT5640_MCLK_EN),
575         },
576         {
577                 .matches = {
578                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
579                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
580                 },
581                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
582                                         BYT_RT5640_JD_SRC_JD2_IN4N |
583                                         BYT_RT5640_OVCD_TH_2000UA |
584                                         BYT_RT5640_OVCD_SF_0P75 |
585                                         BYT_RT5640_MONO_SPEAKER |
586                                         BYT_RT5640_MCLK_EN),
587         },
588         {       /* Estar Beauty HD MID 7316R */
589                 .matches = {
590                         DMI_MATCH(DMI_SYS_VENDOR, "Estar"),
591                         DMI_MATCH(DMI_PRODUCT_NAME, "eSTAR BEAUTY HD Intel Quad core"),
592                 },
593                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
594                                         BYT_RT5640_MONO_SPEAKER |
595                                         BYT_RT5640_SSP0_AIF1 |
596                                         BYT_RT5640_MCLK_EN),
597         },
598         {       /* Glavey TM800A550L */
599                 .matches = {
600                         DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
601                         DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
602                         /* Above strings are too generic, also match on BIOS version */
603                         DMI_MATCH(DMI_BIOS_VERSION, "ZY-8-BI-PX4S70VTR400-X423B-005-D"),
604                 },
605                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
606                                         BYT_RT5640_SSP0_AIF1 |
607                                         BYT_RT5640_MCLK_EN),
608         },
609         {
610                 .matches = {
611                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
612                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"),
613                 },
614                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
615                                         BYT_RT5640_MCLK_EN),
616         },
617         {       /* HP Pavilion x2 10-n000nd */
618                 .matches = {
619                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
620                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP Pavilion x2 Detachable"),
621                 },
622                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
623                                         BYT_RT5640_JD_SRC_JD2_IN4N |
624                                         BYT_RT5640_OVCD_TH_1500UA |
625                                         BYT_RT5640_OVCD_SF_0P75 |
626                                         BYT_RT5640_SSP0_AIF1 |
627                                         BYT_RT5640_MCLK_EN),
628         },
629         {       /* HP Stream 7 */
630                 .matches = {
631                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
632                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP Stream 7 Tablet"),
633                 },
634                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
635                                         BYT_RT5640_MONO_SPEAKER |
636                                         BYT_RT5640_JD_NOT_INV |
637                                         BYT_RT5640_SSP0_AIF1 |
638                                         BYT_RT5640_MCLK_EN),
639         },
640         {       /* I.T.Works TW891 */
641                 .matches = {
642                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "To be filled by O.E.M."),
643                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TW891"),
644                         DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "To be filled by O.E.M."),
645                         DMI_EXACT_MATCH(DMI_BOARD_NAME, "TW891"),
646                 },
647                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
648                                         BYT_RT5640_MONO_SPEAKER |
649                                         BYT_RT5640_SSP0_AIF1 |
650                                         BYT_RT5640_MCLK_EN),
651         },
652         {       /* Lamina I8270 / T701BR.SE */
653                 .matches = {
654                         DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Lamina"),
655                         DMI_EXACT_MATCH(DMI_BOARD_NAME, "T701BR.SE"),
656                 },
657                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
658                                         BYT_RT5640_MONO_SPEAKER |
659                                         BYT_RT5640_JD_NOT_INV |
660                                         BYT_RT5640_SSP0_AIF1 |
661                                         BYT_RT5640_MCLK_EN),
662         },
663         {       /* Lenovo Miix 2 8 */
664                 .matches = {
665                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
666                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "20326"),
667                         DMI_EXACT_MATCH(DMI_BOARD_NAME, "Hiking"),
668                 },
669                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
670                                         BYT_RT5640_JD_SRC_JD2_IN4N |
671                                         BYT_RT5640_OVCD_TH_2000UA |
672                                         BYT_RT5640_OVCD_SF_0P75 |
673                                         BYT_RT5640_MONO_SPEAKER |
674                                         BYT_RT5640_MCLK_EN),
675         },
676         {       /* Lenovo Miix 3-830 */
677                 .matches = {
678                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
679                         DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 3-830"),
680                 },
681                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
682                                         BYT_RT5640_JD_SRC_JD2_IN4N |
683                                         BYT_RT5640_OVCD_TH_2000UA |
684                                         BYT_RT5640_OVCD_SF_0P75 |
685                                         BYT_RT5640_MONO_SPEAKER |
686                                         BYT_RT5640_DIFF_MIC |
687                                         BYT_RT5640_SSP0_AIF1 |
688                                         BYT_RT5640_MCLK_EN),
689         },
690         {       /* Linx Linx7 tablet */
691                 .matches = {
692                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LINX"),
693                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "LINX7"),
694                 },
695                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
696                                         BYT_RT5640_MONO_SPEAKER |
697                                         BYT_RT5640_JD_NOT_INV |
698                                         BYT_RT5640_SSP0_AIF1 |
699                                         BYT_RT5640_MCLK_EN),
700         },
701         {       /* MPMAN Converter 9, similar hw as the I.T.Works TW891 2-in-1 */
702                 .matches = {
703                         DMI_MATCH(DMI_SYS_VENDOR, "MPMAN"),
704                         DMI_MATCH(DMI_PRODUCT_NAME, "Converter9"),
705                 },
706                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
707                                         BYT_RT5640_MONO_SPEAKER |
708                                         BYT_RT5640_SSP0_AIF1 |
709                                         BYT_RT5640_MCLK_EN),
710         },
711         {
712                 /* MPMAN MPWIN895CL */
713                 .matches = {
714                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "MPMAN"),
715                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MPWIN8900CL"),
716                 },
717                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
718                                         BYT_RT5640_MONO_SPEAKER |
719                                         BYT_RT5640_SSP0_AIF1 |
720                                         BYT_RT5640_MCLK_EN),
721         },
722         {       /* MSI S100 tablet */
723                 .matches = {
724                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Micro-Star International Co., Ltd."),
725                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "S100"),
726                 },
727                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
728                                         BYT_RT5640_JD_SRC_JD2_IN4N |
729                                         BYT_RT5640_OVCD_TH_2000UA |
730                                         BYT_RT5640_OVCD_SF_0P75 |
731                                         BYT_RT5640_MONO_SPEAKER |
732                                         BYT_RT5640_DIFF_MIC |
733                                         BYT_RT5640_MCLK_EN),
734         },
735         {       /* Nuvison/TMax TM800W560 */
736                 .matches = {
737                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TMAX"),
738                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TM800W560L"),
739                 },
740                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
741                                         BYT_RT5640_JD_SRC_JD2_IN4N |
742                                         BYT_RT5640_OVCD_TH_2000UA |
743                                         BYT_RT5640_OVCD_SF_0P75 |
744                                         BYT_RT5640_JD_NOT_INV |
745                                         BYT_RT5640_DIFF_MIC |
746                                         BYT_RT5640_SSP0_AIF1 |
747                                         BYT_RT5640_MCLK_EN),
748         },
749         {       /* Onda v975w */
750                 .matches = {
751                         DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
752                         DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
753                         /* The above are too generic, also match BIOS info */
754                         DMI_EXACT_MATCH(DMI_BIOS_VERSION, "5.6.5"),
755                         DMI_EXACT_MATCH(DMI_BIOS_DATE, "07/25/2014"),
756                 },
757                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
758                                         BYT_RT5640_JD_SRC_JD2_IN4N |
759                                         BYT_RT5640_OVCD_TH_2000UA |
760                                         BYT_RT5640_OVCD_SF_0P75 |
761                                         BYT_RT5640_DIFF_MIC |
762                                         BYT_RT5640_MCLK_EN),
763         },
764         {       /* Pipo W4 */
765                 .matches = {
766                         DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
767                         DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
768                         /* The above are too generic, also match BIOS info */
769                         DMI_MATCH(DMI_BIOS_VERSION, "V8L_WIN32_CHIPHD"),
770                 },
771                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
772                                         BYT_RT5640_MONO_SPEAKER |
773                                         BYT_RT5640_SSP0_AIF1 |
774                                         BYT_RT5640_MCLK_EN),
775         },
776         {       /* Point of View Mobii TAB-P800W (V2.0) */
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_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1014"),
782                         DMI_EXACT_MATCH(DMI_BIOS_DATE, "10/24/2014"),
783                 },
784                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
785                                         BYT_RT5640_JD_SRC_JD2_IN4N |
786                                         BYT_RT5640_OVCD_TH_2000UA |
787                                         BYT_RT5640_OVCD_SF_0P75 |
788                                         BYT_RT5640_MONO_SPEAKER |
789                                         BYT_RT5640_DIFF_MIC |
790                                         BYT_RT5640_SSP0_AIF2 |
791                                         BYT_RT5640_MCLK_EN),
792         },
793         {       /* Point of View Mobii TAB-P800W (V2.1) */
794                 .matches = {
795                         DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
796                         DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
797                         /* The above are too generic, also match BIOS info */
798                         DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1013"),
799                         DMI_EXACT_MATCH(DMI_BIOS_DATE, "08/22/2014"),
800                 },
801                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
802                                         BYT_RT5640_JD_SRC_JD2_IN4N |
803                                         BYT_RT5640_OVCD_TH_2000UA |
804                                         BYT_RT5640_OVCD_SF_0P75 |
805                                         BYT_RT5640_MONO_SPEAKER |
806                                         BYT_RT5640_DIFF_MIC |
807                                         BYT_RT5640_SSP0_AIF2 |
808                                         BYT_RT5640_MCLK_EN),
809         },
810         {
811                 /* Teclast X89 */
812                 .matches = {
813                         DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"),
814                         DMI_MATCH(DMI_BOARD_NAME, "tPAD"),
815                 },
816                 .driver_data = (void *)(BYT_RT5640_IN3_MAP |
817                                         BYT_RT5640_JD_SRC_JD1_IN4P |
818                                         BYT_RT5640_OVCD_TH_2000UA |
819                                         BYT_RT5640_OVCD_SF_1P0 |
820                                         BYT_RT5640_SSP0_AIF1 |
821                                         BYT_RT5640_MCLK_EN),
822         },
823         {       /* Toshiba Satellite Click Mini L9W-B */
824                 .matches = {
825                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
826                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "SATELLITE Click Mini L9W-B"),
827                 },
828                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
829                                         BYT_RT5640_JD_SRC_JD2_IN4N |
830                                         BYT_RT5640_OVCD_TH_1500UA |
831                                         BYT_RT5640_OVCD_SF_0P75 |
832                                         BYT_RT5640_SSP0_AIF1 |
833                                         BYT_RT5640_MCLK_EN),
834         },
835         {       /* Toshiba Encore WT8-A */
836                 .matches = {
837                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
838                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT8-A"),
839                 },
840                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
841                                         BYT_RT5640_JD_SRC_JD2_IN4N |
842                                         BYT_RT5640_OVCD_TH_2000UA |
843                                         BYT_RT5640_OVCD_SF_0P75 |
844                                         BYT_RT5640_JD_NOT_INV |
845                                         BYT_RT5640_MCLK_EN),
846         },
847         {       /* Toshiba Encore WT10-A */
848                 .matches = {
849                         DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
850                         DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT10-A-103"),
851                 },
852                 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
853                                         BYT_RT5640_JD_SRC_JD1_IN4P |
854                                         BYT_RT5640_OVCD_TH_2000UA |
855                                         BYT_RT5640_OVCD_SF_0P75 |
856                                         BYT_RT5640_SSP0_AIF2 |
857                                         BYT_RT5640_MCLK_EN),
858         },
859         {       /* Voyo Winpad A15 */
860                 .matches = {
861                         DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
862                         DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
863                         /* Above strings are too generic, also match on BIOS date */
864                         DMI_MATCH(DMI_BIOS_DATE, "11/20/2014"),
865                 },
866                 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
867                                         BYT_RT5640_JD_SRC_JD2_IN4N |
868                                         BYT_RT5640_OVCD_TH_2000UA |
869                                         BYT_RT5640_OVCD_SF_0P75 |
870                                         BYT_RT5640_DIFF_MIC |
871                                         BYT_RT5640_MCLK_EN),
872         },
873         {       /* Catch-all for generic Insyde tablets, must be last */
874                 .matches = {
875                         DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
876                 },
877                 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
878                                         BYT_RT5640_MCLK_EN |
879                                         BYT_RT5640_SSP0_AIF1),
880
881         },
882         {}
883 };
884
885 /*
886  * Note this MUST be called before snd_soc_register_card(), so that the props
887  * are in place before the codec component driver's probe function parses them.
888  */
889 static int byt_rt5640_add_codec_device_props(const char *i2c_dev_name)
890 {
891         struct property_entry props[MAX_NO_PROPS] = {};
892         struct device *i2c_dev;
893         int ret, cnt = 0;
894
895         i2c_dev = bus_find_device_by_name(&i2c_bus_type, NULL, i2c_dev_name);
896         if (!i2c_dev)
897                 return -EPROBE_DEFER;
898
899         switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
900         case BYT_RT5640_DMIC1_MAP:
901                 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic1-data-pin",
902                                                   RT5640_DMIC1_DATA_PIN_IN1P);
903                 break;
904         case BYT_RT5640_DMIC2_MAP:
905                 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic2-data-pin",
906                                                   RT5640_DMIC2_DATA_PIN_IN1N);
907                 break;
908         case BYT_RT5640_IN1_MAP:
909                 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
910                         props[cnt++] =
911                                 PROPERTY_ENTRY_BOOL("realtek,in1-differential");
912                 break;
913         case BYT_RT5640_IN3_MAP:
914                 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
915                         props[cnt++] =
916                                 PROPERTY_ENTRY_BOOL("realtek,in3-differential");
917                 break;
918         }
919
920         if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
921                 props[cnt++] = PROPERTY_ENTRY_U32(
922                                     "realtek,jack-detect-source",
923                                     BYT_RT5640_JDSRC(byt_rt5640_quirk));
924
925                 props[cnt++] = PROPERTY_ENTRY_U32(
926                                     "realtek,over-current-threshold-microamp",
927                                     BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
928
929                 props[cnt++] = PROPERTY_ENTRY_U32(
930                                     "realtek,over-current-scale-factor",
931                                     BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
932         }
933
934         if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
935                 props[cnt++] = PROPERTY_ENTRY_BOOL("realtek,jack-detect-not-inverted");
936
937         ret = device_add_properties(i2c_dev, props);
938         put_device(i2c_dev);
939
940         return ret;
941 }
942
943 static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
944 {
945         struct snd_soc_card *card = runtime->card;
946         struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
947         struct snd_soc_component *component = runtime->codec_dai->component;
948         const struct snd_soc_dapm_route *custom_map;
949         int num_routes;
950         int ret;
951
952         card->dapm.idle_bias_off = true;
953
954         /* Start with RC clk for jack-detect (we disable MCLK below) */
955         if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
956                 snd_soc_component_update_bits(component, RT5640_GLB_CLK,
957                         RT5640_SCLK_SRC_MASK, RT5640_SCLK_SRC_RCCLK);
958
959         rt5640_sel_asrc_clk_src(component,
960                                 RT5640_DA_STEREO_FILTER |
961                                 RT5640_DA_MONO_L_FILTER |
962                                 RT5640_DA_MONO_R_FILTER |
963                                 RT5640_AD_STEREO_FILTER |
964                                 RT5640_AD_MONO_L_FILTER |
965                                 RT5640_AD_MONO_R_FILTER,
966                                 RT5640_CLK_SEL_ASRC);
967
968         ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
969                                         ARRAY_SIZE(byt_rt5640_controls));
970         if (ret) {
971                 dev_err(card->dev, "unable to add card controls\n");
972                 return ret;
973         }
974
975         switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
976         case BYT_RT5640_IN1_MAP:
977                 custom_map = byt_rt5640_intmic_in1_map;
978                 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
979                 break;
980         case BYT_RT5640_IN3_MAP:
981                 custom_map = byt_rt5640_intmic_in3_map;
982                 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in3_map);
983                 break;
984         case BYT_RT5640_DMIC2_MAP:
985                 custom_map = byt_rt5640_intmic_dmic2_map;
986                 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
987                 break;
988         default:
989                 custom_map = byt_rt5640_intmic_dmic1_map;
990                 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
991         }
992
993         ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
994         if (ret)
995                 return ret;
996
997         if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
998                 ret = snd_soc_dapm_add_routes(&card->dapm,
999                                         byt_rt5640_ssp2_aif2_map,
1000                                         ARRAY_SIZE(byt_rt5640_ssp2_aif2_map));
1001         } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
1002                 ret = snd_soc_dapm_add_routes(&card->dapm,
1003                                         byt_rt5640_ssp0_aif1_map,
1004                                         ARRAY_SIZE(byt_rt5640_ssp0_aif1_map));
1005         } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
1006                 ret = snd_soc_dapm_add_routes(&card->dapm,
1007                                         byt_rt5640_ssp0_aif2_map,
1008                                         ARRAY_SIZE(byt_rt5640_ssp0_aif2_map));
1009         } else {
1010                 ret = snd_soc_dapm_add_routes(&card->dapm,
1011                                         byt_rt5640_ssp2_aif1_map,
1012                                         ARRAY_SIZE(byt_rt5640_ssp2_aif1_map));
1013         }
1014         if (ret)
1015                 return ret;
1016
1017         if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
1018                 ret = snd_soc_dapm_add_routes(&card->dapm,
1019                                         byt_rt5640_mono_spk_map,
1020                                         ARRAY_SIZE(byt_rt5640_mono_spk_map));
1021         } else {
1022                 ret = snd_soc_dapm_add_routes(&card->dapm,
1023                                         byt_rt5640_stereo_spk_map,
1024                                         ARRAY_SIZE(byt_rt5640_stereo_spk_map));
1025         }
1026         if (ret)
1027                 return ret;
1028
1029         snd_soc_dapm_ignore_suspend(&card->dapm, "Headphone");
1030         snd_soc_dapm_ignore_suspend(&card->dapm, "Speaker");
1031
1032         if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
1033                 /*
1034                  * The firmware might enable the clock at
1035                  * boot (this information may or may not
1036                  * be reflected in the enable clock register).
1037                  * To change the rate we must disable the clock
1038                  * first to cover these cases. Due to common
1039                  * clock framework restrictions that do not allow
1040                  * to disable a clock that has not been enabled,
1041                  * we need to enable the clock first.
1042                  */
1043                 ret = clk_prepare_enable(priv->mclk);
1044                 if (!ret)
1045                         clk_disable_unprepare(priv->mclk);
1046
1047                 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ)
1048                         ret = clk_set_rate(priv->mclk, 25000000);
1049                 else
1050                         ret = clk_set_rate(priv->mclk, 19200000);
1051
1052                 if (ret) {
1053                         dev_err(card->dev, "unable to set MCLK rate\n");
1054                         return ret;
1055                 }
1056         }
1057
1058         if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
1059                 ret = snd_soc_card_jack_new(card, "Headset",
1060                                             SND_JACK_HEADSET | SND_JACK_BTN_0,
1061                                             &priv->jack, rt5640_pins,
1062                                             ARRAY_SIZE(rt5640_pins));
1063                 if (ret) {
1064                         dev_err(card->dev, "Jack creation failed %d\n", ret);
1065                         return ret;
1066                 }
1067                 snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0,
1068                                  KEY_PLAYPAUSE);
1069                 snd_soc_component_set_jack(component, &priv->jack, NULL);
1070         }
1071
1072         return 0;
1073 }
1074
1075 static const struct snd_soc_pcm_stream byt_rt5640_dai_params = {
1076         .formats = SNDRV_PCM_FMTBIT_S24_LE,
1077         .rate_min = 48000,
1078         .rate_max = 48000,
1079         .channels_min = 2,
1080         .channels_max = 2,
1081 };
1082
1083 static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd,
1084                             struct snd_pcm_hw_params *params)
1085 {
1086         struct snd_interval *rate = hw_param_interval(params,
1087                         SNDRV_PCM_HW_PARAM_RATE);
1088         struct snd_interval *channels = hw_param_interval(params,
1089                                                 SNDRV_PCM_HW_PARAM_CHANNELS);
1090         int ret;
1091
1092         /* The DSP will covert the FE rate to 48k, stereo */
1093         rate->min = rate->max = 48000;
1094         channels->min = channels->max = 2;
1095
1096         if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
1097                 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
1098
1099                 /* set SSP0 to 16-bit */
1100                 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
1101
1102                 /*
1103                  * Default mode for SSP configuration is TDM 4 slot, override config
1104                  * with explicit setting to I2S 2ch 16-bit. The word length is set with
1105                  * dai_set_tdm_slot() since there is no other API exposed
1106                  */
1107                 ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
1108                                         SND_SOC_DAIFMT_I2S     |
1109                                         SND_SOC_DAIFMT_NB_NF   |
1110                                         SND_SOC_DAIFMT_CBS_CFS
1111                         );
1112                 if (ret < 0) {
1113                         dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
1114                         return ret;
1115                 }
1116
1117                 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 16);
1118                 if (ret < 0) {
1119                         dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
1120                         return ret;
1121                 }
1122
1123         } else {
1124
1125                 /* set SSP2 to 24-bit */
1126                 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
1127
1128                 /*
1129                  * Default mode for SSP configuration is TDM 4 slot, override config
1130                  * with explicit setting to I2S 2ch 24-bit. The word length is set with
1131                  * dai_set_tdm_slot() since there is no other API exposed
1132                  */
1133                 ret = snd_soc_dai_set_fmt(rtd->cpu_dai,
1134                                         SND_SOC_DAIFMT_I2S     |
1135                                         SND_SOC_DAIFMT_NB_NF   |
1136                                         SND_SOC_DAIFMT_CBS_CFS
1137                         );
1138                 if (ret < 0) {
1139                         dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
1140                         return ret;
1141                 }
1142
1143                 ret = snd_soc_dai_set_tdm_slot(rtd->cpu_dai, 0x3, 0x3, 2, 24);
1144                 if (ret < 0) {
1145                         dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
1146                         return ret;
1147                 }
1148         }
1149         return 0;
1150 }
1151
1152 static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream)
1153 {
1154         return snd_pcm_hw_constraint_single(substream->runtime,
1155                         SNDRV_PCM_HW_PARAM_RATE, 48000);
1156 }
1157
1158 static const struct snd_soc_ops byt_rt5640_aif1_ops = {
1159         .startup = byt_rt5640_aif1_startup,
1160 };
1161
1162 static const struct snd_soc_ops byt_rt5640_be_ssp2_ops = {
1163         .hw_params = byt_rt5640_aif1_hw_params,
1164 };
1165
1166 static struct snd_soc_dai_link byt_rt5640_dais[] = {
1167         [MERR_DPCM_AUDIO] = {
1168                 .name = "Baytrail Audio Port",
1169                 .stream_name = "Baytrail Audio",
1170                 .cpu_dai_name = "media-cpu-dai",
1171                 .codec_dai_name = "snd-soc-dummy-dai",
1172                 .codec_name = "snd-soc-dummy",
1173                 .platform_name = "sst-mfld-platform",
1174                 .nonatomic = true,
1175                 .dynamic = 1,
1176                 .dpcm_playback = 1,
1177                 .dpcm_capture = 1,
1178                 .ops = &byt_rt5640_aif1_ops,
1179         },
1180         [MERR_DPCM_DEEP_BUFFER] = {
1181                 .name = "Deep-Buffer Audio Port",
1182                 .stream_name = "Deep-Buffer Audio",
1183                 .cpu_dai_name = "deepbuffer-cpu-dai",
1184                 .codec_dai_name = "snd-soc-dummy-dai",
1185                 .codec_name = "snd-soc-dummy",
1186                 .platform_name = "sst-mfld-platform",
1187                 .nonatomic = true,
1188                 .dynamic = 1,
1189                 .dpcm_playback = 1,
1190                 .ops = &byt_rt5640_aif1_ops,
1191         },
1192                 /* back ends */
1193         {
1194                 .name = "SSP2-Codec",
1195                 .id = 0,
1196                 .cpu_dai_name = "ssp2-port", /* overwritten for ssp0 routing */
1197                 .platform_name = "sst-mfld-platform",
1198                 .no_pcm = 1,
1199                 .codec_dai_name = "rt5640-aif1", /* changed w/ quirk */
1200                 .codec_name = "i2c-10EC5640:00", /* overwritten with HID */
1201                 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
1202                                                 | SND_SOC_DAIFMT_CBS_CFS,
1203                 .be_hw_params_fixup = byt_rt5640_codec_fixup,
1204                 .ignore_suspend = 1,
1205                 .nonatomic = true,
1206                 .dpcm_playback = 1,
1207                 .dpcm_capture = 1,
1208                 .init = byt_rt5640_init,
1209                 .ops = &byt_rt5640_be_ssp2_ops,
1210         },
1211 };
1212
1213 /* SoC card */
1214 static char byt_rt5640_codec_name[SND_ACPI_I2C_ID_LEN];
1215 static char byt_rt5640_codec_aif_name[12]; /*  = "rt5640-aif[1|2]" */
1216 static char byt_rt5640_cpu_dai_name[10]; /*  = "ssp[0|2]-port" */
1217 static char byt_rt5640_long_name[40]; /* = "bytcr-rt5640-*-spk-*-mic" */
1218
1219 static int byt_rt5640_suspend(struct snd_soc_card *card)
1220 {
1221         struct snd_soc_component *component;
1222
1223         if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1224                 return 0;
1225
1226         list_for_each_entry(component, &card->component_dev_list, card_list) {
1227                 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1228                         dev_dbg(component->dev, "disabling jack detect before suspend\n");
1229                         snd_soc_component_set_jack(component, NULL, NULL);
1230                         break;
1231                 }
1232         }
1233
1234         return 0;
1235 }
1236
1237 static int byt_rt5640_resume(struct snd_soc_card *card)
1238 {
1239         struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
1240         struct snd_soc_component *component;
1241
1242         if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1243                 return 0;
1244
1245         list_for_each_entry(component, &card->component_dev_list, card_list) {
1246                 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1247                         dev_dbg(component->dev, "re-enabling jack detect after resume\n");
1248                         snd_soc_component_set_jack(component, &priv->jack, NULL);
1249                         break;
1250                 }
1251         }
1252
1253         return 0;
1254 }
1255
1256 static struct snd_soc_card byt_rt5640_card = {
1257         .name = "bytcr-rt5640",
1258         .owner = THIS_MODULE,
1259         .dai_link = byt_rt5640_dais,
1260         .num_links = ARRAY_SIZE(byt_rt5640_dais),
1261         .dapm_widgets = byt_rt5640_widgets,
1262         .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
1263         .dapm_routes = byt_rt5640_audio_map,
1264         .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
1265         .fully_routed = true,
1266         .suspend_pre = byt_rt5640_suspend,
1267         .resume_post = byt_rt5640_resume,
1268 };
1269
1270 static bool is_valleyview(void)
1271 {
1272         static const struct x86_cpu_id cpu_ids[] = {
1273                 { X86_VENDOR_INTEL, 6, 55 }, /* Valleyview, Bay Trail */
1274                 {}
1275         };
1276
1277         if (!x86_match_cpu(cpu_ids))
1278                 return false;
1279         return true;
1280 }
1281
1282 struct acpi_chan_package {   /* ACPICA seems to require 64 bit integers */
1283         u64 aif_value;       /* 1: AIF1, 2: AIF2 */
1284         u64 mclock_value;    /* usually 25MHz (0x17d7940), ignored */
1285 };
1286
1287 static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
1288 {
1289         const char * const map_name[] = { "dmic1", "dmic2", "in1", "in3" };
1290         const struct dmi_system_id *dmi_id;
1291         struct byt_rt5640_private *priv;
1292         struct snd_soc_acpi_mach *mach;
1293         const char *i2c_name = NULL;
1294         int ret_val = 0;
1295         int dai_index = 0;
1296         int i;
1297
1298         is_bytcr = false;
1299         priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
1300         if (!priv)
1301                 return -ENOMEM;
1302
1303         /* register the soc card */
1304         byt_rt5640_card.dev = &pdev->dev;
1305         mach = byt_rt5640_card.dev->platform_data;
1306         snd_soc_card_set_drvdata(&byt_rt5640_card, priv);
1307
1308         /* fix index of codec dai */
1309         for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) {
1310                 if (!strcmp(byt_rt5640_dais[i].codec_name, "i2c-10EC5640:00")) {
1311                         dai_index = i;
1312                         break;
1313                 }
1314         }
1315
1316         /* fixup codec name based on HID */
1317         i2c_name = acpi_dev_get_first_match_name(mach->id, NULL, -1);
1318         if (i2c_name) {
1319                 snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name),
1320                         "%s%s", "i2c-", i2c_name);
1321
1322                 byt_rt5640_dais[dai_index].codec_name = byt_rt5640_codec_name;
1323         }
1324
1325         /*
1326          * swap SSP0 if bytcr is detected
1327          * (will be overridden if DMI quirk is detected)
1328          */
1329         if (is_valleyview()) {
1330                 struct sst_platform_info *p_info = mach->pdata;
1331                 const struct sst_res_info *res_info = p_info->res_info;
1332
1333                 if (res_info->acpi_ipc_irq_index == 0)
1334                         is_bytcr = true;
1335         }
1336
1337         if (is_bytcr) {
1338                 /*
1339                  * Baytrail CR platforms may have CHAN package in BIOS, try
1340                  * to find relevant routing quirk based as done on Windows
1341                  * platforms. We have to read the information directly from the
1342                  * BIOS, at this stage the card is not created and the links
1343                  * with the codec driver/pdata are non-existent
1344                  */
1345
1346                 struct acpi_chan_package chan_package;
1347
1348                 /* format specified: 2 64-bit integers */
1349                 struct acpi_buffer format = {sizeof("NN"), "NN"};
1350                 struct acpi_buffer state = {0, NULL};
1351                 struct snd_soc_acpi_package_context pkg_ctx;
1352                 bool pkg_found = false;
1353
1354                 state.length = sizeof(chan_package);
1355                 state.pointer = &chan_package;
1356
1357                 pkg_ctx.name = "CHAN";
1358                 pkg_ctx.length = 2;
1359                 pkg_ctx.format = &format;
1360                 pkg_ctx.state = &state;
1361                 pkg_ctx.data_valid = false;
1362
1363                 pkg_found = snd_soc_acpi_find_package_from_hid(mach->id,
1364                                                                &pkg_ctx);
1365                 if (pkg_found) {
1366                         if (chan_package.aif_value == 1) {
1367                                 dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n");
1368                                 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF1;
1369                         } else  if (chan_package.aif_value == 2) {
1370                                 dev_info(&pdev->dev, "BIOS Routing: AIF2 connected\n");
1371                                 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1372                         } else {
1373                                 dev_info(&pdev->dev, "BIOS Routing isn't valid, ignored\n");
1374                                 pkg_found = false;
1375                         }
1376                 }
1377
1378                 if (!pkg_found) {
1379                         /* no BIOS indications, assume SSP0-AIF2 connection */
1380                         byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1381                 }
1382
1383                 /* change defaults for Baytrail-CR capture */
1384                 byt_rt5640_quirk |= BYTCR_INPUT_DEFAULTS;
1385         } else {
1386                 byt_rt5640_quirk |= BYT_RT5640_DMIC1_MAP |
1387                                     BYT_RT5640_JD_SRC_JD2_IN4N |
1388                                     BYT_RT5640_OVCD_TH_2000UA |
1389                                     BYT_RT5640_OVCD_SF_0P75;
1390         }
1391
1392         /* check quirks before creating card */
1393         dmi_id = dmi_first_match(byt_rt5640_quirk_table);
1394         if (dmi_id)
1395                 byt_rt5640_quirk = (unsigned long)dmi_id->driver_data;
1396         if (quirk_override) {
1397                 dev_info(&pdev->dev, "Overriding quirk 0x%x => 0x%x\n",
1398                          (unsigned int)byt_rt5640_quirk, quirk_override);
1399                 byt_rt5640_quirk = quirk_override;
1400         }
1401
1402         /* Must be called before register_card, also see declaration comment. */
1403         ret_val = byt_rt5640_add_codec_device_props(byt_rt5640_codec_name);
1404         if (ret_val)
1405                 return ret_val;
1406
1407         log_quirks(&pdev->dev);
1408
1409         if ((byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) ||
1410             (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
1411
1412                 /* fixup codec aif name */
1413                 snprintf(byt_rt5640_codec_aif_name,
1414                         sizeof(byt_rt5640_codec_aif_name),
1415                         "%s", "rt5640-aif2");
1416
1417                 byt_rt5640_dais[dai_index].codec_dai_name =
1418                         byt_rt5640_codec_aif_name;
1419         }
1420
1421         if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
1422             (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
1423
1424                 /* fixup cpu dai name name */
1425                 snprintf(byt_rt5640_cpu_dai_name,
1426                         sizeof(byt_rt5640_cpu_dai_name),
1427                         "%s", "ssp0-port");
1428
1429                 byt_rt5640_dais[dai_index].cpu_dai_name =
1430                         byt_rt5640_cpu_dai_name;
1431         }
1432
1433         if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
1434                 priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
1435                 if (IS_ERR(priv->mclk)) {
1436                         ret_val = PTR_ERR(priv->mclk);
1437
1438                         dev_err(&pdev->dev,
1439                                 "Failed to get MCLK from pmc_plt_clk_3: %d\n",
1440                                 ret_val);
1441
1442                         /*
1443                          * Fall back to bit clock usage for -ENOENT (clock not
1444                          * available likely due to missing dependencies), bail
1445                          * for all other errors, including -EPROBE_DEFER
1446                          */
1447                         if (ret_val != -ENOENT)
1448                                 return ret_val;
1449                         byt_rt5640_quirk &= ~BYT_RT5640_MCLK_EN;
1450                 }
1451         }
1452
1453         snprintf(byt_rt5640_long_name, sizeof(byt_rt5640_long_name),
1454                  "bytcr-rt5640-%s-spk-%s-mic",
1455                  (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) ?
1456                         "mono" : "stereo",
1457                  map_name[BYT_RT5640_MAP(byt_rt5640_quirk)]);
1458         byt_rt5640_card.long_name = byt_rt5640_long_name;
1459
1460         ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card);
1461
1462         if (ret_val) {
1463                 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
1464                         ret_val);
1465                 return ret_val;
1466         }
1467         platform_set_drvdata(pdev, &byt_rt5640_card);
1468         return ret_val;
1469 }
1470
1471 static struct platform_driver snd_byt_rt5640_mc_driver = {
1472         .driver = {
1473                 .name = "bytcr_rt5640",
1474         },
1475         .probe = snd_byt_rt5640_mc_probe,
1476 };
1477
1478 module_platform_driver(snd_byt_rt5640_mc_driver);
1479
1480 MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
1481 MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
1482 MODULE_LICENSE("GPL v2");
1483 MODULE_ALIAS("platform:bytcr_rt5640");