ASoC: Push registers out of mixer power decision
[deliverable/linux.git] / sound / soc / soc-dapm.c
index f79711b9fa5b9c58de8c156b30ff0e613bf26664..4cf58911f3b3bb9131dd67f7bae72931c01f30b1 100644 (file)
@@ -524,7 +524,7 @@ static int is_connected_output_ep(struct snd_soc_dapm_widget *widget)
 
                /* connected jack or spk ? */
                if (widget->id == snd_soc_dapm_hp || widget->id == snd_soc_dapm_spk ||
-                       widget->id == snd_soc_dapm_line)
+                   (widget->id == snd_soc_dapm_line && !list_empty(&widget->sources)))
                        return 1;
        }
 
@@ -573,7 +573,8 @@ static int is_connected_input_ep(struct snd_soc_dapm_widget *widget)
                        return 1;
 
                /* connected jack ? */
-               if (widget->id == snd_soc_dapm_mic || widget->id == snd_soc_dapm_line)
+               if (widget->id == snd_soc_dapm_mic ||
+                   (widget->id == snd_soc_dapm_line && !list_empty(&widget->sinks)))
                        return 1;
        }
 
@@ -718,6 +719,10 @@ static int dapm_supply_check_power(struct snd_soc_dapm_widget *w)
 
        /* Check if one of our outputs is connected */
        list_for_each_entry(path, &w->sinks, list_source) {
+               if (path->connected &&
+                   !path->connected(path->source, path->sink))
+                       continue;
+
                if (path->sink && path->sink->power_check &&
                    path->sink->power_check(path->sink)) {
                        power = 1;
@@ -972,9 +977,19 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
                        if (!w->power_check)
                                continue;
 
-                       power = w->power_check(w);
-                       if (power)
-                               sys_power = 1;
+                       /* If we're suspending then pull down all the 
+                        * power. */
+                       switch (event) {
+                       case SND_SOC_DAPM_STREAM_SUSPEND:
+                               power = 0;
+                               break;
+
+                       default:
+                               power = w->power_check(w);
+                               if (power)
+                                       sys_power = 1;
+                               break;
+                       }
 
                        if (w->power == power)
                                continue;
@@ -998,8 +1013,12 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
                case SND_SOC_DAPM_STREAM_RESUME:
                        sys_power = 1;
                        break;
+               case SND_SOC_DAPM_STREAM_SUSPEND:
+                       sys_power = 0;
+                       break;
                case SND_SOC_DAPM_STREAM_NOP:
                        sys_power = codec->bias_level != SND_SOC_BIAS_STANDBY;
+                       break;
                default:
                        break;
                }
@@ -1128,15 +1147,25 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
        out = is_connected_output_ep(w);
        dapm_clear_walk(w->codec);
 
-       ret = snprintf(buf, PAGE_SIZE, "%s: %s  in %d out %d\n",
+       ret = snprintf(buf, PAGE_SIZE, "%s: %s  in %d out %d",
                       w->name, w->power ? "On" : "Off", in, out);
 
+       if (w->reg >= 0)
+               ret += snprintf(buf + ret, PAGE_SIZE - ret,
+                               " - R%d(0x%x) bit %d",
+                               w->reg, w->reg, w->shift);
+
+       ret += snprintf(buf + ret, PAGE_SIZE - ret, "\n");
+
        if (w->sname)
                ret += snprintf(buf + ret, PAGE_SIZE - ret, " stream %s %s\n",
                                w->sname,
                                w->active ? "active" : "inactive");
 
        list_for_each_entry(p, &w->sources, list_sink) {
+               if (p->connected && !p->connected(w, p->sink))
+                       continue;
+
                if (p->connect)
                        ret += snprintf(buf + ret, PAGE_SIZE - ret,
                                        " in  %s %s\n",
@@ -1144,6 +1173,9 @@ static ssize_t dapm_widget_power_read_file(struct file *file,
                                        p->source->name);
        }
        list_for_each_entry(p, &w->sinks, list_source) {
+               if (p->connected && !p->connected(w, p->sink))
+                       continue;
+
                if (p->connect)
                        ret += snprintf(buf + ret, PAGE_SIZE - ret,
                                        " out %s %s\n",
@@ -1191,8 +1223,8 @@ void snd_soc_dapm_debugfs_init(struct snd_soc_codec *codec)
 
 /* test and update the power status of a mux widget */
 static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
-                                struct snd_kcontrol *kcontrol, int mask,
-                                int mux, int val, struct soc_enum *e)
+                                struct snd_kcontrol *kcontrol, int change,
+                                int mux, struct soc_enum *e)
 {
        struct snd_soc_dapm_path *path;
        int found = 0;
@@ -1201,7 +1233,7 @@ static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
            widget->id != snd_soc_dapm_value_mux)
                return -ENODEV;
 
-       if (!snd_soc_test_bits(widget->codec, e->reg, mask, val))
+       if (!change)
                return 0;
 
        /* find dapm widget path assoc with kcontrol */
@@ -1230,8 +1262,7 @@ static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
 
 /* test and update the power status of a mixer or switch widget */
 static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
-                                  struct snd_kcontrol *kcontrol, int reg,
-                                  int val_mask, int val, int invert)
+                                  struct snd_kcontrol *kcontrol, int connect)
 {
        struct snd_soc_dapm_path *path;
        int found = 0;
@@ -1241,9 +1272,6 @@ static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
            widget->id != snd_soc_dapm_switch)
                return -ENODEV;
 
-       if (!snd_soc_test_bits(widget->codec, reg, val_mask, val))
-               return 0;
-
        /* find dapm widget path assoc with kcontrol */
        list_for_each_entry(path, &widget->codec->dapm_paths, list) {
                if (path->kcontrol != kcontrol)
@@ -1251,12 +1279,7 @@ static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
 
                /* found, now check type */
                found = 1;
-               if (val)
-                       /* new connection */
-                       path->connect = invert ? 0:1;
-               else
-                       /* old connection must be powered down */
-                       path->connect = invert ? 1:0;
+               path->connect = connect;
                break;
        }
 
@@ -1386,10 +1409,13 @@ int snd_soc_dapm_sync(struct snd_soc_codec *codec)
 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync);
 
 static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
