Merge branch 'for-2.6.29' into for-2.6.30
[pandora-kernel.git] / sound / soc / soc-dapm.c
index ad0d801..f4a8753 100644 (file)
 static int dapm_up_seq[] = {
        snd_soc_dapm_pre, snd_soc_dapm_micbias, snd_soc_dapm_mic,
        snd_soc_dapm_mux, snd_soc_dapm_value_mux, snd_soc_dapm_dac,
-       snd_soc_dapm_mixer, snd_soc_dapm_pga, snd_soc_dapm_adc, snd_soc_dapm_hp,
-       snd_soc_dapm_spk, snd_soc_dapm_post
+       snd_soc_dapm_mixer, snd_soc_dapm_mixer_named_ctl, snd_soc_dapm_pga,
+       snd_soc_dapm_adc, snd_soc_dapm_hp, snd_soc_dapm_spk, snd_soc_dapm_post
 };
+
 static int dapm_down_seq[] = {
        snd_soc_dapm_pre, snd_soc_dapm_adc, snd_soc_dapm_hp, snd_soc_dapm_spk,
-       snd_soc_dapm_pga, snd_soc_dapm_mixer, snd_soc_dapm_dac, snd_soc_dapm_mic,
-       snd_soc_dapm_micbias, snd_soc_dapm_mux, snd_soc_dapm_value_mux,
-       snd_soc_dapm_post
+       snd_soc_dapm_pga, snd_soc_dapm_mixer_named_ctl, snd_soc_dapm_mixer,
+       snd_soc_dapm_dac, snd_soc_dapm_mic, snd_soc_dapm_micbias,
+       snd_soc_dapm_mux, snd_soc_dapm_value_mux, snd_soc_dapm_post
 };
 
 static int dapm_status = 1;
