@@ -80,6 +80,8 @@ struct wm8994_priv {
8080 int dac_rates [2 ];
8181 int lrclk_shared [2 ];
8282
83+ int mbc_ena [3 ];
84+
8385 /* Platform dependant DRC configuration */
8486 const char * * drc_texts ;
8587 int drc_cfg [WM8994_NUM_DRC ];
@@ -137,6 +139,7 @@ static int wm8994_volatile(unsigned int reg)
137139 case WM8994_RATE_STATUS :
138140 case WM8994_LDO_1 :
139141 case WM8994_LDO_2 :
142+ case WM8958_DSP2_EXECCONTROL :
140143 return 1 ;
141144 default :
142145 return 0 ;
@@ -520,6 +523,168 @@ static const struct soc_enum aif2dacl_src =
520523static const struct soc_enum aif2dacr_src =
521524 SOC_ENUM_SINGLE (WM8994_AIF2_CONTROL_2 , 14 , 2 , aif_chan_src_text );
522525
526+ static void wm8958_mbc_apply (struct snd_soc_codec * codec , int mbc , int start )
527+ {
528+ struct wm8994_priv * wm8994 = snd_soc_codec_get_drvdata (codec );
529+ int pwr_reg = snd_soc_read (codec , WM8994_POWER_MANAGEMENT_5 );
530+ int ena , reg , aif ;
531+
532+ switch (mbc ) {
533+ case 0 :
534+ pwr_reg &= (WM8994_AIF1DAC1L_ENA | WM8994_AIF1DAC1R_ENA );
535+ aif = 0 ;
536+ break ;
537+ case 1 :
538+ pwr_reg &= (WM8994_AIF1DAC2L_ENA | WM8994_AIF1DAC2R_ENA );
539+ aif = 0 ;
540+ break ;
541+ case 2 :
542+ pwr_reg &= (WM8994_AIF2DACL_ENA | WM8994_AIF2DACR_ENA );
543+ aif = 1 ;
544+ break ;
545+ default :
546+ BUG ();
547+ return ;
548+ }
549+
550+ /* We can only enable the MBC if the AIF is enabled and we
551+ * want it to be enabled. */
552+ ena = pwr_reg && wm8994 -> mbc_ena [mbc ];
553+
554+ reg = snd_soc_read (codec , WM8958_DSP2_PROGRAM );
555+
556+ dev_dbg (codec -> dev , "MBC %d startup: %d, power: %x, DSP: %x\n" ,
557+ mbc , start , pwr_reg , reg );
558+
559+ if (start && ena ) {
560+ /* If the DSP is already running then noop */
561+ if (reg & WM8958_DSP2_ENA )
562+ return ;
563+
564+ /* Switch the clock over to the appropriate AIF */
565+ snd_soc_update_bits (codec , WM8994_CLOCKING_1 ,
566+ WM8958_DSP2CLK_SRC | WM8958_DSP2CLK_ENA ,
567+ aif << WM8958_DSP2CLK_SRC_SHIFT |
568+ WM8958_DSP2CLK_ENA );
569+
570+ snd_soc_update_bits (codec , WM8958_DSP2_PROGRAM ,
571+ WM8958_DSP2_ENA , WM8958_DSP2_ENA );
572+
573+ /* TODO: Apply any user specified MBC settings */
574+
575+ /* Run the DSP */
576+ snd_soc_write (codec , WM8958_DSP2_EXECCONTROL ,
577+ WM8958_DSP2_RUNR );
578+
579+ /* And we're off! */
580+ snd_soc_update_bits (codec , WM8958_DSP2_CONFIG ,
581+ WM8958_MBC_ENA | WM8958_MBC_SEL_MASK ,
582+ mbc << WM8958_MBC_SEL_SHIFT |
583+ WM8958_MBC_ENA );
584+ } else {
585+ /* If the DSP is already stopped then noop */
586+ if (!(reg & WM8958_DSP2_ENA ))
587+ return ;
588+
589+ snd_soc_update_bits (codec , WM8958_DSP2_CONFIG ,
590+ WM8958_MBC_ENA , 0 );
591+ snd_soc_update_bits (codec , WM8958_DSP2_PROGRAM ,
592+ WM8958_DSP2_ENA , 0 );
593+ snd_soc_update_bits (codec , WM8994_CLOCKING_1 ,
594+ WM8958_DSP2CLK_ENA , 0 );
595+ }
596+ }
597+
598+ static int wm8958_aif_ev (struct snd_soc_dapm_widget * w ,
599+ struct snd_kcontrol * kcontrol , int event )
600+ {
601+ struct snd_soc_codec * codec = w -> codec ;
602+ int mbc ;
603+
604+ switch (w -> shift ) {
605+ case 13 :
606+ case 12 :
607+ mbc = 2 ;
608+ break ;
609+ case 11 :
610+ case 10 :
611+ mbc = 1 ;
612+ break ;
613+ case 9 :
614+ case 8 :
615+ mbc = 0 ;
616+ break ;
617+ default :
618+ BUG ();
619+ return - EINVAL ;
620+ }
621+
622+ switch (event ) {
623+ case SND_SOC_DAPM_POST_PMU :
624+ wm8958_mbc_apply (codec , mbc , 1 );
625+ break ;
626+ case SND_SOC_DAPM_POST_PMD :
627+ wm8958_mbc_apply (codec , mbc , 0 );
628+ break ;
629+ }
630+
631+ return 0 ;
632+ }
633+
634+ static int wm8958_mbc_info (struct snd_kcontrol * kcontrol ,
635+ struct snd_ctl_elem_info * uinfo )
636+ {
637+ uinfo -> type = SNDRV_CTL_ELEM_TYPE_BOOLEAN ;
638+ uinfo -> count = 1 ;
639+ uinfo -> value .integer .min = 0 ;
640+ uinfo -> value .integer .max = 1 ;
641+ return 0 ;
642+ }
643+
644+ static int wm8958_mbc_get (struct snd_kcontrol * kcontrol ,
645+ struct snd_ctl_elem_value * ucontrol )
646+ {
647+ int mbc = kcontrol -> private_value ;
648+ struct snd_soc_codec * codec = snd_kcontrol_chip (kcontrol );
649+ struct wm8994_priv * wm8994 = snd_soc_codec_get_drvdata (codec );
650+
651+ ucontrol -> value .integer .value [0 ] = wm8994 -> mbc_ena [mbc ];
652+
653+ return 0 ;
654+ }
655+
656+ static int wm8958_mbc_put (struct snd_kcontrol * kcontrol ,
657+ struct snd_ctl_elem_value * ucontrol )
658+ {
659+ int mbc = kcontrol -> private_value ;
660+ int i ;
661+ struct snd_soc_codec * codec = snd_kcontrol_chip (kcontrol );
662+ struct wm8994_priv * wm8994 = snd_soc_codec_get_drvdata (codec );
663+
664+ if (ucontrol -> value .integer .value [0 ] > 1 )
665+ return - EINVAL ;
666+
667+ for (i = 0 ; i < ARRAY_SIZE (wm8994 -> mbc_ena ); i ++ ) {
668+ if (mbc != i && wm8994 -> mbc_ena [i ]) {
669+ dev_dbg (codec -> dev , "MBC %d active already\n" , mbc );
670+ return - EBUSY ;
671+ }
672+ }
673+
674+ wm8994 -> mbc_ena [mbc ] = ucontrol -> value .integer .value [0 ];
675+
676+ wm8958_mbc_apply (codec , mbc , wm8994 -> mbc_ena [mbc ]);
677+
678+ return 0 ;
679+ }
680+
681+ #define WM8958_MBC_SWITCH (xname , xval ) {\
682+ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = (xname), \
683+ .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,\
684+ .info = wm8958_mbc_info, \
685+ .get = wm8958_mbc_get, .put = wm8958_mbc_put, \
686+ .private_value = xval }
687+
523688static const struct snd_kcontrol_new wm8994_snd_controls [] = {
524689SOC_DOUBLE_R_TLV ("AIF1ADC1 Volume" , WM8994_AIF1_ADC1_LEFT_VOLUME ,
525690 WM8994_AIF1_ADC1_RIGHT_VOLUME ,
@@ -649,6 +814,9 @@ SOC_SINGLE_TLV("AIF2 EQ5 Volume", WM8994_AIF2_EQ_GAINS_2, 6, 31, 0,
649814
650815static const struct snd_kcontrol_new wm8958_snd_controls [] = {
651816SOC_SINGLE_TLV ("AIF3 Boost Volume" , WM8958_AIF3_CONTROL_2 , 10 , 3 , 0 , aif_tlv ),
817+ WM8958_MBC_SWITCH ("AIF1DAC1 MBC Switch" , 0 ),
818+ WM8958_MBC_SWITCH ("AIF1DAC2 MBC Switch" , 1 ),
819+ WM8958_MBC_SWITCH ("AIF2DAC MBC Switch" , 2 ),
652820};
653821
654822static int clk_sys_event (struct snd_soc_dapm_widget * w ,
@@ -1018,19 +1186,23 @@ SND_SOC_DAPM_AIF_OUT("AIF1ADC1L", "AIF1 Capture",
10181186 0 , WM8994_POWER_MANAGEMENT_4 , 9 , 0 ),
10191187SND_SOC_DAPM_AIF_OUT ("AIF1ADC1R" , "AIF1 Capture" ,
10201188 0 , WM8994_POWER_MANAGEMENT_4 , 8 , 0 ),
1021- SND_SOC_DAPM_AIF_IN ("AIF1DAC1L" , NULL , 0 ,
1022- WM8994_POWER_MANAGEMENT_5 , 9 , 0 ),
1023- SND_SOC_DAPM_AIF_IN ("AIF1DAC1R" , NULL , 0 ,
1024- WM8994_POWER_MANAGEMENT_5 , 8 , 0 ),
1189+ SND_SOC_DAPM_AIF_IN_E ("AIF1DAC1L" , NULL , 0 ,
1190+ WM8994_POWER_MANAGEMENT_5 , 9 , 0 , wm8958_aif_ev ,
1191+ SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD ),
1192+ SND_SOC_DAPM_AIF_IN_E ("AIF1DAC1R" , NULL , 0 ,
1193+ WM8994_POWER_MANAGEMENT_5 , 8 , 0 , wm8958_aif_ev ,
1194+ SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD ),
10251195
10261196SND_SOC_DAPM_AIF_OUT ("AIF1ADC2L" , "AIF1 Capture" ,
10271197 0 , WM8994_POWER_MANAGEMENT_4 , 11 , 0 ),
10281198SND_SOC_DAPM_AIF_OUT ("AIF1ADC2R" , "AIF1 Capture" ,
10291199 0 , WM8994_POWER_MANAGEMENT_4 , 10 , 0 ),
1030- SND_SOC_DAPM_AIF_IN ("AIF1DAC2L" , NULL , 0 ,
1031- WM8994_POWER_MANAGEMENT_5 , 11 , 0 ),
1032- SND_SOC_DAPM_AIF_IN ("AIF1DAC2R" , NULL , 0 ,
1033- WM8994_POWER_MANAGEMENT_5 , 10 , 0 ),
1200+ SND_SOC_DAPM_AIF_IN_E ("AIF1DAC2L" , NULL , 0 ,
1201+ WM8994_POWER_MANAGEMENT_5 , 11 , 0 , wm8958_aif_ev ,
1202+ SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD ),
1203+ SND_SOC_DAPM_AIF_IN_E ("AIF1DAC2R" , NULL , 0 ,
1204+ WM8994_POWER_MANAGEMENT_5 , 10 , 0 , wm8958_aif_ev ,
1205+ SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD ),
10341206
10351207SND_SOC_DAPM_MIXER ("AIF1ADC1L Mixer" , SND_SOC_NOPM , 0 , 0 ,
10361208 aif1adc1l_mix , ARRAY_SIZE (aif1adc1l_mix )),
@@ -1059,10 +1231,12 @@ SND_SOC_DAPM_AIF_OUT("AIF2ADCL", NULL, 0,
10591231 WM8994_POWER_MANAGEMENT_4 , 13 , 0 ),
10601232SND_SOC_DAPM_AIF_OUT ("AIF2ADCR" , NULL , 0 ,
10611233 WM8994_POWER_MANAGEMENT_4 , 12 , 0 ),
1062- SND_SOC_DAPM_AIF_IN ("AIF2DACL" , NULL , 0 ,
1063- WM8994_POWER_MANAGEMENT_5 , 13 , 0 ),
1064- SND_SOC_DAPM_AIF_IN ("AIF2DACR" , NULL , 0 ,
1065- WM8994_POWER_MANAGEMENT_5 , 12 , 0 ),
1234+ SND_SOC_DAPM_AIF_IN_E ("AIF2DACL" , NULL , 0 ,
1235+ WM8994_POWER_MANAGEMENT_5 , 13 , 0 , wm8958_aif_ev ,
1236+ SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD ),
1237+ SND_SOC_DAPM_AIF_IN_E ("AIF2DACR" , NULL , 0 ,
1238+ WM8994_POWER_MANAGEMENT_5 , 12 , 0 , wm8958_aif_ev ,
1239+ SND_SOC_DAPM_POST_PMU | SND_SOC_DAPM_PRE_PMD ),
10661240
10671241SND_SOC_DAPM_AIF_IN ("AIF1DACDAT" , "AIF1 Playback" , 0 , SND_SOC_NOPM , 0 , 0 ),
10681242SND_SOC_DAPM_AIF_IN ("AIF2DACDAT" , "AIF2 Playback" , 0 , SND_SOC_NOPM , 0 , 0 ),
0 commit comments