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)
77 #define BYT_RT5640_LINEOUT_AS_HP2 BIT(26)
78 #define BYT_RT5640_HSMIC2_ON_IN1 BIT(27)
80 #define BYTCR_INPUT_DEFAULTS \
81 (BYT_RT5640_IN3_MAP | \
82 BYT_RT5640_JD_SRC_JD1_IN4P | \
83 BYT_RT5640_OVCD_TH_2000UA | \
84 BYT_RT5640_OVCD_SF_0P75 | \
87 /* in-diff or dmic-pin + jdsrc + ovcd-th + -sf + jd-inv + terminating entry */
88 #define MAX_NO_PROPS 6
90 struct byt_rt5640_private {
91 struct snd_soc_jack jack;
93 struct device *codec_dev;
97 static unsigned long byt_rt5640_quirk = BYT_RT5640_MCLK_EN;
98 static int quirk_override = -1;
99 module_param_named(quirk, quirk_override, int, 0444);
100 MODULE_PARM_DESC(quirk, "Board-specific quirk override");
102 static void log_quirks(struct device *dev)
105 bool has_mclk = false;
106 bool has_ssp0 = false;
107 bool has_ssp0_aif1 = false;
108 bool has_ssp0_aif2 = false;
109 bool has_ssp2_aif2 = false;
111 map = BYT_RT5640_MAP(byt_rt5640_quirk);
113 case BYT_RT5640_DMIC1_MAP:
114 dev_info(dev, "quirk DMIC1_MAP enabled\n");
116 case BYT_RT5640_DMIC2_MAP:
117 dev_info(dev, "quirk DMIC2_MAP enabled\n");
119 case BYT_RT5640_IN1_MAP:
120 dev_info(dev, "quirk IN1_MAP enabled\n");
122 case BYT_RT5640_IN3_MAP:
123 dev_info(dev, "quirk IN3_MAP enabled\n");
125 case BYT_RT5640_NO_INTERNAL_MIC_MAP:
126 dev_info(dev, "quirk NO_INTERNAL_MIC_MAP enabled\n");
129 dev_err(dev, "quirk map 0x%x is not supported, microphone input will not work\n", map);
132 if (byt_rt5640_quirk & BYT_RT5640_HSMIC2_ON_IN1)
133 dev_info(dev, "quirk HSMIC2_ON_IN1 enabled\n");
134 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
135 dev_info(dev, "quirk realtek,jack-detect-source %ld\n",
136 BYT_RT5640_JDSRC(byt_rt5640_quirk));
137 dev_info(dev, "quirk realtek,over-current-threshold-microamp %ld\n",
138 BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
139 dev_info(dev, "quirk realtek,over-current-scale-factor %ld\n",
140 BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
142 if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
143 dev_info(dev, "quirk JD_NOT_INV enabled\n");
144 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER)
145 dev_info(dev, "quirk MONO_SPEAKER enabled\n");
146 if (byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS)
147 dev_info(dev, "quirk NO_SPEAKERS enabled\n");
148 if (byt_rt5640_quirk & BYT_RT5640_LINEOUT)
149 dev_info(dev, "quirk LINEOUT enabled\n");
150 if (byt_rt5640_quirk & BYT_RT5640_LINEOUT_AS_HP2)
151 dev_info(dev, "quirk LINEOUT_AS_HP2 enabled\n");
152 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
153 dev_info(dev, "quirk DIFF_MIC enabled\n");
154 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
155 dev_info(dev, "quirk SSP0_AIF1 enabled\n");
157 has_ssp0_aif1 = true;
159 if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
160 dev_info(dev, "quirk SSP0_AIF2 enabled\n");
162 has_ssp0_aif2 = true;
164 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
165 dev_info(dev, "quirk SSP2_AIF2 enabled\n");
166 has_ssp2_aif2 = true;
168 if (is_bytcr && !has_ssp0)
169 dev_err(dev, "Invalid routing, bytcr detected but no SSP0-based quirk, audio cannot work with SSP2 on bytcr\n");
170 if (has_ssp0_aif1 && has_ssp0_aif2)
171 dev_err(dev, "Invalid routing, SSP0 cannot be connected to both AIF1 and AIF2\n");
172 if (has_ssp0 && has_ssp2_aif2)
173 dev_err(dev, "Invalid routing, cannot have both SSP0 and SSP2 connected to codec\n");
175 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
176 dev_info(dev, "quirk MCLK_EN enabled\n");
179 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
181 dev_info(dev, "quirk MCLK_25MHZ enabled\n");
183 dev_err(dev, "quirk MCLK_25MHZ enabled but quirk MCLK not selected, will be ignored\n");
187 static int byt_rt5640_prepare_and_enable_pll1(struct snd_soc_dai *codec_dai,
192 /* Configure the PLL before selecting it */
193 if (!(byt_rt5640_quirk & BYT_RT5640_MCLK_EN)) {
194 /* use bitclock as PLL input */
195 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
196 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
197 /* 2x16 bit slots on SSP0 */
198 ret = snd_soc_dai_set_pll(codec_dai, 0,
200 rate * 32, rate * 512);
202 /* 2x15 bit slots on SSP2 */
203 ret = snd_soc_dai_set_pll(codec_dai, 0,
205 rate * 50, rate * 512);
208 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ) {
209 ret = snd_soc_dai_set_pll(codec_dai, 0,
211 25000000, rate * 512);
213 ret = snd_soc_dai_set_pll(codec_dai, 0,
215 19200000, rate * 512);
220 dev_err(codec_dai->component->dev, "can't set pll: %d\n", ret);
224 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_PLL1,
225 rate * 512, SND_SOC_CLOCK_IN);
227 dev_err(codec_dai->component->dev, "can't set clock %d\n", ret);
234 #define BYT_CODEC_DAI1 "rt5640-aif1"
235 #define BYT_CODEC_DAI2 "rt5640-aif2"
237 static struct snd_soc_dai *byt_rt5640_get_codec_dai(struct snd_soc_dapm_context *dapm)
239 struct snd_soc_card *card = dapm->card;
240 struct snd_soc_dai *codec_dai;
242 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI1);
244 codec_dai = snd_soc_card_get_codec_dai(card, BYT_CODEC_DAI2);
246 dev_err(card->dev, "Error codec dai not found\n");
251 static int platform_clock_control(struct snd_soc_dapm_widget *w,
252 struct snd_kcontrol *k, int event)
254 struct snd_soc_dapm_context *dapm = w->dapm;
255 struct snd_soc_card *card = dapm->card;
256 struct snd_soc_dai *codec_dai;
257 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
260 codec_dai = byt_rt5640_get_codec_dai(dapm);
264 if (SND_SOC_DAPM_EVENT_ON(event)) {
265 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
266 ret = clk_prepare_enable(priv->mclk);
269 "could not configure MCLK state\n");
273 ret = byt_rt5640_prepare_and_enable_pll1(codec_dai, 48000);
276 * Set codec clock source to internal clock before
277 * turning off the platform clock. Codec needs clock
278 * for Jack detection and button press
280 ret = snd_soc_dai_set_sysclk(codec_dai, RT5640_SCLK_S_RCCLK,
284 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
285 clk_disable_unprepare(priv->mclk);
290 dev_err(card->dev, "can't set codec sysclk: %d\n", ret);
297 static int byt_rt5640_event_lineout(struct snd_soc_dapm_widget *w,
298 struct snd_kcontrol *k, int event)
300 unsigned int gpio_ctrl3_val = RT5640_GP1_PF_OUT;
301 struct snd_soc_dai *codec_dai;
303 if (!(byt_rt5640_quirk & BYT_RT5640_LINEOUT_AS_HP2))
307 * On devices which use line-out as a second headphones output,
308 * the codec's GPIO1 pin is used to enable an external HP-amp.
311 codec_dai = byt_rt5640_get_codec_dai(w->dapm);
315 if (SND_SOC_DAPM_EVENT_ON(event))
316 gpio_ctrl3_val |= RT5640_GP1_OUT_HI;
318 snd_soc_component_update_bits(codec_dai->component, RT5640_GPIO_CTRL3,
319 RT5640_GP1_PF_MASK | RT5640_GP1_OUT_MASK, gpio_ctrl3_val);
324 static const struct snd_soc_dapm_widget byt_rt5640_widgets[] = {
325 SND_SOC_DAPM_HP("Headphone", NULL),
326 SND_SOC_DAPM_MIC("Headset Mic", NULL),
327 SND_SOC_DAPM_MIC("Internal Mic", NULL),
328 SND_SOC_DAPM_SPK("Speaker", NULL),
329 SND_SOC_DAPM_LINE("Line Out", byt_rt5640_event_lineout),
330 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM, 0, 0,
331 platform_clock_control, SND_SOC_DAPM_PRE_PMU |
332 SND_SOC_DAPM_POST_PMD),
335 static const struct snd_soc_dapm_route byt_rt5640_audio_map[] = {
336 {"Headphone", NULL, "Platform Clock"},
337 {"Headset Mic", NULL, "Platform Clock"},
338 {"Headset Mic", NULL, "MICBIAS1"},
339 {"IN2P", NULL, "Headset Mic"},
340 {"Headphone", NULL, "HPOL"},
341 {"Headphone", NULL, "HPOR"},
344 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map[] = {
345 {"Internal Mic", NULL, "Platform Clock"},
346 {"DMIC1", NULL, "Internal Mic"},
349 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map[] = {
350 {"Internal Mic", NULL, "Platform Clock"},
351 {"DMIC2", NULL, "Internal Mic"},
354 static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map[] = {
355 {"Internal Mic", NULL, "Platform Clock"},
356 {"Internal Mic", NULL, "MICBIAS1"},
357 {"IN1P", NULL, "Internal Mic"},
360 static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map[] = {
361 {"Internal Mic", NULL, "Platform Clock"},
362 {"Internal Mic", NULL, "MICBIAS1"},
363 {"IN3P", NULL, "Internal Mic"},
366 static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map[] = {
367 {"ssp2 Tx", NULL, "codec_out0"},
368 {"ssp2 Tx", NULL, "codec_out1"},
369 {"codec_in0", NULL, "ssp2 Rx"},
370 {"codec_in1", NULL, "ssp2 Rx"},
372 {"AIF1 Playback", NULL, "ssp2 Tx"},
373 {"ssp2 Rx", NULL, "AIF1 Capture"},
376 static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_map[] = {
377 {"ssp2 Tx", NULL, "codec_out0"},
378 {"ssp2 Tx", NULL, "codec_out1"},
379 {"codec_in0", NULL, "ssp2 Rx"},
380 {"codec_in1", NULL, "ssp2 Rx"},
382 {"AIF2 Playback", NULL, "ssp2 Tx"},
383 {"ssp2 Rx", NULL, "AIF2 Capture"},
386 static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif1_map[] = {
387 {"ssp0 Tx", NULL, "modem_out"},
388 {"modem_in", NULL, "ssp0 Rx"},
390 {"AIF1 Playback", NULL, "ssp0 Tx"},
391 {"ssp0 Rx", NULL, "AIF1 Capture"},
394 static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif2_map[] = {
395 {"ssp0 Tx", NULL, "modem_out"},
396 {"modem_in", NULL, "ssp0 Rx"},
398 {"AIF2 Playback", NULL, "ssp0 Tx"},
399 {"ssp0 Rx", NULL, "AIF2 Capture"},
402 static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map[] = {
403 {"Speaker", NULL, "Platform Clock"},
404 {"Speaker", NULL, "SPOLP"},
405 {"Speaker", NULL, "SPOLN"},
406 {"Speaker", NULL, "SPORP"},
407 {"Speaker", NULL, "SPORN"},
410 static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map[] = {
411 {"Speaker", NULL, "Platform Clock"},
412 {"Speaker", NULL, "SPOLP"},
413 {"Speaker", NULL, "SPOLN"},
416 static const struct snd_soc_dapm_route byt_rt5640_lineout_map[] = {
417 {"Line Out", NULL, "Platform Clock"},
418 {"Line Out", NULL, "LOUTR"},
419 {"Line Out", NULL, "LOUTL"},
422 static const struct snd_kcontrol_new byt_rt5640_controls[] = {
423 SOC_DAPM_PIN_SWITCH("Headphone"),
424 SOC_DAPM_PIN_SWITCH("Headset Mic"),
425 SOC_DAPM_PIN_SWITCH("Internal Mic"),
426 SOC_DAPM_PIN_SWITCH("Speaker"),
427 SOC_DAPM_PIN_SWITCH("Line Out"),
430 static struct snd_soc_jack_pin rt5640_pins[] = {
433 .mask = SND_JACK_HEADPHONE,
436 .pin = "Headset Mic",
437 .mask = SND_JACK_MICROPHONE,
441 static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream *substream,
442 struct snd_pcm_hw_params *params)
444 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
445 struct snd_soc_dai *dai = asoc_rtd_to_codec(rtd, 0);
447 return byt_rt5640_prepare_and_enable_pll1(dai, params_rate(params));
450 /* Please keep this list alphabetically sorted */
451 static const struct dmi_system_id byt_rt5640_quirk_table[] = {
452 { /* Acer Iconia Tab 8 W1-810 */
454 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Acer"),
455 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Iconia W1-810"),
457 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
458 BYT_RT5640_JD_SRC_JD1_IN4P |
459 BYT_RT5640_OVCD_TH_1500UA |
460 BYT_RT5640_OVCD_SF_0P75 |
461 BYT_RT5640_SSP0_AIF1 |
464 { /* Acer One 10 S1002 */
466 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
467 DMI_MATCH(DMI_PRODUCT_NAME, "One S1002"),
469 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
470 BYT_RT5640_JD_SRC_JD2_IN4N |
471 BYT_RT5640_OVCD_TH_2000UA |
472 BYT_RT5640_OVCD_SF_0P75 |
473 BYT_RT5640_DIFF_MIC |
474 BYT_RT5640_SSP0_AIF2 |
479 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
480 DMI_MATCH(DMI_PRODUCT_NAME, "Aspire SW5-012"),
482 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
483 BYT_RT5640_JD_SRC_JD2_IN4N |
484 BYT_RT5640_OVCD_TH_2000UA |
485 BYT_RT5640_OVCD_SF_0P75 |
486 BYT_RT5640_SSP0_AIF1 |
491 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
492 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 80 Cesium"),
494 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
495 BYT_RT5640_MONO_SPEAKER |
496 BYT_RT5640_SSP0_AIF1 |
501 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ARCHOS"),
502 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ARCHOS 140 CESIUM"),
504 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
505 BYT_RT5640_JD_SRC_JD2_IN4N |
506 BYT_RT5640_OVCD_TH_2000UA |
507 BYT_RT5640_OVCD_SF_0P75 |
508 BYT_RT5640_SSP0_AIF1 |
513 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
514 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "ME176C"),
516 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
517 BYT_RT5640_JD_SRC_JD2_IN4N |
518 BYT_RT5640_OVCD_TH_2000UA |
519 BYT_RT5640_OVCD_SF_0P75 |
520 BYT_RT5640_SSP0_AIF1 |
525 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
526 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TA"),
528 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
529 BYT_RT5640_JD_SRC_JD2_IN4N |
530 BYT_RT5640_OVCD_TH_2000UA |
531 BYT_RT5640_OVCD_SF_0P75 |
536 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
537 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "T100TAF"),
539 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
540 BYT_RT5640_JD_SRC_JD2_IN4N |
541 BYT_RT5640_OVCD_TH_2000UA |
542 BYT_RT5640_OVCD_SF_0P75 |
543 BYT_RT5640_MONO_SPEAKER |
544 BYT_RT5640_DIFF_MIC |
545 BYT_RT5640_SSP0_AIF2 |
548 { /* Chuwi Vi8 (CWI506) */
550 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Insyde"),
551 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "i86"),
552 /* The above are too generic, also match BIOS info */
553 DMI_MATCH(DMI_BIOS_VERSION, "CHUWI.D86JLBNR"),
555 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
556 BYT_RT5640_MONO_SPEAKER |
557 BYT_RT5640_SSP0_AIF1 |
561 /* Chuwi Vi10 (CWI505) */
563 DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
564 DMI_MATCH(DMI_BOARD_NAME, "BYT-PF02"),
565 DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
566 DMI_MATCH(DMI_PRODUCT_NAME, "S165"),
568 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
569 BYT_RT5640_JD_SRC_JD2_IN4N |
570 BYT_RT5640_OVCD_TH_2000UA |
571 BYT_RT5640_OVCD_SF_0P75 |
572 BYT_RT5640_DIFF_MIC |
573 BYT_RT5640_SSP0_AIF1 |
577 /* Chuwi Hi8 (CWI509) */
579 DMI_MATCH(DMI_BOARD_VENDOR, "Hampoo"),
580 DMI_MATCH(DMI_BOARD_NAME, "BYT-PA03C"),
581 DMI_MATCH(DMI_SYS_VENDOR, "ilife"),
582 DMI_MATCH(DMI_PRODUCT_NAME, "S806"),
584 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
585 BYT_RT5640_JD_SRC_JD2_IN4N |
586 BYT_RT5640_OVCD_TH_2000UA |
587 BYT_RT5640_OVCD_SF_0P75 |
588 BYT_RT5640_MONO_SPEAKER |
589 BYT_RT5640_DIFF_MIC |
590 BYT_RT5640_SSP0_AIF1 |
595 DMI_MATCH(DMI_SYS_VENDOR, "Circuitco"),
596 DMI_MATCH(DMI_PRODUCT_NAME, "Minnowboard Max B3 PLATFORM"),
598 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP),
600 { /* Connect Tablet 9 */
602 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Connect"),
603 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Tablet 9"),
605 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
606 BYT_RT5640_MONO_SPEAKER |
607 BYT_RT5640_SSP0_AIF1 |
612 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
613 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "Venue 8 Pro 5830"),
615 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
616 BYT_RT5640_JD_SRC_JD2_IN4N |
617 BYT_RT5640_OVCD_TH_2000UA |
618 BYT_RT5640_OVCD_SF_0P75 |
619 BYT_RT5640_MONO_SPEAKER |
622 { /* Estar Beauty HD MID 7316R */
624 DMI_MATCH(DMI_SYS_VENDOR, "Estar"),
625 DMI_MATCH(DMI_PRODUCT_NAME, "eSTAR BEAUTY HD Intel Quad core"),
627 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
628 BYT_RT5640_MONO_SPEAKER |
629 BYT_RT5640_SSP0_AIF1 |
632 { /* Glavey TM800A550L */
634 DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
635 DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
636 /* Above strings are too generic, also match on BIOS version */
637 DMI_MATCH(DMI_BIOS_VERSION, "ZY-8-BI-PX4S70VTR400-X423B-005-D"),
639 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
640 BYT_RT5640_SSP0_AIF1 |
645 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
646 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP ElitePad 1000 G2"),
648 .driver_data = (void *)(BYT_RT5640_DMIC2_MAP |
651 BYT_RT5640_LINEOUT_AS_HP2 |
652 BYT_RT5640_HSMIC2_ON_IN1),
654 { /* HP Pavilion x2 10-k0XX, 10-n0XX */
656 DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
657 DMI_MATCH(DMI_PRODUCT_NAME, "HP Pavilion x2 Detachable"),
659 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
660 BYT_RT5640_JD_SRC_JD2_IN4N |
661 BYT_RT5640_OVCD_TH_1500UA |
662 BYT_RT5640_OVCD_SF_0P75 |
663 BYT_RT5640_SSP0_AIF1 |
666 { /* HP Pavilion x2 10-p0XX */
668 DMI_MATCH(DMI_SYS_VENDOR, "HP"),
669 DMI_MATCH(DMI_PRODUCT_NAME, "HP x2 Detachable 10-p0XX"),
671 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
672 BYT_RT5640_JD_SRC_JD1_IN4P |
673 BYT_RT5640_OVCD_TH_2000UA |
674 BYT_RT5640_OVCD_SF_0P75 |
679 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
680 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "HP Stream 7 Tablet"),
682 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
683 BYT_RT5640_MONO_SPEAKER |
684 BYT_RT5640_JD_NOT_INV |
685 BYT_RT5640_SSP0_AIF1 |
688 { /* I.T.Works TW891 */
690 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "To be filled by O.E.M."),
691 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TW891"),
692 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "To be filled by O.E.M."),
693 DMI_EXACT_MATCH(DMI_BOARD_NAME, "TW891"),
695 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
696 BYT_RT5640_MONO_SPEAKER |
697 BYT_RT5640_SSP0_AIF1 |
700 { /* Lamina I8270 / T701BR.SE */
702 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Lamina"),
703 DMI_EXACT_MATCH(DMI_BOARD_NAME, "T701BR.SE"),
705 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
706 BYT_RT5640_MONO_SPEAKER |
707 BYT_RT5640_JD_NOT_INV |
708 BYT_RT5640_SSP0_AIF1 |
711 { /* Lenovo Miix 2 8 */
713 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
714 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "20326"),
715 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Hiking"),
717 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
718 BYT_RT5640_JD_SRC_JD2_IN4N |
719 BYT_RT5640_OVCD_TH_2000UA |
720 BYT_RT5640_OVCD_SF_0P75 |
721 BYT_RT5640_MONO_SPEAKER |
724 { /* Lenovo Miix 3-830 */
726 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LENOVO"),
727 DMI_EXACT_MATCH(DMI_PRODUCT_VERSION, "Lenovo MIIX 3-830"),
729 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
730 BYT_RT5640_JD_SRC_JD2_IN4N |
731 BYT_RT5640_OVCD_TH_2000UA |
732 BYT_RT5640_OVCD_SF_0P75 |
733 BYT_RT5640_MONO_SPEAKER |
734 BYT_RT5640_DIFF_MIC |
735 BYT_RT5640_SSP0_AIF1 |
738 { /* Linx Linx7 tablet */
740 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "LINX"),
741 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "LINX7"),
743 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
744 BYT_RT5640_MONO_SPEAKER |
745 BYT_RT5640_JD_NOT_INV |
746 BYT_RT5640_SSP0_AIF1 |
749 { /* Mele PCG03 Mini PC */
751 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "Mini PC"),
752 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Mini PC"),
754 .driver_data = (void *)(BYT_RT5640_NO_INTERNAL_MIC_MAP |
755 BYT_RT5640_NO_SPEAKERS |
756 BYT_RT5640_SSP0_AIF1),
758 { /* MPMAN Converter 9, similar hw as the I.T.Works TW891 2-in-1 */
760 DMI_MATCH(DMI_SYS_VENDOR, "MPMAN"),
761 DMI_MATCH(DMI_PRODUCT_NAME, "Converter9"),
763 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
764 BYT_RT5640_MONO_SPEAKER |
765 BYT_RT5640_SSP0_AIF1 |
769 /* MPMAN MPWIN895CL */
771 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "MPMAN"),
772 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "MPWIN8900CL"),
774 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
775 BYT_RT5640_MONO_SPEAKER |
776 BYT_RT5640_SSP0_AIF1 |
779 { /* MSI S100 tablet */
781 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "Micro-Star International Co., Ltd."),
782 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "S100"),
784 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
785 BYT_RT5640_JD_SRC_JD2_IN4N |
786 BYT_RT5640_OVCD_TH_2000UA |
787 BYT_RT5640_OVCD_SF_0P75 |
788 BYT_RT5640_MONO_SPEAKER |
789 BYT_RT5640_DIFF_MIC |
792 { /* Nuvison/TMax TM800W560 */
794 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TMAX"),
795 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TM800W560L"),
797 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
798 BYT_RT5640_JD_SRC_JD2_IN4N |
799 BYT_RT5640_OVCD_TH_2000UA |
800 BYT_RT5640_OVCD_SF_0P75 |
801 BYT_RT5640_JD_NOT_INV |
802 BYT_RT5640_DIFF_MIC |
803 BYT_RT5640_SSP0_AIF1 |
808 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
809 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
810 /* The above are too generic, also match BIOS info */
811 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "5.6.5"),
812 DMI_EXACT_MATCH(DMI_BIOS_DATE, "07/25/2014"),
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 |
823 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
824 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
825 /* The above are too generic, also match BIOS info */
826 DMI_MATCH(DMI_BIOS_VERSION, "V8L_WIN32_CHIPHD"),
828 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
829 BYT_RT5640_MONO_SPEAKER |
830 BYT_RT5640_SSP0_AIF1 |
833 { /* Point of View Mobii TAB-P800W (V2.0) */
835 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
836 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
837 /* The above are too generic, also match BIOS info */
838 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1014"),
839 DMI_EXACT_MATCH(DMI_BIOS_DATE, "10/24/2014"),
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_MONO_SPEAKER |
846 BYT_RT5640_DIFF_MIC |
847 BYT_RT5640_SSP0_AIF2 |
850 { /* Point of View Mobii TAB-P800W (V2.1) */
852 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
853 DMI_EXACT_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
854 /* The above are too generic, also match BIOS info */
855 DMI_EXACT_MATCH(DMI_BIOS_VERSION, "3BAIR1013"),
856 DMI_EXACT_MATCH(DMI_BIOS_DATE, "08/22/2014"),
858 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
859 BYT_RT5640_JD_SRC_JD2_IN4N |
860 BYT_RT5640_OVCD_TH_2000UA |
861 BYT_RT5640_OVCD_SF_0P75 |
862 BYT_RT5640_MONO_SPEAKER |
863 BYT_RT5640_DIFF_MIC |
864 BYT_RT5640_SSP0_AIF2 |
867 { /* Point of View Mobii TAB-P1005W-232 (V2.0) */
869 DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "POV"),
870 DMI_EXACT_MATCH(DMI_BOARD_NAME, "I102A"),
872 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
873 BYT_RT5640_JD_SRC_JD2_IN4N |
874 BYT_RT5640_OVCD_TH_2000UA |
875 BYT_RT5640_OVCD_SF_0P75 |
876 BYT_RT5640_DIFF_MIC |
877 BYT_RT5640_SSP0_AIF1 |
883 DMI_MATCH(DMI_SYS_VENDOR, "Prowise"),
884 DMI_MATCH(DMI_PRODUCT_NAME, "PT301"),
886 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
887 BYT_RT5640_JD_SRC_JD2_IN4N |
888 BYT_RT5640_OVCD_TH_2000UA |
889 BYT_RT5640_OVCD_SF_0P75 |
890 BYT_RT5640_DIFF_MIC |
891 BYT_RT5640_SSP0_AIF1 |
897 DMI_MATCH(DMI_BOARD_VENDOR, "TECLAST"),
898 DMI_MATCH(DMI_BOARD_NAME, "tPAD"),
900 .driver_data = (void *)(BYT_RT5640_IN3_MAP |
901 BYT_RT5640_JD_SRC_JD1_IN4P |
902 BYT_RT5640_OVCD_TH_2000UA |
903 BYT_RT5640_OVCD_SF_1P0 |
904 BYT_RT5640_SSP0_AIF1 |
907 { /* Toshiba Satellite Click Mini L9W-B */
909 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
910 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "SATELLITE Click Mini L9W-B"),
912 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
913 BYT_RT5640_JD_SRC_JD2_IN4N |
914 BYT_RT5640_OVCD_TH_1500UA |
915 BYT_RT5640_OVCD_SF_0P75 |
916 BYT_RT5640_SSP0_AIF1 |
919 { /* Toshiba Encore WT8-A */
921 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
922 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT8-A"),
924 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
925 BYT_RT5640_JD_SRC_JD2_IN4N |
926 BYT_RT5640_OVCD_TH_2000UA |
927 BYT_RT5640_OVCD_SF_0P75 |
928 BYT_RT5640_JD_NOT_INV |
931 { /* Toshiba Encore WT10-A */
933 DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TOSHIBA"),
934 DMI_EXACT_MATCH(DMI_PRODUCT_NAME, "TOSHIBA WT10-A-103"),
936 .driver_data = (void *)(BYT_RT5640_DMIC1_MAP |
937 BYT_RT5640_JD_SRC_JD1_IN4P |
938 BYT_RT5640_OVCD_TH_2000UA |
939 BYT_RT5640_OVCD_SF_0P75 |
940 BYT_RT5640_SSP0_AIF2 |
943 { /* Voyo Winpad A15 */
945 DMI_MATCH(DMI_BOARD_VENDOR, "AMI Corporation"),
946 DMI_MATCH(DMI_BOARD_NAME, "Aptio CRB"),
947 /* Above strings are too generic, also match on BIOS date */
948 DMI_MATCH(DMI_BIOS_DATE, "11/20/2014"),
950 .driver_data = (void *)(BYT_RT5640_IN1_MAP |
951 BYT_RT5640_JD_SRC_JD2_IN4N |
952 BYT_RT5640_OVCD_TH_2000UA |
953 BYT_RT5640_OVCD_SF_0P75 |
954 BYT_RT5640_DIFF_MIC |
957 { /* Catch-all for generic Insyde tablets, must be last */
959 DMI_MATCH(DMI_SYS_VENDOR, "Insyde"),
961 .driver_data = (void *)(BYTCR_INPUT_DEFAULTS |
963 BYT_RT5640_SSP0_AIF1),
970 * Note this MUST be called before snd_soc_register_card(), so that the props
971 * are in place before the codec component driver's probe function parses them.
973 static int byt_rt5640_add_codec_device_props(struct device *i2c_dev,
974 struct byt_rt5640_private *priv)
976 struct property_entry props[MAX_NO_PROPS] = {};
977 struct fwnode_handle *fwnode;
981 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
982 case BYT_RT5640_DMIC1_MAP:
983 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic1-data-pin",
984 RT5640_DMIC1_DATA_PIN_IN1P);
986 case BYT_RT5640_DMIC2_MAP:
987 props[cnt++] = PROPERTY_ENTRY_U32("realtek,dmic2-data-pin",
988 RT5640_DMIC2_DATA_PIN_IN1N);
990 case BYT_RT5640_IN1_MAP:
991 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
993 PROPERTY_ENTRY_BOOL("realtek,in1-differential");
995 case BYT_RT5640_IN3_MAP:
996 if (byt_rt5640_quirk & BYT_RT5640_DIFF_MIC)
998 PROPERTY_ENTRY_BOOL("realtek,in3-differential");
1002 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
1003 props[cnt++] = PROPERTY_ENTRY_U32(
1004 "realtek,jack-detect-source",
1005 BYT_RT5640_JDSRC(byt_rt5640_quirk));
1007 props[cnt++] = PROPERTY_ENTRY_U32(
1008 "realtek,over-current-threshold-microamp",
1009 BYT_RT5640_OVCD_TH(byt_rt5640_quirk) * 100);
1011 props[cnt++] = PROPERTY_ENTRY_U32(
1012 "realtek,over-current-scale-factor",
1013 BYT_RT5640_OVCD_SF(byt_rt5640_quirk));
1016 if (byt_rt5640_quirk & BYT_RT5640_JD_NOT_INV)
1017 props[cnt++] = PROPERTY_ENTRY_BOOL("realtek,jack-detect-not-inverted");
1019 fwnode = fwnode_create_software_node(props, NULL);
1020 if (IS_ERR(fwnode)) {
1021 /* put_device() is handled in caller */
1022 return PTR_ERR(fwnode);
1025 ret = device_add_software_node(i2c_dev, to_software_node(fwnode));
1027 fwnode_handle_put(fwnode);
1032 static int byt_rt5640_init(struct snd_soc_pcm_runtime *runtime)
1034 struct snd_soc_card *card = runtime->card;
1035 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
1036 struct snd_soc_component *component = asoc_rtd_to_codec(runtime, 0)->component;
1037 const struct snd_soc_dapm_route *custom_map = NULL;
1041 card->dapm.idle_bias_off = true;
1043 /* Start with RC clk for jack-detect (we disable MCLK below) */
1044 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN)
1045 snd_soc_component_update_bits(component, RT5640_GLB_CLK,
1046 RT5640_SCLK_SRC_MASK, RT5640_SCLK_SRC_RCCLK);
1048 rt5640_sel_asrc_clk_src(component,
1049 RT5640_DA_STEREO_FILTER |
1050 RT5640_DA_MONO_L_FILTER |
1051 RT5640_DA_MONO_R_FILTER |
1052 RT5640_AD_STEREO_FILTER |
1053 RT5640_AD_MONO_L_FILTER |
1054 RT5640_AD_MONO_R_FILTER,
1055 RT5640_CLK_SEL_ASRC);
1057 ret = snd_soc_add_card_controls(card, byt_rt5640_controls,
1058 ARRAY_SIZE(byt_rt5640_controls));
1060 dev_err(card->dev, "unable to add card controls\n");
1064 switch (BYT_RT5640_MAP(byt_rt5640_quirk)) {
1065 case BYT_RT5640_IN1_MAP:
1066 custom_map = byt_rt5640_intmic_in1_map;
1067 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in1_map);
1069 case BYT_RT5640_IN3_MAP:
1070 custom_map = byt_rt5640_intmic_in3_map;
1071 num_routes = ARRAY_SIZE(byt_rt5640_intmic_in3_map);
1073 case BYT_RT5640_DMIC1_MAP:
1074 custom_map = byt_rt5640_intmic_dmic1_map;
1075 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic1_map);
1077 case BYT_RT5640_DMIC2_MAP:
1078 custom_map = byt_rt5640_intmic_dmic2_map;
1079 num_routes = ARRAY_SIZE(byt_rt5640_intmic_dmic2_map);
1083 ret = snd_soc_dapm_add_routes(&card->dapm, custom_map, num_routes);
1087 if (byt_rt5640_quirk & BYT_RT5640_HSMIC2_ON_IN1) {
1088 ret = snd_soc_dapm_add_routes(&card->dapm,
1089 byt_rt5640_intmic_in1_map,
1090 ARRAY_SIZE(byt_rt5640_intmic_in1_map));
1095 if (byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) {
1096 ret = snd_soc_dapm_add_routes(&card->dapm,
1097 byt_rt5640_ssp2_aif2_map,
1098 ARRAY_SIZE(byt_rt5640_ssp2_aif2_map));
1099 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) {
1100 ret = snd_soc_dapm_add_routes(&card->dapm,
1101 byt_rt5640_ssp0_aif1_map,
1102 ARRAY_SIZE(byt_rt5640_ssp0_aif1_map));
1103 } else if (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2) {
1104 ret = snd_soc_dapm_add_routes(&card->dapm,
1105 byt_rt5640_ssp0_aif2_map,
1106 ARRAY_SIZE(byt_rt5640_ssp0_aif2_map));
1108 ret = snd_soc_dapm_add_routes(&card->dapm,
1109 byt_rt5640_ssp2_aif1_map,
1110 ARRAY_SIZE(byt_rt5640_ssp2_aif1_map));
1115 if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
1116 ret = snd_soc_dapm_add_routes(&card->dapm,
1117 byt_rt5640_mono_spk_map,
1118 ARRAY_SIZE(byt_rt5640_mono_spk_map));
1119 } else if (!(byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS)) {
1120 ret = snd_soc_dapm_add_routes(&card->dapm,
1121 byt_rt5640_stereo_spk_map,
1122 ARRAY_SIZE(byt_rt5640_stereo_spk_map));
1127 if (byt_rt5640_quirk & BYT_RT5640_LINEOUT) {
1128 ret = snd_soc_dapm_add_routes(&card->dapm,
1129 byt_rt5640_lineout_map,
1130 ARRAY_SIZE(byt_rt5640_lineout_map));
1135 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
1137 * The firmware might enable the clock at
1138 * boot (this information may or may not
1139 * be reflected in the enable clock register).
1140 * To change the rate we must disable the clock
1141 * first to cover these cases. Due to common
1142 * clock framework restrictions that do not allow
1143 * to disable a clock that has not been enabled,
1144 * we need to enable the clock first.
1146 ret = clk_prepare_enable(priv->mclk);
1148 clk_disable_unprepare(priv->mclk);
1150 if (byt_rt5640_quirk & BYT_RT5640_MCLK_25MHZ)
1151 ret = clk_set_rate(priv->mclk, 25000000);
1153 ret = clk_set_rate(priv->mclk, 19200000);
1156 dev_err(card->dev, "unable to set MCLK rate\n");
1161 if (BYT_RT5640_JDSRC(byt_rt5640_quirk)) {
1162 ret = snd_soc_card_jack_new(card, "Headset",
1163 SND_JACK_HEADSET | SND_JACK_BTN_0,
1164 &priv->jack, rt5640_pins,
1165 ARRAY_SIZE(rt5640_pins));
1167 dev_err(card->dev, "Jack creation failed %d\n", ret);
1170 snd_jack_set_key(priv->jack.jack, SND_JACK_BTN_0,
1172 snd_soc_component_set_jack(component, &priv->jack, NULL);
1178 static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime *rtd,
1179 struct snd_pcm_hw_params *params)
1181 struct snd_interval *rate = hw_param_interval(params,
1182 SNDRV_PCM_HW_PARAM_RATE);
1183 struct snd_interval *channels = hw_param_interval(params,
1184 SNDRV_PCM_HW_PARAM_CHANNELS);
1187 /* The DSP will covert the FE rate to 48k, stereo */
1188 rate->min = rate->max = 48000;
1189 channels->min = channels->max = 2;
1191 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
1192 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
1193 /* set SSP0 to 16-bit */
1194 params_set_format(params, SNDRV_PCM_FORMAT_S16_LE);
1197 /* set SSP2 to 24-bit */
1198 params_set_format(params, SNDRV_PCM_FORMAT_S24_LE);
1203 * Default mode for SSP configuration is TDM 4 slot, override config
1204 * with explicit setting to I2S 2ch. The word length is set with
1205 * dai_set_tdm_slot() since there is no other API exposed
1207 ret = snd_soc_dai_set_fmt(asoc_rtd_to_cpu(rtd, 0),
1208 SND_SOC_DAIFMT_I2S |
1209 SND_SOC_DAIFMT_NB_NF |
1210 SND_SOC_DAIFMT_CBS_CFS);
1212 dev_err(rtd->dev, "can't set format to I2S, err %d\n", ret);
1216 ret = snd_soc_dai_set_tdm_slot(asoc_rtd_to_cpu(rtd, 0), 0x3, 0x3, 2, bits);
1218 dev_err(rtd->dev, "can't set I2S config, err %d\n", ret);
1225 static int byt_rt5640_aif1_startup(struct snd_pcm_substream *substream)
1227 return snd_pcm_hw_constraint_single(substream->runtime,
1228 SNDRV_PCM_HW_PARAM_RATE, 48000);
1231 static const struct snd_soc_ops byt_rt5640_aif1_ops = {
1232 .startup = byt_rt5640_aif1_startup,
1235 static const struct snd_soc_ops byt_rt5640_be_ssp2_ops = {
1236 .hw_params = byt_rt5640_aif1_hw_params,
1239 SND_SOC_DAILINK_DEF(dummy,
1240 DAILINK_COMP_ARRAY(COMP_DUMMY()));
1242 SND_SOC_DAILINK_DEF(media,
1243 DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
1245 SND_SOC_DAILINK_DEF(deepbuffer,
1246 DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
1248 SND_SOC_DAILINK_DEF(ssp2_port,
1249 /* overwritten for ssp0 routing */
1250 DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));
1251 SND_SOC_DAILINK_DEF(ssp2_codec,
1252 DAILINK_COMP_ARRAY(COMP_CODEC(
1253 /* overwritten with HID */ "i2c-10EC5640:00",
1254 /* changed w/ quirk */ "rt5640-aif1")));
1256 SND_SOC_DAILINK_DEF(platform,
1257 DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
1259 static struct snd_soc_dai_link byt_rt5640_dais[] = {
1260 [MERR_DPCM_AUDIO] = {
1261 .name = "Baytrail Audio Port",
1262 .stream_name = "Baytrail Audio",
1267 .ops = &byt_rt5640_aif1_ops,
1268 SND_SOC_DAILINK_REG(media, dummy, platform),
1270 [MERR_DPCM_DEEP_BUFFER] = {
1271 .name = "Deep-Buffer Audio Port",
1272 .stream_name = "Deep-Buffer Audio",
1276 .ops = &byt_rt5640_aif1_ops,
1277 SND_SOC_DAILINK_REG(deepbuffer, dummy, platform),
1281 .name = "SSP2-Codec",
1284 .dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_NB_NF
1285 | SND_SOC_DAIFMT_CBS_CFS,
1286 .be_hw_params_fixup = byt_rt5640_codec_fixup,
1289 .init = byt_rt5640_init,
1290 .ops = &byt_rt5640_be_ssp2_ops,
1291 SND_SOC_DAILINK_REG(ssp2_port, ssp2_codec, platform),
1296 static char byt_rt5640_codec_name[SND_ACPI_I2C_ID_LEN];
1297 #if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
1298 static char byt_rt5640_long_name[40]; /* = "bytcr-rt5640-*-spk-*-mic" */
1300 static char byt_rt5640_components[64]; /* = "cfg-spk:* cfg-mic:* ..." */
1302 static int byt_rt5640_suspend(struct snd_soc_card *card)
1304 struct snd_soc_component *component;
1306 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1309 for_each_card_components(card, component) {
1310 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1311 dev_dbg(component->dev, "disabling jack detect before suspend\n");
1312 snd_soc_component_set_jack(component, NULL, NULL);
1320 static int byt_rt5640_resume(struct snd_soc_card *card)
1322 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
1323 struct snd_soc_component *component;
1325 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk))
1328 for_each_card_components(card, component) {
1329 if (!strcmp(component->name, byt_rt5640_codec_name)) {
1330 dev_dbg(component->dev, "re-enabling jack detect after resume\n");
1331 snd_soc_component_set_jack(component, &priv->jack, NULL);
1339 /* use space before codec name to simplify card ID, and simplify driver name */
1340 #define SOF_CARD_NAME "bytcht rt5640" /* card name will be 'sof-bytcht rt5640' */
1341 #define SOF_DRIVER_NAME "SOF"
1343 #define CARD_NAME "bytcr-rt5640"
1344 #define DRIVER_NAME NULL /* card name will be used for driver name */
1346 static struct snd_soc_card byt_rt5640_card = {
1347 .owner = THIS_MODULE,
1348 .dai_link = byt_rt5640_dais,
1349 .num_links = ARRAY_SIZE(byt_rt5640_dais),
1350 .dapm_widgets = byt_rt5640_widgets,
1351 .num_dapm_widgets = ARRAY_SIZE(byt_rt5640_widgets),
1352 .dapm_routes = byt_rt5640_audio_map,
1353 .num_dapm_routes = ARRAY_SIZE(byt_rt5640_audio_map),
1354 .fully_routed = true,
1355 .suspend_pre = byt_rt5640_suspend,
1356 .resume_post = byt_rt5640_resume,
1359 struct acpi_chan_package { /* ACPICA seems to require 64 bit integers */
1360 u64 aif_value; /* 1: AIF1, 2: AIF2 */
1361 u64 mclock_value; /* usually 25MHz (0x17d7940), ignored */
1364 static int snd_byt_rt5640_mc_probe(struct platform_device *pdev)
1366 struct device *dev = &pdev->dev;
1367 static const char * const map_name[] = { "dmic1", "dmic2", "in1", "in3", "none" };
1368 __maybe_unused const char *spk_type;
1369 const struct dmi_system_id *dmi_id;
1370 const char *headset2_string = "";
1371 const char *lineout_string = "";
1372 struct byt_rt5640_private *priv;
1373 struct snd_soc_acpi_mach *mach;
1374 const char *platform_name;
1375 struct acpi_device *adev;
1376 struct device *codec_dev;
1384 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
1388 /* register the soc card */
1389 byt_rt5640_card.dev = &pdev->dev;
1390 mach = byt_rt5640_card.dev->platform_data;
1391 snd_soc_card_set_drvdata(&byt_rt5640_card, priv);
1393 /* fix index of codec dai */
1394 for (i = 0; i < ARRAY_SIZE(byt_rt5640_dais); i++) {
1395 if (!strcmp(byt_rt5640_dais[i].codecs->name,
1396 "i2c-10EC5640:00")) {
1402 /* fixup codec name based on HID */
1403 adev = acpi_dev_get_first_match_dev(mach->id, NULL, -1);
1405 snprintf(byt_rt5640_codec_name, sizeof(byt_rt5640_codec_name),
1406 "i2c-%s", acpi_dev_name(adev));
1407 put_device(&adev->dev);
1408 byt_rt5640_dais[dai_index].codecs->name = byt_rt5640_codec_name;
1410 dev_err(&pdev->dev, "Error cannot find '%s' dev\n", mach->id);
1415 * swap SSP0 if bytcr is detected
1416 * (will be overridden if DMI quirk is detected)
1418 if (soc_intel_is_byt()) {
1419 if (mach->mach_params.acpi_ipc_irq_index == 0)
1425 * Baytrail CR platforms may have CHAN package in BIOS, try
1426 * to find relevant routing quirk based as done on Windows
1427 * platforms. We have to read the information directly from the
1428 * BIOS, at this stage the card is not created and the links
1429 * with the codec driver/pdata are non-existent
1432 struct acpi_chan_package chan_package;
1434 /* format specified: 2 64-bit integers */
1435 struct acpi_buffer format = {sizeof("NN"), "NN"};
1436 struct acpi_buffer state = {0, NULL};
1437 struct snd_soc_acpi_package_context pkg_ctx;
1438 bool pkg_found = false;
1440 state.length = sizeof(chan_package);
1441 state.pointer = &chan_package;
1443 pkg_ctx.name = "CHAN";
1445 pkg_ctx.format = &format;
1446 pkg_ctx.state = &state;
1447 pkg_ctx.data_valid = false;
1449 pkg_found = snd_soc_acpi_find_package_from_hid(mach->id,
1452 if (chan_package.aif_value == 1) {
1453 dev_info(&pdev->dev, "BIOS Routing: AIF1 connected\n");
1454 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF1;
1455 } else if (chan_package.aif_value == 2) {
1456 dev_info(&pdev->dev, "BIOS Routing: AIF2 connected\n");
1457 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1459 dev_info(&pdev->dev, "BIOS Routing isn't valid, ignored\n");
1465 /* no BIOS indications, assume SSP0-AIF2 connection */
1466 byt_rt5640_quirk |= BYT_RT5640_SSP0_AIF2;
1469 /* change defaults for Baytrail-CR capture */
1470 byt_rt5640_quirk |= BYTCR_INPUT_DEFAULTS;
1472 byt_rt5640_quirk |= BYT_RT5640_DMIC1_MAP |
1473 BYT_RT5640_JD_SRC_JD2_IN4N |
1474 BYT_RT5640_OVCD_TH_2000UA |
1475 BYT_RT5640_OVCD_SF_0P75;
1478 /* check quirks before creating card */
1479 dmi_id = dmi_first_match(byt_rt5640_quirk_table);
1481 byt_rt5640_quirk = (unsigned long)dmi_id->driver_data;
1482 if (quirk_override != -1) {
1483 dev_info(&pdev->dev, "Overriding quirk 0x%lx => 0x%x\n",
1484 byt_rt5640_quirk, quirk_override);
1485 byt_rt5640_quirk = quirk_override;
1488 codec_dev = acpi_get_first_physical_node(adev);
1490 return -EPROBE_DEFER;
1491 priv->codec_dev = get_device(codec_dev);
1493 /* Must be called before register_card, also see declaration comment. */
1494 ret_val = byt_rt5640_add_codec_device_props(codec_dev, priv);
1498 log_quirks(&pdev->dev);
1500 if ((byt_rt5640_quirk & BYT_RT5640_SSP2_AIF2) ||
1501 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2)) {
1502 byt_rt5640_dais[dai_index].codecs->dai_name = "rt5640-aif2";
1508 if ((byt_rt5640_quirk & BYT_RT5640_SSP0_AIF1) ||
1509 (byt_rt5640_quirk & BYT_RT5640_SSP0_AIF2))
1510 byt_rt5640_dais[dai_index].cpus->dai_name = "ssp0-port";
1512 if (byt_rt5640_quirk & BYT_RT5640_MCLK_EN) {
1513 priv->mclk = devm_clk_get(&pdev->dev, "pmc_plt_clk_3");
1514 if (IS_ERR(priv->mclk)) {
1515 ret_val = PTR_ERR(priv->mclk);
1518 "Failed to get MCLK from pmc_plt_clk_3: %d\n",
1522 * Fall back to bit clock usage for -ENOENT (clock not
1523 * available likely due to missing dependencies), bail
1524 * for all other errors, including -EPROBE_DEFER
1526 if (ret_val != -ENOENT)
1528 byt_rt5640_quirk &= ~BYT_RT5640_MCLK_EN;
1532 if (byt_rt5640_quirk & BYT_RT5640_NO_SPEAKERS) {
1535 } else if (byt_rt5640_quirk & BYT_RT5640_MONO_SPEAKER) {
1540 spk_type = "stereo";
1543 if (byt_rt5640_quirk & BYT_RT5640_LINEOUT) {
1544 if (byt_rt5640_quirk & BYT_RT5640_LINEOUT_AS_HP2)
1545 lineout_string = " cfg-hp2:lineout";
1547 lineout_string = " cfg-lineout:1";
1550 if (byt_rt5640_quirk & BYT_RT5640_HSMIC2_ON_IN1)
1551 headset2_string = " cfg-hs2:in1";
1553 snprintf(byt_rt5640_components, sizeof(byt_rt5640_components),
1554 "cfg-spk:%d cfg-mic:%s aif:%d%s%s", cfg_spk,
1555 map_name[BYT_RT5640_MAP(byt_rt5640_quirk)], aif,
1556 lineout_string, headset2_string);
1557 byt_rt5640_card.components = byt_rt5640_components;
1558 #if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
1559 snprintf(byt_rt5640_long_name, sizeof(byt_rt5640_long_name),
1560 "bytcr-rt5640-%s-spk-%s-mic", spk_type,
1561 map_name[BYT_RT5640_MAP(byt_rt5640_quirk)]);
1562 byt_rt5640_card.long_name = byt_rt5640_long_name;
1565 /* override plaform name, if required */
1566 platform_name = mach->mach_params.platform;
1568 ret_val = snd_soc_fixup_dai_links_platform_name(&byt_rt5640_card,
1573 sof_parent = snd_soc_acpi_sof_parent(&pdev->dev);
1575 /* set card and driver name */
1577 byt_rt5640_card.name = SOF_CARD_NAME;
1578 byt_rt5640_card.driver_name = SOF_DRIVER_NAME;
1580 byt_rt5640_card.name = CARD_NAME;
1581 byt_rt5640_card.driver_name = DRIVER_NAME;
1586 dev->driver->pm = &snd_soc_pm_ops;
1588 ret_val = devm_snd_soc_register_card(&pdev->dev, &byt_rt5640_card);
1591 dev_err(&pdev->dev, "devm_snd_soc_register_card failed %d\n",
1595 platform_set_drvdata(pdev, &byt_rt5640_card);
1599 device_remove_software_node(priv->codec_dev);
1601 put_device(priv->codec_dev);
1605 static int snd_byt_rt5640_mc_remove(struct platform_device *pdev)
1607 struct snd_soc_card *card = platform_get_drvdata(pdev);
1608 struct byt_rt5640_private *priv = snd_soc_card_get_drvdata(card);
1610 device_remove_software_node(priv->codec_dev);
1611 put_device(priv->codec_dev);
1615 static struct platform_driver snd_byt_rt5640_mc_driver = {
1617 .name = "bytcr_rt5640",
1619 .probe = snd_byt_rt5640_mc_probe,
1620 .remove = snd_byt_rt5640_mc_remove,
1623 module_platform_driver(snd_byt_rt5640_mc_driver);
1625 MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
1626 MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
1627 MODULE_LICENSE("GPL v2");
1628 MODULE_ALIAS("platform:bytcr_rt5640");