ASoC: Allow pins to be force enabled
authorMark Brown <broonie@opensource.wolfsonmicro.com>
Mon, 15 Mar 2010 19:23:37 +0000 (19:23 +0000)
committerMark Brown <broonie@opensource.wolfsonmicro.com>
Tue, 16 Mar 2010 15:56:10 +0000 (15:56 +0000)
Allow pins to be forced on regardless of their power state. This is
intended for use with microphone bias supplies which need to be
enabled in order to support microphone detection - in systems without
appropriate hardware leaving the microphone unbiased when not in use
saves power.

The force done at power check time in order to avoid disrupting other
power detection logic.

Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Acked-by: Liam Girdwood <lrg@slimlogic.co.uk>
include/sound/soc-dapm.h
sound/soc/soc-dapm.c

index 5915fc0598429efd2cd32873f478e21770f15894..d5d6ba862dfedf4a2aef1aea1831a4a72239dbd5 100644 (file)
@@ -339,6 +339,8 @@ int snd_soc_dapm_disable_pin(struct snd_soc_codec *codec, const char *pin);
 int snd_soc_dapm_nc_pin(struct snd_soc_codec *codec, const char *pin);
 int snd_soc_dapm_get_pin_status(struct snd_soc_codec *codec, const char *pin);
 int snd_soc_dapm_sync(struct snd_soc_codec *codec);
+int snd_soc_dapm_force_enable_pin(struct snd_soc_codec *codec,
+                                 const char *pin);
 
 /* dapm widget types */
 enum snd_soc_dapm_type {
@@ -426,6 +428,7 @@ struct snd_soc_dapm_widget {
        unsigned char new:1;                    /* cnew complete */
        unsigned char ext:1;                    /* has external widgets */
        unsigned char suspend:1;                /* was active before suspend */
+       unsigned char force:1;                  /* force state */
 
        int (*power_check)(struct snd_soc_dapm_widget *w);
 
index 86ded22e36afe33953bd6e78b0a75d2979b03985..bbb2135a0b21dc9f12db8aae3cc82c51dd6faeaf 100644 (file)
@@ -979,7 +979,10 @@ static int dapm_power_widgets(struct snd_soc_codec *codec, int event)
                                break;
 
                        default:
-                               power = w->power_check(w);
+                               if (!w->force)
+                                       power = w->power_check(w);
+                               else
+                                       power = 1;
                                if (power)
                                        sys_power = 1;
                                break;
@@ -2133,6 +2136,36 @@ int snd_soc_dapm_enable_pin(struct snd_soc_codec *codec, const char *pin)
 }
 EXPORT_SYMBOL_GPL(snd_soc_dapm_enable_pin);
 
+/**
+ * snd_soc_dapm_force_enable_pin - force a pin to be enabled
+ * @codec: SoC codec
+ * @pin: pin name
+ *
+ * Enables input/output pin regardless of any other state.  This is
+ * intended for use with microphone bias supplies used in microphone
+ * jack detection.
+ *
+ * NOTE: snd_soc_dapm_sync() needs to be called after this for DAPM to
+ * do any widget power switching.
+ */
+int snd_soc_dapm_force_enable_pin(struct snd_soc_codec *codec, const char *pin)
+{
+       struct snd_soc_dapm_widget *w;
+
+       list_for_each_entry(w, &codec->dapm_widgets, list) {
+               if (!strcmp(w->name, pin)) {
+                       pr_debug("dapm: %s: pin %s\n", codec->name, pin);
+                       w->connected = 1;
+                       w->force = 1;
+                       return 0;
+               }
+       }
+
+       pr_err("dapm: %s: configuring unknown pin %s\n", codec->name, pin);
+       return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(snd_soc_dapm_force_enable_pin);
+
 /**
  * snd_soc_dapm_disable_pin - disable pin.
  * @codec: SoC codec