-       const char *sink, const char *control, const char *source)
+                                 const struct snd_soc_dapm_route *route)
 {
        struct snd_soc_dapm_path *path;
        struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
+       const char *sink = route->sink;
+       const char *control = route->control;
+       const char *source = route->source;
        int ret = 0;
 
        /* find src and dest widgets */
@@ -1413,6 +1439,7 @@ static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
 
        path->source = wsource;
        path->sink = wsink;
+       path->connected = route->connected;
        INIT_LIST_HEAD(&path->list);
        INIT_LIST_HEAD(&path->list_source);
        INIT_LIST_HEAD(&path->list_sink);
@@ -1513,8 +1540,7 @@ int snd_soc_dapm_add_routes(struct snd_soc_codec *codec,
        int i, ret;
 
        for (i = 0; i < num; i++) {
-               ret = snd_soc_dapm_add_route(codec, route->sink,
-                                            route->control, route->source);
+               ret = snd_soc_dapm_add_route(codec, route);
                if (ret < 0) {
                        printk(KERN_ERR "Failed to add route %s->%s\n",
                               route->source,
@@ -1660,6 +1686,7 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
        unsigned int mask = (1 << fls(max)) - 1;
        unsigned int invert = mc->invert;
        unsigned int val, val2, val_mask;
+       int connect;
        int ret;
 
        val = (ucontrol->value.integer.value[0] & mask);
@@ -1686,7 +1713,17 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
                return 1;
        }
 
-       dapm_mixer_update_power(widget, kcontrol, reg, val_mask, val, invert);
+       if (snd_soc_test_bits(widget->codec, reg, val_mask, val)) {
+               if (val)
+                       /* new connection */
+                       connect = invert ? 0:1;
+               else
+                       /* old connection must be powered down */
+                       connect = invert ? 1:0;
+
+               dapm_mixer_update_power(widget, kcontrol, connect);
+       }
+
        if (widget->event) {
                if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
                        ret = widget->event(widget, kcontrol,
@@ -1751,7 +1788,7 @@ 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 int val, mux;
+       unsigned int val, mux, change;
        unsigned int mask, bitmask;
        int ret = 0;
 
@@ -1771,20 +1808,21 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
 
        mutex_lock(&widget->codec->mutex);
        widget->value = val;
-       dapm_mux_update_power(widget, kcontrol, mask, mux, val, e);
-       if (widget->event) {
-               if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
-                       ret = widget->event(widget,
-                               kcontrol, SND_SOC_DAPM_PRE_REG);
-                       if (ret < 0)
-                               goto out;
-               }
-               ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
-               if (widget->event_flags & SND_SOC_DAPM_POST_REG)
-                       ret = widget->event(widget,
-                               kcontrol, SND_SOC_DAPM_POST_REG);
-       } else
-               ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
+       change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
+       dapm_mux_update_power(widget, kcontrol, change, mux, e);
+
+       if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
+               ret = widget->event(widget,
+                                   kcontrol, SND_SOC_DAPM_PRE_REG);
+               if (ret < 0)
+                       goto out;
+       }
+
+       ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
+
+       if (widget->event_flags & SND_SOC_DAPM_POST_REG)
+               ret = widget->event(widget,
+                                   kcontrol, SND_SOC_DAPM_POST_REG);
 
 out:
        mutex_unlock(&widget->codec->mutex);
@@ -1792,6 +1830,54 @@ out:
 }
 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
 
+/**
+ * snd_soc_dapm_get_enum_virt - Get virtual DAPM mux
+ * @kcontrol: mixer control
+ * @ucontrol: control element information
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_dapm_get_enum_virt(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
+
+       ucontrol->value.enumerated.item[0] = widget->value;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_virt);
+
+/**
+ * snd_soc_dapm_put_enum_virt - Set virtual DAPM mux
+ * @kcontrol: mixer control
+ * @ucontrol: control element information
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_dapm_put_enum_virt(struct snd_kcontrol *kcontrol,
+                              struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
+       struct soc_enum *e =
+               (struct soc_enum *)kcontrol->private_value;
+       int change;
+       int ret = 0;
+
+       if (ucontrol->value.enumerated.item[0] >= e->max)
+               return -EINVAL;
+
+       mutex_lock(&widget->codec->mutex);
+
+       change = widget->value != ucontrol->value.enumerated.item[0];
+       widget->value = ucontrol->value.enumerated.item[0];
+       dapm_mux_update_power(widget, kcontrol, change, widget->value, e);
+
+       mutex_unlock(&widget->codec->mutex);
+       return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_virt);
+
 /**
  * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
  *                                     callback
@@ -1850,7 +1936,7 @@ 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 int val, mux;
+       unsigned int val, mux, change;
        unsigned int mask;
        int ret = 0;
 
@@ -1868,20 +1954,21 @@ int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
 
        mutex_lock(&widget->codec->mutex);
        widget->value = val;
-       dapm_mux_update_power(widget, kcontrol, mask, mux, val, e);
-       if (widget->event) {
-               if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
-                       ret = widget->event(widget,
-                               kcontrol, SND_SOC_DAPM_PRE_REG);
-                       if (ret < 0)
-                               goto out;
-               }
-               ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
-               if (widget->event_flags & SND_SOC_DAPM_POST_REG)
-                       ret = widget->event(widget,
-                               kcontrol, SND_SOC_DAPM_POST_REG);
-       } else
-               ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
+       change = snd_soc_test_bits(widget->codec, e->reg, mask, val);
+       dapm_mux_update_power(widget, kcontrol, change, mux, e);
+
+       if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
+               ret = widget->event(widget,
+                                   kcontrol, SND_SOC_DAPM_PRE_REG);
+               if (ret < 0)
+                       goto out;
+       }
+
+       ret = snd_soc_update_bits(widget->codec, e->reg, mask, val);
+
+       if (widget->event_flags & SND_SOC_DAPM_POST_REG)
+               ret = widget->event(widget,
+                                   kcontrol, SND_SOC_DAPM_POST_REG);
 
 out:
        mutex_unlock(&widget->codec->mutex);
@@ -2071,9 +2158,9 @@ int snd_soc_dapm_stream_event(struct snd_soc_codec *codec,
                        }
                }
        }
-       mutex_unlock(&codec->mutex);
 
        dapm_power_widgets(codec, event);
+       mutex_unlock(&codec->mutex);
        dump_dapm(codec, __func__);
        return 0;
 }
This page took 0.03317 seconds and 5 git commands to generate.