]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - sound/soc/soc-dapm.c
[ALSA] soc - neo1973_wm8753 - Convert to bulk DAPM registration APIs
[linux-2.6-omap-h63xx.git] / sound / soc / soc-dapm.c
index b3193e687db7d757c4faf9a25c39002aefaed4b2..1ef6d94b83572422997e5b5d572ff7e834fbdaec 100644 (file)
@@ -24,7 +24,7 @@
  *    o Automatic Mic Bias support
  *    o Jack insertion power event initiation - e.g. hp insertion will enable
  *      sinks, dacs, etc
- *    o Delayed powerdown of audio susbsytem to reduce pops between a quick
+ *    o Delayed powerdown of audio susbsystem to reduce pops between a quick
  *      device reopen.
  *
  *  Todo:
@@ -43,7 +43,6 @@
 #include <linux/bitops.h>
 #include <linux/platform_device.h>
 #include <linux/jiffies.h>
-#include <sound/driver.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
@@ -227,7 +226,7 @@ static int dapm_update_bits(struct snd_soc_dapm_widget *widget)
                snd_soc_write(codec, widget->reg, new);
                pop_wait(POP_TIME);
        }
-       dbg("reg old %x new %x change %d\n", old, new, change);
+       dbg("reg %x old %x new %x change %d\n", widget->reg, old, new, change);
        return change;
 }
 
@@ -524,11 +523,13 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
                                        continue;
 
                                if (event == SND_SOC_DAPM_STREAM_START) {
-                                       ret = w->event(w, SND_SOC_DAPM_PRE_PMU);
+                                       ret = w->event(w,
+                                               NULL, SND_SOC_DAPM_PRE_PMU);
                                        if (ret < 0)
                                                return ret;
                                } else if (event == SND_SOC_DAPM_STREAM_STOP) {
-                                       ret = w->event(w, SND_SOC_DAPM_PRE_PMD);
+                                       ret = w->event(w,
+                                               NULL, SND_SOC_DAPM_PRE_PMD);
                                        if (ret < 0)
                                                return ret;
                                }
@@ -539,11 +540,13 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
                                        continue;
 
                                if (event == SND_SOC_DAPM_STREAM_START) {
-                                       ret = w->event(w, SND_SOC_DAPM_POST_PMU);
+                                       ret = w->event(w,
+                                               NULL, SND_SOC_DAPM_POST_PMU);
                                        if (ret < 0)
                                                return ret;
                                } else if (event == SND_SOC_DAPM_STREAM_STOP) {
-                                       ret = w->event(w, SND_SOC_DAPM_POST_PMD);
+                                       ret = w->event(w,
+                                               NULL, SND_SOC_DAPM_POST_PMD);
                                        if (ret < 0)
                                                return ret;
                                }
