1 // SPDX-License-Identifier: GPL-2.0-only
3 * rt5668.c -- RT5668B 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/i2c.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/regulator/consumer.h>
21 #include <linux/mutex.h>
22 #include <sound/core.h>
23 #include <sound/pcm.h>
24 #include <sound/pcm_params.h>
25 #include <sound/jack.h>
26 #include <sound/soc.h>
27 #include <sound/soc-dapm.h>
28 #include <sound/initval.h>
29 #include <sound/tlv.h>
30 #include <sound/rt5668.h>
35 #define RT5668_NUM_SUPPLIES 3
37 static const char *rt5668_supply_names
[RT5668_NUM_SUPPLIES
] = {
44 struct snd_soc_component
*component
;
45 struct rt5668_platform_data pdata
;
46 struct regmap
*regmap
;
47 struct snd_soc_jack
*hs_jack
;
48 struct regulator_bulk_data supplies
[RT5668_NUM_SUPPLIES
];
49 struct delayed_work jack_detect_work
;
50 struct delayed_work jd_check_work
;
51 struct mutex calibrate_mutex
;
55 int lrck
[RT5668_AIFS
];
56 int bclk
[RT5668_AIFS
];
57 int master
[RT5668_AIFS
];
66 static const struct reg_default rt5668_reg
[] = {
388 static bool rt5668_volatile_register(struct device
*dev
, unsigned int reg
)
392 case RT5668_CBJ_CTRL_2
:
393 case RT5668_INT_ST_1
:
394 case RT5668_4BTN_IL_CMD_1
:
395 case RT5668_AJD1_CTRL
:
396 case RT5668_HP_CALIB_CTRL_1
:
397 case RT5668_DEVICE_ID
:
398 case RT5668_I2C_MODE
:
399 case RT5668_HP_CALIB_CTRL_10
:
400 case RT5668_EFUSE_CTRL_2
:
401 case RT5668_JD_TOP_VC_VTRL
:
402 case RT5668_HP_IMP_SENS_CTRL_19
:
403 case RT5668_IL_CMD_1
:
404 case RT5668_SAR_IL_CMD_2
:
405 case RT5668_SAR_IL_CMD_4
:
406 case RT5668_SAR_IL_CMD_10
:
407 case RT5668_SAR_IL_CMD_11
:
408 case RT5668_EFUSE_CTRL_6
...RT5668_EFUSE_CTRL_11
:
409 case RT5668_HP_CALIB_STA_1
...RT5668_HP_CALIB_STA_11
:
416 static bool rt5668_readable_register(struct device
*dev
, unsigned int reg
)
420 case RT5668_VERSION_ID
:
421 case RT5668_VENDOR_ID
:
422 case RT5668_DEVICE_ID
:
423 case RT5668_HP_CTRL_1
:
424 case RT5668_HP_CTRL_2
:
425 case RT5668_HPL_GAIN
:
426 case RT5668_HPR_GAIN
:
427 case RT5668_I2C_CTRL
:
428 case RT5668_CBJ_BST_CTRL
:
429 case RT5668_CBJ_CTRL_1
:
430 case RT5668_CBJ_CTRL_2
:
431 case RT5668_CBJ_CTRL_3
:
432 case RT5668_CBJ_CTRL_4
:
433 case RT5668_CBJ_CTRL_5
:
434 case RT5668_CBJ_CTRL_6
:
435 case RT5668_CBJ_CTRL_7
:
436 case RT5668_DAC1_DIG_VOL
:
437 case RT5668_STO1_ADC_DIG_VOL
:
438 case RT5668_STO1_ADC_BOOST
:
439 case RT5668_HP_IMP_GAIN_1
:
440 case RT5668_HP_IMP_GAIN_2
:
441 case RT5668_SIDETONE_CTRL
:
442 case RT5668_STO1_ADC_MIXER
:
443 case RT5668_AD_DA_MIXER
:
444 case RT5668_STO1_DAC_MIXER
:
445 case RT5668_A_DAC1_MUX
:
446 case RT5668_DIG_INF2_DATA
:
447 case RT5668_REC_MIXER
:
449 case RT5668_ALC_BACK_GAIN
:
450 case RT5668_PWR_DIG_1
:
451 case RT5668_PWR_DIG_2
:
452 case RT5668_PWR_ANLG_1
:
453 case RT5668_PWR_ANLG_2
:
454 case RT5668_PWR_ANLG_3
:
455 case RT5668_PWR_MIXER
:
458 case RT5668_RESET_LPF_CTRL
:
459 case RT5668_RESET_HPF_CTRL
:
460 case RT5668_DMIC_CTRL_1
:
461 case RT5668_I2S1_SDP
:
462 case RT5668_I2S2_SDP
:
463 case RT5668_ADDA_CLK_1
:
464 case RT5668_ADDA_CLK_2
:
465 case RT5668_I2S1_F_DIV_CTRL_1
:
466 case RT5668_I2S1_F_DIV_CTRL_2
:
467 case RT5668_TDM_CTRL
:
468 case RT5668_TDM_ADDA_CTRL_1
:
469 case RT5668_TDM_ADDA_CTRL_2
:
470 case RT5668_DATA_SEL_CTRL_1
:
471 case RT5668_TDM_TCON_CTRL
:
473 case RT5668_PLL_CTRL_1
:
474 case RT5668_PLL_CTRL_2
:
475 case RT5668_PLL_TRACK_1
:
476 case RT5668_PLL_TRACK_2
:
477 case RT5668_PLL_TRACK_3
:
478 case RT5668_PLL_TRACK_4
:
479 case RT5668_PLL_TRACK_5
:
480 case RT5668_PLL_TRACK_6
:
481 case RT5668_PLL_TRACK_11
:
482 case RT5668_SDW_REF_CLK
:
485 case RT5668_HP_CHARGE_PUMP_1
:
486 case RT5668_HP_CHARGE_PUMP_2
:
487 case RT5668_MICBIAS_1
:
488 case RT5668_MICBIAS_2
:
489 case RT5668_PLL_TRACK_12
:
490 case RT5668_PLL_TRACK_14
:
491 case RT5668_PLL2_CTRL_1
:
492 case RT5668_PLL2_CTRL_2
:
493 case RT5668_PLL2_CTRL_3
:
494 case RT5668_PLL2_CTRL_4
:
495 case RT5668_RC_CLK_CTRL
:
496 case RT5668_I2S_M_CLK_CTRL_1
:
497 case RT5668_I2S2_F_DIV_CTRL_1
:
498 case RT5668_I2S2_F_DIV_CTRL_2
:
499 case RT5668_EQ_CTRL_1
:
500 case RT5668_EQ_CTRL_2
:
501 case RT5668_IRQ_CTRL_1
:
502 case RT5668_IRQ_CTRL_2
:
503 case RT5668_IRQ_CTRL_3
:
504 case RT5668_IRQ_CTRL_4
:
505 case RT5668_INT_ST_1
:
506 case RT5668_GPIO_CTRL_1
:
507 case RT5668_GPIO_CTRL_2
:
508 case RT5668_GPIO_CTRL_3
:
509 case RT5668_HP_AMP_DET_CTRL_1
:
510 case RT5668_HP_AMP_DET_CTRL_2
:
511 case RT5668_MID_HP_AMP_DET
:
512 case RT5668_LOW_HP_AMP_DET
:
513 case RT5668_DELAY_BUF_CTRL
:
514 case RT5668_SV_ZCD_1
:
515 case RT5668_SV_ZCD_2
:
516 case RT5668_IL_CMD_1
:
517 case RT5668_IL_CMD_2
:
518 case RT5668_IL_CMD_3
:
519 case RT5668_IL_CMD_4
:
520 case RT5668_IL_CMD_5
:
521 case RT5668_IL_CMD_6
:
522 case RT5668_4BTN_IL_CMD_1
:
523 case RT5668_4BTN_IL_CMD_2
:
524 case RT5668_4BTN_IL_CMD_3
:
525 case RT5668_4BTN_IL_CMD_4
:
526 case RT5668_4BTN_IL_CMD_5
:
527 case RT5668_4BTN_IL_CMD_6
:
528 case RT5668_4BTN_IL_CMD_7
:
529 case RT5668_ADC_STO1_HP_CTRL_1
:
530 case RT5668_ADC_STO1_HP_CTRL_2
:
531 case RT5668_AJD1_CTRL
:
534 case RT5668_JD_CTRL_1
:
538 case RT5668_DAC_ADC_DIG_VOL1
:
539 case RT5668_BIAS_CUR_CTRL_2
:
540 case RT5668_BIAS_CUR_CTRL_3
:
541 case RT5668_BIAS_CUR_CTRL_4
:
542 case RT5668_BIAS_CUR_CTRL_5
:
543 case RT5668_BIAS_CUR_CTRL_6
:
544 case RT5668_BIAS_CUR_CTRL_7
:
545 case RT5668_BIAS_CUR_CTRL_8
:
546 case RT5668_BIAS_CUR_CTRL_9
:
547 case RT5668_BIAS_CUR_CTRL_10
:
548 case RT5668_VREF_REC_OP_FB_CAP_CTRL
:
549 case RT5668_CHARGE_PUMP_1
:
550 case RT5668_DIG_IN_CTRL_1
:
551 case RT5668_PAD_DRIVING_CTRL
:
552 case RT5668_SOFT_RAMP_DEPOP
:
553 case RT5668_CHOP_DAC
:
554 case RT5668_CHOP_ADC
:
555 case RT5668_CALIB_ADC_CTRL
:
556 case RT5668_VOL_TEST
:
557 case RT5668_SPKVDD_DET_STA
:
558 case RT5668_TEST_MODE_CTRL_1
:
559 case RT5668_TEST_MODE_CTRL_2
:
560 case RT5668_TEST_MODE_CTRL_3
:
561 case RT5668_TEST_MODE_CTRL_4
:
562 case RT5668_TEST_MODE_CTRL_5
:
563 case RT5668_PLL1_INTERNAL
:
564 case RT5668_PLL2_INTERNAL
:
565 case RT5668_STO_NG2_CTRL_1
:
566 case RT5668_STO_NG2_CTRL_2
:
567 case RT5668_STO_NG2_CTRL_3
:
568 case RT5668_STO_NG2_CTRL_4
:
569 case RT5668_STO_NG2_CTRL_5
:
570 case RT5668_STO_NG2_CTRL_6
:
571 case RT5668_STO_NG2_CTRL_7
:
572 case RT5668_STO_NG2_CTRL_8
:
573 case RT5668_STO_NG2_CTRL_9
:
574 case RT5668_STO_NG2_CTRL_10
:
575 case RT5668_STO1_DAC_SIL_DET
:
576 case RT5668_SIL_PSV_CTRL1
:
577 case RT5668_SIL_PSV_CTRL2
:
578 case RT5668_SIL_PSV_CTRL3
:
579 case RT5668_SIL_PSV_CTRL4
:
580 case RT5668_SIL_PSV_CTRL5
:
581 case RT5668_HP_IMP_SENS_CTRL_01
:
582 case RT5668_HP_IMP_SENS_CTRL_02
:
583 case RT5668_HP_IMP_SENS_CTRL_03
:
584 case RT5668_HP_IMP_SENS_CTRL_04
:
585 case RT5668_HP_IMP_SENS_CTRL_05
:
586 case RT5668_HP_IMP_SENS_CTRL_06
:
587 case RT5668_HP_IMP_SENS_CTRL_07
:
588 case RT5668_HP_IMP_SENS_CTRL_08
:
589 case RT5668_HP_IMP_SENS_CTRL_09
:
590 case RT5668_HP_IMP_SENS_CTRL_10
:
591 case RT5668_HP_IMP_SENS_CTRL_11
:
592 case RT5668_HP_IMP_SENS_CTRL_12
:
593 case RT5668_HP_IMP_SENS_CTRL_13
:
594 case RT5668_HP_IMP_SENS_CTRL_14
:
595 case RT5668_HP_IMP_SENS_CTRL_15
:
596 case RT5668_HP_IMP_SENS_CTRL_16
:
597 case RT5668_HP_IMP_SENS_CTRL_17
:
598 case RT5668_HP_IMP_SENS_CTRL_18
:
599 case RT5668_HP_IMP_SENS_CTRL_19
:
600 case RT5668_HP_IMP_SENS_CTRL_20
:
601 case RT5668_HP_IMP_SENS_CTRL_21
:
602 case RT5668_HP_IMP_SENS_CTRL_22
:
603 case RT5668_HP_IMP_SENS_CTRL_23
:
604 case RT5668_HP_IMP_SENS_CTRL_24
:
605 case RT5668_HP_IMP_SENS_CTRL_25
:
606 case RT5668_HP_IMP_SENS_CTRL_26
:
607 case RT5668_HP_IMP_SENS_CTRL_27
:
608 case RT5668_HP_IMP_SENS_CTRL_28
:
609 case RT5668_HP_IMP_SENS_CTRL_29
:
610 case RT5668_HP_IMP_SENS_CTRL_30
:
611 case RT5668_HP_IMP_SENS_CTRL_31
:
612 case RT5668_HP_IMP_SENS_CTRL_32
:
613 case RT5668_HP_IMP_SENS_CTRL_33
:
614 case RT5668_HP_IMP_SENS_CTRL_34
:
615 case RT5668_HP_IMP_SENS_CTRL_35
:
616 case RT5668_HP_IMP_SENS_CTRL_36
:
617 case RT5668_HP_IMP_SENS_CTRL_37
:
618 case RT5668_HP_IMP_SENS_CTRL_38
:
619 case RT5668_HP_IMP_SENS_CTRL_39
:
620 case RT5668_HP_IMP_SENS_CTRL_40
:
621 case RT5668_HP_IMP_SENS_CTRL_41
:
622 case RT5668_HP_IMP_SENS_CTRL_42
:
623 case RT5668_HP_IMP_SENS_CTRL_43
:
624 case RT5668_HP_LOGIC_CTRL_1
:
625 case RT5668_HP_LOGIC_CTRL_2
:
626 case RT5668_HP_LOGIC_CTRL_3
:
627 case RT5668_HP_CALIB_CTRL_1
:
628 case RT5668_HP_CALIB_CTRL_2
:
629 case RT5668_HP_CALIB_CTRL_3
:
630 case RT5668_HP_CALIB_CTRL_4
:
631 case RT5668_HP_CALIB_CTRL_5
:
632 case RT5668_HP_CALIB_CTRL_6
:
633 case RT5668_HP_CALIB_CTRL_7
:
634 case RT5668_HP_CALIB_CTRL_9
:
635 case RT5668_HP_CALIB_CTRL_10
:
636 case RT5668_HP_CALIB_CTRL_11
:
637 case RT5668_HP_CALIB_STA_1
:
638 case RT5668_HP_CALIB_STA_2
:
639 case RT5668_HP_CALIB_STA_3
:
640 case RT5668_HP_CALIB_STA_4
:
641 case RT5668_HP_CALIB_STA_5
:
642 case RT5668_HP_CALIB_STA_6
:
643 case RT5668_HP_CALIB_STA_7
:
644 case RT5668_HP_CALIB_STA_8
:
645 case RT5668_HP_CALIB_STA_9
:
646 case RT5668_HP_CALIB_STA_10
:
647 case RT5668_HP_CALIB_STA_11
:
648 case RT5668_SAR_IL_CMD_1
:
649 case RT5668_SAR_IL_CMD_2
:
650 case RT5668_SAR_IL_CMD_3
:
651 case RT5668_SAR_IL_CMD_4
:
652 case RT5668_SAR_IL_CMD_5
:
653 case RT5668_SAR_IL_CMD_6
:
654 case RT5668_SAR_IL_CMD_7
:
655 case RT5668_SAR_IL_CMD_8
:
656 case RT5668_SAR_IL_CMD_9
:
657 case RT5668_SAR_IL_CMD_10
:
658 case RT5668_SAR_IL_CMD_11
:
659 case RT5668_SAR_IL_CMD_12
:
660 case RT5668_SAR_IL_CMD_13
:
661 case RT5668_EFUSE_CTRL_1
:
662 case RT5668_EFUSE_CTRL_2
:
663 case RT5668_EFUSE_CTRL_3
:
664 case RT5668_EFUSE_CTRL_4
:
665 case RT5668_EFUSE_CTRL_5
:
666 case RT5668_EFUSE_CTRL_6
:
667 case RT5668_EFUSE_CTRL_7
:
668 case RT5668_EFUSE_CTRL_8
:
669 case RT5668_EFUSE_CTRL_9
:
670 case RT5668_EFUSE_CTRL_10
:
671 case RT5668_EFUSE_CTRL_11
:
672 case RT5668_JD_TOP_VC_VTRL
:
673 case RT5668_DRC1_CTRL_0
:
674 case RT5668_DRC1_CTRL_1
:
675 case RT5668_DRC1_CTRL_2
:
676 case RT5668_DRC1_CTRL_3
:
677 case RT5668_DRC1_CTRL_4
:
678 case RT5668_DRC1_CTRL_5
:
679 case RT5668_DRC1_CTRL_6
:
680 case RT5668_DRC1_HARD_LMT_CTRL_1
:
681 case RT5668_DRC1_HARD_LMT_CTRL_2
:
682 case RT5668_DRC1_PRIV_1
:
683 case RT5668_DRC1_PRIV_2
:
684 case RT5668_DRC1_PRIV_3
:
685 case RT5668_DRC1_PRIV_4
:
686 case RT5668_DRC1_PRIV_5
:
687 case RT5668_DRC1_PRIV_6
:
688 case RT5668_DRC1_PRIV_7
:
689 case RT5668_DRC1_PRIV_8
:
690 case RT5668_EQ_AUTO_RCV_CTRL1
:
691 case RT5668_EQ_AUTO_RCV_CTRL2
:
692 case RT5668_EQ_AUTO_RCV_CTRL3
:
693 case RT5668_EQ_AUTO_RCV_CTRL4
:
694 case RT5668_EQ_AUTO_RCV_CTRL5
:
695 case RT5668_EQ_AUTO_RCV_CTRL6
:
696 case RT5668_EQ_AUTO_RCV_CTRL7
:
697 case RT5668_EQ_AUTO_RCV_CTRL8
:
698 case RT5668_EQ_AUTO_RCV_CTRL9
:
699 case RT5668_EQ_AUTO_RCV_CTRL10
:
700 case RT5668_EQ_AUTO_RCV_CTRL11
:
701 case RT5668_EQ_AUTO_RCV_CTRL12
:
702 case RT5668_EQ_AUTO_RCV_CTRL13
:
703 case RT5668_ADC_L_EQ_LPF1_A1
:
704 case RT5668_R_EQ_LPF1_A1
:
705 case RT5668_L_EQ_LPF1_H0
:
706 case RT5668_R_EQ_LPF1_H0
:
707 case RT5668_L_EQ_BPF1_A1
:
708 case RT5668_R_EQ_BPF1_A1
:
709 case RT5668_L_EQ_BPF1_A2
:
710 case RT5668_R_EQ_BPF1_A2
:
711 case RT5668_L_EQ_BPF1_H0
:
712 case RT5668_R_EQ_BPF1_H0
:
713 case RT5668_L_EQ_BPF2_A1
:
714 case RT5668_R_EQ_BPF2_A1
:
715 case RT5668_L_EQ_BPF2_A2
:
716 case RT5668_R_EQ_BPF2_A2
:
717 case RT5668_L_EQ_BPF2_H0
:
718 case RT5668_R_EQ_BPF2_H0
:
719 case RT5668_L_EQ_BPF3_A1
:
720 case RT5668_R_EQ_BPF3_A1
:
721 case RT5668_L_EQ_BPF3_A2
:
722 case RT5668_R_EQ_BPF3_A2
:
723 case RT5668_L_EQ_BPF3_H0
:
724 case RT5668_R_EQ_BPF3_H0
:
725 case RT5668_L_EQ_BPF4_A1
:
726 case RT5668_R_EQ_BPF4_A1
:
727 case RT5668_L_EQ_BPF4_A2
:
728 case RT5668_R_EQ_BPF4_A2
:
729 case RT5668_L_EQ_BPF4_H0
:
730 case RT5668_R_EQ_BPF4_H0
:
731 case RT5668_L_EQ_HPF1_A1
:
732 case RT5668_R_EQ_HPF1_A1
:
733 case RT5668_L_EQ_HPF1_H0
:
734 case RT5668_R_EQ_HPF1_H0
:
735 case RT5668_L_EQ_PRE_VOL
:
736 case RT5668_R_EQ_PRE_VOL
:
737 case RT5668_L_EQ_POST_VOL
:
738 case RT5668_R_EQ_POST_VOL
:
739 case RT5668_I2C_MODE
:
746 static const DECLARE_TLV_DB_SCALE(hp_vol_tlv
, -2250, 150, 0);
747 static const DECLARE_TLV_DB_SCALE(dac_vol_tlv
, -65625, 375, 0);
748 static const DECLARE_TLV_DB_SCALE(adc_vol_tlv
, -17625, 375, 0);
749 static const DECLARE_TLV_DB_SCALE(adc_bst_tlv
, 0, 1200, 0);
751 /* {0, +20, +24, +30, +35, +40, +44, +50, +52} dB */
752 static const DECLARE_TLV_DB_RANGE(bst_tlv
,
753 0, 0, TLV_DB_SCALE_ITEM(0, 0, 0),
754 1, 1, TLV_DB_SCALE_ITEM(2000, 0, 0),
755 2, 2, TLV_DB_SCALE_ITEM(2400, 0, 0),
756 3, 5, TLV_DB_SCALE_ITEM(3000, 500, 0),
757 6, 6, TLV_DB_SCALE_ITEM(4400, 0, 0),
758 7, 7, TLV_DB_SCALE_ITEM(5000, 0, 0),
759 8, 8, TLV_DB_SCALE_ITEM(5200, 0, 0)
762 /* Interface data select */
763 static const char * const rt5668_data_select
[] = {
764 "L/R", "R/L", "L/L", "R/R"
767 static SOC_ENUM_SINGLE_DECL(rt5668_if2_adc_enum
,
768 RT5668_DIG_INF2_DATA
, RT5668_IF2_ADC_SEL_SFT
, rt5668_data_select
);
770 static SOC_ENUM_SINGLE_DECL(rt5668_if1_01_adc_enum
,
771 RT5668_TDM_ADDA_CTRL_1
, RT5668_IF1_ADC1_SEL_SFT
, rt5668_data_select
);
773 static SOC_ENUM_SINGLE_DECL(rt5668_if1_23_adc_enum
,
774 RT5668_TDM_ADDA_CTRL_1
, RT5668_IF1_ADC2_SEL_SFT
, rt5668_data_select
);
776 static SOC_ENUM_SINGLE_DECL(rt5668_if1_45_adc_enum
,
777 RT5668_TDM_ADDA_CTRL_1
, RT5668_IF1_ADC3_SEL_SFT
, rt5668_data_select
);
779 static SOC_ENUM_SINGLE_DECL(rt5668_if1_67_adc_enum
,
780 RT5668_TDM_ADDA_CTRL_1
, RT5668_IF1_ADC4_SEL_SFT
, rt5668_data_select
);
782 static const struct snd_kcontrol_new rt5668_if2_adc_swap_mux
=
783 SOC_DAPM_ENUM("IF2 ADC Swap Mux", rt5668_if2_adc_enum
);
785 static const struct snd_kcontrol_new rt5668_if1_01_adc_swap_mux
=
786 SOC_DAPM_ENUM("IF1 01 ADC Swap Mux", rt5668_if1_01_adc_enum
);
788 static const struct snd_kcontrol_new rt5668_if1_23_adc_swap_mux
=
789 SOC_DAPM_ENUM("IF1 23 ADC Swap Mux", rt5668_if1_23_adc_enum
);
791 static const struct snd_kcontrol_new rt5668_if1_45_adc_swap_mux
=
792 SOC_DAPM_ENUM("IF1 45 ADC Swap Mux", rt5668_if1_45_adc_enum
);
794 static const struct snd_kcontrol_new rt5668_if1_67_adc_swap_mux
=
795 SOC_DAPM_ENUM("IF1 67 ADC Swap Mux", rt5668_if1_67_adc_enum
);
797 static void rt5668_reset(struct regmap
*regmap
)
799 regmap_write(regmap
, RT5668_RESET
, 0);
800 regmap_write(regmap
, RT5668_I2C_MODE
, 1);
803 * rt5668_sel_asrc_clk_src - select ASRC clock source for a set of filters
804 * @component: SoC audio component device.
805 * @filter_mask: mask of filters.
806 * @clk_src: clock source
808 * The ASRC function is for asynchronous MCLK and LRCK. Also, since RT5668 can
809 * only support standard 32fs or 64fs i2s format, ASRC should be enabled to
810 * support special i2s clock format such as Intel's 100fs(100 * sampling rate).
811 * ASRC function will track i2s clock and generate a corresponding system clock
812 * for codec. This function provides an API to select the clock source for a
813 * set of filters specified by the mask. And the component driver will turn on
814 * ASRC for these filters if ASRC is selected as their clock source.
816 int rt5668_sel_asrc_clk_src(struct snd_soc_component
*component
,
817 unsigned int filter_mask
, unsigned int clk_src
)
821 case RT5668_CLK_SEL_SYS
:
822 case RT5668_CLK_SEL_I2S1_ASRC
:
823 case RT5668_CLK_SEL_I2S2_ASRC
:
830 if (filter_mask
& RT5668_DA_STEREO1_FILTER
) {
831 snd_soc_component_update_bits(component
, RT5668_PLL_TRACK_2
,
832 RT5668_FILTER_CLK_SEL_MASK
,
833 clk_src
<< RT5668_FILTER_CLK_SEL_SFT
);
836 if (filter_mask
& RT5668_AD_STEREO1_FILTER
) {
837 snd_soc_component_update_bits(component
, RT5668_PLL_TRACK_3
,
838 RT5668_FILTER_CLK_SEL_MASK
,
839 clk_src
<< RT5668_FILTER_CLK_SEL_SFT
);
844 EXPORT_SYMBOL_GPL(rt5668_sel_asrc_clk_src
);
846 static int rt5668_button_detect(struct snd_soc_component
*component
)
850 val
= snd_soc_component_read32(component
, RT5668_4BTN_IL_CMD_1
);
851 btn_type
= val
& 0xfff0;
852 snd_soc_component_write(component
, RT5668_4BTN_IL_CMD_1
, val
);
853 pr_debug("%s btn_type=%x\n", __func__
, btn_type
);
858 static void rt5668_enable_push_button_irq(struct snd_soc_component
*component
,
862 snd_soc_component_update_bits(component
, RT5668_SAR_IL_CMD_1
,
863 RT5668_SAR_BUTT_DET_MASK
, RT5668_SAR_BUTT_DET_EN
);
864 snd_soc_component_update_bits(component
, RT5668_SAR_IL_CMD_13
,
865 RT5668_SAR_SOUR_MASK
, RT5668_SAR_SOUR_BTN
);
866 snd_soc_component_write(component
, RT5668_IL_CMD_1
, 0x0040);
867 snd_soc_component_update_bits(component
, RT5668_4BTN_IL_CMD_2
,
868 RT5668_4BTN_IL_MASK
| RT5668_4BTN_IL_RST_MASK
,
869 RT5668_4BTN_IL_EN
| RT5668_4BTN_IL_NOR
);
870 snd_soc_component_update_bits(component
, RT5668_IRQ_CTRL_3
,
871 RT5668_IL_IRQ_MASK
, RT5668_IL_IRQ_EN
);
873 snd_soc_component_update_bits(component
, RT5668_IRQ_CTRL_3
,
874 RT5668_IL_IRQ_MASK
, RT5668_IL_IRQ_DIS
);
875 snd_soc_component_update_bits(component
, RT5668_SAR_IL_CMD_1
,
876 RT5668_SAR_BUTT_DET_MASK
, RT5668_SAR_BUTT_DET_DIS
);
877 snd_soc_component_update_bits(component
, RT5668_4BTN_IL_CMD_2
,
878 RT5668_4BTN_IL_MASK
, RT5668_4BTN_IL_DIS
);
879 snd_soc_component_update_bits(component
, RT5668_4BTN_IL_CMD_2
,
880 RT5668_4BTN_IL_RST_MASK
, RT5668_4BTN_IL_RST
);
881 snd_soc_component_update_bits(component
, RT5668_SAR_IL_CMD_13
,
882 RT5668_SAR_SOUR_MASK
, RT5668_SAR_SOUR_TYPE
);
887 * rt5668_headset_detect - Detect headset.
888 * @component: SoC audio component device.
889 * @jack_insert: Jack insert or not.
891 * Detect whether is headset or not when jack inserted.
893 * Returns detect status.
895 static int rt5668_headset_detect(struct snd_soc_component
*component
,
898 struct rt5668_priv
*rt5668
= snd_soc_component_get_drvdata(component
);
899 struct snd_soc_dapm_context
*dapm
=
900 snd_soc_component_get_dapm(component
);
901 unsigned int val
, count
;
904 snd_soc_dapm_force_enable_pin(dapm
, "CBJ Power");
905 snd_soc_dapm_sync(dapm
);
906 snd_soc_component_update_bits(component
, RT5668_CBJ_CTRL_1
,
907 RT5668_TRIG_JD_MASK
, RT5668_TRIG_JD_HIGH
);
910 val
= snd_soc_component_read32(component
, RT5668_CBJ_CTRL_2
)
911 & RT5668_JACK_TYPE_MASK
;
912 while (val
== 0 && count
< 50) {
913 usleep_range(10000, 15000);
914 val
= snd_soc_component_read32(component
,
915 RT5668_CBJ_CTRL_2
) & RT5668_JACK_TYPE_MASK
;
922 rt5668
->jack_type
= SND_JACK_HEADSET
;
923 rt5668_enable_push_button_irq(component
, true);
926 rt5668
->jack_type
= SND_JACK_HEADPHONE
;
930 rt5668_enable_push_button_irq(component
, false);
931 snd_soc_component_update_bits(component
, RT5668_CBJ_CTRL_1
,
932 RT5668_TRIG_JD_MASK
, RT5668_TRIG_JD_LOW
);
933 snd_soc_dapm_disable_pin(dapm
, "CBJ Power");
934 snd_soc_dapm_sync(dapm
);
936 rt5668
->jack_type
= 0;
939 dev_dbg(component
->dev
, "jack_type = %d\n", rt5668
->jack_type
);
940 return rt5668
->jack_type
;
943 static irqreturn_t
rt5668_irq(int irq
, void *data
)
945 struct rt5668_priv
*rt5668
= data
;
947 mod_delayed_work(system_power_efficient_wq
,
948 &rt5668
->jack_detect_work
, msecs_to_jiffies(250));
953 static void rt5668_jd_check_handler(struct work_struct
*work
)
955 struct rt5668_priv
*rt5668
= container_of(work
, struct rt5668_priv
,
958 if (snd_soc_component_read32(rt5668
->component
, RT5668_AJD1_CTRL
)
959 & RT5668_JDH_RS_MASK
) {
961 rt5668
->jack_type
= rt5668_headset_detect(rt5668
->component
, 0);
963 snd_soc_jack_report(rt5668
->hs_jack
, rt5668
->jack_type
,
965 SND_JACK_BTN_0
| SND_JACK_BTN_1
|
966 SND_JACK_BTN_2
| SND_JACK_BTN_3
);
968 schedule_delayed_work(&rt5668
->jd_check_work
, 500);
972 static int rt5668_set_jack_detect(struct snd_soc_component
*component
,
973 struct snd_soc_jack
*hs_jack
, void *data
)
975 struct rt5668_priv
*rt5668
= snd_soc_component_get_drvdata(component
);
977 switch (rt5668
->pdata
.jd_src
) {
979 snd_soc_component_update_bits(component
, RT5668_CBJ_CTRL_2
,
980 RT5668_EXT_JD_SRC
, RT5668_EXT_JD_SRC_MANUAL
);
981 snd_soc_component_write(component
, RT5668_CBJ_CTRL_1
, 0xd002);
982 snd_soc_component_update_bits(component
, RT5668_CBJ_CTRL_3
,
983 RT5668_CBJ_IN_BUF_EN
, RT5668_CBJ_IN_BUF_EN
);
984 snd_soc_component_update_bits(component
, RT5668_SAR_IL_CMD_1
,
985 RT5668_SAR_POW_MASK
, RT5668_SAR_POW_EN
);
986 regmap_update_bits(rt5668
->regmap
, RT5668_GPIO_CTRL_1
,
987 RT5668_GP1_PIN_MASK
, RT5668_GP1_PIN_IRQ
);
988 regmap_update_bits(rt5668
->regmap
, RT5668_RC_CLK_CTRL
,
989 RT5668_POW_IRQ
| RT5668_POW_JDH
|
990 RT5668_POW_ANA
, RT5668_POW_IRQ
|
991 RT5668_POW_JDH
| RT5668_POW_ANA
);
992 regmap_update_bits(rt5668
->regmap
, RT5668_PWR_ANLG_2
,
993 RT5668_PWR_JDH
| RT5668_PWR_JDL
,
994 RT5668_PWR_JDH
| RT5668_PWR_JDL
);
995 regmap_update_bits(rt5668
->regmap
, RT5668_IRQ_CTRL_2
,
996 RT5668_JD1_EN_MASK
| RT5668_JD1_POL_MASK
,
997 RT5668_JD1_EN
| RT5668_JD1_POL_NOR
);
998 mod_delayed_work(system_power_efficient_wq
,
999 &rt5668
->jack_detect_work
, msecs_to_jiffies(250));
1002 case RT5668_JD_NULL
:
1003 regmap_update_bits(rt5668
->regmap
, RT5668_IRQ_CTRL_2
,
1004 RT5668_JD1_EN_MASK
, RT5668_JD1_DIS
);
1005 regmap_update_bits(rt5668
->regmap
, RT5668_RC_CLK_CTRL
,
1006 RT5668_POW_JDH
| RT5668_POW_JDL
, 0);
1010 dev_warn(component
->dev
, "Wrong JD source\n");
1014 rt5668
->hs_jack
= hs_jack
;
1019 static void rt5668_jack_detect_handler(struct work_struct
*work
)
1021 struct rt5668_priv
*rt5668
=
1022 container_of(work
, struct rt5668_priv
, jack_detect_work
.work
);
1025 while (!rt5668
->component
)
1026 usleep_range(10000, 15000);
1028 while (!rt5668
->component
->card
->instantiated
)
1029 usleep_range(10000, 15000);
1031 mutex_lock(&rt5668
->calibrate_mutex
);
1033 val
= snd_soc_component_read32(rt5668
->component
, RT5668_AJD1_CTRL
)
1034 & RT5668_JDH_RS_MASK
;
1037 if (rt5668
->jack_type
== 0) {
1038 /* jack was out, report jack type */
1040 rt5668_headset_detect(rt5668
->component
, 1);
1042 /* jack is already in, report button event */
1043 rt5668
->jack_type
= SND_JACK_HEADSET
;
1044 btn_type
= rt5668_button_detect(rt5668
->component
);
1046 * rt5668 can report three kinds of button behavior,
1047 * one click, double click and hold. However,
1048 * currently we will report button pressed/released
1049 * event. So all the three button behaviors are
1050 * treated as button pressed.
1056 rt5668
->jack_type
|= SND_JACK_BTN_0
;
1061 rt5668
->jack_type
|= SND_JACK_BTN_1
;
1066 rt5668
->jack_type
|= SND_JACK_BTN_2
;
1071 rt5668
->jack_type
|= SND_JACK_BTN_3
;
1073 case 0x0000: /* unpressed */
1077 dev_err(rt5668
->component
->dev
,
1078 "Unexpected button code 0x%04x\n",
1085 rt5668
->jack_type
= rt5668_headset_detect(rt5668
->component
, 0);
1088 snd_soc_jack_report(rt5668
->hs_jack
, rt5668
->jack_type
,
1090 SND_JACK_BTN_0
| SND_JACK_BTN_1
|
1091 SND_JACK_BTN_2
| SND_JACK_BTN_3
);
1093 if (rt5668
->jack_type
& (SND_JACK_BTN_0
| SND_JACK_BTN_1
|
1094 SND_JACK_BTN_2
| SND_JACK_BTN_3
))
1095 schedule_delayed_work(&rt5668
->jd_check_work
, 0);
1097 cancel_delayed_work_sync(&rt5668
->jd_check_work
);
1099 mutex_unlock(&rt5668
->calibrate_mutex
);
1102 static const struct snd_kcontrol_new rt5668_snd_controls
[] = {
1103 /* Headphone Output Volume */
1104 SOC_DOUBLE_R_TLV("Headphone Playback Volume", RT5668_HPL_GAIN
,
1105 RT5668_HPR_GAIN
, RT5668_G_HP_SFT
, 15, 1, hp_vol_tlv
),
1107 /* DAC Digital Volume */
1108 SOC_DOUBLE_TLV("DAC1 Playback Volume", RT5668_DAC1_DIG_VOL
,
1109 RT5668_L_VOL_SFT
, RT5668_R_VOL_SFT
, 175, 0, dac_vol_tlv
),
1111 /* IN Boost Volume */
1112 SOC_SINGLE_TLV("CBJ Boost Volume", RT5668_CBJ_BST_CTRL
,
1113 RT5668_BST_CBJ_SFT
, 8, 0, bst_tlv
),
1115 /* ADC Digital Volume Control */
1116 SOC_DOUBLE("STO1 ADC Capture Switch", RT5668_STO1_ADC_DIG_VOL
,
1117 RT5668_L_MUTE_SFT
, RT5668_R_MUTE_SFT
, 1, 1),
1118 SOC_DOUBLE_TLV("STO1 ADC Capture Volume", RT5668_STO1_ADC_DIG_VOL
,
1119 RT5668_L_VOL_SFT
, RT5668_R_VOL_SFT
, 127, 0, adc_vol_tlv
),
1121 /* ADC Boost Volume Control */
1122 SOC_DOUBLE_TLV("STO1 ADC Boost Gain Volume", RT5668_STO1_ADC_BOOST
,
1123 RT5668_STO1_ADC_L_BST_SFT
, RT5668_STO1_ADC_R_BST_SFT
,
1128 static int rt5668_div_sel(struct rt5668_priv
*rt5668
,
1129 int target
, const int div
[], int size
)
1133 if (rt5668
->sysclk
< target
) {
1134 pr_err("sysclk rate %d is too low\n",
1139 for (i
= 0; i
< size
- 1; i
++) {
1140 pr_info("div[%d]=%d\n", i
, div
[i
]);
1141 if (target
* div
[i
] == rt5668
->sysclk
)
1143 if (target
* div
[i
+ 1] > rt5668
->sysclk
) {
1144 pr_err("can't find div for sysclk %d\n",
1150 if (target
* div
[i
] < rt5668
->sysclk
)
1151 pr_err("sysclk rate %d is too high\n",
1159 * set_dmic_clk - Set parameter of dmic.
1162 * @kcontrol: The kcontrol of this widget.
1165 * Choose dmic clock between 1MHz and 3MHz.
1166 * It is better for clock to approximate 3MHz.
1168 static int set_dmic_clk(struct snd_soc_dapm_widget
*w
,
1169 struct snd_kcontrol
*kcontrol
, int event
)
1171 struct snd_soc_component
*component
=
1172 snd_soc_dapm_to_component(w
->dapm
);
1173 struct rt5668_priv
*rt5668
= snd_soc_component_get_drvdata(component
);
1175 static const int div
[] = {2, 4, 6, 8, 12, 16, 24, 32, 48, 64, 96, 128};
1177 idx
= rt5668_div_sel(rt5668
, 1500000, div
, ARRAY_SIZE(div
));
1179 snd_soc_component_update_bits(component
, RT5668_DMIC_CTRL_1
,
1180 RT5668_DMIC_CLK_MASK
, idx
<< RT5668_DMIC_CLK_SFT
);
1185 static int set_filter_clk(struct snd_soc_dapm_widget
*w
,
1186 struct snd_kcontrol
*kcontrol
, int event
)
1188 struct snd_soc_component
*component
=
1189 snd_soc_dapm_to_component(w
->dapm
);
1190 struct rt5668_priv
*rt5668
= snd_soc_component_get_drvdata(component
);
1191 int ref
, val
, reg
, idx
= -EINVAL
;
1192 static const int div
[] = {1, 2, 3, 4, 6, 8, 12, 16, 24, 32, 48};
1194 val
= snd_soc_component_read32(component
, RT5668_GPIO_CTRL_1
) &
1195 RT5668_GP4_PIN_MASK
;
1196 if (w
->shift
== RT5668_PWR_ADC_S1F_BIT
&&
1197 val
== RT5668_GP4_PIN_ADCDAT2
)
1198 ref
= 256 * rt5668
->lrck
[RT5668_AIF2
];
1200 ref
= 256 * rt5668
->lrck
[RT5668_AIF1
];
1202 idx
= rt5668_div_sel(rt5668
, ref
, div
, ARRAY_SIZE(div
));
1204 if (w
->shift
== RT5668_PWR_ADC_S1F_BIT
)
1205 reg
= RT5668_PLL_TRACK_3
;
1207 reg
= RT5668_PLL_TRACK_2
;
1209 snd_soc_component_update_bits(component
, reg
,
1210 RT5668_FILTER_CLK_SEL_MASK
, idx
<< RT5668_FILTER_CLK_SEL_SFT
);
1215 static int is_sys_clk_from_pll1(struct snd_soc_dapm_widget
*w
,
1216 struct snd_soc_dapm_widget
*sink
)
1219 struct snd_soc_component
*component
=
1220 snd_soc_dapm_to_component(w
->dapm
);
1222 val
= snd_soc_component_read32(component
, RT5668_GLB_CLK
);
1223 val
&= RT5668_SCLK_SRC_MASK
;
1224 if (val
== RT5668_SCLK_SRC_PLL1
)
1230 static int is_using_asrc(struct snd_soc_dapm_widget
*w
,
1231 struct snd_soc_dapm_widget
*sink
)
1233 unsigned int reg
, shift
, val
;
1234 struct snd_soc_component
*component
=
1235 snd_soc_dapm_to_component(w
->dapm
);
1238 case RT5668_ADC_STO1_ASRC_SFT
:
1239 reg
= RT5668_PLL_TRACK_3
;
1240 shift
= RT5668_FILTER_CLK_SEL_SFT
;
1242 case RT5668_DAC_STO1_ASRC_SFT
:
1243 reg
= RT5668_PLL_TRACK_2
;
1244 shift
= RT5668_FILTER_CLK_SEL_SFT
;
1250 val
= (snd_soc_component_read32(component
, reg
) >> shift
) & 0xf;
1252 case RT5668_CLK_SEL_I2S1_ASRC
:
1253 case RT5668_CLK_SEL_I2S2_ASRC
:
1262 static const struct snd_kcontrol_new rt5668_sto1_adc_l_mix
[] = {
1263 SOC_DAPM_SINGLE("ADC1 Switch", RT5668_STO1_ADC_MIXER
,
1264 RT5668_M_STO1_ADC_L1_SFT
, 1, 1),
1265 SOC_DAPM_SINGLE("ADC2 Switch", RT5668_STO1_ADC_MIXER
,
1266 RT5668_M_STO1_ADC_L2_SFT
, 1, 1),
1269 static const struct snd_kcontrol_new rt5668_sto1_adc_r_mix
[] = {
1270 SOC_DAPM_SINGLE("ADC1 Switch", RT5668_STO1_ADC_MIXER
,
1271 RT5668_M_STO1_ADC_R1_SFT
, 1, 1),
1272 SOC_DAPM_SINGLE("ADC2 Switch", RT5668_STO1_ADC_MIXER
,
1273 RT5668_M_STO1_ADC_R2_SFT
, 1, 1),
1276 static const struct snd_kcontrol_new rt5668_dac_l_mix
[] = {
1277 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5668_AD_DA_MIXER
,
1278 RT5668_M_ADCMIX_L_SFT
, 1, 1),
1279 SOC_DAPM_SINGLE("DAC1 Switch", RT5668_AD_DA_MIXER
,
1280 RT5668_M_DAC1_L_SFT
, 1, 1),
1283 static const struct snd_kcontrol_new rt5668_dac_r_mix
[] = {
1284 SOC_DAPM_SINGLE("Stereo ADC Switch", RT5668_AD_DA_MIXER
,
1285 RT5668_M_ADCMIX_R_SFT
, 1, 1),
1286 SOC_DAPM_SINGLE("DAC1 Switch", RT5668_AD_DA_MIXER
,
1287 RT5668_M_DAC1_R_SFT
, 1, 1),
1290 static const struct snd_kcontrol_new rt5668_sto1_dac_l_mix
[] = {
1291 SOC_DAPM_SINGLE("DAC L1 Switch", RT5668_STO1_DAC_MIXER
,
1292 RT5668_M_DAC_L1_STO_L_SFT
, 1, 1),
1293 SOC_DAPM_SINGLE("DAC R1 Switch", RT5668_STO1_DAC_MIXER
,
1294 RT5668_M_DAC_R1_STO_L_SFT
, 1, 1),
1297 static const struct snd_kcontrol_new rt5668_sto1_dac_r_mix
[] = {
1298 SOC_DAPM_SINGLE("DAC L1 Switch", RT5668_STO1_DAC_MIXER
,
1299 RT5668_M_DAC_L1_STO_R_SFT
, 1, 1),
1300 SOC_DAPM_SINGLE("DAC R1 Switch", RT5668_STO1_DAC_MIXER
,
1301 RT5668_M_DAC_R1_STO_R_SFT
, 1, 1),
1304 /* Analog Input Mixer */
1305 static const struct snd_kcontrol_new rt5668_rec1_l_mix
[] = {
1306 SOC_DAPM_SINGLE("CBJ Switch", RT5668_REC_MIXER
,
1307 RT5668_M_CBJ_RM1_L_SFT
, 1, 1),
1310 /* STO1 ADC1 Source */
1311 /* MX-26 [13] [5] */
1312 static const char * const rt5668_sto1_adc1_src
[] = {
1316 static SOC_ENUM_SINGLE_DECL(
1317 rt5668_sto1_adc1l_enum
, RT5668_STO1_ADC_MIXER
,
1318 RT5668_STO1_ADC1L_SRC_SFT
, rt5668_sto1_adc1_src
);
1320 static const struct snd_kcontrol_new rt5668_sto1_adc1l_mux
=
1321 SOC_DAPM_ENUM("Stereo1 ADC1L Source", rt5668_sto1_adc1l_enum
);
1323 static SOC_ENUM_SINGLE_DECL(
1324 rt5668_sto1_adc1r_enum
, RT5668_STO1_ADC_MIXER
,
1325 RT5668_STO1_ADC1R_SRC_SFT
, rt5668_sto1_adc1_src
);
1327 static const struct snd_kcontrol_new rt5668_sto1_adc1r_mux
=
1328 SOC_DAPM_ENUM("Stereo1 ADC1L Source", rt5668_sto1_adc1r_enum
);
1330 /* STO1 ADC Source */
1331 /* MX-26 [11:10] [3:2] */
1332 static const char * const rt5668_sto1_adc_src
[] = {
1336 static SOC_ENUM_SINGLE_DECL(
1337 rt5668_sto1_adcl_enum
, RT5668_STO1_ADC_MIXER
,
1338 RT5668_STO1_ADCL_SRC_SFT
, rt5668_sto1_adc_src
);
1340 static const struct snd_kcontrol_new rt5668_sto1_adcl_mux
=
1341 SOC_DAPM_ENUM("Stereo1 ADCL Source", rt5668_sto1_adcl_enum
);
1343 static SOC_ENUM_SINGLE_DECL(
1344 rt5668_sto1_adcr_enum
, RT5668_STO1_ADC_MIXER
,
1345 RT5668_STO1_ADCR_SRC_SFT
, rt5668_sto1_adc_src
);
1347 static const struct snd_kcontrol_new rt5668_sto1_adcr_mux
=
1348 SOC_DAPM_ENUM("Stereo1 ADCR Source", rt5668_sto1_adcr_enum
);
1350 /* STO1 ADC2 Source */
1351 /* MX-26 [12] [4] */
1352 static const char * const rt5668_sto1_adc2_src
[] = {
1356 static SOC_ENUM_SINGLE_DECL(
1357 rt5668_sto1_adc2l_enum
, RT5668_STO1_ADC_MIXER
,
1358 RT5668_STO1_ADC2L_SRC_SFT
, rt5668_sto1_adc2_src
);
1360 static const struct snd_kcontrol_new rt5668_sto1_adc2l_mux
=
1361 SOC_DAPM_ENUM("Stereo1 ADC2L Source", rt5668_sto1_adc2l_enum
);
1363 static SOC_ENUM_SINGLE_DECL(
1364 rt5668_sto1_adc2r_enum
, RT5668_STO1_ADC_MIXER
,
1365 RT5668_STO1_ADC2R_SRC_SFT
, rt5668_sto1_adc2_src
);
1367 static const struct snd_kcontrol_new rt5668_sto1_adc2r_mux
=
1368 SOC_DAPM_ENUM("Stereo1 ADC2R Source", rt5668_sto1_adc2r_enum
);
1370 /* MX-79 [6:4] I2S1 ADC data location */
1371 static const unsigned int rt5668_if1_adc_slot_values
[] = {
1378 static const char * const rt5668_if1_adc_slot_src
[] = {
1379 "Slot 0", "Slot 2", "Slot 4", "Slot 6"
1382 static SOC_VALUE_ENUM_SINGLE_DECL(rt5668_if1_adc_slot_enum
,
1383 RT5668_TDM_CTRL
, RT5668_TDM_ADC_LCA_SFT
, RT5668_TDM_ADC_LCA_MASK
,
1384 rt5668_if1_adc_slot_src
, rt5668_if1_adc_slot_values
);
1386 static const struct snd_kcontrol_new rt5668_if1_adc_slot_mux
=
1387 SOC_DAPM_ENUM("IF1 ADC Slot location", rt5668_if1_adc_slot_enum
);
1389 /* Analog DAC L1 Source, Analog DAC R1 Source*/
1390 /* MX-2B [4], MX-2B [0]*/
1391 static const char * const rt5668_alg_dac1_src
[] = {
1392 "Stereo1 DAC Mixer", "DAC1"
1395 static SOC_ENUM_SINGLE_DECL(
1396 rt5668_alg_dac_l1_enum
, RT5668_A_DAC1_MUX
,
1397 RT5668_A_DACL1_SFT
, rt5668_alg_dac1_src
);
1399 static const struct snd_kcontrol_new rt5668_alg_dac_l1_mux
=
1400 SOC_DAPM_ENUM("Analog DAC L1 Source", rt5668_alg_dac_l1_enum
);
1402 static SOC_ENUM_SINGLE_DECL(
1403 rt5668_alg_dac_r1_enum
, RT5668_A_DAC1_MUX
,
1404 RT5668_A_DACR1_SFT
, rt5668_alg_dac1_src
);
1406 static const struct snd_kcontrol_new rt5668_alg_dac_r1_mux
=
1407 SOC_DAPM_ENUM("Analog DAC R1 Source", rt5668_alg_dac_r1_enum
);
1410 static const struct snd_kcontrol_new hpol_switch
=
1411 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5668_HP_CTRL_1
,
1412 RT5668_L_MUTE_SFT
, 1, 1);
1413 static const struct snd_kcontrol_new hpor_switch
=
1414 SOC_DAPM_SINGLE_AUTODISABLE("Switch", RT5668_HP_CTRL_1
,
1415 RT5668_R_MUTE_SFT
, 1, 1);
1417 static int rt5668_hp_event(struct snd_soc_dapm_widget
*w
,
1418 struct snd_kcontrol
*kcontrol
, int event
)
1420 struct snd_soc_component
*component
=
1421 snd_soc_dapm_to_component(w
->dapm
);
1424 case SND_SOC_DAPM_PRE_PMU
:
1425 snd_soc_component_write(component
,
1426 RT5668_HP_LOGIC_CTRL_2
, 0x0012);
1427 snd_soc_component_write(component
,
1428 RT5668_HP_CTRL_2
, 0x6000);
1429 snd_soc_component_update_bits(component
, RT5668_STO_NG2_CTRL_1
,
1430 RT5668_NG2_EN_MASK
, RT5668_NG2_EN
);
1431 snd_soc_component_update_bits(component
,
1432 RT5668_DEPOP_1
, 0x60, 0x60);
1435 case SND_SOC_DAPM_POST_PMD
:
1436 snd_soc_component_update_bits(component
,
1437 RT5668_DEPOP_1
, 0x60, 0x0);
1438 snd_soc_component_write(component
,
1439 RT5668_HP_CTRL_2
, 0x0000);
1450 static int set_dmic_power(struct snd_soc_dapm_widget
*w
,
1451 struct snd_kcontrol
*kcontrol
, int event
)
1454 case SND_SOC_DAPM_POST_PMU
:
1455 /*Add delay to avoid pop noise*/
1466 static int rt5655_set_verf(struct snd_soc_dapm_widget
*w
,
1467 struct snd_kcontrol
*kcontrol
, int event
)
1469 struct snd_soc_component
*component
=
1470 snd_soc_dapm_to_component(w
->dapm
);
1473 case SND_SOC_DAPM_PRE_PMU
:
1475 case RT5668_PWR_VREF1_BIT
:
1476 snd_soc_component_update_bits(component
,
1477 RT5668_PWR_ANLG_1
, RT5668_PWR_FV1
, 0);
1480 case RT5668_PWR_VREF2_BIT
:
1481 snd_soc_component_update_bits(component
,
1482 RT5668_PWR_ANLG_1
, RT5668_PWR_FV2
, 0);
1490 case SND_SOC_DAPM_POST_PMU
:
1491 usleep_range(15000, 20000);
1493 case RT5668_PWR_VREF1_BIT
:
1494 snd_soc_component_update_bits(component
,
1495 RT5668_PWR_ANLG_1
, RT5668_PWR_FV1
,
1499 case RT5668_PWR_VREF2_BIT
:
1500 snd_soc_component_update_bits(component
,
1501 RT5668_PWR_ANLG_1
, RT5668_PWR_FV2
,
1517 static const unsigned int rt5668_adcdat_pin_values
[] = {
1522 static const char * const rt5668_adcdat_pin_select
[] = {
1527 static SOC_VALUE_ENUM_SINGLE_DECL(rt5668_adcdat_pin_enum
,
1528 RT5668_GPIO_CTRL_1
, RT5668_GP4_PIN_SFT
, RT5668_GP4_PIN_MASK
,
1529 rt5668_adcdat_pin_select
, rt5668_adcdat_pin_values
);
1531 static const struct snd_kcontrol_new rt5668_adcdat_pin_ctrl
=
1532 SOC_DAPM_ENUM("ADCDAT", rt5668_adcdat_pin_enum
);
1534 static const struct snd_soc_dapm_widget rt5668_dapm_widgets
[] = {
1535 SND_SOC_DAPM_SUPPLY("LDO2", RT5668_PWR_ANLG_3
, RT5668_PWR_LDO2_BIT
,
1537 SND_SOC_DAPM_SUPPLY("PLL1", RT5668_PWR_ANLG_3
, RT5668_PWR_PLL_BIT
,
1539 SND_SOC_DAPM_SUPPLY("PLL2B", RT5668_PWR_ANLG_3
, RT5668_PWR_PLL2B_BIT
,
1541 SND_SOC_DAPM_SUPPLY("PLL2F", RT5668_PWR_ANLG_3
, RT5668_PWR_PLL2F_BIT
,
1543 SND_SOC_DAPM_SUPPLY("Vref1", RT5668_PWR_ANLG_1
, RT5668_PWR_VREF1_BIT
, 0,
1544 rt5655_set_verf
, SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
),
1545 SND_SOC_DAPM_SUPPLY("Vref2", RT5668_PWR_ANLG_1
, RT5668_PWR_VREF2_BIT
, 0,
1546 rt5655_set_verf
, SND_SOC_DAPM_PRE_PMU
| SND_SOC_DAPM_POST_PMU
),
1549 SND_SOC_DAPM_SUPPLY_S("DAC STO1 ASRC", 1, RT5668_PLL_TRACK_1
,
1550 RT5668_DAC_STO1_ASRC_SFT
, 0, NULL
, 0),
1551 SND_SOC_DAPM_SUPPLY_S("ADC STO1 ASRC", 1, RT5668_PLL_TRACK_1
,
1552 RT5668_ADC_STO1_ASRC_SFT
, 0, NULL
, 0),
1553 SND_SOC_DAPM_SUPPLY_S("AD ASRC", 1, RT5668_PLL_TRACK_1
,
1554 RT5668_AD_ASRC_SFT
, 0, NULL
, 0),
1555 SND_SOC_DAPM_SUPPLY_S("DA ASRC", 1, RT5668_PLL_TRACK_1
,
1556 RT5668_DA_ASRC_SFT
, 0, NULL
, 0),
1557 SND_SOC_DAPM_SUPPLY_S("DMIC ASRC", 1, RT5668_PLL_TRACK_1
,
1558 RT5668_DMIC_ASRC_SFT
, 0, NULL
, 0),
1561 SND_SOC_DAPM_SUPPLY("MICBIAS1", RT5668_PWR_ANLG_2
, RT5668_PWR_MB1_BIT
,
1563 SND_SOC_DAPM_SUPPLY("MICBIAS2", RT5668_PWR_ANLG_2
, RT5668_PWR_MB2_BIT
,
1567 SND_SOC_DAPM_INPUT("DMIC L1"),
1568 SND_SOC_DAPM_INPUT("DMIC R1"),
1570 SND_SOC_DAPM_INPUT("IN1P"),
1572 SND_SOC_DAPM_SUPPLY("DMIC CLK", SND_SOC_NOPM
, 0, 0,
1573 set_dmic_clk
, SND_SOC_DAPM_PRE_PMU
),
1574 SND_SOC_DAPM_SUPPLY("DMIC1 Power", RT5668_DMIC_CTRL_1
,
1575 RT5668_DMIC_1_EN_SFT
, 0, set_dmic_power
, SND_SOC_DAPM_POST_PMU
),
1578 SND_SOC_DAPM_PGA("BST1 CBJ", SND_SOC_NOPM
,
1581 SND_SOC_DAPM_SUPPLY("CBJ Power", RT5668_PWR_ANLG_3
,
1582 RT5668_PWR_CBJ_BIT
, 0, NULL
, 0),
1585 SND_SOC_DAPM_MIXER("RECMIX1L", SND_SOC_NOPM
, 0, 0, rt5668_rec1_l_mix
,
1586 ARRAY_SIZE(rt5668_rec1_l_mix
)),
1587 SND_SOC_DAPM_SUPPLY("RECMIX1L Power", RT5668_PWR_ANLG_2
,
1588 RT5668_PWR_RM1_L_BIT
, 0, NULL
, 0),
1591 SND_SOC_DAPM_ADC("ADC1 L", NULL
, SND_SOC_NOPM
, 0, 0),
1592 SND_SOC_DAPM_ADC("ADC1 R", NULL
, SND_SOC_NOPM
, 0, 0),
1594 SND_SOC_DAPM_SUPPLY("ADC1 L Power", RT5668_PWR_DIG_1
,
1595 RT5668_PWR_ADC_L1_BIT
, 0, NULL
, 0),
1596 SND_SOC_DAPM_SUPPLY("ADC1 R Power", RT5668_PWR_DIG_1
,
1597 RT5668_PWR_ADC_R1_BIT
, 0, NULL
, 0),
1598 SND_SOC_DAPM_SUPPLY("ADC1 clock", RT5668_CHOP_ADC
,
1599 RT5668_CKGEN_ADC1_SFT
, 0, NULL
, 0),
1602 SND_SOC_DAPM_MUX("Stereo1 ADC L1 Mux", SND_SOC_NOPM
, 0, 0,
1603 &rt5668_sto1_adc1l_mux
),
1604 SND_SOC_DAPM_MUX("Stereo1 ADC R1 Mux", SND_SOC_NOPM
, 0, 0,
1605 &rt5668_sto1_adc1r_mux
),
1606 SND_SOC_DAPM_MUX("Stereo1 ADC L2 Mux", SND_SOC_NOPM
, 0, 0,
1607 &rt5668_sto1_adc2l_mux
),
1608 SND_SOC_DAPM_MUX("Stereo1 ADC R2 Mux", SND_SOC_NOPM
, 0, 0,
1609 &rt5668_sto1_adc2r_mux
),
1610 SND_SOC_DAPM_MUX("Stereo1 ADC L Mux", SND_SOC_NOPM
, 0, 0,
1611 &rt5668_sto1_adcl_mux
),
1612 SND_SOC_DAPM_MUX("Stereo1 ADC R Mux", SND_SOC_NOPM
, 0, 0,
1613 &rt5668_sto1_adcr_mux
),
1614 SND_SOC_DAPM_MUX("IF1_ADC Mux", SND_SOC_NOPM
, 0, 0,
1615 &rt5668_if1_adc_slot_mux
),
1618 SND_SOC_DAPM_SUPPLY("ADC Stereo1 Filter", RT5668_PWR_DIG_2
,
1619 RT5668_PWR_ADC_S1F_BIT
, 0, set_filter_clk
,
1620 SND_SOC_DAPM_PRE_PMU
),
1621 SND_SOC_DAPM_MIXER("Stereo1 ADC MIXL", RT5668_STO1_ADC_DIG_VOL
,
1622 RT5668_L_MUTE_SFT
, 1, rt5668_sto1_adc_l_mix
,
1623 ARRAY_SIZE(rt5668_sto1_adc_l_mix
)),
1624 SND_SOC_DAPM_MIXER("Stereo1 ADC MIXR", RT5668_STO1_ADC_DIG_VOL
,
1625 RT5668_R_MUTE_SFT
, 1, rt5668_sto1_adc_r_mix
,
1626 ARRAY_SIZE(rt5668_sto1_adc_r_mix
)),
1629 SND_SOC_DAPM_PGA("Stereo1 ADC MIX", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1631 /* Digital Interface */
1632 SND_SOC_DAPM_SUPPLY("I2S1", RT5668_PWR_DIG_1
, RT5668_PWR_I2S1_BIT
,
1634 SND_SOC_DAPM_SUPPLY("I2S2", RT5668_PWR_DIG_1
, RT5668_PWR_I2S2_BIT
,
1636 SND_SOC_DAPM_PGA("IF1 DAC1", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1637 SND_SOC_DAPM_PGA("IF1 DAC1 L", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1638 SND_SOC_DAPM_PGA("IF1 DAC1 R", SND_SOC_NOPM
, 0, 0, NULL
, 0),
1640 /* Digital Interface Select */
1641 SND_SOC_DAPM_MUX("IF1 01 ADC Swap Mux", SND_SOC_NOPM
, 0, 0,
1642 &rt5668_if1_01_adc_swap_mux
),
1643 SND_SOC_DAPM_MUX("IF1 23 ADC Swap Mux", SND_SOC_NOPM
, 0, 0,
1644 &rt5668_if1_23_adc_swap_mux
),
1645 SND_SOC_DAPM_MUX("IF1 45 ADC Swap Mux", SND_SOC_NOPM
, 0, 0,
1646 &rt5668_if1_45_adc_swap_mux
),
1647 SND_SOC_DAPM_MUX("IF1 67 ADC Swap Mux", SND_SOC_NOPM
, 0, 0,
1648 &rt5668_if1_67_adc_swap_mux
),
1649 SND_SOC_DAPM_MUX("IF2 ADC Swap Mux", SND_SOC_NOPM
, 0, 0,
1650 &rt5668_if2_adc_swap_mux
),
1652 SND_SOC_DAPM_MUX("ADCDAT Mux", SND_SOC_NOPM
, 0, 0,
1653 &rt5668_adcdat_pin_ctrl
),
1655 /* Audio Interface */
1656 SND_SOC_DAPM_AIF_OUT("AIF1TX", "AIF1 Capture", 0,
1657 RT5668_I2S1_SDP
, RT5668_SEL_ADCDAT_SFT
, 1),
1658 SND_SOC_DAPM_AIF_OUT("AIF2TX", "AIF2 Capture", 0,
1659 RT5668_I2S2_SDP
, RT5668_I2S2_PIN_CFG_SFT
, 1),
1660 SND_SOC_DAPM_AIF_IN("AIF1RX", "AIF1 Playback", 0, SND_SOC_NOPM
, 0, 0),
1663 /* DAC mixer before sound effect */
1664 SND_SOC_DAPM_MIXER("DAC1 MIXL", SND_SOC_NOPM
, 0, 0,
1665 rt5668_dac_l_mix
, ARRAY_SIZE(rt5668_dac_l_mix
)),
1666 SND_SOC_DAPM_MIXER("DAC1 MIXR", SND_SOC_NOPM
, 0, 0,
1667 rt5668_dac_r_mix
, ARRAY_SIZE(rt5668_dac_r_mix
)),
1669 /* DAC channel Mux */
1670 SND_SOC_DAPM_MUX("DAC L1 Source", SND_SOC_NOPM
, 0, 0,
1671 &rt5668_alg_dac_l1_mux
),
1672 SND_SOC_DAPM_MUX("DAC R1 Source", SND_SOC_NOPM
, 0, 0,
1673 &rt5668_alg_dac_r1_mux
),
1676 SND_SOC_DAPM_SUPPLY("DAC Stereo1 Filter", RT5668_PWR_DIG_2
,
1677 RT5668_PWR_DAC_S1F_BIT
, 0, set_filter_clk
,
1678 SND_SOC_DAPM_PRE_PMU
),
1679 SND_SOC_DAPM_MIXER("Stereo1 DAC MIXL", SND_SOC_NOPM
, 0, 0,
1680 rt5668_sto1_dac_l_mix
, ARRAY_SIZE(rt5668_sto1_dac_l_mix
)),
1681 SND_SOC_DAPM_MIXER("Stereo1 DAC MIXR", SND_SOC_NOPM
, 0, 0,
1682 rt5668_sto1_dac_r_mix
, ARRAY_SIZE(rt5668_sto1_dac_r_mix
)),
1685 SND_SOC_DAPM_DAC("DAC L1", NULL
, RT5668_PWR_DIG_1
,
1686 RT5668_PWR_DAC_L1_BIT
, 0),
1687 SND_SOC_DAPM_DAC("DAC R1", NULL
, RT5668_PWR_DIG_1
,
1688 RT5668_PWR_DAC_R1_BIT
, 0),
1689 SND_SOC_DAPM_SUPPLY_S("DAC 1 Clock", 3, RT5668_CHOP_DAC
,
1690 RT5668_CKGEN_DAC1_SFT
, 0, NULL
, 0),
1693 SND_SOC_DAPM_PGA_S("HP Amp", 1, SND_SOC_NOPM
, 0, 0, rt5668_hp_event
,
1694 SND_SOC_DAPM_POST_PMD
| SND_SOC_DAPM_PRE_PMU
),
1696 SND_SOC_DAPM_SUPPLY("HP Amp L", RT5668_PWR_ANLG_1
,
1697 RT5668_PWR_HA_L_BIT
, 0, NULL
, 0),
1698 SND_SOC_DAPM_SUPPLY("HP Amp R", RT5668_PWR_ANLG_1
,
1699 RT5668_PWR_HA_R_BIT
, 0, NULL
, 0),
1700 SND_SOC_DAPM_SUPPLY_S("Charge Pump", 1, RT5668_DEPOP_1
,
1701 RT5668_PUMP_EN_SFT
, 0, NULL
, 0),
1702 SND_SOC_DAPM_SUPPLY_S("Capless", 2, RT5668_DEPOP_1
,
1703 RT5668_CAPLESS_EN_SFT
, 0, NULL
, 0),
1705 SND_SOC_DAPM_SWITCH("HPOL Playback", SND_SOC_NOPM
, 0, 0,
1707 SND_SOC_DAPM_SWITCH("HPOR Playback", SND_SOC_NOPM
, 0, 0,
1711 SND_SOC_DAPM_SUPPLY("CLKDET SYS", RT5668_CLK_DET
,
1712 RT5668_SYS_CLK_DET_SFT
, 0, NULL
, 0),
1713 SND_SOC_DAPM_SUPPLY("CLKDET PLL1", RT5668_CLK_DET
,
1714 RT5668_PLL1_CLK_DET_SFT
, 0, NULL
, 0),
1715 SND_SOC_DAPM_SUPPLY("CLKDET PLL2", RT5668_CLK_DET
,
1716 RT5668_PLL2_CLK_DET_SFT
, 0, NULL
, 0),
1717 SND_SOC_DAPM_SUPPLY("CLKDET", RT5668_CLK_DET
,
1718 RT5668_POW_CLK_DET_SFT
, 0, NULL
, 0),
1721 SND_SOC_DAPM_OUTPUT("HPOL"),
1722 SND_SOC_DAPM_OUTPUT("HPOR"),
1726 static const struct snd_soc_dapm_route rt5668_dapm_routes
[] = {
1728 {"ADC Stereo1 Filter", NULL
, "PLL1", is_sys_clk_from_pll1
},
1729 {"DAC Stereo1 Filter", NULL
, "PLL1", is_sys_clk_from_pll1
},
1732 {"ADC Stereo1 Filter", NULL
, "ADC STO1 ASRC", is_using_asrc
},
1733 {"DAC Stereo1 Filter", NULL
, "DAC STO1 ASRC", is_using_asrc
},
1734 {"ADC STO1 ASRC", NULL
, "AD ASRC"},
1735 {"DAC STO1 ASRC", NULL
, "DA ASRC"},
1738 {"MICBIAS1", NULL
, "Vref1"},
1739 {"MICBIAS1", NULL
, "Vref2"},
1740 {"MICBIAS2", NULL
, "Vref1"},
1741 {"MICBIAS2", NULL
, "Vref2"},
1743 {"CLKDET SYS", NULL
, "CLKDET"},
1745 {"IN1P", NULL
, "LDO2"},
1747 {"BST1 CBJ", NULL
, "IN1P"},
1748 {"BST1 CBJ", NULL
, "CBJ Power"},
1749 {"CBJ Power", NULL
, "Vref2"},
1751 {"RECMIX1L", "CBJ Switch", "BST1 CBJ"},
1752 {"RECMIX1L", NULL
, "RECMIX1L Power"},
1754 {"ADC1 L", NULL
, "RECMIX1L"},
1755 {"ADC1 L", NULL
, "ADC1 L Power"},
1756 {"ADC1 L", NULL
, "ADC1 clock"},
1758 {"DMIC L1", NULL
, "DMIC CLK"},
1759 {"DMIC L1", NULL
, "DMIC1 Power"},
1760 {"DMIC R1", NULL
, "DMIC CLK"},
1761 {"DMIC R1", NULL
, "DMIC1 Power"},
1762 {"DMIC CLK", NULL
, "DMIC ASRC"},
1764 {"Stereo1 ADC L Mux", "ADC1 L", "ADC1 L"},
1765 {"Stereo1 ADC L Mux", "ADC1 R", "ADC1 R"},
1766 {"Stereo1 ADC R Mux", "ADC1 L", "ADC1 L"},
1767 {"Stereo1 ADC R Mux", "ADC1 R", "ADC1 R"},
1769 {"Stereo1 ADC L1 Mux", "ADC", "Stereo1 ADC L Mux"},
1770 {"Stereo1 ADC L1 Mux", "DAC MIX", "Stereo1 DAC MIXL"},
1771 {"Stereo1 ADC L2 Mux", "DMIC", "DMIC L1"},
1772 {"Stereo1 ADC L2 Mux", "DAC MIX", "Stereo1 DAC MIXL"},
1774 {"Stereo1 ADC R1 Mux", "ADC", "Stereo1 ADC R Mux"},
1775 {"Stereo1 ADC R1 Mux", "DAC MIX", "Stereo1 DAC MIXR"},
1776 {"Stereo1 ADC R2 Mux", "DMIC", "DMIC R1"},
1777 {"Stereo1 ADC R2 Mux", "DAC MIX", "Stereo1 DAC MIXR"},
1779 {"Stereo1 ADC MIXL", "ADC1 Switch", "Stereo1 ADC L1 Mux"},
1780 {"Stereo1 ADC MIXL", "ADC2 Switch", "Stereo1 ADC L2 Mux"},
1781 {"Stereo1 ADC MIXL", NULL
, "ADC Stereo1 Filter"},
1783 {"Stereo1 ADC MIXR", "ADC1 Switch", "Stereo1 ADC R1 Mux"},
1784 {"Stereo1 ADC MIXR", "ADC2 Switch", "Stereo1 ADC R2 Mux"},
1785 {"Stereo1 ADC MIXR", NULL
, "ADC Stereo1 Filter"},
1787 {"Stereo1 ADC MIX", NULL
, "Stereo1 ADC MIXL"},
1788 {"Stereo1 ADC MIX", NULL
, "Stereo1 ADC MIXR"},
1790 {"IF1 01 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1791 {"IF1 01 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1792 {"IF1 01 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1793 {"IF1 01 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1794 {"IF1 23 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1795 {"IF1 23 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1796 {"IF1 23 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1797 {"IF1 23 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1798 {"IF1 45 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1799 {"IF1 45 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1800 {"IF1 45 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1801 {"IF1 45 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1802 {"IF1 67 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1803 {"IF1 67 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1804 {"IF1 67 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1805 {"IF1 67 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1807 {"IF1_ADC Mux", "Slot 0", "IF1 01 ADC Swap Mux"},
1808 {"IF1_ADC Mux", "Slot 2", "IF1 23 ADC Swap Mux"},
1809 {"IF1_ADC Mux", "Slot 4", "IF1 45 ADC Swap Mux"},
1810 {"IF1_ADC Mux", "Slot 6", "IF1 67 ADC Swap Mux"},
1811 {"IF1_ADC Mux", NULL
, "I2S1"},
1812 {"ADCDAT Mux", "ADCDAT1", "IF1_ADC Mux"},
1813 {"AIF1TX", NULL
, "ADCDAT Mux"},
1814 {"IF2 ADC Swap Mux", "L/R", "Stereo1 ADC MIX"},
1815 {"IF2 ADC Swap Mux", "R/L", "Stereo1 ADC MIX"},
1816 {"IF2 ADC Swap Mux", "L/L", "Stereo1 ADC MIX"},
1817 {"IF2 ADC Swap Mux", "R/R", "Stereo1 ADC MIX"},
1818 {"ADCDAT Mux", "ADCDAT2", "IF2 ADC Swap Mux"},
1819 {"AIF2TX", NULL
, "ADCDAT Mux"},
1821 {"IF1 DAC1 L", NULL
, "AIF1RX"},
1822 {"IF1 DAC1 L", NULL
, "I2S1"},
1823 {"IF1 DAC1 L", NULL
, "DAC Stereo1 Filter"},
1824 {"IF1 DAC1 R", NULL
, "AIF1RX"},
1825 {"IF1 DAC1 R", NULL
, "I2S1"},
1826 {"IF1 DAC1 R", NULL
, "DAC Stereo1 Filter"},
1828 {"DAC1 MIXL", "Stereo ADC Switch", "Stereo1 ADC MIXL"},
1829 {"DAC1 MIXL", "DAC1 Switch", "IF1 DAC1 L"},
1830 {"DAC1 MIXR", "Stereo ADC Switch", "Stereo1 ADC MIXR"},
1831 {"DAC1 MIXR", "DAC1 Switch", "IF1 DAC1 R"},
1833 {"Stereo1 DAC MIXL", "DAC L1 Switch", "DAC1 MIXL"},
1834 {"Stereo1 DAC MIXL", "DAC R1 Switch", "DAC1 MIXR"},
1836 {"Stereo1 DAC MIXR", "DAC R1 Switch", "DAC1 MIXR"},
1837 {"Stereo1 DAC MIXR", "DAC L1 Switch", "DAC1 MIXL"},
1839 {"DAC L1 Source", "DAC1", "DAC1 MIXL"},
1840 {"DAC L1 Source", "Stereo1 DAC Mixer", "Stereo1 DAC MIXL"},
1841 {"DAC R1 Source", "DAC1", "DAC1 MIXR"},
1842 {"DAC R1 Source", "Stereo1 DAC Mixer", "Stereo1 DAC MIXR"},
1844 {"DAC L1", NULL
, "DAC L1 Source"},
1845 {"DAC R1", NULL
, "DAC R1 Source"},
1847 {"DAC L1", NULL
, "DAC 1 Clock"},
1848 {"DAC R1", NULL
, "DAC 1 Clock"},
1850 {"HP Amp", NULL
, "DAC L1"},
1851 {"HP Amp", NULL
, "DAC R1"},
1852 {"HP Amp", NULL
, "HP Amp L"},
1853 {"HP Amp", NULL
, "HP Amp R"},
1854 {"HP Amp", NULL
, "Capless"},
1855 {"HP Amp", NULL
, "Charge Pump"},
1856 {"HP Amp", NULL
, "CLKDET SYS"},
1857 {"HP Amp", NULL
, "CBJ Power"},
1858 {"HP Amp", NULL
, "Vref2"},
1859 {"HPOL Playback", "Switch", "HP Amp"},
1860 {"HPOR Playback", "Switch", "HP Amp"},
1861 {"HPOL", NULL
, "HPOL Playback"},
1862 {"HPOR", NULL
, "HPOR Playback"},
1865 static int rt5668_set_tdm_slot(struct snd_soc_dai
*dai
, unsigned int tx_mask
,
1866 unsigned int rx_mask
, int slots
, int slot_width
)
1868 struct snd_soc_component
*component
= dai
->component
;
1869 unsigned int val
= 0;
1873 val
|= RT5668_TDM_TX_CH_4
;
1874 val
|= RT5668_TDM_RX_CH_4
;
1877 val
|= RT5668_TDM_TX_CH_6
;
1878 val
|= RT5668_TDM_RX_CH_6
;
1881 val
|= RT5668_TDM_TX_CH_8
;
1882 val
|= RT5668_TDM_RX_CH_8
;
1890 snd_soc_component_update_bits(component
, RT5668_TDM_CTRL
,
1891 RT5668_TDM_TX_CH_MASK
| RT5668_TDM_RX_CH_MASK
, val
);
1893 switch (slot_width
) {
1895 val
= RT5668_TDM_CL_16
;
1898 val
= RT5668_TDM_CL_20
;
1901 val
= RT5668_TDM_CL_24
;
1904 val
= RT5668_TDM_CL_32
;
1910 snd_soc_component_update_bits(component
, RT5668_TDM_TCON_CTRL
,
1911 RT5668_TDM_CL_MASK
, val
);
1917 static int rt5668_hw_params(struct snd_pcm_substream
*substream
,
1918 struct snd_pcm_hw_params
*params
, struct snd_soc_dai
*dai
)
1920 struct snd_soc_component
*component
= dai
->component
;
1921 struct rt5668_priv
*rt5668
= snd_soc_component_get_drvdata(component
);
1922 unsigned int len_1
= 0, len_2
= 0;
1923 int pre_div
, frame_size
;
1925 rt5668
->lrck
[dai
->id
] = params_rate(params
);
1926 pre_div
= rl6231_get_clk_info(rt5668
->sysclk
, rt5668
->lrck
[dai
->id
]);
1928 frame_size
= snd_soc_params_to_frame_size(params
);
1929 if (frame_size
< 0) {
1930 dev_err(component
->dev
, "Unsupported frame size: %d\n",
1935 dev_dbg(dai
->dev
, "lrck is %dHz and pre_div is %d for iis %d\n",
1936 rt5668
->lrck
[dai
->id
], pre_div
, dai
->id
);
1938 switch (params_width(params
)) {
1942 len_1
|= RT5668_I2S1_DL_20
;
1943 len_2
|= RT5668_I2S2_DL_20
;
1946 len_1
|= RT5668_I2S1_DL_24
;
1947 len_2
|= RT5668_I2S2_DL_24
;
1950 len_1
|= RT5668_I2S1_DL_32
;
1951 len_2
|= RT5668_I2S2_DL_24
;
1954 len_1
|= RT5668_I2S2_DL_8
;
1955 len_2
|= RT5668_I2S2_DL_8
;
1963 snd_soc_component_update_bits(component
, RT5668_I2S1_SDP
,
1964 RT5668_I2S1_DL_MASK
, len_1
);
1965 if (rt5668
->master
[RT5668_AIF1
]) {
1966 snd_soc_component_update_bits(component
,
1967 RT5668_ADDA_CLK_1
, RT5668_I2S_M_DIV_MASK
,
1968 pre_div
<< RT5668_I2S_M_DIV_SFT
);
1970 if (params_channels(params
) == 1) /* mono mode */
1971 snd_soc_component_update_bits(component
,
1972 RT5668_I2S1_SDP
, RT5668_I2S1_MONO_MASK
,
1973 RT5668_I2S1_MONO_EN
);
1975 snd_soc_component_update_bits(component
,
1976 RT5668_I2S1_SDP
, RT5668_I2S1_MONO_MASK
,
1977 RT5668_I2S1_MONO_DIS
);
1980 snd_soc_component_update_bits(component
, RT5668_I2S2_SDP
,
1981 RT5668_I2S2_DL_MASK
, len_2
);
1982 if (rt5668
->master
[RT5668_AIF2
]) {
1983 snd_soc_component_update_bits(component
,
1984 RT5668_I2S_M_CLK_CTRL_1
, RT5668_I2S2_M_PD_MASK
,
1985 pre_div
<< RT5668_I2S2_M_PD_SFT
);
1987 if (params_channels(params
) == 1) /* mono mode */
1988 snd_soc_component_update_bits(component
,
1989 RT5668_I2S2_SDP
, RT5668_I2S2_MONO_MASK
,
1990 RT5668_I2S2_MONO_EN
);
1992 snd_soc_component_update_bits(component
,
1993 RT5668_I2S2_SDP
, RT5668_I2S2_MONO_MASK
,
1994 RT5668_I2S2_MONO_DIS
);
1997 dev_err(component
->dev
, "Invalid dai->id: %d\n", dai
->id
);
2004 static int rt5668_set_dai_fmt(struct snd_soc_dai
*dai
, unsigned int fmt
)
2006 struct snd_soc_component
*component
= dai
->component
;
2007 struct rt5668_priv
*rt5668
= snd_soc_component_get_drvdata(component
);
2008 unsigned int reg_val
= 0, tdm_ctrl
= 0;
2010 switch (fmt
& SND_SOC_DAIFMT_MASTER_MASK
) {
2011 case SND_SOC_DAIFMT_CBM_CFM
:
2012 rt5668
->master
[dai
->id
] = 1;
2014 case SND_SOC_DAIFMT_CBS_CFS
:
2015 rt5668
->master
[dai
->id
] = 0;
2021 switch (fmt
& SND_SOC_DAIFMT_INV_MASK
) {
2022 case SND_SOC_DAIFMT_NB_NF
:
2024 case SND_SOC_DAIFMT_IB_NF
:
2025 reg_val
|= RT5668_I2S_BP_INV
;
2026 tdm_ctrl
|= RT5668_TDM_S_BP_INV
;
2028 case SND_SOC_DAIFMT_NB_IF
:
2029 if (dai
->id
== RT5668_AIF1
)
2030 tdm_ctrl
|= RT5668_TDM_S_LP_INV
| RT5668_TDM_M_BP_INV
;
2034 case SND_SOC_DAIFMT_IB_IF
:
2035 if (dai
->id
== RT5668_AIF1
)
2036 tdm_ctrl
|= RT5668_TDM_S_BP_INV
| RT5668_TDM_S_LP_INV
|
2037 RT5668_TDM_M_BP_INV
| RT5668_TDM_M_LP_INV
;
2045 switch (fmt
& SND_SOC_DAIFMT_FORMAT_MASK
) {
2046 case SND_SOC_DAIFMT_I2S
:
2048 case SND_SOC_DAIFMT_LEFT_J
:
2049 reg_val
|= RT5668_I2S_DF_LEFT
;
2050 tdm_ctrl
|= RT5668_TDM_DF_LEFT
;
2052 case SND_SOC_DAIFMT_DSP_A
:
2053 reg_val
|= RT5668_I2S_DF_PCM_A
;
2054 tdm_ctrl
|= RT5668_TDM_DF_PCM_A
;
2056 case SND_SOC_DAIFMT_DSP_B
:
2057 reg_val
|= RT5668_I2S_DF_PCM_B
;
2058 tdm_ctrl
|= RT5668_TDM_DF_PCM_B
;
2066 snd_soc_component_update_bits(component
, RT5668_I2S1_SDP
,
2067 RT5668_I2S_DF_MASK
, reg_val
);
2068 snd_soc_component_update_bits(component
, RT5668_TDM_TCON_CTRL
,
2069 RT5668_TDM_MS_MASK
| RT5668_TDM_S_BP_MASK
|
2070 RT5668_TDM_DF_MASK
| RT5668_TDM_M_BP_MASK
|
2071 RT5668_TDM_M_LP_MASK
| RT5668_TDM_S_LP_MASK
,
2072 tdm_ctrl
| rt5668
->master
[dai
->id
]);
2075 if (rt5668
->master
[dai
->id
] == 0)
2076 reg_val
|= RT5668_I2S2_MS_S
;
2077 snd_soc_component_update_bits(component
, RT5668_I2S2_SDP
,
2078 RT5668_I2S2_MS_MASK
| RT5668_I2S_BP_MASK
|
2079 RT5668_I2S_DF_MASK
, reg_val
);
2082 dev_err(component
->dev
, "Invalid dai->id: %d\n", dai
->id
);
2088 static int rt5668_set_component_sysclk(struct snd_soc_component
*component
,
2089 int clk_id
, int source
, unsigned int freq
, int dir
)
2091 struct rt5668_priv
*rt5668
= snd_soc_component_get_drvdata(component
);
2092 unsigned int reg_val
= 0, src
= 0;
2094 if (freq
== rt5668
->sysclk
&& clk_id
== rt5668
->sysclk_src
)
2098 case RT5668_SCLK_S_MCLK
:
2099 reg_val
|= RT5668_SCLK_SRC_MCLK
;
2100 src
= RT5668_CLK_SRC_MCLK
;
2102 case RT5668_SCLK_S_PLL1
:
2103 reg_val
|= RT5668_SCLK_SRC_PLL1
;
2104 src
= RT5668_CLK_SRC_PLL1
;
2106 case RT5668_SCLK_S_PLL2
:
2107 reg_val
|= RT5668_SCLK_SRC_PLL2
;
2108 src
= RT5668_CLK_SRC_PLL2
;
2110 case RT5668_SCLK_S_RCCLK
:
2111 reg_val
|= RT5668_SCLK_SRC_RCCLK
;
2112 src
= RT5668_CLK_SRC_RCCLK
;
2115 dev_err(component
->dev
, "Invalid clock id (%d)\n", clk_id
);
2118 snd_soc_component_update_bits(component
, RT5668_GLB_CLK
,
2119 RT5668_SCLK_SRC_MASK
, reg_val
);
2121 if (rt5668
->master
[RT5668_AIF2
]) {
2122 snd_soc_component_update_bits(component
,
2123 RT5668_I2S_M_CLK_CTRL_1
, RT5668_I2S2_SRC_MASK
,
2124 src
<< RT5668_I2S2_SRC_SFT
);
2127 rt5668
->sysclk
= freq
;
2128 rt5668
->sysclk_src
= clk_id
;
2130 dev_dbg(component
->dev
, "Sysclk is %dHz and clock id is %d\n",
2136 static int rt5668_set_component_pll(struct snd_soc_component
*component
,
2137 int pll_id
, int source
, unsigned int freq_in
,
2138 unsigned int freq_out
)
2140 struct rt5668_priv
*rt5668
= snd_soc_component_get_drvdata(component
);
2141 struct rl6231_pll_code pll_code
;
2144 if (source
== rt5668
->pll_src
&& freq_in
== rt5668
->pll_in
&&
2145 freq_out
== rt5668
->pll_out
)
2148 if (!freq_in
|| !freq_out
) {
2149 dev_dbg(component
->dev
, "PLL disabled\n");
2152 rt5668
->pll_out
= 0;
2153 snd_soc_component_update_bits(component
, RT5668_GLB_CLK
,
2154 RT5668_SCLK_SRC_MASK
, RT5668_SCLK_SRC_MCLK
);
2159 case RT5668_PLL1_S_MCLK
:
2160 snd_soc_component_update_bits(component
, RT5668_GLB_CLK
,
2161 RT5668_PLL1_SRC_MASK
, RT5668_PLL1_SRC_MCLK
);
2163 case RT5668_PLL1_S_BCLK1
:
2164 snd_soc_component_update_bits(component
, RT5668_GLB_CLK
,
2165 RT5668_PLL1_SRC_MASK
, RT5668_PLL1_SRC_BCLK1
);
2168 dev_err(component
->dev
, "Unknown PLL Source %d\n", source
);
2172 ret
= rl6231_pll_calc(freq_in
, freq_out
, &pll_code
);
2174 dev_err(component
->dev
, "Unsupport input clock %d\n", freq_in
);
2178 dev_dbg(component
->dev
, "bypass=%d m=%d n=%d k=%d\n",
2179 pll_code
.m_bp
, (pll_code
.m_bp
? 0 : pll_code
.m_code
),
2180 pll_code
.n_code
, pll_code
.k_code
);
2182 snd_soc_component_write(component
, RT5668_PLL_CTRL_1
,
2183 pll_code
.n_code
<< RT5668_PLL_N_SFT
| pll_code
.k_code
);
2184 snd_soc_component_write(component
, RT5668_PLL_CTRL_2
,
2185 (pll_code
.m_bp
? 0 : pll_code
.m_code
) << RT5668_PLL_M_SFT
|
2186 pll_code
.m_bp
<< RT5668_PLL_M_BP_SFT
);
2188 rt5668
->pll_in
= freq_in
;
2189 rt5668
->pll_out
= freq_out
;
2190 rt5668
->pll_src
= source
;
2195 static int rt5668_set_bclk_ratio(struct snd_soc_dai
*dai
, unsigned int ratio
)
2197 struct snd_soc_component
*component
= dai
->component
;
2198 struct rt5668_priv
*rt5668
= snd_soc_component_get_drvdata(component
);
2200 rt5668
->bclk
[dai
->id
] = ratio
;
2204 snd_soc_component_update_bits(component
, RT5668_ADDA_CLK_2
,
2205 RT5668_I2S2_BCLK_MS2_MASK
,
2206 RT5668_I2S2_BCLK_MS2_64
);
2209 snd_soc_component_update_bits(component
, RT5668_ADDA_CLK_2
,
2210 RT5668_I2S2_BCLK_MS2_MASK
,
2211 RT5668_I2S2_BCLK_MS2_32
);
2214 dev_err(dai
->dev
, "Invalid bclk ratio %d\n", ratio
);
2221 static int rt5668_set_bias_level(struct snd_soc_component
*component
,
2222 enum snd_soc_bias_level level
)
2224 struct rt5668_priv
*rt5668
= snd_soc_component_get_drvdata(component
);
2227 case SND_SOC_BIAS_PREPARE
:
2228 regmap_update_bits(rt5668
->regmap
, RT5668_PWR_ANLG_1
,
2229 RT5668_PWR_MB
| RT5668_PWR_BG
,
2230 RT5668_PWR_MB
| RT5668_PWR_BG
);
2231 regmap_update_bits(rt5668
->regmap
, RT5668_PWR_DIG_1
,
2232 RT5668_DIG_GATE_CTRL
| RT5668_PWR_LDO
,
2233 RT5668_DIG_GATE_CTRL
| RT5668_PWR_LDO
);
2236 case SND_SOC_BIAS_STANDBY
:
2237 regmap_update_bits(rt5668
->regmap
, RT5668_PWR_ANLG_1
,
2238 RT5668_PWR_MB
, RT5668_PWR_MB
);
2239 regmap_update_bits(rt5668
->regmap
, RT5668_PWR_DIG_1
,
2240 RT5668_DIG_GATE_CTRL
, RT5668_DIG_GATE_CTRL
);
2242 case SND_SOC_BIAS_OFF
:
2243 regmap_update_bits(rt5668
->regmap
, RT5668_PWR_DIG_1
,
2244 RT5668_DIG_GATE_CTRL
| RT5668_PWR_LDO
, 0);
2245 regmap_update_bits(rt5668
->regmap
, RT5668_PWR_ANLG_1
,
2246 RT5668_PWR_MB
| RT5668_PWR_BG
, 0);
2256 static int rt5668_probe(struct snd_soc_component
*component
)
2258 struct rt5668_priv
*rt5668
= snd_soc_component_get_drvdata(component
);
2260 rt5668
->component
= component
;
2265 static void rt5668_remove(struct snd_soc_component
*component
)
2267 struct rt5668_priv
*rt5668
= snd_soc_component_get_drvdata(component
);
2269 rt5668_reset(rt5668
->regmap
);
2273 static int rt5668_suspend(struct snd_soc_component
*component
)
2275 struct rt5668_priv
*rt5668
= snd_soc_component_get_drvdata(component
);
2277 regcache_cache_only(rt5668
->regmap
, true);
2278 regcache_mark_dirty(rt5668
->regmap
);
2282 static int rt5668_resume(struct snd_soc_component
*component
)
2284 struct rt5668_priv
*rt5668
= snd_soc_component_get_drvdata(component
);
2286 regcache_cache_only(rt5668
->regmap
, false);
2287 regcache_sync(rt5668
->regmap
);
2292 #define rt5668_suspend NULL
2293 #define rt5668_resume NULL
2296 #define RT5668_STEREO_RATES SNDRV_PCM_RATE_8000_192000
2297 #define RT5668_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE | \
2298 SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S8)
2300 static const struct snd_soc_dai_ops rt5668_aif1_dai_ops
= {
2301 .hw_params
= rt5668_hw_params
,
2302 .set_fmt
= rt5668_set_dai_fmt
,
2303 .set_tdm_slot
= rt5668_set_tdm_slot
,
2306 static const struct snd_soc_dai_ops rt5668_aif2_dai_ops
= {
2307 .hw_params
= rt5668_hw_params
,
2308 .set_fmt
= rt5668_set_dai_fmt
,
2309 .set_bclk_ratio
= rt5668_set_bclk_ratio
,
2312 static struct snd_soc_dai_driver rt5668_dai
[] = {
2314 .name
= "rt5668-aif1",
2317 .stream_name
= "AIF1 Playback",
2320 .rates
= RT5668_STEREO_RATES
,
2321 .formats
= RT5668_FORMATS
,
2324 .stream_name
= "AIF1 Capture",
2327 .rates
= RT5668_STEREO_RATES
,
2328 .formats
= RT5668_FORMATS
,
2330 .ops
= &rt5668_aif1_dai_ops
,
2333 .name
= "rt5668-aif2",
2336 .stream_name
= "AIF2 Capture",
2339 .rates
= RT5668_STEREO_RATES
,
2340 .formats
= RT5668_FORMATS
,
2342 .ops
= &rt5668_aif2_dai_ops
,
2346 static const struct snd_soc_component_driver soc_component_dev_rt5668
= {
2347 .probe
= rt5668_probe
,
2348 .remove
= rt5668_remove
,
2349 .suspend
= rt5668_suspend
,
2350 .resume
= rt5668_resume
,
2351 .set_bias_level
= rt5668_set_bias_level
,
2352 .controls
= rt5668_snd_controls
,
2353 .num_controls
= ARRAY_SIZE(rt5668_snd_controls
),
2354 .dapm_widgets
= rt5668_dapm_widgets
,
2355 .num_dapm_widgets
= ARRAY_SIZE(rt5668_dapm_widgets
),
2356 .dapm_routes
= rt5668_dapm_routes
,
2357 .num_dapm_routes
= ARRAY_SIZE(rt5668_dapm_routes
),
2358 .set_sysclk
= rt5668_set_component_sysclk
,
2359 .set_pll
= rt5668_set_component_pll
,
2360 .set_jack
= rt5668_set_jack_detect
,
2361 .use_pmdown_time
= 1,
2363 .non_legacy_dai_naming
= 1,
2366 static const struct regmap_config rt5668_regmap
= {
2369 .max_register
= RT5668_I2C_MODE
,
2370 .volatile_reg
= rt5668_volatile_register
,
2371 .readable_reg
= rt5668_readable_register
,
2372 .cache_type
= REGCACHE_RBTREE
,
2373 .reg_defaults
= rt5668_reg
,
2374 .num_reg_defaults
= ARRAY_SIZE(rt5668_reg
),
2375 .use_single_read
= true,
2376 .use_single_write
= true,
2379 static const struct i2c_device_id rt5668_i2c_id
[] = {
2383 MODULE_DEVICE_TABLE(i2c
, rt5668_i2c_id
);
2385 static int rt5668_parse_dt(struct rt5668_priv
*rt5668
, struct device
*dev
)
2388 of_property_read_u32(dev
->of_node
, "realtek,dmic1-data-pin",
2389 &rt5668
->pdata
.dmic1_data_pin
);
2390 of_property_read_u32(dev
->of_node
, "realtek,dmic1-clk-pin",
2391 &rt5668
->pdata
.dmic1_clk_pin
);
2392 of_property_read_u32(dev
->of_node
, "realtek,jd-src",
2393 &rt5668
->pdata
.jd_src
);
2395 rt5668
->pdata
.ldo1_en
= of_get_named_gpio(dev
->of_node
,
2396 "realtek,ldo1-en-gpios", 0);
2401 static void rt5668_calibrate(struct rt5668_priv
*rt5668
)
2405 mutex_lock(&rt5668
->calibrate_mutex
);
2407 rt5668_reset(rt5668
->regmap
);
2408 regmap_write(rt5668
->regmap
, RT5668_PWR_ANLG_1
, 0xa2bf);
2409 usleep_range(15000, 20000);
2410 regmap_write(rt5668
->regmap
, RT5668_PWR_ANLG_1
, 0xf2bf);
2411 regmap_write(rt5668
->regmap
, RT5668_MICBIAS_2
, 0x0380);
2412 regmap_write(rt5668
->regmap
, RT5668_PWR_DIG_1
, 0x8001);
2413 regmap_write(rt5668
->regmap
, RT5668_TEST_MODE_CTRL_1
, 0x0000);
2414 regmap_write(rt5668
->regmap
, RT5668_STO1_DAC_MIXER
, 0x2080);
2415 regmap_write(rt5668
->regmap
, RT5668_STO1_ADC_MIXER
, 0x4040);
2416 regmap_write(rt5668
->regmap
, RT5668_DEPOP_1
, 0x0069);
2417 regmap_write(rt5668
->regmap
, RT5668_CHOP_DAC
, 0x3000);
2418 regmap_write(rt5668
->regmap
, RT5668_HP_CTRL_2
, 0x6000);
2419 regmap_write(rt5668
->regmap
, RT5668_HP_CHARGE_PUMP_1
, 0x0f26);
2420 regmap_write(rt5668
->regmap
, RT5668_CALIB_ADC_CTRL
, 0x7f05);
2421 regmap_write(rt5668
->regmap
, RT5668_STO1_ADC_MIXER
, 0x686c);
2422 regmap_write(rt5668
->regmap
, RT5668_CAL_REC
, 0x0d0d);
2423 regmap_write(rt5668
->regmap
, RT5668_HP_CALIB_CTRL_9
, 0x000f);
2424 regmap_write(rt5668
->regmap
, RT5668_PWR_DIG_1
, 0x8d01);
2425 regmap_write(rt5668
->regmap
, RT5668_HP_CALIB_CTRL_2
, 0x0321);
2426 regmap_write(rt5668
->regmap
, RT5668_HP_LOGIC_CTRL_2
, 0x0004);
2427 regmap_write(rt5668
->regmap
, RT5668_HP_CALIB_CTRL_1
, 0x7c00);
2428 regmap_write(rt5668
->regmap
, RT5668_HP_CALIB_CTRL_3
, 0x06a1);
2429 regmap_write(rt5668
->regmap
, RT5668_A_DAC1_MUX
, 0x0311);
2430 regmap_write(rt5668
->regmap
, RT5668_RESET_HPF_CTRL
, 0x0000);
2431 regmap_write(rt5668
->regmap
, RT5668_ADC_STO1_HP_CTRL_1
, 0x3320);
2433 regmap_write(rt5668
->regmap
, RT5668_HP_CALIB_CTRL_1
, 0xfc00);
2435 for (count
= 0; count
< 60; count
++) {
2436 regmap_read(rt5668
->regmap
, RT5668_HP_CALIB_STA_1
, &value
);
2437 if (!(value
& 0x8000))
2440 usleep_range(10000, 10005);
2444 pr_err("HP Calibration Failure\n");
2446 /* restore settings */
2447 regmap_write(rt5668
->regmap
, RT5668_STO1_ADC_MIXER
, 0xc0c4);
2448 regmap_write(rt5668
->regmap
, RT5668_PWR_DIG_1
, 0x0000);
2450 mutex_unlock(&rt5668
->calibrate_mutex
);
2454 static int rt5668_i2c_probe(struct i2c_client
*i2c
,
2455 const struct i2c_device_id
*id
)
2457 struct rt5668_platform_data
*pdata
= dev_get_platdata(&i2c
->dev
);
2458 struct rt5668_priv
*rt5668
;
2462 rt5668
= devm_kzalloc(&i2c
->dev
, sizeof(struct rt5668_priv
),
2468 i2c_set_clientdata(i2c
, rt5668
);
2471 rt5668
->pdata
= *pdata
;
2473 rt5668_parse_dt(rt5668
, &i2c
->dev
);
2475 rt5668
->regmap
= devm_regmap_init_i2c(i2c
, &rt5668_regmap
);
2476 if (IS_ERR(rt5668
->regmap
)) {
2477 ret
= PTR_ERR(rt5668
->regmap
);
2478 dev_err(&i2c
->dev
, "Failed to allocate register map: %d\n",
2483 for (i
= 0; i
< ARRAY_SIZE(rt5668
->supplies
); i
++)
2484 rt5668
->supplies
[i
].supply
= rt5668_supply_names
[i
];
2486 ret
= devm_regulator_bulk_get(&i2c
->dev
, ARRAY_SIZE(rt5668
->supplies
),
2489 dev_err(&i2c
->dev
, "Failed to request supplies: %d\n", ret
);
2493 ret
= regulator_bulk_enable(ARRAY_SIZE(rt5668
->supplies
),
2496 dev_err(&i2c
->dev
, "Failed to enable supplies: %d\n", ret
);
2500 if (gpio_is_valid(rt5668
->pdata
.ldo1_en
)) {
2501 if (devm_gpio_request_one(&i2c
->dev
, rt5668
->pdata
.ldo1_en
,
2502 GPIOF_OUT_INIT_HIGH
, "rt5668"))
2503 dev_err(&i2c
->dev
, "Fail gpio_request gpio_ldo\n");
2506 /* Sleep for 300 ms miniumum */
2507 usleep_range(300000, 350000);
2509 regmap_write(rt5668
->regmap
, RT5668_I2C_MODE
, 0x1);
2510 usleep_range(10000, 15000);
2512 regmap_read(rt5668
->regmap
, RT5668_DEVICE_ID
, &val
);
2513 if (val
!= DEVICE_ID
) {
2514 pr_err("Device with ID register %x is not rt5668\n", val
);
2518 rt5668_reset(rt5668
->regmap
);
2520 rt5668_calibrate(rt5668
);
2522 regmap_write(rt5668
->regmap
, RT5668_DEPOP_1
, 0x0000);
2525 if (rt5668
->pdata
.dmic1_data_pin
!= RT5668_DMIC1_NULL
) {
2526 switch (rt5668
->pdata
.dmic1_data_pin
) {
2527 case RT5668_DMIC1_DATA_GPIO2
: /* share with LRCK2 */
2528 regmap_update_bits(rt5668
->regmap
, RT5668_DMIC_CTRL_1
,
2529 RT5668_DMIC_1_DP_MASK
, RT5668_DMIC_1_DP_GPIO2
);
2530 regmap_update_bits(rt5668
->regmap
, RT5668_GPIO_CTRL_1
,
2531 RT5668_GP2_PIN_MASK
, RT5668_GP2_PIN_DMIC_SDA
);
2534 case RT5668_DMIC1_DATA_GPIO5
: /* share with DACDAT1 */
2535 regmap_update_bits(rt5668
->regmap
, RT5668_DMIC_CTRL_1
,
2536 RT5668_DMIC_1_DP_MASK
, RT5668_DMIC_1_DP_GPIO5
);
2537 regmap_update_bits(rt5668
->regmap
, RT5668_GPIO_CTRL_1
,
2538 RT5668_GP5_PIN_MASK
, RT5668_GP5_PIN_DMIC_SDA
);
2542 dev_dbg(&i2c
->dev
, "invalid DMIC_DAT pin\n");
2546 switch (rt5668
->pdata
.dmic1_clk_pin
) {
2547 case RT5668_DMIC1_CLK_GPIO1
: /* share with IRQ */
2548 regmap_update_bits(rt5668
->regmap
, RT5668_GPIO_CTRL_1
,
2549 RT5668_GP1_PIN_MASK
, RT5668_GP1_PIN_DMIC_CLK
);
2552 case RT5668_DMIC1_CLK_GPIO3
: /* share with BCLK2 */
2553 regmap_update_bits(rt5668
->regmap
, RT5668_GPIO_CTRL_1
,
2554 RT5668_GP3_PIN_MASK
, RT5668_GP3_PIN_DMIC_CLK
);
2558 dev_dbg(&i2c
->dev
, "invalid DMIC_CLK pin\n");
2563 regmap_update_bits(rt5668
->regmap
, RT5668_PWR_ANLG_1
,
2564 RT5668_LDO1_DVO_MASK
| RT5668_HP_DRIVER_MASK
,
2565 RT5668_LDO1_DVO_14
| RT5668_HP_DRIVER_5X
);
2566 regmap_write(rt5668
->regmap
, RT5668_MICBIAS_2
, 0x0380);
2567 regmap_update_bits(rt5668
->regmap
, RT5668_GPIO_CTRL_1
,
2568 RT5668_GP4_PIN_MASK
| RT5668_GP5_PIN_MASK
,
2569 RT5668_GP4_PIN_ADCDAT1
| RT5668_GP5_PIN_DACDAT1
);
2570 regmap_write(rt5668
->regmap
, RT5668_TEST_MODE_CTRL_1
, 0x0000);
2572 INIT_DELAYED_WORK(&rt5668
->jack_detect_work
,
2573 rt5668_jack_detect_handler
);
2574 INIT_DELAYED_WORK(&rt5668
->jd_check_work
,
2575 rt5668_jd_check_handler
);
2577 mutex_init(&rt5668
->calibrate_mutex
);
2580 ret
= devm_request_threaded_irq(&i2c
->dev
, i2c
->irq
, NULL
,
2581 rt5668_irq
, IRQF_TRIGGER_RISING
| IRQF_TRIGGER_FALLING
2582 | IRQF_ONESHOT
, "rt5668", rt5668
);
2584 dev_err(&i2c
->dev
, "Failed to reguest IRQ: %d\n", ret
);
2588 return devm_snd_soc_register_component(&i2c
->dev
, &soc_component_dev_rt5668
,
2589 rt5668_dai
, ARRAY_SIZE(rt5668_dai
));
2592 static void rt5668_i2c_shutdown(struct i2c_client
*client
)
2594 struct rt5668_priv
*rt5668
= i2c_get_clientdata(client
);
2596 rt5668_reset(rt5668
->regmap
);
2600 static const struct of_device_id rt5668_of_match
[] = {
2601 {.compatible
= "realtek,rt5668b"},
2604 MODULE_DEVICE_TABLE(of
, rt5668_of_match
);
2608 static const struct acpi_device_id rt5668_acpi_match
[] = {
2612 MODULE_DEVICE_TABLE(acpi
, rt5668_acpi_match
);
2615 static struct i2c_driver rt5668_i2c_driver
= {
2618 .of_match_table
= of_match_ptr(rt5668_of_match
),
2619 .acpi_match_table
= ACPI_PTR(rt5668_acpi_match
),
2621 .probe
= rt5668_i2c_probe
,
2622 .shutdown
= rt5668_i2c_shutdown
,
2623 .id_table
= rt5668_i2c_id
,
2625 module_i2c_driver(rt5668_i2c_driver
);
2627 MODULE_DESCRIPTION("ASoC RT5668B driver");
2628 MODULE_AUTHOR("Bard Liao <bardliao@realtek.com>");
2629 MODULE_LICENSE("GPL v2");