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