@@ -101,7 +102,8 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
 {
        switch (w->id) {
        case snd_soc_dapm_switch:
-       case snd_soc_dapm_mixer: {
+       case snd_soc_dapm_mixer:
+       case snd_soc_dapm_mixer_named_ctl: {
                int val;
                struct soc_mixer_control *mc = (struct soc_mixer_control *)
                        w->kcontrols[i].private_value;
@@ -137,7 +139,7 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
        }
        break;
        case snd_soc_dapm_value_mux: {
-               struct soc_value_enum *e = (struct soc_value_enum *)
+               struct soc_enum *e = (struct soc_enum *)
                        w->kcontrols[i].private_value;
                int val, item;
 
@@ -200,30 +202,6 @@ static int dapm_connect_mux(struct snd_soc_codec *codec,
        return -ENODEV;
 }
 
-/* connect value_mux widget to it's interconnecting audio paths */
-static int dapm_connect_value_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,
-       const struct snd_kcontrol_new *kcontrol)
-{
-       struct soc_value_enum *e = (struct soc_value_enum *)
-                       kcontrol->private_value;
-       int i;
-
-       for (i = 0; i < e->max; i++) {
-               if (!(strcmp(control_name, e->texts[i]))) {
-                       list_add(&path->list, &codec->dapm_paths);
-                       list_add(&path->list_sink, &dest->sources);
-                       list_add(&path->list_source, &src->sinks);
-                       path->name = (char *)e->texts[i];
-                       dapm_set_path_status(dest, path, 0);
-                       return 0;
-               }
-       }
-
-       return -ENODEV;
-}
-
 /* connect mixer widget to it's 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,
@@ -347,15 +325,33 @@ static int dapm_new_mixer(struct snd_soc_codec *codec,
                        if (path->name != (char*)w->kcontrols[i].name)
                                continue;
 
-                       /* add dapm control with long name */
-                       name_len = 2 + strlen(w->name)
-                               + strlen(w->kcontrols[i].name);
+                       /* add dapm control with long name.
+                        * for dapm_mixer this is the concatenation of the
+                        * mixer and kcontrol name.
+                        * for dapm_mixer_named_ctl this is simply the
+                        * kcontrol name.
+                        */
+                       name_len = strlen(w->kcontrols[i].name) + 1;
+                       if (w->id == snd_soc_dapm_mixer)
+                               name_len += 1 + strlen(w->name);
+
                        path->long_name = kmalloc(name_len, GFP_KERNEL);
+
                        if (path->long_name == NULL)
                                return -ENOMEM;
 
-                       snprintf(path->long_name, name_len, "%s %s",
-                                w->name, w->kcontrols[i].name);
+                       switch (w->id) {
+                       case snd_soc_dapm_mixer:
+                       default:
+                               snprintf(path->long_name, name_len, "%s %s",
+                                        w->name, w->kcontrols[i].name);
+                       break;
+                       case snd_soc_dapm_mixer_named_ctl:
+                               snprintf(path->long_name, name_len, "%s",
+                                        w->kcontrols[i].name);
+                       break;
+                       }
+
                        path->long_name[name_len - 1] = '\0';
 
                        path->kcontrol = snd_soc_cnew(&w->kcontrols[i], w,
@@ -711,6 +707,7 @@ static void dbg_dump_dapm(struct snd_soc_codec* codec, const char *action)
                case snd_soc_dapm_adc:
                case snd_soc_dapm_pga:
                case snd_soc_dapm_mixer:
+               case snd_soc_dapm_mixer_named_ctl:
                        if (w->name) {
                                in = is_connected_input_ep(w);
                                dapm_clear_walk(w->codec);
@@ -744,7 +741,8 @@ static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
        struct snd_soc_dapm_path *path;
        int found = 0;
 
-       if (widget->id != snd_soc_dapm_mux)
+       if (widget->id != snd_soc_dapm_mux &&
+           widget->id != snd_soc_dapm_value_mux)
                return -ENODEV;
 
        if (!snd_soc_test_bits(widget->codec, e->reg, mask, val))
@@ -774,45 +772,6 @@ static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
        return 0;
 }
 
-/* test and update the power status of a value_mux widget */
-static int dapm_value_mux_update_power(struct snd_soc_dapm_widget *widget,
-                                struct snd_kcontrol *kcontrol, int mask,
-                                int mux, int val, struct soc_value_enum *e)
-{
-       struct snd_soc_dapm_path *path;
-       int found = 0;
-
-       if (widget->id != snd_soc_dapm_value_mux)
-               return -ENODEV;
-
-       if (!snd_soc_test_bits(widget->codec, e->reg, 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)
-                       continue;
-
-               if (!path->name || !e->texts[mux])
-                       continue;
-
-               found = 1;
-               /* we now need to match the string in the enum to the path */
-               if (!(strcmp(path->name, e->texts[mux])))
-                       path->connect = 1; /* new connection */
-               else
-                       path->connect = 0; /* old connection must be
-                                             powered down */
-       }
-
-       if (found) {
-               dapm_power_widgets(widget->codec, SND_SOC_DAPM_STREAM_NOP);
-               dump_dapm(widget->codec, "mux power update");
-       }
-
-       return 0;
-}
-
 /* 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,
@@ -822,6 +781,7 @@ static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
        int found = 0;
 
        if (widget->id != snd_soc_dapm_mixer &&
+           widget->id != snd_soc_dapm_mixer_named_ctl &&
            widget->id != snd_soc_dapm_switch)
                return -ENODEV;
 
@@ -857,7 +817,7 @@ static ssize_t dapm_widget_show(struct device *dev,
        struct device_attribute *attr, char *buf)
 {
        struct snd_soc_device *devdata = dev_get_drvdata(dev);
-       struct snd_soc_codec *codec = devdata->codec;
+       struct snd_soc_codec *codec = devdata->card->codec;
        struct snd_soc_dapm_widget *w;
        int count = 0;
        char *state = "not set";
@@ -875,6 +835,7 @@ static ssize_t dapm_widget_show(struct device *dev,
                case snd_soc_dapm_adc:
                case snd_soc_dapm_pga:
                case snd_soc_dapm_mixer:
+               case snd_soc_dapm_mixer_named_ctl:
                        if (w->name)
                                count += sprintf(buf + count, "%s: %s\n",
                                        w->name, w->power ? "On":"Off");
@@ -938,7 +899,7 @@ static void dapm_free_widgets(struct snd_soc_codec *codec)
 }
 
 static int snd_soc_dapm_set_pin(struct snd_soc_codec *codec,
-       char *pin, int status)
+                               const char *pin, int status)
 {
        struct snd_soc_dapm_widget *w;
 
@@ -1045,19 +1006,15 @@ static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
                path->connect = 1;
                return 0;
        case snd_soc_dapm_mux:
+       case snd_soc_dapm_value_mux:
                ret = dapm_connect_mux(codec, wsource, wsink, path, control,
                        &wsink->kcontrols[0]);
                if (ret != 0)
                        goto err;
                break;
-       case snd_soc_dapm_value_mux:
-               ret = dapm_connect_value_mux(codec, wsource, wsink, path,
-                       control, &wsink->kcontrols[0]);
-               if (ret != 0)
-                       goto err;
-               break;
        case snd_soc_dapm_switch:
        case snd_soc_dapm_mixer:
+       case snd_soc_dapm_mixer_named_ctl:
                ret = dapm_connect_mixer(codec, wsource, wsink, path, control);
                if (ret != 0)
                        goto err;
@@ -1135,6 +1092,7 @@ int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec)
                switch(w->id) {
                case snd_soc_dapm_switch:
                case snd_soc_dapm_mixer:
+               case snd_soc_dapm_mixer_named_ctl:
                        dapm_new_mixer(codec, w);
                        break;
                case snd_soc_dapm_mux:
@@ -1382,8 +1340,7 @@ int snd_soc_dapm_get_value_enum_double(struct snd_kcontrol *kcontrol,
        struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
-       struct soc_value_enum *e = (struct soc_value_enum *)
-                       kcontrol->private_value;
+       struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
        unsigned short reg_val, val, mux;
 
        reg_val = snd_soc_read(widget->codec, e->reg);
@@ -1423,8 +1380,7 @@ int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
        struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_dapm_widget *widget = snd_kcontrol_chip(kcontrol);
-       struct soc_value_enum *e = (struct soc_value_enum *)
-                       kcontrol->private_value;
+       struct soc_enum *e = (struct soc_enum *)kcontrol->private_value;
        unsigned short val, mux;
        unsigned short mask;
        int ret = 0;
@@ -1443,7 +1399,7 @@ int snd_soc_dapm_put_value_enum_double(struct snd_kcontrol *kcontrol,
 
        mutex_lock(&widget->codec->mutex);
        widget->value = val;
-       dapm_value_mux_update_power(widget, kcontrol, mask, mux, val, e);
+       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,
@@ -1596,8 +1552,8 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
 int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev,
                                enum snd_soc_bias_level level)
 {
-       struct snd_soc_codec *codec = socdev->codec;
        struct snd_soc_card *card = socdev->card;
+       struct snd_soc_codec *codec = socdev->card->codec;
        int ret = 0;
 
        if (card->set_bias_level)
@@ -1618,7 +1574,7 @@ int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev,
  * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  * do any widget power switching.
  */
-int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, char *pin)
+int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, const char *pin)
 {
        return snd_soc_dapm_set_pin(codec, pin, 1);
 }
@@ -1633,7 +1589,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
  * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  * do any widget power switching.
  */
-int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, char *pin)
+int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, const char *pin)
 {
        return snd_soc_dapm_set_pin(codec, pin, 0);
 }
@@ -1653,7 +1609,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_disable_pin);
  * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
  * do any widget power switching.
  */
-int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, char *pin)
+int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, const char *pin)
 {
        return snd_soc_dapm_set_pin(codec, pin, 0);
 }
@@ -1668,7 +1624,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_nc_pin);
  *
  * Returns 1 for connected otherwise 0.
  */
-int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, char *pin)
+int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, const char *pin)
 {
        struct snd_soc_dapm_widget *w;
 
@@ -1689,7 +1645,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_get_pin_status);
  */
 void snd_soc_dapm_free(struct snd_soc_device *socdev)
 {
-       struct snd_soc_codec *codec = socdev->codec;
+       struct snd_soc_codec *codec = socdev->card->codec;
 
        snd_soc_dapm_sys_remove(socdev->dev);
        dapm_free_widgets(codec);