@@ -567,26 +570,30 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
                                        if (power) {
                                                /* power up event */
                                                if (w->event_flags & SND_SOC_DAPM_PRE_PMU) {
-                                                       ret = w->event(w, SND_SOC_DAPM_PRE_PMU);
+                                                       ret = w->event(w,
+                                                               NULL, SND_SOC_DAPM_PRE_PMU);
                                                        if (ret < 0)
                                                                return ret;
                                                }
                                                dapm_update_bits(w);
                                                if (w->event_flags & SND_SOC_DAPM_POST_PMU){
-                                                       ret = w->event(w, SND_SOC_DAPM_POST_PMU);
+                                                       ret = w->event(w,
+                                                               NULL, SND_SOC_DAPM_POST_PMU);
                                                        if (ret < 0)
                                                                return ret;
                                                }
                                        } else {
                                                /* power down event */
                                                if (w->event_flags & SND_SOC_DAPM_PRE_PMD) {
-                                                       ret = w->event(w, SND_SOC_DAPM_PRE_PMD);
+                                                       ret = w->event(w,
+                                                               NULL, SND_SOC_DAPM_PRE_PMD);
                                                        if (ret < 0)
                                                                return ret;
                                                }
                                                dapm_update_bits(w);
                                                if (w->event_flags & SND_SOC_DAPM_POST_PMD) {
-                                                       ret = w->event(w, SND_SOC_DAPM_POST_PMD);
+                                                       ret = w->event(w,
+                                                               NULL, SND_SOC_DAPM_POST_PMD);
                                                        if (ret < 0)
                                                                return ret;
                                                }
@@ -692,7 +699,7 @@ static int dapm_mux_update_power(struct snd_soc_dapm_widget *widget,
        return 0;
 }
 
-/* test and update the power status of a mixer 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)
@@ -700,7 +707,8 @@ static int dapm_mixer_update_power(struct snd_soc_dapm_widget *widget,
        struct snd_soc_dapm_path *path;
        int found = 0;
 
-       if (widget->id != snd_soc_dapm_mixer)
+       if (widget->id != snd_soc_dapm_mixer &&
+           widget->id != snd_soc_dapm_switch)
                return -ENODEV;
 
        if (!snd_soc_test_bits(widget->codec, reg, val_mask, val))
@@ -833,21 +841,8 @@ int snd_soc_dapm_sync_endpoints(struct snd_soc_codec *codec)
 }
 EXPORT_SYMBOL_GPL(snd_soc_dapm_sync_endpoints);
 
-/**
- * snd_soc_dapm_connect_input - connect dapm widgets
- * @codec: audio codec
- * @sink: name of target widget
- * @control: mixer control name
- * @source: name of source name
- *
- * Connects 2 dapm widgets together via a named audio path. The sink is
- * the widget receiving the audio signal, whilst the source is the sender
- * of the audio signal.
- *
- * Returns 0 for success else error.
- */
-int snd_soc_dapm_connect_input(struct snd_soc_codec *codec, const char *sink,
-       const char * control, const char *source)
+static int snd_soc_dapm_add_route(struct snd_soc_codec *codec,
+       const char *sink, const char *control, const char *source)
 {
        struct snd_soc_dapm_path *path;
        struct snd_soc_dapm_widget *wsource = NULL, *wsink = NULL, *w;
@@ -949,8 +944,63 @@ err:
        kfree(path);
        return ret;
 }
+
+/**
+ * snd_soc_dapm_connect_input - connect dapm widgets
+ * @codec: audio codec
+ * @sink: name of target widget
+ * @control: mixer control name
+ * @source: name of source name
+ *
+ * Connects 2 dapm widgets together via a named audio path. The sink is
+ * the widget receiving the audio signal, whilst the source is the sender
+ * of the audio signal.
+ *
+ * This function has been deprecated in favour of snd_soc_dapm_add_routes().
+ *
+ * Returns 0 for success else error.
+ */
+int snd_soc_dapm_connect_input(struct snd_soc_codec *codec, const char *sink,
+       const char *control, const char *source)
+{
+       return snd_soc_dapm_add_route(codec, sink, control, source);
+}
 EXPORT_SYMBOL_GPL(snd_soc_dapm_connect_input);
 
+/**
+ * snd_soc_dapm_add_routes - Add routes between DAPM widgets
+ * @codec: codec
+ * @route: audio routes
+ * @num: number of routes
+ *
+ * Connects 2 dapm widgets together via a named audio path. The sink is
+ * the widget receiving the audio signal, whilst the source is the sender
+ * of the audio signal.
+ *
+ * Returns 0 for success else error. On error all resources can be freed
+ * with a call to snd_soc_card_free().
+ */
+int snd_soc_dapm_add_routes(struct snd_soc_codec *codec,
+                           const struct snd_soc_dapm_route *route, int num)
+{
+       int i, ret;
+
+       for (i = 0; i < num; i++) {
+               ret = snd_soc_dapm_add_route(codec, route->sink,
+                                            route->control, route->source);
+               if (ret < 0) {
+                       printk(KERN_ERR "Failed to add route %s->%s\n",
+                              route->source,
+                              route->sink);
+                       return ret;
+               }
+               route++;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_add_routes);
+
 /**
  * snd_soc_dapm_new_widgets - add new dapm widgets
  * @codec: audio codec
@@ -963,7 +1013,6 @@ int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec)
 {
        struct snd_soc_dapm_widget *w;
 
-       mutex_lock(&codec->mutex);
        list_for_each_entry(w, &codec->dapm_widgets, list)
        {
                if (w->new)
@@ -998,7 +1047,6 @@ int snd_soc_dapm_new_widgets(struct snd_soc_codec *codec)
        }
 
        dapm_power_widgets(codec, SND_SOC_DAPM_STREAM_NOP);
-       mutex_unlock(&codec->mutex);
        return 0;
 }
 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_widgets);
@@ -1019,8 +1067,9 @@ int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
        int reg = kcontrol->private_value & 0xff;
        int shift = (kcontrol->private_value >> 8) & 0x0f;
        int rshift = (kcontrol->private_value >> 12) & 0x0f;
-       int mask = (kcontrol->private_value >> 16) & 0xff;
+       int max = (kcontrol->private_value >> 16) & 0xff;
        int invert = (kcontrol->private_value >> 24) & 0x01;
+       int mask = (1 << fls(max)) - 1;
 
        /* return the saved value if we are powered down */
        if (widget->id == snd_soc_dapm_pga && !widget->power) {
@@ -1035,10 +1084,10 @@ int snd_soc_dapm_get_volsw(struct snd_kcontrol *kcontrol,
                        (snd_soc_read(widget->codec, reg) >> rshift) & mask;
        if (invert) {
                ucontrol->value.integer.value[0] =
-                       mask - ucontrol->value.integer.value[0];
+                       max - ucontrol->value.integer.value[0];
                if (shift != rshift)
                        ucontrol->value.integer.value[1] =
-                               mask - ucontrol->value.integer.value[1];
+                               max - ucontrol->value.integer.value[1];
        }
 
        return 0;
@@ -1061,7 +1110,8 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
        int reg = kcontrol->private_value & 0xff;
        int shift = (kcontrol->private_value >> 8) & 0x0f;
        int rshift = (kcontrol->private_value >> 12) & 0x0f;
-       int mask = (kcontrol->private_value >> 16) & 0xff;
+       int max = (kcontrol->private_value >> 16) & 0xff;
+       int mask = (1 << fls(max)) - 1;
        int invert = (kcontrol->private_value >> 24) & 0x01;
        unsigned short val, val2, val_mask;
        int ret;
@@ -1069,13 +1119,13 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
        val = (ucontrol->value.integer.value[0] & mask);
 
        if (invert)
-               val = mask - val;
+               val = max - val;
        val_mask = mask << shift;
        val = val << shift;
        if (shift != rshift) {
                val2 = (ucontrol->value.integer.value[1] & mask);
                if (invert)
-                       val2 = mask - val2;
+                       val2 = max - val2;
                val_mask |= mask << rshift;
                val |= val2 << rshift;
        }
@@ -1093,13 +1143,17 @@ int snd_soc_dapm_put_volsw(struct snd_kcontrol *kcontrol,
        dapm_mixer_update_power(widget, kcontrol, reg, val_mask, val, invert);
        if (widget->event) {
                if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
-                       ret = widget->event(widget, SND_SOC_DAPM_PRE_REG);
-                       if (ret < 0)
+                       ret = widget->event(widget, kcontrol,
+                                               SND_SOC_DAPM_PRE_REG);
+                       if (ret < 0) {
+                               ret = 1;
                                goto out;
+                       }
                }
                ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
                if (widget->event_flags & SND_SOC_DAPM_POST_REG)
-                       ret = widget->event(widget, SND_SOC_DAPM_POST_REG);
+                       ret = widget->event(widget, kcontrol,
+                                               SND_SOC_DAPM_POST_REG);
        } else
                ret = snd_soc_update_bits(widget->codec, reg, val_mask, val);
 
@@ -1174,13 +1228,15 @@ int snd_soc_dapm_put_enum_double(struct snd_kcontrol *kcontrol,
        dapm_mux_update_power(widget, kcontrol, mask, mux, e);
        if (widget->event) {
                if (widget->event_flags & SND_SOC_DAPM_PRE_REG) {
-                       ret = widget->event(widget, 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, 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);
 
@@ -1219,6 +1275,33 @@ int snd_soc_dapm_new_control(struct snd_soc_codec *codec,
 }
 EXPORT_SYMBOL_GPL(snd_soc_dapm_new_control);
 
+/**
+ * snd_soc_dapm_new_controls - create new dapm controls
+ * @codec: audio codec
+ * @widget: widget array
+ * @num: number of widgets
+ *
+ * Creates new DAPM controls based upon the templates.
+ *
+ * Returns 0 for success else error.
+ */
+int snd_soc_dapm_new_controls(struct snd_soc_codec *codec,
+       const struct snd_soc_dapm_widget *widget,
+       int num)
+{
+       int i, ret;
+
+       for (i = 0; i < num; i++) {
+               ret = snd_soc_dapm_new_control(codec, widget);
+               if (ret < 0)
+                       return ret;
+               widget++;
+       }
+       return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_new_controls);
+
+
 /**
  * snd_soc_dapm_stream_event - send a stream event to the dapm core
  * @codec: audio codec
@@ -1274,11 +1357,34 @@ int snd_soc_dapm_stream_event(struct snd_soc_codec *codec,
        mutex_unlock(&codec->mutex);
 
        dapm_power_widgets(codec, event);
-       dump_dapm(codec, __FUNCTION__);
+       dump_dapm(codec, __func__);
        return 0;
 }
 EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
 
+/**
+ * snd_soc_dapm_device_event - send a device event to the dapm core
+ * @socdev: audio device
+ * @event: device event
+ *
+ * Sends a device event to the dapm core. The core then makes any
+ * necessary machine or codec power changes..
+ *
+ * Returns 0 for success else error.
+ */
+int snd_soc_dapm_device_event(struct snd_soc_device *socdev, int event)
+{
+       struct snd_soc_codec *codec = socdev->codec;
+       struct snd_soc_machine *machine = socdev->machine;
+
+       if (machine->dapm_event)
+               machine->dapm_event(machine, event);
+       if (codec->dapm_event)
+               codec->dapm_event(codec, event);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_device_event);
+
 /**
  * snd_soc_dapm_set_endpoint - set audio endpoint status
  * @codec: audio codec
@@ -1297,13 +1403,37 @@ int snd_soc_dapm_set_endpoint(struct snd_soc_codec *codec,
        list_for_each_entry(w, &codec->dapm_widgets, list) {
                if (!strcmp(w->name, endpoint)) {
                        w->connected = status;
+                       return 0;
                }
        }
 
-       return 0;
+       return -ENODEV;
 }
 EXPORT_SYMBOL_GPL(snd_soc_dapm_set_endpoint);
 
+/**
+ * snd_soc_dapm_get_endpoint_status - get audio endpoint status
+ * @codec: audio codec
+ * @endpoint: audio signal endpoint (or start point)
+ *
+ * Get audio endpoint status - connected or disconnected.
+ *
+ * Returns status
+ */
+int snd_soc_dapm_get_endpoint_status(struct snd_soc_codec *codec,
+       char *endpoint)
+{
+       struct snd_soc_dapm_widget *w;
+
+       list_for_each_entry(w, &codec->dapm_widgets, list) {
+               if (!strcmp(w->name, endpoint))
+                       return w->connected;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_get_endpoint_status);
+
 /**
  * snd_soc_dapm_free - free dapm resources
  * @socdev: SoC device