Merge branch 'upstream' of git://ftp.linux-mips.org/pub/scm/upstream-linus
[safe/jmp/linux-2.6] / sound / soc / soc-dapm.c
index 04ef841..21c6907 100644 (file)
@@ -12,7 +12,7 @@
  *  Features:
  *    o Changes power status of internal codec blocks depending on the
  *      dynamic configuration of codec internal audio paths and active
- *      DAC's/ADC's.
+ *      DACs/ADCs.
  *    o Platform power domain - can support external components i.e. amps and
  *      mic/meadphone insertion events.
  *    o Automatic Mic Bias support
@@ -67,10 +67,6 @@ static int dapm_down_seq[] = {
        snd_soc_dapm_post
 };
 
-static int dapm_status = 1;
-module_param(dapm_status, int, 0);
-MODULE_PARM_DESC(dapm_status, "enable DPM sysfs entries");
-
 static void pop_wait(u32 pop_time)
 {
        if (pop_time)
@@ -98,6 +94,48 @@ static inline struct snd_soc_dapm_widget *dapm_cnew_widget(
        return kmemdup(_widget, sizeof(*_widget), GFP_KERNEL);
 }
 
+/**
+ * snd_soc_dapm_set_bias_level - set the bias level for the system
+ * @socdev: audio device
+ * @level: level to configure
+ *
+ * Configure the bias (power) levels for the SoC audio device.
+ *
+ * Returns 0 for success else error.
+ */
+static int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev,
+                                      enum snd_soc_bias_level level)
+{
+       struct snd_soc_card *card = socdev->card;
+       struct snd_soc_codec *codec = socdev->card->codec;
+       int ret = 0;
+
+       switch (level) {
+       case SND_SOC_BIAS_ON:
+               dev_dbg(socdev->dev, "Setting full bias\n");
+               break;
+       case SND_SOC_BIAS_PREPARE:
+               dev_dbg(socdev->dev, "Setting bias prepare\n");
+               break;
+       case SND_SOC_BIAS_STANDBY:
+               dev_dbg(socdev->dev, "Setting standby bias\n");
+               break;
+       case SND_SOC_BIAS_OFF:
+               dev_dbg(socdev->dev, "Setting bias off\n");
+               break;
+       default:
+               dev_err(socdev->dev, "Setting invalid bias %d\n", level);
+               return -EINVAL;
+       }
+
+       if (card->set_bias_level)
+               ret = card->set_bias_level(card, level);
+       if (ret == 0 && codec->set_bias_level)
+               ret = codec->set_bias_level(codec, level);
+
+       return ret;
+}
+
 /* set up initial codec paths */
 static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
        struct snd_soc_dapm_path *p, int i)
@@ -182,7 +220,7 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
        }
 }
 
-/* connect mux widget to it's interconnecting audio paths */
+/* connect mux widget to its interconnecting audio paths */
 static int dapm_connect_mux(struct snd_soc_codec *codec,
        struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
        struct snd_soc_dapm_path *path, const char *control_name,
@@ -205,7 +243,7 @@ static int dapm_connect_mux(struct snd_soc_codec *codec,
        return -ENODEV;
 }
 
-/* connect mixer widget to it's interconnecting audio paths */
+/* connect mixer widget to its interconnecting audio paths */
 static int dapm_connect_mixer(struct snd_soc_codec *codec,
        struct snd_soc_dapm_widget *src, struct snd_soc_dapm_widget *dest,
        struct snd_soc_dapm_path *path, const char *control_name)
@@ -711,9 +749,11 @@ static int dapm_power_widget(struct snd_soc_codec *codec, int event,
  */
 static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
 {
+       struct snd_soc_device *socdev = codec->socdev;
        struct snd_soc_dapm_widget *w;
        int ret = 0;
        int i, power;
+       int sys_power = 0;
 
        INIT_LIST_HEAD(&codec->up_list);
        INIT_LIST_HEAD(&codec->down_list);
@@ -735,6 +775,9 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
                                continue;
 
                        power = w->power_check(w);
+                       if (power)
+                               sys_power = 1;
+
                        if (w->power == power)
                                continue;
 
@@ -749,6 +792,15 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
                }
        }
 
+       /* If we're changing to all on or all off then prepare */
+       if ((sys_power && codec->bias_level == SND_SOC_BIAS_STANDBY) ||
+           (!sys_power && codec->bias_level == SND_SOC_BIAS_ON)) {
+               ret = snd_soc_dapm_set_bias_level(socdev,
+                                                 SND_SOC_BIAS_PREPARE);
+               if (ret != 0)
+                       pr_err("Failed to prepare bias: %d\n", ret);
+       }
+
        /* Power down widgets first; try to avoid amplifying pops. */
        for (i = 0; i < ARRAY_SIZE(dapm_down_seq); i++) {
                list_for_each_entry(w, &codec->down_list, power_list) {
@@ -777,6 +829,22 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
                }
        }
 
+       /* If we just powered the last thing off drop to standby bias */
+       if (codec->bias_level == SND_SOC_BIAS_PREPARE && !sys_power) {
+               ret = snd_soc_dapm_set_bias_level(socdev,
+                                                 SND_SOC_BIAS_STANDBY);
+               if (ret != 0)
+                       pr_err("Failed to apply standby bias: %d\n", ret);
+       }
+
+       /* If we just powered up then move to active bias */
+       if (codec->bias_level == SND_SOC_BIAS_PREPARE && sys_power) {
+               ret = snd_soc_dapm_set_bias_level(socdev,
+                                                 SND_SOC_BIAS_ON);
+               if (ret != 0)
+                       pr_err("Failed to apply active bias: %d\n", ret);
+       }
+
        return 0;
 }
 
@@ -974,16 +1042,12 @@ static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
 
 int snd_soc_dapm_sys_add(struct device *dev)
 {
-       if (!dapm_status)
-               return 0;
        return device_create_file(dev, &dev_attr_dapm_widget);
 }
 
 static void snd_soc_dapm_sys_remove(struct device *dev)
 {
-       if (dapm_status) {
-               device_remove_file(dev, &dev_attr_dapm_widget);
-       }
+       device_remove_file(dev, &dev_attr_dapm_widget);
 }
 
 /* free all dapm widgets and resources */
@@ -1729,35 +1793,11 @@ int snd_soc_dapm_stream_event(struct snd_soc_codec *codec,
 EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
 
 /**
- * snd_soc_dapm_set_bias_level - set the bias level for the system
- * @socdev: audio device
- * @level: level to configure
- *
- * Configure the bias (power) levels for the SoC audio device.
- *
- * Returns 0 for success else error.
- */
-int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev,
-                               enum snd_soc_bias_level level)
-{
-       struct snd_soc_card *card = socdev->card;
-       struct snd_soc_codec *codec = socdev->card->codec;
-       int ret = 0;
-
-       if (card->set_bias_level)
-               ret = card->set_bias_level(card, level);
-       if (ret == 0 && codec->set_bias_level)
-               ret = codec->set_bias_level(codec, level);
-
-       return ret;
-}
-
-/**
  * snd_soc_dapm_enable_pin - enable pin.
  * @codec: SoC codec
  * @pin: pin name
  *
- * Enables input/output pin and it's parents or children widgets iff there is
+ * Enables input/output pin and its parents or children widgets iff there is
  * a valid audio route and active audio stream.
  * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  * do any widget power switching.
@@ -1773,7 +1813,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
  * @codec: SoC codec
  * @pin: pin name
  *
- * Disables input/output pin and it's parents or children widgets.
+ * Disables input/output pin and its parents or children widgets.
  * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  * do any widget power switching.
  */