diff options
author | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2009-04-20 12:15:41 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2009-04-20 13:09:41 -0400 |
commit | 6ea31b9f0a0307e16656af27fcda3160e2a64a1b (patch) | |
tree | 9f7ace6b793a4eff0936dc5ff7d81afb2c0a87c9 /sound/soc/soc-dapm.c | |
parent | cd0f2d4736ae8efabc60e54ecc8f677d0eddce02 (diff) |
ASoC: Factor out DAPM power checks for DACs and ADCs
This also switches us to using a switch statement for the widget type
in dapm_power_widget().
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'sound/soc/soc-dapm.c')
-rw-r--r-- | sound/soc/soc-dapm.c | 81 |
1 files changed, 48 insertions, 33 deletions
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c index 28e6e324ccfb..22522e2d83a4 100644 --- a/sound/soc/soc-dapm.c +++ b/sound/soc/soc-dapm.c | |||
@@ -594,6 +594,34 @@ static int dapm_generic_check_power(struct snd_soc_dapm_widget *w) | |||
594 | return out != 0 && in != 0; | 594 | return out != 0 && in != 0; |
595 | } | 595 | } |
596 | 596 | ||
597 | /* Check to see if an ADC has power */ | ||
598 | static int dapm_adc_check_power(struct snd_soc_dapm_widget *w) | ||
599 | { | ||
600 | int in; | ||
601 | |||
602 | if (w->active) { | ||
603 | in = is_connected_input_ep(w); | ||
604 | dapm_clear_walk(w->codec); | ||
605 | return in != 0; | ||
606 | } else { | ||
607 | return dapm_generic_check_power(w); | ||
608 | } | ||
609 | } | ||
610 | |||
611 | /* Check to see if a DAC has power */ | ||
612 | static int dapm_dac_check_power(struct snd_soc_dapm_widget *w) | ||
613 | { | ||
614 | int out; | ||
615 | |||
616 | if (w->active) { | ||
617 | out = is_connected_output_ep(w); | ||
618 | dapm_clear_walk(w->codec); | ||
619 | return out != 0; | ||
620 | } else { | ||
621 | return dapm_generic_check_power(w); | ||
622 | } | ||
623 | } | ||
624 | |||
597 | /* | 625 | /* |
598 | * Scan a single DAPM widget for a complete audio path and update the | 626 | * Scan a single DAPM widget for a complete audio path and update the |
599 | * power status appropriately. | 627 | * power status appropriately. |
@@ -601,36 +629,23 @@ static int dapm_generic_check_power(struct snd_soc_dapm_widget *w) | |||
601 | static int dapm_power_widget(struct snd_soc_codec *codec, int event, | 629 | static int dapm_power_widget(struct snd_soc_codec *codec, int event, |
602 | struct snd_soc_dapm_widget *w) | 630 | struct snd_soc_dapm_widget *w) |
603 | { | 631 | { |
604 | int in, out, power_change, power, ret; | 632 | int power, ret; |
605 | 633 | ||
606 | /* vmid - no action */ | 634 | /* Work out the new power state */ |
607 | if (w->id == snd_soc_dapm_vmid) | 635 | switch (w->id) { |
636 | case snd_soc_dapm_vmid: | ||
637 | /* No action required */ | ||
608 | return 0; | 638 | return 0; |
609 | 639 | ||
610 | /* active ADC */ | 640 | case snd_soc_dapm_adc: |
611 | if (w->id == snd_soc_dapm_adc && w->active) { | 641 | power = dapm_adc_check_power(w); |
612 | in = is_connected_input_ep(w); | 642 | break; |
613 | dapm_clear_walk(w->codec); | ||
614 | power = (in != 0) ? 1 : 0; | ||
615 | if (power == w->power) | ||
616 | return 0; | ||
617 | w->power = power; | ||
618 | return dapm_generic_apply_power(w); | ||
619 | } | ||
620 | 643 | ||
621 | /* active DAC */ | 644 | case snd_soc_dapm_dac: |
622 | if (w->id == snd_soc_dapm_dac && w->active) { | 645 | power = dapm_dac_check_power(w); |
623 | out = is_connected_output_ep(w); | 646 | break; |
624 | dapm_clear_walk(w->codec); | ||
625 | power = (out != 0) ? 1 : 0; | ||
626 | if (power == w->power) | ||
627 | return 0; | ||
628 | w->power = power; | ||
629 | return dapm_generic_apply_power(w); | ||
630 | } | ||
631 | 647 | ||
632 | /* pre and post event widgets */ | 648 | case snd_soc_dapm_pre: |
633 | if (w->id == snd_soc_dapm_pre) { | ||
634 | if (!w->event) | 649 | if (!w->event) |
635 | return 0; | 650 | return 0; |
636 | 651 | ||
@@ -646,8 +661,8 @@ static int dapm_power_widget(struct snd_soc_codec *codec, int event, | |||
646 | return ret; | 661 | return ret; |
647 | } | 662 | } |
648 | return 0; | 663 | return 0; |
649 | } | 664 | |
650 | if (w->id == snd_soc_dapm_post) { | 665 | case snd_soc_dapm_post: |
651 | if (!w->event) | 666 | if (!w->event) |
652 | return 0; | 667 | return 0; |
653 | 668 | ||
@@ -663,15 +678,15 @@ static int dapm_power_widget(struct snd_soc_codec *codec, int event, | |||
663 | return ret; | 678 | return ret; |
664 | } | 679 | } |
665 | return 0; | 680 | return 0; |
666 | } | ||
667 | 681 | ||
668 | /* all other widgets */ | 682 | default: |
669 | power = dapm_generic_check_power(w); | 683 | power = dapm_generic_check_power(w); |
670 | power_change = (w->power == power) ? 0 : 1; | 684 | break; |
671 | w->power = power; | 685 | } |
672 | 686 | ||
673 | if (!power_change) | 687 | if (w->power == power) |
674 | return 0; | 688 | return 0; |
689 | w->power = power; | ||
675 | 690 | ||
676 | return dapm_generic_apply_power(w); | 691 | return dapm_generic_apply_power(w); |
677 | } | 692 | } |