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"
38 BYT_RT5640_NO_INTERNAL_MIC_MAP,
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),
51 BYT_RT5640_OVCD_TH_600UA = (6 << 8),
52 BYT_RT5640_OVCD_TH_1500UA = (15 << 8),
53 BYT_RT5640_OVCD_TH_2000UA = (20 << 8),
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),
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)
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 | \
84 /* in-diff or dmic-pin + jdsrc + ovcd-th + -sf + jd-inv + terminating entry */
85 #define MAX_NO_PROPS 6
87 struct byt_rt5640_private {
88 struct snd_soc_jack jack;
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");
98 static void log_quirks(struct device *dev)
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;
107 map = BYT_RT5640_MAP(byt_rt5640_quirk);
109 case BYT_RT5640_DMIC1_MAP:
110 dev_info(dev, "quirk DMIC1_MAP enabled\n");
112 case BYT_RT5640_DMIC2_MAP:
113 dev_info(dev, "quirk DMIC2_MAP enabled\n");
115 case BYT_RT5640_IN1_MAP:
116 dev_info(dev, "quirk IN1_MAP enabled\n");
118 case BYT_RT5640_IN3_MAP:
119 dev_info(dev, "quirk IN3_MAP enabled\n");
121 case BYT_RT5640_NO_INTERNAL_MIC_MAP:
122 dev_info(dev, "quirk NO_INTERNAL_MIC_MAP enabled\n");
125 dev_err(dev, "quirk map 0x%x is not supported, microphone input will not work\n", map);
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));
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");
147 has_ssp0_aif1 = true;
149 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
150 dev_info(dev, "quirk SSP0_AIF2 enabled\n");
152 has_ssp0_aif2 = true;
154 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
155 dev_info(dev, "quirk SSP2_AIF2 enabled\n");
156 has_ssp2_aif2 = true;
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");
165 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
166 dev_info(dev, "quirk MCLK_EN enabled\n");
169 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
171 dev_info(dev, "quirk MCLK_25MHZ enabled\n");
173 dev_err(dev, "quirk MCLK_25MHZ enabled but quirk MCLK not selected, will be ignored\n");
177 static int byt_rt5640_prepare_and_enable_pll1(struct snd_soc_dai *codec_dai,
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,
190 rate * 32, rate * 512);
192 /* 2x15 bit slots on SSP2 */
193 ret = snd_soc_dai_set_pll(codec_dai, 0,
195 rate * 50, rate * 512);
198 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
199 ret = snd_soc_dai_set_pll(codec_dai, 0,
201 25000000, rate * 512);
203 ret = snd_soc_dai_set_pll(codec_dai, 0,
205 19200000, rate * 512);
210 dev_err(codec_dai->component->dev, "can't set pll: %d\n", ret);
214 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
215 rate * 512, SND_SOC_CLOCK_IN);
217 dev_err(codec_dai->component->dev, "can't set clock %d\n", ret);
224 #define BYT_CODEC_DAI1 "rt5640-aif1"
225 #define BYT_CODEC_DAI2 "rt5640-aif2"
227 static int platform_clock_control(struct snd_soc_dapm_widget *w,
228 struct snd_kcontrol *k, int event)
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);
236 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI1);
238 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI2);
242 "Codec dai not found; Unable to set platform clock\n");
246 if (SND_SOC_DAPM_EVENT_ON(event)) {
247 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
248 ret = clk_prepare_enable(priv->mclk);
251 "could not configure MCLK state\n");
255 ret = byt_rt5640_prepare_and_enable_pll1(codec_dai, 48000);
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
262 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_RCCLK,
266 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
267 clk_disable_unprepare(priv->mclk);
272 dev_err(card->dev, "can't set codec sysclk: %d\n", ret);
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),
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"},
296 {"Headset Mic", NULL, "MICBIAS1"},
297 {"IN2P", NULL, "Headset Mic"},
298 {"Headphone", NULL, "HPOL"},
299 {"Headphone", NULL, "HPOR"},
302 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
303 {"DMIC1", NULL, "Internal Mic"},
306 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
307 {"DMIC2", NULL, "Internal Mic"},
310 static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
311 {"Internal Mic", NULL, "MICBIAS1"},
312 {"IN1P", NULL, "Internal Mic"},
315 static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map[] = {
316 {"Internal Mic", NULL, "MICBIAS1"},
317 {"IN3P", NULL, "Internal Mic"},
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"},
326 {"AIF1 Playback", NULL, "ssp2 Tx"},
327 {"ssp2 Rx", NULL, "AIF1 Capture"},
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"},
336 {"AIF2 Playback", NULL, "ssp2 Tx"},
337 {"ssp2 Rx", NULL, "AIF2 Capture"},
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"},
344 {"AIF1 Playback", NULL, "ssp0 Tx"},
345 {"ssp0 Rx", NULL, "AIF1 Capture"},
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"},
352 {"AIF2 Playback", NULL, "ssp0 Tx"},
353 {"ssp0 Rx", NULL, "AIF2 Capture"},
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"},
363 static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = {
364 {"Speaker", NULL, "SPOLP"},
365 {"Speaker", NULL, "SPOLN"},
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"),
375 static struct snd_soc_jack_pin rt5640_pins[] = {
378 .mask = SND_JACK_HEADPHONE,
381 .pin = "Headset Mic",
382 .mask = SND_JACK_MICROPHONE,
386 static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream,
387 struct snd_pcm_hw_params *params)
389 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
390 struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
392 return byt_rt5640_prepare_and_enable_pll1(dai, params_rate(params));
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 */
399 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"),
400 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Iconia W1-810"),
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 |
409 { /* Acer One 10 S1002 */
411 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
412 DMI_MATCH(DMI_PRODUCT_NAME, "One S1002"),
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 |
424 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
425 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
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 |
436 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
437 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 80 Cesium"),
439 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
440 BYT_RT5640_MONO_SPEAKER |
441 BYT_RT5640_SSP0_AIF1 |
446 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
447 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 140 CESIUM"),
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 |
458 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
459 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ME176C"),
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 |
470 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
471 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
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 |
481 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
482 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"),
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 |
493 { /* Chuwi Vi8 (CWI506) */
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"),
500 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
501 BYT_RT5640_MONO_SPEAKER |
502 BYT_RT5640_SSP0_AIF1 |
506 /* Chuwi Vi10 (CWI505) */
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"),
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 |
522 /* Chuwi Hi8 (CWI509) */
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"),
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 |
540 DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
541 DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"),
543 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP),
545 { /* Connect Tablet 9 */
547 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Connect"),
548 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Tablet 9"),
550 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
551 BYT_RT5640_MONO_SPEAKER |
552 BYT_RT5640_SSP0_AIF1 |
557 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
558 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
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 |
567 { /* Estar Beauty HD MID 7316R */
569 DMI_MATCH(DMI_SYS_VENDOR, "Estar"),
570 DMI_MATCH(DMI_PRODUCT_NAME, "eSTAR BEAUTY HD Intel Quad core"),
572 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
573 BYT_RT5640_MONO_SPEAKER |
574 BYT_RT5640_SSP0_AIF1 |
577 { /* Glavey TM800A550L */
579 DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
580 DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
581 /* Above strings are too generic, also match on BIOS version */
582 DMI_MATCH(DMI_BIOS_VERSION, "ZY-8-BI-PX4S70VTR400-X423B-005-D"),
584 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
585 BYT_RT5640_SSP0_AIF1 |
590 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
591 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"),
593 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
596 { /* HP Pavilion x2 10-k0XX, 10-n0XX */
598 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
599 DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion x2 Detachable"),
601 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
602 BYT_RT5640_JD_SRC_JD2_IN4N |
603 BYT_RT5640_OVCD_TH_1500UA |
604 BYT_RT5640_OVCD_SF_0P75 |
605 BYT_RT5640_SSP0_AIF1 |
608 { /* HP Pavilion x2 10-p0XX */
610 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
611 DMI_MATCH(DMI_PRODUCT_NAME, "HP x2 Detachable 10-p0XX"),
613 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
614 BYT_RT5640_JD_SRC_JD1_IN4P |
615 BYT_RT5640_OVCD_TH_2000UA |
616 BYT_RT5640_OVCD_SF_0P75 |
621 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
622 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP Stream 7 Tablet"),
624 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
625 BYT_RT5640_MONO_SPEAKER |
626 BYT_RT5640_JD_NOT_INV |
627 BYT_RT5640_SSP0_AIF1 |
630 { /* I.T.Works TW891 */
632 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "To be filled by O.E.M."),
633 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TW891"),
634 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "To be filled by O.E.M."),
635 DMI_EXACT_MATCH(DMI_BOARD_NAME, "TW891"),
637 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
638 BYT_RT5640_MONO_SPEAKER |
639 BYT_RT5640_SSP0_AIF1 |
642 { /* Lamina I8270 / T701BR.SE */
644 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Lamina"),
645 DMI_EXACT_MATCH(DMI_BOARD_NAME, "T701BR.SE"),
647 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
648 BYT_RT5640_MONO_SPEAKER |
649 BYT_RT5640_JD_NOT_INV |
650 BYT_RT5640_SSP0_AIF1 |
653 { /* Lenovo Miix 2 8 */
655 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
656 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "20326"),
657 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Hiking"),
659 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
660 BYT_RT5640_JD_SRC_JD2_IN4N |
661 BYT_RT5640_OVCD_TH_2000UA |
662 BYT_RT5640_OVCD_SF_0P75 |
663 BYT_RT5640_MONO_SPEAKER |
666 { /* Lenovo Miix 3-830 */
668 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
669 DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 3-830"),
671 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
672 BYT_RT5640_JD_SRC_JD2_IN4N |
673 BYT_RT5640_OVCD_TH_2000UA |
674 BYT_RT5640_OVCD_SF_0P75 |
675 BYT_RT5640_MONO_SPEAKER |
676 BYT_RT5640_DIFF_MIC |
677 BYT_RT5640_SSP0_AIF1 |
680 { /* Linx Linx7 tablet */
682 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LINX"),
683 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "LINX7"),
685 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
686 BYT_RT5640_MONO_SPEAKER |
687 BYT_RT5640_JD_NOT_INV |
688 BYT_RT5640_SSP0_AIF1 |
691 { /* Mele PCG03 Mini PC */
693 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Mini PC"),
694 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Mini PC"),
696 .driver_data = (void *)(BYT_RT5640_NO_INTERNAL_MIC_MAP |
697 BYT_RT5640_NO_SPEAKERS |
698 BYT_RT5640_SSP0_AIF1),
700 { /* MPMAN Converter 9, similar hw as the I.T.Works TW891 2-in-1 */
702 DMI_MATCH(DMI_SYS_VENDOR, "MPMAN"),
703 DMI_MATCH(DMI_PRODUCT_NAME, "Converter9"),
705 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
706 BYT_RT5640_MONO_SPEAKER |
707 BYT_RT5640_SSP0_AIF1 |
711 /* MPMAN MPWIN895CL */
713 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "MPMAN"),
714 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MPWIN8900CL"),
716 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
717 BYT_RT5640_MONO_SPEAKER |
718 BYT_RT5640_SSP0_AIF1 |
721 { /* MSI S100 tablet */
723 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Micro-Star International Co., Ltd."),
724 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "S100"),
726 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
727 BYT_RT5640_JD_SRC_JD2_IN4N |
728 BYT_RT5640_OVCD_TH_2000UA |
729 BYT_RT5640_OVCD_SF_0P75 |
730 BYT_RT5640_MONO_SPEAKER |
731 BYT_RT5640_DIFF_MIC |
734 { /* Nuvison/TMax TM800W560 */
736 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TMAX"),
737 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TM800W560L"),
739 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
740 BYT_RT5640_JD_SRC_JD2_IN4N |
741 BYT_RT5640_OVCD_TH_2000UA |
742 BYT_RT5640_OVCD_SF_0P75 |
743 BYT_RT5640_JD_NOT_INV |
744 BYT_RT5640_DIFF_MIC |
745 BYT_RT5640_SSP0_AIF1 |
750 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
751 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
752 /* The above are too generic, also match BIOS info */
753 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "5.6.5"),
754 DMI_EXACT_MATCH(DMI_BIOS_DATE, "07/25/2014"),
756 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
757 BYT_RT5640_JD_SRC_JD2_IN4N |
758 BYT_RT5640_OVCD_TH_2000UA |
759 BYT_RT5640_OVCD_SF_0P75 |
760 BYT_RT5640_DIFF_MIC |
765 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
766 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
767 /* The above are too generic, also match BIOS info */
768 DMI_MATCH(DMI_BIOS_VERSION, "V8L_WIN32_CHIPHD"),
770 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
771 BYT_RT5640_MONO_SPEAKER |
772 BYT_RT5640_SSP0_AIF1 |
775 { /* Point of View Mobii TAB-P800W (V2.0) */
777 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
778 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
779 /* The above are too generic, also match BIOS info */
780 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1014"),
781 DMI_EXACT_MATCH(DMI_BIOS_DATE, "10/24/2014"),
783 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
784 BYT_RT5640_JD_SRC_JD2_IN4N |
785 BYT_RT5640_OVCD_TH_2000UA |
786 BYT_RT5640_OVCD_SF_0P75 |
787 BYT_RT5640_MONO_SPEAKER |
788 BYT_RT5640_DIFF_MIC |
789 BYT_RT5640_SSP0_AIF2 |
792 { /* Point of View Mobii TAB-P800W (V2.1) */
794 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
795 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
796 /* The above are too generic, also match BIOS info */
797 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1013"),
798 DMI_EXACT_MATCH(DMI_BIOS_DATE, "08/22/2014"),
800 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
801 BYT_RT5640_JD_SRC_JD2_IN4N |
802 BYT_RT5640_OVCD_TH_2000UA |
803 BYT_RT5640_OVCD_SF_0P75 |
804 BYT_RT5640_MONO_SPEAKER |
805 BYT_RT5640_DIFF_MIC |
806 BYT_RT5640_SSP0_AIF2 |
809 { /* Point of View Mobii TAB-P1005W-232 (V2.0) */
811 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "POV"),
812 DMI_EXACT_MATCH(DMI_BOARD_NAME, "I102A"),
814 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
815 BYT_RT5640_JD_SRC_JD2_IN4N |
816 BYT_RT5640_OVCD_TH_2000UA |
817 BYT_RT5640_OVCD_SF_0P75 |
818 BYT_RT5640_DIFF_MIC |
819 BYT_RT5640_SSP0_AIF1 |
825 DMI_MATCH(DMI_SYS_VENDOR, "Prowise"),
826 DMI_MATCH(DMI_PRODUCT_NAME, "PT301"),
828 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
829 BYT_RT5640_JD_SRC_JD2_IN4N |
830 BYT_RT5640_OVCD_TH_2000UA |
831 BYT_RT5640_OVCD_SF_0P75 |
832 BYT_RT5640_DIFF_MIC |
833 BYT_RT5640_SSP0_AIF1 |
839 DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"),
840 DMI_MATCH(DMI_BOARD_NAME, "tPAD"),
842 .driver_data = (void *)(BYT_RT5640_IN3_MAP |
843 BYT_RT5640_JD_SRC_JD1_IN4P |
844 BYT_RT5640_OVCD_TH_2000UA |
845 BYT_RT5640_OVCD_SF_1P0 |
846 BYT_RT5640_SSP0_AIF1 |
849 { /* Toshiba Satellite Click Mini L9W-B */
851 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
852 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "SATELLITE Click Mini L9W-B"),
854 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
855 BYT_RT5640_JD_SRC_JD2_IN4N |
856 BYT_RT5640_OVCD_TH_1500UA |
857 BYT_RT5640_OVCD_SF_0P75 |
858 BYT_RT5640_SSP0_AIF1 |
861 { /* Toshiba Encore WT8-A */
863 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
864 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT8-A"),
866 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
867 BYT_RT5640_JD_SRC_JD2_IN4N |
868 BYT_RT5640_OVCD_TH_2000UA |
869 BYT_RT5640_OVCD_SF_0P75 |
870 BYT_RT5640_JD_NOT_INV |
873 { /* Toshiba Encore WT10-A */
875 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
876 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT10-A-103"),
878 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
879 BYT_RT5640_JD_SRC_JD1_IN4P |
880 BYT_RT5640_OVCD_TH_2000UA |
881 BYT_RT5640_OVCD_SF_0P75 |
882 BYT_RT5640_SSP0_AIF2 |
885 { /* Voyo Winpad A15 */
887 DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
888 DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
889 /* Above strings are too generic, also match on BIOS date */
890 DMI_MATCH(DMI_BIOS_DATE, "11/20/2014"),
892 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
893 BYT_RT5640_JD_SRC_JD2_IN4N |
894 BYT_RT5640_OVCD_TH_2000UA |
895 BYT_RT5640_OVCD_SF_0P75 |
896 BYT_RT5640_DIFF_MIC |
899 { /* Catch-all for generic Insyde tablets, must be last */
901 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
903 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
905 BYT_RT5640_SSP0_AIF1),
912 * Note this MUST be called before snd_soc_register_card(), so that the props
913 * are in place before the codec component driver's probe function parses them.
915 static int byt_rt5640_add_codec_device_props(const char *i2c_dev_name)
917 struct property_entry props[MAX_NO_PROPS] = {};
918 struct device *i2c_dev;
921 i2c_dev = bus_find_device_by_name(&i2c_bus_type, NULL, i2c_dev_name);
923 return -EPROBE_DEFER;
925 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
926 case BYT_RT5640_DMIC1_MAP:
927 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic1-data-pin",
928 RT5640_DMIC1_DATA_PIN_IN1P);
930 case BYT_RT5640_DMIC2_MAP:
931 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic2-data-pin",
932 RT5640_DMIC2_DATA_PIN_IN1N);
934 case BYT_RT5640_IN1_MAP:
935 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
937 PROPERTY_ENTRY_BOOL("realtek,in1-differential");
939 case BYT_RT5640_IN3_MAP:
940 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
942 PROPERTY_ENTRY_BOOL("realtek,in3-differential");
946 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
947 props[cnt++] = PROPERTY_ENTRY_U32(
948 "realtek,jack-detect-source",
949 BYT_RT5640_JDSRC(byt_rt5640_quirk));
951 props[cnt++] = PROPERTY_ENTRY_U32(
952 "realtek,over-current-threshold-microamp",
953 BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
955 props[cnt++] = PROPERTY_ENTRY_U32(
956 "realtek,over-current-scale-factor",
957 BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
960 if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
961 props[cnt++] = PROPERTY_ENTRY_BOOL("realtek,jack-detect-not-inverted");
963 ret = device_add_properties(i2c_dev, props);
969 static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
971 struct snd_soc_card *card = runtime->card;
972 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
973 struct snd_soc_component *component = asoc_rtd_to_codec(runtime, 0)->component;
974 const struct snd_soc_dapm_route *custom_map = NULL;
978 card->dapm.idle_bias_off = true;
980 /* Start with RC clk for jack-detect (we disable MCLK below) */
981 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
982 snd_soc_component_update_bits(component, RT5640_GLB_CLK,
983 RT5640_SCLK_SRC_MASK, RT5640_SCLK_SRC_RCCLK);
985 rt5640_sel_asrc_clk_src(component,
986 RT5640_DA_STEREO_FILTER |
987 RT5640_DA_MONO_L_FILTER |
988 RT5640_DA_MONO_R_FILTER |
989 RT5640_AD_STEREO_FILTER |
990 RT5640_AD_MONO_L_FILTER |
991 RT5640_AD_MONO_R_FILTER,
992 RT5640_CLK_SEL_ASRC);
994 ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
995 ARRAY_SIZE(byt_rt5640_controls));
997 dev_err(card->dev, "unable to add card controls\n");
1001 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
1002 case BYT_RT5640_IN1_MAP:
1003 custom_map = byt_rt5640_intmic_in1_map;
1004 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
1006 case BYT_RT5640_IN3_MAP:
1007 custom_map = byt_rt5640_intmic_in3_map;
1008 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in3_map);
1010 case BYT_RT5640_DMIC1_MAP:
1011 custom_map = byt_rt5640_intmic_dmic1_map;
1012 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
1014 case BYT_RT5640_DMIC2_MAP:
1015 custom_map = byt_rt5640_intmic_dmic2_map;
1016 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
1020 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
1024 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
1025 ret = snd_soc_dapm_add_routes(&card->dapm,
1026 byt_rt5640_ssp2_aif2_map,
1027 ARRAY_SIZE(byt_rt5640_ssp2_aif2_map));
1028 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
1029 ret = snd_soc_dapm_add_routes(&card->dapm,
1030 byt_rt5640_ssp0_aif1_map,
1031 ARRAY_SIZE(byt_rt5640_ssp0_aif1_map));
1032 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
1033 ret = snd_soc_dapm_add_routes(&card->dapm,
1034 byt_rt5640_ssp0_aif2_map,
1035 ARRAY_SIZE(byt_rt5640_ssp0_aif2_map));
1037 ret = snd_soc_dapm_add_routes(&card->dapm,
1038 byt_rt5640_ssp2_aif1_map,
1039 ARRAY_SIZE(byt_rt5640_ssp2_aif1_map));
1044 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
1045 ret = snd_soc_dapm_add_routes(&card->dapm,
1046 byt_rt5640_mono_spk_map,
1047 ARRAY_SIZE(byt_rt5640_mono_spk_map));
1048 } else if (!(byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS)) {
1049 ret = snd_soc_dapm_add_routes(&card->dapm,
1050 byt_rt5640_stereo_spk_map,
1051 ARRAY_SIZE(byt_rt5640_stereo_spk_map));
1056 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
1058 * The firmware might enable the clock at
1059 * boot (this information may or may not
1060 * be reflected in the enable clock register).
1061 * To change the rate we must disable the clock
1062 * first to cover these cases. Due to common
1063 * clock framework restrictions that do not allow
1064 * to disable a clock that has not been enabled,
1065 * we need to enable the clock first.
1067 ret = clk_prepare_enable(priv->mclk);
1069 clk_disable_unprepare(priv->mclk);
1071 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ)
1072 ret = clk_set_rate(priv->mclk, 25000000);
1074 ret = clk_set_rate(priv->mclk, 19200000);
1077 dev_err(card->dev, "unable to set MCLK rate\n");
1082 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
1083 ret = snd_soc_card_jack_new(card, "Headset",
1084 SND_JACK_HEADSET | SND_JACK_BTN_0,
1085 &priv->jack, rt5640_pins,
1086 ARRAY_SIZE(rt5640_pins));
1088 dev_err(card->dev, "Jack creation failed %d\n", ret);
1091 snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0,
1093 snd_soc_component_set_jack(component, &priv->jack, NULL);
1099 static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd,
1100 struct snd_pcm_hw_params *params)
1102 struct snd_interval *rate = hw_param_interval(params,
1103 SNDRV_PCM_HW_PARAM_RATE);
1104 struct snd_interval *channels = hw_param_interval(params,
1105 SNDRV_PCM_HW_PARAM_CHANNELS);
1108 /* The DSP will covert the FE rate to 48k, stereo */
1109 rate->min = rate->max = 48000;
1110 channels->min = channels->max = 2;
1112 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
1113 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
1114 /* set SSP0 to 16-bit */
1115 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
1118 /* set SSP2 to 24-bit */
1119 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
1124 * Default mode for SSP configuration is TDM 4 slot, override config
1125 * with explicit setting to I2S 2ch. The word length is set with
1126 * dai_set_tdm_slot() since there is no other API exposed
1128 ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
1129 SND_SOC_DAIFMT_I2S |
1130 SND_SOC_DAIFMT_NB_NF |
1131 SND_SOC_DAIFMT_CBS_CFS);
1133 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
1137 ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, bits);
1139 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
1146 static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream)
1148 return snd_pcm_hw_constraint_single(substream->runtime,
1149 SNDRV_PCM_HW_PARAM_RATE, 48000);
1152 static const struct snd_soc_ops byt_rt5640_aif1_ops = {
1153 .startup = byt_rt5640_aif1_startup,
1156 static const struct snd_soc_ops byt_rt5640_be_ssp2_ops = {
1157 .hw_params = byt_rt5640_aif1_hw_params,
1160 SND_SOC_DAILINK_DEF(dummy,
1161 DAILINK_COMP_ARRAY(COMP_DUMMY()));
1163 SND_SOC_DAILINK_DEF(media,
1164 DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
1166 SND_SOC_DAILINK_DEF(deepbuffer,
1167 DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
1169 SND_SOC_DAILINK_DEF(ssp2_port,
1170 /* overwritten for ssp0 routing */
1171 DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));
1172 SND_SOC_DAILINK_DEF(ssp2_codec,
1173 DAILINK_COMP_ARRAY(COMP_CODEC(
1174 /* overwritten with HID */ "i2c-10EC5640:00",
1175 /* changed w/ quirk */ "rt5640-aif1")));
1177 SND_SOC_DAILINK_DEF(platform,
1178 DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
1180 static struct snd_soc_dai_link byt_rt5640_dais[] = {
1181 [MERR_DPCM_AUDIO] = {
1182 .name = "Baytrail Audio Port",
1183 .stream_name = "Baytrail Audio",
1188 .ops = &byt_rt5640_aif1_ops,
1189 SND_SOC_DAILINK_REG(media, dummy, platform),
1191 [MERR_DPCM_DEEP_BUFFER] = {
1192 .name = "Deep-Buffer Audio Port",
1193 .stream_name = "Deep-Buffer Audio",
1197 .ops = &byt_rt5640_aif1_ops,
1198 SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),
1202 .name = "SSP2-Codec",
1205 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
1206 | SND_SOC_DAIFMT_CBS_CFS,
1207 .be_hw_params_fixup = byt_rt5640_codec_fixup,
1210 .init = byt_rt5640_init,
1211 .ops = &byt_rt5640_be_ssp2_ops,
1212 SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform),
1217 static char byt_rt5640_codec_name[SND_ACPI_I2C_ID_LEN];
1218 #if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
1219 static char byt_rt5640_long_name[40]; /* = "bytcr-rt5640-*-spk-*-mic" */
1221 static char byt_rt5640_components[32]; /* = "cfg-spk:* cfg-mic:*" */
1223 static int byt_rt5640_suspend(struct snd_soc_card *card)
1225 struct snd_soc_component *component;
1227 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1230 for_each_card_components(card, component) {
1231 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1232 dev_dbg(component->dev, "disabling jack detect before suspend\n");
1233 snd_soc_component_set_jack(component, NULL, NULL);
1241 static int byt_rt5640_resume(struct snd_soc_card *card)
1243 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
1244 struct snd_soc_component *component;
1246 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1249 for_each_card_components(card, component) {
1250 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1251 dev_dbg(component->dev, "re-enabling jack detect after resume\n");
1252 snd_soc_component_set_jack(component, &priv->jack, NULL);
1260 /* use space before codec name to simplify card ID, and simplify driver name */
1261 #define SOF_CARD_NAME "bytcht rt5640" /* card name will be 'sof-bytcht rt5640' */
1262 #define SOF_DRIVER_NAME "SOF"
1264 #define CARD_NAME "bytcr-rt5640"
1265 #define DRIVER_NAME NULL /* card name will be used for driver name */
1267 static struct snd_soc_card byt_rt5640_card = {
1268 .owner = THIS_MODULE,
1269 .dai_link = byt_rt5640_dais,
1270 .num_links = ARRAY_SIZE(byt_rt5640_dais),
1271 .dapm_widgets = byt_rt5640_widgets,
1272 .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
1273 .dapm_routes = byt_rt5640_audio_map,
1274 .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
1275 .fully_routed = true,
1276 .suspend_pre = byt_rt5640_suspend,
1277 .resume_post = byt_rt5640_resume,
1280 struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */
1281 u64 aif_value; /* 1: AIF1, 2: AIF2 */
1282 u64 mclock_value; /* usually 25MHz (0x17d7940), ignored */
1285 static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
1287 struct device *dev = &pdev->dev;
1288 static const char * const map_name[] = { "dmic1", "dmic2", "in1", "in3", "none" };
1289 __maybe_unused const char *spk_type;
1290 const struct dmi_system_id *dmi_id;
1291 struct byt_rt5640_private *priv;
1292 struct snd_soc_acpi_mach *mach;
1293 const char *platform_name;
1294 struct acpi_device *adev;
1302 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
1306 /* register the soc card */
1307 byt_rt5640_card.dev = &pdev->dev;
1308 mach = byt_rt5640_card.dev->platform_data;
1309 snd_soc_card_set_drvdata(&byt_rt5640_card, priv);
1311 /* fix index of codec dai */
1312 for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) {
1313 if (!strcmp(byt_rt5640_dais[i].codecs->name,
1314 "i2c-10EC5640:00")) {
1320 /* fixup codec name based on HID */
1321 adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);
1323 snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name),
1324 "i2c-%s", acpi_dev_name(adev));
1325 put_device(&adev->dev);
1326 byt_rt5640_dais[dai_index].codecs->name = byt_rt5640_codec_name;
1330 * swap SSP0 if bytcr is detected
1331 * (will be overridden if DMI quirk is detected)
1333 if (soc_intel_is_byt()) {
1334 if (mach->mach_params.acpi_ipc_irq_index == 0)
1340 * Baytrail CR platforms may have CHAN package in BIOS, try
1341 * to find relevant routing quirk based as done on Windows
1342 * platforms. We have to read the information directly from the
1343 * BIOS, at this stage the card is not created and the links
1344 * with the codec driver/pdata are non-existent
1347 struct acpi_chan_package chan_package;
1349 /* format specified: 2 64-bit integers */
1350 struct acpi_buffer format = {sizeof("NN"), "NN"};
1351 struct acpi_buffer state = {0, NULL};
1352 struct snd_soc_acpi_package_context pkg_ctx;
1353 bool pkg_found = false;
1355 state.length = sizeof(chan_package);
1356 state.pointer = &chan_package;
1358 pkg_ctx.name = "CHAN";
1360 pkg_ctx.format = &format;
1361 pkg_ctx.state = &state;
1362 pkg_ctx.data_valid = false;
1364 pkg_found = snd_soc_acpi_find_package_from_hid(mach->id,
1367 if (chan_package.aif_value == 1) {
1368 dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n");
1369 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF1;
1370 } else if (chan_package.aif_value == 2) {
1371 dev_info(&pdev->dev, "BIOS Routing: AIF2 connected\n");
1372 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1374 dev_info(&pdev->dev, "BIOS Routing isn't valid, ignored\n");
1380 /* no BIOS indications, assume SSP0-AIF2 connection */
1381 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1384 /* change defaults for Baytrail-CR capture */
1385 byt_rt5640_quirk |= BYTCR_INPUT_DEFAULTS;
1387 byt_rt5640_quirk |= BYT_RT5640_DMIC1_MAP |
1388 BYT_RT5640_JD_SRC_JD2_IN4N |
1389 BYT_RT5640_OVCD_TH_2000UA |
1390 BYT_RT5640_OVCD_SF_0P75;
1393 /* check quirks before creating card */
1394 dmi_id = dmi_first_match(byt_rt5640_quirk_table);
1396 byt_rt5640_quirk = (unsigned long)dmi_id->driver_data;
1397 if (quirk_override != -1) {
1398 dev_info(&pdev->dev, "Overriding quirk 0x%lx => 0x%x\n",
1399 byt_rt5640_quirk, quirk_override);
1400 byt_rt5640_quirk = quirk_override;
1403 /* Must be called before register_card, also see declaration comment. */
1404 ret_val = byt_rt5640_add_codec_device_props(byt_rt5640_codec_name);
1408 log_quirks(&pdev->dev);
1410 if ((byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) ||
1411 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
1412 byt_rt5640_dais[dai_index].codecs->dai_name = "rt5640-aif2";
1418 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
1419 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2))
1420 byt_rt5640_dais[dai_index].cpus->dai_name = "ssp0-port";
1422 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
1423 priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
1424 if (IS_ERR(priv->mclk)) {
1425 ret_val = PTR_ERR(priv->mclk);
1428 "Failed to get MCLK from pmc_plt_clk_3: %d\n",
1432 * Fall back to bit clock usage for -ENOENT (clock not
1433 * available likely due to missing dependencies), bail
1434 * for all other errors, including -EPROBE_DEFER
1436 if (ret_val != -ENOENT)
1438 byt_rt5640_quirk &= ~BYT_RT5640_MCLK_EN;
1442 if (byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS) {
1445 } else if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
1450 spk_type = "stereo";
1453 snprintf(byt_rt5640_components, sizeof(byt_rt5640_components),
1454 "cfg-spk:%d cfg-mic:%s aif:%d", cfg_spk,
1455 map_name[BYT_RT5640_MAP(byt_rt5640_quirk)], aif);
1456 byt_rt5640_card.components = byt_rt5640_components;
1457 #if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
1458 snprintf(byt_rt5640_long_name, sizeof(byt_rt5640_long_name),
1459 "bytcr-rt5640-%s-spk-%s-mic", spk_type,
1460 map_name[BYT_RT5640_MAP(byt_rt5640_quirk)]);
1461 byt_rt5640_card.long_name = byt_rt5640_long_name;
1464 /* override plaform name, if required */
1465 platform_name = mach->mach_params.platform;
1467 ret_val = snd_soc_fixup_dai_links_platform_name(&byt_rt5640_card,
1472 sof_parent = snd_soc_acpi_sof_parent(&pdev->dev);
1474 /* set card and driver name */
1476 byt_rt5640_card.name = SOF_CARD_NAME;
1477 byt_rt5640_card.driver_name = SOF_DRIVER_NAME;
1479 byt_rt5640_card.name = CARD_NAME;
1480 byt_rt5640_card.driver_name = DRIVER_NAME;
1485 dev->driver->pm = &snd_soc_pm_ops;
1487 ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card);
1490 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
1494 platform_set_drvdata(pdev, &byt_rt5640_card);
1498 static struct platform_driver snd_byt_rt5640_mc_driver = {
1500 .name = "bytcr_rt5640",
1502 .probe = snd_byt_rt5640_mc_probe,
1505 module_platform_driver(snd_byt_rt5640_mc_driver);
1507 MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
1508 MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
1509 MODULE_LICENSE("GPL v2");
1510 MODULE_ALIAS("platform:bytcr_rt5640");