@@ -448,19 +448,6 @@ static const struct snd_soc_dai_ops avs_dai_hda_be_ops = {
448448 .trigger = avs_dai_hda_be_trigger ,
449449};
450450
451- static const unsigned int rates [] = {
452- 8000 , 11025 , 12000 , 16000 ,
453- 22050 , 24000 , 32000 , 44100 ,
454- 48000 , 64000 , 88200 , 96000 ,
455- 128000 , 176400 , 192000 ,
456- };
457-
458- static const struct snd_pcm_hw_constraint_list hw_rates = {
459- .count = ARRAY_SIZE (rates ),
460- .list = rates ,
461- .mask = 0 ,
462- };
463-
464451static int hw_rule_param_size (struct snd_pcm_hw_params * params , struct snd_pcm_hw_rule * rule )
465452{
466453 struct snd_interval * interval = hw_param_interval (params , rule -> var );
@@ -481,40 +468,33 @@ static int hw_rule_param_size(struct snd_pcm_hw_params *params, struct snd_pcm_h
481468 return snd_interval_refine (interval , & to );
482469}
483470
484- static int avs_dai_fe_startup (struct snd_pcm_substream * substream , struct snd_soc_dai * dai )
471+ static int avs_pcm_hw_constraints_init (struct snd_pcm_substream * substream )
485472{
486473 struct snd_pcm_runtime * runtime = substream -> runtime ;
487- struct avs_dma_data * data ;
488- struct hdac_bus * bus ;
489- struct hdac_ext_stream * host_stream ;
474+ static const unsigned int rates [] = {
475+ 8000 , 11025 , 12000 , 16000 ,
476+ 22050 , 24000 , 32000 , 44100 ,
477+ 48000 , 64000 , 88200 , 96000 ,
478+ 128000 , 176400 , 192000 ,
479+ };
480+ static const struct snd_pcm_hw_constraint_list rate_list = {
481+ .count = ARRAY_SIZE (rates ),
482+ .list = rates ,
483+ };
490484 int ret ;
491485
492- ret = avs_dai_startup (substream , dai );
493- if (ret )
494- return ret ;
495-
496- data = snd_soc_dai_get_dma_data (dai , substream );
497- bus = & data -> adev -> base .core ;
498-
499- host_stream = snd_hdac_ext_stream_assign (bus , substream , HDAC_EXT_STREAM_TYPE_HOST );
500- if (!host_stream ) {
501- ret = - EBUSY ;
502- goto err ;
503- }
504-
505- data -> host_stream = host_stream ;
506486 ret = snd_pcm_hw_constraint_integer (runtime , SNDRV_PCM_HW_PARAM_PERIODS );
507487 if (ret < 0 )
508- goto err ;
488+ return ret ;
509489
510- /* avoid wrap-around with wall-clock */
490+ /* Avoid wrap-around with wall-clock. */
511491 ret = snd_pcm_hw_constraint_minmax (runtime , SNDRV_PCM_HW_PARAM_BUFFER_TIME , 20 , 178000000 );
512492 if (ret < 0 )
513- goto err ;
493+ return ret ;
514494
515- ret = snd_pcm_hw_constraint_list (runtime , 0 , SNDRV_PCM_HW_PARAM_RATE , & hw_rates );
495+ ret = snd_pcm_hw_constraint_list (runtime , 0 , SNDRV_PCM_HW_PARAM_RATE , & rate_list );
516496 if (ret < 0 )
517- goto err ;
497+ return ret ;
518498
519499 /* Adjust buffer and period size based on the audio format. */
520500 snd_pcm_hw_rule_add (runtime , 0 , SNDRV_PCM_HW_PARAM_BUFFER_SIZE , hw_rule_param_size , NULL ,
@@ -524,16 +504,40 @@ static int avs_dai_fe_startup(struct snd_pcm_substream *substream, struct snd_so
524504 SNDRV_PCM_HW_PARAM_FORMAT , SNDRV_PCM_HW_PARAM_CHANNELS ,
525505 SNDRV_PCM_HW_PARAM_RATE , -1 );
526506
507+ return ret ;
508+ }
509+
510+ static int avs_dai_fe_startup (struct snd_pcm_substream * substream , struct snd_soc_dai * dai )
511+ {
512+ struct hdac_ext_stream * host_stream ;
513+ struct avs_dma_data * data ;
514+ struct hdac_bus * bus ;
515+ int ret ;
516+
517+ ret = avs_pcm_hw_constraints_init (substream );
518+ if (ret )
519+ return ret ;
520+
521+ ret = avs_dai_startup (substream , dai );
522+ if (ret )
523+ return ret ;
524+
525+ data = snd_soc_dai_get_dma_data (dai , substream );
526+ bus = & data -> adev -> base .core ;
527+
528+ host_stream = snd_hdac_ext_stream_assign (bus , substream , HDAC_EXT_STREAM_TYPE_HOST );
529+ if (!host_stream ) {
530+ avs_dai_shutdown (substream , dai );
531+ return - EBUSY ;
532+ }
533+
534+ data -> host_stream = host_stream ;
527535 snd_pcm_set_sync (substream );
528536
529537 dev_dbg (dai -> dev , "%s fe STARTUP tag %d str %p" ,
530538 __func__ , hdac_stream (host_stream )-> stream_tag , substream );
531539
532540 return 0 ;
533-
534- err :
535- kfree (data );
536- return ret ;
537541}
538542
539543static void avs_dai_fe_shutdown (struct snd_pcm_substream * substream , struct snd_soc_dai * dai )
0 commit comments