ASoC: update gfp/slab.h includes
[deliverable/linux.git] / sound / soc / codecs / wm8350.c
index df2c6d9617fb78d07b2bc3b4edec741f8b808339..8ac92f5e4f9117ce215c597a81e7e62b3c687a2e 100644 (file)
@@ -54,6 +54,7 @@ struct wm8350_output {
 struct wm8350_jack_data {
        struct snd_soc_jack *jack;
        int report;
+       int short_report;
 };
 
 struct wm8350_data {
@@ -62,6 +63,7 @@ struct wm8350_data {
        struct wm8350_output out2;
        struct wm8350_jack_data hpl;
        struct wm8350_jack_data hpr;
+       struct wm8350_jack_data mic;
        struct regulator_bulk_data supplies[ARRAY_SIZE(supply_names)];
        int fll_freq_out;
        int fll_freq_in;
@@ -1391,7 +1393,8 @@ static irqreturn_t wm8350_hp_jack_handler(int irq, void *data)
  * @jack:   jack to report detection events on
  * @report: value to report
  *
- * Enables the headphone jack detection of the WM8350.
+ * Enables the headphone jack detection of the WM8350.  If no report
+ * is specified then detection is disabled.
  */
 int wm8350_hp_jack_detect(struct snd_soc_codec *codec, enum wm8350_jack which,
                          struct snd_soc_jack *jack, int report)
@@ -1420,8 +1423,12 @@ int wm8350_hp_jack_detect(struct snd_soc_codec *codec, enum wm8350_jack which,
                return -EINVAL;
        }
 
-       wm8350_set_bits(wm8350, WM8350_POWER_MGMT_4, WM8350_TOCLK_ENA);
-       wm8350_set_bits(wm8350, WM8350_JACK_DETECT, ena);
+       if (report) {
+               wm8350_set_bits(wm8350, WM8350_POWER_MGMT_4, WM8350_TOCLK_ENA);
+               wm8350_set_bits(wm8350, WM8350_JACK_DETECT, ena);
+       } else {
+               wm8350_clear_bits(wm8350, WM8350_JACK_DETECT, ena);
+       }
 
        /* Sync status */
        wm8350_hp_jack_handler(irq + wm8350->irq_base, priv);
@@ -1430,6 +1437,60 @@ int wm8350_hp_jack_detect(struct snd_soc_codec *codec, enum wm8350_jack which,
 }
 EXPORT_SYMBOL_GPL(wm8350_hp_jack_detect);
 
+static irqreturn_t wm8350_mic_handler(int irq, void *data)
+{
+       struct wm8350_data *priv = data;
+       struct wm8350 *wm8350 = priv->codec.control_data;
+       u16 reg;
+       int report = 0;
+
+       reg = wm8350_reg_read(wm8350, WM8350_JACK_PIN_STATUS);
+       if (reg & WM8350_JACK_MICSCD_LVL)
+               report |= priv->mic.short_report;
+       if (reg & WM8350_JACK_MICSD_LVL)
+               report |= priv->mic.report;
+
+       snd_soc_jack_report(priv->mic.jack, report,
+                           priv->mic.report | priv->mic.short_report);
+
+       return IRQ_HANDLED;
+}
+
+/**
+ * wm8350_mic_jack_detect - Enable microphone jack detection.
+ *
+ * @codec:         WM8350 codec
+ * @jack:          jack to report detection events on
+ * @detect_report: value to report when presence detected
+ * @short_report:  value to report when microphone short detected
+ *
+ * Enables the microphone jack detection of the WM8350.  If both reports
+ * are specified as zero then detection is disabled.
+ */
+int wm8350_mic_jack_detect(struct snd_soc_codec *codec,
+                          struct snd_soc_jack *jack,
+                          int detect_report, int short_report)
+{
+       struct wm8350_data *priv = codec->private_data;
+       struct wm8350 *wm8350 = codec->control_data;
+
+       priv->mic.jack = jack;
+       priv->mic.report = detect_report;
+       priv->mic.short_report = short_report;
+
+       if (detect_report || short_report) {
+               wm8350_set_bits(wm8350, WM8350_POWER_MGMT_4, WM8350_TOCLK_ENA);
+               wm8350_set_bits(wm8350, WM8350_POWER_MGMT_1,
+                               WM8350_MIC_DET_ENA);
+       } else {
+               wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_1,
+                                 WM8350_MIC_DET_ENA);
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(wm8350_mic_jack_detect);
+
 static struct snd_soc_codec *wm8350_codec;
 
 static int wm8350_probe(struct platform_device *pdev)
@@ -1493,6 +1554,10 @@ static int wm8350_probe(struct platform_device *pdev)
        wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_R,
                            wm8350_hp_jack_handler, 0, "Right jack detect",
                            priv);
+       wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_MICSCD,
+                           wm8350_mic_handler, 0, "Microphone short", priv);
+       wm8350_register_irq(wm8350, WM8350_IRQ_CODEC_MICD,
+                           wm8350_mic_handler, 0, "Microphone detect", priv);
 
        ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
        if (ret < 0) {
@@ -1521,11 +1586,14 @@ static int wm8350_remove(struct platform_device *pdev)
                          WM8350_JDL_ENA | WM8350_JDR_ENA);
        wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_4, WM8350_TOCLK_ENA);
 
+       wm8350_free_irq(wm8350, WM8350_IRQ_CODEC_MICD, priv);
+       wm8350_free_irq(wm8350, WM8350_IRQ_CODEC_MICSCD, priv);
        wm8350_free_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_L, priv);
        wm8350_free_irq(wm8350, WM8350_IRQ_CODEC_JCK_DET_R, priv);
 
        priv->hpl.jack = NULL;
        priv->hpr.jack = NULL;
+       priv->mic.jack = NULL;
 
        /* cancel any work waiting to be queued. */
        ret = cancel_delayed_work(&codec->delayed_work);
This page took 0.026177 seconds and 5 git commands to generate.