aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-dapm.c
diff options
context:
space:
mode:
authorMark Brown <broonie@opensource.wolfsonmicro.com>2009-06-07 05:12:52 -0400
committerMark Brown <broonie@opensource.wolfsonmicro.com>2009-06-07 08:03:27 -0400
commit163cac061c97394d4ef9c89efe5921dac937ddb8 (patch)
tree5aa255e94be0f43be371f4ad8a6b271b0ce6457c /sound/soc/soc-dapm.c
parent38357ab2c83631728afa37a783c9b1bd474a0739 (diff)
ASoC: Factor out DAPM sequence execution
Lump the list walk into a single function, and pull in the power application too so we can do some further refactoring. Pure code motion. Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/soc-dapm.c')
-rw-r--r--sound/soc/soc-dapm.c122
1 files changed, 61 insertions, 61 deletions
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 1b38e2195596..257d4f15e00e 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -707,55 +707,6 @@ static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
707 return power; 707 return power;
708} 708}
709 709
710/*
711 * Scan a single DAPM widget for a complete audio path and update the
712 * power status appropriately.
713 */
714static int dapm_power_widget(struct snd_soc_codec *codec, int event,
715 struct snd_soc_dapm_widget *w)
716{
717 int ret;
718
719 switch (w->id) {
720 case snd_soc_dapm_pre:
721 if (!w->event)
722 return 0;
723
724 if (event == SND_SOC_DAPM_STREAM_START) {
725 ret = w->event(w,
726 NULL, SND_SOC_DAPM_PRE_PMU);
727 if (ret < 0)
728 return ret;
729 } else if (event == SND_SOC_DAPM_STREAM_STOP) {
730 ret = w->event(w,
731 NULL, SND_SOC_DAPM_PRE_PMD);
732 if (ret < 0)
733 return ret;
734 }
735 return 0;
736
737 case snd_soc_dapm_post:
738 if (!w->event)
739 return 0;
740
741 if (event == SND_SOC_DAPM_STREAM_START) {
742 ret = w->event(w,
743 NULL, SND_SOC_DAPM_POST_PMU);
744 if (ret < 0)
745 return ret;
746 } else if (event == SND_SOC_DAPM_STREAM_STOP) {
747 ret = w->event(w,
748 NULL, SND_SOC_DAPM_POST_PMD);
749 if (ret < 0)
750 return ret;
751 }
752 return 0;
753
754 default:
755 return dapm_generic_apply_power(w);
756 }
757}
758
759static int dapm_seq_compare(struct snd_soc_dapm_widget *a, 710static int dapm_seq_compare(struct snd_soc_dapm_widget *a,
760 struct snd_soc_dapm_widget *b, 711 struct snd_soc_dapm_widget *b,
761 int sort[]) 712 int sort[])
@@ -782,6 +733,65 @@ static void dapm_seq_insert(struct snd_soc_dapm_widget *new_widget,
782 list_add_tail(&new_widget->power_list, list); 733 list_add_tail(&new_widget->power_list, list);
783} 734}
784 735
736/* Apply a DAPM power sequence */
737static void dapm_seq_run(struct snd_soc_codec *codec, struct list_head *list,
738 int event)
739{
740 struct snd_soc_dapm_widget *w;
741 int ret;
742
743 list_for_each_entry(w, list, power_list) {
744 switch (w->id) {
745 case snd_soc_dapm_pre:
746 if (!w->event)
747 list_for_each_entry_continue(w, list,
748 power_list);
749
750 if (event == SND_SOC_DAPM_STREAM_START) {
751 ret = w->event(w,
752 NULL, SND_SOC_DAPM_PRE_PMU);
753 if (ret < 0)
754 pr_err("PRE widget failed: %d\n",
755 ret);
756 } else if (event == SND_SOC_DAPM_STREAM_STOP) {
757 ret = w->event(w,
758 NULL, SND_SOC_DAPM_PRE_PMD);
759 if (ret < 0)
760 pr_err("PRE widget failed: %d\n",
761 ret);
762 }
763 break;
764
765 case snd_soc_dapm_post:
766 if (!w->event)
767 list_for_each_entry_continue(w, list,
768 power_list);
769
770 if (event == SND_SOC_DAPM_STREAM_START) {
771 ret = w->event(w,
772 NULL, SND_SOC_DAPM_POST_PMU);
773 if (ret < 0)
774 pr_err("POST widget failed: %d\n",
775 ret);
776 } else if (event == SND_SOC_DAPM_STREAM_STOP) {
777 ret = w->event(w,
778 NULL, SND_SOC_DAPM_POST_PMD);
779 if (ret < 0)
780 pr_err("POST widget failed: %d\n",
781 ret);
782 }
783 break;
784
785 default:
786 ret = dapm_generic_apply_power(w);
787 if (ret < 0)
788 pr_err("Failed to apply widget power: %d\n",
789 ret);
790 break;
791 }
792 }
793}
794
785/* 795/*
786 * Scan each dapm widget for complete audio path. 796 * Scan each dapm widget for complete audio path.
787 * A complete path is a route that has valid endpoints i.e.:- 797 * A complete path is a route that has valid endpoints i.e.:-
@@ -847,20 +857,10 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
847 } 857 }
848 858
849 /* Power down widgets first; try to avoid amplifying pops. */ 859 /* Power down widgets first; try to avoid amplifying pops. */
850 list_for_each_entry(w, &codec->down_list, power_list) { 860 dapm_seq_run(codec, &codec->down_list, event);
851 ret = dapm_power_widget(codec, event, w);
852 if (ret != 0)
853 pr_err("Failed to power down %s: %d\n",
854 w->name, ret);
855 }
856 861
857 /* Now power up. */ 862 /* Now power up. */
858 list_for_each_entry(w, &codec->up_list, power_list) { 863 dapm_seq_run(codec, &codec->up_list, event);
859 ret = dapm_power_widget(codec, event, w);
860 if (ret != 0)
861 pr_err("Failed to power up %s: %d\n",
862 w->name, ret);
863 }
864 864
865 /* If we just powered the last thing off drop to standby bias */ 865 /* If we just powered the last thing off drop to standby bias */
866 if (codec->bias_level == SND_SOC_BIAS_PREPARE && !sys_power) { 866 if (codec->bias_level == SND_SOC_BIAS_PREPARE && !sys_power) {