ASoC: Configure WM8731 SYSCLK at startup on AT91SAM9G20-EK
[safe/jmp/linux-2.6] / sound / soc / soc-dapm.c
index 3fc791c..5157ec1 100644 (file)
@@ -286,7 +286,7 @@ static int dapm_connect_mixer(struct snd_soc_codec *codec,
 static int dapm_update_bits(struct snd_soc_dapm_widget *widget)
 {
        int change, power;
-       unsigned short old, new;
+       unsigned int old, new;
        struct snd_soc_codec *codec = widget->codec;
 
        /* check for valid widgets */
@@ -786,6 +786,10 @@ static void dapm_seq_run_coalesced(struct snd_soc_codec *codec,
                                pr_err("%s: pre event failed: %d\n",
                                       w->name, ret);
                }
+
+               /* Lower PGA volume to reduce pops */
+               if (w->id == snd_soc_dapm_pga && !w->power)
+                       dapm_set_pga(w, w->power);
        }
 
        if (reg >= 0) {
@@ -797,6 +801,10 @@ static void dapm_seq_run_coalesced(struct snd_soc_codec *codec,
        }
 
        list_for_each_entry(w, pending, power_list) {
+               /* Raise PGA volume to reduce pops */
+               if (w->id == snd_soc_dapm_pga && w->power)
+                       dapm_set_pga(w, w->power);
+
                /* power up post event */
                if (w->power && w->event &&
                    (w->event_flags & SND_SOC_DAPM_POST_PMU)) {
@@ -886,8 +894,6 @@ static void dapm_seq_run(struct snd_soc_codec *codec, struct list_head *list,
                case snd_soc_dapm_line:
                case snd_soc_dapm_spk:
                        /* No register support currently */
-               case snd_soc_dapm_pga:
-                       /* Don't coalsece these yet due to gain ramping */
                        ret = dapm_generic_apply_power(w);
                        break;
 
@@ -921,23 +927,22 @@ 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;
+       LIST_HEAD(up_list);
+       LIST_HEAD(down_list);
        int ret = 0;
        int power;
        int sys_power = 0;
 
-       INIT_LIST_HEAD(&codec->up_list);
-       INIT_LIST_HEAD(&codec->down_list);
-
        /* Check which widgets we need to power and store them in
         * lists indicating if they should be powered up or down.
         */
        list_for_each_entry(w, &codec->dapm_widgets, list) {
                switch (w->id) {
                case snd_soc_dapm_pre:
-                       dapm_seq_insert(w, &codec->down_list, dapm_down_seq);
+                       dapm_seq_insert(w, &down_list, dapm_down_seq);
                        break;
                case snd_soc_dapm_post:
-                       dapm_seq_insert(w, &codec->up_list, dapm_up_seq);
+                       dapm_seq_insert(w, &up_list, dapm_up_seq);
                        break;
 
                default:
@@ -952,11 +957,9 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
                                continue;
 
                        if (power)
-                               dapm_seq_insert(w, &codec->up_list,
-                                               dapm_up_seq);
+                               dapm_seq_insert(w, &up_list, dapm_up_seq);
                        else
-                               dapm_seq_insert(w, &codec->down_list,
-                                               dapm_down_seq);
+                               dapm_seq_insert(w, &down_list, dapm_down_seq);
 
                        w->power = power;
                        break;
@@ -973,10 +976,10 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
        }
 
        /* Power down widgets first; try to avoid amplifying pops. */
-       dapm_seq_run(codec, &codec->down_list, event, dapm_down_seq);
+       dapm_seq_run(codec, &down_list, event, dapm_down_seq);
 
        /* Now power up. */
-       dapm_seq_run(codec, &codec->up_list, event, dapm_up_seq);
+       dapm_seq_run(codec, &up_list, event, dapm_up_seq);
 
        /* If we just powered the last thing off drop to standby bias */
        if (codec->bias_level == SND_SOC_BIAS_PREPARE && !sys_power) {
@@ -1521,7 +1524,7 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
        int max = mc->max;
        unsigned int mask = (1 << fls(max)) - 1;
        unsigned int invert = mc->invert;
-       unsigned short val, val2, val_mask;
+       unsigned int val, val2, val_mask;
        int ret;
 
        val = (ucontrol->value.integer.value[0] & mask);
@@ -1585,7 +1588,7 @@ int snd_soc_dapm_get_enum_double(struct snd_kcontrol *kcontrol,
 {
        struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
        struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
-       unsigned short val, bitmask;
+       unsigned int val, bitmask;
 
        for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
                ;
@@ -1613,8 +1616,8 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
 {
        struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
        struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
-       unsigned short val, mux;
-       unsigned short mask, bitmask;
+       unsigned int val, mux;
+       unsigned int mask, bitmask;
        int ret = 0;
 
        for (bitmask = 1; bitmask < e->max; bitmask <<= 1)
@@ -1672,7 +1675,7 @@ int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
 {
        struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
        struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
-       unsigned short reg_val, val, mux;
+       unsigned int reg_val, val, mux;
 
        reg_val = snd_soc_read(widget->codec, e->reg);
        val = (reg_val >> e->shift_l) & e->mask;
@@ -1712,8 +1715,8 @@ int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
 {
        struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
        struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
-       unsigned short val, mux;
-       unsigned short mask;
+       unsigned int val, mux;
+       unsigned int mask;
        int ret = 0;
 
        if (ucontrol->value.enumerated.item[0] > e->max - 1)
@@ -2029,6 +2032,36 @@ void snd_soc_dapm_free(struct snd_soc_device *socdev)
 }
 EXPORT_SYMBOL_GPL(snd_soc_dapm_free);
 
+/*
+ * snd_soc_dapm_shutdown - callback for system shutdown
+ */
+void snd_soc_dapm_shutdown(struct snd_soc_device *socdev)
+{
+       struct snd_soc_codec *codec = socdev->card->codec;
+       struct snd_soc_dapm_widget *w;
+       LIST_HEAD(down_list);
+       int powerdown = 0;
+
+       list_for_each_entry(w, &codec->dapm_widgets, list) {
+               if (w->power) {
+                       dapm_seq_insert(w, &down_list, dapm_down_seq);
+                       w->power = 0;
+                       powerdown = 1;
+               }
+       }
+
+       /* If there were no widgets to power down we're already in
+        * standby.
+        */
+       if (powerdown) {
+               snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_PREPARE);
+               dapm_seq_run(codec, &down_list, 0, dapm_down_seq);
+               snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_STANDBY);
+       }
+
+       snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_OFF);
+}
+
 /* Module information */
 MODULE_AUTHOR("Liam Girdwood, lrg@slimlogic.co.uk");
 MODULE_DESCRIPTION("Dynamic Audio Power Management core for ALSA SoC");