2 * rt5640.c -- RT5640/RT5639 ALSA SoC audio codec driver
4 * Copyright 2011 Realtek Semiconductor Corp.
5 * Author: Johnny Hsu <johnnyhsu@realtek.com>
6 * Copyright (c) 2013, NVIDIA CORPORATION. All rights reserved.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
13 #include <linux/module.h>
14 #include <linux/moduleparam.h>
15 #include <linux/init.h>
16 #include <linux/delay.h>
18 #include <linux/gpio.h>
19 #include <linux/i2c.h>
20 #include <linux/regmap.h>
22 #include <linux/of_gpio.h>
23 #include <linux/platform_device.h>
24 #include <linux/spi/spi.h>
25 #include <linux/acpi.h>
26 #include <sound/core.h>
27 #include <sound/pcm.h>
28 #include <sound/pcm_params.h>
29 #include <sound/soc.h>
30 #include <sound/soc-dapm.h>
31 #include <sound/initval.h>
32 #include <sound/tlv.h>
37 #define RT5640_DEVICE_ID 0x6231
39 #define RT5640_PR_RANGE_BASE (0xff + 1)
40 #define RT5640_PR_SPACING 0x100
42 #define RT5640_PR_BASE (RT5640_PR_RANGE_BASE + (0 * RT5640_PR_SPACING))
44 static const struct regmap_range_cfg rt5640_ranges
[] = {
45 { .name
= "PR", .range_min
= RT5640_PR_BASE
,
46 .range_max
= RT5640_PR_BASE
+ 0xb4,
47 .selector_reg
= RT5640_PRIV_INDEX
,
48 .selector_mask
= 0xff,
49 .selector_shift
= 0x0,
50 .window_start
= RT5640_PRIV_DATA
,
54 static const struct reg_sequence init_list
[] = {
55 {RT5640_PR_BASE
+ 0x3d, 0x3600},
56 {RT5640_PR_BASE
+ 0x12, 0x0aa8},
57 {RT5640_PR_BASE
+ 0x14, 0x0aaa},
58 {RT5640_PR_BASE
+ 0x20, 0x6110},
59 {RT5640_PR_BASE
+ 0x21, 0xe0e0},
60 {RT5640_PR_BASE
+ 0x23, 0x1804},
63 static const struct reg_default rt5640_reg
[] = {
169 static int rt5640_reset(struct snd_soc_codec
*codec
)
171 return snd_soc_write(codec
, RT5640_RESET
, 0);
174 static bool rt5640_volatile_register(struct device
*dev
, unsigned int reg
)
178 for (i
= 0; i
< ARRAY_SIZE(rt5640_ranges
); i
++)
179 if ((reg
>= rt5640_ranges
[i
].window_start
&&
180 reg
<= rt5640_ranges
[i
].window_start
+
181 rt5640_ranges
[i
].window_len
) ||
182 (reg
>= rt5640_ranges
[i
].range_min
&&
183 reg
<= rt5640_ranges
[i
].range_max
))
189 case RT5640_EQ_CTRL1
:
190 case RT5640_DRC_AGC_1
:
191 case RT5640_ANC_CTRL1
:
192 case RT5640_IRQ_CTRL2
:
193 case RT5640_INT_IRQ_ST
:
194 case RT5640_DSP_CTRL2
:
195 case RT5640_DSP_CTRL3
:
196 case RT5640_PRIV_INDEX
:
197 case RT5640_PRIV_DATA
:
198 case RT5640_PGM_REG_ARR1
:
199 case RT5640_PGM_REG_ARR3
:
200 case RT5640_VENDOR_ID
:
201 case RT5640_VENDOR_ID1
:
202 case RT5640_VENDOR_ID2
:
209 static bool rt5640_readable_register(struct device
*dev
, unsigned int reg
)
213 for (i
= 0; i
< ARRAY_SIZE(rt5640_ranges
); i
++)
214 if ((reg
>= rt5640_ranges
[i
].window_start
&&
215 reg
<= rt5640_ranges
[i
].window_start
+
216 rt5640_ranges
[i
].window_len
) ||
217 (reg
>= rt5640_ranges
[i
].range_min
&&
218 reg
<= rt5640_ranges
[i
].range_max
))
226 case RT5640_MONO_OUT
:
229 case RT5640_INL_INR_VOL
:
230 case RT5640_DAC1_DIG_VOL
:
231 case RT5640_DAC2_DIG_VOL
:
232 case RT5640_DAC2_CTRL
:
233 case RT5640_ADC_DIG_VOL
:
234 case RT5640_ADC_DATA
:
235 case RT5640_ADC_BST_VOL
:
236 case RT5640_STO_ADC_MIXER
:
237 case RT5640_MONO_ADC_MIXER
:
238 case RT5640_AD_DA_MIXER
:
239 case RT5640_STO_DAC_MIXER
:
240 case RT5640_MONO_DAC_MIXER
:
241 case RT5640_DIG_MIXER
:
242 case RT5640_DSP_PATH1
:
243 case RT5640_DSP_PATH2
:
244 case RT5640_DIG_INF_DATA
:
245 case RT5640_REC_L1_MIXER
:
246 case RT5640_REC_L2_MIXER
:
247 case RT5640_REC_R1_MIXER
:
248 case RT5640_REC_R2_MIXER
:
249 case RT5640_HPO_MIXER
:
250 case RT5640_SPK_L_MIXER
:
251 case RT5640_SPK_R_MIXER
:
252 case RT5640_SPO_L_MIXER
:
253 case RT5640_SPO_R_MIXER
:
254 case RT5640_SPO_CLSD_RATIO
:
255 case RT5640_MONO_MIXER
:
256 case RT5640_OUT_L1_MIXER
:
257 case RT5640_OUT_L2_MIXER
:
258 case RT5640_OUT_L3_MIXER
:
259 case RT5640_OUT_R1_MIXER
:
260 case RT5640_OUT_R2_MIXER
:
261 case RT5640_OUT_R3_MIXER
:
262 case RT5640_LOUT_MIXER
:
263 case RT5640_PWR_DIG1
:
264 case RT5640_PWR_DIG2
:
265 case RT5640_PWR_ANLG1
:
266 case RT5640_PWR_ANLG2
:
267 case RT5640_PWR_MIXER
:
269 case RT5640_PRIV_INDEX
:
270 case RT5640_PRIV_DATA
:
271 case RT5640_I2S1_SDP
:
272 case RT5640_I2S2_SDP
:
273 case RT5640_ADDA_CLK1
:
274 case RT5640_ADDA_CLK2
:
277 case RT5640_PLL_CTRL1
:
278 case RT5640_PLL_CTRL2
:
285 case RT5640_CLS_D_OVCD
:
286 case RT5640_CLS_D_OUT
:
287 case RT5640_DEPOP_M1
:
288 case RT5640_DEPOP_M2
:
289 case RT5640_DEPOP_M3
:
290 case RT5640_CHARGE_PUMP
:
291 case RT5640_PV_DET_SPK_G
:
293 case RT5640_EQ_CTRL1
:
294 case RT5640_EQ_CTRL2
:
295 case RT5640_WIND_FILTER
:
296 case RT5640_DRC_AGC_1
:
297 case RT5640_DRC_AGC_2
:
298 case RT5640_DRC_AGC_3
:
300 case RT5640_ANC_CTRL1
:
301 case RT5640_ANC_CTRL2
:
302 case RT5640_ANC_CTRL3
:
305 case RT5640_IRQ_CTRL1
:
306 case RT5640_IRQ_CTRL2
:
307 case RT5640_INT_IRQ_ST
:
308 case RT5640_GPIO_CTRL1
:
309 case RT5640_GPIO_CTRL2
:
310 case RT5640_GPIO_CTRL3
:
311 case RT5640_DSP_CTRL1
:
312 case RT5640_DSP_CTRL2
:
313 case RT5640_DSP_CTRL3
:
314 case RT5640_DSP_CTRL4
:
315 case RT5640_PGM_REG_ARR1
:
316 case RT5640_PGM_REG_ARR2
:
317 case RT5640_PGM_REG_ARR3
:
318 case RT5640_PGM_REG_ARR4
:
319 case RT5640_PGM_REG_ARR5
:
320 case RT5640_SCB_FUNC
:
321 case RT5640_SCB_CTRL
:
322 case RT5640_BASE_BACK
:
323 case RT5640_MP3_PLUS1
:
324 case RT5640_MP3_PLUS2
:
327 case RT5640_HP_CALIB_AMP_DET
:
328 case RT5640_HP_CALIB2
:
334 case RT5640_VENDOR_ID
:
335 case RT5640_VENDOR_ID1
:
336 case RT5640_VENDOR_ID2
:
343 static const DECLARE_TLV_DB_SCALE(out_vol_tlv
, -4650, 150, 0);
344 static const DECLARE_TLV_DB_SCALE(dac_vol_tlv
, -65625, 375, 0);
345 static const DECLARE_TLV_DB_SCALE(in_vol_tlv
, -3450, 150, 0);
346 static const DECLARE_TLV_DB_SCALE(adc_vol_tlv
, -17625, 375, 0);
347 static const DECLARE_TLV_DB_SCALE(adc_bst_tlv
, 0, 1200, 0);
349 /* {0, +20, +24, +30, +35, +40, +44, +50, +52} dB */
350 static const DECLARE_TLV_DB_RANGE(bst_tlv
,
351 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
352 1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0),
353 2, 2, TLV_DB_SCALE_ITEM(2400, 0, 0),
354 3, 5, TLV_DB_SCALE_ITEM(3000, 500, 0),
355 6, 6, TLV_DB_SCALE_ITEM(4400, 0, 0),
356 7, 7, TLV_DB_SCALE_ITEM(5000, 0, 0),
357 8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0)
360 /* Interface data select */
361 static const char * const rt5640_data_select
[] = {
362 "Normal", "Swap", "left copy to right", "right copy to left"};
364 static SOC_ENUM_SINGLE_DECL(rt5640_if1_dac_enum
, RT5640_DIG_INF_DATA
,
365 RT5640_IF1_DAC_SEL_SFT
, rt5640_data_select
);
367 static SOC_ENUM_SINGLE_DECL(rt5640_if1_adc_enum
, RT5640_DIG_INF_DATA
,
368 RT5640_IF1_ADC_SEL_SFT
, rt5640_data_select
);
370 static SOC_ENUM_SINGLE_DECL(rt5640_if2_dac_enum
, RT5640_DIG_INF_DATA
,
371 RT5640_IF2_DAC_SEL_SFT
, rt5640_data_select
);
373 static SOC_ENUM_SINGLE_DECL(rt5640_if2_adc_enum
, RT5640_DIG_INF_DATA
,
374 RT5640_IF2_ADC_SEL_SFT
, rt5640_data_select
);
376 /* Class D speaker gain ratio */
377 static const char * const rt5640_clsd_spk_ratio
[] = {"1.66x", "1.83x", "1.94x",
378 "2x", "2.11x", "2.22x", "2.33x", "2.44x", "2.55x", "2.66x", "2.77x"};
380 static SOC_ENUM_SINGLE_DECL(rt5640_clsd_spk_ratio_enum
, RT5640_CLS_D_OUT
,
381 RT5640_CLSD_RATIO_SFT
, rt5640_clsd_spk_ratio
);
383 static const struct snd_kcontrol_new rt5640_snd_controls
[] = {
384 /* Speaker Output Volume */
385 SOC_DOUBLE("Speaker Channel Switch", RT5640_SPK_VOL
,
386 RT5640_VOL_L_SFT
, RT5640_VOL_R_SFT
, 1, 1),
387 SOC_DOUBLE_TLV("Speaker Playback Volume", RT5640_SPK_VOL
,
388 RT5640_L_VOL_SFT
, RT5640_R_VOL_SFT
, 39, 1, out_vol_tlv
),
389 /* Headphone Output Volume */
390 SOC_DOUBLE("HP Channel Switch", RT5640_HP_VOL
,
391 RT5640_VOL_L_SFT
, RT5640_VOL_R_SFT
, 1, 1),
392 SOC_DOUBLE_TLV("HP Playback Volume", RT5640_HP_VOL
,
393 RT5640_L_VOL_SFT
, RT5640_R_VOL_SFT
, 39, 1, out_vol_tlv
),
395 SOC_DOUBLE("OUT Playback Switch", RT5640_OUTPUT
,
396 RT5640_L_MUTE_SFT
, RT5640_R_MUTE_SFT
, 1, 1),
397 SOC_DOUBLE("OUT Channel Switch", RT5640_OUTPUT
,
398 RT5640_VOL_L_SFT
, RT5640_VOL_R_SFT
, 1, 1),
399 SOC_DOUBLE_TLV("OUT Playback Volume", RT5640_OUTPUT
,
400 RT5640_L_VOL_SFT
, RT5640_R_VOL_SFT
, 39, 1, out_vol_tlv
),
402 /* DAC Digital Volume */
403 SOC_DOUBLE("DAC2 Playback Switch", RT5640_DAC2_CTRL
,
404 RT5640_M_DAC_L2_VOL_SFT
, RT5640_M_DAC_R2_VOL_SFT
, 1, 1),
405 SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5640_DAC1_DIG_VOL
,
406 RT5640_L_VOL_SFT
, RT5640_R_VOL_SFT
,
407 175, 0, dac_vol_tlv
),
408 /* IN1/IN2/IN3 Control */
409 SOC_SINGLE_TLV("IN1 Boost", RT5640_IN1_IN2
,
410 RT5640_BST_SFT1
, 8, 0, bst_tlv
),
411 SOC_SINGLE_TLV("IN2 Boost", RT5640_IN3_IN4
,
412 RT5640_BST_SFT2
, 8, 0, bst_tlv
),
413 SOC_SINGLE_TLV("IN3 Boost", RT5640_IN1_IN2
,
414 RT5640_BST_SFT2
, 8, 0, bst_tlv
),
416 /* INL/INR Volume Control */
417 SOC_DOUBLE_TLV("IN Capture Volume", RT5640_INL_INR_VOL
,
418 RT5640_INL_VOL_SFT
, RT5640_INR_VOL_SFT
,
420 /* ADC Digital Volume Control */
421 SOC_DOUBLE("ADC Capture Switch", RT5640_ADC_DIG_VOL
,
422 RT5640_L_MUTE_SFT
, RT5640_R_MUTE_SFT
, 1, 1),
423 SOC_DOUBLE_TLV("ADC Capture Volume", RT5640_ADC_DIG_VOL
,
424 RT5640_L_VOL_SFT
, RT5640_R_VOL_SFT
,
425 127, 0, adc_vol_tlv
),
426 SOC_DOUBLE("Mono ADC Capture Switch", RT5640_DUMMY1
,
427 RT5640_M_MONO_ADC_L_SFT
, RT5640_M_MONO_ADC_R_SFT
, 1, 1),
428 SOC_DOUBLE_TLV("Mono ADC Capture Volume", RT5640_ADC_DATA
,
429 RT5640_L_VOL_SFT
, RT5640_R_VOL_SFT
,
430 127, 0, adc_vol_tlv
),
431 /* ADC Boost Volume Control */
432 SOC_DOUBLE_TLV("ADC Boost Gain", RT5640_ADC_BST_VOL
,
433 RT5640_ADC_L_BST_SFT
, RT5640_ADC_R_BST_SFT
,
435 /* Class D speaker gain ratio */
436 SOC_ENUM("Class D SPK Ratio Control", rt5640_clsd_spk_ratio_enum
),
438 SOC_ENUM("ADC IF1 Data Switch", rt5640_if1_adc_enum
),
439 SOC_ENUM("DAC IF1 Data Switch", rt5640_if1_dac_enum
),
440 SOC_ENUM("ADC IF2 Data Switch", rt5640_if2_adc_enum
),
441 SOC_ENUM("DAC IF2 Data Switch", rt5640_if2_dac_enum
),
444 static const struct snd_kcontrol_new rt5640_specific_snd_controls
[] = {
445 /* MONO Output Control */
446 SOC_SINGLE("Mono Playback Switch", RT5640_MONO_OUT
, RT5640_L_MUTE_SFT
,
449 SOC_DOUBLE_TLV("Mono DAC Playback Volume", RT5640_DAC2_DIG_VOL
,
450 RT5640_L_VOL_SFT
, RT5640_R_VOL_SFT
, 175, 0, dac_vol_tlv
),
454 * set_dmic_clk - Set parameter of dmic.
457 * @kcontrol: The kcontrol of this widget.
461 static int set_dmic_clk(struct snd_soc_dapm_widget
*w
,
462 struct snd_kcontrol
*kcontrol
, int event
)
464 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
465 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
468 rate
= rt5640
->sysclk
/ rl6231_get_pre_div(rt5640
->regmap
,
469 RT5640_ADDA_CLK1
, RT5640_I2S_PD1_SFT
);
470 idx
= rl6231_calc_dmic_clk(rate
);
472 dev_err(codec
->dev
, "Failed to set DMIC clock\n");
474 snd_soc_update_bits(codec
, RT5640_DMIC
, RT5640_DMIC_CLK_MASK
,
475 idx
<< RT5640_DMIC_CLK_SFT
);
479 static int is_sys_clk_from_pll(struct snd_soc_dapm_widget
*source
,
480 struct snd_soc_dapm_widget
*sink
)
482 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(source
->dapm
);
485 val
= snd_soc_read(codec
, RT5640_GLB_CLK
);
486 val
&= RT5640_SCLK_SRC_MASK
;
487 if (val
== RT5640_SCLK_SRC_PLL1
)
493 static int is_using_asrc(struct snd_soc_dapm_widget
*source
,
494 struct snd_soc_dapm_widget
*sink
)
496 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(source
->dapm
);
497 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
499 if (!rt5640
->asrc_en
)
506 static const struct snd_kcontrol_new rt5640_sto_adc_l_mix
[] = {
507 SOC_DAPM_SINGLE("ADC1 Switch", RT5640_STO_ADC_MIXER
,
508 RT5640_M_ADC_L1_SFT
, 1, 1),
509 SOC_DAPM_SINGLE("ADC2 Switch", RT5640_STO_ADC_MIXER
,
510 RT5640_M_ADC_L2_SFT
, 1, 1),
513 static const struct snd_kcontrol_new rt5640_sto_adc_r_mix
[] = {
514 SOC_DAPM_SINGLE("ADC1 Switch", RT5640_STO_ADC_MIXER
,
515 RT5640_M_ADC_R1_SFT
, 1, 1),
516 SOC_DAPM_SINGLE("ADC2 Switch", RT5640_STO_ADC_MIXER
,
517 RT5640_M_ADC_R2_SFT
, 1, 1),
520 static const struct snd_kcontrol_new rt5640_mono_adc_l_mix
[] = {
521 SOC_DAPM_SINGLE("ADC1 Switch", RT5640_MONO_ADC_MIXER
,
522 RT5640_M_MONO_ADC_L1_SFT
, 1, 1),
523 SOC_DAPM_SINGLE("ADC2 Switch", RT5640_MONO_ADC_MIXER
,
524 RT5640_M_MONO_ADC_L2_SFT
, 1, 1),
527 static const struct snd_kcontrol_new rt5640_mono_adc_r_mix
[] = {
528 SOC_DAPM_SINGLE("ADC1 Switch", RT5640_MONO_ADC_MIXER
,
529 RT5640_M_MONO_ADC_R1_SFT
, 1, 1),
530 SOC_DAPM_SINGLE("ADC2 Switch", RT5640_MONO_ADC_MIXER
,
531 RT5640_M_MONO_ADC_R2_SFT
, 1, 1),
534 static const struct snd_kcontrol_new rt5640_dac_l_mix
[] = {
535 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5640_AD_DA_MIXER
,
536 RT5640_M_ADCMIX_L_SFT
, 1, 1),
537 SOC_DAPM_SINGLE("INF1 Switch", RT5640_AD_DA_MIXER
,
538 RT5640_M_IF1_DAC_L_SFT
, 1, 1),
541 static const struct snd_kcontrol_new rt5640_dac_r_mix
[] = {
542 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5640_AD_DA_MIXER
,
543 RT5640_M_ADCMIX_R_SFT
, 1, 1),
544 SOC_DAPM_SINGLE("INF1 Switch", RT5640_AD_DA_MIXER
,
545 RT5640_M_IF1_DAC_R_SFT
, 1, 1),
548 static const struct snd_kcontrol_new rt5640_sto_dac_l_mix
[] = {
549 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_STO_DAC_MIXER
,
550 RT5640_M_DAC_L1_SFT
, 1, 1),
551 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_STO_DAC_MIXER
,
552 RT5640_M_DAC_L2_SFT
, 1, 1),
553 SOC_DAPM_SINGLE("ANC Switch", RT5640_STO_DAC_MIXER
,
554 RT5640_M_ANC_DAC_L_SFT
, 1, 1),
557 static const struct snd_kcontrol_new rt5640_sto_dac_r_mix
[] = {
558 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_STO_DAC_MIXER
,
559 RT5640_M_DAC_R1_SFT
, 1, 1),
560 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_STO_DAC_MIXER
,
561 RT5640_M_DAC_R2_SFT
, 1, 1),
562 SOC_DAPM_SINGLE("ANC Switch", RT5640_STO_DAC_MIXER
,
563 RT5640_M_ANC_DAC_R_SFT
, 1, 1),
566 static const struct snd_kcontrol_new rt5639_sto_dac_l_mix
[] = {
567 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_STO_DAC_MIXER
,
568 RT5640_M_DAC_L1_SFT
, 1, 1),
569 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_STO_DAC_MIXER
,
570 RT5640_M_DAC_L2_SFT
, 1, 1),
573 static const struct snd_kcontrol_new rt5639_sto_dac_r_mix
[] = {
574 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_STO_DAC_MIXER
,
575 RT5640_M_DAC_R1_SFT
, 1, 1),
576 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_STO_DAC_MIXER
,
577 RT5640_M_DAC_R2_SFT
, 1, 1),
580 static const struct snd_kcontrol_new rt5640_mono_dac_l_mix
[] = {
581 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_MONO_DAC_MIXER
,
582 RT5640_M_DAC_L1_MONO_L_SFT
, 1, 1),
583 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_MONO_DAC_MIXER
,
584 RT5640_M_DAC_L2_MONO_L_SFT
, 1, 1),
585 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_MONO_DAC_MIXER
,
586 RT5640_M_DAC_R2_MONO_L_SFT
, 1, 1),
589 static const struct snd_kcontrol_new rt5640_mono_dac_r_mix
[] = {
590 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_MONO_DAC_MIXER
,
591 RT5640_M_DAC_R1_MONO_R_SFT
, 1, 1),
592 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_MONO_DAC_MIXER
,
593 RT5640_M_DAC_R2_MONO_R_SFT
, 1, 1),
594 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_MONO_DAC_MIXER
,
595 RT5640_M_DAC_L2_MONO_R_SFT
, 1, 1),
598 static const struct snd_kcontrol_new rt5640_dig_l_mix
[] = {
599 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_DIG_MIXER
,
600 RT5640_M_STO_L_DAC_L_SFT
, 1, 1),
601 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_DIG_MIXER
,
602 RT5640_M_DAC_L2_DAC_L_SFT
, 1, 1),
605 static const struct snd_kcontrol_new rt5640_dig_r_mix
[] = {
606 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_DIG_MIXER
,
607 RT5640_M_STO_R_DAC_R_SFT
, 1, 1),
608 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_DIG_MIXER
,
609 RT5640_M_DAC_R2_DAC_R_SFT
, 1, 1),
612 /* Analog Input Mixer */
613 static const struct snd_kcontrol_new rt5640_rec_l_mix
[] = {
614 SOC_DAPM_SINGLE("HPOL Switch", RT5640_REC_L2_MIXER
,
615 RT5640_M_HP_L_RM_L_SFT
, 1, 1),
616 SOC_DAPM_SINGLE("INL Switch", RT5640_REC_L2_MIXER
,
617 RT5640_M_IN_L_RM_L_SFT
, 1, 1),
618 SOC_DAPM_SINGLE("BST3 Switch", RT5640_REC_L2_MIXER
,
619 RT5640_M_BST2_RM_L_SFT
, 1, 1),
620 SOC_DAPM_SINGLE("BST2 Switch", RT5640_REC_L2_MIXER
,
621 RT5640_M_BST4_RM_L_SFT
, 1, 1),
622 SOC_DAPM_SINGLE("BST1 Switch", RT5640_REC_L2_MIXER
,
623 RT5640_M_BST1_RM_L_SFT
, 1, 1),
624 SOC_DAPM_SINGLE("OUT MIXL Switch", RT5640_REC_L2_MIXER
,
625 RT5640_M_OM_L_RM_L_SFT
, 1, 1),
628 static const struct snd_kcontrol_new rt5640_rec_r_mix
[] = {
629 SOC_DAPM_SINGLE("HPOR Switch", RT5640_REC_R2_MIXER
,
630 RT5640_M_HP_R_RM_R_SFT
, 1, 1),
631 SOC_DAPM_SINGLE("INR Switch", RT5640_REC_R2_MIXER
,
632 RT5640_M_IN_R_RM_R_SFT
, 1, 1),
633 SOC_DAPM_SINGLE("BST3 Switch", RT5640_REC_R2_MIXER
,
634 RT5640_M_BST2_RM_R_SFT
, 1, 1),
635 SOC_DAPM_SINGLE("BST2 Switch", RT5640_REC_R2_MIXER
,
636 RT5640_M_BST4_RM_R_SFT
, 1, 1),
637 SOC_DAPM_SINGLE("BST1 Switch", RT5640_REC_R2_MIXER
,
638 RT5640_M_BST1_RM_R_SFT
, 1, 1),
639 SOC_DAPM_SINGLE("OUT MIXR Switch", RT5640_REC_R2_MIXER
,
640 RT5640_M_OM_R_RM_R_SFT
, 1, 1),
643 /* Analog Output Mixer */
644 static const struct snd_kcontrol_new rt5640_spk_l_mix
[] = {
645 SOC_DAPM_SINGLE("REC MIXL Switch", RT5640_SPK_L_MIXER
,
646 RT5640_M_RM_L_SM_L_SFT
, 1, 1),
647 SOC_DAPM_SINGLE("INL Switch", RT5640_SPK_L_MIXER
,
648 RT5640_M_IN_L_SM_L_SFT
, 1, 1),
649 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_SPK_L_MIXER
,
650 RT5640_M_DAC_L1_SM_L_SFT
, 1, 1),
651 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_SPK_L_MIXER
,
652 RT5640_M_DAC_L2_SM_L_SFT
, 1, 1),
653 SOC_DAPM_SINGLE("OUT MIXL Switch", RT5640_SPK_L_MIXER
,
654 RT5640_M_OM_L_SM_L_SFT
, 1, 1),
657 static const struct snd_kcontrol_new rt5640_spk_r_mix
[] = {
658 SOC_DAPM_SINGLE("REC MIXR Switch", RT5640_SPK_R_MIXER
,
659 RT5640_M_RM_R_SM_R_SFT
, 1, 1),
660 SOC_DAPM_SINGLE("INR Switch", RT5640_SPK_R_MIXER
,
661 RT5640_M_IN_R_SM_R_SFT
, 1, 1),
662 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_SPK_R_MIXER
,
663 RT5640_M_DAC_R1_SM_R_SFT
, 1, 1),
664 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_SPK_R_MIXER
,
665 RT5640_M_DAC_R2_SM_R_SFT
, 1, 1),
666 SOC_DAPM_SINGLE("OUT MIXR Switch", RT5640_SPK_R_MIXER
,
667 RT5640_M_OM_R_SM_R_SFT
, 1, 1),
670 static const struct snd_kcontrol_new rt5640_out_l_mix
[] = {
671 SOC_DAPM_SINGLE("SPK MIXL Switch", RT5640_OUT_L3_MIXER
,
672 RT5640_M_SM_L_OM_L_SFT
, 1, 1),
673 SOC_DAPM_SINGLE("BST1 Switch", RT5640_OUT_L3_MIXER
,
674 RT5640_M_BST1_OM_L_SFT
, 1, 1),
675 SOC_DAPM_SINGLE("INL Switch", RT5640_OUT_L3_MIXER
,
676 RT5640_M_IN_L_OM_L_SFT
, 1, 1),
677 SOC_DAPM_SINGLE("REC MIXL Switch", RT5640_OUT_L3_MIXER
,
678 RT5640_M_RM_L_OM_L_SFT
, 1, 1),
679 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_OUT_L3_MIXER
,
680 RT5640_M_DAC_R2_OM_L_SFT
, 1, 1),
681 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_OUT_L3_MIXER
,
682 RT5640_M_DAC_L2_OM_L_SFT
, 1, 1),
683 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_OUT_L3_MIXER
,
684 RT5640_M_DAC_L1_OM_L_SFT
, 1, 1),
687 static const struct snd_kcontrol_new rt5640_out_r_mix
[] = {
688 SOC_DAPM_SINGLE("SPK MIXR Switch", RT5640_OUT_R3_MIXER
,
689 RT5640_M_SM_L_OM_R_SFT
, 1, 1),
690 SOC_DAPM_SINGLE("BST2 Switch", RT5640_OUT_R3_MIXER
,
691 RT5640_M_BST4_OM_R_SFT
, 1, 1),
692 SOC_DAPM_SINGLE("BST1 Switch", RT5640_OUT_R3_MIXER
,
693 RT5640_M_BST1_OM_R_SFT
, 1, 1),
694 SOC_DAPM_SINGLE("INR Switch", RT5640_OUT_R3_MIXER
,
695 RT5640_M_IN_R_OM_R_SFT
, 1, 1),
696 SOC_DAPM_SINGLE("REC MIXR Switch", RT5640_OUT_R3_MIXER
,
697 RT5640_M_RM_R_OM_R_SFT
, 1, 1),
698 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_OUT_R3_MIXER
,
699 RT5640_M_DAC_L2_OM_R_SFT
, 1, 1),
700 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_OUT_R3_MIXER
,
701 RT5640_M_DAC_R2_OM_R_SFT
, 1, 1),
702 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_OUT_R3_MIXER
,
703 RT5640_M_DAC_R1_OM_R_SFT
, 1, 1),
706 static const struct snd_kcontrol_new rt5639_out_l_mix
[] = {
707 SOC_DAPM_SINGLE("BST1 Switch", RT5640_OUT_L3_MIXER
,
708 RT5640_M_BST1_OM_L_SFT
, 1, 1),
709 SOC_DAPM_SINGLE("INL Switch", RT5640_OUT_L3_MIXER
,
710 RT5640_M_IN_L_OM_L_SFT
, 1, 1),
711 SOC_DAPM_SINGLE("REC MIXL Switch", RT5640_OUT_L3_MIXER
,
712 RT5640_M_RM_L_OM_L_SFT
, 1, 1),
713 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_OUT_L3_MIXER
,
714 RT5640_M_DAC_L1_OM_L_SFT
, 1, 1),
717 static const struct snd_kcontrol_new rt5639_out_r_mix
[] = {
718 SOC_DAPM_SINGLE("BST2 Switch", RT5640_OUT_R3_MIXER
,
719 RT5640_M_BST4_OM_R_SFT
, 1, 1),
720 SOC_DAPM_SINGLE("BST1 Switch", RT5640_OUT_R3_MIXER
,
721 RT5640_M_BST1_OM_R_SFT
, 1, 1),
722 SOC_DAPM_SINGLE("INR Switch", RT5640_OUT_R3_MIXER
,
723 RT5640_M_IN_R_OM_R_SFT
, 1, 1),
724 SOC_DAPM_SINGLE("REC MIXR Switch", RT5640_OUT_R3_MIXER
,
725 RT5640_M_RM_R_OM_R_SFT
, 1, 1),
726 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_OUT_R3_MIXER
,
727 RT5640_M_DAC_R1_OM_R_SFT
, 1, 1),
730 static const struct snd_kcontrol_new rt5640_spo_l_mix
[] = {
731 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_SPO_L_MIXER
,
732 RT5640_M_DAC_R1_SPM_L_SFT
, 1, 1),
733 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_SPO_L_MIXER
,
734 RT5640_M_DAC_L1_SPM_L_SFT
, 1, 1),
735 SOC_DAPM_SINGLE("SPKVOL R Switch", RT5640_SPO_L_MIXER
,
736 RT5640_M_SV_R_SPM_L_SFT
, 1, 1),
737 SOC_DAPM_SINGLE("SPKVOL L Switch", RT5640_SPO_L_MIXER
,
738 RT5640_M_SV_L_SPM_L_SFT
, 1, 1),
739 SOC_DAPM_SINGLE("BST1 Switch", RT5640_SPO_L_MIXER
,
740 RT5640_M_BST1_SPM_L_SFT
, 1, 1),
743 static const struct snd_kcontrol_new rt5640_spo_r_mix
[] = {
744 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_SPO_R_MIXER
,
745 RT5640_M_DAC_R1_SPM_R_SFT
, 1, 1),
746 SOC_DAPM_SINGLE("SPKVOL R Switch", RT5640_SPO_R_MIXER
,
747 RT5640_M_SV_R_SPM_R_SFT
, 1, 1),
748 SOC_DAPM_SINGLE("BST1 Switch", RT5640_SPO_R_MIXER
,
749 RT5640_M_BST1_SPM_R_SFT
, 1, 1),
752 static const struct snd_kcontrol_new rt5640_hpo_mix
[] = {
753 SOC_DAPM_SINGLE("HPO MIX DAC2 Switch", RT5640_HPO_MIXER
,
754 RT5640_M_DAC2_HM_SFT
, 1, 1),
755 SOC_DAPM_SINGLE("HPO MIX DAC1 Switch", RT5640_HPO_MIXER
,
756 RT5640_M_DAC1_HM_SFT
, 1, 1),
757 SOC_DAPM_SINGLE("HPO MIX HPVOL Switch", RT5640_HPO_MIXER
,
758 RT5640_M_HPVOL_HM_SFT
, 1, 1),
761 static const struct snd_kcontrol_new rt5639_hpo_mix
[] = {
762 SOC_DAPM_SINGLE("HPO MIX DAC1 Switch", RT5640_HPO_MIXER
,
763 RT5640_M_DAC1_HM_SFT
, 1, 1),
764 SOC_DAPM_SINGLE("HPO MIX HPVOL Switch", RT5640_HPO_MIXER
,
765 RT5640_M_HPVOL_HM_SFT
, 1, 1),
768 static const struct snd_kcontrol_new rt5640_lout_mix
[] = {
769 SOC_DAPM_SINGLE("DAC L1 Switch", RT5640_LOUT_MIXER
,
770 RT5640_M_DAC_L1_LM_SFT
, 1, 1),
771 SOC_DAPM_SINGLE("DAC R1 Switch", RT5640_LOUT_MIXER
,
772 RT5640_M_DAC_R1_LM_SFT
, 1, 1),
773 SOC_DAPM_SINGLE("OUTVOL L Switch", RT5640_LOUT_MIXER
,
774 RT5640_M_OV_L_LM_SFT
, 1, 1),
775 SOC_DAPM_SINGLE("OUTVOL R Switch", RT5640_LOUT_MIXER
,
776 RT5640_M_OV_R_LM_SFT
, 1, 1),
779 static const struct snd_kcontrol_new rt5640_mono_mix
[] = {
780 SOC_DAPM_SINGLE("DAC R2 Switch", RT5640_MONO_MIXER
,
781 RT5640_M_DAC_R2_MM_SFT
, 1, 1),
782 SOC_DAPM_SINGLE("DAC L2 Switch", RT5640_MONO_MIXER
,
783 RT5640_M_DAC_L2_MM_SFT
, 1, 1),
784 SOC_DAPM_SINGLE("OUTVOL R Switch", RT5640_MONO_MIXER
,
785 RT5640_M_OV_R_MM_SFT
, 1, 1),
786 SOC_DAPM_SINGLE("OUTVOL L Switch", RT5640_MONO_MIXER
,
787 RT5640_M_OV_L_MM_SFT
, 1, 1),
788 SOC_DAPM_SINGLE("BST1 Switch", RT5640_MONO_MIXER
,
789 RT5640_M_BST1_MM_SFT
, 1, 1),
792 static const struct snd_kcontrol_new spk_l_enable_control
=
793 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5640_SPK_VOL
,
794 RT5640_L_MUTE_SFT
, 1, 1);
796 static const struct snd_kcontrol_new spk_r_enable_control
=
797 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5640_SPK_VOL
,
798 RT5640_R_MUTE_SFT
, 1, 1);
800 static const struct snd_kcontrol_new hp_l_enable_control
=
801 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5640_HP_VOL
,
802 RT5640_L_MUTE_SFT
, 1, 1);
804 static const struct snd_kcontrol_new hp_r_enable_control
=
805 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5640_HP_VOL
,
806 RT5640_R_MUTE_SFT
, 1, 1);
808 /* Stereo ADC source */
809 static const char * const rt5640_stereo_adc1_src
[] = {
813 static SOC_ENUM_SINGLE_DECL(rt5640_stereo_adc1_enum
, RT5640_STO_ADC_MIXER
,
814 RT5640_ADC_1_SRC_SFT
, rt5640_stereo_adc1_src
);
816 static const struct snd_kcontrol_new rt5640_sto_adc_1_mux
=
817 SOC_DAPM_ENUM("Stereo ADC1 Mux", rt5640_stereo_adc1_enum
);
819 static const char * const rt5640_stereo_adc2_src
[] = {
820 "DMIC1", "DMIC2", "DIG MIX"
823 static SOC_ENUM_SINGLE_DECL(rt5640_stereo_adc2_enum
, RT5640_STO_ADC_MIXER
,
824 RT5640_ADC_2_SRC_SFT
, rt5640_stereo_adc2_src
);
826 static const struct snd_kcontrol_new rt5640_sto_adc_2_mux
=
827 SOC_DAPM_ENUM("Stereo ADC2 Mux", rt5640_stereo_adc2_enum
);
829 /* Mono ADC source */
830 static const char * const rt5640_mono_adc_l1_src
[] = {
831 "Mono DAC MIXL", "ADCL"
834 static SOC_ENUM_SINGLE_DECL(rt5640_mono_adc_l1_enum
, RT5640_MONO_ADC_MIXER
,
835 RT5640_MONO_ADC_L1_SRC_SFT
, rt5640_mono_adc_l1_src
);
837 static const struct snd_kcontrol_new rt5640_mono_adc_l1_mux
=
838 SOC_DAPM_ENUM("Mono ADC1 left source", rt5640_mono_adc_l1_enum
);
840 static const char * const rt5640_mono_adc_l2_src
[] = {
841 "DMIC L1", "DMIC L2", "Mono DAC MIXL"
844 static SOC_ENUM_SINGLE_DECL(rt5640_mono_adc_l2_enum
, RT5640_MONO_ADC_MIXER
,
845 RT5640_MONO_ADC_L2_SRC_SFT
, rt5640_mono_adc_l2_src
);
847 static const struct snd_kcontrol_new rt5640_mono_adc_l2_mux
=
848 SOC_DAPM_ENUM("Mono ADC2 left source", rt5640_mono_adc_l2_enum
);
850 static const char * const rt5640_mono_adc_r1_src
[] = {
851 "Mono DAC MIXR", "ADCR"
854 static SOC_ENUM_SINGLE_DECL(rt5640_mono_adc_r1_enum
, RT5640_MONO_ADC_MIXER
,
855 RT5640_MONO_ADC_R1_SRC_SFT
, rt5640_mono_adc_r1_src
);
857 static const struct snd_kcontrol_new rt5640_mono_adc_r1_mux
=
858 SOC_DAPM_ENUM("Mono ADC1 right source", rt5640_mono_adc_r1_enum
);
860 static const char * const rt5640_mono_adc_r2_src
[] = {
861 "DMIC R1", "DMIC R2", "Mono DAC MIXR"
864 static SOC_ENUM_SINGLE_DECL(rt5640_mono_adc_r2_enum
, RT5640_MONO_ADC_MIXER
,
865 RT5640_MONO_ADC_R2_SRC_SFT
, rt5640_mono_adc_r2_src
);
867 static const struct snd_kcontrol_new rt5640_mono_adc_r2_mux
=
868 SOC_DAPM_ENUM("Mono ADC2 right source", rt5640_mono_adc_r2_enum
);
870 /* DAC2 channel source */
871 static const char * const rt5640_dac_l2_src
[] = {
875 static int rt5640_dac_l2_values
[] = {
880 static SOC_VALUE_ENUM_SINGLE_DECL(rt5640_dac_l2_enum
,
881 RT5640_DSP_PATH2
, RT5640_DAC_L2_SEL_SFT
,
882 0x3, rt5640_dac_l2_src
, rt5640_dac_l2_values
);
884 static const struct snd_kcontrol_new rt5640_dac_l2_mux
=
885 SOC_DAPM_ENUM("DAC2 left channel source", rt5640_dac_l2_enum
);
887 static const char * const rt5640_dac_r2_src
[] = {
891 static int rt5640_dac_r2_values
[] = {
895 static SOC_VALUE_ENUM_SINGLE_DECL(rt5640_dac_r2_enum
,
896 RT5640_DSP_PATH2
, RT5640_DAC_R2_SEL_SFT
,
897 0x3, rt5640_dac_r2_src
, rt5640_dac_r2_values
);
899 static const struct snd_kcontrol_new rt5640_dac_r2_mux
=
900 SOC_DAPM_ENUM("DAC2 right channel source", rt5640_dac_r2_enum
);
902 /* digital interface and iis interface map */
903 static const char * const rt5640_dai_iis_map
[] = {
904 "1:1|2:2", "1:2|2:1", "1:1|2:1", "1:2|2:2"
907 static int rt5640_dai_iis_map_values
[] = {
914 static SOC_VALUE_ENUM_SINGLE_DECL(rt5640_dai_iis_map_enum
,
915 RT5640_I2S1_SDP
, RT5640_I2S_IF_SFT
,
916 0x7, rt5640_dai_iis_map
,
917 rt5640_dai_iis_map_values
);
919 static const struct snd_kcontrol_new rt5640_dai_mux
=
920 SOC_DAPM_ENUM("DAI select", rt5640_dai_iis_map_enum
);
923 static const char * const rt5640_sdi_sel
[] = {
927 static SOC_ENUM_SINGLE_DECL(rt5640_sdi_sel_enum
, RT5640_I2S2_SDP
,
928 RT5640_I2S2_SDI_SFT
, rt5640_sdi_sel
);
930 static const struct snd_kcontrol_new rt5640_sdi_mux
=
931 SOC_DAPM_ENUM("SDI select", rt5640_sdi_sel_enum
);
933 static void hp_amp_power_on(struct snd_soc_codec
*codec
)
935 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
937 /* depop parameters */
938 regmap_update_bits(rt5640
->regmap
, RT5640_PR_BASE
+
939 RT5640_CHPUMP_INT_REG1
, 0x0700, 0x0200);
940 regmap_update_bits(rt5640
->regmap
, RT5640_DEPOP_M2
,
941 RT5640_DEPOP_MASK
, RT5640_DEPOP_MAN
);
942 regmap_update_bits(rt5640
->regmap
, RT5640_DEPOP_M1
,
943 RT5640_HP_CP_MASK
| RT5640_HP_SG_MASK
| RT5640_HP_CB_MASK
,
944 RT5640_HP_CP_PU
| RT5640_HP_SG_DIS
| RT5640_HP_CB_PU
);
945 regmap_write(rt5640
->regmap
, RT5640_PR_BASE
+ RT5640_HP_DCC_INT1
,
947 /* headphone amp power on */
948 regmap_update_bits(rt5640
->regmap
, RT5640_PWR_ANLG1
,
949 RT5640_PWR_FV1
| RT5640_PWR_FV2
, 0);
950 regmap_update_bits(rt5640
->regmap
, RT5640_PWR_ANLG1
,
953 usleep_range(10000, 15000);
954 regmap_update_bits(rt5640
->regmap
, RT5640_PWR_ANLG1
,
955 RT5640_PWR_FV1
| RT5640_PWR_FV2
,
956 RT5640_PWR_FV1
| RT5640_PWR_FV2
);
959 static void rt5640_pmu_depop(struct snd_soc_codec
*codec
)
961 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
963 regmap_update_bits(rt5640
->regmap
, RT5640_DEPOP_M2
,
964 RT5640_DEPOP_MASK
| RT5640_DIG_DP_MASK
,
965 RT5640_DEPOP_AUTO
| RT5640_DIG_DP_EN
);
966 regmap_update_bits(rt5640
->regmap
, RT5640_CHARGE_PUMP
,
967 RT5640_PM_HP_MASK
, RT5640_PM_HP_HV
);
969 regmap_update_bits(rt5640
->regmap
, RT5640_DEPOP_M3
,
970 RT5640_CP_FQ1_MASK
| RT5640_CP_FQ2_MASK
| RT5640_CP_FQ3_MASK
,
971 (RT5640_CP_FQ_192_KHZ
<< RT5640_CP_FQ1_SFT
) |
972 (RT5640_CP_FQ_12_KHZ
<< RT5640_CP_FQ2_SFT
) |
973 (RT5640_CP_FQ_192_KHZ
<< RT5640_CP_FQ3_SFT
));
975 regmap_write(rt5640
->regmap
, RT5640_PR_BASE
+
976 RT5640_MAMP_INT_REG2
, 0x1c00);
977 regmap_update_bits(rt5640
->regmap
, RT5640_DEPOP_M1
,
978 RT5640_HP_CP_MASK
| RT5640_HP_SG_MASK
,
979 RT5640_HP_CP_PD
| RT5640_HP_SG_EN
);
980 regmap_update_bits(rt5640
->regmap
, RT5640_PR_BASE
+
981 RT5640_CHPUMP_INT_REG1
, 0x0700, 0x0400);
984 static int rt5640_hp_event(struct snd_soc_dapm_widget
*w
,
985 struct snd_kcontrol
*kcontrol
, int event
)
987 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
988 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
991 case SND_SOC_DAPM_POST_PMU
:
992 rt5640_pmu_depop(codec
);
996 case SND_SOC_DAPM_PRE_PMD
:
1008 static int rt5640_lout_event(struct snd_soc_dapm_widget
*w
,
1009 struct snd_kcontrol
*kcontrol
, int event
)
1011 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
1014 case SND_SOC_DAPM_POST_PMU
:
1015 hp_amp_power_on(codec
);
1016 snd_soc_update_bits(codec
, RT5640_PWR_ANLG1
,
1017 RT5640_PWR_LM
, RT5640_PWR_LM
);
1018 snd_soc_update_bits(codec
, RT5640_OUTPUT
,
1019 RT5640_L_MUTE
| RT5640_R_MUTE
, 0);
1022 case SND_SOC_DAPM_PRE_PMD
:
1023 snd_soc_update_bits(codec
, RT5640_OUTPUT
,
1024 RT5640_L_MUTE
| RT5640_R_MUTE
,
1025 RT5640_L_MUTE
| RT5640_R_MUTE
);
1026 snd_soc_update_bits(codec
, RT5640_PWR_ANLG1
,
1037 static int rt5640_hp_power_event(struct snd_soc_dapm_widget
*w
,
1038 struct snd_kcontrol
*kcontrol
, int event
)
1040 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
1043 case SND_SOC_DAPM_POST_PMU
:
1044 hp_amp_power_on(codec
);
1053 static int rt5640_hp_post_event(struct snd_soc_dapm_widget
*w
,
1054 struct snd_kcontrol
*kcontrol
, int event
)
1056 struct snd_soc_codec
*codec
= snd_soc_dapm_to_codec(w
->dapm
);
1057 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
1060 case SND_SOC_DAPM_POST_PMU
:
1061 if (!rt5640
->hp_mute
)
1073 static const struct snd_soc_dapm_widget rt5640_dapm_widgets
[] = {
1074 SND_SOC_DAPM_SUPPLY("PLL1", RT5640_PWR_ANLG2
,
1075 RT5640_PWR_PLL_BIT
, 0, NULL
, 0),
1078 SND_SOC_DAPM_SUPPLY_S("Stereo Filter ASRC", 1, RT5640_ASRC_1
,
1080 SND_SOC_DAPM_SUPPLY_S("I2S2 Filter ASRC", 1, RT5640_ASRC_1
,
1082 SND_SOC_DAPM_SUPPLY_S("I2S2 ASRC", 1, RT5640_ASRC_1
,
1084 SND_SOC_DAPM_SUPPLY_S("DMIC1 ASRC", 1, RT5640_ASRC_1
,
1086 SND_SOC_DAPM_SUPPLY_S("DMIC2 ASRC", 1, RT5640_ASRC_1
,
1092 SND_SOC_DAPM_SUPPLY("LDO2", RT5640_PWR_ANLG1
,
1093 RT5640_PWR_LDO2_BIT
, 0, NULL
, 0),
1094 SND_SOC_DAPM_SUPPLY("MICBIAS1", RT5640_PWR_ANLG2
,
1095 RT5640_PWR_MB1_BIT
, 0, NULL
, 0),
1097 SND_SOC_DAPM_INPUT("DMIC1"),
1098 SND_SOC_DAPM_INPUT("DMIC2"),
1099 SND_SOC_DAPM_INPUT("IN1P"),
1100 SND_SOC_DAPM_INPUT("IN1N"),
1101 SND_SOC_DAPM_INPUT("IN2P"),
1102 SND_SOC_DAPM_INPUT("IN2N"),
1103 SND_SOC_DAPM_INPUT("IN3P"),
1104 SND_SOC_DAPM_INPUT("IN3N"),
1105 SND_SOC_DAPM_PGA("DMIC L1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1106 SND_SOC_DAPM_PGA("DMIC R1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1107 SND_SOC_DAPM_PGA("DMIC L2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1108 SND_SOC_DAPM_PGA("DMIC R2", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1110 SND_SOC_DAPM_SUPPLY("DMIC CLK", SND_SOC_NOPM
, 0, 0,
1111 set_dmic_clk
, SND_SOC_DAPM_PRE_PMU
),
1112 SND_SOC_DAPM_SUPPLY("DMIC1 Power", RT5640_DMIC
, RT5640_DMIC_1_EN_SFT
, 0,
1114 SND_SOC_DAPM_SUPPLY("DMIC2 Power", RT5640_DMIC
, RT5640_DMIC_2_EN_SFT
, 0,
1117 SND_SOC_DAPM_PGA("BST1", RT5640_PWR_ANLG2
,
1118 RT5640_PWR_BST1_BIT
, 0, NULL
, 0),
1119 SND_SOC_DAPM_PGA("BST2", RT5640_PWR_ANLG2
,
1120 RT5640_PWR_BST4_BIT
, 0, NULL
, 0),
1121 SND_SOC_DAPM_PGA("BST3", RT5640_PWR_ANLG2
,
1122 RT5640_PWR_BST2_BIT
, 0, NULL
, 0),
1124 SND_SOC_DAPM_PGA("INL VOL", RT5640_PWR_VOL
,
1125 RT5640_PWR_IN_L_BIT
, 0, NULL
, 0),
1126 SND_SOC_DAPM_PGA("INR VOL", RT5640_PWR_VOL
,
1127 RT5640_PWR_IN_R_BIT
, 0, NULL
, 0),
1129 SND_SOC_DAPM_MIXER("RECMIXL", RT5640_PWR_MIXER
, RT5640_PWR_RM_L_BIT
, 0,
1130 rt5640_rec_l_mix
, ARRAY_SIZE(rt5640_rec_l_mix
)),
1131 SND_SOC_DAPM_MIXER("RECMIXR", RT5640_PWR_MIXER
, RT5640_PWR_RM_R_BIT
, 0,
1132 rt5640_rec_r_mix
, ARRAY_SIZE(rt5640_rec_r_mix
)),
1134 SND_SOC_DAPM_ADC("ADC L", NULL
, RT5640_PWR_DIG1
,
1135 RT5640_PWR_ADC_L_BIT
, 0),
1136 SND_SOC_DAPM_ADC("ADC R", NULL
, RT5640_PWR_DIG1
,
1137 RT5640_PWR_ADC_R_BIT
, 0),
1139 SND_SOC_DAPM_MUX("Stereo ADC L2 Mux", SND_SOC_NOPM
, 0, 0,
1140 &rt5640_sto_adc_2_mux
),
1141 SND_SOC_DAPM_MUX("Stereo ADC R2 Mux", SND_SOC_NOPM
, 0, 0,
1142 &rt5640_sto_adc_2_mux
),
1143 SND_SOC_DAPM_MUX("Stereo ADC L1 Mux", SND_SOC_NOPM
, 0, 0,
1144 &rt5640_sto_adc_1_mux
),
1145 SND_SOC_DAPM_MUX("Stereo ADC R1 Mux", SND_SOC_NOPM
, 0, 0,
1146 &rt5640_sto_adc_1_mux
),
1147 SND_SOC_DAPM_MUX("Mono ADC L2 Mux", SND_SOC_NOPM
, 0, 0,
1148 &rt5640_mono_adc_l2_mux
),
1149 SND_SOC_DAPM_MUX("Mono ADC L1 Mux", SND_SOC_NOPM
, 0, 0,
1150 &rt5640_mono_adc_l1_mux
),
1151 SND_SOC_DAPM_MUX("Mono ADC R1 Mux", SND_SOC_NOPM
, 0, 0,
1152 &rt5640_mono_adc_r1_mux
),
1153 SND_SOC_DAPM_MUX("Mono ADC R2 Mux", SND_SOC_NOPM
, 0, 0,
1154 &rt5640_mono_adc_r2_mux
),
1156 SND_SOC_DAPM_SUPPLY("Stereo Filter", RT5640_PWR_DIG2
,
1157 RT5640_PWR_ADC_SF_BIT
, 0, NULL
, 0),
1158 SND_SOC_DAPM_MIXER("Stereo ADC MIXL", SND_SOC_NOPM
, 0, 0,
1159 rt5640_sto_adc_l_mix
, ARRAY_SIZE(rt5640_sto_adc_l_mix
)),
1160 SND_SOC_DAPM_MIXER("Stereo ADC MIXR", SND_SOC_NOPM
, 0, 0,
1161 rt5640_sto_adc_r_mix
, ARRAY_SIZE(rt5640_sto_adc_r_mix
)),
1162 SND_SOC_DAPM_SUPPLY("Mono Left Filter", RT5640_PWR_DIG2
,
1163 RT5640_PWR_ADC_MF_L_BIT
, 0, NULL
, 0),
1164 SND_SOC_DAPM_MIXER("Mono ADC MIXL", SND_SOC_NOPM
, 0, 0,
1165 rt5640_mono_adc_l_mix
, ARRAY_SIZE(rt5640_mono_adc_l_mix
)),
1166 SND_SOC_DAPM_SUPPLY("Mono Right Filter", RT5640_PWR_DIG2
,
1167 RT5640_PWR_ADC_MF_R_BIT
, 0, NULL
, 0),
1168 SND_SOC_DAPM_MIXER("Mono ADC MIXR", SND_SOC_NOPM
, 0, 0,
1169 rt5640_mono_adc_r_mix
, ARRAY_SIZE(rt5640_mono_adc_r_mix
)),
1171 /* Digital Interface */
1172 SND_SOC_DAPM_SUPPLY("I2S1", RT5640_PWR_DIG1
,
1173 RT5640_PWR_I2S1_BIT
, 0, NULL
, 0),
1174 SND_SOC_DAPM_PGA("IF1 DAC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1175 SND_SOC_DAPM_PGA("IF1 DAC L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1176 SND_SOC_DAPM_PGA("IF1 DAC R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1177 SND_SOC_DAPM_PGA("IF1 ADC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1178 SND_SOC_DAPM_PGA("IF1 ADC L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1179 SND_SOC_DAPM_PGA("IF1 ADC R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1180 SND_SOC_DAPM_SUPPLY("I2S2", RT5640_PWR_DIG1
,
1181 RT5640_PWR_I2S2_BIT
, 0, NULL
, 0),
1182 SND_SOC_DAPM_PGA("IF2 DAC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1183 SND_SOC_DAPM_PGA("IF2 DAC L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1184 SND_SOC_DAPM_PGA("IF2 DAC R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1185 SND_SOC_DAPM_PGA("IF2 ADC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1186 SND_SOC_DAPM_PGA("IF2 ADC L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1187 SND_SOC_DAPM_PGA("IF2 ADC R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1188 /* Digital Interface Select */
1189 SND_SOC_DAPM_MUX("DAI1 RX Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dai_mux
),
1190 SND_SOC_DAPM_MUX("DAI1 TX Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dai_mux
),
1191 SND_SOC_DAPM_MUX("DAI1 IF1 Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dai_mux
),
1192 SND_SOC_DAPM_MUX("DAI1 IF2 Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dai_mux
),
1193 SND_SOC_DAPM_MUX("SDI1 TX Mux", SND_SOC_NOPM
, 0, 0, &rt5640_sdi_mux
),
1194 SND_SOC_DAPM_MUX("DAI2 RX Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dai_mux
),
1195 SND_SOC_DAPM_MUX("DAI2 TX Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dai_mux
),
1196 SND_SOC_DAPM_MUX("DAI2 IF1 Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dai_mux
),
1197 SND_SOC_DAPM_MUX("DAI2 IF2 Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dai_mux
),
1198 SND_SOC_DAPM_MUX("SDI2 TX Mux", SND_SOC_NOPM
, 0, 0, &rt5640_sdi_mux
),
1199 /* Audio Interface */
1200 SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM
, 0, 0),
1201 SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0, SND_SOC_NOPM
, 0, 0),
1202 SND_SOC_DAPM_AIF_IN("AIF2RX", "AIF2 Playback", 0, SND_SOC_NOPM
, 0, 0),
1203 SND_SOC_DAPM_AIF_OUT("AIF2TX", "AIF2 Capture", 0, SND_SOC_NOPM
, 0, 0),
1206 /* DAC mixer before sound effect */
1207 SND_SOC_DAPM_MIXER("DAC MIXL", SND_SOC_NOPM
, 0, 0,
1208 rt5640_dac_l_mix
, ARRAY_SIZE(rt5640_dac_l_mix
)),
1209 SND_SOC_DAPM_MIXER("DAC MIXR", SND_SOC_NOPM
, 0, 0,
1210 rt5640_dac_r_mix
, ARRAY_SIZE(rt5640_dac_r_mix
)),
1213 SND_SOC_DAPM_MIXER("Mono DAC MIXL", SND_SOC_NOPM
, 0, 0,
1214 rt5640_mono_dac_l_mix
, ARRAY_SIZE(rt5640_mono_dac_l_mix
)),
1215 SND_SOC_DAPM_MIXER("Mono DAC MIXR", SND_SOC_NOPM
, 0, 0,
1216 rt5640_mono_dac_r_mix
, ARRAY_SIZE(rt5640_mono_dac_r_mix
)),
1217 SND_SOC_DAPM_MIXER("DIG MIXL", SND_SOC_NOPM
, 0, 0,
1218 rt5640_dig_l_mix
, ARRAY_SIZE(rt5640_dig_l_mix
)),
1219 SND_SOC_DAPM_MIXER("DIG MIXR", SND_SOC_NOPM
, 0, 0,
1220 rt5640_dig_r_mix
, ARRAY_SIZE(rt5640_dig_r_mix
)),
1222 SND_SOC_DAPM_DAC("DAC L1", NULL
, SND_SOC_NOPM
,
1224 SND_SOC_DAPM_DAC("DAC R1", NULL
, SND_SOC_NOPM
,
1226 SND_SOC_DAPM_SUPPLY("DAC L1 Power", RT5640_PWR_DIG1
,
1227 RT5640_PWR_DAC_L1_BIT
, 0, NULL
, 0),
1228 SND_SOC_DAPM_SUPPLY("DAC R1 Power", RT5640_PWR_DIG1
,
1229 RT5640_PWR_DAC_R1_BIT
, 0, NULL
, 0),
1230 SND_SOC_DAPM_SUPPLY("DAC L2 Power", RT5640_PWR_DIG1
,
1231 RT5640_PWR_DAC_L2_BIT
, 0, NULL
, 0),
1232 SND_SOC_DAPM_SUPPLY("DAC R2 Power", RT5640_PWR_DIG1
,
1233 RT5640_PWR_DAC_R2_BIT
, 0, NULL
, 0),
1235 SND_SOC_DAPM_MIXER("SPK MIXL", RT5640_PWR_MIXER
, RT5640_PWR_SM_L_BIT
,
1236 0, rt5640_spk_l_mix
, ARRAY_SIZE(rt5640_spk_l_mix
)),
1237 SND_SOC_DAPM_MIXER("SPK MIXR", RT5640_PWR_MIXER
, RT5640_PWR_SM_R_BIT
,
1238 0, rt5640_spk_r_mix
, ARRAY_SIZE(rt5640_spk_r_mix
)),
1240 SND_SOC_DAPM_PGA("SPKVOL L", RT5640_PWR_VOL
,
1241 RT5640_PWR_SV_L_BIT
, 0, NULL
, 0),
1242 SND_SOC_DAPM_PGA("SPKVOL R", RT5640_PWR_VOL
,
1243 RT5640_PWR_SV_R_BIT
, 0, NULL
, 0),
1244 SND_SOC_DAPM_PGA("OUTVOL L", RT5640_PWR_VOL
,
1245 RT5640_PWR_OV_L_BIT
, 0, NULL
, 0),
1246 SND_SOC_DAPM_PGA("OUTVOL R", RT5640_PWR_VOL
,
1247 RT5640_PWR_OV_R_BIT
, 0, NULL
, 0),
1248 SND_SOC_DAPM_PGA("HPOVOL L", RT5640_PWR_VOL
,
1249 RT5640_PWR_HV_L_BIT
, 0, NULL
, 0),
1250 SND_SOC_DAPM_PGA("HPOVOL R", RT5640_PWR_VOL
,
1251 RT5640_PWR_HV_R_BIT
, 0, NULL
, 0),
1252 /* SPO/HPO/LOUT/Mono Mixer */
1253 SND_SOC_DAPM_MIXER("SPOL MIX", SND_SOC_NOPM
, 0,
1254 0, rt5640_spo_l_mix
, ARRAY_SIZE(rt5640_spo_l_mix
)),
1255 SND_SOC_DAPM_MIXER("SPOR MIX", SND_SOC_NOPM
, 0,
1256 0, rt5640_spo_r_mix
, ARRAY_SIZE(rt5640_spo_r_mix
)),
1257 SND_SOC_DAPM_MIXER("LOUT MIX", SND_SOC_NOPM
, 0, 0,
1258 rt5640_lout_mix
, ARRAY_SIZE(rt5640_lout_mix
)),
1259 SND_SOC_DAPM_SUPPLY_S("Improve HP Amp Drv", 1, SND_SOC_NOPM
,
1260 0, 0, rt5640_hp_power_event
, SND_SOC_DAPM_POST_PMU
),
1261 SND_SOC_DAPM_PGA_S("HP Amp", 1, SND_SOC_NOPM
, 0, 0,
1263 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMU
),
1264 SND_SOC_DAPM_PGA_S("LOUT amp", 1, SND_SOC_NOPM
, 0, 0,
1266 SND_SOC_DAPM_PRE_PMD
| SND_SOC_DAPM_POST_PMU
),
1267 SND_SOC_DAPM_SUPPLY("HP L Amp", RT5640_PWR_ANLG1
,
1268 RT5640_PWR_HP_L_BIT
, 0, NULL
, 0),
1269 SND_SOC_DAPM_SUPPLY("HP R Amp", RT5640_PWR_ANLG1
,
1270 RT5640_PWR_HP_R_BIT
, 0, NULL
, 0),
1271 SND_SOC_DAPM_SUPPLY("Improve SPK Amp Drv", RT5640_PWR_DIG1
,
1272 RT5640_PWR_CLS_D_BIT
, 0, NULL
, 0),
1275 SND_SOC_DAPM_SWITCH("Speaker L Playback", SND_SOC_NOPM
, 0, 0,
1276 &spk_l_enable_control
),
1277 SND_SOC_DAPM_SWITCH("Speaker R Playback", SND_SOC_NOPM
, 0, 0,
1278 &spk_r_enable_control
),
1279 SND_SOC_DAPM_SWITCH("HP L Playback", SND_SOC_NOPM
, 0, 0,
1280 &hp_l_enable_control
),
1281 SND_SOC_DAPM_SWITCH("HP R Playback", SND_SOC_NOPM
, 0, 0,
1282 &hp_r_enable_control
),
1283 SND_SOC_DAPM_POST("HP Post", rt5640_hp_post_event
),
1285 SND_SOC_DAPM_OUTPUT("SPOLP"),
1286 SND_SOC_DAPM_OUTPUT("SPOLN"),
1287 SND_SOC_DAPM_OUTPUT("SPORP"),
1288 SND_SOC_DAPM_OUTPUT("SPORN"),
1289 SND_SOC_DAPM_OUTPUT("HPOL"),
1290 SND_SOC_DAPM_OUTPUT("HPOR"),
1291 SND_SOC_DAPM_OUTPUT("LOUTL"),
1292 SND_SOC_DAPM_OUTPUT("LOUTR"),
1295 static const struct snd_soc_dapm_widget rt5640_specific_dapm_widgets
[] = {
1297 SND_SOC_DAPM_PGA("Audio DSP", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1299 SND_SOC_DAPM_PGA("ANC", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1301 /* DAC2 channel Mux */
1302 SND_SOC_DAPM_MUX("DAC L2 Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dac_l2_mux
),
1303 SND_SOC_DAPM_MUX("DAC R2 Mux", SND_SOC_NOPM
, 0, 0, &rt5640_dac_r2_mux
),
1305 SND_SOC_DAPM_MIXER("Stereo DAC MIXL", SND_SOC_NOPM
, 0, 0,
1306 rt5640_sto_dac_l_mix
, ARRAY_SIZE(rt5640_sto_dac_l_mix
)),
1307 SND_SOC_DAPM_MIXER("Stereo DAC MIXR", SND_SOC_NOPM
, 0, 0,
1308 rt5640_sto_dac_r_mix
, ARRAY_SIZE(rt5640_sto_dac_r_mix
)),
1310 SND_SOC_DAPM_DAC("DAC R2", NULL
, SND_SOC_NOPM
, 0,
1312 SND_SOC_DAPM_DAC("DAC L2", NULL
, SND_SOC_NOPM
, 0,
1315 SND_SOC_DAPM_MIXER("OUT MIXL", RT5640_PWR_MIXER
, RT5640_PWR_OM_L_BIT
,
1316 0, rt5640_out_l_mix
, ARRAY_SIZE(rt5640_out_l_mix
)),
1317 SND_SOC_DAPM_MIXER("OUT MIXR", RT5640_PWR_MIXER
, RT5640_PWR_OM_R_BIT
,
1318 0, rt5640_out_r_mix
, ARRAY_SIZE(rt5640_out_r_mix
)),
1320 SND_SOC_DAPM_MIXER("HPO MIX L", SND_SOC_NOPM
, 0, 0,
1321 rt5640_hpo_mix
, ARRAY_SIZE(rt5640_hpo_mix
)),
1322 SND_SOC_DAPM_MIXER("HPO MIX R", SND_SOC_NOPM
, 0, 0,
1323 rt5640_hpo_mix
, ARRAY_SIZE(rt5640_hpo_mix
)),
1325 SND_SOC_DAPM_MIXER("Mono MIX", RT5640_PWR_ANLG1
, RT5640_PWR_MM_BIT
, 0,
1326 rt5640_mono_mix
, ARRAY_SIZE(rt5640_mono_mix
)),
1327 SND_SOC_DAPM_SUPPLY("Improve MONO Amp Drv", RT5640_PWR_ANLG1
,
1328 RT5640_PWR_MA_BIT
, 0, NULL
, 0),
1330 SND_SOC_DAPM_OUTPUT("MONOP"),
1331 SND_SOC_DAPM_OUTPUT("MONON"),
1334 static const struct snd_soc_dapm_widget rt5639_specific_dapm_widgets
[] = {
1335 SND_SOC_DAPM_MIXER("Stereo DAC MIXL", SND_SOC_NOPM
, 0, 0,
1336 rt5639_sto_dac_l_mix
, ARRAY_SIZE(rt5639_sto_dac_l_mix
)),
1337 SND_SOC_DAPM_MIXER("Stereo DAC MIXR", SND_SOC_NOPM
, 0, 0,
1338 rt5639_sto_dac_r_mix
, ARRAY_SIZE(rt5639_sto_dac_r_mix
)),
1340 SND_SOC_DAPM_MIXER("OUT MIXL", RT5640_PWR_MIXER
, RT5640_PWR_OM_L_BIT
,
1341 0, rt5639_out_l_mix
, ARRAY_SIZE(rt5639_out_l_mix
)),
1342 SND_SOC_DAPM_MIXER("OUT MIXR", RT5640_PWR_MIXER
, RT5640_PWR_OM_R_BIT
,
1343 0, rt5639_out_r_mix
, ARRAY_SIZE(rt5639_out_r_mix
)),
1345 SND_SOC_DAPM_MIXER("HPO MIX L", SND_SOC_NOPM
, 0, 0,
1346 rt5639_hpo_mix
, ARRAY_SIZE(rt5639_hpo_mix
)),
1347 SND_SOC_DAPM_MIXER("HPO MIX R", SND_SOC_NOPM
, 0, 0,
1348 rt5639_hpo_mix
, ARRAY_SIZE(rt5639_hpo_mix
)),
1351 static const struct snd_soc_dapm_route rt5640_dapm_routes
[] = {
1352 { "I2S1", NULL
, "Stereo Filter ASRC", is_using_asrc
},
1353 { "I2S2", NULL
, "I2S2 ASRC", is_using_asrc
},
1354 { "I2S2", NULL
, "I2S2 Filter ASRC", is_using_asrc
},
1355 { "DMIC1", NULL
, "DMIC1 ASRC", is_using_asrc
},
1356 { "DMIC2", NULL
, "DMIC2 ASRC", is_using_asrc
},
1358 {"IN1P", NULL
, "LDO2"},
1359 {"IN2P", NULL
, "LDO2"},
1360 {"IN3P", NULL
, "LDO2"},
1362 {"DMIC L1", NULL
, "DMIC1"},
1363 {"DMIC R1", NULL
, "DMIC1"},
1364 {"DMIC L2", NULL
, "DMIC2"},
1365 {"DMIC R2", NULL
, "DMIC2"},
1367 {"BST1", NULL
, "IN1P"},
1368 {"BST1", NULL
, "IN1N"},
1369 {"BST2", NULL
, "IN2P"},
1370 {"BST2", NULL
, "IN2N"},
1371 {"BST3", NULL
, "IN3P"},
1372 {"BST3", NULL
, "IN3N"},
1374 {"INL VOL", NULL
, "IN2P"},
1375 {"INR VOL", NULL
, "IN2N"},
1377 {"RECMIXL", "HPOL Switch", "HPOL"},
1378 {"RECMIXL", "INL Switch", "INL VOL"},
1379 {"RECMIXL", "BST3 Switch", "BST3"},
1380 {"RECMIXL", "BST2 Switch", "BST2"},
1381 {"RECMIXL", "BST1 Switch", "BST1"},
1382 {"RECMIXL", "OUT MIXL Switch", "OUT MIXL"},
1384 {"RECMIXR", "HPOR Switch", "HPOR"},
1385 {"RECMIXR", "INR Switch", "INR VOL"},
1386 {"RECMIXR", "BST3 Switch", "BST3"},
1387 {"RECMIXR", "BST2 Switch", "BST2"},
1388 {"RECMIXR", "BST1 Switch", "BST1"},
1389 {"RECMIXR", "OUT MIXR Switch", "OUT MIXR"},
1391 {"ADC L", NULL
, "RECMIXL"},
1392 {"ADC R", NULL
, "RECMIXR"},
1394 {"DMIC L1", NULL
, "DMIC CLK"},
1395 {"DMIC L1", NULL
, "DMIC1 Power"},
1396 {"DMIC R1", NULL
, "DMIC CLK"},
1397 {"DMIC R1", NULL
, "DMIC1 Power"},
1398 {"DMIC L2", NULL
, "DMIC CLK"},
1399 {"DMIC L2", NULL
, "DMIC2 Power"},
1400 {"DMIC R2", NULL
, "DMIC CLK"},
1401 {"DMIC R2", NULL
, "DMIC2 Power"},
1403 {"Stereo ADC L2 Mux", "DMIC1", "DMIC L1"},
1404 {"Stereo ADC L2 Mux", "DMIC2", "DMIC L2"},
1405 {"Stereo ADC L2 Mux", "DIG MIX", "DIG MIXL"},
1406 {"Stereo ADC L1 Mux", "ADC", "ADC L"},
1407 {"Stereo ADC L1 Mux", "DIG MIX", "DIG MIXL"},
1409 {"Stereo ADC R1 Mux", "ADC", "ADC R"},
1410 {"Stereo ADC R1 Mux", "DIG MIX", "DIG MIXR"},
1411 {"Stereo ADC R2 Mux", "DMIC1", "DMIC R1"},
1412 {"Stereo ADC R2 Mux", "DMIC2", "DMIC R2"},
1413 {"Stereo ADC R2 Mux", "DIG MIX", "DIG MIXR"},
1415 {"Mono ADC L2 Mux", "DMIC L1", "DMIC L1"},
1416 {"Mono ADC L2 Mux", "DMIC L2", "DMIC L2"},
1417 {"Mono ADC L2 Mux", "Mono DAC MIXL", "Mono DAC MIXL"},
1418 {"Mono ADC L1 Mux", "Mono DAC MIXL", "Mono DAC MIXL"},
1419 {"Mono ADC L1 Mux", "ADCL", "ADC L"},
1421 {"Mono ADC R1 Mux", "Mono DAC MIXR", "Mono DAC MIXR"},
1422 {"Mono ADC R1 Mux", "ADCR", "ADC R"},
1423 {"Mono ADC R2 Mux", "DMIC R1", "DMIC R1"},
1424 {"Mono ADC R2 Mux", "DMIC R2", "DMIC R2"},
1425 {"Mono ADC R2 Mux", "Mono DAC MIXR", "Mono DAC MIXR"},
1427 {"Stereo ADC MIXL", "ADC1 Switch", "Stereo ADC L1 Mux"},
1428 {"Stereo ADC MIXL", "ADC2 Switch", "Stereo ADC L2 Mux"},
1429 {"Stereo ADC MIXL", NULL
, "Stereo Filter"},
1430 {"Stereo Filter", NULL
, "PLL1", is_sys_clk_from_pll
},
1432 {"Stereo ADC MIXR", "ADC1 Switch", "Stereo ADC R1 Mux"},
1433 {"Stereo ADC MIXR", "ADC2 Switch", "Stereo ADC R2 Mux"},
1434 {"Stereo ADC MIXR", NULL
, "Stereo Filter"},
1435 {"Stereo Filter", NULL
, "PLL1", is_sys_clk_from_pll
},
1437 {"Mono ADC MIXL", "ADC1 Switch", "Mono ADC L1 Mux"},
1438 {"Mono ADC MIXL", "ADC2 Switch", "Mono ADC L2 Mux"},
1439 {"Mono ADC MIXL", NULL
, "Mono Left Filter"},
1440 {"Mono Left Filter", NULL
, "PLL1", is_sys_clk_from_pll
},
1442 {"Mono ADC MIXR", "ADC1 Switch", "Mono ADC R1 Mux"},
1443 {"Mono ADC MIXR", "ADC2 Switch", "Mono ADC R2 Mux"},
1444 {"Mono ADC MIXR", NULL
, "Mono Right Filter"},
1445 {"Mono Right Filter", NULL
, "PLL1", is_sys_clk_from_pll
},
1447 {"IF2 ADC L", NULL
, "Mono ADC MIXL"},
1448 {"IF2 ADC R", NULL
, "Mono ADC MIXR"},
1449 {"IF1 ADC L", NULL
, "Stereo ADC MIXL"},
1450 {"IF1 ADC R", NULL
, "Stereo ADC MIXR"},
1452 {"IF1 ADC", NULL
, "I2S1"},
1453 {"IF1 ADC", NULL
, "IF1 ADC L"},
1454 {"IF1 ADC", NULL
, "IF1 ADC R"},
1455 {"IF2 ADC", NULL
, "I2S2"},
1456 {"IF2 ADC", NULL
, "IF2 ADC L"},
1457 {"IF2 ADC", NULL
, "IF2 ADC R"},
1459 {"DAI1 TX Mux", "1:1|2:2", "IF1 ADC"},
1460 {"DAI1 TX Mux", "1:2|2:1", "IF2 ADC"},
1461 {"DAI1 IF1 Mux", "1:1|2:1", "IF1 ADC"},
1462 {"DAI1 IF2 Mux", "1:1|2:1", "IF2 ADC"},
1463 {"SDI1 TX Mux", "IF1", "DAI1 IF1 Mux"},
1464 {"SDI1 TX Mux", "IF2", "DAI1 IF2 Mux"},
1466 {"DAI2 TX Mux", "1:2|2:1", "IF1 ADC"},
1467 {"DAI2 TX Mux", "1:1|2:2", "IF2 ADC"},
1468 {"DAI2 IF1 Mux", "1:2|2:2", "IF1 ADC"},
1469 {"DAI2 IF2 Mux", "1:2|2:2", "IF2 ADC"},
1470 {"SDI2 TX Mux", "IF1", "DAI2 IF1 Mux"},
1471 {"SDI2 TX Mux", "IF2", "DAI2 IF2 Mux"},
1473 {"AIF1TX", NULL
, "DAI1 TX Mux"},
1474 {"AIF1TX", NULL
, "SDI1 TX Mux"},
1475 {"AIF2TX", NULL
, "DAI2 TX Mux"},
1476 {"AIF2TX", NULL
, "SDI2 TX Mux"},
1478 {"DAI1 RX Mux", "1:1|2:2", "AIF1RX"},
1479 {"DAI1 RX Mux", "1:1|2:1", "AIF1RX"},
1480 {"DAI1 RX Mux", "1:2|2:1", "AIF2RX"},
1481 {"DAI1 RX Mux", "1:2|2:2", "AIF2RX"},
1483 {"DAI2 RX Mux", "1:2|2:1", "AIF1RX"},
1484 {"DAI2 RX Mux", "1:1|2:1", "AIF1RX"},
1485 {"DAI2 RX Mux", "1:1|2:2", "AIF2RX"},
1486 {"DAI2 RX Mux", "1:2|2:2", "AIF2RX"},
1488 {"IF1 DAC", NULL
, "I2S1"},
1489 {"IF1 DAC", NULL
, "DAI1 RX Mux"},
1490 {"IF2 DAC", NULL
, "I2S2"},
1491 {"IF2 DAC", NULL
, "DAI2 RX Mux"},
1493 {"IF1 DAC L", NULL
, "IF1 DAC"},
1494 {"IF1 DAC R", NULL
, "IF1 DAC"},
1495 {"IF2 DAC L", NULL
, "IF2 DAC"},
1496 {"IF2 DAC R", NULL
, "IF2 DAC"},
1498 {"DAC MIXL", "Stereo ADC Switch", "Stereo ADC MIXL"},
1499 {"DAC MIXL", "INF1 Switch", "IF1 DAC L"},
1500 {"DAC MIXL", NULL
, "DAC L1 Power"},
1501 {"DAC MIXR", "Stereo ADC Switch", "Stereo ADC MIXR"},
1502 {"DAC MIXR", "INF1 Switch", "IF1 DAC R"},
1503 {"DAC MIXR", NULL
, "DAC R1 Power"},
1505 {"Stereo DAC MIXL", "DAC L1 Switch", "DAC MIXL"},
1506 {"Stereo DAC MIXR", "DAC R1 Switch", "DAC MIXR"},
1508 {"Mono DAC MIXL", "DAC L1 Switch", "DAC MIXL"},
1509 {"Mono DAC MIXR", "DAC R1 Switch", "DAC MIXR"},
1511 {"DIG MIXL", "DAC L1 Switch", "DAC MIXL"},
1512 {"DIG MIXR", "DAC R1 Switch", "DAC MIXR"},
1514 {"DAC L1", NULL
, "Stereo DAC MIXL"},
1515 {"DAC L1", NULL
, "PLL1", is_sys_clk_from_pll
},
1516 {"DAC L1", NULL
, "DAC L1 Power"},
1517 {"DAC R1", NULL
, "Stereo DAC MIXR"},
1518 {"DAC R1", NULL
, "PLL1", is_sys_clk_from_pll
},
1519 {"DAC R1", NULL
, "DAC R1 Power"},
1521 {"SPK MIXL", "REC MIXL Switch", "RECMIXL"},
1522 {"SPK MIXL", "INL Switch", "INL VOL"},
1523 {"SPK MIXL", "DAC L1 Switch", "DAC L1"},
1524 {"SPK MIXL", "OUT MIXL Switch", "OUT MIXL"},
1525 {"SPK MIXR", "REC MIXR Switch", "RECMIXR"},
1526 {"SPK MIXR", "INR Switch", "INR VOL"},
1527 {"SPK MIXR", "DAC R1 Switch", "DAC R1"},
1528 {"SPK MIXR", "OUT MIXR Switch", "OUT MIXR"},
1530 {"OUT MIXL", "BST1 Switch", "BST1"},
1531 {"OUT MIXL", "INL Switch", "INL VOL"},
1532 {"OUT MIXL", "REC MIXL Switch", "RECMIXL"},
1533 {"OUT MIXL", "DAC L1 Switch", "DAC L1"},
1535 {"OUT MIXR", "BST2 Switch", "BST2"},
1536 {"OUT MIXR", "BST1 Switch", "BST1"},
1537 {"OUT MIXR", "INR Switch", "INR VOL"},
1538 {"OUT MIXR", "REC MIXR Switch", "RECMIXR"},
1539 {"OUT MIXR", "DAC R1 Switch", "DAC R1"},
1541 {"SPKVOL L", NULL
, "SPK MIXL"},
1542 {"SPKVOL R", NULL
, "SPK MIXR"},
1543 {"HPOVOL L", NULL
, "OUT MIXL"},
1544 {"HPOVOL R", NULL
, "OUT MIXR"},
1545 {"OUTVOL L", NULL
, "OUT MIXL"},
1546 {"OUTVOL R", NULL
, "OUT MIXR"},
1548 {"SPOL MIX", "DAC R1 Switch", "DAC R1"},
1549 {"SPOL MIX", "DAC L1 Switch", "DAC L1"},
1550 {"SPOL MIX", "SPKVOL R Switch", "SPKVOL R"},
1551 {"SPOL MIX", "SPKVOL L Switch", "SPKVOL L"},
1552 {"SPOL MIX", "BST1 Switch", "BST1"},
1553 {"SPOR MIX", "DAC R1 Switch", "DAC R1"},
1554 {"SPOR MIX", "SPKVOL R Switch", "SPKVOL R"},
1555 {"SPOR MIX", "BST1 Switch", "BST1"},
1557 {"HPO MIX L", "HPO MIX DAC1 Switch", "DAC L1"},
1558 {"HPO MIX L", "HPO MIX HPVOL Switch", "HPOVOL L"},
1559 {"HPO MIX L", NULL
, "HP L Amp"},
1560 {"HPO MIX R", "HPO MIX DAC1 Switch", "DAC R1"},
1561 {"HPO MIX R", "HPO MIX HPVOL Switch", "HPOVOL R"},
1562 {"HPO MIX R", NULL
, "HP R Amp"},
1564 {"LOUT MIX", "DAC L1 Switch", "DAC L1"},
1565 {"LOUT MIX", "DAC R1 Switch", "DAC R1"},
1566 {"LOUT MIX", "OUTVOL L Switch", "OUTVOL L"},
1567 {"LOUT MIX", "OUTVOL R Switch", "OUTVOL R"},
1569 {"HP Amp", NULL
, "HPO MIX L"},
1570 {"HP Amp", NULL
, "HPO MIX R"},
1572 {"Speaker L Playback", "Switch", "SPOL MIX"},
1573 {"Speaker R Playback", "Switch", "SPOR MIX"},
1574 {"SPOLP", NULL
, "Speaker L Playback"},
1575 {"SPOLN", NULL
, "Speaker L Playback"},
1576 {"SPORP", NULL
, "Speaker R Playback"},
1577 {"SPORN", NULL
, "Speaker R Playback"},
1579 {"SPOLP", NULL
, "Improve SPK Amp Drv"},
1580 {"SPOLN", NULL
, "Improve SPK Amp Drv"},
1581 {"SPORP", NULL
, "Improve SPK Amp Drv"},
1582 {"SPORN", NULL
, "Improve SPK Amp Drv"},
1584 {"HPOL", NULL
, "Improve HP Amp Drv"},
1585 {"HPOR", NULL
, "Improve HP Amp Drv"},
1587 {"HP L Playback", "Switch", "HP Amp"},
1588 {"HP R Playback", "Switch", "HP Amp"},
1589 {"HPOL", NULL
, "HP L Playback"},
1590 {"HPOR", NULL
, "HP R Playback"},
1592 {"LOUT amp", NULL
, "LOUT MIX"},
1593 {"LOUTL", NULL
, "LOUT amp"},
1594 {"LOUTR", NULL
, "LOUT amp"},
1597 static const struct snd_soc_dapm_route rt5640_specific_dapm_routes
[] = {
1598 {"ANC", NULL
, "Stereo ADC MIXL"},
1599 {"ANC", NULL
, "Stereo ADC MIXR"},
1601 {"Audio DSP", NULL
, "DAC MIXL"},
1602 {"Audio DSP", NULL
, "DAC MIXR"},
1604 {"DAC L2 Mux", "IF2", "IF2 DAC L"},
1605 {"DAC L2 Mux", "Base L/R", "Audio DSP"},
1606 {"DAC L2 Mux", NULL
, "DAC L2 Power"},
1607 {"DAC R2 Mux", "IF2", "IF2 DAC R"},
1608 {"DAC R2 Mux", NULL
, "DAC R2 Power"},
1610 {"Stereo DAC MIXL", "DAC L2 Switch", "DAC L2 Mux"},
1611 {"Stereo DAC MIXL", "ANC Switch", "ANC"},
1612 {"Stereo DAC MIXR", "DAC R2 Switch", "DAC R2 Mux"},
1613 {"Stereo DAC MIXR", "ANC Switch", "ANC"},
1615 {"Mono DAC MIXL", "DAC L2 Switch", "DAC L2 Mux"},
1616 {"Mono DAC MIXL", "DAC R2 Switch", "DAC R2 Mux"},
1618 {"Mono DAC MIXR", "DAC R2 Switch", "DAC R2 Mux"},
1619 {"Mono DAC MIXR", "DAC L2 Switch", "DAC L2 Mux"},
1621 {"DIG MIXR", "DAC R2 Switch", "DAC R2 Mux"},
1622 {"DIG MIXL", "DAC L2 Switch", "DAC L2 Mux"},
1624 {"DAC L2", NULL
, "Mono DAC MIXL"},
1625 {"DAC L2", NULL
, "PLL1", is_sys_clk_from_pll
},
1626 {"DAC L2", NULL
, "DAC L2 Power"},
1627 {"DAC R2", NULL
, "Mono DAC MIXR"},
1628 {"DAC R2", NULL
, "PLL1", is_sys_clk_from_pll
},
1629 {"DAC R2", NULL
, "DAC R2 Power"},
1631 {"SPK MIXL", "DAC L2 Switch", "DAC L2"},
1632 {"SPK MIXR", "DAC R2 Switch", "DAC R2"},
1634 {"OUT MIXL", "SPK MIXL Switch", "SPK MIXL"},
1635 {"OUT MIXR", "SPK MIXR Switch", "SPK MIXR"},
1637 {"OUT MIXL", "DAC R2 Switch", "DAC R2"},
1638 {"OUT MIXL", "DAC L2 Switch", "DAC L2"},
1640 {"OUT MIXR", "DAC L2 Switch", "DAC L2"},
1641 {"OUT MIXR", "DAC R2 Switch", "DAC R2"},
1643 {"HPO MIX L", "HPO MIX DAC2 Switch", "DAC L2"},
1644 {"HPO MIX R", "HPO MIX DAC2 Switch", "DAC R2"},
1646 {"Mono MIX", "DAC R2 Switch", "DAC R2"},
1647 {"Mono MIX", "DAC L2 Switch", "DAC L2"},
1648 {"Mono MIX", "OUTVOL R Switch", "OUTVOL R"},
1649 {"Mono MIX", "OUTVOL L Switch", "OUTVOL L"},
1650 {"Mono MIX", "BST1 Switch", "BST1"},
1652 {"MONOP", NULL
, "Mono MIX"},
1653 {"MONON", NULL
, "Mono MIX"},
1654 {"MONOP", NULL
, "Improve MONO Amp Drv"},
1657 static const struct snd_soc_dapm_route rt5639_specific_dapm_routes
[] = {
1658 {"Stereo DAC MIXL", "DAC L2 Switch", "IF2 DAC L"},
1659 {"Stereo DAC MIXR", "DAC R2 Switch", "IF2 DAC R"},
1661 {"Mono DAC MIXL", "DAC L2 Switch", "IF2 DAC L"},
1662 {"Mono DAC MIXL", "DAC R2 Switch", "IF2 DAC R"},
1664 {"Mono DAC MIXR", "DAC R2 Switch", "IF2 DAC R"},
1665 {"Mono DAC MIXR", "DAC L2 Switch", "IF2 DAC L"},
1667 {"DIG MIXL", "DAC L2 Switch", "IF2 DAC L"},
1668 {"DIG MIXR", "DAC R2 Switch", "IF2 DAC R"},
1670 {"IF2 DAC L", NULL
, "DAC L2 Power"},
1671 {"IF2 DAC R", NULL
, "DAC R2 Power"},
1674 static int get_sdp_info(struct snd_soc_codec
*codec
, int dai_id
)
1681 val
= snd_soc_read(codec
, RT5640_I2S1_SDP
);
1682 val
= (val
& RT5640_I2S_IF_MASK
) >> RT5640_I2S_IF_SFT
;
1688 ret
|= RT5640_U_IF1
;
1691 ret
|= RT5640_U_IF1
;
1694 ret
|= RT5640_U_IF2
;
1703 ret
|= RT5640_U_IF1
;
1706 ret
|= RT5640_U_IF1
;
1709 ret
|= RT5640_U_IF2
;
1722 static int rt5640_hw_params(struct snd_pcm_substream
*substream
,
1723 struct snd_pcm_hw_params
*params
, struct snd_soc_dai
*dai
)
1725 struct snd_soc_codec
*codec
= dai
->codec
;
1726 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
1727 unsigned int val_len
= 0, val_clk
, mask_clk
;
1728 int dai_sel
, pre_div
, bclk_ms
, frame_size
;
1730 rt5640
->lrck
[dai
->id
] = params_rate(params
);
1731 pre_div
= rl6231_get_clk_info(rt5640
->sysclk
, rt5640
->lrck
[dai
->id
]);
1733 dev_err(codec
->dev
, "Unsupported clock setting %d for DAI %d\n",
1734 rt5640
->lrck
[dai
->id
], dai
->id
);
1737 frame_size
= snd_soc_params_to_frame_size(params
);
1738 if (frame_size
< 0) {
1739 dev_err(codec
->dev
, "Unsupported frame size: %d\n", frame_size
);
1742 if (frame_size
> 32)
1746 rt5640
->bclk
[dai
->id
] = rt5640
->lrck
[dai
->id
] * (32 << bclk_ms
);
1748 dev_dbg(dai
->dev
, "bclk is %dHz and lrck is %dHz\n",
1749 rt5640
->bclk
[dai
->id
], rt5640
->lrck
[dai
->id
]);
1750 dev_dbg(dai
->dev
, "bclk_ms is %d and pre_div is %d for iis %d\n",
1751 bclk_ms
, pre_div
, dai
->id
);
1753 switch (params_width(params
)) {
1757 val_len
|= RT5640_I2S_DL_20
;
1760 val_len
|= RT5640_I2S_DL_24
;
1763 val_len
|= RT5640_I2S_DL_8
;
1769 dai_sel
= get_sdp_info(codec
, dai
->id
);
1771 dev_err(codec
->dev
, "Failed to get sdp info: %d\n", dai_sel
);
1774 if (dai_sel
& RT5640_U_IF1
) {
1775 mask_clk
= RT5640_I2S_BCLK_MS1_MASK
| RT5640_I2S_PD1_MASK
;
1776 val_clk
= bclk_ms
<< RT5640_I2S_BCLK_MS1_SFT
|
1777 pre_div
<< RT5640_I2S_PD1_SFT
;
1778 snd_soc_update_bits(codec
, RT5640_I2S1_SDP
,
1779 RT5640_I2S_DL_MASK
, val_len
);
1780 snd_soc_update_bits(codec
, RT5640_ADDA_CLK1
, mask_clk
, val_clk
);
1782 if (dai_sel
& RT5640_U_IF2
) {
1783 mask_clk
= RT5640_I2S_BCLK_MS2_MASK
| RT5640_I2S_PD2_MASK
;
1784 val_clk
= bclk_ms
<< RT5640_I2S_BCLK_MS2_SFT
|
1785 pre_div
<< RT5640_I2S_PD2_SFT
;
1786 snd_soc_update_bits(codec
, RT5640_I2S2_SDP
,
1787 RT5640_I2S_DL_MASK
, val_len
);
1788 snd_soc_update_bits(codec
, RT5640_ADDA_CLK1
, mask_clk
, val_clk
);
1794 static int rt5640_set_dai_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
1796 struct snd_soc_codec
*codec
= dai
->codec
;
1797 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
1798 unsigned int reg_val
= 0;
1801 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
1802 case SND_SOC_DAIFMT_CBM_CFM
:
1803 rt5640
->master
[dai
->id
] = 1;
1805 case SND_SOC_DAIFMT_CBS_CFS
:
1806 reg_val
|= RT5640_I2S_MS_S
;
1807 rt5640
->master
[dai
->id
] = 0;
1813 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
1814 case SND_SOC_DAIFMT_NB_NF
:
1816 case SND_SOC_DAIFMT_IB_NF
:
1817 reg_val
|= RT5640_I2S_BP_INV
;
1823 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
1824 case SND_SOC_DAIFMT_I2S
:
1826 case SND_SOC_DAIFMT_LEFT_J
:
1827 reg_val
|= RT5640_I2S_DF_LEFT
;
1829 case SND_SOC_DAIFMT_DSP_A
:
1830 reg_val
|= RT5640_I2S_DF_PCM_A
;
1832 case SND_SOC_DAIFMT_DSP_B
:
1833 reg_val
|= RT5640_I2S_DF_PCM_B
;
1839 dai_sel
= get_sdp_info(codec
, dai
->id
);
1841 dev_err(codec
->dev
, "Failed to get sdp info: %d\n", dai_sel
);
1844 if (dai_sel
& RT5640_U_IF1
) {
1845 snd_soc_update_bits(codec
, RT5640_I2S1_SDP
,
1846 RT5640_I2S_MS_MASK
| RT5640_I2S_BP_MASK
|
1847 RT5640_I2S_DF_MASK
, reg_val
);
1849 if (dai_sel
& RT5640_U_IF2
) {
1850 snd_soc_update_bits(codec
, RT5640_I2S2_SDP
,
1851 RT5640_I2S_MS_MASK
| RT5640_I2S_BP_MASK
|
1852 RT5640_I2S_DF_MASK
, reg_val
);
1858 static int rt5640_set_dai_sysclk(struct snd_soc_dai
*dai
,
1859 int clk_id
, unsigned int freq
, int dir
)
1861 struct snd_soc_codec
*codec
= dai
->codec
;
1862 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
1863 unsigned int reg_val
= 0;
1865 if (freq
== rt5640
->sysclk
&& clk_id
== rt5640
->sysclk_src
)
1869 case RT5640_SCLK_S_MCLK
:
1870 reg_val
|= RT5640_SCLK_SRC_MCLK
;
1872 case RT5640_SCLK_S_PLL1
:
1873 reg_val
|= RT5640_SCLK_SRC_PLL1
;
1875 case RT5640_SCLK_S_RCCLK
:
1876 reg_val
|= RT5640_SCLK_SRC_RCCLK
;
1879 dev_err(codec
->dev
, "Invalid clock id (%d)\n", clk_id
);
1882 snd_soc_update_bits(codec
, RT5640_GLB_CLK
,
1883 RT5640_SCLK_SRC_MASK
, reg_val
);
1884 rt5640
->sysclk
= freq
;
1885 rt5640
->sysclk_src
= clk_id
;
1887 dev_dbg(dai
->dev
, "Sysclk is %dHz and clock id is %d\n", freq
, clk_id
);
1891 static int rt5640_set_dai_pll(struct snd_soc_dai
*dai
, int pll_id
, int source
,
1892 unsigned int freq_in
, unsigned int freq_out
)
1894 struct snd_soc_codec
*codec
= dai
->codec
;
1895 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
1896 struct rl6231_pll_code pll_code
;
1899 if (source
== rt5640
->pll_src
&& freq_in
== rt5640
->pll_in
&&
1900 freq_out
== rt5640
->pll_out
)
1903 if (!freq_in
|| !freq_out
) {
1904 dev_dbg(codec
->dev
, "PLL disabled\n");
1907 rt5640
->pll_out
= 0;
1908 snd_soc_update_bits(codec
, RT5640_GLB_CLK
,
1909 RT5640_SCLK_SRC_MASK
, RT5640_SCLK_SRC_MCLK
);
1914 case RT5640_PLL1_S_MCLK
:
1915 snd_soc_update_bits(codec
, RT5640_GLB_CLK
,
1916 RT5640_PLL1_SRC_MASK
, RT5640_PLL1_SRC_MCLK
);
1918 case RT5640_PLL1_S_BCLK1
:
1919 snd_soc_update_bits(codec
, RT5640_GLB_CLK
,
1920 RT5640_PLL1_SRC_MASK
, RT5640_PLL1_SRC_BCLK1
);
1922 case RT5640_PLL1_S_BCLK2
:
1923 snd_soc_update_bits(codec
, RT5640_GLB_CLK
,
1924 RT5640_PLL1_SRC_MASK
, RT5640_PLL1_SRC_BCLK2
);
1927 dev_err(codec
->dev
, "Unknown PLL source %d\n", source
);
1931 ret
= rl6231_pll_calc(freq_in
, freq_out
, &pll_code
);
1933 dev_err(codec
->dev
, "Unsupport input clock %d\n", freq_in
);
1937 dev_dbg(codec
->dev
, "bypass=%d m=%d n=%d k=%d\n",
1938 pll_code
.m_bp
, (pll_code
.m_bp
? 0 : pll_code
.m_code
),
1939 pll_code
.n_code
, pll_code
.k_code
);
1941 snd_soc_write(codec
, RT5640_PLL_CTRL1
,
1942 pll_code
.n_code
<< RT5640_PLL_N_SFT
| pll_code
.k_code
);
1943 snd_soc_write(codec
, RT5640_PLL_CTRL2
,
1944 (pll_code
.m_bp
? 0 : pll_code
.m_code
) << RT5640_PLL_M_SFT
|
1945 pll_code
.m_bp
<< RT5640_PLL_M_BP_SFT
);
1947 rt5640
->pll_in
= freq_in
;
1948 rt5640
->pll_out
= freq_out
;
1949 rt5640
->pll_src
= source
;
1954 static int rt5640_set_bias_level(struct snd_soc_codec
*codec
,
1955 enum snd_soc_bias_level level
)
1957 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
1961 case SND_SOC_BIAS_ON
:
1964 case SND_SOC_BIAS_PREPARE
:
1966 * SND_SOC_BIAS_PREPARE is called while preparing for a
1967 * transition to ON or away from ON. If current bias_level
1968 * is SND_SOC_BIAS_ON, then it is preparing for a transition
1969 * away from ON. Disable the clock in that case, otherwise
1972 if (IS_ERR(rt5640
->mclk
))
1975 if (snd_soc_codec_get_bias_level(codec
) == SND_SOC_BIAS_ON
) {
1976 clk_disable_unprepare(rt5640
->mclk
);
1978 ret
= clk_prepare_enable(rt5640
->mclk
);
1984 case SND_SOC_BIAS_STANDBY
:
1985 if (SND_SOC_BIAS_OFF
== snd_soc_codec_get_bias_level(codec
)) {
1986 snd_soc_update_bits(codec
, RT5640_PWR_ANLG1
,
1987 RT5640_PWR_VREF1
| RT5640_PWR_MB
|
1988 RT5640_PWR_BG
| RT5640_PWR_VREF2
,
1989 RT5640_PWR_VREF1
| RT5640_PWR_MB
|
1990 RT5640_PWR_BG
| RT5640_PWR_VREF2
);
1991 usleep_range(10000, 15000);
1992 snd_soc_update_bits(codec
, RT5640_PWR_ANLG1
,
1993 RT5640_PWR_FV1
| RT5640_PWR_FV2
,
1994 RT5640_PWR_FV1
| RT5640_PWR_FV2
);
1995 snd_soc_update_bits(codec
, RT5640_DUMMY1
,
1997 snd_soc_update_bits(codec
, RT5640_MICBIAS
,
2002 case SND_SOC_BIAS_OFF
:
2003 snd_soc_write(codec
, RT5640_DEPOP_M1
, 0x0004);
2004 snd_soc_write(codec
, RT5640_DEPOP_M2
, 0x1100);
2005 snd_soc_update_bits(codec
, RT5640_DUMMY1
, 0x1, 0);
2006 snd_soc_write(codec
, RT5640_PWR_DIG1
, 0x0000);
2007 snd_soc_write(codec
, RT5640_PWR_DIG2
, 0x0000);
2008 snd_soc_write(codec
, RT5640_PWR_VOL
, 0x0000);
2009 snd_soc_write(codec
, RT5640_PWR_MIXER
, 0x0000);
2010 snd_soc_write(codec
, RT5640_PWR_ANLG1
, 0x0000);
2011 snd_soc_write(codec
, RT5640_PWR_ANLG2
, 0x0000);
2021 int rt5640_dmic_enable(struct snd_soc_codec
*codec
,
2022 bool dmic1_data_pin
, bool dmic2_data_pin
)
2024 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
2026 regmap_update_bits(rt5640
->regmap
, RT5640_GPIO_CTRL1
,
2027 RT5640_GP2_PIN_MASK
, RT5640_GP2_PIN_DMIC1_SCL
);
2029 if (dmic1_data_pin
) {
2030 regmap_update_bits(rt5640
->regmap
, RT5640_DMIC
,
2031 RT5640_DMIC_1_DP_MASK
, RT5640_DMIC_1_DP_GPIO3
);
2032 regmap_update_bits(rt5640
->regmap
, RT5640_GPIO_CTRL1
,
2033 RT5640_GP3_PIN_MASK
, RT5640_GP3_PIN_DMIC1_SDA
);
2036 if (dmic2_data_pin
) {
2037 regmap_update_bits(rt5640
->regmap
, RT5640_DMIC
,
2038 RT5640_DMIC_2_DP_MASK
, RT5640_DMIC_2_DP_GPIO4
);
2039 regmap_update_bits(rt5640
->regmap
, RT5640_GPIO_CTRL1
,
2040 RT5640_GP4_PIN_MASK
, RT5640_GP4_PIN_DMIC2_SDA
);
2045 EXPORT_SYMBOL_GPL(rt5640_dmic_enable
);
2047 int rt5640_sel_asrc_clk_src(struct snd_soc_codec
*codec
,
2048 unsigned int filter_mask
, unsigned int clk_src
)
2050 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
2051 unsigned int asrc2_mask
= 0;
2052 unsigned int asrc2_value
= 0;
2055 case RT5640_CLK_SEL_SYS
:
2056 case RT5640_CLK_SEL_ASRC
:
2066 if (filter_mask
& RT5640_DA_STEREO_FILTER
) {
2067 asrc2_mask
|= RT5640_STO_DAC_M_MASK
;
2068 asrc2_value
= (asrc2_value
& ~RT5640_STO_DAC_M_MASK
)
2069 | (clk_src
<< RT5640_STO_DAC_M_SFT
);
2072 if (filter_mask
& RT5640_DA_MONO_L_FILTER
) {
2073 asrc2_mask
|= RT5640_MDA_L_M_MASK
;
2074 asrc2_value
= (asrc2_value
& ~RT5640_MDA_L_M_MASK
)
2075 | (clk_src
<< RT5640_MDA_L_M_SFT
);
2078 if (filter_mask
& RT5640_DA_MONO_R_FILTER
) {
2079 asrc2_mask
|= RT5640_MDA_R_M_MASK
;
2080 asrc2_value
= (asrc2_value
& ~RT5640_MDA_R_M_MASK
)
2081 | (clk_src
<< RT5640_MDA_R_M_SFT
);
2084 if (filter_mask
& RT5640_AD_STEREO_FILTER
) {
2085 asrc2_mask
|= RT5640_ADC_M_MASK
;
2086 asrc2_value
= (asrc2_value
& ~RT5640_ADC_M_MASK
)
2087 | (clk_src
<< RT5640_ADC_M_SFT
);
2090 if (filter_mask
& RT5640_AD_MONO_L_FILTER
) {
2091 asrc2_mask
|= RT5640_MAD_L_M_MASK
;
2092 asrc2_value
= (asrc2_value
& ~RT5640_MAD_L_M_MASK
)
2093 | (clk_src
<< RT5640_MAD_L_M_SFT
);
2096 if (filter_mask
& RT5640_AD_MONO_R_FILTER
) {
2097 asrc2_mask
|= RT5640_MAD_R_M_MASK
;
2098 asrc2_value
= (asrc2_value
& ~RT5640_MAD_R_M_MASK
)
2099 | (clk_src
<< RT5640_MAD_R_M_SFT
);
2102 snd_soc_update_bits(codec
, RT5640_ASRC_2
,
2103 asrc2_mask
, asrc2_value
);
2105 if (snd_soc_read(codec
, RT5640_ASRC_2
)) {
2106 rt5640
->asrc_en
= true;
2107 snd_soc_update_bits(codec
, RT5640_JD_CTRL
, 0x3, 0x3);
2109 rt5640
->asrc_en
= false;
2110 snd_soc_update_bits(codec
, RT5640_JD_CTRL
, 0x3, 0x0);
2115 EXPORT_SYMBOL_GPL(rt5640_sel_asrc_clk_src
);
2117 static int rt5640_probe(struct snd_soc_codec
*codec
)
2119 struct snd_soc_dapm_context
*dapm
= snd_soc_codec_get_dapm(codec
);
2120 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
2122 /* Check if MCLK provided */
2123 rt5640
->mclk
= devm_clk_get(codec
->dev
, "mclk");
2124 if (PTR_ERR(rt5640
->mclk
) == -EPROBE_DEFER
)
2125 return -EPROBE_DEFER
;
2127 rt5640
->codec
= codec
;
2129 snd_soc_codec_force_bias_level(codec
, SND_SOC_BIAS_OFF
);
2131 snd_soc_update_bits(codec
, RT5640_DUMMY1
, 0x0301, 0x0301);
2132 snd_soc_update_bits(codec
, RT5640_MICBIAS
, 0x0030, 0x0030);
2133 snd_soc_update_bits(codec
, RT5640_DSP_PATH2
, 0xfc00, 0x0c00);
2135 switch (snd_soc_read(codec
, RT5640_RESET
) & RT5640_ID_MASK
) {
2136 case RT5640_ID_5640
:
2137 case RT5640_ID_5642
:
2138 snd_soc_add_codec_controls(codec
,
2139 rt5640_specific_snd_controls
,
2140 ARRAY_SIZE(rt5640_specific_snd_controls
));
2141 snd_soc_dapm_new_controls(dapm
,
2142 rt5640_specific_dapm_widgets
,
2143 ARRAY_SIZE(rt5640_specific_dapm_widgets
));
2144 snd_soc_dapm_add_routes(dapm
,
2145 rt5640_specific_dapm_routes
,
2146 ARRAY_SIZE(rt5640_specific_dapm_routes
));
2148 case RT5640_ID_5639
:
2149 snd_soc_dapm_new_controls(dapm
,
2150 rt5639_specific_dapm_widgets
,
2151 ARRAY_SIZE(rt5639_specific_dapm_widgets
));
2152 snd_soc_dapm_add_routes(dapm
,
2153 rt5639_specific_dapm_routes
,
2154 ARRAY_SIZE(rt5639_specific_dapm_routes
));
2158 "The driver is for RT5639 RT5640 or RT5642 only\n");
2162 if (rt5640
->pdata
.dmic_en
)
2163 rt5640_dmic_enable(codec
, rt5640
->pdata
.dmic1_data_pin
,
2164 rt5640
->pdata
.dmic2_data_pin
);
2169 static int rt5640_remove(struct snd_soc_codec
*codec
)
2171 rt5640_reset(codec
);
2177 static int rt5640_suspend(struct snd_soc_codec
*codec
)
2179 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
2181 snd_soc_codec_force_bias_level(codec
, SND_SOC_BIAS_OFF
);
2182 rt5640_reset(codec
);
2183 regcache_cache_only(rt5640
->regmap
, true);
2184 regcache_mark_dirty(rt5640
->regmap
);
2185 if (gpio_is_valid(rt5640
->pdata
.ldo1_en
))
2186 gpio_set_value_cansleep(rt5640
->pdata
.ldo1_en
, 0);
2191 static int rt5640_resume(struct snd_soc_codec
*codec
)
2193 struct rt5640_priv
*rt5640
= snd_soc_codec_get_drvdata(codec
);
2195 if (gpio_is_valid(rt5640
->pdata
.ldo1_en
)) {
2196 gpio_set_value_cansleep(rt5640
->pdata
.ldo1_en
, 1);
2200 regcache_cache_only(rt5640
->regmap
, false);
2201 regcache_sync(rt5640
->regmap
);
2206 #define rt5640_suspend NULL
2207 #define rt5640_resume NULL
2210 #define RT5640_STEREO_RATES SNDRV_PCM_RATE_8000_96000
2211 #define RT5640_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
2212 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
2214 static const struct snd_soc_dai_ops rt5640_aif_dai_ops
= {
2215 .hw_params
= rt5640_hw_params
,
2216 .set_fmt
= rt5640_set_dai_fmt
,
2217 .set_sysclk
= rt5640_set_dai_sysclk
,
2218 .set_pll
= rt5640_set_dai_pll
,
2221 static struct snd_soc_dai_driver rt5640_dai
[] = {
2223 .name
= "rt5640-aif1",
2226 .stream_name
= "AIF1 Playback",
2229 .rates
= RT5640_STEREO_RATES
,
2230 .formats
= RT5640_FORMATS
,
2233 .stream_name
= "AIF1 Capture",
2236 .rates
= RT5640_STEREO_RATES
,
2237 .formats
= RT5640_FORMATS
,
2239 .ops
= &rt5640_aif_dai_ops
,
2242 .name
= "rt5640-aif2",
2245 .stream_name
= "AIF2 Playback",
2248 .rates
= RT5640_STEREO_RATES
,
2249 .formats
= RT5640_FORMATS
,
2252 .stream_name
= "AIF2 Capture",
2255 .rates
= RT5640_STEREO_RATES
,
2256 .formats
= RT5640_FORMATS
,
2258 .ops
= &rt5640_aif_dai_ops
,
2262 static const struct snd_soc_codec_driver soc_codec_dev_rt5640
= {
2263 .probe
= rt5640_probe
,
2264 .remove
= rt5640_remove
,
2265 .suspend
= rt5640_suspend
,
2266 .resume
= rt5640_resume
,
2267 .set_bias_level
= rt5640_set_bias_level
,
2268 .idle_bias_off
= true,
2269 .component_driver
= {
2270 .controls
= rt5640_snd_controls
,
2271 .num_controls
= ARRAY_SIZE(rt5640_snd_controls
),
2272 .dapm_widgets
= rt5640_dapm_widgets
,
2273 .num_dapm_widgets
= ARRAY_SIZE(rt5640_dapm_widgets
),
2274 .dapm_routes
= rt5640_dapm_routes
,
2275 .num_dapm_routes
= ARRAY_SIZE(rt5640_dapm_routes
),
2279 static const struct regmap_config rt5640_regmap
= {
2282 .use_single_rw
= true,
2284 .max_register
= RT5640_VENDOR_ID2
+ 1 + (ARRAY_SIZE(rt5640_ranges
) *
2286 .volatile_reg
= rt5640_volatile_register
,
2287 .readable_reg
= rt5640_readable_register
,
2289 .cache_type
= REGCACHE_RBTREE
,
2290 .reg_defaults
= rt5640_reg
,
2291 .num_reg_defaults
= ARRAY_SIZE(rt5640_reg
),
2292 .ranges
= rt5640_ranges
,
2293 .num_ranges
= ARRAY_SIZE(rt5640_ranges
),
2296 static const struct i2c_device_id rt5640_i2c_id
[] = {
2302 MODULE_DEVICE_TABLE(i2c
, rt5640_i2c_id
);
2304 #if defined(CONFIG_OF)
2305 static const struct of_device_id rt5640_of_match
[] = {
2306 { .compatible
= "realtek,rt5639", },
2307 { .compatible
= "realtek,rt5640", },
2310 MODULE_DEVICE_TABLE(of
, rt5640_of_match
);
2314 static const struct acpi_device_id rt5640_acpi_match
[] = {
2322 MODULE_DEVICE_TABLE(acpi
, rt5640_acpi_match
);
2325 static int rt5640_parse_dt(struct rt5640_priv
*rt5640
, struct device_node
*np
)
2327 rt5640
->pdata
.in1_diff
= of_property_read_bool(np
,
2328 "realtek,in1-differential");
2329 rt5640
->pdata
.in2_diff
= of_property_read_bool(np
,
2330 "realtek,in2-differential");
2332 rt5640
->pdata
.ldo1_en
= of_get_named_gpio(np
,
2333 "realtek,ldo1-en-gpios", 0);
2335 * LDO1_EN is optional (it may be statically tied on the board).
2336 * -ENOENT means that the property doesn't exist, i.e. there is no
2337 * GPIO, so is not an error. Any other error code means the property
2338 * exists, but could not be parsed.
2340 if (!gpio_is_valid(rt5640
->pdata
.ldo1_en
) &&
2341 (rt5640
->pdata
.ldo1_en
!= -ENOENT
))
2342 return rt5640
->pdata
.ldo1_en
;
2347 static int rt5640_i2c_probe(struct i2c_client
*i2c
,
2348 const struct i2c_device_id
*id
)
2350 struct rt5640_platform_data
*pdata
= dev_get_platdata(&i2c
->dev
);
2351 struct rt5640_priv
*rt5640
;
2355 rt5640
= devm_kzalloc(&i2c
->dev
,
2356 sizeof(struct rt5640_priv
),
2360 i2c_set_clientdata(i2c
, rt5640
);
2363 rt5640
->pdata
= *pdata
;
2365 * Translate zero'd out (default) pdata value to an invalid
2366 * GPIO ID. This makes the pdata and DT paths consistent in
2367 * terms of the value left in this field when no GPIO is
2368 * specified, but means we can't actually use GPIO 0.
2370 if (!rt5640
->pdata
.ldo1_en
)
2371 rt5640
->pdata
.ldo1_en
= -EINVAL
;
2372 } else if (i2c
->dev
.of_node
) {
2373 ret
= rt5640_parse_dt(rt5640
, i2c
->dev
.of_node
);
2377 rt5640
->pdata
.ldo1_en
= -EINVAL
;
2379 rt5640
->regmap
= devm_regmap_init_i2c(i2c
, &rt5640_regmap
);
2380 if (IS_ERR(rt5640
->regmap
)) {
2381 ret
= PTR_ERR(rt5640
->regmap
);
2382 dev_err(&i2c
->dev
, "Failed to allocate register map: %d\n",
2387 if (gpio_is_valid(rt5640
->pdata
.ldo1_en
)) {
2388 ret
= devm_gpio_request_one(&i2c
->dev
, rt5640
->pdata
.ldo1_en
,
2389 GPIOF_OUT_INIT_HIGH
,
2392 dev_err(&i2c
->dev
, "Failed to request LDO1_EN %d: %d\n",
2393 rt5640
->pdata
.ldo1_en
, ret
);
2399 regmap_read(rt5640
->regmap
, RT5640_VENDOR_ID2
, &val
);
2400 if (val
!= RT5640_DEVICE_ID
) {
2402 "Device with ID register %#x is not rt5640/39\n", val
);
2406 regmap_write(rt5640
->regmap
, RT5640_RESET
, 0);
2408 ret
= regmap_register_patch(rt5640
->regmap
, init_list
,
2409 ARRAY_SIZE(init_list
));
2411 dev_warn(&i2c
->dev
, "Failed to apply regmap patch: %d\n", ret
);
2413 regmap_update_bits(rt5640
->regmap
, RT5640_DUMMY1
,
2414 RT5640_MCLK_DET
, RT5640_MCLK_DET
);
2416 if (rt5640
->pdata
.in1_diff
)
2417 regmap_update_bits(rt5640
->regmap
, RT5640_IN1_IN2
,
2418 RT5640_IN_DF1
, RT5640_IN_DF1
);
2420 if (rt5640
->pdata
.in2_diff
)
2421 regmap_update_bits(rt5640
->regmap
, RT5640_IN3_IN4
,
2422 RT5640_IN_DF2
, RT5640_IN_DF2
);
2424 if (rt5640
->pdata
.in3_diff
)
2425 regmap_update_bits(rt5640
->regmap
, RT5640_IN1_IN2
,
2426 RT5640_IN_DF2
, RT5640_IN_DF2
);
2428 rt5640
->hp_mute
= 1;
2430 return snd_soc_register_codec(&i2c
->dev
, &soc_codec_dev_rt5640
,
2431 rt5640_dai
, ARRAY_SIZE(rt5640_dai
));
2434 static int rt5640_i2c_remove(struct i2c_client
*i2c
)
2436 snd_soc_unregister_codec(&i2c
->dev
);
2441 static struct i2c_driver rt5640_i2c_driver
= {
2444 .acpi_match_table
= ACPI_PTR(rt5640_acpi_match
),
2445 .of_match_table
= of_match_ptr(rt5640_of_match
),
2447 .probe
= rt5640_i2c_probe
,
2448 .remove
= rt5640_i2c_remove
,
2449 .id_table
= rt5640_i2c_id
,
2451 module_i2c_driver(rt5640_i2c_driver
);
2453 MODULE_DESCRIPTION("ASoC RT5640/RT5639 driver");
2454 MODULE_AUTHOR("Johnny Hsu <johnnyhsu@realtek.com>");
2455 MODULE_LICENSE("GPL v2");