ASoC: Update SDP3430 machine driver for snd_soc_card
[safe/jmp/linux-2.6] / sound / soc / soc-dapm.c
index 7bf3c40..a2f1da8 100644 (file)
 /* dapm power sequences - make this per codec in the future */
 static int dapm_up_seq[] = {
        snd_soc_dapm_pre, snd_soc_dapm_micbias, snd_soc_dapm_mic,
-       snd_soc_dapm_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_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
 };
 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_post
+       snd_soc_dapm_micbias, snd_soc_dapm_mux, snd_soc_dapm_value_mux,
+       snd_soc_dapm_post
 };
 
 static int dapm_status = 1;
@@ -134,6 +136,25 @@ static void dapm_set_path_status(struct snd_soc_dapm_widget *w,
                }
        }
        break;
+       case snd_soc_dapm_value_mux: {
+               struct soc_enum *e = (struct soc_enum *)
+                       w->kcontrols[i].private_value;
+               int val, item;
+
+               val = snd_soc_read(w->codec, e->reg);
+               val = (val >> e->shift_l) & e->mask;
+               for (item = 0; item < e->max; item++) {
+                       if (val == e->values[item])
+                               break;
+               }
+
+               p->connect = 0;
+               for (i = 0; i < e->max; i++) {
+                       if (!(strcmp(p->name, e->texts[i])) && item == i)
+                               p->connect = 1;
+               }
+       }
+       break;
        /* does not effect routing - always connected */
        case snd_soc_dapm_pga:
        case snd_soc_dapm_output:
@@ -653,6 +674,7 @@ static void dbg_dump_dapm(struct snd_soc_codec* codec, const char *action)
                case snd_soc_dapm_vmid:
                        continue;
                case snd_soc_dapm_mux:
+               case snd_soc_dapm_value_mux:
                case snd_soc_dapm_output:
                case snd_soc_dapm_input:
                case snd_soc_dapm_switch:
@@ -698,7 +720,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))
@@ -822,14 +845,8 @@ static DEVICE_ATTR(dapm_widget, 0444, dapm_widget_show, NULL);
 
 int snd_soc_dapm_sys_add(struct device *dev)
 {
-       int ret;
-
        if (!dapm_status)
                return 0;
-
-       ret = device_create_file(dev, &dev_attr_dapm_widget);
-       if (ret != 0)
-               return ret;
        return device_create_file(dev, &dev_attr_dapm_widget);
 }
 
@@ -966,6 +983,7 @@ 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)
@@ -1053,6 +1071,7 @@ int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec)
                        dapm_new_mixer(codec, w);
                        break;
                case snd_soc_dapm_mux:
+               case snd_soc_dapm_value_mux:
                        dapm_new_mux(codec, w);
                        break;
                case snd_soc_dapm_adc:
