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/sst-dsp.h"
32 #include "../common/soc-intel-quirks.h"
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)
76 #define BYTCR_INPUT_DEFAULTS \
77 (BYT_RT5640_IN3_MAP | \
78 BYT_RT5640_JD_SRC_JD1_IN4P | \
79 BYT_RT5640_OVCD_TH_2000UA | \
80 BYT_RT5640_OVCD_SF_0P75 | \
83 /* in-diff or dmic-pin + jdsrc + ovcd-th + -sf + jd-inv + terminating entry */
84 #define MAX_NO_PROPS 6
86 struct byt_rt5640_private
{
87 struct snd_soc_jack jack
;
92 static unsigned long byt_rt5640_quirk
= BYT_RT5640_MCLK_EN
;
93 static int quirk_override
= -1;
94 module_param_named(quirk
, quirk_override
, int, 0444);
95 MODULE_PARM_DESC(quirk
, "Board-specific quirk override");
97 static void log_quirks(struct device
*dev
)
100 bool has_mclk
= false;
101 bool has_ssp0
= false;
102 bool has_ssp0_aif1
= false;
103 bool has_ssp0_aif2
= false;
104 bool has_ssp2_aif2
= false;
106 map
= BYT_RT5640_MAP(byt_rt5640_quirk
);
108 case BYT_RT5640_DMIC1_MAP
:
109 dev_info(dev
, "quirk DMIC1_MAP enabled\n");
111 case BYT_RT5640_DMIC2_MAP
:
112 dev_info(dev
, "quirk DMIC2_MAP enabled\n");
114 case BYT_RT5640_IN1_MAP
:
115 dev_info(dev
, "quirk IN1_MAP enabled\n");
117 case BYT_RT5640_IN3_MAP
:
118 dev_info(dev
, "quirk IN3_MAP enabled\n");
121 dev_err(dev
, "quirk map 0x%x is not supported, microphone input will not work\n", map
);
124 if (BYT_RT5640_JDSRC(byt_rt5640_quirk
)) {
125 dev_info(dev
, "quirk realtek,jack-detect-source %ld\n",
126 BYT_RT5640_JDSRC(byt_rt5640_quirk
));
127 dev_info(dev
, "quirk realtek,over-current-threshold-microamp %ld\n",
128 BYT_RT5640_OVCD_TH(byt_rt5640_quirk
) * 100);
129 dev_info(dev
, "quirk realtek,over-current-scale-factor %ld\n",
130 BYT_RT5640_OVCD_SF(byt_rt5640_quirk
));
132 if (byt_rt5640_quirk
& BYT_RT5640_JD_NOT_INV
)
133 dev_info(dev
, "quirk JD_NOT_INV enabled\n");
134 if (byt_rt5640_quirk
& BYT_RT5640_MONO_SPEAKER
)
135 dev_info(dev
, "quirk MONO_SPEAKER enabled\n");
136 if (byt_rt5640_quirk
& BYT_RT5640_DIFF_MIC
)
137 dev_info(dev
, "quirk DIFF_MIC enabled\n");
138 if (byt_rt5640_quirk
& BYT_RT5640_SSP0_AIF1
) {
139 dev_info(dev
, "quirk SSP0_AIF1 enabled\n");
141 has_ssp0_aif1
= true;
143 if (byt_rt5640_quirk
& BYT_RT5640_SSP0_AIF2
) {
144 dev_info(dev
, "quirk SSP0_AIF2 enabled\n");
146 has_ssp0_aif2
= true;
148 if (byt_rt5640_quirk
& BYT_RT5640_SSP2_AIF2
) {
149 dev_info(dev
, "quirk SSP2_AIF2 enabled\n");
150 has_ssp2_aif2
= true;
152 if (is_bytcr
&& !has_ssp0
)
153 dev_err(dev
, "Invalid routing, bytcr detected but no SSP0-based quirk, audio cannot work with SSP2 on bytcr\n");
154 if (has_ssp0_aif1
&& has_ssp0_aif2
)
155 dev_err(dev
, "Invalid routing, SSP0 cannot be connected to both AIF1 and AIF2\n");
156 if (has_ssp0
&& has_ssp2_aif2
)
157 dev_err(dev
, "Invalid routing, cannot have both SSP0 and SSP2 connected to codec\n");
159 if (byt_rt5640_quirk
& BYT_RT5640_MCLK_EN
) {
160 dev_info(dev
, "quirk MCLK_EN enabled\n");
163 if (byt_rt5640_quirk
& BYT_RT5640_MCLK_25MHZ
) {
165 dev_info(dev
, "quirk MCLK_25MHZ enabled\n");
167 dev_err(dev
, "quirk MCLK_25MHZ enabled but quirk MCLK not selected, will be ignored\n");
171 static int byt_rt5640_prepare_and_enable_pll1(struct snd_soc_dai
*codec_dai
,
176 /* Configure the PLL before selecting it */
177 if (!(byt_rt5640_quirk
& BYT_RT5640_MCLK_EN
)) {
178 /* use bitclock as PLL input */
179 if ((byt_rt5640_quirk
& BYT_RT5640_SSP0_AIF1
) ||
180 (byt_rt5640_quirk
& BYT_RT5640_SSP0_AIF2
)) {
181 /* 2x16 bit slots on SSP0 */
182 ret
= snd_soc_dai_set_pll(codec_dai
, 0,
184 rate
* 32, rate
* 512);
186 /* 2x15 bit slots on SSP2 */
187 ret
= snd_soc_dai_set_pll(codec_dai
, 0,
189 rate
* 50, rate
* 512);
192 if (byt_rt5640_quirk
& BYT_RT5640_MCLK_25MHZ
) {
193 ret
= snd_soc_dai_set_pll(codec_dai
, 0,
195 25000000, rate
* 512);
197 ret
= snd_soc_dai_set_pll(codec_dai
, 0,
199 19200000, rate
* 512);
204 dev_err(codec_dai
->component
->dev
, "can't set pll: %d\n", ret
);
208 ret
= snd_soc_dai_set_sysclk(codec_dai
, RT5640_SCLK_S_PLL1
,
209 rate
* 512, SND_SOC_CLOCK_IN
);
211 dev_err(codec_dai
->component
->dev
, "can't set clock %d\n", ret
);
218 #define BYT_CODEC_DAI1 "rt5640-aif1"
219 #define BYT_CODEC_DAI2 "rt5640-aif2"
221 static int platform_clock_control(struct snd_soc_dapm_widget
*w
,
222 struct snd_kcontrol
*k
, int event
)
224 struct snd_soc_dapm_context
*dapm
= w
->dapm
;
225 struct snd_soc_card
*card
= dapm
->card
;
226 struct snd_soc_dai
*codec_dai
;
227 struct byt_rt5640_private
*priv
= snd_soc_card_get_drvdata(card
);
230 codec_dai
= snd_soc_card_get_codec_dai(card
, BYT_CODEC_DAI1
);
232 codec_dai
= snd_soc_card_get_codec_dai(card
, BYT_CODEC_DAI2
);
236 "Codec dai not found; Unable to set platform clock\n");
240 if (SND_SOC_DAPM_EVENT_ON(event
)) {
241 if (byt_rt5640_quirk
& BYT_RT5640_MCLK_EN
) {
242 ret
= clk_prepare_enable(priv
->mclk
);
245 "could not configure MCLK state\n");
249 ret
= byt_rt5640_prepare_and_enable_pll1(codec_dai
, 48000);
252 * Set codec clock source to internal clock before
253 * turning off the platform clock. Codec needs clock
254 * for Jack detection and button press
256 ret
= snd_soc_dai_set_sysclk(codec_dai
, RT5640_SCLK_S_RCCLK
,
260 if (byt_rt5640_quirk
& BYT_RT5640_MCLK_EN
)
261 clk_disable_unprepare(priv
->mclk
);
266 dev_err(card
->dev
, "can't set codec sysclk: %d\n", ret
);
273 static const struct snd_soc_dapm_widget byt_rt5640_widgets
[] = {
274 SND_SOC_DAPM_HP("Headphone", NULL
),
275 SND_SOC_DAPM_MIC("Headset Mic", NULL
),
276 SND_SOC_DAPM_MIC("Internal Mic", NULL
),
277 SND_SOC_DAPM_SPK("Speaker", NULL
),
278 SND_SOC_DAPM_SUPPLY("Platform Clock", SND_SOC_NOPM
, 0, 0,
279 platform_clock_control
, SND_SOC_DAPM_PRE_PMU
|
280 SND_SOC_DAPM_POST_PMD
),
284 static const struct snd_soc_dapm_route byt_rt5640_audio_map
[] = {
285 {"Headphone", NULL
, "Platform Clock"},
286 {"Headset Mic", NULL
, "Platform Clock"},
287 {"Internal Mic", NULL
, "Platform Clock"},
288 {"Speaker", NULL
, "Platform Clock"},
290 {"Headset Mic", NULL
, "MICBIAS1"},
291 {"IN2P", NULL
, "Headset Mic"},
292 {"Headphone", NULL
, "HPOL"},
293 {"Headphone", NULL
, "HPOR"},
296 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic1_map
[] = {
297 {"DMIC1", NULL
, "Internal Mic"},
300 static const struct snd_soc_dapm_route byt_rt5640_intmic_dmic2_map
[] = {
301 {"DMIC2", NULL
, "Internal Mic"},
304 static const struct snd_soc_dapm_route byt_rt5640_intmic_in1_map
[] = {
305 {"Internal Mic", NULL
, "MICBIAS1"},
306 {"IN1P", NULL
, "Internal Mic"},
309 static const struct snd_soc_dapm_route byt_rt5640_intmic_in3_map
[] = {
310 {"Internal Mic", NULL
, "MICBIAS1"},
311 {"IN3P", NULL
, "Internal Mic"},
314 static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif1_map
[] = {
315 {"ssp2 Tx", NULL
, "codec_out0"},
316 {"ssp2 Tx", NULL
, "codec_out1"},
317 {"codec_in0", NULL
, "ssp2 Rx"},
318 {"codec_in1", NULL
, "ssp2 Rx"},
320 {"AIF1 Playback", NULL
, "ssp2 Tx"},
321 {"ssp2 Rx", NULL
, "AIF1 Capture"},
324 static const struct snd_soc_dapm_route byt_rt5640_ssp2_aif2_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 {"AIF2 Playback", NULL
, "ssp2 Tx"},
331 {"ssp2 Rx", NULL
, "AIF2 Capture"},
334 static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif1_map
[] = {
335 {"ssp0 Tx", NULL
, "modem_out"},
336 {"modem_in", NULL
, "ssp0 Rx"},
338 {"AIF1 Playback", NULL
, "ssp0 Tx"},
339 {"ssp0 Rx", NULL
, "AIF1 Capture"},
342 static const struct snd_soc_dapm_route byt_rt5640_ssp0_aif2_map
[] = {
343 {"ssp0 Tx", NULL
, "modem_out"},
344 {"modem_in", NULL
, "ssp0 Rx"},
346 {"AIF2 Playback", NULL
, "ssp0 Tx"},
347 {"ssp0 Rx", NULL
, "AIF2 Capture"},
350 static const struct snd_soc_dapm_route byt_rt5640_stereo_spk_map
[] = {
351 {"Speaker", NULL
, "SPOLP"},
352 {"Speaker", NULL
, "SPOLN"},
353 {"Speaker", NULL
, "SPORP"},
354 {"Speaker", NULL
, "SPORN"},
357 static const struct snd_soc_dapm_route byt_rt5640_mono_spk_map
[] = {
358 {"Speaker", NULL
, "SPOLP"},
359 {"Speaker", NULL
, "SPOLN"},
362 static const struct snd_kcontrol_new byt_rt5640_controls
[] = {
363 SOC_DAPM_PIN_SWITCH("Headphone"),
364 SOC_DAPM_PIN_SWITCH("Headset Mic"),
365 SOC_DAPM_PIN_SWITCH("Internal Mic"),
366 SOC_DAPM_PIN_SWITCH("Speaker"),
369 static struct snd_soc_jack_pin rt5640_pins
[] = {
372 .mask
= SND_JACK_HEADPHONE
,
375 .pin
= "Headset Mic",
376 .mask
= SND_JACK_MICROPHONE
,
380 static int byt_rt5640_aif1_hw_params(struct snd_pcm_substream
*substream
,
381 struct snd_pcm_hw_params
*params
)
383 struct snd_soc_pcm_runtime
*rtd
= substream
->private_data
;
384 struct snd_soc_dai
*dai
= rtd
->codec_dai
;
386 return byt_rt5640_prepare_and_enable_pll1(dai
, params_rate(params
));
389 /* Please keep this list alphabetically sorted */
390 static const struct dmi_system_id byt_rt5640_quirk_table
[] = {
391 { /* Acer Iconia Tab 8 W1-810 */
393 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "Acer"),
394 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "Iconia W1-810"),
396 .driver_data
= (void *)(BYT_RT5640_DMIC1_MAP
|
397 BYT_RT5640_JD_SRC_JD1_IN4P
|
398 BYT_RT5640_OVCD_TH_1500UA
|
399 BYT_RT5640_OVCD_SF_0P75
|
400 BYT_RT5640_SSP0_AIF1
|
405 DMI_MATCH(DMI_SYS_VENDOR
, "Acer"),
406 DMI_MATCH(DMI_PRODUCT_NAME
, "Aspire SW5-012"),
408 .driver_data
= (void *)(BYT_RT5640_DMIC1_MAP
|
409 BYT_RT5640_JD_SRC_JD2_IN4N
|
410 BYT_RT5640_OVCD_TH_2000UA
|
411 BYT_RT5640_OVCD_SF_0P75
|
412 BYT_RT5640_SSP0_AIF1
|
417 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "ARCHOS"),
418 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "ARCHOS 80 Cesium"),
420 .driver_data
= (void *)(BYTCR_INPUT_DEFAULTS
|
421 BYT_RT5640_MONO_SPEAKER
|
422 BYT_RT5640_SSP0_AIF1
|
427 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "ASUSTeK COMPUTER INC."),
428 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "ME176C"),
430 .driver_data
= (void *)(BYT_RT5640_IN1_MAP
|
431 BYT_RT5640_JD_SRC_JD2_IN4N
|
432 BYT_RT5640_OVCD_TH_2000UA
|
433 BYT_RT5640_OVCD_SF_0P75
|
434 BYT_RT5640_SSP0_AIF1
|
439 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "ASUSTeK COMPUTER INC."),
440 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "T100TA"),
442 .driver_data
= (void *)(BYT_RT5640_IN1_MAP
|
443 BYT_RT5640_JD_SRC_JD2_IN4N
|
444 BYT_RT5640_OVCD_TH_2000UA
|
445 BYT_RT5640_OVCD_SF_0P75
|
450 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "ASUSTeK COMPUTER INC."),
451 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "T100TAF"),
453 .driver_data
= (void *)(BYT_RT5640_IN1_MAP
|
454 BYT_RT5640_MONO_SPEAKER
|
455 BYT_RT5640_DIFF_MIC
|
456 BYT_RT5640_SSP0_AIF2
|
459 { /* Chuwi Vi8 (CWI506) */
461 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "Insyde"),
462 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "i86"),
463 /* The above are too generic, also match BIOS info */
464 DMI_MATCH(DMI_BIOS_VERSION
, "CHUWI.D86JLBNR"),
466 .driver_data
= (void *)(BYTCR_INPUT_DEFAULTS
|
467 BYT_RT5640_MONO_SPEAKER
|
468 BYT_RT5640_SSP0_AIF1
|
472 /* Chuwi Vi10 (CWI505) */
474 DMI_MATCH(DMI_BOARD_VENDOR
, "Hampoo"),
475 DMI_MATCH(DMI_BOARD_NAME
, "BYT-PF02"),
476 DMI_MATCH(DMI_SYS_VENDOR
, "ilife"),
477 DMI_MATCH(DMI_PRODUCT_NAME
, "S165"),
479 .driver_data
= (void *)(BYT_RT5640_IN1_MAP
|
480 BYT_RT5640_JD_SRC_JD2_IN4N
|
481 BYT_RT5640_OVCD_TH_2000UA
|
482 BYT_RT5640_OVCD_SF_0P75
|
483 BYT_RT5640_DIFF_MIC
|
484 BYT_RT5640_SSP0_AIF1
|
489 DMI_MATCH(DMI_SYS_VENDOR
, "Circuitco"),
490 DMI_MATCH(DMI_PRODUCT_NAME
, "Minnowboard Max B3 PLATFORM"),
492 .driver_data
= (void *)(BYT_RT5640_DMIC1_MAP
),
494 { /* Connect Tablet 9 */
496 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "Connect"),
497 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "Tablet 9"),
499 .driver_data
= (void *)(BYTCR_INPUT_DEFAULTS
|
500 BYT_RT5640_MONO_SPEAKER
|
501 BYT_RT5640_SSP0_AIF1
|
506 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "Dell Inc."),
507 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "Venue 8 Pro 5830"),
509 .driver_data
= (void *)(BYT_RT5640_DMIC1_MAP
|
510 BYT_RT5640_JD_SRC_JD2_IN4N
|
511 BYT_RT5640_OVCD_TH_2000UA
|
512 BYT_RT5640_OVCD_SF_0P75
|
513 BYT_RT5640_MONO_SPEAKER
|
518 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "Hewlett-Packard"),
519 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "HP ElitePad 1000 G2"),
521 .driver_data
= (void *)(BYT_RT5640_IN1_MAP
|
524 { /* HP Pavilion x2 10-n000nd */
526 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "Hewlett-Packard"),
527 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "HP Pavilion x2 Detachable"),
529 .driver_data
= (void *)(BYT_RT5640_DMIC1_MAP
|
530 BYT_RT5640_JD_SRC_JD2_IN4N
|
531 BYT_RT5640_OVCD_TH_1500UA
|
532 BYT_RT5640_OVCD_SF_0P75
|
533 BYT_RT5640_SSP0_AIF1
|
538 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "Hewlett-Packard"),
539 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "HP Stream 7 Tablet"),
541 .driver_data
= (void *)(BYTCR_INPUT_DEFAULTS
|
542 BYT_RT5640_MONO_SPEAKER
|
543 BYT_RT5640_JD_NOT_INV
|
544 BYT_RT5640_SSP0_AIF1
|
547 { /* I.T.Works TW891 */
549 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "To be filled by O.E.M."),
550 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "TW891"),
551 DMI_EXACT_MATCH(DMI_BOARD_VENDOR
, "To be filled by O.E.M."),
552 DMI_EXACT_MATCH(DMI_BOARD_NAME
, "TW891"),
554 .driver_data
= (void *)(BYTCR_INPUT_DEFAULTS
|
555 BYT_RT5640_MONO_SPEAKER
|
556 BYT_RT5640_SSP0_AIF1
|
559 { /* Lamina I8270 / T701BR.SE */
561 DMI_EXACT_MATCH(DMI_BOARD_VENDOR
, "Lamina"),
562 DMI_EXACT_MATCH(DMI_BOARD_NAME
, "T701BR.SE"),
564 .driver_data
= (void *)(BYTCR_INPUT_DEFAULTS
|
565 BYT_RT5640_MONO_SPEAKER
|
566 BYT_RT5640_JD_NOT_INV
|
567 BYT_RT5640_SSP0_AIF1
|
570 { /* Lenovo Miix 2 8 */
572 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "LENOVO"),
573 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "20326"),
574 DMI_EXACT_MATCH(DMI_BOARD_NAME
, "Hiking"),
576 .driver_data
= (void *)(BYT_RT5640_DMIC1_MAP
|
577 BYT_RT5640_JD_SRC_JD2_IN4N
|
578 BYT_RT5640_OVCD_TH_2000UA
|
579 BYT_RT5640_OVCD_SF_0P75
|
580 BYT_RT5640_MONO_SPEAKER
|
583 { /* Linx Linx7 tablet */
585 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "LINX"),
586 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "LINX7"),
588 .driver_data
= (void *)(BYTCR_INPUT_DEFAULTS
|
589 BYT_RT5640_MONO_SPEAKER
|
590 BYT_RT5640_JD_NOT_INV
|
591 BYT_RT5640_SSP0_AIF1
|
594 { /* MSI S100 tablet */
596 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "Micro-Star International Co., Ltd."),
597 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "S100"),
599 .driver_data
= (void *)(BYT_RT5640_IN1_MAP
|
600 BYT_RT5640_JD_SRC_JD2_IN4N
|
601 BYT_RT5640_OVCD_TH_2000UA
|
602 BYT_RT5640_OVCD_SF_0P75
|
603 BYT_RT5640_MONO_SPEAKER
|
604 BYT_RT5640_DIFF_MIC
|
607 { /* Nuvison/TMax TM800W560 */
609 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "TMAX"),
610 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "TM800W560L"),
612 .driver_data
= (void *)(BYT_RT5640_IN1_MAP
|
613 BYT_RT5640_JD_SRC_JD2_IN4N
|
614 BYT_RT5640_OVCD_TH_2000UA
|
615 BYT_RT5640_OVCD_SF_0P75
|
616 BYT_RT5640_JD_NOT_INV
|
617 BYT_RT5640_DIFF_MIC
|
618 BYT_RT5640_SSP0_AIF1
|
623 DMI_EXACT_MATCH(DMI_BOARD_VENDOR
, "AMI Corporation"),
624 DMI_EXACT_MATCH(DMI_BOARD_NAME
, "Aptio CRB"),
625 /* The above are too generic, also match BIOS info */
626 DMI_EXACT_MATCH(DMI_BIOS_VERSION
, "5.6.5"),
627 DMI_EXACT_MATCH(DMI_BIOS_DATE
, "07/25/2014"),
629 .driver_data
= (void *)(BYT_RT5640_IN1_MAP
|
630 BYT_RT5640_JD_SRC_JD2_IN4N
|
631 BYT_RT5640_OVCD_TH_2000UA
|
632 BYT_RT5640_OVCD_SF_0P75
|
633 BYT_RT5640_DIFF_MIC
|
638 DMI_EXACT_MATCH(DMI_BOARD_VENDOR
, "AMI Corporation"),
639 DMI_EXACT_MATCH(DMI_BOARD_NAME
, "Aptio CRB"),
640 /* The above are too generic, also match BIOS info */
641 DMI_MATCH(DMI_BIOS_VERSION
, "V8L_WIN32_CHIPHD"),
643 .driver_data
= (void *)(BYTCR_INPUT_DEFAULTS
|
644 BYT_RT5640_MONO_SPEAKER
|
645 BYT_RT5640_SSP0_AIF1
|
648 { /* Point of View Mobii TAB-P800W (V2.0) */
650 DMI_EXACT_MATCH(DMI_BOARD_VENDOR
, "AMI Corporation"),
651 DMI_EXACT_MATCH(DMI_BOARD_NAME
, "Aptio CRB"),
652 /* The above are too generic, also match BIOS info */
653 DMI_EXACT_MATCH(DMI_BIOS_VERSION
, "3BAIR1014"),
654 DMI_EXACT_MATCH(DMI_BIOS_DATE
, "10/24/2014"),
656 .driver_data
= (void *)(BYT_RT5640_IN1_MAP
|
657 BYT_RT5640_JD_SRC_JD2_IN4N
|
658 BYT_RT5640_OVCD_TH_2000UA
|
659 BYT_RT5640_OVCD_SF_0P75
|
660 BYT_RT5640_MONO_SPEAKER
|
661 BYT_RT5640_DIFF_MIC
|
662 BYT_RT5640_SSP0_AIF2
|
665 { /* Point of View Mobii TAB-P800W (V2.1) */
667 DMI_EXACT_MATCH(DMI_BOARD_VENDOR
, "AMI Corporation"),
668 DMI_EXACT_MATCH(DMI_BOARD_NAME
, "Aptio CRB"),
669 /* The above are too generic, also match BIOS info */
670 DMI_EXACT_MATCH(DMI_BIOS_VERSION
, "3BAIR1013"),
671 DMI_EXACT_MATCH(DMI_BIOS_DATE
, "08/22/2014"),
673 .driver_data
= (void *)(BYT_RT5640_IN1_MAP
|
674 BYT_RT5640_JD_SRC_JD2_IN4N
|
675 BYT_RT5640_OVCD_TH_2000UA
|
676 BYT_RT5640_OVCD_SF_0P75
|
677 BYT_RT5640_MONO_SPEAKER
|
678 BYT_RT5640_DIFF_MIC
|
679 BYT_RT5640_SSP0_AIF2
|
682 { /* Point of View Mobii TAB-P1005W-232 (V2.0) */
684 DMI_EXACT_MATCH(DMI_BOARD_VENDOR
, "POV"),
685 DMI_EXACT_MATCH(DMI_BOARD_NAME
, "I102A"),
687 .driver_data
= (void *)(BYT_RT5640_IN1_MAP
|
688 BYT_RT5640_JD_SRC_JD2_IN4N
|
689 BYT_RT5640_OVCD_TH_2000UA
|
690 BYT_RT5640_OVCD_SF_0P75
|
691 BYT_RT5640_DIFF_MIC
|
692 BYT_RT5640_SSP0_AIF1
|
698 DMI_MATCH(DMI_SYS_VENDOR
, "Prowise"),
699 DMI_MATCH(DMI_PRODUCT_NAME
, "PT301"),
701 .driver_data
= (void *)(BYT_RT5640_IN1_MAP
|
702 BYT_RT5640_JD_SRC_JD2_IN4N
|
703 BYT_RT5640_OVCD_TH_2000UA
|
704 BYT_RT5640_OVCD_SF_0P75
|
705 BYT_RT5640_DIFF_MIC
|
706 BYT_RT5640_SSP0_AIF1
|
712 DMI_MATCH(DMI_BOARD_VENDOR
, "TECLAST"),
713 DMI_MATCH(DMI_BOARD_NAME
, "tPAD"),
715 .driver_data
= (void *)(BYT_RT5640_IN3_MAP
|
716 BYT_RT5640_JD_SRC_JD1_IN4P
|
717 BYT_RT5640_OVCD_TH_2000UA
|
718 BYT_RT5640_OVCD_SF_1P0
|
719 BYT_RT5640_SSP0_AIF1
|
722 { /* Toshiba Satellite Click Mini L9W-B */
724 DMI_EXACT_MATCH(DMI_SYS_VENDOR
, "TOSHIBA"),
725 DMI_EXACT_MATCH(DMI_PRODUCT_NAME
, "SATELLITE Click Mini L9W-B"),
727 .driver_data
= (void *)(BYT_RT5640_DMIC1_MAP
|
728 BYT_RT5640_JD_SRC_JD2_IN4N
|
729 BYT_RT5640_OVCD_TH_1500UA
|
730 BYT_RT5640_OVCD_SF_0P75
|
731 BYT_RT5640_SSP0_AIF1
|
734 { /* Catch-all for generic Insyde tablets, must be last */
736 DMI_MATCH(DMI_SYS_VENDOR
, "Insyde"),
738 .driver_data
= (void *)(BYTCR_INPUT_DEFAULTS
|
740 BYT_RT5640_SSP0_AIF1
),
747 * Note this MUST be called before snd_soc_register_card(), so that the props
748 * are in place before the codec component driver's probe function parses them.
750 static int byt_rt5640_add_codec_device_props(const char *i2c_dev_name
)
752 struct property_entry props
[MAX_NO_PROPS
] = {};
753 struct device
*i2c_dev
;
756 i2c_dev
= bus_find_device_by_name(&i2c_bus_type
, NULL
, i2c_dev_name
);
758 return -EPROBE_DEFER
;
760 switch (BYT_RT5640_MAP(byt_rt5640_quirk
)) {
761 case BYT_RT5640_DMIC1_MAP
:
762 props
[cnt
++] = PROPERTY_ENTRY_U32("realtek,dmic1-data-pin",
763 RT5640_DMIC1_DATA_PIN_IN1P
);
765 case BYT_RT5640_DMIC2_MAP
:
766 props
[cnt
++] = PROPERTY_ENTRY_U32("realtek,dmic2-data-pin",
767 RT5640_DMIC2_DATA_PIN_IN1N
);
769 case BYT_RT5640_IN1_MAP
:
770 if (byt_rt5640_quirk
& BYT_RT5640_DIFF_MIC
)
772 PROPERTY_ENTRY_BOOL("realtek,in1-differential");
774 case BYT_RT5640_IN3_MAP
:
775 if (byt_rt5640_quirk
& BYT_RT5640_DIFF_MIC
)
777 PROPERTY_ENTRY_BOOL("realtek,in3-differential");
781 if (BYT_RT5640_JDSRC(byt_rt5640_quirk
)) {
782 props
[cnt
++] = PROPERTY_ENTRY_U32(
783 "realtek,jack-detect-source",
784 BYT_RT5640_JDSRC(byt_rt5640_quirk
));
786 props
[cnt
++] = PROPERTY_ENTRY_U32(
787 "realtek,over-current-threshold-microamp",
788 BYT_RT5640_OVCD_TH(byt_rt5640_quirk
) * 100);
790 props
[cnt
++] = PROPERTY_ENTRY_U32(
791 "realtek,over-current-scale-factor",
792 BYT_RT5640_OVCD_SF(byt_rt5640_quirk
));
795 if (byt_rt5640_quirk
& BYT_RT5640_JD_NOT_INV
)
796 props
[cnt
++] = PROPERTY_ENTRY_BOOL("realtek,jack-detect-not-inverted");
798 ret
= device_add_properties(i2c_dev
, props
);
804 static int byt_rt5640_init(struct snd_soc_pcm_runtime
*runtime
)
806 struct snd_soc_card
*card
= runtime
->card
;
807 struct byt_rt5640_private
*priv
= snd_soc_card_get_drvdata(card
);
808 struct snd_soc_component
*component
= runtime
->codec_dai
->component
;
809 const struct snd_soc_dapm_route
*custom_map
;
813 card
->dapm
.idle_bias_off
= true;
815 /* Start with RC clk for jack-detect (we disable MCLK below) */
816 if (byt_rt5640_quirk
& BYT_RT5640_MCLK_EN
)
817 snd_soc_component_update_bits(component
, RT5640_GLB_CLK
,
818 RT5640_SCLK_SRC_MASK
, RT5640_SCLK_SRC_RCCLK
);
820 rt5640_sel_asrc_clk_src(component
,
821 RT5640_DA_STEREO_FILTER
|
822 RT5640_DA_MONO_L_FILTER
|
823 RT5640_DA_MONO_R_FILTER
|
824 RT5640_AD_STEREO_FILTER
|
825 RT5640_AD_MONO_L_FILTER
|
826 RT5640_AD_MONO_R_FILTER
,
827 RT5640_CLK_SEL_ASRC
);
829 ret
= snd_soc_add_card_controls(card
, byt_rt5640_controls
,
830 ARRAY_SIZE(byt_rt5640_controls
));
832 dev_err(card
->dev
, "unable to add card controls\n");
836 switch (BYT_RT5640_MAP(byt_rt5640_quirk
)) {
837 case BYT_RT5640_IN1_MAP
:
838 custom_map
= byt_rt5640_intmic_in1_map
;
839 num_routes
= ARRAY_SIZE(byt_rt5640_intmic_in1_map
);
841 case BYT_RT5640_IN3_MAP
:
842 custom_map
= byt_rt5640_intmic_in3_map
;
843 num_routes
= ARRAY_SIZE(byt_rt5640_intmic_in3_map
);
845 case BYT_RT5640_DMIC2_MAP
:
846 custom_map
= byt_rt5640_intmic_dmic2_map
;
847 num_routes
= ARRAY_SIZE(byt_rt5640_intmic_dmic2_map
);
850 custom_map
= byt_rt5640_intmic_dmic1_map
;
851 num_routes
= ARRAY_SIZE(byt_rt5640_intmic_dmic1_map
);
854 ret
= snd_soc_dapm_add_routes(&card
->dapm
, custom_map
, num_routes
);
858 if (byt_rt5640_quirk
& BYT_RT5640_SSP2_AIF2
) {
859 ret
= snd_soc_dapm_add_routes(&card
->dapm
,
860 byt_rt5640_ssp2_aif2_map
,
861 ARRAY_SIZE(byt_rt5640_ssp2_aif2_map
));
862 } else if (byt_rt5640_quirk
& BYT_RT5640_SSP0_AIF1
) {
863 ret
= snd_soc_dapm_add_routes(&card
->dapm
,
864 byt_rt5640_ssp0_aif1_map
,
865 ARRAY_SIZE(byt_rt5640_ssp0_aif1_map
));
866 } else if (byt_rt5640_quirk
& BYT_RT5640_SSP0_AIF2
) {
867 ret
= snd_soc_dapm_add_routes(&card
->dapm
,
868 byt_rt5640_ssp0_aif2_map
,
869 ARRAY_SIZE(byt_rt5640_ssp0_aif2_map
));
871 ret
= snd_soc_dapm_add_routes(&card
->dapm
,
872 byt_rt5640_ssp2_aif1_map
,
873 ARRAY_SIZE(byt_rt5640_ssp2_aif1_map
));
878 if (byt_rt5640_quirk
& BYT_RT5640_MONO_SPEAKER
) {
879 ret
= snd_soc_dapm_add_routes(&card
->dapm
,
880 byt_rt5640_mono_spk_map
,
881 ARRAY_SIZE(byt_rt5640_mono_spk_map
));
883 ret
= snd_soc_dapm_add_routes(&card
->dapm
,
884 byt_rt5640_stereo_spk_map
,
885 ARRAY_SIZE(byt_rt5640_stereo_spk_map
));
890 snd_soc_dapm_ignore_suspend(&card
->dapm
, "Headphone");
891 snd_soc_dapm_ignore_suspend(&card
->dapm
, "Speaker");
893 if (byt_rt5640_quirk
& BYT_RT5640_MCLK_EN
) {
895 * The firmware might enable the clock at
896 * boot (this information may or may not
897 * be reflected in the enable clock register).
898 * To change the rate we must disable the clock
899 * first to cover these cases. Due to common
900 * clock framework restrictions that do not allow
901 * to disable a clock that has not been enabled,
902 * we need to enable the clock first.
904 ret
= clk_prepare_enable(priv
->mclk
);
906 clk_disable_unprepare(priv
->mclk
);
908 if (byt_rt5640_quirk
& BYT_RT5640_MCLK_25MHZ
)
909 ret
= clk_set_rate(priv
->mclk
, 25000000);
911 ret
= clk_set_rate(priv
->mclk
, 19200000);
914 dev_err(card
->dev
, "unable to set MCLK rate\n");
919 if (BYT_RT5640_JDSRC(byt_rt5640_quirk
)) {
920 ret
= snd_soc_card_jack_new(card
, "Headset",
921 SND_JACK_HEADSET
| SND_JACK_BTN_0
,
922 &priv
->jack
, rt5640_pins
,
923 ARRAY_SIZE(rt5640_pins
));
925 dev_err(card
->dev
, "Jack creation failed %d\n", ret
);
928 snd_jack_set_key(priv
->jack
.jack
, SND_JACK_BTN_0
,
930 snd_soc_component_set_jack(component
, &priv
->jack
, NULL
);
936 static int byt_rt5640_codec_fixup(struct snd_soc_pcm_runtime
*rtd
,
937 struct snd_pcm_hw_params
*params
)
939 struct snd_interval
*rate
= hw_param_interval(params
,
940 SNDRV_PCM_HW_PARAM_RATE
);
941 struct snd_interval
*channels
= hw_param_interval(params
,
942 SNDRV_PCM_HW_PARAM_CHANNELS
);
945 /* The DSP will covert the FE rate to 48k, stereo */
946 rate
->min
= rate
->max
= 48000;
947 channels
->min
= channels
->max
= 2;
949 if ((byt_rt5640_quirk
& BYT_RT5640_SSP0_AIF1
) ||
950 (byt_rt5640_quirk
& BYT_RT5640_SSP0_AIF2
)) {
951 /* set SSP0 to 16-bit */
952 params_set_format(params
, SNDRV_PCM_FORMAT_S16_LE
);
955 /* set SSP2 to 24-bit */
956 params_set_format(params
, SNDRV_PCM_FORMAT_S24_LE
);
961 * Default mode for SSP configuration is TDM 4 slot, override config
962 * with explicit setting to I2S 2ch. The word length is set with
963 * dai_set_tdm_slot() since there is no other API exposed
965 ret
= snd_soc_dai_set_fmt(rtd
->cpu_dai
,
967 SND_SOC_DAIFMT_NB_NF
|
968 SND_SOC_DAIFMT_CBS_CFS
);
970 dev_err(rtd
->dev
, "can't set format to I2S, err %d\n", ret
);
974 ret
= snd_soc_dai_set_tdm_slot(rtd
->cpu_dai
, 0x3, 0x3, 2, bits
);
976 dev_err(rtd
->dev
, "can't set I2S config, err %d\n", ret
);
983 static int byt_rt5640_aif1_startup(struct snd_pcm_substream
*substream
)
985 return snd_pcm_hw_constraint_single(substream
->runtime
,
986 SNDRV_PCM_HW_PARAM_RATE
, 48000);
989 static const struct snd_soc_ops byt_rt5640_aif1_ops
= {
990 .startup
= byt_rt5640_aif1_startup
,
993 static const struct snd_soc_ops byt_rt5640_be_ssp2_ops
= {
994 .hw_params
= byt_rt5640_aif1_hw_params
,
997 SND_SOC_DAILINK_DEF(dummy
,
998 DAILINK_COMP_ARRAY(COMP_DUMMY()));
1000 SND_SOC_DAILINK_DEF(media
,
1001 DAILINK_COMP_ARRAY(COMP_CPU("media-cpu-dai")));
1003 SND_SOC_DAILINK_DEF(deepbuffer
,
1004 DAILINK_COMP_ARRAY(COMP_CPU("deepbuffer-cpu-dai")));
1006 SND_SOC_DAILINK_DEF(ssp2_port
,
1007 /* overwritten for ssp0 routing */
1008 DAILINK_COMP_ARRAY(COMP_CPU("ssp2-port")));
1009 SND_SOC_DAILINK_DEF(ssp2_codec
,
1010 DAILINK_COMP_ARRAY(COMP_CODEC(
1011 /* overwritten with HID */ "i2c-10EC5640:00",
1012 /* changed w/ quirk */ "rt5640-aif1")));
1014 SND_SOC_DAILINK_DEF(platform
,
1015 DAILINK_COMP_ARRAY(COMP_PLATFORM("sst-mfld-platform")));
1017 static struct snd_soc_dai_link byt_rt5640_dais
[] = {
1018 [MERR_DPCM_AUDIO
] = {
1019 .name
= "Baytrail Audio Port",
1020 .stream_name
= "Baytrail Audio",
1025 .ops
= &byt_rt5640_aif1_ops
,
1026 SND_SOC_DAILINK_REG(media
, dummy
, platform
),
1028 [MERR_DPCM_DEEP_BUFFER
] = {
1029 .name
= "Deep-Buffer Audio Port",
1030 .stream_name
= "Deep-Buffer Audio",
1034 .ops
= &byt_rt5640_aif1_ops
,
1035 SND_SOC_DAILINK_REG(deepbuffer
, dummy
, platform
),
1039 .name
= "SSP2-Codec",
1042 .dai_fmt
= SND_SOC_DAIFMT_I2S
| SND_SOC_DAIFMT_NB_NF
1043 | SND_SOC_DAIFMT_CBS_CFS
,
1044 .be_hw_params_fixup
= byt_rt5640_codec_fixup
,
1045 .ignore_suspend
= 1,
1049 .init
= byt_rt5640_init
,
1050 .ops
= &byt_rt5640_be_ssp2_ops
,
1051 SND_SOC_DAILINK_REG(ssp2_port
, ssp2_codec
, platform
),
1056 static char byt_rt5640_codec_name
[SND_ACPI_I2C_ID_LEN
];
1057 #if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
1058 static char byt_rt5640_long_name
[40]; /* = "bytcr-rt5640-*-spk-*-mic" */
1060 static char byt_rt5640_components
[32]; /* = "cfg-spk:* cfg-mic:*" */
1062 static int byt_rt5640_suspend(struct snd_soc_card
*card
)
1064 struct snd_soc_component
*component
;
1066 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk
))
1069 for_each_card_components(card
, component
) {
1070 if (!strcmp(component
->name
, byt_rt5640_codec_name
)) {
1071 dev_dbg(component
->dev
, "disabling jack detect before suspend\n");
1072 snd_soc_component_set_jack(component
, NULL
, NULL
);
1080 static int byt_rt5640_resume(struct snd_soc_card
*card
)
1082 struct byt_rt5640_private
*priv
= snd_soc_card_get_drvdata(card
);
1083 struct snd_soc_component
*component
;
1085 if (!BYT_RT5640_JDSRC(byt_rt5640_quirk
))
1088 for_each_card_components(card
, component
) {
1089 if (!strcmp(component
->name
, byt_rt5640_codec_name
)) {
1090 dev_dbg(component
->dev
, "re-enabling jack detect after resume\n");
1091 snd_soc_component_set_jack(component
, &priv
->jack
, NULL
);
1099 static struct snd_soc_card byt_rt5640_card
= {
1100 .name
= "bytcr-rt5640",
1101 .owner
= THIS_MODULE
,
1102 .dai_link
= byt_rt5640_dais
,
1103 .num_links
= ARRAY_SIZE(byt_rt5640_dais
),
1104 .dapm_widgets
= byt_rt5640_widgets
,
1105 .num_dapm_widgets
= ARRAY_SIZE(byt_rt5640_widgets
),
1106 .dapm_routes
= byt_rt5640_audio_map
,
1107 .num_dapm_routes
= ARRAY_SIZE(byt_rt5640_audio_map
),
1108 .fully_routed
= true,
1109 .suspend_pre
= byt_rt5640_suspend
,
1110 .resume_post
= byt_rt5640_resume
,
1113 struct acpi_chan_package
{ /* ACPICA seems to require 64 bit integers */
1114 u64 aif_value
; /* 1: AIF1, 2: AIF2 */
1115 u64 mclock_value
; /* usually 25MHz (0x17d7940), ignored */
1118 static int snd_byt_rt5640_mc_probe(struct platform_device
*pdev
)
1120 static const char * const map_name
[] = { "dmic1", "dmic2", "in1", "in3" };
1121 const struct dmi_system_id
*dmi_id
;
1122 struct byt_rt5640_private
*priv
;
1123 struct snd_soc_acpi_mach
*mach
;
1124 const char *platform_name
;
1125 struct acpi_device
*adev
;
1131 priv
= devm_kzalloc(&pdev
->dev
, sizeof(*priv
), GFP_KERNEL
);
1135 /* register the soc card */
1136 byt_rt5640_card
.dev
= &pdev
->dev
;
1137 mach
= byt_rt5640_card
.dev
->platform_data
;
1138 snd_soc_card_set_drvdata(&byt_rt5640_card
, priv
);
1140 /* fix index of codec dai */
1141 for (i
= 0; i
< ARRAY_SIZE(byt_rt5640_dais
); i
++) {
1142 if (!strcmp(byt_rt5640_dais
[i
].codecs
->name
,
1143 "i2c-10EC5640:00")) {
1149 /* fixup codec name based on HID */
1150 adev
= acpi_dev_get_first_match_dev(mach
->id
, NULL
, -1);
1152 snprintf(byt_rt5640_codec_name
, sizeof(byt_rt5640_codec_name
),
1153 "i2c-%s", acpi_dev_name(adev
));
1154 put_device(&adev
->dev
);
1155 byt_rt5640_dais
[dai_index
].codecs
->name
= byt_rt5640_codec_name
;
1159 * swap SSP0 if bytcr is detected
1160 * (will be overridden if DMI quirk is detected)
1162 if (soc_intel_is_byt()) {
1163 if (mach
->mach_params
.acpi_ipc_irq_index
== 0)
1169 * Baytrail CR platforms may have CHAN package in BIOS, try
1170 * to find relevant routing quirk based as done on Windows
1171 * platforms. We have to read the information directly from the
1172 * BIOS, at this stage the card is not created and the links
1173 * with the codec driver/pdata are non-existent
1176 struct acpi_chan_package chan_package
;
1178 /* format specified: 2 64-bit integers */
1179 struct acpi_buffer format
= {sizeof("NN"), "NN"};
1180 struct acpi_buffer state
= {0, NULL
};
1181 struct snd_soc_acpi_package_context pkg_ctx
;
1182 bool pkg_found
= false;
1184 state
.length
= sizeof(chan_package
);
1185 state
.pointer
= &chan_package
;
1187 pkg_ctx
.name
= "CHAN";
1189 pkg_ctx
.format
= &format
;
1190 pkg_ctx
.state
= &state
;
1191 pkg_ctx
.data_valid
= false;
1193 pkg_found
= snd_soc_acpi_find_package_from_hid(mach
->id
,
1196 if (chan_package
.aif_value
== 1) {
1197 dev_info(&pdev
->dev
, "BIOS Routing: AIF1 connected\n");
1198 byt_rt5640_quirk
|= BYT_RT5640_SSP0_AIF1
;
1199 } else if (chan_package
.aif_value
== 2) {
1200 dev_info(&pdev
->dev
, "BIOS Routing: AIF2 connected\n");
1201 byt_rt5640_quirk
|= BYT_RT5640_SSP0_AIF2
;
1203 dev_info(&pdev
->dev
, "BIOS Routing isn't valid, ignored\n");
1209 /* no BIOS indications, assume SSP0-AIF2 connection */
1210 byt_rt5640_quirk
|= BYT_RT5640_SSP0_AIF2
;
1213 /* change defaults for Baytrail-CR capture */
1214 byt_rt5640_quirk
|= BYTCR_INPUT_DEFAULTS
;
1216 byt_rt5640_quirk
|= BYT_RT5640_DMIC1_MAP
|
1217 BYT_RT5640_JD_SRC_JD2_IN4N
|
1218 BYT_RT5640_OVCD_TH_2000UA
|
1219 BYT_RT5640_OVCD_SF_0P75
;
1222 /* check quirks before creating card */
1223 dmi_id
= dmi_first_match(byt_rt5640_quirk_table
);
1225 byt_rt5640_quirk
= (unsigned long)dmi_id
->driver_data
;
1226 if (quirk_override
!= -1) {
1227 dev_info(&pdev
->dev
, "Overriding quirk 0x%x => 0x%x\n",
1228 (unsigned int)byt_rt5640_quirk
, quirk_override
);
1229 byt_rt5640_quirk
= quirk_override
;
1232 /* Must be called before register_card, also see declaration comment. */
1233 ret_val
= byt_rt5640_add_codec_device_props(byt_rt5640_codec_name
);
1237 log_quirks(&pdev
->dev
);
1239 if ((byt_rt5640_quirk
& BYT_RT5640_SSP2_AIF2
) ||
1240 (byt_rt5640_quirk
& BYT_RT5640_SSP0_AIF2
))
1241 byt_rt5640_dais
[dai_index
].codecs
->dai_name
= "rt5640-aif2";
1243 if ((byt_rt5640_quirk
& BYT_RT5640_SSP0_AIF1
) ||
1244 (byt_rt5640_quirk
& BYT_RT5640_SSP0_AIF2
))
1245 byt_rt5640_dais
[dai_index
].cpus
->dai_name
= "ssp0-port";
1247 if (byt_rt5640_quirk
& BYT_RT5640_MCLK_EN
) {
1248 priv
->mclk
= devm_clk_get(&pdev
->dev
, "pmc_plt_clk_3");
1249 if (IS_ERR(priv
->mclk
)) {
1250 ret_val
= PTR_ERR(priv
->mclk
);
1253 "Failed to get MCLK from pmc_plt_clk_3: %d\n",
1257 * Fall back to bit clock usage for -ENOENT (clock not
1258 * available likely due to missing dependencies), bail
1259 * for all other errors, including -EPROBE_DEFER
1261 if (ret_val
!= -ENOENT
)
1263 byt_rt5640_quirk
&= ~BYT_RT5640_MCLK_EN
;
1267 snprintf(byt_rt5640_components
, sizeof(byt_rt5640_components
),
1268 "cfg-spk:%s cfg-mic:%s",
1269 (byt_rt5640_quirk
& BYT_RT5640_MONO_SPEAKER
) ? "1" : "2",
1270 map_name
[BYT_RT5640_MAP(byt_rt5640_quirk
)]);
1271 byt_rt5640_card
.components
= byt_rt5640_components
;
1272 #if !IS_ENABLED(CONFIG_SND_SOC_INTEL_USER_FRIENDLY_LONG_NAMES)
1273 snprintf(byt_rt5640_long_name
, sizeof(byt_rt5640_long_name
),
1274 "bytcr-rt5640-%s-spk-%s-mic",
1275 (byt_rt5640_quirk
& BYT_RT5640_MONO_SPEAKER
) ?
1277 map_name
[BYT_RT5640_MAP(byt_rt5640_quirk
)]);
1278 byt_rt5640_card
.long_name
= byt_rt5640_long_name
;
1281 /* override plaform name, if required */
1282 platform_name
= mach
->mach_params
.platform
;
1284 ret_val
= snd_soc_fixup_dai_links_platform_name(&byt_rt5640_card
,
1289 ret_val
= devm_snd_soc_register_card(&pdev
->dev
, &byt_rt5640_card
);
1292 dev_err(&pdev
->dev
, "devm_snd_soc_register_card failed %d\n",
1296 platform_set_drvdata(pdev
, &byt_rt5640_card
);
1300 static struct platform_driver snd_byt_rt5640_mc_driver
= {
1302 .name
= "bytcr_rt5640",
1304 .probe
= snd_byt_rt5640_mc_probe
,
1307 module_platform_driver(snd_byt_rt5640_mc_driver
);
1309 MODULE_DESCRIPTION("ASoC Intel(R) Baytrail CR Machine driver");
1310 MODULE_AUTHOR("Subhransu S. Prusty <subhransu.s.prusty@intel.com>");
1311 MODULE_LICENSE("GPL v2");
1312 MODULE_ALIAS("platform:bytcr_rt5640");