1 // SPDX-License-Identifier: GPL-2.0-only
3 // rt5682.c -- RT5682 ALSA SoC audio component driver
5 // Copyright 2018 Realtek Semiconductor Corp.
6 // Author: Bard Liao <bardliao@realtek.com>
9 #include <linux/module.h>
10 #include <linux/moduleparam.h>
11 #include <linux/init.h>
12 #include <linux/delay.h>
14 #include <linux/pm_runtime.h>
15 #include <linux/platform_device.h>
16 #include <linux/spi/spi.h>
17 #include <linux/acpi.h>
18 #include <linux/gpio.h>
19 #include <linux/of_gpio.h>
20 #include <linux/mutex.h>
21 #include <sound/core.h>
22 #include <sound/pcm.h>
23 #include <sound/pcm_params.h>
24 #include <sound/jack.h>
25 #include <sound/soc.h>
26 #include <sound/soc-dapm.h>
27 #include <sound/initval.h>
28 #include <sound/tlv.h>
29 #include <sound/rt5682.h>
34 const char *rt5682_supply_names[RT5682_NUM_SUPPLIES] = {
39 EXPORT_SYMBOL_GPL(rt5682_supply_names);
41 static const struct reg_sequence patch_list[] = {
42 {RT5682_HP_IMP_SENS_CTRL_19, 0x1000},
43 {RT5682_DAC_ADC_DIG_VOL1, 0xa020},
44 {RT5682_I2C_CTRL, 0x000f},
45 {RT5682_PLL2_INTERNAL, 0x8266},
48 void rt5682_apply_patch_list(struct rt5682_priv *rt5682, struct device *dev)
52 ret = regmap_multi_reg_write(rt5682->regmap, patch_list,
53 ARRAY_SIZE(patch_list));
55 dev_warn(dev, "Failed to apply regmap patch: %d\n", ret);
57 EXPORT_SYMBOL_GPL(rt5682_apply_patch_list);
59 const struct reg_default rt5682_reg[RT5682_REG_NUM] = {
379 EXPORT_SYMBOL_GPL(rt5682_reg);
381 bool rt5682_volatile_register(struct device *dev, unsigned int reg)
385 case RT5682_CBJ_CTRL_2:
386 case RT5682_INT_ST_1:
387 case RT5682_4BTN_IL_CMD_1:
388 case RT5682_AJD1_CTRL:
389 case RT5682_HP_CALIB_CTRL_1:
390 case RT5682_DEVICE_ID:
391 case RT5682_I2C_MODE:
392 case RT5682_HP_CALIB_CTRL_10:
393 case RT5682_EFUSE_CTRL_2:
394 case RT5682_JD_TOP_VC_VTRL:
395 case RT5682_HP_IMP_SENS_CTRL_19:
396 case RT5682_IL_CMD_1:
397 case RT5682_SAR_IL_CMD_2:
398 case RT5682_SAR_IL_CMD_4:
399 case RT5682_SAR_IL_CMD_10:
400 case RT5682_SAR_IL_CMD_11:
401 case RT5682_EFUSE_CTRL_6...RT5682_EFUSE_CTRL_11:
402 case RT5682_HP_CALIB_STA_1...RT5682_HP_CALIB_STA_11:
408 EXPORT_SYMBOL_GPL(rt5682_volatile_register);
410 bool rt5682_readable_register(struct device *dev, unsigned int reg)
414 case RT5682_VERSION_ID:
415 case RT5682_VENDOR_ID:
416 case RT5682_DEVICE_ID:
417 case RT5682_HP_CTRL_1:
418 case RT5682_HP_CTRL_2:
419 case RT5682_HPL_GAIN:
420 case RT5682_HPR_GAIN:
421 case RT5682_I2C_CTRL:
422 case RT5682_CBJ_BST_CTRL:
423 case RT5682_CBJ_CTRL_1:
424 case RT5682_CBJ_CTRL_2:
425 case RT5682_CBJ_CTRL_3:
426 case RT5682_CBJ_CTRL_4:
427 case RT5682_CBJ_CTRL_5:
428 case RT5682_CBJ_CTRL_6:
429 case RT5682_CBJ_CTRL_7:
430 case RT5682_DAC1_DIG_VOL:
431 case RT5682_STO1_ADC_DIG_VOL:
432 case RT5682_STO1_ADC_BOOST:
433 case RT5682_HP_IMP_GAIN_1:
434 case RT5682_HP_IMP_GAIN_2:
435 case RT5682_SIDETONE_CTRL:
436 case RT5682_STO1_ADC_MIXER:
437 case RT5682_AD_DA_MIXER:
438 case RT5682_STO1_DAC_MIXER:
439 case RT5682_A_DAC1_MUX:
440 case RT5682_DIG_INF2_DATA:
441 case RT5682_REC_MIXER:
443 case RT5682_ALC_BACK_GAIN:
444 case RT5682_PWR_DIG_1:
445 case RT5682_PWR_DIG_2:
446 case RT5682_PWR_ANLG_1:
447 case RT5682_PWR_ANLG_2:
448 case RT5682_PWR_ANLG_3:
449 case RT5682_PWR_MIXER:
452 case RT5682_RESET_LPF_CTRL:
453 case RT5682_RESET_HPF_CTRL:
454 case RT5682_DMIC_CTRL_1:
455 case RT5682_I2S1_SDP:
456 case RT5682_I2S2_SDP:
457 case RT5682_ADDA_CLK_1:
458 case RT5682_ADDA_CLK_2:
459 case RT5682_I2S1_F_DIV_CTRL_1:
460 case RT5682_I2S1_F_DIV_CTRL_2:
461 case RT5682_TDM_CTRL:
462 case RT5682_TDM_ADDA_CTRL_1:
463 case RT5682_TDM_ADDA_CTRL_2:
464 case RT5682_DATA_SEL_CTRL_1:
465 case RT5682_TDM_TCON_CTRL:
467 case RT5682_PLL_CTRL_1:
468 case RT5682_PLL_CTRL_2:
469 case RT5682_PLL_TRACK_1:
470 case RT5682_PLL_TRACK_2:
471 case RT5682_PLL_TRACK_3:
472 case RT5682_PLL_TRACK_4:
473 case RT5682_PLL_TRACK_5:
474 case RT5682_PLL_TRACK_6:
475 case RT5682_PLL_TRACK_11:
476 case RT5682_SDW_REF_CLK:
479 case RT5682_HP_CHARGE_PUMP_1:
480 case RT5682_HP_CHARGE_PUMP_2:
481 case RT5682_MICBIAS_1:
482 case RT5682_MICBIAS_2:
483 case RT5682_PLL_TRACK_12:
484 case RT5682_PLL_TRACK_14:
485 case RT5682_PLL2_CTRL_1:
486 case RT5682_PLL2_CTRL_2:
487 case RT5682_PLL2_CTRL_3:
488 case RT5682_PLL2_CTRL_4:
489 case RT5682_RC_CLK_CTRL:
490 case RT5682_I2S_M_CLK_CTRL_1:
491 case RT5682_I2S2_F_DIV_CTRL_1:
492 case RT5682_I2S2_F_DIV_CTRL_2:
493 case RT5682_EQ_CTRL_1:
494 case RT5682_EQ_CTRL_2:
495 case RT5682_IRQ_CTRL_1:
496 case RT5682_IRQ_CTRL_2:
497 case RT5682_IRQ_CTRL_3:
498 case RT5682_IRQ_CTRL_4:
499 case RT5682_INT_ST_1:
500 case RT5682_GPIO_CTRL_1:
501 case RT5682_GPIO_CTRL_2:
502 case RT5682_GPIO_CTRL_3:
503 case RT5682_HP_AMP_DET_CTRL_1:
504 case RT5682_HP_AMP_DET_CTRL_2:
505 case RT5682_MID_HP_AMP_DET:
506 case RT5682_LOW_HP_AMP_DET:
507 case RT5682_DELAY_BUF_CTRL:
508 case RT5682_SV_ZCD_1:
509 case RT5682_SV_ZCD_2:
510 case RT5682_IL_CMD_1:
511 case RT5682_IL_CMD_2:
512 case RT5682_IL_CMD_3:
513 case RT5682_IL_CMD_4:
514 case RT5682_IL_CMD_5:
515 case RT5682_IL_CMD_6:
516 case RT5682_4BTN_IL_CMD_1:
517 case RT5682_4BTN_IL_CMD_2:
518 case RT5682_4BTN_IL_CMD_3:
519 case RT5682_4BTN_IL_CMD_4:
520 case RT5682_4BTN_IL_CMD_5:
521 case RT5682_4BTN_IL_CMD_6:
522 case RT5682_4BTN_IL_CMD_7:
523 case RT5682_ADC_STO1_HP_CTRL_1:
524 case RT5682_ADC_STO1_HP_CTRL_2:
525 case RT5682_AJD1_CTRL:
528 case RT5682_JD_CTRL_1:
532 case RT5682_DAC_ADC_DIG_VOL1:
533 case RT5682_BIAS_CUR_CTRL_2:
534 case RT5682_BIAS_CUR_CTRL_3:
535 case RT5682_BIAS_CUR_CTRL_4:
536 case RT5682_BIAS_CUR_CTRL_5:
537 case RT5682_BIAS_CUR_CTRL_6:
538 case RT5682_BIAS_CUR_CTRL_7:
539 case RT5682_BIAS_CUR_CTRL_8:
540 case RT5682_BIAS_CUR_CTRL_9:
541 case RT5682_BIAS_CUR_CTRL_10:
542 case RT5682_VREF_REC_OP_FB_CAP_CTRL:
543 case RT5682_CHARGE_PUMP_1:
544 case RT5682_DIG_IN_CTRL_1:
545 case RT5682_PAD_DRIVING_CTRL:
546 case RT5682_SOFT_RAMP_DEPOP:
547 case RT5682_CHOP_DAC:
548 case RT5682_CHOP_ADC:
549 case RT5682_CALIB_ADC_CTRL:
550 case RT5682_VOL_TEST:
551 case RT5682_SPKVDD_DET_STA:
552 case RT5682_TEST_MODE_CTRL_1:
553 case RT5682_TEST_MODE_CTRL_2:
554 case RT5682_TEST_MODE_CTRL_3:
555 case RT5682_TEST_MODE_CTRL_4:
556 case RT5682_TEST_MODE_CTRL_5:
557 case RT5682_PLL1_INTERNAL:
558 case RT5682_PLL2_INTERNAL:
559 case RT5682_STO_NG2_CTRL_1:
560 case RT5682_STO_NG2_CTRL_2:
561 case RT5682_STO_NG2_CTRL_3:
562 case RT5682_STO_NG2_CTRL_4:
563 case RT5682_STO_NG2_CTRL_5:
564 case RT5682_STO_NG2_CTRL_6:
565 case RT5682_STO_NG2_CTRL_7:
566 case RT5682_STO_NG2_CTRL_8:
567 case RT5682_STO_NG2_CTRL_9:
568 case RT5682_STO_NG2_CTRL_10:
569 case RT5682_STO1_DAC_SIL_DET:
570 case RT5682_SIL_PSV_CTRL1:
571 case RT5682_SIL_PSV_CTRL2:
572 case RT5682_SIL_PSV_CTRL3:
573 case RT5682_SIL_PSV_CTRL4:
574 case RT5682_SIL_PSV_CTRL5:
575 case RT5682_HP_IMP_SENS_CTRL_01:
576 case RT5682_HP_IMP_SENS_CTRL_02:
577 case RT5682_HP_IMP_SENS_CTRL_03:
578 case RT5682_HP_IMP_SENS_CTRL_04:
579 case RT5682_HP_IMP_SENS_CTRL_05:
580 case RT5682_HP_IMP_SENS_CTRL_06:
581 case RT5682_HP_IMP_SENS_CTRL_07:
582 case RT5682_HP_IMP_SENS_CTRL_08:
583 case RT5682_HP_IMP_SENS_CTRL_09:
584 case RT5682_HP_IMP_SENS_CTRL_10:
585 case RT5682_HP_IMP_SENS_CTRL_11:
586 case RT5682_HP_IMP_SENS_CTRL_12:
587 case RT5682_HP_IMP_SENS_CTRL_13:
588 case RT5682_HP_IMP_SENS_CTRL_14:
589 case RT5682_HP_IMP_SENS_CTRL_15:
590 case RT5682_HP_IMP_SENS_CTRL_16:
591 case RT5682_HP_IMP_SENS_CTRL_17:
592 case RT5682_HP_IMP_SENS_CTRL_18:
593 case RT5682_HP_IMP_SENS_CTRL_19:
594 case RT5682_HP_IMP_SENS_CTRL_20:
595 case RT5682_HP_IMP_SENS_CTRL_21:
596 case RT5682_HP_IMP_SENS_CTRL_22:
597 case RT5682_HP_IMP_SENS_CTRL_23:
598 case RT5682_HP_IMP_SENS_CTRL_24:
599 case RT5682_HP_IMP_SENS_CTRL_25:
600 case RT5682_HP_IMP_SENS_CTRL_26:
601 case RT5682_HP_IMP_SENS_CTRL_27:
602 case RT5682_HP_IMP_SENS_CTRL_28:
603 case RT5682_HP_IMP_SENS_CTRL_29:
604 case RT5682_HP_IMP_SENS_CTRL_30:
605 case RT5682_HP_IMP_SENS_CTRL_31:
606 case RT5682_HP_IMP_SENS_CTRL_32:
607 case RT5682_HP_IMP_SENS_CTRL_33:
608 case RT5682_HP_IMP_SENS_CTRL_34:
609 case RT5682_HP_IMP_SENS_CTRL_35:
610 case RT5682_HP_IMP_SENS_CTRL_36:
611 case RT5682_HP_IMP_SENS_CTRL_37:
612 case RT5682_HP_IMP_SENS_CTRL_38:
613 case RT5682_HP_IMP_SENS_CTRL_39:
614 case RT5682_HP_IMP_SENS_CTRL_40:
615 case RT5682_HP_IMP_SENS_CTRL_41:
616 case RT5682_HP_IMP_SENS_CTRL_42:
617 case RT5682_HP_IMP_SENS_CTRL_43:
618 case RT5682_HP_LOGIC_CTRL_1:
619 case RT5682_HP_LOGIC_CTRL_2:
620 case RT5682_HP_LOGIC_CTRL_3:
621 case RT5682_HP_CALIB_CTRL_1:
622 case RT5682_HP_CALIB_CTRL_2:
623 case RT5682_HP_CALIB_CTRL_3:
624 case RT5682_HP_CALIB_CTRL_4:
625 case RT5682_HP_CALIB_CTRL_5:
626 case RT5682_HP_CALIB_CTRL_6:
627 case RT5682_HP_CALIB_CTRL_7:
628 case RT5682_HP_CALIB_CTRL_9:
629 case RT5682_HP_CALIB_CTRL_10:
630 case RT5682_HP_CALIB_CTRL_11:
631 case RT5682_HP_CALIB_STA_1:
632 case RT5682_HP_CALIB_STA_2:
633 case RT5682_HP_CALIB_STA_3:
634 case RT5682_HP_CALIB_STA_4:
635 case RT5682_HP_CALIB_STA_5:
636 case RT5682_HP_CALIB_STA_6:
637 case RT5682_HP_CALIB_STA_7:
638 case RT5682_HP_CALIB_STA_8:
639 case RT5682_HP_CALIB_STA_9:
640 case RT5682_HP_CALIB_STA_10:
641 case RT5682_HP_CALIB_STA_11:
642 case RT5682_SAR_IL_CMD_1:
643 case RT5682_SAR_IL_CMD_2:
644 case RT5682_SAR_IL_CMD_3:
645 case RT5682_SAR_IL_CMD_4:
646 case RT5682_SAR_IL_CMD_5:
647 case RT5682_SAR_IL_CMD_6:
648 case RT5682_SAR_IL_CMD_7:
649 case RT5682_SAR_IL_CMD_8:
650 case RT5682_SAR_IL_CMD_9:
651 case RT5682_SAR_IL_CMD_10:
652 case RT5682_SAR_IL_CMD_11:
653 case RT5682_SAR_IL_CMD_12:
654 case RT5682_SAR_IL_CMD_13:
655 case RT5682_EFUSE_CTRL_1:
656 case RT5682_EFUSE_CTRL_2:
657 case RT5682_EFUSE_CTRL_3:
658 case RT5682_EFUSE_CTRL_4:
659 case RT5682_EFUSE_CTRL_5:
660 case RT5682_EFUSE_CTRL_6:
661 case RT5682_EFUSE_CTRL_7:
662 case RT5682_EFUSE_CTRL_8:
663 case RT5682_EFUSE_CTRL_9:
664 case RT5682_EFUSE_CTRL_10:
665 case RT5682_EFUSE_CTRL_11:
666 case RT5682_JD_TOP_VC_VTRL:
667 case RT5682_DRC1_CTRL_0:
668 case RT5682_DRC1_CTRL_1:
669 case RT5682_DRC1_CTRL_2:
670 case RT5682_DRC1_CTRL_3:
671 case RT5682_DRC1_CTRL_4:
672 case RT5682_DRC1_CTRL_5:
673 case RT5682_DRC1_CTRL_6:
674 case RT5682_DRC1_HARD_LMT_CTRL_1:
675 case RT5682_DRC1_HARD_LMT_CTRL_2:
676 case RT5682_DRC1_PRIV_1:
677 case RT5682_DRC1_PRIV_2:
678 case RT5682_DRC1_PRIV_3:
679 case RT5682_DRC1_PRIV_4:
680 case RT5682_DRC1_PRIV_5:
681 case RT5682_DRC1_PRIV_6:
682 case RT5682_DRC1_PRIV_7:
683 case RT5682_DRC1_PRIV_8:
684 case RT5682_EQ_AUTO_RCV_CTRL1:
685 case RT5682_EQ_AUTO_RCV_CTRL2:
686 case RT5682_EQ_AUTO_RCV_CTRL3:
687 case RT5682_EQ_AUTO_RCV_CTRL4:
688 case RT5682_EQ_AUTO_RCV_CTRL5:
689 case RT5682_EQ_AUTO_RCV_CTRL6:
690 case RT5682_EQ_AUTO_RCV_CTRL7:
691 case RT5682_EQ_AUTO_RCV_CTRL8:
692 case RT5682_EQ_AUTO_RCV_CTRL9:
693 case RT5682_EQ_AUTO_RCV_CTRL10:
694 case RT5682_EQ_AUTO_RCV_CTRL11:
695 case RT5682_EQ_AUTO_RCV_CTRL12:
696 case RT5682_EQ_AUTO_RCV_CTRL13:
697 case RT5682_ADC_L_EQ_LPF1_A1:
698 case RT5682_R_EQ_LPF1_A1:
699 case RT5682_L_EQ_LPF1_H0:
700 case RT5682_R_EQ_LPF1_H0:
701 case RT5682_L_EQ_BPF1_A1:
702 case RT5682_R_EQ_BPF1_A1:
703 case RT5682_L_EQ_BPF1_A2:
704 case RT5682_R_EQ_BPF1_A2:
705 case RT5682_L_EQ_BPF1_H0:
706 case RT5682_R_EQ_BPF1_H0:
707 case RT5682_L_EQ_BPF2_A1:
708 case RT5682_R_EQ_BPF2_A1:
709 case RT5682_L_EQ_BPF2_A2:
710 case RT5682_R_EQ_BPF2_A2:
711 case RT5682_L_EQ_BPF2_H0:
712 case RT5682_R_EQ_BPF2_H0:
713 case RT5682_L_EQ_BPF3_A1:
714 case RT5682_R_EQ_BPF3_A1:
715 case RT5682_L_EQ_BPF3_A2:
716 case RT5682_R_EQ_BPF3_A2:
717 case RT5682_L_EQ_BPF3_H0:
718 case RT5682_R_EQ_BPF3_H0:
719 case RT5682_L_EQ_BPF4_A1:
720 case RT5682_R_EQ_BPF4_A1:
721 case RT5682_L_EQ_BPF4_A2:
722 case RT5682_R_EQ_BPF4_A2:
723 case RT5682_L_EQ_BPF4_H0:
724 case RT5682_R_EQ_BPF4_H0:
725 case RT5682_L_EQ_HPF1_A1:
726 case RT5682_R_EQ_HPF1_A1:
727 case RT5682_L_EQ_HPF1_H0:
728 case RT5682_R_EQ_HPF1_H0:
729 case RT5682_L_EQ_PRE_VOL:
730 case RT5682_R_EQ_PRE_VOL:
731 case RT5682_L_EQ_POST_VOL:
732 case RT5682_R_EQ_POST_VOL:
733 case RT5682_I2C_MODE:
739 EXPORT_SYMBOL_GPL(rt5682_readable_register);
741 static const DECLARE_TLV_DB_SCALE(dac_vol_tlv, -6525, 75, 0);
742 static const DECLARE_TLV_DB_SCALE(adc_vol_tlv, -1725, 75, 0);
743 static const DECLARE_TLV_DB_SCALE(adc_bst_tlv, 0, 1200, 0);
745 /* {0, +20, +24, +30, +35, +40, +44, +50, +52} dB */
746 static const DECLARE_TLV_DB_RANGE(bst_tlv,
747 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
748 1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0),
749 2, 2, TLV_DB_SCALE_ITEM(2400, 0, 0),
750 3, 5, TLV_DB_SCALE_ITEM(3000, 500, 0),
751 6, 6, TLV_DB_SCALE_ITEM(4400, 0, 0),
752 7, 7, TLV_DB_SCALE_ITEM(5000, 0, 0),
753 8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0)
756 /* Interface data select */
757 static const char * const rt5682_data_select[] = {
758 "L/R", "R/L", "L/L", "R/R"
761 static SOC_ENUM_SINGLE_DECL(rt5682_if2_adc_enum,
762 RT5682_DIG_INF2_DATA, RT5682_IF2_ADC_SEL_SFT, rt5682_data_select);
764 static SOC_ENUM_SINGLE_DECL(rt5682_if1_01_adc_enum,
765 RT5682_TDM_ADDA_CTRL_1, RT5682_IF1_ADC1_SEL_SFT, rt5682_data_select);
767 static SOC_ENUM_SINGLE_DECL(rt5682_if1_23_adc_enum,
768 RT5682_TDM_ADDA_CTRL_1, RT5682_IF1_ADC2_SEL_SFT, rt5682_data_select);
770 static SOC_ENUM_SINGLE_DECL(rt5682_if1_45_adc_enum,
771 RT5682_TDM_ADDA_CTRL_1, RT5682_IF1_ADC3_SEL_SFT, rt5682_data_select);
773 static SOC_ENUM_SINGLE_DECL(rt5682_if1_67_adc_enum,
774 RT5682_TDM_ADDA_CTRL_1, RT5682_IF1_ADC4_SEL_SFT, rt5682_data_select);
776 static const struct snd_kcontrol_new rt5682_if2_adc_swap_mux =
777 SOC_DAPM_ENUM("IF2 ADC Swap Mux", rt5682_if2_adc_enum);
779 static const struct snd_kcontrol_new rt5682_if1_01_adc_swap_mux =
780 SOC_DAPM_ENUM("IF1 01 ADC Swap Mux", rt5682_if1_01_adc_enum);
782 static const struct snd_kcontrol_new rt5682_if1_23_adc_swap_mux =
783 SOC_DAPM_ENUM("IF1 23 ADC Swap Mux", rt5682_if1_23_adc_enum);
785 static const struct snd_kcontrol_new rt5682_if1_45_adc_swap_mux =
786 SOC_DAPM_ENUM("IF1 45 ADC Swap Mux", rt5682_if1_45_adc_enum);
788 static const struct snd_kcontrol_new rt5682_if1_67_adc_swap_mux =
789 SOC_DAPM_ENUM("IF1 67 ADC Swap Mux", rt5682_if1_67_adc_enum);
791 static const char * const rt5682_dac_select[] = {
795 static SOC_ENUM_SINGLE_DECL(rt5682_dacl_enum,
796 RT5682_AD_DA_MIXER, RT5682_DAC1_L_SEL_SFT, rt5682_dac_select);
798 static const struct snd_kcontrol_new rt5682_dac_l_mux =
799 SOC_DAPM_ENUM("DAC L Mux", rt5682_dacl_enum);
801 static SOC_ENUM_SINGLE_DECL(rt5682_dacr_enum,
802 RT5682_AD_DA_MIXER, RT5682_DAC1_R_SEL_SFT, rt5682_dac_select);
804 static const struct snd_kcontrol_new rt5682_dac_r_mux =
805 SOC_DAPM_ENUM("DAC R Mux", rt5682_dacr_enum);
807 void rt5682_reset(struct rt5682_priv *rt5682)
809 regmap_write(rt5682->regmap, RT5682_RESET, 0);
811 regmap_write(rt5682->regmap, RT5682_I2C_MODE, 1);
813 EXPORT_SYMBOL_GPL(rt5682_reset);
816 * rt5682_sel_asrc_clk_src - select ASRC clock source for a set of filters
817 * @component: SoC audio component device.
818 * @filter_mask: mask of filters.
819 * @clk_src: clock source
821 * The ASRC function is for asynchronous MCLK and LRCK. Also, since RT5682 can
822 * only support standard 32fs or 64fs i2s format, ASRC should be enabled to
823 * support special i2s clock format such as Intel's 100fs(100 * sampling rate).
824 * ASRC function will track i2s clock and generate a corresponding system clock
825 * for codec. This function provides an API to select the clock source for a
826 * set of filters specified by the mask. And the component driver will turn on
827 * ASRC for these filters if ASRC is selected as their clock source.
829 int rt5682_sel_asrc_clk_src(struct snd_soc_component *component,
830 unsigned int filter_mask, unsigned int clk_src)
833 case RT5682_CLK_SEL_SYS:
834 case RT5682_CLK_SEL_I2S1_ASRC:
835 case RT5682_CLK_SEL_I2S2_ASRC:
842 if (filter_mask & RT5682_DA_STEREO1_FILTER) {
843 snd_soc_component_update_bits(component, RT5682_PLL_TRACK_2,
844 RT5682_FILTER_CLK_SEL_MASK,
845 clk_src << RT5682_FILTER_CLK_SEL_SFT);
848 if (filter_mask & RT5682_AD_STEREO1_FILTER) {
849 snd_soc_component_update_bits(component, RT5682_PLL_TRACK_3,
850 RT5682_FILTER_CLK_SEL_MASK,
851 clk_src << RT5682_FILTER_CLK_SEL_SFT);
856 EXPORT_SYMBOL_GPL(rt5682_sel_asrc_clk_src);
858 static int rt5682_button_detect(struct snd_soc_component *component)
862 val = snd_soc_component_read(component, RT5682_4BTN_IL_CMD_1);
863 btn_type = val & 0xfff0;
864 snd_soc_component_write(component, RT5682_4BTN_IL_CMD_1, val);
865 dev_dbg(component->dev, "%s btn_type=%x\n", __func__, btn_type);
866 snd_soc_component_update_bits(component,
867 RT5682_SAR_IL_CMD_2, 0x10, 0x10);
872 static void rt5682_enable_push_button_irq(struct snd_soc_component *component,
875 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
878 snd_soc_component_update_bits(component, RT5682_SAR_IL_CMD_1,
879 RT5682_SAR_BUTT_DET_MASK, RT5682_SAR_BUTT_DET_EN);
880 snd_soc_component_update_bits(component, RT5682_SAR_IL_CMD_13,
881 RT5682_SAR_SOUR_MASK, RT5682_SAR_SOUR_BTN);
882 snd_soc_component_write(component, RT5682_IL_CMD_1, 0x0040);
883 snd_soc_component_update_bits(component, RT5682_4BTN_IL_CMD_2,
884 RT5682_4BTN_IL_MASK | RT5682_4BTN_IL_RST_MASK,
885 RT5682_4BTN_IL_EN | RT5682_4BTN_IL_NOR);
887 snd_soc_component_update_bits(component,
889 RT5682_IL_IRQ_MASK | RT5682_IL_IRQ_TYPE_MASK,
890 RT5682_IL_IRQ_EN | RT5682_IL_IRQ_PUL);
892 snd_soc_component_update_bits(component,
893 RT5682_IRQ_CTRL_3, RT5682_IL_IRQ_MASK,
896 snd_soc_component_update_bits(component, RT5682_IRQ_CTRL_3,
897 RT5682_IL_IRQ_MASK, RT5682_IL_IRQ_DIS);
898 snd_soc_component_update_bits(component, RT5682_SAR_IL_CMD_1,
899 RT5682_SAR_BUTT_DET_MASK, RT5682_SAR_BUTT_DET_DIS);
900 snd_soc_component_update_bits(component, RT5682_4BTN_IL_CMD_2,
901 RT5682_4BTN_IL_MASK, RT5682_4BTN_IL_DIS);
902 snd_soc_component_update_bits(component, RT5682_4BTN_IL_CMD_2,
903 RT5682_4BTN_IL_RST_MASK, RT5682_4BTN_IL_RST);
904 snd_soc_component_update_bits(component, RT5682_SAR_IL_CMD_13,
905 RT5682_SAR_SOUR_MASK, RT5682_SAR_SOUR_TYPE);
910 * rt5682_headset_detect - Detect headset.
911 * @component: SoC audio component device.
912 * @jack_insert: Jack insert or not.
914 * Detect whether is headset or not when jack inserted.
916 * Returns detect status.
918 int rt5682_headset_detect(struct snd_soc_component *component, int jack_insert)
920 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
921 struct snd_soc_dapm_context *dapm = &component->dapm;
922 unsigned int val, count;
925 snd_soc_component_update_bits(component, RT5682_PWR_ANLG_1,
926 RT5682_PWR_VREF2 | RT5682_PWR_MB,
927 RT5682_PWR_VREF2 | RT5682_PWR_MB);
928 snd_soc_component_update_bits(component,
929 RT5682_PWR_ANLG_1, RT5682_PWR_FV2, 0);
930 usleep_range(15000, 20000);
931 snd_soc_component_update_bits(component,
932 RT5682_PWR_ANLG_1, RT5682_PWR_FV2, RT5682_PWR_FV2);
933 snd_soc_component_update_bits(component, RT5682_PWR_ANLG_3,
934 RT5682_PWR_CBJ, RT5682_PWR_CBJ);
935 snd_soc_component_update_bits(component,
936 RT5682_HP_CHARGE_PUMP_1,
937 RT5682_OSW_L_MASK | RT5682_OSW_R_MASK, 0);
938 snd_soc_component_update_bits(component, RT5682_CBJ_CTRL_1,
939 RT5682_TRIG_JD_MASK, RT5682_TRIG_JD_HIGH);
942 val = snd_soc_component_read(component, RT5682_CBJ_CTRL_2)
943 & RT5682_JACK_TYPE_MASK;
944 while (val == 0 && count < 50) {
945 usleep_range(10000, 15000);
946 val = snd_soc_component_read(component,
947 RT5682_CBJ_CTRL_2) & RT5682_JACK_TYPE_MASK;
954 rt5682->jack_type = SND_JACK_HEADSET;
955 rt5682_enable_push_button_irq(component, true);
958 rt5682->jack_type = SND_JACK_HEADPHONE;
962 snd_soc_component_update_bits(component,
963 RT5682_HP_CHARGE_PUMP_1,
964 RT5682_OSW_L_MASK | RT5682_OSW_R_MASK,
965 RT5682_OSW_L_EN | RT5682_OSW_R_EN);
967 rt5682_enable_push_button_irq(component, false);
968 snd_soc_component_update_bits(component, RT5682_CBJ_CTRL_1,
969 RT5682_TRIG_JD_MASK, RT5682_TRIG_JD_LOW);
970 if (snd_soc_dapm_get_pin_status(dapm, "MICBIAS"))
971 snd_soc_component_update_bits(component,
972 RT5682_PWR_ANLG_1, RT5682_PWR_VREF2, 0);
974 snd_soc_component_update_bits(component,
976 RT5682_PWR_VREF2 | RT5682_PWR_MB, 0);
977 snd_soc_component_update_bits(component, RT5682_PWR_ANLG_3,
980 rt5682->jack_type = 0;
983 dev_dbg(component->dev, "jack_type = %d\n", rt5682->jack_type);
984 return rt5682->jack_type;
986 EXPORT_SYMBOL_GPL(rt5682_headset_detect);
988 static int rt5682_set_jack_detect(struct snd_soc_component *component,
989 struct snd_soc_jack *hs_jack, void *data)
991 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
993 rt5682->hs_jack = hs_jack;
996 regmap_update_bits(rt5682->regmap, RT5682_IRQ_CTRL_2,
997 RT5682_JD1_EN_MASK, RT5682_JD1_DIS);
998 regmap_update_bits(rt5682->regmap, RT5682_RC_CLK_CTRL,
999 RT5682_POW_JDH | RT5682_POW_JDL, 0);
1000 cancel_delayed_work_sync(&rt5682->jack_detect_work);
1005 if (!rt5682->is_sdw) {
1006 switch (rt5682->pdata.jd_src) {
1008 snd_soc_component_update_bits(component,
1009 RT5682_CBJ_CTRL_2, RT5682_EXT_JD_SRC,
1010 RT5682_EXT_JD_SRC_MANUAL);
1011 snd_soc_component_write(component, RT5682_CBJ_CTRL_1,
1013 snd_soc_component_update_bits(component,
1014 RT5682_CBJ_CTRL_3, RT5682_CBJ_IN_BUF_EN,
1015 RT5682_CBJ_IN_BUF_EN);
1016 snd_soc_component_update_bits(component,
1017 RT5682_SAR_IL_CMD_1, RT5682_SAR_POW_MASK,
1019 regmap_update_bits(rt5682->regmap, RT5682_GPIO_CTRL_1,
1020 RT5682_GP1_PIN_MASK, RT5682_GP1_PIN_IRQ);
1021 regmap_update_bits(rt5682->regmap, RT5682_RC_CLK_CTRL,
1022 RT5682_POW_IRQ | RT5682_POW_JDH |
1023 RT5682_POW_ANA, RT5682_POW_IRQ |
1024 RT5682_POW_JDH | RT5682_POW_ANA);
1025 regmap_update_bits(rt5682->regmap, RT5682_PWR_ANLG_2,
1026 RT5682_PWR_JDH | RT5682_PWR_JDL,
1027 RT5682_PWR_JDH | RT5682_PWR_JDL);
1028 regmap_update_bits(rt5682->regmap, RT5682_IRQ_CTRL_2,
1029 RT5682_JD1_EN_MASK | RT5682_JD1_POL_MASK,
1030 RT5682_JD1_EN | RT5682_JD1_POL_NOR);
1031 regmap_update_bits(rt5682->regmap, RT5682_4BTN_IL_CMD_4,
1032 0x7f7f, (rt5682->pdata.btndet_delay << 8 |
1033 rt5682->pdata.btndet_delay));
1034 regmap_update_bits(rt5682->regmap, RT5682_4BTN_IL_CMD_5,
1035 0x7f7f, (rt5682->pdata.btndet_delay << 8 |
1036 rt5682->pdata.btndet_delay));
1037 regmap_update_bits(rt5682->regmap, RT5682_4BTN_IL_CMD_6,
1038 0x7f7f, (rt5682->pdata.btndet_delay << 8 |
1039 rt5682->pdata.btndet_delay));
1040 regmap_update_bits(rt5682->regmap, RT5682_4BTN_IL_CMD_7,
1041 0x7f7f, (rt5682->pdata.btndet_delay << 8 |
1042 rt5682->pdata.btndet_delay));
1043 mod_delayed_work(system_power_efficient_wq,
1044 &rt5682->jack_detect_work,
1045 msecs_to_jiffies(250));
1048 case RT5682_JD_NULL:
1049 regmap_update_bits(rt5682->regmap, RT5682_IRQ_CTRL_2,
1050 RT5682_JD1_EN_MASK, RT5682_JD1_DIS);
1051 regmap_update_bits(rt5682->regmap, RT5682_RC_CLK_CTRL,
1052 RT5682_POW_JDH | RT5682_POW_JDL, 0);
1056 dev_warn(component->dev, "Wrong JD source\n");
1064 void rt5682_jack_detect_handler(struct work_struct *work)
1066 struct rt5682_priv *rt5682 =
1067 container_of(work, struct rt5682_priv, jack_detect_work.work);
1070 while (!rt5682->component)
1071 usleep_range(10000, 15000);
1073 while (!rt5682->component->card->instantiated)
1074 usleep_range(10000, 15000);
1076 mutex_lock(&rt5682->calibrate_mutex);
1078 val = snd_soc_component_read(rt5682->component, RT5682_AJD1_CTRL)
1079 & RT5682_JDH_RS_MASK;
1082 if (rt5682->jack_type == 0) {
1083 /* jack was out, report jack type */
1085 rt5682_headset_detect(rt5682->component, 1);
1087 /* jack is already in, report button event */
1088 rt5682->jack_type = SND_JACK_HEADSET;
1089 btn_type = rt5682_button_detect(rt5682->component);
1091 * rt5682 can report three kinds of button behavior,
1092 * one click, double click and hold. However,
1093 * currently we will report button pressed/released
1094 * event. So all the three button behaviors are
1095 * treated as button pressed.
1101 rt5682->jack_type |= SND_JACK_BTN_0;
1106 rt5682->jack_type |= SND_JACK_BTN_1;
1111 rt5682->jack_type |= SND_JACK_BTN_2;
1116 rt5682->jack_type |= SND_JACK_BTN_3;
1118 case 0x0000: /* unpressed */
1121 dev_err(rt5682->component->dev,
1122 "Unexpected button code 0x%04x\n",
1129 rt5682->jack_type = rt5682_headset_detect(rt5682->component, 0);
1132 snd_soc_jack_report(rt5682->hs_jack, rt5682->jack_type,
1134 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
1135 SND_JACK_BTN_2 | SND_JACK_BTN_3);
1137 if (!rt5682->is_sdw) {
1138 if (rt5682->jack_type & (SND_JACK_BTN_0 | SND_JACK_BTN_1 |
1139 SND_JACK_BTN_2 | SND_JACK_BTN_3))
1140 schedule_delayed_work(&rt5682->jd_check_work, 0);
1142 cancel_delayed_work_sync(&rt5682->jd_check_work);
1145 mutex_unlock(&rt5682->calibrate_mutex);
1147 EXPORT_SYMBOL_GPL(rt5682_jack_detect_handler);
1149 static const struct snd_kcontrol_new rt5682_snd_controls[] = {
1150 /* DAC Digital Volume */
1151 SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5682_DAC1_DIG_VOL,
1152 RT5682_L_VOL_SFT + 1, RT5682_R_VOL_SFT + 1, 87, 0, dac_vol_tlv),
1154 /* IN Boost Volume */
1155 SOC_SINGLE_TLV("CBJ Boost Volume", RT5682_CBJ_BST_CTRL,
1156 RT5682_BST_CBJ_SFT, 8, 0, bst_tlv),
1158 /* ADC Digital Volume Control */
1159 SOC_DOUBLE("STO1 ADC Capture Switch", RT5682_STO1_ADC_DIG_VOL,
1160 RT5682_L_MUTE_SFT, RT5682_R_MUTE_SFT, 1, 1),
1161 SOC_DOUBLE_TLV("STO1 ADC Capture Volume", RT5682_STO1_ADC_DIG_VOL,
1162 RT5682_L_VOL_SFT + 1, RT5682_R_VOL_SFT + 1, 63, 0, adc_vol_tlv),
1164 /* ADC Boost Volume Control */
1165 SOC_DOUBLE_TLV("STO1 ADC Boost Gain Volume", RT5682_STO1_ADC_BOOST,
1166 RT5682_STO1_ADC_L_BST_SFT, RT5682_STO1_ADC_R_BST_SFT,
1170 static int rt5682_div_sel(struct rt5682_priv *rt5682,
1171 int target, const int div[], int size)
1175 if (rt5682->sysclk < target) {
1176 dev_err(rt5682->component->dev,
1177 "sysclk rate %d is too low\n", rt5682->sysclk);
1181 for (i = 0; i < size - 1; i++) {
1182 dev_dbg(rt5682->component->dev, "div[%d]=%d\n", i, div[i]);
1183 if (target * div[i] == rt5682->sysclk)
1185 if (target * div[i + 1] > rt5682->sysclk) {
1186 dev_dbg(rt5682->component->dev,
1187 "can't find div for sysclk %d\n",
1193 if (target * div[i] < rt5682->sysclk)
1194 dev_err(rt5682->component->dev,
1195 "sysclk rate %d is too high\n", rt5682->sysclk);
1201 * set_dmic_clk - Set parameter of dmic.
1204 * @kcontrol: The kcontrol of this widget.
1207 * Choose dmic clock between 1MHz and 3MHz.
1208 * It is better for clock to approximate 3MHz.
1210 static int set_dmic_clk(struct snd_soc_dapm_widget *w,
1211 struct snd_kcontrol *kcontrol, int event)
1213 struct snd_soc_component *component =
1214 snd_soc_dapm_to_component(w->dapm);
1215 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
1216 int idx = -EINVAL, dmic_clk_rate = 3072000;
1217 static const int div[] = {2, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128};
1219 if (rt5682->pdata.dmic_clk_rate)
1220 dmic_clk_rate = rt5682->pdata.dmic_clk_rate;
1222 idx = rt5682_div_sel(rt5682, dmic_clk_rate, div, ARRAY_SIZE(div));
1224 snd_soc_component_update_bits(component, RT5682_DMIC_CTRL_1,
1225 RT5682_DMIC_CLK_MASK, idx << RT5682_DMIC_CLK_SFT);
1230 static int set_filter_clk(struct snd_soc_dapm_widget *w,
1231 struct snd_kcontrol *kcontrol, int event)
1233 struct snd_soc_component *component =
1234 snd_soc_dapm_to_component(w->dapm);
1235 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
1236 int ref, val, reg, idx = -EINVAL;
1237 static const int div_f[] = {1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48};
1238 static const int div_o[] = {1, 2, 4, 6, 8, 12, 16, 24, 32, 48};
1243 val = snd_soc_component_read(component, RT5682_GPIO_CTRL_1) &
1244 RT5682_GP4_PIN_MASK;
1245 if (w->shift == RT5682_PWR_ADC_S1F_BIT &&
1246 val == RT5682_GP4_PIN_ADCDAT2)
1247 ref = 256 * rt5682->lrck[RT5682_AIF2];
1249 ref = 256 * rt5682->lrck[RT5682_AIF1];
1251 idx = rt5682_div_sel(rt5682, ref, div_f, ARRAY_SIZE(div_f));
1253 if (w->shift == RT5682_PWR_ADC_S1F_BIT)
1254 reg = RT5682_PLL_TRACK_3;
1256 reg = RT5682_PLL_TRACK_2;
1258 snd_soc_component_update_bits(component, reg,
1259 RT5682_FILTER_CLK_DIV_MASK, idx << RT5682_FILTER_CLK_DIV_SFT);
1261 /* select over sample rate */
1262 for (idx = 0; idx < ARRAY_SIZE(div_o); idx++) {
1263 if (rt5682->sysclk <= 12288000 * div_o[idx])
1267 snd_soc_component_update_bits(component, RT5682_ADDA_CLK_1,
1268 RT5682_ADC_OSR_MASK | RT5682_DAC_OSR_MASK,
1269 (idx << RT5682_ADC_OSR_SFT) | (idx << RT5682_DAC_OSR_SFT));
1274 static int is_sys_clk_from_pll1(struct snd_soc_dapm_widget *w,
1275 struct snd_soc_dapm_widget *sink)
1278 struct snd_soc_component *component =
1279 snd_soc_dapm_to_component(w->dapm);
1281 val = snd_soc_component_read(component, RT5682_GLB_CLK);
1282 val &= RT5682_SCLK_SRC_MASK;
1283 if (val == RT5682_SCLK_SRC_PLL1)
1289 static int is_sys_clk_from_pll2(struct snd_soc_dapm_widget *w,
1290 struct snd_soc_dapm_widget *sink)
1293 struct snd_soc_component *component =
1294 snd_soc_dapm_to_component(w->dapm);
1296 val = snd_soc_component_read(component, RT5682_GLB_CLK);
1297 val &= RT5682_SCLK_SRC_MASK;
1298 if (val == RT5682_SCLK_SRC_PLL2)
1304 static int is_using_asrc(struct snd_soc_dapm_widget *w,
1305 struct snd_soc_dapm_widget *sink)
1307 unsigned int reg, shift, val;
1308 struct snd_soc_component *component =
1309 snd_soc_dapm_to_component(w->dapm);
1312 case RT5682_ADC_STO1_ASRC_SFT:
1313 reg = RT5682_PLL_TRACK_3;
1314 shift = RT5682_FILTER_CLK_SEL_SFT;
1316 case RT5682_DAC_STO1_ASRC_SFT:
1317 reg = RT5682_PLL_TRACK_2;
1318 shift = RT5682_FILTER_CLK_SEL_SFT;
1324 val = (snd_soc_component_read(component, reg) >> shift) & 0xf;
1326 case RT5682_CLK_SEL_I2S1_ASRC:
1327 case RT5682_CLK_SEL_I2S2_ASRC:
1335 static const struct snd_kcontrol_new rt5682_sto1_adc_l_mix[] = {
1336 SOC_DAPM_SINGLE("ADC1 Switch", RT5682_STO1_ADC_MIXER,
1337 RT5682_M_STO1_ADC_L1_SFT, 1, 1),
1338 SOC_DAPM_SINGLE("ADC2 Switch", RT5682_STO1_ADC_MIXER,
1339 RT5682_M_STO1_ADC_L2_SFT, 1, 1),
1342 static const struct snd_kcontrol_new rt5682_sto1_adc_r_mix[] = {
1343 SOC_DAPM_SINGLE("ADC1 Switch", RT5682_STO1_ADC_MIXER,
1344 RT5682_M_STO1_ADC_R1_SFT, 1, 1),
1345 SOC_DAPM_SINGLE("ADC2 Switch", RT5682_STO1_ADC_MIXER,
1346 RT5682_M_STO1_ADC_R2_SFT, 1, 1),
1349 static const struct snd_kcontrol_new rt5682_dac_l_mix[] = {
1350 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5682_AD_DA_MIXER,
1351 RT5682_M_ADCMIX_L_SFT, 1, 1),
1352 SOC_DAPM_SINGLE("DAC1 Switch", RT5682_AD_DA_MIXER,
1353 RT5682_M_DAC1_L_SFT, 1, 1),
1356 static const struct snd_kcontrol_new rt5682_dac_r_mix[] = {
1357 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5682_AD_DA_MIXER,
1358 RT5682_M_ADCMIX_R_SFT, 1, 1),
1359 SOC_DAPM_SINGLE("DAC1 Switch", RT5682_AD_DA_MIXER,
1360 RT5682_M_DAC1_R_SFT, 1, 1),
1363 static const struct snd_kcontrol_new rt5682_sto1_dac_l_mix[] = {
1364 SOC_DAPM_SINGLE("DAC L1 Switch", RT5682_STO1_DAC_MIXER,
1365 RT5682_M_DAC_L1_STO_L_SFT, 1, 1),
1366 SOC_DAPM_SINGLE("DAC R1 Switch", RT5682_STO1_DAC_MIXER,
1367 RT5682_M_DAC_R1_STO_L_SFT, 1, 1),
1370 static const struct snd_kcontrol_new rt5682_sto1_dac_r_mix[] = {
1371 SOC_DAPM_SINGLE("DAC L1 Switch", RT5682_STO1_DAC_MIXER,
1372 RT5682_M_DAC_L1_STO_R_SFT, 1, 1),
1373 SOC_DAPM_SINGLE("DAC R1 Switch", RT5682_STO1_DAC_MIXER,
1374 RT5682_M_DAC_R1_STO_R_SFT, 1, 1),
1377 /* Analog Input Mixer */
1378 static const struct snd_kcontrol_new rt5682_rec1_l_mix[] = {
1379 SOC_DAPM_SINGLE("CBJ Switch", RT5682_REC_MIXER,
1380 RT5682_M_CBJ_RM1_L_SFT, 1, 1),
1383 /* STO1 ADC1 Source */
1384 /* MX-26 [13] [5] */
1385 static const char * const rt5682_sto1_adc1_src[] = {
1389 static SOC_ENUM_SINGLE_DECL(
1390 rt5682_sto1_adc1l_enum, RT5682_STO1_ADC_MIXER,
1391 RT5682_STO1_ADC1L_SRC_SFT, rt5682_sto1_adc1_src);
1393 static const struct snd_kcontrol_new rt5682_sto1_adc1l_mux =
1394 SOC_DAPM_ENUM("Stereo1 ADC1L Source", rt5682_sto1_adc1l_enum);
1396 static SOC_ENUM_SINGLE_DECL(
1397 rt5682_sto1_adc1r_enum, RT5682_STO1_ADC_MIXER,
1398 RT5682_STO1_ADC1R_SRC_SFT, rt5682_sto1_adc1_src);
1400 static const struct snd_kcontrol_new rt5682_sto1_adc1r_mux =
1401 SOC_DAPM_ENUM("Stereo1 ADC1L Source", rt5682_sto1_adc1r_enum);
1403 /* STO1 ADC Source */
1404 /* MX-26 [11:10] [3:2] */
1405 static const char * const rt5682_sto1_adc_src[] = {
1409 static SOC_ENUM_SINGLE_DECL(
1410 rt5682_sto1_adcl_enum, RT5682_STO1_ADC_MIXER,
1411 RT5682_STO1_ADCL_SRC_SFT, rt5682_sto1_adc_src);
1413 static const struct snd_kcontrol_new rt5682_sto1_adcl_mux =
1414 SOC_DAPM_ENUM("Stereo1 ADCL Source", rt5682_sto1_adcl_enum);
1416 static SOC_ENUM_SINGLE_DECL(
1417 rt5682_sto1_adcr_enum, RT5682_STO1_ADC_MIXER,
1418 RT5682_STO1_ADCR_SRC_SFT, rt5682_sto1_adc_src);
1420 static const struct snd_kcontrol_new rt5682_sto1_adcr_mux =
1421 SOC_DAPM_ENUM("Stereo1 ADCR Source", rt5682_sto1_adcr_enum);
1423 /* STO1 ADC2 Source */
1424 /* MX-26 [12] [4] */
1425 static const char * const rt5682_sto1_adc2_src[] = {
1429 static SOC_ENUM_SINGLE_DECL(
1430 rt5682_sto1_adc2l_enum, RT5682_STO1_ADC_MIXER,
1431 RT5682_STO1_ADC2L_SRC_SFT, rt5682_sto1_adc2_src);
1433 static const struct snd_kcontrol_new rt5682_sto1_adc2l_mux =
1434 SOC_DAPM_ENUM("Stereo1 ADC2L Source", rt5682_sto1_adc2l_enum);
1436 static SOC_ENUM_SINGLE_DECL(
1437 rt5682_sto1_adc2r_enum, RT5682_STO1_ADC_MIXER,
1438 RT5682_STO1_ADC2R_SRC_SFT, rt5682_sto1_adc2_src);
1440 static const struct snd_kcontrol_new rt5682_sto1_adc2r_mux =
1441 SOC_DAPM_ENUM("Stereo1 ADC2R Source", rt5682_sto1_adc2r_enum);
1443 /* MX-79 [6:4] I2S1 ADC data location */
1444 static const unsigned int rt5682_if1_adc_slot_values[] = {
1451 static const char * const rt5682_if1_adc_slot_src[] = {
1452 "Slot 0", "Slot 2", "Slot 4", "Slot 6"
1455 static SOC_VALUE_ENUM_SINGLE_DECL(rt5682_if1_adc_slot_enum,
1456 RT5682_TDM_CTRL, RT5682_TDM_ADC_LCA_SFT, RT5682_TDM_ADC_LCA_MASK,
1457 rt5682_if1_adc_slot_src, rt5682_if1_adc_slot_values);
1459 static const struct snd_kcontrol_new rt5682_if1_adc_slot_mux =
1460 SOC_DAPM_ENUM("IF1 ADC Slot location", rt5682_if1_adc_slot_enum);
1462 /* Analog DAC L1 Source, Analog DAC R1 Source*/
1463 /* MX-2B [4], MX-2B [0]*/
1464 static const char * const rt5682_alg_dac1_src[] = {
1465 "Stereo1 DAC Mixer", "DAC1"
1468 static SOC_ENUM_SINGLE_DECL(
1469 rt5682_alg_dac_l1_enum, RT5682_A_DAC1_MUX,
1470 RT5682_A_DACL1_SFT, rt5682_alg_dac1_src);
1472 static const struct snd_kcontrol_new rt5682_alg_dac_l1_mux =
1473 SOC_DAPM_ENUM("Analog DAC L1 Source", rt5682_alg_dac_l1_enum);
1475 static SOC_ENUM_SINGLE_DECL(
1476 rt5682_alg_dac_r1_enum, RT5682_A_DAC1_MUX,
1477 RT5682_A_DACR1_SFT, rt5682_alg_dac1_src);
1479 static const struct snd_kcontrol_new rt5682_alg_dac_r1_mux =
1480 SOC_DAPM_ENUM("Analog DAC R1 Source", rt5682_alg_dac_r1_enum);
1483 static const struct snd_kcontrol_new hpol_switch =
1484 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5682_HP_CTRL_1,
1485 RT5682_L_MUTE_SFT, 1, 1);
1486 static const struct snd_kcontrol_new hpor_switch =
1487 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5682_HP_CTRL_1,
1488 RT5682_R_MUTE_SFT, 1, 1);
1490 static int rt5682_hp_event(struct snd_soc_dapm_widget *w,
1491 struct snd_kcontrol *kcontrol, int event)
1493 struct snd_soc_component *component =
1494 snd_soc_dapm_to_component(w->dapm);
1497 case SND_SOC_DAPM_PRE_PMU:
1498 snd_soc_component_write(component,
1499 RT5682_HP_LOGIC_CTRL_2, 0x0012);
1500 snd_soc_component_write(component,
1501 RT5682_HP_CTRL_2, 0x6000);
1502 snd_soc_component_update_bits(component,
1503 RT5682_DEPOP_1, 0x60, 0x60);
1504 snd_soc_component_update_bits(component,
1505 RT5682_DAC_ADC_DIG_VOL1, 0x00c0, 0x0080);
1508 case SND_SOC_DAPM_POST_PMD:
1509 snd_soc_component_update_bits(component,
1510 RT5682_DEPOP_1, 0x60, 0x0);
1511 snd_soc_component_write(component,
1512 RT5682_HP_CTRL_2, 0x0000);
1513 snd_soc_component_update_bits(component,
1514 RT5682_DAC_ADC_DIG_VOL1, 0x00c0, 0x0000);
1521 static int set_dmic_power(struct snd_soc_dapm_widget *w,
1522 struct snd_kcontrol *kcontrol, int event)
1524 struct snd_soc_component *component =
1525 snd_soc_dapm_to_component(w->dapm);
1526 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
1527 unsigned int delay = 50;
1529 if (rt5682->pdata.dmic_delay)
1530 delay = rt5682->pdata.dmic_delay;
1533 case SND_SOC_DAPM_POST_PMU:
1534 /*Add delay to avoid pop noise*/
1542 static int rt5682_set_verf(struct snd_soc_dapm_widget *w,
1543 struct snd_kcontrol *kcontrol, int event)
1545 struct snd_soc_component *component =
1546 snd_soc_dapm_to_component(w->dapm);
1549 case SND_SOC_DAPM_PRE_PMU:
1551 case RT5682_PWR_VREF1_BIT:
1552 snd_soc_component_update_bits(component,
1553 RT5682_PWR_ANLG_1, RT5682_PWR_FV1, 0);
1556 case RT5682_PWR_VREF2_BIT:
1557 snd_soc_component_update_bits(component,
1558 RT5682_PWR_ANLG_1, RT5682_PWR_FV2, 0);
1563 case SND_SOC_DAPM_POST_PMU:
1564 usleep_range(15000, 20000);
1566 case RT5682_PWR_VREF1_BIT:
1567 snd_soc_component_update_bits(component,
1568 RT5682_PWR_ANLG_1, RT5682_PWR_FV1,
1572 case RT5682_PWR_VREF2_BIT:
1573 snd_soc_component_update_bits(component,
1574 RT5682_PWR_ANLG_1, RT5682_PWR_FV2,
1584 static const unsigned int rt5682_adcdat_pin_values[] = {
1589 static const char * const rt5682_adcdat_pin_select[] = {
1594 static SOC_VALUE_ENUM_SINGLE_DECL(rt5682_adcdat_pin_enum,
1595 RT5682_GPIO_CTRL_1, RT5682_GP4_PIN_SFT, RT5682_GP4_PIN_MASK,
1596 rt5682_adcdat_pin_select, rt5682_adcdat_pin_values);
1598 static const struct snd_kcontrol_new rt5682_adcdat_pin_ctrl =
1599 SOC_DAPM_ENUM("ADCDAT", rt5682_adcdat_pin_enum);
1601 static const struct snd_soc_dapm_widget rt5682_dapm_widgets[] = {
1602 SND_SOC_DAPM_SUPPLY("LDO2", RT5682_PWR_ANLG_3, RT5682_PWR_LDO2_BIT,
1604 SND_SOC_DAPM_SUPPLY("PLL1", RT5682_PWR_ANLG_3, RT5682_PWR_PLL_BIT,
1606 SND_SOC_DAPM_SUPPLY("PLL2B", RT5682_PWR_ANLG_3, RT5682_PWR_PLL2B_BIT,
1608 SND_SOC_DAPM_SUPPLY("PLL2F", RT5682_PWR_ANLG_3, RT5682_PWR_PLL2F_BIT,
1609 0, set_filter_clk, SND_SOC_DAPM_PRE_PMU),
1610 SND_SOC_DAPM_SUPPLY("Vref1", RT5682_PWR_ANLG_1, RT5682_PWR_VREF1_BIT, 0,
1611 rt5682_set_verf, SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU),
1612 SND_SOC_DAPM_SUPPLY("Vref2", RT5682_PWR_ANLG_1, RT5682_PWR_VREF2_BIT, 0,
1614 SND_SOC_DAPM_SUPPLY("MICBIAS", SND_SOC_NOPM, 0, 0, NULL, 0),
1617 SND_SOC_DAPM_SUPPLY_S("DAC STO1 ASRC", 1, RT5682_PLL_TRACK_1,
1618 RT5682_DAC_STO1_ASRC_SFT, 0, NULL, 0),
1619 SND_SOC_DAPM_SUPPLY_S("ADC STO1 ASRC", 1, RT5682_PLL_TRACK_1,
1620 RT5682_ADC_STO1_ASRC_SFT, 0, NULL, 0),
1621 SND_SOC_DAPM_SUPPLY_S("AD ASRC", 1, RT5682_PLL_TRACK_1,
1622 RT5682_AD_ASRC_SFT, 0, NULL, 0),
1623 SND_SOC_DAPM_SUPPLY_S("DA ASRC", 1, RT5682_PLL_TRACK_1,
1624 RT5682_DA_ASRC_SFT, 0, NULL, 0),
1625 SND_SOC_DAPM_SUPPLY_S("DMIC ASRC", 1, RT5682_PLL_TRACK_1,
1626 RT5682_DMIC_ASRC_SFT, 0, NULL, 0),
1629 SND_SOC_DAPM_SUPPLY("MICBIAS1", RT5682_PWR_ANLG_2, RT5682_PWR_MB1_BIT,
1631 SND_SOC_DAPM_SUPPLY("MICBIAS2", RT5682_PWR_ANLG_2, RT5682_PWR_MB2_BIT,
1635 SND_SOC_DAPM_INPUT("DMIC L1"),
1636 SND_SOC_DAPM_INPUT("DMIC R1"),
1638 SND_SOC_DAPM_INPUT("IN1P"),
1640 SND_SOC_DAPM_SUPPLY("DMIC CLK", SND_SOC_NOPM, 0, 0,
1641 set_dmic_clk, SND_SOC_DAPM_PRE_PMU),
1642 SND_SOC_DAPM_SUPPLY("DMIC1 Power", RT5682_DMIC_CTRL_1,
1643 RT5682_DMIC_1_EN_SFT, 0, set_dmic_power, SND_SOC_DAPM_POST_PMU),
1646 SND_SOC_DAPM_PGA("BST1 CBJ", SND_SOC_NOPM,
1650 SND_SOC_DAPM_MIXER("RECMIX1L", SND_SOC_NOPM, 0, 0, rt5682_rec1_l_mix,
1651 ARRAY_SIZE(rt5682_rec1_l_mix)),
1652 SND_SOC_DAPM_SUPPLY("RECMIX1L Power", RT5682_PWR_ANLG_2,
1653 RT5682_PWR_RM1_L_BIT, 0, NULL, 0),
1656 SND_SOC_DAPM_ADC("ADC1 L", NULL, SND_SOC_NOPM, 0, 0),
1657 SND_SOC_DAPM_ADC("ADC1 R", NULL, SND_SOC_NOPM, 0, 0),
1659 SND_SOC_DAPM_SUPPLY("ADC1 L Power", RT5682_PWR_DIG_1,
1660 RT5682_PWR_ADC_L1_BIT, 0, NULL, 0),
1661 SND_SOC_DAPM_SUPPLY("ADC1 R Power", RT5682_PWR_DIG_1,
1662 RT5682_PWR_ADC_R1_BIT, 0, NULL, 0),
1663 SND_SOC_DAPM_SUPPLY("ADC1 clock", RT5682_CHOP_ADC,
1664 RT5682_CKGEN_ADC1_SFT, 0, NULL, 0),
1667 SND_SOC_DAPM_MUX("Stereo1 ADC L1 Mux", SND_SOC_NOPM, 0, 0,
1668 &rt5682_sto1_adc1l_mux),
1669 SND_SOC_DAPM_MUX("Stereo1 ADC R1 Mux", SND_SOC_NOPM, 0, 0,
1670 &rt5682_sto1_adc1r_mux),
1671 SND_SOC_DAPM_MUX("Stereo1 ADC L2 Mux", SND_SOC_NOPM, 0, 0,
1672 &rt5682_sto1_adc2l_mux),
1673 SND_SOC_DAPM_MUX("Stereo1 ADC R2 Mux", SND_SOC_NOPM, 0, 0,
1674 &rt5682_sto1_adc2r_mux),
1675 SND_SOC_DAPM_MUX("Stereo1 ADC L Mux", SND_SOC_NOPM, 0, 0,
1676 &rt5682_sto1_adcl_mux),
1677 SND_SOC_DAPM_MUX("Stereo1 ADC R Mux", SND_SOC_NOPM, 0, 0,
1678 &rt5682_sto1_adcr_mux),
1679 SND_SOC_DAPM_MUX("IF1_ADC Mux", SND_SOC_NOPM, 0, 0,
1680 &rt5682_if1_adc_slot_mux),
1683 SND_SOC_DAPM_SUPPLY("ADC Stereo1 Filter", RT5682_PWR_DIG_2,
1684 RT5682_PWR_ADC_S1F_BIT, 0, set_filter_clk,
1685 SND_SOC_DAPM_PRE_PMU),
1686 SND_SOC_DAPM_MIXER("Stereo1 ADC MIXL", RT5682_STO1_ADC_DIG_VOL,
1687 RT5682_L_MUTE_SFT, 1, rt5682_sto1_adc_l_mix,
1688 ARRAY_SIZE(rt5682_sto1_adc_l_mix)),
1689 SND_SOC_DAPM_MIXER("Stereo1 ADC MIXR", RT5682_STO1_ADC_DIG_VOL,
1690 RT5682_R_MUTE_SFT, 1, rt5682_sto1_adc_r_mix,
1691 ARRAY_SIZE(rt5682_sto1_adc_r_mix)),
1692 SND_SOC_DAPM_SUPPLY("BTN Detection Mode", RT5682_SAR_IL_CMD_1,
1696 SND_SOC_DAPM_PGA("Stereo1 ADC MIX", SND_SOC_NOPM, 0, 0, NULL, 0),
1698 /* Digital Interface */
1699 SND_SOC_DAPM_SUPPLY("I2S1", RT5682_PWR_DIG_1, RT5682_PWR_I2S1_BIT,
1701 SND_SOC_DAPM_SUPPLY("I2S2", RT5682_PWR_DIG_1, RT5682_PWR_I2S2_BIT,
1703 SND_SOC_DAPM_PGA("IF1 DAC1", SND_SOC_NOPM, 0, 0, NULL, 0),
1704 SND_SOC_DAPM_PGA("IF1 DAC1 L", SND_SOC_NOPM, 0, 0, NULL, 0),
1705 SND_SOC_DAPM_PGA("IF1 DAC1 R", SND_SOC_NOPM, 0, 0, NULL, 0),
1706 SND_SOC_DAPM_PGA("SOUND DAC L", SND_SOC_NOPM, 0, 0, NULL, 0),
1707 SND_SOC_DAPM_PGA("SOUND DAC R", SND_SOC_NOPM, 0, 0, NULL, 0),
1709 /* Digital Interface Select */
1710 SND_SOC_DAPM_MUX("IF1 01 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
1711 &rt5682_if1_01_adc_swap_mux),
1712 SND_SOC_DAPM_MUX("IF1 23 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
1713 &rt5682_if1_23_adc_swap_mux),
1714 SND_SOC_DAPM_MUX("IF1 45 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
1715 &rt5682_if1_45_adc_swap_mux),
1716 SND_SOC_DAPM_MUX("IF1 67 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
1717 &rt5682_if1_67_adc_swap_mux),
1718 SND_SOC_DAPM_MUX("IF2 ADC Swap Mux", SND_SOC_NOPM, 0, 0,
1719 &rt5682_if2_adc_swap_mux),
1721 SND_SOC_DAPM_MUX("ADCDAT Mux", SND_SOC_NOPM, 0, 0,
1722 &rt5682_adcdat_pin_ctrl),
1724 SND_SOC_DAPM_MUX("DAC L Mux", SND_SOC_NOPM, 0, 0,
1726 SND_SOC_DAPM_MUX("DAC R Mux", SND_SOC_NOPM, 0, 0,
1729 /* Audio Interface */
1730 SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0,
1731 RT5682_I2S1_SDP, RT5682_SEL_ADCDAT_SFT, 1),
1732 SND_SOC_DAPM_AIF_OUT("AIF2TX", "AIF2 Capture", 0,
1733 RT5682_I2S2_SDP, RT5682_I2S2_PIN_CFG_SFT, 1),
1734 SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM, 0, 0),
1735 SND_SOC_DAPM_AIF_IN("SDWRX", "SDW Playback", 0, SND_SOC_NOPM, 0, 0),
1736 SND_SOC_DAPM_AIF_OUT("SDWTX", "SDW Capture", 0, SND_SOC_NOPM, 0, 0),
1739 /* DAC mixer before sound effect */
1740 SND_SOC_DAPM_MIXER("DAC1 MIXL", SND_SOC_NOPM, 0, 0,
1741 rt5682_dac_l_mix, ARRAY_SIZE(rt5682_dac_l_mix)),
1742 SND_SOC_DAPM_MIXER("DAC1 MIXR", SND_SOC_NOPM, 0, 0,
1743 rt5682_dac_r_mix, ARRAY_SIZE(rt5682_dac_r_mix)),
1745 /* DAC channel Mux */
1746 SND_SOC_DAPM_MUX("DAC L1 Source", SND_SOC_NOPM, 0, 0,
1747 &rt5682_alg_dac_l1_mux),
1748 SND_SOC_DAPM_MUX("DAC R1 Source", SND_SOC_NOPM, 0, 0,
1749 &rt5682_alg_dac_r1_mux),
1752 SND_SOC_DAPM_SUPPLY("DAC Stereo1 Filter", RT5682_PWR_DIG_2,
1753 RT5682_PWR_DAC_S1F_BIT, 0, set_filter_clk,
1754 SND_SOC_DAPM_PRE_PMU),
1755 SND_SOC_DAPM_MIXER("Stereo1 DAC MIXL", SND_SOC_NOPM, 0, 0,
1756 rt5682_sto1_dac_l_mix, ARRAY_SIZE(rt5682_sto1_dac_l_mix)),
1757 SND_SOC_DAPM_MIXER("Stereo1 DAC MIXR", SND_SOC_NOPM, 0, 0,
1758 rt5682_sto1_dac_r_mix, ARRAY_SIZE(rt5682_sto1_dac_r_mix)),
1761 SND_SOC_DAPM_DAC("DAC L1", NULL, RT5682_PWR_DIG_1,
1762 RT5682_PWR_DAC_L1_BIT, 0),
1763 SND_SOC_DAPM_DAC("DAC R1", NULL, RT5682_PWR_DIG_1,
1764 RT5682_PWR_DAC_R1_BIT, 0),
1765 SND_SOC_DAPM_SUPPLY_S("DAC 1 Clock", 3, RT5682_CHOP_DAC,
1766 RT5682_CKGEN_DAC1_SFT, 0, NULL, 0),
1769 SND_SOC_DAPM_PGA_S("HP Amp", 1, SND_SOC_NOPM, 0, 0, rt5682_hp_event,
1770 SND_SOC_DAPM_POST_PMD | SND_SOC_DAPM_PRE_PMU),
1772 SND_SOC_DAPM_SUPPLY("HP Amp L", RT5682_PWR_ANLG_1,
1773 RT5682_PWR_HA_L_BIT, 0, NULL, 0),
1774 SND_SOC_DAPM_SUPPLY("HP Amp R", RT5682_PWR_ANLG_1,
1775 RT5682_PWR_HA_R_BIT, 0, NULL, 0),
1776 SND_SOC_DAPM_SUPPLY_S("Charge Pump", 1, RT5682_DEPOP_1,
1777 RT5682_PUMP_EN_SFT, 0, NULL, 0),
1778 SND_SOC_DAPM_SUPPLY_S("Capless", 2, RT5682_DEPOP_1,
1779 RT5682_CAPLESS_EN_SFT, 0, NULL, 0),
1781 SND_SOC_DAPM_SWITCH("HPOL Playback", SND_SOC_NOPM, 0, 0,
1783 SND_SOC_DAPM_SWITCH("HPOR Playback", SND_SOC_NOPM, 0, 0,
1787 SND_SOC_DAPM_SUPPLY("CLKDET SYS", RT5682_CLK_DET,
1788 RT5682_SYS_CLK_DET_SFT, 0, NULL, 0),
1789 SND_SOC_DAPM_SUPPLY("CLKDET PLL1", RT5682_CLK_DET,
1790 RT5682_PLL1_CLK_DET_SFT, 0, NULL, 0),
1791 SND_SOC_DAPM_SUPPLY("CLKDET PLL2", RT5682_CLK_DET,
1792 RT5682_PLL2_CLK_DET_SFT, 0, NULL, 0),
1793 SND_SOC_DAPM_SUPPLY("CLKDET", RT5682_CLK_DET,
1794 RT5682_POW_CLK_DET_SFT, 0, NULL, 0),
1797 SND_SOC_DAPM_OUTPUT("HPOL"),
1798 SND_SOC_DAPM_OUTPUT("HPOR"),
1801 static const struct snd_soc_dapm_route rt5682_dapm_routes[] = {
1803 {"ADC Stereo1 Filter", NULL, "PLL1", is_sys_clk_from_pll1},
1804 {"ADC Stereo1 Filter", NULL, "PLL2B", is_sys_clk_from_pll2},
1805 {"ADC Stereo1 Filter", NULL, "PLL2F", is_sys_clk_from_pll2},
1806 {"DAC Stereo1 Filter", NULL, "PLL1", is_sys_clk_from_pll1},
1807 {"DAC Stereo1 Filter", NULL, "PLL2B", is_sys_clk_from_pll2},
1808 {"DAC Stereo1 Filter", NULL, "PLL2F", is_sys_clk_from_pll2},
1811 {"ADC Stereo1 Filter", NULL, "ADC STO1 ASRC", is_using_asrc},
1812 {"DAC Stereo1 Filter", NULL, "DAC STO1 ASRC", is_using_asrc},
1813 {"ADC STO1 ASRC", NULL, "AD ASRC"},
1814 {"ADC STO1 ASRC", NULL, "DA ASRC"},
1815 {"ADC STO1 ASRC", NULL, "CLKDET"},
1816 {"DAC STO1 ASRC", NULL, "AD ASRC"},
1817 {"DAC STO1 ASRC", NULL, "DA ASRC"},
1818 {"DAC STO1 ASRC", NULL, "CLKDET"},
1821 {"MICBIAS1", NULL, "Vref1"},
1822 {"MICBIAS2", NULL, "Vref1"},
1824 {"CLKDET SYS", NULL, "CLKDET"},
1826 {"IN1P", NULL, "LDO2"},
1828 {"BST1 CBJ", NULL, "IN1P"},
1830 {"RECMIX1L", "CBJ Switch", "BST1 CBJ"},
1831 {"RECMIX1L", NULL, "RECMIX1L Power"},
1833 {"ADC1 L", NULL, "RECMIX1L"},
1834 {"ADC1 L", NULL, "ADC1 L Power"},
1835 {"ADC1 L", NULL, "ADC1 clock"},
1837 {"DMIC L1", NULL, "DMIC CLK"},
1838 {"DMIC L1", NULL, "DMIC1 Power"},
1839 {"DMIC R1", NULL, "DMIC CLK"},
1840 {"DMIC R1", NULL, "DMIC1 Power"},
1841 {"DMIC CLK", NULL, "DMIC ASRC"},
1843 {"Stereo1 ADC L Mux", "ADC1 L", "ADC1 L"},
1844 {"Stereo1 ADC L Mux", "ADC1 R", "ADC1 R"},
1845 {"Stereo1 ADC R Mux", "ADC1 L", "ADC1 L"},
1846 {"Stereo1 ADC R Mux", "ADC1 R", "ADC1 R"},
1848 {"Stereo1 ADC L1 Mux", "ADC", "Stereo1 ADC L Mux"},
1849 {"Stereo1 ADC L1 Mux", "DAC MIX", "Stereo1 DAC MIXL"},
1850 {"Stereo1 ADC L2 Mux", "DMIC", "DMIC L1"},
1851 {"Stereo1 ADC L2 Mux", "DAC MIX", "Stereo1 DAC MIXL"},
1853 {"Stereo1 ADC R1 Mux", "ADC", "Stereo1 ADC R Mux"},
1854 {"Stereo1 ADC R1 Mux", "DAC MIX", "Stereo1 DAC MIXR"},
1855 {"Stereo1 ADC R2 Mux", "DMIC", "DMIC R1"},
1856 {"Stereo1 ADC R2 Mux", "DAC MIX", "Stereo1 DAC MIXR"},
1858 {"Stereo1 ADC MIXL", "ADC1 Switch", "Stereo1 ADC L1 Mux"},
1859 {"Stereo1 ADC MIXL", "ADC2 Switch", "Stereo1 ADC L2 Mux"},
1860 {"Stereo1 ADC MIXL", NULL, "ADC Stereo1 Filter"},
1862 {"Stereo1 ADC MIXR", "ADC1 Switch", "Stereo1 ADC R1 Mux"},
1863 {"Stereo1 ADC MIXR", "ADC2 Switch", "Stereo1 ADC R2 Mux"},
1864 {"Stereo1 ADC MIXR", NULL, "ADC Stereo1 Filter"},
1866 {"ADC Stereo1 Filter", NULL, "BTN Detection Mode"},
1868 {"Stereo1 ADC MIX", NULL, "Stereo1 ADC MIXL"},
1869 {"Stereo1 ADC MIX", NULL, "Stereo1 ADC MIXR"},
1871 {"IF1 01 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1872 {"IF1 01 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1873 {"IF1 01 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1874 {"IF1 01 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1875 {"IF1 23 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1876 {"IF1 23 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1877 {"IF1 23 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1878 {"IF1 23 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1879 {"IF1 45 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1880 {"IF1 45 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1881 {"IF1 45 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1882 {"IF1 45 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1883 {"IF1 67 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1884 {"IF1 67 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1885 {"IF1 67 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1886 {"IF1 67 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1888 {"IF1_ADC Mux", "Slot 0", "IF1 01 ADC Swap Mux"},
1889 {"IF1_ADC Mux", "Slot 2", "IF1 23 ADC Swap Mux"},
1890 {"IF1_ADC Mux", "Slot 4", "IF1 45 ADC Swap Mux"},
1891 {"IF1_ADC Mux", "Slot 6", "IF1 67 ADC Swap Mux"},
1892 {"ADCDAT Mux", "ADCDAT1", "IF1_ADC Mux"},
1893 {"AIF1TX", NULL, "I2S1"},
1894 {"AIF1TX", NULL, "ADCDAT Mux"},
1895 {"IF2 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1896 {"IF2 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1897 {"IF2 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1898 {"IF2 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1899 {"ADCDAT Mux", "ADCDAT2", "IF2 ADC Swap Mux"},
1900 {"AIF2TX", NULL, "ADCDAT Mux"},
1902 {"SDWTX", NULL, "PLL2B"},
1903 {"SDWTX", NULL, "PLL2F"},
1904 {"SDWTX", NULL, "ADCDAT Mux"},
1906 {"IF1 DAC1 L", NULL, "AIF1RX"},
1907 {"IF1 DAC1 L", NULL, "I2S1"},
1908 {"IF1 DAC1 L", NULL, "DAC Stereo1 Filter"},
1909 {"IF1 DAC1 R", NULL, "AIF1RX"},
1910 {"IF1 DAC1 R", NULL, "I2S1"},
1911 {"IF1 DAC1 R", NULL, "DAC Stereo1 Filter"},
1913 {"SOUND DAC L", NULL, "SDWRX"},
1914 {"SOUND DAC L", NULL, "DAC Stereo1 Filter"},
1915 {"SOUND DAC L", NULL, "PLL2B"},
1916 {"SOUND DAC L", NULL, "PLL2F"},
1917 {"SOUND DAC R", NULL, "SDWRX"},
1918 {"SOUND DAC R", NULL, "DAC Stereo1 Filter"},
1919 {"SOUND DAC R", NULL, "PLL2B"},
1920 {"SOUND DAC R", NULL, "PLL2F"},
1922 {"DAC L Mux", "IF1", "IF1 DAC1 L"},
1923 {"DAC L Mux", "SOUND", "SOUND DAC L"},
1924 {"DAC R Mux", "IF1", "IF1 DAC1 R"},
1925 {"DAC R Mux", "SOUND", "SOUND DAC R"},
1927 {"DAC1 MIXL", "Stereo ADC Switch", "Stereo1 ADC MIXL"},
1928 {"DAC1 MIXL", "DAC1 Switch", "DAC L Mux"},
1929 {"DAC1 MIXR", "Stereo ADC Switch", "Stereo1 ADC MIXR"},
1930 {"DAC1 MIXR", "DAC1 Switch", "DAC R Mux"},
1932 {"Stereo1 DAC MIXL", "DAC L1 Switch", "DAC1 MIXL"},
1933 {"Stereo1 DAC MIXL", "DAC R1 Switch", "DAC1 MIXR"},
1935 {"Stereo1 DAC MIXR", "DAC R1 Switch", "DAC1 MIXR"},
1936 {"Stereo1 DAC MIXR", "DAC L1 Switch", "DAC1 MIXL"},
1938 {"DAC L1 Source", "DAC1", "DAC1 MIXL"},
1939 {"DAC L1 Source", "Stereo1 DAC Mixer", "Stereo1 DAC MIXL"},
1940 {"DAC R1 Source", "DAC1", "DAC1 MIXR"},
1941 {"DAC R1 Source", "Stereo1 DAC Mixer", "Stereo1 DAC MIXR"},
1943 {"DAC L1", NULL, "DAC L1 Source"},
1944 {"DAC R1", NULL, "DAC R1 Source"},
1946 {"DAC L1", NULL, "DAC 1 Clock"},
1947 {"DAC R1", NULL, "DAC 1 Clock"},
1949 {"HP Amp", NULL, "DAC L1"},
1950 {"HP Amp", NULL, "DAC R1"},
1951 {"HP Amp", NULL, "HP Amp L"},
1952 {"HP Amp", NULL, "HP Amp R"},
1953 {"HP Amp", NULL, "Capless"},
1954 {"HP Amp", NULL, "Charge Pump"},
1955 {"HP Amp", NULL, "CLKDET SYS"},
1956 {"HP Amp", NULL, "Vref1"},
1957 {"HPOL Playback", "Switch", "HP Amp"},
1958 {"HPOR Playback", "Switch", "HP Amp"},
1959 {"HPOL", NULL, "HPOL Playback"},
1960 {"HPOR", NULL, "HPOR Playback"},
1963 static int rt5682_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask,
1964 unsigned int rx_mask, int slots, int slot_width)
1966 struct snd_soc_component *component = dai->component;
1967 unsigned int cl, val = 0;
1969 if (tx_mask || rx_mask)
1970 snd_soc_component_update_bits(component, RT5682_TDM_ADDA_CTRL_2,
1971 RT5682_TDM_EN, RT5682_TDM_EN);
1973 snd_soc_component_update_bits(component, RT5682_TDM_ADDA_CTRL_2,
1978 val |= RT5682_TDM_TX_CH_4;
1979 val |= RT5682_TDM_RX_CH_4;
1982 val |= RT5682_TDM_TX_CH_6;
1983 val |= RT5682_TDM_RX_CH_6;
1986 val |= RT5682_TDM_TX_CH_8;
1987 val |= RT5682_TDM_RX_CH_8;
1995 snd_soc_component_update_bits(component, RT5682_TDM_CTRL,
1996 RT5682_TDM_TX_CH_MASK | RT5682_TDM_RX_CH_MASK, val);
1998 switch (slot_width) {
2000 if (tx_mask || rx_mask)
2002 cl = RT5682_I2S1_TX_CHL_8 | RT5682_I2S1_RX_CHL_8;
2005 val = RT5682_TDM_CL_16;
2006 cl = RT5682_I2S1_TX_CHL_16 | RT5682_I2S1_RX_CHL_16;
2009 val = RT5682_TDM_CL_20;
2010 cl = RT5682_I2S1_TX_CHL_20 | RT5682_I2S1_RX_CHL_20;
2013 val = RT5682_TDM_CL_24;
2014 cl = RT5682_I2S1_TX_CHL_24 | RT5682_I2S1_RX_CHL_24;
2017 val = RT5682_TDM_CL_32;
2018 cl = RT5682_I2S1_TX_CHL_32 | RT5682_I2S1_RX_CHL_32;
2024 snd_soc_component_update_bits(component, RT5682_TDM_TCON_CTRL,
2025 RT5682_TDM_CL_MASK, val);
2026 snd_soc_component_update_bits(component, RT5682_I2S1_SDP,
2027 RT5682_I2S1_TX_CHL_MASK | RT5682_I2S1_RX_CHL_MASK, cl);
2032 static int rt5682_hw_params(struct snd_pcm_substream *substream,
2033 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
2035 struct snd_soc_component *component = dai->component;
2036 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
2037 unsigned int len_1 = 0, len_2 = 0;
2038 int pre_div, frame_size;
2040 rt5682->lrck[dai->id] = params_rate(params);
2041 pre_div = rl6231_get_clk_info(rt5682->sysclk, rt5682->lrck[dai->id]);
2043 frame_size = snd_soc_params_to_frame_size(params);
2044 if (frame_size < 0) {
2045 dev_err(component->dev, "Unsupported frame size: %d\n",
2050 dev_dbg(dai->dev, "lrck is %dHz and pre_div is %d for iis %d\n",
2051 rt5682->lrck[dai->id], pre_div, dai->id);
2053 switch (params_width(params)) {
2057 len_1 |= RT5682_I2S1_DL_20;
2058 len_2 |= RT5682_I2S2_DL_20;
2061 len_1 |= RT5682_I2S1_DL_24;
2062 len_2 |= RT5682_I2S2_DL_24;
2065 len_1 |= RT5682_I2S1_DL_32;
2066 len_2 |= RT5682_I2S2_DL_24;
2069 len_1 |= RT5682_I2S2_DL_8;
2070 len_2 |= RT5682_I2S2_DL_8;
2078 snd_soc_component_update_bits(component, RT5682_I2S1_SDP,
2079 RT5682_I2S1_DL_MASK, len_1);
2080 if (rt5682->master[RT5682_AIF1]) {
2081 snd_soc_component_update_bits(component,
2082 RT5682_ADDA_CLK_1, RT5682_I2S_M_DIV_MASK |
2083 RT5682_I2S_CLK_SRC_MASK,
2084 pre_div << RT5682_I2S_M_DIV_SFT |
2085 (rt5682->sysclk_src) << RT5682_I2S_CLK_SRC_SFT);
2087 if (params_channels(params) == 1) /* mono mode */
2088 snd_soc_component_update_bits(component,
2089 RT5682_I2S1_SDP, RT5682_I2S1_MONO_MASK,
2090 RT5682_I2S1_MONO_EN);
2092 snd_soc_component_update_bits(component,
2093 RT5682_I2S1_SDP, RT5682_I2S1_MONO_MASK,
2094 RT5682_I2S1_MONO_DIS);
2097 snd_soc_component_update_bits(component, RT5682_I2S2_SDP,
2098 RT5682_I2S2_DL_MASK, len_2);
2099 if (rt5682->master[RT5682_AIF2]) {
2100 snd_soc_component_update_bits(component,
2101 RT5682_I2S_M_CLK_CTRL_1, RT5682_I2S2_M_PD_MASK,
2102 pre_div << RT5682_I2S2_M_PD_SFT);
2104 if (params_channels(params) == 1) /* mono mode */
2105 snd_soc_component_update_bits(component,
2106 RT5682_I2S2_SDP, RT5682_I2S2_MONO_MASK,
2107 RT5682_I2S2_MONO_EN);
2109 snd_soc_component_update_bits(component,
2110 RT5682_I2S2_SDP, RT5682_I2S2_MONO_MASK,
2111 RT5682_I2S2_MONO_DIS);
2114 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id);
2121 static int rt5682_set_dai_fmt(struct snd_soc_dai *dai, unsigned int fmt)
2123 struct snd_soc_component *component = dai->component;
2124 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
2125 unsigned int reg_val = 0, tdm_ctrl = 0;
2127 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
2128 case SND_SOC_DAIFMT_CBM_CFM:
2129 rt5682->master[dai->id] = 1;
2131 case SND_SOC_DAIFMT_CBS_CFS:
2132 rt5682->master[dai->id] = 0;
2138 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
2139 case SND_SOC_DAIFMT_NB_NF:
2141 case SND_SOC_DAIFMT_IB_NF:
2142 reg_val |= RT5682_I2S_BP_INV;
2143 tdm_ctrl |= RT5682_TDM_S_BP_INV;
2145 case SND_SOC_DAIFMT_NB_IF:
2146 if (dai->id == RT5682_AIF1)
2147 tdm_ctrl |= RT5682_TDM_S_LP_INV | RT5682_TDM_M_BP_INV;
2151 case SND_SOC_DAIFMT_IB_IF:
2152 if (dai->id == RT5682_AIF1)
2153 tdm_ctrl |= RT5682_TDM_S_BP_INV | RT5682_TDM_S_LP_INV |
2154 RT5682_TDM_M_BP_INV | RT5682_TDM_M_LP_INV;
2162 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
2163 case SND_SOC_DAIFMT_I2S:
2165 case SND_SOC_DAIFMT_LEFT_J:
2166 reg_val |= RT5682_I2S_DF_LEFT;
2167 tdm_ctrl |= RT5682_TDM_DF_LEFT;
2169 case SND_SOC_DAIFMT_DSP_A:
2170 reg_val |= RT5682_I2S_DF_PCM_A;
2171 tdm_ctrl |= RT5682_TDM_DF_PCM_A;
2173 case SND_SOC_DAIFMT_DSP_B:
2174 reg_val |= RT5682_I2S_DF_PCM_B;
2175 tdm_ctrl |= RT5682_TDM_DF_PCM_B;
2183 snd_soc_component_update_bits(component, RT5682_I2S1_SDP,
2184 RT5682_I2S_DF_MASK, reg_val);
2185 snd_soc_component_update_bits(component, RT5682_TDM_TCON_CTRL,
2186 RT5682_TDM_MS_MASK | RT5682_TDM_S_BP_MASK |
2187 RT5682_TDM_DF_MASK | RT5682_TDM_M_BP_MASK |
2188 RT5682_TDM_M_LP_MASK | RT5682_TDM_S_LP_MASK,
2189 tdm_ctrl | rt5682->master[dai->id]);
2192 if (rt5682->master[dai->id] == 0)
2193 reg_val |= RT5682_I2S2_MS_S;
2194 snd_soc_component_update_bits(component, RT5682_I2S2_SDP,
2195 RT5682_I2S2_MS_MASK | RT5682_I2S_BP_MASK |
2196 RT5682_I2S_DF_MASK, reg_val);
2199 dev_err(component->dev, "Invalid dai->id: %d\n", dai->id);
2205 static int rt5682_set_component_sysclk(struct snd_soc_component *component,
2206 int clk_id, int source, unsigned int freq, int dir)
2208 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
2209 unsigned int reg_val = 0, src = 0;
2211 if (freq == rt5682->sysclk && clk_id == rt5682->sysclk_src)
2215 case RT5682_SCLK_S_MCLK:
2216 reg_val |= RT5682_SCLK_SRC_MCLK;
2217 src = RT5682_CLK_SRC_MCLK;
2219 case RT5682_SCLK_S_PLL1:
2220 reg_val |= RT5682_SCLK_SRC_PLL1;
2221 src = RT5682_CLK_SRC_PLL1;
2223 case RT5682_SCLK_S_PLL2:
2224 reg_val |= RT5682_SCLK_SRC_PLL2;
2225 src = RT5682_CLK_SRC_PLL2;
2227 case RT5682_SCLK_S_RCCLK:
2228 reg_val |= RT5682_SCLK_SRC_RCCLK;
2229 src = RT5682_CLK_SRC_RCCLK;
2232 dev_err(component->dev, "Invalid clock id (%d)\n", clk_id);
2235 snd_soc_component_update_bits(component, RT5682_GLB_CLK,
2236 RT5682_SCLK_SRC_MASK, reg_val);
2238 if (rt5682->master[RT5682_AIF2]) {
2239 snd_soc_component_update_bits(component,
2240 RT5682_I2S_M_CLK_CTRL_1, RT5682_I2S2_SRC_MASK,
2241 src << RT5682_I2S2_SRC_SFT);
2244 rt5682->sysclk = freq;
2245 rt5682->sysclk_src = clk_id;
2247 dev_dbg(component->dev, "Sysclk is %dHz and clock id is %d\n",
2253 static int rt5682_set_component_pll(struct snd_soc_component *component,
2254 int pll_id, int source, unsigned int freq_in,
2255 unsigned int freq_out)
2257 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
2258 struct rl6231_pll_code pll_code, pll2f_code, pll2b_code;
2259 unsigned int pll2_fout1, pll2_ps_val;
2262 if (source == rt5682->pll_src[pll_id] &&
2263 freq_in == rt5682->pll_in[pll_id] &&
2264 freq_out == rt5682->pll_out[pll_id])
2267 if (!freq_in || !freq_out) {
2268 dev_dbg(component->dev, "PLL disabled\n");
2270 rt5682->pll_in[pll_id] = 0;
2271 rt5682->pll_out[pll_id] = 0;
2272 snd_soc_component_update_bits(component, RT5682_GLB_CLK,
2273 RT5682_SCLK_SRC_MASK, RT5682_SCLK_SRC_MCLK);
2277 if (pll_id == RT5682_PLL2) {
2279 case RT5682_PLL2_S_MCLK:
2280 snd_soc_component_update_bits(component,
2281 RT5682_GLB_CLK, RT5682_PLL2_SRC_MASK,
2282 RT5682_PLL2_SRC_MCLK);
2285 dev_err(component->dev, "Unknown PLL2 Source %d\n",
2291 * PLL2 concatenates 2 PLL units.
2292 * We suggest the Fout of the front PLL is 3.84MHz.
2294 pll2_fout1 = 3840000;
2295 ret = rl6231_pll_calc(freq_in, pll2_fout1, &pll2f_code);
2297 dev_err(component->dev, "Unsupport input clock %d\n",
2301 dev_dbg(component->dev, "PLL2F: fin=%d fout=%d bypass=%d m=%d n=%d k=%d\n",
2302 freq_in, pll2_fout1,
2304 (pll2f_code.m_bp ? 0 : pll2f_code.m_code),
2305 pll2f_code.n_code, pll2f_code.k_code);
2307 ret = rl6231_pll_calc(pll2_fout1, freq_out, &pll2b_code);
2309 dev_err(component->dev, "Unsupport input clock %d\n",
2313 dev_dbg(component->dev, "PLL2B: fin=%d fout=%d bypass=%d m=%d n=%d k=%d\n",
2314 pll2_fout1, freq_out,
2316 (pll2b_code.m_bp ? 0 : pll2b_code.m_code),
2317 pll2b_code.n_code, pll2b_code.k_code);
2319 snd_soc_component_write(component, RT5682_PLL2_CTRL_1,
2320 pll2f_code.k_code << RT5682_PLL2F_K_SFT |
2321 pll2b_code.k_code << RT5682_PLL2B_K_SFT |
2323 snd_soc_component_write(component, RT5682_PLL2_CTRL_2,
2324 pll2f_code.m_code << RT5682_PLL2F_M_SFT |
2326 snd_soc_component_write(component, RT5682_PLL2_CTRL_3,
2327 pll2f_code.n_code << RT5682_PLL2F_N_SFT);
2329 if (freq_out == 22579200)
2330 pll2_ps_val = 1 << RT5682_PLL2B_SEL_PS_SFT;
2332 pll2_ps_val = 1 << RT5682_PLL2B_PS_BYP_SFT;
2333 snd_soc_component_update_bits(component, RT5682_PLL2_CTRL_4,
2334 RT5682_PLL2B_SEL_PS_MASK | RT5682_PLL2B_PS_BYP_MASK |
2335 RT5682_PLL2B_M_BP_MASK | RT5682_PLL2F_M_BP_MASK | 0xf,
2337 (pll2b_code.m_bp ? 1 : 0) << RT5682_PLL2B_M_BP_SFT |
2338 (pll2f_code.m_bp ? 1 : 0) << RT5682_PLL2F_M_BP_SFT |
2342 case RT5682_PLL1_S_MCLK:
2343 snd_soc_component_update_bits(component,
2344 RT5682_GLB_CLK, RT5682_PLL1_SRC_MASK,
2345 RT5682_PLL1_SRC_MCLK);
2347 case RT5682_PLL1_S_BCLK1:
2348 snd_soc_component_update_bits(component,
2349 RT5682_GLB_CLK, RT5682_PLL1_SRC_MASK,
2350 RT5682_PLL1_SRC_BCLK1);
2353 dev_err(component->dev, "Unknown PLL1 Source %d\n",
2358 ret = rl6231_pll_calc(freq_in, freq_out, &pll_code);
2360 dev_err(component->dev, "Unsupport input clock %d\n",
2365 dev_dbg(component->dev, "bypass=%d m=%d n=%d k=%d\n",
2366 pll_code.m_bp, (pll_code.m_bp ? 0 : pll_code.m_code),
2367 pll_code.n_code, pll_code.k_code);
2369 snd_soc_component_write(component, RT5682_PLL_CTRL_1,
2370 pll_code.n_code << RT5682_PLL_N_SFT | pll_code.k_code);
2371 snd_soc_component_write(component, RT5682_PLL_CTRL_2,
2372 (pll_code.m_bp ? 0 : pll_code.m_code) << RT5682_PLL_M_SFT |
2373 pll_code.m_bp << RT5682_PLL_M_BP_SFT | RT5682_PLL_RST);
2376 rt5682->pll_in[pll_id] = freq_in;
2377 rt5682->pll_out[pll_id] = freq_out;
2378 rt5682->pll_src[pll_id] = source;
2383 static int rt5682_set_bclk1_ratio(struct snd_soc_dai *dai, unsigned int ratio)
2385 struct snd_soc_component *component = dai->component;
2386 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
2388 rt5682->bclk[dai->id] = ratio;
2392 snd_soc_component_update_bits(component, RT5682_TDM_TCON_CTRL,
2393 RT5682_TDM_BCLK_MS1_MASK, RT5682_TDM_BCLK_MS1_256);
2396 snd_soc_component_update_bits(component, RT5682_TDM_TCON_CTRL,
2397 RT5682_TDM_BCLK_MS1_MASK, RT5682_TDM_BCLK_MS1_128);
2400 snd_soc_component_update_bits(component, RT5682_TDM_TCON_CTRL,
2401 RT5682_TDM_BCLK_MS1_MASK, RT5682_TDM_BCLK_MS1_64);
2404 snd_soc_component_update_bits(component, RT5682_TDM_TCON_CTRL,
2405 RT5682_TDM_BCLK_MS1_MASK, RT5682_TDM_BCLK_MS1_32);
2408 dev_err(dai->dev, "Invalid bclk1 ratio %d\n", ratio);
2415 static int rt5682_set_bclk2_ratio(struct snd_soc_dai *dai, unsigned int ratio)
2417 struct snd_soc_component *component = dai->component;
2418 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
2420 rt5682->bclk[dai->id] = ratio;
2424 snd_soc_component_update_bits(component, RT5682_ADDA_CLK_2,
2425 RT5682_I2S2_BCLK_MS2_MASK,
2426 RT5682_I2S2_BCLK_MS2_64);
2429 snd_soc_component_update_bits(component, RT5682_ADDA_CLK_2,
2430 RT5682_I2S2_BCLK_MS2_MASK,
2431 RT5682_I2S2_BCLK_MS2_32);
2434 dev_err(dai->dev, "Invalid bclk2 ratio %d\n", ratio);
2441 static int rt5682_set_bias_level(struct snd_soc_component *component,
2442 enum snd_soc_bias_level level)
2444 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
2447 case SND_SOC_BIAS_PREPARE:
2448 regmap_update_bits(rt5682->regmap, RT5682_PWR_ANLG_1,
2449 RT5682_PWR_BG, RT5682_PWR_BG);
2450 regmap_update_bits(rt5682->regmap, RT5682_PWR_DIG_1,
2451 RT5682_DIG_GATE_CTRL | RT5682_PWR_LDO,
2452 RT5682_DIG_GATE_CTRL | RT5682_PWR_LDO);
2455 case SND_SOC_BIAS_STANDBY:
2456 regmap_update_bits(rt5682->regmap, RT5682_PWR_DIG_1,
2457 RT5682_DIG_GATE_CTRL, RT5682_DIG_GATE_CTRL);
2459 case SND_SOC_BIAS_OFF:
2460 regmap_update_bits(rt5682->regmap, RT5682_PWR_DIG_1,
2461 RT5682_DIG_GATE_CTRL | RT5682_PWR_LDO, 0);
2462 regmap_update_bits(rt5682->regmap, RT5682_PWR_ANLG_1,
2465 case SND_SOC_BIAS_ON:
2472 #ifdef CONFIG_COMMON_CLK
2473 #define CLK_PLL2_FIN 48000000
2474 #define CLK_48 48000
2475 #define CLK_44 44100
2477 static bool rt5682_clk_check(struct rt5682_priv *rt5682)
2479 if (!rt5682->master[RT5682_AIF1]) {
2480 dev_err(rt5682->component->dev, "sysclk/dai not set correctly\n");
2486 static int rt5682_wclk_prepare(struct clk_hw *hw)
2488 struct rt5682_priv *rt5682 =
2489 container_of(hw, struct rt5682_priv,
2490 dai_clks_hw[RT5682_DAI_WCLK_IDX]);
2491 struct snd_soc_component *component = rt5682->component;
2492 struct snd_soc_dapm_context *dapm =
2493 snd_soc_component_get_dapm(component);
2495 if (!rt5682_clk_check(rt5682))
2498 snd_soc_dapm_mutex_lock(dapm);
2500 snd_soc_dapm_force_enable_pin_unlocked(dapm, "MICBIAS");
2501 snd_soc_component_update_bits(component, RT5682_PWR_ANLG_1,
2502 RT5682_PWR_MB, RT5682_PWR_MB);
2503 snd_soc_dapm_force_enable_pin_unlocked(dapm, "I2S1");
2504 snd_soc_dapm_force_enable_pin_unlocked(dapm, "PLL2F");
2505 snd_soc_dapm_force_enable_pin_unlocked(dapm, "PLL2B");
2506 snd_soc_dapm_sync_unlocked(dapm);
2508 snd_soc_dapm_mutex_unlock(dapm);
2513 static void rt5682_wclk_unprepare(struct clk_hw *hw)
2515 struct rt5682_priv *rt5682 =
2516 container_of(hw, struct rt5682_priv,
2517 dai_clks_hw[RT5682_DAI_WCLK_IDX]);
2518 struct snd_soc_component *component = rt5682->component;
2519 struct snd_soc_dapm_context *dapm =
2520 snd_soc_component_get_dapm(component);
2522 if (!rt5682_clk_check(rt5682))
2525 snd_soc_dapm_mutex_lock(dapm);
2527 snd_soc_dapm_disable_pin_unlocked(dapm, "MICBIAS");
2528 if (!rt5682->jack_type)
2529 snd_soc_component_update_bits(component, RT5682_PWR_ANLG_1,
2531 snd_soc_dapm_disable_pin_unlocked(dapm, "I2S1");
2532 snd_soc_dapm_disable_pin_unlocked(dapm, "PLL2F");
2533 snd_soc_dapm_disable_pin_unlocked(dapm, "PLL2B");
2534 snd_soc_dapm_sync_unlocked(dapm);
2536 snd_soc_dapm_mutex_unlock(dapm);
2539 static unsigned long rt5682_wclk_recalc_rate(struct clk_hw *hw,
2540 unsigned long parent_rate)
2542 struct rt5682_priv *rt5682 =
2543 container_of(hw, struct rt5682_priv,
2544 dai_clks_hw[RT5682_DAI_WCLK_IDX]);
2545 struct snd_soc_component *component = rt5682->component;
2546 const char * const clk_name = __clk_get_name(hw->clk);
2548 if (!rt5682_clk_check(rt5682))
2551 * Only accept to set wclk rate to 44.1k or 48kHz.
2553 if (rt5682->lrck[RT5682_AIF1] != CLK_48 &&
2554 rt5682->lrck[RT5682_AIF1] != CLK_44) {
2555 dev_warn(component->dev, "%s: clk %s only support %d or %d Hz output\n",
2556 __func__, clk_name, CLK_44, CLK_48);
2560 return rt5682->lrck[RT5682_AIF1];
2563 static long rt5682_wclk_round_rate(struct clk_hw *hw, unsigned long rate,
2564 unsigned long *parent_rate)
2566 struct rt5682_priv *rt5682 =
2567 container_of(hw, struct rt5682_priv,
2568 dai_clks_hw[RT5682_DAI_WCLK_IDX]);
2569 struct snd_soc_component *component = rt5682->component;
2570 const char * const clk_name = __clk_get_name(hw->clk);
2572 if (!rt5682_clk_check(rt5682))
2575 * Only accept to set wclk rate to 44.1k or 48kHz.
2576 * It will force to 48kHz if not both.
2578 if (rate != CLK_48 && rate != CLK_44) {
2579 dev_warn(component->dev, "%s: clk %s only support %d or %d Hz output\n",
2580 __func__, clk_name, CLK_44, CLK_48);
2587 static int rt5682_wclk_set_rate(struct clk_hw *hw, unsigned long rate,
2588 unsigned long parent_rate)
2590 struct rt5682_priv *rt5682 =
2591 container_of(hw, struct rt5682_priv,
2592 dai_clks_hw[RT5682_DAI_WCLK_IDX]);
2593 struct snd_soc_component *component = rt5682->component;
2594 struct clk *parent_clk;
2595 const char * const clk_name = __clk_get_name(hw->clk);
2597 unsigned int clk_pll2_out;
2599 if (!rt5682_clk_check(rt5682))
2603 * Whether the wclk's parent clk (mclk) exists or not, please ensure
2604 * it is fixed or set to 48MHz before setting wclk rate. It's a
2605 * temporary limitation. Only accept 48MHz clk as the clk provider.
2607 * It will set the codec anyway by assuming mclk is 48MHz.
2609 parent_clk = clk_get_parent(hw->clk);
2611 dev_warn(component->dev,
2612 "Parent mclk of wclk not acquired in driver. Please ensure mclk was provided as %d Hz.\n",
2615 if (parent_rate != CLK_PLL2_FIN)
2616 dev_warn(component->dev, "clk %s only support %d Hz input\n",
2617 clk_name, CLK_PLL2_FIN);
2620 * To achieve the rate conversion from 48MHz to 44.1k or 48kHz,
2623 clk_pll2_out = rate * 512;
2624 rt5682_set_component_pll(component, RT5682_PLL2, RT5682_PLL2_S_MCLK,
2625 CLK_PLL2_FIN, clk_pll2_out);
2627 rt5682_set_component_sysclk(component, RT5682_SCLK_S_PLL2, 0,
2628 clk_pll2_out, SND_SOC_CLOCK_IN);
2630 rt5682->lrck[RT5682_AIF1] = rate;
2632 pre_div = rl6231_get_clk_info(rt5682->sysclk, rate);
2634 snd_soc_component_update_bits(component, RT5682_ADDA_CLK_1,
2635 RT5682_I2S_M_DIV_MASK | RT5682_I2S_CLK_SRC_MASK,
2636 pre_div << RT5682_I2S_M_DIV_SFT |
2637 (rt5682->sysclk_src) << RT5682_I2S_CLK_SRC_SFT);
2642 static unsigned long rt5682_bclk_recalc_rate(struct clk_hw *hw,
2643 unsigned long parent_rate)
2645 struct rt5682_priv *rt5682 =
2646 container_of(hw, struct rt5682_priv,
2647 dai_clks_hw[RT5682_DAI_BCLK_IDX]);
2648 struct snd_soc_component *component = rt5682->component;
2649 unsigned int bclks_per_wclk;
2651 bclks_per_wclk = snd_soc_component_read(component, RT5682_TDM_TCON_CTRL);
2653 switch (bclks_per_wclk & RT5682_TDM_BCLK_MS1_MASK) {
2654 case RT5682_TDM_BCLK_MS1_256:
2655 return parent_rate * 256;
2656 case RT5682_TDM_BCLK_MS1_128:
2657 return parent_rate * 128;
2658 case RT5682_TDM_BCLK_MS1_64:
2659 return parent_rate * 64;
2660 case RT5682_TDM_BCLK_MS1_32:
2661 return parent_rate * 32;
2667 static unsigned long rt5682_bclk_get_factor(unsigned long rate,
2668 unsigned long parent_rate)
2670 unsigned long factor;
2672 factor = rate / parent_rate;
2675 else if (factor < 128)
2677 else if (factor < 256)
2683 static long rt5682_bclk_round_rate(struct clk_hw *hw, unsigned long rate,
2684 unsigned long *parent_rate)
2686 struct rt5682_priv *rt5682 =
2687 container_of(hw, struct rt5682_priv,
2688 dai_clks_hw[RT5682_DAI_BCLK_IDX]);
2689 unsigned long factor;
2691 if (!*parent_rate || !rt5682_clk_check(rt5682))
2695 * BCLK rates are set as a multiplier of WCLK in HW.
2696 * We don't allow changing the parent WCLK. We just do
2697 * some rounding down based on the parent WCLK rate
2698 * and find the appropriate multiplier of BCLK to
2699 * get the rounded down BCLK value.
2701 factor = rt5682_bclk_get_factor(rate, *parent_rate);
2703 return *parent_rate * factor;
2706 static int rt5682_bclk_set_rate(struct clk_hw *hw, unsigned long rate,
2707 unsigned long parent_rate)
2709 struct rt5682_priv *rt5682 =
2710 container_of(hw, struct rt5682_priv,
2711 dai_clks_hw[RT5682_DAI_BCLK_IDX]);
2712 struct snd_soc_component *component = rt5682->component;
2713 struct snd_soc_dai *dai = NULL;
2714 unsigned long factor;
2716 if (!rt5682_clk_check(rt5682))
2719 factor = rt5682_bclk_get_factor(rate, parent_rate);
2721 for_each_component_dais(component, dai)
2722 if (dai->id == RT5682_AIF1)
2725 dev_err(component->dev, "dai %d not found in component\n",
2730 return rt5682_set_bclk1_ratio(dai, factor);
2733 static const struct clk_ops rt5682_dai_clk_ops[RT5682_DAI_NUM_CLKS] = {
2734 [RT5682_DAI_WCLK_IDX] = {
2735 .prepare = rt5682_wclk_prepare,
2736 .unprepare = rt5682_wclk_unprepare,
2737 .recalc_rate = rt5682_wclk_recalc_rate,
2738 .round_rate = rt5682_wclk_round_rate,
2739 .set_rate = rt5682_wclk_set_rate,
2741 [RT5682_DAI_BCLK_IDX] = {
2742 .recalc_rate = rt5682_bclk_recalc_rate,
2743 .round_rate = rt5682_bclk_round_rate,
2744 .set_rate = rt5682_bclk_set_rate,
2748 static int rt5682_register_dai_clks(struct snd_soc_component *component)
2750 struct device *dev = component->dev;
2751 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
2752 struct rt5682_platform_data *pdata = &rt5682->pdata;
2753 struct clk_init_data init;
2754 struct clk *dai_clk;
2755 struct clk_lookup *dai_clk_lookup;
2756 struct clk_hw *dai_clk_hw;
2757 const char *parent_name;
2760 for (i = 0; i < RT5682_DAI_NUM_CLKS; ++i) {
2761 dai_clk_hw = &rt5682->dai_clks_hw[i];
2764 case RT5682_DAI_WCLK_IDX:
2765 /* Make MCLK the parent of WCLK */
2767 parent_name = __clk_get_name(rt5682->mclk);
2768 init.parent_names = &parent_name;
2769 init.num_parents = 1;
2771 init.parent_names = NULL;
2772 init.num_parents = 0;
2775 case RT5682_DAI_BCLK_IDX:
2776 /* Make WCLK the parent of BCLK */
2777 parent_name = __clk_get_name(
2778 rt5682->dai_clks[RT5682_DAI_WCLK_IDX]);
2779 init.parent_names = &parent_name;
2780 init.num_parents = 1;
2783 dev_err(dev, "Invalid clock index\n");
2788 init.name = pdata->dai_clk_names[i];
2789 init.ops = &rt5682_dai_clk_ops[i];
2790 init.flags = CLK_GET_RATE_NOCACHE | CLK_SET_RATE_GATE;
2791 dai_clk_hw->init = &init;
2793 dai_clk = devm_clk_register(dev, dai_clk_hw);
2794 if (IS_ERR(dai_clk)) {
2795 dev_warn(dev, "Failed to register %s: %ld\n",
2796 init.name, PTR_ERR(dai_clk));
2797 ret = PTR_ERR(dai_clk);
2800 rt5682->dai_clks[i] = dai_clk;
2803 devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get,
2806 dai_clk_lookup = clkdev_create(dai_clk, init.name,
2807 "%s", dev_name(dev));
2808 if (!dai_clk_lookup) {
2812 rt5682->dai_clks_lookup[i] = dai_clk_lookup;
2821 if (rt5682->dai_clks_lookup[i])
2822 clkdev_drop(rt5682->dai_clks_lookup[i]);
2827 #endif /* CONFIG_COMMON_CLK */
2829 static int rt5682_probe(struct snd_soc_component *component)
2831 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
2832 struct sdw_slave *slave;
2835 #ifdef CONFIG_COMMON_CLK
2838 rt5682->component = component;
2840 if (rt5682->is_sdw) {
2841 slave = rt5682->slave;
2842 time = wait_for_completion_timeout(
2843 &slave->initialization_complete,
2844 msecs_to_jiffies(RT5682_PROBE_TIMEOUT));
2846 dev_err(&slave->dev, "Initialization not complete, timed out\n");
2850 #ifdef CONFIG_COMMON_CLK
2851 /* Check if MCLK provided */
2852 rt5682->mclk = devm_clk_get(component->dev, "mclk");
2853 if (IS_ERR(rt5682->mclk)) {
2854 if (PTR_ERR(rt5682->mclk) != -ENOENT) {
2855 ret = PTR_ERR(rt5682->mclk);
2858 rt5682->mclk = NULL;
2861 /* Register CCF DAI clock control */
2862 ret = rt5682_register_dai_clks(component);
2866 /* Initial setup for CCF */
2867 rt5682->lrck[RT5682_AIF1] = CLK_48;
2874 static void rt5682_remove(struct snd_soc_component *component)
2876 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
2878 #ifdef CONFIG_COMMON_CLK
2881 for (i = RT5682_DAI_NUM_CLKS - 1; i >= 0; --i) {
2882 if (rt5682->dai_clks_lookup[i])
2883 clkdev_drop(rt5682->dai_clks_lookup[i]);
2887 rt5682_reset(rt5682);
2891 static int rt5682_suspend(struct snd_soc_component *component)
2893 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
2895 regcache_cache_only(rt5682->regmap, true);
2896 regcache_mark_dirty(rt5682->regmap);
2900 static int rt5682_resume(struct snd_soc_component *component)
2902 struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
2904 regcache_cache_only(rt5682->regmap, false);
2905 regcache_sync(rt5682->regmap);
2907 mod_delayed_work(system_power_efficient_wq,
2908 &rt5682->jack_detect_work, msecs_to_jiffies(250));
2913 #define rt5682_suspend NULL
2914 #define rt5682_resume NULL
2917 const struct snd_soc_dai_ops rt5682_aif1_dai_ops = {
2918 .hw_params = rt5682_hw_params,
2919 .set_fmt = rt5682_set_dai_fmt,
2920 .set_tdm_slot = rt5682_set_tdm_slot,
2921 .set_bclk_ratio = rt5682_set_bclk1_ratio,
2923 EXPORT_SYMBOL_GPL(rt5682_aif1_dai_ops);
2925 const struct snd_soc_dai_ops rt5682_aif2_dai_ops = {
2926 .hw_params = rt5682_hw_params,
2927 .set_fmt = rt5682_set_dai_fmt,
2928 .set_bclk_ratio = rt5682_set_bclk2_ratio,
2930 EXPORT_SYMBOL_GPL(rt5682_aif2_dai_ops);
2932 const struct snd_soc_component_driver rt5682_soc_component_dev = {
2933 .probe = rt5682_probe,
2934 .remove = rt5682_remove,
2935 .suspend = rt5682_suspend,
2936 .resume = rt5682_resume,
2937 .set_bias_level = rt5682_set_bias_level,
2938 .controls = rt5682_snd_controls,
2939 .num_controls = ARRAY_SIZE(rt5682_snd_controls),
2940 .dapm_widgets = rt5682_dapm_widgets,
2941 .num_dapm_widgets = ARRAY_SIZE(rt5682_dapm_widgets),
2942 .dapm_routes = rt5682_dapm_routes,
2943 .num_dapm_routes = ARRAY_SIZE(rt5682_dapm_routes),
2944 .set_sysclk = rt5682_set_component_sysclk,
2945 .set_pll = rt5682_set_component_pll,
2946 .set_jack = rt5682_set_jack_detect,
2947 .use_pmdown_time = 1,
2949 .non_legacy_dai_naming = 1,
2951 EXPORT_SYMBOL_GPL(rt5682_soc_component_dev);
2953 int rt5682_parse_dt(struct rt5682_priv *rt5682, struct device *dev)
2956 device_property_read_u32(dev, "realtek,dmic1-data-pin",
2957 &rt5682->pdata.dmic1_data_pin);
2958 device_property_read_u32(dev, "realtek,dmic1-clk-pin",
2959 &rt5682->pdata.dmic1_clk_pin);
2960 device_property_read_u32(dev, "realtek,jd-src",
2961 &rt5682->pdata.jd_src);
2962 device_property_read_u32(dev, "realtek,btndet-delay",
2963 &rt5682->pdata.btndet_delay);
2964 device_property_read_u32(dev, "realtek,dmic-clk-rate-hz",
2965 &rt5682->pdata.dmic_clk_rate);
2966 device_property_read_u32(dev, "realtek,dmic-delay-ms",
2967 &rt5682->pdata.dmic_delay);
2969 rt5682->pdata.ldo1_en = of_get_named_gpio(dev->of_node,
2970 "realtek,ldo1-en-gpios", 0);
2972 if (device_property_read_string_array(dev, "clock-output-names",
2973 rt5682->pdata.dai_clk_names,
2974 RT5682_DAI_NUM_CLKS) < 0)
2975 dev_warn(dev, "Using default DAI clk names: %s, %s\n",
2976 rt5682->pdata.dai_clk_names[RT5682_DAI_WCLK_IDX],
2977 rt5682->pdata.dai_clk_names[RT5682_DAI_BCLK_IDX]);
2981 EXPORT_SYMBOL_GPL(rt5682_parse_dt);
2983 void rt5682_calibrate(struct rt5682_priv *rt5682)
2987 mutex_lock(&rt5682->calibrate_mutex);
2989 rt5682_reset(rt5682);
2990 regmap_write(rt5682->regmap, RT5682_I2C_CTRL, 0x000f);
2991 regmap_write(rt5682->regmap, RT5682_PWR_ANLG_1, 0xa2af);
2992 usleep_range(15000, 20000);
2993 regmap_write(rt5682->regmap, RT5682_PWR_ANLG_1, 0xf2af);
2994 regmap_write(rt5682->regmap, RT5682_MICBIAS_2, 0x0300);
2995 regmap_write(rt5682->regmap, RT5682_GLB_CLK, 0x8000);
2996 regmap_write(rt5682->regmap, RT5682_PWR_DIG_1, 0x0100);
2997 regmap_write(rt5682->regmap, RT5682_HP_IMP_SENS_CTRL_19, 0x3800);
2998 regmap_write(rt5682->regmap, RT5682_CHOP_DAC, 0x3000);
2999 regmap_write(rt5682->regmap, RT5682_CALIB_ADC_CTRL, 0x7005);
3000 regmap_write(rt5682->regmap, RT5682_STO1_ADC_MIXER, 0x686c);
3001 regmap_write(rt5682->regmap, RT5682_CAL_REC, 0x0d0d);
3002 regmap_write(rt5682->regmap, RT5682_HP_CALIB_CTRL_2, 0x0321);
3003 regmap_write(rt5682->regmap, RT5682_HP_LOGIC_CTRL_2, 0x0004);
3004 regmap_write(rt5682->regmap, RT5682_HP_CALIB_CTRL_1, 0x7c00);
3005 regmap_write(rt5682->regmap, RT5682_HP_CALIB_CTRL_3, 0x06a1);
3006 regmap_write(rt5682->regmap, RT5682_A_DAC1_MUX, 0x0311);
3007 regmap_write(rt5682->regmap, RT5682_HP_CALIB_CTRL_1, 0x7c00);
3009 regmap_write(rt5682->regmap, RT5682_HP_CALIB_CTRL_1, 0xfc00);
3011 for (count = 0; count < 60; count++) {
3012 regmap_read(rt5682->regmap, RT5682_HP_CALIB_STA_1, &value);
3013 if (!(value & 0x8000))
3016 usleep_range(10000, 10005);
3020 dev_err(rt5682->component->dev, "HP Calibration Failure\n");
3022 /* restore settings */
3023 regmap_write(rt5682->regmap, RT5682_PWR_ANLG_1, 0x02af);
3024 regmap_write(rt5682->regmap, RT5682_MICBIAS_2, 0x0080);
3025 regmap_write(rt5682->regmap, RT5682_GLB_CLK, 0x0000);
3026 regmap_write(rt5682->regmap, RT5682_PWR_DIG_1, 0x0000);
3027 regmap_write(rt5682->regmap, RT5682_CHOP_DAC, 0x2000);
3028 regmap_write(rt5682->regmap, RT5682_CALIB_ADC_CTRL, 0x2005);
3029 regmap_write(rt5682->regmap, RT5682_STO1_ADC_MIXER, 0xc0c4);
3031 mutex_unlock(&rt5682->calibrate_mutex);
3033 EXPORT_SYMBOL_GPL(rt5682_calibrate);
3035 MODULE_DESCRIPTION("ASoC RT5682 driver");
3036 MODULE_AUTHOR("Bard Liao <bardliao@realtek.com>");
3037 MODULE_LICENSE("GPL v2");