]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - sound/soc/codecs/wm8350.c
Merge tag 'v2.6.37' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[mv-sheeva.git] / sound / soc / codecs / wm8350.c
index 0221ca79b3ae59831a15499e263b7ca9cbf1118b..7611add7f8c38751806684a521d891ede746197f 100644 (file)
@@ -831,7 +831,7 @@ static int wm8350_set_dai_sysclk(struct snd_soc_dai *codec_dai,
        }
 
        /* MCLK direction */
-       if (dir == WM8350_MCLK_DIR_OUT)
+       if (dir == SND_SOC_CLOCK_OUT)
                wm8350_set_bits(wm8350, WM8350_CLOCK_CONTROL_2,
                                WM8350_MCLK_DIR);
        else
@@ -1321,20 +1321,14 @@ static int wm8350_set_bias_level(struct snd_soc_codec *codec,
        return 0;
 }
 
-static int wm8350_suspend(struct platform_device *pdev, pm_message_t state)
+static int wm8350_suspend(struct snd_soc_codec *codec, pm_message_t state)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_codec *codec = socdev->card->codec;
-
        wm8350_set_bias_level(codec, SND_SOC_BIAS_OFF);
        return 0;
 }
 
-static int wm8350_resume(struct platform_device *pdev)
+static int wm8350_resume(struct snd_soc_codec *codec)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_codec *codec = socdev->card->codec;
-
        wm8350_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
        return 0;
@@ -1489,24 +1483,74 @@ int wm8350_mic_jack_detect(struct snd_soc_codec *codec,
 }
 EXPORT_SYMBOL_GPL(wm8350_mic_jack_detect);
 
-static struct snd_soc_codec *wm8350_codec;
+#define WM8350_RATES (SNDRV_PCM_RATE_8000_96000)
+
+#define WM8350_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
+                       SNDRV_PCM_FMTBIT_S20_3LE |\
+                       SNDRV_PCM_FMTBIT_S24_LE)
 
-static int wm8350_probe(struct platform_device *pdev)
+static struct snd_soc_dai_ops wm8350_dai_ops = {
+        .hw_params     = wm8350_pcm_hw_params,
+        .digital_mute  = wm8350_mute,
+        .trigger       = wm8350_pcm_trigger,
+        .set_fmt       = wm8350_set_dai_fmt,
+        .set_sysclk    = wm8350_set_dai_sysclk,
+        .set_pll       = wm8350_set_fll,
+        .set_clkdiv    = wm8350_set_clkdiv,
+};
+
+static struct snd_soc_dai_driver wm8350_dai = {
+       .name = "wm8350-hifi",
+       .playback = {
+               .stream_name = "Playback",
+               .channels_min = 1,
+               .channels_max = 2,
+               .rates = WM8350_RATES,
+               .formats = WM8350_FORMATS,
+       },
+       .capture = {
+                .stream_name = "Capture",
+                .channels_min = 1,
+                .channels_max = 2,
+                .rates = WM8350_RATES,
+                .formats = WM8350_FORMATS,
+        },
+       .ops = &wm8350_dai_ops,
+};
+
+static  int wm8350_codec_probe(struct snd_soc_codec *codec)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_codec *codec;
-       struct wm8350 *wm8350;
+       struct wm8350 *wm8350 = dev_get_platdata(codec->dev);
        struct wm8350_data *priv;
-       int ret;
        struct wm8350_output *out1;
        struct wm8350_output *out2;
+       int ret, i;
 
-       BUG_ON(!wm8350_codec);
+       if (wm8350->codec.platform_data == NULL) {
+               dev_err(codec->dev, "No audio platform data supplied\n");
+               return -EINVAL;
+       }
+
+       priv = kzalloc(sizeof(struct wm8350_data), GFP_KERNEL);
+       if (priv == NULL)
+               return -ENOMEM;
+       snd_soc_codec_set_drvdata(codec, priv);
+
+       for (i = 0; i < ARRAY_SIZE(supply_names); i++)
+               priv->supplies[i].supply = supply_names[i];
+
+       ret = regulator_bulk_get(wm8350->dev, ARRAY_SIZE(priv->supplies),
+                                priv->supplies);
+       if (ret != 0)
+               goto err_priv;
+
+       wm8350->codec.codec = codec;
+       codec->control_data = wm8350;
 
