Merge branch 'topic/asoc' into for-linus
[safe/jmp/linux-2.6] / sound / soc / codecs / wm8350.c
index ff6c101..8ae2020 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/init.h>
+#include <linux/slab.h>
 #include <linux/delay.h>
 #include <linux/pm.h>
 #include <linux/platform_device.h>
@@ -95,7 +96,7 @@ static int wm8350_codec_write(struct snd_soc_codec *codec, unsigned int reg,
  */
 static inline int wm8350_out1_ramp_step(struct snd_soc_codec *codec)
 {
-       struct wm8350_data *wm8350_data = codec->private_data;
+       struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec);
        struct wm8350_output *out1 = &wm8350_data->out1;
        struct wm8350 *wm8350 = codec->control_data;
        int left_complete = 0, right_complete = 0;
@@ -161,7 +162,7 @@ static inline int wm8350_out1_ramp_step(struct snd_soc_codec *codec)
  */
 static inline int wm8350_out2_ramp_step(struct snd_soc_codec *codec)
 {
-       struct wm8350_data *wm8350_data = codec->private_data;
+       struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec);
        struct wm8350_output *out2 = &wm8350_data->out2;
        struct wm8350 *wm8350 = codec->control_data;
        int left_complete = 0, right_complete = 0;
@@ -231,7 +232,7 @@ static void wm8350_pga_work(struct work_struct *work)
 {
        struct snd_soc_codec *codec =
            container_of(work, struct snd_soc_codec, delayed_work.work);
-       struct wm8350_data *wm8350_data = codec->private_data;
+       struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec);
        struct wm8350_output *out1 = &wm8350_data->out1,
            *out2 = &wm8350_data->out2;
        int i, out1_complete, out2_complete;
@@ -278,7 +279,7 @@ static int pga_event(struct snd_soc_dapm_widget *w,
                     struct snd_kcontrol *kcontrol, int event)
 {
        struct snd_soc_codec *codec = w->codec;
-       struct wm8350_data *wm8350_data = codec->private_data;
+       struct wm8350_data *wm8350_data = snd_soc_codec_get_drvdata(codec);
        struct wm8350_output *out;
 
        switch (w->shift) {
@@ -323,7 +324,7 @@ static int wm8350_put_volsw_2r_vu(struct snd_kcontrol *kcontrol,
                                  struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct wm8350_data *wm8350_priv = codec->private_data;
+       struct wm8350_data *wm8350_priv = snd_soc_codec_get_drvdata(codec);
        struct wm8350_output *out = NULL;
        struct soc_mixer_control *mc =
                (struct soc_mixer_control *)kcontrol->private_value;
@@ -366,7 +367,7 @@ static int wm8350_get_volsw_2r(struct snd_kcontrol *kcontrol,
                               struct snd_ctl_elem_value *ucontrol)
 {
        struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
-       struct wm8350_data *wm8350_priv = codec->private_data;
+       struct wm8350_data *wm8350_priv = snd_soc_codec_get_drvdata(codec);
        struct wm8350_output *out1 = &wm8350_priv->out1;
        struct wm8350_output *out2 = &wm8350_priv->out2;
        struct soc_mixer_control *mc =
@@ -1108,7 +1109,7 @@ static int wm8350_set_fll(struct snd_soc_dai *codec_dai,
 {
        struct snd_soc_codec *codec = codec_dai->codec;
        struct wm8350 *wm8350 = codec->control_data;
-       struct wm8350_data *priv = codec->private_data;
+       struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec);
        struct _fll_div fll_div;
        int ret = 0;
        u16 fll_1, fll_4;
@@ -1160,7 +1161,7 @@ static int wm8350_set_bias_level(struct snd_soc_codec *codec,
                                 enum snd_soc_bias_level level)
 {
        struct wm8350 *wm8350 = codec->control_data;
-       struct wm8350_data *priv = codec->private_data;
+       struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec);
        struct wm8350_audio_platform_data *platform =
                wm8350->codec.platform_data;
        u16 pm1;
@@ -1336,9 +1337,6 @@ static int wm8350_resume(struct platform_device *pdev)
 
        wm8350_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
-       if (codec->suspend_bias_level == SND_SOC_BIAS_ON)
-               wm8350_set_bias_level(codec, SND_SOC_BIAS_ON);
-
        return 0;
 }
 
@@ -1393,12 +1391,13 @@ 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)
 {
-       struct wm8350_data *priv = codec->private_data;
+       struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec);
        struct wm8350 *wm8350 = codec->control_data;
        int irq;
        int ena;
@@ -1422,8 +1421,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);
@@ -1459,23 +1462,28 @@ static irqreturn_t wm8350_mic_handler(int irq, void *data)
  * @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.
+ * 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_data *priv = snd_soc_codec_get_drvdata(codec);
        struct wm8350 *wm8350 = codec->control_data;
 
        priv->mic.jack = jack;
        priv->mic.report = detect_report;
        priv->mic.short_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);
-
-       snd_soc_dapm_force_enable_pin(codec, "Mic Bias");
+       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;
 }
@@ -1498,7 +1506,7 @@ static int wm8350_probe(struct platform_device *pdev)
        socdev->card->codec = wm8350_codec;
        codec = socdev->card->codec;
        wm8350 = codec->control_data;
-       priv = codec->private_data;
+       priv = snd_soc_codec_get_drvdata(codec);
 
        /* Enable the codec */
        wm8350_set_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA);
@@ -1569,7 +1577,7 @@ static int wm8350_remove(struct platform_device *pdev)
        struct snd_soc_device *socdev = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = socdev->card->codec;
        struct wm8350 *wm8350 = codec->control_data;
-       struct wm8350_data *priv = codec->private_data;
+       struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec);
        int ret;
 
        wm8350_clear_bits(wm8350, WM8350_JACK_DETECT,
@@ -1688,7 +1696,7 @@ static __devinit int wm8350_codec_probe(struct platform_device *pdev)
        codec->dai = &wm8350_dai;
        codec->num_dai = 1;
        codec->reg_cache_size = WM8350_MAX_REGISTER;
-       codec->private_data = priv;
+       snd_soc_codec_set_drvdata(codec, priv);
        codec->control_data = wm8350;
 
        /* Put the codec into reset if it wasn't already */
@@ -1720,7 +1728,7 @@ static int __devexit wm8350_codec_remove(struct platform_device *pdev)
 {
        struct wm8350 *wm8350 = platform_get_drvdata(pdev);
        struct snd_soc_codec *codec = wm8350->codec.codec;
-       struct wm8350_data *priv = codec->private_data;
+       struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec);
 
        snd_soc_unregister_dai(&wm8350_dai);
        snd_soc_unregister_codec(codec);