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