-       socdev->card->codec = wm8350_codec;
-       codec = socdev->card->codec;
-       wm8350 = codec->control_data;
-       priv = snd_soc_codec_get_drvdata(codec);
+       /* Put the codec into reset if it wasn't already */
+       wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA);
+
+       INIT_DELAYED_WORK(&codec->delayed_work, wm8350_pga_work);
 
        /* Enable the codec */
        wm8350_set_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA);
@@ -1542,6 +1586,13 @@ static int wm8350_probe(struct platform_device *pdev)
        wm8350_set_bits(wm8350, WM8350_ROUT2_VOLUME,
                        WM8350_OUT2_VU | WM8350_OUT2R_MUTE);
 
+       /* Make sure AIF tristating is disabled by default */
+       wm8350_clear_bits(wm8350, WM8350_AI_FORMATING, WM8350_AIF_TRI);
+
+       /* Make sure we've got a sane companding setup too */
+       wm8350_clear_bits(wm8350, WM8350_ADC_DAC_COMP,
+                         WM8350_DAC_COMP | WM8350_LOOPBACK);
+
        /* Make sure jack detect is disabled to start off with */
        wm8350_clear_bits(wm8350, WM8350_JACK_DETECT,
                          WM8350_JDL_ENA | WM8350_JDR_ENA);
@@ -1557,11 +1608,6 @@ static int wm8350_probe(struct platform_device *pdev)
        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) {
-               dev_err(&pdev->dev, "failed to create pcms\n");
-               return ret;
-       }
 
        snd_soc_add_controls(codec, wm8350_snd_controls,
                                ARRAY_SIZE(wm8350_snd_controls));
@@ -1570,14 +1616,16 @@ static int wm8350_probe(struct platform_device *pdev)
        wm8350_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
        return 0;
+
+err_priv:
+       kfree(priv);
+       return ret;
 }
 
-static int wm8350_remove(struct platform_device *pdev)
+static int  wm8350_codec_remove(struct snd_soc_codec *codec)
 {
-       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 = snd_soc_codec_get_drvdata(codec);
+       struct wm8350 *wm8350 = dev_get_platdata(codec->dev);
        int ret;
 
        wm8350_clear_bits(wm8350, WM8350_JACK_DETECT,
@@ -1607,134 +1655,30 @@ static int wm8350_remove(struct platform_device *pdev)
 
        wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA);
 
+       regulator_bulk_free(ARRAY_SIZE(priv->supplies), priv->supplies);
+       kfree(priv);
        return 0;
 }
 