@@ -1083,7 +1102,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
 /**
  * snd_soc_dapm_get_volsw - dapm mixer get callback
  * @kcontrol: mixer control
- * @uinfo: control element information
+ * @ucontrol: control element information
  *
  * Callback to get the value of a dapm mixer control.
  *
@@ -1128,7 +1147,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_get_volsw);
 /**
  * snd_soc_dapm_put_volsw - dapm mixer set callback
  * @kcontrol: mixer control
- * @uinfo: control element information
+ * @ucontrol: control element information
  *
  * Callback to set the value of a dapm mixer control.
  *
@@ -1199,7 +1218,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_put_volsw);
 /**
  * snd_soc_dapm_get_enum_double - dapm enumerated double mixer get callback
  * @kcontrol: mixer control
- * @uinfo: control element information
+ * @ucontrol: control element information
  *
  * Callback to get the value of a dapm enumerated double mixer control.
  *
@@ -1227,7 +1246,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dapm_get_enum_double);
 /**
  * snd_soc_dapm_put_enum_double - dapm enumerated double mixer set callback
  * @kcontrol: mixer control
- * @uinfo: control element information
+ * @ucontrol: control element information
  *
  * Callback to set the value of a dapm enumerated double mixer control.
  *
@@ -1280,6 +1299,103 @@ out:
 EXPORT_SYMBOL_GPL(snd_soc_dapm_put_enum_double);
 
 /**
+ * snd_soc_dapm_get_value_enum_double - dapm semi enumerated double mixer get
+ *                                     callback
+ * @kcontrol: mixer control
+ * @ucontrol: control element information
+ *
+ * Callback to get the value of a dapm semi enumerated double mixer control.
+ *
+ * Semi enumerated mixer: the enumerated items are referred as values. Can be
+ * used for handling bitfield coded enumeration for example.
+ *
+ * Returns 0 for success.
+ */
+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_enum *e = (struct soc_enum *)kcontrol->private_value;
+       unsigned short reg_val, val, mux;
+
+       reg_val = snd_soc_read(widget->codec, e->reg);
+       val = (reg_val >> e->shift_l) & e->mask;
+       for (mux = 0; mux < e->max; mux++) {
+               if (val == e->values[mux])
+                       break;
+       }
+       ucontrol->value.enumerated.item[0] = mux;
+       if (e->shift_l != e->shift_r) {
+               val = (reg_val >> e->shift_r) & e->mask;
+               for (mux = 0; mux < e->max; mux++) {
+                       if (val == e->values[mux])
+                               break;
+               }
+               ucontrol->value.enumerated.item[1] = mux;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_get_value_enum_double);
+
+/**
+ * snd_soc_dapm_put_value_enum_double - dapm semi enumerated double mixer set
+ *                                     callback
+ * @kcontrol: mixer control
+ * @ucontrol: control element information
+ *
+ * Callback to set the value of a dapm semi enumerated double mixer control.
+ *
+ * Semi enumerated mixer: the enumerated items are referred as values. Can be
+ * used for handling bitfield coded enumeration for example.
+ *
+ * Returns 0 for success.
+ */
+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_enum *e = (struct soc_enum *)kcontrol->private_value;
+       unsigned short val, mux;
+       unsigned short mask;
+       int ret = 0;
+
+       if (ucontrol->value.enumerated.item[0] > e->max - 1)
+               return -EINVAL;
+       mux = ucontrol->value.enumerated.item[0];
+       val = e->values[ucontrol->value.enumerated.item[0]] << e->shift_l;
+       mask = e->mask << e->shift_l;
+       if (e->shift_l != e->shift_r) {
+               if (ucontrol->value.enumerated.item[1] > e->max - 1)
+                       return -EINVAL;
+               val |= e->values[ucontrol->value.enumerated.item[1]] << e->shift_r;
+               mask |= e->mask << e->shift_r;
+       }
+
+       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);
+
+out:
+       mutex_unlock(&widget->codec->mutex);
+       return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_put_value_enum_double);
+
+/**
  * snd_soc_dapm_new_control - create new dapm control
  * @codec: audio codec
  * @widget: widget template
@@ -1326,8 +1442,12 @@ int snd_soc_dapm_new_controls(struct snd_soc_codec *codec,
 
        for (i = 0; i < num; i++) {
                ret = snd_soc_dapm_new_control(codec, widget);
-               if (ret < 0)
+               if (ret < 0) {
+                       printk(KERN_ERR
+                              "ASoC: Failed to create DAPM control %s: %d\n",
+                              widget->name, ret);
                        return ret;
+               }
                widget++;
        }
        return 0;
@@ -1408,11 +1528,11 @@ 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_machine *machine = socdev->machine;
+       struct snd_soc_card *card = socdev->card;
        int ret = 0;
 
-       if (machine->set_bias_level)
-               ret = machine->set_bias_level(machine, level);
+       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);
 
@@ -1421,7 +1541,7 @@ int snd_soc_dapm_set_bias_level(struct snd_soc_device *socdev,
 
 /**
  * snd_soc_dapm_enable_pin - enable pin.
- * @snd_soc_codec: SoC codec
+ * @codec: SoC codec
  * @pin: pin name
  *
  * Enables input/output pin and it's parents or children widgets iff there is