@@ -405,7 +405,7 @@ static const struct regmap_config cs42l42_regmap = {
405
405
.use_single_write = true,
406
406
};
407
407
408
- static DECLARE_TLV_DB_SCALE (adc_tlv , -9600 , 100 , false ) ;
408
+ static DECLARE_TLV_DB_SCALE (adc_tlv , -9700 , 100 , true ) ;
409
409
static DECLARE_TLV_DB_SCALE (mixer_tlv , -6300 , 100 , true) ;
410
410
411
411
static const char * const cs42l42_hpf_freq_text [] = {
@@ -425,34 +425,23 @@ static SOC_ENUM_SINGLE_DECL(cs42l42_wnf3_freq_enum, CS42L42_ADC_WNF_HPF_CTL,
425
425
CS42L42_ADC_WNF_CF_SHIFT ,
426
426
cs42l42_wnf3_freq_text ) ;
427
427
428
- static const char * const cs42l42_wnf05_freq_text [] = {
429
- "280Hz" , "315Hz" , "350Hz" , "385Hz" ,
430
- "420Hz" , "455Hz" , "490Hz" , "525Hz"
431
- };
432
-
433
- static SOC_ENUM_SINGLE_DECL (cs42l42_wnf05_freq_enum , CS42L42_ADC_WNF_HPF_CTL ,
434
- CS42L42_ADC_WNF_CF_SHIFT ,
435
- cs42l42_wnf05_freq_text ) ;
436
-
437
428
static const struct snd_kcontrol_new cs42l42_snd_controls [] = {
438
429
/* ADC Volume and Filter Controls */
439
430
SOC_SINGLE ("ADC Notch Switch" , CS42L42_ADC_CTL ,
440
- CS42L42_ADC_NOTCH_DIS_SHIFT , true, false ),
431
+ CS42L42_ADC_NOTCH_DIS_SHIFT , true, true ),
441
432
SOC_SINGLE ("ADC Weak Force Switch" , CS42L42_ADC_CTL ,
442
433
CS42L42_ADC_FORCE_WEAK_VCM_SHIFT , true, false),
443
434
SOC_SINGLE ("ADC Invert Switch" , CS42L42_ADC_CTL ,
444
435
CS42L42_ADC_INV_SHIFT , true, false),
445
436
SOC_SINGLE ("ADC Boost Switch" , CS42L42_ADC_CTL ,
446
437
CS42L42_ADC_DIG_BOOST_SHIFT , true, false),
447
- SOC_SINGLE_SX_TLV ("ADC Volume" , CS42L42_ADC_VOLUME ,
448
- CS42L42_ADC_VOL_SHIFT , 0xA0 , 0x6C , adc_tlv ),
438
+ SOC_SINGLE_S8_TLV ("ADC Volume" , CS42L42_ADC_VOLUME , -97 , 12 , adc_tlv ),
449
439
SOC_SINGLE ("ADC WNF Switch" , CS42L42_ADC_WNF_HPF_CTL ,
450
440
CS42L42_ADC_WNF_EN_SHIFT , true, false),
451
441
SOC_SINGLE ("ADC HPF Switch" , CS42L42_ADC_WNF_HPF_CTL ,
452
442
CS42L42_ADC_HPF_EN_SHIFT , true, false),
453
443
SOC_ENUM ("HPF Corner Freq" , cs42l42_hpf_freq_enum ),
454
444
SOC_ENUM ("WNF 3dB Freq" , cs42l42_wnf3_freq_enum ),
455
- SOC_ENUM ("WNF 05dB Freq" , cs42l42_wnf05_freq_enum ),
456
445
457
446
/* DAC Volume and Filter Controls */
458
447
SOC_SINGLE ("DACA Invert Switch" , CS42L42_DAC_CTL1 ,
@@ -471,8 +460,8 @@ static const struct snd_soc_dapm_widget cs42l42_dapm_widgets[] = {
471
460
SND_SOC_DAPM_OUTPUT ("HP" ),
472
461
SND_SOC_DAPM_DAC ("DAC" , NULL , CS42L42_PWR_CTL1 , CS42L42_HP_PDN_SHIFT , 1 ),
473
462
SND_SOC_DAPM_MIXER ("MIXER" , CS42L42_PWR_CTL1 , CS42L42_MIXER_PDN_SHIFT , 1 , NULL , 0 ),
474
- SND_SOC_DAPM_AIF_IN ("SDIN1" , NULL , 0 , CS42L42_ASP_RX_DAI0_EN , CS42L42_ASP_RX0_CH1_SHIFT , 0 ),
475
- SND_SOC_DAPM_AIF_IN ("SDIN2" , NULL , 1 , CS42L42_ASP_RX_DAI0_EN , CS42L42_ASP_RX0_CH2_SHIFT , 0 ),
463
+ SND_SOC_DAPM_AIF_IN ("SDIN1" , NULL , 0 , SND_SOC_NOPM , 0 , 0 ),
464
+ SND_SOC_DAPM_AIF_IN ("SDIN2" , NULL , 1 , SND_SOC_NOPM , 0 , 0 ),
476
465
477
466
/* Playback Requirements */
478
467
SND_SOC_DAPM_SUPPLY ("ASP DAI0" , CS42L42_PWR_CTL1 , CS42L42_ASP_DAI_PDN_SHIFT , 1 , NULL , 0 ),
@@ -630,6 +619,8 @@ static int cs42l42_pll_config(struct snd_soc_component *component)
630
619
631
620
for (i = 0 ; i < ARRAY_SIZE (pll_ratio_table ); i ++ ) {
632
621
if (pll_ratio_table [i ].sclk == clk ) {
622
+ cs42l42 -> pll_config = i ;
623
+
633
624
/* Configure the internal sample rate */
634
625
snd_soc_component_update_bits (component , CS42L42_MCLK_CTL ,
635
626
CS42L42_INTERNAL_FS_MASK ,
@@ -638,14 +629,9 @@ static int cs42l42_pll_config(struct snd_soc_component *component)
638
629
(pll_ratio_table [i ].mclk_int !=
639
630
24000000 )) <<
640
631
CS42L42_INTERNAL_FS_SHIFT );
641
- /* Set the MCLK src (PLL or SCLK) and the divide
642
- * ratio
643
- */
632
+
644
633
snd_soc_component_update_bits (component , CS42L42_MCLK_SRC_SEL ,
645
- CS42L42_MCLK_SRC_SEL_MASK |
646
634
CS42L42_MCLKDIV_MASK ,
647
- (pll_ratio_table [i ].mclk_src_sel
648
- << CS42L42_MCLK_SRC_SEL_SHIFT ) |
649
635
(pll_ratio_table [i ].mclk_div <<
650
636
CS42L42_MCLKDIV_SHIFT ));
651
637
/* Set up the LRCLK */
@@ -681,15 +667,6 @@ static int cs42l42_pll_config(struct snd_soc_component *component)
681
667
CS42L42_FSYNC_PULSE_WIDTH_MASK ,
682
668
CS42L42_FRAC1_VAL (fsync - 1 ) <<
683
669
CS42L42_FSYNC_PULSE_WIDTH_SHIFT );
684
- snd_soc_component_update_bits (component ,
685
- CS42L42_ASP_FRM_CFG ,
686
- CS42L42_ASP_5050_MASK ,
687
- CS42L42_ASP_5050_MASK );
688
- /* Set the frame delay to 1.0 SCLK clocks */
689
- snd_soc_component_update_bits (component , CS42L42_ASP_FRM_CFG ,
690
- CS42L42_ASP_FSD_MASK ,
691
- CS42L42_ASP_FSD_1_0 <<
692
- CS42L42_ASP_FSD_SHIFT );
693
670
/* Set the sample rates (96k or lower) */
694
671
snd_soc_component_update_bits (component , CS42L42_FS_RATE_EN ,
695
672
CS42L42_FS_EN_MASK ,
@@ -789,7 +766,18 @@ static int cs42l42_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
789
766
/* interface format */
790
767
switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK ) {
791
768
case SND_SOC_DAIFMT_I2S :
792
- case SND_SOC_DAIFMT_LEFT_J :
769
+ /*
770
+ * 5050 mode, frame starts on falling edge of LRCLK,
771
+ * frame delayed by 1.0 SCLKs
772
+ */
773
+ snd_soc_component_update_bits (component ,
774
+ CS42L42_ASP_FRM_CFG ,
775
+ CS42L42_ASP_STP_MASK |
776
+ CS42L42_ASP_5050_MASK |
777
+ CS42L42_ASP_FSD_MASK ,
778
+ CS42L42_ASP_5050_MASK |
779
+ (CS42L42_ASP_FSD_1_0 <<
780
+ CS42L42_ASP_FSD_SHIFT ));
793
781
break ;
794
782
default :
795
783
return - EINVAL ;
@@ -819,6 +807,25 @@ static int cs42l42_set_dai_fmt(struct snd_soc_dai *codec_dai, unsigned int fmt)
819
807
return 0 ;
820
808
}
821
809
810
+ static int cs42l42_dai_startup (struct snd_pcm_substream * substream , struct snd_soc_dai * dai )
811
+ {
812
+ struct snd_soc_component * component = dai -> component ;
813
+ struct cs42l42_private * cs42l42 = snd_soc_component_get_drvdata (component );
814
+
815
+ /*
816
+ * Sample rates < 44.1 kHz would produce an out-of-range SCLK with
817
+ * a standard I2S frame. If the machine driver sets SCLK it must be
818
+ * legal.
819
+ */
820
+ if (cs42l42 -> sclk )
821
+ return 0 ;
822
+
823
+ /* Machine driver has not set a SCLK, limit bottom end to 44.1 kHz */
824
+ return snd_pcm_hw_constraint_minmax (substream -> runtime ,
825
+ SNDRV_PCM_HW_PARAM_RATE ,
826
+ 44100 , 192000 );
827
+ }
828
+
822
829
static int cs42l42_pcm_hw_params (struct snd_pcm_substream * substream ,
823
830
struct snd_pcm_hw_params * params ,
824
831
struct snd_soc_dai * dai )
@@ -832,6 +839,10 @@ static int cs42l42_pcm_hw_params(struct snd_pcm_substream *substream,
832
839
cs42l42 -> srate = params_rate (params );
833
840
cs42l42 -> bclk = snd_soc_params_to_bclk (params );
834
841
842
+ /* I2S frame always has 2 channels even for mono audio */
843
+ if (channels == 1 )
844
+ cs42l42 -> bclk *= 2 ;
845
+
835
846
switch (substream -> stream ) {
836
847
case SNDRV_PCM_STREAM_CAPTURE :
837
848
if (channels == 2 ) {
@@ -855,6 +866,17 @@ static int cs42l42_pcm_hw_params(struct snd_pcm_substream *substream,
855
866
snd_soc_component_update_bits (component , CS42L42_ASP_RX_DAI0_CH2_AP_RES ,
856
867
CS42L42_ASP_RX_CH_AP_MASK |
857
868
CS42L42_ASP_RX_CH_RES_MASK , val );
869
+
870
+ /* Channel B comes from the last active channel */
871
+ snd_soc_component_update_bits (component , CS42L42_SP_RX_CH_SEL ,
872
+ CS42L42_SP_RX_CHB_SEL_MASK ,
873
+ (channels - 1 ) << CS42L42_SP_RX_CHB_SEL_SHIFT );
874
+
875
+ /* Both LRCLK slots must be enabled */
876
+ snd_soc_component_update_bits (component , CS42L42_ASP_RX_DAI0_EN ,
877
+ CS42L42_ASP_RX0_CH_EN_MASK ,
878
+ BIT (CS42L42_ASP_RX0_CH1_SHIFT ) |
879
+ BIT (CS42L42_ASP_RX0_CH2_SHIFT ));
858
880
break ;
859
881
default :
860
882
break ;
@@ -900,13 +922,21 @@ static int cs42l42_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
900
922
*/
901
923
regmap_multi_reg_write (cs42l42 -> regmap , cs42l42_to_osc_seq ,
902
924
ARRAY_SIZE (cs42l42_to_osc_seq ));
925
+
926
+ /* Must disconnect PLL before stopping it */
927
+ snd_soc_component_update_bits (component ,
928
+ CS42L42_MCLK_SRC_SEL ,
929
+ CS42L42_MCLK_SRC_SEL_MASK ,
930
+ 0 );
931
+ usleep_range (100 , 200 );
932
+
903
933
snd_soc_component_update_bits (component , CS42L42_PLL_CTL1 ,
904
934
CS42L42_PLL_START_MASK , 0 );
905
935
}
906
936
} else {
907
937
if (!cs42l42 -> stream_use ) {
908
938
/* SCLK must be running before codec unmute */
909
- if (( cs42l42 -> bclk < 11289600 ) && ( cs42l42 -> sclk < 11289600 ) ) {
939
+ if (pll_ratio_table [ cs42l42 -> pll_config ]. mclk_src_sel ) {
910
940
snd_soc_component_update_bits (component , CS42L42_PLL_CTL1 ,
911
941
CS42L42_PLL_START_MASK , 1 );
912
942
@@ -927,6 +957,12 @@ static int cs42l42_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
927
957
CS42L42_PLL_LOCK_TIMEOUT_US );
928
958
if (ret < 0 )
929
959
dev_warn (component -> dev , "PLL failed to lock: %d\n" , ret );
960
+
961
+ /* PLL must be running to drive glitchless switch logic */
962
+ snd_soc_component_update_bits (component ,
963
+ CS42L42_MCLK_SRC_SEL ,
964
+ CS42L42_MCLK_SRC_SEL_MASK ,
965
+ CS42L42_MCLK_SRC_SEL_MASK );
930
966
}
931
967
932
968
/* Mark SCLK as present, turn off internal oscillator */
@@ -960,8 +996,8 @@ static int cs42l42_mute_stream(struct snd_soc_dai *dai, int mute, int stream)
960
996
SNDRV_PCM_FMTBIT_S24_LE |\
961
997
SNDRV_PCM_FMTBIT_S32_LE )
962
998
963
-
964
999
static const struct snd_soc_dai_ops cs42l42_ops = {
1000
+ .startup = cs42l42_dai_startup ,
965
1001
.hw_params = cs42l42_pcm_hw_params ,
966
1002
.set_fmt = cs42l42_set_dai_fmt ,
967
1003
.set_sysclk = cs42l42_set_sysclk ,
0 commit comments