@@ -3764,53 +3764,122 @@ int snd_soc_dapm_new_controls(struct snd_soc_dapm_context *dapm,
37643764}
37653765EXPORT_SYMBOL_GPL (snd_soc_dapm_new_controls );
37663766
3767- static int snd_soc_dai_link_event (struct snd_soc_dapm_widget * w ,
3768- struct snd_kcontrol * kcontrol , int event )
3767+ static int
3768+ snd_soc_dai_link_event_pre_pmu (struct snd_soc_dapm_widget * w ,
3769+ struct snd_pcm_substream * substream )
37693770{
37703771 struct snd_soc_dapm_path * path ;
37713772 struct snd_soc_dai * source , * sink ;
3772- struct snd_soc_pcm_runtime * rtd = w -> priv ;
3773- const struct snd_soc_pcm_stream * config ;
3774- struct snd_pcm_substream substream ;
3773+ struct snd_soc_pcm_runtime * rtd = substream -> private_data ;
37753774 struct snd_pcm_hw_params * params = NULL ;
3776- struct snd_pcm_runtime * runtime = NULL ;
3775+ const struct snd_soc_pcm_stream * config = NULL ;
37773776 unsigned int fmt ;
3778- int ret = 0 ;
3777+ int ret ;
37793778
3780- config = rtd -> dai_link -> params + rtd -> params_select ;
3779+ params = kzalloc (sizeof (* params ), GFP_KERNEL );
3780+ if (!params )
3781+ return - ENOMEM ;
37813782
3782- if (WARN_ON (!config ) ||
3783- WARN_ON (list_empty (& w -> edges [SND_SOC_DAPM_DIR_OUT ]) ||
3784- list_empty (& w -> edges [SND_SOC_DAPM_DIR_IN ])))
3785- return - EINVAL ;
3783+ substream -> stream = SNDRV_PCM_STREAM_CAPTURE ;
3784+ snd_soc_dapm_widget_for_each_source_path (w , path ) {
3785+ source = path -> source -> priv ;
3786+
3787+ ret = snd_soc_dai_startup (source , substream );
3788+ if (ret < 0 ) {
3789+ dev_err (source -> dev ,
3790+ "ASoC: startup() failed: %d\n" , ret );
3791+ goto out ;
3792+ }
3793+ source -> active ++ ;
3794+ }
3795+
3796+ substream -> stream = SNDRV_PCM_STREAM_PLAYBACK ;
3797+ snd_soc_dapm_widget_for_each_sink_path (w , path ) {
3798+ sink = path -> sink -> priv ;
3799+
3800+ ret = snd_soc_dai_startup (sink , substream );
3801+ if (ret < 0 ) {
3802+ dev_err (sink -> dev ,
3803+ "ASoC: startup() failed: %d\n" , ret );
3804+ goto out ;
3805+ }
3806+ sink -> active ++ ;
3807+ }
3808+
3809+ /*
3810+ * Note: getting the config after .startup() gives a chance to
3811+ * either party on the link to alter the configuration if
3812+ * necessary
3813+ */
3814+ config = rtd -> dai_link -> params + rtd -> params_select ;
3815+ if (WARN_ON (!config )) {
3816+ dev_err (w -> dapm -> dev , "ASoC: link config missing\n" );
3817+ ret = - EINVAL ;
3818+ goto out ;
3819+ }
37863820
37873821 /* Be a little careful as we don't want to overflow the mask array */
37883822 if (config -> formats ) {
37893823 fmt = ffs (config -> formats ) - 1 ;
37903824 } else {
37913825 dev_warn (w -> dapm -> dev , "ASoC: Invalid format %llx specified\n" ,
37923826 config -> formats );
3793- fmt = 0 ;
3794- }
37953827
3796- /* Currently very limited parameter selection */
3797- params = kzalloc (sizeof (* params ), GFP_KERNEL );
3798- if (!params ) {
3799- ret = - ENOMEM ;
3828+ ret = - EINVAL ;
38003829 goto out ;
38013830 }
3802- snd_mask_set (hw_param_mask (params , SNDRV_PCM_HW_PARAM_FORMAT ), fmt );
38033831
3832+ snd_mask_set (hw_param_mask (params , SNDRV_PCM_HW_PARAM_FORMAT ), fmt );
38043833 hw_param_interval (params , SNDRV_PCM_HW_PARAM_RATE )-> min =
38053834 config -> rate_min ;
38063835 hw_param_interval (params , SNDRV_PCM_HW_PARAM_RATE )-> max =
38073836 config -> rate_max ;
3808-
38093837 hw_param_interval (params , SNDRV_PCM_HW_PARAM_CHANNELS )-> min
38103838 = config -> channels_min ;
38113839 hw_param_interval (params , SNDRV_PCM_HW_PARAM_CHANNELS )-> max
38123840 = config -> channels_max ;
38133841
3842+ substream -> stream = SNDRV_PCM_STREAM_CAPTURE ;
3843+ snd_soc_dapm_widget_for_each_source_path (w , path ) {
3844+ source = path -> source -> priv ;
3845+
3846+ ret = snd_soc_dai_hw_params (source , substream , params );
3847+ if (ret < 0 )
3848+ goto out ;
3849+
3850+ dapm_update_dai_unlocked (substream , params , source );
3851+ }
3852+
3853+ substream -> stream = SNDRV_PCM_STREAM_PLAYBACK ;
3854+ snd_soc_dapm_widget_for_each_sink_path (w , path ) {
3855+ sink = path -> sink -> priv ;
3856+
3857+ ret = snd_soc_dai_hw_params (sink , substream , params );
3858+ if (ret < 0 )
3859+ goto out ;
3860+
3861+ dapm_update_dai_unlocked (substream , params , sink );
3862+ }
3863+
3864+ out :
3865+ kfree (params );
3866+ return 0 ;
3867+ }
3868+
3869+ static int snd_soc_dai_link_event (struct snd_soc_dapm_widget * w ,
3870+ struct snd_kcontrol * kcontrol , int event )
3871+ {
3872+ struct snd_soc_dapm_path * path ;
3873+ struct snd_soc_dai * source , * sink ;
3874+ struct snd_soc_pcm_runtime * rtd = w -> priv ;
3875+ struct snd_pcm_substream substream ;
3876+ struct snd_pcm_runtime * runtime = NULL ;
3877+ int ret = 0 ;
3878+
3879+ if (WARN_ON (list_empty (& w -> edges [SND_SOC_DAPM_DIR_OUT ]) ||
3880+ list_empty (& w -> edges [SND_SOC_DAPM_DIR_IN ])))
3881+ return - EINVAL ;
3882+
38143883 memset (& substream , 0 , sizeof (substream ));
38153884
38163885 /* Allocate a dummy snd_pcm_runtime for startup() and other ops() */
@@ -3824,53 +3893,10 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
38243893
38253894 switch (event ) {
38263895 case SND_SOC_DAPM_PRE_PMU :
3827- substream .stream = SNDRV_PCM_STREAM_CAPTURE ;
3828- snd_soc_dapm_widget_for_each_source_path (w , path ) {
3829- source = path -> source -> priv ;
3830-
3831- ret = snd_soc_dai_startup (source , & substream );
3832- if (ret < 0 ) {
3833- dev_err (source -> dev ,
3834- "ASoC: startup() failed: %d\n" , ret );
3835- goto out ;
3836- }
3837- source -> active ++ ;
3838- }
3839-
3840- substream .stream = SNDRV_PCM_STREAM_PLAYBACK ;
3841- snd_soc_dapm_widget_for_each_sink_path (w , path ) {
3842- sink = path -> sink -> priv ;
3843-
3844- ret = snd_soc_dai_startup (sink , & substream );
3845- if (ret < 0 ) {
3846- dev_err (sink -> dev ,
3847- "ASoC: startup() failed: %d\n" , ret );
3848- goto out ;
3849- }
3850- sink -> active ++ ;
3851- }
3852-
3853- substream .stream = SNDRV_PCM_STREAM_CAPTURE ;
3854- snd_soc_dapm_widget_for_each_source_path (w , path ) {
3855- source = path -> source -> priv ;
3856-
3857- ret = snd_soc_dai_hw_params (source , & substream , params );
3858- if (ret < 0 )
3859- goto out ;
3860-
3861- dapm_update_dai_unlocked (& substream , params , source );
3862- }
3863-
3864- substream .stream = SNDRV_PCM_STREAM_PLAYBACK ;
3865- snd_soc_dapm_widget_for_each_sink_path (w , path ) {
3866- sink = path -> sink -> priv ;
3867-
3868- ret = snd_soc_dai_hw_params (sink , & substream , params );
3869- if (ret < 0 )
3870- goto out ;
3896+ ret = snd_soc_dai_link_event_pre_pmu (w , & substream );
3897+ if (ret < 0 )
3898+ goto out ;
38713899
3872- dapm_update_dai_unlocked (& substream , params , sink );
3873- }
38743900 break ;
38753901
38763902 case SND_SOC_DAPM_POST_PMU :
@@ -3932,7 +3958,6 @@ static int snd_soc_dai_link_event(struct snd_soc_dapm_widget *w,
39323958
39333959out :
39343960 kfree (runtime );
3935- kfree (params );
39363961 return ret ;
39373962}
39383963
0 commit comments