-#define WM8350_RATES (SNDRV_PCM_RATE_8000_96000)
-
-#define WM8350_FORMATS (SNDRV_PCM_FMTBIT_S16_LE |\
-                       SNDRV_PCM_FMTBIT_S20_3LE |\
-                       SNDRV_PCM_FMTBIT_S24_LE)
-
-static struct snd_soc_dai_ops wm8350_dai_ops = {
-        .hw_params     = wm8350_pcm_hw_params,
-        .digital_mute  = wm8350_mute,
-        .trigger       = wm8350_pcm_trigger,
-        .set_fmt       = wm8350_set_dai_fmt,
-        .set_sysclk    = wm8350_set_dai_sysclk,
-        .set_pll       = wm8350_set_fll,
-        .set_clkdiv    = wm8350_set_clkdiv,
-};
-
-struct snd_soc_dai wm8350_dai = {
-       .name = "WM8350",
-       .playback = {
-               .stream_name = "Playback",
-               .channels_min = 1,
-               .channels_max = 2,
-               .rates = WM8350_RATES,
-               .formats = WM8350_FORMATS,
-       },
-       .capture = {
-                .stream_name = "Capture",
-                .channels_min = 1,
-                .channels_max = 2,
-                .rates = WM8350_RATES,
-                .formats = WM8350_FORMATS,
-        },
-       .ops = &wm8350_dai_ops,
-};
-EXPORT_SYMBOL_GPL(wm8350_dai);
-
-struct snd_soc_codec_device soc_codec_dev_wm8350 = {
-       .probe =        wm8350_probe,
-       .remove =       wm8350_remove,
+static struct snd_soc_codec_driver soc_codec_dev_wm8350 = {
+       .probe =        wm8350_codec_probe,
+       .remove =       wm8350_codec_remove,
        .suspend =      wm8350_suspend,
        .resume =       wm8350_resume,
+       .read = wm8350_codec_read,
+       .write = wm8350_codec_write,
+       .set_bias_level = wm8350_set_bias_level,
 };
-EXPORT_SYMBOL_GPL(soc_codec_dev_wm8350);
 
-static __devinit int wm8350_codec_probe(struct platform_device *pdev)
+static int __devinit wm8350_probe(struct platform_device *pdev)
 {
-       struct wm8350 *wm8350 = platform_get_drvdata(pdev);
-       struct wm8350_data *priv;
-       struct snd_soc_codec *codec;
-       int ret, i;
-
-       if (wm8350->codec.platform_data == NULL) {
-               dev_err(&pdev->dev, "No audio platform data supplied\n");
-               return -EINVAL;
-       }
-
-       priv = kzalloc(sizeof(struct wm8350_data), GFP_KERNEL);
-       if (priv == NULL)
-               return -ENOMEM;
-
-       for (i = 0; i < ARRAY_SIZE(supply_names); i++)
-               priv->supplies[i].supply = supply_names[i];
-
-       ret = regulator_bulk_get(wm8350->dev, ARRAY_SIZE(priv->supplies),
-                                priv->supplies);
-       if (ret != 0)
-               goto err_priv;
-
-       codec = &priv->codec;
-       wm8350->codec.codec = codec;
-
-       wm8350_dai.dev = &pdev->dev;
-
-       mutex_init(&codec->mutex);
-       INIT_LIST_HEAD(&codec->dapm_widgets);
-       INIT_LIST_HEAD(&codec->dapm_paths);
-       codec->dev = &pdev->dev;
-       codec->name = "WM8350";
-       codec->owner = THIS_MODULE;
-       codec->read = wm8350_codec_read;
-       codec->write = wm8350_codec_write;
-       codec->bias_level = SND_SOC_BIAS_OFF;
-       codec->set_bias_level = wm8350_set_bias_level;
-       codec->dai = &wm8350_dai;
-       codec->num_dai = 1;
-       codec->reg_cache_size = WM8350_MAX_REGISTER;
-       snd_soc_codec_set_drvdata(codec, priv);
-       codec->control_data = wm8350;
-
-       /* Put the codec into reset if it wasn't already */
-       wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_5, WM8350_CODEC_ENA);
-
-       INIT_DELAYED_WORK(&codec->delayed_work, wm8350_pga_work);
-       ret = snd_soc_register_codec(codec);
-       if (ret != 0)
-               goto err_supply;
-
-       wm8350_codec = codec;
-
-       ret = snd_soc_register_dai(&wm8350_dai);
-       if (ret != 0)
-               goto err_codec;
-       return 0;
-
-err_codec:
-       snd_soc_unregister_codec(codec);
-err_supply:
-       regulator_bulk_free(ARRAY_SIZE(priv->supplies), priv->supplies);
-err_priv:
-       kfree(priv);
-       wm8350_codec = NULL;
-       return ret;
+       return snd_soc_register_codec(&pdev->dev, &soc_codec_dev_wm8350,
+                       &wm8350_dai, 1);
 }
 
-static int __devexit wm8350_codec_remove(struct platform_device *pdev)
+static int __devexit wm8350_remove(struct platform_device *pdev)
 {
-       struct wm8350 *wm8350 = platform_get_drvdata(pdev);
-       struct snd_soc_codec *codec = wm8350->codec.codec;
-       struct wm8350_data *priv = snd_soc_codec_get_drvdata(codec);
-
-       snd_soc_unregister_dai(&wm8350_dai);
-       snd_soc_unregister_codec(codec);
-       regulator_bulk_free(ARRAY_SIZE(priv->supplies), priv->supplies);
-       kfree(priv);
-       wm8350_codec = NULL;
+       snd_soc_unregister_codec(&pdev->dev);
        return 0;
 }
 
@@ -1743,8 +1687,8 @@ static struct platform_driver wm8350_codec_driver = {
                   .name = "wm8350-codec",
                   .owner = THIS_MODULE,
                   },
-       .probe = wm8350_codec_probe,
-       .remove = __devexit_p(wm8350_codec_remove),
+       .probe = wm8350_probe,
+       .remove = __devexit_p(wm8350_remove),
 };
 
 static __init int wm8350_init(void)