]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - sound/soc/codecs/wm8988.c
Merge branch 'master' into csb1725
[mv-sheeva.git] / sound / soc / codecs / wm8988.c
index 19ad590ca0b390065850ce4ab8b0e4e2fd5d841a..d7f2597119703e983cccbaf4485109dd2f439130 100644 (file)
@@ -52,7 +52,7 @@ static const u16 wm8988_reg[] = {
 /* codec private data */
 struct wm8988_priv {
        unsigned int sysclk;
-       struct snd_soc_codec codec;
+       enum snd_soc_control_type control_type;
        struct snd_pcm_hw_constraint_list *sysclk_constraints;
        u16 reg_cache[WM8988_NUM_REG];
 };
@@ -608,8 +608,7 @@ static int wm8988_pcm_hw_params(struct snd_pcm_substream *substream,
                                struct snd_soc_dai *dai)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_device *socdev = rtd->socdev;
-       struct snd_soc_codec *codec = socdev->card->codec;
+       struct snd_soc_codec *codec = rtd->codec;
        struct wm8988_priv *wm8988 = snd_soc_codec_get_drvdata(codec);
        u16 iface = snd_soc_read(codec, WM8988_IFACE) & 0x1f3;
        u16 srate = snd_soc_read(codec, WM8988_SRATE) & 0x180;
@@ -711,8 +710,8 @@ static struct snd_soc_dai_ops wm8988_ops = {
        .digital_mute = wm8988_mute,
 };
 
-struct snd_soc_dai wm8988_dai = {
-       .name = "WM8988",
+static struct snd_soc_dai_driver wm8988_dai = {
+       .name = "wm8988-hifi",
        .playback = {
                .stream_name = "Playback",
                .channels_min = 1,
@@ -730,21 +729,15 @@ struct snd_soc_dai wm8988_dai = {
        .ops = &wm8988_ops,
        .symmetric_rates = 1,
 };
-EXPORT_SYMBOL_GPL(wm8988_dai);
 
-static int wm8988_suspend(struct platform_device *pdev, pm_message_t state)
+static int wm8988_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;
-
        wm8988_set_bias_level(codec, SND_SOC_BIAS_OFF);
        return 0;
 }
 
-static int wm8988_resume(struct platform_device *pdev)
+static int wm8988_resume(struct snd_soc_codec *codec)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_codec *codec = socdev->card->codec;
        int i;
        u8 data[2];
        u16 *cache = codec->reg_cache;
@@ -763,99 +756,22 @@ static int wm8988_resume(struct platform_device *pdev)
        return 0;
 }
 
-static struct snd_soc_codec *wm8988_codec;
-
-static int wm8988_probe(struct platform_device *pdev)
+static int wm8988_probe(struct snd_soc_codec *codec)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_codec *codec;
+       struct wm8988_priv *wm8988 = snd_soc_codec_get_drvdata(codec);
        int ret = 0;
-
-       if (wm8988_codec == NULL) {
-               dev_err(&pdev->dev, "Codec device not registered\n");
-               return -ENODEV;
-       }
-
-       socdev->card->codec = wm8988_codec;
-       codec = wm8988_codec;
-
-       /* register pcms */
-       ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
-       if (ret < 0) {
-               dev_err(codec->dev, "failed to create pcms: %d\n", ret);
-               goto pcm_err;
-       }
-
-       snd_soc_add_controls(codec, wm8988_snd_controls,
-                               ARRAY_SIZE(wm8988_snd_controls));
-       snd_soc_dapm_new_controls(codec, wm8988_dapm_widgets,
-                                 ARRAY_SIZE(wm8988_dapm_widgets));
-       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
-
-       return ret;
-
-pcm_err:
-       return ret;
-}
-
-static int wm8988_remove(struct platform_device *pdev)
-{
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-
-       snd_soc_free_pcms(socdev);
-       snd_soc_dapm_free(socdev);
-
-       return 0;
-}
-
-struct snd_soc_codec_device soc_codec_dev_wm8988 = {
-       .probe =        wm8988_probe,
-       .remove =       wm8988_remove,
-       .suspend =      wm8988_suspend,
-       .resume =       wm8988_resume,
-};
-EXPORT_SYMBOL_GPL(soc_codec_dev_wm8988);
-
-static int wm8988_register(struct wm8988_priv *wm8988,
-                          enum snd_soc_control_type control)
-{
-       struct snd_soc_codec *codec = &wm8988->codec;
-       int ret;
        u16 reg;
 
-       if (wm8988_codec) {
-               dev_err(codec->dev, "Another WM8988 is registered\n");
-               ret = -EINVAL;
-               goto err;
-       }
-
-       mutex_init(&codec->mutex);
-       INIT_LIST_HEAD(&codec->dapm_widgets);
-       INIT_LIST_HEAD(&codec->dapm_paths);
-
-       snd_soc_codec_set_drvdata(codec, wm8988);
-       codec->name = "WM8988";
-       codec->owner = THIS_MODULE;
-       codec->dai = &wm8988_dai;
-       codec->num_dai = 1;
-       codec->reg_cache_size = ARRAY_SIZE(wm8988->reg_cache);
-       codec->reg_cache = &wm8988->reg_cache;
-       codec->bias_level = SND_SOC_BIAS_OFF;
-       codec->set_bias_level = wm8988_set_bias_level;
-
-       memcpy(codec->reg_cache, wm8988_reg,
-              sizeof(wm8988_reg));
-
-       ret = snd_soc_codec_set_cache_io(codec, 7, 9, control);
+       ret = snd_soc_codec_set_cache_io(codec, 7, 9, wm8988->control_type);
        if (ret < 0) {
                dev_err(codec->dev, "Failed to set cache I/O: %d\n", ret);
-               goto err;
+               return ret;
        }
 
        ret = wm8988_reset(codec);
        if (ret < 0) {
                dev_err(codec->dev, "Failed to issue reset\n");
-               goto err;
+               return ret;
        }
 
        /* set the update bits (we always update left then right) */
@@ -870,139 +786,132 @@ static int wm8988_register(struct wm8988_priv *wm8988,
        reg = snd_soc_read(codec, WM8988_RINVOL);
        snd_soc_write(codec, WM8988_RINVOL, reg | 0x0100);
 
-       wm8988_set_bias_level(&wm8988->codec, SND_SOC_BIAS_STANDBY);
-
-       wm8988_dai.dev = codec->dev;
-
-       wm8988_codec = codec;
-
-       ret = snd_soc_register_codec(codec);
-       if (ret != 0) {
-               dev_err(codec->dev, "Failed to register codec: %d\n", ret);
-               goto err;
-       }
+       wm8988_set_bias_level(codec, SND_SOC_BIAS_STANDBY);
 
-       ret = snd_soc_register_dai(&wm8988_dai);
-       if (ret != 0) {
-               dev_err(codec->dev, "Failed to register DAI: %d\n", ret);
-               goto err_codec;
-       }
+       snd_soc_add_controls(codec, wm8988_snd_controls,
+                               ARRAY_SIZE(wm8988_snd_controls));
+       snd_soc_dapm_new_controls(codec, wm8988_dapm_widgets,
+                                 ARRAY_SIZE(wm8988_dapm_widgets));
+       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
 
        return 0;
-
-err_codec:
-       snd_soc_unregister_codec(codec);
-err:
-       kfree(wm8988);
-       return ret;
 }
 
-static void wm8988_unregister(struct wm8988_priv *wm8988)
+static int wm8988_remove(struct snd_soc_codec *codec)
 {
-       wm8988_set_bias_level(&wm8988->codec, SND_SOC_BIAS_OFF);
-       snd_soc_unregister_dai(&wm8988_dai);
-       snd_soc_unregister_codec(&wm8988->codec);
-       kfree(wm8988);
-       wm8988_codec = NULL;
+       wm8988_set_bias_level(codec, SND_SOC_BIAS_OFF);
+       return 0;
 }
 
-#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
-static int wm8988_i2c_probe(struct i2c_client *i2c,
-                           const struct i2c_device_id *id)
+static struct snd_soc_codec_driver soc_codec_dev_wm8988 = {
+       .probe =        wm8988_probe,
+       .remove =       wm8988_remove,
+       .suspend =      wm8988_suspend,
+       .resume =       wm8988_resume,
+       .set_bias_level = wm8988_set_bias_level,
+       .reg_cache_size = ARRAY_SIZE(wm8988_reg),
+       .reg_word_size = sizeof(u16),
+       .reg_cache_default = wm8988_reg,
+};
+
+#if defined(CONFIG_SPI_MASTER)
+static int __devinit wm8988_spi_probe(struct spi_device *spi)
 {
        struct wm8988_priv *wm8988;
-       struct snd_soc_codec *codec;
+       int ret;
 
        wm8988 = kzalloc(sizeof(struct wm8988_priv), GFP_KERNEL);
        if (wm8988 == NULL)
                return -ENOMEM;
 
-       codec = &wm8988->codec;
-
-       i2c_set_clientdata(i2c, wm8988);
-       codec->control_data = i2c;
-
-       codec->dev = &i2c->dev;
+       wm8988->control_type = SND_SOC_SPI;
+       spi_set_drvdata(spi, wm8988);
 
-       return wm8988_register(wm8988, SND_SOC_I2C);
+       ret = snd_soc_register_codec(&spi->dev,
+                       &soc_codec_dev_wm8988, &wm8988_dai, 1);
+       if (ret < 0)
+               kfree(wm8988);
+       return ret;
 }
 
-static int wm8988_i2c_remove(struct i2c_client *client)
+static int __devexit wm8988_spi_remove(struct spi_device *spi)
 {
-       struct wm8988_priv *wm8988 = i2c_get_clientdata(client);
-       wm8988_unregister(wm8988);
+       snd_soc_unregister_codec(&spi->dev);
+       kfree(spi_get_drvdata(spi));
        return 0;
 }
 
-static const struct i2c_device_id wm8988_i2c_id[] = {
-       { "wm8988", 0 },
-       { }
-};
-MODULE_DEVICE_TABLE(i2c, wm8988_i2c_id);
-
-static struct i2c_driver wm8988_i2c_driver = {
+static struct spi_driver wm8988_spi_driver = {
        .driver = {
-               .name = "WM8988",
-               .owner = THIS_MODULE,
+               .name   = "wm8988-codec",
+               .owner  = THIS_MODULE,
        },
-       .probe = wm8988_i2c_probe,
-       .remove = wm8988_i2c_remove,
-       .id_table = wm8988_i2c_id,
+       .probe          = wm8988_spi_probe,
+       .remove         = __devexit_p(wm8988_spi_remove),
 };
-#endif
+#endif /* CONFIG_SPI_MASTER */
 
-#if defined(CONFIG_SPI_MASTER)
-static int __devinit wm8988_spi_probe(struct spi_device *spi)
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+static __devinit int wm8988_i2c_probe(struct i2c_client *i2c,
+                                     const struct i2c_device_id *id)
 {
        struct wm8988_priv *wm8988;
-       struct snd_soc_codec *codec;
+       int ret;
 
        wm8988 = kzalloc(sizeof(struct wm8988_priv), GFP_KERNEL);
        if (wm8988 == NULL)
                return -ENOMEM;
 
-       codec = &wm8988->codec;
-       codec->control_data = spi;
-       codec->dev = &spi->dev;
-
-       dev_set_drvdata(&spi->dev, wm8988);
+       i2c_set_clientdata(i2c, wm8988);
+       wm8988->control_type = SND_SOC_I2C;
 
-       return wm8988_register(wm8988, SND_SOC_SPI);
+       ret =  snd_soc_register_codec(&i2c->dev,
+                       &soc_codec_dev_wm8988, &wm8988_dai, 1);
+       if (ret < 0)
+               kfree(wm8988);
+       return ret;
 }
 
-static int __devexit wm8988_spi_remove(struct spi_device *spi)
+static __devexit int wm8988_i2c_remove(struct i2c_client *client)
 {
-       struct wm8988_priv *wm8988 = dev_get_drvdata(&spi->dev);
-
-       wm8988_unregister(wm8988);
-
+       snd_soc_unregister_codec(&client->dev);
+       kfree(i2c_get_clientdata(client));
        return 0;
 }
 
-static struct spi_driver wm8988_spi_driver = {
+static const struct i2c_device_id wm8988_i2c_id[] = {
+       { "wm8988", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, wm8988_i2c_id);
+
+static struct i2c_driver wm8988_i2c_driver = {
        .driver = {
-               .name   = "wm8988",
-               .bus    = &spi_bus_type,
-               .owner  = THIS_MODULE,
+               .name = "wm8988-codec",
+               .owner = THIS_MODULE,
        },
-       .probe          = wm8988_spi_probe,
-       .remove         = __devexit_p(wm8988_spi_remove),
+       .probe =    wm8988_i2c_probe,
+       .remove =   __devexit_p(wm8988_i2c_remove),
+       .id_table = wm8988_i2c_id,
 };
 #endif
 
 static int __init wm8988_modinit(void)
 {
-       int ret;
-
+       int ret = 0;
 #if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
        ret = i2c_add_driver(&wm8988_i2c_driver);
-       if (ret != 0)
-               pr_err("WM8988: Unable to register I2C driver: %d\n", ret);
+       if (ret != 0) {
+               printk(KERN_ERR "Failed to register WM8988 I2C driver: %d\n",
+                      ret);
+       }
 #endif
 #if defined(CONFIG_SPI_MASTER)
        ret = spi_register_driver(&wm8988_spi_driver);
-       if (ret != 0)
-               pr_err("WM8988: Unable to register SPI driver: %d\n", ret);
+       if (ret != 0) {
+               printk(KERN_ERR "Failed to register WM8988 SPI driver: %d\n",
+                      ret);
+       }
 #endif
        return ret;
 }