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)
76 #define BYT_RT5640_LINEOUT BIT(25)
78 #define BYTCR_INPUT_DEFAULTS \
79 (BYT_RT5640_IN3_MAP | \
80 BYT_RT5640_JD_SRC_JD1_IN4P | \
81 BYT_RT5640_OVCD_TH_2000UA | \
82 BYT_RT5640_OVCD_SF_0P75 | \
85 /* in-diff or dmic-pin + jdsrc + ovcd-th + -sf + jd-inv + terminating entry */
86 #define MAX_NO_PROPS 6
88 struct byt_rt5640_private {
89 struct snd_soc_jack jack;
94 static unsigned long byt_rt5640_quirk = BYT_RT5640_MCLK_EN;
95 static int quirk_override = -1;
96 module_param_named(quirk, quirk_override, int, 0444);
97 MODULE_PARM_DESC(quirk, "Board-specific quirk override");
99 static void log_quirks(struct device *dev)
102 bool has_mclk = false;
103 bool has_ssp0 = false;
104 bool has_ssp0_aif1 = false;
105 bool has_ssp0_aif2 = false;
106 bool has_ssp2_aif2 = false;
108 map = BYT_RT5640_MAP(byt_rt5640_quirk);
110 case BYT_RT5640_DMIC1_MAP:
111 dev_info(dev, "quirk DMIC1_MAP enabled\n");
113 case BYT_RT5640_DMIC2_MAP:
114 dev_info(dev, "quirk DMIC2_MAP enabled\n");
116 case BYT_RT5640_IN1_MAP:
117 dev_info(dev, "quirk IN1_MAP enabled\n");
119 case BYT_RT5640_IN3_MAP:
120 dev_info(dev, "quirk IN3_MAP enabled\n");
122 case BYT_RT5640_NO_INTERNAL_MIC_MAP:
123 dev_info(dev, "quirk NO_INTERNAL_MIC_MAP enabled\n");
126 dev_err(dev, "quirk map 0x%x is not supported, microphone input will not work\n", map);
129 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
130 dev_info(dev, "quirk realtek,jack-detect-source %ld\n",
131 BYT_RT5640_JDSRC(byt_rt5640_quirk));
132 dev_info(dev, "quirk realtek,over-current-threshold-microamp %ld\n",
133 BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
134 dev_info(dev, "quirk realtek,over-current-scale-factor %ld\n",
135 BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
137 if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
138 dev_info(dev, "quirk JD_NOT_INV enabled\n");
139 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER)
140 dev_info(dev, "quirk MONO_SPEAKER enabled\n");
141 if (byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS)
142 dev_info(dev, "quirk NO_SPEAKERS enabled\n");
143 if (byt_rt5640_quirk & BYT_RT5640_LINEOUT)
144 dev_info(dev, "quirk LINEOUT enabled\n");
145 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
146 dev_info(dev, "quirk DIFF_MIC enabled\n");
147 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
148 dev_info(dev, "quirk SSP0_AIF1 enabled\n");
150 has_ssp0_aif1 = true;
152 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
153 dev_info(dev, "quirk SSP0_AIF2 enabled\n");
155 has_ssp0_aif2 = true;
157 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
158 dev_info(dev, "quirk SSP2_AIF2 enabled\n");
159 has_ssp2_aif2 = true;
161 if (is_bytcr && !has_ssp0)
162 dev_err(dev, "Invalid routing, bytcr detected but no SSP0-based quirk, audio cannot work with SSP2 on bytcr\n");
163 if (has_ssp0_aif1 && has_ssp0_aif2)
164 dev_err(dev, "Invalid routing, SSP0 cannot be connected to both AIF1 and AIF2\n");
165 if (has_ssp0 && has_ssp2_aif2)
166 dev_err(dev, "Invalid routing, cannot have both SSP0 and SSP2 connected to codec\n");
168 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
169 dev_info(dev, "quirk MCLK_EN enabled\n");
172 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
174 dev_info(dev, "quirk MCLK_25MHZ enabled\n");
176 dev_err(dev, "quirk MCLK_25MHZ enabled but quirk MCLK not selected, will be ignored\n");
180 static int byt_rt5640_prepare_and_enable_pll1(struct snd_soc_dai *codec_dai,
185 /* Configure the PLL before selecting it */
186 if (!(byt_rt5640_quirk & BYT_RT5640_MCLK_EN)) {
187 /* use bitclock as PLL input */
188 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
189 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
190 /* 2x16 bit slots on SSP0 */
191 ret = snd_soc_dai_set_pll(codec_dai, 0,
193 rate * 32, rate * 512);
195 /* 2x15 bit slots on SSP2 */
196 ret = snd_soc_dai_set_pll(codec_dai, 0,
198 rate * 50, rate * 512);
201 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
202 ret = snd_soc_dai_set_pll(codec_dai, 0,
204 25000000, rate * 512);
206 ret = snd_soc_dai_set_pll(codec_dai, 0,
208 19200000, rate * 512);
213 dev_err(codec_dai->component->dev, "can't set pll: %d\n", ret);
217 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
218 rate * 512, SND_SOC_CLOCK_IN);
220 dev_err(codec_dai->component->dev, "can't set clock %d\n", ret);
227 #define BYT_CODEC_DAI1 "rt5640-aif1"
228 #define BYT_CODEC_DAI2 "rt5640-aif2"
230 static int platform_clock_control(struct snd_soc_dapm_widget *w,
231 struct snd_kcontrol *k, int event)
233 struct snd_soc_dapm_context *dapm = w->dapm;
234 struct snd_soc_card *card = dapm->card;
235 struct snd_soc_dai *codec_dai;
236 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
239 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI1);
241 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI2);
245 "Codec dai not found; Unable to set platform clock\n");
249 if (SND_SOC_DAPM_EVENT_ON(event)) {
250 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
251 ret = clk_prepare_enable(priv->mclk);
254 "could not configure MCLK state\n");
258 ret = byt_rt5640_prepare_and_enable_pll1(codec_dai, 48000);
261 * Set codec clock source to internal clock before
262 * turning off the platform clock. Codec needs clock
263 * for Jack detection and button press
265 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_RCCLK,
269 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
270 clk_disable_unprepare(priv->mclk);
275 dev_err(card->dev, "can't set codec sysclk: %d\n", ret);
282 static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
283 SND_SOC_DAPM_HP("Headphone", NULL),
284 SND_SOC_DAPM_MIC("Headset Mic", NULL),
285 SND_SOC_DAPM_MIC("Internal Mic", NULL),
286 SND_SOC_DAPM_SPK("Speaker", NULL),
287 SND_SOC_DAPM_LINE("Line Out", NULL),
288 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
289 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
290 SND_SOC_DAPM_POST_PMD),
293 static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
294 {"Headphone", NULL, "Platform Clock"},
295 {"Headset Mic", NULL, "Platform Clock"},
296 {"Headset Mic", NULL, "MICBIAS1"},
297 {"IN2P", NULL, "Headset Mic"},
298 {"Headphone", NULL, "HPOL"},
299 {"Headphone", NULL, "HPOR"},
302 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
303 {"Internal Mic", NULL, "Platform Clock"},
304 {"DMIC1", NULL, "Internal Mic"},
307 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
308 {"Internal Mic", NULL, "Platform Clock"},
309 {"DMIC2", NULL, "Internal Mic"},
312 static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
313 {"Internal Mic", NULL, "Platform Clock"},
314 {"Internal Mic", NULL, "MICBIAS1"},
315 {"IN1P", NULL, "Internal Mic"},
318 static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map[] = {
319 {"Internal Mic", NULL, "Platform Clock"},
320 {"Internal Mic", NULL, "MICBIAS1"},
321 {"IN3P", NULL, "Internal Mic"},
324 static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = {
325 {"ssp2 Tx", NULL, "codec_out0"},
326 {"ssp2 Tx", NULL, "codec_out1"},
327 {"codec_in0", NULL, "ssp2 Rx"},
328 {"codec_in1", NULL, "ssp2 Rx"},
330 {"AIF1 Playback", NULL, "ssp2 Tx"},
331 {"ssp2 Rx", NULL, "AIF1 Capture"},
334 static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_map[] = {
335 {"ssp2 Tx", NULL, "codec_out0"},
336 {"ssp2 Tx", NULL, "codec_out1"},
337 {"codec_in0", NULL, "ssp2 Rx"},
338 {"codec_in1", NULL, "ssp2 Rx"},
340 {"AIF2 Playback", NULL, "ssp2 Tx"},
341 {"ssp2 Rx", NULL, "AIF2 Capture"},
344 static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif1_map[] = {
345 {"ssp0 Tx", NULL, "modem_out"},
346 {"modem_in", NULL, "ssp0 Rx"},
348 {"AIF1 Playback", NULL, "ssp0 Tx"},
349 {"ssp0 Rx", NULL, "AIF1 Capture"},
352 static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif2_map[] = {
353 {"ssp0 Tx", NULL, "modem_out"},
354 {"modem_in", NULL, "ssp0 Rx"},
356 {"AIF2 Playback", NULL, "ssp0 Tx"},
357 {"ssp0 Rx", NULL, "AIF2 Capture"},
360 static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = {
361 {"Speaker", NULL, "Platform Clock"},
362 {"Speaker", NULL, "SPOLP"},
363 {"Speaker", NULL, "SPOLN"},
364 {"Speaker", NULL, "SPORP"},
365 {"Speaker", NULL, "SPORN"},
368 static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = {
369 {"Speaker", NULL, "Platform Clock"},
370 {"Speaker", NULL, "SPOLP"},
371 {"Speaker", NULL, "SPOLN"},
374 static const struct snd_soc_dapm_route byt_rt5640_lineout_map[] = {
375 {"Line Out", NULL, "Platform Clock"},
376 {"Line Out", NULL, "LOUTR"},
377 {"Line Out", NULL, "LOUTL"},
380 static const struct snd_kcontrol_new byt_rt5640_controls[] = {
381 SOC_DAPM_PIN_SWITCH("Headphone"),
382 SOC_DAPM_PIN_SWITCH("Headset Mic"),
383 SOC_DAPM_PIN_SWITCH("Internal Mic"),
384 SOC_DAPM_PIN_SWITCH("Speaker"),
385 SOC_DAPM_PIN_SWITCH("Line Out"),
388 static struct snd_soc_jack_pin rt5640_pins[] = {
391 .mask = SND_JACK_HEADPHONE,
394 .pin = "Headset Mic",
395 .mask = SND_JACK_MICROPHONE,
399 static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream,
400 struct snd_pcm_hw_params *params)
402 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
403 struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
405 return byt_rt5640_prepare_and_enable_pll1(dai, params_rate(params));
408 /* Please keep this list alphabetically sorted */
409 static const struct dmi_system_id byt_rt5640_quirk_table[] = {
410 { /* Acer Iconia Tab 8 W1-810 */
412 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"),
413 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Iconia W1-810"),
415 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
416 BYT_RT5640_JD_SRC_JD1_IN4P |
417 BYT_RT5640_OVCD_TH_1500UA |
418 BYT_RT5640_OVCD_SF_0P75 |
419 BYT_RT5640_SSP0_AIF1 |
422 { /* Acer One 10 S1002 */
424 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
425 DMI_MATCH(DMI_PRODUCT_NAME, "One S1002"),
427 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
428 BYT_RT5640_JD_SRC_JD2_IN4N |
429 BYT_RT5640_OVCD_TH_2000UA |
430 BYT_RT5640_OVCD_SF_0P75 |
431 BYT_RT5640_DIFF_MIC |
432 BYT_RT5640_SSP0_AIF2 |
437 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
438 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
440 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
441 BYT_RT5640_JD_SRC_JD2_IN4N |
442 BYT_RT5640_OVCD_TH_2000UA |
443 BYT_RT5640_OVCD_SF_0P75 |
444 BYT_RT5640_SSP0_AIF1 |
449 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
450 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 80 Cesium"),
452 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
453 BYT_RT5640_MONO_SPEAKER |
454 BYT_RT5640_SSP0_AIF1 |
459 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
460 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 140 CESIUM"),
462 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
463 BYT_RT5640_JD_SRC_JD2_IN4N |
464 BYT_RT5640_OVCD_TH_2000UA |
465 BYT_RT5640_OVCD_SF_0P75 |
466 BYT_RT5640_SSP0_AIF1 |
471 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
472 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ME176C"),
474 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
475 BYT_RT5640_JD_SRC_JD2_IN4N |
476 BYT_RT5640_OVCD_TH_2000UA |
477 BYT_RT5640_OVCD_SF_0P75 |
478 BYT_RT5640_SSP0_AIF1 |
483 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
484 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
486 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
487 BYT_RT5640_JD_SRC_JD2_IN4N |
488 BYT_RT5640_OVCD_TH_2000UA |
489 BYT_RT5640_OVCD_SF_0P75 |
494 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
495 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"),
497 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
498 BYT_RT5640_JD_SRC_JD2_IN4N |
499 BYT_RT5640_OVCD_TH_2000UA |
500 BYT_RT5640_OVCD_SF_0P75 |
501 BYT_RT5640_MONO_SPEAKER |
502 BYT_RT5640_DIFF_MIC |
503 BYT_RT5640_SSP0_AIF2 |
506 { /* Chuwi Vi8 (CWI506) */
508 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Insyde"),
509 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "i86"),
510 /* The above are too generic, also match BIOS info */
511 DMI_MATCH(DMI_BIOS_VERSION, "CHUWI.D86JLBNR"),
513 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
514 BYT_RT5640_MONO_SPEAKER |
515 BYT_RT5640_SSP0_AIF1 |
519 /* Chuwi Vi10 (CWI505) */
521 DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
522 DMI_MATCH(DMI_BOARD_NAME, "BYT-PF02"),
523 DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
524 DMI_MATCH(DMI_PRODUCT_NAME, "S165"),
526 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
527 BYT_RT5640_JD_SRC_JD2_IN4N |
528 BYT_RT5640_OVCD_TH_2000UA |
529 BYT_RT5640_OVCD_SF_0P75 |
530 BYT_RT5640_DIFF_MIC |
531 BYT_RT5640_SSP0_AIF1 |
535 /* Chuwi Hi8 (CWI509) */
537 DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
538 DMI_MATCH(DMI_BOARD_NAME, "BYT-PA03C"),
539 DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
540 DMI_MATCH(DMI_PRODUCT_NAME, "S806"),
542 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
543 BYT_RT5640_JD_SRC_JD2_IN4N |
544 BYT_RT5640_OVCD_TH_2000UA |
545 BYT_RT5640_OVCD_SF_0P75 |
546 BYT_RT5640_MONO_SPEAKER |
547 BYT_RT5640_DIFF_MIC |
548 BYT_RT5640_SSP0_AIF1 |
553 DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
554 DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"),
556 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP),
558 { /* Connect Tablet 9 */
560 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Connect"),
561 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Tablet 9"),
563 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
564 BYT_RT5640_MONO_SPEAKER |
565 BYT_RT5640_SSP0_AIF1 |
570 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
571 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
573 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
574 BYT_RT5640_JD_SRC_JD2_IN4N |
575 BYT_RT5640_OVCD_TH_2000UA |
576 BYT_RT5640_OVCD_SF_0P75 |
577 BYT_RT5640_MONO_SPEAKER |
580 { /* Estar Beauty HD MID 7316R */
582 DMI_MATCH(DMI_SYS_VENDOR, "Estar"),
583 DMI_MATCH(DMI_PRODUCT_NAME, "eSTAR BEAUTY HD Intel Quad core"),
585 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
586 BYT_RT5640_MONO_SPEAKER |
587 BYT_RT5640_SSP0_AIF1 |
590 { /* Glavey TM800A550L */
592 DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
593 DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
594 /* Above strings are too generic, also match on BIOS version */
595 DMI_MATCH(DMI_BIOS_VERSION, "ZY-8-BI-PX4S70VTR400-X423B-005-D"),
597 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
598 BYT_RT5640_SSP0_AIF1 |
603 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
604 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"),
606 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
609 { /* HP Pavilion x2 10-k0XX, 10-n0XX */
611 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
612 DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion x2 Detachable"),
614 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
615 BYT_RT5640_JD_SRC_JD2_IN4N |
616 BYT_RT5640_OVCD_TH_1500UA |
617 BYT_RT5640_OVCD_SF_0P75 |
618 BYT_RT5640_SSP0_AIF1 |
621 { /* HP Pavilion x2 10-p0XX */
623 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
624 DMI_MATCH(DMI_PRODUCT_NAME, "HP x2 Detachable 10-p0XX"),
626 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
627 BYT_RT5640_JD_SRC_JD1_IN4P |
628 BYT_RT5640_OVCD_TH_2000UA |
629 BYT_RT5640_OVCD_SF_0P75 |
634 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
635 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP Stream 7 Tablet"),
637 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
638 BYT_RT5640_MONO_SPEAKER |
639 BYT_RT5640_JD_NOT_INV |
640 BYT_RT5640_SSP0_AIF1 |
643 { /* I.T.Works TW891 */
645 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "To be filled by O.E.M."),
646 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TW891"),
647 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "To be filled by O.E.M."),
648 DMI_EXACT_MATCH(DMI_BOARD_NAME, "TW891"),
650 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
651 BYT_RT5640_MONO_SPEAKER |
652 BYT_RT5640_SSP0_AIF1 |
655 { /* Lamina I8270 / T701BR.SE */
657 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Lamina"),
658 DMI_EXACT_MATCH(DMI_BOARD_NAME, "T701BR.SE"),
660 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
661 BYT_RT5640_MONO_SPEAKER |
662 BYT_RT5640_JD_NOT_INV |
663 BYT_RT5640_SSP0_AIF1 |
666 { /* Lenovo Miix 2 8 */
668 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
669 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "20326"),
670 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Hiking"),
672 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
673 BYT_RT5640_JD_SRC_JD2_IN4N |
674 BYT_RT5640_OVCD_TH_2000UA |
675 BYT_RT5640_OVCD_SF_0P75 |
676 BYT_RT5640_MONO_SPEAKER |
679 { /* Lenovo Miix 3-830 */
681 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
682 DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 3-830"),
684 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
685 BYT_RT5640_JD_SRC_JD2_IN4N |
686 BYT_RT5640_OVCD_TH_2000UA |
687 BYT_RT5640_OVCD_SF_0P75 |
688 BYT_RT5640_MONO_SPEAKER |
689 BYT_RT5640_DIFF_MIC |
690 BYT_RT5640_SSP0_AIF1 |
693 { /* Linx Linx7 tablet */
695 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LINX"),
696 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "LINX7"),
698 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
699 BYT_RT5640_MONO_SPEAKER |
700 BYT_RT5640_JD_NOT_INV |
701 BYT_RT5640_SSP0_AIF1 |
704 { /* Mele PCG03 Mini PC */
706 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Mini PC"),
707 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Mini PC"),
709 .driver_data = (void *)(BYT_RT5640_NO_INTERNAL_MIC_MAP |
710 BYT_RT5640_NO_SPEAKERS |
711 BYT_RT5640_SSP0_AIF1),
713 { /* MPMAN Converter 9, similar hw as the I.T.Works TW891 2-in-1 */
715 DMI_MATCH(DMI_SYS_VENDOR, "MPMAN"),
716 DMI_MATCH(DMI_PRODUCT_NAME, "Converter9"),
718 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
719 BYT_RT5640_MONO_SPEAKER |
720 BYT_RT5640_SSP0_AIF1 |
724 /* MPMAN MPWIN895CL */
726 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "MPMAN"),
727 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MPWIN8900CL"),
729 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
730 BYT_RT5640_MONO_SPEAKER |
731 BYT_RT5640_SSP0_AIF1 |
734 { /* MSI S100 tablet */
736 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Micro-Star International Co., Ltd."),
737 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "S100"),
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_MONO_SPEAKER |
744 BYT_RT5640_DIFF_MIC |
747 { /* Nuvison/TMax TM800W560 */
749 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TMAX"),
750 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TM800W560L"),
752 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
753 BYT_RT5640_JD_SRC_JD2_IN4N |
754 BYT_RT5640_OVCD_TH_2000UA |
755 BYT_RT5640_OVCD_SF_0P75 |
756 BYT_RT5640_JD_NOT_INV |
757 BYT_RT5640_DIFF_MIC |
758 BYT_RT5640_SSP0_AIF1 |
763 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
764 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
765 /* The above are too generic, also match BIOS info */
766 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "5.6.5"),
767 DMI_EXACT_MATCH(DMI_BIOS_DATE, "07/25/2014"),
769 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
770 BYT_RT5640_JD_SRC_JD2_IN4N |
771 BYT_RT5640_OVCD_TH_2000UA |
772 BYT_RT5640_OVCD_SF_0P75 |
773 BYT_RT5640_DIFF_MIC |
778 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
779 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
780 /* The above are too generic, also match BIOS info */
781 DMI_MATCH(DMI_BIOS_VERSION, "V8L_WIN32_CHIPHD"),
783 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
784 BYT_RT5640_MONO_SPEAKER |
785 BYT_RT5640_SSP0_AIF1 |
788 { /* Point of View Mobii TAB-P800W (V2.0) */
790 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
791 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
792 /* The above are too generic, also match BIOS info */
793 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1014"),
794 DMI_EXACT_MATCH(DMI_BIOS_DATE, "10/24/2014"),
796 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
797 BYT_RT5640_JD_SRC_JD2_IN4N |
798 BYT_RT5640_OVCD_TH_2000UA |
799 BYT_RT5640_OVCD_SF_0P75 |
800 BYT_RT5640_MONO_SPEAKER |
801 BYT_RT5640_DIFF_MIC |
802 BYT_RT5640_SSP0_AIF2 |
805 { /* Point of View Mobii TAB-P800W (V2.1) */
807 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
808 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
809 /* The above are too generic, also match BIOS info */
810 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1013"),
811 DMI_EXACT_MATCH(DMI_BIOS_DATE, "08/22/2014"),
813 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
814 BYT_RT5640_JD_SRC_JD2_IN4N |
815 BYT_RT5640_OVCD_TH_2000UA |
816 BYT_RT5640_OVCD_SF_0P75 |
817 BYT_RT5640_MONO_SPEAKER |
818 BYT_RT5640_DIFF_MIC |
819 BYT_RT5640_SSP0_AIF2 |
822 { /* Point of View Mobii TAB-P1005W-232 (V2.0) */
824 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "POV"),
825 DMI_EXACT_MATCH(DMI_BOARD_NAME, "I102A"),
827 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
828 BYT_RT5640_JD_SRC_JD2_IN4N |
829 BYT_RT5640_OVCD_TH_2000UA |
830 BYT_RT5640_OVCD_SF_0P75 |
831 BYT_RT5640_DIFF_MIC |
832 BYT_RT5640_SSP0_AIF1 |
838 DMI_MATCH(DMI_SYS_VENDOR, "Prowise"),
839 DMI_MATCH(DMI_PRODUCT_NAME, "PT301"),
841 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
842 BYT_RT5640_JD_SRC_JD2_IN4N |
843 BYT_RT5640_OVCD_TH_2000UA |
844 BYT_RT5640_OVCD_SF_0P75 |
845 BYT_RT5640_DIFF_MIC |
846 BYT_RT5640_SSP0_AIF1 |
852 DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"),
853 DMI_MATCH(DMI_BOARD_NAME, "tPAD"),
855 .driver_data = (void *)(BYT_RT5640_IN3_MAP |
856 BYT_RT5640_JD_SRC_JD1_IN4P |
857 BYT_RT5640_OVCD_TH_2000UA |
858 BYT_RT5640_OVCD_SF_1P0 |
859 BYT_RT5640_SSP0_AIF1 |
862 { /* Toshiba Satellite Click Mini L9W-B */
864 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
865 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "SATELLITE Click Mini L9W-B"),
867 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
868 BYT_RT5640_JD_SRC_JD2_IN4N |
869 BYT_RT5640_OVCD_TH_1500UA |
870 BYT_RT5640_OVCD_SF_0P75 |
871 BYT_RT5640_SSP0_AIF1 |
874 { /* Toshiba Encore WT8-A */
876 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
877 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT8-A"),
879 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
880 BYT_RT5640_JD_SRC_JD2_IN4N |
881 BYT_RT5640_OVCD_TH_2000UA |
882 BYT_RT5640_OVCD_SF_0P75 |
883 BYT_RT5640_JD_NOT_INV |
886 { /* Toshiba Encore WT10-A */
888 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
889 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT10-A-103"),
891 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
892 BYT_RT5640_JD_SRC_JD1_IN4P |
893 BYT_RT5640_OVCD_TH_2000UA |
894 BYT_RT5640_OVCD_SF_0P75 |
895 BYT_RT5640_SSP0_AIF2 |
898 { /* Voyo Winpad A15 */
900 DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
901 DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
902 /* Above strings are too generic, also match on BIOS date */
903 DMI_MATCH(DMI_BIOS_DATE, "11/20/2014"),
905 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
906 BYT_RT5640_JD_SRC_JD2_IN4N |
907 BYT_RT5640_OVCD_TH_2000UA |
908 BYT_RT5640_OVCD_SF_0P75 |
909 BYT_RT5640_DIFF_MIC |
912 { /* Catch-all for generic Insyde tablets, must be last */
914 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
916 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
918 BYT_RT5640_SSP0_AIF1),
925 * Note this MUST be called before snd_soc_register_card(), so that the props
926 * are in place before the codec component driver's probe function parses them.
928 static int byt_rt5640_add_codec_device_props(const char *i2c_dev_name)
930 struct property_entry props[MAX_NO_PROPS] = {};
931 struct device *i2c_dev;
934 i2c_dev = bus_find_device_by_name(&i2c_bus_type, NULL, i2c_dev_name);
936 return -EPROBE_DEFER;
938 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
939 case BYT_RT5640_DMIC1_MAP:
940 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic1-data-pin",
941 RT5640_DMIC1_DATA_PIN_IN1P);
943 case BYT_RT5640_DMIC2_MAP:
944 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic2-data-pin",
945 RT5640_DMIC2_DATA_PIN_IN1N);
947 case BYT_RT5640_IN1_MAP:
948 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
950 PROPERTY_ENTRY_BOOL("realtek,in1-differential");
952 case BYT_RT5640_IN3_MAP:
953 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
955 PROPERTY_ENTRY_BOOL("realtek,in3-differential");
959 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
960 props[cnt++] = PROPERTY_ENTRY_U32(
961 "realtek,jack-detect-source",
962 BYT_RT5640_JDSRC(byt_rt5640_quirk));
964 props[cnt++] = PROPERTY_ENTRY_U32(
965 "realtek,over-current-threshold-microamp",
966 BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
968 props[cnt++] = PROPERTY_ENTRY_U32(
969 "realtek,over-current-scale-factor",
970 BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
973 if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
974 props[cnt++] = PROPERTY_ENTRY_BOOL("realtek,jack-detect-not-inverted");
976 ret = device_add_properties(i2c_dev, props);
982 static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
984 struct snd_soc_card *card = runtime->card;
985 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
986 struct snd_soc_component *component = asoc_rtd_to_codec(runtime, 0)->component;
987 const struct snd_soc_dapm_route *custom_map = NULL;
991 card->dapm.idle_bias_off = true;
993 /* Start with RC clk for jack-detect (we disable MCLK below) */
994 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
995 snd_soc_component_update_bits(component, RT5640_GLB_CLK,
996 RT5640_SCLK_SRC_MASK, RT5640_SCLK_SRC_RCCLK);
998 rt5640_sel_asrc_clk_src(component,
999 RT5640_DA_STEREO_FILTER |
1000 RT5640_DA_MONO_L_FILTER |
1001 RT5640_DA_MONO_R_FILTER |
1002 RT5640_AD_STEREO_FILTER |
1003 RT5640_AD_MONO_L_FILTER |
1004 RT5640_AD_MONO_R_FILTER,
1005 RT5640_CLK_SEL_ASRC);
1007 ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
1008 ARRAY_SIZE(byt_rt5640_controls));
1010 dev_err(card->dev, "unable to add card controls\n");
1014 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
1015 case BYT_RT5640_IN1_MAP:
1016 custom_map = byt_rt5640_intmic_in1_map;
1017 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
1019 case BYT_RT5640_IN3_MAP:
1020 custom_map = byt_rt5640_intmic_in3_map;
1021 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in3_map);
1023 case BYT_RT5640_DMIC1_MAP:
1024 custom_map = byt_rt5640_intmic_dmic1_map;
1025 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
1027 case BYT_RT5640_DMIC2_MAP:
1028 custom_map = byt_rt5640_intmic_dmic2_map;
1029 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
1033 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
1037 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
1038 ret = snd_soc_dapm_add_routes(&card->dapm,
1039 byt_rt5640_ssp2_aif2_map,
1040 ARRAY_SIZE(byt_rt5640_ssp2_aif2_map));
1041 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
1042 ret = snd_soc_dapm_add_routes(&card->dapm,
1043 byt_rt5640_ssp0_aif1_map,
1044 ARRAY_SIZE(byt_rt5640_ssp0_aif1_map));
1045 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
1046 ret = snd_soc_dapm_add_routes(&card->dapm,
1047 byt_rt5640_ssp0_aif2_map,
1048 ARRAY_SIZE(byt_rt5640_ssp0_aif2_map));
1050 ret = snd_soc_dapm_add_routes(&card->dapm,
1051 byt_rt5640_ssp2_aif1_map,
1052 ARRAY_SIZE(byt_rt5640_ssp2_aif1_map));
1057 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
1058 ret = snd_soc_dapm_add_routes(&card->dapm,
1059 byt_rt5640_mono_spk_map,
1060 ARRAY_SIZE(byt_rt5640_mono_spk_map));
1061 } else if (!(byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS)) {
1062 ret = snd_soc_dapm_add_routes(&card->dapm,
1063 byt_rt5640_stereo_spk_map,
1064 ARRAY_SIZE(byt_rt5640_stereo_spk_map));
1069 if (byt_rt5640_quirk & BYT_RT5640_LINEOUT) {
1070 ret = snd_soc_dapm_add_routes(&card->dapm,
1071 byt_rt5640_lineout_map,
1072 ARRAY_SIZE(byt_rt5640_lineout_map));
1077 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
1079 * The firmware might enable the clock at
1080 * boot (this information may or may not
1081 * be reflected in the enable clock register).
1082 * To change the rate we must disable the clock
1083 * first to cover these cases. Due to common
1084 * clock framework restrictions that do not allow
1085 * to disable a clock that has not been enabled,
1086 * we need to enable the clock first.
1088 ret = clk_prepare_enable(priv->mclk);
1090 clk_disable_unprepare(priv->mclk);
1092 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ)
1093 ret = clk_set_rate(priv->mclk, 25000000);
1095 ret = clk_set_rate(priv->mclk, 19200000);
1098 dev_err(card->dev, "unable to set MCLK rate\n");
1103 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
1104 ret = snd_soc_card_jack_new(card, "Headset",
1105 SND_JACK_HEADSET | SND_JACK_BTN_0,
1106 &priv->jack, rt5640_pins,
1107 ARRAY_SIZE(rt5640_pins));
1109 dev_err(card->dev, "Jack creation failed %d\n", ret);
1112 snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0,
1114 snd_soc_component_set_jack(component, &priv->jack, NULL);
1120 static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd,
1121 struct snd_pcm_hw_params *params)
1123 struct snd_interval *rate = hw_param_interval(params,
1124 SNDRV_PCM_HW_PARAM_RATE);
1125 struct snd_interval *channels = hw_param_interval(params,
1126 SNDRV_PCM_HW_PARAM_CHANNELS);
1129 /* The DSP will covert the FE rate to 48k, stereo */
1130 rate->min = rate->max = 48000;
1131 channels->min = channels->max = 2;
1133 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
1134 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
1135 /* set SSP0 to 16-bit */
1136 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
1139 /* set SSP2 to 24-bit */
1140 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
1145 * Default mode for SSP configuration is TDM 4 slot, override config
1146 * with explicit setting to I2S 2ch. The word length is set with
1147 * dai_set_tdm_slot() since there is no other API exposed
1149 ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
1150 SND_SOC_DAIFMT_I2S |
1151 SND_SOC_DAIFMT_NB_NF |
1152 SND_SOC_DAIFMT_CBS_CFS);
1154 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
1158 ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, bits);
1160 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
1167 static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream)
1169 return snd_pcm_hw_constraint_single(substream->runtime,
1170 SNDRV_PCM_HW_PARAM_RATE, 48000);
1173 static const struct snd_soc_ops byt_rt5640_aif1_ops = {
1174 .startup = byt_rt5640_aif1_startup,
1177 static const struct snd_soc_ops byt_rt5640_be_ssp2_ops = {
1178 .hw_params = byt_rt5640_aif1_hw_params,
1181 SND_SOC_DAILINK_DEF(dummy,
1182 DAILINK_COMP_ARRAY(COMP_DUMMY()));
1184 SND_SOC_DAILINK_DEF(media,
1185 DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
1187 SND_SOC_DAILINK_DEF(deepbuffer,
1188 DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
1190 SND_SOC_DAILINK_DEF(ssp2_port,
1191 /* overwritten for ssp0 routing */
1192 DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));
1193 SND_SOC_DAILINK_DEF(ssp2_codec,
1194 DAILINK_COMP_ARRAY(COMP_CODEC(
1195 /* overwritten with HID */ "i2c-10EC5640:00",
1196 /* changed w/ quirk */ "rt5640-aif1")));
1198 SND_SOC_DAILINK_DEF(platform,
1199 DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
1201 static struct snd_soc_dai_link byt_rt5640_dais[] = {
1202 [MERR_DPCM_AUDIO] = {
1203 .name = "Baytrail Audio Port",
1204 .stream_name = "Baytrail Audio",
1209 .ops = &byt_rt5640_aif1_ops,
1210 SND_SOC_DAILINK_REG(media, dummy, platform),
1212 [MERR_DPCM_DEEP_BUFFER] = {
1213 .name = "Deep-Buffer Audio Port",
1214 .stream_name = "Deep-Buffer Audio",
1218 .ops = &byt_rt5640_aif1_ops,
1219 SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),
1223 .name = "SSP2-Codec",
1226 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
1227 | SND_SOC_DAIFMT_CBS_CFS,
1228 .be_hw_params_fixup = byt_rt5640_codec_fixup,
1231 .init = byt_rt5640_init,
1232 .ops = &byt_rt5640_be_ssp2_ops,
1233 SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform),
1238 static char byt_rt5640_codec_name[SND_ACPI_I2C_ID_LEN];
1239 #if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
1240 static char byt_rt5640_long_name[40]; /* = "bytcr-rt5640-*-spk-*-mic" */
1242 static char byt_rt5640_components[64]; /* = "cfg-spk:* cfg-mic:* ..." */
1244 static int byt_rt5640_suspend(struct snd_soc_card *card)
1246 struct snd_soc_component *component;
1248 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1251 for_each_card_components(card, component) {
1252 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1253 dev_dbg(component->dev, "disabling jack detect before suspend\n");
1254 snd_soc_component_set_jack(component, NULL, NULL);
1262 static int byt_rt5640_resume(struct snd_soc_card *card)
1264 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
1265 struct snd_soc_component *component;
1267 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1270 for_each_card_components(card, component) {
1271 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1272 dev_dbg(component->dev, "re-enabling jack detect after resume\n");
1273 snd_soc_component_set_jack(component, &priv->jack, NULL);
1281 /* use space before codec name to simplify card ID, and simplify driver name */
1282 #define SOF_CARD_NAME "bytcht rt5640" /* card name will be 'sof-bytcht rt5640' */
1283 #define SOF_DRIVER_NAME "SOF"
1285 #define CARD_NAME "bytcr-rt5640"
1286 #define DRIVER_NAME NULL /* card name will be used for driver name */
1288 static struct snd_soc_card byt_rt5640_card = {
1289 .owner = THIS_MODULE,
1290 .dai_link = byt_rt5640_dais,
1291 .num_links = ARRAY_SIZE(byt_rt5640_dais),
1292 .dapm_widgets = byt_rt5640_widgets,
1293 .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
1294 .dapm_routes = byt_rt5640_audio_map,
1295 .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
1296 .fully_routed = true,
1297 .suspend_pre = byt_rt5640_suspend,
1298 .resume_post = byt_rt5640_resume,
1301 struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */
1302 u64 aif_value; /* 1: AIF1, 2: AIF2 */
1303 u64 mclock_value; /* usually 25MHz (0x17d7940), ignored */
1306 static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
1308 struct device *dev = &pdev->dev;
1309 static const char * const map_name[] = { "dmic1", "dmic2", "in1", "in3", "none" };
1310 __maybe_unused const char *spk_type;
1311 const struct dmi_system_id *dmi_id;
1312 const char *lineout_string = "";
1313 struct byt_rt5640_private *priv;
1314 struct snd_soc_acpi_mach *mach;
1315 const char *platform_name;
1316 struct acpi_device *adev;
1324 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
1328 /* register the soc card */
1329 byt_rt5640_card.dev = &pdev->dev;
1330 mach = byt_rt5640_card.dev->platform_data;
1331 snd_soc_card_set_drvdata(&byt_rt5640_card, priv);
1333 /* fix index of codec dai */
1334 for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) {
1335 if (!strcmp(byt_rt5640_dais[i].codecs->name,
1336 "i2c-10EC5640:00")) {
1342 /* fixup codec name based on HID */
1343 adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);
1345 snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name),
1346 "i2c-%s", acpi_dev_name(adev));
1347 put_device(&adev->dev);
1348 byt_rt5640_dais[dai_index].codecs->name = byt_rt5640_codec_name;
1352 * swap SSP0 if bytcr is detected
1353 * (will be overridden if DMI quirk is detected)
1355 if (soc_intel_is_byt()) {
1356 if (mach->mach_params.acpi_ipc_irq_index == 0)
1362 * Baytrail CR platforms may have CHAN package in BIOS, try
1363 * to find relevant routing quirk based as done on Windows
1364 * platforms. We have to read the information directly from the
1365 * BIOS, at this stage the card is not created and the links
1366 * with the codec driver/pdata are non-existent
1369 struct acpi_chan_package chan_package;
1371 /* format specified: 2 64-bit integers */
1372 struct acpi_buffer format = {sizeof("NN"), "NN"};
1373 struct acpi_buffer state = {0, NULL};
1374 struct snd_soc_acpi_package_context pkg_ctx;
1375 bool pkg_found = false;
1377 state.length = sizeof(chan_package);
1378 state.pointer = &chan_package;
1380 pkg_ctx.name = "CHAN";
1382 pkg_ctx.format = &format;
1383 pkg_ctx.state = &state;
1384 pkg_ctx.data_valid = false;
1386 pkg_found = snd_soc_acpi_find_package_from_hid(mach->id,
1389 if (chan_package.aif_value == 1) {
1390 dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n");
1391 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF1;
1392 } else if (chan_package.aif_value == 2) {
1393 dev_info(&pdev->dev, "BIOS Routing: AIF2 connected\n");
1394 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1396 dev_info(&pdev->dev, "BIOS Routing isn't valid, ignored\n");
1402 /* no BIOS indications, assume SSP0-AIF2 connection */
1403 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1406 /* change defaults for Baytrail-CR capture */
1407 byt_rt5640_quirk |= BYTCR_INPUT_DEFAULTS;
1409 byt_rt5640_quirk |= BYT_RT5640_DMIC1_MAP |
1410 BYT_RT5640_JD_SRC_JD2_IN4N |
1411 BYT_RT5640_OVCD_TH_2000UA |
1412 BYT_RT5640_OVCD_SF_0P75;
1415 /* check quirks before creating card */
1416 dmi_id = dmi_first_match(byt_rt5640_quirk_table);
1418 byt_rt5640_quirk = (unsigned long)dmi_id->driver_data;
1419 if (quirk_override != -1) {
1420 dev_info(&pdev->dev, "Overriding quirk 0x%lx => 0x%x\n",
1421 byt_rt5640_quirk, quirk_override);
1422 byt_rt5640_quirk = quirk_override;
1425 /* Must be called before register_card, also see declaration comment. */
1426 ret_val = byt_rt5640_add_codec_device_props(byt_rt5640_codec_name);
1430 log_quirks(&pdev->dev);
1432 if ((byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) ||
1433 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
1434 byt_rt5640_dais[dai_index].codecs->dai_name = "rt5640-aif2";
1440 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
1441 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2))
1442 byt_rt5640_dais[dai_index].cpus->dai_name = "ssp0-port";
1444 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
1445 priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
1446 if (IS_ERR(priv->mclk)) {
1447 ret_val = PTR_ERR(priv->mclk);
1450 "Failed to get MCLK from pmc_plt_clk_3: %d\n",
1454 * Fall back to bit clock usage for -ENOENT (clock not
1455 * available likely due to missing dependencies), bail
1456 * for all other errors, including -EPROBE_DEFER
1458 if (ret_val != -ENOENT)
1460 byt_rt5640_quirk &= ~BYT_RT5640_MCLK_EN;
1464 if (byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS) {
1467 } else if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
1472 spk_type = "stereo";
1475 if (byt_rt5640_quirk & BYT_RT5640_LINEOUT)
1476 lineout_string = " cfg-lineout:1";
1478 snprintf(byt_rt5640_components, sizeof(byt_rt5640_components),
1479 "cfg-spk:%d cfg-mic:%s aif:%d%s", cfg_spk,
1480 map_name[BYT_RT5640_MAP(byt_rt5640_quirk)], aif,
1482 byt_rt5640_card.components = byt_rt5640_components;
1483 #if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
1484 snprintf(byt_rt5640_long_name, sizeof(byt_rt5640_long_name),
1485 "bytcr-rt5640-%s-spk-%s-mic", spk_type,
1486 map_name[BYT_RT5640_MAP(byt_rt5640_quirk)]);
1487 byt_rt5640_card.long_name = byt_rt5640_long_name;
1490 /* override plaform name, if required */
1491 platform_name = mach->mach_params.platform;
1493 ret_val = snd_soc_fixup_dai_links_platform_name(&byt_rt5640_card,
1498 sof_parent = snd_soc_acpi_sof_parent(&pdev->dev);
1500 /* set card and driver name */
1502 byt_rt5640_card.name = SOF_CARD_NAME;
1503 byt_rt5640_card.driver_name = SOF_DRIVER_NAME;
1505 byt_rt5640_card.name = CARD_NAME;
1506 byt_rt5640_card.driver_name = DRIVER_NAME;
1511 dev->driver->pm = &snd_soc_pm_ops;
1513 ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card);
1516 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
1520 platform_set_drvdata(pdev, &byt_rt5640_card);
1524 static struct platform_driver snd_byt_rt5640_mc_driver = {
1526 .name = "bytcr_rt5640",
1528 .probe = snd_byt_rt5640_mc_probe,
1531 module_platform_driver(snd_byt_rt5640_mc_driver);
1533 MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
1534 MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
1535 MODULE_LICENSE("GPL v2");
1536 MODULE_ALIAS("platform:bytcr_rt5640");