1 // SPDX-License-Identifier: GPL-2.0-only
3 * byt_cr_dpcm_rt5640.c - ASoc Machine driver for Intel Byt CR platform
5 * Copyright (C) 2014 Intel Corp
6 * Author: Subhransu S. Prusty <subhransu.s.prusty@intel.com>
7 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
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"
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),
50 BYT_RT5640_OVCD_TH_600UA = (6 << 8),
51 BYT_RT5640_OVCD_TH_1500UA = (15 << 8),
52 BYT_RT5640_OVCD_TH_2000UA = (20 << 8),
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),
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)
75 #define BYTCR_INPUT_DEFAULTS \
76 (BYT_RT5640_IN3_MAP | \
77 BYT_RT5640_JD_SRC_JD1_IN4P | \
78 BYT_RT5640_OVCD_TH_2000UA | \
79 BYT_RT5640_OVCD_SF_0P75 | \
82 /* in-diff or dmic-pin + jdsrc + ovcd-th + -sf + jd-inv + terminating entry */
83 #define MAX_NO_PROPS 6
85 struct byt_rt5640_private {
86 struct snd_soc_jack jack;
91 static unsigned long byt_rt5640_quirk = BYT_RT5640_MCLK_EN;
92 static int quirk_override = -1;
93 module_param_named(quirk, quirk_override, int, 0444);
94 MODULE_PARM_DESC(quirk, "Board-specific quirk override");
96 static void log_quirks(struct device *dev)
99 bool has_mclk = false;
100 bool has_ssp0 = false;
101 bool has_ssp0_aif1 = false;
102 bool has_ssp0_aif2 = false;
103 bool has_ssp2_aif2 = false;
105 map = BYT_RT5640_MAP(byt_rt5640_quirk);
107 case BYT_RT5640_DMIC1_MAP:
108 dev_info(dev, "quirk DMIC1_MAP enabled\n");
110 case BYT_RT5640_DMIC2_MAP:
111 dev_info(dev, "quirk DMIC2_MAP enabled\n");
113 case BYT_RT5640_IN1_MAP:
114 dev_info(dev, "quirk IN1_MAP enabled\n");
116 case BYT_RT5640_IN3_MAP:
117 dev_info(dev, "quirk IN3_MAP enabled\n");
120 dev_err(dev, "quirk map 0x%x is not supported, microphone input will not work\n", map);
123 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
124 dev_info(dev, "quirk realtek,jack-detect-source %ld\n",
125 BYT_RT5640_JDSRC(byt_rt5640_quirk));
126 dev_info(dev, "quirk realtek,over-current-threshold-microamp %ld\n",
127 BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
128 dev_info(dev, "quirk realtek,over-current-scale-factor %ld\n",
129 BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
131 if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
132 dev_info(dev, "quirk JD_NOT_INV enabled\n");
133 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER)
134 dev_info(dev, "quirk MONO_SPEAKER enabled\n");
135 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
136 dev_info(dev, "quirk DIFF_MIC enabled\n");
137 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
138 dev_info(dev, "quirk SSP0_AIF1 enabled\n");
140 has_ssp0_aif1 = true;
142 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
143 dev_info(dev, "quirk SSP0_AIF2 enabled\n");
145 has_ssp0_aif2 = true;
147 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
148 dev_info(dev, "quirk SSP2_AIF2 enabled\n");
149 has_ssp2_aif2 = true;
151 if (is_bytcr && !has_ssp0)
152 dev_err(dev, "Invalid routing, bytcr detected but no SSP0-based quirk, audio cannot work with SSP2 on bytcr\n");
153 if (has_ssp0_aif1 && has_ssp0_aif2)
154 dev_err(dev, "Invalid routing, SSP0 cannot be connected to both AIF1 and AIF2\n");
155 if (has_ssp0 && has_ssp2_aif2)
156 dev_err(dev, "Invalid routing, cannot have both SSP0 and SSP2 connected to codec\n");
158 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
159 dev_info(dev, "quirk MCLK_EN enabled\n");
162 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
164 dev_info(dev, "quirk MCLK_25MHZ enabled\n");
166 dev_err(dev, "quirk MCLK_25MHZ enabled but quirk MCLK not selected, will be ignored\n");
170 static int byt_rt5640_prepare_and_enable_pll1(struct snd_soc_dai *codec_dai,
175 /* Configure the PLL before selecting it */
176 if (!(byt_rt5640_quirk & BYT_RT5640_MCLK_EN)) {
177 /* use bitclock as PLL input */
178 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
179 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
180 /* 2x16 bit slots on SSP0 */
181 ret = snd_soc_dai_set_pll(codec_dai, 0,
183 rate * 32, rate * 512);
185 /* 2x15 bit slots on SSP2 */
186 ret = snd_soc_dai_set_pll(codec_dai, 0,
188 rate * 50, rate * 512);
191 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
192 ret = snd_soc_dai_set_pll(codec_dai, 0,
194 25000000, rate * 512);
196 ret = snd_soc_dai_set_pll(codec_dai, 0,
198 19200000, rate * 512);
203 dev_err(codec_dai->component->dev, "can't set pll: %d\n", ret);
207 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
208 rate * 512, SND_SOC_CLOCK_IN);
210 dev_err(codec_dai->component->dev, "can't set clock %d\n", ret);
217 #define BYT_CODEC_DAI1 "rt5640-aif1"
218 #define BYT_CODEC_DAI2 "rt5640-aif2"
220 static int platform_clock_control(struct snd_soc_dapm_widget *w,
221 struct snd_kcontrol *k, int event)
223 struct snd_soc_dapm_context *dapm = w->dapm;
224 struct snd_soc_card *card = dapm->card;
225 struct snd_soc_dai *codec_dai;
226 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
229 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI1);
231 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI2);
235 "Codec dai not found; Unable to set platform clock\n");
239 if (SND_SOC_DAPM_EVENT_ON(event)) {
240 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
241 ret = clk_prepare_enable(priv->mclk);
244 "could not configure MCLK state\n");
248 ret = byt_rt5640_prepare_and_enable_pll1(codec_dai, 48000);
251 * Set codec clock source to internal clock before
252 * turning off the platform clock. Codec needs clock
253 * for Jack detection and button press
255 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_RCCLK,
259 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
260 clk_disable_unprepare(priv->mclk);
265 dev_err(card->dev, "can't set codec sysclk: %d\n", ret);
272 static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
273 SND_SOC_DAPM_HP("Headphone", NULL),
274 SND_SOC_DAPM_MIC("Headset Mic", NULL),
275 SND_SOC_DAPM_MIC("Internal Mic", NULL),
276 SND_SOC_DAPM_SPK("Speaker", NULL),
277 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
278 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
279 SND_SOC_DAPM_POST_PMD),
283 static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
284 {"Headphone", NULL, "Platform Clock"},
285 {"Headset Mic", NULL, "Platform Clock"},
286 {"Internal Mic", NULL, "Platform Clock"},
287 {"Speaker", NULL, "Platform Clock"},
289 {"Headset Mic", NULL, "MICBIAS1"},
290 {"IN2P", NULL, "Headset Mic"},
291 {"Headphone", NULL, "HPOL"},
292 {"Headphone", NULL, "HPOR"},
295 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
296 {"DMIC1", NULL, "Internal Mic"},
299 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
300 {"DMIC2", NULL, "Internal Mic"},
303 static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
304 {"Internal Mic", NULL, "MICBIAS1"},
305 {"IN1P", NULL, "Internal Mic"},
308 static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map[] = {
309 {"Internal Mic", NULL, "MICBIAS1"},
310 {"IN3P", NULL, "Internal Mic"},
313 static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = {
314 {"ssp2 Tx", NULL, "codec_out0"},
315 {"ssp2 Tx", NULL, "codec_out1"},
316 {"codec_in0", NULL, "ssp2 Rx"},
317 {"codec_in1", NULL, "ssp2 Rx"},
319 {"AIF1 Playback", NULL, "ssp2 Tx"},
320 {"ssp2 Rx", NULL, "AIF1 Capture"},
323 static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_map[] = {
324 {"ssp2 Tx", NULL, "codec_out0"},
325 {"ssp2 Tx", NULL, "codec_out1"},
326 {"codec_in0", NULL, "ssp2 Rx"},
327 {"codec_in1", NULL, "ssp2 Rx"},
329 {"AIF2 Playback", NULL, "ssp2 Tx"},
330 {"ssp2 Rx", NULL, "AIF2 Capture"},
333 static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif1_map[] = {
334 {"ssp0 Tx", NULL, "modem_out"},
335 {"modem_in", NULL, "ssp0 Rx"},
337 {"AIF1 Playback", NULL, "ssp0 Tx"},
338 {"ssp0 Rx", NULL, "AIF1 Capture"},
341 static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif2_map[] = {
342 {"ssp0 Tx", NULL, "modem_out"},
343 {"modem_in", NULL, "ssp0 Rx"},
345 {"AIF2 Playback", NULL, "ssp0 Tx"},
346 {"ssp0 Rx", NULL, "AIF2 Capture"},
349 static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = {
350 {"Speaker", NULL, "SPOLP"},
351 {"Speaker", NULL, "SPOLN"},
352 {"Speaker", NULL, "SPORP"},
353 {"Speaker", NULL, "SPORN"},
356 static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = {
357 {"Speaker", NULL, "SPOLP"},
358 {"Speaker", NULL, "SPOLN"},
361 static const struct snd_kcontrol_new byt_rt5640_controls[] = {
362 SOC_DAPM_PIN_SWITCH("Headphone"),
363 SOC_DAPM_PIN_SWITCH("Headset Mic"),
364 SOC_DAPM_PIN_SWITCH("Internal Mic"),
365 SOC_DAPM_PIN_SWITCH("Speaker"),
368 static struct snd_soc_jack_pin rt5640_pins[] = {
371 .mask = SND_JACK_HEADPHONE,
374 .pin = "Headset Mic",
375 .mask = SND_JACK_MICROPHONE,
379 static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream,
380 struct snd_pcm_hw_params *params)
382 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
383 struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
385 return byt_rt5640_prepare_and_enable_pll1(dai, params_rate(params));
388 /* Please keep this list alphabetically sorted */
389 static const struct dmi_system_id byt_rt5640_quirk_table[] = {
390 { /* Acer Iconia Tab 8 W1-810 */
392 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"),
393 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Iconia W1-810"),
395 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
396 BYT_RT5640_JD_SRC_JD1_IN4P |
397 BYT_RT5640_OVCD_TH_1500UA |
398 BYT_RT5640_OVCD_SF_0P75 |
399 BYT_RT5640_SSP0_AIF1 |
404 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
405 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
407 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
408 BYT_RT5640_JD_SRC_JD2_IN4N |
409 BYT_RT5640_OVCD_TH_2000UA |
410 BYT_RT5640_OVCD_SF_0P75 |
411 BYT_RT5640_SSP0_AIF1 |
416 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
417 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 80 Cesium"),
419 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
420 BYT_RT5640_MONO_SPEAKER |
421 BYT_RT5640_SSP0_AIF1 |
426 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
427 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ME176C"),
429 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
430 BYT_RT5640_JD_SRC_JD2_IN4N |
431 BYT_RT5640_OVCD_TH_2000UA |
432 BYT_RT5640_OVCD_SF_0P75 |
433 BYT_RT5640_SSP0_AIF1 |
438 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
439 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
441 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
442 BYT_RT5640_JD_SRC_JD2_IN4N |
443 BYT_RT5640_OVCD_TH_2000UA |
444 BYT_RT5640_OVCD_SF_0P75 |
449 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
450 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"),
452 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
453 BYT_RT5640_MONO_SPEAKER |
454 BYT_RT5640_DIFF_MIC |
455 BYT_RT5640_SSP0_AIF2 |
458 { /* Chuwi Vi8 (CWI506) */
460 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Insyde"),
461 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "i86"),
462 /* The above are too generic, also match BIOS info */
463 DMI_MATCH(DMI_BIOS_VERSION, "CHUWI.D86JLBNR"),
465 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
466 BYT_RT5640_MONO_SPEAKER |
467 BYT_RT5640_SSP0_AIF1 |
471 /* Chuwi Vi10 (CWI505) */
473 DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
474 DMI_MATCH(DMI_BOARD_NAME, "BYT-PF02"),
475 DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
476 DMI_MATCH(DMI_PRODUCT_NAME, "S165"),
478 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
479 BYT_RT5640_JD_SRC_JD2_IN4N |
480 BYT_RT5640_OVCD_TH_2000UA |
481 BYT_RT5640_OVCD_SF_0P75 |
482 BYT_RT5640_DIFF_MIC |
483 BYT_RT5640_SSP0_AIF1 |
488 DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
489 DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"),
491 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP),
493 { /* Connect Tablet 9 */
495 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Connect"),
496 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Tablet 9"),
498 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
499 BYT_RT5640_MONO_SPEAKER |
500 BYT_RT5640_SSP0_AIF1 |
505 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
506 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
508 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
509 BYT_RT5640_JD_SRC_JD2_IN4N |
510 BYT_RT5640_OVCD_TH_2000UA |
511 BYT_RT5640_OVCD_SF_0P75 |
512 BYT_RT5640_MONO_SPEAKER |
517 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
518 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"),
520 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
523 { /* HP Pavilion x2 10-n000nd */
525 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
526 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP Pavilion x2 Detachable"),
528 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
529 BYT_RT5640_JD_SRC_JD2_IN4N |
530 BYT_RT5640_OVCD_TH_1500UA |
531 BYT_RT5640_OVCD_SF_0P75 |
532 BYT_RT5640_SSP0_AIF1 |
537 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
538 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP Stream 7 Tablet"),
540 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
541 BYT_RT5640_MONO_SPEAKER |
542 BYT_RT5640_JD_NOT_INV |
543 BYT_RT5640_SSP0_AIF1 |
546 { /* I.T.Works TW891 */
548 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "To be filled by O.E.M."),
549 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TW891"),
550 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "To be filled by O.E.M."),
551 DMI_EXACT_MATCH(DMI_BOARD_NAME, "TW891"),
553 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
554 BYT_RT5640_MONO_SPEAKER |
555 BYT_RT5640_SSP0_AIF1 |
558 { /* Lamina I8270 / T701BR.SE */
560 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Lamina"),
561 DMI_EXACT_MATCH(DMI_BOARD_NAME, "T701BR.SE"),
563 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
564 BYT_RT5640_MONO_SPEAKER |
565 BYT_RT5640_JD_NOT_INV |
566 BYT_RT5640_SSP0_AIF1 |
569 { /* Lenovo Miix 2 8 */
571 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
572 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "20326"),
573 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Hiking"),
575 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
576 BYT_RT5640_JD_SRC_JD2_IN4N |
577 BYT_RT5640_OVCD_TH_2000UA |
578 BYT_RT5640_OVCD_SF_0P75 |
579 BYT_RT5640_MONO_SPEAKER |
582 { /* Linx Linx7 tablet */
584 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LINX"),
585 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "LINX7"),
587 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
588 BYT_RT5640_MONO_SPEAKER |
589 BYT_RT5640_JD_NOT_INV |
590 BYT_RT5640_SSP0_AIF1 |
593 { /* MPMAN Converter 9, similar hw as the I.T.Works TW891 2-in-1 */
595 DMI_MATCH(DMI_SYS_VENDOR, "MPMAN"),
596 DMI_MATCH(DMI_PRODUCT_NAME, "Converter9"),
598 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
599 BYT_RT5640_MONO_SPEAKER |
600 BYT_RT5640_SSP0_AIF1 |
604 /* MPMAN MPWIN895CL */
606 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "MPMAN"),
607 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MPWIN8900CL"),
609 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
610 BYT_RT5640_MONO_SPEAKER |
611 BYT_RT5640_SSP0_AIF1 |
614 { /* MSI S100 tablet */
616 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Micro-Star International Co., Ltd."),
617 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "S100"),
619 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
620 BYT_RT5640_JD_SRC_JD2_IN4N |
621 BYT_RT5640_OVCD_TH_2000UA |
622 BYT_RT5640_OVCD_SF_0P75 |
623 BYT_RT5640_MONO_SPEAKER |
624 BYT_RT5640_DIFF_MIC |
627 { /* Nuvison/TMax TM800W560 */
629 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TMAX"),
630 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TM800W560L"),
632 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
633 BYT_RT5640_JD_SRC_JD2_IN4N |
634 BYT_RT5640_OVCD_TH_2000UA |
635 BYT_RT5640_OVCD_SF_0P75 |
636 BYT_RT5640_JD_NOT_INV |
637 BYT_RT5640_DIFF_MIC |
638 BYT_RT5640_SSP0_AIF1 |
643 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
644 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
645 /* The above are too generic, also match BIOS info */
646 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "5.6.5"),
647 DMI_EXACT_MATCH(DMI_BIOS_DATE, "07/25/2014"),
649 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
650 BYT_RT5640_JD_SRC_JD2_IN4N |
651 BYT_RT5640_OVCD_TH_2000UA |
652 BYT_RT5640_OVCD_SF_0P75 |
653 BYT_RT5640_DIFF_MIC |
658 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
659 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
660 /* The above are too generic, also match BIOS info */
661 DMI_MATCH(DMI_BIOS_VERSION, "V8L_WIN32_CHIPHD"),
663 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
664 BYT_RT5640_MONO_SPEAKER |
665 BYT_RT5640_SSP0_AIF1 |
668 { /* Point of View Mobii TAB-P800W (V2.0) */
670 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
671 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
672 /* The above are too generic, also match BIOS info */
673 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1014"),
674 DMI_EXACT_MATCH(DMI_BIOS_DATE, "10/24/2014"),
676 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
677 BYT_RT5640_JD_SRC_JD2_IN4N |
678 BYT_RT5640_OVCD_TH_2000UA |
679 BYT_RT5640_OVCD_SF_0P75 |
680 BYT_RT5640_MONO_SPEAKER |
681 BYT_RT5640_DIFF_MIC |
682 BYT_RT5640_SSP0_AIF2 |
685 { /* Point of View Mobii TAB-P800W (V2.1) */
687 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
688 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
689 /* The above are too generic, also match BIOS info */
690 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1013"),
691 DMI_EXACT_MATCH(DMI_BIOS_DATE, "08/22/2014"),
693 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
694 BYT_RT5640_JD_SRC_JD2_IN4N |
695 BYT_RT5640_OVCD_TH_2000UA |
696 BYT_RT5640_OVCD_SF_0P75 |
697 BYT_RT5640_MONO_SPEAKER |
698 BYT_RT5640_DIFF_MIC |
699 BYT_RT5640_SSP0_AIF2 |
702 { /* Point of View Mobii TAB-P1005W-232 (V2.0) */
704 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "POV"),
705 DMI_EXACT_MATCH(DMI_BOARD_NAME, "I102A"),
707 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
708 BYT_RT5640_JD_SRC_JD2_IN4N |
709 BYT_RT5640_OVCD_TH_2000UA |
710 BYT_RT5640_OVCD_SF_0P75 |
711 BYT_RT5640_DIFF_MIC |
712 BYT_RT5640_SSP0_AIF1 |
718 DMI_MATCH(DMI_SYS_VENDOR, "Prowise"),
719 DMI_MATCH(DMI_PRODUCT_NAME, "PT301"),
721 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
722 BYT_RT5640_JD_SRC_JD2_IN4N |
723 BYT_RT5640_OVCD_TH_2000UA |
724 BYT_RT5640_OVCD_SF_0P75 |
725 BYT_RT5640_DIFF_MIC |
726 BYT_RT5640_SSP0_AIF1 |
732 DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"),
733 DMI_MATCH(DMI_BOARD_NAME, "tPAD"),
735 .driver_data = (void *)(BYT_RT5640_IN3_MAP |
736 BYT_RT5640_JD_SRC_JD1_IN4P |
737 BYT_RT5640_OVCD_TH_2000UA |
738 BYT_RT5640_OVCD_SF_1P0 |
739 BYT_RT5640_SSP0_AIF1 |
742 { /* Toshiba Satellite Click Mini L9W-B */
744 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
745 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "SATELLITE Click Mini L9W-B"),
747 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
748 BYT_RT5640_JD_SRC_JD2_IN4N |
749 BYT_RT5640_OVCD_TH_1500UA |
750 BYT_RT5640_OVCD_SF_0P75 |
751 BYT_RT5640_SSP0_AIF1 |
754 { /* Toshiba Encore WT8-A */
756 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
757 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT8-A"),
759 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
760 BYT_RT5640_JD_SRC_JD2_IN4N |
761 BYT_RT5640_OVCD_TH_2000UA |
762 BYT_RT5640_OVCD_SF_0P75 |
763 BYT_RT5640_JD_NOT_INV |
766 { /* Toshiba Encore WT10-A */
768 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
769 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT10-A-103"),
771 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
772 BYT_RT5640_JD_SRC_JD1_IN4P |
773 BYT_RT5640_OVCD_TH_2000UA |
774 BYT_RT5640_OVCD_SF_0P75 |
775 BYT_RT5640_SSP0_AIF2 |
778 { /* Catch-all for generic Insyde tablets, must be last */
780 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
782 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
784 BYT_RT5640_SSP0_AIF1),
791 * Note this MUST be called before snd_soc_register_card(), so that the props
792 * are in place before the codec component driver's probe function parses them.
794 static int byt_rt5640_add_codec_device_props(const char *i2c_dev_name)
796 struct property_entry props[MAX_NO_PROPS] = {};
797 struct device *i2c_dev;
800 i2c_dev = bus_find_device_by_name(&i2c_bus_type, NULL, i2c_dev_name);
802 return -EPROBE_DEFER;
804 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
805 case BYT_RT5640_DMIC1_MAP:
806 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic1-data-pin",
807 RT5640_DMIC1_DATA_PIN_IN1P);
809 case BYT_RT5640_DMIC2_MAP:
810 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic2-data-pin",
811 RT5640_DMIC2_DATA_PIN_IN1N);
813 case BYT_RT5640_IN1_MAP:
814 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
816 PROPERTY_ENTRY_BOOL("realtek,in1-differential");
818 case BYT_RT5640_IN3_MAP:
819 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
821 PROPERTY_ENTRY_BOOL("realtek,in3-differential");
825 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
826 props[cnt++] = PROPERTY_ENTRY_U32(
827 "realtek,jack-detect-source",
828 BYT_RT5640_JDSRC(byt_rt5640_quirk));
830 props[cnt++] = PROPERTY_ENTRY_U32(
831 "realtek,over-current-threshold-microamp",
832 BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
834 props[cnt++] = PROPERTY_ENTRY_U32(
835 "realtek,over-current-scale-factor",
836 BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
839 if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
840 props[cnt++] = PROPERTY_ENTRY_BOOL("realtek,jack-detect-not-inverted");
842 ret = device_add_properties(i2c_dev, props);
848 static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
850 struct snd_soc_card *card = runtime->card;
851 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
852 struct snd_soc_component *component = asoc_rtd_to_codec(runtime, 0)->component;
853 const struct snd_soc_dapm_route *custom_map;
857 card->dapm.idle_bias_off = true;
859 /* Start with RC clk for jack-detect (we disable MCLK below) */
860 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
861 snd_soc_component_update_bits(component, RT5640_GLB_CLK,
862 RT5640_SCLK_SRC_MASK, RT5640_SCLK_SRC_RCCLK);
864 rt5640_sel_asrc_clk_src(component,
865 RT5640_DA_STEREO_FILTER |
866 RT5640_DA_MONO_L_FILTER |
867 RT5640_DA_MONO_R_FILTER |
868 RT5640_AD_STEREO_FILTER |
869 RT5640_AD_MONO_L_FILTER |
870 RT5640_AD_MONO_R_FILTER,
871 RT5640_CLK_SEL_ASRC);
873 ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
874 ARRAY_SIZE(byt_rt5640_controls));
876 dev_err(card->dev, "unable to add card controls\n");
880 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
881 case BYT_RT5640_IN1_MAP:
882 custom_map = byt_rt5640_intmic_in1_map;
883 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
885 case BYT_RT5640_IN3_MAP:
886 custom_map = byt_rt5640_intmic_in3_map;
887 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in3_map);
889 case BYT_RT5640_DMIC2_MAP:
890 custom_map = byt_rt5640_intmic_dmic2_map;
891 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
894 custom_map = byt_rt5640_intmic_dmic1_map;
895 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
898 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
902 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
903 ret = snd_soc_dapm_add_routes(&card->dapm,
904 byt_rt5640_ssp2_aif2_map,
905 ARRAY_SIZE(byt_rt5640_ssp2_aif2_map));
906 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
907 ret = snd_soc_dapm_add_routes(&card->dapm,
908 byt_rt5640_ssp0_aif1_map,
909 ARRAY_SIZE(byt_rt5640_ssp0_aif1_map));
910 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
911 ret = snd_soc_dapm_add_routes(&card->dapm,
912 byt_rt5640_ssp0_aif2_map,
913 ARRAY_SIZE(byt_rt5640_ssp0_aif2_map));
915 ret = snd_soc_dapm_add_routes(&card->dapm,
916 byt_rt5640_ssp2_aif1_map,
917 ARRAY_SIZE(byt_rt5640_ssp2_aif1_map));
922 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
923 ret = snd_soc_dapm_add_routes(&card->dapm,
924 byt_rt5640_mono_spk_map,
925 ARRAY_SIZE(byt_rt5640_mono_spk_map));
927 ret = snd_soc_dapm_add_routes(&card->dapm,
928 byt_rt5640_stereo_spk_map,
929 ARRAY_SIZE(byt_rt5640_stereo_spk_map));
934 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
936 * The firmware might enable the clock at
937 * boot (this information may or may not
938 * be reflected in the enable clock register).
939 * To change the rate we must disable the clock
940 * first to cover these cases. Due to common
941 * clock framework restrictions that do not allow
942 * to disable a clock that has not been enabled,
943 * we need to enable the clock first.
945 ret = clk_prepare_enable(priv->mclk);
947 clk_disable_unprepare(priv->mclk);
949 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ)
950 ret = clk_set_rate(priv->mclk, 25000000);
952 ret = clk_set_rate(priv->mclk, 19200000);
955 dev_err(card->dev, "unable to set MCLK rate\n");
960 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
961 ret = snd_soc_card_jack_new(card, "Headset",
962 SND_JACK_HEADSET | SND_JACK_BTN_0,
963 &priv->jack, rt5640_pins,
964 ARRAY_SIZE(rt5640_pins));
966 dev_err(card->dev, "Jack creation failed %d\n", ret);
969 snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0,
971 snd_soc_component_set_jack(component, &priv->jack, NULL);
977 static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd,
978 struct snd_pcm_hw_params *params)
980 struct snd_interval *rate = hw_param_interval(params,
981 SNDRV_PCM_HW_PARAM_RATE);
982 struct snd_interval *channels = hw_param_interval(params,
983 SNDRV_PCM_HW_PARAM_CHANNELS);
986 /* The DSP will covert the FE rate to 48k, stereo */
987 rate->min = rate->max = 48000;
988 channels->min = channels->max = 2;
990 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
991 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
992 /* set SSP0 to 16-bit */
993 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
996 /* set SSP2 to 24-bit */
997 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
1002 * Default mode for SSP configuration is TDM 4 slot, override config
1003 * with explicit setting to I2S 2ch. The word length is set with
1004 * dai_set_tdm_slot() since there is no other API exposed
1006 ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
1007 SND_SOC_DAIFMT_I2S |
1008 SND_SOC_DAIFMT_NB_NF |
1009 SND_SOC_DAIFMT_CBS_CFS);
1011 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
1015 ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, bits);
1017 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
1024 static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream)
1026 return snd_pcm_hw_constraint_single(substream->runtime,
1027 SNDRV_PCM_HW_PARAM_RATE, 48000);
1030 static const struct snd_soc_ops byt_rt5640_aif1_ops = {
1031 .startup = byt_rt5640_aif1_startup,
1034 static const struct snd_soc_ops byt_rt5640_be_ssp2_ops = {
1035 .hw_params = byt_rt5640_aif1_hw_params,
1038 SND_SOC_DAILINK_DEF(dummy,
1039 DAILINK_COMP_ARRAY(COMP_DUMMY()));
1041 SND_SOC_DAILINK_DEF(media,
1042 DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
1044 SND_SOC_DAILINK_DEF(deepbuffer,
1045 DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
1047 SND_SOC_DAILINK_DEF(ssp2_port,
1048 /* overwritten for ssp0 routing */
1049 DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));
1050 SND_SOC_DAILINK_DEF(ssp2_codec,
1051 DAILINK_COMP_ARRAY(COMP_CODEC(
1052 /* overwritten with HID */ "i2c-10EC5640:00",
1053 /* changed w/ quirk */ "rt5640-aif1")));
1055 SND_SOC_DAILINK_DEF(platform,
1056 DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
1058 static struct snd_soc_dai_link byt_rt5640_dais[] = {
1059 [MERR_DPCM_AUDIO] = {
1060 .name = "Baytrail Audio Port",
1061 .stream_name = "Baytrail Audio",
1066 .ops = &byt_rt5640_aif1_ops,
1067 SND_SOC_DAILINK_REG(media, dummy, platform),
1069 [MERR_DPCM_DEEP_BUFFER] = {
1070 .name = "Deep-Buffer Audio Port",
1071 .stream_name = "Deep-Buffer Audio",
1075 .ops = &byt_rt5640_aif1_ops,
1076 SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),
1080 .name = "SSP2-Codec",
1083 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
1084 | SND_SOC_DAIFMT_CBS_CFS,
1085 .be_hw_params_fixup = byt_rt5640_codec_fixup,
1089 .init = byt_rt5640_init,
1090 .ops = &byt_rt5640_be_ssp2_ops,
1091 SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform),
1096 static char byt_rt5640_codec_name[SND_ACPI_I2C_ID_LEN];
1097 #if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
1098 static char byt_rt5640_long_name[40]; /* = "bytcr-rt5640-*-spk-*-mic" */
1100 static char byt_rt5640_components[32]; /* = "cfg-spk:* cfg-mic:*" */
1102 static int byt_rt5640_suspend(struct snd_soc_card *card)
1104 struct snd_soc_component *component;
1106 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1109 for_each_card_components(card, component) {
1110 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1111 dev_dbg(component->dev, "disabling jack detect before suspend\n");
1112 snd_soc_component_set_jack(component, NULL, NULL);
1120 static int byt_rt5640_resume(struct snd_soc_card *card)
1122 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
1123 struct snd_soc_component *component;
1125 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1128 for_each_card_components(card, component) {
1129 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1130 dev_dbg(component->dev, "re-enabling jack detect after resume\n");
1131 snd_soc_component_set_jack(component, &priv->jack, NULL);
1139 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
1140 /* use space before codec name to simplify card ID, and simplify driver name */
1141 #define CARD_NAME "bytcht rt5640" /* card name will be 'sof-bytcht rt5640' */
1142 #define DRIVER_NAME "SOF"
1144 #define CARD_NAME "bytcr-rt5640"
1145 #define DRIVER_NAME NULL /* card name will be used for driver name */
1148 static struct snd_soc_card byt_rt5640_card = {
1150 .driver_name = DRIVER_NAME,
1151 .owner = THIS_MODULE,
1152 .dai_link = byt_rt5640_dais,
1153 .num_links = ARRAY_SIZE(byt_rt5640_dais),
1154 .dapm_widgets = byt_rt5640_widgets,
1155 .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
1156 .dapm_routes = byt_rt5640_audio_map,
1157 .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
1158 .fully_routed = true,
1159 .suspend_pre = byt_rt5640_suspend,
1160 .resume_post = byt_rt5640_resume,
1163 struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */
1164 u64 aif_value; /* 1: AIF1, 2: AIF2 */
1165 u64 mclock_value; /* usually 25MHz (0x17d7940), ignored */
1168 static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
1170 static const char * const map_name[] = { "dmic1", "dmic2", "in1", "in3" };
1171 const struct dmi_system_id *dmi_id;
1172 struct byt_rt5640_private *priv;
1173 struct snd_soc_acpi_mach *mach;
1174 const char *platform_name;
1175 struct acpi_device *adev;
1181 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
1185 /* register the soc card */
1186 byt_rt5640_card.dev = &pdev->dev;
1187 mach = byt_rt5640_card.dev->platform_data;
1188 snd_soc_card_set_drvdata(&byt_rt5640_card, priv);
1190 /* fix index of codec dai */
1191 for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) {
1192 if (!strcmp(byt_rt5640_dais[i].codecs->name,
1193 "i2c-10EC5640:00")) {
1199 /* fixup codec name based on HID */
1200 adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);
1202 snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name),
1203 "i2c-%s", acpi_dev_name(adev));
1204 put_device(&adev->dev);
1205 byt_rt5640_dais[dai_index].codecs->name = byt_rt5640_codec_name;
1209 * swap SSP0 if bytcr is detected
1210 * (will be overridden if DMI quirk is detected)
1212 if (soc_intel_is_byt()) {
1213 if (mach->mach_params.acpi_ipc_irq_index == 0)
1219 * Baytrail CR platforms may have CHAN package in BIOS, try
1220 * to find relevant routing quirk based as done on Windows
1221 * platforms. We have to read the information directly from the
1222 * BIOS, at this stage the card is not created and the links
1223 * with the codec driver/pdata are non-existent
1226 struct acpi_chan_package chan_package;
1228 /* format specified: 2 64-bit integers */
1229 struct acpi_buffer format = {sizeof("NN"), "NN"};
1230 struct acpi_buffer state = {0, NULL};
1231 struct snd_soc_acpi_package_context pkg_ctx;
1232 bool pkg_found = false;
1234 state.length = sizeof(chan_package);
1235 state.pointer = &chan_package;
1237 pkg_ctx.name = "CHAN";
1239 pkg_ctx.format = &format;
1240 pkg_ctx.state = &state;
1241 pkg_ctx.data_valid = false;
1243 pkg_found = snd_soc_acpi_find_package_from_hid(mach->id,
1246 if (chan_package.aif_value == 1) {
1247 dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n");
1248 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF1;
1249 } else if (chan_package.aif_value == 2) {
1250 dev_info(&pdev->dev, "BIOS Routing: AIF2 connected\n");
1251 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1253 dev_info(&pdev->dev, "BIOS Routing isn't valid, ignored\n");
1259 /* no BIOS indications, assume SSP0-AIF2 connection */
1260 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1263 /* change defaults for Baytrail-CR capture */
1264 byt_rt5640_quirk |= BYTCR_INPUT_DEFAULTS;
1266 byt_rt5640_quirk |= BYT_RT5640_DMIC1_MAP |
1267 BYT_RT5640_JD_SRC_JD2_IN4N |
1268 BYT_RT5640_OVCD_TH_2000UA |
1269 BYT_RT5640_OVCD_SF_0P75;
1272 /* check quirks before creating card */
1273 dmi_id = dmi_first_match(byt_rt5640_quirk_table);
1275 byt_rt5640_quirk = (unsigned long)dmi_id->driver_data;
1276 if (quirk_override != -1) {
1277 dev_info(&pdev->dev, "Overriding quirk 0x%lx => 0x%x\n",
1278 byt_rt5640_quirk, quirk_override);
1279 byt_rt5640_quirk = quirk_override;
1282 /* Must be called before register_card, also see declaration comment. */
1283 ret_val = byt_rt5640_add_codec_device_props(byt_rt5640_codec_name);
1287 log_quirks(&pdev->dev);
1289 if ((byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) ||
1290 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2))
1291 byt_rt5640_dais[dai_index].codecs->dai_name = "rt5640-aif2";
1293 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
1294 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2))
1295 byt_rt5640_dais[dai_index].cpus->dai_name = "ssp0-port";
1297 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
1298 priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
1299 if (IS_ERR(priv->mclk)) {
1300 ret_val = PTR_ERR(priv->mclk);
1303 "Failed to get MCLK from pmc_plt_clk_3: %d\n",
1307 * Fall back to bit clock usage for -ENOENT (clock not
1308 * available likely due to missing dependencies), bail
1309 * for all other errors, including -EPROBE_DEFER
1311 if (ret_val != -ENOENT)
1313 byt_rt5640_quirk &= ~BYT_RT5640_MCLK_EN;
1317 snprintf(byt_rt5640_components, sizeof(byt_rt5640_components),
1318 "cfg-spk:%s cfg-mic:%s",
1319 (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) ? "1" : "2",
1320 map_name[BYT_RT5640_MAP(byt_rt5640_quirk)]);
1321 byt_rt5640_card.components = byt_rt5640_components;
1322 #if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
1323 snprintf(byt_rt5640_long_name, sizeof(byt_rt5640_long_name),
1324 "bytcr-rt5640-%s-spk-%s-mic",
1325 (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) ?
1327 map_name[BYT_RT5640_MAP(byt_rt5640_quirk)]);
1328 byt_rt5640_card.long_name = byt_rt5640_long_name;
1331 /* override plaform name, if required */
1332 platform_name = mach->mach_params.platform;
1334 ret_val = snd_soc_fixup_dai_links_platform_name(&byt_rt5640_card,
1339 ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card);
1342 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
1346 platform_set_drvdata(pdev, &byt_rt5640_card);
1350 static struct platform_driver snd_byt_rt5640_mc_driver = {
1352 .name = "bytcr_rt5640",
1353 #if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
1354 .pm = &snd_soc_pm_ops,
1357 .probe = snd_byt_rt5640_mc_probe,
1360 module_platform_driver(snd_byt_rt5640_mc_driver);
1362 MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
1363 MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
1364 MODULE_LICENSE("GPL v2");
1365 MODULE_ALIAS("platform:bytcr_rt5640");